@capybara-hq/plugin-sdk 0.1.0-rc.2 → 0.1.0-rc.21

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 (108) hide show
  1. package/README.md +1 -1
  2. package/agent-docs/agent-templates.md +59 -0
  3. package/agent-docs/concepts.md +63 -0
  4. package/agent-docs/connector-templates.md +48 -0
  5. package/agent-docs/extension-points/channel.md +15 -0
  6. package/agent-docs/extension-points/config-source.md +15 -0
  7. package/agent-docs/extension-points/connector.md +15 -0
  8. package/agent-docs/extension-points/context.md +15 -0
  9. package/agent-docs/extension-points/counter.md +15 -0
  10. package/agent-docs/extension-points/directory.md +15 -0
  11. package/agent-docs/extension-points/file-preview.md +15 -0
  12. package/agent-docs/extension-points/identity-source.md +15 -0
  13. package/agent-docs/extension-points/model-provider.md +15 -0
  14. package/agent-docs/extension-points/object-store.md +15 -0
  15. package/agent-docs/extension-points/sandbox.md +15 -0
  16. package/agent-docs/extension-points/secret-store.md +15 -0
  17. package/agent-docs/extension-points/web-fetch.md +15 -0
  18. package/agent-docs/extension-points/web-search.md +15 -0
  19. package/agent-docs/extensions.md +88 -0
  20. package/agent-docs/plugin-format.md +100 -0
  21. package/agent-docs/setup.md +46 -0
  22. package/agent-docs/skills.md +44 -0
  23. package/agent-docs/tool-naming.md +21 -0
  24. package/dist/agent-template.d.ts +96 -2
  25. package/dist/agent-template.js +381 -3
  26. package/dist/bootstrap.d.ts +15 -1
  27. package/dist/bootstrap.js +17 -1
  28. package/dist/cards.d.ts +39 -5
  29. package/dist/cards.js +70 -11
  30. package/dist/channel.d.ts +20 -1
  31. package/dist/client-css.d.ts +36 -0
  32. package/dist/client-css.js +326 -0
  33. package/dist/client-section.d.ts +35 -0
  34. package/dist/client-section.js +133 -0
  35. package/dist/config-ui.d.ts +24 -1
  36. package/dist/config-ui.js +89 -11
  37. package/dist/connector-auth.d.ts +2 -0
  38. package/dist/connector-auth.js +15 -0
  39. package/dist/context.d.ts +40 -0
  40. package/dist/context.js +2 -0
  41. package/dist/ctx.d.ts +86 -4
  42. package/dist/define-extension.d.ts +5 -1
  43. package/dist/define-extension.js +1 -0
  44. package/dist/dev-hosts.d.ts +6 -0
  45. package/dist/dev-hosts.js +48 -0
  46. package/dist/device-protocol.d.ts +260 -0
  47. package/dist/device-protocol.js +496 -0
  48. package/dist/directory.d.ts +11 -2
  49. package/dist/extension-point.d.ts +6 -0
  50. package/dist/extension-point.js +19 -14
  51. package/dist/file-preview.d.ts +9 -1
  52. package/dist/git-hosts.d.ts +44 -0
  53. package/dist/git-hosts.js +81 -0
  54. package/dist/hooks.d.ts +111 -15
  55. package/dist/hooks.js +5 -0
  56. package/dist/index.d.ts +19 -1
  57. package/dist/index.js +19 -1
  58. package/dist/marketplace.d.ts +55 -2
  59. package/dist/marketplace.js +73 -3
  60. package/dist/model.d.ts +60 -2
  61. package/dist/model.js +22 -0
  62. package/dist/org-access.d.ts +27 -0
  63. package/dist/org-access.js +35 -0
  64. package/dist/permissions.d.ts +33 -8
  65. package/dist/permissions.js +89 -22
  66. package/dist/plugin-manifest.d.ts +60 -7
  67. package/dist/plugin-manifest.js +180 -7
  68. package/dist/plugin-package.d.ts +3 -0
  69. package/dist/plugin-package.js +4 -0
  70. package/dist/sandbox.d.ts +239 -62
  71. package/dist/sandbox.js +99 -14
  72. package/dist/setup-check.d.ts +115 -0
  73. package/dist/setup-check.js +142 -0
  74. package/dist/setup-guide-parse.d.ts +121 -0
  75. package/dist/setup-guide-parse.js +350 -0
  76. package/dist/setup-guide-render.d.ts +45 -0
  77. package/dist/setup-guide-render.js +351 -0
  78. package/dist/setup-guide.d.ts +94 -0
  79. package/dist/setup-guide.js +336 -0
  80. package/dist/skill-invocation.d.ts +9 -5
  81. package/dist/skill-invocation.js +18 -8
  82. package/dist/skill.d.ts +23 -3
  83. package/dist/skill.js +31 -6
  84. package/dist/theme-assets.d.ts +39 -0
  85. package/dist/theme-assets.js +449 -0
  86. package/dist/theme-readability.d.ts +37 -0
  87. package/dist/theme-readability.js +145 -0
  88. package/dist/theme-tokens.generated.d.ts +275 -0
  89. package/dist/theme-tokens.generated.js +172 -0
  90. package/dist/theme.d.ts +152 -0
  91. package/dist/theme.js +392 -0
  92. package/dist/tool.d.ts +26 -3
  93. package/dist/tool.js +8 -0
  94. package/dist/ui-parts.d.ts +23 -0
  95. package/dist/ui-parts.js +337 -0
  96. package/dist/ui-resolve.d.ts +40 -0
  97. package/dist/ui-resolve.js +54 -0
  98. package/dist/ui-slots.d.ts +55 -0
  99. package/dist/ui-slots.js +247 -0
  100. package/dist/ui.d.ts +143 -37
  101. package/dist/ui.js +65 -5
  102. package/dist/web.d.ts +30 -5
  103. package/package.json +10 -2
  104. package/schemas/bootstrap.v1.schema.json +6 -0
  105. package/schemas/connector-template.v1.schema.json +35 -0
  106. package/schemas/marketplace.v1.schema.json +50 -0
  107. package/schemas/plugin.v1.schema.json +144 -7
  108. package/schemas/theme.v1.schema.json +225 -0
