@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
@@ -0,0 +1,680 @@
1
+ import { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { agentProvider, agentSettings, agents, chat, connections, hubActors, hubBindings, hubGrants, skills, tools, unitProvider, } from "@agentorg/interfaces";
4
+ import { describeInterface, Refused } from "@agentorg/sdk";
5
+ import { connect } from "@agentorg/sdk/client";
6
+ import { createActivity } from "./activity.js";
7
+ import { createControl } from "./control.js";
8
+ import { schemaOf, secretsSchemaOf, settle } from "./form.js";
9
+ import { createSkills, readSkillFolder } from "./skills.js";
10
+ import { createStacks, Records, slotFieldOf } from "./stack.js";
11
+ const FILE = "manager.json";
12
+ const ACTIVITY = "activity.jsonl";
13
+ /** Who a control call is made as, when it isn't on an agent's own behalf. */
14
+ const PERSON_CALLER = "person";
15
+ const CHAT_WAIT_MS = 2000;
16
+ const CHAT = "chat@1";
17
+ /** What one agent may add of its own, at most. */
18
+ const AGENT_CONNECTIONS = 16;
19
+ const AGENT_SKILLS = 32;
20
+ const AGENT_SKILL_BYTES = 1024 * 1024;
21
+ const TOOLS_EXPORT = "tools";
22
+ const quiet = { info() { }, warn() { }, error() { } };
23
+ const messageOf = (error) => (error instanceof Error ? error.message : String(error));
24
+ /** The slot a connection is made for by the person: no agent has it yet, so it names nothing. */
25
+ const PERSON_SLOT = "tools";
26
+ const alreadyGone = (error) => error instanceof Refused && error.code === "unknown";
27
+ /**
28
+ * Run management as an Actor exporting `agents@1`, `connections@1`, `skills@1` and, as `settings`,
29
+ * `agent.settings@1`. It keeps only what the Hub can't know. A provider is connected by exposing
30
+ * its export to this Actor: the Hub's slots are the list of them, and what is exposed to an agent
31
+ * is the Hub's bindings. No status is stored, and no secret reaches it to keep.
32
+ */
33
+ export async function startManager(options) {
34
+ const log = options.log ?? quiet;
35
+ const { dir } = options;
36
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
37
+ chmodSync(dir, 0o700);
38
+ const path = join(dir, FILE);
39
+ const read = () => {
40
+ const empty = {
41
+ agents: {},
42
+ connections: {},
43
+ templates: {},
44
+ instances: {},
45
+ authors: { skills: {}, templates: {} },
46
+ };
47
+ let raw;
48
+ try {
49
+ raw = readFileSync(path, "utf8");
50
+ }
51
+ catch (error) {
52
+ if (error.code === "ENOENT")
53
+ return empty;
54
+ throw error;
55
+ }
56
+ try {
57
+ return Records.parse(JSON.parse(raw));
58
+ }
59
+ catch {
60
+ renameSync(path, `${path}.unreadable-${Date.now()}`);
61
+ log.error("Management's records can't be read: they are set aside and start empty.");
62
+ return empty;
63
+ }
64
+ };
65
+ const records = read();
66
+ const save = () => {
67
+ writeFileSync(`${path}.tmp`, JSON.stringify(records), { mode: 0o600, flush: true });
68
+ renameSync(`${path}.tmp`, path);
69
+ };
70
+ const library = createSkills(join(dir, "skills"));
71
+ const activity = createActivity(join(dir, ACTIVITY));
72
+ /** Agents being made: they can read their settings, and nothing else can see them yet. */
73
+ const creating = new Map();
74
+ const client = await connect({
75
+ hubUrl: options.hubUrl,
76
+ actorId: options.actorId,
77
+ credential: options.credential,
78
+ slots: { actors: hubActors, grants: hubGrants, bindings: hubBindings },
79
+ exports: { agents, connections, skills, settings: agentSettings, tools },
80
+ log,
81
+ start(ctx) {
82
+ const hub = {
83
+ actors: ctx.slots.actors.call,
84
+ grants: ctx.slots.grants.call,
85
+ bindings: ctx.slots.bindings.call,
86
+ };
87
+ /** The providers of an interface exposed to this Actor now. */
88
+ const exposed = (iface) => {
89
+ const { id, hash } = describeInterface(iface);
90
+ return ctx
91
+ .exposed()
92
+ .filter(({ described }) => described.id === id && described.hash === hash)
93
+ .map(({ provider, call }) => ({ actor: provider.actor, call: call }));
94
+ };
95
+ const agentProviders = () => exposed(agentProvider);
96
+ const unitProviders = () => exposed(unitProvider);
97
+ const named = (list, actor, what) => {
98
+ const found = list.find((one) => one.actor === actor);
99
+ if (!found)
100
+ throw new Refused("unknown", `${actor} isn't a connected ${what}.`);
101
+ return found;
102
+ };
103
+ const open = async () => new Map((await hub.actors.list({})).actors
104
+ .filter((actor) => actor.state !== "closed")
105
+ .map((actor) => [actor.actorId, actor]));
106
+ const nameOf = async (actor) => (await hub.actors.get({ actorId: actor })).name;
107
+ const changed = (agent) => ctx.exports.settings.emit("changed", {}, { to: agent });
108
+ /** What every one of these answers; one that doesn't is logged and left out. */
109
+ const fromEach = async (list, read) => (await Promise.allSettled(list.map(read))).flatMap((result) => {
110
+ if (result.status === "fulfilled")
111
+ return [result.value];
112
+ log.warn(`A provider didn't answer: ${messageOf(result.reason)}`);
113
+ return [];
114
+ });
115
+ const recordOf = (agent) => {
116
+ const record = records.agents[agent];
117
+ if (!record)
118
+ throw new Refused("unknown", `Management has no agent ${agent}.`);
119
+ return record;
120
+ };
121
+ /** The caller when it's an agent, which reaches these only through its control unit. */
122
+ const agentOf = (caller) => records.agents[caller] || creating.has(caller) ? caller : undefined;
123
+ /** A skill an agent added is seen by it and the agents below it, until the person shares it. */
124
+ const seesSkill = (caller, name) => {
125
+ const author = records.authors.skills[name];
126
+ if (!author || !agentOf(caller))
127
+ return true;
128
+ const seen = new Set();
129
+ for (let at = caller; at && !seen.has(at);) {
130
+ if (at === author)
131
+ return true;
132
+ seen.add(at);
133
+ at = records.agents[at]?.parent?.agent;
134
+ }
135
+ return false;
136
+ };
137
+ const parentOf = ({ parent }) => parent
138
+ ? {
139
+ parent: {
140
+ ...parent,
141
+ ...(records.agents[parent.agent] ? {} : { gone: true }),
142
+ },
143
+ }
144
+ : {};
145
+ const settingsOf = (agent) => creating.get(agent) ?? recordOf(agent);
146
+ const originOf = (connection) => {
147
+ const origin = records.connections[connection];
148
+ if (!origin)
149
+ throw new Refused("unknown", `Management has no connection ${connection}.`);
150
+ return origin;
151
+ };
152
+ const agentStatus = async (agent, provider) => {
153
+ try {
154
+ return await named(agentProviders(), provider, "agent provider").call.status({ agent });
155
+ }
156
+ catch {
157
+ return { state: "down", detail: "Its provider can't be reached." };
158
+ }
159
+ };
160
+ const instanceOf = (connection) => records.instances[connection] ?? connection;
161
+ const forget = (connection) => {
162
+ delete records.connections[connection];
163
+ delete records.instances[connection];
164
+ };
165
+ const connectionStatus = async (connection) => {
166
+ const unit = stacks.unitMaking(connection);
167
+ if (unit)
168
+ return stacks.connectionStatus(unit, connection);
169
+ const origin = records.connections[connection];
170
+ if (!origin) {
171
+ // Exposed by hand, so no provider is known: the Hub says whether it is there.
172
+ const { connected } = await hub.actors.get({ actorId: connection });
173
+ return { state: connected ? "connected" : "down", tools: [] };
174
+ }
175
+ return stacks.connectionStatus({ provider: origin.provider, providerInstance: instanceOf(connection) }, connection);
176
+ };
177
+ const exposeConnection = async (agent, connection, as) => {
178
+ const { slot } = await hub.grants.expose({
179
+ provider: connection,
180
+ export: TOOLS_EXPORT,
181
+ to: agent,
182
+ ...(as ? { as } : {}),
183
+ });
184
+ return slot;
185
+ };
186
+ /** Remove a connection through its provider; one that has lost it leaves only the Actor. */
187
+ const removeConnection = async (connection, provider) => {
188
+ const maker = unitProviders().find((one) => one.actor === provider);
189
+ try {
190
+ if (maker)
191
+ return void (await maker.call.remove({ instance: instanceOf(connection) }));
192
+ }
193
+ catch (error) {
194
+ if (!alreadyGone(error))
195
+ throw error;
196
+ }
197
+ await hub.actors.close({ actorId: connection });
198
+ };
199
+ /** The same for an agent. */
200
+ const removeAgent = async (agent, provider) => {
201
+ const maker = agentProviders().find((one) => one.actor === provider);
202
+ try {
203
+ if (maker)
204
+ return void (await maker.call.remove({ agent }));
205
+ }
206
+ catch (error) {
207
+ if (!alreadyGone(error))
208
+ throw error;
209
+ }
210
+ await hub.actors.close({ actorId: agent });
211
+ };
212
+ /** For undoing: whatever the provider says, the thing goes. */
213
+ const closing = (what, remove) => remove().catch(async (error) => {
214
+ log.warn(`Removing ${what}: ${messageOf(error)}`);
215
+ await hub.actors.close({ actorId: what });
216
+ });
217
+ const dropSkill = (name) => {
218
+ library.remove(name);
219
+ for (const [agent, record] of Object.entries(records.agents))
220
+ if (record.skills.includes(name)) {
221
+ record.skills = record.skills.filter((skill) => skill !== name);
222
+ for (const unit of record.units)
223
+ unit.skills = unit.skills.filter((skill) => skill !== name);
224
+ changed(agent);
225
+ }
226
+ };
227
+ const stacks = createStacks({
228
+ self: options.actorId,
229
+ hub,
230
+ records,
231
+ save,
232
+ library,
233
+ creating,
234
+ log,
235
+ shipped: options.templates ?? [],
236
+ agentProviders,
237
+ unitProviders,
238
+ recordOf,
239
+ openActors: open,
240
+ nameOf,
241
+ changed,
242
+ fromEach,
243
+ exposeConnection,
244
+ closing,
245
+ removeAgent,
246
+ });
247
+ /** An agent's own provider, which runs it and keeps its model. */
248
+ const makerOf = (agent) => named(agentProviders(), recordOf(agent).provider, "agent provider").call;
249
+ const startAgent = async (agent) => makerOf(agent).start({ agent });
250
+ const stopAgent = async (agent) => makerOf(agent).stop({ agent });
251
+ /** Its units and connections go first: if one can't, the agent is here to be tried again. */
252
+ const removeWhole = (agent) => stacks.serial(agent, async () => {
253
+ const record = recordOf(agent);
254
+ await stacks.removeAll(agent, record);
255
+ for (const [connection, origin] of Object.entries(records.connections)) {
256
+ if (origin.madeFor !== agent)
257
+ continue;
258
+ await removeConnection(connection, origin.provider);
259
+ forget(connection);
260
+ save();
261
+ }
262
+ await removeAgent(agent, record.provider);
263
+ delete records.agents[agent];
264
+ // What it wrote or saved is the person's now.
265
+ for (const kept of [records.authors.skills, records.authors.templates])
266
+ for (const [name, author] of Object.entries(kept))
267
+ if (author === agent)
268
+ delete kept[name];
269
+ save();
270
+ return {};
271
+ });
272
+ /** A child's chat: exposed to management when it is made, which takes a moment to arrive. */
273
+ const chatOf = async (agent) => {
274
+ const exposedChat = () => exposed(chat).find((one) => one.actor === agent);
275
+ if (!exposedChat()) {
276
+ // One the person made: its chat is reached as the person reaches it.
277
+ const { bindings } = await hub.bindings.list({ actor: PERSON_CALLER });
278
+ const theirs = bindings.find((one) => one.provider === agent && one.interface === CHAT && one.consumer === PERSON_CALLER);
279
+ if (theirs)
280
+ await hub.grants
281
+ .expose({ provider: agent, export: theirs.export, to: options.actorId })
282
+ .catch((error) => log.warn(`Reaching a chat: ${messageOf(error)}`));
283
+ }
284
+ for (let waited = 0; waited < CHAT_WAIT_MS; waited += 20) {
285
+ const found = exposed(chat).find((one) => one.actor === agent);
286
+ if (found)
287
+ return found.call;
288
+ await new Promise((resolve) => setTimeout(resolve, 20));
289
+ }
290
+ throw new Refused("not_connected", "That agent's chat can't be reached now.");
291
+ };
292
+ /**
293
+ * An agent's chats reach the person, and management too for an agent another agent made. The
294
+ * Hub drops both when the agent comes back offering its chats in another shape, as after an
295
+ * upgrade, so they are made again each time it connects: nothing changes when they are there.
296
+ */
297
+ const reachChats = async (agent) => {
298
+ const record = records.agents[agent];
299
+ if (!record || !(await hub.actors.get({ actorId: agent })).connected)
300
+ return;
301
+ for (const to of [PERSON_CALLER, ...(record.parent ? [options.actorId] : [])])
302
+ await hub.grants.expose({ provider: agent, export: record.chat, to });
303
+ };
304
+ const reaching = (agent) => void reachChats(agent).catch((error) => log.warn(`Reaching a chat: ${messageOf(error)}`));
305
+ ctx.slots.actors.on("changed", ({ actor }) => reaching(actor));
306
+ // And for those that connected while management was away, once it can ask.
307
+ ctx.slots.actors.onBind(() => {
308
+ for (const agent of Object.keys(records.agents))
309
+ reaching(agent);
310
+ });
311
+ /** The person's own handlers, which an agent's control tools call after their checks. */
312
+ const personHandlers = {};
313
+ const control = createControl({
314
+ self: options.actorId,
315
+ records,
316
+ creatingCount: () => creating.size,
317
+ catalog: stacks.catalog,
318
+ boundTo: async (agent) => new Set((await hub.bindings.list({ actor: agent })).bindings
319
+ .filter((binding) => binding.consumer === agent)
320
+ .map((binding) => `${binding.slot} ${binding.provider}`)),
321
+ templates: stacks.allTemplates,
322
+ baseProviderNamed: stacks.baseProviderNamed,
323
+ serial: stacks.serial,
324
+ create: (input, caller, child) => stacks.create(input, caller, child),
325
+ nameOf,
326
+ chatOf,
327
+ statusOf: agentStatus,
328
+ start: startAgent,
329
+ stop: stopAgent,
330
+ remove: removeWhole,
331
+ // Held to the interface's own input, as the person's calls are by the Hub.
332
+ person: async (iface, method, input, caller = PERSON_CALLER) => {
333
+ const handler = personHandlers[iface]?.[method];
334
+ const spec = { agents, connections, skills }[iface].methods[method];
335
+ if (!handler || !spec)
336
+ throw new Refused("unimplemented", `${iface} has no ${method}.`);
337
+ return handler(spec.input.parse(input), { caller });
338
+ },
339
+ hasSkill: (name, caller) => library.has(name) && seesSkill(caller, name),
340
+ templateAuthor: (id) => records.authors.templates[id],
341
+ madeBy: (connection) => records.connections[connection]?.madeBy,
342
+ log: (entry) => activity.add(entry),
343
+ });
344
+ /** Those who call management: the person. An agent comes through its control unit instead. */
345
+ const personOnly = (exported, name) => ({
346
+ implement(handlers) {
347
+ const held = handlers;
348
+ personHandlers[name] = held;
349
+ exported.implement(Object.fromEntries(Object.entries(held).map(([method, handler]) => [
350
+ method,
351
+ (input, context) => {
352
+ if (records.agents[context.caller] || creating.has(context.caller))
353
+ throw new Refused("forbidden", "An agent reaches this through its control unit.");
354
+ return handler(input, context);
355
+ },
356
+ ])));
357
+ },
358
+ });
359
+ ctx.exports.tools.implement({
360
+ list: async (_, { caller }) => ({ tools: await control.list(caller) }),
361
+ call: ({ name, arguments: input }, { caller }) => control.call(caller, name, input),
362
+ });
363
+ ctx.exports.settings.implement({
364
+ get: (_, { caller }) => {
365
+ const { instructions, purpose, skills: names } = settingsOf(caller);
366
+ return {
367
+ instructions: purpose
368
+ ? `${instructions}\n\nWhat you are for: ${purpose}`
369
+ : instructions,
370
+ skills: names.flatMap((name) => library.entry(name) ?? []),
371
+ };
372
+ },
373
+ skill: ({ name, path: file }, { caller }) => {
374
+ const text = settingsOf(caller).skills.includes(name)
375
+ ? library.read(name, file)
376
+ : undefined;
377
+ if (text === undefined)
378
+ throw new Refused("unknown", `No skill ${name} with that file is exposed to you.`);
379
+ return { text };
380
+ },
381
+ });
382
+ personOnly(ctx.exports.agents, "agents").implement({
383
+ creatable: async () => ({
384
+ creatables: (await fromEach(agentProviders(), async ({ actor, call }) => (await call.creatable({})).creatables.map((one) => ({ ...one, provider: actor })))).flat(),
385
+ }),
386
+ providers: async () => ({
387
+ providers: await Promise.all(agentProviders().map(async ({ actor }) => ({
388
+ provider: actor,
389
+ name: await nameOf(actor),
390
+ }))),
391
+ }),
392
+ units: () => stacks.units(),
393
+ templates: () => stacks.templates(),
394
+ saveTemplate: (template, { caller }) => stacks.saveTemplate(template, agentOf(caller)),
395
+ removeTemplate: (input, { caller }) => stacks.removeTemplate(input, agentOf(caller)),
396
+ check: (input) => stacks.check(input),
397
+ create: (input, { caller }) => stacks.create(input, caller),
398
+ addUnit: (input, { caller }) => stacks.serial(input.agent, () => stacks.addUnit(input, caller)),
399
+ removeUnit: (input) => stacks.serial(input.agent, () => stacks.removeUnit(input)),
400
+ activity: (input) => activity.read(input),
401
+ async live({ agent, instance, surface, mode }) {
402
+ const unit = recordOf(agent).units.find((one) => one.instance === instance);
403
+ if (!unit || unit.provider === options.actorId)
404
+ throw new Refused("unknown", `${agent} has nothing like that to open live.`);
405
+ const provider = unitProviders().find((one) => one.actor === unit.provider);
406
+ if (!provider)
407
+ throw new Refused("not_connected", "Its provider can't be reached now.");
408
+ return provider.call.live({ instance: unit.providerInstance, surface, mode });
409
+ },
410
+ async list() {
411
+ const actors = await open();
412
+ return {
413
+ agents: await Promise.all(Object.entries(records.agents).flatMap(([agent, record]) => {
414
+ const actor = actors.get(agent);
415
+ return actor
416
+ ? [
417
+ agentStatus(agent, record.provider).then((status) => ({
418
+ agent,
419
+ name: actor.name,
420
+ status,
421
+ provider: record.provider,
422
+ creatable: record.creatable,
423
+ ...(record.purpose ? { purpose: record.purpose } : {}),
424
+ ...(record.template ? { template: record.template } : {}),
425
+ ...parentOf(record),
426
+ })),
427
+ ]
428
+ : [];
429
+ })),
430
+ };
431
+ },
432
+ async get({ agent }) {
433
+ const record = recordOf(agent);
434
+ const { units, tools, instanceOfSkill, instanceOfSlot } = await stacks.read(agent, record, connectionStatus);
435
+ const [name, status, mcp] = await Promise.all([
436
+ nameOf(agent),
437
+ agentStatus(agent, record.provider),
438
+ Promise.all(tools.map(async (b) => ({
439
+ slot: b.slot,
440
+ connection: b.provider,
441
+ ...(records.connections[b.provider]
442
+ ? { origin: records.connections[b.provider] }
443
+ : {}),
444
+ status: await connectionStatus(b.provider),
445
+ instance: instanceOfSlot(b.slot),
446
+ }))),
447
+ ]);
448
+ return {
449
+ agent,
450
+ name,
451
+ status,
452
+ provider: record.provider,
453
+ creatable: record.creatable,
454
+ ...(record.purpose ? { purpose: record.purpose } : {}),
455
+ ...(record.template ? { template: record.template } : {}),
456
+ ...parentOf(record),
457
+ instructions: record.instructions,
458
+ skills: record.skills.flatMap((skill) => {
459
+ const entry = library.entry(skill);
460
+ return entry ? [{ ...entry, instance: instanceOfSkill(skill) }] : [];
461
+ }),
462
+ mcp,
463
+ units,
464
+ };
465
+ },
466
+ start: ({ agent }) => startAgent(agent),
467
+ stop: ({ agent }) => stopAgent(agent),
468
+ models: ({ agent }) => makerOf(agent).models({ agent }),
469
+ setModel: (input) => makerOf(input.agent).setModel(input),
470
+ expose: (input, { caller }) => stacks.serial(input.agent, async () => {
471
+ const record = recordOf(input.agent);
472
+ if ("connection" in input)
473
+ return { slot: await exposeConnection(input.agent, input.connection, input.as) };
474
+ if (!library.has(input.skill) || !seesSkill(caller, input.skill))
475
+ throw new Refused("unknown", `Management has no skill ${input.skill}.`);
476
+ // The person giving an agent's skill to anyone shares it: it's the person's now.
477
+ if (!agentOf(caller))
478
+ delete records.authors.skills[input.skill];
479
+ if (!record.skills.includes(input.skill)) {
480
+ record.skills.push(input.skill);
481
+ save();
482
+ changed(input.agent);
483
+ }
484
+ return {};
485
+ }),
486
+ unexpose: (input) => stacks.serial(input.agent, async () => {
487
+ const record = recordOf(input.agent);
488
+ if (stacks.fromUnit(record, input))
489
+ throw new Refused("state", "This came with a unit: remove the unit.");
490
+ if ("slot" in input) {
491
+ await hub.grants.unexpose({ to: input.agent, slot: input.slot });
492
+ return {};
493
+ }
494
+ if (record.skills.includes(input.skill)) {
495
+ record.skills = record.skills.filter((skill) => skill !== input.skill);
496
+ save();
497
+ changed(input.agent);
498
+ }
499
+ return {};
500
+ }),
501
+ /** Units and connections go first: if one can't, the agent is still here to be tried again. */
502
+ remove: ({ agent }) => removeWhole(agent),
503
+ });
504
+ personOnly(ctx.exports.connections, "connections").implement({
505
+ providers: async () => ({
506
+ providers: (await fromEach(unitProviders(), async ({ actor, call }) => ({
507
+ provider: actor,
508
+ name: await nameOf(actor),
509
+ kinds: (await call.units({})).units.flatMap((unit) => {
510
+ const slot = slotFieldOf(unit);
511
+ if (!slot)
512
+ return [];
513
+ const fields = unit.form.filter((field) => field.id !== slot);
514
+ return [
515
+ {
516
+ kind: unit.id,
517
+ title: unit.title,
518
+ params: JSON.parse(JSON.stringify(schemaOf(fields))),
519
+ secrets: JSON.parse(JSON.stringify(secretsSchemaOf(fields))),
520
+ },
521
+ ];
522
+ }),
523
+ }))).filter(({ kinds }) => kinds.length > 0),
524
+ }),
525
+ // `secrets` go straight to the provider: nothing here keeps or logs them.
526
+ async create({ provider, kind, params, secrets = {}, name }, { caller }) {
527
+ const agent = agentOf(caller);
528
+ if (agent &&
529
+ Object.values(records.connections).filter((one) => one.madeBy === agent).length >=
530
+ AGENT_CONNECTIONS)
531
+ throw new Refused("limit", `An agent can add at most ${AGENT_CONNECTIONS} connections.`);
532
+ const { call } = named(unitProviders(), provider, "connection provider");
533
+ const unit = (await call.units({})).units.find((one) => one.id === kind);
534
+ const slot = unit && slotFieldOf(unit);
535
+ if (!unit || !slot)
536
+ throw new Refused("invalid", `${provider} offers no ${kind}.`);
537
+ const declared = Object.keys(secrets).filter((id) => unit.form.some((field) => field.id === id && field.value === "secret"));
538
+ const settled = settle(unit.form, { ...params, [slot]: PERSON_SLOT }, declared);
539
+ if (settled.problems.length)
540
+ throw new Refused("invalid", settled.problems.map((one) => one.message).join(" "));
541
+ const applied = await call.apply({
542
+ unit: kind,
543
+ values: settled.values,
544
+ secrets,
545
+ needs: {},
546
+ agent: "person",
547
+ name,
548
+ });
549
+ const [made] = applied.connections;
550
+ if (!made || applied.connections.length !== 1) {
551
+ await call.remove({ instance: applied.instance }).catch(async () => {
552
+ for (const one of applied.connections)
553
+ await hub.actors.close({ actorId: one.connection });
554
+ });
555
+ throw new Refused("failed", `${kind} didn't make one connection.`);
556
+ }
557
+ const { connection, target } = made;
558
+ try {
559
+ records.connections[connection] = {
560
+ provider,
561
+ kind,
562
+ target,
563
+ madeBy: caller,
564
+ // One an agent made goes with it.
565
+ ...(agent ? { madeFor: agent } : {}),
566
+ at: new Date().toISOString(),
567
+ };
568
+ records.instances[connection] = applied.instance;
569
+ save();
570
+ }
571
+ catch (error) {
572
+ await closing(connection, () => removeConnection(connection, provider));
573
+ forget(connection);
574
+ throw error;
575
+ }
576
+ return { connection };
577
+ },
578
+ async list() {
579
+ const actors = await open();
580
+ return {
581
+ connections: await Promise.all(Object.entries(records.connections).flatMap(([connection, origin]) => {
582
+ const actor = actors.get(connection);
583
+ return actor
584
+ ? [
585
+ connectionStatus(connection).then(({ state }) => ({
586
+ connection,
587
+ name: actor.name,
588
+ state,
589
+ origin,
590
+ })),
591
+ ]
592
+ : [];
593
+ })),
594
+ };
595
+ },
596
+ async get({ connection }) {
597
+ const origin = originOf(connection);
598
+ return {
599
+ connection,
600
+ name: await nameOf(connection),
601
+ origin,
602
+ status: await connectionStatus(connection),
603
+ };
604
+ },
605
+ async remove({ connection }, { caller }) {
606
+ const origin = originOf(connection);
607
+ if (agentOf(caller) && origin.madeBy !== caller)
608
+ throw new Refused("unknown", `You have no connection ${connection}.`);
609
+ if (stacks.unitMaking(connection))
610
+ throw new Refused("state", "This connection came with a unit: remove the unit.");
611
+ await removeConnection(connection, origin.provider);
612
+ forget(connection);
613
+ save();
614
+ return {};
615
+ },
616
+ });
617
+ personOnly(ctx.exports.skills, "skills").implement({
618
+ add: (input, { caller }) => {
619
+ const agent = agentOf(caller);
620
+ if (agent) {
621
+ // An agent writes a skill of its own: it can't read a folder, or replace one there is.
622
+ if ("path" in input)
623
+ throw new Refused("forbidden", "An agent gives a skill as files.");
624
+ const named = library.nameOf(input.files);
625
+ if (library.has(named))
626
+ throw new Refused("state", `There is a skill ${named} already.`);
627
+ if (Object.values(records.authors.skills).filter((one) => one === agent).length >=
628
+ AGENT_SKILLS)
629
+ throw new Refused("limit", `An agent can write at most ${AGENT_SKILLS} skills.`);
630
+ const bytes = Object.values(input.files).reduce((sum, text) => sum + Buffer.byteLength(text), 0);
631
+ if (bytes > AGENT_SKILL_BYTES)
632
+ throw new Refused("limit", "An agent's skill can be at most 1 MB.");
633
+ const added = library.add(input.files, named);
634
+ records.authors.skills[added.name] = agent;
635
+ save();
636
+ return added;
637
+ }
638
+ const added = library.add("path" in input ? readSkillFolder(input.path) : input.files);
639
+ // Replaced by the person, it's the person's.
640
+ delete records.authors.skills[added.name];
641
+ for (const [agent, record] of Object.entries(records.agents))
642
+ if (record.skills.includes(added.name))
643
+ changed(agent);
644
+ return added;
645
+ },
646
+ list: (_, { caller }) => ({
647
+ skills: library.list().filter((one) => seesSkill(caller, one.name)),
648
+ }),
649
+ get: ({ name }, { caller }) => {
650
+ const entry = seesSkill(caller, name) ? library.entry(name) : undefined;
651
+ if (!entry)
652
+ throw new Refused("unknown", `Management has no skill ${name}.`);
653
+ return {
654
+ ...entry,
655
+ text: library.read(name),
656
+ files: library.paths(name),
657
+ agents: Object.entries(records.agents)
658
+ .filter(([, record]) => record.skills.includes(name))
659
+ .map(([agent]) => agent),
660
+ };
661
+ },
662
+ remove: ({ name }, { caller }) => {
663
+ const agent = agentOf(caller);
664
+ if (!library.has(name) || (agent && records.authors.skills[name] !== agent))
665
+ throw new Refused("unknown", `Management has no skill ${name}.`);
666
+ dropSkill(name);
667
+ delete records.authors.skills[name];
668
+ save();
669
+ return {};
670
+ },
671
+ });
672
+ },
673
+ });
674
+ return {
675
+ async close() {
676
+ client.close();
677
+ await client.closed;
678
+ },
679
+ };
680
+ }