@lobehub/lobehub 2.0.0-next.187 → 2.0.0-next.189
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/changelog/v1.json +18 -0
- package/e2e/CLAUDE.md +109 -2
- package/e2e/docs/llm-mock.md +68 -0
- package/e2e/docs/local-setup.md +354 -0
- package/e2e/docs/testing-tips.md +94 -0
- package/e2e/src/features/journeys/agent/agent-conversation.feature +0 -32
- package/e2e/src/mocks/llm/index.ts +6 -6
- package/e2e/src/steps/agent/conversation.steps.ts +3 -471
- package/locales/ar/models.json +89 -5
- package/locales/ar/plugin.json +5 -0
- package/locales/ar/providers.json +1 -0
- package/locales/bg-BG/models.json +68 -0
- package/locales/bg-BG/plugin.json +5 -0
- package/locales/bg-BG/providers.json +1 -0
- package/locales/de-DE/models.json +85 -0
- package/locales/de-DE/plugin.json +5 -0
- package/locales/de-DE/providers.json +1 -0
- package/locales/en-US/models.json +11 -10
- package/locales/en-US/plugin.json +5 -0
- package/locales/en-US/providers.json +1 -0
- package/locales/es-ES/models.json +72 -0
- package/locales/es-ES/plugin.json +5 -0
- package/locales/es-ES/providers.json +1 -0
- package/locales/fa-IR/models.json +86 -0
- package/locales/fa-IR/plugin.json +5 -0
- package/locales/fa-IR/providers.json +1 -0
- package/locales/fr-FR/models.json +49 -0
- package/locales/fr-FR/plugin.json +5 -0
- package/locales/fr-FR/providers.json +1 -0
- package/locales/it-IT/models.json +82 -0
- package/locales/it-IT/plugin.json +5 -0
- package/locales/it-IT/providers.json +1 -0
- package/locales/ja-JP/models.json +42 -5
- package/locales/ja-JP/plugin.json +5 -0
- package/locales/ja-JP/providers.json +1 -0
- package/locales/ko-KR/models.json +54 -0
- package/locales/ko-KR/plugin.json +5 -0
- package/locales/ko-KR/providers.json +1 -0
- package/locales/nl-NL/models.json +12 -1
- package/locales/nl-NL/plugin.json +5 -0
- package/locales/nl-NL/providers.json +1 -0
- package/locales/pl-PL/models.json +46 -0
- package/locales/pl-PL/plugin.json +5 -0
- package/locales/pl-PL/providers.json +1 -0
- package/locales/pt-BR/models.json +59 -0
- package/locales/pt-BR/plugin.json +5 -0
- package/locales/pt-BR/providers.json +1 -0
- package/locales/ru-RU/models.json +85 -0
- package/locales/ru-RU/plugin.json +5 -0
- package/locales/ru-RU/providers.json +1 -0
- package/locales/tr-TR/models.json +81 -0
- package/locales/tr-TR/plugin.json +5 -0
- package/locales/tr-TR/providers.json +1 -0
- package/locales/vi-VN/models.json +54 -0
- package/locales/vi-VN/plugin.json +5 -0
- package/locales/vi-VN/providers.json +1 -0
- package/locales/zh-CN/models.json +42 -5
- package/locales/zh-CN/plugin.json +5 -0
- package/locales/zh-CN/providers.json +1 -0
- package/locales/zh-TW/models.json +85 -0
- package/locales/zh-TW/plugin.json +5 -0
- package/locales/zh-TW/providers.json +1 -0
- package/package.json +2 -2
- package/packages/builtin-tool-gtd/src/manifest.ts +13 -8
- package/packages/builtin-tool-gtd/src/systemRole.ts +54 -19
- package/packages/builtin-tool-knowledge-base/package.json +1 -0
- package/packages/builtin-tool-knowledge-base/src/client/Inspector/ReadKnowledge/index.tsx +97 -0
- package/packages/builtin-tool-knowledge-base/src/client/Inspector/SearchKnowledgeBase/index.tsx +75 -0
- package/packages/builtin-tool-knowledge-base/src/client/Inspector/index.ts +11 -0
- package/packages/builtin-tool-knowledge-base/src/client/Render/ReadKnowledge/FileCard.tsx +12 -12
- package/packages/builtin-tool-knowledge-base/src/client/Render/ReadKnowledge/index.tsx +16 -25
- package/packages/builtin-tool-knowledge-base/src/client/Render/SearchKnowledgeBase/Item/index.tsx +21 -47
- package/packages/builtin-tool-knowledge-base/src/client/Render/SearchKnowledgeBase/index.tsx +19 -31
- package/packages/builtin-tool-knowledge-base/src/client/Render/index.ts +0 -5
- package/packages/builtin-tool-knowledge-base/src/client/index.ts +5 -1
- package/packages/builtin-tool-knowledge-base/src/executor/index.ts +119 -0
- package/packages/builtin-tool-local-system/package.json +1 -0
- package/packages/builtin-tool-local-system/src/client/Inspector/EditLocalFile/index.tsx +44 -29
- package/packages/builtin-tool-local-system/src/client/Inspector/GrepContent/index.tsx +20 -18
- package/packages/builtin-tool-local-system/src/client/Inspector/ListLocalFiles/index.tsx +76 -0
- package/packages/builtin-tool-local-system/src/client/Inspector/ReadLocalFile/index.tsx +8 -32
- package/packages/builtin-tool-local-system/src/client/Inspector/RenameLocalFile/index.tsx +62 -0
- package/packages/builtin-tool-local-system/src/client/Inspector/SearchLocalFiles/index.tsx +17 -11
- package/packages/builtin-tool-local-system/src/client/Inspector/WriteLocalFile/index.tsx +61 -0
- package/packages/builtin-tool-local-system/src/client/Inspector/index.ts +6 -0
- package/packages/builtin-tool-local-system/src/client/Render/EditLocalFile/index.tsx +6 -1
- package/packages/builtin-tool-local-system/src/client/Render/SearchFiles/SearchQuery/SearchView.tsx +19 -31
- package/packages/builtin-tool-local-system/src/client/Render/SearchFiles/SearchQuery/index.tsx +2 -42
- package/packages/builtin-tool-local-system/src/client/Render/index.ts +0 -2
- package/packages/builtin-tool-local-system/src/client/components/FilePathDisplay.tsx +56 -0
- package/packages/builtin-tool-local-system/src/client/components/index.ts +2 -0
- package/packages/builtin-tool-local-system/src/executor/index.ts +435 -0
- package/packages/builtin-tool-web-browsing/src/client/Inspector/Search/index.tsx +32 -5
- package/packages/model-runtime/src/core/contextBuilders/google.test.ts +84 -0
- package/packages/model-runtime/src/core/contextBuilders/google.ts +37 -1
- package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/List/Item/Actions.tsx +4 -13
- package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/List/Item/index.tsx +23 -29
- package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/List/Item/useDropdownMenu.tsx +3 -3
- package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/TopicListContent/ThreadList/ThreadItem/Actions.tsx +4 -13
- package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/TopicListContent/ThreadList/ThreadItem/index.tsx +10 -18
- package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/TopicListContent/ThreadList/ThreadItem/useDropdownMenu.tsx +3 -3
- package/src/app/[variants]/(main)/community/(detail)/assistant/features/Sidebar/ActionButton/AddAgent.tsx +47 -27
- package/src/app/[variants]/(main)/community/(detail)/user/features/UserAgentCard.tsx +4 -3
- package/src/app/[variants]/(main)/group/_layout/Sidebar/Topic/List/Item/Actions.tsx +4 -13
- package/src/app/[variants]/(main)/group/_layout/Sidebar/Topic/List/Item/index.tsx +23 -29
- package/src/app/[variants]/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.tsx +3 -3
- package/src/app/[variants]/(main)/group/_layout/Sidebar/Topic/TopicListContent/ThreadList/ThreadItem/Actions.tsx +4 -13
- package/src/app/[variants]/(main)/group/_layout/Sidebar/Topic/TopicListContent/ThreadList/ThreadItem/index.tsx +10 -18
- package/src/app/[variants]/(main)/group/_layout/Sidebar/Topic/TopicListContent/ThreadList/ThreadItem/useDropdownMenu.tsx +3 -3
- package/src/app/[variants]/(main)/group/profile/features/AgentBuilder/TopicSelector.tsx +18 -20
- package/src/app/[variants]/(main)/home/_layout/Body/Agent/List/AgentGroupItem/index.tsx +19 -25
- package/src/app/[variants]/(main)/home/_layout/Body/Agent/List/AgentItem/index.tsx +21 -26
- package/src/app/[variants]/(main)/home/_layout/Body/Agent/List/Item/Actions.tsx +4 -13
- package/src/app/[variants]/(main)/home/_layout/Body/Agent/List/Item/useDropdownMenu.tsx +3 -3
- package/src/app/[variants]/(main)/home/_layout/Body/Project/List/Actions.tsx +4 -13
- package/src/app/[variants]/(main)/home/_layout/Body/Project/List/Item.tsx +8 -15
- package/src/app/[variants]/(main)/home/_layout/Body/Project/List/useDropdownMenu.tsx +3 -3
- package/src/app/[variants]/(main)/home/_layout/Header/components/AddButton.tsx +3 -4
- package/src/app/[variants]/(main)/page/_layout/Body/List/Item/Actions.tsx +4 -13
- package/src/app/[variants]/(main)/page/_layout/Body/List/Item/index.tsx +13 -20
- package/src/app/[variants]/(main)/page/_layout/Body/List/Item/useDropdownMenu.tsx +3 -3
- package/src/app/[variants]/(main)/resource/(home)/_layout/Body/LibraryList/List/Item/Actions.tsx +4 -13
- package/src/app/[variants]/(main)/resource/(home)/_layout/Body/LibraryList/List/Item/index.tsx +16 -23
- package/src/app/[variants]/(main)/resource/(home)/_layout/Body/LibraryList/List/Item/useDropdownMenu.tsx +3 -3
- package/src/app/[variants]/(main)/resource/library/_layout/Header/LibraryHead.tsx +4 -6
- package/src/features/AgentBuilder/TopicSelector.tsx +18 -17
- package/src/features/Conversation/ChatItem/style.ts +7 -0
- package/src/features/Conversation/Messages/Assistant/Actions/Error.tsx +1 -3
- package/src/features/Conversation/Messages/Assistant/Actions/index.tsx +37 -16
- package/src/features/Conversation/Messages/AssistantGroup/Actions/index.tsx +36 -17
- package/src/features/Conversation/Messages/Supervisor/Actions/index.tsx +36 -17
- package/src/features/Conversation/Messages/Task/Actions/Error.tsx +1 -3
- package/src/features/Conversation/Messages/Task/Actions/index.tsx +31 -15
- package/src/features/Conversation/Messages/User/Actions/index.tsx +1 -1
- package/src/features/Conversation/Messages/index.tsx +8 -59
- package/src/features/Conversation/components/ShareMessageModal/index.tsx +1 -1
- package/src/features/Conversation/hooks/useChatItemContextMenu.tsx +313 -83
- package/src/features/NavPanel/components/NavItem.tsx +33 -3
- package/src/features/PageEditor/Copilot/TopicSelector/Actions.tsx +6 -14
- package/src/features/PageEditor/Copilot/TopicSelector/TopicItem.tsx +1 -0
- package/src/features/PageEditor/Copilot/TopicSelector/useDropdownMenu.tsx +6 -3
- package/src/features/ResourceManager/components/Explorer/ItemDropdown/DropdownMenu.tsx +12 -35
- package/src/features/ResourceManager/components/Explorer/ItemDropdown/useFileItemDropdown.tsx +4 -8
- package/src/features/ResourceManager/components/Explorer/ListView/ListItem/index.tsx +162 -160
- package/src/features/ResourceManager/components/Explorer/MasonryView/MasonryFileItem/index.tsx +16 -8
- package/src/features/ResourceManager/components/Explorer/ToolBar/ActionIconWithChevron.tsx +4 -3
- package/src/features/ResourceManager/components/Explorer/ToolBar/BatchActionsDropdown.tsx +6 -12
- package/src/features/ResourceManager/components/Explorer/ToolBar/SortDropdown.tsx +8 -8
- package/src/features/ResourceManager/components/Explorer/ToolBar/ViewSwitcher.tsx +8 -11
- package/src/features/ResourceManager/components/Tree/index.tsx +121 -122
- package/src/helpers/toolEngineering/index.ts +1 -1
- package/src/layout/GlobalProvider/index.tsx +5 -2
- package/src/locales/default/plugin.ts +6 -0
- package/src/server/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts +1 -1
- package/src/server/modules/Mecha/AgentToolsEngine/index.ts +1 -1
- package/src/store/chat/slices/builtinTool/actions/index.ts +1 -11
- package/src/store/tool/slices/builtin/executors/index.ts +4 -0
- package/src/styles/global.ts +6 -0
- package/src/styles/text.ts +1 -1
- package/src/tools/executionRuntimes.ts +3 -8
- package/src/tools/identifiers.ts +1 -1
- package/src/tools/index.ts +1 -1
- package/src/tools/inspectors.ts +5 -0
- package/src/tools/renders.ts +6 -12
- package/packages/builtin-tool-local-system/src/client/Render/RenameLocalFile/index.tsx +0 -37
- package/src/features/Conversation/components/ContextMenu.tsx +0 -418
- package/src/store/chat/slices/builtinTool/actions/__tests__/localSystem.test.ts +0 -201
- package/src/store/chat/slices/builtinTool/actions/knowledgeBase.ts +0 -163
- package/src/store/chat/slices/builtinTool/actions/localSystem.ts +0 -241
- package/src/tools/knowledge-base/ExecutionRuntime/index.ts +0 -25
- package/src/tools/knowledge-base/Render/ReadKnowledge/index.tsx +0 -29
- package/src/tools/knowledge-base/Render/SearchKnowledgeBase/index.tsx +0 -29
- package/src/tools/knowledge-base/Render/index.ts +0 -7
- package/src/tools/knowledge-base/index.ts +0 -12
- package/src/tools/local-system/ExecutionRuntime/index.ts +0 -9
- package/src/tools/local-system/systemRole.ts +0 -1
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import debug from 'debug';
|
|
2
|
-
import { type StateCreator } from 'zustand/vanilla';
|
|
3
|
-
|
|
4
|
-
import { agentSelectors } from '@/store/agent/selectors';
|
|
5
|
-
import { getAgentStoreState } from '@/store/agent/store';
|
|
6
|
-
import { type ChatStore } from '@/store/chat/store';
|
|
7
|
-
import { KnowledgeBaseExecutionRuntime } from '@/tools/knowledge-base/ExecutionRuntime';
|
|
8
|
-
|
|
9
|
-
const log = debug('lobe-store:builtin-tool:knowledge-base');
|
|
10
|
-
|
|
11
|
-
export interface KnowledgeBaseAction {
|
|
12
|
-
internal_triggerKnowledgeBaseToolCalling: (
|
|
13
|
-
id: string,
|
|
14
|
-
callingService: () => Promise<{ content: string; error?: any; state?: any; success: boolean }>,
|
|
15
|
-
) => Promise<boolean>;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Read full content of specific files from knowledge base
|
|
19
|
-
*/
|
|
20
|
-
readKnowledge: (
|
|
21
|
-
id: string,
|
|
22
|
-
params: {
|
|
23
|
-
fileIds: string[];
|
|
24
|
-
},
|
|
25
|
-
) => Promise<boolean>;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Search knowledge base for relevant files and chunks
|
|
29
|
-
*/
|
|
30
|
-
searchKnowledgeBase: (
|
|
31
|
-
id: string,
|
|
32
|
-
params: {
|
|
33
|
-
query: string;
|
|
34
|
-
topK?: number;
|
|
35
|
-
},
|
|
36
|
-
) => Promise<boolean>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const runtime = new KnowledgeBaseExecutionRuntime();
|
|
40
|
-
|
|
41
|
-
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
42
|
-
export const knowledgeBaseSlice: StateCreator<
|
|
43
|
-
ChatStore,
|
|
44
|
-
[['zustand/devtools', never]],
|
|
45
|
-
[],
|
|
46
|
-
KnowledgeBaseAction
|
|
47
|
-
> = (set, get) => ({
|
|
48
|
-
readKnowledge: async (id, params) => {
|
|
49
|
-
return get().internal_triggerKnowledgeBaseToolCalling(id, async () => {
|
|
50
|
-
return await runtime.readKnowledge(params);
|
|
51
|
-
});
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
searchKnowledgeBase: async (id, params) => {
|
|
55
|
-
// Get knowledge base IDs from agent store
|
|
56
|
-
const agentState = getAgentStoreState();
|
|
57
|
-
const knowledgeIds = agentSelectors.currentKnowledgeIds(agentState);
|
|
58
|
-
|
|
59
|
-
// Only search in knowledge bases, not agent files
|
|
60
|
-
// Agent files will be injected as full content in context-engine
|
|
61
|
-
const knowledgeBaseIds = knowledgeIds.knowledgeBaseIds;
|
|
62
|
-
|
|
63
|
-
return get().internal_triggerKnowledgeBaseToolCalling(id, async () => {
|
|
64
|
-
return await runtime.searchKnowledgeBase(params, {
|
|
65
|
-
knowledgeBaseIds,
|
|
66
|
-
messageId: id,
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
// ==================== utils ====================
|
|
72
|
-
|
|
73
|
-
internal_triggerKnowledgeBaseToolCalling: async (id, callingService) => {
|
|
74
|
-
// Get parent operationId from messageOperationMap (should be executeToolCall)
|
|
75
|
-
const parentOperationId = get().messageOperationMap[id];
|
|
76
|
-
|
|
77
|
-
// Create child operation for knowledge base execution
|
|
78
|
-
// Auto-associates message with this operation via messageId in context
|
|
79
|
-
const { operationId: knowledgeBaseOpId, abortController } = get().startOperation({
|
|
80
|
-
context: {
|
|
81
|
-
messageId: id,
|
|
82
|
-
},
|
|
83
|
-
metadata: {
|
|
84
|
-
startTime: Date.now(),
|
|
85
|
-
},
|
|
86
|
-
parentOperationId,
|
|
87
|
-
type: 'builtinToolKnowledgeBase',
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
log(
|
|
91
|
-
'[knowledgeBase] messageId=%s, parentOpId=%s, knowledgeBaseOpId=%s, aborted=%s',
|
|
92
|
-
id,
|
|
93
|
-
parentOperationId,
|
|
94
|
-
knowledgeBaseOpId,
|
|
95
|
-
abortController.signal.aborted,
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
const context = { operationId: knowledgeBaseOpId };
|
|
99
|
-
|
|
100
|
-
try {
|
|
101
|
-
const { state, content, success, error } = await callingService();
|
|
102
|
-
|
|
103
|
-
// Complete knowledge base operation
|
|
104
|
-
get().completeOperation(knowledgeBaseOpId);
|
|
105
|
-
|
|
106
|
-
if (success) {
|
|
107
|
-
if (state) {
|
|
108
|
-
await get().optimisticUpdatePluginState(id, state, context);
|
|
109
|
-
}
|
|
110
|
-
await get().optimisticUpdateMessageContent(id, content, undefined, context);
|
|
111
|
-
} else {
|
|
112
|
-
await get().optimisticUpdateMessagePluginError(
|
|
113
|
-
id,
|
|
114
|
-
{
|
|
115
|
-
body: error,
|
|
116
|
-
message: error?.message || 'Operation failed',
|
|
117
|
-
type: 'PluginServerError',
|
|
118
|
-
},
|
|
119
|
-
context,
|
|
120
|
-
);
|
|
121
|
-
// Still update content even if failed, to show error message
|
|
122
|
-
await get().optimisticUpdateMessageContent(id, content, undefined, context);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return true;
|
|
126
|
-
} catch (error) {
|
|
127
|
-
const err = error as Error;
|
|
128
|
-
|
|
129
|
-
log('[knowledgeBase] Error: messageId=%s, error=%s', id, err.message);
|
|
130
|
-
|
|
131
|
-
// Check if it's an abort error
|
|
132
|
-
if (err.message.includes('The user aborted a request.') || err.name === 'AbortError') {
|
|
133
|
-
log('[knowledgeBase] Request aborted: messageId=%s', id);
|
|
134
|
-
// Fail knowledge base operation for abort
|
|
135
|
-
get().failOperation(knowledgeBaseOpId, {
|
|
136
|
-
message: 'User cancelled the request',
|
|
137
|
-
type: 'UserAborted',
|
|
138
|
-
});
|
|
139
|
-
// Don't update error message for user aborts
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Fail knowledge base operation for other errors
|
|
144
|
-
get().failOperation(knowledgeBaseOpId, {
|
|
145
|
-
message: err.message,
|
|
146
|
-
type: 'PluginServerError',
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// For other errors, update message
|
|
150
|
-
await get().optimisticUpdateMessagePluginError(
|
|
151
|
-
id,
|
|
152
|
-
{
|
|
153
|
-
body: error,
|
|
154
|
-
message: err.message,
|
|
155
|
-
type: 'PluginServerError',
|
|
156
|
-
},
|
|
157
|
-
context,
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
});
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type EditLocalFileParams,
|
|
3
|
-
type GetCommandOutputParams,
|
|
4
|
-
type GlobFilesParams,
|
|
5
|
-
type GrepContentParams,
|
|
6
|
-
type KillCommandParams,
|
|
7
|
-
type ListLocalFileParams,
|
|
8
|
-
type LocalReadFileParams,
|
|
9
|
-
type LocalReadFilesParams,
|
|
10
|
-
type LocalSearchFilesParams,
|
|
11
|
-
type MoveLocalFilesParams,
|
|
12
|
-
type RenameLocalFileParams,
|
|
13
|
-
type RunCommandParams,
|
|
14
|
-
type WriteLocalFileParams,
|
|
15
|
-
} from '@lobechat/electron-client-ipc';
|
|
16
|
-
import debug from 'debug';
|
|
17
|
-
import { type StateCreator } from 'zustand/vanilla';
|
|
18
|
-
|
|
19
|
-
import { type ChatStore } from '@/store/chat/store';
|
|
20
|
-
import { LocalSystemExecutionRuntime } from '@/tools/local-system/ExecutionRuntime';
|
|
21
|
-
|
|
22
|
-
const log = debug('lobe-store:builtin-tool');
|
|
23
|
-
|
|
24
|
-
/* eslint-disable typescript-sort-keys/interface */
|
|
25
|
-
export interface LocalFileAction {
|
|
26
|
-
internal_triggerLocalFileToolCalling: (
|
|
27
|
-
id: string,
|
|
28
|
-
callingService: () => Promise<{ content: string; error?: any; state?: any; success: boolean }>,
|
|
29
|
-
) => Promise<boolean>;
|
|
30
|
-
|
|
31
|
-
// File Operations
|
|
32
|
-
listLocalFiles: (id: string, params: ListLocalFileParams) => Promise<boolean>;
|
|
33
|
-
moveLocalFiles: (id: string, params: MoveLocalFilesParams) => Promise<boolean>;
|
|
34
|
-
readLocalFile: (id: string, params: LocalReadFileParams) => Promise<boolean>;
|
|
35
|
-
readLocalFiles: (id: string, params: LocalReadFilesParams) => Promise<boolean>;
|
|
36
|
-
renameLocalFile: (id: string, params: RenameLocalFileParams) => Promise<boolean>;
|
|
37
|
-
reSearchLocalFiles: (id: string, params: LocalSearchFilesParams) => Promise<boolean>;
|
|
38
|
-
searchLocalFiles: (id: string, params: LocalSearchFilesParams) => Promise<boolean>;
|
|
39
|
-
writeLocalFile: (id: string, params: WriteLocalFileParams) => Promise<boolean>;
|
|
40
|
-
|
|
41
|
-
// Shell Commands
|
|
42
|
-
editLocalFile: (id: string, params: EditLocalFileParams) => Promise<boolean>;
|
|
43
|
-
getCommandOutput: (id: string, params: GetCommandOutputParams) => Promise<boolean>;
|
|
44
|
-
killCommand: (id: string, params: KillCommandParams) => Promise<boolean>;
|
|
45
|
-
runCommand: (id: string, params: RunCommandParams) => Promise<boolean>;
|
|
46
|
-
|
|
47
|
-
// Search & Find
|
|
48
|
-
globLocalFiles: (id: string, params: GlobFilesParams) => Promise<boolean>;
|
|
49
|
-
grepContent: (id: string, params: GrepContentParams) => Promise<boolean>;
|
|
50
|
-
}
|
|
51
|
-
/* eslint-enable typescript-sort-keys/interface */
|
|
52
|
-
|
|
53
|
-
const runtime = new LocalSystemExecutionRuntime();
|
|
54
|
-
|
|
55
|
-
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
56
|
-
export const localSystemSlice: StateCreator<
|
|
57
|
-
ChatStore,
|
|
58
|
-
[['zustand/devtools', never]],
|
|
59
|
-
[],
|
|
60
|
-
LocalFileAction
|
|
61
|
-
> = (set, get) => ({
|
|
62
|
-
// ==================== File Editing ====================
|
|
63
|
-
editLocalFile: async (id, params) => {
|
|
64
|
-
return get().internal_triggerLocalFileToolCalling(id, async () => {
|
|
65
|
-
return await runtime.editLocalFile(params);
|
|
66
|
-
});
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
writeLocalFile: async (id, params) => {
|
|
70
|
-
return get().internal_triggerLocalFileToolCalling(id, async () => {
|
|
71
|
-
return await runtime.writeLocalFile(params);
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
moveLocalFiles: async (id, params) => {
|
|
75
|
-
return get().internal_triggerLocalFileToolCalling(id, async () => {
|
|
76
|
-
return await runtime.moveLocalFiles(params);
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
renameLocalFile: async (id, params) => {
|
|
80
|
-
return get().internal_triggerLocalFileToolCalling(id, async () => {
|
|
81
|
-
return await runtime.renameLocalFile(params);
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
// ==================== Search & Find ====================
|
|
86
|
-
grepContent: async (id, params) => {
|
|
87
|
-
return get().internal_triggerLocalFileToolCalling(id, async () => {
|
|
88
|
-
return await runtime.grepContent(params);
|
|
89
|
-
});
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
globLocalFiles: async (id, params) => {
|
|
93
|
-
return get().internal_triggerLocalFileToolCalling(id, async () => {
|
|
94
|
-
return await runtime.globLocalFiles(params);
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
searchLocalFiles: async (id, params) => {
|
|
99
|
-
return get().internal_triggerLocalFileToolCalling(id, async () => {
|
|
100
|
-
return await runtime.searchLocalFiles(params);
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
listLocalFiles: async (id, params) => {
|
|
105
|
-
return get().internal_triggerLocalFileToolCalling(id, async () => {
|
|
106
|
-
return await runtime.listLocalFiles(params);
|
|
107
|
-
});
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
reSearchLocalFiles: async (id, params) => {
|
|
111
|
-
// Get operationId from messageOperationMap to ensure proper context isolation
|
|
112
|
-
const operationId = get().messageOperationMap[id];
|
|
113
|
-
const context = operationId ? { operationId } : undefined;
|
|
114
|
-
|
|
115
|
-
await get().optimisticUpdatePluginArguments(id, params, false, context);
|
|
116
|
-
|
|
117
|
-
return get().searchLocalFiles(id, params);
|
|
118
|
-
},
|
|
119
|
-
|
|
120
|
-
readLocalFile: async (id, params) => {
|
|
121
|
-
return get().internal_triggerLocalFileToolCalling(id, async () => {
|
|
122
|
-
return await runtime.readLocalFile(params);
|
|
123
|
-
});
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
readLocalFiles: async (id, params) => {
|
|
127
|
-
return get().internal_triggerLocalFileToolCalling(id, async () => {
|
|
128
|
-
return await runtime.readLocalFiles(params);
|
|
129
|
-
});
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
// ==================== Shell Commands ====================
|
|
133
|
-
runCommand: async (id, params) => {
|
|
134
|
-
return get().internal_triggerLocalFileToolCalling(id, async () => {
|
|
135
|
-
return await runtime.runCommand(params);
|
|
136
|
-
});
|
|
137
|
-
},
|
|
138
|
-
killCommand: async (id, params) => {
|
|
139
|
-
return get().internal_triggerLocalFileToolCalling(id, async () => {
|
|
140
|
-
return await runtime.killCommand(params);
|
|
141
|
-
});
|
|
142
|
-
},
|
|
143
|
-
getCommandOutput: async (id, params) => {
|
|
144
|
-
return get().internal_triggerLocalFileToolCalling(id, async () => {
|
|
145
|
-
return await runtime.getCommandOutput(params);
|
|
146
|
-
});
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
// ==================== utils ====================
|
|
150
|
-
|
|
151
|
-
internal_triggerLocalFileToolCalling: async (id, callingService) => {
|
|
152
|
-
// Get parent operationId from messageOperationMap (should be executeToolCall)
|
|
153
|
-
const parentOperationId = get().messageOperationMap[id];
|
|
154
|
-
|
|
155
|
-
// Create child operation for local system execution
|
|
156
|
-
// Auto-associates message with this operation via messageId in context
|
|
157
|
-
const { operationId: localSystemOpId, abortController } = get().startOperation({
|
|
158
|
-
type: 'builtinToolLocalSystem',
|
|
159
|
-
context: {
|
|
160
|
-
messageId: id,
|
|
161
|
-
},
|
|
162
|
-
parentOperationId,
|
|
163
|
-
metadata: {
|
|
164
|
-
startTime: Date.now(),
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
log(
|
|
169
|
-
'[localSystem] messageId=%s, parentOpId=%s, localSystemOpId=%s, aborted=%s',
|
|
170
|
-
id,
|
|
171
|
-
parentOperationId,
|
|
172
|
-
localSystemOpId,
|
|
173
|
-
abortController.signal.aborted,
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
const context = { operationId: localSystemOpId };
|
|
177
|
-
|
|
178
|
-
try {
|
|
179
|
-
const { state, content, success, error } = await callingService();
|
|
180
|
-
|
|
181
|
-
// Complete local system operation
|
|
182
|
-
get().completeOperation(localSystemOpId);
|
|
183
|
-
|
|
184
|
-
if (success) {
|
|
185
|
-
if (state) {
|
|
186
|
-
await get().optimisticUpdatePluginState(id, state, context);
|
|
187
|
-
}
|
|
188
|
-
await get().optimisticUpdateMessageContent(id, content, undefined, context);
|
|
189
|
-
} else {
|
|
190
|
-
await get().optimisticUpdateMessagePluginError(
|
|
191
|
-
id,
|
|
192
|
-
{
|
|
193
|
-
body: error,
|
|
194
|
-
message: error?.message || 'Operation failed',
|
|
195
|
-
type: 'PluginServerError',
|
|
196
|
-
},
|
|
197
|
-
context,
|
|
198
|
-
);
|
|
199
|
-
// Still update content even if failed, to show error message
|
|
200
|
-
await get().optimisticUpdateMessageContent(id, content, undefined, context);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return true;
|
|
204
|
-
} catch (error) {
|
|
205
|
-
const err = error as Error;
|
|
206
|
-
|
|
207
|
-
log('[localSystem] Error: messageId=%s, error=%s', id, err.message);
|
|
208
|
-
|
|
209
|
-
// Check if it's an abort error
|
|
210
|
-
if (err.message.includes('The user aborted a request.') || err.name === 'AbortError') {
|
|
211
|
-
log('[localSystem] Request aborted: messageId=%s', id);
|
|
212
|
-
// Fail local system operation for abort
|
|
213
|
-
get().failOperation(localSystemOpId, {
|
|
214
|
-
message: 'User cancelled the request',
|
|
215
|
-
type: 'UserAborted',
|
|
216
|
-
});
|
|
217
|
-
// Don't update error message for user aborts
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Fail local system operation for other errors
|
|
222
|
-
get().failOperation(localSystemOpId, {
|
|
223
|
-
message: err.message,
|
|
224
|
-
type: 'PluginServerError',
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
// For other errors, update message
|
|
228
|
-
await get().optimisticUpdateMessagePluginError(
|
|
229
|
-
id,
|
|
230
|
-
{
|
|
231
|
-
body: error,
|
|
232
|
-
message: err.message,
|
|
233
|
-
type: 'PluginServerError',
|
|
234
|
-
},
|
|
235
|
-
context,
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
},
|
|
241
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { KnowledgeBaseExecutionRuntime as BaseKnowledgeBaseExecutionRuntime } from '@lobechat/builtin-tool-knowledge-base/executionRuntime';
|
|
2
|
-
import type { ReadKnowledgeArgs, SearchKnowledgeBaseArgs } from '@lobechat/builtin-tool-knowledge-base';
|
|
3
|
-
|
|
4
|
-
import { ragService } from '@/services/rag';
|
|
5
|
-
|
|
6
|
-
// Create a factory that returns an instance with ragService injected
|
|
7
|
-
export class KnowledgeBaseExecutionRuntime extends BaseKnowledgeBaseExecutionRuntime {
|
|
8
|
-
constructor() {
|
|
9
|
-
super(ragService);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
searchKnowledgeBase(
|
|
13
|
-
args: SearchKnowledgeBaseArgs,
|
|
14
|
-
options?: Parameters<BaseKnowledgeBaseExecutionRuntime['searchKnowledgeBase']>[1],
|
|
15
|
-
) {
|
|
16
|
-
return super.searchKnowledgeBase(args, options);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
readKnowledge(args: ReadKnowledgeArgs, options?: Parameters<BaseKnowledgeBaseExecutionRuntime['readKnowledge']>[1]) {
|
|
20
|
-
return super.readKnowledge(args, options);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Re-export types for convenience
|
|
25
|
-
export type { ReadKnowledgeArgs, SearchKnowledgeBaseArgs } from '@lobechat/builtin-tool-knowledge-base';
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { ReadKnowledge as BaseReadKnowledge } from '@lobechat/builtin-tool-knowledge-base/client';
|
|
4
|
-
import { type BuiltinRenderProps } from '@lobechat/types';
|
|
5
|
-
import { memo } from 'react';
|
|
6
|
-
import { useTranslation } from 'react-i18next';
|
|
7
|
-
|
|
8
|
-
import FileIcon from '@/components/FileIcon';
|
|
9
|
-
|
|
10
|
-
import type { ReadKnowledgeArgs, ReadKnowledgeState } from '../../index';
|
|
11
|
-
|
|
12
|
-
const ReadKnowledge = memo<BuiltinRenderProps<ReadKnowledgeArgs, ReadKnowledgeState>>(
|
|
13
|
-
({ pluginState }) => {
|
|
14
|
-
const { t } = useTranslation('tool');
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<BaseReadKnowledge
|
|
18
|
-
FileIcon={FileIcon}
|
|
19
|
-
labels={{
|
|
20
|
-
chars: t('lobe-knowledge-base.readKnowledge.meta.chars'),
|
|
21
|
-
lines: t('lobe-knowledge-base.readKnowledge.meta.lines'),
|
|
22
|
-
}}
|
|
23
|
-
pluginState={pluginState}
|
|
24
|
-
/>
|
|
25
|
-
);
|
|
26
|
-
},
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
export default ReadKnowledge;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { SearchKnowledgeBase as BaseSearchKnowledgeBase } from '@lobechat/builtin-tool-knowledge-base/client';
|
|
4
|
-
import { type BuiltinRenderProps } from '@lobechat/types';
|
|
5
|
-
import { memo } from 'react';
|
|
6
|
-
|
|
7
|
-
import FileIcon from '@/components/FileIcon';
|
|
8
|
-
import { useIsMobile } from '@/hooks/useIsMobile';
|
|
9
|
-
import { useChatStore } from '@/store/chat';
|
|
10
|
-
|
|
11
|
-
import type { SearchKnowledgeBaseArgs, SearchKnowledgeBaseState } from '../../index';
|
|
12
|
-
|
|
13
|
-
const SearchKnowledgeBase = memo<
|
|
14
|
-
BuiltinRenderProps<SearchKnowledgeBaseArgs, SearchKnowledgeBaseState>
|
|
15
|
-
>(({ pluginState }) => {
|
|
16
|
-
const openFilePreview = useChatStore((s) => s.openFilePreview);
|
|
17
|
-
const isMobile = useIsMobile();
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<BaseSearchKnowledgeBase
|
|
21
|
-
FileIcon={FileIcon}
|
|
22
|
-
isMobile={isMobile}
|
|
23
|
-
onFileClick={openFilePreview}
|
|
24
|
-
pluginState={pluginState}
|
|
25
|
-
/>
|
|
26
|
-
);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
export default SearchKnowledgeBase;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// Re-export from the package for backward compatibility
|
|
2
|
-
export {
|
|
3
|
-
type FileContentDetail,
|
|
4
|
-
KnowledgeBaseApiName,
|
|
5
|
-
KnowledgeBaseIdentifier,
|
|
6
|
-
KnowledgeBaseManifest,
|
|
7
|
-
type ReadKnowledgeArgs,
|
|
8
|
-
type ReadKnowledgeState,
|
|
9
|
-
type SearchKnowledgeBaseArgs,
|
|
10
|
-
type SearchKnowledgeBaseState,
|
|
11
|
-
systemPrompt,
|
|
12
|
-
} from '@lobechat/builtin-tool-knowledge-base';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { LocalSystemExecutionRuntime as BaseLocalSystemExecutionRuntime } from '@lobechat/builtin-tool-local-system/executionRuntime';
|
|
2
|
-
|
|
3
|
-
import { localFileService } from '@/services/electron/localFileService';
|
|
4
|
-
|
|
5
|
-
export class LocalSystemExecutionRuntime extends BaseLocalSystemExecutionRuntime {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(localFileService);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { systemPrompt } from '@lobechat/builtin-tool-local-system';
|