mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 23:56:07 +00:00
refactor(codex): simplify native tool diagnostics
This commit is contained in:
@@ -816,29 +816,24 @@ export class CodexAppServerEventProjector {
|
||||
typeof params.item.durationMs === "number" ? params.item.durationMs : undefined;
|
||||
const durationMs =
|
||||
itemDurationMs ?? (startedAt === undefined ? 0 : Math.max(0, Date.now() - startedAt));
|
||||
if (params.status === "blocked") {
|
||||
emitTrustedDiagnosticEvent({
|
||||
type: "tool.execution.blocked",
|
||||
...base,
|
||||
reason: "codex_native_tool_blocked",
|
||||
deniedReason: "codex_native_tool_blocked",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (params.status === "failed") {
|
||||
emitTrustedDiagnosticEvent({
|
||||
type: "tool.execution.error",
|
||||
...base,
|
||||
durationMs,
|
||||
errorCategory: "codex_native_tool_error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
emitTrustedDiagnosticEvent({
|
||||
type: "tool.execution.completed",
|
||||
...base,
|
||||
durationMs,
|
||||
});
|
||||
const terminalEvent =
|
||||
params.status === "blocked"
|
||||
? {
|
||||
type: "tool.execution.blocked" as const,
|
||||
reason: "codex_native_tool_blocked",
|
||||
deniedReason: "codex_native_tool_blocked",
|
||||
}
|
||||
: params.status === "failed"
|
||||
? {
|
||||
type: "tool.execution.error" as const,
|
||||
durationMs,
|
||||
errorCategory: "codex_native_tool_error",
|
||||
}
|
||||
: {
|
||||
type: "tool.execution.completed" as const,
|
||||
durationMs,
|
||||
};
|
||||
emitTrustedDiagnosticEvent({ ...base, ...terminalEvent });
|
||||
}
|
||||
|
||||
private emitToolResultSummary(item: CodexThreadItem | undefined): void {
|
||||
|
||||
@@ -21,6 +21,11 @@ type ActiveTool = {
|
||||
lastProgressAt: number;
|
||||
};
|
||||
|
||||
type DiagnosticToolStartedActivityEvent = Pick<
|
||||
Extract<DiagnosticEventPayload, { type: "tool.execution.started" }>,
|
||||
"runId" | "sessionId" | "sessionKey" | "toolName" | "toolCallId"
|
||||
>;
|
||||
|
||||
export type DiagnosticSessionActivitySnapshot = {
|
||||
activeWorkKind?: DiagnosticSessionActiveWorkKind;
|
||||
activeToolName?: string;
|
||||
@@ -158,9 +163,7 @@ function modelCallKey(event: { runId?: string; provider?: string; model?: string
|
||||
return `${event.runId ?? "unknown"}:${event.provider ?? "provider"}:${event.model ?? "model"}`;
|
||||
}
|
||||
|
||||
function recordToolStarted(
|
||||
event: Extract<DiagnosticEventPayload, { type: "tool.execution.started" }>,
|
||||
): void {
|
||||
function recordToolStarted(event: DiagnosticToolStartedActivityEvent): void {
|
||||
const activity = resolveSessionActivity({ ...event, create: true });
|
||||
if (!activity) {
|
||||
return;
|
||||
@@ -314,18 +317,7 @@ export function markDiagnosticToolStartedForTest(params: {
|
||||
toolName: string;
|
||||
toolCallId?: string;
|
||||
}): void {
|
||||
const activity = resolveSessionActivity({ ...params, create: true });
|
||||
if (!activity) {
|
||||
return;
|
||||
}
|
||||
const now = Date.now();
|
||||
activity.activeTools.set(toolKey(params), {
|
||||
toolName: params.toolName,
|
||||
toolCallId: params.toolCallId,
|
||||
startedAt: now,
|
||||
lastProgressAt: now,
|
||||
});
|
||||
touchSessionActivity(activity, `tool:${params.toolName}:started`, now);
|
||||
recordToolStarted(params);
|
||||
}
|
||||
|
||||
export function resetDiagnosticRunActivityForTest(): void {
|
||||
|
||||
Reference in New Issue
Block a user