Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions apps/mobile/src/components/ComposerToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function ComposerInlineControl(props: {
readonly icon?: ComponentProps<typeof SymbolView>["name"];
readonly iconNode?: ReactNode;
readonly label: string;
readonly maxWidth?: ViewStyle["maxWidth"];
readonly maxWidth?: ViewStyle["maxWidth"] | null;
readonly onPress?: () => void;
readonly selected?: boolean;
readonly static?: boolean;
Expand All @@ -50,7 +50,10 @@ export function ComposerInlineControl(props: {
className="h-11 flex-row items-center gap-2 rounded-xl px-2 active:bg-subtle"
disabled={props.disabled || props.static}
onPress={props.onPress}
style={{ maxWidth: props.maxWidth ?? 190, opacity: props.disabled ? 0.45 : 1 }}
style={{
maxWidth: props.maxWidth === null ? undefined : (props.maxWidth ?? 190),
opacity: props.disabled ? 0.45 : 1,
}}
>
{props.iconNode ? (
<View className="size-4 shrink-0 items-center justify-center">{props.iconNode}</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ export function ModelRowContent(
>
{props.leadingSelection}
<View className="min-w-0 flex-1">
<View className="flex-row items-center gap-2">
<Text
className="min-w-0 shrink text-base font-t3-medium text-foreground"
numberOfLines={props.labelNumberOfLines}
>
<View className="flex-row flex-wrap items-center gap-2">
<Text className="min-w-0 shrink text-base font-t3-medium text-foreground">
{props.option.label}
</Text>
{props.option.isDefault ? (
Expand Down
13 changes: 7 additions & 6 deletions apps/mobile/src/lib/modelOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("mobile model options", () => {
providerKey: "codex",
providerLabel: "Codex",
models: [
{ key: "codex:gpt-5.6-sol", label: "GPT-5.6 Sol", subtitle: "", isLegacy: false },
{ key: "codex:gpt-5.6-sol", label: "GPT-5.6 Sol", subtitle: "Codex", isLegacy: false },
{ key: "codex:gpt-5.4", label: "GPT-5.4", isLegacy: true },
],
},
Expand All @@ -71,7 +71,7 @@ describe("mobile model options", () => {
auth: { status: "authenticated" },
models: sources.map((source) => ({
slug: `${source.id}/claude-fable-5`,
name: "Claude Fable 5",
name: `${source.label}: Claude Fable 5`,
subProvider: source.label,
isCustom: false,
capabilities: null,
Expand All @@ -89,8 +89,8 @@ describe("mobile model options", () => {
expect(options).toMatchObject(
sources.map((source) => ({
key: `opencode_work:${source.id}/claude-fable-5`,
label: "Claude Fable 5",
subtitle: source.label,
label: `Claude Fable 5 · ${source.label}`,
subtitle: "OpenCode Work",
providerLabel: "OpenCode Work",
selection: {
instanceId: "opencode_work",
Expand Down Expand Up @@ -254,8 +254,8 @@ describe("mobile model options", () => {
const [option] = buildModelOptions(unavailableConfig, selection);
expect(option).toMatchObject({
key: `google_work:${selection.model}`,
label: model.name,
subtitle: "Google",
label: `${model.name} · Google`,
subtitle: "Google Work",
providerKey: "google_work",
providerLabel: "Google Work",
providerDriver: "antigravity",
Expand All @@ -282,6 +282,7 @@ describe("mobile model options", () => {
const missing = options.find((option) => option.selection.model === selection.model);
expect(missing).toMatchObject({
label: selection.model,
subtitle: "Google Work",
providerLabel: "Google Work",
providerDriver: "antigravity",
isUnavailable: true,
Expand Down
18 changes: 14 additions & 4 deletions apps/mobile/src/lib/modelOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
import {
buildExplicitProviderOptionSelectionsFromDescriptors,
getProviderOptionDescriptors,
stripLeadingModelQualifier,
} from "@t3tools/shared/model";

export type ModelOption = {
Expand Down Expand Up @@ -39,6 +40,15 @@ function providerDisplayLabel(provider: {
return provider.instanceId;
}

function modelDisplayLabel(model: {
readonly name: string;
readonly subProvider?: string | undefined;
}): string {
const subProvider = model.subProvider?.trim();
const modelName = stripLeadingModelQualifier(model.name, subProvider);
return subProvider ? `${modelName} · ${subProvider}` : modelName;
}

function normalizeSelectionOptions(
selection: ModelSelection,
capabilities: ModelCapabilities | null,
Expand Down Expand Up @@ -168,8 +178,8 @@ export function buildModelOptions(
const key = `${provider.instanceId}:${model.slug}`;
options.set(key, {
key,
label: model.name,
subtitle: model.subProvider ?? "",
label: modelDisplayLabel(model),
Comment thread
macroscopeapp[bot] marked this conversation as resolved.
Resolved
subtitle: providerLabel,
Comment thread
tris203 marked this conversation as resolved.
Resolved
providerKey: provider.instanceId,
providerLabel,
providerDriver: provider.driver,
Expand Down Expand Up @@ -215,8 +225,8 @@ export function buildModelOptions(
});
options.set(key, {
key,
label: model?.name ?? fallbackModelSelection.model,
subtitle: model?.subProvider ?? "",
label: model ? modelDisplayLabel(model) : fallbackModelSelection.model,
subtitle: providerLabel,
providerKey: fallbackModelSelection.instanceId,
providerLabel,
providerDriver,
Expand Down
5 changes: 2 additions & 3 deletions apps/web/src/components/chat/ModelListRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { memo } from "react";
import { CheckIcon, StarIcon } from "lucide-react";
import {
getDisplayModelName,
getModelSourceLabel,
getTriggerDisplayModelLabel,
type ModelEsque,
PROVIDER_ICON_BY_PROVIDER,
Expand Down Expand Up @@ -42,9 +43,7 @@ export const ModelListRow = memo(function ModelListRow(props: {
onToggleFavorite: () => void;
}) {
const ProviderIcon = PROVIDER_ICON_BY_PROVIDER[props.driverKind] ?? null;
const providerLabel = props.model.subProvider
? `${props.providerDisplayName} · ${props.model.subProvider}`
: props.providerDisplayName;
const providerLabel = getModelSourceLabel(props.model, props.providerDisplayName);

const row = (
<ComboboxItem
Expand Down
12 changes: 10 additions & 2 deletions apps/web/src/components/chat/ProviderModelPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
: props.model === ANTIGRAVITY_DEFAULT_MODEL
? "Choose model"
: props.model || "Choose model";
const triggerSubProvider = selectedModel?.subProvider?.trim() || null;
const triggerLabel = selectedModel
? `${getTriggerDisplayModelLabel(selectedModel)}${selectedModel.isUnavailable ? " (Unavailable)" : ""}`
: triggerTitle;
Expand Down Expand Up @@ -259,12 +260,19 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
<TooltipTrigger
render={
<span
className="min-w-0 flex-1 overflow-hidden truncate"
className="flex min-w-0 flex-1 items-center gap-1 overflow-hidden"
data-chat-provider-model-picker-label="true"
/>
}
>
{props.triggerLabel ?? multipleLabel ?? triggerTitle}
<span className="min-w-0 truncate">
{props.triggerLabel ?? multipleLabel ?? triggerTitle}
</span>
{triggerSubProvider && !selectedEntries && props.triggerLabel === undefined ? (
<span className="min-w-0 truncate text-muted-foreground">
· {triggerSubProvider}
</span>
) : null}
</TooltipTrigger>
<TooltipPopup side="top">{triggerTooltipContent}</TooltipPopup>
</Tooltip>
Expand Down
35 changes: 35 additions & 0 deletions apps/web/src/components/chat/providerIconUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { describe, expect, it } from "vite-plus/test";
import { getModelSourceLabel, getTriggerDisplayModelLabel } from "./providerIconUtils";

describe("model provider display labels", () => {
it("qualifies a multi-provider model in the picker trigger", () => {
expect(
getTriggerDisplayModelLabel({
slug: "openai/gpt-5.4",
name: "OpenAI: GPT-5.4",
shortName: "GPT-5.4",
subProvider: "OpenAI",
}),
).toBe("GPT-5.4 · OpenAI");
});

it("describes the model source in terms of its runtime", () => {
expect(
getModelSourceLabel(
{
slug: "openai/gpt-5.4",
name: "GPT-5.4",
subProvider: "OpenAI",
},
"OpenCode",
),
).toBe("OpenCode · OpenAI");
});

it("leaves models without a sub-provider unchanged", () => {
const model = { slug: "gpt-5.4", name: "GPT-5.4" };

expect(getTriggerDisplayModelLabel(model)).toBe("GPT-5.4");
expect(getModelSourceLabel(model, "Codex")).toBe("Codex");
});
});
26 changes: 10 additions & 16 deletions apps/web/src/components/chat/providerIconUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ProviderDriverKind } from "@t3tools/contracts";
import { stripLeadingModelQualifier } from "@t3tools/shared/model";
import {
AntigravityIcon,
ClaudeAI,
Expand Down Expand Up @@ -30,32 +31,25 @@ export type ModelEsque = {
isUnavailable?: boolean | undefined;
};

function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}

function stripLeadingQualifier(value: string, qualifier: string | null | undefined): string {
const trimmedQualifier = qualifier?.trim();
if (!trimmedQualifier) {
return value;
}

const pattern = new RegExp(`^${escapeRegExp(trimmedQualifier)}(?:\\s*[.:/-]\\s*|\\s+)`, "iu");
return value.replace(pattern, "").trim() || value;
}

export function getDisplayModelName(
model: ModelEsque,
options?: { preferShortName?: boolean },
): string {
const name = options?.preferShortName && model.shortName ? model.shortName : model.name;
return stripLeadingQualifier(name, model.subProvider);
return stripLeadingModelQualifier(name, model.subProvider);
}

export function getTriggerDisplayModelName(model: ModelEsque): string {
return getDisplayModelName(model, { preferShortName: true });
}

export function getTriggerDisplayModelLabel(model: ModelEsque): string {
return getTriggerDisplayModelName(model);
const modelName = getTriggerDisplayModelName(model);
const subProvider = model.subProvider?.trim();
return subProvider ? `${modelName} · ${subProvider}` : modelName;
}
Comment thread
tris203 marked this conversation as resolved.
Resolved

export function getModelSourceLabel(model: ModelEsque, runtimeDisplayName: string): string {
const subProvider = model.subProvider?.trim();
return subProvider ? `${runtimeDisplayName} · ${subProvider}` : runtimeDisplayName;
}
6 changes: 4 additions & 2 deletions apps/web/src/components/settings/ProjectDefaultsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import type { ProjectSettingsCategory } from "./ProjectSettingsPanel";
import { searchableSetting } from "./settingsSearch";
import { useSettingsScope } from "./SettingsScopeContext";
import {
SETTINGS_MODEL_CONTROLS_CLASSNAME,
SETTINGS_MODEL_PICKER_TRIGGER_CLASSNAME,
SETTINGS_PICKER_TRIGGER_CLASSNAME,
SettingResetButton,
SettingsRow,
Expand Down Expand Up @@ -155,14 +157,14 @@ export function ProjectDefaultsSettings({ category }: { category: ProjectSetting
}
control={
selection && activeEntry ? (
<div className="flex min-w-0 flex-wrap items-center justify-end gap-1.5">
<div className={`${SETTINGS_MODEL_CONTROLS_CLASSNAME} min-w-0 gap-1.5`}>
<ProviderModelPicker
activeInstanceId={selection.instanceId}
model={selection.model}
lockedProvider={null}
instanceEntries={entries}
modelOptionsByInstance={modelOptions}
triggerClassName={SETTINGS_PICKER_TRIGGER_CLASSNAME}
triggerClassName={SETTINGS_MODEL_PICKER_TRIGGER_CLASSNAME}
{...(mixedModel ? { triggerLabel: "Mixed" } : {})}
getModelDisabledReason={modelDisabledReason}
onOpenProviderSetup={(instanceId) => {
Expand Down
6 changes: 4 additions & 2 deletions apps/web/src/components/settings/SettingsPanels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ import {
} from "./SettingsPanels.logic";
import {
PolicyTooltip,
SETTINGS_MODEL_CONTROLS_CLASSNAME,
SETTINGS_MODEL_PICKER_TRIGGER_CLASSNAME,
SETTINGS_PICKER_TRIGGER_CLASSNAME,
SettingResetButton,
SettingsPageContainer,
Expand Down Expand Up @@ -3106,14 +3108,14 @@ export function GeneralSettingsPanel() {
No text generation providers available.
</span>
) : (
<div className="flex flex-wrap items-center justify-end gap-1.5">
<div className={`${SETTINGS_MODEL_CONTROLS_CLASSNAME} gap-1.5`}>
<ProviderModelPicker
activeInstanceId={textGenInstanceId}
model={textGenModel}
lockedProvider={null}
instanceEntries={textGenerationModelInstanceEntries}
modelOptionsByInstance={textGenerationModelOptionsByInstance}
triggerClassName={SETTINGS_PICKER_TRIGGER_CLASSNAME}
triggerClassName={SETTINGS_MODEL_PICKER_TRIGGER_CLASSNAME}
{...(mixedTextGenerationModel ? { triggerLabel: "Mixed" } : {})}
getModelDisabledReason={textGenerationModelDisabledReason}
{...(environmentId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import { Textarea } from "../ui/textarea";
import { toastManager } from "../ui/toast";
import { Button } from "../ui/button";
import {
SETTINGS_PICKER_TRIGGER_CLASSNAME,
SETTINGS_MODEL_CONTROLS_CLASSNAME,
SETTINGS_MODEL_PICKER_TRIGGER_CLASSNAME,
SettingResetButton,
SettingsRow,
SettingsSection,
Expand Down Expand Up @@ -291,7 +292,7 @@ export function SourceControlWritingSettingsSection() {
Connect an environment to choose its source control writer model.
</span>
) : (
<div className="flex flex-wrap items-center justify-end gap-2">
<div className={`${SETTINGS_MODEL_CONTROLS_CLASSNAME} gap-2`}>
{usesDedicatedModel && !canEnableDedicatedModel ? (
<span className="text-sm text-muted-foreground">
No text generation providers available.
Expand All @@ -304,7 +305,7 @@ export function SourceControlWritingSettingsSection() {
lockedProvider={null}
instanceEntries={instanceEntries}
modelOptionsByInstance={modelOptionsByInstance}
triggerClassName={SETTINGS_PICKER_TRIGGER_CLASSNAME}
triggerClassName={SETTINGS_MODEL_PICKER_TRIGGER_CLASSNAME}
triggerAriaLabel="Source control writer model"
{...(mixedWriterModel ? { triggerLabel: "Mixed" } : {})}
{...(environmentId
Expand Down
5 changes: 5 additions & 0 deletions apps/web/src/components/settings/settingsLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ export function SettingsSearchTarget({
/** Layout for the composer model/traits pickers in a settings row: drop the composer's max-width. */
export const SETTINGS_PICKER_TRIGGER_CLASSNAME = "min-w-0 max-w-none shrink-0";

export const SETTINGS_MODEL_PICKER_TRIGGER_CLASSNAME = `${SETTINGS_PICKER_TRIGGER_CLASSNAME} max-w-full sm:max-w-full`;

export const SETTINGS_MODEL_CONTROLS_CLASSNAME =
"flex max-w-full flex-wrap items-center justify-end sm:max-w-[26rem]";

/** Info affordance explaining how a setting interacts with the shared background policy. */
export function PolicyTooltip({ children }: { readonly children: string }) {
return (
Expand Down
14 changes: 14 additions & 0 deletions packages/shared/src/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
toCustomModelSetting,
getProviderOptionBooleanSelectionValue,
getProviderOptionStringSelectionValue,
stripLeadingModelQualifier,
} from "./model.ts";

const codexCaps: ModelCapabilities = createModelCapabilities({
Expand Down Expand Up @@ -244,3 +245,16 @@ describe("readCustomModelEntries", () => {
});
});
});

describe("model display normalization", () => {
it("removes a repeated provider qualifier", () => {
expect(stripLeadingModelQualifier("OpenAI: GPT-5.4", "OpenAI")).toBe("GPT-5.4");
expect(stripLeadingModelQualifier("GitHub Copilot / Claude Haiku", "github copilot")).toBe(
"Claude Haiku",
);
});

it("preserves names without the provider qualifier", () => {
expect(stripLeadingModelQualifier("GPT-5.4", "OpenAI")).toBe("GPT-5.4");
});
});
Loading
Loading