@lobehub/chat 1.21.10 → 1.21.11
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/CHANGELOG.md +25 -0
- package/package.json +1 -1
- package/src/app/(backend)/{api/openai → _deprecated}/createBizOpenAI/index.ts +1 -1
- package/src/app/(backend)/api/chat/[provider]/route.test.ts +2 -2
- package/src/app/(backend)/api/chat/[provider]/route.ts +3 -4
- package/src/app/(backend)/api/chat/models/[provider]/route.ts +3 -4
- package/src/app/(backend)/{api/middleware → middleware}/auth/index.test.ts +2 -2
- package/src/app/(backend)/{api/middleware → middleware}/auth/index.ts +1 -1
- package/src/app/(backend)/webapi/plugin/gateway/route.ts +2 -2
- package/src/app/(backend)/webapi/stt/openai/route.ts +1 -1
- package/src/app/(backend)/webapi/text-to-image/[provider]/route.ts +3 -3
- package/src/app/(backend)/webapi/tts/openai/route.ts +1 -1
- package/src/libs/agent-runtime/AgentRuntime.test.ts +1 -1
- package/src/libs/trpc/middleware/jwtPayload.test.ts +1 -1
- package/src/libs/trpc/middleware/jwtPayload.ts +1 -1
- package/src/libs/trpc/middleware/keyVaults.ts +1 -1
- package/src/{app/(backend)/api/chat/agentRuntime.test.ts → server/modules/AgentRuntime/index.test.ts} +1 -1
- package/src/server/routers/async/file.ts +1 -1
- package/src/server/routers/async/ragEval.ts +1 -1
- package/src/server/routers/lambda/chunk.ts +1 -1
- package/src/services/chat.ts +1 -1
- package/src/services/ollama.ts +1 -1
- package/src/store/chat/slices/message/actions/rag.ts +1 -1
- /package/src/app/(backend)/{api/openai → _deprecated}/createBizOpenAI/auth.test.ts +0 -0
- /package/src/app/(backend)/{api/openai → _deprecated}/createBizOpenAI/auth.ts +0 -0
- /package/src/app/(backend)/{api/openai → _deprecated}/createBizOpenAI/createAzureOpenai.ts +0 -0
- /package/src/app/(backend)/{api/openai → _deprecated}/createBizOpenAI/createOpenai.ts +0 -0
- /package/src/app/(backend)/{api/middleware → middleware}/auth/utils.test.ts +0 -0
- /package/src/app/(backend)/{api/middleware → middleware}/auth/utils.ts +0 -0
- /package/src/{app/(backend)/api/chat → server/modules/AgentRuntime}/apiKeyManager.test.ts +0 -0
- /package/src/{app/(backend)/api/chat → server/modules/AgentRuntime}/apiKeyManager.ts +0 -0
- /package/src/{app/(backend)/api/chat/agentRuntime.ts → server/modules/AgentRuntime/index.ts} +0 -0
- /package/src/{app/(backend)/api → utils}/errorResponse.test.ts +0 -0
- /package/src/{app/(backend)/api → utils}/errorResponse.ts +0 -0
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,31 @@
|
|
2
2
|
|
3
3
|
# Changelog
|
4
4
|
|
5
|
+
### [Version 1.21.11](https://github.com/lobehub/lobe-chat/compare/v1.21.10...v1.21.11)
|
6
|
+
|
7
|
+
<sup>Released on **2024-10-11**</sup>
|
8
|
+
|
9
|
+
#### ♻ Code Refactoring
|
10
|
+
|
11
|
+
- **misc**: Refactor the backend code for better organization.
|
12
|
+
|
13
|
+
<br/>
|
14
|
+
|
15
|
+
<details>
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
17
|
+
|
18
|
+
#### Code refactoring
|
19
|
+
|
20
|
+
- **misc**: Refactor the backend code for better organization, closes [#4287](https://github.com/lobehub/lobe-chat/issues/4287) ([9a369ac](https://github.com/lobehub/lobe-chat/commit/9a369ac))
|
21
|
+
|
22
|
+
</details>
|
23
|
+
|
24
|
+
<div align="right">
|
25
|
+
|
26
|
+
[](#readme-top)
|
27
|
+
|
28
|
+
</div>
|
29
|
+
|
5
30
|
### [Version 1.21.10](https://github.com/lobehub/lobe-chat/compare/v1.21.9...v1.21.10)
|
6
31
|
|
7
32
|
<sup>Released on **2024-10-11**</sup>
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lobehub/chat",
|
3
|
-
"version": "1.21.
|
3
|
+
"version": "1.21.11",
|
4
4
|
"description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
|
5
5
|
"keywords": [
|
6
6
|
"framework",
|
@@ -2,8 +2,8 @@ import OpenAI from 'openai';
|
|
2
2
|
|
3
3
|
import { getOpenAIAuthFromRequest } from '@/const/fetch';
|
4
4
|
import { ChatErrorType, ErrorType } from '@/types/fetch';
|
5
|
+
import { createErrorResponse } from '@/utils/errorResponse';
|
5
6
|
|
6
|
-
import { createErrorResponse } from '../../errorResponse';
|
7
7
|
import { checkAuth } from './auth';
|
8
8
|
import { createOpenai } from './createOpenai';
|
9
9
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
import { getAuth } from '@clerk/nextjs/server';
|
3
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
4
4
|
|
5
|
-
import { checkAuthMethod, getJWTPayload } from '@/app/(backend)/
|
5
|
+
import { checkAuthMethod, getJWTPayload } from '@/app/(backend)/middleware/auth/utils';
|
6
6
|
import { LOBE_CHAT_AUTH_HEADER, OAUTH_AUTHORIZED } from '@/const/auth';
|
7
7
|
import { AgentRuntime, LobeRuntimeAI } from '@/libs/agent-runtime';
|
8
8
|
import { ChatErrorType } from '@/types/fetch';
|
@@ -13,7 +13,7 @@ vi.mock('@clerk/nextjs/server', () => ({
|
|
13
13
|
getAuth: vi.fn(),
|
14
14
|
}));
|
15
15
|
|
16
|
-
vi.mock('
|
16
|
+
vi.mock('@/app/(backend)/middleware/auth/utils', () => ({
|
17
17
|
getJWTPayload: vi.fn(),
|
18
18
|
checkAuthMethod: vi.fn(),
|
19
19
|
}));
|
@@ -1,12 +1,11 @@
|
|
1
|
-
import {
|
1
|
+
import { checkAuth } from '@/app/(backend)/middleware/auth';
|
2
2
|
import { AgentRuntime, ChatCompletionErrorPayload } from '@/libs/agent-runtime';
|
3
|
+
import { createTraceOptions, initAgentRuntimeWithUserPayload } from '@/server/modules/AgentRuntime';
|
3
4
|
import { ChatErrorType } from '@/types/fetch';
|
4
5
|
import { ChatStreamPayload } from '@/types/openai/chat';
|
6
|
+
import { createErrorResponse } from '@/utils/errorResponse';
|
5
7
|
import { getTracePayload } from '@/utils/trace';
|
6
8
|
|
7
|
-
import { checkAuth } from '../../middleware/auth';
|
8
|
-
import { createTraceOptions, initAgentRuntimeWithUserPayload } from '../agentRuntime';
|
9
|
-
|
10
9
|
export const runtime = 'edge';
|
11
10
|
|
12
11
|
export const POST = checkAuth(async (req: Request, { params, jwtPayload, createRuntime }) => {
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import { NextResponse } from 'next/server';
|
2
2
|
|
3
|
-
import {
|
3
|
+
import { checkAuth } from '@/app/(backend)/middleware/auth';
|
4
4
|
import { ChatCompletionErrorPayload, ModelProvider } from '@/libs/agent-runtime';
|
5
|
+
import { initAgentRuntimeWithUserPayload } from '@/server/modules/AgentRuntime';
|
5
6
|
import { ChatErrorType } from '@/types/fetch';
|
6
|
-
|
7
|
-
import { checkAuth } from '../../../middleware/auth';
|
8
|
-
import { initAgentRuntimeWithUserPayload } from '../../agentRuntime';
|
7
|
+
import { createErrorResponse } from '@/utils/errorResponse';
|
9
8
|
|
10
9
|
export const runtime = 'edge';
|
11
10
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { getAuth } from '@clerk/nextjs/server';
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
3
3
|
|
4
|
-
import { createErrorResponse } from '@/app/(backend)/api/errorResponse';
|
5
4
|
import { AgentRuntimeError } from '@/libs/agent-runtime';
|
6
5
|
import { ChatErrorType } from '@/types/fetch';
|
6
|
+
import { createErrorResponse } from '@/utils/errorResponse';
|
7
7
|
|
8
8
|
import { RequestHandler, checkAuth } from './index';
|
9
9
|
import { checkAuthMethod, getJWTPayload } from './utils';
|
@@ -12,7 +12,7 @@ vi.mock('@clerk/nextjs/server', () => ({
|
|
12
12
|
getAuth: vi.fn(),
|
13
13
|
}));
|
14
14
|
|
15
|
-
vi.mock('@/
|
15
|
+
vi.mock('@/utils/errorResponse', () => ({
|
16
16
|
createErrorResponse: vi.fn(),
|
17
17
|
}));
|
18
18
|
|
@@ -2,10 +2,10 @@ import { AuthObject } from '@clerk/backend';
|
|
2
2
|
import { getAuth } from '@clerk/nextjs/server';
|
3
3
|
import { NextRequest } from 'next/server';
|
4
4
|
|
5
|
-
import { createErrorResponse } from '@/app/(backend)/api/errorResponse';
|
6
5
|
import { JWTPayload, LOBE_CHAT_AUTH_HEADER, OAUTH_AUTHORIZED, enableClerk } from '@/const/auth';
|
7
6
|
import { AgentRuntime, AgentRuntimeError, ChatCompletionErrorPayload } from '@/libs/agent-runtime';
|
8
7
|
import { ChatErrorType } from '@/types/fetch';
|
8
|
+
import { createErrorResponse } from '@/utils/errorResponse';
|
9
9
|
|
10
10
|
import { checkAuthMethod, getJWTPayload } from './utils';
|
11
11
|
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import { PluginRequestPayload } from '@lobehub/chat-plugin-sdk';
|
2
2
|
import { createGatewayOnEdgeRuntime } from '@lobehub/chat-plugins-gateway';
|
3
3
|
|
4
|
-
import {
|
5
|
-
import { getJWTPayload } from '@/app/(backend)/api/middleware/auth/utils';
|
4
|
+
import { getJWTPayload } from '@/app/(backend)/middleware/auth/utils';
|
6
5
|
import { getAppConfig } from '@/config/app';
|
7
6
|
import { LOBE_CHAT_AUTH_HEADER, OAUTH_AUTHORIZED, enableNextAuth } from '@/const/auth';
|
8
7
|
import { LOBE_CHAT_TRACE_ID, TraceNameMap } from '@/const/trace';
|
9
8
|
import { AgentRuntimeError } from '@/libs/agent-runtime';
|
10
9
|
import { TraceClient } from '@/libs/traces';
|
11
10
|
import { ChatErrorType, ErrorType } from '@/types/fetch';
|
11
|
+
import { createErrorResponse } from '@/utils/errorResponse';
|
12
12
|
import { getTracePayload } from '@/utils/trace';
|
13
13
|
|
14
14
|
import { parserPluginSettings } from './settings';
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { OpenAISTTPayload } from '@lobehub/tts';
|
2
2
|
import { createOpenaiAudioTranscriptions } from '@lobehub/tts/server';
|
3
3
|
|
4
|
-
import { createBizOpenAI } from '@/app/(backend)/
|
4
|
+
import { createBizOpenAI } from '@/app/(backend)/_deprecated/createBizOpenAI';
|
5
5
|
|
6
6
|
export const runtime = 'edge';
|
7
7
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { NextResponse } from 'next/server';
|
2
2
|
|
3
|
-
import {
|
4
|
-
import { createErrorResponse } from '@/app/(backend)/api/errorResponse';
|
5
|
-
import { checkAuth } from '@/app/(backend)/api/middleware/auth';
|
3
|
+
import { checkAuth } from '@/app/(backend)/middleware/auth';
|
6
4
|
import { ChatCompletionErrorPayload } from '@/libs/agent-runtime';
|
7
5
|
import { TextToImagePayload } from '@/libs/agent-runtime/types';
|
6
|
+
import { initAgentRuntimeWithUserPayload } from '@/server/modules/AgentRuntime';
|
8
7
|
import { ChatErrorType } from '@/types/fetch';
|
8
|
+
import { createErrorResponse } from '@/utils/errorResponse';
|
9
9
|
|
10
10
|
export const runtime = 'edge';
|
11
11
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { OpenAITTSPayload } from '@lobehub/tts';
|
2
2
|
import { createOpenaiAudioSpeech } from '@lobehub/tts/server';
|
3
3
|
|
4
|
-
import { createBizOpenAI } from '@/app/(backend)/
|
4
|
+
import { createBizOpenAI } from '@/app/(backend)/_deprecated/createBizOpenAI';
|
5
5
|
|
6
6
|
export const runtime = 'edge';
|
7
7
|
|
@@ -4,7 +4,6 @@ import { LangfuseGenerationClient, LangfuseTraceClient } from 'langfuse-core';
|
|
4
4
|
import { ClientOptions } from 'openai';
|
5
5
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
6
6
|
|
7
|
-
import { createTraceOptions } from '@/app/(backend)/api/chat/agentRuntime';
|
8
7
|
import * as langfuseCfg from '@/config/langfuse';
|
9
8
|
import { JWTPayload } from '@/const/auth';
|
10
9
|
import { TraceNameMap } from '@/const/trace';
|
@@ -28,6 +27,7 @@ import {
|
|
28
27
|
} from '@/libs/agent-runtime';
|
29
28
|
import { LobeStepfunAI } from '@/libs/agent-runtime/stepfun';
|
30
29
|
import LobeWenxinAI from '@/libs/agent-runtime/wenxin';
|
30
|
+
import { createTraceOptions } from '@/server/modules/AgentRuntime';
|
31
31
|
|
32
32
|
import { AgentChatOptions } from './AgentRuntime';
|
33
33
|
import { LobeBedrockAIParams } from './bedrock';
|
@@ -2,7 +2,7 @@
|
|
2
2
|
import { TRPCError } from '@trpc/server';
|
3
3
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
4
4
|
|
5
|
-
import * as utils from '@/app/(backend)/
|
5
|
+
import * as utils from '@/app/(backend)/middleware/auth/utils';
|
6
6
|
import { createCallerFactory } from '@/libs/trpc';
|
7
7
|
import { trpc } from '@/libs/trpc/init';
|
8
8
|
import { AuthContext, createContextInner } from '@/server/context';
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { TRPCError } from '@trpc/server';
|
2
2
|
|
3
|
-
import { getJWTPayload } from '@/app/(backend)/
|
3
|
+
import { getJWTPayload } from '@/app/(backend)/middleware/auth/utils';
|
4
4
|
import { trpc } from '@/libs/trpc/init';
|
5
5
|
|
6
6
|
export const jwtPayloadChecker = trpc.middleware(async (opts) => {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { TRPCError } from '@trpc/server';
|
2
2
|
|
3
|
-
import { getJWTPayload } from '@/app/(backend)/
|
3
|
+
import { getJWTPayload } from '@/app/(backend)/middleware/auth/utils';
|
4
4
|
import { trpc } from '@/libs/trpc/init';
|
5
5
|
|
6
6
|
export const keyVaults = trpc.middleware(async (opts) => {
|
@@ -27,7 +27,7 @@ import { AgentRuntime } from '@/libs/agent-runtime';
|
|
27
27
|
import { LobeStepfunAI } from '@/libs/agent-runtime/stepfun';
|
28
28
|
import LobeWenxinAI from '@/libs/agent-runtime/wenxin';
|
29
29
|
|
30
|
-
import { initAgentRuntimeWithUserPayload } from './
|
30
|
+
import { initAgentRuntimeWithUserPayload } from './index';
|
31
31
|
|
32
32
|
// 模拟依赖项
|
33
33
|
vi.mock('@/config/llm', () => ({
|
@@ -3,7 +3,6 @@ import { chunk } from 'lodash-es';
|
|
3
3
|
import pMap from 'p-map';
|
4
4
|
import { z } from 'zod';
|
5
5
|
|
6
|
-
import { initAgentRuntimeWithUserPayload } from '@/app/(backend)/api/chat/agentRuntime';
|
7
6
|
import { fileEnv } from '@/config/file';
|
8
7
|
import { DEFAULT_EMBEDDING_MODEL } from '@/const/settings';
|
9
8
|
import { ASYNC_TASK_TIMEOUT, AsyncTaskModel } from '@/database/server/models/asyncTask';
|
@@ -13,6 +12,7 @@ import { FileModel } from '@/database/server/models/file';
|
|
13
12
|
import { NewChunkItem, NewEmbeddingsItem } from '@/database/server/schemas/lobechat';
|
14
13
|
import { ModelProvider } from '@/libs/agent-runtime';
|
15
14
|
import { asyncAuthedProcedure, asyncRouter as router } from '@/libs/trpc/async';
|
15
|
+
import { initAgentRuntimeWithUserPayload } from '@/server/modules/AgentRuntime';
|
16
16
|
import { S3 } from '@/server/modules/S3';
|
17
17
|
import { ChunkService } from '@/server/services/chunk';
|
18
18
|
import {
|
@@ -2,7 +2,6 @@ import { TRPCError } from '@trpc/server';
|
|
2
2
|
import OpenAI from 'openai';
|
3
3
|
import { z } from 'zod';
|
4
4
|
|
5
|
-
import { initAgentRuntimeWithUserPayload } from '@/app/(backend)/api/chat/agentRuntime';
|
6
5
|
import { chainAnswerWithContext } from '@/chains/answerWithContext';
|
7
6
|
import { DEFAULT_EMBEDDING_MODEL, DEFAULT_MODEL } from '@/const/settings';
|
8
7
|
import { ChunkModel } from '@/database/server/models/chunk';
|
@@ -15,6 +14,7 @@ import {
|
|
15
14
|
} from '@/database/server/models/ragEval';
|
16
15
|
import { ModelProvider } from '@/libs/agent-runtime';
|
17
16
|
import { asyncAuthedProcedure, asyncRouter as router } from '@/libs/trpc/async';
|
17
|
+
import { initAgentRuntimeWithUserPayload } from '@/server/modules/AgentRuntime';
|
18
18
|
import { ChunkService } from '@/server/services/chunk';
|
19
19
|
import { AsyncTaskError } from '@/types/asyncTask';
|
20
20
|
import { EvalEvaluationStatus } from '@/types/eval';
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { inArray } from 'drizzle-orm';
|
2
2
|
import { z } from 'zod';
|
3
3
|
|
4
|
-
import { initAgentRuntimeWithUserPayload } from '@/app/(backend)/api/chat/agentRuntime';
|
5
4
|
import { DEFAULT_EMBEDDING_MODEL } from '@/const/settings';
|
6
5
|
import { serverDB } from '@/database/server';
|
7
6
|
import { AsyncTaskModel } from '@/database/server/models/asyncTask';
|
@@ -13,6 +12,7 @@ import { knowledgeBaseFiles } from '@/database/server/schemas/lobechat';
|
|
13
12
|
import { ModelProvider } from '@/libs/agent-runtime';
|
14
13
|
import { authedProcedure, router } from '@/libs/trpc';
|
15
14
|
import { keyVaults } from '@/libs/trpc/middleware/keyVaults';
|
15
|
+
import { initAgentRuntimeWithUserPayload } from '@/server/modules/AgentRuntime';
|
16
16
|
import { ChunkService } from '@/server/services/chunk';
|
17
17
|
import { SemanticSearchSchema } from '@/types/rag';
|
18
18
|
|
package/src/services/chat.ts
CHANGED
@@ -2,7 +2,6 @@ import { PluginRequestPayload, createHeadersWithPluginSettings } from '@lobehub/
|
|
2
2
|
import { produce } from 'immer';
|
3
3
|
import { merge } from 'lodash-es';
|
4
4
|
|
5
|
-
import { createErrorResponse } from '@/app/(backend)/api/errorResponse';
|
6
5
|
import { DEFAULT_MODEL_PROVIDER_LIST } from '@/config/modelProviders';
|
7
6
|
import { INBOX_GUIDE_SYSTEMROLE } from '@/const/guide';
|
8
7
|
import { INBOX_SESSION_ID } from '@/const/session';
|
@@ -24,6 +23,7 @@ import { ChatErrorType } from '@/types/fetch';
|
|
24
23
|
import { ChatMessage, MessageToolCall } from '@/types/message';
|
25
24
|
import type { ChatStreamPayload, OpenAIChatMessage } from '@/types/openai/chat';
|
26
25
|
import { UserMessageContentPart } from '@/types/openai/chat';
|
26
|
+
import { createErrorResponse } from '@/utils/errorResponse';
|
27
27
|
import { FetchSSEOptions, fetchSSE, getMessageError } from '@/utils/fetch';
|
28
28
|
import { genToolCallingName } from '@/utils/toolCall';
|
29
29
|
import { createTraceHeader, getTraceId } from '@/utils/trace';
|
package/src/services/ollama.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
import { ListResponse, Ollama as OllamaBrowser, ProgressResponse } from 'ollama/browser';
|
2
2
|
|
3
|
-
import { createErrorResponse } from '@/app/(backend)/api/errorResponse';
|
4
3
|
import { ModelProvider } from '@/libs/agent-runtime';
|
5
4
|
import { useUserStore } from '@/store/user';
|
6
5
|
import { keyVaultsConfigSelectors } from '@/store/user/selectors';
|
7
6
|
import { ChatErrorType } from '@/types/fetch';
|
7
|
+
import { createErrorResponse } from '@/utils/errorResponse';
|
8
8
|
import { getMessageError } from '@/utils/fetch';
|
9
9
|
|
10
10
|
const DEFAULT_BASE_URL = 'http://127.0.0.1:11434';
|
@@ -67,7 +67,7 @@ export const chatRag: StateCreator<ChatStore, [['zustand/devtools', never]], [],
|
|
67
67
|
// 1. get the rewrite query
|
68
68
|
let rewriteQuery = message?.ragQuery || userQuery;
|
69
69
|
|
70
|
-
// only rewrite query length is less than 10 characters
|
70
|
+
// only rewrite query length is less than 10 characters, refs: https://github.com/lobehub/lobe-chat/pull/4288
|
71
71
|
// if there is no ragQuery and there is a chat history
|
72
72
|
// we need to rewrite the user message to get better results
|
73
73
|
if (rewriteQuery.length < 10 && !message?.ragQuery && messages.length > 0) {
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
/package/src/{app/(backend)/api/chat/agentRuntime.ts → server/modules/AgentRuntime/index.ts}
RENAMED
File without changes
|
File without changes
|
File without changes
|