@capybara-hq/plugin-sdk 0.1.0-rc.6 → 0.1.0-rc.60

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 (136) 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 +7 -1
  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 +29 -3
  13. package/agent-docs/plugin-format.md +52 -2
  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 +67 -13
  22. package/dist/cards.js +91 -21
  23. package/dist/channel.d.ts +148 -48
  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 +22 -0
  30. package/dist/config-ui.js +64 -4
  31. package/dist/connector-auth.d.ts +15 -2
  32. package/dist/connector-auth.js +97 -8
  33. package/dist/connector.d.ts +74 -32
  34. package/dist/context.d.ts +40 -0
  35. package/dist/context.js +2 -0
  36. package/dist/ctx.d.ts +132 -29
  37. package/dist/define-extension.d.ts +26 -12
  38. package/dist/define-extension.js +12 -5
  39. package/dist/device-denied-paths.d.ts +18 -0
  40. package/dist/device-denied-paths.js +84 -0
  41. package/dist/device-operation.d.ts +333 -0
  42. package/dist/device-operation.js +312 -0
  43. package/dist/device-protocol.d.ts +285 -50
  44. package/dist/device-protocol.js +755 -90
  45. package/dist/device-provider.d.ts +500 -0
  46. package/dist/device-provider.js +302 -0
  47. package/dist/dial-in.d.ts +176 -0
  48. package/dist/dial-in.js +115 -0
  49. package/dist/extension-point.d.ts +2 -0
  50. package/dist/extension-point.js +6 -2
  51. package/dist/file-preview.d.ts +23 -6
  52. package/dist/git-hosts.d.ts +53 -0
  53. package/dist/git-hosts.js +98 -0
  54. package/dist/hooks.d.ts +125 -20
  55. package/dist/hooks.js +5 -0
  56. package/dist/http-access.d.ts +62 -0
  57. package/dist/http-access.js +12 -0
  58. package/dist/identity.d.ts +38 -9
  59. package/dist/identity.js +21 -1
  60. package/dist/index.d.ts +29 -3
  61. package/dist/index.js +29 -3
  62. package/dist/marketplace.d.ts +26 -0
  63. package/dist/marketplace.js +43 -1
  64. package/dist/model-params.d.ts +41 -22
  65. package/dist/model-params.js +28 -15
  66. package/dist/model.d.ts +206 -71
  67. package/dist/model.js +152 -19
  68. package/dist/net.d.ts +52 -0
  69. package/dist/net.js +34 -0
  70. package/dist/network-classes.d.ts +98 -0
  71. package/dist/network-classes.js +291 -0
  72. package/dist/permissions.d.ts +54 -22
  73. package/dist/permissions.js +119 -43
  74. package/dist/plugin-manifest.d.ts +45 -5
  75. package/dist/plugin-manifest.js +174 -6
  76. package/dist/plugin-package.d.ts +82 -38
  77. package/dist/plugin-package.js +61 -29
  78. package/dist/push.d.ts +75 -0
  79. package/dist/push.js +87 -0
  80. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  81. package/dist/sandbox-linux-runtime-source.js +2318 -0
  82. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  83. package/dist/sandbox-native-runtime-source.js +476 -0
  84. package/dist/sandbox-runtime-source.d.ts +19 -0
  85. package/dist/sandbox-runtime-source.js +28 -0
  86. package/dist/sandbox-write-denies.d.ts +139 -0
  87. package/dist/sandbox-write-denies.js +869 -0
  88. package/dist/secret.d.ts +4 -1
  89. package/dist/secret.js +4 -1
  90. package/dist/setup-check.d.ts +128 -0
  91. package/dist/setup-check.js +142 -0
  92. package/dist/setup-guide-parse.d.ts +121 -0
  93. package/dist/setup-guide-parse.js +356 -0
  94. package/dist/setup-guide-render.d.ts +45 -0
  95. package/dist/setup-guide-render.js +351 -0
  96. package/dist/setup-guide.d.ts +108 -0
  97. package/dist/setup-guide.js +367 -0
  98. package/dist/shell-capabilities.d.ts +211 -0
  99. package/dist/shell-capabilities.js +44 -0
  100. package/dist/shell-environment.d.ts +57 -0
  101. package/dist/shell-environment.js +21 -0
  102. package/dist/skill.d.ts +27 -17
  103. package/dist/skill.js +40 -26
  104. package/dist/storage.d.ts +52 -25
  105. package/dist/svg-viewbox.d.ts +10 -0
  106. package/dist/svg-viewbox.js +24 -0
  107. package/dist/theme-assets.d.ts +55 -0
  108. package/dist/theme-assets.js +489 -0
  109. package/dist/theme-readability.d.ts +37 -0
  110. package/dist/theme-readability.js +145 -0
  111. package/dist/theme-tokens.generated.d.ts +299 -0
  112. package/dist/theme-tokens.generated.js +184 -0
  113. package/dist/theme.d.ts +190 -0
  114. package/dist/theme.js +471 -0
  115. package/dist/tool.d.ts +99 -26
  116. package/dist/tool.js +29 -9
  117. package/dist/ui-parts.d.ts +23 -0
  118. package/dist/ui-parts.js +385 -0
  119. package/dist/ui-resolve.d.ts +35 -0
  120. package/dist/ui-resolve.js +42 -0
  121. package/dist/ui-slots.d.ts +65 -0
  122. package/dist/ui-slots.js +261 -0
  123. package/dist/ui.d.ts +212 -76
  124. package/dist/ui.js +101 -27
  125. package/dist/url.d.ts +4 -1
  126. package/dist/url.js +4 -1
  127. package/package.json +13 -1
  128. package/schemas/bootstrap-extra.v1.schema.json +186 -0
  129. package/schemas/bootstrap.v1.schema.json +20 -0
  130. package/schemas/connector-template.v1.schema.json +35 -0
  131. package/schemas/marketplace.v1.schema.json +14 -0
  132. package/schemas/plugin.v1.schema.json +122 -3
  133. package/schemas/theme.v1.schema.json +302 -0
  134. package/agent-docs/extension-points/sandbox.md +0 -15
  135. package/dist/sandbox.d.ts +0 -254
  136. package/dist/sandbox.js +0 -153
