@capybara-hq/plugin-sdk 0.1.0-rc.3 → 0.1.0-rc.31
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 +5 -0
- package/agent-docs/connector-templates.md +2 -1
- package/agent-docs/extension-points/channel.md +1 -1
- 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 +1 -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 +56 -13
- package/dist/cards.js +90 -20
- package/dist/channel.d.ts +111 -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 +135 -26
- package/dist/define-extension.d.ts +26 -12
- package/dist/define-extension.js +11 -4
- package/dist/device-protocol-v3.d.ts +117 -0
- package/dist/device-protocol-v3.js +409 -0
- package/dist/device-protocol.d.ts +330 -0
- package/dist/device-protocol.js +567 -0
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +5 -2
- package/dist/file-preview.d.ts +1 -1
- package/dist/git-hosts.d.ts +44 -0
- package/dist/git-hosts.js +81 -0
- package/dist/hooks.d.ts +111 -21
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +52 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +22 -9
- package/dist/index.d.ts +23 -1
- package/dist/index.js +24 -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 +180 -71
- package/dist/model.js +71 -19
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/permissions.d.ts +42 -20
- package/dist/permissions.js +97 -40
- 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 +1886 -0
- package/dist/sandbox-native-runtime-source.d.ts +8 -0
- package/dist/sandbox-native-runtime-source.js +325 -0
- package/dist/sandbox-operation.d.ts +248 -0
- package/dist/sandbox-operation.js +245 -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 +60 -0
- package/dist/sandbox-write-denies.js +630 -0
- package/dist/sandbox.d.ts +201 -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/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 +279 -0
- package/dist/theme-tokens.generated.js +174 -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 +337 -0
- package/dist/ui-resolve.d.ts +35 -0
- package/dist/ui-resolve.js +42 -0
- package/dist/ui-slots.d.ts +53 -0
- package/dist/ui-slots.js +238 -0
- package/dist/ui.d.ts +191 -79
- package/dist/ui.js +101 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/package.json +7 -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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client stylesheet rule (client extensions spec §4.1, §7.2): one function both sides run, so
|
|
3
|
+
* a stylesheet that packs cleanly imports cleanly. `capybara-plugin pack` wraps every file in
|
|
4
|
+
* `@layer extensions { … }` ({@link wrapClientCss}) and checks the wrapped text; the kernel checks
|
|
5
|
+
* the stored bytes again at import, because a tgz can be written by hand. A file must be one
|
|
6
|
+
* `@layer extensions` block, may not `@import`, and a URL may name only an asset of the plugin
|
|
7
|
+
* (`../assets/<path>`, a file of `client.assets`), a `data:` URL or a `#fragment`. Any other URL,
|
|
8
|
+
* relative ones included, is refused: the stylesheet is served from
|
|
9
|
+
* `/api/v1/client/<plugin>/<build>/styles/`, so `../../../../…` would reach the kernel's own
|
|
10
|
+
* routes with the viewer's cookies.
|
|
11
|
+
*
|
|
12
|
+
* Two passes, both must pass:
|
|
13
|
+
* - a plain-text pass over the escape-decoded file (`cssRemoteProblem`);
|
|
14
|
+
* - a tokenizer that follows the CSS Syntax tokenization (comments, strings, escapes, url tokens)
|
|
15
|
+
* closely enough that every brace it skips is one a browser skips too: the file must start with
|
|
16
|
+
* `@layer extensions {` and the block that opens must close at the file's last character, so no
|
|
17
|
+
* rule lands outside the layer. Every `url(…)` (token or string) is checked after decoding
|
|
18
|
+
* escapes, and an `@import` at-keyword is refused however it is spelled.
|
|
19
|
+
*
|
|
20
|
+
* Two rules close the spellings a plain string check would miss:
|
|
21
|
+
* - URLs are trimmed with CSS whitespace only (space, tab, LF, CR, FF), and a file holding any other
|
|
22
|
+
* whitespace, a zero-width character (U+200B-U+200D, U+2060) or U+FEFF anywhere, escaped or not,
|
|
23
|
+
* is refused: JavaScript's `trim()` strips an NBSP that CSS and the URL parser keep, so
|
|
24
|
+
* `url("\a0 data:/../../v1")` would pass as `data:` and resolve to `/api/v1`;
|
|
25
|
+
* - functions that turn a plain string (or a `var()`) into a URL or reach outside the stylesheet are
|
|
26
|
+
* refused outright: `image-set(var(--u) 1x)` takes its URL from a custom property no string check
|
|
27
|
+
* can see. Plugins write `url(../assets/x)` directly.
|
|
28
|
+
*/
|
|
29
|
+
/** A stylesheet as the packer stores it: wrapped in `@layer extensions { … }` (spec §4.1). */
|
|
30
|
+
export declare function wrapClientCss(css: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* The problem of a client stylesheet as stored (see the file header), or undefined when it is one
|
|
33
|
+
* `@layer extensions` block with no `@import` and every URL a `#fragment`, a `data:` URL or one of
|
|
34
|
+
* the plugin's `assets` (paths relative to `assets/`).
|
|
35
|
+
*/
|
|
36
|
+
export declare function clientCssProblem(css: string, assets: ReadonlySet<string>): string | undefined;
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client stylesheet rule (client extensions spec §4.1, §7.2): one function both sides run, so
|
|
3
|
+
* a stylesheet that packs cleanly imports cleanly. `capybara-plugin pack` wraps every file in
|
|
4
|
+
* `@layer extensions { … }` ({@link wrapClientCss}) and checks the wrapped text; the kernel checks
|
|
5
|
+
* the stored bytes again at import, because a tgz can be written by hand. A file must be one
|
|
6
|
+
* `@layer extensions` block, may not `@import`, and a URL may name only an asset of the plugin
|
|
7
|
+
* (`../assets/<path>`, a file of `client.assets`), a `data:` URL or a `#fragment`. Any other URL,
|
|
8
|
+
* relative ones included, is refused: the stylesheet is served from
|
|
9
|
+
* `/api/v1/client/<plugin>/<build>/styles/`, so `../../../../…` would reach the kernel's own
|
|
10
|
+
* routes with the viewer's cookies.
|
|
11
|
+
*
|
|
12
|
+
* Two passes, both must pass:
|
|
13
|
+
* - a plain-text pass over the escape-decoded file (`cssRemoteProblem`);
|
|
14
|
+
* - a tokenizer that follows the CSS Syntax tokenization (comments, strings, escapes, url tokens)
|
|
15
|
+
* closely enough that every brace it skips is one a browser skips too: the file must start with
|
|
16
|
+
* `@layer extensions {` and the block that opens must close at the file's last character, so no
|
|
17
|
+
* rule lands outside the layer. Every `url(…)` (token or string) is checked after decoding
|
|
18
|
+
* escapes, and an `@import` at-keyword is refused however it is spelled.
|
|
19
|
+
*
|
|
20
|
+
* Two rules close the spellings a plain string check would miss:
|
|
21
|
+
* - URLs are trimmed with CSS whitespace only (space, tab, LF, CR, FF), and a file holding any other
|
|
22
|
+
* whitespace, a zero-width character (U+200B-U+200D, U+2060) or U+FEFF anywhere, escaped or not,
|
|
23
|
+
* is refused: JavaScript's `trim()` strips an NBSP that CSS and the URL parser keep, so
|
|
24
|
+
* `url("\a0 data:/../../v1")` would pass as `data:` and resolve to `/api/v1`;
|
|
25
|
+
* - functions that turn a plain string (or a `var()`) into a URL or reach outside the stylesheet are
|
|
26
|
+
* refused outright: `image-set(var(--u) 1x)` takes its URL from a custom property no string check
|
|
27
|
+
* can see. Plugins write `url(../assets/x)` directly.
|
|
28
|
+
*/
|
|
29
|
+
/** A stylesheet as the packer stores it: wrapped in `@layer extensions { … }` (spec §4.1). */
|
|
30
|
+
export function wrapClientCss(css) {
|
|
31
|
+
return `@layer extensions {\n${css.trimEnd()}\n}\n`;
|
|
32
|
+
}
|
|
33
|
+
/** CSS whitespace (CSS Syntax §4.2): only these are trimmed from a URL. */
|
|
34
|
+
const CSS_SPACE = "[ \\t\\n\\r\\f]";
|
|
35
|
+
const CSS_TRIM = new RegExp(`^${CSS_SPACE}+|${CSS_SPACE}+$`, "g");
|
|
36
|
+
const cssTrim = (s) => s.replace(CSS_TRIM, "");
|
|
37
|
+
/** Whitespace other than CSS's, zero-width characters and U+FEFF: refused anywhere in a file. */
|
|
38
|
+
const INVISIBLE_RE = /[\u0085\u00a0\u1680\u180e\u2000-\u200d\u2028\u2029\u202f\u205f\u2060\u3000\ufeff]/;
|
|
39
|
+
const INVISIBLE_REFUSED = "the stylesheet contains non-ASCII whitespace, a zero-width character or U+FEFF; use plain spaces";
|
|
40
|
+
/**
|
|
41
|
+
* Functions refused in a client stylesheet (case-insensitive, escapes decoded): they take URLs from
|
|
42
|
+
* plain strings or `var()` (`image-set`, `cross-fade`, `src`, `image`), or reach outside it
|
|
43
|
+
* (`element`, `paint`).
|
|
44
|
+
*/
|
|
45
|
+
const REFUSED_FUNCTIONS = new Set([
|
|
46
|
+
"image-set",
|
|
47
|
+
"-webkit-image-set",
|
|
48
|
+
"cross-fade",
|
|
49
|
+
"-webkit-cross-fade",
|
|
50
|
+
"element",
|
|
51
|
+
"-moz-element",
|
|
52
|
+
"paint",
|
|
53
|
+
"src",
|
|
54
|
+
"image",
|
|
55
|
+
]);
|
|
56
|
+
const REFUSED_FUNCTION_RE = /(?<![A-Za-z0-9_-])(-webkit-image-set|image-set|-webkit-cross-fade|cross-fade|-moz-element|element|paint|src|image)\(/i;
|
|
57
|
+
const functionRefused = (name) => `${name}() is not allowed in a client stylesheet; use url(../assets/<file>) directly`;
|
|
58
|
+
/**
|
|
59
|
+
* The plain-text pass, escapes decoded first: no invisible characters (see the file header), no {@link REFUSED_FUNCTIONS}, no
|
|
60
|
+
* `@import`, and every `url()` is {@link cssUrlProblem}-free. `assets` are the plugin's asset paths
|
|
61
|
+
* relative to `assets/` (`a.png`, `fx/boot.ogg`). Returns the problem, or undefined.
|
|
62
|
+
*/
|
|
63
|
+
function cssRemoteProblem(css, assets) {
|
|
64
|
+
const bare = css
|
|
65
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
66
|
+
.replace(/\\([0-9a-f]{1,6})[ \t\n]?|\\([^\n])/gi, (_m, hex, ch) => {
|
|
67
|
+
if (hex === undefined)
|
|
68
|
+
return ch ?? "";
|
|
69
|
+
const cp = Number.parseInt(hex, 16);
|
|
70
|
+
return cp > 0 && cp <= 0x10ffff ? String.fromCodePoint(cp) : "�";
|
|
71
|
+
});
|
|
72
|
+
if (INVISIBLE_RE.test(css) || INVISIBLE_RE.test(bare))
|
|
73
|
+
return INVISIBLE_REFUSED;
|
|
74
|
+
const fn = REFUSED_FUNCTION_RE.exec(bare);
|
|
75
|
+
if (fn !== null)
|
|
76
|
+
return functionRefused(fn[1].toLowerCase());
|
|
77
|
+
if (/@import\b/i.test(bare))
|
|
78
|
+
return IMPORT_REFUSED;
|
|
79
|
+
for (const m of bare.matchAll(/url\([ \t\n\r\f]*(["']?)([^)"']*)\1[ \t\n\r\f]*\)/gi)) {
|
|
80
|
+
const problem = cssUrlProblem(cssTrim(m[2] ?? ""), assets);
|
|
81
|
+
if (problem !== undefined)
|
|
82
|
+
return problem;
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
const IMPORT_REFUSED = "@import is not allowed (a remote stylesheet is not integrity-pinned); inline the rules";
|
|
87
|
+
/** How a stylesheet names one of the plugin's assets (it is served from `styles/`). */
|
|
88
|
+
const ASSETS_URL = "../assets/";
|
|
89
|
+
/**
|
|
90
|
+
* The problem of one URL of a stylesheet (escapes decoded, CSS whitespace trimmed), or undefined
|
|
91
|
+
* when it is a `#fragment`, a `data:` URL or `../assets/<path>` naming one of `assets` exactly.
|
|
92
|
+
*/
|
|
93
|
+
function cssUrlProblem(u, assets) {
|
|
94
|
+
if (u.startsWith("#") || /^data:/i.test(u))
|
|
95
|
+
return undefined;
|
|
96
|
+
if (u.startsWith(ASSETS_URL) && assets.has(u.slice(ASSETS_URL.length)))
|
|
97
|
+
return undefined;
|
|
98
|
+
return `url(${u}) is not allowed; use ../assets/<a file of client/assets>, a data: URL or a #fragment`;
|
|
99
|
+
}
|
|
100
|
+
const WRAP_RE = /^@layer extensions \{/;
|
|
101
|
+
const isNewline = (c) => c === "\n" || c === "\r" || c === "\f";
|
|
102
|
+
const isWhitespace = (c) => c === " " || c === "\t" || isNewline(c);
|
|
103
|
+
const isHex = (c) => c !== undefined && /^[0-9a-f]$/i.test(c);
|
|
104
|
+
/** A name code point (CSS Syntax §4.2): letters, digits, `-`, `_`, anything non-ASCII. */
|
|
105
|
+
const isNameChar = (c) => c !== undefined && (/^[A-Za-z0-9_-]$/.test(c) || c.codePointAt(0) >= 0x80);
|
|
106
|
+
class CssProblem extends Error {
|
|
107
|
+
}
|
|
108
|
+
/** Tokenizes `css` from `start`; see the file header. */
|
|
109
|
+
class Scanner {
|
|
110
|
+
css;
|
|
111
|
+
assets;
|
|
112
|
+
i;
|
|
113
|
+
/** Open `{` blocks; the layer block is the first. */
|
|
114
|
+
depth = 1;
|
|
115
|
+
/** Open function / parenthesis names ("" for a plain `(` or `[`), innermost last. */
|
|
116
|
+
fns = [];
|
|
117
|
+
constructor(css, start, assets) {
|
|
118
|
+
this.css = css;
|
|
119
|
+
this.assets = assets;
|
|
120
|
+
this.i = start;
|
|
121
|
+
}
|
|
122
|
+
run() {
|
|
123
|
+
const s = this.css;
|
|
124
|
+
while (this.i < s.length) {
|
|
125
|
+
const c = s[this.i];
|
|
126
|
+
if (c === "/" && s[this.i + 1] === "*") {
|
|
127
|
+
const end = s.indexOf("*/", this.i + 2);
|
|
128
|
+
if (end < 0)
|
|
129
|
+
throw new CssProblem("a comment is not closed");
|
|
130
|
+
this.i = end + 2;
|
|
131
|
+
}
|
|
132
|
+
else if (c === '"' || c === "'") {
|
|
133
|
+
const value = this.string(c);
|
|
134
|
+
if (this.fns[this.fns.length - 1] === "url") {
|
|
135
|
+
const problem = cssUrlProblem(cssTrim(value), this.assets);
|
|
136
|
+
if (problem !== undefined)
|
|
137
|
+
throw new CssProblem(problem);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if (c === "@") {
|
|
141
|
+
this.i++;
|
|
142
|
+
if (this.startsName()) {
|
|
143
|
+
if (this.name().toLowerCase() === "import")
|
|
144
|
+
throw new CssProblem(IMPORT_REFUSED);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else if (c === "#") {
|
|
148
|
+
this.i++;
|
|
149
|
+
if (this.startsName())
|
|
150
|
+
this.name();
|
|
151
|
+
}
|
|
152
|
+
else if (this.startsName()) {
|
|
153
|
+
const name = this.name().toLowerCase();
|
|
154
|
+
if (s[this.i] === "(") {
|
|
155
|
+
this.i++;
|
|
156
|
+
if (REFUSED_FUNCTIONS.has(name))
|
|
157
|
+
throw new CssProblem(functionRefused(name));
|
|
158
|
+
if (name === "url" && !this.quoteAfterWhitespace())
|
|
159
|
+
this.urlToken();
|
|
160
|
+
else
|
|
161
|
+
this.fns.push(name);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else if (c === "(" || c === "[") {
|
|
165
|
+
this.fns.push("");
|
|
166
|
+
this.i++;
|
|
167
|
+
}
|
|
168
|
+
else if (c === ")" || c === "]") {
|
|
169
|
+
this.fns.pop();
|
|
170
|
+
this.i++;
|
|
171
|
+
}
|
|
172
|
+
else if (c === "{") {
|
|
173
|
+
this.depth++;
|
|
174
|
+
this.i++;
|
|
175
|
+
}
|
|
176
|
+
else if (c === "}") {
|
|
177
|
+
this.depth--;
|
|
178
|
+
this.i++;
|
|
179
|
+
if (this.depth === 0) {
|
|
180
|
+
if (cssTrim(s.slice(this.i)) !== "") {
|
|
181
|
+
throw new CssProblem("a rule is outside @layer extensions; the whole file must be one @layer extensions block");
|
|
182
|
+
}
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
this.i++;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
throw new CssProblem("the @layer extensions block is not closed");
|
|
191
|
+
}
|
|
192
|
+
/** Whether a name starts here: a name code point or a valid escape. */
|
|
193
|
+
startsName() {
|
|
194
|
+
const s = this.css;
|
|
195
|
+
const c = s[this.i];
|
|
196
|
+
return isNameChar(c) || (c === "\\" && this.i + 1 < s.length && !isNewline(s[this.i + 1]));
|
|
197
|
+
}
|
|
198
|
+
/** A valid escape at `this.i` (the backslash); returns the decoded character. */
|
|
199
|
+
escape() {
|
|
200
|
+
const s = this.css;
|
|
201
|
+
this.i++; // the backslash
|
|
202
|
+
if (isHex(s[this.i])) {
|
|
203
|
+
let hex = "";
|
|
204
|
+
while (hex.length < 6 && isHex(s[this.i]))
|
|
205
|
+
hex += s[this.i++];
|
|
206
|
+
if (s[this.i] === "\r" && s[this.i + 1] === "\n")
|
|
207
|
+
this.i += 2;
|
|
208
|
+
else if (isWhitespace(s[this.i]))
|
|
209
|
+
this.i++;
|
|
210
|
+
const cp = Number.parseInt(hex, 16);
|
|
211
|
+
return cp > 0 && cp <= 0x10ffff && (cp < 0xd800 || cp > 0xdfff)
|
|
212
|
+
? String.fromCodePoint(cp)
|
|
213
|
+
: "�";
|
|
214
|
+
}
|
|
215
|
+
const cp = s.codePointAt(this.i);
|
|
216
|
+
if (cp === undefined)
|
|
217
|
+
return "�";
|
|
218
|
+
const ch = String.fromCodePoint(cp);
|
|
219
|
+
this.i += ch.length;
|
|
220
|
+
return ch;
|
|
221
|
+
}
|
|
222
|
+
/** Consumes a name (name code points and valid escapes), decoded. */
|
|
223
|
+
name() {
|
|
224
|
+
const s = this.css;
|
|
225
|
+
let out = "";
|
|
226
|
+
while (this.i < s.length) {
|
|
227
|
+
const c = s[this.i];
|
|
228
|
+
if (isNameChar(c)) {
|
|
229
|
+
out += c;
|
|
230
|
+
this.i++;
|
|
231
|
+
}
|
|
232
|
+
else if (c === "\\" && this.i + 1 < s.length && !isNewline(s[this.i + 1])) {
|
|
233
|
+
out += this.escape();
|
|
234
|
+
}
|
|
235
|
+
else
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
return out;
|
|
239
|
+
}
|
|
240
|
+
/** A string from its opening quote; an unescaped newline or the end of the file refuses. */
|
|
241
|
+
string(quote) {
|
|
242
|
+
const s = this.css;
|
|
243
|
+
this.i++;
|
|
244
|
+
let out = "";
|
|
245
|
+
while (this.i < s.length) {
|
|
246
|
+
const c = s[this.i];
|
|
247
|
+
if (c === quote) {
|
|
248
|
+
this.i++;
|
|
249
|
+
return out;
|
|
250
|
+
}
|
|
251
|
+
if (isNewline(c))
|
|
252
|
+
throw new CssProblem("a string is not closed on its line");
|
|
253
|
+
if (c === "\\") {
|
|
254
|
+
const next = s[this.i + 1];
|
|
255
|
+
if (next === undefined)
|
|
256
|
+
break;
|
|
257
|
+
if (isNewline(next)) {
|
|
258
|
+
this.i += next === "\r" && s[this.i + 2] === "\n" ? 3 : 2;
|
|
259
|
+
}
|
|
260
|
+
else
|
|
261
|
+
out += this.escape();
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
out += c;
|
|
265
|
+
this.i++;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
throw new CssProblem("a string is not closed");
|
|
269
|
+
}
|
|
270
|
+
/** After `url(`: whether the argument is a string (then `url(` is an ordinary function). */
|
|
271
|
+
quoteAfterWhitespace() {
|
|
272
|
+
const s = this.css;
|
|
273
|
+
let j = this.i;
|
|
274
|
+
while (isWhitespace(s[j]))
|
|
275
|
+
j++;
|
|
276
|
+
return s[j] === '"' || s[j] === "'";
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* An unquoted url token after `url(`: everything up to the first unescaped `)` (a bad url, with a
|
|
280
|
+
* quote or `(` inside, ends there too), escapes decoded; the URL is checked.
|
|
281
|
+
*/
|
|
282
|
+
urlToken() {
|
|
283
|
+
const s = this.css;
|
|
284
|
+
let out = "";
|
|
285
|
+
while (this.i < s.length) {
|
|
286
|
+
const c = s[this.i];
|
|
287
|
+
if (c === ")") {
|
|
288
|
+
this.i++;
|
|
289
|
+
const problem = cssUrlProblem(cssTrim(out), this.assets);
|
|
290
|
+
if (problem !== undefined)
|
|
291
|
+
throw new CssProblem(problem);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
if (c === "\\" && this.i + 1 < s.length && !isNewline(s[this.i + 1]))
|
|
295
|
+
out += this.escape();
|
|
296
|
+
else {
|
|
297
|
+
out += c;
|
|
298
|
+
this.i++;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
throw new CssProblem("a url( is not closed");
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* The problem of a client stylesheet as stored (see the file header), or undefined when it is one
|
|
306
|
+
* `@layer extensions` block with no `@import` and every URL a `#fragment`, a `data:` URL or one of
|
|
307
|
+
* the plugin's `assets` (paths relative to `assets/`).
|
|
308
|
+
*/
|
|
309
|
+
export function clientCssProblem(css, assets) {
|
|
310
|
+
const remote = cssRemoteProblem(css, assets);
|
|
311
|
+
if (remote !== undefined)
|
|
312
|
+
return remote;
|
|
313
|
+
const wrap = WRAP_RE.exec(css);
|
|
314
|
+
if (wrap === null) {
|
|
315
|
+
return "the file must start with @layer extensions { (capybara-plugin pack wraps every stylesheet)";
|
|
316
|
+
}
|
|
317
|
+
try {
|
|
318
|
+
new Scanner(css, wrap[0].length, assets).run();
|
|
319
|
+
}
|
|
320
|
+
catch (e) {
|
|
321
|
+
if (e instanceof CssProblem)
|
|
322
|
+
return e.message;
|
|
323
|
+
throw e;
|
|
324
|
+
}
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client section of a plugin's extension (client extensions spec §4.1): the browser bundle, CSS
|
|
3
|
+
* files and assets under `./dist/client/`, each pinned by a sha384 integrity. Written by the packer.
|
|
4
|
+
*/
|
|
5
|
+
export interface PluginClientSection {
|
|
6
|
+
/** `./dist/client/client.mjs`; absent for CSS-only decoration. */
|
|
7
|
+
entry?: string;
|
|
8
|
+
/** `./dist/client/styles/<name>.css`, in injection order. */
|
|
9
|
+
styles?: string[];
|
|
10
|
+
/** `./dist/client/assets/<path>`. */
|
|
11
|
+
assets?: string[];
|
|
12
|
+
/** sha384 of every file above, keyed by its path: `sha384-<base64>`. */
|
|
13
|
+
integrity: Record<string, string>;
|
|
14
|
+
/** {@link CLIENT_API_VERSION} the bundle was built against. */
|
|
15
|
+
apiVersion: number;
|
|
16
|
+
}
|
|
17
|
+
/** The client API version the host provides (`@capybara-hq/plugin-client` carries the same number). */
|
|
18
|
+
export declare const CLIENT_API_VERSION = 1;
|
|
19
|
+
/** Limits of client code (client extensions spec §4.1, §10). */
|
|
20
|
+
export declare const CLIENT_LIMITS: {
|
|
21
|
+
readonly entryBytes: 1048576;
|
|
22
|
+
readonly styleFiles: 8;
|
|
23
|
+
readonly styleBytes: 262144;
|
|
24
|
+
readonly assetFiles: 64;
|
|
25
|
+
readonly assetBytes: 2097152;
|
|
26
|
+
readonly totalBytes: 8388608;
|
|
27
|
+
readonly loadTimeoutMs: 10000;
|
|
28
|
+
readonly pendingMs: 1500;
|
|
29
|
+
readonly crashBudget: 3;
|
|
30
|
+
};
|
|
31
|
+
/** Allowed asset extensions and the content type each is served with. */
|
|
32
|
+
export declare const CLIENT_ASSET_TYPES: Readonly<Record<string, string>>;
|
|
33
|
+
export declare const CLIENT_ENTRY_PATH = "./dist/client/client.mjs";
|
|
34
|
+
/** Checks a client section (`parsePluginManifest` and the packer use it); returns the problems. */
|
|
35
|
+
export declare function validateClientSection(s: unknown): string[];
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { isSafePackagePath } from "./plugin-package.js";
|
|
2
|
+
/** The client API version the host provides (`@capybara-hq/plugin-client` carries the same number). */
|
|
3
|
+
export const CLIENT_API_VERSION = 1;
|
|
4
|
+
/** Limits of client code (client extensions spec §4.1, §10). */
|
|
5
|
+
export const CLIENT_LIMITS = {
|
|
6
|
+
entryBytes: 1048576,
|
|
7
|
+
styleFiles: 8,
|
|
8
|
+
styleBytes: 262144,
|
|
9
|
+
assetFiles: 64,
|
|
10
|
+
assetBytes: 2097152,
|
|
11
|
+
totalBytes: 8388608,
|
|
12
|
+
loadTimeoutMs: 10000,
|
|
13
|
+
pendingMs: 1500,
|
|
14
|
+
crashBudget: 3,
|
|
15
|
+
};
|
|
16
|
+
/** Allowed asset extensions and the content type each is served with. */
|
|
17
|
+
export const CLIENT_ASSET_TYPES = {
|
|
18
|
+
".png": "image/png",
|
|
19
|
+
".webp": "image/webp",
|
|
20
|
+
".svg": "image/svg+xml",
|
|
21
|
+
".woff2": "font/woff2",
|
|
22
|
+
".mp3": "audio/mpeg",
|
|
23
|
+
".ogg": "audio/ogg",
|
|
24
|
+
".wav": "audio/wav",
|
|
25
|
+
};
|
|
26
|
+
export const CLIENT_ENTRY_PATH = "./dist/client/client.mjs";
|
|
27
|
+
const STYLE_RE = /^\.\/dist\/client\/styles\/[A-Za-z0-9][A-Za-z0-9._-]*\.css$/;
|
|
28
|
+
const ASSET_PREFIX = "./dist/client/assets/";
|
|
29
|
+
/** One segment of an asset path: URL-safe characters only (the kernel's delivery key charset). */
|
|
30
|
+
const ASSET_SEGMENT_RE = /^[A-Za-z0-9._-]+$/;
|
|
31
|
+
const INTEGRITY_RE = /^sha384-[A-Za-z0-9+/]{64}$/;
|
|
32
|
+
const isStringArray = (v) => Array.isArray(v) && v.every((x) => typeof x === "string");
|
|
33
|
+
/** Checks a client section (`parsePluginManifest` and the packer use it); returns the problems. */
|
|
34
|
+
export function validateClientSection(s) {
|
|
35
|
+
if (s === null || typeof s !== "object" || Array.isArray(s))
|
|
36
|
+
return ["client must be an object"];
|
|
37
|
+
const o = s;
|
|
38
|
+
const errs = [];
|
|
39
|
+
for (const k of Object.keys(o)) {
|
|
40
|
+
if (!["entry", "styles", "assets", "integrity", "apiVersion"].includes(k)) {
|
|
41
|
+
errs.push(`client.${k} is not a known field`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const listed = [];
|
|
45
|
+
if (o.entry !== undefined) {
|
|
46
|
+
if (o.entry !== CLIENT_ENTRY_PATH)
|
|
47
|
+
errs.push(`client.entry must be ${CLIENT_ENTRY_PATH}`);
|
|
48
|
+
else
|
|
49
|
+
listed.push(o.entry);
|
|
50
|
+
}
|
|
51
|
+
let styleCount = 0;
|
|
52
|
+
if (o.styles !== undefined) {
|
|
53
|
+
if (!isStringArray(o.styles))
|
|
54
|
+
errs.push("client.styles must be an array of strings");
|
|
55
|
+
else {
|
|
56
|
+
styleCount = o.styles.length;
|
|
57
|
+
if (styleCount > CLIENT_LIMITS.styleFiles) {
|
|
58
|
+
errs.push(`client.styles has ${styleCount} files; the limit is ${CLIENT_LIMITS.styleFiles}`);
|
|
59
|
+
}
|
|
60
|
+
for (const p of o.styles) {
|
|
61
|
+
if (!STYLE_RE.test(p)) {
|
|
62
|
+
errs.push(`client.styles: ${p} must be ./dist/client/styles/<name>.css`);
|
|
63
|
+
}
|
|
64
|
+
else if (listed.includes(p))
|
|
65
|
+
errs.push(`client.styles: duplicate ${p}`);
|
|
66
|
+
else
|
|
67
|
+
listed.push(p);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (o.assets !== undefined) {
|
|
72
|
+
if (!isStringArray(o.assets))
|
|
73
|
+
errs.push("client.assets must be an array of strings");
|
|
74
|
+
else {
|
|
75
|
+
if (o.assets.length > CLIENT_LIMITS.assetFiles) {
|
|
76
|
+
errs.push(`client.assets has ${o.assets.length} files; the limit is ${CLIENT_LIMITS.assetFiles}`);
|
|
77
|
+
}
|
|
78
|
+
for (const p of o.assets) {
|
|
79
|
+
const rest = p.startsWith(ASSET_PREFIX) ? p.slice(ASSET_PREFIX.length) : null;
|
|
80
|
+
if (rest === null || !isSafePackagePath(rest)) {
|
|
81
|
+
errs.push(`client.assets: ${p} must be a safe path under ${ASSET_PREFIX}`);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
// the kernel looks a file up by its exact key, never decoding the URL (`%2e%2e` names no
|
|
85
|
+
// file there), so every segment uses the URL-safe characters only
|
|
86
|
+
if (!rest.split("/").every((seg) => ASSET_SEGMENT_RE.test(seg))) {
|
|
87
|
+
errs.push(`client.assets: ${p} must use letters, digits, . _ - in each path segment`);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const name = rest.slice(rest.lastIndexOf("/") + 1);
|
|
91
|
+
const dot = name.lastIndexOf(".");
|
|
92
|
+
if (dot === 0) {
|
|
93
|
+
errs.push(`client.assets: ${p} needs a file name before the extension`);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const ext = dot < 0 ? "" : name.slice(dot).toLowerCase();
|
|
97
|
+
if (!Object.hasOwn(CLIENT_ASSET_TYPES, ext)) {
|
|
98
|
+
errs.push(`client.assets: ${p} has an unsupported type; allowed: ${Object.keys(CLIENT_ASSET_TYPES).join(" ")}`);
|
|
99
|
+
}
|
|
100
|
+
else if (listed.includes(p))
|
|
101
|
+
errs.push(`client.assets: duplicate ${p}`);
|
|
102
|
+
else
|
|
103
|
+
listed.push(p);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (o.entry === undefined && styleCount === 0) {
|
|
108
|
+
errs.push("client needs an entry or at least one style file");
|
|
109
|
+
}
|
|
110
|
+
const integ = o.integrity;
|
|
111
|
+
if (integ === null || typeof integ !== "object" || Array.isArray(integ)) {
|
|
112
|
+
errs.push("client.integrity must be an object");
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const map = integ;
|
|
116
|
+
for (const p of listed) {
|
|
117
|
+
const v = map[p];
|
|
118
|
+
if (v === undefined)
|
|
119
|
+
errs.push(`client.integrity: missing entry for ${p}`);
|
|
120
|
+
else if (typeof v !== "string" || !INTEGRITY_RE.test(v)) {
|
|
121
|
+
errs.push(`client.integrity: ${p} must be sha384-<base64>`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
for (const p of Object.keys(map)) {
|
|
125
|
+
if (!listed.includes(p))
|
|
126
|
+
errs.push(`client.integrity: ${p} is not a listed file`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (typeof o.apiVersion !== "number" || !Number.isInteger(o.apiVersion) || o.apiVersion < 1) {
|
|
130
|
+
errs.push("client.apiVersion must be a positive integer");
|
|
131
|
+
}
|
|
132
|
+
return errs;
|
|
133
|
+
}
|
package/dist/config-ui.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ import type { LocalizedName } from "./plugin-package.js";
|
|
|
10
10
|
export type JsonSchema = Record<string, unknown>;
|
|
11
11
|
/** The input widget of a field. */
|
|
12
12
|
export type ConfigWidget = "text" | "textarea" | "url" | "number" | "select" | "radio" | "switch" | "checkbox" | "tristate" | "tags" | "json";
|
|
13
|
+
/** How a channel connection receives events: a long connection (default) or webhooks. */
|
|
14
|
+
export type ChannelInboundMode = "long_connection" | "webhook";
|
|
15
|
+
/** Every channel inbound mode, in the order forms list them. */
|
|
16
|
+
export declare const CHANNEL_INBOUND_MODES: readonly ChannelInboundMode[];
|
|
13
17
|
/** A labelled value of an enum (or boolean) field. */
|
|
14
18
|
export interface ConfigUiOption {
|
|
15
19
|
value: string | number | boolean;
|
|
@@ -73,6 +77,13 @@ export interface ConfigUiHints {
|
|
|
73
77
|
sections?: ConfigUiSection[];
|
|
74
78
|
/** Root only: localized messages for custom issues (`params: { ui: key }`). */
|
|
75
79
|
messages?: Record<string, LocalizedName>;
|
|
80
|
+
/**
|
|
81
|
+
* Channel connection config only, top-level fields only: the inbound modes the field belongs to.
|
|
82
|
+
* Forms draw it only in those modes and require it there; the kernel refuses a connection whose
|
|
83
|
+
* mode requires it without a value (channel inbound mode fields spec §2, §3). The zod schema keeps
|
|
84
|
+
* the field optional, since the other modes do not use it.
|
|
85
|
+
*/
|
|
86
|
+
inboundModes?: ChannelInboundMode[];
|
|
76
87
|
}
|
|
77
88
|
/** Limits of config UI hints and of the JSON Schemas a plugin package carries. */
|
|
78
89
|
export declare const CONFIG_UI_LIMITS: {
|
|
@@ -129,3 +140,14 @@ export interface ConfigUiProblem {
|
|
|
129
140
|
* problem (empty = valid); never throws. Problem paths are dot paths of the node holding the hint.
|
|
130
141
|
*/
|
|
131
142
|
export declare function validateConfigUi(schema: JsonSchema, level: "deployment" | "org" | "connection"): ConfigUiProblem[];
|
|
143
|
+
/**
|
|
144
|
+
* The top-level fields of a connection config's JSON Schema ({@link configJsonSchema}) that carry
|
|
145
|
+
* an `inboundModes` hint, with their modes (unknown modes dropped). Pure; fields without the hint
|
|
146
|
+
* belong to every mode and are not listed.
|
|
147
|
+
*/
|
|
148
|
+
export declare function inboundModeFields(schema: JsonSchema): Record<string, ChannelInboundMode[]>;
|
|
149
|
+
/**
|
|
150
|
+
* The fields `mode` requires ({@link inboundModeFields}) for which `has(field)` is false, in schema
|
|
151
|
+
* order: what the kernel refuses on a channel connection create or config / mode change.
|
|
152
|
+
*/
|
|
153
|
+
export declare function missingInboundModeFields(schema: JsonSchema, mode: ChannelInboundMode, has: (field: string) => boolean): string[];
|