Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
230 lines
7.1 KiB
TypeScript
230 lines
7.1 KiB
TypeScript
// Provider Auth script supports OpenClaw repository automation.
|
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import { parsePositiveInt, readPositiveIntEnv } from "./env-limits.ts";
|
|
import { die, run } from "./host-command.ts";
|
|
import type { Mode, Platform, Provider, ProviderAuth } from "./types.ts";
|
|
|
|
type ResolveLatestVersionDeps = {
|
|
createTempDir?: typeof mkdtempSync;
|
|
removeDir?: typeof rmSync;
|
|
runCommand?: typeof run;
|
|
tempDir?: typeof tmpdir;
|
|
writeFile?: typeof writeFileSync;
|
|
};
|
|
|
|
export function parseBoolEnv(value: string | undefined): boolean {
|
|
return /^(1|true|yes|on)$/i.test(value ?? "");
|
|
}
|
|
|
|
export function ensureValue(args: string[], index: number, flag: string): string {
|
|
const value = args[index + 1];
|
|
if (value == null || value === "" || value.startsWith("-")) {
|
|
die(`${flag} requires a value`);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
export function resolveProviderAuth(input: {
|
|
provider: Provider;
|
|
apiKeyEnv?: string;
|
|
modelId?: string;
|
|
}): ProviderAuth {
|
|
const providerDefaults: Record<Provider, Omit<ProviderAuth, "apiKeyValue">> = {
|
|
anthropic: {
|
|
apiKeyEnv: input.apiKeyEnv || "ANTHROPIC_API_KEY",
|
|
authChoice: "apiKey",
|
|
authKeyFlag: "anthropic-api-key",
|
|
modelId:
|
|
input.modelId ||
|
|
process.env.OPENCLAW_PARALLELS_ANTHROPIC_MODEL ||
|
|
"anthropic/claude-sonnet-4-6",
|
|
},
|
|
minimax: {
|
|
apiKeyEnv: input.apiKeyEnv || "MINIMAX_API_KEY",
|
|
authChoice: "minimax-global-api",
|
|
authKeyFlag: "minimax-api-key",
|
|
modelId:
|
|
input.modelId || process.env.OPENCLAW_PARALLELS_MINIMAX_MODEL || "minimax/MiniMax-M2.7",
|
|
},
|
|
openai: {
|
|
apiKeyEnv: input.apiKeyEnv || "OPENAI_API_KEY",
|
|
authChoice: "openai-api-key",
|
|
authKeyFlag: "openai-api-key",
|
|
modelId: input.modelId || process.env.OPENCLAW_PARALLELS_OPENAI_MODEL || "openai/gpt-5.5",
|
|
},
|
|
};
|
|
const resolved = providerDefaults[input.provider];
|
|
const apiKeyValue = process.env[resolved.apiKeyEnv] ?? "";
|
|
if (!apiKeyValue) {
|
|
die(`${resolved.apiKeyEnv} is required`);
|
|
}
|
|
return { ...resolved, apiKeyValue };
|
|
}
|
|
|
|
export function resolveWindowsProviderAuth(input: {
|
|
provider: Provider;
|
|
apiKeyEnv?: string;
|
|
modelId?: string;
|
|
}): ProviderAuth {
|
|
const auth = resolveProviderAuth(input);
|
|
if (input.provider !== "openai" || input.modelId) {
|
|
return auth;
|
|
}
|
|
const windowsModel = process.env.OPENCLAW_PARALLELS_WINDOWS_OPENAI_MODEL?.trim();
|
|
if (windowsModel) {
|
|
return { ...auth, modelId: windowsModel };
|
|
}
|
|
if (process.env.OPENCLAW_PARALLELS_OPENAI_MODEL?.trim()) {
|
|
return auth;
|
|
}
|
|
return { ...auth, modelId: "openai/gpt-5.5" };
|
|
}
|
|
|
|
export function providerIdFromModelId(modelId: string): string {
|
|
const providerId = modelId.split("/", 1)[0]?.trim() ?? "";
|
|
return /^[A-Za-z0-9_-]+$/u.test(providerId) ? providerId : "";
|
|
}
|
|
|
|
export function resolveParallelsModelTimeoutSeconds(platform?: Platform): number {
|
|
const platformEnvName =
|
|
platform === undefined
|
|
? undefined
|
|
: `OPENCLAW_PARALLELS_${platform.toUpperCase()}_MODEL_TIMEOUT_S`;
|
|
const platformEnv = platformEnvName === undefined ? undefined : process.env[platformEnvName];
|
|
const defaultSeconds = platform === "macos" || platform === "windows" ? 1800 : 900;
|
|
if (platformEnvName && platformEnv?.trim()) {
|
|
return parsePositiveInt(platformEnv, platformEnvName);
|
|
}
|
|
return readPositiveIntEnv("OPENCLAW_PARALLELS_MODEL_TIMEOUT_S", defaultSeconds);
|
|
}
|
|
|
|
export function providerTimeoutConfigJson(
|
|
modelId: string,
|
|
platform: Platform,
|
|
timeoutSeconds = resolveParallelsModelTimeoutSeconds(platform),
|
|
): string {
|
|
const providerId = providerIdFromModelId(modelId);
|
|
if (providerId !== "openai") {
|
|
return "";
|
|
}
|
|
const modelName = modelId.slice("openai/".length).trim();
|
|
if (!modelName) {
|
|
return "";
|
|
}
|
|
return JSON.stringify({
|
|
api: "openai-responses",
|
|
baseUrl: "https://api.openai.com/v1",
|
|
models: [
|
|
{
|
|
contextWindow: 1_047_576,
|
|
id: modelName,
|
|
maxTokens: 32_768,
|
|
name: modelName,
|
|
},
|
|
],
|
|
timeoutSeconds,
|
|
});
|
|
}
|
|
|
|
export function modelTransportConfigJson(modelId: string): string {
|
|
if (providerIdFromModelId(modelId) !== "openai") {
|
|
return "";
|
|
}
|
|
return JSON.stringify({
|
|
alias: "GPT",
|
|
params: {
|
|
transport: "sse",
|
|
},
|
|
});
|
|
}
|
|
|
|
export function configPathMapKey(key: string): string {
|
|
return `[${JSON.stringify(key)}]`;
|
|
}
|
|
|
|
export function modelProviderConfigBatchJson(
|
|
modelId: string,
|
|
platform: Platform,
|
|
timeoutSeconds = resolveParallelsModelTimeoutSeconds(platform),
|
|
): string {
|
|
const commands: Array<{ path: string; value: unknown }> = [];
|
|
const providerId = providerIdFromModelId(modelId);
|
|
const providerConfig = providerTimeoutConfigJson(modelId, platform, timeoutSeconds);
|
|
if (providerId && providerConfig) {
|
|
commands.push({
|
|
path: `models.providers.${providerId}`,
|
|
value: JSON.parse(providerConfig) as unknown,
|
|
});
|
|
}
|
|
const modelTransportConfig = modelTransportConfigJson(modelId);
|
|
if (modelTransportConfig) {
|
|
commands.push({
|
|
path: `agents.defaults.models${configPathMapKey(modelId)}`,
|
|
value: JSON.parse(modelTransportConfig) as unknown,
|
|
});
|
|
}
|
|
return commands.length === 0 ? "" : JSON.stringify(commands);
|
|
}
|
|
|
|
export function parseProvider(value: string): Provider {
|
|
if (value === "openai" || value === "anthropic" || value === "minimax") {
|
|
return value;
|
|
}
|
|
return die(`invalid --provider: ${value}`);
|
|
}
|
|
|
|
export function parseMode(value: string): Mode {
|
|
if (value === "fresh" || value === "upgrade" || value === "both") {
|
|
return value;
|
|
}
|
|
return die(`invalid --mode: ${value}`);
|
|
}
|
|
|
|
export function parsePlatformList(value: string): Set<Platform> {
|
|
const normalized = value.replaceAll(" ", "");
|
|
if (normalized === "all") {
|
|
return new Set(["macos", "windows", "linux"]);
|
|
}
|
|
const result = new Set<Platform>();
|
|
for (const entry of normalized.split(",")) {
|
|
if (entry === "macos" || entry === "windows" || entry === "linux") {
|
|
if (result.has(entry)) {
|
|
die(`duplicate --platform entry: ${entry}`);
|
|
}
|
|
result.add(entry);
|
|
} else {
|
|
die(`invalid --platform entry: ${entry}`);
|
|
}
|
|
}
|
|
if (result.size === 0) {
|
|
die("--platform must include at least one platform");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export function resolveLatestVersion(
|
|
versionOverride = "",
|
|
deps: ResolveLatestVersionDeps = {},
|
|
): string {
|
|
if (versionOverride) {
|
|
return versionOverride;
|
|
}
|
|
const createTempDir = deps.createTempDir ?? mkdtempSync;
|
|
const removeDir = deps.removeDir ?? rmSync;
|
|
const runCommand = deps.runCommand ?? run;
|
|
const resolveTempDir = deps.tempDir ?? tmpdir;
|
|
const writeFile = deps.writeFile ?? writeFileSync;
|
|
const userConfigDir = createTempDir(path.join(resolveTempDir(), "openclaw-npm-"));
|
|
const userConfigPath = path.join(userConfigDir, "npmrc");
|
|
try {
|
|
writeFile(userConfigPath, "", "utf8");
|
|
return runCommand("npm", ["view", "openclaw", "version", "--userconfig", userConfigPath], {
|
|
quiet: true,
|
|
}).stdout.trim();
|
|
} finally {
|
|
removeDir(userConfigDir, { force: true, recursive: true });
|
|
}
|
|
}
|