package/dist/index.d.ts CHANGED
@@ -1,32 +1,58 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.6";
1
+ export declare const SDK_VERSION = "0.1.0-rc.60";
2
2
  export * from "./agent-template.js";
3
+ export * from "./avatar-presets.js";
3
4
  export * from "./bootstrap.js";
4
5
  export * from "./cards.js";
5
6
  export * from "./channel.js";
7
+ export * from "./client-css.js";
8
+ export * from "./client-section.js";
6
9
  export * from "./config-ui.js";
7
10
  export * from "./connector.js";
8
11
  export * from "./connector-auth.js";
12
+ export * from "./context.js";
9
13
  export * from "./ctx.js";
10
14
  export * from "./define-extension.js";
11
- export * from "./device-protocol.js";
15
+ export { DEVICE_DEFAULT_STATE_PATH, DEVICE_DENIED_SECRET_PATHS } from "./device-denied-paths.js";
16
+ export * from "./device-operation.js";
17
+ export * from "./device-provider.js";
18
+ export * from "./dial-in.js";
12
19
  export * from "./directory.js";
13
20
  export * from "./extension-point.js";
14
21
  export * from "./file-preview.js";
22
+ export * from "./git-hosts.js";
15
23
  export * from "./hooks.js";
24
+ export * from "./http-access.js";
16
25
  export * from "./identity.js";
17
26
  export * from "./marketplace.js";
18
27
  export * from "./model.js";
19
28
  export * from "./model-params.js";
29
+ export * from "./net.js";
30
+ export * from "./network-classes.js";
20
31
  export * from "./org-access.js";
21
32
  export * from "./permissions.js";
22
33
  export * from "./plugin-manifest.js";
23
34
  export * from "./plugin-package.js";
24
- export * from "./sandbox.js";
35
+ export * from "./push.js";
36
+ export { SANDBOX_RUNTIME_SOURCE } from "./sandbox-runtime-source.js";
37
+ export { isSandboxHomeWriteDenied, isSandboxMoveDenied, isSandboxWriteDenied, SANDBOX_GIT_ALLOWED_DIRECTORIES, SANDBOX_GIT_ALLOWED_FILES, SANDBOX_GIT_DENIED_INTERNALS, SANDBOX_HOME_WRITE_DENIES, SANDBOX_MANDATORY_WRITE_DENIES, SANDBOX_PROTECTED_PATH_NAMES, SANDBOX_RESERVED_NAME_PREFIX, SANDBOX_RUNTIME_DIRECTORIES, SANDBOX_SYSTEM_WRITE_DENIES, sandboxRuntimeDirectoryOf, } from "./sandbox-write-denies.js";
25
38
  export * from "./secret.js";
