Initial commit: OpenAI compatible API proxy with auto token refresh

- Implemented OpenAI compatible API proxy server
- Support for Anthropic and custom OpenAI format conversion
- Automatic API key refresh with WorkOS OAuth
- SSE streaming response transformation
- Smart header management for Factory endpoints
- Chinese documentation
This commit is contained in:
1e0n
2025-10-06 02:12:01 +08:00
commit 6dca025e96
15 changed files with 2486 additions and 0 deletions

60
logger.js Normal file
View File

@@ -0,0 +1,60 @@
import { isDevMode } from './config.js';
export function logInfo(message, data = null) {
console.log(`[INFO] ${message}`);
if (data && isDevMode()) {
console.log(JSON.stringify(data, null, 2));
}
}
export function logDebug(message, data = null) {
if (isDevMode()) {
console.log(`[DEBUG] ${message}`);
if (data) {
console.log(JSON.stringify(data, null, 2));
}
}
}
export function logError(message, error = null) {
console.error(`[ERROR] ${message}`);
if (error) {
if (isDevMode()) {
console.error(error);
} else {
console.error(error.message || error);
}
}
}
export function logRequest(method, url, headers = null, body = null) {
if (isDevMode()) {
console.log(`\n${'='.repeat(80)}`);
console.log(`[REQUEST] ${method} ${url}`);
if (headers) {
console.log('[HEADERS]', JSON.stringify(headers, null, 2));
}
if (body) {
console.log('[BODY]', JSON.stringify(body, null, 2));
}
console.log('='.repeat(80) + '\n');
} else {
console.log(`[REQUEST] ${method} ${url}`);
}
}
export function logResponse(status, headers = null, body = null) {
if (isDevMode()) {
console.log(`\n${'-'.repeat(80)}`);
console.log(`[RESPONSE] Status: ${status}`);
if (headers) {
console.log('[HEADERS]', JSON.stringify(headers, null, 2));
}
if (body) {
console.log('[BODY]', JSON.stringify(body, null, 2));
}
console.log('-'.repeat(80) + '\n');
} else {
console.log(`[RESPONSE] Status: ${status}`);
}
}