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
This commit is contained in:
Jason
2026-11-08 22:03:53 +08:00
parent c0a8d87b19
commit cf319bcf35
2 changed files with 64 additions and 25 deletions
@@ -1054,31 +1054,33 @@ export function OpenCodeFormFields({
/>
)}
{modelDialect === "dsh" && isPlainObject(model.compat) && (
<StructuredOptionsEditor
id={`opencode-${key}-compat`}
title={t("pi.form.compatibility")}
hint={t("pi.form.compatibilityHint")}
addLabel={t("pi.form.addCompatibilityOption")}
emptyLabel={t("pi.form.noCompatibilityOptions")}
keyLabel={t("pi.form.optionKey")}
valueLabel={t("pi.form.optionValue")}
keyPlaceholder="supportsDeveloperRole"
valuePlaceholder="false"
removeLabel={t("pi.form.removeCompatibilityOption")}
options={model.compat}
onOptionsChange={(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)) && (
<StructuredOptionsEditor
id={`opencode-${key}-compat`}
title={t("pi.form.compatibility")}
hint={t("pi.form.compatibilityHint")}
addLabel={t("pi.form.addCompatibilityOption")}
emptyLabel={t("pi.form.noCompatibilityOptions")}
keyLabel={t("pi.form.optionKey")}
valueLabel={t("pi.form.optionValue")}
keyPlaceholder="supportsDeveloperRole"
valuePlaceholder="false"
removeLabel={t("pi.form.removeCompatibilityOption")}
options={model.compat ?? {}}
onOptionsChange={(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) */}
<div className="space-y-2 sm:col-span-2">
@@ -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();
});
});