import { ModelIdentityDetails } from './ModelIdentityDetails'; import { useState } from 'react'; import type { RuntimeFailure } from './types'; import { downloadArtifact } from './api'; import './ModelErrorDetails.css'; const decisions: Record = { retry_after_wait: '按等待时间重试', stream_not_replayed: '流式响应已开始,保留原片段并停止自动重发', not_retryable: '该错误不在同一线路自动重试', attempt_limit: '达到本次尝试上限', wait_budget: '剩余等待预算不足,保持上游建议时间并结束本次请求' }; export function ModelErrorDetails({ failure }: { failure: RuntimeFailure }) { const upstream = failure.upstream; const requestId = upstream?.requestId ?? failure.upstreamRequestId; const [notice, setNotice] = useState(''), [busy, setBusy] = useState(false); const origin = failure.origin === 'upstream' ? '上游模型服务' : failure.origin === 'local' || failure.source === 'workbench' ? '工作台本地' : '旧记录未保存具体层级'; return <>{failure.modelIdentity && }
{upstream ? '查看上游原文与请求信息' : '查看错误详情'}
错误来源
{origin}
{failure.model && <>
请求型号
{failure.model}
} {failure.endpoint && <>
实际接口
{failure.endpoint}{failure.route}
} {requestId && <>
上游请求 ID
{requestId}
} {upstream?.responseId && <>
上游响应 ID
{upstream.responseId}
} {failure.wireAttemptId && <>
本地物理尝试 ID
{failure.wireAttemptId}
} {upstream?.code && <>
上游 code
{upstream.code}
} {upstream?.type && <>
上游 type
{upstream.type}
} {upstream?.param && <>
上游参数位置
{upstream.param}
} {upstream?.eventType && <>
上游事件
{upstream.eventType}
} {upstream?.reason && <>
上游结束原因
{upstream.reason}
} {upstream?.retryAfter !== null && upstream?.retryAfter !== undefined && <>
原 Retry-After
{upstream.retryAfter}{upstream.retryAfterMs !== null && upstream.retryAfterMs !== undefined ? ' · ' + upstream.retryAfterMs / 1000 + ' 秒' : ' · 未能解析,已停止自动重试'}
} {failure.limitReason === 'unspecified' && <>
限额类型
上游未提供明确原因
} {failure.retryDecision && <>
重试处理
{decisions[failure.retryDecision] ?? failure.retryDecision}
}
{!upstream && failure.detail &&

{failure.detail}

} {upstream?.rawPreview !== undefined && <>

上游原文{upstream.scope === 'sse-event' ? ' · 失败事件' : ' · 响应正文'}{upstream.capture?.redacted ? ' · 已脱敏' : ''}{upstream.previewTruncated ? ' · 此处显示前 8000 字符' : ''}

{upstream.rawPreview || '(空响应)'}
{upstream.capture &&

已接收 {upstream.capture.receivedBytes.toLocaleString()} 字节,保留前 {upstream.capture.capturedBytes.toLocaleString()} 字节。{upstream.capture.complete ? '该范围完整接收。' : upstream.capture.truncated ? '已达到保存上限,仅保留前缀;完整长度未知。' : '接收中断,原文可能不完整。'}{upstream.artifactScope === 'sse-stream' ? '下载文件包含已保存的整段事件流。' : ''}

} } {!!upstream?.shortenedFields?.length &&

部分诊断字段已缩短,详见保存的原文。

} {upstream?.capture?.retention === 'preview-only' &&

此请求未绑定工程任务,仅保留以上诊断预览;完整原文未归档为任务工件。

} {upstream?.artifactSha256 &&

工件 SHA-256 {upstream.artifactSha256}

} {upstream?.artifactId && upstream.sessionId && } {notice &&

{notice}

}
; }