@agentorg/cli 0.0.5 → 0.0.7

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 (260) hide show
  1. package/README.md +23 -104
  2. package/dist/node_modules/@agentorg/computer/LICENSE +201 -0
  3. package/dist/node_modules/@agentorg/computer/NOTICE +2 -0
  4. package/dist/node_modules/@agentorg/computer/dist/THIRD_PARTY_LICENSES.txt +1321 -0
  5. package/dist/node_modules/@agentorg/computer/dist/sdk.js +24909 -0
  6. package/dist/node_modules/@agentorg/computer/dist/types/generated/schema.d.ts +860 -0
  7. package/dist/node_modules/@agentorg/computer/dist/types/sdk.d.ts +242 -0
  8. package/dist/node_modules/@agentorg/computer/package.json +12 -0
  9. package/dist/node_modules/@agentorg/computer-connector/dist/src/index.d.ts +1 -0
  10. package/dist/node_modules/@agentorg/computer-connector/dist/src/index.js +1 -0
  11. package/dist/node_modules/@agentorg/computer-connector/dist/src/provider.d.ts +24 -0
  12. package/dist/node_modules/@agentorg/computer-connector/dist/src/provider.js +482 -0
  13. package/dist/node_modules/@agentorg/computer-connector/dist/src/unit.d.ts +19 -0
  14. package/dist/node_modules/@agentorg/computer-connector/dist/src/unit.js +149 -0
  15. package/dist/node_modules/@agentorg/computer-connector/package.json +33 -0
  16. package/dist/node_modules/@agentorg/computer-connector/skills/browser/SKILL.md +31 -0
  17. package/dist/node_modules/@agentorg/computer-connector/skills/computer/SKILL.md +30 -0
  18. package/dist/node_modules/@agentorg/computer-connector/skills/files/SKILL.md +28 -0
  19. package/dist/node_modules/@agentorg/computer-connector/skills/terminal/SKILL.md +39 -0
  20. package/dist/node_modules/@agentorg/computer-connector/skills/web-research/SKILL.md +29 -0
  21. package/dist/node_modules/@agentorg/hub/dist/src/hub-actor.d.ts +2 -7
  22. package/dist/node_modules/@agentorg/hub/dist/src/hub-actor.js +4 -144
  23. package/dist/node_modules/@agentorg/hub/dist/src/index.d.ts +1 -3
  24. package/dist/node_modules/@agentorg/hub/dist/src/index.js +1 -3
  25. package/dist/node_modules/@agentorg/hub/dist/src/router.d.ts +9 -58
  26. package/dist/node_modules/@agentorg/hub/dist/src/router.js +41 -414
  27. package/dist/node_modules/@agentorg/hub/dist/src/state.d.ts +17 -317
  28. package/dist/node_modules/@agentorg/hub/dist/src/state.js +42 -536
  29. package/dist/node_modules/@agentorg/hub/dist/src/validate.d.ts +1 -3
  30. package/dist/node_modules/@agentorg/hub/dist/src/validate.js +19 -17
  31. package/dist/node_modules/@agentorg/hub/package.json +0 -3
  32. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-provider.d.ts +119 -0
  33. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-provider.js +96 -0
  34. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-settings.d.ts +42 -0
  35. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-settings.js +53 -0
  36. package/dist/node_modules/@agentorg/interfaces/dist/src/chat.d.ts +93 -38
  37. package/dist/node_modules/@agentorg/interfaces/dist/src/chat.js +71 -22
  38. package/dist/node_modules/@agentorg/interfaces/dist/src/connection.d.ts +36 -0
  39. package/dist/node_modules/@agentorg/interfaces/dist/src/connection.js +31 -0
  40. package/dist/node_modules/@agentorg/interfaces/dist/src/folders.d.ts +19 -0
  41. package/dist/node_modules/@agentorg/interfaces/dist/src/folders.js +25 -0
  42. package/dist/node_modules/@agentorg/interfaces/dist/src/hub.d.ts +16 -286
  43. package/dist/node_modules/@agentorg/interfaces/dist/src/hub.js +17 -159
  44. package/dist/node_modules/@agentorg/interfaces/dist/src/index.d.ts +9 -9
  45. package/dist/node_modules/@agentorg/interfaces/dist/src/index.js +9 -9
  46. package/dist/node_modules/@agentorg/interfaces/dist/src/kv.d.ts +2 -2
  47. package/dist/node_modules/@agentorg/interfaces/dist/src/kv.js +2 -2
  48. package/dist/node_modules/@agentorg/interfaces/dist/src/llm-session.d.ts +2 -0
  49. package/dist/node_modules/@agentorg/interfaces/dist/src/llm-session.js +2 -1
  50. package/dist/node_modules/@agentorg/interfaces/dist/src/manager.d.ts +626 -0
  51. package/dist/node_modules/@agentorg/interfaces/dist/src/manager.js +349 -0
  52. package/dist/node_modules/@agentorg/interfaces/dist/src/tools.d.ts +39 -0
  53. package/dist/node_modules/@agentorg/interfaces/dist/src/tools.js +43 -0
  54. package/dist/node_modules/@agentorg/interfaces/dist/src/units.d.ts +460 -0
  55. package/dist/node_modules/@agentorg/interfaces/dist/src/units.js +204 -0
  56. package/dist/node_modules/@agentorg/looper/dist/src/index.d.ts +5 -0
  57. package/dist/node_modules/@agentorg/looper/dist/src/index.js +5 -0
  58. package/dist/node_modules/@agentorg/looper/dist/src/loop.d.ts +75 -0
  59. package/dist/node_modules/@agentorg/looper/dist/src/loop.js +332 -0
  60. package/dist/node_modules/@agentorg/looper/dist/src/looper.d.ts +71 -0
  61. package/dist/node_modules/@agentorg/looper/dist/src/looper.js +282 -0
  62. package/dist/node_modules/@agentorg/looper/dist/src/record.d.ts +99 -0
  63. package/dist/node_modules/@agentorg/looper/dist/src/record.js +278 -0
  64. package/dist/node_modules/@agentorg/looper/dist/src/tools.d.ts +11 -0
  65. package/dist/node_modules/@agentorg/looper/dist/src/tools.js +42 -0
  66. package/dist/node_modules/@agentorg/looper/dist/src/types.d.ts +147 -0
  67. package/dist/node_modules/@agentorg/looper/dist/src/types.js +32 -0
  68. package/dist/node_modules/@agentorg/looper/package.json +24 -0
  69. package/dist/node_modules/@agentorg/manager/dist/src/activity.d.ts +18 -0
  70. package/dist/node_modules/@agentorg/manager/dist/src/activity.js +65 -0
  71. package/dist/node_modules/@agentorg/manager/dist/src/control.d.ts +134 -0
  72. package/dist/node_modules/@agentorg/manager/dist/src/control.js +1115 -0
  73. package/dist/node_modules/@agentorg/manager/dist/src/form.d.ts +40 -0
  74. package/dist/node_modules/@agentorg/manager/dist/src/form.js +191 -0
  75. package/dist/node_modules/@agentorg/manager/dist/src/index.d.ts +1 -0
  76. package/dist/node_modules/@agentorg/manager/dist/src/index.js +1 -0
  77. package/dist/node_modules/@agentorg/manager/dist/src/manager.d.ts +25 -0
  78. package/dist/node_modules/@agentorg/manager/dist/src/manager.js +680 -0
  79. package/dist/node_modules/@agentorg/manager/dist/src/skills.d.ts +27 -0
  80. package/dist/node_modules/@agentorg/manager/dist/src/skills.js +152 -0
  81. package/dist/node_modules/@agentorg/manager/dist/src/stack.d.ts +454 -0
  82. package/dist/node_modules/@agentorg/manager/dist/src/stack.js +917 -0
  83. package/dist/node_modules/@agentorg/manager/package.json +30 -0
  84. package/dist/node_modules/@agentorg/mcp/dist/src/connection.d.ts +34 -0
  85. package/dist/node_modules/@agentorg/mcp/dist/src/connection.js +296 -0
  86. package/dist/node_modules/@agentorg/mcp/dist/src/index.d.ts +4 -0
  87. package/dist/node_modules/@agentorg/mcp/dist/src/index.js +4 -0
  88. package/dist/node_modules/@agentorg/mcp/dist/src/kinds.d.ts +158 -0
  89. package/dist/node_modules/@agentorg/mcp/dist/src/kinds.js +164 -0
  90. package/dist/node_modules/@agentorg/mcp/dist/src/provider.d.ts +22 -0
  91. package/dist/node_modules/@agentorg/mcp/dist/src/provider.js +197 -0
  92. package/dist/node_modules/@agentorg/mcp/dist/src/public.d.ts +6 -0
  93. package/dist/node_modules/@agentorg/mcp/dist/src/public.js +72 -0
  94. package/dist/node_modules/@agentorg/mcp/package.json +31 -0
  95. package/dist/node_modules/@agentorg/sdk/dist/src/cli.js +3 -23
  96. package/dist/node_modules/@agentorg/sdk/dist/src/client.d.ts +4 -25
  97. package/dist/node_modules/@agentorg/sdk/dist/src/client.js +5 -55
  98. package/dist/node_modules/@agentorg/sdk/dist/src/errors.d.ts +1 -1
  99. package/dist/node_modules/@agentorg/sdk/dist/src/errors.js +3 -3
  100. package/dist/node_modules/@agentorg/sdk/dist/src/filled.d.ts +21 -0
  101. package/dist/node_modules/@agentorg/sdk/dist/src/filled.js +24 -0
  102. package/dist/node_modules/@agentorg/sdk/dist/src/index.d.ts +3 -2
  103. package/dist/node_modules/@agentorg/sdk/dist/src/index.js +2 -1
  104. package/dist/node_modules/@agentorg/sdk/dist/src/interface.d.ts +6 -34
  105. package/dist/node_modules/@agentorg/sdk/dist/src/interface.js +3 -24
  106. package/dist/node_modules/@agentorg/sdk/dist/src/module-host.d.ts +8 -17
  107. package/dist/node_modules/@agentorg/sdk/dist/src/module-host.js +15 -87
  108. package/dist/node_modules/@agentorg/sdk/dist/src/module.d.ts +10 -76
  109. package/dist/node_modules/@agentorg/sdk/dist/src/module.js +3 -23
  110. package/dist/node_modules/@agentorg/sdk/dist/src/person-commands.js +0 -5
  111. package/dist/node_modules/@agentorg/sdk/dist/src/runtime.d.ts +3 -27
  112. package/dist/node_modules/@agentorg/sdk/dist/src/runtime.js +5 -100
  113. package/dist/node_modules/@agentorg/sdk/dist/src/testing.d.ts +7 -8
  114. package/dist/node_modules/@agentorg/sdk/dist/src/testing.js +12 -24
  115. package/dist/node_modules/@agentorg/sdk/package.json +4 -37
  116. package/dist/node_modules/@agentorg/shell/dist/app.css +4624 -739
  117. package/dist/node_modules/@agentorg/shell/dist/app.js +245 -202
  118. package/dist/node_modules/@agentorg/shell/package.json +23 -10
  119. package/dist/node_modules/@agentorg/wire/dist/src/frames.d.ts +2 -3
  120. package/dist/node_modules/@agentorg/wire/dist/src/frames.js +2 -3
  121. package/dist/node_modules/@agentorg/wire/dist/src/ops.d.ts +5 -34
  122. package/dist/node_modules/@agentorg/wire/dist/src/ops.js +2 -17
  123. package/dist/node_modules/assistant/dist/src/chats.d.ts +92 -0
  124. package/dist/node_modules/assistant/dist/src/chats.js +357 -0
  125. package/dist/node_modules/assistant/dist/src/engine.d.ts +42 -0
  126. package/dist/node_modules/assistant/dist/src/engine.js +160 -0
  127. package/dist/node_modules/assistant/dist/src/local-store.d.ts +3 -0
  128. package/dist/node_modules/assistant/dist/src/local-store.js +58 -0
  129. package/dist/node_modules/assistant/dist/src/provider.d.ts +21 -0
  130. package/dist/node_modules/assistant/dist/src/provider.js +259 -0
  131. package/dist/node_modules/assistant/dist/src/settings.d.ts +17 -0
  132. package/dist/node_modules/assistant/dist/src/settings.js +43 -0
  133. package/dist/node_modules/assistant/dist/src/tools.d.ts +57 -0
  134. package/dist/node_modules/assistant/dist/src/tools.js +102 -0
  135. package/dist/node_modules/assistant/package.json +30 -0
  136. package/dist/node_modules/chatgpt/dist/src/account.d.ts +52 -0
  137. package/dist/node_modules/chatgpt/dist/src/account.js +270 -0
  138. package/dist/node_modules/chatgpt/dist/src/encoding.d.ts +7 -0
  139. package/dist/node_modules/chatgpt/dist/src/encoding.js +20 -0
  140. package/dist/node_modules/chatgpt/dist/src/file-store.d.ts +9 -0
  141. package/dist/node_modules/chatgpt/dist/src/file-store.js +68 -0
  142. package/dist/node_modules/chatgpt/dist/src/index.d.ts +1 -0
  143. package/dist/node_modules/chatgpt/dist/src/index.js +1 -0
  144. package/dist/node_modules/chatgpt/dist/src/jwt.d.ts +15 -0
  145. package/dist/node_modules/chatgpt/dist/src/jwt.js +37 -0
  146. package/dist/node_modules/chatgpt/dist/src/oauth.d.ts +43 -0
  147. package/dist/node_modules/chatgpt/dist/src/oauth.js +104 -0
  148. package/dist/node_modules/chatgpt/dist/src/program.d.ts +23 -0
  149. package/dist/node_modules/chatgpt/dist/src/program.js +41 -0
  150. package/dist/node_modules/chatgpt/dist/src/responses.d.ts +54 -0
  151. package/dist/node_modules/chatgpt/dist/src/responses.js +300 -0
  152. package/dist/node_modules/chatgpt/dist/src/serve.d.ts +65 -0
  153. package/dist/node_modules/chatgpt/dist/src/serve.js +46 -0
  154. package/dist/node_modules/chatgpt/package.json +33 -0
  155. package/dist/src/api.d.ts +5 -34
  156. package/dist/src/api.js +10 -68
  157. package/dist/src/cli.js +3 -7
  158. package/dist/src/folders.d.ts +2 -0
  159. package/dist/src/folders.js +45 -0
  160. package/dist/src/gateway.d.ts +13 -8
  161. package/dist/src/gateway.js +119 -296
  162. package/dist/src/index.d.ts +4 -5
  163. package/dist/src/index.js +3 -4
  164. package/dist/src/live.d.ts +17 -0
  165. package/dist/src/live.js +109 -0
  166. package/dist/src/notes.d.ts +11 -0
  167. package/dist/src/notes.js +64 -0
  168. package/dist/src/oauth.d.ts +16 -0
  169. package/dist/src/oauth.js +46 -0
  170. package/dist/src/programs.d.ts +36 -0
  171. package/dist/src/programs.js +198 -0
  172. package/dist/src/signin.d.ts +12 -3
  173. package/dist/src/signin.js +30 -6
  174. package/package.json +4 -11
  175. package/dist/bundled/index.json +0 -6
  176. package/dist/bundled/sha256-0e91cc3d0e9762b81abc2427b5496b20f383abcd6fb97d928a8d50e956b54d1f.agentorg +0 -0
  177. package/dist/bundled/sha256-1f64ca62a0209d767d6aa6c4feb50b0653d60f10bebbc301f79bd3a37e0153c1.agentorg +0 -0
  178. package/dist/bundled/sha256-4055f8fddf6b90f3d356543f554b2a9e9a2c4a8827a8774f8f87952dc1692331.agentorg +0 -0
  179. package/dist/bundled/sha256-e356ea3c1899138a8494baf521556831006f38534fa9e92ae873e7e6956c3a46.agentorg +0 -0
  180. package/dist/node_modules/@agentorg/hub/dist/src/build.d.ts +0 -17
  181. package/dist/node_modules/@agentorg/hub/dist/src/build.js +0 -120
  182. package/dist/node_modules/@agentorg/hub/dist/src/logs.d.ts +0 -33
  183. package/dist/node_modules/@agentorg/hub/dist/src/logs.js +0 -162
  184. package/dist/node_modules/@agentorg/hub/dist/src/net.d.ts +0 -41
  185. package/dist/node_modules/@agentorg/hub/dist/src/net.js +0 -265
  186. package/dist/node_modules/@agentorg/hub/dist/src/processes.d.ts +0 -78
  187. package/dist/node_modules/@agentorg/hub/dist/src/processes.js +0 -485
  188. package/dist/node_modules/@agentorg/hub/dist/src/storage.d.ts +0 -38
  189. package/dist/node_modules/@agentorg/hub/dist/src/storage.js +0 -194
  190. package/dist/node_modules/@agentorg/interfaces/dist/src/http-egress.d.ts +0 -6
  191. package/dist/node_modules/@agentorg/interfaces/dist/src/http-egress.js +0 -7
  192. package/dist/node_modules/@agentorg/interfaces/dist/src/installer.d.ts +0 -191
  193. package/dist/node_modules/@agentorg/interfaces/dist/src/installer.js +0 -136
  194. package/dist/node_modules/@agentorg/interfaces/dist/src/layout.d.ts +0 -47
  195. package/dist/node_modules/@agentorg/interfaces/dist/src/layout.js +0 -52
  196. package/dist/node_modules/@agentorg/interfaces/dist/src/rules.d.ts +0 -35
  197. package/dist/node_modules/@agentorg/interfaces/dist/src/rules.js +0 -37
  198. package/dist/node_modules/@agentorg/interfaces/dist/src/storage-admin.d.ts +0 -23
  199. package/dist/node_modules/@agentorg/interfaces/dist/src/storage-admin.js +0 -31
  200. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-shell.d.ts +0 -14
  201. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-shell.js +0 -26
  202. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-view.d.ts +0 -27
  203. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-view.js +0 -26
  204. package/dist/node_modules/@agentorg/kit/dist/src/chat.d.ts +0 -37
  205. package/dist/node_modules/@agentorg/kit/dist/src/chat.js +0 -131
  206. package/dist/node_modules/@agentorg/kit/dist/src/components.d.ts +0 -94
  207. package/dist/node_modules/@agentorg/kit/dist/src/components.js +0 -66
  208. package/dist/node_modules/@agentorg/kit/dist/src/icons.d.ts +0 -17
  209. package/dist/node_modules/@agentorg/kit/dist/src/icons.js +0 -30
  210. package/dist/node_modules/@agentorg/kit/dist/src/index.d.ts +0 -6
  211. package/dist/node_modules/@agentorg/kit/dist/src/index.js +0 -10
  212. package/dist/node_modules/@agentorg/kit/dist/src/markdown.d.ts +0 -9
  213. package/dist/node_modules/@agentorg/kit/dist/src/markdown.js +0 -14
  214. package/dist/node_modules/@agentorg/kit/dist/src/resizable.d.ts +0 -5
  215. package/dist/node_modules/@agentorg/kit/dist/src/resizable.js +0 -8
  216. package/dist/node_modules/@agentorg/kit/dist/src/styles.d.ts +0 -11
  217. package/dist/node_modules/@agentorg/kit/dist/src/styles.js +0 -166
  218. package/dist/node_modules/@agentorg/kit/package.json +0 -44
  219. package/dist/node_modules/@agentorg/sdk/dist/frame/runtime.js +0 -753
  220. package/dist/node_modules/@agentorg/sdk/dist/host/runner.js +0 -21963
  221. package/dist/node_modules/@agentorg/sdk/dist/src/build.d.ts +0 -2
  222. package/dist/node_modules/@agentorg/sdk/dist/src/build.js +0 -2
  223. package/dist/node_modules/@agentorg/sdk/dist/src/client-http.d.ts +0 -24
  224. package/dist/node_modules/@agentorg/sdk/dist/src/client-http.js +0 -247
  225. package/dist/node_modules/@agentorg/sdk/dist/src/describe.d.ts +0 -13
  226. package/dist/node_modules/@agentorg/sdk/dist/src/describe.js +0 -16
  227. package/dist/node_modules/@agentorg/sdk/dist/src/frame-base.d.ts +0 -8
  228. package/dist/node_modules/@agentorg/sdk/dist/src/frame-base.js +0 -64
  229. package/dist/node_modules/@agentorg/sdk/dist/src/frame-entry.d.ts +0 -1
  230. package/dist/node_modules/@agentorg/sdk/dist/src/frame-entry.js +0 -35
  231. package/dist/node_modules/@agentorg/sdk/dist/src/frame-host.d.ts +0 -57
  232. package/dist/node_modules/@agentorg/sdk/dist/src/frame-host.js +0 -293
  233. package/dist/node_modules/@agentorg/sdk/dist/src/frame-protocol.d.ts +0 -124
  234. package/dist/node_modules/@agentorg/sdk/dist/src/frame-protocol.js +0 -16
  235. package/dist/node_modules/@agentorg/sdk/dist/src/frame.d.ts +0 -25
  236. package/dist/node_modules/@agentorg/sdk/dist/src/frame.js +0 -248
  237. package/dist/node_modules/@agentorg/sdk/dist/src/host-main.d.ts +0 -1
  238. package/dist/node_modules/@agentorg/sdk/dist/src/host-main.js +0 -60
  239. package/dist/node_modules/@agentorg/sdk/dist/src/host.d.ts +0 -25
  240. package/dist/node_modules/@agentorg/sdk/dist/src/host.js +0 -92
  241. package/dist/node_modules/@agentorg/sdk/dist/src/manifest-api.d.ts +0 -2
  242. package/dist/node_modules/@agentorg/sdk/dist/src/manifest-api.js +0 -2
  243. package/dist/node_modules/@agentorg/sdk/dist/src/manifest.d.ts +0 -56
  244. package/dist/node_modules/@agentorg/sdk/dist/src/manifest.js +0 -165
  245. package/dist/node_modules/@agentorg/sdk/dist/src/package.d.ts +0 -60
  246. package/dist/node_modules/@agentorg/sdk/dist/src/package.js +0 -538
  247. package/dist/node_modules/@agentorg/sdk/dist/src/tar.d.ts +0 -7
  248. package/dist/node_modules/@agentorg/sdk/dist/src/tar.js +0 -71
  249. package/dist/node_modules/@agentorg/shell/dist/agent-bindings.js +0 -59
  250. package/dist/node_modules/@agentorg/shell/src/agent-bindings.ts +0 -107
  251. package/dist/src/frames.d.ts +0 -23
  252. package/dist/src/frames.js +0 -78
  253. package/dist/src/layout.d.ts +0 -44
  254. package/dist/src/layout.js +0 -90
  255. package/dist/src/model.d.ts +0 -54
  256. package/dist/src/model.js +0 -299
  257. package/dist/src/rules.d.ts +0 -71
  258. package/dist/src/rules.js +0 -157
  259. package/dist/src/transfer.d.ts +0 -30
  260. package/dist/src/transfer.js +0 -110
