feat: surface codex runtime status

This commit is contained in:
AI Bot
2026-05-31 03:59:53 +08:00
parent cee1e7938e
commit 591638f35f
12 changed files with 544 additions and 6 deletions

View File

@@ -159,6 +159,34 @@ export interface ExecutionProgressRealtime {
closeReason?: string;
}
export interface ExecutionProgressModelRoute {
fromModel: string;
toModel: string;
reason?: string;
}
export interface ExecutionProgressTokenUsage {
totalTokens: number;
inputTokens?: number;
cachedInputTokens?: number;
outputTokens?: number;
reasoningOutputTokens?: number;
modelContextWindow?: number;
contextPercent?: number;
}
export interface ExecutionProgressMcpServer {
name: string;
status?: string;
error?: string;
}
export interface ExecutionProgressRemoteControl {
status: string;
serverName?: string;
environmentId?: string;
}
export interface ExecutionProgressSnapshot {
taskId: string;
projectId: string;
@@ -179,6 +207,10 @@ export interface ExecutionProgressSnapshot {
fileChanges?: ExecutionProgressFileChange[];
threadStatus?: ExecutionProgressThreadStatus;
realtime?: ExecutionProgressRealtime;
modelRoute?: ExecutionProgressModelRoute;
tokenUsage?: ExecutionProgressTokenUsage;
mcpServers?: ExecutionProgressMcpServer[];
remoteControl?: ExecutionProgressRemoteControl;
updatedAt: string;
}
@@ -192,6 +224,10 @@ export interface ExecutionProgressInput {
fileChanges?: Array<Partial<ExecutionProgressFileChange> & { path?: string }>;
threadStatus?: Partial<ExecutionProgressThreadStatus>;
realtime?: Partial<ExecutionProgressRealtime>;
modelRoute?: Partial<ExecutionProgressModelRoute>;
tokenUsage?: Partial<ExecutionProgressTokenUsage>;
mcpServers?: Array<Partial<ExecutionProgressMcpServer> & { name?: string }>;
remoteControl?: Partial<ExecutionProgressRemoteControl> & { installationId?: unknown };
}
export interface ForwardSource {
@@ -3865,6 +3901,10 @@ function normalizeExecutionProgressSnapshot(raw: Partial<ExecutionProgressSnapsh
fileChanges: nativeRemoteControl ? undefined : normalizeExecutionProgressFileChanges(raw.fileChanges),
threadStatus: nativeRemoteControl ? undefined : normalizeExecutionProgressThreadStatus(raw.threadStatus),
realtime: nativeRemoteControl ? undefined : normalizeExecutionProgressRealtime(raw.realtime),
modelRoute: nativeRemoteControl ? undefined : normalizeExecutionProgressModelRoute(raw.modelRoute),
tokenUsage: nativeRemoteControl ? undefined : normalizeExecutionProgressTokenUsage(raw.tokenUsage),
mcpServers: nativeRemoteControl ? undefined : normalizeExecutionProgressMcpServers(raw.mcpServers),
remoteControl: nativeRemoteControl ? undefined : normalizeExecutionProgressRemoteControl(raw.remoteControl),
updatedAt: raw.updatedAt ?? nowIso(),
};
}
@@ -5445,6 +5485,86 @@ function normalizeExecutionProgressRealtime(
};
}
function normalizeExecutionProgressModelRoute(
input?: ExecutionProgressInput["modelRoute"],
): ExecutionProgressModelRoute | undefined {
if (!input) {
return undefined;
}
const fromModel = safeExecutionProgressText(input.fromModel);
const toModel = safeExecutionProgressText(input.toModel);
if (!fromModel || !toModel) {
return undefined;
}
return {
fromModel,
toModel,
reason: safeExecutionProgressText(input.reason) || undefined,
};
}
function normalizeExecutionProgressTokenUsage(
input?: ExecutionProgressInput["tokenUsage"],
): ExecutionProgressTokenUsage | undefined {
if (!input) {
return undefined;
}
const totalTokens = normalizeOptionalNumber(input.totalTokens);
if (totalTokens === undefined) {
return undefined;
}
const modelContextWindow = normalizeOptionalNumber(input.modelContextWindow);
const contextPercent =
input.contextPercent !== undefined
? Math.max(0, Math.min(100, normalizeOptionalNumber(input.contextPercent) ?? 0))
: modelContextWindow && modelContextWindow > 0
? Math.max(0, Math.min(100, Math.ceil((totalTokens / modelContextWindow) * 100)))
: undefined;
return {
totalTokens,
inputTokens: normalizeOptionalNumber(input.inputTokens),
cachedInputTokens: normalizeOptionalNumber(input.cachedInputTokens),
outputTokens: normalizeOptionalNumber(input.outputTokens),
reasoningOutputTokens: normalizeOptionalNumber(input.reasoningOutputTokens),
modelContextWindow,
contextPercent,
};
}
function normalizeExecutionProgressMcpServers(input?: ExecutionProgressInput["mcpServers"]) {
return (input ?? [])
.map((server): ExecutionProgressMcpServer | null => {
const name = safeExecutionProgressText(server?.name);
if (!name) {
return null;
}
return {
name,
status: safeExecutionProgressText(server?.status) || undefined,
error: safeExecutionProgressText(server?.error) || undefined,
};
})
.filter((server): server is ExecutionProgressMcpServer => Boolean(server))
.slice(0, 6);
}
function normalizeExecutionProgressRemoteControl(
input?: ExecutionProgressInput["remoteControl"],
): ExecutionProgressRemoteControl | undefined {
if (!input) {
return undefined;
}
const status = safeExecutionProgressText(input.status);
if (!status) {
return undefined;
}
return {
status,
serverName: safeExecutionProgressText(input.serverName) || undefined,
environmentId: safeExecutionProgressText(input.environmentId) || undefined,
};
}
function defaultExecutionProgressStepTexts(task: Pick<MasterAgentTask, "taskType" | "relayViaMasterAgent">) {
if (task.taskType === "browser_control") {
return [
@@ -5582,6 +5702,10 @@ function buildExecutionProgressSnapshot(
fileChanges: nativeRemoteControl ? undefined : normalizeExecutionProgressFileChanges(input?.fileChanges),
threadStatus: nativeRemoteControl ? undefined : normalizeExecutionProgressThreadStatus(input?.threadStatus),
realtime: nativeRemoteControl ? undefined : normalizeExecutionProgressRealtime(input?.realtime),
modelRoute: nativeRemoteControl ? undefined : normalizeExecutionProgressModelRoute(input?.modelRoute),
tokenUsage: nativeRemoteControl ? undefined : normalizeExecutionProgressTokenUsage(input?.tokenUsage),
mcpServers: nativeRemoteControl ? undefined : normalizeExecutionProgressMcpServers(input?.mcpServers),
remoteControl: nativeRemoteControl ? undefined : normalizeExecutionProgressRemoteControl(input?.remoteControl),
updatedAt: nowIso(),
};
}