nanocodex 0.1.1 → 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,7 +130,47 @@ export class Nanocodex {
120
130
  }
121
131
  }
122
132
  /**
123
- * Start a clean sibling with the same configuration and tools.
133
+ * Enables or disables priority processing for subsequently accepted turns.
134
+ *
135
+ * # Errors
136
+ *
137
+ * Rejects after the driver stops.
138
+ * @param {boolean} enabled
139
+ * @returns {Promise<void>}
140
+ */
141
+ setFastMode(enabled) {
142
+ const ret = wasm.nanocodex_setFastMode(this.__wbg_ptr, enabled);
143
+ return ret;
144
+ }
145
+ /**
146
+ * Changes the reasoning effort for subsequently accepted turns.
147
+ *
148
+ * # Errors
149
+ *
150
+ * Rejects an invalid effort or a stopped driver.
151
+ * @param {string} thinking
152
+ * @returns {Promise<void>}
153
+ */
154
+ setThinking(thinking) {
155
+ const ptr0 = passStringToWasm0(thinking, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
156
+ const len0 = WASM_VECTOR_LEN;
157
+ const ret = wasm.nanocodex_setThinking(this.__wbg_ptr, ptr0, len0);
158
+ return ret;
159
+ }
160
+ /**
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.
124
174
  *
125
175
  * # Errors
126
176
  *
@@ -135,7 +185,7 @@ export class Nanocodex {
135
185
  if (Symbol.dispose) Nanocodex.prototype[Symbol.dispose] = Nanocodex.prototype.free;
136
186
 
137
187
  /**
138
- * Completion and control handle for one accepted WASM turn.
188
+ * JavaScript binding over one shared Rust turn.
139
189
  */
140
190
  export class Turn {
141
191
  static __wrap(ptr) {
@@ -155,11 +205,11 @@ export class Turn {
155
205
  wasm.__wbg_turn_free(ptr, 0);
156
206
  }
157
207
  /**
158
- * Cancel this exact active or queued turn.
208
+ * Cancels this exact active or queued turn.
159
209
  *
160
210
  * # Errors
161
211
  *
162
- * Rejects if the turn is already terminal or the driver stops.
212
+ * Rejects if the turn is already terminal or its driver stopped.
163
213
  * @returns {Promise<void>}
164
214
  */
165
215
  cancel() {
@@ -167,25 +217,23 @@ export class Turn {
167
217
  return ret;
168
218
  }
169
219
  /**
170
- * Wait for the turn and return its final assistant message.
220
+ * Waits for the final assistant message.
171
221
  *
172
222
  * # Errors
173
223
  *
174
- * Rejects when the model run fails, the driver stops, or two consumers
175
- * await the same pending turn concurrently.
176
- * @returns {Promise<string>}
224
+ * Rejects when the model run or driver fails.
225
+ * @returns {Promise<TurnResult>}
177
226
  */
178
227
  result() {
179
228
  const ret = wasm.turn_result(this.__wbg_ptr);
180
229
  return ret;
181
230
  }
182
231
  /**
183
- * Inject input at this active turn's next safe model boundary.
232
+ * Injects text input at the active turn's next safe model boundary.
184
233
  *
185
234
  * # Errors
186
235
  *
187
- * Rejects for empty input, a queued or terminal turn, a full steer queue,
188
- * or a stopped driver.
236
+ * Rejects if the turn is not active or its driver stopped.
189
237
  * @param {string} instruction
190
238
  * @returns {Promise<void>}
191
239
  */
@@ -196,13 +244,11 @@ export class Turn {
196
244
  return ret;
197
245
  }
198
246
  /**
199
- * Inject ordered browser-safe text, image, or audio input at this active
200
- * turn's next safe model boundary.
247
+ * Injects browser-safe multimodal input at the active turn's next boundary.
201
248
  *
202
249
  * # Errors
203
250
  *
204
- * Rejects for malformed or empty content, local filesystem inputs, a
205
- * queued or terminal turn, a full steer queue, or a stopped driver.
251
+ * Rejects malformed input or a turn that is no longer active.
206
252
  * @param {string} content_json
207
253
  * @returns {Promise<void>}
208
254
  */
@@ -214,6 +260,97 @@ export class Turn {
214
260
  }
215
261
  }
216
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.
302
+ *
303
+ * # Errors
304
+ *
305
+ * Throws when serialization fails.
306
+ * @returns {string}
307
+ */
308
+ snapshot() {
309
+ let deferred2_0;
310
+ let deferred2_1;
311
+ try {
312
+ const ret = wasm.turnresult_snapshot(this.__wbg_ptr);
313
+ var ptr1 = ret[0];
314
+ var len1 = ret[1];
315
+ if (ret[3]) {
316
+ ptr1 = 0; len1 = 0;
317
+ throw takeFromExternrefTable0(ret[2]);
318
+ }
319
+ deferred2_0 = ptr1;
320
+ deferred2_1 = len1;
321
+ return getStringFromWasm0(ptr1, len1);
322
+ } finally {
323
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
324
+ }
325
+ }
326
+ /**
327
+ * Serializes exact aggregate usage for this completed logical turn.
328
+ *
329
+ * # Errors
330
+ *
331
+ * Throws when serialization fails.
332
+ * @returns {string}
333
+ */
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
+ }
351
+ }
352
+ }
353
+ if (Symbol.dispose) TurnResult.prototype[Symbol.dispose] = TurnResult.prototype.free;
217
354
  function __wbg_get_imports() {
218
355
  const import0 = {
219
356
  __proto__: null,
@@ -250,30 +387,29 @@ function __wbg_get_imports() {
250
387
  const ret = arg0.call(arg1, arg2);
251
388
  return ret;
252
389
  }, arguments); },
