import { useEffect, useRef, useState } from 'react' import { api } from '../lib/api' import { useTaskEvents } from '../hooks/useTaskEvents' import { PrimaryButton, GhostButton } from '../components/ui-ext/AiButton' const OPERATIONS = [ ['ZLBX_BALANCE', '知了账户余额'], ['BID_SEARCH', '知了公告检索(近 90 天全国,最多 3 条)'], ['BID_DETAIL', '知了公告详情(填写公告 ID)'], ['COMPANY_SEARCH', '知了企业主体搜索'], ['COMPANY_PROFILE', '知了企业画像(必须确认主体)'], ['MODEL_TEXT', 'DeepSeek 文本'], ['MODEL_JSON', 'DeepSeek 结构化 JSON'], ['MODEL_STREAM', 'DeepSeek 真实流式'], ['WEB_SEARCH', 'DeepSeek 联网搜索'], ['WEB_FETCH', 'DeepSeek 公开网页抓取'], ['VISION', 'DeepSeek 无敏感信息样图识别'], ] as const const STATE_LABEL: Record = { RECEIVED: '已接收', PLANNING: '计划中', RUNNING: '执行中', SUCCEEDED: '单项完成', PARTIAL: '部分完成 / 中断', FAILED: '失败', CANCELLED: '已取消', WAITING_INPUT: '等待补充配置或输入', WAITING_ENTITY: '等待确认主体', WAITING_BUDGET: '等待预算处理', } const EVENT_LABEL: Record = { RECEIVED: '接收', STATE: '状态', TOOL_START: '实际请求开始', TOOL_COMPLETE: '实际请求完成', TOOL_FAILED: '实际请求失败', REPORT_FRAGMENT: '模型片段' } /** D1 独立验证面板:每个按钮对应单个真实请求;没有凭证时明确等待,不输出演示报告。 */ export function ServiceCheckPage() { const [ledger, setLedger] = useState(null) const [operation, setOperation] = useState('ZLBX_BALANCE') const [input, setInput] = useState('') const [confirmed, setConfirmed] = useState(false) const [taskId, setTaskId] = useState(null) const [history, setHistory] = useState([]) const [busy, setBusy] = useState(false) const [error, setError] = useState('') const [limits, setLimits] = useState>({}) // 网络结果未知时保留同一幂等键;只在内容改变或成功拿到任务 ID 后更换。 const pending = useRef<{ signature: string; key: string } | null>(null) const { events, task, error: streamError } = useTaskEvents(taskId) useEffect(() => { void api('/agent/tasks').then(setHistory).catch(error => setError(error.message)) void api>('/system/limits').then(setLimits).catch(error => setError(error.message)) }, []) const start = async () => { if (busy) return const request = { operation, workflow: operation.startsWith('COMPANY_') ? 'COMPANY_INTEL' : 'TENDER_SEARCH', input, entityConfirmed: confirmed, maxCalls: Math.min(limits.maxCalls ?? 1, 1), maxCostUnits: Math.min(limits.maxCostUnits ?? 1, 1) } const signature = JSON.stringify(request) if (pending.current?.signature !== signature) pending.current = { signature, key: crypto.randomUUID() } setBusy(true); setError('') try { const created = await api<{ id: string }>('/agent/tasks', { method: 'POST', body: signature, headers: { 'Idempotency-Key': pending.current.key } }) setTaskId(created.id); setHistory(ids => [created.id, ...ids.filter(id => id !== created.id)]) pending.current = null } catch (error) { setError(error instanceof Error ? error.message : '任务创建失败') } finally { setBusy(false) } } const cancel = async () => { if (!taskId) return setBusy(true) try { await api(`/agent/tasks/${taskId}/cancel`, { method: 'POST' }) // 重新挂载事件订阅,以回放取消状态和仍可能到达的实际用量。 setTaskId(null); setTimeout(() => setTaskId(taskId), 0) } catch (error) { setError(error instanceof Error ? error.message : '取消失败') } finally { setBusy(false) } } const resume = async () => { if (!task) return const request = { ...task.request, input: input || task.request.input, entityConfirmed: confirmed || task.request.entityConfirmed, maxCalls: task.status === 'WAITING_BUDGET' ? Math.min(limits.maxCalls ?? 1, task.calls.length + 1) : task.request.maxCalls } const signature = `${task.id}:${JSON.stringify(request)}` if (pending.current?.signature !== signature) pending.current = { signature, key: crypto.randomUUID() } setBusy(true); setError('') try { await api(`/agent/tasks/${task.id}/continue`, { method: 'POST', body: JSON.stringify(request), headers: { 'Idempotency-Key': pending.current.key } }) pending.current = null setTaskId(null); setTimeout(() => setTaskId(task.id), 0) } catch (error) { setError(error instanceof Error ? error.message : '继续失败') } finally { setBusy(false) } } return

服务验证与用量核对

本账号实际调用账本(只读,不查询供应商余额) { void api('/usage').then(setLedger).catch(e => setError(e.message)) }}>读取 / 刷新本地用量{ledger != null &&
{JSON.stringify(ledger, null, 2)}
}

逐项核对知了与 DeepSeek 能力。每次创建最多发出一个请求,可能消耗供应商积分或 token。缺少密钥时显示等待配置。

{!['ZLBX_BALANCE', 'VISION'].includes(operation) &&