@capybara-hq/plugin-sdk 0.1.0-rc.10 → 0.1.0-rc.11

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.
package/dist/ui-slots.js CHANGED
@@ -8,6 +8,10 @@ export const UI_SLOT_IDS = [
8
8
  "agent.detail.section",
9
9
  "org.settings.section",
10
10
  "platform.page",
11
+ "shell.brand",
12
+ "shell.overlay",
13
+ "conversation.empty",
14
+ "conversation.composer.frame",
11
15
  ];
12
16
  const SLOT_DATA = [
13
17
  {
@@ -15,7 +19,7 @@ const SLOT_DATA = [
15
19
  version: 1,
16
20
  owner: "components/conversation/RightArea.tsx",
17
21
  scope: "conversation",
18
- accepts: ["view", "embed"],
22
+ accepts: ["view", "embed", "component"],
19
23
  cardinality: "list",
20
24
  minRole: "guest",
21
25
  args: ["conversationId", "item"],
@@ -31,7 +35,7 @@ const SLOT_DATA = [
31
35
  version: 1,
32
36
  owner: "components/conversation/PropertiesSections.tsx",
33
37
  scope: "conversation",
34
- accepts: ["view", "embed"],
38
+ accepts: ["view", "embed", "component"],
35
39
  cardinality: "list",
36
40
  minRole: "guest",
37
41
  args: ["conversationId"],
@@ -48,7 +52,7 @@ const SLOT_DATA = [
48
52
  version: 1,
49
53
  owner: "components/conversation/RightArea.tsx",
50
54
  scope: "conversation",
51
- accepts: ["view", "embed"],
55
+ accepts: ["view", "embed", "component"],
52
56
  cardinality: "list",
53
57
  minRole: "guest",
54
58
  args: ["conversationId", "card"],
@@ -64,7 +68,7 @@ const SLOT_DATA = [
64
68
  version: 1,
65
69
  owner: "app/(app)/p/[plugin]/[id]/view.tsx",
66
70
  scope: "org",
67
- accepts: ["view", "embed"],
71
+ accepts: ["view", "embed", "component"],
68
72
  cardinality: "list",
69
73
  minRole: "member",
70
74
  args: [],
@@ -96,7 +100,7 @@ const SLOT_DATA = [
96
100
  version: 1,
97
101
  owner: "components/agent/AgentPage.tsx",
98
102
  scope: "agent",
99
- accepts: ["view", "embed"],
103
+ accepts: ["view", "embed", "component"],
100
104
  cardinality: "list",
101
105
  minRole: "guest",
102
106
  args: ["agentId"],
@@ -112,7 +116,7 @@ const SLOT_DATA = [
112
116
  version: 1,
113
117
  owner: "app/(app)/settings/organization/view.tsx",
114
118
  scope: "org",
115
- accepts: ["view", "embed"],
119
+ accepts: ["view", "embed", "component"],
116
120
  cardinality: "list",
117
121
  minRole: "admin",
118
122
  args: [],
@@ -128,7 +132,7 @@ const SLOT_DATA = [
128
132
  version: 1,
129
133
  owner: "app/(app)/admin/p/[plugin]/[id]/view.tsx",
130
134
  scope: "platform",
131
- accepts: ["view", "embed"],
135
+ accepts: ["view", "embed", "component"],
132
136
  cardinality: "list",
133
137
  minRole: "superAdmin",
134
138
  args: [],
@@ -139,6 +143,77 @@ const SLOT_DATA = [
139
143
  zh: "平台管理中的完整页面。",
140
144
  },
141
145
  },
146
+ {
147
+ id: "shell.brand",
148
+ version: 1,
149
+ owner: "components/shell/AppFrame.tsx",
150
+ scope: "org",
151
+ accepts: ["component"],
152
+ cardinality: "single",
153
+ replaceable: true,
154
+ builtin: { en: "The logo and wordmark in the sidebar.", zh: "侧边栏中的标志与字标。" },
155
+ minRole: "guest",
156
+ args: [],
157
+ density: "regular",
158
+ icon: "none",
159
+ description: {
160
+ en: "The brand row of the sidebar (the mark of the collapsed rail).",
161
+ zh: "侧边栏的品牌行(收起后的窄栏标记)。",
162
+ },
163
+ },
164
+ {
165
+ id: "shell.overlay",
166
+ version: 1,
167
+ owner: "components/shell/AppFrame.tsx",
168
+ scope: "org",
169
+ accepts: ["component"],
170
+ cardinality: "list",
171
+ minRole: "guest",
172
+ args: [],
173
+ density: "regular",
174
+ icon: "none",
175
+ limits: { maxShown: 4 },
176
+ description: {
177
+ en: "A full-viewport layer over the workspace shell.",
178
+ zh: "覆盖工作区外壳的全视口图层。",
179
+ },
180
+ },
181
+ {
182
+ id: "conversation.empty",
183
+ version: 1,
184
+ owner: "components/conversation/NewConversation.tsx",
185
+ scope: "org",
186
+ accepts: ["component"],
187
+ cardinality: "single",
188
+ replaceable: true,
189
+ builtin: { en: "The greeting of the new-conversation page.", zh: "新对话页的问候区。" },
190
+ minRole: "guest",
191
+ args: [],
192
+ density: "regular",
193
+ icon: "none",
194
+ description: {
195
+ en: "The hero of the new-conversation page.",
196
+ zh: "新对话页的主视觉区。",
197
+ },
198
+ },
199
+ {
200
+ id: "conversation.composer.frame",
201
+ version: 1,
202
+ owner: "components/conversation/ComposerBar.tsx",
203
+ scope: "org",
204
+ accepts: ["component"],
205
+ cardinality: "single",
206
+ replaceable: true,
207
+ builtin: { en: "The frame around the message composer.", zh: "消息输入框外的边框。" },
208
+ minRole: "guest",
209
+ args: [],
210
+ density: "regular",
211
+ icon: "none",
212
+ description: {
213
+ en: "The frame around the composer, on the new-conversation and conversation pages.",
214
+ zh: "新对话页与对话页中输入框外的边框。",
215
+ },
216
+ },
142
217
  ];
143
218
  export const UI_SLOTS = SLOT_DATA;
144
219
  export function uiSlot(id) {
@@ -162,6 +237,10 @@ export const PLACE_SLOTS = {
162
237
  "file-preview": "file.preview",
163
238
  };
164
239
  export const UI_ARRANGEABLE_SLOTS = UI_SLOT_IDS.filter((id) => id !== "file.preview");
240
+ /** Slots with one winner that replaces a built-in block. */
241
+ export const UI_SINGLE_SLOTS = UI_SLOTS.filter((s) => s.cardinality === "single").map((s) => s.id);
242
+ /** Slots that accept the `component` kind. */
243
+ export const UI_COMPONENT_SLOTS = UI_SLOTS.filter((s) => s.accepts.includes("component")).map((s) => s.id);
165
244
  export const UI_CONTRIBUTION_KEY_RE = /^[a-z][a-z0-9-]{1,40}\/[a-z][a-z0-9-]{0,39}$/;
166
245
  export function uiContributionKey(plugin, id) {
167
246
  return `${plugin}/${id}`;
package/dist/ui.d.ts CHANGED
@@ -23,11 +23,17 @@ export interface UiOpen {
23
23
  contribution: string;
24
24
  item?: string;
25
25
  }
26
- /** 界面贡献的种类:`view` = 渲染 schema(由我们的组件画);`embed` = 插件自己的页面放进 iframe。 */
27
- export type UiKind = "view" | "embed";
28
26
  /**
29
- * 插件清单 `ui` 里的一项界面贡献。`id` 必须同时出现在 `permissions.ui.views`(kind view)
30
- * 或 `permissions.ui.embeds`(kind embed)里;`embed` 的页面由插件路由提供。
27
+ * The kind of a UI contribution: `view` = a render schema drawn by the host's components; `embed` =
28
+ * the extension's own page in an iframe; `component` = a React component from the extension's
29
+ * client code (client extensions spec §5).
30
+ */
31
+ export type UiKind = "view" | "embed" | "component";
32
+ /**
33
+ * One UI contribution of the extension manifest's `ui`. Its `id` must be listed in the list of its
34
+ * kind: `permissions.ui.views` (view), `permissions.ui.embeds` (embed) or
35
+ * `permissions.ui.components` (component, which also needs `permissions.client: true`); an embed's
36
+ * page is served by an extension route.
31
37
  */
32
38
  export interface UiContribution {
33
39
  id: string;
@@ -49,7 +55,7 @@ export interface UiContribution {
49
55
  */
50
56
  after?: string;
51
57
  kind: UiKind;
52
- /** 仅 embed:插件路由下 `/ui/` 开头的路径,须在 `permissions.http` 中声明为 GET。 */
58
+ /** Embed only: a path under `/ui/` of the extension's routes, declared in `permissions.http` as GET. */
53
59
  path?: string;
54
60
  /** Icon from {@link UI_ICONS}; default `puzzle`. */
55
61
  icon?: UiIcon;
@@ -129,12 +135,22 @@ export type UiBlock = {
129
135
  actionId: string;
130
136
  submitLabel: string;
131
137
  };
138
+ /** A JSON value: what survives `JSON.stringify` and `JSON.parse` unchanged. */
139
+ export type JsonValue = string | number | boolean | null | JsonValue[] | {
140
+ [key: string]: JsonValue;
141
+ };
132
142
  /** 插件视图:有上限的块列表;`badge` 显示在标签上(如「2/4」)。 */
133
143
  export interface UiView {
134
144
  badge?: string;
135
145
  /** The ⤢ of an inline card's title row and a properties section's header. */
136
146
  open?: UiOpen;
147
+ /** A component's view may have no blocks (`[]`). */
137
148
  blocks: UiBlock[];
149
+ /**
150
+ * Only from a component's render (`useView` hands it to the component): at most
151
+ * `UI_LIMITS.componentDataBytes` bytes of JSON. Refused in the views of the other kinds.
152
+ */
153
+ data?: JsonValue;
138
154
  }
139
155
  /**
140
156
  * 视图上限({@link validateUiView} 统一检查):
@@ -143,6 +159,7 @@ export interface UiView {
143
159
  * - `checklistItems`:清单项数;
144
160
  * - `textChars`:整个视图所有文本(含表单 JSON)的字符总数;
145
161
  * - `payloadBytes`:单个按钮 `payload` 的 JSON 序列化后 UTF-8 字节数。
162
+ * - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
146
163
  */
147
164
  export declare const UI_LIMITS: {
148
165
  readonly blocks: 50;
@@ -150,13 +167,19 @@ export declare const UI_LIMITS: {
150
167
  readonly checklistItems: 100;
151
168
  readonly textChars: 20000;
152
169
  readonly payloadBytes: 2000;
170
+ readonly componentDataBytes: 32768;
153
171
  };
154
172
  /**
155
173
  * 校验插件返回的视图,返回问题列表(空 = 合法)。链接与图片只允许 http(s) 绝对地址;
156
174
  * Markdown 的检查是纵深防御,网页渲染时仍须只认 http(s) 链接、不渲染原生 HTML。
157
175
  * 按钮与表单的 `actionId` 在整个视图内唯一(动作回调靠它区分来源)。
176
+ * `data` is accepted only with `opts.component` (the view of a component contribution): JSON as is
177
+ * (nothing JSON would drop or rewrite, see `jsonProblem`), up to `UI_LIMITS.componentDataBytes`
178
+ * bytes of UTF-8.
158
179
  */
159
- export declare function validateUiView(v: unknown): string[];
180
+ export declare function validateUiView(v: unknown, opts?: {
181
+ component?: boolean;
182
+ }): string[];
160
183
  /**
161
184
  * The caller's role in the org (owner / admin / member / guest, highest first). A slot's `minRole`
162
185
  * decides who may use its contributions, then its scope's rule (the kernel answers 404 to anyone
package/dist/ui.js CHANGED
@@ -23,6 +23,7 @@ export const UI_ICONS = [
23
23
  * - `checklistItems`:清单项数;
24
24
  * - `textChars`:整个视图所有文本(含表单 JSON)的字符总数;
25
25
  * - `payloadBytes`:单个按钮 `payload` 的 JSON 序列化后 UTF-8 字节数。
26
+ * - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
26
27
  */
27
28
  export const UI_LIMITS = {
28
29
  blocks: 50,
@@ -30,6 +31,7 @@ export const UI_LIMITS = {
30
31
  checklistItems: 100,
31
32
  textChars: 20000,
32
33
  payloadBytes: 2000,
34
+ componentDataBytes: 32768,
33
35
  };
34
36
  const BADGE_MAX = 32;
35
37
  /** Longest item / block `id` and open target `item`. */
@@ -61,15 +63,77 @@ function jsonBytes(v) {
61
63
  return undefined;
62
64
  }
63
65
  }
66
+ const JSON_KINDS = "null, booleans, finite numbers, strings, arrays, plain objects";
67
+ /**
68
+ * The first part of `v` (`at` is its path) that JSON would not carry as is, or undefined: a value
69
+ * `JSON.stringify` drops, rewrites or throws on (a function, symbol or bigint, NaN or ±Infinity,
70
+ * `undefined` in an array, an object that is not plain such as a Map or a Date, a cycle). A plain
71
+ * object's `undefined` property is accepted: JSON drops it, which reads as an absent optional field.
72
+ */
73
+ function jsonProblem(v, at, seen = new Set()) {
74
+ if (v === null || typeof v === "boolean" || typeof v === "string")
75
+ return undefined;
76
+ if (typeof v === "number")
77
+ return Number.isFinite(v) ? undefined : `${at} is ${v}`;
78
+ if (v === undefined)
79
+ return `${at} is undefined`;
80
+ if (typeof v !== "object")
81
+ return `${at} is a ${typeof v}`;
82
+ if (seen.has(v))
83
+ return `${at} is a cycle`;
84
+ seen.add(v);
85
+ try {
86
+ if (Array.isArray(v)) {
87
+ for (let i = 0; i < v.length; i++) {
88
+ const p = jsonProblem(v[i], `${at}[${i}]`, seen);
89
+ if (p !== undefined)
90
+ return p;
91
+ }
92
+ return undefined;
93
+ }
94
+ const proto = Object.getPrototypeOf(v);
95
+ if (proto !== Object.prototype && proto !== null) {
96
+ return `${at} is a ${proto.constructor?.name || "non-plain object"}`;
97
+ }
98
+ for (const [k, x] of Object.entries(v)) {
99
+ if (x === undefined)
100
+ continue;
101
+ const p = jsonProblem(x, `${at}.${k}`, seen);
102
+ if (p !== undefined)
103
+ return p;
104
+ }
105
+ return undefined;
106
+ }
107
+ finally {
108
+ seen.delete(v);
109
+ }
110
+ }
64
111
  /**
65
112
  * 校验插件返回的视图,返回问题列表(空 = 合法)。链接与图片只允许 http(s) 绝对地址;
66
113
  * Markdown 的检查是纵深防御,网页渲染时仍须只认 http(s) 链接、不渲染原生 HTML。
67
114
  * 按钮与表单的 `actionId` 在整个视图内唯一(动作回调靠它区分来源)。
115
+ * `data` is accepted only with `opts.component` (the view of a component contribution): JSON as is
116
+ * (nothing JSON would drop or rewrite, see `jsonProblem`), up to `UI_LIMITS.componentDataBytes`
117
+ * bytes of UTF-8.
68
118
  */
69
- export function validateUiView(v) {
119
+ export function validateUiView(v, opts = {}) {
70
120
  if (!isObj(v))
71
121
  return ["view must be an object"];
72
122
  const out = [];
123
+ if (v.data !== undefined) {
124
+ if (opts.component !== true)
125
+ out.push("view data is only allowed for component views");
126
+ else {
127
+ const problem = jsonProblem(v.data, "data");
128
+ if (problem !== undefined)
129
+ out.push(`view data must be JSON (${JSON_KINDS}): ${problem}`);
130
+ else {
131
+ const n = jsonBytes(v.data) ?? 0;
132
+ if (n > UI_LIMITS.componentDataBytes)
133
+ out.push(`view data is ${n} bytes; the limit is ${UI_LIMITS.componentDataBytes}`);
134
+ }
135
+ }
136
+ }
73
137
  let chars = 0;
74
138
  const text = (at, s, nonEmpty = false) => {
75
139
  if (typeof s !== "string" || (nonEmpty && s === "")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.10",
3
+ "version": "0.1.0-rc.11",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -242,6 +242,27 @@
242
242
  "additionalProperties": false
243
243
  }
244
244
  },
245
+ "suggestedAppearance": {
246
+ "type": "object",
247
+ "properties": {
248
+ "theme": {
249
+ "type": "string",
250
+ "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
251
+ },
252
+ "replacements": {
253
+ "type": "object",
254
+ "propertyNames": {
255
+ "type": "string",
256
+ "maxLength": 100
257
+ },
258
+ "additionalProperties": {
259
+ "type": "string",
260
+ "maxLength": 100
261
+ }
262
+ }
263
+ },
264
+ "additionalProperties": false
265
+ },
245
266
  "extension": {
246
267
  "type": "object",
247
268
  "properties": {
@@ -403,6 +424,52 @@
403
424
  }
404
425
  },
405
426
  "additionalProperties": false
427
+ },
428
+ "client": {
429
+ "type": "object",
430
+ "properties": {
431
+ "entry": {
432
+ "type": "string",
433
+ "maxLength": 512
434
+ },
435
+ "styles": {
436
+ "maxItems": 64,
437
+ "type": "array",
438
+ "items": {
439
+ "type": "string",
440
+ "maxLength": 512
441
+ }
442
+ },
443
+ "assets": {
444
+ "maxItems": 256,
445
+ "type": "array",
446
+ "items": {
447
+ "type": "string",
448
+ "maxLength": 512
449
+ }
450
+ },
451
+ "integrity": {
452
+ "type": "object",
453
+ "propertyNames": {
454
+ "type": "string",
455
+ "maxLength": 512
456
+ },
457
+ "additionalProperties": {
458
+ "type": "string",
459
+ "maxLength": 128
460
+ }
461
+ },
462
+ "apiVersion": {
463
+ "type": "integer",
464
+ "minimum": 1,
465
+ "maximum": 9007199254740991
466
+ }
467
+ },
468
+ "required": [
469
+ "integrity",
470
+ "apiVersion"
471
+ ],
472
+ "additionalProperties": false
406
473
  }
407
474
  },
408
475
  "required": [