39
+ export * from "./setup-check.js";
40
+ export * from "./setup-guide.js";
41
+ export { type ParsedSetupGuide, parseSetupGuide, type SetupGuideCheckLine, type SetupGuideCodeBlock, type SetupGuideParseIssue, type SetupGuideSection, } from "./setup-guide-parse.js";
42
+ export * from "./setup-guide-render.js";
43
+ export * from "./shell-capabilities.js";
44
+ export * from "./shell-environment.js";
26
45
  export * from "./skill.js";
27
46
  export * from "./skill-invocation.js";
28
47
  export * from "./storage.js";
48
+ export * from "./theme.js";
49
+ export * from "./theme-assets.js";
50
+ export * from "./theme-readability.js";
51
+ export * from "./theme-tokens.generated.js";
29
52
  export * from "./tool.js";
30
53
  export * from "./tool-key.js";
31
54
  export * from "./ui.js";
55
+ export * from "./ui-parts.js";
56
+ export * from "./ui-resolve.js";
57
+ export * from "./ui-slots.js";
32
58
  export * from "./web.js";
package/dist/index.js CHANGED
@@ -1,32 +1,58 @@
1
- export const SDK_VERSION = "0.1.0-rc.6";
1
+ export const SDK_VERSION = "0.1.0-rc.60";
2
2
  export * from "./agent-template.js";
3
+ export * from "./avatar-presets.js";
3
4
  export * from "./bootstrap.js";
4
5
  export * from "./cards.js";
5
6
  export * from "./channel.js";
7
+ export * from "./client-css.js";
8
+ export * from "./client-section.js";
6
9
  export * from "./config-ui.js";
7
10
  export * from "./connector.js";
8
11
  export * from "./connector-auth.js";
12
+ export * from "./context.js";
9
13
  export * from "./ctx.js";
10
14
  export * from "./define-extension.js";
11
- export * from "./device-protocol.js";
15
+ export { DEVICE_DEFAULT_STATE_PATH, DEVICE_DENIED_SECRET_PATHS } from "./device-denied-paths.js";
16
+ export * from "./device-operation.js";
17
+ export * from "./device-provider.js";
18
+ export * from "./dial-in.js";
12
19
  export * from "./directory.js";
13
20
  export * from "./extension-point.js";
14
21
  export * from "./file-preview.js";
22
+ export * from "./git-hosts.js";
15
23
  export * from "./hooks.js";
24
+ export * from "./http-access.js";
16
25
  export * from "./identity.js";
17
26
  export * from "./marketplace.js";
18
27
  export * from "./model.js";
19
28
  export * from "./model-params.js";
29
+ export * from "./net.js";
30
+ export * from "./network-classes.js";
20
31
  export * from "./org-access.js";
21
32
  export * from "./permissions.js";
22
33
  export * from "./plugin-manifest.js";
23
34
  export * from "./plugin-package.js";
24
- export * from "./sandbox.js";
35
+ export * from "./push.js";
36
+ export { SANDBOX_RUNTIME_SOURCE } from "./sandbox-runtime-source.js";
37
+ export { isSandboxHomeWriteDenied, isSandboxMoveDenied, isSandboxWriteDenied, SANDBOX_GIT_ALLOWED_DIRECTORIES, SANDBOX_GIT_ALLOWED_FILES, SANDBOX_GIT_DENIED_INTERNALS, SANDBOX_HOME_WRITE_DENIES, SANDBOX_MANDATORY_WRITE_DENIES, SANDBOX_PROTECTED_PATH_NAMES, SANDBOX_RESERVED_NAME_PREFIX, SANDBOX_RUNTIME_DIRECTORIES, SANDBOX_SYSTEM_WRITE_DENIES, sandboxRuntimeDirectoryOf, } from "./sandbox-write-denies.js";
25
38
  export * from "./secret.js";
39
+ export * from "./setup-check.js";
40
+ export * from "./setup-guide.js";
41
+ export { parseSetupGuide, } from "./setup-guide-parse.js";
42
+ export * from "./setup-guide-render.js";
43
+ export * from "./shell-capabilities.js";
44
+ export * from "./shell-environment.js";
26
45
  export * from "./skill.js";
27
46
  export * from "./skill-invocation.js";
28
47
  export * from "./storage.js";
48
+ export * from "./theme.js";
49
+ export * from "./theme-assets.js";
50
+ export * from "./theme-readability.js";
51
+ export * from "./theme-tokens.generated.js";
29
52
  export * from "./tool.js";
30
53
  export * from "./tool-key.js";
31
54
  export * from "./ui.js";
