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

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 (104) 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/hooks.d.ts +111 -15
  53. package/dist/hooks.js +5 -0
  54. package/dist/index.d.ts +18 -1
  55. package/dist/index.js +18 -1
  56. package/dist/marketplace.d.ts +55 -2
  57. package/dist/marketplace.js +73 -3
  58. package/dist/model.d.ts +60 -2
  59. package/dist/model.js +22 -0
  60. package/dist/org-access.d.ts +27 -0
  61. package/dist/org-access.js +35 -0
  62. package/dist/permissions.d.ts +33 -8
  63. package/dist/permissions.js +89 -22
  64. package/dist/plugin-manifest.d.ts +60 -7
  65. package/dist/plugin-manifest.js +178 -7
  66. package/dist/sandbox.d.ts +239 -62
  67. package/dist/sandbox.js +99 -14
  68. package/dist/setup-check.d.ts +115 -0
  69. package/dist/setup-check.js +142 -0
  70. package/dist/setup-guide-parse.d.ts +121 -0
  71. package/dist/setup-guide-parse.js +350 -0
  72. package/dist/setup-guide-render.d.ts +45 -0
  73. package/dist/setup-guide-render.js +351 -0
  74. package/dist/setup-guide.d.ts +94 -0
  75. package/dist/setup-guide.js +336 -0
  76. package/dist/skill-invocation.d.ts +9 -5
  77. package/dist/skill-invocation.js +18 -8
  78. package/dist/skill.d.ts +23 -3
  79. package/dist/skill.js +31 -6
  80. package/dist/theme-assets.d.ts +39 -0
  81. package/dist/theme-assets.js +449 -0
  82. package/dist/theme-readability.d.ts +37 -0
  83. package/dist/theme-readability.js +145 -0
  84. package/dist/theme-tokens.generated.d.ts +275 -0
  85. package/dist/theme-tokens.generated.js +172 -0
  86. package/dist/theme.d.ts +152 -0
  87. package/dist/theme.js +392 -0
  88. package/dist/tool.d.ts +26 -3
  89. package/dist/tool.js +8 -0
  90. package/dist/ui-parts.d.ts +23 -0
  91. package/dist/ui-parts.js +337 -0
  92. package/dist/ui-resolve.d.ts +40 -0
  93. package/dist/ui-resolve.js +54 -0
  94. package/dist/ui-slots.d.ts +55 -0
  95. package/dist/ui-slots.js +247 -0
  96. package/dist/ui.d.ts +143 -37
  97. package/dist/ui.js +65 -5
  98. package/dist/web.d.ts +30 -5
  99. package/package.json +10 -2
  100. package/schemas/bootstrap.v1.schema.json +6 -0
  101. package/schemas/connector-template.v1.schema.json +3 -0
  102. package/schemas/marketplace.v1.schema.json +50 -0
  103. package/schemas/plugin.v1.schema.json +144 -7
  104. package/schemas/theme.v1.schema.json +225 -0
@@ -1,13 +1,18 @@
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";
9
+ import { SETUP_GUIDE_LIMITS, SETUP_GUIDE_PLACES } from "./setup-guide.js";
10
+ import { THEME_LIMITS, themeIdOf } from "./theme.js";
11
+ import { parseSlotRef, uiSlot } from "./ui-slots.js";
8
12
  /**
9
13
  * The plugin manifest `.capybara-plugin/plugin.json` (package ecosystem spec §4.1). A plugin is a
10
- * bundle of at most one extension, skills and connector templates, packed as an npm-pack tgz:
14
+ * bundle of at most one extension, skills, connector templates, agent templates and themes, packed as
15
+ * an npm-pack tgz:
11
16
  *
12
17
  * ```
13
18
  * package/package.json npm metadata; version equals plugin.json version
@@ -15,13 +20,14 @@ import { hasUpperBound } from "./semver-range.js";
15
20
  * package/skills/<name>/SKILL.md skills
16
21
  * package/connectors/<id>.json connector templates ({@link ConnectorTemplateFile})
17
22
  * package/agents/<name>.md agent templates (parsed by `parseAgentTemplate`)
23
+ * package/themes/<id>.json themes (parsed by `parseThemeFile`)
18
24
  * package/dist/index.mjs extension entry (only with an extension)
19
25
  * package/migrations/*.sql, package/ui/**
20
26
  * ```
21
27
  *
22
28
  * Paths start with `./` and stay inside the plugin root. Omitting `skills` / `connectorTemplates`
23
- * / `agents` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md`" (done by the
24
- * kernel when it reads the package). `extension` is written by the packer, never by hand.
29
+ * / `agents` / `themes` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md` /
30
+ * `themes/*.json`" (done by the kernel when it reads the package). `extension` is written by the packer, never by hand.
25
31
  *
26
32
  * The committed JSON Schema (`schemas/plugin.v1.schema.json`) is generated from
27
33
  * {@link PluginManifestSchema} by `pnpm gen:package-schemas` and drift-checked by
@@ -43,14 +49,23 @@ export const PLUGIN_MANIFEST_LIMITS = {
43
49
  connectorTemplates: 20,
44
50
  /** Agent templates ({@link AGENT_TEMPLATE_LIMITS}`.perPlugin`). */
