Pārlūkot izejas kodu

fix(ai): cover official DashScope plan and workspace hosts

saladday 2 mēneši atpakaļ
vecāks
revīzija
ceb224dd94

+ 20 - 0
packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts

@@ -1451,6 +1451,18 @@ describe('LocalModelResolver custom provider compat overrides', () => {
     'https://dashscope.aliyuncs.com/compatible-mode/v1',
     'https://dashscope.aliyuncs.com/compatible-mode/v1',
     'https://dashscope-intl.aliyuncs.com/compatible-mode/v1',
     'https://dashscope-intl.aliyuncs.com/compatible-mode/v1',
     'https://dashscope-us.aliyuncs.com/compatible-mode/v1',
     'https://dashscope-us.aliyuncs.com/compatible-mode/v1',
+    'https://cn-hongkong.dashscope.aliyuncs.com/compatible-mode/v1',
+    'https://coding.dashscope.aliyuncs.com/v1',
+    'https://coding-intl.dashscope.aliyuncs.com/v1',
+    'https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1',
+    'https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1',
+    'https://trial.cn-beijing.maas.aliyuncs.com/compatible-mode/v1',
+    'https://example-workspace.cn-beijing.maas.aliyuncs.com/compatible-mode/v1',
+    'https://example-workspace.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1',
+    'https://example-workspace.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1',
+    'https://example-workspace.ap-northeast-1.maas.aliyuncs.com/compatible-mode/v1',
+    'https://example-workspace.eu-central-1.maas.aliyuncs.com/compatible-mode/v1',
+    'https://example-workspace.us-east-1.maas.aliyuncs.com/compatible-mode/v1',
   ])('keeps the system role for a thinking model at %s', async (baseURL) => {
   ])('keeps the system role for a thinking model at %s', async (baseURL) => {
     expect(await systemPromptRoleFor(undefined, baseURL)).toBe('system');
     expect(await systemPromptRoleFor(undefined, baseURL)).toBe('system');
   });
   });
