@lamplitisles/dsh-nanocodex 0.1.0-beta.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.
Files changed (276) hide show
  1. package/LICENSE +65 -0
  2. package/NOTICE +2 -0
  3. package/README.md +182 -0
  4. package/THIRD_PARTY_NOTICES.md +29 -0
  5. package/cordis.patch.yml +52 -0
  6. package/dist/index.d.ts +435 -0
  7. package/dist/index.js +3405 -0
  8. package/dist/standard-preset.d.ts +7 -0
  9. package/dist/standard-preset.js +25 -0
  10. package/engine-release.json +14 -0
  11. package/package.json +119 -0
  12. package/presets/standard/agent.cordis.yml +6 -0
  13. package/presets/standard/preset.yml +2 -0
  14. package/vendor/nanocodex/README.md +1344 -0
  15. package/vendor/nanocodex/actions/events.d.mts +10 -0
  16. package/vendor/nanocodex/actions/events.mjs +163 -0
  17. package/vendor/nanocodex/actions/index.d.mts +13 -0
  18. package/vendor/nanocodex/actions/index.mjs +35 -0
  19. package/vendor/nanocodex/actions/session.d.mts +66 -0
  20. package/vendor/nanocodex/actions/session.mjs +59 -0
  21. package/vendor/nanocodex/actions/turn.d.mts +59 -0
  22. package/vendor/nanocodex/actions/turn.mjs +37 -0
  23. package/vendor/nanocodex/actions/voice.d.mts +22 -0
  24. package/vendor/nanocodex/actions/voice.mjs +50 -0
  25. package/vendor/nanocodex/browser/Agent.d.mts +55 -0
  26. package/vendor/nanocodex/browser/Agent.mjs +11 -0
  27. package/vendor/nanocodex/browser/ChatGptSubscription.d.mts +7 -0
  28. package/vendor/nanocodex/browser/ChatGptSubscription.mjs +19 -0
  29. package/vendor/nanocodex/browser/InlineAgent.mjs +266 -0
  30. package/vendor/nanocodex/browser/Transport.d.mts +74 -0
  31. package/vendor/nanocodex/browser/Transport.mjs +61 -0
  32. package/vendor/nanocodex/browser/Voice.d.mts +71 -0
  33. package/vendor/nanocodex/browser/Voice.mjs +291 -0
  34. package/vendor/nanocodex/browser/VoiceSession.mjs +688 -0
  35. package/vendor/nanocodex/browser/WorkerAgent.d.mts +65 -0
  36. package/vendor/nanocodex/browser/WorkerAgent.mjs +1472 -0
  37. package/vendor/nanocodex/browser/agent.worker.mjs +3 -0
  38. package/vendor/nanocodex/browser/config.d.mts +36 -0
  39. package/vendor/nanocodex/browser/config.mjs +439 -0
  40. package/vendor/nanocodex/browser/engine.mjs +13 -0
  41. package/vendor/nanocodex/browser/harness.mjs +55 -0
  42. package/vendor/nanocodex/browser/host.d.mts +83 -0
  43. package/vendor/nanocodex/browser/host.mjs +555 -0
  44. package/vendor/nanocodex/browser/hostManagedWebSocket.d.mts +14 -0
  45. package/vendor/nanocodex/browser/hostManagedWebSocket.mjs +110 -0
  46. package/vendor/nanocodex/browser/index.d.mts +92 -0
  47. package/vendor/nanocodex/browser/index.mjs +23 -0
  48. package/vendor/nanocodex/browser/indexeddb-durability-store.mjs +197 -0
  49. package/vendor/nanocodex/browser/workspace.d.mts +16 -0
  50. package/vendor/nanocodex/browser/workspace.mjs +107 -0
  51. package/vendor/nanocodex/cloud/Client.d.mts +83 -0
  52. package/vendor/nanocodex/cloud/Client.mjs +231 -0
  53. package/vendor/nanocodex/cloud/Decorator.d.mts +31 -0
  54. package/vendor/nanocodex/cloud/Decorator.mjs +37 -0
  55. package/vendor/nanocodex/cloud/Dialog.d.mts +113 -0
  56. package/vendor/nanocodex/cloud/Dialog.mjs +366 -0
  57. package/vendor/nanocodex/cloud/Errors.d.mts +22 -0
  58. package/vendor/nanocodex/cloud/Errors.mjs +39 -0
  59. package/vendor/nanocodex/cloud/Principal.d.mts +26 -0
  60. package/vendor/nanocodex/cloud/Principal.mjs +88 -0
  61. package/vendor/nanocodex/cloud/RemoteProvider.mjs +88 -0
  62. package/vendor/nanocodex/cloud/Transport.d.mts +47 -0
  63. package/vendor/nanocodex/cloud/Transport.mjs +454 -0
  64. package/vendor/nanocodex/cloud/actions/account.d.mts +9 -0
  65. package/vendor/nanocodex/cloud/actions/account.mjs +19 -0
  66. package/vendor/nanocodex/cloud/actions/agent.d.mts +18 -0
  67. package/vendor/nanocodex/cloud/actions/agent.mjs +428 -0
  68. package/vendor/nanocodex/cloud/actions/connection.d.mts +133 -0
  69. package/vendor/nanocodex/cloud/actions/connection.mjs +580 -0
  70. package/vendor/nanocodex/cloud/actions/grant.d.mts +10 -0
  71. package/vendor/nanocodex/cloud/actions/grant.mjs +12 -0
  72. package/vendor/nanocodex/cloud/actions/index.d.mts +7 -0
  73. package/vendor/nanocodex/cloud/actions/index.mjs +7 -0
  74. package/vendor/nanocodex/cloud/actions/machineUsd.d.mts +23 -0
  75. package/vendor/nanocodex/cloud/actions/machineUsd.mjs +37 -0
  76. package/vendor/nanocodex/cloud/actions/model.d.mts +12 -0
  77. package/vendor/nanocodex/cloud/actions/model.mjs +50 -0
  78. package/vendor/nanocodex/cloud/actions/mpp.d.mts +28 -0
  79. package/vendor/nanocodex/cloud/actions/mpp.mjs +39 -0
  80. package/vendor/nanocodex/cloud/index.d.mts +30 -0
  81. package/vendor/nanocodex/cloud/index.mjs +9 -0
  82. package/vendor/nanocodex/cloud/internal.mjs +533 -0
  83. package/vendor/nanocodex/cloud/mercator.mjs +108 -0
  84. package/vendor/nanocodex/cloud/server/HostPrincipal.d.mts +34 -0
  85. package/vendor/nanocodex/cloud/server/HostPrincipal.mjs +202 -0
  86. package/vendor/nanocodex/cloud/server/index.d.mts +1 -0
  87. package/vendor/nanocodex/cloud/server/index.mjs +1 -0
  88. package/vendor/nanocodex/cloud/types.d.mts +211 -0
  89. package/vendor/nanocodex/cloudflare/Agent.d.mts +133 -0
  90. package/vendor/nanocodex/cloudflare/Agent.mjs +811 -0
  91. package/vendor/nanocodex/cloudflare/egress-subject.mjs +19 -0
  92. package/vendor/nanocodex/cloudflare/egress.d.mts +41 -0
  93. package/vendor/nanocodex/cloudflare/egress.mjs +119 -0
  94. package/vendor/nanocodex/cloudflare/event-socket.mjs +316 -0
  95. package/vendor/nanocodex/cloudflare/index.d.mts +7 -0
  96. package/vendor/nanocodex/cloudflare/index.mjs +6 -0
  97. package/vendor/nanocodex/host/Agent.d.mts +55 -0
  98. package/vendor/nanocodex/host/Agent.mjs +1 -0
  99. package/vendor/nanocodex/host/index.d.mts +82 -0
  100. package/vendor/nanocodex/host/index.mjs +10 -0
  101. package/vendor/nanocodex/index.d.mts +81 -0
  102. package/vendor/nanocodex/index.mjs +12 -0
  103. package/vendor/nanocodex/internal.mjs +1275 -0
  104. package/vendor/nanocodex/managed/Agent.d.mts +380 -0
  105. package/vendor/nanocodex/managed/Agent.mjs +1694 -0
  106. package/vendor/nanocodex/managed/ManagedError.d.mts +9 -0
  107. package/vendor/nanocodex/managed/ManagedError.mjs +8 -0
  108. package/vendor/nanocodex/managed/README.md +241 -0
  109. package/vendor/nanocodex/managed/Voice.mjs +202 -0
  110. package/vendor/nanocodex/managed/index.d.mts +20 -0
  111. package/vendor/nanocodex/managed/index.mjs +2 -0
  112. package/vendor/nanocodex/managed/internal.mjs +119 -0
  113. package/vendor/nanocodex/node/Agent.d.mts +50 -0
  114. package/vendor/nanocodex/node/Agent.mjs +203 -0
  115. package/vendor/nanocodex/node/ChatGptSubscription.d.mts +9 -0
  116. package/vendor/nanocodex/node/ChatGptSubscription.mjs +17 -0
  117. package/vendor/nanocodex/node/Transport.d.mts +44 -0
  118. package/vendor/nanocodex/node/Transport.mjs +46 -0
  119. package/vendor/nanocodex/node/host.mjs +731 -0
  120. package/vendor/nanocodex/node/index.d.mts +73 -0
  121. package/vendor/nanocodex/node/index.mjs +17 -0
  122. package/vendor/nanocodex/node/workspace.d.mts +10 -0
  123. package/vendor/nanocodex/node/workspace.mjs +198 -0
  124. package/vendor/nanocodex/package.json +200 -0
  125. package/vendor/nanocodex/pkg-node/nanocodex.d.ts +675 -0
  126. package/vendor/nanocodex/pkg-node/nanocodex.js +2628 -0
  127. package/vendor/nanocodex/pkg-node/nanocodex_bg.wasm.d.ts +105 -0
  128. package/vendor/nanocodex/pkg-node/package.json +1 -0
  129. package/vendor/nanocodex/pkg-web/.nanocodex-bindgen-stamp +6 -0
  130. package/vendor/nanocodex/pkg-web/nanocodex-build.json +1 -0
  131. package/vendor/nanocodex/pkg-web/nanocodex.d.ts +805 -0
  132. package/vendor/nanocodex/pkg-web/nanocodex.js +2714 -0
  133. package/vendor/nanocodex/pkg-web/nanocodex_bg.js +2615 -0
  134. package/vendor/nanocodex/pkg-web/nanocodex_bg.wasm +0 -0
  135. package/vendor/nanocodex/pkg-web/nanocodex_bg.wasm.d.ts +105 -0
  136. package/vendor/nanocodex/pkg-web/nanocodex_worker.js +9 -0
  137. package/vendor/nanocodex/pkg-web/package.json +1 -0
  138. package/vendor/nanocodex/runtime/chatgpt-subscription.mjs +212 -0
  139. package/vendor/nanocodex/runtime/cloudflare-durability-store.d.mts +26 -0
  140. package/vendor/nanocodex/runtime/cloudflare-durability-store.mjs +168 -0
  141. package/vendor/nanocodex/runtime/code-evaluator.worker.mjs +137 -0
  142. package/vendor/nanocodex/runtime/code-runtime.mjs +1 -0
  143. package/vendor/nanocodex/runtime/durability-store.d.mts +85 -0
  144. package/vendor/nanocodex/runtime/durability-store.mjs +631 -0
  145. package/vendor/nanocodex/runtime/durability.mjs +153 -0
  146. package/vendor/nanocodex/runtime/managed-transport.mjs +460 -0
  147. package/vendor/nanocodex/runtime/mcp-runtime.mjs +534 -0
  148. package/vendor/nanocodex/runtime/postgres-durability-store.d.mts +64 -0
  149. package/vendor/nanocodex/runtime/postgres-durability-store.mjs +532 -0
  150. package/vendor/nanocodex/runtime/quickjs-evaluator.d.mts +17 -0
  151. package/vendor/nanocodex/runtime/quickjs-evaluator.mjs +236 -0
  152. package/vendor/nanocodex/runtime/responses-transport.mjs +22 -0
  153. package/vendor/nanocodex/runtime/subagents.d.mts +107 -0
  154. package/vendor/nanocodex/runtime/subagents.mjs +54 -0
  155. package/vendor/nanocodex/runtime/subscription-store.d.mts +8 -0
  156. package/vendor/nanocodex/runtime/subscription-store.mjs +42 -0
  157. package/vendor/nanocodex/runtime/tempo-provider.d.mts +125 -0
  158. package/vendor/nanocodex/runtime/tempo-provider.mjs +264 -0
  159. package/vendor/nanocodex/runtime/tool-configuration.mjs +1 -0
  160. package/vendor/nanocodex/runtime/tool-router.mjs +1 -0
  161. package/vendor/nanocodex/runtime/utf8.mjs +1 -0
  162. package/vendor/nanocodex/runtime/worker-evaluator.mjs +162 -0
  163. package/vendor/nanocodex/runtime/workspace.d.mts +1 -0
  164. package/vendor/nanocodex/runtime/workspace.mjs +1 -0
  165. package/vendor/nanocodex/tools/Tools.d.mts +56 -0
  166. package/vendor/nanocodex/tools/Tools.mjs +136 -0
  167. package/vendor/nanocodex/tools/artifact.d.mts +1 -0
  168. package/vendor/nanocodex/tools/artifact.mjs +1 -0
  169. package/vendor/nanocodex/tools/attachment.mjs +1 -0
  170. package/vendor/nanocodex/tools/bash.d.mts +1 -0
  171. package/vendor/nanocodex/tools/bash.mjs +1 -0
  172. package/vendor/nanocodex/tools/browser/accountInfo.mjs +795 -0
  173. package/vendor/nanocodex/tools/browser/browserBuffer.mjs +18 -0
  174. package/vendor/nanocodex/tools/browser/browserCompiler.mjs +155 -0
  175. package/vendor/nanocodex/tools/browser/browserEgress.mjs +161 -0
  176. package/vendor/nanocodex/tools/browser/browserPython.mjs +133 -0
  177. package/vendor/nanocodex/tools/browser/browserShell.mjs +1075 -0
  178. package/vendor/nanocodex/tools/browser/browserSprintf.mjs +4 -0
  179. package/vendor/nanocodex/tools/browser/browserSsh.mjs +201 -0
  180. package/vendor/nanocodex/tools/browser/browserZlib.mjs +136 -0
  181. package/vendor/nanocodex/tools/browser/compiler.worker.mjs +160 -0
  182. package/vendor/nanocodex/tools/browser/devTunnelsSshBrowser.mjs +13 -0
  183. package/vendor/nanocodex/tools/browser/index.d.mts +209 -0
  184. package/vendor/nanocodex/tools/browser/index.mjs +174 -0
  185. package/vendor/nanocodex/tools/browser/opfsGit.mjs +248 -0
  186. package/vendor/nanocodex/tools/browser/python.worker.mjs +114 -0
  187. package/vendor/nanocodex/tools/browser/threadGit.mjs +197 -0
  188. package/vendor/nanocodex/tools/browser/unsupportedNodeRsa.mjs +5 -0
  189. package/vendor/nanocodex/tools/browser/workspace.mjs +83 -0
  190. package/vendor/nanocodex/tools/dataset.d.mts +1 -0
  191. package/vendor/nanocodex/tools/dataset.mjs +1 -0
  192. package/vendor/nanocodex/tools/datasetContract.mjs +1 -0
  193. package/vendor/nanocodex/tools/datasetEngine.mjs +1 -0
  194. package/vendor/nanocodex/tools/hostedCatalog.d.mts +1 -0
  195. package/vendor/nanocodex/tools/hostedCatalog.mjs +1 -0
  196. package/vendor/nanocodex/tools/index.d.mts +49 -0
  197. package/vendor/nanocodex/tools/index.mjs +19 -0
  198. package/vendor/nanocodex/tools/namedTool.mjs +1 -0
  199. package/vendor/nanocodex/tools/repository-workspace.d.mts +1 -0
  200. package/vendor/nanocodex/tools/repository-workspace.mjs +1 -0
  201. package/vendor/nanocodex/tools/ssh.d.mts +1 -0
  202. package/vendor/nanocodex/tools/ssh.mjs +1 -0
  203. package/vendor/nanocodex/tools/standard.mjs +1 -0
  204. package/vendor/nanocodex/tools/standardDescriptions.mjs +1 -0
  205. package/vendor/nanocodex/types.d.mts +663 -0
  206. package/vendor/nanocodex/wasm.d.mts +4 -0
  207. package/vendor/nanocodex/worker/ChatGptSubscription.d.mts +9 -0
  208. package/vendor/nanocodex/worker/ChatGptSubscription.mjs +29 -0
  209. package/vendor/nanocodex/worker/index.d.mts +18 -0
  210. package/vendor/nanocodex/worker/index.mjs +5 -0
  211. package/vendor/nanocodex-tools/README.md +65 -0
  212. package/vendor/nanocodex-tools/dist/hosted/app-tool-catalog.d.ts +7 -0
  213. package/vendor/nanocodex-tools/dist/hosted/app-tool-catalog.js +14 -0
  214. package/vendor/nanocodex-tools/dist/hosted/broker-core.d.ts +172 -0
  215. package/vendor/nanocodex-tools/dist/hosted/broker-core.js +1278 -0
  216. package/vendor/nanocodex-tools/dist/hosted/index.d.ts +3 -0
  217. package/vendor/nanocodex-tools/dist/hosted/index.js +3 -0
  218. package/vendor/nanocodex-tools/dist/hosted/protocol.d.ts +120 -0
  219. package/vendor/nanocodex-tools/dist/hosted/protocol.js +415 -0
  220. package/vendor/nanocodex-tools/dist/index.d.ts +19 -0
  221. package/vendor/nanocodex-tools/dist/index.js +14 -0
  222. package/vendor/nanocodex-tools/dist/memory.d.ts +204 -0
  223. package/vendor/nanocodex-tools/dist/memory.js +411 -0
  224. package/vendor/nanocodex-tools/dist/namespace.d.ts +87 -0
  225. package/vendor/nanocodex-tools/dist/namespace.js +338 -0
  226. package/vendor/nanocodex-tools/dist/repository-archive.d.ts +4 -0
  227. package/vendor/nanocodex-tools/dist/repository-archive.js +104 -0
  228. package/vendor/nanocodex-tools/dist/runtime.d.ts +30 -0
  229. package/vendor/nanocodex-tools/dist/runtime.js +37 -0
  230. package/vendor/nanocodex-tools/dist/session.d.ts +167 -0
  231. package/vendor/nanocodex-tools/dist/session.js +286 -0
  232. package/vendor/nanocodex-tools/dist/shell.d.ts +51 -0
  233. package/vendor/nanocodex-tools/dist/shell.js +553 -0
  234. package/vendor/nanocodex-tools/dist/ssh.d.ts +29 -0
  235. package/vendor/nanocodex-tools/dist/ssh.js +66 -0
  236. package/vendor/nanocodex-tools/dist/workspace.d.ts +45 -0
  237. package/vendor/nanocodex-tools/dist/workspace.js +237 -0
  238. package/vendor/nanocodex-tools/package.json +122 -0
  239. package/vendor/nanocodex-tools/runtime/code-runtime.mjs +817 -0
  240. package/vendor/nanocodex-tools/runtime/tool-configuration.mjs +50 -0
  241. package/vendor/nanocodex-tools/runtime/tool-router.mjs +730 -0
  242. package/vendor/nanocodex-tools/runtime/utf8.d.mts +2 -0
  243. package/vendor/nanocodex-tools/runtime/utf8.mjs +25 -0
  244. package/vendor/nanocodex-tools/tools/artifact.d.mts +69 -0
  245. package/vendor/nanocodex-tools/tools/artifact.mjs +270 -0
  246. package/vendor/nanocodex-tools/tools/attachment.mjs +603 -0
  247. package/vendor/nanocodex-tools/tools/bash.d.mts +90 -0
  248. package/vendor/nanocodex-tools/tools/bash.mjs +742 -0
  249. package/vendor/nanocodex-tools/tools/dataset.d.mts +9 -0
  250. package/vendor/nanocodex-tools/tools/dataset.mjs +47 -0
  251. package/vendor/nanocodex-tools/tools/datasetContract.mjs +54 -0
  252. package/vendor/nanocodex-tools/tools/datasetEngine.mjs +1167 -0
  253. package/vendor/nanocodex-tools/tools/execution-contract.d.mts +5 -0
  254. package/vendor/nanocodex-tools/tools/execution-contract.mjs +63 -0
  255. package/vendor/nanocodex-tools/tools/hostedCatalog.d.mts +20 -0
  256. package/vendor/nanocodex-tools/tools/hostedCatalog.mjs +67 -0
  257. package/vendor/nanocodex-tools/tools/hostedMachine.d.mts +10 -0
  258. package/vendor/nanocodex-tools/tools/hostedMachine.mjs +56 -0
  259. package/vendor/nanocodex-tools/tools/just-bash-browser.d.mts +1 -0
  260. package/vendor/nanocodex-tools/tools/just-bash-browser.mjs +1 -0
  261. package/vendor/nanocodex-tools/tools/namedTool.d.mts +3 -0
  262. package/vendor/nanocodex-tools/tools/namedTool.mjs +3 -0
  263. package/vendor/nanocodex-tools/tools/nodeProcess.d.mts +10 -0
  264. package/vendor/nanocodex-tools/tools/nodeProcess.mjs +314 -0
  265. package/vendor/nanocodex-tools/tools/processOutput.mjs +56 -0
  266. package/vendor/nanocodex-tools/tools/repository-workspace.d.mts +55 -0
  267. package/vendor/nanocodex-tools/tools/repository-workspace.mjs +397 -0
  268. package/vendor/nanocodex-tools/tools/ssh.d.mts +56 -0
  269. package/vendor/nanocodex-tools/tools/ssh.mjs +503 -0
  270. package/vendor/nanocodex-tools/tools/standard.mjs +458 -0
  271. package/vendor/nanocodex-tools/tools/standardDescriptions.mjs +3 -0
  272. package/vendor/nanocodex-tools/tools/types.d.mts +83 -0
  273. package/vendor/nanocodex-tools/tools/workspace.d.mts +25 -0
  274. package/vendor/nanocodex-tools/tools/workspace.mjs +282 -0
  275. package/vendor/nanocodex-tools/tools/x.d.mts +30 -0
  276. package/vendor/nanocodex-tools/tools/x.mjs +91 -0
