feat(ai): add OpenRouter OAuth support (#6927)

Closes #6814
This commit is contained in:
Saryev Rustam
2026-07-22 16:48:39 +03:00
committed by GitHub
parent fe42ba5b38
commit 7b52cef2e6
9 changed files with 522 additions and 6 deletions
+7
View File
@@ -3,6 +3,7 @@ import { InMemoryCredentialStore } from "../src/auth/credential-store.ts";
import { anthropicOAuth } from "../src/auth/oauth/anthropic.ts";
import { githubCopilotOAuth } from "../src/auth/oauth/github-copilot.ts";
import { openaiCodexOAuth } from "../src/auth/oauth/openai-codex.ts";
import { openRouterOAuth } from "../src/auth/oauth/openrouter.ts";
import { xaiOAuth } from "../src/auth/oauth/xai.ts";
import { createModels } from "../src/models.ts";
import * as extensionOAuthCompatibility from "../src/oauth.ts";
@@ -33,6 +34,12 @@ describe.sequential("OAuthAuth adapters", () => {
expect(auth).toEqual({ apiKey: "token" });
});
it("openrouter derives the api key and keeps the permanent credential on refresh", async () => {
const credential = { type: "oauth" as const, access: "token", refresh: "", expires: Number.MAX_SAFE_INTEGER };
expect(await openRouterOAuth.toAuth(credential)).toEqual({ apiKey: "token" });
expect(await openRouterOAuth.refresh(credential)).toBe(credential);
});
it("xAI toAuth derives the api key from the access token", async () => {
const auth = await xaiOAuth.toAuth({ type: "oauth", access: "token", refresh: "r", expires: 0 });
expect(auth).toEqual({ apiKey: "token" });