import * as Haptics from "expo-haptics"; import { SymbolView } from "expo-symbols"; import { deriveThreadQueueWorkflowState } from "@t3tools/client-runtime/state/thread-workflows"; import type { EnvironmentId, RunId, ThreadId } from "@t3tools/contracts"; import { useMemo, useState } from "react"; import { Pressable, ScrollView, View } from "react-native"; import { AppText as Text } from "../../components/AppText"; import { useThemeColor } from "../../lib/useThemeColor"; import { threadEnvironment } from "../../state/threads"; import { useAtomCommand } from "../../state/use-atom-command"; import { useThreadProjection } from "../../state/use-thread-detail"; export function ThreadQueueControl(props: { readonly environmentId: EnvironmentId; readonly threadId: ThreadId; }) { const scoped = useThreadProjection(props); const workflow = useMemo( () => (scoped ? deriveThreadQueueWorkflowState(scoped.projection) : null), [scoped], ); const reorder = useAtomCommand(threadEnvironment.reorderQueuedRun, "reorder queued message"); const promote = useAtomCommand(threadEnvironment.promoteQueuedRun, "promote queued message"); const [busyRunId, setBusyRunId] = useState(null); const iconColor = useThemeColor("--color-icon-subtle"); if (!workflow || workflow.queuedRuns.length === 0) return null; const move = async (runId: RunId, beforeRunId: RunId | null) => { setBusyRunId(runId); void Haptics.selectionAsync(); await reorder({ environmentId: props.environmentId, input: { threadId: props.threadId, runId, beforeRunId }, }); setBusyRunId(null); }; const steer = async (queuedRunId: RunId) => { if (!workflow.activeRun || !workflow.canPromoteToSteer) return; setBusyRunId(queuedRunId); void Haptics.selectionAsync(); await promote({ environmentId: props.environmentId, input: { threadId: props.threadId, queuedRunId, targetRunId: workflow.activeRun.id, }, }); setBusyRunId(null); }; return ( Queue {workflow.queuedRuns.length} {workflow.queuedRuns.map(({ run, text }, index) => ( {index + 1} {text} void move(run.id, workflow.queuedRuns[index - 1]?.run.id ?? null)} className="h-9 w-9 items-center justify-center disabled:opacity-30" > void move(run.id, workflow.queuedRuns[index + 2]?.run.id ?? null)} className="h-9 w-9 items-center justify-center disabled:opacity-30" > void steer(run.id)} className="min-h-8 flex-row items-center gap-1 rounded-lg border border-neutral-300/60 px-2 disabled:opacity-30 dark:border-white/[0.1]" > Steer ))} ); }