@@ -10,7 +10,7 @@ import {
1010} from "@roo-code/types"
1111
1212import { ApiHandlerOptions } from "../../shared/api"
13- import { clearZooCodeToken , getCachedZooCodeToken , getZooCodeBaseUrl } from "../../services/zoo-code-auth"
13+ import { clearZooCodeToken , getZooCodeBaseUrl , resolveZooGatewaySessionToken } from "../../services/zoo-code-auth"
1414import { Package } from "../../shared/package"
1515import { t } from "../../i18n"
1616
@@ -101,9 +101,7 @@ export class ZooGatewayHandler extends RouterProvider implements SingleCompletio
101101 constructor ( options : ApiHandlerOptions ) {
102102 const baseURL = options . zooGatewayBaseUrl ?? `${ getZooCodeBaseUrl ( ) } /api/gateway/v1`
103103
104- // Prefer the secret-storage cache so a 401 clear takes effect immediately; fall back
105- // to the profile-persisted token when the user is signed in but seeding hasn't run yet.
106- const sessionToken = getCachedZooCodeToken ( ) || options . zooSessionToken
104+ const sessionToken = resolveZooGatewaySessionToken ( options . zooSessionToken )
107105
108106 // Merge Zoo-specific enrichment headers into openAiHeaders so they flow through
109107 // the parent's single OpenAI client. We avoid reassigning `this.client` (which
@@ -128,8 +126,7 @@ export class ZooGatewayHandler extends RouterProvider implements SingleCompletio
128126 }
129127
130128 private ensureAuthenticated ( ) : void {
131- const sessionToken = getCachedZooCodeToken ( ) || this . options . zooSessionToken
132- if ( ! sessionToken ) {
129+ if ( ! resolveZooGatewaySessionToken ( this . options . zooSessionToken ) ) {
133130 throw new Error ( ZOO_GATEWAY_AUTH_ERROR )
134131 }
135132 }
@@ -217,12 +214,14 @@ export class ZooGatewayHandler extends RouterProvider implements SingleCompletio
217214 }
218215 }
219216 } catch ( error ) {
220- void surfaceGatewayApiError ( error ) . catch ( ( surfaceError ) => {
217+ try {
218+ await surfaceGatewayApiError ( error )
219+ } catch ( surfaceError ) {
221220 console . error (
222221 "Failed to surface Zoo Gateway error:" ,
223222 surfaceError instanceof Error ? surfaceError . message : surfaceError ,
224223 )
225- } )
224+ }
226225 throw error
227226 }
228227 }
@@ -248,12 +247,14 @@ export class ZooGatewayHandler extends RouterProvider implements SingleCompletio
248247 const response = await this . client . chat . completions . create ( requestOptions )
249248 return response . choices [ 0 ] ?. message . content || ""
250249 } catch ( error ) {
251- void surfaceGatewayApiError ( error ) . catch ( ( surfaceError ) => {
250+ try {
251+ await surfaceGatewayApiError ( error )
252+ } catch ( surfaceError ) {
252253 console . error (
253254 "Failed to surface Zoo Gateway error:" ,
254255 surfaceError instanceof Error ? surfaceError . message : surfaceError ,
255256 )
256- } )
257+ }
257258 if ( error instanceof Error ) {
258259 throw new Error ( `Zoo Gateway completion error: ${ error . message } ` )
259260 }
0 commit comments