fix(ai): use the versioned Ark Agent Plan messages endpoint

This commit is contained in:
陈大猫 committed 2026-11-18 18:48:35 +08:00
1 parent 7b8384573d
commit ef513622dd
3 files changed
+23

No files matched your search

@@ -71,3 +71,19 @@ test("normalizeAnthropicSdkBaseURL preserves custom non-/v1 path prefixes", () =
"https://gateway.example/api/v1",
);
});
test("normalizes the official Ark Agent Plan Anthropic prefix only", () => {
const base = "https://ark.cn-beijing.volces.com/api/plan";
for (const input of [base, base + "/", " " + base + " ", base + "/v1", base + "/v1/"]) {
assert.equal(normalizeAnthropicSdkBaseURL(input), base + "/v1");
}
for (const input of [
base.replace("https:", "http:"),
base.replace(".com", ".com.example"),
base.replace(".com", ".com:8443"),
base + "/custom",
"https://gateway.example/api/plan",
]) {
assert.equal(normalizeAnthropicSdkBaseURL(input), input);
}
});
@@ -39,6 +39,7 @@ export function isBareOriginBaseURL(baseURL: string): boolean {
* Normalize a stored Anthropic-compat Base URL for @ai-sdk/anthropic.
* - Bare hosts gain a /v1 suffix (Claude Code style → SDK style).
* - Bases that already end in /v1 are left unchanged.
* - The official Ark Agent Plan /api/plan prefix gains a /v1 suffix.
* - Other path prefixes (custom proxies) are left unchanged so chat keeps
* requesting `{prefix}/messages` rather than `{prefix}/v1/messages`.
*/
@@ -46,6 +47,9 @@ export function normalizeAnthropicSdkBaseURL(baseURL: string): string {
const trimmed = stripTrailingSlashes(baseURL);
if (!trimmed) return trimmed;
if (anthropicBaseIncludesV1(trimmed)) return trimmed;
// Claude Code appends /v1/messages to the documented Ark Agent Plan base.
// The Anthropic SDK appends only /messages, so supply the missing /v1.
if (trimmed === "https://ark.cn-beijing.volces.com/api/plan") return `${trimmed}/v1`;
if (!isBareOriginBaseURL(trimmed)) return trimmed;
return `${trimmed}/v1`;
}
+3
View File
@@ -365,6 +365,9 @@ test("Anthropic SDK sends x-api-key only on official host and adds Bearer on cus
}));
await assert.rejects(async () => await model.doGenerate({ prompt }));
const request = requests.at(-1)!;
assert.equal(request.url, baseURL.endsWith("/api/plan")
? baseURL + "/v1/messages"
: baseURL + "/messages");
assert.equal(request.headers.get("x-api-key"), "__IPC_SECURED__");
assert.equal(request.headers.get("authorization"), "Bearer __IPC_SECURED__");
assert.equal(request.headers.get("anthropic-version"), "2023-06-01");