Skip to content

Commit 27b0dbb

Browse files
vitalyiegorovclaudejuliusmarminge
authored
fix(clients): handoffs between accounts show which account is on each side (pingdotgg#15477)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 7259e4f commit 27b0dbb

7 files changed

Lines changed: 90 additions & 30 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,7 @@ function renderFeedEntry(
11011101
environmentId={props.environmentId}
11021102
projectedItem={entry.activities[0]!.projectedItem}
11031103
iconColor={iconSubtleColor}
1104+
surfaceColor={props.screenColor}
11041105
/>
11051106
);
11061107
}
@@ -2546,6 +2547,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
25462547
environmentId={props.environmentId}
25472548
endpoints={props.pendingHandoff}
25482549
iconColor={iconSubtleColor}
2550+
surfaceColor={screenColor}
25492551
label="Context handoff pending"
25502552
/>
25512553
) : null

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

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import * as Dialog from "../../components/ui/Dialog";
22
import { useAtomValue } from "@effect/atom-react";
33
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
44
import { resolveHandoffEndpoints, type HandoffEndpoints } from "@t3tools/client-runtime/handoff";
5-
import { resolveProviderInstanceDisplayName } from "@t3tools/client-runtime/state/provider-instance-display";
5+
import {
6+
normalizeProviderAccentColor,
7+
resolveProviderInstanceDisplayName,
8+
shouldShowInstanceBadge,
9+
} from "@t3tools/client-runtime/state/provider-instance-display";
610
import type {
711
EnvironmentId,
812
OrchestrationV2ProjectedTurnItem,
@@ -14,11 +18,16 @@ import { useMemo } from "react";
1418
import { Pressable, View, type ColorValue } from "react-native";
1519
import { AppText as Text } from "../../components/ui/AppText";
1620
import { SymbolView } from "../../components/ui/AppSymbol";
17-
import { ProviderIcon } from "../../components/ProviderIcon";
21+
import { ProviderIcon, ProviderInstanceIcon } from "../../components/ProviderIcon";
1822
import { environmentThreadDetails } from "../../state/threads";
1923
import { serverEnvironment } from "../../state/server";
2024
import { ThreadContextDivider } from "./thread-context-divider";
2125

26+
type HandoffProvider = ServerProvider & {
27+
readonly driverKind: ServerProvider["driver"];
28+
readonly acpRegistryAgentId: string | undefined;
29+
};
30+
2231
function handoffEndpointsAtom(
2332
environmentId: EnvironmentId,
2433
{ item, sourceThreadId }: OrchestrationV2ProjectedTurnItem,
@@ -39,6 +48,7 @@ export function ThreadHandoffRow(props: {
3948
environmentId: EnvironmentId;
4049
projectedItem: OrchestrationV2ProjectedTurnItem;
4150
iconColor: ColorValue;
51+
surfaceColor: string;
4252
}) {
4353
const { item } = props.projectedItem;
4454
const endpointsAtom = useMemo(
@@ -53,6 +63,7 @@ export function ThreadHandoffRow(props: {
5363
environmentId={props.environmentId}
5464
endpoints={endpoints}
5565
iconColor={color}
66+
surfaceColor={props.surfaceColor}
5667
label="Context handoff"
5768
failed={item.status === "failed"}
5869
/>
@@ -63,11 +74,29 @@ export function ThreadHandoffDivider(props: {
6374
environmentId: EnvironmentId;
6475
endpoints: HandoffEndpoints;
6576
iconColor: ColorValue;
77+
surfaceColor: string;
6678
label: string;
6779
failed?: boolean;
6880
}) {
6981
const config = useAtomValue(serverEnvironment.configValueAtom(props.environmentId));
7082
const { endpoints } = props;
83+
const endpointProps = {
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+
}),
98+
surfaceColor: props.surfaceColor,
99+
};
71100
return (
72101
<ThreadContextDivider
73102
label={props.label}
@@ -81,7 +110,7 @@ export function ThreadHandoffDivider(props: {
81110
key={`${endpoint.instanceId}:${endpoint.model ?? ""}`}
82111
className="max-w-full flex-row items-center"
83112
>
84-
<HandoffEndpoint {...endpoint} providers={config?.providers ?? []} />
113+
<HandoffEndpoint {...endpoint} {...endpointProps} />
85114
{index < endpoints.from.length - 1 ? (
86115
<Text accessible={false} className="text-xs text-foreground-muted">
87116
,
@@ -92,7 +121,7 @@ export function ThreadHandoffDivider(props: {
92121
{endpoints.from.length > 0 ? (
93122
<SymbolView name="arrow.right" size={12} tintColor={props.iconColor} />
94123
) : null}
95-
<HandoffEndpoint {...endpoints.to} providers={config?.providers ?? []} />
124+
<HandoffEndpoint {...endpoints.to} {...endpointProps} />
96125
</View>
97126
</ThreadContextDivider>
98127
);
@@ -101,7 +130,8 @@ export function ThreadHandoffDivider(props: {
101130
function HandoffEndpoint(props: {
102131
instanceId: ProviderInstanceId;
103132
model?: string | undefined;
104-
providers: ReadonlyArray<ServerProvider>;
133+
providers: ReadonlyArray<HandoffProvider>;
134+
surfaceColor: string;
105135
}) {
106136
const provider = props.providers.find((candidate) => candidate.instanceId === props.instanceId);
107137
const model = provider?.models.find((candidate) => candidate.slug === props.model);
@@ -110,12 +140,13 @@ function HandoffEndpoint(props: {
110140
model?.name ??
111141
props.model ??
112142
(provider ? resolveProviderInstanceDisplayName(provider) : props.instanceId);
143+
const showBadge = provider !== undefined && shouldShowInstanceBadge(provider, props.providers);
113144
return (
114145
<Pressable
115146
accessibilityRole="button"
116147
accessibilityLabel={label}
117148
accessibilityHint="Show provider account"
118-
className="min-h-6 max-w-full flex-row items-center justify-center gap-1"
149+
className="min-h-6 max-w-full flex-row items-center justify-center gap-1.5"
119150
hitSlop={{ top: 8, bottom: 8 }}
120151
onPress={() =>
121152
Dialog.alert(
@@ -124,11 +155,23 @@ function HandoffEndpoint(props: {
124155
)
125156
}
126157
>
127-
<ProviderIcon
128-
provider={provider?.driver ?? props.instanceId}
129-
iconUrl={provider?.iconUrl}
130-
size={12}
131-
/>
158+
{showBadge && provider !== undefined ? (
159+
<ProviderInstanceIcon
160+
provider={provider.driver}
161+
iconUrl={provider.iconUrl}
162+
size={14}
163+
displayName={resolveProviderInstanceDisplayName(provider)}
164+
accentColor={provider.accentColor}
165+
showBadge
166+
surfaceColor={props.surfaceColor}
167+
/>
168+
) : (
169+
<ProviderIcon
170+
provider={provider?.driver ?? props.instanceId}
171+
iconUrl={provider?.iconUrl}
172+
size={12}
173+
/>
174+
)}
132175
<Text numberOfLines={1} className="shrink text-xs text-foreground-muted">
133176
{label}
134177
</Text>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8001,6 +8001,7 @@ export default function ChatView(props: ChatViewProps) {
80018001
<>
80028002
<div className="chat-content-lane">
80038003
<HandoffRow
8004+
environmentId={environmentId}
80048005
endpoints={pendingHandoff}
80058006
providers={providerStatuses}
80068007
pending

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,8 +905,8 @@ function SidebarProviderStack(props: {
905905
acpRegistryAgentId={currentEntry.acpRegistryAgentId}
906906
acpRegistryIconUrl={currentEntry.acpRegistryIconUrl}
907907
showBadge={showInstanceBadge}
908-
iconClassName="size-3.5 opacity-60"
909-
badgeClassName="right-[-0.1875rem] bottom-[-0.1875rem] h-3 min-w-3 px-0.5 text-5xs"
908+
size="compact"
909+
iconClassName="opacity-60"
910910
/>
911911
);
912912
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: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ import {
4242
} from "lucide-react";
4343

4444
import { Tooltip, TooltipTrigger, TooltipPopup } from "../ui/tooltip";
45-
import { getProviderInstanceEntry } from "../../providerInstances";
45+
import {
46+
applyProviderInstanceSettings,
47+
deriveProviderInstanceEntries,
48+
shouldShowInstanceBadge,
49+
type ProviderInstanceEntry,
50+
} from "../../providerInstances";
4651
import { formatShortTimestamp } from "../../timestampFormat";
4752
import { getTriggerDisplayModelName } from "./providerIconUtils";
4853
import { ProviderInstanceIcon, providerTextColor } from "./ProviderInstanceIcon";
@@ -575,16 +580,20 @@ function EnvironmentHandoffRow({
575580
}) {
576581
const providers =
577582
useAtomValue(serverEnvironment.providersValueAtom(environmentId)) ?? EMPTY_SERVER_PROVIDERS;
578-
return <HandoffRow {...props} providers={providers} />;
583+
return <HandoffRow {...props} environmentId={environmentId} providers={providers} />;
579584
}
580585

581586
export function HandoffRow(props: {
587+
readonly environmentId: EnvironmentId;
582588
readonly endpoints: HandoffEndpoints;
583589
readonly providers: ReadonlyArray<ServerProvider>;
584590
readonly pending?: boolean;
585591
readonly failed?: boolean;
586592
}) {
587593
const { from: fromEndpoints, to } = props.endpoints;
594+
const settings = useAtomValue(serverEnvironment.settingsValueAtom(props.environmentId));
595+
const derived = deriveProviderInstanceEntries(props.providers);
596+
const entries = settings ? applyProviderInstanceSettings(derived, settings, null) : derived;
588597
return (
589598
<TimelineSystemDivider
590599
label={props.pending ? "Context handoff pending" : "Context handoff"}
@@ -599,7 +608,7 @@ export function HandoffRow(props: {
599608
className="inline-flex min-w-0 items-center"
600609
>
601610
<HandoffEndpoint
602-
providers={props.providers}
611+
entries={entries}
603612
instanceId={endpoint.instanceId}
604613
model={endpoint.model}
605614
/>
@@ -613,23 +622,20 @@ export function HandoffRow(props: {
613622
{fromEndpoints.length > 0 ? (
614623
<ArrowRightIcon aria-hidden="true" className="size-3 shrink-0" />
615624
) : null}
616-
<HandoffEndpoint
617-
providers={props.providers}
618-
instanceId={to.instanceId}
619-
model={to.model}
620-
/>
625+
<HandoffEndpoint entries={entries} instanceId={to.instanceId} model={to.model} />
621626
</span>
622627
}
623628
/>
624629
);
625630
}
626631

627632
function HandoffEndpoint(props: {
628-
readonly providers: ReadonlyArray<ServerProvider>;
633+
readonly entries: ReadonlyArray<ProviderInstanceEntry>;
629634
readonly instanceId: ProviderInstanceId;
630635
readonly model?: string | undefined;
631636
}) {
632-
const entry = getProviderInstanceEntry(props.providers, props.instanceId);
637+
const entry = props.entries.find((candidate) => candidate.instanceId === props.instanceId);
638+
const showBadge = entry !== undefined && shouldShowInstanceBadge(entry, props.entries);
633639
const model = props.model?.trim();
634640
const providerModel =
635641
model === undefined || model.length === 0
@@ -650,14 +656,18 @@ function HandoffEndpoint(props: {
650656
render={
651657
<span
652658
tabIndex={0}
653-
className="inline-flex min-w-0 items-center gap-1 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
659+
className="inline-flex min-w-0 items-center gap-1.5 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
654660
>
655661
<ProviderInstanceIcon
656662
driverKind={entry?.driverKind ?? ProviderDriverKind.make(props.instanceId)}
657663
displayName={entry?.displayName ?? props.instanceId}
664+
accentColor={entry?.accentColor}
658665
acpRegistryAgentId={entry?.acpRegistryAgentId}
659666
acpRegistryIconUrl={entry?.acpRegistryIconUrl}
660-
iconClassName="size-3"
667+
showBadge={showBadge}
668+
size="compact"
669+
iconClassName={cn(showBadge && "opacity-60")}
670+
indicatorBackground="var(--background)"
661671
/>
662672
<span
663673
className={cn("truncate font-medium", labelColor.className)}

‎apps/web/src/providerInstances.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export function sortProviderInstanceEntries(
203203
return sorted;
204204
}
205205

206-
export function getProviderInstanceEntry(
206+
function getProviderInstanceEntry(
207207
providers: ReadonlyArray<ServerProvider>,
208208
instanceId: ProviderInstanceId,
209209
): ProviderInstanceEntry | undefined {

0 commit comments

Comments
 (0)