Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AgentActivity.tsx

321 lines10.3 KB

1import { HStack, Spacer, Text, VStack } from "@expo/ui/swift-ui";
2import { font, foregroundStyle, lineLimit, padding } from "@expo/ui/swift-ui/modifiers";
3import {
4 createLiveActivity,
5 type LiveActivityComponent,
6 type LiveActivityLayout,
7} from "expo-widgets";
8​
9type LiveActivityEnvironment = Parameters<LiveActivityComponent<AgentActivityProps>>[1];
10​
11export type AgentActivityPhase =
12 | "starting"
13 | "running"
14 | "waiting_for_approval"
15 | "waiting_for_input"
16 | "completed"
17 | "failed"
18 | "stale";
19​
20export interface AgentActivityRowProps {
21 readonly environmentId: string;
22 readonly threadId: string;
23 readonly projectTitle: string;
24 readonly threadTitle: string;
25 readonly modelTitle: string;
26 readonly phase: AgentActivityPhase;
27 readonly status: string;
28 readonly updatedAt: string;
29 readonly deepLink: string;
31​
32export interface AgentActivityProps {
33 readonly title: string;
34 readonly subtitle: string;
35 readonly activeCount: number;
36 readonly updatedAt: string;
37 readonly activities: ReadonlyArray<AgentActivityRowProps>;
39​
40export function AgentActivity(
41 props: AgentActivityProps,
42 environment: LiveActivityEnvironment,
43): LiveActivityLayout {
44 "widget";
45​
46 const row0 = props.activities[0];
47 const row1 = props.activities[1];
48 const row2 = props.activities[2];
49 const updatedAtMatch = /^\d{4}-\d{2}-\d{2}T(\d{2}):(\d{2}):/.exec(props.updatedAt);
50 const updatedAtHours24 = Number(updatedAtMatch?.[1]);
51 const updatedAtMinutes = updatedAtMatch?.[2];
52 const updatedAt =
53 Number.isInteger(updatedAtHours24) &&
54 updatedAtHours24 >= 0 &&
55 updatedAtHours24 <= 23 &&
56 updatedAtMinutes
57 ? `${updatedAtHours24 % 12 || 12}:${updatedAtMinutes}`
58 : "now";
59 const activeLabel = `${props.activeCount} active`;
60 const isLight = environment.colorScheme === "light";
61 const primaryForeground = isLight ? "#262626" : "#f5f5f5";
62 const secondaryForeground = isLight ? "#525252" : "#a3a3a3";
63 const mutedForeground = isLight ? "#737373" : "#8e8e93";
64 const tint = environment.isLuminanceReduced
65 ? secondaryForeground
66 : row0?.phase === "waiting_for_approval" || row0?.phase === "waiting_for_input"
67 ? "#f97316"
68 : row0?.phase === "failed"
69 ? "#ef4444"
70 : "#14b8a6";
71​
72 return {
73 banner: (
74 <VStack modifiers={[padding({ all: 14 })]}>
75 <HStack>
76 <VStack>
77 <Text
78 modifiers={[font({ weight: "bold", size: 15 }), foregroundStyle(primaryForeground)]}
79 >
80 {props.title}
81 </Text>
82 <Text
83 modifiers={[font({ size: 12 }), foregroundStyle(secondaryForeground), lineLimit(1)]}
84 >
85 {props.subtitle}
86 </Text>
87 </VStack>
88 <Spacer minLength={8} />
89 <Text modifiers={[font({ weight: "semibold", size: 12 }), foregroundStyle(tint)]}>
90 {activeLabel}
91 </Text>
92 </HStack>
93 {row0 ? (
94 <HStack modifiers={[padding({ vertical: 4 })]}>
95 <VStack>
96 <Text
97 modifiers={[
98 font({ weight: "bold", size: 13 }),
99 foregroundStyle(primaryForeground),
100 lineLimit(1),
101 ]}
102 >
103 {row0.threadTitle}
104 </Text>
105 <Text
106 modifiers={[font({ size: 11 }), foregroundStyle(secondaryForeground), lineLimit(1)]}
107 >
108 {row0.projectTitle} - {row0.modelTitle}
109 </Text>
110 </VStack>
111 <Spacer minLength={8} />
112 <Text modifiers={[font({ weight: "semibold", size: 11 }), foregroundStyle(tint)]}>
113 {row0.status}
114 </Text>
115 </HStack>
116 ) : null}
117 {row1 ? (
118 <HStack modifiers={[padding({ vertical: 4 })]}>
119 <VStack>
120 <Text
121 modifiers={[
122 font({ weight: "bold", size: 13 }),
123 foregroundStyle(primaryForeground),
124 lineLimit(1),
125 ]}
126 >
127 {row1.threadTitle}
128 </Text>
129 <Text
130 modifiers={[font({ size: 11 }), foregroundStyle(secondaryForeground), lineLimit(1)]}
131 >
132 {row1.projectTitle} - {row1.modelTitle}
133 </Text>
134 </VStack>
135 <Spacer minLength={8} />
136 <Text modifiers={[font({ weight: "semibold", size: 11 }), foregroundStyle(tint)]}>
137 {row1.status}
138 </Text>
139 </HStack>
140 ) : null}
141 {row2 ? (
142 <HStack modifiers={[padding({ vertical: 4 })]}>
143 <VStack>
144 <Text
145 modifiers={[
146 font({ weight: "bold", size: 13 }),
147 foregroundStyle(primaryForeground),
148 lineLimit(1),
149 ]}
150 >
151 {row2.threadTitle}
152 </Text>
153 <Text
154 modifiers={[font({ size: 11 }), foregroundStyle(secondaryForeground), lineLimit(1)]}
155 >
156 {row2.projectTitle} - {row2.modelTitle}
157 </Text>
158 </VStack>
159 <Spacer minLength={8} />
160 <Text modifiers={[font({ weight: "semibold", size: 11 }), foregroundStyle(tint)]}>
161 {row2.status}
162 </Text>
163 </HStack>
164 ) : null}
165 <Text modifiers={[font({ size: 11 }), foregroundStyle(mutedForeground)]}>
166 Updated {updatedAt}
167 </Text>
168 </VStack>
169 ),
170 bannerSmall: (
171 <VStack modifiers={[padding({ all: 12 })]}>
172 <HStack>
173 <Text
174 modifiers={[font({ weight: "bold", size: 13 }), foregroundStyle(primaryForeground)]}
175 >
176 {props.title}
177 </Text>
178 <Spacer minLength={6} />
179 <Text modifiers={[font({ weight: "semibold", size: 12 }), foregroundStyle(tint)]}>
180 {activeLabel}
181 </Text>
182 </HStack>
183 {row0 ? (
184 <VStack>
185 <Text
186 modifiers={[
187 font({ weight: "bold", size: 12 }),
188 foregroundStyle(primaryForeground),
189 lineLimit(1),
190 ]}
191 >
192 {row0.threadTitle}
193 </Text>
194 <Text
195 modifiers={[font({ size: 11 }), foregroundStyle(secondaryForeground), lineLimit(1)]}
196 >
197 {row0.projectTitle} - {row0.status}
198 </Text>
199 </VStack>
200 ) : null}
201 </VStack>
202 ),
203 compactLeading: (
204 <Text modifiers={[font({ weight: "bold", size: 11 }), foregroundStyle(tint)]}>T3</Text>
205 ),
206 compactTrailing: (
207 <Text modifiers={[font({ weight: "semibold", size: 11 }), foregroundStyle(tint)]}>
208 {activeLabel}
209 </Text>
210 ),
211 minimal: (
212 <Text modifiers={[font({ weight: "bold", size: 11 }), foregroundStyle(tint)]}>T3</Text>
213 ),
214 expandedLeading: (
215 <VStack modifiers={[padding({ all: 8 })]}>
216 <Text modifiers={[font({ weight: "bold", size: 12 }), foregroundStyle(tint)]}>
217 {activeLabel}
218 </Text>
219 </VStack>
220 ),
221 expandedCenter: row0 ? (
222 <VStack>
223 <Text
224 modifiers={[
225 font({ weight: "bold", size: 12 }),
226 foregroundStyle(primaryForeground),
227 lineLimit(1),
228 ]}
229 >
230 {row0.threadTitle}
231 </Text>
232 <Text modifiers={[font({ size: 11 }), foregroundStyle(secondaryForeground), lineLimit(1)]}>
233 {row0.projectTitle} - {row0.status}
234 </Text>
235 </VStack>
236 ) : null,
237 expandedTrailing: (
238 <Text modifiers={[font({ size: 11 }), foregroundStyle(secondaryForeground)]}>
239 Updated {updatedAt}
240 </Text>
241 ),
242 expandedBottom: (
243 <VStack modifiers={[padding({ all: 8 })]}>
244 {row0 ? (
245 <HStack modifiers={[padding({ vertical: 4 })]}>
246 <VStack>
247 <Text
248 modifiers={[
249 font({ weight: "bold", size: 13 }),
250 foregroundStyle(primaryForeground),
251 lineLimit(1),
252 ]}
253 >
254 {row0.threadTitle}
255 </Text>
256 <Text
257 modifiers={[font({ size: 11 }), foregroundStyle(secondaryForeground), lineLimit(1)]}
258 >
259 {row0.projectTitle} - {row0.modelTitle}
260 </Text>
261 </VStack>
262 <Spacer minLength={8} />
263 <Text modifiers={[font({ weight: "semibold", size: 11 }), foregroundStyle(tint)]}>
264 {row0.status}
265 </Text>
266 </HStack>
267 ) : null}
268 {row1 ? (
269 <HStack modifiers={[padding({ vertical: 4 })]}>
270 <VStack>
271 <Text
272 modifiers={[
273 font({ weight: "bold", size: 13 }),
274 foregroundStyle(primaryForeground),
275 lineLimit(1),
276 ]}
277 >
278 {row1.threadTitle}
279 </Text>
280 <Text
281 modifiers={[font({ size: 11 }), foregroundStyle(secondaryForeground), lineLimit(1)]}
282 >
283 {row1.projectTitle} - {row1.modelTitle}
284 </Text>
285 </VStack>
286 <Spacer minLength={8} />
287 <Text modifiers={[font({ weight: "semibold", size: 11 }), foregroundStyle(tint)]}>
288 {row1.status}
289 </Text>
290 </HStack>
291 ) : null}
292 {row2 ? (
293 <HStack modifiers={[padding({ vertical: 4 })]}>
294 <VStack>
295 <Text
296 modifiers={[
297 font({ weight: "bold", size: 13 }),
298 foregroundStyle(primaryForeground),
299 lineLimit(1),
300 ]}
301 >
302 {row2.threadTitle}
303 </Text>
304 <Text
305 modifiers={[font({ size: 11 }), foregroundStyle(secondaryForeground), lineLimit(1)]}
306 >
307 {row2.projectTitle} - {row2.modelTitle}
308 </Text>
309 </VStack>
310 <Spacer minLength={8} />
311 <Text modifiers={[font({ weight: "semibold", size: 11 }), foregroundStyle(tint)]}>
312 {row2.status}
313 </Text>
314 </HStack>
315 ) : null}
316 </VStack>
317 ),
318 };
320​
321export default createLiveActivity<AgentActivityProps>("AgentActivity", AgentActivity);