forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathessential-content.ts
More file actions
72 lines (65 loc) · 1.7 KB
/
Copy pathessential-content.ts
File metadata and controls
72 lines (65 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
export interface PageInput {
path: string;
body: string;
}
export type Status = "pass" | "fail";
export interface ContentResult {
status: Status;
messages: string[];
}
interface Rule {
description: string;
test: (body: string) => boolean;
}
const QUICKSTART_RULES: Rule[] = [
{
description: "install step (bash/npm/uv install)",
test: (b) => /install|npm i\b|uv add|npx /i.test(b),
},
{
description: "run agent step",
test: (b) => /run.*(agent|server|dev)/i.test(b),
},
{
description: "wire CopilotKit provider",
test: (b) => /CopilotKit\s*(?:Provider)?|<CopilotKit\b/i.test(b),
},
{
description: "try-it / first interaction",
test: (b) => /try it|chat|ask the agent|start chatting/i.test(b),
},
];
const FEATURE_RULES: Rule[] = [
{
description: "what-is intro",
test: (b) => /what is this|what is\b|introduction/i.test(b),
},
{
description: "at least one fenced code sample",
test: (b) => /```[a-z]/i.test(b),
},
{
description: "next-steps or further-reading link",
test: (b) =>
/next steps|what's next|further reading|see also/i.test(b) ||
/<Card\b/i.test(b),
},
];
function pickRules(pathRel: string): Rule[] {
if (/quickstart/i.test(pathRel)) return QUICKSTART_RULES;
if (/troubleshooting/i.test(pathRel)) return [];
return FEATURE_RULES;
}
export function checkEssentialContent(input: PageInput): ContentResult {
const rules = pickRules(input.path);
const messages: string[] = [];
for (const rule of rules) {
if (!rule.test(input.body)) {
messages.push(`${input.path}: missing ${rule.description}`);
}
}
return {
status: messages.length === 0 ? "pass" : "fail",
messages,
};
}