mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-28 03:30:40 +00:00
fix(cli): extend preconnect allowlist to cover all DashScope regional endpoints
Import ALIBABA_STANDARD_API_KEY_ENDPOINTS so isDefaultBaseUrl() accepts dashscope-intl (sg), dashscope-us (us-virginia), and cn-hongkong in addition to the mainland cn-beijing endpoint. Also fix the test mock factory to avoid importing the real core package. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
ac82e37e2c
commit
b20896352c
2 changed files with 48 additions and 2 deletions
|
|
@ -95,6 +95,39 @@ describe('apiPreconnect', () => {
|
|||
expect(mockFetch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should accept DashScope regional endpoint (sg-singapore)', () => {
|
||||
preconnectApi('openai', {
|
||||
resolvedBaseUrl:
|
||||
'https://dashscope-intl.aliyuncs.com/compatible-mode/v1',
|
||||
});
|
||||
expect(mockFetch).toHaveBeenCalledWith(
|
||||
'https://dashscope-intl.aliyuncs.com/compatible-mode/v1',
|
||||
expect.objectContaining({ method: 'HEAD' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should accept DashScope regional endpoint (us-virginia)', () => {
|
||||
preconnectApi('openai', {
|
||||
resolvedBaseUrl:
|
||||
'https://dashscope-us.aliyuncs.com/compatible-mode/v1',
|
||||
});
|
||||
expect(mockFetch).toHaveBeenCalledWith(
|
||||
'https://dashscope-us.aliyuncs.com/compatible-mode/v1',
|
||||
expect.objectContaining({ method: 'HEAD' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should accept DashScope regional endpoint (cn-hongkong)', () => {
|
||||
preconnectApi('openai', {
|
||||
resolvedBaseUrl:
|
||||
'https://cn-hongkong.dashscope.aliyuncs.com/compatible-mode/v1',
|
||||
});
|
||||
expect(mockFetch).toHaveBeenCalledWith(
|
||||
'https://cn-hongkong.dashscope.aliyuncs.com/compatible-mode/v1',
|
||||
expect.objectContaining({ method: 'HEAD' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should fall back to default URL when resolvedBaseUrl is undefined', () => {
|
||||
preconnectApi('qwen-oauth');
|
||||
expect(mockFetch).toHaveBeenCalledWith(
|
||||
|
|
|
|||
|
|
@ -21,12 +21,16 @@ import {
|
|||
getOrCreateSharedDispatcher,
|
||||
} from '@qwen-code/qwen-code-core';
|
||||
|
||||
import { ALIBABA_STANDARD_API_KEY_ENDPOINTS } from '../constants/alibabaStandardApiKey.js';
|
||||
|
||||
const debugLogger = createDebugLogger('PRECONNECT');
|
||||
|
||||
let preconnectFired = false;
|
||||
|
||||
/**
|
||||
* Default API base URLs by AuthType
|
||||
* Default API base URLs by AuthType.
|
||||
* DashScope regional endpoints are derived from ALIBABA_STANDARD_API_KEY_ENDPOINTS
|
||||
* so preconnect covers all supported regions (cn-beijing, sg-singapore, us-virginia, cn-hongkong).
|
||||
*/
|
||||
const DEFAULT_BASE_URLS: Record<string, string> = {
|
||||
openai: 'https://api.openai.com',
|
||||
|
|
@ -35,6 +39,15 @@ const DEFAULT_BASE_URLS: Record<string, string> = {
|
|||
dashscope: 'https://dashscope.aliyuncs.com',
|
||||
};
|
||||
|
||||
/**
|
||||
* All known default base URLs, including DashScope regional endpoints.
|
||||
* Used by isDefaultBaseUrl() to accept any supported default endpoint.
|
||||
*/
|
||||
const ALL_DEFAULT_URLS: string[] = [
|
||||
...Object.values(DEFAULT_BASE_URLS),
|
||||
...Object.values(ALIBABA_STANDARD_API_KEY_ENDPOINTS),
|
||||
];
|
||||
|
||||
/**
|
||||
* Check if preconnect should be skipped due to environment conditions
|
||||
*/
|
||||
|
|
@ -64,7 +77,7 @@ function isDefaultBaseUrl(baseUrl: string): boolean {
|
|||
.toLowerCase()
|
||||
.replace(/^https?:\/\//, '')
|
||||
.replace(/\/+$/, '');
|
||||
return Object.values(DEFAULT_BASE_URLS).some((defaultUrl) => {
|
||||
return ALL_DEFAULT_URLS.some((defaultUrl) => {
|
||||
const normalizedDefault = defaultUrl
|
||||
.toLowerCase()
|
||||
.replace(/^https?:\/\//, '')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue