@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.
- package/.env.example +0 -3
- package/.env.example.development +0 -3
- package/CHANGELOG.md +58 -0
- package/Dockerfile +1 -2
- package/changelog/v1.json +18 -0
- package/docs/self-hosting/advanced/auth.mdx +5 -6
- package/docs/self-hosting/advanced/auth.zh-CN.mdx +5 -6
- package/docs/self-hosting/environment-variables/auth.mdx +0 -7
- package/docs/self-hosting/environment-variables/auth.zh-CN.mdx +0 -7
- package/locales/en-US/chat.json +6 -1
- package/locales/en-US/discover.json +1 -0
- package/locales/zh-CN/chat.json +5 -0
- package/locales/zh-CN/discover.json +1 -0
- package/package.json +1 -1
- package/packages/agent-runtime/src/agents/GeneralChatAgent.ts +24 -0
- package/packages/agent-runtime/src/agents/__tests__/GeneralChatAgent.test.ts +210 -0
- package/packages/agent-runtime/src/types/instruction.ts +46 -2
- package/packages/builtin-tool-gtd/src/const.ts +1 -0
- package/packages/builtin-tool-gtd/src/executor/index.ts +38 -21
- package/packages/builtin-tool-gtd/src/manifest.ts +15 -0
- package/packages/builtin-tool-gtd/src/systemRole.ts +33 -1
- package/packages/builtin-tool-gtd/src/types.ts +55 -33
- package/packages/builtin-tool-local-system/src/client/Inspector/ReadLocalFile/index.tsx +1 -0
- package/packages/builtin-tool-local-system/src/client/Inspector/RunCommand/index.tsx +1 -1
- package/packages/builtin-tool-local-system/src/client/Render/WriteFile/index.tsx +1 -1
- package/packages/builtin-tool-local-system/src/client/Streaming/WriteFile/index.tsx +5 -1
- package/packages/builtin-tool-notebook/src/systemRole.ts +27 -7
- package/packages/conversation-flow/src/transformation/FlatListBuilder.ts +13 -1
- package/packages/conversation-flow/src/transformation/__tests__/FlatListBuilder.test.ts +40 -0
- package/packages/database/src/models/__tests__/messages/message.thread-query.test.ts +134 -1
- package/packages/database/src/models/message.ts +8 -1
- package/packages/database/src/models/thread.ts +1 -1
- package/packages/types/src/message/ui/chat.ts +2 -0
- package/packages/types/src/topic/thread.ts +20 -0
- package/scripts/prebuild.mts +2 -2
- package/src/app/[variants]/(main)/community/(list)/agent/features/List/Item.tsx +1 -0
- package/src/components/StreamingMarkdown/index.tsx +10 -43
- package/src/envs/__tests__/app.test.ts +81 -0
- package/src/envs/app.ts +14 -2
- package/src/envs/auth.test.ts +0 -13
- package/src/envs/auth.ts +0 -41
- package/src/features/Conversation/Messages/AssistantGroup/components/MessageContent.tsx +0 -2
- package/src/features/Conversation/Messages/Task/ClientTaskDetail/CompletedState.tsx +108 -0
- package/src/features/Conversation/Messages/Task/ClientTaskDetail/InitializingState.tsx +66 -0
- package/src/features/Conversation/Messages/Task/ClientTaskDetail/InstructionAccordion.tsx +63 -0
- package/src/features/Conversation/Messages/Task/ClientTaskDetail/ProcessingState.tsx +123 -0
- package/src/features/Conversation/Messages/Task/ClientTaskDetail/index.tsx +106 -0
- package/src/features/Conversation/Messages/Task/TaskDetailPanel/index.tsx +1 -0
- package/src/features/Conversation/Messages/Task/index.tsx +11 -6
- package/src/features/Conversation/Messages/Tasks/TaskItem/TaskTitle.tsx +3 -2
- package/src/features/Conversation/Messages/Tasks/shared/InitializingState.tsx +0 -4
- package/src/features/Conversation/Messages/Tasks/shared/utils.ts +22 -1
- package/src/features/Conversation/Messages/components/ContentLoading.tsx +1 -1
- package/src/features/Conversation/components/Thinking/index.tsx +9 -30
- package/src/features/Conversation/store/slices/data/action.ts +2 -3
- package/src/features/NavPanel/components/BackButton.tsx +10 -13
- package/src/features/NavPanel/components/NavPanelDraggable.tsx +4 -0
- package/src/hooks/useAutoScroll.ts +117 -0
- package/src/libs/better-auth/auth-client.ts +0 -9
- package/src/libs/better-auth/define-config.ts +13 -12
- package/src/libs/better-auth/sso/index.ts +2 -1
- package/src/libs/better-auth/utils/config.ts +2 -2
- package/src/libs/next/proxy/define-config.ts +4 -6
- package/src/locales/default/chat.ts +6 -1
- package/src/locales/default/discover.ts +2 -0
- package/src/server/routers/lambda/__tests__/integration/topic.integration.test.ts +74 -0
- package/src/server/routers/lambda/aiAgent.ts +239 -1
- package/src/server/routers/lambda/thread.ts +2 -0
- package/src/server/routers/lambda/topic.ts +6 -0
- package/src/server/services/agentRuntime/AgentRuntimeService.test.ts +4 -1
- package/src/server/services/agentRuntime/AgentRuntimeService.ts +2 -1
- package/src/server/services/message/__tests__/index.test.ts +37 -0
- package/src/server/services/message/index.ts +6 -1
- package/src/services/aiAgent.ts +51 -0
- package/src/services/topic/index.ts +4 -0
- package/src/store/chat/agents/createAgentExecutors.ts +714 -12
- package/src/store/chat/slices/aiChat/actions/streamingExecutor.ts +6 -1
- package/src/store/chat/slices/message/actions/query.ts +33 -1
- package/src/store/chat/slices/message/selectors/displayMessage.test.ts +10 -0
- package/src/store/chat/slices/message/selectors/displayMessage.ts +1 -0
- package/src/store/chat/slices/operation/types.ts +4 -0
- package/src/store/chat/slices/topic/action.test.ts +2 -1
- 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', () => {
|
|
@@ -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.
|
|
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.
|
|
570
|
+
await topicService.removeTopicsByAgentId(activeAgentId);
|
|
571
571
|
await refreshTopic();
|
|
572
572
|
|
|
573
573
|
// switch to default topic
|