@capybara-hq/plugin-sdk 0.1.0-rc.83 → 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/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.83";
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.83";
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" },
@@ -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.83",
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": {