@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,42 @@
1
+ /** Running the functions a model calls, and what is kept of their output. */
2
+ import { codeOf } from "./types.js";
3
+ /** A function's output keeps this many characters, so one result can't fill a request. */
4
+ export const MAX_OUTPUT = 30_000;
5
+ /**
6
+ * `text`, or its first and last `MAX_OUTPUT / 2` characters with what was cut between them: a
7
+ * failing command's error is at the end, and what it was doing at the start.
8
+ */
9
+ export function capped(text) {
10
+ if (text.length <= MAX_OUTPUT)
11
+ return text;
12
+ // Between characters: never half of a surrogate pair at either cut.
13
+ const head = text.slice(0, MAX_OUTPUT / 2).replace(/[\uD800-\uDBFF]$/, "");
14
+ const tail = text.slice(-MAX_OUTPUT / 2).replace(/^[\uDC00-\uDFFF]/, "");
15
+ return `${head}\n… [${text.length - head.length - tail.length} characters cut] …\n${tail}`;
16
+ }
17
+ const failure = ({ code, message }) => JSON.stringify({ error: { code, message } });
18
+ /** Run a function call: the result, or the refusal, as the function's output. */
19
+ export async function runTool(tools, name, args) {
20
+ const refused = (code, message) => ({
21
+ output: failure({ code, message }),
22
+ ok: false,
23
+ code,
24
+ });
25
+ const found = tools.find((tool) => tool.name === name);
26
+ if (!found)
27
+ return refused("unknown_tool", `No tool is named ${name.slice(0, 64)}.`);
28
+ let input;
29
+ try {
30
+ input = args.trim() === "" ? {} : JSON.parse(args);
31
+ }
32
+ catch {
33
+ return refused("invalid", "The arguments aren't JSON.");
34
+ }
35
+ try {
36
+ return await found.run(input);
37
+ }
38
+ catch (error) {
39
+ const { code, message } = codeOf(error);
40
+ return refused(code, message);
41
+ }
42
+ }
@@ -0,0 +1,147 @@
1
+ /**
2
+ * What the looper is given and what it gives back, in its own words. Whoever hosts it maps its own
3
+ * world onto these: the looper names no interface, no chat and no agent.
4
+ */
5
+ import { z } from "zod";
6
+ /** A JSON value. */
7
+ export type Json = string | number | boolean | null | Json[] | {
8
+ [key: string]: Json;
9
+ };
10
+ /** One item of a conversation as a model reads it: something said, a function call, or its output. */
11
+ export declare const Item: z.ZodDiscriminatedUnion<[z.ZodObject<{
12
+ type: z.ZodLiteral<"message">;
13
+ role: z.ZodEnum<{
14
+ assistant: "assistant";
15
+ user: "user";
16
+ }>;
17
+ content: z.ZodString;
18
+ }, z.core.$strip>, z.ZodObject<{
19
+ type: z.ZodLiteral<"function_call">;
20
+ callId: z.ZodString;
21
+ name: z.ZodString;
22
+ arguments: z.ZodString;
23
+ }, z.core.$strip>, z.ZodObject<{
24
+ type: z.ZodLiteral<"function_call_output">;
25
+ callId: z.ZodString;
26
+ output: z.ZodString;
27
+ }, z.core.$strip>], "type">;
28
+ export type Item = z.output<typeof Item>;
29
+ /** What a model gives back: something it says, or a function it calls. */
30
+ export type OutputItem = Exclude<Item, {
31
+ type: "function_call_output";
32
+ }>;
33
+ /** A function the model may call, as a request describes it. */
34
+ export interface ToolSpec {
35
+ name: string;
36
+ description?: string;
37
+ /** The JSON Schema of its arguments. */
38
+ parameters: Record<string, Json>;
39
+ }
40
+ /** How a function call ended, as the model and the record see it. */
41
+ export interface Outcome {
42
+ output: string;
43
+ ok: boolean;
44
+ /** Why it didn't, when `ok` is false. */
45
+ code?: string;
46
+ }
47
+ /**
48
+ * A function the model may call, with the way to run it. `run` gets the call's arguments, parsed;
49
+ * what it throws is the call's output, as a refusal: with its code when it is a `Refusal`.
50
+ */
51
+ export interface Tool extends ToolSpec {
52
+ run(input: unknown): Promise<Outcome>;
53
+ }
54
+ /**
55
+ * The model: one stateless answer to a whole conversation. A request that can't be answered rejects,
56
+ * with a `Refusal` when there is a code to show. Text it writes while it answers is given to the
57
+ * looper's `delta`, with the request's id.
58
+ */
59
+ export interface Model {
60
+ respond(request: {
61
+ requestId: string;
62
+ model?: string;
63
+ instructions: string;
64
+ input: Item[];
65
+ tools: ToolSpec[];
66
+ }): Promise<{
67
+ output: OutputItem[];
68
+ }>;
69
+ /** Stop the answer to `requestId`, if it is still being made; its `respond` then rejects. */
70
+ cancel(request: {
71
+ requestId: string;
72
+ }): Promise<unknown>;
73
+ }
74
+ /** Where the looper keeps its records: values by key, listed in key order a page at a time. */
75
+ export interface Store {
76
+ get(input: {
77
+ key: string;
78
+ }): Promise<{
79
+ value?: Json | undefined;
80
+ }>;
81
+ set(input: {
82
+ key: string;
83
+ value: Json;
84
+ }): Promise<unknown>;
85
+ delete(input: {
86
+ key: string;
87
+ }): Promise<unknown>;
88
+ list(input: {
89
+ prefix?: string;
90
+ after?: string;
91
+ limit?: number;
92
+ }): Promise<{
93
+ keys: string[];
94
+ next: string | null;
95
+ }>;
96
+ }
97
+ /** Where the looper says what an operator may want to know; nothing a thread shows. */
98
+ export interface Log {
99
+ info(message: string, fields?: Record<string, unknown>): void;
100
+ warn(message: string, fields?: Record<string, unknown>): void;
101
+ error(message: string, fields?: Record<string, unknown>): void;
102
+ }
103
+ /**
104
+ * A message as a thread shows it. A `tool` message tells what the loop did: with `tool`, the call
105
+ * it stands for, said as `running` when it starts and again under the same id when it ends;
106
+ * without, its `text` says it in one line, as for calls that never ran or a turn that goes on
107
+ * after it was cut off.
108
+ */
109
+ export interface Shown {
110
+ id: string;
111
+ role: "user" | "assistant" | "tool";
112
+ text: string;
113
+ /** An ISO 8601 time. */
114
+ at: string;
115
+ tool?: {
116
+ name: string;
117
+ state: "running" | "done" | "refused";
118
+ input?: string;
119
+ output?: string;
120
+ };
121
+ }
122
+ /** What a loop is doing. On `error`, `detail.code` is the refusal's code. */
123
+ export type Status = {
124
+ state: "idle" | "thinking" | "tool";
125
+ } | {
126
+ state: "error";
127
+ detail: {
128
+ code: string;
129
+ message: string;
130
+ };
131
+ };
132
+ /**
133
+ * Something refused, with a stable code a host can show or map. A host that refuses for a reason of
134
+ * its own can keep that reason as the `cause`.
135
+ */
136
+ export declare class Refusal extends Error {
137
+ readonly name = "Refusal";
138
+ readonly code: string;
139
+ constructor(code: string, message: string, options?: {
140
+ cause?: unknown;
141
+ });
142
+ }
143
+ /** The code and message of anything a call or a turn can throw. */
144
+ export declare function codeOf(error: unknown): {
145
+ code: string;
146
+ message: string;
147
+ };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * What the looper is given and what it gives back, in its own words. Whoever hosts it maps its own
3
+ * world onto these: the looper names no interface, no chat and no agent.
4
+ */
5
+ import { z } from "zod";
6
+ /** What one text of a model request can hold, and one name in it. */
7
+ const Text = z.string().max(200_000);
8
+ const Name = z.string().min(1).max(256);
9
+ /** One item of a conversation as a model reads it: something said, a function call, or its output. */
10
+ export const Item = z.discriminatedUnion("type", [
11
+ z.object({ type: z.literal("message"), role: z.enum(["user", "assistant"]), content: Text }),
12
+ z.object({ type: z.literal("function_call"), callId: Name, name: Name, arguments: Text }),
13
+ z.object({ type: z.literal("function_call_output"), callId: Name, output: Text }),
14
+ ]);
15
+ /**
16
+ * Something refused, with a stable code a host can show or map. A host that refuses for a reason of
17
+ * its own can keep that reason as the `cause`.
18
+ */
19
+ export class Refusal extends Error {
20
+ name = "Refusal";
21
+ code;
22
+ constructor(code, message, options) {
23
+ super(message, options);
24
+ this.code = code;
25
+ }
26
+ }
27
+ /** The code and message of anything a call or a turn can throw. */
28
+ export function codeOf(error) {
29
+ if (error instanceof Refusal)
30
+ return { code: error.code, message: error.message };
31
+ return { code: "failed", message: "The call failed." };
32
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@agentorg/looper",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "description": "An agent's loops: a model and its tools run on a record, taking messages by thread. It knows nothing of what hosts it.",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/src/index.d.ts",
11
+ "default": "./dist/src/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist/src"
16
+ ],
17
+ "scripts": {
18
+ "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json",
19
+ "test": "node --test \"dist/test/**/*.test.js\""
20
+ },
21
+ "dependencies": {
22
+ "zod": "^4.6.7"
23
+ }
24
+ }
@@ -0,0 +1,18 @@
1
+ import type { Activity } from "./control.js";
2
+ interface Entry extends Activity {
3
+ seq: number;
4
+ at: string;
5
+ }
6
+ export declare function createActivity(path: string, maxBytes?: number): {
7
+ add(entry: Activity): void;
8
+ /** Newest first; with `agent`, those it made or that were about it. */
9
+ read({ agent, before, limit }: {
10
+ agent?: string;
11
+ before?: number;
12
+ limit?: number;
13
+ }): {
14
+ entries: Entry[];
15
+ more: boolean;
16
+ };
17
+ };
18
+ export {};
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The control log: one line for each control call that changed something, and for each refusal.
3
+ * Append-only, and kept to a size: past it, the older half goes. It holds no message an agent
4
+ * sent, and no secret.
5
+ */
6
+ import { appendFileSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
7
+ /** Past this, the older half of the log goes. */
8
+ const MAX_BYTES = 4 * 1024 * 1024;
9
+ export function createActivity(path, maxBytes = MAX_BYTES) {
10
+ const read = () => {
11
+ let text;
12
+ try {
13
+ text = readFileSync(path, "utf8");
14
+ }
15
+ catch {
16
+ return [];
17
+ }
18
+ return text.split("\n").flatMap((line) => {
19
+ try {
20
+ const entry = line ? JSON.parse(line) : undefined;
21
+ return entry && Number.isInteger(entry.seq) ? [entry] : [];
22
+ }
23
+ catch {
24
+ return [];
25
+ }
26
+ });
27
+ };
28
+ const sizeOf = () => {
29
+ try {
30
+ return statSync(path).size;
31
+ }
32
+ catch {
33
+ return 0;
34
+ }
35
+ };
36
+ const kept = read();
37
+ let next = Math.max(-1, ...kept.map((one) => one.seq)) + 1;
38
+ let bytes = sizeOf();
39
+ // A line cut off by a crash ends here, so the next doesn't join it.
40
+ let torn = bytes > 0 && !readFileSync(path, "utf8").endsWith("\n");
41
+ return {
42
+ add(entry) {
43
+ const line = `${JSON.stringify({ seq: next++, at: new Date().toISOString(), ...entry })}\n`;
44
+ appendFileSync(path, torn ? `\n${line}` : line, { mode: 0o600 });
45
+ torn = false;
46
+ bytes += Buffer.byteLength(line);
47
+ if (bytes <= maxBytes)
48
+ return;
49
+ const all = read();
50
+ const newer = all.slice(Math.floor(all.length / 2));
51
+ const text = newer.map((one) => `${JSON.stringify(one)}\n`).join("");
52
+ writeFileSync(`${path}.tmp`, text, { mode: 0o600 });
53
+ renameSync(`${path}.tmp`, path);
54
+ bytes = Buffer.byteLength(text);
55
+ },
56
+ /** Newest first; with `agent`, those it made or that were about it. */
57
+ read({ agent, before, limit = 50 }) {
58
+ const matching = read()
59
+ .filter((one) => before === undefined || one.seq < before)
60
+ .filter((one) => agent === undefined || one.caller === agent || one.target === agent)
61
+ .reverse();
62
+ return { entries: matching.slice(0, limit), more: matching.length > limit };
63
+ },
64
+ };
65
+ }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * AgentOrg control: what lets an agent reach what the person's own surface reaches, within the
3
+ * scopes the person set on its unit. The agent holds no authority of the Hub's. It calls
4
+ * management's tools, and management, which holds that authority, works out who is calling, what
5
+ * that caller's unit allows, and whether the target is within its reach.
6
+ */
7
+ import { type chat, type FieldValues, type Problem, type Template, type Unit } from "@agentorg/interfaces";
8
+ import { type Slot } from "@agentorg/sdk";
9
+ import { z } from "zod";
10
+ import type { AgentRecord, Offer, StackInput } from "./stack.js";
11
+ export declare const AGENTS_UNIT = "control";
12
+ export declare const AGENTS_SLOT = "control";
13
+ /** How many agents one agent may have alive at once, at most and unless the person says. */
14
+ export declare const LIMIT_MAX = 8;
15
+ /** How many levels below an agent may exist, at most. */
16
+ export declare const DEPTH_MAX = 3;
17
+ /** Above this many agents in the home, none is made by an agent. They share one plan. */
18
+ export declare const HOME_CAP = 24;
19
+ export declare const skillFile: (path: string) => "---\nname: delegating\ndescription: How to hand work to agents of your own and see it through, and what else your control tools reach. Use it before creating an agent, and whenever you have work that can run apart from yours.\n---\nYour `control` connection's tools reach what the person allowed you: agents, and perhaps connections, skills and templates. A tool you don't have is one you weren't given.\n\n## Before you create an agent\n\nDo the work yourself when it is short. An agent costs model usage from the plan everyone here shares, and you have a limit on how many you can have. Use one when work can run apart from yours, or needs a shape you were not given.\n\nThere is one create tool per template you may use. Read its description and fields. Give the agent a plain name and a purpose: one sentence on what it is for, which it will be told. Fields you leave out keep the template's value.\n\n## Working with it\n\n- `agent_send` gives it a message and returns at once. It works on its own after that. Your name is on the message's first line.\n- A message with no chat named starts a new chat with it, and tells you which. Name that chat to go on in it. Start another only for work that is apart from the first.\n- `agent_chats` lists its chats and says whether it is working. A chat with a `problem` has a message that got no answer: send it another once the problem is dealt with. `agent_read` shows what was said in one. Check back when you need the result, rather than after every step.\n- Say what you want back and in what form. It knows only what you send it and its purpose.\n\n## When it is done\n\n`agent_remove` it when its work is finished, so your limit is free for the next one. `agent_stop` it to keep it for later. You can remove only agents you made, and theirs. The person sees every agent you create on their Agents page, and every change you make through these tools, and can undo any of it.\n" | undefined;
20
+ type Values = z.infer<typeof FieldValues>;
21
+ type TheUnit = z.infer<typeof Unit>;
22
+ type TheAgent = z.infer<typeof AgentRecord>;
23
+ type TheTemplate = z.infer<typeof Template>;
24
+ type TheProblem = z.infer<typeof Problem>;
25
+ /** The agents unit's form, with what can be chosen today. */
26
+ export declare function agentsUnit(templates: {
27
+ value: string;
28
+ title: string;
29
+ description?: string;
30
+ }[], places: {
31
+ value: string;
32
+ title: string;
33
+ }[]): TheUnit;
34
+ /** A computer's reach: how far it can act, and what an agent sharing it is given. */
35
+ export interface Reach {
36
+ access: string;
37
+ browser: boolean;
38
+ connections: {
39
+ slot: string;
40
+ connection: string;
41
+ }[];
42
+ skills: string[];
43
+ /** Which service it is on, when it says. */
44
+ service?: string;
45
+ }
46
+ /** How far an agent's own computer reaches now. */
47
+ export declare function reachOf(record: TheAgent): Reach;
48
+ /** What an agents unit may not ask for, given the computer of the agent that holds it. */
49
+ export declare function reachProblems(values: Values, reach: {
50
+ access: string;
51
+ browser: boolean;
52
+ }): TheProblem[];
53
+ /** What the control tools use of an agent's chats. */
54
+ type ChatCalls = Pick<Slot<typeof chat>["call"], "send" | "history" | "list" | "state" | "rename">;
55
+ /** What management's own interfaces answer, called as the person would. */
56
+ type Person = (iface: "agents" | "connections" | "skills", method: string, input: object,
57
+ /** Who it's made as: the agent, so what it makes is recorded as its own. */
58
+ caller?: string) => Promise<any>;
59
+ /** One control call that changed something, or was refused: never a message or a secret. */
60
+ export interface Activity {
61
+ caller: string;
62
+ tool: string;
63
+ target?: string;
64
+ outcome: "done" | "refused";
65
+ reason?: string;
66
+ }
67
+ export interface ControlParts {
68
+ self: string;
69
+ records: {
70
+ agents: Record<string, TheAgent>;
71
+ };
72
+ creatingCount(): number;
73
+ catalog(): Promise<Offer[]>;
74
+ /** What is bound to an agent now, each as its slot and provider. */
75
+ boundTo(agent: string): Promise<Set<string>>;
76
+ templates(): TheTemplate[];
77
+ baseProviderNamed(name: string): Promise<string>;
78
+ serial<T>(key: string, work: () => T | Promise<T>): Promise<T>;
79
+ create(input: {
80
+ stack: StackInput;
81
+ name: string;
82
+ purpose: string;
83
+ }, caller: string, child: {
84
+ parent: {
85
+ agent: string;
86
+ name: string;
87
+ };
88
+ reach: Reach;
89
+ shares: {
90
+ slot: string;
91
+ connection: string;
92
+ }[];
93
+ skills: string[];
94
+ computer?: Reach;
95
+ }): Promise<{
96
+ agent: string;
97
+ }>;
98
+ nameOf(actor: string): Promise<string>;
99
+ /** A child's chat, once the Hub has told management of it. */
100
+ chatOf(agent: string): Promise<ChatCalls>;
101
+ statusOf(agent: string, provider: string): Promise<{
102
+ state: string;
103
+ detail?: string;
104
+ }>;
105
+ start(agent: string): Promise<unknown>;
106
+ stop(agent: string): Promise<unknown>;
107
+ remove(agent: string): Promise<unknown>;
108
+ /** Management's interfaces, as the person reaches them. */
109
+ person: Person;
110
+ /** Where each connection came from, to know which an agent made. */
111
+ madeBy(connection: string): string | undefined;
112
+ /** Whether the library has a skill of this name that this agent may see. */
113
+ hasSkill(name: string, caller: string): boolean;
114
+ /** The agent that saved a template, if one did. */
115
+ templateAuthor(id: string): string | undefined;
116
+ /** Keep a line of the control log. */
117
+ log(entry: Activity): void;
118
+ }
119
+ export declare function createControl(parts: ControlParts): {
120
+ list(caller: string): Promise<{
121
+ name: string;
122
+ description?: string | undefined;
123
+ inputSchema: Record<string, z.JSONType>;
124
+ }[]>;
125
+ /** A tool that ran and failed answers `failed`, for the caller's model to read. */
126
+ call(caller: string, name: string, input: unknown): Promise<{
127
+ output: string;
128
+ failed?: undefined;
129
+ } | {
130
+ output: string;
131
+ failed: true;
132
+ }>;
133
+ };
134
+ export {};