48 lines
4.8 KiB
TypeScript
48 lines
4.8 KiB
TypeScript
import { ModelIdentityDetails } from './ModelIdentityDetails';
|
||
import { useState } from 'react';
|
||
import type { RuntimeFailure } from './types';
|
||
import { downloadArtifact } from './api';
|
||
import './ModelErrorDetails.css';
|
||
|
||
const decisions: Record<string, string> = { 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 && <ModelIdentityDetails identity={failure.modelIdentity} requestedModel={failure.model ?? '未记录'} />}<details className="model-error-details"><summary>{upstream ? '查看上游原文与请求信息' : '查看错误详情'}</summary>
|
||
<dl><dt>错误来源</dt><dd>{origin}</dd>
|
||
{failure.model && <><dt>请求型号</dt><dd>{failure.model}</dd></>}
|
||
{failure.endpoint && <><dt>实际接口</dt><dd>{failure.endpoint}{failure.route}</dd></>}
|
||
{requestId && <><dt>上游请求 ID</dt><dd><code>{requestId}</code></dd></>}
|
||
{upstream?.responseId && <><dt>上游响应 ID</dt><dd><code>{upstream.responseId}</code></dd></>}
|
||
{failure.wireAttemptId && <><dt>本地物理尝试 ID</dt><dd><code>{failure.wireAttemptId}</code></dd></>}
|
||
{upstream?.code && <><dt>上游 code</dt><dd><code>{upstream.code}</code></dd></>}
|
||
{upstream?.type && <><dt>上游 type</dt><dd><code>{upstream.type}</code></dd></>}
|
||
{upstream?.param && <><dt>上游参数位置</dt><dd>{upstream.param}</dd></>}
|
||
{upstream?.eventType && <><dt>上游事件</dt><dd>{upstream.eventType}</dd></>}
|
||
{upstream?.reason && <><dt>上游结束原因</dt><dd>{upstream.reason}</dd></>}
|
||
{upstream?.retryAfter !== null && upstream?.retryAfter !== undefined && <><dt>原 Retry-After</dt><dd><code>{upstream.retryAfter}</code>{upstream.retryAfterMs !== null && upstream.retryAfterMs !== undefined ? ' · ' + upstream.retryAfterMs / 1000 + ' 秒' : ' · 未能解析,已停止自动重试'}</dd></>}
|
||
{failure.limitReason === 'unspecified' && <><dt>限额类型</dt><dd>上游未提供明确原因</dd></>}
|
||
{failure.retryDecision && <><dt>重试处理</dt><dd>{decisions[failure.retryDecision] ?? failure.retryDecision}</dd></>}
|
||
</dl>
|
||
{!upstream && failure.detail && <p>{failure.detail}</p>}
|
||
{upstream?.rawPreview !== undefined && <><p className="model-error-caption">上游原文{upstream.scope === 'sse-event' ? ' · 失败事件' : ' · 响应正文'}{upstream.capture?.redacted ? ' · 已脱敏' : ''}{upstream.previewTruncated ? ' · 此处显示前 8000 字符' : ''}</p>
|
||
<pre tabIndex={0} aria-label="上游错误原文">{upstream.rawPreview || '(空响应)'}</pre>
|
||
{upstream.capture && <p className="model-error-caption">已接收 {upstream.capture.receivedBytes.toLocaleString()} 字节,保留前 {upstream.capture.capturedBytes.toLocaleString()} 字节。{upstream.capture.complete ? '该范围完整接收。' : upstream.capture.truncated ? '已达到保存上限,仅保留前缀;完整长度未知。' : '接收中断,原文可能不完整。'}{upstream.artifactScope === 'sse-stream' ? '下载文件包含已保存的整段事件流。' : ''}</p>}
|
||
</>}
|
||
{!!upstream?.shortenedFields?.length && <p className="model-error-caption">部分诊断字段已缩短,详见保存的原文。</p>}
|
||
{upstream?.capture?.retention === 'preview-only' && <p className="model-error-caption">此请求未绑定工程任务,仅保留以上诊断预览;完整原文未归档为任务工件。</p>}
|
||
{upstream?.artifactSha256 && <p className="model-error-hash">工件 SHA-256 <code>{upstream.artifactSha256}</code></p>}
|
||
{upstream?.artifactId && upstream.sessionId && <button className="button secondary" type="button" disabled={busy} onClick={async () => {
|
||
setBusy(true); setNotice('');
|
||
try { await downloadArtifact(upstream.sessionId!, upstream.artifactId!, 'model-error-' + (failure.wireAttemptId ?? upstream.artifactId) + (upstream.artifactScope === 'sse-stream' ? '.sse' : '.txt')); setNotice('已下载保存的脱敏响应。'); }
|
||
catch (cause) { setNotice(cause instanceof Error ? cause.message : '下载失败,请重试。'); }
|
||
finally { setBusy(false); }
|
||
}}>下载已保存的原文</button>}
|
||
{notice && <p role="status">{notice}</p>}
|
||
</details></>;
|
||
}
|