Skip to content

Commit 337379a

Browse files
fix(clients): share compact account badges for handoffs
1 parent daaa87a commit 337379a

4 files changed

Lines changed: 34 additions & 42 deletions

File tree

‎apps/mobile/src/features/threads/thread-handoff-row.tsx‎

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
import type {
1111
EnvironmentId,
1212
OrchestrationV2ProjectedTurnItem,
13-
ProviderInstanceConfig,
1413
ProviderInstanceId,
1514
ServerProvider,
1615
} from "@t3tools/contracts";
@@ -24,6 +23,11 @@ import { environmentThreadDetails } from "../../state/threads";
2423
import { serverEnvironment } from "../../state/server";
2524
import { ThreadContextDivider } from "./thread-context-divider";
2625

26+
type HandoffProvider = ServerProvider & {
27+
readonly driverKind: ServerProvider["driver"];
28+
readonly acpRegistryAgentId: string | undefined;
29+
};
30+
2731
function handoffEndpointsAtom(
2832
environmentId: EnvironmentId,
2933
{ item, sourceThreadId }: OrchestrationV2ProjectedTurnItem,
@@ -77,8 +81,20 @@ export function ThreadHandoffDivider(props: {
7781
const config = useAtomValue(serverEnvironment.configValueAtom(props.environmentId));
7882
const { endpoints } = props;
7983
const endpointProps = {
80-
providers: config?.providers ?? [],
81-
providerInstances: config?.settings.providerInstances,
84+
providers: (config?.providers ?? []).map((provider) => {
85+
const rawConfig = config?.settings.providerInstances[provider.instanceId]?.config;
86+
const instanceConfig =
87+
rawConfig !== null && typeof rawConfig === "object"
88+
? (rawConfig as Readonly<Record<string, unknown>>)
89+
: null;
90+
const agentId = instanceConfig?.source === "local" ? undefined : instanceConfig?.agentId;
91+
return {
92+
...provider,
93+
driverKind: provider.driver,
94+
accentColor: normalizeProviderAccentColor(provider.accentColor),
95+
acpRegistryAgentId: typeof agentId === "string" ? agentId.trim() || undefined : undefined,
96+
};
97+
}),
8298
surfaceColor: props.surfaceColor,
8399
};
84100
return (
@@ -114,8 +130,7 @@ export function ThreadHandoffDivider(props: {
114130
function HandoffEndpoint(props: {
115131
instanceId: ProviderInstanceId;
116132
model?: string | undefined;
117-
providers: ReadonlyArray<ServerProvider>;
118-
providerInstances: Readonly<Record<string, ProviderInstanceConfig>> | undefined;
133+
providers: ReadonlyArray<HandoffProvider>;
119134
surfaceColor: string;
120135
}) {
121136
const provider = props.providers.find((candidate) => candidate.instanceId === props.instanceId);
@@ -125,30 +140,7 @@ function HandoffEndpoint(props: {
125140
model?.name ??
126141
props.model ??
127142
(provider ? resolveProviderInstanceDisplayName(provider) : props.instanceId);
128-
const accentColor = normalizeProviderAccentColor(provider?.accentColor);
129-
// Same account badge as the thread rows: a handoff between two accounts of
130-
// one provider would otherwise show the same glyph on both sides. Settings
131-
// carry each ACP instance's agent, which tells its glyph apart.
132-
const badgeEntry = (candidate: ServerProvider) => {
133-
const config = props.providerInstances?.[candidate.instanceId]?.config;
134-
// A local ACP command has no registry agent, as on web.
135-
const agentId =
136-
typeof config === "object" && config && Reflect.get(config, "source") !== "local"
137-
? Reflect.get(config, "agentId")
138-
: null;
139-
return {
140-
driverKind: candidate.driver,
141-
...(typeof agentId === "string" && agentId.trim()
142-
? { acpRegistryAgentId: agentId.trim() }
143-
: {}),
144-
};
145-
};
146-
const showBadge =
147-
provider !== undefined &&
148-
shouldShowInstanceBadge(
149-
{ ...badgeEntry(provider), accentColor },
150-
props.providers.map(badgeEntry),
151-
);
143+
const showBadge = provider !== undefined && shouldShowInstanceBadge(provider, props.providers);
152144
return (
153145
<Pressable
154146
accessibilityRole="button"
@@ -169,7 +161,7 @@ function HandoffEndpoint(props: {
169161
iconUrl={provider.iconUrl}
170162
size={14}
171163
displayName={resolveProviderInstanceDisplayName(provider)}
172-
accentColor={accentColor}
164+
accentColor={provider.accentColor}
173165
showBadge
174166
surfaceColor={props.surfaceColor}
175167
/>

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,8 +888,8 @@ function SidebarProviderStack(props: {
888888
acpRegistryAgentId={currentEntry.acpRegistryAgentId}
889889
acpRegistryIconUrl={currentEntry.acpRegistryIconUrl}
890890
showBadge={showInstanceBadge}
891-
iconClassName="size-3.5 opacity-60"
892-
badgeClassName="right-[-0.1875rem] bottom-[-0.1875rem] h-3 min-w-3 px-0.5 text-5xs"
891+
size="compact"
892+
iconClassName="opacity-60"
893893
/>
894894
);
895895
if (stack.length === 1) {

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const ProviderInstanceIcon = memo(function ProviderInstanceIcon(props: {
6161
acpRegistryIconUrl?: string | undefined;
6262
showBadge?: boolean;
6363
badgeContent?: "initials" | "none";
64+
size?: "default" | "compact";
6465
className?: string;
6566
iconClassName?: string;
6667
badgeClassName?: string;
@@ -74,6 +75,7 @@ export const ProviderInstanceIcon = memo(function ProviderInstanceIcon(props: {
7475
? ({ "--provider-accent": props.accentColor } as CSSProperties)
7576
: undefined;
7677
const badgeContent = props.badgeContent ?? "initials";
78+
const iconClassName = cn(props.size === "compact" && "size-3.5", props.iconClassName);
7779
const isAcpRegistry = props.driverKind === "acpRegistry";
7880
const acpRegistryIconUrl = resolveProviderInstanceAcpRegistryIconUrl({
7981
driverKind: props.driverKind,
@@ -92,20 +94,20 @@ export const ProviderInstanceIcon = memo(function ProviderInstanceIcon(props: {
9294
>
9395
{isAcpRegistry ? (
9496
<AcpRegistryAgentIcon
95-
className={cn("size-5 rounded-none bg-transparent", props.iconClassName)}
97+
className={cn("size-5 rounded-none bg-transparent", iconClassName)}
9698
fallbackClassName="size-full"
9799
icon={acpRegistryIconUrl}
98100
/>
99101
) : packageIcon ? (
100102
<ProviderPackageIcon
101103
icon={packageIcon}
102-
className={cn("size-5 shrink-0", props.iconClassName)}
104+
className={cn("size-5 shrink-0", iconClassName)}
103105
aria-hidden
104106
/>
105107
) : Icon ? (
106-
<Icon className={cn("size-5 shrink-0", props.iconClassName)} aria-hidden />
108+
<Icon className={cn("size-5 shrink-0", iconClassName)} aria-hidden />
107109
) : (
108-
<span className={cn("text-3xs font-semibold leading-none", props.iconClassName)}>
110+
<span className={cn("text-3xs font-semibold leading-none", iconClassName)}>
109111
{providerInstanceInitials(props.displayName)}
110112
</span>
111113
)}
@@ -126,6 +128,8 @@ export const ProviderInstanceIcon = memo(function ProviderInstanceIcon(props: {
126128
props.accentColor
127129
? "bg-(--provider-accent) text-white"
128130
: "bg-card text-muted-foreground",
131+
props.size === "compact" &&
132+
"right-[-0.1875rem] bottom-[-0.1875rem] h-3 min-w-3 px-0.5 text-5xs",
129133
props.badgeClassName,
130134
)}
131135
style={{ borderColor: indicatorBackground }}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ export function HandoffRow(props: {
592592
}) {
593593
const { from: fromEndpoints, to } = props.endpoints;
594594
const settings = useAtomValue(serverEnvironment.settingsValueAtom(props.environmentId));
595-
// Settings carry each ACP instance's agent, which tells its glyph apart.
596595
const derived = deriveProviderInstanceEntries(props.providers);
597596
const entries = settings ? applyProviderInstanceSettings(derived, settings, null) : derived;
598597
return (
@@ -636,8 +635,6 @@ function HandoffEndpoint(props: {
636635
readonly model?: string | undefined;
637636
}) {
638637
const entry = props.entries.find((candidate) => candidate.instanceId === props.instanceId);
639-
// Same account badge as the sidebar: a handoff between two accounts of one
640-
// provider would otherwise show the same glyph on both sides.
641638
const showBadge = entry !== undefined && shouldShowInstanceBadge(entry, props.entries);
642639
const model = props.model?.trim();
643640
const providerModel =
@@ -668,9 +665,8 @@ function HandoffEndpoint(props: {
668665
acpRegistryAgentId={entry?.acpRegistryAgentId}
669666
acpRegistryIconUrl={entry?.acpRegistryIconUrl}
670667
showBadge={showBadge}
671-
// Glyph dims, badge stays saturated; sized like the sidebar row.
672-
iconClassName={cn("size-3.5", showBadge && "opacity-60")}
673-
badgeClassName="right-[-0.1875rem] bottom-[-0.1875rem] h-3 min-w-3 px-0.5 text-5xs"
668+
size="compact"
669+
iconClassName={cn(showBadge && "opacity-60")}
674670
indicatorBackground="var(--background)"
675671
/>
676672
<span

0 commit comments

Comments
 (0)