@lobehub/lobehub 2.0.0-next.273 → 2.0.0-next.274
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 +34 -0
- package/changelog/v1.json +9 -0
- package/locales/ar/chat.json +7 -0
- package/locales/ar/models.json +2 -3
- package/locales/ar/plugin.json +22 -1
- package/locales/bg-BG/chat.json +7 -0
- package/locales/bg-BG/models.json +3 -3
- package/locales/bg-BG/plugin.json +22 -1
- package/locales/de-DE/chat.json +7 -0
- package/locales/de-DE/models.json +3 -4
- package/locales/de-DE/plugin.json +22 -1
- package/locales/en-US/chat.json +7 -0
- package/locales/en-US/models.json +5 -5
- package/locales/en-US/plugin.json +22 -1
- package/locales/es-ES/chat.json +7 -0
- package/locales/es-ES/models.json +3 -4
- package/locales/es-ES/plugin.json +22 -1
- package/locales/fa-IR/chat.json +7 -0
- package/locales/fa-IR/models.json +3 -4
- package/locales/fa-IR/plugin.json +22 -1
- package/locales/fr-FR/chat.json +7 -0
- package/locales/fr-FR/models.json +50 -3
- package/locales/fr-FR/plugin.json +22 -1
- package/locales/it-IT/chat.json +7 -0
- package/locales/it-IT/models.json +3 -3
- package/locales/it-IT/plugin.json +22 -1
- package/locales/ja-JP/chat.json +7 -0
- package/locales/ja-JP/models.json +43 -4
- package/locales/ja-JP/plugin.json +22 -1
- package/locales/ko-KR/chat.json +7 -0
- package/locales/ko-KR/models.json +3 -4
- package/locales/ko-KR/plugin.json +22 -1
- package/locales/nl-NL/chat.json +7 -0
- package/locales/nl-NL/models.json +51 -3
- package/locales/nl-NL/plugin.json +22 -1
- package/locales/pl-PL/chat.json +7 -0
- package/locales/pl-PL/models.json +3 -3
- package/locales/pl-PL/plugin.json +22 -1
- package/locales/pt-BR/chat.json +7 -0
- package/locales/pt-BR/models.json +3 -4
- package/locales/pt-BR/plugin.json +22 -1
- package/locales/ru-RU/chat.json +7 -0
- package/locales/ru-RU/models.json +3 -4
- package/locales/ru-RU/plugin.json +22 -1
- package/locales/tr-TR/chat.json +7 -0
- package/locales/tr-TR/models.json +3 -4
- package/locales/tr-TR/plugin.json +22 -1
- package/locales/vi-VN/chat.json +7 -0
- package/locales/vi-VN/models.json +3 -3
- package/locales/vi-VN/plugin.json +22 -1
- package/locales/zh-CN/chat.json +7 -0
- package/locales/zh-CN/models.json +54 -4
- package/locales/zh-CN/plugin.json +22 -1
- package/locales/zh-TW/chat.json +7 -0
- package/locales/zh-TW/models.json +43 -4
- package/locales/zh-TW/plugin.json +22 -1
- package/package.json +1 -1
- package/packages/builtin-tool-agent-builder/package.json +1 -0
- package/packages/builtin-tool-agent-builder/src/client/Inspector/GetAvailableModels/index.tsx +66 -0
- package/packages/builtin-tool-agent-builder/src/client/Inspector/InstallPlugin/index.tsx +63 -0
- package/packages/builtin-tool-agent-builder/src/client/Inspector/SearchMarketTools/index.tsx +64 -0
- package/packages/builtin-tool-agent-builder/src/client/Inspector/UpdateConfig/index.tsx +94 -0
- package/packages/builtin-tool-agent-builder/src/client/Inspector/UpdatePrompt/index.tsx +96 -0
- package/packages/builtin-tool-agent-builder/src/client/Inspector/index.ts +29 -0
- package/packages/builtin-tool-agent-builder/src/client/index.ts +13 -0
- package/packages/builtin-tool-agent-builder/src/executor.ts +132 -0
- package/packages/builtin-tool-cloud-sandbox/src/client/Inspector/ExecuteCode/index.tsx +5 -14
- package/packages/builtin-tool-cloud-sandbox/src/client/Inspector/RunCommand/index.tsx +5 -13
- package/packages/builtin-tool-group-agent-builder/package.json +7 -1
- package/packages/builtin-tool-group-agent-builder/src/ExecutionRuntime/index.ts +331 -87
- package/packages/builtin-tool-group-agent-builder/src/client/Inspector/BatchCreateAgents/index.tsx +110 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Inspector/CreateAgent/index.tsx +72 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Inspector/InviteAgent/index.tsx +57 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Inspector/RemoveAgent/index.tsx +57 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Inspector/SearchAgent/index.tsx +66 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Inspector/UpdateAgentPrompt/index.tsx +120 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Inspector/UpdateGroup/index.tsx +87 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Inspector/UpdateGroupPrompt/index.tsx +99 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Inspector/index.ts +52 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Render/BatchCreateAgents.tsx +103 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Render/UpdateAgentPrompt/index.tsx +36 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Render/UpdateGroupPrompt/index.tsx +36 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Render/index.ts +16 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Streaming/BatchCreateAgents/index.tsx +88 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Streaming/UpdateAgentPrompt/index.tsx +37 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Streaming/UpdateGroupPrompt/index.tsx +35 -0
- package/packages/builtin-tool-group-agent-builder/src/client/Streaming/index.ts +22 -0
- package/packages/builtin-tool-group-agent-builder/src/client/index.ts +26 -0
- package/packages/builtin-tool-group-agent-builder/src/executor.ts +284 -0
- package/packages/builtin-tool-group-agent-builder/src/index.ts +1 -14
- package/packages/builtin-tool-group-agent-builder/src/manifest.ts +160 -15
- package/packages/builtin-tool-group-agent-builder/src/systemRole.ts +232 -46
- package/packages/builtin-tool-group-agent-builder/src/types.ts +191 -41
- package/packages/builtin-tool-group-management/src/client/Inspector/Broadcast/index.tsx +2 -2
- package/packages/builtin-tool-group-management/src/manifest.ts +1 -1
- package/packages/builtin-tool-gtd/src/client/Inspector/ClearTodos/index.tsx +5 -11
- package/packages/builtin-tool-gtd/src/client/Inspector/CompleteTodos/index.tsx +3 -9
- package/packages/builtin-tool-gtd/src/client/Inspector/CreatePlan/index.tsx +6 -15
- package/packages/builtin-tool-gtd/src/client/Inspector/CreateTodos/index.tsx +3 -9
- package/packages/builtin-tool-gtd/src/client/Inspector/ExecTask/index.tsx +6 -17
- package/packages/builtin-tool-gtd/src/client/Inspector/RemoveTodos/index.tsx +3 -9
- package/packages/builtin-tool-gtd/src/client/Inspector/UpdatePlan/index.tsx +3 -9
- package/packages/builtin-tool-gtd/src/client/Inspector/UpdateTodos/index.tsx +3 -9
- package/packages/builtin-tool-knowledge-base/src/client/Inspector/ReadKnowledge/index.tsx +4 -16
- package/packages/builtin-tool-knowledge-base/src/client/Inspector/SearchKnowledgeBase/index.tsx +5 -16
- package/packages/builtin-tool-local-system/src/client/Inspector/EditLocalFile/index.tsx +4 -12
- package/packages/builtin-tool-local-system/src/client/Inspector/GlobLocalFiles/index.tsx +5 -13
- package/packages/builtin-tool-local-system/src/client/Inspector/GrepContent/index.tsx +5 -16
- package/packages/builtin-tool-local-system/src/client/Inspector/ListLocalFiles/index.tsx +5 -16
- package/packages/builtin-tool-local-system/src/client/Inspector/ReadLocalFile/index.tsx +5 -16
- package/packages/builtin-tool-local-system/src/client/Inspector/RenameLocalFile/index.tsx +5 -11
- package/packages/builtin-tool-local-system/src/client/Inspector/RunCommand/index.tsx +5 -13
- package/packages/builtin-tool-local-system/src/client/Inspector/SearchLocalFiles/index.tsx +5 -16
- package/packages/builtin-tool-local-system/src/client/Inspector/WriteLocalFile/index.tsx +6 -15
- package/packages/builtin-tool-notebook/src/client/Inspector/CreateDocument/index.tsx +7 -15
- package/packages/builtin-tool-page-agent/src/client/Inspector/EditTitle/index.tsx +5 -14
- package/packages/builtin-tool-page-agent/src/client/Inspector/GetPageContent/index.tsx +7 -8
- package/packages/builtin-tool-page-agent/src/client/Inspector/InitPage/index.tsx +4 -10
- package/packages/builtin-tool-page-agent/src/client/Inspector/ModifyNodes/index.tsx +3 -9
- package/packages/builtin-tool-page-agent/src/client/Inspector/ReplaceText/index.tsx +5 -11
- package/packages/builtin-tool-web-browsing/src/client/Inspector/CrawlMultiPages/index.tsx +6 -15
- package/packages/builtin-tool-web-browsing/src/client/Inspector/CrawlSinglePage/index.tsx +6 -15
- package/packages/builtin-tool-web-browsing/src/client/Inspector/Search/index.tsx +4 -15
- package/packages/database/src/models/chatGroup.ts +1 -1
- package/packages/model-bank/src/aiModels/aihubmix.ts +2 -1
- package/packages/model-bank/src/aiModels/google.ts +2 -1
- package/packages/model-bank/src/aiModels/infiniai.ts +9 -6
- package/packages/model-bank/src/aiModels/minimax.ts +9 -5
- package/packages/model-bank/src/aiModels/ollamacloud.ts +4 -2
- package/packages/model-bank/src/aiModels/vertexai.ts +2 -1
- package/packages/types/src/agentGroup/index.ts +8 -0
- package/patches/@upstash__qstash.patch +13 -1
- package/src/app/[variants]/(main)/agent/_layout/Sidebar/Header/Nav.tsx +1 -1
- package/src/app/[variants]/(main)/agent/cron/[cronId]/index.tsx +4 -3
- package/src/app/[variants]/(main)/agent/profile/features/ProfileEditor/index.tsx +1 -1
- package/src/app/[variants]/(main)/agent/profile/features/store/action.ts +18 -21
- package/src/app/[variants]/(main)/group/_layout/GroupIdSync.tsx +6 -1
- package/src/app/[variants]/(main)/group/_layout/Sidebar/GroupConfig/AgentProfilePopup.tsx +29 -21
- package/src/app/[variants]/(main)/group/_layout/Sidebar/GroupConfig/GroupMember.tsx +1 -0
- package/src/app/[variants]/(main)/group/_layout/Sidebar/GroupConfig/GroupMemberItem.tsx +35 -18
- package/src/app/[variants]/(main)/group/_layout/Sidebar/Header/AddTopicButon.tsx +2 -10
- package/src/app/[variants]/(main)/group/_layout/Sidebar/Header/Nav.tsx +10 -2
- package/src/app/[variants]/(main)/group/_layout/Sidebar/Header/index.tsx +1 -2
- package/src/app/[variants]/(main)/group/profile/features/AgentBuilder/AgentBuilderProvider.tsx +1 -0
- package/src/app/[variants]/(main)/group/profile/features/AgentBuilder/TopicSelector.tsx +15 -9
- package/src/app/[variants]/(main)/group/profile/features/AgentBuilder/index.tsx +12 -6
- package/src/app/[variants]/(main)/group/profile/features/{ProfileEditor/AgentHeader.tsx → GroupProfile/GroupHeader.tsx} +22 -29
- package/src/app/[variants]/(main)/group/profile/features/GroupProfile/index.tsx +96 -0
- package/src/app/[variants]/(main)/group/profile/features/Header/AgentBuilderToggle.tsx +3 -4
- package/src/app/[variants]/(main)/group/profile/features/Header/AutoSaveHint.tsx +11 -7
- package/src/app/[variants]/(main)/group/profile/features/Header/ChromeTabs/index.tsx +147 -0
- package/src/app/[variants]/(main)/group/profile/features/Header/index.tsx +104 -13
- package/src/app/[variants]/(main)/group/profile/features/MemberProfile/AgentHeader.tsx +222 -0
- package/src/app/[variants]/(main)/group/profile/features/MemberProfile/index.tsx +155 -0
- package/src/app/[variants]/(main)/group/profile/features/ProfileHydration.tsx +63 -5
- package/src/app/[variants]/(main)/group/profile/index.tsx +34 -37
- package/src/app/[variants]/(mobile)/(home)/_layout/SessionHydration.tsx +1 -1
- package/src/app/[variants]/(mobile)/(home)/features/SessionListContent/List/Item/index.tsx +1 -1
- package/src/features/AgentBuilder/index.tsx +16 -1
- package/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/StatusIndicator.tsx +3 -2
- package/src/features/EditorCanvas/EditorCanvas.test.tsx +206 -0
- package/src/features/EditorCanvas/EditorDataMode.tsx +53 -19
- package/src/features/EditorModal/index.tsx +2 -2
- package/src/features/NavPanel/components/SessionHydration.tsx +1 -1
- package/src/features/ShareModal/ShareImage/ChatList/index.tsx +1 -1
- package/src/features/ShareModal/SharePdf/index.tsx +1 -1
- package/src/hooks/useBidirectionalQuerySync.ts +112 -0
- package/src/locales/default/chat.ts +10 -0
- package/src/locales/default/plugin.ts +22 -1
- package/src/server/modules/AgentRuntime/RuntimeExecutors.ts +45 -45
- package/src/server/modules/KeyVaultsEncrypt/index.ts +6 -6
- package/src/server/modules/S3/index.ts +1 -1
- package/src/server/routers/lambda/agent.ts +24 -0
- package/src/server/routers/lambda/agentGroup.ts +39 -0
- package/src/services/agent.ts +22 -0
- package/src/services/chatGroup/index.ts +14 -0
- package/src/store/agent/selectors/selectors.ts +3 -0
- package/src/store/agentGroup/initialState.ts +6 -0
- package/src/store/agentGroup/selectors/byId.ts +3 -1
- package/src/store/agentGroup/selectors/current.ts +2 -2
- package/src/store/agentGroup/slices/lifecycle.ts +18 -0
- package/src/store/chat/agents/__tests__/createAgentExecutors/fixtures/mockStore.ts +1 -1
- package/src/store/chat/slices/aiAgent/actions/__tests__/agentGroup.test.ts +4 -1
- package/src/store/chat/slices/aiAgent/actions/agentGroup.ts +1 -1
- package/src/store/chat/slices/aiChat/actions/__tests__/conversationLifecycle.test.ts +65 -0
- package/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts +2 -1
- package/src/store/chat/slices/builtinTool/actions/__tests__/search.test.ts +1 -1
- package/src/store/chat/slices/builtinTool/actions/index.ts +1 -6
- package/src/store/chat/slices/message/action.test.ts +5 -5
- package/src/store/chat/slices/message/actions/publicApi.ts +5 -5
- package/src/store/chat/slices/message/initialState.ts +0 -5
- package/src/store/chat/slices/message/selectors/displayMessage.test.ts +4 -4
- package/src/store/chat/slices/plugin/action.test.ts +54 -19
- package/src/store/chat/slices/plugin/actions/pluginTypes.ts +15 -21
- package/src/store/chat/slices/topic/action.test.ts +74 -24
- package/src/store/chat/slices/topic/action.ts +21 -13
- package/src/store/chat/slices/topic/selectors.test.ts +1 -1
- package/src/store/global/initialState.ts +10 -0
- package/src/store/global/selectors/systemStatus.ts +5 -0
- package/src/store/groupProfile/action.ts +168 -0
- package/src/store/groupProfile/index.ts +16 -0
- package/src/{app/[variants]/(main)/group/profile/features/store → store/groupProfile}/initialState.ts +17 -0
- package/src/store/groupProfile/selectors.ts +13 -0
- package/src/store/tool/slices/builtin/executors/index.ts +4 -0
- package/src/styles/text.ts +16 -0
- package/src/tools/inspectors.ts +13 -0
- package/src/tools/renders.ts +3 -0
- package/src/tools/streamings.ts +8 -0
- package/src/app/[variants]/(main)/group/profile/features/EditorCanvas/TypoBar.tsx +0 -129
- package/src/app/[variants]/(main)/group/profile/features/EditorCanvas/index.tsx +0 -138
- package/src/app/[variants]/(main)/group/profile/features/EditorCanvas/useSlashItems.tsx +0 -139
- package/src/app/[variants]/(main)/group/profile/features/ProfileEditor/index.tsx +0 -82
- package/src/app/[variants]/(main)/group/profile/features/ProfileProvider.tsx +0 -20
- package/src/app/[variants]/(main)/group/profile/features/StoreUpdater.tsx +0 -24
- package/src/app/[variants]/(main)/group/profile/features/store/action.ts +0 -163
- package/src/app/[variants]/(main)/group/profile/features/store/index.ts +0 -23
- package/src/app/[variants]/(main)/group/profile/features/store/selectors.ts +0 -7
- package/src/features/EditorModal/EditorCanvas.tsx +0 -84
- package/src/features/EditorModal/Typobar.tsx +0 -139
- package/src/store/chat/slices/builtinTool/actions/agentBuilder.ts +0 -192
- package/src/store/chat/slices/builtinTool/actions/groupAgentBuilder.ts +0 -242
- package/src/tools/executionRuntimes.ts +0 -14
- /package/src/app/[variants]/(main)/group/profile/features/{ProfileEditor → MemberProfile}/AgentTool.tsx +0 -0
- /package/src/app/[variants]/(main)/group/profile/features/{ProfileEditor → MemberProfile}/MentionList/MentionDropdown.tsx +0 -0
- /package/src/app/[variants]/(main)/group/profile/features/{ProfileEditor → MemberProfile}/MentionList/index.tsx +0 -0
- /package/src/app/[variants]/(main)/group/profile/features/{ProfileEditor → MemberProfile}/MentionList/types.ts +0 -0
- /package/src/app/[variants]/(main)/group/profile/features/{ProfileEditor → MemberProfile}/MentionList/useMentionItems.tsx +0 -0
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { HotkeyEnum, getHotkeyById } from '@lobehub/editor';
|
|
2
|
-
import { FloatActions } from '@lobehub/editor/react';
|
|
3
|
-
import { type ChatInputActionsProps } from '@lobehub/editor/react';
|
|
4
|
-
import {
|
|
5
|
-
BoldIcon,
|
|
6
|
-
CodeXmlIcon,
|
|
7
|
-
ItalicIcon,
|
|
8
|
-
ListIcon,
|
|
9
|
-
ListOrderedIcon,
|
|
10
|
-
ListTodoIcon,
|
|
11
|
-
MessageSquareQuote,
|
|
12
|
-
SigmaIcon,
|
|
13
|
-
SquareDashedBottomCodeIcon,
|
|
14
|
-
StrikethroughIcon,
|
|
15
|
-
UnderlineIcon,
|
|
16
|
-
} from 'lucide-react';
|
|
17
|
-
import { memo, useMemo } from 'react';
|
|
18
|
-
import { useTranslation } from 'react-i18next';
|
|
19
|
-
|
|
20
|
-
import { useProfileStore } from '../store';
|
|
21
|
-
|
|
22
|
-
const TypoBar = memo(() => {
|
|
23
|
-
const { t } = useTranslation('editor');
|
|
24
|
-
const editorState = useProfileStore((s) => s.editorState);
|
|
25
|
-
|
|
26
|
-
const items: ChatInputActionsProps['items'] = useMemo(() => {
|
|
27
|
-
if (!editorState) return [];
|
|
28
|
-
|
|
29
|
-
return [
|
|
30
|
-
{
|
|
31
|
-
active: editorState.isBold,
|
|
32
|
-
icon: BoldIcon,
|
|
33
|
-
key: 'bold',
|
|
34
|
-
label: t('typobar.bold'),
|
|
35
|
-
onClick: editorState.bold,
|
|
36
|
-
tooltipProps: { hotkey: getHotkeyById(HotkeyEnum.Bold).keys },
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
active: editorState.isItalic,
|
|
40
|
-
icon: ItalicIcon,
|
|
41
|
-
key: 'italic',
|
|
42
|
-
label: t('typobar.italic'),
|
|
43
|
-
onClick: editorState.italic,
|
|
44
|
-
tooltipProps: { hotkey: getHotkeyById(HotkeyEnum.Italic).keys },
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
active: editorState.isUnderline,
|
|
48
|
-
icon: UnderlineIcon,
|
|
49
|
-
key: 'underline',
|
|
50
|
-
label: t('typobar.underline'),
|
|
51
|
-
onClick: editorState.underline,
|
|
52
|
-
tooltipProps: { hotkey: getHotkeyById(HotkeyEnum.Underline).keys },
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
active: editorState.isStrikethrough,
|
|
56
|
-
icon: StrikethroughIcon,
|
|
57
|
-
key: 'strikethrough',
|
|
58
|
-
label: t('typobar.strikethrough'),
|
|
59
|
-
onClick: editorState.strikethrough,
|
|
60
|
-
tooltipProps: { hotkey: getHotkeyById(HotkeyEnum.Strikethrough).keys },
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
type: 'divider',
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
{
|
|
67
|
-
icon: ListIcon,
|
|
68
|
-
key: 'bulletList',
|
|
69
|
-
label: t('typobar.bulletList'),
|
|
70
|
-
onClick: editorState.bulletList,
|
|
71
|
-
tooltipProps: { hotkey: getHotkeyById(HotkeyEnum.BulletList).keys },
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
icon: ListOrderedIcon,
|
|
75
|
-
key: 'numberlist',
|
|
76
|
-
label: t('typobar.numberList'),
|
|
77
|
-
onClick: editorState.numberList,
|
|
78
|
-
tooltipProps: { hotkey: getHotkeyById(HotkeyEnum.NumberList).keys },
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
icon: ListTodoIcon,
|
|
82
|
-
key: 'tasklist',
|
|
83
|
-
label: t('typobar.taskList'),
|
|
84
|
-
onClick: editorState.checkList,
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
type: 'divider',
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
active: editorState.isBlockquote,
|
|
91
|
-
icon: MessageSquareQuote,
|
|
92
|
-
key: 'blockquote',
|
|
93
|
-
label: t('typobar.blockquote'),
|
|
94
|
-
onClick: editorState.blockquote,
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
type: 'divider',
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
icon: SigmaIcon,
|
|
101
|
-
key: 'math',
|
|
102
|
-
label: t('typobar.tex'),
|
|
103
|
-
onClick: editorState.insertMath,
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
active: editorState.isCode,
|
|
107
|
-
icon: CodeXmlIcon,
|
|
108
|
-
key: 'code',
|
|
109
|
-
label: t('typobar.code'),
|
|
110
|
-
onClick: editorState.code,
|
|
111
|
-
tooltipProps: { hotkey: getHotkeyById(HotkeyEnum.CodeInline).keys },
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
icon: SquareDashedBottomCodeIcon,
|
|
115
|
-
key: 'codeblock',
|
|
116
|
-
label: t('typobar.codeblock'),
|
|
117
|
-
onClick: editorState.codeblock,
|
|
118
|
-
},
|
|
119
|
-
].filter(Boolean) as ChatInputActionsProps['items'];
|
|
120
|
-
}, [editorState, t]);
|
|
121
|
-
|
|
122
|
-
if (!editorState) return null;
|
|
123
|
-
|
|
124
|
-
return <FloatActions items={items} />;
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
TypoBar.displayName = 'TypoBar';
|
|
128
|
-
|
|
129
|
-
export default TypoBar;
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
ReactCodePlugin,
|
|
5
|
-
ReactCodemirrorPlugin,
|
|
6
|
-
ReactHRPlugin,
|
|
7
|
-
ReactLinkHighlightPlugin,
|
|
8
|
-
ReactListPlugin,
|
|
9
|
-
ReactMathPlugin,
|
|
10
|
-
ReactMentionPlugin,
|
|
11
|
-
ReactTablePlugin,
|
|
12
|
-
ReactToolbarPlugin,
|
|
13
|
-
} from '@lobehub/editor';
|
|
14
|
-
import { Editor } from '@lobehub/editor/react';
|
|
15
|
-
import isEqual from 'fast-deep-equal';
|
|
16
|
-
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
17
|
-
import { useTranslation } from 'react-i18next';
|
|
18
|
-
|
|
19
|
-
import { useAgentGroupStore } from '@/store/agentGroup';
|
|
20
|
-
import { agentGroupSelectors } from '@/store/agentGroup/selectors';
|
|
21
|
-
|
|
22
|
-
import { useMentionOptions } from '../ProfileEditor/MentionList';
|
|
23
|
-
import { EMPTY_EDITOR_STATE } from '../constants';
|
|
24
|
-
import { useProfileStore } from '../store';
|
|
25
|
-
import TypoBar from './TypoBar';
|
|
26
|
-
import { useSlashItems } from './useSlashItems';
|
|
27
|
-
|
|
28
|
-
const EditorCanvas = memo(() => {
|
|
29
|
-
const { t } = useTranslation('setting');
|
|
30
|
-
const [editorInit, setEditorInit] = useState(false);
|
|
31
|
-
const [contentInit, setContentInit] = useState(false);
|
|
32
|
-
|
|
33
|
-
// Get systemPrompt from agentGroup store (groupMap.config.systemPrompt)
|
|
34
|
-
const groupConfig = useAgentGroupStore(agentGroupSelectors.currentGroupConfig, isEqual);
|
|
35
|
-
const systemRole = groupConfig?.systemPrompt;
|
|
36
|
-
const updateGroupConfig = useAgentGroupStore((s) => s.updateGroupConfig);
|
|
37
|
-
|
|
38
|
-
// Get streaming state from agentGroup store
|
|
39
|
-
const streamingInProgress = useAgentGroupStore((s) => s.streamingSystemPromptInProgress);
|
|
40
|
-
const streamingSystemRole = useAgentGroupStore((s) => s.streamingSystemPrompt);
|
|
41
|
-
|
|
42
|
-
// For group profile, we don't use editorData - just systemPrompt
|
|
43
|
-
const editorData = undefined;
|
|
44
|
-
const [initialLoad] = useState(EMPTY_EDITOR_STATE);
|
|
45
|
-
const mentionOptions = useMentionOptions();
|
|
46
|
-
const editor = useProfileStore((s) => s.editor);
|
|
47
|
-
const handleContentChange = useProfileStore((s) => s.handleContentChange);
|
|
48
|
-
const slashItems = useSlashItems();
|
|
49
|
-
|
|
50
|
-
const prevStreamingRef = useRef<string | undefined>(undefined);
|
|
51
|
-
|
|
52
|
-
// Wrap handleContentChange with updateGroupConfig
|
|
53
|
-
const handleChange = useCallback(() => {
|
|
54
|
-
// Don't trigger save during streaming
|
|
55
|
-
if (streamingInProgress) return;
|
|
56
|
-
handleContentChange(async (config) => {
|
|
57
|
-
// Only update systemPrompt in group config
|
|
58
|
-
if (config.systemRole !== undefined) {
|
|
59
|
-
await updateGroupConfig({ systemPrompt: config.systemRole });
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}, [handleContentChange, updateGroupConfig, streamingInProgress]);
|
|
63
|
-
|
|
64
|
-
// Handle streaming updates - update editor with streaming content
|
|
65
|
-
useEffect(() => {
|
|
66
|
-
if (!editor || !editorInit) return;
|
|
67
|
-
if (!streamingInProgress) {
|
|
68
|
-
prevStreamingRef.current = undefined;
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Only update if content has changed
|
|
73
|
-
if (streamingSystemRole !== prevStreamingRef.current) {
|
|
74
|
-
prevStreamingRef.current = streamingSystemRole;
|
|
75
|
-
try {
|
|
76
|
-
editor.setDocument('markdown', streamingSystemRole || '');
|
|
77
|
-
} catch {
|
|
78
|
-
// Ignore errors during streaming updates
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}, [editor, editorInit, streamingSystemRole, streamingInProgress]);
|
|
82
|
-
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
if (!editorInit || !editor || contentInit) return;
|
|
85
|
-
// Don't init if streaming is in progress
|
|
86
|
-
if (streamingInProgress) return;
|
|
87
|
-
try {
|
|
88
|
-
if (editorData) {
|
|
89
|
-
editor.setDocument('json', editorData);
|
|
90
|
-
} else if (systemRole) {
|
|
91
|
-
editor.setDocument('markdown', systemRole);
|
|
92
|
-
}
|
|
93
|
-
// If no editorData and no systemRole, leave editor empty to show placeholder
|
|
94
|
-
setContentInit(true);
|
|
95
|
-
} catch (error) {
|
|
96
|
-
console.error('[EditorCanvas] Failed to init editor content:', error);
|
|
97
|
-
}
|
|
98
|
-
}, [editorInit, contentInit, editor, editorData, systemRole, streamingInProgress]);
|
|
99
|
-
|
|
100
|
-
return (
|
|
101
|
-
<div
|
|
102
|
-
onClick={(e) => {
|
|
103
|
-
e.stopPropagation();
|
|
104
|
-
}}
|
|
105
|
-
>
|
|
106
|
-
<Editor
|
|
107
|
-
content={initialLoad}
|
|
108
|
-
editor={editor!}
|
|
109
|
-
lineEmptyPlaceholder={t('settingAgent.prompt.placeholder')}
|
|
110
|
-
mentionOption={mentionOptions}
|
|
111
|
-
onInit={() => setEditorInit(true)}
|
|
112
|
-
onTextChange={handleChange}
|
|
113
|
-
placeholder={t('settingAgent.prompt.templatePlaceholder')}
|
|
114
|
-
plugins={[
|
|
115
|
-
ReactListPlugin,
|
|
116
|
-
ReactCodePlugin,
|
|
117
|
-
ReactCodemirrorPlugin,
|
|
118
|
-
ReactHRPlugin,
|
|
119
|
-
ReactLinkHighlightPlugin,
|
|
120
|
-
ReactTablePlugin,
|
|
121
|
-
ReactMathPlugin,
|
|
122
|
-
ReactMentionPlugin,
|
|
123
|
-
Editor.withProps(ReactToolbarPlugin, {
|
|
124
|
-
children: <TypoBar />,
|
|
125
|
-
}),
|
|
126
|
-
]}
|
|
127
|
-
slashOption={{
|
|
128
|
-
items: slashItems,
|
|
129
|
-
}}
|
|
130
|
-
style={{
|
|
131
|
-
paddingBottom: 64,
|
|
132
|
-
}}
|
|
133
|
-
/>
|
|
134
|
-
</div>
|
|
135
|
-
);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
export default EditorCanvas;
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
INSERT_CHECK_LIST_COMMAND,
|
|
3
|
-
INSERT_HEADING_COMMAND,
|
|
4
|
-
INSERT_HORIZONTAL_RULE_COMMAND,
|
|
5
|
-
INSERT_MATH_COMMAND,
|
|
6
|
-
INSERT_ORDERED_LIST_COMMAND,
|
|
7
|
-
INSERT_TABLE_COMMAND,
|
|
8
|
-
INSERT_UNORDERED_LIST_COMMAND,
|
|
9
|
-
type SlashOptions,
|
|
10
|
-
} from '@lobehub/editor';
|
|
11
|
-
import { Text } from '@lobehub/ui';
|
|
12
|
-
import {
|
|
13
|
-
Heading1Icon,
|
|
14
|
-
Heading2Icon,
|
|
15
|
-
Heading3Icon,
|
|
16
|
-
ListIcon,
|
|
17
|
-
ListOrderedIcon,
|
|
18
|
-
ListTodoIcon,
|
|
19
|
-
MinusIcon,
|
|
20
|
-
SigmaIcon,
|
|
21
|
-
SquareDashedBottomCodeIcon,
|
|
22
|
-
Table2Icon,
|
|
23
|
-
} from 'lucide-react';
|
|
24
|
-
import { useMemo } from 'react';
|
|
25
|
-
import { useTranslation } from 'react-i18next';
|
|
26
|
-
|
|
27
|
-
import { useProfileStore } from '../store';
|
|
28
|
-
|
|
29
|
-
export const useSlashItems = (): SlashOptions['items'] => {
|
|
30
|
-
const { t } = useTranslation('editor');
|
|
31
|
-
const editorState = useProfileStore((s) => s.editorState);
|
|
32
|
-
return useMemo(() => {
|
|
33
|
-
const data: SlashOptions['items'] = [
|
|
34
|
-
{
|
|
35
|
-
icon: Heading1Icon,
|
|
36
|
-
key: 'h1',
|
|
37
|
-
label: t('slash.h1'),
|
|
38
|
-
onSelect: (editor) => {
|
|
39
|
-
editor.dispatchCommand(INSERT_HEADING_COMMAND, { tag: 'h1' });
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
icon: Heading2Icon,
|
|
44
|
-
key: 'h2',
|
|
45
|
-
label: t('slash.h2'),
|
|
46
|
-
onSelect: (editor) => {
|
|
47
|
-
editor.dispatchCommand(INSERT_HEADING_COMMAND, { tag: 'h2' });
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
icon: Heading3Icon,
|
|
52
|
-
key: 'h3',
|
|
53
|
-
label: t('slash.h3'),
|
|
54
|
-
onSelect: (editor) => {
|
|
55
|
-
editor.dispatchCommand(INSERT_HEADING_COMMAND, { tag: 'h3' });
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
type: 'divider',
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
icon: ListTodoIcon,
|
|
63
|
-
key: 'tl',
|
|
64
|
-
label: t('typobar.taskList'),
|
|
65
|
-
onSelect: (editor) => {
|
|
66
|
-
editor.dispatchCommand(INSERT_CHECK_LIST_COMMAND, undefined);
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
icon: ListIcon,
|
|
71
|
-
key: 'ul',
|
|
72
|
-
label: t('typobar.bulletList'),
|
|
73
|
-
onSelect: (editor) => {
|
|
74
|
-
editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined);
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
icon: ListOrderedIcon,
|
|
79
|
-
key: 'ol',
|
|
80
|
-
label: t('typobar.numberList'),
|
|
81
|
-
onSelect: (editor) => {
|
|
82
|
-
editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, undefined);
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
type: 'divider',
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
icon: MinusIcon,
|
|
90
|
-
key: 'hr',
|
|
91
|
-
label: t('slash.hr'),
|
|
92
|
-
onSelect: (editor) => {
|
|
93
|
-
editor.dispatchCommand(INSERT_HORIZONTAL_RULE_COMMAND, {});
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
icon: Table2Icon,
|
|
98
|
-
key: 'table',
|
|
99
|
-
label: t('slash.table'),
|
|
100
|
-
onSelect: (editor) => {
|
|
101
|
-
editor.dispatchCommand(INSERT_TABLE_COMMAND, { columns: '3', rows: '3' });
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
icon: SquareDashedBottomCodeIcon,
|
|
106
|
-
key: 'codeblock',
|
|
107
|
-
label: t('typobar.codeblock'),
|
|
108
|
-
onSelect: () => {
|
|
109
|
-
editorState.codeblock();
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
icon: SigmaIcon,
|
|
114
|
-
key: 'tex',
|
|
115
|
-
label: t('slash.tex'),
|
|
116
|
-
onSelect: (editor) => {
|
|
117
|
-
editor.dispatchCommand(INSERT_MATH_COMMAND, { code: 'x^2 + y^2 = z^2' });
|
|
118
|
-
queueMicrotask(() => {
|
|
119
|
-
editor.focus();
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
];
|
|
124
|
-
return data.map((item) => {
|
|
125
|
-
if (item.type === 'divider') return item;
|
|
126
|
-
return {
|
|
127
|
-
...item,
|
|
128
|
-
extra: (
|
|
129
|
-
<Text code fontSize={12} type={'secondary'}>
|
|
130
|
-
{item.key}
|
|
131
|
-
</Text>
|
|
132
|
-
),
|
|
133
|
-
style: {
|
|
134
|
-
minWidth: 200,
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
});
|
|
138
|
-
}, [t]);
|
|
139
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { Button, Flexbox } from '@lobehub/ui';
|
|
4
|
-
import { Divider } from 'antd';
|
|
5
|
-
import isEqual from 'fast-deep-equal';
|
|
6
|
-
import { PlayIcon } from 'lucide-react';
|
|
7
|
-
import React, { memo } from 'react';
|
|
8
|
-
import { useTranslation } from 'react-i18next';
|
|
9
|
-
import urlJoin from 'url-join';
|
|
10
|
-
|
|
11
|
-
import ModelSelect from '@/features/ModelSelect';
|
|
12
|
-
import { useQueryRoute } from '@/hooks/useQueryRoute';
|
|
13
|
-
import { useAgentStore } from '@/store/agent';
|
|
14
|
-
import { agentSelectors } from '@/store/agent/selectors';
|
|
15
|
-
import { useAgentGroupStore } from '@/store/agentGroup';
|
|
16
|
-
import { agentGroupSelectors } from '@/store/agentGroup/selectors';
|
|
17
|
-
|
|
18
|
-
import EditorCanvas from '../EditorCanvas';
|
|
19
|
-
import AgentHeader from './AgentHeader';
|
|
20
|
-
import AgentTool from './AgentTool';
|
|
21
|
-
|
|
22
|
-
const ProfileEditor = memo(() => {
|
|
23
|
-
const { t } = useTranslation('setting');
|
|
24
|
-
const config = useAgentStore(agentSelectors.currentAgentConfig, isEqual);
|
|
25
|
-
const updateConfig = useAgentStore((s) => s.updateAgentConfig);
|
|
26
|
-
const groupId = useAgentGroupStore(agentGroupSelectors.activeGroupId);
|
|
27
|
-
const router = useQueryRoute();
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<>
|
|
31
|
-
<Flexbox
|
|
32
|
-
onClick={(e) => {
|
|
33
|
-
e.stopPropagation();
|
|
34
|
-
}}
|
|
35
|
-
style={{ cursor: 'default', marginBottom: 12 }}
|
|
36
|
-
>
|
|
37
|
-
{/* Header: Avatar + Name + Description */}
|
|
38
|
-
<AgentHeader />
|
|
39
|
-
{/* Config Bar: Model Selector */}
|
|
40
|
-
<Flexbox
|
|
41
|
-
align={'center'}
|
|
42
|
-
gap={8}
|
|
43
|
-
horizontal
|
|
44
|
-
justify={'flex-start'}
|
|
45
|
-
style={{ marginBottom: 12 }}
|
|
46
|
-
>
|
|
47
|
-
<ModelSelect
|
|
48
|
-
onChange={updateConfig}
|
|
49
|
-
value={{
|
|
50
|
-
model: config?.model,
|
|
51
|
-
provider: config?.provider,
|
|
52
|
-
}}
|
|
53
|
-
/>
|
|
54
|
-
</Flexbox>
|
|
55
|
-
<AgentTool />
|
|
56
|
-
<Flexbox
|
|
57
|
-
align={'center'}
|
|
58
|
-
gap={8}
|
|
59
|
-
horizontal
|
|
60
|
-
justify={'flex-start'}
|
|
61
|
-
style={{ marginTop: 16 }}
|
|
62
|
-
>
|
|
63
|
-
<Button
|
|
64
|
-
icon={PlayIcon}
|
|
65
|
-
onClick={() => {
|
|
66
|
-
if (!groupId) return;
|
|
67
|
-
router.push(urlJoin('/group', groupId));
|
|
68
|
-
}}
|
|
69
|
-
type={'primary'}
|
|
70
|
-
>
|
|
71
|
-
{t('startConversation')}
|
|
72
|
-
</Button>
|
|
73
|
-
</Flexbox>
|
|
74
|
-
</Flexbox>
|
|
75
|
-
<Divider />
|
|
76
|
-
{/* Main Content: Prompt Editor */}
|
|
77
|
-
<EditorCanvas />
|
|
78
|
-
</>
|
|
79
|
-
);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
export default ProfileEditor;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useEditor } from '@lobehub/editor/react';
|
|
4
|
-
import { type PropsWithChildren, memo } from 'react';
|
|
5
|
-
|
|
6
|
-
import StoreUpdater from './StoreUpdater';
|
|
7
|
-
import { Provider, createStore } from './store';
|
|
8
|
-
|
|
9
|
-
const ProfileProvider = memo<PropsWithChildren>(({ children }) => {
|
|
10
|
-
const editor = useEditor();
|
|
11
|
-
|
|
12
|
-
return (
|
|
13
|
-
<Provider createStore={() => createStore({ editor })}>
|
|
14
|
-
<StoreUpdater />
|
|
15
|
-
{children}
|
|
16
|
-
</Provider>
|
|
17
|
-
);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export default ProfileProvider;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useEditorState } from '@lobehub/editor/react';
|
|
4
|
-
import { memo, useEffect } from 'react';
|
|
5
|
-
|
|
6
|
-
import { type PublicState, useProfileStore, useStoreApi } from './store';
|
|
7
|
-
|
|
8
|
-
export type StoreUpdaterProps = Partial<PublicState>;
|
|
9
|
-
|
|
10
|
-
const StoreUpdater = memo<StoreUpdaterProps>(() => {
|
|
11
|
-
const storeApi = useStoreApi();
|
|
12
|
-
|
|
13
|
-
const editor = useProfileStore((s) => s.editor);
|
|
14
|
-
const editorState = useEditorState(editor);
|
|
15
|
-
|
|
16
|
-
// Update editorState in store
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
storeApi.setState({ editorState });
|
|
19
|
-
}, [editorState, storeApi]);
|
|
20
|
-
|
|
21
|
-
return null;
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
export default StoreUpdater;
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { EDITOR_DEBOUNCE_TIME, EDITOR_MAX_WAIT } from '@lobechat/const';
|
|
2
|
-
import { debounce } from 'es-toolkit/compat';
|
|
3
|
-
import { type StateCreator } from 'zustand';
|
|
4
|
-
|
|
5
|
-
import { type State, initialState } from './initialState';
|
|
6
|
-
|
|
7
|
-
type SaveConfigPayload = {
|
|
8
|
-
editorData: Record<string, any>;
|
|
9
|
-
systemRole: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export interface Action {
|
|
13
|
-
/**
|
|
14
|
-
* Append content to streaming buffer (called during streaming)
|
|
15
|
-
*/
|
|
16
|
-
appendStreamingContent: (chunk: string) => void;
|
|
17
|
-
/**
|
|
18
|
-
* Finalize streaming and save to config
|
|
19
|
-
*/
|
|
20
|
-
finishStreaming: (updateConfig: (payload: SaveConfigPayload) => Promise<void>) => Promise<void>;
|
|
21
|
-
flushSave: () => void;
|
|
22
|
-
handleContentChange: (updateConfig: (payload: SaveConfigPayload) => Promise<void>) => void;
|
|
23
|
-
setChatPanelExpanded: (expanded: boolean | ((prev: boolean) => boolean)) => void;
|
|
24
|
-
/**
|
|
25
|
-
* Start streaming mode - clears editor and prepares for streaming content
|
|
26
|
-
*/
|
|
27
|
-
startStreaming: () => void;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type Store = State & Action;
|
|
31
|
-
|
|
32
|
-
// Create debounced save function outside of store for reuse
|
|
33
|
-
const createDebouncedSave = (
|
|
34
|
-
get: () => Store,
|
|
35
|
-
updateConfig: (payload: SaveConfigPayload) => Promise<void>,
|
|
36
|
-
) =>
|
|
37
|
-
debounce(
|
|
38
|
-
async (payload: SaveConfigPayload) => {
|
|
39
|
-
try {
|
|
40
|
-
await updateConfig(payload);
|
|
41
|
-
} catch (error) {
|
|
42
|
-
console.error('[ProfileEditor] Failed to save:', error);
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
EDITOR_DEBOUNCE_TIME,
|
|
46
|
-
{ leading: false, maxWait: EDITOR_MAX_WAIT, trailing: true },
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
export const store: (initState?: Partial<State>) => StateCreator<Store> =
|
|
50
|
-
(initState) => (set, get) => {
|
|
51
|
-
let debouncedSave: ReturnType<typeof createDebouncedSave> | null = null;
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
...initialState,
|
|
55
|
-
...initState,
|
|
56
|
-
|
|
57
|
-
appendStreamingContent: (chunk) => {
|
|
58
|
-
const currentContent = get().streamingContent || '';
|
|
59
|
-
const newContent = currentContent + chunk;
|
|
60
|
-
set({ streamingContent: newContent });
|
|
61
|
-
|
|
62
|
-
// Update editor with streaming content
|
|
63
|
-
const { editor } = get();
|
|
64
|
-
if (editor) {
|
|
65
|
-
try {
|
|
66
|
-
editor.setDocument('markdown', newContent);
|
|
67
|
-
} catch {
|
|
68
|
-
// Ignore errors during streaming updates
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
finishStreaming: async (updateConfig) => {
|
|
74
|
-
const { editor, streamingContent } = get();
|
|
75
|
-
if (!streamingContent) {
|
|
76
|
-
set({ streamingInProgress: false });
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Get the final content from editor
|
|
81
|
-
let finalContent = streamingContent;
|
|
82
|
-
let editorData = {};
|
|
83
|
-
|
|
84
|
-
if (editor) {
|
|
85
|
-
try {
|
|
86
|
-
finalContent =
|
|
87
|
-
(editor.getDocument('markdown') as unknown as string) || streamingContent;
|
|
88
|
-
editorData = editor.getDocument('json') as unknown as Record<string, any>;
|
|
89
|
-
} catch {
|
|
90
|
-
// Use streaming content if editor read fails
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Save to config
|
|
95
|
-
try {
|
|
96
|
-
await updateConfig({
|
|
97
|
-
editorData: structuredClone(editorData || {}),
|
|
98
|
-
systemRole: finalContent,
|
|
99
|
-
});
|
|
100
|
-
} catch (error) {
|
|
101
|
-
console.error('[ProfileEditor] Failed to save streaming content:', error);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Reset streaming state
|
|
105
|
-
set({
|
|
106
|
-
streamingContent: undefined,
|
|
107
|
-
streamingInProgress: false,
|
|
108
|
-
});
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
flushSave: () => {
|
|
112
|
-
debouncedSave?.flush();
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
handleContentChange: (updateConfig) => {
|
|
116
|
-
const { editor } = get();
|
|
117
|
-
if (!editor) return;
|
|
118
|
-
|
|
119
|
-
// Create debounced save on first use
|
|
120
|
-
if (!debouncedSave) {
|
|
121
|
-
debouncedSave = createDebouncedSave(get, updateConfig);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
try {
|
|
125
|
-
const markdownContent = (editor.getDocument('markdown') as unknown as string) || '';
|
|
126
|
-
const jsonContent = editor.getDocument('json') as unknown as Record<string, any>;
|
|
127
|
-
|
|
128
|
-
debouncedSave({
|
|
129
|
-
editorData: structuredClone(jsonContent || {}),
|
|
130
|
-
systemRole: markdownContent || '',
|
|
131
|
-
});
|
|
132
|
-
} catch (error) {
|
|
133
|
-
console.error('[ProfileEditor] Failed to read editor content:', error);
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
|
|
137
|
-
setChatPanelExpanded: (expanded) => {
|
|
138
|
-
if (typeof expanded === 'function') {
|
|
139
|
-
set((state) => ({ chatPanelExpanded: expanded(state.chatPanelExpanded) }));
|
|
140
|
-
} else {
|
|
141
|
-
set({ chatPanelExpanded: expanded });
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
|
|
145
|
-
startStreaming: () => {
|
|
146
|
-
const { editor } = get();
|
|
147
|
-
|
|
148
|
-
// Clear editor content and prepare for streaming
|
|
149
|
-
if (editor) {
|
|
150
|
-
try {
|
|
151
|
-
editor.setDocument('markdown', '');
|
|
152
|
-
} catch {
|
|
153
|
-
// Ignore errors
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
set({
|
|
158
|
-
streamingContent: '',
|
|
159
|
-
streamingInProgress: true,
|
|
160
|
-
});
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
};
|