@@ -0,0 +1,266 @@
1
+ import { applyBrowserPatch, Nanocodex } from "../pkg-web/nanocodex.js";
2
+
3
+ import { agentActions } from "../actions/index.mjs";
4
+ import {
5
+ activateHost,
6
+ activateCloudflareAgentSession,
7
+ bindHostSession,
8
+ CLOUDFLARE_SESSION_RESERVATION,
9
+ createAgentClient,
10
+ createEventChannel,
11
+ createSessionId,
12
+ defineRuntime,
13
+ loadDurabilityRuntime,
14
+ loadSubscriptionRuntime,
15
+ reportError,
16
+ registerDefinitionHost,
17
+ releaseDefinitionHost,
18
+ releaseHostSession,
19
+ toWasmConfig,
20
+ } from "../internal.mjs";
21
+ import { createBrowserHost } from "./host.mjs";
22
+ import { initializeBrowserEngine } from "./engine.mjs";
23
+ import { resolveResponsesTransport } from "../runtime/responses-transport.mjs";
24
+ import {
25
+ createManagedAgent,
26
+ managedTransportOptions,
27
+ } from "../runtime/managed-transport.mjs";
28
+ import { resolveTools } from "../runtime/tool-configuration.mjs";
29
+ import {
30
+ hostManaged as defaultHostManagedTransport,
31
+ } from "./Transport.mjs";
32
+
33
+ /** Creates the Rust/WASM Agent in the current Web API host isolate. */
34
+ export async function create(options = {}) {
35
+ if (managedTransportOptions(options?.transport)) return createManagedAgent(options);
36
+ const internalRuntime = options[Symbol.for("nanocodex.browser.internalRuntime")];
37
+ if (internalRuntime !== undefined
38
+ && (!internalRuntime || typeof internalRuntime !== "object" || Array.isArray(internalRuntime))) {
39
+ throw new TypeError("browser Agent internal runtime options must be an object");
40
+ }
41
+ const {
42
+ transport,
43
+ module,
44
+ model,
45
+ thinking,
46
+ reasoningMode,
47
+ fastMode,
48
+ instructions,
49
+ additionalInstructions,
50
+ companionCompactionInstruction,
51
+ resolveCompactionInstruction,
52
+ historySeed,
53
+ sessionId,
54
+ workspace,
55
+ resume,
56
+ durability,
57
+ durabilityId,
58
+ terminalReceiptRetention,
59
+ filesystem,
60
+ filesystemTools,
61
+ tools,
62
+ toolMode,
63
+ mcp,
64
+ executionEnvironment,
65
+ codeEvaluator,
66
+ } = options;
67
+ const toolProviders = internalRuntime?.toolProviders;
68
+ const subagentSessions = internalRuntime?.subagentSessions;
69
+ const cloudflareReservation = internalRuntime?.[CLOUDFLARE_SESSION_RESERVATION];
70
+ const stableSessionId = sessionId ?? createSessionId();
71
+ const {
72
+ apiKey,
73
+ hostAuth,
74
+ hostManagedProtocol,
75
+ subscription,
76
+ mpp,
77
+ websocketUrl,
78
+ websocketPreconnect,
79
+ apiBaseUrl,
80
+ websocketWarmup,
81
+ WebSocketImpl,
82
+ createWebSocket,
83
+ } = resolveResponsesTransport(transport ?? defaultHostManagedTransport());
84
+ const { tools: hostTools, subagents: configuredSubagents } = resolveTools(tools);
85
+ const subagentMaxConcurrency = internalRuntime?.subagentMaxConcurrency;
86
+ if (subagentMaxConcurrency !== undefined
87
+ && (!Number.isSafeInteger(subagentMaxConcurrency) || subagentMaxConcurrency < 1)) {
88
+ throw new TypeError("host subagentMaxConcurrency must be a positive safe integer");
89
+ }
90
+ // Hosted runtimes own the resource ceiling, including when their tools are
91
+ // a prepared router rather than a named-tool array. A caller's lower cap wins.
92
+ const subagentConfig = configuredSubagents === undefined || subagentMaxConcurrency === undefined
93
+ ? configuredSubagents
94
+ : {
95
+ ...configuredSubagents,
96
+ max_concurrency: Math.min(configuredSubagents.max_concurrency ?? subagentMaxConcurrency, subagentMaxConcurrency),
97
+ };
98
+ if (filesystem && workspace !== undefined && workspace !== filesystem.root) {
99
+ throw new TypeError("workspace must match filesystem.root when both are provided");
100
+ }
101
+ const events = createEventChannel();
102
+ const tempoMcp = mpp?.[Symbol.for("nanocodex.tempo.mcp")];
103
+ let hostDefinitionId;
104
+ const host = createBrowserHost({
105
+ WebSocketImpl,
106
+ createWebSocket,
107
+ hostAuth: hostAuth === true
108
+ || (apiKey === undefined && mpp === undefined && subscription === undefined),
109
+ hostManagedProtocol,
110
+ mpp,
111
+ onEvent: events.emit,
112
+ filesystem,
113
+ filesystemTools,
114
+ tools: hostTools,
115
+ toolProviders,
116
+ subagentSessions,
117
+ toolMode,
118
+ mcp: mcp === false
119
+ ? undefined
120
+ : tempoMcp ? { ...tempoMcp, ...mcp } : mcp,
121
+ codeEvaluator,
122
+ resolveCompactionInstruction,
123
+ applyPatch: applyBrowserPatch,
124
+ websocketPreconnect,
125
+ websocketUrl,
126
+ onDispose: () => releaseDefinitionHost(hostDefinitionId),
127
+ });
128
+ let durabilityOwner;
129
+ let creationStarted = false;
130
+ hostDefinitionId = registerDefinitionHost(host, cloudflareReservation);
131
+ activateHost(host);
132
+ const runtime = defineRuntime({
133
+ key: "browser-wasm",
134
+ name: "Nanocodex Browser WASM",
135
+ type: "browser",
136
+ async create(config) {
137
+ creationStarted = true;
138
+ let raw;
139
+ try {
140
+ if (durability !== undefined || durabilityId !== undefined) {
141
+ durabilityOwner = (await loadDurabilityRuntime()).own(
142
+ host,
143
+ durability,
144
+ durabilityId,
145
+ );
146
+ }
147
+ activateHost(host);
148
+ await host.ready();
149
+ await initializeBrowserEngine({ module });
150
+ activateHost(host);
151
+ const configJson = JSON.stringify(toWasmConfig({
152
+ apiKey: apiKey ?? (mpp === undefined
153
+ ? subscription === undefined ? "host-managed" : "subscription-managed"
154
+ : "mpp-managed"),
155
+ websocketUrl: websocketUrl ?? (mpp === undefined
156
+ ? undefined
157
+ : "wss://openai.mpp.tempo.xyz/v1/responses"),
158
+ apiBaseUrl,
159
+ websocketWarmup,
160
+ subagents: subagentConfig,
161
+ hostDefinitionId,
162
+ ...config,
163
+ durabilityHostId: durabilityOwner?.id,
164
+ }));
165
+ raw = subscription === undefined
166
+ ? await Nanocodex.create(configJson)
167
+ : await Nanocodex.createWithChatGpt(
168
+ configJson,
169
+ (await loadSubscriptionRuntime()).rawSubscription(subscription),
170
+ );
171
+ if (cloudflareReservation !== undefined) {
172
+ activateCloudflareAgentSession(cloudflareReservation);
173
+ const restoredSubagents = subagentSessions?.restore?.() ?? [];
174
+ if (restoredSubagents.length > 0) {
175
+ const restoredHostContextRefs = Object.fromEntries(
176
+ restoredSubagents.map((descriptor) => {
177
+ const hostContextRef = subagentSessions?.hostContextRef?.(descriptor.sessionId);
178
+ return [descriptor.sessionId, hostContextRef ?? null];
179
+ }),
180
+ );
181
+ await raw.restoreSubagents(
182
+ JSON.stringify(restoredSubagents),
183
+ JSON.stringify(restoredHostContextRefs),
184
+ );
185
+ }
186
+ }
187
+ return raw;
188
+ } catch (error) {
189
+ const cleanupErrors = [];
190
+ if (raw !== undefined) {
191
+ try { await raw.shutdown(); }
192
+ catch (cleanupError) { cleanupErrors.push(cleanupError); }
193
+ try { raw.free(); }
194
+ catch (cleanupError) { cleanupErrors.push(cleanupError); }
195
+ }
196
+ try { durabilityOwner?.abandon(); }
197
+ catch (cleanupError) { cleanupErrors.push(cleanupError); }
198
+ try { await host.dispose(); }
199
+ catch (cleanupError) { cleanupErrors.push(cleanupError); }
200
+ if (cleanupErrors.length > 0) {
201
+ throw new AggregateError(
202
+ [error, ...cleanupErrors],
203
+ "browser Agent creation and cleanup both failed",
204
+ );
205
+ }
206
+ throw error;
207
+ }
208
+ },
209
+ subscribe: events.subscribe,
210
+ adopt(raw) {
211
+ host.retain();
212
+ try {
213
+ durabilityOwner?.retain();
214
+ bindHostSession(host, raw.sessionId, cloudflareReservation);
215
+ events.addSource(raw);
216
+ } catch (error) {
217
+ events.removeSource(raw);
218
+ durabilityOwner?.release();
219
+ releaseHost(host);
220
+ throw error;
221
+ }
222
+ },
223
+ release(raw) {
224
+ events.removeSource(raw);
225
+ host.releaseSession(raw.sessionId);
226
+ releaseHostSession(host, raw.sessionId);
227
+ durabilityOwner?.release();
228
+ releaseHost(host);
229
+ },
230
+ decorate: (agent) => agent.extend(agentActions()),
231
+ });
232
+ let agent;
233
+ try {
234
+ agent = await createAgentClient(runtime, {
235
+ model,
236
+ thinking,
237
+ reasoningMode,
238
+ fastMode,
239
+ instructions,
240
+ additionalInstructions,
241
+ companionCompactionInstruction,
242
+ resolveCompactionInstruction,
243
+ historySeed,
244
+ sessionId: stableSessionId,
245
+ workspace: workspace ?? filesystem?.root,
246
+ executionEnvironment,
247
+ resume,
248
+ durabilityId,
249
+ terminalReceiptRetention,
250
+ }, cloudflareReservation);
251
+ } catch (error) {
252
+ if (!creationStarted) await host.dispose();
253
+ throw error;
254
+ }
255
+ if (websocketPreconnect && websocketUrl) {
256
+ // Preconnect is speculative. A normal turn reconnects through the owned
257
+ // transport path, while adapters that require startup validation (such as
258
+ // Cloudflare) observe the same attempt at their createWebSocket boundary.
259
+ void host.preconnect(websocketUrl, agent.sessionId).catch(() => {});
260
+ }
261
+ return agent;
262
+ }
263
+
264
+ function releaseHost(host) {
265
+ void host.release().catch(reportError);
266
+ }
@@ -0,0 +1,74 @@
1
+ import type {
2
+ ChatGptSubscriptionHandle,
3
+ MppSession,
4
+ } from "../types.mjs";
5
+ import type { Options as ManagedClientOptions } from "../managed/Agent.mjs";
6
+ import type {
7
+ BrowserWebSocketConnection,
8
+ BrowserWebSocketRequest,
9
+ } from "./host.mjs";
10
+
11
+ declare const responsesTransport: unique symbol;
12
+ declare const workerTransport: unique symbol;
13
+ declare const managedTransport: unique symbol;
14
+
15
+ export type ResponsesTransport = Readonly<{
16
+ [responsesTransport]: true;
17
+ }>;
18
+ export type ManagedTransport = Readonly<{ [managedTransport]: true }>;
19
+ export type Transport = ResponsesTransport | ManagedTransport;
20
+
21
+ /** A Responses transport whose complete descriptor can cross a module Worker boundary. */
22
+ export type WorkerTransport = ResponsesTransport & Readonly<{
23
+ [workerTransport]: true;
24
+ }>;
25
+
26
+ type SharedEndpointOptions = Readonly<{
27
+ apiBaseUrl?: string | undefined;
28
+ websocketUrl?: string | undefined;
29
+ /** Open the persistent socket as soon as Agent.create returns. Defaults to true for hostManaged. */
30
+ websocketPreconnect?: boolean | undefined;
31
+ websocketWarmup?: boolean | undefined;
32
+ }>;
33
+
34
+ type WorkerEndpointOptions = SharedEndpointOptions & Readonly<{
35
+ WebSocketImpl?: never;
36
+ createWebSocket?: never;
37
+ }>;
38
+
39
+ type EndpointOptions = SharedEndpointOptions & Readonly<{
40
+ WebSocketImpl?: typeof WebSocket | undefined;
41
+ createWebSocket?(
42
+ endpoint: string,
43
+ sessionId: string,
44
+ request: BrowserWebSocketRequest,
45
+ ): WebSocket | BrowserWebSocketConnection | Promise<WebSocket | BrowserWebSocketConnection>;
46
+ }>;
47
+
48
+ export function openAi(options: WorkerEndpointOptions & Readonly<{
49
+ apiKey: string;
50
+ }>): WorkerTransport;
51
+ export function openAi(options: EndpointOptions & Readonly<{
52
+ apiKey: string;
53
+ }>): ResponsesTransport;
54
+
55
+ export function chatGpt(options: EndpointOptions & Readonly<{
56
+ subscription: ChatGptSubscriptionHandle;
57
+ }>): ResponsesTransport;
58
+
59
+ /** Same-origin Nanocodex Responses proxy; defaults to `/api/responses`. */
60
+ export function hostManaged(options?: WorkerEndpointOptions): WorkerTransport;
61
+ export function hostManaged(options?: EndpointOptions): ResponsesTransport;
62
+
63
+ export function mpp(options: EndpointOptions & Readonly<{
64
+ session: MppSession;
65
+ }>): ResponsesTransport;
66
+
67
+ export type ManagedIdentity =
68
+ | Readonly<{ create: true; id?: never }>
69
+ | Readonly<{ id: string; create?: never }>;
70
+
71
+ /** Account-authenticated durable Agent transport with explicit create/open identity. */
72
+ export function managed(options: ManagedClientOptions & Readonly<{
73
+ agent: ManagedIdentity;
74
+ }>): ManagedTransport;
@@ -0,0 +1,61 @@
1
+ import {
2
+ createResponsesTransport,
3
+ nonEmpty,
4
+ } from "../runtime/responses-transport.mjs";
5
+ import { createManagedTransport } from "../runtime/managed-transport.mjs";
6
+ import { defaultHostManagedWebSocketUrl } from "./hostManagedWebSocket.mjs";
7
+
8
+ export function openAi(options) {
9
+ const apiKey = nonEmpty(options?.apiKey, "OpenAI API key");
10
+ return createResponsesTransport({
11
+ apiKey,
12
+ ...connection(options),
13
+ });
14
+ }
15
+
16
+ export function chatGpt(options) {
17
+ if (!options?.subscription || typeof options.subscription !== "object") {
18
+ throw new TypeError("ChatGPT transport requires a subscription handle");
19
+ }
20
+ return createResponsesTransport({
21
+ subscription: options.subscription,
22
+ ...connection(options),
23
+ });
24
+ }
25
+
26
+ export function hostManaged(options = {}) {
27
+ const websocketUrl = options.websocketUrl
28
+ ?? (options.createWebSocket ? undefined : defaultHostManagedWebSocketUrl());
29
+ return createResponsesTransport({
30
+ hostAuth: true,
31
+ hostManagedProtocol: true,
32
+ ...connection({ ...options, websocketUrl }),
33
+ websocketPreconnect: options.websocketPreconnect ?? true,
34
+ });
35
+ }
36
+
37
+ export function mpp(options) {
38
+ if (!options?.session || typeof options.session.ws !== "function") {
39
+ throw new TypeError("MPP transport requires a session with ws(endpoint)");
40
+ }
41
+ return createResponsesTransport({
42
+ mpp: options.session,
43
+ ...connection(options),
44
+ });
45
+ }
46
+
47
+ /** Account-authenticated durable Agent transport with explicit create/open identity. */
48
+ export function managed(options) {
49
+ return createManagedTransport(options);
50
+ }
51
+
52
+ function connection(options = {}) {
53
+ return {
54
+ WebSocketImpl: options.WebSocketImpl,
55
+ apiBaseUrl: options.apiBaseUrl,
56
+ createWebSocket: options.createWebSocket,
57
+ websocketUrl: options.websocketUrl,
58
+ websocketPreconnect: options.websocketPreconnect,
59
+ websocketWarmup: options.websocketWarmup,
60
+ };
61
+ }
@@ -0,0 +1,71 @@
1
+ import type { DefaultAgent } from "../types.mjs";
2
+ import type { Agent as ManagedAgent } from "../managed/Agent.mjs";
3
+ import type { ConnectAgent } from "../cloud/types.mjs";
4
+
5
+ export const voices: readonly ["juniper", "maple", "spruce", "ember", "vale", "breeze", "arbor", "sol", "cove"];
6
+ export const defaultVoice: "cove";
7
+ export type VoiceName = (typeof voices)[number];
8
+ export type VoiceErrorCode =
9
+ | "ice_gathering_timeout"
10
+ | "microphone_capture_cancelled"
11
+ | "microphone_capture_timeout"
12
+ | "microphone_not_found"
13
+ | "microphone_permission_blocked"
14
+ | "microphone_unavailable"
15
+ | "realtime_call_timeout"
16
+ | "sideband_open_timeout";
17
+ export declare class VoiceError extends Error {
18
+ readonly code: VoiceErrorCode;
19
+ constructor(code: VoiceErrorCode, message: string, options?: { cause?: unknown });
20
+ }
21
+ export type Transcript = Readonly<{
22
+ speaker: "user" | "assistant";
23
+ text: string;
24
+ id?: string;
25
+ isPartial?: boolean;
26
+ }>;
27
+ export type Snapshot = Readonly<{
28
+ error: Error | undefined;
29
+ status: "idle" | "connecting" | "active" | "error";
30
+ statusText: string | undefined;
31
+ transcripts: readonly Transcript[];
32
+ voice: VoiceName | undefined;
33
+ }>;
34
+ export type Event =
35
+ | Readonly<{ type: "connecting"; voice: VoiceName }>
36
+ | Readonly<{ type: "started"; voice: VoiceName }>
37
+ | Readonly<{ type: "transcript"; speaker: "user" | "assistant"; text: string; id?: string; isPartial?: false }>
38
+ | Readonly<{ type: "transcript.delta"; speaker: "user" | "assistant"; text: string; id: string; isPartial: true }>
39
+ | Readonly<{ type: "error"; error: Error }>
40
+ | Readonly<{ type: "stopped" }>;
41
+ export type Settings = Readonly<{
42
+ voice?: VoiceName | undefined;
43
+ /** Additional speaking preferences; base assistant instructions are retained. */
44
+ instructions?: string | undefined;
45
+ pace?: "slow" | "natural" | "fast" | undefined;
46
+ updates?: "auto" | "results" | "silent" | undefined;
47
+ handoffMode?: "thinking" | "commentary" | "bem_tags" | undefined;
48
+ acknowledgements?: boolean | undefined;
49
+ }>;
50
+ export type Options = Settings & Readonly<{
51
+ callUrl?: string | URL | undefined;
52
+ sidebandUrl?(callId: string, sessionId: string): string | URL | Promise<string | URL>;
53
+ captureMicrophone?(): Promise<MediaStream>;
54
+ beforeAgentTurn?(): Promise<void>;
55
+ }>;
56
+ export type Voice = Readonly<{
57
+ cancel(): Promise<boolean>;
58
+ /** Speak explicitly during an active call, independent of background update preferences. */
59
+ speak(text: string): Promise<void>;
60
+ /** Codex subscription voice treats every API role as context text. */
61
+ appendText(text: string, options?: { role?: "user" | "developer" | "assistant" }): Promise<void>;
62
+ appendContext(text: string): Promise<void>;
63
+ destroy(): Promise<void>;
64
+ getSnapshot(): Snapshot;
65
+ onEvent(listener: (event: Event) => void): () => void;
66
+ start(options?: Settings): Promise<void>;
67
+ stop(): Promise<void>;
68
+ subscribe(listener: () => void): () => void;
69
+ toggle(options?: Settings): Promise<void>;
70
+ }>;
71
+ export function create(agent: DefaultAgent | ManagedAgent | ConnectAgent, options?: Options): Voice;