Files
fly-sprites-workers/client/workers-screen.tsx
T

840 lines
30 KiB
TypeScript

import {
type PluginSurfaceProps,
openExternalUrl,
usePaseo,
useRpc,
} from "@getpaseo/plugin/client";
import type { PaseoAgent, PaseoWorkspace } from "@getpaseo/client";
import { ScrollView, TextInput, copyText, useToast } from "@getpaseo/plugin/client/ui";
import { useCallback, useEffect, useMemo, useState } from "react";
import { Pressable, Text, View } from "react-native";
import {
type CheckpointSummary,
type SpriteAgentSummary,
type SpriteHostSummary,
type SpriteSummary,
type TokenSource,
createCheckpointRpc,
createSpriteRpc,
destroySpriteRpc,
ensureSpriteHostRpc,
launchSpriteAgentRpc,
listCheckpointsRpc,
restoreCheckpointRpc,
spriteAgentActionRpc,
statusRpc,
syncWorkspaceRpc,
} from "../shared/contracts";
import { useOpenBaoAuth } from "./use-openbao-auth";
interface WorkersScreenProps extends PluginSurfaceProps {
workspaceName?: string;
workspaceDirectory?: string;
}
const PROVIDER_CHOICES = [
{ id: "auto", label: "Auto" },
{ id: "claude", label: "Claude" },
{ id: "codex", label: "Codex" },
{ id: "opencode", label: "OpenCode" },
{ id: "pi", label: "Pi" },
] as const;
function getWorkspacePath(ws: PaseoWorkspace): string {
return ws.workspaceDirectory || ws.projectRootPath;
}
export function FlySpritesWorkersScreen({
theme,
layout,
host,
navigation,
workspaceName,
workspaceDirectory,
}: WorkersScreenProps) {
const paseo = usePaseo();
const toast = useToast();
const fetchStatus = useRpc(statusRpc);
const createSprite = useRpc(createSpriteRpc);
const ensureSpriteHost = useRpc(ensureSpriteHostRpc);
const launchSpriteAgent = useRpc(launchSpriteAgentRpc);
const spriteAgentAction = useRpc(spriteAgentActionRpc);
const syncWorkspace = useRpc(syncWorkspaceRpc);
const destroySprite = useRpc(destroySpriteRpc);
const listCheckpoints = useRpc(listCheckpointsRpc);
const createCheckpoint = useRpc(createCheckpointRpc);
const restoreCheckpoint = useRpc(restoreCheckpointRpc);
const [configured, setConfigured] = useState(false);
const [tokenSource, setTokenSource] = useState<TokenSource>("none");
const [remoteError, setRemoteError] = useState<string | null>(null);
const [sprites, setSprites] = useState<SpriteSummary[]>([]);
const [spriteHosts, setSpriteHosts] = useState<SpriteHostSummary[]>([]);
const [spriteAgents, setSpriteAgents] = useState<SpriteAgentSummary[]>([]);
const [legacyAgents, setLegacyAgents] = useState<PaseoAgent[]>([]);
const [workspaces, setWorkspaces] = useState<PaseoWorkspace[]>([]);
const [loading, setLoading] = useState(true);
const [busy, setBusy] = useState(false);
const [agentBusyId, setAgentBusyId] = useState<string | null>(null);
const [spriteNameInput, setSpriteNameInput] = useState("");
const [agentTitleInput, setAgentTitleInput] = useState("");
const [promptInput, setPromptInput] = useState("");
const [cwdInput, setCwdInput] = useState(workspaceDirectory ?? "");
const [providerInput, setProviderInput] = useState<string>("auto");
const [syncBeforeOpen, setSyncBeforeOpen] = useState(true);
const [checkpointsSprite, setCheckpointsSprite] = useState<string | null>(null);
const [checkpoints, setCheckpoints] = useState<CheckpointSummary[]>([]);
useEffect(() => {
if (workspaceDirectory && !cwdInput) {
setCwdInput(workspaceDirectory);
setSyncBeforeOpen(true);
}
}, [workspaceDirectory, cwdInput]);
const refreshClusterState = useCallback(async () => {
const [agentsRes, workspacesRes] = await Promise.all([
paseo.agents.list().catch(() => null),
paseo.workspaces.list().catch(() => null),
]);
if (agentsRes) {
const flyAgents = agentsRes.entries
.map((entry) => entry.agent)
.filter((agent) => agent.provider === "fly-sprites" && !agent.archivedAt)
.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
setLegacyAgents(flyAgents);
}
if (workspacesRes) {
const activeWorkspaces = workspacesRes.entries.filter(
(ws) => !ws.archivingAt && !ws.background && Boolean(getWorkspacePath(ws)),
);
setWorkspaces(activeWorkspaces);
setCwdInput((cur) => {
if (cur || workspaceDirectory || activeWorkspaces.length === 0) return cur;
return getWorkspacePath(activeWorkspaces[0]);
});
}
}, [paseo, workspaceDirectory]);
const refresh = useCallback(async () => {
setLoading(true);
try {
const [statusRes] = await Promise.all([
fetchStatus({ includeRemote: true }),
refreshClusterState(),
]);
setConfigured(statusRes.configured);
setTokenSource(statusRes.tokenSource);
setRemoteError(statusRes.remoteError);
setSprites(statusRes.sprites);
setSpriteHosts(statusRes.spriteHosts);
setSpriteAgents(statusRes.spriteAgents);
} catch (error) {
toast.error(error instanceof Error ? error.message : String(error));
} finally {
setLoading(false);
}
}, [fetchStatus, refreshClusterState, toast]);
useEffect(() => {
void refresh();
}, [refresh]);
const openbao = useOpenBaoAuth({ onConnected: refresh });
const pendingFlow =
openbao.status?.pendingAuth?.status === "pending" ? openbao.status.pendingAuth : null;
const hostBySprite = useMemo(() => {
const map = new Map<string, SpriteHostSummary>();
for (const h of spriteHosts) {
map.set(h.spriteName, h);
}
return map;
}, [spriteHosts]);
const handleCreateSprite = async () => {
setBusy(true);
try {
const res = await createSprite({
name: spriteNameInput.trim() || undefined,
syncLocalPath: syncBeforeOpen && cwdInput.trim() ? cwdInput.trim() : undefined,
});
if (!res.ok) {
toast.error(res.error);
return;
}
toast.show(`Sprite ${res.sprite.name} ready`, { variant: "success" });
setSpriteNameInput(res.sprite.name);
await refresh();
} catch (error) {
toast.error(error instanceof Error ? error.message : String(error));
} finally {
setBusy(false);
}
};
const handleConnectHost = async (name?: string) => {
setBusy(true);
try {
const res = await ensureSpriteHost({
spriteName: name?.trim() || undefined,
syncLocalPath: syncBeforeOpen && cwdInput.trim() ? cwdInput.trim() : undefined,
});
if (!res.ok) {
toast.error(res.error);
return;
}
toast.show(`Sprite host ${res.spriteName} connected`, { variant: "success" });
setSpriteNameInput(res.spriteName);
await refresh();
} catch (error) {
toast.error(error instanceof Error ? error.message : String(error));
} finally {
setBusy(false);
}
};
const handleLaunchAgent = async () => {
const targetSprite = spriteNameInput.trim();
const initialPrompt = promptInput.trim();
const title = agentTitleInput.trim();
setBusy(true);
try {
const res = await launchSpriteAgent({
spriteName: targetSprite || undefined,
title: title || undefined,
prompt: initialPrompt || undefined,
syncLocalPath: syncBeforeOpen && cwdInput.trim() ? cwdInput.trim() : undefined,
provider: providerInput || "auto",
});
if (!res.ok) {
toast.error(res.error);
await refresh();
return;
}
toast.show(`Launched on ${res.spriteName} (${res.provider})`, { variant: "success" });
setSpriteNameInput(res.spriteName);
setPromptInput("");
setAgentTitleInput("");
await refresh();
navigation?.openAgent({ agentId: res.agentId, serverId: res.serverId });
} catch (error) {
toast.error(error instanceof Error ? error.message : String(error));
} finally {
setBusy(false);
}
};
const handleSpriteAgentAction = async (
agent: SpriteAgentSummary,
action: "interrupt" | "archive",
) => {
setAgentBusyId(agent.agentId);
try {
const res = await spriteAgentAction({
serverId: agent.serverId,
agentId: agent.agentId,
action,
});
if (!res.ok) {
toast.error(res.error ?? `Failed to ${action} agent`);
return;
}
toast.show(action === "interrupt" ? "Interrupted agent turn" : "Archived agent", {
variant: "info",
});
await refresh();
} catch (error) {
toast.error(error instanceof Error ? error.message : String(error));
} finally {
setAgentBusyId(null);
}
};
const handleArchiveLegacyAgent = async (agentId: string) => {
setAgentBusyId(agentId);
try {
await paseo.agents.ref(agentId).archive();
toast.show("Archived legacy cluster agent", { variant: "info" });
setLegacyAgents((prev) => prev.filter((a) => a.id !== agentId));
} catch (error) {
toast.error(error instanceof Error ? error.message : String(error));
} finally {
setAgentBusyId(null);
}
};
const handleSyncSprite = async (name: string) => {
const localPath = cwdInput.trim();
if (!localPath) {
toast.error("Select a workspace or enter a local folder path to sync.");
return;
}
setBusy(true);
try {
const res = await syncWorkspace({ spriteName: name, localPath });
if (!res.ok) {
toast.error(res.error);
return;
}
toast.show(`Synced ${res.fileCount} files to ${name}:${res.remoteDir}`, { variant: "success" });
} catch (error) {
toast.error(error instanceof Error ? error.message : String(error));
} finally {
setBusy(false);
}
};
const handleCheckpoint = async (name: string) => {
setBusy(true);
try {
const res = await createCheckpoint({
spriteName: name,
comment: `paseo-${new Date().toISOString()}`,
});
if (!res.ok) {
toast.error(res.error);
return;
}
toast.show(`Checkpointed ${name}`, { variant: "success" });
await handleLoadCheckpoints(name);
} catch (error) {
toast.error(error instanceof Error ? error.message : String(error));
} finally {
setBusy(false);
}
};
const handleLoadCheckpoints = async (name: string) => {
setCheckpointsSprite(name);
try {
const res = await listCheckpoints({ spriteName: name });
if (!res.ok) {
toast.error(res.error);
return;
}
setCheckpoints(res.checkpoints);
} catch (error) {
toast.error(error instanceof Error ? error.message : String(error));
}
};
const handleRestoreCheckpoint = async (name: string, checkpointId: string) => {
setBusy(true);
try {
const res = await restoreCheckpoint({ spriteName: name, checkpointId });
if (!res.ok) {
toast.error(res.error);
return;
}
toast.show(`Restored ${name} to ${checkpointId}`, { variant: "success" });
} catch (error) {
toast.error(error instanceof Error ? error.message : String(error));
} finally {
setBusy(false);
}
};
const handleDestroySprite = async (name: string) => {
setBusy(true);
try {
const res = await destroySprite({ spriteName: name });
if (!res.ok) {
toast.error(res.error ?? "Failed to delete sprite");
return;
}
toast.show(`Deleted sprite ${name}`, { variant: "info" });
if (checkpointsSprite === name) {
setCheckpointsSprite(null);
setCheckpoints([]);
}
await refresh();
} catch (error) {
toast.error(error instanceof Error ? error.message : String(error));
} finally {
setBusy(false);
}
};
const styles = useMemo(
() => ({
screen: { flex: 1, backgroundColor: theme.colors.surface0 },
body: { padding: layout.compact ? 16 : 24, gap: 14 },
headerRow: {
flexDirection: "row" as const,
justifyContent: "space-between" as const,
alignItems: "center" as const,
gap: 8,
},
title: { color: theme.colors.foreground, fontSize: 18, fontWeight: "600" as const },
sectionTitle: { color: theme.colors.foreground, fontSize: 15, fontWeight: "600" as const, marginTop: 6 },
muted: { color: theme.colors.foregroundMuted, fontSize: 12 },
error: { color: theme.colors.statusDanger, fontSize: 12 },
card: {
borderWidth: 1,
borderColor: theme.colors.border,
backgroundColor: theme.colors.surface1,
borderRadius: 10,
padding: 12,
gap: 8,
},
input: {
borderWidth: 1,
borderColor: theme.colors.border,
backgroundColor: theme.colors.surface0,
color: theme.colors.foreground,
borderRadius: 8,
paddingHorizontal: 10,
paddingVertical: 8,
fontSize: 13,
},
row: { flexDirection: "row" as const, flexWrap: "wrap" as const, gap: 8, alignItems: "center" as const },
btnPrimary: {
backgroundColor: theme.colors.accent,
borderRadius: 8,
paddingHorizontal: 12,
paddingVertical: 8,
},
btnPrimaryText: { color: theme.colors.accentForeground, fontSize: 12, fontWeight: "600" as const },
btnSecondary: {
borderWidth: 1,
borderColor: theme.colors.border,
backgroundColor: theme.colors.surface2,
borderRadius: 8,
paddingHorizontal: 10,
paddingVertical: 6,
},
btnSecondaryText: { color: theme.colors.foreground, fontSize: 12, fontWeight: "500" as const },
btnDanger: {
borderWidth: 1,
borderColor: theme.colors.statusDanger,
borderRadius: 8,
paddingHorizontal: 10,
paddingVertical: 6,
},
btnDangerText: { color: theme.colors.statusDanger, fontSize: 12, fontWeight: "500" as const },
chip: {
borderWidth: 1,
borderColor: theme.colors.border,
backgroundColor: theme.colors.surface0,
borderRadius: 999,
paddingHorizontal: 10,
paddingVertical: 4,
},
chipActive: {
borderWidth: 1,
borderColor: theme.colors.accent,
backgroundColor: theme.colors.surface2,
borderRadius: 999,
paddingHorizontal: 10,
paddingVertical: 4,
},
chipText: { color: theme.colors.foregroundMuted, fontSize: 12 },
chipActiveText: { color: theme.colors.foreground, fontSize: 12, fontWeight: "600" as const },
monoBox: {
backgroundColor: theme.colors.surface0,
borderWidth: 1,
borderColor: theme.colors.border,
borderRadius: 8,
padding: 10,
},
}),
[theme, layout.compact],
);
const statusColor = (status: string) => {
if (status === "running" || status === "initializing" || status === "connecting") {
return theme.colors.accent;
}
if (status === "error" || status === "offline") return theme.colors.statusDanger;
if (status === "idle" || status === "online") return theme.colors.statusSuccess;
return theme.colors.foregroundMuted;
};
return (
<ScrollView style={styles.screen} contentContainerStyle={styles.body}>
<View style={styles.headerRow}>
<View>
<Text style={styles.title}>Fly Sprites Agents</Text>
<Text style={styles.muted}>
Host: {host.label} · Token: {tokenSource}
{workspaceName ? ` · Workspace: ${workspaceName}` : ""}
</Text>
</View>
<Pressable style={styles.btnSecondary} onPress={() => void refresh()} disabled={loading}>
<Text style={styles.btnSecondaryText}>{loading ? "Refreshing…" : "Refresh"}</Text>
</Pressable>
</View>
{!configured ? (
<View style={styles.card}>
<Text style={styles.error}>
No Fly Sprites API token loaded. Sign in with Zitadel to pull FLY_TOKEN from OpenBao, or configure a token in Settings → Fly Sprites Workers.
</Text>
{openbao.status?.lastError ? (
<Text style={styles.error}>OpenBao: {openbao.status.lastError}</Text>
) : null}
{pendingFlow ? (
<View style={{ gap: 6 }}>
<Text style={styles.muted}>
Waiting for Zitadel approval · Code: {pendingFlow.userCode}
</Text>
<View style={styles.row}>
<Pressable
style={styles.btnPrimary}
onPress={() =>
void openExternalUrl(
pendingFlow.verificationUriComplete || pendingFlow.verificationUri,
)
}
>
<Text style={styles.btnPrimaryText}>Open Zitadel Login</Text>
</Pressable>
<Pressable
style={styles.btnSecondary}
onPress={() => void copyText(pendingFlow.userCode)}
>
<Text style={styles.btnSecondaryText}>Copy Code</Text>
</Pressable>
</View>
</View>
) : (
<View style={styles.row}>
<Pressable
style={styles.btnPrimary}
onPress={() => void openbao.startLogin()}
disabled={openbao.busy}
>
<Text style={styles.btnPrimaryText}>
{openbao.busy
? "Starting…"
: openbao.status?.authenticated
? "Re-authenticate Zitadel"
: "Sign in with Zitadel"}
</Text>
</Pressable>
{openbao.status?.authenticated ? (
<Pressable
style={styles.btnSecondary}
onPress={() => void openbao.pullNow()}
disabled={openbao.busy}
>
<Text style={styles.btnSecondaryText}>Pull from OpenBao</Text>
</Pressable>
) : null}
</View>
)}
</View>
) : null}
{remoteError ? (
<View style={styles.card}>
<Text style={styles.error}>Remote API error: {remoteError}</Text>
</View>
) : null}
<View style={styles.card}>
<Text style={styles.sectionTitle}>Launch Agent on Sprite Host</Text>
<Text style={styles.muted}>
Provisions Paseo inside the Sprite and connects it as its own host so workspaces and agents appear under the Sprite host.
</Text>
<TextInput
style={styles.input}
value={spriteNameInput}
onChangeText={setSpriteNameInput}
placeholder="Target Sprite name (blank creates a new Sprite host)"
placeholderTextColor={theme.colors.foregroundMuted}
/>
<TextInput
style={styles.input}
value={agentTitleInput}
onChangeText={setAgentTitleInput}
placeholder="Agent title (optional)"
placeholderTextColor={theme.colors.foregroundMuted}
/>
<TextInput
style={styles.input}
value={promptInput}
onChangeText={setPromptInput}
placeholder="Initial prompt / task (optional; leave blank for interactive chat)"
placeholderTextColor={theme.colors.foregroundMuted}
multiline
/>
{workspaces.length > 0 && !workspaceDirectory ? (
<View style={styles.row}>
{workspaces.map((ws) => {
const wsPath = getWorkspacePath(ws);
const active = cwdInput === wsPath;
return (
<Pressable
key={ws.id}
style={active ? styles.chipActive : styles.chip}
onPress={() => setCwdInput(wsPath)}
>
<Text style={active ? styles.chipActiveText : styles.chipText}>
{ws.title || ws.name || wsPath}
</Text>
</Pressable>
);
})}
</View>
) : null}
<TextInput
style={styles.input}
value={cwdInput}
onChangeText={setCwdInput}
placeholder="Optional local workspace directory to sync to /workspace"
placeholderTextColor={theme.colors.foregroundMuted}
/>
<View style={styles.row}>
{PROVIDER_CHOICES.map((choice) => {
const active = providerInput === choice.id;
return (
<Pressable
key={choice.id}
style={active ? styles.chipActive : styles.chip}
onPress={() => setProviderInput(choice.id)}
>
<Text style={active ? styles.chipActiveText : styles.chipText}>
{choice.label}
</Text>
</Pressable>
);
})}
<Pressable
style={styles.btnSecondary}
onPress={() => setSyncBeforeOpen((v) => !v)}
>
<Text style={styles.btnSecondaryText}>
{syncBeforeOpen ? "Sync workspace: ON" : "Sync workspace: OFF"}
</Text>
</Pressable>
</View>
<View style={styles.row}>
<Pressable
style={styles.btnSecondary}
onPress={() => void handleCreateSprite()}
disabled={busy || !configured}
>
<Text style={styles.btnSecondaryText}>Create Sprite</Text>
</Pressable>
<Pressable
style={styles.btnSecondary}
onPress={() => void handleConnectHost(spriteNameInput)}
disabled={busy || !configured}
>
<Text style={styles.btnSecondaryText}>Connect Host</Text>
</Pressable>
<Pressable
style={styles.btnPrimary}
onPress={() => void handleLaunchAgent()}
disabled={busy || !configured}
>
<Text style={styles.btnPrimaryText}>
{busy ? "Working…" : "Launch Agent"}
</Text>
</Pressable>
</View>
</View>
<Text style={styles.sectionTitle}>Sprite Host Agents ({spriteAgents.length})</Text>
{spriteAgents.length === 0 ? (
<View style={styles.card}>
<Text style={styles.muted}>
No agents on connected Sprite hosts yet. Launch one above to create it under its Sprite host.
</Text>
</View>
) : (
spriteAgents.map((agent) => {
const isBusy = agentBusyId === agent.agentId;
return (
<View key={`${agent.serverId}:${agent.agentId}`} style={styles.card}>
<View style={styles.headerRow}>
<Text style={{ color: theme.colors.foreground, fontWeight: "600", fontSize: 13, flex: 1 }}>
{agent.title || `Agent ${agent.agentId.slice(0, 8)}`}
</Text>
<Text style={{ color: statusColor(agent.status), fontSize: 12, fontWeight: "600" }}>
{agent.status}
{agent.pendingPermissionsCount > 0 ? " · permission" : ""}
</Text>
</View>
<Text style={styles.muted}>
Host: {agent.hostLabel} · {agent.provider}
{agent.model ? `/${agent.model}` : ""} · {agent.cwd}
</Text>
{agent.lastError ? <Text style={styles.error}>{agent.lastError}</Text> : null}
<View style={styles.row}>
{navigation ? (
<Pressable
style={styles.btnPrimary}
onPress={() =>
navigation.openAgent({ agentId: agent.agentId, serverId: agent.serverId })
}
>
<Text style={styles.btnPrimaryText}>Open</Text>
</Pressable>
) : null}
{agent.status === "running" ? (
<Pressable
style={styles.btnSecondary}
onPress={() => void handleSpriteAgentAction(agent, "interrupt")}
disabled={isBusy}
>
<Text style={styles.btnSecondaryText}>Interrupt</Text>
</Pressable>
) : null}
<Pressable
style={styles.btnDanger}
onPress={() => void handleSpriteAgentAction(agent, "archive")}
disabled={isBusy}
>
<Text style={styles.btnDangerText}>Archive</Text>
</Pressable>
</View>
</View>
);
})
)}
{legacyAgents.length > 0 ? (
<>
<Text style={styles.sectionTitle}>Cluster-Hosted Fly Agents ({legacyAgents.length})</Text>
{legacyAgents.map((agent) => (
<View key={agent.id} style={styles.card}>
<View style={styles.headerRow}>
<Text style={{ color: theme.colors.foreground, fontWeight: "600", fontSize: 13, flex: 1 }}>
{agent.title || `Agent ${agent.id.slice(0, 8)}`}
</Text>
<Text style={{ color: statusColor(agent.status), fontSize: 12, fontWeight: "600" }}>
{agent.status}
</Text>
</View>
<Text style={styles.muted}>
Cluster host ({host.label}) · {agent.cwd}
</Text>
<View style={styles.row}>
{navigation ? (
<Pressable
style={styles.btnSecondary}
onPress={() => navigation.openAgent({ agentId: agent.id, serverId: host.id })}
>
<Text style={styles.btnSecondaryText}>Open</Text>
</Pressable>
) : null}
<Pressable
style={styles.btnDanger}
onPress={() => void handleArchiveLegacyAgent(agent.id)}
disabled={agentBusyId === agent.id}
>
<Text style={styles.btnDangerText}>Archive</Text>
</Pressable>
</View>
</View>
))}
</>
) : null}
<Text style={styles.sectionTitle}>Remote Fly Sprites ({sprites.length})</Text>
{sprites.length === 0 ? (
<View style={styles.card}>
<Text style={styles.muted}>No Fly Sprites found.</Text>
</View>
) : (
sprites.map((sprite) => {
const connectedHost = hostBySprite.get(sprite.name);
return (
<View key={sprite.name} style={styles.card}>
<View style={styles.headerRow}>
<Text style={{ color: theme.colors.foreground, fontWeight: "600", fontSize: 13 }}>
{sprite.name}
</Text>
<Text style={styles.muted}>
VM: {sprite.status}
{connectedHost ? ` · Host: ${connectedHost.status}` : " · Host: not connected"}
</Text>
</View>
{connectedHost?.error ? (
<Text style={styles.error}>Host error: {connectedHost.error}</Text>
) : null}
{sprite.url ? <Text style={styles.muted}>{sprite.url}</Text> : null}
<View style={styles.row}>
<Pressable
style={styles.btnSecondary}
onPress={() => setSpriteNameInput(sprite.name)}
>
<Text style={styles.btnSecondaryText}>Select</Text>
</Pressable>
{!connectedHost || connectedHost.status !== "online" ? (
<Pressable
style={styles.btnSecondary}
onPress={() => void handleConnectHost(sprite.name)}
disabled={busy}
>
<Text style={styles.btnSecondaryText}>Connect Host</Text>
</Pressable>
) : null}
<Pressable
style={styles.btnSecondary}
onPress={() => void handleSyncSprite(sprite.name)}
disabled={busy}
>
<Text style={styles.btnSecondaryText}>Sync Here</Text>
</Pressable>
<Pressable
style={styles.btnSecondary}
onPress={() => void handleCheckpoint(sprite.name)}
disabled={busy}
>
<Text style={styles.btnSecondaryText}>Checkpoint</Text>
</Pressable>
<Pressable
style={styles.btnSecondary}
onPress={() => void handleLoadCheckpoints(sprite.name)}
>
<Text style={styles.btnSecondaryText}>Checkpoints</Text>
</Pressable>
<Pressable
style={styles.btnDanger}
onPress={() => void handleDestroySprite(sprite.name)}
disabled={busy}
>
<Text style={styles.btnDangerText}>Delete</Text>
</Pressable>
</View>
{checkpointsSprite === sprite.name ? (
<View style={styles.monoBox}>
<Text style={[styles.muted, { marginBottom: 4 }]}>
Checkpoints for {sprite.name} ({checkpoints.length})
</Text>
{checkpoints.length === 0 ? (
<Text style={styles.muted}>No checkpoints.</Text>
) : (
checkpoints.map((cp) => (
<View key={cp.id} style={[styles.headerRow, { paddingVertical: 4 }]}>
<Text style={styles.muted}>
{cp.id} {cp.comment ? `— ${cp.comment}` : ""}
</Text>
<Pressable
style={styles.btnSecondary}
onPress={() => void handleRestoreCheckpoint(sprite.name, cp.id)}
disabled={busy}
>
<Text style={styles.btnSecondaryText}>Restore</Text>
</Pressable>
</View>
))
)}
</View>
) : null}
</View>
);
})
)}
</ScrollView>
);
}