@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,264 @@
1
+ const tempoMcp = Symbol.for("nanocodex.tempo.mcp");
2
+
3
+ export const DEFAULT_MERCATOR_MCP_URL = "https://mercator.tempo.xyz/mcp";
4
+
5
+ const defaultMercator = (payment) => ({
6
+ url: DEFAULT_MERCATOR_MCP_URL,
7
+ description: "Discovers and composes paid Tempo services and MPP flows.",
8
+ payment,
9
+ });
10
+
11
+ /**
12
+ * Marks an MPP session as a Tempo provider and uses the same wallet policy for
13
+ * Nanocodex's built-in paid Mercator MCP. Generic MPP sessions remain generic.
14
+ */
15
+ export function createTempoProvider(options) {
16
+ const session = options?.session;
17
+ if (!session || typeof session.ws !== "function") {
18
+ throw new TypeError("session must provide ws(endpoint)");
19
+ }
20
+ if (!options.payment || !Array.isArray(options.payment.methods) || !options.payment.methods.length) {
21
+ throw new TypeError("Tempo provider payment must include at least one MPPx method");
22
+ }
23
+
24
+ const provider = {
25
+ kind: "tempo",
26
+ session,
27
+ ws(endpoint) {
28
+ return session.ws(endpoint);
29
+ },
30
+ ...(typeof options.fetch === "function" ? { fetch: options.fetch } : {}),
31
+ };
32
+ if (typeof session.close === "function") {
33
+ provider.close = () => session.close();
34
+ }
35
+ Object.defineProperty(provider, tempoMcp, {
36
+ value: { mercator: defaultMercator(options.payment) },
37
+ });
38
+ return Object.freeze(provider);
39
+ }
40
+
41
+ /**
42
+ * Creates the model session and Mercator payment method from any Accounts SDK
43
+ * provider. Accounts adapters all meet the same getMppxParameters() contract,
44
+ * so wallet selection remains entirely application-owned.
45
+ */
46
+ export async function createTempoProviderFromAccounts(options) {
47
+ const wallet = options?.wallet;
48
+ if (!wallet || typeof wallet.getMppxParameters !== "function") {
49
+ throw new TypeError("wallet must provide getMppxParameters(options)");
50
+ }
51
+ const accessKey = options.accessKey;
52
+ const walletParametersRaw = wallet.getMppxParameters(
53
+ accessKey === undefined ? undefined : { accessKey },
54
+ );
55
+ if (!walletParametersRaw || typeof walletParametersRaw.getClient !== "function"
56
+ || typeof walletParametersRaw.resolveAccount !== "function") {
57
+ throw new TypeError("wallet.getMppxParameters() returned invalid MPPx parameters");
58
+ }
59
+ // Keep mppx out of normal/API-key browser bundles. It is loaded only when an
60
+ // application explicitly asks Nanocodex to construct a Tempo wallet path.
61
+ const [{ Mppx, tempo }, { createClient, http }] = await Promise.all([
62
+ import("mppx/client"),
63
+ import("viem/tempo"),
64
+ ]);
65
+ const walletParameters = await pinnedScopedAccountParameters(
66
+ wallet,
67
+ walletParametersRaw,
68
+ accessKey,
69
+ {
70
+ account: options.account,
71
+ chainId: options.chainId,
72
+ createClient,
73
+ http,
74
+ },
75
+ );
76
+ const policy = options.policy ?? {};
77
+ const session = tempo.session.manager({
78
+ ...policy,
79
+ ...options.session,
80
+ ...walletParameters,
81
+ });
82
+ const method = tempo({
83
+ ...policy,
84
+ ...options.mercator,
85
+ ...walletParameters,
86
+ });
87
+ const paymentPolicy = options.payment ?? {};
88
+ const approvePayment = paymentApproval(paymentPolicy);
89
+ const payment = {
90
+ methods: [method],
91
+ ...(approvePayment ? { onPaymentRequired: approvePayment } : {}),
92
+ };
93
+ const fetch = (input, init, requestPolicy) => {
94
+ const requestApproval = paymentApproval({
95
+ ...paymentPolicy,
96
+ ...(requestPolicy?.maxAmount === undefined
97
+ ? {}
98
+ : { maxAmount: requestPolicy.maxAmount }),
99
+ });
100
+ const mppx = Mppx.create({
101
+ methods: [method],
102
+ polyfill: false,
103
+ ...(paymentPolicy.fetch ? { fetch: paymentPolicy.fetch } : {}),
104
+ ...(requestPolicy?.intent
105
+ ? {
106
+ orderChallenges(candidates) {
107
+ return [...candidates].sort((left, right) =>
108
+ Number(right.challenge.intent === requestPolicy.intent)
109
+ - Number(left.challenge.intent === requestPolicy.intent));
110
+ },
111
+ }
112
+ : {}),
113
+ ...(requestApproval
114
+ ? {
115
+ async onChallenge(challenge, { createCredential }) {
116
+ if (!(await requestApproval(challenge))) {
117
+ throw new Error("MPP payment declined by Nanocodex policy.");
118
+ }
119
+ return createCredential();
120
+ },
121
+ }
122
+ : {}),
123
+ });
124
+ return mppx.fetch(input, init);
125
+ };
126
+ return createTempoProvider({
127
+ session,
128
+ payment,
129
+ fetch,
130
+ });
131
+ }
132
+
133
+ /** @internal */
134
+ export async function pinnedScopedAccountParameters(wallet, parameters, accessKey, clientFactory) {
135
+ const getAccessKey = wallet?.store?.accessKeys?.get;
136
+ if (accessKey === undefined || typeof getAccessKey !== "function") return parameters;
137
+
138
+ const state = wallet.store.getState?.();
139
+ const rootAccount = clientFactory.account
140
+ ?? wallet.getAccount?.()?.address
141
+ ?? state?.accounts?.[state.activeAccount ?? 0]?.address;
142
+ const chainId = Number(clientFactory.chainId ?? state?.chainId ?? 4217);
143
+ if (typeof rootAccount !== "string") {
144
+ throw new Error("The connected Accounts root address is unavailable.");
145
+ }
146
+ const pinnedAccount = await getAccessKey.call(wallet.store.accessKeys, {
147
+ account: rootAccount,
148
+ accessKey,
149
+ chainId,
150
+ });
151
+ const expected = accessKey.toLowerCase();
152
+ if (!pinnedAccount || pinnedAccount.accessKeyAddress?.toLowerCase() !== expected) {
153
+ throw new Error(`Pinned access key "${accessKey}" is not available in the Accounts keystore.`);
154
+ }
155
+
156
+ const clients = new Map();
157
+
158
+ return {
159
+ ...parameters,
160
+ getClient(info = {}) {
161
+ const source = parameters.getClient(info);
162
+ const requestedChainId = Number(info.chainId ?? source?.chain?.id ?? chainId);
163
+ if (requestedChainId !== chainId) {
164
+ throw new Error(
165
+ `Pinned access key "${accessKey}" is authorized for chain ${chainId}, not ${requestedChainId}.`,
166
+ );
167
+ }
168
+ let client = clients.get(requestedChainId);
169
+ if (client) return client;
170
+
171
+ const rpcUrl = source?.chain?.rpcUrls?.default?.http?.[0];
172
+ if (typeof rpcUrl !== "string") {
173
+ throw new Error(`No direct Tempo RPC URL is configured for chain ${requestedChainId}.`);
174
+ }
175
+ // The Accounts client routes JSON-RPC back through the wallet provider.
176
+ // That transport may auto-select a different valid access key while
177
+ // filling a transaction. Use the chain's direct RPC transport here, but
178
+ // keep reads rooted at the payer account. Setting the client account to
179
+ // the unpublished access key makes viem encode eth_call as a keychain
180
+ // call before the first payment transaction has attached its pending
181
+ // keyAuthorization, so even balanceOf fails with KeyNotFound. MPPx passes
182
+ // the exact local pinnedAccount returned by resolveAccount when it
183
+ // prepares and signs the mutating channel transaction; that is the point
184
+ // where viem attaches and consumes the pending authorization.
185
+ client = clientFactory.createClient({
186
+ account: { address: rootAccount, type: "json-rpc" },
187
+ chain: source.chain,
188
+ transport: clientFactory.http(rpcUrl),
189
+ });
190
+ clients.set(requestedChainId, client);
191
+ return client;
192
+ },
193
+ async resolveAccount(info) {
194
+ const authority = info?.operation?.kind === "authorizePaymentChannel"
195
+ ? info.operation.authority?.toLowerCase()
196
+ : undefined;
197
+ if (authority !== undefined && authority !== expected) {
198
+ throw new Error(
199
+ `MPP channel authority "${info.operation.authority}" does not match pinned access key "${accessKey}".`,
200
+ );
201
+ }
202
+
203
+ // Accounts may have several valid delegated keys for the same Tempo
204
+ // account. Its generic resolver is allowed to choose any key whose
205
+ // scopes cover a transaction, but an MPP channel is bound to one exact
206
+ // authority. Load that signer directly so channel top-ups and closes
207
+ // can never drift to a newer matching key.
208
+ if (info.chainId !== chainId) {
209
+ throw new Error(
210
+ `Pinned access key "${accessKey}" is authorized for chain ${chainId}, not ${info.chainId}.`,
211
+ );
212
+ }
213
+ if (info.account.address.toLowerCase() !== rootAccount.toLowerCase()) {
214
+ throw new Error(
215
+ `Pinned access key "${accessKey}" cannot sign for account "${info.account.address}".`,
216
+ );
217
+ }
218
+ return pinnedAccount;
219
+ },
220
+ };
221
+ }
222
+
223
+ function paymentApproval(policy) {
224
+ const hasMaximum = policy.maxAmount !== undefined;
225
+ const approve = policy.onPaymentRequired;
226
+ if (!hasMaximum && typeof approve !== "function") return undefined;
227
+ const maximum = hasMaximum ? nonNegativeBigInt(policy.maxAmount, "payment.maxAmount") : undefined;
228
+ return async (challenge) => {
229
+ if (maximum !== undefined) {
230
+ const amount = challenge?.request?.amount;
231
+ if (typeof amount !== "string" || !/^\d+$/.test(amount)) {
232
+ throw new Error("MPP payment challenge has no valid atomic amount.");
233
+ }
234
+ if (BigInt(amount) > maximum) {
235
+ throw new Error(
236
+ `MPP payment amount ${amount} exceeds the per-request limit ${maximum}.`,
237
+ );
238
+ }
239
+ }
240
+ return typeof approve === "function" ? approve(challenge) : true;
241
+ };
242
+ }
243
+
244
+ function nonNegativeBigInt(value, name) {
245
+ let parsed;
246
+ try {
247
+ parsed = BigInt(value);
248
+ } catch (error) {
249
+ throw new TypeError(`${name} must be an atomic integer`, { cause: error });
250
+ }
251
+ if (parsed < 0n) throw new TypeError(`${name} must not be negative`);
252
+ return parsed;
253
+ }
254
+
255
+ /** @internal */
256
+ export function resolveMcpServers(provider, configured) {
257
+ if (configured === false) return undefined;
258
+ const defaults = provider?.[tempoMcp];
259
+ if (!defaults) return configured;
260
+ return {
261
+ ...defaults,
262
+ ...configured,
263
+ };
264
+ }
@@ -0,0 +1 @@
1
+ export * from "../../nanocodex-tools/runtime/tool-configuration.mjs";
@@ -0,0 +1 @@
1
+ export * from "../../nanocodex-tools/runtime/tool-router.mjs";
@@ -0,0 +1 @@
1
+ export * from "../../nanocodex-tools/runtime/utf8.mjs";
@@ -0,0 +1,162 @@
1
+ const WORKER_PROTOCOL = "nanocodex.code-evaluator.v1";
2
+ let nextEvaluation = 1;
3
+
4
+ /** Creates the browser's per-cell, synchronously terminable Code Mode boundary. */
5
+ export function createWorkerEvaluator(options = {}) {
6
+ const createWorker = options.createWorker ?? createCodeEvaluatorWorker;
7
+ if (options.createWorker === undefined && typeof globalThis.Worker !== "function") {
8
+ throw new TypeError("browser Code Mode isolation requires Worker");
9
+ }
10
+ if (typeof createWorker !== "function") {
11
+ throw new TypeError("browser Code Mode isolation requires a Worker factory");
12
+ }
13
+
14
+ return (source, environment) => new Promise((resolve, reject) => {
15
+ environment.signal?.throwIfAborted();
16
+ const worker = createWorker();
17
+ const evaluationId = nextEvaluation++;
18
+ let closed = false;
19
+
20
+ const close = () => {
21
+ if (closed) return false;
22
+ closed = true;
23
+ environment.signal?.removeEventListener("abort", onAbort);
24
+ worker.onmessage = null;
25
+ worker.onerror = null;
26
+ worker.onmessageerror = null;
27
+ worker.terminate();
28
+ return true;
29
+ };
30
+ const fail = (error) => {
31
+ if (!close()) return;
32
+ reject(error instanceof Error ? error : new Error(String(error)));
33
+ };
34
+ const onAbort = () => {
35
+ const reason = environment.signal?.reason ?? new Error("Code Mode execution was cancelled");
36
+ // AbortSignal dispatch is synchronous. Let every parent-held nested tool
37
+ // observe cancellation before terminating its guest evaluator boundary.
38
+ queueMicrotask(() => fail(reason));
39
+ };
40
+
41
+ worker.onmessage = ({ data }) => {
42
+ if (closed || data?.protocol !== WORKER_PROTOCOL || data.evaluationId !== evaluationId) return;
43
+ if (data.type === "tool.call") {
44
+ const tool = environment.tools[data.name];
45
+ Promise.resolve().then(() => {
46
+ if (typeof tool !== "function") {
47
+ throw new Error(`unknown application tool: ${data.name}`);
48
+ }
49
+ return tool(data.input);
50
+ }).then(
51
+ (value) => postToolResult(worker, evaluationId, data.id, true, value, () => closed),
52
+ (error) => postToolResult(
53
+ worker,
54
+ evaluationId,
55
+ data.id,
56
+ false,
57
+ cloneableError(error),
58
+ () => closed,
59
+ ),
60
+ );
61
+ return;
62
+ }
63
+ if (data.type === "output") {
64
+ try {
65
+ if (data.kind === "text") environment.text(data.value);
66
+ else if (data.kind === "image") environment.image(data.value, data.detail);
67
+ else if (data.kind === "audio") environment.audio(data.value);
68
+ else if (data.kind === "notify") environment.notify(data.value);
69
+ else if (data.kind === "yield_control") environment.yield_control();
70
+ else if (data.kind === "generatedImage") environment.generatedImage(data.value);
71
+ else throw new Error(`unknown Code Mode output kind: ${data.kind}`);
72
+ } catch (error) {
73
+ fail(error);
74
+ }
75
+ return;
76
+ }
77
+ if (data.type === "console") {
78
+ const logger = typeof environment.console?.[data.level] === "function"
79
+ ? environment.console[data.level]
80
+ : environment.console?.log;
81
+ logger?.(...data.values);
82
+ return;
83
+ }
84
+ if (data.type !== "completed" && data.type !== "failed") {
85
+ fail(new Error(`unknown Code Mode evaluator message: ${data.type}`));
86
+ return;
87
+ }
88
+ try {
89
+ for (const [key, value] of data.storedWrites ?? []) environment.store(key, value);
90
+ } catch (error) {
91
+ fail(error);
92
+ return;
93
+ }
94
+ if (!close()) return;
95
+ if (data.type === "completed") resolve();
96
+ else reject(new Error(data.error || "Code Mode evaluator failed"));
97
+ };
98
+ worker.onerror = (event) => fail(new Error(event?.message || "Code Mode evaluator Worker failed"));
99
+ worker.onmessageerror = () => fail(new Error("Code Mode evaluator Worker returned unreadable data"));
100
+ environment.signal?.addEventListener("abort", onAbort, { once: true });
101
+ try {
102
+ worker.postMessage({
103
+ protocol: WORKER_PROTOCOL,
104
+ evaluationId,
105
+ egress: options.egress,
106
+ type: "evaluate",
107
+ source,
108
+ storedEntries: environment.storedEntries,
109
+ toolDefinitions: environment.toolDefinitions,
110
+ toolNames: Object.keys(environment.tools),
111
+ });
112
+ } catch (error) {
113
+ fail(error);
114
+ }
115
+ });
116
+ }
117
+
118
+ // Vite recognizes only this literal Worker + URL shape as a worker entry. Keep
119
+ // the test factory above out of the production construction path so the
120
+ // evaluator and its imports are emitted as one runnable browser asset.
121
+ function createCodeEvaluatorWorker() {
122
+ return new Worker(
123
+ new URL("./code-evaluator.worker.mjs", import.meta.url),
124
+ { name: "nanocodex-code-evaluator", type: "module" },
125
+ );
126
+ }
127
+
128
+ function postToolResult(worker, evaluationId, id, ok, value, isClosed) {
129
+ if (isClosed()) return;
130
+ try {
131
+ worker.postMessage({
132
+ protocol: WORKER_PROTOCOL,
133
+ evaluationId,
134
+ type: "tool.result",
135
+ id,
136
+ ok,
137
+ value,
138
+ });
139
+ } catch (error) {
140
+ worker.postMessage({
141
+ protocol: WORKER_PROTOCOL,
142
+ evaluationId,
143
+ type: "tool.result",
144
+ id,
145
+ ok: false,
146
+ value: `tool result could not cross the evaluator Worker boundary: ${errorMessage(error)}`,
147
+ });
148
+ }
149
+ }
150
+
151
+ function cloneableError(error) {
152
+ try {
153
+ structuredClone(error);
154
+ return error;
155
+ } catch {
156
+ return errorMessage(error);
157
+ }
158
+ }
159
+
160
+ function errorMessage(error) {
161
+ return error && (error.stack || error.message) ? error.stack || error.message : String(error);
162
+ }
@@ -0,0 +1 @@
1
+ export * from "../../nanocodex-tools/tools/workspace.d.mts";
@@ -0,0 +1 @@
1
+ export * from "../../nanocodex-tools/tools/workspace.mjs";
@@ -0,0 +1,56 @@
1
+ import type { McpServers, NamedTool, ToolMap } from "../types.mjs";
2
+ import type { Workspace } from "../runtime/workspace.mjs";
3
+ import type { HostedMachine } from "./hostedCatalog.mjs";
4
+
5
+ declare const toolsBrand: unique symbol;
6
+
7
+ export type AttachmentSocket = {
8
+ readonly readyState: number;
9
+ send(data: string): void;
10
+ close(code?: number, reason?: string): void;
11
+ addEventListener?(type: string, listener: (event: any) => void, options?: unknown): void;
12
+ on?(type: string, listener: (...args: any[]) => void): void;
13
+ };
14
+
15
+ export type AttachmentTransport = Readonly<{
16
+ connect(target: string | URL): AttachmentSocket | Promise<AttachmentSocket>;
17
+ }>;
18
+
19
+ export type AttachmentTarget = string | URL | Readonly<{
20
+ endpoint: string | URL;
21
+ transport: AttachmentTransport;
22
+ }>;
23
+
24
+ export type AttachmentClient = Readonly<{
25
+ readonly connected: boolean;
26
+ closed(): Promise<void>;
27
+ close(): Promise<void>;
28
+ }>;
29
+
30
+ export type Tools = Readonly<{
31
+ readonly [toolsBrand]: true;
32
+ attach(target: AttachmentTarget): Readonly<{
33
+ connect(): Promise<AttachmentClient>;
34
+ closed(): Promise<void>;
35
+ close(): Promise<void>;
36
+ }>;
37
+ close(): Promise<void>;
38
+ }>;
39
+
40
+ /**
41
+ * Creates one owned tool runtime. Caller-supplied tool ownership transfers only
42
+ * after this promise resolves; a rejected construction leaves those tools with
43
+ * the caller. The returned runtime joins all owned cleanup through close().
44
+ */
45
+ export function createTools(options?: {
46
+ tools?: ToolMap | readonly NamedTool[];
47
+ /** Stable safe ASCII identifier (at most 123 bytes) for this independent attachment. */
48
+ attachmentId?: string;
49
+ /** Sole non-secret machine published by this host; its id must equal attachmentId. */
50
+ machines?: readonly HostedMachine[];
51
+ /** Portable workspace handle; React Native supplies one via createWorkspace({ backend }). */
52
+ workspace?: Workspace;
53
+ workspaceOptions?: { maxEntries?: number; maxReadBytes?: number; maxWriteBytes?: number };
54
+ mcp?: McpServers | false;
55
+ mcpOptions?: Readonly<Record<string, unknown>>;
56
+ }): Promise<Tools>;
@@ -0,0 +1,136 @@
1
+ import { resolveTools } from "../runtime/tool-configuration.mjs";
2
+ import { tools as workspaceTools } from "../runtime/workspace.mjs";
3
+ import {
4
+ providerSource,
5
+ settleCleanup,
6
+ ToolRouter,
7
+ toolMapSource,
8
+ toolRouterBrand,
9
+ toolRouterRuntime,
10
+ toolRuntimeLifecycle,
11
+ } from "../runtime/tool-router.mjs";
12
+ import { createAttachment } from "./attachment.mjs";
13
+ import { normalizeHostedMachines } from "../../nanocodex-tools/tools/hostedMachine.mjs";
14
+
15
+ /**
16
+ * Builds one language-neutral JavaScript-owned tool runtime.
17
+ * Empty custom tools, no workspace, and no MCP are the defaults.
18
+ */
19
+ export async function createTools(options = {}) {
20
+ validateOptions(options);
21
+ const machines = normalizeHostedMachines(options.machines);
22
+ const attachmentId = options.attachmentId;
23
+ if (machines.length > 0 && attachmentId !== machines[0].id) {
24
+ throw new TypeError("createTools machine attachment requires one machine whose id equals attachmentId");
25
+ }
26
+ const router = new ToolRouter();
27
+ const resolved = resolveTools(
28
+ options.tools === undefined ? {} : options.tools,
29
+ { defaultSubagents: false },
30
+ );
31
+ if (resolved.subagents) throw new TypeError("createTools does not accept agent-relative extensions");
32
+ const custom = resolved.tools;
33
+ let mcp;
34
+ try {
35
+ if (Object.keys(custom).length) {
36
+ router.addSource(toolMapSource("custom", custom, { kind: "cloud" }));
37
+ }
38
+ if (options.workspace !== undefined) {
39
+ router.addSource(toolMapSource(
40
+ "workspace",
41
+ workspaceTools(options.workspace, options.workspaceOptions),
42
+ { kind: "cloud" },
43
+ ));
44
+ }
45
+ if (options.mcp !== undefined && options.mcp !== false) {
46
+ const { createMcpRuntime } = await import("../runtime/mcp-runtime.mjs");
47
+ mcp = await createMcpRuntime(options.mcp, options.mcpOptions);
48
+ router.addSource(providerSource("mcp", mcp, { kind: "mcp" }));
49
+ }
50
+ } catch (error) {
51
+ if (!mcp) throw error;
52
+ try { await mcp.close(); }
53
+ catch (cleanupError) {
54
+ throw new AggregateError(
55
+ [error, cleanupError],
56
+ "Tools construction and MCP cleanup failed",
57
+ );
58
+ }
59
+ throw error;
60
+ }
61
+ const attachments = new Set();
62
+ let closed = false;
63
+ let closing;
64
+ let claimed = false;
65
+ let owner;
66
+ const lifecycle = Object.freeze({
67
+ available() {
68
+ if (closed) throw new Error("Tools runtime is closed");
69
+ if (claimed) throw new Error("Tools runtime already belongs to an Agent host");
70
+ },
71
+ claim() {
72
+ this.available();
73
+ claimed = true;
74
+ },
75
+ close() { return owner.close(); },
76
+ });
77
+ owner = {
78
+ [toolRouterBrand]: true,
79
+ [toolRouterRuntime]: router,
80
+ [toolRuntimeLifecycle]: lifecycle,
81
+ attach(target) {
82
+ if (closed) throw new Error("Tools runtime is closed");
83
+ if (arguments.length !== 1) throw new TypeError("Tools.attach accepts only a target");
84
+ const attachment = createAttachment(owner, target, { machines, attachmentId });
85
+ attachments.add(attachment);
86
+ void attachment.closed().then(() => attachments.delete(attachment));
87
+ return attachment;
88
+ },
89
+ close() {
90
+ if (closing) return closing;
91
+ closed = true;
92
+ const ownedAttachments = [...attachments];
93
+ attachments.clear();
94
+ closing = Promise.resolve().then(async () => {
95
+ const errors = [];
96
+ try {
97
+ await settleCleanup(
98
+ ownedAttachments.map((attachment) => () => attachment.close()),
99
+ "tool attachment cleanup failed",
100
+ );
101
+ } catch (error) {
102
+ errors.push(...cleanupErrors(error));
103
+ }
104
+ try { await router.reset(closing); }
105
+ catch (error) { errors.push(...cleanupErrors(error)); }
106
+ if (errors.length === 1) throw errors[0];
107
+ if (errors.length > 1) throw new AggregateError(errors, "Tools cleanup failed");
108
+ });
109
+ return closing;
110
+ },
111
+ };
112
+ return Object.freeze(owner);
113
+ }
114
+
115
+ function cleanupErrors(error) {
116
+ return error instanceof AggregateError ? error.errors : [error];
117
+ }
118
+
119
+ function validateOptions(options) {
120
+ if (!options || typeof options !== "object" || Array.isArray(options)) {
121
+ throw new TypeError("createTools options must be an object");
122
+ }
123
+ const allowed = new Set(["tools", "workspace", "workspaceOptions", "mcp", "mcpOptions", "machines", "attachmentId"]);
124
+ for (const name of Object.keys(options)) {
125
+ if (!allowed.has(name)) throw new TypeError(`unsupported createTools option: ${name}`);
126
+ }
127
+ if (options.attachmentId !== undefined && (typeof options.attachmentId !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,122}$/.test(options.attachmentId))) {
128
+ throw new TypeError("createTools attachmentId must be a safe identifier of at most 123 bytes");
129
+ }
130
+ if (options.workspace === undefined && options.workspaceOptions !== undefined) {
131
+ throw new TypeError("workspaceOptions requires workspace");
132
+ }
133
+ if ((options.mcp === undefined || options.mcp === false) && options.mcpOptions !== undefined) {
134
+ throw new TypeError("mcpOptions requires mcp");
135
+ }
136
+ }
@@ -0,0 +1 @@
1
+ export * from "../../nanocodex-tools/tools/artifact.d.mts";
@@ -0,0 +1 @@
1
+ export * from "../../nanocodex-tools/tools/artifact.mjs";
@@ -0,0 +1 @@
1
+ export * from "../../nanocodex-tools/tools/attachment.mjs";
@@ -0,0 +1 @@
1
+ export * from "../../nanocodex-tools/tools/bash.d.mts";
@@ -0,0 +1 @@
1
+ export * from "../../nanocodex-tools/tools/bash.mjs";