55
+ export * from "./ui-parts.js";
56
+ export * from "./ui-resolve.js";
57
+ export * from "./ui-slots.js";
32
58
  export * from "./web.js";
@@ -28,6 +28,8 @@ export declare const MARKETPLACE_LIMITS: {
28
28
  readonly plugins: 5000;
29
29
  readonly permissionKeys: 500;
30
30
  readonly urlChars: 2000;
31
+ /** Bytes of an entry icon (the plugin icon limit, {@link CONNECTOR_TEMPLATE_LIMITS}). */
32
+ readonly iconBytes: number;
31
33
  };
32
34
  /** Where a marketplace entry's plugin comes from. */
33
35
  export type MarketplaceSource = {
@@ -75,6 +77,18 @@ export interface MarketplaceEntry {
75
77
  };
76
78
  /** https URL. */
77
79
  homepage?: string;
80
+ /**
81
+ * The plugin's icon for marketplace lists, before the plugin is imported (display only; an
82
+ * imported plugin shows its own icon). Either an absolute `https://` URL whose path ends in
83
+ * `.svg` / `.png`, or `./<path>.svg|png` inside the marketplace's repository, read at the commit
84
+ * the marketplace was refreshed at (git marketplaces only; ignored in a marketplace fetched over
85
+ * http). The kernel downloads it on refresh (network rules of the marketplace downloads, never
86
+ * with the marketplace token), keeps it when it really is an svg / png of at most
87
+ * {@link MARKETPLACE_LIMITS}`.iconBytes`, and treats a URL's content as fixed: a new icon needs a
88
+ * new URL. A missing or invalid icon never fails the refresh. `capybara-plugin marketplace
89
+ * --write` fills it with the repository path of the plugin's `plugin.json` `icon`.
90
+ */
91
+ icon?: string;
78
92
  /**
79
93
  * This version is deprecated (`true`, or with a reason shown to admins): browsing lists it under
80
94
  * the plugin's other versions, never as the one to import, and the kernel refuses importing it
@@ -103,6 +117,8 @@ export interface MarketplaceParseOptions {
103
117
  /** Tests only: allow http on loopback addresses for `git` / `archive` URLs. */
104
118
  allowInsecureLoopback?: boolean;
105
119
  }
120
+ /** An entry icon's file extension (of the URL's path, or of the repository path). */
121
+ export declare const MARKETPLACE_ICON_RE: RegExp;
106
122
  /**
107
123
  * The zod schema of `marketplace.json` (https only; non-strict: unknown fields dropped). The JSON
108
124
  * Schema is generated with `z.toJSONSchema(MarketplaceManifestSchema, { io: "input" })`.
@@ -117,6 +133,16 @@ export declare function parseMarketplaceManifest(json: unknown, opts?: Marketpla
117
133
  };
118
134
  /** The entry's version: `version`, else the npm source's version, else `null` (the plugin's own). */
119
135
  export declare function marketplaceEntryVersion(e: MarketplaceEntry): string | null;
136
+ /**
137
+ * The entry's icon (see {@link MarketplaceEntry.icon}): `{ url }` for an absolute URL, `{ path }`
138
+ * (normalized, without the leading `./`) for a path inside the marketplace's repository, `null`
139
+ * without one.
140
+ */
141
+ export declare function marketplaceEntryIcon(e: Pick<MarketplaceEntry, "icon">): {
142
+ url: string;
143
+ } | {
144
+ path: string;
145
+ } | null;
120
146
  /**
121
147
  * The entry's deprecation (see {@link MarketplaceEntry.deprecated}): `null` when it is not
122
148
  * deprecated (absent or `false`), else its reason (`null` without one).
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { CATALOG_ITEM_NAME_RE, isSafePackagePath, NPM_PACKAGE_NAME_RE, SEMVER_VERSION_RE, SHA512_INTEGRITY_RE, } from "./plugin-package.js";
2
+ import { CATALOG_ITEM_NAME_RE, CONNECTOR_TEMPLATE_LIMITS, isSafePackagePath, NPM_PACKAGE_NAME_RE, SEMVER_VERSION_RE, SHA512_INTEGRITY_RE, } from "./plugin-package.js";
3
3
  /**
4
4
  * The marketplace manifest `marketplace.json` (package ecosystem spec §5.2): a list of plugins,
5
5
  * each with one source. One entry is one version. `capybara-plugin marketplace --write` lists one
@@ -29,6 +29,8 @@ export const MARKETPLACE_LIMITS = {
29
29
  plugins: 5000,
30
30
  permissionKeys: 500,
31
31
  urlChars: 2000,
32
+ /** Bytes of an entry icon (the plugin icon limit, {@link CONNECTOR_TEMPLATE_LIMITS}). */
33
+ iconBytes: CONNECTOR_TEMPLATE_LIMITS.iconBytes,
32
34
  };