45
51
  agents: AGENT_TEMPLATE_LIMITS.perPlugin,
52
+ /** Themes ({@link THEME_LIMITS}`.perPlugin`). */
53
+ themes: THEME_LIMITS.perPlugin,
46
54
  descriptionChars: 1024,
47
55
  publisherChars: 100,
48
56
  displayNameChars: 100,
49
57
  pathChars: 512,
58
+ /** Entries of `suggestedAppearance.replacements`. */
59
+ appearanceReplacements: 8,
50
60
  };
61
+ /** A plugin description as `{ en, zh? }` (a plain string is the English text). */
62
+ export function pluginDescription(d) {
63
+ return typeof d === "string" ? { en: d } : { en: d.en, ...(d.zh !== undefined && { zh: d.zh }) };
64
+ }
51
65
  const L = PLUGIN_MANIFEST_LIMITS;
52
66
  const MAX_ERRORS = 50;
53
67
  const ICON_RE = /\.(?:svg|png)$/i;
68
+ const COMPONENT_ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
54
69
  const HTTPS_URL_RE = /^https:\/\/\S+$/;
55
70
  const text = (max, what) => z
56
71
  .string()
@@ -93,6 +108,35 @@ const configSchemaJson = z
93
108
  .refine((v) => new TextEncoder().encode(JSON.stringify(v)).length <= CONFIG_UI_LIMITS.configSchemaBytes, {
94
109
  message: `must be at most ${CONFIG_UI_LIMITS.configSchemaBytes} bytes of JSON (${CONFIG_UI_LIMITS.configSchemaBytes / 1024} KiB)`,
95
110
  });
111
+ const setupGuide = z.strictObject({
112
+ id: z.string().regex(CATALOG_ITEM_NAME_RE, {
113
+ message: "id must match ^[a-z0-9][a-z0-9-]{0,63}$",
114
+ }),
115
+ place: z.enum(SETUP_GUIDE_PLACES),
116
+ template: z
117
+ .string()
118
+ .regex(CATALOG_ITEM_NAME_RE, { message: "template must match ^[a-z0-9][a-z0-9-]{0,63}$" })
119
+ .optional(),
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
+ });
96
140
  const extensionSection = z.strictObject({
97
141
  entry: dotPath("entry").refine((p) => p.endsWith(".mjs"), {
98
142
  message: "entry must be a .mjs file",
@@ -103,6 +147,7 @@ const extensionSection = z.strictObject({
103
147
  configSchemas: z
104
148
  .strictObject({ deployment: configSchemaJson.optional(), org: configSchemaJson.optional() })
105
149
  .optional(),
150
+ client: clientSection.optional(),
106
151
  });
107
152
  const schema = z
108
153
  .strictObject({
@@ -116,7 +161,13 @@ const schema = z
116
161
  .max(256)
117
162
  .regex(SEMVER_VERSION_RE, { message: "version must be an exact semver version" }),
118
163
  publisher: text(L.publisherChars, "publisher"),
119
- description: text(L.descriptionChars, "description"),
164
+ description: z.union([
165
+ text(L.descriptionChars, "description"),
166
+ z.strictObject({
167
+ en: text(L.descriptionChars, "description.en"),
168
+ zh: text(L.descriptionChars, "description.zh").optional(),
169
+ }),
170
+ ]),
120
171
  displayName: localized.optional(),
121
172
  icon: dotPath("icon")
122
173
  .regex(ICON_RE, { message: "icon must be a .svg or .png file" })
@@ -143,7 +194,7 @@ const schema = z
143
194
  .max(L.dependencies)
144
195
  .optional(),
145
196
  skills: z
146
- .array(z.strictObject({ path: dotPath("path"), pinned: z.boolean().optional() }))
197
+ .array(z.strictObject({ path: dotPath("path") }))
147
198
  .max(L.skills)
148
199
  .optional(),
149
200
  connectorTemplates: z
@@ -158,6 +209,14 @@ const schema = z
158
209
  }))
159
210
  .max(L.agents)
160
211
  .optional(),
212
+ themes: z
213
+ .array(z.strictObject({
214
+ 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}$" }),
215
+ }))
216
+ .max(L.themes)
217
+ .optional(),
218
+ setupGuides: z.array(setupGuide).max(SETUP_GUIDE_LIMITS.guides).optional(),
219
+ suggestedAppearance: suggestedAppearance.optional(),
161
220
  extension: extensionSection.optional(),
162
221
  })
