@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
@@ -1,14 +1,7 @@
1
1
  import { hashInterface, NotConnected, OutcomeUnknown, Refused, } from "@agentorg/sdk";
2
- import { errorOf } from "@agentorg/sdk/client";
3
- import { serveOver } from "@agentorg/sdk/http";
4
- import { encodeFrame, eventBody, FrameError, FrameReader, GO_AWAY, HeaderError, input, parseBody, parseHeader, result, Session, wireError, YamuxError, } from "@agentorg/wire";
5
- import { sweepBuilds } from "./build.js";
2
+ import { encodeFrame, eventBody, FrameError, FrameReader, GO_AWAY, HeaderError, input, parseBody, parseHeader, result, Session, wireError, } from "@agentorg/wire";
6
3
  import { HubActor } from "./hub-actor.js";
7
- import { appendLog, boundedEntry } from "./logs.js";
8
- import { Net } from "./net.js";
9
- import { Processes } from "./processes.js";
10
- import { HUB, HubState, NET, STORAGE, } from "./state.js";
11
- import { Storage } from "./storage.js";
4
+ import { HUB, HubState } from "./state.js";
12
5
  import { Validators } from "./validate.js";
13
6
  /** Streams an admitted channel may have open at once. Before admission it may have one: hello. */
14
7
  const MAX_STREAMS = 256;
@@ -25,8 +18,6 @@ const MAX_OPEN_NOTICES = 64;
25
18
  * a provider wait for each delivery, so this bounds the hub Actor's own events.
26
19
  */
27
20
  const MAX_QUEUED_BYTES = 4 * 1024 * 1024;
28
- /** Where the Hub's in-process http serving reports a handler's own failure: nowhere. */
29
- const QUIET = { info() { }, warn() { }, error() { } };
30
21
  const bindingKey = (b) => `${b.consumer}\0${b.slot}`;
31
22
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
32
23
  function errorBody(error) {
@@ -61,20 +52,7 @@ const drain = (reader) => void reader
61
52
  /** Settles when the opener resets its stream; a clean end of its side is not a reset. */
62
53
  const whenReset = (reader) => reader.next().then(() => new Promise(() => { }), () => undefined);
63
54
  /**
64
- * One direction of a splice. A source that fails resets the destination, and a destination its
65
- * side reset resets the source. A destination that can't take more because its channel went ends
66
- * this direction only: cancelling the source would reset its whole stream, and with it the other
67
- * direction, which may still carry an answer. What the source still sends is read and dropped
68
- * until it ends.
69
- */
70
- const pass = (from, to) => from.pipeTo(to.writable, { preventCancel: true }).catch((error) => {
71
- to.reset();
72
- if (error instanceof YamuxError && error.code === "reset")
73
- return from.cancel(error).catch(() => { });
74
- return from.pipeTo(new WritableStream()).catch(() => { });
75
- });
76
- /**
77
- * A value as it would cross the wire: what a built-in Actor (the hub, storage) gives in-process is
55
+ * A value as it would cross the wire: what the hub gives in-process is
78
56
  * checked and sent as a channel provider's would be, so a property left undefined is left out,
79
57
  * never a value that fails its schema.
80
58
  */
@@ -110,18 +88,13 @@ export class Hub {
110
88
  state;
111
89
  #actor;
112
90
  #validators;
113
- #storage;
114
- #processes;
115
- #net;
116
91
  #connections = new Map();
117
- /** Open subscriptions and splices by the binding they run through, ended when it goes. */
92
+ /** Open subscriptions by the binding they run through, ended when it goes. */
118
93
  #live = new Map();
119
94
  #helloTimeoutMs;
120
95
  #answerTimeoutMs;
121
96
  /** Every channel's session, admitted or still in hello. */
122
97
  #sessions = new Set();
123
- /** `viewSlots` listeners by Actor: each hears its view module's slot changes. */
124
- #viewListeners = new Map();
125
98
  constructor(home, options) {
126
99
  this.#helloTimeoutMs = options.helloTimeoutMs ?? 10_000;
127
100
  this.#answerTimeoutMs = options.answerTimeoutMs ?? 60_000;
@@ -136,45 +109,16 @@ export class Hub {
136
109
  this.#notify(binding.consumer, binding.slot, false);
137
110
  }
138
111
  },
139
- closed: (actorId) => {
140
- this.#connections.get(actorId)?.session.close();
141
- // Closing is for good: its stores go too. Unbinding keeps them.
142
- this.#storage.deleteConsumer(actorId);
143
- },
144
- requested: (request, approvers) => actor?.requested(request, approvers),
145
- decided: (request, status, approvers) => actor?.decided(request, status, approvers),
112
+ closed: (actorId) => this.#connections.get(actorId)?.session.close(),
146
113
  exportsChanged: (changed) => actor?.exportsChanged(changed),
147
114
  actorChanged: (changed) => actor?.actorChanged(changed),
148
115
  audited: (entry) => actor?.audited(entry),
149
116
  });
