openai/codex-action

Public

mirrored from https://github.com/openai/codex-actionAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
ffac27a108c7752c85d8e0eef6466f0ba22dd5ec

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/writeProxyConfig.ts

38lines · modecode

1import * as fs from "node:fs/promises";
2import * as path from "node:path";
3
4const MODEL_PROVIDER = "openai-proxy";
5
6export async function writeProxyConfig(
7 codexHome: string,
8 port: number
9): Promise<void> {
10 const configPath = path.join(codexHome, "config.toml");
11
12 let existing = "";
13 try {
14 existing = await fs.readFile(configPath, "utf8");
15 } catch {
16 existing = "";
17 }
18
19 const header = `# Added by codex-action.
20model_provider = "${MODEL_PROVIDER}"
21
22
23`;
24 const table = `
25
26# Added by codex-action.
27[model_providers.${MODEL_PROVIDER}]
28name = "OpenAI Proxy"
29base_url = "http://127.0.0.1:${port}/v1"
30wire_api = "responses"
31`;
32
33 // Prepend model_provider at the very top.
34 let output = `${header}${existing}${table}`;
35
36 await fs.mkdir(codexHome, { recursive: true });
37 await fs.writeFile(configPath, output, "utf8");
38}
39