import { useState } from 'react' import { Link, useNavigate, useParams } from 'react-router' import { useDataProvider, useList, useOne } from '@refinedev/core' import { Alert, Button, Card, CardContent, DetailList, Field, PageHeader, PageState, Select, StatusPill, } from './lib/ui.jsx' import { useTitle } from './lib/hooks.js' const stateTone = { queued: 'neutral', executing: 'info', succeeded: 'success', failed: 'danger', needs_confirmation: 'warning', policy_hold: 'warning', cancelled: 'neutral' } const stateText = { queued: '已排队', executing: '执行中', succeeded: '已成功', failed: '失败', needs_confirmation: '需要人工确认', policy_hold: '策略暂停', cancelled: '已取消' } const holdText = { account_paused: '账号已暂停', account_revoked: '账号授权已撤销', binding_missing: '运行环境绑定缺失', environment_missing: '原运行环境不可用', exit_missing: '固定出口缺失', exit_unhealthy: '固定出口失败或发生漂移', runtime_stop_pending: '停止结果未知,等待人工核验', runtime_missing: '原运行实例不可用', runtime_lease_expired: '运行实例租约已过期', execution_lease_expired: '执行租约过期,结果未知', task_result_uncertain: '执行结果不确定', task_policy_hold: '执行器请求策略暂停', account_version_changed: '账号版本已变化', draft_version_changed: '草稿版本已变化', confirmation_missing: '确认快照缺失', confirmation_version_changed: '确认版本已变化', binding_version_changed: '环境或出口版本已变化', legacy_confirmation_required: '历史任务结果未知,等待人工核验', } const stateLabel = state => stateText[state] || `未知状态:${state}` const holdLabel = reason => reason ? holdText[reason] || `未知停止原因:${reason}` : '无' function actionErrorText(error) { const reason = error?.body?.reason_code if (error?.status === 409) return `当前版本仍不允许恢复(409):${holdLabel(reason)}` if (error?.status === 503) return `原资源尚未恢复(503):${holdLabel(reason)}` return error?.message || '操作失败' } function TaskCard({ task }) { return (
{task.id}
账号:{task.account_id}
确认:{task.confirmation_id || '未确认'}
{holdLabel(task.hold_reason)}

{new Date(task.updated_at || task.created_at).toLocaleString('zh-CN')}

) } export function TaskList() { const [accountFilter, setAccountFilter] = useState('') const [stateFilter, setStateFilter] = useState('') const { result, query } = useList({ resource: 'tasks', filters: [ { field: 'account_id', value: accountFilter }, { field: 'state', value: stateFilter }, ], }) const error = query.error const isPending = query.isPending const tasks = result.data ?? [] useTitle('CreatorHub · 任务中心') return (
setAccountFilter(event.target.value)} placeholder="账号 ID" className="h-9 w-full rounded-md border border-[#c4ccd9] bg-white px-3 text-sm focus:border-primary focus:outline-none" /> setVerification(event.target.value)} options={[ { value: 'not_executed', label: '确认未执行,可评估恢复' }, { value: 'succeeded', label: '确认已成功' }, { value: 'failed', label: '确认已失败' }, ]} /> ) : null} {task.allowed_action === 'resume' ? : null} {task.allowed_action === 'finish' ? : null} {task.allowed_action === 'reconfirm' ? ( <> 版本已变化,旧确认不可继续使用。 ) : null} {task.allowed_action ? null :

当前没有可安全执行的动作。

}

执行尝试

{task.attempts?.length ? (
{task.attempts.map(attempt => ( {attempt.id}

{attempt.outcome || '执行中'} · {new Date(attempt.started_at).toLocaleString('zh-CN')}

脱敏证据:{attempt.evidence?.mock_outcome || '无可公开证据'}

))}
) : (

尚未产生执行尝试。

)}
) }