@capybara-hq/plugin-sdk 0.1.0-rc.7 → 0.1.0-rc.70

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 (146) hide show
  1. package/README.md +1 -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 +2 -0
  9. package/agent-docs/extension-points/model-provider.md +3 -1
  10. package/agent-docs/extension-points/object-store.md +2 -0
  11. package/agent-docs/extension-points/push-provider.md +17 -0
  12. package/agent-docs/extensions.md +76 -3
  13. package/agent-docs/plugin-format.md +51 -12
  14. package/agent-docs/setup.md +54 -0
  15. package/dist/agent-template.d.ts +15 -6
  16. package/dist/agent-template.js +32 -13
  17. package/dist/avatar-presets.d.ts +8 -0
  18. package/dist/avatar-presets.js +17 -0
  19. package/dist/bootstrap.d.ts +109 -1
  20. package/dist/bootstrap.js +185 -2
  21. package/dist/cards.d.ts +60 -13
  22. package/dist/cards.js +88 -18
  23. package/dist/channel.d.ts +128 -47
  24. package/dist/channel.js +10 -5
  25. package/dist/client-css.d.ts +36 -0
  26. package/dist/client-css.js +326 -0
  27. package/dist/client-section.d.ts +35 -0
  28. package/dist/client-section.js +133 -0
  29. package/dist/config-ui.d.ts +28 -6
  30. package/dist/config-ui.js +88 -25
  31. package/dist/config-url-fetch.d.ts +19 -0
  32. package/dist/config-url-fetch.js +43 -0
  33. package/dist/connector-auth.d.ts +13 -2
  34. package/dist/connector-auth.js +82 -8
  35. package/dist/connector.d.ts +74 -32
  36. package/dist/context.d.ts +40 -0
  37. package/dist/context.js +2 -0
  38. package/dist/ctx.d.ts +210 -30
  39. package/dist/ctx.js +9 -1
  40. package/dist/define-extension.d.ts +23 -13
  41. package/dist/define-extension.js +19 -5
  42. package/dist/device-denied-paths.d.ts +20 -0
  43. package/dist/device-denied-paths.js +118 -0
  44. package/dist/device-operation.d.ts +339 -0
  45. package/dist/device-operation.js +312 -0
  46. package/dist/device-protocol.d.ts +285 -50
  47. package/dist/device-protocol.js +755 -90
  48. package/dist/device-provider.d.ts +708 -0
  49. package/dist/device-provider.js +325 -0
  50. package/dist/device-service.d.ts +52 -0
  51. package/dist/device-service.js +105 -0
  52. package/dist/dial-in.d.ts +239 -0
  53. package/dist/dial-in.js +155 -0
  54. package/dist/directory.d.ts +15 -12
  55. package/dist/extension-point.d.ts +2 -0
  56. package/dist/extension-point.js +6 -2
  57. package/dist/field-meta.d.ts +19 -0
  58. package/dist/field-meta.js +54 -0
  59. package/dist/file-preview.d.ts +26 -10
  60. package/dist/git-hosts.d.ts +53 -0
  61. package/dist/git-hosts.js +98 -0
  62. package/dist/hooks.d.ts +125 -20
  63. package/dist/hooks.js +5 -0
  64. package/dist/http-access.d.ts +62 -0
  65. package/dist/http-access.js +12 -0
  66. package/dist/identity.d.ts +38 -9
  67. package/dist/identity.js +21 -1
  68. package/dist/index.d.ts +31 -4
  69. package/dist/index.js +31 -4
  70. package/dist/model-params.d.ts +41 -22
  71. package/dist/model-params.js +28 -15
  72. package/dist/model.d.ts +210 -75
  73. package/dist/model.js +152 -19
  74. package/dist/net.d.ts +52 -0
  75. package/dist/net.js +34 -0
  76. package/dist/network-classes.d.ts +98 -0
  77. package/dist/network-classes.js +291 -0
  78. package/dist/permissions.d.ts +65 -22
  79. package/dist/permissions.js +139 -43
  80. package/dist/platform-only.d.ts +27 -0
  81. package/dist/platform-only.js +35 -0
  82. package/dist/plugin-manifest.d.ts +40 -9
  83. package/dist/plugin-manifest.js +171 -60
  84. package/dist/plugin-package.d.ts +82 -39
  85. package/dist/plugin-package.js +68 -41
  86. package/dist/push.d.ts +75 -0
  87. package/dist/push.js +87 -0
  88. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  89. package/dist/sandbox-linux-runtime-source.js +2343 -0
  90. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  91. package/dist/sandbox-native-runtime-source.js +476 -0
  92. package/dist/sandbox-runtime-source.d.ts +47 -0
  93. package/dist/sandbox-runtime-source.js +73 -0
  94. package/dist/sandbox-write-denies.d.ts +139 -0
  95. package/dist/sandbox-write-denies.js +869 -0
  96. package/dist/secret.d.ts +8 -2
  97. package/dist/secret.js +11 -4
  98. package/dist/setup-check.d.ts +128 -0
  99. package/dist/setup-check.js +142 -0
  100. package/dist/setup-guide-parse.d.ts +121 -0
  101. package/dist/setup-guide-parse.js +356 -0
  102. package/dist/setup-guide-render.d.ts +45 -0
  103. package/dist/setup-guide-render.js +351 -0
  104. package/dist/setup-guide.d.ts +86 -72
  105. package/dist/setup-guide.js +340 -108
  106. package/dist/shell-capabilities.d.ts +211 -0
  107. package/dist/shell-capabilities.js +44 -0
  108. package/dist/shell-environment.d.ts +57 -0
  109. package/dist/shell-environment.js +21 -0
  110. package/dist/skill.d.ts +27 -17
  111. package/dist/skill.js +40 -26
  112. package/dist/storage.d.ts +52 -25
  113. package/dist/svg-viewbox.d.ts +10 -0
  114. package/dist/svg-viewbox.js +24 -0
  115. package/dist/theme-assets.d.ts +55 -0
  116. package/dist/theme-assets.js +489 -0
  117. package/dist/theme-readability.d.ts +37 -0
  118. package/dist/theme-readability.js +145 -0
  119. package/dist/theme-tokens.generated.d.ts +299 -0
  120. package/dist/theme-tokens.generated.js +184 -0
  121. package/dist/theme.d.ts +190 -0
  122. package/dist/theme.js +471 -0
  123. package/dist/tool.d.ts +104 -30
  124. package/dist/tool.js +29 -9
  125. package/dist/ui-parts.d.ts +23 -0
  126. package/dist/ui-parts.js +385 -0
  127. package/dist/ui-resolve.d.ts +35 -0
  128. package/dist/ui-resolve.js +42 -0
  129. package/dist/ui-slots.d.ts +65 -0
  130. package/dist/ui-slots.js +261 -0
  131. package/dist/ui.d.ts +221 -77
  132. package/dist/ui.js +104 -27
  133. package/dist/url.d.ts +4 -1
  134. package/dist/url.js +4 -1
  135. package/dist/web.d.ts +26 -20
  136. package/package.json +13 -1
  137. package/schemas/bootstrap-extra.v1.schema.json +186 -0
  138. package/schemas/bootstrap.v1.schema.json +20 -0
  139. package/schemas/connector-template.v1.schema.json +62 -4
  140. package/schemas/plugin.v1.schema.json +93 -143
  141. package/schemas/theme.v1.schema.json +302 -0
  142. package/agent-docs/extension-points/sandbox.md +0 -15
  143. package/dist/org-access.d.ts +0 -27
  144. package/dist/org-access.js +0 -35
  145. package/dist/sandbox.d.ts +0 -254
  146. package/dist/sandbox.js +0 -153