150
- this.#net = new Net(this.state, options.net);
151
- // Builds a crash interrupted leave their folders; they go now.
152
- sweepBuilds(home);
153
- this.#processes = new Processes(this.state, (channel, admitted) => this.accept(channel, admitted), options.processes);
154
- actor = this.#actor = new HubActor(this.state, this.#processes, (id) => this.connected(id));
155
- try {
156
- this.#storage = new Storage(home, options.storage);
157
- // Stores of Actors closed while a delete couldn't run (a crash, a lock) go now.
158
- this.#storage.keepOnly(new Set(this.state
159
- .actors()
160
- .filter((a) => a.state !== "closed")
161
- .map((a) => a.actorId)));
162
- }
163
- catch (error) {
164
- // Nothing half-open is left: the home's lock and the check workers go with it.
165
- this.#validators.close();
166
- this.state.close();
167
- throw error;
168
- }
117
+ actor = this.#actor = new HubActor(this.state, (id) => this.connected(id));
169
118
  }
170
- /**
171
- * Open the Hub in its home. The host sandbox is probed at once; when it is available, package
172
- * Actors recorded as `running` get their processes back.
173
- */
119
+ /** Open the Hub in its home. */
174
120
  static open(home, options = {}) {
175
- const hub = new Hub(home, options);
176
- hub.#processes.probe().catch(() => { });
177
- return hub;
121
+ return new Hub(home, options);
178
122
  }
179
123
  /** Whether an Actor has a channel now. */
