mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
21 lines
557 B
TypeScript
21 lines
557 B
TypeScript
import type { StructuredTool } from 'langchain/tools';
|
|
import { type IDataObject, type INodeExecutionData } from 'n8n-workflow';
|
|
|
|
import { convertObjectBySchema } from './convertToSchema';
|
|
|
|
export async function executeTool(
|
|
tool: StructuredTool,
|
|
query: string | object,
|
|
): Promise<INodeExecutionData> {
|
|
let convertedQuery: string | object = query;
|
|
if ('schema' in tool && tool.schema) {
|
|
convertedQuery = convertObjectBySchema(query, tool.schema);
|
|
}
|
|
|
|
const result = await tool.invoke(convertedQuery);
|
|
|
|
return {
|
|
json: result as IDataObject,
|
|
};
|
|
}
|