@capybara-hq/plugin-sdk 0.1.0-rc.1 → 0.1.0-rc.11
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 +47 -0
- package/agent-docs/concepts.md +63 -0
- package/agent-docs/connector-templates.md +48 -0
- package/agent-docs/extension-points/channel.md +15 -0
- package/agent-docs/extension-points/config-source.md +15 -0
- package/agent-docs/extension-points/connector.md +15 -0
- package/agent-docs/extension-points/counter.md +15 -0
- package/agent-docs/extension-points/directory.md +15 -0
- package/agent-docs/extension-points/file-preview.md +15 -0
- package/agent-docs/extension-points/identity-source.md +15 -0
- package/agent-docs/extension-points/model-provider.md +15 -0
- package/agent-docs/extension-points/object-store.md +15 -0
- package/agent-docs/extension-points/sandbox.md +15 -0
- package/agent-docs/extension-points/secret-store.md +15 -0
- package/agent-docs/extension-points/web-fetch.md +15 -0
- package/agent-docs/extension-points/web-search.md +15 -0
- package/agent-docs/extensions.md +87 -0
- package/agent-docs/plugin-format.md +100 -0
- package/agent-docs/setup.md +46 -0
- package/agent-docs/skills.md +44 -0
- package/agent-docs/tool-naming.md +21 -0
- package/dist/agent-template.d.ts +85 -0
- package/dist/agent-template.js +361 -2
- package/dist/cards.d.ts +7 -0
- package/dist/cards.js +4 -4
- package/dist/channel.d.ts +20 -1
- 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 +131 -0
- package/dist/config-ui.js +602 -0
- package/dist/connector-auth.d.ts +2 -0
- package/dist/connector-auth.js +15 -0
- package/dist/ctx.d.ts +86 -4
- package/dist/define-extension.d.ts +5 -1
- package/dist/define-extension.js +1 -0
- package/dist/device-protocol.d.ts +118 -0
- package/dist/device-protocol.js +276 -0
- package/dist/directory.d.ts +11 -2
- package/dist/extension-point.d.ts +9 -0
- package/dist/extension-point.js +17 -12
- package/dist/file-preview.d.ts +9 -1
- package/dist/hooks.d.ts +76 -16
- package/dist/index.d.ts +18 -1
- package/dist/index.js +18 -1
- package/dist/marketplace.d.ts +55 -2
- package/dist/marketplace.js +73 -3
- package/dist/model.d.ts +60 -2
- package/dist/model.js +22 -0
- package/dist/org-access.d.ts +27 -0
- package/dist/org-access.js +35 -0
- package/dist/permissions.d.ts +32 -7
- package/dist/permissions.js +86 -22
- package/dist/plugin-manifest.d.ts +70 -5
- package/dist/plugin-manifest.js +186 -6
- package/dist/sandbox.d.ts +164 -62
- package/dist/sandbox.js +71 -14
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +5 -2
- 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 +9 -5
- package/dist/skill-invocation.js +18 -8
- package/dist/skill.d.ts +23 -3
- package/dist/skill.js +31 -6
- 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 +275 -0
- package/dist/theme-tokens.generated.js +167 -0
- package/dist/theme.d.ts +152 -0
- package/dist/theme.js +392 -0
- package/dist/tool.d.ts +11 -3
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +238 -0
- package/dist/ui-resolve.d.ts +40 -0
- package/dist/ui-resolve.js +54 -0
- package/dist/ui-slots.d.ts +55 -0
- package/dist/ui-slots.js +247 -0
- package/dist/ui.d.ts +143 -37
- package/dist/ui.js +65 -5
- package/dist/web.d.ts +105 -0
- package/dist/web.js +135 -0
- package/package.json +10 -2
- package/schemas/connector-template.v1.schema.json +3 -0
- package/schemas/marketplace.v1.schema.json +50 -0
- package/schemas/plugin.v1.schema.json +164 -4
- package/schemas/theme.v1.schema.json +225 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { LocalizedName } from "./plugin-package.js";
|
|
3
|
+
/**
|
|
4
|
+
* Config UI hints (extension config forms spec §3): declarative presentation hints attached to an
|
|
5
|
+
* extension's config schema with {@link ui}, serialized as `x-ui` into the JSON Schema
|
|
6
|
+
* ({@link configJsonSchema}) and drawn by one generic renderer in the web app. Hints never change
|
|
7
|
+
* what validates: the zod schema stays the single source of truth for shape and validation.
|
|
8
|
+
*/
|
|
9
|
+
/** A JSON Schema object (as produced by {@link configJsonSchema}). */
|
|
10
|
+
export type JsonSchema = Record<string, unknown>;
|
|
11
|
+
/** The input widget of a field. */
|
|
12
|
+
export type ConfigWidget = "text" | "textarea" | "url" | "number" | "select" | "radio" | "switch" | "checkbox" | "tristate" | "tags" | "json";
|
|
13
|
+
/** A labelled value of an enum (or boolean) field. */
|
|
14
|
+
export interface ConfigUiOption {
|
|
15
|
+
value: string | number | boolean;
|
|
16
|
+
label: LocalizedName;
|
|
17
|
+
help?: LocalizedName;
|
|
18
|
+
}
|
|
19
|
+
/** A root-level section that fields join with `section`. */
|
|
20
|
+
export interface ConfigUiSection {
|
|
21
|
+
id: string;
|
|
22
|
+
label: LocalizedName;
|
|
23
|
+
help?: LocalizedName;
|
|
24
|
+
}
|
|
25
|
+
/** A prefilled item offered when adding an item to an array of objects. */
|
|
26
|
+
export interface ConfigUiPreset {
|
|
27
|
+
id: string;
|
|
28
|
+
label: LocalizedName;
|
|
29
|
+
help?: LocalizedName;
|
|
30
|
+
/** Prefilled item fields; never a secret. */
|
|
31
|
+
values: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/** A secret drawn inside each item of an array, stored at a fixed record path keyed by an item field. */
|
|
34
|
+
export interface ConfigUiItemSecret {
|
|
35
|
+
/** Dot path, from the schema root, of a `secret(z.record(z.string(), z.string()))` field. */
|
|
36
|
+
path: string;
|
|
37
|
+
/** The item's string field whose value is the record key (e.g. `name`). */
|
|
38
|
+
keyBy: string;
|
|
39
|
+
label: LocalizedName;
|
|
40
|
+
help?: LocalizedName;
|
|
41
|
+
placeholder?: string | LocalizedName;
|
|
42
|
+
/** The item field the input is drawn after (default: last). */
|
|
43
|
+
after?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Presentation hints of one config schema node (zod meta `ui`, JSON Schema `x-ui`). */
|
|
46
|
+
export interface ConfigUiHints {
|
|
47
|
+
label?: LocalizedName;
|
|
48
|
+
help?: LocalizedName;
|
|
49
|
+
placeholder?: string | LocalizedName;
|
|
50
|
+
/** Shown after a number input ("tokens", "ms"). */
|
|
51
|
+
unit?: LocalizedName;
|
|
52
|
+
/** Sort key among siblings (default: declaration order). */
|
|
53
|
+
order?: number;
|
|
54
|
+
/** Root-level section id (`sections` on the root). */
|
|
55
|
+
section?: string;
|
|
56
|
+
/** Collapsed under "Advanced" in its object or item. */
|
|
57
|
+
advanced?: boolean;
|
|
58
|
+
widget?: ConfigWidget;
|
|
59
|
+
options?: ConfigUiOption[];
|
|
60
|
+
/** Objects (and array items): fields stacked (default) or one compact row. */
|
|
61
|
+
layout?: "stack" | "row";
|
|
62
|
+
/** Arrays: how each item is drawn and added. */
|
|
63
|
+
item?: {
|
|
64
|
+
/** `{field}` template from the item's own scalar fields, e.g. "{name}". */
|
|
65
|
+
title?: string;
|
|
66
|
+
subtitle?: string;
|
|
67
|
+
addLabel?: LocalizedName;
|
|
68
|
+
reorder?: boolean;
|
|
69
|
+
};
|
|
70
|
+
presets?: ConfigUiPreset[];
|
|
71
|
+
secrets?: ConfigUiItemSecret[];
|
|
72
|
+
/** Root only. */
|
|
73
|
+
sections?: ConfigUiSection[];
|
|
74
|
+
/** Root only: localized messages for custom issues (`params: { ui: key }`). */
|
|
75
|
+
messages?: Record<string, LocalizedName>;
|
|
76
|
+
}
|
|
77
|
+
/** Limits of config UI hints and of the JSON Schemas a plugin package carries. */
|
|
78
|
+
export declare const CONFIG_UI_LIMITS: {
|
|
79
|
+
/** Characters per language of a `label` (also `unit`, `item.addLabel`). */
|
|
80
|
+
readonly labelChars: 100;
|
|
81
|
+
/** Characters per language of a `help` (also `messages` values). */
|
|
82
|
+
readonly helpChars: 500;
|
|
83
|
+
/** Characters (per language) of a `placeholder`. */
|
|
84
|
+
readonly placeholderChars: 200;
|
|
85
|
+
/** UTF-8 bytes of all `x-ui` JSON of one schema. */
|
|
86
|
+
readonly hintsBytes: number;
|
|
87
|
+
/** Options per node. */
|
|
88
|
+
readonly options: 200;
|
|
89
|
+
/** Presets per node. */
|
|
90
|
+
readonly presets: 20;
|
|
91
|
+
/** Root sections. */
|
|
92
|
+
readonly sections: 20;
|
|
93
|
+
/**
|
|
94
|
+
* UTF-8 bytes of each JSON Schema in `plugin.json` `extension.configSchemas` (96 KiB: two of
|
|
95
|
+
* them must fit in the 256 KiB `plugin.json` text with the rest of the manifest).
|
|
96
|
+
*/
|
|
97
|
+
readonly configSchemaBytes: number;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Attaches config UI hints to a schema (zod meta `ui`), merging with existing meta (`secret`,
|
|
101
|
+
* `hot`, `description`). Returns the same schema type. Convention: put `ui()` outermost, after
|
|
102
|
+
* `.default()` / `.optional()`.
|
|
103
|
+
*/
|
|
104
|
+
export declare function ui<T extends z.ZodTypeAny>(schema: T, hints: ConfigUiHints): T;
|
|
105
|
+
/**
|
|
106
|
+
* An extension config schema as a JSON Schema for forms (the input side, defaults included, no
|
|
107
|
+
* `$schema`):
|
|
108
|
+
* - meta `secret: true` becomes `"x-secret": true`, `hot: true` becomes `"x-hot": true`, `org`
|
|
109
|
+
* (`orgAccess`) becomes `"x-org"`, `ui`
|
|
110
|
+
* becomes `"x-ui"` (a JSON copy of the hints); `title` / `description` are filled from
|
|
111
|
+
* `x-ui.label.en` / `x-ui.help.en` when the node has none;
|
|
112
|
+
* - unrepresentable types become `{ "x-unsupported": true }` instead of throwing;
|
|
113
|
+
* - under a secret node no value is published: `default` / `examples` / `const` / `enum` and
|
|
114
|
+
* `x-ui.options` / `x-ui.presets` are removed from it and all its descendants.
|
|
115
|
+
*/
|
|
116
|
+
export declare function configJsonSchema(schema: z.ZodTypeAny): JsonSchema;
|
|
117
|
+
/** One problem of the hints of a config schema. */
|
|
118
|
+
export interface ConfigUiProblem {
|
|
119
|
+
/**
|
|
120
|
+
* Dot path of the node holding the hint: property names, with `items` / `additionalProperties`
|
|
121
|
+
* for array items and record values (`endpoints.items.models`); `""` is the root.
|
|
122
|
+
*/
|
|
123
|
+
path: string;
|
|
124
|
+
message: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Validates the `x-ui` hints of a JSON Schema produced by {@link configJsonSchema} (spec §3.3) at
|
|
128
|
+
* a config level. Pure; used by the packer, `capybara-plugin check` and the kernel. Returns every
|
|
129
|
+
* problem (empty = valid); never throws. Problem paths are dot paths of the node holding the hint.
|
|
130
|
+
*/
|
|
131
|
+
export declare function validateConfigUi(schema: JsonSchema, level: "deployment" | "org" | "connection"): ConfigUiProblem[];
|