@lobehub/chat 1.61.5 → 1.62.0

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/changelog/v1.json +21 -0
  3. package/docs/self-hosting/advanced/auth/next-auth/casdoor.mdx +2 -1
  4. package/docs/self-hosting/advanced/auth/next-auth/casdoor.zh-CN.mdx +2 -1
  5. package/locales/en-US/components.json +3 -3
  6. package/package.json +2 -2
  7. package/src/app/(backend)/api/webhooks/casdoor/route.ts +5 -7
  8. package/src/app/(backend)/api/webhooks/casdoor/validateRequest.ts +7 -4
  9. package/src/components/ModelSelect/index.tsx +24 -2
  10. package/src/components/Thinking/index.tsx +7 -2
  11. package/src/config/aiModels/jina.ts +7 -5
  12. package/src/config/aiModels/perplexity.ts +8 -0
  13. package/src/config/llm.ts +8 -0
  14. package/src/database/client/migrations.json +12 -8
  15. package/src/database/migrations/0015_add_message_search_metadata.sql +2 -0
  16. package/src/database/migrations/meta/0015_snapshot.json +3616 -0
  17. package/src/database/migrations/meta/_journal.json +7 -0
  18. package/src/database/schemas/message.ts +3 -1
  19. package/src/database/server/models/message.ts +2 -0
  20. package/src/features/Conversation/components/ChatItem/index.tsx +10 -1
  21. package/src/features/Conversation/components/MarkdownElements/Thinking/Render.tsx +5 -1
  22. package/src/features/Conversation/components/MarkdownElements/remarkPlugins/createRemarkCustomTagPlugin.ts +1 -0
  23. package/src/features/Conversation/components/MarkdownElements/remarkPlugins/getNodeContent.test.ts +107 -0
  24. package/src/features/Conversation/components/MarkdownElements/remarkPlugins/getNodeContent.ts +6 -0
  25. package/src/libs/agent-runtime/perplexity/index.test.ts +156 -12
  26. package/src/libs/agent-runtime/utils/streams/anthropic.ts +3 -3
  27. package/src/libs/agent-runtime/utils/streams/bedrock/claude.ts +6 -2
  28. package/src/libs/agent-runtime/utils/streams/bedrock/llama.ts +3 -3
  29. package/src/libs/agent-runtime/utils/streams/google-ai.ts +3 -3
  30. package/src/libs/agent-runtime/utils/streams/ollama.ts +3 -3
  31. package/src/libs/agent-runtime/utils/streams/openai.ts +26 -8
  32. package/src/libs/agent-runtime/utils/streams/protocol.ts +33 -8
  33. package/src/libs/agent-runtime/utils/streams/vertex-ai.ts +3 -3
  34. package/src/locales/default/components.ts +1 -0
  35. package/src/server/globalConfig/index.test.ts +81 -0
  36. package/src/server/routers/lambda/user.test.ts +305 -0
  37. package/src/server/services/nextAuthUser/index.ts +2 -2
  38. package/src/store/chat/slices/aiChat/actions/generateAIChat.ts +17 -6
  39. package/src/store/chat/slices/message/action.ts +12 -7
  40. package/src/types/aiModel.ts +5 -0
  41. package/src/types/message/base.ts +13 -0
  42. package/src/types/message/chat.ts +3 -2
  43. package/src/utils/errorResponse.test.ts +37 -1
  44. package/src/utils/fetch/fetchSSE.ts +17 -1
@@ -1,4 +1,4 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, it, vi } from 'vitest';
2
2
 
3
3
  import { AgentRuntimeErrorType } from '@/libs/agent-runtime';
4
4
  import { ChatErrorType } from '@/types/fetch';
@@ -32,6 +32,30 @@ describe('createErrorResponse', () => {
32
32
  expect(response.status).toBe(403);
33
33
  });
34
34
 
