@capybara-hq/plugin-sdk 0.1.0-rc.2 → 0.1.0-rc.21
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 +59 -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/context.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 +88 -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 +96 -2
- package/dist/agent-template.js +381 -3
- package/dist/bootstrap.d.ts +15 -1
- package/dist/bootstrap.js +17 -1
- package/dist/cards.d.ts +39 -5
- package/dist/cards.js +70 -11
- 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 +24 -1
- package/dist/config-ui.js +89 -11
- package/dist/connector-auth.d.ts +2 -0
- package/dist/connector-auth.js +15 -0
- package/dist/context.d.ts +40 -0
- package/dist/context.js +2 -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/dev-hosts.d.ts +6 -0
- package/dist/dev-hosts.js +48 -0
- package/dist/device-protocol.d.ts +260 -0
- package/dist/device-protocol.js +496 -0
- package/dist/directory.d.ts +11 -2
- package/dist/extension-point.d.ts +6 -0
- package/dist/extension-point.js +19 -14
- package/dist/file-preview.d.ts +9 -1
- package/dist/git-hosts.d.ts +44 -0
- package/dist/git-hosts.js +81 -0
- package/dist/hooks.d.ts +111 -15
- package/dist/hooks.js +5 -0
- package/dist/index.d.ts +19 -1
- package/dist/index.js +19 -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 +33 -8
- package/dist/permissions.js +89 -22
- package/dist/plugin-manifest.d.ts +60 -7
- package/dist/plugin-manifest.js +180 -7
- package/dist/plugin-package.d.ts +3 -0
- package/dist/plugin-package.js +4 -0
- package/dist/sandbox.d.ts +239 -62
- package/dist/sandbox.js +99 -14
- 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 +172 -0
- package/dist/theme.d.ts +152 -0
- package/dist/theme.js +392 -0
- package/dist/tool.d.ts +26 -3
- package/dist/tool.js +8 -0
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +337 -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 +30 -5
- package/package.json +10 -2
- package/schemas/bootstrap.v1.schema.json +6 -0
- package/schemas/connector-template.v1.schema.json +35 -0
- package/schemas/marketplace.v1.schema.json +50 -0
- package/schemas/plugin.v1.schema.json +144 -7
- package/schemas/theme.v1.schema.json +225 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { gfmToMarkdown } from "mdast-util-gfm";
|
|
2
|
+
import { toMarkdown } from "mdast-util-to-markdown";
|
|
3
|
+
import { SETUP_GUIDE_LIMITS, SETUP_GUIDE_PLACE_INFO, } from "./setup-guide.js";
|
|
4
|
+
import { checkMarkerIndex, fenceTitle, lineSelected, nodeText, normalizeGuideSource, parseGuideMarkdown, preparedGuideText, revertSentinels, SETUP_GUIDE_VARIABLE_RE, scanGuide, } from "./setup-guide-parse.js";
|
|
5
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are what is replaced
|
|
6
|
+
const CONTROL_RE = /[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g;
|
|
7
|
+
/** What `JSON.stringify` leaves raw but a YAML parser may refuse or read as a line break. */
|
|
8
|
+
const JSON_RAW_RE = /[\u007f-\u009f\u2028\u2029]/g;
|
|
9
|
+
/** U+2060 WORD JOINER: invisible, and breaks a GFM autolink literal where it stands. */
|
|
10
|
+
const WORD_JOINER = "\u2060";
|
|
11
|
+
const AUTOLINKABLE_RE = /https?:\/\/|www\.|\S@\S+\.\S/i;
|
|
12
|
+
const QUOTING_LANGUAGES = new Set(["yaml", "yml", "json"]);
|
|
13
|
+
const clean = (s) => s.replace(CONTROL_RE, " ");
|
|
14
|
+
/** A value as the inside of a JSON / YAML double-quoted string. */
|
|
15
|
+
const quoted = (s) => JSON.stringify(s)
|
|
16
|
+
.slice(1, -1)
|
|
17
|
+
.replace(JSON_RAW_RE, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
18
|
+
/**
|
|
19
|
+
* Text no GFM parser links (spec §7.1): a word joiner after the colon of `scheme://`, inside `www.`
|
|
20
|
+
* and before `@`, the three places where a GFM autolink literal (URL, `www.` domain, email) starts.
|
|
21
|
+
* Applied to every text node outside a link before serializing, so a name such as
|
|
22
|
+
* `https://evil.example` stays text when the web parses the Markdown again, whoever consumes it.
|
|
23
|
+
*/
|
|
24
|
+
const breakAutolinks = (s) => s
|
|
25
|
+
.replace(/:(?=\/)/g, `:${WORD_JOINER}`)
|
|
26
|
+
.replace(/(www)\./gi, `$1${WORD_JOINER}.`)
|
|
27
|
+
.replace(/@/g, `${WORD_JOINER}@`);
|
|
28
|
+
/** Merges adjacent text nodes and breaks autolinks in every text node outside a link. */
|
|
29
|
+
function unlinkText(node) {
|
|
30
|
+
if (node.type === "link" || !("children" in node))
|
|
31
|
+
return;
|
|
32
|
+
const children = node.children;
|
|
33
|
+
for (let i = children.length - 1; i > 0; i--) {
|
|
34
|
+
const a = children[i - 1];
|
|
35
|
+
const b = children[i];
|
|
36
|
+
if (a?.type === "text" && b?.type === "text") {
|
|
37
|
+
a.value += b.value;
|
|
38
|
+
children.splice(i, 1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const c of children) {
|
|
42
|
+
if (c.type === "text")
|
|
43
|
+
c.value = breakAutolinks(c.value);
|
|
44
|
+
else
|
|
45
|
+
unlinkText(c);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function httpUrl(url, allowHttp) {
|
|
49
|
+
if (!(allowHttp ? /^https?:\/\//i : /^https:\/\//i).test(url))
|
|
50
|
+
return false;
|
|
51
|
+
try {
|
|
52
|
+
new URL(url);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Renders a guide document for a place, mode and audience (spec §6, §7): sections selected, known
|
|
61
|
+
* variables with a value substituted and escaped for where they stand, unknown and unresolved ones
|
|
62
|
+
* left as written, the tree sanitized (raw HTML as text, images as links or alt text, links only to
|
|
63
|
+
* absolute https URLs or http(s) URLs built from a `url` variable, text kept from being auto-linked)
|
|
64
|
+
* and cut into blocks. Pure and deterministic.
|
|
65
|
+
*/
|
|
66
|
+
export function renderSetupGuide(source, input) {
|
|
67
|
+
const info = SETUP_GUIDE_PLACE_INFO[input.place];
|
|
68
|
+
const scan = scanGuide(normalizeGuideSource(source));
|
|
69
|
+
const include = (i) => lineSelected(scan, i, input.mode, input.audience);
|
|
70
|
+
const entries = [];
|
|
71
|
+
const missing = new Set();
|
|
72
|
+
const text = preparedGuideText(scan, include, (t) => t.replace(SETUP_GUIDE_VARIABLE_RE, (whole, name) => {
|
|
73
|
+
const type = Object.hasOwn(info.variables, name) ? info.variables[name] : undefined;
|
|
74
|
+
if (type === undefined)
|
|
75
|
+
return whole;
|
|
76
|
+
const value = Object.hasOwn(input.values, name) ? input.values[name] : undefined;
|
|
77
|
+
if (value === null || value === undefined) {
|
|
78
|
+
missing.add(name);
|
|
79
|
+
return whole;
|
|
80
|
+
}
|
|
81
|
+
entries.push({ name, value, type });
|
|
82
|
+
return `${entries.length - 1}`;
|
|
83
|
+
}));
|
|
84
|
+
const names = entries.map((e) => e.name);
|
|
85
|
+
const revert = (s) => revertSentinels(s, names);
|
|
86
|
+
const tree = parseGuideMarkdown(text);
|
|
87
|
+
const definitions = new Map();
|
|
88
|
+
for (const n of tree.children) {
|
|
89
|
+
if (n.type === "definition")
|
|
90
|
+
definitions.set(n.identifier, n.url);
|
|
91
|
+
}
|
|
92
|
+
const substText = (value, inLink) => {
|
|
93
|
+
const out = [];
|
|
94
|
+
const push = (s) => {
|
|
95
|
+
if (s === "")
|
|
96
|
+
return;
|
|
97
|
+
const last = out.at(-1);
|
|
98
|
+
if (last?.type === "text")
|
|
99
|
+
last.value += s;
|
|
100
|
+
else
|
|
101
|
+
out.push({ type: "text", value: s });
|
|
102
|
+
};
|
|
103
|
+
let at = 0;
|
|
104
|
+
for (const m of value.matchAll(/<(\d+)>|(\d+)/g)) {
|
|
105
|
+
push(value.slice(at, m.index));
|
|
106
|
+
at = m.index + m[0].length;
|
|
107
|
+
const e = entries[Number(m[1] ?? m[2])];
|
|
108
|
+
if (e === undefined)
|
|
109
|
+
continue;
|
|
110
|
+
if (m[1] !== undefined) {
|
|
111
|
+
if (!inLink && e.type === "url" && httpUrl(e.value, true)) {
|
|
112
|
+
out.push({
|
|
113
|
+
type: "link",
|
|
114
|
+
url: e.value,
|
|
115
|
+
children: [{ type: "text", value: clean(e.value) }],
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
else
|
|
119
|
+
push(`<${clean(e.value)}>`);
|
|
120
|
+
}
|
|
121
|
+
else if (!inLink && e.type === "url" && httpUrl(e.value, true)) {
|
|
122
|
+
// a url variable in prose is an explicit link: the text around it never re-parses into one
|
|
123
|
+
out.push({
|
|
124
|
+
type: "link",
|
|
125
|
+
url: e.value,
|
|
126
|
+
children: [{ type: "text", value: clean(e.value) }],
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
else
|
|
130
|
+
push(clean(e.value));
|
|
131
|
+
}
|
|
132
|
+
push(value.slice(at));
|
|
133
|
+
return out;
|
|
134
|
+
};
|
|
135
|
+
const substCode = (value, lang) => value.replace(/(\d+)/g, (whole, n) => {
|
|
136
|
+
const e = entries[Number(n)];
|
|
137
|
+
if (e === undefined)
|
|
138
|
+
return whole;
|
|
139
|
+
return QUOTING_LANGUAGES.has(lang) ? quoted(e.value) : clean(e.value);
|
|
140
|
+
});
|
|
141
|
+
const substInline = (value) => value.replace(/\uE000(\d+)\uE001/g, (whole, n) => {
|
|
142
|
+
const e = entries[Number(n)];
|
|
143
|
+
return e === undefined ? whole : clean(e.value);
|
|
144
|
+
});
|
|
145
|
+
const finishLink = (url, children) => {
|
|
146
|
+
let href = null;
|
|
147
|
+
const m = /^(?:|%EE%80%80)(\d+)(?:|%EE%80%81)/i.exec(url);
|
|
148
|
+
const rest = m === null ? url : url.slice(m[0].length);
|
|
149
|
+
const restHasSentinel = revert(rest) !== rest;
|
|
150
|
+
if (m !== null) {
|
|
151
|
+
const e = entries[Number(m[1])];
|
|
152
|
+
if (e !== undefined &&
|
|
153
|
+
e.type === "url" &&
|
|
154
|
+
!restHasSentinel &&
|
|
155
|
+
httpUrl(e.value + rest, true)) {
|
|
156
|
+
href = e.value + rest;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if (!restHasSentinel && httpUrl(url, false)) {
|
|
160
|
+
href = url;
|
|
161
|
+
}
|
|
162
|
+
if (href === null) {
|
|
163
|
+
// a refused link renders as its text; text the web's GFM parser would link again
|
|
164
|
+
// (an autolink's URL, `www.`, an email address) renders as inline code instead
|
|
165
|
+
const t = children.map((c) => nodeText(c)).join("");
|
|
166
|
+
return AUTOLINKABLE_RE.test(t) ? [{ type: "inlineCode", value: clean(t) }] : children;
|
|
167
|
+
}
|
|
168
|
+
const link = { type: "link", url: href, children };
|
|
169
|
+
return [link];
|
|
170
|
+
};
|
|
171
|
+
const phrasing = (nodes, depth, inLink) => nodes.flatMap((c) => tx(c, depth, false, inLink));
|
|
172
|
+
/** Transforms one node into its sanitized replacement(s). */
|
|
173
|
+
const tx = (node, depth, flow, inLink) => {
|
|
174
|
+
const asText = (value) => {
|
|
175
|
+
const t = substText(value, true);
|
|
176
|
+
if (t.length === 0)
|
|
177
|
+
return [];
|
|
178
|
+
return flow ? [{ type: "paragraph", children: t }] : t;
|
|
179
|
+
};
|
|
180
|
+
if (depth > SETUP_GUIDE_LIMITS.depth)
|
|
181
|
+
return asText(nodeText(node));
|
|
182
|
+
switch (node.type) {
|
|
183
|
+
case "text":
|
|
184
|
+
return substText(node.value, inLink);
|
|
185
|
+
case "html":
|
|
186
|
+
return asText(node.value);
|
|
187
|
+
case "inlineCode":
|
|
188
|
+
return [{ type: "inlineCode", value: substInline(node.value) }];
|
|
189
|
+
case "code": {
|
|
190
|
+
const lang = revert(node.lang ?? "");
|
|
191
|
+
return [
|
|
192
|
+
{
|
|
193
|
+
type: "code",
|
|
194
|
+
lang: lang === "" ? null : lang,
|
|
195
|
+
meta: node.meta === null || node.meta === undefined ? null : revert(node.meta),
|
|
196
|
+
value: substCode(node.value, lang.toLowerCase()),
|
|
197
|
+
},
|
|
198
|
+
];
|
|
199
|
+
}
|
|
200
|
+
case "link": {
|
|
201
|
+
const children = phrasing(node.children, depth + 1, true);
|
|
202
|
+
return inLink ? children : finishLink(node.url, children);
|
|
203
|
+
}
|
|
204
|
+
case "linkReference": {
|
|
205
|
+
const children = phrasing(node.children, depth + 1, true);
|
|
206
|
+
if (inLink)
|
|
207
|
+
return children;
|
|
208
|
+
return finishLink(definitions.get(node.identifier) ?? "", children);
|
|
209
|
+
}
|
|
210
|
+
case "image":
|
|
211
|
+
case "imageReference": {
|
|
212
|
+
const alt = revert(node.alt ?? "");
|
|
213
|
+
const url = node.type === "image" ? node.url : (definitions.get(node.identifier) ?? "");
|
|
214
|
+
const altText = alt === "" ? [] : [{ type: "text", value: clean(alt) }];
|
|
215
|
+
const out = !inLink && revert(url) === url && httpUrl(url, false)
|
|
216
|
+
? [
|
|
217
|
+
{
|
|
218
|
+
type: "link",
|
|
219
|
+
url,
|
|
220
|
+
children: altText.length > 0 ? altText : [{ type: "text", value: url }],
|
|
221
|
+
},
|
|
222
|
+
]
|
|
223
|
+
: altText;
|
|
224
|
+
return flow && out.length > 0 ? [{ type: "paragraph", children: out }] : out;
|
|
225
|
+
}
|
|
226
|
+
case "definition":
|
|
227
|
+
case "footnoteDefinition":
|
|
228
|
+
case "footnoteReference":
|
|
229
|
+
return [];
|
|
230
|
+
case "heading":
|
|
231
|
+
return [
|
|
232
|
+
{
|
|
233
|
+
type: "heading",
|
|
234
|
+
depth: Math.min(Math.max(node.depth, 2), 4),
|
|
235
|
+
children: phrasing(node.children, depth + 1, inLink),
|
|
236
|
+
},
|
|
237
|
+
];
|
|
238
|
+
case "paragraph":
|
|
239
|
+
return [{ type: "paragraph", children: phrasing(node.children, depth + 1, inLink) }];
|
|
240
|
+
case "emphasis":
|
|
241
|
+
case "strong":
|
|
242
|
+
case "delete":
|
|
243
|
+
return [{ type: node.type, children: phrasing(node.children, depth + 1, inLink) }];
|
|
244
|
+
case "tableCell":
|
|
245
|
+
return [{ type: "tableCell", children: phrasing(node.children, depth + 1, inLink) }];
|
|
246
|
+
case "blockquote":
|
|
247
|
+
return [{ type: "blockquote", children: flowChildren(node.children, depth + 1) }];
|
|
248
|
+
case "listItem":
|
|
249
|
+
return [
|
|
250
|
+
{
|
|
251
|
+
type: "listItem",
|
|
252
|
+
spread: node.spread ?? false,
|
|
253
|
+
checked: node.checked ?? null,
|
|
254
|
+
children: flowChildren(node.children, depth + 1),
|
|
255
|
+
},
|
|
256
|
+
];
|
|
257
|
+
case "list":
|
|
258
|
+
return [
|
|
259
|
+
{
|
|
260
|
+
type: "list",
|
|
261
|
+
ordered: node.ordered ?? false,
|
|
262
|
+
start: node.start ?? null,
|
|
263
|
+
spread: node.spread ?? false,
|
|
264
|
+
children: node.children.flatMap((c) => tx(c, depth + 1, false, inLink)),
|
|
265
|
+
},
|
|
266
|
+
];
|
|
267
|
+
case "table":
|
|
268
|
+
return [
|
|
269
|
+
{
|
|
270
|
+
type: "table",
|
|
271
|
+
align: node.align ?? null,
|
|
272
|
+
children: node.children.flatMap((c) => tx(c, depth + 1, false, inLink)),
|
|
273
|
+
},
|
|
274
|
+
];
|
|
275
|
+
case "tableRow":
|
|
276
|
+
return [
|
|
277
|
+
{
|
|
278
|
+
type: "tableRow",
|
|
279
|
+
children: node.children.flatMap((c) => tx(c, depth + 1, false, inLink)),
|
|
280
|
+
},
|
|
281
|
+
];
|
|
282
|
+
case "thematicBreak":
|
|
283
|
+
return [{ type: "thematicBreak" }];
|
|
284
|
+
case "break":
|
|
285
|
+
return [{ type: "break" }];
|
|
286
|
+
default:
|
|
287
|
+
return asText(nodeText(node));
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
const flowChildren = (nodes, depth) => nodes.flatMap((c) => tx(c, depth, true, false));
|
|
291
|
+
// the title: the leading level-1 heading, lifted out
|
|
292
|
+
let title = "";
|
|
293
|
+
let body = tree.children;
|
|
294
|
+
const first = body[0];
|
|
295
|
+
if (first?.type === "heading" && first.depth === 1) {
|
|
296
|
+
title = phrasing(first.children, 2, false)
|
|
297
|
+
.map((n) => nodeText(n))
|
|
298
|
+
.join("")
|
|
299
|
+
.trim();
|
|
300
|
+
body = body.slice(1);
|
|
301
|
+
}
|
|
302
|
+
const blocks = [];
|
|
303
|
+
let group = [];
|
|
304
|
+
const flush = () => {
|
|
305
|
+
if (group.length === 0)
|
|
306
|
+
return;
|
|
307
|
+
const root = { type: "root", children: group };
|
|
308
|
+
unlinkText(root);
|
|
309
|
+
const md = toMarkdown(root, { extensions: [gfmToMarkdown()], bullet: "-" }).replace(/\n+$/, "");
|
|
310
|
+
if (md.trim() !== "")
|
|
311
|
+
blocks.push({ kind: "markdown", text: md });
|
|
312
|
+
group = [];
|
|
313
|
+
};
|
|
314
|
+
for (const node of body) {
|
|
315
|
+
const c = checkMarkerIndex(node);
|
|
316
|
+
if (c !== undefined) {
|
|
317
|
+
const check = scan.checks[c];
|
|
318
|
+
if (check !== undefined) {
|
|
319
|
+
flush();
|
|
320
|
+
blocks.push({ kind: "check", id: check.id, label: check.label });
|
|
321
|
+
}
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (node.type === "code") {
|
|
325
|
+
flush();
|
|
326
|
+
const lang = revert(node.lang ?? "");
|
|
327
|
+
blocks.push({
|
|
328
|
+
kind: "code",
|
|
329
|
+
language: lang,
|
|
330
|
+
title: fenceTitle(revert(node.meta ?? "")).title,
|
|
331
|
+
text: substCode(node.value, lang.toLowerCase()),
|
|
332
|
+
});
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
group.push(...tx(node, 1, true, false));
|
|
336
|
+
}
|
|
337
|
+
flush();
|
|
338
|
+
const usedModes = new Set();
|
|
339
|
+
const usedAudiences = new Set();
|
|
340
|
+
for (const s of scan.sections)
|
|
341
|
+
(s.type === "mode" ? usedModes : usedAudiences).add(s.value);
|
|
342
|
+
const checkSource = (id) => id.startsWith("capybara:") ? "kernel" : "plugin";
|
|
343
|
+
return {
|
|
344
|
+
title,
|
|
345
|
+
modes: info.modes.filter((m) => usedModes.has(m)),
|
|
346
|
+
audiences: info.audiences.filter((a) => usedAudiences.has(a)),
|
|
347
|
+
blocks,
|
|
348
|
+
checks: blocks.flatMap((b) => b.kind === "check" ? [{ id: b.id, label: b.label, source: checkSource(b.id) }] : []),
|
|
349
|
+
unresolved: Object.keys(info.variables).filter((n) => missing.has(n)),
|
|
350
|
+
};
|
|
351
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a guide is shown. `channel-connection`: 新建渠道 and the channel detail page;
|
|
3
|
+
* `connector-template`: the pages of a connector template and the connectors made from it.
|
|
4
|
+
*/
|
|
5
|
+
export declare const SETUP_GUIDE_PLACES: readonly ["channel-connection", "connector-template"];
|
|
6
|
+
export type SetupGuidePlace = (typeof SETUP_GUIDE_PLACES)[number];
|
|
7
|
+
/** Who the rendered text is for: `admin` sets the integration up, `member` uses it. */
|
|
8
|
+
export type SetupGuideAudience = "admin" | "member";
|
|
9
|
+
/**
|
|
10
|
+
* The type of a variable: `url` values are built by the kernel from deployment settings and ids,
|
|
11
|
+
* `text` values hold whatever a person typed (names), `token` values are ids and enum values.
|
|
12
|
+
*/
|
|
13
|
+
export type SetupGuideVariableType = "url" | "text" | "token";
|
|
14
|
+
/** What a place defines: its modes, audiences and variables, and whether its targets record acks. */
|
|
15
|
+
export interface SetupGuidePlaceInfo {
|
|
16
|
+
modes: readonly string[];
|
|
17
|
+
audiences: readonly SetupGuideAudience[];
|
|
18
|
+
variables: Readonly<Record<string, SetupGuideVariableType>>;
|
|
19
|
+
drift: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** The place registry. None of the variables is a secret. */
|
|
22
|
+
export declare const SETUP_GUIDE_PLACE_INFO: Readonly<Record<SetupGuidePlace, SetupGuidePlaceInfo>>;
|
|
23
|
+
/** Limits of setup guides. */
|
|
24
|
+
export declare const SETUP_GUIDE_LIMITS: {
|
|
25
|
+
/** Guides per plugin. */
|
|
26
|
+
readonly guides: 8;
|
|
27
|
+
/** Bytes per document (each language). */
|
|
28
|
+
readonly docBytes: 65536;
|
|
29
|
+
/** Fenced code blocks per document. */
|
|
30
|
+
readonly codeBlocks: 24;
|
|
31
|
+
/** Check lines per document. */
|
|
32
|
+
readonly checks: 16;
|
|
33
|
+
/** Sections per document. */
|
|
34
|
+
readonly sections: 16;
|
|
35
|
+
/** Characters of the title and of a heading. */
|
|
36
|
+
readonly titleChars: 100;
|
|
37
|
+
/** Characters of a check label. */
|
|
38
|
+
readonly checkLabelChars: 80;
|
|
39
|
+
/** Characters of a code fence title. */
|
|
40
|
+
readonly fenceTitleChars: 100;
|
|
41
|
+
/** Markdown nesting depth. */
|
|
42
|
+
readonly depth: 16;
|
|
43
|
+
};
|
|
44
|
+
/** A setup guide in `plugin.json` `setupGuides`. */
|
|
45
|
+
export interface PluginSetupGuide {
|
|
46
|
+
/** `^[a-z0-9][a-z0-9-]{0,63}$`, unique in the plugin; the documents are `guides/<id>.md`. */
|
|
47
|
+
id: string;
|
|
48
|
+
place: SetupGuidePlace;
|
|
49
|
+
/** Only and required for `connector-template`: one of the plugin's connector template ids. */
|
|
50
|
+
template?: string;
|
|
51
|
+
}
|
|
52
|
+
/** The package path of a guide's document: `guides/<id>.md` (en) or `guides/<id>.zh.md` (zh). */
|
|
53
|
+
export declare function setupGuideDocPath(id: string, locale: "en" | "zh"): string;
|
|
54
|
+
/**
|
|
55
|
+
* Whether a guide document is usable as a file: present, at most
|
|
56
|
+
* {@link SETUP_GUIDE_LIMITS}`.docBytes`, valid UTF-8 without NUL and without U+E000–U+E0FF. The
|
|
57
|
+
* problem (English, naming the path), or undefined. Shared by the packer and the kernel's reader.
|
|
58
|
+
*/
|
|
59
|
+
export declare function setupGuideDocProblem(path: string, data: Uint8Array | undefined): string | undefined;
|
|
60
|
+
/** A problem {@link validateSetupGuide} found. */
|
|
61
|
+
export interface SetupGuideIssue {
|
|
62
|
+
level: "error" | "warning";
|
|
63
|
+
message: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Validates a guide's documents for a place (spec §4.5): title, sections well formed and known to
|
|
67
|
+
* the place, check lines, fence info strings, no indented code, limits, variables known to the place
|
|
68
|
+
* and allowed where they stand (§6.2), language parity of the zh document (§4.3), and, when
|
|
69
|
+
* `pluginChecks` is given, that every plugin check id is declared there (the extension's
|
|
70
|
+
* `permissions.setupChecks`). Messages name the file (`guides/<id>.md` when `id` is given) and line.
|
|
71
|
+
* `allowUnknownVariables` (the kernel's importer) accepts variables the place does not define: they
|
|
72
|
+
* render as written. Pure.
|
|
73
|
+
*/
|
|
74
|
+
export declare function validateSetupGuide(input: {
|
|
75
|
+
place: SetupGuidePlace;
|
|
76
|
+
en: string;
|
|
77
|
+
zh?: string;
|
|
78
|
+
pluginChecks?: readonly string[];
|
|
79
|
+
/** The guide id, to name the files in messages. */
|
|
80
|
+
id?: string;
|
|
81
|
+
allowUnknownVariables?: boolean;
|
|
82
|
+
}): SetupGuideIssue[];
|
|
83
|
+
/**
|
|
84
|
+
* The drift hash of a guide for one mode and audience (spec §11): sha256 (hex) over the place, guide
|
|
85
|
+
* id, mode and audience, then, in document order after section selection, each fenced code block
|
|
86
|
+
* (language and text, title excluded) and each check id of the English document. Variables are not
|
|
87
|
+
* substituted; line endings are normalized. Prose, headings and check labels do not move it.
|
|
88
|
+
*/
|
|
89
|
+
export declare function setupGuideHash(enSource: string, input: {
|
|
90
|
+
place: SetupGuidePlace;
|
|
91
|
+
guideId: string;
|
|
92
|
+
mode: string | null;
|
|
93
|
+
audience: SetupGuideAudience;
|
|
94
|
+
}): string;
|