@@ -9,11 +9,26 @@ import { z } from "zod";
9
9
  * the official plugins are published: `path` is packed with `packages/plugin-tools`, which is
10
10
  * byte-reproducible, and `integrity` is that pack's sha512).
11
11
  *
12
+ * `required` and `builtin` are two different promises. A required entry is imported in the first
13
+ * pass, before the extensions load, and the start fails without it (so it can ship no skills or
14
+ * templates: those need object storage, which is not running then). A `builtin` entry is imported
15
+ * once the extensions have loaded (object storage available), so it may ship skills; its failure
16
+ * is logged and retried on the next start. Both give the plugin a builtin catalog item (scope
17
+ * `all`, on in every org, not switchable) and are imported again when missing. An entry is never
18
+ * both.
19
+ *
20
+ * An optional preinstall (neither) may carry `scope: "all"`: its catalog item is then created with
21
+ * scope `all` (on in every org, an org admin may switch it off) instead of `optional` (off until
22
+ * switched on). The scope is read only at the first import; a later change in the manifest never
23
+ * rewrites the item, the super admin owns it after that. `scope` on a required or builtin entry
24
+ * is refused.
25
+ *
12
26
  * Objects are strict (unknown keys rejected, `$schema` allowed): the manifest ships with core, so
13
27
  * there is no older reader to stay compatible with and a misspelt key is a mistake. The committed
