History

Normalize branch and model selection handling

- Deduplicate terminal IDs and favorite model slugs with trim-aware iteration - Use effect-based filtering for local branch and built-in model lists - Switch stable array handling to non-mutating `toSorted`

Julius Marminge committed 6 months ago

Commit 7793bd61 parent 7f03f4d8 files · +63 −23Browse files

Showing the changes to apps/web/src/modelSelection.ts (1 of 8 files). Show all

Unified · Split

apps/web/src/modelSelection.ts+8−4
@@ -14,6 +14,8 @@ import { · 13 unmodified lines
1414 } from "@t3tools/shared/model";
1515 import { getComposerProviderState } from "./components/chat/composerProviderState";
1616 import { UnifiedSettings } from "@t3tools/contracts/settings";
17+import * as Arr from "effect/Array";
18+import * as Result from "effect/Result";
1719 import {
1820 getDefaultServerModel,
1921 getProviderModels,
@@ -150,9 +152,9 @@ export function getAppModelOptions( · 130 unmodified lines
150152 const options: AppModelOption[] = getProviderModels(providers, provider).map(toAppModelOption);
151153 const seen = new Set(options.map((option) => option.slug));
152154 const builtInModelSlugs = new Set(
153− getProviderModels(providers, provider)
154− .filter((model) => !model.isCustom)
155− .map((model) => model.slug),
155+ Arr.filterMap(getProviderModels(providers, provider), (model) =>
156+ model.isCustom ? Result.failVoid : Result.succeed(model.slug),
157+ ),
156158 );
157159
158160 // Read from the default instance's config first (that's where edits
@@ -198,7 +200,9 @@ export function getAppModelOptionsForInstance( · 39 unmodified lines
198200 const options: AppModelOption[] = entry.models.map(toAppModelOption);
199201 const seen = new Set(options.map((option) => option.slug));
200202 const builtInModelSlugs = new Set(
201− entry.models.filter((model) => !model.isCustom).map((model) => model.slug),
203+ Arr.filterMap(entry.models, (model) =>
204+ model.isCustom ? Result.failVoid : Result.succeed(model.slug),
205+ ),
202206 );
203207
204208 const customModels = readInstanceCustomModels(settings, entry.instanceId, entry.driverKind);