package/dist/model.d.ts CHANGED
@@ -4,9 +4,32 @@
4
4
  * 见 `model-params.ts`);旧契约 `model-provider@1`(`ModelProviderV1` 等)由内核经适配层继续支持。
5
5
  */
6
6
  import type { Effort, ModelParameter, ParamValue } from "./model-params.js";
7
+ import type { LocalizedName } from "./plugin-package.js";
8
+ /** What a model does. Absent on a `ModelInfo` means `chat`. */
9
+ export type ModelKind = "chat" | "embedding" | "rerank" | "image_generation" | "video_generation" | "speech_to_text" | "text_to_speech";
10
+ /** Embedding facts of a model whose `kind` is `embedding`. */
11
+ export interface ModelEmbeddingInfo {
12
+ /** The output dimensions the model can produce (a single entry when not adjustable). */
13
+ dimensions: number[];
14
+ defaultDimensions: number;
15
+ /** Most tokens one input may hold. */
16
+ maxInputTokens: number;
17
+ /** Most inputs one `embed` call may carry. */
18
+ maxBatch: number;
19
+ }
7
20
  export interface ModelInfo {
8
21
  id: string;
9
22
  displayName: string;
23
+ /** Defaults to `chat`. Chat-only fields below stay required for every kind. */
24
+ kind?: ModelKind;
25
+ /** Who made the model (display only). */
26
+ publisher?: string;
27
+ /** Display only. */
28
+ description?: LocalizedName | string;
29
+ /** ISO date after which the model is retired (display only). */
30
+ retiresAt?: string;
31
+ /** Set when `kind` is `embedding`. */
32
+ embedding?: ModelEmbeddingInfo;
10
33
  contextWindow: number;
11
34
  maxOutputTokens: number;
12
35
  capabilities: {
@@ -206,14 +229,49 @@ export declare class ModelError extends Error {
206
229
  /** rate_limited / overloaded / server / timeout / network 为 true。 */
207
230
  get retryable(): boolean;
208
231
  }
232
+ /**
233
+ * Options of a model call made for an organization.
234
+ * `config` is the extension's effective deployment config for this org: the platform's deployment
235
+ * config with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
236
+ * platform's config (equal to `ctx.config`) while the org follows it. Use it, not `ctx.config`, for
237
+ * work done for this org. Optional in the type so older providers compile; the kernel always passes
238
+ * both.
239
+ */
240
+ export interface ModelCallOptions {
241
+ orgId?: string;
242
+ config?: unknown;
243
+ }
244
+ export interface EmbedRequest {
245
+ model: string;
246
+ input: string[];
247
+ /** One of the model's `embedding.dimensions`; the model's default when absent. */
248
+ dimensions?: number;
249
+ inputType?: "query" | "document";
250
+ }
251
+ export interface EmbedResult {
252
+ /** One vector per input, in input order. */
253
+ vectors: number[][];
254
+ usage: {
255
+ inputTokens: number;
256
+ };
257
+ }
258
+ /**
259
+ * Checks an embedding result against its request and the model's embedding facts. Returns null when
260
+ * valid, else the reason: wrong vector count, wrong dimension, or a non-finite number.
261
+ */
262
+ export declare function validateEmbedResult(req: EmbedRequest, info: ModelEmbeddingInfo, res: EmbedResult): string | null;
209
263
  /** `model-provider@2` 的实现。 */
210
264
  export interface ModelProvider {
211
265
  /** 每个模型的 `parameters` 须通过 `assertValidDeclarations`,否则内核不使用该供应商。 */
212
- listModels(): Promise<ModelInfo[]>;
266
+ listModels(opts?: ModelCallOptions): Promise<ModelInfo[]>;
213
267
  /** 事件序列必须以且仅以一个 message_complete 结束;出错抛 ModelError。 */
214
268
  stream(req: ModelRequest, opts: {
215
269
  signal: AbortSignal;
216
- }): AsyncIterable<ModelStreamEvent>;
270
+ } & ModelCallOptions): AsyncIterable<ModelStreamEvent>;
271
+ /** Present only on a provider that lists `embedding` models. */
272
+ embed?(req: EmbedRequest, opts: {
273
+ signal: AbortSignal;
274
+ } & ModelCallOptions): Promise<EmbedResult>;
217
275
  }