14
28
  * JSON Schema (`schemas/bootstrap.v1.schema.json`) is generated from {@link BootstrapManifestSchema}
15
29
  * by `pnpm gen:package-schemas`; the cross-field rules (unique names, `marketplace` required with an
16
- * npm entry) are decided only by {@link parseBootstrapManifest}.
30
+ * npm entry, not both `required` and `builtin`, `scope` only on an optional preinstall) are
31
+ * decided only by {@link parseBootstrapManifest}.
17
32
  */
18
33
  /** Manifest format version. */
19
34
  export declare const BOOTSTRAP_MANIFEST_SCHEMA_VERSION = 1;
@@ -30,6 +45,18 @@ export type BootstrapEntry = {
30
45
  integrity: string;
31
46
  /** Enabled in every org and neither disableable nor uninstallable. */
32
47
  required: boolean;
48
+ /**
49
+ * Builtin but not required: imported after the extensions loaded (it may ship skills), its
50
+ * catalog item builtin; a failure does not stop the start. Never together with `required`.
51
+ */
52
+ builtin?: boolean;
53
+ /**
54
+ * Only for an optional preinstall (neither `required` nor `builtin`): the scope its catalog
55
+ * item gets when first imported (default `optional`: off in every org until switched on).
56
+ * `all` is on in every org and an org admin may switch it off. Read only at the first
57
+ * import: a later change here never rewrites the item (the super admin owns it then).
58
+ */
59
+ scope?: "all" | "optional";
33
60
  } | {
34
61
  name: string;
35
62
  source: "workspace";
@@ -38,6 +65,14 @@ export type BootstrapEntry = {
38
65
  version: string;
39
66
  integrity: string;
40
67
  required: boolean;
68
+ builtin?: boolean;
69
+ /**
70
+ * Only for an optional preinstall (neither `required` nor `builtin`): the scope its catalog
71
+ * item gets when first imported (default `optional`: off in every org until switched on).
72
+ * `all` is on in every org and an org admin may switch it off. Read only at the first
73
+ * import: a later change here never rewrites the item (the super admin owns it then).
74
+ */
75
+ scope?: "all" | "optional";
41
76
  };
42
77
  /** `bootstrap.json`. */
43
78
  export interface BootstrapManifest {
@@ -65,3 +100,76 @@ export declare function parseBootstrapManifest(json: unknown): BootstrapManifest
65
100
  };
66
101
  /** The file name of an entry's tgz in the bootstrap directory: `<name>-<version>.tgz`. */
67
102
  export declare function bootstrapFileName(e: BootstrapEntry): string;
103
+ /** Extra manifest format version. */
104
+ export declare const BOOTSTRAP_EXTRA_MANIFEST_SCHEMA_VERSION = 1;
105
+ /** A `git` entry: a plugin directory of a declared marketplace at a pinned commit. */
106
+ export interface BootstrapGitEntry {
107
+ /** Catalog item name. */
108
+ name: string;
109
+ source: "git";
110
+ /** A name from the manifest's `marketplaces`. */
111
+ marketplace: string;
112
+ /** 40-hex commit the tree is read at (never a branch). */
113
+ commit: string;
114
+ /** The plugin directory inside the repository: `./<path>`, or `.` / `./` for its root. */
115
+ path: string;
116
+ /** Exact semver. */
117
+ version: string;
118
+ /** `sha512-<base64>` of the kernel's canonical pack of the tree. */
119
+ integrity: string;
120
+ required?: boolean;
121
+ builtin?: boolean;
122
+ /** As on {@link BootstrapEntry}: only for an optional preinstall. */
123
+ scope?: "all" | "optional";
124
+ }
125
+ /** An entry of the extra manifest: npm (`required` optional) or git. */
126
+ export type BootstrapExtraEntry = (Omit<Extract<BootstrapEntry, {
127
+ source: "npm";
128
+ }>, "required"> & {
129
+ required?: boolean;
130
+ }) | BootstrapGitEntry;
131
+ /** A marketplace the extra manifest declares for its `git` entries. */
132
+ export interface BootstrapExtraMarketplace {
133
+ /** `^[a-z0-9][a-z0-9-]{0,63}$`, unique, not `official`. */
134
+ name: string;
135
+ /** An https URL without userinfo. */
136
+ url: string;
137
+ ref?: string;
138
+ /** HTTP basic username of the credential (`^[A-Za-z0-9._-]{1,64}$`). */
139
+ username?: string;
140
+ }
141
+ /**
142
+ * The extra bootstrap manifest (`bootstrap-extra.v1`): a second manifest a distribution supplies (the file
143
+ * `bootstrap.extraManifest` points at), merged into the built-in one (spec 2026-11-20-bootstrap-extra-manifest §2). It adds
144
+ * `marketplaces` the entries can name, `git` entries (a plugin directory of such a marketplace at
145
+ * a pinned commit) and an optional `defaultTheme`. `required` is optional here (default `false`).
146
+ * Objects are strict. The committed JSON Schema (`schemas/bootstrap-extra.v1.schema.json`) is
147
+ * generated from {@link BootstrapExtraManifestSchema}; the cross-field rules (unique names, a
148
+ * declared marketplace, `defaultTheme` naming a builtin entry, not both `required` and `builtin`)
149
+ * are decided only by {@link parseBootstrapExtraManifest}.
150
+ */
151
+ export interface BootstrapExtraManifest {
152
+ $schema?: string;
153
+ schemaVersion: 1;
154
+ marketplaces: BootstrapExtraMarketplace[];
155
+ plugins: BootstrapExtraEntry[];
156
+ /** The platform default theme: `plugin` is a builtin entry of this manifest. */
157
+ defaultTheme?: {
158
+ plugin: string;
159
+ theme: string;
160
+ };
161
+ }
162
+ /**
163
+ * The zod schema of the extra manifest (strict objects). The JSON Schema is generated with
164
+ * `z.toJSONSchema(BootstrapExtraManifestSchema, { io: "input" })`.
165
+ */
166
+ export declare const BootstrapExtraManifestSchema: z.ZodType<BootstrapExtraManifest>;
167
+ /**
168
+ * Validates and parses the extra manifest. Invalid input returns `{ errors }` (`<path>: <reason>`,
169
+ * at most 50); never throws.
170
+ */
171
+ export declare function parseBootstrapExtraManifest(json: unknown): {
172
+ manifest: BootstrapExtraManifest;
173
+ } | {
174
+ errors: string[];
175
+ };
package/dist/bootstrap.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
- import { CATALOG_ITEM_NAME_RE, NPM_PACKAGE_NAME_RE, SEMVER_VERSION_RE, SHA512_INTEGRITY_RE, } from "./plugin-package.js";
2
+ import { GIT_USERNAME_RE } from "./git-hosts.js";
3
+ import { CATALOG_ITEM_NAME_RE, isSafePackagePath, NPM_PACKAGE_NAME_RE, SEMVER_VERSION_RE, SHA512_INTEGRITY_RE, } from "./plugin-package.js";
3
4
  /**
4
5
  * The bootstrap manifest `packages/kernel/bootstrap.json` (package ecosystem spec §7): the plugins
5
6
  * a deployment installs at init, each pinned to an exact version and the sha512 of its tgz. The
@@ -10,15 +11,31 @@ import { CATALOG_ITEM_NAME_RE, NPM_PACKAGE_NAME_RE, SEMVER_VERSION_RE, SHA512_IN
10
11
  * the official plugins are published: `path` is packed with `packages/plugin-tools`, which is
11
12
  * byte-reproducible, and `integrity` is that pack's sha512).
12
13
  *
14
+ * `required` and `builtin` are two different promises. A required entry is imported in the first
15
+ * pass, before the extensions load, and the start fails without it (so it can ship no skills or
16
+ * templates: those need object storage, which is not running then). A `builtin` entry is imported
17
+ * once the extensions have loaded (object storage available), so it may ship skills; its failure
18
+ * is logged and retried on the next start. Both give the plugin a builtin catalog item (scope
19
+ * `all`, on in every org, not switchable) and are imported again when missing. An entry is never
20
+ * both.
21
+ *
22
+ * An optional preinstall (neither) may carry `scope: "all"`: its catalog item is then created with
23
+ * scope `all` (on in every org, an org admin may switch it off) instead of `optional` (off until
24
+ * switched on). The scope is read only at the first import; a later change in the manifest never
25
+ * rewrites the item, the super admin owns it after that. `scope` on a required or builtin entry
26
+ * is refused.
27
+ *
13
28
  * Objects are strict (unknown keys rejected, `$schema` allowed): the manifest ships with core, so
14
29
  * there is no older reader to stay compatible with and a misspelt key is a mistake. The committed
15
30
  * JSON Schema (`schemas/bootstrap.v1.schema.json`) is generated from {@link BootstrapManifestSchema}
16
31
  * by `pnpm gen:package-schemas`; the cross-field rules (unique names, `marketplace` required with an
17
- * npm entry) are decided only by {@link parseBootstrapManifest}.
32
+ * npm entry, not both `required` and `builtin`, `scope` only on an optional preinstall) are
33
+ * decided only by {@link parseBootstrapManifest}.
18
34
  */
19
35
  /** Manifest format version. */
20
36
  export const BOOTSTRAP_MANIFEST_SCHEMA_VERSION = 1;
21
37
  const MAX_ERRORS = 50;
38
+ const SCOPE_MESSAGE = "scope applies only to optional preinstalls";
22
39
  const URL_CHARS = 2000;
23
40
  const COMMIT_RE = /^[0-9a-f]{40}$/;
24
41
  const HTTPS_URL_RE = /^https:\/\/\S+$/;
@@ -35,6 +52,8 @@ const common = {
35
52
  .string()
36
53
  .regex(SHA512_INTEGRITY_RE, { message: "integrity must be sha512-<86 base64 chars>==" }),
37
54
  required: z.boolean(),
55
+ builtin: z.boolean().optional(),
56
+ scope: z.enum(["all", "optional"]).optional(),
38
57
  };
39
58
  const entry = z.discriminatedUnion("source", [
40
59
  z.strictObject({
@@ -74,6 +93,20 @@ const schema = z
74
93
  });
75
94
  }
76
95
  seen.add(e.name);
96
+ if (e.required && e.builtin === true) {
97
+ ctx.addIssue({
98
+ code: "custom",
99
+ path: ["plugins", i, "builtin"],
100
+ message: "an entry is either required or builtin, not both",
101
+ });
102
+ }
103
+ if (e.scope !== undefined && (e.required || e.builtin === true)) {
104
+ ctx.addIssue({
105
+ code: "custom",
106
+ path: ["plugins", i, "scope"],
107
+ message: SCOPE_MESSAGE,
108
+ });
109
+ }
77
110
  });
