Ordo UI
AI助手与对话

AssistantRunLine

@mox-hub/patterns · AI · 助手与对话 · canonical

assistant-run-line@mox-hub/patternsAI Executioncanonicalsrc/components/assistant-run-line.tsx
变体演示assistant-run-line

执行完成

把登录页拆成三项验收标准

执行失败

部署 staging

CLI 进程退出码 1

Props API

Prop类型默认值说明
entry*AssistantRunEntryView——
status*string——
error*string——
retrying*booleanfalse—
onViewDetail*() => void——
onOpenExecutions*() => void——
onRetry*() => void——
labels*Partial<AssistantRunLineLabels>——

源码

packages/patterns/src/components/assistant-run-line.tsx
/**
 * 执行行卡片 —— 「转执行」后的运行条目展示壳。
 *
 * 库内只负责状态渲染与动作槽;轮询、事件失效、重试 mutation、运行详情弹窗与
 * 执行中心跳转全部由消费方注入。
 */
import { Bot, CheckCircle2, ExternalLink, FileText, RotateCcw, XCircle } from 'lucide-react'
import { cn } from '@mox-hub/ui'
import { Button } from '@mox-hub/ui/components/button'
import { Spinner } from '@mox-hub/ui/components/spinner'
import { usePatternLabels } from '../lib/i18n'

const TERMINAL_STATUSES = ['completed', 'failed', 'blocked', 'superseded', 'cancelled']

/** 运行条目最小形状(与 ordo AssistantRunEntry 结构兼容)。 */
export interface AssistantRunEntryView {
  runId: string
  content: string
}

/** 组件内文案缺省(中文常量;消费方经 labels 覆写接入 i18n)。 */
export interface AssistantRunLineLabels {
  running: string
  failed: string
  completed: string
  retry: string
  viewDetail: string
  openExecutions: string
}

export const ASSISTANT_RUN_LINE_DEFAULT_LABELS: AssistantRunLineLabels = {
  running: '正在执行',
  failed: '执行失败',
  completed: '执行完成',
  retry: '重试',
  viewDetail: '运行详情',
  openExecutions: '前往执行中心',
}

export interface AssistantRunLineProps {
  entry: AssistantRunEntryView
  /** 服务端运行状态;undefined = 尚未取到 */
  status?: string
  /** 失败原因(终态输出) */
  error?: string | null
  /** 重试进行中 */
  retrying?: boolean
  onViewDetail: () => void
  onOpenExecutions: () => void
  /** 传了才渲染重试键 */
  onRetry?: () => void
  /** 文案覆写(默认 zh-CN;主仓 i18n 适配层集中传入 t() 结果)。 */
  labels?: Partial<AssistantRunLineLabels>
}

export function AssistantRunLine({
  entry,
  status,
  error,
  retrying = false,
  onViewDetail,
  onOpenExecutions,
  onRetry,
  labels,
}: AssistantRunLineProps) {
  const D = usePatternLabels(
    'assistantRunLine',
    ASSISTANT_RUN_LINE_DEFAULT_LABELS,
  )
  const text = {
    running: labels?.running ?? D.running,
    failed: labels?.failed ?? D.failed,
    completed: labels?.completed ?? D.completed,
    retry: labels?.retry ?? D.retry,
    viewDetail: labels?.viewDetail ?? D.viewDetail,
    openExecutions:
      labels?.openExecutions ?? D.openExecutions,
  }
  const isTerminal = !!status && TERMINAL_STATUSES.includes(status)
  const isFailed = status === 'failed' || status === 'blocked' || status === 'cancelled'

  return (
    <div className="flex items-start gap-2" data-ai-component="assistant.run-line">
      <span className="flex size-6 shrink-0 items-center justify-center rounded-lg bg-accent-purple-light text-accent-purple">
        <Bot className="size-3.5" />
      </span>
      <div
        className={cn(
          'max-w-4/5 flex-1 rounded-lg border px-3 py-2 text-xs',
          isFailed
            ? 'border-accent-red/30 bg-accent-red-light/60 text-accent-red'
            : isTerminal
              ? 'border-accent-green/30 bg-accent-green-light/60 text-content-text'
              : 'border-border bg-content-bg-secondary/60 text-content-text-secondary',
        )}
      >
        <p className="flex items-center gap-1.5 font-medium">
          {!isTerminal ? (
            <Spinner size="sm" className="size-3 text-accent-blue" />
          ) : isFailed ? (
            <XCircle className="size-3" />
          ) : (
            <CheckCircle2 className="size-3 text-accent-green" />
          )}
          {!isTerminal ? text.running : isFailed ? text.failed : text.completed}
        </p>
        <p className="mt-0.5 line-clamp-2 text-2xs text-content-text-muted">{entry.content}</p>
        {isFailed && error ? (
          <p className="mt-0.5 break-words text-2xs">{error}</p>
        ) : null}
        {/* 卡片操作区统一右对齐:按钮不再用 hover 下划线(与 hover 底色重复),
            下划线只属于纯文本链接。 */}
        <div className="mt-1 flex items-center justify-end gap-1">
          <Button
            type="button"
            variant="ghost"
            tone="info"
            onClick={onViewDetail}
            className="h-5 gap-1 px-1 text-2xs"
          >
            <FileText className="size-3" />
            {text.viewDetail}
          </Button>
          <Button
            type="button"
            variant="ghost"
            onClick={onOpenExecutions}
            className="h-5 gap-1 px-1 text-2xs text-content-text-muted"
          >
            <ExternalLink className="size-3" />
            {text.openExecutions}
          </Button>
          {isFailed && onRetry ? (
            <Button
              type="button"
              variant="ghost"
              disabled={retrying}
              onClick={onRetry}
              className="h-5 gap-1 px-1 text-2xs"
            >
              {retrying ? <Spinner size="sm" className="size-3" /> : <RotateCcw className="size-3" />}
              {text.retry}
            </Button>
          ) : null}
        </div>
      </div>
    </div>
  )
}

可访问性与 RTL

  • 键盘:交互件保留:focus-visible焦点环;浮层支持 Escape 关闭与焦点归还,菜单 / 页签按 Base UI 约定支持方向键。 筛选菜单、拖拽排序、执行树与模型 listbox 等关键键盘流由 Playwright 断言覆盖,见规范示例 · 交互与可访问性。
  • RTL:间距、对齐与方向性图标使用逻辑属性 (ms-* /text-start /rtl:-scale-x-100);通过 ThemeProvider 或I18nProvider 的direction="rtl"驱动,`lint:rtl` 会拦截新增物理类。
  • 文案:优先用组件labels /translate /translator props,其次用I18nProvider目录;内置 zh-CN 默认值,en-US 为参考翻译。见Theming · i18n 与 RTL。
  • 对比度:高对比度 token、2px 控件边框与 3px 焦点环由主题层统一提供,见Foundations · Contrast。

用法说明

执行行卡片:运行/完成/失败三态 + 内容摘要 + 错误 + 运行详情/执行中心/重试动作;数据与 callbacks 全部注入。