fix: 修复TypeScript配置错误并更新项目文档
详细说明: - 修复了@n8n/config包的TypeScript配置错误 - 移除了不存在的jest-expect-message类型引用 - 清理了所有TypeScript构建缓存 - 更新了可行性分析文档,添加了技术实施方案 - 更新了Agent prompt文档 - 添加了会展策划工作流文档 - 包含了n8n-chinese-translation子项目 - 添加了exhibition-demo展示系统框架
This commit is contained in:
63
n8n-n8n-1.109.2/packages/@n8n/nodes-langchain/utils/schemaParsing 2.ts
Executable file
63
n8n-n8n-1.109.2/packages/@n8n/nodes-langchain/utils/schemaParsing 2.ts
Executable file
@@ -0,0 +1,63 @@
|
||||
import { jsonSchemaToZod } from '@n8n/json-schema-to-zod';
|
||||
import { json as generateJsonSchema } from 'generate-schema';
|
||||
import type { SchemaObject } from 'generate-schema';
|
||||
import type { JSONSchema7 } from 'json-schema';
|
||||
import type { IExecuteFunctions } from 'n8n-workflow';
|
||||
import { NodeOperationError, jsonParse } from 'n8n-workflow';
|
||||
import type { z } from 'zod';
|
||||
|
||||
function makeAllPropertiesRequired(schema: JSONSchema7): JSONSchema7 {
|
||||
function isPropertySchema(property: unknown): property is JSONSchema7 {
|
||||
return typeof property === 'object' && property !== null && 'type' in property;
|
||||
}
|
||||
|
||||
// Handle object properties
|
||||
if (schema.type === 'object' && schema.properties) {
|
||||
const properties = Object.keys(schema.properties);
|
||||
if (properties.length > 0) {
|
||||
schema.required = properties;
|
||||
}
|
||||
|
||||
for (const key of properties) {
|
||||
if (isPropertySchema(schema.properties[key])) {
|
||||
makeAllPropertiesRequired(schema.properties[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle arrays
|
||||
if (schema.type === 'array' && schema.items && isPropertySchema(schema.items)) {
|
||||
schema.items = makeAllPropertiesRequired(schema.items);
|
||||
}
|
||||
|
||||
return schema;
|
||||
}
|
||||
|
||||
export function generateSchemaFromExample(
|
||||
exampleJsonString: string,
|
||||
allFieldsRequired = false,
|
||||
): JSONSchema7 {
|
||||
const parsedExample = jsonParse<SchemaObject>(exampleJsonString);
|
||||
|
||||
const schema = generateJsonSchema(parsedExample) as JSONSchema7;
|
||||
|
||||
if (allFieldsRequired) {
|
||||
return makeAllPropertiesRequired(schema);
|
||||
}
|
||||
|
||||
return schema;
|
||||
}
|
||||
|
||||
export function convertJsonSchemaToZod<T extends z.ZodTypeAny = z.ZodTypeAny>(schema: JSONSchema7) {
|
||||
return jsonSchemaToZod<T>(schema);
|
||||
}
|
||||
|
||||
export function throwIfToolSchema(ctx: IExecuteFunctions, error: Error) {
|
||||
if (error?.message?.includes('tool input did not match expected schema')) {
|
||||
throw new NodeOperationError(
|
||||
ctx.getNode(),
|
||||
`${error.message}.
|
||||
This is most likely because some of your tools are configured to require a specific schema. This is not supported by Conversational Agent. Remove the schema from the tool configuration or use Tools agent instead.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user