@lobehub/chat 0.19.0 → 0.21.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 (34) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/package.json +1 -1
  3. package/src/{features → components}/SliderWithInput/index.tsx +1 -0
  4. package/src/locales/default/common.ts +2 -2
  5. package/src/locales/default/setting.ts +1 -0
  6. package/src/pages/chat/[id]/Config/SideBar.tsx +9 -5
  7. package/src/pages/chat/[id]/Config/Topic.tsx +27 -0
  8. package/src/pages/chat/[id]/Config/TopicItem.tsx +80 -0
  9. package/src/pages/chat/[id]/Conversation/Input/Action.tsx +66 -7
  10. package/src/pages/chat/[id]/Conversation/Input/index.tsx +5 -2
  11. package/src/pages/chat/[id]/Header.tsx +14 -10
  12. package/src/pages/chat/[id]/edit/AgentConfig/index.tsx +1 -1
  13. package/src/pages/chat/layout.tsx +10 -4
  14. package/src/pages/setting/SettingForm.tsx +1 -1
  15. package/src/prompts/chat.ts +19 -0
  16. package/src/store/session/selectors.ts +1 -1
  17. package/src/store/session/slices/agentConfig/selectors.ts +4 -0
  18. package/src/store/session/slices/chat/actions/index.ts +21 -0
  19. package/src/store/session/slices/chat/{action.ts → actions/message.ts} +33 -23
  20. package/src/store/session/slices/chat/actions/topic.ts +98 -0
  21. package/src/store/session/slices/chat/index.ts +1 -1
  22. package/src/store/session/slices/chat/initialState.ts +2 -5
  23. package/src/store/session/slices/chat/reducers/message.test.ts +92 -0
  24. package/src/store/session/slices/chat/reducers/message.ts +16 -1
  25. package/src/store/session/slices/chat/reducers/topic.test.ts +179 -0
  26. package/src/store/session/slices/chat/reducers/topic.ts +59 -0
  27. package/src/store/session/slices/chat/selectors/chat.ts +8 -4
  28. package/src/store/session/slices/chat/selectors/index.ts +5 -0
  29. package/src/store/session/slices/chat/selectors/topic.ts +16 -0
  30. package/src/store/session/slices/chat/selectors/utils.test.ts +81 -1
  31. package/src/store/session/slices/chat/selectors/utils.ts +8 -2
  32. package/src/store/session/slices/session/reducers/session.ts +25 -1
  33. package/src/types/topic.ts +0 -1
  34. package/src/pages/chat/[id]/Config/ConfigCell.tsx +0 -68
@@ -3,6 +3,7 @@ import { produce } from 'immer';
3
3
  import { ChatMessageMap } from '@/types/chatMessage';
4
4
  import { MetaData } from '@/types/meta';
5
5
  import { LobeAgentConfig, LobeAgentSession, LobeSessions } from '@/types/session';
6
+ import { ChatTopicMap } from '@/types/topic';
6
7
 
7
8
  /**
8
9
  * @title 添加会话
@@ -37,6 +38,19 @@ interface UpdateSessionChat {
37
38
  type: 'updateSessionChat';
38
39
  }
39
40
 
41
+ /**
42
+ * @title 更新会话聊天上下文
43
+ */
44
+ interface UpdateSessionTopic {
45
+ /**
46
+ * 会话 ID
47
+ */
48
+ id: string;
49
+ topics: ChatTopicMap;
50
+
51
+ type: 'updateSessionTopic';
52
+ }
53
+
40
54
  interface UpdateSessionMeta {
41
55
  id: string;
42
56
  key: keyof MetaData;
@@ -55,7 +69,8 @@ export type SessionDispatch =
55
69
  | UpdateSessionChat
56
70
  | RemoveSession
57
71
  | UpdateSessionMeta
58
- | UpdateSessionAgentConfig;
72
+ | UpdateSessionAgentConfig
73
+ | UpdateSessionTopic;
59
74
 
60
75
  export const sessionsReducer = (state: LobeSessions, payload: SessionDispatch): LobeSessions => {
61
76
  switch (payload.type) {
@@ -96,6 +111,15 @@ export const sessionsReducer = (state: LobeSessions, payload: SessionDispatch):
96
111
  });
97
112
  }
98
113
 
114
+ case 'updateSessionTopic': {
115
+ return produce(state, (draft) => {
116
+ const chat = draft[payload.id];
117
+ if (!chat) return;
118
+
119
+ chat.topics = payload.topics;
120
+ });
121
+ }
122
+
99
123
  case 'updateSessionConfig': {
100
124
  return produce(state, (draft) => {
101
125
  const { id, config } = payload;
@@ -1,7 +1,6 @@
1
1
  import { BaseDataModel } from '@/types/meta';
2
2
 
3
3
  export interface ChatTopic extends Omit<BaseDataModel, 'meta'> {
4
- chats: string[];
5
4
  favorite?: boolean;
6
5
  title: string;
7
6
  }
@@ -1,68 +0,0 @@
1
- import { Icon } from '@lobehub/ui';
2
- import { createStyles } from 'antd-style';
3
- import { LucideChevronRight, LucideIcon } from 'lucide-react';
4
- import { memo } from 'react';
5
- import { Flexbox } from 'react-layout-kit';
6
-
7
- const useStyles = createStyles(({ css, token }) => ({
8
- container: css`
9
- background: ${token.colorFillQuaternary};
10
- border-radius: 6px;
11
- `,
12
- split: css`
13
- border-bottom: 1px solid ${token.colorSplit};
14
- `,
15
- }));
16
- export interface ConfigItem {
17
- icon: LucideIcon;
18
- label: string;
19
- value?: string | number;
20
- }
21
-
22
- export type ConfigCellProps = ConfigItem;
23
-
24
- export const ConfigCell = memo<ConfigCellProps>(({ icon, label, value }) => {
25
- const { styles } = useStyles();
26
- return (
27
- <Flexbox
28
- className={styles.container}
29
- distribution={'space-between'}
30
- horizontal
31
- padding={'10px 12px'}
32
- >
33
- <Flexbox gap={8} horizontal>
34
- <Icon icon={icon} />
35
- <Flexbox>{label}</Flexbox>
36
- </Flexbox>
37
- {value ?? <Icon icon={LucideChevronRight} />}
38
- </Flexbox>
39
- );
40
- });
41
-
42
- export interface CellGroupProps {
43
- items: ConfigItem[];
44
- }
45
-
46
- export const ConfigCellGroup = memo<CellGroupProps>(({ items }) => {
47
- const { styles } = useStyles();
48
-
49
- return (
50
- <Flexbox className={styles.container}>
51
- {items.map(({ label, icon, value }, index) => (
52
- <Flexbox
53
- className={items.length === index + 1 ? undefined : styles.split}
54
- distribution={'space-between'}
55
- horizontal
56
- key={label}
57
- padding={'10px 12px'}
58
- >
59
- <Flexbox gap={8} horizontal>
60
- <Icon icon={icon} />
61
- <Flexbox>{label}</Flexbox>
62
- </Flexbox>
63
- {value ?? <Icon icon={LucideChevronRight} />}
64
- </Flexbox>
65
- ))}
66
- </Flexbox>
67
- );
68
- });