feat: summarize codex stream progress events
This commit is contained in:
@@ -2143,6 +2143,7 @@ function createProgressCollector() {
|
||||
let reasoningSummary;
|
||||
let accountStatus;
|
||||
let modelVerification;
|
||||
let streamEvents;
|
||||
|
||||
const upsertArtifact = (artifact) => {
|
||||
if (!artifact || artifacts.some((item) => item.label === artifact.label)) {
|
||||
@@ -2245,11 +2246,71 @@ function createProgressCollector() {
|
||||
}
|
||||
};
|
||||
|
||||
const ensureStreamEvents = () => {
|
||||
if (!streamEvents) {
|
||||
streamEvents = {
|
||||
status: "streaming",
|
||||
agentDeltaCount: 0,
|
||||
planDeltaCount: 0,
|
||||
reasoningDeltaCount: 0,
|
||||
toolProgressCount: 0,
|
||||
commandOutputChunkCount: 0,
|
||||
terminalInteractionCount: 0,
|
||||
fileOutputChunkCount: 0,
|
||||
};
|
||||
}
|
||||
return streamEvents;
|
||||
};
|
||||
|
||||
const incrementStreamEvent = (key) => {
|
||||
const state = ensureStreamEvents();
|
||||
state.status = state.status === "completed" ? "completed" : "streaming";
|
||||
state[key] = Math.min(9999, Number(state[key] ?? 0) + 1);
|
||||
};
|
||||
|
||||
return {
|
||||
observe(message) {
|
||||
if (!message || typeof message !== "object") {
|
||||
return;
|
||||
}
|
||||
if (message.method === "item/agentMessage/delta") {
|
||||
incrementStreamEvent("agentDeltaCount");
|
||||
return;
|
||||
}
|
||||
if (message.method === "item/plan/delta") {
|
||||
incrementStreamEvent("planDeltaCount");
|
||||
return;
|
||||
}
|
||||
if (
|
||||
message.method === "item/reasoning/summaryPartAdded" ||
|
||||
message.method === "item/reasoning/summaryTextDelta" ||
|
||||
message.method === "item/reasoning/textDelta"
|
||||
) {
|
||||
incrementStreamEvent("reasoningDeltaCount");
|
||||
return;
|
||||
}
|
||||
if (message.method === "item/mcpToolCall/progress") {
|
||||
incrementStreamEvent("toolProgressCount");
|
||||
return;
|
||||
}
|
||||
if (message.method === "command/exec/outputDelta" || message.method === "item/commandExecution/outputDelta") {
|
||||
incrementStreamEvent("commandOutputChunkCount");
|
||||
return;
|
||||
}
|
||||
if (message.method === "item/commandExecution/terminalInteraction") {
|
||||
incrementStreamEvent("terminalInteractionCount");
|
||||
return;
|
||||
}
|
||||
if (message.method === "item/fileChange/outputDelta") {
|
||||
incrementStreamEvent("fileOutputChunkCount");
|
||||
return;
|
||||
}
|
||||
if (message.method === "turn/completed") {
|
||||
if (streamEvents) {
|
||||
streamEvents.status = "completed";
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (message.method === "turn/plan/updated") {
|
||||
const nextSteps = extractPlanItems(message.params)
|
||||
.map((item, index) => {
|
||||
@@ -2634,6 +2695,9 @@ function createProgressCollector() {
|
||||
if (modelVerification) {
|
||||
result.modelVerification = { ...modelVerification };
|
||||
}
|
||||
if (streamEvents) {
|
||||
result.streamEvents = { ...streamEvents };
|
||||
}
|
||||
return Object.keys(result).length > 0 ? result : undefined;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user