From cf319bcf355ef7fe17d2f2f1421e2fc3df653064 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 8 Nov 2026 22:03:53 +0800 Subject: [PATCH] fix(dsh): offer the compatibility editor on custom models DeepSeek Harness's pi-ai adapter sends the system prompt as role "developer" to reasoning models unless the model declares compat.supportsDeveloperRole: false. Endpoints such as DashScope's compatible mode reject that role with a 400. CC Switch already writes a model-level compat object to the DSH profile, and the presets carry the switches they need, but the provider form only rendered the compatibility editor when the model already had a compat object. Models added by hand (custom provider, fetched or typed model ids) had no way to set it outside the raw JSON editor. Render the editor for DSH models without compat too, starting empty. Nothing is written until an option is added; non-object compat values keep falling back to the generic model-properties editor. Refs #9330 --- .../providers/forms/OpenCodeFormFields.tsx | 52 ++++++++++--------- tests/components/OpenCodeFormFields.test.tsx | 37 +++++++++++++ 2 files changed, 64 insertions(+), 25 deletions(-) diff --git a/src/components/providers/forms/OpenCodeFormFields.tsx b/src/components/providers/forms/OpenCodeFormFields.tsx index c07e2a077..5b1efd62a 100644 --- a/src/components/providers/forms/OpenCodeFormFields.tsx +++ b/src/components/providers/forms/OpenCodeFormFields.tsx @@ -1054,31 +1054,33 @@ export function OpenCodeFormFields({ /> )} - {modelDialect === "dsh" && isPlainObject(model.compat) && ( - { - const { compat: _previous, ...rest } = model; - updateModel( - key, - Object.keys(compat).length > 0 - ? { ...rest, compat } - : (rest as OpenCodeModel), - ); - }} - className="sm:col-span-2" - /> - )} + {modelDialect === "dsh" && + (model.compat === undefined || + isPlainObject(model.compat)) && ( + { + const { compat: _previous, ...rest } = model; + updateModel( + key, + Object.keys(compat).length > 0 + ? { ...rest, compat } + : (rest as OpenCodeModel), + ); + }} + className="sm:col-span-2" + /> + )} {/* Model Properties (extra fields like variants, cost) */}
diff --git a/tests/components/OpenCodeFormFields.test.tsx b/tests/components/OpenCodeFormFields.test.tsx index e2a074d27..8b8280328 100644 --- a/tests/components/OpenCodeFormFields.test.tsx +++ b/tests/components/OpenCodeFormFields.test.tsx @@ -939,4 +939,41 @@ describe("OpenCodeFormFields", () => { "mimo-v2.6-pro": { ...model, reasoning: false, reasoningEfforts: false }, }); }); + + // 自定义 DSH 模型也要能填兼容性(百炼兼容模式不认 developer 角色,#9330) + it("offers DeepSeek Harness compatibility for models that have none yet", () => { + const onModelsChange = vi.fn(); + const model = { name: "DeepSeek V4.1 Flash", reasoning: true }; + renderOpenCodeForm({ + modelDialect: "dsh", + onModelsChange, + models: { "deepseek-v4.1-flash": model }, + }); + + expandFirstModel(); + expect( + screen.getByText("pi.form.noCompatibilityOptions"), + ).toBeInTheDocument(); + fireEvent.click( + screen.getByRole("button", { name: "pi.form.addCompatibilityOption" }), + ); + fireEvent.change(screen.getByPlaceholderText("supportsDeveloperRole"), { + target: { value: "supportsDeveloperRole" }, + }); + const value = screen.getByPlaceholderText("false"); + fireEvent.change(value, { target: { value: "false" } }); + fireEvent.keyDown(value, { key: "Enter" }); + expect(onModelsChange).toHaveBeenLastCalledWith({ + "deepseek-v4.1-flash": { + ...model, + compat: { supportsDeveloperRole: false }, + }, + }); + }); + + it("keeps compatibility out of OpenCode models", () => { + renderOpenCodeForm(); + expandFirstModel(); + expect(screen.queryByText("pi.form.compatibility")).not.toBeInTheDocument(); + }); });