@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
@@ -1,13 +1,19 @@
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";
7
+ import { GitSourceSchema } from "./git-hosts.js";
6
8
  import { CATALOG_ITEM_NAME_RE, CONNECTOR_TEMPLATE_LIMITS, isSafePackagePath, SEMVER_VERSION_RE, validateConnectorTemplate, } from "./plugin-package.js";
7
9
  import { hasUpperBound } from "./semver-range.js";
10
+ import { SETUP_GUIDE_LIMITS, SETUP_GUIDE_PLACES } from "./setup-guide.js";
11
+ import { THEME_LIMITS, themeIdOf } from "./theme.js";
12
+ import { parseSlotRef, uiSlot } from "./ui-slots.js";
8
13
  /**
9
14
  * 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:
15
+ * bundle of at most one extension, skills, connector templates, agent templates and themes, packed as
16
+ * an npm-pack tgz:
11
17
  *
12
18
  * ```
13
19
  * package/package.json npm metadata; version equals plugin.json version
@@ -15,13 +21,14 @@ import { hasUpperBound } from "./semver-range.js";
15
21
  * package/skills/<name>/SKILL.md skills
16
22
  * package/connectors/<id>.json connector templates ({@link ConnectorTemplateFile})
17
23
  * package/agents/<name>.md agent templates (parsed by `parseAgentTemplate`)
24
+ * package/themes/<id>.json themes (parsed by `parseThemeFile`)
18
25
  * package/dist/index.mjs extension entry (only with an extension)
19
26
  * package/migrations/*.sql, package/ui/**
20
27
  * ```
21
28
  *
22
29
  * 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.
30
+ * / `agents` / `themes` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md` /
31
+ * `themes/*.json`" (done by the kernel when it reads the package). `extension` is written by the packer, never by hand.
25
32
  *
26
33
  * The committed JSON Schema (`schemas/plugin.v1.schema.json`) is generated from
27
34
  * {@link PluginManifestSchema} by `pnpm gen:package-schemas` and drift-checked by
@@ -43,14 +50,23 @@ export const PLUGIN_MANIFEST_LIMITS = {
43
50
  connectorTemplates: 20,
44
51
  /** Agent templates ({@link AGENT_TEMPLATE_LIMITS}`.perPlugin`). */
45
52
  agents: AGENT_TEMPLATE_LIMITS.perPlugin,
53
+ /** Themes ({@link THEME_LIMITS}`.perPlugin`). */
54
+ themes: THEME_LIMITS.perPlugin,
46
55
  descriptionChars: 1024,
47
56
  publisherChars: 100,
48
57
  displayNameChars: 100,
49
58
  pathChars: 512,
59
+ /** Entries of `suggestedAppearance.replacements`. */
60
+ appearanceReplacements: 8,
50
61
  };
62
+ /** A plugin description as `{ en, zh? }` (a plain string is the English text). */
63
+ export function pluginDescription(d) {
64
+ return typeof d === "string" ? { en: d } : { en: d.en, ...(d.zh !== undefined && { zh: d.zh }) };
65
+ }
51
66
  const L = PLUGIN_MANIFEST_LIMITS;
52
67
  const MAX_ERRORS = 50;
53
68
  const ICON_RE = /\.(?:svg|png)$/i;
69
+ const COMPONENT_ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
54
70
  const HTTPS_URL_RE = /^https:\/\/\S+$/;
55
71
  const text = (max, what) => z
56
72
  .string()
@@ -93,6 +109,35 @@ const configSchemaJson = z
93
109
  .refine((v) => new TextEncoder().encode(JSON.stringify(v)).length <= CONFIG_UI_LIMITS.configSchemaBytes, {
94
110
  message: `must be at most ${CONFIG_UI_LIMITS.configSchemaBytes} bytes of JSON (${CONFIG_UI_LIMITS.configSchemaBytes / 1024} KiB)`,
95
111
  });
