@capybara-hq/plugin-sdk 0.1.0-rc.26 → 0.1.0-rc.28

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.
Files changed (48) hide show
  1. package/agent-docs/extension-points/model-provider.md +1 -1
  2. package/dist/cards.d.ts +17 -8
  3. package/dist/cards.js +21 -10
  4. package/dist/channel.d.ts +91 -47
  5. package/dist/channel.js +10 -5
  6. package/dist/connector-auth.d.ts +5 -2
  7. package/dist/connector-auth.js +14 -8
  8. package/dist/connector.d.ts +67 -32
  9. package/dist/ctx.d.ts +41 -23
  10. package/dist/define-extension.d.ts +21 -11
  11. package/dist/define-extension.js +10 -4
  12. package/dist/device-protocol.d.ts +2 -1
  13. package/dist/extension-point.js +1 -1
  14. package/dist/identity.d.ts +22 -9
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/model-params.d.ts +41 -22
  18. package/dist/model-params.js +28 -15
  19. package/dist/model.d.ts +96 -64
  20. package/dist/model.js +25 -14
  21. package/dist/permissions.d.ts +6 -6
  22. package/dist/permissions.js +8 -32
  23. package/dist/plugin-package.d.ts +79 -38
  24. package/dist/plugin-package.js +57 -29
  25. package/dist/sandbox-linux-runtime-source.d.ts +15 -0
  26. package/dist/sandbox-linux-runtime-source.js +1421 -0
  27. package/dist/sandbox-runtime-source.d.ts +9 -3
  28. package/dist/sandbox-runtime-source.js +16 -4
  29. package/dist/sandbox.d.ts +4 -1
  30. package/dist/sandbox.js +7 -3
  31. package/dist/secret.d.ts +4 -1
  32. package/dist/secret.js +4 -1
  33. package/dist/setup-guide.d.ts +1 -1
  34. package/dist/setup-guide.js +1 -1
  35. package/dist/skill.d.ts +27 -17
  36. package/dist/skill.js +39 -25
  37. package/dist/storage.d.ts +45 -25
  38. package/dist/tool.d.ts +51 -23
  39. package/dist/tool.js +21 -9
  40. package/dist/ui-resolve.d.ts +2 -7
  41. package/dist/ui-resolve.js +7 -19
  42. package/dist/ui-slots.d.ts +1 -3
  43. package/dist/ui-slots.js +0 -9
  44. package/dist/ui.d.ts +63 -49
  45. package/dist/ui.js +36 -22
  46. package/dist/url.d.ts +4 -1
  47. package/dist/url.js +4 -1
  48. package/package.json +1 -1
package/dist/tool.js CHANGED
@@ -54,7 +54,10 @@ export function validateToolPresentation(spec) {
54
54
  return out;
55
55
  }
56
56
  const DISPLAY_MAX = 200;
57
- /** 校验 {@link ToolDisplay},返回问题列表(空 = 合法);长度按 Unicode 码点计。 */
57
+ /**
58
+ * Validates a {@link ToolDisplay} and returns the list of problems (empty = valid); length is
59
+ * counted in Unicode code points.
60
+ */
58
61
  export function validateToolDisplay(d) {
59
62
  if (typeof d !== "object" || d === null || Array.isArray(d))
60
63
  return ["display must be an object"];
@@ -69,7 +72,7 @@ export function validateToolDisplay(d) {
69
72
  }
70
73
  return out;
71
74
  }
