@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,36 @@
|
|
|
1
|
+
import type { DefaultAgent } from "../types.mjs";
|
|
2
|
+
import type { create as createAgent } from "./Agent.mjs";
|
|
3
|
+
|
|
4
|
+
export type AgentStatus = "idle" | "pending" | "success" | "error";
|
|
5
|
+
|
|
6
|
+
export type AgentSnapshot =
|
|
7
|
+
| Readonly<{ data: undefined; error: undefined; status: "idle" }>
|
|
8
|
+
| Readonly<{ data: undefined; error: undefined; status: "pending" }>
|
|
9
|
+
| Readonly<{ data: DefaultAgent; error: undefined; status: "success" }>
|
|
10
|
+
| Readonly<{ data: undefined; error: unknown; status: "error" }>;
|
|
11
|
+
|
|
12
|
+
export type AgentParameters = Readonly<{
|
|
13
|
+
enabled?: boolean | undefined;
|
|
14
|
+
threadId?: string | undefined;
|
|
15
|
+
}>;
|
|
16
|
+
|
|
17
|
+
export type Config = Readonly<{
|
|
18
|
+
getAgent(parameters?: AgentParameters): AgentSnapshot;
|
|
19
|
+
subscribeAgent(parameters: AgentParameters, listener: () => void): () => void;
|
|
20
|
+
refetchAgent(parameters?: AgentParameters): void;
|
|
21
|
+
destroy(): Promise<void>;
|
|
22
|
+
}>;
|
|
23
|
+
|
|
24
|
+
export type CreateConfigParameters = Readonly<{
|
|
25
|
+
/** Defaults inherited by every Agent created by this config. */
|
|
26
|
+
agent?: createAgent.Options | undefined;
|
|
27
|
+
/** Stable origin included in both preparation and creation of the browser harness. */
|
|
28
|
+
origin?: string | undefined;
|
|
29
|
+
/** Agent startup retries after the first attempt. Defaults to 2. */
|
|
30
|
+
retry?: number | undefined;
|
|
31
|
+
/** Backoff before a startup retry. Defaults to 400ms × attempt. */
|
|
32
|
+
retryDelay?: ((attempt: number, error: unknown) => number) | undefined;
|
|
33
|
+
}>;
|
|
34
|
+
|
|
35
|
+
/** Creates the stable browser runtime consumed by framework bindings. */
|
|
36
|
+
export function createConfig(options?: CreateConfigParameters): Config;
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import { createWorkerAgent, prepareWorkerAgent } from "./WorkerAgent.mjs";
|
|
2
|
+
|
|
3
|
+
const IDLE_SNAPSHOT = Object.freeze({
|
|
4
|
+
data: undefined,
|
|
5
|
+
error: undefined,
|
|
6
|
+
status: "idle",
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
/** Creates the stable browser runtime consumed by framework bindings. */
|
|
10
|
+
export function createConfig(options = {}) {
|
|
11
|
+
return createAgentConfig(options, {
|
|
12
|
+
create: createWorkerAgent,
|
|
13
|
+
prepare: prepareWorkerAgent,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** @internal Dependency-injected config constructor used by focused tests. */
|
|
18
|
+
export function createAgentConfig(options = {}, runtime) {
|
|
19
|
+
const entries = new Map();
|
|
20
|
+
const agentOptions = Object.freeze({ ...(options.agent ?? {}) });
|
|
21
|
+
const defaultThreadId = nonEmptyString(agentOptions.threadId)
|
|
22
|
+
?? nonEmptyString(agentOptions.sessionId)
|
|
23
|
+
?? randomId();
|
|
24
|
+
const retry = nonNegativeInteger(options.retry ?? 2, "retry");
|
|
25
|
+
const retryDelay = options.retryDelay ?? ((attempt) => 400 * attempt);
|
|
26
|
+
if (typeof retryDelay !== "function") throw new TypeError("retryDelay must be a function");
|
|
27
|
+
const failedAgents = new WeakSet();
|
|
28
|
+
const underlyingAgents = new WeakMap();
|
|
29
|
+
const presentedAgents = new WeakMap();
|
|
30
|
+
let destroyed = false;
|
|
31
|
+
let destruction;
|
|
32
|
+
|
|
33
|
+
function resolveThreadId(parameters = {}) {
|
|
34
|
+
return nonEmptyString(parameters.threadId) ?? defaultThreadId;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function createEntry(threadId) {
|
|
38
|
+
const createOptions = Object.freeze({
|
|
39
|
+
...agentOptions,
|
|
40
|
+
threadId,
|
|
41
|
+
...(options.origin === undefined ? {} : { origin: options.origin }),
|
|
42
|
+
});
|
|
43
|
+
const entry = {
|
|
44
|
+
activeSubscribers: 0,
|
|
45
|
+
activeTurns: 0,
|
|
46
|
+
agent: undefined,
|
|
47
|
+
closing: Promise.resolve(),
|
|
48
|
+
createOptions,
|
|
49
|
+
generation: 0,
|
|
50
|
+
key: threadId,
|
|
51
|
+
refetchRequested: false,
|
|
52
|
+
subscriptions: new Set(),
|
|
53
|
+
operation: undefined,
|
|
54
|
+
snapshot: IDLE_SNAPSHOT,
|
|
55
|
+
};
|
|
56
|
+
entries.set(threadId, entry);
|
|
57
|
+
return entry;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function publish(entry, status, data, error) {
|
|
61
|
+
const snapshot = Object.freeze({ data, error, status });
|
|
62
|
+
if (
|
|
63
|
+
entry.snapshot.status === snapshot.status
|
|
64
|
+
&& entry.snapshot.data === snapshot.data
|
|
65
|
+
&& entry.snapshot.error === snapshot.error
|
|
66
|
+
) return;
|
|
67
|
+
entry.snapshot = snapshot;
|
|
68
|
+
notify(entry.subscriptions);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function notify(subscriptions) {
|
|
72
|
+
for (const subscription of [...subscriptions]) {
|
|
73
|
+
if (!subscription.subscribed) continue;
|
|
74
|
+
try { subscription.listener(); } catch (error) { reportError(error); }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function close(agent) {
|
|
79
|
+
if (agent === undefined) return;
|
|
80
|
+
const underlyingAgent = underlyingAgents.get(agent) ?? agent;
|
|
81
|
+
if (failedAgents.has(underlyingAgent)) {
|
|
82
|
+
disposeFailedAgent(underlyingAgent);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
await underlyingAgent.session.shutdown();
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (!failedAgents.has(underlyingAgent)) throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function disposeFailedAgent(agent) {
|
|
93
|
+
failedAgents.add(agent);
|
|
94
|
+
try { agent.dispose(); } catch (error) { reportError(error); }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function failAgent(entry, operation, agent, error) {
|
|
98
|
+
disposeFailedAgent(agent);
|
|
99
|
+
const presentedAgent = presentedAgents.get(agent) ?? agent;
|
|
100
|
+
if (
|
|
101
|
+
destroyed
|
|
102
|
+
|| entry.operation !== operation
|
|
103
|
+
|| entry.generation !== operation.generation
|
|
104
|
+
|| entry.agent !== presentedAgent
|
|
105
|
+
) return;
|
|
106
|
+
entry.agent = undefined;
|
|
107
|
+
finishGeneration(entry, operation);
|
|
108
|
+
if (entry.activeSubscribers > 0) publish(entry, "error", undefined, error);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function retireAgent(entry) {
|
|
112
|
+
const agent = entry.agent;
|
|
113
|
+
entry.agent = undefined;
|
|
114
|
+
if (agent === undefined) return entry.closing;
|
|
115
|
+
const closing = entry.closing.then(() => close(agent));
|
|
116
|
+
entry.closing = closing.catch(() => {});
|
|
117
|
+
return closing;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function trackDurableTurns(entry, agent) {
|
|
121
|
+
if (typeof agent?.turn?.prompt !== "function") return agent;
|
|
122
|
+
let presentedAgent;
|
|
123
|
+
const turn = Object.freeze({
|
|
124
|
+
...agent.turn,
|
|
125
|
+
prompt(options) {
|
|
126
|
+
const owned = agent.turn.prompt(options);
|
|
127
|
+
entry.activeTurns += 1;
|
|
128
|
+
let settled = false;
|
|
129
|
+
const settle = () => {
|
|
130
|
+
if (settled) return;
|
|
131
|
+
settled = true;
|
|
132
|
+
entry.activeTurns = Math.max(0, entry.activeTurns - 1);
|
|
133
|
+
if (destroyed || entry.activeTurns > 0) return;
|
|
134
|
+
if (entry.refetchRequested && entry.activeSubscribers > 0) {
|
|
135
|
+
start(entry, true);
|
|
136
|
+
} else if (entry.activeSubscribers === 0) {
|
|
137
|
+
release(entry);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
let completion;
|
|
141
|
+
try { completion = Promise.resolve(owned.result()); }
|
|
142
|
+
catch (error) { completion = Promise.reject(error); }
|
|
143
|
+
void completion.then(settle, settle);
|
|
144
|
+
return Object.freeze({
|
|
145
|
+
...owned,
|
|
146
|
+
agent: presentedAgent,
|
|
147
|
+
result() { return completion; },
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
presentedAgent = Object.freeze(
|
|
152
|
+
typeof agent.extend === "function"
|
|
153
|
+
? agent.extend(() => ({ turn }))
|
|
154
|
+
: { ...agent, turn },
|
|
155
|
+
);
|
|
156
|
+
presentedAgents.set(agent, presentedAgent);
|
|
157
|
+
underlyingAgents.set(presentedAgent, agent);
|
|
158
|
+
return presentedAgent;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function cancelGeneration(entry) {
|
|
162
|
+
entry.generation += 1;
|
|
163
|
+
const operation = entry.operation;
|
|
164
|
+
entry.operation = undefined;
|
|
165
|
+
operation?.controller.abort();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function isCurrent(entry, operation) {
|
|
169
|
+
return !destroyed
|
|
170
|
+
&& entry.operation === operation
|
|
171
|
+
&& entry.generation === operation.generation
|
|
172
|
+
&& entry.activeSubscribers > 0;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function finishGeneration(entry, operation) {
|
|
176
|
+
if (entry.operation !== operation) return;
|
|
177
|
+
entry.operation = undefined;
|
|
178
|
+
operation.controller.abort();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function start(entry, force = false) {
|
|
182
|
+
if (destroyed || entry.activeSubscribers === 0) return;
|
|
183
|
+
const replace = force || entry.refetchRequested;
|
|
184
|
+
if (entry.activeTurns > 0) {
|
|
185
|
+
// A refetch (or a new observer after a live Worker failure) requests a
|
|
186
|
+
// replacement; it is not authority to abandon accepted work. Coalesce
|
|
187
|
+
// the request until every eagerly observed result lease has settled.
|
|
188
|
+
if (replace || entry.agent === undefined) entry.refetchRequested = true;
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (!replace && (entry.operation !== undefined || entry.agent !== undefined)) return;
|
|
192
|
+
entry.refetchRequested = false;
|
|
193
|
+
cancelGeneration(entry);
|
|
194
|
+
const operation = {
|
|
195
|
+
controller: new AbortController(),
|
|
196
|
+
generation: ++entry.generation,
|
|
197
|
+
};
|
|
198
|
+
entry.operation = operation;
|
|
199
|
+
const closing = retireAgent(entry);
|
|
200
|
+
publish(entry, "pending", undefined, undefined);
|
|
201
|
+
if (!isCurrent(entry, operation)) return;
|
|
202
|
+
try {
|
|
203
|
+
void Promise.resolve(runtime.prepare(entry.createOptions, {
|
|
204
|
+
signal: operation.controller.signal,
|
|
205
|
+
})).catch(() => {
|
|
206
|
+
// Agent.create reports an actionable error if warmup cannot be reused.
|
|
207
|
+
});
|
|
208
|
+
} catch {
|
|
209
|
+
// Agent.create reports an actionable error if warmup cannot be reused.
|
|
210
|
+
}
|
|
211
|
+
void runGeneration(entry, operation, closing);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function runGeneration(entry, operation, closing) {
|
|
215
|
+
try {
|
|
216
|
+
try {
|
|
217
|
+
await closing;
|
|
218
|
+
} catch (error) {
|
|
219
|
+
if (isCurrent(entry, operation)) publish(entry, "error", undefined, error);
|
|
220
|
+
finishGeneration(entry, operation);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (!isCurrent(entry, operation)) return;
|
|
224
|
+
|
|
225
|
+
let candidate;
|
|
226
|
+
let creationFailure;
|
|
227
|
+
for (let attempt = 0; attempt <= retry; attempt += 1) {
|
|
228
|
+
if (!isCurrent(entry, operation)) return;
|
|
229
|
+
let attemptCandidate;
|
|
230
|
+
let attemptFailure;
|
|
231
|
+
try {
|
|
232
|
+
attemptCandidate = await runtime.create(entry.createOptions, {
|
|
233
|
+
signal: operation.controller.signal,
|
|
234
|
+
onFailure(error) {
|
|
235
|
+
if (attemptCandidate === undefined) {
|
|
236
|
+
attemptFailure ??= error;
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
failAgent(entry, operation, attemptCandidate, error);
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
candidate = attemptCandidate;
|
|
243
|
+
creationFailure = attemptFailure;
|
|
244
|
+
break;
|
|
245
|
+
} catch (error) {
|
|
246
|
+
if (!isCurrent(entry, operation)) return;
|
|
247
|
+
if (attempt === retry) {
|
|
248
|
+
publish(entry, "error", undefined, error);
|
|
249
|
+
finishGeneration(entry, operation);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
let delay;
|
|
253
|
+
try {
|
|
254
|
+
delay = nonNegativeNumber(retryDelay(attempt + 1, error), "retryDelay result");
|
|
255
|
+
} catch (retryError) {
|
|
256
|
+
if (isCurrent(entry, operation)) publish(entry, "error", undefined, retryError);
|
|
257
|
+
finishGeneration(entry, operation);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (delay > 0) {
|
|
261
|
+
try {
|
|
262
|
+
await wait(delay, operation.controller.signal);
|
|
263
|
+
} catch {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (candidate === undefined) return;
|
|
270
|
+
if (creationFailure !== undefined) {
|
|
271
|
+
if (!isCurrent(entry, operation)) {
|
|
272
|
+
disposeFailedAgent(candidate);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
entry.agent = candidate;
|
|
276
|
+
failAgent(entry, operation, candidate, creationFailure);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (!isCurrent(entry, operation)) {
|
|
280
|
+
await close(candidate).catch(reportError);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const ownedCandidate = trackDurableTurns(entry, candidate);
|
|
284
|
+
entry.agent = ownedCandidate;
|
|
285
|
+
publish(entry, "success", ownedCandidate, undefined);
|
|
286
|
+
} catch (error) {
|
|
287
|
+
if (isCurrent(entry, operation)) {
|
|
288
|
+
publish(entry, "error", undefined, error);
|
|
289
|
+
finishGeneration(entry, operation);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function release(entry) {
|
|
295
|
+
queueMicrotask(() => {
|
|
296
|
+
if (entry.activeSubscribers > 0 || destroyed) return;
|
|
297
|
+
// A route subscription is only a presentation observer. Accepted turns
|
|
298
|
+
// retain the Agent until their result settles; an actually idle Agent is
|
|
299
|
+
// still reclaimed immediately.
|
|
300
|
+
if (entry.activeTurns > 0) return;
|
|
301
|
+
const closing = retireAgent(entry);
|
|
302
|
+
publish(entry, "idle", undefined, undefined);
|
|
303
|
+
void closing.catch(reportError).finally(() => {
|
|
304
|
+
if (
|
|
305
|
+
entries.get(entry.key) === entry
|
|
306
|
+
&& entry.activeSubscribers === 0
|
|
307
|
+
&& entry.subscriptions.size === 0
|
|
308
|
+
) entries.delete(entry.key);
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const config = {
|
|
314
|
+
getAgent(parameters = {}) {
|
|
315
|
+
if (parameters.enabled === false || destroyed) return IDLE_SNAPSHOT;
|
|
316
|
+
return entries.get(resolveThreadId(parameters))?.snapshot ?? IDLE_SNAPSHOT;
|
|
317
|
+
},
|
|
318
|
+
subscribeAgent(parameters = {}, listener) {
|
|
319
|
+
if (typeof listener !== "function") throw new TypeError("subscribeAgent requires a listener");
|
|
320
|
+
if (destroyed) return () => {};
|
|
321
|
+
const threadId = resolveThreadId(parameters);
|
|
322
|
+
const entry = entries.get(threadId) ?? createEntry(threadId);
|
|
323
|
+
const enabled = parameters.enabled !== false;
|
|
324
|
+
const subscription = { listener, subscribed: true };
|
|
325
|
+
entry.subscriptions.add(subscription);
|
|
326
|
+
if (enabled) {
|
|
327
|
+
entry.activeSubscribers += 1;
|
|
328
|
+
start(entry);
|
|
329
|
+
}
|
|
330
|
+
return () => {
|
|
331
|
+
if (!subscription.subscribed) return;
|
|
332
|
+
subscription.subscribed = false;
|
|
333
|
+
if (destroyed) return;
|
|
334
|
+
entry.subscriptions.delete(subscription);
|
|
335
|
+
if (!enabled) {
|
|
336
|
+
if (entry.subscriptions.size === 0 && entry.activeSubscribers === 0) entries.delete(entry.key);
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
entry.activeSubscribers -= 1;
|
|
340
|
+
if (entry.activeSubscribers === 0) {
|
|
341
|
+
cancelGeneration(entry);
|
|
342
|
+
release(entry);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
},
|
|
346
|
+
refetchAgent(parameters = {}) {
|
|
347
|
+
if (parameters.enabled === false || destroyed) return;
|
|
348
|
+
const entry = entries.get(resolveThreadId(parameters));
|
|
349
|
+
if (entry !== undefined) start(entry, true);
|
|
350
|
+
},
|
|
351
|
+
destroy() {
|
|
352
|
+
if (destruction !== undefined) return destruction;
|
|
353
|
+
let rejectDestruction;
|
|
354
|
+
let resolveDestruction;
|
|
355
|
+
destruction = new Promise((resolve, reject) => {
|
|
356
|
+
rejectDestruction = reject;
|
|
357
|
+
resolveDestruction = resolve;
|
|
358
|
+
});
|
|
359
|
+
destroyed = true;
|
|
360
|
+
const closures = [];
|
|
361
|
+
const notifications = [];
|
|
362
|
+
try {
|
|
363
|
+
for (const entry of entries.values()) {
|
|
364
|
+
cancelGeneration(entry);
|
|
365
|
+
entry.snapshot = IDLE_SNAPSHOT;
|
|
366
|
+
const subscriptions = [...entry.subscriptions];
|
|
367
|
+
entry.subscriptions.clear();
|
|
368
|
+
entry.activeSubscribers = 0;
|
|
369
|
+
for (const subscription of subscriptions) {
|
|
370
|
+
subscription.subscribed = false;
|
|
371
|
+
}
|
|
372
|
+
notifications.push(subscriptions);
|
|
373
|
+
// Destruction is the explicit application boundary allowed to force
|
|
374
|
+
// shutdown even when an accepted result lease does not settle.
|
|
375
|
+
closures.push(retireAgent(entry));
|
|
376
|
+
}
|
|
377
|
+
entries.clear();
|
|
378
|
+
} catch (error) {
|
|
379
|
+
rejectDestruction(error);
|
|
380
|
+
return destruction;
|
|
381
|
+
}
|
|
382
|
+
Promise.all(closures).then(resolveDestruction, rejectDestruction);
|
|
383
|
+
for (const subscriptions of notifications) notifyDestroyed(subscriptions);
|
|
384
|
+
return destruction;
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
return Object.freeze(config);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function notifyDestroyed(subscriptions) {
|
|
391
|
+
for (const subscription of subscriptions) {
|
|
392
|
+
try { subscription.listener(); } catch (error) { reportError(error); }
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function reportError(error) {
|
|
397
|
+
try {
|
|
398
|
+
if (typeof globalThis.reportError === "function") globalThis.reportError(error);
|
|
399
|
+
else globalThis.console?.error?.(error);
|
|
400
|
+
} catch {}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function nonNegativeInteger(value, name) {
|
|
404
|
+
if (!Number.isInteger(value) || value < 0) throw new TypeError(`${name} must be a non-negative integer`);
|
|
405
|
+
return value;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function nonNegativeNumber(value, name) {
|
|
409
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
410
|
+
throw new TypeError(`${name} must be a non-negative finite number`);
|
|
411
|
+
}
|
|
412
|
+
return value;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function nonEmptyString(value) {
|
|
416
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function randomId() {
|
|
420
|
+
return globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random()}`;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function wait(duration, signal) {
|
|
424
|
+
signal.throwIfAborted();
|
|
425
|
+
return new Promise((resolve, reject) => {
|
|
426
|
+
let settled = false;
|
|
427
|
+
const timer = setTimeout(() => settle(resolve), duration);
|
|
428
|
+
const onAbort = () => settle(reject, signal.reason);
|
|
429
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
430
|
+
|
|
431
|
+
function settle(complete, value) {
|
|
432
|
+
if (settled) return;
|
|
433
|
+
settled = true;
|
|
434
|
+
clearTimeout(timer);
|
|
435
|
+
signal.removeEventListener("abort", onAbort);
|
|
436
|
+
complete(value);
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import init from "../pkg-web/nanocodex.js";
|
|
2
|
+
|
|
3
|
+
let initialized;
|
|
4
|
+
|
|
5
|
+
/** @internal Initializes the browser WASM module once per realm. */
|
|
6
|
+
export function initializeBrowserEngine(options = {}) {
|
|
7
|
+
return initialized ||= (options.module === undefined
|
|
8
|
+
? init()
|
|
9
|
+
: init({ module_or_path: options.module })).catch((error) => {
|
|
10
|
+
initialized = undefined;
|
|
11
|
+
throw error;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createWorkerEvaluator } from "../runtime/worker-evaluator.mjs";
|
|
2
|
+
import { browser } from "../tools/browser/index.mjs";
|
|
3
|
+
|
|
4
|
+
/** Builds the one canonical browser Agent harness used by every browser surface. */
|
|
5
|
+
export async function createBrowserHarness(options) {
|
|
6
|
+
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
|
7
|
+
throw new TypeError("browser harness options must be an object");
|
|
8
|
+
}
|
|
9
|
+
const origin = new URL(options.origin).origin;
|
|
10
|
+
if (typeof options.threadId !== "string" || !options.threadId) {
|
|
11
|
+
throw new TypeError("browser harness threadId must be a non-empty string");
|
|
12
|
+
}
|
|
13
|
+
const retainedImages = [];
|
|
14
|
+
const ownsRecentImages = options.recentImages === undefined
|
|
15
|
+
&& options.rememberImage === undefined;
|
|
16
|
+
const runtime = await browser({
|
|
17
|
+
...options,
|
|
18
|
+
origin,
|
|
19
|
+
...(ownsRecentImages ? {
|
|
20
|
+
recentImages: (_sessionId, count) => retainedImages.slice(-count),
|
|
21
|
+
rememberImage: (_sessionId, image) => {
|
|
22
|
+
retainedImages.push(image);
|
|
23
|
+
if (retainedImages.length > 5) retainedImages.splice(0, retainedImages.length - 5);
|
|
24
|
+
},
|
|
25
|
+
} : {}),
|
|
26
|
+
});
|
|
27
|
+
const now = new Date();
|
|
28
|
+
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
29
|
+
return Object.freeze({
|
|
30
|
+
codeEvaluator: createWorkerEvaluator({
|
|
31
|
+
egress: {
|
|
32
|
+
origin,
|
|
33
|
+
threadId: options.threadId,
|
|
34
|
+
...(options.headers === undefined ? {} : { headers: options.headers }),
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
executionEnvironment: {
|
|
38
|
+
currentDate: localDate(now),
|
|
39
|
+
timezone,
|
|
40
|
+
...(runtime.projectInstructions === undefined
|
|
41
|
+
? {}
|
|
42
|
+
: { projectInstructions: runtime.projectInstructions }),
|
|
43
|
+
},
|
|
44
|
+
filesystem: runtime.filesystem,
|
|
45
|
+
instructions: runtime.instructions,
|
|
46
|
+
release() {
|
|
47
|
+
retainedImages.length = 0;
|
|
48
|
+
},
|
|
49
|
+
tools: runtime.tools,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function localDate(date) {
|
|
54
|
+
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
|
55
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CompactionInstructionResolver,
|
|
3
|
+
CodeEvaluator,
|
|
4
|
+
McpServers,
|
|
5
|
+
MppSession,
|
|
6
|
+
SubagentToolContext,
|
|
7
|
+
ToolMap,
|
|
8
|
+
} from "../types.mjs";
|
|
9
|
+
import type { Workspace } from "./workspace.mjs";
|
|
10
|
+
export type BrowserTool = {
|
|
11
|
+
description: string;
|
|
12
|
+
parameters: Record<string, unknown>;
|
|
13
|
+
handler: (
|
|
14
|
+
input: unknown,
|
|
15
|
+
context: { sessionId: string; signal: AbortSignal },
|
|
16
|
+
) => unknown | Promise<unknown>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type BrowserToolMap = Record<string, BrowserTool>;
|
|
20
|
+
|
|
21
|
+
type BrowserWebSocketMetadata = {
|
|
22
|
+
accountId?: string | undefined;
|
|
23
|
+
fedramp?: boolean | undefined;
|
|
24
|
+
threadId?: string | undefined;
|
|
25
|
+
turnState?: string | undefined;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type BrowserWebSocketRequest = BrowserWebSocketMetadata & (
|
|
29
|
+
| {
|
|
30
|
+
authorization: "bearer";
|
|
31
|
+
/** Resolved credential for this handshake. Do not retain or log it. */
|
|
32
|
+
bearerToken: string;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
authorization: "host_managed";
|
|
36
|
+
bearerToken?: never;
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
/** Credential-free eager connection; the later model connect consumes this exact socket. */
|
|
40
|
+
authorization: "preconnect";
|
|
41
|
+
bearerToken?: never;
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export type BrowserWebSocketConnection = {
|
|
46
|
+
socket: WebSocket;
|
|
47
|
+
status?: number | undefined;
|
|
48
|
+
requestId?: string | undefined;
|
|
49
|
+
serverModel?: string | undefined;
|
|
50
|
+
reasoningIncluded?: boolean | undefined;
|
|
51
|
+
turnState?: string | undefined;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export function createBrowserHost(options?: {
|
|
55
|
+
WebSocketImpl?: typeof WebSocket;
|
|
56
|
+
hostAuth?: boolean;
|
|
57
|
+
hostManagedProtocol?: boolean;
|
|
58
|
+
createWebSocket?: (
|
|
59
|
+
endpoint: string,
|
|
60
|
+
sessionId: string,
|
|
61
|
+
request: BrowserWebSocketRequest,
|
|
62
|
+
) => WebSocket | BrowserWebSocketConnection | Promise<WebSocket | BrowserWebSocketConnection>;
|
|
63
|
+
filesystem?: Workspace;
|
|
64
|
+
filesystemTools?: boolean;
|
|
65
|
+
onEvent?: (eventJson: string) => void;
|
|
66
|
+
tools?: ToolMap;
|
|
67
|
+
mpp?: MppSession;
|
|
68
|
+
/** Remote MCP servers exposed through native and Code Mode tool_search plus deferred tools. */
|
|
69
|
+
mcp?: McpServers;
|
|
70
|
+
codeEvaluator?: CodeEvaluator;
|
|
71
|
+
/** Selects the private summary instruction in the current isolate for each compaction operation. */
|
|
72
|
+
resolveCompactionInstruction?: CompactionInstructionResolver;
|
|
73
|
+
toolMode?: "code" | "direct";
|
|
74
|
+
/** @internal Durable host lifecycle for Rust-owned subagent descriptors. */
|
|
75
|
+
subagentSessions?: {
|
|
76
|
+
restore(): readonly SubagentToolContext[];
|
|
77
|
+
bind(sessionId: string, descriptor: SubagentToolContext): void;
|
|
78
|
+
release(sessionId: string): void;
|
|
79
|
+
};
|
|
80
|
+
maxQueuedMessages?: number;
|
|
81
|
+
maxQueuedBytes?: number;
|
|
82
|
+
maxBufferedSendBytes?: number;
|
|
83
|
+
}): unknown;
|