@capybara-hq/plugin-sdk 0.1.0-rc.52 → 0.1.0-rc.54

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.
@@ -0,0 +1,146 @@
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
+ /**
10
+ * A dial-in protocol: `<name>/<major>`, a lower-case name of 1 to 41 characters and a major
11
+ * version from 1 to 9999 (for example `capybara-device/5`). A machine's hello must name exactly
12
+ * the protocol of the provider serving its device.
13
+ */
14
+ export declare const DIAL_IN_PROTOCOL_RE: RegExp;
15
+ /** A frame from the machine. The kernel checks the envelope; `body` is the provider's. */
16
+ export type DialInMachineFrame = {
17
+ /** The first frame after the socket opens. */
18
+ type: "hello";
19
+ /** Must equal the serving provider's `permissions.dialIn.protocol`. */
20
+ protocol: string;
21
+ /** Random per run of the machine's program, the same on each of its connections. */
22
+ programRunId: string;
23
+ program: {
24
+ version: string;
25
+ os: string;
26
+ arch: string;
27
+ bootId?: string;
28
+ };
29
+ /** The largest frame, in UTF-8 bytes, the machine accepts. */
30
+ transport: {
31
+ maxFrameBytes: number;
32
+ };
33
+ body: unknown;
34
+ }
35
+ /** The answer to the kernel's `req` with the same `id`. */
36
+ | {
37
+ type: "res";
38
+ id: string;
39
+ body: unknown;
40
+ }
41
+ /** An unsolicited frame, handed to {@link DialInHandler.onFrame}. */
42
+ | {
43
+ type: "event";
44
+ body: unknown;
45
+ };
46
+ /** A frame from the kernel to the machine. */
47
+ export type DialInKernelFrame =
48
+ /**
49
+ * The kernel accepted the hello (the provider's `onHello` answered ok). `maxFrameBytes` is the
50
+ * connection's effective frame capacity: the smaller of the machine's `transport.maxFrameBytes`
51
+ * and the kernel's limit. Neither side sends a larger frame on this connection.
52
+ */
53
+ {
54
+ type: "ready";
55
+ connectionId: string;
56
+ maxFrameBytes: number;
57
+ }
58
+ /** A provider's request ({@link DialInChannel.request}); answered by a `res` with its `id`. */
59
+ | {
60
+ type: "req";
61
+ id: string;
62
+ deadlineMs: number;
63
+ body: unknown;
64
+ }
65
+ /** The kernel no longer waits for request `id` (aborted or timed out). */
66
+ | {
67
+ type: "cancel";
68
+ id: string;
69
+ }
70
+ /** The machine should finish its work and disconnect (`drain`) or stop at once (`stop`). */
71
+ | {
72
+ type: "stop";
73
+ reason: "drain" | "stop";
74
+ };
75
+ /** A machine frame that is not a valid dial-in envelope. The kernel closes the socket on it. */
76
+ export declare class DialInProtocolError extends Error {
77
+ constructor(message: string);
78
+ }
79
+ /**
80
+ * Strictly parses one machine frame: the text must be at most `maxBytes` UTF-8 bytes (checked
81
+ * before `JSON.parse`), an object of a known `type` with exactly that type's keys. `body` is kept
82
+ * as parsed, never inspected. Throws {@link DialInProtocolError}; a `maxBytes` that is not a
83
+ * positive integer throws a `RangeError`.
84
+ */
85
+ export declare function parseDialInMachineFrame(text: string, maxBytes: number): DialInMachineFrame;
86
+ /**
87
+ * The machine's side of {@link parseDialInMachineFrame}: strictly parses one kernel frame, at most
88
+ * `maxBytes` UTF-8 bytes (checked before `JSON.parse`), an object of a known `type` with exactly
89
+ * that type's keys; `body` is kept as parsed. Throws {@link DialInProtocolError}; a `maxBytes`
90
+ * that is not a positive integer throws a `RangeError`.
91
+ */
92
+ export declare function parseDialInKernelFrame(text: string, maxBytes: number): DialInKernelFrame;
93
+ /**
94
+ * The provider's side of the dial-in channel: `DeviceProvider.dialIn`, required when the extension
95
+ * declares `permissions.dialIn = { protocol: "<name>/<major>" }`.
96
+ */
97
+ export interface DialInHandler {
98
+ /** Called on the gateway replica holding the socket, after the kernel authenticated it. */
99
+ onHello(deviceId: string, hello: unknown, signal: AbortSignal): Promise<{
100
+ ok: true;
101
+ } | {
102
+ ok: false;
103
+ code: string;
104
+ message: string;
105
+ }>;
106
+ /** Unsolicited frames from the machine (not responses to requests). */
107
+ onFrame?(deviceId: string, frame: unknown): Promise<void>;
108
+ onClose?(deviceId: string, reason: "offline" | "replaced" | "revoked" | "deleted"): void;
109
+ }
110
+ /**
111
+ * `ctx.dialIn` (requires `permissions.dialIn`): talks to the machines serving this extension's
112
+ * devices. Each call checks that the device is served by the calling extension.
113
+ */
114
+ export interface DialInChannel {
115
+ /**
116
+ * Sends `frame` as the body of a `req` and resolves the body of the machine's `res`. Throws
117
+ * {@link DeviceOfflineError} when no machine holds the device within the reconnect grace.
118
+ */
119
+ request(deviceId: string, frame: unknown, opts: {
120
+ timeoutMs: number;
121
+ signal?: AbortSignal;
122
+ }): Promise<unknown>;
123
+ online(deviceId: string): Promise<boolean>;
124
+ stop(deviceId: string, reason: "drain" | "stop"): Promise<void>;
125
+ }
126
+ /**
127
+ * `ctx.devices` (requires `provides: ["device-provider@1"]`): what a device provider tells the
128
+ * kernel about its devices.
129
+ */
130
+ export interface DevicesCtx {
131
+ /**
132
+ * The device's report (`DeviceProvider.report`) or its permission support may have changed: the
133
+ * kernel reads the report again and, when its revision changed, invalidates what was approved
134
+ * against the old one.
135
+ */
136
+ reportChanged(deviceId: string): Promise<void>;
137
+ }
138
+ /** No machine serves the device (it is not connected, and did not reconnect within the grace). */
139
+ export declare class DeviceOfflineError extends Error {
140
+ readonly code = "device.offline";
141
+ constructor(deviceId: string, opts?: {
142
+ cause?: unknown;
143
+ });
144
+ }
145
+ /** Recognizes {@link DeviceOfflineError} by name and code, so another SDK copy's error matches. */
146
+ export declare function isDeviceOfflineError(e: unknown): e is DeviceOfflineError;
@@ -0,0 +1,115 @@
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/5`). 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
+ /** A machine frame that is not a valid dial-in envelope. The kernel closes the socket on it. */
17
+ export class DialInProtocolError extends Error {
18
+ constructor(message) {
19
+ super(message);
20
+ this.name = "DialInProtocolError";
21
+ }
22
+ }
23
+ /** Ids, `programRunId` and `bootId`: 1 to 128 letters, digits, `.`, `_`, `:` and `-`. */
24
+ const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
25
+ const id = z.string().regex(ID_RE);
26
+ const label = z.string().min(1).max(64);
27
+ // a frame without a body is malformed (JSON has no undefined, so this is a missing key)
28
+ const body = z.unknown().refine((v) => v !== undefined, "body is required");
29
+ const machineFrame = z.discriminatedUnion("type", [
30
+ z.strictObject({
31
+ type: z.literal("hello"),
32
+ protocol: z.string().regex(DIAL_IN_PROTOCOL_RE),
33
+ programRunId: id,
34
+ program: z.strictObject({
35
+ version: label,
36
+ os: label,
37
+ arch: label,
38
+ bootId: id.optional(),
39
+ }),
40
+ transport: z.strictObject({
41
+ maxFrameBytes: z.number().int().min(1024).max(Number.MAX_SAFE_INTEGER),
42
+ }),
43
+ body,
44
+ }),
45
+ z.strictObject({ type: z.literal("res"), id, body }),
46
+ z.strictObject({ type: z.literal("event"), body }),
47
+ ]);
48
+ /**
49
+ * Strictly parses one machine frame: the text must be at most `maxBytes` UTF-8 bytes (checked
50
+ * before `JSON.parse`), an object of a known `type` with exactly that type's keys. `body` is kept
51
+ * as parsed, never inspected. Throws {@link DialInProtocolError}; a `maxBytes` that is not a
52
+ * positive integer throws a `RangeError`.
53
+ */
54
+ export function parseDialInMachineFrame(text, maxBytes) {
55
+ return parseFrame(machineFrame, text, maxBytes);
56
+ }
57
+ function parseFrame(schema, text, maxBytes) {
58
+ if (!Number.isSafeInteger(maxBytes) || maxBytes < 1)
59
+ throw new RangeError(`maxBytes must be a positive integer, got ${maxBytes}`);
60
+ // a UTF-16 code unit is at least one UTF-8 byte: the length alone may already decide it
61
+ if (text.length > maxBytes || new TextEncoder().encode(text).byteLength > maxBytes)
62
+ throw new DialInProtocolError(`frame exceeds ${maxBytes} bytes`);
63
+ let parsed;
64
+ try {
65
+ parsed = JSON.parse(text);
66
+ }
67
+ catch {
68
+ throw new DialInProtocolError("frame is not valid JSON");
69
+ }
70
+ const r = schema.safeParse(parsed);
71
+ if (!r.success) {
72
+ const issue = r.error.issues[0];
73
+ const at = issue?.path.length ? ` at ${issue.path.join(".")}` : "";
74
+ throw new DialInProtocolError(`invalid dial-in frame${at}: ${issue?.message ?? "malformed"}`);
75
+ }
76
+ return r.data;
77
+ }
78
+ const kernelFrame = z.discriminatedUnion("type", [
79
+ z.strictObject({
80
+ type: z.literal("ready"),
81
+ connectionId: id,
82
+ maxFrameBytes: z.number().int().min(1024).max(Number.MAX_SAFE_INTEGER),
83
+ }),
84
+ z.strictObject({
85
+ type: z.literal("req"),
86
+ id,
87
+ deadlineMs: z.number().int().min(1).max(Number.MAX_SAFE_INTEGER),
88
+ body,
89
+ }),
90
+ z.strictObject({ type: z.literal("cancel"), id }),
91
+ z.strictObject({ type: z.literal("stop"), reason: z.enum(["drain", "stop"]) }),
92
+ ]);
93
+ /**
94
+ * The machine's side of {@link parseDialInMachineFrame}: strictly parses one kernel frame, at most
95
+ * `maxBytes` UTF-8 bytes (checked before `JSON.parse`), an object of a known `type` with exactly
96
+ * that type's keys; `body` is kept as parsed. Throws {@link DialInProtocolError}; a `maxBytes`
97
+ * that is not a positive integer throws a `RangeError`.
98
+ */
99
+ export function parseDialInKernelFrame(text, maxBytes) {
100
+ return parseFrame(kernelFrame, text, maxBytes);
101
+ }
102
+ /** No machine serves the device (it is not connected, and did not reconnect within the grace). */
103
+ export class DeviceOfflineError extends Error {
104
+ code = "device.offline";
105
+ constructor(deviceId, opts) {
106
+ super(`Device ${deviceId} is offline: no machine is connected for it. Reconnect the machine and retry.`, opts && "cause" in opts ? { cause: opts.cause } : undefined);
107
+ this.name = "DeviceOfflineError";
108
+ }
109
+ }
110
+ /** Recognizes {@link DeviceOfflineError} by name and code, so another SDK copy's error matches. */
111
+ export function isDeviceOfflineError(e) {
112
+ return (e instanceof Error &&
113
+ e.name === "DeviceOfflineError" &&
114
+ e.code === "device.offline");
115
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.52";
1
+ export declare const SDK_VERSION = "0.1.0-rc.54";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
@@ -14,8 +14,8 @@ export * from "./ctx.js";
14
14
  export * from "./define-extension.js";
15
15
  export { DEVICE_DEFAULT_STATE_PATH, DEVICE_DENIED_SECRET_PATHS } from "./device-denied-paths.js";
16
16
  export * from "./device-operation.js";
17
- export * from "./device-protocol.js";
18
17
  export * from "./device-provider.js";
18
+ export * from "./dial-in.js";
19
19
  export * from "./directory.js";
20
20
  export * from "./extension-point.js";
21
21
  export * from "./file-preview.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.52";
1
+ export const SDK_VERSION = "0.1.0-rc.54";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
@@ -14,8 +14,8 @@ export * from "./ctx.js";
14
14
  export * from "./define-extension.js";
15
15
  export { DEVICE_DEFAULT_STATE_PATH, DEVICE_DENIED_SECRET_PATHS } from "./device-denied-paths.js";
16
16
  export * from "./device-operation.js";
17
- export * from "./device-protocol.js";
18
17
  export * from "./device-provider.js";
18
+ export * from "./dial-in.js";
19
19
  export * from "./directory.js";
20
20
  export * from "./extension-point.js";
21
21
  export * from "./file-preview.js";
@@ -58,6 +58,15 @@ export interface ExtensionPermissions {
58
58
  * receives for the same target.
59
59
  */
60
60
  setupChecks?: string[];
61
+ /**
62
+ * The dial-in channel (`ctx.dialIn`): machines connect to the deployment and serve this
63
+ * extension's devices, speaking `protocol` (`<name>/<major>`, {@link DIAL_IN_PROTOCOL_RE}) inside
64
+ * the kernel's envelope. Only for an extension that provides `device-provider@1`; its provider
65
+ * then implements `dialIn` (`DialInHandler`).
66
+ */
67
+ dialIn?: {
68
+ protocol: string;
69
+ };
61
70
  }
62
71
  /** Hook mount points (a closed list, see the overall design 2.4). */
63
72
  export declare const HOOK_MOUNT_POINTS: readonly ["session.start", "session.end", "agent.preStep", "model.request", "model.response", "tool.preExecute", "tool.postExecute", "usage.report", "org.member_removed", "agent.deleted", "org.deleted"];
@@ -71,8 +80,11 @@ export declare class ExtensionPermissionError extends Error {
71
80
  export declare class ExtensionPointUnavailableError extends Error {
72
81
  constructor(message: string);
73
82
  }
74
- /** Validates the permission manifest and returns the list of errors (empty means valid). */
75
- export declare function validatePermissions(plugin: string, p: unknown): string[];
83
+ /**
84
+ * Validates the permission manifest and returns the list of errors (empty means valid). `provides`
85
+ * is the manifest's `provides` (`permissions.dialIn` needs `device-provider@1` in it).
86
+ */
87
+ export declare function validatePermissions(plugin: string, p: unknown, provides?: readonly string[]): string[];
76
88
  /**
77
89
  * Checks the structure of the manifest's `ui` and cross-checks it with the permission manifest;
78
90
  * returns the problems (empty = valid). Only structural problems (UI slots spec §3.2, client
@@ -1,3 +1,5 @@
1
+ import { DEVICE_PROVIDER_EXTENSION_POINT } from "./device-provider.js";
2
+ import { DIAL_IN_PROTOCOL_RE } from "./dial-in.js";
1
3
  import { POLICY_HOOKS } from "./hooks.js";
2
4
  import { HTTP_ACCESS } from "./http-access.js";
3
5
  import { SETUP_CHECK_ID_RE, SETUP_CHECK_LIMITS } from "./setup-check.js";
@@ -44,6 +46,7 @@ const KEYS = new Set([
44
46
  "ui",
45
47
  "client",
46
48
  "setupChecks",
49
+ "dialIn",
47
50
  ]);
48
51
  const POLICY = new Set(POLICY_HOOKS);
49
52
  const METHODS = new Set(["GET", "POST", "PUT", "DELETE"]);
@@ -65,8 +68,11 @@ function strList(label, v, errs) {
65
68
  }
66
69
  return out;
67
70
  }
68
- /** Validates the permission manifest and returns the list of errors (empty means valid). */
69
- export function validatePermissions(plugin, p) {
71
+ /**
72
+ * Validates the permission manifest and returns the list of errors (empty means valid). `provides`
73
+ * is the manifest's `provides` (`permissions.dialIn` needs `device-provider@1` in it).
74
+ */
75
+ export function validatePermissions(plugin, p, provides = []) {
70
76
  if (p === undefined)
71
77
  return [];
72
78
  if (!isObj(p))
@@ -198,6 +204,17 @@ export function validatePermissions(plugin, p) {
198
204
  }
199
205
  }
200
206
  }
207
+ if (p.dialIn !== undefined) {
208
+ if (!isObj(p.dialIn) ||
209
+ Object.keys(p.dialIn).some((k) => k !== "protocol") ||
210
+ typeof p.dialIn.protocol !== "string" ||
211
+ !DIAL_IN_PROTOCOL_RE.test(p.dialIn.protocol)) {
212
+ errs.push(`permissions.dialIn must be { protocol: "<name>/<major>" } matching ${DIAL_IN_PROTOCOL_RE}`);
213
+ }
214
+ if (!provides.includes(DEVICE_PROVIDER_EXTENSION_POINT)) {
215
+ errs.push(`permissions.dialIn needs "${DEVICE_PROVIDER_EXTENSION_POINT}" in provides`);
216
+ }
217
+ }
201
218
  return errs;
202
219
  }
203
220
  const UI_ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
@@ -166,15 +166,21 @@ export declare const MOBILE_SHELL_LIMITS: {
166
166
  readonly shareTitle: 256;
167
167
  readonly shareText: 4000;
168
168
  readonly url: 2048;
169
- /** `nav@1`: a section or menu label is 1..32 characters. */
169
+ /** `nav@1`: an item or action label is 1..32 characters. */
170
170
  readonly navLabel: 32;
171
171
  /** `nav@1`: a badge count is an integer 0..9999 (`countMore` says there are more). */
172
172
  readonly navCount: 9999;
173
+ /** `nav@1`: the account's name is 1..64 characters (its initial 1..2). */
174
+ readonly navAccountName: 64;
173
175
  };
174
176
  /** The menu item id pattern, checked on `menu@1.show` (the shell validates every input). */
175
177
  export declare const MENU_ITEM_ID: RegExp;
176
- export type NavSectionId = "chats" | "inbox" | "agents" | "schedules";
177
- /** The strip's sections in display order. */
178
+ /**
179
+ * The strip's items: the four sections and, last, `search` (opens the web's command palette; never
180
+ * `current`).
181
+ */
182
+ export type NavSectionId = "chats" | "inbox" | "agents" | "schedules" | "search";
183
+ /** The strip's items in display order. */
178
184
  export declare const NAV_SECTION_ORDER: readonly NavSectionId[];
179
185
  export interface NavBadgeV1 {
180
186
  count?: number;
@@ -184,21 +190,53 @@ export interface NavItemV1 extends NavBadgeV1 {
184
190
  id: NavSectionId;
185
191
  label: string;
186
192
  }
187
- export interface NavMenuV1 extends NavBadgeV1 {
193
+ /**
194
+ * The pill's top item, accent-filled: the page's primary action, else the new conversation
195
+ * (`id` matches MENU_ITEM_ID, `label` 1..navLabel; the shell draws its own glyph per `icon`).
196
+ */
197
+ export interface NavActionV1 {
198
+ id: string;
188
199
  label: string;
200
+ icon: "plus" | "square-pen";
201
+ }
202
+ /**
203
+ * The account avatar under the strip's status: the image at `avatarUrl` (an absolute https URL
204
+ * or one on the profile's origin), else `initial` in a circle; `badge` a count 0..navCount.
205
+ */
206
+ export interface NavAccountV1 {
207
+ name: string;
208
+ avatarUrl?: string | null;
209
+ initial: string;
210
+ badge?: number;
189
211
  }
190
212
  export interface NavStateV1 {
191
- /** The sections the person sees, in NAV_SECTION_ORDER (a guest has no `schedules`). */
213
+ /** The items the person sees, in NAV_SECTION_ORDER (a guest has no `schedules`). */
192
214
  items: NavItemV1[];
215
+ /**
216
+ * The section of the page on screen; `null`: no section is selected and the shell clears its
217
+ * highlight (the new-conversation home, a page outside the sections). Never `search`.
218
+ */
193
219
  current: NavSectionId | null;
194
- /** The strip's menu button, or null for none (non-null while the web's class is compact). */
195
- menu: NavMenuV1 | null;
220
+ /** The pill's top item: the page's primary, else the new conversation (no menu button, D12). */
221
+ action: NavActionV1;
222
+ /** The avatar under the status (absent: the shell shows none). */
223
+ account?: NavAccountV1;
196
224
  }
197
- /** `nav@1`: offered only while the window has a strip (mobile app spec §6.1): presence is visibility. */
225
+ /**
226
+ * `nav@1`: offered only while the window has a strip (mobile app spec §6.1): presence is
227
+ * visibility. `side` is the edge the strip is on (right unless the app is the left one of a
228
+ * split), reported with the capability and updated with the envelope's `change`. The shell and
229
+ * the web ship this shape in lockstep (no older-shell path before 0.1.0): the shell's nav@1
230
+ * minor version of 2026-11-22 ships with or before the web that sends it.
231
+ */
198
232
  export interface NavCapabilityV1 {
199
233
  set(state: NavStateV1): Promise<void>;
200
234
  onSelect(listener: (id: NavSectionId) => void): () => void;
201
- onMenu(listener: () => void): () => void;
235
+ /** The pill's top item was tapped: the web runs the action. */
236
+ onAction(listener: () => void): () => void;
237
+ /** The account avatar was tapped: the web opens its account sheet. */
238
+ onAccount(listener: () => void): () => void;
239
+ readonly side?: "left" | "right";
202
240
  }
203
241
  /** `profiles@1`: the native profile switcher. */
204
242
  export interface ProfilesCapabilityV1 {
@@ -26,12 +26,20 @@ export const MOBILE_SHELL_LIMITS = {
26
26
  shareTitle: 256,
27
27
  shareText: 4000,
28
28
  url: 2048,
29
- /** `nav@1`: a section or menu label is 1..32 characters. */
29
+ /** `nav@1`: an item or action label is 1..32 characters. */
30
30
  navLabel: 32,
31
31
  /** `nav@1`: a badge count is an integer 0..9999 (`countMore` says there are more). */
32
32
  navCount: 9999,
33
+ /** `nav@1`: the account's name is 1..64 characters (its initial 1..2). */
34
+ navAccountName: 64,
33
35
  };
34
36
  /** The menu item id pattern, checked on `menu@1.show` (the shell validates every input). */
35
37
  export const MENU_ITEM_ID = /^[A-Za-z0-9_.-]{1,64}$/;
36
- /** The strip's sections in display order. */
37
- export const NAV_SECTION_ORDER = ["chats", "inbox", "agents", "schedules"];
38
+ /** The strip's items in display order. */
39
+ export const NAV_SECTION_ORDER = [
40
+ "chats",
41
+ "inbox",
42
+ "agents",
43
+ "schedules",
44
+ "search",
45
+ ];
@@ -0,0 +1,10 @@
1
+ /** Characters of a viewBox value; longer values are refused before any regex sees them. */
2
+ export declare const VIEWBOX_MAX_CHARS = 128;
3
+ /**
4
+ * The only regexes the viewBox parser runs. Each is one character class under one quantifier,
5
+ * so matching is linear in the (already capped) input: there is nothing to backtrack into.
6
+ */
7
+ export declare const VIEWBOX_SEPARATOR_RE: RegExp;
8
+ export declare const VIEWBOX_NUMBER_RE: RegExp;
9
+ /** `min-x min-y width height`, width and height > 0; undefined when malformed. */
10
+ export declare function parseViewBox(v: string): [number, number, number, number] | undefined;
@@ -0,0 +1,24 @@
1
+ // Internal to the SDK: not re-exported from index.ts, so not part of the public API.
2
+ /** Characters of a viewBox value; longer values are refused before any regex sees them. */
3
+ export const VIEWBOX_MAX_CHARS = 128;
4
+ /**
5
+ * The only regexes the viewBox parser runs. Each is one character class under one quantifier,
6
+ * so matching is linear in the (already capped) input: there is nothing to backtrack into.
7
+ */
8
+ export const VIEWBOX_SEPARATOR_RE = /[\s,]+/;
9
+ export const VIEWBOX_NUMBER_RE = /^[-+.0-9eE]+$/;
10
+ /** `min-x min-y width height`, width and height > 0; undefined when malformed. */
11
+ export function parseViewBox(v) {
12
+ if (v.length > VIEWBOX_MAX_CHARS)
13
+ return undefined;
14
+ const parts = v
15
+ .trim()
16
+ .split(VIEWBOX_SEPARATOR_RE)
17
+ .filter((p) => p !== "");
18
+ if (parts.length !== 4 || !parts.every((p) => VIEWBOX_NUMBER_RE.test(p)))
19
+ return undefined;
20
+ const n = parts.map(Number);
21
+ if (!n.every(Number.isFinite) || n[2] <= 0 || n[3] <= 0)
22
+ return undefined;
23
+ return n;
24
+ }
@@ -1,5 +1,6 @@
1
1
  import { SaxesParser } from "saxes";
2
2
  import { isSafePackagePath } from "./plugin-package.js";
3
+ import { parseViewBox } from "./svg-viewbox.js";
3
4
  import { THEME_LIMITS } from "./theme.js";
4
5
  /**
5
6
  * Checks of a theme's asset files (themes spec §4.2-§4.4, theme brand coverage spec §1): woff2
@@ -80,10 +81,6 @@ const SVG_ELEMENTS = new Set([
80
81
  const XML_ATTRS = new Set(["space", "lang"]);
81
82
  /** Root attributes dropped: the design system sizes the logo to its slot. */
82
83
  const ROOT_DROPPED = new Set(["width", "height", "class"]);
83
- /** Characters of a viewBox value; longer values are refused before they are split. */
84
- const VIEWBOX_MAX_CHARS = 128;
85
- /** Characters a viewBox number may use (checked per character class, no backtracking). */
86
- const VIEWBOX_NUMBER_RE = /^[-+.0-9eE]+$/;
87
84
  /**
88
85
  * The only functions an attribute value may call: colors and transforms. `url` is allowed only as
89
86
  * `url(#id)` (checked separately); everything else (`image-set`, `cross-fade`, `element`,
@@ -151,21 +148,6 @@ function checkValue(el, attr, value) {
151
148
  }
152
149
  }
