import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { cloudAgentsApi } from '@/lib/cloud-agents-api'; import type { CloudPendingOperation } from '../../../shared/cloud-agents'; const labels: Record = { createAgent: '创建智能体', submit: '发送消息', preview: '预览草稿', resume: '继续任务', publish: '发布版本', createApplication: '创建应用', createKey: '创建密钥', createKnowledge: '创建知识库', processKnowledge: '处理文档', createSchedule: '创建自动任务', runSchedule: '立即运行任务', importKnowledgeAttachment: '导入附件到知识库', createChild: '创建子智能体', wechatBindVerification: '微信连接验证', channelAccountWechatBindVerification: '微信连接验证', createChannelAccount: '添加微信账号', routeChannelAccount: '切换目标智能体', enableChannelAccount: '启用渠道', pauseChannelAccount: '暂停渠道', disconnectChannelAccount: '断开微信账号', channelAccountWechatBindStart: '微信扫码连接', channelAccountWechatUnbind: '解除微信登录', }; export function CloudRecovery({ pending, onResolved }: { pending: CloudPendingOperation[]; onResolved: () => void }) { const [busy, setBusy] = useState(''); const [error, setError] = useState(''); const [notice, setNotice] = useState(''); const [result, setResult] = useState<{ operation: string; value: unknown } | null>(null); const resolve = async (item: CloudPendingOperation, discard = false) => { setBusy(item.id); setError(''); setNotice(''); try { const response = await cloudAgentsApi.resolvePending(item.id, discard); if (response.requires_input) { setResult(null); setNotice('这次微信验证还需要验证码。请进入「渠道 → 微信」,选择对应账号后继续连接验证。'); } else if (!discard) setResult({ operation: item.operation, value: response.result }); onResolved(); } catch (e) { setError(e instanceof Error ? e.message : '暂时无法确认结果'); } finally { setBusy(''); } }; if (!pending.length && !result && !error && !notice) return null; return ; }