@lobehub/lobehub 2.0.0-next.327 → 2.0.0-next.329

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 (83) hide show
  1. package/.env.example +0 -3
  2. package/.env.example.development +0 -3
  3. package/CHANGELOG.md +58 -0
  4. package/Dockerfile +1 -2
  5. package/changelog/v1.json +18 -0
  6. package/docs/self-hosting/advanced/auth.mdx +5 -6
  7. package/docs/self-hosting/advanced/auth.zh-CN.mdx +5 -6
  8. package/docs/self-hosting/environment-variables/auth.mdx +0 -7
  9. package/docs/self-hosting/environment-variables/auth.zh-CN.mdx +0 -7
  10. package/locales/en-US/chat.json +6 -1
  11. package/locales/en-US/discover.json +1 -0
  12. package/locales/zh-CN/chat.json +5 -0
  13. package/locales/zh-CN/discover.json +1 -0
  14. package/package.json +1 -1
  15. package/packages/agent-runtime/src/agents/GeneralChatAgent.ts +24 -0
  16. package/packages/agent-runtime/src/agents/__tests__/GeneralChatAgent.test.ts +210 -0
  17. package/packages/agent-runtime/src/types/instruction.ts +46 -2
  18. package/packages/builtin-tool-gtd/src/const.ts +1 -0
  19. package/packages/builtin-tool-gtd/src/executor/index.ts +38 -21
  20. package/packages/builtin-tool-gtd/src/manifest.ts +15 -0
  21. package/packages/builtin-tool-gtd/src/systemRole.ts +33 -1
  22. package/packages/builtin-tool-gtd/src/types.ts +55 -33
  23. package/packages/builtin-tool-local-system/src/client/Inspector/ReadLocalFile/index.tsx +1 -0
  24. package/packages/builtin-tool-local-system/src/client/Inspector/RunCommand/index.tsx +1 -1
  25. package/packages/builtin-tool-local-system/src/client/Render/WriteFile/index.tsx +1 -1
  26. package/packages/builtin-tool-local-system/src/client/Streaming/WriteFile/index.tsx +5 -1
  27. package/packages/builtin-tool-notebook/src/systemRole.ts +27 -7
  28. package/packages/conversation-flow/src/transformation/FlatListBuilder.ts +13 -1
  29. package/packages/conversation-flow/src/transformation/__tests__/FlatListBuilder.test.ts +40 -0
  30. package/packages/database/src/models/__tests__/messages/message.thread-query.test.ts +134 -1
  31. package/packages/database/src/models/message.ts +8 -1
  32. package/packages/database/src/models/thread.ts +1 -1
  33. package/packages/types/src/message/ui/chat.ts +2 -0
  34. package/packages/types/src/topic/thread.ts +20 -0
  35. package/scripts/prebuild.mts +2 -2
  36. package/src/app/[variants]/(main)/community/(list)/agent/features/List/Item.tsx +1 -0
  37. package/src/components/StreamingMarkdown/index.tsx +10 -43
  38. package/src/envs/__tests__/app.test.ts +81 -0
  39. package/src/envs/app.ts +14 -2
  40. package/src/envs/auth.test.ts +0 -13
  41. package/src/envs/auth.ts +0 -41
  42. package/src/features/Conversation/Messages/AssistantGroup/components/MessageContent.tsx +0 -2
  43. package/src/features/Conversation/Messages/Task/ClientTaskDetail/CompletedState.tsx +108 -0
  44. package/src/features/Conversation/Messages/Task/ClientTaskDetail/InitializingState.tsx +66 -0
  45. package/src/features/Conversation/Messages/Task/ClientTaskDetail/InstructionAccordion.tsx +63 -0
  46. package/src/features/Conversation/Messages/Task/ClientTaskDetail/ProcessingState.tsx +123 -0
  47. package/src/features/Conversation/Messages/Task/ClientTaskDetail/index.tsx +106 -0
  48. package/src/features/Conversation/Messages/Task/TaskDetailPanel/index.tsx +1 -0
  49. package/src/features/Conversation/Messages/Task/index.tsx +11 -6
  50. package/src/features/Conversation/Messages/Tasks/TaskItem/TaskTitle.tsx +3 -2
  51. package/src/features/Conversation/Messages/Tasks/shared/InitializingState.tsx +0 -4
  52. package/src/features/Conversation/Messages/Tasks/shared/utils.ts +22 -1
  53. package/src/features/Conversation/Messages/components/ContentLoading.tsx +1 -1
  54. package/src/features/Conversation/components/Thinking/index.tsx +9 -30
  55. package/src/features/Conversation/store/slices/data/action.ts +2 -3
  56. package/src/features/NavPanel/components/BackButton.tsx +10 -13
  57. package/src/features/NavPanel/components/NavPanelDraggable.tsx +4 -0
  58. package/src/hooks/useAutoScroll.ts +117 -0
  59. package/src/libs/better-auth/auth-client.ts +0 -9
  60. package/src/libs/better-auth/define-config.ts +13 -12
  61. package/src/libs/better-auth/sso/index.ts +2 -1
  62. package/src/libs/better-auth/utils/config.ts +2 -2
  63. package/src/libs/next/proxy/define-config.ts +4 -6
  64. package/src/locales/default/chat.ts +6 -1
  65. package/src/locales/default/discover.ts +2 -0
  66. package/src/server/routers/lambda/__tests__/integration/topic.integration.test.ts +74 -0
  67. package/src/server/routers/lambda/aiAgent.ts +239 -1
  68. package/src/server/routers/lambda/thread.ts +2 -0
  69. package/src/server/routers/lambda/topic.ts +6 -0
  70. package/src/server/services/agentRuntime/AgentRuntimeService.test.ts +4 -1
  71. package/src/server/services/agentRuntime/AgentRuntimeService.ts +2 -1
  72. package/src/server/services/message/__tests__/index.test.ts +37 -0
  73. package/src/server/services/message/index.ts +6 -1
  74. package/src/services/aiAgent.ts +51 -0
  75. package/src/services/topic/index.ts +4 -0
  76. package/src/store/chat/agents/createAgentExecutors.ts +714 -12
  77. package/src/store/chat/slices/aiChat/actions/streamingExecutor.ts +6 -1
  78. package/src/store/chat/slices/message/actions/query.ts +33 -1
  79. package/src/store/chat/slices/message/selectors/displayMessage.test.ts +10 -0
  80. package/src/store/chat/slices/message/selectors/displayMessage.ts +1 -0
  81. package/src/store/chat/slices/operation/types.ts +4 -0
  82. package/src/store/chat/slices/topic/action.test.ts +2 -1
  83. package/src/store/chat/slices/topic/action.ts +1 -1
