@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
@@ -2,35 +2,48 @@
2
2
  "name": "@agentorg/shell",
3
3
  "version": "0.0.0",
4
4
  "private": true,
5
- "description": "The person's web shell for AgentOrg: their agents, their views and their settings.",
5
+ "description": "The person's web shell for AgentOrg: their agents, what each is made of, and their settings.",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "engines": {
9
9
  "node": ">=22.15"
10
10
  },
11
11
  "exports": {
12
- "./package.json": "./package.json",
13
- "./agent-bindings": {
14
- "types": "./src/agent-bindings.ts",
15
- "default": "./dist/agent-bindings.js"
16
- }
12
+ "./package.json": "./package.json"
17
13
  },
18
14
  "files": [
19
- "dist",
20
- "src/agent-bindings.ts"
15
+ "dist"
21
16
  ],
22
17
  "scripts": {
23
- "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json && node scripts/build.js"
18
+ "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json && tsc -p tsconfig.test.json && node scripts/build.js",
19
+ "test": "node --experimental-strip-types --no-warnings --test --test-concurrency=3 --test-timeout=60000 \"test/**/*.test.ts\""
24
20
  },
25
21
  "devDependencies": {
26
22
  "@agentorg/interfaces": "0.0.0",
27
- "@agentorg/kit": "0.0.0",
28
23
  "@agentorg/sdk": "0.0.0",
24
+ "@playwright/test": "1.64.1",
25
+ "@shadcn/react": "0.3.1",
26
+ "@tailwindcss/cli": "4.3.5",
29
27
  "@types/react": "19.3.0",
30
28
  "@types/react-dom": "19.3.0",
29
+ "@types/ws": "8.18.2",
30
+ "@xterm/addon-fit": "0.10.0",
31
+ "@xterm/xterm": "5.5.0",
32
+ "class-variance-authority": "0.7.1",
33
+ "clsx": "2.1.1",
31
34
  "esbuild": "0.28.2",
35
+ "lucide-react": "1.70.0",
36
+ "radix-ui": "1.8.1",
32
37
  "react": "19.3.1",
33
38
  "react-dom": "19.3.1",
39
+ "streamdown": "2.7.1",
40
+ "tailwind-merge": "3.7.0",
41
+ "tailwindcss": "4.3.5",
42
+ "tw-animate-css": "1.4.0",
43
+ "ws": "8.22.1",
34
44
  "zod": "^4.6.7"
45
+ },
46
+ "dependencies": {
47
+ "react-diff-view": "3.3.3"
35
48
  }
36
49
  }
@@ -1,4 +1,4 @@
1
- /** The largest JSON frame: 1 MiB. `stream` and `http` bodies are raw bytes, not frames. */
1
+ /** The largest JSON frame: 1 MiB. */
2
2
  export declare const MAX_FRAME: number;
