nanocodex 0.6.4 → 0.6.6

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.
Files changed (78) hide show
  1. package/README.md +37 -11
  2. package/browser/Agent.d.mts +1 -1
  3. package/browser/ElevenLabsPlayback.mjs +119 -0
  4. package/browser/InlineAgent.mjs +22 -17
  5. package/browser/Transport.d.mts +2 -0
  6. package/browser/Transport.mjs +3 -2
  7. package/browser/Voice.d.mts +4 -0
  8. package/browser/Voice.mjs +38 -6
  9. package/browser/VoiceSession.mjs +37 -7
  10. package/browser/host.d.mts +20 -4
  11. package/browser/host.mjs +156 -18
  12. package/cloud/types.d.mts +1 -0
  13. package/cloudflare/Agent.d.mts +14 -9
  14. package/cloudflare/Agent.mjs +354 -96
  15. package/cloudflare/agent-settings.d.mts +15 -0
  16. package/cloudflare/agent-settings.mjs +135 -0
  17. package/cloudflare/chat-reasoning.mjs +20 -0
  18. package/cloudflare/durable-placement.d.mts +12 -0
  19. package/cloudflare/durable-placement.mjs +82 -0
  20. package/cloudflare/egress.d.mts +31 -0
  21. package/cloudflare/gateway-binding-responses.mjs +84 -0
  22. package/cloudflare/gateway-responses.d.mts +48 -0
  23. package/cloudflare/gateway-responses.mjs +191 -0
  24. package/cloudflare/index.d.mts +6 -0
  25. package/cloudflare/index.mjs +3 -0
  26. package/cloudflare/managed-auth.d.mts +15 -0
  27. package/cloudflare/managed-auth.mjs +119 -0
  28. package/cloudflare/managed-live.d.mts +7 -0
  29. package/cloudflare/managed-live.mjs +56 -0
  30. package/cloudflare/prepared-connection.mjs +49 -0
  31. package/cloudflare/provider-stream.mjs +353 -0
  32. package/cloudflare/rpc.d.mts +9 -0
  33. package/cloudflare/rpc.mjs +14 -0
  34. package/cloudflare/tool-alias-diagnostic.mjs +21 -0
  35. package/cloudflare/tracing.d.mts +16 -0
  36. package/cloudflare/tracing.mjs +47 -0
  37. package/cloudflare/workers-ai-responses.d.mts +28 -0
  38. package/cloudflare/workers-ai-responses.mjs +399 -0
  39. package/host/Agent.d.mts +1 -1
  40. package/index.d.mts +2 -0
  41. package/internal.mjs +53 -14
  42. package/managed/Agent.d.mts +25 -69
  43. package/managed/Agent.mjs +82 -196
  44. package/managed/README.md +9 -38
  45. package/managed/Voice.mjs +5 -2
  46. package/managed/index.d.mts +0 -3
  47. package/managed/internal.mjs +2 -1
  48. package/node/Agent.d.mts +1 -1
  49. package/node/Agent.mjs +9 -3
  50. package/node/host.mjs +5 -0
  51. package/package.json +34 -2
  52. package/pkg-node/nanocodex.d.ts +22 -18
  53. package/pkg-node/nanocodex.js +118 -92
  54. package/pkg-node/nanocodex_bg.wasm.d.ts +6 -5
  55. package/pkg-web/.nanocodex-bindgen-stamp +7 -1
  56. package/pkg-web/nanocodex-build.json +1 -1
  57. package/pkg-web/nanocodex.d.ts +28 -23
  58. package/pkg-web/nanocodex.js +117 -91
  59. package/pkg-web/nanocodex_bg.js +117 -91
  60. package/pkg-web/nanocodex_bg.wasm +0 -0
  61. package/pkg-web/nanocodex_bg.wasm.d.ts +6 -5
  62. package/pkg-web/nanocodex_worker.js +1 -1
  63. package/runtime/before-compaction.mjs +49 -0
  64. package/runtime/code-evaluator.worker.mjs +2 -9
  65. package/runtime/managed-transport.mjs +10 -2
  66. package/runtime/mcp-runtime.mjs +20 -4
  67. package/runtime/quickjs-evaluator.mjs +11 -5
  68. package/runtime/response-controls.mjs +67 -4
  69. package/runtime/steer-receipt.mjs +13 -0
  70. package/runtime/subagent-routing.d.mts +38 -0
  71. package/runtime/subagent-routing.mjs +81 -0
  72. package/runtime/subagents.d.mts +1 -1
  73. package/runtime/tempo-provider.d.mts +1 -1
  74. package/runtime/tempo-provider.mjs +1 -1
  75. package/tools/environment.d.mts +17 -2
  76. package/tools/environment.mjs +30 -3
  77. package/tools/index.d.mts +2 -0
  78. package/types.d.mts +30 -2
