refactor(open-sse): remove reverse coupling open-sse -> src (E2)
Move clineAuth into open-sse/shared (src re-exports back). Add standalone open-sse/shared/machineId for codex session hashing (no @/lib/dataDir). sttCore receives sttConfig via param instead of importing AI_PROVIDERS. No behavior change; gate: no regression (26 known-fails unchanged). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
8f0a9ff9d4
commit
87fe069e9e
9 changed files with 65 additions and 46 deletions
|
|
@ -9,7 +9,7 @@ import {
|
||||||
import { normalizeResponsesInput } from "../translator/helpers/responsesApiHelper.js";
|
import { normalizeResponsesInput } from "../translator/helpers/responsesApiHelper.js";
|
||||||
import { fetchImageAsBase64 } from "../translator/helpers/imageHelper.js";
|
import { fetchImageAsBase64 } from "../translator/helpers/imageHelper.js";
|
||||||
import { getModelUpstreamId } from "../config/providerModels.js";
|
import { getModelUpstreamId } from "../config/providerModels.js";
|
||||||
import { getConsistentMachineId } from "../../src/shared/utils/machineId.js";
|
import { getConsistentMachineId } from "../shared/machineId.js";
|
||||||
import { DEFAULT_RETRY_CONFIG, resolveRetryEntry } from "../config/runtimeConfig.js";
|
import { DEFAULT_RETRY_CONFIG, resolveRetryEntry } from "../config/runtimeConfig.js";
|
||||||
import { dbg } from "../utils/debugLog.js";
|
import { dbg } from "../utils/debugLog.js";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { BaseExecutor } from "./base.js";
|
import { BaseExecutor } from "./base.js";
|
||||||
import { PROVIDERS } from "../config/providers.js";
|
import { PROVIDERS } from "../config/providers.js";
|
||||||
import { OAUTH_ENDPOINTS, buildKimiHeaders } from "../config/appConstants.js";
|
import { OAUTH_ENDPOINTS, buildKimiHeaders } from "../config/appConstants.js";
|
||||||
import { buildClineHeaders } from "../../src/shared/utils/clineAuth.js";
|
import { buildClineHeaders } from "../shared/clineAuth.js";
|
||||||
import { getCachedClaudeHeaders } from "../utils/claudeHeaderCache.js";
|
import { getCachedClaudeHeaders } from "../utils/claudeHeaderCache.js";
|
||||||
import { proxyAwareFetch } from "../utils/proxyFetch.js";
|
import { proxyAwareFetch } from "../utils/proxyFetch.js";
|
||||||
import { injectReasoningContent } from "../utils/reasoningContentInjector.js";
|
import { injectReasoningContent } from "../utils/reasoningContentInjector.js";
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { Buffer } from "node:buffer";
|
import { Buffer } from "node:buffer";
|
||||||
import { createErrorResult } from "../utils/error.js";
|
import { createErrorResult } from "../utils/error.js";
|
||||||
import { HTTP_STATUS } from "../config/runtimeConfig.js";
|
import { HTTP_STATUS } from "../config/runtimeConfig.js";
|
||||||
import { AI_PROVIDERS } from "../../src/shared/constants/providers.js";
|
|
||||||
|
|
||||||
// Build auth headers from sttConfig + token
|
// Build auth headers from sttConfig + token
|
||||||
function buildAuthHeaders(cfg, token) {
|
function buildAuthHeaders(cfg, token) {
|
||||||
|
|
@ -167,11 +166,11 @@ function jsonResponse(obj) {
|
||||||
* STT core handler — dispatch by sttConfig.format.
|
* STT core handler — dispatch by sttConfig.format.
|
||||||
* @returns {Promise<{success, response, status?, error?}>}
|
* @returns {Promise<{success, response, status?, error?}>}
|
||||||
*/
|
*/
|
||||||
export async function handleSttCore({ provider, model, formData, credentials }) {
|
export async function handleSttCore({ provider, model, formData, credentials, sttConfig }) {
|
||||||
const file = formData.get("file");
|
const file = formData.get("file");
|
||||||
if (!file) return createErrorResult(HTTP_STATUS.BAD_REQUEST, "Missing required field: file");
|
if (!file) return createErrorResult(HTTP_STATUS.BAD_REQUEST, "Missing required field: file");
|
||||||
|
|
||||||
const cfg = AI_PROVIDERS[provider]?.sttConfig;
|
const cfg = sttConfig;
|
||||||
if (!cfg) return createErrorResult(HTTP_STATUS.BAD_REQUEST, `Provider '${provider}' does not support STT`);
|
if (!cfg) return createErrorResult(HTTP_STATUS.BAD_REQUEST, `Provider '${provider}' does not support STT`);
|
||||||
|
|
||||||
const token = cfg.authType === "none" ? null : (credentials?.apiKey || credentials?.accessToken);
|
const token = cfg.authType === "none" ? null : (credentials?.apiKey || credentials?.accessToken);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { PROVIDERS } from "../config/providers.js";
|
import { PROVIDERS } from "../config/providers.js";
|
||||||
import { buildClineHeaders } from "../../src/shared/utils/clineAuth.js";
|
import { buildClineHeaders } from "../shared/clineAuth.js";
|
||||||
|
|
||||||
const OPENAI_COMPATIBLE_PREFIX = "openai-compatible-";
|
const OPENAI_COMPATIBLE_PREFIX = "openai-compatible-";
|
||||||
const OPENAI_COMPATIBLE_DEFAULTS = {
|
const OPENAI_COMPATIBLE_DEFAULTS = {
|
||||||
|
|
|
||||||
37
open-sse/shared/clineAuth.js
Normal file
37
open-sse/shared/clineAuth.js
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
19
open-sse/shared/machineId.js
Normal file
19
open-sse/shared/machineId.js
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { machineIdSync } from "node-machine-id";
|
||||||
|
import crypto from "node:crypto";
|
||||||
|
|
||||||
|
let cachedRawId = null;
|
||||||
|
|
||||||
|
function loadRawMachineId() {
|
||||||
|
if (cachedRawId) return cachedRawId;
|
||||||
|
try {
|
||||||
|
cachedRawId = machineIdSync();
|
||||||
|
} catch {
|
||||||
|
cachedRawId = crypto.randomUUID();
|
||||||
|
}
|
||||||
|
return cachedRawId;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getConsistentMachineId(salt = "endpoint-proxy-salt") {
|
||||||
|
const rawId = loadRawMachineId();
|
||||||
|
return crypto.createHash("sha256").update(rawId + salt).digest("hex").substring(0, 16);
|
||||||
|
}
|
||||||
|
|
@ -1,37 +1 @@
|
||||||
import pkg from "../../../package.json" with { type: "json" };
|
export * from "../../../open-sse/shared/clineAuth.js";
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ export async function handleStt(request) {
|
||||||
|
|
||||||
// noAuth providers
|
// noAuth providers
|
||||||
if (!CREDENTIALED_PROVIDERS.has(provider)) {
|
if (!CREDENTIALED_PROVIDERS.has(provider)) {
|
||||||
const result = await handleSttCore({ provider, model, formData });
|
const result = await handleSttCore({ provider, model, formData, sttConfig: AI_PROVIDERS[provider]?.sttConfig });
|
||||||
if (result.success) return result.response;
|
if (result.success) return result.response;
|
||||||
return errorResponse(result.status || HTTP_STATUS.BAD_GATEWAY, result.error || "STT failed");
|
return errorResponse(result.status || HTTP_STATUS.BAD_GATEWAY, result.error || "STT failed");
|
||||||
}
|
}
|
||||||
|
|
@ -72,7 +72,7 @@ export async function handleStt(request) {
|
||||||
|
|
||||||
log.info("AUTH", `\x1b[32mUsing ${provider} account: ${credentials.connectionName}\x1b[0m`);
|
log.info("AUTH", `\x1b[32mUsing ${provider} account: ${credentials.connectionName}\x1b[0m`);
|
||||||
|
|
||||||
const result = await handleSttCore({ provider, model, formData, credentials });
|
const result = await handleSttCore({ provider, model, formData, credentials, sttConfig: AI_PROVIDERS[provider]?.sttConfig });
|
||||||
|
|
||||||
if (result.success) return result.response;
|
if (result.success) return result.response;
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue