Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion src/client/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type {
} from './types';
import { EXTERNAL_URLS } from '../consts';

export const OFFICIAL_DEEPSEEK_API_HOST = 'api.deepseek.com';
export const MAX_DIAGNOSTIC_FIELD_LENGTH = 300;

export const API_PROVIDER_HTTP_ERROR_LINKS: Readonly<
Expand Down
14 changes: 3 additions & 11 deletions src/client/error/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { isOfficialDeepSeekBaseUrl } from '../../endpoint';
import { t } from '../../i18n';
import { safeStringify } from '../../json';
import {
API_PROVIDER_HTTP_ERROR_LINKS,
MAX_DIAGNOSTIC_FIELD_LENGTH,
OFFICIAL_DEEPSEEK_API_HOST,
} from '../consts';
import { API_PROVIDER_HTTP_ERROR_LINKS, MAX_DIAGNOSTIC_FIELD_LENGTH } from '../consts';
import { getNetworkErrorCauseInfo, getNetworkErrorCode, getNetworkErrorMessage } from './network';
import type {
ApiProviderId,
Expand Down Expand Up @@ -322,12 +319,7 @@ function escapeBoldText(value: string): string {
}

function identifyApiProvider(baseUrl: string): ApiProviderId | undefined {
try {
const hostname = new URL(baseUrl).hostname.toLowerCase();
return hostname === OFFICIAL_DEEPSEEK_API_HOST ? 'deepseek' : undefined;
} catch {
return undefined;
}
return isOfficialDeepSeekBaseUrl(baseUrl) ? 'deepseek' : undefined;
}

function getHttpErrorLinkStatusKey(status: number): HttpErrorLinkStatusKey | undefined {
Expand Down
13 changes: 13 additions & 0 deletions src/endpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const OFFICIAL_DEEPSEEK_API_HOST = 'api.deepseek.com';

export function isOfficialDeepSeekBaseUrl(baseUrl: string): boolean {
try {
return new URL(baseUrl).hostname.toLowerCase() === OFFICIAL_DEEPSEEK_API_HOST;
} catch {
return false;
}
}

export function normalizeBaseUrl(baseUrl: string): string {
return baseUrl.trim().replace(/\/+$/u, '');
}
14 changes: 1 addition & 13 deletions src/provider/pricing/currency.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import vscode from 'vscode';
import { AuthManager } from '../../auth';
import { OFFICIAL_DEEPSEEK_API_HOST } from '../../client/consts';
import { getBaseUrl } from '../../config';
import { isOfficialDeepSeekBaseUrl, normalizeBaseUrl } from '../../endpoint';
import { logger } from '../../logger';
import type { PricingCurrency } from '../../types';

Expand Down Expand Up @@ -133,18 +133,6 @@ export class BalanceCurrencyResolver {
}
}

export function isOfficialDeepSeekBaseUrl(baseUrl: string): boolean {
try {
return new URL(baseUrl).hostname.toLowerCase() === OFFICIAL_DEEPSEEK_API_HOST;
} catch {
return false;
}
}

export function normalizeBaseUrl(baseUrl: string): string {
return baseUrl.trim().replace(/\/+$/u, '');
}

function getLocaleFallbackCurrency(): PricingCurrency {
return vscode.env.language.toLowerCase().startsWith('zh') ? 'CNY' : 'USD';
}
Expand Down
10 changes: 8 additions & 2 deletions src/provider/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AuthManager } from '../auth';
import { DeepSeekClient } from '../client';
import { getApiModelId, getBaseUrl, getMaxTokens } from '../config';
import { MODELS } from '../consts';
import { isOfficialDeepSeekBaseUrl } from '../endpoint';
import { t } from '../i18n';
import type { DeepSeekRequest } from '../types';
import { convertMessages, countMessageChars } from './convert';
Expand Down Expand Up @@ -60,7 +61,8 @@ export async function prepareChatRequest({
throw new Error(t('auth.notConfigured'));
}

const client = new DeepSeekClient(getBaseUrl(), apiKey);
const baseUrl = getBaseUrl();
const client = new DeepSeekClient(baseUrl, apiKey);
Comment thread
Vizards marked this conversation as resolved.
const modelDef = MODELS.find((m) => m.id === modelInfo.id);
const isThinkingModel = modelDef?.capabilities.thinking ?? false;
const maxTokens = getMaxTokens();
Expand All @@ -86,7 +88,11 @@ export async function prepareChatRequest({
const configuredThinkingEffort = getConfiguredThinkingEffort(
options as ModelConfigurationOptions,
);
const thinkingEffort = shouldForceThinkingNone(requestKind) ? 'none' : configuredThinkingEffort;
// Only force helper requests into disabled thinking on the official API.
// Custom endpoints keep their configured effort to preserve pre-#137 request shape.
const forceNoneThinking =
shouldForceThinkingNone(requestKind) && isOfficialDeepSeekBaseUrl(baseUrl);
const thinkingEffort = forceNoneThinking ? 'none' : configuredThinkingEffort;
const request: DeepSeekRequest = {
...baseRequest,
...(isThinkingModel
Expand Down
Loading