@capybara-hq/plugin-sdk 0.1.0-rc.70 → 0.1.0-rc.72

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  <!-- generated:extension-point -->
4
4
  - Name: `file-preview` (a ref is `file-preview@<major>`)
5
- - Renders previews of files of given types in the conversation UI.
5
+ - Renders previews of files of given types: conversation files, shared files and skill files.
6
6
  - Providers: several
7
7
  - Enabled per org: yes
8
8
  - Brokered by the platform: no
@@ -12,6 +12,6 @@ Contract: FilePreviewProvider (`file-preview.ts`)
12
12
 
13
13
  Declare which file types you can preview and render them through schema views or an approved embed. Enabled per org.
14
14
 
15
- `render` args are a union on `source`: `"conversation"` (org, account, conversation) or `"share"` (org and share id; `file.id` is the share id; no account or conversation). A previewer that needs the conversation declines `source: "share"` by throwing; the kernel reports the failure and the share page falls to the next previewer. A share token is valid only for the `file.preview` slot, never for `/api`.
15
+ `render` args are a union on `source`: `"conversation"` (org, account, conversation), `"share"` (org and share id; `file.id` is the share id; no account or conversation) or `"skill"` (a skill version's file on the skill page: org, account, `skillId`, `version` and `path`; `file.id` is `<skillId>@<version>/<path>`; no conversation). An embed previewer of a skill file gets an org token whose claims carry `skillFile: { skillId, version, path }` instead of `conversationId` / `fileId`; that token reaches every `embed` route of the extension, so an embed route must not treat an org caller without `conversationId` as entitled to conversation data, and should serve a `caller.skillFile` caller only that file. A previewer that needs the conversation declines any `source` other than `"conversation"` by throwing; the kernel reports the failure and the page (a share page, a skill page) falls to the next previewer. A share token is valid only for the `file.preview` slot, never for `/api`.
16
16
 
17
17
  See `extensions` for the rules every extension follows.
@@ -125,7 +125,7 @@ look like `channel@1`: name and major version. The registered points:
125
125
  | `directory` | multi | yes | Syncs members and departments from an external company directory. |
126
126
  | `counter` | multi | no | Counts usage so quotas and reports can be built on it. |
127
127
  | `connector` | multi | no | Speaks one protocol (MCP, OpenAPI) to external systems and exposes their tools to agents. |
128
- | `file-preview` | multi | yes | Renders previews of files of given types in the conversation UI. |
128
+ | `file-preview` | multi | yes | Renders previews of files of given types: conversation files, shared files and skill files. |
129
129
  | `web-search` | multi | yes | Searches the web for the WebSearch tool; each org picks a default provider. |
130
130
  | `context` | multi | yes | Adds text to the model's context at run start in conversations of orgs that enable it. |
131
131
  | `web-fetch` | multi | yes | Fetches and extracts web pages for the WebFetch tool; each org picks a default provider. |
@@ -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
- /** A device service name: 1 to 32 characters, a lower-case letter then letters, digits and `-`. */
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
- /** One service per name per device; matches {@link DEVICE_SERVICE_NAME_RE}. */
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}): writes
617
- * `spec.files` into the service's code directory, then runs `spec.entry` with Node, the
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.
@@ -189,8 +189,31 @@ export function isProjectPathRefusedError(e) {
189
189
  e.projectPathRefused === true &&
190
190
  isRecord(e.reason));
191
191
  }
