openai/codex-action

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
pr18

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/writeProxyConfig.ts

38lines · modeblame

1c44f3d7Michael Bolin9 months ago1import * as fs from "node:fs/promises";
2import * as path from "node:path";
3
4const MODEL_PROVIDER = "openai-proxy";
5
6export async function writeProxyConfig(
7codexHome: string,
8port: number
9): Promise<void> {
10const configPath = path.join(codexHome, "config.toml");
11
12let existing = "";
13try {
14existing = await fs.readFile(configPath, "utf8");
15} catch {
16existing = "";
17}
18
19const header = `# Added by codex-action.
20model_provider = "${MODEL_PROVIDER}"
21
22
23`;
24const 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.
34let output = `${header}${existing}${table}`;
35
36await fs.mkdir(codexHome, { recursive: true });
37await fs.writeFile(configPath, output, "utf8");
38}