🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✅ test: add model runtime tests (#9128)
Arvin Xuf813d0c42997
diff --git a/packages/const/src/settings/hotkey.ts b/packages/const/src/settings/hotkey.tsindex e2ebf8b8e1c..dd09333321f 100644--- a/packages/const/src/settings/hotkey.ts+++ b/packages/const/src/settings/hotkey.ts@@ -1,5 +1,6 @@-import { HOTKEYS_REGISTRATION } from '@/const/hotkeys';-import { UserHotkeyConfig } from '@/types/user/settings';+import { UserHotkeyConfig } from '@lobechat/types';++import { HOTKEYS_REGISTRATION } from '../hotkeys';export const DEFAULT_HOTKEY_CONFIG: UserHotkeyConfig = HOTKEYS_REGISTRATION.reduce((acc: UserHotkeyConfig, item) => {diff --git a/packages/const/src/user.ts b/packages/const/src/user.tsindex 81f6a5b1aca..12ec37f5319 100644--- a/packages/const/src/user.ts+++ b/packages/const/src/user.ts@@ -1,5 +1,4 @@-import { TopicDisplayMode } from '@/types/topic';-import { UserPreference } from '@/types/user';+import { TopicDisplayMode, UserPreference } from '@lobechat/types';export const DEFAULT_PREFERENCE: UserPreference = {guide: {diff --git a/packages/model-runtime/package.json b/packages/model-runtime/package.jsonindex c10783bb06f..cca871dc0c3 100644--- a/packages/model-runtime/package.json+++ b/packages/model-runtime/package.json@@ -8,7 +8,8 @@},"scripts": {"test": "vitest",- "test:coverage": "vitest --coverage"+ "test:coverage": "vitest --coverage",+ "test:update": "vitest -u"},"dependencies": {"@aws-sdk/client-bedrock-runtime": "^3.862.0",diff --git a/packages/model-runtime/src/ai21/index.test.ts b/packages/model-runtime/src/ai21/index.test.tsindex e0620f6e502..dd417418a30 100644--- a/packages/model-runtime/src/ai21/index.test.ts+++ b/packages/model-runtime/src/ai21/index.test.ts@@ -1,7 +1,7 @@// @vitest-environment node-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';+import { ModelProvider } from '@lobechat/model-runtime';+import { testProvider } from '../providerTestUtils';import { LobeAi21AI } from './index';testProvider({diff --git a/packages/model-runtime/src/ai360/index.test.ts b/packages/model-runtime/src/ai360/index.test.tsindex 17bdf355f4b..a1e980e84d6 100644--- a/packages/model-runtime/src/ai360/index.test.ts+++ b/packages/model-runtime/src/ai360/index.test.ts@@ -1,7 +1,7 @@// @vitest-environment node-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';+import { ModelProvider } from '@lobechat/model-runtime';+import { testProvider } from '../providerTestUtils';import { LobeAi360AI } from './index';testProvider({diff --git a/packages/model-runtime/src/akashchat/index.test.ts b/packages/model-runtime/src/akashchat/index.test.tsnew file mode 100644index 00000000000..6a3c455fc7f--- /dev/null+++ b/packages/model-runtime/src/akashchat/index.test.ts@@ -0,0 +1,19 @@+// @vitest-environment node+import { ModelProvider } from '@lobechat/model-runtime';++import { testProvider } from '../providerTestUtils';+import { LobeAkashChatAI } from './index';++const provider = ModelProvider.AkashChat;+const defaultBaseURL = 'https://chatapi.akash.network/api/v1';++testProvider({+ Runtime: LobeAkashChatAI,+ provider,+ defaultBaseURL,+ chatDebugEnv: 'DEBUG_AKASH_CHAT_COMPLETION',+ chatModel: 'llama-3.1-8b-instruct',+ test: {+ skipAPICall: true,+ },+});diff --git a/packages/model-runtime/src/anthropic/index.test.ts b/packages/model-runtime/src/anthropic/index.test.tsindex 07e617aa942..c5f200d3ad5 100644--- a/packages/model-runtime/src/anthropic/index.test.ts+++ b/packages/model-runtime/src/anthropic/index.test.ts@@ -1,8 +1,7 @@// @vitest-environment node+import { ChatCompletionTool, ChatStreamPayload } from '@lobechat/model-runtime';import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { ChatCompletionTool, ChatStreamPayload } from '@/libs/model-runtime';-import * as anthropicHelpers from '../utils/anthropicHelpers';import * as debugStreamModule from '../utils/debugStream';import { LobeAnthropicAI } from './index';diff --git a/packages/model-runtime/src/baichuan/index.test.ts b/packages/model-runtime/src/baichuan/index.test.tsindex b0f2c15713c..bd44c4233ea 100644--- a/packages/model-runtime/src/baichuan/index.test.ts+++ b/packages/model-runtime/src/baichuan/index.test.ts@@ -1,8 +1,7 @@// @vitest-environment node+import { LobeOpenAICompatibleRuntime, ModelProvider } from '@lobechat/model-runtime';import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { LobeOpenAICompatibleRuntime, ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '../providerTestUtils';import { LobeBaichuanAI } from './index';diff --git a/packages/model-runtime/src/bedrock/index.test.ts b/packages/model-runtime/src/bedrock/index.test.tsindex 4b57ab91174..f9cd2226b6b 100644--- a/packages/model-runtime/src/bedrock/index.test.ts+++ b/packages/model-runtime/src/bedrock/index.test.ts@@ -1,9 +1,8 @@// @vitest-environment nodeimport { InvokeModelWithResponseStreamCommand } from '@aws-sdk/client-bedrock-runtime';+import { AgentRuntimeErrorType, ModelProvider } from '@lobechat/model-runtime';import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { AgentRuntimeErrorType, ModelProvider } from '@/libs/model-runtime';-import * as debugStreamModule from '../utils/debugStream';import { LobeBedrockAI } from './index';diff --git a/packages/model-runtime/src/bfl/createImage.test.ts b/packages/model-runtime/src/bfl/createImage.test.tsindex 89da043cb51..b884f56eaa1 100644--- a/packages/model-runtime/src/bfl/createImage.test.ts+++ b/packages/model-runtime/src/bfl/createImage.test.ts@@ -1,8 +1,7 @@// @vitest-environment nodeimport { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { CreateImagePayload } from '@/libs/model-runtime/types/image';-+import { CreateImagePayload } from '../types/image';import { createBflImage } from './createImage';import { BflStatusResponse } from './types';diff --git a/packages/model-runtime/src/bfl/index.test.ts b/packages/model-runtime/src/bfl/index.test.tsindex fc45bef9e28..02d71f585b2 100644--- a/packages/model-runtime/src/bfl/index.test.ts+++ b/packages/model-runtime/src/bfl/index.test.ts@@ -1,8 +1,7 @@// @vitest-environment nodeimport { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { CreateImagePayload } from '@/libs/model-runtime/types/image';-+import { CreateImagePayload } from '../types/image';import { LobeBflAI } from './index';// Mock the createBflImage functiondiff --git a/packages/model-runtime/src/cloudflare/index.test.ts b/packages/model-runtime/src/cloudflare/index.test.tsindex ae7381c27a4..f47ba71bae3 100644--- a/packages/model-runtime/src/cloudflare/index.test.ts+++ b/packages/model-runtime/src/cloudflare/index.test.ts@@ -1,8 +1,7 @@// @vitest-environment node+import { ChatCompletionTool } from '@lobechat/model-runtime';import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { ChatCompletionTool } from '@/libs/model-runtime';-import * as debugStreamModule from '../utils/debugStream';import { LobeCloudflareAI } from './index';diff --git a/packages/model-runtime/src/cohere/index.test.ts b/packages/model-runtime/src/cohere/index.test.tsnew file mode 100644index 00000000000..629cca9369e--- /dev/null+++ b/packages/model-runtime/src/cohere/index.test.ts@@ -0,0 +1,19 @@+// @vitest-environment node+import { ModelProvider } from '@lobechat/model-runtime';++import { testProvider } from '../providerTestUtils';+import { LobeCohereAI } from './index';++const provider = ModelProvider.Cohere;+const defaultBaseURL = 'https://api.cohere.ai/compatibility/v1';++testProvider({+ Runtime: LobeCohereAI,+ provider,+ defaultBaseURL,+ chatDebugEnv: 'DEBUG_COHERE_CHAT_COMPLETION',+ chatModel: 'command-r7b',+ test: {+ skipAPICall: true,+ },+});diff --git a/packages/model-runtime/src/deepseek/index.test.ts b/packages/model-runtime/src/deepseek/index.test.tsindex 34142dccf53..e5f630f1eb9 100644--- a/packages/model-runtime/src/deepseek/index.test.ts+++ b/packages/model-runtime/src/deepseek/index.test.ts@@ -1,7 +1,7 @@// @vitest-environment node-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';+import { ModelProvider } from '@lobechat/model-runtime';+import { testProvider } from '../providerTestUtils';import { LobeDeepSeekAI } from './index';const provider = ModelProvider.DeepSeek;diff --git a/packages/model-runtime/src/fireworksai/index.test.ts b/packages/model-runtime/src/fireworksai/index.test.tsindex e310e4a4f51..67f1c0551d3 100644--- a/packages/model-runtime/src/fireworksai/index.test.ts+++ b/packages/model-runtime/src/fireworksai/index.test.ts@@ -1,7 +1,7 @@// @vitest-environment node-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';+import { ModelProvider } from '@lobechat/model-runtime';+import { testProvider } from '../providerTestUtils';import { LobeFireworksAI } from './index';const provider = ModelProvider.FireworksAI;diff --git a/packages/model-runtime/src/giteeai/index.test.ts b/packages/model-runtime/src/giteeai/index.test.tsindex d2488366b3a..d957f02629b 100644--- a/packages/model-runtime/src/giteeai/index.test.ts+++ b/packages/model-runtime/src/giteeai/index.test.ts@@ -1,7 +1,7 @@// @vitest-environment node-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';+import { ModelProvider } from '@lobechat/model-runtime';+import { testProvider } from '../providerTestUtils';import { LobeGiteeAI } from './index';testProvider({diff --git a/packages/model-runtime/src/github/index.test.ts b/packages/model-runtime/src/github/index.test.tsindex 33926238a3c..022c1dde57e 100644--- a/packages/model-runtime/src/github/index.test.ts+++ b/packages/model-runtime/src/github/index.test.ts@@ -1,7 +1,7 @@// @vitest-environment node-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';+import { ModelProvider } from '@lobechat/model-runtime';+import { testProvider } from '../providerTestUtils';import { LobeGithubAI } from './index';testProvider({diff --git a/packages/model-runtime/src/google/createImage.test.ts b/packages/model-runtime/src/google/createImage.test.tsindex 871d8281756..79e7b4f18d3 100644--- a/packages/model-runtime/src/google/createImage.test.ts+++ b/packages/model-runtime/src/google/createImage.test.ts@@ -2,8 +2,7 @@import { GoogleGenAI } from '@google/genai';import { beforeEach, describe, expect, it, vi } from 'vitest';-import { CreateImagePayload } from '@/libs/model-runtime/types/image';-+import { CreateImagePayload } from '../types/image';import * as imageToBase64Module from '../utils/imageToBase64';import { createGoogleImage } from './createImage';diff --git a/packages/model-runtime/src/google/index.test.ts b/packages/model-runtime/src/google/index.test.tsindex fd1fcf54926..be35d3c9a20 100644--- a/packages/model-runtime/src/google/index.test.ts+++ b/packages/model-runtime/src/google/index.test.ts@@ -1,9 +1,9 @@// @vitest-environment edge-runtimeimport { GenerateContentResponse, Tool } from '@google/genai';+import { OpenAIChatMessage } from '@lobechat/model-runtime';import OpenAI from 'openai';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { OpenAIChatMessage } from '@/libs/model-runtime';import { ChatStreamPayload } from '@/types/openai/chat';import * as debugStreamModule from '../utils/debugStream';diff --git a/packages/model-runtime/src/groq/index.test.ts b/packages/model-runtime/src/groq/index.test.tsindex 367d0a4a6ae..76160f6ced9 100644--- a/packages/model-runtime/src/groq/index.test.ts+++ b/packages/model-runtime/src/groq/index.test.ts@@ -1,9 +1,8 @@// @vitest-environment node+import { LobeOpenAICompatibleRuntime } from '@lobechat/model-runtime';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { LobeOpenAICompatibleRuntime } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';-+import { testProvider } from '../providerTestUtils';import { LobeGroq } from './index';testProvider({diff --git a/packages/model-runtime/src/huggingface/index.test.ts b/packages/model-runtime/src/huggingface/index.test.tsnew file mode 100644index 00000000000..414a9c37089--- /dev/null+++ b/packages/model-runtime/src/huggingface/index.test.ts@@ -0,0 +1,40 @@+// @vitest-environment node+import { ModelProvider } from '@lobechat/model-runtime';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { LobeHuggingFaceAI } from './index';++describe('LobeHuggingFaceAI', () => {+ let instance: any;++ beforeEach(() => {+ instance = new LobeHuggingFaceAI({ apiKey: 'test' });++ const mockAsyncIterable = {+ async *[Symbol.asyncIterator]() {+ yield { choices: [] } as any;+ },+ } as any;++ // mock custom client's chatCompletionStream+ instance['client'] = {+ chatCompletionStream: vi.fn().mockReturnValue(mockAsyncIterable),+ } as any;+ });++ it('should initialize and return StreamingTextResponse on chat', async () => {+ const res = await instance.chat({+ messages: [{ role: 'user', content: 'hello' }],+ model: 'meta-llama/Meta-Llama-3.1-8B-Instruct',+ temperature: 0,+ stream: true,+ });++ expect(res).toBeInstanceOf(Response);+ });++ it('should set provider id properly', async () => {+ // provider id 用于错误封装等,这里验证暴露 id 一致+ expect(ModelProvider.HuggingFace).toBe('huggingface');+ });+});diff --git a/packages/model-runtime/src/hunyuan/index.test.ts b/packages/model-runtime/src/hunyuan/index.test.tsindex d1331347974..e55931bbb62 100644--- a/packages/model-runtime/src/hunyuan/index.test.ts+++ b/packages/model-runtime/src/hunyuan/index.test.ts@@ -1,9 +1,8 @@// @vitest-environment node+import { LobeOpenAICompatibleRuntime, ModelProvider } from '@lobechat/model-runtime';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { LobeOpenAICompatibleRuntime, ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';-+import { testProvider } from '../providerTestUtils';import { LobeHunyuanAI } from './index';testProvider({diff --git a/packages/model-runtime/src/internlm/index.test.ts b/packages/model-runtime/src/internlm/index.test.tsindex 6581ac3afd8..a4931194a4f 100644--- a/packages/model-runtime/src/internlm/index.test.ts+++ b/packages/model-runtime/src/internlm/index.test.ts@@ -1,7 +1,7 @@// @vitest-environment node-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';+import { ModelProvider } from '@lobechat/model-runtime';+import { testProvider } from '../providerTestUtils';import { LobeInternLMAI } from './index';testProvider({diff --git a/packages/model-runtime/src/jina/index.test.ts b/packages/model-runtime/src/jina/index.test.tsnew file mode 100644index 00000000000..c10c01bd2ea--- /dev/null+++ b/packages/model-runtime/src/jina/index.test.ts@@ -0,0 +1,19 @@+// @vitest-environment node+import { ModelProvider } from '@lobechat/model-runtime';++import { testProvider } from '../providerTestUtils';+import { LobeJinaAI } from './index';++const provider = ModelProvider.Jina;+const defaultBaseURL = 'https://deepsearch.jina.ai/v1';++testProvider({+ Runtime: LobeJinaAI,+ provider,+ defaultBaseURL,+ chatDebugEnv: 'DEBUG_JINA_CHAT_COMPLETION',+ chatModel: 'jina-embeddings-v3',+ test: {+ skipAPICall: true,+ },+});diff --git a/packages/model-runtime/src/lmstudio/index.test.ts b/packages/model-runtime/src/lmstudio/index.test.tsindex 8c3a8868618..7dde8a7e9d0 100644--- a/packages/model-runtime/src/lmstudio/index.test.ts+++ b/packages/model-runtime/src/lmstudio/index.test.ts@@ -1,7 +1,7 @@// @vitest-environment node-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';+import { ModelProvider } from '@lobechat/model-runtime';+import { testProvider } from '../providerTestUtils';import { LobeLMStudioAI } from './index';const provider = ModelProvider.LMStudio;diff --git a/packages/model-runtime/src/minimax/index.test.ts b/packages/model-runtime/src/minimax/index.test.tsnew file mode 100644index 00000000000..08d95adec48--- /dev/null+++ b/packages/model-runtime/src/minimax/index.test.ts@@ -0,0 +1,19 @@+// @vitest-environment node+import { ModelProvider } from '@lobechat/model-runtime';++import { testProvider } from '../providerTestUtils';+import { LobeMinimaxAI } from './index';++const provider = ModelProvider.Minimax;+const defaultBaseURL = 'https://api.minimax.chat/v1';++testProvider({+ Runtime: LobeMinimaxAI,+ provider,+ defaultBaseURL,+ chatDebugEnv: 'DEBUG_MINIMAX_CHAT_COMPLETION',+ chatModel: 'abab6.5s-chat',+ test: {+ skipAPICall: true,+ },+});diff --git a/packages/model-runtime/src/mistral/index.test.ts b/packages/model-runtime/src/mistral/index.test.tsindex adcdadada24..a4a44531dca 100644--- a/packages/model-runtime/src/mistral/index.test.ts+++ b/packages/model-runtime/src/mistral/index.test.ts@@ -1,9 +1,8 @@// @vitest-environment node+import { LobeOpenAICompatibleRuntime } from '@lobechat/model-runtime';import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { LobeOpenAICompatibleRuntime } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';-+import { testProvider } from '../providerTestUtils';import { LobeMistralAI } from './index';testProvider({diff --git a/packages/model-runtime/src/modelscope/index.test.ts b/packages/model-runtime/src/modelscope/index.test.tsnew file mode 100644index 00000000000..d94affbfb44--- /dev/null+++ b/packages/model-runtime/src/modelscope/index.test.ts@@ -0,0 +1,19 @@+// @vitest-environment node+import { ModelProvider } from '@lobechat/model-runtime';++import { testProvider } from '../providerTestUtils';+import { LobeModelScopeAI } from './index';++const provider = ModelProvider.ModelScope;+const defaultBaseURL = 'https://api-inference.modelscope.cn/v1';++testProvider({+ Runtime: LobeModelScopeAI,+ provider,+ defaultBaseURL,+ chatDebugEnv: 'DEBUG_MODELSCOPE_CHAT_COMPLETION',+ chatModel: 'qwen2-7b-instruct',+ test: {+ skipAPICall: true,+ },+});diff --git a/packages/model-runtime/src/moonshot/index.test.ts b/packages/model-runtime/src/moonshot/index.test.tsindex 3e0071e1915..d2eda36a77c 100644--- a/packages/model-runtime/src/moonshot/index.test.ts+++ b/packages/model-runtime/src/moonshot/index.test.ts@@ -1,6 +1,5 @@// @vitest-environment node-import { testProvider } from '@/libs/model-runtime/providerTestUtils';-+import { testProvider } from '../providerTestUtils';import { LobeMoonshotAI } from './index';const provider = 'moonshot';diff --git a/packages/model-runtime/src/nebius/index.test.ts b/packages/model-runtime/src/nebius/index.test.tsnew file mode 100644index 00000000000..7600e10443d--- /dev/null+++ b/packages/model-runtime/src/nebius/index.test.ts@@ -0,0 +1,19 @@+// @vitest-environment node+import { ModelProvider } from '@lobechat/model-runtime';++import { testProvider } from '../providerTestUtils';+import { LobeNebiusAI } from './index';++const provider = ModelProvider.Nebius;+const defaultBaseURL = 'https://api.studio.nebius.com/v1';++testProvider({+ Runtime: LobeNebiusAI,+ provider,+ defaultBaseURL,+ chatDebugEnv: 'DEBUG_NEBIUS_CHAT_COMPLETION',+ chatModel: 'meta/llama-3.1-8b-instruct',+ test: {+ skipAPICall: true,+ },+});diff --git a/packages/model-runtime/src/novita/index.test.ts b/packages/model-runtime/src/novita/index.test.tsindex 8f8e96f3b11..4e3a3d13dcf 100644--- a/packages/model-runtime/src/novita/index.test.ts+++ b/packages/model-runtime/src/novita/index.test.ts@@ -1,10 +1,9 @@// @vitest-environment node+import { LobeOpenAICompatibleRuntime } from '@lobechat/model-runtime';+import { ModelProvider } from '@lobechat/model-runtime';import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { LobeOpenAICompatibleRuntime } from '@/libs/model-runtime';-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';-+import { testProvider } from '../providerTestUtils';import models from './fixtures/models.json';import { LobeNovitaAI } from './index';diff --git a/packages/model-runtime/src/nvidia/index.test.ts b/packages/model-runtime/src/nvidia/index.test.tsnew file mode 100644index 00000000000..482cb615918--- /dev/null+++ b/packages/model-runtime/src/nvidia/index.test.ts@@ -0,0 +1,19 @@+// @vitest-environment node+import { ModelProvider } from '@lobechat/model-runtime';++import { testProvider } from '../providerTestUtils';+import { LobeNvidiaAI } from './index';++const provider = ModelProvider.Nvidia;+const defaultBaseURL = 'https://integrate.api.nvidia.com/v1';++testProvider({+ Runtime: LobeNvidiaAI,+ provider,+ defaultBaseURL,+ chatDebugEnv: 'DEBUG_NVIDIA_CHAT_COMPLETION',+ chatModel: 'meta/llama-3.1-8b-instruct',+ test: {+ skipAPICall: true,+ },+});diff --git a/packages/model-runtime/src/openrouter/__snapshots__/index.test.ts.snap b/packages/model-runtime/src/openrouter/__snapshots__/index.test.ts.snapdeleted file mode 100644index e23c0cb32b5..00000000000--- a/packages/model-runtime/src/openrouter/__snapshots__/index.test.ts.snap+++ /dev/null@@ -1,113 +0,0 @@-// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html--exports[`LobeOpenRouterAI > chat > should handle fetch error gracefully 1`] = `-[- {- "contextWindowTokens": 131072,- "description": "Reflection Llama-3.1 70B is trained with a new technique called Reflection-Tuning that teaches a LLM to detect mistakes in its reasoning and correct course.--The model was trained on synthetic data.--_These are free, rate-limited endpoints for [Reflection 70B](/models/mattshumer/reflection-70b). Outputs may be cached. Read about rate limits [here](/docs/limits)._",- "displayName": "Reflection 70B",- "enabled": false,- "functionCall": false,- "id": "mattshumer/reflection-70b:free",- "maxOutput": undefined,- "pricing": undefined,- "reasoning": false,- "releasedAt": "1970-01-20",- "type": "chat",- "vision": false,- },-]-`;--exports[`LobeOpenRouterAI > chat > should handle fetch failure gracefully 1`] = `-[- {- "contextWindowTokens": 131072,- "description": "Reflection Llama-3.1 70B is trained with a new technique called Reflection-Tuning that teaches a LLM to detect mistakes in its reasoning and correct course.--The model was trained on synthetic data.--_These are free, rate-limited endpoints for [Reflection 70B](/models/mattshumer/reflection-70b). Outputs may be cached. Read about rate limits [here](/docs/limits)._",- "displayName": "Reflection 70B",- "enabled": false,- "functionCall": false,- "id": "mattshumer/reflection-70b:free",- "maxOutput": undefined,- "pricing": undefined,- "reasoning": false,- "releasedAt": "1970-01-20",- "type": "chat",- "vision": false,- },-]-`;--exports[`LobeOpenRouterAI > models > should get models with frontend models data 1`] = `-[- {- "contextWindowTokens": 131072,- "description": "Reflection Llama-3.1 70B is trained with a new technique called Reflection-Tuning that teaches a LLM to detect mistakes in its reasoning and correct course.--The model was trained on synthetic data.--_These are free, rate-limited endpoints for [Reflection 70B](/models/mattshumer/reflection-70b). Outputs may be cached. Read about rate limits [here](/docs/limits)._",- "displayName": "Reflection 70B",- "enabled": false,- "functionCall": true,- "id": "mattshumer/reflection-70b:free",- "maxOutput": 4096,- "reasoning": true,- "releasedAt": "2024-09-06",- "type": "chat",- "vision": false,- },-]-`;--exports[`LobeOpenRouterAI > models > should handle fetch error gracefully 1`] = `-[- {- "contextWindowTokens": 131072,- "description": "Reflection Llama-3.1 70B is trained with a new technique called Reflection-Tuning that teaches a LLM to detect mistakes in its reasoning and correct course.--The model was trained on synthetic data.--_These are free, rate-limited endpoints for [Reflection 70B](/models/mattshumer/reflection-70b). Outputs may be cached. Read about rate limits [here](/docs/limits)._",- "displayName": "Reflection 70B",- "enabled": false,- "functionCall": false,- "id": "mattshumer/reflection-70b:free",- "maxOutput": 4096,- "reasoning": false,- "releasedAt": "2024-09-06",- "type": "chat",- "vision": false,- },-]-`;--exports[`LobeOpenRouterAI > models > should handle fetch failure gracefully 1`] = `-[- {- "contextWindowTokens": 131072,- "description": "Reflection Llama-3.1 70B is trained with a new technique called Reflection-Tuning that teaches a LLM to detect mistakes in its reasoning and correct course.--The model was trained on synthetic data.--_These are free, rate-limited endpoints for [Reflection 70B](/models/mattshumer/reflection-70b). Outputs may be cached. Read about rate limits [here](/docs/limits)._",- "displayName": "Reflection 70B",- "enabled": false,- "functionCall": false,- "id": "mattshumer/reflection-70b:free",- "maxOutput": 4096,- "reasoning": false,- "releasedAt": "2024-09-06",- "type": "chat",- "vision": false,- },-]-`;diff --git a/packages/model-runtime/src/openrouter/index.test.ts b/packages/model-runtime/src/openrouter/index.test.tsindex 5327d4d97a6..538c2e84bd9 100644--- a/packages/model-runtime/src/openrouter/index.test.ts+++ b/packages/model-runtime/src/openrouter/index.test.ts@@ -1,9 +1,8 @@// @vitest-environment node+import { LobeOpenAICompatibleRuntime } from '@lobechat/model-runtime';import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { LobeOpenAICompatibleRuntime } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';-+import { testProvider } from '../providerTestUtils';import models from './fixtures/models.json';import { LobeOpenRouterAI } from './index';diff --git a/packages/model-runtime/src/perplexity/index.test.ts b/packages/model-runtime/src/perplexity/index.test.tsindex d3d31074e4d..66133dbaf98 100644--- a/packages/model-runtime/src/perplexity/index.test.ts+++ b/packages/model-runtime/src/perplexity/index.test.ts@@ -1,9 +1,8 @@// @vitest-environment node+import { LobeOpenAICompatibleRuntime, ModelProvider } from '@lobechat/model-runtime';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { LobeOpenAICompatibleRuntime, ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';-+import { testProvider } from '../providerTestUtils';import { LobePerplexityAI } from './index';testProvider({diff --git a/packages/model-runtime/src/ppio/index.test.ts b/packages/model-runtime/src/ppio/index.test.tsindex 9f420dae7c5..0c8164cdf39 100644--- a/packages/model-runtime/src/ppio/index.test.ts+++ b/packages/model-runtime/src/ppio/index.test.ts@@ -1,10 +1,9 @@// @vitest-environment node+import { LobeOpenAICompatibleRuntime } from '@lobechat/model-runtime';+import { ModelProvider } from '@lobechat/model-runtime';import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { LobeOpenAICompatibleRuntime } from '@/libs/model-runtime';-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';-+import { testProvider } from '../providerTestUtils';import models from './fixtures/models.json';import { LobePPIOAI } from './index';diff --git a/packages/model-runtime/src/qwen/index.test.ts b/packages/model-runtime/src/qwen/index.test.tsindex 2b87e72d581..c8e7ec44a84 100644--- a/packages/model-runtime/src/qwen/index.test.ts+++ b/packages/model-runtime/src/qwen/index.test.ts@@ -1,7 +1,7 @@// @vitest-environment node-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';+import { ModelProvider } from '@lobechat/model-runtime';+import { testProvider } from '../providerTestUtils';import { LobeQwenAI } from './index';const provider = ModelProvider.Qwen;diff --git a/packages/model-runtime/src/sambanova/index.test.ts b/packages/model-runtime/src/sambanova/index.test.tsnew file mode 100644index 00000000000..f1fb50ea085--- /dev/null+++ b/packages/model-runtime/src/sambanova/index.test.ts@@ -0,0 +1,19 @@+// @vitest-environment node+import { ModelProvider } from '@lobechat/model-runtime';++import { testProvider } from '../providerTestUtils';+import { LobeSambaNovaAI } from './index';++const provider = ModelProvider.SambaNova;+const defaultBaseURL = 'https://api.sambanova.ai/v1';++testProvider({+ Runtime: LobeSambaNovaAI,+ provider,+ defaultBaseURL,+ chatDebugEnv: 'DEBUG_SAMBANOVA_CHAT_COMPLETION',+ chatModel: 'Meta-Llama-3.1-8B-Instruct',+ test: {+ skipAPICall: true,+ },+});diff --git a/packages/model-runtime/src/search1api/index.test.ts b/packages/model-runtime/src/search1api/index.test.tsnew file mode 100644index 00000000000..59eb1f3a920--- /dev/null+++ b/packages/model-runtime/src/search1api/index.test.ts@@ -0,0 +1,19 @@+// @vitest-environment node+import { ModelProvider } from '@lobechat/model-runtime';++import { testProvider } from '../providerTestUtils';+import { LobeSearch1API } from './index';++const provider = ModelProvider.Search1API;+const defaultBaseURL = 'https://api.search1api.com/v1';++testProvider({+ Runtime: LobeSearch1API,+ provider,+ defaultBaseURL,+ chatDebugEnv: 'DEBUG_SEARCH1API_CHAT_COMPLETION',+ chatModel: 'gpt-4o-mini',+ test: {+ skipAPICall: true,+ },+});diff --git a/packages/model-runtime/src/sensenova/index.test.ts b/packages/model-runtime/src/sensenova/index.test.tsindex 457479625d1..26a874706d8 100644--- a/packages/model-runtime/src/sensenova/index.test.ts+++ b/packages/model-runtime/src/sensenova/index.test.ts@@ -1,7 +1,7 @@// @vitest-environment node-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';+import { ModelProvider } from '@lobechat/model-runtime';+import { testProvider } from '../providerTestUtils';import { LobeSenseNovaAI } from './index';const provider = ModelProvider.SenseNova;diff --git a/packages/model-runtime/src/spark/index.test.ts b/packages/model-runtime/src/spark/index.test.tsindex e0b662821e2..ef49dc52360 100644--- a/packages/model-runtime/src/spark/index.test.ts+++ b/packages/model-runtime/src/spark/index.test.ts@@ -1,7 +1,7 @@// @vitest-environment node-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';+import { ModelProvider } from '@lobechat/model-runtime';+import { testProvider } from '../providerTestUtils';import { LobeSparkAI } from './index';const provider = ModelProvider.Spark;diff --git a/packages/model-runtime/src/stepfun/index.test.ts b/packages/model-runtime/src/stepfun/index.test.tsindex c7369a61db7..c8120ceee53 100644--- a/packages/model-runtime/src/stepfun/index.test.ts+++ b/packages/model-runtime/src/stepfun/index.test.ts@@ -1,7 +1,7 @@// @vitest-environment node-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';+import { ModelProvider } from '@lobechat/model-runtime';+import { testProvider } from '../providerTestUtils';import { LobeStepfunAI } from './index';const provider = ModelProvider.Stepfun;diff --git a/packages/model-runtime/src/taichu/index.test.ts b/packages/model-runtime/src/taichu/index.test.tsindex 9af0a8b97ac..45bfd563576 100644--- a/packages/model-runtime/src/taichu/index.test.ts+++ b/packages/model-runtime/src/taichu/index.test.ts@@ -1,15 +1,14 @@// @vitest-environment node-import OpenAI from 'openai';-import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import {ChatStreamCallbacks,LobeMoonshotAI,LobeOpenAICompatibleRuntime,ModelProvider,-} from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';+} from '@lobechat/model-runtime';+import OpenAI from 'openai';+import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { testProvider } from '../providerTestUtils';import * as debugStreamModule from '../utils/debugStream';import { LobeTaichuAI } from './index';diff --git a/packages/model-runtime/src/tencentcloud/index.test.ts b/packages/model-runtime/src/tencentcloud/index.test.tsindex 07377acd4d1..2f782649ba1 100644--- a/packages/model-runtime/src/tencentcloud/index.test.ts+++ b/packages/model-runtime/src/tencentcloud/index.test.ts@@ -1,5 +1,5 @@// @vitest-environment node-import { ModelProvider } from '@/libs/model-runtime';+import { ModelProvider } from '@lobechat/model-runtime';import { testProvider } from '../providerTestUtils';import { LobeTencentCloudAI } from './index';diff --git a/packages/model-runtime/src/togetherai/index.test.ts b/packages/model-runtime/src/togetherai/index.test.tsindex 01a5356852f..af50a9dde0c 100644--- a/packages/model-runtime/src/togetherai/index.test.ts+++ b/packages/model-runtime/src/togetherai/index.test.ts@@ -1,6 +1,5 @@// @vitest-environment node-import { testProvider } from '@/libs/model-runtime/providerTestUtils';-+import { testProvider } from '../providerTestUtils';import { LobeTogetherAI } from './index';testProvider({diff --git a/packages/model-runtime/src/upstage/index.test.ts b/packages/model-runtime/src/upstage/index.test.tsindex f00c90ca737..c0296ea71c8 100644--- a/packages/model-runtime/src/upstage/index.test.ts+++ b/packages/model-runtime/src/upstage/index.test.ts@@ -1,6 +1,5 @@// @vitest-environment node-import { testProvider } from '@/libs/model-runtime/providerTestUtils';-+import { testProvider } from '../providerTestUtils';import { LobeUpstageAI } from './index';testProvider({diff --git a/packages/model-runtime/src/utils/openaiCompatibleFactory/index.test.ts b/packages/model-runtime/src/utils/openaiCompatibleFactory/index.test.tsindex b607b837228..b4870891a50 100644--- a/packages/model-runtime/src/utils/openaiCompatibleFactory/index.test.ts+++ b/packages/model-runtime/src/utils/openaiCompatibleFactory/index.test.ts@@ -1,22 +1,24 @@// @vitest-environment node-import OpenAI from 'openai';-import type { Stream } from 'openai/streaming';-import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import {AgentRuntimeErrorType,ChatStreamCallbacks,ChatStreamPayload,LobeOpenAICompatibleRuntime,ModelProvider,-} from '@/libs/model-runtime';-import officalOpenAIModels from '@/libs/model-runtime/openai/fixtures/openai-models.json';-import { sleep } from '@/utils/sleep';+} from '@lobechat/model-runtime';+import OpenAI from 'openai';+import type { Stream } from 'openai/streaming';+import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import * as debugStreamModule from '../debugStream';import * as openaiHelpers from '../openaiHelpers';import { createOpenAICompatibleRuntime } from './index';+const sleep = async (ms: number) =>+ await new Promise((resolve) => {+ setTimeout(resolve, ms);+ });+const provider = 'groq';const defaultBaseURL = 'https://api.groq.com/openai/v1';const bizErrorType = 'ProviderBizError';diff --git a/packages/model-runtime/src/utils/streams/openai/responsesStream.test.ts b/packages/model-runtime/src/utils/streams/openai/responsesStream.test.tsindex ec20be5eefe..25df52a50ec 100644--- a/packages/model-runtime/src/utils/streams/openai/responsesStream.test.ts+++ b/packages/model-runtime/src/utils/streams/openai/responsesStream.test.ts@@ -1,7 +1,6 @@+import { AgentRuntimeErrorType } from '@lobechat/model-runtime';import { describe, expect, it, vi } from 'vitest';-import { AgentRuntimeErrorType } from '@/libs/model-runtime';-import { FIRST_CHUNK_ERROR_KEY } from '../protocol';import { createReadableStream, readStreamChunk } from '../utils';import { OpenAIResponsesStream } from './responsesStream';diff --git a/packages/model-runtime/src/wenxin/index.test.ts b/packages/model-runtime/src/wenxin/index.test.tsindex e5bfff0299d..ecc405d8ec2 100644--- a/packages/model-runtime/src/wenxin/index.test.ts+++ b/packages/model-runtime/src/wenxin/index.test.ts@@ -1,9 +1,8 @@// @vitest-environment node+import { LobeOpenAICompatibleRuntime, ModelProvider } from '@lobechat/model-runtime';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { LobeOpenAICompatibleRuntime, ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';-+import { testProvider } from '../providerTestUtils';import { LobeWenxinAI } from './index';testProvider({diff --git a/packages/model-runtime/src/xai/index.test.ts b/packages/model-runtime/src/xai/index.test.tsindex 071f06083a1..dc8b0e4e0fe 100644--- a/packages/model-runtime/src/xai/index.test.ts+++ b/packages/model-runtime/src/xai/index.test.ts@@ -1,7 +1,7 @@// @vitest-environment node-import { ModelProvider } from '@/libs/model-runtime';-import { testProvider } from '@/libs/model-runtime/providerTestUtils';+import { ModelProvider } from '@lobechat/model-runtime';+import { testProvider } from '../providerTestUtils';import { LobeXAI } from './index';testProvider({diff --git a/packages/model-runtime/src/zeroone/index.test.ts b/packages/model-runtime/src/zeroone/index.test.tsindex 271ae57828c..0df6449ef9b 100644--- a/packages/model-runtime/src/zeroone/index.test.ts+++ b/packages/model-runtime/src/zeroone/index.test.ts@@ -1,6 +1,5 @@// @vitest-environment node-import { testProvider } from '@/libs/model-runtime/providerTestUtils';-+import { testProvider } from '../providerTestUtils';import { LobeZeroOneAI } from './index';testProvider({diff --git a/packages/model-runtime/src/zhipu/index.test.ts b/packages/model-runtime/src/zhipu/index.test.tsindex 92b8b34d6f8..d9e887e25d0 100644--- a/packages/model-runtime/src/zhipu/index.test.ts+++ b/packages/model-runtime/src/zhipu/index.test.ts@@ -1,10 +1,9 @@// @vitest-environment node+import { ChatStreamCallbacks, LobeOpenAICompatibleRuntime } from '@lobechat/model-runtime';import { OpenAI } from 'openai';import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { ChatStreamCallbacks, LobeOpenAI, LobeOpenAICompatibleRuntime } from '@/libs/model-runtime';-import * as debugStreamModule from '@/libs/model-runtime/utils/debugStream';-+import * as debugStreamModule from '../utils/debugStream';import { LobeZhipuAI } from './index';const bizErrorType = 'ProviderBizError';diff --git a/packages/model-runtime/vitest.config.mts b/packages/model-runtime/vitest.config.mtsindex 3eb8f5374ca..e769c7cd856 100644--- a/packages/model-runtime/vitest.config.mts+++ b/packages/model-runtime/vitest.config.mts@@ -4,14 +4,7 @@ import { defineConfig } from 'vitest/config';export default defineConfig({test: {alias: {- /* eslint-disable sort-keys-fix/sort-keys-fix */- '@/libs/model-runtime': resolve(__dirname, './src'),- '@/types': resolve(__dirname, '../types/src'),- '@/utils/errorResponse': resolve(__dirname, '../../src/utils/errorResponse'),- '@/utils': resolve(__dirname, '../utils/src'),- '@/const': resolve(__dirname, '../const/src'),'@': resolve(__dirname, '../../src'),- /* eslint-enable */},coverage: {reporter: ['text', 'json', 'lcov', 'text-summary'],diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.tsindex 55f645bac3b..3d6c8c86d81 100644--- a/packages/utils/src/index.ts+++ b/packages/utils/src/index.ts@@ -7,4 +7,5 @@ export * from './object';export * from './parseModels';export * from './pricing';export * from './safeParseJSON';+export * from './sleep';export * from './uuid';diff --git a/src/libs/traces/index.ts b/src/libs/traces/index.tsindex 9b783dd742b..526b769fcd0 100644--- a/src/libs/traces/index.ts+++ b/src/libs/traces/index.ts@@ -1,7 +1,7 @@+import { CURRENT_VERSION } from '@lobechat/const';import { Langfuse } from 'langfuse';import { CreateLangfuseTraceBody } from 'langfuse-core';-import { CURRENT_VERSION } from '@/const/version';import { getLangfuseConfig } from '@/envs/langfuse';import { TraceEventClient } from '@/libs/traces/event';diff --git a/src/server/modules/ModelRuntime/trace.ts b/src/server/modules/ModelRuntime/trace.tsindex a9c2fc58ee9..6ee18e7e0c2 100644--- a/src/server/modules/ModelRuntime/trace.ts+++ b/src/server/modules/ModelRuntime/trace.ts@@ -1,9 +1,8 @@+import { INBOX_SESSION_ID, LOBE_CHAT_OBSERVATION_ID, LOBE_CHAT_TRACE_ID } from '@lobechat/const';import { ChatStreamCallbacks, ChatStreamPayload } from '@lobechat/model-runtime';import { TracePayload, TraceTagMap } from '@lobechat/types';import { after } from 'next/server';-import { INBOX_SESSION_ID } from '@/const/session';-import { LOBE_CHAT_OBSERVATION_ID, LOBE_CHAT_TRACE_ID } from '@/const/trace';import { TraceClient } from '@/libs/traces';export interface AgentChatOptions {