@capybara-hq/plugin-sdk 0.1.0-rc.82 → 0.1.0-rc.84

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.
@@ -14,4 +14,6 @@ Map the kernel's messages and tools to the vendor API and stream the result. Do
14
14
 
15
15
  Messages may carry an `image` or a `document` block, gated by `capabilities.vision` and `capabilities.documents`; the kernel replaces a block the model cannot take with an English placeholder and never sends the bytes. A `file` block is an attachment the model can only reference (an xlsx, say): the kernel resolves it to text before the request, so a provider never receives one. Resolve any block you do not recognize by skipping it. The `size` on an attachment block is display metadata (the UI chip, the reference line) and is never sent to a provider.
16
16
 
17
+ Declare each model's prompt cache in `ModelInfo.cache` (absent = mechanism `none`; it must pass `validateModelCache`): the `mechanism` (`explicit` breakpoints, `implicit` service caching, `none`), the lifetimes a request can choose in seconds (`ttlOptions`, ascending; empty when the service decides alone), `defaultTtl` (required and one of `ttlOptions` when `ttlOptions` is non-empty), `ttlIsMinimum`, `refreshOnHit` (true only if a hit refreshes the lifetime of every tier the kernel may select; the kernel selects only `defaultTtl` or the smallest option of at least 1800 s, so OpenAI GPT-5.6+ declares true: its 30m tier refreshes, its 12h tier does not and is never selected; when unconfirmed, declare false), `ttlClock`, `minTokens` and `guaranteed` (a hit on an unchanged prefix within the lifetime is expected, not best-effort). `ModelRequest.cacheTtl` is one of the model's `ttlOptions` (the kernel sends no other value): map it to the vendor's field (`cache_control.ttl`, `prompt_cache_options.ttl`), and ignore it for a model without options. When the vendor reports writes per lifetime tier, report them in `ModelUsage.cacheWriteByTtl` (`{ ttl, tokens }[]`, summing to `cacheWriteTokens`; `validateCacheWriteByTtl`).
18
+
17
19
  See `extensions` for the rules every extension follows.
