@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,10 @@
1
+ import type { Agent, AgentEvent, EventWatcher, WatchEventsOptions } from "../types.mjs";
2
+
3
+ /** Creates a lazy, terminal watcher for an Agent's ordered event stream. */
4
+ export function watch(agent: Agent<object>, options?: watch.Options): watch.ReturnType;
5
+ export declare namespace watch {
6
+ type OnEventFn = (event: AgentEvent) => void;
7
+ type Options = WatchEventsOptions;
8
+ type ReturnType = EventWatcher;
9
+ type Watcher = EventWatcher;
10
+ }
@@ -0,0 +1,163 @@
1
+ import { reportError, subscribeAgentEvents } from "../internal.mjs";
2
+ import { utf8ByteLength } from "../runtime/utf8.mjs";
3
+
4
+ const MAX_BUFFERED_EVENTS = 4_096;
5
+ const MAX_BUFFERED_EVENT_BYTES = 32 * 1024 * 1024;
6
+
7
+ export function watch(agent, options = {}) {
8
+ const listeners = new Set();
9
+ const iterators = new Set();
10
+ let unsubscribe;
11
+ let closed = false;
12
+
13
+ const emit = (event, encodedLength, encodedEvent, agentId) => {
14
+ for (const listener of listeners) {
15
+ try {
16
+ listener(event, encodedLength, encodedEvent, agentId);
17
+ } catch (error) {
18
+ reportError(error);
19
+ }
20
+ }
21
+ for (const iterator of iterators) iterator.push(event, encodedLength);
22
+ };
23
+
24
+ const start = () => {
25
+ if (closed || unsubscribe) return;
26
+ unsubscribe = subscribeAgentEvents(agent, emit, options, () => watcher.off());
27
+ };
28
+
29
+ const stopIfIdle = () => {
30
+ if (listeners.size || iterators.size) return;
31
+ unsubscribe?.();
32
+ unsubscribe = undefined;
33
+ };
34
+
35
+ const watcher = {
36
+ onEvent(listener) {
37
+ if (typeof listener !== "function") throw new TypeError("events.watch.onEvent requires a listener");
38
+ if (closed) return () => {};
39
+ listeners.add(listener);
40
+ start();
41
+ return () => {
42
+ listeners.delete(listener);
43
+ stopIfIdle();
44
+ };
45
+ },
46
+ off() {
47
+ if (closed) return;
48
+ closed = true;
49
+ unsubscribe?.();
50
+ unsubscribe = undefined;
51
+ listeners.clear();
52
+ for (const iterator of [...iterators]) iterator.end();
53
+ iterators.clear();
54
+ },
55
+ [Symbol.asyncIterator]() {
56
+ if (closed) return emptyIterator();
57
+ const iterator = eventIterator(() => {
58
+ iterators.delete(iterator);
59
+ stopIfIdle();
60
+ });
61
+ iterators.add(iterator);
62
+ start();
63
+ return iterator;
64
+ },
65
+ };
66
+ return Object.freeze(watcher);
67
+ }
68
+
69
+ function eventIterator(onEnd) {
70
+ const queue = [];
71
+ let head = 0;
72
+ let bufferedBytes = 0;
73
+ const pending = [];
74
+ let pendingHead = 0;
75
+ let ended = false;
76
+ let failure;
77
+ let failureReported = false;
78
+ let detached = false;
79
+
80
+ const detach = () => {
81
+ if (detached) return;
82
+ detached = true;
83
+ onEnd();
84
+ };
85
+
86
+ const iterator = {
87
+ push(event, encodedLength) {
88
+ if (ended || failure) return;
89
+ if (pendingHead < pending.length) {
90
+ const resolve = pending[pendingHead++];
91
+ if (pendingHead === pending.length) {
92
+ pending.length = 0;
93
+ pendingHead = 0;
94
+ }
95
+ resolve({ done: false, value: event });
96
+ } else {
97
+ const bytes = encodedLength ?? utf8ByteLength(JSON.stringify(event));
98
+ if (
99
+ queue.length - head >= MAX_BUFFERED_EVENTS
100
+ || bufferedBytes + bytes > MAX_BUFFERED_EVENT_BYTES
101
+ ) {
102
+ failure = new RangeError(
103
+ `event iterator exceeded its private buffer of ${MAX_BUFFERED_EVENTS} events or `
104
+ + `${MAX_BUFFERED_EVENT_BYTES} encoded bytes`,
105
+ );
106
+ detach();
107
+ return;
108
+ }
109
+ queue.push({ bytes, event });
110
+ bufferedBytes += bytes;
111
+ }
112
+ },
113
+ end() {
114
+ if (ended) return;
115
+ ended = true;
116
+ detach();
117
+ while (pendingHead < pending.length) {
118
+ pending[pendingHead++]({ done: true, value: undefined });
119
+ }
120
+ pending.length = 0;
121
+ pendingHead = 0;
122
+ queue.length = 0;
123
+ head = 0;
124
+ bufferedBytes = 0;
125
+ },
126
+ next() {
127
+ if (head < queue.length) {
128
+ const entry = queue[head++];
129
+ bufferedBytes -= entry.bytes;
130
+ if (head === queue.length) {
131
+ queue.length = 0;
132
+ head = 0;
133
+ }
134
+ return Promise.resolve({ done: false, value: entry.event });
135
+ }
136
+ if (failure && !failureReported) {
137
+ failureReported = true;
138
+ return Promise.reject(failure);
139
+ }
140
+ if (ended || failure) return Promise.resolve({ done: true, value: undefined });
141
+ if (pending.length - pendingHead >= MAX_BUFFERED_EVENTS) {
142
+ return Promise.reject(new RangeError(
143
+ `event iterator exceeded its private buffer of ${MAX_BUFFERED_EVENTS} pending reads`,
144
+ ));
145
+ }
146
+ return new Promise((resolve) => { pending.push(resolve); });
147
+ },
148
+ return() {
149
+ iterator.end();
150
+ return Promise.resolve({ done: true, value: undefined });
151
+ },
152
+ [Symbol.asyncIterator]() { return this; },
153
+ };
154
+ return iterator;
155
+ }
156
+
157
+ function emptyIterator() {
158
+ return {
159
+ next: () => Promise.resolve({ done: true, value: undefined }),
160
+ return: () => Promise.resolve({ done: true, value: undefined }),
161
+ [Symbol.asyncIterator]() { return this; },
162
+ };
163
+ }
@@ -0,0 +1,13 @@
1
+ import type { Agent, AgentActions } from "../types.mjs";
2
+
3
+ export * as events from "./events.mjs";
4
+ export * as session from "./session.mjs";
5
+ export * as turn from "./turn.mjs";
6
+ export * as voice from "./voice.mjs";
7
+
8
+ /** Decorates a base Agent with the standard `turn`, `session`, and `events` domains. */
9
+ export function agentActions(): agentActions.DecoratorFn;
10
+ export declare namespace agentActions {
11
+ type Decorator = AgentActions;
12
+ type DecoratorFn = (agent: Agent<object>) => Decorator;
13
+ }
@@ -0,0 +1,35 @@
1
+ import * as events from "./events.mjs";
2
+ import * as session from "./session.mjs";
3
+ import * as turn from "./turn.mjs";
4
+ import * as voice from "./voice.mjs";
5
+
6
+ export { events, session, turn, voice };
7
+
8
+ export function agentActions() {
9
+ return (agent) => ({
10
+ events: {
11
+ watch: (options) => events.watch(agent, options),
12
+ },
13
+ session: {
14
+ appendDeveloperMessage: (text) => session.appendDeveloperMessage(agent, text),
15
+ compact: () => session.compact(agent),
16
+ context: () => session.context(agent),
17
+ fork: (options) => session.fork(agent, options),
18
+ snapshot: () => session.snapshot(agent),
19
+ setModel: (model) => session.setModel(agent, model),
20
+ setFastMode: (enabled) => session.setFastMode(agent, enabled),
21
+ setThinking: (thinking) => session.setThinking(agent, thinking),
22
+ shutdown: () => session.shutdown(agent),
23
+ spawn: () => session.spawn(agent),
24
+ realtime: {
25
+ start: () => session.startRealtimeConversation(agent),
26
+ end: () => session.endRealtimeConversation(agent),
27
+ delegation: (input, transcript) => session.realtimeDelegation(agent, input, transcript),
28
+ tailDelegation: (transcript) => session.realtimeTailDelegation(agent, transcript),
29
+ },
30
+ },
31
+ turn: {
32
+ prompt: (options) => turn.prompt(agent, options),
33
+ },
34
+ });
35
+ }
@@ -0,0 +1,66 @@
1
+ import type {
2
+ Agent,
3
+ AgentSessionContext,
4
+ CompactionOutcome,
5
+ DefaultAgent,
6
+ ForkOptions,
7
+ RealtimeTranscriptEntry,
8
+ SessionSnapshot,
9
+ Thinking,
10
+ } from "../types.mjs";
11
+
12
+ /** Appends adapter-owned developer context and returns the latest safe session context. */
13
+ export function appendDeveloperMessage(
14
+ agent: Agent<object>,
15
+ text: string,
16
+ ): Promise<AgentSessionContext>;
17
+
18
+ /** Starts the canonical Codex Realtime adapter lifecycle at a safe boundary. */
19
+ export function startRealtimeConversation(agent: Agent<object>): Promise<AgentSessionContext>;
20
+
21
+ /** Ends the canonical Codex Realtime adapter lifecycle at a safe boundary. */
22
+ export function endRealtimeConversation(agent: Agent<object>): Promise<AgentSessionContext>;
23
+
24
+ /** Formats structured Realtime input using canonical Codex delegation markers. */
25
+ export function realtimeDelegation(
26
+ agent: Agent<object>,
27
+ input: string,
28
+ transcript?: readonly RealtimeTranscriptEntry[],
29
+ ): Promise<string>;
30
+
31
+ /** Formats an unconsumed transcript tail, or returns undefined for an empty tail. */
32
+ export function realtimeTailDelegation(
33
+ agent: Agent<object>,
34
+ transcript: readonly RealtimeTranscriptEntry[],
35
+ ): Promise<string | undefined>;
36
+
37
+ /** Compacts retained history; provider-default compaction returns null. */
38
+ export function compact(agent: Agent<object>): Promise<CompactionOutcome | null>;
39
+
40
+ /** Returns complete read-only model context at the latest safe boundary. */
41
+ export function context(agent: Agent<object>): Promise<AgentSessionContext>;
42
+
43
+ /** Returns the latest committed, resumable engine-owned session snapshot. */
44
+ export function snapshot(agent: Agent<object>): Promise<SessionSnapshot>;
45
+
46
+ /** Forks the latest checkpoint, or the exact completed result supplied in `options.at`. */
47
+ export function fork(agent: Agent<object>, options?: fork.Options): Promise<fork.ReturnType>;
48
+ export declare namespace fork {
49
+ type Options = ForkOptions;
50
+ type ReturnType = DefaultAgent;
51
+ }
52
+
53
+ /** Creates a clean sibling with the Agent's configuration and tools. */
54
+ export function spawn(agent: Agent<object>): Promise<spawn.ReturnType>;
55
+ export declare namespace spawn {
56
+ type ReturnType = DefaultAgent;
57
+ }
58
+
59
+ /** Changes the reasoning effort for subsequently accepted turns. */
60
+ export function setThinking(agent: Agent<object>, thinking: Thinking): Promise<void>;
61
+
62
+ /** Enables or disables priority processing for subsequently accepted turns. */
63
+ export function setFastMode(agent: Agent<object>, enabled: boolean): Promise<void>;
64
+
65
+ /** Stops the driver and joins every resource owned by this Agent. */
66
+ export function shutdown(agent: Agent<object>): Promise<void>;
@@ -0,0 +1,59 @@
1
+ import {
2
+ appendDeveloperMessage as appendAgentDeveloperMessage,
3
+ compact as compactAgent,
4
+ context as agentContext,
5
+ fork as forkAgent,
6
+ snapshot as snapshotAgent,
7
+ setFastMode as setAgentFastMode,
8
+ setModel as setAgentModel,
9
+ setThinking as setAgentThinking,
10
+ shutdown as shutdownAgent,
11
+ spawn as spawnAgent,
12
+ } from "../internal.mjs";
13
+
14
+ export {
15
+ endRealtimeConversation,
16
+ realtimeDelegation,
17
+ realtimeTailDelegation,
18
+ startRealtimeConversation,
19
+ } from "../internal.mjs";
20
+
21
+ export function appendDeveloperMessage(agent, text) {
22
+ return appendAgentDeveloperMessage(agent, text);
23
+ }
24
+
25
+ export function compact(agent) {
26
+ return compactAgent(agent);
27
+ }
28
+
29
+ export function context(agent) {
30
+ return agentContext(agent);
31
+ }
32
+
33
+ export function snapshot(agent) {
34
+ return snapshotAgent(agent);
35
+ }
36
+
37
+ export function fork(agent, options = {}) {
38
+ return forkAgent(agent, options);
39
+ }
40
+
41
+ export function spawn(agent) {
42
+ return spawnAgent(agent);
43
+ }
44
+
45
+ export function setThinking(agent, thinking) {
46
+ return setAgentThinking(agent, thinking);
47
+ }
48
+
49
+ export function setModel(agent, model) {
50
+ return setAgentModel(agent, model);
51
+ }
52
+
53
+ export function setFastMode(agent, enabled) {
54
+ return setAgentFastMode(agent, enabled);
55
+ }
56
+
57
+ export function shutdown(agent) {
58
+ return shutdownAgent(agent);
59
+ }
@@ -0,0 +1,59 @@
1
+ import type {
2
+ Agent,
3
+ PromptInput,
4
+ SessionSnapshot,
5
+ Turn,
6
+ TurnResult,
7
+ TurnUsage,
8
+ } from "../types.mjs";
9
+
10
+ /** Accepts a prompt on an owned Agent and returns its independently awaitable Turn. */
11
+ export function prompt<const agent extends Agent<object>>(
12
+ agent: agent,
13
+ options: prompt.Options,
14
+ ): prompt.ReturnType<agent>;
15
+ export declare namespace prompt {
16
+ type Options = {
17
+ input: PromptInput;
18
+ id?: string | undefined;
19
+ supplementaryContext?: string | undefined;
20
+ };
21
+ type ReturnType<agent extends Agent<object> = Agent<object>> = Turn<agent>;
22
+ }
23
+
24
+ /** Waits for durable admission and returns its request ID when one was assigned. */
25
+ export function accepted(turn: Turn): Promise<accepted.ReturnType>;
26
+ export declare namespace accepted {
27
+ type ReturnType = string | undefined;
28
+ }
29
+
30
+ /** Waits for a Turn's typed completed result. */
31
+ export function getResult(turn: Turn): Promise<getResult.ReturnType>;
32
+ export declare namespace getResult {
33
+ type ReturnType = TurnResult;
34
+ }
35
+
36
+ /** Materializes a completed result's serializable session snapshot. */
37
+ export function getSnapshot(result: TurnResult): Promise<getSnapshot.ReturnType>;
38
+ export declare namespace getSnapshot {
39
+ type ReturnType = SessionSnapshot;
40
+ }
41
+
42
+ /** Materializes exact aggregate token usage from a completed result. */
43
+ export function getUsage(result: TurnResult): Promise<getUsage.ReturnType>;
44
+ export declare namespace getUsage {
45
+ type ReturnType = TurnUsage;
46
+ }
47
+
48
+ /** Adds input to an active Turn. */
49
+ export function steer(turn: Turn, options: steer.Options): Promise<void>;
50
+ export declare namespace steer {
51
+ type Options = { input: PromptInput };
52
+ type ReturnType = void;
53
+ }
54
+
55
+ /** Cancels an active or queued Turn. */
56
+ export function cancel(turn: Turn): Promise<void>;
57
+ export declare namespace cancel {
58
+ type ReturnType = void;
59
+ }
@@ -0,0 +1,37 @@
1
+ import {
2
+ awaitTurnAcceptance,
3
+ cancel as cancelTurn,
4
+ getTurnResult,
5
+ getTurnSnapshot,
6
+ getTurnUsage,
7
+ prompt as promptTurn,
8
+ steer as steerTurn,
9
+ } from "../internal.mjs";
10
+
11
+ export function prompt(agent, options) {
12
+ return promptTurn(agent, options);
13
+ }
14
+
15
+ export function getResult(turn) {
16
+ return getTurnResult(turn);
17
+ }
18
+
19
+ export function accepted(turn) {
20
+ return awaitTurnAcceptance(turn);
21
+ }
22
+
23
+ export function getSnapshot(result) {
24
+ return getTurnSnapshot(result);
25
+ }
26
+
27
+ export function getUsage(result) {
28
+ return getTurnUsage(result);
29
+ }
30
+
31
+ export function steer(turn, options) {
32
+ return steerTurn(turn, options);
33
+ }
34
+
35
+ export function cancel(turn) {
36
+ return cancelTurn(turn);
37
+ }
@@ -0,0 +1,22 @@
1
+ import type {
2
+ create as createResource,
3
+ Event,
4
+ Options,
5
+ Snapshot,
6
+ Settings,
7
+ Voice,
8
+ } from "../browser/Voice.mjs";
9
+
10
+ export function create(agent: Parameters<typeof createResource>[0], options?: Options): Voice;
11
+ export function start(voice: Voice, options?: Settings): Promise<void>;
12
+ export function stop(voice: Voice): Promise<void>;
13
+ export function toggle(voice: Voice, options?: Settings): Promise<void>;
14
+ export function cancel(voice: Voice): Promise<boolean>;
15
+ export function destroy(voice: Voice): Promise<void>;
16
+ export function getSnapshot(voice: Voice): Snapshot;
17
+ export function subscribe(voice: Voice, listener: () => void): () => void;
18
+ export function onEvent(voice: Voice, listener: (event: Event) => void): () => void;
19
+
20
+ export function speak(voice: Voice, text: string): Promise<void>;
21
+ export function appendText(voice: Voice, text: string, options?: { role?: "user" | "developer" | "assistant" }): Promise<void>;
22
+ export function appendContext(voice: Voice, text: string): Promise<void>;
@@ -0,0 +1,50 @@
1
+ import { create as createResource } from "../browser/Voice.mjs";
2
+
3
+ /** Creates one browser voice resource backed by the Agent's Rust/WASM controller. */
4
+ export function create(agent, options) {
5
+ return createResource(agent, options);
6
+ }
7
+
8
+ export function start(voice, options) {
9
+ return voice.start(options);
10
+ }
11
+
12
+ export function stop(voice) {
13
+ return voice.stop();
14
+ }
15
+
16
+ export function toggle(voice, options) {
17
+ return voice.toggle(options);
18
+ }
19
+
20
+ export function cancel(voice) {
21
+ return voice.cancel();
22
+ }
23
+
24
+ export function destroy(voice) {
25
+ return voice.destroy();
26
+ }
27
+
28
+ export function getSnapshot(voice) {
29
+ return voice.getSnapshot();
30
+ }
31
+
32
+ export function subscribe(voice, listener) {
33
+ return voice.subscribe(listener);
34
+ }
35
+
36
+ export function onEvent(voice, listener) {
37
+ return voice.onEvent(listener);
38
+ }
39
+
40
+ export function speak(voice, text) {
41
+ return voice.speak(text);
42
+ }
43
+
44
+ export function appendText(voice, text, options) {
45
+ return voice.appendText(text, options);
46
+ }
47
+
48
+ export function appendContext(voice, text) {
49
+ return voice.appendContext(text);
50
+ }
@@ -0,0 +1,55 @@
1
+ import type {
2
+ AgentLifecycle,
3
+ AgentOptions,
4
+ DefaultAgent,
5
+ ExecutionEnvironment,
6
+ } from "../types.mjs";
7
+ import type { ManagedTransport, WorkerTransport } from "./Transport.mjs";
8
+ import type { Tools } from "../tools/Tools.mjs";
9
+
10
+ export type Agent = DefaultAgent;
11
+ /** Worker options exclude function-valued resolver callbacks. */
12
+ type WorkerAgentOptions = Omit<AgentOptions, "resolveCompactionInstruction">;
13
+
14
+ type WorkerMcpServer = Readonly<{
15
+ url?: string | URL | undefined;
16
+ description?: string | undefined;
17
+ headers?: Readonly<Record<string, string>> | readonly (readonly [string, string])[] | undefined;
18
+ enabledTools?: readonly string[] | undefined;
19
+ disabledTools?: readonly string[] | undefined;
20
+ supportsParallelToolCalls?: boolean | undefined;
21
+ parallelTools?: readonly string[] | undefined;
22
+ startupTimeoutMs?: number | undefined;
23
+ timeoutMs?: number | undefined;
24
+ }>;
25
+ type WorkerMcpServers = Readonly<Record<string, string | URL | WorkerMcpServer>>;
26
+ type WorkerToolExposureOptions =
27
+ | { mcp?: false | undefined; toolMode?: "code" | "direct" | undefined }
28
+ | { mcp: WorkerMcpServers; toolMode?: "code" | undefined };
29
+
30
+ /** Creates a Rust/WASM Agent in a package-owned browser module Worker. */
31
+ export function create(options: create.ManagedOptions): Promise<AgentLifecycle>;
32
+ export function create(options?: create.Options): Promise<create.ReturnType>;
33
+ export declare namespace create {
34
+ type ManagedOptions = Readonly<{
35
+ transport: ManagedTransport;
36
+ tools?: Tools | undefined;
37
+ }>;
38
+ type Options = WorkerAgentOptions & WorkerToolExposureOptions & {
39
+ /** Precompiled browser module; WebAssembly modules are structured-clone-safe. */
40
+ module?: WebAssembly.Module | undefined;
41
+ /** Fixed browser workspace facts, including its AGENTS.md snapshot. */
42
+ executionEnvironment?: ExecutionEnvironment | undefined;
43
+ /** Defaults to the same-origin Nanocodex `/api/responses` proxy. */
44
+ transport?: WorkerTransport | undefined;
45
+ /** Stable OPFS/Git workspace identity for the default browser harness. */
46
+ threadId?: string | undefined;
47
+ /** Exposes provider authorization links in the default browser harness. */
48
+ accountConnectionRequests?: boolean | undefined;
49
+ /** Set false to keep this browser session out of the IndexedDB durability store. */
50
+ durability?: false | undefined;
51
+ /** Set false to omit the default OPFS, shell, web, image, plan, and artifact tools. */
52
+ harness?: false | undefined;
53
+ };
54
+ type ReturnType = Agent;
55
+ }
@@ -0,0 +1,11 @@
1
+ import {
2
+ createManagedAgent,
3
+ managedTransportOptions,
4
+ } from "../runtime/managed-transport.mjs";
5
+
6
+ /** Create the browser Agent in its package-owned module Worker. */
7
+ export function create(options = {}) {
8
+ if (managedTransportOptions(options?.transport)) return createManagedAgent(options);
9
+ return import("./WorkerAgent.mjs").then(({ createWorkerAgent }) =>
10
+ createWorkerAgent(options));
11
+ }
@@ -0,0 +1,7 @@
1
+ import type {
2
+ ChatGptSubscriptionHandle,
3
+ ChatGptSubscriptionOptions,
4
+ } from "../types.mjs";
5
+
6
+ /** Opens the Rust-owned ChatGPT device-login and credential lifecycle. */
7
+ export function open(options: ChatGptSubscriptionOptions): Promise<ChatGptSubscriptionHandle>;
@@ -0,0 +1,19 @@
1
+ import init, { ChatGptSubscription as WasmChatGptSubscription } from "../pkg-web/nanocodex.js";
2
+
3
+ import { installHostBridge } from "../internal.mjs";
4
+ import { openSubscription } from "../runtime/chatgpt-subscription.mjs";
5
+
6
+ let initialized;
7
+
8
+ /** Opens a Rust-managed ChatGPT subscription over caller-owned storage and fetch. */
9
+ export async function open(options) {
10
+ installHostBridge();
11
+ initialized ||= init(options?.module === undefined
12
+ ? undefined
13
+ : { module_or_path: options.module }).catch((error) => {
14
+ initialized = undefined;
15
+ throw error;
16
+ });
17
+ await initialized;
18
+ return openSubscription(options, (config) => WasmChatGptSubscription.open(config));
19
+ }