@capybara-hq/plugin-sdk 0.1.0-rc.5 → 0.1.0-rc.50
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 +14 -2
- package/agent-docs/concepts.md +14 -5
- package/agent-docs/connector-templates.md +4 -1
- package/agent-docs/extension-points/channel.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/file-preview.md +2 -0
- package/agent-docs/extension-points/model-provider.md +3 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- package/agent-docs/extension-points/push-provider.md +17 -0
- package/agent-docs/extension-points/sandbox.md +2 -2
- package/agent-docs/extensions.md +29 -3
- package/agent-docs/plugin-format.md +48 -2
- package/agent-docs/setup.md +54 -0
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/avatar-presets.d.ts +8 -0
- package/dist/avatar-presets.js +17 -0
- package/dist/bootstrap.d.ts +86 -1
- package/dist/bootstrap.js +161 -2
- package/dist/cards.d.ts +67 -13
- package/dist/cards.js +91 -21
- package/dist/channel.d.ts +148 -48
- package/dist/channel.js +10 -5
- package/dist/client-css.d.ts +36 -0
- package/dist/client-css.js +326 -0
- package/dist/client-section.d.ts +35 -0
- package/dist/client-section.js +133 -0
- package/dist/config-ui.d.ts +22 -0
- package/dist/config-ui.js +64 -4
- package/dist/connector-auth.d.ts +7 -2
- package/dist/connector-auth.js +29 -8
- package/dist/connector.d.ts +74 -32
- package/dist/context.d.ts +40 -0
- package/dist/context.js +2 -0
- package/dist/ctx.d.ts +120 -29
- package/dist/define-extension.d.ts +26 -12
- package/dist/define-extension.js +11 -4
- package/dist/device-denied-paths.d.ts +14 -0
- package/dist/device-denied-paths.js +41 -0
- package/dist/device-protocol.d.ts +489 -0
- package/dist/device-protocol.js +1116 -0
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +6 -2
- package/dist/file-preview.d.ts +23 -6
- package/dist/git-hosts.d.ts +53 -0
- package/dist/git-hosts.js +98 -0
- package/dist/hooks.d.ts +125 -20
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +62 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +38 -9
- package/dist/identity.js +21 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +28 -1
- package/dist/marketplace.d.ts +26 -0
- package/dist/marketplace.js +43 -1
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +206 -71
- package/dist/model.js +152 -19
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/network-classes.d.ts +98 -0
- package/dist/network-classes.js +291 -0
- package/dist/permissions.d.ts +41 -21
- package/dist/permissions.js +101 -42
- package/dist/plugin-manifest.d.ts +45 -5
- package/dist/plugin-manifest.js +169 -6
- package/dist/plugin-package.d.ts +82 -38
- package/dist/plugin-package.js +61 -29
- package/dist/push.d.ts +75 -0
- package/dist/push.js +87 -0
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +2318 -0
- package/dist/sandbox-native-runtime-source.d.ts +10 -0
- package/dist/sandbox-native-runtime-source.js +476 -0
- package/dist/sandbox-operation.d.ts +298 -0
- package/dist/sandbox-operation.js +282 -0
- package/dist/sandbox-runtime-source.d.ts +19 -0
- package/dist/sandbox-runtime-source.js +28 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/sandbox.d.ts +190 -16
- package/dist/sandbox.js +89 -14
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-check.d.ts +128 -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 +96 -0
- package/dist/setup-guide.js +348 -0
- package/dist/shell-capabilities.d.ts +231 -0
- package/dist/shell-capabilities.js +37 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +22 -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 +55 -0
- package/dist/theme-assets.js +507 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +299 -0
- package/dist/theme-tokens.generated.js +184 -0
- package/dist/theme.d.ts +190 -0
- package/dist/theme.js +471 -0
- package/dist/tool.d.ts +69 -26
- package/dist/tool.js +29 -9
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +348 -0
- package/dist/ui-resolve.d.ts +35 -0
- package/dist/ui-resolve.js +42 -0
- package/dist/ui-slots.d.ts +65 -0
- package/dist/ui-slots.js +261 -0
- package/dist/ui.d.ts +212 -76
- package/dist/ui.js +101 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/package.json +8 -1
- package/schemas/bootstrap-extra.v1.schema.json +172 -0
- 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 +116 -3
- package/schemas/theme.v1.schema.json +302 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin setup guides v2 (spec `2026-11-09-setup-guides-v2-design.md`): Markdown documents a plugin
|
|
3
|
+
* ships (`guides/<id>.md`, optional `guides/<id>.zh.md`) that the kernel renders for a place with a
|
|
4
|
+
* fixed set of safe, deterministic variables, mode and audience sections and live check rows. The
|
|
5
|
+
* declaration lives in `plugin.json` `setupGuides` ({@link PluginSetupGuide}); this module holds the
|
|
6
|
+
* place registry, the limits, the validator and the drift hash. The parser is
|
|
7
|
+
* `setup-guide-parse.ts`, the renderer `setup-guide-render.ts`.
|
|
8
|
+
*
|
|
9
|
+
* Variables are `{{name}}` (spaces inside the braces allowed) with `name` matching
|
|
10
|
+
* `[A-Za-z][A-Za-z0-9]*`. There is no other template syntax.
|
|
11
|
+
*/
|
|
12
|
+
import { createHash } from "node:crypto";
|
|
13
|
+
import { analyzeSetupGuide, checkMarkerIndex, ENCODED_SENTINEL_RE, lineSelected, normalizeGuideSource, parseGuideMarkdown, preparedGuideText, SENTINEL_RE, scanGuide, visitGuide, } from "./setup-guide-parse.js";
|
|
14
|
+
/**
|
|
15
|
+
* Where a guide is shown. `channel-connection`: "New channel" and the channel detail page;
|
|
16
|
+
* `connector-template`: the pages of a connector template and the connectors made from it;
|
|
17
|
+
* `extension-deployment`: the super admin's page of the extension, whose checks verify the
|
|
18
|
+
* platform deployment config (a push provider's credentials).
|
|
19
|
+
*/
|
|
20
|
+
export const SETUP_GUIDE_PLACES = [
|
|
21
|
+
"channel-connection",
|
|
22
|
+
"connector-template",
|
|
23
|
+
"extension-deployment",
|
|
24
|
+
];
|
|
25
|
+
const COMMON_VARIABLES = {
|
|
26
|
+
publicUrl: "url",
|
|
27
|
+
orgName: "text",
|
|
28
|
+
pluginName: "token",
|
|
29
|
+
pluginVersion: "token",
|
|
30
|
+
mode: "token",
|
|
31
|
+
};
|
|
32
|
+
/** The place registry. None of the variables is a secret. */
|
|
33
|
+
export const SETUP_GUIDE_PLACE_INFO = {
|
|
34
|
+
"channel-connection": {
|
|
35
|
+
modes: ["long_connection", "webhook"],
|
|
36
|
+
audiences: ["admin"],
|
|
37
|
+
variables: {
|
|
38
|
+
...COMMON_VARIABLES,
|
|
39
|
+
webhookUrl: "url",
|
|
40
|
+
signInCallbackUrl: "url",
|
|
41
|
+
connectionName: "text",
|
|
42
|
+
},
|
|
43
|
+
drift: true,
|
|
44
|
+
},
|
|
45
|
+
"connector-template": {
|
|
46
|
+
modes: [],
|
|
47
|
+
audiences: ["admin", "member"],
|
|
48
|
+
variables: {
|
|
49
|
+
...COMMON_VARIABLES,
|
|
50
|
+
oauthCallbackUrl: "url",
|
|
51
|
+
signInCallbackUrl: "url",
|
|
52
|
+
templateId: "token",
|
|
53
|
+
templateName: "text",
|
|
54
|
+
connectorName: "text",
|
|
55
|
+
},
|
|
56
|
+
drift: true,
|
|
57
|
+
},
|
|
58
|
+
"extension-deployment": {
|
|
59
|
+
modes: [],
|
|
60
|
+
audiences: ["admin"],
|
|
61
|
+
variables: { ...COMMON_VARIABLES, pluginName: "text" },
|
|
62
|
+
drift: false,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
/** Limits of setup guides. */
|
|
66
|
+
export const SETUP_GUIDE_LIMITS = {
|
|
67
|
+
/** Guides per plugin. */
|
|
68
|
+
guides: 8,
|
|
69
|
+
/** Bytes per document (each language). */
|
|
70
|
+
docBytes: 65536,
|
|
71
|
+
/** Fenced code blocks per document. */
|
|
72
|
+
codeBlocks: 24,
|
|
73
|
+
/** Check lines per document. */
|
|
74
|
+
checks: 16,
|
|
75
|
+
/** Sections per document. */
|
|
76
|
+
sections: 16,
|
|
77
|
+
/** Characters of the title and of a heading. */
|
|
78
|
+
titleChars: 100,
|
|
79
|
+
/** Characters of a check label. */
|
|
80
|
+
checkLabelChars: 80,
|
|
81
|
+
/** Characters of a code fence title. */
|
|
82
|
+
fenceTitleChars: 100,
|
|
83
|
+
/** Markdown nesting depth. */
|
|
84
|
+
depth: 16,
|
|
85
|
+
};
|
|
86
|
+
/** The package path of a guide's document: `guides/<id>.md` (en) or `guides/<id>.zh.md` (zh). */
|
|
87
|
+
export function setupGuideDocPath(id, locale) {
|
|
88
|
+
return locale === "zh" ? `guides/${id}.zh.md` : `guides/${id}.md`;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Whether a guide document is usable as a file: present, at most
|
|
92
|
+
* {@link SETUP_GUIDE_LIMITS}`.docBytes`, valid UTF-8 without NUL and without U+E000–U+E0FF. The
|
|
93
|
+
* problem (English, naming the path), or undefined. Shared by the packer and the kernel's reader.
|
|
94
|
+
*/
|
|
95
|
+
export function setupGuideDocProblem(path, data) {
|
|
96
|
+
if (data === undefined)
|
|
97
|
+
return `${path} not found in the package`;
|
|
98
|
+
if (data.byteLength > SETUP_GUIDE_LIMITS.docBytes) {
|
|
99
|
+
return `${path} is larger than ${SETUP_GUIDE_LIMITS.docBytes} bytes`;
|
|
100
|
+
}
|
|
101
|
+
let text;
|
|
102
|
+
try {
|
|
103
|
+
text = new TextDecoder("utf-8", { fatal: true }).decode(data);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return `${path} is not valid UTF-8 text`;
|
|
107
|
+
}
|
|
108
|
+
if (text.includes("\u0000"))
|
|
109
|
+
return `${path} is not a text file (it contains NUL)`;
|
|
110
|
+
if (/[-]/.test(text)) {
|
|
111
|
+
return `${path} contains a private-use character (U+E000–U+E0FF), which guides may not use`;
|
|
112
|
+
}
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
const QUOTING_LANGUAGES = new Set(["yaml", "yml", "json"]);
|
|
116
|
+
const firstUrlSentinel = /^(?:|%EE%80%80)(\d+)(?:|%EE%80%81)/i;
|
|
117
|
+
const hasSentinel = (s) => s !== null &&
|
|
118
|
+
s !== undefined &&
|
|
119
|
+
(new RegExp(SENTINEL_RE.source).test(s) || new RegExp(ENCODED_SENTINEL_RE.source, "i").test(s));
|
|
120
|
+
const sentinelIndexes = (s) => [
|
|
121
|
+
...[...s.matchAll(SENTINEL_RE)].map((m) => Number(m[1])),
|
|
122
|
+
...[...s.matchAll(ENCODED_SENTINEL_RE)].map((m) => Number(m[1])),
|
|
123
|
+
];
|
|
124
|
+
/**
|
|
125
|
+
* Validates a guide's documents for a place (spec §4.5): title, sections well formed and known to
|
|
126
|
+
* the place, check lines, fence info strings, no indented code, limits, variables known to the place
|
|
127
|
+
* and allowed where they stand (§6.2), language parity of the zh document (§4.3), and, when
|
|
128
|
+
* `pluginChecks` is given, that every plugin check id is declared there (the extension's
|
|
129
|
+
* `permissions.setupChecks`). Messages name the file (`guides/<id>.md` when `id` is given) and line.
|
|
130
|
+
* `allowUnknownVariables` (the kernel's importer) accepts variables the place does not define: they
|
|
131
|
+
* render as written. Pure.
|
|
132
|
+
*/
|
|
133
|
+
export function validateSetupGuide(input) {
|
|
134
|
+
const info = SETUP_GUIDE_PLACE_INFO[input.place];
|
|
135
|
+
const fileOf = (locale) => input.id !== undefined
|
|
136
|
+
? setupGuideDocPath(input.id, locale)
|
|
137
|
+
: locale === "en"
|
|
138
|
+
? "the English document"
|
|
139
|
+
: "the Chinese document";
|
|
140
|
+
const out = [];
|
|
141
|
+
const parsedBy = {};
|
|
142
|
+
const one = (locale, source) => {
|
|
143
|
+
const file = fileOf(locale);
|
|
144
|
+
const push = (i) => out.push({
|
|
145
|
+
level: i.level,
|
|
146
|
+
message: i.line !== undefined ? `${file}:${i.line}: ${i.message}` : `${file}: ${i.message}`,
|
|
147
|
+
});
|
|
148
|
+
const bytes = new TextEncoder().encode(source).byteLength;
|
|
149
|
+
if (bytes > SETUP_GUIDE_LIMITS.docBytes) {
|
|
150
|
+
push({ level: "error", message: `is larger than ${SETUP_GUIDE_LIMITS.docBytes} bytes` });
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const { parsed, scan, tree, uses } = analyzeSetupGuide(source);
|
|
154
|
+
parsedBy[locale] = parsed;
|
|
155
|
+
const issues = [...parsed.issues];
|
|
156
|
+
const err = (line, message, level = "error") => issues.push({ level, ...(line !== undefined && { line }), message });
|
|
157
|
+
for (const s of parsed.sections) {
|
|
158
|
+
if (s.type === "mode" && !info.modes.includes(s.value)) {
|
|
159
|
+
err(s.line, info.modes.length === 0
|
|
160
|
+
? `place ${input.place} has no modes`
|
|
161
|
+
: `mode "${s.value}" is not one of the modes of place ${input.place}: ${info.modes.join(", ")}`);
|
|
162
|
+
}
|
|
163
|
+
if (s.type === "audience" && !info.audiences.includes(s.value)) {
|
|
164
|
+
err(s.line, `audience "${s.value}" is not one of the audiences of place ${input.place}: ${info.audiences.join(", ")}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (input.pluginChecks !== undefined) {
|
|
168
|
+
for (const c of parsed.checks) {
|
|
169
|
+
if (c.source === "plugin" && !input.pluginChecks.includes(c.id)) {
|
|
170
|
+
err(c.line, `check ${c.id} is not declared in the extension's permissions.setupChecks`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// a check id twice in one rendering
|
|
175
|
+
const dupes = new Set();
|
|
176
|
+
for (const mode of [null, ...info.modes]) {
|
|
177
|
+
for (const audience of info.audiences) {
|
|
178
|
+
const seen = new Set();
|
|
179
|
+
parsed.checks.forEach((c) => {
|
|
180
|
+
if (!lineSelected(scan, c.line - 1, mode, audience))
|
|
181
|
+
return;
|
|
182
|
+
if (seen.has(c.id) && !dupes.has(c.id)) {
|
|
183
|
+
dupes.add(c.id);
|
|
184
|
+
err(c.line, `check ${c.id} appears twice in one rendering of the guide`);
|
|
185
|
+
}
|
|
186
|
+
seen.add(c.id);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// variables: known to the place, and allowed where they stand
|
|
191
|
+
const reported = new Set();
|
|
192
|
+
for (const u of uses) {
|
|
193
|
+
if (Object.hasOwn(info.variables, u.name) || input.allowUnknownVariables === true)
|
|
194
|
+
continue;
|
|
195
|
+
if (reported.has(u.name))
|
|
196
|
+
continue;
|
|
197
|
+
reported.add(u.name);
|
|
198
|
+
err(u.line, `unknown variable {{${u.name}}} for place ${input.place} (known: ${Object.keys(info.variables).join(", ")})`);
|
|
199
|
+
}
|
|
200
|
+
const typeOf = (n) => {
|
|
201
|
+
const name = uses[n]?.name;
|
|
202
|
+
return name === undefined ? undefined : info.variables[name];
|
|
203
|
+
};
|
|
204
|
+
const nameOf = (n) => `{{${uses[n]?.name ?? "?"}}}`;
|
|
205
|
+
const checkDestination = (url, line) => {
|
|
206
|
+
const all = sentinelIndexes(url);
|
|
207
|
+
if (all.length === 0)
|
|
208
|
+
return;
|
|
209
|
+
const m = firstUrlSentinel.exec(url);
|
|
210
|
+
const ok = m !== null && all.length === 1 && typeOf(Number(m[1])) === "url";
|
|
211
|
+
if (!ok) {
|
|
212
|
+
err(line, `${all.map(nameOf).join(", ")} in a link destination: only a url variable may stand there, at its start`);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
visitGuide(tree, (node) => {
|
|
216
|
+
const line = node.position?.start.line;
|
|
217
|
+
switch (node.type) {
|
|
218
|
+
case "code": {
|
|
219
|
+
const lang = (node.lang ?? "").toLowerCase();
|
|
220
|
+
if (QUOTING_LANGUAGES.has(lang)) {
|
|
221
|
+
// values are JSON-escaped without the quotes: only safe inside a "…" string
|
|
222
|
+
for (const lineText of node.value.split("\n")) {
|
|
223
|
+
for (const m of lineText.matchAll(SENTINEL_RE)) {
|
|
224
|
+
const n = Number(m[1]);
|
|
225
|
+
if (typeOf(n) !== "text")
|
|
226
|
+
continue;
|
|
227
|
+
const before = lineText.slice(0, m.index).replace(/\\./g, "");
|
|
228
|
+
if ((before.match(/"/g)?.length ?? 0) % 2 === 1)
|
|
229
|
+
continue;
|
|
230
|
+
err(line, `the text variable ${nameOf(n)} in a ${lang} code block is not inside double quotes; its value is escaped as a string and may break the block or change its type ("${nameOf(n)}")`, "warning");
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
for (const n of sentinelIndexes(node.value)) {
|
|
236
|
+
if (typeOf(n) === "text") {
|
|
237
|
+
err(line, `the text variable ${nameOf(n)} in a ${lang || "plain"} code block is not quoted; a value with spaces or quotes may break it (use a yaml or json block with "${nameOf(n)}")`, "warning");
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
case "link":
|
|
243
|
+
case "definition":
|
|
244
|
+
checkDestination(node.url, line);
|
|
245
|
+
if (hasSentinel(node.title))
|
|
246
|
+
err(line, "variables are not allowed in a link title");
|
|
247
|
+
return;
|
|
248
|
+
case "image":
|
|
249
|
+
case "imageReference":
|
|
250
|
+
if (hasSentinel(node.alt) ||
|
|
251
|
+
(node.type === "image" && (hasSentinel(node.url) || hasSentinel(node.title)))) {
|
|
252
|
+
err(line, "variables are not allowed in an image");
|
|
253
|
+
}
|
|
254
|
+
return;
|
|
255
|
+
default:
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
issues.sort((a, b) => (a.line ?? 0) - (b.line ?? 0));
|
|
260
|
+
issues.forEach(push);
|
|
261
|
+
};
|
|
262
|
+
one("en", input.en);
|
|
263
|
+
if (input.zh !== undefined)
|
|
264
|
+
one("zh", input.zh);
|
|
265
|
+
const en = parsedBy.en;
|
|
266
|
+
const zh = parsedBy.zh;
|
|
267
|
+
if (en !== undefined && zh !== undefined) {
|
|
268
|
+
const enFile = fileOf("en");
|
|
269
|
+
const zhFile = fileOf("zh");
|
|
270
|
+
const sec = (p) => JSON.stringify(p.sections.map((s) => [s.type, s.value, s.parent]));
|
|
271
|
+
if (sec(en) !== sec(zh)) {
|
|
272
|
+
out.push({
|
|
273
|
+
level: "error",
|
|
274
|
+
message: `${zhFile}: the sections differ from ${enFile}; both languages need the same sections in the same order`,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
const chk = (p) => JSON.stringify(p.checks.map((c) => [c.section, c.id]));
|
|
278
|
+
if (chk(en) !== chk(zh)) {
|
|
279
|
+
out.push({
|
|
280
|
+
level: "error",
|
|
281
|
+
message: `${zhFile}: the checks differ from ${enFile}; both languages need the same check ids in the same sections`,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
if (en.codeBlocks.length !== zh.codeBlocks.length) {
|
|
285
|
+
out.push({
|
|
286
|
+
level: "error",
|
|
287
|
+
message: `${zhFile}: has ${zh.codeBlocks.length} code blocks and ${enFile} has ${en.codeBlocks.length}; code blocks must be identical in every language`,
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
en.codeBlocks.forEach((e, i) => {
|
|
292
|
+
const z = zh.codeBlocks[i];
|
|
293
|
+
if (z === undefined)
|
|
294
|
+
return;
|
|
295
|
+
const n = i + 1;
|
|
296
|
+
const name = `code block ${n}${z.title !== null ? ` ("${z.title}")` : ""}`;
|
|
297
|
+
if (z.section !== e.section) {
|
|
298
|
+
out.push({
|
|
299
|
+
level: "error",
|
|
300
|
+
message: `${zhFile}: ${name} is in another section than ${enFile} block ${n}; code blocks must be identical in every language`,
|
|
301
|
+
});
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (z.language === e.language && z.text === e.text)
|
|
305
|
+
return;
|
|
306
|
+
if (z.language !== e.language) {
|
|
307
|
+
out.push({
|
|
308
|
+
level: "error",
|
|
309
|
+
message: `${zhFile}: ${name} is ${z.language || "without a language"} but ${enFile} block ${n} is ${e.language || "without a language"}; code blocks must be identical in every language`,
|
|
310
|
+
});
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const el = e.text.split("\n");
|
|
314
|
+
const zl = z.text.split("\n");
|
|
315
|
+
let line = 0;
|
|
316
|
+
while (line < el.length && line < zl.length && el[line] === zl[line])
|
|
317
|
+
line++;
|
|
318
|
+
out.push({
|
|
319
|
+
level: "error",
|
|
320
|
+
message: `${zhFile}: ${name} differs from ${enFile} block ${n} at line ${line + 1}; code blocks must be identical in every language`,
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* The drift hash of a guide for one mode and audience (spec §11): sha256 (hex) over the place, guide
|
|
329
|
+
* id, mode and audience, then, in document order after section selection, each fenced code block
|
|
330
|
+
* (language and text, title excluded) and each check id of the English document. Variables are not
|
|
331
|
+
* substituted; line endings are normalized. Prose, headings and check labels do not move it.
|
|
332
|
+
*/
|
|
333
|
+
export function setupGuideHash(enSource, input) {
|
|
334
|
+
const scan = scanGuide(normalizeGuideSource(enSource));
|
|
335
|
+
const tree = parseGuideMarkdown(preparedGuideText(scan, (i) => lineSelected(scan, i, input.mode, input.audience)));
|
|
336
|
+
const h = createHash("sha256");
|
|
337
|
+
h.update(`capybara-guide-v2\0${input.place}\0${input.guideId}\0${input.mode ?? ""}\0${input.audience}\0`);
|
|
338
|
+
visitGuide(tree, (node) => {
|
|
339
|
+
if (node.type === "code") {
|
|
340
|
+
h.update(`code\0${node.lang ?? ""}\0${node.value}\0`);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const c = checkMarkerIndex(node);
|
|
344
|
+
if (c !== undefined)
|
|
345
|
+
h.update(`check\0${scan.checks[c]?.id ?? ""}\0`);
|
|
346
|
+
});
|
|
347
|
+
return h.digest("hex");
|
|
348
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import type { PushPlatform } from "./push.js";
|
|
2
|
+
/**
|
|
3
|
+
* Desktop shell capabilities (desktop client spec §8): the shapes of the objects a desktop shell
|
|
4
|
+
* puts in `window.capybaraShell.capabilities` under the keys of `SHELL_CAPABILITY_KEYS`. Types and
|
|
5
|
+
* key constants only; `capybara-hq/clients` implements them. A rejected call carries
|
|
6
|
+
* `{ code: ShellCallError }`.
|
|
7
|
+
*/
|
|
8
|
+
/** Capability keys, `name@major`; each value is a key of `SHELL_CAPABILITIES`. */
|
|
9
|
+
export declare const SHELL_CAPABILITY_KEYS: {
|
|
10
|
+
readonly chrome: "chrome@1";
|
|
11
|
+
readonly device: "device@1";
|
|
12
|
+
readonly notify: "notify@1";
|
|
13
|
+
readonly openExternal: "openExternal@1";
|
|
14
|
+
readonly signIn: "signIn@1";
|
|
15
|
+
readonly haptics: "haptics@1";
|
|
16
|
+
readonly share: "share@1";
|
|
17
|
+
readonly menu: "menu@1";
|
|
18
|
+
readonly nav: "nav@1";
|
|
19
|
+
readonly profiles: "profiles@1";
|
|
20
|
+
readonly push: "push@1";
|
|
21
|
+
};
|
|
22
|
+
export type KeepAwakeMode = "off" | "while-busy" | "connected";
|
|
23
|
+
export type DeviceConnection = "starting" | "online" | "offline" | "draining" | "stopped";
|
|
24
|
+
/** What this machine is to the deployment the shell shows. */
|
|
25
|
+
export type ThisMachineStatus = {
|
|
26
|
+
state: "not_connected";
|
|
27
|
+
} | {
|
|
28
|
+
state: "connected_elsewhere";
|
|
29
|
+
origin: string;
|
|
30
|
+
} | {
|
|
31
|
+
state: "connected";
|
|
32
|
+
deviceId: string;
|
|
33
|
+
orgId: string;
|
|
34
|
+
mode: "os" | "docker";
|
|
35
|
+
connection: DeviceConnection;
|
|
36
|
+
offlineReason?: string;
|
|
37
|
+
serviceInstalled: boolean;
|
|
38
|
+
keepAwake: {
|
|
39
|
+
mode: KeepAwakeMode;
|
|
40
|
+
held: boolean;
|
|
41
|
+
unavailable?: string;
|
|
42
|
+
};
|
|
43
|
+
lastWakeAt?: string;
|
|
44
|
+
};
|
|
45
|
+
/** One operation running on this machine for the deployment. */
|
|
46
|
+
export interface RunningOperationView {
|
|
47
|
+
tag: string;
|
|
48
|
+
conversationId: string | null;
|
|
49
|
+
accountId: string | null;
|
|
50
|
+
isolation: "restricted" | "full";
|
|
51
|
+
startedAt: string;
|
|
52
|
+
}
|
|
53
|
+
/** The `code` of a rejected shell call. */
|
|
54
|
+
export type ShellCallError = "busy" | "no_activation" | "cancelled" | "failed";
|
|
55
|
+
/**
|
|
56
|
+
* A change to this machine's owner ceiling, as `capybara-device ceiling set` takes it
|
|
57
|
+
* (`--outside-sandbox on|off`, `--network open|allowlist`, `--project-reach workspace|os-user`):
|
|
58
|
+
* only the fields to change. A field left out is never touched, so a stale value on the page can
|
|
59
|
+
* never narrow it. A widening needs the shell's native confirmation; a narrowing applies at once.
|
|
60
|
+
*/
|
|
61
|
+
export interface DeviceCeilingRequest {
|
|
62
|
+
outsideSandbox?: boolean;
|
|
63
|
+
network?: "open" | "allowlist";
|
|
64
|
+
projectReach?: "workspace" | "os-user";
|
|
65
|
+
}
|
|
66
|
+
/** `device@1`: connect this machine to the deployment as a device. */
|
|
67
|
+
export interface DeviceCapabilityV1 {
|
|
68
|
+
status(): Promise<ThisMachineStatus>;
|
|
69
|
+
onStatus(listener: (s: ThisMachineStatus) => void): () => void;
|
|
70
|
+
running(): Promise<RunningOperationView[]>;
|
|
71
|
+
connect(input: {
|
|
72
|
+
orgId: string;
|
|
73
|
+
deviceId?: string;
|
|
74
|
+
}): Promise<"connected" | "cancelled">;
|
|
75
|
+
pause(): Promise<void>;
|
|
76
|
+
resume(): Promise<"resumed" | "cancelled">;
|
|
77
|
+
disconnect(): Promise<void>;
|
|
78
|
+
requestCeiling(input: DeviceCeilingRequest): Promise<"applied" | "cancelled">;
|
|
79
|
+
setKeepAwake(mode: KeepAwakeMode): Promise<"applied" | "cancelled">;
|
|
80
|
+
}
|
|
81
|
+
/** `notify@1`: a native notification; `path` is the in-app path opened on click. */
|
|
82
|
+
export interface NotifyCapabilityV1 {
|
|
83
|
+
notify(input: {
|
|
84
|
+
title: string;
|
|
85
|
+
body: string;
|
|
86
|
+
path?: string;
|
|
87
|
+
}): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
/** `openExternal@1`: open a URL in the system browser. */
|
|
90
|
+
export interface OpenExternalCapabilityV1 {
|
|
91
|
+
open(url: string): Promise<void>;
|
|
92
|
+
}
|
|
93
|
+
/** `signIn@1`: sign in through the system browser (desktop client spec §6.5). */
|
|
94
|
+
export interface SignInCapabilityV1 {
|
|
95
|
+
start(): Promise<"signedIn" | "cancelled">;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The page's main color tokens (the computed `--cb-bg`, `--cb-panel`, `--cb-ink`, `--cb-muted`,
|
|
99
|
+
* `--cb-line`, `--cb-accent`, `--cb-on-accent`), each a CSS hex or `rgb()` / `rgba()` color. The
|
|
100
|
+
* shell validates them and uses them only as custom properties of its own pages, never as markup.
|
|
101
|
+
*/
|
|
102
|
+
export interface ShellChromeTokens {
|
|
103
|
+
bg: string;
|
|
104
|
+
panel: string;
|
|
105
|
+
ink: string;
|
|
106
|
+
muted: string;
|
|
107
|
+
line: string;
|
|
108
|
+
accent: string;
|
|
109
|
+
onAccent: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* `chrome@1` (mobile layout spec §9.2): the native chrome (window background, title bar, the
|
|
113
|
+
* shell's own pages) follows the page's theme. `tokens` is sent only when all seven are colors;
|
|
114
|
+
* `singleScheme` is true under a UI theme with one scheme (no light / dark toggle on either side).
|
|
115
|
+
*/
|
|
116
|
+
export interface ChromeCapabilityV1 {
|
|
117
|
+
setAppearance(input: {
|
|
118
|
+
scheme: "light" | "dark";
|
|
119
|
+
background: string;
|
|
120
|
+
tokens?: ShellChromeTokens;
|
|
121
|
+
singleScheme?: boolean;
|
|
122
|
+
}): Promise<void>;
|
|
123
|
+
/** The web's first paint is done (mobile app spec §5.2); a shell may leave it out. */
|
|
124
|
+
ready?(): Promise<void>;
|
|
125
|
+
}
|
|
126
|
+
export type HapticKind = "selection" | "light" | "success" | "warning";
|
|
127
|
+
/** `haptics@1`: a haptic impact (mobile app spec §5.2). */
|
|
128
|
+
export interface HapticsCapabilityV1 {
|
|
129
|
+
impact(kind: HapticKind): Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
export interface ShareInputV1 {
|
|
132
|
+
title?: string;
|
|
133
|
+
text?: string;
|
|
134
|
+
url?: string;
|
|
135
|
+
}
|
|
136
|
+
/** `share@1`: the system share sheet; resolves whether shared or dismissed. */
|
|
137
|
+
export interface ShareCapabilityV1 {
|
|
138
|
+
share(input: ShareInputV1): Promise<void>;
|
|
139
|
+
}
|
|
140
|
+
export interface MenuItemV1 {
|
|
141
|
+
id: string;
|
|
142
|
+
label: string;
|
|
143
|
+
destructive?: boolean;
|
|
144
|
+
disabled?: boolean;
|
|
145
|
+
}
|
|
146
|
+
export interface MenuInputV1 {
|
|
147
|
+
title?: string;
|
|
148
|
+
items: MenuItemV1[];
|
|
149
|
+
/** A rect in CSS px from the web view's top-left corner. */
|
|
150
|
+
anchor?: {
|
|
151
|
+
x: number;
|
|
152
|
+
y: number;
|
|
153
|
+
width: number;
|
|
154
|
+
height: number;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/** `menu@1`: a native menu; resolves the chosen item id, or null when dismissed. */
|
|
158
|
+
export interface MenuCapabilityV1 {
|
|
159
|
+
show(input: MenuInputV1): Promise<string | null>;
|
|
160
|
+
}
|
|
161
|
+
/** The shell validates every input against these (and the web keeps within them). */
|
|
162
|
+
export declare const MOBILE_SHELL_LIMITS: {
|
|
163
|
+
readonly menuItems: 12;
|
|
164
|
+
readonly menuLabel: 64;
|
|
165
|
+
readonly menuTitle: 128;
|
|
166
|
+
readonly shareTitle: 256;
|
|
167
|
+
readonly shareText: 4000;
|
|
168
|
+
readonly url: 2048;
|
|
169
|
+
/** `nav@1`: a section or menu label is 1..32 characters. */
|
|
170
|
+
readonly navLabel: 32;
|
|
171
|
+
/** `nav@1`: a badge count is an integer 0..9999 (`countMore` says there are more). */
|
|
172
|
+
readonly navCount: 9999;
|
|
173
|
+
};
|
|
174
|
+
/** The menu item id pattern, checked on `menu@1.show` (the shell validates every input). */
|
|
175
|
+
export declare const MENU_ITEM_ID: RegExp;
|
|
176
|
+
export type NavSectionId = "chats" | "inbox" | "agents" | "schedules";
|
|
177
|
+
/** The strip's sections in display order. */
|
|
178
|
+
export declare const NAV_SECTION_ORDER: readonly NavSectionId[];
|
|
179
|
+
export interface NavBadgeV1 {
|
|
180
|
+
count?: number;
|
|
181
|
+
countMore?: boolean;
|
|
182
|
+
}
|
|
183
|
+
export interface NavItemV1 extends NavBadgeV1 {
|
|
184
|
+
id: NavSectionId;
|
|
185
|
+
label: string;
|
|
186
|
+
}
|
|
187
|
+
export interface NavMenuV1 extends NavBadgeV1 {
|
|
188
|
+
label: string;
|
|
189
|
+
}
|
|
190
|
+
export interface NavStateV1 {
|
|
191
|
+
/** The sections the person sees, in NAV_SECTION_ORDER (a guest has no `schedules`). */
|
|
192
|
+
items: NavItemV1[];
|
|
193
|
+
current: NavSectionId | null;
|
|
194
|
+
/** The strip's menu button, or null for none (non-null while the web's class is compact). */
|
|
195
|
+
menu: NavMenuV1 | null;
|
|
196
|
+
}
|
|
197
|
+
/** `nav@1`: offered only while the window has a strip (mobile app spec §6.1): presence is visibility. */
|
|
198
|
+
export interface NavCapabilityV1 {
|
|
199
|
+
set(state: NavStateV1): Promise<void>;
|
|
200
|
+
onSelect(listener: (id: NavSectionId) => void): () => void;
|
|
201
|
+
onMenu(listener: () => void): () => void;
|
|
202
|
+
}
|
|
203
|
+
/** `profiles@1`: the native profile switcher. */
|
|
204
|
+
export interface ProfilesCapabilityV1 {
|
|
205
|
+
/** Opens the native profile switcher; resolves when it closes, with nothing. */
|
|
206
|
+
show(): Promise<void>;
|
|
207
|
+
}
|
|
208
|
+
export type PushPermission = "granted" | "denied" | "prompt";
|
|
209
|
+
export interface PushStatus {
|
|
210
|
+
permission: PushPermission;
|
|
211
|
+
/** The server-side registration id this install holds, or null. */
|
|
212
|
+
registrationId: string | null;
|
|
213
|
+
/** The OS token differs from the one last registered. */
|
|
214
|
+
tokenChanged: boolean;
|
|
215
|
+
}
|
|
216
|
+
/** What the shell hands the web app to register with the deployment. */
|
|
217
|
+
export interface PushRegistration {
|
|
218
|
+
platform: PushPlatform;
|
|
219
|
+
appId: string;
|
|
220
|
+
provider: string;
|
|
221
|
+
token: string;
|
|
222
|
+
}
|
|
223
|
+
/** `push@1`: native push registration (mobile shells). */
|
|
224
|
+
export interface PushCapabilityV1 {
|
|
225
|
+
status(): Promise<PushStatus>;
|
|
226
|
+
/** User activation only when permission is "prompt"; rejects { code: "cancelled" } when denied. */
|
|
227
|
+
register(): Promise<PushRegistration>;
|
|
228
|
+
/** Tells the shell the deployment's registration id for this install. */
|
|
229
|
+
registered(id: string): Promise<void>;
|
|
230
|
+
unregister(): Promise<void>;
|
|
231
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Desktop shell capabilities (desktop client spec §8): the shapes of the objects a desktop shell
|
|
3
|
+
* puts in `window.capybaraShell.capabilities` under the keys of `SHELL_CAPABILITY_KEYS`. Types and
|
|
4
|
+
* key constants only; `capybara-hq/clients` implements them. A rejected call carries
|
|
5
|
+
* `{ code: ShellCallError }`.
|
|
6
|
+
*/
|
|
7
|
+
/** Capability keys, `name@major`; each value is a key of `SHELL_CAPABILITIES`. */
|
|
8
|
+
export const SHELL_CAPABILITY_KEYS = {
|
|
9
|
+
chrome: "chrome@1",
|
|
10
|
+
device: "device@1",
|
|
11
|
+
notify: "notify@1",
|
|
12
|
+
openExternal: "openExternal@1",
|
|
13
|
+
signIn: "signIn@1",
|
|
14
|
+
haptics: "haptics@1",
|
|
15
|
+
share: "share@1",
|
|
16
|
+
menu: "menu@1",
|
|
17
|
+
nav: "nav@1",
|
|
18
|
+
profiles: "profiles@1",
|
|
19
|
+
push: "push@1",
|
|
20
|
+
};
|
|
21
|
+
/** The shell validates every input against these (and the web keeps within them). */
|
|
22
|
+
export const MOBILE_SHELL_LIMITS = {
|
|
23
|
+
menuItems: 12,
|
|
24
|
+
menuLabel: 64,
|
|
25
|
+
menuTitle: 128,
|
|
26
|
+
shareTitle: 256,
|
|
27
|
+
shareText: 4000,
|
|
28
|
+
url: 2048,
|
|
29
|
+
/** `nav@1`: a section or menu label is 1..32 characters. */
|
|
30
|
+
navLabel: 32,
|
|
31
|
+
/** `nav@1`: a badge count is an integer 0..9999 (`countMore` says there are more). */
|
|
32
|
+
navCount: 9999,
|
|
33
|
+
};
|
|
34
|
+
/** The menu item id pattern, checked on `menu@1.show` (the shell validates every input). */
|
|
35
|
+
export const MENU_ITEM_ID = /^[A-Za-z0-9_.-]{1,64}$/;
|
|
36
|
+
/** The strip's sections in display order. */
|
|
37
|
+
export const NAV_SECTION_ORDER = ["chats", "inbox", "agents", "schedules"];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell environment (mobile layout spec §9, desktop client spec): the contract of the global a
|
|
3
|
+
* native shell injects as `window.capybaraShell`, only into the top frame of the deployment's
|
|
4
|
+
* origin. Types and the capability registry only; `capybara-hq/clients` implements it.
|
|
5
|
+
*/
|
|
6
|
+
export interface CapybaraShell {
|
|
7
|
+
/** The envelope version; bumped only on an incompatible change of this shape. */
|
|
8
|
+
readonly version: 1;
|
|
9
|
+
/** Which shell: drives nothing but the shell attributes. */
|
|
10
|
+
readonly kind: "desktop" | "mobile";
|
|
11
|
+
/** The operating system, for platform conventions only (traffic lights, back gesture). */
|
|
12
|
+
readonly platform: "macos" | "windows" | "linux" | "ios" | "android";
|
|
13
|
+
/** The shell's own version, for reports and diagnostics; never parsed for features. */
|
|
14
|
+
readonly shellVersion: string;
|
|
15
|
+
/**
|
|
16
|
+
* CSS px the shell's own chrome covers at each edge of the web view, beyond the OS safe areas
|
|
17
|
+
* (macOS traffic lights with `titleBarStyle: hiddenInset`, a native title bar overlay).
|
|
18
|
+
*/
|
|
19
|
+
readonly insets: {
|
|
20
|
+
top: number;
|
|
21
|
+
right: number;
|
|
22
|
+
bottom: number;
|
|
23
|
+
left: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The rectangle the shell's window controls occupy over the web view, in CSS px from the web
|
|
27
|
+
* view's top-left corner (macOS traffic lights, a Windows caption-button overlay at the right);
|
|
28
|
+
* null when there are none or they are hidden (fullscreen). Modelled on Window Controls
|
|
29
|
+
* Overlay's `titlebar-area-*`. Optional: a shell without overlaid controls omits it.
|
|
30
|
+
*/
|
|
31
|
+
readonly controls?: {
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
} | null;
|
|
37
|
+
/** Capabilities by `name@major` (as extension points are named, `channel@1`). */
|
|
38
|
+
readonly capabilities: Readonly<Record<string, object>>;
|
|
39
|
+
/**
|
|
40
|
+
* Insets, controls or capabilities changed (fullscreen hides the traffic lights; a capability
|
|
41
|
+
* appears after load). Returns unsubscribe.
|
|
42
|
+
*/
|
|
43
|
+
on(event: "change", listener: () => void): () => void;
|
|
44
|
+
}
|
|
45
|
+
declare global {
|
|
46
|
+
interface Window {
|
|
47
|
+
capybaraShell?: CapybaraShell;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The registry of capability names (mobile layout spec §9.2). A new capability is added here
|
|
52
|
+
* (key, owner) by the spec that defines it; the owner names the spec holding its functions.
|
|
53
|
+
*/
|
|
54
|
+
export declare const SHELL_CAPABILITIES: readonly {
|
|
55
|
+
key: string;
|
|
56
|
+
owner: string;
|
|
57
|
+
}[];
|