@@ -128,7 +128,8 @@ export async function handleBenchmarksRoutes(req: Request, url: URL): Promise<Re
128128 }
129129 }
130130
131- // POST /api/benchmarks/:name/expand-ids - Expand conversation/session patterns to question IDs
131+ // POST /api/benchmarks/:name/expand-ids - Expand patterns to question IDs
132+ // Supports: exact question IDs, session IDs, and prefix matching (works across all benchmarks)
132133 const expandIdsMatch = pathname . match ( / ^ \/ a p i \/ b e n c h m a r k s \/ ( [ ^ / ] + ) \/ e x p a n d - i d s $ / )
133134 if ( method === "POST" && expandIdsMatch ) {
134135 const benchmarkName = expandIdsMatch [ 1 ]
@@ -153,39 +154,27 @@ export async function handleBenchmarksRoutes(req: Request, url: URL): Promise<Re
153154 if ( ! trimmed ) continue
154155
155156 const expanded : string [ ] = [ ]
156-
157- // Pattern 1: Conversation ID (e.g., "conv-26") - expand to all questions
158- // Check if pattern ends with a number and doesn't have -q or -session suffix
159- if ( / ^ [ a - z A - Z ] + - \d + $ / . test ( trimmed ) ) {
160- const matchingQuestions = allQuestions . filter ( ( q ) =>
161- q . questionId . startsWith ( trimmed + "-q" )
162- )
163- matchingQuestions . forEach ( ( q ) => {
164- expanded . push ( q . questionId )
165- expandedIds . add ( q . questionId )
166- } )
167- }
168- // Pattern 2: Session ID (e.g., "conv-26-session_1" or "001be529-session-0")
169- // Find all questions that reference this session
170- else if ( trimmed . includes ( "-session" ) ) {
171- const matchingQuestions = allQuestions . filter ( ( q ) =>
172- q . haystackSessionIds . includes ( trimmed )
173- )
174- matchingQuestions . forEach ( ( q ) => {
175- expanded . push ( q . questionId )
176- expandedIds . add ( q . questionId )
177- } )
178- }
179- // Pattern 3: Direct question ID - add as-is if it exists
180- else {
181- const exactMatch = allQuestions . find ( ( q ) => q . questionId === trimmed )
182- if ( exactMatch ) {
183- expanded . push ( trimmed )
184- expandedIds . add ( trimmed )
185- }
157+ const addMatch = ( id : string ) => { expanded . push ( id ) ; expandedIds . add ( id ) }
158+
159+ // Priority: exact match > session lookup > prefix expansion
160+ const exactMatch = allQuestions . find ( ( q ) => q . questionId === trimmed )
161+ if ( exactMatch ) {
162+ addMatch ( trimmed )
163+ } else if ( trimmed . includes ( "-session" ) ) {
164+ // Session ID — find all questions that reference this session
165+ allQuestions
166+ . filter ( ( q ) => q . haystackSessionIds . includes ( trimmed ) )
167+ . forEach ( ( q ) => addMatch ( q . questionId ) )
168+ } else {
169+ // Prefix match — works across all benchmarks (e.g., "conv-26" matches
170+ // "conv-26-q0", "convomem-user_evidence" matches "convomem-user_evidence-0")
171+ const prefix = trimmed . endsWith ( "-" ) ? trimmed : trimmed + "-"
172+ allQuestions
173+ . filter ( ( q ) => q . questionId . startsWith ( prefix ) )
174+ . forEach ( ( q ) => addMatch ( q . questionId ) )
186175 }
187176
188- patternResults [ pattern ] = expanded
177+ patternResults [ trimmed ] = expanded
189178 }
190179
191180 return json ( {
0 commit comments