@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,236 @@
|
|
|
1
|
+
const DEFAULT_MEMORY_LIMIT_BYTES = 64 * 1024 * 1024;
|
|
2
|
+
const DEFAULT_STACK_LIMIT_BYTES = 512 * 1024;
|
|
3
|
+
const DEFAULT_INTERRUPT_CYCLES = 1_000_000;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Builds a Code Mode evaluator for runtimes that reject eval/new Function.
|
|
7
|
+
* Pass an asyncified QuickJS WASM module from quickjs-emscripten-core.
|
|
8
|
+
*/
|
|
9
|
+
export function createQuickJsEvaluator(quickJs, options = {}) {
|
|
10
|
+
if (!quickJs || typeof quickJs.newContext !== "function") {
|
|
11
|
+
throw new TypeError("quickJs must be an asyncified QuickJS WASM module");
|
|
12
|
+
}
|
|
13
|
+
let queue = Promise.resolve();
|
|
14
|
+
|
|
15
|
+
return (source, environment) => {
|
|
16
|
+
const evaluation = queue.then(() => evaluate(quickJs, source, environment, options));
|
|
17
|
+
queue = evaluation.catch(() => {});
|
|
18
|
+
return evaluation;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function evaluate(quickJs, source, environment, options) {
|
|
23
|
+
environment.signal?.throwIfAborted();
|
|
24
|
+
const vm = quickJs.newContext();
|
|
25
|
+
const runtime = vm.runtime;
|
|
26
|
+
runtime.setMemoryLimit(options.memoryLimitBytes ?? DEFAULT_MEMORY_LIMIT_BYTES);
|
|
27
|
+
runtime.setMaxStackSize(options.stackLimitBytes ?? DEFAULT_STACK_LIMIT_BYTES);
|
|
28
|
+
let interruptCycles = 0;
|
|
29
|
+
const maxInterruptCycles = options.maxInterruptCycles ?? DEFAULT_INTERRUPT_CYCLES;
|
|
30
|
+
let aborted = environment.signal?.aborted === true;
|
|
31
|
+
const onAbort = () => { aborted = true; };
|
|
32
|
+
environment.signal?.addEventListener("abort", onAbort, { once: true });
|
|
33
|
+
runtime.setInterruptHandler(() => aborted || ++interruptCycles > maxInterruptCycles);
|
|
34
|
+
let closed = false;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
expose(vm, "__nanocodex_call_tool", (nameHandle, inputHandle) => {
|
|
38
|
+
const name = vm.getString(nameHandle);
|
|
39
|
+
const input = vm.getString(inputHandle);
|
|
40
|
+
const deferred = vm.newPromise();
|
|
41
|
+
invokeTool(environment, name, input).then((encoded) => {
|
|
42
|
+
if (closed) return;
|
|
43
|
+
vm.newString(encoded).consume(deferred.resolve);
|
|
44
|
+
runtime.executePendingJobs().unwrap();
|
|
45
|
+
});
|
|
46
|
+
return deferred.handle;
|
|
47
|
+
});
|
|
48
|
+
expose(vm, "__nanocodex_emit", (kindHandle, payloadHandle) => {
|
|
49
|
+
const kind = vm.getString(kindHandle);
|
|
50
|
+
const payload = JSON.parse(vm.getString(payloadHandle));
|
|
51
|
+
if (kind === "text") environment.text(payload);
|
|
52
|
+
else if (kind === "image") environment.image(payload.value, payload.detail);
|
|
53
|
+
else if (kind === "audio") environment.audio(payload);
|
|
54
|
+
else if (kind === "notify") environment.notify(payload);
|
|
55
|
+
else if (kind === "yield_control") environment.yield_control();
|
|
56
|
+
else if (kind === "generatedImage") environment.generatedImage(payload);
|
|
57
|
+
else throw new Error(`unknown Code Mode output kind: ${kind}`);
|
|
58
|
+
});
|
|
59
|
+
expose(vm, "__nanocodex_sleep", (delayHandle) => {
|
|
60
|
+
const deferred = vm.newPromise();
|
|
61
|
+
environment.setTimeout(() => {
|
|
62
|
+
if (closed) return;
|
|
63
|
+
deferred.resolve();
|
|
64
|
+
runtime.executePendingJobs().unwrap();
|
|
65
|
+
}, vm.getNumber(delayHandle));
|
|
66
|
+
return deferred.handle;
|
|
67
|
+
});
|
|
68
|
+
expose(vm, "__nanocodex_store", (keyHandle, valueHandle) => {
|
|
69
|
+
const key = vm.getString(keyHandle);
|
|
70
|
+
const envelope = JSON.parse(vm.getString(valueHandle));
|
|
71
|
+
environment.store(key, envelope.value);
|
|
72
|
+
});
|
|
73
|
+
expose(vm, "__nanocodex_load", (keyHandle) => {
|
|
74
|
+
const value = environment.load(vm.getString(keyHandle));
|
|
75
|
+
return vm.newString(JSON.stringify({ value }));
|
|
76
|
+
});
|
|
77
|
+
expose(vm, "__nanocodex_log", (levelHandle, valuesHandle) => {
|
|
78
|
+
const level = vm.getString(levelHandle);
|
|
79
|
+
const values = JSON.parse(vm.getString(valuesHandle));
|
|
80
|
+
const logger = typeof environment.console?.[level] === "function"
|
|
81
|
+
? environment.console[level]
|
|
82
|
+
: environment.console?.log;
|
|
83
|
+
logger?.(...values);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const setup = guestSource(
|
|
87
|
+
source,
|
|
88
|
+
Object.keys(environment.tools),
|
|
89
|
+
environment.toolDefinitions,
|
|
90
|
+
);
|
|
91
|
+
const started = await vm.evalCodeAsync(setup, "nanocodex-code-mode.js");
|
|
92
|
+
const promise = unwrap(vm, started);
|
|
93
|
+
try {
|
|
94
|
+
const settling = vm.resolvePromise(promise);
|
|
95
|
+
runtime.executePendingJobs().unwrap();
|
|
96
|
+
const settled = await abortable(settling, environment.signal);
|
|
97
|
+
unwrap(vm, settled).dispose();
|
|
98
|
+
} finally {
|
|
99
|
+
promise.dispose();
|
|
100
|
+
}
|
|
101
|
+
} finally {
|
|
102
|
+
closed = true;
|
|
103
|
+
environment.signal?.removeEventListener("abort", onAbort);
|
|
104
|
+
vm.dispose();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function abortable(promise, signal) {
|
|
109
|
+
if (!signal) return promise;
|
|
110
|
+
if (signal.aborted) return Promise.reject(signal.reason);
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
const onAbort = () => reject(signal.reason ?? new Error("Code Mode execution was cancelled"));
|
|
113
|
+
const settle = (callback, value) => {
|
|
114
|
+
signal.removeEventListener("abort", onAbort);
|
|
115
|
+
callback(value);
|
|
116
|
+
};
|
|
117
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
118
|
+
Promise.resolve(promise).then(
|
|
119
|
+
(value) => settle(resolve, value),
|
|
120
|
+
(error) => settle(reject, error),
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function expose(vm, name, handler) {
|
|
126
|
+
vm.newFunction(name, handler).consume((handle) => vm.setProp(vm.global, name, handle));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function exposeAsync(vm, name, handler) {
|
|
130
|
+
if (typeof vm.newAsyncifiedFunction !== "function") {
|
|
131
|
+
throw new TypeError("QuickJS module must use an asyncify variant");
|
|
132
|
+
}
|
|
133
|
+
vm.newAsyncifiedFunction(name, handler).consume((handle) => vm.setProp(vm.global, name, handle));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function unwrap(vm, result) {
|
|
137
|
+
if (result.error) {
|
|
138
|
+
const dumped = vm.dump(result.error);
|
|
139
|
+
result.error.dispose();
|
|
140
|
+
throw new Error(formatQuickJsError(dumped));
|
|
141
|
+
}
|
|
142
|
+
return result.value;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function formatQuickJsError(error) {
|
|
146
|
+
if (typeof error === "string") return error;
|
|
147
|
+
if (error && typeof error === "object") {
|
|
148
|
+
if (typeof error.stack === "string") {
|
|
149
|
+
return typeof error.message === "string" && !error.stack.includes(error.message)
|
|
150
|
+
? `${error.message}\n${error.stack}`
|
|
151
|
+
: error.stack;
|
|
152
|
+
}
|
|
153
|
+
if (typeof error.message === "string") return error.message;
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
return JSON.stringify(error);
|
|
157
|
+
} catch {
|
|
158
|
+
return String(error);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function guestSource(source, toolNames, toolDefinitions) {
|
|
163
|
+
return `
|
|
164
|
+
const __nanocodex_exit = Symbol("exit");
|
|
165
|
+
const __nanocodex_stringify = (value) => {
|
|
166
|
+
if (typeof value === "string") return value;
|
|
167
|
+
if (value === undefined) return "undefined";
|
|
168
|
+
try { return JSON.stringify(value); } catch { return String(value); }
|
|
169
|
+
};
|
|
170
|
+
const __nanocodex_decode = (encoded) => {
|
|
171
|
+
const result = JSON.parse(encoded);
|
|
172
|
+
if (!result.ok) throw new Error(result.error);
|
|
173
|
+
return result.value;
|
|
174
|
+
};
|
|
175
|
+
const tools = Object.freeze(Object.fromEntries(
|
|
176
|
+
${JSON.stringify(toolNames)}.map((name) => [name, (input) =>
|
|
177
|
+
__nanocodex_call_tool(name, JSON.stringify(input ?? null)).then(__nanocodex_decode)])
|
|
178
|
+
));
|
|
179
|
+
const ALL_TOOLS = Object.freeze(${JSON.stringify(toolDefinitions)});
|
|
180
|
+
const text = (value) => __nanocodex_emit("text", JSON.stringify(__nanocodex_stringify(value)));
|
|
181
|
+
const image = (value, detail) =>
|
|
182
|
+
__nanocodex_emit("image", JSON.stringify({ value, detail }));
|
|
183
|
+
const audio = (value) => __nanocodex_emit("audio", JSON.stringify(value));
|
|
184
|
+
const notify = (value) => __nanocodex_emit("notify", JSON.stringify(__nanocodex_stringify(value)));
|
|
185
|
+
const yield_control = () => __nanocodex_emit("yield_control", "null");
|
|
186
|
+
const __nanocodex_timers = new Map();
|
|
187
|
+
let __nanocodex_next_timer = 1;
|
|
188
|
+
const setTimeout = (callback, delay = 0) => {
|
|
189
|
+
const id = __nanocodex_next_timer++;
|
|
190
|
+
__nanocodex_timers.set(id, callback);
|
|
191
|
+
__nanocodex_sleep(Number(delay) || 0).then(() => {
|
|
192
|
+
const callback = __nanocodex_timers.get(id);
|
|
193
|
+
__nanocodex_timers.delete(id);
|
|
194
|
+
callback?.();
|
|
195
|
+
});
|
|
196
|
+
return id;
|
|
197
|
+
};
|
|
198
|
+
const clearTimeout = (id) => __nanocodex_timers.delete(id);
|
|
199
|
+
const generatedImage = (value) =>
|
|
200
|
+
__nanocodex_emit("generatedImage", JSON.stringify(value));
|
|
201
|
+
const store = (key, value) => {
|
|
202
|
+
if (typeof key !== "string") throw new TypeError("store key must be a string");
|
|
203
|
+
__nanocodex_store(key, JSON.stringify({ value }));
|
|
204
|
+
};
|
|
205
|
+
const load = (key) => JSON.parse(__nanocodex_load(key)).value;
|
|
206
|
+
const exit = () => { throw __nanocodex_exit; };
|
|
207
|
+
const require = undefined;
|
|
208
|
+
const console = Object.freeze(Object.fromEntries(
|
|
209
|
+
["debug", "info", "log", "warn", "error"].map((level) => [level, (...values) =>
|
|
210
|
+
__nanocodex_log(level, JSON.stringify(values.map(__nanocodex_stringify)))])
|
|
211
|
+
));
|
|
212
|
+
(async () => {
|
|
213
|
+
try {
|
|
214
|
+
${source}
|
|
215
|
+
} catch (error) {
|
|
216
|
+
if (error !== __nanocodex_exit) throw error;
|
|
217
|
+
}
|
|
218
|
+
})()
|
|
219
|
+
`;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function errorMessage(error) {
|
|
223
|
+
if (error && (error.stack || error.message)) return error.stack || error.message;
|
|
224
|
+
return String(error);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function invokeTool(environment, name, encodedInput) {
|
|
228
|
+
try {
|
|
229
|
+
const tool = environment.tools[name];
|
|
230
|
+
if (typeof tool !== "function") throw new Error(`unknown application tool: ${name}`);
|
|
231
|
+
const value = await tool(JSON.parse(encodedInput));
|
|
232
|
+
return JSON.stringify({ ok: true, value });
|
|
233
|
+
} catch (error) {
|
|
234
|
+
return JSON.stringify({ ok: false, error: errorMessage(error) });
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const responsesTransports = new WeakMap();
|
|
2
|
+
|
|
3
|
+
export function createResponsesTransport(setup) {
|
|
4
|
+
const transport = Object.freeze({});
|
|
5
|
+
responsesTransports.set(transport, Object.freeze({ ...setup }));
|
|
6
|
+
return transport;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function resolveResponsesTransport(transport) {
|
|
10
|
+
const setup = responsesTransports.get(transport);
|
|
11
|
+
if (setup === undefined) {
|
|
12
|
+
throw new TypeError("Agent.create requires a Responses transport");
|
|
13
|
+
}
|
|
14
|
+
return setup;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function nonEmpty(value, label) {
|
|
18
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
19
|
+
throw new TypeError(`${label} must be a non-empty string`);
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { DefaultAgent, Thinking } from "../types.mjs";
|
|
2
|
+
|
|
3
|
+
// Adapter-specific extend() signatures do not change subagent ownership.
|
|
4
|
+
type SubagentOwner = Omit<DefaultAgent, "extend">;
|
|
5
|
+
|
|
6
|
+
declare const subagentToolBrand: unique symbol;
|
|
7
|
+
|
|
8
|
+
/** Opaque selector for the Rust-owned subagent tool set. */
|
|
9
|
+
export type Tool = Readonly<{
|
|
10
|
+
[subagentToolBrand]: true;
|
|
11
|
+
}>;
|
|
12
|
+
|
|
13
|
+
export type Subagents = readonly [Tool];
|
|
14
|
+
|
|
15
|
+
export interface Options {
|
|
16
|
+
/** Optional finite concurrency limit. Omit for unlimited active turns. */
|
|
17
|
+
maxConcurrency?: number | undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type AgentId = number;
|
|
21
|
+
export type AgentStatus =
|
|
22
|
+
| Readonly<{ state: "pending" | "running" | "interrupted" | "closing" | "closed" }>
|
|
23
|
+
| Readonly<{ state: "completed"; output: unknown }>
|
|
24
|
+
| Readonly<{ state: "failed"; error: string }>;
|
|
25
|
+
export type AgentSummary = Readonly<{
|
|
26
|
+
agent_id: AgentId;
|
|
27
|
+
role: string;
|
|
28
|
+
task: string;
|
|
29
|
+
parent_agent_id: AgentId | null;
|
|
30
|
+
status: AgentStatus;
|
|
31
|
+
last_output?: unknown;
|
|
32
|
+
}>;
|
|
33
|
+
export type JsonSchema = boolean | Readonly<Record<string, unknown>>;
|
|
34
|
+
export type SpawnOptions = Readonly<{
|
|
35
|
+
role: string;
|
|
36
|
+
task: string;
|
|
37
|
+
model?: "sol" | "terra" | "luna" | "astra" | undefined;
|
|
38
|
+
thinking?: Thinking | undefined;
|
|
39
|
+
outputSchema: JsonSchema;
|
|
40
|
+
}>;
|
|
41
|
+
export type BatchSpawnOptions = Readonly<{
|
|
42
|
+
role: string;
|
|
43
|
+
task: string;
|
|
44
|
+
outputSchema: JsonSchema;
|
|
45
|
+
}>;
|
|
46
|
+
export type SpawnReport = Readonly<{
|
|
47
|
+
agent_id: AgentId;
|
|
48
|
+
role: string;
|
|
49
|
+
status: Readonly<{ state: "running" }>;
|
|
50
|
+
}>;
|
|
51
|
+
export type WaitOptions = Readonly<{
|
|
52
|
+
agentIds: readonly AgentId[];
|
|
53
|
+
timeoutMs?: number | undefined;
|
|
54
|
+
}>;
|
|
55
|
+
export type WaitReport = Readonly<{
|
|
56
|
+
agents: readonly AgentSummary[];
|
|
57
|
+
timed_out: boolean;
|
|
58
|
+
}>;
|
|
59
|
+
export type LifecycleReport = Readonly<{ agents: readonly AgentSummary[] }>;
|
|
60
|
+
export type DirectoryEntry = AgentSummary & Readonly<{
|
|
61
|
+
can_message: boolean;
|
|
62
|
+
can_manage: boolean;
|
|
63
|
+
}>;
|
|
64
|
+
export type DirectoryOptions = Readonly<{
|
|
65
|
+
includeCompleted?: boolean | undefined;
|
|
66
|
+
includeSelf?: boolean | undefined;
|
|
67
|
+
}>;
|
|
68
|
+
export type DirectoryReport = Readonly<{ agents: readonly DirectoryEntry[] }>;
|
|
69
|
+
export type MessagePriority = "deferred" | "urgent";
|
|
70
|
+
export type MessagePurpose = "delegate" | "coordinate" | "finding" | "question" | "reply";
|
|
71
|
+
export type MessageSender =
|
|
72
|
+
| Readonly<{ kind: "root" }>
|
|
73
|
+
| Readonly<{ kind: "agent"; agent_id: AgentId }>;
|
|
74
|
+
export type SendOptions = Readonly<{
|
|
75
|
+
agentId: AgentId;
|
|
76
|
+
message: string;
|
|
77
|
+
priority?: MessagePriority | undefined;
|
|
78
|
+
purpose?: MessagePurpose | undefined;
|
|
79
|
+
inReplyTo?: number | undefined;
|
|
80
|
+
}>;
|
|
81
|
+
export type MessageReceipt = Readonly<{
|
|
82
|
+
message_id: number;
|
|
83
|
+
thread_id: number;
|
|
84
|
+
from: MessageSender;
|
|
85
|
+
to_agent_id: AgentId;
|
|
86
|
+
disposition: "started" | "queued" | "steered";
|
|
87
|
+
}>;
|
|
88
|
+
|
|
89
|
+
/** Returns a spreadable Rust-backed tool extension for an Agent's tools array. */
|
|
90
|
+
export function create(options?: Options): Subagents;
|
|
91
|
+
/** Directly invokes the canonical Rust spawn_agent handler. */
|
|
92
|
+
export function spawn(agent: SubagentOwner, options: SpawnOptions): Promise<SpawnReport>;
|
|
93
|
+
/** Atomically reserves and starts an ordered batch of canonical Rust subagents. */
|
|
94
|
+
export function spawnMany(
|
|
95
|
+
agent: SubagentOwner,
|
|
96
|
+
options: readonly BatchSpawnOptions[],
|
|
97
|
+
): Promise<readonly SpawnReport[]>;
|
|
98
|
+
/** Directly invokes the canonical Rust wait_agent handler. */
|
|
99
|
+
export function wait(agent: SubagentOwner, options: WaitOptions): Promise<WaitReport>;
|
|
100
|
+
/** Directly invokes the canonical Rust list_agents handler. */
|
|
101
|
+
export function list(agent: SubagentOwner, options?: DirectoryOptions): Promise<DirectoryReport>;
|
|
102
|
+
/** Directly invokes the canonical Rust send_agent_message handler. */
|
|
103
|
+
export function send(agent: SubagentOwner, options: SendOptions): Promise<MessageReceipt>;
|
|
104
|
+
/** Directly invokes the canonical Rust interrupt_agent handler. */
|
|
105
|
+
export function interrupt(agent: SubagentOwner, agentId: AgentId): Promise<LifecycleReport>;
|
|
106
|
+
/** Directly invokes the canonical Rust close_agent handler. */
|
|
107
|
+
export function close(agent: SubagentOwner, agentId: AgentId): Promise<LifecycleReport>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
closeSubagent,
|
|
3
|
+
interruptSubagent,
|
|
4
|
+
listSubagents,
|
|
5
|
+
sendSubagentMessage,
|
|
6
|
+
spawnSubagent,
|
|
7
|
+
spawnSubagents,
|
|
8
|
+
waitSubagents,
|
|
9
|
+
} from "../internal.mjs";
|
|
10
|
+
import {
|
|
11
|
+
defaultSubagentMaxConcurrency,
|
|
12
|
+
subagentsBrand,
|
|
13
|
+
} from "./tool-configuration.mjs";
|
|
14
|
+
|
|
15
|
+
export function create(options = {}) {
|
|
16
|
+
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
|
17
|
+
throw new TypeError("Subagents.create options must be an object");
|
|
18
|
+
}
|
|
19
|
+
const maxConcurrency = options.maxConcurrency ?? defaultSubagentMaxConcurrency;
|
|
20
|
+
if (maxConcurrency !== undefined && (!Number.isSafeInteger(maxConcurrency) || maxConcurrency < 1)) {
|
|
21
|
+
throw new TypeError("subagents maxConcurrency must be a positive safe integer");
|
|
22
|
+
}
|
|
23
|
+
return Object.freeze([Object.freeze({
|
|
24
|
+
[subagentsBrand]: Object.freeze({ maxConcurrency }),
|
|
25
|
+
})]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function spawn(agent, options) {
|
|
29
|
+
return spawnSubagent(agent, options);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function spawnMany(agent, options) {
|
|
33
|
+
return spawnSubagents(agent, options);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function wait(agent, options) {
|
|
37
|
+
return waitSubagents(agent, options);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function list(agent, options) {
|
|
41
|
+
return listSubagents(agent, options);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function send(agent, options) {
|
|
45
|
+
return sendSubagentMessage(agent, options);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function interrupt(agent, agentId) {
|
|
49
|
+
return interruptSubagent(agent, agentId);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function close(agent, agentId) {
|
|
53
|
+
return closeSubagent(agent, agentId);
|
|
54
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function subscriptionRevision(
|
|
2
|
+
value: string | bigint,
|
|
3
|
+
): import("../types.mjs").SubscriptionRevision;
|
|
4
|
+
|
|
5
|
+
export declare function createMemoryChatGptSubscriptionStore(
|
|
6
|
+
id: string,
|
|
7
|
+
initial?: import("../types.mjs").SubscriptionStoredValue,
|
|
8
|
+
): import("../types.mjs").MemoryChatGptSubscriptionStore;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const MAX_REVISION = 18_446_744_073_709_551_615n;
|
|
2
|
+
|
|
3
|
+
export function subscriptionRevision(value) {
|
|
4
|
+
const revision = String(value);
|
|
5
|
+
if (!/^(0|[1-9][0-9]*)$/.test(revision) || BigInt(revision) > MAX_REVISION) {
|
|
6
|
+
throw new TypeError("subscription revision must be an unsigned 64-bit decimal string");
|
|
7
|
+
}
|
|
8
|
+
return revision;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function createMemoryChatGptSubscriptionStore(id, initial) {
|
|
12
|
+
if (typeof id !== "string" || !id.trim()) {
|
|
13
|
+
throw new TypeError("subscription ID must be a non-empty string");
|
|
14
|
+
}
|
|
15
|
+
let stored = Object.freeze({
|
|
16
|
+
revision: subscriptionRevision(initial?.revision ?? 0n),
|
|
17
|
+
...(initial?.payload === undefined ? {} : { payload: initial.payload }),
|
|
18
|
+
});
|
|
19
|
+
const select = (selected) => {
|
|
20
|
+
if (selected !== id) throw new Error(`unknown ChatGPT subscription: ${selected}`);
|
|
21
|
+
};
|
|
22
|
+
return Object.freeze({
|
|
23
|
+
id,
|
|
24
|
+
load(selected) {
|
|
25
|
+
select(selected);
|
|
26
|
+
return stored;
|
|
27
|
+
},
|
|
28
|
+
compareAndSwap(selected, request) {
|
|
29
|
+
select(selected);
|
|
30
|
+
const expectedRevision = subscriptionRevision(request.expectedRevision);
|
|
31
|
+
if (expectedRevision !== stored.revision) {
|
|
32
|
+
return { status: "conflict", actualRevision: stored.revision };
|
|
33
|
+
}
|
|
34
|
+
const revision = subscriptionRevision(BigInt(stored.revision) + 1n);
|
|
35
|
+
stored = Object.freeze({ revision, payload: request.payload });
|
|
36
|
+
return { status: "committed", revision };
|
|
37
|
+
},
|
|
38
|
+
snapshot() {
|
|
39
|
+
return stored;
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { McpPayment, McpServers, MppSession } from "../types.mjs";
|
|
2
|
+
|
|
3
|
+
export declare const DEFAULT_MERCATOR_MCP_URL = "https://mercator.tempo.xyz/mcp";
|
|
4
|
+
|
|
5
|
+
export type TempoProvider<Session extends MppSession = MppSession> = MppSession & Readonly<{
|
|
6
|
+
kind: "tempo";
|
|
7
|
+
/** The underlying session, available for channel and payment telemetry. */
|
|
8
|
+
session: Session;
|
|
9
|
+
/** MPP-aware HTTP fetch using the same methods as paid MCP calls. */
|
|
10
|
+
fetch?: TempoPaymentFetch | undefined;
|
|
11
|
+
}>;
|
|
12
|
+
|
|
13
|
+
export function createTempoProvider<Session extends MppSession>(
|
|
14
|
+
options: { session: Session; payment: McpPayment; fetch?: TempoPaymentFetch | undefined },
|
|
15
|
+
): TempoProvider<Session>;
|
|
16
|
+
|
|
17
|
+
export type TempoPaymentFetch = (
|
|
18
|
+
input: RequestInfo | URL,
|
|
19
|
+
init?: RequestInit | undefined,
|
|
20
|
+
policy?: Readonly<{
|
|
21
|
+
maxAmount?: bigint | undefined;
|
|
22
|
+
intent?: "charge" | "session" | undefined;
|
|
23
|
+
}> | undefined,
|
|
24
|
+
) => Promise<Response>;
|
|
25
|
+
|
|
26
|
+
type WalletParameters = {
|
|
27
|
+
getClient: (...args: any[]) => any;
|
|
28
|
+
resolveAccount: (...args: any[]) => any;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** The adapter-neutral surface implemented by every Accounts SDK provider. */
|
|
32
|
+
export type AccountsWallet = {
|
|
33
|
+
getMppxParameters(options?: { accessKey?: `0x${string}` | undefined }): WalletParameters;
|
|
34
|
+
getAccount?(options?: unknown): { address: `0x${string}` };
|
|
35
|
+
store?: {
|
|
36
|
+
getState?(): { activeAccount?: number; accounts?: readonly { address: `0x${string}` }[]; chainId?: number };
|
|
37
|
+
accessKeys?: {
|
|
38
|
+
get(options: {
|
|
39
|
+
account: `0x${string}`;
|
|
40
|
+
accessKey: `0x${string}`;
|
|
41
|
+
chainId: number;
|
|
42
|
+
}): Promise<unknown>;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type AccountsTempoPolicy = {
|
|
48
|
+
/**
|
|
49
|
+
* These values stay structurally typed so a wallet may use any compatible
|
|
50
|
+
* Accounts/MPPx/Viem dependency instance without nominal package coupling.
|
|
51
|
+
*/
|
|
52
|
+
autoSwap?: unknown;
|
|
53
|
+
channelStore?: unknown;
|
|
54
|
+
decimals?: number | undefined;
|
|
55
|
+
escrow?: `0x${string}` | undefined;
|
|
56
|
+
maxDeposit?: string | undefined;
|
|
57
|
+
topUpAmount?: string | undefined;
|
|
58
|
+
[option: string]: unknown;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type AccountsTempoSessionOptions = AccountsTempoPolicy & {
|
|
62
|
+
bootstrap?: boolean | undefined;
|
|
63
|
+
fetch?: typeof globalThis.fetch | undefined;
|
|
64
|
+
webSocket?: unknown;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type AccountsTempoMercatorOptions = AccountsTempoPolicy & {
|
|
68
|
+
onChannelUpdate?: ((entry: {
|
|
69
|
+
channelId: `0x${string}`;
|
|
70
|
+
cumulativeAmount: bigint;
|
|
71
|
+
[field: string]: unknown;
|
|
72
|
+
}) => void | Promise<void>) | undefined;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type AccountsTempoPaymentOptions = {
|
|
76
|
+
/** Raw fetch wrapped by MPPx. */
|
|
77
|
+
fetch?: typeof globalThis.fetch | undefined;
|
|
78
|
+
/** Maximum atomic amount accepted from one HTTP or MCP challenge. */
|
|
79
|
+
maxAmount?: bigint | undefined;
|
|
80
|
+
/** Optional application approval composed after the amount check. */
|
|
81
|
+
onPaymentRequired?: ((challenge: unknown) => boolean | Promise<boolean>) | undefined;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type AccountsTempoSession = MppSession & {
|
|
85
|
+
readonly channelId: `0x${string}` | undefined;
|
|
86
|
+
readonly cumulative: bigint;
|
|
87
|
+
readonly opened: boolean;
|
|
88
|
+
readonly state: unknown;
|
|
89
|
+
close(): Promise<unknown>;
|
|
90
|
+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
91
|
+
topUp(amount: string | bigint): Promise<unknown>;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type AccountsTempoProviderOptions = {
|
|
95
|
+
/** Any provider returned by Accounts SDK `Provider.create(...)`. */
|
|
96
|
+
wallet: AccountsWallet;
|
|
97
|
+
/** Connected root account owning the delegated key. Inferred from Accounts when omitted. */
|
|
98
|
+
account?: `0x${string}` | undefined;
|
|
99
|
+
/** Optional Accounts SDK access key to pin for both model and MCP payments. */
|
|
100
|
+
accessKey?: `0x${string}` | undefined;
|
|
101
|
+
/** Chain on which the delegated key is authorized. Inferred from Accounts when omitted. */
|
|
102
|
+
chainId?: number | undefined;
|
|
103
|
+
/** Shared Tempo payment policy applied to the model session and Mercator. */
|
|
104
|
+
policy?: AccountsTempoPolicy | undefined;
|
|
105
|
+
/** Model-session-only overrides, such as `bootstrap` or `webSocket`. */
|
|
106
|
+
session?: AccountsTempoSessionOptions | undefined;
|
|
107
|
+
/** Mercator-only Tempo method overrides, such as `onChannelUpdate`. */
|
|
108
|
+
mercator?: AccountsTempoMercatorOptions | undefined;
|
|
109
|
+
/** Shared HTTP and MCP challenge policy. */
|
|
110
|
+
payment?: AccountsTempoPaymentOptions | undefined;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Constructs a Tempo provider from any Accounts SDK wallet adapter without
|
|
115
|
+
* taking a runtime dependency on `accounts`.
|
|
116
|
+
*/
|
|
117
|
+
export function createTempoProviderFromAccounts(
|
|
118
|
+
options: AccountsTempoProviderOptions,
|
|
119
|
+
): Promise<TempoProvider<AccountsTempoSession>>;
|
|
120
|
+
|
|
121
|
+
/** @internal */
|
|
122
|
+
export function resolveMcpServers(
|
|
123
|
+
provider: MppSession | undefined,
|
|
124
|
+
configured: McpServers | false | undefined,
|
|
125
|
+
): McpServers | undefined;
|