fix(qwen): preserve custom modelstudio providers

This commit is contained in:
Peter Steinberger
2026-04-27 12:24:05 +01:00
parent dca9fa471f
commit 5afa24a9fc
8 changed files with 205 additions and 8 deletions

View File

@@ -0,0 +1,49 @@
import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../../src/config/types.js";
import { registerSingleProviderPlugin } from "../../src/test-utils/plugin-registration.js";
import qwenPlugin from "./index.js";
async function registerQwenProvider() {
return registerSingleProviderPlugin(qwenPlugin);
}
describe("qwen provider plugin", () => {
it("does not suppress exact custom modelstudio providers owned by another api", async () => {
const provider = await registerQwenProvider();
const config = {
models: {
providers: {
modelstudio: {
api: "openai-completions",
baseUrl: "https://coding-intl.dashscope.aliyuncs.com/v1",
models: [{ id: "qwen3.6-plus", name: "Qwen 3.6 Plus" }],
},
},
},
} as unknown as OpenClawConfig;
expect(
provider.suppressBuiltInModel?.({
config,
env: {},
provider: "modelstudio",
modelId: "qwen3.6-plus",
baseUrl: "https://coding-intl.dashscope.aliyuncs.com/v1",
}),
).toBeUndefined();
});
it("still suppresses legacy modelstudio refs on Qwen Coding Plan endpoints", async () => {
const provider = await registerQwenProvider();
expect(
provider.suppressBuiltInModel?.({
config: {},
env: {},
provider: "modelstudio",
modelId: "qwen3.6-plus",
baseUrl: "https://coding-intl.dashscope.aliyuncs.com/v1",
})?.suppress,
).toBe(true);
});
});

View File

@@ -47,6 +47,22 @@ function isQwen36PlusUnsupportedForConfig(params: {
return isQwenCodingPlanBaseUrl(params.baseUrl ?? resolveConfiguredQwenBaseUrl(params.config));
}
function hasExactForeignApiOwner(params: {
provider: string;
config: { models?: { providers?: Record<string, { api?: string } | undefined> } } | undefined;
}): boolean {
const providers = params.config?.models?.providers;
if (!providers) {
return false;
}
const provider = normalizeProviderId(params.provider);
const exact = Object.entries(providers).find(
([providerId]) => normalizeProviderId(providerId) === provider,
)?.[1];
const api = normalizeProviderId(exact?.api ?? "");
return !!api && api !== PROVIDER_ID && api !== LEGACY_PROVIDER_ID;
}
export default defineSingleProviderPluginEntry({
id: PROVIDER_ID,
name: "Qwen Provider",
@@ -180,6 +196,7 @@ export default defineSingleProviderPluginEntry({
const provider = normalizeProviderId(ctx.provider);
if (
(provider !== PROVIDER_ID && provider !== LEGACY_PROVIDER_ID) ||
hasExactForeignApiOwner({ provider: ctx.provider, config: ctx.config }) ||
ctx.modelId !== QWEN_36_PLUS_MODEL_ID ||
!isQwen36PlusUnsupportedForConfig({ config: ctx.config, baseUrl: ctx.baseUrl })
) {