@n8n/instance-ai 1.10.0 → 1.11.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.
Files changed (221) hide show
  1. package/README.md +128 -0
  2. package/dist/agent/instance-agent.js +8 -0
  3. package/dist/agent/instance-agent.js.map +1 -1
  4. package/dist/agent/shared-prompts.d.ts +1 -0
  5. package/dist/agent/shared-prompts.js +25 -0
  6. package/dist/agent/shared-prompts.js.map +1 -1
  7. package/dist/agent/sub-agent-debriefing.d.ts +8 -8
  8. package/dist/agent/system-prompt.d.ts +2 -0
  9. package/dist/agent/system-prompt.js +52 -93
  10. package/dist/agent/system-prompt.js.map +1 -1
  11. package/dist/build.tsbuildinfo +1 -1
  12. package/dist/constants/max-steps.d.ts +0 -1
  13. package/dist/constants/max-steps.js +0 -1
  14. package/dist/constants/max-steps.js.map +1 -1
  15. package/dist/index.d.ts +123 -33
  16. package/dist/index.js +103 -96
  17. package/dist/index.js.map +1 -1
  18. package/dist/knowledge-base/build-templates-index.d.ts +12 -0
  19. package/dist/knowledge-base/build-templates-index.js +113 -0
  20. package/dist/knowledge-base/build-templates-index.js.map +1 -0
  21. package/dist/knowledge-base/extract-builder-templates-archive.d.ts +2 -0
  22. package/dist/knowledge-base/extract-builder-templates-archive.js +89 -0
  23. package/dist/knowledge-base/extract-builder-templates-archive.js.map +1 -0
  24. package/dist/knowledge-base/materialize-knowledge-base.d.ts +67 -0
  25. package/dist/knowledge-base/materialize-knowledge-base.js +186 -0
  26. package/dist/knowledge-base/materialize-knowledge-base.js.map +1 -0
  27. package/dist/mcp/mcp-client-manager.js +6 -1
  28. package/dist/mcp/mcp-client-manager.js.map +1 -1
  29. package/dist/parsers/pdf-parser.js +4 -0
  30. package/dist/parsers/pdf-parser.js.map +1 -1
  31. package/dist/planned-tasks/planned-task-service.d.ts +5 -1
  32. package/dist/planned-tasks/planned-task-service.js +29 -1
  33. package/dist/planned-tasks/planned-task-service.js.map +1 -1
  34. package/dist/runtime/run-state-registry.d.ts +8 -0
  35. package/dist/runtime/run-state-registry.js.map +1 -1
  36. package/dist/runtime/terminal-response-guard.d.ts +2 -1
  37. package/dist/runtime/terminal-response-guard.js +20 -0
  38. package/dist/runtime/terminal-response-guard.js.map +1 -1
  39. package/dist/skills/materialize-runtime-skills.d.ts +1 -7
  40. package/dist/skills/materialize-runtime-skills.js +96 -176
  41. package/dist/skills/materialize-runtime-skills.js.map +1 -1
  42. package/dist/storage/index.d.ts +1 -1
  43. package/dist/storage/planned-task-storage.js +1 -0
  44. package/dist/storage/planned-task-storage.js.map +1 -1
  45. package/dist/storage/terminal-outcome-storage.d.ts +2 -2
  46. package/dist/storage/workflow-loop-storage.d.ts +199 -70
  47. package/dist/storage/workflow-loop-storage.js +107 -0
  48. package/dist/storage/workflow-loop-storage.js.map +1 -1
  49. package/dist/stream/work-summary-accumulator.d.ts +6 -6
  50. package/dist/tools/attachments/parse-file.tool.d.ts +18 -18
  51. package/dist/tools/credentials.tool.d.ts +2 -5
  52. package/dist/tools/credentials.tool.js +2 -6
  53. package/dist/tools/credentials.tool.js.map +1 -1
  54. package/dist/tools/executions.tool.js +53 -7
  55. package/dist/tools/executions.tool.js.map +1 -1
  56. package/dist/tools/index.js +3 -9
  57. package/dist/tools/index.js.map +1 -1
  58. package/dist/tools/nodes/node-search-engine.d.ts +2 -0
  59. package/dist/tools/nodes/node-search-engine.js +66 -7
  60. package/dist/tools/nodes/node-search-engine.js.map +1 -1
  61. package/dist/tools/nodes.tool.js +10 -3
  62. package/dist/tools/nodes.tool.js.map +1 -1
  63. package/dist/tools/orchestration/complete-checkpoint.tool.js +69 -0
  64. package/dist/tools/orchestration/complete-checkpoint.tool.js.map +1 -1
  65. package/dist/tools/orchestration/delegate.schemas.d.ts +5 -5
  66. package/dist/tools/orchestration/delegate.tool.js +1 -1
  67. package/dist/tools/orchestration/delegate.tool.js.map +1 -1
  68. package/dist/tools/orchestration/plan.tool.js +96 -60
  69. package/dist/tools/orchestration/plan.tool.js.map +1 -1
  70. package/dist/tools/orchestration/report-verification-verdict.tool.d.ts +9 -6
  71. package/dist/tools/orchestration/report-verification-verdict.tool.js +6 -1
  72. package/dist/tools/orchestration/report-verification-verdict.tool.js.map +1 -1
  73. package/dist/tools/orchestration/verify-built-workflow.tool.js +3 -2
  74. package/dist/tools/orchestration/verify-built-workflow.tool.js.map +1 -1
  75. package/dist/tools/tool-ids.d.ts +0 -5
  76. package/dist/tools/tool-ids.js +3 -7
  77. package/dist/tools/tool-ids.js.map +1 -1
  78. package/dist/tools/workflows/build-workflow.tool.d.ts +8 -2
  79. package/dist/tools/workflows/build-workflow.tool.js +371 -17
  80. package/dist/tools/workflows/build-workflow.tool.js.map +1 -1
  81. package/dist/tools/workflows/materialize-node-type.tool.d.ts +4 -4
  82. package/dist/tools/workflows/materialize-node-type.tool.js +2 -2
  83. package/dist/tools/workflows/materialize-node-type.tool.js.map +1 -1
  84. package/dist/tools/workflows/setup-workflow.schema.d.ts +32 -32
  85. package/dist/tools/workflows/submit-workflow.tool.d.ts +16 -12
  86. package/dist/tools/workflows/submit-workflow.tool.js +9 -2
  87. package/dist/tools/workflows/submit-workflow.tool.js.map +1 -1
  88. package/dist/tools/workflows/write-sandbox-file.tool.js +2 -2
  89. package/dist/tools/workflows/write-sandbox-file.tool.js.map +1 -1
  90. package/dist/tools/workflows.tool.js +5 -0
  91. package/dist/tools/workflows.tool.js.map +1 -1
  92. package/dist/tracing/langsmith-tracing.js +6 -1
  93. package/dist/tracing/langsmith-tracing.js.map +1 -1
  94. package/dist/tracing/trace-payloads.js +2 -6
  95. package/dist/tracing/trace-payloads.js.map +1 -1
  96. package/dist/types.d.ts +48 -9
  97. package/dist/types.js.map +1 -1
  98. package/dist/workflow-builder/build-failure-tracker.d.ts +10 -0
  99. package/dist/workflow-builder/build-failure-tracker.js +36 -0
  100. package/dist/workflow-builder/build-failure-tracker.js.map +1 -0
  101. package/dist/workflow-builder/index.d.ts +1 -0
  102. package/dist/workflow-builder/index.js +4 -1
  103. package/dist/workflow-builder/index.js.map +1 -1
  104. package/dist/workflow-loop/guidance.js +10 -6
  105. package/dist/workflow-loop/guidance.js.map +1 -1
  106. package/dist/workflow-loop/index.d.ts +3 -2
  107. package/dist/workflow-loop/index.js +14 -1
  108. package/dist/workflow-loop/index.js.map +1 -1
  109. package/dist/workflow-loop/runtime.js +3 -1
  110. package/dist/workflow-loop/runtime.js.map +1 -1
  111. package/dist/workflow-loop/verification-obligation.d.ts +15 -0
  112. package/dist/workflow-loop/verification-obligation.js +140 -0
  113. package/dist/workflow-loop/verification-obligation.js.map +1 -0
  114. package/dist/workflow-loop/workflow-loop-controller.js +26 -1
  115. package/dist/workflow-loop/workflow-loop-controller.js.map +1 -1
  116. package/dist/workflow-loop/workflow-loop-state.d.ts +416 -62
  117. package/dist/workflow-loop/workflow-loop-state.js +66 -1
  118. package/dist/workflow-loop/workflow-loop-state.js.map +1 -1
  119. package/dist/workspace/builder-templates-service.js.map +1 -1
  120. package/dist/workspace/compute-workspace-content-hash.d.ts +1 -0
  121. package/dist/workspace/compute-workspace-content-hash.js +15 -0
  122. package/dist/workspace/compute-workspace-content-hash.js.map +1 -0
  123. package/dist/workspace/create-workspace.d.ts +9 -43
  124. package/dist/workspace/create-workspace.js +45 -56
  125. package/dist/workspace/create-workspace.js.map +1 -1
  126. package/dist/workspace/lazy-runtime-workspace.js +1 -1
  127. package/dist/workspace/lazy-runtime-workspace.js.map +1 -1
  128. package/dist/workspace/prebaked-workspace-bundle.d.ts +39 -0
  129. package/dist/workspace/prebaked-workspace-bundle.js +75 -0
  130. package/dist/workspace/prebaked-workspace-bundle.js.map +1 -0
  131. package/dist/workspace/sandbox-fs.d.ts +9 -24
  132. package/dist/workspace/sandbox-fs.js +2 -16
  133. package/dist/workspace/sandbox-fs.js.map +1 -1
  134. package/dist/workspace/sandbox-setup.d.ts +1 -7
  135. package/dist/workspace/sandbox-setup.js +28 -170
  136. package/dist/workspace/sandbox-setup.js.map +1 -1
  137. package/dist/workspace/snapshot-image-context.d.ts +5 -0
  138. package/dist/workspace/snapshot-image-context.js +36 -0
  139. package/dist/workspace/snapshot-image-context.js.map +1 -0
  140. package/dist/workspace/snapshot-manager.d.ts +9 -9
  141. package/dist/workspace/snapshot-manager.js +57 -67
  142. package/dist/workspace/snapshot-manager.js.map +1 -1
  143. package/dist/workspace/template-telemetry.js +4 -4
  144. package/dist/workspace/template-telemetry.js.map +1 -1
  145. package/dist/workspace/workspace-file-content.d.ts +2 -0
  146. package/dist/workspace/workspace-file-content.js +11 -0
  147. package/dist/workspace/workspace-file-content.js.map +1 -0
  148. package/dist/workspace/workspace-files.d.ts +20 -0
  149. package/dist/workspace/workspace-files.js +74 -0
  150. package/dist/workspace/workspace-files.js.map +1 -0
  151. package/dist/workspace/workspace-manifest.d.ts +12 -0
  152. package/dist/workspace/workspace-manifest.js +28 -0
  153. package/dist/workspace/workspace-manifest.js.map +1 -0
  154. package/package.json +19 -13
  155. package/skills/data-table-manager/SKILL.md +6 -6
  156. package/skills/debugging-executions/SKILL.md +44 -0
  157. package/skills/planned-task-runtime/SKILL.md +163 -0
  158. package/skills/planning/SKILL.md +137 -0
  159. package/skills/post-build-flow/SKILL.md +119 -0
  160. package/skills/post-build-flow/references/trigger-input-data-shapes.md +38 -0
  161. package/skills/workflow-builder/SKILL.md +608 -0
  162. package/dist/tools/best-practices/index.d.ts +0 -2
  163. package/dist/tools/best-practices/index.js +0 -10
  164. package/dist/tools/best-practices/index.js.map +0 -1
  165. package/dist/tools/best-practices/techniques.d.ts +0 -1
  166. package/dist/tools/best-practices/techniques.js +0 -7
  167. package/dist/tools/best-practices/techniques.js.map +0 -1
  168. package/dist/tools/orchestration/add-plan-item.tool.d.ts +0 -5
  169. package/dist/tools/orchestration/add-plan-item.tool.js +0 -89
  170. package/dist/tools/orchestration/add-plan-item.tool.js.map +0 -1
  171. package/dist/tools/orchestration/blueprint-accumulator.d.ts +0 -49
  172. package/dist/tools/orchestration/blueprint-accumulator.js +0 -176
  173. package/dist/tools/orchestration/blueprint-accumulator.js.map +0 -1
  174. package/dist/tools/orchestration/blueprint.schema.d.ts +0 -182
  175. package/dist/tools/orchestration/blueprint.schema.js +0 -56
  176. package/dist/tools/orchestration/blueprint.schema.js.map +0 -1
  177. package/dist/tools/orchestration/build-workflow-agent.prompt.d.ts +0 -8
  178. package/dist/tools/orchestration/build-workflow-agent.prompt.js +0 -466
  179. package/dist/tools/orchestration/build-workflow-agent.prompt.js.map +0 -1
  180. package/dist/tools/orchestration/build-workflow-agent.tool.d.ts +0 -148
  181. package/dist/tools/orchestration/build-workflow-agent.tool.js +0 -1498
  182. package/dist/tools/orchestration/build-workflow-agent.tool.js.map +0 -1
  183. package/dist/tools/orchestration/builder-memory-compaction.d.ts +0 -42
  184. package/dist/tools/orchestration/builder-memory-compaction.js +0 -132
  185. package/dist/tools/orchestration/builder-memory-compaction.js.map +0 -1
  186. package/dist/tools/orchestration/plan-agent-prompt.d.ts +0 -1
  187. package/dist/tools/orchestration/plan-agent-prompt.js +0 -83
  188. package/dist/tools/orchestration/plan-agent-prompt.js.map +0 -1
  189. package/dist/tools/orchestration/plan-with-agent.tool.d.ts +0 -27
  190. package/dist/tools/orchestration/plan-with-agent.tool.js +0 -710
  191. package/dist/tools/orchestration/plan-with-agent.tool.js.map +0 -1
  192. package/dist/tools/orchestration/submit-plan.tool.d.ts +0 -3
  193. package/dist/tools/orchestration/submit-plan.tool.js +0 -98
  194. package/dist/tools/orchestration/submit-plan.tool.js.map +0 -1
  195. package/dist/tools/templates.tool.d.ts +0 -1
  196. package/dist/tools/templates.tool.js +0 -58
  197. package/dist/tools/templates.tool.js.map +0 -1
  198. package/dist/workspace/daytona-auth-manager.d.ts +0 -26
  199. package/dist/workspace/daytona-auth-manager.js +0 -90
  200. package/dist/workspace/daytona-auth-manager.js.map +0 -1
  201. package/dist/workspace/daytona-filesystem.d.ts +0 -26
  202. package/dist/workspace/daytona-filesystem.js +0 -133
  203. package/dist/workspace/daytona-filesystem.js.map +0 -1
  204. package/dist/workspace/daytona-sandbox.d.ts +0 -65
  205. package/dist/workspace/daytona-sandbox.js +0 -314
  206. package/dist/workspace/daytona-sandbox.js.map +0 -1
  207. package/dist/workspace/lazy-daytona.d.ts +0 -2
  208. package/dist/workspace/lazy-daytona.js +0 -12
  209. package/dist/workspace/lazy-daytona.js.map +0 -1
  210. package/dist/workspace/local-filesystem.d.ts +0 -48
  211. package/dist/workspace/local-filesystem.js +0 -250
  212. package/dist/workspace/local-filesystem.js.map +0 -1
  213. package/dist/workspace/local-sandbox.d.ts +0 -28
  214. package/dist/workspace/local-sandbox.js +0 -121
  215. package/dist/workspace/local-sandbox.js.map +0 -1
  216. package/dist/workspace/n8n-sandbox-filesystem.d.ts +0 -25
  217. package/dist/workspace/n8n-sandbox-filesystem.js +0 -128
  218. package/dist/workspace/n8n-sandbox-filesystem.js.map +0 -1
  219. package/dist/workspace/n8n-sandbox-sandbox.d.ts +0 -35
  220. package/dist/workspace/n8n-sandbox-sandbox.js +0 -143
  221. package/dist/workspace/n8n-sandbox-sandbox.js.map +0 -1
@@ -1,28 +0,0 @@
1
- import type { CommandResult, ExecuteCommandOptions, ProviderStatus, SandboxInfo } from '@n8n/agents';
2
- import { BaseSandbox } from '@n8n/agents';
3
- export interface LocalSandboxOptions {
4
- id?: string;
5
- workingDirectory?: string;
6
- env?: NodeJS.ProcessEnv;
7
- timeout?: number;
8
- instructions?: string;
9
- }
10
- export declare class LocalSandbox extends BaseSandbox {
11
- readonly id: string;
12
- readonly name = "LocalSandbox";
13
- readonly provider = "local";
14
- status: ProviderStatus;
15
- readonly workingDirectory: string;
16
- private readonly env?;
17
- private readonly timeout?;
18
- private readonly instructions?;
19
- private readonly createdAt;
20
- constructor(options?: LocalSandboxOptions);
21
- start(): Promise<void>;
22
- stop(): Promise<void>;
23
- destroy(): Promise<void>;
24
- executeCommand(command: string, args?: string[], options?: ExecuteCommandOptions): Promise<CommandResult>;
25
- getInfo(): SandboxInfo;
26
- getInstructions(): string;
27
- private runCommand;
28
- }
@@ -1,121 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LocalSandbox = void 0;
4
- const agents_1 = require("@n8n/agents");
5
- const node_child_process_1 = require("node:child_process");
6
- const node_crypto_1 = require("node:crypto");
7
- const promises_1 = require("node:fs/promises");
8
- const node_path_1 = require("node:path");
9
- function shellEscape(value) {
10
- return /^[A-Za-z0-9_./:=@+-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`;
11
- }
12
- function toShellCommand(command, args = []) {
13
- if (args.length === 0)
14
- return command;
15
- return [command, ...args.map((arg) => shellEscape(arg))].join(' ');
16
- }
17
- class LocalSandbox extends agents_1.BaseSandbox {
18
- id;
19
- name = 'LocalSandbox';
20
- provider = 'local';
21
- status = 'pending';
22
- workingDirectory;
23
- env;
24
- timeout;
25
- instructions;
26
- createdAt = new Date();
27
- constructor(options = {}) {
28
- super();
29
- this.id = options.id ?? `local-sandbox-${(0, node_crypto_1.randomUUID)()}`;
30
- this.workingDirectory = (0, node_path_1.resolve)(options.workingDirectory ?? './workspace');
31
- this.env = options.env;
32
- this.timeout = options.timeout;
33
- this.instructions = options.instructions;
34
- }
35
- async start() {
36
- await (0, promises_1.mkdir)(this.workingDirectory, { recursive: true });
37
- }
38
- async stop() { }
39
- async destroy() { }
40
- async executeCommand(command, args = [], options) {
41
- await this.ensureRunning();
42
- return await this.runCommand(toShellCommand(command, args), options);
43
- }
44
- getInfo() {
45
- return {
46
- id: this.id,
47
- name: this.name,
48
- provider: this.provider,
49
- status: this.status,
50
- createdAt: this.createdAt,
51
- metadata: {
52
- workingDirectory: this.workingDirectory,
53
- },
54
- };
55
- }
56
- getInstructions() {
57
- return (this.instructions ??
58
- `Local sandbox executing host commands in ${this.workingDirectory}. This provider is for development only.`);
59
- }
60
- async runCommand(command, options) {
61
- const startedAt = Date.now();
62
- const cwd = options?.cwd ?? this.workingDirectory;
63
- const env = {
64
- PATH: process.env.PATH,
65
- ...this.env,
66
- ...options?.env,
67
- };
68
- return await new Promise((resolveResult, reject) => {
69
- const child = (0, node_child_process_1.spawn)(command, {
70
- shell: true,
71
- cwd,
72
- env,
73
- stdio: ['pipe', 'pipe', 'pipe'],
74
- });
75
- let stdout = '';
76
- let stderr = '';
77
- let timedOut = false;
78
- let killed = false;
79
- const timeoutMs = options?.timeout ?? this.timeout;
80
- const timeoutHandle = timeoutMs === undefined
81
- ? undefined
82
- : setTimeout(() => {
83
- timedOut = true;
84
- killed = child.kill('SIGTERM');
85
- }, timeoutMs);
86
- const abort = () => {
87
- killed = child.kill('SIGTERM');
88
- };
89
- options?.abortSignal?.addEventListener('abort', abort, { once: true });
90
- child.stdout.on('data', (chunk) => {
91
- const text = chunk.toString('utf-8');
92
- stdout += text;
93
- options?.onStdout?.(text);
94
- });
95
- child.stderr.on('data', (chunk) => {
96
- const text = chunk.toString('utf-8');
97
- stderr += text;
98
- options?.onStderr?.(text);
99
- });
100
- child.on('error', reject);
101
- child.on('close', (code) => {
102
- if (timeoutHandle)
103
- clearTimeout(timeoutHandle);
104
- options?.abortSignal?.removeEventListener('abort', abort);
105
- const exitCode = code ?? (timedOut ? 124 : 1);
106
- resolveResult({
107
- command,
108
- success: exitCode === 0 && !timedOut,
109
- exitCode,
110
- stdout,
111
- stderr,
112
- executionTimeMs: Date.now() - startedAt,
113
- timedOut,
114
- killed,
115
- });
116
- });
117
- });
118
- }
119
- }
120
- exports.LocalSandbox = LocalSandbox;
121
- //# sourceMappingURL=local-sandbox.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"local-sandbox.js","sourceRoot":"","sources":["../../src/workspace/local-sandbox.ts"],"names":[],"mappings":";;;AAMA,wCAA0C;AAC1C,2DAA2C;AAC3C,6CAAyC;AACzC,+CAAyC;AACzC,yCAAoC;AAUpC,SAAS,WAAW,CAAC,KAAa;IACjC,OAAO,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC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YAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAE1B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBAC1B,IAAI,aAAa;oBAAE,YAAY,CAAC,aAAa,CAAC,CAAC;gBAC/C,OAAO,EAAE,WAAW,EAAE,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gBAC1D,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC9C,aAAa,CAAC;oBACb,OAAO;oBACP,OAAO,EAAE,QAAQ,KAAK,CAAC,IAAI,CAAC,QAAQ;oBACpC,QAAQ;oBACR,MAAM;oBACN,MAAM;oBACN,eAAe,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;oBACvC,QAAQ;oBACR,MAAM;iBACN,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAhID,oCAgIC"}
@@ -1,25 +0,0 @@
1
- import type { CopyOptions, FileContent, FileEntry, FileStat, ListOptions, ProviderStatus, ReadOptions, RemoveOptions, WriteOptions } from '@n8n/agents';
2
- import { BaseFilesystem } from '@n8n/agents';
3
- import type { N8nSandboxServiceSandbox } from './n8n-sandbox-sandbox';
4
- export declare class N8nSandboxFilesystem extends BaseFilesystem {
5
- private readonly sandbox;
6
- readonly id: string;
7
- readonly name = "N8nSandboxFilesystem";
8
- readonly provider = "n8n-sandbox";
9
- status: ProviderStatus;
10
- constructor(sandbox: N8nSandboxServiceSandbox);
11
- private getClientAndSandboxId;
12
- readFile(path: string, options?: ReadOptions): Promise<string | Buffer>;
13
- writeFile(path: string, content: FileContent, options?: WriteOptions): Promise<void>;
14
- appendFile(path: string, content: FileContent): Promise<void>;
15
- deleteFile(path: string, options?: RemoveOptions): Promise<void>;
16
- copyFile(src: string, dest: string, options?: CopyOptions): Promise<void>;
17
- moveFile(src: string, dest: string, options?: CopyOptions): Promise<void>;
18
- mkdir(path: string, options?: {
19
- recursive?: boolean;
20
- }): Promise<void>;
21
- rmdir(path: string, options?: RemoveOptions): Promise<void>;
22
- readdir(path: string, _options?: ListOptions): Promise<FileEntry[]>;
23
- exists(path: string): Promise<boolean>;
24
- stat(path: string): Promise<FileStat>;
25
- }
@@ -1,128 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.N8nSandboxFilesystem = void 0;
4
- const agents_1 = require("@n8n/agents");
5
- const sandbox_client_1 = require("@n8n/sandbox-client");
6
- const posix_1 = require("node:path/posix");
7
- function getParentDirectory(path) {
8
- const parent = (0, posix_1.dirname)(path);
9
- return parent === '.' || parent === '/' ? null : parent;
10
- }
11
- class N8nSandboxFilesystem extends agents_1.BaseFilesystem {
12
- sandbox;
13
- id;
14
- name = 'N8nSandboxFilesystem';
15
- provider = 'n8n-sandbox';
16
- status = 'pending';
17
- constructor(sandbox) {
18
- super();
19
- this.sandbox = sandbox;
20
- this.id = `n8n-sandbox-fs-${sandbox.id}`;
21
- }
22
- async getClientAndSandboxId() {
23
- await this.sandbox.ensureRunning();
24
- return {
25
- client: this.sandbox.getClient(),
26
- sandboxId: this.sandbox.id,
27
- };
28
- }
29
- async readFile(path, options) {
30
- await this.ensureReady();
31
- const { client, sandboxId } = await this.getClientAndSandboxId();
32
- const content = await client.readFile(sandboxId, path);
33
- if (options?.encoding) {
34
- return content.toString(options.encoding);
35
- }
36
- return content;
37
- }
38
- async writeFile(path, content, options) {
39
- await this.ensureReady();
40
- const { client, sandboxId } = await this.getClientAndSandboxId();
41
- if (options?.recursive) {
42
- const parent = getParentDirectory(path);
43
- if (parent) {
44
- await client.mkdir(sandboxId, parent, true);
45
- }
46
- }
47
- await client.writeFile(sandboxId, path, content, options?.overwrite ?? true);
48
- }
49
- async appendFile(path, content) {
50
- await this.ensureReady();
51
- const { client, sandboxId } = await this.getClientAndSandboxId();
52
- await client.appendFile(sandboxId, path, content);
53
- }
54
- async deleteFile(path, options) {
55
- await this.ensureReady();
56
- const { client, sandboxId } = await this.getClientAndSandboxId();
57
- await client.deleteFile(sandboxId, path, {
58
- recursive: options?.recursive,
59
- force: options?.force,
60
- });
61
- }
62
- async copyFile(src, dest, options) {
63
- await this.ensureReady();
64
- const { client, sandboxId } = await this.getClientAndSandboxId();
65
- await client.copyFile(sandboxId, {
66
- src,
67
- dest,
68
- recursive: options?.recursive,
69
- overwrite: options?.overwrite,
70
- });
71
- }
72
- async moveFile(src, dest, options) {
73
- await this.ensureReady();
74
- const { client, sandboxId } = await this.getClientAndSandboxId();
75
- await client.moveFile(sandboxId, {
76
- src,
77
- dest,
78
- overwrite: options?.overwrite,
79
- });
80
- }
81
- async mkdir(path, options) {
82
- await this.ensureReady();
83
- const { client, sandboxId } = await this.getClientAndSandboxId();
84
- await client.mkdir(sandboxId, path, options?.recursive ?? false);
85
- }
86
- async rmdir(path, options) {
87
- await this.deleteFile(path, options);
88
- }
89
- async readdir(path, _options) {
90
- await this.ensureReady();
91
- const { client, sandboxId } = await this.getClientAndSandboxId();
92
- const files = await client.listFiles(sandboxId, { path });
93
- return files.map((entry) => ({
94
- name: entry.name,
95
- type: entry.isDir ? 'directory' : 'file',
96
- size: entry.size,
97
- }));
98
- }
99
- async exists(path) {
100
- await this.ensureReady();
101
- try {
102
- const { client, sandboxId } = await this.getClientAndSandboxId();
103
- await client.stat(sandboxId, path);
104
- return true;
105
- }
106
- catch (error) {
107
- if (error instanceof sandbox_client_1.SandboxServiceError && error.status === 404) {
108
- return false;
109
- }
110
- throw error;
111
- }
112
- }
113
- async stat(path) {
114
- await this.ensureReady();
115
- const { client, sandboxId } = await this.getClientAndSandboxId();
116
- const stat = await client.stat(sandboxId, path);
117
- return {
118
- name: stat.name,
119
- path: stat.path,
120
- type: stat.type,
121
- size: stat.size,
122
- createdAt: new Date(stat.createdAt),
123
- modifiedAt: new Date(stat.modifiedAt),
124
- };
125
- }
126
- }
127
- exports.N8nSandboxFilesystem = N8nSandboxFilesystem;
128
- //# sourceMappingURL=n8n-sandbox-filesystem.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"n8n-sandbox-filesystem.js","sourceRoot":"","sources":["../../src/workspace/n8n-sandbox-filesystem.ts"],"names":[],"mappings":";;;AAWA,wCAA6C;AAC7C,wDAA0D;AAC1D,2CAA0C;AAI1C,SAAS,kBAAkB,CAAC,IAAY;IACvC,MAAM,MAAM,GAAG,IAAA,eAAO,EAAC,IAAI,CAAC,CAAC;IAC7B,OAAO,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;AACzD,CAAC;AAGD,MAAa,oBAAqB,SAAQ,uBAAc;IAS1B;IARpB,EAAE,CAAS;IAEX,IAAI,GAAG,sBAAsB,CAAC;IAE9B,QAAQ,GAAG,aAAa,CAAC;IAElC,MAAM,GAAmB,SAAS,CAAC;IAEnC,YAA6B,OAAiC;QAC7D,KAAK,EAAE,CAAC;QADoB,YAAO,GAAP,OAAO,CAA0B;QAE7D,IAAI,CAAC,EAAE,GAAG,kBAAkB,OAAO,CAAC,EAAE,EAAE,CAAC;IAC1C,CAAC;IAEO,KAAK,CAAC,qBAAqB;QAClC,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QACnC,OAAO;YACN,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YAChC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE;SAC1B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAY,EAAE,OAAqB;QACjD,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QACzB,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAC;QACjE,MAAM,OAAO,GAAG,MAAM,MAAM,CA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AC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAChD,OAAO;YACN,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;YACnC,UAAU,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;SACrC,CAAC;IACH,CAAC;CACD;AAhID,oDAgIC"}
@@ -1,35 +0,0 @@
1
- import type { CommandResult, ExecuteCommandOptions, ProviderStatus, SandboxInfo } from '@n8n/agents';
2
- import { BaseSandbox } from '@n8n/agents';
3
- import { SandboxClient } from '@n8n/sandbox-client';
4
- export interface N8nSandboxServiceSandboxOptions {
5
- id?: string;
6
- apiKey?: string;
7
- serviceUrl?: string;
8
- timeout?: number;
9
- env?: Record<string, string>;
10
- }
11
- export declare class N8nSandboxServiceSandbox extends BaseSandbox {
12
- private readonly options;
13
- readonly name = "N8nSandboxServiceSandbox";
14
- readonly provider = "n8n-sandbox";
15
- status: ProviderStatus;
16
- private readonly instanceId;
17
- private readonly client;
18
- private readonly timeout;
19
- private static readonly HOME_DIR;
20
- private static readonly WORKSPACE_DIR;
21
- private sandboxId?;
22
- private createdAt?;
23
- constructor(options: N8nSandboxServiceSandboxOptions);
24
- get id(): string;
25
- start(): Promise<void>;
26
- destroy(): Promise<void>;
27
- stop(): Promise<void>;
28
- getInfo(): Promise<SandboxInfo>;
29
- getInstructions(): string;
30
- executeCommand(command: string, args?: string[], options?: ExecuteCommandOptions): Promise<CommandResult>;
31
- getClient(): SandboxClient;
32
- private tryGetExistingSandbox;
33
- private compactEnv;
34
- private requireSandboxId;
35
- }
@@ -1,143 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.N8nSandboxServiceSandbox = void 0;
7
- const agents_1 = require("@n8n/agents");
8
- const sandbox_client_1 = require("@n8n/sandbox-client");
9
- const strict_1 = __importDefault(require("node:assert/strict"));
10
- const node_crypto_1 = require("node:crypto");
11
- function shellEscape(value) {
12
- return /^[A-Za-z0-9_./:=+-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`;
13
- }
14
- function toShellCommand(command, args = []) {
15
- if (args.length === 0)
16
- return command;
17
- return [command, ...args.map((arg) => shellEscape(arg))].join(' ');
18
- }
19
- class N8nSandboxServiceSandbox extends agents_1.BaseSandbox {
20
- options;
21
- name = 'N8nSandboxServiceSandbox';
22
- provider = 'n8n-sandbox';
23
- status = 'pending';
24
- instanceId = `n8n-sandbox-${(0, node_crypto_1.randomUUID)()}`;
25
- client;
26
- timeout;
27
- static HOME_DIR = '/home/user';
28
- static WORKSPACE_DIR = `${N8nSandboxServiceSandbox.HOME_DIR}/workspace`;
29
- sandboxId;
30
- createdAt;
31
- constructor(options) {
32
- super();
33
- this.options = options;
34
- this.client = new sandbox_client_1.SandboxClient({
35
- apiKey: options.apiKey,
36
- baseUrl: options.serviceUrl,
37
- });
38
- this.sandboxId = options.id;
39
- this.timeout = options.timeout ?? 300_000;
40
- }
41
- get id() {
42
- return this.sandboxId ?? this.instanceId;
43
- }
44
- async start() {
45
- if (this.sandboxId) {
46
- const existing = await this.tryGetExistingSandbox(this.sandboxId);
47
- if (existing) {
48
- this.createdAt = new Date(existing.createdAt * 1000);
49
- return;
50
- }
51
- }
52
- const sandbox = await this.client.createSandbox();
53
- this.sandboxId = sandbox.id;
54
- this.createdAt = new Date();
55
- }
56
- async destroy() {
57
- if (!this.sandboxId)
58
- return;
59
- try {
60
- await this.client.deleteSandbox(this.sandboxId);
61
- }
62
- catch (error) {
63
- if (error instanceof sandbox_client_1.SandboxServiceError && error.status === 404)
64
- return;
65
- throw error;
66
- }
67
- }
68
- async stop() {
69
- }
70
- async getInfo() {
71
- await this.ensureRunning();
72
- const sandbox = await this.client.getSandbox(this.requireSandboxId());
73
- return {
74
- id: sandbox.id,
75
- name: this.name,
76
- provider: this.provider,
77
- status: this.status,
78
- createdAt: this.createdAt ?? new Date(sandbox.createdAt * 1000),
79
- metadata: {
80
- lastActiveAt: new Date(sandbox.lastActiveAt * 1000).toISOString(),
81
- remoteStatus: sandbox.status,
82
- workingDirectory: N8nSandboxServiceSandbox.WORKSPACE_DIR,
83
- },
84
- };
85
- }
86
- getInstructions() {
87
- return [
88
- 'Cloud sandbox with isolated execution (TypeScript runtime).',
89
- `Default working directory: ${N8nSandboxServiceSandbox.WORKSPACE_DIR}.`,
90
- `Command timeout: ${Math.ceil(this.timeout / 1000)}s.`,
91
- ].join(' ');
92
- }
93
- async executeCommand(command, args = [], options) {
94
- await this.ensureRunning();
95
- const result = await this.client.exec(this.requireSandboxId(), {
96
- command: toShellCommand(command, args),
97
- env: this.compactEnv(options?.env),
98
- workdir: options?.cwd,
99
- timeoutMs: options?.timeout ?? this.timeout,
100
- abortSignal: options?.abortSignal,
101
- onStdout: options?.onStdout,
102
- onStderr: options?.onStderr,
103
- });
104
- return {
105
- command,
106
- args,
107
- success: result.success,
108
- exitCode: result.exitCode,
109
- stdout: result.stdout,
110
- stderr: result.stderr,
111
- executionTimeMs: result.executionTimeMs,
112
- timedOut: result.timedOut,
113
- killed: result.killed,
114
- };
115
- }
116
- getClient() {
117
- return this.client;
118
- }
119
- async tryGetExistingSandbox(sandboxId) {
120
- try {
121
- return await this.client.getSandbox(sandboxId);
122
- }
123
- catch (error) {
124
- if (error instanceof sandbox_client_1.SandboxServiceError && error.status === 404)
125
- return null;
126
- throw error;
127
- }
128
- }
129
- compactEnv(env) {
130
- const merged = {
131
- ...this.options.env,
132
- ...env,
133
- };
134
- const entries = Object.entries(merged).filter((entry) => typeof entry[1] === 'string');
135
- return entries.length > 0 ? Object.fromEntries(entries) : undefined;
136
- }
137
- requireSandboxId() {
138
- (0, strict_1.default)(this.sandboxId, 'Sandbox has not been created yet');
139
- return this.sandboxId;
140
- }
141
- }
142
- exports.N8nSandboxServiceSandbox = N8nSandboxServiceSandbox;
143
- //# sourceMappingURL=n8n-sandbox-sandbox.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"n8n-sandbox-sandbox.js","sourceRoot":"","sources":["../../src/workspace/n8n-sandbox-sandbox.ts"],"names":[],"mappings":";;;;;;AAMA,wCAA0C;AAC1C,wDAA6F;AAC7F,gEAAwC;AACxC,6CAAyC;AAUzC,SAAS,WAAW,CAAC,KAAa;IACjC,OAAO,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC;AAC1F,CAAC;AAED,SAAS,cAAc,CAAC,OAAe,EAAE,OAAiB,EAAE;IAC3D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IACtC,OAAO,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpE,CAAC;AAGD,MAAa,wBAAyB,SAAQ,oBAAW;IAqB3B;IApBpB,IAAI,GAAG,0BAA0B,CAAC;IAElC,QAAQ,GAAG,aAAa,CAAC;IAElC,MAAM,GAAmB,SAAS,CAAC;IAElB,UAAU,GAAG,eAAe,IAAA,wBAAU,GAAE,EAAE,CAAC;IAE3C,MAAM,CAAgB;IAEtB,OAAO,CAAS;IAEzB,MAAM,CAAU,QAAQ,GAAG,YAAY,CAAC;IAExC,MAAM,CAAU,aAAa,GAAG,GAAG,wBAAwB,CAAC,QAAQ,YAAY,CAAC;IAEjF,SAAS,CAAU;IAEnB,SAAS,CAAQ;IAEzB,YAA6B,OAAwC;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