@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,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/sandbox/frame-channel.ts"],
|
|
4
|
+
"sourcesContent": ["// An ordered, bidirectional frame transport: a WebSocket or any message\n// stream. Text frames are JSON-RPC, binary frames are stream chunks.\n\nexport type WireFrame = string | Uint8Array;\n\nexport interface FrameChannelCloseIface {\n code: number;\n reason: string;\n}\n\nexport interface FrameChannelHandlersIface {\n frame: (frame: WireFrame) => void;\n close: (info: FrameChannelCloseIface) => void;\n}\n\nexport interface FrameChannelIface {\n send(frame: WireFrame): void;\n close(code?: number, reason?: string): void;\n // Registers the single consumer; frames received earlier are delivered first.\n listen(handlers: FrameChannelHandlersIface): void;\n}\n\nconst ABNORMAL_CLOSE = 1006;\n\nconst createBufferedListener = () => {\n const pending: WireFrame[] = [];\n let closed: FrameChannelCloseIface | null = null;\n let handlers: FrameChannelHandlersIface | null = null;\n return {\n frame: (frame: WireFrame) => {\n if (handlers == null) pending.push(frame);\n else handlers.frame(frame);\n },\n close: (info: FrameChannelCloseIface) => {\n if (closed != null) return;\n closed = info;\n handlers?.close(info);\n },\n listen: (next: FrameChannelHandlersIface) => {\n handlers = next;\n for (const frame of pending.splice(0)) next.frame(frame);\n if (closed != null) next.close(closed);\n },\n isClosed: () => closed != null,\n };\n};\n\n// The subset of the WHATWG WebSocket API the adapters need (browsers, Workers,\n// Node's global WebSocket and the `ws` package all satisfy it).\n// What WebSocket implementations deliver: text, or binary as ArrayBuffer,\n// a view, a Blob (when binaryType was ignored) or `ws`'s fragment arrays.\nexport type WebSocketMessageData = string | ArrayBuffer | ArrayBufferView | Blob | Uint8Array[];\n\nexport interface WebSocketMessageEventLikeIface {\n readonly data: WebSocketMessageData;\n}\n\nexport interface WebSocketEventLikeIface {\n readonly type: string;\n}\n\nexport interface WebSocketCloseEventLikeIface {\n readonly code: number;\n readonly reason: string;\n}\n\nexport interface WebSocketLikeIface {\n readonly readyState: number;\n binaryType: string;\n send(data: string | Uint8Array<ArrayBuffer>): void;\n close(code?: number, reason?: string): void;\n addEventListener(\n type: 'message',\n listener: (event: WebSocketMessageEventLikeIface) => void,\n ): void;\n addEventListener(type: 'close', listener: (event: WebSocketCloseEventLikeIface) => void): void;\n addEventListener(type: 'open', listener: (event: WebSocketEventLikeIface) => void): void;\n addEventListener(type: 'error', listener: (event: WebSocketEventLikeIface) => void): void;\n}\n\nexport type WebSocketConstructorIface = new (\n url: string,\n protocols?: string | string[],\n) => WebSocketLikeIface;\n\nconst WS_OPEN = 1;\n\nconst toWireFrame = (data: WebSocketMessageData): WireFrame | null => {\n if (data instanceof Uint8Array) return data;\n if (data instanceof ArrayBuffer) return new Uint8Array(data);\n if (ArrayBuffer.isView(data))\n return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n if (data instanceof Blob) return null;\n // `ws` may deliver fragmented binary messages as an array of buffers.\n if (Array.isArray(data)) {\n let total = 0;\n for (const part of data) total += part.byteLength;\n const out = new Uint8Array(total);\n let offset = 0;\n for (const part of data) {\n out.set(part, offset);\n offset += part.byteLength;\n }\n return out;\n }\n return data;\n};\n\n// Wraps a WebSocket. `opened` resolves once the socket is open (immediately\n// for an already open server-side socket) and rejects if it closes first.\nexport interface WebSocketFrameChannelIface {\n channel: FrameChannelIface;\n opened: Promise<void>;\n}\n\nexport const frameChannelFromWebSocket = (\n socket: WebSocketLikeIface,\n): WebSocketFrameChannelIface => {\n socket.binaryType = 'arraybuffer';\n const listener = createBufferedListener();\n let resolveOpen: () => void = () => undefined;\n let rejectOpen: (error: Error) => void = () => undefined;\n const opened = new Promise<void>((resolve, reject) => {\n resolveOpen = resolve;\n rejectOpen = reject;\n });\n // Avoid an unhandled rejection when nobody awaits `opened`.\n opened.catch(() => undefined);\n if (socket.readyState === WS_OPEN) resolveOpen();\n socket.addEventListener('open', () => resolveOpen());\n socket.addEventListener('message', (event) => {\n const frame = toWireFrame(event.data);\n if (frame != null) listener.frame(frame);\n });\n socket.addEventListener('close', (event) => {\n rejectOpen(new Error(`websocket closed before opening (${event.code})`));\n listener.close({ code: event.code, reason: event.reason });\n });\n socket.addEventListener('error', () => {\n rejectOpen(new Error('websocket failed to open'));\n });\n const channel: FrameChannelIface = {\n send: (frame) => {\n if (socket.readyState !== WS_OPEN) return;\n if (!(frame instanceof Uint8Array)) socket.send(frame);\n else if (frame.buffer instanceof ArrayBuffer)\n socket.send(new Uint8Array(frame.buffer, frame.byteOffset, frame.byteLength));\n else socket.send(new Uint8Array(frame));\n },\n close: (code, reason) => {\n try {\n socket.close(code, reason);\n } catch {\n socket.close();\n }\n listener.close({ code: code ?? 1000, reason: reason ?? '' });\n },\n listen: (handlers) => listener.listen(handlers),\n };\n return { channel, opened };\n};\n\nexport interface FrameStreamIface {\n readable: ReadableStream<WireFrame>;\n writable: WritableStream<WireFrame>;\n}\n\n// Wraps an ordered message stream (a MessagePort bridge, a relay, a test pair).\n// Close codes are not transmitted: the far side sees 1000 on a clean end.\nexport const frameChannelFromStream = (stream: FrameStreamIface): FrameChannelIface => {\n const listener = createBufferedListener();\n const writer = stream.writable.getWriter();\n const reader = stream.readable.getReader();\n const pump = async () => {\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n listener.frame(value);\n }\n listener.close({ code: 1000, reason: '' });\n } catch (error) {\n listener.close({\n code: ABNORMAL_CLOSE,\n reason: error instanceof Error ? error.message : 'stream error',\n });\n }\n };\n void pump();\n return {\n send: (frame) => {\n if (listener.isClosed()) return;\n writer\n .write(frame)\n .catch(() => listener.close({ code: ABNORMAL_CLOSE, reason: 'write failed' }));\n },\n close: (code, reason) => {\n if (listener.isClosed()) return;\n listener.close({ code: code ?? 1000, reason: reason ?? '' });\n writer.close().catch(() => undefined);\n reader.cancel().catch(() => undefined);\n },\n listen: (handlers) => listener.listen(handlers),\n };\n};\n\n// Two connected in-memory channels with asynchronous delivery, like a socket.\n// Close codes and reasons propagate to the far side.\nexport const createFrameChannelPair = (): [FrameChannelIface, FrameChannelIface] => {\n const left = createBufferedListener();\n const right = createBufferedListener();\n const deliver = (target: ReturnType<typeof createBufferedListener>, frame: WireFrame) => {\n queueMicrotask(() => target.frame(frame));\n };\n const closeBoth = (info: FrameChannelCloseIface) => {\n queueMicrotask(() => {\n left.close(info);\n right.close(info);\n });\n };\n let closed = false;\n const make = (\n peer: ReturnType<typeof createBufferedListener>,\n self: ReturnType<typeof createBufferedListener>,\n ) => ({\n send: (frame: WireFrame) => {\n if (closed) return;\n // Copy binary frames so senders may reuse buffers.\n deliver(peer, frame instanceof Uint8Array ? frame.slice() : frame);\n },\n close: (code?: number, reason?: string) => {\n if (closed) return;\n closed = true;\n closeBoth({ code: code ?? 1000, reason: reason ?? '' });\n },\n listen: (handlers: FrameChannelHandlersIface) => self.listen(handlers),\n });\n return [make(right, left), make(left, right)];\n};\n"],
|
|
5
|
+
"mappings": "AAsBA,MAAM,iBAAiB;AAEvB,MAAM,yBAAyB,MAAM;AACnC,QAAM,UAAuB,CAAC;AAC9B,MAAI,SAAwC;AAC5C,MAAI,WAA6C;AACjD,SAAO;AAAA,IACL,OAAO,CAAC,UAAqB;AAC3B,UAAI,YAAY,KAAM,SAAQ,KAAK,KAAK;AAAA,UACnC,UAAS,MAAM,KAAK;AAAA,IAC3B;AAAA,IACA,OAAO,CAAC,SAAiC;AACvC,UAAI,UAAU,KAAM;AACpB,eAAS;AACT,gBAAU,MAAM,IAAI;AAAA,IACtB;AAAA,IACA,QAAQ,CAAC,SAAoC;AAC3C,iBAAW;AACX,iBAAW,SAAS,QAAQ,OAAO,CAAC,EAAG,MAAK,MAAM,KAAK;AACvD,UAAI,UAAU,KAAM,MAAK,MAAM,MAAM;AAAA,IACvC;AAAA,IACA,UAAU,MAAM,UAAU;AAAA,EAC5B;AACF;AAwCA,MAAM,UAAU;AAEhB,MAAM,cAAc,CAAC,SAAiD;AACpE,MAAI,gBAAgB,WAAY,QAAO;AACvC,MAAI,gBAAgB,YAAa,QAAO,IAAI,WAAW,IAAI;AAC3D,MAAI,YAAY,OAAO,IAAI;AACzB,WAAO,IAAI,WAAW,KAAK,QAAQ,KAAK,YAAY,KAAK,UAAU;AACrE,MAAI,gBAAgB,KAAM,QAAO;AAEjC,MAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,QAAI,QAAQ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A,IACA,QAAQ,CAAC,aAAa,SAAS,OAAO,QAAQ;AAAA,EAChD;AACF;AAIO,MAAM,yBAAyB,MAA8C;AAClF,QAAM,OAAO,uBAAuB;AACpC,QAAM,QAAQ,uBAAuB;AACrC,QAAM,UAAU,CAAC,QAAmD,UAAqB;AACvF,mBAAe,MAAM,OAAO,MAAM,KAAK,CAAC;AAAA,EAC1C;AACA,QAAM,YAAY,CAAC,SAAiC;AAClD,mBAAe,MAAM;AACnB,WAAK,MAAM,IAAI;AACf,YAAM,MAAM,IAAI;AAAA,IAClB,CAAC;AAAA,EACH;AACA,MAAI,SAAS;AACb,QAAM,OAAO,CACX,MACA,UACI;AAAA,IACJ,MAAM,CAAC,UAAqB;AAC1B,UAAI,OAAQ;AAEZ,cAAQ,MAAM,iBAAiB,aAAa,MAAM,MAAM,IAAI,KAAK;AAAA,IACnE;AAAA,IACA,OAAO,CAAC,MAAe,WAAoB;AACzC,UAAI,OAAQ;AACZ,eAAS;AACT,gBAAU,EAAE,MAAM,QAAQ,KAAM,QAAQ,UAAU,GAAG,CAAC;AAAA,IACxD;AAAA,IACA,QAAQ,CAAC,aAAwC,KAAK,OAAO,QAAQ;AAAA,EACvE;AACA,SAAO,CAAC,KAAK,OAAO,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC;AAC9C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { ProcessInspectionOperation, inspectedProcessSchema, processInspectionDetailSchema, processInspectionPageSchema, processInspectionRequestSchema, processInspectionResultSchema, type InspectedProcessIface, type ProcessInspectionDetailIface, type ProcessInspectionPageIface, type ProcessInspectionRequestIface, type ProcessInspectionResultIface, } from '@finalai/agent-protocol/process-inspection';
|
|
2
|
+
export { decodeSandboxText, encodeSandboxText } from "./bytes.mjs";
|
|
3
|
+
export * from "./client.mjs";
|
|
4
|
+
export { createConfinedFileReader } from "./confined-files.mjs";
|
|
5
|
+
export * from "./convenience.mjs";
|
|
6
|
+
export * from "./mcp.mjs";
|
|
7
|
+
export * from "./mcp-testing.mjs";
|
|
8
|
+
export * from "./memory-sandbox.mjs";
|
|
9
|
+
export * from "./open-scope.mjs";
|
|
10
|
+
export { MAX_SANDBOX_SEED_BYTES, SANDBOX_SEED_MARKER, SANDBOX_SEED_PROTOCOL, materializeSandboxSeeds, sandboxPreparationInputs, sandboxSeedArtifact, sandboxSeedArtifactSchema, sandboxSeedFiles, sandboxSeedFilesForStart, sandboxSeedFilesSchema, sandboxSeedIdentity, } from "./seeds.mjs";
|
|
11
|
+
export * from "./server.mjs";
|
|
12
|
+
export * from "./testing.mjs";
|
|
13
|
+
export * from "./types.mjs";
|
|
14
|
+
export * from "./wire.mjs";
|
|
15
|
+
export { mapSessionPath, withSessionWorkspaceRoot } from "./workspace-root.mjs";
|
|
16
|
+
export type { MapSessionPathArgsIface } from "./workspace-root.mjs";
|
|
17
|
+
export * from "./snapshots.mjs";
|
|
18
|
+
export { SandboxEditorOperation, sandboxEditorRequestSchema, sandboxEditorResultSchema, sandboxEditorSessionSchema, type SandboxEditorRequestIface, type SandboxEditorResultIface, type SandboxEditorSessionIface, } from "./editor.mjs";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ProcessInspectionOperation,
|
|
3
|
+
inspectedProcessSchema,
|
|
4
|
+
processInspectionDetailSchema,
|
|
5
|
+
processInspectionPageSchema,
|
|
6
|
+
processInspectionRequestSchema,
|
|
7
|
+
processInspectionResultSchema
|
|
8
|
+
} from "@finalai/agent-protocol/process-inspection";
|
|
9
|
+
import { decodeSandboxText, encodeSandboxText } from "./bytes.mjs";
|
|
10
|
+
export * from "./client.mjs";
|
|
11
|
+
import { createConfinedFileReader } from "./confined-files.mjs";
|
|
12
|
+
export * from "./convenience.mjs";
|
|
13
|
+
export * from "./mcp.mjs";
|
|
14
|
+
export * from "./mcp-testing.mjs";
|
|
15
|
+
export * from "./memory-sandbox.mjs";
|
|
16
|
+
export * from "./open-scope.mjs";
|
|
17
|
+
import {
|
|
18
|
+
MAX_SANDBOX_SEED_BYTES,
|
|
19
|
+
SANDBOX_SEED_MARKER,
|
|
20
|
+
SANDBOX_SEED_PROTOCOL,
|
|
21
|
+
materializeSandboxSeeds,
|
|
22
|
+
sandboxPreparationInputs,
|
|
23
|
+
sandboxSeedArtifact,
|
|
24
|
+
sandboxSeedArtifactSchema,
|
|
25
|
+
sandboxSeedFiles,
|
|
26
|
+
sandboxSeedFilesForStart,
|
|
27
|
+
sandboxSeedFilesSchema,
|
|
28
|
+
sandboxSeedIdentity
|
|
29
|
+
} from "./seeds.mjs";
|
|
30
|
+
export * from "./server.mjs";
|
|
31
|
+
export * from "./testing.mjs";
|
|
32
|
+
export * from "./types.mjs";
|
|
33
|
+
export * from "./wire.mjs";
|
|
34
|
+
import { mapSessionPath, withSessionWorkspaceRoot } from "./workspace-root.mjs";
|
|
35
|
+
export * from "./snapshots.mjs";
|
|
36
|
+
import {
|
|
37
|
+
SandboxEditorOperation,
|
|
38
|
+
sandboxEditorRequestSchema,
|
|
39
|
+
sandboxEditorResultSchema,
|
|
40
|
+
sandboxEditorSessionSchema
|
|
41
|
+
} from "./editor.mjs";
|
|
42
|
+
export {
|
|
43
|
+
MAX_SANDBOX_SEED_BYTES,
|
|
44
|
+
ProcessInspectionOperation,
|
|
45
|
+
SANDBOX_SEED_MARKER,
|
|
46
|
+
SANDBOX_SEED_PROTOCOL,
|
|
47
|
+
SandboxEditorOperation,
|
|
48
|
+
createConfinedFileReader,
|
|
49
|
+
decodeSandboxText,
|
|
50
|
+
encodeSandboxText,
|
|
51
|
+
inspectedProcessSchema,
|
|
52
|
+
mapSessionPath,
|
|
53
|
+
materializeSandboxSeeds,
|
|
54
|
+
processInspectionDetailSchema,
|
|
55
|
+
processInspectionPageSchema,
|
|
56
|
+
processInspectionRequestSchema,
|
|
57
|
+
processInspectionResultSchema,
|
|
58
|
+
sandboxEditorRequestSchema,
|
|
59
|
+
sandboxEditorResultSchema,
|
|
60
|
+
sandboxEditorSessionSchema,
|
|
61
|
+
sandboxPreparationInputs,
|
|
62
|
+
sandboxSeedArtifact,
|
|
63
|
+
sandboxSeedArtifactSchema,
|
|
64
|
+
sandboxSeedFiles,
|
|
65
|
+
sandboxSeedFilesForStart,
|
|
66
|
+
sandboxSeedFilesSchema,
|
|
67
|
+
sandboxSeedIdentity,
|
|
68
|
+
withSessionWorkspaceRoot
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/sandbox/index.ts"],
|
|
4
|
+
"sourcesContent": ["export {\n ProcessInspectionOperation,\n inspectedProcessSchema,\n processInspectionDetailSchema,\n processInspectionPageSchema,\n processInspectionRequestSchema,\n processInspectionResultSchema,\n type InspectedProcessIface,\n type ProcessInspectionDetailIface,\n type ProcessInspectionPageIface,\n type ProcessInspectionRequestIface,\n type ProcessInspectionResultIface,\n} from '@finalai/agent-protocol/process-inspection';\nexport { decodeSandboxText, encodeSandboxText } from \"./bytes.mjs\";\nexport * from \"./client.mjs\";\nexport { createConfinedFileReader } from \"./confined-files.mjs\";\nexport * from \"./convenience.mjs\";\nexport * from \"./mcp.mjs\";\nexport * from \"./mcp-testing.mjs\";\nexport * from \"./memory-sandbox.mjs\";\nexport * from \"./open-scope.mjs\";\nexport {\n MAX_SANDBOX_SEED_BYTES,\n SANDBOX_SEED_MARKER,\n SANDBOX_SEED_PROTOCOL,\n materializeSandboxSeeds,\n sandboxPreparationInputs,\n sandboxSeedArtifact,\n sandboxSeedArtifactSchema,\n sandboxSeedFiles,\n sandboxSeedFilesForStart,\n sandboxSeedFilesSchema,\n sandboxSeedIdentity,\n} from \"./seeds.mjs\";\nexport * from \"./server.mjs\";\nexport * from \"./testing.mjs\";\nexport * from \"./types.mjs\";\nexport * from \"./wire.mjs\";\nexport { mapSessionPath, withSessionWorkspaceRoot } from \"./workspace-root.mjs\";\nexport type { MapSessionPathArgsIface } from \"./workspace-root.mjs\";\n\nexport * from \"./snapshots.mjs\";\n\nexport {\n SandboxEditorOperation,\n sandboxEditorRequestSchema,\n sandboxEditorResultSchema,\n sandboxEditorSessionSchema,\n type SandboxEditorRequestIface,\n type SandboxEditorResultIface,\n type SandboxEditorSessionIface,\n} from \"./editor.mjs\";\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AACP,SAAS,mBAAmB,yBAAyB;AACrD,cAAc;AACd,SAAS,gCAAgC;AACzC,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,gBAAgB,gCAAgC;AAGzD,cAAc;AAEd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Transport } from '@modelcontextprotocol/client';
|
|
2
|
+
import type { McpChannelIface } from "./types.mjs";
|
|
3
|
+
export interface McpChannelTransportArgsIface {
|
|
4
|
+
channel: McpChannelIface;
|
|
5
|
+
sleep?: (ms: number) => Promise<void>;
|
|
6
|
+
pollMinMs?: number;
|
|
7
|
+
pollMaxMs?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const createMcpChannelTransport: (args: McpChannelTransportArgsIface) => Transport;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isJSONRPCRequest,
|
|
3
|
+
isJSONRPCResponse,
|
|
4
|
+
parseJSONRPCMessage
|
|
5
|
+
} from "@modelcontextprotocol/client";
|
|
6
|
+
import { jsonValueSchema } from "../json.mjs";
|
|
7
|
+
const POLL_MIN_MS = 25;
|
|
8
|
+
const POLL_MAX_MS = 1e3;
|
|
9
|
+
const INTERNAL_ERROR = -32603;
|
|
10
|
+
const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
11
|
+
const createMcpChannelTransport = (args) => {
|
|
12
|
+
const sleep = args.sleep ?? defaultSleep;
|
|
13
|
+
const pollMinMs = args.pollMinMs ?? POLL_MIN_MS;
|
|
14
|
+
const pollMaxMs = args.pollMaxMs ?? POLL_MAX_MS;
|
|
15
|
+
const pending = /* @__PURE__ */ new Set();
|
|
16
|
+
let polling = null;
|
|
17
|
+
let closed = false;
|
|
18
|
+
const transport = {
|
|
19
|
+
start: async () => void 0,
|
|
20
|
+
send: async (message) => {
|
|
21
|
+
if (closed) throw new Error("the MCP channel is closed");
|
|
22
|
+
await args.channel.send(jsonValueSchema.parse(JSON.parse(JSON.stringify(message))));
|
|
23
|
+
if (isJSONRPCRequest(message)) {
|
|
24
|
+
pending.add(message.id);
|
|
25
|
+
polling ??= poll().finally(() => {
|
|
26
|
+
polling = null;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
close: async () => {
|
|
31
|
+
if (closed) return;
|
|
32
|
+
closed = true;
|
|
33
|
+
pending.clear();
|
|
34
|
+
await args.channel.close().catch(() => void 0);
|
|
35
|
+
transport.onclose?.();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const deliver = (message) => {
|
|
39
|
+
if (isJSONRPCResponse(message) && message.id != null) pending.delete(message.id);
|
|
40
|
+
transport.onmessage?.(message);
|
|
41
|
+
};
|
|
42
|
+
const failPending = (error) => {
|
|
43
|
+
transport.onerror?.(error);
|
|
44
|
+
for (const id of [...pending]) {
|
|
45
|
+
deliver({ jsonrpc: "2.0", id, error: { code: INTERNAL_ERROR, message: error.message } });
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const poll = async () => {
|
|
49
|
+
let delay = pollMinMs;
|
|
50
|
+
while (!closed && pending.size > 0) {
|
|
51
|
+
let messages;
|
|
52
|
+
try {
|
|
53
|
+
messages = await args.channel.receive();
|
|
54
|
+
} catch (error) {
|
|
55
|
+
failPending(error instanceof Error ? error : new Error(String(error)));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
for (const raw of messages) {
|
|
59
|
+
try {
|
|
60
|
+
deliver(parseJSONRPCMessage(raw));
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (messages.length > 0) {
|
|
65
|
+
delay = pollMinMs;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
await sleep(delay);
|
|
69
|
+
delay = Math.min(delay * 2, pollMaxMs);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
return transport;
|
|
73
|
+
};
|
|
74
|
+
export {
|
|
75
|
+
createMcpChannelTransport
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=mcp-channel.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/sandbox/mcp-channel.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n isJSONRPCRequest,\n isJSONRPCResponse,\n parseJSONRPCMessage,\n type JSONRPCMessage,\n type Transport,\n} from '@modelcontextprotocol/client';\nimport { jsonValueSchema } from \"../json.mjs\";\nimport type { McpChannelIface } from \"./types.mjs\";\n\n// An MCP client transport over a sandbox's MCP channel (types.ts\n// McpChannelIface). The channel only answers `receive` with what has arrived,\n// so the transport polls it while requests are outstanding, quickly at first\n// and backing off while the server is busy; an idle channel is not polled.\n\nconst POLL_MIN_MS = 25;\nconst POLL_MAX_MS = 1_000;\nconst INTERNAL_ERROR = -32603;\n\nexport interface McpChannelTransportArgsIface {\n channel: McpChannelIface;\n sleep?: (ms: number) => Promise<void>;\n pollMinMs?: number;\n pollMaxMs?: number;\n}\n\nconst defaultSleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));\n\nexport const createMcpChannelTransport = (args: McpChannelTransportArgsIface): Transport => {\n const sleep = args.sleep ?? defaultSleep;\n const pollMinMs = args.pollMinMs ?? POLL_MIN_MS;\n const pollMaxMs = args.pollMaxMs ?? POLL_MAX_MS;\n // Ids of our requests still waiting for a response.\n const pending = new Set<string | number>();\n let polling: Promise<void> | null = null;\n let closed = false;\n\n const transport: Transport = {\n start: async () => undefined,\n send: async (message) => {\n if (closed) throw new Error('the MCP channel is closed');\n await args.channel.send(jsonValueSchema.parse(JSON.parse(JSON.stringify(message))));\n if (isJSONRPCRequest(message)) {\n pending.add(message.id);\n polling ??= poll().finally(() => {\n polling = null;\n });\n }\n },\n close: async () => {\n if (closed) return;\n closed = true;\n pending.clear();\n await args.channel.close().catch(() => undefined);\n transport.onclose?.();\n },\n };\n\n const deliver = (message: JSONRPCMessage) => {\n if (isJSONRPCResponse(message) && message.id != null) pending.delete(message.id);\n transport.onmessage?.(message);\n };\n\n // A channel that failed answers every outstanding request with the error, so\n // callers fail at once instead of at their request timeout.\n const failPending = (error: Error) => {\n transport.onerror?.(error);\n for (const id of [...pending]) {\n deliver({ jsonrpc: '2.0', id, error: { code: INTERNAL_ERROR, message: error.message } });\n }\n };\n\n const poll = async (): Promise<void> => {\n let delay = pollMinMs;\n while (!closed && pending.size > 0) {\n let messages;\n try {\n messages = await args.channel.receive();\n } catch (error) {\n failPending(error instanceof Error ? error : new Error(String(error)));\n return;\n }\n for (const raw of messages) {\n try {\n deliver(parseJSONRPCMessage(raw));\n } catch {\n // Not JSON-RPC; dropped.\n }\n }\n if (messages.length > 0) {\n delay = pollMinMs;\n continue;\n }\n await sleep(delay);\n delay = Math.min(delay * 2, pollMaxMs);\n }\n };\n\n return transport;\n};\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS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AAA,IACzF;AAAA,EACF;AAEA,QAAM,OAAO,YAA2B;AACtC,QAAI,QAAQ;AACZ,WAAO,CAAC,UAAU,QAAQ,OAAO,GAAG;AAClC,UAAI;AACJ,UAAI;AACF,mBAAW,MAAM,KAAK,QAAQ,QAAQ;AAAA,MACxC,SAAS,OAAO;AACd,oBAAY,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC,CAAC;AACrE;AAAA,MACF;AACA,iBAAW,OAAO,UAAU;AAC1B,YAAI;AACF,kBAAQ,oBAAoB,GAAG,CAAC;AAAA,QAClC,QAAQ;AAAA,QAER;AAAA,MACF;AACA,UAAI,SAAS,SAAS,GAAG;AACvB,gBAAQ;AACR;AAAA,MACF;AACA,YAAM,MAAM,KAAK;AACjB,cAAQ,KAAK,IAAI,QAAQ,GAAG,SAAS;AAAA,IACvC;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type FetchLike } from '@modelcontextprotocol/client';
|
|
2
|
+
import type { CallToolResult } from '@modelcontextprotocol/server';
|
|
3
|
+
import type { JsonObject } from "../json.mjs";
|
|
4
|
+
import { type ToolDescriptorIface } from "../manifest.mjs";
|
|
5
|
+
import { type McpEndpointIface, type NetworkSandboxSessionIface, type SandboxMcpCatalogIface } from "./types.mjs";
|
|
6
|
+
export declare enum SandboxHostedServerKind {
|
|
7
|
+
ComputerUse = "computerUse",
|
|
8
|
+
Local = "local"
|
|
9
|
+
}
|
|
10
|
+
export type SandboxHostedServer = {
|
|
11
|
+
kind: SandboxHostedServerKind.ComputerUse;
|
|
12
|
+
} | {
|
|
13
|
+
kind: SandboxHostedServerKind.Local;
|
|
14
|
+
name: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const COMPUTER_USE_SERVER_NAME = "computer-use";
|
|
17
|
+
export declare const EMPTY_MCP_CATALOG: SandboxMcpCatalogIface;
|
|
18
|
+
export interface HostedToolIface {
|
|
19
|
+
name: string;
|
|
20
|
+
server: SandboxHostedServer;
|
|
21
|
+
tool: ToolDescriptorIface;
|
|
22
|
+
policyKeys: string[];
|
|
23
|
+
}
|
|
24
|
+
export declare const hostedTools: (args: {
|
|
25
|
+
catalog: SandboxMcpCatalogIface;
|
|
26
|
+
computerUse: boolean;
|
|
27
|
+
localMcp: boolean;
|
|
28
|
+
localServer?: string;
|
|
29
|
+
taken: ReadonlySet<string>;
|
|
30
|
+
}) => HostedToolIface[];
|
|
31
|
+
export interface HostedMcpConnectionsIface {
|
|
32
|
+
call(server: SandboxHostedServer, tool: string, input: JsonObject): Promise<CallToolResult>;
|
|
33
|
+
tools(server: SandboxHostedServer): Promise<ToolDescriptorIface[]>;
|
|
34
|
+
learn(sandbox: NetworkSandboxSessionIface, needed: {
|
|
35
|
+
computerUse: boolean;
|
|
36
|
+
localMcp: boolean;
|
|
37
|
+
}): Promise<Partial<SandboxMcpCatalogIface>>;
|
|
38
|
+
close(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
export declare const createHostedMcpConnections: (args: {
|
|
41
|
+
getSandbox: () => Promise<NetworkSandboxSessionIface>;
|
|
42
|
+
fetch?: FetchLike;
|
|
43
|
+
name?: string;
|
|
44
|
+
version?: string;
|
|
45
|
+
}) => HostedMcpConnectionsIface;
|
|
46
|
+
export declare const withHostedMcpEndpoints: <S extends NetworkSandboxSessionIface>(sandbox: S, endpointFor: (server: SandboxHostedServer) => McpEndpointIface) => S;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Client,
|
|
3
|
+
ProtocolError,
|
|
4
|
+
StreamableHTTPClientTransport
|
|
5
|
+
} from "@modelcontextprotocol/client";
|
|
6
|
+
import { toolDescriptorSchema } from "../manifest.mjs";
|
|
7
|
+
import { createMcpChannelTransport } from "./mcp-channel.mjs";
|
|
8
|
+
import {
|
|
9
|
+
isMcpChannelEndpoint,
|
|
10
|
+
SandboxCapability
|
|
11
|
+
} from "./types.mjs";
|
|
12
|
+
var SandboxHostedServerKind = /* @__PURE__ */ ((SandboxHostedServerKind2) => {
|
|
13
|
+
SandboxHostedServerKind2["ComputerUse"] = "computerUse";
|
|
14
|
+
SandboxHostedServerKind2["Local"] = "local";
|
|
15
|
+
return SandboxHostedServerKind2;
|
|
16
|
+
})(SandboxHostedServerKind || {});
|
|
17
|
+
const COMPUTER_USE_SERVER_NAME = "computer-use";
|
|
18
|
+
const EMPTY_MCP_CATALOG = { computerUse: null, localMcp: null };
|
|
19
|
+
const toolNameSafe = (value) => value.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
20
|
+
const hostedTools = (args) => {
|
|
21
|
+
const taken = new Set(args.taken);
|
|
22
|
+
const tools = [];
|
|
23
|
+
const claim = (preferred, fallback) => {
|
|
24
|
+
const name = taken.has(preferred) ? fallback : preferred;
|
|
25
|
+
if (taken.has(name)) return null;
|
|
26
|
+
taken.add(name);
|
|
27
|
+
return name;
|
|
28
|
+
};
|
|
29
|
+
if (args.computerUse) {
|
|
30
|
+
for (const tool of args.catalog.computerUse ?? []) {
|
|
31
|
+
const name = claim(tool.name, `computer_use_${tool.name}`);
|
|
32
|
+
if (name == null) continue;
|
|
33
|
+
tools.push({
|
|
34
|
+
name,
|
|
35
|
+
server: { kind: "computerUse" /* ComputerUse */ },
|
|
36
|
+
tool,
|
|
37
|
+
policyKeys: [SandboxCapability.ComputerUse]
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (args.localMcp) {
|
|
42
|
+
const servers = Object.entries(args.catalog.localMcp ?? {}).filter(
|
|
43
|
+
([server]) => args.localServer == null || server === args.localServer
|
|
44
|
+
);
|
|
45
|
+
const counts = /* @__PURE__ */ new Map();
|
|
46
|
+
for (const [, serverTools] of servers) {
|
|
47
|
+
for (const tool of serverTools) counts.set(tool.name, (counts.get(tool.name) ?? 0) + 1);
|
|
48
|
+
}
|
|
49
|
+
for (const [server, serverTools] of servers) {
|
|
50
|
+
for (const tool of serverTools) {
|
|
51
|
+
const prefixed = `${toolNameSafe(server)}_${tool.name}`;
|
|
52
|
+
const name = (counts.get(tool.name) ?? 0) > 1 ? claim(prefixed, prefixed) : claim(tool.name, prefixed);
|
|
53
|
+
if (name == null) continue;
|
|
54
|
+
tools.push({
|
|
55
|
+
name,
|
|
56
|
+
server: { kind: "local" /* Local */, name: server },
|
|
57
|
+
tool,
|
|
58
|
+
policyKeys: [`${server}/${tool.name}`, SandboxCapability.LocalMcp]
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return tools;
|
|
64
|
+
};
|
|
65
|
+
const serverKeyOf = (server) => server.kind === "computerUse" /* ComputerUse */ ? "computer-use" : `local\0${server.name}`;
|
|
66
|
+
const createHostedMcpConnections = (args) => {
|
|
67
|
+
const clients = /* @__PURE__ */ new Map();
|
|
68
|
+
const connect = async (endpoint) => {
|
|
69
|
+
const client = new Client({ name: args.name ?? "final-sandbox", version: args.version ?? "1" });
|
|
70
|
+
if (isMcpChannelEndpoint(endpoint)) {
|
|
71
|
+
await client.connect(createMcpChannelTransport({ channel: await endpoint.connect() }));
|
|
72
|
+
return client;
|
|
73
|
+
}
|
|
74
|
+
await client.connect(
|
|
75
|
+
new StreamableHTTPClientTransport(new URL(endpoint.url), {
|
|
76
|
+
requestInit: { headers: endpoint.headers },
|
|
77
|
+
fetch: args.fetch
|
|
78
|
+
})
|
|
79
|
+
);
|
|
80
|
+
return client;
|
|
81
|
+
};
|
|
82
|
+
const endpointOf = async (sandbox, server) => {
|
|
83
|
+
if (server.kind === "computerUse" /* ComputerUse */) {
|
|
84
|
+
if (sandbox.computerUse == null) throw new Error("this sandbox has no computer use");
|
|
85
|
+
return sandbox.computerUse();
|
|
86
|
+
}
|
|
87
|
+
if (sandbox.localMcp == null) throw new Error("this sandbox has no local MCP servers");
|
|
88
|
+
const found = (await sandbox.localMcp()).find((endpoint) => endpoint.name === server.name);
|
|
89
|
+
if (found == null) throw new Error(`this sandbox has no local MCP server ${server.name}`);
|
|
90
|
+
return found;
|
|
91
|
+
};
|
|
92
|
+
const forget = (key) => {
|
|
93
|
+
const client = clients.get(key);
|
|
94
|
+
clients.delete(key);
|
|
95
|
+
void client?.then((connected) => connected.close()).catch(() => void 0);
|
|
96
|
+
};
|
|
97
|
+
const clientFor = (key, endpoint) => {
|
|
98
|
+
const existing = clients.get(key);
|
|
99
|
+
if (existing != null) return existing;
|
|
100
|
+
const connecting = endpoint().then(connect);
|
|
101
|
+
clients.set(key, connecting);
|
|
102
|
+
connecting.catch(() => {
|
|
103
|
+
if (clients.get(key) === connecting) clients.delete(key);
|
|
104
|
+
});
|
|
105
|
+
return connecting;
|
|
106
|
+
};
|
|
107
|
+
const withClient = async (key, endpoint, work, retry = true) => {
|
|
108
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
109
|
+
try {
|
|
110
|
+
return await work(await clientFor(key, endpoint));
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (error instanceof ProtocolError) throw error;
|
|
113
|
+
forget(key);
|
|
114
|
+
if (!retry || attempt > 0) throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const toolsOf = async (client) => {
|
|
119
|
+
const tools = [];
|
|
120
|
+
let cursor;
|
|
121
|
+
do {
|
|
122
|
+
const page = await client.listTools(cursor == null ? void 0 : { cursor });
|
|
123
|
+
for (const tool of page.tools) {
|
|
124
|
+
const parsed = toolDescriptorSchema.safeParse(
|
|
125
|
+
JSON.parse(
|
|
126
|
+
JSON.stringify({
|
|
127
|
+
name: tool.name,
|
|
128
|
+
description: tool.description ?? tool.title ?? tool.name,
|
|
129
|
+
inputSchema: tool.inputSchema,
|
|
130
|
+
outputSchema: tool.outputSchema,
|
|
131
|
+
annotations: tool.annotations
|
|
132
|
+
})
|
|
133
|
+
)
|
|
134
|
+
);
|
|
135
|
+
if (parsed.success) tools.push(parsed.data);
|
|
136
|
+
}
|
|
137
|
+
cursor = page.nextCursor;
|
|
138
|
+
} while (cursor != null);
|
|
139
|
+
return tools;
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
call: async (server, tool, input) => withClient(
|
|
143
|
+
serverKeyOf(server),
|
|
144
|
+
async () => endpointOf(await args.getSandbox(), server),
|
|
145
|
+
async (client) => {
|
|
146
|
+
const result = await client.callTool({ name: tool, arguments: input });
|
|
147
|
+
const proxied = { content: result.content };
|
|
148
|
+
if (result.structuredContent != null)
|
|
149
|
+
proxied.structuredContent = result.structuredContent;
|
|
150
|
+
if (result.isError === true) proxied.isError = true;
|
|
151
|
+
return proxied;
|
|
152
|
+
},
|
|
153
|
+
false
|
|
154
|
+
),
|
|
155
|
+
tools: async (server) => withClient(
|
|
156
|
+
serverKeyOf(server),
|
|
157
|
+
async () => endpointOf(await args.getSandbox(), server),
|
|
158
|
+
toolsOf
|
|
159
|
+
),
|
|
160
|
+
learn: async (sandbox, needed) => {
|
|
161
|
+
const learned = {};
|
|
162
|
+
if (needed.computerUse && sandbox.computerUse != null) {
|
|
163
|
+
const server = { kind: "computerUse" /* ComputerUse */ };
|
|
164
|
+
learned.computerUse = await withClient(
|
|
165
|
+
serverKeyOf(server),
|
|
166
|
+
() => endpointOf(sandbox, server),
|
|
167
|
+
toolsOf
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
if (needed.localMcp && sandbox.localMcp != null) {
|
|
171
|
+
const local = {};
|
|
172
|
+
for (const endpoint of await sandbox.localMcp()) {
|
|
173
|
+
const server = {
|
|
174
|
+
kind: "local" /* Local */,
|
|
175
|
+
name: endpoint.name
|
|
176
|
+
};
|
|
177
|
+
try {
|
|
178
|
+
local[endpoint.name] = await withClient(
|
|
179
|
+
serverKeyOf(server),
|
|
180
|
+
async () => endpoint,
|
|
181
|
+
toolsOf
|
|
182
|
+
);
|
|
183
|
+
} catch {
|
|
184
|
+
local[endpoint.name] = [];
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
learned.localMcp = local;
|
|
188
|
+
}
|
|
189
|
+
return learned;
|
|
190
|
+
},
|
|
191
|
+
close: async () => {
|
|
192
|
+
const open = [...clients.values()];
|
|
193
|
+
clients.clear();
|
|
194
|
+
await Promise.all(
|
|
195
|
+
open.map((client) => client.then((connected) => connected.close()).catch(() => void 0))
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
const withHostedMcpEndpoints = (sandbox, endpointFor) => {
|
|
201
|
+
const addressed = { ...sandbox };
|
|
202
|
+
if (sandbox.computerUse != null) {
|
|
203
|
+
addressed.computerUse = async () => endpointFor({ kind: "computerUse" /* ComputerUse */ });
|
|
204
|
+
}
|
|
205
|
+
const localMcp = sandbox.localMcp;
|
|
206
|
+
if (localMcp != null) {
|
|
207
|
+
addressed.localMcp = async () => (await localMcp()).map(
|
|
208
|
+
(endpoint) => endpointFor({ kind: "local" /* Local */, name: endpoint.name })
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
return addressed;
|
|
212
|
+
};
|
|
213
|
+
export {
|
|
214
|
+
COMPUTER_USE_SERVER_NAME,
|
|
215
|
+
EMPTY_MCP_CATALOG,
|
|
216
|
+
SandboxHostedServerKind,
|
|
217
|
+
createHostedMcpConnections,
|
|
218
|
+
hostedTools,
|
|
219
|
+
withHostedMcpEndpoints
|
|
220
|
+
};
|
|
221
|
+
//# sourceMappingURL=mcp-hosted.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/sandbox/mcp-hosted.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n Client,\n ProtocolError,\n StreamableHTTPClientTransport,\n type FetchLike,\n} from '@modelcontextprotocol/client';\nimport type { CallToolResult } from '@modelcontextprotocol/server';\nimport type { JsonObject } from \"../json.mjs\";\nimport { toolDescriptorSchema, type ToolDescriptorIface } from \"../manifest.mjs\";\nimport { createMcpChannelTransport } from \"./mcp-channel.mjs\";\nimport {\n isMcpChannelEndpoint,\n SandboxCapability,\n type McpEndpointIface,\n type NetworkSandboxSessionIface,\n type SandboxMcpCatalogIface,\n type SandboxMcpEndpoint,\n} from \"./types.mjs\";\n\n// A sandbox's hosted MCP servers (its computer-use server and local MCP\n// servers) as the MCP projection serves them: their own tools, by their own\n// names, proxied through the handle's `computerUse()` / `localMcp()`. Catalogs\n// come from the provider before anything starts when it can give them, and\n// are otherwise learned from the servers once the sandbox is attached.\n\nexport enum SandboxHostedServerKind {\n ComputerUse = 'computerUse',\n Local = 'local',\n}\n\nexport type SandboxHostedServer =\n | { kind: SandboxHostedServerKind.ComputerUse }\n | { kind: SandboxHostedServerKind.Local; name: string };\n\nexport const COMPUTER_USE_SERVER_NAME = 'computer-use';\n\nexport const EMPTY_MCP_CATALOG: SandboxMcpCatalogIface = { computerUse: null, localMcp: null };\n\n// One projected tool of a hosted server.\nexport interface HostedToolIface {\n // The name the projection lists: the tool's own, prefixed only on a collision.\n name: string;\n server: SandboxHostedServer;\n tool: ToolDescriptorIface;\n // toolPolicy keys after `name`, most specific first.\n policyKeys: string[];\n}\n\nconst toolNameSafe = (value: string): string => value.replace(/[^A-Za-z0-9_-]/g, '_');\n\n// Hosted tools under the names the projection lists. Computer-use tools keep\n// their names unless a built-in tool has it (`computer_use_<name>`); a local\n// tool keeps its name unless something else has it or another local server\n// has the same tool (`<server>_<name>`).\nexport const hostedTools = (args: {\n catalog: SandboxMcpCatalogIface;\n computerUse: boolean;\n localMcp: boolean;\n // Only this local server (a per-server endpoint).\n localServer?: string;\n taken: ReadonlySet<string>;\n}): HostedToolIface[] => {\n const taken = new Set(args.taken);\n const tools: HostedToolIface[] = [];\n const claim = (preferred: string, fallback: string): string | null => {\n const name = taken.has(preferred) ? fallback : preferred;\n if (taken.has(name)) return null;\n taken.add(name);\n return name;\n };\n if (args.computerUse) {\n for (const tool of args.catalog.computerUse ?? []) {\n const name = claim(tool.name, `computer_use_${tool.name}`);\n if (name == null) continue;\n tools.push({\n name,\n server: { kind: SandboxHostedServerKind.ComputerUse },\n tool,\n policyKeys: [SandboxCapability.ComputerUse],\n });\n }\n }\n if (args.localMcp) {\n const servers = Object.entries(args.catalog.localMcp ?? {}).filter(\n ([server]) => args.localServer == null || server === args.localServer,\n );\n const counts = new Map<string, number>();\n for (const [, serverTools] of servers) {\n for (const tool of serverTools) counts.set(tool.name, (counts.get(tool.name) ?? 0) + 1);\n }\n for (const [server, serverTools] of servers) {\n for (const tool of serverTools) {\n const prefixed = `${toolNameSafe(server)}_${tool.name}`;\n const name =\n (counts.get(tool.name) ?? 0) > 1 ? claim(prefixed, prefixed) : claim(tool.name, prefixed);\n if (name == null) continue;\n tools.push({\n name,\n server: { kind: SandboxHostedServerKind.Local, name: server },\n tool,\n policyKeys: [`${server}/${tool.name}`, SandboxCapability.LocalMcp],\n });\n }\n }\n }\n return tools;\n};\n\nconst serverKeyOf = (server: SandboxHostedServer): string =>\n server.kind === SandboxHostedServerKind.ComputerUse\n ? 'computer-use'\n : `local\\u0000${server.name}`;\n\nexport interface HostedMcpConnectionsIface {\n call(server: SandboxHostedServer, tool: string, input: JsonObject): Promise<CallToolResult>;\n // One server's live tools, over the connection its calls use.\n tools(server: SandboxHostedServer): Promise<ToolDescriptorIface[]>;\n // Reads the catalogs `needed` asks for (null fields) from the live sandbox.\n learn(\n sandbox: NetworkSandboxSessionIface,\n needed: { computerUse: boolean; localMcp: boolean },\n ): Promise<Partial<SandboxMcpCatalogIface>>;\n close(): Promise<void>;\n}\n\nexport const createHostedMcpConnections = (args: {\n getSandbox: () => Promise<NetworkSandboxSessionIface>;\n fetch?: FetchLike;\n name?: string;\n version?: string;\n}): HostedMcpConnectionsIface => {\n const clients = new Map<string, Promise<Client>>();\n\n const connect = async (endpoint: SandboxMcpEndpoint): Promise<Client> => {\n const client = new Client({ name: args.name ?? 'final-sandbox', version: args.version ?? '1' });\n if (isMcpChannelEndpoint(endpoint)) {\n await client.connect(createMcpChannelTransport({ channel: await endpoint.connect() }));\n return client;\n }\n await client.connect(\n new StreamableHTTPClientTransport(new URL(endpoint.url), {\n requestInit: { headers: endpoint.headers },\n fetch: args.fetch,\n }),\n );\n return client;\n };\n\n const endpointOf = async (\n sandbox: NetworkSandboxSessionIface,\n server: SandboxHostedServer,\n ): Promise<SandboxMcpEndpoint> => {\n if (server.kind === SandboxHostedServerKind.ComputerUse) {\n if (sandbox.computerUse == null) throw new Error('this sandbox has no computer use');\n return sandbox.computerUse();\n }\n if (sandbox.localMcp == null) throw new Error('this sandbox has no local MCP servers');\n const found = (await sandbox.localMcp()).find((endpoint) => endpoint.name === server.name);\n if (found == null) throw new Error(`this sandbox has no local MCP server ${server.name}`);\n return found;\n };\n\n const forget = (key: string) => {\n const client = clients.get(key);\n clients.delete(key);\n void client?.then((connected) => connected.close()).catch(() => undefined);\n };\n\n const clientFor = (key: string, endpoint: () => Promise<SandboxMcpEndpoint>): Promise<Client> => {\n const existing = clients.get(key);\n if (existing != null) return existing;\n const connecting = endpoint().then(connect);\n clients.set(key, connecting);\n connecting.catch(() => {\n if (clients.get(key) === connecting) clients.delete(key);\n });\n return connecting;\n };\n\n // One retry on a fresh connection: a parked or restarted server drops the old\n // one. An error the server answered with leaves the connection as it is.\n const withClient = async <T>(\n key: string,\n endpoint: () => Promise<SandboxMcpEndpoint>,\n work: (client: Client) => Promise<T>,\n retry = true,\n ): Promise<T> => {\n for (let attempt = 0; ; attempt += 1) {\n try {\n return await work(await clientFor(key, endpoint));\n } catch (error) {\n if (error instanceof ProtocolError) throw error;\n forget(key);\n if (!retry || attempt > 0) throw error;\n }\n }\n };\n\n const toolsOf = async (client: Client): Promise<ToolDescriptorIface[]> => {\n const tools: ToolDescriptorIface[] = [];\n let cursor: string | undefined;\n do {\n const page = await client.listTools(cursor == null ? undefined : { cursor });\n for (const tool of page.tools) {\n const parsed = toolDescriptorSchema.safeParse(\n JSON.parse(\n JSON.stringify({\n name: tool.name,\n description: tool.description ?? tool.title ?? tool.name,\n inputSchema: tool.inputSchema,\n outputSchema: tool.outputSchema,\n annotations: tool.annotations,\n }),\n ),\n );\n if (parsed.success) tools.push(parsed.data);\n }\n cursor = page.nextCursor;\n } while (cursor != null);\n return tools;\n };\n\n return {\n call: async (server, tool, input) =>\n withClient(\n serverKeyOf(server),\n async () => endpointOf(await args.getSandbox(), server),\n async (client) => {\n const result = await client.callTool({ name: tool, arguments: input });\n const proxied: CallToolResult = { content: result.content };\n if (result.structuredContent != null)\n proxied.structuredContent = result.structuredContent;\n if (result.isError === true) proxied.isError = true;\n return proxied;\n },\n false,\n ),\n tools: async (server) =>\n withClient(\n serverKeyOf(server),\n async () => endpointOf(await args.getSandbox(), server),\n toolsOf,\n ),\n learn: async (sandbox, needed) => {\n const learned: Partial<SandboxMcpCatalogIface> = {};\n if (needed.computerUse && sandbox.computerUse != null) {\n const server: SandboxHostedServer = { kind: SandboxHostedServerKind.ComputerUse };\n learned.computerUse = await withClient(\n serverKeyOf(server),\n () => endpointOf(sandbox, server),\n toolsOf,\n );\n }\n if (needed.localMcp && sandbox.localMcp != null) {\n const local: Record<string, ToolDescriptorIface[]> = {};\n for (const endpoint of await sandbox.localMcp()) {\n const server: SandboxHostedServer = {\n kind: SandboxHostedServerKind.Local,\n name: endpoint.name,\n };\n try {\n local[endpoint.name] = await withClient(\n serverKeyOf(server),\n async () => endpoint,\n toolsOf,\n );\n } catch {\n // A local server that fails to start lists nothing; the rest still do.\n local[endpoint.name] = [];\n }\n }\n learned.localMcp = local;\n }\n return learned;\n },\n close: async () => {\n const open = [...clients.values()];\n clients.clear();\n await Promise.all(\n open.map((client) => client.then((connected) => connected.close()).catch(() => undefined)),\n );\n },\n };\n};\n\n// A handle whose hosted servers are re-addressed: `computerUse()` and\n// `localMcp()` return HTTP endpoints where the host of the handle serves them\n// (its per-binding MCP addresses), so they can cross the handle RPC and the\n// sandbox's own endpoints and credentials never leave the host.\nexport const withHostedMcpEndpoints = <S extends NetworkSandboxSessionIface>(\n sandbox: S,\n endpointFor: (server: SandboxHostedServer) => McpEndpointIface,\n): S => {\n const addressed: S = { ...sandbox };\n if (sandbox.computerUse != null) {\n addressed.computerUse = async () => endpointFor({ kind: SandboxHostedServerKind.ComputerUse });\n }\n const localMcp = sandbox.localMcp;\n if (localMcp != null) {\n addressed.localMcp = async () =>\n (await localMcp()).map((endpoint) =>\n endpointFor({ kind: SandboxHostedServerKind.Local, name: endpoint.name }),\n );\n }\n return addressed;\n};\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAGP,SAAS,4BAAsD;AAC/D,SAAS,iCAAiC;AAC1C;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AAQA,IAAK,0BAAL,kBAAKA,6BAAL;AACL,EAAAA,yBAAA,iBAAc;AACd,EAAAA,yBAAA,WAAQ;AAFE,SAAAA;AAAA,GAAA;AASL,MAAM,2BAA2B;AAEjC,MAAM,oBAA4C,EAAE,aAAa,MAAM,UAAU,KAAK;AAY7F,MAAM,eAAe,CAAC,UAA0B,MAAM,QAAQ,mBAAmB,GAAG;AAM7E,MAAM,cAAc,CAAC,SAOH;AACvB,QAAM,QAAQ,IAAI,IAAI,KAAK,KAAK;AAChC,QAAM,QAA2B,CAAC;AAClC,QAAM,QAAQ,CAAC,WAAmB,aAAoC;AACpE,UAAM,OAAO,MAAM,IAAI,SAAS,IAAI,WAAW;AAC/C,QAAI,MAAM,IAAI,IAAI,EAAG,QAAO;AAC5B,UAAM,IAAI,IAAI;AACd,WAAO;AAAA,EACT;AACA,MAAI,KAAK,aAAa;AACpB,eAAW,QAAQ,KAAK,QAAQ,eAAe,CAAC,GAAG;AACjD,YAAM,OAAO,MAAM,KAAK,MAAM,gBAAgB,KAAK,IAAI,EAAE;AACzD,UAAI,QAAQ,KAAM;AAClB,YAAM,KAAK;AAAA,QACT;AAAA,QACA,QAAQ,EAAE,MAAM,gCAAoC;AAAA,QACpD;AAAA,QACA,YAAY,CAAC,kBAAkB,WAAW;AAA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M,WAAW,QAAQ;AACzB,MAAI,YAAY,MAAM;AACpB,cAAU,WAAW,aAClB,MAAM,SAAS,GAAG;AAAA,MAAI,CAAC,aACtB,YAAY,EAAE,MAAM,qBAA+B,MAAM,SAAS,KAAK,CAAC;AAAA,IAC1E;AAAA,EACJ;AACA,SAAO;AACT;",
|
|
6
|
+
"names": ["SandboxHostedServerKind"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { SandboxEntryType, type SandboxSessionIface } from "./types.mjs";
|
|
2
|
+
export interface WalkLimitsIface {
|
|
3
|
+
maxEntries: number;
|
|
4
|
+
maxFileBytes: number;
|
|
5
|
+
}
|
|
6
|
+
export declare const DEFAULT_WALK_LIMITS: WalkLimitsIface;
|
|
7
|
+
export declare const globToRegExp: (glob: string) => {
|
|
8
|
+
test(input: string): boolean;
|
|
9
|
+
};
|
|
10
|
+
export interface WalkEntryIface {
|
|
11
|
+
path: string;
|
|
12
|
+
relative: string;
|
|
13
|
+
type: SandboxEntryType;
|
|
14
|
+
size: number | null;
|
|
15
|
+
}
|
|
16
|
+
export declare const walkTree: (sandbox: Pick<SandboxSessionIface, "readDir">, root: string, options: {
|
|
17
|
+
limits?: WalkLimitsIface;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
onEntry: (entry: WalkEntryIface) => boolean | Promise<boolean>;
|
|
20
|
+
}) => Promise<{
|
|
21
|
+
truncated: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
export declare const globFiles: (args: {
|
|
24
|
+
sandbox: Pick<SandboxSessionIface, "readDir">;
|
|
25
|
+
cwd: string;
|
|
26
|
+
pattern: string;
|
|
27
|
+
path?: string;
|
|
28
|
+
maxResults: number;
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
}) => Promise<{
|
|
31
|
+
paths: string[];
|
|
32
|
+
truncated: boolean;
|
|
33
|
+
}>;
|
|
34
|
+
export interface GrepMatchIface {
|
|
35
|
+
path: string;
|
|
36
|
+
line: number;
|
|
37
|
+
text: string;
|
|
38
|
+
}
|
|
39
|
+
export declare const grepFiles: (args: {
|
|
40
|
+
sandbox: Pick<SandboxSessionIface, "readDir" | "readTextFile" | "stat">;
|
|
41
|
+
cwd: string;
|
|
42
|
+
pattern: string;
|
|
43
|
+
path?: string;
|
|
44
|
+
glob?: string;
|
|
45
|
+
ignoreCase?: boolean;
|
|
46
|
+
maxResults: number;
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
}) => Promise<{
|
|
49
|
+
matches: GrepMatchIface[];
|
|
50
|
+
truncated: boolean;
|
|
51
|
+
}>;
|