218
276
  /** `model-provider@1` 的实现(旧契约,内核经适配层接入:effort 由 `capabilities.effort` 推导)。 */
219
277
  export interface ModelProviderV1 {
package/dist/model.js CHANGED
@@ -148,5 +148,27 @@ export class ModelError extends Error {
148
148
  return isRetryableKind(this.kind);
149
149
  }
150
150
  }
151
+ /**
152
+ * Checks an embedding result against its request and the model's embedding facts. Returns null when
153
+ * valid, else the reason: wrong vector count, wrong dimension, or a non-finite number.
154
+ */
155
+ export function validateEmbedResult(req, info, res) {
156
+ if (res.vectors.length !== req.input.length) {
157
+ return `vector count ${res.vectors.length} does not match input count ${req.input.length}`;
158
+ }
159
+ const dims = req.dimensions ?? info.defaultDimensions;
160
+ for (let i = 0; i < res.vectors.length; i++) {
161
+ const v = res.vectors[i];
162
+ if (v.length !== dims) {
163
+ return `vector ${i} has dimension ${v.length}, expected ${dims}`;
164
+ }
165
+ for (const x of v) {
166
+ if (typeof x !== "number" || !Number.isFinite(x)) {
167
+ return `vector ${i} holds a non-finite number`;
168
+ }
169
+ }
170
+ }
171
+ return null;
172
+ }
151
173
  export const MODEL_PROVIDER_EXTENSION_POINT = "model-provider@1";
152
174
  export const MODEL_PROVIDER_EXTENSION_POINT_V2 = "model-provider@2";
