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

46
config.js Normal file
View File

@@ -0,0 +1,46 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
let config = null;
export function loadConfig() {
try {
const configPath = path.join(__dirname, 'config.json');
const configData = fs.readFileSync(configPath, 'utf-8');
config = JSON.parse(configData);
return config;
} catch (error) {
throw new Error(`Failed to load config.json: ${error.message}`);
}
}
export function getConfig() {
if (!config) {
loadConfig();
}
return config;
}
export function getModelById(modelId) {
const cfg = getConfig();
return cfg.models.find(m => m.id === modelId);
}
export function getEndpointByType(type) {
const cfg = getConfig();
return cfg.endpoint.find(e => e.name === type);
}
export function isDevMode() {
const cfg = getConfig();
return cfg.dev_mode === true;
}
export function getPort() {
const cfg = getConfig();
return cfg.port || 3000;
}