feat: 接入模型动态 Fallback 与调用审计
This commit is contained in:
@@ -258,6 +258,61 @@
|
||||
overflow: auto;
|
||||
}
|
||||
.admin-json-err { color: var(--accent-crimson); background: var(--crimson-bg); border-color: var(--crimson-bd); }
|
||||
.admin-attempt-list {
|
||||
margin: 0 0 20px;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border-muted);
|
||||
border-radius: var(--r-md);
|
||||
overflow: hidden;
|
||||
}
|
||||
.admin-attempt {
|
||||
padding: 14px 16px;
|
||||
}
|
||||
.admin-attempt + .admin-attempt { border-top: 1px solid var(--border-faint); }
|
||||
.admin-attempt-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.admin-attempt-seq { color: var(--black-alpha-48); font-size: 11px; }
|
||||
.admin-attempt-kind { margin-left: auto; color: var(--black-alpha-56); font-size: 11px; }
|
||||
.admin-attempt-model {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 6px;
|
||||
color: var(--accent-black);
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.admin-attempt-model strong { font-weight: 500; }
|
||||
.admin-attempt-sep { color: var(--black-alpha-24); }
|
||||
.admin-attempt-meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px 14px;
|
||||
margin-top: 6px;
|
||||
color: var(--black-alpha-48);
|
||||
font-size: 11px;
|
||||
}
|
||||
.admin-attempt-error {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
margin-top: 10px;
|
||||
padding: 8px 10px;
|
||||
background: var(--crimson-bg);
|
||||
border-radius: var(--r-sm);
|
||||
color: var(--accent-crimson);
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.admin-attempt-head { align-items: flex-start; flex-wrap: wrap; }
|
||||
.admin-attempt-kind { width: 100%; margin-left: 0; }
|
||||
}
|
||||
|
||||
/* ── 计费 / 额度策略 ── */
|
||||
.admin-switch-row {
|
||||
|
||||
@@ -30,6 +30,12 @@ function statusPill(status: string) {
|
||||
return <span className="pill info"><span className="dot" />进行中</span>;
|
||||
}
|
||||
|
||||
function attemptKind(attempt: AdminTaskDetail["attempts"][number]) {
|
||||
if (attempt.is_fallback) return "Fallback";
|
||||
if (attempt.is_retry) return "原模型重试";
|
||||
return "首次调用";
|
||||
}
|
||||
|
||||
export function AdminTasksPage({ notify }: { notify: Notify }) {
|
||||
const [tasks, setTasks] = useState<AdminTask[]>([]);
|
||||
const [count, setCount] = useState(0);
|
||||
@@ -171,13 +177,55 @@ export function AdminTasksPage({ notify }: { notify: Notify }) {
|
||||
<p className="admin-modal-desc">加载中…</p>
|
||||
) : (
|
||||
<>
|
||||
{(() => {
|
||||
const attempts = detail.attempts || [];
|
||||
const finalAttempt = [...attempts].reverse().find((attempt) => attempt.status === "succeeded");
|
||||
const fallbackUsed = attempts.some((attempt) => attempt.is_fallback);
|
||||
return (
|
||||
<div className="admin-detail-meta">
|
||||
<div><span className="k">状态</span><span className="v">{statusPill(detail.status)}</span></div>
|
||||
<div><span className="k">团队</span><span className="v">{detail.team_name || "—"}</span></div>
|
||||
<div><span className="k">模型</span><span className="v">{detail.model_name || "—"}</span></div>
|
||||
<div><span className="k">计价</span><span className="v mono">{pts(detail.estimated_cost)} → {pts(detail.actual_cost)} 积分{detail.cost_anomaly ? " ⚠" : ""}</span></div>
|
||||
<div><span className="k">平台成本</span><span className="v mono">{Number(detail.base_cost || 0) > 0 ? `¥${detail.base_cost} · 毛利 ${detail.margin_yuan != null ? `¥${detail.margin_yuan}` : "—"}` : "未知"}</span></div>
|
||||
<div><span className="k">模型调用</span><span className="v mono">{attempts.length ? `${attempts.length} 次 · ${fallbackUsed ? "发生 Fallback" : "未切换"}` : "旧任务 · 无尝试链"}</span></div>
|
||||
{finalAttempt && <div><span className="k">最终成功模型</span><span className="v">{finalAttempt.provider_display_name || finalAttempt.provider_name} / {finalAttempt.model_display_name || finalAttempt.model_name}</span></div>}
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
{detail.attempts?.length > 0 && (
|
||||
<>
|
||||
<div className="admin-detail-subhead">模型调用链 · {detail.attempts.length} 次</div>
|
||||
<div className="admin-attempt-list">
|
||||
{detail.attempts.map((attempt) => (
|
||||
<div className="admin-attempt" key={attempt.id}>
|
||||
<div className="admin-attempt-head">
|
||||
<span className="admin-attempt-seq mono">// {String(attempt.sequence).padStart(2, "0")}</span>
|
||||
{statusPill(attempt.status)}
|
||||
<span className="admin-attempt-kind mono">{attemptKind(attempt)}</span>
|
||||
</div>
|
||||
<div className="admin-attempt-model">
|
||||
<span>{attempt.provider_display_name || attempt.provider_name}</span>
|
||||
<span className="admin-attempt-sep">/</span>
|
||||
<strong>{attempt.model_display_name || attempt.model_name}</strong>
|
||||
</div>
|
||||
<div className="admin-attempt-meta mono">
|
||||
<span>{attempt.operation}</span>
|
||||
<span>{attempt.duration_ms == null ? "耗时 —" : `耗时 ${attempt.duration_ms} ms`}</span>
|
||||
<span>{Number(attempt.platform_cost || 0) > 0 ? `平台成本 ¥${attempt.platform_cost}` : "平台成本未知"}</span>
|
||||
{attempt.provider_task_id && <span>Provider ID {attempt.provider_task_id}</span>}
|
||||
</div>
|
||||
{(attempt.error_type || attempt.raw_error) && (
|
||||
<div className="admin-attempt-error">
|
||||
<span className="mono">[{attempt.error_type || "unknown"}{attempt.provider_error_code ? ` · ${attempt.provider_error_code}` : ""}]</span>
|
||||
<span>{attempt.raw_error || attempt.safe_error_summary}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{detail.error_message && (
|
||||
<>
|
||||
<div className="admin-detail-subhead">错误</div>
|
||||
|
||||
@@ -133,6 +133,33 @@ export type AdminTask = {
|
||||
reapable?: boolean;
|
||||
created_at: string;
|
||||
};
|
||||
export type AdminModelAttempt = {
|
||||
id: string;
|
||||
sequence: number;
|
||||
provider_name: string;
|
||||
provider_display_name: string;
|
||||
model_name: string;
|
||||
model_display_name: string;
|
||||
public_model_name: string;
|
||||
capability: string;
|
||||
operation: string;
|
||||
status: string;
|
||||
is_retry: boolean;
|
||||
is_fallback: boolean;
|
||||
previous_attempt: string | null;
|
||||
provider_task_id: string;
|
||||
started_at: string;
|
||||
finished_at: string | null;
|
||||
duration_ms: number | null;
|
||||
error_type: string;
|
||||
provider_error_code: string;
|
||||
raw_error: string;
|
||||
safe_error_summary: string;
|
||||
usage: Record<string, unknown>;
|
||||
platform_cost: string;
|
||||
request_summary: Record<string, unknown>;
|
||||
response_summary: Record<string, unknown>;
|
||||
};
|
||||
export type AdminTaskDetail = AdminTask & {
|
||||
project: string | null;
|
||||
idempotency_key: string;
|
||||
@@ -141,6 +168,7 @@ export type AdminTaskDetail = AdminTask & {
|
||||
error_message: string;
|
||||
submitted_at: string | null;
|
||||
completed_at: string | null;
|
||||
attempts: AdminModelAttempt[];
|
||||
};
|
||||
export type AdminLedger = {
|
||||
id: string;
|
||||
|
||||
Reference in New Issue
Block a user