mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 01:28:27 +00:00
feat(zai): auto-detect endpoint + default glm-5 (#14786)
* feat(zai): auto-detect endpoint + default glm-5 * test: fix Z.AI default endpoint expectation (#14786) * test: bump embedded runner beforeAll timeout * chore: update changelog for Z.AI GLM-5 autodetect (#14786) * chore: resolve changelog merge conflict with main (#14786) * chore: append changelog note for #14786 without merge conflict * chore: sync changelog with main to resolve merge conflict
This commit is contained in:
committed by
GitHub
parent
2b5df1dfea
commit
5e7842a41d
@@ -69,6 +69,7 @@ import {
|
||||
ZAI_DEFAULT_MODEL_REF,
|
||||
} from "./onboard-auth.js";
|
||||
import { OPENCODE_ZEN_DEFAULT_MODEL } from "./opencode-zen-model-default.js";
|
||||
import { detectZaiEndpoint } from "./zai-endpoint-detect.js";
|
||||
|
||||
export async function applyAuthChoiceApiProviders(
|
||||
params: ApplyAuthChoiceParams,
|
||||
@@ -627,8 +628,7 @@ export async function applyAuthChoiceApiProviders(
|
||||
authChoice === "zai-global" ||
|
||||
authChoice === "zai-cn"
|
||||
) {
|
||||
// Determine endpoint from authChoice or prompt
|
||||
let endpoint: string;
|
||||
let endpoint: "global" | "cn" | "coding-global" | "coding-cn" | undefined;
|
||||
if (authChoice === "zai-coding-global") {
|
||||
endpoint = "coding-global";
|
||||
} else if (authChoice === "zai-coding-cn") {
|
||||
@@ -637,41 +637,15 @@ export async function applyAuthChoiceApiProviders(
|
||||
endpoint = "global";
|
||||
} else if (authChoice === "zai-cn") {
|
||||
endpoint = "cn";
|
||||
} else {
|
||||
// zai-api-key: prompt for endpoint selection
|
||||
endpoint = await params.prompter.select({
|
||||
message: "Select Z.AI endpoint",
|
||||
options: [
|
||||
{
|
||||
value: "coding-global",
|
||||
label: "Coding-Plan-Global",
|
||||
hint: "GLM Coding Plan Global (api.z.ai)",
|
||||
},
|
||||
{
|
||||
value: "coding-cn",
|
||||
label: "Coding-Plan-CN",
|
||||
hint: "GLM Coding Plan CN (open.bigmodel.cn)",
|
||||
},
|
||||
{
|
||||
value: "global",
|
||||
label: "Global",
|
||||
hint: "Z.AI Global (api.z.ai)",
|
||||
},
|
||||
{
|
||||
value: "cn",
|
||||
label: "CN",
|
||||
hint: "Z.AI CN (open.bigmodel.cn)",
|
||||
},
|
||||
],
|
||||
initialValue: "coding-global",
|
||||
});
|
||||
}
|
||||
|
||||
// Input API key
|
||||
let hasCredential = false;
|
||||
let apiKey = "";
|
||||
|
||||
if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "zai") {
|
||||
await setZaiApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
|
||||
apiKey = normalizeApiKeyInput(params.opts.token);
|
||||
await setZaiApiKey(apiKey, params.agentDir);
|
||||
hasCredential = true;
|
||||
}
|
||||
|
||||
@@ -682,7 +656,8 @@ export async function applyAuthChoiceApiProviders(
|
||||
initialValue: true,
|
||||
});
|
||||
if (useExisting) {
|
||||
await setZaiApiKey(envKey.apiKey, params.agentDir);
|
||||
apiKey = envKey.apiKey;
|
||||
await setZaiApiKey(apiKey, params.agentDir);
|
||||
hasCredential = true;
|
||||
}
|
||||
}
|
||||
@@ -691,27 +666,76 @@ export async function applyAuthChoiceApiProviders(
|
||||
message: "Enter Z.AI API key",
|
||||
validate: validateApiKeyInput,
|
||||
});
|
||||
await setZaiApiKey(normalizeApiKeyInput(String(key)), params.agentDir);
|
||||
apiKey = normalizeApiKeyInput(String(key));
|
||||
await setZaiApiKey(apiKey, params.agentDir);
|
||||
}
|
||||
|
||||
// zai-api-key: auto-detect endpoint + choose a working default model.
|
||||
let modelIdOverride: string | undefined;
|
||||
if (!endpoint) {
|
||||
const detected = await detectZaiEndpoint({ apiKey });
|
||||
if (detected) {
|
||||
endpoint = detected.endpoint;
|
||||
modelIdOverride = detected.modelId;
|
||||
await params.prompter.note(detected.note, "Z.AI endpoint");
|
||||
} else {
|
||||
endpoint = await params.prompter.select({
|
||||
message: "Select Z.AI endpoint",
|
||||
options: [
|
||||
{
|
||||
value: "coding-global",
|
||||
label: "Coding-Plan-Global",
|
||||
hint: "GLM Coding Plan Global (api.z.ai)",
|
||||
},
|
||||
{
|
||||
value: "coding-cn",
|
||||
label: "Coding-Plan-CN",
|
||||
hint: "GLM Coding Plan CN (open.bigmodel.cn)",
|
||||
},
|
||||
{
|
||||
value: "global",
|
||||
label: "Global",
|
||||
hint: "Z.AI Global (api.z.ai)",
|
||||
},
|
||||
{
|
||||
value: "cn",
|
||||
label: "CN",
|
||||
hint: "Z.AI CN (open.bigmodel.cn)",
|
||||
},
|
||||
],
|
||||
initialValue: "global",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "zai:default",
|
||||
provider: "zai",
|
||||
mode: "api_key",
|
||||
});
|
||||
{
|
||||
const applied = await applyDefaultModelChoice({
|
||||
config: nextConfig,
|
||||
setDefaultModel: params.setDefaultModel,
|
||||
defaultModel: ZAI_DEFAULT_MODEL_REF,
|
||||
applyDefaultConfig: (config) => applyZaiConfig(config, { endpoint }),
|
||||
applyProviderConfig: (config) => applyZaiProviderConfig(config, { endpoint }),
|
||||
noteDefault: ZAI_DEFAULT_MODEL_REF,
|
||||
noteAgentModel,
|
||||
prompter: params.prompter,
|
||||
});
|
||||
nextConfig = applied.config;
|
||||
agentModelOverride = applied.agentModelOverride ?? agentModelOverride;
|
||||
}
|
||||
|
||||
const defaultModel = modelIdOverride ? `zai/${modelIdOverride}` : ZAI_DEFAULT_MODEL_REF;
|
||||
const applied = await applyDefaultModelChoice({
|
||||
config: nextConfig,
|
||||
setDefaultModel: params.setDefaultModel,
|
||||
defaultModel,
|
||||
applyDefaultConfig: (config) =>
|
||||
applyZaiConfig(config, {
|
||||
endpoint,
|
||||
...(modelIdOverride ? { modelId: modelIdOverride } : {}),
|
||||
}),
|
||||
applyProviderConfig: (config) =>
|
||||
applyZaiProviderConfig(config, {
|
||||
endpoint,
|
||||
...(modelIdOverride ? { modelId: modelIdOverride } : {}),
|
||||
}),
|
||||
noteDefault: defaultModel,
|
||||
noteAgentModel,
|
||||
prompter: params.prompter,
|
||||
});
|
||||
nextConfig = applied.config;
|
||||
agentModelOverride = applied.agentModelOverride ?? agentModelOverride;
|
||||
|
||||
return { config: nextConfig, agentModelOverride };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user