Skip to content
TypeScript

fix(web): remote delegates show their harness icon, a parent row, and new links in settings (#26434)

Theo Browne96a330c9572a
diff --git a/apps/mobile/src/features/threads/LinkRequestCard.tsx b/apps/mobile/src/features/threads/LinkRequestCard.tsx
index ac960630018..4150c96a34e 100644
--- a/apps/mobile/src/features/threads/LinkRequestCard.tsx
+++ b/apps/mobile/src/features/threads/LinkRequestCard.tsx
@@ -30,9 +30,8 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
import { SymbolView, type AppSymbolName } from "../../components/ui/AppSymbol";
import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText";
import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol";
-import { useLinkableMachines } from "../../state/peerLinks";
+import { peerLinkEnvironment, useLinkableMachines } from "../../state/peerLinks";
import { mintPairingCodeOn } from "../../state/peerPairingCode";
-import { serverEnvironment } from "../../state/server";
import { useEnvironmentScope, usePreparedConnection } from "../../state/session";
import { useAtomCommand } from "../../state/use-atom-command";
import { ListChoiceRow as SettingsChoiceRow } from "../../components/ui/ListChoiceRow";
@@ -107,13 +106,13 @@ function PendingLinkRequest(props: {
const [open, setOpen] = useState(false);
const [declining, setDeclining] = useState(false);
const [error, setError] = useState<string | null>(null);
- const answer = useAtomCommand(serverEnvironment.answerLinkRequest, {
+ const answer = useAtomCommand(peerLinkEnvironment.answerRequest, {
label: "decline link request",
reportFailure: false,
reportDefect: false,
});
const canAnswer = useAtomValue(
- serverEnvironment.answerLinkRequest.permissionAtom(props.environmentId),
+ peerLinkEnvironment.answerRequest.permissionAtom(props.environmentId),
);
const target = linkRequestTargetName(item);
@@ -244,7 +243,7 @@ function LinkRequestSheet(props: {
const [mintFailed, setMintFailed] = useState<ReadonlySet<EnvironmentId>>(new Set());
// Submit then a tap can both run before a re-render; this guard is synchronous.
const inFlight = useRef(false);
- const answer = useAtomCommand(serverEnvironment.answerLinkRequest, {
+ const answer = useAtomCommand(peerLinkEnvironment.answerRequest, {
label: "answer link request",
// The failure cause holds the request, and with it the code; keep it out of the console.
reportFailure: false,
diff --git a/apps/mobile/src/features/threads/thread-subagent-group.tsx b/apps/mobile/src/features/threads/thread-subagent-group.tsx
index f83b85de0b8..cabd4eeb371 100644
--- a/apps/mobile/src/features/threads/thread-subagent-group.tsx
+++ b/apps/mobile/src/features/threads/thread-subagent-group.tsx
@@ -7,6 +7,7 @@ import type {
EnvironmentId,
OrchestrationV2Subagent,
OrchestrationV2TurnItem,
+ ServerProvider,
} from "@t3tools/contracts";
import { Pressable, View, type ColorValue } from "react-native";
@@ -41,14 +42,22 @@ function SubagentElapsed({ agents }: { readonly agents: ReadonlyArray<AgentTimin
function SubagentAvatar(props: {
readonly item: SubagentItem;
- readonly iconUrl?: string | null | undefined;
+ readonly provider: ServerProvider | undefined;
}) {
+ // A remote task's own driver is only a "remote" label.
+ const driver =
+ props.provider?.driver ??
+ (props.item.remoteChild === undefined ? props.item.driver : undefined);
return (
<View
accessible={false}
className="h-7 w-7 shrink-0 items-center justify-center rounded-full border border-border bg-card"
>
- <ProviderIcon provider={props.item.driver} iconUrl={props.iconUrl} size={15} />
+ {driver === undefined ? (
+ <SymbolView name="sparkles" size={13} tintColorClassName="accent-icon-muted" />
+ ) : (
+ <ProviderIcon provider={driver} iconUrl={props.provider?.iconUrl} size={15} />
+ )}
</View>
);
}
@@ -91,11 +100,11 @@ export function ThreadSubagentGroup(props: {
const expanded = props.expandedRows[props.anchorKey] ?? false;
const serverConfigs = useServerConfigs();
// A task in a linked environment runs a provider instance of that environment.
- const iconUrl = (item: SubagentItem) =>
+ const providerOf = (item: SubagentItem) =>
(item.remoteChild === undefined
? config
: serverConfigs.get(item.remoteChild.environmentId)
- )?.providers.find((provider) => provider.instanceId === item.providerInstanceId)?.iconUrl;
+ )?.providers.find((provider) => provider.instanceId === item.providerInstanceId);
return (
<WorkLogBlock>
{grouped ? (
@@ -109,7 +118,7 @@ export function ThreadSubagentGroup(props: {
<View className="flex-row items-center">
{agents.slice(0, 3).map((agent, index) => (
<View key={agent.item.id} style={{ marginLeft: index === 0 ? 0 : -7 }}>
- <SubagentAvatar item={agent.item} iconUrl={iconUrl(agent.item)} />
+ <SubagentAvatar item={agent.item} provider={providerOf(agent.item)} />
</View>
))}
{agents.length > 3 ? (
diff --git a/apps/web/src/components/chat/LinkRequestCard.tsx b/apps/web/src/components/chat/LinkRequestCard.tsx
index 728c8fe61ef..a9bdd0fb111 100644
--- a/apps/web/src/components/chat/LinkRequestCard.tsx
+++ b/apps/web/src/components/chat/LinkRequestCard.tsx
@@ -28,8 +28,7 @@ import { useId, useRef, useState } from "react";
import { useEnvironmentScope, usePreparedConnection } from "../../state/session";
import { mintPairingCodeOn } from "../../state/peerPairingCode";
-import { useLinkableMachines } from "../../state/peerLinks";
-import { serverEnvironment } from "../../state/server";
+import { peerLinkEnvironment, useLinkableMachines } from "../../state/peerLinks";
import { useAtomCommand } from "../../state/use-atom-command";
import { accessConfig } from "../auth/ConnectAgentSurface";
import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
@@ -88,13 +87,13 @@ function PendingLinkRequest(props: {
const [open, setOpen] = useState(false);
const [declining, setDeclining] = useState(false);
const [error, setError] = useState<string | null>(null);
- const answer = useAtomCommand(serverEnvironment.answerLinkRequest, {
+ const answer = useAtomCommand(peerLinkEnvironment.answerRequest, {
label: "decline link request",
reportFailure: false,
reportDefect: false,
});
const canAnswer = useAtomValue(
- serverEnvironment.answerLinkRequest.permissionAtom(props.environmentId),
+ peerLinkEnvironment.answerRequest.permissionAtom(props.environmentId),
);
const target = linkRequestTargetName(item);
@@ -223,7 +222,7 @@ function LinkRequestDialog(props: {
const [mintFailed, setMintFailed] = useState<ReadonlySet<EnvironmentId>>(new Set());
// Enter then a click can both run before a re-render; this guard is synchronous.
const inFlight = useRef(false);
- const answer = useAtomCommand(serverEnvironment.answerLinkRequest, {
+ const answer = useAtomCommand(peerLinkEnvironment.answerRequest, {
label: "answer link request",
// The failure cause holds the request, and with it the code; keep it out of the console.
reportFailure: false,
diff --git a/apps/web/src/components/chat/ThreadRelationshipsControl.tsx b/apps/web/src/components/chat/ThreadRelationshipsControl.tsx
index b37f9d1d107..e107bbc4039 100644
--- a/apps/web/src/components/chat/ThreadRelationshipsControl.tsx
+++ b/apps/web/src/components/chat/ThreadRelationshipsControl.tsx
@@ -32,6 +32,7 @@ import {
isProviderNativeSubagentThread,
NodeId,
type EnvironmentId,
+ type OrchestrationV2DelegatedFrom,
type OrchestrationV2RemoteTaskChild,
type OrchestrationV2Subagent,
type OrchestrationV2ThreadShell,
@@ -60,6 +61,7 @@ import { useArchivedThreadSnapshots } from "../../lib/archivedThreadsState";
import { buildThreadRouteParams } from "../../threadRoutes";
import {
useProjects,
+ useQuietThreadShell,
useThreadProjection,
useThreadRelationshipShells,
} from "../../state/entities";
@@ -261,7 +263,8 @@ function RemoteSubagentRow(props: {
}
>
<ThreadRelationshipIcon
- driver={props.agent.driver}
+ // The task's own driver here is only a "remote" label.
+ driver={props.provider?.driver}
provider={props.provider}
fallbackIcon={BotIcon}
status={status}
@@ -287,6 +290,62 @@ function RemoteSubagentRow(props: {
);
}
+/**
+ * The thread on a linked environment whose agent delegated this one. It opens
+ * there when this client is connected to that environment.
+ */
+function DelegatedFromRow(props: {
+ readonly delegatedFrom: OrchestrationV2DelegatedFrom;
+ readonly fallbackLabel: string | undefined;
+}) {
+ const navigate = useNavigate();
+ const { delegatedFrom } = props;
+ const environment = useEnvironment(delegatedFrom.environmentId);
+ const parentRef = scopeThreadRef(delegatedFrom.environmentId, delegatedFrom.threadId);
+ // The title it had at delegation, until this client sees the parent itself.
+ const parent = useQuietThreadShell(parentRef);
+ const label = environment?.label ?? props.fallbackLabel;
+ const title = parent?.title ?? delegatedFrom.title;
+ return (
+ <li className="group relative flex h-8 items-center rounded-lg">
+ <Tooltip>
+ <TooltipTrigger
+ delay={200}
+ render={
+ <ThreadDetailsControl
+ size="sm"
+ variant="ghost"
+ part="row"
+ disabled={environment === null}
+ onClick={() =>
+ void navigate({
+ to: "/$environmentId/$threadId",
+ params: buildThreadRouteParams(parentRef),
+ })
+ }
+ />
+ }
+ >
+ <ThreadRelationshipIcon fallbackIcon={CornerLeftUpIcon} status={null} />
+ <span className="min-w-0 flex-1">
+ <span className="block truncate text-left text-sm font-medium leading-4 text-foreground/85">
+ {title}
+ </span>
+ </span>
+ {label ? (
+ <span className="shrink-0 text-2xs text-muted-foreground">on {label}</span>
+ ) : null}
+ </TooltipTrigger>
+ <TooltipPopup side="left">
+ {environment === null
+ ? `Delegated from ${label ?? "a linked environment"}. Connect to it to open the parent thread.`
+ : "Open parent agent"}
+ </TooltipPopup>
+ </Tooltip>
+ </li>
+ );
+}
+
export function ThreadRelationshipsPanel(props: {
readonly environmentId: EnvironmentId;
readonly threadId: ThreadId;
@@ -412,7 +471,15 @@ export function ThreadRelationshipsPanel(props: {
(agent) => agent.childThreadId === null && agent.status === "running",
).length ?? 0) + active.filter(({ edge }) => edge.status === "running").length;
- if (relationshipRows.length === 0 && runningCount === 0 && remoteSubagents.length === 0) {
+ // A linked environment's agent may have delegated this thread from there.
+ const delegatedFrom = currentThread?.delegatedFrom;
+
+ if (
+ relationshipRows.length === 0 &&
+ runningCount === 0 &&
+ remoteSubagents.length === 0 &&
+ delegatedFrom === undefined
+ ) {
return null;
}
@@ -487,7 +554,13 @@ export function ThreadRelationshipsPanel(props: {
headingId="thread-details-lineage-heading"
title={runningCount > 0 ? `Lineage · ${runningCount} running` : "Lineage"}
// A lone "Previous agents" row names itself; the heading returns for status or actions.
- showHeading={runningCount > 0 || canDetach || related.length > 0 || active.length > 0}
+ showHeading={
+ runningCount > 0 ||
+ canDetach ||
+ related.length > 0 ||
+ active.length > 0 ||
+ delegatedFrom !== undefined
+ }
data-thread-relationships-panel
actions={
canDetach ? (
@@ -515,6 +588,14 @@ export function ThreadRelationshipsPanel(props: {
) : null
}
>
+ {delegatedFrom === undefined ? null : (
+ <ThreadLineageRowList hiddenCount={0} onShowMore={() => {}}>
+ <DelegatedFromRow
+ delegatedFrom={delegatedFrom}
+ fallbackLabel={currentThread?.linkOrigin?.label}
+ />
+ </ThreadLineageRowList>
+ )}
{groups.map((group) => (
<ThreadLineageGroup key={`${scopedThreadKey(ref)}:${group.id}`} {...group}>
{(visibleRows) =>
diff --git a/apps/web/src/components/chat/TimelineV2EventRow.tsx b/apps/web/src/components/chat/TimelineV2EventRow.tsx
index 66e1b6fac1d..e69ffdbaffd 100644
--- a/apps/web/src/components/chat/TimelineV2EventRow.tsx
+++ b/apps/web/src/components/chat/TimelineV2EventRow.tsx
@@ -109,6 +109,7 @@ const V2SubagentGroup = memo(function V2SubagentGroup({
environmentId={ctx.activeThreadEnvironmentId}
providerInstanceId={item.providerInstanceId}
driver={item.driver}
+ remote={item.remoteChild}
status={agents.length === 1 ? status : undefined}
/>
))}
diff --git a/apps/web/src/components/chat/V2LifecycleRow.tsx b/apps/web/src/components/chat/V2LifecycleRow.tsx
index e1af81cab35..42ab22fa5f3 100644
--- a/apps/web/src/components/chat/V2LifecycleRow.tsx
+++ b/apps/web/src/components/chat/V2LifecycleRow.tsx
@@ -250,14 +250,25 @@ function SubagentAvatar({
export function EnvironmentSubagentAvatar({
environmentId,
providerInstanceId,
+ driver,
+ remote,
...props
}: {
environmentId: EnvironmentId;
providerInstanceId: ProviderInstanceId;
driver?: ProviderDriverKind | undefined;
+ /** A task in a linked environment runs a provider instance there; its driver here is only a label. */
+ remote?: OrchestrationV2RemoteTaskChild | undefined;
status?: OrchestrationV2TurnItem["status"] | undefined;
}) {
- const providersAtom = serverEnvironment.providersValueAtom(environmentId);
+ const providersAtom = serverEnvironment.providersValueAtom(
+ remote?.environmentId ?? environmentId,
+ );
+ const providerDriver = useAtomValue(
+ providersAtom,
+ (providers) =>
+ providers?.find((provider) => provider.instanceId === providerInstanceId)?.driver,
+ );
const displayName = useAtomValue(
providersAtom,
(providers) =>
@@ -268,7 +279,14 @@ export function EnvironmentSubagentAvatar({
(providers) =>
providers?.find((provider) => provider.instanceId === providerInstanceId)?.iconUrl,
);
- return <SubagentAvatar {...props} displayName={displayName} iconUrl={iconUrl} />;
+ return (
+ <SubagentAvatar
+ {...props}
+ driver={providerDriver ?? (remote === undefined ? driver : undefined)}
+ displayName={displayName}
+ iconUrl={iconUrl}
+ />
+ );
}
const NOTIFICATION_OUTCOME_STATUS: Record<
@@ -399,6 +417,7 @@ function SubagentTimelineLink(props: {
environmentId={props.parentRef.environmentId}
providerInstanceId={props.providerInstanceId}
driver={props.driver}
+ remote={remote}
status={status ?? undefined}
/>
<span className="min-w-0 flex-1">
diff --git a/packages/client-runtime/src/state/peerLinks.ts b/packages/client-runtime/src/state/peerLinks.ts
index 6e65f62eeb7..9295bf1b401 100644
--- a/packages/client-runtime/src/state/peerLinks.ts
+++ b/packages/client-runtime/src/state/peerLinks.ts
@@ -30,6 +30,18 @@ export function createPeerLinkEnvironmentAtoms<R, E>(
onSuccess: ({ environmentId }, registry) =>
Effect.sync(() => registry.refresh(list({ environmentId, input: {} }))),
}),
+ // An agent's link card. One answer per card at a time.
+ answerRequest: createEnvironmentRpcCommand(runtime, {
+ label: "environment-data:peer-links:answer-request",
+ tag: WS_METHODS.peerLinksAnswerRequest,
+ concurrency: {
+ mode: "singleFlight",
+ key: ({ environmentId, input }) =>
+ JSON.stringify([environmentId, input.threadId, input.turnItemId]),
+ },
+ onSuccess: ({ environmentId }, registry) =>
+ Effect.sync(() => registry.refresh(list({ environmentId, input: {} }))),
+ }),
};
}
diff --git a/packages/client-runtime/src/state/server.ts b/packages/client-runtime/src/state/server.ts
index 3cb4f77325f..c8ce8b38787 100644
--- a/packages/client-runtime/src/state/server.ts
+++ b/packages/client-runtime/src/state/server.ts
@@ -1527,16 +1527,6 @@ export function createServerEnvironmentAtoms<R, E>(
JSON.stringify([environmentId, input.threadId, input.turnItemId]),
},
}),
- // Like a secret card's answer: off the config lane, one per card at a time.
- answerLinkRequest: createEnvironmentRpcCommand(runtime, {
- label: "environment-data:server:peer-links:answer-request",
- tag: WS_METHODS.peerLinksAnswerRequest,
- concurrency: {
- mode: "singleFlight",
- key: ({ environmentId, input }) =>
- JSON.stringify([environmentId, input.threadId, input.turnItemId]),
- },
- }),
refreshUsageRates: createEnvironmentRpcCommand(runtime, {
label: "environment-data:server:refresh-usage-rates",
tag: WS_METHODS.serverRefreshUsageRates,