Search now matches across model label, id, provider, and description with multi-token fuzzy matching, so "kimi zen" finds the OpenCode Zen Kimi model.
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import type { AgentModelDefinition } from "@server/server/agent/agent-sdk-types";
|
|
import type { AgentProviderDefinition } from "@server/server/agent/provider-manifest";
|
|
import { buildFavoriteModelKey, type FavoriteModelRow } from "@/hooks/use-form-preferences";
|
|
|
|
export type SelectorModelRow = FavoriteModelRow;
|
|
|
|
export function resolveProviderLabel(
|
|
providerDefinitions: AgentProviderDefinition[],
|
|
providerId: string,
|
|
): string {
|
|
return (
|
|
providerDefinitions.find((definition) => definition.id === providerId)?.label ?? providerId
|
|
);
|
|
}
|
|
|
|
export function buildSelectedTriggerLabel(modelLabel: string): string {
|
|
return modelLabel;
|
|
}
|
|
|
|
export function buildModelRows(
|
|
providerDefinitions: AgentProviderDefinition[],
|
|
allProviderModels: Map<string, AgentModelDefinition[]>,
|
|
): SelectorModelRow[] {
|
|
const providerLabelMap = new Map(
|
|
providerDefinitions.map((definition) => [definition.id, definition.label]),
|
|
);
|
|
const rows: SelectorModelRow[] = [];
|
|
|
|
for (const definition of providerDefinitions) {
|
|
const providerLabel = providerLabelMap.get(definition.id) ?? definition.label;
|
|
for (const model of allProviderModels.get(definition.id) ?? []) {
|
|
rows.push({
|
|
favoriteKey: buildFavoriteModelKey({ provider: definition.id, modelId: model.id }),
|
|
provider: definition.id,
|
|
providerLabel,
|
|
modelId: model.id,
|
|
modelLabel: model.label,
|
|
description: model.description,
|
|
});
|
|
}
|
|
}
|
|
|
|
return rows;
|
|
}
|
|
|
|
export function matchesSearch(row: SelectorModelRow, normalizedQuery: string): boolean {
|
|
if (!normalizedQuery) {
|
|
return true;
|
|
}
|
|
|
|
const haystack = [row.modelLabel, row.modelId, row.providerLabel, row.description ?? ""]
|
|
.join(" ")
|
|
.toLowerCase();
|
|
|
|
const tokens = normalizedQuery.split(/\s+/).filter((token) => token.length > 0);
|
|
return tokens.every((token) => haystack.includes(token));
|
|
}
|