fix trace view message overlay
This commit is contained in:
@@ -754,6 +754,33 @@ function coalesceTranscriptMessageFragments(entries: TranscriptLine[]): Transcri
|
||||
return merged;
|
||||
}
|
||||
|
||||
function traceMessageOverlayKey(line: TranscriptLine): string | null {
|
||||
return messageFragmentMergeKey(line);
|
||||
}
|
||||
|
||||
function traceMessageOverlayCandidate(line: TranscriptLine): boolean {
|
||||
return traceMessageOverlayKey(line) !== null && String(line.bodyPreview || "").trim().length > 0;
|
||||
}
|
||||
|
||||
function overlayTraceMessagesFromRawTranscript(oaLines: TranscriptLine[], rawLines: TranscriptLine[]): TranscriptLine[] {
|
||||
const rawMessages = rawLines.filter(traceMessageOverlayCandidate);
|
||||
if (rawMessages.length === 0) return oaLines;
|
||||
const messageSeqs = new Set<number>();
|
||||
for (const line of oaLines) {
|
||||
if (traceMessageOverlayKey(line) === null) continue;
|
||||
for (const seq of Array.isArray(line.rawSeqs) && line.rawSeqs.length > 0 ? line.rawSeqs : [line.seq]) {
|
||||
if (Number.isFinite(Number(seq))) messageSeqs.add(Number(seq));
|
||||
}
|
||||
}
|
||||
const result = oaLines.filter((line) => traceMessageOverlayKey(line) === null);
|
||||
for (const raw of rawMessages) {
|
||||
const seqs = Array.isArray(raw.rawSeqs) && raw.rawSeqs.length > 0 ? raw.rawSeqs : [raw.seq];
|
||||
if (!seqs.some((seq) => messageSeqs.has(Number(seq)))) continue;
|
||||
result.push(raw);
|
||||
}
|
||||
return coalesceTranscriptMessageFragments(result);
|
||||
}
|
||||
|
||||
|
||||
function commandKind(command: string): TranscriptKind {
|
||||
if (/\b(apply_patch|git apply|cat >|tee .*<<|sed -i|python3? .*write_text)\b/u.test(command)) return "edited";
|
||||
@@ -1836,9 +1863,12 @@ function oaTraceStepToTranscriptLine(step: OaTraceStepSummary): TranscriptLine {
|
||||
};
|
||||
}
|
||||
|
||||
async function oaTraceTranscriptForTask(taskId: string, attemptIndex: number | null): Promise<TranscriptLine[]> {
|
||||
async function oaTraceTranscriptForTask(task: QueueTask, attemptIndex: number | null): Promise<TranscriptLine[]> {
|
||||
const taskId = task.id;
|
||||
const steps = await readOaTraceStepsForTask(taskId, attemptIndex);
|
||||
return coalesceTranscriptMessageFragments(steps.map(oaTraceStepToTranscriptLine).filter(traceLineVisibleInTraceView));
|
||||
const oaLines = coalesceTranscriptMessageFragments(steps.map(oaTraceStepToTranscriptLine).filter(traceLineVisibleInTraceView));
|
||||
const rawLines = fullTranscript(task).filter(traceLineVisibleInTraceView);
|
||||
return overlayTraceMessagesFromRawTranscript(oaLines, rawLines);
|
||||
}
|
||||
|
||||
function mergeTraceWindowLines(left: TranscriptLine[], right: TranscriptLine[]): TranscriptLine[] {
|
||||
@@ -2243,7 +2273,7 @@ async function taskTraceStepsResponse(task: QueueTask, url: URL): Promise<Respon
|
||||
const limit = ctx().parseLimit(url);
|
||||
const attemptIndex = ctx().parseSeqParam(url, "attempt", null);
|
||||
const agentPort = codeAgentPortForModel(task.model);
|
||||
const transcript = await oaTraceTranscriptForTask(task.id, attemptIndex);
|
||||
const transcript = await oaTraceTranscriptForTask(task, attemptIndex);
|
||||
const page = ctx().pageBySeq(transcript, url, limit);
|
||||
return ctx().jsonResponse({
|
||||
ok: true,
|
||||
@@ -2282,7 +2312,7 @@ async function taskTraceStepDetailResponse(task: QueueTask, url: URL): Promise<R
|
||||
const seq = Number(url.searchParams.get("seq"));
|
||||
if (!Number.isFinite(seq)) return ctx().jsonResponse({ ok: false, error: "seq is required" }, 400);
|
||||
const agentPort = codeAgentPortForModel(task.model);
|
||||
const transcript = await oaTraceTranscriptForTask(task.id, null);
|
||||
const transcript = await oaTraceTranscriptForTask(task, null);
|
||||
const line = transcript.find((item) => Number(item.seq) === seq || item.rawSeqs.includes(seq));
|
||||
if (line === undefined) return ctx().jsonResponse({ ok: false, error: "trace step not found", seq }, 404);
|
||||
return ctx().jsonResponse({
|
||||
|
||||
Reference in New Issue
Block a user