skill-list-mock.ts
4.12 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
export interface SkillListMockItem extends Record<string, unknown> {
skill_code: string;
skill_name: string;
description: string;
}
export interface SkillDetailMockItem extends SkillListMockItem {
doc_markdown: string;
}
export interface SkillListMockFixture {
loading?: boolean;
error?: boolean;
items: SkillListMockItem[];
}
export interface SkillDetailMockFixture extends SkillListMockFixture {
items: SkillDetailMockItem[];
total?: number;
detailLoading?: boolean;
}
export interface SkillListPageQuery {
keyword?: string;
source?: SkillDetailMockItem[];
}
const normalSkills: SkillDetailMockItem[] = [
{
skill_code: 'browser:browser',
skill_name: 'Browser automation for the Codex in-app browser.',
description: '支持本地目标、浏览器检查和使用说明预览。',
doc_markdown: [
'# Browser automation for the Codex in-app browser.',
'',
'适用于访问 [localhost](http://localhost) 与其他本地页面。',
'',
'> 推荐在改完前端后立即验证关键流程。',
'',
'- 支持打开页面',
'- 支持点击与输入',
'',
'运行命令:`npm run dev`',
'',
'```bash',
'npm run dev',
'```',
].join('\n'),
},
{
skill_code: 'imagegen',
skill_name: 'Generate or edit raster images.',
description: '适用于生成插图、贴图、透明背景素材和长 Markdown 示例文档。',
doc_markdown: [
'# imagegen',
'',
'用于创建或编辑位图素材。',
'',
'## Markdown Example',
'',
'可以配合长说明文档一起使用。',
].join('\n'),
},
];
export const skillListMockFixtures = {
normal: { items: normalSkills, total: normalSkills.length },
loading: { loading: true, items: [] },
error: { error: true, items: [] },
empty: { items: [] },
detailLoading: { items: normalSkills, detailLoading: true },
emptyMarkdown: {
items: normalSkills.map((item) => (item.skill_code === 'imagegen' ? { ...item, doc_markdown: '' } : item)),
},
detailError: { items: normalSkills },
longMarkdown: {
items: normalSkills.map((item) => (
item.skill_code === 'browser:browser'
? {
...item,
doc_markdown: [
'# Browser automation for the Codex in-app browser.',
'',
...Array.from({ length: 24 }, (_, index) => `## Section ${index + 1}\n\n这是用于验证抽屉滚动的长内容段落 ${index + 1}。`),
'',
'```ts',
"const longLine = 'This code block should stay scrollable inside the drawer content area.';",
'```',
].join('\n'),
}
: item
)),
},
} satisfies Record<string, SkillDetailMockFixture>;
export function getSkillFixtureByScenario(scenario: string): SkillDetailMockFixture {
switch (scenario) {
case 'loading':
return skillListMockFixtures.loading;
case 'error':
return skillListMockFixtures.error;
case 'empty':
return skillListMockFixtures.empty;
case 'detailLoading':
return skillListMockFixtures.detailLoading;
case 'emptyMarkdown':
return skillListMockFixtures.emptyMarkdown;
case 'detailError':
return skillListMockFixtures.detailError;
case 'longMarkdown':
return skillListMockFixtures.longMarkdown;
default:
return skillListMockFixtures.normal;
}
}
export function getSkillList({ keyword = '', source }: SkillListPageQuery) {
const normalizedKeyword = keyword.trim().toLowerCase();
const items = source ?? skillListMockFixtures.normal.items;
return items.filter((item) => {
if (!normalizedKeyword) return true;
return [item.skill_code, item.skill_name, item.description, item.doc_markdown]
.join(' ')
.toLowerCase()
.includes(normalizedKeyword);
});
}
export function getSkillDetail(skillCode: string | undefined, scenario = 'normal') {
if (!skillCode) return undefined;
if (scenario === 'detailError' || scenario === 'detailLoading') return undefined;
return getSkillFixtureByScenario(scenario).items.find((item) => item.skill_code === skillCode);
}