@capybara-hq/plugin-sdk 0.1.0-rc.7 → 0.1.0-rc.71
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/README.md +1 -1
- package/agent-docs/agent-templates.md +14 -2
- package/agent-docs/concepts.md +14 -5
- package/agent-docs/connector-templates.md +11 -3
- package/agent-docs/extension-points/channel.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/device-provider.md +15 -0
- package/agent-docs/extension-points/file-preview.md +3 -1
- package/agent-docs/extension-points/model-provider.md +3 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- package/agent-docs/extension-points/push-provider.md +17 -0
- package/agent-docs/extensions.md +77 -4
- package/agent-docs/plugin-format.md +51 -12
- package/agent-docs/setup.md +54 -0
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/avatar-presets.d.ts +8 -0
- package/dist/avatar-presets.js +17 -0
- package/dist/bootstrap.d.ts +109 -1
- package/dist/bootstrap.js +185 -2
- package/dist/cards.d.ts +60 -13
- package/dist/cards.js +88 -18
- package/dist/channel.d.ts +128 -47
- 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 +28 -6
- package/dist/config-ui.js +88 -25
- package/dist/config-url-fetch.d.ts +19 -0
- package/dist/config-url-fetch.js +43 -0
- package/dist/connector-auth.d.ts +13 -2
- package/dist/connector-auth.js +82 -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 +210 -30
- package/dist/ctx.js +9 -1
- package/dist/define-extension.d.ts +23 -13
- package/dist/define-extension.js +19 -5
- package/dist/device-denied-paths.d.ts +20 -0
- package/dist/device-denied-paths.js +118 -0
- package/dist/device-operation.d.ts +339 -0
- package/dist/device-operation.js +312 -0
- package/dist/device-protocol.d.ts +285 -50
- package/dist/device-protocol.js +755 -90
- package/dist/device-provider.d.ts +708 -0
- package/dist/device-provider.js +325 -0
- package/dist/device-service.d.ts +52 -0
- package/dist/device-service.js +105 -0
- package/dist/dial-in.d.ts +239 -0
- package/dist/dial-in.js +155 -0
- package/dist/directory.d.ts +15 -12
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +7 -3
- package/dist/field-meta.d.ts +19 -0
- package/dist/field-meta.js +54 -0
- package/dist/file-preview.d.ts +43 -10
- package/dist/git-hosts.d.ts +53 -0
- package/dist/git-hosts.js +98 -0
- package/dist/hooks.d.ts +125 -20
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +71 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +38 -9
- package/dist/identity.js +21 -1
- package/dist/index.d.ts +31 -4
- package/dist/index.js +31 -4
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +210 -75
- 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 +65 -22
- package/dist/permissions.js +139 -43
- package/dist/platform-only.d.ts +27 -0
- package/dist/platform-only.js +35 -0
- package/dist/plugin-manifest.d.ts +40 -9
- package/dist/plugin-manifest.js +171 -60
- package/dist/plugin-package.d.ts +82 -39
- package/dist/plugin-package.js +68 -41
- package/dist/push.d.ts +75 -0
- package/dist/push.js +87 -0
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +2343 -0
- package/dist/sandbox-native-runtime-source.d.ts +10 -0
- package/dist/sandbox-native-runtime-source.js +476 -0
- package/dist/sandbox-runtime-source.d.ts +47 -0
- package/dist/sandbox-runtime-source.js +73 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/secret.d.ts +8 -2
- package/dist/secret.js +11 -4
- package/dist/setup-check.d.ts +128 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +356 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +86 -72
- package/dist/setup-guide.js +340 -108
- package/dist/shell-capabilities.d.ts +211 -0
- package/dist/shell-capabilities.js +44 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +21 -0
- package/dist/skill.d.ts +27 -17
- package/dist/skill.js +40 -26
- package/dist/storage.d.ts +52 -25
- package/dist/svg-viewbox.d.ts +10 -0
- package/dist/svg-viewbox.js +24 -0
- package/dist/theme-assets.d.ts +55 -0
- package/dist/theme-assets.js +489 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +299 -0
- package/dist/theme-tokens.generated.js +184 -0
- package/dist/theme.d.ts +190 -0
- package/dist/theme.js +471 -0
- package/dist/tool.d.ts +104 -30
- package/dist/tool.js +29 -9
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +385 -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 +232 -77
- package/dist/ui.js +104 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/dist/web.d.ts +26 -20
- package/package.json +13 -1
- package/schemas/bootstrap-extra.v1.schema.json +186 -0
- package/schemas/bootstrap.v1.schema.json +20 -0
- package/schemas/connector-template.v1.schema.json +62 -4
- package/schemas/plugin.v1.schema.json +93 -143
- package/schemas/theme.v1.schema.json +302 -0
- package/agent-docs/extension-points/sandbox.md +0 -15
- package/dist/org-access.d.ts +0 -27
- package/dist/org-access.js +0 -35
- package/dist/sandbox.d.ts +0 -254
- package/dist/sandbox.js +0 -153
package/dist/bootstrap.d.ts
CHANGED
|
@@ -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
|
|
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 {
|
|
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
|
|
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
|
-
*
|
|
4
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
69
|
-
*
|
|
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;
|