Explorar o código

test(core): B7 piModel.id uses deploymentName for CodingPlan models

fanghanjun hai 6 meses
pai
achega
65ebd8da1f

+ 26 - 0
packages/core/src/__tests__/provider.test.ts

@@ -647,4 +647,30 @@ describe("createLLMClient with providers lookup", () => {
     }));
     }));
     expect(client.defaults.maxTokens).toBe(64_000);
     expect(client.defaults.maxTokens).toBe(64_000);
   });
   });
+
+  it("B7: kimiCodingPlan 的 kimi-k2.5 走 API 时 piModel.id 是 deploymentName (k2p5)", async () => {
+    const { createLLMClient } = await import("../llm/provider.js");
+    const { LLMConfigSchema } = await import("../models/project.js");
+    const client = createLLMClient(LLMConfigSchema.parse({
+      provider: "anthropic",
+      service: "kimiCodingPlan",
+      model: "kimi-k2.5",
+      apiKey: "test",
+      baseUrl: "https://api.moonshot.cn/anthropic",
+    }));
+    expect(client._piModel?.id).toBe("k2p5");
+  });
+
+  it("B7: 没有 deploymentName 的 model piModel.id 保持原 config.model", async () => {
+    const { createLLMClient } = await import("../llm/provider.js");
+    const { LLMConfigSchema } = await import("../models/project.js");
+    const client = createLLMClient(LLMConfigSchema.parse({
+      provider: "anthropic",
+      service: "kimiCodingPlan",
+      model: "kimi-k2-thinking",
+      apiKey: "test",
+      baseUrl: "https://api.moonshot.cn/anthropic",
+    }));
+    expect(client._piModel?.id).toBe("kimi-k2-thinking");
+  });
 });
 });

+ 4 - 4
packages/core/src/llm/provider.ts

@@ -154,15 +154,15 @@ export interface ChatWithToolsResult {
 // === Factory ===
 // === Factory ===
 
 
 export function createLLMClient(config: LLMConfig): LLMClient {
 export function createLLMClient(config: LLMConfig): LLMClient {
-  // 提前查一次 modelCard 以便给 defaults.maxTokens 做 fallback(A 组过渡期逻辑,见下面 piModel 再查一次是幂等的)
+  // 提前查一次 modelCard,用于 defaults.maxTokens 推导(下面 piModel 构造再查一次是幂等的)
   const _earlyCard = lookupModel(config.service ?? "custom", config.model);
   const _earlyCard = lookupModel(config.service ?? "custom", config.model);
   const defaults = {
   const defaults = {
     temperature: config.temperature ?? 0.7,
     temperature: config.temperature ?? 0.7,
-    // fallback: agent 没传 per-call 时用这个。优先 config.maxTokens(过渡期兼容),否则 modelCard.maxOutput,否则 8192
-    maxTokens: config.maxTokens ?? _earlyCard?.maxOutput ?? 8192,
+    // A 组起:providers 接管 — 命中 modelCard 用其 maxOutput,否则 fallback 到 config.maxTokens / 8192
+    maxTokens: _earlyCard?.maxOutput ?? config.maxTokens ?? 8192,
     // cap: 只在用户显式配 maxTokensCap 时生效;默认 null = 不封顶 per-call。
     // cap: 只在用户显式配 maxTokensCap 时生效;默认 null = 不封顶 per-call。
     // **禁止**改成 `config.maxTokens ?? null` —— 那样会让 architect 的 per-call
     // **禁止**改成 `config.maxTokens ?? null` —— 那样会让 architect 的 per-call
-    // 16384 被用户 config.maxTokens=8192 自动裁剪,基础设定输出会被截断。
+    // 16384 被用户 config.maxTokens=8192 自动裁剪,基础设定输出被截断。
     maxTokensCap: config.maxTokensCap ?? null,
     maxTokensCap: config.maxTokensCap ?? null,
     thinkingBudget: config.thinkingBudget ?? 0,
     thinkingBudget: config.thinkingBudget ?? 0,
     extra: config.extra ?? {},
     extra: config.extra ?? {},