@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,428 @@
|
|
|
1
|
+
import { Agent as ManagedAgent } from "../../managed/index.mjs";
|
|
2
|
+
import { registerManagedAgentAlias } from "../../managed/internal.mjs";
|
|
3
|
+
import { createTools } from "../../tools/Tools.mjs";
|
|
4
|
+
import { AttachmentRejectedError } from "../../tools/attachment.mjs";
|
|
5
|
+
import {
|
|
6
|
+
hostedAppToolCatalog,
|
|
7
|
+
hostedToolCatalogDigest,
|
|
8
|
+
} from "../../tools/hostedCatalog.mjs";
|
|
9
|
+
|
|
10
|
+
const PROVIDER_NAME = "ChatGPT · Nanocodex Connect";
|
|
11
|
+
const MCP_CONNECTION_ID = /^[A-Za-z0-9_-]{43}$/;
|
|
12
|
+
const ATTACHMENT_BACKOFF_MS = [250, 500, 1_000, 2_000, 5_000];
|
|
13
|
+
|
|
14
|
+
/** Opens the durable Nanocodex agent provisioned by a signed Connect approval. */
|
|
15
|
+
export async function create(client, options) {
|
|
16
|
+
const connection = options?.connection;
|
|
17
|
+
if (!connection || typeof connection !== "object") {
|
|
18
|
+
throw new TypeError("agent.create requires an active connection");
|
|
19
|
+
}
|
|
20
|
+
if (connection.grant?.status !== "active") {
|
|
21
|
+
throw new Error("The Connect authorization is not active.");
|
|
22
|
+
}
|
|
23
|
+
if (!connection.grant.connectors?.includes("chatgpt")) {
|
|
24
|
+
throw new Error("Connect ChatGPT before opening the durable Nanocodex agent.");
|
|
25
|
+
}
|
|
26
|
+
const unsupported = Object.keys(options ?? {}).find((key) => (
|
|
27
|
+
key !== "connection" && key !== "signal" && key !== "tools"
|
|
28
|
+
));
|
|
29
|
+
if (unsupported) {
|
|
30
|
+
throw new TypeError(`Connect durable agents do not accept app-local ${unsupported}`);
|
|
31
|
+
}
|
|
32
|
+
options.signal?.throwIfAborted();
|
|
33
|
+
|
|
34
|
+
const appCatalog = hostedAppToolCatalog(options.tools ?? []);
|
|
35
|
+
const appCatalogDigest = appCatalog.length === 0
|
|
36
|
+
? undefined
|
|
37
|
+
: await hostedToolCatalogDigest(appCatalog);
|
|
38
|
+
if (appCatalogDigest !== connection.grant.appToolCatalogDigest) {
|
|
39
|
+
throw new Error("The app-local tools do not match the exact signed Connect grant.");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const grantSession = client._captureSession?.();
|
|
43
|
+
if (!grantSession) throw new Error("The Connect authorization session is unavailable.");
|
|
44
|
+
const transport = {
|
|
45
|
+
baseUrl: client.transport.baseUrl,
|
|
46
|
+
grantSession,
|
|
47
|
+
};
|
|
48
|
+
let tools;
|
|
49
|
+
if (options.tools !== undefined || connection.grant.mcpConnections.length > 0) {
|
|
50
|
+
tools = await createAttachedTools(
|
|
51
|
+
transport,
|
|
52
|
+
connection.grant.id,
|
|
53
|
+
options.tools,
|
|
54
|
+
connection.grant.mcpConnections,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
const managedOptions = {
|
|
58
|
+
baseUrl: client.transport.baseUrl,
|
|
59
|
+
fetch: managedGrantFetch(
|
|
60
|
+
grantSession,
|
|
61
|
+
client.transport.baseUrl,
|
|
62
|
+
connection.grant.id,
|
|
63
|
+
connection.agentId,
|
|
64
|
+
),
|
|
65
|
+
...(tools === undefined ? {} : {
|
|
66
|
+
toolsTransport: connectToolsTransport(
|
|
67
|
+
transport,
|
|
68
|
+
connection.grant.id,
|
|
69
|
+
connection.agentId,
|
|
70
|
+
),
|
|
71
|
+
}),
|
|
72
|
+
};
|
|
73
|
+
try {
|
|
74
|
+
const managed = ManagedAgent.open(connection.agentId, managedOptions);
|
|
75
|
+
return await connectAgent(managed, connection, transport, tools, options.signal);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
await tools?.close();
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function connectAgent(managed, connection, transport, tools, signal) {
|
|
83
|
+
const visibility = connection.grant.visibility;
|
|
84
|
+
const toolState = tools === undefined ? undefined : startToolAttachment(managed, tools, signal);
|
|
85
|
+
try {
|
|
86
|
+
await toolState?.supervisor;
|
|
87
|
+
signal?.throwIfAborted();
|
|
88
|
+
} finally {
|
|
89
|
+
detachInitialToolAbort(toolState);
|
|
90
|
+
}
|
|
91
|
+
const agent = {
|
|
92
|
+
id: managed.id,
|
|
93
|
+
sessionId: managed.id,
|
|
94
|
+
type: "connect",
|
|
95
|
+
provider: PROVIDER_NAME,
|
|
96
|
+
state: () => managed.state(),
|
|
97
|
+
events: Object.freeze({
|
|
98
|
+
async page(options) {
|
|
99
|
+
const page = await managed.events.page(options);
|
|
100
|
+
if (!visibility.conversationHistory && !visibility.rawTraces) {
|
|
101
|
+
return Object.freeze({
|
|
102
|
+
data: Object.freeze([]),
|
|
103
|
+
hasMore: false,
|
|
104
|
+
latestCursor: page.latestCursor,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return Object.freeze({
|
|
108
|
+
...page,
|
|
109
|
+
data: Object.freeze(page.data
|
|
110
|
+
.map((event) => projectManagedEvent(event, visibility))
|
|
111
|
+
.filter(Boolean)),
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
watch(options) {
|
|
115
|
+
return projectManagedEvents(managed.events.watch(options), visibility);
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
118
|
+
mercator: Object.freeze({
|
|
119
|
+
enabled: true,
|
|
120
|
+
channelId: undefined,
|
|
121
|
+
cumulative: 0n,
|
|
122
|
+
opened: false,
|
|
123
|
+
}),
|
|
124
|
+
turn: Object.freeze({
|
|
125
|
+
prompt(parameters) {
|
|
126
|
+
const turn = managed.turn.prompt(parameters);
|
|
127
|
+
return Object.freeze({
|
|
128
|
+
idempotencyKey: turn.idempotencyKey,
|
|
129
|
+
accepted: () => turn.accepted(),
|
|
130
|
+
state: () => turn.state(),
|
|
131
|
+
steer: (options) => turn.steer(options),
|
|
132
|
+
cancel: () => turn.cancel(),
|
|
133
|
+
async result(options) {
|
|
134
|
+
const result = await turn.result(options);
|
|
135
|
+
return Object.freeze({
|
|
136
|
+
...result,
|
|
137
|
+
finalMessage: visibility.finalMessages ? result.finalMessage : "",
|
|
138
|
+
provider: PROVIDER_NAME,
|
|
139
|
+
capabilitiesUsed: Object.freeze([]),
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
}),
|
|
145
|
+
session: Object.freeze({
|
|
146
|
+
shutdown: () => shutdownToolAttachment(toolState),
|
|
147
|
+
}),
|
|
148
|
+
};
|
|
149
|
+
registerManagedAgentAlias(agent, managed, {
|
|
150
|
+
voiceTransport: connectVoiceTransport(transport, connection.grant.id, connection.agentId),
|
|
151
|
+
});
|
|
152
|
+
return Object.freeze(agent);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function createAttachedTools({ baseUrl, grantSession }, grantId, tools, connections) {
|
|
156
|
+
const mcp = Object.fromEntries(connections.map(({ id, name }) => {
|
|
157
|
+
if (!MCP_CONNECTION_ID.test(id)) {
|
|
158
|
+
throw new TypeError("Connect grant contains an invalid MCP connection ID");
|
|
159
|
+
}
|
|
160
|
+
return [id, {
|
|
161
|
+
description: name,
|
|
162
|
+
fetch: grantMcpFetch(grantSession, baseUrl, grantId, id),
|
|
163
|
+
url: new URL(`/v1/grants/${grantId}/mcp/${id}`, baseUrl),
|
|
164
|
+
}];
|
|
165
|
+
}));
|
|
166
|
+
return createTools({
|
|
167
|
+
...(tools === undefined ? {} : { tools }),
|
|
168
|
+
...(connections.length === 0 ? {} : {
|
|
169
|
+
mcp,
|
|
170
|
+
mcpOptions: {
|
|
171
|
+
catalogProvider: (connectionId) => `mcp:${connectionId}`,
|
|
172
|
+
},
|
|
173
|
+
}),
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function grantMcpFetch(session, baseUrl, grantId, connectionId) {
|
|
178
|
+
const endpoint = new URL(`/v1/grants/${grantId}/mcp/${connectionId}`, baseUrl);
|
|
179
|
+
return (input, init) => {
|
|
180
|
+
const url = new URL(input instanceof Request ? input.url : input, endpoint);
|
|
181
|
+
if (url.origin !== endpoint.origin || url.pathname !== endpoint.pathname) {
|
|
182
|
+
throw new TypeError("Connect MCP fetch is restricted to its authorized grant connection");
|
|
183
|
+
}
|
|
184
|
+
if (input instanceof Request) {
|
|
185
|
+
const request = init === undefined ? input : new Request(input, init);
|
|
186
|
+
return session.fetch(new Request(url, request));
|
|
187
|
+
}
|
|
188
|
+
return session.fetch(url, init);
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function connectToolsTransport({ baseUrl, grantSession }, grantId, agentId) {
|
|
193
|
+
const path = `/v1/grants/${grantId}/agents/${encodeURIComponent(agentId)}/tool-host`;
|
|
194
|
+
return async () => {
|
|
195
|
+
const response = await grantSession.fetch(new Request(new URL(`${path}/ticket`, baseUrl), {
|
|
196
|
+
method: "POST",
|
|
197
|
+
}));
|
|
198
|
+
const receipt = await response.json().catch(() => undefined);
|
|
199
|
+
if (!response.ok || typeof receipt?.ticket !== "string" || !receipt.ticket) {
|
|
200
|
+
const message = receipt?.error?.message ?? "managed tool-host authorization failed";
|
|
201
|
+
if (terminalToolHostStatus(response.status)) throw new AttachmentRejectedError(message);
|
|
202
|
+
throw new Error(message);
|
|
203
|
+
}
|
|
204
|
+
const url = new URL(path, baseUrl);
|
|
205
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
206
|
+
url.searchParams.set("ticket", receipt.ticket);
|
|
207
|
+
const WebSocketImpl = globalThis.WebSocket;
|
|
208
|
+
if (typeof WebSocketImpl !== "function") {
|
|
209
|
+
throw new Error("WebSocket is unavailable in this runtime.");
|
|
210
|
+
}
|
|
211
|
+
return new WebSocketImpl(url);
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function terminalToolHostStatus(status) {
|
|
216
|
+
return status >= 400 && status < 500 && status !== 408 && status !== 425 && status !== 429;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function startToolAttachment(managed, tools, signal) {
|
|
220
|
+
signal?.throwIfAborted();
|
|
221
|
+
const state = {
|
|
222
|
+
abort: new AbortController(),
|
|
223
|
+
closing: undefined,
|
|
224
|
+
connector: undefined,
|
|
225
|
+
initialSignal: signal,
|
|
226
|
+
onInitialAbort: undefined,
|
|
227
|
+
tools,
|
|
228
|
+
};
|
|
229
|
+
if (signal) {
|
|
230
|
+
state.onInitialAbort = () => {
|
|
231
|
+
state.abort.abort(signal.reason);
|
|
232
|
+
state.connector?.close();
|
|
233
|
+
};
|
|
234
|
+
signal.addEventListener("abort", state.onInitialAbort, { once: true });
|
|
235
|
+
if (signal.aborted) state.onInitialAbort();
|
|
236
|
+
}
|
|
237
|
+
state.supervisor = superviseToolAttachment(state, managed.toolsTarget());
|
|
238
|
+
return state;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function detachInitialToolAbort(state) {
|
|
242
|
+
if (!state?.onInitialAbort) return;
|
|
243
|
+
state.initialSignal.removeEventListener("abort", state.onInitialAbort);
|
|
244
|
+
state.onInitialAbort = undefined;
|
|
245
|
+
state.initialSignal = undefined;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async function superviseToolAttachment(state, target) {
|
|
249
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
250
|
+
if (state.abort.signal.aborted) {
|
|
251
|
+
throwInitialToolAbort(state);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const connector = state.tools.attach(target);
|
|
255
|
+
state.connector = connector;
|
|
256
|
+
try {
|
|
257
|
+
await connector.connect();
|
|
258
|
+
return;
|
|
259
|
+
} catch (error) {
|
|
260
|
+
connector.close();
|
|
261
|
+
if (state.connector === connector) state.connector = undefined;
|
|
262
|
+
if (error instanceof AttachmentRejectedError) throw error;
|
|
263
|
+
if (state.abort.signal.aborted) {
|
|
264
|
+
throwInitialToolAbort(state);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
await attachmentBackoff(
|
|
268
|
+
ATTACHMENT_BACKOFF_MS[Math.min(attempt, ATTACHMENT_BACKOFF_MS.length - 1)],
|
|
269
|
+
state.abort.signal,
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function throwInitialToolAbort(state) {
|
|
276
|
+
if (state.initialSignal?.aborted) throw state.initialSignal.reason;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function attachmentBackoff(milliseconds, signal) {
|
|
280
|
+
if (signal.aborted) return Promise.resolve();
|
|
281
|
+
return new Promise((resolve) => {
|
|
282
|
+
const timer = setTimeout(done, milliseconds);
|
|
283
|
+
signal.addEventListener("abort", done, { once: true });
|
|
284
|
+
function done() {
|
|
285
|
+
clearTimeout(timer);
|
|
286
|
+
signal.removeEventListener("abort", done);
|
|
287
|
+
resolve();
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function shutdownToolAttachment(state) {
|
|
293
|
+
if (!state) return Promise.resolve();
|
|
294
|
+
if (state.closing) return state.closing;
|
|
295
|
+
state.abort.abort();
|
|
296
|
+
state.connector?.close();
|
|
297
|
+
state.closing = (async () => {
|
|
298
|
+
await state.supervisor;
|
|
299
|
+
await state.tools.close();
|
|
300
|
+
})();
|
|
301
|
+
return state.closing;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function connectVoiceTransport({ baseUrl, grantSession }, grantId, agentId) {
|
|
305
|
+
const grantPath = `/v1/grants/${grantId}/agents/${encodeURIComponent(agentId)}/realtime`;
|
|
306
|
+
let voiceSessionId;
|
|
307
|
+
return Object.freeze({
|
|
308
|
+
call(body, signal) {
|
|
309
|
+
const call = managedRealtimeCallBody(body, agentId);
|
|
310
|
+
voiceSessionId = call.voiceSessionId;
|
|
311
|
+
return grantSession.fetch(new Request(new URL(`${grantPath}/calls`, baseUrl), {
|
|
312
|
+
method: "POST",
|
|
313
|
+
headers: {
|
|
314
|
+
"content-type": "application/json",
|
|
315
|
+
"x-nanocodex-voice-session-id": voiceSessionId,
|
|
316
|
+
},
|
|
317
|
+
body: call.body,
|
|
318
|
+
signal,
|
|
319
|
+
}));
|
|
320
|
+
},
|
|
321
|
+
async sidebandUrl(callId) {
|
|
322
|
+
if (!voiceSessionId) throw new Error("Connect voice call must open before its sideband");
|
|
323
|
+
const response = await grantSession.fetch(new Request(new URL(`${grantPath}/ticket`, baseUrl), {
|
|
324
|
+
method: "POST",
|
|
325
|
+
headers: { "content-type": "application/json" },
|
|
326
|
+
body: JSON.stringify({ call_id: callId, voice_session_id: voiceSessionId }),
|
|
327
|
+
}));
|
|
328
|
+
const receipt = await response.json().catch(() => undefined);
|
|
329
|
+
if (!response.ok || typeof receipt?.ticket !== "string") {
|
|
330
|
+
throw new Error(receipt?.error?.message ?? "voice sideband authorization failed");
|
|
331
|
+
}
|
|
332
|
+
const url = new URL(`${grantPath}/sideband`, baseUrl);
|
|
333
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
334
|
+
url.searchParams.set("call_id", callId);
|
|
335
|
+
url.searchParams.set("ticket", receipt.ticket);
|
|
336
|
+
url.searchParams.set("voice_session_id", voiceSessionId);
|
|
337
|
+
return url;
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function managedRealtimeCallBody(encoded, agentId) {
|
|
343
|
+
let envelope;
|
|
344
|
+
try { envelope = JSON.parse(encoded); }
|
|
345
|
+
catch { throw new TypeError("Connect voice call body is invalid"); }
|
|
346
|
+
if (!envelope || typeof envelope !== "object" || Array.isArray(envelope)
|
|
347
|
+
|| envelope.managed_agent_id !== agentId
|
|
348
|
+
|| typeof envelope.call_body !== "string"
|
|
349
|
+
|| typeof envelope.realtime_session_id !== "string") {
|
|
350
|
+
throw new TypeError("Connect voice call body is invalid");
|
|
351
|
+
}
|
|
352
|
+
return { body: envelope.call_body, voiceSessionId: envelope.realtime_session_id };
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function managedGrantFetch(session, baseUrl, grantId, agentId) {
|
|
356
|
+
const origin = new URL(baseUrl).origin;
|
|
357
|
+
const prefix = `/v1/agents/${encodeURIComponent(agentId)}`;
|
|
358
|
+
return async (input, init) => {
|
|
359
|
+
const url = new URL(input instanceof Request ? input.url : input);
|
|
360
|
+
if (url.origin !== origin || (url.pathname !== prefix && !url.pathname.startsWith(`${prefix}/`))) {
|
|
361
|
+
throw new TypeError("Connect managed fetch is restricted to its authorized durable agent");
|
|
362
|
+
}
|
|
363
|
+
const source = input instanceof Request
|
|
364
|
+
? (init === undefined ? input : new Request(input, init))
|
|
365
|
+
: undefined;
|
|
366
|
+
const method = source?.method ?? init?.method ?? "GET";
|
|
367
|
+
const read = method === "GET" && isManagedReadPath(url.pathname.slice(prefix.length));
|
|
368
|
+
url.pathname = `/v1/grants/${grantId}/agents/${encodeURIComponent(agentId)}${url.pathname.slice(prefix.length)}`;
|
|
369
|
+
if (read) {
|
|
370
|
+
const request = new Request(url, source ?? init);
|
|
371
|
+
return session.fetch(new Request(request, { method: "POST" }));
|
|
372
|
+
}
|
|
373
|
+
if (source) return session.fetch(new Request(url, source));
|
|
374
|
+
return session.fetch(url, init);
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** @internal Exact managed reads tunneled as POST so browsers send Origin. */
|
|
379
|
+
export function isManagedReadPath(pathname) {
|
|
380
|
+
return pathname === ""
|
|
381
|
+
|| pathname === "/events"
|
|
382
|
+
|| pathname === "/events/history"
|
|
383
|
+
|| /^\/turns\/[^/]+$/.test(pathname);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
async function* projectManagedEvents(events, visibility) {
|
|
387
|
+
try {
|
|
388
|
+
for await (const event of events) {
|
|
389
|
+
const projected = projectManagedEvent(event, visibility);
|
|
390
|
+
if (projected) yield projected;
|
|
391
|
+
}
|
|
392
|
+
} finally {
|
|
393
|
+
await events.return?.();
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function projectManagedEvent(event, visibility) {
|
|
398
|
+
if (visibility.rawTraces) return event;
|
|
399
|
+
const data = event?.data;
|
|
400
|
+
if (!data || typeof data !== "object") return undefined;
|
|
401
|
+
if (data.type === "event") {
|
|
402
|
+
const eventType = data.event?.type;
|
|
403
|
+
if ((eventType === "assistant.delta" || eventType === "assistant.message")
|
|
404
|
+
&& visibility.finalMessages) {
|
|
405
|
+
const payload = data.event?.payload;
|
|
406
|
+
return payload?.phase === "commentary" ? undefined : event;
|
|
407
|
+
}
|
|
408
|
+
return visibility.actionSummaries
|
|
409
|
+
&& (eventType === "tool.call" || eventType === "tool.result")
|
|
410
|
+
? event
|
|
411
|
+
: undefined;
|
|
412
|
+
}
|
|
413
|
+
if (data.type === "turn_completed" && !visibility.finalMessages) {
|
|
414
|
+
return Object.freeze({
|
|
415
|
+
...event,
|
|
416
|
+
data: Object.freeze({ ...data, final_message: "" }),
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
return event;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** @internal Projects app-visible result fields from the signed SIWE resources. */
|
|
423
|
+
export function projectAgentObservations(visibility, finalMessage, capabilitiesUsed) {
|
|
424
|
+
return Object.freeze({
|
|
425
|
+
finalMessage: visibility.finalMessages ? finalMessage : "",
|
|
426
|
+
capabilitiesUsed: Object.freeze(visibility.actionSummaries ? [...capabilitiesUsed] : []),
|
|
427
|
+
});
|
|
428
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { Base, Client } from "../Client.mjs";
|
|
2
|
+
import type { Instance as PrincipalInstance } from "../Principal.mjs";
|
|
3
|
+
import type {
|
|
4
|
+
CloudAccount,
|
|
5
|
+
Connection,
|
|
6
|
+
HostConnection,
|
|
7
|
+
McpConnection,
|
|
8
|
+
WalletConnection,
|
|
9
|
+
} from "../types.mjs";
|
|
10
|
+
import type { NamedTool } from "../../host/index.mjs";
|
|
11
|
+
|
|
12
|
+
export type Auth = string | Readonly<{
|
|
13
|
+
url?: string | undefined;
|
|
14
|
+
challenge?: string | undefined;
|
|
15
|
+
verify?: string | undefined;
|
|
16
|
+
logout?: string | undefined;
|
|
17
|
+
/** URI resources echoed into the exact EIP-4361 message before signing. */
|
|
18
|
+
resources?: readonly string[] | undefined;
|
|
19
|
+
returnToken?: boolean | undefined;
|
|
20
|
+
}>;
|
|
21
|
+
|
|
22
|
+
export type AuthorizeAccessKey = Readonly<{
|
|
23
|
+
address?: `0x${string}` | undefined;
|
|
24
|
+
chainId?: bigint | undefined;
|
|
25
|
+
expiry: number;
|
|
26
|
+
keyType?: "secp256k1" | "p256" | "webAuthn" | undefined;
|
|
27
|
+
limits?: readonly Readonly<{
|
|
28
|
+
token: `0x${string}`;
|
|
29
|
+
limit: bigint;
|
|
30
|
+
period?: number | undefined;
|
|
31
|
+
}>[] | undefined;
|
|
32
|
+
/** Accounts policy for reusing a locally persisted matching signer. */
|
|
33
|
+
reuse?: Readonly<{
|
|
34
|
+
minExpiry?: number | undefined;
|
|
35
|
+
minLimits?: readonly Readonly<{
|
|
36
|
+
token: `0x${string}`;
|
|
37
|
+
limit: bigint;
|
|
38
|
+
period?: number | undefined;
|
|
39
|
+
}>[] | undefined;
|
|
40
|
+
}> | undefined;
|
|
41
|
+
publicKey?: `0x${string}` | undefined;
|
|
42
|
+
scopes?: readonly Readonly<{
|
|
43
|
+
address: `0x${string}`;
|
|
44
|
+
selector?: `0x${string}` | string | undefined;
|
|
45
|
+
recipients?: readonly `0x${string}`[] | undefined;
|
|
46
|
+
}>[] | undefined;
|
|
47
|
+
}>;
|
|
48
|
+
|
|
49
|
+
export type Capabilities = Readonly<{
|
|
50
|
+
/** SIWE authentication folded into the same passkey ceremony. */
|
|
51
|
+
auth?: Auth | undefined;
|
|
52
|
+
/** Access key authorized by the same passkey ceremony. */
|
|
53
|
+
authorizeAccessKey?: AuthorizeAccessKey | undefined;
|
|
54
|
+
/** Cloud accounts authorized by the same SIWE/passkey message. */
|
|
55
|
+
cloudAccounts?: CloudAccounts | undefined;
|
|
56
|
+
/** App-visible agent output. Omitted fields use the documented defaults. */
|
|
57
|
+
agent?: AgentVisibility | undefined;
|
|
58
|
+
}>;
|
|
59
|
+
|
|
60
|
+
export type CloudAccounts = Readonly<Partial<Record<CloudAccount, true>>>;
|
|
61
|
+
|
|
62
|
+
export type AgentVisibility = Readonly<{
|
|
63
|
+
/** Expose completed assistant messages to the app. @default true */
|
|
64
|
+
finalMessages?: boolean | undefined;
|
|
65
|
+
/** Expose summaries of capabilities used during a turn. @default true */
|
|
66
|
+
actionSummaries?: boolean | undefined;
|
|
67
|
+
/** Allow the app to read retained conversation history. @default false */
|
|
68
|
+
conversationHistory?: boolean | undefined;
|
|
69
|
+
/** Expose the raw ordered agent event stream. Implies every other visibility. @default false */
|
|
70
|
+
rawTraces?: boolean | undefined;
|
|
71
|
+
}>;
|
|
72
|
+
|
|
73
|
+
export declare namespace connect {
|
|
74
|
+
type Options = Readonly<{
|
|
75
|
+
capabilities?: Capabilities | undefined;
|
|
76
|
+
/** Use account-hosted authorization with no access key, spending, or contract authority. @default "hosted" */
|
|
77
|
+
authorization?: "access_key" | "hosted" | undefined;
|
|
78
|
+
/** Let an owning UI close the dialog after its connected state commits. @default "auto" */
|
|
79
|
+
dialog?: Readonly<{ close?: "auto" | "manual" | undefined }> | undefined;
|
|
80
|
+
/** Nanocodex permission preset selected by the app. @default "agent.run" */
|
|
81
|
+
permission?: string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Exact existing account-owned hosted MCP connections requested by this app.
|
|
84
|
+
* Endpoints, provider tokens, and registration credentials are never accepted.
|
|
85
|
+
*/
|
|
86
|
+
mcpConnections?: readonly McpConnection[] | undefined;
|
|
87
|
+
/** Optional requested MCP connection to foreground in the hosted dialog. */
|
|
88
|
+
focusMcpConnectionId?: string | undefined;
|
|
89
|
+
/** Select one newly approved durable conversation by an app-generated UUIDv4. */
|
|
90
|
+
conversationId?: string | undefined;
|
|
91
|
+
/** Exact app-local tool catalog bound into the signed grant. */
|
|
92
|
+
tools?: readonly NamedTool[] | undefined;
|
|
93
|
+
signal?: AbortSignal | undefined;
|
|
94
|
+
}>;
|
|
95
|
+
type ReturnType = Promise<Connection>;
|
|
96
|
+
type ErrorType = Error;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function connect(client: Base<PrincipalInstance>, options: connect.Options): Promise<HostConnection>;
|
|
100
|
+
export function connect(client: Base<undefined>, options: connect.Options): Promise<WalletConnection>;
|
|
101
|
+
export function connect(client: Client, options: connect.Options): connect.ReturnType;
|
|
102
|
+
|
|
103
|
+
export declare namespace disconnect {
|
|
104
|
+
type Options = Readonly<{ signal?: AbortSignal | undefined }>;
|
|
105
|
+
type ReturnType = Promise<void>;
|
|
106
|
+
type ErrorType = Error;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function disconnect(client: Client, options?: disconnect.Options | undefined): disconnect.ReturnType;
|
|
110
|
+
|
|
111
|
+
export declare namespace reconnect {
|
|
112
|
+
type Options = Readonly<{
|
|
113
|
+
/** Reject a retained grant outside these app capability boundaries. */
|
|
114
|
+
capabilities?: Pick<Capabilities, "agent" | "cloudAccounts"> | undefined;
|
|
115
|
+
/** Defaults to the retained connection mode, then to hosted. */
|
|
116
|
+
authorization?: "access_key" | "hosted" | undefined;
|
|
117
|
+
tools?: readonly NamedTool[] | undefined;
|
|
118
|
+
/** Reject a retained grant issued for another permission preset. */
|
|
119
|
+
permission?: string | undefined;
|
|
120
|
+
/** Reject a retained grant with a different exact hosted MCP slice. */
|
|
121
|
+
mcpConnectionIds?: readonly string[] | undefined;
|
|
122
|
+
/** Reject a retained grant for another durable conversation. */
|
|
123
|
+
conversationId?: string | undefined;
|
|
124
|
+
signal?: AbortSignal | undefined;
|
|
125
|
+
}>;
|
|
126
|
+
type ReturnType = Promise<Connection | undefined>;
|
|
127
|
+
type ErrorType = Error;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Restores and validates this app's persisted grant session, if one exists. */
|
|
131
|
+
export function reconnect(client: Base<PrincipalInstance>, options?: reconnect.Options | undefined): Promise<HostConnection | undefined>;
|
|
132
|
+
export function reconnect(client: Base<undefined>, options?: reconnect.Options | undefined): Promise<WalletConnection | undefined>;
|
|
133
|
+
export function reconnect(client: Client, options?: reconnect.Options | undefined): reconnect.ReturnType;
|