package/dist/cards.d.ts CHANGED
@@ -39,8 +39,12 @@ export type ChannelCard = {
39
39
  kind: "question";
40
40
  id: string;
41
41
  form: InputForm;
42
- /** `skipped`: the person sent a message instead of answering (the run went on with it). */
43
- state: "pending" | "answered" | "skipped" | "expired" | "cancelled";
42
+ /**
43
+ * `skipped`: the person sent a message instead of answering (the run went on with it).
44
+ * `woken`: a watched wait the tool's watcher ended (the condition it waited for held, or the
45
+ * wait could no longer be watched); nobody answered.
46
+ */
47
+ state: "pending" | "answered" | "skipped" | "expired" | "cancelled" | "woken";
44
48
  answerSummary?: string;
45
49
  webUrl: string;
46
50
  /**
package/dist/cards.js CHANGED
@@ -56,7 +56,14 @@ const APPROVAL_STATES = [
56
56
  "skipped",
57
57
  ];
58
58
  const MAX_SCOPE_LABEL = 40;
59
- const QUESTION_STATES = ["pending", "answered", "skipped", "expired", "cancelled"];
59
+ const QUESTION_STATES = [
60
+ "pending",
61
+ "answered",
62
+ "skipped",
63
+ "expired",
64
+ "cancelled",
65
+ "woken",
66
+ ];
60
67
  const TEXT_REPLY = ["plain", "mention"];
61
68
  const ISO_8601 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
62
69
  const list = (xs) => xs.map((x) => JSON.stringify(x)).join(", ");
@@ -224,6 +231,7 @@ const TEXT = {
224
231
  skipped: "Skipped (replied instead)",
225
232
  expired: "Expired",
226
233
  cancelled: "Cancelled",
234
+ woken: "Wait ended",
227
235
  },
228
236
  textReply: {
229
237
  plain: "You can also just reply with text",
@@ -262,6 +270,7 @@ const TEXT = {
262
270
  skipped: "已跳过(已直接回复)",
263
271
  expired: "已过期",
264
272
  cancelled: "已取消",
273
+ woken: "等待已结束",
265
274
  },
266
275
  textReply: {
267
276
  plain: "也可以直接回复文字",
package/dist/ctx.d.ts CHANGED
@@ -8,7 +8,7 @@ import type { ImageAspectRatio, ImageMediaType, ImageSize, ModelEmbeddingInfo, M
8
8
  import type { ExtensionNet } from "./net.js";
9
9
  import type { SetupCheckDefinition } from "./setup-check.js";
10
10
  import type { ObjectHead, PresignedUpload, PresignGetOptions } from "./storage.js";
11
- import type { ToolCallContext, ToolHandler, ToolSpec } from "./tool.js";
11
+ import type { ToolCallContext, ToolHandler, ToolSpec, ToolWatcher } from "./tool.js";
12
12
  import type { EmbedClaims, UiActionArgs, UiActionResult, UiRenderArgs, UiView } from "./ui.js";
13
13
  /** Logger interface. */
14
14
  export interface Logger {
@@ -195,11 +195,17 @@ export interface DeviceAccessCtx {
195
195
  * closed) and starts it through the device's provider.
196
196
  */
197
197
  ensureService(call: ToolCallContext, spec: DeviceServiceSpec): Promise<DeviceServiceStatus>;
198
- /** One request to the service's socket; resolves its answer. */
198
+ /**
199
+ * One request to the service's socket; resolves its answer. `ifRunning`: only a running
200
+ * instance with the service running answers, otherwise {@link DeviceAccessError}
201
+ * `not_running`; nothing is resumed or started (a running instance's last use is refreshed). A
202
+ * watcher's requests ({@link ToolWatcher}) always run so.
203
+ */
199
204
  request(call: ToolCallContext, req: {
200
205
  service: string;
201
206
  body: Uint8Array;
202
207
  timeoutMs: number;
208
+ ifRunning?: boolean;
203
209
  }): Promise<Uint8Array>;
204
210
  /**
205
211
  * The service saw requests to `hosts` refused by the device's network during this call, each
@@ -249,7 +255,9 @@ export interface DeviceAccessCtx {
249
255
  }): Promise<void>;
250
256
  }
251
257
  /** Why a {@link DeviceAccessCtx} call was refused. */
252
- export type DeviceAccessErrorCode = "no_device" | "provider_unavailable" | "capability_missing" | "not_owner" | "service_not_declared";
258
+ export type DeviceAccessErrorCode = "no_device" | "provider_unavailable" | "capability_missing" | "not_owner" | "service_not_declared"
259
+ /** An `ifRunning` request found the device's instance or the service not running. */
260
+ | "not_running";
253
261
  /** A {@link DeviceAccessCtx} call was refused; the message is actionable English for the model. */
254
262
  export declare class DeviceAccessError extends Error {
255
263
  readonly code: DeviceAccessErrorCode;
@@ -314,8 +322,13 @@ export interface ExtensionContext {
314
322
  route(method: "GET" | "POST" | "PUT" | "DELETE", path: string, handler: (req: Request, caller: RouteCaller) => Promise<Response>): void;
315
323
  };
316
324
  tools: {
317
- /** Registers a tool; callable only during `setup`, names must not repeat. */
318
- register(spec: ToolSpec, handler: ToolHandler): void;
325
+ /**
326
+ * Registers a tool; callable only during `setup`, names must not repeat. `opts.watch`: the
327
+ * tool's watcher for watched waits (`InputRequired.watch`, see {@link ToolWatcher}).
328
+ */
329
+ register(spec: ToolSpec, handler: ToolHandler, opts?: {
330
+ watch?: ToolWatcher;
331
+ }): void;
319
332
  };
320
333
  /**
321
334
  * Consume extension points provided by other extensions: only non-brokered refs declared in the
@@ -25,6 +25,10 @@
25
25
  * ({@link parseViewerContext}); a later message of the same shape comes from the panel and is
26
26
  * never context. Providers and the device program pass the viewer context through like any
27
27
  * stream message.
28
+ *
29
+ * **Kernel requests.** Besides the extension's own requests (`ctx.deviceAccess.request`), the
30
+ * kernel sends two request bodies of its own: the roll check ({@link DEVICE_SERVICE_ROLL_CHECK})
31
+ * and the conversation-deleted notice ({@link encodeConversationDeleted}).
28
32
  */
29
33
  /**
30
34
  * The request body the kernel sends a running service before restarting it on new files (an
@@ -47,6 +51,40 @@ export interface DeviceServiceRollCheck {
47
51
  export declare function isRollCheck(body: Uint8Array | string): boolean;
48
52
  /** Reads a service's answer to the roll check: busy only for `{"busy":true}` (never throws). */
49
53
  export declare function parseRollCheck(body: Uint8Array | string): DeviceServiceRollCheck;
54
+ /**
55
+ * How long a service may restore state it saved (after a restart, or when its device resumes):
56
+ * state saved longer ago than this is not restored. The kernel keeps a
57
+ * {@link encodeConversationDeleted} notice owed for at least this long after the deletion while
58
+ * the service is not running, so a service that restores within it still learns of the deletion.
59
+ */
60
+ export declare const DEVICE_SERVICE_RESTORE_MAX_AGE_MS: number;
61
+ /**
62
+ * The kernel's notice that a conversation was deleted: a request body the kernel sends every
63
+ * running service of an extension on the deleted conversation's device, at least once, soon after
64
+ * the deletion (a device that is offline gets it when it is back; a service that is stopped gets
65
+ * it when it runs again within {@link DEVICE_SERVICE_RESTORE_MAX_AGE_MS}). The kernel builds it
66
+ * from the deleted conversation's id. It arrives on a **request** connection only: a stream
67
+ * message of this shape is a viewer's (panel) input and never the notice, so a service parses it
68
+ * only on request connections. As with the roll check, the extension's own requests
69
+ * (`ctx.deviceAccess.request`) reach the same connection kind: a body of this shape sent by the
70
+ * extension is the extension's to answer for. The service forgets what it keeps for that
71
+ * conversation and for the conversations whose tree root it is (closes their pages, drops their
72
+ * state; never shared data such as a browser profile) and answers with any message: the kernel
73
+ * reads no more than that it answered. Handling it twice must be harmless. A service that does
74
+ * not know it ignores it, as any unknown body.
75
+ */
76
+ export interface DeviceServiceConversationDeleted {
77
+ capybara: "conversation-deleted";
78
+ conversationId: string;
79
+ }
80
+ /** The body of the kernel's conversation-deleted notice (UTF-8 JSON; the provider frames it). */
81
+ export declare function encodeConversationDeleted(conversationId: string): Uint8Array;
82
+ /**
83
+ * Reads a request body as the kernel's conversation-deleted notice: `capybara` is
84
+ * `"conversation-deleted"` and `conversationId` a non-empty string. Null for anything else (not
85
+ * UTF-8, not JSON, another shape, the roll check); never throws.
86
+ */
87
+ export declare function parseConversationDeleted(body: Uint8Array | string): DeviceServiceConversationDeleted | null;
50
88
  /** Names the unix socket path the service listens on. */
51
89
  export declare const DEVICE_SERVICE_SOCKET_ENV = "CAPYBARA_SERVICE_SOCKET";
52
90
  /** Names the service's state directory (its own data, its write root; not where its code is). */
@@ -25,6 +25,10 @@
25
25
  * ({@link parseViewerContext}); a later message of the same shape comes from the panel and is
26
26
  * never context. Providers and the device program pass the viewer context through like any
27
27
  * stream message.
28
+ *
29
+ * **Kernel requests.** Besides the extension's own requests (`ctx.deviceAccess.request`), the
30
+ * kernel sends two request bodies of its own: the roll check ({@link DEVICE_SERVICE_ROLL_CHECK})
31
+ * and the conversation-deleted notice ({@link encodeConversationDeleted}).
28
32
  */
29
33
  /**
30
34
  * The request body the kernel sends a running service before restarting it on new files (an
@@ -63,6 +67,42 @@ export function parseRollCheck(body) {
63
67
  }
64
68
  return { busy: false };
65
69
  }
70
+ /**
71
+ * How long a service may restore state it saved (after a restart, or when its device resumes):
72
+ * state saved longer ago than this is not restored. The kernel keeps a
73
+ * {@link encodeConversationDeleted} notice owed for at least this long after the deletion while
74
+ * the service is not running, so a service that restores within it still learns of the deletion.
75
+ */
76
+ export const DEVICE_SERVICE_RESTORE_MAX_AGE_MS = 10 * 60_000;
77
+ /** The body of the kernel's conversation-deleted notice (UTF-8 JSON; the provider frames it). */
78
+ export function encodeConversationDeleted(conversationId) {
79
+ if (typeof conversationId !== "string" || conversationId === "")
80
+ throw new TypeError("encodeConversationDeleted needs a conversation id");
81
+ return new TextEncoder().encode(JSON.stringify({ capybara: "conversation-deleted", conversationId }));
82
+ }
83
+ /**
84
+ * Reads a request body as the kernel's conversation-deleted notice: `capybara` is
85
+ * `"conversation-deleted"` and `conversationId` a non-empty string. Null for anything else (not
86
+ * UTF-8, not JSON, another shape, the roll check); never throws.
87
+ */
88
+ export function parseConversationDeleted(body) {
89
+ let msg;
90
+ try {
91
+ const text = typeof body === "string" ? body : new TextDecoder("utf-8", { fatal: true }).decode(body);
92
+ msg = JSON.parse(text);
93
+ }
94
+ catch {
95
+ return null;
96
+ }
97
+ if (typeof msg !== "object" || msg === null || Array.isArray(msg))
98
+ return null;
99
+ const { capybara, conversationId } = msg;
100
+ if (capybara !== "conversation-deleted")
101
+ return null;
102
+ if (typeof conversationId !== "string" || conversationId === "")
103
+ return null;
104
+ return { capybara: "conversation-deleted", conversationId };
105
+ }
66
106
  /** Names the unix socket path the service listens on. */
67
107
  export const DEVICE_SERVICE_SOCKET_ENV = "CAPYBARA_SERVICE_SOCKET";
68
108
  /** Names the service's state directory (its own data, its write root; not where its code is). */
package/dist/hooks.d.ts CHANGED
@@ -81,8 +81,11 @@ export type HookModelMessage = {
81
81
  role: "system";
82
82
  content: string;
83
83
  };
84
- /** The request of a `model.request` payload: the request sent to the provider, without media bytes. */
85
- export type HookModelRequest = Omit<ModelRequest, "messages"> & {
84
+ /**
85
+ * The request of a `model.request` payload: the request sent to the provider, without media bytes
86
+ * and without the transport option `cacheTtl`.
87
+ */
88
+ export type HookModelRequest = Omit<ModelRequest, "messages" | "cacheTtl"> & {
86
89
  messages: HookModelMessage[];
87
90
  };
88
91
  /**
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.82";
1
+ export declare const SDK_VERSION = "0.1.0-rc.84";
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.82";
1
+ export const SDK_VERSION = "0.1.0-rc.84";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
package/dist/model.d.ts CHANGED
@@ -42,6 +42,48 @@ export interface ModelImageGenerationInfo {
42
42
  /** The media types the model returns. */
43
43
  outputMediaTypes: ImageMediaType[];
44
44
  }
45
+ /**
46
+ * explicit: the plugin places breakpoints and the lifetime is known; implicit: the service caches
47
+ * on its own (best-effort unless it declares a lifetime floor); none: no caching.
48
+ */
49
+ export type ModelCacheMechanism = "explicit" | "implicit" | "none";
50
+ /** How a model's prompt cache behaves. Absent or `mechanism: "none"` = no caching. */
51
+ export interface ModelCacheInfo {
52
+ /** See {@link ModelCacheMechanism}. */
53
+ mechanism: ModelCacheMechanism;
54
+ /**
55
+ * Lifetimes a request can choose, in seconds ([300, 3600] Anthropic / Qwen4, [1800, 43200]
56
+ * OpenAI 5.6+, [300] Bailian); empty when the service decides alone. Ascending and unique.
57
+ */
58
+ ttlOptions: number[];
59
+ /**
60
+ * The lifetime a request that names none gets (OpenAI 5.6+: 1800). Required, and one of
61
+ * `ttlOptions`, when `ttlOptions` is non-empty.
62
+ */
63
+ defaultTtl?: number;
64
+ /** OpenAI: the lifetime is a floor, entries may live longer; Anthropic / Bailian: exact. */
65
+ ttlIsMinimum: boolean;
66
+ /**
67
+ * True only if a hit restarts the lifetime of every tier the kernel may select. The kernel
68
+ * selects only `defaultTtl` or the smallest option of at least 1800 s, so OpenAI GPT-5.6+
69
+ * declares true (its 30m tier refreshes on a hit; its 12h tier does not, and the kernel never
70
+ * selects 43200). Anthropic and Bailian declare true. When unconfirmed, declare false.
71
+ */
72
+ refreshOnHit: boolean;
73
+ /** When the lifetime starts counting; Anthropic: the request's start. */
74
+ ttlClock: "request_start" | "unknown";
75
+ /** Below this many prompt tokens nothing is cached. */
76
+ minTokens?: number;
77
+ /** A hit on an unchanged prefix within the lifetime is expected, not best-effort. */
78
+ guaranteed: boolean;
79
+ }
80
+ /**
81
+ * Checks a model's cache declaration: positive integer TTLs, `ttlOptions` ascending and unique,
82
+ * `defaultTtl` present and among the options when options exist, `none` with no options and no
83
+ * guarantee, a guarantee only with a known lifetime, `minTokens` a positive integer. Returns the
84
+ * first problem (naming the field), or `null` when valid.
85
+ */
86
+ export declare function validateModelCache(cache: ModelCacheInfo | undefined): string | null;
45
87
  export interface ModelInfo {
46
88
  id: string;
47
89
  displayName: string;
@@ -63,7 +105,6 @@ export interface ModelInfo {
63
105
  tools: boolean;
64
106
  vision: boolean;
65
107
  reasoning: boolean;
66
- caching: boolean;
67
108
  midConversationSystem: boolean;
68
109
  /**
69
110
  * Whether `document` blocks are accepted (default false). Images are governed by `vision`. When
@@ -80,6 +121,8 @@ export interface ModelInfo {
80
121
  * uses the config default.
81
122
  */
82
123
  streamIdleTimeoutMs?: number;
124
+ /** The model's prompt cache (must pass `validateModelCache`). Absent = mechanism `none`. */
125
+ cache?: ModelCacheInfo;
83
126
  /**
84
127
  * The parameters this model supports (may be an empty array; must pass
85
128
  * `assertValidDeclarations`). Effort is the standard `effort` knob declared here.
@@ -261,6 +304,12 @@ export interface ModelRequest {
261
304
  * API.
262
305
  */
263
306
  purpose?: ModelCallPurpose;
307
+ /**
308
+ * The prompt cache lifetime to ask for: seconds, one of the model's `ttlOptions` (the kernel
309
+ * only ever sends one of them); a plugin of a model without options ignores it; the plugin maps
310
+ * it to the vendor's field. Absent = the model's default.
311
+ */
312
+ cacheTtl?: number;
264
313
  }
265
314
  export type StopReason = "end_turn" | "tool_use" | "max_tokens" | "refusal" | "other";
266
315
  /**
@@ -284,7 +333,22 @@ export interface ModelUsage {
284
333
  cacheWriteTokens: number;
285
334
  /** Images produced (image generation calls). */
286
335
  outputImages?: number;
336
+ /**
337
+ * Cache writes per lifetime tier: optional; sums to `cacheWriteTokens`; from the vendor's
338
+ * per-tier write counts.
339
+ */
340
+ cacheWriteByTtl?: CacheWriteByTtl[];
341
+ }
342
+ /** Input tokens written to the prompt cache with one lifetime (`ttl`, seconds). */
343
+ export interface CacheWriteByTtl {
344
+ ttl: number;
345
+ tokens: number;
287
346
  }
347
+ /**
348
+ * Checks `usage.cacheWriteByTtl` when present: positive integer `ttl`s, each once; non-negative
349
+ * integer `tokens`; the tokens sum to `cacheWriteTokens`. Returns the first problem, or `null`.
350
+ */
351
+ export declare function validateCacheWriteByTtl(usage: ModelUsage): string | null;
288
352
  /**
289
353
  * One event of a model stream. Tool call events are display only: a provider MAY emit
290
354
  * `tool_call_start` when a tool call begins and `tool_call_delta` with raw input JSON fragments
package/dist/model.js CHANGED
@@ -1,5 +1,63 @@
1
1
  /** The aspect ratios a caller may ask for instead of an exact size. */
2
2
  export const IMAGE_ASPECT_RATIOS = ["1:1", "4:3", "3:4", "3:2", "2:3", "16:9", "9:16"];
3
+ const isPositiveInt = (n) => typeof n === "number" && Number.isInteger(n) && n > 0;
4
+ /**
5
+ * Checks a model's cache declaration: positive integer TTLs, `ttlOptions` ascending and unique,
6
+ * `defaultTtl` present and among the options when options exist, `none` with no options and no
7
+ * guarantee, a guarantee only with a known lifetime, `minTokens` a positive integer. Returns the
8
+ * first problem (naming the field), or `null` when valid.
9
+ */
10
+ export function validateModelCache(cache) {
11
+ if (cache === undefined)
12
+ return null;
13
+ if (typeof cache !== "object" || cache === null || Array.isArray(cache)) {
14
+ return "cache must be an object";
15
+ }
16
+ if (!["explicit", "implicit", "none"].includes(cache.mechanism)) {
17
+ return `cache.mechanism must be "explicit", "implicit" or "none"`;
18
+ }
19
+ if (!Array.isArray(cache.ttlOptions))
20
+ return "cache.ttlOptions must be an array";
21
+ for (const [i, ttl] of cache.ttlOptions.entries()) {
22
+ if (!isPositiveInt(ttl))
23
+ return `cache.ttlOptions[${i}] must be a positive integer (seconds)`;
24
+ const prev = cache.ttlOptions[i - 1];
25
+ if (i > 0 && prev !== undefined && ttl <= prev) {
26
+ return "cache.ttlOptions must be ascending and unique";
27
+ }
28
+ }
29
+ if (cache.defaultTtl !== undefined) {
30
+ if (!isPositiveInt(cache.defaultTtl)) {
31
+ return "cache.defaultTtl must be a positive integer (seconds)";
32
+ }
33
+ if (cache.ttlOptions.length > 0 && !cache.ttlOptions.includes(cache.defaultTtl)) {
34
+ return "cache.defaultTtl must be one of cache.ttlOptions";
35
+ }
36
+ }
37
+ if (!["request_start", "unknown"].includes(cache.ttlClock)) {
38
+ return `cache.ttlClock must be "request_start" or "unknown"`;
39
+ }
40
+ for (const field of ["ttlIsMinimum", "refreshOnHit", "guaranteed"]) {
41
+ if (typeof cache[field] !== "boolean")
42
+ return `cache.${field} must be a boolean`;
43
+ }
44
+ if (cache.minTokens !== undefined && !isPositiveInt(cache.minTokens)) {
45
+ return "cache.minTokens must be a positive integer";
46
+ }
47
+ if (cache.mechanism === "none") {
48
+ if (cache.ttlOptions.length > 0)
49
+ return 'cache.mechanism "none" takes no ttlOptions';
50
+ if (cache.guaranteed)
51
+ return 'cache.guaranteed must be false with mechanism "none"';
52
+ }
53
+ if (cache.ttlOptions.length > 0 && cache.defaultTtl === undefined) {
54
+ return "cache.defaultTtl is required when cache.ttlOptions is non-empty";
55
+ }
56
+ if (cache.guaranteed && cache.ttlOptions.length === 0 && cache.defaultTtl === undefined) {
57
+ return "cache.guaranteed needs a known lifetime (ttlOptions or defaultTtl)";
58
+ }
59
+ return null;
60
+ }
3
61
  /** Types accepted by image blocks. */
4
62
  export const IMAGE_MEDIA_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp"];
5
63
  /** Types accepted by document blocks. */
@@ -134,6 +192,39 @@ export function validateMediaBlock(b) {
134
192
  }
135
193
  return errs;
136
194
  }
195
+ /**
196
+ * Checks `usage.cacheWriteByTtl` when present: positive integer `ttl`s, each once; non-negative
197
+ * integer `tokens`; the tokens sum to `cacheWriteTokens`. Returns the first problem, or `null`.
198
+ */
199
+ export function validateCacheWriteByTtl(usage) {
200
+ if (typeof usage !== "object" || usage === null)
201
+ return "usage must be an object";
202
+ const tiers = usage.cacheWriteByTtl;
203
+ if (tiers === undefined)
204
+ return null;
205
+ if (!Array.isArray(tiers))
206
+ return "cacheWriteByTtl must be an array";
207
+ const seen = new Set();
208
+ let sum = 0;
209
+ for (const [i, tier] of tiers.entries()) {
210
+ if (typeof tier !== "object" || tier === null)
211
+ return `cacheWriteByTtl[${i}] must be an object`;
212
+ if (!isPositiveInt(tier.ttl)) {
213
+ return `cacheWriteByTtl[${i}].ttl must be a positive integer (seconds)`;
214
+ }
215
+ if (seen.has(tier.ttl))
216
+ return `cacheWriteByTtl has ttl ${tier.ttl} twice`;
217
+ seen.add(tier.ttl);
218
+ if (typeof tier.tokens !== "number" || !Number.isInteger(tier.tokens) || tier.tokens < 0) {
219
+ return `cacheWriteByTtl[${i}].tokens must be a non-negative integer`;
220
+ }
221
+ sum += tier.tokens;
222
+ }
223
+ if (sum !== usage.cacheWriteTokens) {
224
+ return `cacheWriteByTtl sums to ${sum}, not cacheWriteTokens ${usage.cacheWriteTokens}`;
225
+ }
226
+ return null;
227
+ }
137
228
  const ALL_KINDS = new Set([
138
229
  "rate_limited",
139
230
  "overloaded",
@@ -31,6 +31,11 @@ export interface NotifyCapabilityV1 {
31
31
  /** `openExternal@1`: open a URL in the system browser. */
32
32
  export interface OpenExternalCapabilityV1 {
33
33
  open(url: string): Promise<void>;
34
+ /**
35
+ * The shell's own URL scheme, the one in its `<scheme>://auth/callback` (optional): a browser
36
+ * handoff's done page links back into the app through `<scheme>://open?url=…`.
37
+ */
38
+ readonly returnScheme?: string;
34
39
  }
35
40
  /** `signIn@1`: sign in through the system browser (desktop client spec §6.5). */
36
41
  export interface SignInCapabilityV1 {
@@ -3,7 +3,7 @@ export declare const THEME_TOKENS: {
3
3
  readonly color: {
4
4
  readonly bg: {
5
5
  readonly dark: "#0A0A0A";
6
- readonly light: "#FAF9F6";
6
+ readonly light: "#FDFDFC";
7
7
  };
8
8
  readonly panel: {
9
9
  readonly dark: "#111110";
@@ -14,11 +14,11 @@ export declare const THEME_TOKENS: {
14
14
  readonly light: "#FCFBF9";
15
15
  };
16
16
  readonly sidebar: {
17
- readonly dark: "#111110";
18
- readonly light: "#F3F2EE";
17
+ readonly dark: "#171716";
18
+ readonly light: "#EDECE7";
19
19
  };
20
20
  readonly "sidebar-active": {
21
- readonly dark: "#1A1A18";
21
+ readonly dark: "rgba(255,255,255,0.07)";
22
22
  readonly light: "rgba(26,26,24,0.09)";
23
23
  };
24
24
  readonly raised: {
@@ -26,12 +26,12 @@ export declare const THEME_TOKENS: {
26
26
  readonly light: "#FFFFFF";
27
27
  };
28
28
  readonly selected: {
29
- readonly dark: "#1F1F1D";
29
+ readonly dark: "#21211F";
30
30
  readonly light: "rgba(26,26,24,0.07)";
31
31
  };
32
32
  readonly hover: {
33
- readonly dark: "#171716";
34
- readonly light: "rgba(26,26,24,0.04)";
33
+ readonly dark: "rgba(255,255,255,0.04)";
34
+ readonly light: "rgba(26,26,24,0.045)";
35
35
  };
36
36
  readonly "line-soft": {
37
37
  readonly dark: "#1C1C1A";
@@ -3,14 +3,14 @@
3
3
  /** The built-in token values a theme overrides (design spec §2). */
4
4
  export const THEME_TOKENS = {
5
5
  color: {
6
- "bg": { dark: "#0A0A0A", light: "#FAF9F6" },
6
+ "bg": { dark: "#0A0A0A", light: "#FDFDFC" },
7
7
  "panel": { dark: "#111110", light: "#FFFFFF" },
8
8
  "panel-2": { dark: "#0E0E0D", light: "#FCFBF9" },
9
- "sidebar": { dark: "#111110", light: "#F3F2EE" },
10
- "sidebar-active": { dark: "#1A1A18", light: "rgba(26,26,24,0.09)" },
9
+ "sidebar": { dark: "#171716", light: "#EDECE7" },
10
+ "sidebar-active": { dark: "rgba(255,255,255,0.07)", light: "rgba(26,26,24,0.09)" },
11
11
  "raised": { dark: "#141413", light: "#FFFFFF" },
12
- "selected": { dark: "#1F1F1D", light: "rgba(26,26,24,0.07)" },
13
- "hover": { dark: "#171716", light: "rgba(26,26,24,0.04)" },
12
+ "selected": { dark: "#21211F", light: "rgba(26,26,24,0.07)" },
13
+ "hover": { dark: "rgba(255,255,255,0.04)", light: "rgba(26,26,24,0.045)" },
14
14
  "line-soft": { dark: "#1C1C1A", light: "#E8E7E2" },
15
15
  "line": { dark: "#2A2A28", light: "#D9D8D2" },
16
16
  "line-strong": { dark: "#3A3A37", light: "#B5B5AE" },
package/dist/tool.d.ts CHANGED
@@ -236,7 +236,21 @@ export interface InputRequired {
236
236
  * warning and the form is asked as usual.
237
237
  */
238
238
  open?: UiOpen;
239
+ /**
240
+ * A watched wait: besides the person's answer and the deadline, the tool's registered watcher
241
+ * ({@link ToolWatcher}, `ctx.tools.register(spec, handler, { watch })`) may settle it. The
242
+ * kernel parks the run (no model turn, no worker held) and calls the watcher every 10 s while
243
+ * the wait is pending. `deadlineMs` is a positive integer number of milliseconds (anything else
244
+ * is refused with an invalid-form result), bounded by the deployment's
245
+ * `tools.approvalTimeoutHours`; a shorter kernel deadline resumes the call with
246
+ * `outcome: "expired"`.
247
+ */
248
+ watch?: {
249
+ deadlineMs: number;
250
+ };
239
251
  }
252
+ /** How an input round ended when the handler is called again ({@link ToolCallContext.resume}). */
253
+ export type ToolResumeOutcome = "answered" | "woken" | "expired";
240
254
  export type FormAnswer = Record<string, string | number | boolean | string[]>;
241
255
  /**
242
256
  * What a tool handler gets with each invocation.
@@ -282,10 +296,17 @@ export interface ToolCallContext {
282
296
  */
283
297
  idempotencyKey?: string;
284
298
  signal: AbortSignal;
285
- /** null = the user cancelled or it timed out. */
299
+ /**
300
+ * The previous input round's state and answer. `answer` is null unless the person answered.
301
+ * `outcome`: `answered` (the person answered), `woken` (a watched wait's watcher settled it, or
302
+ * the kernel ended the watch early: the watcher failed, is gone, or the tool is no longer
303
+ * available) or `expired` (the deadline passed). A tool with its own source of truth (a watched
304
+ * condition) asks it first and uses `outcome` only for what happened otherwise.
305
+ */
286
306
  resume?: {
287
307
  state: unknown;
288
308
  answer: FormAnswer | null;
309
+ outcome: ToolResumeOutcome;
289
310
  };
290
311
  /**
291
312
  * The extension's effective deployment config for this org: the platform's deployment config
@@ -302,6 +323,28 @@ export interface ToolCallContext {
302
323
  role?: "owner" | "admin" | "member" | "guest";
303
324
  }
304
325
  export type ToolHandler = (input: unknown, ctx: ToolCallContext) => Promise<ToolResult | InputRequired>;
326
+ /**
327
+ * What a watcher gets: the call's context as the handler got it (the same `callId`,
328
+ * `idempotencyKey`, accounts, conversations and effective config), without `resume`, plus the
329
+ * state the handler returned with its watched `InputRequired`.
330
+ */
331
+ export interface ToolWatchContext extends Omit<ToolCallContext, "resume"> {
332
+ state: unknown;
333
+ }
334
+ /**
335
+ * A watched wait's watcher (`ctx.tools.register(spec, handler, { watch })`). The kernel calls it
336
+ * every 10 s while the wait is pending, never twice at once for one wait, never after it
337
+ * settled; `settle` ends the wait (the handler is called again with `resume.outcome: "woken"`),
338
+ * `pending` keeps it. It must be cheap: the kernel aborts `ctx.signal` and stops waiting for it
339
+ * after 5 s, which counts as a failure, as a throw does; 3 consecutive failures end the wait. A
340
+ * watcher that ignores the signal keeps running after that, so a later poll may overlap it, and a
341
+ * poll already running when the wait ends (the person answered) may overlap the resumed handler:
342
+ * keep the watcher read-only and honour `ctx.signal`. Its
343
+ * `ctx.deviceAccess.request` calls run as `ifRunning` (a stopped device or service answers
344
+ * `not_running`, nothing is resumed or started), `ensureService` is refused, and
345
+ * `reportBlockedHosts` calls are dropped.
346
+ */
347
+ export type ToolWatcher = (ctx: ToolWatchContext) => Promise<"settle" | "pending">;
305
348
  /**
306
349
  * Tool error categories:
307
350
  * - `error` (default): the remote is available but this call failed (bad parameters, business
@@ -1,7 +1,7 @@
1
1
  /** The ARIA / data states a part promises (client extensions spec §7.1). */
2
2
  export type UiPartState = "aria-current" | "aria-selected" | "aria-expanded" | "aria-busy" | "aria-checked" | "aria-pressed" | "disabled";
3
3
  /** Every part name of the catalog, in catalog order. */
4
- export declare const UI_PART_NAMES: readonly ["shell", "sidebar", "sidebar.brand", "sidebar.item", "title-bar", "page-header", "thread", "message.user", "message.user.bubble", "message.assistant", "tool-row", "composer", "composer.box", "composer.options", "composer.send", "properties-panel", "section", "right-panel", "status-bar", "button", "button.primary", "card", "input", "dialog", "code-block", "menu", "segmented", "stat-card", "switch", "switch.knob", "org-avatar", "agent-chip", "image-placeholder"];
4
+ export declare const UI_PART_NAMES: readonly ["shell", "sidebar", "sidebar.brand", "sidebar.item", "title-bar", "page-header", "thread", "message.user", "message.user.bubble", "message.assistant", "tool-row", "composer", "composer.box", "composer.options", "composer.send", "properties-panel", "section", "right-panel", "button", "button.primary", "card", "input", "dialog", "code-block", "menu", "segmented", "stat-card", "switch", "switch.knob", "org-avatar", "agent-chip", "image-placeholder"];
5
5
  export type UiPartName = (typeof UI_PART_NAMES)[number];
6
6
  /** One built-in element plugin CSS may select with `[data-cap-part~="<name>"]`. */
7
7
  export interface UiPartSpec {
package/dist/ui-parts.js CHANGED
@@ -18,7 +18,6 @@ export const UI_PART_NAMES = [
18
18
  "properties-panel",
19
19
  "section",
20
20
  "right-panel",
21
- "status-bar",
22
21
  "button",
23
22
  "button.primary",
24
23
  "card",
@@ -221,16 +220,6 @@ export const UI_PARTS = [
221
220
  zh: "占满高度的右侧窗格。",
222
221
  },
223
222
  },
224
- {
225
- name: "status-bar",
226
- version: 1,
227
- owner: ["packages/design/src/shell/status-bar.tsx"],
228
- states: [],
229
- description: {
230
- en: "The status bar.",
231
- zh: "状态栏。",
232
- },
233
- },
234
223
  {
235
224
  name: "button",
236
225
  version: 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.82",
3
+ "version": "0.1.0-rc.84",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {