{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "elements-job-progress",
  "type": "registry:component",
  "title": "Long job",
  "description": "Work measured in minutes: weighted stages, an ETA, and a way out.",
  "registryDependencies": [
    "https://r.assistant-ui.com/elements-surfaces.json",
    "https://r.assistant-ui.com/elements-range.json"
  ],
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "type": "registry:component",
      "path": "components/assistant-ui/elements/job-progress.tsx",
      "sourcePath": "packages/ui/src/components/react/assistant-ui/elements/job-progress.tsx",
      "content": "\"use client\";\n\nimport type { ComponentProps } from \"react\";\nimport {\n  CheckIcon,\n  CircleAlertIcon,\n  CircleSlashIcon,\n  Loader2Icon,\n  XIcon,\n} from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\nimport { ghostButton, mono, paper } from \"./surfaces\";\nimport { announced, clamp, pct, progressOf, take } from \"../utils/range\";\n\nexport interface JobStage {\n  name: string;\n  weight: number;\n  description?: string | undefined;\n}\n\ntype JobOutcomeStatus = \"success\" | \"partial\" | \"failed\" | \"cancelled\";\n\nfunction formatElapsed(elapsedMs: number) {\n  const seconds = Math.max(\n    0,\n    Math.round(Number.isFinite(elapsedMs) ? elapsedMs / 1_000 : 0),\n  );\n  const minutes = Math.floor(seconds / 60);\n  const remainder = seconds % 60;\n\n  return {\n    dateTime: `PT${seconds}S`,\n    label:\n      minutes === 0\n        ? `${seconds}s`\n        : remainder === 0\n          ? `${minutes}m`\n          : `${minutes}m ${remainder}s`,\n  };\n}\n\nexport function JobProgress({\n  title,\n  stages,\n  stageIndex,\n  stageProgress,\n  eta,\n  onCancel,\n  outcome,\n  elapsedMs,\n  className,\n  ...props\n}: Omit<\n  ComponentProps<\"div\">,\n  | \"children\"\n  | \"title\"\n  | \"stages\"\n  | \"stageIndex\"\n  | \"stageProgress\"\n  | \"eta\"\n  | \"onCancel\"\n  | \"outcome\"\n  | \"elapsedMs\"\n> & {\n  title: string;\n  stages: readonly JobStage[];\n  stageIndex: number;\n  stageProgress: number;\n  eta: string;\n  onCancel?: (() => void) | undefined;\n  outcome?:\n    | {\n        status: JobOutcomeStatus;\n        summary?: string | undefined;\n      }\n    | undefined;\n  elapsedMs?: number | undefined;\n}) {\n  const stage = progressOf(stageIndex, stages.length);\n  const progress = clamp(stageProgress, 0, 1);\n  const totalWeight = stages.reduce((sum, item) => sum + item.weight, 0) || 1;\n  const completed = take(stages, stage).reduce(\n    (sum, item) => sum + item.weight,\n    0,\n  );\n  const current = stages[stage];\n  const overall = pct(\n    completed + (current ? current.weight * progress : 0),\n    totalWeight,\n  );\n  const finished = stage >= stages.length;\n  const running = !finished && outcome === undefined;\n  const state = outcome?.status ?? (finished ? \"done\" : \"running\");\n  const elapsed =\n    !running && elapsedMs !== undefined ? formatElapsed(elapsedMs) : undefined;\n  const statusWord =\n    outcome?.status === \"success\" ? \"done\" : (outcome?.status ?? \"done\");\n  const announcement = outcome\n    ? `Job ${outcome.status === \"success\" ? \"done\" : outcome.status === \"partial\" ? \"partly done\" : outcome.status}`\n    : current\n      ? `Current stage: ${current.name}`\n      : finished\n        ? \"Job done\"\n        : \"Job running\";\n  const outcomeBar =\n    outcome?.status === \"success\"\n      ? \"bg-emerald-500\"\n      : outcome?.status === \"partial\"\n        ? \"bg-amber-500 dark:bg-amber-400\"\n        : outcome?.status === \"failed\"\n          ? \"bg-red-600 dark:bg-red-400\"\n          : outcome?.status === \"cancelled\"\n            ? \"bg-foreground/20\"\n            : undefined;\n  const progressPercent = outcome?.status === \"success\" ? 100 : overall;\n\n  return (\n    <div\n      data-slot=\"job-progress\"\n      data-state={state}\n      className={cn(\n        paper,\n        \"flex w-full max-w-sm flex-col gap-3 rounded-2xl p-4\",\n        className,\n      )}\n      {...props}\n    >\n      <div className=\"flex items-center gap-2.5\">\n        {outcome?.status === \"partial\" ? (\n          <CircleAlertIcon className=\"size-3.5 shrink-0 text-amber-500 dark:text-amber-400\" />\n        ) : outcome?.status === \"failed\" ? (\n          <XIcon className=\"size-3.5 shrink-0 text-red-600 dark:text-red-400\" />\n        ) : outcome?.status === \"cancelled\" ? (\n          <CircleSlashIcon className=\"text-muted-foreground size-3.5 shrink-0\" />\n        ) : !running ? (\n          <CheckIcon className=\"size-3.5 shrink-0 text-emerald-500\" />\n        ) : (\n          <Loader2Icon className=\"text-muted-foreground size-3.5 shrink-0 animate-spin motion-reduce:animate-none\" />\n        )}\n        <span className=\"min-w-0 flex-1 truncate text-[13.5px] font-medium\">\n          {title}\n        </span>\n        <span\n          className={cn(mono, \"text-muted-foreground shrink-0 tabular-nums\")}\n        >\n          {elapsed ? (\n            <time dateTime={elapsed.dateTime}>{elapsed.label}</time>\n          ) : !running ? (\n            statusWord\n          ) : (\n            eta\n          )}\n        </span>\n        {running && onCancel ? (\n          <button\n            type=\"button\"\n            aria-label=\"Cancel the job\"\n            onClick={onCancel}\n            className={cn(ghostButton, \"size-6 shrink-0\")}\n          >\n            <XIcon className=\"size-3.5\" />\n          </button>\n        ) : null}\n      </div>\n\n      <span\n        role=\"progressbar\"\n        aria-label={`${title} progress`}\n        aria-valuemin={0}\n        aria-valuemax={100}\n        aria-valuenow={announced(progressPercent)}\n        className=\"bg-foreground/[0.06] inset-ring-border h-1 w-full overflow-hidden rounded-full inset-ring forced-colors:border\"\n      >\n        <span\n          className={cn(\n            \"block h-full rounded-full transition-[width] duration-500 ease-out forced-color-adjust-none motion-reduce:transition-none\",\n            outcomeBar ??\n              (finished ? \"bg-emerald-500\" : \"bg-blue-500 dark:bg-blue-400\"),\n          )}\n          style={{ width: `${progressPercent}%` }}\n        />\n      </span>\n\n      <div className=\"flex flex-col gap-0.5\">\n        <div className=\"flex flex-wrap gap-x-3 gap-y-1\">\n          {stages.map((item, i) => (\n            <span\n              key={item.name}\n              className={cn(\n                mono,\n                i === stage ? \"text-foreground/90\" : \"text-muted-foreground\",\n              )}\n            >\n              {item.name}\n            </span>\n          ))}\n        </div>\n        {current?.description ? (\n          <p className=\"text-muted-foreground text-xs leading-4 break-words\">\n            {current.description}\n          </p>\n        ) : null}\n      </div>\n      {outcome?.summary ? (\n        <p className=\"text-foreground/60 text-[13px] leading-snug break-words\">\n          {outcome.summary}\n        </p>\n      ) : null}\n      <span className=\"sr-only\" role=\"status\">\n        {announcement}\n      </span>\n    </div>\n  );\n}\n"
    }
  ]
}