153
150
  }
154
- /** `min-x min-y width height`, width and height > 0; undefined when malformed. */
155
- function parseViewBox(v) {
156
- if (v.length > VIEWBOX_MAX_CHARS)
157
- return undefined;
158
- const parts = v
159
- .trim()
160
- .split(/[\s,]+/)
161
- .filter((p) => p !== "");
162
- if (parts.length !== 4 || !parts.every((p) => VIEWBOX_NUMBER_RE.test(p)))
163
- return undefined;
164
- const n = parts.map(Number);
165
- if (!n.every(Number.isFinite) || n[2] <= 0 || n[3] <= 0)
166
- return undefined;
167
- return n;
168
- }
169
151
  /** The serialized attributes of an allowed SVG element; rejects the forbidden ones. */
170
152
  function attributesOf(tag, isRoot, usesXlink) {
171
153
  const el = tag.local;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.52",
3
+ "version": "0.1.0-rc.54",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -19,6 +19,11 @@
19
19
  "import": "./dist/index.js",
20
20
  "default": "./dist/index.js"
21
21
  },
22
+ "./device-protocol": {
23
+ "types": "./dist/device-protocol.d.ts",
24
+ "import": "./dist/device-protocol.js",
25
+ "default": "./dist/device-protocol.js"
26
+ },
22
27
  "./package.json": "./package.json"
