Skip to content

Commit 80b33d4

Browse files
t3dotggclaude
andcommitted
fix(web): remote delegates show their harness icon, a parent row, and new links in settings
- Tasks delegated to a linked environment resolve their icon from that environment's provider instead of the "remote" driver label. - Answering an agent's link card refreshes the linked environments list. - A thread delegated from another machine gets a parent row in Lineage. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 48a2923 commit 80b33d4

8 files changed

Lines changed: 140 additions & 30 deletions

File tree

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
3030
import { SymbolView, type AppSymbolName } from "../../components/ui/AppSymbol";
3131
import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText";
3232
import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol";
33-
import { useLinkableMachines } from "../../state/peerLinks";
33+
import { peerLinkEnvironment, useLinkableMachines } from "../../state/peerLinks";
3434
import { mintPairingCodeOn } from "../../state/peerPairingCode";
35-
import { serverEnvironment } from "../../state/server";
3635
import { useEnvironmentScope, usePreparedConnection } from "../../state/session";
3736
import { useAtomCommand } from "../../state/use-atom-command";
3837
import { ListChoiceRow as SettingsChoiceRow } from "../../components/ui/ListChoiceRow";
@@ -107,13 +106,13 @@ function PendingLinkRequest(props: {
107106
const [open, setOpen] = useState(false);
108107
const [declining, setDeclining] = useState(false);
109108
const [error, setError] = useState<string | null>(null);
110-
const answer = useAtomCommand(serverEnvironment.answerLinkRequest, {
109+
const answer = useAtomCommand(peerLinkEnvironment.answerRequest, {
111110
label: "decline link request",
112111
reportFailure: false,
113112
reportDefect: false,
114113
});
115114
const canAnswer = useAtomValue(
116-
serverEnvironment.answerLinkRequest.permissionAtom(props.environmentId),
115+
peerLinkEnvironment.answerRequest.permissionAtom(props.environmentId),
117116
);
118117
const target = linkRequestTargetName(item);
119118

@@ -244,7 +243,7 @@ function LinkRequestSheet(props: {
244243
const [mintFailed, setMintFailed] = useState<ReadonlySet<EnvironmentId>>(new Set());
245244
// Submit then a tap can both run before a re-render; this guard is synchronous.
246245
const inFlight = useRef(false);
247-
const answer = useAtomCommand(serverEnvironment.answerLinkRequest, {
246+
const answer = useAtomCommand(peerLinkEnvironment.answerRequest, {
248247
label: "answer link request",
249248
// The failure cause holds the request, and with it the code; keep it out of the console.
250249
reportFailure: false,

‎apps/mobile/src/features/threads/thread-subagent-group.tsx‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
EnvironmentId,
88
OrchestrationV2Subagent,
99
OrchestrationV2TurnItem,
10+
ServerProvider,
1011
} from "@t3tools/contracts";
1112
import { Pressable, View, type ColorValue } from "react-native";
1213

@@ -41,14 +42,22 @@ function SubagentElapsed({ agents }: { readonly agents: ReadonlyArray<AgentTimin
4142

4243
function SubagentAvatar(props: {
4344
readonly item: SubagentItem;
44-
readonly iconUrl?: string | null | undefined;
45+
readonly provider: ServerProvider | undefined;
4546
}) {
47+
// A remote task's own driver is only a "remote" label.
48+
const driver =
49+
props.provider?.driver ??
50+
(props.item.remoteChild === undefined ? props.item.driver : undefined);
4651
return (
4752
<View
4853
accessible={false}
4954
className="h-7 w-7 shrink-0 items-center justify-center rounded-full border border-border bg-card"
5055
>
51-
<ProviderIcon provider={props.item.driver} iconUrl={props.iconUrl} size={15} />
56+
{driver === undefined ? (
57+
<SymbolView name="sparkles" size={13} tintColorClassName="accent-icon-muted" />
58+
) : (
59+
<ProviderIcon provider={driver} iconUrl={props.provider?.iconUrl} size={15} />
60+
)}
5261
</View>
5362
);
5463
}
@@ -91,11 +100,11 @@ export function ThreadSubagentGroup(props: {
91100
const expanded = props.expandedRows[props.anchorKey] ?? false;
92101
const serverConfigs = useServerConfigs();
93102
// A task in a linked environment runs a provider instance of that environment.
94-
const iconUrl = (item: SubagentItem) =>
103+
const providerOf = (item: SubagentItem) =>
95104
(item.remoteChild === undefined
96105
? config
97106
: serverConfigs.get(item.remoteChild.environmentId)
98-
)?.providers.find((provider) => provider.instanceId === item.providerInstanceId)?.iconUrl;
107+
)?.providers.find((provider) => provider.instanceId === item.providerInstanceId);
99108
return (
100109
<WorkLogBlock>
101110
{grouped ? (
@@ -109,7 +118,7 @@ export function ThreadSubagentGroup(props: {
109118
<View className="flex-row items-center">
110119
{agents.slice(0, 3).map((agent, index) => (
111120
<View key={agent.item.id} style={{ marginLeft: index === 0 ? 0 : -7 }}>
112-
<SubagentAvatar item={agent.item} iconUrl={iconUrl(agent.item)} />
121+
<SubagentAvatar item={agent.item} provider={providerOf(agent.item)} />
113122
</View>
114123
))}
115124
{agents.length > 3 ? (

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ import { useId, useRef, useState } from "react";
2828

2929
import { useEnvironmentScope, usePreparedConnection } from "../../state/session";
3030
import { mintPairingCodeOn } from "../../state/peerPairingCode";
31-
import { useLinkableMachines } from "../../state/peerLinks";
32-
import { serverEnvironment } from "../../state/server";
31+
import { peerLinkEnvironment, useLinkableMachines } from "../../state/peerLinks";
3332
import { useAtomCommand } from "../../state/use-atom-command";
3433
import { accessConfig } from "../auth/ConnectAgentSurface";
3534
import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
@@ -88,13 +87,13 @@ function PendingLinkRequest(props: {
8887
const [open, setOpen] = useState(false);
8988
const [declining, setDeclining] = useState(false);
9089
const [error, setError] = useState<string | null>(null);
91-
const answer = useAtomCommand(serverEnvironment.answerLinkRequest, {
90+
const answer = useAtomCommand(peerLinkEnvironment.answerRequest, {
9291
label: "decline link request",
9392
reportFailure: false,
9493
reportDefect: false,
9594
});
9695
const canAnswer = useAtomValue(
97-
serverEnvironment.answerLinkRequest.permissionAtom(props.environmentId),
96+
peerLinkEnvironment.answerRequest.permissionAtom(props.environmentId),
9897
);
9998
const target = linkRequestTargetName(item);
10099

@@ -223,7 +222,7 @@ function LinkRequestDialog(props: {
223222
const [mintFailed, setMintFailed] = useState<ReadonlySet<EnvironmentId>>(new Set());
224223
// Enter then a click can both run before a re-render; this guard is synchronous.
225224
const inFlight = useRef(false);
226-
const answer = useAtomCommand(serverEnvironment.answerLinkRequest, {
225+
const answer = useAtomCommand(peerLinkEnvironment.answerRequest, {
227226
label: "answer link request",
228227
// The failure cause holds the request, and with it the code; keep it out of the console.
229228
reportFailure: false,

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

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
isProviderNativeSubagentThread,
3333
NodeId,
3434
type EnvironmentId,
35+
type OrchestrationV2DelegatedFrom,
3536
type OrchestrationV2RemoteTaskChild,
3637
type OrchestrationV2Subagent,
3738
type OrchestrationV2ThreadShell,
@@ -60,6 +61,7 @@ import { useArchivedThreadSnapshots } from "../../lib/archivedThreadsState";
6061
import { buildThreadRouteParams } from "../../threadRoutes";
6162
import {
6263
useProjects,
64+
useQuietThreadShell,
6365
useThreadProjection,
6466
useThreadRelationshipShells,
6567
} from "../../state/entities";
@@ -261,7 +263,8 @@ function RemoteSubagentRow(props: {
261263
}
262264
>
263265
<ThreadRelationshipIcon
264-
driver={props.agent.driver}
266+
// The task's own driver here is only a "remote" label.
267+
driver={props.provider?.driver}
265268
provider={props.provider}
266269
fallbackIcon={BotIcon}
267270
status={status}
@@ -287,6 +290,62 @@ function RemoteSubagentRow(props: {
287290
);
288291
}
289292

293+
/**
294+
* The thread on a linked environment whose agent delegated this one. It opens
295+
* there when this client is connected to that environment.
296+
*/
297+
function DelegatedFromRow(props: {
298+
readonly delegatedFrom: OrchestrationV2DelegatedFrom;
299+
readonly fallbackLabel: string | undefined;
300+
}) {
301+
const navigate = useNavigate();
302+
const { delegatedFrom } = props;
303+
const environment = useEnvironment(delegatedFrom.environmentId);
304+
const parentRef = scopeThreadRef(delegatedFrom.environmentId, delegatedFrom.threadId);
305+
// The title it had at delegation, until this client sees the parent itself.
306+
const parent = useQuietThreadShell(parentRef);
307+
const label = environment?.label ?? props.fallbackLabel;
308+
const title = parent?.title ?? delegatedFrom.title;
309+
return (
310+
<li className="group relative flex h-8 items-center rounded-lg">
311+
<Tooltip>
312+
<TooltipTrigger
313+
delay={200}
314+
render={
315+
<ThreadDetailsControl
316+
size="sm"
317+
variant="ghost"
318+
part="row"
319+
disabled={environment === null}
320+
onClick={() =>
321+
void navigate({
322+
to: "/$environmentId/$threadId",
323+
params: buildThreadRouteParams(parentRef),
324+
})
325+
}
326+
/>
327+
}
328+
>
329+
<ThreadRelationshipIcon fallbackIcon={CornerLeftUpIcon} status={null} />
330+
<span className="min-w-0 flex-1">
331+
<span className="block truncate text-left text-sm font-medium leading-4 text-foreground/85">
332+
{title}
333+
</span>
334+
</span>
335+
{label ? (
336+
<span className="shrink-0 text-2xs text-muted-foreground">on {label}</span>
337+
) : null}
338+
</TooltipTrigger>
339+
<TooltipPopup side="left">
340+
{environment === null
341+
? `Delegated from ${label ?? "a linked environment"}. Connect to it to open the parent thread.`
342+
: "Open parent agent"}
343+
</TooltipPopup>
344+
</Tooltip>
345+
</li>
346+
);
347+
}
348+
290349
export function ThreadRelationshipsPanel(props: {
291350
readonly environmentId: EnvironmentId;
292351
readonly threadId: ThreadId;
@@ -412,7 +471,15 @@ export function ThreadRelationshipsPanel(props: {
412471
(agent) => agent.childThreadId === null && agent.status === "running",
413472
).length ?? 0) + active.filter(({ edge }) => edge.status === "running").length;
414473

415-
if (relationshipRows.length === 0 && runningCount === 0 && remoteSubagents.length === 0) {
474+
// A linked environment's agent may have delegated this thread from there.
475+
const delegatedFrom = currentThread?.delegatedFrom;
476+
477+
if (
478+
relationshipRows.length === 0 &&
479+
runningCount === 0 &&
480+
remoteSubagents.length === 0 &&
481+
delegatedFrom === undefined
482+
) {
416483
return null;
417484
}
418485

@@ -487,7 +554,13 @@ export function ThreadRelationshipsPanel(props: {
487554
headingId="thread-details-lineage-heading"
488555
title={runningCount > 0 ? `Lineage · ${runningCount} running` : "Lineage"}
489556
// A lone "Previous agents" row names itself; the heading returns for status or actions.
490-
showHeading={runningCount > 0 || canDetach || related.length > 0 || active.length > 0}
557+
showHeading={
558+
runningCount > 0 ||
559+
canDetach ||
560+
related.length > 0 ||
561+
active.length > 0 ||
562+
delegatedFrom !== undefined
563+
}
491564
data-thread-relationships-panel
492565
actions={
493566
canDetach ? (
@@ -515,6 +588,14 @@ export function ThreadRelationshipsPanel(props: {
515588
) : null
516589
}
517590
>
591+
{delegatedFrom === undefined ? null : (
592+
<ThreadLineageRowList hiddenCount={0} onShowMore={() => {}}>
593+
<DelegatedFromRow
594+
delegatedFrom={delegatedFrom}
595+
fallbackLabel={currentThread?.linkOrigin?.label}
596+
/>
597+
</ThreadLineageRowList>
598+
)}
518599
{groups.map((group) => (
519600
<ThreadLineageGroup key={`${scopedThreadKey(ref)}:${group.id}`} {...group}>
520601
{(visibleRows) =>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const V2SubagentGroup = memo(function V2SubagentGroup({
109109
environmentId={ctx.activeThreadEnvironmentId}
110110
providerInstanceId={item.providerInstanceId}
111111
driver={item.driver}
112+
remote={item.remoteChild}
112113
status={agents.length === 1 ? status : undefined}
113114
/>
114115
))}

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,25 @@ function SubagentAvatar({
250250
export function EnvironmentSubagentAvatar({
251251
environmentId,
252252
providerInstanceId,
253+
driver,
254+
remote,
253255
...props
254256
}: {
255257
environmentId: EnvironmentId;
256258
providerInstanceId: ProviderInstanceId;
257259
driver?: ProviderDriverKind | undefined;
260+
/** A task in a linked environment runs a provider instance there; its driver here is only a label. */
261+
remote?: OrchestrationV2RemoteTaskChild | undefined;
258262
status?: OrchestrationV2TurnItem["status"] | undefined;
259263
}) {
260-
const providersAtom = serverEnvironment.providersValueAtom(environmentId);
264+
const providersAtom = serverEnvironment.providersValueAtom(
265+
remote?.environmentId ?? environmentId,
266+
);
267+
const providerDriver = useAtomValue(
268+
providersAtom,
269+
(providers) =>
270+
providers?.find((provider) => provider.instanceId === providerInstanceId)?.driver,
271+
);
261272
const displayName = useAtomValue(
262273
providersAtom,
263274
(providers) =>
@@ -268,7 +279,14 @@ export function EnvironmentSubagentAvatar({
268279
(providers) =>
269280
providers?.find((provider) => provider.instanceId === providerInstanceId)?.iconUrl,
270281
);
271-
return <SubagentAvatar {...props} displayName={displayName} iconUrl={iconUrl} />;
282+
return (
283+
<SubagentAvatar
284+
{...props}
285+
driver={providerDriver ?? (remote === undefined ? driver : undefined)}
286+
displayName={displayName}
287+
iconUrl={iconUrl}
288+
/>
289+
);
272290
}
273291

274292
const NOTIFICATION_OUTCOME_STATUS: Record<
@@ -399,6 +417,7 @@ function SubagentTimelineLink(props: {
399417
environmentId={props.parentRef.environmentId}
400418
providerInstanceId={props.providerInstanceId}
401419
driver={props.driver}
420+
remote={remote}
402421
status={status ?? undefined}
403422
/>
404423
<span className="min-w-0 flex-1">

‎packages/client-runtime/src/state/peerLinks.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ export function createPeerLinkEnvironmentAtoms<R, E>(
3030
onSuccess: ({ environmentId }, registry) =>
3131
Effect.sync(() => registry.refresh(list({ environmentId, input: {} }))),
3232
}),
33+
// An agent's link card. One answer per card at a time.
34+
answerRequest: createEnvironmentRpcCommand(runtime, {
35+
label: "environment-data:peer-links:answer-request",
36+
tag: WS_METHODS.peerLinksAnswerRequest,
37+
concurrency: {
38+
mode: "singleFlight",
39+
key: ({ environmentId, input }) =>
40+
JSON.stringify([environmentId, input.threadId, input.turnItemId]),
41+
},
42+
onSuccess: ({ environmentId }, registry) =>
43+
Effect.sync(() => registry.refresh(list({ environmentId, input: {} }))),
44+
}),
3345
};
3446
}
3547

‎packages/client-runtime/src/state/server.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,16 +1527,6 @@ export function createServerEnvironmentAtoms<R, E>(
15271527
JSON.stringify([environmentId, input.threadId, input.turnItemId]),
15281528
},
15291529
}),
1530-
// Like a secret card's answer: off the config lane, one per card at a time.
1531-
answerLinkRequest: createEnvironmentRpcCommand(runtime, {
1532-
label: "environment-data:server:peer-links:answer-request",
1533-
tag: WS_METHODS.peerLinksAnswerRequest,
1534-
concurrency: {
1535-
mode: "singleFlight",
1536-
key: ({ environmentId, input }) =>
1537-
JSON.stringify([environmentId, input.threadId, input.turnItemId]),
1538-
},
1539-
}),
15401530
refreshUsageRates: createEnvironmentRpcCommand(runtime, {
15411531
label: "environment-data:server:refresh-usage-rates",
15421532
tag: WS_METHODS.serverRefreshUsageRates,

0 commit comments

Comments
 (0)