@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
package/packages/builtin-tool-knowledge-base/src/client/Inspector/SearchKnowledgeBase/index.tsx
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type BuiltinInspectorProps } from '@lobechat/types';
|
|
4
|
+
import { Text } from '@lobehub/ui';
|
|
5
|
+
import { createStaticStyles, cssVar, cx } from 'antd-style';
|
|
6
|
+
import { memo } from 'react';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
|
|
9
|
+
import { highlightTextStyles, shinyTextStyles } from '@/styles';
|
|
10
|
+
|
|
11
|
+
import { type SearchKnowledgeBaseArgs, type SearchKnowledgeBaseState } from '../../..';
|
|
12
|
+
|
|
13
|
+
const styles = createStaticStyles(({ css, cssVar }) => ({
|
|
14
|
+
root: css`
|
|
15
|
+
overflow: hidden;
|
|
16
|
+
display: -webkit-box;
|
|
17
|
+
-webkit-box-orient: vertical;
|
|
18
|
+
-webkit-line-clamp: 1;
|
|
19
|
+
|
|
20
|
+
color: ${cssVar.colorTextSecondary};
|
|
21
|
+
`,
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
export const SearchKnowledgeBaseInspector = memo<
|
|
25
|
+
BuiltinInspectorProps<SearchKnowledgeBaseArgs, SearchKnowledgeBaseState>
|
|
26
|
+
>(({ args, partialArgs, isArgumentsStreaming, isLoading, pluginState }) => {
|
|
27
|
+
const { t } = useTranslation('plugin');
|
|
28
|
+
|
|
29
|
+
const query = args?.query || partialArgs?.query || '';
|
|
30
|
+
// Use fileResults length for display (aggregated by file)
|
|
31
|
+
const resultCount = pluginState?.fileResults?.length ?? 0;
|
|
32
|
+
const hasResults = resultCount > 0;
|
|
33
|
+
|
|
34
|
+
// During argument streaming
|
|
35
|
+
if (isArgumentsStreaming) {
|
|
36
|
+
if (!query)
|
|
37
|
+
return (
|
|
38
|
+
<div className={cx(styles.root, shinyTextStyles.shinyText)}>
|
|
39
|
+
<span>{t('builtins.lobe-knowledge-base.apiName.searchKnowledgeBase')}</span>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div className={cx(styles.root, shinyTextStyles.shinyText)}>
|
|
45
|
+
<span>{t('builtins.lobe-knowledge-base.apiName.searchKnowledgeBase')}: </span>
|
|
46
|
+
<span className={highlightTextStyles.gold}>{query}</span>
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div className={cx(styles.root, isLoading && shinyTextStyles.shinyText)}>
|
|
53
|
+
<span style={{ marginInlineStart: 2 }}>
|
|
54
|
+
<span>{t('builtins.lobe-knowledge-base.apiName.searchKnowledgeBase')}: </span>
|
|
55
|
+
{query && <span className={highlightTextStyles.gold}>{query}</span>}
|
|
56
|
+
{!isLoading &&
|
|
57
|
+
pluginState?.fileResults &&
|
|
58
|
+
(hasResults ? (
|
|
59
|
+
<span style={{ marginInlineStart: 4 }}>({resultCount})</span>
|
|
60
|
+
) : (
|
|
61
|
+
<Text
|
|
62
|
+
as={'span'}
|
|
63
|
+
color={cssVar.colorTextDescription}
|
|
64
|
+
fontSize={12}
|
|
65
|
+
style={{ marginInlineStart: 4 }}
|
|
66
|
+
>
|
|
67
|
+
({t('builtins.lobe-knowledge-base.inspector.noResults')})
|
|
68
|
+
</Text>
|
|
69
|
+
))}
|
|
70
|
+
</span>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
SearchKnowledgeBaseInspector.displayName = 'SearchKnowledgeBaseInspector';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { KnowledgeBaseApiName } from '../../types';
|
|
2
|
+
import { ReadKnowledgeInspector } from './ReadKnowledge';
|
|
3
|
+
import { SearchKnowledgeBaseInspector } from './SearchKnowledgeBase';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Knowledge Base Inspector Components Registry
|
|
7
|
+
*/
|
|
8
|
+
export const KnowledgeBaseInspectors = {
|
|
9
|
+
[KnowledgeBaseApiName.readKnowledge]: ReadKnowledgeInspector,
|
|
10
|
+
[KnowledgeBaseApiName.searchKnowledgeBase]: SearchKnowledgeBaseInspector,
|
|
11
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { Alert, Flexbox, Text } from '@lobehub/ui';
|
|
3
|
+
import { Alert, Flexbox, MaterialFileTypeIcon, Text } from '@lobehub/ui';
|
|
4
4
|
import { Descriptions } from 'antd';
|
|
5
5
|
import { createStaticStyles } from 'antd-style';
|
|
6
|
-
import {
|
|
6
|
+
import { memo } from 'react';
|
|
7
7
|
|
|
8
8
|
import { FileContentDetail } from '../../../types';
|
|
9
9
|
|
|
@@ -63,21 +63,21 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
|
|
|
63
63
|
}));
|
|
64
64
|
|
|
65
65
|
interface FileCardProps {
|
|
66
|
-
FileIcon: ComponentType<{ fileName: string; size: number }>;
|
|
67
66
|
file: FileContentDetail;
|
|
68
|
-
labels: {
|
|
69
|
-
chars: string;
|
|
70
|
-
lines: string;
|
|
71
|
-
};
|
|
72
67
|
}
|
|
73
68
|
|
|
74
|
-
const FileCard = memo<FileCardProps>(({ file
|
|
69
|
+
const FileCard = memo<FileCardProps>(({ file }) => {
|
|
75
70
|
if (file.error) {
|
|
76
71
|
return (
|
|
77
72
|
<Flexbox className={styles.container} gap={8}>
|
|
78
73
|
<Flexbox className={styles.cardBody} gap={8}>
|
|
79
74
|
<Flexbox align={'center'} className={styles.titleRow} gap={8} horizontal>
|
|
80
|
-
<
|
|
75
|
+
<MaterialFileTypeIcon
|
|
76
|
+
filename={file.filename}
|
|
77
|
+
size={16}
|
|
78
|
+
type={'file'}
|
|
79
|
+
variant={'raw'}
|
|
80
|
+
/>
|
|
81
81
|
<div className={styles.title}>{file.filename}</div>
|
|
82
82
|
</Flexbox>
|
|
83
83
|
</Flexbox>
|
|
@@ -92,7 +92,7 @@ const FileCard = memo<FileCardProps>(({ file, FileIcon, labels }) => {
|
|
|
92
92
|
<Flexbox className={styles.container} justify={'space-between'}>
|
|
93
93
|
<Flexbox className={styles.cardBody} gap={8}>
|
|
94
94
|
<Flexbox align={'center'} className={styles.titleRow} gap={8} horizontal>
|
|
95
|
-
<
|
|
95
|
+
<MaterialFileTypeIcon filename={file.filename} size={16} type={'file'} variant={'raw'} />
|
|
96
96
|
<div className={styles.title}>{file.filename}</div>
|
|
97
97
|
</Flexbox>
|
|
98
98
|
{file.preview && (
|
|
@@ -118,11 +118,11 @@ const FileCard = memo<FileCardProps>(({ file, FileIcon, labels }) => {
|
|
|
118
118
|
items={[
|
|
119
119
|
{
|
|
120
120
|
children: file.totalCharCount?.toLocaleString(),
|
|
121
|
-
label:
|
|
121
|
+
label: 'Chars',
|
|
122
122
|
},
|
|
123
123
|
{
|
|
124
124
|
children: file.totalLineCount?.toLocaleString(),
|
|
125
|
-
label:
|
|
125
|
+
label: 'Lines',
|
|
126
126
|
},
|
|
127
127
|
]}
|
|
128
128
|
size="small"
|
|
@@ -2,36 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
import { BuiltinRenderProps } from '@lobechat/types';
|
|
4
4
|
import { Flexbox } from '@lobehub/ui';
|
|
5
|
-
import {
|
|
5
|
+
import { memo } from 'react';
|
|
6
6
|
|
|
7
7
|
import { ReadKnowledgeArgs, ReadKnowledgeState } from '../../../types';
|
|
8
8
|
import FileCard from './FileCard';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
> {
|
|
14
|
-
FileIcon: ComponentType<{ fileName: string; size: number }>;
|
|
15
|
-
labels: {
|
|
16
|
-
chars: string;
|
|
17
|
-
lines: string;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
10
|
+
const ReadKnowledge = memo<BuiltinRenderProps<ReadKnowledgeArgs, ReadKnowledgeState>>(
|
|
11
|
+
({ pluginState }) => {
|
|
12
|
+
const { files } = pluginState || {};
|
|
20
13
|
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
if (!files || files.length === 0) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
23
17
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
</Flexbox>
|
|
34
|
-
);
|
|
35
|
-
});
|
|
18
|
+
return (
|
|
19
|
+
<Flexbox gap={12} horizontal style={{ flexWrap: 'wrap' }}>
|
|
20
|
+
{files.map((file) => (
|
|
21
|
+
<FileCard file={file} key={file.fileId} />
|
|
22
|
+
))}
|
|
23
|
+
</Flexbox>
|
|
24
|
+
);
|
|
25
|
+
},
|
|
26
|
+
);
|
|
36
27
|
|
|
37
28
|
export default ReadKnowledge;
|
package/packages/builtin-tool-knowledge-base/src/client/Render/SearchKnowledgeBase/Item/index.tsx
CHANGED
|
@@ -1,62 +1,36 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { FileSearchResult } from '@lobechat/types';
|
|
4
|
-
import { Center, Flexbox, Text, Tooltip } from '@lobehub/ui';
|
|
4
|
+
import { Center, Flexbox, MaterialFileTypeIcon, Text, Tooltip } from '@lobehub/ui';
|
|
5
5
|
import { cx, useThemeMode } from 'antd-style';
|
|
6
|
-
import {
|
|
6
|
+
import { memo } from 'react';
|
|
7
7
|
|
|
8
8
|
import { styles } from './style';
|
|
9
9
|
|
|
10
10
|
export interface FileItemProps extends FileSearchResult {
|
|
11
|
-
FileIcon: ComponentType<{
|
|
12
|
-
fileName: string;
|
|
13
|
-
size: number;
|
|
14
|
-
variant?: 'raw' | 'file' | 'folder';
|
|
15
|
-
}>;
|
|
16
11
|
index: number;
|
|
17
|
-
isMobile?: boolean;
|
|
18
|
-
onFileClick?: (params: { chunkId: string; chunkText: string; fileId: string }) => void;
|
|
19
12
|
}
|
|
20
13
|
|
|
21
|
-
const FileItem = memo<FileItemProps>(
|
|
22
|
-
|
|
23
|
-
const { isDarkMode } = useThemeMode();
|
|
14
|
+
const FileItem = memo<FileItemProps>(({ fileId, fileName, relevanceScore }) => {
|
|
15
|
+
const { isDarkMode } = useThemeMode();
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
onClick={(e) => {
|
|
40
|
-
e.stopPropagation();
|
|
41
|
-
if (firstChunk && onFileClick) {
|
|
42
|
-
onFileClick({
|
|
43
|
-
chunkId: firstChunk.id,
|
|
44
|
-
chunkText: firstChunk.text,
|
|
45
|
-
fileId,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}}
|
|
49
|
-
>
|
|
50
|
-
<FileIcon fileName={fileName} size={20} variant={'raw'} />
|
|
51
|
-
<Flexbox gap={12} horizontal justify={'space-between'} style={{ maxWidth: 200 }}>
|
|
52
|
-
<Text ellipsis>{fileName}</Text>
|
|
53
|
-
<Tooltip title={`Relevance: ${(relevanceScore * 100).toFixed(1)}%`}>
|
|
54
|
-
<Center className={styles.badge}>{relevanceScore.toFixed(2)}</Center>
|
|
55
|
-
</Tooltip>
|
|
56
|
-
</Flexbox>
|
|
17
|
+
return (
|
|
18
|
+
<Flexbox
|
|
19
|
+
align={'center'}
|
|
20
|
+
className={cx(styles.container, isDarkMode ? styles.containerDark : styles.containerLight)}
|
|
21
|
+
gap={4}
|
|
22
|
+
horizontal
|
|
23
|
+
key={fileId}
|
|
24
|
+
>
|
|
25
|
+
<MaterialFileTypeIcon filename={fileName} size={20} type={'file'} variant={'raw'} />
|
|
26
|
+
<Flexbox gap={12} horizontal justify={'space-between'} style={{ maxWidth: 200 }}>
|
|
27
|
+
<Text ellipsis>{fileName}</Text>
|
|
28
|
+
<Tooltip title={`Relevance: ${(relevanceScore * 100).toFixed(1)}%`}>
|
|
29
|
+
<Center className={styles.badge}>{relevanceScore.toFixed(2)}</Center>
|
|
30
|
+
</Tooltip>
|
|
57
31
|
</Flexbox>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
);
|
|
32
|
+
</Flexbox>
|
|
33
|
+
);
|
|
34
|
+
});
|
|
61
35
|
|
|
62
36
|
export default FileItem;
|
package/packages/builtin-tool-knowledge-base/src/client/Render/SearchKnowledgeBase/index.tsx
CHANGED
|
@@ -1,42 +1,30 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { BuiltinRenderProps } from '@lobechat/types';
|
|
4
|
-
import { Flexbox } from '@lobehub/ui';
|
|
5
|
-
import {
|
|
4
|
+
import { Empty, Flexbox } from '@lobehub/ui';
|
|
5
|
+
import { memo } from 'react';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
6
7
|
|
|
7
8
|
import { SearchKnowledgeBaseArgs, SearchKnowledgeBaseState } from '../../../types';
|
|
8
9
|
import FileItem from './Item';
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
BuiltinRenderProps<SearchKnowledgeBaseArgs, SearchKnowledgeBaseState
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
isMobile?: boolean;
|
|
16
|
-
onFileClick?: (params: { chunkId: string; chunkText: string; fileId: string }) => void;
|
|
17
|
-
}
|
|
11
|
+
const SearchKnowledgeBase = memo<
|
|
12
|
+
BuiltinRenderProps<SearchKnowledgeBaseArgs, SearchKnowledgeBaseState>
|
|
13
|
+
>(({ pluginState }) => {
|
|
14
|
+
const { t } = useTranslation('plugin');
|
|
15
|
+
const { fileResults } = pluginState || {};
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
if (!fileResults || fileResults.length === 0) {
|
|
18
|
+
return <Empty description={t('builtins.lobe-knowledge-base.inspector.noResults')} />;
|
|
19
|
+
}
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
key={file.fileId}
|
|
32
|
-
onFileClick={onFileClick}
|
|
33
|
-
{...file}
|
|
34
|
-
/>
|
|
35
|
-
);
|
|
36
|
-
})}
|
|
37
|
-
</Flexbox>
|
|
38
|
-
);
|
|
39
|
-
},
|
|
40
|
-
);
|
|
21
|
+
return (
|
|
22
|
+
<Flexbox gap={8} horizontal wrap={'wrap'}>
|
|
23
|
+
{fileResults.map((file, index) => {
|
|
24
|
+
return <FileItem index={index} key={file.fileId} {...file} />;
|
|
25
|
+
})}
|
|
26
|
+
</Flexbox>
|
|
27
|
+
);
|
|
28
|
+
});
|
|
41
29
|
|
|
42
30
|
export default SearchKnowledgeBase;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// Inspector components (customized tool call headers)
|
|
2
|
+
export { KnowledgeBaseInspectors } from './Inspector';
|
|
3
|
+
|
|
4
|
+
// Render components (read-only snapshots)
|
|
5
|
+
export { KnowledgeBaseRenders } from './Render';
|
|
2
6
|
|
|
3
7
|
// Re-export types and manifest for convenience
|
|
4
8
|
export { KnowledgeBaseManifest } from '../manifest';
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { formatSearchResults, promptFileContents, promptNoSearchResults } from '@lobechat/prompts';
|
|
2
|
+
import { BaseExecutor, type BuiltinToolContext, type BuiltinToolResult } from '@lobechat/types';
|
|
3
|
+
|
|
4
|
+
import { ragService } from '@/services/rag';
|
|
5
|
+
import { agentSelectors } from '@/store/agent/selectors';
|
|
6
|
+
import { getAgentStoreState } from '@/store/agent/store';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
type FileContentDetail,
|
|
10
|
+
KnowledgeBaseIdentifier,
|
|
11
|
+
type ReadKnowledgeArgs,
|
|
12
|
+
type ReadKnowledgeState,
|
|
13
|
+
type SearchKnowledgeBaseArgs,
|
|
14
|
+
type SearchKnowledgeBaseState,
|
|
15
|
+
} from '../types';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Knowledge Base Tool Executor
|
|
19
|
+
*
|
|
20
|
+
* Handles knowledge base search and retrieval operations.
|
|
21
|
+
*/
|
|
22
|
+
class KnowledgeBaseExecutor extends BaseExecutor<{
|
|
23
|
+
readKnowledge: 'readKnowledge';
|
|
24
|
+
searchKnowledgeBase: 'searchKnowledgeBase';
|
|
25
|
+
}> {
|
|
26
|
+
readonly identifier = KnowledgeBaseIdentifier;
|
|
27
|
+
protected readonly apiEnum = {
|
|
28
|
+
readKnowledge: 'readKnowledge' as const,
|
|
29
|
+
searchKnowledgeBase: 'searchKnowledgeBase' as const,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Search knowledge base and return file summaries with relevant chunks
|
|
34
|
+
*/
|
|
35
|
+
searchKnowledgeBase = async (
|
|
36
|
+
params: SearchKnowledgeBaseArgs,
|
|
37
|
+
ctx: BuiltinToolContext,
|
|
38
|
+
): Promise<BuiltinToolResult> => {
|
|
39
|
+
try {
|
|
40
|
+
const { query, topK = 20 } = params;
|
|
41
|
+
|
|
42
|
+
// Get knowledge base IDs from agent store
|
|
43
|
+
const agentState = getAgentStoreState();
|
|
44
|
+
const knowledgeIds = agentSelectors.currentKnowledgeIds(agentState);
|
|
45
|
+
|
|
46
|
+
// Only search in knowledge bases, not agent files
|
|
47
|
+
// Agent files will be injected as full content in context-engine
|
|
48
|
+
const knowledgeBaseIds = knowledgeIds.knowledgeBaseIds;
|
|
49
|
+
|
|
50
|
+
const { chunks, fileResults } = await ragService.semanticSearchForChat(
|
|
51
|
+
{ knowledgeIds: knowledgeBaseIds, query, topK },
|
|
52
|
+
ctx.signal,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
if (chunks.length === 0) {
|
|
56
|
+
const state: SearchKnowledgeBaseState = { chunks: [], fileResults: [], totalResults: 0 };
|
|
57
|
+
|
|
58
|
+
return { content: promptNoSearchResults(query), state, success: true };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Format search results for AI
|
|
62
|
+
const formattedContent = formatSearchResults(fileResults, query);
|
|
63
|
+
|
|
64
|
+
const state: SearchKnowledgeBaseState = { chunks, fileResults, totalResults: chunks.length };
|
|
65
|
+
|
|
66
|
+
return { content: formattedContent, state, success: true };
|
|
67
|
+
} catch (e) {
|
|
68
|
+
return {
|
|
69
|
+
content: `Error searching knowledge base: ${(e as Error).message}`,
|
|
70
|
+
error: { body: e, message: (e as Error).message, type: 'PluginServerError' },
|
|
71
|
+
success: false,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Read full content of specific files from knowledge base
|
|
78
|
+
*/
|
|
79
|
+
readKnowledge = async (params: ReadKnowledgeArgs): Promise<BuiltinToolResult> => {
|
|
80
|
+
try {
|
|
81
|
+
const { fileIds } = params;
|
|
82
|
+
|
|
83
|
+
if (!fileIds || fileIds.length === 0) {
|
|
84
|
+
return {
|
|
85
|
+
content: 'Error: No file IDs provided',
|
|
86
|
+
success: false,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const fileContents = await ragService.getFileContents(fileIds);
|
|
91
|
+
|
|
92
|
+
const formattedContent = promptFileContents(fileContents);
|
|
93
|
+
|
|
94
|
+
const state: ReadKnowledgeState = {
|
|
95
|
+
files: fileContents.map(
|
|
96
|
+
(file): FileContentDetail => ({
|
|
97
|
+
error: file.error,
|
|
98
|
+
fileId: file.fileId,
|
|
99
|
+
filename: file.filename,
|
|
100
|
+
preview: file.preview,
|
|
101
|
+
totalCharCount: file.totalCharCount,
|
|
102
|
+
totalLineCount: file.totalLineCount,
|
|
103
|
+
}),
|
|
104
|
+
),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return { content: formattedContent, state, success: true };
|
|
108
|
+
} catch (e) {
|
|
109
|
+
return {
|
|
110
|
+
content: `Error reading knowledge: ${(e as Error).message}`,
|
|
111
|
+
error: { body: e, message: (e as Error).message, type: 'PluginServerError' },
|
|
112
|
+
success: false,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Export the executor instance for registration
|
|
119
|
+
export const knowledgeBaseExecutor = new KnowledgeBaseExecutor();
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
import { type EditLocalFileParams } from '@lobechat/electron-client-ipc';
|
|
4
4
|
import { type BuiltinInspectorProps } from '@lobechat/types';
|
|
5
|
+
import { Icon, Text } from '@lobehub/ui';
|
|
5
6
|
import { createStaticStyles, cssVar, cx } from 'antd-style';
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import { memo } from 'react';
|
|
7
|
+
import { Minus, Plus } from 'lucide-react';
|
|
8
|
+
import { type ReactNode, memo } from 'react';
|
|
9
9
|
import { useTranslation } from 'react-i18next';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { shinyTextStyles } from '@/styles';
|
|
12
12
|
|
|
13
13
|
import { type EditLocalFileState } from '../../../types';
|
|
14
|
+
import { FilePathDisplay } from '../../components/FilePathDisplay';
|
|
14
15
|
|
|
15
16
|
const styles = createStaticStyles(({ css, cssVar }) => ({
|
|
16
17
|
root: css`
|
|
@@ -21,9 +22,9 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
|
|
|
21
22
|
|
|
22
23
|
color: ${cssVar.colorTextSecondary};
|
|
23
24
|
`,
|
|
24
|
-
|
|
25
|
-
margin-
|
|
26
|
-
|
|
25
|
+
separator: css`
|
|
26
|
+
margin-inline: 2px;
|
|
27
|
+
color: ${cssVar.colorTextQuaternary};
|
|
27
28
|
`,
|
|
28
29
|
}));
|
|
29
30
|
|
|
@@ -32,18 +33,11 @@ export const EditLocalFileInspector = memo<
|
|
|
32
33
|
>(({ args, partialArgs, isArgumentsStreaming, pluginState, isLoading }) => {
|
|
33
34
|
const { t } = useTranslation('plugin');
|
|
34
35
|
|
|
35
|
-
// Show filename with parent directory for context
|
|
36
36
|
const filePath = args?.file_path || partialArgs?.file_path || '';
|
|
37
|
-
let displayPath = '';
|
|
38
|
-
if (filePath) {
|
|
39
|
-
const { base, dir } = path.parse(filePath);
|
|
40
|
-
const parentDir = path.basename(dir);
|
|
41
|
-
displayPath = parentDir ? `${parentDir}/${base}` : base;
|
|
42
|
-
}
|
|
43
37
|
|
|
44
38
|
// During argument streaming
|
|
45
39
|
if (isArgumentsStreaming) {
|
|
46
|
-
if (!
|
|
40
|
+
if (!filePath)
|
|
47
41
|
return (
|
|
48
42
|
<div className={cx(styles.root, shinyTextStyles.shinyText)}>
|
|
49
43
|
<span>{t('builtins.lobe-local-system.apiName.editLocalFile')}</span>
|
|
@@ -53,27 +47,48 @@ export const EditLocalFileInspector = memo<
|
|
|
53
47
|
return (
|
|
54
48
|
<div className={cx(styles.root, shinyTextStyles.shinyText)}>
|
|
55
49
|
<span>{t('builtins.lobe-local-system.apiName.editLocalFile')}: </span>
|
|
56
|
-
<
|
|
50
|
+
<FilePathDisplay filePath={filePath} />
|
|
57
51
|
</div>
|
|
58
52
|
);
|
|
59
53
|
}
|
|
60
54
|
|
|
61
|
-
//
|
|
62
|
-
const
|
|
55
|
+
// Build stats parts with colors and icons
|
|
56
|
+
const linesAdded = pluginState?.linesAdded ?? 0;
|
|
57
|
+
const linesDeleted = pluginState?.linesDeleted ?? 0;
|
|
58
|
+
|
|
59
|
+
const statsParts: ReactNode[] = [];
|
|
60
|
+
if (linesAdded > 0) {
|
|
61
|
+
statsParts.push(
|
|
62
|
+
<Text as={'span'} code color={cssVar.colorSuccess} fontSize={12} key="added">
|
|
63
|
+
<Icon icon={Plus} size={12} />
|
|
64
|
+
{linesAdded}
|
|
65
|
+
</Text>,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
if (linesDeleted > 0) {
|
|
69
|
+
statsParts.push(
|
|
70
|
+
<Text as={'span'} code color={cssVar.colorError} fontSize={12} key="deleted">
|
|
71
|
+
<Icon icon={Minus} size={12} />
|
|
72
|
+
{linesDeleted}
|
|
73
|
+
</Text>,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
63
76
|
|
|
64
77
|
return (
|
|
65
78
|
<div className={cx(styles.root, isLoading && shinyTextStyles.shinyText)}>
|
|
66
|
-
<span
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
<span>{t('builtins.lobe-local-system.apiName.editLocalFile')}: </span>
|
|
80
|
+
<FilePathDisplay filePath={filePath} />
|
|
81
|
+
{!isLoading && statsParts.length > 0 && (
|
|
82
|
+
<>
|
|
83
|
+
{' '}
|
|
84
|
+
{statsParts.map((part, index) => (
|
|
85
|
+
<span key={index}>
|
|
86
|
+
{index > 0 && <span className={styles.separator}> / </span>}
|
|
87
|
+
{part}
|
|
88
|
+
</span>
|
|
89
|
+
))}
|
|
90
|
+
</>
|
|
91
|
+
)}
|
|
77
92
|
</div>
|
|
78
93
|
);
|
|
79
94
|
});
|