180
124
  connected(actorId) {
@@ -182,22 +126,11 @@ export class Hub {
182
126
  }
183
127
  /**
184
128
  * Take a channel. Its first stream must be `hello`, and nothing else may open before it is
185
- * admitted. An external client's hello carries its credential, within the hello deadline. A
186
- * channel the Hub made itself, a pipe to a package Actor's process it spawned, is given with
187
- * that Actor's id: its hello names that Actor and needs no credential, and its spawner keeps
188
- * the deadline. The handle settles when the channel ends, and closes it.
129
+ * admitted. A hello carries the Actor's credential, within the hello deadline. The handle settles
130
+ * when the channel ends, and closes it.
189
131
  */
190
- accept(channel, admitted) {
191
- if (admitted) {
192
- const actor = this.state.actor(admitted.actorId);
193
- if (actor.package === "external" || actor.package === "builtin" || actor.state === "closed")
194
- throw new Refused("state", `${this.state.named(actor.actorId)} isn't a live package Actor.`);
195
- }
132
+ accept(channel) {
196
133
  let conn;
197
- let admit;
198
- const admittedNow = new Promise((resolve) => {
199
- admit = resolve;
200
- });
201
134
  let helloSeen = false;
202
135
  let ended = false;
203
136
  const options = {
@@ -210,11 +143,10 @@ export class Hub {
210
143
  stream.reset();
211
144
  else {
212
145
  helloSeen = true;
213
- void this.#hello(stream, session, admitted, (actorId, replace) => {
146
+ void this.#hello(stream, session, (actorId, replace) => {
214
147
  if (ended)
215
148
  throw new NotConnected("The channel");
216
- // Closed while its hello was on the way (a pipe made before a close, or declares
217
- // being checked): a closed Actor is never admitted.
149
+ // Closed while its hello was on the way: a closed Actor is never admitted.
218
150
  if (this.state.actor(actorId).state === "closed")
219
151
  throw new Refused("state", `${this.state.named(actorId)} is closed for good; make another.`);
220
152
  // Checked again as the channel is admitted: one may have connected while declares
@@ -222,7 +154,6 @@ export class Hub {
222
154
  if (replace === false && this.#connections.has(actorId))
223
155
  throw new Refused("connected", `${this.state.named(actorId)} already has a channel to this Hub; close that one first.`);
224
156
  conn = this.#admit(actorId, session);
225
- admit();
226
157
  options.maxStreams = MAX_STREAMS;
227
158
  });
228
159
  }
@@ -230,13 +161,10 @@ export class Hub {
230
161
  };
231
162
  const session = new Session(channel, options);
232
163
  this.#sessions.add(session);
233
- // A pipe's hello is waited for by whoever spawned its process, under its own deadline.
234
- const timer = admitted
235
- ? undefined
236
- : setTimeout(() => {
237
- if (!conn)
238
- session.close(GO_AWAY.protocolError);
239
- }, this.#helloTimeoutMs);
164
+ const timer = setTimeout(() => {
165
+ if (!conn)
166
+ session.close(GO_AWAY.protocolError);
167
+ }, this.#helloTimeoutMs);
240
168
  const closed = session.closed.then(() => {
241
169
  ended = true;
242
170
  clearTimeout(timer);
@@ -244,155 +172,14 @@ export class Hub {
244
172
  if (conn)
245
173
  this.#dropped(conn);
246
174
  });
247
- return { admitted: admittedNow, closed, close: () => session.close() };
248
- }
249
- /**
250
- * A call from one of a package Actor's view modules, run in this process for the gateway that
251
- * shows it (step 4): through `<module>.<slot>` of the Actor, as the Actor, checked and audited
252
- * like any call. A module that isn't a view of the Actor's package is refused.
253
- */
254
- async viewCall(actorId, module, slot, method, input) {
255
- const name = this.#viewSlot(actorId, module, slot, { op: "call", method });
256
- const { body } = await this.#invoke(actorId, name, method, async () => ({
257
- value: input,
258
- cancelled: new Promise(() => { }),
259
- }));
260
- if ("error" in body)
261
- throw errorOf(body.error, name);
262
- return body.result;
263
- }
264
- /**
265
- * Events of a view module's slot, as `viewCall` reaches its methods. `onEvent` may return a
266
- * promise: the next event waits for it. Returns how to stop; `onEnd` hears when it ended
267
- * otherwise, with the reason if it wasn't a clean end.
268
- */
269
- viewSubscribe(actorId, module, slot, event, onEvent, onEnd) {
270
- const name = this.#viewSlot(actorId, module, slot, { op: "subscribe", method: event });
271
- let stopped = false;
272
- let starting = true;
273
- let refused;
274
- const stop = this.#subscribeCore(actorId, name, event, {
275
- send: async (payload) => {
276
- await onEvent(payload);
277
- },
278
- end: (error) => {
279
- if (starting)
280
- refused = error;
281
- else if (!stopped)
282
- try {
283
- onEnd?.(error ? errorOf(error.error, name) : undefined);
284
- }
285
- catch {
286
- // The gateway's own trouble; other subscriptions and the unbind go on.
287
- }
288
- },
289
- });
290
- starting = false;
291
- // Refused at the start: thrown, as a module that isn't a view is.
292
- if (!stop)
293
- throw errorOf(refused?.error ?? { name: "NotConnected", message: name }, name);
294
- return () => {
295
- stopped = true;
296
- stop();
297
- };
175
+ return { closed, close: () => session.close() };
298
176
  }
299
- /**
300
- * A view module's slots, for the gateway's frame that shows it: `onSlot` hears each slot (named
301
- * within the module, as `viewCall` takes it) that is bound now, at once, then every change:
302
- * bound, unbound, and bound again when it is usable again: its provider's channel or the
303
- * Actor's own comes back. Refused unless `module` is one of the view modules of the Actor's
304
- * package; the Actor needn't be running. Returns how to stop, the only way a listener goes
305
- * (closing the Actor unbinds each slot, which it hears, but doesn't stop it).
306
- */
307
- viewSlots(actorId, module, onSlot) {
308
- this.#viewModule(actorId, module, { running: false });
309
- const listener = { module, onSlot };
310
- const listeners = this.#viewListeners.get(actorId) ?? new Set();
311
- this.#viewListeners.set(actorId, listeners);
312
- listeners.add(listener);
313
- const prefix = `${module}.`;
314
- for (const binding of this.state.bindings(actorId))
315
- if (binding.consumer === actorId &&
316
- binding.slot.startsWith(prefix) &&
317
- listeners.has(listener))
318
- this.#tellView(listener, binding.slot.slice(prefix.length), true);
319
- return () => {
320
- listeners.delete(listener);
321
- if (!listeners.size && this.#viewListeners.get(actorId) === listeners)
322
- this.#viewListeners.delete(actorId);
323
- };
324
- }
325
- /** A slot change to an Actor's view listeners whose module holds that slot. */
326
- #notifyViews(actorId, slot, bound) {
327
- const listeners = this.#viewListeners.get(actorId);
328
- // A copy, so a listener may stop itself or another; one stopped meanwhile hears no more.
329
- for (const listener of [...(listeners ?? [])])
330
- if (listeners?.has(listener) && slot.startsWith(`${listener.module}.`))
331
- this.#tellView(listener, slot.slice(listener.module.length + 1), bound);
332
- }
333
- #tellView(listener, slot, bound) {
334
- try {
335
- listener.onSlot(slot, bound);
336
- }
337
- catch {
338
- // The gateway's own trouble; other listeners and the change go on.
339
- }
340
- }
341
- /**
342
- * `<module>.<slot>` of a running package Actor, when `module` is one of its view modules. A
343
- * refusal here is audited as the Actor's, as a refusal while resolving a channel's call is.
344
- */
345
- #viewSlot(actorId, module, slot, call) {
346
- const name = `${module}.${slot}`;
347
- try {
348
- this.#viewModule(actorId, module, { running: true });
349
- return name;
350
- }
351
- catch (error) {
352
- if (error instanceof Refused && error.code !== "unknown")
353
- this.#audit(actorId, name, undefined, {
354
- ...call,
355
- outcome: outcomeOf(errorBody(error).error),
356
- });
357
- throw error;
358
- }
359
- }
360
- /** Refused unless `module` is one of the view modules of the Actor's package (and it runs). */
361
- #viewModule(actorId, module, options) {
362
- const actor = this.state.actor(actorId);
363
- if (actor.package === "external" || actor.package === "builtin")
364
- throw new Refused("forbidden", `${this.state.named(actorId)} has no package, so no views.`);
365
- if (options.running && actor.state !== "running")
366
- throw new Refused("state", `${this.state.named(actorId)} is ${actor.state}${actor.state === "closed" ? "" : "; start it with hub.actors.start"}.`);
367
- const { manifest } = this.state.package(actor.package);
368
- if (!Object.hasOwn(manifest.modules, module) || manifest.modules[module]?.placement !== "view")
369
- throw new Refused("forbidden", `${module} isn't a view module of ${this.state.named(actorId)}'s package; hub.actors.get lists its views.`);
370
- }
371
- /**
372
- * A line a view module logged, into its Actor's log, marked with the module. The Hub bounds it
373
- * itself: a known level, the text cut to 4 KiB, at most 16 fields of 1 KiB each, and its own time.
374
- * Refused `forbidden` for a module that isn't a view, `unknown` for no such Actor (or a closed
375
- * one whose package is gone); the Actor may be stopped or closed. Not audited: it isn't a call.
376
- * A line the disk won't take is dropped.
377
- */
378
- viewLog(actorId, module, line) {
379
- this.#viewModule(actorId, module, { running: false });
380
- try {
381
- appendLog(this.state.home, actorId, boundedEntry(line.level, line.message, line.data, module));
382
- }
383
- catch {
384
- // The disk's trouble (full, unwritable) isn't the view's: its line is lost, nothing else.
385
- }
386
- }
387
- /** Kill every host process, close every channel, admitted or not, then the state. */
177
+ /** Close every channel, admitted or not, then the state. */
388
178
  close() {
389
- this.#processes.close();
390
179
  for (const session of [...this.#sessions])
391
180
  session.close();
392
181
  this.#connections.clear();
393
- this.#viewListeners.clear();
394
182
  this.#validators.close();
395
- this.#storage.close();
396
183
  this.state.close();
397
184
  }
398
185
  #admit(actorId, session) {
@@ -406,13 +193,9 @@ export class Hub {
406
193
  this.#connections.set(actorId, conn);
407
194
  this.#actor.actorChanged(actorId);
408
195
  // Its consumers' subscriptions ended when it went; a notice tells each slot it is usable again.
409
- // Exports offered at run time went with the old channel, and their bindings with them. Its own
410
- // channel is new and learns its slots from hello; its views, served apart and callable only
411
- // while it runs, hear that each of their slots is usable again, whoever provides it.
196
+ // Its channel is new and learns its slots from hello.
412
197
  for (const binding of this.state.bindings(actorId))
413
- if (binding.consumer === actorId)
414
- this.#notifyViews(actorId, binding.slot, true);
415
- else if (this.state.declaration(actorId, "export", binding.export)?.dynamic === false)
198
+ if (binding.consumer !== actorId)
416
199
  this.#notify(binding.consumer, binding.slot, true);
417
200
  return conn;
418
201
  }
@@ -421,28 +204,15 @@ export class Hub {
421
204
  return;
422
205
  this.#connections.delete(conn.actorId);
423
206
  this.#actor.actorChanged(conn.actorId);
424
- try {
425
- this.state.disconnected(conn.actorId);
426
- }
427
- catch {
428
- // The state is closed: the Hub is shutting down.
429
- }
430
207
  }
431
- async #hello(stream, session, pipe, admit) {
208
+ async #hello(stream, session, admit) {
432
209
  const reader = new FrameReader(stream.readable);
433
210
  const writer = stream.writable.getWriter();
434
211
  try {
435
212
  const header = parseHeader(await reader.next());
436
213
  if (header.op !== "hello")
437
214
  throw new Refused("invalid", "A channel's first stream must be hello.");
438
- if (pipe) {
439
- // The pipe is the proof: it was made for this one Actor's process.
440
- if (header.actorId !== pipe.actorId)
441
- throw new Refused("forbidden", `This channel is ${this.state.named(pipe.actorId)}'s.`);
442
- if (header.declares !== undefined)
443
- throw new Refused("invalid", "A package Actor declares through its manifest.");
444
- }
445
- else if (header.credential === undefined ||
215
+ if (header.credential === undefined ||
446
216
  !this.state.authenticate(header.actorId, header.credential))
447
217
  throw new Refused("forbidden", "No such Actor, or the credential is wrong.");
448
218
  if (header.replace === false && this.#connections.has(header.actorId))
@@ -465,7 +235,7 @@ export class Hub {
465
235
  session.close(GO_AWAY.protocolError);
466
236
  }
467
237
  }
468
- /** Tell an Actor's channel and its views' listeners that one of its slots was bound or unbound. */
238
+ /** Tell an Actor's channel that one of its slots was bound or unbound. */
469
239
  /** A slot made at run time, as its consumer is told of it: the export's interface, and whose it is. */
470
240
  #exposure(binding) {
471
241
  return {
@@ -474,7 +244,6 @@ export class Hub {
474
244
  };
475
245
  }
476
246
  #notify(actorId, slot, bound) {
477
- this.#notifyViews(actorId, slot, bound);
478
247
  const conn = this.#connections.get(actorId);
479
248
  if (!conn)
480
249
  return;
@@ -545,6 +314,9 @@ export class Hub {
545
314
  catch {
546
315
  recomputed = undefined;
547
316
  }
317
+ // Any other kind could only come from a program built against an older SDK.
318
+ if (iface.kind !== "rpc")
319
+ throw new Refused("invalid", `${iface.id} isn't an rpc interface.`);
548
320
  // The hash keys the compiled schemas, so it is checked before anything is compiled.
549
321
  if (recomputed !== hash)
550
322
  throw new Refused("invalid", `${iface.id}'s hash doesn't match its schemas.`);
@@ -562,17 +334,6 @@ export class Hub {
562
334
  return await this.#call(conn, header, reader, writer);
563
335
  case "subscribe":
564
336
  return await this.#subscribe(conn, header, stream, reader, writer);
565
- case "open":
566
- case "http":
567
- return await this.#splice(conn, header, stream, reader, writer);
568
- case "offer":
569
- this.state.offer(conn.actorId, header.name, await this.#described(conn.actorId, header.interface, "interface"));
570
- await answer(writer, result({}));
571
- return drain(reader);
572
- case "withdraw":
573
- this.state.withdraw(conn.actorId, header.name);
574
- await answer(writer, result({}));
575
- return drain(reader);
576
337
  default:
577
338
  throw new Refused("invalid", `A ${header.op} stream can't be opened here.`);
578
339
  }
@@ -582,7 +343,7 @@ export class Hub {
582
343
  drain(reader);
583
344
  }
584
345
  }
585
- /** Keep an open subscription or splice under its binding, so the binding's end ends it. */
346
+ /** Keep an open subscription under its binding, so the binding's end ends it. */
586
347
  #track(binding, end) {
587
348
  const key = bindingKey(binding);
588
349
  const ends = this.#live.get(key) ?? new Set();
@@ -597,16 +358,14 @@ export class Hub {
597
358
  // Every schema check runs in the turn of the Actor the work is for: a call's input and output in
598
359
  // the caller's, a subscription's events in the subscriber's, a hello's or offer's compile in the
599
360
  // declaring Actor's. A slow provider so delays only the callers using it, each in its own turn.
600
- /** A consumer's slot, resolved through its binding to a live provider of the right kind. */
601
- #resolve(caller, slot, kind) {
361
+ /** A consumer's slot, resolved through its binding to a live provider. */
362
+ #resolve(caller, slot) {
602
363
  const resolved = this.state.resolveCall(caller, slot);
603
364
  if (!resolved)
604
365
  throw new NotConnected(slot);
605
366
  const { binding, target } = resolved;
606
- if (target.iface.kind !== kind)
607
- throw new Refused("invalid", `${slot} is an ${target.iface.kind} slot, not ${kind}.`);
608
- // The built-in Actors are served in this process; any other provider needs its channel.
609
- const builtin = binding.provider === HUB || binding.provider === STORAGE || binding.provider === NET;
367
+ // The hub is served in this process; any other provider needs its channel.
368
+ const builtin = binding.provider === HUB;
610
369
  const provider = builtin ? undefined : this.#connections.get(binding.provider);
611
370
  if (!builtin && !provider)
612
371
  throw new NotConnected(slot);
@@ -636,7 +395,7 @@ export class Hub {
636
395
  drain(reader);
637
396
  }
638
397
  /**
639
- * A call through a caller's slot, without a channel: resolve it, check the input, reach the
398
+ * A call through a caller's slot: resolve it, check the input, reach the
640
399
  * provider, check the output, audit. `input` gives the value (and how the caller cancels) once
641
400
  * the slot is known to have the method.
642
401
  */
@@ -645,7 +404,7 @@ export class Hub {
645
404
  let reply;
646
405
  let outcome = "ok";
647
406
  try {
648
- const resolved = this.#resolve(caller, slot, "rpc");
407
+ const resolved = this.#resolve(caller, slot);
649
408
  binding = resolved.binding;
650
409
  const { iface, provider } = resolved;
651
410
  const part = { method, side: "input" };
@@ -673,38 +432,10 @@ export class Hub {
673
432
  this.#audit(caller, slot, binding, { op: "call", method, outcome });
674
433
  return encoded;
675
434
  }
676
- /**
677
- * `storage.admin@1`'s seed, for its caller (the installer): into a live Actor's empty store,
678
- * audited with the consumer, the slot and how many entries.
679
- */
680
- #seed(caller, method, input) {
681
- if (method !== "seed")
682
- throw new Refused("unimplemented", `storage.admin@1 has no method ${method}.`);
683
- if (this.state.actor(input.consumer).state === "closed")
684
- throw new Refused("state", `${this.state.named(input.consumer)} is closed for good.`);
685
- // Only a store the consumer can reach: its slot, bound to storage's kv.
686
- const bound = this.state.binding(input.consumer, input.slot);
687
- if (bound?.provider !== STORAGE || bound.export !== "kv")
688
- throw new Refused("invalid", `${this.state.named(input.consumer)}'s ${input.slot} isn't a slot bound to storage.kv; bind it there first.`);
689
- this.#storage.seed(input.consumer, input.slot, input.entries, this.state.named(input.consumer));
690
- // The seed is done; an audit that fails now (the Hub closing) doesn't undo or hide it.
691
- try {
692
- this.state.auditHub("storage.seed", { consumer: input.consumer, slot: input.slot, entries: input.entries.length }, caller);
693
- }
694
- catch {
695
- // The state is closed.
696
- }
697
- return {};
698
- }
699
- /** A call to a built-in Actor: the hub, or storage with the consumer's own store. */
435
+ /** A call to the hub's own exports. */
700
436
  async #builtinCall(binding, method, caller, value) {
701
437
  try {
702
- const out = binding.provider !== STORAGE
703
- ? await this.#actor.call(binding.export, method, caller, value)
704
- : binding.export === "admin"
705
- ? this.#seed(caller, method, value)
706
- : this.#storage.call(binding.consumer, binding.slot, method, value);
707
- return result(asJson(out));
438
+ return result(asJson(await this.#actor.call(binding.export, method, caller, value)));
708
439
  }
709
440
  catch (error) {
710
441
  return errorBody(error);
@@ -806,7 +537,7 @@ export class Hub {
806
537
  reader.next().then((more) => more !== undefined && stop(wireError("Refused", "A subscriber sends nothing.", "invalid")), () => stop());
807
538
  }
808
539
  /**
809
- * Events of a caller's slot, without a channel: each checked, then handed to `sink` in order, the
540
+ * Events of a caller's slot: each checked, then handed to `sink` in order, the
810
541
  * next waiting for the last to be taken, until the provider ends it, the binding goes, or the
811
542
  * returned `stop` runs. A refusal at the start ends the sink at once and returns nothing.
812
543
  */
@@ -814,7 +545,7 @@ export class Hub {
814
545
  let resolved;
815
546
  const part = { event };
816
547
  try {
817
- resolved = this.#resolve(caller, slot, "rpc");
548
+ resolved = this.#resolve(caller, slot);
818
549
  if (!this.#validators.has(resolved.iface, part))
819
550
  throw new Refused("invalid", `${resolved.iface.id} has no event ${event}.`);
820
551
  }
@@ -937,110 +668,4 @@ export class Hub {
937
668
  })();
938
669
  return end;
939
670
  }
940
- /**
941
- * An accepted http stream to `net`: its requests are made from this process, HTTP/1.1 over the
942
- * stream's raw bytes, until either side ends it or its binding goes.
943
- */
944
- async #egress(consumer, binding, stream, reader, writer, untrack) {
945
- try {
946
- await writer.write(encodeFrame(result({})));
947
- }
948
- catch {
949
- untrack();
950
- return stream.reset();
951
- }
952
- writer.releaseLock();
953
- await serveOver({ readable: reader.rest(), writable: stream.writable }, (request) => this.#net.handle(request, { consumer, slot: binding.slot }), QUIET);
954
- untrack();
955
- }
956
- /**
957
- * `open` and `http`: validated, then the provider accepts or refuses with one body, which the Hub
958
- * passes on; after an accept, raw bytes both ways until either side ends them.
959
- */
960
- async #splice(conn, header, stream, reader, writer) {
961
- let binding;
962
- let out;
963
- let upstream;
964
- let answered;
965
- let outcome = "ok";
966
- let unbound = false;
967
- let untrack = () => { };
968
- /** `net`'s egress, served here: no provider stream to splice. */
969
- let egress = false;
970
- try {
971
- const resolved = this.#resolve(conn.actorId, header.slot, header.op === "open" ? "stream" : "http");
972
- binding = resolved.binding;
973
- // Tracked from here, so a binding that goes while the provider decides ends it too.
974
- untrack = this.#track(binding, () => {
975
- unbound = true;
976
- out?.reset();
977
- stream.reset();
978
- });
979
- if (header.op === "open")
980
- await this.#validators.check(conn.actorId, resolved.iface, { open: true }, header.params, "invalid");
981
- if (!resolved.provider && binding.provider === NET && header.op === "http") {
982
- // net's egress is served in this process: accepted here, then the stream is its.
983
- egress = true;
984
- answered = result({});
985
- }
986
- else {
987
- // The hub's and storage's exports are all rpc, so #resolve refused them already.
988
- if (!resolved.provider)
989
- throw new NotConnected(header.slot);
990
- const opened = this.#openTo(resolved.provider, binding);
991
- out = opened;
992
- try {
993
- const head = opened.writable.getWriter();
994
- await head.write(encodeFrame({
995
- op: "serve",
996
- kind: header.op,
997
- export: binding.export,
998
- caller: conn.actorId,
999
- slot: binding.slot,
1000
- ...(header.op === "open" ? { params: header.params } : {}),
1001
- }));
1002
- head.releaseLock();
1003
- }
1004
- catch {
1005
- throw new OutcomeUnknown(`${binding.provider} went away before answering.`);
1006
- }
1007
- upstream = new FrameReader(opened.readable);
1008
- const body = await this.#answerFrom(opened, upstream, binding, new Promise(() => { }));
1009
- if (unbound)
1010
- throw new NotConnected(header.slot);
1011
- if ("error" in body) {
1012
- outcome = "refused";
1013
- answered = body;
1014
- }
1015
- else if ("result" in body)
1016
- answered = result({});
1017
- else
1018
- throw new Refused("bad_output", "A provider answers an open with {result} or {error}.");
1019
- }
1020
- }
1021
- catch (error) {
1022
- answered = errorBody(unbound ? new NotConnected(header.slot) : error);
1023
- outcome = outcomeOf(answered.error);
1024
- }
1025
- this.#audit(conn.actorId, header.slot, binding, { op: header.op, outcome });
1026
- if (egress && binding && "result" in answered)
1027
- return this.#egress(conn.actorId, binding, stream, reader, writer, untrack);
1028
- if (!("result" in answered) || !out || !upstream) {
1029
- untrack();
1030
- out?.reset();
1031
- await answer(writer, answered);
1032
- return drain(reader);
1033
- }
1034
- const provider = out;
1035
- try {
1036
- await writer.write(encodeFrame(answered));
1037
- }
1038
- catch {
1039
- untrack();
1040
- return provider.reset();
1041
- }
1042
- writer.releaseLock();
1043
- await Promise.all([pass(reader.rest(), provider), pass(upstream.rest(), stream)]);
1044
- untrack();
1045
- }
1046
671
  }