feat(mobile): fetch available model list from the LLM gateway#2564
feat(mobile): fetch available model list from the LLM gateway#2564oliverb123 wants to merge 3 commits into
Conversation
The mobile app hardcoded its model list in `composer/options.ts`, so new models (e.g. 4.8 / 5) never appeared without shipping a new build. The desktop app instead downloads the catalogue from the LLM gateway's `/v1/models` endpoint. Move the gateway URL construction and model-fetch/format logic into `@posthog/shared` (zero-dependency, already a mobile dependency) as the single source of truth, and have `packages/agent` re-export from it so the desktop path is literally the same code. Mobile now fetches the list the same way via a `useModels` hook backed by a persisted cache, falling back to a small built-in list only on a cold start or when the gateway is unreachable. Generated-By: PostHog Code Task-Id: 89aa4bb4-eaa8-4894-8c4c-3f6b096fc78a
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
|
| // Models that expose a reasoning-effort control. Mirrors `MODELS_WITH_EFFORT` | ||
| // in packages/agent/src/adapters/claude/session/models.ts — keep in sync. | ||
| const MODELS_WITH_EFFORT = new Set([ |
There was a problem hiding this comment.
Duplicated
MODELS_WITH_EFFORT set — two sources of truth that must be kept in sync manually
supportsReasoningEffort here and supportsEffort in packages/agent/src/adapters/claude/session/models.ts both maintain private copies of the same four-model set. The comment even says "keep in sync". Now that this logic lives in @posthog/shared, the agent's copy can be deleted and replaced with an import of supportsReasoningEffort — removing the manual sync requirement entirely.
| // Models that expose a reasoning-effort control. Mirrors `MODELS_WITH_EFFORT` | |
| // in packages/agent/src/adapters/claude/session/models.ts — keep in sync. | |
| const MODELS_WITH_EFFORT = new Set([ | |
| // Models that expose a reasoning-effort control. | |
| const MODELS_WITH_EFFORT = new Set([ |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/shared/src/gateway-models.ts
Line: 220-222
Comment:
**Duplicated `MODELS_WITH_EFFORT` set — two sources of truth that must be kept in sync manually**
`supportsReasoningEffort` here and `supportsEffort` in `packages/agent/src/adapters/claude/session/models.ts` both maintain private copies of the same four-model set. The comment even says "keep in sync". Now that this logic lives in `@posthog/shared`, the agent's copy can be deleted and replaced with an import of `supportsReasoningEffort` — removing the manual sync requirement entirely.
```suggestion
// Models that expose a reasoning-effort control.
const MODELS_WITH_EFFORT = new Set([
```
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
- Fix the `quality` (biome ci) failure: organize imports/exports in utils/gateway.ts. - Address Greptile review: delete the agent's duplicate MODELS_WITH_EFFORT set and have `supportsEffort` delegate to `supportsReasoningEffort` in @posthog/shared, so there's a single source of truth instead of two sets kept in sync manually. Generated-By: PostHog Code Task-Id: 89aa4bb4-eaa8-4894-8c4c-3f6b096fc78a
Address Greptile review: - Include cloudRegion in the useModels query key. The gateway URL is region-derived, so a constant key served the previous region's cached models for the full staleTime window after a region switch. - Convert the isBlockedModelId and supportsReasoningEffort tests to it.each tables to match the repo's parameterized-test convention. Generated-By: PostHog Code Task-Id: 89aa4bb4-eaa8-4894-8c4c-3f6b096fc78a
Problem
On mobile, the available model list was hardcoded in
composer/options.ts, so newer models (e.g. 4.8 / 5) never showed up without shipping a new app build. The desktop app already downloads the list from the LLM gateway, so the two clients drifted.Changes
@posthog/shared(zero-dependency, already a mobile dependency) as the single source of truth;packages/agentnow re-exports from it so the desktop path is literally the same code./v1/modelsendpoint via a newuseModelshook backed by a persisted cache, mapping models exactly like the desktop app (Anthropic models, gateway-formatted names). A small built-in list remains only as a cold-start / offline fallback so the picker is never empty.How did you test this?
pnpm --filter @posthog/shared test(incl. new gateway URL + model tests) — passgateway-models,utils/gateway) — passpnpm --filter agent typecheckand agent build — passtscon touched files (clean), biome on changed files (clean), andvitest run src/features/tasks(84 tests) — passAutomatic notifications
Created with PostHog Code from a Slack thread