feat(ai): add Qwen Token Plan as built-in provider (#6858)
Add Alibaba Cloud Model Studio Token Plan subscription service as two built-in API-key providers: qwen-token-plan (international, Singapore) and qwen-token-plan-cn (China, Beijing). Each provider exposes 15 text-generation models (Qwen, DeepSeek, GLM, Kimi, MiniMax) via the OpenAI-compatible endpoint with DashScope enable_thinking support. Model metadata is sourced from models.dev; qwen3.8-max-preview is hardcoded until models.dev includes it. Also fixes kimi-coding test references (k2p7 -> kimi-for-coding) after models.dev catalog update picked up by generate-models. Closes #6850
This commit is contained in:
@@ -249,6 +249,30 @@ describe("AI Providers Abort Tests", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_API_KEY)("Qwen Token Plan Provider Abort", () => {
|
||||
const llm = getModel("qwen-token-plan", "qwen3.7-max");
|
||||
|
||||
it("should abort mid-stream", { retry: 3 }, async () => {
|
||||
await testAbortSignal(llm);
|
||||
});
|
||||
|
||||
it("should handle immediate abort", { retry: 3 }, async () => {
|
||||
await testImmediateAbort(llm);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_CN_API_KEY)("Qwen Token Plan (CN) Provider Abort", () => {
|
||||
const llm = getModel("qwen-token-plan-cn", "qwen3.7-max");
|
||||
|
||||
it("should abort mid-stream", { retry: 3 }, async () => {
|
||||
await testAbortSignal(llm);
|
||||
});
|
||||
|
||||
it("should handle immediate abort", { retry: 3 }, async () => {
|
||||
await testImmediateAbort(llm);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.KIMI_API_KEY)("Kimi For Coding Provider Abort", () => {
|
||||
const llm = getModel("kimi-coding", "kimi-for-coding");
|
||||
|
||||
|
||||
@@ -466,6 +466,30 @@ describe("Context overflow error handling", () => {
|
||||
}, 120000);
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_API_KEY)("Qwen Token Plan", () => {
|
||||
it("qwen3.7-max - should detect overflow via isContextOverflow", async () => {
|
||||
const model = getModel("qwen-token-plan", "qwen3.7-max");
|
||||
const result = await testContextOverflow(model, process.env.QWEN_TOKEN_PLAN_API_KEY!);
|
||||
logResult(result);
|
||||
|
||||
expect(result.stopReason).toBe("error");
|
||||
expect(result.errorMessage).toMatch(/input length/i);
|
||||
expect(isContextOverflow(result.response, model.contextWindow)).toBe(true);
|
||||
}, 120000);
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_CN_API_KEY)("Qwen Token Plan (CN)", () => {
|
||||
it("qwen3.7-max - should detect overflow via isContextOverflow", async () => {
|
||||
const model = getModel("qwen-token-plan-cn", "qwen3.7-max");
|
||||
const result = await testContextOverflow(model, process.env.QWEN_TOKEN_PLAN_CN_API_KEY!);
|
||||
logResult(result);
|
||||
|
||||
expect(result.stopReason).toBe("error");
|
||||
expect(result.errorMessage).toMatch(/input length/i);
|
||||
expect(isContextOverflow(result.response, model.contextWindow)).toBe(true);
|
||||
}, 120000);
|
||||
});
|
||||
|
||||
// =============================================================================
|
||||
// Kimi For Coding
|
||||
// =============================================================================
|
||||
|
||||
@@ -130,6 +130,9 @@ const PROVIDER_MODEL_PAIRS: ProviderModelPair[] = [
|
||||
{ provider: "xiaomi-token-plan-cn", model: "mimo-v2.5-pro", label: "xiaomi-token-plan-cn-mimo-v2.5-pro" },
|
||||
{ provider: "xiaomi-token-plan-ams", model: "mimo-v2.5-pro", label: "xiaomi-token-plan-ams-mimo-v2.5-pro" },
|
||||
{ provider: "xiaomi-token-plan-sgp", model: "mimo-v2.5-pro", label: "xiaomi-token-plan-sgp-mimo-v2.5-pro" },
|
||||
// Qwen Token Plan
|
||||
{ provider: "qwen-token-plan", model: "qwen3.7-max", label: "qwen-token-plan-qwen3.7-max" },
|
||||
{ provider: "qwen-token-plan-cn", model: "qwen3.7-max", label: "qwen-token-plan-cn-qwen3.7-max" },
|
||||
];
|
||||
|
||||
// Cached context structure
|
||||
|
||||
@@ -535,6 +535,46 @@ describe("AI Providers Empty Message Tests", () => {
|
||||
},
|
||||
);
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_API_KEY)("Qwen Token Plan Provider Empty Messages", () => {
|
||||
const llm = getModel("qwen-token-plan", "qwen3.7-max");
|
||||
|
||||
it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testEmptyMessage(llm);
|
||||
});
|
||||
|
||||
it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testEmptyStringMessage(llm);
|
||||
});
|
||||
|
||||
it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testWhitespaceOnlyMessage(llm);
|
||||
});
|
||||
|
||||
it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testEmptyAssistantMessage(llm);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_CN_API_KEY)("Qwen Token Plan (CN) Provider Empty Messages", () => {
|
||||
const llm = getModel("qwen-token-plan-cn", "qwen3.7-max");
|
||||
|
||||
it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testEmptyMessage(llm);
|
||||
});
|
||||
|
||||
it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testEmptyStringMessage(llm);
|
||||
});
|
||||
|
||||
it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testWhitespaceOnlyMessage(llm);
|
||||
});
|
||||
|
||||
it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testEmptyAssistantMessage(llm);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.KIMI_API_KEY)("Kimi For Coding Provider Empty Messages", () => {
|
||||
const llm = getModel("kimi-coding", "kimi-for-coding");
|
||||
|
||||
|
||||
@@ -381,6 +381,30 @@ describe("Tool Results with Images", () => {
|
||||
},
|
||||
);
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_API_KEY)("Qwen Token Plan Provider (qwen3.7-max)", () => {
|
||||
const llm = getModel("qwen-token-plan", "qwen3.7-max");
|
||||
|
||||
it("should handle tool result with only image", { retry: 3, timeout: 30000 }, async () => {
|
||||
await handleToolWithImageResult(llm);
|
||||
});
|
||||
|
||||
it("should handle tool result with text and image", { retry: 3, timeout: 30000 }, async () => {
|
||||
await handleToolWithTextAndImageResult(llm);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_CN_API_KEY)("Qwen Token Plan (CN) Provider (qwen3.7-max)", () => {
|
||||
const llm = getModel("qwen-token-plan-cn", "qwen3.7-max");
|
||||
|
||||
it("should handle tool result with only image", { retry: 3, timeout: 30000 }, async () => {
|
||||
await handleToolWithImageResult(llm);
|
||||
});
|
||||
|
||||
it("should handle tool result with text and image", { retry: 3, timeout: 30000 }, async () => {
|
||||
await handleToolWithTextAndImageResult(llm);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.KIMI_API_KEY)("Kimi For Coding Provider (kimi-for-coding)", () => {
|
||||
const llm = getModel("kimi-coding", "kimi-for-coding");
|
||||
|
||||
|
||||
@@ -1088,6 +1088,18 @@ describe("openai-completions tool_choice", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("stores Qwen Token Plan reasoning replay compat in built-in metadata", () => {
|
||||
const providers = ["qwen-token-plan", "qwen-token-plan-cn"] as const;
|
||||
|
||||
for (const provider of providers) {
|
||||
const model = getModel(provider, "qwen3.7-max")!;
|
||||
expect(model.compat?.thinkingFormat).toBe("qwen");
|
||||
expect(model.compat?.requiresReasoningContentOnAssistantMessages).toBeUndefined();
|
||||
expect(model.compat?.supportsDeveloperRole).toBe(false);
|
||||
expect(model.compat?.supportsStore).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it("replays Xiaomi MiMo assistant tool calls with empty reasoning_content when thinking is missing", async () => {
|
||||
const model = getModel("xiaomi", "mimo-v2.5-pro")!;
|
||||
const assistantMessage: AssistantMessage = {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getModels } from "../src/compat.ts";
|
||||
|
||||
const TEXT_MODELS = [
|
||||
"MiniMax-M2.5",
|
||||
"deepseek-v3.2",
|
||||
"deepseek-v4-flash",
|
||||
"deepseek-v4-pro",
|
||||
"glm-5",
|
||||
"glm-5.1",
|
||||
"glm-5.2",
|
||||
"kimi-k2.5",
|
||||
"kimi-k2.6",
|
||||
"kimi-k2.7-code",
|
||||
"qwen3.6-flash",
|
||||
"qwen3.6-plus",
|
||||
"qwen3.7-max",
|
||||
"qwen3.7-plus",
|
||||
"qwen3.8-max-preview",
|
||||
];
|
||||
|
||||
const IMAGE_MODELS = ["qwen-image-2.0", "qwen-image-2.0-pro", "wan2.7-image", "wan2.7-image-pro"];
|
||||
|
||||
describe("Qwen Token Plan models", () => {
|
||||
it.each(["qwen-token-plan", "qwen-token-plan-cn"] as const)("exposes all text models on %s", (provider) => {
|
||||
const modelIds = getModels(provider).map((model) => model.id);
|
||||
for (const expected of TEXT_MODELS) {
|
||||
expect(modelIds, `${provider} should include ${expected}`).toContain(expected);
|
||||
}
|
||||
});
|
||||
|
||||
it.each(["qwen-token-plan", "qwen-token-plan-cn"] as const)("omits image models from %s", (provider) => {
|
||||
const modelIds = getModels(provider).map((model) => model.id);
|
||||
for (const excluded of IMAGE_MODELS) {
|
||||
expect(modelIds, `${provider} should not include ${excluded}`).not.toContain(excluded);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1168,6 +1168,65 @@ describe("Generate E2E Tests", () => {
|
||||
},
|
||||
);
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_API_KEY)(
|
||||
"Qwen Token Plan Provider (Qwen3.7-Max, international)",
|
||||
() => {
|
||||
const llm = getModel("qwen-token-plan", "qwen3.7-max");
|
||||
const thinkingOptions = {
|
||||
thinkingEnabled: true,
|
||||
reasoningEffort: "high",
|
||||
} satisfies StreamOptionsWithExtras;
|
||||
|
||||
it("should complete basic text generation", { retry: 3 }, async () => {
|
||||
await basicTextGeneration(llm);
|
||||
});
|
||||
|
||||
it("should handle tool calling", { retry: 3 }, async () => {
|
||||
await handleToolCall(llm);
|
||||
});
|
||||
|
||||
it("should handle streaming", { retry: 3 }, async () => {
|
||||
await handleStreaming(llm);
|
||||
});
|
||||
|
||||
it("should handle thinking mode", { retry: 3 }, async () => {
|
||||
await handleThinking(llm, thinkingOptions);
|
||||
});
|
||||
|
||||
it("should handle multi-turn with thinking and tools", { retry: 3 }, async () => {
|
||||
await multiTurn(llm, thinkingOptions);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_CN_API_KEY)("Qwen Token Plan Provider (Qwen3.7-Max, CN region)", () => {
|
||||
const llm = getModel("qwen-token-plan-cn", "qwen3.7-max");
|
||||
const thinkingOptions = {
|
||||
thinkingEnabled: true,
|
||||
reasoningEffort: "high",
|
||||
} satisfies StreamOptionsWithExtras;
|
||||
|
||||
it("should complete basic text generation", { retry: 3 }, async () => {
|
||||
await basicTextGeneration(llm);
|
||||
});
|
||||
|
||||
it("should handle tool calling", { retry: 3 }, async () => {
|
||||
await handleToolCall(llm);
|
||||
});
|
||||
|
||||
it("should handle streaming", { retry: 3 }, async () => {
|
||||
await handleStreaming(llm);
|
||||
});
|
||||
|
||||
it("should handle thinking mode", { retry: 3 }, async () => {
|
||||
await handleThinking(llm, thinkingOptions);
|
||||
});
|
||||
|
||||
it("should handle multi-turn with thinking and tools", { retry: 3 }, async () => {
|
||||
await multiTurn(llm, thinkingOptions);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.ANT_LING_API_KEY)("Ant Ling Provider (Ling 2.6 Flash via OpenAI Completions)", () => {
|
||||
const llm = getModel("ant-ling", "Ling-2.6-flash");
|
||||
|
||||
|
||||
@@ -276,6 +276,22 @@ describe("Token Statistics on Abort", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_API_KEY)("Qwen Token Plan Provider", () => {
|
||||
const llm = getModel("qwen-token-plan", "qwen3.7-max");
|
||||
|
||||
it("should include token stats when aborted mid-stream", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testTokensOnAbort(llm);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_CN_API_KEY)("Qwen Token Plan (CN) Provider", () => {
|
||||
const llm = getModel("qwen-token-plan-cn", "qwen3.7-max");
|
||||
|
||||
it("should include token stats when aborted mid-stream", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testTokensOnAbort(llm);
|
||||
});
|
||||
});
|
||||
|
||||
// =========================================================================
|
||||
// OAuth-based providers (credentials from ~/.pi/agent/oauth.json)
|
||||
// =========================================================================
|
||||
|
||||
@@ -254,6 +254,22 @@ describe("Tool Call Without Result Tests", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_API_KEY)("Qwen Token Plan Provider", () => {
|
||||
const model = getModel("qwen-token-plan", "qwen3.7-max");
|
||||
|
||||
it("should filter out tool calls without corresponding tool results", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testToolCallWithoutResult(model);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_CN_API_KEY)("Qwen Token Plan (CN) Provider", () => {
|
||||
const model = getModel("qwen-token-plan-cn", "qwen3.7-max");
|
||||
|
||||
it("should filter out tool calls without corresponding tool results", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testToolCallWithoutResult(model);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.KIMI_API_KEY)("Kimi For Coding Provider", () => {
|
||||
const model = getModel("kimi-coding", "kimi-for-coding");
|
||||
|
||||
|
||||
@@ -562,6 +562,56 @@ describe("totalTokens field", () => {
|
||||
);
|
||||
});
|
||||
|
||||
// =========================================================================
|
||||
// Qwen Token Plan
|
||||
// =========================================================================
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_API_KEY)("Qwen Token Plan", () => {
|
||||
it(
|
||||
"qwen3.7-max - should return totalTokens equal to sum of components",
|
||||
{ retry: 3, timeout: 60000 },
|
||||
async () => {
|
||||
const llm = getModel("qwen-token-plan", "qwen3.7-max");
|
||||
|
||||
console.log(`\nQwen Token Plan / ${llm.id}:`);
|
||||
const { first, second } = await testTotalTokensWithCache(llm, {
|
||||
apiKey: process.env.QWEN_TOKEN_PLAN_API_KEY,
|
||||
});
|
||||
|
||||
logUsage("First request", first);
|
||||
logUsage("Second request", second);
|
||||
|
||||
assertTotalTokensEqualsComponents(first);
|
||||
assertTotalTokensEqualsComponents(second);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
// =========================================================================
|
||||
// Qwen Token Plan CN
|
||||
// =========================================================================
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_CN_API_KEY)("Qwen Token Plan (CN)", () => {
|
||||
it(
|
||||
"qwen3.7-max - should return totalTokens equal to sum of components",
|
||||
{ retry: 3, timeout: 60000 },
|
||||
async () => {
|
||||
const llm = getModel("qwen-token-plan-cn", "qwen3.7-max");
|
||||
|
||||
console.log(`\nQwen Token Plan CN / ${llm.id}:`);
|
||||
const { first, second } = await testTotalTokensWithCache(llm, {
|
||||
apiKey: process.env.QWEN_TOKEN_PLAN_CN_API_KEY,
|
||||
});
|
||||
|
||||
logUsage("First request", first);
|
||||
logUsage("Second request", second);
|
||||
|
||||
assertTotalTokensEqualsComponents(first);
|
||||
assertTotalTokensEqualsComponents(second);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
// =========================================================================
|
||||
// Kimi For Coding
|
||||
// =========================================================================
|
||||
|
||||
@@ -695,6 +695,38 @@ describe("AI Providers Unicode Surrogate Pair Tests", () => {
|
||||
},
|
||||
);
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_API_KEY)("Qwen Token Plan Provider Unicode Handling", () => {
|
||||
const llm = getModel("qwen-token-plan", "qwen3.7-max");
|
||||
|
||||
it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testEmojiInToolResults(llm);
|
||||
});
|
||||
|
||||
it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testRealWorldLinkedInData(llm);
|
||||
});
|
||||
|
||||
it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testUnpairedHighSurrogate(llm);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.QWEN_TOKEN_PLAN_CN_API_KEY)("Qwen Token Plan (CN) Provider Unicode Handling", () => {
|
||||
const llm = getModel("qwen-token-plan-cn", "qwen3.7-max");
|
||||
|
||||
it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testEmojiInToolResults(llm);
|
||||
});
|
||||
|
||||
it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testRealWorldLinkedInData(llm);
|
||||
});
|
||||
|
||||
it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
|
||||
await testUnpairedHighSurrogate(llm);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!process.env.KIMI_API_KEY)("Kimi For Coding Provider Unicode Handling", () => {
|
||||
const llm = getModel("kimi-coding", "kimi-for-coding");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user