@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
package/dist/theme.js
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CATALOG_ITEM_NAME_RE, isSafePackagePath } from "./plugin-package.js";
|
|
3
|
+
import { checkThemeReadability } from "./theme-readability.js";
|
|
4
|
+
import { THEME_OVERRIDABLE, THEME_TOKENS } from "./theme-tokens.generated.js";
|
|
5
|
+
/**
|
|
6
|
+
* A theme file `themes/<id>.json` (themes spec §4): a partial override of the design tokens per
|
|
7
|
+
* scheme, optional fonts and an optional logo. The id is the file's base name
|
|
8
|
+
* ({@link themeIdOf}, `CATALOG_ITEM_NAME_RE`).
|
|
9
|
+
*
|
|
10
|
+
* {@link parseThemeFile} is the CSS-injection boundary: every token value is parsed against the
|
|
11
|
+
* grammar `tokens.json` uses (`#RRGGBB`, `rgba(r,g,b,a)`, shadows `<x> <y> <blur> [<spread>]
|
|
12
|
+
* <color>`) and re-rendered from its parts in canonical form. Asset paths (`fonts[].file`,
|
|
13
|
+
* `logo.*`) are relative to the plugin root (an optional leading `./`) and every segment is limited
|
|
14
|
+
* to `[A-Za-z0-9._-]`, so they need no escaping inside `url(...)`. Font families are limited to
|
|
15
|
+
* letters, digits, spaces and `-`. Free text (`name`, `description`, `logo.wordmark`) carries no
|
|
16
|
+
* control, format, line / paragraph separator or lone surrogate characters; it is text for the UI,
|
|
17
|
+
* never CSS. Whether the files exist and their size / signature / SVG rules are checked by
|
|
18
|
+
* the reader of the package, with {@link THEME_LIMITS}.
|
|
19
|
+
*
|
|
20
|
+
* The committed JSON Schema (`schemas/theme.v1.schema.json`) is generated from
|
|
21
|
+
* {@link ThemeFileSchema} (the shape only) by `pnpm gen:package-schemas`; token names, value
|
|
22
|
+
* grammar, path safety and readability are decided only by {@link parseThemeFile}.
|
|
23
|
+
*/
|
|
24
|
+
/** Limits of theme files and their assets. */
|
|
25
|
+
export const THEME_LIMITS = {
|
|
26
|
+
/** UTF-8 bytes of one theme file. */
|
|
27
|
+
fileBytes: 64 * 1024,
|
|
28
|
+
/** Themes per plugin. */
|
|
29
|
+
perPlugin: 10,
|
|
30
|
+
/** Total bytes of a plugin's theme assets (fonts and logos). */
|
|
31
|
+
assetsBytes: 16 * 1024 * 1024,
|
|
32
|
+
/** Fonts per theme. */
|
|
33
|
+
fonts: 8,
|
|
34
|
+
/** Bytes of one woff2 font. */
|
|
35
|
+
fontBytes: 2 * 1024 * 1024,
|
|
36
|
+
/** Bytes of a logo SVG. */
|
|
37
|
+
svgBytes: 128 * 1024,
|
|
38
|
+
/** Bytes of a logo PNG. */
|
|
39
|
+
pngBytes: 256 * 1024,
|
|
40
|
+
/** Minimum pixel height of a logo PNG. */
|
|
41
|
+
pngMinHeight: 64,
|
|
42
|
+
/** Characters of the wordmark. */
|
|
43
|
+
wordmark: 24,
|
|
44
|
+
};
|
|
45
|
+
/** `themes/night-city.json` → `night-city`. */
|
|
46
|
+
export function themeIdOf(path) {
|
|
47
|
+
return (path.split("/").pop() ?? "").replace(/\.json$/, "");
|
|
48
|
+
}
|
|
49
|
+
const MAX_ERRORS = 50;
|
|
50
|
+
const FAMILY_RE = /^[A-Za-z0-9 -]{1,64}$/;
|
|
51
|
+
/** Control, format, line / paragraph separator and lone surrogate characters. */
|
|
52
|
+
const FORBIDDEN_CHARS_RE = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Cs}]/u;
|
|
53
|
+
const PATH_SEGMENT_RE = /^[A-Za-z0-9._-]+$/;
|
|
54
|
+
const FORBIDDEN_CHARS_MESSAGE = "must not contain control, format, line / paragraph separator or lone surrogate characters";
|
|
55
|
+
const IMAGE_RE = /\.(?:svg|png)$/i;
|
|
56
|
+
const MAX_VALUE_CHARS = 256;
|
|
57
|
+
const text = (max, what) => z
|
|
58
|
+
.string()
|
|
59
|
+
.min(1)
|
|
60
|
+
.max(max)
|
|
61
|
+
.regex(/\S/, { message: `${what} must not be blank` })
|
|
62
|
+
.refine((t) => !FORBIDDEN_CHARS_RE.test(t), { message: `${what} ${FORBIDDEN_CHARS_MESSAGE}` });
|
|
63
|
+
/** A plugin-root relative path (optional `./`), each segment `[A-Za-z0-9._-]`, no `.` / `..`. */
|
|
64
|
+
const isPlainAssetPath = (p) => {
|
|
65
|
+
const rest = p.replace(/^\.\//, "");
|
|
66
|
+
return (isSafePackagePath(rest) &&
|
|
67
|
+
rest.split("/").every((seg) => PATH_SEGMENT_RE.test(seg) && seg !== "." && seg !== ".."));
|
|
68
|
+
};
|
|
69
|
+
const assetPath = (what, ext, kind) => z
|
|
70
|
+
.string()
|
|
71
|
+
.max(512)
|
|
72
|
+
.refine((p) => isPlainAssetPath(p) && ext.test(p), {
|
|
73
|
+
message: `${what} must be a relative ${kind} path inside the plugin, each segment of letters, digits, ".", "_" or "-"`,
|
|
74
|
+
});
|
|
75
|
+
const tokenValues = z.record(z.string().max(64), z.string().max(MAX_VALUE_CHARS));
|
|
76
|
+
const radius = z.number().int().min(0).max(16);
|
|
77
|
+
const schemeOverride = z.strictObject({
|
|
78
|
+
color: tokenValues.optional(),
|
|
79
|
+
shadow: tokenValues.optional(),
|
|
80
|
+
radius: z
|
|
81
|
+
.strictObject({ sm: radius.optional(), md: radius.optional(), bubble: radius.optional() })
|
|
82
|
+
.optional(),
|
|
83
|
+
});
|
|
84
|
+
const shape = z.strictObject({
|
|
85
|
+
$schema: z.string().max(512).optional(),
|
|
86
|
+
name: z.strictObject({ zh: text(100, "name.zh"), en: text(100, "name.en") }),
|
|
87
|
+
description: z
|
|
88
|
+
.strictObject({
|
|
89
|
+
en: text(1024, "description.en"),
|
|
90
|
+
zh: text(1024, "description.zh").optional(),
|
|
91
|
+
})
|
|
92
|
+
.optional(),
|
|
93
|
+
schemes: z
|
|
94
|
+
.strictObject({ dark: schemeOverride.optional(), light: schemeOverride.optional() })
|
|
95
|
+
.refine((s) => s.dark !== undefined || s.light !== undefined, {
|
|
96
|
+
message: "schemes must define dark, light or both",
|
|
97
|
+
}),
|
|
98
|
+
fonts: z
|
|
99
|
+
.array(z.strictObject({
|
|
100
|
+
family: z.string().regex(FAMILY_RE, {
|
|
101
|
+
message: "family must be 1-64 letters, digits, spaces or '-'",
|
|
102
|
+
}),
|
|
103
|
+
file: assetPath("file", /\.woff2$/i, ".woff2"),
|
|
104
|
+
weight: z.number().int().min(100).max(900),
|
|
105
|
+
style: z.enum(["normal", "italic"]).optional(),
|
|
106
|
+
role: z.enum(["prose", "mono"]),
|
|
107
|
+
}))
|
|
108
|
+
.max(THEME_LIMITS.fonts)
|
|
109
|
+
.optional(),
|
|
110
|
+
logo: z
|
|
111
|
+
.strictObject({
|
|
112
|
+
mark: assetPath("mark", IMAGE_RE, ".svg or .png").optional(),
|
|
113
|
+
wordmark: z
|
|
114
|
+
.string()
|
|
115
|
+
.regex(/\S/, { message: "wordmark must not be blank" })
|
|
116
|
+
.refine((w) => [...w].length <= THEME_LIMITS.wordmark, {
|
|
117
|
+
message: `wordmark must be at most ${THEME_LIMITS.wordmark} characters`,
|
|
118
|
+
})
|
|
119
|
+
.refine((w) => !FORBIDDEN_CHARS_RE.test(w), {
|
|
120
|
+
message: `wordmark ${FORBIDDEN_CHARS_MESSAGE}`,
|
|
121
|
+
})
|
|
122
|
+
.optional(),
|
|
123
|
+
favicon: assetPath("favicon", IMAGE_RE, ".svg or .png").optional(),
|
|
124
|
+
})
|
|
125
|
+
.optional(),
|
|
126
|
+
});
|
|
127
|
+
/**
|
|
128
|
+
* The zod schema of a theme file's shape (strict objects). Token names and values are only
|
|
129
|
+
* strings here; see {@link parseThemeFile}. The JSON Schema is generated with
|
|
130
|
+
* `z.toJSONSchema(ThemeFileSchema, { io: "input" })`.
|
|
131
|
+
*/
|
|
132
|
+
export const ThemeFileSchema = shape;
|
|
133
|
+
const HEX_RE = /^#([0-9A-Fa-f]{6})$/;
|
|
134
|
+
const RGBA_RE = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d{1,4})\s*\)$/;
|
|
135
|
+
const LENGTH_RE = /^(-?)(\d{1,3})(px)?$/;
|
|
136
|
+
/** `#RRGGBB` uppercase or `rgba(r,g,b,a)` rendered from its parts; undefined outside the grammar. */
|
|
137
|
+
function parseColor(v) {
|
|
138
|
+
const hex = HEX_RE.exec(v);
|
|
139
|
+
if (hex)
|
|
140
|
+
return `#${hex[1].toUpperCase()}`;
|
|
141
|
+
const m = RGBA_RE.exec(v);
|
|
142
|
+
if (!m)
|
|
143
|
+
return undefined;
|
|
144
|
+
const ch = [m[1], m[2], m[3]].map(Number);
|
|
145
|
+
if (ch.some((c) => c > 255))
|
|
146
|
+
return undefined;
|
|
147
|
+
return `rgba(${ch.join(",")},${String(Number(m[4]))})`;
|
|
148
|
+
}
|
|
149
|
+
/** A shadow length: `0` or `<n>px` (unitless only for 0), rendered as `0` / `<n>px`. */
|
|
150
|
+
function parseLength(v, allowNegative) {
|
|
151
|
+
const m = LENGTH_RE.exec(v);
|
|
152
|
+
if (!m)
|
|
153
|
+
return undefined;
|
|
154
|
+
const n = Number(m[2]);
|
|
155
|
+
if (n !== 0 && m[3] === undefined)
|
|
156
|
+
return undefined;
|
|
157
|
+
if (n === 0)
|
|
158
|
+
return "0";
|
|
159
|
+
if (m[1] === "-" && !allowNegative)
|
|
160
|
+
return undefined;
|
|
161
|
+
return `${m[1]}${n}px`;
|
|
162
|
+
}
|
|
163
|
+
/** `<x> <y> <blur> [<spread>] <color>`, rendered canonically; undefined outside the grammar. */
|
|
164
|
+
function parseShadow(v) {
|
|
165
|
+
const s = v.trim();
|
|
166
|
+
const at = s.endsWith(")") ? s.lastIndexOf("rgba(") : s.lastIndexOf(" ") + 1;
|
|
167
|
+
if (at <= 0 || !/\s/.test(s.charAt(at - 1)))
|
|
168
|
+
return undefined;
|
|
169
|
+
const color = parseColor(s.slice(at));
|
|
170
|
+
const lengths = s.slice(0, at).trim().split(/\s+/);
|
|
171
|
+
if (color === undefined || lengths.length < 3 || lengths.length > 4)
|
|
172
|
+
return undefined;
|
|
173
|
+
// x, y and spread may be negative; blur may not.
|
|
174
|
+
const parts = lengths.map((l, i) => parseLength(l, i !== 2));
|
|
175
|
+
if (parts.some((p) => p === undefined))
|
|
176
|
+
return undefined;
|
|
177
|
+
return `${parts.join(" ")} ${color}`;
|
|
178
|
+
}
|
|
179
|
+
const SCHEMES = ["dark", "light"];
|
|
180
|
+
const OVERRIDABLE = {
|
|
181
|
+
color: new Set(THEME_OVERRIDABLE.color),
|
|
182
|
+
shadow: new Set(THEME_OVERRIDABLE.shadow),
|
|
183
|
+
};
|
|
184
|
+
const GRAMMAR = {
|
|
185
|
+
color: { parse: parseColor, form: "#RRGGBB or rgba(r,g,b,a)" },
|
|
186
|
+
shadow: {
|
|
187
|
+
parse: parseShadow,
|
|
188
|
+
form: "<x> <y> <blur> [<spread>] <color> with px lengths and a #RRGGBB or rgba(r,g,b,a) color",
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* The canonical form of a token value under the grammar of `group` (the one {@link parseThemeFile}
|
|
193
|
+
* applies), or undefined when `value` is not a string within it. For readers of stored themes that
|
|
194
|
+
* emit values again (the kernel's stylesheet, themes spec §8): a stored value is re-validated
|
|
195
|
+
* before it reaches CSS, so a changed database row cannot inject CSS.
|
|
196
|
+
*/
|
|
197
|
+
export function canonicalThemeValue(group, value) {
|
|
198
|
+
if (typeof value !== "string" || value.length > MAX_VALUE_CHARS)
|
|
199
|
+
return undefined;
|
|
200
|
+
return GRAMMAR[group].parse(value);
|
|
201
|
+
}
|
|
202
|
+
/** Whether `v` is a font family a theme may name: 1-64 letters, digits, spaces or `-`. */
|
|
203
|
+
export function isThemeFontFamily(v) {
|
|
204
|
+
return typeof v === "string" && FAMILY_RE.test(v);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Whether `v` is an asset path a theme may name: plugin-root relative (an optional leading `./`),
|
|
208
|
+
* every segment of `[A-Za-z0-9._-]`, no `.` / `..` segments (the extension is not checked).
|
|
209
|
+
*/
|
|
210
|
+
export function isThemeAssetPath(v) {
|
|
211
|
+
return typeof v === "string" && v.length <= 512 && isPlainAssetPath(v);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Each scheme the theme defines, merged onto the current built-in values (for swatches, the
|
|
215
|
+
* readability check and anything else that needs full values). A stored theme is read leniently:
|
|
216
|
+
* an override whose token name the built-in tokens no longer know (renamed in core), that is not
|
|
217
|
+
* overridable, or whose value falls outside the grammar is skipped, as the stylesheet skips it.
|
|
218
|
+
*/
|
|
219
|
+
export function mergeThemeSchemes(theme) {
|
|
220
|
+
const out = {};
|
|
221
|
+
const schemes = theme?.schemes;
|
|
222
|
+
if (schemes === null || typeof schemes !== "object")
|
|
223
|
+
return out;
|
|
224
|
+
for (const scheme of SCHEMES) {
|
|
225
|
+
const over = schemes[scheme];
|
|
226
|
+
if (over === null || typeof over !== "object")
|
|
227
|
+
continue;
|
|
228
|
+
const m = builtIn(scheme);
|
|
229
|
+
for (const group of ["color", "shadow"]) {
|
|
230
|
+
const values = over[group];
|
|
231
|
+
if (values === null || typeof values !== "object")
|
|
232
|
+
continue;
|
|
233
|
+
for (const [name, raw] of Object.entries(values)) {
|
|
234
|
+
if (!OVERRIDABLE[group].has(name))
|
|
235
|
+
continue;
|
|
236
|
+
const v = canonicalThemeValue(group, raw);
|
|
237
|
+
if (v !== undefined)
|
|
238
|
+
m[group][name] = v;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const radii = over.radius;
|
|
242
|
+
if (radii !== null && typeof radii === "object") {
|
|
243
|
+
for (const key of ["sm", "md", "bubble"]) {
|
|
244
|
+
const v = radii[key];
|
|
245
|
+
if (Number.isInteger(v) && v >= 0 && v <= 16) {
|
|
246
|
+
m.radius[key] = v;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
out[scheme] = m;
|
|
251
|
+
}
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
/** The built-in values of one scheme. */
|
|
255
|
+
function builtIn(scheme) {
|
|
256
|
+
const pick = (group) => Object.fromEntries(Object.entries(group).map(([n, v]) => [n, v[scheme]]));
|
|
257
|
+
return {
|
|
258
|
+
color: pick(THEME_TOKENS.color),
|
|
259
|
+
shadow: pick(THEME_TOKENS.shadow),
|
|
260
|
+
radius: { ...THEME_TOKENS.radius },
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function readJson(json) {
|
|
264
|
+
let text;
|
|
265
|
+
if (typeof json === "string") {
|
|
266
|
+
text = json;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
// An already parsed value is measured by its JSON serialization.
|
|
270
|
+
try {
|
|
271
|
+
text = JSON.stringify(json) ?? "";
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return { errors: ["theme file must be a JSON object"] };
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (new TextEncoder().encode(text).length > THEME_LIMITS.fileBytes) {
|
|
278
|
+
return { errors: [`theme file is larger than ${THEME_LIMITS.fileBytes} bytes`] };
|
|
279
|
+
}
|
|
280
|
+
if (typeof json !== "string")
|
|
281
|
+
return { value: json };
|
|
282
|
+
try {
|
|
283
|
+
return { value: JSON.parse(json.startsWith("\uFEFF") ? json.slice(1) : json) };
|
|
284
|
+
}
|
|
285
|
+
catch (e) {
|
|
286
|
+
const first = (e instanceof Error ? e.message : String(e)).split("\n")[0];
|
|
287
|
+
return { errors: [`theme file is not valid JSON: ${first}`] };
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Parses and validates a theme file: the parsed JSON value or the file text (larger than
|
|
292
|
+
* {@link THEME_LIMITS}`.fileBytes`, measured as text or as the value's JSON, is refused). Checks the id, the shape, token names against
|
|
293
|
+
* the generated allowlist (an unknown or non-overridable name is an error), the value grammar,
|
|
294
|
+
* fonts and logo; then (unless `options.readability` is false) merges every defined scheme onto
|
|
295
|
+
* the built-in tokens ({@link mergeThemeSchemes}) and reports each readability issue as an error
|
|
296
|
+
* starting `unreadable:`. Returned values are canonical (uppercase
|
|
297
|
+
* hex, rgba and shadows re-rendered from their parts). Invalid input returns `{ errors }`
|
|
298
|
+
* (`<path>: <reason>`, English, at most 50); never throws.
|
|
299
|
+
*/
|
|
300
|
+
export function parseThemeFile(id, json, options = {}) {
|
|
301
|
+
if (!CATALOG_ITEM_NAME_RE.test(id)) {
|
|
302
|
+
return { errors: [`theme id "${id}" must match ^[a-z0-9][a-z0-9-]{0,63}$`] };
|
|
303
|
+
}
|
|
304
|
+
const read = readJson(json);
|
|
305
|
+
if ("errors" in read)
|
|
306
|
+
return read;
|
|
307
|
+
const data = read.value;
|
|
308
|
+
if (data === null || typeof data !== "object" || Array.isArray(data)) {
|
|
309
|
+
return { errors: ["theme file must be a JSON object"] };
|
|
310
|
+
}
|
|
311
|
+
const r = shape.safeParse(data);
|
|
312
|
+
if (!r.success) {
|
|
313
|
+
return {
|
|
314
|
+
errors: r.error.issues.slice(0, MAX_ERRORS).map((i) => {
|
|
315
|
+
const path = i.path.map(String).join(".");
|
|
316
|
+
return path ? `${path}: ${i.message}` : i.message;
|
|
317
|
+
}),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
const file = r.data;
|
|
321
|
+
const errors = [];
|
|
322
|
+
const seenFonts = new Set();
|
|
323
|
+
file.fonts?.forEach((f, i) => {
|
|
324
|
+
const key = `${f.family.toLowerCase()}|${f.weight}|${f.style ?? "normal"}|${f.role}`;
|
|
325
|
+
if (seenFonts.has(key)) {
|
|
326
|
+
errors.push(`fonts.${i}: duplicate font ${f.family} ${f.weight} ${f.style ?? "normal"} (${f.role})`);
|
|
327
|
+
}
|
|
328
|
+
seenFonts.add(key);
|
|
329
|
+
});
|
|
330
|
+
const schemes = {};
|
|
331
|
+
for (const scheme of SCHEMES) {
|
|
332
|
+
const over = file.schemes[scheme];
|
|
333
|
+
if (over === undefined)
|
|
334
|
+
continue;
|
|
335
|
+
const out = {};
|
|
336
|
+
// Token names come from the raw object's own keys: the zod record drops `__proto__`.
|
|
337
|
+
const rawScheme = data.schemes[scheme];
|
|
338
|
+
for (const group of ["color", "shadow"]) {
|
|
339
|
+
const values = over[group];
|
|
340
|
+
if (values === undefined)
|
|
341
|
+
continue;
|
|
342
|
+
const rawGroup = rawScheme?.[group];
|
|
343
|
+
const names = rawGroup !== null && typeof rawGroup === "object" ? Object.keys(rawGroup) : [];
|
|
344
|
+
const canonical = {};
|
|
345
|
+
for (const name of names) {
|
|
346
|
+
const path = `schemes.${scheme}.${group}.${name}`;
|
|
347
|
+
if (!OVERRIDABLE[group].has(name)) {
|
|
348
|
+
errors.push(Object.hasOwn(THEME_TOKENS[group], name)
|
|
349
|
+
? `${path}: token ${group}.${name} is not overridable`
|
|
350
|
+
: `${path}: unknown token ${group}.${name}`);
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
const raw = values[name];
|
|
354
|
+
const v = raw === undefined ? undefined : GRAMMAR[group].parse(raw);
|
|
355
|
+
if (v === undefined) {
|
|
356
|
+
errors.push(`${path}: must be ${GRAMMAR[group].form}`);
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
canonical[name] = v;
|
|
360
|
+
}
|
|
361
|
+
out[group] = canonical;
|
|
362
|
+
}
|
|
363
|
+
if (over.radius !== undefined)
|
|
364
|
+
out.radius = { ...over.radius };
|
|
365
|
+
schemes[scheme] = out;
|
|
366
|
+
}
|
|
367
|
+
if (errors.length > 0)
|
|
368
|
+
return { errors: errors.slice(0, MAX_ERRORS) };
|
|
369
|
+
const merged = options.readability === false ? {} : mergeThemeSchemes({ schemes });
|
|
370
|
+
for (const scheme of SCHEMES) {
|
|
371
|
+
const m = merged[scheme];
|
|
372
|
+
if (m === undefined)
|
|
373
|
+
continue;
|
|
374
|
+
for (const issue of checkThemeReadability(scheme, m)) {
|
|
375
|
+
errors.push(issue.kind === "unevaluable"
|
|
376
|
+
? `unreadable: schemes.${scheme}: ${issue.pair} has a value the check cannot evaluate`
|
|
377
|
+
: issue.kind === "separation-order"
|
|
378
|
+
? `unreadable: schemes.${scheme}: ${issue.pair} must stand further from the surface than hover (${issue.ratio.toFixed(1)} ≤ ${issue.floor.toFixed(1)})`
|
|
379
|
+
: `unreadable: schemes.${scheme}: ${issue.pair} ${issue.kind} ${issue.ratio.toFixed(2)} is below ${issue.floor}${issue.detail === undefined ? "" : ` (${issue.detail})`}`);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (errors.length > 0)
|
|
383
|
+
return { errors: errors.slice(0, MAX_ERRORS) };
|
|
384
|
+
const defined = SCHEMES.filter((s) => schemes[s] !== undefined);
|
|
385
|
+
const { $schema: _schema, ...rest } = file;
|
|
386
|
+
return {
|
|
387
|
+
...rest,
|
|
388
|
+
schemes,
|
|
389
|
+
id,
|
|
390
|
+
singleScheme: defined.length === 1 ? defined[0] : null,
|
|
391
|
+
};
|
|
392
|
+
}
|
package/dist/tool.d.ts
CHANGED
|
@@ -72,9 +72,9 @@ export interface ToolResult {
|
|
|
72
72
|
display?: ToolDisplay;
|
|
73
73
|
/**
|
|
74
74
|
* Optional: an inline card under this call in the conversation: `view` is a ui contribution of
|
|
75
|
-
* the same extension
|
|
76
|
-
* (recorded on the `tool_result` event, never in the model's
|
|
77
|
-
* with a warning and the result is kept.
|
|
75
|
+
* the same extension in the `conversation.tool-result.card` slot, rendered with
|
|
76
|
+
* `card: { callId, key }`. Display only (recorded on the `tool_result` event, never in the model's
|
|
77
|
+
* context); an unknown view is dropped with a warning and the result is kept.
|
|
78
78
|
*/
|
|
79
79
|
card?: {
|
|
80
80
|
view: string;
|
|
@@ -129,6 +129,14 @@ export interface ToolCallContext {
|
|
|
129
129
|
state: unknown;
|
|
130
130
|
answer: FormAnswer | null;
|
|
131
131
|
};
|
|
132
|
+
/**
|
|
133
|
+
* The extension's effective deployment config for this org: the platform's deployment config
|
|
134
|
+
* with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
|
|
135
|
+
* platform's config (equal to `ctx.config`) while the org follows it. Use it, not `ctx.config`,
|
|
136
|
+
* for work done for this org. Optional in the type so older extensions compile; the kernel
|
|
137
|
+
* always passes it.
|
|
138
|
+
*/
|
|
139
|
+
config?: unknown;
|
|
132
140
|
}
|
|
133
141
|
export type ToolHandler = (input: unknown, ctx: ToolCallContext) => Promise<ToolResult | InputRequired>;
|
|
134
142
|
/**
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The ARIA / data states a part promises (client extensions spec §7.1). */
|
|
2
|
+
export type UiPartState = "aria-current" | "aria-selected" | "aria-expanded" | "aria-busy" | "disabled";
|
|
3
|
+
/** Every part name of the catalog, in catalog order. */
|
|
4
|
+
export declare const UI_PART_NAMES: readonly ["shell", "sidebar", "sidebar.brand", "sidebar.item", "title-bar", "page-header", "thread", "message.user", "message.assistant", "tool-row", "composer", "properties-panel", "section", "right-panel", "status-bar", "button", "button.primary", "card", "input", "dialog"];
|
|
5
|
+
export type UiPartName = (typeof UI_PART_NAMES)[number];
|
|
6
|
+
/** One built-in element plugin CSS may select with `[data-cap-part~="<name>"]`. */
|
|
7
|
+
export interface UiPartSpec {
|
|
8
|
+
name: UiPartName;
|
|
9
|
+
/** Bumped when the part is renamed, removed or drops a promised state. */
|
|
10
|
+
version: number;
|
|
11
|
+
/**
|
|
12
|
+
* The files (relative to the repository root) that render the element: one concept can be drawn
|
|
13
|
+
* by several components (a sidebar row, a card). `check:ui-parts` pins each literal to one of them.
|
|
14
|
+
*/
|
|
15
|
+
owner: readonly string[];
|
|
16
|
+
states: readonly UiPartState[];
|
|
17
|
+
description: {
|
|
18
|
+
en: string;
|
|
19
|
+
zh: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare const UI_PARTS: readonly UiPartSpec[];
|
|
23
|
+
export declare function uiPart(name: string): UiPartSpec | undefined;
|
package/dist/ui-parts.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/** Every part name of the catalog, in catalog order. */
|
|
2
|
+
export const UI_PART_NAMES = [
|
|
3
|
+
"shell",
|
|
4
|
+
"sidebar",
|
|
5
|
+
"sidebar.brand",
|
|
6
|
+
"sidebar.item",
|
|
7
|
+
"title-bar",
|
|
8
|
+
"page-header",
|
|
9
|
+
"thread",
|
|
10
|
+
"message.user",
|
|
11
|
+
"message.assistant",
|
|
12
|
+
"tool-row",
|
|
13
|
+
"composer",
|
|
14
|
+
"properties-panel",
|
|
15
|
+
"section",
|
|
16
|
+
"right-panel",
|
|
17
|
+
"status-bar",
|
|
18
|
+
"button",
|
|
19
|
+
"button.primary",
|
|
20
|
+
"card",
|
|
21
|
+
"input",
|
|
22
|
+
"dialog",
|
|
23
|
+
];
|
|
24
|
+
export const UI_PARTS = [
|
|
25
|
+
{
|
|
26
|
+
name: "shell",
|
|
27
|
+
version: 1,
|
|
28
|
+
owner: ["packages/design/src/shell/app-shell.tsx"],
|
|
29
|
+
states: [],
|
|
30
|
+
description: {
|
|
31
|
+
en: "The App Shell root.",
|
|
32
|
+
zh: "应用外壳的根节点。",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "sidebar",
|
|
37
|
+
version: 1,
|
|
38
|
+
owner: ["packages/design/src/shell/sidebar.tsx"],
|
|
39
|
+
states: [],
|
|
40
|
+
description: {
|
|
41
|
+
en: "The left sidebar.",
|
|
42
|
+
zh: "左侧边栏。",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "sidebar.brand",
|
|
47
|
+
version: 1,
|
|
48
|
+
owner: ["packages/design/src/shell/sidebar.tsx"],
|
|
49
|
+
states: [],
|
|
50
|
+
description: {
|
|
51
|
+
en: "The brand row of the sidebar.",
|
|
52
|
+
zh: "侧边栏的品牌行。",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "sidebar.item",
|
|
57
|
+
version: 1,
|
|
58
|
+
owner: [
|
|
59
|
+
"packages/design/src/shell/sidebar.tsx",
|
|
60
|
+
"packages/design/src/shell/sidebar-conversations.tsx",
|
|
61
|
+
],
|
|
62
|
+
states: ["aria-current"],
|
|
63
|
+
description: {
|
|
64
|
+
en: "A navigation or conversation row of the sidebar.",
|
|
65
|
+
zh: "侧边栏的导航行或对话行。",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "title-bar",
|
|
70
|
+
version: 1,
|
|
71
|
+
owner: ["packages/design/src/conversation/title-bar.tsx"],
|
|
72
|
+
states: [],
|
|
73
|
+
description: {
|
|
74
|
+
en: "The conversation title bar.",
|
|
75
|
+
zh: "对话标题栏。",
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "page-header",
|
|
80
|
+
version: 1,
|
|
81
|
+
owner: ["packages/design/src/shell/page-header.tsx"],
|
|
82
|
+
states: [],
|
|
83
|
+
description: {
|
|
84
|
+
en: "The header of a page.",
|
|
85
|
+
zh: "页面头部。",
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "thread",
|
|
90
|
+
version: 1,
|
|
91
|
+
owner: ["packages/design/src/templates/conversation-page.tsx"],
|
|
92
|
+
states: ["aria-busy"],
|
|
93
|
+
description: {
|
|
94
|
+
en: "The conversation stream.",
|
|
95
|
+
zh: "对话消息流。",
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: "message.user",
|
|
100
|
+
version: 1,
|
|
101
|
+
owner: ["packages/design/src/conversation/bubble.tsx"],
|
|
102
|
+
states: [],
|
|
103
|
+
description: {
|
|
104
|
+
en: "A person's message.",
|
|
105
|
+
zh: "用户发出的消息。",
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "message.assistant",
|
|
110
|
+
version: 1,
|
|
111
|
+
owner: ["apps/web/src/components/conversation/Thread.tsx"],
|
|
112
|
+
states: [],
|
|
113
|
+
description: {
|
|
114
|
+
en: "An assistant turn.",
|
|
115
|
+
zh: "智能体的一轮回复。",
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: "tool-row",
|
|
120
|
+
version: 1,
|
|
121
|
+
owner: ["packages/design/src/conversation/tool-row.tsx"],
|
|
122
|
+
states: ["aria-expanded"],
|
|
123
|
+
description: {
|
|
124
|
+
en: "A tool call line.",
|
|
125
|
+
zh: "工具调用行。",
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: "composer",
|
|
130
|
+
version: 1,
|
|
131
|
+
owner: ["packages/design/src/conversation/composer.tsx"],
|
|
132
|
+
states: ["aria-busy"],
|
|
133
|
+
description: {
|
|
134
|
+
en: "The composer box.",
|
|
135
|
+
zh: "输入框。",
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "properties-panel",
|
|
140
|
+
version: 1,
|
|
141
|
+
owner: ["packages/design/src/conversation/panels.tsx"],
|
|
142
|
+
states: [],
|
|
143
|
+
description: {
|
|
144
|
+
en: "The conversation properties panel.",
|
|
145
|
+
zh: "对话属性面板。",
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: "section",
|
|
150
|
+
version: 1,
|
|
151
|
+
owner: [
|
|
152
|
+
"packages/design/src/conversation/panels.tsx",
|
|
153
|
+
"packages/design/src/templates/form-page.tsx",
|
|
154
|
+
],
|
|
155
|
+
states: [],
|
|
156
|
+
description: {
|
|
157
|
+
en: "A property section or form section.",
|
|
158
|
+
zh: "属性分区或表单分区。",
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: "right-panel",
|
|
163
|
+
version: 1,
|
|
164
|
+
owner: ["packages/design/src/conversation/panels.tsx"],
|
|
165
|
+
states: [],
|
|
166
|
+
description: {
|
|
167
|
+
en: "A full-height right pane.",
|
|
168
|
+
zh: "占满高度的右侧窗格。",
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
name: "status-bar",
|
|
173
|
+
version: 1,
|
|
174
|
+
owner: ["packages/design/src/shell/status-bar.tsx"],
|
|
175
|
+
states: [],
|
|
176
|
+
description: {
|
|
177
|
+
en: "The status bar.",
|
|
178
|
+
zh: "状态栏。",
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
name: "button",
|
|
183
|
+
version: 1,
|
|
184
|
+
owner: ["packages/design/src/controls/button.tsx"],
|
|
185
|
+
states: ["disabled"],
|
|
186
|
+
description: {
|
|
187
|
+
en: "Every button.",
|
|
188
|
+
zh: "所有按钮。",
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: "button.primary",
|
|
193
|
+
version: 1,
|
|
194
|
+
owner: ["packages/design/src/controls/button.tsx"],
|
|
195
|
+
states: ["disabled"],
|
|
196
|
+
description: {
|
|
197
|
+
en: "A primary button (carried together with `button`).",
|
|
198
|
+
zh: "主按钮(与 button 同时出现)。",
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
name: "card",
|
|
203
|
+
version: 1,
|
|
204
|
+
owner: [
|
|
205
|
+
"packages/design/src/layout/index.tsx",
|
|
206
|
+
"packages/design/src/conversation/panels.tsx",
|
|
207
|
+
"packages/design/src/display/card-grid.tsx",
|
|
208
|
+
],
|
|
209
|
+
states: [],
|
|
210
|
+
description: {
|
|
211
|
+
en: "A card, inline card or object card.",
|
|
212
|
+
zh: "卡片、行内卡片或对象卡片。",
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
name: "input",
|
|
217
|
+
version: 1,
|
|
218
|
+
owner: ["packages/design/src/controls/inputs.tsx", "packages/design/src/controls/select.tsx"],
|
|
219
|
+
states: ["disabled"],
|
|
220
|
+
description: {
|
|
221
|
+
en: "Text inputs, textareas and selects.",
|
|
222
|
+
zh: "文本框、多行文本框和下拉选择。",
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: "dialog",
|
|
227
|
+
version: 1,
|
|
228
|
+
owner: ["packages/design/src/overlays/dialog.tsx", "packages/design/src/overlays/sheet.tsx"],
|
|
229
|
+
states: [],
|
|
230
|
+
description: {
|
|
231
|
+
en: "A dialog or sheet.",
|
|
232
|
+
zh: "对话框或抽屉。",
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
];
|
|
236
|
+
export function uiPart(name) {
|
|
237
|
+
return UI_PARTS.find((p) => p.name === name);
|
|
238
|
+
}
|