@capybara-hq/plugin-sdk 0.1.0-rc.71 → 0.1.0-rc.73
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/dist/device-provider.d.ts +32 -4
- package/dist/device-provider.js +24 -1
- package/dist/device-service.d.ts +16 -0
- package/dist/device-service.js +16 -0
- package/dist/dial-in.d.ts +50 -3
- package/dist/dial-in.js +58 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/model.d.ts +1 -1
- package/dist/tool.d.ts +22 -0
- package/dist/tool.js +11 -0
- package/dist/ui.d.ts +14 -1
- package/package.json +1 -1
|
@@ -231,8 +231,26 @@ export declare class ProjectPathRefusedError extends Error {
|
|
|
231
231
|
}
|
|
232
232
|
/** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
|
|
233
233
|
export declare function isProjectPathRefusedError(e: unknown): e is ProjectPathRefusedError;
|
|
234
|
-
/**
|
|
234
|
+
/**
|
|
235
|
+
* A device service name as an extension declares it (`permissions.deviceAccess.services`) and
|
|
236
|
+
* names it in `ctx.deviceAccess`: 1 to 32 characters, a lower-case letter then letters, digits
|
|
237
|
+
* and `-`.
|
|
238
|
+
*/
|
|
235
239
|
export declare const DEVICE_SERVICE_NAME_RE: RegExp;
|
|
240
|
+
/**
|
|
241
|
+
* A device service id: what a device provider receives as the service's name. The kernel
|
|
242
|
+
* namespaces every extension's service names by the extension (`<extension>.<name>`,
|
|
243
|
+
* {@link deviceServiceId}), so two extensions declaring the same name never start, stop or reach
|
|
244
|
+
* each other's process; the provider keys everything of a service (its state and code
|
|
245
|
+
* directories, its socket, its process) by the id. At most 74 characters, one path segment.
|
|
246
|
+
*/
|
|
247
|
+
export declare const DEVICE_SERVICE_ID_RE: RegExp;
|
|
248
|
+
/**
|
|
249
|
+
* The device service id of an extension's service (`<extension>.<name>`,
|
|
250
|
+
* {@link DEVICE_SERVICE_ID_RE}). Throws a `TypeError` for an extension name that is not one or a
|
|
251
|
+
* service name breaking {@link DEVICE_SERVICE_NAME_RE}.
|
|
252
|
+
*/
|
|
253
|
+
export declare function deviceServiceId(extension: string, name: string): string;
|
|
236
254
|
/**
|
|
237
255
|
* A long-lived service process in a device ({@link DeviceProvider.ensureService}), started on an
|
|
238
256
|
* extension's behalf. It runs under the device's own sandbox (not under any one conversation's
|
|
@@ -243,7 +261,11 @@ export declare const DEVICE_SERVICE_NAME_RE: RegExp;
|
|
|
243
261
|
* (`device-service.ts`).
|
|
244
262
|
*/
|
|
245
263
|
export interface DeviceServiceSpec {
|
|
246
|
-
/**
|
|
264
|
+
/**
|
|
265
|
+
* One service per name per device. In `ctx.deviceAccess.ensureService` the extension's service
|
|
266
|
+
* name ({@link DEVICE_SERVICE_NAME_RE}); a provider receives the kernel's service id in its place
|
|
267
|
+
* (`<extension>.<name>`, {@link DEVICE_SERVICE_ID_RE}).
|
|
268
|
+
*/
|
|
247
269
|
name: string;
|
|
248
270
|
/** The provider supplies Node 22 or later. */
|
|
249
271
|
runtime: "node";
|
|
@@ -272,6 +294,10 @@ export interface DeviceServiceSpec {
|
|
|
272
294
|
}
|
|
273
295
|
/** A device service's state ({@link DeviceProvider.ensureService}). */
|
|
274
296
|
export interface DeviceServiceStatus {
|
|
297
|
+
/**
|
|
298
|
+
* The name the status was asked for: the service id from a provider, the extension's service
|
|
299
|
+
* name from `ctx.deviceAccess`.
|
|
300
|
+
*/
|
|
275
301
|
name: string;
|
|
276
302
|
state: "running" | "stopped";
|
|
277
303
|
/** ISO 8601 time the running process started; null when stopped. */
|
|
@@ -613,8 +639,10 @@ export interface DeviceProvider {
|
|
|
613
639
|
}[]>;
|
|
614
640
|
/**
|
|
615
641
|
* Starts the named service in the instance, or finds it running (optional, with
|
|
616
|
-
* {@link DeviceProvider.stopService} and {@link DeviceProvider.serviceRequest})
|
|
617
|
-
*
|
|
642
|
+
* {@link DeviceProvider.stopService} and {@link DeviceProvider.serviceRequest}). Every service
|
|
643
|
+
* method names the service by its id (`spec.name`, `name`, `target.service`:
|
|
644
|
+
* `<extension>.<name>`, {@link DEVICE_SERVICE_ID_RE}), never by the extension's bare name.
|
|
645
|
+
* It writes `spec.files` into the service's code directory, then runs `spec.entry` with Node, the
|
|
618
646
|
* service socket and state directory named in its environment (`DEVICE_SERVICE_SOCKET_ENV`,
|
|
619
647
|
* `DEVICE_SERVICE_STATE_ENV`). A service already running under the name is kept as is. The
|
|
620
648
|
* kernel has passed the launch through the command review before it calls this.
|
package/dist/device-provider.js
CHANGED
|
@@ -189,8 +189,31 @@ export function isProjectPathRefusedError(e) {
|
|
|
189
189
|
e.projectPathRefused === true &&
|
|
190
190
|
isRecord(e.reason));
|
|
191
191
|
}
|
|
192
|
-
/**
|
|
192
|
+
/**
|
|
193
|
+
* A device service name as an extension declares it (`permissions.deviceAccess.services`) and
|
|
194
|
+
* names it in `ctx.deviceAccess`: 1 to 32 characters, a lower-case letter then letters, digits
|
|
195
|
+
* and `-`.
|
|
196
|
+
*/
|
|
193
197
|
export const DEVICE_SERVICE_NAME_RE = /^[a-z][a-z0-9-]{0,31}$/;
|
|
198
|
+
/**
|
|
199
|
+
* A device service id: what a device provider receives as the service's name. The kernel
|
|
200
|
+
* namespaces every extension's service names by the extension (`<extension>.<name>`,
|
|
201
|
+
* {@link deviceServiceId}), so two extensions declaring the same name never start, stop or reach
|
|
202
|
+
* each other's process; the provider keys everything of a service (its state and code
|
|
203
|
+
* directories, its socket, its process) by the id. At most 74 characters, one path segment.
|
|
204
|
+
*/
|
|
205
|
+
export const DEVICE_SERVICE_ID_RE = /^[a-z][a-z0-9-]{1,40}\.[a-z][a-z0-9-]{0,31}$/;
|
|
206
|
+
/**
|
|
207
|
+
* The device service id of an extension's service (`<extension>.<name>`,
|
|
208
|
+
* {@link DEVICE_SERVICE_ID_RE}). Throws a `TypeError` for an extension name that is not one or a
|
|
209
|
+
* service name breaking {@link DEVICE_SERVICE_NAME_RE}.
|
|
210
|
+
*/
|
|
211
|
+
export function deviceServiceId(extension, name) {
|
|
212
|
+
const id = `${extension}.${name}`;
|
|
213
|
+
if (!DEVICE_SERVICE_NAME_RE.test(name) || !DEVICE_SERVICE_ID_RE.test(id))
|
|
214
|
+
throw new TypeError(`Invalid device service ${JSON.stringify(name)} of extension ${JSON.stringify(extension)}`);
|
|
215
|
+
return id;
|
|
216
|
+
}
|
|
194
217
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are exactly what must be blocked
|
|
195
218
|
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
196
219
|
/**
|
package/dist/device-service.d.ts
CHANGED
|
@@ -24,6 +24,22 @@ export declare const DEVICE_SERVICE_STATE_ENV = "CAPYBARA_SERVICE_STATE";
|
|
|
24
24
|
* it); a service confines the files it takes in (uploads) and lets out (downloads) to it.
|
|
25
25
|
*/
|
|
26
26
|
export declare const DEVICE_SERVICE_WORKSPACE_ENV = "CAPYBARA_SERVICE_WORKSPACE";
|
|
27
|
+
/**
|
|
28
|
+
* Names the service's install directory, where the provider gives it one (device-local does;
|
|
29
|
+
* absent elsewhere): a place for what the service fetches once and then only runs, such as a
|
|
30
|
+
* browser, apart from its state. The service may write it until it creates the regular file
|
|
31
|
+
* {@link DEVICE_SERVICE_INSTALL_SEAL} in it; from its next start on the directory is read only
|
|
32
|
+
* for the service, so nothing the service later runs (a compromised browser included) can
|
|
33
|
+
* replace what was installed. The provider empties it at every start that does not find it
|
|
34
|
+
* sealed under the service's current files (unsealed, or a plugin upgrade since), so a service
|
|
35
|
+
* installs afresh while unsealed and never trusts what it finds there. The process that seals
|
|
36
|
+
* keeps its write access until it exits, so a service runs no untrusted input (no web page) while
|
|
37
|
+
* unsealed, seals only a complete install and then exits; the next start, reviewed again, runs it
|
|
38
|
+
* read only.
|
|
39
|
+
*/
|
|
40
|
+
export declare const DEVICE_SERVICE_INSTALL_ENV = "CAPYBARA_SERVICE_INSTALL";
|
|
41
|
+
/** The file that seals a service's install directory ({@link DEVICE_SERVICE_INSTALL_ENV}). */
|
|
42
|
+
export declare const DEVICE_SERVICE_INSTALL_SEAL = ".sealed";
|
|
27
43
|
/** The largest message body, in bytes, either side may send on a service connection. */
|
|
28
44
|
export declare const DEVICE_SERVICE_MAX_MESSAGE: number;
|
|
29
45
|
/** The kinds a connection's first message may name. */
|
package/dist/device-service.js
CHANGED
|
@@ -24,6 +24,22 @@ export const DEVICE_SERVICE_STATE_ENV = "CAPYBARA_SERVICE_STATE";
|
|
|
24
24
|
* it); a service confines the files it takes in (uploads) and lets out (downloads) to it.
|
|
25
25
|
*/
|
|
26
26
|
export const DEVICE_SERVICE_WORKSPACE_ENV = "CAPYBARA_SERVICE_WORKSPACE";
|
|
27
|
+
/**
|
|
28
|
+
* Names the service's install directory, where the provider gives it one (device-local does;
|
|
29
|
+
* absent elsewhere): a place for what the service fetches once and then only runs, such as a
|
|
30
|
+
* browser, apart from its state. The service may write it until it creates the regular file
|
|
31
|
+
* {@link DEVICE_SERVICE_INSTALL_SEAL} in it; from its next start on the directory is read only
|
|
32
|
+
* for the service, so nothing the service later runs (a compromised browser included) can
|
|
33
|
+
* replace what was installed. The provider empties it at every start that does not find it
|
|
34
|
+
* sealed under the service's current files (unsealed, or a plugin upgrade since), so a service
|
|
35
|
+
* installs afresh while unsealed and never trusts what it finds there. The process that seals
|
|
36
|
+
* keeps its write access until it exits, so a service runs no untrusted input (no web page) while
|
|
37
|
+
* unsealed, seals only a complete install and then exits; the next start, reviewed again, runs it
|
|
38
|
+
* read only.
|
|
39
|
+
*/
|
|
40
|
+
export const DEVICE_SERVICE_INSTALL_ENV = "CAPYBARA_SERVICE_INSTALL";
|
|
41
|
+
/** The file that seals a service's install directory ({@link DEVICE_SERVICE_INSTALL_ENV}). */
|
|
42
|
+
export const DEVICE_SERVICE_INSTALL_SEAL = ".sealed";
|
|
27
43
|
/** The largest message body, in bytes, either side may send on a service connection. */
|
|
28
44
|
export const DEVICE_SERVICE_MAX_MESSAGE = 8 * 1024 * 1024;
|
|
29
45
|
/** The kinds a connection's first message may name. */
|
package/dist/dial-in.d.ts
CHANGED
|
@@ -21,7 +21,9 @@ export declare const DIAL_IN_PROTOCOL_RE: RegExp;
|
|
|
21
21
|
export declare const DIAL_IN_STREAM_INITIAL_CREDIT = 8;
|
|
22
22
|
/**
|
|
23
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`.
|
|
24
|
+
* in standard base64; the frame, like every frame, fits the connection's `maxFrameBytes`. On a
|
|
25
|
+
* connection whose hello and ready both set `binaryStreamData`, both sides send `stream-data` as
|
|
26
|
+
* a binary WebSocket message instead ({@link encodeDialInStreamData}: no base64, no JSON).
|
|
25
27
|
*/
|
|
26
28
|
export type DialInStreamFrame = {
|
|
27
29
|
type: "stream-data";
|
|
@@ -54,9 +56,14 @@ export type DialInMachineFrame = {
|
|
|
54
56
|
arch: string;
|
|
55
57
|
bootId?: string;
|
|
56
58
|
};
|
|
57
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* The largest frame, in UTF-8 bytes, the machine accepts; `binaryStreamData`: the machine
|
|
61
|
+
* sends and accepts binary `stream-data` ({@link encodeDialInStreamData}) once the kernel's
|
|
62
|
+
* ready says so too.
|
|
63
|
+
*/
|
|
58
64
|
transport: {
|
|
59
65
|
maxFrameBytes: number;
|
|
66
|
+
binaryStreamData?: true;
|
|
60
67
|
};
|
|
61
68
|
body: unknown;
|
|
62
69
|
}
|
|
@@ -89,6 +96,11 @@ export type DialInKernelFrame =
|
|
|
89
96
|
type: "ready";
|
|
90
97
|
connectionId: string;
|
|
91
98
|
maxFrameBytes: number;
|
|
99
|
+
/**
|
|
100
|
+
* Set when the machine's hello offered it: from now on both sides send `stream-data` only
|
|
101
|
+
* as binary messages ({@link encodeDialInStreamData}); every other frame stays JSON text.
|
|
102
|
+
*/
|
|
103
|
+
binaryStreamData?: true;
|
|
92
104
|
}
|
|
93
105
|
/** A provider's request ({@link DialInChannel.request}); answered by a `res` with its `id`. */
|
|
94
106
|
| {
|
|
@@ -131,6 +143,25 @@ export declare function parseDialInMachineFrame(text: string, maxBytes: number):
|
|
|
131
143
|
* that is not a positive integer throws a `RangeError`.
|
|
132
144
|
*/
|
|
133
145
|
export declare function parseDialInKernelFrame(text: string, maxBytes: number): DialInKernelFrame;
|
|
146
|
+
/** The first byte of a binary `stream-data` message (the only binary dial-in message). */
|
|
147
|
+
export declare const DIAL_IN_STREAM_DATA_TAG = 1;
|
|
148
|
+
/**
|
|
149
|
+
* One `stream-data` as a binary WebSocket message, for a connection whose hello and ready set
|
|
150
|
+
* `binaryStreamData`: the tag {@link DIAL_IN_STREAM_DATA_TAG}, the stream id's length in bytes (one
|
|
151
|
+
* byte), the id in ASCII, then the message's bytes as they are. Like every frame it must fit the
|
|
152
|
+
* connection's `maxFrameBytes` (its byte length). Throws a `RangeError` for an id that is not a
|
|
153
|
+
* dial-in id.
|
|
154
|
+
*/
|
|
155
|
+
export declare function encodeDialInStreamData(streamId: string, data: Uint8Array): Uint8Array;
|
|
156
|
+
/**
|
|
157
|
+
* Reads a binary `stream-data` message ({@link encodeDialInStreamData}); `data` is a view into
|
|
158
|
+
* `message`. Throws {@link DialInProtocolError} for anything else: another tag, a truncated
|
|
159
|
+
* header, an id that is not a dial-in id.
|
|
160
|
+
*/
|
|
161
|
+
export declare function decodeDialInStreamData(message: Uint8Array): {
|
|
162
|
+
streamId: string;
|
|
163
|
+
data: Uint8Array;
|
|
164
|
+
};
|
|
134
165
|
/**
|
|
135
166
|
* The provider's side of the dial-in channel: `DeviceProvider.dialIn`, required when the extension
|
|
136
167
|
* declares `permissions.dialIn = { protocol: "<name>/<major>" }`.
|
|
@@ -172,7 +203,10 @@ export interface DialInConnectionInfo {
|
|
|
172
203
|
export interface DialInChannel {
|
|
173
204
|
/**
|
|
174
205
|
* 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
|
|
206
|
+
* {@link DeviceOfflineError} when no machine holds the device within the reconnect grace,
|
|
207
|
+
* {@link DialInAnswerTimeoutError} when the machine stayed connected but sent no answer within
|
|
208
|
+
* `timeoutMs` plus a short margin (the outcome is unknown), and `DeviceRequestNotSentError` when
|
|
209
|
+
* the request provably never reached the machine (given up while still queued).
|
|
176
210
|
*/
|
|
177
211
|
request(deviceId: string, frame: unknown, opts: {
|
|
178
212
|
timeoutMs: number;
|
|
@@ -237,3 +271,16 @@ export declare class DeviceOfflineError extends Error {
|
|
|
237
271
|
}
|
|
238
272
|
/** Recognizes {@link DeviceOfflineError} by name and code, so another SDK copy's error matches. */
|
|
239
273
|
export declare function isDeviceOfflineError(e: unknown): e is DeviceOfflineError;
|
|
274
|
+
/**
|
|
275
|
+
* The machine stayed connected but sent no answer within the request's deadline plus a short
|
|
276
|
+
* margin (`ctx.dialIn.request`): it may have run the request, so the outcome is unknown. A cancel
|
|
277
|
+
* was queued for it.
|
|
278
|
+
*/
|
|
279
|
+
export declare class DialInAnswerTimeoutError extends Error {
|
|
280
|
+
readonly code = "device.answer_timeout";
|
|
281
|
+
constructor(deadlineMs: number, opts?: {
|
|
282
|
+
cause?: unknown;
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
/** Recognizes {@link DialInAnswerTimeoutError} by name and code, so another SDK copy's error matches. */
|
|
286
|
+
export declare function isDialInAnswerTimeoutError(e: unknown): e is DialInAnswerTimeoutError;
|
package/dist/dial-in.js
CHANGED
|
@@ -59,6 +59,7 @@ const machineFrame = z.discriminatedUnion("type", [
|
|
|
59
59
|
}),
|
|
60
60
|
transport: z.strictObject({
|
|
61
61
|
maxFrameBytes: z.number().int().min(1024).max(Number.MAX_SAFE_INTEGER),
|
|
62
|
+
binaryStreamData: z.literal(true).optional(),
|
|
62
63
|
}),
|
|
63
64
|
body,
|
|
64
65
|
}),
|
|
@@ -107,6 +108,7 @@ const kernelFrame = z.discriminatedUnion("type", [
|
|
|
107
108
|
type: z.literal("ready"),
|
|
108
109
|
connectionId: id,
|
|
109
110
|
maxFrameBytes: z.number().int().min(1024).max(Number.MAX_SAFE_INTEGER),
|
|
111
|
+
binaryStreamData: z.literal(true).optional(),
|
|
110
112
|
}),
|
|
111
113
|
z.strictObject({
|
|
112
114
|
type: z.literal("req"),
|
|
@@ -128,6 +130,44 @@ const kernelFrame = z.discriminatedUnion("type", [
|
|
|
128
130
|
export function parseDialInKernelFrame(text, maxBytes) {
|
|
129
131
|
return parseFrame(kernelFrame, text, maxBytes);
|
|
130
132
|
}
|
|
133
|
+
/** The first byte of a binary `stream-data` message (the only binary dial-in message). */
|
|
134
|
+
export const DIAL_IN_STREAM_DATA_TAG = 1;
|
|
135
|
+
/**
|
|
136
|
+
* One `stream-data` as a binary WebSocket message, for a connection whose hello and ready set
|
|
137
|
+
* `binaryStreamData`: the tag {@link DIAL_IN_STREAM_DATA_TAG}, the stream id's length in bytes (one
|
|
138
|
+
* byte), the id in ASCII, then the message's bytes as they are. Like every frame it must fit the
|
|
139
|
+
* connection's `maxFrameBytes` (its byte length). Throws a `RangeError` for an id that is not a
|
|
140
|
+
* dial-in id.
|
|
141
|
+
*/
|
|
142
|
+
export function encodeDialInStreamData(streamId, data) {
|
|
143
|
+
if (!ID_RE.test(streamId))
|
|
144
|
+
throw new RangeError(`not a dial-in stream id: ${streamId}`);
|
|
145
|
+
const out = new Uint8Array(2 + streamId.length + data.byteLength);
|
|
146
|
+
out[0] = DIAL_IN_STREAM_DATA_TAG;
|
|
147
|
+
out[1] = streamId.length;
|
|
148
|
+
for (let i = 0; i < streamId.length; i++)
|
|
149
|
+
out[2 + i] = streamId.charCodeAt(i);
|
|
150
|
+
out.set(data, 2 + streamId.length);
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Reads a binary `stream-data` message ({@link encodeDialInStreamData}); `data` is a view into
|
|
155
|
+
* `message`. Throws {@link DialInProtocolError} for anything else: another tag, a truncated
|
|
156
|
+
* header, an id that is not a dial-in id.
|
|
157
|
+
*/
|
|
158
|
+
export function decodeDialInStreamData(message) {
|
|
159
|
+
if (message.byteLength < 2 || message[0] !== DIAL_IN_STREAM_DATA_TAG)
|
|
160
|
+
throw new DialInProtocolError("binary frame is not stream-data");
|
|
161
|
+
const len = message[1];
|
|
162
|
+
if (message.byteLength < 2 + len)
|
|
163
|
+
throw new DialInProtocolError("binary stream-data is truncated");
|
|
164
|
+
let streamId = "";
|
|
165
|
+
for (let i = 0; i < len; i++)
|
|
166
|
+
streamId += String.fromCharCode(message[2 + i]);
|
|
167
|
+
if (!ID_RE.test(streamId))
|
|
168
|
+
throw new DialInProtocolError("binary stream-data has an invalid id");
|
|
169
|
+
return { streamId, data: message.subarray(2 + len) };
|
|
170
|
+
}
|
|
131
171
|
/**
|
|
132
172
|
* {@link DialInChannel.openStream} was called on a replica that does not hold the machine's
|
|
133
173
|
* socket: the caller must reach the holding gateway replica instead.
|
|
@@ -153,3 +193,21 @@ export function isDeviceOfflineError(e) {
|
|
|
153
193
|
e.name === "DeviceOfflineError" &&
|
|
154
194
|
e.code === "device.offline");
|
|
155
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* The machine stayed connected but sent no answer within the request's deadline plus a short
|
|
198
|
+
* margin (`ctx.dialIn.request`): it may have run the request, so the outcome is unknown. A cancel
|
|
199
|
+
* was queued for it.
|
|
200
|
+
*/
|
|
201
|
+
export class DialInAnswerTimeoutError extends Error {
|
|
202
|
+
code = "device.answer_timeout";
|
|
203
|
+
constructor(deadlineMs, opts) {
|
|
204
|
+
super(`The connected machine did not answer within the request's deadline of ${Math.ceil(deadlineMs / 1000)} s; the outcome is unknown, check the device and retry`, opts && "cause" in opts ? { cause: opts.cause } : undefined);
|
|
205
|
+
this.name = "DialInAnswerTimeoutError";
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/** Recognizes {@link DialInAnswerTimeoutError} by name and code, so another SDK copy's error matches. */
|
|
209
|
+
export function isDialInAnswerTimeoutError(e) {
|
|
210
|
+
return (e instanceof Error &&
|
|
211
|
+
e.name === "DialInAnswerTimeoutError" &&
|
|
212
|
+
e.code === "device.answer_timeout");
|
|
213
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/model.d.ts
CHANGED
|
@@ -69,7 +69,7 @@ export interface ModelInfo {
|
|
|
69
69
|
* Whether `document` blocks are accepted (default false). Images are governed by `vision`. When
|
|
70
70
|
* the model does not support them the kernel replaces media blocks with English text
|
|
71
71
|
* placeholders
|
|
72
|
-
* (e.g. `[Attached image "<name>" — this model cannot view images. Read with file_id <id> sends it to the organization's vision model, if one is set.]`; `text/*` documents are
|
|
72
|
+
* (e.g. `[Attached image "<name>" — this model cannot view images. If Read is available to you, Read with file_id <id> sends it to the organization's vision model, if one is set.]`; `text/*` documents are
|
|
73
73
|
* inlined as truncated text instead),
|
|
74
74
|
* and never sends the bytes to it.
|
|
75
75
|
*/
|
package/dist/tool.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ParamSchema } from "./model-params.js";
|
|
2
|
+
import type { UiOpen } from "./ui.js";
|
|
2
3
|
/** Tool annotations (hints aligned with MCP, used to derive the default policy). */
|
|
3
4
|
export interface ToolAnnotations {
|
|
4
5
|
readOnlyHint?: boolean;
|
|
@@ -47,7 +48,21 @@ export interface ToolSpec {
|
|
|
47
48
|
* {@link CONVERSATION_SOURCES}.
|
|
48
49
|
*/
|
|
49
50
|
sources?: ConversationSource[];
|
|
51
|
+
/**
|
|
52
|
+
* Extension tools only: the time limit of one call in milliseconds, a whole number from
|
|
53
|
+
* {@link TOOL_TIMEOUT_MIN_MS} to {@link TOOL_TIMEOUT_MAX_MS}. When declared, the deployment's
|
|
54
|
+
* `tools.timeoutMs` no longer applies to the tool; the deployment's `tools.maxTimeoutMs`
|
|
55
|
+
* (default {@link TOOL_TIMEOUT_MAX_MS}) cuts a longer value. Absent: `tools.timeoutMs`. Declare
|
|
56
|
+
* it when a call may legitimately take longer, e.g. one that first starts a device service
|
|
57
|
+
* (`ctx.deviceAccess.ensureService`). Never sent to the model and not part of the definition
|
|
58
|
+
* fingerprint.
|
|
59
|
+
*/
|
|
60
|
+
timeoutMs?: number;
|
|
50
61
|
}
|
|
62
|
+
/** Shortest {@link ToolSpec.timeoutMs}: one second. */
|
|
63
|
+
export declare const TOOL_TIMEOUT_MIN_MS = 1000;
|
|
64
|
+
/** Longest {@link ToolSpec.timeoutMs} the kernel accepts: ten minutes. */
|
|
65
|
+
export declare const TOOL_TIMEOUT_MAX_MS = 600000;
|
|
51
66
|
/** Longest {@link ToolSpec.title}, in code points. */
|
|
52
67
|
export declare const TOOL_TITLE_MAX = 80;
|
|
53
68
|
/** Most {@link ToolSpec.keyArgs}. */
|
|
@@ -144,6 +159,13 @@ export interface InputRequired {
|
|
|
144
159
|
kind: "input_required";
|
|
145
160
|
form: InputForm;
|
|
146
161
|
state?: unknown;
|
|
162
|
+
/**
|
|
163
|
+
* Opens a `conversation.panel` of the same extension on the asking person's open conversation
|
|
164
|
+
* page when the form is asked (e.g. the browser panel for a handoff), as a view's `open` does
|
|
165
|
+
* on a click. Display only: a target that names no panel of the extension is dropped with a
|
|
166
|
+
* warning and the form is asked as usual.
|
|
167
|
+
*/
|
|
168
|
+
open?: UiOpen;
|
|
147
169
|
}
|
|
148
170
|
export type FormAnswer = Record<string, string | number | boolean | string[]>;
|
|
149
171
|
/**
|
package/dist/tool.js
CHANGED
|
@@ -2,6 +2,10 @@ import { checkParamValue } from "./model-params.js";
|
|
|
2
2
|
import { isHttpUrl } from "./url.js";
|
|
3
3
|
/** Where a conversation comes from; a tool may limit itself to some of these. */
|
|
4
4
|
export const CONVERSATION_SOURCES = ["web", "channel_dm", "channel_group", "subagent"];
|
|
5
|
+
/** Shortest {@link ToolSpec.timeoutMs}: one second. */
|
|
6
|
+
export const TOOL_TIMEOUT_MIN_MS = 1000;
|
|
7
|
+
/** Longest {@link ToolSpec.timeoutMs} the kernel accepts: ten minutes. */
|
|
8
|
+
export const TOOL_TIMEOUT_MAX_MS = 600_000;
|
|
5
9
|
/** Longest {@link ToolSpec.title}, in code points. */
|
|
6
10
|
export const TOOL_TITLE_MAX = 80;
|
|
7
11
|
/** Most {@link ToolSpec.keyArgs}. */
|
|
@@ -107,6 +111,13 @@ export function validateToolSpec(spec) {
|
|
|
107
111
|
sources.length === 0 ||
|
|
108
112
|
sources.some((s) => !CONVERSATION_SOURCES.includes(s))))
|
|
109
113
|
out.push(`sources must be a non-empty list of ${CONVERSATION_SOURCES.join(", ")}`);
|
|
114
|
+
const timeout = spec?.timeoutMs;
|
|
115
|
+
if (timeout !== undefined &&
|
|
116
|
+
(typeof timeout !== "number" ||
|
|
117
|
+
!Number.isInteger(timeout) ||
|
|
118
|
+
timeout < TOOL_TIMEOUT_MIN_MS ||
|
|
119
|
+
timeout > TOOL_TIMEOUT_MAX_MS))
|
|
120
|
+
out.push(`timeoutMs must be a whole number of milliseconds from ${TOOL_TIMEOUT_MIN_MS} to ${TOOL_TIMEOUT_MAX_MS}`);
|
|
110
121
|
return out;
|
|
111
122
|
}
|
|
112
123
|
const SCHEMA_KEYS = {
|
package/dist/ui.d.ts
CHANGED
|
@@ -378,6 +378,18 @@ export type EmbedParentMessage = {
|
|
|
378
378
|
theme: "dark" | "light";
|
|
379
379
|
tokens: Record<string, string>;
|
|
380
380
|
}
|
|
381
|
+
/**
|
|
382
|
+
* Only to an embed in the `conversation.panel` slot: whether the conversation's right panel is
|
|
383
|
+
* maximised (`full`). Sent right after `init` and on every change, whoever made it (the embed's
|
|
384
|
+
* own `panel-mode` ask, the host's close control or Esc, a size-class change, the host refusing
|
|
385
|
+
* full mode): derive the layout from this message, not from what was asked. The panel's frame
|
|
386
|
+
* stays mounted across a change.
|
|
387
|
+
*/
|
|
388
|
+
| {
|
|
389
|
+
protocol: typeof EMBED_PROTOCOL;
|
|
390
|
+
type: "panel-mode";
|
|
391
|
+
full: boolean;
|
|
392
|
+
}
|
|
381
393
|
/**
|
|
382
394
|
* Only to a `file-preview` embed, once, after `init`: the file being previewed. The embed never
|
|
383
395
|
* gets a URL for it.
|
|
@@ -413,7 +425,8 @@ export type EmbedChildMessage =
|
|
|
413
425
|
}
|
|
414
426
|
/**
|
|
415
427
|
* Asks the host to maximise (`true`) or restore (`false`) the conversation's right panel; only an
|
|
416
|
-
* embed in the `conversation.panel` slot is honoured.
|
|
428
|
+
* embed in the `conversation.panel` slot is honoured. The host answers with its own
|
|
429
|
+
* `panel-mode` once the mode changed (it may refuse, e.g. on a phone).
|
|
417
430
|
*/
|
|
418
431
|
| {
|
|
419
432
|
protocol: typeof EMBED_PROTOCOL;
|