112
+ const setupGuide = z.strictObject({
113
+ id: z.string().regex(CATALOG_ITEM_NAME_RE, {
114
+ message: "id must match ^[a-z0-9][a-z0-9-]{0,63}$",
115
+ }),
116
+ place: z.enum(SETUP_GUIDE_PLACES),
117
+ template: z
118
+ .string()
119
+ .regex(CATALOG_ITEM_NAME_RE, { message: "template must match ^[a-z0-9][a-z0-9-]{0,63}$" })
120
+ .optional(),
121
+ });
122
+ const clientSection = z
123
+ .strictObject({
124
+ entry: z.string().max(L.pathChars).optional(),
125
+ styles: z.array(z.string().max(L.pathChars)).max(64).optional(),
126
+ assets: z.array(z.string().max(L.pathChars)).max(256).optional(),
127
+ integrity: z.record(z.string().max(L.pathChars), z.string().max(128)),
128
+ apiVersion: z.number().int().min(1),
129
+ })
130
+ .superRefine((c, ctx) => {
131
+ for (const e of validateClientSection(c))
132
+ ctx.addIssue({ code: "custom", path: [], message: e });
133
+ });
134
+ const suggestedAppearance = z.strictObject({
135
+ theme: z
136
+ .string()
137
+ .regex(CATALOG_ITEM_NAME_RE, { message: "theme must match ^[a-z0-9][a-z0-9-]{0,63}$" })
138
+ .optional(),
139
+ replacements: z.record(z.string().max(100), z.string().max(100)).optional(),
140
+ });
96
141
  const extensionSection = z.strictObject({
97
142
  entry: dotPath("entry").refine((p) => p.endsWith(".mjs"), {
98
143
  message: "entry must be a .mjs file",
@@ -103,6 +148,7 @@ const extensionSection = z.strictObject({
103
148
  configSchemas: z
104
149
  .strictObject({ deployment: configSchemaJson.optional(), org: configSchemaJson.optional() })
105
150
  .optional(),
151
+ client: clientSection.optional(),
106
152
  });
107
153
  const schema = z
108
154
  .strictObject({
@@ -116,7 +162,13 @@ const schema = z
116
162
  .max(256)
117
163
  .regex(SEMVER_VERSION_RE, { message: "version must be an exact semver version" }),
118
164
  publisher: text(L.publisherChars, "publisher"),
119
- description: text(L.descriptionChars, "description"),
165
+ description: z.union([
166
+ text(L.descriptionChars, "description"),
167
+ z.strictObject({
168
+ en: text(L.descriptionChars, "description.en"),
169
+ zh: text(L.descriptionChars, "description.zh").optional(),
170
+ }),
171
+ ]),
120
172
  displayName: localized.optional(),
121
173
  icon: dotPath("icon")
122
174
  .regex(ICON_RE, { message: "icon must be a .svg or .png file" })
@@ -143,7 +195,7 @@ const schema = z
143
195
  .max(L.dependencies)
144
196
  .optional(),
145
197
  skills: z
146
- .array(z.strictObject({ path: dotPath("path"), pinned: z.boolean().optional() }))
198
+ .array(z.strictObject({ path: dotPath("path") }))
147
199
  .max(L.skills)
148
200
  .optional(),
149
201
  connectorTemplates: z
@@ -158,6 +210,14 @@ const schema = z
158
210
  }))
159
211
  .max(L.agents)
160
212
  .optional(),
213
+ themes: z
214
+ .array(z.strictObject({
215
+ 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}$" }),
216
+ }))
217
+ .max(L.themes)
218
+ .optional(),
219
+ setupGuides: z.array(setupGuide).max(SETUP_GUIDE_LIMITS.guides).optional(),
220
+ suggestedAppearance: suggestedAppearance.optional(),
161
221
  extension: extensionSection.optional(),
162
222
  })
163
223
  .superRefine((m, ctx) => {
@@ -196,16 +256,117 @@ const schema = z
196
256
  issue(["agents", i, "path"], `duplicate agent template path ${a.path}`);
197
257
  agentPaths.add(a.path);
198
258
  });
