MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / runCodexNativeApiServe

Function runCodexNativeApiServe

src/cli.ts:399–497  ·  view source on GitHub ↗
(args: string[])

Source from the content-addressed store, hash-verified

397}
398
399async function runCodexNativeApiServe(args: string[]) {
400 const i18n = createI18n();
401 const options = parseCodexNativeApiServeArgs(args);
402 const stateDir = path.resolve(options.stateDir ?? defaultCodexBridgeStateDir());
403 const defaultCwd = path.resolve(options.cwd ?? process.env.CODEXBRIDGE_DEFAULT_CWD ?? process.cwd());
404 const serveLock = await acquireServeLock(path.join(stateDir, 'runtime', 'codex-native-api-serve.lock'));
405 const repositories = createFileJsonRepositories(path.join(stateDir, 'runtime'));
406 const codexProfiles = loadCodexProfilesFromEnv();
407 const codexAuthManager = createWeixinServeCodexAuthManager(stateDir);
408 const runtime = createCodexBridgeRuntime({
409 providerPlugins: [
410 new OpenAINativeProviderPlugin(),
411 new OpenAICompatibleProviderPlugin(),
412 ],
413 providerProfiles: codexProfiles.profiles,
414 defaultProviderProfileId: codexProfiles.defaultProviderProfileId,
415 defaultCwd,
416 locale: i18n.locale,
417 repositories,
418 assistantAttachmentRoot: path.join(stateDir, 'assistant', 'attachments'),
419 codexAuthManager,
420 codexGoalManager: createWeixinServeCodexGoalManager(stateDir),
421 });
422 const host = options.host
423 ?? normalizeCliString(process.env.CODEX_NATIVE_API_HOST)
424 ?? DEFAULT_CODEX_NATIVE_API_HOST;
425 const port = options.port
426 ?? parseOptionalNonNegativeInt(process.env.CODEX_NATIVE_API_PORT)
427 ?? DEFAULT_CODEX_NATIVE_API_PORT;
428 const providerProfileId = options.providerProfileId
429 ?? normalizeCliString(process.env.CODEX_NATIVE_API_PROVIDER_PROFILE_ID)
430 ?? null;
431 const authToken = normalizeCliString(process.env.CODEX_NATIVE_API_AUTH_TOKEN);
432 const defaultModel = normalizeCliString(process.env.CODEX_NATIVE_API_DEFAULT_MODEL);
433 const requestTitlePrefix = normalizeCliString(process.env.CODEX_NATIVE_API_TITLE_PREFIX);
434 const nativeApi = new CodexNativeApiService({
435 providerProfiles: runtime.repositories.providerProfiles,
436 providerRegistry: runtime.registry,
437 defaultProviderProfileId: runtime.config.defaultProviderProfileId,
438 providerProfileId,
439 authPath: codexAuthManager.authPath,
440 env: process.env,
441 host,
442 port,
443 authToken,
444 defaultModel,
445 defaultCwd,
446 defaultLocale: i18n.locale,
447 requestTitlePrefix,
448 });
449
450 process.once('exit', () => {
451 serveLock.releaseSync();
452 });
453
454 let stopped = false;
455 let resolveStopped: (() => void) | null = null;
456 const stoppedPromise = new Promise<void>((resolve) => {

Callers 1

mainFunction · 0.85

Calls 15

startMethod · 0.95
stopMethod · 0.95
createI18nFunction · 0.85
acquireServeLockFunction · 0.85
loadCodexProfilesFromEnvFunction · 0.85
createCodexBridgeRuntimeFunction · 0.85
normalizeCliStringFunction · 0.85

Tested by

no test coverage detected