@lobehub/chat 1.26.20 → 1.26.21

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 CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.26.21](https://github.com/lobehub/lobe-chat/compare/v1.26.20...v1.26.21)
6
+
7
+ <sup>Released on **2024-11-04**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: If enable login and not signed in, return unauthorized error.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: If enable login and not signed in, return unauthorized error, closes [#4571](https://github.com/lobehub/lobe-chat/issues/4571) ([e00c90e](https://github.com/lobehub/lobe-chat/commit/e00c90e))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ### [Version 1.26.20](https://github.com/lobehub/lobe-chat/compare/v1.26.19...v1.26.20)
6
31
 
7
32
  <sup>Released on **2024-11-04**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.26.20",
3
+ "version": "1.26.21",
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,10 +2,8 @@ import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
2
2
  import { act } from '@testing-library/react';
3
3
  import { merge } from 'lodash-es';
4
4
  import OpenAI from 'openai';
5
- import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
5
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
6
6
 
7
- import { getAppConfig } from '@/config/app';
8
- import { getServerDBConfig } from '@/config/db';
9
7
  import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
10
8
  import {
11
9
  LobeAnthropicAI,
@@ -28,7 +26,6 @@ import {
28
26
  ModelProvider,
29
27
  } from '@/libs/agent-runtime';
30
28
  import { AgentRuntime } from '@/libs/agent-runtime';
31
- import { useFileStore } from '@/store/file';
32
29
  import { useToolStore } from '@/store/tool';
33
30
  import { UserStore } from '@/store/user';
34
31
  import { UserSettingsState, initialSettingsState } from '@/store/user/slices/settings/initialState';
@@ -38,6 +35,8 @@ import { ChatStreamPayload, type OpenAIChatMessage } from '@/types/openai/chat';
38
35
  import { LobeTool } from '@/types/tool';
39
36
 
40
37
  import { chatService, initializeWithClientStore } from '../chat';
38
+ import { useUserStore } from '@/store/user';
39
+ import {modelConfigSelectors} from "@/store/user/selectors";
41
40
 
42
41
  // Mocking external dependencies
43
42
  vi.mock('i18next', () => ({
@@ -524,6 +523,48 @@ describe('ChatService', () => {
524
523
  });
525
524
  });
526
525
 
526
+ it('should throw InvalidAccessCode error when enableFetchOnClient is true and auth is enabled but user is not signed in', async () => {
527
+ // Mock userStore
528
+ const mockUserStore = {
529
+ enableAuth: () => true,
530
+ isSignedIn: false,
531
+ };
532
+
533
+ // Mock modelConfigSelectors
534
+ const mockModelConfigSelectors = {
535
+ isProviderFetchOnClient: () => () => true,
536
+ };
537
+
538
+ vi.spyOn(useUserStore, 'getState').mockImplementationOnce(() => mockUserStore as any);
539
+ vi.spyOn(modelConfigSelectors, 'isProviderFetchOnClient').mockImplementationOnce(mockModelConfigSelectors.isProviderFetchOnClient);
540
+
541
+ const params: Partial<ChatStreamPayload> = {
542
+ model: 'test-model',
543
+ messages: [],
544
+ };
545
+ const options = {};
546
+ const expectedPayload = {
547
+ model: DEFAULT_AGENT_CONFIG.model,
548
+ stream: true,
549
+ ...DEFAULT_AGENT_CONFIG.params,
550
+ ...params,
551
+ };
552
+
553
+ const result = await chatService.getChatCompletion(params,options);
554
+
555
+ expect(global.fetch).toHaveBeenCalledWith(
556
+ expect.any(String),
557
+ {
558
+ body: JSON.stringify(expectedPayload),
559
+ headers: expect.objectContaining({
560
+ 'Content-Type': 'application/json',
561
+ }),
562
+ method: 'POST',
563
+ },
564
+ );
565
+ expect(result.status).toBe(401);
566
+ });
567
+
527
568
  // Add more test cases to cover different scenarios and edge cases
528
569
  });
529
570
 
@@ -8,7 +8,7 @@ import { INBOX_SESSION_ID } from '@/const/session';
8
8
  import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
9
9
  import { TracePayload, TraceTagMap } from '@/const/trace';
10
10
  import { isServerMode } from '@/const/version';
11
- import { AgentRuntime, ChatCompletionErrorPayload, ModelProvider } from '@/libs/agent-runtime';
11
+ import {AgentRuntime, AgentRuntimeError, ChatCompletionErrorPayload, ModelProvider} from '@/libs/agent-runtime';
12
12
  import { filesPrompts } from '@/prompts/files';
13
13
  import { useSessionStore } from '@/store/session';
14
14
  import { sessionMetaSelectors } from '@/store/session/selectors';
@@ -533,6 +533,14 @@ class ChatService {
533
533
  const agentRuntime = await initializeWithClientStore(params.provider, params.payload);
534
534
  const data = params.payload as ChatStreamPayload;
535
535
 
536
+ /**
537
+ * if enable login and not signed in, return unauthorized error
538
+ */
539
+ const userStore = useUserStore.getState();
540
+ if (userStore.enableAuth() && !userStore.isSignedIn) {
541
+ throw AgentRuntimeError.createError(ChatErrorType.InvalidAccessCode);
542
+ }
543
+
536
544
  return agentRuntime.chat(data, { signal: params.signal });
537
545
  };
538
546