Skip to content
Source
Sign inSign up
Open History to see the last commit

composerModelMentions.ts

43 lines2.0 KB

1import { rankComposerModelMentions } from "@t3tools/client-runtime/composer-model-mentions";
2import type { ProviderInstanceId } from "@t3tools/contracts";
3​
4import { isProviderInstancePickerReady, type ProviderInstanceEntry } from "../../providerInstances";
5import type { ComposerCommandItem } from "./ComposerCommandMenu";
6import { getDisplayModelName, type ModelEsque } from "./providerIconUtils";
7​
8type ComposerModelItem = Extract<ComposerCommandItem, { type: "model" }>;
9​
10export function matchComposerModelItems(input: {
11 readonly instanceEntries: ReadonlyArray<ProviderInstanceEntry>;
12 readonly modelOptionsByInstance: ReadonlyMap<ProviderInstanceId, ReadonlyArray<ModelEsque>>;
13 readonly query: string;
14}): ComposerModelItem[] {
15 const candidates: Array<{ entry: ProviderInstanceEntry; option: ModelEsque }> = [];
16 for (const entry of input.instanceEntries) {
17 if (!isProviderInstancePickerReady(entry)) continue;
18 for (const option of input.modelOptionsByInstance.get(entry.instanceId) ?? []) {
19 // The picker hides legacy models by default; skip them so they don't fill the result cap.
20 if (option.isLegacy || option.isUnavailable) continue;
21 candidates.push({ entry, option });
22 }
23 }
24​
25 return rankComposerModelMentions(candidates, input.query, ({ entry, option }) => ({
26 name: option.name,
27 ...(option.shortName ? { shortName: option.shortName } : {}),
28 ...(option.subProvider ? { subProvider: option.subProvider } : {}),
29 driverKind: entry.driverKind,
30 providerDisplayName: entry.displayName,
31 })).map(({ entry, option }) => ({
32 id: `model:${entry.instanceId}:${option.slug}`,
33 type: "model",
34 instanceId: entry.instanceId,
35 model: option.slug,
36 driverKind: entry.driverKind,
37 providerDisplayName: entry.displayName,
38 acpRegistryAgentId: entry.acpRegistryAgentId,
39 acpRegistryIconUrl: entry.acpRegistryIconUrl,
40 label: getDisplayModelName(option),
41 description: option.subProvider ?? entry.displayName,
42 }));