@lobehub/lobehub 2.0.0-next.37 → 2.0.0-next.39
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 +50 -0
- package/apps/desktop/src/main/modules/networkProxy/__tests__/dispatcher.test.ts +401 -0
- package/apps/desktop/src/main/modules/networkProxy/__tests__/tester.test.ts +531 -0
- package/apps/desktop/src/main/modules/networkProxy/__tests__/urlBuilder.test.ts +349 -0
- package/apps/desktop/src/main/modules/networkProxy/__tests__/validator.test.ts +492 -0
- package/changelog/v1.json +14 -0
- package/locales/ar/auth.json +45 -1
- package/locales/ar/modelProvider.json +13 -1
- package/locales/bg-BG/auth.json +45 -1
- package/locales/bg-BG/modelProvider.json +13 -1
- package/locales/de-DE/auth.json +45 -1
- package/locales/de-DE/modelProvider.json +13 -1
- package/locales/en-US/auth.json +45 -1
- package/locales/en-US/modelProvider.json +13 -1
- package/locales/es-ES/auth.json +45 -1
- package/locales/es-ES/modelProvider.json +13 -1
- package/locales/fa-IR/auth.json +45 -1
- package/locales/fa-IR/modelProvider.json +13 -1
- package/locales/fr-FR/auth.json +45 -1
- package/locales/fr-FR/modelProvider.json +13 -1
- package/locales/it-IT/auth.json +45 -1
- package/locales/it-IT/modelProvider.json +13 -1
- package/locales/ja-JP/auth.json +45 -1
- package/locales/ja-JP/modelProvider.json +13 -1
- package/locales/ko-KR/auth.json +45 -1
- package/locales/ko-KR/modelProvider.json +13 -1
- package/locales/nl-NL/auth.json +45 -1
- package/locales/nl-NL/modelProvider.json +13 -1
- package/locales/pl-PL/auth.json +45 -1
- package/locales/pl-PL/modelProvider.json +13 -1
- package/locales/pt-BR/auth.json +45 -1
- package/locales/pt-BR/modelProvider.json +13 -1
- package/locales/ru-RU/auth.json +45 -1
- package/locales/ru-RU/modelProvider.json +13 -1
- package/locales/tr-TR/auth.json +45 -1
- package/locales/tr-TR/modelProvider.json +13 -1
- package/locales/vi-VN/auth.json +45 -1
- package/locales/vi-VN/modelProvider.json +13 -1
- package/locales/zh-CN/auth.json +45 -1
- package/locales/zh-CN/modelProvider.json +13 -1
- package/locales/zh-TW/auth.json +45 -1
- package/locales/zh-TW/modelProvider.json +13 -1
- package/package.json +1 -1
- package/packages/context-engine/src/processors/MessageCleanup.ts +1 -0
- package/packages/context-engine/src/processors/__tests__/MessageCleanup.test.ts +28 -0
- package/packages/obervability-otel/package.json +3 -1
- package/packages/obervability-otel/src/api.ts +2 -0
- package/packages/obervability-otel/src/trpc/convention.ts +16 -0
- package/packages/obervability-otel/src/trpc/index.test.ts +38 -0
- package/packages/obervability-otel/src/trpc/index.ts +62 -0
- package/packages/obervability-otel/src/trpc/metrics.ts +31 -0
- package/packages/types/src/usage/usageRecord.ts +54 -0
- package/packages/web-crawler/src/crawImpl/browserless.ts +1 -1
- package/packages/web-crawler/src/crawImpl/naive.ts +9 -9
- package/packages/web-crawler/src/crawler.ts +5 -5
- package/packages/web-crawler/src/urlRules.ts +13 -13
- package/packages/web-crawler/src/utils/appUrlRules.ts +5 -5
- package/src/app/[variants]/(main)/profile/hooks/useCategory.tsx +10 -1
- package/src/app/[variants]/(main)/profile/usage/Client.tsx +114 -0
- package/src/app/[variants]/(main)/profile/usage/features/UsageCards/ActiveModels/ModelTable.tsx +175 -0
- package/src/app/[variants]/(main)/profile/usage/features/UsageCards/ActiveModels/index.tsx +126 -0
- package/src/app/[variants]/(main)/profile/usage/features/UsageCards/MonthSpend.tsx +53 -0
- package/src/app/[variants]/(main)/profile/usage/features/UsageCards/TodaySpend.tsx +67 -0
- package/src/app/[variants]/(main)/profile/usage/features/UsageCards/index.tsx +19 -0
- package/src/app/[variants]/(main)/profile/usage/features/UsageTable.tsx +145 -0
- package/src/app/[variants]/(main)/profile/usage/features/UsageTrends.tsx +107 -0
- package/src/app/[variants]/(main)/profile/usage/features/components/UsageBarChart.tsx +48 -0
- package/src/app/[variants]/(main)/profile/usage/page.tsx +23 -0
- package/src/features/Conversation/Messages/Assistant/Tool/Render/CustomRender.tsx +3 -3
- package/src/features/Conversation/Messages/Group/Actions/WithoutContentId.tsx +37 -14
- package/src/features/Conversation/Messages/Group/Error/index.tsx +1 -1
- package/src/features/Conversation/Messages/Group/GroupChildren.tsx +13 -35
- package/src/features/Conversation/Messages/Group/GroupItem.tsx +43 -0
- package/src/features/Conversation/Messages/Group/Tool/Inspector/index.tsx +1 -2
- package/src/features/Conversation/Messages/Group/Tool/Render/CustomRender.tsx +1 -1
- package/src/features/Conversation/Messages/Group/Tool/index.tsx +0 -2
- package/src/features/Conversation/Messages/Group/index.tsx +7 -2
- package/src/features/Conversation/components/Extras/Usage/UsageDetail/index.tsx +3 -0
- package/src/features/Conversation/hooks/useChatListActionsBar.tsx +21 -7
- package/src/features/PluginsUI/Render/BuiltinType/index.tsx +1 -1
- package/src/features/PluginsUI/Render/MCPType/index.tsx +52 -0
- package/src/features/PluginsUI/Render/StandaloneType/Iframe.tsx +2 -2
- package/src/features/PluginsUI/Render/index.tsx +17 -0
- package/src/libs/mcp/client.ts +3 -2
- package/src/libs/mcp/types.ts +71 -0
- package/src/libs/trpc/lambda/index.ts +5 -2
- package/src/libs/trpc/middleware/openTelemetry.ts +141 -0
- package/src/locales/default/auth.ts +44 -0
- package/src/locales/default/chat.ts +1 -0
- package/src/server/routers/desktop/mcp.ts +1 -3
- package/src/server/routers/lambda/index.ts +2 -0
- package/src/server/routers/lambda/usage.ts +36 -0
- package/src/server/routers/tools/mcp.ts +1 -3
- package/src/server/services/mcp/index.test.ts +28 -15
- package/src/server/services/mcp/index.ts +29 -18
- package/src/server/services/usage/index.test.ts +310 -0
- package/src/server/services/usage/index.ts +164 -0
- package/src/services/chat/contextEngineering.test.ts +4 -0
- package/src/services/mcp.test.ts +7 -1
- package/src/services/mcp.ts +13 -12
- package/src/services/usage.ts +13 -0
- package/src/store/chat/agents/createAgentExecutors.ts +2 -3
- package/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts +40 -1
- package/src/store/chat/slices/aiChat/actions/streamingExecutor.ts +13 -5
- package/src/store/chat/slices/builtinTool/actions/__tests__/localSystem.test.ts +3 -3
- package/src/store/chat/slices/builtinTool/actions/__tests__/search.test.ts +6 -6
- package/src/store/chat/slices/builtinTool/actions/interpreter.ts +2 -2
- package/src/store/chat/slices/builtinTool/actions/localSystem.ts +2 -2
- package/src/store/chat/slices/builtinTool/actions/search.ts +6 -6
- package/src/store/chat/slices/message/actions/publicApi.ts +19 -1
- package/src/store/chat/slices/message/initialState.ts +5 -0
- package/src/store/chat/slices/message/selectors/chat.test.ts +22 -602
- package/src/store/chat/slices/message/selectors/chat.ts +0 -2
- package/src/store/chat/slices/message/selectors/dbMessage.test.ts +51 -0
- package/src/store/chat/slices/message/selectors/displayMessage.test.ts +818 -0
- package/src/store/chat/slices/message/selectors/displayMessage.ts +52 -1
- package/src/store/chat/slices/message/selectors/messageState.ts +2 -0
- package/src/store/chat/slices/plugin/action.test.ts +4 -4
- package/src/store/chat/slices/plugin/actions/index.ts +39 -0
- package/src/store/chat/slices/plugin/actions/internals.ts +83 -0
- package/src/store/chat/slices/plugin/actions/optimisticUpdate.ts +188 -0
- package/src/store/chat/slices/plugin/actions/pluginTypes.ts +213 -0
- package/src/store/chat/slices/plugin/actions/publicApi.ts +115 -0
- package/src/store/chat/slices/plugin/actions/workflow.ts +121 -0
- package/src/store/chat/store.ts +1 -1
- package/src/store/global/initialState.ts +1 -0
- package/src/store/chat/slices/plugin/action.ts +0 -539
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/* eslint-disable sort-keys-fix/sort-keys-fix, typescript-sort-keys/interface */
|
|
2
|
+
import { ChatToolPayload, UIChatMessage } from '@lobechat/types';
|
|
3
|
+
import { StateCreator } from 'zustand/vanilla';
|
|
4
|
+
|
|
5
|
+
import { ChatStore } from '@/store/chat/store';
|
|
6
|
+
|
|
7
|
+
import { displayMessageSelectors } from '../../message/selectors';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Public API for plugin operations
|
|
11
|
+
* These methods are called by UI components or other business scenarios
|
|
12
|
+
*/
|
|
13
|
+
export interface PluginPublicApiAction {
|
|
14
|
+
/**
|
|
15
|
+
* Fill plugin message content and optionally trigger AI message
|
|
16
|
+
*/
|
|
17
|
+
fillPluginMessageContent: (
|
|
18
|
+
id: string,
|
|
19
|
+
content: string,
|
|
20
|
+
triggerAiMessage?: boolean,
|
|
21
|
+
) => Promise<void>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Re-invoke a tool message (retry failed plugin call)
|
|
25
|
+
*/
|
|
26
|
+
reInvokeToolMessage: (id: string) => Promise<void>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Summary plugin content using AI
|
|
30
|
+
*/
|
|
31
|
+
summaryPluginContent: (id: string) => Promise<void>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Invoke different type of plugin based on payload type
|
|
35
|
+
* This is the unified entry point for plugin invocation
|
|
36
|
+
*/
|
|
37
|
+
internal_invokeDifferentTypePlugin: (id: string, payload: ChatToolPayload) => Promise<any>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const pluginPublicApi: StateCreator<
|
|
41
|
+
ChatStore,
|
|
42
|
+
[['zustand/devtools', never]],
|
|
43
|
+
[],
|
|
44
|
+
PluginPublicApiAction
|
|
45
|
+
> = (set, get) => ({
|
|
46
|
+
fillPluginMessageContent: async (id, content, triggerAiMessage) => {
|
|
47
|
+
const { triggerAIMessage, optimisticUpdateMessageContent } = get();
|
|
48
|
+
|
|
49
|
+
await optimisticUpdateMessageContent(id, content);
|
|
50
|
+
|
|
51
|
+
if (triggerAiMessage) await triggerAIMessage({ parentId: id });
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
reInvokeToolMessage: async (id) => {
|
|
55
|
+
const message = displayMessageSelectors.getDisplayMessageById(id)(get());
|
|
56
|
+
if (!message || message.role !== 'tool' || !message.plugin) return;
|
|
57
|
+
|
|
58
|
+
// if there is error content, then clear the error
|
|
59
|
+
if (!!message.pluginError) {
|
|
60
|
+
get().optimisticUpdateMessagePluginError(id, null);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const payload: ChatToolPayload = { ...message.plugin, id: message.tool_call_id! };
|
|
64
|
+
|
|
65
|
+
await get().internal_invokeDifferentTypePlugin(id, payload);
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
summaryPluginContent: async (id) => {
|
|
69
|
+
const message = displayMessageSelectors.getDisplayMessageById(id)(get());
|
|
70
|
+
if (!message || message.role !== 'tool') return;
|
|
71
|
+
|
|
72
|
+
await get().internal_execAgentRuntime({
|
|
73
|
+
messages: [
|
|
74
|
+
{
|
|
75
|
+
role: 'assistant',
|
|
76
|
+
content: '作为一名总结专家,请结合以上系统提示词,将以下内容进行总结:',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
...message,
|
|
80
|
+
content: message.content,
|
|
81
|
+
role: 'assistant',
|
|
82
|
+
name: undefined,
|
|
83
|
+
tool_call_id: undefined,
|
|
84
|
+
},
|
|
85
|
+
] as UIChatMessage[],
|
|
86
|
+
parentMessageId: message.id,
|
|
87
|
+
parentMessageType: 'assistant',
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
internal_invokeDifferentTypePlugin: async (id, payload) => {
|
|
92
|
+
switch (payload.type) {
|
|
93
|
+
case 'standalone': {
|
|
94
|
+
return await get().invokeStandaloneTypePlugin(id, payload);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
case 'markdown': {
|
|
98
|
+
return await get().invokeMarkdownTypePlugin(id, payload);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
case 'builtin': {
|
|
102
|
+
return await get().invokeBuiltinTool(id, payload);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
case 'mcp': {
|
|
107
|
+
return await get().invokeMCPTypePlugin(id, payload);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
default: {
|
|
111
|
+
return await get().invokeDefaultTypePlugin(id, payload);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* eslint-disable sort-keys-fix/sort-keys-fix, typescript-sort-keys/interface */
|
|
2
|
+
import { CreateMessageParams } from '@lobechat/types';
|
|
3
|
+
import { StateCreator } from 'zustand/vanilla';
|
|
4
|
+
|
|
5
|
+
import { messageService } from '@/services/message';
|
|
6
|
+
import { ChatStore } from '@/store/chat/store';
|
|
7
|
+
|
|
8
|
+
import { dbMessageSelectors, displayMessageSelectors } from '../../message/selectors';
|
|
9
|
+
import { threadSelectors } from '../../thread/selectors';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Workflow orchestration actions
|
|
13
|
+
* Handle complex business flows involving multiple steps
|
|
14
|
+
*/
|
|
15
|
+
export interface PluginWorkflowAction {
|
|
16
|
+
/**
|
|
17
|
+
* Create an assistant message by plugin result
|
|
18
|
+
*/
|
|
19
|
+
createAssistantMessageByPlugin: (content: string, parentId: string) => Promise<void>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Trigger AI message after tool calls
|
|
23
|
+
*/
|
|
24
|
+
triggerAIMessage: (params: {
|
|
25
|
+
parentId?: string;
|
|
26
|
+
traceId?: string;
|
|
27
|
+
threadId?: string;
|
|
28
|
+
inPortalThread?: boolean;
|
|
29
|
+
inSearchWorkflow?: boolean;
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Trigger tool calls (V1 deprecated method)
|
|
34
|
+
* @deprecated
|
|
35
|
+
*/
|
|
36
|
+
triggerToolCalls: (
|
|
37
|
+
id: string,
|
|
38
|
+
params?: { threadId?: string; inPortalThread?: boolean; inSearchWorkflow?: boolean },
|
|
39
|
+
) => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const pluginWorkflow: StateCreator<
|
|
43
|
+
ChatStore,
|
|
44
|
+
[['zustand/devtools', never]],
|
|
45
|
+
[],
|
|
46
|
+
PluginWorkflowAction
|
|
47
|
+
> = (set, get) => ({
|
|
48
|
+
createAssistantMessageByPlugin: async (content, parentId) => {
|
|
49
|
+
const newMessage: CreateMessageParams = {
|
|
50
|
+
content,
|
|
51
|
+
parentId,
|
|
52
|
+
role: 'assistant',
|
|
53
|
+
sessionId: get().activeId,
|
|
54
|
+
topicId: get().activeTopicId, // if there is activeTopicId,then add it to topicId
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const result = await messageService.createMessage(newMessage);
|
|
58
|
+
get().replaceMessages(result.messages);
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
triggerAIMessage: async ({ parentId, traceId, threadId, inPortalThread, inSearchWorkflow }) => {
|
|
62
|
+
const { internal_execAgentRuntime } = get();
|
|
63
|
+
|
|
64
|
+
const chats = inPortalThread
|
|
65
|
+
? threadSelectors.portalAIChatsWithHistoryConfig(get())
|
|
66
|
+
: displayMessageSelectors.mainAIChatsWithHistoryConfig(get());
|
|
67
|
+
|
|
68
|
+
await internal_execAgentRuntime({
|
|
69
|
+
messages: chats,
|
|
70
|
+
parentMessageId: parentId ?? chats.at(-1)!.id,
|
|
71
|
+
parentMessageType: 'user',
|
|
72
|
+
traceId,
|
|
73
|
+
threadId,
|
|
74
|
+
inPortalThread,
|
|
75
|
+
inSearchWorkflow,
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
triggerToolCalls: async (assistantId, { threadId, inPortalThread, inSearchWorkflow } = {}) => {
|
|
80
|
+
const message = displayMessageSelectors.getDisplayMessageById(assistantId)(get());
|
|
81
|
+
if (!message || !message.tools) return;
|
|
82
|
+
|
|
83
|
+
let shouldCreateMessage = false;
|
|
84
|
+
let latestToolId = '';
|
|
85
|
+
const messagePools = message.tools.map(async (payload) => {
|
|
86
|
+
const toolMessage: CreateMessageParams = {
|
|
87
|
+
content: '',
|
|
88
|
+
parentId: assistantId,
|
|
89
|
+
plugin: payload,
|
|
90
|
+
role: 'tool',
|
|
91
|
+
sessionId: get().activeId,
|
|
92
|
+
tool_call_id: payload.id,
|
|
93
|
+
threadId,
|
|
94
|
+
topicId: get().activeTopicId, // if there is activeTopicId,then add it to topicId
|
|
95
|
+
groupId: message.groupId, // Propagate groupId from parent message for group chat
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const result = await get().optimisticCreateMessage(toolMessage);
|
|
99
|
+
if (!result) return;
|
|
100
|
+
|
|
101
|
+
// trigger the plugin call
|
|
102
|
+
const data = await get().internal_invokeDifferentTypePlugin(result.id, payload);
|
|
103
|
+
|
|
104
|
+
if (data && !['markdown', 'standalone'].includes(payload.type)) {
|
|
105
|
+
shouldCreateMessage = true;
|
|
106
|
+
latestToolId = result.id;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
await Promise.all(messagePools);
|
|
111
|
+
|
|
112
|
+
await get().internal_toggleMessageInToolsCalling(false, assistantId);
|
|
113
|
+
|
|
114
|
+
// only default type tool calls should trigger AI message
|
|
115
|
+
if (!shouldCreateMessage) return;
|
|
116
|
+
|
|
117
|
+
const traceId = dbMessageSelectors.getTraceIdByDbMessageId(latestToolId)(get());
|
|
118
|
+
|
|
119
|
+
await get().triggerAIMessage({ traceId, threadId, inPortalThread, inSearchWorkflow });
|
|
120
|
+
},
|
|
121
|
+
});
|
package/src/store/chat/store.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { ChatBuiltinToolAction, chatToolSlice } from './slices/builtinTool/actio
|
|
|
10
10
|
import { ChatPortalAction, chatPortalSlice } from './slices/portal/action';
|
|
11
11
|
import { ChatTranslateAction, chatTranslate } from './slices/translate/action';
|
|
12
12
|
import { ChatMessageAction, chatMessage } from './slices/message/actions';
|
|
13
|
-
import { ChatPluginAction, chatPlugin } from './slices/plugin/
|
|
13
|
+
import { ChatPluginAction, chatPlugin } from './slices/plugin/actions';
|
|
14
14
|
import { ChatTopicAction, chatTopic } from './slices/topic/action';
|
|
15
15
|
import { ChatAIChatAction, chatAiChat } from './slices/aiChat/actions';
|
|
16
16
|
import { ChatTTSAction, chatTTS } from './slices/tts/action';
|