MCPcopy
hub / github.com/coder/mux / recordWorkspaceModelChange

Function recordWorkspaceModelChange

src/browser/utils/modelChange.ts:18–42  ·  view source on GitHub ↗
(
  workspaceId: string,
  model: string,
  origin: ModelChangeOrigin
)

Source from the content-addressed store, hash-verified

16const normalizeExplicitModel = (model: string): string => normalizeToCanonical(model).trim();
17
18export 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
44export function consumeWorkspaceModelChange(
45 workspaceId: string,

Calls 4

readPersistedStringFunction · 0.90
getModelKeyFunction · 0.90
normalizeExplicitModelFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected