@@ -5,27 +5,27 @@ import path from "path";
5
5
function parseAgentsFile ( ) : Array < { id : string , agentKeys : string [ ] } > {
6
6
const agentsFilePath = path . join ( __dirname , '../src/agents.ts' ) ;
7
7
const agentsContent = fs . readFileSync ( agentsFilePath , 'utf8' ) ;
8
-
8
+
9
9
const agentConfigs : Array < { id : string , agentKeys : string [ ] } > = [ ] ;
10
-
10
+
11
11
// Split the content to process each agent configuration individually
12
12
const agentBlocks = agentsContent . split ( / (? = \s * { \s * i d : \s * [ " ' ] ) / ) ;
13
-
13
+
14
14
for ( const block of agentBlocks ) {
15
15
// Extract the ID
16
16
const idMatch = block . match ( / i d : \s * [ " ' ] ( [ ^ " ' ] + ) [ " ' ] / ) ;
17
17
if ( ! idMatch ) continue ;
18
-
18
+
19
19
const id = idMatch [ 1 ] ;
20
-
20
+
21
21
// Find the return object by looking for the pattern and then manually parsing balanced braces
22
22
const returnMatch = block . match ( / a g e n t s : \s * a s y n c \s * \( \) \s * = > \s * { \s * r e t u r n \s * { / ) ;
23
23
if ( ! returnMatch ) continue ;
24
-
24
+
25
25
const startIndex = returnMatch . index ! + returnMatch [ 0 ] . length ;
26
26
const returnObjectContent = extractBalancedBraces ( block , startIndex ) ;
27
-
28
-
27
+
28
+
29
29
// Extract keys from the return object - only capture keys that are followed by a colon and then 'new'
30
30
// This ensures we only get the top-level keys like "agentic_chat: new ..." not nested keys like "url: ..."
31
31
const keyRegex = / ^ \s * ( \w + ) : \s * n e w \s + \w + / gm;
@@ -34,18 +34,18 @@ function parseAgentsFile(): Array<{id: string, agentKeys: string[]}> {
34
34
while ( ( keyMatch = keyRegex . exec ( returnObjectContent ) ) !== null ) {
35
35
keys . push ( keyMatch [ 1 ] ) ;
36
36
}
37
-
37
+
38
38
agentConfigs . push ( { id, agentKeys : keys } ) ;
39
39
}
40
-
40
+
41
41
return agentConfigs ;
42
42
}
43
43
44
44
// Helper function to extract content between balanced braces
45
45
function extractBalancedBraces ( text : string , startIndex : number ) : string {
46
46
let braceCount = 0 ;
47
47
let i = startIndex ;
48
-
48
+
49
49
while ( i < text . length ) {
50
50
if ( text [ i ] === '{' ) {
51
51
braceCount ++ ;
@@ -58,7 +58,7 @@ function extractBalancedBraces(text: string, startIndex: number): string {
58
58
}
59
59
i ++ ;
60
60
}
61
-
61
+
62
62
return '' ;
63
63
}
64
64
@@ -71,23 +71,23 @@ async function getFile(_filePath: string | undefined, _fileName?: string) {
71
71
console . warn ( `File path is undefined, skipping.` ) ;
72
72
return { }
73
73
}
74
-
74
+
75
75
const fileName = _fileName ?? _filePath . split ( '/' ) . pop ( ) ?? ''
76
76
const filePath = _fileName ? path . join ( _filePath , fileName ) : _filePath ;
77
-
77
+
78
78
// Check if it's a remote URL
79
79
const isRemoteUrl = _filePath . startsWith ( 'http://' ) || _filePath . startsWith ( 'https://' ) ;
80
-
80
+
81
81
let content : string ;
82
-
82
+
83
83
try {
84
84
if ( isRemoteUrl ) {
85
85
// Convert GitHub URLs to raw URLs for direct file access
86
86
let fetchUrl = _filePath ;
87
87
if ( _filePath . includes ( 'github.com' ) && _filePath . includes ( '/blob/' ) ) {
88
88
fetchUrl = _filePath . replace ( 'github.com' , 'raw.githubusercontent.com' ) . replace ( '/blob/' , '/' ) ;
89
89
}
90
-
90
+
91
91
// Fetch remote file content
92
92
console . log ( `Fetching remote file: ${ fetchUrl } ` ) ;
93
93
const response = await fetch ( fetchUrl ) ;
@@ -228,6 +228,6 @@ async function runGenerateContent() {
228
228
path . join ( __dirname , "../src/files.json" ) ,
229
229
JSON . stringify ( result , null , 2 )
230
230
) ;
231
-
231
+
232
232
console . log ( "Successfully generated src/files.json" ) ;
233
233
} ) ( ) ;
0 commit comments