@@ -4,7 +4,9 @@ import {
4
4
  AgentRuntime,
5
5
  type AgentRuntimeContext,
6
6
  type AgentState,
7
+ type Cost,
7
8
  GeneralChatAgent,
9
+ type Usage,
8
10
  computeStepContext,
9
11
  } from '@lobechat/agent-runtime';
10
12
  import { PageAgentIdentifier } from '@lobechat/builtin-tool-page-agent';
@@ -130,7 +132,7 @@ export interface StreamingExecutorAction {
130
132
  */
131
133
  parentOperationId?: string;
132
134
  skipCreateFirstMessage?: boolean;
133
- }) => Promise<void>;
135
+ }) => Promise<{ cost?: Cost; usage?: Usage } | void>;
134
136
  }
135
137
 
136
138
  export const streamingExecutor: StateCreator<
@@ -875,5 +877,8 @@ export const streamingExecutor: StateCreator<
875
877
  console.error('Desktop notification error:', error);
876
878
  }
877
879
  }
880
+
881
+ // Return usage and cost data for caller to use
882
+ return { cost: state.cost, usage: state.usage };
878
883
  },
879
884
  });
@@ -1,9 +1,11 @@
1
1
  import { parse } from '@lobechat/conversation-flow';
2
2
  import { type ConversationContext, type UIChatMessage } from '@lobechat/types';
3
3
  import isEqual from 'fast-deep-equal';
4
+ import { type SWRResponse } from 'swr';
4
5
  import { type StateCreator } from 'zustand/vanilla';
5
6
 
6
- import { mutate } from '@/libs/swr';
7
+ import { mutate, useClientDataSWRWithSync } from '@/libs/swr';
8
+ import { messageService } from '@/services/message';
7
9
  import { type ChatStore } from '@/store/chat/store';
8
10
 
9
11
  import { type MessageMapKeyInput, messageMapKey } from '../../../utils/messageMapKey';
@@ -39,6 +41,18 @@ export interface MessageQueryAction {
39
41
  operationId?: string;
40
42
  },
41
43
  ) => void;