23
28
  },
24
29
  "files": [
@@ -71,6 +71,13 @@
71
71
  "builtin": {
72
72
  "type": "boolean"
73
73
  },
74
+ "scope": {
75
+ "type": "string",
76
+ "enum": [
77
+ "all",
78
+ "optional"
79
+ ]
80
+ },
74
81
  "source": {
75
82
  "type": "string",
76
83
  "const": "npm"
@@ -112,6 +119,13 @@
112
119
  "builtin": {
113
120
  "type": "boolean"
114
121
  },
122
+ "scope": {
123
+ "type": "string",
124
+ "enum": [
125
+ "all",
126
+ "optional"
127
+ ]
128
+ },
115
129
  "source": {
116
130
  "type": "string",
117
131
  "const": "git"
@@ -58,6 +58,13 @@
58
58
  "builtin": {
59
59
  "type": "boolean"
60
60
  },
61
+ "scope": {
62
+ "type": "string",
63
+ "enum": [
64
+ "all",
65
+ "optional"
66
+ ]
67
+ },
61
68
  "source": {
62
69
  "type": "string",
63
70
  "const": "npm"
@@ -100,6 +107,13 @@
100
107
  "builtin": {
101
108
  "type": "boolean"
102
109
  },
110
+ "scope": {
111
+ "type": "string",
112
+ "enum": [
113
+ "all",
114
+ "optional"
115
+ ]
116
+ },
103
117
  "source": {
104
118
  "type": "string",
105
119
  "const": "workspace"