@capybara-hq/plugin-sdk 0.1.0-rc.7 → 0.1.0-rc.71
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 +1 -1
- package/agent-docs/agent-templates.md +14 -2
- package/agent-docs/concepts.md +14 -5
- package/agent-docs/connector-templates.md +11 -3
- package/agent-docs/extension-points/channel.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/device-provider.md +15 -0
- package/agent-docs/extension-points/file-preview.md +3 -1
- package/agent-docs/extension-points/model-provider.md +3 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- package/agent-docs/extension-points/push-provider.md +17 -0
- package/agent-docs/extensions.md +77 -4
- package/agent-docs/plugin-format.md +51 -12
- package/agent-docs/setup.md +54 -0
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/avatar-presets.d.ts +8 -0
- package/dist/avatar-presets.js +17 -0
- package/dist/bootstrap.d.ts +109 -1
- package/dist/bootstrap.js +185 -2
- package/dist/cards.d.ts +60 -13
- package/dist/cards.js +88 -18
- package/dist/channel.d.ts +128 -47
- package/dist/channel.js +10 -5
- package/dist/client-css.d.ts +36 -0
- package/dist/client-css.js +326 -0
- package/dist/client-section.d.ts +35 -0
- package/dist/client-section.js +133 -0
- package/dist/config-ui.d.ts +28 -6
- package/dist/config-ui.js +88 -25
- package/dist/config-url-fetch.d.ts +19 -0
- package/dist/config-url-fetch.js +43 -0
- package/dist/connector-auth.d.ts +13 -2
- package/dist/connector-auth.js +82 -8
- package/dist/connector.d.ts +74 -32
- package/dist/context.d.ts +40 -0
- package/dist/context.js +2 -0
- package/dist/ctx.d.ts +210 -30
- package/dist/ctx.js +9 -1
- package/dist/define-extension.d.ts +23 -13
- package/dist/define-extension.js +19 -5
- package/dist/device-denied-paths.d.ts +20 -0
- package/dist/device-denied-paths.js +118 -0
- package/dist/device-operation.d.ts +339 -0
- package/dist/device-operation.js +312 -0
- package/dist/device-protocol.d.ts +285 -50
- package/dist/device-protocol.js +755 -90
- package/dist/device-provider.d.ts +708 -0
- package/dist/device-provider.js +325 -0
- package/dist/device-service.d.ts +52 -0
- package/dist/device-service.js +105 -0
- package/dist/dial-in.d.ts +239 -0
- package/dist/dial-in.js +155 -0
- package/dist/directory.d.ts +15 -12
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +7 -3
- package/dist/field-meta.d.ts +19 -0
- package/dist/field-meta.js +54 -0
- package/dist/file-preview.d.ts +43 -10
- package/dist/git-hosts.d.ts +53 -0
- package/dist/git-hosts.js +98 -0
- package/dist/hooks.d.ts +125 -20
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +71 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +38 -9
- package/dist/identity.js +21 -1
- package/dist/index.d.ts +31 -4
- package/dist/index.js +31 -4
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +210 -75
- package/dist/model.js +152 -19
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/network-classes.d.ts +98 -0
- package/dist/network-classes.js +291 -0
- package/dist/permissions.d.ts +65 -22
- package/dist/permissions.js +139 -43
- package/dist/platform-only.d.ts +27 -0
- package/dist/platform-only.js +35 -0
- package/dist/plugin-manifest.d.ts +40 -9
- package/dist/plugin-manifest.js +171 -60
- package/dist/plugin-package.d.ts +82 -39
- package/dist/plugin-package.js +68 -41
- package/dist/push.d.ts +75 -0
- package/dist/push.js +87 -0
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +2343 -0
- package/dist/sandbox-native-runtime-source.d.ts +10 -0
- package/dist/sandbox-native-runtime-source.js +476 -0
- package/dist/sandbox-runtime-source.d.ts +47 -0
- package/dist/sandbox-runtime-source.js +73 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/secret.d.ts +8 -2
- package/dist/secret.js +11 -4
- package/dist/setup-check.d.ts +128 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +356 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +86 -72
- package/dist/setup-guide.js +340 -108
- package/dist/shell-capabilities.d.ts +211 -0
- package/dist/shell-capabilities.js +44 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +21 -0
- package/dist/skill.d.ts +27 -17
- package/dist/skill.js +40 -26
- package/dist/storage.d.ts +52 -25
- package/dist/svg-viewbox.d.ts +10 -0
- package/dist/svg-viewbox.js +24 -0
- package/dist/theme-assets.d.ts +55 -0
- package/dist/theme-assets.js +489 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +299 -0
- package/dist/theme-tokens.generated.js +184 -0
- package/dist/theme.d.ts +190 -0
- package/dist/theme.js +471 -0
- package/dist/tool.d.ts +104 -30
- package/dist/tool.js +29 -9
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +385 -0
- package/dist/ui-resolve.d.ts +35 -0
- package/dist/ui-resolve.js +42 -0
- package/dist/ui-slots.d.ts +65 -0
- package/dist/ui-slots.js +261 -0
- package/dist/ui.d.ts +232 -77
- package/dist/ui.js +104 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/dist/web.d.ts +26 -20
- package/package.json +13 -1
- package/schemas/bootstrap-extra.v1.schema.json +186 -0
- package/schemas/bootstrap.v1.schema.json +20 -0
- package/schemas/connector-template.v1.schema.json +62 -4
- package/schemas/plugin.v1.schema.json +93 -143
- package/schemas/theme.v1.schema.json +302 -0
- package/agent-docs/extension-points/sandbox.md +0 -15
- package/dist/org-access.d.ts +0 -27
- package/dist/org-access.js +0 -35
- package/dist/sandbox.d.ts +0 -254
- package/dist/sandbox.js +0 -153
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dial-in channel: the kernel's generic way for a machine to connect to a deployment and
|
|
3
|
+
* serve one device of a `device-provider@1` extension that declares `permissions.dialIn`. The
|
|
4
|
+
* kernel signs the machine in, holds its socket on the gateway role, bounds every frame by the
|
|
5
|
+
* negotiated size and relays the frames' opaque `body` between the machine and the device's
|
|
6
|
+
* provider. It never reads a body: what a body means is the provider's protocol, named by
|
|
7
|
+
* `permissions.dialIn.protocol` and by the machine's hello.
|
|
8
|
+
*/
|
|
9
|
+
import type { DeviceStream } from "./device-provider.js";
|
|
10
|
+
/**
|
|
11
|
+
* A dial-in protocol: `<name>/<major>`, a lower-case name of 1 to 41 characters and a major
|
|
12
|
+
* version from 1 to 9999 (for example `capybara-device/6`). A machine's hello must name exactly
|
|
13
|
+
* the protocol of the provider serving its device.
|
|
14
|
+
*/
|
|
15
|
+
export declare const DIAL_IN_PROTOCOL_RE: RegExp;
|
|
16
|
+
/**
|
|
17
|
+
* The credit, in messages, each side of a dial-in stream starts with for the other: a side sends a
|
|
18
|
+
* `stream-data` only while it holds credit, and grants more with `stream-credit` as it consumes
|
|
19
|
+
* messages, so one stream cannot fill the connection and starve the machine's other frames.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DIAL_IN_STREAM_INITIAL_CREDIT = 8;
|
|
22
|
+
/**
|
|
23
|
+
* The stream frames both sides send ({@link DialInChannel.openStream}). `data` is one whole message
|
|
24
|
+
* in standard base64; the frame, like every frame, fits the connection's `maxFrameBytes`.
|
|
25
|
+
*/
|
|
26
|
+
export type DialInStreamFrame = {
|
|
27
|
+
type: "stream-data";
|
|
28
|
+
streamId: string;
|
|
29
|
+
data: string;
|
|
30
|
+
}
|
|
31
|
+
/** Grants the peer `messages` more `stream-data` frames on the stream. */
|
|
32
|
+
| {
|
|
33
|
+
type: "stream-credit";
|
|
34
|
+
streamId: string;
|
|
35
|
+
messages: number;
|
|
36
|
+
}
|
|
37
|
+
/** Either side ends the stream; no frame of it follows. */
|
|
38
|
+
| {
|
|
39
|
+
type: "stream-close";
|
|
40
|
+
streamId: string;
|
|
41
|
+
reason: string;
|
|
42
|
+
};
|
|
43
|
+
/** A frame from the machine. The kernel checks the envelope; `body` is the provider's. */
|
|
44
|
+
export type DialInMachineFrame = {
|
|
45
|
+
/** The first frame after the socket opens. */
|
|
46
|
+
type: "hello";
|
|
47
|
+
/** Must equal the serving provider's `permissions.dialIn.protocol`. */
|
|
48
|
+
protocol: string;
|
|
49
|
+
/** Random per run of the machine's program, the same on each of its connections. */
|
|
50
|
+
programRunId: string;
|
|
51
|
+
program: {
|
|
52
|
+
version: string;
|
|
53
|
+
os: string;
|
|
54
|
+
arch: string;
|
|
55
|
+
bootId?: string;
|
|
56
|
+
};
|
|
57
|
+
/** The largest frame, in UTF-8 bytes, the machine accepts. */
|
|
58
|
+
transport: {
|
|
59
|
+
maxFrameBytes: number;
|
|
60
|
+
};
|
|
61
|
+
body: unknown;
|
|
62
|
+
}
|
|
63
|
+
/** The answer to the kernel's `req` with the same `id`. */
|
|
64
|
+
| {
|
|
65
|
+
type: "res";
|
|
66
|
+
id: string;
|
|
67
|
+
body: unknown;
|
|
68
|
+
}
|
|
69
|
+
/** An unsolicited frame, handed to {@link DialInHandler.onFrame}. */
|
|
70
|
+
| {
|
|
71
|
+
type: "event";
|
|
72
|
+
body: unknown;
|
|
73
|
+
}
|
|
74
|
+
/** The answer to the kernel's `stream-open`: the machine opened the stream, or why not. */
|
|
75
|
+
| {
|
|
76
|
+
type: "stream-opened";
|
|
77
|
+
streamId: string;
|
|
78
|
+
ok: boolean;
|
|
79
|
+
error?: string;
|
|
80
|
+
} | DialInStreamFrame;
|
|
81
|
+
/** A frame from the kernel to the machine. */
|
|
82
|
+
export type DialInKernelFrame =
|
|
83
|
+
/**
|
|
84
|
+
* The kernel accepted the hello (the provider's `onHello` answered ok). `maxFrameBytes` is the
|
|
85
|
+
* connection's effective frame capacity: the smaller of the machine's `transport.maxFrameBytes`
|
|
86
|
+
* and the kernel's limit. Neither side sends a larger frame on this connection.
|
|
87
|
+
*/
|
|
88
|
+
{
|
|
89
|
+
type: "ready";
|
|
90
|
+
connectionId: string;
|
|
91
|
+
maxFrameBytes: number;
|
|
92
|
+
}
|
|
93
|
+
/** A provider's request ({@link DialInChannel.request}); answered by a `res` with its `id`. */
|
|
94
|
+
| {
|
|
95
|
+
type: "req";
|
|
96
|
+
id: string;
|
|
97
|
+
deadlineMs: number;
|
|
98
|
+
body: unknown;
|
|
99
|
+
}
|
|
100
|
+
/** The kernel no longer waits for request `id` (aborted or timed out). */
|
|
101
|
+
| {
|
|
102
|
+
type: "cancel";
|
|
103
|
+
id: string;
|
|
104
|
+
}
|
|
105
|
+
/** The machine should finish its work and disconnect (`drain`) or stop at once (`stop`). */
|
|
106
|
+
| {
|
|
107
|
+
type: "stop";
|
|
108
|
+
reason: "drain" | "stop";
|
|
109
|
+
}
|
|
110
|
+
/** Opens a stream on the machine; `body` names the target in the provider's protocol. */
|
|
111
|
+
| {
|
|
112
|
+
type: "stream-open";
|
|
113
|
+
streamId: string;
|
|
114
|
+
body: unknown;
|
|
115
|
+
} | DialInStreamFrame;
|
|
116
|
+
/** A machine frame that is not a valid dial-in envelope. The kernel closes the socket on it. */
|
|
117
|
+
export declare class DialInProtocolError extends Error {
|
|
118
|
+
constructor(message: string);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Strictly parses one machine frame: the text must be at most `maxBytes` UTF-8 bytes (checked
|
|
122
|
+
* before `JSON.parse`), an object of a known `type` with exactly that type's keys. `body` is kept
|
|
123
|
+
* as parsed, never inspected. Throws {@link DialInProtocolError}; a `maxBytes` that is not a
|
|
124
|
+
* positive integer throws a `RangeError`.
|
|
125
|
+
*/
|
|
126
|
+
export declare function parseDialInMachineFrame(text: string, maxBytes: number): DialInMachineFrame;
|
|
127
|
+
/**
|
|
128
|
+
* The machine's side of {@link parseDialInMachineFrame}: strictly parses one kernel frame, at most
|
|
129
|
+
* `maxBytes` UTF-8 bytes (checked before `JSON.parse`), an object of a known `type` with exactly
|
|
130
|
+
* that type's keys; `body` is kept as parsed. Throws {@link DialInProtocolError}; a `maxBytes`
|
|
131
|
+
* that is not a positive integer throws a `RangeError`.
|
|
132
|
+
*/
|
|
133
|
+
export declare function parseDialInKernelFrame(text: string, maxBytes: number): DialInKernelFrame;
|
|
134
|
+
/**
|
|
135
|
+
* The provider's side of the dial-in channel: `DeviceProvider.dialIn`, required when the extension
|
|
136
|
+
* declares `permissions.dialIn = { protocol: "<name>/<major>" }`.
|
|
137
|
+
*/
|
|
138
|
+
export interface DialInHandler {
|
|
139
|
+
/**
|
|
140
|
+
* Called on the gateway replica holding the socket, after the kernel authenticated it.
|
|
141
|
+
* `connection` names the machine and the connection the hello arrived on.
|
|
142
|
+
*/
|
|
143
|
+
onHello(deviceId: string, hello: unknown, signal: AbortSignal, connection: DialInConnectionInfo): Promise<{
|
|
144
|
+
ok: true;
|
|
145
|
+
} | {
|
|
146
|
+
ok: false;
|
|
147
|
+
code: string;
|
|
148
|
+
message: string;
|
|
149
|
+
}>;
|
|
150
|
+
/** Unsolicited frames from the machine (not responses to requests), with their connection. */
|
|
151
|
+
onFrame?(deviceId: string, frame: unknown, connection: DialInConnectionInfo): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* The connection whose hello this provider accepted closed. `connection` is that connection's,
|
|
154
|
+
* so a `replaced` close names the old machine, never the one that replaced it.
|
|
155
|
+
*/
|
|
156
|
+
onClose?(deviceId: string, reason: "offline" | "replaced" | "revoked" | "deleted", connection: DialInConnectionInfo): void;
|
|
157
|
+
}
|
|
158
|
+
/** Which machine and which of its connections a {@link DialInHandler} call is about. */
|
|
159
|
+
export interface DialInConnectionInfo {
|
|
160
|
+
/**
|
|
161
|
+
* The kernel's id of the signed-in machine (its credential): a machine signing in again to the
|
|
162
|
+
* same device, or another machine replacing it, gets another id.
|
|
163
|
+
*/
|
|
164
|
+
machineId: string;
|
|
165
|
+
/** The connection id, the same the kernel sends to the machine in `ready`. */
|
|
166
|
+
connectionId: string;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* `ctx.dialIn` (requires `permissions.dialIn`): talks to the machines serving this extension's
|
|
170
|
+
* devices. Each call checks that the device is served by the calling extension.
|
|
171
|
+
*/
|
|
172
|
+
export interface DialInChannel {
|
|
173
|
+
/**
|
|
174
|
+
* Sends `frame` as the body of a `req` and resolves the body of the machine's `res`. Throws
|
|
175
|
+
* {@link DeviceOfflineError} when no machine holds the device within the reconnect grace.
|
|
176
|
+
*/
|
|
177
|
+
request(deviceId: string, frame: unknown, opts: {
|
|
178
|
+
timeoutMs: number;
|
|
179
|
+
signal?: AbortSignal;
|
|
180
|
+
}): Promise<unknown>;
|
|
181
|
+
online(deviceId: string): Promise<boolean>;
|
|
182
|
+
/**
|
|
183
|
+
* The negotiated frame capacity of the machine's current connection: the `maxFrameBytes` the
|
|
184
|
+
* kernel sent in that connection's `ready` (the smaller of the machine's announced
|
|
185
|
+
* `transport.maxFrameBytes` and the deployment's limit). A provider sizes its request bodies
|
|
186
|
+
* and the answers it asks for by it: a `req` frame larger than this is refused. Null when no
|
|
187
|
+
* machine holds the device now. Read from shared state at every call, so a reconnect with
|
|
188
|
+
* another capacity shows at once; it can change between this call and a later request.
|
|
189
|
+
*/
|
|
190
|
+
capacity(deviceId: string): Promise<{
|
|
191
|
+
maxFrameBytes: number;
|
|
192
|
+
} | null>;
|
|
193
|
+
stop(deviceId: string, reason: "drain" | "stop"): Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* Opens a stream to the machine serving the device: sends `stream-open` with `body` (the
|
|
196
|
+
* target, in the provider's protocol) and resolves once the machine answers `stream-opened` ok.
|
|
197
|
+
* Stream frames go straight over the machine's socket, never through shared state, so this
|
|
198
|
+
* works only on the gateway replica holding that socket: elsewhere it throws
|
|
199
|
+
* {@link DialInStreamElsewhereError}. Throws {@link DeviceOfflineError} when no machine holds the
|
|
200
|
+
* device. Each message must fit the connection's frame capacity once base64-encoded in a
|
|
201
|
+
* `stream-data` frame. `signal` bounds the opening only.
|
|
202
|
+
*/
|
|
203
|
+
openStream(deviceId: string, body: unknown, opts: {
|
|
204
|
+
signal: AbortSignal;
|
|
205
|
+
}): Promise<DeviceStream>;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* {@link DialInChannel.openStream} was called on a replica that does not hold the machine's
|
|
209
|
+
* socket: the caller must reach the holding gateway replica instead.
|
|
210
|
+
*/
|
|
211
|
+
export declare class DialInStreamElsewhereError extends Error {
|
|
212
|
+
readonly code = "device.stream_elsewhere";
|
|
213
|
+
constructor(deviceId: string, opts?: {
|
|
214
|
+
cause?: unknown;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* `ctx.devices` (requires `provides: ["device-provider@1"]`): what a device provider tells the
|
|
219
|
+
* kernel about its devices.
|
|
220
|
+
*/
|
|
221
|
+
export interface DevicesCtx {
|
|
222
|
+
/**
|
|
223
|
+
* The device's report (`DeviceProvider.report`) or its permission support may have changed: the
|
|
224
|
+
* kernel reads the report (and the permission support of the device's instance, if any) again
|
|
225
|
+
* and stores them. When the revision changed, it invalidates what was approved against the old
|
|
226
|
+
* one; when only display text changed under the same revision, the new text is stored and no
|
|
227
|
+
* approval is invalidated.
|
|
228
|
+
*/
|
|
229
|
+
reportChanged(deviceId: string): Promise<void>;
|
|
230
|
+
}
|
|
231
|
+
/** No machine serves the device (it is not connected, and did not reconnect within the grace). */
|
|
232
|
+
export declare class DeviceOfflineError extends Error {
|
|
233
|
+
readonly code = "device.offline";
|
|
234
|
+
constructor(deviceId: string, opts?: {
|
|
235
|
+
cause?: unknown;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/** Recognizes {@link DeviceOfflineError} by name and code, so another SDK copy's error matches. */
|
|
239
|
+
export declare function isDeviceOfflineError(e: unknown): e is DeviceOfflineError;
|
package/dist/dial-in.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dial-in channel: the kernel's generic way for a machine to connect to a deployment and
|
|
3
|
+
* serve one device of a `device-provider@1` extension that declares `permissions.dialIn`. The
|
|
4
|
+
* kernel signs the machine in, holds its socket on the gateway role, bounds every frame by the
|
|
5
|
+
* negotiated size and relays the frames' opaque `body` between the machine and the device's
|
|
6
|
+
* provider. It never reads a body: what a body means is the provider's protocol, named by
|
|
7
|
+
* `permissions.dialIn.protocol` and by the machine's hello.
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
/**
|
|
11
|
+
* A dial-in protocol: `<name>/<major>`, a lower-case name of 1 to 41 characters and a major
|
|
12
|
+
* version from 1 to 9999 (for example `capybara-device/6`). A machine's hello must name exactly
|
|
13
|
+
* the protocol of the provider serving its device.
|
|
14
|
+
*/
|
|
15
|
+
export const DIAL_IN_PROTOCOL_RE = /^[a-z][a-z0-9-]{0,40}\/[1-9][0-9]{0,3}$/;
|
|
16
|
+
/**
|
|
17
|
+
* The credit, in messages, each side of a dial-in stream starts with for the other: a side sends a
|
|
18
|
+
* `stream-data` only while it holds credit, and grants more with `stream-credit` as it consumes
|
|
19
|
+
* messages, so one stream cannot fill the connection and starve the machine's other frames.
|
|
20
|
+
*/
|
|
21
|
+
export const DIAL_IN_STREAM_INITIAL_CREDIT = 8;
|
|
22
|
+
/** A machine frame that is not a valid dial-in envelope. The kernel closes the socket on it. */
|
|
23
|
+
export class DialInProtocolError extends Error {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = "DialInProtocolError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Ids, `programRunId` and `bootId`: 1 to 128 letters, digits, `.`, `_`, `:` and `-`. */
|
|
30
|
+
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
31
|
+
const id = z.string().regex(ID_RE);
|
|
32
|
+
const label = z.string().min(1).max(64);
|
|
33
|
+
// a frame without a body is malformed (JSON has no undefined, so this is a missing key)
|
|
34
|
+
const body = z.unknown().refine((v) => v !== undefined, "body is required");
|
|
35
|
+
// standard base64, padded; empty is an empty message
|
|
36
|
+
const base64 = z
|
|
37
|
+
.string()
|
|
38
|
+
.regex(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/, "data must be base64");
|
|
39
|
+
const reason = z.string().max(500);
|
|
40
|
+
const streamFrames = [
|
|
41
|
+
z.strictObject({ type: z.literal("stream-data"), streamId: id, data: base64 }),
|
|
42
|
+
z.strictObject({
|
|
43
|
+
type: z.literal("stream-credit"),
|
|
44
|
+
streamId: id,
|
|
45
|
+
messages: z.number().int().min(1).max(1_000_000),
|
|
46
|
+
}),
|
|
47
|
+
z.strictObject({ type: z.literal("stream-close"), streamId: id, reason }),
|
|
48
|
+
];
|
|
49
|
+
const machineFrame = z.discriminatedUnion("type", [
|
|
50
|
+
z.strictObject({
|
|
51
|
+
type: z.literal("hello"),
|
|
52
|
+
protocol: z.string().regex(DIAL_IN_PROTOCOL_RE),
|
|
53
|
+
programRunId: id,
|
|
54
|
+
program: z.strictObject({
|
|
55
|
+
version: label,
|
|
56
|
+
os: label,
|
|
57
|
+
arch: label,
|
|
58
|
+
bootId: id.optional(),
|
|
59
|
+
}),
|
|
60
|
+
transport: z.strictObject({
|
|
61
|
+
maxFrameBytes: z.number().int().min(1024).max(Number.MAX_SAFE_INTEGER),
|
|
62
|
+
}),
|
|
63
|
+
body,
|
|
64
|
+
}),
|
|
65
|
+
z.strictObject({ type: z.literal("res"), id, body }),
|
|
66
|
+
z.strictObject({ type: z.literal("event"), body }),
|
|
67
|
+
z.strictObject({
|
|
68
|
+
type: z.literal("stream-opened"),
|
|
69
|
+
streamId: id,
|
|
70
|
+
ok: z.boolean(),
|
|
71
|
+
error: reason.optional(),
|
|
72
|
+
}),
|
|
73
|
+
...streamFrames,
|
|
74
|
+
]);
|
|
75
|
+
/**
|
|
76
|
+
* Strictly parses one machine frame: the text must be at most `maxBytes` UTF-8 bytes (checked
|
|
77
|
+
* before `JSON.parse`), an object of a known `type` with exactly that type's keys. `body` is kept
|
|
78
|
+
* as parsed, never inspected. Throws {@link DialInProtocolError}; a `maxBytes` that is not a
|
|
79
|
+
* positive integer throws a `RangeError`.
|
|
80
|
+
*/
|
|
81
|
+
export function parseDialInMachineFrame(text, maxBytes) {
|
|
82
|
+
return parseFrame(machineFrame, text, maxBytes);
|
|
83
|
+
}
|
|
84
|
+
function parseFrame(schema, text, maxBytes) {
|
|
85
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1)
|
|
86
|
+
throw new RangeError(`maxBytes must be a positive integer, got ${maxBytes}`);
|
|
87
|
+
// a UTF-16 code unit is at least one UTF-8 byte: the length alone may already decide it
|
|
88
|
+
if (text.length > maxBytes || new TextEncoder().encode(text).byteLength > maxBytes)
|
|
89
|
+
throw new DialInProtocolError(`frame exceeds ${maxBytes} bytes`);
|
|
90
|
+
let parsed;
|
|
91
|
+
try {
|
|
92
|
+
parsed = JSON.parse(text);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
throw new DialInProtocolError("frame is not valid JSON");
|
|
96
|
+
}
|
|
97
|
+
const r = schema.safeParse(parsed);
|
|
98
|
+
if (!r.success) {
|
|
99
|
+
const issue = r.error.issues[0];
|
|
100
|
+
const at = issue?.path.length ? ` at ${issue.path.join(".")}` : "";
|
|
101
|
+
throw new DialInProtocolError(`invalid dial-in frame${at}: ${issue?.message ?? "malformed"}`);
|
|
102
|
+
}
|
|
103
|
+
return r.data;
|
|
104
|
+
}
|
|
105
|
+
const kernelFrame = z.discriminatedUnion("type", [
|
|
106
|
+
z.strictObject({
|
|
107
|
+
type: z.literal("ready"),
|
|
108
|
+
connectionId: id,
|
|
109
|
+
maxFrameBytes: z.number().int().min(1024).max(Number.MAX_SAFE_INTEGER),
|
|
110
|
+
}),
|
|
111
|
+
z.strictObject({
|
|
112
|
+
type: z.literal("req"),
|
|
113
|
+
id,
|
|
114
|
+
deadlineMs: z.number().int().min(1).max(Number.MAX_SAFE_INTEGER),
|
|
115
|
+
body,
|
|
116
|
+
}),
|
|
117
|
+
z.strictObject({ type: z.literal("cancel"), id }),
|
|
118
|
+
z.strictObject({ type: z.literal("stop"), reason: z.enum(["drain", "stop"]) }),
|
|
119
|
+
z.strictObject({ type: z.literal("stream-open"), streamId: id, body }),
|
|
120
|
+
...streamFrames,
|
|
121
|
+
]);
|
|
122
|
+
/**
|
|
123
|
+
* The machine's side of {@link parseDialInMachineFrame}: strictly parses one kernel frame, at most
|
|
124
|
+
* `maxBytes` UTF-8 bytes (checked before `JSON.parse`), an object of a known `type` with exactly
|
|
125
|
+
* that type's keys; `body` is kept as parsed. Throws {@link DialInProtocolError}; a `maxBytes`
|
|
126
|
+
* that is not a positive integer throws a `RangeError`.
|
|
127
|
+
*/
|
|
128
|
+
export function parseDialInKernelFrame(text, maxBytes) {
|
|
129
|
+
return parseFrame(kernelFrame, text, maxBytes);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* {@link DialInChannel.openStream} was called on a replica that does not hold the machine's
|
|
133
|
+
* socket: the caller must reach the holding gateway replica instead.
|
|
134
|
+
*/
|
|
135
|
+
export class DialInStreamElsewhereError extends Error {
|
|
136
|
+
code = "device.stream_elsewhere";
|
|
137
|
+
constructor(deviceId, opts) {
|
|
138
|
+
super(`Device ${deviceId}'s machine is connected to another gateway replica; open the stream there.`, opts && "cause" in opts ? { cause: opts.cause } : undefined);
|
|
139
|
+
this.name = "DialInStreamElsewhereError";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** No machine serves the device (it is not connected, and did not reconnect within the grace). */
|
|
143
|
+
export class DeviceOfflineError extends Error {
|
|
144
|
+
code = "device.offline";
|
|
145
|
+
constructor(deviceId, opts) {
|
|
146
|
+
super(`Device ${deviceId} is offline: no machine is connected for it. Reconnect the machine and retry.`, opts && "cause" in opts ? { cause: opts.cause } : undefined);
|
|
147
|
+
this.name = "DeviceOfflineError";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** Recognizes {@link DeviceOfflineError} by name and code, so another SDK copy's error matches. */
|
|
151
|
+
export function isDeviceOfflineError(e) {
|
|
152
|
+
return (e instanceof Error &&
|
|
153
|
+
e.name === "DeviceOfflineError" &&
|
|
154
|
+
e.code === "device.offline");
|
|
155
|
+
}
|
package/dist/directory.d.ts
CHANGED
|
@@ -8,27 +8,30 @@ export interface DirectoryMember {
|
|
|
8
8
|
}
|
|
9
9
|
export interface Directory {
|
|
10
10
|
/**
|
|
11
|
-
* Optional: whether
|
|
12
|
-
* credential filled in). Implement it in an extension whose directory fields are
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* Optional: whether the org's effective config has the directory fully set up (e.g. every
|
|
12
|
+
* required credential filled in). Implement it in an extension whose directory fields are
|
|
13
|
+
* optional (the same extension also provides other extension points such as a channel, and an
|
|
14
|
+
* org that uses only those leaves the directory fields empty). When it returns false the kernel
|
|
15
15
|
* treats the directory as "not configured": the hourly scan, `directory_changed` and the
|
|
16
16
|
* pre-removal recheck are skipped silently (no job, no audit, no warning), and a manual sync by an
|
|
17
17
|
* admin returns 409 `directory.not_configured`. When not implemented, any config that satisfies
|
|
18
18
|
* the schema counts as configured. Must be a pure function (no requests, never throws). `config`
|
|
19
|
-
* is the effective
|
|
19
|
+
* is the effective config for the org (see `listMembers`' `config`).
|
|
20
20
|
*/
|
|
21
|
-
configured?(
|
|
21
|
+
configured?(config: unknown): boolean;
|
|
22
22
|
listMembers(args: {
|
|
23
|
-
orgConfig: unknown;
|
|
24
23
|
/**
|
|
25
|
-
* The extension's effective
|
|
26
|
-
*
|
|
24
|
+
* The extension's effective config for this org: the platform's deployment config with the
|
|
25
|
+
* org's copy applied to the overridable fields (every field not marked `platformOnly`), or the
|
|
27
26
|
* platform's config (equal to `ctx.config`) while the org follows it. Use it, not `ctx.config`,
|
|
28
|
-
* for work done for this org.
|
|
29
|
-
* always passes it.
|
|
27
|
+
* for work done for this org.
|
|
30
28
|
*/
|
|
31
|
-
config
|
|
29
|
+
config: unknown;
|
|
30
|
+
/**
|
|
31
|
+
* The org the call is made for. Pass it to `configUrlFetch` (`orgId`) or `ctx.net.fetch`, so a
|
|
32
|
+
* URL an org set is checked against that org's network rules. The kernel always sets it.
|
|
33
|
+
*/
|
|
34
|
+
orgId?: string;
|
|
32
35
|
cursor?: string;
|
|
33
36
|
signal: AbortSignal;
|
|
34
37
|
}): Promise<{
|
|
@@ -31,6 +31,8 @@ export declare const CHANNEL_EXTENSION_POINT = "channel@1";
|
|
|
31
31
|
export declare const IDENTITY_SOURCE_EXTENSION_POINT = "identity-source@1";
|
|
32
32
|
/** Directory sync extension point ref (see `directory.ts`). */
|
|
33
33
|
export declare const DIRECTORY_EXTENSION_POINT = "directory@1";
|
|
34
|
+
/** Context provider extension point ref (see `context.ts`). */
|
|
35
|
+
export declare const CONTEXT_EXTENSION_POINT = "context@1";
|
|
34
36
|
/** Parses an extension point ref; throws when the format is invalid. */
|
|
35
37
|
export declare function parseExtensionPoint(ref: string): {
|
|
36
38
|
name: string;
|
package/dist/extension-point.js
CHANGED
|
@@ -8,19 +8,21 @@ const info = (majors, description, cardinality, brokered = false, orgScoped = fa
|
|
|
8
8
|
});
|
|
9
9
|
/** The registered extension points. */
|
|
10
10
|
export const EXTENSION_POINTS = {
|
|
11
|
-
|
|
11
|
+
"device-provider": info([1], "Provides devices (an instance plus kept files) agents run commands in: containers, microVMs, connected machines.", "multi", true, true),
|
|
12
12
|
"config-source": info([1], "Supplies deployment configuration from an external store such as Nacos.", "single"),
|
|
13
13
|
"secret-store": info([1], "Stores and resolves secrets (connector credentials, secret config) outside the database.", "single", true),
|
|
14
14
|
"object-store": info([1], "Stores files and artifacts in S3-compatible object storage, with presigned uploads.", "single", true),
|
|
15
15
|
channel: info([1], "Connects an instant-messaging platform (Slack, Lark): inbound events, replies and cards.", "multi", false, true),
|
|
16
|
-
"model-provider": info([
|
|
16
|
+
"model-provider": info([2], "Calls a model vendor's API and streams the result back to the runtime.", "multi", true),
|
|
17
17
|
"identity-source": info([1], "Signs people in through an external identity provider (SSO).", "multi"),
|
|
18
18
|
directory: info([1], "Syncs members and departments from an external company directory.", "multi", false, true),
|
|
19
19
|
counter: info([1], "Counts usage so quotas and reports can be built on it.", "multi"),
|
|
20
20
|
connector: info([1], "Speaks one protocol (MCP, OpenAPI) to external systems and exposes their tools to agents.", "multi", true),
|
|
21
|
-
"file-preview": info([1], "Renders previews of files of given types
|
|
21
|
+
"file-preview": info([1], "Renders previews of files of given types: conversation files, shared files and skill files.", "multi", false, true),
|
|
22
22
|
"web-search": info([1], "Searches the web for the WebSearch tool; each org picks a default provider.", "multi", true, true, "org-default"),
|
|
23
|
+
context: info([1], "Adds text to the model's context at run start in conversations of orgs that enable it.", "multi", true, true),
|
|
23
24
|
"web-fetch": info([1], "Fetches and extracts web pages for the WebFetch tool; each org picks a default provider.", "multi", true, true, "org-default"),
|
|
25
|
+
"push-provider": info([1], "Delivers push notifications to people's mobile apps through one channel (APNs, FCM, an aggregator).", "multi", true),
|
|
24
26
|
};
|
|
25
27
|
/** Cardinality of the registered extension points (derived from EXTENSION_POINTS). */
|
|
26
28
|
export const EXTENSION_POINT_CARDINALITY = Object.fromEntries(Object.entries(EXTENSION_POINTS).map(([k, v]) => [k, v.cardinality]));
|
|
@@ -32,6 +34,8 @@ export const CHANNEL_EXTENSION_POINT = "channel@1";
|
|
|
32
34
|
export const IDENTITY_SOURCE_EXTENSION_POINT = "identity-source@1";
|
|
33
35
|
/** Directory sync extension point ref (see `directory.ts`). */
|
|
34
36
|
export const DIRECTORY_EXTENSION_POINT = "directory@1";
|
|
37
|
+
/** Context provider extension point ref (see `context.ts`). */
|
|
38
|
+
export const CONTEXT_EXTENSION_POINT = "context@1";
|
|
35
39
|
/** Parses an extension point ref; throws when the format is invalid. */
|
|
36
40
|
export function parseExtensionPoint(ref) {
|
|
37
41
|
const m = /^([a-z][a-z0-9-]*)@(\d+)$/.exec(ref);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The wrappers a config field's marks are read through: the same set the kernel's `configFields`
|
|
4
|
+
* strips and `configJsonSchema` inherits meta across.
|
|
5
|
+
*/
|
|
6
|
+
export declare const META_WRAPPERS: ReadonlySet<string>;
|
|
7
|
+
type Meta = Record<string, unknown>;
|
|
8
|
+
/** The schema and every node under it reached through {@link META_WRAPPERS}, outermost first. */
|
|
9
|
+
export declare function wrapperChain(schema: z.ZodTypeAny): z.ZodTypeAny[];
|
|
10
|
+
/**
|
|
11
|
+
* The meta of a config field merged across its wrapper chain: an outer key wins over an inner one,
|
|
12
|
+
* except `secret` and `platformOnly`, which are true when any node of the chain carries them
|
|
13
|
+
* (fail-safe: a wrapper's meta never hides a secret or clears a platform-only mark). Zod's `id` is
|
|
14
|
+
* left out: it names one schema instance.
|
|
15
|
+
*/
|
|
16
|
+
export declare function chainMeta(schema: z.ZodTypeAny): Meta;
|
|
17
|
+
/** Sets `key: value` on the schema's meta, keeping every mark found through its wrappers. */
|
|
18
|
+
export declare function withMeta<T extends z.ZodTypeAny>(schema: T, key: string, value: unknown): T;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wrappers a config field's marks are read through: the same set the kernel's `configFields`
|
|
3
|
+
* strips and `configJsonSchema` inherits meta across.
|
|
4
|
+
*/
|
|
5
|
+
export const META_WRAPPERS = new Set([
|
|
6
|
+
"default",
|
|
7
|
+
"prefault",
|
|
8
|
+
"optional",
|
|
9
|
+
"nullable",
|
|
10
|
+
"readonly",
|
|
11
|
+
"catch",
|
|
12
|
+
]);
|
|
13
|
+
/** The schema and every node under it reached through {@link META_WRAPPERS}, outermost first. */
|
|
14
|
+
export function wrapperChain(schema) {
|
|
15
|
+
const out = [];
|
|
16
|
+
let node = schema;
|
|
17
|
+
while (node) {
|
|
18
|
+
out.push(node);
|
|
19
|
+
const def = node._zod.def;
|
|
20
|
+
node = META_WRAPPERS.has(def.type) ? def.innerType : undefined;
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The meta of a config field merged across its wrapper chain: an outer key wins over an inner one,
|
|
26
|
+
* except `secret` and `platformOnly`, which are true when any node of the chain carries them
|
|
27
|
+
* (fail-safe: a wrapper's meta never hides a secret or clears a platform-only mark). Zod's `id` is
|
|
28
|
+
* left out: it names one schema instance.
|
|
29
|
+
*/
|
|
30
|
+
export function chainMeta(schema) {
|
|
31
|
+
const out = {};
|
|
32
|
+
let secret = false;
|
|
33
|
+
let platformOnly = false;
|
|
34
|
+
for (const node of wrapperChain(schema).reverse()) {
|
|
35
|
+
const m = node.meta();
|
|
36
|
+
if (!m)
|
|
37
|
+
continue;
|
|
38
|
+
if (m.secret === true)
|
|
39
|
+
secret = true;
|
|
40
|
+
if (m.platformOnly === true)
|
|
41
|
+
platformOnly = true;
|
|
42
|
+
Object.assign(out, m);
|
|
43
|
+
}
|
|
44
|
+
delete out.id;
|
|
45
|
+
if (secret)
|
|
46
|
+
out.secret = true;
|
|
47
|
+
if (platformOnly)
|
|
48
|
+
out.platformOnly = true;
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
/** Sets `key: value` on the schema's meta, keeping every mark found through its wrappers. */
|
|
52
|
+
export function withMeta(schema, key, value) {
|
|
53
|
+
return schema.meta({ ...(schema.meta() ?? {}), ...chainMeta(schema), [key]: value });
|
|
54
|
+
}
|
package/dist/file-preview.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare const FILE_PREVIEW_MAX_BYTES: number;
|
|
|
7
7
|
/**
|
|
8
8
|
* One previewer of a `file-preview@1` provider: which files it previews and how. It renders either a
|
|
9
9
|
* view (`render`, drawn by the web app like any `UiView`) or an embed page (`embed`, the id of a ui
|
|
10
|
-
* contribution `{ kind: "embed",
|
|
10
|
+
* contribution `{ kind: "embed", slot: "file.preview" }` of the same extension, which receives the
|
|
11
11
|
* file over the message bridge). Exactly one of the two.
|
|
12
12
|
*/
|
|
13
13
|
export interface FilePreviewer {
|
|
@@ -34,14 +34,15 @@ export interface FilePreviewer {
|
|
|
34
34
|
export interface FilePreviewProvider {
|
|
35
35
|
previewers: FilePreviewer[];
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
export interface
|
|
39
|
-
orgId: string;
|
|
40
|
-
accountId: string;
|
|
41
|
-
conversationId: string;
|
|
37
|
+
/** What every {@link FilePreviewArgs} variant carries. */
|
|
38
|
+
export interface FilePreviewArgsBase {
|
|
42
39
|
locale: Locale;
|
|
43
40
|
/** Aborted at the kernel's time limit: stop reading and rendering. */
|
|
44
41
|
signal: AbortSignal;
|
|
42
|
+
/**
|
|
43
|
+
* In the share variant `file.id` is the share id; in the skill variant it is
|
|
44
|
+
* `<skillId>@<version>/<path>`.
|
|
45
|
+
*/
|
|
45
46
|
file: {
|
|
46
47
|
id: string;
|
|
47
48
|
name: string;
|
|
@@ -55,13 +56,45 @@ export interface FilePreviewArgs {
|
|
|
55
56
|
read(): Promise<Uint8Array>;
|
|
56
57
|
/**
|
|
57
58
|
* The extension's effective deployment config for this org: the platform's deployment config
|
|
58
|
-
* with the org's copy applied to the overridable fields (
|
|
59
|
-
* platform's config (equal to `ctx.config`) while the org follows it. Use it, not
|
|
60
|
-
* for work done for this org.
|
|
61
|
-
* always passes it.
|
|
59
|
+
* with the org's copy applied to the overridable fields (every field not marked `platformOnly`),
|
|
60
|
+
* or the platform's config (equal to `ctx.config`) while the org follows it. Use it, not
|
|
61
|
+
* `ctx.config`, for work done for this org.
|
|
62
62
|
*/
|
|
63
63
|
config?: unknown;
|
|
64
64
|
}
|
|
65
|
+
/** A preview inside a conversation; identities come from the kernel after authentication. */
|
|
66
|
+
export interface FilePreviewConversationArgs extends FilePreviewArgsBase {
|
|
67
|
+
source: "conversation";
|
|
68
|
+
orgId: string;
|
|
69
|
+
accountId: string;
|
|
70
|
+
conversationId: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A preview on a share page: there is no account and no conversation. A previewer that needs the
|
|
74
|
+
* conversation declines this variant by throwing; the kernel reports the failure and the page falls
|
|
75
|
+
* to the next previewer.
|
|
76
|
+
*/
|
|
77
|
+
export interface FilePreviewShareArgs extends FilePreviewArgsBase {
|
|
78
|
+
source: "share";
|
|
79
|
+
orgId: string;
|
|
80
|
+
shareId: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A file of a skill version, previewed on the skill's page: the person who opened it (`accountId`),
|
|
84
|
+
* the skill, the version and the file's path in it (a path of the version's manifest). There is no
|
|
85
|
+
* conversation. `file.id` is `<skillId>@<version>/<path>`. A previewer that needs the conversation
|
|
86
|
+
* declines this variant by throwing, as it does a share.
|
|
87
|
+
*/
|
|
88
|
+
export interface FilePreviewSkillArgs extends FilePreviewArgsBase {
|
|
89
|
+
source: "skill";
|
|
90
|
+
orgId: string;
|
|
91
|
+
accountId: string;
|
|
92
|
+
skillId: string;
|
|
93
|
+
version: number;
|
|
94
|
+
path: string;
|
|
95
|
+
}
|
|
96
|
+
/** Arguments of {@link FilePreviewer.render}: narrow on `source`. */
|
|
97
|
+
export type FilePreviewArgs = FilePreviewConversationArgs | FilePreviewShareArgs | FilePreviewSkillArgs;
|
|
65
98
|
/** Checks a `file-preview@1` provider; returns the problems (empty = valid). */
|
|
66
99
|
export declare function validateFilePreviewProvider(p: unknown): string[];
|
|
67
100
|
/** Whether a previewer takes this file: its type or extension is accepted and it is within `maxBytes`. */
|