( workspaceId: string, model: string, origin: ModelChangeOrigin )
| 16 | const normalizeExplicitModel = (model: string): string => normalizeToCanonical(model).trim(); |
| 17 | |
| 18 | export function recordWorkspaceModelChange( |
| 19 | workspaceId: string, |
| 20 | model: string, |
| 21 | origin: ModelChangeOrigin |
| 22 | ): void { |
| 23 | if (origin === "sync") return; |
| 24 | |
| 25 | const normalized = normalizeExplicitModel(model); |
| 26 | const current = readPersistedString(getModelKey(workspaceId)); |
| 27 | const normalizedCurrent = current ? normalizeExplicitModel(current) : null; |
| 28 | |
| 29 | // Avoid leaving stale explicit-change entries when the effective model doesn't change |
| 30 | // (ex: user re-selects the current model, or callers pass gateway-vs-canonical equivalents). |
| 31 | // Without this guard, a later sync-driven away→back transition could incorrectly consume the |
| 32 | // lingering entry and surface a warning that wasn't explicitly triggered. |
| 33 | if (normalizedCurrent === normalized) { |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | pendingExplicitChanges.set(workspaceId, { |
| 38 | model: normalized, |
| 39 | origin, |
| 40 | previousModel: normalizedCurrent, |
| 41 | }); |
| 42 | } |
| 43 | |
| 44 | export function consumeWorkspaceModelChange( |
| 45 | workspaceId: string, |
no test coverage detected