44
+
45
+ /**
46
+ * Fetch messages for a specific context using SWR
47
+ * Used for fetching thread messages or messages for a specific context
48
+ *
49
+ * @param context - Conversation context with agentId, topicId, threadId, etc.
50
+ * @param skipFetch - When true, SWR key is null and no fetch occurs
51
+ */
52
+ useFetchMessages: (
53
+ context: ConversationContext,
54
+ skipFetch?: boolean,
55
+ ) => SWRResponse<UIChatMessage[]>;
42
56
  }
43
57
 
44
58
  export const messageQuery: StateCreator<
@@ -111,4 +125,22 @@ export const messageQuery: StateCreator<
111
125
  params?.action ?? 'replaceMessages',
112
126
  );
113
127
  },
128
+
129
+ useFetchMessages: (context, skipFetch) => {
130
+ // Skip fetch when skipFetch is true or required fields are missing
131
+ const shouldFetch = !skipFetch && !!context.agentId && !!context.topicId;
132
+
133
+ return useClientDataSWRWithSync<UIChatMessage[]>(
134
+ shouldFetch ? ['CHAT_STORE_FETCH_MESSAGES', context] : null,
135
+ () => messageService.getMessages(context),
136
+ {
137
+ onData: (data) => {
138
+ if (!data || !context.topicId) return;
139
+
140
+ // Use replaceMessages to store the fetched messages
141
+ get().replaceMessages(data, { action: 'useFetchMessages', context });
142
+ },
143
+ },
144
+ );
145
+ },
114
146
  });
@@ -347,6 +347,16 @@ describe('displayMessageSelectors', () => {
347
347
  messageMapKey({ agentId: 'testId', groupId: 'groupId', topicId: 'topicId' }),
348
348
  );
349
349
  });
350
+
351
+ it('should generate correct key with activeThreadId for thread conversations', () => {
352
+ const state: Partial<ChatStore> = {
353
+ activeAgentId: 'testId',
354
+ activeThreadId: 'threadId',
355
+ activeTopicId: 'topicId',
356
+ };
357
+ const result = displayMessageSelectors.currentDisplayChatKey(state as ChatStore);
358
+ expect(result).toBe('thread_testId_topicId_threadId');
359
+ });
350
360
  });
351
361
 
352
362
  describe('activeDisplayMessages with group chat messages', () => {
@@ -30,6 +30,7 @@ export const currentDisplayChatKey = (s: ChatStoreState) =>
30
30
  messageMapKey({
31
31
  agentId: s.activeAgentId,
32
32
  groupId: s.activeGroupId,
33
+ threadId: s.activeThreadId,
33
34
  topicId: s.activeTopicId,
34
35
  });
35
36
 
@@ -53,6 +53,10 @@ export type OperationType =
53
53
  | 'groupAgentGenerate' // Group agent generate (deprecated, use groupAgentStream)
54
54
  | 'groupAgentStream' // Group agent SSE stream (sub-operation of execServerAgentRuntime)
55
55
 
56
+ // === Async Task (Desktop only) ===
57
+ | 'execClientTask' // Execute single async sub-agent task on desktop client
58
+ | 'execClientTasks' // Execute multiple async sub-agent tasks on desktop client
59
+
56
60
  // === Others ===
57
61
  | 'translate' // Translate message
58
62
  | 'topicSummary' // Topic summary
@@ -28,6 +28,7 @@ vi.mock('zustand/traditional');
28
28
  vi.mock('@/services/topic', () => ({
29
29
  topicService: {
30
30
  removeTopics: vi.fn(),
31
+ removeTopicsByAgentId: vi.fn(),
31
32
  removeAllTopic: vi.fn(),
32
33
  removeTopic: vi.fn(),
33
34
  cloneTopic: vi.fn(),
@@ -570,7 +571,7 @@ describe('topic action', () => {
570
571
  await result.current.removeSessionTopics();
571
572
  });
572
573
 
573
- expect(topicService.removeTopics).toHaveBeenCalledWith(activeAgentId);
574
+ expect(topicService.removeTopicsByAgentId).toHaveBeenCalledWith(activeAgentId);
574
575
  expect(refreshTopicSpy).toHaveBeenCalled();
575
576
  expect(switchTopicSpy).toHaveBeenCalled();
576
577
  });
@@ -567,7 +567,7 @@ export const chatTopic: StateCreator<
567
567
  const { switchTopic, activeAgentId, refreshTopic } = get();
568
568
  if (!activeAgentId) return;
569
569
 
570
- await topicService.removeTopics(activeAgentId);
570
+ await topicService.removeTopicsByAgentId(activeAgentId);
571
571
  await refreshTopic();
572
572
 
573
573
  // switch to default topic