Skip to content
TypeScript

fix(clients): handoffs between accounts show which account is on each side (#15477)

Vitaly Iegorov27b0dbb30ee1
diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsx
index 84fb8d84d6b..cc36b4b2b6a 100644
--- a/apps/mobile/src/features/threads/ThreadFeed.tsx
+++ b/apps/mobile/src/features/threads/ThreadFeed.tsx
@@ -1101,6 +1101,7 @@ function renderFeedEntry(
environmentId={props.environmentId}
projectedItem={entry.activities[0]!.projectedItem}
iconColor={iconSubtleColor}
+ surfaceColor={props.screenColor}
/>
);
}
@@ -2546,6 +2547,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
environmentId={props.environmentId}
endpoints={props.pendingHandoff}
iconColor={iconSubtleColor}
+ surfaceColor={screenColor}
label="Context handoff pending"
/>
) : null
diff --git a/apps/mobile/src/features/threads/thread-handoff-row.tsx b/apps/mobile/src/features/threads/thread-handoff-row.tsx
index 0417287cbb3..4cb04fa6b3e 100644
--- a/apps/mobile/src/features/threads/thread-handoff-row.tsx
+++ b/apps/mobile/src/features/threads/thread-handoff-row.tsx
@@ -2,7 +2,11 @@ import * as Dialog from "../../components/ui/Dialog";
import { useAtomValue } from "@effect/atom-react";
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
import { resolveHandoffEndpoints, type HandoffEndpoints } from "@t3tools/client-runtime/handoff";
-import { resolveProviderInstanceDisplayName } from "@t3tools/client-runtime/state/provider-instance-display";
+import {
+ normalizeProviderAccentColor,
+ resolveProviderInstanceDisplayName,
+ shouldShowInstanceBadge,
+} from "@t3tools/client-runtime/state/provider-instance-display";
import type {
EnvironmentId,
OrchestrationV2ProjectedTurnItem,
@@ -14,11 +18,16 @@ import { useMemo } from "react";
import { Pressable, View, type ColorValue } from "react-native";
import { AppText as Text } from "../../components/ui/AppText";
import { SymbolView } from "../../components/ui/AppSymbol";
-import { ProviderIcon } from "../../components/ProviderIcon";
+import { ProviderIcon, ProviderInstanceIcon } from "../../components/ProviderIcon";
import { environmentThreadDetails } from "../../state/threads";
import { serverEnvironment } from "../../state/server";
import { ThreadContextDivider } from "./thread-context-divider";
+type HandoffProvider = ServerProvider & {
+ readonly driverKind: ServerProvider["driver"];
+ readonly acpRegistryAgentId: string | undefined;
+};
+
function handoffEndpointsAtom(
environmentId: EnvironmentId,
{ item, sourceThreadId }: OrchestrationV2ProjectedTurnItem,
@@ -39,6 +48,7 @@ export function ThreadHandoffRow(props: {
environmentId: EnvironmentId;
projectedItem: OrchestrationV2ProjectedTurnItem;
iconColor: ColorValue;
+ surfaceColor: string;
}) {
const { item } = props.projectedItem;
const endpointsAtom = useMemo(
@@ -53,6 +63,7 @@ export function ThreadHandoffRow(props: {
environmentId={props.environmentId}
endpoints={endpoints}
iconColor={color}
+ surfaceColor={props.surfaceColor}
label="Context handoff"
failed={item.status === "failed"}
/>
@@ -63,11 +74,29 @@ export function ThreadHandoffDivider(props: {
environmentId: EnvironmentId;
endpoints: HandoffEndpoints;
iconColor: ColorValue;
+ surfaceColor: string;
label: string;
failed?: boolean;
}) {
const config = useAtomValue(serverEnvironment.configValueAtom(props.environmentId));
const { endpoints } = props;
+ const endpointProps = {
+ providers: (config?.providers ?? []).map((provider) => {
+ const rawConfig = config?.settings.providerInstances[provider.instanceId]?.config;
+ const instanceConfig =
+ rawConfig !== null && typeof rawConfig === "object"
+ ? (rawConfig as Readonly<Record<string, unknown>>)
+ : null;
+ const agentId = instanceConfig?.source === "local" ? undefined : instanceConfig?.agentId;
+ return {
+ ...provider,
+ driverKind: provider.driver,
+ accentColor: normalizeProviderAccentColor(provider.accentColor),
+ acpRegistryAgentId: typeof agentId === "string" ? agentId.trim() || undefined : undefined,
+ };
+ }),
+ surfaceColor: props.surfaceColor,
+ };
return (
<ThreadContextDivider
label={props.label}
@@ -81,7 +110,7 @@ export function ThreadHandoffDivider(props: {
key={`${endpoint.instanceId}:${endpoint.model ?? ""}`}
className="max-w-full flex-row items-center"
>
- <HandoffEndpoint {...endpoint} providers={config?.providers ?? []} />
+ <HandoffEndpoint {...endpoint} {...endpointProps} />
{index < endpoints.from.length - 1 ? (
<Text accessible={false} className="text-xs text-foreground-muted">
,
@@ -92,7 +121,7 @@ export function ThreadHandoffDivider(props: {
{endpoints.from.length > 0 ? (
<SymbolView name="arrow.right" size={12} tintColor={props.iconColor} />
) : null}
- <HandoffEndpoint {...endpoints.to} providers={config?.providers ?? []} />
+ <HandoffEndpoint {...endpoints.to} {...endpointProps} />
</View>
</ThreadContextDivider>
);
@@ -101,7 +130,8 @@ export function ThreadHandoffDivider(props: {
function HandoffEndpoint(props: {
instanceId: ProviderInstanceId;
model?: string | undefined;
- providers: ReadonlyArray<ServerProvider>;
+ providers: ReadonlyArray<HandoffProvider>;
+ surfaceColor: string;
}) {
const provider = props.providers.find((candidate) => candidate.instanceId === props.instanceId);
const model = provider?.models.find((candidate) => candidate.slug === props.model);
@@ -110,12 +140,13 @@ function HandoffEndpoint(props: {
model?.name ??
props.model ??
(provider ? resolveProviderInstanceDisplayName(provider) : props.instanceId);
+ const showBadge = provider !== undefined && shouldShowInstanceBadge(provider, props.providers);
return (
<Pressable
accessibilityRole="button"
accessibilityLabel={label}
accessibilityHint="Show provider account"
- className="min-h-6 max-w-full flex-row items-center justify-center gap-1"
+ className="min-h-6 max-w-full flex-row items-center justify-center gap-1.5"
hitSlop={{ top: 8, bottom: 8 }}
onPress={() =>
Dialog.alert(
@@ -124,11 +155,23 @@ function HandoffEndpoint(props: {
)
}
>
- <ProviderIcon
- provider={provider?.driver ?? props.instanceId}
- iconUrl={provider?.iconUrl}
- size={12}
- />
+ {showBadge && provider !== undefined ? (
+ <ProviderInstanceIcon
+ provider={provider.driver}
+ iconUrl={provider.iconUrl}
+ size={14}
+ displayName={resolveProviderInstanceDisplayName(provider)}
+ accentColor={provider.accentColor}
+ showBadge
+ surfaceColor={props.surfaceColor}
+ />
+ ) : (
+ <ProviderIcon
+ provider={provider?.driver ?? props.instanceId}
+ iconUrl={provider?.iconUrl}
+ size={12}
+ />
+ )}
<Text numberOfLines={1} className="shrink text-xs text-foreground-muted">
{label}
</Text>
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index 77d30a08588..425007855ba 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -8001,6 +8001,7 @@ export default function ChatView(props: ChatViewProps) {
<>
<div className="chat-content-lane">
<HandoffRow
+ environmentId={environmentId}
endpoints={pendingHandoff}
providers={providerStatuses}
pending
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx
index 7f912cfef5e..0d743bb2dc5 100644
--- a/apps/web/src/components/Sidebar.tsx
+++ b/apps/web/src/components/Sidebar.tsx
@@ -905,8 +905,8 @@ function SidebarProviderStack(props: {
acpRegistryAgentId={currentEntry.acpRegistryAgentId}
acpRegistryIconUrl={currentEntry.acpRegistryIconUrl}
showBadge={showInstanceBadge}
- iconClassName="size-3.5 opacity-60"
- badgeClassName="right-[-0.1875rem] bottom-[-0.1875rem] h-3 min-w-3 px-0.5 text-5xs"
+ size="compact"
+ iconClassName="opacity-60"
/>
);
if (stack.length === 1) {
diff --git a/apps/web/src/components/chat/ProviderInstanceIcon.tsx b/apps/web/src/components/chat/ProviderInstanceIcon.tsx
index 8479f75c856..c10dce7e938 100644
--- a/apps/web/src/components/chat/ProviderInstanceIcon.tsx
+++ b/apps/web/src/components/chat/ProviderInstanceIcon.tsx
@@ -61,6 +61,7 @@ export const ProviderInstanceIcon = memo(function ProviderInstanceIcon(props: {
acpRegistryIconUrl?: string | undefined;
showBadge?: boolean;
badgeContent?: "initials" | "none";
+ size?: "default" | "compact";
className?: string;
iconClassName?: string;
badgeClassName?: string;
@@ -74,6 +75,7 @@ export const ProviderInstanceIcon = memo(function ProviderInstanceIcon(props: {
? ({ "--provider-accent": props.accentColor } as CSSProperties)
: undefined;
const badgeContent = props.badgeContent ?? "initials";
+ const iconClassName = cn(props.size === "compact" && "size-3.5", props.iconClassName);
const isAcpRegistry = props.driverKind === "acpRegistry";
const acpRegistryIconUrl = resolveProviderInstanceAcpRegistryIconUrl({
driverKind: props.driverKind,
@@ -92,20 +94,20 @@ export const ProviderInstanceIcon = memo(function ProviderInstanceIcon(props: {
>
{isAcpRegistry ? (
<AcpRegistryAgentIcon
- className={cn("size-5 rounded-none bg-transparent", props.iconClassName)}
+ className={cn("size-5 rounded-none bg-transparent", iconClassName)}
fallbackClassName="size-full"
icon={acpRegistryIconUrl}
/>
) : packageIcon ? (
<ProviderPackageIcon
icon={packageIcon}
- className={cn("size-5 shrink-0", props.iconClassName)}
+ className={cn("size-5 shrink-0", iconClassName)}
aria-hidden
/>
) : Icon ? (
- <Icon className={cn("size-5 shrink-0", props.iconClassName)} aria-hidden />
+ <Icon className={cn("size-5 shrink-0", iconClassName)} aria-hidden />
) : (
- <span className={cn("text-3xs font-semibold leading-none", props.iconClassName)}>
+ <span className={cn("text-3xs font-semibold leading-none", iconClassName)}>
{providerInstanceInitials(props.displayName)}
</span>
)}
@@ -126,6 +128,8 @@ export const ProviderInstanceIcon = memo(function ProviderInstanceIcon(props: {
props.accentColor
? "bg-(--provider-accent) text-white"
: "bg-card text-muted-foreground",
+ props.size === "compact" &&
+ "right-[-0.1875rem] bottom-[-0.1875rem] h-3 min-w-3 px-0.5 text-5xs",
props.badgeClassName,
)}
style={{ borderColor: indicatorBackground }}
diff --git a/apps/web/src/components/chat/V2LifecycleRow.tsx b/apps/web/src/components/chat/V2LifecycleRow.tsx
index 3a59284ff4c..06e6f8fc3b3 100644
--- a/apps/web/src/components/chat/V2LifecycleRow.tsx
+++ b/apps/web/src/components/chat/V2LifecycleRow.tsx
@@ -42,7 +42,12 @@ import {
} from "lucide-react";
import { Tooltip, TooltipTrigger, TooltipPopup } from "../ui/tooltip";
-import { getProviderInstanceEntry } from "../../providerInstances";
+import {
+ applyProviderInstanceSettings,
+ deriveProviderInstanceEntries,
+ shouldShowInstanceBadge,
+ type ProviderInstanceEntry,
+} from "../../providerInstances";
import { formatShortTimestamp } from "../../timestampFormat";
import { getTriggerDisplayModelName } from "./providerIconUtils";
import { ProviderInstanceIcon, providerTextColor } from "./ProviderInstanceIcon";
@@ -575,16 +580,20 @@ function EnvironmentHandoffRow({
}) {
const providers =
useAtomValue(serverEnvironment.providersValueAtom(environmentId)) ?? EMPTY_SERVER_PROVIDERS;
- return <HandoffRow {...props} providers={providers} />;
+ return <HandoffRow {...props} environmentId={environmentId} providers={providers} />;
}
export function HandoffRow(props: {
+ readonly environmentId: EnvironmentId;
readonly endpoints: HandoffEndpoints;
readonly providers: ReadonlyArray<ServerProvider>;
readonly pending?: boolean;
readonly failed?: boolean;
}) {
const { from: fromEndpoints, to } = props.endpoints;
+ const settings = useAtomValue(serverEnvironment.settingsValueAtom(props.environmentId));
+ const derived = deriveProviderInstanceEntries(props.providers);
+ const entries = settings ? applyProviderInstanceSettings(derived, settings, null) : derived;
return (
<TimelineSystemDivider
label={props.pending ? "Context handoff pending" : "Context handoff"}
@@ -599,7 +608,7 @@ export function HandoffRow(props: {
className="inline-flex min-w-0 items-center"
>
<HandoffEndpoint
- providers={props.providers}
+ entries={entries}
instanceId={endpoint.instanceId}
model={endpoint.model}
/>
@@ -613,11 +622,7 @@ export function HandoffRow(props: {
{fromEndpoints.length > 0 ? (
<ArrowRightIcon aria-hidden="true" className="size-3 shrink-0" />
) : null}
- <HandoffEndpoint
- providers={props.providers}
- instanceId={to.instanceId}
- model={to.model}
- />
+ <HandoffEndpoint entries={entries} instanceId={to.instanceId} model={to.model} />
</span>
}
/>
@@ -625,11 +630,12 @@ export function HandoffRow(props: {
}
function HandoffEndpoint(props: {
- readonly providers: ReadonlyArray<ServerProvider>;
+ readonly entries: ReadonlyArray<ProviderInstanceEntry>;
readonly instanceId: ProviderInstanceId;
readonly model?: string | undefined;
}) {
- const entry = getProviderInstanceEntry(props.providers, props.instanceId);
+ const entry = props.entries.find((candidate) => candidate.instanceId === props.instanceId);
+ const showBadge = entry !== undefined && shouldShowInstanceBadge(entry, props.entries);
const model = props.model?.trim();
const providerModel =
model === undefined || model.length === 0
@@ -650,14 +656,18 @@ function HandoffEndpoint(props: {
render={
<span
tabIndex={0}
- 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"
+ 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"
>
<ProviderInstanceIcon
driverKind={entry?.driverKind ?? ProviderDriverKind.make(props.instanceId)}
displayName={entry?.displayName ?? props.instanceId}
+ accentColor={entry?.accentColor}
acpRegistryAgentId={entry?.acpRegistryAgentId}
acpRegistryIconUrl={entry?.acpRegistryIconUrl}
- iconClassName="size-3"
+ showBadge={showBadge}
+ size="compact"
+ iconClassName={cn(showBadge && "opacity-60")}
+ indicatorBackground="var(--background)"
/>
<span
className={cn("truncate font-medium", labelColor.className)}
diff --git a/apps/web/src/providerInstances.ts b/apps/web/src/providerInstances.ts
index 1ac8e5e7e77..e574b48b486 100644
--- a/apps/web/src/providerInstances.ts
+++ b/apps/web/src/providerInstances.ts
@@ -203,7 +203,7 @@ export function sortProviderInstanceEntries(
return sorted;
}
-export function getProviderInstanceEntry(
+function getProviderInstanceEntry(
providers: ReadonlyArray<ServerProvider>,
instanceId: ProviderInstanceId,
): ProviderInstanceEntry | undefined {