@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,209 @@
1
+ import type { Workspace } from "../../runtime/workspace.mjs";
2
+ import type { NamedTool } from "../../types.mjs";
3
+ import type { JustBashDescriptor } from "../bash.mjs";
4
+ import type { DatasetOptions, JsonToolOptions } from "../index.mjs";
5
+
6
+ export type BrowserThread = Readonly<{
7
+ id: string;
8
+ workspaceName: string;
9
+ repositoryName: string;
10
+ branch: "nanocodex";
11
+ remoteUrl: string;
12
+ shareUrl: string;
13
+ }>;
14
+
15
+ export type ThreadGitStatus = Readonly<{
16
+ branch: "nanocodex";
17
+ head?: string | undefined;
18
+ changes: string[];
19
+ remoteUrl: string;
20
+ }>;
21
+
22
+ export type OpfsFileStat = Readonly<{
23
+ size: number;
24
+ mtimeMs: number;
25
+ isFile(): boolean;
26
+ isDirectory(): boolean;
27
+ isSymbolicLink(): false;
28
+ }>;
29
+
30
+ export type OpfsDirectoryEntry = Readonly<{
31
+ name: string;
32
+ isFile(): boolean;
33
+ isDirectory(): boolean;
34
+ isSymbolicLink(): false;
35
+ }>;
36
+
37
+ export type OpfsGitFs = Readonly<{
38
+ promises: Readonly<{
39
+ readFile(path: string): Promise<Uint8Array>;
40
+ readFile(path: string, options: string | { encoding: string; maxBytes?: number }): Promise<string>;
41
+ readFile(path: string, options: { maxBytes: number; encoding?: undefined }): Promise<Uint8Array>;
42
+ writeFile(path: string, value: string | Uint8Array): Promise<void>;
43
+ appendFile(path: string, value: string | Uint8Array): Promise<void>;
44
+ unlink(path: string): Promise<void>;
45
+ readdir(path: string): Promise<string[]>;
46
+ readdirWithFileTypes(path: string): Promise<OpfsDirectoryEntry[]>;
47
+ mkdir(path: string): Promise<void>;
48
+ rmdir(path: string): Promise<void>;
49
+ rm(path: string, options?: { recursive?: boolean }): Promise<void>;
50
+ stat(path: string): Promise<OpfsFileStat>;
51
+ lstat(path: string): Promise<OpfsFileStat>;
52
+ readlink(path: string): Promise<never>;
53
+ symlink(target: string, path: string): Promise<never>;
54
+ }>;
55
+ }>;
56
+
57
+ export type BrowserCommandResult = Readonly<{
58
+ output: string;
59
+ wall_time_seconds: number;
60
+ exit_code: number;
61
+ original_token_count?: number | undefined;
62
+ }>;
63
+
64
+ export type BrowserBashResult = Readonly<{
65
+ stdout: string;
66
+ stderr: string;
67
+ exitCode: number;
68
+ env: Record<string, string>;
69
+ }>;
70
+
71
+ export type BrowserBash = {
72
+ exec(
73
+ script: string,
74
+ options?: Readonly<{
75
+ cwd?: string | undefined;
76
+ env?: Record<string, string> | undefined;
77
+ replaceEnv?: boolean | undefined;
78
+ rawScript?: boolean | undefined;
79
+ stdin?: string | undefined;
80
+ stdinKind?: "text" | "bytes" | undefined;
81
+ signal?: AbortSignal | undefined;
82
+ args?: string[] | undefined;
83
+ }>,
84
+ ): Promise<BrowserBashResult>;
85
+ };
86
+
87
+ export type BrowserShellStat = Readonly<{
88
+ isFile: boolean;
89
+ isDirectory: boolean;
90
+ isSymbolicLink: boolean;
91
+ mode: number;
92
+ size: number;
93
+ mtime: Date;
94
+ }>;
95
+
96
+ export type BrowserShellFileSystem = {
97
+ readonly mutationVersion: number;
98
+ refreshPaths(): Promise<void>;
99
+ recordExternalWrite(path: string): void;
100
+ recordExternalRemove(path: string): void;
101
+ recordRepositoryMutation(): void;
102
+ readFile(path: string, options?: string | { encoding?: string }): Promise<string>;
103
+ readFileBytes(path: string): Promise<string>;
104
+ readFileBuffer(path: string): Promise<Uint8Array>;
105
+ writeFile(path: string, content: string | Uint8Array, options?: string): Promise<void>;
106
+ appendFile(path: string, content: string | Uint8Array, options?: string): Promise<void>;
107
+ exists(path: string): Promise<boolean>;
108
+ stat(path: string): Promise<BrowserShellStat>;
109
+ mkdir(path: string): Promise<void>;
110
+ readdir(path: string): Promise<string[]>;
111
+ readdirWithFileTypes(path: string): Promise<OpfsDirectoryEntry[]>;
112
+ rm(path: string, options?: { force?: boolean; recursive?: boolean }): Promise<void>;
113
+ cp(src: string, dest: string, options?: { recursive?: boolean }): Promise<void>;
114
+ mv(src: string, dest: string): Promise<void>;
115
+ resolvePath(base: string, path: string): string;
116
+ getAllPaths(): string[];
117
+ chmod(path: string, mode: number): Promise<void>;
118
+ symlink(target: string, linkPath: string): Promise<never>;
119
+ link(existingPath: string, newPath: string): Promise<never>;
120
+ readlink(path: string): Promise<never>;
121
+ lstat(path: string): Promise<BrowserShellStat>;
122
+ realpath(path: string): Promise<string>;
123
+ utimes(path: string, atime: Date | number, mtime: Date | number): Promise<void>;
124
+ };
125
+
126
+ export type BrowserOptions = Readonly<{
127
+ threadId: string;
128
+ origin?: string | undefined;
129
+ fetch?: typeof globalThis.fetch | undefined;
130
+ headers?: HeadersInit | undefined;
131
+ installFetch?: boolean | undefined;
132
+ /** Exposes a tool that returns provider authorization links for account connections. */
133
+ accountConnectionRequests?: boolean | undefined;
134
+ accountInfo?: Readonly<{
135
+ endpoint?: string | undefined;
136
+ requireAuthorization?: boolean | undefined;
137
+ }> | undefined;
138
+ web?: JsonToolOptions | undefined;
139
+ images?: JsonToolOptions | undefined;
140
+ dataset?: DatasetOptions | undefined;
141
+ recentImages?(sessionId: string, count: number): string[];
142
+ rememberImage?(sessionId: string, imageUrl: string): void;
143
+ }>;
144
+
145
+ export type BrowserTools = Readonly<{
146
+ filesystem: Workspace;
147
+ instructions: string;
148
+ projectInstructions?: string | undefined;
149
+ tools: readonly NamedTool[];
150
+ }>;
151
+
152
+ /** Thread-scoped OPFS, Git, shell, and module state reusable across Agent starts. */
153
+ export type PreparedBrowser = Readonly<{
154
+ origin: string;
155
+ threadId: string;
156
+ }>;
157
+
158
+ /** Opens a persistent OPFS workspace and composes its WASM-backed tools. */
159
+ export function browser(options: BrowserOptions): Promise<BrowserTools>;
160
+ export function prepareBrowser(
161
+ options: Pick<BrowserOptions, "threadId" | "origin">,
162
+ ): Promise<PreparedBrowser>;
163
+ export function bindBrowser(prepared: PreparedBrowser, options: BrowserOptions): BrowserTools;
164
+
165
+ export function browserThread(threadId: string, origin: string): BrowserThread;
166
+ export function getBrowserThread(): BrowserThread;
167
+ export function selectBrowserThread(threadId: string): BrowserThread;
168
+ export function openKernelWorkspace(): Promise<Workspace>;
169
+ export function openThreadWorkspace(threadId: string): Promise<Workspace>;
170
+ export function subscribeThreadWorkspaceChanges(threadId: string, listener: () => void): () => void;
171
+
172
+ export function openOpfsWorkspaceRoot(workspaceName: string): Promise<FileSystemDirectoryHandle>;
173
+ export function openOpfsGitFs(workspaceName: string): Promise<OpfsGitFs>;
174
+ export function createOpfsGitFs(root: FileSystemDirectoryHandle): OpfsGitFs;
175
+
176
+ export function initializeThreadGit(thread: BrowserThread): Promise<ThreadGitStatus>;
177
+ export function inspectThreadGit<T>(thread: BrowserThread, inspect: (fs: OpfsGitFs) => Promise<T>): Promise<T>;
178
+ export function threadGitStatus(thread: BrowserThread): Promise<ThreadGitStatus>;
179
+ export function commitAndPushThread(
180
+ thread: BrowserThread,
181
+ message?: string,
182
+ notificationSource?: string,
183
+ ): Promise<ThreadGitStatus>;
184
+ export function pullThread(thread: BrowserThread, notificationSource?: string): Promise<ThreadGitStatus>;
185
+ export function subscribeThreadGitChanges(thread: BrowserThread, listener: (source?: string) => void): () => void;
186
+ export function notifyThreadGitChanged(thread: BrowserThread, source?: string): void;
187
+ export function withThreadGitLock<T>(
188
+ thread: BrowserThread,
189
+ operation: () => Promise<T>,
190
+ signal?: AbortSignal,
191
+ ): Promise<T>;
192
+
193
+ export function loadBrowserProjectInstructions(rawFs: OpfsGitFs): Promise<string | undefined>;
194
+ export function validateBrowserArtifactSource(source: string): Promise<void>;
195
+ export function createBrowserBash(
196
+ rawFs: OpfsGitFs,
197
+ thread: BrowserThread,
198
+ options?: Record<string, unknown>,
199
+ ): Promise<{
200
+ bash: BrowserBash;
201
+ descriptor: JustBashDescriptor;
202
+ filesystem: BrowserShellFileSystem;
203
+ instructions: string;
204
+ tool: NamedTool;
205
+ exec(
206
+ input: Record<string, unknown>,
207
+ context?: { signal?: AbortSignal },
208
+ ): Promise<BrowserCommandResult>;
209
+ }>;
@@ -0,0 +1,174 @@
1
+ import "./browserBuffer.mjs";
2
+ import { browseX } from "../../../nanocodex-tools/tools/x.mjs";
3
+ import {
4
+ createBrowserEgressFetch,
5
+ createBrowserRuntimeFetch,
6
+ installBrowserEgressFetch,
7
+ } from "./browserEgress.mjs";
8
+ import {
9
+ browserAccountConnectionTool,
10
+ browserAccountInfoTool,
11
+ browserRuntimeInfoTool,
12
+ } from "./accountInfo.mjs";
13
+
14
+ const preparedBrowsers = new Map();
15
+ const ACCOUNT_CONNECTION_INSTRUCTIONS = "Use requestAccountConnection when the user asks to connect or authenticate GitHub, a Google Workspace service, Slack, or X. For authorization_required results, return the exact authorization_url as a Markdown link. Never claim the account is connected until a later accountInfo call reports it as authenticated.";
16
+
17
+ export {
18
+ createOpfsGitFs,
19
+ openOpfsGitFs,
20
+ openOpfsWorkspaceRoot,
21
+ } from "./opfsGit.mjs";
22
+ export {
23
+ browserThread,
24
+ commitAndPushThread,
25
+ initializeThreadGit,
26
+ inspectThreadGit,
27
+ notifyThreadGitChanged,
28
+ pullThread,
29
+ subscribeThreadGitChanges,
30
+ threadGitStatus,
31
+ withThreadGitLock,
32
+ } from "./threadGit.mjs";
33
+ export {
34
+ getBrowserThread,
35
+ selectBrowserThread,
36
+ openKernelWorkspace,
37
+ openThreadWorkspace,
38
+ subscribeThreadWorkspaceChanges,
39
+ } from "./workspace.mjs";
40
+
41
+ export async function browser(options) {
42
+ const prepared = options?.prepared ?? await prepareBrowser(options);
43
+ return bindBrowser(prepared, options);
44
+ }
45
+
46
+ export function prepareBrowser(options) {
47
+ if (!options || typeof options !== "object" || Array.isArray(options)) {
48
+ throw new TypeError("browser tool options must be an object");
49
+ }
50
+ const origin = options.origin ?? globalThis.location?.origin;
51
+ if (typeof options.threadId !== "string" || !options.threadId) {
52
+ throw new TypeError("browser threadId must be a non-empty string");
53
+ }
54
+ if (typeof origin !== "string" || !origin) {
55
+ throw new TypeError("browser origin is required outside a browser location");
56
+ }
57
+ if (options.installFetch === false) {
58
+ return prepareBrowserRuntime(options.threadId, origin, options);
59
+ }
60
+ const key = `${origin}\n${options.threadId}`;
61
+ let prepared = preparedBrowsers.get(key);
62
+ prepared ??= prepareBrowserRuntime(options.threadId, origin, options).catch((error) => {
63
+ preparedBrowsers.delete(key);
64
+ throw error;
65
+ });
66
+ preparedBrowsers.set(key, prepared);
67
+ return prepared;
68
+ }
69
+
70
+ async function prepareBrowserRuntime(threadId, origin, options) {
71
+ const [shellModule, standard, datasets] = await Promise.all([
72
+ import("./browserShell.mjs"),
73
+ import("../standard.mjs"),
74
+ import("../dataset.mjs"),
75
+ ]);
76
+ const fetch = (options.installFetch === false
77
+ ? createBrowserRuntimeFetch
78
+ : installBrowserEgressFetch)({
79
+ fetch: options.fetch,
80
+ headers: options.headers,
81
+ origin,
82
+ threadId,
83
+ });
84
+ const secureFetch = createBrowserEgressFetch({ fetch, origin, threadId });
85
+ const shell = await shellModule.prepareBrowserShell(
86
+ threadId,
87
+ origin,
88
+ secureFetch,
89
+ options.headers,
90
+ );
91
+ return Object.freeze({
92
+ origin,
93
+ threadId,
94
+ fetch,
95
+ shell,
96
+ standard,
97
+ datasets,
98
+ });
99
+ }
100
+
101
+ export function bindBrowser(prepared, options = {}) {
102
+ if (!prepared || typeof prepared !== "object" || Array.isArray(prepared)) {
103
+ throw new TypeError("prepared browser runtime is required");
104
+ }
105
+ if (options.threadId !== undefined && options.threadId !== prepared.threadId) {
106
+ throw new Error("prepared browser runtime belongs to a different thread");
107
+ }
108
+ const { datasets, fetch, shell, standard } = prepared;
109
+ const web = {
110
+ url: new URL("/api/tools/web-search", prepared.origin),
111
+ fetch,
112
+ ...options.web,
113
+ };
114
+ const images = {
115
+ url: new URL("/api/tools/image-generation", prepared.origin),
116
+ fetch,
117
+ ...options.images,
118
+ };
119
+ const account = {
120
+ endpoint: options.accountInfo?.endpoint,
121
+ fetch,
122
+ origin: prepared.origin,
123
+ requireAuthorization: options.accountInfo?.requireAuthorization,
124
+ };
125
+ return Object.freeze({
126
+ filesystem: shell.workspace,
127
+ instructions: options.accountConnectionRequests
128
+ ? `${shell.instructions}\n\n${ACCOUNT_CONNECTION_INSTRUCTIONS}`
129
+ : shell.instructions,
130
+ projectInstructions: shell.projectInstructions,
131
+ tools: Object.freeze([
132
+ standard.namedTool("exec_command", shell.execTool),
133
+ browserRuntimeInfoTool(account, shell.descriptor),
134
+ browserAccountInfoTool(account),
135
+ ...(options.accountConnectionRequests ? [browserAccountConnectionTool(account)] : []),
136
+ browseX({
137
+ fetch: (input, init) => {
138
+ const source = new URL(input);
139
+ const url = new URL(`/api/tools/x/${source.pathname.slice("/api/".length)}`, prepared.origin);
140
+ url.search = source.search;
141
+ const headers = new Headers(init?.headers);
142
+ headers.set("x-nanocodex-request", "1");
143
+ return fetch(url, { ...init, headers, credentials: "same-origin" });
144
+ },
145
+ }),
146
+ standard.web(web),
147
+ standard.imageGeneration({
148
+ ...images,
149
+ recentImages: options.recentImages,
150
+ rememberImage: options.rememberImage,
151
+ workspace: shell.workspace,
152
+ }),
153
+ standard.viewImage({ workspace: shell.workspace }),
154
+ standard.updatePlan(),
155
+ datasets.dataset(options.dataset),
156
+ shell.artifactTool,
157
+ ]),
158
+ });
159
+ }
160
+
161
+ export async function createBrowserBash(rawFs, thread, options) {
162
+ const { createBrowserBash: create } = await import("./browserShell.mjs");
163
+ return create(rawFs, thread, options);
164
+ }
165
+
166
+ export async function loadBrowserProjectInstructions(rawFs) {
167
+ const { loadBrowserProjectInstructions: load } = await import("./browserShell.mjs");
168
+ return load(rawFs);
169
+ }
170
+
171
+ export async function validateBrowserArtifactSource(source) {
172
+ const { validateBrowserArtifactSource: validate } = await import("./browserShell.mjs");
173
+ return validate(source);
174
+ }
@@ -0,0 +1,248 @@
1
+ const WORKSPACE_DIRECTORY = "nanocodex-workspaces";
2
+ export async function openOpfsWorkspaceRoot(workspaceName) {
3
+ if (!navigator.storage?.getDirectory) {
4
+ throw new Error("Origin Private File System storage is unavailable in this browser");
5
+ }
6
+ const origin = await navigator.storage.getDirectory();
7
+ const workspaces = await origin.getDirectoryHandle(WORKSPACE_DIRECTORY, { create: true });
8
+ return workspaces.getDirectoryHandle(encodeURIComponent(workspaceName), { create: true });
9
+ }
10
+ export async function openOpfsGitFs(workspaceName) {
11
+ return createOpfsGitFs(await openOpfsWorkspaceRoot(workspaceName));
12
+ }
13
+ export function createOpfsGitFs(root) {
14
+ return { promises: createPromises(root) };
15
+ }
16
+ function createPromises(root) {
17
+ return {
18
+ async readFile(path, options) {
19
+ const relative = normalize(path);
20
+ if (!relative)
21
+ throw fsError("EISDIR", "cannot read a directory");
22
+ try {
23
+ const { parent, name } = await parentHandle(root, relative, false);
24
+ const file = await (await parent.getFileHandle(name)).getFile();
25
+ const maxBytes = typeof options === "object" ? options.maxBytes : undefined;
26
+ const source = maxBytes === undefined ? file : file.slice(0, maxBytes);
27
+ let bytes = new Uint8Array(await source.arrayBuffer());
28
+ if (maxBytes !== undefined && bytes.byteLength > maxBytes) {
29
+ bytes = bytes.subarray(0, maxBytes);
30
+ }
31
+ const encoding = typeof options === "string" ? options : options?.encoding;
32
+ return encoding ? new TextDecoder(encoding).decode(bytes) : bytes;
33
+ }
34
+ catch (error) {
35
+ throw translateError(error, "ENOENT", `cannot read ${relative}`);
36
+ }
37
+ },
38
+ async writeFile(path, value) {
39
+ const relative = normalize(path);
40
+ if (!relative)
41
+ throw fsError("EISDIR", "cannot write a directory");
42
+ try {
43
+ const { parent, name } = await parentHandle(root, relative, false);
44
+ const handle = await parent.getFileHandle(name, { create: true });
45
+ const writable = await handle.createWritable();
46
+ try {
47
+ await writable.write(asWriteValue(value));
48
+ await writable.close();
49
+ }
50
+ catch (error) {
51
+ await writable.abort(error).catch(() => undefined);
52
+ throw error;
53
+ }
54
+ }
55
+ catch (error) {
56
+ throw translateError(error, "ENOENT", `cannot write ${relative}`);
57
+ }
58
+ },
59
+ async appendFile(path, value) {
60
+ const relative = normalize(path);
61
+ if (!relative)
62
+ throw fsError("EISDIR", "cannot append to a directory");
63
+ try {
64
+ const { parent, name } = await parentHandle(root, relative, false);
65
+ const handle = await parent.getFileHandle(name, { create: true });
66
+ const size = (await handle.getFile()).size;
67
+ const writable = await handle.createWritable({ keepExistingData: true });
68
+ try {
69
+ await writable.seek(size);
70
+ await writable.write(asWriteValue(value));
71
+ await writable.close();
72
+ }
73
+ catch (error) {
74
+ await writable.abort(error).catch(() => undefined);
75
+ throw error;
76
+ }
77
+ }
78
+ catch (error) {
79
+ throw translateError(error, "ENOENT", `cannot append ${relative}`);
80
+ }
81
+ },
82
+ async unlink(path) {
83
+ await remove(root, normalize(path), false);
84
+ },
85
+ async readdir(path) {
86
+ const directory = await directoryHandle(root, normalize(path), false);
87
+ const names = [];
88
+ const entries = directoryEntries(directory);
89
+ for await (const [name] of entries)
90
+ names.push(name);
91
+ return names;
92
+ },
93
+ async readdirWithFileTypes(path) {
94
+ const directory = await directoryHandle(root, normalize(path), false);
95
+ const entries = [];
96
+ for await (const [name, handle] of directoryEntries(directory)) {
97
+ entries.push({
98
+ name,
99
+ isFile: handle.kind === "file",
100
+ isDirectory: handle.kind === "directory",
101
+ isSymbolicLink: false,
102
+ });
103
+ }
104
+ return entries;
105
+ },
106
+ async mkdir(path) {
107
+ await directoryHandle(root, normalize(path), true);
108
+ },
109
+ async rmdir(path) {
110
+ const relative = normalize(path);
111
+ if (!relative)
112
+ throw fsError("EPERM", "cannot remove workspace root");
113
+ await remove(root, relative, false);
114
+ },
115
+ async rm(path, options) {
116
+ const relative = normalize(path);
117
+ if (!relative)
118
+ throw fsError("EPERM", "cannot remove workspace root");
119
+ await remove(root, relative, Boolean(options?.recursive));
120
+ },
121
+ async stat(path) {
122
+ return stat(root, normalize(path));
123
+ },
124
+ async lstat(path) {
125
+ return stat(root, normalize(path));
126
+ },
127
+ async readlink() {
128
+ throw fsError("ENOSYS", "OPFS does not support symbolic links");
129
+ },
130
+ async symlink() {
131
+ throw fsError("ENOSYS", "OPFS does not support symbolic links");
132
+ },
133
+ };
134
+ }
135
+ function directoryEntries(directory) {
136
+ return directory.entries();
137
+ }
138
+ async function stat(root, relative) {
139
+ try {
140
+ const handle = relative ? await entryHandle(root, relative) : root;
141
+ if (handle.kind === "directory") {
142
+ return fileStat("directory", 0, 0);
143
+ }
144
+ const file = await handle.getFile();
145
+ return fileStat("file", file.size, file.lastModified);
146
+ }
147
+ catch (error) {
148
+ throw translateError(error, "ENOENT", `cannot stat ${relative}`);
149
+ }
150
+ }
151
+ function fileStat(kind, size, modifiedAt) {
152
+ return {
153
+ size,
154
+ mode: kind === "directory" ? 0o040755 : 0o100644,
155
+ mtimeMs: modifiedAt,
156
+ ctimeMs: modifiedAt,
157
+ isFile: () => kind === "file",
158
+ isDirectory: () => kind === "directory",
159
+ isSymbolicLink: () => false,
160
+ };
161
+ }
162
+ async function entryHandle(root, relative) {
163
+ const { parent, name } = await parentHandle(root, relative, false);
164
+ try {
165
+ return await parent.getFileHandle(name);
166
+ }
167
+ catch (fileError) {
168
+ try {
169
+ return await parent.getDirectoryHandle(name);
170
+ }
171
+ catch {
172
+ throw fileError;
173
+ }
174
+ }
175
+ }
176
+ async function directoryHandle(root, relative, create) {
177
+ let directory = root;
178
+ if (!relative)
179
+ return directory;
180
+ try {
181
+ for (const segment of relative.split("/")) {
182
+ directory = await directory.getDirectoryHandle(segment, { create });
183
+ }
184
+ return directory;
185
+ }
186
+ catch (error) {
187
+ throw translateError(error, "ENOENT", `cannot open directory ${relative}`);
188
+ }
189
+ }
190
+ async function parentHandle(root, relative, create) {
191
+ const segments = relative.split("/");
192
+ const name = segments.pop();
193
+ if (!name)
194
+ throw fsError("EINVAL", "path cannot be empty");
195
+ return { parent: await directoryHandle(root, segments.join("/"), create), name };
196
+ }
197
+ async function remove(root, relative, recursive) {
198
+ try {
199
+ const { parent, name } = await parentHandle(root, relative, false);
200
+ await parent.removeEntry(name, { recursive });
201
+ }
202
+ catch (error) {
203
+ throw translateError(error, "ENOENT", `cannot remove ${relative}`);
204
+ }
205
+ }
206
+ function normalize(path) {
207
+ if (typeof path !== "string")
208
+ throw fsError("EINVAL", "path must be a string");
209
+ const raw = path.replace(/\\/g, "/").replace(/^\/+/, "");
210
+ const relative = raw === "workspace" ? "" : raw.startsWith("workspace/") ? raw.slice(10) : raw;
211
+ const segments = [];
212
+ for (const segment of relative.split("/")) {
213
+ if (!segment || segment === ".")
214
+ continue;
215
+ if (segment === "..")
216
+ throw fsError("EPERM", "path escapes the workspace");
217
+ segments.push(segment);
218
+ }
219
+ return segments.join("/");
220
+ }
221
+ function asWriteValue(value) {
222
+ if (typeof value === "string" || value instanceof Blob)
223
+ return value;
224
+ if (value instanceof ArrayBuffer)
225
+ return value;
226
+ if (ArrayBuffer.isView(value)) {
227
+ const bytes = new Uint8Array(value.byteLength);
228
+ bytes.set(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
229
+ return bytes;
230
+ }
231
+ throw fsError("EINVAL", "file contents must be bytes or text");
232
+ }
233
+ function translateError(error, fallback, message) {
234
+ if (error && typeof error === "object" && "code" in error &&
235
+ typeof error.code === "string") {
236
+ return error;
237
+ }
238
+ const name = error instanceof DOMException ? error.name : "";
239
+ const code = name === "NotFoundError" ? "ENOENT"
240
+ : name === "TypeMismatchError" ? "ENOTDIR"
241
+ : name === "InvalidModificationError" ? "ENOTEMPTY"
242
+ : name === "NoModificationAllowedError" ? "EPERM"
243
+ : fallback;
244
+ return fsError(code, message, error);
245
+ }
246
+ function fsError(code, message, cause) {
247
+ return Object.assign(new Error(message, cause === undefined ? undefined : { cause }), { code });
248
+ }