@lobehub/chat 1.124.0 → 1.124.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +5 -0
- package/.github/scripts/pr-comment.js +11 -2
- package/.github/workflows/desktop-pr-build.yml +86 -12
- package/.github/workflows/release-desktop-beta.yml +91 -20
- package/CHANGELOG.md +58 -0
- package/Dockerfile +2 -0
- package/Dockerfile.database +2 -0
- package/Dockerfile.pglite +2 -0
- package/apps/desktop/electron-builder.js +8 -4
- package/changelog/v1.json +21 -0
- package/docs/self-hosting/environment-variables/model-provider.mdx +18 -0
- package/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx +20 -0
- package/locales/ar/chat.json +2 -0
- package/locales/bg-BG/chat.json +2 -0
- package/locales/de-DE/chat.json +2 -0
- package/locales/en-US/chat.json +2 -0
- package/locales/es-ES/chat.json +2 -0
- package/locales/fa-IR/chat.json +2 -0
- package/locales/fr-FR/chat.json +2 -0
- package/locales/it-IT/chat.json +2 -0
- package/locales/ja-JP/chat.json +2 -0
- package/locales/ko-KR/chat.json +2 -0
- package/locales/nl-NL/chat.json +2 -0
- package/locales/pl-PL/chat.json +2 -0
- package/locales/pt-BR/chat.json +2 -0
- package/locales/ru-RU/chat.json +2 -0
- package/locales/tr-TR/chat.json +2 -0
- package/locales/vi-VN/chat.json +2 -0
- package/locales/zh-CN/chat.json +2 -0
- package/locales/zh-CN/modelProvider.json +1 -1
- package/locales/zh-TW/chat.json +2 -0
- package/package.json +1 -1
- package/packages/const/src/hotkeys.ts +1 -1
- package/packages/const/src/index.ts +1 -0
- package/packages/const/src/settings/hotkey.ts +3 -2
- package/packages/const/src/trace.ts +1 -1
- package/packages/const/src/user.ts +1 -2
- package/packages/database/src/client/db.test.ts +19 -13
- package/packages/electron-server-ipc/src/ipcClient.test.ts +783 -1
- package/packages/file-loaders/src/loadFile.test.ts +61 -0
- package/packages/file-loaders/src/utils/isTextReadableFile.test.ts +43 -0
- package/packages/file-loaders/src/utils/parser-utils.test.ts +155 -0
- package/packages/model-bank/src/aiModels/aihubmix.ts +38 -4
- package/packages/model-bank/src/aiModels/groq.ts +26 -8
- package/packages/model-bank/src/aiModels/hunyuan.ts +3 -3
- package/packages/model-bank/src/aiModels/modelscope.ts +13 -2
- package/packages/model-bank/src/aiModels/moonshot.ts +25 -5
- package/packages/model-bank/src/aiModels/novita.ts +40 -9
- package/packages/model-bank/src/aiModels/openrouter.ts +0 -13
- package/packages/model-bank/src/aiModels/qwen.ts +62 -1
- package/packages/model-bank/src/aiModels/siliconcloud.ts +20 -0
- package/packages/model-bank/src/aiModels/volcengine.ts +141 -15
- package/packages/model-runtime/package.json +2 -1
- package/packages/model-runtime/src/ai21/index.test.ts +2 -2
- package/packages/model-runtime/src/ai360/index.test.ts +2 -2
- package/packages/model-runtime/src/akashchat/index.test.ts +19 -0
- package/packages/model-runtime/src/anthropic/index.test.ts +1 -2
- package/packages/model-runtime/src/baichuan/index.test.ts +1 -2
- package/packages/model-runtime/src/bedrock/index.test.ts +1 -2
- package/packages/model-runtime/src/bfl/createImage.test.ts +1 -2
- package/packages/model-runtime/src/bfl/index.test.ts +1 -2
- package/packages/model-runtime/src/cloudflare/index.test.ts +1 -2
- package/packages/model-runtime/src/cohere/index.test.ts +19 -0
- package/packages/model-runtime/src/deepseek/index.test.ts +2 -2
- package/packages/model-runtime/src/fireworksai/index.test.ts +2 -2
- package/packages/model-runtime/src/giteeai/index.test.ts +2 -2
- package/packages/model-runtime/src/github/index.test.ts +2 -2
- package/packages/model-runtime/src/google/createImage.test.ts +1 -2
- package/packages/model-runtime/src/google/index.test.ts +1 -1
- package/packages/model-runtime/src/groq/index.test.ts +2 -3
- package/packages/model-runtime/src/huggingface/index.test.ts +40 -0
- package/packages/model-runtime/src/hunyuan/index.test.ts +2 -3
- package/packages/model-runtime/src/internlm/index.test.ts +2 -2
- package/packages/model-runtime/src/jina/index.test.ts +19 -0
- package/packages/model-runtime/src/lmstudio/index.test.ts +2 -2
- package/packages/model-runtime/src/minimax/index.test.ts +19 -0
- package/packages/model-runtime/src/mistral/index.test.ts +2 -3
- package/packages/model-runtime/src/modelscope/index.test.ts +19 -0
- package/packages/model-runtime/src/moonshot/index.test.ts +1 -2
- package/packages/model-runtime/src/nebius/index.test.ts +19 -0
- package/packages/model-runtime/src/newapi/index.test.ts +49 -42
- package/packages/model-runtime/src/newapi/index.ts +124 -143
- package/packages/model-runtime/src/novita/index.test.ts +3 -4
- package/packages/model-runtime/src/nvidia/index.test.ts +19 -0
- package/packages/model-runtime/src/openrouter/index.test.ts +2 -3
- package/packages/model-runtime/src/perplexity/index.test.ts +2 -3
- package/packages/model-runtime/src/ppio/index.test.ts +3 -4
- package/packages/model-runtime/src/qwen/index.test.ts +2 -2
- package/packages/model-runtime/src/sambanova/index.test.ts +19 -0
- package/packages/model-runtime/src/search1api/index.test.ts +19 -0
- package/packages/model-runtime/src/sensenova/index.test.ts +2 -2
- package/packages/model-runtime/src/spark/index.test.ts +2 -2
- package/packages/model-runtime/src/stepfun/index.test.ts +2 -2
- package/packages/model-runtime/src/taichu/index.test.ts +4 -5
- package/packages/model-runtime/src/tencentcloud/index.test.ts +1 -1
- package/packages/model-runtime/src/togetherai/index.test.ts +1 -2
- package/packages/model-runtime/src/upstage/index.test.ts +1 -2
- package/packages/model-runtime/src/utils/openaiCompatibleFactory/index.test.ts +9 -7
- package/packages/model-runtime/src/utils/streams/anthropic.ts +2 -2
- package/packages/model-runtime/src/utils/streams/openai/openai.ts +20 -13
- package/packages/model-runtime/src/utils/streams/openai/responsesStream.test.ts +1 -2
- package/packages/model-runtime/src/utils/streams/openai/responsesStream.ts +2 -2
- package/packages/model-runtime/src/utils/streams/protocol.ts +2 -2
- package/packages/model-runtime/src/wenxin/index.test.ts +2 -3
- package/packages/model-runtime/src/xai/index.test.ts +2 -2
- package/packages/model-runtime/src/zeroone/index.test.ts +1 -2
- package/packages/model-runtime/src/zhipu/index.test.ts +2 -3
- package/packages/model-runtime/vitest.config.mts +0 -7
- package/packages/types/src/index.ts +2 -0
- package/packages/types/src/message/base.ts +1 -1
- package/packages/types/src/openai/chat.ts +2 -3
- package/packages/utils/package.json +2 -1
- package/packages/utils/src/_deprecated/parseModels.test.ts +1 -1
- package/packages/utils/src/_deprecated/parseModels.ts +1 -1
- package/packages/utils/src/client/topic.test.ts +1 -2
- package/packages/utils/src/client/topic.ts +1 -2
- package/packages/utils/src/electron/desktopRemoteRPCFetch.ts +1 -1
- package/packages/utils/src/fetch/fetchSSE.ts +7 -8
- package/packages/utils/src/fetch/parseError.ts +1 -3
- package/packages/utils/src/format.test.ts +1 -2
- package/packages/utils/src/index.ts +1 -0
- package/packages/utils/src/toolManifest.ts +1 -2
- package/packages/utils/src/trace.ts +1 -1
- package/packages/utils/vitest.config.mts +1 -1
- package/packages/web-crawler/src/__tests__/urlRules.test.ts +275 -0
- package/packages/web-crawler/src/crawImpl/__tests__/exa.test.ts +269 -0
- package/packages/web-crawler/src/crawImpl/__tests__/firecrawl.test.ts +284 -0
- package/packages/web-crawler/src/crawImpl/__tests__/naive.test.ts +234 -0
- package/packages/web-crawler/src/crawImpl/__tests__/tavily.test.ts +359 -0
- package/packages/web-crawler/src/utils/__tests__/errorType.test.ts +217 -0
- package/packages/web-crawler/vitest.config.mts +3 -0
- package/scripts/electronWorkflow/mergeMacReleaseFiles.ts +207 -0
- package/src/app/[variants]/(main)/settings/provider/(detail)/newapi/page.tsx +1 -1
- package/src/components/Thinking/index.tsx +2 -3
- package/src/config/llm.ts +8 -0
- package/src/features/ChatInput/Desktop/index.tsx +16 -4
- package/src/features/ChatInput/StoreUpdater.tsx +2 -0
- package/src/libs/traces/index.ts +1 -1
- package/src/locales/default/chat.ts +1 -0
- package/src/locales/default/modelProvider.ts +1 -1
- package/src/server/modules/ModelRuntime/trace.ts +1 -2
- package/src/store/chat/slices/aiChat/actions/__tests__/cancel-functionality.test.ts +107 -0
- package/src/store/chat/slices/aiChat/actions/__tests__/generateAIChatV2.test.ts +352 -7
- package/src/store/chat/slices/aiChat/actions/generateAIChatV2.ts +2 -1
- package/packages/model-runtime/src/openrouter/__snapshots__/index.test.ts.snap +0 -113
@@ -1,9 +1,8 @@
|
|
1
1
|
// @vitest-environment node
|
2
|
+
import { LobeOpenAICompatibleRuntime } from '@lobechat/model-runtime';
|
2
3
|
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
3
4
|
|
4
|
-
import {
|
5
|
-
import { testProvider } from '@/libs/model-runtime/providerTestUtils';
|
6
|
-
|
5
|
+
import { testProvider } from '../providerTestUtils';
|
7
6
|
import { LobeMistralAI } from './index';
|
8
7
|
|
9
8
|
testProvider({
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// @vitest-environment node
|
2
|
+
import { ModelProvider } from '@lobechat/model-runtime';
|
3
|
+
|
4
|
+
import { testProvider } from '../providerTestUtils';
|
5
|
+
import { LobeModelScopeAI } from './index';
|
6
|
+
|
7
|
+
const provider = ModelProvider.ModelScope;
|
8
|
+
const defaultBaseURL = 'https://api-inference.modelscope.cn/v1';
|
9
|
+
|
10
|
+
testProvider({
|
11
|
+
Runtime: LobeModelScopeAI,
|
12
|
+
provider,
|
13
|
+
defaultBaseURL,
|
14
|
+
chatDebugEnv: 'DEBUG_MODELSCOPE_CHAT_COMPLETION',
|
15
|
+
chatModel: 'qwen2-7b-instruct',
|
16
|
+
test: {
|
17
|
+
skipAPICall: true,
|
18
|
+
},
|
19
|
+
});
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// @vitest-environment node
|
2
|
+
import { ModelProvider } from '@lobechat/model-runtime';
|
3
|
+
|
4
|
+
import { testProvider } from '../providerTestUtils';
|
5
|
+
import { LobeNebiusAI } from './index';
|
6
|
+
|
7
|
+
const provider = ModelProvider.Nebius;
|
8
|
+
const defaultBaseURL = 'https://api.studio.nebius.com/v1';
|
9
|
+
|
10
|
+
testProvider({
|
11
|
+
Runtime: LobeNebiusAI,
|
12
|
+
provider,
|
13
|
+
defaultBaseURL,
|
14
|
+
chatDebugEnv: 'DEBUG_NEBIUS_CHAT_COMPLETION',
|
15
|
+
chatModel: 'meta/llama-3.1-8b-instruct',
|
16
|
+
test: {
|
17
|
+
skipAPICall: true,
|
18
|
+
},
|
19
|
+
});
|
@@ -62,7 +62,7 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
62
62
|
describe('HandlePayload Function Branch Coverage - Direct Testing', () => {
|
63
63
|
// Create a mock Set for testing
|
64
64
|
let testResponsesAPIModels: Set<string>;
|
65
|
-
|
65
|
+
|
66
66
|
const testHandlePayload = (payload: ChatStreamPayload) => {
|
67
67
|
// This replicates the exact handlePayload logic from the source
|
68
68
|
if (
|
@@ -85,7 +85,7 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
85
85
|
};
|
86
86
|
|
87
87
|
const result = testHandlePayload(payload);
|
88
|
-
|
88
|
+
|
89
89
|
expect(result).toEqual({ ...payload, apiMode: 'responses' });
|
90
90
|
});
|
91
91
|
|
@@ -99,7 +99,7 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
99
99
|
};
|
100
100
|
|
101
101
|
const result = testHandlePayload(payload);
|
102
|
-
|
102
|
+
|
103
103
|
expect(result).toEqual({ ...payload, apiMode: 'responses' });
|
104
104
|
});
|
105
105
|
|
@@ -113,7 +113,7 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
113
113
|
};
|
114
114
|
|
115
115
|
const result = testHandlePayload(payload);
|
116
|
-
|
116
|
+
|
117
117
|
expect(result).toEqual({ ...payload, apiMode: 'responses' });
|
118
118
|
});
|
119
119
|
|
@@ -127,7 +127,7 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
127
127
|
};
|
128
128
|
|
129
129
|
const result = testHandlePayload(payload);
|
130
|
-
|
130
|
+
|
131
131
|
expect(result).toEqual({ ...payload, apiMode: 'responses' });
|
132
132
|
});
|
133
133
|
|
@@ -141,7 +141,7 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
141
141
|
};
|
142
142
|
|
143
143
|
const result = testHandlePayload(payload);
|
144
|
-
|
144
|
+
|
145
145
|
expect(result).toEqual(payload);
|
146
146
|
});
|
147
147
|
});
|
@@ -207,7 +207,7 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
207
207
|
|
208
208
|
describe('Models Function Branch Coverage - Logical Testing', () => {
|
209
209
|
// Test the complex models function logic by replicating its branching behavior
|
210
|
-
|
210
|
+
|
211
211
|
describe('Data Handling Branches', () => {
|
212
212
|
it('should handle undefined data from models.list (Branch 3.1: data = undefined)', () => {
|
213
213
|
const data = undefined;
|
@@ -293,63 +293,63 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
293
293
|
it('should use model_price when > 0 (Branch 3.8: model_price && model_price > 0 = true)', () => {
|
294
294
|
const pricing = { model_price: 15, model_ratio: 10 };
|
295
295
|
let inputPrice;
|
296
|
-
|
296
|
+
|
297
297
|
if (pricing.model_price && pricing.model_price > 0) {
|
298
298
|
inputPrice = pricing.model_price * 2;
|
299
299
|
} else if (pricing.model_ratio) {
|
300
300
|
inputPrice = pricing.model_ratio * 2;
|
301
301
|
}
|
302
|
-
|
302
|
+
|
303
303
|
expect(inputPrice).toBe(30); // model_price * 2
|
304
304
|
});
|
305
305
|
|
306
306
|
it('should fallback to model_ratio when model_price = 0 (Branch 3.8: model_price > 0 = false, Branch 3.9: model_ratio = true)', () => {
|
307
307
|
const pricing = { model_price: 0, model_ratio: 12 };
|
308
308
|
let inputPrice;
|
309
|
-
|
309
|
+
|
310
310
|
if (pricing.model_price && pricing.model_price > 0) {
|
311
311
|
inputPrice = pricing.model_price * 2;
|
312
312
|
} else if (pricing.model_ratio) {
|
313
313
|
inputPrice = pricing.model_ratio * 2;
|
314
314
|
}
|
315
|
-
|
315
|
+
|
316
316
|
expect(inputPrice).toBe(24); // model_ratio * 2
|
317
317
|
});
|
318
318
|
|
319
319
|
it('should handle missing model_ratio (Branch 3.9: model_ratio = undefined)', () => {
|
320
320
|
const pricing: Partial<NewAPIPricing> = { quota_type: 0 }; // No model_price and no model_ratio
|
321
321
|
let inputPrice: number | undefined;
|
322
|
-
|
322
|
+
|
323
323
|
if (pricing.model_price && pricing.model_price > 0) {
|
324
324
|
inputPrice = pricing.model_price * 2;
|
325
325
|
} else if (pricing.model_ratio) {
|
326
326
|
inputPrice = pricing.model_ratio * 2;
|
327
327
|
}
|
328
|
-
|
328
|
+
|
329
329
|
expect(inputPrice).toBeUndefined();
|
330
330
|
});
|
331
331
|
|
332
332
|
it('should calculate output price when inputPrice is defined (Branch 3.10: inputPrice !== undefined = true)', () => {
|
333
333
|
const inputPrice = 20;
|
334
334
|
const completionRatio = 1.5;
|
335
|
-
|
335
|
+
|
336
336
|
let outputPrice;
|
337
337
|
if (inputPrice !== undefined) {
|
338
338
|
outputPrice = inputPrice * (completionRatio || 1);
|
339
339
|
}
|
340
|
-
|
340
|
+
|
341
341
|
expect(outputPrice).toBe(30);
|
342
342
|
});
|
343
343
|
|
344
344
|
it('should use default completion_ratio when not provided', () => {
|
345
345
|
const inputPrice = 16;
|
346
346
|
const completionRatio = undefined;
|
347
|
-
|
347
|
+
|
348
348
|
let outputPrice;
|
349
349
|
if (inputPrice !== undefined) {
|
350
350
|
outputPrice = inputPrice * (completionRatio || 1);
|
351
351
|
}
|
352
|
-
|
352
|
+
|
353
353
|
expect(outputPrice).toBe(16); // input * 1 (default)
|
354
354
|
});
|
355
355
|
});
|
@@ -358,74 +358,77 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
358
358
|
it('should use supported_endpoint_types with anthropic (Branch 3.11: length > 0 = true, Branch 3.12: includes anthropic = true)', () => {
|
359
359
|
const model = { supported_endpoint_types: ['anthropic'] };
|
360
360
|
let detectedProvider = 'openai';
|
361
|
-
|
361
|
+
|
362
362
|
if (model.supported_endpoint_types && model.supported_endpoint_types.length > 0) {
|
363
363
|
if (model.supported_endpoint_types.includes('anthropic')) {
|
364
364
|
detectedProvider = 'anthropic';
|
365
365
|
}
|
366
366
|
}
|
367
|
-
|
367
|
+
|
368
368
|
expect(detectedProvider).toBe('anthropic');
|
369
369
|
});
|
370
370
|
|
371
371
|
it('should use supported_endpoint_types with gemini (Branch 3.13: includes gemini = true)', () => {
|
372
372
|
const model = { supported_endpoint_types: ['gemini'] };
|
373
373
|
let detectedProvider = 'openai';
|
374
|
-
|
374
|
+
|
375
375
|
if (model.supported_endpoint_types && model.supported_endpoint_types.length > 0) {
|
376
376
|
if (model.supported_endpoint_types.includes('gemini')) {
|
377
377
|
detectedProvider = 'google';
|
378
378
|
}
|
379
379
|
}
|
380
|
-
|
380
|
+
|
381
381
|
expect(detectedProvider).toBe('google');
|
382
382
|
});
|
383
383
|
|
384
384
|
it('should use supported_endpoint_types with xai (Branch 3.14: includes xai = true)', () => {
|
385
385
|
const model = { supported_endpoint_types: ['xai'] };
|
386
386
|
let detectedProvider = 'openai';
|
387
|
-
|
387
|
+
|
388
388
|
if (model.supported_endpoint_types && model.supported_endpoint_types.length > 0) {
|
389
389
|
if (model.supported_endpoint_types.includes('xai')) {
|
390
390
|
detectedProvider = 'xai';
|
391
391
|
}
|
392
392
|
}
|
393
|
-
|
393
|
+
|
394
394
|
expect(detectedProvider).toBe('xai');
|
395
395
|
});
|
396
396
|
|
397
397
|
it('should fallback to owned_by when supported_endpoint_types is empty (Branch 3.11: length > 0 = false, Branch 3.15: owned_by = true)', () => {
|
398
|
-
const model: Partial<NewAPIModelCard> = {
|
398
|
+
const model: Partial<NewAPIModelCard> = {
|
399
|
+
supported_endpoint_types: [],
|
400
|
+
owned_by: 'anthropic',
|
401
|
+
};
|
399
402
|
let detectedProvider = 'openai';
|
400
|
-
|
403
|
+
|
401
404
|
if (model.supported_endpoint_types && model.supported_endpoint_types.length > 0) {
|
402
405
|
// Skip - empty array
|
403
406
|
} else if (model.owned_by) {
|
404
407
|
detectedProvider = 'anthropic'; // Simplified for test
|
405
408
|
}
|
406
|
-
|
409
|
+
|
407
410
|
expect(detectedProvider).toBe('anthropic');
|
408
411
|
});
|
409
412
|
|
410
413
|
it('should fallback to owned_by when no supported_endpoint_types (Branch 3.15: owned_by = true)', () => {
|
411
414
|
const model: Partial<NewAPIModelCard> = { owned_by: 'google' };
|
412
415
|
let detectedProvider = 'openai';
|
413
|
-
|
416
|
+
|
414
417
|
if (model.supported_endpoint_types && model.supported_endpoint_types.length > 0) {
|
415
418
|
// Skip - no supported_endpoint_types
|
416
419
|
} else if (model.owned_by) {
|
417
420
|
detectedProvider = 'google'; // Simplified for test
|
418
421
|
}
|
419
|
-
|
422
|
+
|
420
423
|
expect(detectedProvider).toBe('google');
|
421
424
|
});
|
422
425
|
|
423
426
|
it('should use detectModelProvider fallback when no owned_by (Branch 3.15: owned_by = false, Branch 3.17)', () => {
|
424
427
|
const model: Partial<NewAPIModelCard> = { id: 'claude-3-sonnet', owned_by: '' };
|
425
428
|
mockDetectModelProvider.mockReturnValue('anthropic');
|
426
|
-
|
429
|
+
|
427
430
|
let detectedProvider = 'openai';
|
428
|
-
|
431
|
+
|
429
432
|
if (model.supported_endpoint_types && model.supported_endpoint_types.length > 0) {
|
430
433
|
// Skip - no supported_endpoint_types
|
431
434
|
} else if (model.owned_by) {
|
@@ -433,7 +436,7 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
433
436
|
} else {
|
434
437
|
detectedProvider = mockDetectModelProvider(model.id || '');
|
435
438
|
}
|
436
|
-
|
439
|
+
|
437
440
|
expect(detectedProvider).toBe('anthropic');
|
438
441
|
expect(mockDetectModelProvider).toHaveBeenCalledWith('claude-3-sonnet');
|
439
442
|
});
|
@@ -444,11 +447,11 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
444
447
|
displayName: 'Test Model',
|
445
448
|
_detectedProvider: 'openai',
|
446
449
|
};
|
447
|
-
|
450
|
+
|
448
451
|
if (model._detectedProvider) {
|
449
452
|
delete model._detectedProvider;
|
450
453
|
}
|
451
|
-
|
454
|
+
|
452
455
|
expect(model).not.toHaveProperty('_detectedProvider');
|
453
456
|
});
|
454
457
|
|
@@ -457,27 +460,31 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
457
460
|
id: 'test-model',
|
458
461
|
displayName: 'Test Model',
|
459
462
|
};
|
460
|
-
|
463
|
+
|
461
464
|
const hadDetectedProvider = '_detectedProvider' in model;
|
462
|
-
|
465
|
+
|
463
466
|
if (model._detectedProvider) {
|
464
467
|
delete model._detectedProvider;
|
465
468
|
}
|
466
|
-
|
469
|
+
|
467
470
|
expect(hadDetectedProvider).toBe(false);
|
468
471
|
});
|
469
472
|
});
|
470
473
|
|
471
474
|
describe('URL Processing Branch Coverage', () => {
|
472
|
-
it('should remove trailing
|
475
|
+
it('should remove trailing API version paths from baseURL', () => {
|
473
476
|
const testURLs = [
|
474
477
|
{ input: 'https://api.newapi.com/v1', expected: 'https://api.newapi.com' },
|
475
478
|
{ input: 'https://api.newapi.com/v1/', expected: 'https://api.newapi.com' },
|
479
|
+
{ input: 'https://api.newapi.com/v1beta', expected: 'https://api.newapi.com' },
|
480
|
+
{ input: 'https://api.newapi.com/v1beta/', expected: 'https://api.newapi.com' },
|
481
|
+
{ input: 'https://api.newapi.com/v2', expected: 'https://api.newapi.com' },
|
482
|
+
{ input: 'https://api.newapi.com/v1alpha', expected: 'https://api.newapi.com' },
|
476
483
|
{ input: 'https://api.newapi.com', expected: 'https://api.newapi.com' },
|
477
484
|
];
|
478
485
|
|
479
486
|
testURLs.forEach(({ input, expected }) => {
|
480
|
-
const result = input.replace(/\/
|
487
|
+
const result = input.replace(/\/v\d+[a-z]*\/?$/, '');
|
481
488
|
expect(result).toBe(expected);
|
482
489
|
});
|
483
490
|
});
|
@@ -538,7 +545,7 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
538
545
|
{ model_name: 'openai-gpt4', quota_type: 1, model_price: 30 }, // Should be skipped
|
539
546
|
];
|
540
547
|
|
541
|
-
const pricingMap = new Map(pricingData.map(p => [p.model_name, p]));
|
548
|
+
const pricingMap = new Map(pricingData.map((p) => [p.model_name, p]));
|
542
549
|
|
543
550
|
const enrichedModels = models.map((model) => {
|
544
551
|
let enhancedModel: any = { ...model };
|
@@ -601,7 +608,7 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
601
608
|
// Test the dynamic routers configuration
|
602
609
|
const testOptions = {
|
603
610
|
apiKey: 'test-key',
|
604
|
-
baseURL: 'https://yourapi.cn/v1'
|
611
|
+
baseURL: 'https://yourapi.cn/v1',
|
605
612
|
};
|
606
613
|
|
607
614
|
// Create instance to test dynamic routers
|
@@ -611,8 +618,8 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
|
|
611
618
|
// The dynamic routers should be configured with user's baseURL
|
612
619
|
// This is tested indirectly through successful instantiation
|
613
620
|
// since the routers function processes the options.baseURL
|
614
|
-
const expectedBaseURL = testOptions.baseURL.replace(/\/
|
621
|
+
const expectedBaseURL = testOptions.baseURL.replace(/\/v\d+[a-z]*\/?$/, '');
|
615
622
|
expect(expectedBaseURL).toBe('https://yourapi.cn');
|
616
623
|
});
|
617
624
|
});
|
618
|
-
});
|
625
|
+
});
|