1
1
import * as v from 'valibot' ;
2
- import { documentation_sections_schema } from '../mcp/schemas/index.js' ;
2
+ import { documentation_sections_schema , section_schema } from '../mcp/schemas/index.js' ;
3
3
import summary_data from '../use_cases.json' with { type : 'json' } ;
4
4
5
5
export async function fetch_with_timeout (
@@ -25,7 +25,8 @@ export async function get_sections() {
25
25
) . then ( ( res ) => res . json ( ) ) ;
26
26
const validated_sections = v . safeParse ( documentation_sections_schema , sections ) ;
27
27
if ( ! validated_sections . success ) return [ ] ;
28
- return Object . entries ( validated_sections . output ) . map ( ( [ , section ] ) => {
28
+
29
+ const mapped_sections = Object . entries ( validated_sections . output ) . map ( ( [ , section ] ) => {
29
30
const original_slug = section . slug ;
30
31
const cleaned_slug = original_slug . startsWith ( 'docs/' )
31
32
? original_slug . slice ( 'docs/' . length )
@@ -40,6 +41,14 @@ export async function get_sections() {
40
41
url : `https://svelte.dev/${ original_slug } /llms.txt` ,
41
42
} ;
42
43
} ) ;
44
+
45
+ const validated_output = v . safeParse ( v . array ( section_schema ) , mapped_sections ) ;
46
+ if ( ! validated_output . success ) {
47
+ console . error ( 'Section validation failed:' , validated_output . issues ) ;
48
+ return [ ] ;
49
+ }
50
+
51
+ return validated_output . output ;
43
52
}
44
53
45
54
export async function format_sections_list ( ) : Promise < string > {
0 commit comments