mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(Information Extractor Node): Add new simplified AI-node for information extraction (#10149)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { z } from 'zod';
|
||||
import type { AttributeDefinition } from './types';
|
||||
|
||||
function makeAttributeSchema(attributeDefinition: AttributeDefinition, required: boolean = true) {
|
||||
let schema: z.ZodTypeAny;
|
||||
|
||||
if (attributeDefinition.type === 'string') {
|
||||
schema = z.string();
|
||||
} else if (attributeDefinition.type === 'number') {
|
||||
schema = z.number();
|
||||
} else if (attributeDefinition.type === 'boolean') {
|
||||
schema = z.boolean();
|
||||
} else if (attributeDefinition.type === 'date') {
|
||||
schema = z.string().date();
|
||||
} else {
|
||||
schema = z.unknown();
|
||||
}
|
||||
|
||||
if (!required) {
|
||||
schema = schema.optional();
|
||||
}
|
||||
|
||||
return schema.describe(attributeDefinition.description);
|
||||
}
|
||||
|
||||
export function makeZodSchemaFromAttributes(attributes: AttributeDefinition[]) {
|
||||
const schemaEntries = attributes.map((attr) => [
|
||||
attr.name,
|
||||
makeAttributeSchema(attr, attr.required),
|
||||
]);
|
||||
|
||||
return z.object(Object.fromEntries(schemaEntries));
|
||||
}
|
||||
Reference in New Issue
Block a user