@n8n/agents 0.10.1 → 0.12.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 +10 -2
- package/dist/index.js +36 -5
- package/dist/index.js.map +1 -1
- package/dist/runtime/agent-runtime.d.ts +14 -6
- package/dist/runtime/agent-runtime.js +359 -267
- 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 +2 -3
- package/dist/runtime/mcp-connection.js +3 -6
- 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 +8 -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 +40 -4
- package/dist/sdk/catalog.js.map +1 -1
- package/dist/sdk/guardrails/index.d.ts +5 -0
- package/dist/sdk/guardrails/index.js +15 -0
- package/dist/sdk/guardrails/index.js.map +1 -0
- package/dist/sdk/guardrails/patterns.d.ts +13 -0
- package/dist/sdk/guardrails/patterns.js +61 -0
- package/dist/sdk/guardrails/patterns.js.map +1 -0
- package/dist/sdk/guardrails/redactor.d.ts +24 -0
- package/dist/sdk/guardrails/redactor.js +86 -0
- package/dist/sdk/guardrails/redactor.js.map +1 -0
- package/dist/sdk/guardrails/streaming-redactor.d.ts +9 -0
- package/dist/sdk/guardrails/streaming-redactor.js +43 -0
- package/dist/sdk/guardrails/streaming-redactor.js.map +1 -0
- 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/guardrail.d.ts +1 -1
- 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/create-workspace.d.ts +4 -0
- package/dist/workspace/sandbox/create-workspace.js +68 -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 +45 -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
package/dist/sdk/tool.js
CHANGED
|
@@ -1,25 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Tool = void 0;
|
|
4
|
+
exports.getToolApprovalDisplayName = getToolApprovalDisplayName;
|
|
4
5
|
exports.wrapToolForApproval = wrapToolForApproval;
|
|
5
6
|
const zod_1 = require("zod");
|
|
6
7
|
const zod_2 = require("../utils/zod");
|
|
7
8
|
const APPROVAL_SUSPEND_SCHEMA = zod_1.z.object({
|
|
8
9
|
type: zod_1.z.literal('approval'),
|
|
9
10
|
toolName: zod_1.z.string(),
|
|
11
|
+
displayName: zod_1.z.string().optional(),
|
|
10
12
|
args: zod_1.z.unknown(),
|
|
11
13
|
});
|
|
12
14
|
const APPROVAL_RESUME_SCHEMA = zod_1.z.object({
|
|
13
15
|
approved: zod_1.z.boolean(),
|
|
14
16
|
});
|
|
17
|
+
function emitToolExecutionStart(tool, input, ctx) {
|
|
18
|
+
if (!ctx.toolCallId)
|
|
19
|
+
return;
|
|
20
|
+
ctx.emitEvent?.({
|
|
21
|
+
type: "tool_execution_start",
|
|
22
|
+
toolCallId: ctx.toolCallId,
|
|
23
|
+
toolName: tool.name,
|
|
24
|
+
args: input,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function getToolApprovalDisplayName(tool) {
|
|
28
|
+
const metadata = tool.metadata;
|
|
29
|
+
const displayName = metadata?.displayName ?? metadata?.workflowName;
|
|
30
|
+
return typeof displayName === 'string' && displayName.length > 0 ? displayName : undefined;
|
|
31
|
+
}
|
|
15
32
|
function wrapToolForApproval(tool, config) {
|
|
16
33
|
const originalHandler = tool.handler;
|
|
34
|
+
const hasConditionalApproval = config.needsApprovalFn !== undefined;
|
|
17
35
|
return {
|
|
18
36
|
...tool,
|
|
19
|
-
|
|
37
|
+
approval: {
|
|
38
|
+
required: config.requireApproval === true,
|
|
39
|
+
...(hasConditionalApproval ? { conditional: true } : {}),
|
|
40
|
+
},
|
|
20
41
|
suspendSchema: APPROVAL_SUSPEND_SCHEMA,
|
|
21
42
|
resumeSchema: APPROVAL_RESUME_SCHEMA,
|
|
22
|
-
|
|
43
|
+
async handler(input, ctx) {
|
|
44
|
+
const currentTool = this ?? tool;
|
|
23
45
|
const interruptCtx = ctx;
|
|
24
46
|
if (interruptCtx.resumeData === undefined) {
|
|
25
47
|
let needs = config.requireApproval ?? false;
|
|
@@ -27,19 +49,24 @@ function wrapToolForApproval(tool, config) {
|
|
|
27
49
|
needs = await config.needsApprovalFn(input);
|
|
28
50
|
}
|
|
29
51
|
if (needs) {
|
|
30
|
-
|
|
52
|
+
const displayName = getToolApprovalDisplayName(currentTool);
|
|
53
|
+
return await interruptCtx.suspend({
|
|
54
|
+
type: 'approval',
|
|
55
|
+
toolName: currentTool.name,
|
|
56
|
+
...(displayName ? { displayName } : {}),
|
|
57
|
+
args: input,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (hasConditionalApproval) {
|
|
61
|
+
emitToolExecutionStart(currentTool, input, interruptCtx);
|
|
31
62
|
}
|
|
32
|
-
return await originalHandler(input,
|
|
33
|
-
parentTelemetry: interruptCtx.parentTelemetry,
|
|
34
|
-
});
|
|
63
|
+
return await originalHandler(input, interruptCtx);
|
|
35
64
|
}
|
|
36
65
|
const { approved } = interruptCtx.resumeData;
|
|
37
66
|
if (!approved) {
|
|
38
|
-
return { declined: true, message: `Tool "${
|
|
67
|
+
return { declined: true, message: `Tool "${currentTool.name}" was not approved` };
|
|
39
68
|
}
|
|
40
|
-
return await originalHandler(input,
|
|
41
|
-
parentTelemetry: interruptCtx.parentTelemetry,
|
|
42
|
-
});
|
|
69
|
+
return await originalHandler(input, interruptCtx);
|
|
43
70
|
},
|
|
44
71
|
};
|
|
45
72
|
}
|
|
@@ -87,6 +114,10 @@ class Tool {
|
|
|
87
114
|
this.toModelOutputFn = fn;
|
|
88
115
|
return this;
|
|
89
116
|
}
|
|
117
|
+
handleCancellation() {
|
|
118
|
+
this.handleCancellationValue = true;
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
90
121
|
requireApproval() {
|
|
91
122
|
this.requireApprovalValue = true;
|
|
92
123
|
return this;
|
|
@@ -130,6 +161,7 @@ class Tool {
|
|
|
130
161
|
systemInstruction: this.systemInstructionText,
|
|
131
162
|
suspendSchema: this.suspendSchemaValue,
|
|
132
163
|
resumeSchema: this.resumeSchemaValue,
|
|
164
|
+
handleCancellation: this.handleCancellationValue,
|
|
133
165
|
toMessage: this.toMessageFn,
|
|
134
166
|
toModelOutput: this.toModelOutputFn,
|
|
135
167
|
handler: this.handlerFn,
|
package/dist/sdk/tool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/sdk/tool.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/sdk/tool.ts"],"names":[],"mappings":";;;AA4CA,gEAIC;AAYD,kDA4CC;AAvGD,6BAAwB;AAOxB,sCAA4D;AAE5D,MAAM,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,UAAU,CAAC;IAC3B,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;IACpB,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,IAAI,EAAE,OAAC,CAAC,OAAO,EAAE;CACjB,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IACvC,QAAQ,EAAE,OAAC,CAAC,OAAO,EAAE;CACrB,CAAC,CAAC;AAWH,SAAS,sBAAsB,CAC9B,IAAe,EACf,KAAc,EACd,GAA6B;IAE7B,IAAI,CAAC,GAAG,CAAC,UAAU;QAAE,OAAO;IAC5B,GAAG,CAAC,SAAS,EAAE,CAAC;QACf,IAAI,wBAA+B;QACnC,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,QAAQ,EAAE,IAAI,CAAC,IAAI;QACnB,IAAI,EAAE,KAAK;KACX,CAAC,CAAC;AACJ,CAAC;AAED,SAAgB,0BAA0B,CAAC,IAAe;IACzD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;IAC/B,MAAM,WAAW,GAAG,QAAQ,EAAE,WAAW,IAAI,QAAQ,EAAE,YAAY,CAAC;IACpE,OAAO,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC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EAAE,IAAI,CAAC,kBAAkB,KAAK,SAAS;YACjD,SAAS,EAAE,IAAI,CAAC,iBAAiB,KAAK,SAAS;YAC/C,YAAY,EAAE,IAAI,CAAC,WAAW,KAAK,SAAS;YAC5C,eAAe,EAAE,IAAI,CAAC,oBAAoB,IAAI,KAAK;YACnD,eAAe,EAAE,IAAI,CAAC,oBAAoB,IAAI,IAAI;SAClD,CAAC;IACH,CAAC;CACD;AAzPD,oBAyPC"}
|
|
@@ -18,37 +18,6 @@ export declare abstract class BaseMemory<TConstructorOptions extends JSONObject
|
|
|
18
18
|
messages: AgentDbMessage[];
|
|
19
19
|
}): Promise<void>;
|
|
20
20
|
deleteMessages(_messageIds: string[]): Promise<void>;
|
|
21
|
-
search?(_query: string, _opts?: {
|
|
22
|
-
scope?: 'thread' | 'resource';
|
|
23
|
-
threadId?: string;
|
|
24
|
-
resourceId?: string;
|
|
25
|
-
topK?: number;
|
|
26
|
-
messageRange?: {
|
|
27
|
-
before: number;
|
|
28
|
-
after: number;
|
|
29
|
-
};
|
|
30
|
-
}): Promise<AgentDbMessage[]>;
|
|
31
|
-
saveEmbeddings?(_opts: {
|
|
32
|
-
scope?: 'thread' | 'resource';
|
|
33
|
-
threadId?: string;
|
|
34
|
-
resourceId?: string;
|
|
35
|
-
entries: Array<{
|
|
36
|
-
id: string;
|
|
37
|
-
vector: number[];
|
|
38
|
-
text: string;
|
|
39
|
-
model: string;
|
|
40
|
-
}>;
|
|
41
|
-
}): Promise<void>;
|
|
42
|
-
queryEmbeddings?(_opts: {
|
|
43
|
-
scope?: 'thread' | 'resource';
|
|
44
|
-
threadId?: string;
|
|
45
|
-
resourceId?: string;
|
|
46
|
-
vector: number[];
|
|
47
|
-
topK: number;
|
|
48
|
-
}): Promise<Array<{
|
|
49
|
-
id: string;
|
|
50
|
-
score: number;
|
|
51
|
-
}>>;
|
|
52
21
|
close?(): Promise<void>;
|
|
53
22
|
describe(): MemoryDescriptor<TConstructorOptions>;
|
|
54
23
|
}
|
|
@@ -24,15 +24,6 @@ class BaseMemory {
|
|
|
24
24
|
deleteMessages(_messageIds) {
|
|
25
25
|
throw new Error('Method not implemented.');
|
|
26
26
|
}
|
|
27
|
-
search(_query, _opts) {
|
|
28
|
-
throw new Error('Method not implemented.');
|
|
29
|
-
}
|
|
30
|
-
saveEmbeddings(_opts) {
|
|
31
|
-
throw new Error('Method not implemented.');
|
|
32
|
-
}
|
|
33
|
-
queryEmbeddings(_opts) {
|
|
34
|
-
throw new Error('Method not implemented.');
|
|
35
|
-
}
|
|
36
27
|
close() {
|
|
37
28
|
throw new Error('Method not implemented.');
|
|
38
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-memory.js","sourceRoot":"","sources":["../../src/storage/base-memory.ts"],"names":[],"mappings":";;;AAKA,MAAsB,UAAU;IAG/B,YACoB,IAAY,EACZ,kBAAuC;QADvC,SAAI,GAAJ,IAAI,CAAQ;QACZ,uBAAkB,GAAlB,kBAAkB,CAAqB;IACxD,CAAC;IAEJ,SAAS,CAAC,SAAiB;QAC1B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IACD,UAAU,CAAC,OAAgD;QAC1D,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IACD,YAAY,CAAC,SAAiB;QAC7B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IACD,WAAW,CACV,SAAiB,EACjB,KAAyC;QAEzC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IACD,YAAY,CAAC,KAIZ;QACA,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IACD,cAAc,CAAC,WAAqB;QACnC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;
|
|
1
|
+
{"version":3,"file":"base-memory.js","sourceRoot":"","sources":["../../src/storage/base-memory.ts"],"names":[],"mappings":";;;AAKA,MAAsB,UAAU;IAG/B,YACoB,IAAY,EACZ,kBAAuC;QADvC,SAAI,GAAJ,IAAI,CAAQ;QACZ,uBAAkB,GAAlB,kBAAkB,CAAqB;IACxD,CAAC;IAEJ,SAAS,CAAC,SAAiB;QAC1B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IACD,UAAU,CAAC,OAAgD;QAC1D,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IACD,YAAY,CAAC,SAAiB;QAC7B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IACD,WAAW,CACV,SAAiB,EACjB,KAAyC;QAEzC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IACD,YAAY,CAAC,KAIZ;QACA,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IACD,cAAc,CAAC,WAAqB;QACnC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK;QACJ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IAED,QAAQ;QACP,OAAO;YACN,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YACtC,gBAAgB,EAAE,IAAI,CAAC,kBAAkB;SACzC,CAAC;IACH,CAAC;CACD;AA7CD,gCA6CC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export type { JSONValue, JSONObject, JSONArray } from './utils/json';
|
|
2
2
|
export type { MessageRole, MessageContent, ContentMetadata, ContentCitation, ContentText, ContentReasoning, ContentFile, ContentToolCall, ContentInvalidToolCall, ContentProvider, Message, AgentMessageBase, CustomAgentMessages, AgentMessage, AgentDbMessage, } from './sdk/message';
|
|
3
3
|
export type { Provider, AnthropicThinkingConfig, OpenAIThinkingConfig, GoogleThinkingConfig, XaiThinkingConfig, ThinkingConfigFor, ThinkingConfig, } from './sdk/provider';
|
|
4
|
-
export type { AgentResult, StreamChunk, FinishReason, TokenUsage, ModelConfig, RunOptions, ExecutionOptions, AgentExecutionCounter, PersistedExecutionOptions, ResumeOptions, GenerateResult, StreamResult,
|
|
4
|
+
export type { AgentResult, StreamChunk, FinishReason, TokenUsage, ModelConfig, RunOptions, ExecutionOptions, SmoothStreamOptions, AgentExecutionCounter, PersistedExecutionOptions, ResumeOptions, GenerateResult, StreamResult, BuiltAgent, AgentRunState, AgentResumeData, PendingToolCall, SerializableAgentState, } from './sdk/agent';
|
|
5
5
|
export type { SerializedMessageList } from './runtime/message-list';
|
|
6
6
|
export type { ToolContext, ToolExecutionContext, InterruptibleToolContext, BuiltTool, BuiltProviderTool, } from './sdk/tool';
|
|
7
|
-
export type { Thread, BuiltMemory, BuiltEpisodicMemoryStore, EpisodicMemoryConfig, EpisodicMemoryCursor, EpisodicMemoryEmbeddingProviderOptions, EpisodicMemoryEntry, EpisodicMemoryEntrySource, EpisodicMemoryExtractFn, EpisodicMemoryExtraction, EpisodicMemoryExtractionCandidate, EpisodicMemoryExtractorInput, EpisodicMemoryMethods, EpisodicMemoryPrompts, EpisodicMemoryReflectFn, EpisodicMemoryReflection, EpisodicMemoryReflectionApply, EpisodicMemoryReflectionApplyMerge, EpisodicMemoryReflectionMerge, EpisodicMemoryReflectionResult, EpisodicMemoryReflectorInput, EpisodicMemoryScope, EpisodicMemorySearchOptions, EpisodicMemoryStatus, EpisodicMemoryTaskLockHandle, EpisodicMemoryTaskLockMethods, NewEpisodicMemoryCursor, NewEpisodicMemoryEntry, NewEpisodicMemoryEntrySource, NewEpisodicMemoryEntrySourceForEntry, RetrievedEpisodicMemoryEntry, ObservationCapableMemory, MemoryDescriptor,
|
|
7
|
+
export type { Thread, BuiltMemory, BuiltEpisodicMemoryStore, EpisodicMemoryConfig, EpisodicMemoryCursor, EpisodicMemoryEmbeddingProviderOptions, EpisodicMemoryEntry, EpisodicMemoryEntrySource, EpisodicMemoryExtractFn, EpisodicMemoryExtraction, EpisodicMemoryExtractionCandidate, EpisodicMemoryExtractorInput, EpisodicMemoryMethods, EpisodicMemoryPrompts, EpisodicMemoryReflectFn, EpisodicMemoryReflection, EpisodicMemoryReflectionApply, EpisodicMemoryReflectionApplyMerge, EpisodicMemoryReflectionMerge, EpisodicMemoryReflectionResult, EpisodicMemoryReflectorInput, EpisodicMemoryScope, EpisodicMemorySearchOptions, EpisodicMemoryStatus, EpisodicMemoryTaskLockHandle, EpisodicMemoryTaskLockMethods, NewEpisodicMemoryCursor, NewEpisodicMemoryEntry, NewEpisodicMemoryEntrySource, NewEpisodicMemoryEntrySourceForEntry, RetrievedEpisodicMemoryEntry, ObservationCapableMemory, MemoryDescriptor, MemoryConfig, ObservationLogMemoryConfig, ObservationalMemoryConfig, CheckpointStore, TitleGenerationConfig, } from './sdk/memory';
|
|
8
8
|
export type { ObservationCursor } from './sdk/observation';
|
|
9
9
|
export type { BuiltObservationLogStore, BuiltObservationLogTaskLockStore, NewObservationLogEntry, ObservationLogEntry, ObservationLogMarker, ObservationLogMerge, ObservationLogObserveFn, ObservationLogObserverInput, ObservationLogReadOptions, ObservationLogReflectFn, ObservationLogReflectorInput, ObservationLogReflection, ObservationLogReflectionResult, ObservationLogScope, ObservationLogStatus, ObservationLogTaskKind, ObservationLogTaskLockHandle, TokenCounter, } from './sdk/observation-log';
|
|
10
10
|
export { estimateObservationTokens, OBSERVATION_LOG_MARKERS, OBSERVATION_LOG_STATUSES, } from './sdk/observation-log';
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AA4HA,yDAI+B;AAH9B,4HAAA,yBAAyB,OAAA;AACzB,0HAAA,uBAAuB,OAAA;AACvB,2HAAA,wBAAwB,OAAA;AA6BzB,yCAA6C;AAApC,mGAAA,UAAU,OAAA"}
|
|
@@ -1,4 +1,28 @@
|
|
|
1
|
+
import type { FinishReason, TokenUsage } from '../sdk/agent';
|
|
1
2
|
import type { AgentMessage, ContentToolCall } from '../sdk/message';
|
|
3
|
+
export type SubAgentLifecycleUsage = Pick<TokenUsage, 'promptTokens' | 'completionTokens' | 'totalTokens' | 'cost'>;
|
|
4
|
+
export interface SubAgentLifecycleBase {
|
|
5
|
+
taskName: string;
|
|
6
|
+
taskPath: string;
|
|
7
|
+
parentRunId?: string;
|
|
8
|
+
parentToolCallId?: string;
|
|
9
|
+
subAgentId?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SubAgentStartedPayload extends SubAgentLifecycleBase {
|
|
12
|
+
startedAt: number;
|
|
13
|
+
}
|
|
14
|
+
export interface SubAgentCompletedPayload extends SubAgentLifecycleBase {
|
|
15
|
+
status: 'completed' | 'failed' | 'suspended';
|
|
16
|
+
startedAt: number;
|
|
17
|
+
finishedAt: number;
|
|
18
|
+
durationMs: number;
|
|
19
|
+
runId?: string;
|
|
20
|
+
threadId?: string;
|
|
21
|
+
model?: string;
|
|
22
|
+
usage?: SubAgentLifecycleUsage;
|
|
23
|
+
finishReason?: FinishReason;
|
|
24
|
+
error?: string;
|
|
25
|
+
}
|
|
2
26
|
export declare const enum AgentEvent {
|
|
3
27
|
AgentStart = "agent_start",
|
|
4
28
|
AgentEnd = "agent_end",
|
|
@@ -6,6 +30,8 @@ export declare const enum AgentEvent {
|
|
|
6
30
|
TurnEnd = "turn_end",
|
|
7
31
|
ToolExecutionStart = "tool_execution_start",
|
|
8
32
|
ToolExecutionEnd = "tool_execution_end",
|
|
33
|
+
SubAgentStarted = "subagent_started",
|
|
34
|
+
SubAgentCompleted = "subagent_completed",
|
|
9
35
|
Error = "error"
|
|
10
36
|
}
|
|
11
37
|
export type AgentEventData = {
|
|
@@ -30,7 +56,11 @@ export type AgentEventData = {
|
|
|
30
56
|
toolName: string;
|
|
31
57
|
result: unknown;
|
|
32
58
|
isError: boolean;
|
|
33
|
-
} | {
|
|
59
|
+
} | ({
|
|
60
|
+
type: AgentEvent.SubAgentStarted;
|
|
61
|
+
} & SubAgentStartedPayload) | ({
|
|
62
|
+
type: AgentEvent.SubAgentCompleted;
|
|
63
|
+
} & SubAgentCompletedPayload) | {
|
|
34
64
|
type: AgentEvent.Error;
|
|
35
65
|
message: string;
|
|
36
66
|
error: unknown;
|
|
@@ -9,6 +9,8 @@ var AgentEvent;
|
|
|
9
9
|
AgentEvent["TurnEnd"] = "turn_end";
|
|
10
10
|
AgentEvent["ToolExecutionStart"] = "tool_execution_start";
|
|
11
11
|
AgentEvent["ToolExecutionEnd"] = "tool_execution_end";
|
|
12
|
+
AgentEvent["SubAgentStarted"] = "subagent_started";
|
|
13
|
+
AgentEvent["SubAgentCompleted"] = "subagent_completed";
|
|
12
14
|
AgentEvent["Error"] = "error";
|
|
13
15
|
})(AgentEvent || (exports.AgentEvent = AgentEvent = {}));
|
|
14
16
|
//# sourceMappingURL=event.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../../src/types/runtime/event.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../../src/types/runtime/event.ts"],"names":[],"mappings":";;;AAmCA,IAAkB,UAUjB;AAVD,WAAkB,UAAU;IAC3B,wCAA0B,CAAA;IAC1B,oCAAsB,CAAA;IACtB,sCAAwB,CAAA;IACxB,kCAAoB,CAAA;IACpB,yDAA2C,CAAA;IAC3C,qDAAuC,CAAA;IACvC,kDAAoC,CAAA;IACpC,sDAAwC,CAAA;IACxC,6BAAe,CAAA;AAChB,CAAC,EAViB,UAAU,0BAAV,UAAU,QAU3B"}
|
|
@@ -17,7 +17,6 @@ export interface AgentBuilder {
|
|
|
17
17
|
providerTool(t: BuiltProviderTool): this;
|
|
18
18
|
thinking(provider: string, config?: Record<string, unknown>): this;
|
|
19
19
|
toolCallConcurrency(n: number): this;
|
|
20
|
-
requireToolApproval(): this;
|
|
21
20
|
memory(m: unknown): this;
|
|
22
21
|
checkpoint(storage: 'memory' | CheckpointStore): this;
|
|
23
22
|
inputGuardrail(g: BuiltGuardrail): this;
|
|
@@ -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>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type GuardrailType = 'pii' | 'prompt-injection' | 'moderation' | 'custom';
|
|
2
2
|
export type GuardrailStrategy = 'block' | 'redact' | 'warn';
|
|
3
|
-
export type PiiDetectionType = 'email' | 'phone' | 'credit-card' | 'ssn' | 'address';
|
|
3
|
+
export type PiiDetectionType = 'email' | 'phone' | 'credit-card' | 'ssn-us' | 'address';
|
|
4
4
|
export interface BuiltGuardrail {
|
|
5
5
|
readonly name: string;
|
|
6
6
|
readonly guardType: 'pii' | 'prompt-injection' | 'moderation' | 'custom';
|
|
@@ -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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oB,KAAK,IAAI,EAAE,CAAC;QAC7F,MAAM,CAAC,oBAAoB,GAAG,cAAc,CAAC,MAAM,CAAC,oBAAoB,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
|
+
}
|