@capybara-hq/kernel 0.1.0-rc.67 → 0.1.0-rc.69
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/bootstrap.json +9 -1
- package/dist/admin/admin.module.js +2 -0
- package/dist/admin/health.service.d.ts +11 -4
- package/dist/admin/health.service.js +33 -17
- package/dist/background/poll.job.js +2 -2
- package/dist/background/tasks.service.d.ts +5 -5
- package/dist/background/tasks.service.js +9 -8
- package/dist/catalog/credential-key.d.ts +10 -0
- package/dist/catalog/credential-key.js +28 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-upgrade.js +1 -19
- package/dist/catalog/requests.service.js +1 -1
- package/dist/config/schema.d.ts +1 -1
- package/dist/config/schema.js +9 -9
- package/dist/conversations/conversations.controller.d.ts +8 -3
- package/dist/conversations/conversations.controller.js +8 -3
- package/dist/conversations/conversations.service.d.ts +33 -15
- package/dist/conversations/conversations.service.js +60 -10
- package/dist/conversations/events.d.ts +21 -41
- package/dist/conversations/events.js +57 -31
- package/dist/conversations/permission-profiles.controller.d.ts +6 -4
- package/dist/conversations/permission-profiles.service.d.ts +6 -4
- package/dist/ctx/create-ctx.d.ts +20 -1
- package/dist/ctx/create-ctx.js +77 -6
- package/dist/ctx/device-provider-check.d.ts +6 -2
- package/dist/ctx/device-provider-check.js +17 -2
- package/dist/db/kernel-schema.d.ts +10 -48
- package/dist/devices/access.d.ts +3 -4
- package/dist/devices/access.js +3 -4
- package/dist/devices/conversation-devices.d.ts +1 -3
- package/dist/devices/conversation-devices.js +2 -7
- package/dist/devices/device-projects.service.js +24 -29
- package/dist/devices/device-provider-selection.d.ts +5 -6
- package/dist/devices/device-provider-selection.js +8 -9
- package/dist/devices/devices.controller.d.ts +8 -21
- package/dist/devices/devices.controller.js +9 -34
- package/dist/devices/devices.module.js +6 -4
- package/dist/devices/devices.schemas.d.ts +1 -5
- package/dist/devices/devices.schemas.js +1 -5
- package/dist/devices/devices.service.d.ts +84 -147
- package/dist/devices/devices.service.js +134 -229
- package/dist/devices/dto.d.ts +5 -32
- package/dist/devices/dto.js +5 -37
- package/dist/devices/errors.d.ts +6 -5
- package/dist/devices/errors.js +7 -8
- package/dist/devices/project-rules.d.ts +9 -11
- package/dist/devices/project-rules.js +7 -7
- package/dist/devices/working-root.d.ts +3 -6
- package/dist/devices/working-root.js +3 -8
- package/dist/dial-in/access.d.ts +23 -0
- package/dist/dial-in/access.js +64 -0
- package/dist/{local-devices/device-auth.controller.d.ts → dial-in/auth.controller.d.ts} +12 -6
- package/dist/{local-devices/device-auth.controller.js → dial-in/auth.controller.js} +30 -15
- package/dist/dial-in/auth.module.d.ts +7 -0
- package/dist/dial-in/auth.module.js +27 -0
- package/dist/{local-devices/device-auth.d.ts → dial-in/auth.service.d.ts} +42 -13
- package/dist/{local-devices/device-auth.js → dial-in/auth.service.js} +83 -32
- package/dist/dial-in/dial-in.module.d.ts +9 -0
- package/dist/dial-in/dial-in.module.js +37 -0
- package/dist/{local-devices → dial-in}/dto.d.ts +17 -2
- package/dist/{local-devices → dial-in}/dto.js +14 -2
- package/dist/dial-in/envelope.d.ts +95 -0
- package/dist/dial-in/envelope.js +89 -0
- package/dist/dial-in/gateway.d.ts +214 -0
- package/dist/{local-devices/local-device-gateway.js → dial-in/gateway.js} +337 -181
- package/dist/dial-in/handlers.d.ts +47 -0
- package/dist/dial-in/handlers.js +84 -0
- package/dist/dial-in/machines.d.ts +155 -0
- package/dist/dial-in/machines.js +383 -0
- package/dist/dial-in/relay.d.ts +135 -0
- package/dist/dial-in/relay.js +444 -0
- package/dist/dial-in/relay.module.d.ts +7 -0
- package/dist/dial-in/relay.module.js +24 -0
- package/dist/{local-devices/device-routes.d.ts → dial-in/routes.d.ts} +19 -11
- package/dist/{local-devices/device-routes.js → dial-in/routes.js} +45 -25
- package/dist/{local-devices → dial-in}/targets.d.ts +3 -18
- package/dist/{local-devices → dial-in}/targets.js +3 -48
- package/dist/errors.d.ts +8 -27
- package/dist/errors.js +8 -27
- package/dist/extensions/bootstrap.d.ts +5 -0
- package/dist/extensions/bootstrap.js +10 -1
- package/dist/extensions/extensions.module.js +6 -0
- package/dist/extensions/host.d.ts +6 -0
- package/dist/extensions/host.js +12 -2
- package/dist/extensions/permission-set.d.ts +15 -1
- package/dist/extensions/permission-set.js +11 -1
- package/dist/extensions/permission-view.d.ts +1 -1
- package/dist/extensions/permission-view.js +4 -1
- package/dist/http/api.module.js +4 -4
- package/dist/http/gateway-routes.d.ts +1 -1
- package/dist/http/gateway-routes.js +1 -1
- package/dist/http/meta.controller.js +1 -1
- package/dist/identity/settings.d.ts +1 -1
- package/dist/identity/settings.js +6 -8
- package/dist/infra/config/kernel-config.service.js +2 -2
- package/dist/infra/outbox/registry.d.ts +0 -14
- package/dist/infra/outbox/registry.js +0 -15
- package/dist/infra/throttler/named-throttlers.d.ts +1 -1
- package/dist/infra/throttler/named-throttlers.js +1 -1
- package/dist/kernel.module.js +0 -3
- package/dist/orgs/settings.service.js +5 -10
- package/dist/overrides.d.ts +0 -4
- package/dist/overrides.js +0 -2
- package/dist/platform/exclusions.js +5 -5
- package/dist/platform/ops/admin.ops.js +1 -1
- package/dist/platform/ops/conversations.ops.js +5 -2
- package/dist/platform/ops/devices.ops.js +11 -24
- package/dist/platform/ops/inbox.ops.js +1 -1
- package/dist/roles/gateway-role.d.ts +3 -3
- package/dist/roles/gateway-role.js +4 -4
- package/dist/roles/gateway.module.d.ts +1 -1
- package/dist/roles/gateway.module.js +5 -5
- package/dist/runtime/context/device-paths.d.ts +4 -1
- package/dist/runtime/context/permission-profile.js +5 -5
- package/dist/runtime/maintenance.d.ts +2 -5
- package/dist/runtime/maintenance.js +9 -19
- package/dist/runtime/project/knowledge.js +4 -5
- package/dist/runtime/project/knowledge.service.js +2 -1
- package/dist/sandbox/cloud-permission-snapshot.d.ts +1 -1
- package/dist/sandbox/cloud-permission-snapshot.js +1 -3
- package/dist/sandbox/device-reports.d.ts +74 -14
- package/dist/sandbox/device-reports.js +190 -33
- package/dist/sandbox/device-reports.module.d.ts +7 -0
- package/dist/sandbox/device-reports.module.js +25 -0
- package/dist/sandbox/device-sandbox.d.ts +39 -41
- package/dist/sandbox/device-sandbox.js +44 -83
- package/dist/sandbox/kernel-read.d.ts +2 -2
- package/dist/sandbox/legacy-retirement.d.ts +11 -59
- package/dist/sandbox/legacy-retirement.js +34 -186
- package/dist/sandbox/legacy-retirement.module.d.ts +2 -2
- package/dist/sandbox/legacy-retirement.module.js +2 -2
- package/dist/sandbox/managed-device-context.d.ts +16 -4
- package/dist/sandbox/managed-device-context.js +25 -8
- package/dist/sandbox/managed-device-context.module.js +4 -0
- package/dist/sandbox/modes.d.ts +3 -12
- package/dist/sandbox/modes.js +2 -14
- package/dist/{local-devices → sandbox}/network-grants.d.ts +2 -21
- package/dist/{local-devices → sandbox}/network-grants.js +4 -49
- package/dist/sandbox/operation-authority-types.d.ts +2 -1
- package/dist/sandbox/operation-authority.d.ts +6 -20
- package/dist/sandbox/operation-authority.js +43 -104
- package/dist/sandbox/operation-authority.module.js +1 -1
- package/dist/sandbox/operation-intents.d.ts +4 -1
- package/dist/sandbox/operation-intents.js +11 -2
- package/dist/sandbox/operation-reconcile.job.js +2 -4
- package/dist/sandbox/permission-availability.d.ts +6 -7
- package/dist/sandbox/permission-availability.js +7 -10
- package/dist/sandbox/permission-call-grants.d.ts +2 -1
- package/dist/sandbox/permission-call-grants.js +1 -7
- package/dist/sandbox/permission-call-types.d.ts +4 -4
- package/dist/sandbox/permission-ceiling-writes.d.ts +7 -23
- package/dist/sandbox/permission-ceiling-writes.js +8 -35
- package/dist/sandbox/permission-config-publication.d.ts +9 -1
- package/dist/sandbox/permission-config-publication.js +29 -21
- package/dist/sandbox/permission-context-types.d.ts +17 -10
- package/dist/sandbox/permission-facts.d.ts +98 -95
- package/dist/sandbox/permission-facts.js +160 -314
- package/dist/sandbox/permission-instance-writes.d.ts +23 -37
- package/dist/sandbox/permission-instance-writes.js +44 -121
- package/dist/sandbox/permission-runtime-reports.d.ts +38 -30
- package/dist/sandbox/permission-runtime-reports.js +105 -122
- package/dist/sandbox/providers.d.ts +26 -38
- package/dist/sandbox/providers.js +36 -18
- package/dist/sandbox/request-not-sent.d.ts +2 -13
- package/dist/sandbox/request-not-sent.js +2 -13
- package/dist/sandbox/review/permission-candidate.d.ts +13 -8
- package/dist/sandbox/review/permission-candidate.js +38 -48
- package/dist/sandbox/sandbox.module.js +7 -3
- package/dist/sandbox/sandbox.service.d.ts +49 -59
- package/dist/sandbox/sandbox.service.js +139 -259
- package/dist/schedules/fire.d.ts +15 -6
- package/dist/schedules/fire.js +27 -13
- package/dist/schedules/grant-rules.js +1 -1
- package/dist/schedules/scheduled-tasks.service.d.ts +0 -7
- package/dist/schedules/scheduled-tasks.service.js +1 -4
- package/dist/schedules/schedules.module.js +5 -3
- package/dist/skills/invoke.d.ts +1 -1
- package/dist/skills/invoke.js +2 -3
- package/dist/tools/approvals.service.d.ts +8 -5
- package/dist/tools/approvals.service.js +5 -5
- package/dist/tools/builtins/sandbox/bash.js +1 -2
- package/dist/tools/builtins/sandbox/common.d.ts +15 -9
- package/dist/tools/builtins/sandbox/common.js +37 -38
- package/dist/tools/connectors.controller.d.ts +2 -0
- package/dist/tools/connectors.schemas.d.ts +2 -0
- package/dist/tools/credentials.d.ts +2 -0
- package/dist/tools/network-asks.d.ts +19 -22
- package/dist/tools/network-asks.js +15 -21
- package/dist/tools/oauth/authorization-params.d.ts +7 -0
- package/dist/tools/oauth/authorization-params.js +19 -0
- package/dist/tools/oauth/flow.js +7 -0
- package/dist/tools/oauth/tokens.js +2 -1
- package/dist/tools/pipeline.d.ts +6 -7
- package/dist/tools/pipeline.js +17 -21
- package/dist/tools/tools.module.js +3 -7
- package/package.json +3 -4
- package/src/migrations/0177_dial_in_contract.sql +32 -0
- package/dist/local-devices/device-auth.module.d.ts +0 -7
- package/dist/local-devices/device-auth.module.js +0 -25
- package/dist/local-devices/device-policy.service.d.ts +0 -213
- package/dist/local-devices/device-policy.service.js +0 -605
- package/dist/local-devices/instance-bindings.d.ts +0 -82
- package/dist/local-devices/instance-bindings.js +0 -307
- package/dist/local-devices/local-device-gateway.d.ts +0 -153
- package/dist/local-devices/local-device-provider.d.ts +0 -122
- package/dist/local-devices/local-device-provider.js +0 -326
- package/dist/local-devices/local-devices.module.d.ts +0 -31
- package/dist/local-devices/local-devices.module.js +0 -100
- package/dist/local-devices/machines.d.ts +0 -211
- package/dist/local-devices/machines.js +0 -766
- package/dist/local-devices/owner-report.d.ts +0 -81
- package/dist/local-devices/owner-report.js +0 -150
- package/dist/local-devices/owner-reports.d.ts +0 -48
- package/dist/local-devices/owner-reports.js +0 -208
- package/dist/local-devices/policy-op-jobs.d.ts +0 -15
- package/dist/local-devices/policy-op-jobs.js +0 -12
- package/dist/local-devices/policy-summary.d.ts +0 -102
- package/dist/local-devices/policy-summary.js +0 -155
- package/dist/local-devices/relay.d.ts +0 -166
- package/dist/local-devices/relay.js +0 -559
- package/dist/tools/device-op-resolver.d.ts +0 -34
- package/dist/tools/device-op-resolver.js +0 -120
- /package/dist/{local-devices → dial-in}/keys.d.ts +0 -0
- /package/dist/{local-devices → dial-in}/keys.js +0 -0
- /package/dist/{local-devices → sandbox}/network-grants.module.d.ts +0 -0
- /package/dist/{local-devices → sandbox}/network-grants.module.js +0 -0
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import type { LocalizedName } from "@capybara-hq/plugin-sdk";
|
|
1
2
|
import type { Redis } from "ioredis";
|
|
2
3
|
import { DevicesService } from "../devices/devices.service.js";
|
|
4
|
+
import { ExtensionDisplayNames } from "../extensions/display-name.js";
|
|
3
5
|
import type { UserPrincipal } from "../identity/principal.js";
|
|
4
6
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
5
7
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
6
8
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
7
9
|
import type { KernelLogger } from "../log.js";
|
|
8
|
-
import {
|
|
10
|
+
import { DialInHandlers } from "./handlers.js";
|
|
11
|
+
import { DialInMachines } from "./machines.js";
|
|
9
12
|
/** The 20 consonants a user code is made of (no vowels: no words; no look-alike letters). */
|
|
10
13
|
export declare const USER_CODE_ALPHABET = "BCDFGHJKLMNPQRSTVWXZ";
|
|
11
14
|
/** What `slow_down` adds to the poll interval (RFC 8628 §3.5). */
|
|
@@ -24,6 +27,17 @@ export interface DeviceMachineInfo {
|
|
|
24
27
|
os: "darwin" | "linux";
|
|
25
28
|
arch: string;
|
|
26
29
|
programVersion: string;
|
|
30
|
+
/** The dial-in protocol the program speaks: only providers declaring it may take the machine. */
|
|
31
|
+
protocol: string;
|
|
32
|
+
}
|
|
33
|
+
/** A dial-in provider a pending code may choose, with the person's devices of it. */
|
|
34
|
+
export interface DialInProviderChoice {
|
|
35
|
+
plugin: string;
|
|
36
|
+
displayName: LocalizedName;
|
|
37
|
+
devices: {
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
}[];
|
|
27
41
|
}
|
|
28
42
|
interface Grant {
|
|
29
43
|
credential: string;
|
|
@@ -41,7 +55,7 @@ export interface DeviceAuthorization {
|
|
|
41
55
|
export interface DeviceGrant extends Grant {
|
|
42
56
|
connectUrl: string;
|
|
43
57
|
reconnectGraceSeconds: number;
|
|
44
|
-
/** `devices.
|
|
58
|
+
/** `devices.dialIn.maxFrameBytes`: the program never sends a larger frame (ruling R26). */
|
|
45
59
|
maxFrameBytes: number;
|
|
46
60
|
/**
|
|
47
61
|
* Whether the platform and the organization allow running outside the sandbox now
|
|
@@ -57,19 +71,21 @@ export declare function normalizeUserCode(input: string): string | null;
|
|
|
57
71
|
* for a code pair (`authorize`), the signed-in person confirms the user code on the web page
|
|
58
72
|
* `/device` (`pending`, `confirm` or `deny`), and the program polls `token` until it gets the
|
|
59
73
|
* machine credential, once. State lives only in Redis, both keys with the code's TTL
|
|
60
|
-
* (`devices.
|
|
74
|
+
* (`devices.dialIn.authCodeTtlSeconds`): `capk:device-auth:<sha256(deviceCode)>` (a hash:
|
|
61
75
|
* `info` JSON, `status`, `interval`, `lastPollAt`, the parked `grant`) and
|
|
62
76
|
* `capk:device-user:<userCode>` → the device code's hash. The device code itself is never stored.
|
|
63
77
|
*/
|
|
64
|
-
export declare class
|
|
78
|
+
export declare class DialInAuthService {
|
|
65
79
|
private readonly db;
|
|
66
80
|
readonly txHost: TransactionHost;
|
|
67
81
|
private readonly redis;
|
|
68
82
|
private readonly config;
|
|
69
83
|
private readonly devices;
|
|
84
|
+
private readonly dialIn;
|
|
85
|
+
private readonly displayNames;
|
|
70
86
|
private readonly machines;
|
|
71
87
|
private readonly log;
|
|
72
|
-
constructor(db: KernelDb, txHost: TransactionHost, redis: Redis, config: Pick<KernelConfigService, "get" | "fieldSource">, devices: Pick<DevicesService, "
|
|
88
|
+
constructor(db: KernelDb, txHost: TransactionHost, redis: Redis, config: Pick<KernelConfigService, "get" | "fieldSource">, devices: Pick<DevicesService, "createDialIn">, dialIn: Pick<DialInHandlers, "onInOrg">, displayNames: Pick<ExtensionDisplayNames, "many">, machines: Pick<DialInMachines, "issue" | "revokeMachine">, log: Pick<KernelLogger, "warn">);
|
|
73
89
|
/** A new code pair for a machine. Needs `http.publicUrl` (the page and the connection URL). */
|
|
74
90
|
authorize(machine: DeviceMachineInfo): Promise<DeviceAuthorization>;
|
|
75
91
|
/**
|
|
@@ -84,18 +100,31 @@ export declare class DeviceAuthService {
|
|
|
84
100
|
expiresAt: string;
|
|
85
101
|
}>;
|
|
86
102
|
/**
|
|
87
|
-
* The
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
103
|
+
* The dial-in providers a pending code may choose in `orgId` (the person may use agents there,
|
|
104
|
+
* `agents.use`): the ones on in the org whose protocol is the program's
|
|
105
|
+
* ({@link DialInHandlers.onInOrg}), each with the person's own live devices of it there.
|
|
106
|
+
*/
|
|
107
|
+
providers(principal: UserPrincipal, input: {
|
|
108
|
+
orgId: string;
|
|
109
|
+
userCode: string;
|
|
110
|
+
}): Promise<{
|
|
111
|
+
providers: DialInProviderChoice[];
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* The person confirms a user code: in an org where they may use agents (`agents.use`), with a
|
|
115
|
+
* dial-in provider on in that org that speaks the program's protocol (else
|
|
116
|
+
* `device.provider_unavailable`), into one of their own live devices of that provider there or
|
|
117
|
+
* a new one named `name` (` 2`, ` 3`, … appended while the name is taken). One transaction
|
|
118
|
+
* creates the device if needed, issues the machine (revoking the device's previous one) and
|
|
119
|
+
* audits `device.machine_connected` with the provider (retried once when a concurrent
|
|
120
|
+
* confirmation took the new name); after the commit the credential is parked for the poll
|
|
121
|
+
* ({@link park}). The code is claimed first, so two confirmations of one code cannot both issue
|
|
122
|
+
* a machine; a confirmation that fails before the commit leaves it pending.
|
|
95
123
|
*/
|
|
96
124
|
confirm(principal: UserPrincipal, input: {
|
|
97
125
|
userCode: string;
|
|
98
126
|
orgId: string;
|
|
127
|
+
provider: string;
|
|
99
128
|
deviceId?: string | undefined;
|
|
100
129
|
name?: string | undefined;
|
|
101
130
|
}): Promise<{
|
|
@@ -9,8 +9,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
9
9
|
};
|
|
10
10
|
import { randomBytes } from "node:crypto";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
|
-
import { DevicesService } from "../devices/devices.service.js";
|
|
12
|
+
import { DevicesService, dialInProviderUnavailable } from "../devices/devices.service.js";
|
|
13
13
|
import { ApiError } from "../errors.js";
|
|
14
|
+
import { ExtensionDisplayNames } from "../extensions/display-name.js";
|
|
14
15
|
import { audit } from "../identity/audit.js";
|
|
15
16
|
import { sha256Hex } from "../identity/hash.js";
|
|
16
17
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
@@ -21,9 +22,9 @@ import { KERNEL_LOGGER, REDIS } from "../infra/tokens.js";
|
|
|
21
22
|
import { authorizeOrgAction } from "../orgs/org.guard.js";
|
|
22
23
|
import { readOrgSettings } from "../orgs/settings.service.js";
|
|
23
24
|
import { allowedDeviceMode, readDeploymentDevicePolicy } from "../sandbox/modes.js";
|
|
24
|
-
import { LOCAL_PROVIDER } from "../sandbox/providers.js";
|
|
25
25
|
import { deviceNotFound } from "../sandbox/sandbox.service.js";
|
|
26
|
-
import {
|
|
26
|
+
import { DialInHandlers } from "./handlers.js";
|
|
27
|
+
import { DialInMachines } from "./machines.js";
|
|
27
28
|
/** The 20 consonants a user code is made of (no vowels: no words; no look-alike letters). */
|
|
28
29
|
export const USER_CODE_ALPHABET = "BCDFGHJKLMNPQRSTVWXZ";
|
|
29
30
|
const USER_CODE_LENGTH = 8;
|
|
@@ -109,31 +110,35 @@ function newUserCode() {
|
|
|
109
110
|
* for a code pair (`authorize`), the signed-in person confirms the user code on the web page
|
|
110
111
|
* `/device` (`pending`, `confirm` or `deny`), and the program polls `token` until it gets the
|
|
111
112
|
* machine credential, once. State lives only in Redis, both keys with the code's TTL
|
|
112
|
-
* (`devices.
|
|
113
|
+
* (`devices.dialIn.authCodeTtlSeconds`): `capk:device-auth:<sha256(deviceCode)>` (a hash:
|
|
113
114
|
* `info` JSON, `status`, `interval`, `lastPollAt`, the parked `grant`) and
|
|
114
115
|
* `capk:device-user:<userCode>` → the device code's hash. The device code itself is never stored.
|
|
115
116
|
*/
|
|
116
|
-
let
|
|
117
|
+
let DialInAuthService = class DialInAuthService {
|
|
117
118
|
db;
|
|
118
119
|
txHost;
|
|
119
120
|
redis;
|
|
120
121
|
config;
|
|
121
122
|
devices;
|
|
123
|
+
dialIn;
|
|
124
|
+
displayNames;
|
|
122
125
|
machines;
|
|
123
126
|
log;
|
|
124
|
-
constructor(db, txHost, redis, config, devices, machines, log) {
|
|
127
|
+
constructor(db, txHost, redis, config, devices, dialIn, displayNames, machines, log) {
|
|
125
128
|
this.db = db;
|
|
126
129
|
this.txHost = txHost;
|
|
127
130
|
this.redis = redis;
|
|
128
131
|
this.config = config;
|
|
129
132
|
this.devices = devices;
|
|
133
|
+
this.dialIn = dialIn;
|
|
134
|
+
this.displayNames = displayNames;
|
|
130
135
|
this.machines = machines;
|
|
131
136
|
this.log = log;
|
|
132
137
|
}
|
|
133
138
|
/** A new code pair for a machine. Needs `http.publicUrl` (the page and the connection URL). */
|
|
134
139
|
async authorize(machine) {
|
|
135
140
|
const web = this.publicUrl();
|
|
136
|
-
const { authCodeTtlSeconds: ttl, pollIntervalSeconds: interval } = this.config.get().devices.
|
|
141
|
+
const { authCodeTtlSeconds: ttl, pollIntervalSeconds: interval } = this.config.get().devices.dialIn;
|
|
137
142
|
const deviceCode = DEVICE_CODE_PREFIX + randomBytes(32).toString("base64url");
|
|
138
143
|
const hash = sha256Hex(deviceCode);
|
|
139
144
|
for (let attempt = 0;; attempt++) {
|
|
@@ -182,7 +187,7 @@ let DeviceAuthService = class DeviceAuthService {
|
|
|
182
187
|
switch (r[0]) {
|
|
183
188
|
case "approved": {
|
|
184
189
|
const grant = JSON.parse(r[1]);
|
|
185
|
-
const
|
|
190
|
+
const dialIn = this.config.get().devices.dialIn;
|
|
186
191
|
const [deployment, settings] = await Promise.all([
|
|
187
192
|
readDeploymentDevicePolicy(this.db.db, this.config),
|
|
188
193
|
readOrgSettings(this.db.db, grant.orgId),
|
|
@@ -190,8 +195,8 @@ let DeviceAuthService = class DeviceAuthService {
|
|
|
190
195
|
return {
|
|
191
196
|
...grant,
|
|
192
197
|
connectUrl,
|
|
193
|
-
reconnectGraceSeconds:
|
|
194
|
-
maxFrameBytes:
|
|
198
|
+
reconnectGraceSeconds: dialIn.reconnectGraceSeconds,
|
|
199
|
+
maxFrameBytes: dialIn.maxFrameBytes,
|
|
195
200
|
outsideSandbox: allowedDeviceMode(deployment.fullAccess, settings.outsideSandbox) === "auto"
|
|
196
201
|
? "allowed"
|
|
197
202
|
: "off",
|
|
@@ -214,14 +219,51 @@ let DeviceAuthService = class DeviceAuthService {
|
|
|
214
219
|
return { machine: info.machine, expiresAt: info.expiresAt };
|
|
215
220
|
}
|
|
216
221
|
/**
|
|
217
|
-
* The
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
222
|
+
* The dial-in providers a pending code may choose in `orgId` (the person may use agents there,
|
|
223
|
+
* `agents.use`): the ones on in the org whose protocol is the program's
|
|
224
|
+
* ({@link DialInHandlers.onInOrg}), each with the person's own live devices of it there.
|
|
225
|
+
*/
|
|
226
|
+
async providers(principal, input) {
|
|
227
|
+
await authorizeOrgAction(this.db.db, principal, input.orgId, "agents.use");
|
|
228
|
+
const { info } = await this.lookup(input.userCode, "pending");
|
|
229
|
+
const served = (await this.dialIn.onInOrg(input.orgId)).filter((p) => p.protocol === info.machine.protocol);
|
|
230
|
+
if (served.length === 0)
|
|
231
|
+
return { providers: [] };
|
|
232
|
+
const plugins = served.map((p) => p.plugin);
|
|
233
|
+
const [names, rows] = await Promise.all([
|
|
234
|
+
this.displayNames.many(plugins),
|
|
235
|
+
this.db
|
|
236
|
+
.selectFrom("devices")
|
|
237
|
+
.select(["id", "name", "provider"])
|
|
238
|
+
.where("org_id", "=", input.orgId)
|
|
239
|
+
.where("owner_kind", "=", "personal")
|
|
240
|
+
.where("owner_account_id", "=", principal.account.id)
|
|
241
|
+
.where("provider", "in", plugins)
|
|
242
|
+
.where("deleted_at", "is", null)
|
|
243
|
+
.orderBy("created_at")
|
|
244
|
+
.orderBy("id")
|
|
245
|
+
.execute(),
|
|
246
|
+
]);
|
|
247
|
+
return {
|
|
248
|
+
providers: plugins.map((plugin) => ({
|
|
249
|
+
plugin,
|
|
250
|
+
displayName: names.get(plugin) ?? { en: plugin, zh: plugin },
|
|
251
|
+
devices: rows
|
|
252
|
+
.filter((r) => r.provider === plugin)
|
|
253
|
+
.map((r) => ({ id: r.id, name: r.name ?? "" })),
|
|
254
|
+
})),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* The person confirms a user code: in an org where they may use agents (`agents.use`), with a
|
|
259
|
+
* dial-in provider on in that org that speaks the program's protocol (else
|
|
260
|
+
* `device.provider_unavailable`), into one of their own live devices of that provider there or
|
|
261
|
+
* a new one named `name` (` 2`, ` 3`, … appended while the name is taken). One transaction
|
|
262
|
+
* creates the device if needed, issues the machine (revoking the device's previous one) and
|
|
263
|
+
* audits `device.machine_connected` with the provider (retried once when a concurrent
|
|
264
|
+
* confirmation took the new name); after the commit the credential is parked for the poll
|
|
265
|
+
* ({@link park}). The code is claimed first, so two confirmations of one code cannot both issue
|
|
266
|
+
* a machine; a confirmation that fails before the commit leaves it pending.
|
|
225
267
|
*/
|
|
226
268
|
async confirm(principal, input) {
|
|
227
269
|
await authorizeOrgAction(this.db.db, principal, input.orgId, "agents.use");
|
|
@@ -299,11 +341,17 @@ let DeviceAuthService = class DeviceAuthService {
|
|
|
299
341
|
await this.redis.del(deviceUserKey(info.userCode));
|
|
300
342
|
}
|
|
301
343
|
async confirmIn(accountId, input, info) {
|
|
302
|
-
const { orgId } = input;
|
|
344
|
+
const { orgId, provider } = input;
|
|
345
|
+
const { machine } = info;
|
|
346
|
+
// the provider takes machines in this org and speaks this program's protocol
|
|
347
|
+
const served = (await this.dialIn.onInOrg(orgId)).find((p) => p.plugin === provider);
|
|
348
|
+
if (served === undefined || served.protocol !== machine.protocol) {
|
|
349
|
+
throw dialInProviderUnavailable(provider);
|
|
350
|
+
}
|
|
303
351
|
let deviceId;
|
|
304
352
|
if (input.name !== undefined) {
|
|
305
353
|
const name = await this.freeName(orgId, accountId, input.name);
|
|
306
|
-
deviceId = (await this.devices.
|
|
354
|
+
deviceId = (await this.devices.createDialIn(orgId, accountId, provider, name)).id;
|
|
307
355
|
}
|
|
308
356
|
else {
|
|
309
357
|
const env = await this.db
|
|
@@ -313,8 +361,7 @@ let DeviceAuthService = class DeviceAuthService {
|
|
|
313
361
|
.where("org_id", "=", orgId)
|
|
314
362
|
.where("owner_kind", "=", "personal")
|
|
315
363
|
.where("owner_account_id", "=", accountId)
|
|
316
|
-
.where("
|
|
317
|
-
.where("provider", "=", LOCAL_PROVIDER)
|
|
364
|
+
.where("provider", "=", provider)
|
|
318
365
|
.where("deleted_at", "is", null)
|
|
319
366
|
.forNoKeyUpdate()
|
|
320
367
|
.executeTakeFirst();
|
|
@@ -322,19 +369,21 @@ let DeviceAuthService = class DeviceAuthService {
|
|
|
322
369
|
throw deviceNotFound();
|
|
323
370
|
deviceId = env.id;
|
|
324
371
|
}
|
|
325
|
-
const { machine } = info;
|
|
326
372
|
const { machineId, credential } = await this.machines.issue({
|
|
327
373
|
orgId,
|
|
328
374
|
deviceId,
|
|
329
375
|
accountId,
|
|
330
|
-
|
|
376
|
+
name: machine.name,
|
|
377
|
+
os: machine.os,
|
|
378
|
+
arch: machine.arch,
|
|
379
|
+
programVersion: machine.programVersion,
|
|
331
380
|
});
|
|
332
381
|
await audit(this.db.db, {
|
|
333
382
|
actorAccountId: accountId,
|
|
334
383
|
orgId,
|
|
335
384
|
action: "device.machine_connected",
|
|
336
385
|
target: deviceId,
|
|
337
|
-
detail: { machineId, ...machine },
|
|
386
|
+
detail: { machineId, provider, ...machine },
|
|
338
387
|
});
|
|
339
388
|
return {
|
|
340
389
|
deviceId,
|
|
@@ -392,19 +441,21 @@ let DeviceAuthService = class DeviceAuthService {
|
|
|
392
441
|
};
|
|
393
442
|
__decorate([
|
|
394
443
|
Transactional()
|
|
395
|
-
],
|
|
444
|
+
], DialInAuthService.prototype, "abandon", null);
|
|
396
445
|
__decorate([
|
|
397
446
|
Transactional()
|
|
398
|
-
],
|
|
399
|
-
|
|
447
|
+
], DialInAuthService.prototype, "confirmIn", null);
|
|
448
|
+
DialInAuthService = __decorate([
|
|
400
449
|
Injectable(),
|
|
401
450
|
__param(0, Inject(KernelDb)),
|
|
402
451
|
__param(1, Inject(TransactionHost)),
|
|
403
452
|
__param(2, Inject(REDIS)),
|
|
404
453
|
__param(3, Inject(KernelConfigService)),
|
|
405
454
|
__param(4, Inject(DevicesService)),
|
|
406
|
-
__param(5, Inject(
|
|
407
|
-
__param(6, Inject(
|
|
408
|
-
|
|
409
|
-
|
|
455
|
+
__param(5, Inject(DialInHandlers)),
|
|
456
|
+
__param(6, Inject(ExtensionDisplayNames)),
|
|
457
|
+
__param(7, Inject(DialInMachines)),
|
|
458
|
+
__param(8, Inject(KERNEL_LOGGER))
|
|
459
|
+
], DialInAuthService);
|
|
460
|
+
export { DialInAuthService };
|
|
410
461
|
const expired = () => new ApiError("device_sign_in.expired", "This sign-in code has expired or was already used; run capybara-device login again");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dial-in side of signed-in machines (device provider spec §5): the caller side of the
|
|
3
|
+
* relay ({@link DialInRelayModule}), the machines and their credentials ({@link DialInMachines})
|
|
4
|
+
* and the providers' dial-in handlers ({@link DialInHandlers}). Imported on every role: any
|
|
5
|
+
* replica may run an operation on a device (the socket itself is held by the gateway role,
|
|
6
|
+
* `DialInGateway`).
|
|
7
|
+
*/
|
|
8
|
+
export declare class DialInModule {
|
|
9
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Module } from "@nestjs/common";
|
|
8
|
+
import { DeviceProviderSelectionModule } from "../devices/device-provider-selection.module.js";
|
|
9
|
+
import { ExtensionRegistryModule } from "../extensions/registry.js";
|
|
10
|
+
import { SandboxProviderRegistryModule } from "../sandbox/providers.module.js";
|
|
11
|
+
import { SandboxModule } from "../sandbox/sandbox.module.js";
|
|
12
|
+
import { DialInHandlers } from "./handlers.js";
|
|
13
|
+
import { DialInMachines } from "./machines.js";
|
|
14
|
+
import { DialInRelayModule } from "./relay.module.js";
|
|
15
|
+
/**
|
|
16
|
+
* The dial-in side of signed-in machines (device provider spec §5): the caller side of the
|
|
17
|
+
* relay ({@link DialInRelayModule}), the machines and their credentials ({@link DialInMachines})
|
|
18
|
+
* and the providers' dial-in handlers ({@link DialInHandlers}). Imported on every role: any
|
|
19
|
+
* replica may run an operation on a device (the socket itself is held by the gateway role,
|
|
20
|
+
* `DialInGateway`).
|
|
21
|
+
*/
|
|
22
|
+
let DialInModule = class DialInModule {
|
|
23
|
+
};
|
|
24
|
+
DialInModule = __decorate([
|
|
25
|
+
Module({
|
|
26
|
+
imports: [
|
|
27
|
+
DialInRelayModule,
|
|
28
|
+
DeviceProviderSelectionModule,
|
|
29
|
+
ExtensionRegistryModule,
|
|
30
|
+
SandboxModule,
|
|
31
|
+
SandboxProviderRegistryModule,
|
|
32
|
+
],
|
|
33
|
+
providers: [DialInMachines, DialInHandlers],
|
|
34
|
+
exports: [DialInRelayModule, DialInMachines, DialInHandlers],
|
|
35
|
+
})
|
|
36
|
+
], DialInModule);
|
|
37
|
+
export { DialInModule };
|
|
@@ -8,6 +8,7 @@ export declare const DeviceAuthorizeBody: z.ZodObject<{
|
|
|
8
8
|
}>;
|
|
9
9
|
arch: z.ZodString;
|
|
10
10
|
programVersion: z.ZodString;
|
|
11
|
+
protocol: z.ZodString;
|
|
11
12
|
}, z.core.$strict>;
|
|
12
13
|
/** `POST /api/v1/device/token`: the secret device code from `authorize`. */
|
|
13
14
|
export declare const DeviceTokenBody: z.ZodObject<{
|
|
@@ -19,13 +20,19 @@ export declare const DeviceUserCodeParams: z.ZodObject<{
|
|
|
19
20
|
export declare const DeviceUserCodeBody: z.ZodObject<{
|
|
20
21
|
userCode: z.ZodString;
|
|
21
22
|
}, z.core.$strict>;
|
|
23
|
+
/** `GET /api/v1/device/providers`: the dial-in providers a pending code may choose in an org. */
|
|
24
|
+
export declare const DeviceProvidersQuery: z.ZodObject<{
|
|
25
|
+
orgId: z.ZodString;
|
|
26
|
+
userCode: z.ZodString;
|
|
27
|
+
}, z.core.$strict>;
|
|
22
28
|
/**
|
|
23
|
-
* `POST /api/v1/device/confirm`: the org and exactly one of an existing
|
|
24
|
-
* person's (`deviceId`) or the name of a new one (`name`).
|
|
29
|
+
* `POST /api/v1/device/confirm`: the org, the dial-in provider, and exactly one of an existing
|
|
30
|
+
* device of the person's of that provider (`deviceId`) or the name of a new one (`name`).
|
|
25
31
|
*/
|
|
26
32
|
export declare const DeviceConfirmBody: z.ZodObject<{
|
|
27
33
|
userCode: z.ZodString;
|
|
28
34
|
orgId: z.ZodString;
|
|
35
|
+
provider: z.ZodString;
|
|
29
36
|
deviceId: z.ZodOptional<z.ZodUUID>;
|
|
30
37
|
name: z.ZodOptional<z.ZodString>;
|
|
31
38
|
}, z.core.$strict>;
|
|
@@ -37,6 +44,7 @@ declare const DeviceAuthorizeBodyDto_base: import("../infra/validation/create-zo
|
|
|
37
44
|
}>;
|
|
38
45
|
arch: z.ZodString;
|
|
39
46
|
programVersion: z.ZodString;
|
|
47
|
+
protocol: z.ZodString;
|
|
40
48
|
}, z.core.$strict>>;
|
|
41
49
|
export declare class DeviceAuthorizeBodyDto extends DeviceAuthorizeBodyDto_base {
|
|
42
50
|
}
|
|
@@ -55,9 +63,16 @@ declare const DeviceUserCodeBodyDto_base: import("../infra/validation/create-zod
|
|
|
55
63
|
}, z.core.$strict>>;
|
|
56
64
|
export declare class DeviceUserCodeBodyDto extends DeviceUserCodeBodyDto_base {
|
|
57
65
|
}
|
|
66
|
+
declare const DeviceProvidersQueryDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{
|
|
67
|
+
orgId: z.ZodString;
|
|
68
|
+
userCode: z.ZodString;
|
|
69
|
+
}, z.core.$strict>>;
|
|
70
|
+
export declare class DeviceProvidersQueryDto extends DeviceProvidersQueryDto_base {
|
|
71
|
+
}
|
|
58
72
|
declare const DeviceConfirmBodyDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{
|
|
59
73
|
userCode: z.ZodString;
|
|
60
74
|
orgId: z.ZodString;
|
|
75
|
+
provider: z.ZodString;
|
|
61
76
|
deviceId: z.ZodOptional<z.ZodUUID>;
|
|
62
77
|
name: z.ZodOptional<z.ZodString>;
|
|
63
78
|
}, z.core.$strict>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DIAL_IN_PROTOCOL_RE } from "@capybara-hq/plugin-sdk";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { DeviceName } from "../devices/dto.js";
|
|
3
4
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
@@ -8,6 +9,8 @@ export const DeviceAuthorizeBody = z
|
|
|
8
9
|
os: z.enum(["darwin", "linux"]),
|
|
9
10
|
arch: z.string().trim().min(1).max(32),
|
|
10
11
|
programVersion: z.string().trim().min(1).max(64),
|
|
12
|
+
/** The dial-in protocol the program speaks (`<name>/<major>`): its providers are offered. */
|
|
13
|
+
protocol: z.string().regex(DIAL_IN_PROTOCOL_RE),
|
|
11
14
|
})
|
|
12
15
|
.strict();
|
|
13
16
|
/** `POST /api/v1/device/token`: the secret device code from `authorize`. */
|
|
@@ -16,14 +19,21 @@ export const DeviceTokenBody = z.object({ deviceCode: z.string().min(1).max(200)
|
|
|
16
19
|
const UserCode = z.string().min(1).max(32);
|
|
17
20
|
export const DeviceUserCodeParams = z.object({ userCode: UserCode });
|
|
18
21
|
export const DeviceUserCodeBody = z.object({ userCode: UserCode }).strict();
|
|
22
|
+
/** A dial-in provider: the name of a plugin that declares `permissions.dialIn`. */
|
|
23
|
+
const ProviderName = z.string().min(1).max(100);
|
|
24
|
+
/** `GET /api/v1/device/providers`: the dial-in providers a pending code may choose in an org. */
|
|
25
|
+
export const DeviceProvidersQuery = z
|
|
26
|
+
.object({ orgId: z.string().min(1).max(100), userCode: UserCode })
|
|
27
|
+
.strict();
|
|
19
28
|
/**
|
|
20
|
-
* `POST /api/v1/device/confirm`: the org and exactly one of an existing
|
|
21
|
-
* person's (`deviceId`) or the name of a new one (`name`).
|
|
29
|
+
* `POST /api/v1/device/confirm`: the org, the dial-in provider, and exactly one of an existing
|
|
30
|
+
* device of the person's of that provider (`deviceId`) or the name of a new one (`name`).
|
|
22
31
|
*/
|
|
23
32
|
export const DeviceConfirmBody = z
|
|
24
33
|
.object({
|
|
25
34
|
userCode: UserCode,
|
|
26
35
|
orgId: z.string().min(1).max(100),
|
|
36
|
+
provider: ProviderName,
|
|
27
37
|
deviceId: z.uuid().optional(),
|
|
28
38
|
name: DeviceName.optional(),
|
|
29
39
|
})
|
|
@@ -40,5 +50,7 @@ export class DeviceUserCodeParamsDto extends createZodDto(DeviceUserCodeParams,
|
|
|
40
50
|
}
|
|
41
51
|
export class DeviceUserCodeBodyDto extends createZodDto(DeviceUserCodeBody, "DeviceUserCodeBody") {
|
|
42
52
|
}
|
|
53
|
+
export class DeviceProvidersQueryDto extends createZodDto(DeviceProvidersQuery, "DeviceProvidersQuery") {
|
|
54
|
+
}
|
|
43
55
|
export class DeviceConfirmBodyDto extends createZodDto(DeviceConfirmBody, "DeviceConfirmBody") {
|
|
44
56
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { DialInKernelFrame } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* The dial-in envelope as it crosses Redis between the relay (any replica) and the gateway replica
|
|
4
|
+
* holding the machine's socket. The relay queues kernel frames with kernel-internal fields next to
|
|
5
|
+
* them (the connection a request is fenced to, the machine a `stop` is for); the holder strips
|
|
6
|
+
* them before a frame goes out ({@link wireFrameOf}). The holder stores each machine `res` with
|
|
7
|
+
* the connection it arrived on (and, only for its own refusal, {@link GATEWAY_NOT_SENT}); the relay
|
|
8
|
+
* strips those again before the provider sees the body ({@link readStoredResult}). The kernel never
|
|
9
|
+
* reads a `body`.
|
|
10
|
+
*/
|
|
11
|
+
/** The connection a request is fenced to: the id the gateway sent in `ready` and its capacity. */
|
|
12
|
+
export interface DialInConnectionFence {
|
|
13
|
+
connectionId: string;
|
|
14
|
+
maxFrameBytes: number;
|
|
15
|
+
}
|
|
16
|
+
/** A request on the device's list: the wire frame plus the connection it may go out on. */
|
|
17
|
+
export interface QueuedRequest extends DialInConnectionFence {
|
|
18
|
+
type: "req";
|
|
19
|
+
id: string;
|
|
20
|
+
deadlineMs: number;
|
|
21
|
+
body: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** A cancel on the list; unfenced (it must reach the machine after a reconnect too). */
|
|
24
|
+
export interface QueuedCancel {
|
|
25
|
+
type: "cancel";
|
|
26
|
+
id: string;
|
|
27
|
+
}
|
|
28
|
+
/** A stop on the list; with `machineId`, only that machine's connection gets it. */
|
|
29
|
+
export interface QueuedStop {
|
|
30
|
+
type: "stop";
|
|
31
|
+
reason: "drain" | "stop";
|
|
32
|
+
machineId?: string;
|
|
33
|
+
}
|
|
34
|
+
export type QueuedFrame = QueuedRequest | QueuedCancel | QueuedStop;
|
|
35
|
+
/**
|
|
36
|
+
* The marker of a result the gateway stored itself for a request it never sent (the request was
|
|
37
|
+
* fenced to another connection, or did not fit): never a machine's field, since the strict
|
|
38
|
+
* envelope parse refuses unknown keys.
|
|
39
|
+
*/
|
|
40
|
+
export declare const GATEWAY_NOT_SENT: "notSent";
|
|
41
|
+
/** A result as the holder stores and publishes it. */
|
|
42
|
+
export interface StoredResult extends DialInConnectionFence {
|
|
43
|
+
type: "res";
|
|
44
|
+
id: string;
|
|
45
|
+
/** The machine's body; absent only on the gateway's own refusal. */
|
|
46
|
+
body?: unknown;
|
|
47
|
+
/** The gateway's refusal of a request it never sent: why, for the caller's error. */
|
|
48
|
+
[GATEWAY_NOT_SENT]?: string;
|
|
49
|
+
}
|
|
50
|
+
/** Why the holder did not send a queued frame. */
|
|
51
|
+
export type WireDecision = {
|
|
52
|
+
send: DialInKernelFrame;
|
|
53
|
+
text: string;
|
|
54
|
+
}
|
|
55
|
+
/** A request fenced to another connection: refused as not sent. */
|
|
56
|
+
| {
|
|
57
|
+
refuse: string;
|
|
58
|
+
id: string;
|
|
59
|
+
}
|
|
60
|
+
/** Nothing to send (a stop for another machine, or a malformed item): with the reason to log. */
|
|
61
|
+
| {
|
|
62
|
+
drop: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* What the holder sends for one queued item (`raw`, as popped from the list) on its connection:
|
|
66
|
+
* the kernel frame without the kernel-internal fields, or why it does not send it. A request goes
|
|
67
|
+
* out only on the connection it is fenced to; a cancel always; a stop only to the machine it names
|
|
68
|
+
* (when it names one).
|
|
69
|
+
*/
|
|
70
|
+
export declare function wireFrameOf(raw: string, conn: DialInConnectionFence & {
|
|
71
|
+
machineId: string;
|
|
72
|
+
}): WireDecision;
|
|
73
|
+
/**
|
|
74
|
+
* The result the holder stores for a machine's `res` (`body` given) or for its own refusal of a
|
|
75
|
+
* request it never sent (`notSent` given, no body), tagged with the connection it belongs to.
|
|
76
|
+
*/
|
|
77
|
+
export declare function storedResult(res: {
|
|
78
|
+
id: string;
|
|
79
|
+
body?: unknown;
|
|
80
|
+
}, conn: DialInConnectionFence, notSent?: string): StoredResult;
|
|
81
|
+
/** A stored result as the relay reads it: the body for the provider and the kernel's tags apart. */
|
|
82
|
+
export interface ReadResult {
|
|
83
|
+
id: string;
|
|
84
|
+
body: unknown;
|
|
85
|
+
/** The connection the result arrived on. */
|
|
86
|
+
connection: DialInConnectionFence;
|
|
87
|
+
/** The gateway's refusal (the request never reached the machine), with its reason. */
|
|
88
|
+
notSent?: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Reads a stored result (as stored, or as published on the bus): the machine's body with every
|
|
92
|
+
* kernel-internal field stripped, the connection it arrived on, and the gateway's not-sent refusal.
|
|
93
|
+
* Throws on anything else (no connection tag, a body missing without a refusal).
|
|
94
|
+
*/
|
|
95
|
+
export declare function readStoredResult(stored: unknown): ReadResult;
|