(argv: string[])
| 21 | } |
| 22 | |
| 23 | async function serve(argv: string[]): Promise<void> { |
| 24 | const options = parseCliArgs(argv); |
| 25 | const defaultCwd = path.resolve(options.cwd ?? process.cwd()); |
| 26 | const host = normalizeServeHost(options); |
| 27 | const service = new CodexNativeApiService({ |
| 28 | env: process.env, |
| 29 | host, |
| 30 | port: options.port, |
| 31 | authPath: options.authPath, |
| 32 | authToken: options.authToken, |
| 33 | defaultCwd, |
| 34 | providerProfileId: options.providerProfileId, |
| 35 | defaultModel: options.defaultModel, |
| 36 | }); |
| 37 | |
| 38 | let stopped = false; |
| 39 | const stop = async (signal: string) => { |
| 40 | if (stopped) { |
| 41 | return; |
| 42 | } |
| 43 | stopped = true; |
| 44 | process.stdout.write(`stopping: ${signal}\n`); |
| 45 | await service.stop(); |
| 46 | process.exit(0); |
| 47 | }; |
| 48 | |
| 49 | process.on('SIGINT', () => { void stop('SIGINT'); }); |
| 50 | process.on('SIGTERM', () => { void stop('SIGTERM'); }); |
| 51 | |
| 52 | const binding = await service.start(); |
| 53 | process.stdout.write('codex-native-api started\n'); |
| 54 | process.stdout.write(`base_url: ${service.baseUrl}\n`); |
| 55 | process.stdout.write(`default_cwd: ${defaultCwd}\n`); |
| 56 | process.stdout.write(`provider_profile: ${binding.providerProfileId}\n`); |
| 57 | process.stdout.write(`provider_kind: ${binding.providerKind}\n`); |
| 58 | process.stdout.write(`provider_display_name: ${binding.providerDisplayName}\n`); |
| 59 | process.stdout.write(`auth_path: ${binding.authPath ?? 'none'}\n`); |
| 60 | process.stdout.write(`access_scope: ${isLoopbackHost(host) ? 'localhost' : 'public'}\n`); |
| 61 | |
| 62 | if (!isLoopbackHost(host) && !options.authToken) { |
| 63 | process.stderr.write( |
| 64 | 'warning: public bind enabled without --auth-token; anyone who can reach this port can use your logged-in Codex runtime.\n', |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | await new Promise<void>(() => {}); |
| 69 | } |
| 70 | |
| 71 | const parseCliArgs = parseServeCliArgs; |
| 72 |
no test coverage detected