@agentorg/cli 0.0.5 → 0.0.6

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 (206) hide show
  1. package/README.md +18 -102
  2. package/dist/node_modules/@agentorg/hub/dist/src/hub-actor.d.ts +2 -7
  3. package/dist/node_modules/@agentorg/hub/dist/src/hub-actor.js +4 -144
  4. package/dist/node_modules/@agentorg/hub/dist/src/index.d.ts +1 -3
  5. package/dist/node_modules/@agentorg/hub/dist/src/index.js +1 -3
  6. package/dist/node_modules/@agentorg/hub/dist/src/router.d.ts +6 -57
  7. package/dist/node_modules/@agentorg/hub/dist/src/router.js +38 -413
  8. package/dist/node_modules/@agentorg/hub/dist/src/state.d.ts +17 -317
  9. package/dist/node_modules/@agentorg/hub/dist/src/state.js +42 -536
  10. package/dist/node_modules/@agentorg/hub/dist/src/validate.d.ts +1 -3
  11. package/dist/node_modules/@agentorg/hub/dist/src/validate.js +3 -15
  12. package/dist/node_modules/@agentorg/hub/package.json +0 -3
  13. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-provider.d.ts +132 -0
  14. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-provider.js +105 -0
  15. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-settings.d.ts +42 -0
  16. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-settings.js +53 -0
  17. package/dist/node_modules/@agentorg/interfaces/dist/src/chat.d.ts +15 -0
  18. package/dist/node_modules/@agentorg/interfaces/dist/src/chat.js +14 -0
  19. package/dist/node_modules/@agentorg/interfaces/dist/src/hub.d.ts +16 -286
  20. package/dist/node_modules/@agentorg/interfaces/dist/src/hub.js +17 -159
  21. package/dist/node_modules/@agentorg/interfaces/dist/src/index.d.ts +6 -8
  22. package/dist/node_modules/@agentorg/interfaces/dist/src/index.js +6 -8
  23. package/dist/node_modules/@agentorg/interfaces/dist/src/kv.d.ts +2 -2
  24. package/dist/node_modules/@agentorg/interfaces/dist/src/kv.js +2 -2
  25. package/dist/node_modules/@agentorg/interfaces/dist/src/manager.d.ts +272 -0
  26. package/dist/node_modules/@agentorg/interfaces/dist/src/manager.js +185 -0
  27. package/dist/node_modules/@agentorg/interfaces/dist/src/mcp-provider.d.ts +88 -0
  28. package/dist/node_modules/@agentorg/interfaces/dist/src/mcp-provider.js +78 -0
  29. package/dist/node_modules/@agentorg/interfaces/dist/src/tools.d.ts +39 -0
  30. package/dist/node_modules/@agentorg/interfaces/dist/src/tools.js +43 -0
  31. package/dist/node_modules/@agentorg/manager/dist/src/index.d.ts +1 -0
  32. package/dist/node_modules/@agentorg/manager/dist/src/index.js +1 -0
  33. package/dist/node_modules/@agentorg/manager/dist/src/manager.d.ts +21 -0
  34. package/dist/node_modules/@agentorg/manager/dist/src/manager.js +528 -0
  35. package/dist/node_modules/@agentorg/manager/dist/src/skills.d.ts +25 -0
  36. package/dist/node_modules/@agentorg/manager/dist/src/skills.js +145 -0
  37. package/dist/node_modules/@agentorg/manager/package.json +30 -0
  38. package/dist/node_modules/@agentorg/mcp/dist/src/connection.d.ts +33 -0
  39. package/dist/node_modules/@agentorg/mcp/dist/src/connection.js +290 -0
  40. package/dist/node_modules/@agentorg/mcp/dist/src/index.d.ts +1 -0
  41. package/dist/node_modules/@agentorg/mcp/dist/src/index.js +1 -0
  42. package/dist/node_modules/@agentorg/mcp/dist/src/kinds.d.ts +50 -0
  43. package/dist/node_modules/@agentorg/mcp/dist/src/kinds.js +69 -0
  44. package/dist/node_modules/@agentorg/mcp/dist/src/provider.d.ts +22 -0
  45. package/dist/node_modules/@agentorg/mcp/dist/src/provider.js +167 -0
  46. package/dist/node_modules/@agentorg/mcp/package.json +31 -0
  47. package/dist/node_modules/@agentorg/sdk/dist/src/cli.js +3 -23
  48. package/dist/node_modules/@agentorg/sdk/dist/src/client.d.ts +4 -25
  49. package/dist/node_modules/@agentorg/sdk/dist/src/client.js +5 -55
  50. package/dist/node_modules/@agentorg/sdk/dist/src/errors.d.ts +1 -1
  51. package/dist/node_modules/@agentorg/sdk/dist/src/errors.js +3 -3
  52. package/dist/node_modules/@agentorg/sdk/dist/src/index.d.ts +2 -2
  53. package/dist/node_modules/@agentorg/sdk/dist/src/index.js +1 -1
  54. package/dist/node_modules/@agentorg/sdk/dist/src/interface.d.ts +6 -34
  55. package/dist/node_modules/@agentorg/sdk/dist/src/interface.js +3 -24
  56. package/dist/node_modules/@agentorg/sdk/dist/src/module-host.d.ts +8 -17
  57. package/dist/node_modules/@agentorg/sdk/dist/src/module-host.js +15 -87
  58. package/dist/node_modules/@agentorg/sdk/dist/src/module.d.ts +10 -76
  59. package/dist/node_modules/@agentorg/sdk/dist/src/module.js +3 -23
  60. package/dist/node_modules/@agentorg/sdk/dist/src/person-commands.js +0 -5
  61. package/dist/node_modules/@agentorg/sdk/dist/src/runtime.d.ts +3 -27
  62. package/dist/node_modules/@agentorg/sdk/dist/src/runtime.js +5 -100
  63. package/dist/node_modules/@agentorg/sdk/dist/src/testing.d.ts +7 -8
  64. package/dist/node_modules/@agentorg/sdk/dist/src/testing.js +12 -24
  65. package/dist/node_modules/@agentorg/sdk/package.json +4 -37
  66. package/dist/node_modules/@agentorg/shell/dist/app.css +3435 -739
  67. package/dist/node_modules/@agentorg/shell/dist/app.js +204 -202
  68. package/dist/node_modules/@agentorg/shell/package.json +18 -10
  69. package/dist/node_modules/@agentorg/wire/dist/src/frames.d.ts +2 -3
  70. package/dist/node_modules/@agentorg/wire/dist/src/frames.js +2 -3
  71. package/dist/node_modules/@agentorg/wire/dist/src/ops.d.ts +5 -34
  72. package/dist/node_modules/@agentorg/wire/dist/src/ops.js +2 -17
  73. package/dist/node_modules/assistant/dist/src/agent.d.ts +62 -0
  74. package/dist/node_modules/assistant/dist/src/agent.js +226 -0
  75. package/dist/node_modules/assistant/dist/src/engine.d.ts +23 -0
  76. package/dist/node_modules/assistant/dist/src/engine.js +88 -0
  77. package/dist/node_modules/assistant/dist/src/history.d.ts +97 -0
  78. package/dist/node_modules/assistant/dist/src/history.js +235 -0
  79. package/dist/node_modules/assistant/dist/src/local-store.d.ts +3 -0
  80. package/dist/node_modules/assistant/dist/src/local-store.js +58 -0
  81. package/dist/node_modules/assistant/dist/src/provider.d.ts +21 -0
  82. package/dist/node_modules/assistant/dist/src/provider.js +231 -0
  83. package/dist/node_modules/assistant/dist/src/settings.d.ts +17 -0
  84. package/dist/node_modules/assistant/dist/src/settings.js +43 -0
  85. package/dist/node_modules/assistant/dist/src/tools.d.ts +74 -0
  86. package/dist/node_modules/assistant/dist/src/tools.js +123 -0
  87. package/dist/node_modules/assistant/package.json +29 -0
  88. package/dist/node_modules/chatgpt/dist/src/account.d.ts +52 -0
  89. package/dist/node_modules/chatgpt/dist/src/account.js +270 -0
  90. package/dist/node_modules/chatgpt/dist/src/encoding.d.ts +7 -0
  91. package/dist/node_modules/chatgpt/dist/src/encoding.js +20 -0
  92. package/dist/node_modules/chatgpt/dist/src/file-store.d.ts +9 -0
  93. package/dist/node_modules/chatgpt/dist/src/file-store.js +68 -0
  94. package/dist/node_modules/chatgpt/dist/src/index.d.ts +1 -0
  95. package/dist/node_modules/chatgpt/dist/src/index.js +1 -0
  96. package/dist/node_modules/chatgpt/dist/src/jwt.d.ts +15 -0
  97. package/dist/node_modules/chatgpt/dist/src/jwt.js +37 -0
  98. package/dist/node_modules/chatgpt/dist/src/oauth.d.ts +43 -0
  99. package/dist/node_modules/chatgpt/dist/src/oauth.js +104 -0
  100. package/dist/node_modules/chatgpt/dist/src/program.d.ts +23 -0
  101. package/dist/node_modules/chatgpt/dist/src/program.js +41 -0
  102. package/dist/node_modules/chatgpt/dist/src/responses.d.ts +54 -0
  103. package/dist/node_modules/chatgpt/dist/src/responses.js +300 -0
  104. package/dist/node_modules/chatgpt/dist/src/serve.d.ts +65 -0
  105. package/dist/node_modules/chatgpt/dist/src/serve.js +46 -0
  106. package/dist/node_modules/chatgpt/package.json +33 -0
  107. package/dist/src/api.d.ts +5 -34
  108. package/dist/src/api.js +6 -68
  109. package/dist/src/cli.js +3 -7
  110. package/dist/src/gateway.d.ts +6 -7
  111. package/dist/src/gateway.js +39 -285
  112. package/dist/src/index.d.ts +4 -5
  113. package/dist/src/index.js +3 -4
  114. package/dist/src/notes.d.ts +11 -0
  115. package/dist/src/notes.js +64 -0
  116. package/dist/src/oauth.d.ts +16 -0
  117. package/dist/src/oauth.js +46 -0
  118. package/dist/src/programs.d.ts +29 -0
  119. package/dist/src/programs.js +171 -0
  120. package/package.json +3 -11
  121. package/dist/bundled/index.json +0 -6
  122. package/dist/bundled/sha256-0e91cc3d0e9762b81abc2427b5496b20f383abcd6fb97d928a8d50e956b54d1f.agentorg +0 -0
  123. package/dist/bundled/sha256-1f64ca62a0209d767d6aa6c4feb50b0653d60f10bebbc301f79bd3a37e0153c1.agentorg +0 -0
  124. package/dist/bundled/sha256-4055f8fddf6b90f3d356543f554b2a9e9a2c4a8827a8774f8f87952dc1692331.agentorg +0 -0
  125. package/dist/bundled/sha256-e356ea3c1899138a8494baf521556831006f38534fa9e92ae873e7e6956c3a46.agentorg +0 -0
  126. package/dist/node_modules/@agentorg/hub/dist/src/build.d.ts +0 -17
  127. package/dist/node_modules/@agentorg/hub/dist/src/build.js +0 -120
  128. package/dist/node_modules/@agentorg/hub/dist/src/logs.d.ts +0 -33
  129. package/dist/node_modules/@agentorg/hub/dist/src/logs.js +0 -162
  130. package/dist/node_modules/@agentorg/hub/dist/src/net.d.ts +0 -41
  131. package/dist/node_modules/@agentorg/hub/dist/src/net.js +0 -265
  132. package/dist/node_modules/@agentorg/hub/dist/src/processes.d.ts +0 -78
  133. package/dist/node_modules/@agentorg/hub/dist/src/processes.js +0 -485
  134. package/dist/node_modules/@agentorg/hub/dist/src/storage.d.ts +0 -38
  135. package/dist/node_modules/@agentorg/hub/dist/src/storage.js +0 -194
  136. package/dist/node_modules/@agentorg/interfaces/dist/src/http-egress.d.ts +0 -6
  137. package/dist/node_modules/@agentorg/interfaces/dist/src/http-egress.js +0 -7
  138. package/dist/node_modules/@agentorg/interfaces/dist/src/installer.d.ts +0 -191
  139. package/dist/node_modules/@agentorg/interfaces/dist/src/installer.js +0 -136
  140. package/dist/node_modules/@agentorg/interfaces/dist/src/layout.d.ts +0 -47
  141. package/dist/node_modules/@agentorg/interfaces/dist/src/layout.js +0 -52
  142. package/dist/node_modules/@agentorg/interfaces/dist/src/rules.d.ts +0 -35
  143. package/dist/node_modules/@agentorg/interfaces/dist/src/rules.js +0 -37
  144. package/dist/node_modules/@agentorg/interfaces/dist/src/storage-admin.d.ts +0 -23
  145. package/dist/node_modules/@agentorg/interfaces/dist/src/storage-admin.js +0 -31
  146. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-shell.d.ts +0 -14
  147. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-shell.js +0 -26
  148. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-view.d.ts +0 -27
  149. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-view.js +0 -26
  150. package/dist/node_modules/@agentorg/kit/dist/src/chat.d.ts +0 -37
  151. package/dist/node_modules/@agentorg/kit/dist/src/chat.js +0 -131
  152. package/dist/node_modules/@agentorg/kit/dist/src/components.d.ts +0 -94
  153. package/dist/node_modules/@agentorg/kit/dist/src/components.js +0 -66
  154. package/dist/node_modules/@agentorg/kit/dist/src/icons.d.ts +0 -17
  155. package/dist/node_modules/@agentorg/kit/dist/src/icons.js +0 -30
  156. package/dist/node_modules/@agentorg/kit/dist/src/index.d.ts +0 -6
  157. package/dist/node_modules/@agentorg/kit/dist/src/index.js +0 -10
  158. package/dist/node_modules/@agentorg/kit/dist/src/markdown.d.ts +0 -9
  159. package/dist/node_modules/@agentorg/kit/dist/src/markdown.js +0 -14
  160. package/dist/node_modules/@agentorg/kit/dist/src/resizable.d.ts +0 -5
  161. package/dist/node_modules/@agentorg/kit/dist/src/resizable.js +0 -8
  162. package/dist/node_modules/@agentorg/kit/dist/src/styles.d.ts +0 -11
  163. package/dist/node_modules/@agentorg/kit/dist/src/styles.js +0 -166
  164. package/dist/node_modules/@agentorg/kit/package.json +0 -44
  165. package/dist/node_modules/@agentorg/sdk/dist/frame/runtime.js +0 -753
  166. package/dist/node_modules/@agentorg/sdk/dist/host/runner.js +0 -21963
  167. package/dist/node_modules/@agentorg/sdk/dist/src/build.d.ts +0 -2
  168. package/dist/node_modules/@agentorg/sdk/dist/src/build.js +0 -2
  169. package/dist/node_modules/@agentorg/sdk/dist/src/client-http.d.ts +0 -24
  170. package/dist/node_modules/@agentorg/sdk/dist/src/client-http.js +0 -247
  171. package/dist/node_modules/@agentorg/sdk/dist/src/describe.d.ts +0 -13
  172. package/dist/node_modules/@agentorg/sdk/dist/src/describe.js +0 -16
  173. package/dist/node_modules/@agentorg/sdk/dist/src/frame-base.d.ts +0 -8
  174. package/dist/node_modules/@agentorg/sdk/dist/src/frame-base.js +0 -64
  175. package/dist/node_modules/@agentorg/sdk/dist/src/frame-entry.d.ts +0 -1
  176. package/dist/node_modules/@agentorg/sdk/dist/src/frame-entry.js +0 -35
  177. package/dist/node_modules/@agentorg/sdk/dist/src/frame-host.d.ts +0 -57
  178. package/dist/node_modules/@agentorg/sdk/dist/src/frame-host.js +0 -293
  179. package/dist/node_modules/@agentorg/sdk/dist/src/frame-protocol.d.ts +0 -124
  180. package/dist/node_modules/@agentorg/sdk/dist/src/frame-protocol.js +0 -16
  181. package/dist/node_modules/@agentorg/sdk/dist/src/frame.d.ts +0 -25
  182. package/dist/node_modules/@agentorg/sdk/dist/src/frame.js +0 -248
  183. package/dist/node_modules/@agentorg/sdk/dist/src/host-main.d.ts +0 -1
  184. package/dist/node_modules/@agentorg/sdk/dist/src/host-main.js +0 -60
  185. package/dist/node_modules/@agentorg/sdk/dist/src/host.d.ts +0 -25
  186. package/dist/node_modules/@agentorg/sdk/dist/src/host.js +0 -92
  187. package/dist/node_modules/@agentorg/sdk/dist/src/manifest-api.d.ts +0 -2
  188. package/dist/node_modules/@agentorg/sdk/dist/src/manifest-api.js +0 -2
  189. package/dist/node_modules/@agentorg/sdk/dist/src/manifest.d.ts +0 -56
  190. package/dist/node_modules/@agentorg/sdk/dist/src/manifest.js +0 -165
  191. package/dist/node_modules/@agentorg/sdk/dist/src/package.d.ts +0 -60
  192. package/dist/node_modules/@agentorg/sdk/dist/src/package.js +0 -538
  193. package/dist/node_modules/@agentorg/sdk/dist/src/tar.d.ts +0 -7
  194. package/dist/node_modules/@agentorg/sdk/dist/src/tar.js +0 -71
  195. package/dist/node_modules/@agentorg/shell/dist/agent-bindings.js +0 -59
  196. package/dist/node_modules/@agentorg/shell/src/agent-bindings.ts +0 -107
  197. package/dist/src/frames.d.ts +0 -23
  198. package/dist/src/frames.js +0 -78
  199. package/dist/src/layout.d.ts +0 -44
  200. package/dist/src/layout.js +0 -90
  201. package/dist/src/model.d.ts +0 -54
  202. package/dist/src/model.js +0 -299
  203. package/dist/src/rules.d.ts +0 -71
  204. package/dist/src/rules.js +0 -157
  205. package/dist/src/transfer.d.ts +0 -30
  206. package/dist/src/transfer.js +0 -110
