Skip to content

Commit 1533e05

Browse files
committed
fix(mobile): show the provider account badge on thread rows
Thread rows drew a bare provider glyph, so two accounts on the same provider looked identical. Rows now carry the same accent-color initials badge the web sidebar shows, driven by the badge rule shared through client-runtime so the two clients cannot drift. Built with Claude Fable 5.1 in Claude Code.
1 parent b491e41 commit 1533e05

11 files changed

Lines changed: 432 additions & 124 deletions

File tree

‎apps/mobile/src/components/ProviderIcon.tsx‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Image } from "expo-image";
22
import { Path, Svg } from "react-native-svg";
3+
import { View } from "react-native";
4+
import { providerInstanceInitials } from "@t3tools/client-runtime/state/provider-instance-display";
35
import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
6+
import { AppText as Text } from "./AppText";
47

58
type ProviderIconProps = {
69
readonly provider: string | null | undefined;
@@ -80,3 +83,58 @@ export function ProviderIcon(props: ProviderIconProps) {
8083
</Svg>
8184
);
8285
}
86+
87+
/**
88+
* `ProviderIcon` plus the web sidebar's account badge: an accent-color
89+
* initials bubble in the bottom-right corner, drawn when `showBadge` is set
90+
* (accent color present, or several instances share this driver). The glyph
91+
* dims to 60% opacity while the badge stays fully saturated, matching
92+
* `apps/web/src/components/chat/ProviderInstanceIcon.tsx`.
93+
*/
94+
export function ProviderInstanceIcon(props: {
95+
readonly provider: string | null | undefined;
96+
readonly size?: number;
97+
readonly displayName: string;
98+
readonly accentColor?: string;
99+
readonly showBadge?: boolean;
100+
readonly surfaceColor: string;
101+
}) {
102+
return (
103+
<View style={{ position: "relative" }}>
104+
<View style={{ opacity: 0.6 }}>
105+
<ProviderIcon provider={props.provider} size={props.size} />
106+
</View>
107+
{props.showBadge ? (
108+
<View
109+
className={props.accentColor ? undefined : "bg-card"}
110+
style={{
111+
position: "absolute",
112+
right: -3,
113+
bottom: -3,
114+
height: 12,
115+
minWidth: 12,
116+
paddingHorizontal: 2,
117+
borderRadius: 999,
118+
borderWidth: 1,
119+
borderColor: props.surfaceColor,
120+
backgroundColor: props.accentColor,
121+
alignItems: "center",
122+
justifyContent: "center",
123+
}}
124+
>
125+
<Text
126+
className={props.accentColor ? undefined : "text-foreground-muted"}
127+
style={{
128+
fontSize: 7,
129+
fontWeight: "600",
130+
lineHeight: 9,
131+
color: props.accentColor ? "#ffffff" : undefined,
132+
}}
133+
>
134+
{providerInstanceInitials(props.displayName)}
135+
</Text>
136+
</View>
137+
) : null}
138+
</View>
139+
);
140+
}

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
ThreadListV2SettledShelfHeader,
5252
ThreadListV2SnoozedShelfHeader,
5353
} from "../threads/thread-list-v2-items";
54+
import { resolveThreadProviderInstance } from "../threads/thread-provider-instance";
5455
import {
5556
buildThreadListV2Items,
5657
getThreadListV2OrderedSection,
@@ -840,15 +841,7 @@ export function HomeScreen(props: HomeScreenProps) {
840841
projectTitle={v2ProjectTitleByProjectKey.get(
841842
scopedProjectKey(thread.environmentId, thread.projectId),
842843
)}
843-
providerDriver={
844-
serverConfigs
845-
.get(thread.environmentId)
846-
?.providers.find(
847-
(provider) =>
848-
provider.instanceId ===
849-
(thread.session?.providerInstanceId ?? thread.modelSelection.instanceId),
850-
)?.driver ?? null
851-
}
844+
providerInstance={resolveThreadProviderInstance(serverConfigs, thread)}
852845
environmentLabel={
853846
Object.keys(props.savedConnectionsById).length > 1
854847
? (props.savedConnectionsById[thread.environmentId]?.environmentLabel ?? null)

‎apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import {
7878
ThreadListV2SettledShelfHeader,
7979
ThreadListV2SnoozedShelfHeader,
8080
} from "./thread-list-v2-items";
81+
import { resolveThreadProviderInstance } from "./thread-provider-instance";
8182
import {
8283
buildThreadListV2Items,
8384
getThreadListV2OrderedSection,
@@ -901,15 +902,7 @@ function ThreadNavigationSidebarPane(
901902
snoozeWakeLabelText={item.snoozeWakeLabelText}
902903
project={projectByKey.get(scopeKey) ?? null}
903904
projectTitle={projectTitleByProjectKey.get(scopeKey)}
904-
providerDriver={
905-
serverConfigs
906-
.get(thread.environmentId)
907-
?.providers.find(
908-
(provider) =>
909-
provider.instanceId ===
910-
(thread.session?.providerInstanceId ?? thread.modelSelection.instanceId),
911-
)?.driver ?? null
912-
}
905+
providerInstance={resolveThreadProviderInstance(serverConfigs, thread)}
913906
environmentLabel={
914907
Object.keys(savedConnectionsById).length > 1
915908
? (savedConnectionsById[thread.environmentId]?.environmentLabel ?? null)

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import { AppText as Text } from "../../components/AppText";
1616
import { ControlPillMenu } from "../../components/ControlPill";
1717
import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol";
1818
import { ProjectFavicon } from "../../components/ProjectFavicon";
19-
import { ProviderIcon } from "../../components/ProviderIcon";
19+
import { ProviderInstanceIcon } from "../../components/ProviderIcon";
20+
import type { ThreadRowProviderInstance } from "./thread-provider-instance";
2021
import { cn } from "../../lib/cn";
2122
import { relativeTime } from "../../lib/time";
2223
import { useUniwindTheme } from "../../lib/useUniwindTheme";
@@ -349,7 +350,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
349350
readonly snoozePresetMinute: string;
350351
readonly project: EnvironmentProject | null;
351352
readonly projectTitle?: string;
352-
readonly providerDriver: string | null;
353+
readonly providerInstance: ThreadRowProviderInstance | null;
353354
/** Which machine hosts the thread. Null when only one environment is
354355
connected — repeating the same label on every row is noise. Mirrors
355356
the web sidebar's remote-environment cloud icon, but as text since
@@ -435,6 +436,15 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
435436
const selectedBackgroundColor = theme["--color-user-bubble"];
436437
const sidebarPane = props.pane === "sidebar";
437438
const selected = props.selected === true;
439+
// The provider badge's border blends into the row's own surface, which
440+
// differs by pane and (for the sidebar pane) selection: the sidebar row
441+
// background becomes the selected fill or the drawer surface, while the
442+
// flat "screen" pane rows always sit on the screen background.
443+
const providerIconSurfaceColor = sidebarPane
444+
? selected
445+
? selectedBackgroundColor
446+
: drawerColor
447+
: screenColor;
438448

439449
const status = resolveThreadListV2Status(thread);
440450
const statusLabel = STATUS_LABEL_BY_STATUS[status];
@@ -825,10 +835,15 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
825835
#{pr.label}
826836
</Text>
827837
) : null}
828-
{props.providerDriver ? (
829-
<View className="opacity-60">
830-
<ProviderIcon provider={props.providerDriver} size={14} />
831-
</View>
838+
{props.providerInstance ? (
839+
<ProviderInstanceIcon
840+
provider={props.providerInstance.driverKind}
841+
size={14}
842+
displayName={props.providerInstance.displayName}
843+
accentColor={props.providerInstance.accentColor}
844+
showBadge={props.providerInstance.showBadge}
845+
surfaceColor={providerIconSurfaceColor}
846+
/>
832847
) : null}
833848
</View>
834849
</>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
2+
import {
3+
EnvironmentId,
4+
ProjectId,
5+
ProviderInstanceId,
6+
ThreadId,
7+
type ServerConfig,
8+
} from "@t3tools/contracts";
9+
import { describe, expect, it } from "vite-plus/test";
10+
11+
import { resolveThreadProviderInstance } from "./thread-provider-instance";
12+
13+
function makeConfig(
14+
providers: ReadonlyArray<{
15+
readonly instanceId: string;
16+
readonly driver: string;
17+
readonly displayName?: string;
18+
readonly accentColor?: string;
19+
}>,
20+
): ServerConfig {
21+
return { providers } as unknown as ServerConfig;
22+
}
23+
24+
function makeThread(environmentId: EnvironmentId, instanceId: string): EnvironmentThreadShell {
25+
return {
26+
environmentId,
27+
id: ThreadId.make("thread-1"),
28+
projectId: ProjectId.make("project-1"),
29+
title: "Thread",
30+
modelSelection: { instanceId: ProviderInstanceId.make(instanceId), model: "gpt-5.4" },
31+
runtimeMode: "full-access",
32+
interactionMode: "default",
33+
branch: null,
34+
worktreePath: null,
35+
latestTurn: null,
36+
createdAt: "2026-06-01T00:00:00.000Z",
37+
updatedAt: "2026-06-01T00:00:00.000Z",
38+
archivedAt: null,
39+
settledOverride: null,
40+
settledAt: null,
41+
session: null,
42+
latestUserMessageAt: null,
43+
hasPendingApprovals: false,
44+
hasPendingUserInput: false,
45+
hasActionableProposedPlan: false,
46+
} as unknown as EnvironmentThreadShell;
47+
}
48+
49+
describe("resolveThreadProviderInstance", () => {
50+
it("resolves two environments with the same default instance id independently", () => {
51+
const environmentA = EnvironmentId.make("environment-a");
52+
const environmentB = EnvironmentId.make("environment-b");
53+
const serverConfigs = new Map<EnvironmentId, ServerConfig>([
54+
[
55+
environmentA,
56+
makeConfig([{ instanceId: "codex", driver: "codex", accentColor: "#ff8800" }]),
57+
],
58+
[environmentB, makeConfig([{ instanceId: "codex", driver: "codex" }])],
59+
]);
60+
61+
const threadA = makeThread(environmentA, "codex");
62+
const threadB = makeThread(environmentB, "codex");
63+
64+
expect(resolveThreadProviderInstance(serverConfigs, threadA)?.accentColor).toBe("#ff8800");
65+
expect(resolveThreadProviderInstance(serverConfigs, threadB)?.accentColor).toBeUndefined();
66+
});
67+
68+
it("labels a custom instance by its id so its initials differ from the default", () => {
69+
const environmentId = EnvironmentId.make("environment-a");
70+
const serverConfigs = new Map<EnvironmentId, ServerConfig>([
71+
[
72+
environmentId,
73+
makeConfig([
74+
{ instanceId: "codex", driver: "codex", displayName: "Codex" },
75+
{ instanceId: "codex_personal", driver: "codex", displayName: "Codex" },
76+
]),
77+
],
78+
]);
79+
80+
expect(
81+
resolveThreadProviderInstance(serverConfigs, makeThread(environmentId, "codex"))?.displayName,
82+
).toBe("Codex");
83+
expect(
84+
resolveThreadProviderInstance(serverConfigs, makeThread(environmentId, "codex_personal"))
85+
?.displayName,
86+
).toBe("Codex Personal");
87+
});
88+
89+
it("hides the badge for a single instance with no accent color", () => {
90+
const environmentId = EnvironmentId.make("environment-a");
91+
const serverConfigs = new Map<EnvironmentId, ServerConfig>([
92+
[environmentId, makeConfig([{ instanceId: "codex", driver: "codex" }])],
93+
]);
94+
const thread = makeThread(environmentId, "codex");
95+
96+
expect(resolveThreadProviderInstance(serverConfigs, thread)?.showBadge).toBe(false);
97+
});
98+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
2+
import {
3+
normalizeProviderAccentColor,
4+
resolveProviderInstanceDisplayName,
5+
shouldShowInstanceBadge,
6+
} from "@t3tools/client-runtime/state/provider-instance-display";
7+
import type { EnvironmentId, ProviderDriverKind, ServerConfig } from "@t3tools/contracts";
8+
9+
/** What a thread row needs to draw the provider glyph and its account badge. */
10+
export interface ThreadRowProviderInstance {
11+
readonly driverKind: ProviderDriverKind;
12+
readonly displayName: string;
13+
readonly accentColor?: string | undefined;
14+
readonly showBadge: boolean;
15+
}
16+
17+
/**
18+
* Resolve the provider instance a thread runs on, scoped to the thread's own
19+
* environment: default instance ids are the driver slug, so the same id
20+
* names a different account on every server.
21+
*/
22+
export function resolveThreadProviderInstance(
23+
serverConfigs: ReadonlyMap<EnvironmentId, ServerConfig>,
24+
thread: EnvironmentThreadShell,
25+
): ThreadRowProviderInstance | null {
26+
const providers = serverConfigs.get(thread.environmentId)?.providers ?? [];
27+
const instanceId = thread.session?.providerInstanceId ?? thread.modelSelection.instanceId;
28+
const snapshot = providers.find((provider) => provider.instanceId === instanceId);
29+
if (!snapshot) return null;
30+
const entry = {
31+
driverKind: snapshot.driver,
32+
displayName: resolveProviderInstanceDisplayName(snapshot),
33+
accentColor: normalizeProviderAccentColor(snapshot.accentColor),
34+
};
35+
return {
36+
...entry,
37+
showBadge: shouldShowInstanceBadge(
38+
entry,
39+
providers.map((provider) => ({ driverKind: provider.driver })),
40+
),
41+
};
42+
}

‎apps/web/src/components/chat/ProviderInstanceIcon.tsx‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import { type CSSProperties, memo } from "react";
22
import { type ProviderDriverKind } from "@t3tools/contracts";
3+
import { providerInstanceInitials } from "@t3tools/client-runtime/state/provider-instance-display";
34

45
import { PROVIDER_ICON_BY_PROVIDER } from "./providerIconUtils";
56
import { cn } from "~/lib/utils";
67

7-
export function providerInstanceInitials(label: string): string {
8-
const words = label.replace(/[_-]+/g, " ").split(/\s+/u).filter(Boolean);
9-
if (words.length === 0) return "";
10-
if (words.length === 1) return words[0]!.slice(0, 2).toUpperCase();
11-
return words
12-
.slice(0, 2)
13-
.map((word) => word[0]?.toUpperCase() ?? "")
14-
.join("");
15-
}
8+
export { providerInstanceInitials };
169

1710
export const ProviderInstanceIcon = memo(function ProviderInstanceIcon(props: {
1811
driverKind: ProviderDriverKind;

0 commit comments

Comments
 (0)