33
35
  const M = MARKETPLACE_LIMITS;
34
36
  const MAX_ERRORS = 50;
@@ -37,6 +39,13 @@ const PERMISSION_KEY_RE = /^[a-z][a-z.]{0,62}(?::[^\r\n]{1,256})?$/;
37
39
  const SHA256_INTEGRITY_RE = /^sha256-[A-Za-z0-9+/]{43}=$/;
38
40
  const COMMIT_RE = /^[0-9a-f]{40}$/;
39
41
  const HTTPS_URL_RE = /^https:\/\/\S+$/;
42
+ /** An entry icon's file extension (of the URL's path, or of the repository path). */
43
+ export const MARKETPLACE_ICON_RE = /\.(?:svg|png)$/i;
44
+ // Spelled without the `i` flag so the generated JSON Schema keeps the rule
45
+ const ICON_EXT = "\\.(?:[sS][vV][gG]|[pP][nN][gG])";
46
+ const ICON_URL_RE = new RegExp(`^https://[^\\s?#]+${ICON_EXT}(?:\\?[^\\s#]*)?$`);
47
+ const ICON_URL_OR_LOOPBACK_RE = new RegExp(`^(?:https://[^\\s?#]+|http://(?:127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|localhost|\\[::1\\])(?::\\d{1,5})?/[^\\s?#]*)${ICON_EXT}(?:\\?[^\\s#]*)?$`);
48
+ const ICON_PATH_RE = new RegExp(`^\\./[^\\s?#]+${ICON_EXT}$`);
40
49
  const HTTPS_OR_LOOPBACK_RE = /^(?:https:\/\/\S+|http:\/\/(?:127\.\d{1,3}\.\d{1,3}\.\d{1,3}|localhost|\[::1\])(?::\d{1,5})?(?:\/\S*)?)$/;
41
50
  const urlString = (re) => z
42
51
  .string()
@@ -55,6 +64,15 @@ const exactVersion = (what) => z
55
64
  .string()
56
65
  .max(256)
57
66
  .regex(SEMVER_VERSION_RE, { message: `${what} must be an exact semver version` });
67
+ /** The path of a URL (empty when it does not parse). */
68
+ const urlPathname = (s) => {
69
+ try {
70
+ return new URL(s).pathname;
71
+ }
72
+ catch {
73
+ return "";
74
+ }
75
+ };
58
76
  /** `./<safe path>` inside the marketplace repo. */
59
77
  const repoPath = z
60
78
  .string()
@@ -144,6 +162,12 @@ function buildSchema(opts) {
144
162
  })
145
163
  .optional(),
146
164
  homepage: urlString(HTTPS_URL_RE).optional(),
165
+ icon: z
166
+ .union([
167
+ urlString(opts.allowInsecureLoopback ? ICON_URL_OR_LOOPBACK_RE : ICON_URL_RE).refine((s) => MARKETPLACE_ICON_RE.test(urlPathname(s)), { message: "an icon URL's path must end in .svg or .png" }),
168
+ repoPath.regex(ICON_PATH_RE, { message: "icon must be a .svg or .png file" }),
169
+ ])
170
+ .optional(),
147
171
  deprecated: z