@@ -0,0 +1,46 @@
1
+ /** What the sign-in tab says, by outcome: `complete`'s refusal code, or `signed_in`. */
2
+ const SAYS = {
3
+ signed_in: "Signed in to ChatGPT. You can close this tab.",
4
+ denied: "You declined on ChatGPT's page. Start again from AgentOrg when you're ready.",
5
+ expired: "This sign-in expired. Start again from AgentOrg.",
6
+ };
7
+ const FAILED = "The sign-in didn't work. Start again from AgentOrg.";
8
+ /**
9
+ * `/oauth/chatgpt`: where ChatGPT sends the browser back. It hands the whole callback address to
10
+ * the person's `login.complete`, then sends the tab on to `?result=<outcome>`, an address without
11
+ * the sign-in's code, so the code stays out of the tab's address and history; that page says how
12
+ * it went and links back to the shell. The code is never logged or shown, and no page sends a
13
+ * referrer.
14
+ */
15
+ export function oauthRoute(person) {
16
+ return (request, response, url) => {
17
+ if (request.method !== "GET")
18
+ return void response.writeHead(405).end();
19
+ const result = url.searchParams.get("result");
20
+ if (result !== null && [...url.searchParams.keys()].length === 1)
21
+ return page(response, result === "signed_in" ? 200 : 400, Object.hasOwn(SAYS, result) ? SAYS[result] : FAILED);
22
+ const after = (outcome) => {
23
+ response.writeHead(303, {
24
+ Location: `${url.pathname}?result=${encodeURIComponent(outcome)}`,
25
+ "Cache-Control": "no-store",
26
+ "Referrer-Policy": "no-referrer",
27
+ });
28
+ response.end();
29
+ };
30
+ void person.call("login", "complete", { callbackUrl: url.href }).then(() => after("signed_in"), (error) => {
31
+ const code = error?.code;
32
+ after(typeof code === "string" && Object.hasOwn(SAYS, code) ? code : "failed");
33
+ });
34
+ };
35
+ }
36
+ function page(response, status, text) {
37
+ response.writeHead(status, {
38
+ "Content-Type": "text/html; charset=utf-8",
39
+ "Cache-Control": "no-store",
40
+ "Referrer-Policy": "no-referrer",
41
+ "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; frame-ancestors 'none'",
42
+ });
43
+ response.end(`<!doctype html><meta charset="utf-8"><title>AgentOrg</title>` +
44
+ `<style>body{font:15px system-ui,sans-serif;margin:20vh auto;max-width:28rem;padding:0 16px}</style>` +
45
+ `<p>${text}</p><p><a href="/">Back to AgentOrg</a></p>`);
46
+ }
@@ -0,0 +1,29 @@
1
+ import type { PersonCalls } from "./oauth.js";
2
+ export interface ProgramsOptions {
3
+ home: string;
4
+ hubUrl: string;
5
+ /** Where the first run says what it couldn't do. */
6
+ log?: (message: string) => void;
7
+ /** How ChatGPT's requests leave, instead of the network. For tests. */
8
+ fetch?: (request: Request, init: RequestInit) => Promise<Response>;
9
+ }
10
+ export interface Programs {
11
+ /** The Actors running now, by program. */
12
+ chatgpt?: string;
13
+ agents?: string;
14
+ mcp?: string;
15
+ management?: string;
16
+ /** Leave the Hub, in the order that lets each finish. What each keeps stays. */
17
+ close(): Promise<void>;
18
+ }
19
+ /**
20
+ * Close every Actor that runs a package, as an earlier release's do: the programs replace them.
21
+ * Before the Hub opens. Each stays listed as closed; the files it left in the home stay too, unread.
22
+ */
23
+ export declare function closePackageActors(home: string): void;
24
+ /**
25
+ * Make what is missing and start each program. A program whose Actor exists keeps it and its
26
+ * credential. A step that fails is logged, the programs that don't need it still start, and the
27
+ * next start tries again.
28
+ */
29
+ export declare function startPrograms(person: PersonCalls, options: ProgramsOptions): Promise<Programs>;
@@ -0,0 +1,171 @@
1
+ // The app's programs: ChatGPT, the agent provider, the MCP provider and management, each an Actor
2
+ // of its own that this process runs on its own channel, with its own private folder under the home.
3
+ // Every step reads what is there before it acts, so each start converges on the same system.
4
+ import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
5
+ import { join } from "node:path";
6
+ import { HubState, PERSON } from "@agentorg/hub";
7
+ import { startManager } from "@agentorg/manager";
8
+ import { startMcpProvider } from "@agentorg/mcp";
9
+ import { startAgentProvider } from "assistant/provider";
10
+ import { startChatGPT } from "chatgpt";
11
+ /**
12
+ * Close every Actor that runs a package, as an earlier release's do: the programs replace them.
13
+ * Before the Hub opens. Each stays listed as closed; the files it left in the home stay too, unread.
14
+ */
15
+ export function closePackageActors(home) {
16
+ if (!existsSync(join(home, "hub.db")))
17
+ return;
18
+ const state = HubState.open(home);
19
+ try {
20
+ for (const { actorId, package: from, state: now } of state.actors())
21
+ if (now !== "closed" && from !== "external" && from !== "builtin")
22
+ state.closeActor(PERSON, actorId);
23
+ }
24
+ finally {
25
+ state.close();
26
+ }
27
+ }
28
+ /** The Hub's exports each program holds. */
29
+ const hubBinding = (name) => ({ slot: name, provider: "hub", export: name });
30
+ /**
31
+ * Make what is missing and start each program. A program whose Actor exists keeps it and its
32
+ * credential. A step that fails is logged, the programs that don't need it still start, and the
33
+ * next start tries again.
34
+ */
35
+ export async function startPrograms(person, options) {
36
+ const log = options.log ?? (() => { });
37
+ const { hubUrl } = options;
38
+ const root = join(options.home, "programs");
39
+ mkdirSync(root, { recursive: true, mode: 0o700 });
40
+ chmodSync(root, 0o700);
41
+ const call = (slot, method, input = {}) => person.call(slot, method, input);
42
+ const programLog = {
43
+ info() { },
44
+ warn() { },
45
+ error: (message) => log(message),
46
+ };
47
+ const dirOf = (name) => join(root, name);
48
+ const identityFile = (name) => join(root, `${name}.identity`);
49
+ /** The program's Actor: the one kept for it unless that is closed, or a new one. */
50
+ const identity = async (name, title, bindings) => {
51
+ let kept;
52
+ try {
53
+ kept = JSON.parse(readFileSync(identityFile(name), "utf8"));
54
+ }
55
+ catch (error) {
56
+ if (error.code !== "ENOENT")
57
+ throw error;
58
+ }
59
+ if (kept) {
60
+ const { actors } = await call("actors", "list");
61
+ const { actorId } = kept;
62
+ if (actors.some((actor) => actor.actorId === actorId && actor.state !== "closed"))
63
+ return kept;
64
+ }
65
+ const made = await call("actors", "create", { name: title, bindings });
66
+ const file = identityFile(name);
67
+ writeFileSync(`${file}.tmp`, JSON.stringify(made), { mode: 0o600, flush: true });
68
+ renameSync(`${file}.tmp`, file);
69
+ return made;
70
+ };
71
+ /** Bind the person's `slot` to `export` of `provider`, unless it is bound already. */
72
+ const personSlot = async (slot, provider, exported) => {
73
+ const { bindings } = await call("bindings", "list", {
74
+ actor: "person",
75
+ });
76
+ if (bindings.some((binding) => binding.consumer === "person" && binding.slot === slot))
77
+ return;
78
+ await call("grants", "bind", { consumer: "person", slot, provider, export: exported });
79
+ };
80
+ const closers = [];
81
+ const attempt = async (what, run) => {
82
+ try {
83
+ return await run();
84
+ }
85
+ catch (error) {
86
+ log(`First run: ${what} didn't work: ${error instanceof Error ? error.message : String(error)}`);
87
+ return undefined;
88
+ }
89
+ };
90
+ const chatgpt = await attempt("ChatGPT", async () => {
91
+ const { actorId, credential } = await identity("chatgpt", "ChatGPT", []);
92
+ const running = await startChatGPT({
93
+ hubUrl,
94
+ actorId,
95
+ credential,
96
+ dir: dirOf("chatgpt"),
97
+ log: programLog,
98
+ ...(options.fetch ? { fetch: options.fetch } : {}),
99
+ });
100
+ closers.unshift(() => running.close());
101
+ await personSlot("login", actorId, "login");
102
+ return actorId;
103
+ });
104
+ // Each agent's binding to the model comes from the provider's own, so ChatGPT goes first.
105
+ const agents = chatgpt &&
106
+ (await attempt("the agent provider", async () => {
107
+ const { actorId, credential } = await identity("agents", "AgentOrg", [
108
+ hubBinding("actors"),
109
+ { slot: "model", provider: chatgpt, export: "session" },
110
+ ]);
111
+ const running = await startAgentProvider({
112
+ hubUrl,
113
+ actorId,
114
+ credential,
115
+ model: { actor: chatgpt, export: "session" },
116
+ dir: dirOf("agents"),
117
+ log: programLog,
118
+ });
119
+ closers.unshift(() => running.close());
120
+ return actorId;
121
+ }));
122
+ const mcp = await attempt("the MCP provider", async () => {
123
+ const { actorId, credential } = await identity("mcp", "Local", [hubBinding("actors")]);
124
+ const running = await startMcpProvider({
125
+ hubUrl,
126
+ actorId,
127
+ credential,
128
+ dir: dirOf("mcp"),
129
+ log: programLog,
130
+ });
131
+ closers.unshift(() => running.close());
132
+ return actorId;
133
+ });
134
+ const management = await attempt("management", async () => {
135
+ const { actorId, credential } = await identity("management", "Management", [
136
+ hubBinding("actors"),
137
+ hubBinding("grants"),
138
+ hubBinding("bindings"),
139
+ ]);
140
+ // Management outlasts the providers at the end and is up before they're connected to it.
141
+ const running = await startManager({
142
+ hubUrl,
143
+ actorId,
144
+ credential,
145
+ dir: dirOf("management"),
146
+ log: programLog,
147
+ });
148
+ closers.push(() => running.close());
149
+ for (const [slot, exported] of [
150
+ ["agents", "agents"],
151
+ ["connections", "connections"],
152
+ ["skills", "skills"],
153
+ ])
154
+ await personSlot(slot, actorId, exported);
155
+ return actorId;
156
+ });
157
+ if (management)
158
+ for (const provider of [agents, mcp])
159
+ if (provider)
160
+ await attempt("connecting a provider to management", () => call("grants", "expose", { provider, export: "provider", to: management }));
161
+ return {
162
+ ...(chatgpt ? { chatgpt } : {}),
163
+ ...(agents ? { agents } : {}),
164
+ ...(mcp ? { mcp } : {}),
165
+ ...(management ? { management } : {}),
166
+ async close() {
167
+ for (const close of closers)
168
+ await close().catch((error) => log(`A program didn't stop: ${String(error)}`));
169
+ },
170
+ };
171
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentorg/cli",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "AgentOrg as one app: the Hub, the person's gateway and the shell, on loopback.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -23,22 +23,14 @@
23
23
  },
