@capybara-hq/plugin-sdk 0.1.0-rc.9 → 0.1.0-rc.90

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 (159) hide show
  1. package/README.md +3 -1
  2. package/agent-docs/agent-templates.md +14 -2
  3. package/agent-docs/concepts.md +14 -5
  4. package/agent-docs/connector-templates.md +11 -3
  5. package/agent-docs/extension-points/channel.md +1 -1
  6. package/agent-docs/extension-points/context.md +15 -0
  7. package/agent-docs/extension-points/device-provider.md +15 -0
  8. package/agent-docs/extension-points/file-preview.md +3 -1
  9. package/agent-docs/extension-points/identity-source.md +2 -0
  10. package/agent-docs/extension-points/model-provider.md +5 -1
  11. package/agent-docs/extension-points/object-store.md +2 -0
  12. package/agent-docs/extension-points/push-provider.md +17 -0
  13. package/agent-docs/extension-points/trigger-source.md +19 -0
  14. package/agent-docs/extensions.md +98 -4
  15. package/agent-docs/plugin-format.md +45 -10
  16. package/agent-docs/setup.md +54 -0
  17. package/api/plugin-sdk.api.md +5983 -0
  18. package/dist/agent-template.d.ts +15 -6
  19. package/dist/agent-template.js +32 -13
  20. package/dist/agents-ctx.d.ts +116 -0
  21. package/dist/agents-ctx.js +22 -0
  22. package/dist/avatar-presets.d.ts +8 -0
  23. package/dist/avatar-presets.js +17 -0
  24. package/dist/bootstrap.d.ts +109 -1
  25. package/dist/bootstrap.js +185 -2
  26. package/dist/cards.d.ts +121 -13
  27. package/dist/cards.js +161 -19
  28. package/dist/channel.d.ts +133 -47
  29. package/dist/channel.js +10 -5
  30. package/dist/client-css.d.ts +36 -0
  31. package/dist/client-css.js +326 -0
  32. package/dist/client-section.d.ts +35 -0
  33. package/dist/client-section.js +133 -0
  34. package/dist/config-ui.d.ts +28 -6
  35. package/dist/config-ui.js +88 -25
  36. package/dist/config-url-fetch.d.ts +19 -0
  37. package/dist/config-url-fetch.js +43 -0
  38. package/dist/connector-auth.d.ts +13 -2
  39. package/dist/connector-auth.js +82 -8
  40. package/dist/connector.d.ts +74 -32
  41. package/dist/context.d.ts +40 -0
  42. package/dist/context.js +2 -0
  43. package/dist/ctx.d.ts +344 -31
  44. package/dist/ctx.js +9 -1
  45. package/dist/define-extension.d.ts +18 -12
  46. package/dist/define-extension.js +18 -5
  47. package/dist/device-denied-paths.d.ts +20 -0
  48. package/dist/device-denied-paths.js +118 -0
  49. package/dist/device-operation.d.ts +348 -0
  50. package/dist/device-operation.js +312 -0
  51. package/dist/device-protocol.d.ts +286 -49
  52. package/dist/device-protocol.js +766 -89
  53. package/dist/device-provider.d.ts +820 -0
  54. package/dist/device-provider.js +432 -0
  55. package/dist/device-service.d.ts +204 -0
  56. package/dist/device-service.js +291 -0
  57. package/dist/dial-in.d.ts +286 -0
  58. package/dist/dial-in.js +213 -0
  59. package/dist/directory.d.ts +15 -12
  60. package/dist/extension-point.d.ts +2 -0
  61. package/dist/extension-point.js +8 -3
  62. package/dist/field-meta.d.ts +19 -0
  63. package/dist/field-meta.js +54 -0
  64. package/dist/file-preview.d.ts +46 -9
  65. package/dist/git-hosts.d.ts +53 -0
  66. package/dist/git-hosts.js +98 -0
  67. package/dist/hooks.d.ts +185 -22
  68. package/dist/hooks.js +6 -0
  69. package/dist/http-access.d.ts +71 -0
  70. package/dist/http-access.js +12 -0
  71. package/dist/identity.d.ts +70 -9
  72. package/dist/identity.js +46 -1
  73. package/dist/inbox.d.ts +103 -0
  74. package/dist/inbox.js +173 -0
  75. package/dist/index.d.ts +30 -4
  76. package/dist/index.js +30 -4
  77. package/dist/model-params.d.ts +41 -22
  78. package/dist/model-params.js +28 -15
  79. package/dist/model.d.ts +295 -77
  80. package/dist/model.js +249 -21
  81. package/dist/native-failure.d.ts +13 -0
  82. package/dist/native-failure.js +31 -0
  83. package/dist/net.d.ts +52 -0
  84. package/dist/net.js +34 -0
  85. package/dist/network-classes.d.ts +98 -0
  86. package/dist/network-classes.js +291 -0
  87. package/dist/permissions.d.ts +95 -25
  88. package/dist/permissions.js +175 -54
  89. package/dist/platform-only.d.ts +27 -0
  90. package/dist/platform-only.js +35 -0
  91. package/dist/plugin-manifest.d.ts +30 -6
  92. package/dist/plugin-manifest.js +147 -55
  93. package/dist/plugin-package.d.ts +82 -39
  94. package/dist/plugin-package.js +68 -41
  95. package/dist/push.d.ts +75 -0
  96. package/dist/push.js +87 -0
  97. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  98. package/dist/sandbox-linux-runtime-source.js +2343 -0
  99. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  100. package/dist/sandbox-native-runtime-source.js +480 -0
  101. package/dist/sandbox-runtime-source.d.ts +47 -0
  102. package/dist/sandbox-runtime-source.js +73 -0
  103. package/dist/sandbox-write-denies.d.ts +139 -0
  104. package/dist/sandbox-write-denies.js +869 -0
  105. package/dist/secret.d.ts +8 -2
  106. package/dist/secret.js +11 -4
  107. package/dist/setup-check.d.ts +128 -0
  108. package/dist/setup-check.js +142 -0
  109. package/dist/setup-guide-parse.d.ts +121 -0
  110. package/dist/setup-guide-parse.js +356 -0
  111. package/dist/setup-guide-render.d.ts +45 -0
  112. package/dist/setup-guide-render.js +351 -0
  113. package/dist/setup-guide.d.ts +86 -72
  114. package/dist/setup-guide.js +340 -108
  115. package/dist/shell-capabilities.d.ts +216 -0
  116. package/dist/shell-capabilities.js +44 -0
  117. package/dist/shell-environment.d.ts +57 -0
  118. package/dist/shell-environment.js +21 -0
  119. package/dist/skill-invocation.d.ts +5 -0
  120. package/dist/skill-invocation.js +4 -3
  121. package/dist/skill.d.ts +27 -17
  122. package/dist/skill.js +40 -26
  123. package/dist/storage.d.ts +52 -25
  124. package/dist/svg-viewbox.d.ts +10 -0
  125. package/dist/svg-viewbox.js +24 -0
  126. package/dist/theme-assets.d.ts +25 -9
  127. package/dist/theme-assets.js +87 -47
  128. package/dist/theme-tokens.generated.d.ts +40 -12
  129. package/dist/theme-tokens.generated.js +36 -8
  130. package/dist/theme.d.ts +56 -10
  131. package/dist/theme.js +117 -23
  132. package/dist/tool.d.ts +242 -28
  133. package/dist/tool.js +135 -13
  134. package/dist/trigger-source.d.ts +35 -0
  135. package/dist/trigger-source.js +2 -0
  136. package/dist/triggers.d.ts +88 -0
  137. package/dist/triggers.js +71 -0
  138. package/dist/ui-parts.d.ts +23 -0
  139. package/dist/ui-parts.js +374 -0
  140. package/dist/ui-resolve.d.ts +2 -7
  141. package/dist/ui-resolve.js +7 -19
  142. package/dist/ui-slots.d.ts +27 -5
  143. package/dist/ui-slots.js +112 -19
  144. package/dist/ui.d.ts +203 -64
  145. package/dist/ui.js +117 -23
  146. package/dist/url.d.ts +4 -1
  147. package/dist/url.js +4 -1
  148. package/dist/web.d.ts +26 -20
  149. package/package.json +13 -1
  150. package/schemas/bootstrap-extra.v1.schema.json +186 -0
  151. package/schemas/bootstrap.v1.schema.json +20 -0
  152. package/schemas/connector-template.v1.schema.json +62 -4
  153. package/schemas/plugin.v1.schema.json +74 -143
  154. package/schemas/theme.v1.schema.json +77 -0
  155. package/agent-docs/extension-points/sandbox.md +0 -15
  156. package/dist/org-access.d.ts +0 -27
  157. package/dist/org-access.js +0 -35
  158. package/dist/sandbox.d.ts +0 -254
  159. package/dist/sandbox.js +0 -153