3
3
  export declare class FrameError extends Error {
4
4
  readonly name = "FrameError";
@@ -6,8 +6,7 @@ export declare class FrameError extends Error {
6
6
  /** A frame: a 4-byte big-endian length, then that many bytes of UTF-8 JSON. */
7
7
  export declare function encodeFrame(value: unknown): Uint8Array;
8
8
  /**
9
- * Reads frames from a byte stream, then hands over what follows them untouched: a stream starts
10
- * with a header frame, and for `open` and `http` the rest is raw bytes.
9
+ * Reads frames from a byte stream, and can hand over what follows them untouched.
11
10
  */
12
11
  export declare class FrameReader {
13
12
  #private;
@@ -1,5 +1,5 @@
1
1
  import { ByteQueue } from "./bytes.js";
2
- /** The largest JSON frame: 1 MiB. `stream` and `http` bodies are raw bytes, not frames. */
2
+ /** The largest JSON frame: 1 MiB. */
3
3
  export const MAX_FRAME = 1024 * 1024;
4
4
  export class FrameError extends Error {
5
5
  name = "FrameError";
@@ -16,8 +16,7 @@ export function encodeFrame(value) {
16
16
  return frame;
17
17
  }
18
18
  /**
19
- * Reads frames from a byte stream, then hands over what follows them untouched: a stream starts
20
- * with a header frame, and for `open` and `http` the rest is raw bytes.
19
+ * Reads frames from a byte stream, and can hand over what follows them untouched.
21
20
  */
22
21
  export class FrameReader {
23
22
  #reader;
@@ -7,9 +7,7 @@
7
7
  * closes the channel too. Without `declares` the Actor keeps what it declared before; with it,
8
8
  * `declares` replaces that. The result is `{actorId, bound}`: the Actor's slots bound now. A
9
9
  * newer channel for an Actor replaces its older one; with `replace: false` the hello is refused
10
- * instead (`Refused`, code `connected`) while the Actor has a live channel. On a pipe the Hub
11
- * made for a package Actor's process, the hello names that Actor and carries no credential (the
12
- * pipe is the proof) and no `declares` (a package declares through its manifest).
10
+ * instead (`Refused`, code `connected`) while the Actor has a live channel.
13
11
  * - `slot`: from the Hub, one of the Actor's slots was bound or unbound after its channel's hello
14
12
  * result was taken. The header is the whole message: the Hub closes its side, and the Actor
15
13
  * closes its side once it has read it (an open notice counts against its streams). Applied in
@@ -17,22 +15,16 @@
17
15
  * they give each slot's state. A `bound: true` for a slot already bound means its provider came
18
16
  * back after going away: the slot is usable again, and what was subscribed must be again. A
19
17
  * provider going away sends nothing; calls meanwhile are `NotConnected`.
20
- * - `offer` and `withdraw`: the channel's own Actor offers an export at run time, or withdraws
21
- * one it offered; one body (`{result: {}}` or `{error}`) answers, then the stream closes.
22
18
  * - `call`: the caller sends one `{input}` body and closes its side; the answer is one `{result}`
23
19
  * or `{error}` body, then the stream closes.
24
20
  * - `subscribe`: `{event}` bodies flow until the subscriber resets the stream, or the provider
25
21
  * side closes it (with an `{error}` body first when it was refused).
26
- * - `open` and `http`: the answering side sends exactly one body first, `{result: {}}` to accept
27
- * or `{error}` to refuse; after an accept, raw bytes flow both ways, each side closing its own
28
- * direction, and a reset ends both. The provider answers the Hub, and the Hub forwards that
29
- * answer. The opener may send bytes before the answer; they wait.
30
22
  * Cancelling a reader of a yamux stream resets it.
31
23
  */
32
24
  export type Header =
33
25
  /**
34
- * Admits a channel; its first stream. An external client's carries its credential and may
35
- * declare (the Hub validates `declares`); a pipe's names its Actor only.
26
+ * Admits a channel; its first stream. It carries the Actor's credential and may declare (the
27
+ * Hub validates `declares`).
36
28
  */
37
29
  {
38
30
  op: "hello";
@@ -49,26 +41,6 @@ export type Header =
49
41
  slot: string;
50
42
  event: string;
51
43
  }
52
- /** Raw bytes in the interface's protocol, after the Hub validates `params`. */
53
- | {
54
- op: "open";
55
- slot: string;
56
- params: unknown;
57
- }
58
- /** HTTP/1.1 bytes. */
59
- | {
60
- op: "http";
61
- slot: string;
62
- }
63
- /** Offer an export at run time, as a described interface; it lasts until withdrawn or disconnect. */
64
- | {
65
- op: "offer";
66
- name: string;
67
- interface: unknown;
68
- } | {
69
- op: "withdraw";
70
- name: string;
71
- }
72
44
  /**
73
45
  * From the Hub to an Actor: one of its slots was bound or unbound. A slot made at run time (an
74
46
  * export exposed to this Actor) carries `exposed` while bound: the export's described interface
@@ -81,18 +53,17 @@ export type Header =
81
53
  exposed?: Exposure;
82
54
  }
83
55
  /**
84
- * From the Hub to a provider: the same four, naming its export, who is calling, and through which
56
+ * From the Hub to a provider: the same two, naming its export, who is calling, and through which
85
57
  * of the caller's slots (a provider keeping state per consumer keys it by both).
86
58
  */
87
59
  | {
88
60
  op: "serve";
89
- kind: "call" | "subscribe" | "open" | "http";
61
+ kind: "call" | "subscribe";
90
62
  export: string;
91
63
  caller: string;
92
64
  slot: string;
93
65
  method?: string;
94
66
  event?: string;
95
- params?: unknown;
96
67
  };
97
68
  /** A slot made at run time, as the Hub describes it: the export's interface, and whose it is. */
98
69
  export interface Exposure {
@@ -25,18 +25,6 @@ export function parseHeader(value) {
25
25
  return { op: "call", slot: text(value, "slot"), method: text(value, "method") };
26
26
  case "subscribe":
27
27
  return { op: "subscribe", slot: text(value, "slot"), event: text(value, "event") };
28
- case "open":
29
- if (!("params" in value))
30
- throw new HeaderError("An open header needs params.");
31
- return { op: "open", slot: text(value, "slot"), params: value.params };
32
- case "http":
33
- return { op: "http", slot: text(value, "slot") };
34
- case "offer":
35
- if (!isRecord(value.interface))
36
- throw new HeaderError("An offer header needs an interface.");
37
- return { op: "offer", name: text(value, "name"), interface: value.interface };
38
- case "withdraw":
39
- return { op: "withdraw", name: text(value, "name") };
40
28
  case "slot": {
41
29
  if (typeof value.bound !== "boolean")
42
30
  throw new HeaderError("A slot header needs bound.");
@@ -63,10 +51,8 @@ export function parseHeader(value) {
63
51
  }
64
52
  case "serve": {
65
53
  const kind = value.kind;
66
- if (kind !== "call" && kind !== "subscribe" && kind !== "open" && kind !== "http")
67
- throw new HeaderError("A serve header's kind must be call, subscribe, open or http.");
68
- if (kind === "open" && !("params" in value))
69
- throw new HeaderError("An open serve header needs params.");
54
+ if (kind !== "call" && kind !== "subscribe")
55
+ throw new HeaderError("A serve header's kind must be call or subscribe.");
70
56
  return {
71
57
  op: "serve",
72
58
  kind,
@@ -75,7 +61,6 @@ export function parseHeader(value) {
75
61
  slot: text(value, "slot"),
76
62
  ...(kind === "call" ? { method: text(value, "method") } : {}),
77
63
  ...(kind === "subscribe" ? { event: text(value, "event") } : {}),
78
- ...(kind === "open" ? { params: value.params } : {}),
79
64
  };
80
65
  }
81
66
  default:
@@ -0,0 +1,92 @@
1
+ /**
2
+ * An agent's chats: each one's entry in the store, and the looper's thread it is. A chat is made by
3
+ * the message that starts it and is never deleted. The entries are read when a chat is first asked
4
+ * for, all of them, and then stay in memory.
5
+ */
6
+ import { type ChatEntry, type chat, type kv } from "@agentorg/interfaces";
7
+ import { type Model, type Tool } from "@agentorg/looper";
8
+ import { type Log, type Slot } from "@agentorg/sdk";
9
+ import { z } from "zod";
10
+ type Store = Slot<typeof kv>["call"];
11
+ type Listed = z.input<typeof ChatEntry>;
12
+ type Input<M extends keyof (typeof chat)["methods"]> = z.output<(typeof chat)["methods"][M]["input"]>;
13
+ type Emitted<E extends keyof (typeof chat)["events"]> = z.input<(typeof chat)["events"][E]["payload"]>;
14
+ export declare function createChats(options: {
15
+ store: Store;
16
+ /** The agent's model, and what a request to it says and offers, as its looper asks for them. */
17
+ model: Model;
18
+ request(): Promise<{
19
+ instructions: string;
20
+ tools: Tool[];
21
+ model?: string | undefined;
22
+ }>;
23
+ /** Whether the agent is stopped when its chats are first held. */
24
+ stopped: boolean;
25
+ emit: {
26
+ message(message: Emitted<"message">): void;
27
+ delta(delta: Emitted<"delta">): void;
28
+ status(status: Emitted<"status">): void;
29
+ chat(entry: Listed): void;
30
+ };
31
+ log: Log;
32
+ }): {
33
+ /**
34
+ * Say a message in a chat, or in a new chat it starts. With no turn in the chat it starts one;
35
+ * a turn running there takes it at its next model request.
36
+ */
37
+ send({ chat, text }: Input<"send">): Promise<{
38
+ chat: string;
39
+ messageId: string;
40
+ }>;
41
+ history: ({ chat, before, limit }: Input<"history">) => Promise<{
42
+ messages: import("@agentorg/looper").Shown[];
43
+ more: boolean;
44
+ }>;
45
+ /** What the agent is doing now. */
46
+ state: () => {
47
+ state: "idle" | "working";
48
+ };
49
+ /**
50
+ * The chats after `before` in the list, the one a message was last sent in first. `before`
51
+ * holds its place whether it is archived or not, so a page never leaves out a chat that hasn't
52
+ * moved since the page before it.
53
+ */
54
+ list({ archived, before, limit }: Input<"list">): Promise<{
55
+ chats: {
56
+ id: string;
57
+ title: string;
58
+ at: string;
59
+ latest?: {
60
+ id: string;
61
+ at: string;
62
+ } | undefined;
63
+ problem?: {
64
+ code: string;
65
+ message: string;
66
+ } | undefined;
67
+ archived: boolean;
68
+ }[];
69
+ more: boolean;
70
+ }>;
71
+ rename({ chat, title }: Input<"rename">): Promise<{}>;
72
+ archive({ chat, archived }: Input<"archive">): Promise<{}>;
73
+ /**
74
+ * Stop the agent: its turns are cut, and none starts until it is started. A call already
75
+ * running finishes first, so this answers when nothing more will be written. Its chats stay as
76
+ * they are, to be read.
77
+ */
78
+ stop: () => Promise<void>;
79
+ start: () => void;
80
+ /** Go on with the turns that were cut off when the agent last ran, each once. */
81
+ resume(): Promise<void>;
82
+ /**
83
+ * Close for good: its turns are cut, and none starts after. They stay marked, so the engine
84
+ * that opens this store next goes on with them.
85
+ */
86
+ close: () => Promise<void>;
87
+ /** Settles when every chat's latest turn has written all it will. */
88
+ settled(): Promise<void>;
89
+ /** Streamed text of the model request running now. */
90
+ delta(requestId: string, text: string): void;
91
+ };
92
+ export {};
@@ -0,0 +1,357 @@
1
+ /**
2
+ * An agent's chats: each one's entry in the store, and the looper's thread it is. A chat is made by
3
+ * the message that starts it and is never deleted. The entries are read when a chat is first asked
4
+ * for, all of them, and then stay in memory.
5
+ */
6
+ import { CHAT_TITLE_MAX, } from "@agentorg/interfaces";
7
+ import { createLooper, Entry, Refusal, textOf, } from "@agentorg/looper";
8
+ import { Refused } from "@agentorg/sdk";
9
+ import { z } from "zod";
10
+ import { head, relayed } from "./tools.js";
11
+ /** A chat's entry is kept under `chats/<id>`. */
12
+ const ENTRIES = "chats/";
13
+ /**
14
+ * The looper's keys in the agent's store. A chat is a thread by its id, and a thread's record is
15
+ * where a chat's has always been, under `chat/<id>/`; anything else the looper keeps is under
16
+ * `loop/`. A list is of one or of the other, never across both. What the store refuses, the looper
17
+ * is told as its own refusal.
18
+ */
19
+ const THREADS = "thread/";
20
+ const CHATS = "chat/";
21
+ const REST = "loop/";
22
+ const toStore = (key) => key.startsWith(THREADS) ? CHATS + key.slice(THREADS.length) : REST + key;
23
+ const fromStore = (key) => key.startsWith(CHATS) ? THREADS + key.slice(CHATS.length) : key.slice(REST.length);
24
+ function forLooper(store) {
25
+ return {
26
+ get: ({ key }) => relayed(store.get({ key: toStore(key) })),
27
+ set: ({ key, value }) => relayed(store.set({ key: toStore(key), value })),
28
+ delete: ({ key }) => relayed(store.delete({ key: toStore(key) })),
29
+ async list({ prefix = "", after, limit }) {
30
+ const page = await relayed(store.list({
31
+ prefix: toStore(prefix),
32
+ ...(after === undefined ? {} : { after: toStore(after) }),
33
+ ...(limit === undefined ? {} : { limit }),
34
+ }));
35
+ return {
36
+ keys: page.keys.map(fromStore),
37
+ next: page.next === null ? null : fromStore(page.next),
38
+ };
39
+ },
40
+ };
41
+ }
42
+ /**
43
+ * The looper as the chats call it: every call into it passes here. What the looper refuses is
44
+ * refused as the chat's, and what the store refused comes back as the store's own error.
45
+ */
46
+ function forChats(looper) {
47
+ const outward = (error) => {
48
+ if (!(error instanceof Refusal))
49
+ throw error;
50
+ throw error.cause ?? new Refused(error.code, error.message);
51
+ };
52
+ return new Proxy(looper, {
53
+ get(target, name, receiver) {
54
+ const member = Reflect.get(target, name, receiver);
55
+ if (typeof member !== "function")
56
+ return member;
57
+ return (...given) => {
58
+ try {
59
+ const result = member.apply(target, given);
60
+ return result instanceof Promise ? result.catch(outward) : result;
61
+ }
62
+ catch (error) {
63
+ return outward(error);
64
+ }
65
+ };
66
+ },
67
+ });
68
+ }
69
+ /** Where the one conversation an agent had before it had chats was kept. */
70
+ const LEGACY = "msg/";
71
+ /** Stored values read at once when the entries, or that conversation, are first loaded. */
72
+ const READS = 16;
73
+ /** The chat that the one conversation an agent had before it had chats becomes. */
74
+ const FIRST = "first";
75
+ const PAGE = 50;
76
+ /** What is kept of a chat beside its record. */
77
+ const Stored = z.object({
78
+ title: z.string(),
79
+ at: z.string(),
80
+ /** Its place in the list: the highest is the chat a message was last sent in. */
81
+ order: z.number(),
82
+ latest: z.object({ id: z.string(), at: z.string() }).optional(),
83
+ /** Why a message in it got no answer, until its next reply. */
84
+ problem: z.object({ code: z.string(), message: z.string() }).optional(),
85
+ archived: z.boolean(),
86
+ });
87
+ /** A title from a message: its first line with anything in it, on one line. */
88
+ const titleOf = (text) => head((text.split("\n").find((line) => /\S/.test(line)) ?? "").replace(/\s+/g, " ").trim(), CHAT_TITLE_MAX);
89
+ /** Every key under `prefix`, in order. */
90
+ async function keysUnder(store, prefix) {
91
+ const keys = [];
92
+ let after;
93
+ do {
94
+ const page = await store.list({ prefix, limit: 1000, ...(after ? { after } : {}) });
95
+ keys.push(...page.keys);
96
+ after = page.next ?? undefined;
97
+ } while (after);
98
+ return keys;
99
+ }
100
+ export function createChats(options) {
101
+ const { store, emit, log } = options;
102
+ /** The highest place in the list given so far. */
103
+ let top = 0;
104
+ /** Entries being written, one after another, so the latest written is the latest said. */
105
+ let writing = Promise.resolve();
106
+ /** The chats, by id, once their entries are read. */
107
+ const chats = new Map();
108
+ let loaded;
109
+ /** The chats whose loops are at work now: the agent is working while there is one. */
110
+ const atWork = new Set();
111
+ const stateNow = () => ({ state: atWork.size > 0 ? "working" : "idle" });
112
+ /** The chats' loops: a chat is the looper's thread of the same name. */
113
+ const looper = forChats(createLooper({
114
+ store: forLooper(store),
115
+ model: options.model,
116
+ request: options.request,
117
+ out: {
118
+ message(thread, message) {
119
+ const held = chats.get(thread);
120
+ if (held)
121
+ sent(held, message);
122
+ emit.message({ ...message, chat: thread });
123
+ },
124
+ delta: (thread, id, text) => emit.delta({ chat: thread, id, text }),
125
+ status(thread, status) {
126
+ const was = atWork.size > 0;
127
+ if (status.state === "thinking" || status.state === "tool")
128
+ atWork.add(thread);
129
+ else
130
+ atWork.delete(thread);
131
+ // A turn that failed left its chat's message with no answer: the chat is told why,
132
+ // before the agent is said to be idle.
133
+ const held = chats.get(thread);
134
+ if (status.state === "error" && held) {
135
+ const { code, message } = status.detail;
136
+ held.stored.problem = { code: head(code, 128), message: head(message, 2000) };
137
+ told(held);
138
+ }
139
+ if (atWork.size > 0 !== was)
140
+ emit.status(stateNow());
141
+ },
142
+ },
143
+ stopped: options.stopped,
144
+ log,
145
+ }));
146
+ const entryOf = ({ id, stored }) => ({
147
+ id,
148
+ title: stored.title,
149
+ at: stored.at,
150
+ ...(stored.latest ? { latest: stored.latest } : {}),
151
+ ...(stored.problem ? { problem: stored.problem } : {}),
152
+ archived: stored.archived,
153
+ });
154
+ /** Write a chat's entry as it now is, after any write before it. */
155
+ const save = (held) => {
156
+ const value = { ...held.stored };
157
+ const written = writing.then(() => store.set({ key: ENTRIES + held.id, value }));
158
+ writing = written.catch(() => { });
159
+ return written;
160
+ };
161
+ /** Say a chat's entry as it now is; its write follows. */
162
+ const told = (held) => {
163
+ // What it tells is already so: an entry that can't be written is behind until the next.
164
+ save(held).catch((error) => log.error("A chat's entry couldn't be stored.", { chat: held.id, error: String(error) }));
165
+ emit.chat(entryOf(held));
166
+ };
167
+ /**
168
+ * A message sent in a chat moves it to the front of the list; a reply is what is new in it, and
169
+ * its message has its answer.
170
+ */
171
+ const sent = (held, message) => {
172
+ if (message.role === "tool")
173
+ return;
174
+ held.stored.order = ++top;
175
+ if (message.role === "assistant") {
176
+ held.stored.latest = { id: message.id, at: message.at };
177
+ delete held.stored.problem;
178
+ }
179
+ told(held);
180
+ };
181
+ /** Change what a chat is called or where it is listed: a change the store refuses isn't made. */
182
+ const keep = async (held, key, value) => {
183
+ const was = held.stored[key];
184
+ held.stored[key] = value;
185
+ try {
186
+ await save(held);
187
+ }
188
+ catch (error) {
189
+ held.stored[key] = was;
190
+ throw error;
191
+ }
192
+ emit.chat(entryOf(held));
193
+ };
194
+ /**
195
+ * The conversation an agent had before it had chats becomes its first chat. Its entry is written
196
+ * before any message moves, from all of them, so a move cut short goes on from where it stopped
197
+ * with the entry it began with.
198
+ */
199
+ const adopt = async () => {
200
+ const keys = await keysUnder(store, LEGACY);
201
+ if (keys.length === 0)
202
+ return;
203
+ const values = [];
204
+ for (let at = 0; at < keys.length; at += READS)
205
+ values.push(...(await Promise.all(keys.slice(at, at + READS).map((key) => store.get({ key })))).map((read) => read.value));
206
+ if (!Stored.safeParse((await store.get({ key: ENTRIES + FIRST })).value).success) {
207
+ const read = values.flatMap((value) => {
208
+ const entry = Entry.safeParse(value);
209
+ return entry.success ? [entry.data] : [];
210
+ });
211
+ const reply = read.findLast((entry) => entry.role === "assistant");
212
+ const opening = read.find((entry) => entry.role === "user") ?? read[0];
213
+ const stored = {
214
+ title: opening ? titleOf(textOf(opening)) : "",
215
+ at: read[0]?.at ?? new Date().toISOString(),
216
+ // Behind every chat started since.
217
+ order: 0,
218
+ ...(reply ? { latest: { id: reply.id, at: reply.at } } : {}),
219
+ archived: false,
220
+ };
221
+ await store.set({ key: ENTRIES + FIRST, value: stored });
222
+ }
223
+ for (const [i, key] of keys.entries()) {
224
+ if (values[i] !== undefined)
225
+ await store.set({
226
+ key: `${CHATS}${FIRST}/${key}`,
227
+ value: values[i],
228
+ });
229
+ await store.delete({ key });
230
+ }
231
+ log.info("The conversation it had is now its first chat.", { messages: keys.length });
232
+ };
233
+ const load = () => {
234
+ if (loaded)
235
+ return loaded;
236
+ const attempt = (async () => {
237
+ await adopt();
238
+ const keys = await keysUnder(store, ENTRIES);
239
+ for (let at = 0; at < keys.length; at += READS) {
240
+ const some = keys.slice(at, at + READS);
241
+ const values = await Promise.all(some.map((key) => store.get({ key })));
242
+ some.forEach((key, i) => {
243
+ const stored = Stored.safeParse(values[i]?.value);
244
+ const id = key.slice(ENTRIES.length);
245
+ if (!stored.success) {
246
+ log.warn("A chat's entry didn't read back; the chat is left out.", { key });
247
+ return;
248
+ }
249
+ chats.set(id, { id, stored: stored.data });
250
+ top = Math.max(top, stored.data.order);
251
+ });
252
+ }
253
+ return chats;
254
+ })();
255
+ loaded = attempt;
256
+ attempt.catch(() => {
257
+ if (loaded === attempt)
258
+ loaded = undefined;
259
+ });
260
+ return attempt;
261
+ };
262
+ const heldOf = async (id) => {
263
+ const held = (await load()).get(id);
264
+ if (!held)
265
+ throw new Refused("unknown", "This agent has no such chat.");
266
+ return held;
267
+ };
268
+ return {
269
+ /**
270
+ * Say a message in a chat, or in a new chat it starts. With no turn in the chat it starts one;
271
+ * a turn running there takes it at its next model request.
272
+ */
273
+ async send({ chat, text }) {
274
+ if (chat !== undefined) {
275
+ await heldOf(chat);
276
+ const { messageId } = await looper.send(chat, text);
277
+ return { chat, messageId };
278
+ }
279
+ const found = await load();
280
+ const held = {
281
+ id: crypto.randomUUID(),
282
+ stored: {
283
+ title: titleOf(text),
284
+ at: new Date().toISOString(),
285
+ order: ++top,
286
+ archived: false,
287
+ },
288
+ };
289
+ try {
290
+ // Its entry first: a record with no entry would be a chat nobody can find.
291
+ await store.set({ key: ENTRIES + held.id, value: held.stored });
292
+ found.set(held.id, held);
293
+ const { messageId } = await looper.send(held.id, text);
294
+ return { chat: held.id, messageId };
295
+ }
296
+ catch (error) {
297
+ found.delete(held.id);
298
+ await store.delete({ key: ENTRIES + held.id }).catch(() => { });
299
+ throw error;
300
+ }
301
+ },
302
+ history: async ({ chat, before, limit }) => looper.page((await heldOf(chat)).id, before, limit ?? PAGE),
303
+ /** What the agent is doing now. */
304
+ state: stateNow,
305
+ /**
306
+ * The chats after `before` in the list, the one a message was last sent in first. `before`
307
+ * holds its place whether it is archived or not, so a page never leaves out a chat that hasn't
308
+ * moved since the page before it.
309
+ */
310
+ async list({ archived = false, before, limit = PAGE }) {
311
+ const found = await load();
312
+ const mark = before === undefined ? undefined : found.get(before);
313
+ if (before !== undefined && !mark)
314
+ return { chats: [], more: false };
315
+ const rest = [...found.values()]
316
+ .filter(({ stored }) => stored.archived === archived && (!mark || stored.order < mark.stored.order))
317
+ .sort((a, b) => b.stored.order - a.stored.order);
318
+ return { chats: rest.slice(0, limit).map(entryOf), more: rest.length > limit };
319
+ },
320
+ async rename({ chat, title }) {
321
+ await keep(await heldOf(chat), "title", titleOf(title));
322
+ return {};
323
+ },
324
+ async archive({ chat, archived }) {
325
+ await keep(await heldOf(chat), "archived", archived);
326
+ return {};
327
+ },
328
+ /**
329
+ * Stop the agent: its turns are cut, and none starts until it is started. A call already
330
+ * running finishes first, so this answers when nothing more will be written. Its chats stay as
331
+ * they are, to be read.
332
+ */
333
+ stop: () => looper.stop(),
334
+ start: () => looper.start(),
335
+ /** Go on with the turns that were cut off when the agent last ran, each once. */
336
+ async resume() {
337
+ // The chats first: what a turn says moves its chat in the list.
338
+ await load();
339
+ await looper.resume();
340
+ },
341
+ /**
342
+ * Close for good: its turns are cut, and none starts after. They stay marked, so the engine
343
+ * that opens this store next goes on with them.
344
+ */
345
+ close: () => looper.close(),
346
+ /** Settles when every chat's latest turn has written all it will. */
347
+ async settled() {
348
+ await loaded?.catch(() => undefined);
349
+ await looper.settled();
350
+ await writing;
351
+ },
352
+ /** Streamed text of the model request running now. */
353
+ delta(requestId, text) {
354
+ looper.delta(requestId, text);
355
+ },
356
+ };
357
+ }