Repository Public
1import type { SessionState, TaskState } from '@cr/shared';2import type { Tone } from '@/components/ui/badge';3import type { Brand } from '@/lib/branding';45const RECOVERABLE_TEMPLATE = 'The host restarted; the process is gone. Restart resumes the {short} conversation, not the process.';67export const SESSION_STATE: Record<SessionState, { label: string; tone: Tone; pulse?: boolean; hint: string }> = {8 CREATED: { label: 'Created', tone: 'muted', hint: 'Registered, not started yet.' },9 STARTING: { label: 'Starting', tone: 'accent', pulse: true, hint: 'The process is being started.' },10 RUNNING: { label: 'Running', tone: 'success', hint: 'The process is running with a client attached.' },11 DETACHED: { label: 'Detached', tone: 'neutral', hint: 'Running on the server; no browser is attached.' },12 WAITING_FOR_INPUT: { label: 'Needs you', tone: 'coral', pulse: true, hint: '{agentName} signalled that it needs your attention.' },13 STOPPING: { label: 'Stopping', tone: 'muted', pulse: true, hint: 'The process is being stopped.' },14 STOPPED: { label: 'Stopped', tone: 'muted', hint: 'The process has ended.' },15 FAILED: { label: 'Failed', tone: 'error', hint: 'The process could not be started or crashed.' },16 RECOVERABLE: { label: 'Recoverable', tone: 'warning', hint: RECOVERABLE_TEMPLATE },17};18const fill = (template: string, brand: Brand): string => template.replaceAll('{agentName}', brand.agentName).replaceAll('{short}', brand.short);19/** Tooltip text of a session state, worded for the instance's agent (`hint` holds {agentName}/{short} placeholders). */20export const sessionStateHint = (state: SessionState, brand: Brand): string => fill(SESSION_STATE[state].hint, brand);21export const recoverableExplanation = (brand: Brand): string => fill(RECOVERABLE_TEMPLATE, brand);2223export const TASK_STATE: Record<TaskState, { label: string; tone: Tone; pulse?: boolean }> = {24 QUEUED: { label: 'Queued', tone: 'neutral' },25 RUNNING: { label: 'Running', tone: 'accent', pulse: true },26 SUCCEEDED: { label: 'Succeeded', tone: 'success' },27 FAILED: { label: 'Failed', tone: 'error' },28 CANCELLING: { label: 'Cancelling', tone: 'warning', pulse: true },29 CANCELLED: { label: 'Cancelled', tone: 'muted' },30 TIMED_OUT: { label: 'Timed out', tone: 'error' },31 LOST: { label: 'Lost', tone: 'warning' },32};33export const TASK_ACTIVE: readonly TaskState[] = ['QUEUED', 'RUNNING', 'CANCELLING'];34