@@ -1461,12 +1473,20 @@ describe('LocalModelResolver custom provider compat overrides', () => {
     ['https://api.moonshot.ai/v1', 'system'],
     ['https://api.moonshot.ai/v1', 'system'],
     ['https://dashscope.aliyuncs.com.example/v1', 'developer'],
     ['https://dashscope.aliyuncs.com.example/v1', 'developer'],
     ['https://gateway.example/dashscope.aliyuncs.com/v1', 'developer'],
     ['https://gateway.example/dashscope.aliyuncs.com/v1', 'developer'],
+    ['https://coding.dashscope.aliyuncs.com.example/v1', 'developer'],
+    ['https://token-plan.cn-beijing.maas.aliyuncs.com.example/v1', 'developer'],
+    ['https://gateway.example/token-plan.cn-beijing.maas.aliyuncs.com/v1', 'developer'],
+    ['https://example-workspace.unknown-region.maas.aliyuncs.com/v1', 'developer'],
+    ['https://example-workspace.cn-beijing.aliyuncs.com/v1', 'developer'],
   ])('preserves the system prompt role for %s', async (baseURL, role) => {
   ])('preserves the system prompt role for %s', async (baseURL, role) => {
     expect(await systemPromptRoleFor(undefined, baseURL)).toBe(role);
     expect(await systemPromptRoleFor(undefined, baseURL)).toBe(role);
   });
   });
 
 
   it.each([
   it.each([
     'https://dashscope.aliyuncs.com/compatible-mode/v1',
     'https://dashscope.aliyuncs.com/compatible-mode/v1',
+    'https://coding.dashscope.aliyuncs.com/v1',
+    'https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1',
+    'https://example-workspace.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1',
   ])('honors an explicit developer-role override on %s', async (baseURL) => {
   ])('honors an explicit developer-role override on %s', async (baseURL) => {
     expect(
     expect(
       await systemPromptRoleFor(
       await systemPromptRoleFor(

+ 3 - 2
third_party/pi-mono/MINIMAX_CHANGES.md

@@ -17,9 +17,10 @@ No upstream source files are changed in the baseline import.
 
 
 - Reason: DashScope endpoints were treated as supporting the `developer` role, causing thinking-enabled OpenAI-compatible conversations to send an unsupported system-prompt role.
 - Reason: DashScope endpoints were treated as supporting the `developer` role, causing thinking-enabled OpenAI-compatible conversations to send an unsupported system-prompt role.
 - Affected package: `packages/ai` (`@earendil-works/pi-ai`), OpenAI Completions compatibility detection.
 - Affected package: `packages/ai` (`@earendil-works/pi-ai`), OpenAI Completions compatibility detection.
-- Change: default to the `system` role for the standard DashScope regional hosts (`dashscope`, `dashscope-intl`, and `dashscope-us` under `aliyuncs.com`). Preserve thinking, other request options, explicit compatibility overrides, and other providers.
+- Change: default to the `system` role for official DashScope regional and Coding Plan hosts, plus workspace, trial, and Token Plan hosts under the documented regional `maas.aliyuncs.com` domains. Preserve thinking, other request options, explicit compatibility overrides, and other providers.
+- References: [official endpoint list](https://help.aliyun.com/en/model-studio/base-url), [Coding Plan role rejection](https://github.com/openclaw/openclaw/issues/23575), [Token Plan role rejection](https://github.com/earendil-works/pi/issues/7723), and [merged OpenClaw DashScope fix](https://github.com/openclaw/openclaw/pull/24675).
 - Upstream PR: not opened.
 - Upstream PR: not opened.
-- Validation: offline request-payload regressions in `packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts`. A minimal live `qwen3.5-plus` role comparison on the China DashScope endpoint returned HTTP 200 for `system` and HTTP 400 for `developer`. Other DashScope regions remain untested; this does not establish full CLI acceptance.
+- Validation: request-payload regressions in `packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts`, including official endpoints, unrelated hosts, and explicit compatibility overrides.
 
 
 ### 2026-08-31 — Windows PowerShell ConstrainedLanguage compatibility
 ### 2026-08-31 — Windows PowerShell ConstrainedLanguage compatibility
 
 

+ 3 - 1
third_party/pi-mono/packages/ai/src/providers/openai-completions.ts

@@ -1090,7 +1090,9 @@ function detectCompat(model: Model<"openai-completions">): ResolvedOpenAIComplet
 	const isTogether =
 	const isTogether =
 		provider === "together" || baseUrl.includes("api.together.ai") || baseUrl.includes("api.together.xyz");
 		provider === "together" || baseUrl.includes("api.together.ai") || baseUrl.includes("api.together.xyz");
 	const isMoonshot = provider === "moonshotai" || provider === "moonshotai-cn" || baseUrl.includes("api.moonshot.");
 	const isMoonshot = provider === "moonshotai" || provider === "moonshotai-cn" || baseUrl.includes("api.moonshot.");
-	const isDashScope = /^https?:\/\/dashscope(?:-intl|-us)?\.aliyuncs\.com(?::\d+)?(?:\/|$)/i.test(baseUrl);
+	const isDashScope =
+		/^https?:\/\/(?:dashscope(?:-intl|-us)?|(?:coding(?:-intl)?|cn-hongkong)\.dashscope)\.aliyuncs\.com(?::\d+)?(?:\/|$)/i.test(baseUrl) ||
+		/^https?:\/\/[a-z0-9-]+\.(?:cn-beijing|cn-hongkong|ap-southeast-1|ap-northeast-1|eu-central-1|us-east-1)\.maas\.aliyuncs\.com(?::\d+)?(?:\/|$)/i.test(baseUrl);
 	const isOpenRouter = provider === "openrouter" || baseUrl.includes("openrouter.ai");
 	const isOpenRouter = provider === "openrouter" || baseUrl.includes("openrouter.ai");
 	const isCloudflareWorkersAI = provider === "cloudflare-workers-ai" || baseUrl.includes("api.cloudflare.com");
 	const isCloudflareWorkersAI = provider === "cloudflare-workers-ai" || baseUrl.includes("api.cloudflare.com");
 	const isCloudflareAiGateway = provider === "cloudflare-ai-gateway" || baseUrl.includes("gateway.ai.cloudflare.com");
 	const isCloudflareAiGateway = provider === "cloudflare-ai-gateway" || baseUrl.includes("gateway.ai.cloudflare.com");