@capybara-hq/plugin-sdk 0.1.0-rc.0 → 0.1.0-rc.10
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/README.md +3 -3
- package/agent-docs/agent-templates.md +47 -0
- package/agent-docs/concepts.md +63 -0
- package/agent-docs/connector-templates.md +48 -0
- package/agent-docs/extension-points/channel.md +15 -0
- package/agent-docs/extension-points/config-source.md +15 -0
- package/agent-docs/extension-points/connector.md +15 -0
- package/agent-docs/extension-points/counter.md +15 -0
- package/agent-docs/extension-points/directory.md +15 -0
- package/agent-docs/extension-points/file-preview.md +15 -0
- package/agent-docs/extension-points/identity-source.md +15 -0
- package/agent-docs/extension-points/model-provider.md +15 -0
- package/agent-docs/extension-points/object-store.md +15 -0
- package/agent-docs/extension-points/sandbox.md +15 -0
- package/agent-docs/extension-points/secret-store.md +15 -0
- package/agent-docs/extension-points/web-fetch.md +15 -0
- package/agent-docs/extension-points/web-search.md +15 -0
- package/agent-docs/extensions.md +87 -0
- package/agent-docs/plugin-format.md +99 -0
- package/agent-docs/setup.md +46 -0
- package/agent-docs/skills.md +44 -0
- package/agent-docs/tool-naming.md +21 -0
- package/dist/agent-template.d.ts +85 -0
- package/dist/agent-template.js +362 -3
- package/dist/cards.d.ts +7 -0
- package/dist/cards.js +4 -4
- package/dist/channel.d.ts +20 -1
- package/dist/config-ui.d.ts +131 -0
- package/dist/config-ui.js +602 -0
- package/dist/connector-auth.d.ts +2 -0
- package/dist/connector-auth.js +15 -0
- package/dist/ctx.d.ts +86 -4
- package/dist/define-extension.d.ts +5 -1
- package/dist/define-extension.js +1 -0
- package/dist/device-protocol.d.ts +118 -0
- package/dist/device-protocol.js +276 -0
- package/dist/directory.d.ts +11 -2
- package/dist/extension-point.d.ts +9 -0
- package/dist/extension-point.js +17 -12
- package/dist/file-preview.d.ts +9 -1
- package/dist/hooks.d.ts +79 -18
- package/dist/index.d.ts +16 -1
- package/dist/index.js +16 -1
- package/dist/marketplace.d.ts +55 -2
- package/dist/marketplace.js +73 -3
- package/dist/model.d.ts +60 -2
- package/dist/model.js +22 -0
- package/dist/org-access.d.ts +27 -0
- package/dist/org-access.js +35 -0
- package/dist/permissions.d.ts +20 -5
- package/dist/permissions.js +51 -15
- package/dist/plugin-manifest.d.ts +48 -5
- package/dist/plugin-manifest.js +93 -6
- package/dist/sandbox.d.ts +164 -62
- package/dist/sandbox.js +71 -14
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +5 -2
- package/dist/setup-check.d.ts +115 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +350 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +94 -0
- package/dist/setup-guide.js +336 -0
- package/dist/skill-invocation.d.ts +12 -8
- package/dist/skill-invocation.js +19 -9
- package/dist/skill.d.ts +23 -3
- package/dist/skill.js +31 -6
- package/dist/theme-assets.d.ts +39 -0
- package/dist/theme-assets.js +449 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +275 -0
- package/dist/theme-tokens.generated.js +167 -0
- package/dist/theme.d.ts +152 -0
- package/dist/theme.js +392 -0
- package/dist/tool-key.d.ts +28 -0
- package/dist/tool-key.js +40 -0
- package/dist/tool.d.ts +11 -3
- package/dist/ui-resolve.d.ts +40 -0
- package/dist/ui-resolve.js +54 -0
- package/dist/ui-slots.d.ts +43 -0
- package/dist/ui-slots.js +168 -0
- package/dist/ui.d.ts +114 -31
- package/dist/ui.js +0 -4
- package/dist/web.d.ts +105 -0
- package/dist/web.js +135 -0
- package/package.json +10 -2
- package/schemas/connector-template.v1.schema.json +3 -0
- package/schemas/marketplace.v1.schema.json +50 -0
- package/schemas/plugin.v1.schema.json +97 -4
- package/schemas/theme.v1.schema.json +225 -0
package/dist/permissions.d.ts
CHANGED
|
@@ -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";
|
|
@@ -43,6 +46,13 @@ export interface ExtensionPermissions {
|
|
|
43
46
|
views?: string[];
|
|
44
47
|
embeds?: string[];
|
|
45
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Setup check ids registered with `ctx.setup.check` (each matches `SETUP_CHECK_ID_RE`, at most
|
|
51
|
+
* `SETUP_CHECK_LIMITS.idsPerExtension`). Recorded in the snapshot and shown at review as
|
|
52
|
+
* `setupCheck:<id>`, but never blocks loading: a check receives only data the extension already
|
|
53
|
+
* receives for the same target.
|
|
54
|
+
*/
|
|
55
|
+
setupChecks?: string[];
|
|
46
56
|
}
|
|
47
57
|
/** hook 挂载点(封闭列表,见总设计 2.4)。 */
|
|
48
58
|
export declare const HOOK_MOUNT_POINTS: readonly ["session.start", "session.end", "agent.preStep", "model.request", "model.response", "tool.preExecute", "tool.postExecute", "usage.report"];
|
|
@@ -59,9 +69,14 @@ export declare class ExtensionPointUnavailableError extends Error {
|
|
|
59
69
|
/** 校验权限清单,返回错误列表(空表示合法)。 */
|
|
60
70
|
export declare function validatePermissions(plugin: string, p: unknown): string[];
|
|
61
71
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
72
|
+
* 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
|
+
* Assumes `permissions` passed {@link validatePermissions}.
|
|
66
81
|
*/
|
|
67
82
|
export declare function validateUiContributions(ui: unknown, permissions: unknown): string[];
|
package/dist/permissions.js
CHANGED
|
@@ -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",
|
|
@@ -36,6 +38,7 @@ const KEYS = new Set([
|
|
|
36
38
|
"storage",
|
|
37
39
|
"network",
|
|
38
40
|
"ui",
|
|
41
|
+
"setupChecks",
|
|
39
42
|
]);
|
|
40
43
|
const POLICY = new Set(POLICY_HOOKS);
|
|
41
44
|
const METHODS = new Set(["GET", "POST", "PUT", "DELETE"]);
|
|
@@ -137,6 +140,17 @@ export function validatePermissions(plugin, p) {
|
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
142
|
}
|
|
143
|
+
if (p.setupChecks !== undefined) {
|
|
144
|
+
const ids = strList("permissions.setupChecks", p.setupChecks, errs);
|
|
145
|
+
for (const id of ids) {
|
|
146
|
+
if (!SETUP_CHECK_ID_RE.test(id)) {
|
|
147
|
+
errs.push(`permissions.setupChecks id "${id}" must match ${SETUP_CHECK_ID_RE}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (ids.length > SETUP_CHECK_LIMITS.idsPerExtension) {
|
|
151
|
+
errs.push(`permissions.setupChecks has more than ${SETUP_CHECK_LIMITS.idsPerExtension} ids`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
140
154
|
if (p.models !== undefined) {
|
|
141
155
|
if (!Array.isArray(p.models))
|
|
142
156
|
errs.push("permissions.models must be an array");
|
|
@@ -168,20 +182,18 @@ export function validatePermissions(plugin, p) {
|
|
|
168
182
|
}
|
|
169
183
|
const UI_ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
|
|
170
184
|
const UI_TITLE_MAX = 100;
|
|
171
|
-
const UI_PLACES =
|
|
172
|
-
"conversation",
|
|
173
|
-
"panel",
|
|
174
|
-
"section",
|
|
175
|
-
"inline",
|
|
176
|
-
"page",
|
|
177
|
-
"file-preview",
|
|
178
|
-
];
|
|
185
|
+
const UI_PLACES = Object.keys(PLACE_SLOTS);
|
|
179
186
|
const UI_EMBED_PREFIX = "/ui/";
|
|
180
187
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
188
|
+
* 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.
|
|
196
|
+
* Assumes `permissions` passed {@link validatePermissions}.
|
|
185
197
|
*/
|
|
186
198
|
export function validateUiContributions(ui, permissions) {
|
|
187
199
|
const perms = isObj(permissions) ? permissions : {};
|
|
@@ -219,22 +231,46 @@ export function validateUiContributions(ui, permissions) {
|
|
|
219
231
|
if (!title ||
|
|
220
232
|
[title.zh, title.en].some((t) => typeof t !== "string" || t === "" || t.length > UI_TITLE_MAX))
|
|
221
233
|
errs.push(`ui "${id}" title needs non-empty zh and en of at most ${UI_TITLE_MAX} characters`);
|
|
222
|
-
|
|
234
|
+
// the slot it names, when the slot / place is well formed (known to the catalog or not)
|
|
235
|
+
let slotRef = null;
|
|
236
|
+
if ((c.slot === undefined) === (c.place === undefined)) {
|
|
237
|
+
errs.push(`ui "${id}" needs exactly one of slot and place`);
|
|
238
|
+
}
|
|
239
|
+
else if (c.slot !== undefined) {
|
|
240
|
+
slotRef = typeof c.slot === "string" ? parseSlotRef(c.slot) : null;
|
|
241
|
+
if (slotRef === null)
|
|
242
|
+
errs.push(`ui "${id}" slot must be a slot reference like "org.page" or "org.page@1"`);
|
|
243
|
+
}
|
|
244
|
+
else if (!UI_PLACES.includes(c.place)) {
|
|
223
245
|
errs.push(`ui "${id}" place must be one of ${UI_PLACES.join(", ")}`);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
slotRef = { id: PLACE_SLOTS[c.place], version: 1 };
|
|
249
|
+
}
|
|
250
|
+
if (c.after !== undefined && typeof c.after !== "string")
|
|
251
|
+
errs.push(`ui "${id}" after must be a string`);
|
|
224
252
|
if (c.kind !== "view" && c.kind !== "embed") {
|
|
225
253
|
errs.push(`ui "${id}" kind must be view or embed`);
|
|
226
254
|
return;
|
|
227
255
|
}
|
|
228
256
|
if (c.icon !== undefined && !UI_ICONS.includes(c.icon))
|
|
229
257
|
errs.push(`ui "${id}" icon must be one of ${UI_ICONS.join(", ")}`);
|
|
258
|
+
// the slot checks describe only the catalog's version: another version is left to
|
|
259
|
+
// resolveUiSlots, which drops it (unsupported-version) without failing the extension
|
|
260
|
+
const known = slotRef === null ? undefined : uiSlot(slotRef.id);
|
|
261
|
+
const spec = known !== undefined && known.version === slotRef?.version ? known : undefined;
|
|
262
|
+
if (spec !== undefined) {
|
|
263
|
+
if (!spec.accepts.includes(c.kind))
|
|
264
|
+
errs.push(`ui "${id}" slot ${spec.id} does not accept kind ${c.kind}`);
|
|
265
|
+
if (spec.icon === "required" && c.icon === undefined && c.aliasOf === undefined)
|
|
266
|
+
errs.push(`ui "${id}" slot ${spec.id} needs an icon`);
|
|
267
|
+
}
|
|
230
268
|
if (c.aliasOf !== undefined)
|
|
231
269
|
aliases.push({ id, kind: c.kind, target: c.aliasOf });
|
|
232
270
|
if (seen.has(id))
|
|
233
271
|
errs.push(`ui has duplicate id "${id}"`);
|
|
234
272
|
seen.set(id, c.kind);
|
|
235
273
|
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
274
|
if (c.path !== undefined)
|
|
239
275
|
errs.push(`ui "${id}" path is only allowed for kind embed`);
|
|
240
276
|
if (!views.includes(id))
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { type JsonSchema } from "./config-ui.js";
|
|
2
3
|
import { type ConnectorTemplateSpec, type LocalizedName, type StaticExtensionManifest } from "./plugin-package.js";
|
|
4
|
+
import { type PluginSetupGuide } from "./setup-guide.js";
|
|
5
|
+
import { type PluginThemeRef } from "./theme.js";
|
|
3
6
|
/**
|
|
4
7
|
* The plugin manifest `.capybara-plugin/plugin.json` (package ecosystem spec §4.1). A plugin is a
|
|
5
|
-
* bundle of at most one extension, skills
|
|
8
|
+
* bundle of at most one extension, skills, connector templates, agent templates and themes, packed as
|
|
9
|
+
* an npm-pack tgz:
|
|
6
10
|
*
|
|
7
11
|
* ```
|
|
8
12
|
* package/package.json npm metadata; version equals plugin.json version
|
|
@@ -10,13 +14,14 @@ import { type ConnectorTemplateSpec, type LocalizedName, type StaticExtensionMan
|
|
|
10
14
|
* package/skills/<name>/SKILL.md skills
|
|
11
15
|
* package/connectors/<id>.json connector templates ({@link ConnectorTemplateFile})
|
|
12
16
|
* package/agents/<name>.md agent templates (parsed by `parseAgentTemplate`)
|
|
17
|
+
* package/themes/<id>.json themes (parsed by `parseThemeFile`)
|
|
13
18
|
* package/dist/index.mjs extension entry (only with an extension)
|
|
14
19
|
* package/migrations/*.sql, package/ui/**
|
|
15
20
|
* ```
|
|
16
21
|
*
|
|
17
22
|
* Paths start with `./` and stay inside the plugin root. Omitting `skills` / `connectorTemplates`
|
|
18
|
-
* / `agents` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md`
|
|
19
|
-
* kernel when it reads the package). `extension` is written by the packer, never by hand.
|
|
23
|
+
* / `agents` / `themes` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md` /
|
|
24
|
+
* `themes/*.json`" (done by the kernel when it reads the package). `extension` is written by the packer, never by hand.
|
|
20
25
|
*
|
|
21
26
|
* The committed JSON Schema (`schemas/plugin.v1.schema.json`) is generated from
|
|
22
27
|
* {@link PluginManifestSchema} by `pnpm gen:package-schemas` and drift-checked by
|
|
@@ -38,6 +43,8 @@ export declare const PLUGIN_MANIFEST_LIMITS: {
|
|
|
38
43
|
readonly connectorTemplates: 20;
|
|
39
44
|
/** Agent templates ({@link AGENT_TEMPLATE_LIMITS}`.perPlugin`). */
|
|
40
45
|
readonly agents: 64;
|
|
46
|
+
/** Themes ({@link THEME_LIMITS}`.perPlugin`). */
|
|
47
|
+
readonly themes: 10;
|
|
41
48
|
readonly descriptionChars: 1024;
|
|
42
49
|
readonly publisherChars: 100;
|
|
43
50
|
readonly displayNameChars: 100;
|
|
@@ -74,7 +81,29 @@ export interface PluginExtensionSection {
|
|
|
74
81
|
migrations?: string;
|
|
75
82
|
/** `./ui`. */
|
|
76
83
|
ui?: string;
|
|
84
|
+
/**
|
|
85
|
+
* The config JSON Schemas (`configJsonSchema`, with `x-ui` hints), written by the packer so an
|
|
86
|
+
* extension not loaded on a replica still gets its form; each ≤
|
|
87
|
+
* {@link CONFIG_UI_LIMITS}`.configSchemaBytes`. Not part of the `manifest_mismatch` comparison.
|
|
88
|
+
*/
|
|
89
|
+
configSchemas?: {
|
|
90
|
+
deployment?: JsonSchema;
|
|
91
|
+
org?: JsonSchema;
|
|
92
|
+
};
|
|
77
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* A plugin's description: a string (English) or `{ en, zh? }`, each ≤ 1024 characters. Read it
|
|
96
|
+
* through {@link pluginDescription}.
|
|
97
|
+
*/
|
|
98
|
+
export type PluginDescription = string | {
|
|
99
|
+
en: string;
|
|
100
|
+
zh?: string;
|
|
101
|
+
};
|
|
102
|
+
/** A plugin description as `{ en, zh? }` (a plain string is the English text). */
|
|
103
|
+
export declare function pluginDescription(d: PluginDescription): {
|
|
104
|
+
en: string;
|
|
105
|
+
zh?: string;
|
|
106
|
+
};
|
|
78
107
|
/** `.capybara-plugin/plugin.json`. */
|
|
79
108
|
export interface PluginManifest {
|
|
80
109
|
$schema?: string;
|
|
@@ -84,8 +113,8 @@ export interface PluginManifest {
|
|
|
84
113
|
/** Exact semver version. */
|
|
85
114
|
version: string;
|
|
86
115
|
publisher: string;
|
|
87
|
-
/** ≤ 1024 characters. */
|
|
88
|
-
description:
|
|
116
|
+
/** A string (English) or `{ en, zh? }`, each ≤ 1024 characters; see {@link pluginDescription}. */
|
|
117
|
+
description: PluginDescription;
|
|
89
118
|
displayName?: LocalizedName;
|
|
90
119
|
/** `./…` .svg / .png inside the plugin. */
|
|
91
120
|
icon?: string;
|
|
@@ -100,6 +129,14 @@ export interface PluginManifest {
|
|
|
100
129
|
connectorTemplates?: PluginConnectorTemplateRef[];
|
|
101
130
|
/** Agent templates; omitted = scan `agents/*.md`. */
|
|
102
131
|
agents?: PluginAgentRef[];
|
|
132
|
+
/** Themes; omitted = scan `themes/*.json`. */
|
|
133
|
+
themes?: PluginThemeRef[];
|
|
134
|
+
/**
|
|
135
|
+
* Setup guides (spec `2026-11-09-setup-guides-v2-design.md`): Markdown documents at
|
|
136
|
+
* `guides/<id>.md` (+ `guides/<id>.zh.md`) the kernel renders for a place; see
|
|
137
|
+
* {@link PluginSetupGuide}.
|
|
138
|
+
*/
|
|
139
|
+
setupGuides?: PluginSetupGuide[];
|
|
103
140
|
extension?: PluginExtensionSection;
|
|
104
141
|
}
|
|
105
142
|
/** A connector template file `connectors/<id>.json`; the template id is the file's base name. */
|
|
@@ -108,6 +145,12 @@ export interface ConnectorTemplateFile {
|
|
|
108
145
|
description?: string;
|
|
109
146
|
/** Safe path relative to the plugin root (an optional leading `./`), .svg / .png. */
|
|
110
147
|
icon?: string;
|
|
148
|
+
/**
|
|
149
|
+
* `false`: the template starts switched off in every org, even where its plugin is on, until an
|
|
150
|
+
* org admin switches it on (it then needs no org input while off). Default `true`: on wherever
|
|
151
|
+
* its plugin is. Ignored for a builtin plugin.
|
|
152
|
+
*/
|
|
153
|
+
defaultEnabled?: boolean;
|
|
111
154
|
/** Validated by {@link validateConnectorTemplate}. */
|
|
112
155
|
template: ConnectorTemplateSpec;
|
|
113
156
|
}
|
package/dist/plugin-manifest.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import semver from "semver";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { AGENT_TEMPLATE_LIMITS } from "./agent-template.js";
|
|
4
|
+
import { CONFIG_UI_LIMITS } from "./config-ui.js";
|
|
4
5
|
import { defineExtension, EXTENSION_NAME_RE } from "./define-extension.js";
|
|
5
6
|
import { CATALOG_ITEM_NAME_RE, CONNECTOR_TEMPLATE_LIMITS, isSafePackagePath, SEMVER_VERSION_RE, validateConnectorTemplate, } from "./plugin-package.js";
|
|
6
7
|
import { hasUpperBound } from "./semver-range.js";
|
|
8
|
+
import { SETUP_GUIDE_LIMITS, SETUP_GUIDE_PLACES } from "./setup-guide.js";
|
|
9
|
+
import { THEME_LIMITS, themeIdOf } from "./theme.js";
|
|
7
10
|
/**
|
|
8
11
|
* The plugin manifest `.capybara-plugin/plugin.json` (package ecosystem spec §4.1). A plugin is a
|
|
9
|
-
* bundle of at most one extension, skills
|
|
12
|
+
* bundle of at most one extension, skills, connector templates, agent templates and themes, packed as
|
|
13
|
+
* an npm-pack tgz:
|
|
10
14
|
*
|
|
11
15
|
* ```
|
|
12
16
|
* package/package.json npm metadata; version equals plugin.json version
|
|
@@ -14,13 +18,14 @@ import { hasUpperBound } from "./semver-range.js";
|
|
|
14
18
|
* package/skills/<name>/SKILL.md skills
|
|
15
19
|
* package/connectors/<id>.json connector templates ({@link ConnectorTemplateFile})
|
|
16
20
|
* package/agents/<name>.md agent templates (parsed by `parseAgentTemplate`)
|
|
21
|
+
* package/themes/<id>.json themes (parsed by `parseThemeFile`)
|
|
17
22
|
* package/dist/index.mjs extension entry (only with an extension)
|
|
18
23
|
* package/migrations/*.sql, package/ui/**
|
|
19
24
|
* ```
|
|
20
25
|
*
|
|
21
26
|
* Paths start with `./` and stay inside the plugin root. Omitting `skills` / `connectorTemplates`
|
|
22
|
-
* / `agents` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md`
|
|
23
|
-
* kernel when it reads the package). `extension` is written by the packer, never by hand.
|
|
27
|
+
* / `agents` / `themes` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md` /
|
|
28
|
+
* `themes/*.json`" (done by the kernel when it reads the package). `extension` is written by the packer, never by hand.
|
|
24
29
|
*
|
|
25
30
|
* The committed JSON Schema (`schemas/plugin.v1.schema.json`) is generated from
|
|
26
31
|
* {@link PluginManifestSchema} by `pnpm gen:package-schemas` and drift-checked by
|
|
@@ -42,11 +47,17 @@ export const PLUGIN_MANIFEST_LIMITS = {
|
|
|
42
47
|
connectorTemplates: 20,
|
|
43
48
|
/** Agent templates ({@link AGENT_TEMPLATE_LIMITS}`.perPlugin`). */
|
|
44
49
|
agents: AGENT_TEMPLATE_LIMITS.perPlugin,
|
|
50
|
+
/** Themes ({@link THEME_LIMITS}`.perPlugin`). */
|
|
51
|
+
themes: THEME_LIMITS.perPlugin,
|
|
45
52
|
descriptionChars: 1024,
|
|
46
53
|
publisherChars: 100,
|
|
47
54
|
displayNameChars: 100,
|
|
48
55
|
pathChars: 512,
|
|
49
56
|
};
|
|
57
|
+
/** A plugin description as `{ en, zh? }` (a plain string is the English text). */
|
|
58
|
+
export function pluginDescription(d) {
|
|
59
|
+
return typeof d === "string" ? { en: d } : { en: d.en, ...(d.zh !== undefined && { zh: d.zh }) };
|
|
60
|
+
}
|
|
50
61
|
const L = PLUGIN_MANIFEST_LIMITS;
|
|
51
62
|
const MAX_ERRORS = 50;
|
|
52
63
|
const ICON_RE = /\.(?:svg|png)$/i;
|
|
@@ -87,6 +98,21 @@ const staticExtensionManifest = z.strictObject({
|
|
|
87
98
|
ui: z.array(z.record(z.string(), z.unknown())).optional(),
|
|
88
99
|
config: z.strictObject({ deployment: configFields, org: configFields }),
|
|
89
100
|
});
|
|
101
|
+
const configSchemaJson = z
|
|
102
|
+
.record(z.string(), z.unknown())
|
|
103
|
+
.refine((v) => new TextEncoder().encode(JSON.stringify(v)).length <= CONFIG_UI_LIMITS.configSchemaBytes, {
|
|
104
|
+
message: `must be at most ${CONFIG_UI_LIMITS.configSchemaBytes} bytes of JSON (${CONFIG_UI_LIMITS.configSchemaBytes / 1024} KiB)`,
|
|
105
|
+
});
|
|
106
|
+
const setupGuide = z.strictObject({
|
|
107
|
+
id: z.string().regex(CATALOG_ITEM_NAME_RE, {
|
|
108
|
+
message: "id must match ^[a-z0-9][a-z0-9-]{0,63}$",
|
|
109
|
+
}),
|
|
110
|
+
place: z.enum(SETUP_GUIDE_PLACES),
|
|
111
|
+
template: z
|
|
112
|
+
.string()
|
|
113
|
+
.regex(CATALOG_ITEM_NAME_RE, { message: "template must match ^[a-z0-9][a-z0-9-]{0,63}$" })
|
|
114
|
+
.optional(),
|
|
115
|
+
});
|
|
90
116
|
const extensionSection = z.strictObject({
|
|
91
117
|
entry: dotPath("entry").refine((p) => p.endsWith(".mjs"), {
|
|
92
118
|
message: "entry must be a .mjs file",
|
|
@@ -94,6 +120,9 @@ const extensionSection = z.strictObject({
|
|
|
94
120
|
manifest: staticExtensionManifest,
|
|
95
121
|
migrations: dotPath("migrations").optional(),
|
|
96
122
|
ui: dotPath("ui").optional(),
|
|
123
|
+
configSchemas: z
|
|
124
|
+
.strictObject({ deployment: configSchemaJson.optional(), org: configSchemaJson.optional() })
|
|
125
|
+
.optional(),
|
|
97
126
|
});
|
|
98
127
|
const schema = z
|
|
99
128
|
.strictObject({
|
|
@@ -107,7 +136,13 @@ const schema = z
|
|
|
107
136
|
.max(256)
|
|
108
137
|
.regex(SEMVER_VERSION_RE, { message: "version must be an exact semver version" }),
|
|
109
138
|
publisher: text(L.publisherChars, "publisher"),
|
|
110
|
-
description:
|
|
139
|
+
description: z.union([
|
|
140
|
+
text(L.descriptionChars, "description"),
|
|
141
|
+
z.strictObject({
|
|
142
|
+
en: text(L.descriptionChars, "description.en"),
|
|
143
|
+
zh: text(L.descriptionChars, "description.zh").optional(),
|
|
144
|
+
}),
|
|
145
|
+
]),
|
|
111
146
|
displayName: localized.optional(),
|
|
112
147
|
icon: dotPath("icon")
|
|
113
148
|
.regex(ICON_RE, { message: "icon must be a .svg or .png file" })
|
|
@@ -149,6 +184,13 @@ const schema = z
|
|
|
149
184
|
}))
|
|
150
185
|
.max(L.agents)
|
|
151
186
|
.optional(),
|
|
187
|
+
themes: z
|
|
188
|
+
.array(z.strictObject({
|
|
189
|
+
path: dotPath("path").refine((p) => p.endsWith(".json") && CATALOG_ITEM_NAME_RE.test(themeIdOf(p)), { message: "path must be a <id>.json file with id matching ^[a-z0-9][a-z0-9-]{0,63}$" }),
|
|
190
|
+
}))
|
|
191
|
+
.max(L.themes)
|
|
192
|
+
.optional(),
|
|
193
|
+
setupGuides: z.array(setupGuide).max(SETUP_GUIDE_LIMITS.guides).optional(),
|
|
152
194
|
extension: extensionSection.optional(),
|
|
153
195
|
})
|
|
154
196
|
.superRefine((m, ctx) => {
|
|
@@ -187,11 +229,55 @@ const schema = z
|
|
|
187
229
|
issue(["agents", i, "path"], `duplicate agent template path ${a.path}`);
|
|
188
230
|
agentPaths.add(a.path);
|
|
189
231
|
});
|
|
232
|
+
const themeIds = new Set();
|
|
233
|
+
m.themes?.forEach((t, i) => {
|
|
234
|
+
const id = themeIdOf(t.path);
|
|
235
|
+
if (themeIds.has(id))
|
|
236
|
+
issue(["themes", i, "path"], `duplicate theme id ${id}`);
|
|
237
|
+
themeIds.add(id);
|
|
238
|
+
});
|
|
239
|
+
const guideIds = new Set();
|
|
240
|
+
const guideTemplates = new Set();
|
|
241
|
+
let channelGuides = 0;
|
|
242
|
+
m.setupGuides?.forEach((g, i) => {
|
|
243
|
+
if (guideIds.has(g.id))
|
|
244
|
+
issue(["setupGuides", i, "id"], `duplicate setup guide id ${g.id}`);
|
|
245
|
+
guideIds.add(g.id);
|
|
246
|
+
if (g.place === "connector-template") {
|
|
247
|
+
if (g.template === undefined) {
|
|
248
|
+
issue(["setupGuides", i, "template"], "template is required for a connector-template guide");
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
if (m.connectorTemplates !== undefined && !ids.has(g.template)) {
|
|
252
|
+
issue(["setupGuides", i, "template"], `template ${g.template} is not one of the plugin's connector templates`);
|
|
253
|
+
}
|
|
254
|
+
if (guideTemplates.has(g.template)) {
|
|
255
|
+
issue(["setupGuides", i, "template"], `at most one setup guide per connector template (${g.template} has two)`);
|
|
256
|
+
}
|
|
257
|
+
guideTemplates.add(g.template);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
else if (g.template !== undefined) {
|
|
261
|
+
issue(["setupGuides", i, "template"], "template is only for connector-template guides");
|
|
262
|
+
}
|
|
263
|
+
if (g.place === "channel-connection") {
|
|
264
|
+
channelGuides++;
|
|
265
|
+
if (channelGuides === 2) {
|
|
266
|
+
issue(["setupGuides", i, "place"], "a plugin has at most one channel-connection guide");
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (g.place === "channel-connection" &&
|
|
270
|
+
m.extension !== undefined &&
|
|
271
|
+
!m.extension.manifest.provides.some((p) => p.startsWith("channel@"))) {
|
|
272
|
+
issue(["setupGuides", i, "place"], "a channel-connection guide needs the plugin's extension to provide channel@1");
|
|
273
|
+
}
|
|
274
|
+
});
|
|
190
275
|
if (m.extension === undefined &&
|
|
191
276
|
m.skills?.length === 0 &&
|
|
192
277
|
m.connectorTemplates?.length === 0 &&
|
|
193
|
-
(m.agents === undefined || m.agents.length === 0)
|
|
194
|
-
|
|
278
|
+
(m.agents === undefined || m.agents.length === 0) &&
|
|
279
|
+
(m.themes === undefined || m.themes.length === 0)) {
|
|
280
|
+
issue([], "a plugin must contain an extension, a skill, a connector template, an agent template or a theme");
|
|
195
281
|
}
|
|
196
282
|
const ext = m.extension;
|
|
197
283
|
if (ext === undefined)
|
|
@@ -262,6 +348,7 @@ const templateFile = z
|
|
|
262
348
|
message: "icon must be a relative .svg or .png path inside the plugin",
|
|
263
349
|
})
|
|
264
350
|
.optional(),
|
|
351
|
+
defaultEnabled: z.boolean().optional(),
|
|
265
352
|
template,
|
|
266
353
|
})
|
|
267
354
|
// Field rules (no credentials, auth presets, editableEndpoint, ...) belong to validateConnectorTemplate.
|