Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,61 @@ describe('DashScopeOpenAICompatibleProvider', () => {
expect(result).toBe(true);
});

it('should return true for internal alibaba-inc.com subdomain', () => {
const config = {
authType: AuthType.USE_OPENAI,
baseUrl: 'https://gateway.alibaba-inc.com/dashscope/v1',
} as ContentGeneratorConfig;

const result =
DashScopeOpenAICompatibleProvider.isDashScopeProvider(config);
expect(result).toBe(true);
});

it('should return true for internal aliyun-inc.com subdomain', () => {
const config = {
authType: AuthType.USE_OPENAI,
baseUrl: 'https://model-gateway.aliyun-inc.com/dashscope/v1',
} as ContentGeneratorConfig;

const result =
DashScopeOpenAICompatibleProvider.isDashScopeProvider(config);
expect(result).toBe(true);
});

it('should return true for multi-level internal subdomain', () => {
const config = {
authType: AuthType.USE_OPENAI,
baseUrl: 'https://a.b.alibaba-inc.com/dashscope/v1',
} as ContentGeneratorConfig;

const result =
DashScopeOpenAICompatibleProvider.isDashScopeProvider(config);
expect(result).toBe(true);
});

it('should return false for bare alibaba-inc.com domain', () => {
const config = {
authType: AuthType.USE_OPENAI,
baseUrl: 'https://alibaba-inc.com/v1',
} as ContentGeneratorConfig;

const result =
DashScopeOpenAICompatibleProvider.isDashScopeProvider(config);
expect(result).toBe(false);
});

it('should return false for bare aliyun-inc.com domain', () => {
const config = {
authType: AuthType.USE_OPENAI,
baseUrl: 'https://aliyun-inc.com/v1',
} as ContentGeneratorConfig;

const result =
DashScopeOpenAICompatibleProvider.isDashScopeProvider(config);
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
expect(result).toBe(false);
});

it('should return false for non-DashScope configurations', () => {
const configs = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ export class DashScopeOpenAICompatibleProvider extends DefaultOpenAICompatiblePr
super(contentGeneratorConfig, cliConfig);
}

/**
* Determines whether to use the DashScope-compatible provider.
* Covers dashscope.aliyuncs.com, dashscope-intl.aliyuncs.com,
* internal Alibaba domains (*.alibaba-inc.com, *.aliyun-inc.com),
* and proxy matches.
*
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
* Note: any *.alibaba-inc.com / *.aliyun-inc.com host is treated as a
* DashScope-compatible endpoint by design. If a future internal service
* under these domains is not DashScope-compatible, narrow the match via
* a runtime provider property rather than re-introducing business-name
* subdomains here.
*/
static isDashScopeProvider(
contentGeneratorConfig: ContentGeneratorConfig,
): boolean {
Expand Down Expand Up @@ -60,6 +72,13 @@ export class DashScopeOpenAICompatibleProvider extends DefaultOpenAICompatiblePr
hostname.endsWith('.dashscope.aliyuncs.com') ||
hostname.endsWith('.dashscope-intl.aliyuncs.com'));

// Internal Alibaba domains proxying to DashScope-compatible APIs.
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
// Covers *.alibaba-inc.com and *.aliyun-inc.com.
const isInternalOrigin =
hostname !== null &&
(hostname.endsWith('.alibaba-inc.com') ||
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
hostname.endsWith('.aliyun-inc.com'));
Comment thread
yiliang114 marked this conversation as resolved.
Resolved

// Check if proxy is configured and matches
const normalizedProxyUrl = DASHSCOPE_PROXY_BASE_URL?.endsWith('/')
? DASHSCOPE_PROXY_BASE_URL.slice(0, -1)
Expand All @@ -70,13 +89,18 @@ export class DashScopeOpenAICompatibleProvider extends DefaultOpenAICompatiblePr
normalizedBaseUrl.toLowerCase() === normalizedProxyUrl.toLowerCase(),
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
);

if (normalizedProxyUrl && !isDashscopeOrigin && !isProxyMatch) {
if (
normalizedProxyUrl &&
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
!isDashscopeOrigin &&
!isInternalOrigin &&
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
!isProxyMatch
) {
debugLogger.debug(
`DASHSCOPE_PROXY_BASE_URL is configured but the request baseUrl does not match. DashScope headers/cache control will be skipped.`,
);
}

return isDashscopeOrigin || isProxyMatch;
return isDashscopeOrigin || isInternalOrigin || isProxyMatch;
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
}
Comment thread
yiliang114 marked this conversation as resolved.
Resolved

override buildHeaders(): Record<string, string | undefined> {
Expand Down
Loading