@@ -14,7 +14,7 @@ import {
1414export const loader = async ( { request, params } : LoaderFunctionArgs ) => {
1515 const userId = await requireUserId ( request ) ;
1616 const user = await prisma . user . findUnique ( { where : { id : userId } } ) ;
17- if ( ! user ?. admin ) return redirect ( "/" ) ;
17+ if ( ! user ?. admin ) throw redirect ( "/" ) ;
1818
1919 // Model name is URL-encoded in the URL param
2020 const modelName = decodeURIComponent ( params . model ?? "" ) ;
@@ -142,7 +142,7 @@ export default function AdminMissingModelDetailRoute() {
142142 </ span >
143143 < div className = "flex gap-4 mt-1 font-mono text-text-bright" >
144144 < span > input: { providerCosts [ 0 ] . estimatedInputPrice . toExponential ( 4 ) } </ span >
145- < span > output: { providerCosts [ 0 ] . estimatedOutputPrice ?? 0. toExponential ( 4 ) } </ span >
145+ < span > output: { ( providerCosts [ 0 ] . estimatedOutputPrice ?? 0 ) . toExponential ( 4 ) } </ span >
146146 </ div >
147147 < span className = "text-text-dimmed mt-1 block" >
148148 Cross-reference with the provider's pricing page before using these estimates.
@@ -176,7 +176,7 @@ export default function AdminMissingModelDetailRoute() {
176176 const expanded = expandedSpans . has ( s . span_id ) ;
177177 let parsedAttrs : Record < string , unknown > | null = null ;
178178 try {
179- parsedAttrs = JSON . parse ( s . attributes_text ) ;
179+ parsedAttrs = JSON . parse ( s . attributes_text ) as Record < string , unknown > ;
180180 } catch {
181181 // ignore
182182 }
@@ -226,7 +226,7 @@ function extractTokenTypes(samples: MissingModelSample[]): TokenTypeSummary[] {
226226 for ( const s of samples ) {
227227 let attrs : Record < string , unknown > ;
228228 try {
229- attrs = JSON . parse ( s . attributes_text ) ;
229+ attrs = JSON . parse ( s . attributes_text ) as Record < string , unknown > ;
230230 } catch {
231231 continue ;
232232 }
@@ -300,7 +300,7 @@ function extractProviderCosts(samples: MissingModelSample[]): ProviderCostInfo[]
300300 for ( const s of samples ) {
301301 let attrs : Record < string , unknown > ;
302302 try {
303- attrs = JSON . parse ( s . attributes_text ) ;
303+ attrs = JSON . parse ( s . attributes_text ) as Record < string , unknown > ;
304304 } catch {
305305 continue ;
306306 }
@@ -310,7 +310,7 @@ function extractProviderCosts(samples: MissingModelSample[]): ProviderCostInfo[]
310310 const aiResponse = getNestedObj ( attrs , [ "ai" , "response" ] ) ;
311311 const rawMeta = aiResponse ?. providerMetadata ;
312312 if ( typeof rawMeta === "string" ) {
313- try { providerMeta = JSON . parse ( rawMeta ) ; } catch { }
313+ try { providerMeta = JSON . parse ( rawMeta ) as Record < string , unknown > ; } catch { }
314314 } else if ( rawMeta && typeof rawMeta === "object" ) {
315315 providerMeta = rawMeta as Record < string , unknown > ;
316316 }
@@ -390,13 +390,15 @@ function buildPrompt(modelName: string, samples: MissingModelSample[], providerC
390390 let sampleAttrs = "" ;
391391 if ( samples . length > 0 ) {
392392 try {
393- const attrs = JSON . parse ( samples [ 0 ] . attributes_text ) ;
393+ const attrs = JSON . parse ( samples [ 0 ] . attributes_text ) as Record < string , unknown > ;
394+ const ai = attrs . ai as Record < string , unknown > | undefined ;
395+ const aiResponse = ( ai ?. response ?? { } ) as Record < string , unknown > ;
394396 // Extract just the relevant fields
395397 const compact : Record < string , unknown > = { } ;
396398 if ( attrs . gen_ai ) compact . gen_ai = attrs . gen_ai ;
397- if ( attrs . ai ?. usage ) compact [ "ai.usage" ] = attrs . ai . usage ;
398- if ( attrs . ai ?. response ? .providerMetadata ) {
399- compact [ "ai.response.providerMetadata" ] = attrs . ai . response . providerMetadata ;
399+ if ( ai ?. usage ) compact [ "ai.usage" ] = ai . usage ;
400+ if ( aiResponse . providerMetadata ) {
401+ compact [ "ai.response.providerMetadata" ] = aiResponse . providerMetadata ;
400402 }
401403 sampleAttrs = JSON . stringify ( compact , null , 2 ) ;
402404 } catch {
@@ -457,7 +459,7 @@ The gateway/router is reporting costs for this model. Use these to cross-referen
457459${ providerCosts . map ( ( c ) => `- $${ c . cost . toFixed ( 6 ) } for ${ c . inputTokens . toLocaleString ( ) } input + ${ c . outputTokens . toLocaleString ( ) } output tokens` ) . join ( "\n" ) } ${ providerCosts [ 0 ] . estimatedInputPrice != null ? `
458460- Estimated per-token rates (rough, assuming ~3x output/input ratio):
459461 - input: ${ providerCosts [ 0 ] . estimatedInputPrice . toExponential ( 4 ) } (${ ( providerCosts [ 0 ] . estimatedInputPrice * 1_000_000 ) . toFixed ( 4 ) } $/M)
460- - output: ${ providerCosts [ 0 ] . estimatedOutputPrice ?? 0. toExponential ( 4 ) } (${ ( providerCosts [ 0 ] . estimatedOutputPrice ?? 0 * 1_000_000 ) . toFixed ( 4 ) } $/M)
462+ - output: ${ ( providerCosts [ 0 ] . estimatedOutputPrice ?? 0 ) . toExponential ( 4 ) } (${ ( ( providerCosts [ 0 ] . estimatedOutputPrice ?? 0 ) * 1_000_000 ) . toFixed ( 4 ) } $/M)
461463- Verify these against the official pricing page before using.` : "" } ` : "" } ${ sampleAttrs ? `
462464
463465## Sample span attributes (first span)
0 commit comments