-
Notifications
You must be signed in to change notification settings - Fork 8
Fetch gateway models directly from Electron instead of spawning preview sessions #1363
Description
Problem
To populate the model selector dropdown, we currently spawn a lightweight "preview session" (__preview__ task ID) via the agent package, wait for it to initialize, and extract the available models from its configOptions response. This means:
- Unnecessary latency — full agent session startup just to get a model list
- Unnecessary complexity — preview session lifecycle management, cleanup logic, the
__preview__task ID convention - Fragility — if the agent fails to start, no models appear in the selector
Current flow
TaskInput mount
→ usePreviewSession() hook
→ sessionService.startPreviewSession({ adapter })
→ trpcClient.agent.start.mutate({ taskId: "__preview__", ... })
→ Agent initializes → Claude adapter → fetchGatewayModels()
→ configOptions returned with model list
→ Model selector populated
Proposed change
Call fetchGatewayModels() directly from a main process service and expose it via a tRPC query. The main process already has the gateway URL and API credentials — no agent session needed.
A tRPC endpoint (getGatewayModels) already exists in apps/code/src/main/trpc/routers/agent.ts that does exactly this. We should:
- Have the renderer call this tRPC query directly to populate the model selector
- Remove the preview session machinery (
usePreviewSession,startPreviewSession,cancelPreviewSession,PREVIEW_TASK_ID) - Keep the 10-min TTL cache in
packages/agent/src/gateway-models.ts(still used by real sessions)
Key files
packages/agent/src/gateway-models.ts—fetchGatewayModels()with 10-min cacheapps/code/src/main/trpc/routers/agent.ts— existinggetGatewayModelstRPC query (~line 197)apps/code/src/main/services/agent/service.ts—getGatewayModels()(~line 1675)apps/code/src/renderer/features/task-detail/hooks/usePreviewSession.ts— preview session hook (to remove)apps/code/src/renderer/features/sessions/service/service.ts—startPreviewSession()(to remove)apps/code/src/renderer/features/sessions/components/ModelSelector.tsx— needs to use tRPC query instead
Context
From Josh: "for the model select issue thingy we've had open for a while, iirc we spawn some kind of preview session and then use the agent package to load the available models — why do we do that vs calling the gateway directly from electron?"
Answer: no good reason. The direct approach is simpler, faster and already partially wired up.