mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:10:43 +00:00
refactor: share ui select option helper
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
||||
normalizeChatModelOverrideValue,
|
||||
resolvePreferredServerChatModelValue,
|
||||
} from "./chat-model-ref.ts";
|
||||
import { normalizeLowercaseStringOrEmpty } from "./string-coerce.ts";
|
||||
import { pushUniqueTrimmedSelectOption } from "./select-options.ts";
|
||||
import type { ModelCatalogEntry } from "./types.ts";
|
||||
|
||||
type ChatModelSelectStateInput = Pick<
|
||||
@@ -65,16 +65,7 @@ function buildChatModelOptions(
|
||||
const options: ChatModelSelectOption[] = [];
|
||||
|
||||
const addOption = (value: string, label?: string) => {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) {
|
||||
return;
|
||||
}
|
||||
const key = normalizeLowercaseStringOrEmpty(trimmed);
|
||||
if (seen.has(key)) {
|
||||
return;
|
||||
}
|
||||
seen.add(key);
|
||||
options.push({ value: trimmed, label: label ?? trimmed });
|
||||
pushUniqueTrimmedSelectOption(options, seen, value, (trimmed) => label ?? trimmed);
|
||||
};
|
||||
|
||||
for (const entry of catalog) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from "../chat-model-select-state.ts";
|
||||
import { refreshVisibleToolsEffectiveForCurrentSession } from "../controllers/agents.ts";
|
||||
import { loadSessions } from "../controllers/sessions.ts";
|
||||
import { pushUniqueTrimmedSelectOption } from "../select-options.ts";
|
||||
import { parseAgentSessionKey } from "../session-key.ts";
|
||||
import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "../string-coerce.ts";
|
||||
import {
|
||||
@@ -146,24 +147,17 @@ function buildThinkingOptions(
|
||||
const options: ChatThinkingSelectOption[] = [];
|
||||
|
||||
const addOption = (value: string, label?: string) => {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) {
|
||||
return;
|
||||
}
|
||||
const key = normalizeLowercaseStringOrEmpty(trimmed);
|
||||
if (seen.has(key)) {
|
||||
return;
|
||||
}
|
||||
seen.add(key);
|
||||
options.push({
|
||||
value: trimmed,
|
||||
label:
|
||||
pushUniqueTrimmedSelectOption(
|
||||
options,
|
||||
seen,
|
||||
value,
|
||||
(trimmed) =>
|
||||
label ??
|
||||
trimmed
|
||||
.split(/[-_]/g)
|
||||
.map((part) => (part ? part[0].toUpperCase() + part.slice(1) : part))
|
||||
.join(" "),
|
||||
});
|
||||
);
|
||||
};
|
||||
|
||||
for (const label of listThinkingLevelLabels(provider)) {
|
||||
|
||||
24
ui/src/ui/select-options.ts
Normal file
24
ui/src/ui/select-options.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { normalizeLowercaseStringOrEmpty } from "./string-coerce.ts";
|
||||
|
||||
export type SelectOption = {
|
||||
value: string;
|
||||
label: string;
|
||||
};
|
||||
|
||||
export function pushUniqueTrimmedSelectOption(
|
||||
options: SelectOption[],
|
||||
seen: Set<string>,
|
||||
value: string,
|
||||
labelForValue: (trimmed: string) => string,
|
||||
) {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) {
|
||||
return;
|
||||
}
|
||||
const key = normalizeLowercaseStringOrEmpty(trimmed);
|
||||
if (seen.has(key)) {
|
||||
return;
|
||||
}
|
||||
seen.add(key);
|
||||
options.push({ value: trimmed, label: labelForValue(trimmed) });
|
||||
}
|
||||
Reference in New Issue
Block a user