UNPKG

n8n

Version:

n8n Workflow Automation Tool

128 lines 4.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AgentJsonConfigPartialSchema = exports.AgentJsonConfigSchema = exports.NodeConfigSchema = void 0; exports.tryParseConfigJson = tryParseConfigJson; exports.formatZodErrors = formatZodErrors; exports.isNodeToolsEnabled = isNodeToolsEnabled; const zod_1 = require("zod"); const integration_config_1 = require("./integration-config"); const SemanticRecallSchema = zod_1.z.object({ topK: zod_1.z.number().int().min(1).max(100), scope: zod_1.z.enum(['thread', 'resource']).optional(), messageRange: zod_1.z .object({ before: zod_1.z.number().int().min(0), after: zod_1.z.number().int().min(0), }) .optional(), embedder: zod_1.z.string().optional(), }); const MemoryConfigSchema = zod_1.z.object({ enabled: zod_1.z.boolean(), storage: zod_1.z.enum(['n8n', 'sqlite', 'postgres']), connection: zod_1.z.record(zod_1.z.unknown()).optional(), lastMessages: zod_1.z.number().int().min(1).max(200).optional(), semanticRecall: SemanticRecallSchema.optional(), }); const ThinkingConfigSchema = zod_1.z.object({ provider: zod_1.z.enum(['anthropic', 'openai']), budgetTokens: zod_1.z.number().int().optional(), reasoningEffort: zod_1.z.string().optional(), }); const NodeToolCredentialSchema = zod_1.z.object({ id: zod_1.z.string(), name: zod_1.z.string(), }); exports.NodeConfigSchema = zod_1.z.object({ nodeType: zod_1.z.string().min(1), nodeTypeVersion: zod_1.z.number(), nodeParameters: zod_1.z.record(zod_1.z.unknown()).optional().default({}), credentials: zod_1.z.record(NodeToolCredentialSchema).optional(), }); const AgentJsonSkillConfigSchema = zod_1.z.object({ type: zod_1.z.literal('skill'), id: zod_1.z .string() .min(1) .regex(/^[A-Za-z0-9_-]+$/), }); const AgentJsonToolConfigSchema = zod_1.z.discriminatedUnion('type', [ zod_1.z.object({ type: zod_1.z.literal('custom'), id: zod_1.z .string() .min(1) .regex(/^[A-Za-z0-9_-]+$/), requireApproval: zod_1.z.boolean().optional(), }), zod_1.z .object({ type: zod_1.z.literal('workflow'), workflow: zod_1.z.string().min(1), name: zod_1.z.string().optional(), description: zod_1.z.string().optional(), requireApproval: zod_1.z.boolean().optional(), allOutputs: zod_1.z .boolean() .optional() .describe('Whether to return all node outputs instead of just the last node'), }) .strict(), zod_1.z .object({ type: zod_1.z.literal('node'), name: zod_1.z.string().min(1), description: zod_1.z.string().optional(), node: exports.NodeConfigSchema, requireApproval: zod_1.z.boolean().optional(), }) .strict(), ]); exports.AgentJsonConfigSchema = zod_1.z.object({ name: zod_1.z.string().min(1).max(128), description: zod_1.z.string().max(512).optional(), model: zod_1.z .string() .min(1) .regex(/^[a-z0-9-]+\/(?:[a-z0-9._-]+\/)*[a-z0-9._-]+$/i, 'Model must be "provider/model-name" format (e.g. "anthropic/claude-sonnet-4-5" or "openrouter/amazon/nova-micro-v1")'), credential: zod_1.z.string().optional(), instructions: zod_1.z.string(), memory: MemoryConfigSchema.optional(), tools: zod_1.z.array(AgentJsonToolConfigSchema).optional(), skills: zod_1.z.array(AgentJsonSkillConfigSchema).optional(), providerTools: zod_1.z.record(zod_1.z.record(zod_1.z.unknown())).optional(), integrations: zod_1.z.array(integration_config_1.AgentIntegrationSchema).optional(), config: zod_1.z .object({ thinking: ThinkingConfigSchema.optional(), toolCallConcurrency: zod_1.z.number().int().min(1).max(20).optional(), nodeTools: zod_1.z .object({ enabled: zod_1.z.boolean(), }) .optional(), }) .optional(), }); exports.AgentJsonConfigPartialSchema = exports.AgentJsonConfigSchema.partial(); function tryParseConfigJson(raw) { try { return { ok: true, data: JSON.parse(raw) }; } catch (e) { const msg = e instanceof SyntaxError ? e.message : String(e); return { ok: false, errors: [{ path: '(root)', message: `JSON parse error: ${msg}` }] }; } } function formatZodErrors(error) { return error.issues.map((issue) => ({ path: issue.path.join('.') || '(root)', message: issue.message, expected: 'expected' in issue ? String(issue.expected) : undefined, received: 'received' in issue ? String(issue.received) : undefined, })); } function isNodeToolsEnabled(config) { return config?.nodeTools?.enabled === true; } //# sourceMappingURL=agent-json-config.js.map