72
- /** 工具执行失败:message 给模型看,须为英文且可操作。 */
75
+ /** A tool execution failure: message is for the model and must be in English and actionable. */
73
76
  export class ToolError extends Error {
74
77
  kind;
75
78
  constructor(message, opts) {
@@ -78,9 +81,12 @@ export class ToolError extends Error {
78
81
  this.kind = opts?.kind ?? "error";
79
82
  }
80
83
  }
81
- /** 插件工具名规则。 */
84
+ /** Plugin tool name rule. */
82
85
  export const EXTENSION_TOOL_NAME = /^[a-zA-Z0-9_-]{1,40}$/;
83
- /** 校验插件注册的工具声明,返回问题列表(空 = 合法)。 */
86
+ /**
87
+ * Validates the tool declarations a plugin registers and returns the list of problems (empty =
88
+ * valid).
89
+ */
84
90
  export function validateToolSpec(spec) {
85
91
  const out = [];
86
92
  if (typeof spec?.name !== "string" || !EXTENSION_TOOL_NAME.test(spec.name))
@@ -109,7 +115,7 @@ const SCHEMA_KEYS = {
109
115
  number: ["type", "minimum", "maximum"],
110
116
  integer: ["type", "minimum", "maximum"],
111
117
  };
112
- /** 检查 schema 是否落在 ParamSchema 子集内,返回问题列表。 */
118
+ /** Checks whether a schema falls within the ParamSchema subset and returns the list of problems. */
113
119
  function schemaProblems(schema) {
114
120
  if (typeof schema !== "object" || schema === null || Array.isArray(schema))
115
121
  return ["schema must be an object"];
@@ -138,7 +144,7 @@ function schemaProblems(schema) {
138
144
  return out;
139
145
  }
140
146
  const isEnum = (s) => s.type === "string" && "enum" in s;
141
- /** 校验交互表单的声明,返回问题列表(空 = 合法)。 */
147
+ /** Validates an interactive form declaration and returns the list of problems (empty = valid). */
142
148
  export function validateInputForm(form) {
143
149
  const out = [];
144
150
  if (!form || !Array.isArray(form.fields))
@@ -167,7 +173,10 @@ export function validateInputForm(form) {
167
173
  }
168
174
  return out;
169
175
  }
170
- /** 校验用户提交的答案是否符合表单,返回问题列表(空 = 合法)。 */
176
+ /**
177
+ * Validates whether the answer a user submitted conforms to the form and returns the list of
178
+ * problems (empty = valid).
179
+ */
171
180
  export function validateAnswer(form, answer) {
172
181
  const out = [];
173
182
  const byKey = new Map(form.fields.map((f) => [f.key, f]));
@@ -176,7 +185,8 @@ export function validateAnswer(form, answer) {
176
185
  out.push(`unknown field ${JSON.stringify(k)}`);
177
186
  for (const f of form.fields) {
178
187
  const at = `field ${JSON.stringify(f.key)}`;
179
- // 只认答案自身的键:`toString` / `constructor` 等继承属性不算已回答
188
+ // Look only at the answer's own keys: inherited properties such as `toString` / `constructor`
189
+ // do not count as answered
180
190
  const v = Object.hasOwn(answer, f.key) ? answer[f.key] : undefined;
181
191
  if (v === undefined) {
182
192
  if (f.required)
@@ -217,7 +227,9 @@ export function validateAnswer(form, answer) {
217
227
  }
218
228
  return out;
219
229
  }
220
- /** allowOther 的枚举字段接受任意非空文本,其余按 schema 校验。 */
230
+ /**
231
+ * An allowOther enum field accepts any non-empty text; the rest are validated against the schema.
232
+ */
221
233
  function otherOrValue(f, v) {
222
234
  if (f.allowOther && isEnum(f.schema)) {
223
235
  return typeof v === "string" && v !== "" ? undefined : "other text must be a non-empty string";
@@ -19,15 +19,11 @@ export interface DroppedUiContribution {
19
19
  ref: string;
20
20
  reason: UiDropReason;
21
21
  }
22
- /** The slot reference a contribution names: its `slot`, or the slot of its deprecated `place`. */
23
- export declare function slotRefOf(c: UiContribution): string;
24
22
  /**
25
23
  * Resolves the slots of a manifest's `ui` against the catalog (UI slots spec §3.2). Assumes
26
24
  * `validateUiContributions` passed; never throws. A contribution to an unknown slot or to a version
27
- * other than the slot's is dropped (an alias whose target is dropped is dropped with the target's
28
- * reason and its own `ref`); an `after` that is not an anchor of the slot is listed in
29
- * `unknownAnchors` and the contribution keeps the slot's default position. `deprecatedPlace` lists
30
- * the ids that still say `place`. Both lists keep manifest order.
25
+ * other than the slot's is dropped; an `after` that is not an anchor of the slot is listed in
26
+ * `unknownAnchors` and the contribution keeps the slot's default position. Both lists keep manifest order.
31
27
  */
32
28
  export declare function resolveUiSlots(ui: readonly UiContribution[] | undefined): {
33
29
  resolved: ResolvedUiContribution[];
@@ -36,5 +32,4 @@ export declare function resolveUiSlots(ui: readonly UiContribution[] | undefined
36
32
  id: string;
37
33
  after: string;
38
34
  }[];
39
- deprecatedPlace: string[];
40
35
  };
@@ -1,22 +1,15 @@
1
- import { PLACE_SLOTS, parseSlotRef, uiSlot } from "./ui-slots.js";
2
- /** The slot reference a contribution names: its `slot`, or the slot of its deprecated `place`. */
3
- export function slotRefOf(c) {
4
- // biome-ignore lint/style/noNonNullAssertion: validateUiContributions requires slot or place
5
- return c.slot ?? PLACE_SLOTS[c.place];
6
- }
1
+ import { parseSlotRef, uiSlot } from "./ui-slots.js";
7
2
  /**
8
3
  * Resolves the slots of a manifest's `ui` against the catalog (UI slots spec §3.2). Assumes
9
4
  * `validateUiContributions` passed; never throws. A contribution to an unknown slot or to a version
10
- * other than the slot's is dropped (an alias whose target is dropped is dropped with the target's
11
- * reason and its own `ref`); an `after` that is not an anchor of the slot is listed in
12
- * `unknownAnchors` and the contribution keeps the slot's default position. `deprecatedPlace` lists
13
- * the ids that still say `place`. Both lists keep manifest order.
5
+ * other than the slot's is dropped; an `after` that is not an anchor of the slot is listed in
6
+ * `unknownAnchors` and the contribution keeps the slot's default position. Both lists keep manifest order.
14
7
  */
15
8
  export function resolveUiSlots(ui) {
16
9
  const list = ui ?? [];
17
10
  const own = new Map();
18
11
  for (const c of list) {
19
- const ref = parseSlotRef(slotRefOf(c));
12
+ const ref = parseSlotRef(c.slot);
20
13
  const slot = ref === null ? undefined : uiSlot(ref.id);
21
14
  own.set(c.id, ref === null || slot === undefined
22
15
  ? { ok: false, reason: "unknown-slot" }
@@ -27,15 +20,10 @@ export function resolveUiSlots(ui) {
27
20
  const resolved = [];
28
21
  const dropped = [];
29
22
  const unknownAnchors = [];
30
- const deprecatedPlace = [];
31
23
  for (const c of list) {
32
- if (c.slot === undefined && c.place !== undefined)
33
- deprecatedPlace.push(c.id);
34
- const mine = own.get(c.id);
35
- const target = c.aliasOf === undefined ? undefined : own.get(c.aliasOf);
36
- const r = mine.ok && target !== undefined && !target.ok ? target : mine;
24
+ const r = own.get(c.id);
37
25
  if (!r.ok) {
38
- dropped.push({ id: c.id, ref: slotRefOf(c), reason: r.reason });
26
+ dropped.push({ id: c.id, ref: c.slot, reason: r.reason });
39
27
  continue;
40
28
  }
41
29
  const anchors = r.slot.anchors ?? [];
@@ -50,5 +38,5 @@ export function resolveUiSlots(ui) {
50
38
  ...(anchors.length > 0 && { after }),
51
39
  });
52
40
  }
53
- return { resolved, dropped, unknownAnchors, deprecatedPlace };
41
+ return { resolved, dropped, unknownAnchors };
54
42
  }
@@ -1,4 +1,4 @@
1
- import type { UiKind, UiPlace } from "./ui.js";
1
+ import type { UiKind } from "./ui.js";
2
2
  export type UiSlotScope = "conversation" | "agent" | "org" | "platform" | "file";
3
3
  export type UiSlotRole = "guest" | "member" | "admin" | "superAdmin";
4
4
  /** Every slot id of the catalog, in catalog order (UI slots spec §3). */
@@ -44,8 +44,6 @@ export declare function parseSlotRef(ref: string): {
44
44
  id: string;
45
45
  version: number;
46
46
  } | null;
47
- /** @deprecated step A of the UI slots spec §4 */
48
- export declare const PLACE_SLOTS: Readonly<Record<UiPlace, UiSlotId>>;
49
47
  export declare const UI_ARRANGEABLE_SLOTS: readonly UiSlotId[];
50
48
  /** Slots with one winner that replaces a built-in block. */
51
49
  export declare const UI_SINGLE_SLOTS: readonly UiSlotId[];
package/dist/ui-slots.js CHANGED
@@ -227,15 +227,6 @@ export function parseSlotRef(ref) {
227
227
  return null;
228
228
  return { id: m[1], version: m[2] === undefined ? 1 : Number(m[2]) };
229
229
  }
230
- /** @deprecated step A of the UI slots spec §4 */
231
- export const PLACE_SLOTS = {
232
- panel: "conversation.panel",
233
- conversation: "conversation.panel",
234
- section: "conversation.properties.section",
235
- inline: "conversation.tool-result.card",
236
- page: "org.page",
237
- "file-preview": "file.preview",
238
- };
239
230
  export const UI_ARRANGEABLE_SLOTS = UI_SLOT_IDS.filter((id) => id !== "file.preview");
240
231
  /** Slots with one winner that replaces a built-in block. */
241
232
  export const UI_SINGLE_SLOTS = UI_SLOTS.filter((s) => s.cardinality === "single").map((s) => s.id);
package/dist/ui.d.ts CHANGED
@@ -1,13 +1,6 @@
1
1
  import type { Locale } from "./cards.js";
2
2
  import { type FormAnswer, type InputForm } from "./tool.js";
3
3
  import type { UiSlotId, UiSlotScope } from "./ui-slots.js";
4
- /**
5
- * The places of the first UI design, kept as a deprecated input (UI slots spec §4, step A): each maps
6
- * to a slot through `PLACE_SLOTS` (`panel` and `conversation` → `conversation.panel`, `section` →
7
- * `conversation.properties.section`, `inline` → `conversation.tool-result.card`, `page` →
8
- * `org.page`, `file-preview` → `file.preview`).
9
- */
10
- export type UiPlace = "conversation" | "panel" | "section" | "inline" | "page" | "file-preview";
11
4
  /**
12
5
  * Icons a contribution may use (design system icon names; `puzzle` is the default and is drawn as
13
6
  * the design `extension` icon). The title-bar button of a panel shows it.
@@ -42,13 +35,11 @@ export interface UiContribution {
42
35
  en: string;
43
36
  };
44
37
  /**
45
- * The slot it goes in: `"<id>"` (version 1) or `"<id>@<n>"`, an id of `UI_SLOTS`. Exactly one of
46
- * `slot` and `place`. An unknown slot or version does not fail the extension: the contribution is
47
- * dropped (see `resolveUiSlots`).
38
+ * The slot it goes in: `"<id>"` (version 1) or `"<id>@<n>"`, an id of `UI_SLOTS`. Required. An
39
+ * unknown slot or version does not fail the extension: the contribution is dropped (see
40
+ * `resolveUiSlots`).
48
41
  */
49
- slot?: string;
50
- /** @deprecated use slot (UI slots spec §4, step A) */
51
- place?: UiPlace;
42
+ slot: string;
52
43
  /**
53
44
  * One of the slot's `anchors` to be placed after; omitted (or not an anchor of the slot) = the
54
45
  * slot's first anchor.
@@ -59,16 +50,11 @@ export interface UiContribution {
59
50
  path?: string;
60
51
  /** Icon from {@link UI_ICONS}; default `puzzle`. */
61
52
  icon?: UiIcon;
62
- /**
63
- * A retired id kept answering for a release: it is not listed, and fetching it renders (or
64
- * embeds) the named contribution of the same extension and kind. It still needs its entry in
65
- * `permissions.ui`, and no `ctx.ui.view` of its own.
66
- */
67
- aliasOf?: string;
68
53
  }
69
54
  /**
70
- * 渲染 schema 的块。文本是给人看的、按原样展示(插件自行决定语言,通常取 `locale`)。
71
- * `text.markdown` 不支持原生 HTML,链接只允许 http(s) 绝对地址。
55
+ * Blocks of the render schema. Text is for humans and shown as is (the plugin decides the language
56
+ * itself, usually taking `locale`).
57
+ * `text.markdown` does not support native HTML, and links may only be absolute http(s) addresses.
72
58
  */
73
59
  export type UiBlock = {
74
60
  type: "heading";
@@ -100,8 +86,10 @@ export type UiBlock = {
100
86
  label: string;
101
87
  }[];
102
88
  /**
103
- * 每行按列 key 取单元格,可以缺列。渲染时用 `Object.hasOwn(row, key)` 判断单元格是否存在,
104
- * 不要用 `row[key]` 或 `in`:列 key 可能是 `constructor` / `toString` 之类,会取到原型链上的值。
89
+ * Each row takes its cell by column key, and a column may be missing. When rendering, use
90
+ * `Object.hasOwn(row, key)` to tell whether a cell exists,
91
+ * do not use `row[key]` or `in`: a column key may be `constructor` / `toString` and the like,
92
+ * which would pick up values from the prototype chain.
105
93
  */
106
94
  rows: Record<string, string>[];
107
95
  /** Per row (same index), an open target or null; never a key inside a row. */
@@ -139,7 +127,7 @@ export type UiBlock = {
139
127
  export type JsonValue = string | number | boolean | null | JsonValue[] | {
140
128
  [key: string]: JsonValue;
141
129
  };
142
- /** 插件视图:有上限的块列表;`badge` 显示在标签上(如「2/4」)。 */
130
+ /** A plugin view: a block list with limits; `badge` is shown on the tab (e.g. "2/4"). */
143
131
  export interface UiView {
144
132
  badge?: string;
145
133
  /** The ⤢ of an inline card's title row and a properties section's header. */
@@ -153,12 +141,13 @@ export interface UiView {
153
141
  data?: JsonValue;
154
142
  }
155
143
  /**
156
- * 视图上限({@link validateUiView} 统一检查):
157
- * - `blocks`:块数;
158
- * - `tableRows`:表格行数,也用作 keyValue 项数、表格列数、图表点数、按钮数的上限;
159
- * - `checklistItems`:清单项数;
160
- * - `textChars`:整个视图所有文本(含表单 JSON)的字符总数;
161
- * - `payloadBytes`:单个按钮 `payload` 的 JSON 序列化后 UTF-8 字节数。
144
+ * View limits (checked uniformly by {@link validateUiView}):
145
+ * - `blocks`: number of blocks;
146
+ * - `tableRows`: number of table rows, also used as the upper bound for keyValue items, table
147
+ * columns, chart points and buttons;
148
+ * - `checklistItems`: number of checklist items;
149
+ * - `textChars`: total characters of all text in the whole view (form JSON included);
150
+ * - `payloadBytes`: UTF-8 bytes of a single button `payload` after JSON serialization.
162
151
  * - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
163
152
  */
164
153
  export declare const UI_LIMITS: {
@@ -170,9 +159,12 @@ export declare const UI_LIMITS: {
170
159
  readonly componentDataBytes: 32768;
171
160
  };
172
161
  /**
173
- * 校验插件返回的视图,返回问题列表(空 = 合法)。链接与图片只允许 http(s) 绝对地址;
174
- * Markdown 的检查是纵深防御,网页渲染时仍须只认 http(s) 链接、不渲染原生 HTML。
175
- * 按钮与表单的 `actionId` 在整个视图内唯一(动作回调靠它区分来源)。
162
+ * Validates the view a plugin returns and returns the list of problems (empty = valid). Links and
163
+ * images may only be absolute http(s) addresses;
164
+ * the Markdown check is defense in depth, and web rendering must still accept only http(s) links
165
+ * and not render native HTML.
166
+ * The `actionId` of buttons and forms is unique within the whole view (action callbacks tell the
167
+ * source by it).
176
168
  * `data` is accepted only with `opts.component` (the view of a component contribution): JSON as is
177
169
  * (nothing JSON would drop or rewrite, see `jsonProblem`), up to `UI_LIMITS.componentDataBytes`
178
170
  * bytes of UTF-8.
@@ -205,14 +197,20 @@ export interface UiRenderArgsBase {
205
197
  */
206
198
  config?: unknown;
207
199
  }
208
- /** 内核调用插件 `render` 时传入的参数,组织内的位置(会话、智能体、组织、文件)。 */
200
+ /**
201
+ * The parameters passed when the kernel calls the plugin's `render`: the position within the org
202
+ * (conversation, agent, org, file).
203
+ */
209
204
  export interface UiOrgRenderArgs extends UiRenderArgsBase {
210
205
  /** The scope of {@link slot}: which of the context ids below are set. */
211
206
  scope: Exclude<UiSlotScope, "platform">;
212
207
  orgId: string;
213
- /** 调用者此刻在 `orgId` 的角色(内核按成员关系填,插件可据此收紧按钮等,见 {@link UiRole})。 */
208
+ /**
209
+ * The caller's role in `orgId` at this moment (filled by the kernel from membership; a plugin may
210
+ * use it to tighten buttons etc., see {@link UiRole}).
211
+ */
214
212
  role: UiRole;
215
- /** 仅对话视图。 */
213
+ /** Conversation views only. */
216
214
  conversationId?: string;
217
215
  /** Only an agent view (`agent.detail.section`): an agent of `orgId` the caller can read. */
218
216
  agentId?: string;
@@ -241,7 +239,10 @@ export interface UiPlatformRenderArgs extends UiRenderArgsBase {
241
239
  item?: undefined;
242
240
  card?: undefined;
243
241
  }
244
- /** 内核调用插件 `render` 时传入的参数:narrow on `scope` (`"platform"` has no `orgId`). */
242
+ /**
243
+ * The parameters passed when the kernel calls the plugin's `render`: narrow on `scope`
244
+ * (`"platform"` has no `orgId`).
245
+ */
245
246
  export type UiRenderArgs = UiOrgRenderArgs | UiPlatformRenderArgs;
246
247
  /** What a button or form submit adds to the render args. */
247
248
  export interface UiActionInput {
@@ -255,9 +256,12 @@ export interface UiOrgActionArgs extends UiOrgRenderArgs, UiActionInput {
255
256
  /** An action of a `platform.page` view. */
256
257
  export interface UiPlatformActionArgs extends UiPlatformRenderArgs, UiActionInput {
257
258
  }
258
- /** 视图里的按钮或表单提交:`actionId` 来自块;表单提交时带 `answer`。 */
259
+ /**
260
+ * A button or form submission in a view: `actionId` comes from the block; a form submission carries
261
+ * `answer`.
262
+ */
259
263
  export type UiActionArgs = UiOrgActionArgs | UiPlatformActionArgs;
260
- /** 动作结果:一条提示,或一份新的视图。 */
264
+ /** An action result: a notice, or a new view. */
261
265
  export type UiActionResult = {
262
266
  toast?: {
263
267
  zh: string;
@@ -266,7 +270,7 @@ export type UiActionResult = {
266
270
  } | {
267
271
  view: UiView;
268
272
  };
269
- /** The embed claims both scopes share. `exp` 为 Unix 秒。 */
273
+ /** The embed claims both scopes share. `exp` is Unix seconds. */
270
274
  export interface EmbedClaimsBase {
271
275
  plugin: string;
272
276
  accountId: string;
@@ -277,7 +281,10 @@ export interface EmbedClaimsBase {
277
281
  export interface OrgEmbedClaims extends EmbedClaimsBase {
278
282
  scope: "org";
279
283
  orgId: string;
280
- /** 调用者的角色:签发时写入;`ctx.ui.verifyEmbedToken` 返回校验时刻的当前角色。 */
284
+ /**
285
+ * The caller's role: written at issuance; `ctx.ui.verifyEmbedToken` returns the current role at
286
+ * validation time.
287
+ */
281
288
  role: UiRole;
282
289
  conversationId?: string;
283
290
  /** Only an agent embed's token (`agent.detail.section`): the agent it was issued for. */
@@ -295,11 +302,14 @@ export interface PlatformEmbedClaims extends EmbedClaimsBase {
295
302
  fileId?: undefined;
296
303
  }
297
304
  /**
298
- * 嵌入令牌里的声明(经 `ctx.ui.verifyEmbedToken` 校验后可信): narrow on `scope` (`"platform"` has no
305
+ * Claims in an embed token (trustworthy after validation by `ctx.ui.verifyEmbedToken`): narrow on
306
+ * `scope` (`"platform"` has no
299
307
  * `orgId` and `role` `"superAdmin"`).
300
308
  */
301
309
  export type EmbedClaims = OrgEmbedClaims | PlatformEmbedClaims;
302
- /** 外层页面与嵌入 iframe 之间 `postMessage` 协议的版本标识。 */
310
+ /**
311
+ * The version marker of the `postMessage` protocol between the outer page and the embedded iframe.
312
+ */
303
313
  export declare const EMBED_PROTOCOL = "capybara-embed/1";
304
314
  /**
305
315
  * What an embed's `init` says about where it is shown, narrowed on `scope` like {@link EmbedClaims}:
@@ -315,7 +325,7 @@ export type EmbedInitContext = {
315
325
  orgId?: undefined;
316
326
  conversationId?: undefined;
317
327
  };
318
- /** 外层页面发给 iframe 的消息。 */
328
+ /** Messages the outer page sends to the iframe. */
319
329
  export type EmbedParentMessage = {
320
330
  protocol: typeof EMBED_PROTOCOL;
321
331
  type: "init";
@@ -346,15 +356,18 @@ export type EmbedParentMessage = {
346
356
  size: number;
347
357
  data: ArrayBuffer;
348
358
  };
349
- /** iframe 发给外层页面的消息。 */
359
+ /** Messages the iframe sends to the outer page. */
350
360
  export type EmbedChildMessage =
351
- /** 高度为 CSS 像素,0–10000。 */
361
+ /** Height in CSS pixels, 0–10000. */
352
362
  {
353
363
  protocol: typeof EMBED_PROTOCOL;
354
364
  type: "resize";
355
365
  height: number;
356
366
  }
357
- /** 只允许站内路径:单个 `/` 开头、没有 `//`、没有 `.` / `..` 段(含 `%2e` 编码)、规范化后不变。 */
367
+ /**
368
+ * Only in-site paths: a single leading `/`, no `//`, no `.` / `..` segments (including `%2e`
369
+ * encoding), unchanged after normalization.
370
+ */
358
371
  | {
359
372
  protocol: typeof EMBED_PROTOCOL;
360
373
  type: "navigate";
@@ -365,7 +378,8 @@ export type EmbedChildMessage =
365
378
  text: string;
366
379
  };
367
380
  /**
368
- * 解析 iframe 发来的消息:协议、类型、字段都对才返回(只留已知字段的新对象),否则返回 null。
369
- * 外层页面还须先核对消息来源是这个 iframe。
381
+ * Parses a message sent by the iframe: returns it only when protocol, type and fields are all right
382
+ * (a new object keeping only known fields), otherwise null.
383
+ * The outer page must also first check that the message source is this iframe.
370
384
  */
371
385
  export declare function parseEmbedChildMessage(m: unknown): EmbedChildMessage | null;
package/dist/ui.js CHANGED
@@ -17,12 +17,13 @@ export const UI_ICONS = [
17
17
  "puzzle",
18
18
  ];
19
19
  /**
20
- * 视图上限({@link validateUiView} 统一检查):
21
- * - `blocks`:块数;
22
- * - `tableRows`:表格行数,也用作 keyValue 项数、表格列数、图表点数、按钮数的上限;
23
- * - `checklistItems`:清单项数;
24
- * - `textChars`:整个视图所有文本(含表单 JSON)的字符总数;
25
- * - `payloadBytes`:单个按钮 `payload` 的 JSON 序列化后 UTF-8 字节数。
20
+ * View limits (checked uniformly by {@link validateUiView}):
21
+ * - `blocks`: number of blocks;
22
+ * - `tableRows`: number of table rows, also used as the upper bound for keyValue items, table
23
+ * columns, chart points and buttons;
24
+ * - `checklistItems`: number of checklist items;
25
+ * - `textChars`: total characters of all text in the whole view (form JSON included);
26
+ * - `payloadBytes`: UTF-8 bytes of a single button `payload` after JSON serialization.
26
27
  * - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
27
28
  */
28
29
  export const UI_LIMITS = {
@@ -44,7 +45,7 @@ const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
44
45
  const MD_INLINE_LINK = /\]\(\s*<?([^\s)>]*)/g;
45
46
  const MD_REF_DEF = /^ {0,3}\[[^\]\n]+\]:[ \t]*<?([^\s>]*)/gm;
46
47
  const MD_AUTOLINK = /<([a-zA-Z][a-zA-Z0-9+.-]{1,31}:[^<>\s]*)>/g;
47
- /** Markdown 里的链接 / 图片目标(行内、引用定义、尖括号自动链接)。 */
48
+ /** Link / image targets in Markdown (inline, reference definitions, angle-bracket autolinks). */
48
49
  function markdownLinks(md) {
49
50
  const out = [];
50
51
  for (const re of [MD_INLINE_LINK, MD_REF_DEF, MD_AUTOLINK]) {
@@ -53,7 +54,7 @@ function markdownLinks(md) {
53
54
  }
54
55
  return out;
55
56
  }
56
- /** JSON 序列化后的 UTF-8 字节数;不可序列化返回 undefined。 */
57
+ /** UTF-8 bytes after JSON serialization; undefined when not serializable. */
57
58
  function jsonBytes(v) {
58
59
  try {
59
60
  const s = JSON.stringify(v);
@@ -109,9 +110,12 @@ function jsonProblem(v, at, seen = new Set()) {
109
110
  }
110
111
  }
111
112
  /**
112
- * 校验插件返回的视图,返回问题列表(空 = 合法)。链接与图片只允许 http(s) 绝对地址;
113
- * Markdown 的检查是纵深防御,网页渲染时仍须只认 http(s) 链接、不渲染原生 HTML。
114
- * 按钮与表单的 `actionId` 在整个视图内唯一(动作回调靠它区分来源)。
113
+ * Validates the view a plugin returns and returns the list of problems (empty = valid). Links and
114
+ * images may only be absolute http(s) addresses;
115
+ * the Markdown check is defense in depth, and web rendering must still accept only http(s) links
116
+ * and not render native HTML.
117
+ * The `actionId` of buttons and forms is unique within the whole view (action callbacks tell the
118
+ * source by it).
115
119
  * `data` is accepted only with `opts.component` (the view of a component contribution): JSON as is
116
120
  * (nothing JSON would drop or rewrite, see `jsonProblem`), up to `UI_LIMITS.componentDataBytes`
117
121
  * bytes of UTF-8.
@@ -346,22 +350,31 @@ export function validateUiView(v, opts = {}) {
346
350
  out.push(`view text must be at most ${UI_LIMITS.textChars} characters in total`);
347
351
  return out;
348
352
  }
349
- /** 外层页面与嵌入 iframe 之间 `postMessage` 协议的版本标识。 */
353
+ /**
354
+ * The version marker of the `postMessage` protocol between the outer page and the embedded iframe.
355
+ */
350
356
  export const EMBED_PROTOCOL = "capybara-embed/1";
351
357
  const NAV_MAX = 2000;
352
358
  const RESIZE_MAX = 10000;
353
359
  const TOAST_MAX = 500;
354
- // capybara:embed-nav-begin(这一段在 packages/plugin-sdk/src/ui.ts 与 apps/web/src/lib/embed-bridge.ts 里逐字相同,有测试核对)
355
- // 控制字符与反斜杠:浏览器会把 `/\host` 当成 `//host`,也会剥掉路径里的换行 / 制表符
356
- // biome-ignore lint/suspicious/noControlCharactersInRegex: 正是要拒绝控制字符
360
+ // capybara:embed-nav-begin (this section is verbatim identical in packages/plugin-sdk/src/ui.ts and apps/web/src/lib/embed-bridge.ts, checked by a test)
361
+ // Control characters and backslash: browsers treat `/\host` as `//host`, and strip newlines / tabs
362
+ // inside a path
363
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are exactly what must be rejected
357
364
  const NAV_BAD = /[\u0000-\u001f\u007f\\]/;
358
- /** 路径部分里编码的 `/`、`\` 与控制字符(任意大小写):解码后会改变路径结构。 */
365
+ /**
366
+ * Encoded `/`, `\` and control characters in the path part (any case): decoding them would change
367
+ * the path structure.
368
+ */
359
369
  const NAV_BAD_ENCODED = /%(?:2f|5c|[01][0-9a-f]|7f)/i;
360
370
  /**
361
- * 站内路径:以单个 `/` 开头,任何位置都没有 `//`,没有控制字符与反斜杠;路径部分没有 `.` / `..` 段
362
- * (含任意大小写的 `%2e` 编码),也没有编码的 `/`(`%2f`)、`\`(`%5c`)与控制字符(`%00`–`%1f`、`%7f`);
363
- * 且按 URL 规范化后与原文完全相同、不以 `//` 开头——规范化不会把它变成别的路径,
364
- * 交给站内路由时不会跳到站外或上层目录。
371
+ * In-site path: starts with a single `/`, has no `//` anywhere, no control characters or
372
+ * backslashes; the path part has no `.` / `..` segments
373
+ * (including `%2e` in any case), no encoded `/` (`%2f`), `\` (`%5c`) or control characters
374
+ * (`%00`–`%1f`, `%7f`);
375
+ * and after URL normalization it is exactly identical to the original and does not start with `//`:
376
+ * normalization cannot turn it into another path,
377
+ * so handing it to in-site routing cannot jump outside the site or to a parent directory.
365
378
  */
366
379
  function isInSitePath(p) {
367
380
  if (!p.startsWith("/") || p.includes("//") || NAV_BAD.test(p))
@@ -385,8 +398,9 @@ function isInSitePath(p) {
385
398
  }
386
399
  // capybara:embed-nav-end
387
400
  /**
388
- * 解析 iframe 发来的消息:协议、类型、字段都对才返回(只留已知字段的新对象),否则返回 null。
389
- * 外层页面还须先核对消息来源是这个 iframe。
401
+ * Parses a message sent by the iframe: returns it only when protocol, type and fields are all right
402
+ * (a new object keeping only known fields), otherwise null.
403
+ * The outer page must also first check that the message source is this iframe.
390
404
  */
391
405
  export function parseEmbedChildMessage(m) {
392
406
  if (!isObj(m) || m.protocol !== EMBED_PROTOCOL)
package/dist/url.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- /** 内部工具(index.ts 不导出):是否为 http(s) 绝对地址且长度不超过 max。 */
1
+ /**
2
+ * Internal helper (not exported by index.ts): whether it is an absolute http(s) address no longer
3
+ * than max.
4
+ */
2
5
  export declare function isHttpUrl(v: unknown, max?: number): boolean;
package/dist/url.js CHANGED
@@ -1,4 +1,7 @@
1
- /** 内部工具(index.ts 不导出):是否为 http(s) 绝对地址且长度不超过 max。 */
1
+ /**
2
+ * Internal helper (not exported by index.ts): whether it is an absolute http(s) address no longer
3
+ * than max.
4
+ */
2
5
  export function isHttpUrl(v, max = 2000) {
3
6
  if (typeof v !== "string" || v.length > max)
4
7
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.26",
3
+ "version": "0.1.0-rc.28",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {