feat(coding-agent): replace model registry with model runtime

Move provider auth and OAuth flows onto pi-ai Models, compose models.json and extension overlays through ModelRuntime, and retain ModelRegistry as an extension compatibility facade.
This commit is contained in:
Mario Zechner
2026-07-14 17:48:45 +02:00
parent 6731a0ba9e
commit 9993c96907
133 changed files with 5103 additions and 4340 deletions
@@ -3,9 +3,9 @@ import { type AssistantMessage, getModel, type Usage } from "@earendil-works/pi-
import { describe, expect, it } from "vitest";
import { AgentSession } from "../src/core/agent-session.ts";
import { AuthStorage } from "../src/core/auth-storage.ts";
import { ModelRegistry } from "../src/core/model-registry.ts";
import { SessionManager } from "../src/core/session-manager.ts";
import { SettingsManager } from "../src/core/settings-manager.ts";
import { createInMemoryModelRegistry, getModelRuntime } from "./model-runtime-test-utils.ts";
import { createTestResourceLoader } from "./utilities.ts";
const model = getModel("anthropic", "claude-sonnet-4-5")!;
@@ -48,11 +48,11 @@ function createUserMessage(text: string, timestamp: number) {
};
}
function createSession() {
async function createSession() {
const settingsManager = SettingsManager.inMemory();
const sessionManager = SessionManager.inMemory();
const authStorage = AuthStorage.inMemory();
authStorage.setRuntimeApiKey("anthropic", "test-key");
await authStorage.modify("anthropic", async () => ({ type: "api_key", key: "test-key" }));
const session = new AgentSession({
agent: new Agent({
getApiKey: () => "test-key",
@@ -66,7 +66,7 @@ function createSession() {
sessionManager,
settingsManager,
cwd: process.cwd(),
modelRegistry: ModelRegistry.inMemory(authStorage),
modelRuntime: getModelRuntime(await createInMemoryModelRegistry(authStorage)),
resourceLoader: createTestResourceLoader(),
});
@@ -78,8 +78,8 @@ function syncAgentMessages(session: AgentSession, sessionManager: SessionManager
}
describe("AgentSession.getSessionStats", () => {
it("exposes the current context usage alongside token totals", () => {
const { session, sessionManager } = createSession();
it("exposes the current context usage alongside token totals", async () => {
const { session, sessionManager } = await createSession();
try {
sessionManager.appendMessage(createUserMessage("hello", 1));
@@ -96,8 +96,8 @@ describe("AgentSession.getSessionStats", () => {
}
});
it("reports unknown current context usage immediately after compaction", () => {
const { session, sessionManager } = createSession();
it("reports unknown current context usage immediately after compaction", async () => {
const { session, sessionManager } = await createSession();
try {
sessionManager.appendMessage(createUserMessage("first", 1));
@@ -119,8 +119,8 @@ describe("AgentSession.getSessionStats", () => {
}
});
it("uses post-compaction usage for current context instead of stale kept usage", () => {
const { session, sessionManager } = createSession();
it("uses post-compaction usage for current context instead of stale kept usage", async () => {
const { session, sessionManager } = await createSession();
try {
sessionManager.appendMessage(createUserMessage("first", 1));
@@ -143,8 +143,8 @@ describe("AgentSession.getSessionStats", () => {
}
});
it("ignores zero-usage messages when checking for post-compaction context usage", () => {
const { session, sessionManager } = createSession();
it("ignores zero-usage messages when checking for post-compaction context usage", async () => {
const { session, sessionManager } = await createSession();
try {
sessionManager.appendMessage(createUserMessage("first", 1));