Skip to content

Commit 9963635

Browse files
committed
feat(mobile): show compact workflow phase cards
1 parent f82eb01 commit 9963635

4 files changed

Lines changed: 452 additions & 123 deletions

File tree

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,28 +88,21 @@ export function ThreadAgentsSheet({ route }: StaticScreenProps<AgentsTarget>) {
8888
) : (
8989
subagents.map((subagent) => {
9090
const group = workflowGroups.get(subagent.id);
91-
const row = (
92-
<AgentRow
93-
subagent={
94-
subagent.workflow?.name === undefined
95-
? subagent
96-
: { ...subagent, title: subagent.workflow.name }
97-
}
98-
environmentId={target.environmentId}
99-
tickSeconds={hasLiveAgent}
100-
onOpen={openChildThread}
101-
/>
102-
);
10391
return group === undefined ? (
10492
<View key={subagent.id} className="border-b border-border">
105-
{row}
93+
<AgentRow
94+
subagent={subagent}
95+
environmentId={target.environmentId}
96+
tickSeconds={hasLiveAgent}
97+
onOpen={openChildThread}
98+
/>
10699
</View>
107100
) : (
108101
<ThreadWorkflowGroup
109102
key={subagent.id}
110103
environmentId={target.environmentId}
104+
subagent={subagent}
111105
group={group}
112-
header={row}
113106
onOpen={openChildThread}
114107
/>
115108
);

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

Lines changed: 156 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,173 @@
11
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
22
import {
33
isActiveSubagentStatus,
4-
workflowPhaseElapsed,
5-
workflowPhaseStatus,
64
type RuntimeSubagent,
75
type SubagentWorkflowGroup,
86
} from "@t3tools/client-runtime/state/subagentRuntime";
9-
import { ThreadId, type EnvironmentId } from "@t3tools/contracts";
7+
import {
8+
ThreadId,
9+
type EnvironmentId,
10+
type OrchestrationV2Subagent,
11+
type ServerProvider,
12+
} from "@t3tools/contracts";
1013
import { deriveSubagentElapsedMs, formatDuration } from "@t3tools/shared/orchestrationTiming";
11-
import { useState, type ReactNode } from "react";
12-
import { Pressable, View } from "react-native";
14+
import { Fragment, useState } from "react";
15+
import { Pressable, ScrollView, View } from "react-native";
1316

1417
import { AppText as Text } from "../../components/AppText";
15-
import { SymbolView } from "../../components/AppSymbol";
18+
import { SymbolView, type AppSymbolName } from "../../components/AppSymbol";
1619
import { cn } from "../../lib/cn";
17-
import { useThreadShell } from "../../state/entities";
18-
import { subagentCardDetail } from "./subagent-card-presentation";
20+
import { useEnvironmentServerConfig, useThreadShell } from "../../state/entities";
1921
import { SUBAGENT_TONE_TEXT_CLASS, SubagentStatusDot } from "./SubagentStatusDot";
20-
import { resolveSubagentRowPresentation, workflowGroupSummary } from "./threadAgentsPresentation";
22+
import { SubagentStopButton } from "./SubagentStopButton";
23+
import {
24+
nextWorkflowSelection,
25+
resolveSubagentRowPresentation,
26+
workflowMemberDetail,
27+
workflowMemberMetadata,
28+
workflowRail,
29+
type WorkflowRailTone,
30+
} from "./threadAgentsPresentation";
2131
import { useVisibleSecondClock } from "./use-visible-second-clock";
2232

33+
const RAIL_ICON = {
34+
working: { name: "circle.inset.filled", tint: "accent-adaptive-sky-600-400" },
35+
completed: { name: "checkmark.circle.fill", tint: "accent-adaptive-emerald-600-400" },
36+
failed: { name: "xmark.circle.fill", tint: "accent-adaptive-rose-600-400" },
37+
stopped: { name: "circle", tint: "accent-icon-subtle" },
38+
queued: { name: "circle.dashed", tint: "accent-icon-subtle" },
39+
} as const satisfies Record<WorkflowRailTone, { name: AppSymbolName; tint: string }>;
40+
2341
export function ThreadWorkflowGroup(props: {
2442
readonly environmentId: EnvironmentId;
43+
readonly subagent: OrchestrationV2Subagent;
2544
readonly group: SubagentWorkflowGroup;
26-
readonly header: ReactNode;
2745
readonly onOpen: (threadId: ThreadId) => void;
2846
}) {
2947
const { group } = props;
30-
const [expanded, setExpanded] = useState(() => isActiveSubagentStatus(group.workflow.status));
31-
const [phaseOpen, setPhaseOpen] = useState<ReadonlyMap<number, boolean>>(() => new Map());
48+
const provider = useEnvironmentServerConfig(props.environmentId)?.providers.find(
49+
(candidate) => candidate.instanceId === props.subagent.providerInstanceId,
50+
);
51+
const [selected, setSelected] = useState<string | null>(null);
52+
const rail = workflowRail(group);
53+
const open = rail.find((item) => item.key === selected);
3254
const label = group.workflow.workflowName ?? group.workflow.title;
33-
const summary = workflowGroupSummary(group);
34-
const phases = group.phases.filter((phase) => phase.members.length > 0);
55+
const tone = resolveSubagentRowPresentation(props.subagent).tone;
3556

3657
return (
37-
<View className="border-b border-border pb-2">
38-
{props.header}
39-
<View className="-mt-2 flex-row items-center gap-2">
58+
<View className="my-2 rounded-[20px] border border-border border-continuous bg-card px-3 pb-1">
59+
<View className="flex-row items-center gap-1">
4060
<Pressable
4161
accessibilityRole="button"
42-
accessibilityLabel={`${expanded ? "Collapse" : "Expand"} ${label}, ${summary}`}
43-
accessibilityState={{ expanded }}
44-
onPress={() => setExpanded(!expanded)}
45-
className="min-h-11 min-w-0 flex-1 flex-row items-center gap-3 rounded-lg active:opacity-70"
62+
accessibilityLabel={`${label} workflow`}
63+
accessibilityHint={open ? "Collapses the workflow" : "Opens the current phase"}
64+
accessibilityState={{ expanded: open !== undefined }}
65+
disabled={rail.length === 0}
66+
onPress={() => setSelected(nextWorkflowSelection(rail, selected))}
67+
className="min-h-11 min-w-0 flex-1 flex-row items-center gap-2.5 active:opacity-70"
4668
>
47-
<View className="w-2 items-center">
69+
<View>
4870
<SymbolView
49-
name={expanded ? "chevron.down" : "chevron.right"}
50-
size={11}
51-
tintColorClassName="accent-icon-subtle"
71+
name="point.3.connected.trianglepath.dotted"
72+
size={18}
73+
tintColorClassName="accent-icon-muted"
5274
/>
75+
<View className="absolute -right-0.5 -top-0.5">
76+
<SubagentStatusDot tone={tone} />
77+
</View>
5378
</View>
54-
<Text numberOfLines={1} className="min-w-0 shrink text-xs text-foreground-muted">
55-
{summary}
79+
<Text
80+
numberOfLines={1}
81+
className="min-w-0 shrink font-t3-medium text-base text-foreground"
82+
>
83+
{label}
5684
</Text>
85+
{rail.length > 0 ? (
86+
<SymbolView
87+
name={open ? "chevron.up" : "chevron.down"}
88+
size={12}
89+
tintColorClassName="accent-icon-subtle"
90+
/>
91+
) : null}
5792
</Pressable>
93+
<WorkflowElapsed timing={group.workflow} />
94+
<SubagentStopButton environmentId={props.environmentId} subagent={props.subagent} />
5895
</View>
59-
{expanded ? (
60-
<View className="ml-[3px] border-l border-border pl-3.5">
61-
{phases.map((phase) => {
62-
const open = phaseOpen.get(phase.index) ?? phase.state === "running";
63-
const status = workflowPhaseStatus(phase);
64-
const count = `${phase.settledCount}/${phase.members.length} ${phase.members.length === 1 ? "agent" : "agents"}`;
96+
{rail.length > 0 ? (
97+
<ScrollView
98+
horizontal
99+
showsHorizontalScrollIndicator={false}
100+
className="-mx-3"
101+
contentContainerClassName="items-center px-3"
102+
>
103+
{rail.map((item, position) => {
104+
const icon = RAIL_ICON[item.tone];
105+
const isOpen = item.key === selected;
106+
const count =
107+
item.tone === "working" || item.tone === "failed"
108+
? `${item.completedCount}/${item.members.length}`
109+
: null;
65110
return (
66-
<View key={phase.index}>
111+
<Fragment key={item.key}>
112+
{position > 0 ? <View className="mx-0.5 h-px w-2 bg-border" /> : null}
67113
<Pressable
68114
accessibilityRole="button"
69-
accessibilityLabel={`${phase.title} phase, ${status}, ${count} done`}
70-
accessibilityState={{ expanded: open }}
71-
onPress={() =>
72-
setPhaseOpen((current) => new Map(current).set(phase.index, !open))
73-
}
74-
className="min-h-11 flex-row items-center gap-2 active:opacity-70"
115+
accessibilityLabel={`${item.title} phase, ${item.tone}${count ? `, ${count} completed` : ""}`}
116+
accessibilityState={{ expanded: isOpen }}
117+
onPress={() => setSelected(nextWorkflowSelection(rail, selected, item.key))}
118+
className="min-h-11 justify-center active:opacity-70"
75119
>
76-
<SymbolView
77-
name={open ? "chevron.down" : "chevron.right"}
78-
size={10}
79-
tintColorClassName="accent-icon-subtle"
80-
/>
81-
<Text
82-
numberOfLines={1}
120+
<View
83121
className={cn(
84-
"min-w-0 shrink font-t3-medium text-xs",
85-
phase.state === "running" ? "text-foreground" : "text-foreground-muted",
122+
"flex-row items-center gap-1.5 rounded-lg px-2 py-1",
123+
isOpen && "bg-foreground/10",
86124
)}
87125
>
88-
{phase.title}
89-
</Text>
90-
{status === "failed" ? (
126+
<SymbolView name={icon.name} size={13} tintColorClassName={icon.tint} />
91127
<Text
92-
className={cn("text-2xs font-t3-medium", SUBAGENT_TONE_TEXT_CLASS.failed)}
128+
numberOfLines={1}
129+
className={cn(
130+
"max-w-40 text-sm",
131+
item.tone === "failed"
132+
? SUBAGENT_TONE_TEXT_CLASS.failed
133+
: item.tone === "working" || isOpen
134+
? "text-foreground"
135+
: "text-foreground-muted",
136+
)}
93137
>
94-
Failed
138+
{item.title}
95139
</Text>
96-
) : null}
97-
<View className="flex-1" />
98-
<Text className="text-2xs tabular-nums text-foreground-muted">{count}</Text>
99-
<WorkflowElapsed timing={workflowPhaseElapsed(phase)} />
140+
{count ? (
141+
<Text className="text-xs tabular-nums text-foreground-muted">{count}</Text>
142+
) : null}
143+
</View>
100144
</Pressable>
101-
{open
102-
? phase.members.map((member) => (
103-
<WorkflowMemberRow
104-
key={member.id}
105-
environmentId={props.environmentId}
106-
member={member}
107-
onOpen={props.onOpen}
108-
/>
109-
))
110-
: null}
111-
</View>
145+
</Fragment>
112146
);
113147
})}
114-
{group.unphasedMembers.map((member) => (
115-
<WorkflowMemberRow
116-
key={member.id}
117-
environmentId={props.environmentId}
118-
member={member}
119-
onOpen={props.onOpen}
120-
/>
121-
))}
122-
</View>
148+
</ScrollView>
123149
) : null}
150+
{open === undefined ? null : open.members.length === 0 ? (
151+
<Text className="pb-2 pl-1 text-xs text-foreground-muted">No agents yet</Text>
152+
) : (
153+
open.members.map((member) => (
154+
<WorkflowMemberRow
155+
key={member.id}
156+
environmentId={props.environmentId}
157+
member={member}
158+
provider={provider}
159+
onOpen={props.onOpen}
160+
/>
161+
))
162+
)}
124163
</View>
125164
);
126165
}
127166

128167
function WorkflowMemberRow(props: {
129168
readonly environmentId: EnvironmentId;
130169
readonly member: RuntimeSubagent;
170+
readonly provider: ServerProvider | undefined;
131171
readonly onOpen: (threadId: ThreadId) => void;
132172
}) {
133173
const { member } = props;
@@ -140,19 +180,26 @@ function WorkflowMemberRow(props: {
140180
title: member.title,
141181
prompt: "",
142182
status: member.status,
143-
progress: member.progress ?? undefined,
144-
result: member.result ?? member.error,
183+
result: null,
145184
childThreadId: threadId,
146185
});
147-
const detail = subagentCardDetail(presentation.detail);
186+
const { detail, error } = workflowMemberDetail(member);
187+
const metadata = workflowMemberMetadata(member, props.provider);
188+
const labels = [metadata.model, metadata.effort].filter((value) => value !== null);
148189
return (
149190
<Pressable
150191
accessibilityRole={canOpen ? "link" : undefined}
151-
accessibilityLabel={`${presentation.title}, ${presentation.statusLabel}`}
192+
accessibilityLabel={[
193+
presentation.title,
194+
presentation.statusLabel,
195+
...labels,
196+
...(metadata.speed === null ? [] : [metadata.speed]),
197+
...(error === null ? [] : [error]),
198+
].join(", ")}
152199
accessibilityHint={canOpen ? "Opens this agent's thread" : "Its thread is not available yet"}
153200
disabled={!canOpen}
154201
onPress={() => threadId !== null && props.onOpen(threadId)}
155-
className="min-h-11 flex-row gap-2.5 py-2 active:opacity-70"
202+
className="min-h-11 flex-row gap-2.5 py-2 pl-1 active:opacity-70"
156203
>
157204
<View className="h-5 justify-center">
158205
<SubagentStatusDot tone={presentation.tone} />
@@ -162,19 +209,41 @@ function WorkflowMemberRow(props: {
162209
<Text numberOfLines={1} className="min-w-0 flex-1 text-sm text-foreground">
163210
{presentation.title}
164211
</Text>
165-
<Text className={cn("shrink-0 text-xs", SUBAGENT_TONE_TEXT_CLASS[presentation.tone])}>
166-
{presentation.statusLabel}
167-
</Text>
168212
<WorkflowElapsed timing={member} />
169213
{canOpen ? (
170214
<SymbolView name="chevron.right" size={12} tintColorClassName="accent-icon-subtle" />
171215
) : null}
172216
</View>
217+
{labels.length > 0 || metadata.speed !== null ? (
218+
<View className="min-w-0 flex-row items-center">
219+
<Text numberOfLines={1} className="min-w-0 shrink text-xs text-foreground-muted">
220+
{labels.join(" · ")}
221+
{labels.length > 0 && metadata.speed !== null ? " · " : ""}
222+
</Text>
223+
{metadata.fast ? (
224+
<View className="shrink-0 flex-row items-center gap-0.5">
225+
<SymbolView
226+
name={{ ios: "bolt.fill", android: "bolt" }}
227+
size={11}
228+
tintColorClassName="accent-adaptive-amber-700-300"
229+
/>
230+
<Text className="text-xs text-adaptive-amber-700-300">{metadata.speed}</Text>
231+
</View>
232+
) : metadata.speed !== null ? (
233+
<Text className="shrink-0 text-xs text-foreground-muted">{metadata.speed}</Text>
234+
) : null}
235+
</View>
236+
) : null}
173237
{detail ? (
174-
<Text numberOfLines={2} className="text-xs text-foreground-muted">
238+
<Text numberOfLines={1} className="text-xs text-foreground-muted">
175239
{detail}
176240
</Text>
177241
) : null}
242+
{error ? (
243+
<Text numberOfLines={1} className={cn("text-xs", SUBAGENT_TONE_TEXT_CLASS.failed)}>
244+
{error}
245+
</Text>
246+
) : null}
178247
</View>
179248
</Pressable>
180249
);

0 commit comments

Comments
 (0)