-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathagents.ts
More file actions
43 lines (37 loc) · 1.02 KB
/
agents.ts
File metadata and controls
43 lines (37 loc) · 1.02 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
import { parseFrontmatter, stripFrontmatter } from './frontmatter.js'
import { walkDir } from './walk-dir.js'
export interface AgentFrontmatter {
name: string
description: string
prompt: string
}
export interface AgentInfo {
name: string
file: string
category?: string
}
export function findAgentsInDir(dir: string, maxDepth = 2): AgentInfo[] {
const entries = walkDir(dir, {
maxDepth,
filter: (e) => !e.isDirectory && e.name.endsWith('.md'),
})
return entries.map((entry) => ({
name: entry.name.replace(/\.md$/, ''),
file: entry.path,
category: entry.category,
}))
}
export function extractAgentFrontmatter(content: string): AgentFrontmatter {
const { data, parseError } = parseFrontmatter<{
name?: string
description?: string
}>(content)
return {
name: !parseError && typeof data.name === 'string' ? data.name : '',
description:
!parseError && typeof data.description === 'string'
? data.description
: '',
prompt: stripFrontmatter(content),
}
}