diff --git a/.github/workflows/release-checks.yml b/.github/workflows/release-checks.yml index 938024f25..a338cc60c 100644 --- a/.github/workflows/release-checks.yml +++ b/.github/workflows/release-checks.yml @@ -311,6 +311,7 @@ jobs: curl --silent --fail "$CREATION_WEB_URL/" >/dev/null node tests/browser/bilingual_defaults.mjs node tests/browser/assistant_auxiliary_panels.mjs + node tests/browser/trace_original_export.mjs - name: Print isolated service logs on failure if: failure() run: | diff --git a/docs/architecture/agent-runtime.md b/docs/architecture/agent-runtime.md index 5189d2628..27d903a38 100644 --- a/docs/architecture/agent-runtime.md +++ b/docs/architecture/agent-runtime.md @@ -106,6 +106,12 @@ CLI 通过环境变量中的本轮本地 Socket 地址连接业务网关,不 ## 对话轨迹页 / Conversation trace page -轨迹页 `/?traceProject=…&conversation=…&turn=…` 在一页内按顺序列出一个对话的全部已执行轮次,每轮可独立展开,展开时才读取该轮日志与关联 Job。轮次索引来自只读接口 `GET .../assistant/conversations/{conversation_id}/trace`,它解析当前对话、已归档对话和 `reusedCreateIds` 别名,只返回轮次元数据(序号、用户输入摘要、运行时、状态),不读取日志正文,不激活对话,不获取编辑租约。轮次由持久化的身份关系确定:用户消息与 id 为 `uuid5(用户消息 id, 'assistant')` 的助手消息成对才算已执行的一轮;没有该助手记录的用户消息(例如排队中、未执行)不出现。每轮使用自己记录的运行时选择日志源和解析器,仅 Default(opencode)显示模型原始请求。`GET .../traces/{turn_id}/conversation` 供旧的单轮链接查找所属对话;找不到时保持原单轮页面。 +轨迹页 `/?traceProject=…&conversation=…&turn=…` 在一页内按顺序列出一个对话的全部已执行轮次,每轮可独立展开,展开时才读取该轮日志与关联 Job;“下载原始轨迹”是用户显式触发的例外,见下。轮次索引来自只读接口 `GET .../assistant/conversations/{conversation_id}/trace`,它解析当前对话、已归档对话和 `reusedCreateIds` 别名,只返回轮次元数据(序号、用户输入摘要、运行时、状态),不读取日志正文,不激活对话,不获取编辑租约。轮次由持久化的身份关系确定:用户消息与 id 为 `uuid5(用户消息 id, 'assistant')` 的助手消息成对才算已执行的一轮;没有该助手记录的用户消息(例如排队中、未执行)不出现。每轮使用自己记录的运行时选择日志源和解析器,仅 Default(opencode)显示模型原始请求。`GET .../traces/{turn_id}/conversation` 供旧的单轮链接查找所属对话;找不到时保持原单轮页面。 -English summary: the trace page lists every executed turn of a conversation, expanded one at a time, and reads a turn's logs and linked Jobs only when it is opened. The turn index comes from the read-only `GET .../assistant/conversations/{conversation_id}/trace`, which resolves current, archived and aliased (`reusedCreateIds`) conversation ids and returns metadata only (number, input summary, runtime, status). It never reads log bodies, activates a conversation or takes a lease. A turn is a user message paired with the assistant message whose id is `uuid5(user id, 'assistant')`, so queued or never executed user messages are not listed. Each turn uses its own recorded runtime for the log source and parser, and raw model requests are offered for the Default (opencode) runtime only. `GET .../traces/{turn_id}/conversation` lets old single-turn links find their conversation; when none is found the single-turn page remains. +English summary: the trace page lists every executed turn of a conversation, expanded one at a time, and reads a turn's logs and linked Jobs only when it is opened; the user-triggered original trace download is the one exception (below). The turn index comes from the read-only `GET .../assistant/conversations/{conversation_id}/trace`, which resolves current, archived and aliased (`reusedCreateIds`) conversation ids and returns metadata only (number, input summary, runtime, status). It never reads log bodies, activates a conversation or takes a lease. A turn is a user message paired with the assistant message whose id is `uuid5(user id, 'assistant')`, so queued or never executed user messages are not listed. Each turn uses its own recorded runtime for the log source and parser, and raw model requests are offered for the Default (opencode) runtime only. `GET .../traces/{turn_id}/conversation` lets old single-turn links find their conversation; when none is found the single-turn page remains. + +### 原始轨迹归档 / Original trace archive + +“下载原始轨迹”由前端完成,不新增或修改后端接口,复用 `src/canvas/zipArchive.ts` 的 `createZip()`(`compress: false`,保留原始字节)与 `downloadFile()`。流程:先重新请求 `GET .../conversations/{conversation_id}/trace`,任何轮次为 `streaming` 即拒绝;随后对每轮按其运行时逐个请求 `GET .../traces/{turn_id}/{source}`(404 记为 `missing`,其他非 2xx、超时、响应提前结束、超限一律失败),读完后再次校验轮次状态,不一致则失败。任何失败都不产出 ZIP。因此归档是逐来源读取的结果,不是跨文件原子快照,`manifest.json` 的 `snapshot` 字段如实说明。容量上限为 64 MiB,含每个条目的本地头、中央目录项、结束记录和 manifest,没有单文件上限,超限时错误指出轮次与来源。每个请求和整个导出都有超时,用户可取消,读取流在失败、超限、取消时被取消并释放。内容不脱敏,`model.jsonl` 原样包含;`manifest.json` 区分 Job 为空(`jobs: []`)与查询失败(`jobs: null`、`jobsStatus: "unavailable"`)。 + +English summary: the download is built in the frontend with no backend change, reusing `createZip()` (`compress: false`, original bytes) and `downloadFile()`. It re-fetches the conversation trace index and refuses when any turn is `streaming`, reads each source sequentially (404 becomes `missing`; any other non-2xx, timeout, early end or cap overrun fails), then re-checks turn status and fails on any difference. No failure produces a ZIP, and the archive is explicitly a per-source read, not an atomic snapshot across files (`manifest.json` says so). The 64 MiB cap covers raw bytes plus ZIP headers, central directory, end record and manifest; there is no per-file cap, and an overrun names the turn and source. Requests and the whole export are time-bounded, the user can cancel, and streams are cancelled and released on failure, overrun or cancel. Content is not redacted (`model.jsonl` included). The manifest separates no linked Jobs (`jobs: []`) from a failed lookup (`jobs: null`, `jobsStatus: "unavailable"`). diff --git a/docs/guides/user-guide.md b/docs/guides/user-guide.md index 0e9cc762e..328b650c3 100644 --- a/docs/guides/user-guide.md +++ b/docs/guides/user-guide.md @@ -156,6 +156,14 @@ Use **New conversation** at the top of the panel to start a separate chat. **Con Asset generation may continue after the reply ends. Check its progress in **Generation history**. +### Download the original trace + +Open the conversation trace page and choose **Download original trace (.zip)** to save the raw per-turn log files for local debugging. The ZIP holds one `manifest.json` and, under `turn-NNNN/`, the unmodified `.jsonl` log of each source (the Default runtime also includes `model.jsonl`, the model requests). Nothing is redacted, so the files can contain credentials, prompts, tool inputs and outputs and private paths. A confirmation appears first; review the files before sharing them. + +- The archive is read source by source and is not an atomic snapshot across files. It is only built when no turn is running, and turn status is checked again at click time and after reading. While a turn is running the button is disabled; wait for it to finish. +- A source file that does not exist is listed as `missing` in `manifest.json`. A failed Jobs lookup is recorded as `jobsStatus: "unavailable"`, which differs from a turn that has no linked Jobs (`jobs: []`). +- The total is capped at 64 MiB including ZIP overhead. If a read fails, times out, ends early, or goes over the cap, the page names the turn and source and no ZIP is saved. You can cancel while it is preparing. + ## Edit images, video, and audio Select a node, then choose an action from its toolbar. diff --git a/docs/guides/user-guide.zh-CN.md b/docs/guides/user-guide.zh-CN.md index fcb1992a8..43aa920c7 100644 --- a/docs/guides/user-guide.zh-CN.md +++ b/docs/guides/user-guide.zh-CN.md @@ -156,6 +156,14 @@ Codex 网页检索引用在具有匹配来源时显示为编号链接;复制 素材生成可能在回复结束后继续进行,可在“生成历史”查看进度。 +### 下载原始轨迹 + +在对话轨迹页选择“下载原始轨迹(.zip)”,可保存各轮次的原始日志文件,供本地排障。ZIP 内含一个 `manifest.json`,以及 `turn-NNNN/` 目录下各来源未经修改的 `.jsonl` 日志(Default 运行时另含记录模型请求的 `model.jsonl`)。内容不做脱敏,可能包含密钥、提示词、工具输入输出和私有路径。下载前会先弹出确认,分享前请自行检查文件内容。 + +- 压缩包是逐个来源读取的归档,不是跨文件的原子快照。仅在没有轮次执行时才会生成;点击时和读取结束后都会重新校验轮次状态。有轮次正在执行时按钮不可用,请等待结束。 +- 不存在的来源文件在 `manifest.json` 中标记为 `missing`。Job 查询失败记为 `jobsStatus: "unavailable"`,与没有关联 Job(`jobs: []`)不同。 +- 总大小(含 ZIP 开销)上限为 64 MiB。读取失败、超时、响应提前结束或超限时,页面会指出轮次和来源,且不保存任何 ZIP。准备过程中可以取消。 + ## 编辑图片、视频和音频 选中节点,通过工具栏选择所需操作。 diff --git a/src/canvas/AssistantTracePage.tsx b/src/canvas/AssistantTracePage.tsx index a07a40e85..7f57bedf5 100644 --- a/src/canvas/AssistantTracePage.tsx +++ b/src/canvas/AssistantTracePage.tsx @@ -7,6 +7,8 @@ import { traceCategory, isThinkingTokenEstimate, readableTraceValue } from "./tr import { initialTurn, normalizeTrace, runtimeName, traceRuntime, traceSources, type ConversationTurn } from "./traceTurns.ts"; import { readTurnJobs, turnJobView, type TurnJob } from "./traceJobs.ts"; +import { downloadFile } from "./assets.ts"; +import { conversationTraceArchive, TraceExportError } from "./traceExport.ts"; import "./assistant-trace.css"; @@ -297,14 +299,51 @@ const STATUS_KEYS: Record = { stopped: "trace.turn.status.stopped", interrupted: "trace.turn.status.interrupted", }; -function ConversationTrace({ project, target, turns }: { - project: string; target: string; turns: ConversationTurn[]; +function ConversationTrace({ project, conversationId, target, turns }: { + project: string; conversationId: string; target: string; turns: ConversationTurn[]; }) { const t = useT(); const [open, setOpen] = useState>(() => new Set()); const [loaded, setLoaded] = useState>(() => new Set()); const placed = useRef(false); const initial = initialTurn(turns, target); + const [exporting, setExporting] = useState(false); + const [exportError, setExportError] = useState(null); + const exportAbort = useRef(null); + const running = turns.some((item) => item.status === "streaming"); + useEffect(() => () => exportAbort.current?.abort(), []); + function exportMessage(error: unknown): string | null { + if (!(error instanceof TraceExportError)) return t("trace.export.failed"); + const { turn, source, status, limit } = error.detail; + const params = { turn: turn ?? "-", source: source ?? "-", status: status ?? "-", + limit: limit ? Math.round(limit / 1048576) : 0 }; + switch (error.code) { + case "aborted": return null; + case "running": return t("trace.export.error.running", params); + case "tooLarge": return t("trace.export.error.tooLarge", params); + case "tooManyFiles": return t("trace.export.error.tooManyFiles", params); + case "timeout": return t("trace.export.error.timeout", params); + case "changed": return t("trace.export.error.changed", params); + case "incomplete": return t("trace.export.error.incomplete", params); + default: return t("trace.export.error.read", params); + } + } + async function exportArchive() { + if (exporting || running || !window.confirm(t("trace.export.warning"))) return; + const controller = new AbortController(); + exportAbort.current = controller; + setExporting(true); + setExportError(null); + try { + const archive = await conversationTraceArchive(project, conversationId, { signal: controller.signal }); + downloadFile(archive, "opendirector-trace-" + conversationId + ".zip"); + } catch (error) { + setExportError(exportMessage(error)); + } finally { + exportAbort.current = null; + setExporting(false); + } + } function toggle(id: string, value: boolean) { setOpen((previous) => { @@ -327,6 +366,14 @@ function ConversationTrace({ project, target, turns }: { return ( <> +
+ + {exporting && } + {running && !exporting && {t("trace.export.blockedRunning")}} + {exportError && {exportError}} +