nanocodex 0.2.0 → 0.3.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.
@@ -1,7 +1,7 @@
1
1
  /* @ts-self-types="./nanocodex.d.ts" */
2
2
 
3
3
  /**
4
- * Persistent WASM agent handle hosted by Node.js or a browser Worker.
4
+ * JavaScript binding over the shared Rust agent lifecycle.
5
5
  */
6
6
  export class Nanocodex {
7
7
  static __wrap(ptr) {
@@ -21,7 +21,19 @@ export class Nanocodex {
21
21
  wasm.__wbg_nanocodex_free(ptr, 0);
22
22
  }
23
23
  /**
24
- * Fork the latest safe committed model boundary.
24
+ * Compacts retained history immediately without fabricating a user prompt.
25
+ *
26
+ * # Errors
27
+ *
28
+ * Throws when compaction or the agent driver fails.
29
+ * @returns {Promise<void>}
30
+ */
31
+ compact() {
32
+ const ret = wasm.nanocodex_compact(this.__wbg_ptr);
33
+ return ret;
34
+ }
35
+ /**
36
+ * Forks the latest safe committed model boundary.
25
37
  *
26
38
  * # Errors
27
39
  *
@@ -33,26 +45,25 @@ export class Nanocodex {
33
45
  return ret;
34
46
  }
35
47
  /**
36
- * Fork from the exact checkpoint retained by a completed historical turn.
48
+ * Forks from an exact completed historical turn.
37
49
  *
38
50
  * # Errors
39
51
  *
40
- * Rejects if the turn is incomplete, belongs to another lineage, or the
41
- * driver stops.
42
- * @param {Turn} turn
52
+ * Rejects if the result belongs to another agent or the driver stopped.
53
+ * @param {TurnResult} result
43
54
  * @returns {Promise<Nanocodex>}
44
55
  */
45
- forkFrom(turn) {
46
- _assertClass(turn, Turn);
47
- const ret = wasm.nanocodex_forkFrom(this.__wbg_ptr, turn.__wbg_ptr);
56
+ forkFrom(result) {
57
+ _assertClass(result, TurnResult);
58
+ const ret = wasm.nanocodex_forkFrom(this.__wbg_ptr, result.__wbg_ptr);
48
59
  return ret;
49
60
  }
50
61
  /**
51
- * Build a persistent agent from a JSON configuration object.
62
+ * Builds an agent from its JavaScript JSON configuration.
52
63
  *
53
64
  * # Errors
54
65
  *
55
- * Throws when the JSON or required configuration is invalid.
66
+ * Throws when the JSON or agent policy is invalid.
56
67
  * @param {string} config_json
57
68
  */
58
69
  constructor(config_json) {
@@ -67,11 +78,11 @@ export class Nanocodex {
67
78
  return this;
68
79
  }
69
80
  /**
70
- * Accept a prompt immediately and return its independently awaitable turn.
81
+ * Accepts a text prompt and returns its independently awaitable turn.
71
82
  *
72
83
  * # Errors
73
84
  *
74
- * Throws when the prompt is empty or the agent driver has stopped.
85
+ * Throws when the prompt is empty.
75
86
  * @param {string} instruction
76
87
  * @returns {Turn}
77
88
  */
@@ -85,12 +96,11 @@ export class Nanocodex {
85
96
  return Turn.__wrap(ret[0]);
86
97
  }
87
98
  /**
88
- * Accept ordered browser-safe text, image, or audio input encoded as JSON.
99
+ * Accepts browser-safe multimodal input encoded as JSON.
89
100
  *
90
101
  * # Errors
91
102
  *
92
- * Throws for malformed or empty content, local filesystem inputs, or a
93
- * stopped driver.
103
+ * Throws for malformed, empty, or local-filesystem input.
94
104
  * @param {string} content_json
95
105
  * @returns {Turn}
96
106
  */
@@ -104,7 +114,7 @@ export class Nanocodex {
104
114
  return Turn.__wrap(ret[0]);
105
115
  }
106
116
  /**
107
- * Stable session identifier used to route this agent's event stream.
117
+ * Returns the stable `UUIDv7` session identity.
108
118
  * @returns {string}
109
119
  */
110
120
  get sessionId() {
@@ -120,11 +130,11 @@ export class Nanocodex {
120
130
  }
121
131
  }
122
132
  /**
123
- * Enable or disable priority processing for subsequently accepted turns.
133
+ * Enables or disables priority processing for subsequently accepted turns.
124
134
  *
125
135
  * # Errors
126
136
  *
127
- * Rejects after the agent driver stops.
137
+ * Rejects after the driver stops.
128
138
  * @param {boolean} enabled
129
139
  * @returns {Promise<void>}
130
140
  */
@@ -133,11 +143,11 @@ export class Nanocodex {
133
143
  return ret;
134
144
  }
135
145
  /**
136
- * Change the reasoning effort for subsequently accepted turns.
146
+ * Changes the reasoning effort for subsequently accepted turns.
137
147
  *
138
148
  * # Errors
139
149
  *
140
- * Rejects an unsupported effort or a stopped agent driver.
150
+ * Rejects an invalid effort or a stopped driver.
141
151
  * @param {string} thinking
142
152
  * @returns {Promise<void>}
143
153
  */
@@ -148,7 +158,19 @@ export class Nanocodex {
148
158
  return ret;
149
159
  }
150
160
  /**
151
- * Start a clean sibling with the same configuration and tools.
161
+ * Gracefully stops the driver and joins every resource owned by this agent.
162
+ *
163
+ * # Errors
164
+ *
165
+ * Rejects when the driver had already stopped or cleanup fails.
166
+ * @returns {Promise<void>}
167
+ */
168
+ shutdown() {
169
+ const ret = wasm.nanocodex_shutdown(this.__wbg_ptr);
170
+ return ret;
171
+ }
172
+ /**
173
+ * Starts a clean sibling with the same private agent policy.
152
174
  *
153
175
  * # Errors
154
176
  *
@@ -163,7 +185,7 @@ export class Nanocodex {
163
185
  if (Symbol.dispose) Nanocodex.prototype[Symbol.dispose] = Nanocodex.prototype.free;
164
186
 
165
187
  /**
166
- * Completion and control handle for one accepted WASM turn.
188
+ * JavaScript binding over one shared Rust turn.
167
189
  */
168
190
  export class Turn {
169
191
  static __wrap(ptr) {
@@ -183,11 +205,11 @@ export class Turn {
183
205
  wasm.__wbg_turn_free(ptr, 0);
184
206
  }
185
207
  /**
186
- * Cancel this exact active or queued turn.
208
+ * Cancels this exact active or queued turn.
187
209
  *
188
210
  * # Errors
189
211
  *
190
- * Rejects if the turn is already terminal or the driver stops.
212
+ * Rejects if the turn is already terminal or its driver stopped.
191
213
  * @returns {Promise<void>}
192
214
  */
193
215
  cancel() {
@@ -195,31 +217,99 @@ export class Turn {
195
217
  return ret;
196
218
  }
197
219
  /**
198
- * Wait for the turn and return its final assistant message.
220
+ * Waits for the final assistant message.
199
221
  *
200
222
  * # Errors
201
223
  *
202
- * Rejects when the model run fails, the driver stops, or two consumers
203
- * await the same pending turn concurrently.
204
- * @returns {Promise<string>}
224
+ * Rejects when the model run or driver fails.
225
+ * @returns {Promise<TurnResult>}
205
226
  */
206
227
  result() {
207
228
  const ret = wasm.turn_result(this.__wbg_ptr);
208
229
  return ret;
209
230
  }
210
231
  /**
211
- * Serialize this completed turn's resumable session snapshot.
232
+ * Injects text input at the active turn's next safe model boundary.
233
+ *
234
+ * # Errors
235
+ *
236
+ * Rejects if the turn is not active or its driver stopped.
237
+ * @param {string} instruction
238
+ * @returns {Promise<void>}
239
+ */
240
+ steer(instruction) {
241
+ const ptr0 = passStringToWasm0(instruction, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
242
+ const len0 = WASM_VECTOR_LEN;
243
+ const ret = wasm.turn_steer(this.__wbg_ptr, ptr0, len0);
244
+ return ret;
245
+ }
246
+ /**
247
+ * Injects browser-safe multimodal input at the active turn's next boundary.
248
+ *
249
+ * # Errors
250
+ *
251
+ * Rejects malformed input or a turn that is no longer active.
252
+ * @param {string} content_json
253
+ * @returns {Promise<void>}
254
+ */
255
+ steerContent(content_json) {
256
+ const ptr0 = passStringToWasm0(content_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
257
+ const len0 = WASM_VECTOR_LEN;
258
+ const ret = wasm.turn_steerContent(this.__wbg_ptr, ptr0, len0);
259
+ return ret;
260
+ }
261
+ }
262
+ if (Symbol.dispose) Turn.prototype[Symbol.dispose] = Turn.prototype.free;
263
+
264
+ /**
265
+ * JavaScript binding over one completed Rust turn result.
266
+ */
267
+ export class TurnResult {
268
+ static __wrap(ptr) {
269
+ const obj = Object.create(TurnResult.prototype);
270
+ obj.__wbg_ptr = ptr;
271
+ TurnResultFinalization.register(obj, obj.__wbg_ptr, obj);
272
+ return obj;
273
+ }
274
+ __destroy_into_raw() {
275
+ const ptr = this.__wbg_ptr;
276
+ this.__wbg_ptr = 0;
277
+ TurnResultFinalization.unregister(this);
278
+ return ptr;
279
+ }
280
+ free() {
281
+ const ptr = this.__destroy_into_raw();
282
+ wasm.__wbg_turnresult_free(ptr, 0);
283
+ }
284
+ /**
285
+ * Returns the final assistant message.
286
+ * @returns {string}
287
+ */
288
+ get finalMessage() {
289
+ let deferred1_0;
290
+ let deferred1_1;
291
+ try {
292
+ const ret = wasm.turnresult_finalMessage(this.__wbg_ptr);
293
+ deferred1_0 = ret[0];
294
+ deferred1_1 = ret[1];
295
+ return getStringFromWasm0(ret[0], ret[1]);
296
+ } finally {
297
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
298
+ }
299
+ }
300
+ /**
301
+ * Serializes this completed boundary's resumable session snapshot.
212
302
  *
213
303
  * # Errors
214
304
  *
215
- * Throws until the turn has completed or if serialization fails.
305
+ * Throws when serialization fails.
216
306
  * @returns {string}
217
307
  */
218
308
  snapshot() {
219
309
  let deferred2_0;
220
310
  let deferred2_1;
221
311
  try {
222
- const ret = wasm.turn_snapshot(this.__wbg_ptr);
312
+ const ret = wasm.turnresult_snapshot(this.__wbg_ptr);
223
313
  var ptr1 = ret[0];
224
314
  var len1 = ret[1];
225
315
  if (ret[3]) {
@@ -234,40 +324,33 @@ export class Turn {
234
324
  }
235
325
  }
236
326
  /**
237
- * Inject input at this active turn's next safe model boundary.
327
+ * Serializes exact aggregate usage for this completed logical turn.
238
328
  *
239
329
  * # Errors
240
330
  *
241
- * Rejects for empty input, a queued or terminal turn, a full steer queue,
242
- * or a stopped driver.
243
- * @param {string} instruction
244
- * @returns {Promise<void>}
245
- */
246
- steer(instruction) {
247
- const ptr0 = passStringToWasm0(instruction, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
248
- const len0 = WASM_VECTOR_LEN;
249
- const ret = wasm.turn_steer(this.__wbg_ptr, ptr0, len0);
250
- return ret;
251
- }
252
- /**
253
- * Inject ordered browser-safe text, image, or audio input at this active
254
- * turn's next safe model boundary.
255
- *
256
- * # Errors
257
- *
258
- * Rejects for malformed or empty content, local filesystem inputs, a
259
- * queued or terminal turn, a full steer queue, or a stopped driver.
260
- * @param {string} content_json
261
- * @returns {Promise<void>}
331
+ * Throws when serialization fails.
332
+ * @returns {string}
262
333
  */
263
- steerContent(content_json) {
264
- const ptr0 = passStringToWasm0(content_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
265
- const len0 = WASM_VECTOR_LEN;
266
- const ret = wasm.turn_steerContent(this.__wbg_ptr, ptr0, len0);
267
- return ret;
334
+ usage() {
335
+ let deferred2_0;
336
+ let deferred2_1;
337
+ try {
338
+ const ret = wasm.turnresult_usage(this.__wbg_ptr);
339
+ var ptr1 = ret[0];
340
+ var len1 = ret[1];
341
+ if (ret[3]) {
342
+ ptr1 = 0; len1 = 0;
343
+ throw takeFromExternrefTable0(ret[2]);
344
+ }
345
+ deferred2_0 = ptr1;
346
+ deferred2_1 = len1;
347
+ return getStringFromWasm0(ptr1, len1);
348
+ } finally {
349
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
350
+ }
268
351
  }
269
352
  }
270
- if (Symbol.dispose) Turn.prototype[Symbol.dispose] = Turn.prototype.free;
353
+ if (Symbol.dispose) TurnResult.prototype[Symbol.dispose] = TurnResult.prototype.free;
271
354
  function __wbg_get_imports() {
272
355
  const import0 = {
273
356
  __proto__: null,
@@ -304,30 +387,29 @@ function __wbg_get_imports() {
304
387
  const ret = arg0.call(arg1, arg2);
305
388
  return ret;
306
389
  }, arguments); },
307
- __wbg_close_fc18ac046d437740: function(arg0) {
390
+ __wbg_close_84b985b15720666a: function(arg0) {
308
391
  globalThis.nanocodexHost.close(arg0 >>> 0);
309
392
  },
310
- __wbg_connect_703930fc33e0b1fe: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
311
- const ret = globalThis.nanocodexHost.connect(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5));
393
+ __wbg_connect_fdf81494b56b3a0a: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) {
394
+ const ret = globalThis.nanocodexHost.connect(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), arg4 === 0 ? undefined : getStringFromWasm0(arg4, arg5), arg6 !== 0, getStringFromWasm0(arg7, arg8), arg9 === 0 ? undefined : getStringFromWasm0(arg9, arg10));
312
395
  return ret;
313
396
  }, arguments); },
314
- __wbg_emitEvent_6aeed1b6a9321c6d: function(arg0, arg1) {
397
+ __wbg_emitEvent_52491cc5b9c996ad: function(arg0, arg1) {
315
398
  globalThis.nanocodexHost.emitEvent(getStringFromWasm0(arg0, arg1));
316
399
  },
317
- __wbg_executeCode_9b60ca31e4917172: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
400
+ __wbg_executeCode_616baf56d3c8480c: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
318
401
  const ret = globalThis.nanocodexHost.executeCode(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5));
319
402
  return ret;
320
403
  }, arguments); },
321
- __wbg_getDate_a1a40c1c5f40fe3b: function(arg0) {
322
- const ret = arg0.getDate();
323
- return ret;
324
- },
325
- __wbg_getFullYear_6af8b229792ae254: function(arg0) {
326
- const ret = arg0.getFullYear();
404
+ __wbg_getRandomValues_ceb34d8ffce7e87f: function() { return handleError(function (arg0, arg1) {
405
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
406
+ }, arguments); },
407
+ __wbg_getTime_d6f070c088c9b5ed: function(arg0) {
408
+ const ret = arg0.getTime();
327
409
  return ret;
328
410
  },
329
- __wbg_getMonth_fffe29d654d5eb69: function(arg0) {
330
- const ret = arg0.getMonth();
411
+ __wbg_getTimezoneOffset_dc9862c79e5a81a3: function(arg0) {
412
+ const ret = arg0.getTimezoneOffset();
331
413
  return ret;
332
414
  },
333
415
  __wbg_get_78f252d074a84d0b: function() { return handleError(function (arg0, arg1) {
@@ -354,6 +436,10 @@ function __wbg_get_imports() {
354
436
  const ret = new Intl.DateTimeFormat(arg0, arg1);
355
437
  return ret;
356
438
  },
439
+ __wbg_new_cc984128914cfc6f: function(arg0) {
440
+ const ret = new Date(arg0);
441
+ return ret;
442
+ },
357
443
  __wbg_new_da52cf8fe3429cb2: function() {
358
444
  const ret = new Object();
359
445
  return ret;
@@ -365,7 +451,7 @@ function __wbg_get_imports() {
365
451
  const a = state0.a;
366
452
  state0.a = 0;
367
453
  try {
368
- return wasm_bindgen_6c97e59ea7837008___convert__closures_____invoke___js_sys_ec93bd22bf926fce___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined___js_sys_ec93bd22bf926fce___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined_______true_(a, state0.b, arg0, arg1);
454
+ return wasm_bindgen_6c97e59ea7837008___convert__closures_____invoke___js_sys_d57619d9eac2c6da___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined___js_sys_d57619d9eac2c6da___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined_______true_(a, state0.b, arg0, arg1);
369
455
  } finally {
370
456
  state0.a = a;
371
457
  }
@@ -376,18 +462,18 @@ function __wbg_get_imports() {
376
462
  state0.a = 0;
377
463
  }
378
464
  },
379
- __wbg_next_49b0de35982cd4f1: function() { return handleError(function (arg0, arg1) {
465
+ __wbg_next_4acad3c8f1e88dfb: function() { return handleError(function (arg0, arg1) {
380
466
  const ret = globalThis.nanocodexHost.next(arg0 >>> 0, arg1 >>> 0);
381
467
  return ret;
382
468
  }, arguments); },
383
- __wbg_now_86c0d4ba3fa605b8: function() {
384
- const ret = Date.now();
385
- return ret;
386
- },
387
469
  __wbg_now_e7c6795a7f81e10f: function(arg0) {
388
470
  const ret = arg0.now();
389
471
  return ret;
390
472
  },
473
+ __wbg_now_f663ab0a5177b799: function() { return handleError(function () {
474
+ const ret = Date.now();
475
+ return ret;
476
+ }, arguments); },
391
477
  __wbg_performance_3fcf6e32a7e1ed0a: function(arg0) {
392
478
  const ret = arg0.performance;
393
479
  return ret;
@@ -407,14 +493,14 @@ function __wbg_get_imports() {
407
493
  const ret = arg0.resolvedOptions();
408
494
  return ret;
409
495
  },
410
- __wbg_send_dcb152f7d2b1f786: function() { return handleError(function (arg0, arg1, arg2) {
496
+ __wbg_send_bdd41ab8e18f6042: function() { return handleError(function (arg0, arg1, arg2) {
411
497
  const ret = globalThis.nanocodexHost.send(arg0 >>> 0, getStringFromWasm0(arg1, arg2));
412
498
  return ret;
413
499
  }, arguments); },
414
- __wbg_sleep_f4e409e87a98636b: function(arg0) {
415
- const ret = globalThis.nanocodexHost.sleep(arg0 >>> 0);
500
+ __wbg_sleep_c32f4fdaac627991: function() { return handleError(function (arg0, arg1, arg2) {
501
+ const ret = globalThis.nanocodexHost.sleep(getStringFromWasm0(arg0, arg1), arg2 >>> 0);
416
502
  return ret;
417
- },
503
+ }, arguments); },
418
504
  __wbg_static_accessor_GLOBAL_4ef717fb391d88b7: function() {
419
505
  const ret = typeof global === 'undefined' ? null : global;
420
506
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
@@ -439,19 +525,28 @@ function __wbg_get_imports() {
439
525
  const ret = arg0.then(arg1);
440
526
  return ret;
441
527
  },
442
- __wbg_toolDefinitions_7280a1e99f843af9: function(arg0, arg1, arg2) {
528
+ __wbg_toolDefinitions_4f496f9fbb096753: function() { return handleError(function (arg0, arg1, arg2) {
443
529
  const ret = globalThis.nanocodexHost.toolDefinitions(getStringFromWasm0(arg1, arg2));
444
530
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
445
531
  const len1 = WASM_VECTOR_LEN;
446
532
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
447
533
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
534
+ }, arguments); },
535
+ __wbg_turnresult_new: function(arg0) {
536
+ const ret = TurnResult.__wrap(arg0);
537
+ return ret;
448
538
  },
449
539
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
450
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 58, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
540
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 446, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
451
541
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_6c97e59ea7837008___convert__closures_____invoke___wasm_bindgen_6c97e59ea7837008___JsValue__core_9b3796e30d99ddb7___result__Result_____wasm_bindgen_6c97e59ea7837008___JsError___true_);
452
542
  return ret;
453
543
  },
454
- __wbindgen_cast_0000000000000002: function(arg0, arg1) {
544
+ __wbindgen_cast_0000000000000002: function(arg0) {
545
+ // Cast intrinsic for `F64 -> Externref`.
546
+ const ret = arg0;
547
+ return ret;
548
+ },
549
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
455
550
  // Cast intrinsic for `Ref(String) -> Externref`.
456
551
  const ret = getStringFromWasm0(arg0, arg1);
457
552
  return ret;
@@ -479,8 +574,8 @@ function wasm_bindgen_6c97e59ea7837008___convert__closures_____invoke___wasm_bin
479
574
  }
480
575
  }
481
576
 
482
- function wasm_bindgen_6c97e59ea7837008___convert__closures_____invoke___js_sys_ec93bd22bf926fce___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined___js_sys_ec93bd22bf926fce___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined_______true_(arg0, arg1, arg2, arg3) {
483
- wasm.wasm_bindgen_6c97e59ea7837008___convert__closures_____invoke___js_sys_ec93bd22bf926fce___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined___js_sys_ec93bd22bf926fce___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined_______true_(arg0, arg1, arg2, arg3);
577
+ function wasm_bindgen_6c97e59ea7837008___convert__closures_____invoke___js_sys_d57619d9eac2c6da___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined___js_sys_d57619d9eac2c6da___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined_______true_(arg0, arg1, arg2, arg3) {
578
+ wasm.wasm_bindgen_6c97e59ea7837008___convert__closures_____invoke___js_sys_d57619d9eac2c6da___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined___js_sys_d57619d9eac2c6da___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined_______true_(arg0, arg1, arg2, arg3);
484
579
  }
485
580
 
486
581
  const NanocodexFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -489,6 +584,9 @@ const NanocodexFinalization = (typeof FinalizationRegistry === 'undefined')
489
584
  const TurnFinalization = (typeof FinalizationRegistry === 'undefined')
490
585
  ? { register: () => {}, unregister: () => {} }
491
586
  : new FinalizationRegistry(ptr => wasm.__wbg_turn_free(ptr, 1));
587
+ const TurnResultFinalization = (typeof FinalizationRegistry === 'undefined')
588
+ ? { register: () => {}, unregister: () => {} }
589
+ : new FinalizationRegistry(ptr => wasm.__wbg_turnresult_free(ptr, 1));
492
590
 
493
591
  function addToExternrefTable0(obj) {
494
592
  const idx = wasm.__externref_table_alloc();
@@ -571,6 +669,11 @@ function debugString(val) {
571
669
  return className;
572
670
  }
573
671
 
672
+ function getArrayU8FromWasm0(ptr, len) {
673
+ ptr = ptr >>> 0;
674
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
675
+ }
676
+
574
677
  let cachedDataViewMemory0 = null;
575
678
  function getDataViewMemory0() {
576
679
  if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
Binary file
@@ -3,6 +3,8 @@
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_nanocodex_free: (a: number, b: number) => void;
5
5
  export const __wbg_turn_free: (a: number, b: number) => void;
6
+ export const __wbg_turnresult_free: (a: number, b: number) => void;
7
+ export const nanocodex_compact: (a: number) => any;
6
8
  export const nanocodex_fork: (a: number) => any;
7
9
  export const nanocodex_forkFrom: (a: number, b: number) => any;
8
10
  export const nanocodex_new: (a: number, b: number) => [number, number, number];
@@ -11,14 +13,17 @@ export const nanocodex_promptContent: (a: number, b: number, c: number) => [numb
11
13
  export const nanocodex_sessionId: (a: number) => [number, number];
12
14
  export const nanocodex_setFastMode: (a: number, b: number) => any;
13
15
  export const nanocodex_setThinking: (a: number, b: number, c: number) => any;
16
+ export const nanocodex_shutdown: (a: number) => any;
14
17
  export const nanocodex_spawn: (a: number) => any;
15
18
  export const turn_cancel: (a: number) => any;
16
19
  export const turn_result: (a: number) => any;
17
- export const turn_snapshot: (a: number) => [number, number, number, number];
18
20
  export const turn_steer: (a: number, b: number, c: number) => any;
19
21
  export const turn_steerContent: (a: number, b: number, c: number) => any;
22
+ export const turnresult_finalMessage: (a: number) => [number, number];
23
+ export const turnresult_snapshot: (a: number) => [number, number, number, number];
24
+ export const turnresult_usage: (a: number) => [number, number, number, number];
20
25
  export const wasm_bindgen_6c97e59ea7837008___convert__closures_____invoke___wasm_bindgen_6c97e59ea7837008___JsValue__core_9b3796e30d99ddb7___result__Result_____wasm_bindgen_6c97e59ea7837008___JsError___true_: (a: number, b: number, c: any) => [number, number];
21
- export const wasm_bindgen_6c97e59ea7837008___convert__closures_____invoke___js_sys_ec93bd22bf926fce___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined___js_sys_ec93bd22bf926fce___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
26
+ export const wasm_bindgen_6c97e59ea7837008___convert__closures_____invoke___js_sys_d57619d9eac2c6da___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined___js_sys_d57619d9eac2c6da___Function_fn_wasm_bindgen_6c97e59ea7837008___JsValue_____wasm_bindgen_6c97e59ea7837008___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
22
27
  export const __wbindgen_malloc: (a: number, b: number) => number;
23
28
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
24
29
  export const __wbindgen_exn_store: (a: number) => void;
@@ -2,23 +2,27 @@ export function createCodeRuntime(toolConfiguration = {}, extras = {}) {
2
2
  const stores = new Map();
3
3
  let nextCallId = 1;
4
4
  const definitions = [];
5
+ const configuredTools = [];
5
6
 
6
7
  for (const [name, tool] of Object.entries(toolConfiguration)) {
7
8
  if (!tool || typeof tool.handler !== "function") {
8
9
  throw new TypeError(`tool ${name} requires a handler function`);
9
10
  }
10
- definitions.push({
11
+ configuredTools.push(Object.freeze({ handler: tool.handler, name }));
12
+ definitions.push(deepFreeze({
11
13
  type: "function",
12
14
  name,
13
15
  description: tool.description || "Application-defined tool.",
14
16
  strict: false,
15
- parameters: tool.parameters || {
17
+ parameters: jsonSnapshot(tool.parameters || {
16
18
  type: "object",
17
19
  additionalProperties: true,
18
- },
19
- });
20
+ }, `tool ${name} parameters`),
21
+ }));
20
22
  }
23
+ Object.freeze(configuredTools);
21
24
  Object.freeze(definitions);
25
+ const encodedDefinitions = JSON.stringify(definitions);
22
26
 
23
27
  async function executeCode(source, sessionId = "default", parentCallId = "exec") {
24
28
  const startedAt = performance.now();
@@ -27,7 +31,7 @@ export function createCodeRuntime(toolConfiguration = {}, extras = {}) {
27
31
  stores.set(sessionId, stored);
28
32
  const nestedCalls = [];
29
33
  const tools = Object.create(null);
30
- for (const [name, tool] of Object.entries(toolConfiguration)) {
34
+ for (const { handler, name } of configuredTools) {
31
35
  tools[name] = async (input) => {
32
36
  const callId = `${parentCallId}/code-${nextCallId++}`;
33
37
  const toolStartedAt = performance.now();
@@ -35,14 +39,13 @@ export function createCodeRuntime(toolConfiguration = {}, extras = {}) {
35
39
  0,
36
40
  Math.round((toolStartedAt - startedAt) * 1_000_000),
37
41
  );
42
+ const recordedInput = clone(input) ?? null;
38
43
  try {
39
- const result = await tool.handler(input, { sessionId, parentCallId, callId });
44
+ const result = await handler(input, { sessionId, parentCallId, callId });
40
45
  nestedCalls.push({
41
46
  call_id: callId,
42
47
  name,
43
- // JSON.stringify omits object fields whose value is undefined.
44
- // Keep zero-argument calls wire-complete for Rust's typed event.
45
- input: clone(input) ?? null,
48
+ input: recordedInput,
46
49
  output: outputBody(result),
47
50
  success: true,
48
51
  started_after_ns: startedAfterNs,
@@ -53,7 +56,7 @@ export function createCodeRuntime(toolConfiguration = {}, extras = {}) {
53
56
  nestedCalls.push({
54
57
  call_id: callId,
55
58
  name,
56
- input: clone(input) ?? null,
59
+ input: recordedInput,
57
60
  output: errorMessage(error),
58
61
  success: false,
59
62
  started_after_ns: startedAfterNs,
@@ -148,7 +151,7 @@ export function createCodeRuntime(toolConfiguration = {}, extras = {}) {
148
151
 
149
152
  return Object.freeze({
150
153
  executeCode,
151
- toolDefinitions: () => JSON.stringify(definitions),
154
+ toolDefinitions: () => encodedDefinitions,
152
155
  reset() {
153
156
  stores.clear();
154
157
  },
@@ -157,7 +160,7 @@ export function createCodeRuntime(toolConfiguration = {}, extras = {}) {
157
160
 
158
161
  function outputBody(value) {
159
162
  if (Array.isArray(value) && value.every((item) => item?.type === "input_text" || item?.type === "input_image")) {
160
- return value;
163
+ return clone(value);
161
164
  }
162
165
  return stringify(value);
163
166
  }
@@ -177,6 +180,20 @@ function clone(value) {
177
180
  return value === undefined ? undefined : JSON.parse(JSON.stringify(value));
178
181
  }
179
182
 
183
+ function jsonSnapshot(value, label) {
184
+ try {
185
+ return JSON.parse(JSON.stringify(value));
186
+ } catch (error) {
187
+ throw new TypeError(`${label} must be JSON-serializable`, { cause: error });
188
+ }
189
+ }
190
+
191
+ function deepFreeze(value) {
192
+ if (!value || typeof value !== "object" || Object.isFrozen(value)) return value;
193
+ for (const child of Object.values(value)) deepFreeze(child);
194
+ return Object.freeze(value);
195
+ }
196
+
180
197
  function errorMessage(error) {
181
198
  if (error && (error.stack || error.message)) return error.stack || error.message;
182
199
  return String(error);