Skip to content

Commit 8ea4c77

Browse files
author
Jay Kumar
committed
fix(registry/coder-labs/modules/codex): rename aibridge to aigateway in config, add pnpm/bun fallbacks
- Rename model_provider and [model_providers.] section from 'aibridge' to 'aigateway' across main.tf, install template, tests, and README. The API path and env var stay unchanged (protocol-level). - Add pnpm and bun as fallback package managers for codex installation when npm is not available.
1 parent 2aa54d4 commit 8ea4c77

4 files changed

Lines changed: 32 additions & 26 deletions

File tree

registry/coder-labs/modules/codex/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ module "codex" {
7777
}
7878
```
7979

80-
When `enable_ai_gateway = true`, the module configures Codex to use the `aibridge` model provider in `config.toml` with the workspace owner's session token for authentication.
80+
When `enable_ai_gateway = true`, the module configures Codex to use the `aigateway` model provider in `config.toml` with the workspace owner's session token for authentication.
8181

8282
> [!CAUTION]
8383
> `enable_ai_gateway = true` is mutually exclusive with `openai_api_key`. Setting both fails at plan time.
8484
8585
> [!NOTE]
86-
> If you provide a custom `base_config_toml`, the module writes it verbatim and does not inject `model_provider = "aibridge"` automatically. Add it to your config yourself:
86+
> If you provide a custom `base_config_toml`, the module writes it verbatim and does not inject `model_provider = "aigateway"` automatically. Add it to your config yourself:
8787
>
8888
> ```toml
89-
> model_provider = "aibridge"
89+
> model_provider = "aigateway"
9090
> ```
9191
9292
### Advanced Configuration

registry/coder-labs/modules/codex/main.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ describe("codex", async () => {
314314
id,
315315
"/home/coder/.codex/config.toml",
316316
);
317-
expect(configToml).toContain('model_provider = "aibridge"');
317+
expect(configToml).toContain('model_provider = "aigateway"');
318318
expect(configToml).toContain('model_reasoning_effort = "none"');
319-
expect(configToml).toContain("[model_providers.aibridge]");
319+
expect(configToml).toContain("[model_providers.aigateway]");
320320
});
321321

322322
test("model-reasoning-effort-standalone", async () => {
@@ -367,7 +367,7 @@ describe("codex", async () => {
367367
test("ai-gateway-with-custom-base-config", async () => {
368368
const baseConfig = [
369369
'sandbox_mode = "danger-full-access"',
370-
'model_provider = "aibridge"',
370+
'model_provider = "aigateway"',
371371
].join("\n");
372372
const { id, coderEnvVars, scripts } = await setup({
373373
moduleVariables: {
@@ -380,15 +380,15 @@ describe("codex", async () => {
380380
id,
381381
"/home/coder/.codex/config.toml",
382382
);
383-
expect(configToml).toContain('model_provider = "aibridge"');
384-
expect(configToml).toContain("[model_providers.aibridge]");
383+
expect(configToml).toContain('model_provider = "aigateway"');
384+
expect(configToml).toContain("[model_providers.aigateway]");
385385
});
386386

387387
test("ai-gateway-custom-config-no-duplicate-provider", async () => {
388388
const baseConfig = [
389-
'model_provider = "aibridge"',
389+
'model_provider = "aigateway"',
390390
"",
391-
"[model_providers.aibridge]",
391+
"[model_providers.aigateway]",
392392
'name = "Custom AI Bridge"',
393393
'base_url = "https://custom.example.com"',
394394
'env_key = "CODER_AIBRIDGE_SESSION_TOKEN"',
@@ -405,7 +405,7 @@ describe("codex", async () => {
405405
id,
406406
"/home/coder/.codex/config.toml",
407407
);
408-
const matches = configToml.match(/\[model_providers\.aibridge\]/g) || [];
408+
const matches = configToml.match(/\[model_providers\.aigateway\]/g) || [];
409409
expect(matches.length).toBe(1);
410410
expect(configToml).toContain("Custom AI Bridge");
411411
});

registry/coder-labs/modules/codex/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ variable "base_config_toml" {
6868
When empty, the module generates a minimal default:
6969
7070
preferred_auth_method = "apikey"
71-
# model_provider = "aibridge" (sets the default profile, when enable_ai_gateway = true)
71+
# model_provider = "aigateway" (sets the default profile, when enable_ai_gateway = true)
7272
# model_reasoning_effort = "<value>" (sets the reasoning effort, when model_reasoning_effort is set)
7373
7474
[projects."<workdir>"] (when workdir is set)
@@ -117,7 +117,7 @@ resource "coder_env" "openai_api_key" {
117117
}
118118

119119
# Authenticates the client against Coder's AI Gateway using the workspace
120-
# owner's session token. Referenced by config.toml model_providers.aibridge.
120+
# owner's session token. Referenced by config.toml model_providers.aigateway.
121121
resource "coder_env" "ai_gateway_session_token" {
122122
count = var.enable_ai_gateway ? 1 : 0
123123
agent_id = var.agent_id
@@ -128,7 +128,7 @@ resource "coder_env" "ai_gateway_session_token" {
128128
locals {
129129
workdir = var.workdir != null ? trimsuffix(var.workdir, "/") : ""
130130
aibridge_config = <<-EOF
131-
[model_providers.aibridge]
131+
[model_providers.aigateway]
132132
name = "AI Gateway"
133133
base_url = "${data.coder_workspace.me.access_url}/api/v2/aibridge/openai/v1"
134134
env_key = "CODER_AIBRIDGE_SESSION_TOKEN"

registry/coder-labs/modules/codex/scripts/install.sh.tftpl

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,29 @@ function install_codex() {
3636
. "$NVM_DIR/nvm.sh"
3737
fi
3838

39-
if ! command_exists npm; then
40-
echo "Error: npm is required to install Codex. Install Node.js/npm first or set install_codex = false."
39+
# Detect a package manager for global installs.
40+
if command_exists npm; then
41+
PKG_INSTALL="npm install -g"
42+
if ! command_exists nvm; then
43+
mkdir -p "$HOME/.npm-global"
44+
npm config set prefix "$HOME/.npm-global"
45+
export PATH="$HOME/.npm-global/bin:$PATH"
46+
fi
47+
elif command_exists pnpm; then
48+
PKG_INSTALL="pnpm add -g"
49+
elif command_exists bun; then
50+
PKG_INSTALL="bun add -g"
51+
else
52+
echo "Error: npm, pnpm, or bun is required to install Codex. Install one of them first or set install_codex = false."
4153
exit 1
4254
fi
4355

44-
if ! command_exists nvm; then
45-
mkdir -p "$HOME/.npm-global"
46-
npm config set prefix "$HOME/.npm-global"
47-
export PATH="$HOME/.npm-global/bin:$PATH"
48-
fi
49-
5056
printf "%s Installing Codex CLI\n" "$${BOLD}"
5157

5258
if [ -n "$${ARG_CODEX_VERSION}" ]; then
53-
npm install -g "@openai/codex@$${ARG_CODEX_VERSION}"
59+
$PKG_INSTALL "@openai/codex@$${ARG_CODEX_VERSION}"
5460
else
55-
npm install -g "@openai/codex"
61+
$PKG_INSTALL "@openai/codex"
5662
fi
5763
printf "%s Installed Codex CLI: %s\n" "$${BOLD}" "$(codex --version)"
5864
}
@@ -62,7 +68,7 @@ function write_minimal_default_config() {
6268
local optional_config=""
6369

6470
if [ "$${ARG_ENABLE_AI_GATEWAY}" = "true" ]; then
65-
optional_config='model_provider = "aibridge"'
71+
optional_config='model_provider = "aigateway"'
6672
fi
6773

6874
if [ -n "$${ARG_MODEL_REASONING_EFFORT}" ]; then
@@ -102,7 +108,7 @@ function populate_config_toml() {
102108
fi
103109

104110
if [ "$${ARG_ENABLE_AI_GATEWAY}" = "true" ] && [ -n "$${ARG_AIBRIDGE_CONFIG}" ]; then
105-
if ! grep -q '\[model_providers\.aibridge\]' "$${config_path}" 2>/dev/null; then
111+
if ! grep -q '\[model_providers\.aigateway\]' "$${config_path}" 2>/dev/null; then
106112
printf "Adding AI Gateway configuration\n"
107113
echo -e "\n$${ARG_AIBRIDGE_CONFIG}" >> "$${config_path}"
108114
else

0 commit comments

Comments
 (0)