feat(coding-agent): merge origin/main into model runtime facade

This commit is contained in:
Mario Zechner
2026-07-15 12:25:36 +02:00
119 changed files with 4275 additions and 631 deletions
@@ -0,0 +1,59 @@
import { InMemoryModelsStore, type Model } from "@earendil-works/pi-ai";
import { describe, expect, it } from "vitest";
import { AuthStorage } from "../src/core/auth-storage.ts";
import { ModelRuntime } from "../src/core/model-runtime.ts";
function model(id: string): Model<"openai-completions"> {
return {
id,
name: id,
api: "openai-completions",
provider: "extension-oauth",
baseUrl: "https://example.test/v1",
reasoning: false,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 1000,
maxTokens: 100,
};
}
describe("legacy extension OAuth modifyModels", () => {
it("applies the synchronous projection after async credential initialization", async () => {
const runtime = await ModelRuntime.create({
credentials: AuthStorage.inMemory({
"extension-oauth": {
type: "oauth",
access: "access",
refresh: "refresh",
expires: Date.now() + 60_000,
},
}),
modelsStore: new InMemoryModelsStore(),
modelsPath: null,
allowModelNetwork: false,
});
runtime.registerProvider("extension-oauth", {
baseUrl: "https://example.test/v1",
api: "openai-completions",
models: [model("base")],
oauth: {
name: "Extension OAuth",
login: async () => {
throw new Error("not used");
},
refreshToken: async (credential) => credential,
getApiKey: (credential) => credential.access,
modifyModels: (models, credential) =>
credential.access === "access" ? [...models, model("credential-model")] : models,
},
});
await runtime.refresh({ allowNetwork: false });
expect(runtime.getModel("extension-oauth", "base")).toBeDefined();
expect(runtime.getModel("extension-oauth", "credential-model")).toBeDefined();
await runtime.logout("extension-oauth");
expect(runtime.getModel("extension-oauth", "credential-model")).toBeUndefined();
});
});