78
111
  if (m.marketplace === undefined && m.plugins.some((e) => e.source === "npm")) {
79
112
  ctx.addIssue({
@@ -107,3 +140,153 @@ export function parseBootstrapManifest(json) {
107
140
  export function bootstrapFileName(e) {
108
141
  return `${e.name}-${e.version}.tgz`;
109
142
  }
143
+ /** Extra manifest format version. */
144
+ export const BOOTSTRAP_EXTRA_MANIFEST_SCHEMA_VERSION = 1;
145
+ const RESERVED_MARKETPLACE_NAME = "official";
146
+ const extraCommon = {
147
+ name: common.name,
148
+ version: common.version,
149
+ integrity: common.integrity,
150
+ required: z.boolean().optional(),
151
+ builtin: common.builtin,
152
+ scope: common.scope,
153
+ };
154
+ const extraEntry = z.discriminatedUnion("source", [
155
+ z.strictObject({
156
+ ...extraCommon,
157
+ source: z.literal("npm"),
158
+ npm: z
159
+ .string()
160
+ .max(214)
161
+ .regex(NPM_PACKAGE_NAME_RE, { message: "npm must be an npm package name" }),
162
+ }),
163
+ z.strictObject({
164
+ ...extraCommon,
165
+ source: z.literal("git"),
166
+ marketplace: common.name,
167
+ commit: z.string().regex(COMMIT_RE, { message: "commit must be 40 hex characters" }),
168
+ path: z
169
+ .string()
170
+ .max(512)
171
+ // "." / "./": the repository root (a single-plugin repository)
172
+ .refine((p) => p === "." || p === "./" || (p.startsWith("./") && isSafePackagePath(p.slice(2))), {
173
+ message: 'path must be "." (the repository root) or start with "./" and stay inside the repository',
174
+ }),
175
+ }),
176
+ ]);
177
+ const extraMarketplace = z.strictObject({
178
+ name: common.name,
179
+ url: z
180
+ .string()
181
+ .max(URL_CHARS)
182
+ .regex(HTTPS_URL_RE, { message: "url must be an https URL" })
183
+ .refine((s) => {
184
+ try {
185
+ const u = new URL(s);
186
+ return u.username === "" && u.password === "";
187
+ }
188
+ catch {
189
+ return false;
190
+ }
191
+ }, { message: "url must be a valid URL without userinfo" }),
192
+ ref: z.string().min(1).max(256).optional(),
193
+ username: z
194
+ .string()
195
+ .regex(GIT_USERNAME_RE, { message: "username must match ^[A-Za-z0-9._-]{1,64}$" })
196
+ .optional(),
197
+ });
198
+ const extraSchema = z
199
+ .strictObject({
200
+ $schema: z.string().max(URL_CHARS).optional(),
201
+ schemaVersion: z.literal(BOOTSTRAP_EXTRA_MANIFEST_SCHEMA_VERSION),
202
+ marketplaces: z.array(extraMarketplace).max(50),
203
+ plugins: z.array(extraEntry).max(500),
204
+ defaultTheme: z
205
+ .strictObject({
206
+ plugin: common.name,
207
+ theme: z.string().min(1).max(256),
208
+ })
209
+ .optional(),
210
+ })
211
+ .superRefine((m, ctx) => {
212
+ const marketplaces = new Set();
213
+ m.marketplaces.forEach((mk, i) => {
214
+ if (mk.name === RESERVED_MARKETPLACE_NAME) {
215
+ ctx.addIssue({
216
+ code: "custom",
217
+ path: ["marketplaces", i, "name"],
218
+ message: `the name ${RESERVED_MARKETPLACE_NAME} is reserved`,
219
+ });
220
+ }
221
+ if (marketplaces.has(mk.name)) {
222
+ ctx.addIssue({
223
+ code: "custom",
224
+ path: ["marketplaces", i, "name"],
225
+ message: `duplicate marketplace ${mk.name}`,
226
+ });
227
+ }
228
+ marketplaces.add(mk.name);
229
+ });
230
+ const seen = new Set();
231
+ m.plugins.forEach((e, i) => {
232
+ if (seen.has(e.name)) {
233
+ ctx.addIssue({
234
+ code: "custom",
235
+ path: ["plugins", i, "name"],
236
+ message: `duplicate entry ${e.name}`,
237
+ });
238
+ }
239
+ seen.add(e.name);
240
+ if (e.required === true && e.builtin === true) {
241
+ ctx.addIssue({
242
+ code: "custom",
243
+ path: ["plugins", i, "builtin"],
244
+ message: "an entry is either required or builtin, not both",
245
+ });
246
+ }
247
+ if (e.scope !== undefined && (e.required === true || e.builtin === true)) {
248
+ ctx.addIssue({
249
+ code: "custom",
250
+ path: ["plugins", i, "scope"],
251
+ message: SCOPE_MESSAGE,
252
+ });
253
+ }
254
+ if (e.source === "git" && !marketplaces.has(e.marketplace)) {
255
+ ctx.addIssue({
256
+ code: "custom",
257
+ path: ["plugins", i, "marketplace"],
258
+ message: `marketplace "${e.marketplace}" is not declared`,
259
+ });
260
+ }
261
+ });
262
+ if (m.defaultTheme !== undefined) {
263
+ const target = m.plugins.find((e) => e.name === m.defaultTheme?.plugin);
264
+ if (target === undefined || target.builtin !== true) {
265
+ ctx.addIssue({
266
+ code: "custom",
267
+ path: ["defaultTheme", "plugin"],
268
+ message: "must name an entry of this manifest with builtin: true",
269
+ });
270
+ }
271
+ }
272
+ });
273
+ /**
274
+ * The zod schema of the extra manifest (strict objects). The JSON Schema is generated with
275
+ * `z.toJSONSchema(BootstrapExtraManifestSchema, { io: "input" })`.
276
+ */
277
+ export const BootstrapExtraManifestSchema = extraSchema;
278
+ /**
279
+ * Validates and parses the extra manifest. Invalid input returns `{ errors }` (`<path>: <reason>`,
280
+ * at most 50); never throws.
281
+ */
282
+ export function parseBootstrapExtraManifest(json) {
283
+ const r = BootstrapExtraManifestSchema.safeParse(json);
284
+ if (r.success)
285
+ return { manifest: r.data };
286
+ return {
287
+ errors: r.error.issues.slice(0, MAX_ERRORS).map((i) => {
288
+ const path = i.path.map(String).join(".");
289
+ return path ? `${path}: ${i.message}` : i.message;
290
+ }),
291
+ };
292
+ }
package/dist/cards.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { type FormAnswer, type InputForm } from "./tool.js";
2
2
  /**
3
- * 渠道中立的 IM 卡片:由内核定义与产出,渠道插件按各自 IM 的原生格式渲染;
4
- * 不支持卡片的渠道用 {@link renderCardAsText} 退回为文本。
3
+ * Channel-neutral IM cards: defined and produced by the kernel, rendered by channel plugins in each
4
+ * IM's native format;
5
+ * channels without card support fall back to text with {@link renderCardAsText}.
5
6
  */
6
7
  export type ChannelCard = {
7
8
  kind: "approval";
@@ -19,20 +20,36 @@ export type ChannelCard = {
19
20
  */
20
21
  inputPreview: string;
21
22
  scopes: ("once" | "session" | "always")[];
23
+ /**
24
+ * The kernel's names for the scopes when they mean something other than the default (a
25
+ * network ask: `once` = "Allow this time", `always` = "Always allow on this device"). Plain
26
+ * text, 1 to 40 characters; a channel that does not know the field renders its default
27
+ * scope labels. Kernel-written, never model-controlled.
28
+ */
29
+ scopeLabels?: Partial<Record<"once" | "session" | "always", string>>;
22
30
  expiresAt: string;
23
- state: "pending" | "approved" | "denied" | "expired" | "cancelled";
31
+ /** `skipped`: the person sent a message instead of deciding (the run went on with it). */
32
+ state: "pending" | "approved" | "denied" | "expired" | "cancelled" | "skipped";
24
33
  decidedBy?: string;
25
34
  /** A denied approval: the reason the person gave (plain text, never formatted). */
26
35
  denyReason?: string;
27
- /** 可决定该审批的会话网页链接。 */
36
+ /** Web link to the conversation that can decide this approval. */
28
37
  webUrl: string;
29
38
  } | {
30
39
  kind: "question";
31
40
  id: string;
32
41
  form: InputForm;
33
- state: "pending" | "answered" | "expired" | "cancelled";
42
+ /** `skipped`: the person sent a message instead of answering (the run went on with it). */
43
+ state: "pending" | "answered" | "skipped" | "expired" | "cancelled";
34
44
  answerSummary?: string;
35
45
  webUrl: string;
46
+ /**
47
+ * The person may answer by replying with text instead (pending cards only): `plain` in a DM
48
+ * (any reply reaches the agent), `mention` in a group thread (the reply must mention the bot;
49
+ * the kernel ignores group messages without it). Absent: only the card's own controls work
50
+ * (a sub-agent's question). Render the hint with {@link questionTextReplyHint}.
51
+ */
52
+ textReply?: "plain" | "mention";
36
53
  } | {
37
54
  kind: "connect";
38
55
  appName: string;
@@ -42,7 +59,10 @@ export type ChannelCard = {
42
59
  url: string;
43
60
  text: string;
44
61
  };
45
- /** 用户在 IM 卡片上的操作,由渠道插件解析后经入站事件交给内核。 */
62
+ /**
63
+ * A user action on an IM card, parsed by the channel plugin and handed to the kernel through an
64
+ * inbound event.
65
+ */
46
66
  export interface CardAction {
47
67
  cardKind: "approval" | "question";
48
68
  cardId: string;
@@ -50,22 +70,49 @@ export interface CardAction {
50
70
  scope?: "once" | "session" | "always";
51
71
  answer?: FormAnswer;
52
72
  }
53
- /** 发往 IM 的一条消息:text 为 Markdown(渠道插件转换为原生富文本),可附卡片。 */
73
+ /**
74
+ * One message sent to an IM: `text` is Markdown (the channel plugin converts it to native rich
75
+ * text); a card may be attached.
76
+ */
54
77
  export interface OutboundMessage {
55
78
  text: string;
56
79
  cards?: ChannelCard[];
57
80
  }
58
81
  /**
59
- * 提问能否在 IM 内直接作答:仅当表单恰有一个枚举字段(单选 ≤ 5 项 / 多选 ≤ 10 项)且不允许「其他」时为真;
60
- * 否则卡片只给网页链接。
82
+ * Whether IM can draw the question's controls: exactly one enum field (single choice ≤ 5 options /
83
+ * multi-select ≤ 10). A field with `allowOther` qualifies only when the card has `textReply`
84
+ * (pass `{ textReply: card.textReply !== undefined }`): the Other path is then a plain reply, so
85
+ * never draw an Other button. Otherwise the card only links to the web.
61
86
  */
62
- export declare function questionRenderableInline(form: InputForm): boolean;
63
- /** 校验卡片结构,返回问题列表(空 = 合法)。 */
87
+ export declare function questionRenderableInline(form: InputForm, opts?: {
88
+ textReply?: boolean;
89
+ }): boolean;
90
+ /** Validates the card structure and returns the list of problems (empty = valid). */
64
91
  export declare function validateChannelCard(card: unknown): string[];
65
92
  /** A UI locale. */
66
93
  export type Locale = "zh" | "en";
67
94
  /**
68
- * 不支持卡片的渠道的统一退回文本(含链接);固定话术按 locale 取 zh / en。结果是 Markdown(放进
69
- * `OutboundMessage.text`,由渠道插件转换):模型可控的字段放在代码里(见 `asCode`),不会产生链接。
95
+ * Puts model-controllable values (approval title, call summary, question title, answer summary)
96
+ * into code, so that in the fallback text they do not turn into links, emphasis or HTML:
97
+ * single-line values use inline code, multi-line values a fenced code block (starting with a
98
+ * newline); the delimiters are always longer than the longest backtick run in the value (CommonMark
99
+ * 6.1 / 4.5).
100
+ * Code is chosen over backslash-escaping punctuation because code is the only form CommonMark / GFM
101
+ * guarantee to display content verbatim (a backslash does not stop GFM bare-URL
102
+ * autolinks, and channel converters treat backslashes inconsistently).
103
+ */
104
+ export declare function asCode(s: string): string;
105
+ /** The hint line of a pending question card with `textReply`, as {@link renderCardAsText} writes it. */
106
+ export declare function questionTextReplyHint(mode: "plain" | "mention", locale: Locale): string;
107
+ /**
108
+ * The label of a question card's state, as {@link renderCardAsText} writes it. A state this SDK
109
+ * does not know (a newer kernel) returns the state itself, never `undefined`.
110
+ */
111
+ export declare function questionStateLabel(state: string, locale: Locale): string;
112
+ /**
113
+ * The uniform fallback text for channels without card support (links included); the fixed phrases
114
+ * are taken by locale, zh / en. The result is Markdown (put into
115
+ * `OutboundMessage.text`, converted by the channel plugin): model-controllable fields go into code
116
+ * (see `asCode`), so they never produce links.
70
117
  */
71
118
  export declare function renderCardAsText(card: ChannelCard, locale: Locale): string;