@kairos-sdk/core 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -7
- package/dist/{chunk-Q77XA7UC.js → chunk-KQSNT3HZ.js} +2 -2
- package/dist/{chunk-DDV7ZART.js → chunk-RYGYNOR6.js} +20 -5
- package/dist/chunk-RYGYNOR6.js.map +1 -0
- package/dist/cli.cjs +19 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/index.cjs +19 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +2 -2
- package/dist/mcp-server.cjs +150 -5
- package/dist/mcp-server.cjs.map +1 -1
- package/dist/mcp-server.js +136 -2
- package/dist/mcp-server.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-DDV7ZART.js.map +0 -1
- /package/dist/{chunk-Q77XA7UC.js.map → chunk-KQSNT3HZ.js.map} +0 -0
package/dist/mcp-server.js
CHANGED
|
@@ -1,18 +1,79 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
DEFAULT_REGISTRY,
|
|
3
4
|
FileLibrary,
|
|
4
5
|
N8nApiClient,
|
|
5
6
|
N8nFieldStripper,
|
|
6
7
|
N8nValidator,
|
|
8
|
+
NodeRegistry,
|
|
7
9
|
PromptBuilder,
|
|
8
10
|
TelemetryReader,
|
|
9
11
|
nullLogger
|
|
10
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-RYGYNOR6.js";
|
|
11
13
|
|
|
12
14
|
// src/mcp-server.ts
|
|
13
15
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
14
16
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
15
17
|
import { z } from "zod";
|
|
18
|
+
|
|
19
|
+
// src/validation/node-syncer.ts
|
|
20
|
+
var TRIGGER_PATTERNS = [/trigger/i, /Trigger$/];
|
|
21
|
+
var NodeSyncer = class {
|
|
22
|
+
baseRegistry;
|
|
23
|
+
constructor() {
|
|
24
|
+
this.baseRegistry = new Map(DEFAULT_REGISTRY.map((d) => [d.type, d]));
|
|
25
|
+
}
|
|
26
|
+
sync(liveNodes) {
|
|
27
|
+
const merged = new Map(this.baseRegistry);
|
|
28
|
+
let newNodes = 0;
|
|
29
|
+
for (const node of liveNodes) {
|
|
30
|
+
const versions = Array.isArray(node.version) ? node.version : [node.version];
|
|
31
|
+
const isTrigger = TRIGGER_PATTERNS.some((p) => p.test(node.name));
|
|
32
|
+
const credentialType = node.credentials?.[0]?.name;
|
|
33
|
+
const existing = merged.get(node.name);
|
|
34
|
+
if (existing) {
|
|
35
|
+
const allVersions = /* @__PURE__ */ new Set([...existing.safeTypeVersions, ...versions]);
|
|
36
|
+
merged.set(node.name, {
|
|
37
|
+
...existing,
|
|
38
|
+
safeTypeVersions: [...allVersions].sort((a, b) => a - b)
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
newNodes++;
|
|
42
|
+
merged.set(node.name, {
|
|
43
|
+
type: node.name,
|
|
44
|
+
safeTypeVersions: versions.sort((a, b) => a - b),
|
|
45
|
+
requiredParams: [],
|
|
46
|
+
...credentialType ? { credentialType } : {},
|
|
47
|
+
...isTrigger ? { isTrigger: true } : {}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const definitions = [...merged.values()];
|
|
52
|
+
const registry = new NodeRegistry(definitions);
|
|
53
|
+
const catalogText = this.buildCatalog(definitions);
|
|
54
|
+
return { registry, catalogText, nodeCount: definitions.length, newNodes };
|
|
55
|
+
}
|
|
56
|
+
buildCatalog(definitions) {
|
|
57
|
+
const triggers = definitions.filter((d) => d.isTrigger);
|
|
58
|
+
const regular = definitions.filter((d) => !d.isTrigger);
|
|
59
|
+
const formatEntry = (d) => {
|
|
60
|
+
const versions = d.safeTypeVersions.join(", ");
|
|
61
|
+
const cred = d.credentialType ? ` \u2014 cred: ${d.credentialType}` : "";
|
|
62
|
+
return `${d.type} typeVersion: ${versions}${cred}`;
|
|
63
|
+
};
|
|
64
|
+
const triggerLines = triggers.map(formatEntry).join("\n");
|
|
65
|
+
const regularLines = regular.map(formatEntry).join("\n");
|
|
66
|
+
return `## NODE CATALOG \u2014 synced from your n8n instance (${definitions.length} node types)
|
|
67
|
+
|
|
68
|
+
### Triggers:
|
|
69
|
+
${triggerLines}
|
|
70
|
+
|
|
71
|
+
### Regular nodes:
|
|
72
|
+
${regularLines}`;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/mcp-server.ts
|
|
16
77
|
import { readFileSync } from "fs";
|
|
17
78
|
import { dirname, join } from "path";
|
|
18
79
|
import { fileURLToPath } from "url";
|
|
@@ -20,6 +81,8 @@ var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
20
81
|
var pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
|
|
21
82
|
var library = new FileLibrary();
|
|
22
83
|
var validator = new N8nValidator();
|
|
84
|
+
var nodeSyncer = new NodeSyncer();
|
|
85
|
+
var lastSync = null;
|
|
23
86
|
var stripper = new N8nFieldStripper();
|
|
24
87
|
var promptBuilder = new PromptBuilder();
|
|
25
88
|
function getTelemetryReader() {
|
|
@@ -41,6 +104,22 @@ function getApiClient() {
|
|
|
41
104
|
}
|
|
42
105
|
return new N8nApiClient(baseUrl, apiKey, nullLogger);
|
|
43
106
|
}
|
|
107
|
+
async function autoSync() {
|
|
108
|
+
if (lastSync) return lastSync;
|
|
109
|
+
const baseUrl = process.env["N8N_BASE_URL"];
|
|
110
|
+
const apiKey = process.env["N8N_API_KEY"];
|
|
111
|
+
if (!baseUrl || !apiKey) return null;
|
|
112
|
+
try {
|
|
113
|
+
const client = new N8nApiClient(baseUrl, apiKey, nullLogger);
|
|
114
|
+
const nodeTypes = await client.getNodeTypes();
|
|
115
|
+
if (nodeTypes.length === 0) return null;
|
|
116
|
+
lastSync = nodeSyncer.sync(nodeTypes);
|
|
117
|
+
validator = new N8nValidator(lastSync.registry);
|
|
118
|
+
return lastSync;
|
|
119
|
+
} catch {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
44
123
|
var server = new McpServer({
|
|
45
124
|
name: "kairos",
|
|
46
125
|
version: pkg.version
|
|
@@ -53,12 +132,24 @@ server.tool(
|
|
|
53
132
|
name: z.string().optional().describe("Optional workflow name override")
|
|
54
133
|
},
|
|
55
134
|
async ({ description, name }) => {
|
|
135
|
+
const baseUrl = process.env["N8N_BASE_URL"];
|
|
136
|
+
const apiKey = process.env["N8N_API_KEY"];
|
|
137
|
+
if (!baseUrl || !apiKey) {
|
|
138
|
+
return {
|
|
139
|
+
content: [{
|
|
140
|
+
type: "text",
|
|
141
|
+
text: JSON.stringify({ error: "N8N_BASE_URL and N8N_API_KEY are required. Kairos needs to sync your n8n instance's node types to generate accurate workflows." })
|
|
142
|
+
}],
|
|
143
|
+
isError: true
|
|
144
|
+
};
|
|
145
|
+
}
|
|
56
146
|
await library.initialize();
|
|
147
|
+
const syncResult = await autoSync();
|
|
57
148
|
const matches = await library.search(description);
|
|
58
149
|
const telemetryReader = getTelemetryReader();
|
|
59
150
|
const failureRates = await telemetryReader?.getFailureRates() ?? [];
|
|
60
151
|
const request = { description, ...name ? { name } : {} };
|
|
61
|
-
const built = promptBuilder.build(request, matches, failureRates);
|
|
152
|
+
const built = promptBuilder.build(request, matches, failureRates, syncResult?.catalogText);
|
|
62
153
|
const systemText = built.system.map((block) => block.text).join("\n\n---\n\n");
|
|
63
154
|
return {
|
|
64
155
|
content: [{
|
|
@@ -67,6 +158,9 @@ server.tool(
|
|
|
67
158
|
mode: built.mode,
|
|
68
159
|
matchCount: matches.length,
|
|
69
160
|
topMatchScore: matches[0]?.score ?? null,
|
|
161
|
+
nodeCatalog: syncResult ? "synced" : "static",
|
|
162
|
+
nodeCount: syncResult?.nodeCount ?? null,
|
|
163
|
+
...syncResult ? {} : { syncWarning: "Could not sync node types from your n8n instance. Using static fallback catalog \u2014 generated workflows may not match your exact n8n setup." },
|
|
70
164
|
systemPrompt: systemText,
|
|
71
165
|
userMessage: built.userMessage,
|
|
72
166
|
outputFormat: {
|
|
@@ -246,6 +340,46 @@ server.tool(
|
|
|
246
340
|
};
|
|
247
341
|
}
|
|
248
342
|
);
|
|
343
|
+
server.tool(
|
|
344
|
+
"kairos_sync",
|
|
345
|
+
"Sync the node catalog from your live n8n instance. Fetches all installed node types and versions so Kairos knows exactly what your n8n supports. Automatically called by kairos_prompt when n8n credentials are set, but you can call this manually to force a refresh.",
|
|
346
|
+
{},
|
|
347
|
+
async () => {
|
|
348
|
+
const baseUrl = process.env["N8N_BASE_URL"];
|
|
349
|
+
const apiKey = process.env["N8N_API_KEY"];
|
|
350
|
+
if (!baseUrl || !apiKey) {
|
|
351
|
+
return {
|
|
352
|
+
content: [{
|
|
353
|
+
type: "text",
|
|
354
|
+
text: JSON.stringify({ error: "N8N_BASE_URL and N8N_API_KEY are required for sync." })
|
|
355
|
+
}],
|
|
356
|
+
isError: true
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
lastSync = null;
|
|
360
|
+
const result = await autoSync();
|
|
361
|
+
if (!result) {
|
|
362
|
+
return {
|
|
363
|
+
content: [{
|
|
364
|
+
type: "text",
|
|
365
|
+
text: JSON.stringify({ error: "Failed to fetch node types from n8n. Check your credentials and that your instance is running." })
|
|
366
|
+
}],
|
|
367
|
+
isError: true
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
content: [{
|
|
372
|
+
type: "text",
|
|
373
|
+
text: JSON.stringify({
|
|
374
|
+
synced: true,
|
|
375
|
+
nodeCount: result.nodeCount,
|
|
376
|
+
newNodes: result.newNodes,
|
|
377
|
+
message: `Synced ${result.nodeCount} node types from your n8n instance (${result.newNodes} not in default catalog).`
|
|
378
|
+
}, null, 2)
|
|
379
|
+
}]
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
);
|
|
249
383
|
server.tool(
|
|
250
384
|
"kairos_list",
|
|
251
385
|
"List all workflows deployed on the connected n8n instance.",
|
package/dist/mcp-server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mcp-server.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * Kairos MCP Server — decomposed architecture.\n *\n * The host LLM (Claude, GPT, Gemini, whatever) generates the workflow.\n * Kairos provides the knowledge (system prompt, library, failure patterns)\n * and guardrails (validator, deployer). Zero Anthropic API key needed.\n */\n\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'\nimport { z } from 'zod'\nimport { FileLibrary } from './library/file-library.js'\nimport { N8nValidator } from './validation/validator.js'\nimport { N8nFieldStripper } from './providers/n8n/stripper.js'\nimport { N8nApiClient } from './providers/n8n/api-client.js'\nimport { PromptBuilder } from './generation/prompt-builder.js'\nimport { TelemetryReader } from './telemetry/reader.js'\nimport { nullLogger } from './utils/logger.js'\nimport type { N8nWorkflow } from './types/workflow.js'\nimport { readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\nconst pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8')) as { version: string }\n\nconst library = new FileLibrary()\nconst validator = new N8nValidator()\nconst stripper = new N8nFieldStripper()\nconst promptBuilder = new PromptBuilder()\n\nfunction getTelemetryReader(): TelemetryReader | null {\n try {\n return new TelemetryReader()\n } catch {\n return null\n }\n}\n\nfunction isAllowed(action: 'deploy' | 'activate' | 'delete'): boolean {\n const key = `KAIROS_MCP_ALLOW_${action.toUpperCase()}`\n return process.env[key] === 'true'\n}\n\nfunction getApiClient(): N8nApiClient {\n const baseUrl = process.env['N8N_BASE_URL']\n const apiKey = process.env['N8N_API_KEY']\n if (!baseUrl || !apiKey) {\n throw new Error('N8N_BASE_URL and N8N_API_KEY environment variables are required for n8n operations')\n }\n return new N8nApiClient(baseUrl, apiKey, nullLogger)\n}\n\nconst server = new McpServer({\n name: 'kairos',\n version: pkg.version,\n})\n\n// ── Core generation tools (no API key needed) ──────────────────────────────\n\nserver.tool(\n 'kairos_prompt',\n 'Get the specialized n8n workflow generation context. Returns a system prompt with node catalog, connection rules, validation rules, plus library matches and failure patterns for the given description. Feed this to yourself as context, then generate the workflow JSON.',\n {\n description: z.string().describe('Plain-English description of the workflow to build'),\n name: z.string().optional().describe('Optional workflow name override'),\n },\n async ({ description, name }) => {\n await library.initialize()\n const matches = await library.search(description)\n const telemetryReader = getTelemetryReader()\n const failureRates = await telemetryReader?.getFailureRates() ?? []\n\n const request = { description, ...(name ? { name } : {}) }\n const built = promptBuilder.build(request, matches, failureRates)\n\n const systemText = built.system.map(block => block.text).join('\\n\\n---\\n\\n')\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n mode: built.mode,\n matchCount: matches.length,\n topMatchScore: matches[0]?.score ?? null,\n systemPrompt: systemText,\n userMessage: built.userMessage,\n outputFormat: {\n description: 'Generate a JSON object with this exact structure. The workflow field contains the n8n workflow. credentialsNeeded lists services requiring credentials.',\n schema: {\n workflow: {\n name: 'string — descriptive workflow name',\n nodes: 'array — n8n node objects with id (UUID v4), type, typeVersion, name, position, parameters',\n connections: 'object — keyed by source node NAME, maps to target nodes',\n settings: 'object — include executionOrder: \"v1\"',\n },\n credentialsNeeded: [{\n service: 'string — e.g. \"Slack\"',\n credentialType: 'string — e.g. \"slackOAuth2Api\"',\n description: 'string — what the user needs to set up',\n }],\n },\n },\n }, null, 2),\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_validate',\n 'Validate n8n workflow JSON against 23 structural rules. Returns pass/fail with specific issues. If validation fails, fix the issues and call this again. Errors block deployment; warnings are advisory.',\n {\n workflow: z.string().describe('The workflow JSON string to validate'),\n },\n async ({ workflow: workflowStr }) => {\n let parsed: N8nWorkflow\n try {\n parsed = JSON.parse(workflowStr) as N8nWorkflow\n } catch (e) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n valid: false,\n error: `Invalid JSON: ${e instanceof Error ? e.message : String(e)}`,\n }, null, 2),\n }],\n }\n }\n\n const result = validator.validate(parsed)\n const errors = result.issues.filter(i => i.severity === 'error')\n const warnings = result.issues.filter(i => i.severity === 'warn')\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n valid: result.valid,\n errorCount: errors.length,\n warningCount: warnings.length,\n errors: errors.map(i => ({\n rule: i.rule,\n message: i.message,\n nodeId: i.nodeId ?? null,\n })),\n warnings: warnings.map(i => ({\n rule: i.rule,\n message: i.message,\n nodeId: i.nodeId ?? null,\n })),\n deployable: errors.length === 0,\n }, null, 2),\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_deploy',\n 'Deploy a validated workflow to n8n. Pass the workflow JSON that passed kairos_validate. Strips server-assigned fields automatically. Requires N8N_BASE_URL and N8N_API_KEY.',\n {\n workflow: z.string().describe('The validated workflow JSON string to deploy'),\n activate: z.boolean().default(false).describe('Activate the workflow immediately after deployment'),\n },\n async ({ workflow: workflowStr, activate }) => {\n if (!isAllowed('deploy')) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({ error: 'Deploy is disabled. Set KAIROS_MCP_ALLOW_DEPLOY=true to enable.' }),\n }],\n isError: true,\n }\n }\n\n let parsed: N8nWorkflow\n try {\n parsed = JSON.parse(workflowStr) as N8nWorkflow\n } catch (e) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({ error: `Invalid JSON: ${e instanceof Error ? e.message : String(e)}` }),\n }],\n }\n }\n\n const validation = validator.validate(parsed)\n const errors = validation.issues.filter(i => i.severity === 'error')\n if (errors.length > 0) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n error: 'Workflow has validation errors — fix them before deploying',\n errors: errors.map(i => ({ rule: i.rule, message: i.message })),\n }, null, 2),\n }],\n }\n }\n\n const client = getApiClient()\n const stripped = stripper.stripForCreate(parsed)\n const response = await client.createWorkflow(stripped)\n\n if (activate) {\n if (!isAllowed('activate')) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n workflowId: response.id,\n name: response.name,\n activated: false,\n warning: 'Workflow deployed but activation is disabled. Set KAIROS_MCP_ALLOW_ACTIVATE=true to enable.',\n url: `${process.env['N8N_BASE_URL']}/workflow/${response.id}`,\n }, null, 2),\n }],\n }\n }\n await client.activateWorkflow(response.id)\n }\n\n // Save to library for future retrieval\n await library.initialize()\n await library.save(parsed, {\n description: parsed.name,\n generationMode: 'scratch',\n generationAttempts: 1,\n })\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n workflowId: response.id,\n name: response.name,\n activated: activate,\n url: `${process.env['N8N_BASE_URL']}/workflow/${response.id}`,\n }, null, 2),\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_search',\n 'Search the local workflow library for similar past builds. Returns matching workflows with scores, useful for finding examples and reusing patterns.',\n {\n query: z.string().describe('Search query — a workflow description or keywords'),\n limit: z.number().default(5).describe('Maximum number of results'),\n },\n async ({ query, limit }) => {\n await library.initialize()\n const matches = await library.search(query)\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify(\n matches.slice(0, limit).map(m => ({\n score: Number(m.score.toFixed(3)),\n mode: m.mode,\n description: m.workflow.description,\n nodeCount: m.workflow.workflow.nodes.length,\n nodes: m.workflow.workflow.nodes.map(n => n.name),\n failurePatterns: m.workflow.failurePatterns ?? [],\n })),\n null,\n 2,\n ),\n }],\n }\n },\n)\n\n// ── n8n management tools (need N8N_BASE_URL + N8N_API_KEY) ─────────────────\n\nserver.tool(\n 'kairos_list',\n 'List all workflows deployed on the connected n8n instance.',\n {},\n async () => {\n const client = getApiClient()\n const workflows = await client.listWorkflows()\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify(workflows, null, 2),\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_get',\n 'Get the full JSON definition of a specific workflow by ID.',\n {\n workflow_id: z.string().describe('The n8n workflow ID'),\n },\n async ({ workflow_id }) => {\n const client = getApiClient()\n const workflow = await client.getWorkflow(workflow_id)\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify(workflow, null, 2),\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_activate',\n 'Activate a deployed workflow so it starts running on triggers.',\n {\n workflow_id: z.string().describe('The n8n workflow ID to activate'),\n },\n async ({ workflow_id }) => {\n if (!isAllowed('activate')) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({ error: 'Activate is disabled. Set KAIROS_MCP_ALLOW_ACTIVATE=true to enable.' }),\n }],\n isError: true,\n }\n }\n\n const client = getApiClient()\n await client.activateWorkflow(workflow_id)\n\n return {\n content: [{\n type: 'text' as const,\n text: `Activated workflow ${workflow_id}`,\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_deactivate',\n 'Deactivate a running workflow.',\n {\n workflow_id: z.string().describe('The n8n workflow ID to deactivate'),\n },\n async ({ workflow_id }) => {\n const client = getApiClient()\n await client.deactivateWorkflow(workflow_id)\n\n return {\n content: [{\n type: 'text' as const,\n text: `Deactivated workflow ${workflow_id}`,\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_delete',\n 'Delete a workflow from n8n. This is irreversible.',\n {\n workflow_id: z.string().describe('The n8n workflow ID to delete'),\n },\n async ({ workflow_id }) => {\n if (!isAllowed('delete')) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({ error: 'Delete is disabled. Set KAIROS_MCP_ALLOW_DELETE=true to enable.' }),\n }],\n isError: true,\n }\n }\n\n const client = getApiClient()\n await client.deleteWorkflow(workflow_id)\n\n return {\n content: [{\n type: 'text' as const,\n text: `Deleted workflow ${workflow_id}`,\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_executions',\n 'List recent executions for a workflow, showing status and timing.',\n {\n workflow_id: z.string().optional().describe('Filter to a specific workflow ID (omit for all)'),\n limit: z.number().default(20).describe('Maximum number of executions to return'),\n },\n async ({ workflow_id, limit }) => {\n const client = getApiClient()\n const executions = await client.getExecutions(workflow_id, { limit })\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify(executions, null, 2),\n }],\n }\n },\n)\n\nasync function main() {\n const transport = new StdioServerTransport()\n await server.connect(transport)\n}\n\nmain().catch((err: unknown) => {\n console.error('Kairos MCP server failed to start:', err)\n process.exit(1)\n})\n"],"mappings":";;;;;;;;;;;;AAUA,SAAS,iBAAiB;AAC1B,SAAS,4BAA4B;AACrC,SAAS,SAAS;AASlB,SAAS,oBAAoB;AAC7B,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;AAE9B,IAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AACxD,IAAM,MAAM,KAAK,MAAM,aAAa,KAAK,WAAW,MAAM,cAAc,GAAG,OAAO,CAAC;AAEnF,IAAM,UAAU,IAAI,YAAY;AAChC,IAAM,YAAY,IAAI,aAAa;AACnC,IAAM,WAAW,IAAI,iBAAiB;AACtC,IAAM,gBAAgB,IAAI,cAAc;AAExC,SAAS,qBAA6C;AACpD,MAAI;AACF,WAAO,IAAI,gBAAgB;AAAA,EAC7B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,UAAU,QAAmD;AACpE,QAAM,MAAM,oBAAoB,OAAO,YAAY,CAAC;AACpD,SAAO,QAAQ,IAAI,GAAG,MAAM;AAC9B;AAEA,SAAS,eAA6B;AACpC,QAAM,UAAU,QAAQ,IAAI,cAAc;AAC1C,QAAM,SAAS,QAAQ,IAAI,aAAa;AACxC,MAAI,CAAC,WAAW,CAAC,QAAQ;AACvB,UAAM,IAAI,MAAM,oFAAoF;AAAA,EACtG;AACA,SAAO,IAAI,aAAa,SAAS,QAAQ,UAAU;AACrD;AAEA,IAAM,SAAS,IAAI,UAAU;AAAA,EAC3B,MAAM;AA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E,MAAM,CAAC;AAEpE,WAAO;AAAA,MACL,SAAS,CAAC;AAAA,QACR,MAAM;AAAA,QACN,MAAM,KAAK,UAAU,YAAY,MAAM,CAAC;AAAA,MAC1C,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,eAAe,OAAO;AACpB,QAAM,YAAY,IAAI,qBAAqB;AAC3C,QAAM,OAAO,QAAQ,SAAS;AAChC;AAEA,KAAK,EAAE,MAAM,CAAC,QAAiB;AAC7B,UAAQ,MAAM,sCAAsC,GAAG;AACvD,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/mcp-server.ts","../src/validation/node-syncer.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * Kairos MCP Server — decomposed architecture.\n *\n * The host LLM (Claude, GPT, Gemini, whatever) generates the workflow.\n * Kairos provides the knowledge (system prompt, library, failure patterns)\n * and guardrails (validator, deployer). Zero Anthropic API key needed.\n */\n\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'\nimport { z } from 'zod'\nimport { FileLibrary } from './library/file-library.js'\nimport { N8nValidator } from './validation/validator.js'\nimport { N8nFieldStripper } from './providers/n8n/stripper.js'\nimport { N8nApiClient } from './providers/n8n/api-client.js'\nimport { PromptBuilder } from './generation/prompt-builder.js'\nimport { TelemetryReader } from './telemetry/reader.js'\nimport { NodeSyncer, type SyncResult } from './validation/node-syncer.js'\nimport { nullLogger } from './utils/logger.js'\nimport type { N8nWorkflow } from './types/workflow.js'\nimport { readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\nconst pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8')) as { version: string }\n\nconst library = new FileLibrary()\nlet validator = new N8nValidator()\nconst nodeSyncer = new NodeSyncer()\nlet lastSync: SyncResult | null = null\nconst stripper = new N8nFieldStripper()\nconst promptBuilder = new PromptBuilder()\n\nfunction getTelemetryReader(): TelemetryReader | null {\n try {\n return new TelemetryReader()\n } catch {\n return null\n }\n}\n\nfunction isAllowed(action: 'deploy' | 'activate' | 'delete'): boolean {\n const key = `KAIROS_MCP_ALLOW_${action.toUpperCase()}`\n return process.env[key] === 'true'\n}\n\nfunction getApiClient(): N8nApiClient {\n const baseUrl = process.env['N8N_BASE_URL']\n const apiKey = process.env['N8N_API_KEY']\n if (!baseUrl || !apiKey) {\n throw new Error('N8N_BASE_URL and N8N_API_KEY environment variables are required for n8n operations')\n }\n return new N8nApiClient(baseUrl, apiKey, nullLogger)\n}\n\nasync function autoSync(): Promise<SyncResult | null> {\n if (lastSync) return lastSync\n const baseUrl = process.env['N8N_BASE_URL']\n const apiKey = process.env['N8N_API_KEY']\n if (!baseUrl || !apiKey) return null\n try {\n const client = new N8nApiClient(baseUrl, apiKey, nullLogger)\n const nodeTypes = await client.getNodeTypes()\n if (nodeTypes.length === 0) return null\n lastSync = nodeSyncer.sync(nodeTypes)\n validator = new N8nValidator(lastSync.registry)\n return lastSync\n } catch {\n return null\n }\n}\n\nconst server = new McpServer({\n name: 'kairos',\n version: pkg.version,\n})\n\n// ── Core generation tools (no API key needed) ──────────────────────────────\n\nserver.tool(\n 'kairos_prompt',\n 'Get the specialized n8n workflow generation context. Returns a system prompt with node catalog, connection rules, validation rules, plus library matches and failure patterns for the given description. Feed this to yourself as context, then generate the workflow JSON.',\n {\n description: z.string().describe('Plain-English description of the workflow to build'),\n name: z.string().optional().describe('Optional workflow name override'),\n },\n async ({ description, name }) => {\n const baseUrl = process.env['N8N_BASE_URL']\n const apiKey = process.env['N8N_API_KEY']\n if (!baseUrl || !apiKey) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({ error: 'N8N_BASE_URL and N8N_API_KEY are required. Kairos needs to sync your n8n instance\\'s node types to generate accurate workflows.' }),\n }],\n isError: true,\n }\n }\n\n await library.initialize()\n const syncResult = await autoSync()\n const matches = await library.search(description)\n const telemetryReader = getTelemetryReader()\n const failureRates = await telemetryReader?.getFailureRates() ?? []\n\n const request = { description, ...(name ? { name } : {}) }\n const built = promptBuilder.build(request, matches, failureRates, syncResult?.catalogText)\n\n const systemText = built.system.map(block => block.text).join('\\n\\n---\\n\\n')\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n mode: built.mode,\n matchCount: matches.length,\n topMatchScore: matches[0]?.score ?? null,\n nodeCatalog: syncResult ? 'synced' : 'static',\n nodeCount: syncResult?.nodeCount ?? null,\n ...(syncResult ? {} : { syncWarning: 'Could not sync node types from your n8n instance. Using static fallback catalog — generated workflows may not match your exact n8n setup.' }),\n systemPrompt: systemText,\n userMessage: built.userMessage,\n outputFormat: {\n description: 'Generate a JSON object with this exact structure. The workflow field contains the n8n workflow. credentialsNeeded lists services requiring credentials.',\n schema: {\n workflow: {\n name: 'string — descriptive workflow name',\n nodes: 'array — n8n node objects with id (UUID v4), type, typeVersion, name, position, parameters',\n connections: 'object — keyed by source node NAME, maps to target nodes',\n settings: 'object — include executionOrder: \"v1\"',\n },\n credentialsNeeded: [{\n service: 'string — e.g. \"Slack\"',\n credentialType: 'string — e.g. \"slackOAuth2Api\"',\n description: 'string — what the user needs to set up',\n }],\n },\n },\n }, null, 2),\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_validate',\n 'Validate n8n workflow JSON against 23 structural rules. Returns pass/fail with specific issues. If validation fails, fix the issues and call this again. Errors block deployment; warnings are advisory.',\n {\n workflow: z.string().describe('The workflow JSON string to validate'),\n },\n async ({ workflow: workflowStr }) => {\n let parsed: N8nWorkflow\n try {\n parsed = JSON.parse(workflowStr) as N8nWorkflow\n } catch (e) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n valid: false,\n error: `Invalid JSON: ${e instanceof Error ? e.message : String(e)}`,\n }, null, 2),\n }],\n }\n }\n\n const result = validator.validate(parsed)\n const errors = result.issues.filter(i => i.severity === 'error')\n const warnings = result.issues.filter(i => i.severity === 'warn')\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n valid: result.valid,\n errorCount: errors.length,\n warningCount: warnings.length,\n errors: errors.map(i => ({\n rule: i.rule,\n message: i.message,\n nodeId: i.nodeId ?? null,\n })),\n warnings: warnings.map(i => ({\n rule: i.rule,\n message: i.message,\n nodeId: i.nodeId ?? null,\n })),\n deployable: errors.length === 0,\n }, null, 2),\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_deploy',\n 'Deploy a validated workflow to n8n. Pass the workflow JSON that passed kairos_validate. Strips server-assigned fields automatically. Requires N8N_BASE_URL and N8N_API_KEY.',\n {\n workflow: z.string().describe('The validated workflow JSON string to deploy'),\n activate: z.boolean().default(false).describe('Activate the workflow immediately after deployment'),\n },\n async ({ workflow: workflowStr, activate }) => {\n if (!isAllowed('deploy')) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({ error: 'Deploy is disabled. Set KAIROS_MCP_ALLOW_DEPLOY=true to enable.' }),\n }],\n isError: true,\n }\n }\n\n let parsed: N8nWorkflow\n try {\n parsed = JSON.parse(workflowStr) as N8nWorkflow\n } catch (e) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({ error: `Invalid JSON: ${e instanceof Error ? e.message : String(e)}` }),\n }],\n }\n }\n\n const validation = validator.validate(parsed)\n const errors = validation.issues.filter(i => i.severity === 'error')\n if (errors.length > 0) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n error: 'Workflow has validation errors — fix them before deploying',\n errors: errors.map(i => ({ rule: i.rule, message: i.message })),\n }, null, 2),\n }],\n }\n }\n\n const client = getApiClient()\n const stripped = stripper.stripForCreate(parsed)\n const response = await client.createWorkflow(stripped)\n\n if (activate) {\n if (!isAllowed('activate')) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n workflowId: response.id,\n name: response.name,\n activated: false,\n warning: 'Workflow deployed but activation is disabled. Set KAIROS_MCP_ALLOW_ACTIVATE=true to enable.',\n url: `${process.env['N8N_BASE_URL']}/workflow/${response.id}`,\n }, null, 2),\n }],\n }\n }\n await client.activateWorkflow(response.id)\n }\n\n // Save to library for future retrieval\n await library.initialize()\n await library.save(parsed, {\n description: parsed.name,\n generationMode: 'scratch',\n generationAttempts: 1,\n })\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n workflowId: response.id,\n name: response.name,\n activated: activate,\n url: `${process.env['N8N_BASE_URL']}/workflow/${response.id}`,\n }, null, 2),\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_search',\n 'Search the local workflow library for similar past builds. Returns matching workflows with scores, useful for finding examples and reusing patterns.',\n {\n query: z.string().describe('Search query — a workflow description or keywords'),\n limit: z.number().default(5).describe('Maximum number of results'),\n },\n async ({ query, limit }) => {\n await library.initialize()\n const matches = await library.search(query)\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify(\n matches.slice(0, limit).map(m => ({\n score: Number(m.score.toFixed(3)),\n mode: m.mode,\n description: m.workflow.description,\n nodeCount: m.workflow.workflow.nodes.length,\n nodes: m.workflow.workflow.nodes.map(n => n.name),\n failurePatterns: m.workflow.failurePatterns ?? [],\n })),\n null,\n 2,\n ),\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_sync',\n 'Sync the node catalog from your live n8n instance. Fetches all installed node types and versions so Kairos knows exactly what your n8n supports. Automatically called by kairos_prompt when n8n credentials are set, but you can call this manually to force a refresh.',\n {},\n async () => {\n const baseUrl = process.env['N8N_BASE_URL']\n const apiKey = process.env['N8N_API_KEY']\n if (!baseUrl || !apiKey) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({ error: 'N8N_BASE_URL and N8N_API_KEY are required for sync.' }),\n }],\n isError: true,\n }\n }\n\n lastSync = null\n const result = await autoSync()\n if (!result) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({ error: 'Failed to fetch node types from n8n. Check your credentials and that your instance is running.' }),\n }],\n isError: true,\n }\n }\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n synced: true,\n nodeCount: result.nodeCount,\n newNodes: result.newNodes,\n message: `Synced ${result.nodeCount} node types from your n8n instance (${result.newNodes} not in default catalog).`,\n }, null, 2),\n }],\n }\n },\n)\n\n// ── n8n management tools (need N8N_BASE_URL + N8N_API_KEY) ─────────────────\n\nserver.tool(\n 'kairos_list',\n 'List all workflows deployed on the connected n8n instance.',\n {},\n async () => {\n const client = getApiClient()\n const workflows = await client.listWorkflows()\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify(workflows, null, 2),\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_get',\n 'Get the full JSON definition of a specific workflow by ID.',\n {\n workflow_id: z.string().describe('The n8n workflow ID'),\n },\n async ({ workflow_id }) => {\n const client = getApiClient()\n const workflow = await client.getWorkflow(workflow_id)\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify(workflow, null, 2),\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_activate',\n 'Activate a deployed workflow so it starts running on triggers.',\n {\n workflow_id: z.string().describe('The n8n workflow ID to activate'),\n },\n async ({ workflow_id }) => {\n if (!isAllowed('activate')) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({ error: 'Activate is disabled. Set KAIROS_MCP_ALLOW_ACTIVATE=true to enable.' }),\n }],\n isError: true,\n }\n }\n\n const client = getApiClient()\n await client.activateWorkflow(workflow_id)\n\n return {\n content: [{\n type: 'text' as const,\n text: `Activated workflow ${workflow_id}`,\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_deactivate',\n 'Deactivate a running workflow.',\n {\n workflow_id: z.string().describe('The n8n workflow ID to deactivate'),\n },\n async ({ workflow_id }) => {\n const client = getApiClient()\n await client.deactivateWorkflow(workflow_id)\n\n return {\n content: [{\n type: 'text' as const,\n text: `Deactivated workflow ${workflow_id}`,\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_delete',\n 'Delete a workflow from n8n. This is irreversible.',\n {\n workflow_id: z.string().describe('The n8n workflow ID to delete'),\n },\n async ({ workflow_id }) => {\n if (!isAllowed('delete')) {\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({ error: 'Delete is disabled. Set KAIROS_MCP_ALLOW_DELETE=true to enable.' }),\n }],\n isError: true,\n }\n }\n\n const client = getApiClient()\n await client.deleteWorkflow(workflow_id)\n\n return {\n content: [{\n type: 'text' as const,\n text: `Deleted workflow ${workflow_id}`,\n }],\n }\n },\n)\n\nserver.tool(\n 'kairos_executions',\n 'List recent executions for a workflow, showing status and timing.',\n {\n workflow_id: z.string().optional().describe('Filter to a specific workflow ID (omit for all)'),\n limit: z.number().default(20).describe('Maximum number of executions to return'),\n },\n async ({ workflow_id, limit }) => {\n const client = getApiClient()\n const executions = await client.getExecutions(workflow_id, { limit })\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify(executions, null, 2),\n }],\n }\n },\n)\n\nasync function main() {\n const transport = new StdioServerTransport()\n await server.connect(transport)\n}\n\nmain().catch((err: unknown) => {\n console.error('Kairos MCP server failed to start:', err)\n process.exit(1)\n})\n","import type { N8nNodeTypeInfo } from '../providers/n8n/types.js'\nimport type { NodeDefinition } from './registry.js'\nimport { NodeRegistry, DEFAULT_REGISTRY } from './registry.js'\n\nconst TRIGGER_PATTERNS = [/trigger/i, /Trigger$/]\n\nexport interface SyncResult {\n registry: NodeRegistry\n catalogText: string\n nodeCount: number\n newNodes: number\n}\n\nexport class NodeSyncer {\n private readonly baseRegistry: Map<string, NodeDefinition>\n\n constructor() {\n this.baseRegistry = new Map(DEFAULT_REGISTRY.map(d => [d.type, d]))\n }\n\n sync(liveNodes: N8nNodeTypeInfo[]): SyncResult {\n const merged = new Map(this.baseRegistry)\n let newNodes = 0\n\n for (const node of liveNodes) {\n const versions = Array.isArray(node.version) ? node.version : [node.version]\n const isTrigger = TRIGGER_PATTERNS.some(p => p.test(node.name))\n const credentialType = node.credentials?.[0]?.name\n\n const existing = merged.get(node.name)\n if (existing) {\n const allVersions = new Set([...existing.safeTypeVersions, ...versions])\n merged.set(node.name, {\n ...existing,\n safeTypeVersions: [...allVersions].sort((a, b) => a - b),\n })\n } else {\n newNodes++\n merged.set(node.name, {\n type: node.name,\n safeTypeVersions: versions.sort((a, b) => a - b),\n requiredParams: [],\n ...(credentialType ? { credentialType } : {}),\n ...(isTrigger ? { isTrigger: true } : {}),\n })\n }\n }\n\n const definitions = [...merged.values()]\n const registry = new NodeRegistry(definitions)\n const catalogText = this.buildCatalog(definitions)\n\n return { registry, catalogText, nodeCount: definitions.length, newNodes }\n }\n\n private buildCatalog(definitions: NodeDefinition[]): string {\n const triggers = definitions.filter(d => d.isTrigger)\n const regular = definitions.filter(d => !d.isTrigger)\n\n const formatEntry = (d: NodeDefinition): string => {\n const versions = d.safeTypeVersions.join(', ')\n const cred = d.credentialType ? ` — cred: ${d.credentialType}` : ''\n return `${d.type} typeVersion: ${versions}${cred}`\n }\n\n const triggerLines = triggers.map(formatEntry).join('\\n')\n const regularLines = regular.map(formatEntry).join('\\n')\n\n return `## NODE CATALOG — synced from your n8n instance (${definitions.length} node types)\n\n### Triggers:\n${triggerLines}\n\n### Regular nodes:\n${regularLines}`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAUA,SAAS,iBAAiB;AAC1B,SAAS,4BAA4B;AACrC,SAAS,SAAS;;;ACRlB,IAAM,mBAAmB,CAAC,YAAY,UAAU;AASzC,IAAM,aAAN,MAAiB;AAAA,EACL;AAAA,EAEjB,cAAc;AACZ,SAAK,eAAe,IAAI,IAAI,iBAAiB,IAAI,OAAK,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAAA,EACpE;AAAA,EAEA,KAAK,WAA0C;AAC7C,UAAM,SAAS,IAAI,IAAI,KAAK,YAAY;AACxC,QAAI,WAAW;AAEf,eAAW,QAAQ,WAAW;AAC5B,YAAM,WAAW,MAAM,QAAQ,KAAK,OAAO,IAAI,KAAK,UAAU,CAAC,KA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oB,WAAW;AAAA,MACvC,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,OAAO;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,IACE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,iDAAiD;AAAA,IAC7F,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,SAAS,wCAAwC;AAAA,EACjF;AAAA,EACA,OAAO,EAAE,aAAa,MAAM,MAAM;AAChC,UAAM,SAAS,aAAa;AAC5B,UAAM,aAAa,MAAM,OAAO,cAAc,aAAa,EAAE,MAAM,CAAC;AAEpE,WAAO;AAAA,MACL,SAAS,CAAC;AAAA,QACR,MAAM;AAAA,QACN,MAAM,KAAK,UAAU,YAAY,MAAM,CAAC;AAAA,MAC1C,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,eAAe,OAAO;AACpB,QAAM,YAAY,IAAI,qBAAqB;AAC3C,QAAM,OAAO,QAAQ,SAAS;AAChC;AAEA,KAAK,EAAE,MAAM,CAAC,QAAiB;AAC7B,UAAQ,MAAM,sCAAsC,GAAG;AACvD,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors/base.ts","../src/errors/api-error.ts","../src/errors/provider-error.ts","../src/utils/retry.ts","../src/providers/n8n/api-client.ts","../src/providers/n8n/types.ts","../src/providers/n8n/stripper.ts","../src/validation/registry.ts","../src/validation/validator.ts","../src/generation/prompts/v1.ts","../src/utils/thresholds.ts","../src/generation/prompt-builder.ts","../src/telemetry/reader.ts","../src/utils/logger.ts","../src/library/scorer.ts","../src/library/cluster.ts","../src/library/file-library.ts","../src/utils/uuid.ts"],"sourcesContent":["export class KairosError extends Error {\n constructor(message: string, public readonly cause?: unknown) {\n super(message)\n this.name = 'KairosError'\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor)\n }\n }\n}\n","import { KairosError } from './base.js'\n\nexport class ApiError extends KairosError {\n constructor(\n message: string,\n public readonly statusCode: number,\n cause?: unknown,\n ) {\n super(message, cause)\n this.name = 'ApiError'\n }\n}\n","import { KairosError } from './base.js'\n\nexport class ProviderError extends KairosError {\n constructor(message: string, cause?: unknown) {\n super(message, cause)\n this.name = 'ProviderError'\n }\n}\n","export async function withRetry<T>(\n fn: () => Promise<T>,\n maxAttempts: number,\n delayMs: number,\n shouldRetry?: (err: unknown) => boolean,\n): Promise<T> {\n let lastError: unknown\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n if (attempt > 0) {\n const jitter = Math.random() * delayMs * 0.5\n await new Promise((resolve) => setTimeout(resolve, delayMs * 2 ** (attempt - 1) + jitter))\n }\n try {\n return await fn()\n } catch (err) {\n lastError = err\n if (shouldRetry && !shouldRetry(err)) throw err\n }\n }\n throw lastError\n}\n\nexport function fetchWithTimeout(url: string, init: RequestInit, timeoutMs: number): Promise<Response> {\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), timeoutMs)\n return fetch(url, { ...init, signal: controller.signal }).finally(() => clearTimeout(timer))\n}\n","import type { N8nWorkflow, Tag } from '../../types/workflow.js'\nimport type { WorkflowListItem, ExecutionSummary, ExecutionDetail } from '../../types/result.js'\nimport type { ExecutionFilter } from '../../types/options.js'\nimport type { ILogger } from '../../utils/logger.js'\nimport { ApiError } from '../../errors/api-error.js'\nimport { ProviderError } from '../../errors/provider-error.js'\nimport { withRetry, fetchWithTimeout } from '../../utils/retry.js'\nimport type {\n N8nWorkflowResponse,\n N8nWorkflowListResponse,\n N8nExecutionResponse,\n N8nExecutionListResponse,\n N8nTagResponse,\n N8nTagListResponse,\n} from './types.js'\n\nconst EXECUTION_LIMIT_CAP = 100\nconst REQUEST_TIMEOUT_MS = 30_000\nconst RETRY_ATTEMPTS = 3\nconst RETRY_DELAY_MS = 1000\n\nexport class N8nApiClient {\n constructor(\n private readonly baseUrl: string,\n private readonly apiKey: string,\n private readonly logger: ILogger,\n ) {}\n\n private async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const url = `${this.baseUrl.replace(/\\/$/, '')}/api/v1${path}`\n this.logger.debug(`n8n ${method} ${path}`)\n\n const isSafe = method === 'GET'\n if (!isSafe) {\n return this.singleRequest<T>(url, method, path, body)\n }\n\n return withRetry(\n () => this.singleRequest<T>(url, method, path, body),\n RETRY_ATTEMPTS,\n RETRY_DELAY_MS,\n (err) => err instanceof ProviderError || (err instanceof ApiError && err.statusCode === 429),\n )\n }\n\n private async singleRequest<T>(url: string, method: string, path: string, body?: unknown): Promise<T> {\n let response: Response\n try {\n response = await fetchWithTimeout(url, {\n method,\n headers: {\n 'X-N8N-API-KEY': this.apiKey,\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n },\n ...(body !== undefined ? { body: JSON.stringify(body) } : {}),\n }, REQUEST_TIMEOUT_MS)\n } catch (err) {\n throw new ProviderError(`Network error calling n8n API: ${path}`, err)\n }\n\n if (!response.ok) {\n let errorBody: unknown\n try {\n errorBody = await response.json()\n } catch {\n errorBody = await response.text().catch(() => '')\n }\n this.logger.error(`n8n API error ${response.status} on ${method} ${path}`, {\n status: response.status,\n body: String(errorBody),\n })\n throw new ApiError(\n `n8n API returned ${response.status} for ${method} ${path}: ${JSON.stringify(errorBody)}`,\n response.status,\n errorBody,\n )\n }\n\n if (response.status === 204) return undefined as T\n return response.json() as Promise<T>\n }\n\n async createWorkflow(workflow: N8nWorkflow): Promise<N8nWorkflowResponse> {\n return this.request<N8nWorkflowResponse>('POST', '/workflows', workflow)\n }\n\n async updateWorkflow(id: string, workflow: N8nWorkflow): Promise<N8nWorkflowResponse> {\n return this.request<N8nWorkflowResponse>('PUT', `/workflows/${id}`, workflow)\n }\n\n async getWorkflow(id: string): Promise<N8nWorkflowResponse> {\n return this.request<N8nWorkflowResponse>('GET', `/workflows/${id}`)\n }\n\n async listWorkflows(): Promise<WorkflowListItem[]> {\n const all: WorkflowListItem[] = []\n let path = '/workflows?limit=250'\n\n for (;;) {\n const response: N8nWorkflowListResponse = await this.request<N8nWorkflowListResponse>('GET', path)\n for (const w of response.data) {\n all.push({\n id: w.id,\n name: w.name,\n active: w.active,\n createdAt: w.createdAt,\n updatedAt: w.updatedAt,\n ...(w.tags !== undefined ? { tags: w.tags } : {}),\n })\n }\n if (!response.nextCursor) break\n path = `/workflows?limit=250&cursor=${response.nextCursor}`\n }\n\n return all\n }\n\n async deleteWorkflow(id: string): Promise<void> {\n await this.request<void>('DELETE', `/workflows/${id}`)\n }\n\n async activateWorkflow(id: string): Promise<void> {\n await this.request<void>('POST', `/workflows/${id}/activate`)\n }\n\n async deactivateWorkflow(id: string): Promise<void> {\n await this.request<void>('POST', `/workflows/${id}/deactivate`)\n }\n\n async getExecutions(workflowId?: string, filter?: ExecutionFilter): Promise<ExecutionSummary[]> {\n const params = new URLSearchParams()\n if (workflowId) params.set('workflowId', workflowId)\n if (filter?.status) params.set('status', filter.status)\n const limit = Math.min(filter?.limit ?? 20, EXECUTION_LIMIT_CAP)\n params.set('limit', String(limit))\n if (filter?.cursor) params.set('cursor', filter.cursor)\n\n const qs = params.toString()\n const response = await this.request<N8nExecutionListResponse>('GET', `/executions${qs ? `?${qs}` : ''}`)\n return response.data.map(this.mapExecution)\n }\n\n async getExecution(id: string): Promise<ExecutionDetail> {\n const response = await this.request<N8nExecutionResponse>('GET', `/executions/${id}`)\n return { ...this.mapExecution(response), data: response.data, workflowData: response.workflowData }\n }\n\n async listTags(): Promise<Tag[]> {\n const all: Tag[] = []\n let path = '/tags?limit=250'\n\n for (;;) {\n const response: N8nTagListResponse = await this.request<N8nTagListResponse>('GET', path)\n for (const t of response.data) {\n all.push({ id: t.id, name: t.name })\n }\n if (!response.nextCursor) break\n path = `/tags?limit=250&cursor=${response.nextCursor}`\n }\n\n return all\n }\n\n async createTag(name: string): Promise<Tag> {\n const response = await this.request<N8nTagResponse>('POST', '/tags', { name })\n return { id: response.id, name: response.name }\n }\n\n async tagWorkflow(workflowId: string, tagIds: string[]): Promise<void> {\n await this.request<void>('PUT', `/workflows/${workflowId}/tags`, tagIds.map((id) => ({ id })))\n }\n\n async untagWorkflow(workflowId: string, tagIds: string[]): Promise<void> {\n const current = await this.getWorkflow(workflowId)\n const remaining = (current.tags ?? [])\n .filter((t) => !tagIds.includes(t.id))\n .map((t) => ({ id: t.id }))\n await this.request<void>('PUT', `/workflows/${workflowId}/tags`, remaining)\n }\n\n private mapExecution(e: N8nExecutionResponse): ExecutionSummary {\n return {\n id: e.id,\n workflowId: e.workflowId,\n status: e.status,\n startedAt: e.startedAt,\n ...(e.stoppedAt !== undefined ? { stoppedAt: e.stoppedAt } : {}),\n mode: e.mode,\n }\n }\n}\n","import type { N8nNode, N8nConnections, N8nSettings, Tag } from '../../types/workflow.js'\n\nexport interface N8nWorkflowResponse {\n id: string\n name: string\n active: boolean\n nodes: N8nNode[]\n connections: N8nConnections\n settings?: N8nSettings\n tags?: Tag[]\n createdAt: string\n updatedAt: string\n versionId?: string\n meta?: Record<string, unknown>\n pinData?: Record<string, unknown>\n staticData?: unknown\n triggerCount?: number\n shared?: boolean\n isArchived?: boolean\n}\n\nexport interface N8nWorkflowListResponse {\n data: N8nWorkflowResponse[]\n nextCursor: string | null\n}\n\nexport interface N8nExecutionResponse {\n id: string\n workflowId: string\n status: 'success' | 'error' | 'waiting' | 'running' | 'canceled'\n startedAt: string\n stoppedAt?: string\n mode: string\n data?: unknown\n workflowData?: unknown\n}\n\nexport interface N8nExecutionListResponse {\n data: N8nExecutionResponse[]\n nextCursor: string | null\n}\n\nexport interface N8nTagResponse {\n id: string\n name: string\n createdAt?: string\n updatedAt?: string\n}\n\nexport interface N8nTagListResponse {\n data: N8nTagResponse[]\n nextCursor: string | null\n}\n\nexport const FORBIDDEN_ON_CREATE = [\n 'id',\n 'createdAt',\n 'updatedAt',\n 'versionId',\n 'meta',\n 'isArchived',\n 'activeVersionId',\n 'activeVersion',\n 'active',\n 'pinData',\n 'triggerCount',\n 'shared',\n 'staticData',\n] as const\n\nexport const FORBIDDEN_ON_UPDATE = FORBIDDEN_ON_CREATE.filter((f) => f !== 'id')\n\nexport type ForbiddenField = (typeof FORBIDDEN_ON_CREATE)[number]\n","import type { N8nWorkflow } from '../../types/workflow.js'\nimport { FORBIDDEN_ON_CREATE, FORBIDDEN_ON_UPDATE } from './types.js'\n\nexport class N8nFieldStripper {\n stripForCreate(workflow: N8nWorkflow): N8nWorkflow {\n return this.strip(workflow, FORBIDDEN_ON_CREATE as readonly string[])\n }\n\n stripForUpdate(workflow: N8nWorkflow): N8nWorkflow {\n return this.strip(workflow, FORBIDDEN_ON_UPDATE as readonly string[])\n }\n\n private strip(workflow: N8nWorkflow, forbidden: readonly string[]): N8nWorkflow {\n const result = { ...workflow } as unknown as Record<string, unknown>\n for (const field of forbidden) {\n delete result[field]\n }\n return result as unknown as N8nWorkflow\n }\n}\n","export interface NodeDefinition {\n type: string\n safeTypeVersions: number[]\n requiredParams: string[]\n credentialType?: string\n isTrigger?: boolean\n}\n\nexport const DEFAULT_REGISTRY: NodeDefinition[] = [\n // Trigger nodes\n { type: 'n8n-nodes-base.manualTrigger', safeTypeVersions: [1], requiredParams: [], isTrigger: true },\n { type: 'n8n-nodes-base.scheduleTrigger', safeTypeVersions: [1, 1.1, 1.2], requiredParams: [], isTrigger: true },\n { type: 'n8n-nodes-base.webhook', safeTypeVersions: [1, 1.1, 2], requiredParams: ['httpMethod', 'path'], isTrigger: true },\n { type: 'n8n-nodes-base.formTrigger', safeTypeVersions: [1, 2, 2.1, 2.2], requiredParams: [], isTrigger: true },\n { type: 'n8n-nodes-base.emailReadImap', safeTypeVersions: [2], requiredParams: [], credentialType: 'imap', isTrigger: true },\n { type: 'n8n-nodes-base.errorTrigger', safeTypeVersions: [1], requiredParams: [], isTrigger: true },\n { type: 'n8n-nodes-base.executeWorkflowTrigger', safeTypeVersions: [1, 1.1], requiredParams: [], isTrigger: true },\n { type: 'n8n-nodes-base.gmailTrigger', safeTypeVersions: [1, 1.1, 1.2], requiredParams: [], credentialType: 'gmailOAuth2', isTrigger: true },\n { type: 'n8n-nodes-base.googleDriveTrigger', safeTypeVersions: [1], requiredParams: [], credentialType: 'googleDriveOAuth2Api', isTrigger: true },\n { type: 'n8n-nodes-base.googleSheetsTrigger', safeTypeVersions: [1], requiredParams: [], credentialType: 'googleSheetsTriggerOAuth2Api', isTrigger: true },\n { type: 'n8n-nodes-base.slackTrigger', safeTypeVersions: [1], requiredParams: [], credentialType: 'slackApi', isTrigger: true },\n { type: 'n8n-nodes-base.telegramTrigger', safeTypeVersions: [1, 1.1, 1.2], requiredParams: [], credentialType: 'telegramApi', isTrigger: true },\n { type: 'n8n-nodes-base.githubTrigger', safeTypeVersions: [1], requiredParams: [], credentialType: 'githubApi', isTrigger: true },\n { type: 'n8n-nodes-base.stripeTrigger', safeTypeVersions: [1], requiredParams: [], credentialType: 'stripeApi', isTrigger: true },\n { type: 'n8n-nodes-base.airtableTrigger', safeTypeVersions: [1], requiredParams: [], credentialType: 'airtableTokenApi', isTrigger: true },\n { type: 'n8n-nodes-base.notionTrigger', safeTypeVersions: [1], requiredParams: [], credentialType: 'notionApi', isTrigger: true },\n { type: '@n8n/n8n-nodes-langchain.chatTrigger', safeTypeVersions: [1, 1.1], requiredParams: [], isTrigger: true },\n\n // Core logic nodes\n { type: 'n8n-nodes-base.code', safeTypeVersions: [1, 2], requiredParams: [] },\n { type: 'n8n-nodes-base.httpRequest', safeTypeVersions: [1, 2, 3, 4, 4.1, 4.2], requiredParams: ['url'] },\n { type: 'n8n-nodes-base.set', safeTypeVersions: [1, 2, 3, 3.1, 3.2, 3.3, 3.4], requiredParams: [] },\n { type: 'n8n-nodes-base.if', safeTypeVersions: [1, 2, 2.1, 2.2], requiredParams: [] },\n { type: 'n8n-nodes-base.switch', safeTypeVersions: [1, 2, 3, 3.1, 3.2], requiredParams: [] },\n { type: 'n8n-nodes-base.filter', safeTypeVersions: [1, 2, 2.1, 2.2], requiredParams: [] },\n { type: 'n8n-nodes-base.merge', safeTypeVersions: [1, 2, 2.1, 3], requiredParams: [] },\n { type: 'n8n-nodes-base.splitInBatches', safeTypeVersions: [1, 2, 3], requiredParams: [] },\n { type: 'n8n-nodes-base.wait', safeTypeVersions: [1, 1.1], requiredParams: [] },\n { type: 'n8n-nodes-base.executeWorkflow', safeTypeVersions: [1, 1.1, 1.2], requiredParams: [] },\n { type: 'n8n-nodes-base.respondToWebhook', safeTypeVersions: [1, 1.1], requiredParams: [] },\n { type: 'n8n-nodes-base.noOp', safeTypeVersions: [1], requiredParams: [] },\n { type: 'n8n-nodes-base.stopAndError', safeTypeVersions: [1], requiredParams: [] },\n { type: 'n8n-nodes-base.splitOut', safeTypeVersions: [1], requiredParams: [] },\n { type: 'n8n-nodes-base.aggregate', safeTypeVersions: [1], requiredParams: [] },\n { type: 'n8n-nodes-base.stickyNote', safeTypeVersions: [1], requiredParams: [] },\n\n // Email / messaging\n { type: 'n8n-nodes-base.emailSend', safeTypeVersions: [1, 2, 2.1], requiredParams: [], credentialType: 'smtp' },\n { type: 'n8n-nodes-base.slack', safeTypeVersions: [1, 2, 2.1, 2.2], requiredParams: [], credentialType: 'slackOAuth2Api' },\n { type: 'n8n-nodes-base.telegram', safeTypeVersions: [1, 1.1, 1.2], requiredParams: [], credentialType: 'telegramApi' },\n { type: 'n8n-nodes-base.discord', safeTypeVersions: [1, 2], requiredParams: [], credentialType: 'discordWebhookApi' },\n\n // Google\n { type: 'n8n-nodes-base.gmail', safeTypeVersions: [1, 2, 2.1], requiredParams: [], credentialType: 'gmailOAuth2' },\n { type: 'n8n-nodes-base.googleSheets', safeTypeVersions: [1, 2, 3, 4, 4.1, 4.2, 4.3, 4.4, 4.5], requiredParams: [], credentialType: 'googleSheetsOAuth2Api' },\n { type: 'n8n-nodes-base.googleDrive', safeTypeVersions: [1, 2, 3], requiredParams: [], credentialType: 'googleDriveOAuth2Api' },\n { type: 'n8n-nodes-base.googleCalendar', safeTypeVersions: [1, 1.1, 1.2, 1.3], requiredParams: [], credentialType: 'googleCalendarOAuth2Api' },\n\n // Project management / CRM\n { type: 'n8n-nodes-base.notion', safeTypeVersions: [1, 2, 2.1, 2.2], requiredParams: [], credentialType: 'notionApi' },\n { type: 'n8n-nodes-base.airtable', safeTypeVersions: [1, 2, 2.1], requiredParams: [], credentialType: 'airtableTokenApi' },\n { type: 'n8n-nodes-base.github', safeTypeVersions: [1, 1.1], requiredParams: [], credentialType: 'githubApi' },\n { type: 'n8n-nodes-base.jira', safeTypeVersions: [1], requiredParams: [], credentialType: 'jiraSoftwareCloudApi' },\n { type: 'n8n-nodes-base.hubspot', safeTypeVersions: [1, 2, 2.1], requiredParams: [], credentialType: 'hubspotOAuth2Api' },\n\n // Databases\n { type: 'n8n-nodes-base.postgres', safeTypeVersions: [1, 2, 2.1, 2.2, 2.3, 2.4, 2.5], requiredParams: [], credentialType: 'postgres' },\n { type: 'n8n-nodes-base.mySql', safeTypeVersions: [1, 2, 2.1, 2.2, 2.3, 2.4], requiredParams: [], credentialType: 'mySql' },\n { type: 'n8n-nodes-base.redis', safeTypeVersions: [1], requiredParams: [], credentialType: 'redis' },\n { type: 'n8n-nodes-base.supabase', safeTypeVersions: [1], requiredParams: [], credentialType: 'supabaseApi' },\n\n // Cloud\n { type: 'n8n-nodes-base.awsS3', safeTypeVersions: [1, 2], requiredParams: [], credentialType: 'aws' },\n\n // Payment / commerce\n { type: 'n8n-nodes-base.stripe', safeTypeVersions: [1], requiredParams: [], credentialType: 'stripeApi' },\n\n // AI / LangChain root nodes\n { type: '@n8n/n8n-nodes-langchain.agent', safeTypeVersions: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9], requiredParams: [] },\n { type: '@n8n/n8n-nodes-langchain.chainLlm', safeTypeVersions: [1, 1.1, 1.2, 1.3, 1.4, 1.5], requiredParams: [] },\n { type: '@n8n/n8n-nodes-langchain.chainRetrievalQa', safeTypeVersions: [1, 1.1, 1.2, 1.3, 1.4], requiredParams: [] },\n { type: '@n8n/n8n-nodes-langchain.openAi', safeTypeVersions: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8], requiredParams: [], credentialType: 'openAiApi' },\n { type: '@n8n/n8n-nodes-langchain.anthropic', safeTypeVersions: [1], requiredParams: [], credentialType: 'anthropicApi' },\n { type: '@n8n/n8n-nodes-langchain.informationExtractor', safeTypeVersions: [1], requiredParams: [] },\n { type: '@n8n/n8n-nodes-langchain.textClassifier', safeTypeVersions: [1], requiredParams: [] },\n\n // AI / LangChain sub-nodes (models)\n { type: '@n8n/n8n-nodes-langchain.lmChatOpenAi', safeTypeVersions: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7], requiredParams: [], credentialType: 'openAiApi' },\n { type: '@n8n/n8n-nodes-langchain.lmChatAnthropic', safeTypeVersions: [1, 1.1, 1.2, 1.3], requiredParams: [], credentialType: 'anthropicApi' },\n { type: '@n8n/n8n-nodes-langchain.lmChatGoogleGemini', safeTypeVersions: [1], requiredParams: [], credentialType: 'googlePalmApi' },\n\n // AI / LangChain sub-nodes (memory, tools, etc.)\n { type: '@n8n/n8n-nodes-langchain.memoryBufferWindow', safeTypeVersions: [1, 1.1, 1.2, 1.3], requiredParams: [] },\n { type: '@n8n/n8n-nodes-langchain.toolWorkflow', safeTypeVersions: [1, 1.1, 1.2, 1.3], requiredParams: [] },\n { type: '@n8n/n8n-nodes-langchain.toolCode', safeTypeVersions: [1, 1.1], requiredParams: [] },\n { type: '@n8n/n8n-nodes-langchain.toolHttpRequest', safeTypeVersions: [1, 1.1], requiredParams: [] },\n { type: '@n8n/n8n-nodes-langchain.toolCalculator', safeTypeVersions: [1], requiredParams: [] },\n]\n\nexport class NodeRegistry {\n private readonly byType: Map<string, NodeDefinition>\n\n constructor(definitions: NodeDefinition[] = DEFAULT_REGISTRY) {\n this.byType = new Map(definitions.map((d) => [d.type, d]))\n }\n\n get(type: string): NodeDefinition | undefined {\n return this.byType.get(type)\n }\n\n isTrigger(type: string): boolean {\n return this.byType.get(type)?.isTrigger === true\n }\n\n isKnown(type: string): boolean {\n return this.byType.has(type)\n }\n\n isVersionSafe(type: string, version: number): boolean {\n const def = this.byType.get(type)\n if (!def) return true\n return def.safeTypeVersions.includes(version)\n }\n\n getRequiredParams(type: string): string[] {\n return this.byType.get(type)?.requiredParams ?? []\n }\n}\n","import type { N8nWorkflow, N8nNode } from '../types/workflow.js'\nimport type { ValidationIssue, ValidationResult } from './types.js'\nimport { NodeRegistry, DEFAULT_REGISTRY } from './registry.js'\nimport { FORBIDDEN_ON_CREATE } from '../providers/n8n/types.js'\n\nconst AI_CONNECTION_TYPES = [\n 'ai_languageModel',\n 'ai_memory',\n 'ai_tool',\n 'ai_outputParser',\n 'ai_embedding',\n 'ai_document',\n 'ai_textSplitter',\n 'ai_retriever',\n 'ai_vectorStore',\n]\n\nconst TRIGGER_TYPE_PATTERNS = [/trigger/i, /Trigger$/]\n\nconst NODE_TYPE_PATTERN = /^(@[a-z0-9-]+\\/[a-z0-9-]+\\.|n8n-nodes-[a-z0-9-]+\\.)[a-zA-Z][a-zA-Z0-9-]+$/\n\nexport class N8nValidator {\n private readonly registry: NodeRegistry\n\n constructor(registry: NodeRegistry = new NodeRegistry(DEFAULT_REGISTRY)) {\n this.registry = registry\n }\n\n validate(workflow: N8nWorkflow): ValidationResult {\n const issues: ValidationIssue[] = []\n\n this.checkRule1(workflow, issues)\n this.checkRule2(workflow, issues)\n this.checkRule3(workflow, issues)\n this.checkRule4(workflow, issues)\n this.checkRule5(workflow, issues)\n this.checkRule6(workflow, issues)\n this.checkRule7(workflow, issues)\n this.checkRule8(workflow, issues)\n this.checkRule9(workflow, issues)\n this.checkRule10(workflow, issues)\n this.checkRule11(workflow, issues)\n this.checkRule12(workflow, issues)\n this.checkRule13(workflow, issues)\n this.checkRule14(workflow, issues)\n this.checkRule15(workflow, issues)\n this.checkRule16(workflow, issues)\n this.checkRule17(workflow, issues)\n this.checkRule18(workflow, issues)\n this.checkRule19(workflow, issues)\n this.checkRule20(workflow, issues)\n this.checkRule21(workflow, issues)\n this.checkRule22(workflow, issues)\n this.checkRule23(workflow, issues)\n\n const errors = issues.filter((i) => i.severity === 'error')\n return { valid: errors.length === 0, issues }\n }\n\n private err(issues: ValidationIssue[], rule: number, message: string, nodeId?: string): void {\n const issue: ValidationIssue = { rule, severity: 'error', message }\n if (nodeId !== undefined) issue.nodeId = nodeId\n issues.push(issue)\n }\n\n private warn(issues: ValidationIssue[], rule: number, message: string, nodeId?: string): void {\n const issue: ValidationIssue = { rule, severity: 'warn', message }\n if (nodeId !== undefined) issue.nodeId = nodeId\n issues.push(issue)\n }\n\n private isTriggerNode(node: N8nNode): boolean {\n if (this.registry.isTrigger(node.type)) return true\n return TRIGGER_TYPE_PATTERNS.some((p) => p.test(node.type))\n }\n\n // Rule 1: name is a non-empty string\n private checkRule1(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (typeof w.name !== 'string' || w.name.trim() === '') {\n this.err(issues, 1, 'Workflow name is required and must be a non-empty string')\n }\n }\n\n // Rule 2: nodes is an array with at least one element\n private checkRule2(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes) || w.nodes.length === 0) {\n this.err(issues, 2, 'Workflow must have at least one node')\n }\n }\n\n // Rule 3: every node has a non-empty id\n private checkRule3(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes)) return\n for (const node of w.nodes) {\n if (typeof node.id !== 'string' || node.id.trim() === '') {\n this.err(issues, 3, `Node \"${node.name ?? 'unknown'}\" is missing a valid id`, node.id)\n }\n }\n }\n\n // Rule 4: node ids are unique\n private checkRule4(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes)) return\n const seen = new Set<string>()\n for (const node of w.nodes) {\n if (!node.id) continue\n if (seen.has(node.id)) {\n this.err(issues, 4, `Duplicate node id: \"${node.id}\"`, node.id)\n }\n seen.add(node.id)\n }\n }\n\n // Rule 5: every node has a non-empty type string\n private checkRule5(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes)) return\n for (const node of w.nodes) {\n if (typeof node.type !== 'string' || node.type.trim() === '') {\n this.err(issues, 5, `Node \"${node.name ?? node.id}\" is missing a type`, node.id)\n }\n }\n }\n\n // Rule 6: every node has a positive typeVersion number\n private checkRule6(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes)) return\n for (const node of w.nodes) {\n if (typeof node.typeVersion !== 'number' || node.typeVersion <= 0) {\n this.err(issues, 6, `Node \"${node.name}\" has invalid typeVersion: ${String(node.typeVersion)}`, node.id)\n }\n }\n }\n\n // Rule 7: every node has a valid [x, y] position\n private checkRule7(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes)) return\n for (const node of w.nodes) {\n const pos = node.position\n if (\n !Array.isArray(pos) ||\n pos.length !== 2 ||\n typeof pos[0] !== 'number' ||\n typeof pos[1] !== 'number'\n ) {\n this.err(issues, 7, `Node \"${node.name}\" has invalid position (must be [x, y])`, node.id)\n }\n }\n }\n\n // Rule 8: every node has a non-empty name\n private checkRule8(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes)) return\n for (const node of w.nodes) {\n if (typeof node.name !== 'string' || node.name.trim() === '') {\n this.err(issues, 8, `Node with id \"${node.id}\" is missing a name`, node.id)\n }\n }\n }\n\n // Rule 9: connections is a plain object\n private checkRule9(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (typeof w.connections !== 'object' || w.connections === null || Array.isArray(w.connections)) {\n this.err(issues, 9, 'connections must be a plain object (use {} for single-node workflows)')\n }\n }\n\n // Rule 10: every connection target node name exists in nodes\n private checkRule10(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes) || typeof w.connections !== 'object' || w.connections === null) return\n const nodeNames = new Set(w.nodes.map((n) => n.name))\n for (const [sourceName, outputs] of Object.entries(w.connections)) {\n if (!nodeNames.has(sourceName)) {\n this.err(issues, 10, `Connection source \"${sourceName}\" does not exist in nodes`)\n continue\n }\n if (typeof outputs !== 'object' || outputs === null) continue\n for (const portGroup of Object.values(outputs)) {\n if (!Array.isArray(portGroup)) continue\n for (const targets of portGroup) {\n if (!Array.isArray(targets)) continue\n for (const target of targets) {\n const t = target as { node?: string }\n if (typeof t?.node === 'string' && !nodeNames.has(t.node)) {\n this.err(issues, 10, `Connection target \"${t.node}\" does not exist in nodes`)\n }\n }\n }\n }\n }\n }\n\n // Rule 11 (WARN): every non-trigger node has at least one incoming connection\n private checkRule11(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes) || typeof w.connections !== 'object' || w.connections === null) return\n const reachable = new Set<string>()\n for (const [, outputs] of Object.entries(w.connections)) {\n if (typeof outputs !== 'object' || outputs === null) continue\n for (const portGroup of Object.values(outputs)) {\n if (!Array.isArray(portGroup)) continue\n for (const targets of portGroup) {\n if (!Array.isArray(targets)) continue\n for (const target of targets) {\n const t = target as { node?: string }\n if (typeof t?.node === 'string') reachable.add(t.node)\n }\n }\n }\n }\n for (const node of w.nodes) {\n if (node.type.includes('stickyNote')) continue\n if (!this.isTriggerNode(node) && !reachable.has(node.name)) {\n this.warn(issues, 11, `Node \"${node.name}\" has no incoming connections and may never execute`, node.id)\n }\n }\n }\n\n // Rule 12: forbidden fields absent from workflow root\n private checkRule12(w: N8nWorkflow, issues: ValidationIssue[]): void {\n const wObj = w as unknown as Record<string, unknown>\n for (const field of FORBIDDEN_ON_CREATE) {\n if (field in wObj) {\n this.err(issues, 12, `Forbidden field \"${field}\" present in workflow — remove it before deploying`)\n }\n }\n }\n\n // Rule 13: settings, if present, is a plain object\n private checkRule13(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (w.settings !== undefined) {\n if (typeof w.settings !== 'object' || w.settings === null || Array.isArray(w.settings)) {\n this.err(issues, 13, 'workflow.settings must be a plain object')\n }\n }\n }\n\n // Rule 14: at least one trigger node is present\n private checkRule14(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes)) return\n const hasTrigger = w.nodes.some((n) => this.isTriggerNode(n))\n if (!hasTrigger) {\n this.err(issues, 14, 'Workflow must contain at least one trigger node')\n }\n }\n\n // Rule 15: node type string matches expected format\n private checkRule15(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes)) return\n for (const node of w.nodes) {\n if (typeof node.type !== 'string') continue\n if (!NODE_TYPE_PATTERN.test(node.type)) {\n this.err(issues, 15, `Node \"${node.name}\" has malformed type string: \"${node.type}\"`, node.id)\n }\n }\n }\n\n // Rule 16: node names are unique within the workflow\n private checkRule16(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes)) return\n const seen = new Set<string>()\n for (const node of w.nodes) {\n if (!node.name) continue\n if (seen.has(node.name)) {\n this.err(issues, 16, `Duplicate node name: \"${node.name}\"`, node.id)\n }\n seen.add(node.name)\n }\n }\n\n // Rule 17: credentials shape — each entry has id and name\n private checkRule17(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes)) return\n for (const node of w.nodes) {\n if (!node.credentials) continue\n for (const [credType, credRef] of Object.entries(node.credentials)) {\n if (typeof credRef !== 'object' || credRef === null) {\n this.err(issues, 17, `Node \"${node.name}\" credential \"${credType}\" must be an object with id and name`, node.id)\n continue\n }\n const ref = credRef as unknown as Record<string, unknown>\n if (\n typeof ref['id'] !== 'string' || ref['id'].trim() === '' ||\n typeof ref['name'] !== 'string' || ref['name'].trim() === ''\n ) {\n this.err(issues, 17, `Node \"${node.name}\" credential \"${credType}\" must have non-empty string id and name fields`, node.id)\n }\n }\n }\n }\n\n // Rule 18 (ERROR): AI connections must originate from sub-nodes, not the agent/chain root\n private checkRule18(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (typeof w.connections !== 'object' || w.connections === null) return\n const agentTypes = new Set([\n '@n8n/n8n-nodes-langchain.agent',\n '@n8n/n8n-nodes-langchain.chainLlm',\n '@n8n/n8n-nodes-langchain.chainRetrievalQa',\n '@n8n/n8n-nodes-langchain.chainSummarization',\n ])\n if (!Array.isArray(w.nodes)) return\n const nodesByName = new Map(w.nodes.map((n) => [n.name, n]))\n\n for (const [sourceName, outputs] of Object.entries(w.connections)) {\n const sourceNode = nodesByName.get(sourceName)\n if (!sourceNode) continue\n if (!agentTypes.has(sourceNode.type)) continue\n if (typeof outputs !== 'object' || outputs === null) continue\n for (const connType of AI_CONNECTION_TYPES) {\n if (connType in outputs) {\n this.err(\n issues,\n 18,\n `Node \"${sourceName}\" uses AI connection type \"${connType}\" as a SOURCE — AI sub-nodes should be the source, not the agent/chain root`,\n sourceNode.id,\n )\n }\n }\n }\n }\n\n // Rule 19 (WARN): typeVersion is within known safe range for registered node types\n private checkRule19(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes)) return\n for (const node of w.nodes) {\n if (typeof node.type !== 'string' || typeof node.typeVersion !== 'number') continue\n if (!this.registry.isVersionSafe(node.type, node.typeVersion)) {\n this.warn(\n issues,\n 19,\n `Node \"${node.name}\" uses typeVersion ${node.typeVersion} for type \"${node.type}\" which is not in the known safe list`,\n node.id,\n )\n }\n }\n }\n\n // Rule 20 (WARN): cycle detection — no node should be reachable from itself\n // Exempts splitInBatches loops which are an intentional n8n pattern\n private checkRule20(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes) || typeof w.connections !== 'object' || w.connections === null) return\n\n const splitBatchNodes = new Set(\n w.nodes.filter((n) => n.type.includes('splitInBatches')).map((n) => n.name),\n )\n\n const adj = new Map<string, string[]>()\n for (const [sourceName, outputs] of Object.entries(w.connections)) {\n if (typeof outputs !== 'object' || outputs === null) continue\n const targets: string[] = []\n for (const portGroup of Object.values(outputs)) {\n if (!Array.isArray(portGroup)) continue\n for (const conns of portGroup) {\n if (!Array.isArray(conns)) continue\n for (const conn of conns) {\n const t = conn as { node?: string }\n if (typeof t?.node === 'string') {\n if (splitBatchNodes.has(t.node)) continue\n targets.push(t.node)\n }\n }\n }\n }\n adj.set(sourceName, targets)\n }\n\n const WHITE = 0, GRAY = 1, BLACK = 2\n const color = new Map<string, number>()\n for (const node of w.nodes) color.set(node.name, WHITE)\n\n const dfs = (name: string): boolean => {\n color.set(name, GRAY)\n for (const neighbor of adj.get(name) ?? []) {\n const c = color.get(neighbor)\n if (c === GRAY) return true\n if (c === WHITE && dfs(neighbor)) return true\n }\n color.set(name, BLACK)\n return false\n }\n\n for (const node of w.nodes) {\n if (color.get(node.name) === WHITE && dfs(node.name)) {\n this.warn(issues, 20, 'Workflow contains a connection cycle — this may cause infinite loops')\n return\n }\n }\n }\n\n // Rule 22 (WARN): check requiredParams from registry\n private checkRule22(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes)) return\n for (const node of w.nodes) {\n if (typeof node.type !== 'string') continue\n const required = this.registry.getRequiredParams(node.type)\n if (required.length === 0) continue\n const params = (node.parameters ?? {}) as Record<string, unknown>\n for (const param of required) {\n const value = params[param]\n if (value === undefined || value === null || value === '') {\n this.warn(\n issues,\n 22,\n `Node \"${node.name}\" (${node.type}) is missing required parameter \"${param}\"`,\n node.id,\n )\n }\n }\n }\n }\n\n // Rule 23 (WARN): unknown node types not in registry\n private checkRule23(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes)) return\n for (const node of w.nodes) {\n if (typeof node.type !== 'string') continue\n if (node.type.includes('stickyNote')) continue\n if (!NODE_TYPE_PATTERN.test(node.type)) continue\n if (!this.registry.isKnown(node.type)) {\n this.warn(\n issues,\n 23,\n `Node \"${node.name}\" uses unknown type \"${node.type}\" — it may not exist in n8n`,\n node.id,\n )\n }\n }\n }\n\n // Rule 21 (WARN): webhook with responseMode=\"responseNode\" must have respondToWebhook node\n private checkRule21(w: N8nWorkflow, issues: ValidationIssue[]): void {\n if (!Array.isArray(w.nodes)) return\n\n const webhooksNeedingResponse = w.nodes.filter((n) => {\n if (!n.type.includes('webhook')) return false\n const params = n.parameters as Record<string, unknown> | undefined\n return params?.responseMode === 'responseNode'\n })\n\n if (webhooksNeedingResponse.length === 0) return\n\n const hasRespondNode = w.nodes.some((n) => n.type.includes('respondToWebhook'))\n if (!hasRespondNode) {\n for (const wh of webhooksNeedingResponse) {\n this.warn(\n issues,\n 21,\n `Webhook \"${wh.name}\" uses responseMode \"responseNode\" but no respondToWebhook node exists in the workflow`,\n wh.id,\n )\n }\n }\n }\n}\n","export const SYSTEM_PROMPT_V1 = `You are a workflow generation engine for n8n. Your only output is a generate_workflow tool call containing valid n8n workflow JSON. You never respond with prose, explanations, or markdown. If you cannot fulfill the request, set the error field in the tool call.\n\n## HARD RULES — violating any of these causes immediate deployment failure\n\n### Forbidden fields — NEVER include these in the workflow object:\nid, active, createdAt, updatedAt, versionId, meta, isArchived, activeVersionId, activeVersion, pinData, triggerCount, shared, staticData\n\n### Required top-level structure:\n{\n \"name\": \"<descriptive name>\",\n \"nodes\": [...],\n \"connections\": {...},\n \"settings\": {\n \"saveExecutionProgress\": true,\n \"saveManualExecutions\": true,\n \"saveDataErrorExecution\": \"all\",\n \"saveDataSuccessExecution\": \"all\",\n \"executionTimeout\": 3600,\n \"timezone\": \"UTC\",\n \"executionOrder\": \"v1\"\n }\n}\n\n### Node IDs:\n- Every node.id must be a valid UUID v4 (random hex, format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx)\n- Never reuse IDs, never use sequential fake IDs like \"node-1\"\n\n### Credentials:\n- Only reference credentials with exact type names (see catalog below)\n- If credential ID is unknown, OMIT the credentials block entirely — never invent credential IDs\n- Never put API keys or tokens in parameters when a credential type exists\n\n### Node names:\n- All node names must be unique within the workflow\n- Use descriptive names: \"Fetch Open Invoices\" not \"HTTP Request 2\"\n\n### Positioning:\n- Trigger node: [250, 300]\n- Each subsequent step: x + 220 minimum\n- Parallel branches: offset y by ±150\n- AI sub-nodes: place below their root node (y + 200)\n\n---\n\n## CONNECTION RULES — the most common source of errors\n\n### Standard connections (main data flow):\n\"NodeA\": { \"main\": [ [ { \"node\": \"NodeB\", \"type\": \"main\", \"index\": 0 } ] ] }\n\n### AI connections — CRITICAL: the SUB-NODE is the SOURCE, NOT the agent/chain:\n\"OpenAI Chat Model\": { \"ai_languageModel\": [ [ { \"node\": \"AI Agent\", \"type\": \"ai_languageModel\", \"index\": 0 } ] ] }\n\"Simple Memory\": { \"ai_memory\": [ [ { \"node\": \"AI Agent\", \"type\": \"ai_memory\", \"index\": 0 } ] ] }\n\"Calculator Tool\": { \"ai_tool\": [ [ { \"node\": \"AI Agent\", \"type\": \"ai_tool\", \"index\": 0 } ] ] }\n\nThe AI Agent node does NOT appear in connections as a source for ai_* types.\nEvery AI Agent must have at least one ai_languageModel sub-node connected.\n\n### IF node — two output ports (0 = true, 1 = false):\n\"IF Check\": { \"main\": [ [{ \"node\": \"True Path\", \"type\": \"main\", \"index\": 0 }], [{ \"node\": \"False Path\", \"type\": \"main\", \"index\": 0 }] ] }\n\n### SplitInBatches — two output ports (0 = done/finished, 1 = loop body per batch):\nConnect output 0 to the node that runs AFTER all batches complete.\nConnect output 1 to the processing chain for each batch. The last node in the chain loops back to SplitInBatches via main input.\n\n### Webhook + RespondToWebhook pattern:\nWhen webhook responseMode is \"responseNode\", you MUST include a respondToWebhook node in the flow.\n\"Webhook\": { \"main\": [[{ \"node\": \"Process Data\", \"type\": \"main\", \"index\": 0 }]] }\n\"Process Data\": { \"main\": [[{ \"node\": \"Respond to Webhook\", \"type\": \"main\", \"index\": 0 }]] }\n\n### Triggers have no incoming connections.\n### Connection keys are NODE NAMES, never node IDs.\n\n### Nested parameters:\nNode parameters like conditions, assignments, and rule intervals MUST include all required nested fields. Do not leave nested objects empty or partially filled.\n\n---\n\n## NODE CATALOG — exact type strings and safe typeVersions\n\n### Triggers (always at least one required):\nn8n-nodes-base.manualTrigger typeVersion: 1 — testing only\nn8n-nodes-base.scheduleTrigger typeVersion: 1.2 — params: rule.interval[{field, ...}]\nn8n-nodes-base.webhook typeVersion: 2 — params: httpMethod, path, responseMode\nn8n-nodes-base.formTrigger typeVersion: 2.2\nn8n-nodes-base.emailReadImap typeVersion: 2 — cred: imap\nn8n-nodes-base.errorTrigger typeVersion: 1\nn8n-nodes-base.executeWorkflowTrigger typeVersion: 1.1\nn8n-nodes-base.gmailTrigger typeVersion: 1.2 — cred: gmailOAuth2\nn8n-nodes-base.slackTrigger typeVersion: 1 — cred: slackApi\nn8n-nodes-base.telegramTrigger typeVersion: 1.2 — cred: telegramApi\nn8n-nodes-base.githubTrigger typeVersion: 1 — cred: githubApi\nn8n-nodes-base.airtableTrigger typeVersion: 1 — cred: airtableTokenApi\nn8n-nodes-base.notionTrigger typeVersion: 1 — cred: notionApi\n@n8n/n8n-nodes-langchain.chatTrigger typeVersion: 1.1 — pairs with AI Agent\n\n### Core logic:\nn8n-nodes-base.code typeVersion: 2 — params: mode, jsCode\nn8n-nodes-base.httpRequest typeVersion: 4.2 — params: method, url, [sendBody, jsonBody, sendHeaders, headerParameters]\nn8n-nodes-base.set typeVersion: 3.4 — params: assignments.assignments[{id, name, value, type}]\nn8n-nodes-base.if typeVersion: 2.2 — params: conditions.conditions[{id, leftValue, rightValue, operator}], combinator\nn8n-nodes-base.switch typeVersion: 3.2 — multi-branch routing\nn8n-nodes-base.filter typeVersion: 2.2 — params: conditions (same as IF), 1 output\nn8n-nodes-base.merge typeVersion: 3 — modes: append/combine/chooseBranch\nn8n-nodes-base.splitInBatches typeVersion: 3 — output 0=done, output 1=loop body\nn8n-nodes-base.wait typeVersion: 1.1\nn8n-nodes-base.executeWorkflow typeVersion: 1.2\nn8n-nodes-base.respondToWebhook typeVersion: 1.1 — required when webhook responseMode is \"responseNode\"\nn8n-nodes-base.noOp typeVersion: 1\nn8n-nodes-base.splitOut typeVersion: 1\nn8n-nodes-base.aggregate typeVersion: 1\nn8n-nodes-base.stickyNote typeVersion: 1 — never connected, canvas annotation only\n\n### Email / messaging:\nn8n-nodes-base.emailSend typeVersion: 2.1 — cred: smtp\nn8n-nodes-base.slack typeVersion: 2.2 — cred: slackOAuth2Api — params: resource, operation, select, channelId{__rl}, text\nn8n-nodes-base.telegram typeVersion: 1.2 — cred: telegramApi\nn8n-nodes-base.discord typeVersion: 2 — cred: discordWebhookApi\n\n### Google:\nn8n-nodes-base.gmail typeVersion: 2.1 — cred: gmailOAuth2 — params: resource, operation\nn8n-nodes-base.googleSheets typeVersion: 4.5 — cred: googleSheetsOAuth2Api — params: resource, operation, documentId{__rl}, sheetName{__rl}\nn8n-nodes-base.googleDrive typeVersion: 3 — cred: googleDriveOAuth2Api\nn8n-nodes-base.googleCalendar typeVersion: 1.3 — cred: googleCalendarOAuth2Api\n\n### Productivity:\nn8n-nodes-base.notion typeVersion: 2.2 — cred: notionApi\nn8n-nodes-base.airtable typeVersion: 2.1 — cred: airtableTokenApi\nn8n-nodes-base.github typeVersion: 1.1 — cred: githubApi\nn8n-nodes-base.jira typeVersion: 1 — cred: jiraSoftwareCloudApi\nn8n-nodes-base.hubspot typeVersion: 2.1 — cred: hubspotOAuth2Api\n\n### Databases:\nn8n-nodes-base.postgres typeVersion: 2.5 — cred: postgres\nn8n-nodes-base.mySql typeVersion: 2.4 — cred: mySql\nn8n-nodes-base.redis typeVersion: 1 — cred: redis\nn8n-nodes-base.supabase typeVersion: 1 — cred: supabaseApi\nn8n-nodes-base.awsS3 typeVersion: 2 — cred: aws\n\n### AI — Root nodes (sit on main data flow, receive ai_* connections as TARGETS):\n@n8n/n8n-nodes-langchain.agent typeVersion: 1.9 — params: promptType, text (if define), options.systemMessage\n@n8n/n8n-nodes-langchain.chainLlm typeVersion: 1.5\n@n8n/n8n-nodes-langchain.chainRetrievalQa typeVersion: 1.4\n@n8n/n8n-nodes-langchain.openAi typeVersion: 1.8 — cred: openAiApi — standalone node, calls OpenAI directly without sub-nodes\n@n8n/n8n-nodes-langchain.anthropic typeVersion: 1 — cred: anthropicApi — standalone node, calls Anthropic directly without sub-nodes\n\n### AI — Sub-nodes (sources of ai_* connections, wire INTO root nodes above):\n@n8n/n8n-nodes-langchain.lmChatOpenAi typeVersion: 1.7 — cred: openAiApi — ai_languageModel — use with agent/chain, NOT standalone\n@n8n/n8n-nodes-langchain.lmChatAnthropic typeVersion: 1.3 — cred: anthropicApi — ai_languageModel — use with agent/chain, NOT standalone\n@n8n/n8n-nodes-langchain.lmChatGoogleGemini typeVersion: 1 — cred: googlePalmApi — ai_languageModel\n@n8n/n8n-nodes-langchain.memoryBufferWindow typeVersion: 1.3 — — ai_memory\n@n8n/n8n-nodes-langchain.toolWorkflow typeVersion: 2 — — ai_tool\n@n8n/n8n-nodes-langchain.toolCode typeVersion: 1.1 — — ai_tool\n@n8n/n8n-nodes-langchain.toolHttpRequest typeVersion: 1.1 — — ai_tool\n@n8n/n8n-nodes-langchain.toolCalculator typeVersion: 1 — — ai_tool\n\n### Resource locator (__rl) format (Google / Slack / Notion modern nodes):\n{ \"__rl\": true, \"mode\": \"id\", \"value\": \"ACTUAL_ID\" }\n{ \"__rl\": true, \"mode\": \"name\", \"value\": \"#channel-name\" }\n\n### App node parameter pattern:\n{ \"resource\": \"message\", \"operation\": \"send\", ...operation-specific fields }\n\n### Schedule Trigger — daily at 9am example:\n{ \"rule\": { \"interval\": [{ \"field\": \"days\", \"daysInterval\": 1, \"triggerAtHour\": 9, \"triggerAtMinute\": 0 }] } }\nCron: { \"rule\": { \"interval\": [{ \"field\": \"cronExpression\", \"expression\": \"0 9 * * 1-5\" }] } }\n\n---\n\n## PRE-DELIVERY SELF-CHECK (do this before calling the tool):\n1. Every connection source/target name exists in nodes array\n2. No duplicate node names\n3. No duplicate node IDs\n4. No forbidden fields at the workflow root\n5. At least one trigger node present\n6. Every AI Agent has an ai_languageModel sub-node\n7. settings block is complete with executionOrder: \"v1\"\n\n---\n\nRespond ONLY with a generate_workflow tool call. No prose. No markdown outside the tool call.\nIf the request is impossible or unclear, set the error field instead of generating a workflow.`\n","export const DIRECT_THRESHOLD = 0.92\nexport const REFERENCE_THRESHOLD = 0.72\n\nexport function scoreToMode(score: number): 'direct' | 'reference' | 'scratch' {\n if (score >= DIRECT_THRESHOLD) return 'direct'\n if (score >= REFERENCE_THRESHOLD) return 'reference'\n return 'scratch'\n}\n","import type { WorkflowMatch } from '../library/types.js'\nimport type { RuleFailureRate } from '../telemetry/reader.js'\nimport type { DesignRequest, BuiltPrompt, SystemPromptBlock } from './types.js'\nimport { SYSTEM_PROMPT_V1 } from './prompts/v1.js'\nimport { scoreToMode } from '../utils/thresholds.js'\n\nconst RULE_REMEDIES: Record<number, string> = {\n 1: 'Provide a non-empty workflow name string',\n 2: 'Include at least one node in the nodes array',\n 3: 'Every node must have a unique UUID v4 string as its id field',\n 4: 'Ensure all node ids are unique — no two nodes can share the same id',\n 5: 'Every node must have a non-empty type string',\n 6: 'Every node must have a positive integer typeVersion',\n 7: 'Every node must have a position array of exactly [x, y] numbers',\n 8: 'Every node must have a non-empty name string',\n 9: 'connections must be a plain object (use {} if no connections)',\n 10: 'Every node name in connections (source and target) must exactly match a name in the nodes array',\n 12: 'Remove forbidden fields: id, active, createdAt, updatedAt, versionId, meta, tags — these are server-assigned',\n 14: 'Include at least one trigger node (e.g. webhook, scheduleTrigger, manualTrigger)',\n 15: 'Node type strings must be fully qualified: \"n8n-nodes-base.httpRequest\" not just \"httpRequest\"',\n 16: 'All node names must be unique within the workflow',\n 17: 'Credentials must be an object with non-empty string id and name fields: { id: \"placeholder-id\", name: \"My Credential\" }',\n 18: 'AI sub-nodes (languageModel, memory, tool) must be the CONNECTION SOURCE pointing TO the agent — not the reverse',\n 19: 'Use known safe typeVersion values for each node type',\n 20: 'Remove connection cycles — ensure no node can reach itself through the connection graph',\n 21: 'When using webhook with responseMode \"responseNode\", include a respondToWebhook node in the flow',\n 22: 'Ensure all required parameters are set for each node type (e.g. webhook needs httpMethod and path)',\n}\n\nexport class PromptBuilder {\n build(request: DesignRequest, matches: WorkflowMatch[], globalFailureRates: RuleFailureRate[] = []): BuiltPrompt {\n const mode = this.resolveMode(matches)\n const system = this.buildSystem(matches, mode, globalFailureRates)\n const userMessage = this.buildUserMessage(request, matches, mode)\n return { system, userMessage, mode, matches }\n }\n\n buildCorrectionMessage(\n request: DesignRequest,\n matches: WorkflowMatch[],\n allIssues: string[],\n attempt: number,\n ): string {\n const base = this.buildUserMessage(request, matches, this.resolveMode(matches))\n return `${base}\n\nIMPORTANT: A previous generation attempt (attempt ${attempt}) failed validation with these issues:\n${allIssues.join('\\n')}\n\nFix ALL of the above issues in your new response. Do not repeat any of these mistakes.`\n }\n\n private resolveMode(matches: WorkflowMatch[]): 'direct' | 'reference' | 'scratch' {\n if (matches.length === 0) return 'scratch'\n const top = matches[0]\n if (!top) return 'scratch'\n return scoreToMode(top.score)\n }\n\n private buildSystem(matches: WorkflowMatch[], mode: 'direct' | 'reference' | 'scratch', globalFailureRates: RuleFailureRate[] = []): SystemPromptBlock[] {\n const blocks: SystemPromptBlock[] = [\n {\n type: 'text',\n text: SYSTEM_PROMPT_V1,\n cache_control: { type: 'ephemeral' },\n },\n ]\n\n if (mode === 'reference' && matches.length > 0) {\n const refText = matches\n .slice(0, 3)\n .map((m) => {\n const nodes = m.workflow.workflow.nodes\n .map((n) => ` - ${n.name} (${n.type} v${n.typeVersion})`)\n .join('\\n')\n return `Reference workflow: \"${m.workflow.description}\" (similarity: ${m.score.toFixed(2)})\\nNodes:\\n${nodes}`\n })\n .join('\\n\\n')\n\n blocks.push({\n type: 'text',\n text: `## Similar Workflows From Library (for reference only — adapt, do not copy verbatim)\\n\\n${refText}`,\n })\n }\n\n if (mode === 'direct' && matches[0]) {\n const match = matches[0]\n const json = JSON.stringify(match.workflow.workflow, null, 2)\n if (json.length > 30_000) {\n const nodes = match.workflow.workflow.nodes\n .map((n) => ` - ${n.name} (${n.type} v${n.typeVersion})`)\n .join('\\n')\n blocks.push({\n type: 'text',\n text: `## Closely Matched Workflow (score: ${match.score.toFixed(2)}) — too large for full JSON, using reference:\\nNodes:\\n${nodes}`,\n })\n } else {\n blocks.push({\n type: 'text',\n text: `## Closely Matched Workflow (score: ${match.score.toFixed(2)}) — adapt this structure:\\n\\n${json}`,\n })\n }\n }\n\n if (mode === 'scratch' && matches.length > 0 && matches[0]!.score >= 0.40) {\n const hint = matches[0]!\n const nodeTypes = hint.workflow.workflow.nodes.map((n) => n.type.split('.').pop()).join(', ')\n blocks.push({\n type: 'text',\n text: `## Weak Structural Hint\\nA loosely similar workflow (score: ${hint.score.toFixed(2)}) used these node types: ${nodeTypes}`,\n })\n }\n\n const warnings = this.buildFailureWarnings(matches, globalFailureRates)\n if (warnings) {\n blocks.push({ type: 'text', text: warnings })\n }\n\n return blocks\n }\n\n private buildFailureWarnings(matches: WorkflowMatch[], globalFailureRates: RuleFailureRate[]): string | null {\n const lines: string[] = []\n\n for (const match of matches) {\n const patterns = match.workflow.failurePatterns\n if (!patterns?.length) continue\n for (const fp of patterns) {\n const remedy = RULE_REMEDIES[fp.rule]\n const remedyStr = remedy ? ` — Fix: ${remedy}` : ''\n lines.push(`- Rule ${fp.rule}: \"${fp.message}\"${remedyStr} (seen ${fp.occurrences}x in similar workflows)`)\n }\n }\n\n const highFreqRules = globalFailureRates.filter((r) => r.rate >= 0.15)\n for (const rule of highFreqRules) {\n const remedy = RULE_REMEDIES[rule.rule]\n const remedyStr = remedy ? ` — Fix: ${remedy}` : ''\n lines.push(`- Rule ${rule.rule}: \"${rule.commonMessage}\"${remedyStr} (fails in ${Math.round(rule.rate * 100)}% of all builds)`)\n }\n\n if (lines.length === 0) return null\n\n const unique = [...new Set(lines)]\n return `## Known Failure Patterns — AVOID THESE\\n\\nPrevious builds frequently failed the following validation rules. Ensure your output does NOT repeat these mistakes:\\n${unique.join('\\n')}`\n }\n\n private buildUserMessage(request: DesignRequest, _matches: WorkflowMatch[], _mode: string): string {\n const namePart = request.name ? `\\nWorkflow name: \"${request.name}\"` : ''\n return `Build a workflow that: ${request.description}${namePart}`\n }\n}\n","import { readFile, readdir } from 'node:fs/promises'\nimport { join } from 'node:path'\nimport { homedir } from 'node:os'\nimport type { TelemetryEvent } from './types.js'\n\nexport interface RuleFailureRate {\n rule: number\n failureCount: number\n totalBuilds: number\n rate: number\n commonMessage: string\n}\n\nexport class TelemetryReader {\n private readonly dir: string\n private cache: RuleFailureRate[] | null = null\n private cacheTime = 0\n\n constructor(dir?: string) {\n this.dir = dir ?? join(homedir(), '.kairos', 'telemetry')\n }\n\n async getFailureRates(days = 30): Promise<RuleFailureRate[]> {\n const now = Date.now()\n if (this.cache && now - this.cacheTime < 5 * 60 * 1000) {\n return this.cache\n }\n\n const events = await this.readRecentEvents(days)\n\n const buildSessions = new Set(\n events\n .filter((e) => e.eventType === 'build_complete' && !(e.data as { dryRun?: boolean }).dryRun)\n .map((e) => e.sessionId),\n )\n if (buildSessions.size === 0) return []\n\n const ruleSessions = new Map<number, { sessions: Set<string>; messages: Map<string, number> }>()\n\n for (const event of events) {\n if (event.eventType !== 'generation_attempt') continue\n if (!buildSessions.has(event.sessionId)) continue\n const data = event.data as { validationPassed?: boolean; issues?: Array<{ rule: number; message: string }> }\n if (data.validationPassed || !data.issues) continue\n\n for (const issue of data.issues) {\n const entry = ruleSessions.get(issue.rule) ?? { sessions: new Set(), messages: new Map() }\n entry.sessions.add(event.sessionId)\n entry.messages.set(issue.message, (entry.messages.get(issue.message) ?? 0) + 1)\n ruleSessions.set(issue.rule, entry)\n }\n }\n\n const rates: RuleFailureRate[] = []\n for (const [rule, entry] of ruleSessions) {\n let topMessage = ''\n let topCount = 0\n for (const [msg, count] of entry.messages) {\n if (count > topCount) {\n topMessage = msg\n topCount = count\n }\n }\n rates.push({\n rule,\n failureCount: entry.sessions.size,\n totalBuilds: buildSessions.size,\n rate: entry.sessions.size / buildSessions.size,\n commonMessage: topMessage,\n })\n }\n\n rates.sort((a, b) => b.rate - a.rate)\n this.cache = rates\n this.cacheTime = now\n return rates\n }\n\n private async readRecentEvents(days: number): Promise<TelemetryEvent[]> {\n let files: string[]\n try {\n files = await readdir(this.dir)\n } catch {\n return []\n }\n\n const cutoff = new Date()\n cutoff.setDate(cutoff.getDate() - days)\n const cutoffStr = cutoff.toISOString().slice(0, 10)\n\n const datePattern = /^\\d{4}-\\d{2}-\\d{2}\\.jsonl$/\n const recentFiles = files\n .filter((f) => datePattern.test(f) && f >= cutoffStr)\n .sort()\n\n const events: TelemetryEvent[] = []\n for (const file of recentFiles) {\n try {\n const content = await readFile(join(this.dir, file), 'utf-8')\n for (const line of content.split('\\n')) {\n if (!line.trim()) continue\n try {\n events.push(JSON.parse(line) as TelemetryEvent)\n } catch {\n // skip malformed lines\n }\n }\n } catch {\n // skip unreadable files\n }\n }\n return events\n }\n}\n","export interface ILogger {\n debug(msg: string, meta?: Record<string, unknown>): void\n info(msg: string, meta?: Record<string, unknown>): void\n warn(msg: string, meta?: Record<string, unknown>): void\n error(msg: string, meta?: Record<string, unknown>): void\n}\n\nexport const nullLogger: ILogger = {\n debug() {},\n info() {},\n warn() {},\n error() {},\n}\n","import type { StoredWorkflow } from './types.js'\n\nconst WEIGHTS = {\n tfidf: 0.35,\n nodeFingerprint: 0.30,\n outcome: 0.20,\n deploy: 0.15,\n}\n\nconst NODE_KEYWORDS: Record<string, string[]> = {\n slack: ['slack', 'slackApi'],\n email: ['gmail', 'sendEmail', 'emailSend', 'emailReadImap'],\n webhook: ['webhook', 'webhookTrigger'],\n schedule: ['scheduleTrigger', 'cron'],\n http: ['httpRequest'],\n sheets: ['googleSheets'],\n github: ['github', 'githubTrigger'],\n telegram: ['telegram', 'telegramTrigger'],\n ai: ['agent', 'openAi', 'lmChatOpenAi', 'lmChatAnthropic', 'chainLlm', 'chainSummarization'],\n memory: ['memoryBufferWindow', 'memoryXata', 'memoryPostgres'],\n vector: ['vectorStoreInMemory', 'vectorStorePinecone', 'vectorStoreQdrant'],\n database: ['postgres', 'mySql', 'redis', 'mongoDb'],\n airtable: ['airtable'],\n notion: ['notion'],\n s3: ['awsS3'],\n code: ['code'],\n merge: ['merge'],\n switch: ['switch'],\n if: ['if'],\n wait: ['wait'],\n rss: ['rssFeedRead', 'rssFeedReadTrigger'],\n form: ['formTrigger'],\n set: ['set'],\n split: ['splitInBatches'],\n filter: ['filter'],\n telegram_trigger: ['telegramTrigger'],\n stripe: ['stripe'],\n}\n\nfunction extractQueryFingerprint(description: string): Set<string> {\n const lower = description.toLowerCase()\n const matches = new Set<string>()\n\n for (const [keyword, nodeTypes] of Object.entries(NODE_KEYWORDS)) {\n if (lower.includes(keyword)) {\n for (const nt of nodeTypes) matches.add(nt)\n }\n }\n\n if (/\\bevery\\b|\\bdaily\\b|\\bhourly\\b|\\bweekly\\b|\\bmonthly\\b|\\bcron\\b|\\bschedule\\b|\\bat \\d/.test(lower)) {\n matches.add('scheduleTrigger')\n }\n if (/\\bwebhook\\b|\\breceive\\b.*\\bpost\\b|\\bpost\\b.*\\brequest\\b/.test(lower)) {\n matches.add('webhook')\n }\n if (/\\bchat\\b|\\bchatbot\\b|\\bconversation\\b/.test(lower)) {\n matches.add('chatTrigger')\n }\n if (/\\bai\\b|\\bllm\\b|\\bgpt\\b|\\bclaude\\b|\\bagent\\b|\\bsummariz/.test(lower)) {\n matches.add('agent')\n }\n\n return matches\n}\n\nfunction extractWorkflowFingerprint(w: StoredWorkflow): Set<string> {\n const fp = new Set<string>()\n for (const node of w.workflow.nodes) {\n const bare = node.type.split('.').pop() ?? ''\n fp.add(bare)\n }\n return fp\n}\n\nfunction jaccardSimilarity(a: Set<string>, b: Set<string>): number {\n if (a.size === 0 && b.size === 0) return 0\n let intersection = 0\n for (const item of a) {\n if (b.has(item)) intersection++\n }\n const union = a.size + b.size - intersection\n return union > 0 ? intersection / union : 0\n}\n\nfunction outcomeScore(w: StoredWorkflow): number {\n const stats = w.outcomeStats\n if (!stats || stats.totalUses === 0) return 0.5\n\n const passRate = stats.firstTryPasses / stats.totalUses\n const avgAttempts = stats.totalAttempts / stats.totalUses\n const attemptPenalty = Math.max(0, 1 - (avgAttempts - 1) * 0.3)\n\n return passRate * 0.6 + attemptPenalty * 0.4\n}\n\nfunction deployScore(w: StoredWorkflow): number {\n return 1 + Math.log(w.deployCount + 1) * 0.1\n}\n\nexport interface ScoredEntry {\n workflow: StoredWorkflow\n score: number\n signals: {\n tfidf: number\n nodeFingerprint: number\n outcome: number\n deploy: number\n }\n}\n\nexport function hybridScore(\n queryTokens: string[],\n queryDescription: string,\n workflows: StoredWorkflow[],\n docTokenArrays: string[][],\n idf: Map<string, number>,\n): ScoredEntry[] {\n const queryFp = extractQueryFingerprint(queryDescription)\n const ceiling = queryTokens.reduce((sum, qt) => sum + (idf.get(qt) ?? 0), 0) || 1\n\n return workflows.map((w, i) => {\n const docTokens = docTokenArrays[i]!\n let tfidfRaw = 0\n const docFreq = new Map<string, number>()\n for (const t of docTokens) {\n docFreq.set(t, (docFreq.get(t) ?? 0) + 1)\n }\n for (const qt of queryTokens) {\n const tf = docTokens.length > 0 ? (docFreq.get(qt) ?? 0) / docTokens.length : 0\n const idfVal = idf.get(qt) ?? 0\n tfidfRaw += tf * idfVal\n }\n const tfidf = Math.min(tfidfRaw / ceiling, 1)\n\n const workflowFp = extractWorkflowFingerprint(w)\n const nodeFingerprint = queryFp.size > 0 ? jaccardSimilarity(queryFp, workflowFp) : 0\n\n const outcome = outcomeScore(w)\n const deploy = Math.min(deployScore(w), 1.5) / 1.5\n\n const score = Math.min(\n WEIGHTS.tfidf * tfidf +\n WEIGHTS.nodeFingerprint * nodeFingerprint +\n WEIGHTS.outcome * outcome +\n WEIGHTS.deploy * deploy,\n 1,\n )\n\n return {\n workflow: w,\n score,\n signals: { tfidf, nodeFingerprint, outcome, deploy },\n }\n })\n}\n","import type { StoredWorkflow } from './types.js'\n\nexport interface WorkflowCluster {\n pattern: string\n fingerprint: string[]\n members: StoredWorkflow[]\n avgFirstTryPassRate: number\n avgAttempts: number\n commonFailedRules: Array<{ rule: number; frequency: number }>\n}\n\nfunction getFingerprint(w: StoredWorkflow): string[] {\n return w.workflow.nodes\n .map((n) => n.type.split('.').pop() ?? '')\n .sort()\n}\n\nfunction fingerprintKey(fp: string[]): string {\n return fp.join('|')\n}\n\nfunction describePattern(fp: string[]): string {\n const triggers = fp.filter((n) => /trigger/i.test(n))\n const outputs = fp.filter((n) => /slack|gmail|email|telegram|sheets|airtable|notion/i.test(n))\n const ai = fp.filter((n) => /agent|openai|anthropic|chain|memory/i.test(n))\n const core = fp.filter((n) => /httpRequest|code|merge|switch|if|set|filter/i.test(n))\n\n const parts: string[] = []\n if (triggers.length > 0) parts.push(triggers[0]!)\n if (ai.length > 0) parts.push('AI')\n if (core.length > 0) parts.push(core.slice(0, 2).join('+'))\n if (outputs.length > 0) parts.push(outputs[0]!)\n\n return parts.length > 0 ? parts.join(' → ') : fp.slice(0, 3).join(' → ')\n}\n\nexport function clusterWorkflows(workflows: StoredWorkflow[]): WorkflowCluster[] {\n const groups = new Map<string, StoredWorkflow[]>()\n\n for (const w of workflows) {\n const fp = getFingerprint(w)\n const key = fingerprintKey(fp)\n\n const existing = groups.get(key)\n if (existing) {\n existing.push(w)\n } else {\n groups.set(key, [w])\n }\n }\n\n const clusters: WorkflowCluster[] = []\n\n for (const [, members] of groups) {\n if (members.length === 0) continue\n\n const fp = getFingerprint(members[0]!)\n const withStats = members.filter((m) => m.outcomeStats && m.outcomeStats.totalUses > 0)\n\n let avgFirstTryPassRate = 0\n let avgAttempts = 0\n\n if (withStats.length > 0) {\n avgFirstTryPassRate = withStats.reduce((sum, m) => {\n const s = m.outcomeStats!\n return sum + s.firstTryPasses / s.totalUses\n }, 0) / withStats.length\n\n avgAttempts = withStats.reduce((sum, m) => {\n const s = m.outcomeStats!\n return sum + s.totalAttempts / s.totalUses\n }, 0) / withStats.length\n }\n\n const ruleCounts = new Map<number, number>()\n let totalFailureInstances = 0\n for (const m of withStats) {\n const rules = m.outcomeStats!.failedRules\n for (const [rule, count] of Object.entries(rules)) {\n const r = parseInt(rule, 10)\n ruleCounts.set(r, (ruleCounts.get(r) ?? 0) + count)\n totalFailureInstances += count\n }\n }\n\n const commonFailedRules = [...ruleCounts.entries()]\n .map(([rule, count]) => ({\n rule,\n frequency: totalFailureInstances > 0 ? count / totalFailureInstances : 0,\n }))\n .filter((r) => r.frequency >= 0.1)\n .sort((a, b) => b.frequency - a.frequency)\n\n clusters.push({\n pattern: describePattern(fp),\n fingerprint: fp,\n members,\n avgFirstTryPassRate,\n avgAttempts,\n commonFailedRules,\n })\n }\n\n return clusters.sort((a, b) => b.members.length - a.members.length)\n}\n\nexport function rerank(\n candidates: Array<{ workflow: StoredWorkflow; score: number }>,\n clusters: WorkflowCluster[],\n): Array<{ workflow: StoredWorkflow; score: number; clusterPattern?: string }> {\n const clusterMap = new Map<string, WorkflowCluster>()\n for (const cluster of clusters) {\n for (const member of cluster.members) {\n clusterMap.set(member.id, cluster)\n }\n }\n\n return candidates\n .map((c) => {\n const cluster = clusterMap.get(c.workflow.id)\n let boost = 0\n\n if (cluster && cluster.avgFirstTryPassRate > 0) {\n boost = (cluster.avgFirstTryPassRate - 0.5) * 0.1\n }\n\n if (cluster && cluster.commonFailedRules.length > 0) {\n boost -= cluster.commonFailedRules.length * 0.02\n }\n\n return {\n workflow: c.workflow,\n score: Math.max(0, Math.min(1, c.score + boost)),\n ...(cluster ? { clusterPattern: cluster.pattern } : {}),\n }\n })\n .sort((a, b) => b.score - a.score)\n}\n","import { readFile, writeFile, rename, mkdir, readdir } from 'node:fs/promises'\nimport { join } from 'node:path'\nimport { homedir } from 'node:os'\nimport type { N8nWorkflow } from '../types/workflow.js'\nimport type {\n IWorkflowLibrary,\n WorkflowMatch,\n StoredWorkflow,\n WorkflowMetadataInput,\n LibraryFilters,\n SearchOptions,\n OutcomeData,\n} from './types.js'\nimport { generateUUID } from '../utils/uuid.js'\nimport { scoreToMode } from '../utils/thresholds.js'\nimport { hybridScore } from './scorer.js'\nimport { clusterWorkflows, rerank } from './cluster.js'\n\nexport function tokenize(text: string): string[] {\n return text\n .toLowerCase()\n .replace(/[^a-z0-9\\s]/g, ' ')\n .split(/\\s+/)\n .filter((t) => t.length > 2)\n}\n\nexport function buildSearchCorpus(w: StoredWorkflow): string {\n const nodeTokens = w.workflow.nodes.map((n) => {\n const bare = n.type.split('.').pop() ?? ''\n const spaced = bare.replace(/([A-Z])/g, ' $1').trim().toLowerCase()\n return `${bare} ${spaced}`\n })\n return `${w.description} ${w.workflow.name} ${w.tags.join(' ')} ${nodeTokens.join(' ')}`\n}\n\nconst MAX_LIBRARY_SIZE = 500\n\nexport class FileLibrary implements IWorkflowLibrary {\n private readonly dir: string\n private workflows: StoredWorkflow[] = []\n private initPromise: Promise<void> | null = null\n private writeQueue: Promise<void> = Promise.resolve()\n\n constructor(dir?: string) {\n this.dir = dir ?? join(homedir(), '.kairos', 'library')\n }\n\n async initialize(): Promise<void> {\n if (!this.initPromise) {\n this.initPromise = this.doInitialize()\n }\n return this.initPromise\n }\n\n private async doInitialize(): Promise<void> {\n await mkdir(this.dir, { recursive: true })\n\n const indexPath = join(this.dir, 'index.json')\n try {\n const raw = await readFile(indexPath, 'utf-8')\n const parsed: unknown = JSON.parse(raw)\n if (!Array.isArray(parsed)) {\n this.workflows = []\n } else {\n this.workflows = parsed.filter(\n (item): item is StoredWorkflow =>\n typeof item === 'object' &&\n item !== null &&\n typeof (item as Record<string, unknown>).id === 'string' &&\n typeof (item as Record<string, unknown>).description === 'string' &&\n typeof (item as Record<string, unknown>).workflow === 'object' &&\n (item as Record<string, unknown>).workflow !== null &&\n Array.isArray(((item as Record<string, unknown>).workflow as Record<string, unknown>).nodes),\n )\n }\n } catch {\n this.workflows = []\n }\n }\n\n async search(description: string, options?: SearchOptions): Promise<WorkflowMatch[]> {\n const searchable = this.workflows.filter((w) => w.trustLevel !== 'blocked')\n if (searchable.length === 0) return []\n\n const limit = options?.limit ?? 3\n const queryTokens = tokenize(description)\n if (queryTokens.length === 0) return []\n\n const docTokenArrays = searchable.map((w) => tokenize(buildSearchCorpus(w)))\n const docTokenSets = docTokenArrays.map((tokens) => new Set(tokens))\n\n const docCount = searchable.length\n const idf = new Map<string, number>()\n const allTokens = new Set(queryTokens)\n for (const token of allTokens) {\n const docsWithToken = docTokenSets.filter((d) => d.has(token)).length\n idf.set(token, Math.log((docCount + 1) / (docsWithToken + 1)) + 1)\n }\n\n const scored = hybridScore(queryTokens, description, searchable, docTokenArrays, idf)\n .filter((m) => m.score > 0)\n .sort((a, b) => b.score - a.score)\n\n const clusters = clusterWorkflows(searchable)\n const reranked = rerank(scored, clusters).slice(0, limit)\n\n const results = reranked.map((m) => {\n return { workflow: m.workflow, score: m.score, mode: scoreToMode(m.score) }\n })\n\n if (results.length > 0) {\n for (const r of results) {\n r.workflow.timesRetrieved = (r.workflow.timesRetrieved ?? 0) + 1\n }\n this.persist()\n }\n\n return results\n }\n\n async save(workflow: N8nWorkflow, metadata: WorkflowMetadataInput): Promise<string> {\n const id = generateUUID()\n const failurePatterns = this.deduplicateFailurePatterns(metadata.failurePatterns)\n const stored: StoredWorkflow = {\n id,\n workflow,\n description: metadata.description,\n tags: metadata.tags ?? [],\n platform: metadata.platform ?? 'n8n',\n deployCount: 0,\n createdAt: new Date().toISOString(),\n ...(failurePatterns?.length ? { failurePatterns } : {}),\n ...(metadata.sourceWorkflowIds?.length ? { sourceWorkflowIds: metadata.sourceWorkflowIds } : {}),\n ...(metadata.generationMode ? { generationMode: metadata.generationMode } : {}),\n ...(metadata.topMatchScore != null ? { topMatchScore: metadata.topMatchScore } : {}),\n ...(metadata.generationAttempts != null ? { generationAttempts: metadata.generationAttempts } : {}),\n ...(metadata.credentialsNeeded?.length ? { credentialsNeeded: metadata.credentialsNeeded } : {}),\n ...(metadata.sourceKind ? { sourceKind: metadata.sourceKind } : {}),\n ...(metadata.sourceId ? { sourceId: metadata.sourceId } : {}),\n ...(metadata.sourceUrl ? { sourceUrl: metadata.sourceUrl } : {}),\n ...(metadata.trustLevel ? { trustLevel: metadata.trustLevel } : {}),\n }\n this.workflows.push(stored)\n if (this.workflows.length > MAX_LIBRARY_SIZE) {\n this.workflows.sort((a, b) => (b.deployCount ?? 1) - (a.deployCount ?? 1))\n this.workflows = this.workflows.slice(0, MAX_LIBRARY_SIZE)\n }\n await this.persist()\n return id\n }\n\n async recordDeployment(id: string): Promise<void> {\n const w = this.workflows.find((w) => w.id === id)\n if (w) {\n w.deployCount++\n w.lastDeployedAt = new Date().toISOString()\n await this.persist()\n }\n }\n\n async recordOutcome(id: string, outcome: OutcomeData): Promise<void> {\n const w = this.workflows.find((w) => w.id === id)\n if (!w) return\n\n if (outcome.mode === 'direct') {\n w.timesUsedAsDirect = (w.timesUsedAsDirect ?? 0) + 1\n } else {\n w.timesUsedAsReference = (w.timesUsedAsReference ?? 0) + 1\n }\n\n const stats = w.outcomeStats ?? { totalUses: 0, totalAttempts: 0, firstTryPasses: 0, failedRules: {} }\n stats.totalUses++\n stats.totalAttempts += outcome.attempts\n if (outcome.firstTryPass) stats.firstTryPasses++\n for (const rule of outcome.failedRules) {\n const key = String(rule)\n stats.failedRules[key] = (stats.failedRules[key] ?? 0) + 1\n }\n w.outcomeStats = stats\n\n await this.persist()\n }\n\n async drain(): Promise<void> {\n await this.writeQueue\n }\n\n async get(id: string): Promise<StoredWorkflow | null> {\n return this.workflows.find((w) => w.id === id) ?? null\n }\n\n async list(filters?: LibraryFilters): Promise<StoredWorkflow[]> {\n let result = this.workflows\n if (filters?.platform) {\n result = result.filter((w) => w.platform === filters.platform)\n }\n if (filters?.tags && filters.tags.length > 0) {\n result = result.filter((w) => filters.tags!.some((t) => w.tags.includes(t)))\n }\n return result\n }\n\n private deduplicateFailurePatterns(\n patterns?: Array<{ rule: number; message: string }>,\n ): StoredWorkflow['failurePatterns'] | undefined {\n if (!patterns?.length) return undefined\n const map = new Map<number, { rule: number; message: string; occurrences: number }>()\n for (const fp of patterns) {\n const existing = map.get(fp.rule)\n if (existing) {\n existing.occurrences++\n } else {\n map.set(fp.rule, { rule: fp.rule, message: fp.message, occurrences: 1 })\n }\n }\n return [...map.values()]\n }\n\n private persist(): Promise<void> {\n this.writeQueue = this.writeQueue.then(async () => {\n const indexPath = join(this.dir, 'index.json')\n const tmpPath = `${indexPath}.tmp`\n await writeFile(tmpPath, JSON.stringify(this.workflows, null, 2), 'utf-8')\n await rename(tmpPath, indexPath)\n })\n return this.writeQueue\n }\n}\n","export function generateUUID(): string {\n return crypto.randomUUID()\n}\n"],"mappings":";AAAO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YAAY,SAAiC,OAAiB;AAC5D,UAAM,OAAO;AAD8B;AAE3C,SAAK,OAAO;AACZ,QAAI,MAAM,mBAAmB;AAC3B,YAAM,kBAAkB,MAAM,KAAK,WAAW;AAAA,IAChD;AAAA,EACF;AAAA,EAN6C;AAO/C;;;ACNO,IAAM,WAAN,cAAuB,YAAY;AAAA,EACxC,YACE,SACgB,YAChB,OACA;AACA,UAAM,SAAS,KAAK;AAHJ;AAIhB,SAAK,OAAO;AAAA,EACd;AAAA,EALkB;AAMpB;;;ACTO,IAAM,gBAAN,cAA4B,YAAY;AAAA,EAC7C,YAAY,SAAiB,OAAiB;AAC5C,UAAM,SAAS,KAAK;AACpB,SAAK,OAAO;AAAA,EACd;AACF;;;ACPA,eAAsB,UACpB,IACA,aACA,SACA,aACY;AACZ,MAAI;AACJ,WAAS,UAAU,GAAG,UAAU,aAAa,WAAW;AACtD,QAAI,UAAU,GAAG;AACf,YAAM,SAAS,KAAK,OAAO,IAAI,UAAU;AACzC,YAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,UAAU,MAAM,UAAU,KAAK,MAAM,CAAC;AAAA,IAC3F;AACA,QAAI;AACF,aAAO,MAAM,GAAG;AAAA,IAClB,SAAS,KAAK;AACZ,kBAAY;AACZ,UAAI,eAAe,CAAC,YAAY,GAAG,EAAG,OAAM;AAAA,IAC9C;AAAA,EACF;AACA,QAAM;AACR;AAEO,SAAS,iBAAiB,KAAa,MAAmB,WAAsC;AACrG,QAAM,aAAa,IAAI,gBAAgB;AACvC,QAAM,QAAQ,WAAW,MAAM,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