@nextclaw/ui 0.9.18 → 0.10.1
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 +17 -0
- package/dist/assets/ChannelsList-BX7KqEk7.js +8 -0
- package/dist/assets/ChatPage-zXLBKIAY.js +38 -0
- package/dist/assets/{DocBrowser-DiLg-99Z.js → DocBrowser-Cdbh4cVD.js} +1 -1
- package/dist/assets/{LogoBadge-B0RCYFfk.js → LogoBadge-4801esOJ.js} +1 -1
- package/dist/assets/MarketplacePage-GZgus0Or.js +49 -0
- package/dist/assets/{McpMarketplacePage-C9AxrIdJ.js → McpMarketplacePage-CAGGvoMo.js} +1 -1
- package/dist/assets/{ModelConfig-Cns1fRR4.js → ModelConfig-CfLYjQM3.js} +1 -1
- package/dist/assets/ProvidersList-CEo1kdf-.js +1 -0
- package/dist/assets/{RemoteAccessPage-BVph-WSP.js → RemoteAccessPage-6GYzD7cc.js} +1 -1
- package/dist/assets/{RuntimeConfig-BhBUz1gc.js → RuntimeConfig-BZdbp8mH.js} +1 -1
- package/dist/assets/{SearchConfig-D8t1on1b.js → SearchConfig-ifvYKix-.js} +1 -1
- package/dist/assets/{SecretsConfig-BoOaUo2a.js → SecretsConfig-tDPbhTeR.js} +1 -1
- package/dist/assets/{SessionsConfig-B-LZan9R.js → SessionsConfig-DhkAIzGm.js} +1 -1
- package/dist/assets/{chat-message-C8oGQU2P.js → chat-message-C5Gl-dCH.js} +1 -1
- package/dist/assets/index-BTt_JlNV.css +1 -0
- package/dist/assets/index-JN3V84h_.js +8 -0
- package/dist/assets/{label-D8x2fgJm.js → label-D8zWKdqp.js} +1 -1
- package/dist/assets/{page-layout-Bxdxpr9D.js → page-layout-qAJ47LNQ.js} +1 -1
- package/dist/assets/{popover-Daq39m2s.js → popover-hyBGxpxS.js} +1 -1
- package/dist/assets/{security-config-Bd51WlxA.js → security-config-BJYZSnCA.js} +1 -1
- package/dist/assets/skeleton-CUQLsNsM.js +1 -0
- package/dist/assets/{status-dot-D11eQRlx.js → status-dot-DKcoD-iY.js} +1 -1
- package/dist/assets/{switch-DizAKjZa.js → switch-DtUdQxr_.js} +1 -1
- package/dist/assets/tabs-custom-Dj1BWHGK.js +1 -0
- package/dist/assets/useConfirmDialog-nZdrtETU.js +1 -0
- package/dist/assets/{vendor-DJt0Azq5.js → vendor-CNhxtHCf.js} +1 -1
- package/dist/index.html +3 -3
- package/package.json +4 -4
- package/src/components/chat/ChatSidebar.tsx +41 -69
- package/src/components/chat/adapters/chat-message.adapter.test.ts +141 -163
- package/src/components/chat/adapters/chat-message.adapter.ts +35 -0
- package/src/components/chat/chat-composer-state.ts +38 -0
- package/src/components/chat/chat-stream/types.ts +2 -0
- package/src/components/chat/containers/chat-input-bar.container.tsx +116 -55
- package/src/components/chat/containers/chat-message-list.container.tsx +2 -0
- package/src/components/chat/managers/chat-session-list.manager.test.ts +16 -1
- package/src/components/chat/managers/chat-session-list.manager.ts +0 -2
- package/src/components/chat/managers/chat-thread.manager.ts +0 -1
- package/src/components/chat/ncp/NcpChatPage.tsx +18 -18
- package/src/components/chat/ncp/ncp-chat-input.manager.ts +56 -1
- package/src/components/chat/ncp/ncp-chat-thread.manager.ts +0 -1
- package/src/components/chat/presenter/chat-presenter-context.tsx +6 -0
- package/src/components/chat/stores/chat-input.store.ts +3 -0
- package/src/components/config/ChannelsList.test.tsx +2 -1
- package/src/components/config/channel-form-fields.ts +9 -1
- package/src/components/config/weixin-channel-auth-section.test.tsx +2 -1
- package/src/components/layout/Sidebar.tsx +62 -102
- package/src/components/layout/sidebar-items.tsx +172 -0
- package/src/components/layout/sidebar.layout.test.tsx +11 -4
- package/src/lib/i18n.channels.ts +1 -0
- package/src/lib/i18n.chat.ts +117 -0
- package/src/lib/i18n.remote.ts +1 -1
- package/src/lib/i18n.ts +2 -112
- package/src/transport/remote.transport.test.ts +135 -0
- package/src/transport/remote.transport.ts +11 -1
- package/dist/assets/ChannelsList-BrUyWJt-.js +0 -8
- package/dist/assets/ChatPage-BkVleCOF.js +0 -38
- package/dist/assets/MarketplacePage-CS2QbUvK.js +0 -49
- package/dist/assets/ProvidersList-BeKvkVyz.js +0 -1
- package/dist/assets/index-C63mHRbE.css +0 -1
- package/dist/assets/index-D45Vnh0I.js +0 -8
- package/dist/assets/skeleton-CAcIFczu.js +0 -1
- package/dist/assets/tabs-custom-Daa81i4V.js +0 -1
- package/dist/assets/useConfirmDialog-DS-q2zMX.js +0 -1
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { useMemo, useState } from 'react';
|
|
1
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { ChatInputBar } from '@nextclaw/agent-chat-ui';
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_NCP_IMAGE_ATTACHMENT_ACCEPT,
|
|
5
|
+
DEFAULT_NCP_IMAGE_ATTACHMENT_MAX_BYTES,
|
|
6
|
+
readFilesAsNcpDraftAttachments
|
|
7
|
+
} from '@nextclaw/ncp-react';
|
|
3
8
|
import {
|
|
4
9
|
buildChatSlashItems,
|
|
5
10
|
buildModelStateHint,
|
|
@@ -14,6 +19,7 @@ import { usePresenter } from '@/components/chat/presenter/chat-presenter-context
|
|
|
14
19
|
import { useI18n } from '@/components/providers/I18nProvider';
|
|
15
20
|
import { useChatInputStore } from '@/components/chat/stores/chat-input.store';
|
|
16
21
|
import { t } from '@/lib/i18n';
|
|
22
|
+
import { toast } from 'sonner';
|
|
17
23
|
|
|
18
24
|
function buildThinkingLabels(): Record<ChatThinkingLevel, string> {
|
|
19
25
|
return {
|
|
@@ -70,6 +76,7 @@ export function ChatInputBarContainer() {
|
|
|
70
76
|
const { language } = useI18n();
|
|
71
77
|
const snapshot = useChatInputStore((state) => state.snapshot);
|
|
72
78
|
const [slashQuery, setSlashQuery] = useState<string | null>(null);
|
|
79
|
+
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
|
73
80
|
|
|
74
81
|
const officialSkillBadgeLabel = useMemo(() => {
|
|
75
82
|
// Keep memo reactive to locale switches even though `t` is imported as a stable function.
|
|
@@ -102,6 +109,7 @@ export function ChatInputBarContainer() {
|
|
|
102
109
|
const isModelOptionsEmpty = snapshot.isProviderStateResolved && !hasModelOptions;
|
|
103
110
|
const inputDisabled =
|
|
104
111
|
((isModelOptionsLoading || isModelOptionsEmpty) && !snapshot.isSending) || snapshot.sessionTypeUnavailable;
|
|
112
|
+
const attachmentSupported = typeof presenter.chatInputManager.addAttachments === 'function';
|
|
105
113
|
const textareaPlaceholder = isModelOptionsLoading
|
|
106
114
|
? ''
|
|
107
115
|
: hasModelOptions
|
|
@@ -122,6 +130,33 @@ export function ChatInputBarContainer() {
|
|
|
122
130
|
? t('chatStopPreparing')
|
|
123
131
|
: snapshot.stopDisabledReason?.trim() || t('chatStopUnavailable');
|
|
124
132
|
|
|
133
|
+
const showAttachmentError = useCallback((reason: 'unsupported-type' | 'too-large' | 'read-failed') => {
|
|
134
|
+
if (reason === 'unsupported-type') {
|
|
135
|
+
toast.error(t('chatInputImageUnsupported'));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (reason === 'too-large') {
|
|
139
|
+
toast.error(
|
|
140
|
+
t('chatInputImageTooLarge').replace('{maxMb}', String(DEFAULT_NCP_IMAGE_ATTACHMENT_MAX_BYTES / (1024 * 1024)))
|
|
141
|
+
);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
toast.error(t('chatInputImageReadFailed'));
|
|
145
|
+
}, []);
|
|
146
|
+
|
|
147
|
+
const handleFilesAdd = useCallback(async (files: File[]) => {
|
|
148
|
+
if (!attachmentSupported || files.length === 0) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const result = await readFilesAsNcpDraftAttachments(files);
|
|
152
|
+
if (result.attachments.length > 0) {
|
|
153
|
+
presenter.chatInputManager.addAttachments?.(result.attachments);
|
|
154
|
+
}
|
|
155
|
+
if (result.rejected.length > 0) {
|
|
156
|
+
showAttachmentError(result.rejected[0].reason);
|
|
157
|
+
}
|
|
158
|
+
}, [attachmentSupported, presenter.chatInputManager, showAttachmentError]);
|
|
159
|
+
|
|
125
160
|
const toolbarSelects = [
|
|
126
161
|
buildModelToolbarSelect({
|
|
127
162
|
modelOptions: modelRecords,
|
|
@@ -160,60 +195,86 @@ export function ChatInputBarContainer() {
|
|
|
160
195
|
});
|
|
161
196
|
|
|
162
197
|
return (
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
hint={buildModelStateHint({
|
|
183
|
-
isModelOptionsLoading,
|
|
184
|
-
isModelOptionsEmpty,
|
|
185
|
-
onGoToProviders: presenter.chatInputManager.goToProviders,
|
|
186
|
-
texts: {
|
|
187
|
-
noModelOptionsLabel: t('chatModelNoOptions'),
|
|
188
|
-
configureProviderLabel: t('chatGoConfigureProvider')
|
|
189
|
-
}
|
|
190
|
-
})}
|
|
191
|
-
toolbar={{
|
|
192
|
-
selects: toolbarSelects,
|
|
193
|
-
accessories: [
|
|
194
|
-
{
|
|
195
|
-
key: 'attach',
|
|
196
|
-
label: t('chatInputAttach'),
|
|
197
|
-
icon: 'paperclip',
|
|
198
|
-
iconOnly: true,
|
|
199
|
-
disabled: true,
|
|
200
|
-
tooltip: t('chatInputAttachComingSoon')
|
|
198
|
+
<>
|
|
199
|
+
<ChatInputBar
|
|
200
|
+
composer={{
|
|
201
|
+
nodes: snapshot.composerNodes,
|
|
202
|
+
placeholder: textareaPlaceholder,
|
|
203
|
+
disabled: inputDisabled,
|
|
204
|
+
onNodesChange: presenter.chatInputManager.setComposerNodes,
|
|
205
|
+
...(attachmentSupported ? { onFilesAdd: handleFilesAdd } : {}),
|
|
206
|
+
onSlashQueryChange: setSlashQuery
|
|
207
|
+
}}
|
|
208
|
+
slashMenu={{
|
|
209
|
+
isLoading: snapshot.isSkillsLoading,
|
|
210
|
+
items: slashItems,
|
|
211
|
+
texts: {
|
|
212
|
+
slashLoadingLabel: t('chatSlashLoading'),
|
|
213
|
+
slashSectionLabel: t('chatSlashSectionSkills'),
|
|
214
|
+
slashEmptyLabel: t('chatSlashNoResult'),
|
|
215
|
+
slashHintLabel: t('chatSlashHint'),
|
|
216
|
+
slashSkillHintLabel: t('chatSlashSkillHint')
|
|
201
217
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
+
}}
|
|
219
|
+
hint={buildModelStateHint({
|
|
220
|
+
isModelOptionsLoading,
|
|
221
|
+
isModelOptionsEmpty,
|
|
222
|
+
onGoToProviders: presenter.chatInputManager.goToProviders,
|
|
223
|
+
texts: {
|
|
224
|
+
noModelOptionsLabel: t('chatModelNoOptions'),
|
|
225
|
+
configureProviderLabel: t('chatGoConfigureProvider')
|
|
226
|
+
}
|
|
227
|
+
})}
|
|
228
|
+
toolbar={{
|
|
229
|
+
selects: toolbarSelects,
|
|
230
|
+
accessories: [
|
|
231
|
+
{
|
|
232
|
+
key: 'attach',
|
|
233
|
+
label: t('chatInputAttach'),
|
|
234
|
+
icon: 'paperclip',
|
|
235
|
+
iconOnly: true,
|
|
236
|
+
disabled: !attachmentSupported || inputDisabled || snapshot.isSending,
|
|
237
|
+
...(attachmentSupported
|
|
238
|
+
? {
|
|
239
|
+
onClick: () => fileInputRef.current?.click()
|
|
240
|
+
}
|
|
241
|
+
: {
|
|
242
|
+
tooltip: t('chatInputAttachComingSoon')
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
],
|
|
246
|
+
skillPicker,
|
|
247
|
+
actions: {
|
|
248
|
+
sendError: snapshot.sendError,
|
|
249
|
+
isSending: snapshot.isSending,
|
|
250
|
+
canStopGeneration: snapshot.canStopGeneration,
|
|
251
|
+
sendDisabled:
|
|
252
|
+
(snapshot.draft.trim().length === 0 && snapshot.attachments.length === 0) ||
|
|
253
|
+
!hasModelOptions ||
|
|
254
|
+
snapshot.sessionTypeUnavailable,
|
|
255
|
+
stopDisabled: !snapshot.canStopGeneration,
|
|
256
|
+
stopHint: resolvedStopHint,
|
|
257
|
+
sendButtonLabel: t('chatSend'),
|
|
258
|
+
stopButtonLabel: t('chatStop'),
|
|
259
|
+
onSend: presenter.chatInputManager.send,
|
|
260
|
+
onStop: presenter.chatInputManager.stop
|
|
261
|
+
}
|
|
262
|
+
}}
|
|
263
|
+
/>
|
|
264
|
+
{attachmentSupported ? (
|
|
265
|
+
<input
|
|
266
|
+
ref={fileInputRef}
|
|
267
|
+
type="file"
|
|
268
|
+
accept={DEFAULT_NCP_IMAGE_ATTACHMENT_ACCEPT}
|
|
269
|
+
multiple
|
|
270
|
+
className="hidden"
|
|
271
|
+
onChange={async (event) => {
|
|
272
|
+
const files = Array.from(event.target.files ?? []);
|
|
273
|
+
event.currentTarget.value = '';
|
|
274
|
+
await handleFilesAdd(files);
|
|
275
|
+
}}
|
|
276
|
+
/>
|
|
277
|
+
) : null}
|
|
278
|
+
</>
|
|
218
279
|
);
|
|
219
280
|
}
|
|
@@ -48,6 +48,8 @@ export function ChatMessageListContainer(props: ChatMessageListContainerProps) {
|
|
|
48
48
|
toolResultLabel: t("chatToolResult"),
|
|
49
49
|
toolNoOutputLabel: t("chatToolNoOutput"),
|
|
50
50
|
toolOutputLabel: t("chatToolOutput"),
|
|
51
|
+
imageAttachmentLabel: t("chatImageAttachment"),
|
|
52
|
+
fileAttachmentLabel: t("chatFileAttachment"),
|
|
51
53
|
unknownPartLabel: t("chatUnknownPart"),
|
|
52
54
|
},
|
|
53
55
|
}),
|
|
@@ -33,7 +33,22 @@ describe('ChatSessionListManager', () => {
|
|
|
33
33
|
|
|
34
34
|
expect(streamActionsManager.resetStreamState).toHaveBeenCalledTimes(1);
|
|
35
35
|
expect(uiManager.goToChatRoot).toHaveBeenCalledTimes(1);
|
|
36
|
-
expect(useChatSessionListStore.getState().snapshot.selectedSessionKey).
|
|
36
|
+
expect(useChatSessionListStore.getState().snapshot.selectedSessionKey).toBe('session-1');
|
|
37
37
|
expect(useChatInputStore.getState().snapshot.pendingSessionType).toBe('codex');
|
|
38
38
|
});
|
|
39
|
+
|
|
40
|
+
it('delegates existing-session selection to routing without eagerly mutating the selected session state', () => {
|
|
41
|
+
const uiManager = {
|
|
42
|
+
goToSession: vi.fn()
|
|
43
|
+
} as unknown as ConstructorParameters<typeof ChatSessionListManager>[0];
|
|
44
|
+
const streamActionsManager = {
|
|
45
|
+
resetStreamState: vi.fn()
|
|
46
|
+
} as unknown as ConstructorParameters<typeof ChatSessionListManager>[1];
|
|
47
|
+
|
|
48
|
+
const manager = new ChatSessionListManager(uiManager, streamActionsManager);
|
|
49
|
+
manager.selectSession('session-2');
|
|
50
|
+
|
|
51
|
+
expect(uiManager.goToSession).toHaveBeenCalledWith('session-2');
|
|
52
|
+
expect(useChatSessionListStore.getState().snapshot.selectedSessionKey).toBe('session-1');
|
|
53
|
+
});
|
|
39
54
|
});
|
|
@@ -62,13 +62,11 @@ export class ChatSessionListManager {
|
|
|
62
62
|
? sessionType.trim()
|
|
63
63
|
: defaultSessionType;
|
|
64
64
|
this.streamActionsManager.resetStreamState();
|
|
65
|
-
this.setSelectedSessionKey(null);
|
|
66
65
|
useChatInputStore.getState().setSnapshot({ pendingSessionType: nextSessionType });
|
|
67
66
|
this.uiManager.goToChatRoot();
|
|
68
67
|
};
|
|
69
68
|
|
|
70
69
|
selectSession = (sessionKey: string) => {
|
|
71
|
-
this.setSelectedSessionKey(sessionKey);
|
|
72
70
|
this.uiManager.goToSession(sessionKey);
|
|
73
71
|
};
|
|
74
72
|
|
|
@@ -78,7 +78,6 @@ export class ChatThreadManager {
|
|
|
78
78
|
try {
|
|
79
79
|
await deleteSessionApi(selectedSessionKey);
|
|
80
80
|
this.streamActionsManager.resetStreamState();
|
|
81
|
-
useChatSessionListStore.getState().setSnapshot({ selectedSessionKey: null });
|
|
82
81
|
this.uiManager.goToChatRoot({ replace: true });
|
|
83
82
|
await this.actions.refetchSessions();
|
|
84
83
|
} finally {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { NcpHttpAgentClientEndpoint } from '@nextclaw/ncp-http-agent-client';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
buildNcpRequestEnvelope,
|
|
5
|
+
useHydratedNcpAgent,
|
|
6
|
+
type NcpConversationSeed
|
|
7
|
+
} from '@nextclaw/ncp-react';
|
|
4
8
|
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
|
5
9
|
import { API_BASE } from '@/api/api-base';
|
|
6
10
|
import { fetchNcpSessionMessages } from '@/api/ncp-session';
|
|
@@ -186,29 +190,25 @@ export function NcpChatPage({ view }: ChatPageProps) {
|
|
|
186
190
|
sessionType: payload.sessionType,
|
|
187
191
|
requestedSkills: payload.requestedSkills
|
|
188
192
|
});
|
|
193
|
+
const envelope = buildNcpRequestEnvelope({
|
|
194
|
+
sessionId: payload.sessionKey,
|
|
195
|
+
text: payload.message,
|
|
196
|
+
attachments: payload.attachments,
|
|
197
|
+
metadata
|
|
198
|
+
});
|
|
199
|
+
if (!envelope) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
189
202
|
try {
|
|
190
203
|
void sessionsQuery.refetch();
|
|
191
|
-
await agent.send(
|
|
192
|
-
sessionId: payload.sessionKey,
|
|
193
|
-
message: {
|
|
194
|
-
id: `user-${Date.now().toString(36)}`,
|
|
195
|
-
sessionId: payload.sessionKey,
|
|
196
|
-
role: 'user',
|
|
197
|
-
status: 'final',
|
|
198
|
-
parts: [{ type: 'text', text: payload.message }],
|
|
199
|
-
timestamp: new Date().toISOString(),
|
|
200
|
-
...(Object.keys(metadata).length > 0 ? { metadata } : {})
|
|
201
|
-
},
|
|
202
|
-
...(Object.keys(metadata).length > 0 ? { metadata } : {})
|
|
203
|
-
});
|
|
204
|
+
await agent.send(envelope);
|
|
204
205
|
await sessionsQuery.refetch();
|
|
205
206
|
} catch (error) {
|
|
206
207
|
if (payload.restoreDraftOnError) {
|
|
207
208
|
if (payload.composerNodes && payload.composerNodes.length > 0) {
|
|
208
|
-
presenter.chatInputManager.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
: currentNodes
|
|
209
|
+
presenter.chatInputManager.restoreComposerState?.(
|
|
210
|
+
payload.composerNodes,
|
|
211
|
+
payload.attachments ?? []
|
|
212
212
|
);
|
|
213
213
|
} else {
|
|
214
214
|
presenter.chatInputManager.setDraft((currentDraft) =>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ChatComposerNode } from '@nextclaw/agent-chat-ui';
|
|
2
|
+
import type { NcpDraftAttachment } from '@nextclaw/ncp-react';
|
|
2
3
|
import type { SetStateAction } from 'react';
|
|
3
4
|
import type { ThinkingLevel } from '@/api/types';
|
|
4
5
|
import { updateNcpSession } from '@/api/ncp-session';
|
|
@@ -7,6 +8,8 @@ import {
|
|
|
7
8
|
createInitialChatComposerNodes,
|
|
8
9
|
deriveChatComposerDraft,
|
|
9
10
|
deriveSelectedSkillsFromComposer,
|
|
11
|
+
pruneComposerAttachments,
|
|
12
|
+
syncComposerAttachments,
|
|
10
13
|
syncComposerSkills
|
|
11
14
|
} from '@/components/chat/chat-composer-state';
|
|
12
15
|
import { useChatInputStore } from '@/components/chat/stores/chat-input.store';
|
|
@@ -48,13 +51,47 @@ export class NcpChatInputManager {
|
|
|
48
51
|
left.length === right.length && left.every((value, index) => value === right[index]);
|
|
49
52
|
|
|
50
53
|
private syncComposerSnapshot = (nodes: ChatComposerNode[]) => {
|
|
54
|
+
const currentAttachments = useChatInputStore.getState().snapshot.attachments;
|
|
55
|
+
const attachments = pruneComposerAttachments(nodes, currentAttachments);
|
|
51
56
|
useChatInputStore.getState().setSnapshot({
|
|
52
57
|
composerNodes: nodes,
|
|
58
|
+
attachments,
|
|
53
59
|
draft: deriveChatComposerDraft(nodes),
|
|
54
60
|
selectedSkills: deriveSelectedSkillsFromComposer(nodes)
|
|
55
61
|
});
|
|
56
62
|
};
|
|
57
63
|
|
|
64
|
+
private syncComposerSnapshotWithAttachments = (
|
|
65
|
+
nodes: ChatComposerNode[],
|
|
66
|
+
attachments: NcpDraftAttachment[]
|
|
67
|
+
) => {
|
|
68
|
+
useChatInputStore.getState().setSnapshot({
|
|
69
|
+
composerNodes: nodes,
|
|
70
|
+
attachments,
|
|
71
|
+
draft: deriveChatComposerDraft(nodes),
|
|
72
|
+
selectedSkills: deriveSelectedSkillsFromComposer(nodes)
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
private dedupeAttachments = (attachments: NcpDraftAttachment[]): NcpDraftAttachment[] => {
|
|
77
|
+
const seen = new Set<string>();
|
|
78
|
+
const output: NcpDraftAttachment[] = [];
|
|
79
|
+
for (const attachment of attachments) {
|
|
80
|
+
const signature = [
|
|
81
|
+
attachment.name,
|
|
82
|
+
attachment.mimeType,
|
|
83
|
+
String(attachment.sizeBytes),
|
|
84
|
+
attachment.contentBase64,
|
|
85
|
+
].join(':');
|
|
86
|
+
if (seen.has(signature)) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
seen.add(signature);
|
|
90
|
+
output.push(attachment);
|
|
91
|
+
}
|
|
92
|
+
return output;
|
|
93
|
+
};
|
|
94
|
+
|
|
58
95
|
syncSnapshot = (patch: Partial<ChatInputSnapshot>) => {
|
|
59
96
|
if (!this.hasSnapshotChanges(patch)) {
|
|
60
97
|
return;
|
|
@@ -88,6 +125,22 @@ export class NcpChatInputManager {
|
|
|
88
125
|
this.syncComposerSnapshot(value);
|
|
89
126
|
};
|
|
90
127
|
|
|
128
|
+
addAttachments = (attachments: NcpDraftAttachment[]) => {
|
|
129
|
+
if (attachments.length === 0) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const snapshot = useChatInputStore.getState().snapshot;
|
|
133
|
+
const nextAttachments = this.dedupeAttachments([...snapshot.attachments, ...attachments]);
|
|
134
|
+
const nextNodes = syncComposerAttachments(snapshot.composerNodes, nextAttachments);
|
|
135
|
+
this.syncComposerSnapshotWithAttachments(nextNodes, nextAttachments);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
restoreComposerState = (nodes: ChatComposerNode[], attachments: NcpDraftAttachment[]) => {
|
|
139
|
+
const nextAttachments = this.dedupeAttachments(attachments);
|
|
140
|
+
const nextNodes = syncComposerAttachments(nodes, nextAttachments);
|
|
141
|
+
this.syncComposerSnapshotWithAttachments(nextNodes, nextAttachments);
|
|
142
|
+
};
|
|
143
|
+
|
|
91
144
|
setPendingSessionType = (next: SetStateAction<string>) => {
|
|
92
145
|
const prev = useChatInputStore.getState().snapshot.pendingSessionType;
|
|
93
146
|
const value = this.resolveUpdateValue(prev, next);
|
|
@@ -101,7 +154,8 @@ export class NcpChatInputManager {
|
|
|
101
154
|
const inputSnapshot = useChatInputStore.getState().snapshot;
|
|
102
155
|
const sessionSnapshot = useChatSessionListStore.getState().snapshot;
|
|
103
156
|
const message = inputSnapshot.draft.trim();
|
|
104
|
-
|
|
157
|
+
const attachments = inputSnapshot.attachments;
|
|
158
|
+
if (!message && attachments.length === 0) {
|
|
105
159
|
return;
|
|
106
160
|
}
|
|
107
161
|
const { selectedSkills: requestedSkills, composerNodes } = inputSnapshot;
|
|
@@ -119,6 +173,7 @@ export class NcpChatInputManager {
|
|
|
119
173
|
thinkingLevel: inputSnapshot.selectedThinkingLevel ?? undefined,
|
|
120
174
|
stopSupported: true,
|
|
121
175
|
requestedSkills,
|
|
176
|
+
attachments,
|
|
122
177
|
restoreDraftOnError: true,
|
|
123
178
|
composerNodes
|
|
124
179
|
});
|
|
@@ -79,7 +79,6 @@ export class NcpChatThreadManager {
|
|
|
79
79
|
try {
|
|
80
80
|
await deleteNcpSessionApi(selectedSessionKey);
|
|
81
81
|
this.streamActionsManager.resetStreamState();
|
|
82
|
-
useChatSessionListStore.getState().setSnapshot({ selectedSessionKey: null });
|
|
83
82
|
this.uiManager.goToChatRoot({ replace: true });
|
|
84
83
|
await this.actions.refetchSessions();
|
|
85
84
|
} finally {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ChatComposerNode } from '@nextclaw/agent-chat-ui';
|
|
2
|
+
import type { NcpDraftAttachment } from '@nextclaw/ncp-react';
|
|
2
3
|
import { createContext, useContext } from 'react';
|
|
3
4
|
import type { ReactNode } from 'react';
|
|
4
5
|
import type { SetStateAction } from 'react';
|
|
@@ -13,6 +14,11 @@ export type ChatInputManagerLike = {
|
|
|
13
14
|
syncSnapshot: (patch: Record<string, unknown>) => void;
|
|
14
15
|
setDraft: (next: SetStateAction<string>) => void;
|
|
15
16
|
setComposerNodes: (next: SetStateAction<ChatComposerNode[]>) => void;
|
|
17
|
+
addAttachments?: (attachments: NcpDraftAttachment[]) => void;
|
|
18
|
+
restoreComposerState?: (
|
|
19
|
+
nodes: ChatComposerNode[],
|
|
20
|
+
attachments: NcpDraftAttachment[]
|
|
21
|
+
) => void;
|
|
16
22
|
setPendingSessionType: (next: SetStateAction<string>) => void;
|
|
17
23
|
send: () => Promise<void>;
|
|
18
24
|
stop: () => Promise<void>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { create } from 'zustand';
|
|
2
2
|
import type { ChatComposerNode } from '@nextclaw/agent-chat-ui';
|
|
3
|
+
import type { NcpDraftAttachment } from '@nextclaw/ncp-react';
|
|
3
4
|
import type { MarketplaceInstalledRecord } from '@/api/types';
|
|
4
5
|
import type { ThinkingLevel } from '@/api/types';
|
|
5
6
|
import type { ChatModelOption } from '@/components/chat/chat-input.types';
|
|
@@ -8,6 +9,7 @@ import { createInitialChatComposerNodes } from '@/components/chat/chat-composer-
|
|
|
8
9
|
export type ChatInputSnapshot = {
|
|
9
10
|
isProviderStateResolved: boolean;
|
|
10
11
|
composerNodes: ChatComposerNode[];
|
|
12
|
+
attachments: NcpDraftAttachment[];
|
|
11
13
|
draft: string;
|
|
12
14
|
pendingSessionType: string;
|
|
13
15
|
defaultSessionType: string;
|
|
@@ -50,6 +52,7 @@ type ChatInputStore = {
|
|
|
50
52
|
const initialSnapshot: ChatInputSnapshot = {
|
|
51
53
|
isProviderStateResolved: false,
|
|
52
54
|
composerNodes: createInitialChatComposerNodes(),
|
|
55
|
+
attachments: [],
|
|
53
56
|
draft: '',
|
|
54
57
|
pendingSessionType: 'native',
|
|
55
58
|
defaultSessionType: 'native',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
2
2
|
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import type * as ReactQueryModule from '@tanstack/react-query';
|
|
3
4
|
import { ChannelsList } from '@/components/config/ChannelsList';
|
|
4
5
|
|
|
5
6
|
const mocks = vi.hoisted(() => ({
|
|
@@ -58,7 +59,7 @@ vi.mock('qrcode', () => ({
|
|
|
58
59
|
}));
|
|
59
60
|
|
|
60
61
|
vi.mock('@tanstack/react-query', async () => {
|
|
61
|
-
const actual = await vi.importActual<typeof
|
|
62
|
+
const actual = await vi.importActual<typeof ReactQueryModule>('@tanstack/react-query');
|
|
62
63
|
return {
|
|
63
64
|
...actual,
|
|
64
65
|
useQueryClient: () => ({
|
|
@@ -70,7 +70,15 @@ export function buildChannelFields(): Record<string, ChannelField[]> {
|
|
|
70
70
|
{ name: 'appSecret', type: 'password', label: t('appSecret') },
|
|
71
71
|
{ name: 'encryptKey', type: 'password', label: t('encryptKey') },
|
|
72
72
|
{ name: 'verificationToken', type: 'password', label: t('verificationToken') },
|
|
73
|
-
{ name: '
|
|
73
|
+
{ name: 'domain', type: 'text', label: 'Domain' },
|
|
74
|
+
{ name: 'allowFrom', type: 'tags', label: t('allowFrom') },
|
|
75
|
+
{ name: 'dmPolicy', type: 'select', label: t('dmPolicy'), options: DM_POLICY_OPTIONS },
|
|
76
|
+
{ name: 'groupPolicy', type: 'select', label: t('groupPolicy'), options: GROUP_POLICY_OPTIONS },
|
|
77
|
+
{ name: 'groupAllowFrom', type: 'tags', label: t('groupAllowFrom') },
|
|
78
|
+
{ name: 'requireMention', type: 'boolean', label: t('requireMention') },
|
|
79
|
+
{ name: 'mentionPatterns', type: 'tags', label: t('mentionPatterns') },
|
|
80
|
+
{ name: 'groups', type: 'json', label: t('groupRulesJson') },
|
|
81
|
+
{ name: 'accounts', type: 'json', label: t('accountsJson') }
|
|
74
82
|
],
|
|
75
83
|
dingtalk: [
|
|
76
84
|
{ name: 'enabled', type: 'boolean', label: t('enabled') },
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
2
|
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import type * as ReactQueryModule from '@tanstack/react-query';
|
|
3
4
|
import { WeixinChannelAuthSection } from './weixin-channel-auth-section';
|
|
4
5
|
|
|
5
6
|
const mocks = vi.hoisted(() => ({
|
|
@@ -9,7 +10,7 @@ const mocks = vi.hoisted(() => ({
|
|
|
9
10
|
}));
|
|
10
11
|
|
|
11
12
|
vi.mock('@tanstack/react-query', async () => {
|
|
12
|
-
const actual = await vi.importActual<typeof
|
|
13
|
+
const actual = await vi.importActual<typeof ReactQueryModule>('@tanstack/react-query');
|
|
13
14
|
return {
|
|
14
15
|
...actual,
|
|
15
16
|
useQueryClient: () => ({
|