@finalai/agent-provider 0.1.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.
Potentially problematic release.
This version of @finalai/agent-provider might be problematic. Click here for more details.
- package/README.md +12 -0
- package/dist/modules/channel-context.d.mts +102 -0
- package/dist/modules/channel-context.mjs +52 -0
- package/dist/modules/channel-context.mjs.map +7 -0
- package/dist/modules/channel-socket.d.mts +65 -0
- package/dist/modules/channel-socket.mjs +188 -0
- package/dist/modules/channel-socket.mjs.map +7 -0
- package/dist/modules/channel.d.mts +382 -0
- package/dist/modules/channel.mjs +146 -0
- package/dist/modules/channel.mjs.map +7 -0
- package/dist/modules/conformance/agent.d.mts +20 -0
- package/dist/modules/conformance/agent.mjs +623 -0
- package/dist/modules/conformance/agent.mjs.map +7 -0
- package/dist/modules/conformance/fixtures.d.mts +41 -0
- package/dist/modules/conformance/fixtures.mjs +190 -0
- package/dist/modules/conformance/fixtures.mjs.map +7 -0
- package/dist/modules/conformance/harness-kit.d.mts +82 -0
- package/dist/modules/conformance/harness-kit.mjs +1303 -0
- package/dist/modules/conformance/harness-kit.mjs.map +7 -0
- package/dist/modules/conformance/image.d.mts +2 -0
- package/dist/modules/conformance/image.mjs +79 -0
- package/dist/modules/conformance/image.mjs.map +7 -0
- package/dist/modules/conformance/index.d.mts +8 -0
- package/dist/modules/conformance/index.mjs +12 -0
- package/dist/modules/conformance/index.mjs.map +7 -0
- package/dist/modules/conformance/local-harness.d.mts +25 -0
- package/dist/modules/conformance/local-harness.mjs +108 -0
- package/dist/modules/conformance/local-harness.mjs.map +7 -0
- package/dist/modules/conformance/protocol.d.mts +30 -0
- package/dist/modules/conformance/protocol.mjs +56 -0
- package/dist/modules/conformance/protocol.mjs.map +7 -0
- package/dist/modules/conformance/sandbox-kit.d.mts +19 -0
- package/dist/modules/conformance/sandbox-kit.mjs +320 -0
- package/dist/modules/conformance/sandbox-kit.mjs.map +7 -0
- package/dist/modules/conformance/scripted-model/chat-completions.d.mts +30 -0
- package/dist/modules/conformance/scripted-model/chat-completions.mjs +125 -0
- package/dist/modules/conformance/scripted-model/chat-completions.mjs.map +7 -0
- package/dist/modules/conformance/scripted-model/directives.d.mts +84 -0
- package/dist/modules/conformance/scripted-model/directives.mjs +304 -0
- package/dist/modules/conformance/scripted-model/directives.mjs.map +7 -0
- package/dist/modules/conformance/scripted-model/handler.d.mts +14 -0
- package/dist/modules/conformance/scripted-model/handler.mjs +133 -0
- package/dist/modules/conformance/scripted-model/handler.mjs.map +7 -0
- package/dist/modules/conformance/scripted-model/index.d.mts +6 -0
- package/dist/modules/conformance/scripted-model/index.mjs +7 -0
- package/dist/modules/conformance/scripted-model/index.mjs.map +7 -0
- package/dist/modules/conformance/scripted-model/messages.d.mts +39 -0
- package/dist/modules/conformance/scripted-model/messages.mjs +139 -0
- package/dist/modules/conformance/scripted-model/messages.mjs.map +7 -0
- package/dist/modules/conformance/scripted-model/responses.d.mts +62 -0
- package/dist/modules/conformance/scripted-model/responses.mjs +273 -0
- package/dist/modules/conformance/scripted-model/responses.mjs.map +7 -0
- package/dist/modules/conformance/scripted-model/sse.d.mts +15 -0
- package/dist/modules/conformance/scripted-model/sse.mjs +75 -0
- package/dist/modules/conformance/scripted-model/sse.mjs.map +7 -0
- package/dist/modules/conformance/v1-agent.d.mts +24 -0
- package/dist/modules/conformance/v1-agent.mjs +40 -0
- package/dist/modules/conformance/v1-agent.mjs.map +7 -0
- package/dist/modules/credential-routes.d.mts +24 -0
- package/dist/modules/credential-routes.mjs +25 -0
- package/dist/modules/credential-routes.mjs.map +7 -0
- package/dist/modules/credentials.d.mts +206 -0
- package/dist/modules/credentials.mjs +207 -0
- package/dist/modules/credentials.mjs.map +7 -0
- package/dist/modules/dynamic.d.mts +32 -0
- package/dist/modules/dynamic.mjs +77 -0
- package/dist/modules/dynamic.mjs.map +7 -0
- package/dist/modules/harness.d.mts +397 -0
- package/dist/modules/harness.mjs +213 -0
- package/dist/modules/harness.mjs.map +7 -0
- package/dist/modules/index.d.mts +15 -0
- package/dist/modules/index.mjs +40 -0
- package/dist/modules/index.mjs.map +7 -0
- package/dist/modules/json.d.mts +12 -0
- package/dist/modules/json.mjs +19 -0
- package/dist/modules/json.mjs.map +7 -0
- package/dist/modules/local-channel-socket.d.mts +23 -0
- package/dist/modules/local-channel-socket.mjs +141 -0
- package/dist/modules/local-channel-socket.mjs.map +7 -0
- package/dist/modules/manifest.d.mts +558 -0
- package/dist/modules/manifest.mjs +266 -0
- package/dist/modules/manifest.mjs.map +7 -0
- package/dist/modules/mcp-content.d.mts +21 -0
- package/dist/modules/mcp-content.mjs +86 -0
- package/dist/modules/mcp-content.mjs.map +7 -0
- package/dist/modules/provider-ref.d.mts +29 -0
- package/dist/modules/provider-ref.mjs +55 -0
- package/dist/modules/provider-ref.mjs.map +7 -0
- package/dist/modules/sandbox/bytes.d.mts +9 -0
- package/dist/modules/sandbox/bytes.mjs +154 -0
- package/dist/modules/sandbox/bytes.mjs.map +7 -0
- package/dist/modules/sandbox/client.d.mts +51 -0
- package/dist/modules/sandbox/client.mjs +500 -0
- package/dist/modules/sandbox/client.mjs.map +7 -0
- package/dist/modules/sandbox/confined-files.d.mts +22 -0
- package/dist/modules/sandbox/confined-files.mjs +142 -0
- package/dist/modules/sandbox/confined-files.mjs.map +7 -0
- package/dist/modules/sandbox/convenience.d.mts +10 -0
- package/dist/modules/sandbox/convenience.mjs +116 -0
- package/dist/modules/sandbox/convenience.mjs.map +7 -0
- package/dist/modules/sandbox/editor.d.mts +49 -0
- package/dist/modules/sandbox/editor.mjs +43 -0
- package/dist/modules/sandbox/editor.mjs.map +7 -0
- package/dist/modules/sandbox/frame-channel.d.mts +47 -0
- package/dist/modules/sandbox/frame-channel.mjs +153 -0
- package/dist/modules/sandbox/frame-channel.mjs.map +7 -0
- package/dist/modules/sandbox/index.d.mts +18 -0
- package/dist/modules/sandbox/index.mjs +70 -0
- package/dist/modules/sandbox/index.mjs.map +7 -0
- package/dist/modules/sandbox/mcp-channel.d.mts +9 -0
- package/dist/modules/sandbox/mcp-channel.mjs +77 -0
- package/dist/modules/sandbox/mcp-channel.mjs.map +7 -0
- package/dist/modules/sandbox/mcp-hosted.d.mts +46 -0
- package/dist/modules/sandbox/mcp-hosted.mjs +221 -0
- package/dist/modules/sandbox/mcp-hosted.mjs.map +7 -0
- package/dist/modules/sandbox/mcp-search.d.mts +51 -0
- package/dist/modules/sandbox/mcp-search.mjs +129 -0
- package/dist/modules/sandbox/mcp-search.mjs.map +7 -0
- package/dist/modules/sandbox/mcp-shell.d.mts +21 -0
- package/dist/modules/sandbox/mcp-shell.mjs +205 -0
- package/dist/modules/sandbox/mcp-shell.mjs.map +7 -0
- package/dist/modules/sandbox/mcp-testing.d.mts +11 -0
- package/dist/modules/sandbox/mcp-testing.mjs +33 -0
- package/dist/modules/sandbox/mcp-testing.mjs.map +7 -0
- package/dist/modules/sandbox/mcp.d.mts +83 -0
- package/dist/modules/sandbox/mcp.mjs +971 -0
- package/dist/modules/sandbox/mcp.mjs.map +7 -0
- package/dist/modules/sandbox/memory-sandbox.d.mts +32 -0
- package/dist/modules/sandbox/memory-sandbox.mjs +416 -0
- package/dist/modules/sandbox/memory-sandbox.mjs.map +7 -0
- package/dist/modules/sandbox/memory-shell.d.mts +29 -0
- package/dist/modules/sandbox/memory-shell.mjs +278 -0
- package/dist/modules/sandbox/memory-shell.mjs.map +7 -0
- package/dist/modules/sandbox/open-scope-node.d.mts +4 -0
- package/dist/modules/sandbox/open-scope-node.mjs +19 -0
- package/dist/modules/sandbox/open-scope-node.mjs.map +7 -0
- package/dist/modules/sandbox/open-scope.d.mts +16 -0
- package/dist/modules/sandbox/open-scope.mjs +66 -0
- package/dist/modules/sandbox/open-scope.mjs.map +7 -0
- package/dist/modules/sandbox/paths.d.mts +7 -0
- package/dist/modules/sandbox/paths.mjs +50 -0
- package/dist/modules/sandbox/paths.mjs.map +7 -0
- package/dist/modules/sandbox/rpc-peer.d.mts +35 -0
- package/dist/modules/sandbox/rpc-peer.mjs +224 -0
- package/dist/modules/sandbox/rpc-peer.mjs.map +7 -0
- package/dist/modules/sandbox/seeds.d.mts +26 -0
- package/dist/modules/sandbox/seeds.mjs +228 -0
- package/dist/modules/sandbox/seeds.mjs.map +7 -0
- package/dist/modules/sandbox/server.d.mts +66 -0
- package/dist/modules/sandbox/server.mjs +567 -0
- package/dist/modules/sandbox/server.mjs.map +7 -0
- package/dist/modules/sandbox/snapshots.d.mts +49 -0
- package/dist/modules/sandbox/snapshots.mjs +55 -0
- package/dist/modules/sandbox/snapshots.mjs.map +7 -0
- package/dist/modules/sandbox/stream-mux.d.mts +18 -0
- package/dist/modules/sandbox/stream-mux.mjs +285 -0
- package/dist/modules/sandbox/stream-mux.mjs.map +7 -0
- package/dist/modules/sandbox/testing.d.mts +25 -0
- package/dist/modules/sandbox/testing.mjs +64 -0
- package/dist/modules/sandbox/testing.mjs.map +7 -0
- package/dist/modules/sandbox/types.d.mts +352 -0
- package/dist/modules/sandbox/types.mjs +86 -0
- package/dist/modules/sandbox/types.mjs.map +7 -0
- package/dist/modules/sandbox/wire.d.mts +671 -0
- package/dist/modules/sandbox/wire.mjs +537 -0
- package/dist/modules/sandbox/wire.mjs.map +7 -0
- package/dist/modules/sandbox/workspace-root.d.mts +8 -0
- package/dist/modules/sandbox/workspace-root.mjs +79 -0
- package/dist/modules/sandbox/workspace-root.mjs.map +7 -0
- package/dist/modules/schemas.d.mts +121 -0
- package/dist/modules/schemas.mjs +146 -0
- package/dist/modules/schemas.mjs.map +7 -0
- package/dist/modules/semantic-events.d.mts +31 -0
- package/dist/modules/semantic-events.mjs +23 -0
- package/dist/modules/semantic-events.mjs.map +7 -0
- package/package.json +199 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
connectSandboxClient
|
|
3
|
+
} from "./client.mjs";
|
|
4
|
+
import {
|
|
5
|
+
createHandleRpcMessageHandler,
|
|
6
|
+
serveSandboxHandle
|
|
7
|
+
} from "./server.mjs";
|
|
8
|
+
import { createFrameChannelPair } from "./wire.mjs";
|
|
9
|
+
const allowAllTokens = async () => ({ expiresAt: null });
|
|
10
|
+
const createInMemoryHandleNetwork = () => {
|
|
11
|
+
const endpoints = /* @__PURE__ */ new Map();
|
|
12
|
+
const open = /* @__PURE__ */ new Set();
|
|
13
|
+
const dialLog = [];
|
|
14
|
+
const network = {
|
|
15
|
+
serve: (args) => {
|
|
16
|
+
const server = serveSandboxHandle({
|
|
17
|
+
sandbox: args.sandbox,
|
|
18
|
+
handle: args.handle,
|
|
19
|
+
authorize: args.authorize ?? allowAllTokens,
|
|
20
|
+
access: args.access,
|
|
21
|
+
binary: args.binary,
|
|
22
|
+
mcpChannels: args.mcpChannels
|
|
23
|
+
});
|
|
24
|
+
endpoints.set(args.url, (channel, token) => {
|
|
25
|
+
server.attach(channel, { token });
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
mount: (url, options) => {
|
|
29
|
+
endpoints.set(url, (channel, token) => {
|
|
30
|
+
const handler = createHandleRpcMessageHandler({
|
|
31
|
+
...options,
|
|
32
|
+
connectionToken: token,
|
|
33
|
+
send: (frame) => channel.send(frame),
|
|
34
|
+
close: (code, reason) => channel.close(code, reason)
|
|
35
|
+
});
|
|
36
|
+
channel.listen({
|
|
37
|
+
frame: (frame) => handler.onFrame(frame),
|
|
38
|
+
close: (info) => handler.onClose(info.code, info.reason)
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
openChannel: async (target) => {
|
|
43
|
+
dialLog.push(target.url);
|
|
44
|
+
const endpoint = endpoints.get(target.url);
|
|
45
|
+
if (endpoint == null) throw new Error(`nothing listens at ${target.url}`);
|
|
46
|
+
const [client, server] = createFrameChannelPair();
|
|
47
|
+
open.add(client);
|
|
48
|
+
endpoint(server, target.token);
|
|
49
|
+
return client;
|
|
50
|
+
},
|
|
51
|
+
connect: (args) => connectSandboxClient({ ...args, openChannel: network.openChannel }),
|
|
52
|
+
dropAll: () => {
|
|
53
|
+
for (const channel of open) channel.close(1006, "network drop");
|
|
54
|
+
open.clear();
|
|
55
|
+
},
|
|
56
|
+
dials: () => [...dialLog]
|
|
57
|
+
};
|
|
58
|
+
return network;
|
|
59
|
+
};
|
|
60
|
+
export {
|
|
61
|
+
allowAllTokens,
|
|
62
|
+
createInMemoryHandleNetwork
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=testing.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/sandbox/testing.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n connectSandboxClient,\n type ConnectSandboxClientArgsIface,\n type SandboxClientIface,\n} from \"./client.mjs\";\nimport {\n createHandleRpcMessageHandler,\n serveSandboxHandle,\n type HandleAccessPolicyIface,\n type HandleAuthorizeFn,\n type HandleLifecycle,\n type HandleRpcMessageHandlerOptionsIface,\n} from \"./server.mjs\";\nimport type { NetworkSandboxSessionIface } from \"./types.mjs\";\nimport { createFrameChannelPair, type FrameChannelIface } from \"./wire.mjs\";\n\n// In-memory hosting for the handle RPC: routes dial URLs to in-process\n// endpoints over frame channel pairs. Used by tests and the conformance kit.\n\nexport interface InMemoryHandleNetworkIface {\n // Serves `sandbox` at `url`.\n serve(args: {\n url: string;\n sandbox: NetworkSandboxSessionIface;\n handle?: HandleLifecycle;\n authorize?: HandleAuthorizeFn;\n access?: HandleAccessPolicyIface;\n binary?: boolean;\n mcpChannels?: boolean;\n }): void;\n // Mounts a raw message handler at `url` (a stable endpoint that starts the\n // sandbox on the first connection).\n mount(\n url: string,\n options: Omit<HandleRpcMessageHandlerOptionsIface, 'send' | 'close' | 'connectionToken'>,\n ): void;\n openChannel(target: { url: string; token: string }): Promise<FrameChannelIface>;\n connect(args: Omit<ConnectSandboxClientArgsIface, 'openChannel'>): Promise<SandboxClientIface>;\n // Closes every connection the network opened (simulates a network drop).\n dropAll(): void;\n dials(): string[];\n}\n\nexport const allowAllTokens: HandleAuthorizeFn = async () => ({ expiresAt: null });\n\nexport const createInMemoryHandleNetwork = (): InMemoryHandleNetworkIface => {\n const endpoints = new Map<string, (channel: FrameChannelIface, token: string) => void>();\n const open = new Set<FrameChannelIface>();\n const dialLog: string[] = [];\n const network: InMemoryHandleNetworkIface = {\n serve: (args) => {\n const server = serveSandboxHandle({\n sandbox: args.sandbox,\n handle: args.handle,\n authorize: args.authorize ?? allowAllTokens,\n access: args.access,\n binary: args.binary,\n mcpChannels: args.mcpChannels,\n });\n endpoints.set(args.url, (channel, token) => {\n server.attach(channel, { token });\n });\n },\n mount: (url, options) => {\n endpoints.set(url, (channel, token) => {\n const handler = createHandleRpcMessageHandler({\n ...options,\n connectionToken: token,\n send: (frame) => channel.send(frame),\n close: (code, reason) => channel.close(code, reason),\n });\n channel.listen({\n frame: (frame) => handler.onFrame(frame),\n close: (info) => handler.onClose(info.code, info.reason),\n });\n });\n },\n openChannel: async (target) => {\n dialLog.push(target.url);\n const endpoint = endpoints.get(target.url);\n if (endpoint == null) throw new Error(`nothing listens at ${target.url}`);\n const [client, server] = createFrameChannelPair();\n open.add(client);\n endpoint(server, target.token);\n return client;\n },\n connect: (args) => connectSandboxClient({ ...args, openChannel: network.openChannel }),\n dropAll: () => {\n for (const channel of open) channel.close(1006, 'network drop');\n open.clear();\n },\n dials: () => [...dialLog],\n };\n return network;\n};\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AAEP,SAAS,8BAAsD;AA6BxD,MAAM,iBAAoC,aAAa,EAAE,WAAW,KAAK;AAEzE,MAAM,8BAA8B,MAAkC;AAC3E,QAAM,YAAY,oBAAI,IAAiE;AACvF,QAAM,OAAO,oBAAI,IAAuB;AACxC,QAAM,UAAoB,CAAC;AAC3B,QAAM,UAAsC;AAAA,IAC1C,OAAO,CAAC,SAAS;AACf,YAAM,SAAS,mBAAmB;AAAA,QAChC,SAAS,KAAK;AAAA,QACd,QAAQ,KAAK;AAAA,QACb,WAAW,KAAK,aAAa;AAAA,QAC7B,QAAQ,KAAK;AAAA,QACb,QAAQ,KAAK;AAAA,QACb,aAAa,KAAK;AAAA,MACpB,CAAC;AACD,gBAAU,IAAI,KAAK,KAAK,CAAC,SAAS,UAAU;AAC1C,eAAO,OAAO,SAAS,EAAE,MAAM,CAAC;AAAA,MAClC,CAAC;AAAA,IACH;AAAA,IACA,OAAO,CAAC,KAAK,YAAY;AACvB,gBAAU,IAAI,KAAK,CAAC,SAAS,UAAU;AACrC,cAAM,UAAU,8BAA8B;AAAA,UAC5C,GAAG;AAAA,UACH,iBAAiB;AAAA,UACjB,MAAM,CAAC,UAAU,QAAQ,KAAK,KAAK;AAAA,UACnC,OAAO,CAAC,MAAM,WAAW,QAAQ,MAAM,MAAM,MAAM;AAAA,QACrD,CAAC;AACD,gBAAQ,OAAO;AAAA,UACb,OAAO,CAAC,UAAU,QAAQ,QAAQ,KAAK;AAAA,UACvC,OAAO,CAAC,SAAS,QAAQ,QAAQ,KAAK,MAAM,KAAK,MAAM;AAAA,QACzD,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,IACA,aAAa,OAAO,WAAW;AAC7B,cAAQ,KAAK,OAAO,GAAG;AACvB,YAAM,WAAW,UAAU,IAAI,OAAO,GAAG;AACzC,UAAI,YAAY,KAAM,OAAM,IAAI,MAAM,sBAAsB,OAAO,GAAG,EAAE;AACxE,YAAM,CAAC,QAAQ,MAAM,IAAI,uBAAuB;AAChD,WAAK,IAAI,MAAM;AACf,eAAS,QAAQ,OAAO,KAAK;AAC7B,aAAO;AAAA,IACT;AAAA,IACA,SAAS,CAAC,SAAS,qBAAqB,EAAE,GAAG,MAAM,aAAa,QAAQ,YAAY,CAAC;AAAA,IACrF,SAAS,MAAM;AACb,iBAAW,WAAW,KAAM,SAAQ,MAAM,MAAM,cAAc;AAC9D,WAAK,MAAM;AAAA,IACb;AAAA,IACA,OAAO,MAAM,CAAC,GAAG,OAAO;AAAA,EAC1B;AACA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import type { ProcessInspectionRequestIface, ProcessInspectionResultIface } from '@finalai/agent-protocol/process-inspection';
|
|
2
|
+
import type { JsonValue } from "../json.mjs";
|
|
3
|
+
import type { ToolDescriptorIface } from "../manifest.mjs";
|
|
4
|
+
import type { SandboxEditorRequestIface, SandboxEditorResultIface } from "./editor.mjs";
|
|
5
|
+
import { type AwaitableSandboxOpenRequestIface } from "./open-scope.mjs";
|
|
6
|
+
import type { SandboxSnapshotRequestIface, SandboxSnapshotResponseIface } from "./snapshots.mjs";
|
|
7
|
+
export interface AbortableIface {
|
|
8
|
+
abortSignal?: AbortSignal;
|
|
9
|
+
}
|
|
10
|
+
export interface SandboxProcessOptionsIface extends AbortableIface {
|
|
11
|
+
command: string;
|
|
12
|
+
args?: string[];
|
|
13
|
+
cwd?: string;
|
|
14
|
+
env?: Record<string, string>;
|
|
15
|
+
shell?: boolean;
|
|
16
|
+
stdin?: ReadableStream<Uint8Array> | string;
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface SandboxProcessIface {
|
|
20
|
+
readonly pid: string | null;
|
|
21
|
+
readonly stdout: ReadableStream<Uint8Array>;
|
|
22
|
+
readonly stderr: ReadableStream<Uint8Array>;
|
|
23
|
+
write(data: Uint8Array | string, options?: {
|
|
24
|
+
end?: boolean;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
wait(): Promise<{
|
|
27
|
+
exitCode: number;
|
|
28
|
+
}>;
|
|
29
|
+
kill(signal?: string): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export interface SandboxRunResultIface {
|
|
32
|
+
exitCode: number;
|
|
33
|
+
stdout: string;
|
|
34
|
+
stderr: string;
|
|
35
|
+
}
|
|
36
|
+
export declare enum SandboxEntryType {
|
|
37
|
+
File = "file",
|
|
38
|
+
Directory = "directory",
|
|
39
|
+
Symlink = "symlink",
|
|
40
|
+
Other = "other"
|
|
41
|
+
}
|
|
42
|
+
export interface StatIface {
|
|
43
|
+
path: string;
|
|
44
|
+
type: SandboxEntryType;
|
|
45
|
+
size: number;
|
|
46
|
+
modifiedAt: string | null;
|
|
47
|
+
mode: number | null;
|
|
48
|
+
}
|
|
49
|
+
export interface DirEntryIface {
|
|
50
|
+
name: string;
|
|
51
|
+
path: string;
|
|
52
|
+
type: SandboxEntryType;
|
|
53
|
+
size: number | null;
|
|
54
|
+
}
|
|
55
|
+
export interface ConfinedSandboxFilesIface {
|
|
56
|
+
readFile(options: {
|
|
57
|
+
path: string;
|
|
58
|
+
root: string;
|
|
59
|
+
} & AbortableIface): Promise<ReadableStream<Uint8Array> | null>;
|
|
60
|
+
stat(options: {
|
|
61
|
+
path: string;
|
|
62
|
+
root: string;
|
|
63
|
+
} & AbortableIface): Promise<StatIface | null>;
|
|
64
|
+
readDir(options: {
|
|
65
|
+
path: string;
|
|
66
|
+
root: string;
|
|
67
|
+
} & AbortableIface): Promise<DirEntryIface[] | null>;
|
|
68
|
+
}
|
|
69
|
+
export interface SandboxSessionIface {
|
|
70
|
+
readonly description: string;
|
|
71
|
+
readonly confinedFileReader?: ConfinedSandboxFilesIface;
|
|
72
|
+
readFile(options: {
|
|
73
|
+
path: string;
|
|
74
|
+
root?: string;
|
|
75
|
+
} & AbortableIface): Promise<ReadableStream<Uint8Array> | null>;
|
|
76
|
+
readBinaryFile(options: {
|
|
77
|
+
path: string;
|
|
78
|
+
} & AbortableIface): Promise<Uint8Array | null>;
|
|
79
|
+
readTextFile(options: {
|
|
80
|
+
path: string;
|
|
81
|
+
encoding?: string;
|
|
82
|
+
startLine?: number;
|
|
83
|
+
endLine?: number;
|
|
84
|
+
} & AbortableIface): Promise<string | null>;
|
|
85
|
+
writeFile(options: {
|
|
86
|
+
path: string;
|
|
87
|
+
content: ReadableStream<Uint8Array>;
|
|
88
|
+
} & AbortableIface): Promise<void>;
|
|
89
|
+
writeBinaryFile(options: {
|
|
90
|
+
path: string;
|
|
91
|
+
content: Uint8Array;
|
|
92
|
+
} & AbortableIface): Promise<void>;
|
|
93
|
+
writeTextFile(options: {
|
|
94
|
+
path: string;
|
|
95
|
+
content: string;
|
|
96
|
+
encoding?: string;
|
|
97
|
+
} & AbortableIface): Promise<void>;
|
|
98
|
+
spawn(options: SandboxProcessOptionsIface): Promise<SandboxProcessIface>;
|
|
99
|
+
run(options: SandboxProcessOptionsIface): Promise<SandboxRunResultIface>;
|
|
100
|
+
stat(options: {
|
|
101
|
+
path: string;
|
|
102
|
+
root?: string;
|
|
103
|
+
} & AbortableIface): Promise<StatIface | null>;
|
|
104
|
+
readDir(options: {
|
|
105
|
+
path: string;
|
|
106
|
+
root?: string;
|
|
107
|
+
} & AbortableIface): Promise<DirEntryIface[]>;
|
|
108
|
+
resolvePath(path: string): string;
|
|
109
|
+
removePath(options: {
|
|
110
|
+
path: string;
|
|
111
|
+
recursive?: boolean;
|
|
112
|
+
force?: boolean;
|
|
113
|
+
} & AbortableIface): Promise<void>;
|
|
114
|
+
}
|
|
115
|
+
export declare enum NetworkPolicy {
|
|
116
|
+
AllowAll = "allow-all",
|
|
117
|
+
DenyAll = "deny-all",
|
|
118
|
+
Allowlist = "allowlist"
|
|
119
|
+
}
|
|
120
|
+
export interface NetworkPolicyIface {
|
|
121
|
+
mode: NetworkPolicy;
|
|
122
|
+
allow?: string[];
|
|
123
|
+
}
|
|
124
|
+
export declare enum PortProtocol {
|
|
125
|
+
Http = "http",
|
|
126
|
+
Https = "https",
|
|
127
|
+
Ws = "ws"
|
|
128
|
+
}
|
|
129
|
+
export interface McpEndpointIface {
|
|
130
|
+
name: string;
|
|
131
|
+
url: string;
|
|
132
|
+
headers: Record<string, string>;
|
|
133
|
+
}
|
|
134
|
+
export interface McpChannelIface {
|
|
135
|
+
send(message: JsonValue, options?: AbortableIface): Promise<void>;
|
|
136
|
+
receive(options?: AbortableIface): Promise<JsonValue[]>;
|
|
137
|
+
close(): Promise<void>;
|
|
138
|
+
}
|
|
139
|
+
export interface McpChannelEndpointIface {
|
|
140
|
+
name: string;
|
|
141
|
+
connect(options?: AbortableIface): Promise<McpChannelIface>;
|
|
142
|
+
}
|
|
143
|
+
export type SandboxMcpEndpoint = McpEndpointIface | McpChannelEndpointIface;
|
|
144
|
+
export interface SandboxMcpCatalogIface {
|
|
145
|
+
computerUse: ToolDescriptorIface[] | null;
|
|
146
|
+
localMcp: Record<string, ToolDescriptorIface[]> | null;
|
|
147
|
+
}
|
|
148
|
+
export declare const isMcpChannelEndpoint: (endpoint: SandboxMcpEndpoint) => endpoint is McpChannelEndpointIface;
|
|
149
|
+
export interface ScreenOptionsIface {
|
|
150
|
+
viewOnly?: boolean;
|
|
151
|
+
}
|
|
152
|
+
export interface ScreenSessionIface {
|
|
153
|
+
url: string;
|
|
154
|
+
token: string;
|
|
155
|
+
expiresAt: string;
|
|
156
|
+
}
|
|
157
|
+
export interface NetworkSandboxSessionIface extends SandboxSessionIface {
|
|
158
|
+
readonly id: string;
|
|
159
|
+
readonly defaultWorkingDirectory: string;
|
|
160
|
+
readonly ports: readonly number[];
|
|
161
|
+
getPortEndpoint(options: {
|
|
162
|
+
port: number;
|
|
163
|
+
protocol?: PortProtocol;
|
|
164
|
+
}): Promise<{
|
|
165
|
+
url: string;
|
|
166
|
+
headers?: Record<string, string>;
|
|
167
|
+
}>;
|
|
168
|
+
getPortUrl(options: {
|
|
169
|
+
port: number;
|
|
170
|
+
protocol?: PortProtocol;
|
|
171
|
+
}): Promise<string>;
|
|
172
|
+
stop(): Promise<void>;
|
|
173
|
+
destroy(): Promise<void>;
|
|
174
|
+
setNetworkPolicy?(policy: NetworkPolicyIface): Promise<void>;
|
|
175
|
+
computerUse?(): Promise<SandboxMcpEndpoint>;
|
|
176
|
+
screen?(options?: ScreenOptionsIface): Promise<ScreenSessionIface>;
|
|
177
|
+
localMcp?(): Promise<SandboxMcpEndpoint[]>;
|
|
178
|
+
}
|
|
179
|
+
export declare enum SandboxCapability {
|
|
180
|
+
Files = "files",
|
|
181
|
+
Process = "process",
|
|
182
|
+
Ports = "ports",
|
|
183
|
+
NetworkPolicy = "networkPolicy",
|
|
184
|
+
ComputerUse = "computerUse",
|
|
185
|
+
Screen = "screen",
|
|
186
|
+
LocalMcp = "localMcp",
|
|
187
|
+
Browser = "browser"
|
|
188
|
+
}
|
|
189
|
+
export interface SandboxProviderHandleIface<S extends SandboxSessionIface> {
|
|
190
|
+
readonly sandbox: S;
|
|
191
|
+
onSandboxStop(): Promise<void>;
|
|
192
|
+
onSandboxDelete(options?: {
|
|
193
|
+
reason?: string;
|
|
194
|
+
}): Promise<void>;
|
|
195
|
+
onRuntimeShutdown(): Promise<void>;
|
|
196
|
+
}
|
|
197
|
+
export interface SandboxGuideVersionIface {
|
|
198
|
+
guideId: string;
|
|
199
|
+
versionId: string;
|
|
200
|
+
slug: string;
|
|
201
|
+
title: string;
|
|
202
|
+
number: number;
|
|
203
|
+
image: string;
|
|
204
|
+
templateConfig: JsonValue;
|
|
205
|
+
defaultParameters: JsonValue;
|
|
206
|
+
instructionsMarkdown: string | null;
|
|
207
|
+
preparedArtifact?: {
|
|
208
|
+
providerRef: string;
|
|
209
|
+
key: string;
|
|
210
|
+
artifact: JsonValue;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
export interface SandboxGuidesIface {
|
|
214
|
+
get(args: {
|
|
215
|
+
ref: string;
|
|
216
|
+
version: number | 'latest';
|
|
217
|
+
}): Promise<SandboxGuideVersionIface | null>;
|
|
218
|
+
default(): Promise<SandboxGuideVersionIface | null>;
|
|
219
|
+
}
|
|
220
|
+
export interface SandboxRepositoryCloneSourceIface {
|
|
221
|
+
url: string;
|
|
222
|
+
ref: string | null;
|
|
223
|
+
authorization: string | null;
|
|
224
|
+
}
|
|
225
|
+
export interface SandboxRepositoriesIface {
|
|
226
|
+
cloneSource(args: {
|
|
227
|
+
repository: string;
|
|
228
|
+
ref: string | null;
|
|
229
|
+
}): Promise<SandboxRepositoryCloneSourceIface | null>;
|
|
230
|
+
}
|
|
231
|
+
export interface SandboxVariablesIface {
|
|
232
|
+
get(name: string): Promise<string | null>;
|
|
233
|
+
}
|
|
234
|
+
export declare const noSandboxGuides: SandboxGuidesIface;
|
|
235
|
+
export declare const noSandboxRepositories: SandboxRepositoriesIface;
|
|
236
|
+
export declare const noSandboxVariables: SandboxVariablesIface;
|
|
237
|
+
export interface SandboxActingUserIface {
|
|
238
|
+
current(): Promise<string | null>;
|
|
239
|
+
}
|
|
240
|
+
export declare const noSandboxActingUser: SandboxActingUserIface;
|
|
241
|
+
export interface SandboxOfferContextIface {
|
|
242
|
+
organizationId: string;
|
|
243
|
+
actingUser: SandboxActingUserIface;
|
|
244
|
+
}
|
|
245
|
+
export interface SandboxEnvironmentContextIface {
|
|
246
|
+
organizationId: string;
|
|
247
|
+
guides: SandboxGuidesIface;
|
|
248
|
+
}
|
|
249
|
+
export interface SandboxArtifactsIface {
|
|
250
|
+
get(key: string): Promise<JsonValue | null>;
|
|
251
|
+
put(key: string, artifact: JsonValue): Promise<void>;
|
|
252
|
+
}
|
|
253
|
+
export interface SandboxPreparationSourceIface {
|
|
254
|
+
sourceRevision: string;
|
|
255
|
+
read(): Promise<{
|
|
256
|
+
files: Record<string, string>;
|
|
257
|
+
resources: Record<string, JsonValue>;
|
|
258
|
+
}>;
|
|
259
|
+
}
|
|
260
|
+
export interface SandboxPrepareContextIface {
|
|
261
|
+
preparation?: SandboxPreparationSourceIface;
|
|
262
|
+
artifacts?: SandboxArtifactsIface;
|
|
263
|
+
files: Record<string, string>;
|
|
264
|
+
resources: Record<string, JsonValue>;
|
|
265
|
+
sourceRevision: string;
|
|
266
|
+
storagePath: string;
|
|
267
|
+
organizationId: string;
|
|
268
|
+
guides: SandboxGuidesIface;
|
|
269
|
+
actingUser: SandboxActingUserIface;
|
|
270
|
+
log?: (message: string) => void;
|
|
271
|
+
}
|
|
272
|
+
export interface SandboxStartContextIface {
|
|
273
|
+
/** Passive recovery only: never wake, create, seed, or restart backend services. */
|
|
274
|
+
passive?: boolean;
|
|
275
|
+
preparation?: SandboxPreparationSourceIface;
|
|
276
|
+
session: {
|
|
277
|
+
id: string;
|
|
278
|
+
organizationId: string;
|
|
279
|
+
conversationId: string | null;
|
|
280
|
+
definitionId: string;
|
|
281
|
+
bindingId: string;
|
|
282
|
+
target: string;
|
|
283
|
+
};
|
|
284
|
+
storagePath: string;
|
|
285
|
+
guides: SandboxGuidesIface;
|
|
286
|
+
variables: SandboxVariablesIface;
|
|
287
|
+
repositories: SandboxRepositoriesIface;
|
|
288
|
+
actingUser: SandboxActingUserIface;
|
|
289
|
+
}
|
|
290
|
+
export declare enum SandboxSessionEndReason {
|
|
291
|
+
Completed = "completed",
|
|
292
|
+
Expired = "expired",
|
|
293
|
+
Failed = "failed"
|
|
294
|
+
}
|
|
295
|
+
export declare enum SandboxWorkspace {
|
|
296
|
+
Session = "session",
|
|
297
|
+
Conversation = "conversation",
|
|
298
|
+
Ephemeral = "ephemeral"
|
|
299
|
+
}
|
|
300
|
+
export interface SandboxProviderImplementationIface<OpenOptions, Artifact extends JsonValue, State extends JsonValue, S extends NetworkSandboxSessionIface> {
|
|
301
|
+
workspace?(ctx: SandboxEnvironmentContextIface): Promise<SandboxWorkspace | null>;
|
|
302
|
+
capabilities?(ctx: SandboxOfferContextIface): Promise<SandboxCapability[] | null>;
|
|
303
|
+
mcpCatalog?(ctx: SandboxOfferContextIface): Promise<SandboxMcpCatalogIface | null>;
|
|
304
|
+
readSnapshot?(ctx: SandboxOfferContextIface, state: State, request: SandboxSnapshotRequestIface): Promise<SandboxSnapshotResponseIface | null>;
|
|
305
|
+
processes?(ctx: SandboxOfferContextIface & {
|
|
306
|
+
bindingId: string;
|
|
307
|
+
}, state: State, request: ProcessInspectionRequestIface): Promise<ProcessInspectionResultIface>;
|
|
308
|
+
editor?(ctx: SandboxOfferContextIface, state: State, request: SandboxEditorRequestIface): Promise<SandboxEditorResultIface>;
|
|
309
|
+
artifactKey(ctx: SandboxPrepareContextIface): Promise<string>;
|
|
310
|
+
prepare(ctx: SandboxPrepareContextIface): Promise<Artifact>;
|
|
311
|
+
start(ctx: SandboxStartContextIface, options: OpenOptions | undefined, artifact: Artifact): Promise<{
|
|
312
|
+
handle: SandboxProviderHandleIface<S>;
|
|
313
|
+
state: State;
|
|
314
|
+
region?: string | null;
|
|
315
|
+
}>;
|
|
316
|
+
resume(ctx: SandboxStartContextIface, artifact: Artifact, state: State): Promise<SandboxProviderHandleIface<S>>;
|
|
317
|
+
resumePassive?(ctx: SandboxStartContextIface, artifact: Artifact, state: State): Promise<SandboxProviderHandleIface<S>>;
|
|
318
|
+
park?(ctx: SandboxStartContextIface, artifact: Artifact, state: State): Promise<State>;
|
|
319
|
+
onSessionEnd?(ctx: SandboxStartContextIface, artifact: Artifact, state: State, options: {
|
|
320
|
+
reason: SandboxSessionEndReason;
|
|
321
|
+
}): Promise<void>;
|
|
322
|
+
}
|
|
323
|
+
export interface SandboxProviderDefinitionIface<EnvOptions, OpenOptions, Artifact extends JsonValue, State extends JsonValue, S extends NetworkSandboxSessionIface> {
|
|
324
|
+
name: string;
|
|
325
|
+
stateProtocolVersion?: number;
|
|
326
|
+
environment(options?: EnvOptions): SandboxProviderImplementationIface<OpenOptions, Artifact, State, S>;
|
|
327
|
+
}
|
|
328
|
+
export interface SandboxProviderIface<EnvOptions, OpenOptions, Artifact extends JsonValue, State extends JsonValue, S extends NetworkSandboxSessionIface> {
|
|
329
|
+
readonly definition: SandboxProviderDefinitionIface<EnvOptions, OpenOptions, Artifact, State, S>;
|
|
330
|
+
readonly name: string;
|
|
331
|
+
environment(options?: EnvOptions): AwaitableSandboxEnvironmentIface<EnvOptions, OpenOptions>;
|
|
332
|
+
}
|
|
333
|
+
export interface SandboxEnvironmentIface<EnvOptions, OpenOptions> {
|
|
334
|
+
readonly providerName: string;
|
|
335
|
+
readonly options: EnvOptions | undefined;
|
|
336
|
+
readonly authoringWarnings?: readonly string[];
|
|
337
|
+
open(options?: OpenOptions): SandboxOpenRequestIface<EnvOptions, OpenOptions>;
|
|
338
|
+
}
|
|
339
|
+
export interface AwaitableSandboxEnvironmentIface<EnvOptions, OpenOptions> extends SandboxEnvironmentIface<EnvOptions, OpenOptions> {
|
|
340
|
+
open(options?: OpenOptions): AwaitableSandboxOpenRequestIface<EnvOptions, OpenOptions>;
|
|
341
|
+
}
|
|
342
|
+
export interface SandboxOpenRequestIface<EnvOptions, OpenOptions> {
|
|
343
|
+
readonly providerName: string;
|
|
344
|
+
readonly environmentOptions: EnvOptions | undefined;
|
|
345
|
+
readonly openOptions: OpenOptions | undefined;
|
|
346
|
+
readonly authoringWarnings?: readonly string[];
|
|
347
|
+
}
|
|
348
|
+
export declare const defineSandboxProvider: <EnvOptions, OpenOptions, Artifact extends JsonValue, State extends JsonValue, S extends NetworkSandboxSessionIface>(definition: SandboxProviderDefinitionIface<EnvOptions, OpenOptions, Artifact, State, S>) => SandboxProviderIface<EnvOptions, OpenOptions, Artifact, State, S>;
|
|
349
|
+
export type AnySandboxProviderIface = SandboxProviderIface<JsonValue, JsonValue, JsonValue, JsonValue, NetworkSandboxSessionIface>;
|
|
350
|
+
export declare enum SandboxEventKind {
|
|
351
|
+
ProcessExited = "process_exited"
|
|
352
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { awaitableOpenRequest } from "./open-scope.mjs";
|
|
2
|
+
var SandboxEntryType = /* @__PURE__ */ ((SandboxEntryType2) => {
|
|
3
|
+
SandboxEntryType2["File"] = "file";
|
|
4
|
+
SandboxEntryType2["Directory"] = "directory";
|
|
5
|
+
SandboxEntryType2["Symlink"] = "symlink";
|
|
6
|
+
SandboxEntryType2["Other"] = "other";
|
|
7
|
+
return SandboxEntryType2;
|
|
8
|
+
})(SandboxEntryType || {});
|
|
9
|
+
var NetworkPolicy = /* @__PURE__ */ ((NetworkPolicy2) => {
|
|
10
|
+
NetworkPolicy2["AllowAll"] = "allow-all";
|
|
11
|
+
NetworkPolicy2["DenyAll"] = "deny-all";
|
|
12
|
+
NetworkPolicy2["Allowlist"] = "allowlist";
|
|
13
|
+
return NetworkPolicy2;
|
|
14
|
+
})(NetworkPolicy || {});
|
|
15
|
+
var PortProtocol = /* @__PURE__ */ ((PortProtocol2) => {
|
|
16
|
+
PortProtocol2["Http"] = "http";
|
|
17
|
+
PortProtocol2["Https"] = "https";
|
|
18
|
+
PortProtocol2["Ws"] = "ws";
|
|
19
|
+
return PortProtocol2;
|
|
20
|
+
})(PortProtocol || {});
|
|
21
|
+
const isMcpChannelEndpoint = (endpoint) => "connect" in endpoint;
|
|
22
|
+
var SandboxCapability = /* @__PURE__ */ ((SandboxCapability2) => {
|
|
23
|
+
SandboxCapability2["Files"] = "files";
|
|
24
|
+
SandboxCapability2["Process"] = "process";
|
|
25
|
+
SandboxCapability2["Ports"] = "ports";
|
|
26
|
+
SandboxCapability2["NetworkPolicy"] = "networkPolicy";
|
|
27
|
+
SandboxCapability2["ComputerUse"] = "computerUse";
|
|
28
|
+
SandboxCapability2["Screen"] = "screen";
|
|
29
|
+
SandboxCapability2["LocalMcp"] = "localMcp";
|
|
30
|
+
SandboxCapability2["Browser"] = "browser";
|
|
31
|
+
return SandboxCapability2;
|
|
32
|
+
})(SandboxCapability || {});
|
|
33
|
+
const noSandboxGuides = {
|
|
34
|
+
get: async () => null,
|
|
35
|
+
default: async () => null
|
|
36
|
+
};
|
|
37
|
+
const noSandboxRepositories = {
|
|
38
|
+
cloneSource: async () => null
|
|
39
|
+
};
|
|
40
|
+
const noSandboxVariables = { get: async () => null };
|
|
41
|
+
const noSandboxActingUser = { current: async () => null };
|
|
42
|
+
var SandboxSessionEndReason = /* @__PURE__ */ ((SandboxSessionEndReason2) => {
|
|
43
|
+
SandboxSessionEndReason2["Completed"] = "completed";
|
|
44
|
+
SandboxSessionEndReason2["Expired"] = "expired";
|
|
45
|
+
SandboxSessionEndReason2["Failed"] = "failed";
|
|
46
|
+
return SandboxSessionEndReason2;
|
|
47
|
+
})(SandboxSessionEndReason || {});
|
|
48
|
+
var SandboxWorkspace = /* @__PURE__ */ ((SandboxWorkspace2) => {
|
|
49
|
+
SandboxWorkspace2["Session"] = "session";
|
|
50
|
+
SandboxWorkspace2["Conversation"] = "conversation";
|
|
51
|
+
SandboxWorkspace2["Ephemeral"] = "ephemeral";
|
|
52
|
+
return SandboxWorkspace2;
|
|
53
|
+
})(SandboxWorkspace || {});
|
|
54
|
+
const defineSandboxProvider = (definition) => ({
|
|
55
|
+
definition,
|
|
56
|
+
name: definition.name,
|
|
57
|
+
environment: (options) => ({
|
|
58
|
+
providerName: definition.name,
|
|
59
|
+
options,
|
|
60
|
+
open: (openOptions) => awaitableOpenRequest({
|
|
61
|
+
providerName: definition.name,
|
|
62
|
+
environmentOptions: options,
|
|
63
|
+
openOptions
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
var SandboxEventKind = /* @__PURE__ */ ((SandboxEventKind2) => {
|
|
68
|
+
SandboxEventKind2["ProcessExited"] = "process_exited";
|
|
69
|
+
return SandboxEventKind2;
|
|
70
|
+
})(SandboxEventKind || {});
|
|
71
|
+
export {
|
|
72
|
+
NetworkPolicy,
|
|
73
|
+
PortProtocol,
|
|
74
|
+
SandboxCapability,
|
|
75
|
+
SandboxEntryType,
|
|
76
|
+
SandboxEventKind,
|
|
77
|
+
SandboxSessionEndReason,
|
|
78
|
+
SandboxWorkspace,
|
|
79
|
+
defineSandboxProvider,
|
|
80
|
+
isMcpChannelEndpoint,
|
|
81
|
+
noSandboxActingUser,
|
|
82
|
+
noSandboxGuides,
|
|
83
|
+
noSandboxRepositories,
|
|
84
|
+
noSandboxVariables
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/sandbox/types.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n ProcessInspectionRequestIface,\n ProcessInspectionResultIface,\n} from '@finalai/agent-protocol/process-inspection';\nimport type { JsonValue } from \"../json.mjs\";\nimport type { ToolDescriptorIface } from \"../manifest.mjs\";\nimport type { SandboxEditorRequestIface, SandboxEditorResultIface } from \"./editor.mjs\";\nimport { awaitableOpenRequest, type AwaitableSandboxOpenRequestIface } from \"./open-scope.mjs\";\nimport type { SandboxSnapshotRequestIface, SandboxSnapshotResponseIface } from \"./snapshots.mjs\";\n\n// Sandbox providers and consumers share the streaming session contract.\n\nexport interface AbortableIface {\n abortSignal?: AbortSignal;\n}\n\nexport interface SandboxProcessOptionsIface extends AbortableIface {\n command: string;\n args?: string[];\n cwd?: string;\n env?: Record<string, string>;\n // Run through the sandbox's login shell (`bash -lc`) instead of exec'ing.\n shell?: boolean;\n stdin?: ReadableStream<Uint8Array> | string;\n timeoutMs?: number;\n}\n\nexport interface SandboxProcessIface {\n readonly pid: string | null;\n readonly stdout: ReadableStream<Uint8Array>;\n readonly stderr: ReadableStream<Uint8Array>;\n // Writes to the process's stdin; closes stdin when `end` is true.\n write(data: Uint8Array | string, options?: { end?: boolean }): Promise<void>;\n wait(): Promise<{ exitCode: number }>;\n kill(signal?: string): Promise<void>;\n}\n\nexport interface SandboxRunResultIface {\n exitCode: number;\n stdout: string;\n stderr: string;\n}\n\nexport enum SandboxEntryType {\n File = 'file',\n Directory = 'directory',\n Symlink = 'symlink',\n Other = 'other',\n}\n\nexport interface StatIface {\n path: string;\n type: SandboxEntryType;\n size: number;\n modifiedAt: string | null;\n mode: number | null;\n}\n\nexport interface DirEntryIface {\n name: string;\n path: string;\n type: SandboxEntryType;\n size: number | null;\n}\n\nexport interface ConfinedSandboxFilesIface {\n readFile(\n options: { path: string; root: string } & AbortableIface,\n ): Promise<ReadableStream<Uint8Array> | null>;\n stat(options: { path: string; root: string } & AbortableIface): Promise<StatIface | null>;\n readDir(\n options: { path: string; root: string } & AbortableIface,\n ): Promise<DirEntryIface[] | null>;\n}\n\nexport interface SandboxSessionIface {\n readonly description: string;\n readonly confinedFileReader?: ConfinedSandboxFilesIface;\n // On the RPC surface, root confines viewer reads to this directory, rejects\n // symlink ancestors and requires Python 3 in the sandbox (confinedFiles feature).\n readFile(\n options: { path: string; root?: string } & AbortableIface,\n ): Promise<ReadableStream<Uint8Array> | null>;\n readBinaryFile(options: { path: string } & AbortableIface): Promise<Uint8Array | null>;\n readTextFile(\n options: {\n path: string;\n encoding?: string;\n startLine?: number;\n endLine?: number;\n } & AbortableIface,\n ): Promise<string | null>;\n writeFile(\n options: { path: string; content: ReadableStream<Uint8Array> } & AbortableIface,\n ): Promise<void>;\n writeBinaryFile(options: { path: string; content: Uint8Array } & AbortableIface): Promise<void>;\n writeTextFile(\n options: { path: string; content: string; encoding?: string } & AbortableIface,\n ): Promise<void>;\n spawn(options: SandboxProcessOptionsIface): Promise<SandboxProcessIface>;\n run(options: SandboxProcessOptionsIface): Promise<SandboxRunResultIface>;\n stat(options: { path: string; root?: string } & AbortableIface): Promise<StatIface | null>;\n readDir(options: { path: string; root?: string } & AbortableIface): Promise<DirEntryIface[]>;\n resolvePath(path: string): string;\n removePath(\n options: { path: string; recursive?: boolean; force?: boolean } & AbortableIface,\n ): Promise<void>;\n}\n\nexport enum NetworkPolicy {\n AllowAll = 'allow-all',\n DenyAll = 'deny-all',\n Allowlist = 'allowlist',\n}\n\nexport interface NetworkPolicyIface {\n mode: NetworkPolicy;\n allow?: string[];\n}\n\nexport enum PortProtocol {\n Http = 'http',\n Https = 'https',\n Ws = 'ws',\n}\n\n// An MCP transport the sandbox serves for an optional capability: an HTTP MCP\n// endpoint the harness (or the session service) can dial.\nexport interface McpEndpointIface {\n name: string;\n url: string;\n headers: Record<string, string>;\n}\n\n// A JSON-RPC message channel to an MCP server the sandbox hosts, for backends\n// whose API reaches it some other way than HTTP MCP (a byte pipe, a socket).\n// Messages are JSON-RPC objects, in order.\nexport interface McpChannelIface {\n send(message: JsonValue, options?: AbortableIface): Promise<void>;\n // The messages that arrived since the last call; [] when none did.\n receive(options?: AbortableIface): Promise<JsonValue[]>;\n close(): Promise<void>;\n}\n\n// An MCP server the sandbox hosts, opened in process by whoever runs the handle.\n// It cannot cross the handle RPC wire.\nexport interface McpChannelEndpointIface {\n name: string;\n connect(options?: AbortableIface): Promise<McpChannelIface>;\n}\n\nexport type SandboxMcpEndpoint = McpEndpointIface | McpChannelEndpointIface;\n\n// The tools of a sandbox's hosted MCP servers, as far as they are known without\n// starting it. Null: unknown until the sandbox is attached and asked.\nexport interface SandboxMcpCatalogIface {\n computerUse: ToolDescriptorIface[] | null;\n // Local MCP server name \u2192 its tools.\n localMcp: Record<string, ToolDescriptorIface[]> | null;\n}\n\nexport const isMcpChannelEndpoint = (\n endpoint: SandboxMcpEndpoint,\n): endpoint is McpChannelEndpointIface => 'connect' in endpoint;\n\nexport interface ScreenOptionsIface {\n // View-only by default; explicit input control requires execute access.\n viewOnly?: boolean;\n}\n\nexport interface ScreenSessionIface {\n // A short-lived viewer grant; providers enforce the requested input access.\n url: string;\n token: string;\n expiresAt: string;\n}\n\nexport interface NetworkSandboxSessionIface extends SandboxSessionIface {\n readonly id: string;\n readonly defaultWorkingDirectory: string;\n readonly ports: readonly number[];\n getPortEndpoint(options: {\n port: number;\n protocol?: PortProtocol;\n }): Promise<{ url: string; headers?: Record<string, string> }>;\n getPortUrl(options: { port: number; protocol?: PortProtocol }): Promise<string>;\n stop(): Promise<void>;\n destroy(): Promise<void>;\n setNetworkPolicy?(policy: NetworkPolicyIface): Promise<void>;\n computerUse?(): Promise<SandboxMcpEndpoint>;\n screen?(options?: ScreenOptionsIface): Promise<ScreenSessionIface>;\n localMcp?(): Promise<SandboxMcpEndpoint[]>;\n}\n\n// Capabilities a started sandbox advertises (and the handle RPC exposes).\nexport enum SandboxCapability {\n Files = 'files',\n Process = 'process',\n Ports = 'ports',\n NetworkPolicy = 'networkPolicy',\n ComputerUse = 'computerUse',\n Screen = 'screen',\n LocalMcp = 'localMcp',\n Browser = 'browser',\n}\n\nexport interface SandboxProviderHandleIface<S extends SandboxSessionIface> {\n readonly sandbox: S;\n onSandboxStop(): Promise<void>;\n onSandboxDelete(options?: { reason?: string }): Promise<void>;\n onRuntimeShutdown(): Promise<void>;\n}\n\n// A saved computer setup guide version: Build's versioned build-\n// and start-time inputs for a sandbox, as the session service serves them.\nexport interface SandboxGuideVersionIface {\n guideId: string;\n versionId: string;\n slug: string;\n title: string;\n number: number;\n image: string;\n // `.final/sandbox-template.yaml` v2 as JSON.\n templateConfig: JsonValue;\n // The start-time parameters this version defaults to.\n defaultParameters: JsonValue;\n instructionsMarkdown: string | null;\n // A ready build from the guide's provider, reusable independently of workspace seeds.\n preparedArtifact?: { providerRef: string; key: string; artifact: JsonValue };\n}\n\n// The organization's computer setup guides, read through the session service.\n// Every provider gets the same reader; a provider whose\n// environments name no guide never calls it.\nexport interface SandboxGuidesIface {\n get(args: { ref: string; version: number | 'latest' }): Promise<SandboxGuideVersionIface | null>;\n // The organization's default guide; null when it has none.\n default(): Promise<SandboxGuideVersionIface | null>;\n}\n\n// Where to clone a repository from, with a short-lived read credential that\n// must reach only the clone process (never a repository's git config).\nexport interface SandboxRepositoryCloneSourceIface {\n url: string;\n // Checked out after the clone; null keeps the default branch.\n ref: string | null;\n // An HTTP Authorization header value for the clone, or null.\n authorization: string | null;\n}\n\n// Repository credentials for the repositories an environment names (a Code\n// Storage id, a GitHub owner/name), resolved by the session service for the\n// session's organization only. Null: not a repository it can resolve.\nexport interface SandboxRepositoriesIface {\n cloneSource(args: {\n repository: string;\n ref: string | null;\n }): Promise<SandboxRepositoryCloneSourceIface | null>;\n}\n\n// Reads a named organization variable (managed in Build) for the session's\n// organization. Values are injected into the sandbox only, never stored in a\n// manifest, a state or the log.\nexport interface SandboxVariablesIface {\n get(name: string): Promise<string | null>;\n}\n\nexport const noSandboxGuides: SandboxGuidesIface = {\n get: async () => null,\n default: async () => null,\n};\n\nexport const noSandboxRepositories: SandboxRepositoriesIface = {\n cloneSource: async () => null,\n};\n\nexport const noSandboxVariables: SandboxVariablesIface = { get: async () => null };\n\n// The user a session acts for: the author of its running turn, else its owner,\n// else the user whose Home its conversation is. A call a person makes through\n// the platform's sandbox viewer acts for that person instead. Null when it acts\n// for no user (a turn nobody prompted in a shared conversation) and outside any\n// session (a guide build). Read on each call, because it changes between turns\n// and between callers.\nexport interface SandboxActingUserIface {\n current(): Promise<string | null>;\n}\n\nexport const noSandboxActingUser: SandboxActingUserIface = { current: async () => null };\n\n// What an environment's pre-start reads (capabilities, mcpCatalog) are given.\nexport interface SandboxOfferContextIface {\n organizationId: string;\n actingUser: SandboxActingUserIface;\n}\n\n// What an environment's hooks are given before anything starts.\nexport interface SandboxEnvironmentContextIface {\n organizationId: string;\n guides: SandboxGuidesIface;\n}\n\n// Scoped by the host to this organization and provider. Providers can retain\n// reusable intermediate artifacts independently of a revision's seed files.\nexport interface SandboxArtifactsIface {\n get(key: string): Promise<JsonValue | null>;\n put(key: string, artifact: JsonValue): Promise<void>;\n}\n\nexport interface SandboxPreparationSourceIface {\n sourceRevision: string;\n read(): Promise<{ files: Record<string, string>; resources: Record<string, JsonValue> }>;\n}\n\nexport interface SandboxPrepareContextIface {\n // A host-persisted resource source; artifacts may retain its identity instead of seed contents.\n preparation?: SandboxPreparationSourceIface;\n artifacts?: SandboxArtifactsIface;\n // Agent revisions supply workspace-relative seeds; setup-guide builds supply\n // guide.json and optional instructions.md. Resources name workspace, skills or guide.\n // Model instructions remain harness config.\n files: Record<string, string>;\n resources: Record<string, JsonValue>;\n sourceRevision: string;\n storagePath: string;\n organizationId: string;\n // The guide inputs (build-time) an environment names, resolved by the platform.\n guides: SandboxGuidesIface;\n // Who the session the artifact is prepared for acts for, for environments that\n // name a backend resource relative to that user; the key must then name it.\n actingUser: SandboxActingUserIface;\n log?: (message: string) => void;\n}\n\nexport interface SandboxStartContextIface {\n /** Passive recovery only: never wake, create, seed, or restart backend services. */\n passive?: boolean;\n preparation?: SandboxPreparationSourceIface;\n session: {\n id: string;\n organizationId: string;\n conversationId: string | null;\n definitionId: string;\n bindingId: string;\n target: string;\n };\n storagePath: string;\n // Start-time inputs: guides, the variables to inject, repository credentials.\n guides: SandboxGuidesIface;\n variables: SandboxVariablesIface;\n repositories: SandboxRepositoriesIface;\n actingUser: SandboxActingUserIface;\n}\n\nexport enum SandboxSessionEndReason {\n Completed = 'completed',\n Expired = 'expired',\n Failed = 'failed',\n}\n\n// How long an environment's sandbox outlives a session: `session`\n// keeps it for the session's life; `conversation` gives every session in the\n// conversation one shared sandbox per target, surviving session resets;\n// `ephemeral` discards it when released.\nexport enum SandboxWorkspace {\n Session = 'session',\n Conversation = 'conversation',\n Ephemeral = 'ephemeral',\n}\n\nexport interface SandboxProviderImplementationIface<\n OpenOptions,\n Artifact extends JsonValue,\n State extends JsonValue,\n S extends NetworkSandboxSessionIface,\n> {\n // The workspace this environment declares, read before anything starts so the\n // session service knows which sessions share a binding. Absent or null: session.\n workspace?(ctx: SandboxEnvironmentContextIface): Promise<SandboxWorkspace | null>;\n // The capabilities this environment's sandboxes offer, read before anything\n // starts through the backend's own API. Absent or null: unknown\n // until started; local MCP is then not projected.\n capabilities?(ctx: SandboxOfferContextIface): Promise<SandboxCapability[] | null>;\n // The hosted MCP servers' tool catalogs the backend can give without starting\n // a sandbox (from its own records), so the MCP projection lists them from the\n // first `tools/list`. The projection checks a server's catalog against the\n // live server when a call first opens that server (servers a session never\n // uses stay closed) and announces a change with\n // `notifications/tools/list_changed`.\n //\n // Trade-off: a catalog left unknown (absent hook, null, or a null field) can\n // only be learned from the live sandbox, so the first `tools/list` that finds\n // it unknown starts the sandbox in the background, at session start rather\n // than on the first tool call. Otherwise those tools would never be listed,\n // and nothing would ever call them. Providers that can give the catalog keep\n // attach lazy.\n mcpCatalog?(ctx: SandboxOfferContextIface): Promise<SandboxMcpCatalogIface | null>;\n // Reads committed files without starting/resuming a sandbox. Null means the backend\n // is live or offers no snapshot. An unavailable sleeping snapshot must throw,\n // never fall through to a read that wakes it. Pin subsequent ranges by snapshotId.\n readSnapshot?(\n ctx: SandboxOfferContextIface,\n state: State,\n request: SandboxSnapshotRequestIface,\n ): Promise<SandboxSnapshotResponseIface | null>;\n // Inspect retained backend processes without opening, resuming or extending a sandbox.\n // Stop requires execute access; the provider also enforces backend ownership.\n processes?(\n ctx: SandboxOfferContextIface & { bindingId: string },\n state: State,\n request: ProcessInspectionRequestIface,\n ): Promise<ProcessInspectionResultIface>;\n // Browser editor for this provider's existing workspace. The host checks write\n // authorization; this hook never creates or wakes a backend. Credentials stay\n // in the authentication form, never the editor URL or stored provider state.\n editor?(\n ctx: SandboxOfferContextIface,\n state: State,\n request: SandboxEditorRequestIface,\n ): Promise<SandboxEditorResultIface>;\n // Content-addressed by `artifactKey`; the session service caches artifacts in\n // agent.sandbox_artifacts and calls prepare only on a miss.\n artifactKey(ctx: SandboxPrepareContextIface): Promise<string>;\n prepare(ctx: SandboxPrepareContextIface): Promise<Artifact>;\n // `region`: where the backend placed the sandbox (its own region name), so the\n // session service can place the harness near it; null when unknown.\n start(\n ctx: SandboxStartContextIface,\n options: OpenOptions | undefined,\n artifact: Artifact,\n ): Promise<{ handle: SandboxProviderHandleIface<S>; state: State; region?: string | null }>;\n resume(\n ctx: SandboxStartContextIface,\n artifact: Artifact,\n state: State,\n ): Promise<SandboxProviderHandleIface<S>>;\n // Reconnect to an already running backend after host restart for a read-only viewer.\n // Absent: viewers can use a retained live handle but cannot trigger resume.\n resumePassive?(\n ctx: SandboxStartContextIface,\n artifact: Artifact,\n state: State,\n ): Promise<SandboxProviderHandleIface<S>>;\n // Park: pause or stop the sandbox, returning the state resume needs.\n park?(ctx: SandboxStartContextIface, artifact: Artifact, state: State): Promise<State>;\n onSessionEnd?(\n ctx: SandboxStartContextIface,\n artifact: Artifact,\n state: State,\n options: { reason: SandboxSessionEndReason },\n ): Promise<void>;\n}\n\nexport interface SandboxProviderDefinitionIface<\n EnvOptions,\n OpenOptions,\n Artifact extends JsonValue,\n State extends JsonValue,\n S extends NetworkSandboxSessionIface,\n> {\n name: string;\n // The version of `State`'s shape. The session service records it with each\n // binding and refuses to resume a state written under another version (the\n // next call starts the sandbox again instead).\n stateProtocolVersion?: number;\n environment(\n options?: EnvOptions,\n ): SandboxProviderImplementationIface<OpenOptions, Artifact, State, S>;\n}\n\n// A defined provider: the definition plus authoring sugar. `environment(opts)`\n// returns an environment whose `.open(openOptions)` records a sandbox binding\n// target when authored, and is what the session service drives at run time.\nexport interface SandboxProviderIface<\n EnvOptions,\n OpenOptions,\n Artifact extends JsonValue,\n State extends JsonValue,\n S extends NetworkSandboxSessionIface,\n> {\n readonly definition: SandboxProviderDefinitionIface<EnvOptions, OpenOptions, Artifact, State, S>;\n readonly name: string;\n environment(options?: EnvOptions): AwaitableSandboxEnvironmentIface<EnvOptions, OpenOptions>;\n}\n\nexport interface SandboxEnvironmentIface<EnvOptions, OpenOptions> {\n readonly providerName: string;\n readonly options: EnvOptions | undefined;\n // Provider-authored notices shown by the compiler and Build before publication.\n readonly authoringWarnings?: readonly string[];\n // Authoring: records the open options (access, ...) for this target.\n open(options?: OpenOptions): SandboxOpenRequestIface<EnvOptions, OpenOptions>;\n}\n\n// An environment whose open request a sandbox.ts selector can await to get\n// the live session (open-scope.ts); what defineSandboxProvider and the\n// installed helpers return.\nexport interface AwaitableSandboxEnvironmentIface<\n EnvOptions,\n OpenOptions,\n> extends SandboxEnvironmentIface<EnvOptions, OpenOptions> {\n open(options?: OpenOptions): AwaitableSandboxOpenRequestIface<EnvOptions, OpenOptions>;\n}\n\nexport interface SandboxOpenRequestIface<EnvOptions, OpenOptions> {\n readonly providerName: string;\n readonly environmentOptions: EnvOptions | undefined;\n readonly openOptions: OpenOptions | undefined;\n readonly authoringWarnings?: readonly string[];\n}\n\nexport const defineSandboxProvider = <\n EnvOptions,\n OpenOptions,\n Artifact extends JsonValue,\n State extends JsonValue,\n S extends NetworkSandboxSessionIface,\n>(\n definition: SandboxProviderDefinitionIface<EnvOptions, OpenOptions, Artifact, State, S>,\n): SandboxProviderIface<EnvOptions, OpenOptions, Artifact, State, S> => ({\n definition,\n name: definition.name,\n environment: (options) => ({\n providerName: definition.name,\n options,\n open: (openOptions) =>\n awaitableOpenRequest({\n providerName: definition.name,\n environmentOptions: options,\n openOptions,\n }),\n }),\n});\n\n// Erased form the session service stores in its provider registry.\nexport type AnySandboxProviderIface = SandboxProviderIface<\n JsonValue,\n JsonValue,\n JsonValue,\n JsonValue,\n NetworkSandboxSessionIface\n>;\n\n// Events emitted through a sandbox provider's process lifecycle.\nexport enum SandboxEventKind {\n ProcessExited = 'process_exited',\n}\n"],
|
|
5
|
+
"mappings": "AAOA,SAAS,4BAAmE;AAoCrE,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,UAAO;AACP,EAAAA,kBAAA,eAAY;AACZ,EAAAA,kBAAA,aAAU;AACV,EAAAA,kBAAA,WAAQ;AAJE,SAAAA;AAAA,GAAA;AAkEL,IAAK,gBAAL,kBAAKC,mBAAL;AACL,EAAAA,eAAA,cAAW;AACX,EAAAA,eAAA,aAAU;AACV,EAAAA,eAAA,eAAY;AAHF,SAAAA;AAAA,GAAA;AAWL,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,UAAO;AACP,EAAAA,cAAA,WAAQ;AACR,EAAAA,cAAA,QAAK;AAHK,SAAAA;AAAA,GAAA;AAyCL,MAAM,uBAAuB,CAClC,aACwC,aAAa;AAgChD,IAAK,oBAAL,kBAAKC,uBAAL;AACL,EAAAA,mBAAA,WAAQ;AACR,EAAAA,mBAAA,aAAU;AACV,EAAAA,mBAAA,WAAQ;AACR,EAAAA,mBAAA,mBAAgB;AAChB,EAAAA,mBAAA,iBAAc;AACd,EAAAA,mBAAA,YAAS;AACT,EAAAA,mBAAA,cAAW;AACX,EAAAA,mBAAA,aAAU;AARA,SAAAA;AAAA,GAAA;AAwEL,MAAM,kBAAsC;AAAA,EACjD,KAAK,YAAY;AAAA,EACjB,SAAS,YAAY;AACvB;AAEO,MAAM,wBAAkD;AAAA,EAC7D,aAAa,YAAY;AAC3B;AAEO,MAAM,qBAA4C,EAAE,KAAK,YAAY,KAAK;AAY1E,MAAM,sBAA8C,EAAE,SAAS,YAAY,KAAK;AAkEhF,IAAK,0BAAL,kBAAKC,6BAAL;AACL,EAAAA,yBAAA,eAAY;AACZ,EAAAA,yBAAA,aAAU;AACV,EAAAA,yBAAA,YAAS;AAHC,SAAAA;AAAA,GAAA;AAUL,IAAK,mBAAL,kBAAKC,sBAAL;AACL,EAAAA,kBAAA,aAAU;AACV,EAAAA,kBAAA,kBAAe;AACf,EAAAA,kBAAA,eAAY;AAHF,SAAAA;AAAA,GAAA;AAmJL,MAAM,wBAAwB,CAOnC,gBACuE;AAAA,EACvE;AAAA,EACA,MAAM,WAAW;AAAA,EACjB,aAAa,CAAC,aAAa;AAAA,IACzB,cAAc,WAAW;AAAA,IACzB;AAAA,IACA,MAAM,CAAC,gBACL,qBAAqB;AAAA,MACnB,cAAc,WAAW;AAAA,MACzB,oBAAoB;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACL;AACF;AAYO,IAAK,mBAAL,kBAAKC,sBAAL;AACL,EAAAA,kBAAA,mBAAgB;AADN,SAAAA;AAAA,GAAA;",
|
|
6
|
+
"names": ["SandboxEntryType", "NetworkPolicy", "PortProtocol", "SandboxCapability", "SandboxSessionEndReason", "SandboxWorkspace", "SandboxEventKind"]
|
|
7
|
+
}
|