package/dist/src/model.js DELETED
@@ -1,299 +0,0 @@
1
- // The app's first run: the bundled packages, the installer the person bootstraps, the model Actor
2
- // installed through it, and the person's `login` bound to that model. Every step reads what is
3
- // there before it acts, so each start converges on the same system and makes nothing twice.
4
- import { readFileSync } from "node:fs";
5
- import { dirname, join } from "node:path";
6
- import { fileURLToPath } from "node:url";
7
- /** The app's bundled packages, built into `dist/bundled` with the app. */
8
- const BUNDLED = join(dirname(fileURLToPath(import.meta.url)), "..", "bundled");
9
- const PERSON = "person";
10
- /** How long the first run waits for the installer's process to connect, and how often it looks. */
11
- const CONNECT_MS = 30_000;
12
- const CONNECT_EVERY_MS = 100;
13
- /**
14
- * Where the first run keeps the Actors it made, in the person's store: it trusts those, never an
15
- * Actor because of the name its package gives itself, which any package can take.
16
- */
17
- const RECORD = "app/first-run";
18
- /** The installer's own module, and the model's. */
19
- const INSTALLER = "installer";
20
- const CHATGPT = "chatgpt";
21
- /**
22
- * The installer's slots, each bound explicitly by the person at first run: the Hub's management
23
- * (it is the person's delegated manager), seeding new Actors' stores, and the person's layout.
24
- */
25
- const INSTALLER_BINDINGS = [
26
- ...["packages", "actors", "grants", "exports", "bindings"].map((name) => ({
27
- slot: `installer.${name}`,
28
- provider: "hub",
29
- export: name,
30
- })),
31
- { slot: "installer.storage", provider: "storage", export: "admin" },
32
- { slot: "installer.layout", provider: PERSON, export: "layout" },
33
- ];
34
- /**
35
- * The first run, at every start after the person's store is bound: add the bundled packages,
36
- * ensure the installer (made by the person, with its bindings, started), bind the person's
37
- * `installer` to it, ensure the model Actor installed through it (`web` to `egress`, `store` to
38
- * storage's `kv`, started), and bind the person's `login` to the model's. What earlier runs made
39
- * (recorded in the person's store) is kept and brought to this build: an installer or model Actor
40
- * on another package is upgraded in place, with its id, its store and its bindings; so is an agent
41
- * on an assistant build an earlier run bundled (by the hashes recorded, never by a package's
42
- * name). A binding an upgrade drops, its interface having changed, is made again where its ends
43
- * match now. A step that fails is logged and the rest still runs where it can; the next start
44
- * tries again.
45
- */
46
- export async function firstRun(person, options = {}) {
47
- const log = options.log ?? (() => { });
48
- const call = (slot, method, input = {}) => person.call(slot, method, input);
49
- const attempt = async (what, run) => {
50
- try {
51
- return await run();
52
- }
53
- catch (error) {
54
- log(`First run: ${what} didn't work: ${error instanceof Error ? error.message : String(error)}`);
55
- return undefined;
56
- }
57
- };
58
- const bundled = options.bundled ?? BUNDLED;
59
- const index = JSON.parse(readFileSync(join(bundled, "index.json"), "utf8"));
60
- const packages = {};
61
- for (const [name, file] of Object.entries(index)) {
62
- const added = await attempt(`adding ${name}`, () => call("packages", "add", { path: join(bundled, file) }));
63
- if (added)
64
- packages[name] = added.hash;
65
- }
66
- // What earlier runs made, by role, kept while it isn't closed. Unread, nothing is made: a run that
67
- // couldn't see its record would make a second installer.
68
- const read = (await call("store", "get", { key: RECORD })).value;
69
- const kept = (read ?? {});
70
- // Every assistant build a run has bundled, by hash: an agent on one of them is this app's to
71
- // bring to this build. Never a package by its name, which an agent's own package could take.
72
- const earlier = [
73
- ...(Array.isArray(kept.assistants) ? kept.assistants : []),
74
- kept.assistant,
75
- ].filter((hash) => typeof hash === "string");
76
- const isWiring = (wiring) => typeof wiring === "object" &&
77
- wiring !== null &&
78
- ["consumer", "slot", "provider", "export"].every((key) => typeof wiring[key] === "string");
79
- const record = {
80
- ...Object.fromEntries(Object.entries(kept).filter(([role, id]) => (role === "installer" || role === "chatgpt" || role === "assistant") &&
81
- typeof id === "string")),
82
- ...(earlier.length ? { assistants: [...new Set(earlier)] } : {}),
83
- ...(Array.isArray(kept.rebind) && kept.rebind.some(isWiring)
84
- ? { rebind: kept.rebind.filter(isWiring) }
85
- : {}),
86
- };
87
- const save = () => call("store", "set", { key: RECORD, value: { ...record } });
88
- const remember = (role, actorId) => {
89
- record[role] = actorId;
90
- return save();
91
- };
92
- // The assistant New agent installs is this build's, by hash.
93
- if (packages.assistant) {
94
- record.assistant = packages.assistant;
95
- record.assistants = [...new Set([...earlier, packages.assistant])];
96
- await attempt("recording the assistant", save);
97
- }
98
- /** Run this build's package as an Actor an earlier run made, keeping its id and its store. */
99
- const upgrade = async (actor, hash, what) => {
100
- const { dropped: lost } = await call("actors", "upgrade", {
101
- actorId: actor.actorId,
102
- package: hash,
103
- });
104
- if (lost.length) {
105
- record.rebind = [...(record.rebind ?? []), ...lost];
106
- await attempt("recording the bindings to make again", save);
107
- }
108
- log(`First run: upgraded ${what} (${actor.actorId}) to this build${lost.length ? `; ${lost.length} of its bindings to make again` : ""}.`);
109
- return { ...actor, package: hash };
110
- };
111
- /** The Actor an earlier run made for `role`, unless it is gone or closed. */
112
- const madeBefore = async (role) => {
113
- const id = record[role];
114
- if (!id)
115
- return undefined;
116
- const { actors } = await call("actors", "list");
117
- return actors.find((a) => a.actorId === id && a.state !== "closed");
118
- };
119
- const running = async (actor) => {
120
- if (actor.state !== "running")
121
- await call("actors", "start", { actorId: actor.actorId });
122
- };
123
- const bindingsOf = async (actor) => (await call("bindings", "list", { actor })).bindings.filter((b) => b.consumer === actor);
124
- /**
125
- * Made before: each of these slots it lost is bound again, if its package declares the slot (an
126
- * older build may not); one bound to another is kept.
127
- */
128
- const rebind = async (actor, bindings) => {
129
- const { manifest } = await call("packages", "get", { hash: actor.package });
130
- const declared = (slot) => {
131
- const [module = "", name = ""] = slot.split(".");
132
- return Object.hasOwn(manifest.modules[module]?.slots ?? {}, name);
133
- };
134
- const held = new Set((await bindingsOf(actor.actorId)).map((b) => b.slot));
135
- for (const binding of bindings)
136
- if (!held.has(binding.slot) && declared(binding.slot))
137
- await call("grants", "bind", { consumer: actor.actorId, ...binding });
138
- };
139
- /** Bind the person's `slot` to `target`, unless it is bound already (to it, or to another). */
140
- const personSlot = async (slot, target) => {
141
- if ((await bindingsOf(PERSON)).some((b) => b.slot === slot))
142
- return;
143
- await call("grants", "bind", {
144
- consumer: PERSON,
145
- slot,
146
- provider: target.actor,
147
- export: target.export,
148
- });
149
- };
150
- const installer = await attempt("the installer", async () => {
151
- let actor = await madeBefore("installer");
152
- if (!actor) {
153
- const hash = packages[INSTALLER];
154
- if (!hash)
155
- return undefined;
156
- const { actorId } = await call("actors", "create", {
157
- name: "Installer",
158
- package: hash,
159
- bindings: INSTALLER_BINDINGS,
160
- });
161
- await remember("installer", actorId);
162
- log("First run: made the installer.");
163
- actor = { actorId, name: "Installer", package: hash, state: "created" };
164
- }
165
- else {
166
- const hash = packages[INSTALLER];
167
- const before = actor;
168
- if (hash && actor.package !== hash)
169
- actor =
170
- (await attempt("upgrading the installer", () => upgrade(before, hash, "the installer"))) ?? actor;
171
- await rebind(actor, INSTALLER_BINDINGS);
172
- }
173
- await personSlot("installer", { actor: actor.actorId, export: "installer.installer" });
174
- await running(actor);
175
- return actor.actorId;
176
- });
177
- const egress = options.egress ?? { actor: "net", export: "egress" };
178
- const chatgptBindings = [
179
- { slot: "model.web", provider: egress.actor, export: egress.export },
180
- { slot: "model.store", provider: "storage", export: "kv" },
181
- ];
182
- const chatgpt = await attempt("ChatGPT", async () => {
183
- let actor = await madeBefore("chatgpt");
184
- if (actor) {
185
- const hash = packages[CHATGPT];
186
- const before = actor;
187
- if (hash && actor.package !== hash)
188
- actor =
189
- (await attempt("upgrading ChatGPT", () => upgrade(before, hash, "ChatGPT"))) ?? actor;
190
- await rebind(actor, chatgptBindings);
191
- await running(actor);
192
- return actor.actorId;
193
- }
194
- const hash = packages[CHATGPT];
195
- if (!hash || !installer)
196
- return undefined;
197
- // The installer's process may still be connecting: wait for it, then install once.
198
- const { connected } = options;
199
- if (connected) {
200
- const until = Date.now() + CONNECT_MS;
201
- while (!connected(installer)) {
202
- if (Date.now() > until)
203
- throw new Error("the installer's process didn't connect; the next start tries again.");
204
- await new Promise((done) => setTimeout(done, CONNECT_EVERY_MS));
205
- }
206
- }
207
- const { actorId } = await call("installer", "install", {
208
- package: hash,
209
- name: "ChatGPT",
210
- connections: Object.fromEntries(chatgptBindings.map((b) => [b.slot, { actor: b.provider, export: b.export }])),
211
- start: true,
212
- });
213
- await remember("chatgpt", actorId);
214
- log("First run: installed ChatGPT.");
215
- return actorId;
216
- });
217
- if (chatgpt)
218
- await attempt("binding the login", () => personSlot("login", { actor: chatgpt, export: "model.login" }));
219
- // Agents on an assistant build an earlier run bundled: brought to this build's assistant.
220
- const assistant = packages.assistant;
221
- if (assistant) {
222
- const agents = await attempt("finding agents on earlier builds", async () => (await call("actors", "list")).actors.filter((a) => a.state !== "closed" && a.package !== assistant && earlier.includes(a.package)));
223
- for (const agent of agents ?? [])
224
- await attempt(`upgrading ${agent.name}`, () => upgrade(agent, assistant, `the agent ${agent.name}`));
225
- }
226
- // What upgrades dropped, this run or one that stopped before this, made again where its slot is
227
- // still unbound: the ends now match, both on this build. One that can't be yet (an upgrade
228
- // failed, or its ends still differ) is logged and kept for the next start.
229
- if (record.rebind) {
230
- const left = [];
231
- for (const wiring of record.rebind) {
232
- const made = await attempt(`binding ${wiring.slot} again`, async () => {
233
- if ((await bindingsOf(wiring.consumer)).some((b) => b.slot === wiring.slot))
234
- return true;
235
- await call("grants", "bind", wiring);
236
- log(`First run: bound ${wiring.consumer}'s ${wiring.slot} again.`);
237
- return true;
238
- });
239
- if (!made)
240
- left.push(wiring);
241
- }
242
- if (left.length)
243
- record.rebind = left;
244
- else
245
- delete record.rebind;
246
- await attempt("recording the bindings made again", save);
247
- }
248
- return {
249
- packages,
250
- ...(installer ? { installer } : {}),
251
- ...(chatgpt ? { chatgpt } : {}),
252
- };
253
- }
254
- /** What the sign-in tab says, by outcome: `complete`'s refusal code, or `signed_in`. */
255
- const SAYS = {
256
- signed_in: "Signed in to ChatGPT. You can close this tab.",
257
- denied: "You declined on ChatGPT's page. Start again from AgentOrg when you're ready.",
258
- expired: "This sign-in expired. Start again from AgentOrg.",
259
- };
260
- const FAILED = "The sign-in didn't work. Start again from AgentOrg.";
261
- /**
262
- * `/oauth/chatgpt`: where ChatGPT sends the browser back. It hands the whole callback address to
263
- * the person's `login.complete`, then sends the tab on to `?result=<outcome>`, an address without
264
- * the sign-in's code, so the code stays out of the tab's address and history; that page says how
265
- * it went and links back to the shell. The code is never logged or shown, and no page sends a
266
- * referrer.
267
- */
268
- export function oauthRoute(person) {
269
- return (request, response, url) => {
270
- if (request.method !== "GET")
271
- return void response.writeHead(405).end();
272
- const result = url.searchParams.get("result");
273
- if (result !== null && [...url.searchParams.keys()].length === 1)
274
- return page(response, result === "signed_in" ? 200 : 400, Object.hasOwn(SAYS, result) ? SAYS[result] : FAILED);
275
- const after = (outcome) => {
276
- response.writeHead(303, {
277
- Location: `${url.pathname}?result=${encodeURIComponent(outcome)}`,
278
- "Cache-Control": "no-store",
279
- "Referrer-Policy": "no-referrer",
280
- });
281
- response.end();
282
- };
283
- void person.call("login", "complete", { callbackUrl: url.href }).then(() => after("signed_in"), (error) => {
284
- const code = error?.code;
285
- after(typeof code === "string" && Object.hasOwn(SAYS, code) ? code : "failed");
286
- });
287
- };
288
- }
289
- function page(response, status, text) {
290
- response.writeHead(status, {
291
- "Content-Type": "text/html; charset=utf-8",
292
- "Cache-Control": "no-store",
293
- "Referrer-Policy": "no-referrer",
294
- "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; frame-ancestors 'none'",
295
- });
296
- response.end(`<!doctype html><meta charset="utf-8"><title>AgentOrg</title>` +
297
- `<style>body{font:15px system-ui,sans-serif;margin:20vh auto;max-width:28rem;padding:0 16px}</style>` +
298
- `<p>${text}</p><p><a href="/">Back to AgentOrg</a></p>`);
299
- }
@@ -1,71 +0,0 @@
1
- import type { PersonSide } from "./api.js";
2
- /** Where the rules that are on are kept, in the person's store: `{<id>: {on}}`. */
3
- export declare const RULES_KEY = "app/rules";
4
- /** An exposure a request asks for: `provider`'s `export`, as a slot on `to`. */
5
- export interface Exposure {
6
- provider: string;
7
- export: string;
8
- to: string;
9
- as?: string;
10
- }
11
- /** An exposure as a request asks for it: by whom, and which side it lacks. */
12
- export interface Asked extends Exposure {
13
- requestedBy?: string;
14
- /** The side the requester lacks: `export` when it holds the slot side, as `to` does. */
15
- needs?: string;
16
- }
17
- /** An open request, as `hub.grants` tells it. */
18
- export interface Request {
19
- requestId: string;
20
- [field: string]: unknown;
21
- }
22
- /**
23
- * The exposure an open request asks for, if it asks for one. The one place that reads the Hub's
24
- * request shape for exposures.
25
- */
26
- export declare function exposureOf(request: Request): Asked | undefined;
27
- interface Definition {
28
- id: string;
29
- name: string;
30
- says: string;
31
- /** Whether this rule approves the exposure, read from the Hub as the person. */
32
- approves(asked: Asked, person: PersonSide): Promise<boolean>;
33
- }
34
- /** The rules the app knows, in the order Settings lists them. */
35
- export declare const DEFINITIONS: readonly Definition[];
36
- export interface RulesOptions {
37
- person: PersonSide;
38
- /** Where the rules say what they approved, and what they couldn't. */
39
- log?: (message: string) => void;
40
- /** Told after a rule is turned on or off. */
41
- changed?: () => void;
42
- }
43
- /**
44
- * The rules, for `app.rules@1`, and their engine: it hears each request the person could approve,
45
- * and goes through the open ones at start and whenever a rule is turned on. It approves a request a
46
- * rule that is on matches, as an approver does, with the call the request asked for; the Hub checks
47
- * that the person could grant it. It never declines: anything no rule matches stays for the person.
48
- */
49
- export declare class Rules {
50
- #private;
51
- constructor(options: RulesOptions);
52
- list(): Promise<{
53
- rules: {
54
- id: string;
55
- name: string;
56
- says: string;
57
- on: boolean;
58
- }[];
59
- }>;
60
- set({ id, on }: {
61
- id: string;
62
- on: boolean;
63
- }): Promise<Record<string, never>>;
64
- /** Hear each new request, and settle the open ones. */
65
- start(): Promise<void>;
66
- /** Stop: nothing more is heard, and a sweep under way approves nothing more. */
67
- close(): void;
68
- /** Go through every open request the person could approve. */
69
- sweep(): Promise<void>;
70
- }
71
- export {};
package/dist/src/rules.js DELETED
@@ -1,157 +0,0 @@
1
- // The person's named rules: conveniences the person turns on, held by the gateway, which acts on a
2
- // rule that is on as the person (a manager) and only within what the person could grant. Each rule
3
- // is named and visible, and off until the person turns it on; nothing else acts on provenance.
4
- import { Refused } from "@agentorg/sdk";
5
- /** Where the rules that are on are kept, in the person's store: `{<id>: {on}}`. */
6
- export const RULES_KEY = "app/rules";
7
- /**
8
- * The exposure an open request asks for, if it asks for one. The one place that reads the Hub's
9
- * request shape for exposures.
10
- */
11
- export function exposureOf(request) {
12
- const { exposed, provider, export: name, consumer, slot, requestedBy, needs, } = request;
13
- if (exposed !== true)
14
- return undefined;
15
- if (typeof provider !== "string" || typeof name !== "string" || typeof consumer !== "string")
16
- return undefined;
17
- return {
18
- provider,
19
- export: name,
20
- to: consumer,
21
- ...(typeof slot === "string" ? { as: slot } : {}),
22
- ...(typeof requestedBy === "string" ? { requestedBy } : {}),
23
- ...(typeof needs === "string" ? { needs } : {}),
24
- };
25
- }
26
- /** The rules the app knows, in the order Settings lists them. */
27
- export const DEFINITIONS = [
28
- {
29
- id: "agents-use-what-they-install",
30
- name: "Let an agent use what it installs",
31
- says: "When an agent asks to use an Actor it installed, approve it.",
32
- async approves(asked, person) {
33
- // The agent asked for itself: it holds its slot side and lacks the export side.
34
- if (asked.requestedBy !== asked.to || asked.needs !== "export")
35
- return false;
36
- // Provenance only: who the installer installed it for. The Hub grants nothing from it.
37
- const actor = (await person.call("actors", "get", { actorId: asked.provider }));
38
- return actor.state !== "closed" && actor.installedFor === asked.to;
39
- },
40
- },
41
- ];
42
- /**
43
- * The rules, for `app.rules@1`, and their engine: it hears each request the person could approve,
44
- * and goes through the open ones at start and whenever a rule is turned on. It approves a request a
45
- * rule that is on matches, as an approver does, with the call the request asked for; the Hub checks
46
- * that the person could grant it. It never declines: anything no rule matches stays for the person.
47
- */
48
- export class Rules {
49
- #person;
50
- #log;
51
- #changed;
52
- /** Requests being settled, so an event and a sweep don't settle one twice. */
53
- #settling = new Set();
54
- #stop;
55
- #closed = false;
56
- /** Turning rules on and off, one at a time, so none is lost. */
57
- #setting = Promise.resolve();
58
- constructor(options) {
59
- this.#person = options.person;
60
- this.#log = options.log ?? (() => { });
61
- this.#changed = options.changed ?? (() => { });
62
- }
63
- /** The ids of the rules that are on. */
64
- async #on() {
65
- const { value } = (await this.#person.call("store", "get", { key: RULES_KEY }));
66
- const held = typeof value === "object" && value !== null ? value : {};
67
- return new Set(DEFINITIONS.filter((rule) => held[rule.id]?.on === true).map((rule) => rule.id));
68
- }
69
- async list() {
70
- const on = await this.#on();
71
- return {
72
- rules: DEFINITIONS.map(({ id, name, says }) => ({ id, name, says, on: on.has(id) })),
73
- };
74
- }
75
- set({ id, on }) {
76
- if (!DEFINITIONS.some((rule) => rule.id === id))
77
- return Promise.reject(new Refused("unknown", `There is no rule ${id}.`));
78
- const done = this.#setting.then(async () => {
79
- const now = await this.#on();
80
- if (on)
81
- now.add(id);
82
- else
83
- now.delete(id);
84
- await this.#person.call("store", "set", {
85
- key: RULES_KEY,
86
- value: Object.fromEntries([...now].map((ruleId) => [ruleId, { on: true }])),
87
- });
88
- this.#changed();
89
- // Turned on, it settles what already waits for it; a sweep that fails is logged, as the
90
- // rule is on either way.
91
- if (on)
92
- await this.sweep().catch((error) => this.#log(`The rules couldn't go through what waits: ${messageOf(error)}`));
93
- return {};
94
- });
95
- this.#setting = done.catch(() => { });
96
- return done;
97
- }
98
- /** Hear each new request, and settle the open ones. */
99
- async start() {
100
- await this.sweep();
101
- }
102
- /** Hear each new request, once; heard again after a subscription that ended. */
103
- #listen() {
104
- if (this.#closed)
105
- return;
106
- this.#stop ??= this.#person.subscribe("grants", "requested", (request) => void this.#settle(request), () => {
107
- this.#stop = undefined;
108
- });
109
- }
110
- /** Stop: nothing more is heard, and a sweep under way approves nothing more. */
111
- close() {
112
- this.#closed = true;
113
- this.#stop?.();
114
- this.#stop = undefined;
115
- }
116
- /** Go through every open request the person could approve. */
117
- async sweep() {
118
- this.#listen();
119
- for (const request of await this.#open())
120
- await this.#settle(request);
121
- }
122
- async #open() {
123
- if (this.#closed)
124
- return [];
125
- return (await this.#person.call("grants", "requests", {}))
126
- .requests;
127
- }
128
- async #settle(request) {
129
- const asked = exposureOf(request);
130
- if (!asked || this.#closed || this.#settling.has(request.requestId))
131
- return;
132
- this.#settling.add(request.requestId);
133
- try {
134
- const on = await this.#on();
135
- for (const rule of DEFINITIONS) {
136
- if (!on.has(rule.id) || !(await rule.approves(asked, this.#person)))
137
- continue;
138
- // Still open just before: one the person declined, or that was settled meanwhile, is left.
139
- if (!(await this.#open()).some((open) => open.requestId === request.requestId))
140
- return;
141
- const { provider, export: name, to, as } = asked;
142
- const exposure = { provider, export: name, to, ...(as ? { as } : {}) };
143
- // As an approver approves: the call the request asked for, checked by the Hub.
144
- await this.#person.call("grants", "expose", exposure);
145
- this.#log(`Rule "${rule.name}" approved ${exposure.provider}'s ${exposure.export} for ${exposure.to}.`);
146
- return;
147
- }
148
- }
149
- catch (error) {
150
- this.#log(`A rule couldn't settle request ${request.requestId}: ${messageOf(error)}`);
151
- }
152
- finally {
153
- this.#settling.delete(request.requestId);
154
- }
155
- }
156
- }
157
- const messageOf = (error) => (error instanceof Error ? error.message : String(error));
@@ -1,30 +0,0 @@
1
- import { Composition } from "@agentorg/interfaces";
2
- import type { z } from "zod";
3
- /** A package's or a system's file, sent or received: 64 MiB at most. */
4
- export declare const MAX_TRANSFER: number;
5
- /**
6
- * A stored package as its archive. The Hub keeps a package as its verified tree, so the archive is
7
- * made again from it, in the SDK's deterministic tar: the same bytes `agentorg build` writes, and
8
- * so the same hash. `undefined` for a package the store doesn't hold.
9
- */
10
- export declare function packageArchive(home: string, hash: string): Uint8Array | undefined;
11
- /**
12
- * Run `use` with `bytes` in a private temporary file in the home, named `name`, then delete it,
13
- * whatever happens: the Hub adds packages from a path.
14
- */
15
- export declare function withTemporaryFile<T>(home: string, name: string, bytes: Uint8Array, use: (path: string) => Promise<T>): Promise<T>;
16
- export type SystemComposition = z.output<typeof Composition>;
17
- /** The hash each of a composition's Actors pins: its package is `name@version#hash`. */
18
- export declare function pinnedHashes(composition: SystemComposition): string[];
19
- /** A system file: `composition.json`, and each pinned package's archive under `packages/`. */
20
- export declare function writeSystem(composition: SystemComposition, archives: Map<string, Uint8Array>): Uint8Array;
21
- /**
22
- * A system file, read strictly: a tar of regular files whose entries are exactly
23
- * `composition.json` and `packages/sha256-<64 hex>.agentorg`, nothing else. A composition may
24
- * come from anyone, so anything else is refused (`invalid`). Each archive's hash is checked
25
- * against its name when it is added.
26
- */
27
- export declare function readSystem(bytes: Uint8Array): {
28
- composition: SystemComposition;
29
- packages: Map<string, Uint8Array>;
30
- };
@@ -1,110 +0,0 @@
1
- import { randomBytes } from "node:crypto";
2
- import { mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
- import { join, relative, sep } from "node:path";
4
- import { Composition } from "@agentorg/interfaces";
5
- import { Refused } from "@agentorg/sdk";
6
- import { readTar, writeTar } from "@agentorg/sdk/manifest";
7
- /** A package's or a system's file, sent or received: 64 MiB at most. */
8
- export const MAX_TRANSFER = 64 * 1024 * 1024;
9
- const HASH = /^sha256-[0-9a-f]{64}$/;
10
- /** A system file's package entries: exactly `packages/<hash>.agentorg`. */
11
- const PACKAGE_ENTRY = /^packages\/(sha256-[0-9a-f]{64})\.agentorg$/;
12
- /**
13
- * A stored package as its archive. The Hub keeps a package as its verified tree, so the archive is
14
- * made again from it, in the SDK's deterministic tar: the same bytes `agentorg build` writes, and
15
- * so the same hash. `undefined` for a package the store doesn't hold.
16
- */
17
- export function packageArchive(home, hash) {
18
- if (!HASH.test(hash))
19
- return undefined;
20
- const root = join(home, "packages", hash);
21
- const files = new Map();
22
- const walk = (dir) => {
23
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
24
- const path = join(dir, entry.name);
25
- if (entry.isDirectory())
26
- walk(path);
27
- else if (entry.isFile())
28
- files.set(relative(root, path).split(sep).join("/"), readFileSync(path));
29
- }
30
- };
31
- try {
32
- walk(root);
33
- }
34
- catch {
35
- return undefined;
36
- }
37
- return files.size ? writeTar(files) : undefined;
38
- }
39
- /**
40
- * Run `use` with `bytes` in a private temporary file in the home, named `name`, then delete it,
41
- * whatever happens: the Hub adds packages from a path.
42
- */
43
- export async function withTemporaryFile(home, name, bytes, use) {
44
- const dir = join(home, "tmp", randomBytes(9).toString("base64url"));
45
- mkdirSync(dir, { recursive: true, mode: 0o700 });
46
- try {
47
- const path = join(dir, name);
48
- writeFileSync(path, bytes, { mode: 0o600 });
49
- return await use(path);
50
- }
51
- finally {
52
- rmSync(dir, { recursive: true, force: true });
53
- }
54
- }
55
- /** The hash each of a composition's Actors pins: its package is `name@version#hash`. */
56
- export function pinnedHashes(composition) {
57
- const hashes = new Set();
58
- for (const { package: pinned } of Object.values(composition.actors)) {
59
- const hash = pinned.slice(pinned.lastIndexOf("#") + 1);
60
- if (HASH.test(hash))
61
- hashes.add(hash);
62
- }
63
- return [...hashes];
64
- }
65
- /** A system file: `composition.json`, and each pinned package's archive under `packages/`. */
66
- export function writeSystem(composition, archives) {
67
- const files = new Map([
68
- ["composition.json", new TextEncoder().encode(`${JSON.stringify(composition, null, 2)}\n`)],
69
- ]);
70
- for (const [hash, archive] of archives)
71
- files.set(`packages/${hash}.agentorg`, archive);
72
- return writeTar(files);
73
- }
74
- /**
75
- * A system file, read strictly: a tar of regular files whose entries are exactly
76
- * `composition.json` and `packages/sha256-<64 hex>.agentorg`, nothing else. A composition may
77
- * come from anyone, so anything else is refused (`invalid`). Each archive's hash is checked
78
- * against its name when it is added.
79
- */
80
- export function readSystem(bytes) {
81
- let files;
82
- try {
83
- files = readTar(bytes);
84
- }
85
- catch (error) {
86
- throw new Refused("invalid", `This isn't a system file: ${error.message}`);
87
- }
88
- const packages = new Map();
89
- let composition;
90
- for (const [path, data] of files) {
91
- const entry = PACKAGE_ENTRY.exec(path);
92
- if (entry)
93
- packages.set(entry[1], data);
94
- else if (path === "composition.json")
95
- try {
96
- composition = JSON.parse(new TextDecoder().decode(data));
97
- }
98
- catch {
99
- throw new Refused("invalid", "composition.json isn't JSON.");
100
- }
101
- else
102
- throw new Refused("invalid", `A system file holds no ${JSON.stringify(path)}.`);
103
- }
104
- if (composition === undefined)
105
- throw new Refused("invalid", "A system file has a composition.json.");
106
- const parsed = Composition.safeParse(composition);
107
- if (!parsed.success)
108
- throw new Refused("invalid", `composition.json doesn't fit: ${parsed.error.issues[0]?.message}`);
109
- return { composition: parsed.data, packages };
110
- }