feat: 支持 provider profile config.toml 管理

This commit is contained in:
Codex
2026-06-05 22:35:40 +08:00
parent 17e9cd3995
commit dd58cf9a8e
5 changed files with 163 additions and 3 deletions
+21
View File
@@ -41,7 +41,9 @@ async function dispatch(args: ParsedArgs): Promise<JsonValue> {
if (group === "backends" && command === "list") return client(args).get("/api/v1/backends");
if (group === "provider-profiles" && command === "list") return client(args).get("/api/v1/provider-profiles");
if (group === "provider-profiles" && command === "show" && id) return client(args).get(`/api/v1/provider-profiles/${encodeURIComponent(normalizeProfile(id))}`);
if (group === "provider-profiles" && command === "config" && id) return client(args).get(`/api/v1/provider-profiles/${encodeURIComponent(normalizeProfile(id))}/config`);
if (group === "provider-profiles" && command === "set-key" && id) return setProviderProfileKey(args, id);
if (group === "provider-profiles" && command === "set-config" && id) return setProviderProfileConfig(args, id);
if (group === "provider-profiles" && command === "validate" && id) return validateProviderProfileCli(args, id);
if (group === "secrets" && command === "codex" && id === "render") return renderCodexSecret(args);
if (group === "sessions" && command === "ps") return listSessions(args);
@@ -419,6 +421,23 @@ async function setProviderProfileKey(args: ParsedArgs, profileValue: string): Pr
return await client(args).put(`/api/v1/provider-profiles/${encodeURIComponent(profile)}/credential`, body) as JsonRecord;
}
async function setProviderProfileConfig(args: ParsedArgs, profileValue: string): Promise<JsonRecord> {
const profile = normalizeProfile(profileValue);
if (args.flags.get("config-stdin") !== true) throw new AgentRunError("schema-invalid", "provider-profiles set-config requires --config-stdin", { httpStatus: 2 });
const configToml = await readStdinText();
if (configToml.trim().length === 0) throw new AgentRunError("schema-invalid", "stdin config.toml is empty", { httpStatus: 2 });
return await client(args).put(`/api/v1/provider-profiles/${encodeURIComponent(profile)}/config`, {
configToml,
reason: optionalFlag(args, "reason") ?? "operator-cli",
delegatedBy: {
system: optionalFlag(args, "delegated-system") ?? "operator-cli",
userId: optionalFlag(args, "delegated-user-id") ?? null,
username: optionalFlag(args, "delegated-username") ?? null,
requestId: optionalFlag(args, "delegated-request-id") ?? null,
},
}) as JsonRecord;
}
async function validateProviderProfileCli(args: ParsedArgs, profileValue: string): Promise<JsonRecord> {
const profile = normalizeProfile(profileValue);
const started = await client(args).post(`/api/v1/provider-profiles/${encodeURIComponent(profile)}/validate`, {}) as JsonRecord;
@@ -770,7 +789,9 @@ function help(): JsonRecord {
"secrets codex render --dry-run [--profile codex|deepseek|minimax-m3] [--codex-home <dir>] [--namespace agentrun-v01] [--secret-name <name>]",
"provider-profiles list",
"provider-profiles show <profile>",
"provider-profiles config <profile>",
"provider-profiles set-key <profile> --key-stdin [--model <model>] [--base-url <url>]",
"provider-profiles set-config <profile> --config-stdin",
"provider-profiles validate <profile> [--wait] [--timeout-ms <ms>]",
"backends list",
"server start [--port <port>] [--host <host>] [--foreground]",