192
- /** A device service name: 1 to 32 characters, a lower-case letter then letters, digits and `-`. */
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
  /**
@@ -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. */
@@ -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
- /** The largest frame, in UTF-8 bytes, the machine accepts. */
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
+ }
@@ -18,7 +18,7 @@ export const EXTENSION_POINTS = {
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 in the conversation UI.", "multi", false, true),
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
23
  context: info([1], "Adds text to the model's context at run start in conversations of orgs that enable it.", "multi", true, true),
24
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"),
@@ -39,7 +39,10 @@ export interface FilePreviewArgsBase {
39
39
  locale: Locale;
40
40
  /** Aborted at the kernel's time limit: stop reading and rendering. */
41
41
  signal: AbortSignal;
42
- /** In the share variant `file.id` is the share id. */
42
+ /**
43
+ * In the share variant `file.id` is the share id; in the skill variant it is
44
+ * `<skillId>@<version>/<path>`.
45
+ */
43
46
  file: {
44
47
  id: string;
45
48
  name: string;
@@ -76,8 +79,22 @@ export interface FilePreviewShareArgs extends FilePreviewArgsBase {
76
79
  orgId: string;
77
80
  shareId: string;
78
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
+ }
79
96
  /** Arguments of {@link FilePreviewer.render}: narrow on `source`. */
80
- export type FilePreviewArgs = FilePreviewConversationArgs | FilePreviewShareArgs;
97
+ export type FilePreviewArgs = FilePreviewConversationArgs | FilePreviewShareArgs | FilePreviewSkillArgs;
81
98
  /** Checks a `file-preview@1` provider; returns the problems (empty = valid). */
82
99
  export declare function validateFilePreviewProvider(p: unknown): string[];
83
100
  /** Whether a previewer takes this file: its type or extension is accepted and it is within `maxBytes`. */
@@ -32,6 +32,15 @@ export type RouteCaller = {
32
32
  role: UiRole;
33
33
  contribution: string;
34
34
  conversationId?: string;
35
+ /**
36
+ * A skill file previewer's token (`OrgEmbedClaims.skillFile`): the skill, version and path;
37
+ * no conversation.
38
+ */
39
+ skillFile?: {
40
+ skillId: string;
41
+ version: number;
42
+ path: string;
43
+ };
35
44
  /** The token's expiry (Unix seconds): a long-lived response (SSE) ends by then. */
36
45
  exp: number;
37
46
  config: unknown;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.70";
1
+ export declare const SDK_VERSION = "0.1.0-rc.72";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.70";
1
+ export const SDK_VERSION = "0.1.0-rc.72";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
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
@@ -295,6 +295,15 @@ export interface OrgEmbedClaims extends EmbedClaimsBase {
295
295
  agentId?: string;
296
296
  /** Only a `file-preview` embed's token: the one file (of `conversationId`) it previews. */
297
297
  fileId?: string;
298
+ /**
299
+ * Only a `file-preview` embed's token for a skill file (no `conversationId`, `agentId` or
300
+ * `fileId`): the skill, the version and the file's path in it.
301
+ */
302
+ skillFile?: {
303
+ skillId: string;
304
+ version: number;
305
+ path: string;
306
+ };
298
307
  }
299
308
  /** A `platform.page` embed token's claims: a super admin's, with no org, conversation, agent or file. */
300
309
  export interface PlatformEmbedClaims extends EmbedClaimsBase {
@@ -305,6 +314,7 @@ export interface PlatformEmbedClaims extends EmbedClaimsBase {
305
314
  conversationId?: undefined;
306
315
  agentId?: undefined;
307
316
  fileId?: undefined;
317
+ skillFile?: undefined;
308
318
  }
309
319
  /**
310
320
  * A share page's `file.preview` embed token's claims: no account and no role, only the org, the
@@ -320,6 +330,7 @@ export interface ShareEmbedClaims extends EmbedClaimsBase {
320
330
  conversationId?: undefined;
321
331
  agentId?: undefined;
322
332
  fileId?: undefined;
333
+ skillFile?: undefined;
323
334
  }
324
335
  /**
325
336
  * Claims in an embed token (trustworthy after validation by `ctx.ui.verifyEmbedToken`): narrow on
@@ -367,6 +378,18 @@ export type EmbedParentMessage = {
367
378
  theme: "dark" | "light";
368
379
  tokens: Record<string, string>;
369
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
+ }
370
393
  /**
371
394
  * Only to a `file-preview` embed, once, after `init`: the file being previewed. The embed never
372
395
  * gets a URL for it.
@@ -402,7 +425,8 @@ export type EmbedChildMessage =
402
425
  }
403
426
  /**
404
427
  * Asks the host to maximise (`true`) or restore (`false`) the conversation's right panel; only an
405
- * 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).
406
430
  */
407
431
  | {
408
432
  protocol: typeof EMBED_PROTOCOL;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.70",
3
+ "version": "0.1.0-rc.72",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {