@@ -3,52 +3,13 @@ import axios from "axios"
33import type { ModelInfo } from "@roo-code/types"
44
55import type { ApiHandlerOptions } from "../../../shared/api"
6- import { getZooCodeBaseUrl } from "../../../services/zoo-code-auth"
6+ import { getCachedZooCodeToken , getZooCodeBaseUrl } from "../../../services/zoo-code-auth"
77
8- // Reuse the same schemas and parsing logic from vercel-ai-gateway since the API format is identical
9- import { type VercelAiGatewayModel , parseVercelAiGatewayModel } from "./vercel-ai-gateway"
10-
11- import { z } from "zod"
12-
13- /**
14- * ZooGatewayPricing (same format as Vercel AI Gateway)
15- */
16-
17- const zooGatewayPricingSchema = z . object ( {
18- input : z . string ( ) . optional ( ) ,
19- output : z . string ( ) . optional ( ) ,
20- input_cache_write : z . string ( ) . optional ( ) ,
21- input_cache_read : z . string ( ) . optional ( ) ,
22- image : z . string ( ) . optional ( ) ,
23- } )
24-
25- /**
26- * ZooGatewayModel (same format as Vercel AI Gateway)
27- */
28-
29- const zooGatewayModelSchema = z . object ( {
30- id : z . string ( ) ,
31- object : z . string ( ) ,
32- created : z . number ( ) ,
33- owned_by : z . string ( ) ,
34- name : z . string ( ) ,
35- description : z . string ( ) ,
36- context_window : z . number ( ) ,
37- max_tokens : z . number ( ) ,
38- type : z . string ( ) ,
39- pricing : zooGatewayPricingSchema ,
40- } )
41-
42- /**
43- * ZooGatewayModelsResponse
44- */
45-
46- const zooGatewayModelsResponseSchema = z . object ( {
47- object : z . string ( ) ,
48- data : z . array ( zooGatewayModelSchema ) ,
49- } )
50-
51- type ZooGatewayModelsResponse = z . infer < typeof zooGatewayModelsResponseSchema >
8+ import {
9+ type VercelAiGatewayModel ,
10+ parseVercelAiGatewayModel ,
11+ vercelAiGatewayModelsResponseSchema ,
12+ } from "./vercel-ai-gateway"
5213
5314// Bound model discovery so a network stall can't hang provider initialization paths.
5415const MODEL_DISCOVERY_TIMEOUT_MS = 15_000
@@ -63,28 +24,27 @@ export async function getZooGatewayModels(options?: ApiHandlerOptions): Promise<
6324 const models : Record < string , ModelInfo > = { }
6425 const baseURL = options ?. zooGatewayBaseUrl ?? `${ getZooCodeBaseUrl ( ) } /api/gateway/v1`
6526
66- // Build headers - Zoo Gateway requires authentication via the zoo_ext_ session token
27+ // Build headers - Zoo Gateway requires authentication via the zoo_ext_ session token.
28+ // Fall back to the secret-storage cache when the profile hasn't been seeded yet.
29+ const sessionToken = options ?. zooSessionToken || getCachedZooCodeToken ( )
6730 const headers : Record < string , string > = { }
68- if ( options ?. zooSessionToken ) {
69- headers [ "Authorization" ] = `Bearer ${ options . zooSessionToken } `
31+ if ( sessionToken ) {
32+ headers [ "Authorization" ] = `Bearer ${ sessionToken } `
7033 }
7134
7235 try {
73- const response = await axios . get < ZooGatewayModelsResponse > ( `${ baseURL } /models` , {
36+ const response = await axios . get ( `${ baseURL } /models` , {
7437 headers,
7538 timeout : MODEL_DISCOVERY_TIMEOUT_MS ,
7639 } )
77- const result = zooGatewayModelsResponseSchema . safeParse ( response . data )
78-
79- // Fall back to the raw response only when it looks structurally sound; otherwise return
80- // an empty list rather than crashing on `response.data.data` being undefined.
81- const data = result . success ? result . data . data : Array . isArray ( response . data ?. data ) ? response . data . data : [ ]
40+ const result = vercelAiGatewayModelsResponseSchema . safeParse ( response . data )
8241
8342 if ( ! result . success ) {
8443 console . error ( `Zoo Gateway models response is invalid ${ JSON . stringify ( result . error . format ( ) ) } ` )
44+ return models
8545 }
8646
87- for ( const model of data ) {
47+ for ( const model of result . data . data ) {
8848 const { id } = model
8949
9050 // Only include language models for chat inference.
@@ -93,8 +53,7 @@ export async function getZooGatewayModels(options?: ApiHandlerOptions): Promise<
9353 continue
9454 }
9555
96- // Parse model using the same logic as Vercel AI Gateway since formats are identical
97- models [ id ] = parseZooGatewayModel ( { id, model : model as VercelAiGatewayModel } )
56+ models [ id ] = parseZooGatewayModel ( { id, model } )
9857 }
9958 } catch ( error ) {
10059 // Log only safe fields; never serialize the full error object because it
@@ -121,6 +80,5 @@ export async function getZooGatewayModels(options?: ApiHandlerOptions): Promise<
12180 */
12281
12382export const parseZooGatewayModel = ( { id, model } : { id : string ; model : VercelAiGatewayModel } ) : ModelInfo => {
124- // Reuse the parsing logic from vercel-ai-gateway
12583 return parseVercelAiGatewayModel ( { id, model } )
12684}
0 commit comments