mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor: Replace json-schema-to-zod with our own fork (#11229)
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
/* eslint-disable n8n-nodes-base/node-dirname-against-convention */
|
||||
import { DynamicStructuredTool, DynamicTool } from '@langchain/core/tools';
|
||||
import type { JSONSchema7 } from 'json-schema';
|
||||
import { JavaScriptSandbox } from 'n8n-nodes-base/dist/nodes/Code/JavaScriptSandbox';
|
||||
import { PythonSandbox } from 'n8n-nodes-base/dist/nodes/Code/PythonSandbox';
|
||||
import type { Sandbox } from 'n8n-nodes-base/dist/nodes/Code/Sandbox';
|
||||
import { getSandboxContext } from 'n8n-nodes-base/dist/nodes/Code/Sandbox';
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
INodeType,
|
||||
@@ -7,23 +13,16 @@ import type {
|
||||
ExecutionError,
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { jsonParse, NodeConnectionType, NodeOperationError } from 'n8n-workflow';
|
||||
import type { Sandbox } from 'n8n-nodes-base/dist/nodes/Code/Sandbox';
|
||||
import { getSandboxContext } from 'n8n-nodes-base/dist/nodes/Code/Sandbox';
|
||||
import { JavaScriptSandbox } from 'n8n-nodes-base/dist/nodes/Code/JavaScriptSandbox';
|
||||
import { PythonSandbox } from 'n8n-nodes-base/dist/nodes/Code/PythonSandbox';
|
||||
|
||||
import { DynamicStructuredTool, DynamicTool } from '@langchain/core/tools';
|
||||
import { getConnectionHintNoticeField } from '../../../utils/sharedFields';
|
||||
import type { DynamicZodObject } from '../../../types/zod.types';
|
||||
import {
|
||||
inputSchemaField,
|
||||
jsonSchemaExampleField,
|
||||
schemaTypeField,
|
||||
} from '../../../utils/descriptions';
|
||||
import { generateSchema, getSandboxWithZod } from '../../../utils/schemaParsing';
|
||||
import type { JSONSchema7 } from 'json-schema';
|
||||
import type { DynamicZodObject } from '../../../types/zod.types';
|
||||
import { convertJsonSchemaToZod, generateSchema } from '../../../utils/schemaParsing';
|
||||
import { getConnectionHintNoticeField } from '../../../utils/sharedFields';
|
||||
|
||||
export class ToolCode implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -273,10 +272,9 @@ export class ToolCode implements INodeType {
|
||||
? generateSchema(jsonExample)
|
||||
: jsonParse<JSONSchema7>(inputSchema);
|
||||
|
||||
const zodSchemaSandbox = getSandboxWithZod(this, jsonSchema, 0);
|
||||
const zodSchema = await zodSchemaSandbox.runCode<DynamicZodObject>();
|
||||
const zodSchema = convertJsonSchemaToZod<DynamicZodObject>(jsonSchema);
|
||||
|
||||
tool = new DynamicStructuredTool<typeof zodSchema>({
|
||||
tool = new DynamicStructuredTool({
|
||||
schema: zodSchema,
|
||||
...commonToolOptions,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user