259
+ const themeIds = new Set();
260
+ m.themes?.forEach((t, i) => {
261
+ const id = themeIdOf(t.path);
262
+ if (themeIds.has(id))
263
+ issue(["themes", i, "path"], `duplicate theme id ${id}`);
264
+ themeIds.add(id);
265
+ });
266
+ const guideIds = new Set();
267
+ const guideTemplates = new Set();
268
+ let channelGuides = 0;
269
+ m.setupGuides?.forEach((g, i) => {
270
+ if (guideIds.has(g.id))
271
+ issue(["setupGuides", i, "id"], `duplicate setup guide id ${g.id}`);
272
+ guideIds.add(g.id);
273
+ if (g.place === "connector-template") {
274
+ if (g.template === undefined) {
275
+ issue(["setupGuides", i, "template"], "template is required for a connector-template guide");
276
+ }
277
+ else {
278
+ if (m.connectorTemplates !== undefined && !ids.has(g.template)) {
279
+ issue(["setupGuides", i, "template"], `template ${g.template} is not one of the plugin's connector templates`);
280
+ }
281
+ if (guideTemplates.has(g.template)) {
282
+ issue(["setupGuides", i, "template"], `at most one setup guide per connector template (${g.template} has two)`);
283
+ }
284
+ guideTemplates.add(g.template);
285
+ }
286
+ }
287
+ else if (g.template !== undefined) {
288
+ issue(["setupGuides", i, "template"], "template is only for connector-template guides");
289
+ }
290
+ if (g.place === "channel-connection") {
291
+ channelGuides++;
292
+ if (channelGuides === 2) {
293
+ issue(["setupGuides", i, "place"], "a plugin has at most one channel-connection guide");
294
+ }
295
+ }
296
+ if (g.place === "channel-connection" &&
297
+ m.extension !== undefined &&
298
+ !m.extension.manifest.provides.some((p) => p.startsWith("channel@"))) {
299
+ issue(["setupGuides", i, "place"], "a channel-connection guide needs the plugin's extension to provide channel@1");
300
+ }
301
+ });
302
+ const sa = m.suggestedAppearance;
303
+ if (sa !== undefined) {
304
+ const at = ["suggestedAppearance"];
305
+ if (sa.theme === undefined && sa.replacements === undefined) {
306
+ issue(at, "suggestedAppearance needs theme or replacements");
307
+ }
308
+ if (sa.theme !== undefined && m.themes !== undefined && !themeIds.has(sa.theme)) {
309
+ issue([...at, "theme"], `suggestedAppearance.theme names ${sa.theme}, which is not a theme of the plugin`);
310
+ }
311
+ if (sa.replacements !== undefined) {
312
+ const entries = Object.entries(sa.replacements);
313
+ if (m.extension === undefined) {
314
+ issue([...at, "replacements"], "suggestedAppearance.replacements needs an extension");
315
+ }
316
+ if (entries.length > L.appearanceReplacements) {
317
+ issue([...at, "replacements"], `suggestedAppearance.replacements has ${entries.length} entries; the limit is ${L.appearanceReplacements}`);
318
+ }
319
+ const seen = new Set();
320
+ for (const [slot, id] of entries) {
321
+ const ref = parseSlotRef(slot);
322
+ if (ref === null) {
323
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} is not a slot ref`);
324
+ continue;
325
+ }
326
+ if (seen.has(ref.id)) {
327
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names the slot ${ref.id} again; give each slot once`);
328
+ continue;
329
+ }
330
+ seen.add(ref.id);
331
+ if (!COMPONENT_ID_RE.test(id)) {
332
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names ${id}, which is not a contribution id`);
333
+ continue;
334
+ }
335
+ const known = uiSlot(ref.id);
336
+ if (known === undefined)
337
+ continue;
338
+ if (known.cardinality !== "single") {
339
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} is not a replaceable slot`);
340
+ continue;
341
+ }
342
+ const ok = (m.extension?.manifest.ui ?? []).some((u) => {
343
+ const us = typeof u.slot === "string" ? parseSlotRef(u.slot) : null;
344
+ return u.id === id && u.kind === "component" && us?.id === ref.id;
345
+ });
346
+ if (!ok) {
347
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names ${id}, which is not a component contribution in that slot`);
348
+ }
349
+ }
350
+ }
351
+ }
199
352
  if (m.extension === undefined &&
200
353
  m.skills?.length === 0 &&
201
354
  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");
355
+ (m.agents === undefined || m.agents.length === 0) &&
356
+ (m.themes === undefined || m.themes.length === 0)) {
357
+ issue([], "a plugin must contain an extension, a skill, a connector template, an agent template or a theme");
204
358
  }
205
359
  const ext = m.extension;
206
360
  if (ext === undefined)
207
361
  return;
208
362
  const em = ext.manifest;
363
+ const hasClientPermission = em.permissions.client === true;
364
+ if (ext.client !== undefined && !hasClientPermission) {
365
+ issue(["extension", "client"], "extension.client needs permissions.client: true");
366
+ }
367
+ if (ext.client === undefined && hasClientPermission) {
368
+ 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)");
369
+ }
209
370
  if (!EXTENSION_NAME_RE.test(m.name)) {
210
371
  issue(["name"], `a plugin with an extension needs an extension name (${EXTENSION_NAME_RE})`);
211
372
  }
@@ -258,6 +419,7 @@ const template = z.strictObject({
258
419
  auth: z.record(z.string(), z.unknown()),
259
420
  ownership: z.enum(["org", "personal"]).optional(),
260
421
  defaultToolPolicies: z.record(z.string(), z.enum(["allow", "ask", "deny"])).optional(),
422
+ git: GitSourceSchema.optional(),
261
423
  icon: z.string().max(L.pathChars).optional(),
262
424
  });
263
425
  const templateFile = z
@@ -271,6 +433,7 @@ const templateFile = z
271
433
  message: "icon must be a relative .svg or .png path inside the plugin",
272
434
  })
273
435
  .optional(),
436
+ defaultEnabled: z.boolean().optional(),
274
437
  template,
275
438
  })
276
439
  // Field rules (no credentials, auth presets, editableEndpoint, ...) belong to validateConnectorTemplate.
@@ -329,3 +492,13 @@ export function parsePluginManifest(json) {
329
492
  export function parseConnectorTemplateFile(json) {
330
493
  return parseWith(ConnectorTemplateFileSchema, json, "connector template file");
331
494
  }
495
+ /**
496
+ * The theme check of `suggestedAppearance` after the themes are known (the manifest may omit
497
+ * `themes` and let the scan find them): shared by the packer and the kernel.
498
+ */
499
+ export function appearanceIssues(manifest, themeIds) {
500
+ const theme = manifest.suggestedAppearance?.theme;
501
+ if (theme === undefined || themeIds.includes(theme))
502
+ return [];
503
+ return [`suggestedAppearance.theme names ${theme}, which is not a theme of the plugin`];
504
+ }
@@ -1,4 +1,5 @@
1
1
  import { type ExtensionManifest } from "./define-extension.js";
2
+ import { type GitSource } from "./git-hosts.js";
2
3
  import type { ExtensionPermissions } from "./permissions.js";
3
4
  import type { PluginManifest } from "./plugin-manifest.js";
4
5
  /**
@@ -98,6 +99,8 @@ export interface ConnectorTemplateSpec {
98
99
  ownership?: "org" | "personal";
99
100
  /** 工具名 → 默认策略(安装后记 `policy_source 'template'`)。 */
100
101
  defaultToolPolicies?: Record<string, "allow" | "ask" | "deny">;
102
+ /** Git hosts this connector's credential serves in sandboxes ({@link GitSource}). */
103
+ git?: GitSource;
101
104
  /** 包内路径,svg / png,≤ {@link CONNECTOR_TEMPLATE_LIMITS}`.iconBytes`。 */
102
105
  icon?: string;
103
106
  }
@@ -1,6 +1,7 @@
1
1
  import semver from "semver";
2
2
  import { ConnectorAuthSchema } from "./connector-auth.js";
3
3
  import { EXTENSION_NAME_RE } from "./define-extension.js";
4
+ import { validateGitSource } from "./git-hosts.js";
4
5
  /**
5
6
  * Plugin package (npm-pack tgz) rules shared by the SDK, the packer and the kernel (spec §4.1). Pure
6
7
  * functions only: the kernel reads the tgz and scans imports, `packages/plugin-tools` packs it. The
@@ -333,6 +334,7 @@ const TEMPLATE_KEYS = new Set([
333
334
  "auth",
334
335
  "ownership",
335
336
  "defaultToolPolicies",
337
+ "git",
336
338
  "icon",
337
339
  ]);
338
340
  /**
@@ -439,6 +441,8 @@ export function validateConnectorTemplate(t) {
439
441
  }
440
442
  }
441
443
  }
444
+ if (t.git !== undefined)
445
+ errs.push(...validateGitSource(t.git, "template.git"));
442
446
  if (t.icon !== undefined) {
443
447
  if (typeof t.icon !== "string" || !isSafePackagePath(t.icon) || !/\.(svg|png)$/i.test(t.icon)) {
444
448
  errs.push("template.icon must be a relative .svg or .png path inside the package");