24
24
  "files": [
25
25
  "dist/src",
26
- "dist/bundled",
27
26
  "static",
28
27
  "dist/node_modules"
29
28
  ],
30
29
  "dependencies": {
31
- "@assistant-ui/react": "^0.15.32",
30
+ "@modelcontextprotocol/client": "2.4.0",
32
31
  "ajv": "^8.20.0",
33
- "esbuild": "0.28.2",
34
- "radix-ui": "^1.8.1",
35
- "react": "^19.3.1",
36
- "react-dom": "^19.3.1",
37
- "react-markdown": "^10.1.0",
38
- "react-resizable-panels": "^4.19.1",
39
- "remark-gfm": "^4.0.1",
40
- "remend": "^1.4.0",
41
32
  "ws": "^8.22.1",
33
+ "yaml": "2.9.1",
42
34
  "zod": "^4.6.7"
43
35
  },
44
36
  "publishConfig": {
@@ -1,6 +0,0 @@
1
- {
2
- "installer": "sha256-4055f8fddf6b90f3d356543f554b2a9e9a2c4a8827a8774f8f87952dc1692331.agentorg",
3
- "chatgpt": "sha256-e356ea3c1899138a8494baf521556831006f38534fa9e92ae873e7e6956c3a46.agentorg",
4
- "assistant": "sha256-1f64ca62a0209d767d6aa6c4feb50b0653d60f10bebbc301f79bd3a37e0153c1.agentorg",
5
- "board": "sha256-0e91cc3d0e9762b81abc2427b5496b20f383abcd6fb97d928a8d50e956b54d1f.agentorg"
6
- }
@@ -1,17 +0,0 @@
1
- /** What a package's source may total, paths and text: it fits in one frame. */
2
- export declare const MAX_SOURCE: number;
3
- /**
4
- * The source as given, checked before anything is written or queued: its paths (no two the same
5
- * but for case, none both a file and a folder), its size.
6
- */
7
- export declare function checkSource(files: unknown): [string, string][];
8
- /**
9
- * Build a package from its source, given as data, and add it with `add`: the files are written to
10
- * a fresh folder in the home, built as `agentorg build` builds (importing by name only the SDK,
11
- * the interfaces, zod, React, react-dom and the kit, and nothing outside the folder; reading no tsconfig; at most 16
12
- * modules and 16 MiB built), and the folder is gone after, whatever happened. A build that fails
13
- * is `Refused("build")` with the build's message, which names no path outside the package.
14
- */
15
- export declare function buildSource<T>(home: string, entries: [string, string][], sandbox: (paths: string[]) => string[], add: (file: string) => T): Promise<T>;
16
- /** Folders of builds a crash interrupted: removed when the Hub opens. */
17
- export declare function sweepBuilds(home: string): void;
@@ -1,120 +0,0 @@
1
- import { readdirSync, rmSync } from "node:fs";
2
- import { mkdir, mkdtemp, realpath, rm, writeFile } from "node:fs/promises";
3
- import { dirname, join } from "node:path";
4
- import { fileURLToPath } from "node:url";
5
- import { Refused } from "@agentorg/sdk";
6
- import { BuildError, buildPackage } from "@agentorg/sdk/build";
7
- /** What a package's source may total, paths and text: it fits in one frame. */
8
- export const MAX_SOURCE = 768 * 1024;
9
- /** Files one package's source may have. */
10
- const MAX_FILES = 256;
11
- /**
12
- * What a package built by the Hub may import by name: the SDK, the interfaces, zod, and React and
13
- * the kit for views (`react/jsx-runtime`, which JSX compiles to, is React's).
14
- */
15
- const ALLOWED = [
16
- "@agentorg/sdk",
17
- "@agentorg/interfaces",
18
- "zod",
19
- "react",
20
- "react-dom",
21
- "@agentorg/kit",
22
- ];
23
- /** Where those are found: this package's own folder (dist/src/build.js → the package). */
24
- const FROM = fileURLToPath(new URL("../..", import.meta.url));
25
- /** A source path: `package.json`, or a source file under `src/` named plainly. */
26
- const PATH = /^(package\.json|src(\/[A-Za-z0-9_][A-Za-z0-9_.-]*)*\/[A-Za-z0-9_][A-Za-z0-9_.-]*\.(ts|tsx|mts|js|mjs|jsx|json))$/;
27
- /** Files under `src/` that tools read as configuration: a tsconfig can name any file to read. */
28
- const CONFIG = /(^|\/)(tsconfig|jsconfig|package)\.json$/;
29
- /** At most 16 modules and 16 MiB built; 30 s to bundle each module, 60 s for the whole build. */
30
- const LIMITS = { modules: 16, bytes: 16 * 1024 * 1024, bundleMs: 30_000, totalMs: 60_000 };
31
- /** How long reading one module's definition may take, in a Hub build. */
32
- const DESCRIBE_MS = 5_000;
33
- /**
34
- * The source as given, checked before anything is written or queued: its paths (no two the same
35
- * but for case, none both a file and a folder), its size.
36
- */
37
- export function checkSource(files) {
38
- if (typeof files !== "object" || files === null || Array.isArray(files))
39
- throw new Refused("invalid", "files is an object of path to text.");
40
- const entries = Object.entries(files);
41
- if (entries.length > MAX_FILES)
42
- throw new Refused("invalid", `A package's source is at most ${MAX_FILES} files.`);
43
- let size = 0;
44
- const seen = new Set();
45
- for (const [path, text] of entries) {
46
- if (path.length > 256 || !PATH.test(path) || (path !== "package.json" && CONFIG.test(path)))
47
- throw new Refused("invalid", `${JSON.stringify(path)}: a package's source is package.json and source files under src/ (.ts, .tsx, .mts, .js, .mjs, .jsx, .json; no tsconfig, jsconfig or package.json there), by plain relative paths.`);
48
- const lower = path.toLowerCase();
49
- if (seen.has(lower))
50
- throw new Refused("invalid", `${path}: another path differs from it only by case.`);
51
- seen.add(lower);
52
- if (typeof text !== "string")
53
- throw new Refused("invalid", `${path} isn't text.`);
54
- size += Buffer.byteLength(path) + Buffer.byteLength(text);
55
- }
56
- if (size > MAX_SOURCE)
57
- throw new Refused("invalid", `A package's source is at most ${MAX_SOURCE / 1024} KiB.`);
58
- if (!entries.some(([path]) => path === "package.json"))
59
- throw new Refused("invalid", "A package's source has a package.json.");
60
- for (const lower of seen)
61
- for (let at = lower.indexOf("/"); at > 0; at = lower.indexOf("/", at + 1))
62
- if (seen.has(lower.slice(0, at)))
63
- throw new Refused("invalid", `${lower.slice(0, at)} is both a file and a folder.`);
64
- return entries;
65
- }
66
- /**
67
- * A build's message as the caller may see it: the package's own paths relative to it, and the
68
- * places the Hub knows (its home, its installation) never named. The SDK already tells a place
69
- * outside the package as <outside>; only known prefixes are replaced here, so what the caller
70
- * wrote comes back as written.
71
- */
72
- function told(message, source, home) {
73
- return message
74
- .replaceAll(`${source}/`, "")
75
- .replaceAll(source, ".")
76
- .replaceAll(home, "<home>")
77
- .replaceAll(FROM.replace(/\/$/, ""), "<hub>");
78
- }
79
- /**
80
- * Build a package from its source, given as data, and add it with `add`: the files are written to
81
- * a fresh folder in the home, built as `agentorg build` builds (importing by name only the SDK,
82
- * the interfaces, zod, React, react-dom and the kit, and nothing outside the folder; reading no tsconfig; at most 16
83
- * modules and 16 MiB built), and the folder is gone after, whatever happened. A build that fails
84
- * is `Refused("build")` with the build's message, which names no path outside the package.
85
- */
86
- export async function buildSource(home, entries, sandbox, add) {
87
- const dir = await realpath(await mkdtemp(join(home, "build-")));
88
- const source = join(dir, "source");
89
- try {
90
- let built;
91
- try {
92
- for (const [path, text] of entries) {
93
- await mkdir(dirname(join(source, path)), { recursive: true, mode: 0o700 });
94
- await writeFile(join(source, path), text, { mode: 0o600, flag: "wx" });
95
- }
96
- built = await buildPackage(source, {
97
- out: join(dir, "out"),
98
- packages: { allowed: ALLOWED, from: FROM },
99
- limits: LIMITS,
100
- describeTimeoutMs: DESCRIBE_MS,
101
- // The describer runs the source's code: in the OS sandbox host processes run in.
102
- describer: { sandbox },
103
- });
104
- }
105
- catch (error) {
106
- const message = error instanceof Error ? error.message : String(error);
107
- throw new Refused("build", told(error instanceof BuildError ? message : `The build failed: ${message}`, source, await realpath(home)));
108
- }
109
- return add(built.file);
110
- }
111
- finally {
112
- await rm(dir, { recursive: true, force: true });
113
- }
114
- }
115
- /** Folders of builds a crash interrupted: removed when the Hub opens. */
116
- export function sweepBuilds(home) {
117
- for (const name of readdirSync(home))
118
- if (name.startsWith("build-"))
119
- rmSync(join(home, name), { recursive: true, force: true });
120
- }
@@ -1,33 +0,0 @@
1
- /** One line of an Actor's log, as `hub.actors.logs` returns it. */
2
- export interface LogLine {
3
- level: "info" | "warn" | "error";
4
- message: string;
5
- data?: Record<string, unknown>;
6
- module?: string;
7
- at: string;
8
- }
9
- /** Where an Actor's log is kept in the home; the previous file, rotated once, is `<file>.1`. */
10
- export declare const logFile: (home: string, actorId: string) => string;
11
- /**
12
- * The newest `limit` entries of an Actor's log, oldest first, across its file and the one rotated
13
- * before it. Lines that aren't a log entry are skipped and don't count.
14
- */
15
- export declare function readLogs(home: string, actorId: string, limit: number): LogLine[];
16
- /**
17
- * An entry as it is written, whoever gave it: a known level, the text cut, and the data rebuilt
18
- * as a fresh object of at most `MAX_FIELDS` keys, each value a primitive or JSON text, cut.
19
- */
20
- export declare function boundedEntry(level: unknown, message: unknown, data: unknown, module: string | undefined): LogLine;
21
- /**
22
- * Add an entry to an Actor's log (0600). A file that would pass 1 MiB is rotated to `<file>.1`
23
- * first, replacing the one before, so an Actor's logs never hold more than two files.
24
- */
25
- export declare function appendLog(home: string, actorId: string, entry: LogLine): void;
26
- /** Add entries to an Actor's log in one write, rotating first as `appendLog` does. */
27
- export declare function appendLogs(home: string, actorId: string, entries: LogLine[]): void;
28
- /**
29
- * A line a host process wrote, as a log entry: on stderr, a JSON line with a message and a time is
30
- * one of the runner's `ctx.log` entries (bounded like any other); anything else is the process's
31
- * own output, `info` from stdout and `error` from stderr.
32
- */
33
- export declare function outputEntry(stream: "stdout" | "stderr", line: string): LogLine;
@@ -1,162 +0,0 @@
1
- import { appendFileSync, closeSync, fstatSync, mkdirSync, openSync, readSync, renameSync, statSync, } from "node:fs";
2
- import { join } from "node:path";
3
- /** Where an Actor's log is kept in the home; the previous file, rotated once, is `<file>.1`. */
4
- export const logFile = (home, actorId) => join(home, "logs", `${actorId}.log`);
5
- /** A log file is rotated once it would pass this; each read takes at most this of a file's end. */
6
- const MAX_FILE = 1024 * 1024;
7
- const TAIL = MAX_FILE;
8
- /** A line's text is cut to this. */
9
- const MAX_MESSAGE = 4096;
10
- /** A line's data: this many keys at most, each value a primitive or JSON text, cut to this. */
11
- const MAX_FIELDS = 16;
12
- const MAX_FIELD = 1024;
13
- function tail(path) {
14
- let fd;
15
- try {
16
- fd = openSync(path, "r");
17
- }
18
- catch {
19
- return []; // Not written yet.
20
- }
21
- try {
22
- const size = fstatSync(fd).size;
23
- const length = Math.min(size, TAIL);
24
- const buffer = Buffer.alloc(length);
25
- readSync(fd, buffer, 0, length, size - length);
26
- const lines = buffer.toString("utf8").split("\n");
27
- // Cut mid-file, the first line is a fragment.
28
- return size > length ? lines.slice(1) : lines;
29
- }
30
- finally {
31
- closeSync(fd);
32
- }
33
- }
34
- const LEVELS = new Set(["info", "warn", "error"]);
35
- const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
36
- /** A line as a log entry, built from its known fields only; anything else isn't one. */
37
- function entryOf(line) {
38
- let raw;
39
- try {
40
- raw = JSON.parse(line);
41
- }
42
- catch {
43
- return undefined; // A partial line from a crash, or not ours.
44
- }
45
- if (!isRecord(raw) || typeof raw.message !== "string" || typeof raw.at !== "string")
46
- return undefined;
47
- return {
48
- level: LEVELS.has(raw.level) ? raw.level : "info",
49
- message: raw.message,
50
- ...(isRecord(raw.data) ? { data: raw.data } : {}),
51
- ...(typeof raw.module === "string" ? { module: raw.module } : {}),
52
- at: raw.at,
53
- };
54
- }
55
- /**
56
- * The newest `limit` entries of an Actor's log, oldest first, across its file and the one rotated
57
- * before it. Lines that aren't a log entry are skipped and don't count.
58
- */
59
- export function readLogs(home, actorId, limit) {
60
- const file = logFile(home, actorId);
61
- const lines = [...tail(`${file}.1`), ...tail(file)];
62
- const entries = [];
63
- for (let i = lines.length - 1; i >= 0 && entries.length < limit; i--) {
64
- const entry = entryOf(lines[i]);
65
- if (entry)
66
- entries.push(entry);
67
- }
68
- return entries.reverse();
69
- }
70
- /** Anything as text, even what can't say itself (no prototype, a throwing `toString`). */
71
- function textOf(value) {
72
- try {
73
- return String(value);
74
- }
75
- catch {
76
- return "[unprintable]";
77
- }
78
- }
79
- /** One field's value as it is kept: a number, boolean or null as is, anything else as text, cut. */
80
- function fieldOf(read) {
81
- try {
82
- const value = read();
83
- if (value === null || typeof value === "number" || typeof value === "boolean")
84
- return value;
85
- const text = typeof value === "string" ? value : textOf(JSON.stringify(value));
86
- return text.slice(0, MAX_FIELD);
87
- }
88
- catch {
89
- return "[unreadable]"; // A getter, toJSON or bigint that throws.
90
- }
91
- }
92
- /**
93
- * An entry as it is written, whoever gave it: a known level, the text cut, and the data rebuilt
94
- * as a fresh object of at most `MAX_FIELDS` keys, each value a primitive or JSON text, cut.
95
- */
96
- export function boundedEntry(level, message, data, module) {
97
- let fields;
98
- try {
99
- if (isRecord(data)) {
100
- // No prototype: a `__proto__` key is a key like any other.
101
- fields = Object.create(null);
102
- let kept = 0;
103
- // Only the first keys are read: the rest are never touched.
104
- for (const key in data) {
105
- if (!Object.hasOwn(data, key))
106
- continue;
107
- if (kept++ >= MAX_FIELDS)
108
- break;
109
- fields[key.slice(0, MAX_FIELD)] = fieldOf(() => data[key]);
110
- }
111
- }
112
- }
113
- catch {
114
- fields = undefined; // Data that can't even list its keys (a hostile proxy) is left out.
115
- }
116
- return {
117
- level: LEVELS.has(level) ? level : "info",
118
- message: textOf(message).slice(0, MAX_MESSAGE),
119
- ...(fields ? { data: fields } : {}),
120
- ...(module === undefined ? {} : { module }),
121
- at: new Date().toISOString(),
122
- };
123
- }
124
- /**
125
- * Add an entry to an Actor's log (0600). A file that would pass 1 MiB is rotated to `<file>.1`
126
- * first, replacing the one before, so an Actor's logs never hold more than two files.
127
- */
128
- export function appendLog(home, actorId, entry) {
129
- appendLogs(home, actorId, [entry]);
130
- }
131
- /** Add entries to an Actor's log in one write, rotating first as `appendLog` does. */
132
- export function appendLogs(home, actorId, entries) {
133
- if (!entries.length)
134
- return;
135
- const file = logFile(home, actorId);
136
- const line = entries.map((entry) => `${JSON.stringify(entry)}\n`).join("");
137
- // Past what a reader takes of a file, a line could never be read back.
138
- if (Buffer.byteLength(line) > MAX_FILE)
139
- return;
140
- mkdirSync(join(home, "logs"), { recursive: true, mode: 0o700 });
141
- let size = 0;
142
- try {
143
- size = statSync(file).size;
144
- }
145
- catch {
146
- // Not written yet.
147
- }
148
- if (size > 0 && size + Buffer.byteLength(line) > MAX_FILE)
149
- renameSync(file, `${file}.1`);
150
- appendFileSync(file, line, { mode: 0o600 });
151
- }
152
- /**
153
- * A line a host process wrote, as a log entry: on stderr, a JSON line with a message and a time is
154
- * one of the runner's `ctx.log` entries (bounded like any other); anything else is the process's
155
- * own output, `info` from stdout and `error` from stderr.
156
- */
157
- export function outputEntry(stream, line) {
158
- const parsed = stream === "stderr" ? entryOf(line) : undefined;
159
- return parsed
160
- ? boundedEntry(parsed.level, parsed.message, parsed.data, parsed.module?.slice(0, 64))
161
- : boundedEntry(stream === "stdout" ? "info" : "error", line, undefined, undefined);
162
- }