nanocodex 0.6.0 → 0.6.4

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 (54) hide show
  1. package/README.md +158 -6
  2. package/browser/InlineAgent.mjs +2 -0
  3. package/browser/Transport.d.mts +3 -0
  4. package/browser/Transport.mjs +1 -0
  5. package/browser/Voice.d.mts +2 -0
  6. package/browser/Voice.mjs +12 -6
  7. package/browser/VoiceSession.mjs +71 -21
  8. package/browser/WorkerAgent.mjs +2 -1
  9. package/browser/host.d.mts +7 -0
  10. package/browser/host.mjs +19 -0
  11. package/cloud/Decorator.d.mts +9 -0
  12. package/cloud/Decorator.mjs +9 -0
  13. package/cloud/Transport.mjs +6 -0
  14. package/cloud/actions/connection.mjs +3 -0
  15. package/cloud/actions/connector.d.mts +18 -0
  16. package/cloud/actions/connector.mjs +22 -0
  17. package/cloud/actions/index.d.mts +2 -0
  18. package/cloud/actions/index.mjs +2 -0
  19. package/cloud/internal.mjs +5 -0
  20. package/cloud/types.d.mts +2 -0
  21. package/cloudflare/Agent.mjs +7 -1
  22. package/cloudflare/egress.d.mts +3 -1
  23. package/cloudflare/egress.mjs +14 -0
  24. package/cloudflare/managed-access.d.mts +23 -0
  25. package/cloudflare/managed-access.mjs +120 -0
  26. package/internal.mjs +27 -0
  27. package/managed/Access.d.mts +5 -0
  28. package/managed/Access.mjs +66 -0
  29. package/managed/Agent.d.mts +16 -7
  30. package/managed/Agent.mjs +28 -7
  31. package/managed/Voice.mjs +1 -0
  32. package/managed/index.d.mts +1 -0
  33. package/managed/index.mjs +1 -0
  34. package/node/host.mjs +12 -0
  35. package/package.json +11 -2
  36. package/pkg-node/nanocodex.js +55 -40
  37. package/pkg-node/nanocodex_bg.wasm.d.ts +3 -3
  38. package/pkg-web/.nanocodex-bindgen-stamp +1 -1
  39. package/pkg-web/nanocodex-build.json +1 -1
  40. package/pkg-web/nanocodex.d.ts +3 -3
  41. package/pkg-web/nanocodex.js +55 -40
  42. package/pkg-web/nanocodex_bg.js +55 -40
  43. package/pkg-web/nanocodex_bg.wasm +0 -0
  44. package/pkg-web/nanocodex_bg.wasm.d.ts +3 -3
  45. package/runtime/code-evaluator.worker.mjs +28 -22
  46. package/runtime/managed-transport.mjs +1 -0
  47. package/runtime/quickjs-evaluator.mjs +59 -17
  48. package/runtime/response-controls.mjs +41 -24
  49. package/runtime/responses-http.mjs +69 -0
  50. package/tools/browser/accountInfo.mjs +53 -8
  51. package/tools/browser/browserShell.mjs +2 -2
  52. package/tools/browser/index.mjs +3 -3
  53. package/tools/environment.d.mts +34 -0
  54. package/tools/environment.mjs +59 -0
@@ -2064,10 +2064,10 @@ export function __wbg___wbindgen_throw_344f42d3211c4765(arg0, arg1) {
2064
2064
  export function __wbg__wbg_cb_unref_fffb441def202758(arg0) {
2065
2065
  getObject(arg0)._wbg_cb_unref();
2066
2066
  }
2067
- export function __wbg_beginCodeTurn_562e43a4d024e969(arg0, arg1) {
2067
+ export function __wbg_beginCodeTurn_0a7124b7eee451a5(arg0, arg1) {
2068
2068
  globalThis.nanocodexHost.beginCodeTurn(getStringFromWasm0(arg0, arg1));
2069
2069
  }
2070
- export function __wbg_bindSubagentSession_0739d749b1a66d55() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) {
2070
+ export function __wbg_bindSubagentSession_94bff1e8dd70d1d1() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) {
2071
2071
  globalThis.nanocodexHost.bindSubagentSession(arg0 >>> 0, getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4), getStringFromWasm0(arg5, arg6), arg7 === 0 ? undefined : getStringFromWasm0(arg7, arg8));
2072
2072
  }, arguments); }
