@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 43 lines 1.95 KB
Raw
1 import { rankComposerModelMentions } from "@t3tools/client-runtime/composer-model-mentions";
2 import type { ProviderInstanceId } from "@t3tools/contracts";
3
4 import { isProviderInstancePickerReady, type ProviderInstanceEntry } from "../../providerInstances";
5 import type { ComposerCommandItem } from "./ComposerCommandMenu";
6 import { getDisplayModelName, type ModelEsque } from "./providerIconUtils";
7
8 type ComposerModelItem = Extract<ComposerCommandItem, { type: "model" }>;
9
10 export 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 }));
43 }