nanocodex 0.4.0 → 0.6.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/README.md +944 -78
- package/actions/events.mjs +14 -25
- package/actions/index.d.mts +1 -0
- package/actions/index.mjs +11 -1
- package/actions/session.d.mts +29 -1
- package/actions/session.mjs +22 -0
- package/actions/turn.d.mts +15 -6
- package/actions/turn.mjs +10 -0
- package/actions/voice.d.mts +26 -0
- package/actions/voice.mjs +54 -0
- package/browser/Agent.d.mts +41 -24
- package/browser/Agent.mjs +7 -84
- package/browser/ChatGptSubscription.d.mts +7 -0
- package/browser/ChatGptSubscription.mjs +19 -0
- package/browser/InlineAgent.mjs +267 -0
- package/browser/Transport.d.mts +80 -0
- package/browser/Transport.mjs +63 -0
- package/browser/Voice.d.mts +86 -0
- package/browser/Voice.mjs +316 -0
- package/browser/VoiceSession.mjs +763 -0
- package/browser/WorkerAgent.d.mts +65 -0
- package/browser/WorkerAgent.mjs +1467 -0
- package/browser/agent.worker.mjs +3 -0
- package/browser/config.d.mts +36 -0
- package/browser/config.mjs +439 -0
- package/browser/engine.mjs +13 -0
- package/browser/harness.mjs +55 -0
- package/browser/host.d.mts +33 -5
- package/browser/host.mjs +320 -26
- package/browser/hostManagedWebSocket.d.mts +14 -0
- package/browser/hostManagedWebSocket.mjs +110 -0
- package/browser/index.d.mts +64 -1
- package/browser/index.mjs +22 -1
- package/browser/indexeddb-durability-store.mjs +210 -0
- package/browser/workspace.d.mts +16 -0
- package/browser/workspace.mjs +107 -0
- package/cloud/Client.d.mts +83 -0
- package/cloud/Client.mjs +231 -0
- package/cloud/Decorator.d.mts +31 -0
- package/cloud/Decorator.mjs +37 -0
- package/cloud/Dialog.d.mts +113 -0
- package/cloud/Dialog.mjs +366 -0
- package/cloud/Errors.d.mts +22 -0
- package/cloud/Errors.mjs +39 -0
- package/cloud/Principal.d.mts +26 -0
- package/cloud/Principal.mjs +88 -0
- package/cloud/RemoteProvider.mjs +88 -0
- package/cloud/Transport.d.mts +47 -0
- package/cloud/Transport.mjs +454 -0
- package/cloud/actions/account.d.mts +9 -0
- package/cloud/actions/account.mjs +19 -0
- package/cloud/actions/agent.d.mts +18 -0
- package/cloud/actions/agent.mjs +429 -0
- package/cloud/actions/connection.d.mts +133 -0
- package/cloud/actions/connection.mjs +580 -0
- package/cloud/actions/grant.d.mts +10 -0
- package/cloud/actions/grant.mjs +12 -0
- package/cloud/actions/index.d.mts +7 -0
- package/cloud/actions/index.mjs +7 -0
- package/cloud/actions/machineUsd.d.mts +23 -0
- package/cloud/actions/machineUsd.mjs +37 -0
- package/cloud/actions/model.d.mts +12 -0
- package/cloud/actions/model.mjs +50 -0
- package/cloud/actions/mpp.d.mts +28 -0
- package/cloud/actions/mpp.mjs +39 -0
- package/cloud/index.d.mts +30 -0
- package/cloud/index.mjs +9 -0
- package/cloud/internal.mjs +533 -0
- package/cloud/mercator.mjs +108 -0
- package/cloud/server/HostPrincipal.d.mts +34 -0
- package/cloud/server/HostPrincipal.mjs +202 -0
- package/cloud/server/index.d.mts +1 -0
- package/cloud/server/index.mjs +1 -0
- package/cloud/types.d.mts +212 -0
- package/cloudflare/Agent.d.mts +136 -0
- package/cloudflare/Agent.mjs +784 -0
- package/cloudflare/egress-subject.mjs +19 -0
- package/cloudflare/egress.d.mts +41 -0
- package/cloudflare/egress.mjs +119 -0
- package/cloudflare/event-socket.mjs +316 -0
- package/cloudflare/index.d.mts +7 -0
- package/cloudflare/index.mjs +6 -0
- package/host/Agent.d.mts +55 -0
- package/host/Agent.mjs +1 -0
- package/host/index.d.mts +71 -0
- package/host/index.mjs +10 -0
- package/index.d.mts +46 -0
- package/index.mjs +11 -0
- package/internal.mjs +673 -61
- package/managed/Agent.d.mts +459 -0
- package/managed/Agent.mjs +1824 -0
- package/managed/ManagedError.d.mts +9 -0
- package/managed/ManagedError.mjs +8 -0
- package/managed/README.md +244 -0
- package/managed/Voice.mjs +209 -0
- package/managed/index.d.mts +22 -0
- package/managed/index.mjs +2 -0
- package/managed/internal.mjs +119 -0
- package/node/Agent.d.mts +35 -8
- package/node/Agent.mjs +116 -25
- package/node/ChatGptSubscription.d.mts +9 -0
- package/node/ChatGptSubscription.mjs +17 -0
- package/node/Transport.d.mts +41 -0
- package/node/Transport.mjs +46 -0
- package/node/host.mjs +99 -17
- package/node/index.d.mts +45 -1
- package/node/index.mjs +16 -1
- package/node/workspace.d.mts +10 -0
- package/node/workspace.mjs +198 -0
- package/package.json +145 -11
- package/pkg-node/nanocodex.d.ts +523 -11
- package/pkg-node/nanocodex.js +2038 -179
- package/pkg-node/nanocodex_bg.wasm.d.ts +100 -29
- package/pkg-web/.nanocodex-bindgen-stamp +6 -0
- package/pkg-web/nanocodex-build.json +1 -0
- package/pkg-web/nanocodex.d.ts +623 -40
- package/pkg-web/nanocodex.js +2031 -178
- package/pkg-web/nanocodex_bg.js +2667 -0
- package/pkg-web/nanocodex_bg.wasm +0 -0
- package/pkg-web/nanocodex_bg.wasm.d.ts +100 -29
- package/pkg-web/nanocodex_worker.js +9 -0
- package/runtime/chatgpt-subscription.mjs +212 -0
- package/runtime/cloudflare-durability-store.d.mts +26 -0
- package/runtime/cloudflare-durability-store.mjs +14 -0
- package/runtime/code-evaluator.worker.mjs +137 -0
- package/runtime/code-runtime.mjs +1 -243
- package/runtime/durability-store.d.mts +85 -0
- package/runtime/durability-store.mjs +752 -0
- package/runtime/durability.mjs +174 -0
- package/runtime/managed-transport.mjs +461 -0
- package/runtime/mcp-runtime.mjs +534 -0
- package/runtime/postgres-durability-store.d.mts +64 -0
- package/runtime/postgres-durability-store.mjs +581 -0
- package/runtime/quickjs-evaluator.d.mts +17 -0
- package/runtime/quickjs-evaluator.mjs +236 -0
- package/runtime/response-controls.mjs +42 -0
- package/runtime/response-lanes.mjs +72 -0
- package/runtime/responses-transport.mjs +22 -0
- package/runtime/subagents.d.mts +107 -0
- package/runtime/subagents.mjs +54 -0
- package/runtime/subscription-store.d.mts +8 -0
- package/runtime/subscription-store.mjs +42 -0
- package/runtime/tempo-provider.d.mts +125 -0
- package/runtime/tempo-provider.mjs +264 -0
- package/runtime/tool-configuration.mjs +1 -0
- package/runtime/tool-router.mjs +1 -0
- package/runtime/utf8.mjs +1 -0
- package/runtime/worker-evaluator.mjs +162 -0
- package/runtime/workspace.d.mts +1 -0
- package/runtime/workspace.mjs +1 -0
- package/tools/Tools.d.mts +56 -0
- package/tools/Tools.mjs +136 -0
- package/tools/artifact.d.mts +1 -0
- package/tools/artifact.mjs +1 -0
- package/tools/attachment.mjs +1 -0
- package/tools/bash.d.mts +1 -0
- package/tools/bash.mjs +1 -0
- package/tools/browser/accountInfo.mjs +795 -0
- package/tools/browser/browserBuffer.mjs +18 -0
- package/tools/browser/browserCompiler.mjs +155 -0
- package/tools/browser/browserEgress.mjs +161 -0
- package/tools/browser/browserPython.mjs +133 -0
- package/tools/browser/browserShell.mjs +1075 -0
- package/tools/browser/browserSprintf.mjs +4 -0
- package/tools/browser/browserSsh.mjs +201 -0
- package/tools/browser/browserZlib.mjs +136 -0
- package/tools/browser/compiler.worker.mjs +160 -0
- package/tools/browser/devTunnelsSshBrowser.mjs +13 -0
- package/tools/browser/index.d.mts +209 -0
- package/tools/browser/index.mjs +174 -0
- package/tools/browser/opfsGit.mjs +248 -0
- package/tools/browser/python.worker.mjs +114 -0
- package/tools/browser/threadGit.mjs +197 -0
- package/tools/browser/unsupportedNodeRsa.mjs +5 -0
- package/tools/browser/workspace.mjs +83 -0
- package/tools/dataset.d.mts +1 -0
- package/tools/dataset.mjs +1 -0
- package/tools/datasetContract.mjs +1 -0
- package/tools/datasetEngine.mjs +1 -0
- package/tools/hostedCatalog.d.mts +1 -0
- package/tools/hostedCatalog.mjs +1 -0
- package/tools/index.d.mts +49 -0
- package/tools/index.mjs +19 -0
- package/tools/namedTool.mjs +1 -0
- package/tools/repository-workspace.d.mts +1 -0
- package/tools/repository-workspace.mjs +1 -0
- package/tools/ssh.d.mts +1 -0
- package/tools/ssh.mjs +1 -0
- package/tools/standard.mjs +1 -0
- package/tools/standardDescriptions.mjs +1 -0
- package/types.d.mts +431 -16
- package/worker/ChatGptSubscription.d.mts +9 -0
- package/worker/ChatGptSubscription.mjs +29 -0
- package/worker/index.d.mts +18 -0
- package/worker/index.mjs +5 -0
- package/pkg-node/nanocodex_bg.wasm +0 -0
package/tools/Tools.mjs
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { resolveTools } from "../runtime/tool-configuration.mjs";
|
|
2
|
+
import { tools as workspaceTools } from "../runtime/workspace.mjs";
|
|
3
|
+
import {
|
|
4
|
+
providerSource,
|
|
5
|
+
settleCleanup,
|
|
6
|
+
ToolRouter,
|
|
7
|
+
toolMapSource,
|
|
8
|
+
toolRouterBrand,
|
|
9
|
+
toolRouterRuntime,
|
|
10
|
+
toolRuntimeLifecycle,
|
|
11
|
+
} from "../runtime/tool-router.mjs";
|
|
12
|
+
import { createAttachment } from "./attachment.mjs";
|
|
13
|
+
import { normalizeHostedMachines } from "nanocodex-tools/internal/hosted-machine";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Builds one language-neutral JavaScript-owned tool runtime.
|
|
17
|
+
* Empty custom tools, no workspace, and no MCP are the defaults.
|
|
18
|
+
*/
|
|
19
|
+
export async function createTools(options = {}) {
|
|
20
|
+
validateOptions(options);
|
|
21
|
+
const machines = normalizeHostedMachines(options.machines);
|
|
22
|
+
const attachmentId = options.attachmentId;
|
|
23
|
+
if (machines.length > 0 && attachmentId !== machines[0].id) {
|
|
24
|
+
throw new TypeError("createTools machine attachment requires one machine whose id equals attachmentId");
|
|
25
|
+
}
|
|
26
|
+
const router = new ToolRouter();
|
|
27
|
+
const resolved = resolveTools(
|
|
28
|
+
options.tools === undefined ? {} : options.tools,
|
|
29
|
+
{ defaultSubagents: false },
|
|
30
|
+
);
|
|
31
|
+
if (resolved.subagents) throw new TypeError("createTools does not accept agent-relative extensions");
|
|
32
|
+
const custom = resolved.tools;
|
|
33
|
+
let mcp;
|
|
34
|
+
try {
|
|
35
|
+
if (Object.keys(custom).length) {
|
|
36
|
+
router.addSource(toolMapSource("custom", custom, { kind: "cloud" }));
|
|
37
|
+
}
|
|
38
|
+
if (options.workspace !== undefined) {
|
|
39
|
+
router.addSource(toolMapSource(
|
|
40
|
+
"workspace",
|
|
41
|
+
workspaceTools(options.workspace, options.workspaceOptions),
|
|
42
|
+
{ kind: "cloud" },
|
|
43
|
+
));
|
|
44
|
+
}
|
|
45
|
+
if (options.mcp !== undefined && options.mcp !== false) {
|
|
46
|
+
const { createMcpRuntime } = await import("../runtime/mcp-runtime.mjs");
|
|
47
|
+
mcp = await createMcpRuntime(options.mcp, options.mcpOptions);
|
|
48
|
+
router.addSource(providerSource("mcp", mcp, { kind: "mcp" }));
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (!mcp) throw error;
|
|
52
|
+
try { await mcp.close(); }
|
|
53
|
+
catch (cleanupError) {
|
|
54
|
+
throw new AggregateError(
|
|
55
|
+
[error, cleanupError],
|
|
56
|
+
"Tools construction and MCP cleanup failed",
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
const attachments = new Set();
|
|
62
|
+
let closed = false;
|
|
63
|
+
let closing;
|
|
64
|
+
let claimed = false;
|
|
65
|
+
let owner;
|
|
66
|
+
const lifecycle = Object.freeze({
|
|
67
|
+
available() {
|
|
68
|
+
if (closed) throw new Error("Tools runtime is closed");
|
|
69
|
+
if (claimed) throw new Error("Tools runtime already belongs to an Agent host");
|
|
70
|
+
},
|
|
71
|
+
claim() {
|
|
72
|
+
this.available();
|
|
73
|
+
claimed = true;
|
|
74
|
+
},
|
|
75
|
+
close() { return owner.close(); },
|
|
76
|
+
});
|
|
77
|
+
owner = {
|
|
78
|
+
[toolRouterBrand]: true,
|
|
79
|
+
[toolRouterRuntime]: router,
|
|
80
|
+
[toolRuntimeLifecycle]: lifecycle,
|
|
81
|
+
attach(target) {
|
|
82
|
+
if (closed) throw new Error("Tools runtime is closed");
|
|
83
|
+
if (arguments.length !== 1) throw new TypeError("Tools.attach accepts only a target");
|
|
84
|
+
const attachment = createAttachment(owner, target, { machines, attachmentId });
|
|
85
|
+
attachments.add(attachment);
|
|
86
|
+
void attachment.closed().then(() => attachments.delete(attachment));
|
|
87
|
+
return attachment;
|
|
88
|
+
},
|
|
89
|
+
close() {
|
|
90
|
+
if (closing) return closing;
|
|
91
|
+
closed = true;
|
|
92
|
+
const ownedAttachments = [...attachments];
|
|
93
|
+
attachments.clear();
|
|
94
|
+
closing = Promise.resolve().then(async () => {
|
|
95
|
+
const errors = [];
|
|
96
|
+
try {
|
|
97
|
+
await settleCleanup(
|
|
98
|
+
ownedAttachments.map((attachment) => () => attachment.close()),
|
|
99
|
+
"tool attachment cleanup failed",
|
|
100
|
+
);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
errors.push(...cleanupErrors(error));
|
|
103
|
+
}
|
|
104
|
+
try { await router.reset(closing); }
|
|
105
|
+
catch (error) { errors.push(...cleanupErrors(error)); }
|
|
106
|
+
if (errors.length === 1) throw errors[0];
|
|
107
|
+
if (errors.length > 1) throw new AggregateError(errors, "Tools cleanup failed");
|
|
108
|
+
});
|
|
109
|
+
return closing;
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
return Object.freeze(owner);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function cleanupErrors(error) {
|
|
116
|
+
return error instanceof AggregateError ? error.errors : [error];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function validateOptions(options) {
|
|
120
|
+
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
|
121
|
+
throw new TypeError("createTools options must be an object");
|
|
122
|
+
}
|
|
123
|
+
const allowed = new Set(["tools", "workspace", "workspaceOptions", "mcp", "mcpOptions", "machines", "attachmentId"]);
|
|
124
|
+
for (const name of Object.keys(options)) {
|
|
125
|
+
if (!allowed.has(name)) throw new TypeError(`unsupported createTools option: ${name}`);
|
|
126
|
+
}
|
|
127
|
+
if (options.attachmentId !== undefined && (typeof options.attachmentId !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,122}$/.test(options.attachmentId))) {
|
|
128
|
+
throw new TypeError("createTools attachmentId must be a safe identifier of at most 123 bytes");
|
|
129
|
+
}
|
|
130
|
+
if (options.workspace === undefined && options.workspaceOptions !== undefined) {
|
|
131
|
+
throw new TypeError("workspaceOptions requires workspace");
|
|
132
|
+
}
|
|
133
|
+
if ((options.mcp === undefined || options.mcp === false) && options.mcpOptions !== undefined) {
|
|
134
|
+
throw new TypeError("mcpOptions requires mcp");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "nanocodex-tools/artifact";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "nanocodex-tools/artifact";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "nanocodex-tools/attachment";
|
package/tools/bash.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "nanocodex-tools/bash";
|
package/tools/bash.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "nanocodex-tools/bash";
|