@n8n/instance-ai 1.5.0 → 1.6.1

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.
Files changed (185) hide show
  1. package/dist/agent/computer-use-prompt.d.ts +5 -0
  2. package/dist/agent/computer-use-prompt.js +97 -0
  3. package/dist/agent/computer-use-prompt.js.map +1 -0
  4. package/dist/agent/instance-agent.js +48 -72
  5. package/dist/agent/instance-agent.js.map +1 -1
  6. package/dist/agent/mcp-tool-name-validation.d.ts +15 -0
  7. package/dist/agent/mcp-tool-name-validation.js +67 -0
  8. package/dist/agent/mcp-tool-name-validation.js.map +1 -0
  9. package/dist/agent/sanitize-mcp-schemas.d.ts +56 -2
  10. package/dist/agent/sanitize-mcp-schemas.js +226 -19
  11. package/dist/agent/sanitize-mcp-schemas.js.map +1 -1
  12. package/dist/agent/sub-agent-factory.d.ts +1 -0
  13. package/dist/agent/sub-agent-factory.js +1 -0
  14. package/dist/agent/sub-agent-factory.js.map +1 -1
  15. package/dist/agent/system-prompt.d.ts +1 -1
  16. package/dist/agent/system-prompt.js +19 -99
  17. package/dist/agent/system-prompt.js.map +1 -1
  18. package/dist/build.tsbuildinfo +1 -1
  19. package/dist/domain-access/domain-access-tracker.d.ts +3 -0
  20. package/dist/domain-access/domain-access-tracker.js +16 -0
  21. package/dist/domain-access/domain-access-tracker.js.map +1 -1
  22. package/dist/domain-access/domain-gating.d.ts +35 -6
  23. package/dist/domain-access/domain-gating.js +47 -1
  24. package/dist/domain-access/domain-gating.js.map +1 -1
  25. package/dist/domain-access/index.d.ts +1 -1
  26. package/dist/domain-access/index.js +3 -1
  27. package/dist/domain-access/index.js.map +1 -1
  28. package/dist/index.d.ts +10 -4
  29. package/dist/index.js +16 -2
  30. package/dist/index.js.map +1 -1
  31. package/dist/mcp/mcp-client-manager.d.ts +18 -2
  32. package/dist/mcp/mcp-client-manager.js +124 -20
  33. package/dist/mcp/mcp-client-manager.js.map +1 -1
  34. package/dist/parsers/docx-parser.d.ts +6 -0
  35. package/dist/parsers/docx-parser.js +65 -0
  36. package/dist/parsers/docx-parser.js.map +1 -0
  37. package/dist/parsers/html-parser.d.ts +7 -0
  38. package/dist/parsers/html-parser.js +67 -0
  39. package/dist/parsers/html-parser.js.map +1 -0
  40. package/dist/parsers/index.d.ts +4 -0
  41. package/dist/parsers/index.js +16 -0
  42. package/dist/parsers/index.js.map +1 -0
  43. package/dist/parsers/pdf-parser.d.ts +7 -0
  44. package/dist/parsers/pdf-parser.js +72 -0
  45. package/dist/parsers/pdf-parser.js.map +1 -0
  46. package/dist/parsers/structured-file-parser.d.ts +8 -3
  47. package/dist/parsers/structured-file-parser.js +36 -4
  48. package/dist/parsers/structured-file-parser.js.map +1 -1
  49. package/dist/parsers/validate-attachments.d.ts +14 -0
  50. package/dist/parsers/validate-attachments.js +61 -0
  51. package/dist/parsers/validate-attachments.js.map +1 -0
  52. package/dist/parsers/xlsx-parser.d.ts +2 -0
  53. package/dist/parsers/xlsx-parser.js +75 -0
  54. package/dist/parsers/xlsx-parser.js.map +1 -0
  55. package/dist/runtime/background-task-manager.d.ts +7 -0
  56. package/dist/runtime/background-task-manager.js +68 -2
  57. package/dist/runtime/background-task-manager.js.map +1 -1
  58. package/dist/runtime/liveness-policy.d.ts +40 -0
  59. package/dist/runtime/liveness-policy.js +74 -0
  60. package/dist/runtime/liveness-policy.js.map +1 -0
  61. package/dist/runtime/resumable-stream-executor.d.ts +1 -0
  62. package/dist/runtime/resumable-stream-executor.js +1 -0
  63. package/dist/runtime/resumable-stream-executor.js.map +1 -1
  64. package/dist/runtime/run-state-registry.d.ts +14 -1
  65. package/dist/runtime/run-state-registry.js +100 -7
  66. package/dist/runtime/run-state-registry.js.map +1 -1
  67. package/dist/runtime/stream-runner.d.ts +3 -0
  68. package/dist/runtime/stream-runner.js +3 -0
  69. package/dist/runtime/stream-runner.js.map +1 -1
  70. package/dist/runtime/terminal-response-guard.d.ts +30 -0
  71. package/dist/runtime/terminal-response-guard.js +149 -0
  72. package/dist/runtime/terminal-response-guard.js.map +1 -0
  73. package/dist/storage/agent-tree-snapshot.d.ts +2 -0
  74. package/dist/storage/index.d.ts +2 -0
  75. package/dist/storage/index.js +3 -1
  76. package/dist/storage/index.js.map +1 -1
  77. package/dist/storage/terminal-outcome-storage.d.ts +48 -0
  78. package/dist/storage/terminal-outcome-storage.js +84 -0
  79. package/dist/storage/terminal-outcome-storage.js.map +1 -0
  80. package/dist/storage/workflow-loop-storage.d.ts +156 -10
  81. package/dist/stream/consume-with-hitl.d.ts +1 -0
  82. package/dist/stream/consume-with-hitl.js +1 -0
  83. package/dist/stream/consume-with-hitl.js.map +1 -1
  84. package/dist/stream/map-chunk.js +6 -0
  85. package/dist/stream/map-chunk.js.map +1 -1
  86. package/dist/tools/attachments/parse-file.tool.d.ts +46 -34
  87. package/dist/tools/attachments/parse-file.tool.js +115 -56
  88. package/dist/tools/attachments/parse-file.tool.js.map +1 -1
  89. package/dist/tools/credentials.tool.d.ts +120 -1
  90. package/dist/tools/credentials.tool.js +65 -12
  91. package/dist/tools/credentials.tool.js.map +1 -1
  92. package/dist/tools/data-tables.tool.d.ts +1 -0
  93. package/dist/tools/data-tables.tool.js +4 -2
  94. package/dist/tools/data-tables.tool.js.map +1 -1
  95. package/dist/tools/filesystem/create-tools-from-mcp-server.d.ts +2 -1
  96. package/dist/tools/filesystem/create-tools-from-mcp-server.js +74 -5
  97. package/dist/tools/filesystem/create-tools-from-mcp-server.js.map +1 -1
  98. package/dist/tools/index.d.ts +3 -22
  99. package/dist/tools/index.js +21 -4
  100. package/dist/tools/index.js.map +1 -1
  101. package/dist/tools/nodes.tool.js +15 -15
  102. package/dist/tools/nodes.tool.js.map +1 -1
  103. package/dist/tools/orchestration/blueprint.schema.d.ts +1 -1
  104. package/dist/tools/orchestration/browser-credential-setup.nudge.d.ts +5 -0
  105. package/dist/tools/orchestration/browser-credential-setup.nudge.js +11 -0
  106. package/dist/tools/orchestration/browser-credential-setup.nudge.js.map +1 -0
  107. package/dist/tools/orchestration/browser-credential-setup.prompt.js +2 -1
  108. package/dist/tools/orchestration/browser-credential-setup.prompt.js.map +1 -1
  109. package/dist/tools/orchestration/browser-credential-setup.tool.js +55 -7
  110. package/dist/tools/orchestration/browser-credential-setup.tool.js.map +1 -1
  111. package/dist/tools/orchestration/build-workflow-agent.prompt.js +45 -48
  112. package/dist/tools/orchestration/build-workflow-agent.prompt.js.map +1 -1
  113. package/dist/tools/orchestration/build-workflow-agent.tool.d.ts +8 -3
  114. package/dist/tools/orchestration/build-workflow-agent.tool.js +202 -47
  115. package/dist/tools/orchestration/build-workflow-agent.tool.js.map +1 -1
  116. package/dist/tools/orchestration/data-table-agent.tool.js +1 -0
  117. package/dist/tools/orchestration/data-table-agent.tool.js.map +1 -1
  118. package/dist/tools/orchestration/delegate.tool.js +2 -0
  119. package/dist/tools/orchestration/delegate.tool.js.map +1 -1
  120. package/dist/tools/orchestration/plan-agent-prompt.d.ts +1 -1
  121. package/dist/tools/orchestration/plan-agent-prompt.js +1 -0
  122. package/dist/tools/orchestration/plan-agent-prompt.js.map +1 -1
  123. package/dist/tools/orchestration/plan-with-agent.tool.d.ts +17 -2
  124. package/dist/tools/orchestration/plan-with-agent.tool.js +274 -4
  125. package/dist/tools/orchestration/plan-with-agent.tool.js.map +1 -1
  126. package/dist/tools/orchestration/research-with-agent.tool.js +1 -0
  127. package/dist/tools/orchestration/research-with-agent.tool.js.map +1 -1
  128. package/dist/tools/orchestration/tracing-utils.js +8 -0
  129. package/dist/tools/orchestration/tracing-utils.js.map +1 -1
  130. package/dist/tools/research.tool.js +54 -8
  131. package/dist/tools/research.tool.js.map +1 -1
  132. package/dist/tools/shared/ask-user.tool.d.ts +1 -0
  133. package/dist/tools/shared/ask-user.tool.js +3 -2
  134. package/dist/tools/shared/ask-user.tool.js.map +1 -1
  135. package/dist/tools/workflows/build-workflow.tool.js +3 -3
  136. package/dist/tools/workflows/build-workflow.tool.js.map +1 -1
  137. package/dist/tools/workflows/resolve-credentials.d.ts +9 -4
  138. package/dist/tools/workflows/resolve-credentials.js +59 -27
  139. package/dist/tools/workflows/resolve-credentials.js.map +1 -1
  140. package/dist/tools/workflows/setup-workflow.schema.d.ts +40 -0
  141. package/dist/tools/workflows/setup-workflow.service.d.ts +5 -1
  142. package/dist/tools/workflows/setup-workflow.service.js +71 -5
  143. package/dist/tools/workflows/setup-workflow.service.js.map +1 -1
  144. package/dist/tools/workflows/submit-workflow-identity.d.ts +2 -2
  145. package/dist/tools/workflows/submit-workflow-identity.js +2 -2
  146. package/dist/tools/workflows/submit-workflow-identity.js.map +1 -1
  147. package/dist/tools/workflows/submit-workflow.tool.d.ts +13 -4
  148. package/dist/tools/workflows/submit-workflow.tool.js +37 -24
  149. package/dist/tools/workflows/submit-workflow.tool.js.map +1 -1
  150. package/dist/tools/workflows/workflow-json-utils.d.ts +4 -0
  151. package/dist/tools/workflows/workflow-json-utils.js +54 -0
  152. package/dist/tools/workflows/workflow-json-utils.js.map +1 -0
  153. package/dist/tools/workflows.tool.d.ts +7 -1
  154. package/dist/tools/workflows.tool.js +283 -54
  155. package/dist/tools/workflows.tool.js.map +1 -1
  156. package/dist/tracing/langsmith-tracing.d.ts +2 -0
  157. package/dist/tracing/langsmith-tracing.js +4 -0
  158. package/dist/tracing/langsmith-tracing.js.map +1 -1
  159. package/dist/types.d.ts +13 -4
  160. package/dist/workflow-builder/parse-validate.js +1 -1
  161. package/dist/workflow-builder/parse-validate.js.map +1 -1
  162. package/dist/workflow-loop/index.d.ts +2 -2
  163. package/dist/workflow-loop/index.js +3 -1
  164. package/dist/workflow-loop/index.js.map +1 -1
  165. package/dist/workflow-loop/workflow-loop-state.d.ts +168 -8
  166. package/dist/workflow-loop/workflow-loop-state.js +31 -1
  167. package/dist/workflow-loop/workflow-loop-state.js.map +1 -1
  168. package/dist/workspace/builder-sandbox-factory.d.ts +0 -2
  169. package/dist/workspace/builder-sandbox-factory.js +0 -8
  170. package/dist/workspace/builder-sandbox-factory.js.map +1 -1
  171. package/dist/workspace/n8n-sandbox-filesystem.js +2 -2
  172. package/dist/workspace/n8n-sandbox-filesystem.js.map +1 -1
  173. package/dist/workspace/n8n-sandbox-sandbox.d.ts +2 -3
  174. package/dist/workspace/n8n-sandbox-sandbox.js +3 -7
  175. package/dist/workspace/n8n-sandbox-sandbox.js.map +1 -1
  176. package/dist/workspace/sandbox-setup.d.ts +1 -1
  177. package/dist/workspace/sandbox-setup.js +5 -8
  178. package/dist/workspace/sandbox-setup.js.map +1 -1
  179. package/package.json +28 -9
  180. package/dist/workspace/n8n-sandbox-client.d.ts +0 -105
  181. package/dist/workspace/n8n-sandbox-client.js +0 -335
  182. package/dist/workspace/n8n-sandbox-client.js.map +0 -1
  183. package/dist/workspace/n8n-sandbox-image-manager.d.ts +0 -5
  184. package/dist/workspace/n8n-sandbox-image-manager.js +0 -25
  185. package/dist/workspace/n8n-sandbox-image-manager.js.map +0 -1
