@agentorg/cli 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -104
- package/dist/node_modules/@agentorg/computer/LICENSE +201 -0
- package/dist/node_modules/@agentorg/computer/NOTICE +2 -0
- package/dist/node_modules/@agentorg/computer/dist/THIRD_PARTY_LICENSES.txt +1321 -0
- package/dist/node_modules/@agentorg/computer/dist/sdk.js +24909 -0
- package/dist/node_modules/@agentorg/computer/dist/types/generated/schema.d.ts +860 -0
- package/dist/node_modules/@agentorg/computer/dist/types/sdk.d.ts +242 -0
- package/dist/node_modules/@agentorg/computer/package.json +12 -0
- package/dist/node_modules/@agentorg/computer-connector/dist/src/index.d.ts +1 -0
- package/dist/node_modules/@agentorg/computer-connector/dist/src/index.js +1 -0
- package/dist/node_modules/@agentorg/computer-connector/dist/src/provider.d.ts +24 -0
- package/dist/node_modules/@agentorg/computer-connector/dist/src/provider.js +482 -0
- package/dist/node_modules/@agentorg/computer-connector/dist/src/unit.d.ts +19 -0
- package/dist/node_modules/@agentorg/computer-connector/dist/src/unit.js +149 -0
- package/dist/node_modules/@agentorg/computer-connector/package.json +33 -0
- package/dist/node_modules/@agentorg/computer-connector/skills/browser/SKILL.md +31 -0
- package/dist/node_modules/@agentorg/computer-connector/skills/computer/SKILL.md +30 -0
- package/dist/node_modules/@agentorg/computer-connector/skills/files/SKILL.md +28 -0
- package/dist/node_modules/@agentorg/computer-connector/skills/terminal/SKILL.md +39 -0
- package/dist/node_modules/@agentorg/computer-connector/skills/web-research/SKILL.md +29 -0
- package/dist/node_modules/@agentorg/hub/dist/src/hub-actor.d.ts +2 -7
- package/dist/node_modules/@agentorg/hub/dist/src/hub-actor.js +4 -144
- package/dist/node_modules/@agentorg/hub/dist/src/index.d.ts +1 -3
- package/dist/node_modules/@agentorg/hub/dist/src/index.js +1 -3
- package/dist/node_modules/@agentorg/hub/dist/src/router.d.ts +9 -58
- package/dist/node_modules/@agentorg/hub/dist/src/router.js +41 -414
- package/dist/node_modules/@agentorg/hub/dist/src/state.d.ts +17 -317
- package/dist/node_modules/@agentorg/hub/dist/src/state.js +42 -536
- package/dist/node_modules/@agentorg/hub/dist/src/validate.d.ts +1 -3
- package/dist/node_modules/@agentorg/hub/dist/src/validate.js +19 -17
- package/dist/node_modules/@agentorg/hub/package.json +0 -3
- package/dist/node_modules/@agentorg/interfaces/dist/src/agent-provider.d.ts +119 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/agent-provider.js +96 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/agent-settings.d.ts +42 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/agent-settings.js +53 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/chat.d.ts +93 -38
- package/dist/node_modules/@agentorg/interfaces/dist/src/chat.js +71 -22
- package/dist/node_modules/@agentorg/interfaces/dist/src/connection.d.ts +36 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/connection.js +31 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/folders.d.ts +19 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/folders.js +25 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/hub.d.ts +16 -286
- package/dist/node_modules/@agentorg/interfaces/dist/src/hub.js +17 -159
- package/dist/node_modules/@agentorg/interfaces/dist/src/index.d.ts +9 -9
- package/dist/node_modules/@agentorg/interfaces/dist/src/index.js +9 -9
- package/dist/node_modules/@agentorg/interfaces/dist/src/kv.d.ts +2 -2
- package/dist/node_modules/@agentorg/interfaces/dist/src/kv.js +2 -2
- package/dist/node_modules/@agentorg/interfaces/dist/src/llm-session.d.ts +2 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/llm-session.js +2 -1
- package/dist/node_modules/@agentorg/interfaces/dist/src/manager.d.ts +626 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/manager.js +349 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/tools.d.ts +39 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/tools.js +43 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/units.d.ts +460 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/units.js +204 -0
- package/dist/node_modules/@agentorg/looper/dist/src/index.d.ts +5 -0
- package/dist/node_modules/@agentorg/looper/dist/src/index.js +5 -0
- package/dist/node_modules/@agentorg/looper/dist/src/loop.d.ts +75 -0
- package/dist/node_modules/@agentorg/looper/dist/src/loop.js +332 -0
- package/dist/node_modules/@agentorg/looper/dist/src/looper.d.ts +71 -0
- package/dist/node_modules/@agentorg/looper/dist/src/looper.js +282 -0
- package/dist/node_modules/@agentorg/looper/dist/src/record.d.ts +99 -0
- package/dist/node_modules/@agentorg/looper/dist/src/record.js +278 -0
- package/dist/node_modules/@agentorg/looper/dist/src/tools.d.ts +11 -0
- package/dist/node_modules/@agentorg/looper/dist/src/tools.js +42 -0
- package/dist/node_modules/@agentorg/looper/dist/src/types.d.ts +147 -0
- package/dist/node_modules/@agentorg/looper/dist/src/types.js +32 -0
- package/dist/node_modules/@agentorg/looper/package.json +24 -0
- package/dist/node_modules/@agentorg/manager/dist/src/activity.d.ts +18 -0
- package/dist/node_modules/@agentorg/manager/dist/src/activity.js +65 -0
- package/dist/node_modules/@agentorg/manager/dist/src/control.d.ts +134 -0
- package/dist/node_modules/@agentorg/manager/dist/src/control.js +1115 -0
- package/dist/node_modules/@agentorg/manager/dist/src/form.d.ts +40 -0
- package/dist/node_modules/@agentorg/manager/dist/src/form.js +191 -0
- package/dist/node_modules/@agentorg/manager/dist/src/index.d.ts +1 -0
- package/dist/node_modules/@agentorg/manager/dist/src/index.js +1 -0
- package/dist/node_modules/@agentorg/manager/dist/src/manager.d.ts +25 -0
- package/dist/node_modules/@agentorg/manager/dist/src/manager.js +680 -0
- package/dist/node_modules/@agentorg/manager/dist/src/skills.d.ts +27 -0
- package/dist/node_modules/@agentorg/manager/dist/src/skills.js +152 -0
- package/dist/node_modules/@agentorg/manager/dist/src/stack.d.ts +454 -0
- package/dist/node_modules/@agentorg/manager/dist/src/stack.js +917 -0
- package/dist/node_modules/@agentorg/manager/package.json +30 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/connection.d.ts +34 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/connection.js +296 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/index.d.ts +4 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/index.js +4 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/kinds.d.ts +158 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/kinds.js +164 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/provider.d.ts +22 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/provider.js +197 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/public.d.ts +6 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/public.js +72 -0
- package/dist/node_modules/@agentorg/mcp/package.json +31 -0
- package/dist/node_modules/@agentorg/sdk/dist/src/cli.js +3 -23
- package/dist/node_modules/@agentorg/sdk/dist/src/client.d.ts +4 -25
- package/dist/node_modules/@agentorg/sdk/dist/src/client.js +5 -55
- package/dist/node_modules/@agentorg/sdk/dist/src/errors.d.ts +1 -1
- package/dist/node_modules/@agentorg/sdk/dist/src/errors.js +3 -3
- package/dist/node_modules/@agentorg/sdk/dist/src/filled.d.ts +21 -0
- package/dist/node_modules/@agentorg/sdk/dist/src/filled.js +24 -0
- package/dist/node_modules/@agentorg/sdk/dist/src/index.d.ts +3 -2
- package/dist/node_modules/@agentorg/sdk/dist/src/index.js +2 -1
- package/dist/node_modules/@agentorg/sdk/dist/src/interface.d.ts +6 -34
- package/dist/node_modules/@agentorg/sdk/dist/src/interface.js +3 -24
- package/dist/node_modules/@agentorg/sdk/dist/src/module-host.d.ts +8 -17
- package/dist/node_modules/@agentorg/sdk/dist/src/module-host.js +15 -87
- package/dist/node_modules/@agentorg/sdk/dist/src/module.d.ts +10 -76
- package/dist/node_modules/@agentorg/sdk/dist/src/module.js +3 -23
- package/dist/node_modules/@agentorg/sdk/dist/src/person-commands.js +0 -5
- package/dist/node_modules/@agentorg/sdk/dist/src/runtime.d.ts +3 -27
- package/dist/node_modules/@agentorg/sdk/dist/src/runtime.js +5 -100
- package/dist/node_modules/@agentorg/sdk/dist/src/testing.d.ts +7 -8
- package/dist/node_modules/@agentorg/sdk/dist/src/testing.js +12 -24
- package/dist/node_modules/@agentorg/sdk/package.json +4 -37
- package/dist/node_modules/@agentorg/shell/dist/app.css +4624 -739
- package/dist/node_modules/@agentorg/shell/dist/app.js +245 -202
- package/dist/node_modules/@agentorg/shell/package.json +23 -10
- package/dist/node_modules/@agentorg/wire/dist/src/frames.d.ts +2 -3
- package/dist/node_modules/@agentorg/wire/dist/src/frames.js +2 -3
- package/dist/node_modules/@agentorg/wire/dist/src/ops.d.ts +5 -34
- package/dist/node_modules/@agentorg/wire/dist/src/ops.js +2 -17
- package/dist/node_modules/assistant/dist/src/chats.d.ts +92 -0
- package/dist/node_modules/assistant/dist/src/chats.js +357 -0
- package/dist/node_modules/assistant/dist/src/engine.d.ts +42 -0
- package/dist/node_modules/assistant/dist/src/engine.js +160 -0
- package/dist/node_modules/assistant/dist/src/local-store.d.ts +3 -0
- package/dist/node_modules/assistant/dist/src/local-store.js +58 -0
- package/dist/node_modules/assistant/dist/src/provider.d.ts +21 -0
- package/dist/node_modules/assistant/dist/src/provider.js +259 -0
- package/dist/node_modules/assistant/dist/src/settings.d.ts +17 -0
- package/dist/node_modules/assistant/dist/src/settings.js +43 -0
- package/dist/node_modules/assistant/dist/src/tools.d.ts +57 -0
- package/dist/node_modules/assistant/dist/src/tools.js +102 -0
- package/dist/node_modules/assistant/package.json +30 -0
- package/dist/node_modules/chatgpt/dist/src/account.d.ts +52 -0
- package/dist/node_modules/chatgpt/dist/src/account.js +270 -0
- package/dist/node_modules/chatgpt/dist/src/encoding.d.ts +7 -0
- package/dist/node_modules/chatgpt/dist/src/encoding.js +20 -0
- package/dist/node_modules/chatgpt/dist/src/file-store.d.ts +9 -0
- package/dist/node_modules/chatgpt/dist/src/file-store.js +68 -0
- package/dist/node_modules/chatgpt/dist/src/index.d.ts +1 -0
- package/dist/node_modules/chatgpt/dist/src/index.js +1 -0
- package/dist/node_modules/chatgpt/dist/src/jwt.d.ts +15 -0
- package/dist/node_modules/chatgpt/dist/src/jwt.js +37 -0
- package/dist/node_modules/chatgpt/dist/src/oauth.d.ts +43 -0
- package/dist/node_modules/chatgpt/dist/src/oauth.js +104 -0
- package/dist/node_modules/chatgpt/dist/src/program.d.ts +23 -0
- package/dist/node_modules/chatgpt/dist/src/program.js +41 -0
- package/dist/node_modules/chatgpt/dist/src/responses.d.ts +54 -0
- package/dist/node_modules/chatgpt/dist/src/responses.js +300 -0
- package/dist/node_modules/chatgpt/dist/src/serve.d.ts +65 -0
- package/dist/node_modules/chatgpt/dist/src/serve.js +46 -0
- package/dist/node_modules/chatgpt/package.json +33 -0
- package/dist/src/api.d.ts +5 -34
- package/dist/src/api.js +10 -68
- package/dist/src/cli.js +3 -7
- package/dist/src/folders.d.ts +2 -0
- package/dist/src/folders.js +45 -0
- package/dist/src/gateway.d.ts +13 -8
- package/dist/src/gateway.js +119 -296
- package/dist/src/index.d.ts +4 -5
- package/dist/src/index.js +3 -4
- package/dist/src/live.d.ts +17 -0
- package/dist/src/live.js +109 -0
- package/dist/src/notes.d.ts +11 -0
- package/dist/src/notes.js +64 -0
- package/dist/src/oauth.d.ts +16 -0
- package/dist/src/oauth.js +46 -0
- package/dist/src/programs.d.ts +36 -0
- package/dist/src/programs.js +198 -0
- package/dist/src/signin.d.ts +12 -3
- package/dist/src/signin.js +30 -6
- package/package.json +4 -11
- package/dist/bundled/index.json +0 -6
- package/dist/bundled/sha256-0e91cc3d0e9762b81abc2427b5496b20f383abcd6fb97d928a8d50e956b54d1f.agentorg +0 -0
- package/dist/bundled/sha256-1f64ca62a0209d767d6aa6c4feb50b0653d60f10bebbc301f79bd3a37e0153c1.agentorg +0 -0
- package/dist/bundled/sha256-4055f8fddf6b90f3d356543f554b2a9e9a2c4a8827a8774f8f87952dc1692331.agentorg +0 -0
- package/dist/bundled/sha256-e356ea3c1899138a8494baf521556831006f38534fa9e92ae873e7e6956c3a46.agentorg +0 -0
- package/dist/node_modules/@agentorg/hub/dist/src/build.d.ts +0 -17
- package/dist/node_modules/@agentorg/hub/dist/src/build.js +0 -120
- package/dist/node_modules/@agentorg/hub/dist/src/logs.d.ts +0 -33
- package/dist/node_modules/@agentorg/hub/dist/src/logs.js +0 -162
- package/dist/node_modules/@agentorg/hub/dist/src/net.d.ts +0 -41
- package/dist/node_modules/@agentorg/hub/dist/src/net.js +0 -265
- package/dist/node_modules/@agentorg/hub/dist/src/processes.d.ts +0 -78
- package/dist/node_modules/@agentorg/hub/dist/src/processes.js +0 -485
- package/dist/node_modules/@agentorg/hub/dist/src/storage.d.ts +0 -38
- package/dist/node_modules/@agentorg/hub/dist/src/storage.js +0 -194
- package/dist/node_modules/@agentorg/interfaces/dist/src/http-egress.d.ts +0 -6
- package/dist/node_modules/@agentorg/interfaces/dist/src/http-egress.js +0 -7
- package/dist/node_modules/@agentorg/interfaces/dist/src/installer.d.ts +0 -191
- package/dist/node_modules/@agentorg/interfaces/dist/src/installer.js +0 -136
- package/dist/node_modules/@agentorg/interfaces/dist/src/layout.d.ts +0 -47
- package/dist/node_modules/@agentorg/interfaces/dist/src/layout.js +0 -52
- package/dist/node_modules/@agentorg/interfaces/dist/src/rules.d.ts +0 -35
- package/dist/node_modules/@agentorg/interfaces/dist/src/rules.js +0 -37
- package/dist/node_modules/@agentorg/interfaces/dist/src/storage-admin.d.ts +0 -23
- package/dist/node_modules/@agentorg/interfaces/dist/src/storage-admin.js +0 -31
- package/dist/node_modules/@agentorg/interfaces/dist/src/ui-shell.d.ts +0 -14
- package/dist/node_modules/@agentorg/interfaces/dist/src/ui-shell.js +0 -26
- package/dist/node_modules/@agentorg/interfaces/dist/src/ui-view.d.ts +0 -27
- package/dist/node_modules/@agentorg/interfaces/dist/src/ui-view.js +0 -26
- package/dist/node_modules/@agentorg/kit/dist/src/chat.d.ts +0 -37
- package/dist/node_modules/@agentorg/kit/dist/src/chat.js +0 -131
- package/dist/node_modules/@agentorg/kit/dist/src/components.d.ts +0 -94
- package/dist/node_modules/@agentorg/kit/dist/src/components.js +0 -66
- package/dist/node_modules/@agentorg/kit/dist/src/icons.d.ts +0 -17
- package/dist/node_modules/@agentorg/kit/dist/src/icons.js +0 -30
- package/dist/node_modules/@agentorg/kit/dist/src/index.d.ts +0 -6
- package/dist/node_modules/@agentorg/kit/dist/src/index.js +0 -10
- package/dist/node_modules/@agentorg/kit/dist/src/markdown.d.ts +0 -9
- package/dist/node_modules/@agentorg/kit/dist/src/markdown.js +0 -14
- package/dist/node_modules/@agentorg/kit/dist/src/resizable.d.ts +0 -5
- package/dist/node_modules/@agentorg/kit/dist/src/resizable.js +0 -8
- package/dist/node_modules/@agentorg/kit/dist/src/styles.d.ts +0 -11
- package/dist/node_modules/@agentorg/kit/dist/src/styles.js +0 -166
- package/dist/node_modules/@agentorg/kit/package.json +0 -44
- package/dist/node_modules/@agentorg/sdk/dist/frame/runtime.js +0 -753
- package/dist/node_modules/@agentorg/sdk/dist/host/runner.js +0 -21963
- package/dist/node_modules/@agentorg/sdk/dist/src/build.d.ts +0 -2
- package/dist/node_modules/@agentorg/sdk/dist/src/build.js +0 -2
- package/dist/node_modules/@agentorg/sdk/dist/src/client-http.d.ts +0 -24
- package/dist/node_modules/@agentorg/sdk/dist/src/client-http.js +0 -247
- package/dist/node_modules/@agentorg/sdk/dist/src/describe.d.ts +0 -13
- package/dist/node_modules/@agentorg/sdk/dist/src/describe.js +0 -16
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-base.d.ts +0 -8
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-base.js +0 -64
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-entry.d.ts +0 -1
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-entry.js +0 -35
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-host.d.ts +0 -57
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-host.js +0 -293
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-protocol.d.ts +0 -124
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-protocol.js +0 -16
- package/dist/node_modules/@agentorg/sdk/dist/src/frame.d.ts +0 -25
- package/dist/node_modules/@agentorg/sdk/dist/src/frame.js +0 -248
- package/dist/node_modules/@agentorg/sdk/dist/src/host-main.d.ts +0 -1
- package/dist/node_modules/@agentorg/sdk/dist/src/host-main.js +0 -60
- package/dist/node_modules/@agentorg/sdk/dist/src/host.d.ts +0 -25
- package/dist/node_modules/@agentorg/sdk/dist/src/host.js +0 -92
- package/dist/node_modules/@agentorg/sdk/dist/src/manifest-api.d.ts +0 -2
- package/dist/node_modules/@agentorg/sdk/dist/src/manifest-api.js +0 -2
- package/dist/node_modules/@agentorg/sdk/dist/src/manifest.d.ts +0 -56
- package/dist/node_modules/@agentorg/sdk/dist/src/manifest.js +0 -165
- package/dist/node_modules/@agentorg/sdk/dist/src/package.d.ts +0 -60
- package/dist/node_modules/@agentorg/sdk/dist/src/package.js +0 -538
- package/dist/node_modules/@agentorg/sdk/dist/src/tar.d.ts +0 -7
- package/dist/node_modules/@agentorg/sdk/dist/src/tar.js +0 -71
- package/dist/node_modules/@agentorg/shell/dist/agent-bindings.js +0 -59
- package/dist/node_modules/@agentorg/shell/src/agent-bindings.ts +0 -107
- package/dist/src/frames.d.ts +0 -23
- package/dist/src/frames.js +0 -78
- package/dist/src/layout.d.ts +0 -44
- package/dist/src/layout.js +0 -90
- package/dist/src/model.d.ts +0 -54
- package/dist/src/model.js +0 -299
- package/dist/src/rules.d.ts +0 -71
- package/dist/src/rules.js +0 -157
- package/dist/src/transfer.d.ts +0 -30
- package/dist/src/transfer.js +0 -110
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { hashInterface, NotConnected, OutcomeUnknown, Refused, } from "@agentorg/sdk";
|
|
2
|
-
import {
|
|
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 {
|
|
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
|
-
*
|
|
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,21 +88,18 @@ 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
|
|
92
|
+
/** Open subscriptions by the binding they run through, ended when it goes. */
|
|
118
93
|
#live = new Map();
|
|
119
94
|
#helloTimeoutMs;
|
|
120
95
|
#answerTimeoutMs;
|
|
96
|
+
#answerTimeoutsMs;
|
|
121
97
|
/** Every channel's session, admitted or still in hello. */
|
|
122
98
|
#sessions = new Set();
|
|
123
|
-
/** `viewSlots` listeners by Actor: each hears its view module's slot changes. */
|
|
124
|
-
#viewListeners = new Map();
|
|
125
99
|
constructor(home, options) {
|
|
126
100
|
this.#helloTimeoutMs = options.helloTimeoutMs ?? 10_000;
|
|
127
101
|
this.#answerTimeoutMs = options.answerTimeoutMs ?? 60_000;
|
|
102
|
+
this.#answerTimeoutsMs = options.answerTimeoutsMs ?? {};
|
|
128
103
|
this.#validators = new Validators(options.checks);
|
|
129
104
|
let actor;
|
|
130
105
|
this.state = HubState.open(home, {
|
|
@@ -136,45 +111,16 @@ export class Hub {
|
|
|
136
111
|
this.#notify(binding.consumer, binding.slot, false);
|
|
137
112
|
}
|
|
138
113
|
},
|
|
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),
|
|
114
|
+
closed: (actorId) => this.#connections.get(actorId)?.session.close(),
|
|
146
115
|
exportsChanged: (changed) => actor?.exportsChanged(changed),
|
|
147
116
|
actorChanged: (changed) => actor?.actorChanged(changed),
|
|
148
117
|
audited: (entry) => actor?.audited(entry),
|
|
149
118
|
});
|
|
150
|
-
this.#
|
|
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
|
-
}
|
|
119
|
+
actor = this.#actor = new HubActor(this.state, (id) => this.connected(id));
|
|
169
120
|
}
|
|
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
|
-
*/
|
|
121
|
+
/** Open the Hub in its home. */
|
|
174
122
|
static open(home, options = {}) {
|
|
175
|
-
|
|
176
|
-
hub.#processes.probe().catch(() => { });
|
|
177
|
-
return hub;
|
|
123
|
+
return new Hub(home, options);
|
|
178
124
|
}
|
|
179
125
|
/** Whether an Actor has a channel now. */
|
|
180
126
|
connected(actorId) {
|
|
@@ -182,22 +128,11 @@ export class Hub {
|
|
|
182
128
|
}
|
|
183
129
|
/**
|
|
184
130
|
* Take a channel. Its first stream must be `hello`, and nothing else may open before it is
|
|
185
|
-
* admitted.
|
|
186
|
-
*
|
|
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.
|
|
131
|
+
* admitted. A hello carries the Actor's credential, within the hello deadline. The handle settles
|
|
132
|
+
* when the channel ends, and closes it.
|
|
189
133
|
*/
|
|
190
|
-
accept(channel
|
|
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
|
-
}
|
|
134
|
+
accept(channel) {
|
|
196
135
|
let conn;
|
|
197
|
-
let admit;
|
|
198
|
-
const admittedNow = new Promise((resolve) => {
|
|
199
|
-
admit = resolve;
|
|
200
|
-
});
|
|
201
136
|
let helloSeen = false;
|
|
202
137
|
let ended = false;
|
|
203
138
|
const options = {
|
|
@@ -210,11 +145,10 @@ export class Hub {
|
|
|
210
145
|
stream.reset();
|
|
211
146
|
else {
|
|
212
147
|
helloSeen = true;
|
|
213
|
-
void this.#hello(stream, session,
|
|
148
|
+
void this.#hello(stream, session, (actorId, replace) => {
|
|
214
149
|
if (ended)
|
|
215
150
|
throw new NotConnected("The channel");
|
|
216
|
-
// Closed while its hello was on the way
|
|
217
|
-
// being checked): a closed Actor is never admitted.
|
|
151
|
+
// Closed while its hello was on the way: a closed Actor is never admitted.
|
|
218
152
|
if (this.state.actor(actorId).state === "closed")
|
|
219
153
|
throw new Refused("state", `${this.state.named(actorId)} is closed for good; make another.`);
|
|
220
154
|
// Checked again as the channel is admitted: one may have connected while declares
|
|
@@ -222,7 +156,6 @@ export class Hub {
|
|
|
222
156
|
if (replace === false && this.#connections.has(actorId))
|
|
223
157
|
throw new Refused("connected", `${this.state.named(actorId)} already has a channel to this Hub; close that one first.`);
|
|
224
158
|
conn = this.#admit(actorId, session);
|
|
225
|
-
admit();
|
|
226
159
|
options.maxStreams = MAX_STREAMS;
|
|
227
160
|
});
|
|
228
161
|
}
|
|
@@ -230,13 +163,10 @@ export class Hub {
|
|
|
230
163
|
};
|
|
231
164
|
const session = new Session(channel, options);
|
|
232
165
|
this.#sessions.add(session);
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if (!conn)
|
|
238
|
-
session.close(GO_AWAY.protocolError);
|
|
239
|
-
}, this.#helloTimeoutMs);
|
|
166
|
+
const timer = setTimeout(() => {
|
|
167
|
+
if (!conn)
|
|
168
|
+
session.close(GO_AWAY.protocolError);
|
|
169
|
+
}, this.#helloTimeoutMs);
|
|
240
170
|
const closed = session.closed.then(() => {
|
|
241
171
|
ended = true;
|
|
242
172
|
clearTimeout(timer);
|
|
@@ -244,155 +174,14 @@ export class Hub {
|
|
|
244
174
|
if (conn)
|
|
245
175
|
this.#dropped(conn);
|
|
246
176
|
});
|
|
247
|
-
return {
|
|
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
|
-
};
|
|
177
|
+
return { closed, close: () => session.close() };
|
|
298
178
|
}
|
|
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. */
|
|
179
|
+
/** Close every channel, admitted or not, then the state. */
|
|
388
180
|
close() {
|
|
389
|
-
this.#processes.close();
|
|
390
181
|
for (const session of [...this.#sessions])
|
|
391
182
|
session.close();
|
|
392
183
|
this.#connections.clear();
|
|
393
|
-
this.#viewListeners.clear();
|
|
394
184
|
this.#validators.close();
|
|
395
|
-
this.#storage.close();
|
|
396
185
|
this.state.close();
|
|
397
186
|
}
|
|
398
187
|
#admit(actorId, session) {
|
|
@@ -406,13 +195,9 @@ export class Hub {
|
|
|
406
195
|
this.#connections.set(actorId, conn);
|
|
407
196
|
this.#actor.actorChanged(actorId);
|
|
408
197
|
// Its consumers' subscriptions ended when it went; a notice tells each slot it is usable again.
|
|
409
|
-
//
|
|
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.
|
|
198
|
+
// Its channel is new and learns its slots from hello.
|
|
412
199
|
for (const binding of this.state.bindings(actorId))
|
|
413
|
-
if (binding.consumer
|
|
414
|
-
this.#notifyViews(actorId, binding.slot, true);
|
|
415
|
-
else if (this.state.declaration(actorId, "export", binding.export)?.dynamic === false)
|
|
200
|
+
if (binding.consumer !== actorId)
|
|
416
201
|
this.#notify(binding.consumer, binding.slot, true);
|
|
417
202
|
return conn;
|
|
418
203
|
}
|
|
@@ -421,28 +206,15 @@ export class Hub {
|
|
|
421
206
|
return;
|
|
422
207
|
this.#connections.delete(conn.actorId);
|
|
423
208
|
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
209
|
}
|
|
431
|
-
async #hello(stream, session,
|
|
210
|
+
async #hello(stream, session, admit) {
|
|
432
211
|
const reader = new FrameReader(stream.readable);
|
|
433
212
|
const writer = stream.writable.getWriter();
|
|
434
213
|
try {
|
|
435
214
|
const header = parseHeader(await reader.next());
|
|
436
215
|
if (header.op !== "hello")
|
|
437
216
|
throw new Refused("invalid", "A channel's first stream must be hello.");
|
|
438
|
-
if (
|
|
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 ||
|
|
217
|
+
if (header.credential === undefined ||
|
|
446
218
|
!this.state.authenticate(header.actorId, header.credential))
|
|
447
219
|
throw new Refused("forbidden", "No such Actor, or the credential is wrong.");
|
|
448
220
|
if (header.replace === false && this.#connections.has(header.actorId))
|
|
@@ -465,7 +237,7 @@ export class Hub {
|
|
|
465
237
|
session.close(GO_AWAY.protocolError);
|
|
466
238
|
}
|
|
467
239
|
}
|
|
468
|
-
/** Tell an Actor's channel
|
|
240
|
+
/** Tell an Actor's channel that one of its slots was bound or unbound. */
|
|
469
241
|
/** A slot made at run time, as its consumer is told of it: the export's interface, and whose it is. */
|
|
470
242
|
#exposure(binding) {
|
|
471
243
|
return {
|
|
@@ -474,7 +246,6 @@ export class Hub {
|
|
|
474
246
|
};
|
|
475
247
|
}
|
|
476
248
|
#notify(actorId, slot, bound) {
|
|
477
|
-
this.#notifyViews(actorId, slot, bound);
|
|
478
249
|
const conn = this.#connections.get(actorId);
|
|
479
250
|
if (!conn)
|
|
480
251
|
return;
|
|
@@ -545,6 +316,9 @@ export class Hub {
|
|
|
545
316
|
catch {
|
|
546
317
|
recomputed = undefined;
|
|
547
318
|
}
|
|
319
|
+
// Any other kind could only come from a program built against an older SDK.
|
|
320
|
+
if (iface.kind !== "rpc")
|
|
321
|
+
throw new Refused("invalid", `${iface.id} isn't an rpc interface.`);
|
|
548
322
|
// The hash keys the compiled schemas, so it is checked before anything is compiled.
|
|
549
323
|
if (recomputed !== hash)
|
|
550
324
|
throw new Refused("invalid", `${iface.id}'s hash doesn't match its schemas.`);
|
|
@@ -562,17 +336,6 @@ export class Hub {
|
|
|
562
336
|
return await this.#call(conn, header, reader, writer);
|
|
563
337
|
case "subscribe":
|
|
564
338
|
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
339
|
default:
|
|
577
340
|
throw new Refused("invalid", `A ${header.op} stream can't be opened here.`);
|
|
578
341
|
}
|
|
@@ -582,7 +345,7 @@ export class Hub {
|
|
|
582
345
|
drain(reader);
|
|
583
346
|
}
|
|
584
347
|
}
|
|
585
|
-
/** Keep an open subscription
|
|
348
|
+
/** Keep an open subscription under its binding, so the binding's end ends it. */
|
|
586
349
|
#track(binding, end) {
|
|
587
350
|
const key = bindingKey(binding);
|
|
588
351
|
const ends = this.#live.get(key) ?? new Set();
|
|
@@ -597,16 +360,14 @@ export class Hub {
|
|
|
597
360
|
// Every schema check runs in the turn of the Actor the work is for: a call's input and output in
|
|
598
361
|
// the caller's, a subscription's events in the subscriber's, a hello's or offer's compile in the
|
|
599
362
|
// 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
|
|
601
|
-
#resolve(caller, slot
|
|
363
|
+
/** A consumer's slot, resolved through its binding to a live provider. */
|
|
364
|
+
#resolve(caller, slot) {
|
|
602
365
|
const resolved = this.state.resolveCall(caller, slot);
|
|
603
366
|
if (!resolved)
|
|
604
367
|
throw new NotConnected(slot);
|
|
605
368
|
const { binding, target } = resolved;
|
|
606
|
-
|
|
607
|
-
|
|
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;
|
|
369
|
+
// The hub is served in this process; any other provider needs its channel.
|
|
370
|
+
const builtin = binding.provider === HUB;
|
|
610
371
|
const provider = builtin ? undefined : this.#connections.get(binding.provider);
|
|
611
372
|
if (!builtin && !provider)
|
|
612
373
|
throw new NotConnected(slot);
|
|
@@ -636,7 +397,7 @@ export class Hub {
|
|
|
636
397
|
drain(reader);
|
|
637
398
|
}
|
|
638
399
|
/**
|
|
639
|
-
* A call through a caller's slot
|
|
400
|
+
* A call through a caller's slot: resolve it, check the input, reach the
|
|
640
401
|
* provider, check the output, audit. `input` gives the value (and how the caller cancels) once
|
|
641
402
|
* the slot is known to have the method.
|
|
642
403
|
*/
|
|
@@ -645,7 +406,7 @@ export class Hub {
|
|
|
645
406
|
let reply;
|
|
646
407
|
let outcome = "ok";
|
|
647
408
|
try {
|
|
648
|
-
const resolved = this.#resolve(caller, slot
|
|
409
|
+
const resolved = this.#resolve(caller, slot);
|
|
649
410
|
binding = resolved.binding;
|
|
650
411
|
const { iface, provider } = resolved;
|
|
651
412
|
const part = { method, side: "input" };
|
|
@@ -673,38 +434,10 @@ export class Hub {
|
|
|
673
434
|
this.#audit(caller, slot, binding, { op: "call", method, outcome });
|
|
674
435
|
return encoded;
|
|
675
436
|
}
|
|
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. */
|
|
437
|
+
/** A call to the hub's own exports. */
|
|
700
438
|
async #builtinCall(binding, method, caller, value) {
|
|
701
439
|
try {
|
|
702
|
-
|
|
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));
|
|
440
|
+
return result(asJson(await this.#actor.call(binding.export, method, caller, value)));
|
|
708
441
|
}
|
|
709
442
|
catch (error) {
|
|
710
443
|
return errorBody(error);
|
|
@@ -748,7 +481,7 @@ export class Hub {
|
|
|
748
481
|
async #answerFrom(out, reader, binding, cancelled) {
|
|
749
482
|
let timer;
|
|
750
483
|
const late = new Promise((resolve) => {
|
|
751
|
-
timer = setTimeout(() => resolve("late"), this.#answerTimeoutMs);
|
|
484
|
+
timer = setTimeout(() => resolve("late"), this.#answerTimeoutsMs[binding.interface] ?? this.#answerTimeoutMs);
|
|
752
485
|
});
|
|
753
486
|
let first;
|
|
754
487
|
try {
|
|
@@ -806,7 +539,7 @@ export class Hub {
|
|
|
806
539
|
reader.next().then((more) => more !== undefined && stop(wireError("Refused", "A subscriber sends nothing.", "invalid")), () => stop());
|
|
807
540
|
}
|
|
808
541
|
/**
|
|
809
|
-
* Events of a caller's slot
|
|
542
|
+
* Events of a caller's slot: each checked, then handed to `sink` in order, the
|
|
810
543
|
* next waiting for the last to be taken, until the provider ends it, the binding goes, or the
|
|
811
544
|
* returned `stop` runs. A refusal at the start ends the sink at once and returns nothing.
|
|
812
545
|
*/
|
|
@@ -814,7 +547,7 @@ export class Hub {
|
|
|
814
547
|
let resolved;
|
|
815
548
|
const part = { event };
|
|
816
549
|
try {
|
|
817
|
-
resolved = this.#resolve(caller, slot
|
|
550
|
+
resolved = this.#resolve(caller, slot);
|
|
818
551
|
if (!this.#validators.has(resolved.iface, part))
|
|
819
552
|
throw new Refused("invalid", `${resolved.iface.id} has no event ${event}.`);
|
|
820
553
|
}
|
|
@@ -937,110 +670,4 @@ export class Hub {
|
|
|
937
670
|
})();
|
|
938
671
|
return end;
|
|
939
672
|
}
|
|
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
673
|
}
|