mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 20:17:45 +00:00
Issue #1161. Sweeps 127 files to import from src/config/config-loader-facade.ts instead of unified-config-loader or utils/config-manager directly. WRITE callers (32 files): replaced raw saveUnifiedConfig / mutateUnifiedConfig / updateUnifiedConfig calls with the facade's cache-coherent wrappers saveConfig / mutateConfig / updateConfig. This fixes a latent stale-cache window where direct writes through the underlying loader bypassed the facade's memoization. READ callers (95 files): mechanical import-path migration only — function names unchanged because the facade re-exports them. No behavior change. Also updated: - tests/unit/utils/browser/browser-setup.test.ts (DI interface rename) - src/management/checks/image-analysis-check.ts (dynamic import rename) - src/web-server/health-service.ts (dynamic require rename) - src/ccs.ts (path prefix fix from sweep script) After sweep: zero raw write callers remain outside src/config/. Direct imports of config-manager remain only for symbols not in the facade (getConfigPath, getCcsDirSource, etc). Behavior unchanged; full suite passes 1824/1824. Out of scope: switching loadOrCreateUnifiedConfig() callers to getCachedConfig() — needs per-callsite cache-safety analysis. Tracked as follow-up. Refs #1161
89 lines
2.3 KiB
TypeScript
89 lines
2.3 KiB
TypeScript
import { resolveOpenAICompatProfileConfig } from './profile-router';
|
|
import { OPENAI_COMPAT_PROXY_DEFAULT_PORT } from './proxy-daemon-paths';
|
|
import { startOpenAICompatProxyServer } from './server/proxy-server';
|
|
import { loadSettings } from '../config/config-loader-facade';
|
|
|
|
interface RuntimeOptions {
|
|
port: number;
|
|
host: string;
|
|
profileName: string;
|
|
settingsPath: string;
|
|
authToken: string;
|
|
insecure: boolean;
|
|
}
|
|
|
|
function parseArgs(argv: string[]): RuntimeOptions {
|
|
let port = OPENAI_COMPAT_PROXY_DEFAULT_PORT;
|
|
let host = '127.0.0.1';
|
|
let profileName = '';
|
|
let settingsPath = '';
|
|
let authToken = '';
|
|
let insecure = false;
|
|
|
|
for (let i = 0; i < argv.length; i++) {
|
|
const arg = argv[i];
|
|
if (arg === '--port' && argv[i + 1]) {
|
|
port = Number.parseInt(argv[++i] || '', 10) || port;
|
|
continue;
|
|
}
|
|
if (arg === '--host' && argv[i + 1]) {
|
|
host = argv[++i] || host;
|
|
continue;
|
|
}
|
|
if (arg === '--profile' && argv[i + 1]) {
|
|
profileName = argv[++i] || '';
|
|
continue;
|
|
}
|
|
if (arg === '--settings-path' && argv[i + 1]) {
|
|
settingsPath = argv[++i] || '';
|
|
continue;
|
|
}
|
|
if (arg === '--auth-token' && argv[i + 1]) {
|
|
authToken = argv[++i] || '';
|
|
continue;
|
|
}
|
|
if (arg === '--insecure') {
|
|
insecure = true;
|
|
}
|
|
}
|
|
|
|
return { port, host, profileName, settingsPath, authToken, insecure };
|
|
}
|
|
|
|
function startRuntime(options: RuntimeOptions): void {
|
|
if (!options.authToken.trim()) {
|
|
throw new Error('Missing local proxy auth token');
|
|
}
|
|
|
|
const settings = loadSettings(options.settingsPath);
|
|
const profile = resolveOpenAICompatProfileConfig(
|
|
options.profileName,
|
|
options.settingsPath,
|
|
settings.env || {}
|
|
);
|
|
if (!profile) {
|
|
throw new Error(
|
|
`Profile "${options.profileName}" is not an OpenAI-compatible settings profile`
|
|
);
|
|
}
|
|
|
|
const server = startOpenAICompatProxyServer({
|
|
profile,
|
|
host: options.host,
|
|
port: options.port,
|
|
authToken: options.authToken,
|
|
insecure: options.insecure,
|
|
});
|
|
server.once('error', (error) => {
|
|
console.error((error as Error).message);
|
|
process.exit(1);
|
|
});
|
|
const shutdown = () => server.close();
|
|
process.on('SIGTERM', shutdown);
|
|
process.on('SIGINT', shutdown);
|
|
}
|
|
|
|
if (require.main === module) {
|
|
startRuntime(parseArgs(process.argv.slice(2)));
|
|
}
|