@n8n/agents 0.10.0 → 0.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.
- package/dist/build.tsbuildinfo +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +27 -5
- package/dist/index.js.map +1 -1
- package/dist/runtime/agent-runtime.d.ts +14 -6
- package/dist/runtime/agent-runtime.js +320 -243
- package/dist/runtime/agent-runtime.js.map +1 -1
- package/dist/runtime/delegate-sub-agent-tool.d.ts +87 -0
- package/dist/runtime/delegate-sub-agent-tool.js +362 -0
- package/dist/runtime/delegate-sub-agent-tool.js.map +1 -0
- package/dist/runtime/event-bus.d.ts +8 -0
- package/dist/runtime/event-bus.js +48 -0
- package/dist/runtime/event-bus.js.map +1 -1
- package/dist/runtime/mcp-connection.d.ts +1 -2
- package/dist/runtime/mcp-connection.js +1 -4
- package/dist/runtime/mcp-connection.js.map +1 -1
- package/dist/runtime/message-list.d.ts +9 -3
- package/dist/runtime/message-list.js +16 -5
- package/dist/runtime/message-list.js.map +1 -1
- package/dist/runtime/messages.js +10 -2
- package/dist/runtime/messages.js.map +1 -1
- package/dist/runtime/model-factory.js +12 -0
- package/dist/runtime/model-factory.js.map +1 -1
- package/dist/runtime/provider-credentials.d.ts +13 -0
- package/dist/runtime/provider-credentials.js +1 -0
- package/dist/runtime/provider-credentials.js.map +1 -1
- package/dist/runtime/runtime-helpers.d.ts +1 -2
- package/dist/runtime/runtime-helpers.js +0 -8
- package/dist/runtime/runtime-helpers.js.map +1 -1
- package/dist/runtime/sdk-owned-tool.d.ts +4 -0
- package/dist/runtime/sdk-owned-tool.js +19 -0
- package/dist/runtime/sdk-owned-tool.js.map +1 -0
- package/dist/runtime/stream.js +8 -0
- package/dist/runtime/stream.js.map +1 -1
- package/dist/runtime/sub-agent-task-path.d.ts +10 -0
- package/dist/runtime/sub-agent-task-path.js +39 -0
- package/dist/runtime/sub-agent-task-path.js.map +1 -0
- package/dist/runtime/title-generation.js +3 -5
- package/dist/runtime/title-generation.js.map +1 -1
- package/dist/runtime/tool-adapter.d.ts +0 -9
- package/dist/runtime/tool-adapter.js +12 -21
- package/dist/runtime/tool-adapter.js.map +1 -1
- package/dist/runtime/write-todos-tool.d.ts +3 -0
- package/dist/runtime/write-todos-tool.js +95 -0
- package/dist/runtime/write-todos-tool.js.map +1 -0
- package/dist/sdk/agent.d.ts +19 -12
- package/dist/sdk/agent.js +318 -91
- package/dist/sdk/agent.js.map +1 -1
- package/dist/sdk/cancellation.d.ts +7 -0
- package/dist/sdk/cancellation.js +16 -0
- package/dist/sdk/cancellation.js.map +1 -0
- package/dist/sdk/catalog.js +20 -4
- package/dist/sdk/catalog.js.map +1 -1
- package/dist/sdk/mcp-client.d.ts +1 -1
- package/dist/sdk/mcp-client.js +2 -2
- package/dist/sdk/mcp-client.js.map +1 -1
- package/dist/sdk/memory.d.ts +1 -3
- package/dist/sdk/memory.js +0 -14
- package/dist/sdk/memory.js.map +1 -1
- package/dist/sdk/provider-capabilities.js +1 -0
- package/dist/sdk/provider-capabilities.js.map +1 -1
- package/dist/sdk/tool.d.ts +3 -0
- package/dist/sdk/tool.js +42 -10
- package/dist/sdk/tool.js.map +1 -1
- package/dist/storage/base-memory.d.ts +0 -31
- package/dist/storage/base-memory.js +0 -9
- package/dist/storage/base-memory.js.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/runtime/event.d.ts +31 -1
- package/dist/types/runtime/event.js +2 -0
- package/dist/types/runtime/event.js.map +1 -1
- package/dist/types/sdk/agent-builder.d.ts +0 -1
- package/dist/types/sdk/agent.d.ts +20 -15
- package/dist/types/sdk/memory.d.ts +0 -42
- package/dist/types/sdk/message.d.ts +1 -0
- package/dist/types/sdk/tool.d.ts +19 -1
- package/dist/utils/json-schema.d.ts +3 -0
- package/dist/utils/json-schema.js +72 -0
- package/dist/utils/json-schema.js.map +1 -0
- package/dist/workspace/filesystem/daytona-filesystem.d.ts +25 -0
- package/dist/workspace/filesystem/daytona-filesystem.js +130 -0
- package/dist/workspace/filesystem/daytona-filesystem.js.map +1 -0
- package/dist/workspace/filesystem/n8n-sandbox-filesystem.d.ts +25 -0
- package/dist/workspace/filesystem/n8n-sandbox-filesystem.js +126 -0
- package/dist/workspace/filesystem/n8n-sandbox-filesystem.js.map +1 -0
- package/dist/workspace/sandbox/base-sandbox.d.ts +1 -0
- package/dist/workspace/sandbox/base-sandbox.js +5 -0
- package/dist/workspace/sandbox/base-sandbox.js.map +1 -1
- package/dist/workspace/sandbox/create-workspace.d.ts +4 -0
- package/dist/workspace/sandbox/create-workspace.js +58 -0
- package/dist/workspace/sandbox/create-workspace.js.map +1 -0
- package/dist/workspace/sandbox/daytona-auth-manager.d.ts +26 -0
- package/dist/workspace/sandbox/daytona-auth-manager.js +84 -0
- package/dist/workspace/sandbox/daytona-auth-manager.js.map +1 -0
- package/dist/workspace/sandbox/daytona-sandbox.d.ts +72 -0
- package/dist/workspace/sandbox/daytona-sandbox.js +357 -0
- package/dist/workspace/sandbox/daytona-sandbox.js.map +1 -0
- package/dist/workspace/sandbox/index.d.ts +7 -0
- package/dist/workspace/sandbox/index.js +22 -0
- package/dist/workspace/sandbox/index.js.map +1 -0
- package/dist/workspace/sandbox/lazy-daytona.d.ts +2 -0
- package/dist/workspace/sandbox/lazy-daytona.js +12 -0
- package/dist/workspace/sandbox/lazy-daytona.js.map +1 -0
- package/dist/workspace/sandbox/logger.d.ts +12 -0
- package/dist/workspace/sandbox/logger.js +3 -0
- package/dist/workspace/sandbox/logger.js.map +1 -0
- package/dist/workspace/sandbox/n8n-sandbox-sandbox.d.ts +35 -0
- package/dist/workspace/sandbox/n8n-sandbox-sandbox.js +138 -0
- package/dist/workspace/sandbox/n8n-sandbox-sandbox.js.map +1 -0
- package/dist/workspace/sandbox/provider.d.ts +4 -0
- package/dist/workspace/sandbox/provider.js +14 -0
- package/dist/workspace/sandbox/provider.js.map +1 -0
- package/dist/workspace/sandbox/run-in-sandbox.d.ts +26 -0
- package/dist/workspace/sandbox/run-in-sandbox.js +19 -0
- package/dist/workspace/sandbox/run-in-sandbox.js.map +1 -0
- package/dist/workspace/sandbox/types.d.ts +41 -0
- package/dist/workspace/sandbox/types.js +3 -0
- package/dist/workspace/sandbox/types.js.map +1 -0
- package/dist/workspace/sandbox/workspace-root.d.ts +16 -0
- package/dist/workspace/sandbox/workspace-root.js +69 -0
- package/dist/workspace/sandbox/workspace-root.js.map +1 -0
- package/dist/workspace/tools/batch-str-replace-file.js +2 -2
- package/dist/workspace/tools/batch-str-replace-file.js.map +1 -1
- package/dist/workspace/tools/str-replace-file.js +2 -2
- package/dist/workspace/tools/str-replace-file.js.map +1 -1
- package/package.json +29 -17
- package/dist/sdk/network.d.ts +0 -20
- package/dist/sdk/network.js +0 -46
- package/dist/sdk/network.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { ProviderOptions } from '@ai-sdk/provider-utils';
|
|
2
|
-
import type { LanguageModel } from 'ai';
|
|
2
|
+
import type { LanguageModel, smoothStream } from 'ai';
|
|
3
3
|
import type { JsonSchema7Type } from 'zod-to-json-schema';
|
|
4
4
|
import type { AgentMessage, ContentMetadata } from './message';
|
|
5
|
-
import type { BuiltTool } from './tool';
|
|
6
5
|
import type { ProviderId, ProviderCredentials } from '../../runtime/provider-credentials';
|
|
7
|
-
import type { AgentEvent, AgentEventHandler } from '../runtime/event';
|
|
6
|
+
import type { AgentEvent, AgentEventHandler, SubAgentCompletedPayload, SubAgentStartedPayload } from '../runtime/event';
|
|
8
7
|
import type { SerializedMessageList } from '../runtime/message-list';
|
|
9
8
|
import type { BuiltTelemetry } from '../telemetry';
|
|
10
9
|
import type { JSONValue } from '../utils/json';
|
|
10
|
+
export type SmoothStreamOptions = NonNullable<Parameters<typeof smoothStream>[0]>;
|
|
11
11
|
export type FinishReason = 'stop' | 'max-iterations' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other';
|
|
12
12
|
export type TokenUsage<T extends Record<string, unknown> = Record<string, unknown>> = {
|
|
13
13
|
promptTokens: number;
|
|
@@ -82,12 +82,20 @@ export type StreamChunk = ContentMetadata & ({
|
|
|
82
82
|
type: 'tool-execution-start';
|
|
83
83
|
toolCallId: string;
|
|
84
84
|
toolName: string;
|
|
85
|
+
startTime: number;
|
|
86
|
+
} | {
|
|
87
|
+
type: 'tool-execution-end';
|
|
88
|
+
toolCallId: string;
|
|
89
|
+
toolName: string;
|
|
90
|
+
isError: boolean;
|
|
91
|
+
endTime: number;
|
|
85
92
|
} | {
|
|
86
93
|
type: 'tool-result';
|
|
87
94
|
toolCallId: string;
|
|
88
95
|
toolName: string;
|
|
89
96
|
output: unknown;
|
|
90
97
|
isError?: boolean;
|
|
98
|
+
canceled?: boolean;
|
|
91
99
|
} | {
|
|
92
100
|
type: 'tool-call-suspended';
|
|
93
101
|
runId: string;
|
|
@@ -99,14 +107,16 @@ export type StreamChunk = ContentMetadata & ({
|
|
|
99
107
|
} | {
|
|
100
108
|
type: 'message';
|
|
101
109
|
message: AgentMessage;
|
|
102
|
-
} | {
|
|
110
|
+
} | ({
|
|
111
|
+
type: 'subagent-started';
|
|
112
|
+
} & SubAgentStartedPayload) | ({
|
|
113
|
+
type: 'subagent-completed';
|
|
114
|
+
} & SubAgentCompletedPayload) | {
|
|
103
115
|
type: 'finish';
|
|
104
116
|
finishReason: FinishReason;
|
|
105
117
|
usage?: TokenUsage;
|
|
106
118
|
model?: string;
|
|
107
119
|
structuredOutput?: unknown;
|
|
108
|
-
subAgentUsage?: SubAgentUsage[];
|
|
109
|
-
totalCost?: number;
|
|
110
120
|
} | {
|
|
111
121
|
type: 'error';
|
|
112
122
|
error: unknown;
|
|
@@ -123,6 +133,7 @@ export interface ExecutionOptions {
|
|
|
123
133
|
maxIterations?: number;
|
|
124
134
|
abortSignal?: AbortSignal;
|
|
125
135
|
providerOptions?: ProviderOptions;
|
|
136
|
+
smoothStream?: SmoothStreamOptions | false;
|
|
126
137
|
telemetry?: BuiltTelemetry;
|
|
127
138
|
executionCounter?: AgentExecutionCounter;
|
|
128
139
|
}
|
|
@@ -134,11 +145,7 @@ export interface ToolResultEntry {
|
|
|
134
145
|
input: unknown;
|
|
135
146
|
output: unknown;
|
|
136
147
|
transformed?: boolean;
|
|
137
|
-
|
|
138
|
-
export interface SubAgentUsage {
|
|
139
|
-
agent: string;
|
|
140
|
-
model?: string;
|
|
141
|
-
usage: TokenUsage;
|
|
148
|
+
canceled?: boolean;
|
|
142
149
|
}
|
|
143
150
|
export interface GenerateResult {
|
|
144
151
|
runId: string;
|
|
@@ -149,8 +156,6 @@ export interface GenerateResult {
|
|
|
149
156
|
finishReason?: FinishReason;
|
|
150
157
|
providerMetadata?: Record<string, unknown>;
|
|
151
158
|
toolCalls?: ToolResultEntry[];
|
|
152
|
-
subAgentUsage?: SubAgentUsage[];
|
|
153
|
-
totalCost?: number;
|
|
154
159
|
pendingSuspend?: Array<{
|
|
155
160
|
runId: string;
|
|
156
161
|
toolCallId: string;
|
|
@@ -160,10 +165,12 @@ export interface GenerateResult {
|
|
|
160
165
|
resumeSchema?: JsonSchema7Type;
|
|
161
166
|
}>;
|
|
162
167
|
error?: unknown;
|
|
168
|
+
getState(): SerializableAgentState;
|
|
163
169
|
}
|
|
164
170
|
export interface StreamResult {
|
|
165
171
|
runId: string;
|
|
166
172
|
stream: ReadableStream<StreamChunk>;
|
|
173
|
+
getState(): SerializableAgentState;
|
|
167
174
|
}
|
|
168
175
|
export interface ResumeOptions {
|
|
169
176
|
runId: string;
|
|
@@ -174,8 +181,6 @@ export interface BuiltAgent {
|
|
|
174
181
|
generate(input: AgentMessage[] | string, options?: RunOptions & ExecutionOptions): Promise<GenerateResult>;
|
|
175
182
|
stream(input: AgentMessage[] | string, options?: RunOptions & ExecutionOptions): Promise<StreamResult>;
|
|
176
183
|
on(event: AgentEvent, handler: AgentEventHandler): void;
|
|
177
|
-
asTool(description: string): BuiltTool;
|
|
178
|
-
getState(): SerializableAgentState;
|
|
179
184
|
abort(): void;
|
|
180
185
|
close(): Promise<void>;
|
|
181
186
|
resume(method: 'generate', data: unknown, options: ResumeOptions & ExecutionOptions): Promise<GenerateResult>;
|
|
@@ -31,51 +31,10 @@ export interface BuiltMemory {
|
|
|
31
31
|
messages: AgentDbMessage[];
|
|
32
32
|
}): Promise<void>;
|
|
33
33
|
deleteMessages(messageIds: string[]): Promise<void>;
|
|
34
|
-
search?(query: string, opts?: {
|
|
35
|
-
scope?: 'thread' | 'resource';
|
|
36
|
-
threadId?: string;
|
|
37
|
-
resourceId?: string;
|
|
38
|
-
topK?: number;
|
|
39
|
-
messageRange?: {
|
|
40
|
-
before: number;
|
|
41
|
-
after: number;
|
|
42
|
-
};
|
|
43
|
-
}): Promise<AgentDbMessage[]>;
|
|
44
|
-
saveEmbeddings?(opts: {
|
|
45
|
-
scope?: 'thread' | 'resource';
|
|
46
|
-
threadId?: string;
|
|
47
|
-
resourceId?: string;
|
|
48
|
-
entries: Array<{
|
|
49
|
-
id: string;
|
|
50
|
-
vector: number[];
|
|
51
|
-
text: string;
|
|
52
|
-
model: string;
|
|
53
|
-
}>;
|
|
54
|
-
}): Promise<void>;
|
|
55
|
-
queryEmbeddings?(opts: {
|
|
56
|
-
scope?: 'thread' | 'resource';
|
|
57
|
-
threadId?: string;
|
|
58
|
-
resourceId?: string;
|
|
59
|
-
vector: number[];
|
|
60
|
-
topK: number;
|
|
61
|
-
}): Promise<Array<{
|
|
62
|
-
id: string;
|
|
63
|
-
score: number;
|
|
64
|
-
}>>;
|
|
65
34
|
episodic?: EpisodicMemoryMethods;
|
|
66
35
|
close?(): Promise<void>;
|
|
67
36
|
describe(): MemoryDescriptor;
|
|
68
37
|
}
|
|
69
|
-
export interface SemanticRecallConfig {
|
|
70
|
-
scope?: 'thread' | 'resource';
|
|
71
|
-
topK: number;
|
|
72
|
-
messageRange?: {
|
|
73
|
-
before: number;
|
|
74
|
-
after: number;
|
|
75
|
-
};
|
|
76
|
-
embedder?: string;
|
|
77
|
-
apiKey?: string;
|
|
78
|
-
}
|
|
79
38
|
export type EpisodicMemoryStatus = 'active' | 'superseded' | 'dropped';
|
|
80
39
|
export interface EpisodicMemoryScope {
|
|
81
40
|
resourceId: string;
|
|
@@ -244,7 +203,6 @@ export interface ObservationalMemoryConfig {
|
|
|
244
203
|
}
|
|
245
204
|
interface MemoryConfigBase {
|
|
246
205
|
observationLog?: ObservationLogMemoryConfig;
|
|
247
|
-
semanticRecall?: SemanticRecallConfig;
|
|
248
206
|
episodicMemory?: EpisodicMemoryConfig;
|
|
249
207
|
titleGeneration?: TitleGenerationConfig;
|
|
250
208
|
}
|
package/dist/types/sdk/tool.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { JSONSchema7 } from 'json-schema';
|
|
2
2
|
import type { ZodType } from 'zod';
|
|
3
|
+
import type { AgentExecutionCounter } from './agent';
|
|
3
4
|
import type { AgentMessage } from './message';
|
|
5
|
+
import type { AgentEventData } from '../runtime/event';
|
|
4
6
|
import type { BuiltTelemetry } from '../telemetry';
|
|
5
7
|
import type { JSONObject } from '../utils/json';
|
|
6
8
|
export interface ToolExecutionContext {
|
|
@@ -9,20 +11,32 @@ export interface ToolExecutionContext {
|
|
|
9
11
|
threadId: string;
|
|
10
12
|
resourceId: string;
|
|
11
13
|
};
|
|
14
|
+
emitEvent?: (event: AgentEventData) => void;
|
|
15
|
+
abortSignal?: AbortSignal;
|
|
16
|
+
executionCounter?: AgentExecutionCounter;
|
|
12
17
|
}
|
|
13
18
|
export interface ToolContext {
|
|
14
19
|
toolCallId?: string;
|
|
15
20
|
runId?: string;
|
|
16
21
|
persistence?: ToolExecutionContext['persistence'];
|
|
17
22
|
parentTelemetry?: BuiltTelemetry;
|
|
23
|
+
emitEvent?: ToolExecutionContext['emitEvent'];
|
|
24
|
+
abortSignal?: ToolExecutionContext['abortSignal'];
|
|
25
|
+
executionCounter?: ToolExecutionContext['executionCounter'];
|
|
18
26
|
}
|
|
19
27
|
export interface InterruptibleToolContext<S = unknown, R = unknown> {
|
|
20
28
|
suspend: (payload: S) => Promise<never>;
|
|
21
29
|
resumeData: R | undefined;
|
|
30
|
+
cancellation?: {
|
|
31
|
+
message: string;
|
|
32
|
+
};
|
|
22
33
|
toolCallId?: string;
|
|
23
34
|
runId?: string;
|
|
24
35
|
persistence?: ToolExecutionContext['persistence'];
|
|
25
36
|
parentTelemetry?: BuiltTelemetry;
|
|
37
|
+
emitEvent?: ToolExecutionContext['emitEvent'];
|
|
38
|
+
abortSignal?: ToolExecutionContext['abortSignal'];
|
|
39
|
+
executionCounter?: ToolExecutionContext['executionCounter'];
|
|
26
40
|
}
|
|
27
41
|
export interface BuiltTool {
|
|
28
42
|
readonly name: string;
|
|
@@ -30,7 +44,11 @@ export interface BuiltTool {
|
|
|
30
44
|
readonly systemInstruction?: string;
|
|
31
45
|
readonly suspendSchema?: ZodType | JSONSchema7;
|
|
32
46
|
readonly resumeSchema?: ZodType | JSONSchema7;
|
|
33
|
-
readonly
|
|
47
|
+
readonly approval?: {
|
|
48
|
+
readonly required: boolean;
|
|
49
|
+
readonly conditional?: boolean;
|
|
50
|
+
};
|
|
51
|
+
readonly handleCancellation?: boolean;
|
|
34
52
|
readonly toMessage?: (output: unknown) => AgentMessage | undefined;
|
|
35
53
|
readonly toModelOutput?: (output: unknown) => unknown;
|
|
36
54
|
readonly handler?: (input: unknown, ctx: ToolContext | InterruptibleToolContext) => Promise<unknown>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fixSchema = void 0;
|
|
4
|
+
exports.lockAdditionalProperties = lockAdditionalProperties;
|
|
5
|
+
const fixSchema = (schema) => {
|
|
6
|
+
if (typeof schema === 'object' &&
|
|
7
|
+
schema !== null &&
|
|
8
|
+
'properties' in schema &&
|
|
9
|
+
!('type' in schema)) {
|
|
10
|
+
return { ...schema, type: 'object' };
|
|
11
|
+
}
|
|
12
|
+
return schema;
|
|
13
|
+
};
|
|
14
|
+
exports.fixSchema = fixSchema;
|
|
15
|
+
function lockAdditionalProperties(schema) {
|
|
16
|
+
const result = lockDefinition(schema);
|
|
17
|
+
return typeof result === 'object' ? result : schema;
|
|
18
|
+
}
|
|
19
|
+
function lockDefinition(schema) {
|
|
20
|
+
if (typeof schema !== 'object' || schema === null)
|
|
21
|
+
return schema;
|
|
22
|
+
const result = { ...schema };
|
|
23
|
+
if (result.properties !== undefined && result.type === undefined) {
|
|
24
|
+
result.type = 'object';
|
|
25
|
+
}
|
|
26
|
+
const isObjectSchema = result.type === 'object' ||
|
|
27
|
+
(Array.isArray(result.type) && result.type.includes('object')) ||
|
|
28
|
+
result.properties !== undefined;
|
|
29
|
+
if (isObjectSchema && result.additionalProperties === undefined) {
|
|
30
|
+
result.additionalProperties = false;
|
|
31
|
+
}
|
|
32
|
+
if (result.properties) {
|
|
33
|
+
result.properties = mapDefinitions(result.properties);
|
|
34
|
+
}
|
|
35
|
+
if (result.$defs) {
|
|
36
|
+
result.$defs = mapDefinitions(result.$defs);
|
|
37
|
+
}
|
|
38
|
+
if (result.definitions) {
|
|
39
|
+
result.definitions = mapDefinitions(result.definitions);
|
|
40
|
+
}
|
|
41
|
+
if (result.items !== undefined) {
|
|
42
|
+
result.items = Array.isArray(result.items)
|
|
43
|
+
? result.items.map(lockDefinition)
|
|
44
|
+
: lockDefinition(result.items);
|
|
45
|
+
}
|
|
46
|
+
if (typeof result.additionalProperties === 'object' && result.additionalProperties !== null) {
|
|
47
|
+
result.additionalProperties = lockDefinition(result.additionalProperties);
|
|
48
|
+
}
|
|
49
|
+
for (const key of ['allOf', 'anyOf', 'oneOf']) {
|
|
50
|
+
const branch = result[key];
|
|
51
|
+
if (Array.isArray(branch)) {
|
|
52
|
+
result[key] = branch.map(lockDefinition);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (result.not !== undefined) {
|
|
56
|
+
result.not = lockDefinition(result.not);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
function mapDefinitions(record) {
|
|
61
|
+
const out = {};
|
|
62
|
+
for (const [key, value] of Object.entries(record)) {
|
|
63
|
+
Object.defineProperty(out, key, {
|
|
64
|
+
value: lockDefinition(value),
|
|
65
|
+
enumerable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=json-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../../src/utils/json-schema.ts"],"names":[],"mappings":";;;AAqCA,4DAGC;AA7BM,MAAM,SAAS,GAAG,CAAC,MAAmB,EAAe,EAAE;IAC7D,IACC,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,YAAY,IAAI,MAAM;QACtB,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,EAClB,CAAC;QACF,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,QAAiB,EAAE,CAAC;IAC/C,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAVW,QAAA,SAAS,aAUpB;AAgBF,SAAgB,wBAAwB,CAAC,MAAmB;IAC3D,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IACtC,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;AACrD,CAAC;AAED,SAAS,cAAc,CAAC,MAA6B;IACpD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAEjE,MAAM,MAAM,GAAgB,EAAE,GAAG,MAAM,EAAE,CAAC;IAG1C,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,KAAK,S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CAAC,CAAC;IAC3E,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAU,EAAE,CAAC;QACxD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC1C,CAAC;IACF,CAAC;IACD,IAAI,MAAM,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,CAAC,GAAG,GAAG,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAOD,SAAS,cAAc,CACtB,MAA6C;IAE7C,MAAM,GAAG,GAA0C,EAAE,CAAC;IACtD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE;YAC/B,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC;YAC5B,UAAU,EAAE,IAAI;YAChB,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,IAAI;SAClB,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CopyOptions, FileContent, FileEntry, FileStat, ListOptions, ProviderStatus, ReadOptions, RemoveOptions, WriteOptions } from '../types';
|
|
2
|
+
import { BaseFilesystem } from './base-filesystem';
|
|
3
|
+
import type { DaytonaSandbox } from '../sandbox/daytona-sandbox';
|
|
4
|
+
export declare class DaytonaFilesystem extends BaseFilesystem {
|
|
5
|
+
private readonly sandbox;
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly name = "DaytonaFilesystem";
|
|
8
|
+
readonly provider = "daytona";
|
|
9
|
+
status: ProviderStatus;
|
|
10
|
+
constructor(sandbox: DaytonaSandbox);
|
|
11
|
+
private withFs;
|
|
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
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DaytonaFilesystem = void 0;
|
|
4
|
+
const base_filesystem_1 = require("./base-filesystem");
|
|
5
|
+
class DaytonaFilesystem extends base_filesystem_1.BaseFilesystem {
|
|
6
|
+
constructor(sandbox) {
|
|
7
|
+
super();
|
|
8
|
+
this.sandbox = sandbox;
|
|
9
|
+
this.name = 'DaytonaFilesystem';
|
|
10
|
+
this.provider = 'daytona';
|
|
11
|
+
this.status = 'pending';
|
|
12
|
+
this.id = `daytona-fs-${sandbox.id}`;
|
|
13
|
+
}
|
|
14
|
+
async withFs(op) {
|
|
15
|
+
await this.ensureReady();
|
|
16
|
+
return await this.sandbox.withFilesystem(op);
|
|
17
|
+
}
|
|
18
|
+
async readFile(path, options) {
|
|
19
|
+
return await this.withFs(async (fs) => {
|
|
20
|
+
const buffer = await fs.downloadFile(path);
|
|
21
|
+
if (options?.encoding) {
|
|
22
|
+
return buffer.toString(options.encoding);
|
|
23
|
+
}
|
|
24
|
+
return buffer;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async writeFile(path, content, options) {
|
|
28
|
+
await this.withFs(async (fs) => {
|
|
29
|
+
if (options?.recursive) {
|
|
30
|
+
const dir = path.substring(0, path.lastIndexOf('/'));
|
|
31
|
+
if (dir) {
|
|
32
|
+
await fs.createFolder(dir, '755');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const buffer = typeof content === 'string' ? Buffer.from(content, 'utf-8') : Buffer.from(content);
|
|
36
|
+
await fs.uploadFile(buffer, path);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async appendFile(path, content) {
|
|
40
|
+
await this.withFs(async (fs) => {
|
|
41
|
+
let existing;
|
|
42
|
+
try {
|
|
43
|
+
existing = await fs.downloadFile(path);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (!isDaytona404(error))
|
|
47
|
+
throw error;
|
|
48
|
+
existing = Buffer.alloc(0);
|
|
49
|
+
}
|
|
50
|
+
const append = typeof content === 'string' ? Buffer.from(content, 'utf-8') : Buffer.from(content);
|
|
51
|
+
await fs.uploadFile(Buffer.concat([existing, append]), path);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async deleteFile(path, options) {
|
|
55
|
+
await this.withFs(async (fs) => await fs.deleteFile(path, options?.recursive));
|
|
56
|
+
}
|
|
57
|
+
async copyFile(src, dest, _options) {
|
|
58
|
+
await this.withFs(async (fs) => {
|
|
59
|
+
const content = await fs.downloadFile(src);
|
|
60
|
+
await fs.uploadFile(content, dest);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async moveFile(src, dest, _options) {
|
|
64
|
+
await this.withFs(async (fs) => await fs.moveFiles(src, dest));
|
|
65
|
+
}
|
|
66
|
+
async mkdir(path, _options) {
|
|
67
|
+
await this.withFs(async (fs) => await fs.createFolder(path, '755'));
|
|
68
|
+
}
|
|
69
|
+
async rmdir(path, options) {
|
|
70
|
+
await this.withFs(async (fs) => await fs.deleteFile(path, options?.recursive ?? false));
|
|
71
|
+
}
|
|
72
|
+
async readdir(path, _options) {
|
|
73
|
+
return await this.withFs(async (fs) => {
|
|
74
|
+
const files = await fs.listFiles(path);
|
|
75
|
+
return files.map((f) => ({
|
|
76
|
+
name: f.name ?? '',
|
|
77
|
+
type: f.isDir ? 'directory' : 'file',
|
|
78
|
+
size: f.size,
|
|
79
|
+
}));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async exists(path) {
|
|
83
|
+
return await this.withFs(async (fs) => {
|
|
84
|
+
try {
|
|
85
|
+
await fs.getFileDetails(path);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
if (isDaytona404(error))
|
|
90
|
+
return false;
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async stat(path) {
|
|
96
|
+
return await this.withFs(async (fs) => {
|
|
97
|
+
let info;
|
|
98
|
+
try {
|
|
99
|
+
info = await fs.getFileDetails(path);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (isDaytona404(error)) {
|
|
103
|
+
throw new DaytonaFileNotFoundError(path);
|
|
104
|
+
}
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
name: info.name ?? path.split('/').pop() ?? '',
|
|
109
|
+
path,
|
|
110
|
+
type: info.isDir ? 'directory' : 'file',
|
|
111
|
+
size: info.size ?? 0,
|
|
112
|
+
createdAt: new Date(info.modTime ?? 0),
|
|
113
|
+
modifiedAt: new Date(info.modTime ?? 0),
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.DaytonaFilesystem = DaytonaFilesystem;
|
|
119
|
+
class DaytonaFileNotFoundError extends Error {
|
|
120
|
+
constructor(path) {
|
|
121
|
+
super(`File not found: ${path}`);
|
|
122
|
+
this.name = 'DaytonaFileNotFoundError';
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function isDaytona404(error) {
|
|
126
|
+
return (error instanceof Error &&
|
|
127
|
+
'statusCode' in error &&
|
|
128
|
+
error.statusCode === 404);
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=daytona-filesystem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daytona-filesystem.js","sourceRoot":"","sources":["../../../src/workspace/filesystem/daytona-filesystem.ts"],"names":[],"mappings":";;;AAoBA,uDAAmD;AASnD,MAAa,iBAAkB,SAAQ,gCAAc;IAMpD,YAA6B,OAAuB;QACnD,KAAK,EAAE,CAAC;QADoB,YAAO,GAAP,OAAO,CAAgB;QAJ3C,SAAI,GAAG,mBAAmB,CAAC;QAC3B,aAAQ,GAAG,SAAS,CAAC;QAC9B,WAAM,GAAmB,SAAS,CAAC;QAIlC,IAAI,CAAC,EAAE,GAAG,cAAc,OAAO,CAAC,EAAE,EAAE,CAAC;IACtC,CAAC;IAOO,KAAK,CAAC,MAAM,CAAI,EAAuC;QAC9D,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QACzB,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAY,EAAE,OAAqB;QACjD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;YACrC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,OAAO,EAAE,QAAQ,EAAE,CAAC;gBACvB,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC1C,CAAC;YACD,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cAAc,CAAC,IAAI,CAAC,CAAC;YACtC,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACzB,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;oBACzB,MAAM,IAAI,wBAAwB,CAAC,IAAI,CAAC,CAAC;gBAC1C,CAAC;gBACD,MAAM,KAAK,CAAC;YACb,CAAC;YACD,OAAO;gBACN,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE;gBAC9C,IAAI;gBACJ,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM;gBACvC,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC;gBACpB,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;gBACtC,UAAU,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;aACvC,CAAC;QACH,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AArID,8CAqIC;AAED,MAAM,wBAAyB,SAAQ,KAAK;IAC3C,YAAY,IAAY;QACvB,KAAK,CAAC,mBAAmB,IAAI,EAAE,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACxC,CAAC;CACD;AAED,SAAS,YAAY,CAAC,KAAc;IACnC,OAAO,CACN,KAAK,YAAY,KAAK;QACtB,YAAY,IAAI,KAAK;QACpB,KAAiC,CAAC,UAAU,KAAK,GAAG,CACrD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CopyOptions, FileContent, FileEntry, FileStat, ListOptions, ProviderStatus, ReadOptions, RemoveOptions, WriteOptions } from '../types';
|
|
2
|
+
import { BaseFilesystem } from './base-filesystem';
|
|
3
|
+
import type { N8nSandboxServiceSandbox } from '../sandbox/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
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.N8nSandboxFilesystem = void 0;
|
|
4
|
+
const sandbox_client_1 = require("@n8n/sandbox-client");
|
|
5
|
+
const posix_1 = require("node:path/posix");
|
|
6
|
+
const base_filesystem_1 = require("./base-filesystem");
|
|
7
|
+
function getParentDirectory(path) {
|
|
8
|
+
const parent = (0, posix_1.dirname)(path);
|
|
9
|
+
return parent === '.' || parent === '/' ? null : parent;
|
|
10
|
+
}
|
|
11
|
+
class N8nSandboxFilesystem extends base_filesystem_1.BaseFilesystem {
|
|
12
|
+
constructor(sandbox) {
|
|
13
|
+
super();
|
|
14
|
+
this.sandbox = sandbox;
|
|
15
|
+
this.name = 'N8nSandboxFilesystem';
|
|
16
|
+
this.provider = 'n8n-sandbox';
|
|
17
|
+
this.status = 'pending';
|
|
18
|
+
this.id = `n8n-sandbox-fs-${sandbox.id}`;
|
|
19
|
+
}
|
|
20
|
+
async getClientAndSandboxId() {
|
|
21
|
+
await this.sandbox.ensureRunning();
|
|
22
|
+
return {
|
|
23
|
+
client: this.sandbox.getClient(),
|
|
24
|
+
sandboxId: this.sandbox.id,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
async readFile(path, options) {
|
|
28
|
+
await this.ensureReady();
|
|
29
|
+
const { client, sandboxId } = await this.getClientAndSandboxId();
|
|
30
|
+
const content = await client.readFile(sandboxId, path);
|
|
31
|
+
if (options?.encoding) {
|
|
32
|
+
return content.toString(options.encoding);
|
|
33
|
+
}
|
|
34
|
+
return content;
|
|
35
|
+
}
|
|
36
|
+
async writeFile(path, content, options) {
|
|
37
|
+
await this.ensureReady();
|
|
38
|
+
const { client, sandboxId } = await this.getClientAndSandboxId();
|
|
39
|
+
if (options?.recursive) {
|
|
40
|
+
const parent = getParentDirectory(path);
|
|
41
|
+
if (parent) {
|
|
42
|
+
await client.mkdir(sandboxId, parent, true);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
await client.writeFile(sandboxId, path, content, options?.overwrite ?? true);
|
|
46
|
+
}
|
|
47
|
+
async appendFile(path, content) {
|
|
48
|
+
await this.ensureReady();
|
|
49
|
+
const { client, sandboxId } = await this.getClientAndSandboxId();
|
|
50
|
+
await client.appendFile(sandboxId, path, content);
|
|
51
|
+
}
|
|
52
|
+
async deleteFile(path, options) {
|
|
53
|
+
await this.ensureReady();
|
|
54
|
+
const { client, sandboxId } = await this.getClientAndSandboxId();
|
|
55
|
+
await client.deleteFile(sandboxId, path, {
|
|
56
|
+
recursive: options?.recursive,
|
|
57
|
+
force: options?.force,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async copyFile(src, dest, options) {
|
|
61
|
+
await this.ensureReady();
|
|
62
|
+
const { client, sandboxId } = await this.getClientAndSandboxId();
|
|
63
|
+
await client.copyFile(sandboxId, {
|
|
64
|
+
src,
|
|
65
|
+
dest,
|
|
66
|
+
recursive: options?.recursive,
|
|
67
|
+
overwrite: options?.overwrite,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async moveFile(src, dest, options) {
|
|
71
|
+
await this.ensureReady();
|
|
72
|
+
const { client, sandboxId } = await this.getClientAndSandboxId();
|
|
73
|
+
await client.moveFile(sandboxId, {
|
|
74
|
+
src,
|
|
75
|
+
dest,
|
|
76
|
+
overwrite: options?.overwrite,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async mkdir(path, options) {
|
|
80
|
+
await this.ensureReady();
|
|
81
|
+
const { client, sandboxId } = await this.getClientAndSandboxId();
|
|
82
|
+
await client.mkdir(sandboxId, path, options?.recursive ?? false);
|
|
83
|
+
}
|
|
84
|
+
async rmdir(path, options) {
|
|
85
|
+
await this.deleteFile(path, options);
|
|
86
|
+
}
|
|
87
|
+
async readdir(path, _options) {
|
|
88
|
+
await this.ensureReady();
|
|
89
|
+
const { client, sandboxId } = await this.getClientAndSandboxId();
|
|
90
|
+
const files = await client.listFiles(sandboxId, { path });
|
|
91
|
+
return files.map((entry) => ({
|
|
92
|
+
name: entry.name,
|
|
93
|
+
type: entry.isDir ? 'directory' : 'file',
|
|
94
|
+
size: entry.size,
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
async exists(path) {
|
|
98
|
+
await this.ensureReady();
|
|
99
|
+
try {
|
|
100
|
+
const { client, sandboxId } = await this.getClientAndSandboxId();
|
|
101
|
+
await client.stat(sandboxId, path);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (error instanceof sandbox_client_1.SandboxServiceError && error.status === 404) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async stat(path) {
|
|
112
|
+
await this.ensureReady();
|
|
113
|
+
const { client, sandboxId } = await this.getClientAndSandboxId();
|
|
114
|
+
const stat = await client.stat(sandboxId, path);
|
|
115
|
+
return {
|
|
116
|
+
name: stat.name,
|
|
117
|
+
path: stat.path,
|
|
118
|
+
type: stat.type,
|
|
119
|
+
size: stat.size,
|
|
120
|
+
createdAt: new Date(stat.createdAt),
|
|
121
|
+
modifiedAt: new Date(stat.modifiedAt),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.N8nSandboxFilesystem = N8nSandboxFilesystem;
|
|
126
|
+
//# sourceMappingURL=n8n-sandbox-filesystem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"n8n-sandbox-filesystem.js","sourceRoot":"","sources":["../../../src/workspace/filesystem/n8n-sandbox-filesystem.ts"],"names":[],"mappings":";;;AAAA,wDAA0D;AAC1D,2CAA0C;AAa1C,uDAAmD;AAGnD,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,gCAAc;IASvD,YAA6B,OAAiC;QAC7D,KAAK,EAAE,CAAC;QADoB,YAAO,GAAP,OAAO,CAA0B;QANrD,SAAI,GAAG,sBAAsB,CAAC;QAE9B,aAAQ,GAAG,aAAa,CAAC;QAElC,WAAM,GAAmB,SAAS,CAAC;QAIlC,IAAI,CAAC,EAAE,GAAG,kBAAkB,OAAO,CAAC,EAAE,EAAE,CAAC;IAC1C,CAAC;IAEO,KAAK,CAAC,qBAAqB;QAClC,MAAM,IAAI,CAAC,O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,KAAK,EAAE,CAAC;YAChB,IAAI,KAAK,YAAY,oCAAmB,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBAClE,OAAO,KAAK,CAAC;YACd,CAAC;YACD,MAAM,KAAK,CAAC;QACb,CAAC;IACF,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAY;QACtB,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QACzB,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAC;QACjE,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,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"}
|
|
@@ -19,6 +19,7 @@ export declare abstract class BaseSandbox implements WorkspaceSandbox {
|
|
|
19
19
|
_start(): Promise<void>;
|
|
20
20
|
_stop(): Promise<void>;
|
|
21
21
|
_destroy(): Promise<void>;
|
|
22
|
+
protected markNeedsStart(): void;
|
|
22
23
|
ensureRunning(): Promise<void>;
|
|
23
24
|
executeCommand(command: string, args?: string[], options?: ExecuteCommandOptions): Promise<CommandResult>;
|
|
24
25
|
getInstructions(): string;
|
|
@@ -75,6 +75,11 @@ class BaseSandbox {
|
|
|
75
75
|
this.destroyPromise = undefined;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
+
markNeedsStart() {
|
|
79
|
+
if (this.status === 'destroyed' || this.status === 'destroying')
|
|
80
|
+
return;
|
|
81
|
+
this.status = 'pending';
|
|
82
|
+
}
|
|
78
83
|
async ensureRunning() {
|
|
79
84
|
if (this.status === 'destroyed') {
|
|
80
85
|
throw new Error(`Sandbox "${this.name}" has been destroyed`);
|