148
172
  .union([
149
173
  z.boolean(),
@@ -248,6 +272,14 @@ const SOURCE_FORMS = ["path", "git", "npm", "archive"];
248
272
  * form the source uses instead, or that it must use exactly one form.
249
273
  */
250
274
  function explainSource(json, issue) {
275
+ if (issue.code === "invalid_union" && issue.path[issue.path.length - 1] === "icon") {
276
+ return [
277
+ {
278
+ path: issue.path,
279
+ message: 'icon must be an https URL whose path ends in .svg or .png, or a "./" path inside the repository ending in .svg or .png',
280
+ },
281
+ ];
282
+ }
251
283
  if (issue.code !== "invalid_union" || issue.path[issue.path.length - 1] !== "source") {
252
284
  return [issue];
253
285
  }
@@ -272,6 +304,16 @@ export function marketplaceEntryVersion(e) {
272
304
  return e.source.npm.version;
273
305
  return null;
274
306
  }
307
+ /**
308
+ * The entry's icon (see {@link MarketplaceEntry.icon}): `{ url }` for an absolute URL, `{ path }`
309
+ * (normalized, without the leading `./`) for a path inside the marketplace's repository, `null`
310
+ * without one.
311
+ */
312
+ export function marketplaceEntryIcon(e) {
313
+ if (e.icon === undefined)
314
+ return null;
315
+ return e.icon.startsWith("./") ? { path: e.icon.slice(2) } : { url: e.icon };
316
+ }
275
317
  /**
276
318
  * The entry's deprecation (see {@link MarketplaceEntry.deprecated}): `null` when it is not
277
319
  * deprecated (absent or `false`), else its reason (`null` without one).
@@ -1,22 +1,29 @@
1
1
  /**
2
- * `model-provider@2` 的参数声明与校验(纯函数;issue / 错误信息用英文,供日志与 API 返回)。
3
- * 每个模型在 `ModelInfo.parameters` 中声明自己支持的参数,取值约束是受限的 JSON Schema 子集。
2
+ * Parameter declarations and validation for `model-provider@2` (pure functions; issues / error
3
+ * messages are in English, for logs and API responses).
4
+ * Each model declares in `ModelInfo.parameters` the parameters it supports; value constraints are a
5
+ * restricted JSON Schema subset.
4
6
  */
5
7
  export type Effort = "low" | "medium" | "high" | "xhigh" | "max";
6
8
  /**
7
- * 标准旋钮:平台统一语义,界面专门渲染,换模型或兜底时语义可迁移;插件负责映射到原生参数。
8
- * - `effort`:思考深度,`{ type: "string", enum }`,取值是 `low|medium|high|xhigh|max` 的子集;
9
- * - `thinking`:思考模式,`{ type: "string", enum }`,取值是 `off|on|summarized` 的子集;
10
- * - `temperature`:`{ type: "number" }`(可带范围);
11
- * - `maxOutputTokens`:最大输出 token,`{ type: "integer" }`(可带范围)。
9
+ * Standard knobs: uniform platform semantics, rendered specially by the UI, with semantics that
10
+ * carry over when switching models or falling back; the plugin maps them to native parameters.
11
+ * - `effort`: thinking depth, `{ type: "string", enum }`, values a subset of
12
+ * `low|medium|high|xhigh|max`;
13
+ * - `thinking`: thinking mode, `{ type: "string", enum }`, values a subset of `off|on|summarized`;
14
+ * - `temperature`: `{ type: "number" }` (may carry a range);
15
+ * - `maxOutputTokens`: maximum output tokens, `{ type: "integer" }` (may carry a range).
12
16
  */
13
17
  export type StandardKnob = "effort" | "thinking" | "temperature" | "maxOutputTokens";
14
18
  export declare const STANDARD_KNOBS: readonly StandardKnob[];
15
- /** `effort` 旋钮允许的取值全集。 */
19
+ /** The full set of values the `effort` knob allows. */
16
20
  export declare const EFFORT_VALUES: readonly Effort[];
17
- /** `thinking` 旋钮允许的取值全集。 */
21
+ /** The full set of values the `thinking` knob allows. */
18
22
  export declare const THINKING_VALUES: readonly string[];
19
- /** 参数取值约束:受限的 JSON Schema 子集(可序列化后交给界面;内核自行校验,不依赖 ajv)。 */
23
+ /**
24
+ * Parameter value constraints: a restricted JSON Schema subset (serializable for the UI; the kernel
25
+ * validates it itself, without ajv).
26
+ */
20
27
  export type ParamSchema = {
21
28
  type: "string";
22
29
  enum: string[];
@@ -31,14 +38,20 @@ export type ParamSchema = {
31
38
  maximum?: number;
32
39
  };
33
40
  export type ParamValue = string | number | boolean;
34
- /** 模型声明的一个参数。 */
41
+ /** One parameter a model declares. */
35
42
  export interface ModelParameter {
36
- /** 标准旋钮名(见 {@link StandardKnob}),或厂商专有参数 `"<插件名>.<名称>"`。 */
43
+ /**
44
+ * A standard knob name (see {@link StandardKnob}), or a vendor-specific parameter `"<plugin
45
+ * name>.<name>"`.
46
+ */
37
47
  key: string;
38
- /** key 为标准旋钮时必填且必须等于 key;厂商专有参数不得填写。 */
48
+ /**
49
+ * Required when key is a standard knob and must equal key; vendor-specific parameters must not
50
+ * set it.
51
+ */
39
52
  standard?: StandardKnob;
40
53
  schema: ParamSchema;
41
- /** 未设置时使用的值;必须满足 schema。 */
54
+ /** The value used when unset; must satisfy the schema. */
42
55
  default?: ParamValue;
43
56
  label: {
44
57
  zh: string;
@@ -53,11 +66,13 @@ export interface ParamIssue {
53
66
  key: string;
54
67
  message: string;
55
68
  }
56
- /** 值不满足 schema 时返回英文原因,满足时返回 undefined。 */
69
+ /** Returns an English reason when the value does not satisfy the schema, undefined when it does. */
57
70
  export declare function checkParamValue(schema: ParamSchema, v: unknown): string | undefined;
58
71
  /**
59
- * 严格校验(保存 agent 时用):未知键、类型不符、枚举越界、超出范围都算错,逐键报告。
60
- * 成功时 `value` 为传入的参数,不补默认值;值为 undefined 的键视为未设置。
72
+ * Strict validation (used when saving an agent): unknown keys, type mismatches, enum violations and
73
+ * out-of-range values are all errors, reported per key.
74
+ * On success `value` is the input parameters, with no defaults filled in; a key whose value is
75
+ * undefined counts as unset.
61
76
  */
62
77
  export declare function validateParams(decl: ModelParameter[], params: Record<string, unknown>): {
63
78
  ok: true;
@@ -67,16 +82,20 @@ export declare function validateParams(decl: ModelParameter[], params: Record<st
67
82
  issues: ParamIssue[];
68
83
  };
69
84
  /**
70
- * 宽松版(运行时用):丢弃未知或不合法的项(键记入 `dropped`),再为未设置的已声明参数补默认值。
71
- * 用于插件升级后已保存的参数不再合法的情况,不让整轮运行失败。
85
+ * The lenient variant (used at runtime): drops unknown or invalid entries (their keys go into
86
+ * `dropped`), then fills defaults for declared parameters that are unset.
87
+ * For the case where saved parameters are no longer valid after a plugin upgrade, so that the whole
88
+ * run does not fail.
72
89
  */
73
90
  export declare function sanitizeParams(decl: ModelParameter[], params: Record<string, unknown>): {
74
91
  value: Record<string, ParamValue>;
75
92
  dropped: string[];
76
93
  };
77
94
  /**
78
- * 校验插件为一个模型声明的参数:键名是标准旋钮或 `<plugin>.<名称>`、`standard` 与键一致、
79
- * schema 属于受支持的子集、标准旋钮符合取值约定、默认值满足 schema、文案齐全、键不重复。
80
- * 有问题时抛错,信息点名插件与各个键(英文)。
95
+ * Validates the parameters a plugin declares for a model: the key is a standard knob or
96
+ * `<plugin>.<name>`, `standard` agrees with the key,
97
+ * the schema belongs to the supported subset, standard knobs satisfy the value conventions,
98
+ * defaults satisfy the schema, copy is complete, keys do not repeat.
99
+ * Throws when there is a problem, with a message naming the plugin and each key (in English).
81
100
  */
82
101
  export declare function assertValidDeclarations(plugin: string, decl: ModelParameter[]): void;
@@ -1,6 +1,8 @@
1
1
  /**
2
- * `model-provider@2` 的参数声明与校验(纯函数;issue / 错误信息用英文,供日志与 API 返回)。
3
- * 每个模型在 `ModelInfo.parameters` 中声明自己支持的参数,取值约束是受限的 JSON Schema 子集。
2
+ * Parameter declarations and validation for `model-provider@2` (pure functions; issues / error
3
+ * messages are in English, for logs and API responses).
4
+ * Each model declares in `ModelInfo.parameters` the parameters it supports; value constraints are a
5
+ * restricted JSON Schema subset.
4
6
  */
5
7
  export const STANDARD_KNOBS = [
6
8
  "effort",
@@ -8,13 +10,13 @@ export const STANDARD_KNOBS = [
8
10
  "temperature",
9
11
  "maxOutputTokens",
10
12
  ];
11
- /** `effort` 旋钮允许的取值全集。 */
13
+ /** The full set of values the `effort` knob allows. */
12
14
  export const EFFORT_VALUES = ["low", "medium", "high", "xhigh", "max"];
13
- /** `thinking` 旋钮允许的取值全集。 */
15
+ /** The full set of values the `thinking` knob allows. */
14
16
  export const THINKING_VALUES = ["off", "on", "summarized"];
15
17
  const isStandardKnob = (k) => STANDARD_KNOBS.includes(k);
16
18
  const VENDOR_NAME = /^[A-Za-z][A-Za-z0-9_-]*$/;
17
- /** 值不满足 schema 时返回英文原因,满足时返回 undefined。 */
19
+ /** Returns an English reason when the value does not satisfy the schema, undefined when it does. */
18
20
  export function checkParamValue(schema, v) {
19
21
  switch (schema.type) {
20
22
  case "boolean":
@@ -45,11 +47,16 @@ export function checkParamValue(schema, v) {
45
47
  return `has unsupported schema type ${JSON.stringify(schema.type)}`;
46
48
  }
47
49
  }
48
- /** 按键查声明(用 Map,避免 `constructor` 等原型属性被当成已声明的键)。 */
50
+ /**
51
+ * Looks up a declaration by key (uses a Map so that prototype properties such as `constructor` are
52
+ * not mistaken for declared keys).
53
+ */
49
54
  const declMap = (decl) => new Map(decl.map((d) => [d.key, d]));
50
55
  /**
51
- * 严格校验(保存 agent 时用):未知键、类型不符、枚举越界、超出范围都算错,逐键报告。
52
- * 成功时 `value` 为传入的参数,不补默认值;值为 undefined 的键视为未设置。
56
+ * Strict validation (used when saving an agent): unknown keys, type mismatches, enum violations and
57
+ * out-of-range values are all errors, reported per key.
58
+ * On success `value` is the input parameters, with no defaults filled in; a key whose value is
59
+ * undefined counts as unset.
53
60
  */
54
61
  export function validateParams(decl, params) {
55
62
  const byKey = declMap(decl);
@@ -72,8 +79,10 @@ export function validateParams(decl, params) {
72
79
  return issues.length > 0 ? { ok: false, issues } : { ok: true, value };
73
80
  }
74
81
  /**
75
- * 宽松版(运行时用):丢弃未知或不合法的项(键记入 `dropped`),再为未设置的已声明参数补默认值。
76
- * 用于插件升级后已保存的参数不再合法的情况,不让整轮运行失败。
82
+ * The lenient variant (used at runtime): drops unknown or invalid entries (their keys go into
83
+ * `dropped`), then fills defaults for declared parameters that are unset.
84
+ * For the case where saved parameters are no longer valid after a plugin upgrade, so that the whole
85
+ * run does not fail.
77
86
  */
78
87
  export function sanitizeParams(decl, params) {
79
88
  const byKey = declMap(decl);
@@ -143,7 +152,9 @@ function schemaProblems(schema) {
143
152
  return [`unsupported schema type ${JSON.stringify(s.type)}`];
144
153
  }
145
154
  }
146
- /** 标准旋钮的取值约定(schema 本身已合法时才检查)。 */
155
+ /**
156
+ * The value conventions of standard knobs (checked only when the schema itself is already valid).
157
+ */
147
158
  function knobProblems(key, schema) {
148
159
  const values = schema.type === "string" && "enum" in schema ? schema.enum : undefined;
149
160
  switch (key) {
@@ -178,7 +189,7 @@ function textProblems(d) {
178
189
  }
179
190
  return out;
180
191
  }
181
- /** 一个参数声明的全部问题;无问题返回空数组。 */
192
+ /** All problems of one parameter declaration; an empty array when there are none. */
182
193
  function declarationProblems(plugin, d) {
183
194
  if (typeof d !== "object" || d === null)
184
195
  return ["declaration must be an object"];
@@ -198,9 +209,11 @@ function declarationProblems(plugin, d) {
198
209
  return out;
199
210
  }
200
211
  /**
201
- * 校验插件为一个模型声明的参数:键名是标准旋钮或 `<plugin>.<名称>`、`standard` 与键一致、
202
- * schema 属于受支持的子集、标准旋钮符合取值约定、默认值满足 schema、文案齐全、键不重复。
203
- * 有问题时抛错,信息点名插件与各个键(英文)。
212
+ * Validates the parameters a plugin declares for a model: the key is a standard knob or
213
+ * `<plugin>.<name>`, `standard` agrees with the key,
214
+ * the schema belongs to the supported subset, standard knobs satisfy the value conventions,
215
+ * defaults satisfy the schema, copy is complete, keys do not repeat.
216
+ * Throws when there is a problem, with a message naming the plugin and each key (in English).
204
217
  */
205
218
  export function assertValidDeclarations(plugin, decl) {
206
219
  if (!Array.isArray(decl)) {