@lamplitisles/dsh-nanocodex 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +65 -0
- package/NOTICE +2 -0
- package/README.md +182 -0
- package/THIRD_PARTY_NOTICES.md +29 -0
- package/cordis.patch.yml +52 -0
- package/dist/index.d.ts +435 -0
- package/dist/index.js +3405 -0
- package/dist/standard-preset.d.ts +7 -0
- package/dist/standard-preset.js +25 -0
- package/engine-release.json +14 -0
- package/package.json +119 -0
- package/presets/standard/agent.cordis.yml +6 -0
- package/presets/standard/preset.yml +2 -0
- package/vendor/nanocodex/README.md +1344 -0
- package/vendor/nanocodex/actions/events.d.mts +10 -0
- package/vendor/nanocodex/actions/events.mjs +163 -0
- package/vendor/nanocodex/actions/index.d.mts +13 -0
- package/vendor/nanocodex/actions/index.mjs +35 -0
- package/vendor/nanocodex/actions/session.d.mts +66 -0
- package/vendor/nanocodex/actions/session.mjs +59 -0
- package/vendor/nanocodex/actions/turn.d.mts +59 -0
- package/vendor/nanocodex/actions/turn.mjs +37 -0
- package/vendor/nanocodex/actions/voice.d.mts +22 -0
- package/vendor/nanocodex/actions/voice.mjs +50 -0
- package/vendor/nanocodex/browser/Agent.d.mts +55 -0
- package/vendor/nanocodex/browser/Agent.mjs +11 -0
- package/vendor/nanocodex/browser/ChatGptSubscription.d.mts +7 -0
- package/vendor/nanocodex/browser/ChatGptSubscription.mjs +19 -0
- package/vendor/nanocodex/browser/InlineAgent.mjs +266 -0
- package/vendor/nanocodex/browser/Transport.d.mts +74 -0
- package/vendor/nanocodex/browser/Transport.mjs +61 -0
- package/vendor/nanocodex/browser/Voice.d.mts +71 -0
- package/vendor/nanocodex/browser/Voice.mjs +291 -0
- package/vendor/nanocodex/browser/VoiceSession.mjs +688 -0
- package/vendor/nanocodex/browser/WorkerAgent.d.mts +65 -0
- package/vendor/nanocodex/browser/WorkerAgent.mjs +1472 -0
- package/vendor/nanocodex/browser/agent.worker.mjs +3 -0
- package/vendor/nanocodex/browser/config.d.mts +36 -0
- package/vendor/nanocodex/browser/config.mjs +439 -0
- package/vendor/nanocodex/browser/engine.mjs +13 -0
- package/vendor/nanocodex/browser/harness.mjs +55 -0
- package/vendor/nanocodex/browser/host.d.mts +83 -0
- package/vendor/nanocodex/browser/host.mjs +555 -0
- package/vendor/nanocodex/browser/hostManagedWebSocket.d.mts +14 -0
- package/vendor/nanocodex/browser/hostManagedWebSocket.mjs +110 -0
- package/vendor/nanocodex/browser/index.d.mts +92 -0
- package/vendor/nanocodex/browser/index.mjs +23 -0
- package/vendor/nanocodex/browser/indexeddb-durability-store.mjs +197 -0
- package/vendor/nanocodex/browser/workspace.d.mts +16 -0
- package/vendor/nanocodex/browser/workspace.mjs +107 -0
- package/vendor/nanocodex/cloud/Client.d.mts +83 -0
- package/vendor/nanocodex/cloud/Client.mjs +231 -0
- package/vendor/nanocodex/cloud/Decorator.d.mts +31 -0
- package/vendor/nanocodex/cloud/Decorator.mjs +37 -0
- package/vendor/nanocodex/cloud/Dialog.d.mts +113 -0
- package/vendor/nanocodex/cloud/Dialog.mjs +366 -0
- package/vendor/nanocodex/cloud/Errors.d.mts +22 -0
- package/vendor/nanocodex/cloud/Errors.mjs +39 -0
- package/vendor/nanocodex/cloud/Principal.d.mts +26 -0
- package/vendor/nanocodex/cloud/Principal.mjs +88 -0
- package/vendor/nanocodex/cloud/RemoteProvider.mjs +88 -0
- package/vendor/nanocodex/cloud/Transport.d.mts +47 -0
- package/vendor/nanocodex/cloud/Transport.mjs +454 -0
- package/vendor/nanocodex/cloud/actions/account.d.mts +9 -0
- package/vendor/nanocodex/cloud/actions/account.mjs +19 -0
- package/vendor/nanocodex/cloud/actions/agent.d.mts +18 -0
- package/vendor/nanocodex/cloud/actions/agent.mjs +428 -0
- package/vendor/nanocodex/cloud/actions/connection.d.mts +133 -0
- package/vendor/nanocodex/cloud/actions/connection.mjs +580 -0
- package/vendor/nanocodex/cloud/actions/grant.d.mts +10 -0
- package/vendor/nanocodex/cloud/actions/grant.mjs +12 -0
- package/vendor/nanocodex/cloud/actions/index.d.mts +7 -0
- package/vendor/nanocodex/cloud/actions/index.mjs +7 -0
- package/vendor/nanocodex/cloud/actions/machineUsd.d.mts +23 -0
- package/vendor/nanocodex/cloud/actions/machineUsd.mjs +37 -0
- package/vendor/nanocodex/cloud/actions/model.d.mts +12 -0
- package/vendor/nanocodex/cloud/actions/model.mjs +50 -0
- package/vendor/nanocodex/cloud/actions/mpp.d.mts +28 -0
- package/vendor/nanocodex/cloud/actions/mpp.mjs +39 -0
- package/vendor/nanocodex/cloud/index.d.mts +30 -0
- package/vendor/nanocodex/cloud/index.mjs +9 -0
- package/vendor/nanocodex/cloud/internal.mjs +533 -0
- package/vendor/nanocodex/cloud/mercator.mjs +108 -0
- package/vendor/nanocodex/cloud/server/HostPrincipal.d.mts +34 -0
- package/vendor/nanocodex/cloud/server/HostPrincipal.mjs +202 -0
- package/vendor/nanocodex/cloud/server/index.d.mts +1 -0
- package/vendor/nanocodex/cloud/server/index.mjs +1 -0
- package/vendor/nanocodex/cloud/types.d.mts +211 -0
- package/vendor/nanocodex/cloudflare/Agent.d.mts +133 -0
- package/vendor/nanocodex/cloudflare/Agent.mjs +811 -0
- package/vendor/nanocodex/cloudflare/egress-subject.mjs +19 -0
- package/vendor/nanocodex/cloudflare/egress.d.mts +41 -0
- package/vendor/nanocodex/cloudflare/egress.mjs +119 -0
- package/vendor/nanocodex/cloudflare/event-socket.mjs +316 -0
- package/vendor/nanocodex/cloudflare/index.d.mts +7 -0
- package/vendor/nanocodex/cloudflare/index.mjs +6 -0
- package/vendor/nanocodex/host/Agent.d.mts +55 -0
- package/vendor/nanocodex/host/Agent.mjs +1 -0
- package/vendor/nanocodex/host/index.d.mts +82 -0
- package/vendor/nanocodex/host/index.mjs +10 -0
- package/vendor/nanocodex/index.d.mts +81 -0
- package/vendor/nanocodex/index.mjs +12 -0
- package/vendor/nanocodex/internal.mjs +1275 -0
- package/vendor/nanocodex/managed/Agent.d.mts +380 -0
- package/vendor/nanocodex/managed/Agent.mjs +1694 -0
- package/vendor/nanocodex/managed/ManagedError.d.mts +9 -0
- package/vendor/nanocodex/managed/ManagedError.mjs +8 -0
- package/vendor/nanocodex/managed/README.md +241 -0
- package/vendor/nanocodex/managed/Voice.mjs +202 -0
- package/vendor/nanocodex/managed/index.d.mts +20 -0
- package/vendor/nanocodex/managed/index.mjs +2 -0
- package/vendor/nanocodex/managed/internal.mjs +119 -0
- package/vendor/nanocodex/node/Agent.d.mts +50 -0
- package/vendor/nanocodex/node/Agent.mjs +203 -0
- package/vendor/nanocodex/node/ChatGptSubscription.d.mts +9 -0
- package/vendor/nanocodex/node/ChatGptSubscription.mjs +17 -0
- package/vendor/nanocodex/node/Transport.d.mts +44 -0
- package/vendor/nanocodex/node/Transport.mjs +46 -0
- package/vendor/nanocodex/node/host.mjs +731 -0
- package/vendor/nanocodex/node/index.d.mts +73 -0
- package/vendor/nanocodex/node/index.mjs +17 -0
- package/vendor/nanocodex/node/workspace.d.mts +10 -0
- package/vendor/nanocodex/node/workspace.mjs +198 -0
- package/vendor/nanocodex/package.json +200 -0
- package/vendor/nanocodex/pkg-node/nanocodex.d.ts +675 -0
- package/vendor/nanocodex/pkg-node/nanocodex.js +2628 -0
- package/vendor/nanocodex/pkg-node/nanocodex_bg.wasm.d.ts +105 -0
- package/vendor/nanocodex/pkg-node/package.json +1 -0
- package/vendor/nanocodex/pkg-web/.nanocodex-bindgen-stamp +6 -0
- package/vendor/nanocodex/pkg-web/nanocodex-build.json +1 -0
- package/vendor/nanocodex/pkg-web/nanocodex.d.ts +805 -0
- package/vendor/nanocodex/pkg-web/nanocodex.js +2714 -0
- package/vendor/nanocodex/pkg-web/nanocodex_bg.js +2615 -0
- package/vendor/nanocodex/pkg-web/nanocodex_bg.wasm +0 -0
- package/vendor/nanocodex/pkg-web/nanocodex_bg.wasm.d.ts +105 -0
- package/vendor/nanocodex/pkg-web/nanocodex_worker.js +9 -0
- package/vendor/nanocodex/pkg-web/package.json +1 -0
- package/vendor/nanocodex/runtime/chatgpt-subscription.mjs +212 -0
- package/vendor/nanocodex/runtime/cloudflare-durability-store.d.mts +26 -0
- package/vendor/nanocodex/runtime/cloudflare-durability-store.mjs +168 -0
- package/vendor/nanocodex/runtime/code-evaluator.worker.mjs +137 -0
- package/vendor/nanocodex/runtime/code-runtime.mjs +1 -0
- package/vendor/nanocodex/runtime/durability-store.d.mts +85 -0
- package/vendor/nanocodex/runtime/durability-store.mjs +631 -0
- package/vendor/nanocodex/runtime/durability.mjs +153 -0
- package/vendor/nanocodex/runtime/managed-transport.mjs +460 -0
- package/vendor/nanocodex/runtime/mcp-runtime.mjs +534 -0
- package/vendor/nanocodex/runtime/postgres-durability-store.d.mts +64 -0
- package/vendor/nanocodex/runtime/postgres-durability-store.mjs +532 -0
- package/vendor/nanocodex/runtime/quickjs-evaluator.d.mts +17 -0
- package/vendor/nanocodex/runtime/quickjs-evaluator.mjs +236 -0
- package/vendor/nanocodex/runtime/responses-transport.mjs +22 -0
- package/vendor/nanocodex/runtime/subagents.d.mts +107 -0
- package/vendor/nanocodex/runtime/subagents.mjs +54 -0
- package/vendor/nanocodex/runtime/subscription-store.d.mts +8 -0
- package/vendor/nanocodex/runtime/subscription-store.mjs +42 -0
- package/vendor/nanocodex/runtime/tempo-provider.d.mts +125 -0
- package/vendor/nanocodex/runtime/tempo-provider.mjs +264 -0
- package/vendor/nanocodex/runtime/tool-configuration.mjs +1 -0
- package/vendor/nanocodex/runtime/tool-router.mjs +1 -0
- package/vendor/nanocodex/runtime/utf8.mjs +1 -0
- package/vendor/nanocodex/runtime/worker-evaluator.mjs +162 -0
- package/vendor/nanocodex/runtime/workspace.d.mts +1 -0
- package/vendor/nanocodex/runtime/workspace.mjs +1 -0
- package/vendor/nanocodex/tools/Tools.d.mts +56 -0
- package/vendor/nanocodex/tools/Tools.mjs +136 -0
- package/vendor/nanocodex/tools/artifact.d.mts +1 -0
- package/vendor/nanocodex/tools/artifact.mjs +1 -0
- package/vendor/nanocodex/tools/attachment.mjs +1 -0
- package/vendor/nanocodex/tools/bash.d.mts +1 -0
- package/vendor/nanocodex/tools/bash.mjs +1 -0
- package/vendor/nanocodex/tools/browser/accountInfo.mjs +795 -0
- package/vendor/nanocodex/tools/browser/browserBuffer.mjs +18 -0
- package/vendor/nanocodex/tools/browser/browserCompiler.mjs +155 -0
- package/vendor/nanocodex/tools/browser/browserEgress.mjs +161 -0
- package/vendor/nanocodex/tools/browser/browserPython.mjs +133 -0
- package/vendor/nanocodex/tools/browser/browserShell.mjs +1075 -0
- package/vendor/nanocodex/tools/browser/browserSprintf.mjs +4 -0
- package/vendor/nanocodex/tools/browser/browserSsh.mjs +201 -0
- package/vendor/nanocodex/tools/browser/browserZlib.mjs +136 -0
- package/vendor/nanocodex/tools/browser/compiler.worker.mjs +160 -0
- package/vendor/nanocodex/tools/browser/devTunnelsSshBrowser.mjs +13 -0
- package/vendor/nanocodex/tools/browser/index.d.mts +209 -0
- package/vendor/nanocodex/tools/browser/index.mjs +174 -0
- package/vendor/nanocodex/tools/browser/opfsGit.mjs +248 -0
- package/vendor/nanocodex/tools/browser/python.worker.mjs +114 -0
- package/vendor/nanocodex/tools/browser/threadGit.mjs +197 -0
- package/vendor/nanocodex/tools/browser/unsupportedNodeRsa.mjs +5 -0
- package/vendor/nanocodex/tools/browser/workspace.mjs +83 -0
- package/vendor/nanocodex/tools/dataset.d.mts +1 -0
- package/vendor/nanocodex/tools/dataset.mjs +1 -0
- package/vendor/nanocodex/tools/datasetContract.mjs +1 -0
- package/vendor/nanocodex/tools/datasetEngine.mjs +1 -0
- package/vendor/nanocodex/tools/hostedCatalog.d.mts +1 -0
- package/vendor/nanocodex/tools/hostedCatalog.mjs +1 -0
- package/vendor/nanocodex/tools/index.d.mts +49 -0
- package/vendor/nanocodex/tools/index.mjs +19 -0
- package/vendor/nanocodex/tools/namedTool.mjs +1 -0
- package/vendor/nanocodex/tools/repository-workspace.d.mts +1 -0
- package/vendor/nanocodex/tools/repository-workspace.mjs +1 -0
- package/vendor/nanocodex/tools/ssh.d.mts +1 -0
- package/vendor/nanocodex/tools/ssh.mjs +1 -0
- package/vendor/nanocodex/tools/standard.mjs +1 -0
- package/vendor/nanocodex/tools/standardDescriptions.mjs +1 -0
- package/vendor/nanocodex/types.d.mts +663 -0
- package/vendor/nanocodex/wasm.d.mts +4 -0
- package/vendor/nanocodex/worker/ChatGptSubscription.d.mts +9 -0
- package/vendor/nanocodex/worker/ChatGptSubscription.mjs +29 -0
- package/vendor/nanocodex/worker/index.d.mts +18 -0
- package/vendor/nanocodex/worker/index.mjs +5 -0
- package/vendor/nanocodex-tools/README.md +65 -0
- package/vendor/nanocodex-tools/dist/hosted/app-tool-catalog.d.ts +7 -0
- package/vendor/nanocodex-tools/dist/hosted/app-tool-catalog.js +14 -0
- package/vendor/nanocodex-tools/dist/hosted/broker-core.d.ts +172 -0
- package/vendor/nanocodex-tools/dist/hosted/broker-core.js +1278 -0
- package/vendor/nanocodex-tools/dist/hosted/index.d.ts +3 -0
- package/vendor/nanocodex-tools/dist/hosted/index.js +3 -0
- package/vendor/nanocodex-tools/dist/hosted/protocol.d.ts +120 -0
- package/vendor/nanocodex-tools/dist/hosted/protocol.js +415 -0
- package/vendor/nanocodex-tools/dist/index.d.ts +19 -0
- package/vendor/nanocodex-tools/dist/index.js +14 -0
- package/vendor/nanocodex-tools/dist/memory.d.ts +204 -0
- package/vendor/nanocodex-tools/dist/memory.js +411 -0
- package/vendor/nanocodex-tools/dist/namespace.d.ts +87 -0
- package/vendor/nanocodex-tools/dist/namespace.js +338 -0
- package/vendor/nanocodex-tools/dist/repository-archive.d.ts +4 -0
- package/vendor/nanocodex-tools/dist/repository-archive.js +104 -0
- package/vendor/nanocodex-tools/dist/runtime.d.ts +30 -0
- package/vendor/nanocodex-tools/dist/runtime.js +37 -0
- package/vendor/nanocodex-tools/dist/session.d.ts +167 -0
- package/vendor/nanocodex-tools/dist/session.js +286 -0
- package/vendor/nanocodex-tools/dist/shell.d.ts +51 -0
- package/vendor/nanocodex-tools/dist/shell.js +553 -0
- package/vendor/nanocodex-tools/dist/ssh.d.ts +29 -0
- package/vendor/nanocodex-tools/dist/ssh.js +66 -0
- package/vendor/nanocodex-tools/dist/workspace.d.ts +45 -0
- package/vendor/nanocodex-tools/dist/workspace.js +237 -0
- package/vendor/nanocodex-tools/package.json +122 -0
- package/vendor/nanocodex-tools/runtime/code-runtime.mjs +817 -0
- package/vendor/nanocodex-tools/runtime/tool-configuration.mjs +50 -0
- package/vendor/nanocodex-tools/runtime/tool-router.mjs +730 -0
- package/vendor/nanocodex-tools/runtime/utf8.d.mts +2 -0
- package/vendor/nanocodex-tools/runtime/utf8.mjs +25 -0
- package/vendor/nanocodex-tools/tools/artifact.d.mts +69 -0
- package/vendor/nanocodex-tools/tools/artifact.mjs +270 -0
- package/vendor/nanocodex-tools/tools/attachment.mjs +603 -0
- package/vendor/nanocodex-tools/tools/bash.d.mts +90 -0
- package/vendor/nanocodex-tools/tools/bash.mjs +742 -0
- package/vendor/nanocodex-tools/tools/dataset.d.mts +9 -0
- package/vendor/nanocodex-tools/tools/dataset.mjs +47 -0
- package/vendor/nanocodex-tools/tools/datasetContract.mjs +54 -0
- package/vendor/nanocodex-tools/tools/datasetEngine.mjs +1167 -0
- package/vendor/nanocodex-tools/tools/execution-contract.d.mts +5 -0
- package/vendor/nanocodex-tools/tools/execution-contract.mjs +63 -0
- package/vendor/nanocodex-tools/tools/hostedCatalog.d.mts +20 -0
- package/vendor/nanocodex-tools/tools/hostedCatalog.mjs +67 -0
- package/vendor/nanocodex-tools/tools/hostedMachine.d.mts +10 -0
- package/vendor/nanocodex-tools/tools/hostedMachine.mjs +56 -0
- package/vendor/nanocodex-tools/tools/just-bash-browser.d.mts +1 -0
- package/vendor/nanocodex-tools/tools/just-bash-browser.mjs +1 -0
- package/vendor/nanocodex-tools/tools/namedTool.d.mts +3 -0
- package/vendor/nanocodex-tools/tools/namedTool.mjs +3 -0
- package/vendor/nanocodex-tools/tools/nodeProcess.d.mts +10 -0
- package/vendor/nanocodex-tools/tools/nodeProcess.mjs +314 -0
- package/vendor/nanocodex-tools/tools/processOutput.mjs +56 -0
- package/vendor/nanocodex-tools/tools/repository-workspace.d.mts +55 -0
- package/vendor/nanocodex-tools/tools/repository-workspace.mjs +397 -0
- package/vendor/nanocodex-tools/tools/ssh.d.mts +56 -0
- package/vendor/nanocodex-tools/tools/ssh.mjs +503 -0
- package/vendor/nanocodex-tools/tools/standard.mjs +458 -0
- package/vendor/nanocodex-tools/tools/standardDescriptions.mjs +3 -0
- package/vendor/nanocodex-tools/tools/types.d.mts +83 -0
- package/vendor/nanocodex-tools/tools/workspace.d.mts +25 -0
- package/vendor/nanocodex-tools/tools/workspace.mjs +282 -0
- package/vendor/nanocodex-tools/tools/x.d.mts +30 -0
- package/vendor/nanocodex-tools/tools/x.mjs +91 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { type HostedMachine } from "../../tools/hostedMachine.mjs";
|
|
2
|
+
export declare const HOSTED_TOOLS_LEASE_MS = 60000;
|
|
3
|
+
export declare const HOSTED_TOOL_CALL_TIMEOUT_MS = 120000;
|
|
4
|
+
export declare const MAX_HOSTED_TOOLS_FRAME_BYTES: number;
|
|
5
|
+
export declare const MAX_HOSTED_TOOL_CATALOG_ENTRIES = 256;
|
|
6
|
+
export declare const MAX_HOSTED_TOOL_NAME_BYTES = 128;
|
|
7
|
+
export declare const MAX_HOSTED_TOOL_SCHEMA_BYTES: number;
|
|
8
|
+
export declare const MAX_HOSTED_TOOL_INPUT_BYTES: number;
|
|
9
|
+
export declare const MAX_HOSTED_TOOL_OUTPUT_BYTES: number;
|
|
10
|
+
export type HostedToolDefinition = {
|
|
11
|
+
type: "function";
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
strict: boolean;
|
|
15
|
+
parameters: Record<string, unknown>;
|
|
16
|
+
output_schema?: Record<string, unknown>;
|
|
17
|
+
} | {
|
|
18
|
+
type: "custom";
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
format: {
|
|
22
|
+
type: "grammar";
|
|
23
|
+
syntax: string;
|
|
24
|
+
definition: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export type HostedToolCatalogEntry = {
|
|
28
|
+
provider: string;
|
|
29
|
+
remote_name: string;
|
|
30
|
+
definition: HostedToolDefinition;
|
|
31
|
+
parallel_safe: boolean;
|
|
32
|
+
summary?: string;
|
|
33
|
+
timeout_ms: number;
|
|
34
|
+
};
|
|
35
|
+
export type { HostedMachine } from "../../tools/hostedMachine.mjs";
|
|
36
|
+
export type HostedToolOutputContent = {
|
|
37
|
+
type: "input_text";
|
|
38
|
+
text: string;
|
|
39
|
+
} | {
|
|
40
|
+
type: "input_image";
|
|
41
|
+
image_url: string;
|
|
42
|
+
detail: "auto" | "low" | "high" | "original";
|
|
43
|
+
} | {
|
|
44
|
+
type: "input_audio";
|
|
45
|
+
audio_url: string;
|
|
46
|
+
};
|
|
47
|
+
export type HostedToolProcessTrace = {
|
|
48
|
+
exit_code: number | null;
|
|
49
|
+
session_id: number | null;
|
|
50
|
+
original_token_count: number | null;
|
|
51
|
+
output_bytes: number;
|
|
52
|
+
wall_time_seconds: number;
|
|
53
|
+
};
|
|
54
|
+
export type HostedToolOutputWire = {
|
|
55
|
+
output: string | HostedToolOutputContent[];
|
|
56
|
+
success: boolean;
|
|
57
|
+
structured_result: unknown | null;
|
|
58
|
+
metadata: unknown | null;
|
|
59
|
+
process_trace: HostedToolProcessTrace | null;
|
|
60
|
+
};
|
|
61
|
+
export type HostedToolCallOutcome = {
|
|
62
|
+
status: "completed";
|
|
63
|
+
output: HostedToolOutputWire;
|
|
64
|
+
} | {
|
|
65
|
+
status: "unavailable";
|
|
66
|
+
message: string;
|
|
67
|
+
} | {
|
|
68
|
+
status: "ambiguous";
|
|
69
|
+
message: string;
|
|
70
|
+
} | {
|
|
71
|
+
status: "cancelled";
|
|
72
|
+
message: string;
|
|
73
|
+
};
|
|
74
|
+
export type HostedToolsHostFrame = {
|
|
75
|
+
type: "catalog";
|
|
76
|
+
tools: HostedToolCatalogEntry[];
|
|
77
|
+
machines?: HostedMachine[];
|
|
78
|
+
attachment_id?: string;
|
|
79
|
+
} | {
|
|
80
|
+
type: "result";
|
|
81
|
+
call_id: string;
|
|
82
|
+
outcome: HostedToolCallOutcome;
|
|
83
|
+
} | {
|
|
84
|
+
type: "ping";
|
|
85
|
+
nonce: string;
|
|
86
|
+
} | {
|
|
87
|
+
type: "drain";
|
|
88
|
+
};
|
|
89
|
+
export type HostedToolsManagedFrame = {
|
|
90
|
+
type: "ready";
|
|
91
|
+
} | {
|
|
92
|
+
type: "call";
|
|
93
|
+
session_id: string;
|
|
94
|
+
call_id: string;
|
|
95
|
+
model: string;
|
|
96
|
+
name: string;
|
|
97
|
+
input: Record<string, unknown> | string;
|
|
98
|
+
output_token_budget: number;
|
|
99
|
+
output_byte_budget: number;
|
|
100
|
+
deadline_at: number;
|
|
101
|
+
} | {
|
|
102
|
+
type: "cancel";
|
|
103
|
+
call_id: string;
|
|
104
|
+
} | {
|
|
105
|
+
type: "ack";
|
|
106
|
+
call_id: string;
|
|
107
|
+
} | {
|
|
108
|
+
type: "pong";
|
|
109
|
+
nonce: string;
|
|
110
|
+
} | {
|
|
111
|
+
type: "draining";
|
|
112
|
+
};
|
|
113
|
+
export type HostedToolsFrame = HostedToolsHostFrame | HostedToolsManagedFrame;
|
|
114
|
+
export declare function parseHostedToolsHostFrame(encoded: string): HostedToolsHostFrame;
|
|
115
|
+
export declare function parseHostedToolsManagedFrame(encoded: string): HostedToolsManagedFrame;
|
|
116
|
+
export declare function parseHostedToolsFrame(encoded: string): HostedToolsFrame;
|
|
117
|
+
export declare class HostedToolsProtocolError extends Error {
|
|
118
|
+
readonly code: string;
|
|
119
|
+
constructor(code: string, message: string);
|
|
120
|
+
}
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import { normalizeHostedMachines, } from "../../tools/hostedMachine.mjs";
|
|
2
|
+
export const HOSTED_TOOLS_LEASE_MS = 60_000;
|
|
3
|
+
export const HOSTED_TOOL_CALL_TIMEOUT_MS = 120_000;
|
|
4
|
+
export const MAX_HOSTED_TOOLS_FRAME_BYTES = 256 * 1024;
|
|
5
|
+
export const MAX_HOSTED_TOOL_CATALOG_ENTRIES = 256;
|
|
6
|
+
export const MAX_HOSTED_TOOL_NAME_BYTES = 128;
|
|
7
|
+
export const MAX_HOSTED_TOOL_SCHEMA_BYTES = 64 * 1024;
|
|
8
|
+
export const MAX_HOSTED_TOOL_INPUT_BYTES = 128 * 1024;
|
|
9
|
+
export const MAX_HOSTED_TOOL_OUTPUT_BYTES = 128 * 1024;
|
|
10
|
+
const MAX_DESCRIPTION_BYTES = 8 * 1024;
|
|
11
|
+
const MAX_SUMMARY_BYTES = 2 * 1024;
|
|
12
|
+
const MAX_MESSAGE_BYTES = 2 * 1024;
|
|
13
|
+
const MAX_NONCE_BYTES = 128;
|
|
14
|
+
const MAX_OUTPUT_CONTENT_ITEMS = 64;
|
|
15
|
+
const MAX_OUTPUT_TOKEN_BUDGET = 1_000_000;
|
|
16
|
+
const IDENTIFIER = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
17
|
+
const RESERVED_TOOL_NAMES = new Set(["exec", "tool_search", "wait"]);
|
|
18
|
+
const encoder = new TextEncoder();
|
|
19
|
+
const HOST_FRAME_TYPES = new Set(["catalog", "result", "ping", "drain"]);
|
|
20
|
+
const MANAGED_FRAME_TYPES = new Set(["ready", "call", "cancel", "ack", "pong", "draining"]);
|
|
21
|
+
export function parseHostedToolsHostFrame(encoded) {
|
|
22
|
+
const frame = parseHostedToolsFrame(encoded);
|
|
23
|
+
if (!HOST_FRAME_TYPES.has(frame.type)) {
|
|
24
|
+
throw new HostedToolsProtocolError("wrong_direction", `${frame.type} is not a host-to-managed tools frame`);
|
|
25
|
+
}
|
|
26
|
+
return frame;
|
|
27
|
+
}
|
|
28
|
+
export function parseHostedToolsManagedFrame(encoded) {
|
|
29
|
+
const frame = parseHostedToolsFrame(encoded);
|
|
30
|
+
if (!MANAGED_FRAME_TYPES.has(frame.type)) {
|
|
31
|
+
throw new HostedToolsProtocolError("wrong_direction", `${frame.type} is not a managed-to-host tools frame`);
|
|
32
|
+
}
|
|
33
|
+
return frame;
|
|
34
|
+
}
|
|
35
|
+
export function parseHostedToolsFrame(encoded) {
|
|
36
|
+
if (encoder.encode(encoded).byteLength > MAX_HOSTED_TOOLS_FRAME_BYTES) {
|
|
37
|
+
throw new HostedToolsProtocolError("message_too_large", `Hosted Tools frames are limited to ${MAX_HOSTED_TOOLS_FRAME_BYTES} bytes`);
|
|
38
|
+
}
|
|
39
|
+
let value;
|
|
40
|
+
try {
|
|
41
|
+
value = JSON.parse(encoded);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
throw new HostedToolsProtocolError("invalid_json", "Hosted Tools frames must be JSON objects");
|
|
45
|
+
}
|
|
46
|
+
const frame = objectValue(value, "Hosted Tools frame");
|
|
47
|
+
switch (frame.type) {
|
|
48
|
+
case "catalog":
|
|
49
|
+
return parseCatalog(frame);
|
|
50
|
+
case "result":
|
|
51
|
+
return parseResult(frame);
|
|
52
|
+
case "ping":
|
|
53
|
+
return parsePing(frame);
|
|
54
|
+
case "drain":
|
|
55
|
+
exactKeys(frame, ["type"]);
|
|
56
|
+
return { type: "drain" };
|
|
57
|
+
case "ready":
|
|
58
|
+
exactKeys(frame, ["type"]);
|
|
59
|
+
return { type: "ready" };
|
|
60
|
+
case "call":
|
|
61
|
+
return parseCall(frame);
|
|
62
|
+
case "cancel":
|
|
63
|
+
return parseCancel(frame);
|
|
64
|
+
case "ack":
|
|
65
|
+
return parseAck(frame);
|
|
66
|
+
case "pong":
|
|
67
|
+
return parsePong(frame);
|
|
68
|
+
case "draining":
|
|
69
|
+
exactKeys(frame, ["type"]);
|
|
70
|
+
return { type: "draining" };
|
|
71
|
+
default:
|
|
72
|
+
throw new HostedToolsProtocolError("unknown_message", "unsupported Hosted Tools frame type");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function parseCatalog(frame) {
|
|
76
|
+
exactKeys(frame, ["type", "tools", "machines", "attachment_id"]);
|
|
77
|
+
if (!Array.isArray(frame.tools) || frame.tools.length > MAX_HOSTED_TOOL_CATALOG_ENTRIES) {
|
|
78
|
+
throw new HostedToolsProtocolError("invalid_catalog", `tools must be an array of at most ${MAX_HOSTED_TOOL_CATALOG_ENTRIES} entries`);
|
|
79
|
+
}
|
|
80
|
+
const tools = frame.tools.map((entry, index) => catalogEntry(entry, index));
|
|
81
|
+
const machines = machineCatalog(frame.machines);
|
|
82
|
+
const attachmentId = frame.attachment_id === undefined
|
|
83
|
+
? undefined
|
|
84
|
+
: sourceIdentifier(frame.attachment_id, "attachment_id");
|
|
85
|
+
if (machines !== undefined && machines.length > 0
|
|
86
|
+
&& (machines.length !== 1 || attachmentId !== machines[0]?.id)) {
|
|
87
|
+
throw new HostedToolsProtocolError("invalid_catalog", "a machine catalog requires one machine whose id equals attachment_id");
|
|
88
|
+
}
|
|
89
|
+
const names = new Set();
|
|
90
|
+
const identities = new Set();
|
|
91
|
+
for (const tool of tools) {
|
|
92
|
+
if (names.has(tool.definition.name)) {
|
|
93
|
+
throw new HostedToolsProtocolError("invalid_catalog", `duplicate tool name: ${tool.definition.name}`);
|
|
94
|
+
}
|
|
95
|
+
names.add(tool.definition.name);
|
|
96
|
+
const identity = `${tool.provider}\u0000${tool.remote_name}`;
|
|
97
|
+
if (identities.has(identity)) {
|
|
98
|
+
throw new HostedToolsProtocolError("invalid_catalog", `duplicate provider tool identity: ${tool.provider}:${tool.remote_name}`);
|
|
99
|
+
}
|
|
100
|
+
identities.add(identity);
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
type: "catalog",
|
|
104
|
+
tools,
|
|
105
|
+
...(machines === undefined ? {} : { machines }),
|
|
106
|
+
...(attachmentId === undefined ? {} : { attachment_id: attachmentId }),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function machineCatalog(value) {
|
|
110
|
+
if (value === undefined)
|
|
111
|
+
return undefined;
|
|
112
|
+
try {
|
|
113
|
+
return [...normalizeHostedMachines(value)];
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
throw new HostedToolsProtocolError("invalid_catalog", error instanceof Error ? error.message : String(error));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function parseResult(frame) {
|
|
120
|
+
exactKeys(frame, ["type", "call_id", "outcome"]);
|
|
121
|
+
return {
|
|
122
|
+
type: "result",
|
|
123
|
+
call_id: identifier(frame.call_id, "call_id"),
|
|
124
|
+
outcome: callOutcome(frame.outcome),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function parsePing(frame) {
|
|
128
|
+
exactKeys(frame, ["type", "nonce"]);
|
|
129
|
+
return {
|
|
130
|
+
type: "ping",
|
|
131
|
+
nonce: boundedText(frame.nonce, 0, MAX_NONCE_BYTES, "nonce"),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function parseCall(frame) {
|
|
135
|
+
exactKeys(frame, [
|
|
136
|
+
"type", "session_id", "call_id", "model", "name", "input", "output_token_budget",
|
|
137
|
+
"output_byte_budget", "deadline_at",
|
|
138
|
+
]);
|
|
139
|
+
const input = typeof frame.input === "string"
|
|
140
|
+
? frame.input
|
|
141
|
+
: objectValue(frame.input, "call input");
|
|
142
|
+
boundedJson(input, MAX_HOSTED_TOOL_INPUT_BYTES, "input_too_large", "call input");
|
|
143
|
+
return {
|
|
144
|
+
type: "call",
|
|
145
|
+
session_id: identifier(frame.session_id, "session_id"),
|
|
146
|
+
call_id: identifier(frame.call_id, "call_id"),
|
|
147
|
+
model: identifier(frame.model, "model"),
|
|
148
|
+
name: toolName(frame.name),
|
|
149
|
+
input,
|
|
150
|
+
output_token_budget: boundedInteger(frame.output_token_budget, 1, MAX_OUTPUT_TOKEN_BUDGET, "output_token_budget"),
|
|
151
|
+
output_byte_budget: boundedInteger(frame.output_byte_budget, 1, MAX_HOSTED_TOOL_OUTPUT_BYTES, "output_byte_budget"),
|
|
152
|
+
deadline_at: timestamp(frame.deadline_at, "deadline_at"),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function parseCancel(frame) {
|
|
156
|
+
exactKeys(frame, ["type", "call_id"]);
|
|
157
|
+
return {
|
|
158
|
+
type: "cancel",
|
|
159
|
+
call_id: identifier(frame.call_id, "call_id"),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function parseAck(frame) {
|
|
163
|
+
exactKeys(frame, ["type", "call_id"]);
|
|
164
|
+
return {
|
|
165
|
+
type: "ack",
|
|
166
|
+
call_id: identifier(frame.call_id, "call_id"),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function parsePong(frame) {
|
|
170
|
+
exactKeys(frame, ["type", "nonce"]);
|
|
171
|
+
return {
|
|
172
|
+
type: "pong",
|
|
173
|
+
nonce: boundedText(frame.nonce, 0, MAX_NONCE_BYTES, "nonce"),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function catalogEntry(value, index) {
|
|
177
|
+
const entry = objectValue(value, `tools[${index}]`);
|
|
178
|
+
exactKeys(entry, ["provider", "remote_name", "definition", "parallel_safe", "summary", "timeout_ms"]);
|
|
179
|
+
if (typeof entry.parallel_safe !== "boolean") {
|
|
180
|
+
throw new HostedToolsProtocolError("invalid_catalog", `tools[${index}].parallel_safe must be boolean`);
|
|
181
|
+
}
|
|
182
|
+
const definition = toolDefinition(entry.definition, index);
|
|
183
|
+
return {
|
|
184
|
+
provider: identifier(entry.provider, `tools[${index}].provider`),
|
|
185
|
+
remote_name: identifier(entry.remote_name, `tools[${index}].remote_name`),
|
|
186
|
+
definition,
|
|
187
|
+
parallel_safe: entry.parallel_safe,
|
|
188
|
+
...(entry.summary === undefined
|
|
189
|
+
? {}
|
|
190
|
+
: { summary: boundedText(entry.summary, 1, MAX_SUMMARY_BYTES, `tools[${index}].summary`) }),
|
|
191
|
+
timeout_ms: boundedInteger(entry.timeout_ms, 1, HOSTED_TOOL_CALL_TIMEOUT_MS, `tools[${index}].timeout_ms`),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function toolDefinition(value, index) {
|
|
195
|
+
const definition = objectValue(value, `tools[${index}].definition`);
|
|
196
|
+
const name = toolName(definition.name);
|
|
197
|
+
const description = boundedText(definition.description, 1, MAX_DESCRIPTION_BYTES, `tools[${index}].definition.description`);
|
|
198
|
+
if (definition.type === "function") {
|
|
199
|
+
exactKeys(definition, ["type", "name", "description", "strict", "parameters", "output_schema"]);
|
|
200
|
+
if (typeof definition.strict !== "boolean") {
|
|
201
|
+
throw new HostedToolsProtocolError("invalid_catalog", `tools[${index}].definition.strict must be boolean`);
|
|
202
|
+
}
|
|
203
|
+
const parameters = objectValue(definition.parameters, `tools[${index}].definition.parameters`);
|
|
204
|
+
if (!isObjectInputSchema(parameters)) {
|
|
205
|
+
throw new HostedToolsProtocolError("invalid_schema", `tools[${index}].definition.parameters must be an object JSON Schema`);
|
|
206
|
+
}
|
|
207
|
+
boundedJson(parameters, MAX_HOSTED_TOOL_SCHEMA_BYTES, "schema_too_large", `tools[${index}].definition.parameters`);
|
|
208
|
+
const outputSchema = definition.output_schema === undefined
|
|
209
|
+
? undefined
|
|
210
|
+
: objectValue(definition.output_schema, `tools[${index}].definition.output_schema`);
|
|
211
|
+
if (outputSchema !== undefined) {
|
|
212
|
+
boundedJson(outputSchema, MAX_HOSTED_TOOL_SCHEMA_BYTES, "schema_too_large", `tools[${index}].definition.output_schema`);
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
type: "function",
|
|
216
|
+
name,
|
|
217
|
+
description,
|
|
218
|
+
strict: definition.strict,
|
|
219
|
+
parameters,
|
|
220
|
+
...(outputSchema === undefined ? {} : { output_schema: outputSchema }),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
if (definition.type === "custom") {
|
|
224
|
+
exactKeys(definition, ["type", "name", "description", "format"]);
|
|
225
|
+
const format = objectValue(definition.format, `tools[${index}].definition.format`);
|
|
226
|
+
exactKeys(format, ["type", "syntax", "definition"]);
|
|
227
|
+
if (format.type !== "grammar") {
|
|
228
|
+
throw new HostedToolsProtocolError("invalid_schema", "custom tool format must be grammar");
|
|
229
|
+
}
|
|
230
|
+
const syntax = identifier(format.syntax, `tools[${index}].definition.format.syntax`);
|
|
231
|
+
const grammar = boundedText(format.definition, 1, MAX_HOSTED_TOOL_SCHEMA_BYTES, `tools[${index}].definition.format.definition`);
|
|
232
|
+
return {
|
|
233
|
+
type: "custom",
|
|
234
|
+
name,
|
|
235
|
+
description,
|
|
236
|
+
format: { type: "grammar", syntax, definition: grammar },
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
throw new HostedToolsProtocolError("invalid_catalog", `tools[${index}].definition.type must be function or custom`);
|
|
240
|
+
}
|
|
241
|
+
function isObjectInputSchema(schema) {
|
|
242
|
+
if (schema.type === "object")
|
|
243
|
+
return true;
|
|
244
|
+
return Array.isArray(schema.oneOf)
|
|
245
|
+
&& schema.oneOf.length > 0
|
|
246
|
+
&& schema.oneOf.every((branch) => {
|
|
247
|
+
const candidate = branch;
|
|
248
|
+
return candidate !== null
|
|
249
|
+
&& typeof candidate === "object"
|
|
250
|
+
&& !Array.isArray(candidate)
|
|
251
|
+
&& candidate.type === "object";
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
function callOutcome(value) {
|
|
255
|
+
const outcome = objectValue(value, "result outcome");
|
|
256
|
+
switch (outcome.status) {
|
|
257
|
+
case "completed":
|
|
258
|
+
exactKeys(outcome, ["status", "output"]);
|
|
259
|
+
return { status: "completed", output: toolOutput(outcome.output) };
|
|
260
|
+
case "unavailable":
|
|
261
|
+
case "ambiguous":
|
|
262
|
+
case "cancelled":
|
|
263
|
+
exactKeys(outcome, ["status", "message"]);
|
|
264
|
+
return {
|
|
265
|
+
status: outcome.status,
|
|
266
|
+
message: boundedText(outcome.message, 1, MAX_MESSAGE_BYTES, "outcome message"),
|
|
267
|
+
};
|
|
268
|
+
default:
|
|
269
|
+
throw new HostedToolsProtocolError("invalid_outcome", "result outcome must be completed, unavailable, ambiguous, or cancelled");
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function toolOutput(value) {
|
|
273
|
+
const output = objectValue(value, "completed output");
|
|
274
|
+
exactKeys(output, ["output", "success", "structured_result", "metadata", "process_trace"]);
|
|
275
|
+
if (typeof output.success !== "boolean"
|
|
276
|
+
|| !Object.hasOwn(output, "structured_result")
|
|
277
|
+
|| !Object.hasOwn(output, "metadata")
|
|
278
|
+
|| !Object.hasOwn(output, "process_trace")) {
|
|
279
|
+
throw new HostedToolsProtocolError("invalid_output", "completed output requires success and all nullable output metadata fields");
|
|
280
|
+
}
|
|
281
|
+
const body = typeof output.output === "string"
|
|
282
|
+
? output.output
|
|
283
|
+
: outputContent(output.output);
|
|
284
|
+
const wire = {
|
|
285
|
+
output: body,
|
|
286
|
+
success: output.success,
|
|
287
|
+
structured_result: output.structured_result,
|
|
288
|
+
metadata: output.metadata,
|
|
289
|
+
process_trace: output.process_trace === null ? null : processTrace(output.process_trace),
|
|
290
|
+
};
|
|
291
|
+
boundedJson(wire, MAX_HOSTED_TOOL_OUTPUT_BYTES, "output_too_large", "completed output");
|
|
292
|
+
return wire;
|
|
293
|
+
}
|
|
294
|
+
function outputContent(value) {
|
|
295
|
+
if (!Array.isArray(value) || value.length > MAX_OUTPUT_CONTENT_ITEMS) {
|
|
296
|
+
throw new HostedToolsProtocolError("invalid_output", `completed output content must have at most ${MAX_OUTPUT_CONTENT_ITEMS} items`);
|
|
297
|
+
}
|
|
298
|
+
return value.map((item, index) => {
|
|
299
|
+
const content = objectValue(item, `completed output content[${index}]`);
|
|
300
|
+
if (content.type === "input_text") {
|
|
301
|
+
exactKeys(content, ["type", "text"]);
|
|
302
|
+
return {
|
|
303
|
+
type: "input_text",
|
|
304
|
+
text: boundedText(content.text, 0, MAX_HOSTED_TOOL_OUTPUT_BYTES, `content[${index}].text`),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
if (content.type === "input_image") {
|
|
308
|
+
exactKeys(content, ["type", "image_url", "detail"]);
|
|
309
|
+
if (content.detail !== "auto" && content.detail !== "low"
|
|
310
|
+
&& content.detail !== "high" && content.detail !== "original") {
|
|
311
|
+
throw new HostedToolsProtocolError("invalid_output", `content[${index}].detail is invalid`);
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
type: "input_image",
|
|
315
|
+
image_url: boundedText(content.image_url, 1, MAX_HOSTED_TOOL_OUTPUT_BYTES, `content[${index}].image_url`),
|
|
316
|
+
detail: content.detail,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
if (content.type === "input_audio") {
|
|
320
|
+
exactKeys(content, ["type", "audio_url"]);
|
|
321
|
+
return {
|
|
322
|
+
type: "input_audio",
|
|
323
|
+
audio_url: boundedText(content.audio_url, 1, MAX_HOSTED_TOOL_OUTPUT_BYTES, `content[${index}].audio_url`),
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
throw new HostedToolsProtocolError("invalid_output", `content[${index}].type is invalid`);
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
function processTrace(value) {
|
|
330
|
+
const trace = objectValue(value, "process_trace");
|
|
331
|
+
exactKeys(trace, [
|
|
332
|
+
"exit_code", "session_id", "original_token_count", "output_bytes", "wall_time_seconds",
|
|
333
|
+
]);
|
|
334
|
+
const exitCode = nullableInteger(trace.exit_code, -2_147_483_648, 2_147_483_647, "exit_code");
|
|
335
|
+
const sessionId = nullableInteger(trace.session_id, 0, Number.MAX_SAFE_INTEGER, "process session_id");
|
|
336
|
+
const originalTokenCount = nullableInteger(trace.original_token_count, 0, Number.MAX_SAFE_INTEGER, "original_token_count");
|
|
337
|
+
if (typeof trace.wall_time_seconds !== "number"
|
|
338
|
+
|| !Number.isFinite(trace.wall_time_seconds)
|
|
339
|
+
|| trace.wall_time_seconds < 0) {
|
|
340
|
+
throw new HostedToolsProtocolError("invalid_output", "wall_time_seconds must be a finite non-negative number");
|
|
341
|
+
}
|
|
342
|
+
return {
|
|
343
|
+
exit_code: exitCode,
|
|
344
|
+
session_id: sessionId,
|
|
345
|
+
original_token_count: originalTokenCount,
|
|
346
|
+
output_bytes: boundedInteger(trace.output_bytes, 0, Number.MAX_SAFE_INTEGER, "output_bytes"),
|
|
347
|
+
wall_time_seconds: trace.wall_time_seconds,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function identifier(value, name) {
|
|
351
|
+
if (typeof value !== "string" || !IDENTIFIER.test(value)) {
|
|
352
|
+
throw new HostedToolsProtocolError("invalid_identifier", `${name} must be 1-${MAX_HOSTED_TOOL_NAME_BYTES} safe ASCII bytes`);
|
|
353
|
+
}
|
|
354
|
+
return value;
|
|
355
|
+
}
|
|
356
|
+
function sourceIdentifier(value, name) {
|
|
357
|
+
if (typeof value !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,122}$/.test(value)) {
|
|
358
|
+
throw new HostedToolsProtocolError("invalid_identifier", `${name} must be 1-123 safe ASCII bytes`);
|
|
359
|
+
}
|
|
360
|
+
return value;
|
|
361
|
+
}
|
|
362
|
+
function toolName(value) {
|
|
363
|
+
const name = identifier(value, "tool name");
|
|
364
|
+
if (RESERVED_TOOL_NAMES.has(name)) {
|
|
365
|
+
throw new HostedToolsProtocolError("invalid_identifier", "tool name is reserved");
|
|
366
|
+
}
|
|
367
|
+
return name;
|
|
368
|
+
}
|
|
369
|
+
function timestamp(value, name) {
|
|
370
|
+
return boundedInteger(value, 1, Number.MAX_SAFE_INTEGER, name);
|
|
371
|
+
}
|
|
372
|
+
function nullableInteger(value, minimum, maximum, name) {
|
|
373
|
+
return value === null ? null : boundedInteger(value, minimum, maximum, name);
|
|
374
|
+
}
|
|
375
|
+
function boundedInteger(value, minimum, maximum, name) {
|
|
376
|
+
if (!Number.isSafeInteger(value) || Number(value) < minimum || Number(value) > maximum) {
|
|
377
|
+
throw new HostedToolsProtocolError("invalid_integer", `${name} must be an integer from ${minimum} through ${maximum}`);
|
|
378
|
+
}
|
|
379
|
+
return Number(value);
|
|
380
|
+
}
|
|
381
|
+
function boundedText(value, minimum, maximum, name) {
|
|
382
|
+
if (typeof value !== "string") {
|
|
383
|
+
throw new HostedToolsProtocolError("invalid_string", `${name} must be text`);
|
|
384
|
+
}
|
|
385
|
+
const bytes = encoder.encode(value).byteLength;
|
|
386
|
+
if (bytes < minimum || bytes > maximum) {
|
|
387
|
+
throw new HostedToolsProtocolError("invalid_string", `${name} must be ${minimum}-${maximum} UTF-8 bytes`);
|
|
388
|
+
}
|
|
389
|
+
return value;
|
|
390
|
+
}
|
|
391
|
+
function boundedJson(value, maximum, code, name) {
|
|
392
|
+
const bytes = encoder.encode(JSON.stringify(value)).byteLength;
|
|
393
|
+
if (bytes > maximum) {
|
|
394
|
+
throw new HostedToolsProtocolError(code, `${name} is limited to ${maximum} encoded bytes`);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function objectValue(value, name) {
|
|
398
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
399
|
+
throw new HostedToolsProtocolError("invalid_message", `${name} must be an object`);
|
|
400
|
+
}
|
|
401
|
+
return value;
|
|
402
|
+
}
|
|
403
|
+
function exactKeys(value, allowed) {
|
|
404
|
+
const fields = new Set(allowed);
|
|
405
|
+
if (Object.keys(value).some((key) => !fields.has(key))) {
|
|
406
|
+
throw new HostedToolsProtocolError("invalid_message", "Hosted Tools frame has unsupported fields");
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
export class HostedToolsProtocolError extends Error {
|
|
410
|
+
code;
|
|
411
|
+
constructor(code, message) {
|
|
412
|
+
super(message);
|
|
413
|
+
this.code = code;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { createComputerRuntime, type ComputerCommandContext, type ComputerRuntime, type ComputerRuntimeOptions, } from "./runtime.js";
|
|
2
|
+
export { createGhCommand, createGitCommand, type ShellFetch, type ShellFetchOptions, type ShellFetchResult, } from "./shell.js";
|
|
3
|
+
export { createWorkspaceSshCommand, type SshConnect, type SshSocket, } from "./ssh.js";
|
|
4
|
+
export { createWorkspaceFilesystem, type WorkspaceStorageClient, } from "./workspace.js";
|
|
5
|
+
export * from "./namespace.js";
|
|
6
|
+
export * from "./memory.js";
|
|
7
|
+
export * from "./hosted/index.js";
|
|
8
|
+
export { namedTool } from "../tools/namedTool.mjs";
|
|
9
|
+
export * from "../tools/execution-contract.mjs";
|
|
10
|
+
export * from "../tools/artifact.mjs";
|
|
11
|
+
export { dataset } from "../tools/dataset.mjs";
|
|
12
|
+
export type { DatasetOptions } from "../tools/dataset.mjs";
|
|
13
|
+
export { justBash } from "../tools/bash.mjs";
|
|
14
|
+
export type { JustBashCustomCommand, JustBashDescriptor, JustBashFetch, JustBashNetworkOptions, JustBashRuntime, } from "../tools/bash.mjs";
|
|
15
|
+
export { materializeRepositoryWorkspace } from "../tools/repository-workspace.mjs";
|
|
16
|
+
export type { RepositoryWorkspaceDescriptor, RepositoryWorkspaceFetch, RepositoryWorkspaceRemote, } from "../tools/repository-workspace.mjs";
|
|
17
|
+
export { createSshCommand, createWebStreamSshStream } from "../tools/ssh.mjs";
|
|
18
|
+
export type { SshCommandOptions, SshCommandResult, SshEndpoint, SshIdentityReferenceRequest, SshStream, } from "../tools/ssh.mjs";
|
|
19
|
+
export type { CustomToolFormat, NamedTool, SubagentToolContext, Tool, ToolContext, ToolDefinition, ToolJson, ToolMap, Workspace, WorkspaceEntry, } from "../tools/types.mjs";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { createComputerRuntime, } from "./runtime.js";
|
|
2
|
+
export { createGhCommand, createGitCommand, } from "./shell.js";
|
|
3
|
+
export { createWorkspaceSshCommand, } from "./ssh.js";
|
|
4
|
+
export { createWorkspaceFilesystem, } from "./workspace.js";
|
|
5
|
+
export * from "./namespace.js";
|
|
6
|
+
export * from "./memory.js";
|
|
7
|
+
export * from "./hosted/index.js";
|
|
8
|
+
export { namedTool } from "../tools/namedTool.mjs";
|
|
9
|
+
export * from "../tools/execution-contract.mjs";
|
|
10
|
+
export * from "../tools/artifact.mjs";
|
|
11
|
+
export { dataset } from "../tools/dataset.mjs";
|
|
12
|
+
export { justBash } from "../tools/bash.mjs";
|
|
13
|
+
export { materializeRepositoryWorkspace } from "../tools/repository-workspace.mjs";
|
|
14
|
+
export { createSshCommand, createWebStreamSshStream } from "../tools/ssh.mjs";
|