35
+ it('returns a 429 status for InsufficientQuota error type', () => {
36
+ const errorType = AgentRuntimeErrorType.InsufficientQuota;
37
+ const response = createErrorResponse(errorType);
38
+ expect(response.status).toBe(429);
39
+ });
40
+
41
+ it('returns a 429 status for QuotaLimitReached error type', () => {
42
+ const errorType = AgentRuntimeErrorType.QuotaLimitReached;
43
+ const response = createErrorResponse(errorType);
44
+ expect(response.status).toBe(429);
45
+ });
46
+
47
+ it('returns a 400 status for ExceededContextWindow error type', () => {
48
+ const errorType = AgentRuntimeErrorType.ExceededContextWindow;
49
+ const response = createErrorResponse(errorType);
50
+ expect(response.status).toBe(400);
51
+ });
52
+
53
+ it('returns a 400 status for SystemTimeNotMatchError error type', () => {
54
+ const errorType = ChatErrorType.SystemTimeNotMatchError;
55
+ const response = createErrorResponse(errorType);
56
+ expect(response.status).toBe(400);
57
+ });
58
+
35
59
  describe('Provider Biz Error', () => {
36
60
  it('returns a 471 status for ProviderBizError error type', () => {
37
61
  const errorType = AgentRuntimeErrorType.ProviderBizError;
@@ -44,6 +68,18 @@ describe('createErrorResponse', () => {
44
68
  const response = createErrorResponse(errorType);
45
69
  expect(response.status).toBe(470);
46
70
  });
71
+
72
+ it('returns a 472 status for OllamaBizError error type', () => {
73
+ const errorType = AgentRuntimeErrorType.OllamaBizError;
74
+ const response = createErrorResponse(errorType);
75
+ expect(response.status).toBe(472);
76
+ });
77
+
78
+ it('returns a 472 status for OllamaServiceUnavailable error type', () => {
79
+ const errorType = ChatErrorType.OllamaServiceUnavailable;
80
+ const response = createErrorResponse(errorType);
81
+ expect(response.status).toBe(472);
82
+ });
47
83
  });
48
84
 
49
85
  // 测试状态码不在200-599范围内的情况
@@ -6,6 +6,7 @@ import { ChatErrorType } from '@/types/fetch';
6
6
  import { SmoothingParams } from '@/types/llm';
7
7
  import {
8
8
  ChatMessageError,
9
+ CitationItem,
9
10
  MessageToolCall,
10
11
  MessageToolCallChunk,
11
12
  MessageToolCallSchema,
@@ -20,6 +21,7 @@ type SSEFinishType = 'done' | 'error' | 'abort';
20
21
  export type OnFinishHandler = (
21
22
  text: string,
22
23
  context: {
24
+ citations?: CitationItem[];
23
25
  observationId?: string | null;
24
26
  reasoning?: string;
25
27
  toolCalls?: MessageToolCall[];
@@ -38,6 +40,11 @@ export interface MessageReasoningChunk {
38
40
  type: 'reasoning';
39
41
  }
40
42
 
43
+ export interface MessageCitationsChunk {
44
+ citations: CitationItem[];
45
+ type: 'citations';
46
+ }
47
+
41
48
  interface MessageToolCallsChunk {
42
49
  isAnimationActives?: boolean[];
43
50
  tool_calls: MessageToolCall[];
@@ -50,7 +57,7 @@ export interface FetchSSEOptions {
50
57
  onErrorHandle?: (error: ChatMessageError) => void;
51
58
  onFinish?: OnFinishHandler;
52
59
  onMessageHandle?: (
53
- chunk: MessageTextChunk | MessageToolCallsChunk | MessageReasoningChunk,
60
+ chunk: MessageTextChunk | MessageToolCallsChunk | MessageReasoningChunk | MessageCitationsChunk,
54
61
  ) => void;
55
62
  smoothing?: SmoothingParams | boolean;
56
63
  }
@@ -279,6 +286,7 @@ export const fetchSSE = async (url: string, options: RequestInit & FetchSSEOptio
279
286
  startSpeed: smoothingSpeed,
280
287
  });
281
288
 
289
+ let citations: CitationItem[] | undefined = undefined;
282
290
  await fetchEventSource(url, {
283
291
  body: options.body,
284
292
  fetch: options?.fetcher,
@@ -350,6 +358,13 @@ export const fetchSSE = async (url: string, options: RequestInit & FetchSSEOptio
350
358
 
351
359
  break;
352
360
  }
361
+
362
+ case 'citations': {
363
+ citations = data;
364
+ options.onMessageHandle?.({ citations: data, type: 'citations' });
365
+ break;
366
+ }
367
+
353
368
  case 'reasoning': {
354
369
  if (textSmoothing) {
355
370
  thinkingController.pushToQueue(data);
@@ -419,6 +434,7 @@ export const fetchSSE = async (url: string, options: RequestInit & FetchSSEOptio
419
434
  }
420
435
 
421
436
  await options?.onFinish?.(output, {
437
+ citations,
422
438
  observationId,
423
439
  reasoning: !!thinking ? thinking : undefined,
424
440
  toolCalls,