From 35a44b749074ba3d968cdf39388ced2b5b811aab Mon Sep 17 00:00:00 2001 From: pttsrd Date: Sat, 21 Nov 2026 09:54:45 +0800 Subject: [PATCH] feat(models): show ACP model credit multipliers in pickers CodeBuddy Code reports each model's credit multiplier as the ACP model option description (e.g. "x0.29 credits"). T3 parsed that field but dropped it when building the client model catalog. Forward compact descriptions through ServerProviderModel and render them as secondary text in web/mobile model pickers and @ mentions, including search. Long prose descriptions are filtered out so other ACP agents keep their current UI. --- .../threads/ThreadSettingsRows.shared.tsx | 7 +++- .../threads/thread-settings-sheet-state.ts | 1 + .../threads/use-composer-command-menu.ts | 10 ++++-- apps/mobile/src/lib/modelOptions.ts | 4 +++ apps/web/src/components/chat/ModelListRow.tsx | 15 ++++++++ .../components/chat/ModelPickerContent.tsx | 4 +++ .../components/chat/composerModelMentions.ts | 5 ++- .../src/components/chat/providerIconUtils.ts | 1 + apps/web/src/modelSelection.ts | 2 ++ .../src/composerModelMentions.ts | 1 + .../client-runtime/src/modelSearch.test.ts | 20 +++++++++++ packages/client-runtime/src/modelSearch.ts | 11 +++++- packages/contracts/src/server.ts | 2 ++ .../src/server/driver.test.ts | 34 ++++++++++++++++++- .../src/server/driver.ts | 14 +++++++- 15 files changed, 123 insertions(+), 8 deletions(-) diff --git a/apps/mobile/src/features/threads/ThreadSettingsRows.shared.tsx b/apps/mobile/src/features/threads/ThreadSettingsRows.shared.tsx index 6d46c230e6761..cf5a36339c9fd 100644 --- a/apps/mobile/src/features/threads/ThreadSettingsRows.shared.tsx +++ b/apps/mobile/src/features/threads/ThreadSettingsRows.shared.tsx @@ -53,7 +53,9 @@ export function ModelRowContent( )} > ) : null} + {props.option.description ? ( + {props.option.description} + ) : null} {props.trailingSelection} diff --git a/apps/mobile/src/features/threads/thread-settings-sheet-state.ts b/apps/mobile/src/features/threads/thread-settings-sheet-state.ts index 4fff09253ab4b..9d39fdbda6687 100644 --- a/apps/mobile/src/features/threads/thread-settings-sheet-state.ts +++ b/apps/mobile/src/features/threads/thread-settings-sheet-state.ts @@ -30,6 +30,7 @@ export function modelMatchesCatalogQuery(input: { return [ input.model.label, input.model.subtitle, + input.model.description ?? "", input.model.selection.model, input.providerLabel, ].some((value) => value.toLocaleLowerCase().includes(query)); diff --git a/apps/mobile/src/features/threads/use-composer-command-menu.ts b/apps/mobile/src/features/threads/use-composer-command-menu.ts index b5b6ce681c018..684965b4d8a5e 100644 --- a/apps/mobile/src/features/threads/use-composer-command-menu.ts +++ b/apps/mobile/src/features/threads/use-composer-command-menu.ts @@ -212,6 +212,7 @@ export function buildComposerModelItems( query, (option) => ({ name: option.label, + ...(option.description ? { description: option.description } : {}), ...(option.subtitle ? { subProvider: option.subtitle } : {}), driverKind: option.providerDriver, providerDisplayName: option.providerLabel, @@ -221,9 +222,12 @@ export function buildComposerModelItems( type: "model", option, label: option.label, - description: option.subtitle - ? `${option.providerLabel} · ${option.subtitle}` - : option.providerLabel, + description: [ + option.subtitle ? `${option.providerLabel} · ${option.subtitle}` : option.providerLabel, + option.description, + ] + .filter(Boolean) + .join(" · "), })); } diff --git a/apps/mobile/src/lib/modelOptions.ts b/apps/mobile/src/lib/modelOptions.ts index f3d6fc022c0a4..ee92b65a4eff2 100644 --- a/apps/mobile/src/lib/modelOptions.ts +++ b/apps/mobile/src/lib/modelOptions.ts @@ -40,6 +40,8 @@ export type ModelOption = { readonly key: string; readonly label: string; readonly shortName?: string; + /** Secondary provider metadata, such as a credit multiplier. Kept separate from `subtitle`, which groups models by sub-provider. */ + readonly description?: string | undefined; readonly subtitle: string; readonly providerKey: string; readonly providerLabel: string; @@ -421,6 +423,7 @@ export function buildModelOptions( key, label: model.name, ...(shortName ? { shortName } : {}), + ...(model.description ? { description: model.description } : {}), subtitle: model.subProvider ?? "", providerKey: provider.instanceId, providerLabel, @@ -491,6 +494,7 @@ export function buildModelOptions( key, label: model?.name ?? fallbackModelSelection.model, ...(shortName ? { shortName } : {}), + ...(model?.description ? { description: model.description } : {}), subtitle: model?.subProvider ?? "", providerKey: fallbackModelSelection.instanceId, providerLabel, diff --git a/apps/web/src/components/chat/ModelListRow.tsx b/apps/web/src/components/chat/ModelListRow.tsx index 74dae2dc23582..0ade1bff2d21c 100644 --- a/apps/web/src/components/chat/ModelListRow.tsx +++ b/apps/web/src/components/chat/ModelListRow.tsx @@ -16,6 +16,7 @@ export const ModelListRow = memo(function ModelListRow(props: { index: number; slug: string; name: string; + description?: string | undefined; subProvider?: string | undefined; instanceId: ProviderInstanceId; driverKind: ProviderDriverKind; @@ -87,6 +88,20 @@ export const ModelListRow = memo(function ModelListRow(props: { {props.subProvider} ) : null} + {props.description ? ( + + + {props.description} + + } + /> + + {props.description} + + + ) : null} {props.showNewBadge ? ( matchesLockedProvider(m)) : result; return rankModelPickerSearch(candidates, searchQuery, (model) => ({ name: model.name, + ...(model.description ? { description: model.description } : {}), ...(model.shortName ? { shortName: model.shortName } : {}), ...(model.subProvider ? { subProvider: model.subProvider } : {}), driverKind: model.driverKind, @@ -1215,6 +1218,7 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: { index={index} slug={model.slug} name={model.name} + description={model.description} subProvider={model.subProvider} instanceId={model.instanceId} driverKind={model.driverKind} diff --git a/apps/web/src/components/chat/composerModelMentions.ts b/apps/web/src/components/chat/composerModelMentions.ts index b0a8d0bd3b649..9f50e978c5bbb 100644 --- a/apps/web/src/components/chat/composerModelMentions.ts +++ b/apps/web/src/components/chat/composerModelMentions.ts @@ -24,6 +24,7 @@ export function matchComposerModelItems(input: { return rankComposerModelMentions(candidates, input.query, ({ entry, option }) => ({ name: option.name, + ...(option.description ? { description: option.description } : {}), ...(option.shortName ? { shortName: option.shortName } : {}), ...(option.subProvider ? { subProvider: option.subProvider } : {}), driverKind: entry.driverKind, @@ -38,6 +39,8 @@ export function matchComposerModelItems(input: { acpRegistryAgentId: entry.acpRegistryAgentId, acpRegistryIconUrl: entry.acpRegistryIconUrl, label: getDisplayModelName(option), - description: option.subProvider ?? entry.displayName, + description: option.description + ? `${option.subProvider ?? entry.displayName} · ${option.description}` + : (option.subProvider ?? entry.displayName), })); } diff --git a/apps/web/src/components/chat/providerIconUtils.ts b/apps/web/src/components/chat/providerIconUtils.ts index 565dc25c05f1d..54ba098b5b384 100644 --- a/apps/web/src/components/chat/providerIconUtils.ts +++ b/apps/web/src/components/chat/providerIconUtils.ts @@ -4,6 +4,7 @@ import { resolveModelShortName } from "@t3tools/client-runtime/provider-clients" export type ModelEsque = { slug: string; name: string; + description?: string | undefined; shortName?: string | undefined; subProvider?: string | undefined; aliases?: ReadonlyArray | undefined; diff --git a/apps/web/src/modelSelection.ts b/apps/web/src/modelSelection.ts index ff8ac2b1a80eb..10a0c40d7152e 100644 --- a/apps/web/src/modelSelection.ts +++ b/apps/web/src/modelSelection.ts @@ -64,6 +64,7 @@ export function readInstanceCustomModels( export interface AppModelOption { slug: string; name: string; + description?: string; shortName?: string; subProvider?: string; aliases?: ReadonlyArray; @@ -102,6 +103,7 @@ function toAppModelOption( name: model.name, isCustom: model.isCustom, }; + if (model.description) option.description = model.description; const shortName = resolveModelShortName(model, driverKind); if (shortName) option.shortName = shortName; if (model.subProvider) option.subProvider = model.subProvider; diff --git a/packages/client-runtime/src/composerModelMentions.ts b/packages/client-runtime/src/composerModelMentions.ts index 140786d778ee2..c2ddac9991988 100644 --- a/packages/client-runtime/src/composerModelMentions.ts +++ b/packages/client-runtime/src/composerModelMentions.ts @@ -31,6 +31,7 @@ export function rankComposerModelMentions( model.name, model.shortName, model.subProvider, + model.description, model.driverKind, model.providerDisplayName, ] diff --git a/packages/client-runtime/src/modelSearch.test.ts b/packages/client-runtime/src/modelSearch.test.ts index 3e6be15d89cf4..37e1926ded798 100644 --- a/packages/client-runtime/src/modelSearch.test.ts +++ b/packages/client-runtime/src/modelSearch.test.ts @@ -58,6 +58,7 @@ type CatalogModel = { providerDisplayName: string; name: string; subProvider?: string; + description?: string; isFavorite?: boolean; }; @@ -134,6 +135,25 @@ function search(query: string, models: ReadonlyArray = catalog): s } describe("rankModelPickerSearch", () => { + it("matches provider metadata such as a credit multiplier", () => { + const models: CatalogModel[] = [ + { + driverKind: "acpRegistry", + providerDisplayName: "Codebuddy", + name: "Hy4", + description: "x0.29 credits", + }, + { + driverKind: "acpRegistry", + providerDisplayName: "Codebuddy", + name: "Hy4 flash", + description: "x0.00 credits", + }, + ]; + expect(search("x0.00", models)).toEqual(["Hy4 flash"]); + expect(search("credits", models)).toEqual(["Hy4", "Hy4 flash"]); + }); + it("keeps newest first when a version token narrows the family", () => { expect(search("opus 4")).toEqual([ "Claude Opus 4.8", diff --git a/packages/client-runtime/src/modelSearch.ts b/packages/client-runtime/src/modelSearch.ts index bf1a278c87ad8..07d0033f6e78a 100644 --- a/packages/client-runtime/src/modelSearch.ts +++ b/packages/client-runtime/src/modelSearch.ts @@ -6,6 +6,7 @@ export type ModelPickerSearchableModel = { name: string; shortName?: string; subProvider?: string; + description?: string; isFavorite?: boolean; }; @@ -20,6 +21,7 @@ function getModelPickerSearchFields(model: ModelPickerSearchableModel): string[] normalizeSearchQuery(model.driverKind), normalizeSearchQuery(model.providerDisplayName), buildModelPickerSearchText(model), + ...(model.description ? [normalizeSearchQuery(model.description)] : []), ]; } @@ -46,7 +48,14 @@ function normalizeModelName(name: string): string { function buildModelPickerSearchText(model: ModelPickerSearchableModel): string { return normalizeSearchQuery( - [model.name, model.shortName, model.subProvider, model.driverKind, model.providerDisplayName] + [ + model.name, + model.shortName, + model.subProvider, + model.driverKind, + model.providerDisplayName, + model.description, + ] .filter((value): value is string => typeof value === "string" && value.length > 0) .join(" "), ); diff --git a/packages/contracts/src/server.ts b/packages/contracts/src/server.ts index afd870ef97cc7..3462ff03ccb25 100644 --- a/packages/contracts/src/server.ts +++ b/packages/contracts/src/server.ts @@ -78,6 +78,8 @@ export type ServerProviderAuth = typeof ServerProviderAuth.Type; export const ServerProviderModel = Schema.Struct({ slug: TrimmedNonEmptyString, name: TrimmedNonEmptyString, + /** Secondary model metadata reported by the provider, such as a credit multiplier. */ + description: Schema.optional(TrimmedNonEmptyString), shortName: Schema.optional(TrimmedNonEmptyString), subProvider: Schema.optional(TrimmedNonEmptyString), aliases: Schema.optional(Schema.Array(TrimmedNonEmptyString)), diff --git a/packages/provider-acp-registry/src/server/driver.test.ts b/packages/provider-acp-registry/src/server/driver.test.ts index 684eb21d7456b..b3cb6b4e2214c 100644 --- a/packages/provider-acp-registry/src/server/driver.test.ts +++ b/packages/provider-acp-registry/src/server/driver.test.ts @@ -103,6 +103,37 @@ function providerWithModels( } describe("acpRegistrySnapshotReadiness", () => { + it("forwards ACP model descriptions to the client model catalog", () => { + const provider = providerWithModels( + [{ id: "hy4", name: "Hy4", description: "x0.29 credits" }], + "hy4", + ); + expect(provider.models).toMatchObject([ + { slug: "hy4", name: "Hy4", description: "x0.29 credits" }, + ]); + + const live = normalizeAcpRegistryLiveConfiguration([ + { + id: "model", + name: "Model", + description: "Select the AI model to use for this session", + category: "model", + type: "select", + currentValue: "hy4", + options: [{ value: "hy4", name: "Hy4", description: "x0.29 credits" }], + }, + ]); + expect( + applyAcpRegistryLiveConfiguration(providerWithModels([], null), live, []).models, + ).toMatchObject([{ slug: "hy4", description: "x0.29 credits" }]); + + const verbose = providerWithModels( + [{ id: "verbose", name: "Verbose", description: "A very long prose description ".repeat(3) }], + "verbose", + ); + expect(verbose.models[0]).not.toHaveProperty("description"); + }); + it("keeps the custom model display name and options saved by the Settings editor", () => { const fastMode = { id: "fast", label: "Fast mode", type: "boolean" } as const; const snapshot = buildCheckedAcpRegistrySnapshot({ @@ -260,7 +291,7 @@ describe("acpRegistrySnapshotReadiness", () => { ready: true, icon: null, authMethods: [], - models: [{ id: "probe-model", name: "Probe model", description: null }], + models: [{ id: "probe-model", name: "Probe model", description: "x0.29 credits" }], currentModelId: "probe-model", configOptions: [], sessionManagement: { @@ -325,6 +356,7 @@ describe("acpRegistrySnapshotReadiness", () => { ).toMatchObject([ { slug: "probe-model", + description: "x0.29 credits", isDefault: true, capabilities: { optionDescriptors: [{ id: "effort", currentValue: "high" }] }, }, diff --git a/packages/provider-acp-registry/src/server/driver.ts b/packages/provider-acp-registry/src/server/driver.ts index 46d8ed3219aa4..4449f6f1bfc8f 100644 --- a/packages/provider-acp-registry/src/server/driver.ts +++ b/packages/provider-acp-registry/src/server/driver.ts @@ -153,6 +153,17 @@ const makeUnsupportedTextGeneration = (): ProviderTextGeneration => { }; }; +/** + * Only compact provider metadata belongs in a model picker row. ACP agents can report long + * prose as an option description; forwarding that would crowd out the model name in every + * client. Credit multipliers such as `x0.29 credits` stay well under this limit. + */ +const MAX_FORWARDED_MODEL_DESCRIPTION_LENGTH = 32; +const isPickerDescription = (description: string | null | undefined): description is string => + typeof description === "string" && + description.length > 0 && + description.length <= MAX_FORWARDED_MODEL_DESCRIPTION_LENGTH; + function modelsFromDiscovery( discovery: | Pick< @@ -206,6 +217,7 @@ function modelsFromDiscovery( : discovered.map((model) => ({ slug: model.id, name: model.name, + ...(isPickerDescription(model.description) ? { description: model.description } : {}), isCustom: false, ...(model.id === discovery?.currentModelId ? { isDefault: true } : {}), capabilities: capabilitiesFor(model), @@ -382,7 +394,7 @@ export function applyAcpRegistryLiveConfiguration( models: probedModels.map((model) => ({ id: model.slug, name: model.name, - description: null, + description: model.description ?? null, })), currentModelId: selectedProbedModelId, };