mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
feat(kimchi): add Kimchi OAuth provider support
Add Kimchi as a browser-token OAuth provider routed through its OpenAI-compatible gateway. Discover live models for /v1/models and provider models, normalize Claude-compatible requests, and wire up provider connection tests. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
committed by
decolua
co-authored by
Cursor
parent
2d94fffe3b
commit
8a664d619d
@@ -108,6 +108,9 @@ export const GITLAB_CONFIG = { ...PROVIDER_OAUTH["gitlab"] };
|
||||
// CodeBuddy (Tencent) OAuth Configuration (Browser OAuth Polling Flow)
|
||||
export const CODEBUDDY_CONFIG = { ...PROVIDER_OAUTH["codebuddy-cn"] };
|
||||
|
||||
// Kimchi OAuth Configuration (Browser token callback flow)
|
||||
export const KIMCHI_CONFIG = { ...PROVIDER_OAUTH["kimchi"] };
|
||||
|
||||
// OAuth timeout (5 minutes)
|
||||
export const OAUTH_TIMEOUT = 300000;
|
||||
|
||||
@@ -129,4 +132,5 @@ export const PROVIDERS = {
|
||||
CLINE: "cline",
|
||||
GITLAB: "gitlab",
|
||||
CODEBUDDY: "codebuddy-cn",
|
||||
KIMCHI: "kimchi",
|
||||
};
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
CLINE_CONFIG,
|
||||
GITLAB_CONFIG,
|
||||
CODEBUDDY_CONFIG,
|
||||
KIMCHI_CONFIG,
|
||||
getOAuthClientMetadata,
|
||||
} from "./constants/oauth";
|
||||
import { XAI_CONFIG, XAI_PKCE_VERIFIER_BYTES } from "./constants/xai";
|
||||
@@ -1252,6 +1253,78 @@ const PROVIDERS = {
|
||||
providerSpecificData: {},
|
||||
}),
|
||||
},
|
||||
|
||||
kimchi: {
|
||||
config: KIMCHI_CONFIG,
|
||||
flowType: "browser_token",
|
||||
buildAuthUrl: (config, redirectUri, state) => {
|
||||
const baseUrl = (config.webAppUrl || "https://app.kimchi.dev").replace(/\/+$/, "");
|
||||
const params = new URLSearchParams({
|
||||
callback: redirectUri,
|
||||
state,
|
||||
});
|
||||
return `${baseUrl}/cli-auth?${params.toString()}`;
|
||||
},
|
||||
exchangeToken: async (config, token) => {
|
||||
const accessToken = String(token || "").trim();
|
||||
if (!accessToken) {
|
||||
throw new Error("Missing Kimchi token");
|
||||
}
|
||||
|
||||
const validationUrl = config.validationUrl || "https://api.cast.ai/v1/llm/openai/supported-providers";
|
||||
const validationRes = await fetch(validationUrl, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
});
|
||||
if (!validationRes.ok) {
|
||||
throw new Error(`Kimchi token validation failed: ${validationRes.status}`);
|
||||
}
|
||||
|
||||
let userInfo = {};
|
||||
if (config.userInfoUrl) {
|
||||
try {
|
||||
const userRes = await fetch(config.userInfoUrl, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
});
|
||||
if (userRes.ok) {
|
||||
userInfo = await userRes.json();
|
||||
}
|
||||
} catch {
|
||||
userInfo = {};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
access_token: accessToken,
|
||||
token_type: "Bearer",
|
||||
_kimchiUser: userInfo,
|
||||
};
|
||||
},
|
||||
mapTokens: (tokens) => {
|
||||
const user = tokens._kimchiUser || {};
|
||||
const userId = user.id ? String(user.id) : "";
|
||||
const username = user.username || "";
|
||||
const email = user.email || (userId ? `kimchi-user-${userId}` : null);
|
||||
return {
|
||||
accessToken: tokens.access_token,
|
||||
refreshToken: null,
|
||||
email,
|
||||
displayName: user.name || username || null,
|
||||
providerSpecificData: {
|
||||
authMethod: "browser_token",
|
||||
userId,
|
||||
username,
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user