163
222
  .superRefine((m, ctx) => {
@@ -196,16 +255,117 @@ const schema = z
196
255
  issue(["agents", i, "path"], `duplicate agent template path ${a.path}`);
197
256
  agentPaths.add(a.path);
198
257
  });
258
+ const themeIds = new Set();
259
+ m.themes?.forEach((t, i) => {
260
+ const id = themeIdOf(t.path);
261
+ if (themeIds.has(id))
262
+ issue(["themes", i, "path"], `duplicate theme id ${id}`);
263
+ themeIds.add(id);
264
+ });
265
+ const guideIds = new Set();
266
+ const guideTemplates = new Set();
267
+ let channelGuides = 0;
268
+ m.setupGuides?.forEach((g, i) => {
269
+ if (guideIds.has(g.id))
270
+ issue(["setupGuides", i, "id"], `duplicate setup guide id ${g.id}`);
271
+ guideIds.add(g.id);
272
+ if (g.place === "connector-template") {
273
+ if (g.template === undefined) {
274
+ issue(["setupGuides", i, "template"], "template is required for a connector-template guide");
275
+ }
276
+ else {
277
+ if (m.connectorTemplates !== undefined && !ids.has(g.template)) {
278
+ issue(["setupGuides", i, "template"], `template ${g.template} is not one of the plugin's connector templates`);
279
+ }
280
+ if (guideTemplates.has(g.template)) {
281
+ issue(["setupGuides", i, "template"], `at most one setup guide per connector template (${g.template} has two)`);
282
+ }
283
+ guideTemplates.add(g.template);
284
+ }
285
+ }
286
+ else if (g.template !== undefined) {
287
+ issue(["setupGuides", i, "template"], "template is only for connector-template guides");
288
+ }
289
+ if (g.place === "channel-connection") {
290
+ channelGuides++;
291
+ if (channelGuides === 2) {
292
+ issue(["setupGuides", i, "place"], "a plugin has at most one channel-connection guide");
293
+ }
294
+ }
295
+ if (g.place === "channel-connection" &&
296
+ m.extension !== undefined &&
297
+ !m.extension.manifest.provides.some((p) => p.startsWith("channel@"))) {
298
+ issue(["setupGuides", i, "place"], "a channel-connection guide needs the plugin's extension to provide channel@1");
299
+ }
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
+ }
199
351
  if (m.extension === undefined &&
200
352
  m.skills?.length === 0 &&
201
353
  m.connectorTemplates?.length === 0 &&
202
- (m.agents === undefined || m.agents.length === 0)) {
203
- issue([], "a plugin must contain an extension, a skill, a connector template or an agent template");
354
+ (m.agents === undefined || m.agents.length === 0) &&
355
+ (m.themes === undefined || m.themes.length === 0)) {
356
+ issue([], "a plugin must contain an extension, a skill, a connector template, an agent template or a theme");
204
357
  }
205
358
  const ext = m.extension;
206
359
  if (ext === undefined)
207
360
  return;
208
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
+ }
209
369
  if (!EXTENSION_NAME_RE.test(m.name)) {
210
370
  issue(["name"], `a plugin with an extension needs an extension name (${EXTENSION_NAME_RE})`);
211
371
  }
@@ -271,6 +431,7 @@ const templateFile = z
271
431
  message: "icon must be a relative .svg or .png path inside the plugin",
272
432
  })
273
433
  .optional(),
434
+ defaultEnabled: z.boolean().optional(),
274
435
  template,
275
436
  })
276
437
  // Field rules (no credentials, auth presets, editableEndpoint, ...) belong to validateConnectorTemplate.
@@ -329,3 +490,13 @@ export function parsePluginManifest(json) {
329
490
  export function parseConnectorTemplateFile(json) {
330
491
  return parseWith(ConnectorTemplateFileSchema, json, "connector template file");
331
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
+ }