feat: add agent runtime info tracking with model detection from rollout files

This commit is contained in:
Mohamed Boudra
2025-12-21 23:16:49 +07:00
parent a70842d9ef
commit abe3a42478
23 changed files with 1243 additions and 159 deletions
@@ -33,6 +33,7 @@ import {
HOME_NAVIGATION_KEY,
startNavigationTiming,
} from "@/utils/navigation-timing";
import { extractAgentModel } from "@/utils/extract-agent-model";
const DROPDOWN_WIDTH = 220;
const EMPTY_STREAM_ITEMS: StreamItem[] = [];
@@ -44,47 +45,6 @@ type GitRepoInfoResponseMessage = Extract<
type BranchStatus = "idle" | "loading" | "ready" | "error";
function extractAgentModel(agent?: Agent | null): string | null {
if (!agent) {
return null;
}
const directModel = typeof agent.model === "string" ? agent.model.trim() : "";
if (directModel.length > 0) {
return directModel;
}
const metadata = agent.persistence?.metadata;
if (!metadata || typeof metadata !== "object") {
return null;
}
const persistedModel = (metadata as Record<string, unknown>).model;
if (typeof persistedModel === "string" && persistedModel.trim().length > 0) {
return persistedModel.trim();
}
const extra = (metadata as Record<string, unknown>).extra;
if (!extra || typeof extra !== "object") {
return null;
}
const getModelFrom = (source: unknown) => {
if (!source || typeof source !== "object") {
return null;
}
const candidate = (source as Record<string, unknown>).model;
return typeof candidate === "string" && candidate.trim().length > 0
? candidate.trim()
: null;
};
return (
getModelFrom((extra as Record<string, unknown>).codex) ??
getModelFrom((extra as Record<string, unknown>).claude)
);
}
export default function AgentScreen() {
const router = useRouter();
const { serverId, agentId } = useLocalSearchParams<{ serverId: string; agentId: string }>();
@@ -130,6 +130,7 @@ function normalizeAgentSnapshot(snapshot: AgentSnapshotPayload, serverId: string
availableModes: snapshot.availableModes ?? [],
pendingPermissions: snapshot.pendingPermissions ?? [],
persistence: snapshot.persistence ?? null,
runtimeInfo: snapshot.runtimeInfo,
lastUsage: snapshot.lastUsage,
lastError: snapshot.lastError ?? null,
title: snapshot.title ?? null,
+9
View File
@@ -74,6 +74,14 @@ export type ProviderModelState = {
isLoading: boolean;
};
export interface AgentRuntimeInfo {
provider: AgentProvider;
sessionId: string | null;
model?: string | null;
modeId?: string | null;
extra?: Record<string, unknown>;
}
export interface Agent {
serverId: string;
id: string;
@@ -89,6 +97,7 @@ export interface Agent {
availableModes: AgentMode[];
pendingPermissions: any[];
persistence: AgentPersistenceHandle | null;
runtimeInfo?: AgentRuntimeInfo;
lastUsage?: AgentUsage;
lastError?: string | null;
title: string | null;
@@ -0,0 +1,22 @@
import { describe, expect, it } from "vitest";
import type { Agent } from "@/stores/session-store";
import { extractAgentModel } from "./extract-agent-model";
describe("extractAgentModel", () => {
it("returns runtime model when present", () => {
const agent = {
runtimeInfo: { model: "gpt-5.2-codex" },
} as Partial<Agent> as Agent;
expect(extractAgentModel(agent)).toBe("gpt-5.2-codex");
});
it("returns null when runtime model missing even if config model is set", () => {
const agent = {
model: "gpt-5.1-codex",
runtimeInfo: {},
} as Partial<Agent> as Agent;
expect(extractAgentModel(agent)).toBeNull();
});
});
@@ -0,0 +1,9 @@
import type { Agent } from "@/stores/session-store";
export function extractAgentModel(agent?: Agent | null): string | null {
if (!agent) return null;
const runtimeModel = agent.runtimeInfo?.model;
return typeof runtimeModel === "string" && runtimeModel.trim().length > 0
? runtimeModel.trim()
: null;
}