Skip to content

Commit 29ec5b3

Browse files
committed
chore(deadcode): share session model default check
1 parent fa08942 commit 29ec5b3

4 files changed

Lines changed: 24 additions & 43 deletions

File tree

ui/src/ui/chat/session-controls.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
normalizeAgentId,
3030
parseAgentSessionKey,
3131
} from "../session-key.ts";
32+
import { sessionModelMatchesDefaults } from "../session-model-defaults.ts";
3233
import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "../string-coerce.ts";
3334
import {
3435
formatInheritedThinkingLabel,
@@ -958,16 +959,6 @@ function resolveChatFastModeSelectState(
958959
};
959960
}
960961

961-
function sessionModelMatchesDefaults(
962-
row: SessionsListResult["sessions"][number] | undefined,
963-
defaults: SessionsListResult["defaults"] | undefined,
964-
): boolean {
965-
return (
966-
(!row?.modelProvider || row.modelProvider === defaults?.modelProvider) &&
967-
(!row?.model || row.model === defaults?.model)
968-
);
969-
}
970-
971962
function buildThinkingOptions(
972963
levels: readonly GatewayThinkingLevelOption[],
973964
currentOverride: string,
@@ -1006,18 +997,14 @@ function resolveThinkingLevelOptions(
1006997
model: string | null,
1007998
catalog: readonly ThinkingCatalogEntry[],
1008999
): GatewayThinkingLevelOption[] {
1009-
const sessionModelMatchesDefaultsLocal =
1010-
(!activeRow?.modelProvider || activeRow.modelProvider === defaults?.modelProvider) &&
1011-
(!activeRow?.model || activeRow.model === defaults?.model);
1000+
const modelMatchesDefaults = sessionModelMatchesDefaults(activeRow, defaults);
10121001
const catalogEntry =
10131002
provider && model
10141003
? catalog.find((entry) => entry.provider === provider && entry.id === model)
10151004
: undefined;
10161005
const explicitLevels =
10171006
(activeRow?.thinkingLevels?.length ? activeRow.thinkingLevels : null) ??
1018-
(sessionModelMatchesDefaultsLocal && defaults?.thinkingLevels?.length
1019-
? defaults.thinkingLevels
1020-
: null);
1007+
(modelMatchesDefaults && defaults?.thinkingLevels?.length ? defaults.thinkingLevels : null);
10211008
if (explicitLevels) {
10221009
if (catalogEntry?.reasoning === false && isOffOnlyThinkingLevels(explicitLevels)) {
10231010
return [];
@@ -1026,9 +1013,7 @@ function resolveThinkingLevelOptions(
10261013
}
10271014
const explicitLabels =
10281015
(activeRow?.thinkingOptions?.length ? activeRow.thinkingOptions : null) ??
1029-
(sessionModelMatchesDefaultsLocal && defaults?.thinkingOptions?.length
1030-
? defaults.thinkingOptions
1031-
: null);
1016+
(modelMatchesDefaults && defaults?.thinkingOptions?.length ? defaults.thinkingOptions : null);
10321017
if (catalogEntry?.reasoning === false) {
10331018
if (!explicitLabels || explicitLabels.every(isOffThinkingOption)) {
10341019
return [];

ui/src/ui/chat/slash-command-executor.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "../chat-model-ref.ts";
1010
import type { GatewayBrowserClient } from "../gateway.ts";
1111
import { DEFAULT_AGENT_ID, DEFAULT_MAIN_KEY, parseAgentSessionKey } from "../session-key.ts";
12+
import { sessionModelMatchesDefaults } from "../session-model-defaults.ts";
1213
import {
1314
normalizeLowercaseStringOrEmpty,
1415
normalizeOptionalLowercaseString,
@@ -594,16 +595,6 @@ function resolveThinkingLevelOptionsForSession(
594595
}));
595596
}
596597

597-
function sessionModelMatchesDefaults(
598-
session: GatewaySessionRow | undefined,
599-
defaults: SessionsListResult["defaults"] | undefined,
600-
): boolean {
601-
return (
602-
(!session?.modelProvider || session.modelProvider === defaults?.modelProvider) &&
603-
(!session?.model || session.model === defaults?.model)
604-
);
605-
}
606-
607598
async function loadCurrentSession(
608599
client: GatewayBrowserClient,
609600
sessionKey: string,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Shared helpers for comparing session rows against list defaults.
2+
import type { GatewaySessionRow, SessionsListResult } from "./types.ts";
3+
4+
type SessionModelFields = Pick<GatewaySessionRow, "model" | "modelProvider">;
5+
6+
export function sessionModelMatchesDefaults(
7+
session: SessionModelFields | null | undefined,
8+
defaults: SessionsListResult["defaults"] | undefined,
9+
): boolean {
10+
return (
11+
(!session?.modelProvider || session.modelProvider === defaults?.modelProvider) &&
12+
(!session?.model || session.model === defaults?.model)
13+
);
14+
}

ui/src/ui/views/sessions.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { icons } from "../icons.ts";
66
import { pathForTab } from "../navigation.ts";
77
import { formatSessionTokens } from "../presenter.ts";
88
import { formatGoalDetail, formatGoalSummary } from "../session-goal.ts";
9+
import { sessionModelMatchesDefaults } from "../session-model-defaults.ts";
910
import { isSessionRunActive } from "../session-run-state.ts";
1011
import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "../string-coerce.ts";
1112
import {
@@ -97,31 +98,21 @@ function getAgentIdentity(
9798
return Object.hasOwn(agentIdentityById, agentId) ? (agentIdentityById[agentId] ?? null) : null;
9899
}
99100

100-
function rowMatchesSessionDefaults(
101-
row: GatewaySessionRow,
102-
defaults: SessionsListResult["defaults"] | undefined,
103-
): boolean {
104-
return (
105-
(!row.modelProvider || row.modelProvider === defaults?.modelProvider) &&
106-
(!row.model || row.model === defaults?.model)
107-
);
108-
}
109-
110101
function resolveThinkLevelOptions(
111102
row: GatewaySessionRow,
112103
defaults?: SessionsListResult["defaults"],
113104
): readonly { value: string; label: string }[] {
114-
const sessionModelMatchesDefaults = rowMatchesSessionDefaults(row, defaults);
105+
const modelMatchesDefaults = sessionModelMatchesDefaults(row, defaults);
115106
const defaultLabel = formatInheritedThinkingLabel(
116-
row.thinkingDefault ?? (sessionModelMatchesDefaults ? defaults?.thinkingDefault : undefined),
107+
row.thinkingDefault ?? (modelMatchesDefaults ? defaults?.thinkingDefault : undefined),
117108
);
118109
const options: readonly GatewayThinkingLevelOption[] = row.thinkingLevels?.length
119110
? row.thinkingLevels
120-
: sessionModelMatchesDefaults && defaults?.thinkingLevels?.length
111+
: modelMatchesDefaults && defaults?.thinkingLevels?.length
121112
? defaults.thinkingLevels
122113
: (row.thinkingOptions?.length
123114
? row.thinkingOptions
124-
: sessionModelMatchesDefaults && defaults?.thinkingOptions?.length
115+
: modelMatchesDefaults && defaults?.thinkingOptions?.length
125116
? defaults.thinkingOptions
126117
: DEFAULT_THINK_LEVELS
127118
).map((label) => ({

0 commit comments

Comments
 (0)