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

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/config-ui.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { z } from "zod";
2
+ /** Every channel inbound mode, in the order forms list them. */
3
+ export const CHANNEL_INBOUND_MODES = ["long_connection", "webhook"];
2
4
  /** Limits of config UI hints and of the JSON Schemas a plugin package carries. */
3
5
  export const CONFIG_UI_LIMITS = {
4
6
  /** Characters per language of a `label` (also `unit`, `item.addLabel`). */
@@ -163,9 +165,18 @@ const HINT_KEYS = new Set([
163
165
  "secrets",
164
166
  "sections",
165
167
  "messages",
168
+ "inboundModes",
166
169
  ]);
167
170
  /** The only hints a secret node may carry. */
168
- const SECRET_HINT_KEYS = new Set(["label", "help", "placeholder", "order", "section", "advanced"]);
171
+ const SECRET_HINT_KEYS = new Set([
172
+ "label",
173
+ "help",
174
+ "placeholder",
175
+ "order",
176
+ "section",
177
+ "advanced",
178
+ "inboundModes",
179
+ ]);
169
180
  const ITEM_KEYS = new Set(["title", "subtitle", "addLabel", "reorder"]);
170
181
  const utf8Bytes = (s) => new TextEncoder().encode(s).length;
171
182
  /** The JSON types a node accepts (`type`, a type list, or the branches of a nullable `anyOf`). */
@@ -326,7 +337,7 @@ export function validateConfigUi(schema, level) {
326
337
  if (!isObj(raw))
327
338
  report("x-ui must be an object");
328
339
  else
329
- checkHints(raw, node, isRoot, report, text);
340
+ checkHints(raw, node, isRoot, depth, report, text);
330
341
  }
331
342
  const shape = shapeOf(node);
332
343
  const props = shape.properties;
@@ -343,7 +354,7 @@ export function validateConfigUi(schema, level) {
343
354
  visit(shape.additionalProperties, path === "" ? "additionalProperties" : `${path}.additionalProperties`, false, depth + 1);
344
355
  }
345
356
  };
346
- const checkHints = (h, node, isRoot, report, text) => {
357
+ const checkHints = (h, node, isRoot, depth, report, text) => {
347
358
  const shape = shapeOf(node);
348
359
  const types = typesOf(node);
349
360
  const isArray = types.has("array");
@@ -356,7 +367,7 @@ export function validateConfigUi(schema, level) {
356
367
  if (node["x-secret"] === true) {
357
368
  const bad = Object.keys(h).filter((k) => HINT_KEYS.has(k) && !SECRET_HINT_KEYS.has(k));
358
369
  if (bad.length > 0) {
359
- report(`a secret field allows only label, help, placeholder, order, section and advanced hints, not ${bad.join(", ")}`);
370
+ report(`a secret field allows only label, help, placeholder, order, section, advanced and inboundModes hints, not ${bad.join(", ")}`);
360
371
  }
361
372
  }
362
373
  text(h.label, "label", L.labelChars);
@@ -369,6 +380,28 @@ export function validateConfigUi(schema, level) {
369
380
  if (h.advanced !== undefined && typeof h.advanced !== "boolean") {
370
381
  report("advanced must be a boolean");
371
382
  }
383
+ if (h.inboundModes !== undefined) {
384
+ const modes = h.inboundModes;
385
+ if (level !== "connection") {
386
+ report(`inboundModes is only allowed at the connection level, not ${level}`);
387
+ }
388
+ else if (depth !== 1) {
389
+ report("inboundModes is only allowed on a top-level field of the config");
390
+ }
391
+ else if (!Array.isArray(modes) || modes.length === 0) {
392
+ report("inboundModes must be a non-empty array");
393
+ }
394
+ else {
395
+ modes.forEach((m, i) => {
396
+ if (!CHANNEL_INBOUND_MODES.includes(m)) {
397
+ report(`inboundModes[${i}] must be one of ${CHANNEL_INBOUND_MODES.join(", ")}`);
398
+ }
399
+ else if (modes.indexOf(m) !== i) {
400
+ report(`inboundModes[${i}] "${String(m)}" is listed twice`);
401
+ }
402
+ });
403
+ }
404
+ }
372
405
  if (h.section !== undefined) {
373
406
  if (typeof h.section !== "string" || !sectionIds.has(h.section)) {
374
407
  report(`section "${String(h.section)}" is not an id of the root's sections`);
@@ -600,3 +633,30 @@ export function validateConfigUi(schema, level) {
600
633
  }
601
634
  return problems;
602
635
  }
636
+ /**
637
+ * The top-level fields of a connection config's JSON Schema ({@link configJsonSchema}) that carry
638
+ * an `inboundModes` hint, with their modes (unknown modes dropped). Pure; fields without the hint
639
+ * belong to every mode and are not listed.
640
+ */
641
+ export function inboundModeFields(schema) {
642
+ const out = {};
643
+ for (const [key, node] of Object.entries(properties(schema))) {
644
+ const hints = isObj(node) ? node["x-ui"] : undefined;
645
+ const modes = isObj(hints) ? hints.inboundModes : undefined;
646
+ if (!Array.isArray(modes))
647
+ continue;
648
+ const known = CHANNEL_INBOUND_MODES.filter((m) => modes.includes(m));
649
+ if (known.length > 0)
650
+ out[key] = known;
651
+ }
652
+ return out;
653
+ }
654
+ /**
655
+ * The fields `mode` requires ({@link inboundModeFields}) for which `has(field)` is false, in schema
656
+ * order: what the kernel refuses on a channel connection create or config / mode change.
657
+ */
658
+ export function missingInboundModeFields(schema, mode, has) {
659
+ return Object.entries(inboundModeFields(schema))
660
+ .filter(([key, modes]) => modes.includes(mode) && !has(key))
661
+ .map(([key]) => key);
662
+ }
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.10";
1
+ export declare const SDK_VERSION = "0.1.0-rc.12";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
5
5
  export * from "./channel.js";
6
+ export * from "./client-css.js";
7
+ export * from "./client-section.js";
6
8
  export * from "./config-ui.js";
7
9
  export * from "./connector.js";
8
10
  export * from "./connector-auth.js";
@@ -37,6 +39,7 @@ export * from "./theme-tokens.generated.js";
37
39
  export * from "./tool.js";
38
40
  export * from "./tool-key.js";
39
41
  export * from "./ui.js";
42
+ export * from "./ui-parts.js";
40
43
  export * from "./ui-resolve.js";
41
44
  export * from "./ui-slots.js";
42
45
  export * from "./web.js";
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
- export const SDK_VERSION = "0.1.0-rc.10";
1
+ export const SDK_VERSION = "0.1.0-rc.12";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
5
5
  export * from "./channel.js";
6
+ export * from "./client-css.js";
7
+ export * from "./client-section.js";
6
8
  export * from "./config-ui.js";
7
9
  export * from "./connector.js";
8
10
  export * from "./connector-auth.js";
@@ -37,6 +39,7 @@ export * from "./theme-tokens.generated.js";
37
39
  export * from "./tool.js";
38
40
  export * from "./tool-key.js";
39
41
  export * from "./ui.js";
42
+ export * from "./ui-parts.js";
40
43
  export * from "./ui-resolve.js";
41
44
  export * from "./ui-slots.js";
42
45
  export * from "./web.js";
@@ -39,12 +39,19 @@ export interface ExtensionPermissions {
39
39
  /** 访问的域名,只展示不拦截。 */
40
40
  network?: string[];
41
41
  /**
42
- * 界面贡献的 id(与清单 `ui` 一一对应):`views` 记入快照但不卡加载;
43
- * `embeds` 卡加载、需批准,并标为敏感项。
42
+ * Client code: the package's `client` section (a browser bundle the web app loads for the
43
+ * extension's orgs). Sensitive and blocking; required when `ui.components` lists anything.
44
+ */
45
+ client?: boolean;
46
+ /**
47
+ * The ids of the `ui` contributions, one list per kind (each id in exactly one list): `views`
48
+ * are recorded in the snapshot without blocking the load; `embeds` and `components` block the
49
+ * load until approved and are sensitive. `components` needs `client: true`.
44
50
  */
45
51
  ui?: {
46
52
  views?: string[];
47
53
  embeds?: string[];
54
+ components?: string[];
48
55
  };
49
56
  /**
50
57
  * Setup check ids registered with `ctx.setup.check` (each matches `SETUP_CHECK_ID_RE`, at most
@@ -70,13 +77,16 @@ export declare class ExtensionPointUnavailableError extends Error {
70
77
  export declare function validatePermissions(plugin: string, p: unknown): string[];
71
78
  /**
72
79
  * Checks the structure of the manifest's `ui` and cross-checks it with the permission manifest;
73
- * returns the problems (empty = valid). Only structural problems (UI slots spec §3.2): each
74
- * contribution's id is listed in exactly `permissions.ui.views` (kind view) or
75
- * `permissions.ui.embeds` (kind embed), and `permissions.ui` lists no id the `ui` lacks; an embed's
76
- * path starts with `/ui/` and is declared in `permissions.http` as GET; exactly one of `slot` (a
77
- * well-formed slot reference) and `place` (a known place); for a slot the catalog knows at the
78
- * version named, a kind it accepts and, unless an alias, the icon it requires. An unknown slot id or version is not a
79
- * problem here: `resolveUiSlots` drops that contribution and the rest of the extension loads.
80
+ * returns the problems (empty = valid). Only structural problems (UI slots spec §3.2, client
81
+ * extensions spec §5.1): each contribution's id is listed in the list of its kind,
82
+ * `permissions.ui.views` (view), `permissions.ui.embeds` (embed) or `permissions.ui.components`
83
+ * (component), an id is in at most one of the three, and `permissions.ui` lists no id the `ui`
84
+ * lacks; `permissions.ui.components` needs `permissions.client: true`; an embed's path starts with
85
+ * `/ui/` and is declared in `permissions.http` as GET, a view or component has no path; exactly one
86
+ * of `slot` (a well-formed slot reference) and `place` (a known place); for a slot the catalog
87
+ * knows at the version named, a kind it accepts and, unless an alias, the icon it requires. An
88
+ * unknown slot id or version is not a problem here: `resolveUiSlots` drops that contribution and
89
+ * the rest of the extension loads.
80
90
  * Assumes `permissions` passed {@link validatePermissions}.
81
91
  */
82
92
  export declare function validateUiContributions(ui: unknown, permissions: unknown): string[];
@@ -38,6 +38,7 @@ const KEYS = new Set([
38
38
  "storage",
39
39
  "network",
40
40
  "ui",
41
+ "client",
41
42
  "setupChecks",
42
43
  ]);
43
44
  const POLICY = new Set(POLICY_HOOKS);
@@ -71,7 +72,7 @@ export function validatePermissions(plugin, p) {
71
72
  if (!KEYS.has(k))
72
73
  errs.push(`unknown permissions key "${k}"`);
73
74
  }
74
- for (const k of ["secrets", "storage"]) {
75
+ for (const k of ["secrets", "storage", "client"]) {
75
76
  if (p[k] !== undefined && typeof p[k] !== "boolean") {
76
77
  errs.push(`permissions.${k} must be a boolean`);
77
78
  }
@@ -129,9 +130,11 @@ export function validatePermissions(plugin, p) {
129
130
  errs.push("permissions.ui must be an object");
130
131
  else {
131
132
  for (const k of Object.keys(p.ui)) {
132
- if (k !== "views" && k !== "embeds")
133
+ if (k !== "views" && k !== "embeds" && k !== "components")
133
134
  errs.push(`unknown permissions.ui key "${k}"`);
134
135
  }
136
+ if (p.ui.components !== undefined)
137
+ strList("permissions.ui.components", p.ui.components, errs);
135
138
  const views = p.ui.views === undefined ? [] : strList("permissions.ui.views", p.ui.views, errs);
136
139
  const embeds = p.ui.embeds === undefined ? [] : strList("permissions.ui.embeds", p.ui.embeds, errs);
137
140
  for (const id of views) {
@@ -186,13 +189,16 @@ const UI_PLACES = Object.keys(PLACE_SLOTS);
186
189
  const UI_EMBED_PREFIX = "/ui/";
187
190
  /**
188
191
  * Checks the structure of the manifest's `ui` and cross-checks it with the permission manifest;
189
- * returns the problems (empty = valid). Only structural problems (UI slots spec §3.2): each
190
- * contribution's id is listed in exactly `permissions.ui.views` (kind view) or
191
- * `permissions.ui.embeds` (kind embed), and `permissions.ui` lists no id the `ui` lacks; an embed's
192
- * path starts with `/ui/` and is declared in `permissions.http` as GET; exactly one of `slot` (a
193
- * well-formed slot reference) and `place` (a known place); for a slot the catalog knows at the
194
- * version named, a kind it accepts and, unless an alias, the icon it requires. An unknown slot id or version is not a
195
- * problem here: `resolveUiSlots` drops that contribution and the rest of the extension loads.
192
+ * returns the problems (empty = valid). Only structural problems (UI slots spec §3.2, client
193
+ * extensions spec §5.1): each contribution's id is listed in the list of its kind,
194
+ * `permissions.ui.views` (view), `permissions.ui.embeds` (embed) or `permissions.ui.components`
195
+ * (component), an id is in at most one of the three, and `permissions.ui` lists no id the `ui`
196
+ * lacks; `permissions.ui.components` needs `permissions.client: true`; an embed's path starts with
197
+ * `/ui/` and is declared in `permissions.http` as GET, a view or component has no path; exactly one
198
+ * of `slot` (a well-formed slot reference) and `place` (a known place); for a slot the catalog
199
+ * knows at the version named, a kind it accepts and, unless an alias, the icon it requires. An
200
+ * unknown slot id or version is not a problem here: `resolveUiSlots` drops that contribution and
201
+ * the rest of the extension loads.
196
202
  * Assumes `permissions` passed {@link validatePermissions}.
197
203
  */
198
204
  export function validateUiContributions(ui, permissions) {
@@ -203,10 +209,21 @@ export function validateUiContributions(ui, permissions) {
203
209
  : [];
204
210
  const views = listed("views");
205
211
  const embeds = listed("embeds");
212
+ const components = listed("components");
213
+ // an id in more than one list is reported once, not again as a mismatch of each list
214
+ const multiListed = new Set();
215
+ for (const id of new Set([...views, ...embeds, ...components])) {
216
+ if ([views, embeds, components].filter((l) => l.includes(id)).length > 1)
217
+ multiListed.add(id);
218
+ }
206
219
  const gets = new Set((Array.isArray(perms.http) ? perms.http : [])
207
220
  .filter((r) => isObj(r) && r.method === "GET")
208
221
  .map((r) => r.path));
209
222
  const errs = [];
223
+ for (const id of multiListed)
224
+ errs.push(`ui "${id}" is listed in more than one of permissions.ui.views / embeds / components`);
225
+ if (components.length > 0 && perms.client !== true)
226
+ errs.push("permissions.ui.components needs permissions.client: true");
210
227
  const contributions = [];
211
228
  if (ui !== undefined) {
212
229
  if (!Array.isArray(ui))
@@ -249,8 +266,8 @@ export function validateUiContributions(ui, permissions) {
249
266
  }
250
267
  if (c.after !== undefined && typeof c.after !== "string")
251
268
  errs.push(`ui "${id}" after must be a string`);
252
- if (c.kind !== "view" && c.kind !== "embed") {
253
- errs.push(`ui "${id}" kind must be view or embed`);
269
+ if (c.kind !== "view" && c.kind !== "embed" && c.kind !== "component") {
270
+ errs.push(`ui "${id}" kind must be view, embed or component`);
254
271
  return;
255
272
  }
256
273
  if (c.icon !== undefined && !UI_ICONS.includes(c.icon))
@@ -273,11 +290,18 @@ export function validateUiContributions(ui, permissions) {
273
290
  if (c.kind === "view") {
274
291
  if (c.path !== undefined)
275
292
  errs.push(`ui "${id}" path is only allowed for kind embed`);
276
- if (!views.includes(id))
293
+ if (!views.includes(id) && !multiListed.has(id))
277
294
  errs.push(`ui "${id}" (view) must be listed in permissions.ui.views`);
278
295
  return;
279
296
  }
280
- if (!embeds.includes(id))
297
+ if (c.kind === "component") {
298
+ if (c.path !== undefined)
299
+ errs.push(`ui "${id}" is a component and cannot have a path`);
300
+ if (!components.includes(id) && !multiListed.has(id))
301
+ errs.push(`ui "${id}" is a component; list it in permissions.ui.components`);
302
+ return;
303
+ }
304
+ if (!embeds.includes(id) && !multiListed.has(id))
281
305
  errs.push(`ui "${id}" (embed) must be listed in permissions.ui.embeds`);
282
306
  if (typeof c.path !== "string" || !c.path.startsWith(UI_EMBED_PREFIX)) {
283
307
  errs.push(`ui "${id}" (embed) path must start with "${UI_EMBED_PREFIX}"`);
@@ -299,9 +323,13 @@ export function validateUiContributions(ui, permissions) {
299
323
  ["embeds", "embed", embeds],
300
324
  ]) {
301
325
  for (const id of ids) {
302
- if (seen.get(id) !== kind)
326
+ if (seen.get(id) !== kind && !multiListed.has(id))
303
327
  errs.push(`permissions.ui.${k} entry "${id}" has no matching ${kind} contribution in ui`);
304
328
  }
305
329
  }
330
+ for (const id of components) {
331
+ if (seen.get(id) !== "component" && !multiListed.has(id))
332
+ errs.push(`permissions.ui.components lists "${id}", which is not a component contribution`);
333
+ }
306
334
  return errs;
307
335
  }
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { type PluginClientSection } from "./client-section.js";
2
3
  import { type JsonSchema } from "./config-ui.js";
3
4
  import { type ConnectorTemplateSpec, type LocalizedName, type StaticExtensionManifest } from "./plugin-package.js";
4
5
  import { type PluginSetupGuide } from "./setup-guide.js";
@@ -49,6 +50,8 @@ export declare const PLUGIN_MANIFEST_LIMITS: {
49
50
  readonly publisherChars: 100;
50
51
  readonly displayNameChars: 100;
51
52
  readonly pathChars: 512;
53
+ /** Entries of `suggestedAppearance.replacements`. */
54
+ readonly appearanceReplacements: 8;
52
55
  };
53
56
  /** A plugin this one depends on: a plugin name and a semver range. */
54
57
  export interface PluginDependency {
@@ -90,6 +93,18 @@ export interface PluginExtensionSection {
90
93
  deployment?: JsonSchema;
91
94
  org?: JsonSchema;
92
95
  };
96
+ /** Browser code, styles and assets (needs `permissions.client: true`); see {@link PluginClientSection}. */
97
+ client?: PluginClientSection;
98
+ }
99
+ /**
100
+ * How the plugin suggests it should look when chosen (client extensions spec §6.5). Nothing applies
101
+ * on install; an admin applies it in one confirmed step.
102
+ */
103
+ export interface SuggestedAppearance {
104
+ /** A theme id (file base name) of this plugin. */
105
+ theme?: string;
106
+ /** Replaceable slot id → a `component` contribution id of this plugin's extension in that slot. */
107
+ replacements?: Record<string, string>;
93
108
  }
94
109
  /**
95
110
  * A plugin's description: a string (English) or `{ en, zh? }`, each ≤ 1024 characters. Read it
@@ -137,6 +152,8 @@ export interface PluginManifest {
137
152
  * {@link PluginSetupGuide}.
138
153
  */
139
154
  setupGuides?: PluginSetupGuide[];
155
+ /** See {@link SuggestedAppearance}. */
156
+ suggestedAppearance?: SuggestedAppearance;
140
157
  extension?: PluginExtensionSection;
141
158
  }
142
159
  /** A connector template file `connectors/<id>.json`; the template id is the file's base name. */
@@ -182,3 +199,8 @@ export declare function parsePluginManifest(json: unknown): PluginManifest | {
182
199
  export declare function parseConnectorTemplateFile(json: unknown): ConnectorTemplateFile | {
183
200
  errors: string[];
184
201
  };
202
+ /**
203
+ * The theme check of `suggestedAppearance` after the themes are known (the manifest may omit
204
+ * `themes` and let the scan find them): shared by the packer and the kernel.
205
+ */
206
+ export declare function appearanceIssues(manifest: PluginManifest, themeIds: readonly string[]): string[];
@@ -1,12 +1,14 @@
1
1
  import semver from "semver";
2
2
  import { z } from "zod";
3
3
  import { AGENT_TEMPLATE_LIMITS } from "./agent-template.js";
4
+ import { validateClientSection } from "./client-section.js";
4
5
  import { CONFIG_UI_LIMITS } from "./config-ui.js";
5
6
  import { defineExtension, EXTENSION_NAME_RE } from "./define-extension.js";
6
7
  import { CATALOG_ITEM_NAME_RE, CONNECTOR_TEMPLATE_LIMITS, isSafePackagePath, SEMVER_VERSION_RE, validateConnectorTemplate, } from "./plugin-package.js";
7
8
  import { hasUpperBound } from "./semver-range.js";
8
9
  import { SETUP_GUIDE_LIMITS, SETUP_GUIDE_PLACES } from "./setup-guide.js";
9
10
  import { THEME_LIMITS, themeIdOf } from "./theme.js";
11
+ import { parseSlotRef, uiSlot } from "./ui-slots.js";
10
12
  /**
11
13
  * The plugin manifest `.capybara-plugin/plugin.json` (package ecosystem spec §4.1). A plugin is a
12
14
  * bundle of at most one extension, skills, connector templates, agent templates and themes, packed as
@@ -53,6 +55,8 @@ export const PLUGIN_MANIFEST_LIMITS = {
53
55
  publisherChars: 100,
54
56
  displayNameChars: 100,
55
57
  pathChars: 512,
58
+ /** Entries of `suggestedAppearance.replacements`. */
59
+ appearanceReplacements: 8,
56
60
  };
57
61
  /** A plugin description as `{ en, zh? }` (a plain string is the English text). */
58
62
  export function pluginDescription(d) {
@@ -61,6 +65,7 @@ export function pluginDescription(d) {
61
65
  const L = PLUGIN_MANIFEST_LIMITS;
62
66
  const MAX_ERRORS = 50;
63
67
  const ICON_RE = /\.(?:svg|png)$/i;
68
+ const COMPONENT_ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
64
69
  const HTTPS_URL_RE = /^https:\/\/\S+$/;
65
70
  const text = (max, what) => z
66
71
  .string()
@@ -113,6 +118,25 @@ const setupGuide = z.strictObject({
113
118
  .regex(CATALOG_ITEM_NAME_RE, { message: "template must match ^[a-z0-9][a-z0-9-]{0,63}$" })
114
119
  .optional(),
115
120
  });
121
+ const clientSection = z
122
+ .strictObject({
123
+ entry: z.string().max(L.pathChars).optional(),
124
+ styles: z.array(z.string().max(L.pathChars)).max(64).optional(),
125
+ assets: z.array(z.string().max(L.pathChars)).max(256).optional(),
126
+ integrity: z.record(z.string().max(L.pathChars), z.string().max(128)),
127
+ apiVersion: z.number().int().min(1),
128
+ })
129
+ .superRefine((c, ctx) => {
130
+ for (const e of validateClientSection(c))
131
+ ctx.addIssue({ code: "custom", path: [], message: e });
132
+ });
133
+ const suggestedAppearance = z.strictObject({
134
+ theme: z
135
+ .string()
136
+ .regex(CATALOG_ITEM_NAME_RE, { message: "theme must match ^[a-z0-9][a-z0-9-]{0,63}$" })
137
+ .optional(),
138
+ replacements: z.record(z.string().max(100), z.string().max(100)).optional(),
139
+ });
116
140
  const extensionSection = z.strictObject({
117
141
  entry: dotPath("entry").refine((p) => p.endsWith(".mjs"), {
118
142
  message: "entry must be a .mjs file",
@@ -123,6 +147,7 @@ const extensionSection = z.strictObject({
123
147
  configSchemas: z
124
148
  .strictObject({ deployment: configSchemaJson.optional(), org: configSchemaJson.optional() })
125
149
  .optional(),
150
+ client: clientSection.optional(),
126
151
  });
127
152
  const schema = z
128
153
  .strictObject({
@@ -191,6 +216,7 @@ const schema = z
191
216
  .max(L.themes)
192
217
  .optional(),
193
218
  setupGuides: z.array(setupGuide).max(SETUP_GUIDE_LIMITS.guides).optional(),
219
+ suggestedAppearance: suggestedAppearance.optional(),
194
220
  extension: extensionSection.optional(),
195
221
  })
196
222
  .superRefine((m, ctx) => {
@@ -272,6 +298,56 @@ const schema = z
272
298
  issue(["setupGuides", i, "place"], "a channel-connection guide needs the plugin's extension to provide channel@1");
273
299
  }
274
300
  });
301
+ const sa = m.suggestedAppearance;
302
+ if (sa !== undefined) {
303
+ const at = ["suggestedAppearance"];
304
+ if (sa.theme === undefined && sa.replacements === undefined) {
305
+ issue(at, "suggestedAppearance needs theme or replacements");
306
+ }
307
+ if (sa.theme !== undefined && m.themes !== undefined && !themeIds.has(sa.theme)) {
308
+ issue([...at, "theme"], `suggestedAppearance.theme names ${sa.theme}, which is not a theme of the plugin`);
309
+ }
310
+ if (sa.replacements !== undefined) {
311
+ const entries = Object.entries(sa.replacements);
312
+ if (m.extension === undefined) {
313
+ issue([...at, "replacements"], "suggestedAppearance.replacements needs an extension");
314
+ }
315
+ if (entries.length > L.appearanceReplacements) {
316
+ issue([...at, "replacements"], `suggestedAppearance.replacements has ${entries.length} entries; the limit is ${L.appearanceReplacements}`);
317
+ }
318
+ const seen = new Set();
319
+ for (const [slot, id] of entries) {
320
+ const ref = parseSlotRef(slot);
321
+ if (ref === null) {
322
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} is not a slot ref`);
323
+ continue;
324
+ }
325
+ if (seen.has(ref.id)) {
326
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names the slot ${ref.id} again; give each slot once`);
327
+ continue;
328
+ }
329
+ seen.add(ref.id);
330
+ if (!COMPONENT_ID_RE.test(id)) {
331
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names ${id}, which is not a contribution id`);
332
+ continue;
333
+ }
334
+ const known = uiSlot(ref.id);
335
+ if (known === undefined)
336
+ continue;
337
+ if (known.cardinality !== "single") {
338
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} is not a replaceable slot`);
339
+ continue;
340
+ }
341
+ const ok = (m.extension?.manifest.ui ?? []).some((u) => {
342
+ const us = typeof u.slot === "string" ? parseSlotRef(u.slot) : null;
343
+ return u.id === id && u.kind === "component" && us?.id === ref.id;
344
+ });
345
+ if (!ok) {
346
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names ${id}, which is not a component contribution in that slot`);
347
+ }
348
+ }
349
+ }
350
+ }
275
351
  if (m.extension === undefined &&
276
352
  m.skills?.length === 0 &&
277
353
  m.connectorTemplates?.length === 0 &&
@@ -283,6 +359,13 @@ const schema = z
283
359
  if (ext === undefined)
284
360
  return;
285
361
  const em = ext.manifest;
362
+ const hasClientPermission = em.permissions.client === true;
363
+ if (ext.client !== undefined && !hasClientPermission) {
364
+ issue(["extension", "client"], "extension.client needs permissions.client: true");
365
+ }
366
+ if (ext.client === undefined && hasClientPermission) {
367
+ issue(["extension", "manifest", "permissions", "client"], "permissions.client is true but extension.client is missing (pack the plugin with its client code, or drop permissions.client)");
368
+ }
286
369
  if (!EXTENSION_NAME_RE.test(m.name)) {
287
370
  issue(["name"], `a plugin with an extension needs an extension name (${EXTENSION_NAME_RE})`);
288
371
  }
@@ -407,3 +490,13 @@ export function parsePluginManifest(json) {
407
490
  export function parseConnectorTemplateFile(json) {
408
491
  return parseWith(ConnectorTemplateFileSchema, json, "connector template file");
409
492
  }
493
+ /**
494
+ * The theme check of `suggestedAppearance` after the themes are known (the manifest may omit
495
+ * `themes` and let the scan find them): shared by the packer and the kernel.
496
+ */
497
+ export function appearanceIssues(manifest, themeIds) {
498
+ const theme = manifest.suggestedAppearance?.theme;
499
+ if (theme === undefined || themeIds.includes(theme))
500
+ return [];
501
+ return [`suggestedAppearance.theme names ${theme}, which is not a theme of the plugin`];
502
+ }
package/dist/theme.d.ts CHANGED
@@ -108,7 +108,7 @@ export interface ParseThemeOptions {
108
108
  */
109
109
  readability?: boolean;
110
110
  }
111
- /** `themes/night-city.json` → `night-city`. */
111
+ /** `themes/neon-grid.json` → `neon-grid`. */
112
112
  export declare function themeIdOf(path: string): string;
113
113
  /**
114
114
  * The zod schema of a theme file's shape (strict objects). Token names and values are only
package/dist/theme.js CHANGED
@@ -42,7 +42,7 @@ export const THEME_LIMITS = {
42
42
  /** Characters of the wordmark. */
43
43
  wordmark: 24,
44
44
  };
45
- /** `themes/night-city.json` → `night-city`. */
45
+ /** `themes/neon-grid.json` → `neon-grid`. */
46
46
  export function themeIdOf(path) {
47
47
  return (path.split("/").pop() ?? "").replace(/\.json$/, "");
48
48
  }
@@ -0,0 +1,23 @@
1
+ /** The ARIA / data states a part promises (client extensions spec §7.1). */
2
+ export type UiPartState = "aria-current" | "aria-selected" | "aria-expanded" | "aria-busy" | "disabled";
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.assistant", "tool-row", "composer", "properties-panel", "section", "right-panel", "status-bar", "button", "button.primary", "card", "input", "dialog"];
5
+ export type UiPartName = (typeof UI_PART_NAMES)[number];
6
+ /** One built-in element plugin CSS may select with `[data-cap-part~="<name>"]`. */
7
+ export interface UiPartSpec {
8
+ name: UiPartName;
9
+ /** Bumped when the part is renamed, removed or drops a promised state. */
10
+ version: number;
11
+ /**
12
+ * The files (relative to the repository root) that render the element: one concept can be drawn
13
+ * by several components (a sidebar row, a card). `check:ui-parts` pins each literal to one of them.
14
+ */
15
+ owner: readonly string[];
16
+ states: readonly UiPartState[];
17
+ description: {
18
+ en: string;
19
+ zh: string;
20
+ };
21
+ }
22
+ export declare const UI_PARTS: readonly UiPartSpec[];
23
+ export declare function uiPart(name: string): UiPartSpec | undefined;