Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

codexLaunchArgs.ts

48 lines1.6 KB

1import { tokenizeCliArgs } from "@t3tools/shared/cliArgs";
2​
3export const T3CODE_CODEX_LAUNCH_ARGS_ENV = "T3CODE_CODEX_LAUNCH_ARGS";
4​
5export const resolveCodexLaunchArgs = (
6 launchArgs?: string,
7 environment: NodeJS.ProcessEnv = process.env,
8) => environment[T3CODE_CODEX_LAUNCH_ARGS_ENV]?.trim() || launchArgs?.trim() || "";
9​
10export const codexLaunchArgv = (launchArgs?: string): ReadonlyArray<string> =>
11 tokenizeCliArgs(launchArgs);
12​
13export const codexAppServerArgs = (launchArgs?: string) => [
14 "app-server",
15 ...codexLaunchArgv(launchArgs),
16];
17​
18export const codexExecLaunchArgs = (launchArgs?: string) => {
19 const args = codexLaunchArgv(launchArgs);
20 const execArgs: Array<string> = [];
21​
22 for (let index = 0; index < args.length; index++) {
23 const arg = args[index];
24 if (arg === undefined) continue;
25​
26 if (arg === "--strict-config" || arg.startsWith("--config=") || arg.startsWith("-c=")) {
27 execArgs.push(arg);
28 } else if (arg === "--config" || arg === "-c" || arg === "--enable" || arg === "--disable") {
29 const value = args[index + 1];
30 if (value !== undefined && !value.startsWith("-")) {
31 execArgs.push(arg, value);
32 index++;
33 }
34 } else if (arg.startsWith("--enable=") || arg.startsWith("--disable=")) {
35 execArgs.push(arg);
36 }
37 }
38​
39 return execArgs;
40};
41​
42export const codexSessionAppServerArgs = (
43 appServerArgs: ReadonlyArray<string> | undefined,
44 launchArgs: string | undefined,
45) => {
46 const launchAppServerArgs = codexAppServerArgs(launchArgs);
47 return appServerArgs ? [...launchAppServerArgs, ...appServerArgs] : launchAppServerArgs;
48};