@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
|
Binary file
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_browservoice_free: (a: number, b: number) => void;
|
|
5
|
+
export const __wbg_chatgptsubscription_free: (a: number, b: number) => void;
|
|
6
|
+
export const __wbg_managedbrowservoice_free: (a: number, b: number) => void;
|
|
7
|
+
export const __wbg_nanocodex_free: (a: number, b: number) => void;
|
|
8
|
+
export const __wbg_turn_free: (a: number, b: number) => void;
|
|
9
|
+
export const __wbg_turnresult_free: (a: number, b: number) => void;
|
|
10
|
+
export const applyBrowserPatch: (a: number, b: number, c: number, d: number) => number;
|
|
11
|
+
export const browservoice_agentEvent: (a: number, b: number, c: number, d: number) => void;
|
|
12
|
+
export const browservoice_appendContext: (a: number, b: number, c: number, d: number) => void;
|
|
13
|
+
export const browservoice_appendSpeech: (a: number, b: number, c: number, d: number) => void;
|
|
14
|
+
export const browservoice_appendText: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
15
|
+
export const browservoice_callBody: (a: number, b: number, c: number, d: number) => void;
|
|
16
|
+
export const browservoice_cancel: (a: number) => number;
|
|
17
|
+
export const browservoice_completeCall: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
18
|
+
export const browservoice_configure: (a: number, b: number, c: number, d: number) => void;
|
|
19
|
+
export const browservoice_flush: (a: number, b: number, c: number) => void;
|
|
20
|
+
export const browservoice_framesSent: (a: number, b: number) => void;
|
|
21
|
+
export const browservoice_preferredPhysicalInput: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
22
|
+
export const browservoice_realtimeMessage: (a: number, b: number, c: number) => number;
|
|
23
|
+
export const browservoice_requiresAgentAdmission: (a: number, b: number, c: number) => number;
|
|
24
|
+
export const browservoice_sidebandClosed: (a: number, b: number, c: number) => void;
|
|
25
|
+
export const browservoice_sidebandOpened: (a: number, b: number) => void;
|
|
26
|
+
export const browservoice_sidebandUrl: (a: number, b: number, c: number, d: number) => void;
|
|
27
|
+
export const browservoice_start: (a: number) => number;
|
|
28
|
+
export const browservoice_stop: (a: number) => number;
|
|
29
|
+
export const chatgptsubscription_credential: (a: number) => number;
|
|
30
|
+
export const chatgptsubscription_logout: (a: number) => number;
|
|
31
|
+
export const chatgptsubscription_open: (a: number, b: number) => number;
|
|
32
|
+
export const chatgptsubscription_recover: (a: number, b: number, c: number) => number;
|
|
33
|
+
export const chatgptsubscription_startLogin: (a: number) => number;
|
|
34
|
+
export const chatgptsubscription_status: (a: number) => number;
|
|
35
|
+
export const managedBootstrapPlan: (a: number, b: number, c: number) => void;
|
|
36
|
+
export const managedbrowservoice_agentEvent: (a: number, b: number, c: number, d: number) => void;
|
|
37
|
+
export const managedbrowservoice_appendContext: (a: number, b: number, c: number, d: number) => void;
|
|
38
|
+
export const managedbrowservoice_appendSpeech: (a: number, b: number, c: number, d: number) => void;
|
|
39
|
+
export const managedbrowservoice_appendText: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
40
|
+
export const managedbrowservoice_callBody: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
41
|
+
export const managedbrowservoice_completeCall: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
42
|
+
export const managedbrowservoice_configure: (a: number, b: number, c: number, d: number) => void;
|
|
43
|
+
export const managedbrowservoice_flush: (a: number, b: number, c: number) => void;
|
|
44
|
+
export const managedbrowservoice_framesSent: (a: number, b: number) => void;
|
|
45
|
+
export const managedbrowservoice_managedEvent: (a: number, b: number, c: number, d: number) => void;
|
|
46
|
+
export const managedbrowservoice_new: (a: number, b: number, c: number) => void;
|
|
47
|
+
export const managedbrowservoice_preferredPhysicalInput: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
48
|
+
export const managedbrowservoice_realtimeMessage: (a: number, b: number, c: number, d: number) => void;
|
|
49
|
+
export const managedbrowservoice_requiresAgentAdmission: (a: number, b: number, c: number) => number;
|
|
50
|
+
export const managedbrowservoice_sidebandClosed: (a: number, b: number, c: number) => void;
|
|
51
|
+
export const managedbrowservoice_sidebandOpened: (a: number, b: number) => void;
|
|
52
|
+
export const managedbrowservoice_sidebandUrl: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
53
|
+
export const managedbrowservoice_start: (a: number, b: number, c: number, d: number) => void;
|
|
54
|
+
export const managedbrowservoice_stop: (a: number, b: number) => void;
|
|
55
|
+
export const nanocodex_agentId: (a: number, b: number) => void;
|
|
56
|
+
export const nanocodex_appendDeveloperMessage: (a: number, b: number, c: number) => number;
|
|
57
|
+
export const nanocodex_browserVoice: (a: number, b: number, c: number, d: number) => void;
|
|
58
|
+
export const nanocodex_closeSubagent: (a: number, b: number, c: number) => number;
|
|
59
|
+
export const nanocodex_compact: (a: number) => number;
|
|
60
|
+
export const nanocodex_compactOutcome: (a: number) => number;
|
|
61
|
+
export const nanocodex_context: (a: number) => number;
|
|
62
|
+
export const nanocodex_create: (a: number, b: number) => number;
|
|
63
|
+
export const nanocodex_createWithChatGpt: (a: number, b: number, c: number) => number;
|
|
64
|
+
export const nanocodex_endRealtimeConversation: (a: number) => number;
|
|
65
|
+
export const nanocodex_fork: (a: number) => number;
|
|
66
|
+
export const nanocodex_forkFrom: (a: number, b: number) => number;
|
|
67
|
+
export const nanocodex_interruptSubagent: (a: number, b: number, c: number) => number;
|
|
68
|
+
export const nanocodex_listSubagents: (a: number, b: number, c: number) => number;
|
|
69
|
+
export const nanocodex_prompt: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
70
|
+
export const nanocodex_promptContent: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
71
|
+
export const nanocodex_realtimeDelegation: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
72
|
+
export const nanocodex_realtimeTailDelegation: (a: number, b: number, c: number, d: number) => void;
|
|
73
|
+
export const nanocodex_restoreSubagents: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
74
|
+
export const nanocodex_routePrompt: (a: number, b: number, c: number) => number;
|
|
75
|
+
export const nanocodex_sendSubagentMessage: (a: number, b: number, c: number) => number;
|
|
76
|
+
export const nanocodex_sessionId: (a: number, b: number) => void;
|
|
77
|
+
export const nanocodex_setEventForwarding: (a: number, b: number) => void;
|
|
78
|
+
export const nanocodex_setFastMode: (a: number, b: number) => number;
|
|
79
|
+
export const nanocodex_setModel: (a: number, b: number, c: number) => number;
|
|
80
|
+
export const nanocodex_setThinking: (a: number, b: number, c: number) => number;
|
|
81
|
+
export const nanocodex_shutdown: (a: number) => number;
|
|
82
|
+
export const nanocodex_snapshot: (a: number) => number;
|
|
83
|
+
export const nanocodex_spawn: (a: number) => number;
|
|
84
|
+
export const nanocodex_spawnSubagent: (a: number, b: number, c: number) => number;
|
|
85
|
+
export const nanocodex_spawnSubagents: (a: number, b: number, c: number) => number;
|
|
86
|
+
export const nanocodex_startRealtimeConversation: (a: number) => number;
|
|
87
|
+
export const nanocodex_waitSubagents: (a: number, b: number, c: number) => number;
|
|
88
|
+
export const pruneDurableReceipts: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
89
|
+
export const turn_accepted: (a: number) => number;
|
|
90
|
+
export const turn_cancel: (a: number) => number;
|
|
91
|
+
export const turn_result: (a: number) => number;
|
|
92
|
+
export const turn_steer: (a: number, b: number, c: number) => number;
|
|
93
|
+
export const turn_steerContent: (a: number, b: number, c: number) => number;
|
|
94
|
+
export const turnresult_finalMessage: (a: number, b: number) => void;
|
|
95
|
+
export const turnresult_snapshot: (a: number, b: number) => void;
|
|
96
|
+
export const turnresult_usage: (a: number, b: number) => void;
|
|
97
|
+
export const __wasm_bindgen_func_elem_20354: (a: number, b: number, c: number, d: number) => void;
|
|
98
|
+
export const __wasm_bindgen_func_elem_20356: (a: number, b: number, c: number, d: number) => void;
|
|
99
|
+
export const __wasm_bindgen_func_elem_4730: (a: number, b: number) => void;
|
|
100
|
+
export const __wbindgen_export: (a: number, b: number) => number;
|
|
101
|
+
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
102
|
+
export const __wbindgen_export3: (a: number) => void;
|
|
103
|
+
export const __wbindgen_export4: (a: number, b: number) => void;
|
|
104
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
105
|
+
export const __wbindgen_export5: (a: number, b: number, c: number) => void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* @ts-self-types="./nanocodex.d.ts" */
|
|
2
|
+
import * as wasm from "./nanocodex_bg.wasm";
|
|
3
|
+
import { __wbg_set_wasm } from "./nanocodex_bg.js";
|
|
4
|
+
|
|
5
|
+
__wbg_set_wasm(wasm);
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
BrowserVoice, ChatGptSubscription, ManagedBrowserVoice, Nanocodex, Turn, TurnResult, applyBrowserPatch, managedBootstrapPlan, pruneDurableReceipts
|
|
9
|
+
} from "./nanocodex_bg.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
const hosts = new Map();
|
|
2
|
+
const RAW_SUBSCRIPTION = Symbol.for("nanocodex.chatgpt.subscription");
|
|
3
|
+
const DEFAULT_MAX_RESPONSE_BYTES = 16 * 1024;
|
|
4
|
+
|
|
5
|
+
export async function openSubscription(options, openRaw, { replaceHost = false } = {}) {
|
|
6
|
+
if (!options || typeof options !== "object") {
|
|
7
|
+
throw new TypeError("ChatGptSubscription.open requires options");
|
|
8
|
+
}
|
|
9
|
+
const id = requiredId(options.id);
|
|
10
|
+
const fetch = options.fetch;
|
|
11
|
+
const host = {
|
|
12
|
+
store: options.store,
|
|
13
|
+
// Cloudflare's global fetch requires the Worker global as its receiver.
|
|
14
|
+
// Keep the stored capability receiver-neutral so calling it through the
|
|
15
|
+
// host record cannot accidentally bind `this` to that record.
|
|
16
|
+
fetch: fetch === undefined
|
|
17
|
+
? (...args) => globalThis.fetch(...args)
|
|
18
|
+
: (...args) => fetch(...args),
|
|
19
|
+
references: 0,
|
|
20
|
+
};
|
|
21
|
+
validateHost(host);
|
|
22
|
+
bind(id, host, replaceHost);
|
|
23
|
+
try {
|
|
24
|
+
const raw = await openRaw(JSON.stringify({
|
|
25
|
+
id,
|
|
26
|
+
...(options.issuer === undefined ? {} : { issuer: options.issuer }),
|
|
27
|
+
...(options.seed === undefined ? {} : { seed: options.seed }),
|
|
28
|
+
}));
|
|
29
|
+
const view = Object.freeze({
|
|
30
|
+
id,
|
|
31
|
+
[RAW_SUBSCRIPTION]: raw,
|
|
32
|
+
async startLogin() {
|
|
33
|
+
return JSON.parse(await raw.startLogin());
|
|
34
|
+
},
|
|
35
|
+
async status() {
|
|
36
|
+
return JSON.parse(await raw.status());
|
|
37
|
+
},
|
|
38
|
+
async credential() {
|
|
39
|
+
return parseCredential(await raw.credential());
|
|
40
|
+
},
|
|
41
|
+
async recover(rejectedRevision) {
|
|
42
|
+
return parseCredential(await raw.recover(revision(
|
|
43
|
+
rejectedRevision,
|
|
44
|
+
"rejected credential revision",
|
|
45
|
+
)));
|
|
46
|
+
},
|
|
47
|
+
async logout() {
|
|
48
|
+
await raw.logout();
|
|
49
|
+
},
|
|
50
|
+
dispose() {
|
|
51
|
+
release(id, host);
|
|
52
|
+
raw.free();
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
host.references += 1;
|
|
56
|
+
return view;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
release(id, host);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function rawSubscription(subscription) {
|
|
64
|
+
const raw = subscription?.[RAW_SUBSCRIPTION];
|
|
65
|
+
if (!raw || typeof raw.status !== "function") {
|
|
66
|
+
throw new TypeError("subscription must be an open ChatGptSubscription");
|
|
67
|
+
}
|
|
68
|
+
return raw;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function load(subscriptionId) {
|
|
72
|
+
const stored = await requiredHost(subscriptionId).store.load(subscriptionId);
|
|
73
|
+
if (!stored || typeof stored !== "object") {
|
|
74
|
+
throw new TypeError("subscription store load() must return { revision, payload? }");
|
|
75
|
+
}
|
|
76
|
+
return JSON.stringify({
|
|
77
|
+
revision: revision(stored.revision, "subscription load revision"),
|
|
78
|
+
...(stored.payload === undefined || stored.payload === null
|
|
79
|
+
? {}
|
|
80
|
+
: { payload: requiredString(stored.payload, "subscription payload") }),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function compareAndSwap(subscriptionId, expectedRevision, payload) {
|
|
85
|
+
const result = await requiredHost(subscriptionId).store.compareAndSwap(subscriptionId, {
|
|
86
|
+
expectedRevision,
|
|
87
|
+
payload,
|
|
88
|
+
});
|
|
89
|
+
if (result?.status === "committed") {
|
|
90
|
+
return JSON.stringify({
|
|
91
|
+
status: "committed",
|
|
92
|
+
revision: revision(result.revision, "subscription commit revision"),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (result?.status === "conflict") {
|
|
96
|
+
return JSON.stringify({
|
|
97
|
+
status: "conflict",
|
|
98
|
+
actual_revision: revision(result.actualRevision, "subscription conflict revision"),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
throw new TypeError("subscription compareAndSwap() must return committed or conflict");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function request(subscriptionId, encoded) {
|
|
105
|
+
const host = requiredHost(subscriptionId);
|
|
106
|
+
const request = JSON.parse(encoded);
|
|
107
|
+
if (request.method !== "POST") throw new TypeError("subscription HTTP method must be POST");
|
|
108
|
+
const url = new URL(request.url);
|
|
109
|
+
if (url.origin !== "https://auth.openai.com" && url.hostname !== "127.0.0.1") {
|
|
110
|
+
throw new TypeError("subscription HTTP is restricted to auth.openai.com");
|
|
111
|
+
}
|
|
112
|
+
const maxResponseBytes = positiveInteger(
|
|
113
|
+
request.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES,
|
|
114
|
+
"subscription response limit",
|
|
115
|
+
);
|
|
116
|
+
const response = await host.fetch(url, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers: { "content-type": requiredString(request.contentType, "subscription content type") },
|
|
119
|
+
body: requiredString(request.body, "subscription request body"),
|
|
120
|
+
redirect: "manual",
|
|
121
|
+
});
|
|
122
|
+
if (!(response instanceof Response)) {
|
|
123
|
+
throw new TypeError("subscription fetch() must return a Response");
|
|
124
|
+
}
|
|
125
|
+
return JSON.stringify({
|
|
126
|
+
status: response.status,
|
|
127
|
+
body: await readBoundedText(response, maxResponseBytes),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function bind(id, host, replaceHost) {
|
|
132
|
+
if (!replaceHost && hosts.has(id)) {
|
|
133
|
+
throw new Error(`ChatGPT subscription is already open: ${id}`);
|
|
134
|
+
}
|
|
135
|
+
hosts.set(id, host);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function release(id, host) {
|
|
139
|
+
if (hosts.get(id) !== host) return;
|
|
140
|
+
if (host.references > 0) host.references -= 1;
|
|
141
|
+
if (host.references === 0) hosts.delete(id);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function requiredHost(id) {
|
|
145
|
+
const host = hosts.get(id);
|
|
146
|
+
if (!host) throw new Error(`no host owns ChatGPT subscription: ${id}`);
|
|
147
|
+
return host;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function validateHost(host) {
|
|
151
|
+
if (!host.store || typeof host.store.load !== "function"
|
|
152
|
+
|| typeof host.store.compareAndSwap !== "function") {
|
|
153
|
+
throw new TypeError("ChatGPT subscription requires load and compareAndSwap storage");
|
|
154
|
+
}
|
|
155
|
+
if (typeof host.fetch !== "function") {
|
|
156
|
+
throw new TypeError("ChatGPT subscription requires a fetch capability");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function readBoundedText(response, limit) {
|
|
161
|
+
if (!response.body) return "";
|
|
162
|
+
const reader = response.body.getReader();
|
|
163
|
+
const decoder = new TextDecoder();
|
|
164
|
+
let size = 0;
|
|
165
|
+
let body = "";
|
|
166
|
+
while (true) {
|
|
167
|
+
const { done, value } = await reader.read();
|
|
168
|
+
if (done) return body + decoder.decode();
|
|
169
|
+
size += value.byteLength;
|
|
170
|
+
if (size > limit) {
|
|
171
|
+
await reader.cancel();
|
|
172
|
+
throw new Error(`subscription response exceeded ${limit} bytes`);
|
|
173
|
+
}
|
|
174
|
+
body += decoder.decode(value, { stream: true });
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function revision(value, name) {
|
|
179
|
+
if (typeof value !== "string" || !/^(0|[1-9][0-9]*)$/.test(value)) {
|
|
180
|
+
throw new TypeError(`${name} must be an unsigned decimal string`);
|
|
181
|
+
}
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function requiredId(value) {
|
|
186
|
+
if (typeof value !== "string" || !/^[A-Za-z0-9._:-]{1,200}$/.test(value)) {
|
|
187
|
+
throw new TypeError("subscription id must be a bounded stable identifier");
|
|
188
|
+
}
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function requiredString(value, name) {
|
|
193
|
+
if (typeof value !== "string") throw new TypeError(`${name} must be a string`);
|
|
194
|
+
return value;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function positiveInteger(value, name) {
|
|
198
|
+
if (!Number.isSafeInteger(value) || value <= 0) throw new TypeError(`${name} must be positive`);
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function parseCredential(encoded) {
|
|
203
|
+
const credential = JSON.parse(encoded);
|
|
204
|
+
if (credential?.kind !== "chatgpt" || typeof credential.accessToken !== "string"
|
|
205
|
+
|| typeof credential.accountId !== "string" || typeof credential.fedramp !== "boolean") {
|
|
206
|
+
throw new TypeError("Rust returned an invalid ChatGPT credential");
|
|
207
|
+
}
|
|
208
|
+
return Object.freeze({
|
|
209
|
+
...credential,
|
|
210
|
+
revision: revision(credential.revision, "credential revision"),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DurabilitySqliteRow,
|
|
3
|
+
DurabilitySqliteValue,
|
|
4
|
+
DurabilityPortableStore,
|
|
5
|
+
} from "../types.mjs";
|
|
6
|
+
|
|
7
|
+
export type CloudflareDurableObjectStorage = Readonly<{
|
|
8
|
+
sql: Readonly<{
|
|
9
|
+
exec<Row extends DurabilitySqliteRow>(
|
|
10
|
+
sql: string,
|
|
11
|
+
...bindings: readonly DurabilitySqliteValue[]
|
|
12
|
+
): Readonly<{
|
|
13
|
+
toArray(): readonly Row[];
|
|
14
|
+
[Symbol.iterator](): IterableIterator<Row>;
|
|
15
|
+
}>;
|
|
16
|
+
}>;
|
|
17
|
+
transactionSync<Result>(callback: () => Result): Result;
|
|
18
|
+
}>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Initializes and adapts one Durable Object's colocated SQLite durable state.
|
|
22
|
+
* Rust owns the opaque total-state payload; the host only provides atomic storage.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createCloudflareDurabilityStore(
|
|
25
|
+
storage: CloudflareDurableObjectStorage,
|
|
26
|
+
): DurabilityPortableStore;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { createSqliteDurabilityStore, sqliteDurabilitySchema } from "./durability-store.mjs";
|
|
2
|
+
|
|
3
|
+
const DIRECT_PAYLOAD_BYTES = 1_000_000;
|
|
4
|
+
const PAYLOAD_CHUNK_CODE_UNITS = 256_000;
|
|
5
|
+
const encoder = new TextEncoder();
|
|
6
|
+
|
|
7
|
+
const cloudflareDurabilitySchema = Object.freeze([
|
|
8
|
+
...sqliteDurabilitySchema,
|
|
9
|
+
`CREATE TABLE IF NOT EXISTS nanocodex_durable_chunk_heads (
|
|
10
|
+
state_id TEXT PRIMARY KEY,
|
|
11
|
+
revision TEXT NOT NULL,
|
|
12
|
+
chunk_count INTEGER NOT NULL CHECK (chunk_count > 0)
|
|
13
|
+
)`,
|
|
14
|
+
`CREATE TABLE IF NOT EXISTS nanocodex_durable_state_chunks (
|
|
15
|
+
state_id TEXT NOT NULL,
|
|
16
|
+
revision TEXT NOT NULL,
|
|
17
|
+
chunk_index INTEGER NOT NULL,
|
|
18
|
+
payload TEXT NOT NULL,
|
|
19
|
+
PRIMARY KEY (state_id, revision, chunk_index)
|
|
20
|
+
)`,
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
/** Adapts one Cloudflare Durable Object's colocated SQLite to Nanocodex. */
|
|
24
|
+
export function createCloudflareDurabilityStore(storage) {
|
|
25
|
+
if (
|
|
26
|
+
!storage?.sql
|
|
27
|
+
|| typeof storage.sql.exec !== "function"
|
|
28
|
+
|| typeof storage.transactionSync !== "function"
|
|
29
|
+
) {
|
|
30
|
+
throw new TypeError("Cloudflare durability requires Durable Object storage with SQLite");
|
|
31
|
+
}
|
|
32
|
+
const raw = (sql, args) => {
|
|
33
|
+
const cursor = storage.sql.exec(sql, ...args);
|
|
34
|
+
if (typeof cursor?.[Symbol.iterator] !== "function") return cursor.toArray();
|
|
35
|
+
return [...cursor];
|
|
36
|
+
};
|
|
37
|
+
for (const statement of cloudflareDurabilitySchema) storage.sql.exec(statement);
|
|
38
|
+
validateSchema(raw);
|
|
39
|
+
const query = (sql, args) => {
|
|
40
|
+
if (sql.startsWith("INSERT INTO nanocodex_durable_states")) {
|
|
41
|
+
return replaceState(raw, sql, args);
|
|
42
|
+
}
|
|
43
|
+
const rows = raw(sql, args);
|
|
44
|
+
return sql.startsWith("SELECT revision, payload FROM nanocodex_durable_states")
|
|
45
|
+
? hydrateState(raw, args[0], rows)
|
|
46
|
+
: rows;
|
|
47
|
+
};
|
|
48
|
+
return createSqliteDurabilityStore({
|
|
49
|
+
transaction: (callback) => storage.transactionSync(() => callback(query)),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function validateSchema(query) {
|
|
54
|
+
const tables = [
|
|
55
|
+
["nanocodex_durable_owners", [
|
|
56
|
+
["state_id", "TEXT", 0, 1], ["owner_id", "TEXT", 1, 0], ["fence", "TEXT", 1, 0],
|
|
57
|
+
]],
|
|
58
|
+
["nanocodex_durable_states", [
|
|
59
|
+
["state_id", "TEXT", 0, 1], ["revision", "TEXT", 1, 0], ["payload", "TEXT", 1, 0],
|
|
60
|
+
]],
|
|
61
|
+
["nanocodex_durable_chunk_heads", [
|
|
62
|
+
["state_id", "TEXT", 0, 1], ["revision", "TEXT", 1, 0], ["chunk_count", "INTEGER", 1, 0],
|
|
63
|
+
]],
|
|
64
|
+
["nanocodex_durable_state_chunks", [
|
|
65
|
+
["state_id", "TEXT", 1, 1], ["revision", "TEXT", 1, 2],
|
|
66
|
+
["chunk_index", "INTEGER", 1, 3], ["payload", "TEXT", 1, 0],
|
|
67
|
+
]],
|
|
68
|
+
];
|
|
69
|
+
for (const [table, expected] of tables) {
|
|
70
|
+
const rows = query(`PRAGMA table_info('${table}')`, []);
|
|
71
|
+
const valid = rows.length === expected.length && rows.every((row, index) => {
|
|
72
|
+
const shape = expected[index];
|
|
73
|
+
return row.name === shape[0]
|
|
74
|
+
&& String(row.type).toUpperCase() === shape[1]
|
|
75
|
+
&& Number(row.notnull) === shape[2]
|
|
76
|
+
&& Number(row.pk) === shape[3];
|
|
77
|
+
});
|
|
78
|
+
if (!valid) {
|
|
79
|
+
throw new Error(`incompatible Cloudflare durability schema for ${table}; recreate it`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function replaceState(query, sql, [stateId, revision, payload]) {
|
|
85
|
+
if (typeof payload !== "string") {
|
|
86
|
+
throw new TypeError("durability state payload must be a string");
|
|
87
|
+
}
|
|
88
|
+
query("DELETE FROM nanocodex_durable_chunk_heads WHERE state_id = ?", [stateId]);
|
|
89
|
+
query("DELETE FROM nanocodex_durable_state_chunks WHERE state_id = ?", [stateId]);
|
|
90
|
+
// UTF-8 needs at least one byte per UTF-16 code unit. Do not allocate
|
|
91
|
+
// another full-state byte buffer just to decide an already-large payload
|
|
92
|
+
// needs chunks. The remaining encoding is bounded by the inline threshold.
|
|
93
|
+
if (payload.length <= DIRECT_PAYLOAD_BYTES
|
|
94
|
+
&& encoder.encode(payload).byteLength <= DIRECT_PAYLOAD_BYTES) {
|
|
95
|
+
return query(sql, [stateId, revision, payload]);
|
|
96
|
+
}
|
|
97
|
+
const result = query(sql, [stateId, revision, ""]);
|
|
98
|
+
const chunks = payloadChunks(payload);
|
|
99
|
+
query(
|
|
100
|
+
`INSERT INTO nanocodex_durable_chunk_heads (state_id, revision, chunk_count)
|
|
101
|
+
VALUES (?, ?, ?)`,
|
|
102
|
+
[stateId, revision, chunks.length],
|
|
103
|
+
);
|
|
104
|
+
for (let index = 0; index < chunks.length; index += 1) {
|
|
105
|
+
query(
|
|
106
|
+
`INSERT INTO nanocodex_durable_state_chunks
|
|
107
|
+
(state_id, revision, chunk_index, payload) VALUES (?, ?, ?, ?)`,
|
|
108
|
+
[stateId, revision, index, chunks[index]],
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function hydrateState(query, stateId, rows) {
|
|
115
|
+
if (rows.length === 0) return rows;
|
|
116
|
+
if (rows.length !== 1) throw new Error("Cloudflare durability retained duplicate states");
|
|
117
|
+
const row = rows[0];
|
|
118
|
+
const head = query(
|
|
119
|
+
`SELECT revision, chunk_count FROM nanocodex_durable_chunk_heads
|
|
120
|
+
WHERE state_id = ?`,
|
|
121
|
+
[stateId],
|
|
122
|
+
)[0];
|
|
123
|
+
if (!head) return rows;
|
|
124
|
+
if (head.revision !== row.revision || row.payload !== "") {
|
|
125
|
+
throw new Error("invalid Cloudflare durability chunk head");
|
|
126
|
+
}
|
|
127
|
+
const chunks = query(
|
|
128
|
+
`SELECT revision, chunk_index, payload FROM nanocodex_durable_state_chunks
|
|
129
|
+
WHERE state_id = ? ORDER BY chunk_index`,
|
|
130
|
+
[stateId],
|
|
131
|
+
);
|
|
132
|
+
if (chunks.length !== head.chunk_count) {
|
|
133
|
+
throw new Error(`missing Cloudflare durability chunks for revision ${row.revision} (expected ${head.chunk_count}, found ${chunks.length})`);
|
|
134
|
+
}
|
|
135
|
+
for (let index = 0; index < chunks.length; index += 1) {
|
|
136
|
+
const chunk = chunks[index];
|
|
137
|
+
if (chunk.revision !== row.revision || chunk.chunk_index !== index
|
|
138
|
+
|| typeof chunk.payload !== "string") {
|
|
139
|
+
throw new Error(`invalid Cloudflare durability chunks for revision ${row.revision}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return [{ ...row, payload: chunks.map((chunk) => chunk.payload).join("") }];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function payloadChunks(payload) {
|
|
146
|
+
const chunks = [];
|
|
147
|
+
for (let offset = 0; offset < payload.length;) {
|
|
148
|
+
let end = Math.min(offset + PAYLOAD_CHUNK_CODE_UNITS, payload.length);
|
|
149
|
+
if (
|
|
150
|
+
end < payload.length
|
|
151
|
+
&& isHighSurrogate(payload.charCodeAt(end - 1))
|
|
152
|
+
&& isLowSurrogate(payload.charCodeAt(end))
|
|
153
|
+
) {
|
|
154
|
+
end -= 1;
|
|
155
|
+
}
|
|
156
|
+
chunks.push(payload.slice(offset, end));
|
|
157
|
+
offset = end;
|
|
158
|
+
}
|
|
159
|
+
return chunks;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function isHighSurrogate(codeUnit) {
|
|
163
|
+
return codeUnit >= 0xd800 && codeUnit <= 0xdbff;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function isLowSurrogate(codeUnit) {
|
|
167
|
+
return codeUnit >= 0xdc00 && codeUnit <= 0xdfff;
|
|
168
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { installBrowserEgressFetch } from "../tools/browser/browserEgress.mjs";
|
|
2
|
+
|
|
3
|
+
const WORKER_PROTOCOL = "nanocodex.code-evaluator.v1";
|
|
4
|
+
const pendingTools = new Map();
|
|
5
|
+
const toolInvocations = [];
|
|
6
|
+
let nextToolCall = 1;
|
|
7
|
+
let evaluating = false;
|
|
8
|
+
let evaluationId;
|
|
9
|
+
|
|
10
|
+
globalThis.onmessage = ({ data }) => {
|
|
11
|
+
if (data?.protocol !== WORKER_PROTOCOL) return;
|
|
12
|
+
if (data.type === "tool.result") {
|
|
13
|
+
if (data.evaluationId !== evaluationId) return;
|
|
14
|
+
const pending = pendingTools.get(data.id);
|
|
15
|
+
if (!pending) return;
|
|
16
|
+
pendingTools.delete(data.id);
|
|
17
|
+
(data.ok ? pending.resolve : pending.reject)(data.value);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (data.type !== "evaluate" || evaluating) return;
|
|
21
|
+
if (data.egress) installBrowserEgressFetch(data.egress);
|
|
22
|
+
evaluating = true;
|
|
23
|
+
evaluationId = data.evaluationId;
|
|
24
|
+
void evaluate(data).then(
|
|
25
|
+
(storedWrites) => post("completed", { storedWrites }),
|
|
26
|
+
({ error, storedWrites }) => post("failed", { error: errorMessage(error), storedWrites }),
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
async function evaluate({ source, storedEntries = [], toolDefinitions = [], toolNames = [] }) {
|
|
31
|
+
const stored = new Map(storedEntries);
|
|
32
|
+
const storedWrites = new Map();
|
|
33
|
+
const tools = Object.create(null);
|
|
34
|
+
for (const name of toolNames) tools[name] = (input) => callTool(name, input);
|
|
35
|
+
const callableTools = new Proxy(tools, {
|
|
36
|
+
get(target, property) {
|
|
37
|
+
if (typeof property !== "string") return Reflect.get(target, property);
|
|
38
|
+
return target[property] ?? ((input) => callTool(property, input));
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
Object.freeze(tools);
|
|
42
|
+
|
|
43
|
+
const text = (value) => post("output", { kind: "text", value });
|
|
44
|
+
const image = (value, detail) => post("output", {
|
|
45
|
+
kind: "image",
|
|
46
|
+
value,
|
|
47
|
+
detail,
|
|
48
|
+
});
|
|
49
|
+
const audio = (value) => post("output", { kind: "audio", value });
|
|
50
|
+
const notify = (value) => post("output", { kind: "notify", value });
|
|
51
|
+
const yield_control = () => post("output", { kind: "yield_control" });
|
|
52
|
+
const generatedImage = (value) => post("output", { kind: "generatedImage", value });
|
|
53
|
+
const store = (key, value) => {
|
|
54
|
+
if (typeof key !== "string") throw new TypeError("store key must be a string");
|
|
55
|
+
const snapshot = structuredClone(value);
|
|
56
|
+
stored.set(key, snapshot);
|
|
57
|
+
storedWrites.set(key, snapshot);
|
|
58
|
+
};
|
|
59
|
+
const load = (key) => stored.has(key) ? structuredClone(stored.get(key)) : undefined;
|
|
60
|
+
const EXIT = Symbol("exit");
|
|
61
|
+
const exit = () => { throw EXIT; };
|
|
62
|
+
const guestConsole = Object.freeze(Object.fromEntries(
|
|
63
|
+
["debug", "info", "log", "warn", "error"].map((level) => [level, (...values) => {
|
|
64
|
+
post("console", { level, values: values.map(stringify) });
|
|
65
|
+
}]),
|
|
66
|
+
));
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
|
|
70
|
+
const script = new AsyncFunction(
|
|
71
|
+
"tools",
|
|
72
|
+
"ALL_TOOLS",
|
|
73
|
+
"text",
|
|
74
|
+
"image",
|
|
75
|
+
"generatedImage",
|
|
76
|
+
"audio",
|
|
77
|
+
"notify",
|
|
78
|
+
"yield_control",
|
|
79
|
+
"store",
|
|
80
|
+
"load",
|
|
81
|
+
"exit",
|
|
82
|
+
"require",
|
|
83
|
+
"console",
|
|
84
|
+
source,
|
|
85
|
+
);
|
|
86
|
+
try {
|
|
87
|
+
await script(
|
|
88
|
+
callableTools,
|
|
89
|
+
Object.freeze(toolDefinitions),
|
|
90
|
+
text,
|
|
91
|
+
image,
|
|
92
|
+
generatedImage,
|
|
93
|
+
audio,
|
|
94
|
+
notify,
|
|
95
|
+
yield_control,
|
|
96
|
+
store,
|
|
97
|
+
load,
|
|
98
|
+
exit,
|
|
99
|
+
undefined,
|
|
100
|
+
guestConsole,
|
|
101
|
+
);
|
|
102
|
+
} finally {
|
|
103
|
+
// Discarding a tool Promise or calling exit() must not orphan parent-held
|
|
104
|
+
// work. The evaluator remains alive until each invocation receives its
|
|
105
|
+
// terminal response, or its supervisor terminates this cell on cancel.
|
|
106
|
+
await Promise.allSettled(toolInvocations);
|
|
107
|
+
}
|
|
108
|
+
return [...storedWrites];
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (error === EXIT) return [...storedWrites];
|
|
111
|
+
throw { error, storedWrites: [...storedWrites] };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function callTool(name, input) {
|
|
116
|
+
const id = nextToolCall++;
|
|
117
|
+
const invocation = new Promise((resolve, reject) => {
|
|
118
|
+
pendingTools.set(id, { resolve, reject });
|
|
119
|
+
post("tool.call", { id, input: input ?? null, name });
|
|
120
|
+
});
|
|
121
|
+
toolInvocations.push(invocation.then(() => undefined, () => undefined));
|
|
122
|
+
return invocation;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function post(type, value = {}) {
|
|
126
|
+
globalThis.postMessage({ protocol: WORKER_PROTOCOL, evaluationId, type, ...value });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function stringify(value) {
|
|
130
|
+
if (typeof value === "string") return value;
|
|
131
|
+
if (value === undefined) return "undefined";
|
|
132
|
+
try { return JSON.stringify(value); } catch { return String(value); }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function errorMessage(error) {
|
|
136
|
+
return error && (error.stack || error.message) ? error.stack || error.message : String(error);
|
|
137
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../nanocodex-tools/runtime/code-runtime.mjs";
|