import { HStack, Spacer, Text, VStack } from "@expo/ui/swift-ui"; import { font, foregroundStyle, lineLimit, padding } from "@expo/ui/swift-ui/modifiers"; import { createLiveActivity, type LiveActivityComponent, type LiveActivityLayout, } from "expo-widgets"; type LiveActivityEnvironment = Parameters>[1]; export type AgentActivityPhase = | "starting" | "running" | "waiting_for_approval" | "waiting_for_input" | "completed" | "failed" | "stale"; export interface AgentActivityRowProps { readonly environmentId: string; readonly threadId: string; readonly projectTitle: string; readonly threadTitle: string; readonly modelTitle: string; readonly phase: AgentActivityPhase; readonly status: string; readonly updatedAt: string; readonly deepLink: string; } export interface AgentActivityProps { readonly title: string; readonly subtitle: string; readonly activeCount: number; readonly updatedAt: string; readonly activities: ReadonlyArray; } export function AgentActivity( props: AgentActivityProps, environment: LiveActivityEnvironment, ): LiveActivityLayout { "widget"; const row0 = props.activities[0]; const row1 = props.activities[1]; const row2 = props.activities[2]; const updatedAtMatch = /^\d{4}-\d{2}-\d{2}T(\d{2}):(\d{2}):/.exec(props.updatedAt); const updatedAtHours24 = Number(updatedAtMatch?.[1]); const updatedAtMinutes = updatedAtMatch?.[2]; const updatedAt = Number.isInteger(updatedAtHours24) && updatedAtHours24 >= 0 && updatedAtHours24 <= 23 && updatedAtMinutes ? `${updatedAtHours24 % 12 || 12}:${updatedAtMinutes}` : "now"; const activeLabel = `${props.activeCount} active`; const isLight = environment.colorScheme === "light"; const primaryForeground = isLight ? "#262626" : "#f5f5f5"; const secondaryForeground = isLight ? "#525252" : "#a3a3a3"; const mutedForeground = isLight ? "#737373" : "#8e8e93"; const tint = environment.isLuminanceReduced ? secondaryForeground : row0?.phase === "waiting_for_approval" || row0?.phase === "waiting_for_input" ? "#f97316" : row0?.phase === "failed" ? "#ef4444" : "#14b8a6"; return { banner: ( {props.title} {props.subtitle} {activeLabel} {row0 ? ( {row0.threadTitle} {row0.projectTitle} - {row0.modelTitle} {row0.status} ) : null} {row1 ? ( {row1.threadTitle} {row1.projectTitle} - {row1.modelTitle} {row1.status} ) : null} {row2 ? ( {row2.threadTitle} {row2.projectTitle} - {row2.modelTitle} {row2.status} ) : null} Updated {updatedAt} ), bannerSmall: ( {props.title} {activeLabel} {row0 ? ( {row0.threadTitle} {row0.projectTitle} - {row0.status} ) : null} ), compactLeading: ( T3 ), compactTrailing: ( {activeLabel} ), minimal: ( T3 ), expandedLeading: ( {activeLabel} ), expandedCenter: row0 ? ( {row0.threadTitle} {row0.projectTitle} - {row0.status} ) : null, expandedTrailing: ( Updated {updatedAt} ), expandedBottom: ( {row0 ? ( {row0.threadTitle} {row0.projectTitle} - {row0.modelTitle} {row0.status} ) : null} {row1 ? ( {row1.threadTitle} {row1.projectTitle} - {row1.modelTitle} {row1.status} ) : null} {row2 ? ( {row2.threadTitle} {row2.projectTitle} - {row2.modelTitle} {row2.status} ) : null} ), }; } export default createLiveActivity("AgentActivity", AgentActivity);