@@ -0,0 +1,27 @@
1
+ import type { z } from "zod";
2
+ /**
3
+ * How an org may treat a deployment config field: `readonly` (the org sees it, never sets it) or
4
+ * `override` (an org may set its own value). A field without a level is deployment-only.
5
+ */
6
+ export type OrgAccess = "readonly" | "override";
7
+ /**
8
+ * Marks a deployment config field with an org access level (Zod 4 meta `{ org: access }`), merging
9
+ * with existing meta (`secret`, `hot`, `ui`), so `orgAccess(secret(x), …)` and
10
+ * `secret(orgAccess(x, …))` are the same. `configJsonSchema` publishes it as `"x-org"`.
11
+ *
12
+ * The author's promise for `override`: the extension reads the field from the per-call `config`
13
+ * the kernel passes with each request, not from `ctx.config`, and the field may be absent from
14
+ * `ctx.config` (the deployment value is the default, which an org may replace per call).
15
+ *
16
+ * The per-call config of an org that has its own copy still contains the platform's hidden
17
+ * (platform-only) secrets, which an org cannot set; it never contains an overridable platform
18
+ * secret. Never send a hidden secret to an endpoint taken from an overridable field: an org could
19
+ * point that endpoint at a server it controls.
20
+ */
21
+ export declare function orgAccess<T extends z.ZodTypeAny>(schema: T, access: OrgAccess): T;
22
+ /**
23
+ * The org access level of a schema's meta, or undefined when it has none. It sees through
24
+ * `.optional()`, `.default()`, `.nullable()`, `.prefault()`, `.catch()` and `.readonly()` (the
25
+ * outermost level wins), so it agrees with the `"x-org"` that `configJsonSchema` publishes.
26
+ */
27
+ export declare function orgAccessOf(schema: z.ZodTypeAny): OrgAccess | undefined;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Marks a deployment config field with an org access level (Zod 4 meta `{ org: access }`), merging
3
+ * with existing meta (`secret`, `hot`, `ui`), so `orgAccess(secret(x), …)` and
4
+ * `secret(orgAccess(x, …))` are the same. `configJsonSchema` publishes it as `"x-org"`.
5
+ *
6
+ * The author's promise for `override`: the extension reads the field from the per-call `config`
7
+ * the kernel passes with each request, not from `ctx.config`, and the field may be absent from
8
+ * `ctx.config` (the deployment value is the default, which an org may replace per call).
9
+ *
10
+ * The per-call config of an org that has its own copy still contains the platform's hidden
11
+ * (platform-only) secrets, which an org cannot set; it never contains an overridable platform
12
+ * secret. Never send a hidden secret to an endpoint taken from an overridable field: an org could
13
+ * point that endpoint at a server it controls.
14
+ */
15
+ export function orgAccess(schema, access) {
16
+ return schema.meta({ ...(schema.meta() ?? {}), org: access });
17
+ }
18
+ /** The wrappers a field's org level is read through, as `configJsonSchema` inherits meta. */
19
+ const WRAPPERS = new Set(["default", "prefault", "optional", "nullable", "readonly", "catch"]);
20
+ /**
21
+ * The org access level of a schema's meta, or undefined when it has none. It sees through
22
+ * `.optional()`, `.default()`, `.nullable()`, `.prefault()`, `.catch()` and `.readonly()` (the
23
+ * outermost level wins), so it agrees with the `"x-org"` that `configJsonSchema` publishes.
24
+ */
25
+ export function orgAccessOf(schema) {
26
+ let node = schema;
27
+ while (node) {
28
+ const v = node.meta()?.org;
29
+ if (v === "readonly" || v === "override")
30
+ return v;
31
+ const def = node._zod.def;
32
+ node = WRAPPERS.has(def.type) ? def.innerType : undefined;
33
+ }
34
+ return undefined;
35
+ }
@@ -22,7 +22,10 @@ export interface ExtensionPermissions {
22
22
  * on a replica, calls on these mount points fail closed there.
23
23
  */
24
24
  policyHooks?: PolicyHook[];
25
- /** 预留:模型用途,键须为 `<插件名>.<名称>`。 */
25
+ /**
26
+ * Model purposes (`ctx.models`): each key must be `<extension name>.<name>`; an org admin maps
27
+ * each to a model of its `kind`. `ctx.models.embed` / `describe` accept the `embedding` ones.
28
+ */
26
29
  models?: {
27
30
  purpose: string;
28
31
  kind: "chat" | "embedding";
@@ -36,16 +39,30 @@ export interface ExtensionPermissions {
36
39
  /** 访问的域名,只展示不拦截。 */
37
40
  network?: string[];
38
41
  /**
39
- * 界面贡献的 id(与清单 `ui` 一一对应):`views` 记入快照但不卡加载;
40
- * `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`.
41
50
  */
42
51
  ui?: {
43
52
  views?: string[];
44
53
  embeds?: string[];
54
+ components?: string[];
45
55
  };
56
+ /**
57
+ * Setup check ids registered with `ctx.setup.check` (each matches `SETUP_CHECK_ID_RE`, at most
58
+ * `SETUP_CHECK_LIMITS.idsPerExtension`). Recorded in the snapshot and shown at review as
59
+ * `setupCheck:<id>`, but never blocks loading: a check receives only data the extension already
60
+ * receives for the same target.
61
+ */
62
+ setupChecks?: string[];
46
63
  }
47
64
  /** hook 挂载点(封闭列表,见总设计 2.4)。 */
48
- export declare const HOOK_MOUNT_POINTS: readonly ["session.start", "session.end", "agent.preStep", "model.request", "model.response", "tool.preExecute", "tool.postExecute", "usage.report"];
65
+ export declare const HOOK_MOUNT_POINTS: readonly ["session.start", "session.end", "agent.preStep", "model.request", "model.response", "tool.preExecute", "tool.postExecute", "usage.report", "org.member_removed", "agent.deleted", "org.deleted"];
49
66
  /** hook 挂载点名。 */
50
67
  export type HookMountPoint = (typeof HOOK_MOUNT_POINTS)[number];
51
68
  /** A platform API not declared in the manifest was used. */
@@ -59,9 +76,17 @@ export declare class ExtensionPointUnavailableError extends Error {
59
76
  /** 校验权限清单,返回错误列表(空表示合法)。 */
60
77
  export declare function validatePermissions(plugin: string, p: unknown): string[];
61
78
  /**
62
- * 校验清单 `ui` 并与权限清单交叉核对,返回错误列表(空表示合法):
63
- * 每个贡献的 id 恰好出现在 `permissions.ui.views`(kind view)或 `permissions.ui.embeds`(kind embed)里,
64
- * `permissions.ui` 里也不能有清单 `ui` 没有的 id;embed 的 path 以 `/ui/` 开头并在 `permissions.http` 中声明为 GET。
65
- * 假定 `permissions` 已经过 {@link validatePermissions}。
79
+ * Checks the structure of the manifest's `ui` and cross-checks it with the permission manifest;
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.
90
+ * Assumes `permissions` passed {@link validatePermissions}.
66
91
  */
67
92
  export declare function validateUiContributions(ui: unknown, permissions: unknown): string[];
@@ -1,5 +1,7 @@
1
1
  import { POLICY_HOOKS } from "./hooks.js";
2
+ import { SETUP_CHECK_ID_RE, SETUP_CHECK_LIMITS } from "./setup-check.js";
2
3
  import { UI_ICONS } from "./ui.js";
4
+ import { PLACE_SLOTS, parseSlotRef, uiSlot } from "./ui-slots.js";
3
5
  /** hook 挂载点(封闭列表,见总设计 2.4)。 */
4
6
  export const HOOK_MOUNT_POINTS = [
5
7
  "session.start",
@@ -10,6 +12,9 @@ export const HOOK_MOUNT_POINTS = [
10
12
  "tool.preExecute",
11
13
  "tool.postExecute",
12
14
  "usage.report",
15
+ "org.member_removed",
16
+ "agent.deleted",
17
+ "org.deleted",
13
18
  ];
14
19
  const HOOKS = new Set(HOOK_MOUNT_POINTS);
15
20
  /** A platform API not declared in the manifest was used. */
@@ -36,6 +41,8 @@ const KEYS = new Set([
36
41
  "storage",
37
42
  "network",
38
43
  "ui",
44
+ "client",
45
+ "setupChecks",
39
46
  ]);
40
47
  const POLICY = new Set(POLICY_HOOKS);
41
48
  const METHODS = new Set(["GET", "POST", "PUT", "DELETE"]);
@@ -68,7 +75,7 @@ export function validatePermissions(plugin, p) {
68
75
  if (!KEYS.has(k))
69
76
  errs.push(`unknown permissions key "${k}"`);
70
77
  }
71
- for (const k of ["secrets", "storage"]) {
78
+ for (const k of ["secrets", "storage", "client"]) {
72
79
  if (p[k] !== undefined && typeof p[k] !== "boolean") {
73
80
  errs.push(`permissions.${k} must be a boolean`);
74
81
  }
@@ -126,9 +133,11 @@ export function validatePermissions(plugin, p) {
126
133
  errs.push("permissions.ui must be an object");
127
134
  else {
128
135
  for (const k of Object.keys(p.ui)) {
129
- if (k !== "views" && k !== "embeds")
136
+ if (k !== "views" && k !== "embeds" && k !== "components")
130
137
  errs.push(`unknown permissions.ui key "${k}"`);
131
138
  }
139
+ if (p.ui.components !== undefined)
140
+ strList("permissions.ui.components", p.ui.components, errs);
132
141
  const views = p.ui.views === undefined ? [] : strList("permissions.ui.views", p.ui.views, errs);
133
142
  const embeds = p.ui.embeds === undefined ? [] : strList("permissions.ui.embeds", p.ui.embeds, errs);
134
143
  for (const id of views) {
@@ -137,6 +146,17 @@ export function validatePermissions(plugin, p) {
137
146
  }
138
147
  }
139
148
  }
149
+ if (p.setupChecks !== undefined) {
150
+ const ids = strList("permissions.setupChecks", p.setupChecks, errs);
151
+ for (const id of ids) {
152
+ if (!SETUP_CHECK_ID_RE.test(id)) {
153
+ errs.push(`permissions.setupChecks id "${id}" must match ${SETUP_CHECK_ID_RE}`);
154
+ }
155
+ }
156
+ if (ids.length > SETUP_CHECK_LIMITS.idsPerExtension) {
157
+ errs.push(`permissions.setupChecks has more than ${SETUP_CHECK_LIMITS.idsPerExtension} ids`);
158
+ }
159
+ }
140
160
  if (p.models !== undefined) {
141
161
  if (!Array.isArray(p.models))
142
162
  errs.push("permissions.models must be an array");
@@ -168,20 +188,21 @@ export function validatePermissions(plugin, p) {
168
188
  }
169
189
  const UI_ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
170
190
  const UI_TITLE_MAX = 100;
171
- const UI_PLACES = [
172
- "conversation",
173
- "panel",
174
- "section",
175
- "inline",
176
- "page",
177
- "file-preview",
178
- ];
191
+ const UI_PLACES = Object.keys(PLACE_SLOTS);
179
192
  const UI_EMBED_PREFIX = "/ui/";
180
193
  /**
181
- * 校验清单 `ui` 并与权限清单交叉核对,返回错误列表(空表示合法):
182
- * 每个贡献的 id 恰好出现在 `permissions.ui.views`(kind view)或 `permissions.ui.embeds`(kind embed)里,
183
- * `permissions.ui` 里也不能有清单 `ui` 没有的 id;embed 的 path 以 `/ui/` 开头并在 `permissions.http` 中声明为 GET。
184
- * 假定 `permissions` 已经过 {@link validatePermissions}。
194
+ * Checks the structure of the manifest's `ui` and cross-checks it with the permission manifest;
195
+ * returns the problems (empty = valid). Only structural problems (UI slots spec §3.2, client
196
+ * extensions spec §5.1): each contribution's id is listed in the list of its kind,
197
+ * `permissions.ui.views` (view), `permissions.ui.embeds` (embed) or `permissions.ui.components`
198
+ * (component), an id is in at most one of the three, and `permissions.ui` lists no id the `ui`
199
+ * lacks; `permissions.ui.components` needs `permissions.client: true`; an embed's path starts with
200
+ * `/ui/` and is declared in `permissions.http` as GET, a view or component has no path; exactly one
201
+ * of `slot` (a well-formed slot reference) and `place` (a known place); for a slot the catalog
202
+ * knows at the version named, a kind it accepts and, unless an alias, the icon it requires. An
203
+ * unknown slot id or version is not a problem here: `resolveUiSlots` drops that contribution and
204
+ * the rest of the extension loads.
205
+ * Assumes `permissions` passed {@link validatePermissions}.
185
206
  */
186
207
  export function validateUiContributions(ui, permissions) {
187
208
  const perms = isObj(permissions) ? permissions : {};
@@ -191,10 +212,21 @@ export function validateUiContributions(ui, permissions) {
191
212
  : [];
192
213
  const views = listed("views");
193
214
  const embeds = listed("embeds");
215
+ const components = listed("components");
216
+ // an id in more than one list is reported once, not again as a mismatch of each list
217
+ const multiListed = new Set();
218
+ for (const id of new Set([...views, ...embeds, ...components])) {
219
+ if ([views, embeds, components].filter((l) => l.includes(id)).length > 1)
220
+ multiListed.add(id);
221
+ }
194
222
  const gets = new Set((Array.isArray(perms.http) ? perms.http : [])
195
223
  .filter((r) => isObj(r) && r.method === "GET")
196
224
  .map((r) => r.path));
197
225
  const errs = [];
226
+ for (const id of multiListed)
227
+ errs.push(`ui "${id}" is listed in more than one of permissions.ui.views / embeds / components`);
228
+ if (components.length > 0 && perms.client !== true)
229
+ errs.push("permissions.ui.components needs permissions.client: true");
198
230
  const contributions = [];
199
231
  if (ui !== undefined) {
200
232
  if (!Array.isArray(ui))
@@ -219,29 +251,60 @@ export function validateUiContributions(ui, permissions) {
219
251
  if (!title ||
220
252
  [title.zh, title.en].some((t) => typeof t !== "string" || t === "" || t.length > UI_TITLE_MAX))
221
253
  errs.push(`ui "${id}" title needs non-empty zh and en of at most ${UI_TITLE_MAX} characters`);
222
- if (!UI_PLACES.includes(c.place))
254
+ // the slot it names, when the slot / place is well formed (known to the catalog or not)
255
+ let slotRef = null;
256
+ if ((c.slot === undefined) === (c.place === undefined)) {
257
+ errs.push(`ui "${id}" needs exactly one of slot and place`);
258
+ }
259
+ else if (c.slot !== undefined) {
260
+ slotRef = typeof c.slot === "string" ? parseSlotRef(c.slot) : null;
261
+ if (slotRef === null)
262
+ errs.push(`ui "${id}" slot must be a slot reference like "org.page" or "org.page@1"`);
263
+ }
264
+ else if (!UI_PLACES.includes(c.place)) {
223
265
  errs.push(`ui "${id}" place must be one of ${UI_PLACES.join(", ")}`);
224
- if (c.kind !== "view" && c.kind !== "embed") {
225
- errs.push(`ui "${id}" kind must be view or embed`);
266
+ }
267
+ else {
268
+ slotRef = { id: PLACE_SLOTS[c.place], version: 1 };
269
+ }
270
+ if (c.after !== undefined && typeof c.after !== "string")
271
+ errs.push(`ui "${id}" after must be a string`);
272
+ if (c.kind !== "view" && c.kind !== "embed" && c.kind !== "component") {
273
+ errs.push(`ui "${id}" kind must be view, embed or component`);
226
274
  return;
227
275
  }
228
276
  if (c.icon !== undefined && !UI_ICONS.includes(c.icon))
229
277
  errs.push(`ui "${id}" icon must be one of ${UI_ICONS.join(", ")}`);
278
+ // the slot checks describe only the catalog's version: another version is left to
279
+ // resolveUiSlots, which drops it (unsupported-version) without failing the extension
280
+ const known = slotRef === null ? undefined : uiSlot(slotRef.id);
281
+ const spec = known !== undefined && known.version === slotRef?.version ? known : undefined;
282
+ if (spec !== undefined) {
283
+ if (!spec.accepts.includes(c.kind))
284
+ errs.push(`ui "${id}" slot ${spec.id} does not accept kind ${c.kind}`);
285
+ if (spec.icon === "required" && c.icon === undefined && c.aliasOf === undefined)
286
+ errs.push(`ui "${id}" slot ${spec.id} needs an icon`);
287
+ }
230
288
  if (c.aliasOf !== undefined)
231
289
  aliases.push({ id, kind: c.kind, target: c.aliasOf });
232
290
  if (seen.has(id))
233
291
  errs.push(`ui has duplicate id "${id}"`);
234
292
  seen.set(id, c.kind);
235
293
  if (c.kind === "view") {
236
- if (c.place === "file-preview")
237
- errs.push(`ui "${id}" place file-preview is only allowed for kind embed`);
238
294
  if (c.path !== undefined)
239
295
  errs.push(`ui "${id}" path is only allowed for kind embed`);
240
- if (!views.includes(id))
296
+ if (!views.includes(id) && !multiListed.has(id))
241
297
  errs.push(`ui "${id}" (view) must be listed in permissions.ui.views`);
242
298
  return;
243
299
  }
244
- if (!embeds.includes(id))
300
+ if (c.kind === "component") {
301
+ if (c.path !== undefined)
302
+ errs.push(`ui "${id}" is a component and cannot have a path`);
303
+ if (!components.includes(id) && !multiListed.has(id))
304
+ errs.push(`ui "${id}" is a component; list it in permissions.ui.components`);
305
+ return;
306
+ }
307
+ if (!embeds.includes(id) && !multiListed.has(id))
245
308
  errs.push(`ui "${id}" (embed) must be listed in permissions.ui.embeds`);
246
309
  if (typeof c.path !== "string" || !c.path.startsWith(UI_EMBED_PREFIX)) {
247
310
  errs.push(`ui "${id}" (embed) path must start with "${UI_EMBED_PREFIX}"`);
@@ -263,9 +326,13 @@ export function validateUiContributions(ui, permissions) {
263
326
  ["embeds", "embed", embeds],
264
327
  ]) {
265
328
  for (const id of ids) {
266
- if (seen.get(id) !== kind)
329
+ if (seen.get(id) !== kind && !multiListed.has(id))
267
330
  errs.push(`permissions.ui.${k} entry "${id}" has no matching ${kind} contribution in ui`);
268
331
  }
269
332
  }
333
+ for (const id of components) {
334
+ if (seen.get(id) !== "component" && !multiListed.has(id))
335
+ errs.push(`permissions.ui.components lists "${id}", which is not a component contribution`);
336
+ }
270
337
  return errs;
271
338
  }
@@ -1,9 +1,13 @@
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";
5
+ import { type PluginSetupGuide } from "./setup-guide.js";
6
+ import { type PluginThemeRef } from "./theme.js";
4
7
  /**
5
8
  * The plugin manifest `.capybara-plugin/plugin.json` (package ecosystem spec §4.1). A plugin is a
6
- * bundle of at most one extension, skills and connector templates, packed as an npm-pack tgz:
9
+ * bundle of at most one extension, skills, connector templates, agent templates and themes, packed as
10
+ * an npm-pack tgz:
7
11
  *
8
12
  * ```
9
13
  * package/package.json npm metadata; version equals plugin.json version
@@ -11,13 +15,14 @@ import { type ConnectorTemplateSpec, type LocalizedName, type StaticExtensionMan
11
15
  * package/skills/<name>/SKILL.md skills
12
16
  * package/connectors/<id>.json connector templates ({@link ConnectorTemplateFile})
13
17
  * package/agents/<name>.md agent templates (parsed by `parseAgentTemplate`)
18
+ * package/themes/<id>.json themes (parsed by `parseThemeFile`)
14
19
  * package/dist/index.mjs extension entry (only with an extension)
15
20
  * package/migrations/*.sql, package/ui/**
16
21
  * ```
17
22
  *
18
23
  * Paths start with `./` and stay inside the plugin root. Omitting `skills` / `connectorTemplates`
19
- * / `agents` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md`" (done by the
20
- * kernel when it reads the package). `extension` is written by the packer, never by hand.
24
+ * / `agents` / `themes` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md` /
25
+ * `themes/*.json`" (done by the kernel when it reads the package). `extension` is written by the packer, never by hand.
21
26
  *
22
27
  * The committed JSON Schema (`schemas/plugin.v1.schema.json`) is generated from
23
28
  * {@link PluginManifestSchema} by `pnpm gen:package-schemas` and drift-checked by
@@ -39,10 +44,14 @@ export declare const PLUGIN_MANIFEST_LIMITS: {
39
44
  readonly connectorTemplates: 20;
40
45
  /** Agent templates ({@link AGENT_TEMPLATE_LIMITS}`.perPlugin`). */
41
46
  readonly agents: 64;
47
+ /** Themes ({@link THEME_LIMITS}`.perPlugin`). */
48
+ readonly themes: 10;
42
49
  readonly descriptionChars: 1024;
43
50
  readonly publisherChars: 100;
44
51
  readonly displayNameChars: 100;
45
52
  readonly pathChars: 512;
53
+ /** Entries of `suggestedAppearance.replacements`. */
54
+ readonly appearanceReplacements: 8;
46
55
  };
47
56
  /** A plugin this one depends on: a plugin name and a semver range. */
48
57
  export interface PluginDependency {
@@ -54,8 +63,6 @@ export interface PluginDependency {
54
63
  /** A skill of the plugin: a `./…` directory holding SKILL.md. */
55
64
  export interface PluginSkillRef {
56
65
  path: string;
57
- /** Suggested as pinned when an agent selects the skill (spec §9.1). */
58
- pinned?: boolean;
59
66
  }
60
67
  /** A connector template of the plugin: a `./…/<id>.json` file ({@link ConnectorTemplateFile}). */
61
68
  export interface PluginConnectorTemplateRef {
@@ -84,7 +91,32 @@ export interface PluginExtensionSection {
84
91
  deployment?: JsonSchema;
85
92
  org?: JsonSchema;
86
93
  };
94
+ /** Browser code, styles and assets (needs `permissions.client: true`); see {@link PluginClientSection}. */
95
+ client?: PluginClientSection;
87
96
  }
97
+ /**
98
+ * How the plugin suggests it should look when chosen (client extensions spec §6.5). Nothing applies
99
+ * on install; an admin applies it in one confirmed step.
100
+ */
101
+ export interface SuggestedAppearance {
102
+ /** A theme id (file base name) of this plugin. */
103
+ theme?: string;
104
+ /** Replaceable slot id → a `component` contribution id of this plugin's extension in that slot. */
105
+ replacements?: Record<string, string>;
106
+ }
107
+ /**
108
+ * A plugin's description: a string (English) or `{ en, zh? }`, each ≤ 1024 characters. Read it
109
+ * through {@link pluginDescription}.
110
+ */
111
+ export type PluginDescription = string | {
112
+ en: string;
113
+ zh?: string;
114
+ };
115
+ /** A plugin description as `{ en, zh? }` (a plain string is the English text). */
116
+ export declare function pluginDescription(d: PluginDescription): {
117
+ en: string;
118
+ zh?: string;
119
+ };
88
120
  /** `.capybara-plugin/plugin.json`. */
89
121
  export interface PluginManifest {
90
122
  $schema?: string;
@@ -94,8 +126,8 @@ export interface PluginManifest {
94
126
  /** Exact semver version. */
95
127
  version: string;
96
128
  publisher: string;
97
- /** ≤ 1024 characters. */
98
- description: string;
129
+ /** A string (English) or `{ en, zh? }`, each ≤ 1024 characters; see {@link pluginDescription}. */
130
+ description: PluginDescription;
99
131
  displayName?: LocalizedName;
100
132
  /** `./…` .svg / .png inside the plugin. */
101
133
  icon?: string;
@@ -110,6 +142,16 @@ export interface PluginManifest {
110
142
  connectorTemplates?: PluginConnectorTemplateRef[];
111
143
  /** Agent templates; omitted = scan `agents/*.md`. */
112
144
  agents?: PluginAgentRef[];
145
+ /** Themes; omitted = scan `themes/*.json`. */
146
+ themes?: PluginThemeRef[];
147
+ /**
148
+ * Setup guides (spec `2026-11-09-setup-guides-v2-design.md`): Markdown documents at
149
+ * `guides/<id>.md` (+ `guides/<id>.zh.md`) the kernel renders for a place; see
150
+ * {@link PluginSetupGuide}.
151
+ */
152
+ setupGuides?: PluginSetupGuide[];
153
+ /** See {@link SuggestedAppearance}. */
154
+ suggestedAppearance?: SuggestedAppearance;
113
155
  extension?: PluginExtensionSection;
114
156
  }
115
157
  /** A connector template file `connectors/<id>.json`; the template id is the file's base name. */
@@ -118,6 +160,12 @@ export interface ConnectorTemplateFile {
118
160
  description?: string;
119
161
  /** Safe path relative to the plugin root (an optional leading `./`), .svg / .png. */
120
162
  icon?: string;
163
+ /**
164
+ * `false`: the template starts switched off in every org, even where its plugin is on, until an
165
+ * org admin switches it on (it then needs no org input while off). Default `true`: on wherever
166
+ * its plugin is. Ignored for a builtin plugin.
167
+ */
168
+ defaultEnabled?: boolean;
121
169
  /** Validated by {@link validateConnectorTemplate}. */
122
170
  template: ConnectorTemplateSpec;
123
171
  }
@@ -149,3 +197,8 @@ export declare function parsePluginManifest(json: unknown): PluginManifest | {
149
197
  export declare function parseConnectorTemplateFile(json: unknown): ConnectorTemplateFile | {
150
198
  errors: string[];
151
199
  };
200
+ /**
201
+ * The theme check of `suggestedAppearance` after the themes are known (the manifest may omit
202
+ * `themes` and let the scan find them): shared by the packer and the kernel.
203
+ */
204
+ export declare function appearanceIssues(manifest: PluginManifest, themeIds: readonly string[]): string[];