import { Check, CircuitBoard, Loader2 } from 'lucide-react' import { useRef, useState } from 'react' import { api } from '../lib/api' import { useTaskEvents } from '../hooks/useTaskEvents' import type { AgentTask } from '../hooks/useTaskEvents' import type { ResearchReport } from '../lib/day3' import { toolNames } from '../lib/day3' import { inputClass, message } from '../lib/day2' import { GhostButton, PrimaryButton } from './ui-ext/AiButton' const labels: Record = { fullname: '企业全称', name: '名称', title: '标题', province: '省份', city: '城市', county: '区县', industry: '行业', capital: '注册资本', size: '企业规模', business_status: '经营状态', establishment_date: '成立日期', business_scope: '经营范围', caller_count: '招标次数', winner_count: '中标次数', company_name: '企业', company_id: '主体编号', cooperation_count: '合作次数', cooperation_amount: '合作金额(元)', cooperation_amount_wan: '合作金额(万元)', last_cooperation_time: '最近合作时间', products: '合作品类', keywords: '业务词', partners: '合作伙伴', items: '公告记录', total: '平台总数', bid_id: '公告编号', pub_time: '发布时间', money: '金额(元)', money_wan: '金额(万元)', caller_name: '采购方', winner_names: '中标方', sm_names: '标的物', fulltext: '正文', competitors: '竞争者', co_bid_count: '共同投标次数', top_co_bid_products: '交锋品类', top_co_bid_callers: '共同客户', top_co_bid_provinces: '交锋区域', keyword: '关键词', count: '次数', amount: '金额(元)', buckets: '聚合结果', key: '分组', sum_amount: '金额合计(元)', total_count: '记录总数', total_amount: '金额合计(元)', content: '正文', results: '公开资料', snippet: '摘录', url: '原始来源', filename: '文件名', segments: '定位段落', locator: '位置', text: '正文', needsVision: '需视觉识别', price_stats: '价格统计', bidders: '潜在投标者', service_end_date: '服务截止时间', agency_name: '代理机构' } function sectionTitle(section: ResearchReport['sections'][number]) { if (section.key.endsWith(':customers')) return '历史客户' if (section.key.endsWith(':suppliers')) return '历史供应商' if (section.key.includes(':light:')) return `Top 竞对 ${Number(section.key.split(':').at(-1)) + 1} 基础画像` return toolNames[section.tool] ?? section.tool } /** React 仅渲染文字节点,不解析供应商 HTML;外链再次限制 HTTP(S),保留签名参数。 */ function Facts({ value }: { value: unknown }) { if (value == null || value === '') return 未提供 if (typeof value === 'string') return /^https?:\/\//i.test(value) ? 查看原始来源 : {value} if (typeof value === 'boolean') return {value ? '是' : '否'} if (typeof value === 'number') return {String(value)} if (Array.isArray(value)) return value.length ? : 本次未查到记录 return
{Object.entries(value).map(([key, item]) =>
{labels[key] ?? key}
)}
} /** 四个调研入口共用真实 SSE、确认、取消、报告与费用组件,页面刷新只读取任务。 */ export function ResearchTask({ id, onTask }: { id: string; onTask?: (task: AgentTask) => void }) { const [revision, setRevision] = useState(0) const { task, error: streamError } = useTaskEvents(id, revision) const [busy, setBusy] = useState(false), [error, setError] = useState('') const pending = useRef<{ signature: string; key: string } | null>(null) const report = task?.result as ResearchReport | null const command = async (cancel: boolean, form?: HTMLFormElement) => { if (!task || busy) return setBusy(true); setError('') try { if (cancel) await api(`/agent/tasks/${id}/cancel`, { method: 'POST' }) else { const data = new FormData(form) const selections = { ...task.request.research?.selections } for (const choice of report?.choices ?? []) { const selected = data.get(choice.key) if (selected) selections[choice.key] = String(selected) } const body = { ...task.request, input: String(data.get('input') ?? task.request.input), maxCalls: Number(data.get('maxCalls') ?? task.request.maxCalls), maxCostUnits: Number(data.get('maxCostUnits') ?? task.request.maxCostUnits), ...(task.request.research ? { research: { ...task.request.research, selections, acknowledgedCalls: task.status === 'WAITING_BUDGET' ? task.calls.filter(c => c.provider !== 'LOCAL').length : task.request.research.acknowledgedCalls } } : {}) } const signature = `${id}:${JSON.stringify(body)}` if (pending.current?.signature !== signature) pending.current = { signature, key: crypto.randomUUID() } await api(`/agent/tasks/${id}/continue`, { method: 'POST', body: JSON.stringify(body), headers: { 'Idempotency-Key': pending.current.key } }) pending.current = null } setRevision(x => x + 1) onTask?.(await api(`/agent/tasks/${id}`)) } catch (e) { setError(message(e)) } finally { setBusy(false) } } if (!task) return

{streamError || '正在读取任务…'}

const complete = ['SUCCEEDED', 'FAILED', 'PARTIAL', 'CANCELLED'].includes(task.status) // 原型的回复由“Skill 调用进展 + 正文”组成,只把真实执行和报告映射到这两个区域。 // 调用账本、模型参数和刷新按钮不属于原型,不再额外插入消息内容。 return
{complete ? : } Skill 调用进展
    {task.calls.map(call =>
  • {call.status === 'SUCCEEDED' ? : }{toolNames[String(call.tool_name)] ?? String(call.tool_name)}
  • )}
{(error || streamError) &&

{error || streamError}

} {(task.status.startsWith('WAITING_') || task.status === 'FAILED') && task.question &&

{task.question}

} {task.status.startsWith('WAITING_') &&
{ e.preventDefault(); void command(false, e.currentTarget) }} className="space-y-3 rounded-ctrl bg-canvas p-4"> {task.status === 'WAITING_ENTITY' && report?.choices?.map(choice => )} {task.status === 'WAITING_INPUT' && task.operation === 'BID_RESEARCH' && } {task.status === 'WAITING_BUDGET' && <>

已发生费用保留。继续从下一步执行;未知积分需先核对账单,首个未知单价请求可能超出积分上限。

}
void command(true)}>取消确认并继续
} {report &&
{report.observations?.map((item, index) =>

{item.text}

)} {report.ownFit &&

结合公司档案对照

贴合度参考:{report.ownFit.match.score ?? '资料不足'} 分

{Object.entries(report.ownFit.match.dimensions).map(([key, dimension]) =>

{dimension.basis}

)}
} {report.commonCustomers &&

共同客户

{report.commonCustomers.join('、') || '当前样本未检出共同客户'}

} {report.sections?.map(section =>

{sectionTitle(section)}

)} {report.gaps?.length > 0 &&
    {report.gaps.map(gap =>
  • {gap}
  • )}
}
}
}