@@ -59,13 +59,14 @@ export function routeManagedRealtime(agent, voiceSessionId, operationId, input)
59
59
  }
60
60
 
61
61
  /** @internal Ends the canonical Realtime lifecycle on the selected durable Agent. */
62
- export function stopManagedRealtime(agent, voiceSessionId, operationId) {
62
+ export function stopManagedRealtime(agent, voiceSessionId, operationId, transcript) {
63
63
  const { client, id } = managedAgent(agent);
64
64
  return client.json(`${agentPath(id)}/realtime/stop`, {
65
65
  method: "POST",
66
66
  body: JSON.stringify({
67
67
  voice_session_id: voiceSessionId,
68
68
  operation_id: operationId,
69
+ ...(transcript?.length ? { transcript } : {}),
69
70
  }),
70
71
  });
71
72
  }
package/node/Agent.d.mts CHANGED
@@ -40,7 +40,7 @@ export declare namespace create {
40
40
  | {
41
41
  durability: DurabilityStore;
42
42
  durabilityId: string;
43
- /** The root remains durable; clean subagent children are in-memory. */
43
+ /** The root remains durable; all subagent children are ephemeral. */
44
44
  tools?: ToolConfiguration<SubagentTool> | undefined;
45
45
  }
46
46
  );
package/node/Agent.mjs CHANGED
@@ -35,8 +35,10 @@ export function create(options = {}) {
35
35
  thinking,
36
36
  reasoningMode,
37
37
  fastMode,
38
+ rawApiEvents,
38
39
  instructions,
39
40
  additionalInstructions,
41
+ beforeCompaction,
40
42
  sessionId,
41
43
  workspace,
42
44
  resume,
@@ -72,6 +74,7 @@ export function create(options = {}) {
72
74
  ? undefined
73
75
  : tempoMcp ? { ...tempoMcp, ...mcp } : mcp,
74
76
  onEvent: events.emit,
77
+ beforeCompaction,
75
78
  filesystem,
76
79
  tools: hostTools,
77
80
  toolMode,
@@ -114,6 +117,7 @@ export function create(options = {}) {
114
117
  websocketWarmup,
115
118
  subagents: subagentConfig,
116
119
  hostDefinitionId,
120
+ beforeCompaction: beforeCompaction !== undefined,
117
121
  ...config,
118
122
  durabilityHostId: durabilityOwner?.id,
119
123
  }));
@@ -133,12 +137,13 @@ export function create(options = {}) {
133
137
  adopt(raw) {
134
138
  host.retain();
135
139
  try {
136
- durabilityOwner?.retain();
140
+ // Adopted child handles are ephemeral and do not own the root store.
141
+ if (raw.sessionId === stableSessionId) durabilityOwner?.retain();
137
142
  bindHostSession(host, raw.sessionId);
138
143
  events.addSource(raw);
139
144
  } catch (error) {
140
145
  events.removeSource(raw);
141
- durabilityOwner?.release();
146
+ if (raw.sessionId === stableSessionId) durabilityOwner?.release();
142
147
  releaseHost(host);
143
148
  throw error;
144
149
  }
@@ -147,7 +152,7 @@ export function create(options = {}) {
147
152
  events.removeSource(raw);
148
153
  host.releaseSession(raw.sessionId);
149
154
  releaseHostSession(host, raw.sessionId);
150
- durabilityOwner?.release();
155
+ if (raw.sessionId === stableSessionId) durabilityOwner?.release();
151
156
  releaseHost(host);
152
157
  },
153
158
  decorate: (agent) => agent.extend(agentActions()),
@@ -157,6 +162,7 @@ export function create(options = {}) {
157
162
  thinking,
158
163
  reasoningMode,
159
164
  fastMode,
165
+ rawApiEvents,
160
166
  instructions,
161
167
  additionalInstructions,
162
168
  sessionId: stableSessionId,
package/node/host.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { createBeforeCompaction } from "../runtime/before-compaction.mjs";
1
2
  import { createResponsesHttp, responsesHttpHeaders } from "../runtime/responses-http.mjs";
2
3
  import { Console } from "node:console";
3
4
  import { createRequire } from "node:module";
@@ -23,6 +24,7 @@ const DEFAULT_MAX_FRAME_BYTES = 16 * 1024 * 1024;
23
24
  const MPP_CLIENT_PROTOCOL_ERROR_CLOSE_CODE = 3008;
24
25
 
25
26
  export function createNodeHost(options = {}) {
27
+ const preservation = createBeforeCompaction(options.beforeCompaction);
26
28
  const toolMode = options.toolMode ?? "code";
27
29
  if (toolMode !== "code" && toolMode !== "direct") {
28
30
  throw new TypeError("toolMode must be code or direct");
@@ -295,6 +297,7 @@ export function createNodeHost(options = {}) {
295
297
 
296
298
  function dispose() {
297
299
  if (disposal) return disposal;
300
+ preservation.dispose();
298
301
  http.dispose();
299
302
  disposal = Promise.resolve().then(() => settleCleanup([
300
303
  ...[...connections.keys()].map((handle) => () => close(handle)),
@@ -317,6 +320,8 @@ export function createNodeHost(options = {}) {
317
320
  if (references > 0) references -= 1;
318
321
  return references === 0 ? dispose() : Promise.resolve();
319
322
  },
323
+ beforeCompaction: preservation.preserve,
324
+ cancelBeforeCompaction: preservation.cancel,
320
325
  httpOpen: http.httpOpen,
321
326
  httpReady: http.httpReady,
322
327
  httpNext: http.httpNext,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanocodex",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "Viem-style Node and browser bindings for the Nanocodex WASM agent",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -51,10 +51,22 @@
51
51
  "types": "./cloudflare/index.d.mts",
52
52
  "import": "./cloudflare/index.mjs"
53
53
  },
54
+ "./cloudflare/workers-ai-responses": {
55
+ "types": "./cloudflare/workers-ai-responses.d.mts",
56
+ "import": "./cloudflare/workers-ai-responses.mjs"
57
+ },
58
+ "./cloudflare/durable-placement": {
59
+ "types": "./cloudflare/durable-placement.d.mts",
60
+ "import": "./cloudflare/durable-placement.mjs"
61
+ },
54
62
  "./cloudflare/managed-access": {
55
63
  "types": "./cloudflare/managed-access.d.mts",
56
64
  "import": "./cloudflare/managed-access.mjs"
57
65
  },
66
+ "./cloudflare/rpc": {
67
+ "types": "./cloudflare/rpc.d.mts",
68
+ "import": "./cloudflare/rpc.mjs"
69
+ },
58
70
  "./cloudflare/egress": {
59
71
  "types": "./cloudflare/egress.d.mts",
60
72
  "import": "./cloudflare/egress.mjs"
@@ -134,6 +146,26 @@
134
146
  "./tools/environment": {
135
147
  "types": "./tools/environment.d.mts",
136
148
  "import": "./tools/environment.mjs"
149
+ },
150
+ "./cloudflare/gateway-responses": {
151
+ "types": "./cloudflare/gateway-responses.d.mts",
152
+ "import": "./cloudflare/gateway-responses.mjs"
153
+ },
154
+ "./cloudflare/agent-settings": {
155
+ "types": "./cloudflare/agent-settings.d.mts",
156
+ "import": "./cloudflare/agent-settings.mjs"
157
+ },
158
+ "./cloudflare/managed-auth": {
159
+ "types": "./cloudflare/managed-auth.d.mts",
160
+ "import": "./cloudflare/managed-auth.mjs"
161
+ },
162
+ "./cloudflare/managed-live": {
163
+ "types": "./cloudflare/managed-live.d.mts",
164
+ "import": "./cloudflare/managed-live.mjs"
165
+ },
166
+ "./cloudflare/tracing": {
167
+ "types": "./cloudflare/tracing.d.mts",
168
+ "import": "./cloudflare/tracing.mjs"
137
169
  }
138
170
  },
139
171
  "files": [
@@ -171,7 +203,7 @@
171
203
  "isomorphic-git": "^1.41.5",
172
204
  "minisearch": "7.2.0",
173
205
  "mppx": "0.9.1",
174
- "nanocodex-tools": "0.6.4",
206
+ "nanocodex-tools": "0.6.6",
175
207
  "ox": "1.6.2",
176
208
  "pako": "2.1.0",
177
209
  "pyodide": "314.0.5",
@@ -140,7 +140,7 @@ export class BrowserVoice {
140
140
  */
141
141
  start(): Promise<void>;
142
142
  /**
143
- * Flushes any final transcript tail and ends Codex's Realtime lifecycle.
143
+ * Retains final transcript history without a task and ends the Realtime lifecycle.
144
144
  *
145
145
  * # Errors
146
146
  *
@@ -220,6 +220,13 @@ export class ManagedBrowserVoice {
220
220
  * Rejects inactive sessions, invalid roles/text, or a full output queue.
221
221
  */
222
222
  appendText(role: string, text: string): string;
223
+ /**
224
+ * Binds the known managed call before admission or microphone setup begins.
225
+ *
226
+ * # Errors
227
+ * Rejects invalid session IDs or rebinding an active call.
228
+ */
229
+ bindSession(managed_session_id: string): void;
223
230
  /**
224
231
  * Encodes the managed same-origin call request after the browser creates its SDP offer.
225
232
  *
@@ -331,9 +338,9 @@ export class ManagedBrowserVoice {
331
338
  *
332
339
  * Rejects malformed `AgentSessionContext` JSON.
333
340
  */
334
- start(context_json: string): void;
341
+ start(context_json: string): string;
335
342
  /**
336
- * Stops the protocol and returns final transcript delegation plus close effects.
343
+ * Stops the protocol and returns transcript history plus close effects, without a delegation.
337
344
  *
338
345
  * # Errors
339
346
  *
@@ -367,6 +374,14 @@ export class Nanocodex {
367
374
  * Rejects voices outside Codex's ChatGPT V3 catalog.
368
375
  */
369
376
  browserVoice(voice: string): BrowserVoice;
377
+ /**
378
+ * Exports the exact latest committed model boundary without mutating this agent.
379
+ *
380
+ * # Errors
381
+ *
382
+ * Rejects before the first safe boundary or after the driver stops.
383
+ */
384
+ checkpoint(): Promise<string>;
370
385
  /**
371
386
  * Closes one canonical task-tree child and its descendants.
372
387
  */
@@ -463,16 +478,6 @@ export class Nanocodex {
463
478
  * Rejects malformed transcript JSON.
464
479
  */
465
480
  realtimeTailDelegation(transcript: string): string | undefined;
466
- /**
467
- * Restores persisted logical children after the JavaScript owner acquires
468
- * its durability generation and activates the replacement host.
469
- *
470
- * # Errors
471
- *
472
- * Rejects malformed descriptors, disabled subagents, duplicate restoration,
473
- * or an invalid persisted topology.
474
- */
475
- restoreSubagents(descriptors_json: string, host_contexts_json?: string | null): Promise<void>;
476
481
  /**
477
482
  * Atomically steers the active turn or starts a new independently awaitable turn.
478
483
  *
@@ -665,12 +670,11 @@ export class TurnResult {
665
670
  */
666
671
  export function applyBrowserPatch(patch: string, session_id: string): Promise<string>;
667
672
 
668
- /**
669
- * Returns the shared bounded first-prompt retrieval plan for a managed host.
670
- */
671
- export function managedBootstrapPlan(input: string): string;
672
-
673
673
  /**
674
674
  * Prunes old replay receipts before the full Agent runtime is constructed.
675
+ * Capability marker checked against the actual bundled module before deployment.
676
+ * Older kernels reject the native child route emitted by the current host.
675
677
  */
678
+ export function nativeSpawnContractVersion(): number;
679
+
676
680
  export function pruneDurableReceipts(durability_host_id: string, durability_id: string, terminal_receipt_limit: number): Promise<void>;