@kairos-sdk/core 0.4.0 → 0.5.0

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.
@@ -0,0 +1,569 @@
1
+ import {
2
+ RULE_EXAMPLES,
3
+ RULE_MITIGATIONS,
4
+ scoreToMode
5
+ } from "./chunk-KIFT5LA7.js";
6
+
7
+ // src/generation/prompt-builder.ts
8
+ import { readFileSync } from "fs";
9
+ import { join } from "path";
10
+ import { homedir } from "os";
11
+
12
+ // src/generation/prompts/v1.ts
13
+ var 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.
14
+
15
+ ## HARD RULES \u2014 violating any of these causes immediate deployment failure
16
+
17
+ ### Forbidden fields \u2014 NEVER include these in the workflow object:
18
+ id, active, createdAt, updatedAt, versionId, meta, isArchived, activeVersionId, activeVersion, pinData, triggerCount, shared, staticData
19
+
20
+ ### Required top-level structure:
21
+ {
22
+ "name": "<descriptive name>",
23
+ "nodes": [...],
24
+ "connections": {...},
25
+ "settings": {
26
+ "saveExecutionProgress": true,
27
+ "saveManualExecutions": true,
28
+ "saveDataErrorExecution": "all",
29
+ "saveDataSuccessExecution": "all",
30
+ "executionTimeout": 3600,
31
+ "timezone": "UTC",
32
+ "executionOrder": "v1"
33
+ }
34
+ }
35
+
36
+ ### Node IDs:
37
+ - Every node.id must be a valid UUID v4 (random hex, format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx)
38
+ - Never reuse IDs, never use sequential fake IDs like "node-1"
39
+
40
+ ### Credentials:
41
+ - Each credential is keyed by its type string, with an object value containing id and name:
42
+ "credentials": { "slackOAuth2Api": { "id": "placeholder-id", "name": "My Slack Credential" } }
43
+ - Use "placeholder-id" as the id \u2014 users replace this with their real credential ID from n8n after deployment
44
+ - The credentialsNeeded field in your response declares what credentials the user must configure
45
+ - Never put API keys or tokens directly in node parameters when a credential type exists
46
+
47
+ ### Node names:
48
+ - All node names must be unique within the workflow
49
+ - Use descriptive names: "Fetch Open Invoices" not "HTTP Request 2"
50
+
51
+ ### Positioning:
52
+ - Trigger node: [250, 300]
53
+ - Each subsequent step: x + 220 minimum
54
+ - Parallel branches: offset y by \xB1150
55
+ - AI sub-nodes: place below their root node (y + 200)
56
+
57
+ ---
58
+
59
+ ## CONNECTION RULES \u2014 the most common source of errors
60
+
61
+ ### Standard connections (main data flow):
62
+ "NodeA": { "main": [ [ { "node": "NodeB", "type": "main", "index": 0 } ] ] }
63
+
64
+ ### AI connections \u2014 CRITICAL: the SUB-NODE is the SOURCE, NOT the agent/chain:
65
+ "OpenAI Chat Model": { "ai_languageModel": [ [ { "node": "AI Agent", "type": "ai_languageModel", "index": 0 } ] ] }
66
+ "Simple Memory": { "ai_memory": [ [ { "node": "AI Agent", "type": "ai_memory", "index": 0 } ] ] }
67
+ "Calculator Tool": { "ai_tool": [ [ { "node": "AI Agent", "type": "ai_tool", "index": 0 } ] ] }
68
+
69
+ The AI Agent node does NOT appear in connections as a source for ai_* types.
70
+ Every AI Agent must have at least one ai_languageModel sub-node connected.
71
+
72
+ ### IF node \u2014 two output ports (0 = true, 1 = false):
73
+ "IF Check": { "main": [ [{ "node": "True Path", "type": "main", "index": 0 }], [{ "node": "False Path", "type": "main", "index": 0 }] ] }
74
+
75
+ ### SplitInBatches \u2014 two output ports (0 = done/finished, 1 = loop body per batch):
76
+ Connect output 0 to the node that runs AFTER all batches complete.
77
+ Connect output 1 to the processing chain for each batch. The last node in the chain loops back to SplitInBatches via main input.
78
+
79
+ ### Webhook + RespondToWebhook pattern:
80
+ When webhook responseMode is "responseNode", you MUST include a respondToWebhook node in the flow.
81
+ "Webhook": { "main": [[{ "node": "Process Data", "type": "main", "index": 0 }]] }
82
+ "Process Data": { "main": [[{ "node": "Respond to Webhook", "type": "main", "index": 0 }]] }
83
+
84
+ ### Triggers have no incoming connections.
85
+ ### Connection keys are NODE NAMES, never node IDs.
86
+
87
+ ### Nested parameters:
88
+ Node parameters like conditions, assignments, and rule intervals MUST include all required nested fields. Do not leave nested objects empty or partially filled.
89
+
90
+ ---
91
+
92
+ ## EXPRESSION SYNTAX \u2014 how to reference upstream node data
93
+
94
+ ### Accessing a field from an upstream node:
95
+ - CORRECT: $('NodeName').item.json.field
96
+ - WRONG: $node["NodeName"].json.field \u2190 deprecated accessor, fails at runtime (Rule 24)
97
+
98
+ ### Accessing array items from $json:
99
+ - CORRECT: $json.field \u2190 n8n auto-flattens items; each item is already a flat object
100
+ - WRONG: $json.items[0].field \u2190 do not index into items[] (Rule 25)
101
+
102
+ ### Calling node data \u2014 always qualify with .first() or .all():
103
+ - CORRECT: $('NodeName').first().json.field \u2190 single item
104
+ - CORRECT: $('NodeName').all() \u2190 array of all items
105
+ - WRONG: $('NodeName').json \u2190 throws at runtime without .first() or .all() (Rule 26)
106
+
107
+ ---
108
+
109
+ ## NODE CATALOG \u2014 exact type strings and safe typeVersions
110
+
111
+ ### Triggers (always at least one required):
112
+ n8n-nodes-base.manualTrigger typeVersion: 1 \u2014 testing only
113
+ n8n-nodes-base.scheduleTrigger typeVersion: 1.2 \u2014 params: rule.interval[{field, ...}]
114
+ n8n-nodes-base.webhook typeVersion: 2 \u2014 params: httpMethod, path, responseMode
115
+ n8n-nodes-base.formTrigger typeVersion: 2.2
116
+ n8n-nodes-base.emailReadImap typeVersion: 2 \u2014 cred: imap
117
+ n8n-nodes-base.errorTrigger typeVersion: 1
118
+ n8n-nodes-base.executeWorkflowTrigger typeVersion: 1.1
119
+ n8n-nodes-base.gmailTrigger typeVersion: 1.2 \u2014 cred: gmailOAuth2
120
+ n8n-nodes-base.slackTrigger typeVersion: 1 \u2014 cred: slackApi
121
+ n8n-nodes-base.telegramTrigger typeVersion: 1.2 \u2014 cred: telegramApi
122
+ n8n-nodes-base.githubTrigger typeVersion: 1 \u2014 cred: githubApi
123
+ n8n-nodes-base.airtableTrigger typeVersion: 1 \u2014 cred: airtableTokenApi
124
+ n8n-nodes-base.notionTrigger typeVersion: 1 \u2014 cred: notionApi
125
+ @n8n/n8n-nodes-langchain.chatTrigger typeVersion: 1.1 \u2014 pairs with AI Agent
126
+
127
+ ### Core logic:
128
+ n8n-nodes-base.code typeVersion: 2 \u2014 params: mode, jsCode
129
+ n8n-nodes-base.httpRequest typeVersion: 4.2 \u2014 params: method, url, [sendBody, jsonBody, sendHeaders, headerParameters]
130
+ n8n-nodes-base.set typeVersion: 3.4 \u2014 params: assignments.assignments[{id, name, value, type}]
131
+ n8n-nodes-base.if typeVersion: 2.2 \u2014 params: conditions.conditions[{id, leftValue, rightValue, operator}], combinator
132
+ n8n-nodes-base.switch typeVersion: 3.2 \u2014 multi-branch routing
133
+ n8n-nodes-base.filter typeVersion: 2.2 \u2014 params: conditions (same as IF), 1 output
134
+ n8n-nodes-base.merge typeVersion: 3 \u2014 modes: append/combine/chooseBranch
135
+ n8n-nodes-base.splitInBatches typeVersion: 3 \u2014 output 0=done, output 1=loop body
136
+ n8n-nodes-base.wait typeVersion: 1.1
137
+ n8n-nodes-base.executeWorkflow typeVersion: 1.2
138
+ n8n-nodes-base.respondToWebhook typeVersion: 1.1 \u2014 required when webhook responseMode is "responseNode"
139
+ n8n-nodes-base.noOp typeVersion: 1
140
+ n8n-nodes-base.splitOut typeVersion: 1
141
+ n8n-nodes-base.aggregate typeVersion: 1
142
+ n8n-nodes-base.stickyNote typeVersion: 1 \u2014 never connected, canvas annotation only
143
+
144
+ ### Email / messaging:
145
+ n8n-nodes-base.emailSend typeVersion: 2.1 \u2014 cred: smtp
146
+ n8n-nodes-base.slack typeVersion: 2.2 \u2014 cred: slackOAuth2Api \u2014 params: resource, operation, select, channelId{__rl}, text
147
+ n8n-nodes-base.telegram typeVersion: 1.2 \u2014 cred: telegramApi
148
+ n8n-nodes-base.discord typeVersion: 2 \u2014 cred: discordWebhookApi
149
+
150
+ ### Google:
151
+ n8n-nodes-base.gmail typeVersion: 2.1 \u2014 cred: gmailOAuth2 \u2014 params: resource, operation
152
+ n8n-nodes-base.googleSheets typeVersion: 4.5 \u2014 cred: googleSheetsOAuth2Api \u2014 params: resource, operation, documentId{__rl}, sheetName{__rl}
153
+ n8n-nodes-base.googleDrive typeVersion: 3 \u2014 cred: googleDriveOAuth2Api
154
+ n8n-nodes-base.googleCalendar typeVersion: 1.3 \u2014 cred: googleCalendarOAuth2Api
155
+
156
+ ### Productivity:
157
+ n8n-nodes-base.notion typeVersion: 2.2 \u2014 cred: notionApi
158
+ n8n-nodes-base.airtable typeVersion: 2.1 \u2014 cred: airtableTokenApi
159
+ n8n-nodes-base.github typeVersion: 1.1 \u2014 cred: githubApi
160
+ n8n-nodes-base.jira typeVersion: 1 \u2014 cred: jiraSoftwareCloudApi
161
+ n8n-nodes-base.hubspot typeVersion: 2.1 \u2014 cred: hubspotOAuth2Api
162
+
163
+ ### Databases:
164
+ n8n-nodes-base.postgres typeVersion: 2.5 \u2014 cred: postgres
165
+ n8n-nodes-base.mySql typeVersion: 2.4 \u2014 cred: mySql
166
+ n8n-nodes-base.redis typeVersion: 1 \u2014 cred: redis
167
+ n8n-nodes-base.supabase typeVersion: 1 \u2014 cred: supabaseApi
168
+ n8n-nodes-base.awsS3 typeVersion: 2 \u2014 cred: aws
169
+
170
+ ### AI \u2014 Root nodes (sit on main data flow, receive ai_* connections as TARGETS):
171
+ @n8n/n8n-nodes-langchain.agent typeVersion: 1.9 \u2014 params: promptType, text (if define), options.systemMessage
172
+ @n8n/n8n-nodes-langchain.chainLlm typeVersion: 1.5
173
+ @n8n/n8n-nodes-langchain.chainRetrievalQa typeVersion: 1.4
174
+ @n8n/n8n-nodes-langchain.openAi typeVersion: 1.8 \u2014 cred: openAiApi \u2014 standalone node, calls OpenAI directly without sub-nodes
175
+ @n8n/n8n-nodes-langchain.anthropic typeVersion: 1 \u2014 cred: anthropicApi \u2014 standalone node, calls Anthropic directly without sub-nodes
176
+
177
+ ### AI \u2014 Sub-nodes (sources of ai_* connections, wire INTO root nodes above):
178
+ @n8n/n8n-nodes-langchain.lmChatOpenAi typeVersion: 1.7 \u2014 cred: openAiApi \u2014 ai_languageModel \u2014 use with agent/chain, NOT standalone
179
+ @n8n/n8n-nodes-langchain.lmChatAnthropic typeVersion: 1.3 \u2014 cred: anthropicApi \u2014 ai_languageModel \u2014 use with agent/chain, NOT standalone
180
+ @n8n/n8n-nodes-langchain.lmChatGoogleGemini typeVersion: 1 \u2014 cred: googlePalmApi \u2014 ai_languageModel
181
+ @n8n/n8n-nodes-langchain.memoryBufferWindow typeVersion: 1.3 \u2014 \u2014 ai_memory
182
+ @n8n/n8n-nodes-langchain.toolWorkflow typeVersion: 2 \u2014 \u2014 ai_tool
183
+ @n8n/n8n-nodes-langchain.toolCode typeVersion: 1.1 \u2014 \u2014 ai_tool
184
+ @n8n/n8n-nodes-langchain.toolHttpRequest typeVersion: 1.1 \u2014 \u2014 ai_tool
185
+ @n8n/n8n-nodes-langchain.toolCalculator typeVersion: 1 \u2014 \u2014 ai_tool
186
+
187
+ ### Resource locator (__rl) format (Google / Slack / Notion modern nodes):
188
+ { "__rl": true, "mode": "id", "value": "ACTUAL_ID" }
189
+ { "__rl": true, "mode": "name", "value": "#channel-name" }
190
+
191
+ ### App node parameter pattern:
192
+ { "resource": "message", "operation": "send", ...operation-specific fields }
193
+
194
+ ### Schedule Trigger \u2014 daily at 9am example:
195
+ { "rule": { "interval": [{ "field": "days", "daysInterval": 1, "triggerAtHour": 9, "triggerAtMinute": 0 }] } }
196
+ Cron: { "rule": { "interval": [{ "field": "cronExpression", "expression": "0 9 * * 1-5" }] } }
197
+
198
+ ---
199
+
200
+ ## PRE-DELIVERY SELF-CHECK (do this before calling the tool):
201
+ 1. Every connection source/target name exists in nodes array
202
+ 2. No duplicate node names
203
+ 3. No duplicate node IDs
204
+ 4. No forbidden fields at the workflow root
205
+ 5. At least one trigger node present
206
+ 6. Every AI Agent has an ai_languageModel sub-node
207
+ 7. settings block is complete with executionOrder: "v1"
208
+ 8. No deprecated $node["NodeName"].json \u2014 use $('NodeName').item.json.field
209
+ 9. No $json.items[0] array indexing \u2014 access fields directly as $json.field
210
+ 10. No bare $('NodeName').json \u2014 always use .first().json.field or .all()
211
+ 11. httpRequest URL is a real endpoint (not "example.com" or "YOUR_URL")
212
+ 12. code nodes contain actual logic \u2014 not empty or comment-only
213
+ 13. Slack message nodes have a channel specified (channelId or channel)
214
+ 14. Gmail send nodes have a recipient (to field non-empty)
215
+ 15. if nodes have at least one condition in conditions.conditions[]
216
+ 16. set nodes have at least one entry in assignments.assignments[]
217
+ 17. scheduleTrigger has at least one rule in rule.interval[]
218
+ 18. webhook path is relative (no spaces, no leading slash, no http://)
219
+
220
+ ---
221
+
222
+ Respond ONLY with a generate_workflow tool call. No prose. No markdown outside the tool call.
223
+ If the request is impossible or unclear, set the error field instead of generating a workflow.`;
224
+
225
+ // src/generation/prompt-builder.ts
226
+ var CRITICAL_SCORE_THRESHOLD = 0.15;
227
+ function resolveProfile() {
228
+ const env = process.env["KAIROS_PROMPT_PROFILE"];
229
+ if (env === "minimal" || env === "standard" || env === "rich") return env;
230
+ return "standard";
231
+ }
232
+ var PROACTIVE_EXPRESSION_GUIDANCE = `## Expression Syntax Quick Reference
233
+
234
+ Always use these patterns in expressions:
235
+ - Access node data: $('NodeName').item.json.field (not $node["NodeName"].json)
236
+ - Access JSON field: $json.field (not $json.items[0].field)
237
+ - Single item: $('NodeName').first().json.field
238
+ - All items: $('NodeName').all()`;
239
+ var PromptBuilder = class {
240
+ patternsPath;
241
+ profile;
242
+ _lastActivePatterns = null;
243
+ constructor(patternsPath, profile) {
244
+ this.patternsPath = patternsPath ?? join(homedir(), ".kairos", "patterns.json");
245
+ this.profile = profile ?? resolveProfile();
246
+ }
247
+ resolveMaxPatterns() {
248
+ if (this.profile === "minimal") return 3;
249
+ if (this.profile === "rich") return 15;
250
+ return 10;
251
+ }
252
+ build(request, matches, globalFailureRates = [], dynamicCatalog) {
253
+ const mode = this.resolveMode(matches);
254
+ const system = this.buildSystem(matches, mode, globalFailureRates, dynamicCatalog, request.description);
255
+ const userMessage = this.buildUserMessage(request, matches, mode);
256
+ return { system, userMessage, mode, matches };
257
+ }
258
+ buildCorrectionMessage(request, matches, allIssues, attempt, failingRuleIds) {
259
+ const base = this.buildUserMessage(request, matches, this.resolveMode(matches));
260
+ let examplesSection = "";
261
+ if (failingRuleIds && failingRuleIds.length > 0) {
262
+ const uniqueRules = [...new Set(failingRuleIds)];
263
+ const exampleLines = [];
264
+ for (const rule of uniqueRules) {
265
+ const ex = RULE_EXAMPLES[rule];
266
+ if (ex) {
267
+ exampleLines.push(`Rule ${rule}:
268
+ Bad: ${ex.bad}
269
+ Good: ${ex.good}`);
270
+ }
271
+ }
272
+ if (exampleLines.length > 0) {
273
+ examplesSection = `
274
+
275
+ ## Concrete Fix Examples
276
+ ${exampleLines.join("\n\n")}`;
277
+ }
278
+ }
279
+ return `${base}
280
+
281
+ IMPORTANT: A previous generation attempt (attempt ${attempt}) failed validation with these issues:
282
+ ${allIssues.join("\n")}
283
+
284
+ Fix ALL of the above issues in your new response. Do not repeat any of these mistakes.${examplesSection}`;
285
+ }
286
+ resolveMode(matches) {
287
+ if (matches.length === 0) return "scratch";
288
+ const top = matches[0];
289
+ if (!top) return "scratch";
290
+ return scoreToMode(top.score);
291
+ }
292
+ buildSystem(matches, mode, globalFailureRates = [], dynamicCatalog, description) {
293
+ let basePrompt = SYSTEM_PROMPT_V1;
294
+ if (dynamicCatalog) {
295
+ basePrompt = basePrompt.replace(
296
+ /## NODE CATALOG — exact type strings and safe typeVersions[\s\S]*?(?=## PRE-DELIVERY SELF-CHECK)/,
297
+ dynamicCatalog + "\n\n"
298
+ );
299
+ }
300
+ const blocks = [
301
+ {
302
+ type: "text",
303
+ text: basePrompt,
304
+ cache_control: { type: "ephemeral" }
305
+ }
306
+ ];
307
+ if (this.profile !== "minimal") {
308
+ if (mode === "reference" && matches.length > 0) {
309
+ const refText = matches.slice(0, 3).map((m) => {
310
+ const nodes = m.workflow.workflow.nodes.map((n) => ` - ${n.name} (${n.type} v${n.typeVersion})`).join("\n");
311
+ return `Reference workflow: "${m.workflow.description}" (similarity: ${m.score.toFixed(2)})
312
+ Nodes:
313
+ ${nodes}`;
314
+ }).join("\n\n");
315
+ blocks.push({
316
+ type: "text",
317
+ text: `## Similar Workflows From Library (for reference only \u2014 adapt, do not copy verbatim)
318
+
319
+ ${refText}`
320
+ });
321
+ }
322
+ if (mode === "direct" && matches[0]) {
323
+ const match = matches[0];
324
+ const json = JSON.stringify(match.workflow.workflow, null, 2);
325
+ if (json.length > 3e4) {
326
+ const nodes = match.workflow.workflow.nodes.map((n) => ` - ${n.name} (${n.type} v${n.typeVersion})`).join("\n");
327
+ blocks.push({
328
+ type: "text",
329
+ text: `## Closely Matched Workflow (score: ${match.score.toFixed(2)}) \u2014 too large for full JSON, using reference:
330
+ Nodes:
331
+ ${nodes}`
332
+ });
333
+ } else {
334
+ blocks.push({
335
+ type: "text",
336
+ text: `## Closely Matched Workflow (score: ${match.score.toFixed(2)}) \u2014 adapt this structure:
337
+
338
+ ${json}`
339
+ });
340
+ }
341
+ }
342
+ if (mode === "scratch" && matches.length > 0 && matches[0].score >= 0.4) {
343
+ const hint = matches[0];
344
+ const nodeTypes = hint.workflow.workflow.nodes.map((n) => n.type.split(".").pop()).join(", ");
345
+ blocks.push({
346
+ type: "text",
347
+ text: `## Weak Structural Hint
348
+ A loosely similar workflow (score: ${hint.score.toFixed(2)}) used these node types: ${nodeTypes}`
349
+ });
350
+ }
351
+ }
352
+ const warnings = this.buildFailureWarnings(matches, globalFailureRates, description);
353
+ if (warnings) {
354
+ blocks.push({ type: "text", text: warnings });
355
+ }
356
+ if (this.profile === "rich") {
357
+ const expressionRules = /* @__PURE__ */ new Set([24, 25, 26]);
358
+ const expressionAlreadyCovered = (this._lastActivePatterns ?? []).some((p) => expressionRules.has(p.rule));
359
+ if (!expressionAlreadyCovered) {
360
+ blocks.push({ type: "text", text: PROACTIVE_EXPRESSION_GUIDANCE });
361
+ }
362
+ }
363
+ return blocks;
364
+ }
365
+ loadPatterns() {
366
+ try {
367
+ const raw = readFileSync(this.patternsPath, "utf-8");
368
+ const analysis = JSON.parse(raw);
369
+ const patterns = analysis.topFailureRules ?? [];
370
+ return patterns.filter((p) => typeof p.pipelineStage === "string" && typeof p.state === "string");
371
+ } catch {
372
+ return [];
373
+ }
374
+ }
375
+ getWarnedRules() {
376
+ const patterns = this._lastActivePatterns ?? this.getActivePatterns(this.resolveMaxPatterns());
377
+ return patterns.map((p) => p.rule);
378
+ }
379
+ getActivePatterns(maxCount = 10, description) {
380
+ const all = this.loadPatterns().filter((p) => p.state !== "resolved" && p.confidence > 0);
381
+ const regressed = all.filter((p) => p.regressed).sort((a, b) => b.compositeScore - a.compositeScore);
382
+ const confirmed = all.filter((p) => !p.regressed && p.state === "confirmed").sort((a, b) => b.compositeScore - a.compositeScore);
383
+ const drafts = all.filter((p) => !p.regressed && p.state !== "confirmed").sort((a, b) => b.compositeScore - a.compositeScore);
384
+ const ordered = [...regressed, ...confirmed, ...drafts];
385
+ if (this.profile === "minimal" && description) {
386
+ return this.rankByRelevance(ordered, description).slice(0, maxCount);
387
+ }
388
+ return ordered.slice(0, maxCount);
389
+ }
390
+ rankByRelevance(patterns, description) {
391
+ const lower = description.toLowerCase();
392
+ const STAGE_KEYWORDS = {
393
+ credential_injection: ["credential", "auth", "api key", "token", "oauth", "smtp", "imap", "password", "secret"],
394
+ connection_wiring: ["connect", "link", "wire", "chain", "merge", "branch", "join"],
395
+ expression_syntax: ["expression", "variable", "json", "field", "data", "$json", "item"],
396
+ workflow_structure: ["trigger", "webhook", "schedule", "structure", "workflow"],
397
+ node_generation: ["node", "generate", "create", "build", "send", "fetch", "email", "slack", "http"]
398
+ };
399
+ return patterns.map((p) => {
400
+ const keywords = STAGE_KEYWORDS[p.pipelineStage] ?? [];
401
+ const relevanceBoost = keywords.some((kw) => lower.includes(kw)) ? 1 : 0;
402
+ return { pattern: p, sort: relevanceBoost * 10 + p.compositeScore };
403
+ }).sort((a, b) => b.sort - a.sort).map((x) => x.pattern);
404
+ }
405
+ buildFailureWarnings(matches, globalFailureRates, description) {
406
+ const richPatterns = this.getActivePatterns(this.resolveMaxPatterns(), description);
407
+ this._lastActivePatterns = richPatterns;
408
+ if (richPatterns.length > 0) {
409
+ return this.buildStageGroupedWarnings(richPatterns, matches);
410
+ }
411
+ return this.buildLegacyWarnings(matches, globalFailureRates);
412
+ }
413
+ buildStageGroupedWarnings(patterns, matches) {
414
+ const stageLabels = {
415
+ credential_injection: "CREDENTIAL FORMATTING",
416
+ connection_wiring: "CONNECTION WIRING",
417
+ node_generation: "NODE GENERATION",
418
+ workflow_structure: "WORKFLOW STRUCTURE",
419
+ expression_syntax: "EXPRESSION SYNTAX"
420
+ };
421
+ const byStage = /* @__PURE__ */ new Map();
422
+ for (const p of patterns) {
423
+ const list = byStage.get(p.pipelineStage) ?? [];
424
+ list.push(p);
425
+ byStage.set(p.pipelineStage, list);
426
+ }
427
+ const sections = [];
428
+ for (const [stage, stagePatterns] of byStage) {
429
+ const label = stageLabels[stage] ?? stage;
430
+ const byMitigation = /* @__PURE__ */ new Map();
431
+ for (const p of stagePatterns) {
432
+ const key = p.mitigation ?? `rule_${p.rule}`;
433
+ const list = byMitigation.get(key) ?? [];
434
+ list.push(p);
435
+ byMitigation.set(key, list);
436
+ }
437
+ const lines = [];
438
+ for (const group of byMitigation.values()) {
439
+ if (group.length === 1) {
440
+ const p = group[0];
441
+ const urgency = p.regressed ? "CRITICAL REGRESSION: " : (p.compositeScore ?? 0) >= CRITICAL_SCORE_THRESHOLD ? "CRITICAL: " : "";
442
+ const statePrefix = p.state === "confirmed" ? "[CONFIRMED] " : "";
443
+ const trendSuffix = p.trend === "worsening" ? " (GETTING WORSE)" : p.trend === "improving" ? " (improving)" : "";
444
+ const remedy = p.mitigation ?? RULE_MITIGATIONS[p.rule];
445
+ const remedyStr = remedy ? `
446
+ Fix: ${remedy}` : "";
447
+ const ex = RULE_EXAMPLES[p.rule];
448
+ const exampleStr = ex ? `
449
+ Bad: ${ex.bad}
450
+ Good: ${ex.good}` : "";
451
+ lines.push(`- ${urgency}${statePrefix}Rule ${p.rule}${trendSuffix}: ${p.exampleMessages[0] ?? "No example"}${remedyStr}${exampleStr}`);
452
+ } else {
453
+ const ruleNums = group.map((p) => p.rule).join(", ");
454
+ const totalFailures = group.reduce((s, p) => s + p.failureCount, 0);
455
+ const hasConfirmed = group.some((p) => p.state === "confirmed");
456
+ const statePrefix = hasConfirmed ? "[CONFIRMED] " : "";
457
+ const remedy = group[0].mitigation;
458
+ const remedyStr = remedy ? `
459
+ Fix: ${remedy}` : "";
460
+ lines.push(`- ${statePrefix}Rules ${ruleNums} (${totalFailures} failures combined): same root cause${remedyStr}`);
461
+ }
462
+ }
463
+ sections.push(`### ${label}
464
+ ${lines.join("\n")}`);
465
+ }
466
+ for (const match of matches) {
467
+ const fps = match.workflow.failurePatterns;
468
+ if (!fps?.length) continue;
469
+ const coveredRules = new Set(patterns.map((p) => p.rule));
470
+ const extra = fps.filter((fp) => !coveredRules.has(fp.rule));
471
+ for (const fp of extra) {
472
+ const remedy = RULE_MITIGATIONS[fp.rule];
473
+ const remedyStr = remedy ? ` \u2014 Fix: ${remedy}` : "";
474
+ sections.push(`- Rule ${fp.rule}: "${fp.message}"${remedyStr} (seen in similar workflows)`);
475
+ }
476
+ }
477
+ if (sections.length === 0) return null;
478
+ return `## Known Failure Patterns \u2014 AVOID THESE
479
+
480
+ Grouped by generation stage. Fix these BEFORE outputting your response:
481
+
482
+ ${sections.join("\n\n")}`;
483
+ }
484
+ buildLegacyWarnings(matches, globalFailureRates) {
485
+ const lines = [];
486
+ for (const match of matches) {
487
+ const patterns = match.workflow.failurePatterns;
488
+ if (!patterns?.length) continue;
489
+ for (const fp of patterns) {
490
+ const remedy = RULE_MITIGATIONS[fp.rule];
491
+ const remedyStr = remedy ? ` \u2014 Fix: ${remedy}` : "";
492
+ lines.push(`- Rule ${fp.rule}: "${fp.message}"${remedyStr} (seen ${fp.occurrences}x in similar workflows)`);
493
+ }
494
+ }
495
+ const highFreqRules = globalFailureRates.filter((r) => r.rate >= 0.15);
496
+ for (const rule of highFreqRules) {
497
+ const remedy = RULE_MITIGATIONS[rule.rule];
498
+ const remedyStr = remedy ? ` \u2014 Fix: ${remedy}` : "";
499
+ lines.push(`- Rule ${rule.rule}: "${rule.commonMessage}"${remedyStr} (fails in ${Math.round(rule.rate * 100)}% of all builds)`);
500
+ }
501
+ if (lines.length === 0) return null;
502
+ const unique = [...new Set(lines)];
503
+ return `## Known Failure Patterns \u2014 AVOID THESE
504
+
505
+ Previous builds frequently failed the following validation rules. Ensure your output does NOT repeat these mistakes:
506
+ ${unique.join("\n")}`;
507
+ }
508
+ buildUserMessage(request, _matches, _mode) {
509
+ const namePart = request.name ? `
510
+ Workflow name: "${request.name}"` : "";
511
+ return `Build a workflow that: ${request.description}${namePart}`;
512
+ }
513
+ };
514
+
515
+ // src/utils/workflow-type.ts
516
+ var TYPE_KEYWORDS = [
517
+ ["gmail", "email"],
518
+ ["imap", "email"],
519
+ ["smtp", "email"],
520
+ [" email", "email"],
521
+ ["slack", "slack"],
522
+ ["telegram", "messaging"],
523
+ ["discord", "messaging"],
524
+ [" sms", "messaging"],
525
+ ["twilio", "messaging"],
526
+ ["webhook", "webhook"],
527
+ ["google sheets", "data"],
528
+ ["spreadsheet", "data"],
529
+ ["airtable", "data"],
530
+ ["notion", "data"],
531
+ ["github", "devops"],
532
+ ["gitlab", "devops"],
533
+ ["schedule", "schedule"],
534
+ [" cron", "schedule"],
535
+ ["daily", "schedule"],
536
+ ["weekly", "schedule"],
537
+ ["hourly", "schedule"],
538
+ ["every day", "schedule"],
539
+ ["every hour", "schedule"],
540
+ ["every morning", "schedule"],
541
+ ["postgres", "database"],
542
+ ["mysql", "database"],
543
+ ["supabase", "database"],
544
+ ["redis", "database"],
545
+ [" database", "database"],
546
+ [" llm", "ai"],
547
+ [" gpt", "ai"],
548
+ ["claude", "ai"],
549
+ [" agent", "ai"],
550
+ ["langchain", "ai"],
551
+ [" ai ", "ai"],
552
+ [" ai", "ai"],
553
+ ["http request", "api"],
554
+ ["rest api", "api"],
555
+ [" api", "api"]
556
+ ];
557
+ function inferWorkflowType(description) {
558
+ const lower = " " + description.toLowerCase();
559
+ for (const [keyword, type] of TYPE_KEYWORDS) {
560
+ if (lower.includes(keyword)) return type;
561
+ }
562
+ return null;
563
+ }
564
+
565
+ export {
566
+ PromptBuilder,
567
+ inferWorkflowType
568
+ };
569
+ //# sourceMappingURL=chunk-EVOAYH2K.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generation/prompt-builder.ts","../src/generation/prompts/v1.ts","../src/utils/workflow-type.ts"],"sourcesContent":["import { readFileSync } from 'node:fs'\nimport { join } from 'node:path'\nimport { homedir } from 'node:os'\nimport type { WorkflowMatch } from '../library/types.js'\nimport type { RuleFailureRate } from '../telemetry/reader.js'\nimport type { PatternAnalysis, Pattern } from '../telemetry/pattern-analyzer.js'\nimport type { DesignRequest, BuiltPrompt, SystemPromptBlock } from './types.js'\nimport { SYSTEM_PROMPT_V1 } from './prompts/v1.js'\nimport { scoreToMode } from '../utils/thresholds.js'\nimport { RULE_MITIGATIONS, RULE_EXAMPLES } from '../validation/rule-metadata.js'\n\nconst CRITICAL_SCORE_THRESHOLD = 0.15\n\ntype PromptProfile = 'minimal' | 'standard' | 'rich'\n\nfunction resolveProfile(): PromptProfile {\n const env = process.env['KAIROS_PROMPT_PROFILE']\n if (env === 'minimal' || env === 'standard' || env === 'rich') return env\n return 'standard'\n}\n\nconst PROACTIVE_EXPRESSION_GUIDANCE = `## Expression Syntax Quick Reference\\n\\nAlways use these patterns in expressions:\\n- Access node data: $('NodeName').item.json.field (not $node[\"NodeName\"].json)\\n- Access JSON field: $json.field (not $json.items[0].field)\\n- Single item: $('NodeName').first().json.field\\n- All items: $('NodeName').all()`\n\nexport class PromptBuilder {\n private readonly patternsPath: string\n private readonly profile: PromptProfile\n private _lastActivePatterns: Pattern[] | null = null\n\n constructor(patternsPath?: string, profile?: PromptProfile) {\n this.patternsPath = patternsPath ?? join(homedir(), '.kairos', 'patterns.json')\n this.profile = profile ?? resolveProfile()\n }\n\n private resolveMaxPatterns(): number {\n if (this.profile === 'minimal') return 3\n if (this.profile === 'rich') return 15\n return 10\n }\n\n build(request: DesignRequest, matches: WorkflowMatch[], globalFailureRates: RuleFailureRate[] = [], dynamicCatalog?: string): BuiltPrompt {\n const mode = this.resolveMode(matches)\n const system = this.buildSystem(matches, mode, globalFailureRates, dynamicCatalog, request.description)\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 failingRuleIds?: number[],\n ): string {\n const base = this.buildUserMessage(request, matches, this.resolveMode(matches))\n\n let examplesSection = ''\n if (failingRuleIds && failingRuleIds.length > 0) {\n const uniqueRules = [...new Set(failingRuleIds)]\n const exampleLines: string[] = []\n for (const rule of uniqueRules) {\n const ex = RULE_EXAMPLES[rule]\n if (ex) {\n exampleLines.push(`Rule ${rule}:\\n Bad: ${ex.bad}\\n Good: ${ex.good}`)\n }\n }\n if (exampleLines.length > 0) {\n examplesSection = `\\n\\n## Concrete Fix Examples\\n${exampleLines.join('\\n\\n')}`\n }\n }\n\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.${examplesSection}`\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[] = [], dynamicCatalog?: string, description?: string): SystemPromptBlock[] {\n let basePrompt = SYSTEM_PROMPT_V1\n if (dynamicCatalog) {\n basePrompt = basePrompt.replace(\n /## NODE CATALOG — exact type strings and safe typeVersions[\\s\\S]*?(?=## PRE-DELIVERY SELF-CHECK)/,\n dynamicCatalog + '\\n\\n',\n )\n }\n\n const blocks: SystemPromptBlock[] = [\n {\n type: 'text',\n text: basePrompt,\n cache_control: { type: 'ephemeral' },\n },\n ]\n\n if (this.profile !== 'minimal') {\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\n const warnings = this.buildFailureWarnings(matches, globalFailureRates, description)\n if (warnings) {\n blocks.push({ type: 'text', text: warnings })\n }\n\n if (this.profile === 'rich') {\n const expressionRules = new Set([24, 25, 26])\n const expressionAlreadyCovered = (this._lastActivePatterns ?? []).some(p => expressionRules.has(p.rule))\n if (!expressionAlreadyCovered) {\n blocks.push({ type: 'text', text: PROACTIVE_EXPRESSION_GUIDANCE })\n }\n }\n\n return blocks\n }\n\n private loadPatterns(): Pattern[] {\n try {\n const raw = readFileSync(this.patternsPath, 'utf-8')\n const analysis = JSON.parse(raw) as PatternAnalysis\n const patterns = analysis.topFailureRules ?? []\n return patterns.filter(p => typeof p.pipelineStage === 'string' && typeof p.state === 'string')\n } catch {\n return []\n }\n }\n\n getWarnedRules(): number[] {\n const patterns = this._lastActivePatterns ?? this.getActivePatterns(this.resolveMaxPatterns())\n return patterns.map(p => p.rule)\n }\n\n private getActivePatterns(maxCount = 10, description?: string): Pattern[] {\n const all = this.loadPatterns()\n .filter(p => p.state !== 'resolved' && p.confidence > 0)\n\n const regressed = all.filter(p => p.regressed).sort((a, b) => b.compositeScore - a.compositeScore)\n const confirmed = all.filter(p => !p.regressed && p.state === 'confirmed').sort((a, b) => b.compositeScore - a.compositeScore)\n const drafts = all.filter(p => !p.regressed && p.state !== 'confirmed').sort((a, b) => b.compositeScore - a.compositeScore)\n\n const ordered = [...regressed, ...confirmed, ...drafts]\n\n if (this.profile === 'minimal' && description) {\n return this.rankByRelevance(ordered, description).slice(0, maxCount)\n }\n\n return ordered.slice(0, maxCount)\n }\n\n private rankByRelevance(patterns: Pattern[], description: string): Pattern[] {\n const lower = description.toLowerCase()\n const STAGE_KEYWORDS: Record<string, string[]> = {\n credential_injection: ['credential', 'auth', 'api key', 'token', 'oauth', 'smtp', 'imap', 'password', 'secret'],\n connection_wiring: ['connect', 'link', 'wire', 'chain', 'merge', 'branch', 'join'],\n expression_syntax: ['expression', 'variable', 'json', 'field', 'data', '$json', 'item'],\n workflow_structure: ['trigger', 'webhook', 'schedule', 'structure', 'workflow'],\n node_generation: ['node', 'generate', 'create', 'build', 'send', 'fetch', 'email', 'slack', 'http'],\n }\n\n return patterns\n .map(p => {\n const keywords = STAGE_KEYWORDS[p.pipelineStage] ?? []\n const relevanceBoost = keywords.some(kw => lower.includes(kw)) ? 1 : 0\n return { pattern: p, sort: relevanceBoost * 10 + p.compositeScore }\n })\n .sort((a, b) => b.sort - a.sort)\n .map(x => x.pattern)\n }\n\n private buildFailureWarnings(matches: WorkflowMatch[], globalFailureRates: RuleFailureRate[], description?: string): string | null {\n const richPatterns = this.getActivePatterns(this.resolveMaxPatterns(), description)\n this._lastActivePatterns = richPatterns\n\n if (richPatterns.length > 0) {\n return this.buildStageGroupedWarnings(richPatterns, matches)\n }\n\n return this.buildLegacyWarnings(matches, globalFailureRates)\n }\n\n private buildStageGroupedWarnings(patterns: Pattern[], matches: WorkflowMatch[]): string | null {\n const stageLabels: Record<string, string> = {\n credential_injection: 'CREDENTIAL FORMATTING',\n connection_wiring: 'CONNECTION WIRING',\n node_generation: 'NODE GENERATION',\n workflow_structure: 'WORKFLOW STRUCTURE',\n expression_syntax: 'EXPRESSION SYNTAX',\n }\n\n const byStage = new Map<string, Pattern[]>()\n for (const p of patterns) {\n const list = byStage.get(p.pipelineStage) ?? []\n list.push(p)\n byStage.set(p.pipelineStage, list)\n }\n\n const sections: string[] = []\n for (const [stage, stagePatterns] of byStage) {\n const label = stageLabels[stage] ?? stage\n\n const byMitigation = new Map<string, Pattern[]>()\n for (const p of stagePatterns) {\n const key = p.mitigation ?? `rule_${p.rule}`\n const list = byMitigation.get(key) ?? []\n list.push(p)\n byMitigation.set(key, list)\n }\n\n const lines: string[] = []\n for (const group of byMitigation.values()) {\n if (group.length === 1) {\n const p = group[0]!\n const urgency = p.regressed ? 'CRITICAL REGRESSION: ' : (p.compositeScore ?? 0) >= CRITICAL_SCORE_THRESHOLD ? 'CRITICAL: ' : ''\n const statePrefix = p.state === 'confirmed' ? '[CONFIRMED] ' : ''\n const trendSuffix = p.trend === 'worsening' ? ' (GETTING WORSE)' : p.trend === 'improving' ? ' (improving)' : ''\n const remedy = p.mitigation ?? RULE_MITIGATIONS[p.rule]\n const remedyStr = remedy ? `\\n Fix: ${remedy}` : ''\n const ex = RULE_EXAMPLES[p.rule]\n const exampleStr = ex ? `\\n Bad: ${ex.bad}\\n Good: ${ex.good}` : ''\n lines.push(`- ${urgency}${statePrefix}Rule ${p.rule}${trendSuffix}: ${p.exampleMessages[0] ?? 'No example'}${remedyStr}${exampleStr}`)\n } else {\n const ruleNums = group.map(p => p.rule).join(', ')\n const totalFailures = group.reduce((s, p) => s + p.failureCount, 0)\n const hasConfirmed = group.some(p => p.state === 'confirmed')\n const statePrefix = hasConfirmed ? '[CONFIRMED] ' : ''\n const remedy = group[0]!.mitigation\n const remedyStr = remedy ? `\\n Fix: ${remedy}` : ''\n lines.push(`- ${statePrefix}Rules ${ruleNums} (${totalFailures} failures combined): same root cause${remedyStr}`)\n }\n }\n sections.push(`### ${label}\\n${lines.join('\\n')}`)\n }\n\n for (const match of matches) {\n const fps = match.workflow.failurePatterns\n if (!fps?.length) continue\n const coveredRules = new Set(patterns.map(p => p.rule))\n const extra = fps.filter(fp => !coveredRules.has(fp.rule))\n for (const fp of extra) {\n const remedy = RULE_MITIGATIONS[fp.rule]\n const remedyStr = remedy ? ` — Fix: ${remedy}` : ''\n sections.push(`- Rule ${fp.rule}: \"${fp.message}\"${remedyStr} (seen in similar workflows)`)\n }\n }\n\n if (sections.length === 0) return null\n\n return `## Known Failure Patterns — AVOID THESE\\n\\nGrouped by generation stage. Fix these BEFORE outputting your response:\\n\\n${sections.join('\\n\\n')}`\n }\n\n private buildLegacyWarnings(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_MITIGATIONS[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_MITIGATIONS[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","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- Each credential is keyed by its type string, with an object value containing id and name:\n \"credentials\": { \"slackOAuth2Api\": { \"id\": \"placeholder-id\", \"name\": \"My Slack Credential\" } }\n- Use \"placeholder-id\" as the id — users replace this with their real credential ID from n8n after deployment\n- The credentialsNeeded field in your response declares what credentials the user must configure\n- Never put API keys or tokens directly in node 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## EXPRESSION SYNTAX — how to reference upstream node data\n\n### Accessing a field from an upstream node:\n- CORRECT: $('NodeName').item.json.field\n- WRONG: $node[\"NodeName\"].json.field ← deprecated accessor, fails at runtime (Rule 24)\n\n### Accessing array items from $json:\n- CORRECT: $json.field ← n8n auto-flattens items; each item is already a flat object\n- WRONG: $json.items[0].field ← do not index into items[] (Rule 25)\n\n### Calling node data — always qualify with .first() or .all():\n- CORRECT: $('NodeName').first().json.field ← single item\n- CORRECT: $('NodeName').all() ← array of all items\n- WRONG: $('NodeName').json ← throws at runtime without .first() or .all() (Rule 26)\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\"\n8. No deprecated $node[\"NodeName\"].json — use $('NodeName').item.json.field\n9. No $json.items[0] array indexing — access fields directly as $json.field\n10. No bare $('NodeName').json — always use .first().json.field or .all()\n11. httpRequest URL is a real endpoint (not \"example.com\" or \"YOUR_URL\")\n12. code nodes contain actual logic — not empty or comment-only\n13. Slack message nodes have a channel specified (channelId or channel)\n14. Gmail send nodes have a recipient (to field non-empty)\n15. if nodes have at least one condition in conditions.conditions[]\n16. set nodes have at least one entry in assignments.assignments[]\n17. scheduleTrigger has at least one rule in rule.interval[]\n18. webhook path is relative (no spaces, no leading slash, no http://)\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","const TYPE_KEYWORDS: Array<[string, string]> = [\n ['gmail', 'email'],\n ['imap', 'email'],\n ['smtp', 'email'],\n [' email', 'email'],\n ['slack', 'slack'],\n ['telegram', 'messaging'],\n ['discord', 'messaging'],\n [' sms', 'messaging'],\n ['twilio', 'messaging'],\n ['webhook', 'webhook'],\n ['google sheets', 'data'],\n ['spreadsheet', 'data'],\n ['airtable', 'data'],\n ['notion', 'data'],\n ['github', 'devops'],\n ['gitlab', 'devops'],\n ['schedule', 'schedule'],\n [' cron', 'schedule'],\n ['daily', 'schedule'],\n ['weekly', 'schedule'],\n ['hourly', 'schedule'],\n ['every day', 'schedule'],\n ['every hour', 'schedule'],\n ['every morning', 'schedule'],\n ['postgres', 'database'],\n ['mysql', 'database'],\n ['supabase', 'database'],\n ['redis', 'database'],\n [' database', 'database'],\n [' llm', 'ai'],\n [' gpt', 'ai'],\n ['claude', 'ai'],\n [' agent', 'ai'],\n ['langchain', 'ai'],\n [' ai ', 'ai'],\n [' ai', 'ai'],\n ['http request', 'api'],\n ['rest api', 'api'],\n [' api', 'api'],\n]\n\nexport function inferWorkflowType(description: string): string | null {\n const lower = ' ' + description.toLowerCase()\n for (const [keyword, type] of TYPE_KEYWORDS) {\n if (lower.includes(keyword)) return type\n }\n return null\n}\n"],"mappings":";;;;;;;AAAA,SAAS,oBAAoB;AAC7B,SAAS,YAAY;AACrB,SAAS,eAAe;;;ACFjB,IAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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