mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
fix(cline): use workos auth token shape
Made-with: Cursor
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { BaseExecutor } from "./base.js";
|
import { BaseExecutor } from "./base.js";
|
||||||
import { PROVIDERS, OAUTH_ENDPOINTS } from "../config/constants.js";
|
import { PROVIDERS, OAUTH_ENDPOINTS } from "../config/constants.js";
|
||||||
|
import { buildClineHeaders } from "../../src/shared/utils/clineAuth.js";
|
||||||
|
|
||||||
export class DefaultExecutor extends BaseExecutor {
|
export class DefaultExecutor extends BaseExecutor {
|
||||||
constructor(provider) {
|
constructor(provider) {
|
||||||
@@ -65,6 +66,8 @@ export class DefaultExecutor extends BaseExecutor {
|
|||||||
if (credentials.providerSpecificData?.orgId) {
|
if (credentials.providerSpecificData?.orgId) {
|
||||||
headers["X-Kilocode-OrganizationID"] = credentials.providerSpecificData.orgId;
|
headers["X-Kilocode-OrganizationID"] = credentials.providerSpecificData.orgId;
|
||||||
}
|
}
|
||||||
|
} else if (this.provider === "cline") {
|
||||||
|
Object.assign(headers, buildClineHeaders(credentials.apiKey || credentials.accessToken));
|
||||||
} else {
|
} else {
|
||||||
headers["Authorization"] = `Bearer ${credentials.apiKey || credentials.accessToken}`;
|
headers["Authorization"] = `Bearer ${credentials.apiKey || credentials.accessToken}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { PROVIDERS } from "../config/constants.js";
|
import { PROVIDERS } from "../config/constants.js";
|
||||||
|
import { buildClineHeaders } from "../../src/shared/utils/clineAuth.js";
|
||||||
|
|
||||||
const OPENAI_COMPATIBLE_PREFIX = "openai-compatible-";
|
const OPENAI_COMPATIBLE_PREFIX = "openai-compatible-";
|
||||||
const OPENAI_COMPATIBLE_DEFAULTS = {
|
const OPENAI_COMPATIBLE_DEFAULTS = {
|
||||||
@@ -285,6 +286,10 @@ export function buildProviderHeaders(provider, credentials, stream = true, body
|
|||||||
case "openrouter":
|
case "openrouter":
|
||||||
headers["Authorization"] = `Bearer ${credentials.apiKey || credentials.accessToken}`;
|
headers["Authorization"] = `Bearer ${credentials.apiKey || credentials.accessToken}`;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "cline":
|
||||||
|
Object.assign(headers, buildClineHeaders(credentials.apiKey || credentials.accessToken));
|
||||||
|
break;
|
||||||
|
|
||||||
case "glm":
|
case "glm":
|
||||||
case "kimi":
|
case "kimi":
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
CLINE_CONFIG,
|
CLINE_CONFIG,
|
||||||
KILOCODE_CONFIG,
|
KILOCODE_CONFIG,
|
||||||
} from "@/lib/oauth/constants/oauth";
|
} from "@/lib/oauth/constants/oauth";
|
||||||
|
import { buildClineHeaders } from "@/shared/utils/clineAuth";
|
||||||
|
|
||||||
// OAuth provider test endpoints
|
// OAuth provider test endpoints
|
||||||
const OAUTH_TEST_CONFIG = {
|
const OAUTH_TEST_CONFIG = {
|
||||||
@@ -58,19 +59,10 @@ const OAUTH_TEST_CONFIG = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function probeClineAccessToken(accessToken) {
|
async function probeClineAccessToken(accessToken) {
|
||||||
const res = await fetch("https://api.cline.bot/api/v1/chat/completions", {
|
const res = await fetch("https://api.cline.bot/api/v1/users/me", {
|
||||||
method: "POST",
|
method: "GET",
|
||||||
headers: {
|
headers: buildClineHeaders(accessToken, {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Accept: "application/json",
|
||||||
"Content-Type": "application/json",
|
|
||||||
"HTTP-Referer": "https://cline.bot",
|
|
||||||
"X-Title": "Cline",
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
model: "cl/anthropic/claude-sonnet-4-20250514",
|
|
||||||
messages: [{ role: "user", content: "test" }],
|
|
||||||
max_tokens: 1,
|
|
||||||
stream: false,
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import pkg from "../../../package.json" with { type: "json" };
|
||||||
|
|
||||||
|
const APP_VERSION = pkg.version || "0.0.0";
|
||||||
|
|
||||||
|
export function getClineAccessToken(token) {
|
||||||
|
if (typeof token !== "string") return "";
|
||||||
|
const trimmed = token.trim();
|
||||||
|
if (!trimmed) return "";
|
||||||
|
return trimmed.startsWith("workos:") ? trimmed : `workos:${trimmed}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getClineAuthorizationHeader(token) {
|
||||||
|
const accessToken = getClineAccessToken(token);
|
||||||
|
return accessToken ? `Bearer ${accessToken}` : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildClineHeaders(token, extraHeaders = {}) {
|
||||||
|
const authorization = getClineAuthorizationHeader(token);
|
||||||
|
const headers = {
|
||||||
|
"HTTP-Referer": "https://cline.bot",
|
||||||
|
"X-Title": "Cline",
|
||||||
|
"User-Agent": `9Router/${APP_VERSION}`,
|
||||||
|
"X-PLATFORM": process.platform || "unknown",
|
||||||
|
"X-PLATFORM-VERSION": process.version || "unknown",
|
||||||
|
"X-CLIENT-TYPE": "9router",
|
||||||
|
"X-CLIENT-VERSION": APP_VERSION,
|
||||||
|
"X-CORE-VERSION": APP_VERSION,
|
||||||
|
"X-IS-MULTIROOT": "false",
|
||||||
|
...extraHeaders,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (authorization) {
|
||||||
|
headers.Authorization = authorization;
|
||||||
|
}
|
||||||
|
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user