@@ -1,12 +1,15 @@
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";
8
- import { SETUP_GUIDE_FILE_RE, SETUP_GUIDE_LANGUAGES, SETUP_GUIDE_LIMITS, SETUP_GUIDE_MODES, SETUP_GUIDE_PLACES, } from "./setup-guide.js";
10
+ import { SETUP_GUIDE_LIMITS, SETUP_GUIDE_PLACES } from "./setup-guide.js";
9
11
  import { THEME_LIMITS, themeIdOf } from "./theme.js";
12
+ import { parseSlotRef, uiSlot } from "./ui-slots.js";
10
13
  /**
11
14
  * The plugin manifest `.capybara-plugin/plugin.json` (package ecosystem spec §4.1). A plugin is a
12
15
  * bundle of at most one extension, skills, connector templates, agent templates and themes, packed as
@@ -53,6 +56,8 @@ export const PLUGIN_MANIFEST_LIMITS = {
53
56
  publisherChars: 100,
54
57
  displayNameChars: 100,
55
58
  pathChars: 512,
59
+ /** Entries of `suggestedAppearance.replacements`. */
60
+ appearanceReplacements: 8,
56
61
  };
57
62
  /** A plugin description as `{ en, zh? }` (a plain string is the English text). */
58
63
  export function pluginDescription(d) {
@@ -61,6 +66,7 @@ export function pluginDescription(d) {
61
66
  const L = PLUGIN_MANIFEST_LIMITS;
62
67
  const MAX_ERRORS = 50;
63
68
  const ICON_RE = /\.(?:svg|png)$/i;
69
+ const COMPONENT_ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
64
70
  const HTTPS_URL_RE = /^https:\/\/\S+$/;
65
71
  const text = (max, what) => z
66
72
  .string()
@@ -87,6 +93,11 @@ const baseId = (p) => (p.split("/").pop() ?? "").replace(/\.json$/, "");
87
93
  const configFields = z
88
94
  .array(z.strictObject({ path: z.string().max(1000), secret: z.boolean(), hot: z.boolean() }))
89
95
  .max(1000);
96
+ const configSchemaJson = z
97
+ .record(z.string(), z.unknown())
98
+ .refine((v) => new TextEncoder().encode(JSON.stringify(v)).length <= CONFIG_UI_LIMITS.configSchemaBytes, {
99
+ message: `must be at most ${CONFIG_UI_LIMITS.configSchemaBytes} bytes of JSON (${CONFIG_UI_LIMITS.configSchemaBytes / 1024} KiB)`,
100
+ });
90
101
  const staticExtensionManifest = z.strictObject({
91
102
  name: z.string(),
92
103
  version: z.string(),
@@ -96,39 +107,39 @@ const staticExtensionManifest = z.strictObject({
96
107
  optional: z.array(z.string()),
97
108
  permissions: z.record(z.string(), z.unknown()),
98
109
  ui: z.array(z.record(z.string(), z.unknown())).optional(),
99
- config: z.strictObject({ deployment: configFields, org: configFields }),
110
+ config: z.strictObject({ deployment: configFields }),
100
111
  });
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 guideText = (max, what) => z.strictObject({ en: text(max, `${what}.en`), zh: text(max, `${what}.zh`).optional() });
107
112
  const setupGuide = z.strictObject({
108
113
  id: z.string().regex(CATALOG_ITEM_NAME_RE, {
109
114
  message: "id must match ^[a-z0-9][a-z0-9-]{0,63}$",
110
115
  }),
111
116
  place: z.enum(SETUP_GUIDE_PLACES),
112
- title: guideText(SETUP_GUIDE_LIMITS.titleChars, "title"),
113
- steps: z
114
- .array(z.strictObject({
115
- en: text(SETUP_GUIDE_LIMITS.stepChars, "en"),
116
- zh: text(SETUP_GUIDE_LIMITS.stepChars, "zh").optional(),
117
- mode: z.string().max(64).optional(),
117
+ templates: z
118
+ .array(z.string().regex(CATALOG_ITEM_NAME_RE, {
119
+ message: "a template must match ^[a-z0-9][a-z0-9-]{0,63}$",
118
120
  }))
119
- .max(SETUP_GUIDE_LIMITS.steps)
121
+ .min(1)
122
+ .max(SETUP_GUIDE_LIMITS.templatesPerGuide)
120
123
  .optional(),
121
- files: z
122
- .array(z.strictObject({
123
- path: dotPath("path").regex(SETUP_GUIDE_FILE_RE, {
124
- message: "path must be a .tmpl, .yaml, .yml, .json or .txt file",
125
- }),
126
- title: guideText(SETUP_GUIDE_LIMITS.titleChars, "title"),
127
- language: z.enum(SETUP_GUIDE_LANGUAGES),
128
- mode: z.string().max(64).optional(),
129
- }))
130
- .max(SETUP_GUIDE_LIMITS.files)
124
+ });
125
+ const clientSection = z
126
+ .strictObject({
127
+ entry: z.string().max(L.pathChars).optional(),
128
+ styles: z.array(z.string().max(L.pathChars)).max(64).optional(),
129
+ assets: z.array(z.string().max(L.pathChars)).max(256).optional(),
130
+ integrity: z.record(z.string().max(L.pathChars), z.string().max(128)),
131
+ apiVersion: z.number().int().min(1),
132
+ })
133
+ .superRefine((c, ctx) => {
134
+ for (const e of validateClientSection(c))
135
+ ctx.addIssue({ code: "custom", path: [], message: e });
136
+ });
137
+ const suggestedAppearance = z.strictObject({
138
+ theme: z
139
+ .string()
140
+ .regex(CATALOG_ITEM_NAME_RE, { message: "theme must match ^[a-z0-9][a-z0-9-]{0,63}$" })
131
141
  .optional(),
142
+ replacements: z.record(z.string().max(100), z.string().max(100)).optional(),
132
143
  });
133
144
  const extensionSection = z.strictObject({
134
145
  entry: dotPath("entry").refine((p) => p.endsWith(".mjs"), {
@@ -137,9 +148,8 @@ const extensionSection = z.strictObject({
137
148
  manifest: staticExtensionManifest,
138
149
  migrations: dotPath("migrations").optional(),
139
150
  ui: dotPath("ui").optional(),
140
- configSchemas: z
141
- .strictObject({ deployment: configSchemaJson.optional(), org: configSchemaJson.optional() })
142
- .optional(),
151
+ configSchemas: z.strictObject({ deployment: configSchemaJson.optional() }).optional(),
152
+ client: clientSection.optional(),
143
153
  });
144
154
  const schema = z
145
155
  .strictObject({
@@ -186,7 +196,7 @@ const schema = z
186
196
  .max(L.dependencies)
187
197
  .optional(),
188
198
  skills: z
189
- .array(z.strictObject({ path: dotPath("path"), pinned: z.boolean().optional() }))
199
+ .array(z.strictObject({ path: dotPath("path") }))
190
200
  .max(L.skills)
191
201
  .optional(),
192
202
  connectorTemplates: z
@@ -208,6 +218,7 @@ const schema = z
208
218
  .max(L.themes)
209
219
  .optional(),
210
220
  setupGuides: z.array(setupGuide).max(SETUP_GUIDE_LIMITS.guides).optional(),
221
+ suggestedAppearance: suggestedAppearance.optional(),
211
222
  extension: extensionSection.optional(),
212
223
  })
213
224
  .superRefine((m, ctx) => {
@@ -254,36 +265,93 @@ const schema = z
254
265
  themeIds.add(id);
255
266
  });
256
267
  const guideIds = new Set();
268
+ const guideTemplates = new Set();
269
+ let channelGuides = 0;
257
270
  m.setupGuides?.forEach((g, i) => {
258
271
  if (guideIds.has(g.id))
259
272
  issue(["setupGuides", i, "id"], `duplicate setup guide id ${g.id}`);
260
273
  guideIds.add(g.id);
261
- if ((g.steps?.length ?? 0) === 0 && (g.files?.length ?? 0) === 0) {
262
- issue(["setupGuides", i], "a setup guide needs at least one step or file");
263
- }
264
- const modes = SETUP_GUIDE_MODES[g.place];
265
- const badMode = (mode, path) => {
266
- if (mode !== undefined && !modes.includes(mode)) {
267
- issue(path, `mode must be one of ${modes.join(", ")} for place ${g.place}`);
274
+ if (g.place === "connector-template") {
275
+ if (g.templates === undefined) {
276
+ issue(["setupGuides", i, "templates"], "templates is required for a connector-template guide");
268
277
  }
269
- };
270
- g.steps?.forEach((s, j) => {
271
- badMode(s.mode, ["setupGuides", i, "steps", j, "mode"]);
272
- });
273
- const paths = new Set();
274
- g.files?.forEach((f, j) => {
275
- badMode(f.mode, ["setupGuides", i, "files", j, "mode"]);
276
- if (paths.has(f.path)) {
277
- issue(["setupGuides", i, "files", j, "path"], `duplicate file ${f.path} in the guide`);
278
+ else {
279
+ g.templates.forEach((t, j) => {
280
+ if (m.connectorTemplates !== undefined && !ids.has(t)) {
281
+ issue(["setupGuides", i, "templates", j], `template ${t} is not one of the plugin's connector templates`);
282
+ }
283
+ if (guideTemplates.has(t)) {
284
+ issue(["setupGuides", i, "templates", j], `at most one setup guide per connector template (${t} is named twice)`);
285
+ }
286
+ guideTemplates.add(t);
287
+ });
278
288
  }
279
- paths.add(f.path);
280
- });
289
+ }
290
+ else if (g.templates !== undefined) {
291
+ issue(["setupGuides", i, "templates"], "templates is only for connector-template guides");
292
+ }
293
+ if (g.place === "channel-connection") {
294
+ channelGuides++;
295
+ if (channelGuides === 2) {
296
+ issue(["setupGuides", i, "place"], "a plugin has at most one channel-connection guide");
297
+ }
298
+ }
281
299
  if (g.place === "channel-connection" &&
282
300
  m.extension !== undefined &&
283
301
  !m.extension.manifest.provides.some((p) => p.startsWith("channel@"))) {
284
302
  issue(["setupGuides", i, "place"], "a channel-connection guide needs the plugin's extension to provide channel@1");
285
303
  }
286
304
  });
305
+ const sa = m.suggestedAppearance;
306
+ if (sa !== undefined) {
307
+ const at = ["suggestedAppearance"];
308
+ if (sa.theme === undefined && sa.replacements === undefined) {
309
+ issue(at, "suggestedAppearance needs theme or replacements");
310
+ }
311
+ if (sa.theme !== undefined && m.themes !== undefined && !themeIds.has(sa.theme)) {
312
+ issue([...at, "theme"], `suggestedAppearance.theme names ${sa.theme}, which is not a theme of the plugin`);
313
+ }
314
+ if (sa.replacements !== undefined) {
315
+ const entries = Object.entries(sa.replacements);
316
+ if (m.extension === undefined) {
317
+ issue([...at, "replacements"], "suggestedAppearance.replacements needs an extension");
318
+ }
319
+ if (entries.length > L.appearanceReplacements) {
320
+ issue([...at, "replacements"], `suggestedAppearance.replacements has ${entries.length} entries; the limit is ${L.appearanceReplacements}`);
321
+ }
322
+ const seen = new Set();
323
+ for (const [slot, id] of entries) {
324
+ const ref = parseSlotRef(slot);
325
+ if (ref === null) {
326
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} is not a slot ref`);
327
+ continue;
328
+ }
329
+ if (seen.has(ref.id)) {
330
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names the slot ${ref.id} again; give each slot once`);
331
+ continue;
332
+ }
333
+ seen.add(ref.id);
334
+ if (!COMPONENT_ID_RE.test(id)) {
335
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names ${id}, which is not a contribution id`);
336
+ continue;
337
+ }
338
+ const known = uiSlot(ref.id);
339
+ if (known === undefined)
340
+ continue;
341
+ if (known.cardinality !== "single") {
342
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} is not a replaceable slot`);
343
+ continue;
344
+ }
345
+ const ok = (m.extension?.manifest.ui ?? []).some((u) => {
346
+ const us = typeof u.slot === "string" ? parseSlotRef(u.slot) : null;
347
+ return u.id === id && u.kind === "component" && us?.id === ref.id;
348
+ });
349
+ if (!ok) {
350
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names ${id}, which is not a component contribution in that slot`);
351
+ }
352
+ }
353
+ }
354
+ }
287
355
  if (m.extension === undefined &&
288
356
  m.skills?.length === 0 &&
289
357
  m.connectorTemplates?.length === 0 &&
@@ -295,6 +363,13 @@ const schema = z
295
363
  if (ext === undefined)
296
364
  return;
297
365
  const em = ext.manifest;
366
+ const hasClientPermission = em.permissions.client === true;
367
+ if (ext.client !== undefined && !hasClientPermission) {
368
+ issue(["extension", "client"], "extension.client needs permissions.client: true");
369
+ }
370
+ if (ext.client === undefined && hasClientPermission) {
371
+ 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)");
372
+ }
298
373
  if (!EXTENSION_NAME_RE.test(m.name)) {
299
374
  issue(["name"], `a plugin with an extension needs an extension name (${EXTENSION_NAME_RE})`);
300
375
  }
@@ -307,14 +382,12 @@ const schema = z
307
382
  if (semver.validRange(em.sdk) !== null && !hasUpperBound(em.sdk)) {
308
383
  issue(["extension", "manifest", "sdk"], `"${em.sdk}" has no upper bound: use a range such as ^0.1.0 so a future major SDK is not assumed compatible`);
309
384
  }
310
- for (const k of ["deployment", "org"]) {
311
- const seen = new Set();
312
- for (const f of em.config[k]) {
313
- if (seen.has(f.path)) {
314
- issue(["extension", "manifest", "config", k], `duplicate config path "${f.path}"`);
315
- }
316
- seen.add(f.path);
385
+ const seen = new Set();
386
+ for (const f of em.config.deployment) {
387
+ if (seen.has(f.path)) {
388
+ issue(["extension", "manifest", "config", "deployment"], `duplicate config path "${f.path}"`);
317
389
  }
390
+ seen.add(f.path);
318
391
  }
319
392
  // Name, version, sdk range, extension point refs, permissions, UI contributions: the same
320
393
  // rules as defineExtension (with a placeholder setup).
@@ -347,12 +420,21 @@ const template = z.strictObject({
347
420
  auth: z.record(z.string(), z.unknown()),
348
421
  ownership: z.enum(["org", "personal"]).optional(),
349
422
  defaultToolPolicies: z.record(z.string(), z.enum(["allow", "ask", "deny"])).optional(),
423
+ git: GitSourceSchema.optional(),
350
424
  icon: z.string().max(L.pathChars).optional(),
351
425
  });
352
426
  const templateFile = z
353
427
  .strictObject({
354
428
  displayName: localized,
355
- description: text(CONNECTOR_TEMPLATE_LIMITS.descriptionChars, "description").optional(),
429
+ description: z
430
+ .union([
431
+ text(CONNECTOR_TEMPLATE_LIMITS.descriptionChars, "description"),
432
+ z.strictObject({
433
+ zh: text(CONNECTOR_TEMPLATE_LIMITS.descriptionChars, "description.zh"),
434
+ en: text(CONNECTOR_TEMPLATE_LIMITS.descriptionChars, "description.en"),
435
+ }),
436
+ ])
437
+ .optional(),
356
438
  icon: z
357
439
  .string()
358
440
  .max(L.pathChars)
@@ -419,3 +501,13 @@ export function parsePluginManifest(json) {
419
501
  export function parseConnectorTemplateFile(json) {
420
502
  return parseWith(ConnectorTemplateFileSchema, json, "connector template file");
421
503
  }
504
+ /**
505
+ * The theme check of `suggestedAppearance` after the themes are known (the manifest may omit
506
+ * `themes` and let the scan find them): shared by the packer and the kernel.
507
+ */
508
+ export function appearanceIssues(manifest, themeIds) {
509
+ const theme = manifest.suggestedAppearance?.theme;
510
+ if (theme === undefined || themeIds.includes(theme))
511
+ return [];
512
+ return [`suggestedAppearance.theme names ${theme}, which is not a theme of the plugin`];
513
+ }
@@ -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
  /**
@@ -10,17 +11,29 @@ import type { PluginManifest } from "./plugin-manifest.js";
10
11
  * entry is single-file ESM with third-party dependencies bundled; only {@link HOST_PROVIDED_PACKAGES}
11
12
  * come from the host.
12
13
  */
13
- /** 宿主提供的包(peerDependencies,安装时链接到宿主副本);其余三方依赖必须打进 entry。 */
14
+ /**
15
+ * Packages provided by the host (peerDependencies, linked to the host's copy on install); every
16
+ * other third-party dependency must be bundled into the entry.
17
+ */
14
18
  export declare const HOST_PROVIDED_PACKAGES: readonly ["@capybara-hq/plugin-sdk", "zod"];
15
- /** npm 安装时会自动执行的脚本:插件包一律不许有(安装不跑脚本,有也是误导)。 */
19
+ /**
20
+ * Scripts npm runs automatically on install: a plugin package must never have any (installs run no
21
+ * scripts, so having them would mislead).
22
+ */
16
23
  export declare const FORBIDDEN_INSTALL_SCRIPTS: readonly ["preinstall", "install", "postinstall", "prepare"];
17
- /** 静态清单里的一个配置字段(点路径,根即叶子时为空串)。 */
24
+ /**
25
+ * A config field in the static manifest (a dotted path; an empty string when the root is itself the
26
+ * leaf).
27
+ */
18
28
  export interface StaticConfigField {
19
29
  path: string;
20
30
  secret: boolean;
21
31
  hot: boolean;
22
32
  }
23
- /** 插件清单的静态部分(可 JSON 序列化;不含 setup、zod schema、migrations 路径)。 */
33
+ /**
34
+ * The static part of the plugin manifest (JSON-serializable; excludes setup, zod schemas and
35
+ * migration paths).
36
+ */
24
37
  export interface StaticExtensionManifest {
25
38
  name: string;
26
39
  version: string;
@@ -32,30 +45,40 @@ export interface StaticExtensionManifest {
32
45
  ui?: ExtensionManifest["ui"];
33
46
  config: {
34
47
  deployment: StaticConfigField[];
35
- org: StaticConfigField[];
36
48
  };
37
49
  }
38
- /** 入口模块里的一个 import:`name` 是 specifier(非字面量的动态 import 时为空串)。 */
50
+ /**
51
+ * An import in the entry module: `name` is the specifier (an empty string for a dynamic import that
52
+ * is not a literal).
53
+ */
39
54
  export interface EntryImport {
40
55
  name: string;
41
56
  dynamic: boolean;
42
57
  literal: boolean;
43
58
  }
44
- /** npm 包名规则(简化):可带 scope,小写,≤ 214 字符(长度另行检查)。 */
59
+ /**
60
+ * npm package name rule (simplified): may carry a scope, lowercase, ≤ 214 characters (the length is
61
+ * checked separately).
62
+ */
45
63
  export declare const NPM_PACKAGE_NAME_RE: RegExp;
46
64
  /**
47
- * 包内相对路径是否安全:非空、不以 `/` 开头、不含 `\`、控制字符与盘符,没有空段、`.` 与 `..` 段,≤ 1024 字符。
65
+ * Whether a path relative to the package is safe: non-empty, not starting with `/`, no `\`, control
66
+ * characters or drive letters, no empty segments, `.` or `..` segments, ≤ 1024 characters.
48
67
  */
49
68
  export declare function isSafePackagePath(p: string): boolean;
50
69
  /**
51
- * 核对入口模块的 import(C11):静态与字面量动态 import 只许 `node:*`、{@link HOST_PROVIDED_PACKAGES}(含子路径)
52
- * 与包内相对路径(`./`、`../`;是否越出包外由调用方按文件位置判断);非字面量的动态 import 一律拒绝。
53
- * 返回问题列表(空表示合法)。
70
+ * Checks the entry module's imports (C11): static and literal dynamic imports may only be `node:*`,
71
+ * {@link HOST_PROVIDED_PACKAGES} (subpaths included)
72
+ * and in-package relative paths (`./`, `../`; whether they escape the package is judged by the
73
+ * caller from the file location); non-literal dynamic imports are always rejected.
74
+ * Returns the list of problems (empty means valid).
54
75
  */
55
76
  export declare function checkEntryImports(specifiers: EntryImport[]): string[];
56
77
  /**
57
- * 真实清单的静态部分:打包时写进 `capybara.manifest`,加载时与包内的比对(`manifest_mismatch`)。
58
- * 结果可 JSON 往返(undefined 字段去掉);配置字段按路径排序。
78
+ * The static part of the real manifest: written into `capybara.manifest` when packing, and compared
79
+ * with the in-package one at load time (`manifest_mismatch`).
80
+ * The result survives a JSON round trip (undefined fields removed); config fields are sorted by
81
+ * path.
59
82
  */
60
83
  export declare function staticManifestOf(m: ExtensionManifest): StaticExtensionManifest;
61
84
  /**
@@ -78,62 +101,82 @@ export declare function validatePluginPackageJsonFor(pkg: unknown, manifest: Plu
78
101
  */
79
102
  export declare function hostSdkProblem(sdk: string, hostSdkVersion: string): string | undefined;
80
103
  /**
81
- * 连接器模板(C30):连接器插件引用 + `Connector.kind` + 端点预设 + 组织可改的端点路径 + 认证预设(不含凭据)+
82
- * 默认 ownership + 各工具默认策略 + 图标。组织安装时只能填凭据、客户端 id / secret 与 `editableEndpoint` 里的字段。
104
+ * Connector template (C30): connector plugin reference + `Connector.kind` + endpoint preset +
105
+ * endpoint paths an org may change + auth preset (no credentials) +
106
+ * default ownership + default policy per tool + icon. When installing, an org may only fill in
107
+ * credentials, the client id / secret and the fields in `editableEndpoint`.
83
108
  */
84
109
  export interface ConnectorTemplateSpec {
85
- /** 连接器插件名(如 `connector-mcp`)。 */
110
+ /** Connector plugin name (e.g. `connector-mcp`). */
86
111
  plugin: string;
87
- /** 连接器插件的 semver 范围,可选。 */
112
+ /** Semver range of the connector plugin, optional. */
88
113
  pluginVersion?: string;
89
- /** `Connector.kind`(如 `"mcp"`)。 */
114
+ /** `Connector.kind` (e.g. `"mcp"`). */
90
115
  connector: string;
91
- /** 端点预设;导入时内核按该连接器的 `endpointSchema` 校验。 */
116
+ /**
117
+ * Endpoint preset; on import the kernel validates it against that connector's `endpointSchema`.
118
+ */
92
119
  endpoint: Record<string, unknown>;
93
- /** 组织安装时允许改的点路径(如 `"url"`);其余以模板为准。路径必须存在于连接器的端点 schema 中。 */
120
+ /**
121
+ * Dotted paths an org may change when installing (e.g. `"url"`); everything else follows the
122
+ * template. The paths must exist in the connector's endpoint schema.
123
+ */
94
124
  editableEndpoint?: string[];
95
- /** 与连接器安装接口的认证方式同形({@link ConnectorAuthSchema}),不含任何凭据。 */
125
+ /**
126
+ * The same shape as the auth method of the connector install API ({@link ConnectorAuthSchema}),
127
+ * carrying no credentials.
128
+ */
96
129
  auth: Record<string, unknown>;
97
- /** 缺省取 `auth.ownership`;给了就必须与之一致。 */
130
+ /** Defaults to `auth.ownership`; if given it must agree. */
98
131
  ownership?: "org" | "personal";
99
- /** 工具名 → 默认策略(安装后记 `policy_source 'template'`)。 */
132
+ /** Tool name -> default policy (recorded as `policy_source 'template'` after install). */
100
133
  defaultToolPolicies?: Record<string, "allow" | "ask" | "deny">;
101
- /** 包内路径,svg / png,≤ {@link CONNECTOR_TEMPLATE_LIMITS}`.iconBytes`。 */
134
+ /** Git hosts this connector's credential serves in sandboxes ({@link GitSource}). */
135
+ git?: GitSource;
136
+ /** In-package path, svg / png, ≤ {@link CONNECTOR_TEMPLATE_LIMITS}`.iconBytes`. */
102
137
  icon?: string;
103
138
  }
104
- /** 双语显示名。 */
139
+ /** Bilingual display name. */
105
140
  export interface LocalizedName {
106
141
  zh: string;
107
142
  en: string;
108
143
  }
109
- /** 连接器模板与目录段的上限。 */
144
+ /** Limits of connector templates and catalog segments. */
110
145
  export declare const CONNECTOR_TEMPLATE_LIMITS: {
111
- /** 图标字节数上限。 */
146
+ /** Upper bound on icon bytes. */
112
147
  readonly iconBytes: number;
113
- /** 端点预设 JSON 序列化后的字符数上限。 */
148
+ /** Upper bound on the characters of the endpoint preset after JSON serialization. */
114
149
  readonly endpointChars: number;
115
- /** `editableEndpoint` 条数上限。 */
150
+ /** Upper bound on the number of `editableEndpoint` entries. */
116
151
  readonly editablePaths: 50;
117
- /** `defaultToolPolicies` 条数上限。 */
152
+ /** Upper bound on the number of `defaultToolPolicies` entries. */
118
153
  readonly toolPolicies: 1000;
119
- /** publisher 字符数上限。 */
154
+ /** Upper bound on the characters of publisher. */
120
155
  readonly publisherChars: 100;
121
- /** description 字符数上限。 */
156
+ /** Upper bound on the characters of description (per language when it is `{ zh, en }`). */
122
157
  readonly descriptionChars: 1024;
123
- /** displayName 每种语言的字符数上限。 */
158
+ /** Upper bound on the characters of displayName per language. */
124
159
  readonly displayNameChars: 100;
125
160
  };
126
- /** 目录条目名(与清单条目名同一规则):小写字母或数字开头,之后小写字母、数字、连字符,≤ 64。 */
161
+ /**
162
+ * Catalog entry name (the same rule as manifest entry names): starts with a lowercase letter or
163
+ * digit, then lowercase letters, digits and hyphens, ≤ 64.
164
+ */
127
165
  export declare const CATALOG_ITEM_NAME_RE: RegExp;
128
166
  /** An exact semver version (a regex JSON Schema can use). */
129
167
  export declare const SEMVER_VERSION_RE: RegExp;
130
168
  /** The sha512 SRI of an npm package tgz: `sha512-<86 base64 chars>==`. */
131
169
  export declare const SHA512_INTEGRITY_RE: RegExp;
132
170
  /**
133
- * 校验连接器模板({@link ConnectorTemplateSpec})的静态部分,返回问题列表(空表示合法;路径相对模板根,不回显值):
134
- * 字段齐全、无未知字段;`auth` 符合 {@link ConnectorAuthSchema}(strict:夹带 `token` 等多余字段即拒绝);
135
- * 端点预设里任何层级都不许有凭据样式的键;`editableEndpoint` 是不重复的点路径;`ownership` 与 `auth.ownership`
136
- * 一致;默认策略只许 allow / ask / deny;icon 是包内 .svg / .png 路径。
137
- * 端点是否符合连接器的 `endpointSchema`、`editableEndpoint` 是否存在于其中,由内核在导入时按已加载的连接器校验。
171
+ * Validates the static part of a connector template ({@link ConnectorTemplateSpec}) and returns the
172
+ * list of problems (empty means valid; paths are relative to the template root, values are not
173
+ * echoed):
174
+ * fields complete, no unknown fields; `auth` conforms to {@link ConnectorAuthSchema} (strict: extra
175
+ * fields such as `token` are rejected);
176
+ * no credential-style key at any level of the endpoint preset; `editableEndpoint` is a list of
177
+ * distinct dotted paths; `ownership` agrees with `auth.ownership`;
178
+ * default policies may only be allow / ask / deny; icon is an in-package .svg / .png path.
179
+ * Whether the endpoint conforms to the connector's `endpointSchema` and whether `editableEndpoint`
180
+ * exists in it is checked by the kernel on import against the loaded connector.
138
181
  */
139
182
  export declare function validateConnectorTemplate(t: unknown): string[];