@agentorg/cli 0.0.4 → 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 -111
  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 +20 -298
  9. package/dist/node_modules/@agentorg/hub/dist/src/state.js +73 -456
  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 -267
  20. package/dist/node_modules/@agentorg/interfaces/dist/src/hub.js +17 -145
  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-01d69bc3888c2a53963f4413d47de909d129ad27c78e9af6d830bb50c3478419.agentorg +0 -0
  123. package/dist/bundled/sha256-84165e3be5c904fc971d983dab31102e07cca725d8629a6fd7d118fa3a0a88b8.agentorg +0 -0
  124. package/dist/bundled/sha256-ade9132b3f34b4c39db92adeadc7e540dc745e4a81b5b54f5d45bf9ec92bca75.agentorg +0 -0
  125. package/dist/bundled/sha256-f4330f5987f37d8cf3aeb44d2f831b573641a87186daa2f811f0c35ba04804f0.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 -51
  202. package/dist/src/model.js +0 -230
  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
@@ -1,59 +0,0 @@
1
- const AGENT_GRANTS = [
2
- { slot: "model", what: "ChatGPT", iface: "llm.session@1", fixed: true },
3
- { slot: "store", what: "its own storage", iface: "kv@1", fixed: true },
4
- { slot: "layout", what: "your home", iface: "layout@1", fixed: false },
5
- { slot: "packages", what: "install packages", iface: "hub.packages@1", fixed: false },
6
- { slot: "actors", what: "create and run Actors", iface: "hub.actors@1", fixed: false },
7
- { slot: "grants", what: "ask for connections", iface: "hub.grants@1", fixed: false },
8
- { slot: "exports", what: "see what's offered", iface: "hub.exports@1", fixed: false },
9
- {
10
- slot: "installer",
11
- what: "install Actors",
12
- iface: "installer@1",
13
- fixed: false,
14
- needs: "actors"
15
- }
16
- ];
17
- const FIRST_RUN = "app/first-run";
18
- const PROVIDERS = {
19
- model: (ids) => ({ provider: ids.chatgpt, export: "model.session" }),
20
- store: () => ({ provider: "storage", export: "kv" }),
21
- layout: () => ({ provider: "person", export: "layout" }),
22
- packages: () => ({ provider: "hub", export: "packages" }),
23
- actors: () => ({ provider: "hub", export: "actors" }),
24
- grants: () => ({ provider: "hub", export: "grants" }),
25
- exports: () => ({ provider: "hub", export: "exports" }),
26
- installer: (ids) => ({ provider: ids.installer, export: "installer.installer" })
27
- };
28
- function agentConnections(ids, off = /* @__PURE__ */ new Set()) {
29
- return Object.fromEntries(
30
- AGENT_GRANTS.filter((grant) => grant.fixed || !off.has(grant.slot)).map((grant) => {
31
- const { provider, export: name } = PROVIDERS[grant.slot](ids);
32
- return [`logic.${grant.slot}`, { actor: provider, export: name }];
33
- })
34
- );
35
- }
36
- async function agentProviders(call) {
37
- const { bindings } = await call("bindings", "list", { actor: "person" });
38
- const of = (slot) => bindings.find((b) => b.consumer === "person" && b.slot === slot)?.provider;
39
- const chatgpt = of("login");
40
- const installer = of("installer");
41
- if (!chatgpt || !installer)
42
- throw new Error("AgentOrg isn't set up yet. Restart it to finish setting up.");
43
- return { chatgpt, installer };
44
- }
45
- async function installAgent(call, agent) {
46
- return await call("installer", "install", {
47
- package: agent.assistant,
48
- name: agent.name,
49
- connections: agentConnections(await agentProviders(call), agent.off),
50
- start: true
51
- });
52
- }
53
- export {
54
- AGENT_GRANTS,
55
- FIRST_RUN,
56
- agentConnections,
57
- agentProviders,
58
- installAgent
59
- };
@@ -1,107 +0,0 @@
1
- /**
2
- * What a new agent gets: the assistant package's slots, each bound at creation (step 5, §4). The
3
- * slots are its `logic` module's; `model` and `store` it always gets, and the person decides the
4
- * rest in New agent's dialog. A grant that `needs` another is off while that one is: installing
5
- * creates and starts Actors.
6
- */
7
- export const AGENT_GRANTS = [
8
- { slot: "model", what: "ChatGPT", iface: "llm.session@1", fixed: true },
9
- { slot: "store", what: "its own storage", iface: "kv@1", fixed: true },
10
- { slot: "layout", what: "your home", iface: "layout@1", fixed: false },
11
- { slot: "packages", what: "install packages", iface: "hub.packages@1", fixed: false },
12
- { slot: "actors", what: "create and run Actors", iface: "hub.actors@1", fixed: false },
13
- { slot: "grants", what: "ask for connections", iface: "hub.grants@1", fixed: false },
14
- { slot: "exports", what: "see what's offered", iface: "hub.exports@1", fixed: false },
15
- {
16
- slot: "installer",
17
- what: "install Actors",
18
- iface: "installer@1",
19
- fixed: false,
20
- needs: "actors",
21
- },
22
- ] as const;
23
-
24
- export type AgentSlot = (typeof AGENT_GRANTS)[number]["slot"];
25
-
26
- /**
27
- * Where the app's first run records what it made, in the person's store: its `assistant` is the
28
- * package New agent installs, by hash, never a package found by its name.
29
- */
30
- export const FIRST_RUN = "app/first-run";
31
-
32
- /**
33
- * The Actors a new agent's slots reach beside the built-ins: the person's own ChatGPT (what its
34
- * `login` is bound to) and installer (what its `installer` is bound to).
35
- */
36
- export interface AgentProviders {
37
- chatgpt: string;
38
- installer: string;
39
- }
40
-
41
- /** Where each slot is served: ChatGPT's session, the installer, the built-ins, the person's layout. */
42
- const PROVIDERS: Record<AgentSlot, (ids: AgentProviders) => { provider: string; export: string }> =
43
- {
44
- model: (ids) => ({ provider: ids.chatgpt, export: "model.session" }),
45
- store: () => ({ provider: "storage", export: "kv" }),
46
- layout: () => ({ provider: "person", export: "layout" }),
47
- packages: () => ({ provider: "hub", export: "packages" }),
48
- actors: () => ({ provider: "hub", export: "actors" }),
49
- grants: () => ({ provider: "hub", export: "grants" }),
50
- exports: () => ({ provider: "hub", export: "exports" }),
51
- installer: (ids) => ({ provider: ids.installer, export: "installer.installer" }),
52
- };
53
-
54
- /**
55
- * A new agent's connections for `installer.install`: every grant but the ones switched off, which
56
- * can't be `model` or `store`.
57
- */
58
- export function agentConnections(
59
- ids: AgentProviders,
60
- off: ReadonlySet<string> = new Set(),
61
- ): Record<string, { actor: string; export: string }> {
62
- return Object.fromEntries(
63
- AGENT_GRANTS.filter((grant) => grant.fixed || !off.has(grant.slot)).map((grant) => {
64
- const { provider, export: name } = PROVIDERS[grant.slot](ids);
65
- return [`logic.${grant.slot}`, { actor: provider, export: name }];
66
- }),
67
- );
68
- }
69
-
70
- type Call = (slot: string, method: string, input: unknown) => Promise<unknown>;
71
-
72
- /**
73
- * The person's ChatGPT and installer: the Actors the person's `login` and `installer` are bound to,
74
- * as the app's first run binds them (never an Actor found by its package's name).
75
- */
76
- export async function agentProviders(call: Call): Promise<AgentProviders> {
77
- const { bindings } = (await call("bindings", "list", { actor: "person" })) as {
78
- bindings: { consumer: string; slot: string; provider: string }[];
79
- };
80
- const of = (slot: string) =>
81
- bindings.find((b) => b.consumer === "person" && b.slot === slot)?.provider;
82
- const chatgpt = of("login");
83
- const installer = of("installer");
84
- // Both are bound by the app's first run at its start; one that didn't finish tries again then.
85
- if (!chatgpt || !installer)
86
- throw new Error("AgentOrg isn't set up yet. Restart it to finish setting up.");
87
- return { chatgpt, installer };
88
- }
89
-
90
- /**
91
- * New agent itself: install the assistant package `assistant` named `name` through the person's
92
- * `installer`, with `agentConnections` to the person's own ChatGPT and installer, and start it, all
93
- * or nothing. `call` is the person's call (the shell's `/api`, or a test's). Returns the installer's
94
- * answer: its id, the slots left unbound (the switched-off ones among them) and the seeds that
95
- * didn't land.
96
- */
97
- export async function installAgent(
98
- call: Call,
99
- agent: { assistant: string; name: string; off?: ReadonlySet<string> },
100
- ): Promise<{ actorId: string; unbound: string[]; unseeded: string[] }> {
101
- return (await call("installer", "install", {
102
- package: agent.assistant,
103
- name: agent.name,
104
- connections: agentConnections(await agentProviders(call), agent.off),
105
- start: true,
106
- })) as { actorId: string; unbound: string[]; unseeded: string[] };
107
- }
@@ -1,23 +0,0 @@
1
- export interface Served {
2
- status: number;
3
- headers: Record<string, string>;
4
- body: string | Uint8Array;
5
- }
6
- /** Where a view module's bundle is: its file, if `module` is a `view` module of that package. */
7
- export type ViewBundle = (hash: string, module: string) => string | undefined;
8
- /**
9
- * A frame's policy, on every `/frames/` response: sandboxed with scripts only, so its origin is
10
- * opaque however it is loaded, and nothing in it can reach the shell origin's storage, where the
11
- * session is. Scripts only from the gateway's `/frames/`, nothing fetched, no forms, no frames
12
- * inside. The origin being opaque, `'self'` would match nothing: the gateway's is named. Styles may
13
- * be inline, as a view sets its own.
14
- */
15
- export declare const frameCsp: (origin: string) => string;
16
- /**
17
- * Serve `/frames/`: the runtime, a view's frame document and its bundle. A frame has an opaque
18
- * origin, so a module script it loads is a CORS request from `Origin: null`: only that one is
19
- * answered `Access-Control-Allow-Origin: null`, and no other origin is allowed to read a script.
20
- * No request here reads or needs the session. A bundle is served only for a `view` module, by
21
- * hash, and never changes. `from` is the request's `Origin` header.
22
- */
23
- export declare function serveFrame(path: string, origin: string, bundle: ViewBundle, from?: string): Served | undefined;
@@ -1,78 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { createRequire } from "node:module";
3
- const HASH = /^sha256-[0-9a-f]{64}$/;
4
- const MODULE = /^[a-z][A-Za-z0-9_]{0,63}$/;
5
- /** The SDK's frame runtime, the one script every frame loads first. */
6
- const runtime = () => readFileSync(createRequire(import.meta.url).resolve("@agentorg/sdk/frame/runtime.js"));
7
- /**
8
- * A frame's policy, on every `/frames/` response: sandboxed with scripts only, so its origin is
9
- * opaque however it is loaded, and nothing in it can reach the shell origin's storage, where the
10
- * session is. Scripts only from the gateway's `/frames/`, nothing fetched, no forms, no frames
11
- * inside. The origin being opaque, `'self'` would match nothing: the gateway's is named. Styles may
12
- * be inline, as a view sets its own.
13
- */
14
- export const frameCsp = (origin) => [
15
- "default-src 'none'",
16
- `script-src ${origin}/frames/`,
17
- "style-src 'unsafe-inline'",
18
- "img-src data: blob:",
19
- "font-src data:",
20
- "connect-src 'none'",
21
- "form-action 'none'",
22
- "base-uri 'none'",
23
- `frame-ancestors ${origin}`,
24
- // However it's loaded, top-level included, its origin is opaque: nothing runs as the shell's.
25
- "sandbox allow-scripts",
26
- ].join("; ");
27
- /**
28
- * The frame document: nothing but the runtime, which waits for the shell's port, and the shell's
29
- * base text, from the theme's tokens once the view is mounted.
30
- */
31
- const DOCUMENT = '<!doctype html><html><head><meta charset="utf-8"><style>html,body{margin:0}body{font:14px/1.45 var(--font, ui-sans-serif, system-ui, sans-serif);color:var(--fg)}</style><script type="module" src="/frames/runtime.js"></script></head><body></body></html>';
32
- /**
33
- * Serve `/frames/`: the runtime, a view's frame document and its bundle. A frame has an opaque
34
- * origin, so a module script it loads is a CORS request from `Origin: null`: only that one is
35
- * answered `Access-Control-Allow-Origin: null`, and no other origin is allowed to read a script.
36
- * No request here reads or needs the session. A bundle is served only for a `view` module, by
37
- * hash, and never changes. `from` is the request's `Origin` header.
38
- */
39
- export function serveFrame(path, origin, bundle, from) {
40
- const base = {
41
- "Content-Security-Policy": frameCsp(origin),
42
- "X-Content-Type-Options": "nosniff",
43
- "Referrer-Policy": "no-referrer",
44
- };
45
- const script = {
46
- ...base,
47
- "Content-Type": "text/javascript; charset=utf-8",
48
- // A sandboxed frame's own request: nothing else needs to read a script across origins.
49
- ...(from === "null" ? { "Access-Control-Allow-Origin": "null" } : {}),
50
- Vary: "Origin",
51
- };
52
- if (path === "/frames/runtime.js")
53
- return { status: 200, headers: { ...script, "Cache-Control": "no-cache" }, body: runtime() };
54
- const match = /^\/frames\/([^/]+)\/([^/]+)\.(html|js)$/.exec(path);
55
- if (!match)
56
- return undefined;
57
- const [, hash = "", module = "", kind] = match;
58
- if (!HASH.test(hash) || !MODULE.test(module))
59
- return undefined;
60
- const file = bundle(hash, module);
61
- if (!file)
62
- return undefined;
63
- if (kind === "html")
64
- return {
65
- status: 200,
66
- headers: {
67
- ...base,
68
- "Content-Type": "text/html; charset=utf-8",
69
- "Cache-Control": "no-cache",
70
- },
71
- body: DOCUMENT,
72
- };
73
- return {
74
- status: 200,
75
- headers: { ...script, "Cache-Control": "public, max-age=31536000, immutable" },
76
- body: readFileSync(file),
77
- };
78
- }
@@ -1,44 +0,0 @@
1
- import type { Placement } from "@agentorg/interfaces";
2
- import type { z } from "zod";
3
- export type PlacementRecord = z.output<typeof Placement>;
4
- /** Where the layout is kept: the person's `kv@1` slot, under one key. */
5
- export interface LayoutStore {
6
- get(key: string): Promise<{
7
- value?: unknown;
8
- }>;
9
- set(key: string, value: unknown): Promise<unknown>;
10
- }
11
- /** The key the layout is kept under, in the person's store. */
12
- export declare const LAYOUT_KEY = "layout";
13
- /**
14
- * `layout@1`'s logic: what the person has placed, in order, kept in its own store, so it is state
15
- * like any other Actor's. Writes run one at a time; each one tells `changed`. `isView` says whether
16
- * a module is a `view` module of an Actor's package, the only thing `place` accepts.
17
- */
18
- export declare class Layout {
19
- #private;
20
- constructor(options: {
21
- store: () => LayoutStore;
22
- isView(actor: string, module: string): boolean;
23
- changed(): void;
24
- });
25
- get(): Promise<{
26
- home: PlacementRecord[];
27
- }>;
28
- /** Place a view, recording `by`, the Actor that asked, as the call's caller says. */
29
- place(input: {
30
- actor: string;
31
- module: string;
32
- title?: string;
33
- after?: string;
34
- }, by: string): Promise<{
35
- id: string;
36
- }>;
37
- remove(input: {
38
- id: string;
39
- }): Promise<{}>;
40
- move(input: {
41
- id: string;
42
- after?: string;
43
- }): Promise<{}>;
44
- }
@@ -1,90 +0,0 @@
1
- import { randomBytes } from "node:crypto";
2
- import { Refused } from "@agentorg/sdk";
3
- /** The key the layout is kept under, in the person's store. */
4
- export const LAYOUT_KEY = "layout";
5
- /** Placements one layout holds; past it, `place` is refused. */
6
- const MAX_PLACEMENTS = 200;
7
- /**
8
- * `layout@1`'s logic: what the person has placed, in order, kept in its own store, so it is state
9
- * like any other Actor's. Writes run one at a time; each one tells `changed`. `isView` says whether
10
- * a module is a `view` module of an Actor's package, the only thing `place` accepts.
11
- */
12
- export class Layout {
13
- #store;
14
- #isView;
15
- #changed;
16
- #queue = Promise.resolve();
17
- constructor(options) {
18
- this.#store = options.store;
19
- this.#isView = options.isView;
20
- this.#changed = options.changed;
21
- }
22
- async get() {
23
- return { home: await this.#read() };
24
- }
25
- /** Place a view, recording `by`, the Actor that asked, as the call's caller says. */
26
- place(input, by) {
27
- return this.#write((home) => {
28
- if (!this.#isView(input.actor, input.module))
29
- throw new Refused("invalid", `${input.actor}.${input.module} isn't a view module of a running package Actor.`);
30
- if (home.length >= MAX_PLACEMENTS)
31
- throw new Refused("quota", `A layout holds ${MAX_PLACEMENTS} placements at most.`);
32
- const placement = {
33
- id: randomBytes(9).toString("base64url"),
34
- actor: input.actor,
35
- module: input.module,
36
- ...(input.title === undefined ? {} : { title: input.title }),
37
- by,
38
- };
39
- return { home: insert(home, placement, input.after), result: { id: placement.id } };
40
- });
41
- }
42
- remove(input) {
43
- return this.#write((home) => {
44
- at(home, input.id);
45
- return { home: home.filter((placement) => placement.id !== input.id), result: {} };
46
- });
47
- }
48
- move(input) {
49
- return this.#write((home) => {
50
- const placement = at(home, input.id);
51
- if (input.after === input.id)
52
- throw new Refused("invalid", "A placement can't follow itself.");
53
- const rest = home.filter((other) => other.id !== input.id);
54
- // Moved with no `after`, it goes first; placed with none, last.
55
- return { home: insert(rest, placement, input.after ?? null), result: {} };
56
- });
57
- }
58
- async #read() {
59
- const { value } = await this.#store().get(LAYOUT_KEY);
60
- return Array.isArray(value) ? value : [];
61
- }
62
- /** One write at a time: read, change, write back, then tell. */
63
- #write(change) {
64
- const run = this.#queue.then(async () => {
65
- const { home, result } = change(await this.#read());
66
- await this.#store().set(LAYOUT_KEY, home);
67
- this.#changed();
68
- return result;
69
- });
70
- this.#queue = run.catch(() => { });
71
- return run;
72
- }
73
- }
74
- function at(home, id) {
75
- const found = home.find((placement) => placement.id === id);
76
- if (!found)
77
- throw new Refused("unknown", `No placement ${id}.`);
78
- return found;
79
- }
80
- /** `placement` after the one with id `after`: first for `null`, last for `undefined`. */
81
- function insert(home, placement, after) {
82
- if (after === undefined)
83
- return [...home, placement];
84
- if (after === null)
85
- return [placement, ...home];
86
- const index = home.findIndex((other) => other.id === after);
87
- if (index < 0)
88
- throw new Refused("unknown", `No placement ${after}.`);
89
- return [...home.slice(0, index + 1), placement, ...home.slice(index + 1)];
90
- }
@@ -1,51 +0,0 @@
1
- import type { IncomingMessage, ServerResponse } from "node:http";
2
- /**
3
- * How the first run reaches the Hub: the person's own calls, as `/api` makes them. A call that
4
- * doesn't reach its provider rejects with an error named `NotConnected`, as `/api` names it.
5
- */
6
- export interface PersonCalls {
7
- call(slot: string, method: string, input: unknown): Promise<unknown>;
8
- }
9
- /** An export of a running Actor. */
10
- export interface Target {
11
- actor: string;
12
- export: string;
13
- }
14
- export interface FirstRunOptions {
15
- /** Where the bundled archives and their `index.json` are; the app's own by default. */
16
- bundled?: string;
17
- /** What the model Actor's `web` connects to: the built-in `net`'s `egress` by default. */
18
- egress?: Target;
19
- /** Where the first run says what it did, and what it couldn't. */
20
- log?: (message: string) => void;
21
- /**
22
- * Whether an Actor's process is connected (the Hub's `connected`): the first run waits for the
23
- * installer's before it installs through it. Without it, it installs at once.
24
- */
25
- connected?: (actorId: string) => boolean;
26
- }
27
- export interface FirstRun {
28
- /** The bundled packages by name, each added. */
29
- packages: Record<string, string>;
30
- /** The installer Actor and the model Actor, when they exist. */
31
- installer?: string;
32
- chatgpt?: string;
33
- }
34
- /**
35
- * The first run, at every start after the person's store is bound: add the bundled packages,
36
- * ensure the installer (made by the person, with its bindings, started), bind the person's
37
- * `installer` to it, ensure the model Actor installed through it (`web` to `egress`, `store` to
38
- * storage's `kv`, started), and bind the person's `login` to the model's. What is there already is
39
- * kept: an installer or model Actor an earlier run made (recorded in the person's store) stays,
40
- * of whatever build. A step that fails is logged and the rest still runs where it can; the next
41
- * start tries again.
42
- */
43
- export declare function firstRun(person: PersonCalls, options?: FirstRunOptions): Promise<FirstRun>;
44
- /**
45
- * `/oauth/chatgpt`: where ChatGPT sends the browser back. It hands the whole callback address to
46
- * the person's `login.complete`, then sends the tab on to `?result=<outcome>`, an address without
47
- * the sign-in's code, so the code stays out of the tab's address and history; that page says how
48
- * it went and links back to the shell. The code is never logged or shown, and no page sends a
49
- * referrer.
50
- */
51
- export declare function oauthRoute(person: PersonCalls): (request: IncomingMessage, response: ServerResponse, url: URL) => void;