253
- __wbg_close_b36455f162d504cf: function(arg0) {
390
+ __wbg_close_84b985b15720666a: function(arg0) {
254
391
  globalThis.nanocodexHost.close(arg0 >>> 0);
255
392
  },
256
- __wbg_connect_82a82e999c6dad2f: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
257
- 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));
258
395
  return ret;
259
396
  }, arguments); },
260
- __wbg_emitEvent_fe69df479c60b4dc: function(arg0, arg1) {
397
+ __wbg_emitEvent_52491cc5b9c996ad: function(arg0, arg1) {
261
398
  globalThis.nanocodexHost.emitEvent(getStringFromWasm0(arg0, arg1));
262
399
  },
263
- __wbg_executeCode_1b0871b5adb65342: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
400
+ __wbg_executeCode_616baf56d3c8480c: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
264
401
  const ret = globalThis.nanocodexHost.executeCode(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5));
265
402
  return ret;
266
403
  }, arguments); },
267
- __wbg_getDate_a1a40c1c5f40fe3b: function(arg0) {
268
- const ret = arg0.getDate();
269
- return ret;
270
- },
271
- __wbg_getFullYear_6af8b229792ae254: function(arg0) {
272
- 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();
273
409
  return ret;
274
410
  },
275
- __wbg_getMonth_fffe29d654d5eb69: function(arg0) {
276
- const ret = arg0.getMonth();
411
+ __wbg_getTimezoneOffset_dc9862c79e5a81a3: function(arg0) {
412
+ const ret = arg0.getTimezoneOffset();
277
413
  return ret;
278
414
  },
279
415
  __wbg_get_78f252d074a84d0b: function() { return handleError(function (arg0, arg1) {
@@ -300,6 +436,10 @@ function __wbg_get_imports() {
300
436
  const ret = new Intl.DateTimeFormat(arg0, arg1);
301
437
  return ret;
302
438
  },
439
+ __wbg_new_cc984128914cfc6f: function(arg0) {
440
+ const ret = new Date(arg0);
441
+ return ret;
442
+ },
303
443
  __wbg_new_da52cf8fe3429cb2: function() {
304
444
  const ret = new Object();
305
445
  return ret;
@@ -311,7 +451,7 @@ function __wbg_get_imports() {
311
451
  const a = state0.a;
312
452
  state0.a = 0;
313
453
  try {
314
- return wasm_bindgen__convert__closures_____invoke__h179cb8eb2e8755ae(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);
315
455
  } finally {
316
456
  state0.a = a;
317
457
  }
@@ -322,18 +462,18 @@ function __wbg_get_imports() {
322
462
  state0.a = 0;
323
463
  }
324
464
  },
325
- __wbg_next_9da746b48109347a: function() { return handleError(function (arg0, arg1) {
465
+ __wbg_next_4acad3c8f1e88dfb: function() { return handleError(function (arg0, arg1) {
326
466
  const ret = globalThis.nanocodexHost.next(arg0 >>> 0, arg1 >>> 0);
327
467
  return ret;
328
468
  }, arguments); },
329
- __wbg_now_86c0d4ba3fa605b8: function() {
330
- const ret = Date.now();
331
- return ret;
332
- },
333
469
  __wbg_now_e7c6795a7f81e10f: function(arg0) {
334
470
  const ret = arg0.now();
335
471
  return ret;
336
472
  },
473
+ __wbg_now_f663ab0a5177b799: function() { return handleError(function () {
474
+ const ret = Date.now();
475
+ return ret;
476
+ }, arguments); },
337
477
  __wbg_performance_3fcf6e32a7e1ed0a: function(arg0) {
338
478
  const ret = arg0.performance;
339
479
  return ret;
@@ -353,14 +493,14 @@ function __wbg_get_imports() {
353
493
  const ret = arg0.resolvedOptions();
354
494
  return ret;
355
495
  },
356
- __wbg_send_211e498fb0677de2: function() { return handleError(function (arg0, arg1, arg2) {
496
+ __wbg_send_bdd41ab8e18f6042: function() { return handleError(function (arg0, arg1, arg2) {
357
497
  const ret = globalThis.nanocodexHost.send(arg0 >>> 0, getStringFromWasm0(arg1, arg2));
358
498
  return ret;
359
499
  }, arguments); },
360
- __wbg_sleep_03cdb40ace612b9f: function(arg0) {
361
- 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);
362
502
  return ret;
363
- },
503
+ }, arguments); },
364
504
  __wbg_static_accessor_GLOBAL_4ef717fb391d88b7: function() {
365
505
  const ret = typeof global === 'undefined' ? null : global;
366
506
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
@@ -385,19 +525,28 @@ function __wbg_get_imports() {
385
525
  const ret = arg0.then(arg1);
386
526
  return ret;
387
527
  },
388
- __wbg_toolDefinitions_976a998d8a17c04c: function(arg0, arg1, arg2) {
528
+ __wbg_toolDefinitions_4f496f9fbb096753: function() { return handleError(function (arg0, arg1, arg2) {
389
529
  const ret = globalThis.nanocodexHost.toolDefinitions(getStringFromWasm0(arg1, arg2));
390
530
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
391
531
  const len1 = WASM_VECTOR_LEN;
392
532
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
393
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;
394
538
  },
395
539
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
396
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 57, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
397
- const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h02eb5eea4c10a535);
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`.
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_);
542
+ return ret;
543
+ },
544
+ __wbindgen_cast_0000000000000002: function(arg0) {
545
+ // Cast intrinsic for `F64 -> Externref`.
546
+ const ret = arg0;
398
547
  return ret;
399
548
  },
400
- __wbindgen_cast_0000000000000002: function(arg0, arg1) {
549
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
401
550
  // Cast intrinsic for `Ref(String) -> Externref`.
402
551
  const ret = getStringFromWasm0(arg0, arg1);
403
552
  return ret;
@@ -418,15 +567,15 @@ function __wbg_get_imports() {
418
567
  };
419
568
  }
420
569
 
421
- function wasm_bindgen__convert__closures_____invoke__h02eb5eea4c10a535(arg0, arg1, arg2) {
422
- const ret = wasm.wasm_bindgen__convert__closures_____invoke__h02eb5eea4c10a535(arg0, arg1, arg2);
570
+ function wasm_bindgen_6c97e59ea7837008___convert__closures_____invoke___wasm_bindgen_6c97e59ea7837008___JsValue__core_9b3796e30d99ddb7___result__Result_____wasm_bindgen_6c97e59ea7837008___JsError___true_(arg0, arg1, arg2) {
571
+ const ret = wasm.wasm_bindgen_6c97e59ea7837008___convert__closures_____invoke___wasm_bindgen_6c97e59ea7837008___JsValue__core_9b3796e30d99ddb7___result__Result_____wasm_bindgen_6c97e59ea7837008___JsError___true_(arg0, arg1, arg2);
423
572
  if (ret[1]) {
424
573
  throw takeFromExternrefTable0(ret[0]);
425
574
  }
426
575
  }
427
576
 
428
- function wasm_bindgen__convert__closures_____invoke__h179cb8eb2e8755ae(arg0, arg1, arg2, arg3) {
429
- wasm.wasm_bindgen__convert__closures_____invoke__h179cb8eb2e8755ae(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);
430
579
  }
431
580
 
432
581
  const NanocodexFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -435,6 +584,9 @@ const NanocodexFinalization = (typeof FinalizationRegistry === 'undefined')
435
584
  const TurnFinalization = (typeof FinalizationRegistry === 'undefined')
436
585
  ? { register: () => {}, unregister: () => {} }
437
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));
438
590
 
439
591
  function addToExternrefTable0(obj) {
440
592
  const idx = wasm.__externref_table_alloc();
@@ -517,6 +669,11 @@ function debugString(val) {
517
669
  return className;
518
670
  }
519
671
 
672
+ function getArrayU8FromWasm0(ptr, len) {
673
+ ptr = ptr >>> 0;
674
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
675
+ }
676
+
520
677
  let cachedDataViewMemory0 = null;
521
678
  function getDataViewMemory0() {
522
679
  if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
Binary file
@@ -3,19 +3,27 @@
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];
9
11
  export const nanocodex_prompt: (a: number, b: number, c: number) => [number, number, number];
10
12
  export const nanocodex_promptContent: (a: number, b: number, c: number) => [number, number, number];
11
13
  export const nanocodex_sessionId: (a: number) => [number, number];
14
+ export const nanocodex_setFastMode: (a: number, b: number) => any;
15
+ export const nanocodex_setThinking: (a: number, b: number, c: number) => any;
16
+ export const nanocodex_shutdown: (a: number) => any;
12
17
  export const nanocodex_spawn: (a: number) => any;
13
18
  export const turn_cancel: (a: number) => any;
14
19
  export const turn_result: (a: number) => any;
15
20
  export const turn_steer: (a: number, b: number, c: number) => any;
16
21
  export const turn_steerContent: (a: number, b: number, c: number) => any;
17
- export const wasm_bindgen__convert__closures_____invoke__h02eb5eea4c10a535: (a: number, b: number, c: any) => [number, number];
18
- export const wasm_bindgen__convert__closures_____invoke__h179cb8eb2e8755ae: (a: number, b: number, c: any, d: any) => void;
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];
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];
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;
19
27
  export const __wbindgen_malloc: (a: number, b: number) => number;
20
28
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
21
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,20 +31,24 @@ 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();
38
+ const startedAfterNs = Math.max(
39
+ 0,
40
+ Math.round((toolStartedAt - startedAt) * 1_000_000),
41
+ );
42
+ const recordedInput = clone(input) ?? null;
34
43
  try {
35
- const result = await tool.handler(input, { sessionId, parentCallId, callId });
44
+ const result = await handler(input, { sessionId, parentCallId, callId });
36
45
  nestedCalls.push({
37
46
  call_id: callId,
38
47
  name,
39
- // JSON.stringify omits object fields whose value is undefined.
40
- // Keep zero-argument calls wire-complete for Rust's typed event.
41
- input: clone(input) ?? null,
48
+ input: recordedInput,
42
49
  output: outputBody(result),
43
50
  success: true,
51
+ started_after_ns: startedAfterNs,
44
52
  duration_ns: elapsedNs(toolStartedAt),
45
53
  });
46
54
  return result;
@@ -48,9 +56,10 @@ export function createCodeRuntime(toolConfiguration = {}, extras = {}) {
48
56
  nestedCalls.push({
49
57
  call_id: callId,
50
58
  name,
51
- input: clone(input) ?? null,
59
+ input: recordedInput,
52
60
  output: errorMessage(error),
53
61
  success: false,
62
+ started_after_ns: startedAfterNs,
54
63
  duration_ns: elapsedNs(toolStartedAt),
55
64
  });
56
65
  throw error;
@@ -142,7 +151,7 @@ export function createCodeRuntime(toolConfiguration = {}, extras = {}) {
142
151
 
143
152
  return Object.freeze({
144
153
  executeCode,
145
- toolDefinitions: () => JSON.stringify(definitions),
154
+ toolDefinitions: () => encodedDefinitions,
146
155
  reset() {
147
156
  stores.clear();
148
157
  },
@@ -151,7 +160,7 @@ export function createCodeRuntime(toolConfiguration = {}, extras = {}) {
151
160
 
152
161
  function outputBody(value) {
153
162
  if (Array.isArray(value) && value.every((item) => item?.type === "input_text" || item?.type === "input_image")) {
154
- return value;
163
+ return clone(value);
155
164
  }
156
165
  return stringify(value);
157
166
  }
@@ -171,6 +180,20 @@ function clone(value) {
171
180
  return value === undefined ? undefined : JSON.parse(JSON.stringify(value));
172
181
  }
173
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
+
174
197
  function errorMessage(error) {
175
198
  if (error && (error.stack || error.message)) return error.stack || error.message;
176
199
  return String(error);