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`
This commit is contained in:
1 parent
7f03f4d19a
commit
7793bd6de7
8 files changed
+63
-23
No files matched your search
@@ -194,6 +194,7 @@ import {
|
||||
isVersionMismatchDismissed,
|
||||
resolveServerConfigVersionMismatch,
|
||||
} from "../versionSkew";
|
||||
import { equals } from "effect/Equal";
|
||||
|
||||
const IMAGE_ONLY_BOOTSTRAP_PROMPT =
|
||||
"[User attached one or more images without additional text. Respond using the conversation context and the attached image(s).]";
|
||||
@@ -438,8 +439,8 @@ function terminalIdListsEqual(left: readonly string[], right: readonly string[])
|
||||
if (left.length === 0) {
|
||||
return true;
|
||||
}
|
||||
const sortedLeft = [...left].sort((a, b) => a.localeCompare(b));
|
||||
const sortedRight = [...right].sort((a, b) => a.localeCompare(b));
|
||||
const sortedLeft = left.toSorted((a, b) => a.localeCompare(b));
|
||||
const sortedRight = right.toSorted((a, b) => a.localeCompare(b));
|
||||
for (let index = 0; index < sortedLeft.length; index += 1) {
|
||||
if (sortedLeft[index] !== sortedRight[index]) {
|
||||
return false;
|
||||
|
||||
@@ -870,7 +870,15 @@ export default function ThreadTerminalDrawer({
|
||||
const didResizeDuringDragRef = useRef(false);
|
||||
|
||||
const normalizedTerminalIds = useMemo(() => {
|
||||
return [...new Set(terminalIds.map((id) => id.trim()).filter((id) => id.length > 0))];
|
||||
const normalizedIds: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
for (const id of terminalIds) {
|
||||
const trimmedId = id.trim();
|
||||
if (trimmedId.length === 0 || seen.has(trimmedId)) continue;
|
||||
seen.add(trimmedId);
|
||||
normalizedIds.push(trimmedId);
|
||||
}
|
||||
return normalizedIds;
|
||||
}, [terminalIds]);
|
||||
|
||||
const resolvedActiveTerminalId =
|
||||
@@ -904,13 +912,17 @@ export default function ThreadTerminalDrawer({
|
||||
};
|
||||
|
||||
for (const terminalGroup of terminalGroups) {
|
||||
const nextTerminalIds = [
|
||||
...new Set(terminalGroup.terminalIds.map((id) => id.trim()).filter((id) => id.length > 0)),
|
||||
].filter((terminalId) => {
|
||||
if (!validTerminalIdSet.has(terminalId)) return false;
|
||||
if (assignedTerminalIds.has(terminalId)) return false;
|
||||
return true;
|
||||
});
|
||||
const nextTerminalIds: string[] = [];
|
||||
const seenGroupTerminalIds = new Set<string>();
|
||||
for (const id of terminalGroup.terminalIds) {
|
||||
const terminalId = id.trim();
|
||||
if (terminalId.length === 0) continue;
|
||||
if (seenGroupTerminalIds.has(terminalId)) continue;
|
||||
seenGroupTerminalIds.add(terminalId);
|
||||
if (!validTerminalIdSet.has(terminalId)) continue;
|
||||
if (assignedTerminalIds.has(terminalId)) continue;
|
||||
nextTerminalIds.push(terminalId);
|
||||
}
|
||||
if (nextTerminalIds.length === 0) continue;
|
||||
|
||||
for (const terminalId of nextTerminalIds) {
|
||||
|
||||
@@ -14,8 +14,10 @@ import {
|
||||
import { scopeThreadRef } from "@t3tools/client-runtime";
|
||||
import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";
|
||||
import { createModelSelection } from "@t3tools/shared/model";
|
||||
import * as Arr from "effect/Array";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Equal from "effect/Equal";
|
||||
import * as Result from "effect/Result";
|
||||
import { APP_VERSION, HOSTED_APP_CHANNEL, HOSTED_APP_CHANNEL_LABEL } from "../../branding";
|
||||
import {
|
||||
canCheckForUpdate,
|
||||
@@ -1143,7 +1145,12 @@ export function ProviderSettingsPanel() {
|
||||
nextFavoriteModels: ReadonlyArray<string>,
|
||||
) => {
|
||||
const favoriteModels = [
|
||||
...new Set(nextFavoriteModels.map((slug) => slug.trim()).filter((slug) => slug.length > 0)),
|
||||
...new Set(
|
||||
Arr.filterMap(nextFavoriteModels, (slug) => {
|
||||
const trimmedSlug = slug.trim();
|
||||
return trimmedSlug.length > 0 ? Result.succeed(trimmedSlug) : Result.failVoid;
|
||||
}),
|
||||
),
|
||||
];
|
||||
updateSettings({
|
||||
favorites: [
|
||||
@@ -1249,9 +1256,9 @@ export function ProviderSettingsPanel() {
|
||||
hiddenModels: [],
|
||||
modelOrder: [],
|
||||
};
|
||||
const favoriteModels = (settings.favorites ?? [])
|
||||
.filter((favorite) => favorite.provider === row.instanceId)
|
||||
.map((favorite) => favorite.model);
|
||||
const favoriteModels = Arr.filterMap(settings.favorites ?? [], (favorite) =>
|
||||
favorite.provider === row.instanceId ? Result.succeed(favorite.model) : Result.failVoid,
|
||||
);
|
||||
const resetLabel = driverOption?.label ?? String(row.driver);
|
||||
const headerAction =
|
||||
row.isDefault && row.isDirty ? (
|
||||
|
||||
@@ -204,7 +204,7 @@ export function useSourceControlActionRunning(
|
||||
scope: SourceControlActionScope,
|
||||
kinds: ReadonlyArray<SourceControlActionKind>,
|
||||
): boolean {
|
||||
const stableKinds = useMemo(() => [...kinds].sort(), [kinds]);
|
||||
const stableKinds = useMemo(() => kinds.toSorted(), [kinds]);
|
||||
const appActionRunning = useSyncExternalStore(
|
||||
subscribeActionState,
|
||||
() => isAnyActionRunning(stableKinds, scope),
|
||||
|
||||
@@ -14,6 +14,8 @@ import {
|
||||
} from "@t3tools/shared/model";
|
||||
import { getComposerProviderState } from "./components/chat/composerProviderState";
|
||||
import { UnifiedSettings } from "@t3tools/contracts/settings";
|
||||
import * as Arr from "effect/Array";
|
||||
import * as Result from "effect/Result";
|
||||
import {
|
||||
getDefaultServerModel,
|
||||
getProviderModels,
|
||||
@@ -150,9 +152,9 @@ export function getAppModelOptions(
|
||||
const options: AppModelOption[] = getProviderModels(providers, provider).map(toAppModelOption);
|
||||
const seen = new Set(options.map((option) => option.slug));
|
||||
const builtInModelSlugs = new Set(
|
||||
getProviderModels(providers, provider)
|
||||
.filter((model) => !model.isCustom)
|
||||
.map((model) => model.slug),
|
||||
Arr.filterMap(getProviderModels(providers, provider), (model) =>
|
||||
model.isCustom ? Result.failVoid : Result.succeed(model.slug),
|
||||
),
|
||||
);
|
||||
|
||||
// Read from the default instance's config first (that's where edits
|
||||
@@ -198,7 +200,9 @@ export function getAppModelOptionsForInstance(
|
||||
const options: AppModelOption[] = entry.models.map(toAppModelOption);
|
||||
const seen = new Set(options.map((option) => option.slug));
|
||||
const builtInModelSlugs = new Set(
|
||||
entry.models.filter((model) => !model.isCustom).map((model) => model.slug),
|
||||
Arr.filterMap(entry.models, (model) =>
|
||||
model.isCustom ? Result.failVoid : Result.succeed(model.slug),
|
||||
),
|
||||
);
|
||||
|
||||
const customModels = readInstanceCustomModels(settings, entry.instanceId, entry.driverKind);
|
||||
|
||||
@@ -58,7 +58,15 @@ function createTerminalUiStateStorage() {
|
||||
}
|
||||
|
||||
function normalizeTerminalIds(terminalIds: string[]): string[] {
|
||||
return [...new Set(terminalIds.map((id) => id.trim()).filter((id) => id.length > 0))];
|
||||
const normalizedIds: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
for (const id of terminalIds) {
|
||||
const trimmedId = id.trim();
|
||||
if (trimmedId.length === 0 || seen.has(trimmedId)) continue;
|
||||
seen.add(trimmedId);
|
||||
normalizedIds.push(trimmedId);
|
||||
}
|
||||
return normalizedIds;
|
||||
}
|
||||
|
||||
function fallbackGroupId(terminalId: string): string {
|
||||
@@ -84,7 +92,7 @@ function findGroupIndexByTerminalId(
|
||||
}
|
||||
|
||||
function normalizeTerminalGroupIds(terminalIds: string[]): string[] {
|
||||
return [...new Set(terminalIds.map((id) => id.trim()).filter((id) => id.length > 0))];
|
||||
return normalizeTerminalIds(terminalIds);
|
||||
}
|
||||
|
||||
function normalizeTerminalGroups(
|
||||
|
||||
Reference in new issue
Block a user