2073
2073
  export function __wbg_call_8a2dd23819f8a60a() { return handleError(function (arg0, arg1) {
@@ -2078,50 +2078,50 @@ export function __wbg_call_a6e5c5dce5018821() { return handleError(function (arg
2078
2078
  const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
2079
2079
  return addHeapObject(ret);
2080
2080
  }, arguments); }
2081
- export function __wbg_cancelCodeTurn_0289eab94b547fa9(arg0, arg1) {
2081
+ export function __wbg_cancelCodeTurn_cd5a2ff077ecc94f(arg0, arg1) {
2082
2082
  globalThis.nanocodexHost.cancelCodeTurn(getStringFromWasm0(arg0, arg1));
2083
2083
  }
2084
- export function __wbg_cancelCode_34a11a338ededbe2(arg0, arg1) {
2084
+ export function __wbg_cancelCode_c598a558677e0400(arg0, arg1) {
2085
2085
  globalThis.nanocodexHost.cancelCode(getStringFromWasm0(arg0, arg1));
2086
2086
  }
2087
2087
  export function __wbg_chatgptsubscription_new(arg0) {
2088
2088
  const ret = ChatGptSubscription.__wrap(arg0);
2089
2089
  return addHeapObject(ret);
2090
2090
  }
2091
- export function __wbg_close_e47f7852ba6527a3(arg0) {
2091
+ export function __wbg_close_fdf88ca6545d2dfa(arg0) {
2092
2092
  globalThis.nanocodexHost.close(arg0 >>> 0);
2093
2093
  }
2094
- export function __wbg_connect_f17b2b140b3402d3() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) {
2094
+ export function __wbg_connect_a4aca5683039d7a7() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) {
2095
2095
  const ret = globalThis.nanocodexHost.connect(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), arg4 === 0 ? undefined : getStringFromWasm0(arg4, arg5), arg6 !== 0, getStringFromWasm0(arg7, arg8), getStringFromWasm0(arg9, arg10), arg11 === 0 ? undefined : getStringFromWasm0(arg11, arg12));
2096
2096
  return addHeapObject(ret);
2097
2097
  }, arguments); }
2098
- export function __wbg_durabilityAcquire_f93999e2fde26eb1() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
2098
+ export function __wbg_durabilityAcquire_2ef4917a34fa75f2() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
2099
2099
  const ret = globalThis.nanocodexHost.durabilityAcquire(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5));
2100
2100
  return addHeapObject(ret);
2101
2101
  }, arguments); }
2102
- export function __wbg_durabilityReadRecord_a95f9c0591d8bdd7() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
2102
+ export function __wbg_durabilityReadRecord_539304eeef4f34de() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
2103
2103
  const ret = globalThis.nanocodexHost.durabilityReadRecord(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5));
2104
2104
  return addHeapObject(ret);
2105
2105
  }, arguments); }
2106
- export function __wbg_durabilityReadRecords_55154229140c587c() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
2106
+ export function __wbg_durabilityReadRecords_d858dd4d53e07fad() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
2107
2107
  const ret = globalThis.nanocodexHost.durabilityReadRecords(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5));
2108
2108
  return addHeapObject(ret);
2109
2109
  }, arguments); }
2110
- export function __wbg_durabilityReplace_c4b92bb6e96144af() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13) {
2110
+ export function __wbg_durabilityReplace_98e18f8a4e1ffa87() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13) {
2111
2111
  const ret = globalThis.nanocodexHost.durabilityReplace(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5), getStringFromWasm0(arg6, arg7), getStringFromWasm0(arg8, arg9), getStringFromWasm0(arg10, arg11), getStringFromWasm0(arg12, arg13));
2112
2112
  return addHeapObject(ret);
2113
2113
  }, arguments); }
2114
- export function __wbg_emitEvent_117683c6b324c5d7() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
2114
+ export function __wbg_emitEvent_ea060841206c3e75() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
2115
2115
  globalThis.nanocodexHost.emitEvent(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), arg4 >>> 0, arg5 === 0 ? undefined : getStringFromWasm0(arg5, arg6));
2116
2116
  }, arguments); }
2117
- export function __wbg_error_142f90eed0c7cc75() { return handleError(function (arg0, arg1, arg2) {
2117
+ export function __wbg_error_90a3fc8068d88664() { return handleError(function (arg0, arg1, arg2) {
2118
2118
  console.error(getStringFromWasm0(arg0, arg1), getObject(arg2));
2119
2119
  }, arguments); }
2120
- export function __wbg_executeCode_c07d50da74c407df() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
2120
+ export function __wbg_executeCode_1f043e54c74768ed() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
2121
2121
  const ret = globalThis.nanocodexHost.executeCode(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5), getStringFromWasm0(arg6, arg7));
2122
2122
  return addHeapObject(ret);
2123
2123
  }, arguments); }
2124
- export function __wbg_executeTool_86d627717b7b04d6() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {
2124
+ export function __wbg_executeTool_77f3e9a52b85860c() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {
2125
2125
  const ret = globalThis.nanocodexHost.executeTool(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5), getStringFromWasm0(arg6, arg7), getStringFromWasm0(arg8, arg9));
2126
2126
  return addHeapObject(ret);
2127
2127
  }, arguments); }
@@ -2147,6 +2147,21 @@ export function __wbg_get_unchecked_6e0ad6d2a41b06f6(arg0, arg1) {
2147
2147
  const ret = getObject(arg0)[arg1 >>> 0];
2148
2148
  return addHeapObject(ret);
2149
2149
  }
2150
+ export function __wbg_httpClose_bb7d713b151b9a56(arg0) {
2151
+ globalThis.nanocodexHost.httpClose(arg0 >>> 0);
2152
+ }
2153
+ export function __wbg_httpNext_4cb6bce08da7fadb() { return handleError(function (arg0) {
2154
+ const ret = globalThis.nanocodexHost.httpNext(arg0 >>> 0);
2155
+ return addHeapObject(ret);
2156
+ }, arguments); }
2157
+ export function __wbg_httpOpen_7b0f76ffd6c246d1() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14) {
2158
+ const ret = globalThis.nanocodexHost.httpOpen(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), arg4 === 0 ? undefined : getStringFromWasm0(arg4, arg5), arg6 !== 0, getStringFromWasm0(arg7, arg8), getStringFromWasm0(arg9, arg10), arg11 === 0 ? undefined : getStringFromWasm0(arg11, arg12), getStringFromWasm0(arg13, arg14));
2159
+ return ret;
2160
+ }, arguments); }
2161
+ export function __wbg_httpReady_472d23f7f1654a26() { return handleError(function (arg0) {
2162
+ const ret = globalThis.nanocodexHost.httpReady(arg0 >>> 0);
2163
+ return addHeapObject(ret);
2164
+ }, arguments); }
2150
2165
  export function __wbg_instanceof_Uint8Array_309b927aaf7a3fc7(arg0) {
2151
2166
  let result;
2152
2167
  try {
@@ -2212,7 +2227,7 @@ export function __wbg_new_typed_1824d93f294193e5(arg0, arg1) {
2212
2227
  const a = state0.a;
2213
2228
  state0.a = 0;
2214
2229
  try {
2215
- return __wasm_bindgen_func_elem_19793(a, state0.b, arg0, arg1);
2230
+ return __wasm_bindgen_func_elem_24935(a, state0.b, arg0, arg1);
2216
2231
  } finally {
2217
2232
  state0.a = a;
2218
2233
  }
@@ -2223,11 +2238,11 @@ export function __wbg_new_typed_1824d93f294193e5(arg0, arg1) {
2223
2238
  state0.a = 0;
2224
2239
  }
2225
2240
  }
2226
- export function __wbg_nextCodeUpdate_81e642d6973d8080() { return handleError(function (arg0, arg1, arg2, arg3) {
2241
+ export function __wbg_nextCodeUpdate_8f3d030aa1cf40cf() { return handleError(function (arg0, arg1, arg2, arg3) {
2227
2242
  const ret = globalThis.nanocodexHost.nextCodeUpdate(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3));
2228
2243
  return addHeapObject(ret);
2229
2244
  }, arguments); }
2230
- export function __wbg_next_a97247e133bb6188() { return handleError(function (arg0) {
2245
+ export function __wbg_next_73a833f68917f36e() { return handleError(function (arg0) {
2231
2246
  const ret = globalThis.nanocodexHost.next(arg0 >>> 0);
2232
2247
  return addHeapObject(ret);
2233
2248
  }, arguments); }
@@ -2257,14 +2272,14 @@ export function __wbg_queueMicrotask_0ab5b2d2393e99b9(arg0) {
2257
2272
  export function __wbg_queueMicrotask_6a09b7bc46549209(arg0) {
2258
2273
  queueMicrotask(getObject(arg0));
2259
2274
  }
2260
- export function __wbg_readWorkspaceFile_ce1dfa978e09347b() { return handleError(function (arg0, arg1, arg2, arg3) {
2275
+ export function __wbg_readWorkspaceFile_aa4a72507d05aff1() { return handleError(function (arg0, arg1, arg2, arg3) {
2261
2276
  const ret = globalThis.nanocodexHost.readWorkspaceFile(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3));
2262
2277
  return addHeapObject(ret);
2263
2278
  }, arguments); }
2264
- export function __wbg_releaseSubagentSession_3b41b91262fb7b84() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
2279
+ export function __wbg_releaseSubagentSession_1a80c6837d2f614c() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
2265
2280
  globalThis.nanocodexHost.releaseSubagentSession(arg0 >>> 0, getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
2266
2281
  }, arguments); }
2267
- export function __wbg_removeWorkspaceFile_913543277dc3d8a6() { return handleError(function (arg0, arg1, arg2, arg3) {
2282
+ export function __wbg_removeWorkspaceFile_142bc3149a6ebc97() { return handleError(function (arg0, arg1, arg2, arg3) {
2268
2283
  const ret = globalThis.nanocodexHost.removeWorkspaceFile(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3));
2269
2284
  return addHeapObject(ret);
2270
2285
  }, arguments); }
@@ -2276,11 +2291,11 @@ export function __wbg_resolvedOptions_ce0ede387898d6bd(arg0) {
2276
2291
  const ret = getObject(arg0).resolvedOptions();
2277
2292
  return addHeapObject(ret);
2278
2293
  }
2279
- export function __wbg_send_7e40303b2078ba70() { return handleError(function (arg0, arg1, arg2) {
2294
+ export function __wbg_send_4a0833d63a63b91f() { return handleError(function (arg0, arg1, arg2) {
2280
2295
  const ret = globalThis.nanocodexHost.send(arg0 >>> 0, getStringFromWasm0(arg1, arg2));
2281
2296
  return addHeapObject(ret);
2282
2297
  }, arguments); }
2283
- export function __wbg_setTimeout_5a8020b9bc901945(arg0, arg1) {
2298
+ export function __wbg_setTimeout_c6205ad5adcd1a59(arg0, arg1) {
2284
2299
  const ret = globalThis.setTimeout(getObject(arg0), arg1);
2285
2300
  return addHeapObject(ret);
2286
2301
  }
@@ -2288,7 +2303,7 @@ export function __wbg_set_8535240470bf2500() { return handleError(function (arg0
2288
2303
  const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
2289
2304
  return ret;
2290
2305
  }, arguments); }
2291
- export function __wbg_sleep_f8472ee57dd033c4() { return handleError(function (arg0, arg1, arg2) {
2306
+ export function __wbg_sleep_3921e17fb319947c() { return handleError(function (arg0, arg1, arg2) {
2292
2307
  const ret = globalThis.nanocodexHost.sleep(getStringFromWasm0(arg0, arg1), arg2 >>> 0);
2293
2308
  return addHeapObject(ret);
2294
2309
  }, arguments); }
@@ -2308,15 +2323,15 @@ export function __wbg_static_accessor_WINDOW_f2829a2234d7819e() {
2308
2323
  const ret = typeof window === 'undefined' ? null : window;
2309
2324
  return isLikeNone(ret) ? 0 : addHeapObject(ret);
2310
2325
  }
2311
- export function __wbg_subscriptionCompareAndSwap_314b83b503c547e4() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
2326
+ export function __wbg_subscriptionCompareAndSwap_a9d25cd277d5d0ef() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
2312
2327
  const ret = globalThis.nanocodexHost.subscriptionCompareAndSwap(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5));
2313
2328
  return addHeapObject(ret);
2314
2329
  }, arguments); }
2315
- export function __wbg_subscriptionLoad_ba70514eb107cef9() { return handleError(function (arg0, arg1) {
2330
+ export function __wbg_subscriptionLoad_26d28b5db170c54b() { return handleError(function (arg0, arg1) {
2316
2331
  const ret = globalThis.nanocodexHost.subscriptionLoad(getStringFromWasm0(arg0, arg1));
2317
2332
  return addHeapObject(ret);
2318
2333
  }, arguments); }
2319
- export function __wbg_subscriptionRequest_a13061bc25f3b48c() { return handleError(function (arg0, arg1, arg2, arg3) {
2334
+ export function __wbg_subscriptionRequest_cedb47bd8ab61075() { return handleError(function (arg0, arg1, arg2, arg3) {
2320
2335
  const ret = globalThis.nanocodexHost.subscriptionRequest(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3));
2321
2336
  return addHeapObject(ret);
2322
2337
  }, arguments); }
@@ -2328,14 +2343,14 @@ export function __wbg_then_6ec10ae38b3e92f7(arg0, arg1) {
2328
2343
  const ret = getObject(arg0).then(getObject(arg1));
2329
2344
  return addHeapObject(ret);
2330
2345
  }
2331
- export function __wbg_toolDefinitions_1b7c861eb298b0f7() { return handleError(function (arg0, arg1, arg2, arg3) {
2346
+ export function __wbg_toolDefinitions_1a0d8e90ad1fa7f9() { return handleError(function (arg0, arg1, arg2, arg3) {
2332
2347
  const ret = globalThis.nanocodexHost.toolDefinitions(arg1 >>> 0, getStringFromWasm0(arg2, arg3));
2333
2348
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
2334
2349
  const len1 = WASM_VECTOR_LEN;
2335
2350
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
2336
2351
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
2337
2352
  }, arguments); }
2338
- export function __wbg_toolMode_e724941f28c8358d(arg0, arg1, arg2, arg3) {
2353
+ export function __wbg_toolMode_a1078d9aa4c7dda3(arg0, arg1, arg2, arg3) {
2339
2354
  const ret = globalThis.nanocodexHost.toolMode(arg1 >>> 0, getStringFromWasm0(arg2, arg3));
2340
2355
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
2341
2356
  const len1 = WASM_VECTOR_LEN;
@@ -2350,22 +2365,22 @@ export function __wbg_turnresult_new(arg0) {
2350
2365
  const ret = TurnResult.__wrap(arg0);
2351
2366
  return addHeapObject(ret);
2352
2367
  }
2353
- export function __wbg_waitCode_643e87f0ee663a3f() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
2368
+ export function __wbg_waitCode_a3ad47cf509664d9() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
2354
2369
  const ret = globalThis.nanocodexHost.waitCode(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5));
2355
2370
  return addHeapObject(ret);
2356
2371
  }, arguments); }
2357
- export function __wbg_writeWorkspaceFile_28ef4bf3f8930a6f() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
2372
+ export function __wbg_writeWorkspaceFile_6285745ca0de9e76() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
2358
2373
  const ret = globalThis.nanocodexHost.writeWorkspaceFile(getStringFromWasm0(arg0, arg1), getObject(arg2), getStringFromWasm0(arg3, arg4));
2359
2374
  return addHeapObject(ret);
2360
2375
  }, arguments); }
2361
2376
  export function __wbindgen_cast_0000000000000001(arg0, arg1) {
2362
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 2813, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
2363
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_19791);
2377
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 3664, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
2378
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_24933);
2364
2379
  return addHeapObject(ret);
2365
2380
  }
2366
2381
  export function __wbindgen_cast_0000000000000002(arg0, arg1) {
2367
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 508, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2368
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_4593);
2382
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 529, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2383
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_4744);
2369
2384
  return addHeapObject(ret);
2370
2385
  }
2371
2386
  export function __wbindgen_cast_0000000000000003(arg0) {
@@ -2385,14 +2400,14 @@ export function __wbindgen_object_clone_ref(arg0) {
2385
2400
  export function __wbindgen_object_drop_ref(arg0) {
2386
2401
  takeObject(arg0);
2387
2402
  }
2388
- function __wasm_bindgen_func_elem_4593(arg0, arg1) {
2389
- wasm.__wasm_bindgen_func_elem_4593(arg0, arg1);
2403
+ function __wasm_bindgen_func_elem_4744(arg0, arg1) {
2404
+ wasm.__wasm_bindgen_func_elem_4744(arg0, arg1);
2390
2405
  }
2391
2406
 
2392
- function __wasm_bindgen_func_elem_19791(arg0, arg1, arg2) {
2407
+ function __wasm_bindgen_func_elem_24933(arg0, arg1, arg2) {
2393
2408
  try {
2394
2409
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2395
- wasm.__wasm_bindgen_func_elem_19791(retptr, arg0, arg1, addHeapObject(arg2));
2410
+ wasm.__wasm_bindgen_func_elem_24933(retptr, arg0, arg1, addHeapObject(arg2));
2396
2411
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2397
2412
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2398
2413
  if (r1) {
@@ -2403,8 +2418,8 @@ function __wasm_bindgen_func_elem_19791(arg0, arg1, arg2) {
2403
2418
  }
2404
2419
  }
2405
2420
 
2406
- function __wasm_bindgen_func_elem_19793(arg0, arg1, arg2, arg3) {
2407
- wasm.__wasm_bindgen_func_elem_19793(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
2421
+ function __wasm_bindgen_func_elem_24935(arg0, arg1, arg2, arg3) {
2422
+ wasm.__wasm_bindgen_func_elem_24935(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
2408
2423
  }
2409
2424
 
2410
2425
  const BrowserVoiceFinalization = (typeof FinalizationRegistry === 'undefined')
Binary file
@@ -95,9 +95,9 @@ export const turn_withdrawSteer: (a: number, b: number, c: number) => number;
95
95
  export const turnresult_finalMessage: (a: number, b: number) => void;
96
96
  export const turnresult_snapshot: (a: number, b: number) => void;
97
97
  export const turnresult_usage: (a: number, b: number) => void;
98
- export const __wasm_bindgen_func_elem_19791: (a: number, b: number, c: number, d: number) => void;
99
- export const __wasm_bindgen_func_elem_19793: (a: number, b: number, c: number, d: number) => void;
100
- export const __wasm_bindgen_func_elem_4593: (a: number, b: number) => void;
98
+ export const __wasm_bindgen_func_elem_24933: (a: number, b: number, c: number, d: number) => void;
99
+ export const __wasm_bindgen_func_elem_24935: (a: number, b: number, c: number, d: number) => void;
100
+ export const __wasm_bindgen_func_elem_4744: (a: number, b: number) => void;
101
101
  export const __wbindgen_export: (a: number, b: number) => number;
102
102
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
103
103
  export const __wbindgen_export3: (a: number) => void;
@@ -1,3 +1,4 @@
1
+ import { stringify, storeSnapshot, normalizeImage, normalizeAudio, generatedImageItems } from "nanocodex-tools/runtime/code-values";
1
2
  import { installBrowserEgressFetch } from "../tools/browser/browserEgress.mjs";
2
3
 
3
4
  const WORKER_PROTOCOL = "nanocodex.code-evaluator.v1";
@@ -40,23 +41,36 @@ async function evaluate({ source, storedEntries = [], toolDefinitions = [], tool
40
41
  });
41
42
  Object.freeze(tools);
42
43
 
43
- const text = (value) => post("output", { kind: "text", value });
44
- const image = (value, detail) => post("output", {
45
- kind: "image",
46
- value,
47
- detail,
48
- });
49
- const audio = (value) => post("output", { kind: "audio", value });
50
- const notify = (value) => post("output", { kind: "notify", value });
44
+ const text = (value) => post("output", { kind: "text", value: stringify(value) });
45
+ const image = (value, detail) => {
46
+ const item = normalizeImage(value, detail);
47
+ post("output", { kind: "image", value: item, detail: item.detail });
48
+ };
49
+ const audio = (value) => {
50
+ const item = normalizeAudio(value);
51
+ if (item.type === "input_text") text(item.text);
52
+ else post("output", { kind: "audio", value: item });
53
+ };
54
+ const notify = (value) => {
55
+ const text = stringify(value);
56
+ if (!text.trim()) throw new TypeError("notify expects non-empty text");
57
+ post("output", { kind: "notify", value: text });
58
+ };
51
59
  const yield_control = () => post("output", { kind: "yield_control" });
52
- const generatedImage = (value) => post("output", { kind: "generatedImage", value });
60
+ const generatedImage = (value) => {
61
+ for (const item of generatedImageItems(value)) {
62
+ if (item.type === "input_text") text(item.text);
63
+ else image(item);
64
+ }
65
+ };
53
66
  const store = (key, value) => {
54
- if (typeof key !== "string") throw new TypeError("store key must be a string");
55
- const snapshot = structuredClone(value);
67
+ const entry = storeSnapshot(key, value);
68
+ key = entry[0];
69
+ const snapshot = entry[1];
56
70
  stored.set(key, snapshot);
57
71
  storedWrites.set(key, snapshot);
58
72
  };
59
- const load = (key) => stored.has(key) ? structuredClone(stored.get(key)) : undefined;
73
+ const load = (key) => { key = `${key}`; return stored.has(key) ? JSON.parse(JSON.stringify(stored.get(key))) : undefined; };
60
74
  const EXIT = Symbol("exit");
61
75
  const exit = () => { throw EXIT; };
62
76
  const guestConsole = Object.freeze(Object.fromEntries(
@@ -100,10 +114,8 @@ async function evaluate({ source, storedEntries = [], toolDefinitions = [], tool
100
114
  guestConsole,
101
115
  );
102
116
  } finally {
103
- // Discarding a tool Promise or calling exit() must not orphan parent-held
104
- // work. The evaluator remains alive until each invocation receives its
105
- // terminal response, or its supervisor terminates this cell on cancel.
106
- await Promise.allSettled(toolInvocations);
117
+ // The supervisor disposes the worker and cancels pending nested calls
118
+ // when the root script completes.
107
119
  }
108
120
  return [...storedWrites];
109
121
  } catch (error) {
@@ -126,12 +138,6 @@ function post(type, value = {}) {
126
138
  globalThis.postMessage({ protocol: WORKER_PROTOCOL, evaluationId, type, ...value });
127
139
  }
128
140
 
129
- function stringify(value) {
130
- if (typeof value === "string") return value;
131
- if (value === undefined) return "undefined";
132
- try { return JSON.stringify(value); } catch { return String(value); }
133
- }
134
-
135
141
  function errorMessage(error) {
136
142
  return error && (error.stack || error.message) ? error.stack || error.message : String(error);
137
143
  }
@@ -50,6 +50,7 @@ export async function createManagedAgent(options) {
50
50
  const managed = setup.identity.kind === "create"
51
51
  ? await ManagedAgent.create(setup.client)
52
52
  : ManagedAgent.open(setup.identity.id, setup.client);
53
+ void managed.prepare().catch(() => {});
53
54
  const managedState = await managed.state();
54
55
  if (managedState.agent_id !== managed.id
55
56
  || typeof managedState.session_id !== "string"
@@ -1,3 +1,4 @@
1
+ import { guestValueHelpers } from "nanocodex-tools/runtime/code-values";
1
2
  const DEFAULT_MEMORY_LIMIT_BYTES = 64 * 1024 * 1024;
2
3
  const DEFAULT_STACK_LIMIT_BYTES = 512 * 1024;
3
4
  const DEFAULT_INTERRUPT_CYCLES = 1_000_000;
@@ -32,12 +33,14 @@ async function evaluate(quickJs, source, environment, options) {
32
33
  environment.signal?.addEventListener("abort", onAbort, { once: true });
33
34
  runtime.setInterruptHandler(() => aborted || ++interruptCycles > maxInterruptCycles);
34
35
  let closed = false;
36
+ const pending = new Set();
35
37
 
36
38
  try {
37
39
  expose(vm, "__nanocodex_call_tool", (nameHandle, inputHandle) => {
38
40
  const name = vm.getString(nameHandle);
39
41
  const input = vm.getString(inputHandle);
40
42
  const deferred = vm.newPromise();
43
+ pending.add(deferred);
41
44
  invokeTool(environment, name, input).then((encoded) => {
42
45
  if (closed) return;
43
46
  vm.newString(encoded).consume(deferred.resolve);
@@ -58,6 +61,7 @@ async function evaluate(quickJs, source, environment, options) {
58
61
  });
59
62
  expose(vm, "__nanocodex_sleep", (delayHandle) => {
60
63
  const deferred = vm.newPromise();
64
+ pending.add(deferred);
61
65
  environment.setTimeout(() => {
62
66
  if (closed) return;
63
67
  deferred.resolve();
@@ -101,6 +105,7 @@ async function evaluate(quickJs, source, environment, options) {
101
105
  } finally {
102
106
  closed = true;
103
107
  environment.signal?.removeEventListener("abort", onAbort);
108
+ for (const deferred of pending) deferred.dispose();
104
109
  vm.dispose();
105
110
  }
106
111
  }
@@ -162,14 +167,23 @@ function formatQuickJsError(error) {
162
167
  function guestSource(source, toolNames, toolDefinitions) {
163
168
  return `
164
169
  const __nanocodex_exit = Symbol("exit");
165
- const __nanocodex_stringify = (value) => {
166
- if (typeof value === "string") return value;
167
- if (value === undefined) return "undefined";
168
- try { return JSON.stringify(value); } catch { return String(value); }
169
- };
170
+ ${guestValueHelpers()}
171
+ const __nanocodex_stringify = stringify;
170
172
  const __nanocodex_decode = (encoded) => {
171
173
  const result = JSON.parse(encoded);
172
- if (!result.ok) throw new Error(result.error);
174
+ if (!result.ok) {
175
+ const failure = result.error;
176
+ const structured = failure !== null && typeof failure === "object";
177
+ const error = new Error(structured && typeof failure.message === "string"
178
+ ? failure.message
179
+ : __nanocodex_stringify(failure));
180
+ if (structured) {
181
+ if (typeof failure.stack === "string") error.stack = failure.stack;
182
+ if (Object.hasOwn(failure, "code")) error.code = failure.code;
183
+ if (Object.hasOwn(failure, "details")) error.details = failure.details;
184
+ }
185
+ throw error;
186
+ }
173
187
  return result.value;
174
188
  };
175
189
  const tools = Object.freeze(Object.fromEntries(
@@ -178,9 +192,15 @@ const tools = Object.freeze(Object.fromEntries(
178
192
  ));
179
193
  const ALL_TOOLS = Object.freeze(${JSON.stringify(toolDefinitions)});
180
194
  const text = (value) => __nanocodex_emit("text", JSON.stringify(__nanocodex_stringify(value)));
181
- const image = (value, detail) =>
182
- __nanocodex_emit("image", JSON.stringify({ value, detail }));
183
- const audio = (value) => __nanocodex_emit("audio", JSON.stringify(value));
195
+ const image = (value, detail) => {
196
+ const item = normalizeImage(value, detail);
197
+ __nanocodex_emit("image", JSON.stringify({ value: item, detail: item.detail }));
198
+ };
199
+ const audio = (value) => {
200
+ const item = normalizeAudio(value);
201
+ if (item.type === "input_text") text(item.text);
202
+ else __nanocodex_emit("audio", JSON.stringify(item));
203
+ };
184
204
  const notify = (value) => __nanocodex_emit("notify", JSON.stringify(__nanocodex_stringify(value)));
185
205
  const yield_control = () => __nanocodex_emit("yield_control", "null");
186
206
  const __nanocodex_timers = new Map();
@@ -196,13 +216,20 @@ const setTimeout = (callback, delay = 0) => {
196
216
  return id;
197
217
  };
198
218
  const clearTimeout = (id) => __nanocodex_timers.delete(id);
199
- const generatedImage = (value) =>
200
- __nanocodex_emit("generatedImage", JSON.stringify(value));
219
+ const generatedImage = (value) => {
220
+ for (const item of generatedImageItems(value)) {
221
+ if (item.type === "input_text") text(item.text);
222
+ else image(item);
223
+ }
224
+ };
201
225
  const store = (key, value) => {
202
- if (typeof key !== "string") throw new TypeError("store key must be a string");
203
- __nanocodex_store(key, JSON.stringify({ value }));
226
+ const entry = storeSnapshot(key, value);
227
+ __nanocodex_store(entry[0], JSON.stringify({ value: entry[1] }));
228
+ };
229
+ const load = (key) => {
230
+ if (typeof key === "symbol") throw new TypeError("load key must be a string");
231
+ return JSON.parse(__nanocodex_load(String(key))).value;
204
232
  };
205
- const load = (key) => JSON.parse(__nanocodex_load(key)).value;
206
233
  const exit = () => { throw __nanocodex_exit; };
207
234
  const require = undefined;
208
235
  const console = Object.freeze(Object.fromEntries(
@@ -219,8 +246,15 @@ ${source}
219
246
  `;
220
247
  }
221
248
 
222
- function errorMessage(error) {
223
- if (error && (error.stack || error.message)) return error.stack || error.message;
249
+ function serializeToolError(error) {
250
+ if (error && typeof error === "object") {
251
+ return {
252
+ message: typeof error.message === "string" ? error.message : formatQuickJsError(error),
253
+ ...(typeof error.stack === "string" ? { stack: error.stack } : {}),
254
+ ...(Object.hasOwn(error, "code") ? { code: error.code } : {}),
255
+ ...(Object.hasOwn(error, "details") ? { details: error.details } : {}),
256
+ };
257
+ }
224
258
  return String(error);
225
259
  }
226
260
 
@@ -231,6 +265,14 @@ async function invokeTool(environment, name, encodedInput) {
231
265
  const value = await tool(JSON.parse(encodedInput));
232
266
  return JSON.stringify({ ok: true, value });
233
267
  } catch (error) {
234
- return JSON.stringify({ ok: false, error: errorMessage(error) });
268
+ const ancestors = [];
269
+ return JSON.stringify({ ok: false, error: serializeToolError(error) }, function (_key, value) {
270
+ if (typeof value === "bigint") return String(value);
271
+ if (value === null || typeof value !== "object") return value;
272
+ while (ancestors.length && ancestors.at(-1) !== this) ancestors.pop();
273
+ if (ancestors.includes(value)) return "[Circular]";
274
+ ancestors.push(value);
275
+ return value;
276
+ });
235
277
  }
236
278
  }
@@ -1,35 +1,13 @@
1
1
  /** Apply stable managed response policy at the provider wire boundary, including replay. */
2
2
  export function responseControlsSocket(socket, controls = {}) {
3
- if (controls.promptCacheKey !== undefined && (typeof controls.promptCacheKey !== "string" || controls.promptCacheKey.length === 0 || controls.promptCacheKey.length > 64)) {
4
- throw new TypeError("invalid prompt cache key");
5
- }
6
- if (controls.promptCache !== undefined && !["implicit", "explicit"].includes(controls.promptCache)) {
7
- throw new TypeError("invalid prompt cache mode");
8
- }
9
- if (controls.outputSchema !== undefined && (!controls.outputSchema || typeof controls.outputSchema !== "object" || Array.isArray(controls.outputSchema))) {
10
- throw new TypeError("output schema must be an object");
11
- }
3
+ validateResponseControls(controls);
12
4
  return new Proxy({}, {
13
5
  get(_target, property) {
14
6
  const target = socket;
15
7
  if (property === "send") return (data, ...args) => {
16
8
  const body = typeof data === "string" ? JSON.parse(data) : undefined;
17
9
  if (body?.type === "response.create") {
18
- if (controls.promptCacheKey !== undefined) body.prompt_cache_key = controls.promptCacheKey;
19
- if (controls.outputSchema !== undefined) body.text = {
20
- ...body.text, format: { type: "json_schema", name: "managed_output", strict: true, schema: controls.outputSchema },
21
- };
22
- if (controls.promptCache !== undefined) {
23
- body.prompt_cache_options = { mode: controls.promptCache, ttl: "30m" };
24
- if (controls.promptCache === "explicit") {
25
- // Cache the developer context without marking changing user input.
26
- // Continuations with no prefix intentionally do not write new cache entries.
27
- const developers = (Array.isArray(body.input) ? body.input : []).filter(item => item.role === "developer");
28
- const text = developers.flatMap(item => Array.isArray(item.content) ? item.content : [])
29
- .filter(part => part.type === "input_text").at(-1);
30
- if (text) text.prompt_cache_breakpoint = { mode: "explicit" };
31
- }
32
- }
10
+ applyResponseControls(body, controls);
33
11
  return target.send(JSON.stringify(body), ...args);
34
12
  }
35
13
  return target.send(data, ...args);
@@ -40,3 +18,42 @@ export function responseControlsSocket(socket, controls = {}) {
40
18
  set(_target, property, value) { return Reflect.set(socket, property, value, socket); },
41
19
  });
42
20
  }
21
+
22
+ /** Apply the same policy to an HTTPS Responses body before provider dispatch. */
23
+ export function responseControlsBody(encoded, controls = {}) {
24
+ validateResponseControls(controls);
25
+ const body = JSON.parse(encoded);
26
+ if (!body || typeof body !== "object" || Array.isArray(body)) throw new TypeError("response body must be an object");
27
+ applyResponseControls(body, controls);
28
+ return JSON.stringify(body);
29
+ }
30
+
31
+ function validateResponseControls(controls) {
32
+ if (controls.promptCacheKey !== undefined && (typeof controls.promptCacheKey !== "string" || controls.promptCacheKey.length === 0 || controls.promptCacheKey.length > 64)) {
33
+ throw new TypeError("invalid prompt cache key");
34
+ }
35
+ if (controls.promptCache !== undefined && !["implicit", "explicit"].includes(controls.promptCache)) {
36
+ throw new TypeError("invalid prompt cache mode");
37
+ }
38
+ if (controls.outputSchema !== undefined && (!controls.outputSchema || typeof controls.outputSchema !== "object" || Array.isArray(controls.outputSchema))) {
39
+ throw new TypeError("output schema must be an object");
40
+ }
41
+ }
42
+
43
+ function applyResponseControls(body, controls) {
44
+ if (controls.promptCacheKey !== undefined) body.prompt_cache_key = controls.promptCacheKey;
45
+ if (controls.outputSchema !== undefined) body.text = {
46
+ ...body.text, format: { type: "json_schema", name: "managed_output", strict: true, schema: controls.outputSchema },
47
+ };
48
+ if (controls.promptCache !== undefined) {
49
+ body.prompt_cache_options = { mode: controls.promptCache, ttl: "30m" };
50
+ if (controls.promptCache === "explicit") {
51
+ // Cache the developer context without marking changing user input.
52
+ // Continuations with no prefix intentionally do not write new cache entries.
53
+ const developers = (Array.isArray(body.input) ? body.input : []).filter(item => item.role === "developer");
54
+ const text = developers.flatMap(item => Array.isArray(item.content) ? item.content : [])
55
+ .filter(part => part.type === "input_text").at(-1);
56
+ if (text) text.prompt_cache_breakpoint = { mode: "explicit" };
57
+ }
58
+ }
59
+ }