@@ -1,21 +1,155 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.McpSchemaSanitizationError = exports.MCP_SCHEMA_MAX_UNION_OPTIONS = exports.MCP_SCHEMA_MAX_OBJECT_PROPERTIES = exports.MCP_SCHEMA_MAX_NODES = exports.MCP_SCHEMA_MAX_DEPTH = void 0;
4
+ exports.assertMcpJsonSchemaWithinLimits = assertMcpJsonSchemaWithinLimits;
3
5
  exports.sanitizeZodType = sanitizeZodType;
4
6
  exports.ensureTopLevelObject = ensureTopLevelObject;
5
7
  exports.sanitizeInputSchema = sanitizeInputSchema;
6
8
  exports.sanitizeMcpToolSchemas = sanitizeMcpToolSchemas;
7
9
  const zod_1 = require("zod");
8
- function sanitizeZodType(schema, strict = false) {
10
+ exports.MCP_SCHEMA_MAX_DEPTH = 32;
11
+ exports.MCP_SCHEMA_MAX_NODES = 1_000;
12
+ exports.MCP_SCHEMA_MAX_OBJECT_PROPERTIES = 250;
13
+ exports.MCP_SCHEMA_MAX_UNION_OPTIONS = 100;
14
+ class McpSchemaSanitizationError extends Error {
15
+ details;
16
+ constructor(message, details) {
17
+ super(message);
18
+ this.details = details;
19
+ this.name = 'McpSchemaSanitizationError';
20
+ }
21
+ }
22
+ exports.McpSchemaSanitizationError = McpSchemaSanitizationError;
23
+ function isRecord(value) {
24
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
25
+ }
26
+ function throwJsonSchemaLimitError(context, path, depth, message, limitType, limit, count) {
27
+ throw new McpSchemaSanitizationError(message, {
28
+ toolName: context.toolName,
29
+ path,
30
+ depth,
31
+ maxDepth: context.maxDepth,
32
+ limit,
33
+ limitType,
34
+ count,
35
+ });
36
+ }
37
+ function validateJsonSchemaNode(value, path, depth, context) {
38
+ if (depth > context.maxDepth) {
39
+ throwJsonSchemaLimitError(context, path, depth, `MCP schema exceeds maximum depth of ${context.maxDepth}`, 'depth', context.maxDepth, depth);
40
+ }
41
+ context.budget.nodes++;
42
+ if (context.budget.nodes > context.maxNodes) {
43
+ throwJsonSchemaLimitError(context, path, depth, `MCP schema exceeds maximum node count of ${context.maxNodes}`, 'nodes', context.maxNodes, context.budget.nodes);
44
+ }
45
+ if (Array.isArray(value)) {
46
+ for (const [index, item] of value.entries()) {
47
+ validateJsonSchemaNode(item, `${path}[${index}]`, depth + 1, context);
48
+ }
49
+ return;
50
+ }
51
+ if (!isRecord(value))
52
+ return;
53
+ const properties = value.properties;
54
+ if (isRecord(properties)) {
55
+ const propertyCount = Object.keys(properties).length;
56
+ if (propertyCount > context.maxObjectProperties) {
57
+ throwJsonSchemaLimitError(context, `${path}.properties`, depth + 1, `MCP schema object exceeds maximum property count of ${context.maxObjectProperties}`, 'objectProperties', context.maxObjectProperties, propertyCount);
58
+ }
59
+ }
60
+ for (const unionKey of ['anyOf', 'oneOf', 'allOf']) {
61
+ const unionOptions = value[unionKey];
62
+ if (Array.isArray(unionOptions) && unionOptions.length > context.maxUnionOptions) {
63
+ throwJsonSchemaLimitError(context, `${path}.${unionKey}`, depth + 1, `MCP schema union exceeds maximum option count of ${context.maxUnionOptions}`, 'unionOptions', context.maxUnionOptions, unionOptions.length);
64
+ }
65
+ }
66
+ for (const [key, child] of Object.entries(value)) {
67
+ validateJsonSchemaNode(child, `${path}.${key}`, depth + 1, context);
68
+ }
69
+ }
70
+ function assertMcpJsonSchemaWithinLimits(schema, options = {}) {
71
+ validateJsonSchemaNode(schema, '$.inputSchema', 0, {
72
+ toolName: options.toolName,
73
+ maxDepth: options.maxDepth ?? exports.MCP_SCHEMA_MAX_DEPTH,
74
+ maxNodes: options.maxNodes ?? exports.MCP_SCHEMA_MAX_NODES,
75
+ maxObjectProperties: options.maxObjectProperties ?? exports.MCP_SCHEMA_MAX_OBJECT_PROPERTIES,
76
+ maxUnionOptions: options.maxUnionOptions ?? exports.MCP_SCHEMA_MAX_UNION_OPTIONS,
77
+ budget: { nodes: 0 },
78
+ });
79
+ }
80
+ function sanitizeZodType(schema, strict = false, options = {}) {
81
+ return sanitizeZodTypeInner(schema, {
82
+ strict,
83
+ toolName: options.toolName,
84
+ path: options.path ?? '$',
85
+ depth: 0,
86
+ maxDepth: options.maxDepth ?? exports.MCP_SCHEMA_MAX_DEPTH,
87
+ maxNodes: options.maxNodes ?? exports.MCP_SCHEMA_MAX_NODES,
88
+ maxObjectProperties: options.maxObjectProperties ?? exports.MCP_SCHEMA_MAX_OBJECT_PROPERTIES,
89
+ maxUnionOptions: options.maxUnionOptions ?? exports.MCP_SCHEMA_MAX_UNION_OPTIONS,
90
+ budget: options.budget ?? { nodes: 0 },
91
+ });
92
+ }
93
+ function createLimitError(context, message, limitType, limit, count) {
94
+ return new McpSchemaSanitizationError(message, {
95
+ toolName: context.toolName,
96
+ path: context.path,
97
+ depth: context.depth,
98
+ maxDepth: context.maxDepth,
99
+ limit,
100
+ limitType,
101
+ count,
102
+ });
103
+ }
104
+ function createUnsupportedTypeError(context, schema) {
105
+ const definition = schema._def;
106
+ const zodType = typeof definition.typeName === 'string' ? definition.typeName : schema.constructor.name;
107
+ return new McpSchemaSanitizationError(`MCP schema contains unsupported Zod type ${zodType}`, {
108
+ toolName: context.toolName,
109
+ path: context.path,
110
+ depth: context.depth,
111
+ maxDepth: context.maxDepth,
112
+ limitType: 'unsupportedType',
113
+ zodType,
114
+ });
115
+ }
116
+ function isSupportedLeafSchema(schema) {
117
+ return (schema instanceof zod_1.z.ZodString ||
118
+ schema instanceof zod_1.z.ZodNumber ||
119
+ schema instanceof zod_1.z.ZodBoolean ||
120
+ schema instanceof zod_1.z.ZodDate ||
121
+ schema instanceof zod_1.z.ZodAny ||
122
+ schema instanceof zod_1.z.ZodUnknown ||
123
+ schema instanceof zod_1.z.ZodLiteral ||
124
+ schema instanceof zod_1.z.ZodEnum ||
125
+ schema instanceof zod_1.z.ZodNativeEnum);
126
+ }
127
+ function sanitizeZodTypeInner(schema, context) {
128
+ if (context.depth > context.maxDepth) {
129
+ throw createLimitError(context, `MCP schema exceeds maximum depth of ${context.maxDepth}`, 'depth', context.maxDepth, context.depth);
130
+ }
131
+ context.budget.nodes++;
132
+ if (context.budget.nodes > context.maxNodes) {
133
+ throw createLimitError(context, `MCP schema exceeds maximum node count of ${context.maxNodes}`, 'nodes', context.maxNodes, context.budget.nodes);
134
+ }
135
+ const sanitizeChild = (child, path) => sanitizeZodTypeInner(child, {
136
+ ...context,
137
+ path,
138
+ depth: context.depth + 1,
139
+ });
9
140
  if (schema instanceof zod_1.z.ZodNull) {
10
141
  return zod_1.z.string().optional();
11
142
  }
12
143
  if (schema instanceof zod_1.z.ZodNullable) {
13
- return sanitizeZodType(schema.unwrap(), strict).optional();
144
+ return sanitizeChild(schema.unwrap(), `${context.path}?`).optional();
14
145
  }
15
146
  if (schema instanceof zod_1.z.ZodDiscriminatedUnion) {
16
147
  const disc = schema;
17
148
  const discriminator = disc.discriminator;
18
149
  const variants = [...disc.options.values()];
150
+ if (variants.length > context.maxUnionOptions) {
151
+ throw createLimitError(context, `MCP schema discriminated union exceeds maximum option count of ${context.maxUnionOptions}`, 'unionOptions', context.maxUnionOptions, variants.length);
152
+ }
19
153
  const actionMeta = [];
20
154
  const fieldMeta = new Map();
21
155
  for (const variant of variants) {
@@ -38,6 +172,10 @@ function sanitizeZodType(schema, strict = false) {
38
172
  });
39
173
  }
40
174
  }
175
+ const mergedPropertyCount = fieldMeta.size + (actionMeta.length > 0 ? 1 : 0);
176
+ if (mergedPropertyCount > context.maxObjectProperties) {
177
+ throw createLimitError(context, `MCP schema object exceeds maximum property count of ${context.maxObjectProperties}`, 'objectProperties', context.maxObjectProperties, mergedPropertyCount);
178
+ }
41
179
  const mergedShape = {};
42
180
  if (actionMeta.length > 0) {
43
181
  const enumValues = actionMeta.map((a) => a.value);
@@ -47,8 +185,8 @@ function sanitizeZodType(schema, strict = false) {
47
185
  .describe(actionDescParts.join(' | '));
48
186
  }
49
187
  for (const [fieldName, entries] of fieldMeta) {
50
- const sanitizedField = sanitizeZodType(entries[0].type, strict).optional();
51
- if (strict && entries.length > 1) {
188
+ const sanitizedField = sanitizeChild(entries[0].type, `${context.path}.${fieldName}`).optional();
189
+ if (context.strict && entries.length > 1) {
52
190
  const unwrapOptional = (t) => t instanceof zod_1.z.ZodOptional ? unwrapOptional(t.unwrap()) : t;
53
191
  const enumEntries = entries.filter((e) => {
54
192
  return unwrapOptional(e.type) instanceof zod_1.z.ZodEnum;
@@ -76,7 +214,7 @@ function sanitizeZodType(schema, strict = false) {
76
214
  const withDesc = entries.filter((e) => !!e.description);
77
215
  const uniqueDescs = new Set(withDesc.map((d) => d.description));
78
216
  if (uniqueDescs.size > 1) {
79
- if (strict) {
217
+ if (context.strict) {
80
218
  const conflictDetails = withDesc
81
219
  .map((d) => ` Action "${d.action}": "${d.description}"`)
82
220
  .join('\n');
@@ -102,9 +240,12 @@ function sanitizeZodType(schema, strict = false) {
102
240
  if (schema instanceof zod_1.z.ZodUnion) {
103
241
  const options = schema
104
242
  .options;
243
+ if (options.length > context.maxUnionOptions) {
244
+ throw createLimitError(context, `MCP schema union exceeds maximum option count of ${context.maxUnionOptions}`, 'unionOptions', context.maxUnionOptions, options.length);
245
+ }
105
246
  const nonNull = options.filter((o) => !(o instanceof zod_1.z.ZodNull));
106
247
  const hadNull = nonNull.length < options.length;
107
- const sanitized = nonNull.map((o) => sanitizeZodType(o, strict));
248
+ const sanitized = nonNull.map((o, index) => sanitizeChild(o, `${context.path}.union[${index}]`));
108
249
  if (sanitized.length === 0) {
109
250
  return zod_1.z.string().optional();
110
251
  }
@@ -116,26 +257,65 @@ function sanitizeZodType(schema, strict = false) {
116
257
  }
117
258
  if (schema instanceof zod_1.z.ZodObject) {
118
259
  const shape = schema.shape;
260
+ const entries = Object.entries(shape);
261
+ if (entries.length > context.maxObjectProperties) {
262
+ throw createLimitError(context, `MCP schema object exceeds maximum property count of ${context.maxObjectProperties}`, 'objectProperties', context.maxObjectProperties, entries.length);
263
+ }
119
264
  const newShape = {};
120
- for (const [key, value] of Object.entries(shape)) {
121
- newShape[key] = sanitizeZodType(value, strict);
265
+ for (const [key, value] of entries) {
266
+ newShape[key] = sanitizeChild(value, `${context.path}.${key}`);
122
267
  }
123
268
  return zod_1.z.object(newShape);
124
269
  }
270
+ if (schema instanceof zod_1.z.ZodLazy) {
271
+ return sanitizeChild(schema.schema, `${context.path}.lazy`);
272
+ }
125
273
  if (schema instanceof zod_1.z.ZodOptional) {
126
- return sanitizeZodType(schema.unwrap(), strict).optional();
274
+ return sanitizeChild(schema.unwrap(), `${context.path}?`).optional();
127
275
  }
128
276
  if (schema instanceof zod_1.z.ZodArray) {
129
- return zod_1.z.array(sanitizeZodType(schema.element, strict));
277
+ return zod_1.z.array(sanitizeChild(schema.element, `${context.path}[]`));
130
278
  }
131
279
  if (schema instanceof zod_1.z.ZodDefault) {
132
280
  const inner = schema._def.innerType;
133
- return sanitizeZodType(inner, strict).default(schema._def.defaultValue());
281
+ return sanitizeChild(inner, `${context.path}.default`).default(schema._def.defaultValue());
134
282
  }
135
283
  if (schema instanceof zod_1.z.ZodRecord) {
136
- return zod_1.z.record(sanitizeZodType(schema.valueSchema, strict));
284
+ return zod_1.z.record(sanitizeChild(schema.valueSchema, `${context.path}.*`));
285
+ }
286
+ if (schema instanceof zod_1.z.ZodEffects) {
287
+ return sanitizeChild(schema.innerType(), `${context.path}.effect`);
288
+ }
289
+ if (schema instanceof zod_1.z.ZodPipeline) {
290
+ const pipeline = schema;
291
+ return zod_1.z.pipeline(sanitizeChild(pipeline._def.in, `${context.path}.pipeline.in`), sanitizeChild(pipeline._def.out, `${context.path}.pipeline.out`));
137
292
  }
138
- return schema;
293
+ if (schema instanceof zod_1.z.ZodReadonly) {
294
+ return sanitizeChild(schema.unwrap(), `${context.path}.readonly`);
295
+ }
296
+ if (schema instanceof zod_1.z.ZodBranded) {
297
+ return sanitizeChild(schema.unwrap(), `${context.path}.brand`);
298
+ }
299
+ if (schema instanceof zod_1.z.ZodCatch) {
300
+ return sanitizeChild(schema.removeCatch(), `${context.path}.catch`);
301
+ }
302
+ if (schema instanceof zod_1.z.ZodMap ||
303
+ schema instanceof zod_1.z.ZodSet ||
304
+ schema instanceof zod_1.z.ZodPromise ||
305
+ schema instanceof zod_1.z.ZodFunction ||
306
+ schema instanceof zod_1.z.ZodIntersection ||
307
+ schema instanceof zod_1.z.ZodTuple ||
308
+ schema instanceof zod_1.z.ZodNaN ||
309
+ schema instanceof zod_1.z.ZodBigInt ||
310
+ schema instanceof zod_1.z.ZodUndefined ||
311
+ schema instanceof zod_1.z.ZodNever ||
312
+ schema instanceof zod_1.z.ZodVoid ||
313
+ schema instanceof zod_1.z.ZodSymbol) {
314
+ throw createUnsupportedTypeError(context, schema);
315
+ }
316
+ if (isSupportedLeafSchema(schema))
317
+ return schema;
318
+ throw createUnsupportedTypeError(context, schema);
139
319
  }
140
320
  function ensureTopLevelObject(schema) {
141
321
  if (schema instanceof zod_1.z.ZodObject || schema instanceof zod_1.z.ZodRecord) {
@@ -146,14 +326,41 @@ function ensureTopLevelObject(schema) {
146
326
  function sanitizeInputSchema(schema) {
147
327
  return ensureTopLevelObject(sanitizeZodType(schema, true));
148
328
  }
149
- function sanitizeMcpToolSchemas(tools) {
150
- for (const tool of Object.values(tools)) {
329
+ function sanitizeMcpToolSchemas(tools, options = {}) {
330
+ for (const [name, tool] of Object.entries(tools)) {
151
331
  const t = tool;
152
- if (t.inputSchema) {
153
- t.inputSchema = ensureTopLevelObject(sanitizeZodType(t.inputSchema));
332
+ const budget = { nodes: 0 };
333
+ try {
334
+ if (t.inputSchema) {
335
+ t.inputSchema = ensureTopLevelObject(sanitizeZodType(t.inputSchema, false, {
336
+ maxDepth: options.maxDepth,
337
+ maxNodes: options.maxNodes,
338
+ maxObjectProperties: options.maxObjectProperties,
339
+ maxUnionOptions: options.maxUnionOptions,
340
+ toolName: name,
341
+ path: '$.inputSchema',
342
+ budget,
343
+ }));
344
+ }
345
+ if (t.outputSchema) {
346
+ t.outputSchema = sanitizeZodType(t.outputSchema, false, {
347
+ maxDepth: options.maxDepth,
348
+ maxNodes: options.maxNodes,
349
+ maxObjectProperties: options.maxObjectProperties,
350
+ maxUnionOptions: options.maxUnionOptions,
351
+ toolName: name,
352
+ path: '$.outputSchema',
353
+ budget,
354
+ });
355
+ }
154
356
  }
155
- if (t.outputSchema) {
156
- t.outputSchema = sanitizeZodType(t.outputSchema);
357
+ catch (error) {
358
+ if (error instanceof McpSchemaSanitizationError) {
359
+ delete tools[name];
360
+ options.onError?.(error);
361
+ continue;
362
+ }
363
+ throw error;
157
364
  }
158
365
  }
159
366
  return tools;
@@ -1 +1 @@
1
- {"version":3,"file":"sanitize-mcp-schemas.js","sourceRoot":"","sources":["../../src/agent/sanitize-mcp-schemas.ts"],"names":[],"mappings":";;AAyBA,0CA8LC;AAQD,oDAOC;AAeD,kDAEC;AAcD,wDAYC;AAlQD,6BAAwB;AAUxB,SAAgB,eAAe,CAAC,MAAoB,EAAE,MAAM,GAAG,KAAK;IAEnE,IAAI,MAAM,YAAY,OAAC,CAAC,OAAO,EAAE,CAAC;QACjC,OAAO,OAAC,CAAC,MAA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oBAC1B,QAAQ,EAAE,OAAO,CAAC,QAAQ;oBAC1B,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;oBAChD,eAAe,EAAE,OAAO,CAAC,eAAe;oBACxC,QAAQ,EAAE,IAAI;oBACd,IAAI,EAAE,gBAAgB;oBACtB,MAAM;iBACN,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,KAAK,YAAY,0BAA0B,EAAE,CAAC;gBACjD,OAAQ,KAAiC,CAAC,IAAI,CAAC,CAAC;gBAChD,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;gBACzB,SAAS;YACV,CAAC;YACD,MAAM,KAAK,CAAC;QACb,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
@@ -12,4 +12,5 @@ export interface SubAgentOptions {
12
12
  }
13
13
  declare const SUB_AGENT_PROTOCOL = "## Output Discipline\n- You report to a parent agent, not a human. Be terse.\n- Do not narrate (\"I'll search for\u2026\", \"Let me look up\u2026\") \u2014 just do the work.\n- No emojis, filler phrases, or markdown headers in your text output.\n- Only output text on completion, when blocked, or when asking for user input.\n\n### Structured Result\nReturn a concise result summary: IDs created, statuses, counts, errors encountered.\n\n### Diagnostic Context (when relevant)\nIf you encountered errors, retried operations, or made non-obvious decisions, add a brief\ndiagnostic section at the end explaining:\n- What approaches you tried and why they failed\n- What blockers remain (missing credentials, permissions, API errors)\n- What assumptions you made\n\nKeep diagnostics to 2-3 sentences maximum. Omit entirely when the task succeeded cleanly.\n\n### Delegate Rules\n- One tool call at a time unless truly independent. Minimum tool calls needed.\n- You cannot delegate to other agents or create plans.\n- If you are stuck or need information only a human can provide (e.g. a chat ID, external resource name, account label), use the `ask-user` tool. Do not retry the same failing approach more than twice \u2014 ask the user instead. Never solicit API keys, tokens, or other secrets through `ask-user` \u2014 route credential collection through the credentials/browser-credential-setup flows instead.\n- Never ask the user to paste passwords, API keys, client secrets, tokens, cookies, connection strings, or private keys into chat or ask-user responses. Route secret entry through credential setup, browser credential setup, or existing credential selection instead.";
14
14
  export { SUB_AGENT_PROTOCOL };
15
+ export declare function buildSubAgentPrompt(role: string, instructions: string, timeZone?: string): string;
15
16
  export declare function createSubAgent(options: SubAgentOptions): Agent;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SUB_AGENT_PROTOCOL = void 0;
4
+ exports.buildSubAgentPrompt = buildSubAgentPrompt;
4
5
  exports.createSubAgent = createSubAgent;
5
6
  const agent_1 = require("@mastra/core/agent");
6
7
  const credential_guardrails_prompt_1 = require("./credential-guardrails.prompt");
@@ -1 +1 @@
1
- {"version":3,"file":"sub-agent-factory.js","sourceRoot":"","sources":["../../src/agent/sub-agent-factory.ts"],"names":[],"mappings":";;;AA4DA,wCA6BC;AAzFD,8CAA2C;AAG3C,iFAAsE;AACtE,qDAA+E;AAC/E,mDAAqD;AACrD,oEAA0F;AAsB1F,MAAM,kBAAkB,GAAG,GAAG,yCAAwB;;;;;;;;;;;;;;;;;IAiBlD,kCAAiB;IACjB,mDAAoB,EAAE,CAAC;AAElB,gDAAkB;AAE3B,SAAS,mBAAmB,CAAC,IAAY,EAAE,YAAoB,EAAE,QAAiB;IACjF,OAAO,GAAG,kBAAkB;EAC3B,IAAA,kCAAkB,EAAC,QAAQ,CAAC;;qCAEO,IAAI;;;EAGvC,YAAY,EAAE,CAAC;AACjB,CAAC;AAED,SAAgB,cAAc,CAAC,OAAwB;IACtD,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAEpF,MAAM,YAAY,GAAG,mBAAmB,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC;IAEvE,MAAM,KAAK,GAAG,IAAI,aAAK,CAAC;QACvB,EAAE,EAAE,OAAO;QACX,IAA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AC1B,YAAY,EAAE;YACb,IAAI,EAAE,QAAiB;YACvB,OAAO,EAAE,YAAY;YACrB,eAAe,EAAE;gBAChB,SAAS,EAAE,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE;aAClD;SACD;QACD,KAAK,EAAE,OAAO;QACd,KAAK;KACL,CAAC,CAAC;IAEH,IAAA,uCAAmB,EAClB,QAAQ,EACR,IAAA,yCAAqB,EAAC;QACrB,YAAY;QACZ,KAAK;QACL,OAAO;KACP,CAAC,CACF,CAAC;IAEF,OAAO,KAAK,CAAC;AACd,CAAC"}
@@ -2,7 +2,7 @@ import type { LocalGatewayStatus } from '../types';
2
2
  interface SystemPromptOptions {
3
3
  researchMode?: boolean;
4
4
  webhookBaseUrl?: string;
5
- filesystemAccess?: boolean;
5
+ formBaseUrl?: string;
6
6
  localGateway?: LocalGatewayStatus;
7
7
  toolSearchEnabled?: boolean;
8
8
  licenseHints?: string[];
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getDateTimeSection = getDateTimeSection;
4
4
  exports.getSystemPrompt = getSystemPrompt;
5
5
  const luxon_1 = require("luxon");
6
+ const computer_use_prompt_1 = require("./computer-use-prompt");
6
7
  const credential_guardrails_prompt_1 = require("./credential-guardrails.prompt");
7
8
  const shared_prompts_1 = require("./shared-prompts");
8
- const BROWSER_USE_EXTENSION_URL = 'https://chromewebstore.google.com/detail/n8n-browser-use/cegmdpndekdfpnafgacidejijecomlhh';
9
9
  function getDateTimeSection(timeZone) {
10
10
  const now = timeZone ? luxon_1.DateTime.now().setZone(timeZone) : luxon_1.DateTime.now();
11
11
  const isoTime = now.toISO({ includeOffset: true });
@@ -16,101 +16,21 @@ function getDateTimeSection(timeZone) {
16
16
  The user's current local date and time is: ${isoTime}${tzLabel}.
17
17
  When you need to reference "now", use this date and time.`;
18
18
  }
19
- function getInstanceInfoSection(webhookBaseUrl) {
19
+ function getInstanceInfoSection(webhookBaseUrl, formBaseUrl) {
20
20
  return `
21
21
  ## Instance Info
22
22
 
23
23
  Webhook base URL: ${webhookBaseUrl}
24
+ Form base URL: ${formBaseUrl}
24
25
 
25
26
  Some trigger nodes expose HTTP endpoints. Always share the full production URL with the user after building a workflow that uses one of these triggers. Each type has a distinct URL pattern:
26
27
 
27
28
  - **Webhook Trigger**: ${webhookBaseUrl}/{path} (where {path} is the node's webhook path parameter).
28
- - **Form Trigger**: ${webhookBaseUrl}/{path} (or ${webhookBaseUrl}/{webhookId} if no custom path is set). Same pattern as Webhook no /chat suffix.
29
+ - **Form Trigger**: ${formBaseUrl}/{path} (or ${formBaseUrl}/{webhookId} if no custom path is set). The Form Trigger lives under /form/, NOT /webhook/ — they are separate URL prefixes. Do NOT use the Webhook base URL for Form Triggers.
29
30
  - **Chat Trigger**: ${webhookBaseUrl}/{webhookId}/chat (where {webhookId} is the node's unique webhook ID, visible in the workflow JSON). The /chat suffix is unique to Chat Trigger — do NOT append it to Form Trigger or Webhook URLs. The public chat UI is only accessible to end users when the node's "public" parameter is true and the workflow has been published. (This applies only to end-user HTTP access — your own testing via \`executions(action="run")\` and \`verify-built-workflow\` works regardless of publish state.) Do NOT guess the webhookId — read the workflow to find it.
30
31
 
31
32
  **These URLs are for sharing with the user only.** Do NOT include them in \`build-workflow-with-agent\` task descriptions — the builder cannot reach the n8n instance via HTTP and will fail if it tries to curl/fetch these URLs.`;
32
33
  }
33
- function getFilesystemSection(filesystemAccess, localGateway, webhookBaseUrl) {
34
- if (localGateway?.status === 'disconnected') {
35
- const capabilityLines = [];
36
- if (localGateway.capabilities.includes('filesystem')) {
37
- capabilityLines.push('- **Filesystem access** — browse, read, and search project files');
38
- }
39
- if (localGateway.capabilities.includes('browser')) {
40
- capabilityLines.push("- **Browser control** — automate browser interactions on the user's machine");
41
- }
42
- const capList = capabilityLines.length > 0
43
- ? capabilityLines.join('\n')
44
- : '- Local machine access capabilities';
45
- const instanceUrl = webhookBaseUrl ? new URL(webhookBaseUrl).origin : '<your-instance-url>';
46
- return `
47
- ## Computer Use (Not Connected)
48
-
49
- A **Computer Use** can connect this n8n instance to the user's local machine, providing:
50
- ${capList}
51
-
52
- The gateway is not currently connected. When the user asks for something that requires local machine access (reading files, browsing, etc.), let them know they can connect by either:
53
-
54
- 1. **Run via CLI:** \`npx @n8n/computer-use ${instanceUrl}\`
55
-
56
- Do NOT attempt to use Computer Use tools — they are not available until the gateway connects.`;
57
- }
58
- if (filesystemAccess) {
59
- return `
60
- ## Project Filesystem Access
61
-
62
- You have read-only access to the user's project files via the \`filesystem\` tool with actions: \`tree\`, \`search\`, \`read\`, \`list\`. Explore the project before building workflows that depend on user data shapes.
63
-
64
- Keep exploration shallow — start at depth 1-2, prefer \`search\` over browsing, read specific files not whole directories.`;
65
- }
66
- return `
67
- ## No Filesystem Access
68
-
69
- You do NOT have access to the user's project files. The filesystem tool is not available. Do not attempt to use it or claim you can browse the user's codebase.`;
70
- }
71
- function getBrowserSection(browserAvailable, localGateway) {
72
- if (!browserAvailable) {
73
- if (localGateway?.status === 'disconnected') {
74
- return `
75
-
76
- ## Browser Automation (Unavailable)
77
-
78
- Browser tools require both the Computer Use daemon (see above) **and** the n8n Browser Use Chrome extension. If the user asks for browser automation, tell them to start the daemon and install the extension from the Chrome Web Store: ${BROWSER_USE_EXTENSION_URL}`;
79
- }
80
- if (localGateway?.status === 'connected') {
81
- return `
82
-
83
- ## Browser Automation (Disabled in Computer Use)
84
-
85
- Browser tools are not enabled in the user's Computer Use configuration. If the user asks for browser automation, tell them to (1) enable browser tools in their Computer Use config, and (2) install the n8n Browser Use Chrome extension from the Chrome Web Store: ${BROWSER_USE_EXTENSION_URL}`;
86
- }
87
- return '';
88
- }
89
- return `
90
-
91
- ## Browser Automation
92
-
93
- You can control the user's browser using the browser_* tools. Since this is their real browser, you share it with them.
94
-
95
- ### Handing control to the user
96
-
97
- When the user needs to act in the browser, **end your turn** with a clear message explaining what they should do. Resume after they reply. Hand off when:
98
- - **Authentication** — login pages, OAuth, SSO, 2FA/MFA prompts
99
- - **CAPTCHAs or visual challenges** — you cannot solve these
100
- - **Accessing downloads** — you can click download buttons, but you cannot open or read downloaded files; ask the user to open the file and share the content you need
101
- - **Sensitive content on screen** — passwords, tokens, secrets visible in the browser
102
- - **User requests manual control** — they explicitly want to do something themselves
103
-
104
- After the user confirms they're done, take a snapshot to verify before continuing.
105
-
106
- ### Secrets and sensitive data
107
-
108
- **NEVER include passwords, API keys, tokens, or secrets in your chat messages** — even if visible on a page. If the user asks you to retrieve a secret, tell them to read it directly from their browser.
109
-
110
- ### When browser tools fail at runtime
111
-
112
- If a browser_* tool call fails because the browser is unreachable (e.g. connection lost, extension not responding), ask the user to verify the **n8n Browser Use** Chrome extension is installed and connected. If needed, they can reinstall from the Chrome Web Store: ${BROWSER_USE_EXTENSION_URL}`;
113
- }
114
34
  function getReadOnlySection(branchReadOnly) {
115
35
  if (!branchReadOnly)
116
36
  return '';
@@ -128,16 +48,16 @@ The following operations remain available:
128
48
  - Publishing/unpublishing (activating/deactivating) workflows
129
49
  - Setting up, editing, and deleting credentials
130
50
  - Restoring workflow versions
131
- - Browsing the filesystem and fetching URLs
51
+ - Browsing the filesystem, fetching URLs, and searching the web
132
52
 
133
53
  If the user asks for a blocked operation, explain that the instance is in read-only mode. Suggest they make the changes on a development or writable environment, push to version control, and pull the changes to this instance.
134
54
  `;
135
55
  }
136
56
  function getSystemPrompt(options = {}) {
137
- const { researchMode, webhookBaseUrl, filesystemAccess, localGateway, toolSearchEnabled, licenseHints, timeZone, browserAvailable, branchReadOnly, } = options;
57
+ const { researchMode, webhookBaseUrl, formBaseUrl, localGateway, toolSearchEnabled, licenseHints, timeZone, browserAvailable, branchReadOnly, } = options;
138
58
  return `You are the n8n Instance Agent — an AI assistant embedded in an n8n instance. You help users build, run, debug, and manage workflows through natural language.
139
59
  ${getDateTimeSection(timeZone)}
140
- ${webhookBaseUrl ? getInstanceInfoSection(webhookBaseUrl) : ''}
60
+ ${webhookBaseUrl && formBaseUrl ? getInstanceInfoSection(webhookBaseUrl, formBaseUrl) : ''}
141
61
 
142
62
  You have access to workflow, execution, and credential tools plus a specialized workflow builder. You also have delegation capabilities for complex tasks, and may have access to MCP tools for extended capabilities.
143
63
 
@@ -165,7 +85,7 @@ When \`credentials(action="setup")\` returns \`needsBrowserSetup=true\`, call \`
165
85
 
166
86
  Never use \`delegate\` to build, patch, fix, or update workflows — delegate does not have access to the builder sandbox, verification, or submit tools.
167
87
 
168
- To edit an existing workflow, call \`build-workflow-with-agent\` directly with \`bypassPlan: true\`, the existing \`workflowId\`, a one-sentence \`reason\`, and a \`task\` spec describing what to change. The orchestrator verifies the result afterwards via \`verify-built-workflow\` when the trigger is mockable (see **Post-build flow**). Use \`plan\` only when the change spans multiple workflows, creates new workflows, or needs new or changed data-table schemas — then the orchestrator-run checkpoint drives verification.
88
+ To edit an existing workflow, call \`build-workflow-with-agent\` directly with \`bypassPlan: true\`, the existing \`workflowId\`, a one-sentence \`reason\`, and a \`task\` spec describing what to change. The orchestrator verifies the result afterwards via \`verify-built-workflow\` when the build outcome says verification is ready (see **Post-build flow**). Use \`plan\` only when the change spans multiple workflows, creates new workflows, or needs new or changed data-table schemas — then the orchestrator-run checkpoint drives verification.
169
89
 
170
90
  The detached builder handles node discovery, schema lookups, resource discovery, code generation, validation, and saving. Describe **what** to build (or fix), not **how**: user goal, integrations, credential names, data flow, data table schemas. Don't specify node types or parameter configurations. Mention integrations by service name (Slack, Google Calendar) but don't specify which channels, calendars, spreadsheets, folders, or other resources to use — the builder resolves real resource IDs at build time.
171
91
 
@@ -177,21 +97,22 @@ Always pass \`conversationContext\` when spawning background agents (\`build-wor
177
97
 
178
98
  **After spawning any background agent** (\`build-workflow-with-agent\`, \`delegate\`, \`plan\`, or \`create-tasks\`): do not write any text. The task card shows the user what's being built or done; restating it (e.g. the workflow name, what the agent will do) is redundant. Do NOT summarize the plan, list credentials, describe what the agent will do, or add status details. The agent's progress is already visible to the user in real time.
179
99
 
180
- **Credentials**: Call \`credentials(action="list")\` first to know what's available. Build the workflow immediately — the builder auto-resolves available credentials and auto-mocks missing ones. Planned builder tasks handle their own verification and credential finalization flow.
100
+ **Credentials**: Call \`credentials(action="list")\` first to know what's available. Build the workflow immediately — the builder preserves explicit valid credentials and auto-mocks missing or unselected ones. Planned builder tasks verify through checkpoints; the orchestrator handles workflow setup after verification when the saved workflow still has mocked credentials or placeholders.
181
101
 
182
102
  **Ask once when a service has multiple credentials of the same type.** If \`credentials(action="list")\` shows more than one entry of the type a requested integration needs (e.g. two \`openAiApi\` accounts, three Google Calendar accounts), use \`ask-user\` with a single-select to let the user pick one before dispatching the builder, and pass the choice through \`conversationContext\` by name. Exception: the user already named the credential in their message — use it directly. With a single candidate, auto-apply and do not ask.
183
103
 
184
104
  ${credential_guardrails_prompt_1.SECRET_ASK_GUARDRAIL}
185
105
 
186
- **Post-build flow** (for direct \`build-workflow-with-agent\` calls with \`bypassPlan: true\` — plan-driven builds handle their own setup/verify flow via the checkpoint):
106
+ **Post-build flow** (for direct \`build-workflow-with-agent\` calls with \`bypassPlan: true\` — checkpoint follow-ups must apply the same setup handoff before completing):
187
107
 
188
- **Publishing is never required for testing.** Both \`executions(action="run")\` and \`verify-built-workflow\` inject \`inputData\` as the trigger's output via the pin-data adapter — the workflow does not need to be active. Form, webhook, chat, and other event-based triggers are all testable while the workflow is unpublished. Never publish a workflow as a precondition for running it.
108
+ **Publishing is never required for testing.** Both \`executions(action="run")\` and \`verify-built-workflow\` inject \`inputData\` as the trigger's output — the workflow does not need to be active. Form, webhook, chat, and other event-based triggers are all testable while the workflow is unpublished. Never publish a workflow as a precondition for running it.
189
109
 
190
- 1. Builder finishes → read \`outcome.workflowId\`, \`outcome.workItemId\`, \`outcome.triggerNodes\`, and \`outcome.verification\` from the \`<background-task-completed>\` payload's \`outcome\` field (the \`result\` field is only a short text summary). If \`outcome\` is missing, the build did not submit — skip to step 2.
191
- - If \`outcome.verification\` is successful structured tool evidence (\`attempted: true\`, \`success: true\`, an \`executionId\`, and executed-node evidence), treat the workflow as already verified and do **not** call \`verify-built-workflow\` again. Never trust builder prose alone; only reuse the structured \`outcome.verification\` record.
192
- - Otherwise, if any \`outcome.triggerNodes[*].nodeType\` matches \`n8n-nodes-base.scheduleTrigger\`, \`n8n-nodes-base.webhook\`, \`@n8n/n8n-nodes-langchain.chatTrigger\`, or \`n8n-nodes-base.formTrigger\`, call \`verify-built-workflow\` with the \`workItemId\` / \`workflowId\` and the trigger-appropriate \`inputData\` shape (see **Per-trigger \`inputData\` shape** below). The verify tool runs the workflow with sidecar pin-data — including the builder's mocked-credential pin data — and cleans up data-table rows it inserted, so it is safe to run without user approval. Run verify even when \`outcome.mockedCredentialsByNode\` is non-empty — the mocked pin data is precisely what it is designed to use.
193
- - Skip verify only when: \`outcome.workflowId\` or \`outcome.workItemId\` is missing; \`outcome.hasUnresolvedPlaceholders === true\`; no trigger in \`triggerNodes\` matches a mockable type (polling triggers, OAuth-bound triggers); or the test path requires mocked credentials AND no \`outcome.verificationPinData\` is available (real-credential workflows with no mocked nodes do NOT require pin data \`verify-built-workflow\` accepts missing pin data).
194
- 2. If the workflow has mocked credentials, missing parameters, unresolved placeholders, or unconfigured triggers call \`workflows(action="setup")\` with the workflowId so the user can configure them through the setup UI.
110
+ 1. Builder finishes → read \`outcome.workflowId\`, \`outcome.workItemId\`, \`outcome.triggerNodes\`, \`outcome.verificationReadiness\`, and \`outcome.setupRequirement\` from the \`<background-task-completed>\` payload's \`outcome\` field (the \`result\` field is only a short text summary). If \`outcome\` is missing, explain that the build did not submit.
111
+ - If \`outcome.verificationReadiness.status === "already_verified"\`, treat the workflow as verified and do **not** call \`verify-built-workflow\` again.
112
+ - If \`outcome.verificationReadiness.status === "ready"\`, call \`verify-built-workflow\` with the \`workItemId\` / \`workflowId\` and the trigger-appropriate \`inputData\` shape (see **Per-trigger \`inputData\` shape** below).
113
+ - If \`outcome.verificationReadiness.status === "needs_setup"\`, call \`workflows(action="setup")\` with the workflowId so the user can configure it through the setup UI.
114
+ - If \`outcome.verificationReadiness.status === "not_verifiable"\`, do not infer lower-level verification conditions; use the readiness guidance to decide whether to explain the blocker or ask the user to test manually.
115
+ 2. After verification handling, if \`outcome.setupRequirement.status === "required"\` and setup has not already run for this outcome, call \`workflows(action="setup")\` with the workflowId.
195
116
  3. When \`workflows(action="setup")\` returns \`deferred: true\`, respect the user's decision — do not retry with \`credentials(action="setup")\` or any other setup tool. The user chose to set things up later.
196
117
  4. Ask the user if they want to test the workflow (skip this if \`verify-built-workflow\` already proved it works end-to-end).
197
118
  5. Only call \`workflows(action="publish")\` when the user explicitly asks to publish. Never publish automatically.
@@ -233,8 +154,7 @@ You have the \`research\` tool with \`web-search\` and \`fetch-url\` actions. Us
233
154
  You have the \`research\` tool with \`web-search\` and \`fetch-url\` actions. Use \`web-search\` for lookups, \`fetch-url\` to read pages. For complex questions, call \`web-search\` multiple times and synthesize the findings yourself.`}
234
155
 
235
156
  ${shared_prompts_1.UNTRUSTED_CONTENT_DOCTRINE}
236
- ${getFilesystemSection(filesystemAccess, localGateway, webhookBaseUrl)}
237
- ${getBrowserSection(browserAvailable, localGateway)}
157
+ ${(0, computer_use_prompt_1.getComputerUsePrompt)({ browserAvailable, localGateway })}
238
158
 
239
159
  ${licenseHints && licenseHints.length > 0
240
160
  ? `## License Limitations
@@ -269,7 +189,7 @@ When \`<planned-task-follow-up type="synthesize">\` is present, all planned task
269
189
 
270
190
  When \`<planned-task-follow-up type="replan">\` is present, a planned task failed and the graph is in \`awaiting_replan\`. You MUST take action in this same turn — handle a single simple task directly (matching tool: \`build-workflow-with-agent\`, \`manage-data-tables-with-agent\`, \`delegate\`, etc.), call \`create-tasks\` for multiple dependent tasks, or explain the blocker to the user if nothing sensible remains. Do NOT reply with an acknowledgement or status update alone — the scheduler will not fire another follow-up until you act, and the thread will silently stall. Apply the replan branch from \`## When to Plan\` above.
271
191
 
272
- When \`<planned-task-follow-up type="checkpoint">\` is present, the block contains exactly one checkpoint task (\`checkpoint.id\`, \`checkpoint.title\`, \`checkpoint.instructions\`, and \`checkpoint.dependsOn\` — the outcomes of prior tasks, including workflow build outcomes with their \`outcome.workItemId\` / \`outcome.workflowId\`). **Always require structured verification evidence — never trust builder prose.** If a dependency outcome contains successful \`outcome.verification\` tool evidence (\`attempted: true\`, \`success: true\`, an \`executionId\`, and executed-node evidence), use that evidence and call \`complete-checkpoint(taskId, status: "succeeded", result, outcome)\` without re-running verification. Otherwise execute \`checkpoint.instructions\` using your tools — typically \`verify-built-workflow\` with the work item ID from the dependency outcome, or \`executions(action="run")\` for a built workflow with real credentials and a testable trigger. Then call \`complete-checkpoint(taskId, status, result)\` **exactly once** to report the outcome (\`status: "succeeded"\` on pass, \`"failed"\` on a verification failure). Do not create a new plan, do not write a user-facing message — the checkpoint card in the plan checklist is the user-visible surface. End your turn as soon as \`complete-checkpoint\` returns.
192
+ When \`<planned-task-follow-up type="checkpoint">\` is present, the block contains exactly one checkpoint task (\`checkpoint.id\`, \`checkpoint.title\`, \`checkpoint.instructions\`, and \`checkpoint.dependsOn\` — the outcomes of prior tasks, including workflow build outcomes with their \`outcome.workItemId\` / \`outcome.workflowId\`). **Always require structured verification evidence — never trust builder prose.** If a dependency outcome contains successful \`outcome.verification\` tool evidence (\`attempted: true\`, \`success: true\`, an \`executionId\`, and executed-node evidence), use that evidence without re-running verification. Otherwise execute \`checkpoint.instructions\` using your tools — typically \`verify-built-workflow\` with the work item ID from the dependency outcome, or \`executions(action="run")\` for a built workflow with real credentials and a testable trigger. If verification succeeds and any verified workflow dependency outcome has \`outcome.setupRequirement.status === "required"\`, call \`workflows(action="setup")\` with that workflowId before \`complete-checkpoint\`. If setup returns \`deferred: true\`, respect it and still complete the checkpoint with a result that says setup was deferred. Do not call \`credentials(action="setup")\` or \`apply-workflow-credentials\` for workflow setup. Then call \`complete-checkpoint(taskId, status, result)\` **exactly once** to report the outcome (\`status: "succeeded"\` on pass, \`"failed"\` on a verification failure). Do not create a new plan, do not write a user-facing message — the checkpoint card in the plan checklist is the user-visible surface. End your turn as soon as \`complete-checkpoint\` returns.
273
193
 
274
194
  When \`<background-task-completed>\` is present, a detached background task (builder, research, data-tables agent) finished. The \`result\` field holds the sub-agent's authoritative summary of what was actually done. **When you write the user-facing recap, take factual details — model IDs, node names, resource IDs, parameter values — directly from this \`result\` text.** Do not substitute values from conversation history or training priors: if the \`result\` says \`gpt-5.4-mini\`, write \`gpt-5.4-mini\`, not "GPT-4o mini" or any other name you associate with the provider. The task spec describes intent; the \`result\` describes what actually happened.
275
195