Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions packages/pulumi/src/components/cloud-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as zlib from "zlib";
import { generateConfigPatchScript, PluginEntry } from "./config-generator";
import { CODING_AGENT_REGISTRY, type CodingAgentEntry } from "@clawup/core";
import { CODING_AGENT_REGISTRY, MODEL_PROVIDERS, type CodingAgentEntry } from "@clawup/core";

/**
* Config for a plugin to be installed on an agent.
Expand All @@ -25,8 +25,10 @@ export interface PluginInstallConfig {
}

export interface CloudInitConfig {
/** Anthropic API key (for backward compatibility) */
/** Model provider API key (named anthropicApiKey for backward compatibility) */
anthropicApiKey: string;
/** Model provider key (e.g., "anthropic", "openai"). Defaults to "anthropic". */
modelProvider?: string;
/** Tailscale auth key */
tailscaleAuthKey: string;
/** Gateway authentication token */
Expand Down Expand Up @@ -298,8 +300,12 @@ if ! grep -q 'NVM_DIR' ~/.bashrc; then
fi
UBUNTU_SCRIPT

# Set environment variables for ubuntu user
# Auto-detect credential type and export the correct variable
# Set environment variables for ubuntu user (provider-aware)
${config.modelProvider && config.modelProvider !== "anthropic"
? `# ${config.modelProvider} provider: export ${MODEL_PROVIDERS[config.modelProvider as keyof typeof MODEL_PROVIDERS]?.envVar ?? "MODEL_API_KEY"}
echo 'export ${MODEL_PROVIDERS[config.modelProvider as keyof typeof MODEL_PROVIDERS]?.envVar ?? "MODEL_API_KEY"}="\${ANTHROPIC_API_KEY}"' >> /home/ubuntu/.bashrc
echo "Configured ${MODEL_PROVIDERS[config.modelProvider as keyof typeof MODEL_PROVIDERS]?.envVar ?? "MODEL_API_KEY"} for ${config.modelProvider}"`
: `# Auto-detect Anthropic credential type and export the correct variable
if [[ "\${ANTHROPIC_API_KEY}" =~ ^sk-ant-oat ]]; then
# OAuth token from Claude Pro/Max subscription
echo 'export CLAUDE_CODE_OAUTH_TOKEN="\${ANTHROPIC_API_KEY}"' >> /home/ubuntu/.bashrc
Expand All @@ -308,7 +314,7 @@ else
# API key from Anthropic Console
echo 'export ANTHROPIC_API_KEY="\${ANTHROPIC_API_KEY}"' >> /home/ubuntu/.bashrc
echo "Detected API key, exporting as ANTHROPIC_API_KEY"
fi
fi`}
${(config.plugins ?? [])
.flatMap((p) => Object.values(p.secretEnvVars ?? {}))
.map((envVar) => `[ -n "\${${envVar}:-}" ] && echo 'export ${envVar}="\${${envVar}:-}"' >> /home/ubuntu/.bashrc`)
Expand Down
15 changes: 11 additions & 4 deletions packages/pulumi/src/components/config-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Builds the openclaw.json configuration file content
*/

import { CODING_AGENT_REGISTRY } from "@clawup/core";
import { CODING_AGENT_REGISTRY, MODEL_PROVIDERS, getProviderForModel } from "@clawup/core";

/**
* A single plugin entry for the OpenClaw config.
Expand Down Expand Up @@ -288,6 +288,8 @@ export function generateConfigPatchScript(options: OpenClawConfigOptions): strin
// Build model config (primary + optional fallbacks)
const model = options.model ?? "anthropic/claude-opus-4-6";
const backupModel = options.backupModel;
const providerKey = getProviderForModel(model);
const providerDef = MODEL_PROVIDERS[providerKey as keyof typeof MODEL_PROVIDERS];

// Build cliBackends config from coding agent registry
const codingAgentName = options.codingAgent ?? "claude-code";
Expand Down Expand Up @@ -321,8 +323,8 @@ config["gateway"]["auth"] = {
"token": os.environ["GATEWAY_TOKEN"]
}

# Configure environment variables for child processes (including Claude Code, Linear CLI)
# Auto-detect credential type: OAuth token (oat) vs API key (api)
# Configure environment variables for child processes (model provider API key)
${providerKey === "anthropic" ? `# Anthropic: auto-detect credential type (OAuth token vs API key)
anthropic_cred = os.environ.get("ANTHROPIC_API_KEY", "")
if anthropic_cred.startswith("sk-ant-oat"):
# OAuth token from Claude Pro/Max subscription (use with CLAUDE_CODE_OAUTH_TOKEN)
Expand All @@ -335,7 +337,12 @@ else:
config["env"] = {
"ANTHROPIC_API_KEY": anthropic_cred
}
print("Configured environment variables: ANTHROPIC_API_KEY (API key)")
print("Configured environment variables: ANTHROPIC_API_KEY (API key)")` : `# ${providerDef?.name ?? providerKey}: set provider API key env var
provider_key = os.environ.get("${providerDef?.envVar ?? "MODEL_API_KEY"}", "")
config["env"] = {
"${providerDef?.envVar ?? "MODEL_API_KEY"}": provider_key
}
print("Configured environment variables: ${providerDef?.envVar ?? "MODEL_API_KEY"}")`}

# Configure heartbeat (proactive mode)
config.setdefault("agents", {})
Expand Down