mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-11-24 09:41:51 +08:00
feat: expose scripts to review and add approval side chat
This commit is contained in:
1 parent
ee413324c8
commit
9b0d1bdb3c
18 files changed
+935
-217
No files matched your search
@@ -15,6 +15,7 @@ import {
|
||||
} from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { SideQuestionButton, SideQuestionWorkspace } from "@/components/side-question-workspace";
|
||||
import { TablePagination } from "@/components/table-pagination";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
@@ -25,6 +26,7 @@ import { Field, FieldGroup, FieldLabel } from "@/components/ui/field";
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { useSideQuestions } from "@/hooks/use-side-questions";
|
||||
import { api } from "@/lib/api";
|
||||
import type {
|
||||
InterceptApprovalFilter,
|
||||
@@ -174,6 +176,63 @@ const executionLabels: Record<InterceptAudit["execution_status"], string> = {
|
||||
unknown: "执行结果未知",
|
||||
};
|
||||
|
||||
function ReviewBackgroundBlock({ background }: { background?: InterceptReviewInput["background"] }) {
|
||||
if (!background) return <p className="text-muted-foreground text-xs">本次审查未附带背景消息。</p>;
|
||||
return (
|
||||
<div className="flex min-w-0 flex-col gap-2">
|
||||
<CodeBlock
|
||||
label={background.source === "user_message" ? "背景 · 用户消息" : "背景 · Worker 意图摘要(旧版)"}
|
||||
text={background.text}
|
||||
truncated={background.truncated}
|
||||
/>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
{background.source === "user_message"
|
||||
? "取自当前用户消息。"
|
||||
: "这是旧版发送的 Worker 意图摘要;新版 Worker 审查不再发送此内容。"}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ScriptSnapshotSummary({ input }: { input: InterceptReviewInput }) {
|
||||
const files = input.script_files ?? [];
|
||||
if (!files.length) return null;
|
||||
return (
|
||||
<section className="flex min-w-0 flex-col gap-2 rounded-lg border bg-background p-3" aria-label="已附加脚本快照">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<h3 className="font-medium text-sm">审查脚本快照</h3>
|
||||
<Badge variant={input.script_capture_status === "incomplete" ? "destructive" : "secondary"}>
|
||||
{input.script_capture_status === "incomplete" ? "读取不完整 · 需人工确认" : "已附加"}
|
||||
</Badge>
|
||||
</div>
|
||||
{files.map((file) => (
|
||||
<div key={file.path} className="flex min-w-0 flex-col gap-2">
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-xs">
|
||||
<code className="break-all">{file.path}</code>
|
||||
{file.sha256 ? <span className="text-muted-foreground">SHA-256 {file.sha256.slice(0, 12)}…</span> : null}
|
||||
{file.bytes != null ? <span className="text-muted-foreground">{file.bytes} 字节</span> : null}
|
||||
</div>
|
||||
{file.read_error ? <p className="text-destructive text-xs">{file.read_error}</p> : null}
|
||||
{file.content ? (
|
||||
<Collapsible>
|
||||
<CollapsibleTrigger asChild>
|
||||
<Button variant="ghost" size="sm" className="self-start px-0">
|
||||
<ChevronDownIcon data-icon="inline-start" />
|
||||
查看脚本内容
|
||||
</Button>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent className="pt-2">
|
||||
<CodeBlock label="脚本内容(审查快照)" text={file.content} />
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
) : null}
|
||||
</div>
|
||||
))}
|
||||
<p className="text-muted-foreground text-xs">这是执行前实际发送给审查模型的脚本快照。</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function ModelReviewContext({ input }: { input: InterceptReviewInput }) {
|
||||
return (
|
||||
<section className="flex min-w-0 flex-col gap-4" aria-label="模型审查上下文">
|
||||
@@ -189,22 +248,7 @@ function ModelReviewContext({ input }: { input: InterceptReviewInput }) {
|
||||
text={JSON.stringify({ tool_name: input.tool_name, arguments: input.arguments }, null, 2)}
|
||||
/>
|
||||
{input.version >= 2 ? (
|
||||
input.background ? (
|
||||
<div className="flex min-w-0 flex-col gap-2">
|
||||
<CodeBlock
|
||||
label={input.background.source === "user_message" ? "背景 · 用户消息" : "背景 · Worker 意图摘要(旧版)"}
|
||||
text={input.background.text}
|
||||
truncated={input.background.truncated}
|
||||
/>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
{input.background.source === "user_message"
|
||||
? "取自当前用户消息。"
|
||||
: "这是旧版发送的 Worker 意图摘要;新版 Worker 审查不再发送此内容。"}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-muted-foreground text-xs">本次审查未附带背景消息。</p>
|
||||
)
|
||||
<ReviewBackgroundBlock background={input.background} />
|
||||
) : (
|
||||
<>
|
||||
{input.turn_input ? (
|
||||
@@ -223,6 +267,39 @@ function ModelReviewContext({ input }: { input: InterceptReviewInput }) {
|
||||
</>
|
||||
)}
|
||||
{input.working_directory ? <CodeBlock label="工作目录" text={input.working_directory} /> : null}
|
||||
{input.script_files?.length ? (
|
||||
<section className="flex min-w-0 flex-col gap-4" aria-label="脚本快照">
|
||||
<div>
|
||||
<h3 className="font-medium text-sm">脚本快照</h3>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
这是审查前由平台从当前调用引用的路径读取的内容;不会在审查过程中执行脚本。
|
||||
</p>
|
||||
</div>
|
||||
{input.script_files.map((file) => (
|
||||
<div key={file.path} className="flex min-w-0 flex-col gap-2 rounded-lg border p-3">
|
||||
<div className="flex flex-wrap gap-x-4 gap-y-1 text-xs">
|
||||
<span className="break-all font-mono">{file.path}</span>
|
||||
{file.sha256 ? <span className="text-muted-foreground">SHA-256 {file.sha256}</span> : null}
|
||||
{file.bytes != null ? <span className="text-muted-foreground">{file.bytes} 字节</span> : null}
|
||||
</div>
|
||||
{file.content ? <CodeBlock label="脚本内容" text={file.content} /> : null}
|
||||
{file.read_error ? (
|
||||
<Alert variant="destructive">
|
||||
<AlertDescription>{file.read_error}</AlertDescription>
|
||||
</Alert>
|
||||
) : null}
|
||||
{file.truncated ? (
|
||||
<p className="text-muted-foreground text-xs">脚本内容不完整,不能据此自动放行。</p>
|
||||
) : null}
|
||||
</div>
|
||||
))}
|
||||
{input.script_capture_status === "incomplete" ? (
|
||||
<Alert variant="destructive">
|
||||
<AlertDescription>无法完整读取当前执行脚本,平台要求人工确认。</AlertDescription>
|
||||
</Alert>
|
||||
) : null}
|
||||
</section>
|
||||
) : null}
|
||||
{input.version >= 3 ? (
|
||||
<p className="text-muted-foreground text-xs">本次审查未发送历史调用或执行结果。</p>
|
||||
) : (
|
||||
@@ -301,6 +378,7 @@ export function ApprovalDetail({
|
||||
const [error, setError] = React.useState("");
|
||||
const [retry, setRetry] = React.useState(0);
|
||||
const [more, setMore] = React.useState(defaultExpanded);
|
||||
const side = useSideQuestions(`/api/intercept/history/${row.id}`);
|
||||
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: Status, refresh and retry invalidate details without closing the panel.
|
||||
React.useEffect(() => {
|
||||
@@ -337,181 +415,201 @@ export function ApprovalDetail({
|
||||
if (audit?.model_fallback) initialLabel = "模型异常回退";
|
||||
|
||||
return (
|
||||
<div className="flex min-w-0 flex-col gap-4 p-3 sm:p-5">
|
||||
<div className="grid min-w-0 gap-5 rounded-xl border bg-muted/20 p-4 lg:grid-cols-2">
|
||||
<div className="flex min-w-0 flex-col gap-3">
|
||||
<CodeBlock
|
||||
label={`${current.agent_name || current.conv_agent_key || "Agent"} · 工具请求`}
|
||||
text={JSON.stringify(row.tool_input ?? {}, null, 2)}
|
||||
/>
|
||||
{command ? (
|
||||
<Collapsible>
|
||||
<CollapsibleTrigger asChild>
|
||||
<Button variant="ghost" size="sm">
|
||||
<ChevronDownIcon data-icon="inline-start" />
|
||||
查看命令内容
|
||||
</Button>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent className="pt-2">
|
||||
<CodeBlock label="命令内容" text={command} />
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
) : null}
|
||||
<p className="text-muted-foreground text-xs">
|
||||
执行结果:<span className="text-foreground">{detail ? execution : "加载中…"}</span>
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex min-w-0 flex-col gap-4 lg:border-l lg:pl-5">
|
||||
<h3 className="font-medium text-muted-foreground text-xs">
|
||||
{current.status === "pending" ? "审查状态" : "审批裁决"}
|
||||
</h3>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<StatusBadge status={current.status} />
|
||||
<MatchCell row={current} showReason={false} />
|
||||
<SideQuestionWorkspace
|
||||
side={side}
|
||||
label={`审批 #${row.id} · ${row.tool_name}`}
|
||||
composerLayout="stacked"
|
||||
placeholder="询问此审批中的脚本或审查理由…"
|
||||
suggestions={[
|
||||
"此脚本的作用是什么?",
|
||||
"脚本会修改哪些文件或数据?",
|
||||
"为什么这次被放行或拦截?",
|
||||
"脚本中有哪些未确定行为?",
|
||||
]}
|
||||
>
|
||||
<div className="flex min-w-0 flex-col gap-4 p-3 sm:p-5">
|
||||
<div className="grid min-w-0 gap-5 rounded-xl border bg-muted/20 p-4 lg:grid-cols-2">
|
||||
<div className="flex min-w-0 flex-col gap-3">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<span className="font-medium text-sm">审批上下文</span>
|
||||
<SideQuestionButton side={side} />
|
||||
</div>
|
||||
<CodeBlock
|
||||
label={`${current.agent_name || current.conv_agent_key || "Agent"} · 工具请求`}
|
||||
text={JSON.stringify(row.tool_input ?? {}, null, 2)}
|
||||
/>
|
||||
{command ? (
|
||||
<Collapsible>
|
||||
<CollapsibleTrigger asChild>
|
||||
<Button variant="ghost" size="sm">
|
||||
<ChevronDownIcon data-icon="inline-start" />
|
||||
查看命令内容
|
||||
</Button>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent className="pt-2">
|
||||
<CodeBlock label="命令内容" text={command} />
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
) : null}
|
||||
<p className="text-muted-foreground text-xs">
|
||||
执行结果:<span className="text-foreground">{detail ? execution : "加载中…"}</span>
|
||||
</p>
|
||||
{audit?.model_input ? <ScriptSnapshotSummary input={audit.model_input} /> : null}
|
||||
</div>
|
||||
<p className="whitespace-pre-wrap break-words text-sm leading-7 [overflow-wrap:anywhere]">
|
||||
{current.reason?.replace(/^\[模型\]\s*/, "") || "未记录审批理由"}
|
||||
</p>
|
||||
{audit?.decision_reason ? <p className="text-sm">{audit.decision_reason}</p> : null}
|
||||
{audit?.effective_action ? <p className="text-sm">最终动作:{actionLabels[audit.effective_action]}</p> : null}
|
||||
<dl className="grid grid-cols-[auto_minmax(0,1fr)] gap-x-4 gap-y-2 text-xs">
|
||||
<dt className="text-muted-foreground">来源</dt>
|
||||
<dd className="break-words">
|
||||
<ApprovalOrigin row={current} detail />
|
||||
</dd>
|
||||
<dt className="text-muted-foreground">申请时间</dt>
|
||||
<dd>{fmtTime(row.created_at)}</dd>
|
||||
<dt className="text-muted-foreground">决定时间</dt>
|
||||
<dd>{fmtTime(current.decided_at)}</dd>
|
||||
{audit?.rule_name ? (
|
||||
<>
|
||||
<dt className="text-muted-foreground">规则快照</dt>
|
||||
<dd>{audit.rule_name}</dd>
|
||||
</>
|
||||
) : null}
|
||||
{audit?.profile_id ? (
|
||||
<>
|
||||
<dt className="text-muted-foreground">审批模型配置</dt>
|
||||
<dd>#{audit.profile_id}</dd>
|
||||
</>
|
||||
) : null}
|
||||
</dl>
|
||||
{!readOnly ? <DecisionActions row={current} busy={busy} decide={decide} /> : null}
|
||||
</div>
|
||||
</div>
|
||||
{error ? (
|
||||
<Alert variant="destructive">
|
||||
<AlertDescription>
|
||||
<div className="flex min-w-0 flex-col gap-4 lg:border-l lg:pl-5">
|
||||
<h3 className="font-medium text-muted-foreground text-xs">
|
||||
{current.status === "pending" ? "审查状态" : "审批裁决"}
|
||||
</h3>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span>详情加载失败:{error}</span>
|
||||
<Button variant="outline" size="sm" onClick={() => setRetry((v) => v + 1)}>
|
||||
重试详情
|
||||
<StatusBadge status={current.status} />
|
||||
<MatchCell row={current} showReason={false} />
|
||||
</div>
|
||||
<p className="whitespace-pre-wrap break-words text-sm leading-7 [overflow-wrap:anywhere]">
|
||||
{current.reason?.replace(/^\[模型\]\s*/, "") || "未记录审批理由"}
|
||||
</p>
|
||||
{audit?.decision_reason ? <p className="text-sm">{audit.decision_reason}</p> : null}
|
||||
{audit?.effective_action ? (
|
||||
<p className="text-sm">最终动作:{actionLabels[audit.effective_action]}</p>
|
||||
) : null}
|
||||
<dl className="grid grid-cols-[auto_minmax(0,1fr)] gap-x-4 gap-y-2 text-xs">
|
||||
<dt className="text-muted-foreground">来源</dt>
|
||||
<dd className="break-words">
|
||||
<ApprovalOrigin row={current} detail />
|
||||
</dd>
|
||||
<dt className="text-muted-foreground">申请时间</dt>
|
||||
<dd>{fmtTime(row.created_at)}</dd>
|
||||
<dt className="text-muted-foreground">决定时间</dt>
|
||||
<dd>{fmtTime(current.decided_at)}</dd>
|
||||
{audit?.rule_name ? (
|
||||
<>
|
||||
<dt className="text-muted-foreground">规则快照</dt>
|
||||
<dd>{audit.rule_name}</dd>
|
||||
</>
|
||||
) : null}
|
||||
{audit?.profile_id ? (
|
||||
<>
|
||||
<dt className="text-muted-foreground">审批模型配置</dt>
|
||||
<dd>#{audit.profile_id}</dd>
|
||||
</>
|
||||
) : null}
|
||||
</dl>
|
||||
{!readOnly ? <DecisionActions row={current} busy={busy} decide={decide} /> : null}
|
||||
</div>
|
||||
</div>
|
||||
{error ? (
|
||||
<Alert variant="destructive">
|
||||
<AlertDescription>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span>详情加载失败:{error}</span>
|
||||
<Button variant="outline" size="sm" onClick={() => setRetry((v) => v + 1)}>
|
||||
重试详情
|
||||
</Button>
|
||||
</div>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
) : null}
|
||||
{!detail && !error ? <Skeleton className="h-8 w-60" /> : null}
|
||||
{detail && !audit ? (
|
||||
<Alert>
|
||||
<AlertDescription>此记录未保存审批详情快照,无法还原当时的上下文、模型初判和执行输出。</AlertDescription>
|
||||
</Alert>
|
||||
) : null}
|
||||
{audit ? (
|
||||
<Collapsible open={more} onOpenChange={setMore}>
|
||||
<CollapsibleTrigger asChild>
|
||||
<Button variant="ghost" size="sm">
|
||||
<ChevronDownIcon data-icon="inline-start" className={cn(more && "rotate-180")} />
|
||||
{more ? "收起上下文" : "查看上下文与执行结果"}
|
||||
</Button>
|
||||
</div>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
) : null}
|
||||
{!detail && !error ? <Skeleton className="h-8 w-60" /> : null}
|
||||
{detail && !audit ? (
|
||||
<Alert>
|
||||
<AlertDescription>此记录未保存审批详情快照,无法还原当时的上下文、模型初判和执行输出。</AlertDescription>
|
||||
</Alert>
|
||||
) : null}
|
||||
{audit ? (
|
||||
<Collapsible open={more} onOpenChange={setMore}>
|
||||
<CollapsibleTrigger asChild>
|
||||
<Button variant="ghost" size="sm">
|
||||
<ChevronDownIcon data-icon="inline-start" className={cn(more && "rotate-180")} />
|
||||
{more ? "收起上下文" : "查看上下文与执行结果"}
|
||||
</Button>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent className="pt-4">
|
||||
<div className="flex min-w-0 flex-col gap-5">
|
||||
{audit.model_input ? (
|
||||
<ModelReviewContext input={audit.model_input} />
|
||||
) : (
|
||||
<Alert>
|
||||
<AlertDescription>
|
||||
{audit.model_input_digest
|
||||
? "此历史记录仅保存审查输入指纹,未保存输入原文,无法还原当时发给模型的上下文。这不代表审查时没有上下文;新产生的模型裁决会保留输入快照。"
|
||||
: "此记录没有保存模型审查输入,可能由规则直接裁决、模型调用前发生异常或产生于旧版本。"}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
{audit.user_message || audit.context?.length ? (
|
||||
<Collapsible>
|
||||
<CollapsibleTrigger asChild>
|
||||
<Button variant="ghost" size="sm">
|
||||
<ChevronDownIcon data-icon="inline-start" />
|
||||
{audit.model_input && audit.model_input.version >= 3
|
||||
? "查看会话审计片段(未发送模型)"
|
||||
: "查看会话审计片段"}
|
||||
</Button>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent className="pt-3">
|
||||
<div className="flex min-w-0 flex-col gap-3">
|
||||
{audit.user_message ? (
|
||||
<CodeBlock
|
||||
label="会话当前轮输入(审计片段)"
|
||||
text={audit.user_message}
|
||||
truncated={audit.user_truncated}
|
||||
/>
|
||||
) : null}
|
||||
<section className="flex min-w-0 flex-col gap-3">
|
||||
<h3 className="font-medium text-muted-foreground text-xs">可见会话上下文</h3>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
保存于 {fmtTime(audit.captured_at)} 的会话记录片段。模型实际使用的内容以“模型审查输入”为准。
|
||||
</p>
|
||||
{audit.context_truncated ? (
|
||||
<p className="text-muted-foreground text-xs">仅保存最近的上下文,部分内容已截断。</p>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent className="pt-4">
|
||||
<div className="flex min-w-0 flex-col gap-5">
|
||||
{audit.model_input ? (
|
||||
<ModelReviewContext input={audit.model_input} />
|
||||
) : (
|
||||
<Alert>
|
||||
<AlertDescription>
|
||||
{audit.model_input_digest
|
||||
? "此历史记录仅保存审查输入指纹,未保存输入原文,无法还原当时发给模型的上下文。这不代表审查时没有上下文;新产生的模型裁决会保留输入快照。"
|
||||
: "此记录没有保存模型审查输入,可能由规则直接裁决、模型调用前发生异常或产生于旧版本。"}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
{audit.user_message || audit.context?.length ? (
|
||||
<Collapsible>
|
||||
<CollapsibleTrigger asChild>
|
||||
<Button variant="ghost" size="sm">
|
||||
<ChevronDownIcon data-icon="inline-start" />
|
||||
{audit.model_input && audit.model_input.version >= 3
|
||||
? "查看会话审计片段(未发送模型)"
|
||||
: "查看会话审计片段"}
|
||||
</Button>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent className="pt-3">
|
||||
<div className="flex min-w-0 flex-col gap-3">
|
||||
{audit.user_message ? (
|
||||
<CodeBlock
|
||||
label="会话当前轮输入(审计片段)"
|
||||
text={audit.user_message}
|
||||
truncated={audit.user_truncated}
|
||||
/>
|
||||
) : null}
|
||||
{audit.context?.length ? (
|
||||
audit.context.map((entry, index) => (
|
||||
<CodeBlock
|
||||
key={`${entry.kind}-${entry.tool_use_id || index}`}
|
||||
label={`${contextLabels[entry.kind] ?? entry.kind}${entry.tool ? ` · ${entry.tool}` : ""}${entry.is_error ? " · 异常" : ""}`}
|
||||
text={entry.text}
|
||||
truncated={entry.truncated}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
<p className="text-muted-foreground text-sm">未记录可关联的上下文</p>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
) : null}
|
||||
<CodeBlock
|
||||
label={`${initialLabel}:${actionLabels[audit.initial_action] ?? audit.initial_action}`}
|
||||
text={audit.initial_reason.replace(/^\[模型\]\s*/, "")}
|
||||
/>
|
||||
<CodeBlock
|
||||
label="执行输出"
|
||||
text={audit.output ?? (audit.execution_status === "not_executed" ? "工具未执行。" : "尚无执行输出")}
|
||||
truncated={audit.output_truncated}
|
||||
/>
|
||||
{audit.correlation !== "exact" ? (
|
||||
<Alert>
|
||||
<AlertDescription>
|
||||
{audit.correlation === "ambiguous"
|
||||
? "存在相同参数的并发调用,无法唯一关联工具调用;本记录不展示推测的执行结果。"
|
||||
: "未记录可唯一关联的工具调用 ID。"}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
) : null}
|
||||
<dl className="grid gap-2 text-muted-foreground text-xs [overflow-wrap:anywhere]">
|
||||
<div>工具调用 ID:{audit.tool_use_id || "未记录"}</div>
|
||||
<div>参数摘要 SHA-256:{audit.input_digest}</div>
|
||||
<div>审查配置指纹 SHA-256:{audit.config_digest || "未记录"}</div>
|
||||
{audit.model_input_digest ? <div>模型审查输入 SHA-256:{audit.model_input_digest}</div> : null}
|
||||
{audit.execution_ended_at ? <div>结果记录时间:{fmtTime(audit.execution_ended_at)}</div> : null}
|
||||
</dl>
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
) : null}
|
||||
</div>
|
||||
<section className="flex min-w-0 flex-col gap-3">
|
||||
<h3 className="font-medium text-muted-foreground text-xs">可见会话上下文</h3>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
保存于 {fmtTime(audit.captured_at)} 的会话记录片段。模型实际使用的内容以“模型审查输入”为准。
|
||||
</p>
|
||||
{audit.context_truncated ? (
|
||||
<p className="text-muted-foreground text-xs">仅保存最近的上下文,部分内容已截断。</p>
|
||||
) : null}
|
||||
{audit.context?.length ? (
|
||||
audit.context.map((entry, index) => (
|
||||
<CodeBlock
|
||||
key={`${entry.kind}-${entry.tool_use_id || index}`}
|
||||
label={`${contextLabels[entry.kind] ?? entry.kind}${entry.tool ? ` · ${entry.tool}` : ""}${entry.is_error ? " · 异常" : ""}`}
|
||||
text={entry.text}
|
||||
truncated={entry.truncated}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
<p className="text-muted-foreground text-sm">未记录可关联的上下文</p>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
) : null}
|
||||
<CodeBlock
|
||||
label={`${initialLabel}:${actionLabels[audit.initial_action] ?? audit.initial_action}`}
|
||||
text={audit.initial_reason.replace(/^\[模型\]\s*/, "")}
|
||||
/>
|
||||
<CodeBlock
|
||||
label="执行输出"
|
||||
text={audit.output ?? (audit.execution_status === "not_executed" ? "工具未执行。" : "尚无执行输出")}
|
||||
truncated={audit.output_truncated}
|
||||
/>
|
||||
{audit.correlation !== "exact" ? (
|
||||
<Alert>
|
||||
<AlertDescription>
|
||||
{audit.correlation === "ambiguous"
|
||||
? "存在相同参数的并发调用,无法唯一关联工具调用;本记录不展示推测的执行结果。"
|
||||
: "未记录可唯一关联的工具调用 ID。"}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
) : null}
|
||||
<dl className="grid gap-2 text-muted-foreground text-xs [overflow-wrap:anywhere]">
|
||||
<div>工具调用 ID:{audit.tool_use_id || "未记录"}</div>
|
||||
<div>参数摘要 SHA-256:{audit.input_digest}</div>
|
||||
<div>审查配置指纹 SHA-256:{audit.config_digest || "未记录"}</div>
|
||||
{audit.model_input_digest ? <div>模型审查输入 SHA-256:{audit.model_input_digest}</div> : null}
|
||||
{audit.execution_ended_at ? <div>结果记录时间:{fmtTime(audit.execution_ended_at)}</div> : null}
|
||||
</dl>
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
) : null}
|
||||
</div>
|
||||
</SideQuestionWorkspace>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -681,7 +779,9 @@ export function ApprovalRecords({ taskId }: { taskId?: string }) {
|
||||
// filter. Older requests must remain actionable even when newer decisions
|
||||
// fill the page or a filter would hide them.
|
||||
const [history, pending] = await Promise.allSettled([
|
||||
taskId ? api.interceptTaskPage(taskId, page, pageSize, filter) : api.interceptHistoryPage(page, pageSize, filter),
|
||||
taskId
|
||||
? api.interceptTaskPage(taskId, page, pageSize, filter)
|
||||
: api.interceptHistoryPage(page, pageSize, filter),
|
||||
api.interceptPending(),
|
||||
]);
|
||||
if (id !== request.current) return;
|
||||
|
||||
@@ -51,10 +51,14 @@ function SidePanel({
|
||||
side,
|
||||
label,
|
||||
composerLayout,
|
||||
suggestions,
|
||||
placeholder,
|
||||
}: {
|
||||
side: SideQuestions;
|
||||
label: string;
|
||||
composerLayout: ComposerLayout;
|
||||
suggestions?: string[];
|
||||
placeholder?: string;
|
||||
}) {
|
||||
const inlineComposer = composerLayout === "inline";
|
||||
const [confirm, setConfirm] = useState(false);
|
||||
@@ -164,7 +168,7 @@ function SidePanel({
|
||||
rows={1}
|
||||
className={cn("overflow-y-auto", inlineComposer ? "max-h-40 min-h-0" : "max-h-36 min-h-9")}
|
||||
aria-label="旁路问题"
|
||||
placeholder="询问当前上下文…"
|
||||
placeholder={placeholder ?? "询问当前上下文…"}
|
||||
value={side.draft}
|
||||
maxLength={4000}
|
||||
disabled={side.busy}
|
||||
@@ -202,6 +206,22 @@ function SidePanel({
|
||||
)}
|
||||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
{suggestions?.length ? (
|
||||
<fieldset className="mt-2 flex flex-wrap gap-1.5" aria-label="快捷问题">
|
||||
{suggestions.map((suggestion) => (
|
||||
<Button
|
||||
key={suggestion}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-auto whitespace-normal text-left text-xs"
|
||||
disabled={side.busy || !side.snapshot?.available}
|
||||
onClick={() => void side.ask(suggestion)}
|
||||
>
|
||||
{suggestion}
|
||||
</Button>
|
||||
))}
|
||||
</fieldset>
|
||||
) : null}
|
||||
</div>
|
||||
{inlineComposer && (
|
||||
<div className="shrink-0 truncate px-3 pt-0.5 pb-1 text-muted-foreground text-xs">独立问答 · 无工具执行</div>
|
||||
@@ -229,11 +249,15 @@ export function SideQuestionWorkspace({
|
||||
label,
|
||||
children,
|
||||
composerLayout = "stacked",
|
||||
suggestions,
|
||||
placeholder,
|
||||
}: {
|
||||
side: SideQuestions;
|
||||
label: string;
|
||||
children: ReactNode;
|
||||
composerLayout?: ComposerLayout;
|
||||
suggestions?: string[];
|
||||
placeholder?: string;
|
||||
}) {
|
||||
const mobile = useIsMobile();
|
||||
return (
|
||||
@@ -246,7 +270,13 @@ export function SideQuestionWorkspace({
|
||||
<>
|
||||
<ResizableHandle withHandle />
|
||||
<ResizablePanel id="side-question" defaultSize="38%" minSize="280px" maxSize="65%">
|
||||
<SidePanel side={side} label={label} composerLayout={composerLayout} />
|
||||
<SidePanel
|
||||
side={side}
|
||||
label={label}
|
||||
composerLayout={composerLayout}
|
||||
suggestions={suggestions}
|
||||
placeholder={placeholder}
|
||||
/>
|
||||
</ResizablePanel>
|
||||
</>
|
||||
)}
|
||||
@@ -257,7 +287,13 @@ export function SideQuestionWorkspace({
|
||||
<DrawerTitle>旁路提问</DrawerTitle>
|
||||
<DrawerDescription>{label} 的独立问答</DrawerDescription>
|
||||
</DrawerHeader>
|
||||
<SidePanel side={side} label={label} composerLayout={composerLayout} />
|
||||
<SidePanel
|
||||
side={side}
|
||||
label={label}
|
||||
composerLayout={composerLayout}
|
||||
suggestions={suggestions}
|
||||
placeholder={placeholder}
|
||||
/>
|
||||
</DrawerContent>
|
||||
</Drawer>
|
||||
</>
|
||||
|
||||
@@ -3548,6 +3548,21 @@ export const interceptDetails: Record<number, InterceptAudit> = {
|
||||
initial_reason: "[模型] 疑似备份表,无法确定是否生产数据。",
|
||||
profile_id: 1,
|
||||
execution_status: "not_started",
|
||||
model_input: {
|
||||
version: 5,
|
||||
working_directory: "/app/data/tasks/48/i2182",
|
||||
script_capture_status: "complete",
|
||||
script_files: [
|
||||
{
|
||||
path: "/app/data/tasks/48/i2182/cleanup.sql",
|
||||
sha256: "demo-cleanup-sha256",
|
||||
bytes: 92,
|
||||
content: "DROP TABLE users_bak_0921;\n-- 仅用于本次测试的脚本说明待核实。\n",
|
||||
},
|
||||
],
|
||||
tool_name: "Bash",
|
||||
arguments: { command: "mysql -e 'source cleanup.sql'" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -2250,7 +2250,8 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
|
||||
if (path === "/settings" && m === "GET") return D.settings;
|
||||
if (path === "/settings" && m === "PUT") return { ...D.settings, ...b };
|
||||
if (path === "/settings/basic-auth" && m === "GET") return { enabled: false, username: "", password_set: false };
|
||||
if (path === "/settings/basic-auth" && m === "PUT") throw new Error("演示模式不支持修改 HTTP Basic Auth,请在实际部署中配置");
|
||||
if (path === "/settings/basic-auth" && m === "PUT")
|
||||
throw new Error("演示模式不支持修改 HTTP Basic Auth,请在实际部署中配置");
|
||||
if (path === "/settings/web-search/test") return { ok: true, count: 5, backend: D.settings.web_search_backend };
|
||||
if (path === "/settings/python/detect") return { python_interpreter: "/usr/bin/python3" };
|
||||
if (path === "/chat")
|
||||
@@ -2508,7 +2509,36 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
|
||||
// ── 旁路提问(/btw):demo 无旁路会话 ──
|
||||
// 必须显式命中:路径以 s 结尾会被下面的读兜底判成集合返回 [],items 就成了 undefined。
|
||||
if (seg.at(-1) === "side-questions") {
|
||||
if (m === "GET") return { items: [], current: null, next_cursor: 0, snapshot: null };
|
||||
if (m === "GET") {
|
||||
if (seg[0] === "intercept" && seg[1] === "history") {
|
||||
return {
|
||||
items: [],
|
||||
current: null,
|
||||
next_cursor: 0,
|
||||
snapshot: {
|
||||
captured_at: new Date().toISOString(),
|
||||
model: { model: "demo-review", name: "审查模型", format: "openai", profile_id: 1 },
|
||||
available: true,
|
||||
reason: "",
|
||||
},
|
||||
};
|
||||
}
|
||||
return { items: [], current: null, next_cursor: 0, snapshot: null };
|
||||
}
|
||||
if (m === "POST" && seg[0] === "intercept" && seg[1] === "history") {
|
||||
return {
|
||||
id: `approval-btw-${Date.now()}`,
|
||||
ordinal: Date.now(),
|
||||
client_request_id: b.client_request_id,
|
||||
question: b.question,
|
||||
answer: "演示模式:此旁路回答基于当前审批记录中的命令、用户消息和脚本快照。",
|
||||
status: "completed",
|
||||
model: { model: "demo-review", name: "审查模型", format: "openai", profile_id: 1 },
|
||||
snapshot_at: new Date().toISOString(),
|
||||
created_at: new Date().toISOString(),
|
||||
sequence: 1,
|
||||
};
|
||||
}
|
||||
if (m === "POST") throw new Error("演示模式不支持旁路提问");
|
||||
}
|
||||
|
||||
|
||||
@@ -1480,6 +1480,16 @@ export interface LLMTask {
|
||||
// The exact JSON sent to the review model, retained for all model verdicts.
|
||||
export interface InterceptReviewInput {
|
||||
version: number;
|
||||
script_capture_status?: "not_applicable" | "complete" | "incomplete";
|
||||
script_files?: {
|
||||
path: string;
|
||||
sha256?: string;
|
||||
bytes?: number;
|
||||
content?: string;
|
||||
complete?: boolean;
|
||||
truncated?: boolean;
|
||||
read_error?: string;
|
||||
}[];
|
||||
background?: {
|
||||
// worker_summary is retained only for immutable v2/v3 snapshots.
|
||||
source: "user_message" | "worker_summary";
|
||||
|
||||
Reference in new issue
Block a user