@capybara-hq/plugin-sdk 0.1.0-rc.4 → 0.1.0-rc.40
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.
- package/agent-docs/agent-templates.md +15 -3
- package/agent-docs/concepts.md +13 -3
- package/agent-docs/connector-templates.md +2 -1
- package/agent-docs/extension-points/channel.md +2 -2
- package/agent-docs/extension-points/config-source.md +1 -1
- package/agent-docs/extension-points/connector.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/counter.md +1 -1
- package/agent-docs/extension-points/directory.md +1 -1
- package/agent-docs/extension-points/file-preview.md +3 -1
- package/agent-docs/extension-points/identity-source.md +1 -1
- package/agent-docs/extension-points/model-provider.md +4 -2
- package/agent-docs/extension-points/object-store.md +3 -1
- package/agent-docs/extension-points/sandbox.md +3 -3
- package/agent-docs/extension-points/secret-store.md +1 -1
- package/agent-docs/extension-points/web-fetch.md +1 -1
- package/agent-docs/extension-points/web-search.md +1 -1
- package/agent-docs/extensions.md +29 -4
- package/agent-docs/plugin-format.md +43 -3
- package/agent-docs/setup.md +46 -0
- package/agent-docs/skills.md +1 -1
- package/agent-docs/tool-naming.md +1 -1
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/bootstrap.d.ts +15 -1
- package/dist/bootstrap.js +17 -1
- package/dist/cards.d.ts +67 -13
- package/dist/cards.js +91 -21
- package/dist/channel.d.ts +148 -48
- package/dist/channel.js +10 -5
- package/dist/client-css.d.ts +36 -0
- package/dist/client-css.js +326 -0
- package/dist/client-section.d.ts +35 -0
- package/dist/client-section.js +133 -0
- package/dist/config-ui.d.ts +22 -0
- package/dist/config-ui.js +64 -4
- package/dist/connector-auth.d.ts +7 -2
- package/dist/connector-auth.js +29 -8
- package/dist/connector.d.ts +74 -32
- package/dist/context.d.ts +40 -0
- package/dist/context.js +2 -0
- package/dist/ctx.d.ts +120 -29
- package/dist/define-extension.d.ts +26 -12
- package/dist/define-extension.js +11 -4
- package/dist/device-denied-paths.d.ts +14 -0
- package/dist/device-denied-paths.js +41 -0
- package/dist/device-protocol.d.ts +481 -0
- package/dist/device-protocol.js +1113 -0
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +5 -2
- package/dist/file-preview.d.ts +23 -6
- package/dist/git-hosts.d.ts +44 -0
- package/dist/git-hosts.js +81 -0
- package/dist/hooks.d.ts +125 -20
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +62 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +22 -9
- package/dist/index.d.ts +26 -1
- package/dist/index.js +26 -1
- package/dist/marketplace.d.ts +26 -0
- package/dist/marketplace.js +43 -1
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +206 -71
- package/dist/model.js +152 -19
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/network-classes.d.ts +98 -0
- package/dist/network-classes.js +291 -0
- package/dist/permissions.d.ts +41 -21
- package/dist/permissions.js +101 -42
- package/dist/plugin-manifest.d.ts +45 -5
- package/dist/plugin-manifest.js +169 -6
- package/dist/plugin-package.d.ts +82 -38
- package/dist/plugin-package.js +61 -29
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +2318 -0
- package/dist/sandbox-native-runtime-source.d.ts +8 -0
- package/dist/sandbox-native-runtime-source.js +465 -0
- package/dist/sandbox-operation.d.ts +284 -0
- package/dist/sandbox-operation.js +262 -0
- package/dist/sandbox-runtime-source.d.ts +19 -0
- package/dist/sandbox-runtime-source.js +28 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/sandbox.d.ts +190 -16
- package/dist/sandbox.js +89 -14
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-check.d.ts +115 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +350 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +94 -0
- package/dist/setup-guide.js +336 -0
- package/dist/shell-capabilities.d.ts +80 -0
- package/dist/shell-capabilities.js +13 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +16 -0
- package/dist/skill-invocation.d.ts +4 -3
- package/dist/skill-invocation.js +5 -4
- package/dist/skill.d.ts +34 -21
- package/dist/skill.js +48 -31
- package/dist/storage.d.ts +52 -25
- package/dist/theme-assets.d.ts +39 -0
- package/dist/theme-assets.js +449 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +287 -0
- package/dist/theme-tokens.generated.js +176 -0
- package/dist/theme.d.ts +152 -0
- package/dist/theme.js +392 -0
- package/dist/tool.d.ts +69 -26
- package/dist/tool.js +29 -9
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +348 -0
- package/dist/ui-resolve.d.ts +35 -0
- package/dist/ui-resolve.js +42 -0
- package/dist/ui-slots.d.ts +65 -0
- package/dist/ui-slots.js +261 -0
- package/dist/ui.d.ts +212 -76
- package/dist/ui.js +101 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/package.json +8 -1
- package/schemas/bootstrap.v1.schema.json +6 -0
- package/schemas/connector-template.v1.schema.json +35 -0
- package/schemas/marketplace.v1.schema.json +14 -0
- package/schemas/plugin.v1.schema.json +115 -3
- package/schemas/theme.v1.schema.json +225 -0
package/dist/index.js
CHANGED
|
@@ -1,31 +1,56 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.1.0-rc.
|
|
1
|
+
export const SDK_VERSION = "0.1.0-rc.40";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./bootstrap.js";
|
|
4
4
|
export * from "./cards.js";
|
|
5
5
|
export * from "./channel.js";
|
|
6
|
+
export * from "./client-css.js";
|
|
7
|
+
export * from "./client-section.js";
|
|
6
8
|
export * from "./config-ui.js";
|
|
7
9
|
export * from "./connector.js";
|
|
8
10
|
export * from "./connector-auth.js";
|
|
11
|
+
export * from "./context.js";
|
|
9
12
|
export * from "./ctx.js";
|
|
10
13
|
export * from "./define-extension.js";
|
|
14
|
+
export { DEVICE_DEFAULT_STATE_PATH, DEVICE_DENIED_SECRET_PATHS } from "./device-denied-paths.js";
|
|
15
|
+
export * from "./device-protocol.js";
|
|
11
16
|
export * from "./directory.js";
|
|
12
17
|
export * from "./extension-point.js";
|
|
13
18
|
export * from "./file-preview.js";
|
|
19
|
+
export * from "./git-hosts.js";
|
|
14
20
|
export * from "./hooks.js";
|
|
21
|
+
export * from "./http-access.js";
|
|
15
22
|
export * from "./identity.js";
|
|
16
23
|
export * from "./marketplace.js";
|
|
17
24
|
export * from "./model.js";
|
|
18
25
|
export * from "./model-params.js";
|
|
26
|
+
export * from "./net.js";
|
|
27
|
+
export * from "./network-classes.js";
|
|
19
28
|
export * from "./org-access.js";
|
|
20
29
|
export * from "./permissions.js";
|
|
21
30
|
export * from "./plugin-manifest.js";
|
|
22
31
|
export * from "./plugin-package.js";
|
|
23
32
|
export * from "./sandbox.js";
|
|
33
|
+
export * from "./sandbox-operation.js";
|
|
34
|
+
export { SANDBOX_RUNTIME_SOURCE } from "./sandbox-runtime-source.js";
|
|
35
|
+
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";
|
|
24
36
|
export * from "./secret.js";
|
|
37
|
+
export * from "./setup-check.js";
|
|
38
|
+
export * from "./setup-guide.js";
|
|
39
|
+
export { parseSetupGuide, } from "./setup-guide-parse.js";
|
|
40
|
+
export * from "./setup-guide-render.js";
|
|
41
|
+
export * from "./shell-capabilities.js";
|
|
42
|
+
export * from "./shell-environment.js";
|
|
25
43
|
export * from "./skill.js";
|
|
26
44
|
export * from "./skill-invocation.js";
|
|
27
45
|
export * from "./storage.js";
|
|
46
|
+
export * from "./theme.js";
|
|
47
|
+
export * from "./theme-assets.js";
|
|
48
|
+
export * from "./theme-readability.js";
|
|
49
|
+
export * from "./theme-tokens.generated.js";
|
|
28
50
|
export * from "./tool.js";
|
|
29
51
|
export * from "./tool-key.js";
|
|
30
52
|
export * from "./ui.js";
|
|
53
|
+
export * from "./ui-parts.js";
|
|
54
|
+
export * from "./ui-resolve.js";
|
|
55
|
+
export * from "./ui-slots.js";
|
|
31
56
|
export * from "./web.js";
|
package/dist/marketplace.d.ts
CHANGED
|
@@ -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).
|
package/dist/marketplace.js
CHANGED
|
@@ -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).
|
package/dist/model-params.d.ts
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `model-provider@2`
|
|
3
|
-
*
|
|
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
|
-
*
|
|
9
|
-
* - `thinking
|
|
10
|
-
*
|
|
11
|
-
* - `
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* A standard knob name (see {@link StandardKnob}), or a vendor-specific parameter `"<plugin
|
|
45
|
+
* name>.<name>"`.
|
|
46
|
+
*/
|
|
37
47
|
key: string;
|
|
38
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
60
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
79
|
-
*
|
|
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;
|
package/dist/model-params.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `model-provider@2`
|
|
3
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
52
|
-
*
|
|
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
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
202
|
-
*
|
|
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)) {
|