@zero-library/chat-agent 2.1.5 → 2.1.7
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/dist/index.cjs.js +170 -154
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +18 -8
- package/dist/index.d.ts +18 -8
- package/dist/index.esm.js +173 -157
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { RenderControl, UserInfo } from '@zero-library/common';
|
|
2
|
+
import { ButtonProps, ThemeConfig } from 'antd';
|
|
2
3
|
import * as react from 'react';
|
|
3
4
|
import { Conversation } from '@ant-design/x';
|
|
4
|
-
import { ThemeConfig } from 'antd';
|
|
5
|
-
|
|
6
|
-
type ConversationMemberEnum = 'agent' | 'user' | 'other';
|
|
7
5
|
|
|
8
6
|
interface InputFile {
|
|
9
7
|
/**
|
|
@@ -242,6 +240,8 @@ interface AgentInfo {
|
|
|
242
240
|
feature?: string;
|
|
243
241
|
}
|
|
244
242
|
|
|
243
|
+
type ConversationMemberEnum = 'agent' | 'user' | 'other';
|
|
244
|
+
|
|
245
245
|
type ConversationStrategy = 1 | 2;
|
|
246
246
|
interface ReferencesContent extends MessageQuoteMsg {
|
|
247
247
|
name?: string;
|
|
@@ -261,7 +261,7 @@ interface ChatHooks {
|
|
|
261
261
|
onBeforeSend?: (message: ConversationMessageSend['msgContent'], files: InputFile[]) => boolean | Promise<boolean> | void;
|
|
262
262
|
onAfterSend?: () => void;
|
|
263
263
|
onBeforeSwitchAgent?: (agentId: string) => boolean | Promise<boolean> | void;
|
|
264
|
-
onAfterSwitchAgent?: (
|
|
264
|
+
onAfterSwitchAgent?: (agent: AgentInfo) => void;
|
|
265
265
|
onBeforeSwitchConversation?: (conversationId: string) => boolean | Promise<boolean> | void;
|
|
266
266
|
onAfterSwitchConversation?: (conversationId: string) => void;
|
|
267
267
|
onBeforeInitMessages?: (conversationId: string) => boolean | Promise<boolean> | void;
|
|
@@ -290,6 +290,9 @@ interface ChatLayoutSender {
|
|
|
290
290
|
placeholder?: string;
|
|
291
291
|
extraBtn?: RenderControl<void, void>;
|
|
292
292
|
referencesBtn?: RenderControl<void, void>;
|
|
293
|
+
footerBelow?: RenderControl<void, void>;
|
|
294
|
+
sendBtnProps?: ButtonProps;
|
|
295
|
+
prompts?: boolean;
|
|
293
296
|
}
|
|
294
297
|
interface ChatLayoutMessageList {
|
|
295
298
|
avatar?: boolean | Partial<Record<ConversationMemberEnum, boolean>>;
|
|
@@ -302,13 +305,18 @@ interface ChatLayout {
|
|
|
302
305
|
messageList?: RenderControl<void, ChatLayoutMessageList>;
|
|
303
306
|
senderHeader?: RenderControl<void, void>;
|
|
304
307
|
sender?: RenderControl<void, ChatLayoutSender>;
|
|
305
|
-
senderPrompts?: boolean;
|
|
306
308
|
senderFooter?: RenderControl<void, void>;
|
|
307
309
|
globalHeader?: RenderControl<void, ChatLayoutHeader>;
|
|
308
310
|
chatHeader?: RenderControl<void, ChatLayoutHeader>;
|
|
309
311
|
disclaimerNotice?: RenderControl<void, void>;
|
|
310
312
|
}
|
|
311
313
|
|
|
314
|
+
interface ChatSenderHandle {
|
|
315
|
+
focus: (options?: {
|
|
316
|
+
cursor?: 'start' | 'end';
|
|
317
|
+
}) => void;
|
|
318
|
+
}
|
|
319
|
+
|
|
312
320
|
interface ChatConfig {
|
|
313
321
|
receiverType?: number;
|
|
314
322
|
receiverId?: string;
|
|
@@ -325,13 +333,15 @@ interface Props {
|
|
|
325
333
|
}
|
|
326
334
|
interface ChatHandle {
|
|
327
335
|
sendMessage: (message?: string, files?: InputFile[]) => void;
|
|
328
|
-
switchAgentConversation: (agentId: AgentInfo['id'], strategy?: ConversationStrategy) => void
|
|
329
|
-
switchConversation: (id?: Conversation['id']) => void
|
|
336
|
+
switchAgentConversation: (agentId: AgentInfo['id'], strategy?: ConversationStrategy) => Promise<void>;
|
|
337
|
+
switchConversation: (id?: Conversation['id']) => Promise<void>;
|
|
330
338
|
createConversation: () => Promise<void>;
|
|
331
339
|
setReferences: (references?: ReferencesType) => void;
|
|
332
340
|
setMessage: (message?: string) => void;
|
|
333
341
|
setFiles: (files?: InputFile[]) => void;
|
|
342
|
+
setParams: (params?: ChatParams) => void;
|
|
343
|
+
senderFocus: ChatSenderHandle['focus'];
|
|
334
344
|
}
|
|
335
345
|
declare const _default: react.ForwardRefExoticComponent<Props & react.RefAttributes<ChatHandle>>;
|
|
336
346
|
|
|
337
|
-
export { type ChatConfig, _default as ChatCopilot, type ChatHandle, type ChatLayout };
|
|
347
|
+
export { type AgentInfo, type ChatConfig, _default as ChatCopilot, type ChatHandle, type ChatLayout, type InputFile };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { RenderControl, UserInfo } from '@zero-library/common';
|
|
2
|
+
import { ButtonProps, ThemeConfig } from 'antd';
|
|
2
3
|
import * as react from 'react';
|
|
3
4
|
import { Conversation } from '@ant-design/x';
|
|
4
|
-
import { ThemeConfig } from 'antd';
|
|
5
|
-
|
|
6
|
-
type ConversationMemberEnum = 'agent' | 'user' | 'other';
|
|
7
5
|
|
|
8
6
|
interface InputFile {
|
|
9
7
|
/**
|
|
@@ -242,6 +240,8 @@ interface AgentInfo {
|
|
|
242
240
|
feature?: string;
|
|
243
241
|
}
|
|
244
242
|
|
|
243
|
+
type ConversationMemberEnum = 'agent' | 'user' | 'other';
|
|
244
|
+
|
|
245
245
|
type ConversationStrategy = 1 | 2;
|
|
246
246
|
interface ReferencesContent extends MessageQuoteMsg {
|
|
247
247
|
name?: string;
|
|
@@ -261,7 +261,7 @@ interface ChatHooks {
|
|
|
261
261
|
onBeforeSend?: (message: ConversationMessageSend['msgContent'], files: InputFile[]) => boolean | Promise<boolean> | void;
|
|
262
262
|
onAfterSend?: () => void;
|
|
263
263
|
onBeforeSwitchAgent?: (agentId: string) => boolean | Promise<boolean> | void;
|
|
264
|
-
onAfterSwitchAgent?: (
|
|
264
|
+
onAfterSwitchAgent?: (agent: AgentInfo) => void;
|
|
265
265
|
onBeforeSwitchConversation?: (conversationId: string) => boolean | Promise<boolean> | void;
|
|
266
266
|
onAfterSwitchConversation?: (conversationId: string) => void;
|
|
267
267
|
onBeforeInitMessages?: (conversationId: string) => boolean | Promise<boolean> | void;
|
|
@@ -290,6 +290,9 @@ interface ChatLayoutSender {
|
|
|
290
290
|
placeholder?: string;
|
|
291
291
|
extraBtn?: RenderControl<void, void>;
|
|
292
292
|
referencesBtn?: RenderControl<void, void>;
|
|
293
|
+
footerBelow?: RenderControl<void, void>;
|
|
294
|
+
sendBtnProps?: ButtonProps;
|
|
295
|
+
prompts?: boolean;
|
|
293
296
|
}
|
|
294
297
|
interface ChatLayoutMessageList {
|
|
295
298
|
avatar?: boolean | Partial<Record<ConversationMemberEnum, boolean>>;
|
|
@@ -302,13 +305,18 @@ interface ChatLayout {
|
|
|
302
305
|
messageList?: RenderControl<void, ChatLayoutMessageList>;
|
|
303
306
|
senderHeader?: RenderControl<void, void>;
|
|
304
307
|
sender?: RenderControl<void, ChatLayoutSender>;
|
|
305
|
-
senderPrompts?: boolean;
|
|
306
308
|
senderFooter?: RenderControl<void, void>;
|
|
307
309
|
globalHeader?: RenderControl<void, ChatLayoutHeader>;
|
|
308
310
|
chatHeader?: RenderControl<void, ChatLayoutHeader>;
|
|
309
311
|
disclaimerNotice?: RenderControl<void, void>;
|
|
310
312
|
}
|
|
311
313
|
|
|
314
|
+
interface ChatSenderHandle {
|
|
315
|
+
focus: (options?: {
|
|
316
|
+
cursor?: 'start' | 'end';
|
|
317
|
+
}) => void;
|
|
318
|
+
}
|
|
319
|
+
|
|
312
320
|
interface ChatConfig {
|
|
313
321
|
receiverType?: number;
|
|
314
322
|
receiverId?: string;
|
|
@@ -325,13 +333,15 @@ interface Props {
|
|
|
325
333
|
}
|
|
326
334
|
interface ChatHandle {
|
|
327
335
|
sendMessage: (message?: string, files?: InputFile[]) => void;
|
|
328
|
-
switchAgentConversation: (agentId: AgentInfo['id'], strategy?: ConversationStrategy) => void
|
|
329
|
-
switchConversation: (id?: Conversation['id']) => void
|
|
336
|
+
switchAgentConversation: (agentId: AgentInfo['id'], strategy?: ConversationStrategy) => Promise<void>;
|
|
337
|
+
switchConversation: (id?: Conversation['id']) => Promise<void>;
|
|
330
338
|
createConversation: () => Promise<void>;
|
|
331
339
|
setReferences: (references?: ReferencesType) => void;
|
|
332
340
|
setMessage: (message?: string) => void;
|
|
333
341
|
setFiles: (files?: InputFile[]) => void;
|
|
342
|
+
setParams: (params?: ChatParams) => void;
|
|
343
|
+
senderFocus: ChatSenderHandle['focus'];
|
|
334
344
|
}
|
|
335
345
|
declare const _default: react.ForwardRefExoticComponent<Props & react.RefAttributes<ChatHandle>>;
|
|
336
346
|
|
|
337
|
-
export { type ChatConfig, _default as ChatCopilot, type ChatHandle, type ChatLayout };
|
|
347
|
+
export { type AgentInfo, type ChatConfig, _default as ChatCopilot, type ChatHandle, type ChatLayout, type InputFile };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useRefState, useDebounce, useSyncInput,
|
|
2
|
-
import { App, Badge, Button, Flex, Spin, Splitter, Tag,
|
|
1
|
+
import { useRefState, useDebounce, useSyncInput, RenderWrapper, shouldRender, useDeepEffect, useWebSocket, getWebSocketUrl, getToken, isLocalhost, downloadFile, FilePreview, MarkdownEditor, useCreateValtioContext, isNumber, getFileSuffixName, isObject, isNullOrUnDef, isBoolean, UserAvatar, request, deepCopy, getCurrentUser, deepMerge, RenderMarkdown, copyText, FileIcon, isExternal } from '@zero-library/common';
|
|
2
|
+
import { App, Badge, Button, Flex, Typography, Spin, Splitter, Tag, Popover, List, Avatar, Space, message, Empty, Collapse, Modal, Row, Col, Drawer } from 'antd';
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import { forwardRef, useRef, useEffect, useImperativeHandle, useMemo, useState } from 'react';
|
|
6
|
-
import { CloudUploadOutlined, PaperClipOutlined, CloseOutlined, PlusOutlined, CommentOutlined, OpenAIOutlined, CopyOutlined, LikeOutlined, DislikeOutlined,
|
|
6
|
+
import { CloudUploadOutlined, PaperClipOutlined, EnterOutlined, UserSwitchOutlined, CloseOutlined, PlusOutlined, CommentOutlined, OpenAIOutlined, CopyOutlined, LikeOutlined, DislikeOutlined, DeleteOutlined, RedoOutlined, PlayCircleOutlined, CaretRightOutlined } from '@ant-design/icons';
|
|
7
7
|
import { Attachments, Sender, Suggestion, XProvider, Welcome, Prompts, Bubble, Conversations } from '@ant-design/x';
|
|
8
8
|
import classNames7 from 'classnames';
|
|
9
9
|
import { useSnapshot, proxy } from 'valtio';
|
|
@@ -357,7 +357,6 @@ var defaultAgentLayout = {
|
|
|
357
357
|
firstMessage: false,
|
|
358
358
|
senderHeader: false,
|
|
359
359
|
sender: true,
|
|
360
|
-
senderPrompts: true,
|
|
361
360
|
senderFooter: false,
|
|
362
361
|
globalHeader: false,
|
|
363
362
|
chatHeader: true,
|
|
@@ -370,8 +369,11 @@ var defaultExpertLayout = {
|
|
|
370
369
|
messageList: true,
|
|
371
370
|
firstMessage: false,
|
|
372
371
|
senderHeader: false,
|
|
373
|
-
sender:
|
|
374
|
-
|
|
372
|
+
sender: {
|
|
373
|
+
props: {
|
|
374
|
+
prompts: false
|
|
375
|
+
}
|
|
376
|
+
},
|
|
375
377
|
senderFooter: false,
|
|
376
378
|
globalHeader: false,
|
|
377
379
|
chatHeader: {
|
|
@@ -417,7 +419,7 @@ function createChatStore() {
|
|
|
417
419
|
const defaultLayout = receiverType === 3 ? defaultAgentLayout : defaultExpertLayout;
|
|
418
420
|
config.layout = deepMerge(defaultLayout, layout);
|
|
419
421
|
};
|
|
420
|
-
const
|
|
422
|
+
const setParams = (params = {}) => {
|
|
421
423
|
config.params = { ...params };
|
|
422
424
|
};
|
|
423
425
|
const setHooks = (hooks = {}) => {
|
|
@@ -449,7 +451,9 @@ function createChatStore() {
|
|
|
449
451
|
const switchAgent = async (agentId) => {
|
|
450
452
|
if (receiver.active.id === agentId) return;
|
|
451
453
|
const canProceed = await config.hooks?.onBeforeSwitchAgent?.(agentId);
|
|
452
|
-
if (canProceed === false)
|
|
454
|
+
if (canProceed === false) {
|
|
455
|
+
throw new Error("\u64CD\u4F5C\u88AB\u963B\u6B62");
|
|
456
|
+
}
|
|
453
457
|
try {
|
|
454
458
|
receiver.loading = true;
|
|
455
459
|
const { data } = await agentInfoQuery(agentId);
|
|
@@ -475,7 +479,9 @@ function createChatStore() {
|
|
|
475
479
|
if (receiver.active.feature?.deepThink) {
|
|
476
480
|
setReceiverParams({ thinkMode: "2" });
|
|
477
481
|
}
|
|
478
|
-
config.hooks?.onAfterSwitchAgent?.(
|
|
482
|
+
config.hooks?.onAfterSwitchAgent?.(data);
|
|
483
|
+
} catch (error) {
|
|
484
|
+
throw error;
|
|
479
485
|
} finally {
|
|
480
486
|
receiver.loading = false;
|
|
481
487
|
}
|
|
@@ -692,47 +698,51 @@ function createChatStore() {
|
|
|
692
698
|
await switchAgent(agentId);
|
|
693
699
|
const conversationId = await resolveConversationId(agentId, strategy);
|
|
694
700
|
if (conversationId) {
|
|
695
|
-
switchConversation(conversationId);
|
|
701
|
+
await switchConversation(conversationId);
|
|
696
702
|
}
|
|
697
703
|
};
|
|
698
704
|
const createConversation = async () => {
|
|
699
705
|
if (!receiver.active.id) return;
|
|
700
706
|
const conversationId = await resolveConversationId(receiver.active.id);
|
|
701
707
|
if (conversationId) {
|
|
702
|
-
switchConversation(conversationId);
|
|
708
|
+
await switchConversation(conversationId);
|
|
703
709
|
}
|
|
704
710
|
};
|
|
705
711
|
const switchConversation = async (id) => {
|
|
706
712
|
const conversationId = String(id);
|
|
707
713
|
if (conversation.active.id === conversationId) return;
|
|
708
714
|
const canProceed = await config.hooks?.onBeforeSwitchConversation?.(conversationId);
|
|
709
|
-
if (canProceed === false)
|
|
715
|
+
if (canProceed === false) {
|
|
716
|
+
throw new Error("\u64CD\u4F5C\u88AB\u963B\u6B62");
|
|
717
|
+
}
|
|
710
718
|
await initConversation(conversationId);
|
|
711
719
|
setPreview();
|
|
712
720
|
config.hooks?.onAfterSwitchConversation?.(conversationId);
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
721
|
+
try {
|
|
722
|
+
if (conversation.active.member.agent) {
|
|
723
|
+
switchAgent(conversation.active.member.agent.memberId);
|
|
724
|
+
} else if (conversation.active.member.other) {
|
|
725
|
+
switchExpert(conversation.active.member.other);
|
|
726
|
+
}
|
|
727
|
+
} catch (e) {
|
|
718
728
|
}
|
|
729
|
+
await getMessages(conversationId);
|
|
719
730
|
};
|
|
720
731
|
const getMessages = async (conversationId) => {
|
|
721
732
|
const canProceed = await config.hooks?.onBeforeInitMessages?.(conversationId);
|
|
722
|
-
if (canProceed === false)
|
|
733
|
+
if (canProceed === false) {
|
|
734
|
+
throw new Error("\u64CD\u4F5C\u88AB\u963B\u6B62");
|
|
735
|
+
}
|
|
723
736
|
if (!conversation.messages[conversationId]) {
|
|
724
737
|
setInitMessage(conversationId);
|
|
725
738
|
}
|
|
726
739
|
if (conversation.messages[conversationId].message.length === 0) {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
conversation.messages[conversationId].message = data.items;
|
|
734
|
-
} finally {
|
|
735
|
-
}
|
|
740
|
+
const { data } = await conversationMessagesQuery({
|
|
741
|
+
pageNo: 1,
|
|
742
|
+
pageSize: 1e3,
|
|
743
|
+
conversationId
|
|
744
|
+
});
|
|
745
|
+
conversation.messages[conversationId].message = data.items;
|
|
736
746
|
config.hooks?.onAfterInitMessages?.(conversation.messages[conversationId].message);
|
|
737
747
|
config.hooks?.onAfterInit?.();
|
|
738
748
|
}
|
|
@@ -868,7 +878,7 @@ function createChatStore() {
|
|
|
868
878
|
setPreview,
|
|
869
879
|
setLayout,
|
|
870
880
|
setHooks,
|
|
871
|
-
|
|
881
|
+
setParams,
|
|
872
882
|
setUserInfo,
|
|
873
883
|
character,
|
|
874
884
|
getCharacters,
|
|
@@ -1582,7 +1592,7 @@ var ChatSender_default = forwardRef(
|
|
|
1582
1592
|
extraHeader,
|
|
1583
1593
|
extraFooter,
|
|
1584
1594
|
extraFooterBelow,
|
|
1585
|
-
|
|
1595
|
+
sendBtnProps,
|
|
1586
1596
|
fileUpload: fileUpload2
|
|
1587
1597
|
}, ref) => {
|
|
1588
1598
|
const senderRef = useRef(null);
|
|
@@ -1636,7 +1646,7 @@ var ChatSender_default = forwardRef(
|
|
|
1636
1646
|
extraFooter,
|
|
1637
1647
|
" "
|
|
1638
1648
|
] }),
|
|
1639
|
-
/* @__PURE__ */ jsx(Flex, { align: "center", children: loading ? /* @__PURE__ */ jsx(LoadingButton, {}) : /* @__PURE__ */ jsx(SendButton, { ...
|
|
1649
|
+
/* @__PURE__ */ jsx(Flex, { align: "center", children: loading ? /* @__PURE__ */ jsx(LoadingButton, {}) : /* @__PURE__ */ jsx(SendButton, { ...sendBtnProps }) })
|
|
1640
1650
|
] }),
|
|
1641
1651
|
extraFooterBelow
|
|
1642
1652
|
] });
|
|
@@ -1650,94 +1660,141 @@ var ChatSender_default = forwardRef(
|
|
|
1650
1660
|
|
|
1651
1661
|
// src/ui/common/ChatSender.tsx
|
|
1652
1662
|
init_Context();
|
|
1653
|
-
|
|
1663
|
+
|
|
1664
|
+
// src/ui/common/SenderPromptsItems.tsx
|
|
1665
|
+
init_Context();
|
|
1666
|
+
var SenderPromptsItems_default = () => {
|
|
1654
1667
|
const chatStore = useChatStore();
|
|
1655
1668
|
const receiverState = useSnapshot(chatStore.receiver);
|
|
1656
|
-
const
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1669
|
+
const component = useMemo(
|
|
1670
|
+
() => receiverState.active.config?.labels?.length > 0 && /* @__PURE__ */ jsxs(Flex, { gap: 4, className: "overflow-hidden", children: [
|
|
1671
|
+
/* @__PURE__ */ jsx(Button, { disabled: true, color: "default", variant: "text", children: "\u968F\u4FBF\u804A\u804A" }),
|
|
1672
|
+
receiverState.active.config.labels.map((question) => /* @__PURE__ */ jsx(
|
|
1673
|
+
Popover,
|
|
1674
|
+
{
|
|
1675
|
+
content: /* @__PURE__ */ jsx(
|
|
1676
|
+
List,
|
|
1677
|
+
{
|
|
1678
|
+
itemLayout: "horizontal",
|
|
1679
|
+
split: false,
|
|
1680
|
+
className: styles_module_default2.senderList,
|
|
1681
|
+
dataSource: question.items,
|
|
1682
|
+
renderItem: (item) => /* @__PURE__ */ jsx(List.Item, { onClick: () => chatStore.sendMessage(item.question), className: styles_module_default2.senderListItem, children: item.question }),
|
|
1683
|
+
footer: /* @__PURE__ */ jsx(Flex, { justify: "end", className: styles_module_default2.senderListFooter, children: "(\u60A8\u53EF\u70B9\u51FB\u4EE5\u4E0A\u95EE\u9898\u5F00\u542FAI\u4F53\u9A8C)" })
|
|
1684
|
+
}
|
|
1685
|
+
),
|
|
1686
|
+
title: /* @__PURE__ */ jsx(
|
|
1687
|
+
"div",
|
|
1688
|
+
{
|
|
1689
|
+
className: classNames7(styles_module_default2.senderListTitle, "text-ellipsis"),
|
|
1690
|
+
children: `${receiverState.active.name}\u5F00\u59CB\u5173\u6CE8${question.name}\u5185\u5BB9\uFF01`
|
|
1691
|
+
}
|
|
1692
|
+
),
|
|
1693
|
+
children: /* @__PURE__ */ jsx(Button, { color: "default", variant: "filled", children: question.name })
|
|
1694
|
+
},
|
|
1695
|
+
question.id
|
|
1696
|
+
))
|
|
1697
|
+
] }),
|
|
1698
|
+
[receiverState.active.config?.labels]
|
|
1660
1699
|
);
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
config: receiverState.active.config?.fileUpload
|
|
1684
|
-
},
|
|
1685
|
-
extraFooter: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1686
|
-
receiverState.active.feature?.deepThink && /* @__PURE__ */ jsx(
|
|
1687
|
-
Button,
|
|
1688
|
-
{
|
|
1689
|
-
size: "small",
|
|
1690
|
-
color: receiverState.params.thinkMode === "1" ? "primary" : "default",
|
|
1691
|
-
variant: "filled",
|
|
1692
|
-
onClick: () => chatStore.setReceiverParams({ thinkMode: receiverState.params.thinkMode === "1" ? "2" : "1" }),
|
|
1693
|
-
children: "\u6DF1\u5EA6\u601D\u8003"
|
|
1694
|
-
}
|
|
1695
|
-
),
|
|
1696
|
-
receiverState.active.feature?.switchManual && /* @__PURE__ */ jsx(
|
|
1697
|
-
Button,
|
|
1698
|
-
{
|
|
1699
|
-
size: "small",
|
|
1700
|
-
title: chatMessage?.speakHuman ? "\u5F53\u524D\u72B6\u6001\u4E3A\u4EBA\u5DE5\u6A21\u5F0F\u3002\u60A8\u53D1\u9001\u7684\u95EE\u9898\u5C06\u76F4\u63A5\u53D1\u9001\u7ED9\u4E13\u5BB6\uFF0C\u667A\u80FD\u52A9\u624B\u5C06\u4E0D\u518D\u56DE\u590D" : "\u5F53\u524D\u72B6\u6001\u4E3A\u667A\u80FD\u52A9\u624B\u6A21\u5F0F\u3002\u60A8\u53D1\u9001\u7684\u95EE\u9898\u5C06\u53D1\u9001\u7ED9\u667A\u80FD\u52A9\u624B\uFF0C\u667A\u80FD\u52A9\u624B\u5C06\u56DE\u590D\u60A8",
|
|
1701
|
-
shape: "round",
|
|
1702
|
-
icon: /* @__PURE__ */ jsx(UserSwitchOutlined, {}),
|
|
1703
|
-
color: chatMessage?.speakHuman ? "primary" : "default",
|
|
1704
|
-
variant: "filled",
|
|
1705
|
-
onClick: () => {
|
|
1706
|
-
chatStore.setSpeakHuman?.(!chatMessage?.speakHuman);
|
|
1707
|
-
},
|
|
1708
|
-
children: "\u5411\u4E13\u5BB6\u54A8\u8BE2"
|
|
1709
|
-
}
|
|
1710
|
-
),
|
|
1711
|
-
/* @__PURE__ */ jsx(RenderWrapper, { control: extraBtn })
|
|
1712
|
-
] }),
|
|
1713
|
-
extraHeader: /* @__PURE__ */ jsx(
|
|
1714
|
-
Sender.Header,
|
|
1700
|
+
return component;
|
|
1701
|
+
};
|
|
1702
|
+
var ChatSender_default2 = forwardRef(
|
|
1703
|
+
({ placeholder, extraBtn = false, referencesBtn = false, sendBtnProps = {}, footerBelow = false, prompts = true }, ref) => {
|
|
1704
|
+
const chatStore = useChatStore();
|
|
1705
|
+
const receiverState = useSnapshot(chatStore.receiver);
|
|
1706
|
+
const conversationState = useSnapshot(chatStore.conversation);
|
|
1707
|
+
const chatMessage = useMemo(
|
|
1708
|
+
() => conversationState.messages[conversationState.active.id] || {},
|
|
1709
|
+
[conversationState.messages[conversationState.active.id]]
|
|
1710
|
+
);
|
|
1711
|
+
const referenceHandle = (con) => {
|
|
1712
|
+
if (chatMessage?.loading) return;
|
|
1713
|
+
chatStore.setContent(con);
|
|
1714
|
+
setTimeout(() => {
|
|
1715
|
+
chatStore.sendMessage();
|
|
1716
|
+
}, 10);
|
|
1717
|
+
};
|
|
1718
|
+
return /* @__PURE__ */ jsxs(Flex, { vertical: true, gap: 8, children: [
|
|
1719
|
+
/* @__PURE__ */ jsx(RenderWrapper, { control: prompts, DefaultComponent: SenderPromptsItems_default }),
|
|
1720
|
+
/* @__PURE__ */ jsx(
|
|
1721
|
+
ChatSender_default,
|
|
1715
1722
|
{
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1723
|
+
ref,
|
|
1724
|
+
placeholder,
|
|
1725
|
+
content: chatMessage.content,
|
|
1726
|
+
fileList: chatMessage.files,
|
|
1727
|
+
headerOpen: chatMessage.headerOpen,
|
|
1728
|
+
loading: chatMessage.loading,
|
|
1729
|
+
onContentChange: chatStore.setContent,
|
|
1730
|
+
onFileListChange: chatStore.setFileList,
|
|
1731
|
+
onHeaderOpenChange: chatStore.setHeaderOpen,
|
|
1732
|
+
onSend: () => chatStore.sendMessage(),
|
|
1733
|
+
onCancel: chatStore.cancelReceive,
|
|
1734
|
+
onFocus: chatStore.config.hooks?.onSenderFocus,
|
|
1735
|
+
fileUpload: {
|
|
1736
|
+
config: receiverState.active.config?.fileUpload
|
|
1725
1737
|
},
|
|
1726
|
-
|
|
1727
|
-
|
|
1738
|
+
sendBtnProps,
|
|
1739
|
+
extraFooterBelow: /* @__PURE__ */ jsx(RenderWrapper, { control: footerBelow }),
|
|
1740
|
+
extraFooter: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1741
|
+
receiverState.active.feature?.deepThink && /* @__PURE__ */ jsx(
|
|
1742
|
+
Button,
|
|
1743
|
+
{
|
|
1744
|
+
size: "small",
|
|
1745
|
+
color: receiverState.params.thinkMode === "1" ? "primary" : "default",
|
|
1746
|
+
variant: "filled",
|
|
1747
|
+
onClick: () => chatStore.setReceiverParams({ thinkMode: receiverState.params.thinkMode === "1" ? "2" : "1" }),
|
|
1748
|
+
children: "\u6DF1\u5EA6\u601D\u8003"
|
|
1749
|
+
}
|
|
1750
|
+
),
|
|
1751
|
+
receiverState.active.feature?.switchManual && /* @__PURE__ */ jsx(
|
|
1752
|
+
Button,
|
|
1753
|
+
{
|
|
1754
|
+
size: "small",
|
|
1755
|
+
title: chatMessage?.speakHuman ? "\u5F53\u524D\u72B6\u6001\u4E3A\u4EBA\u5DE5\u6A21\u5F0F\u3002\u60A8\u53D1\u9001\u7684\u95EE\u9898\u5C06\u76F4\u63A5\u53D1\u9001\u7ED9\u4E13\u5BB6\uFF0C\u667A\u80FD\u52A9\u624B\u5C06\u4E0D\u518D\u56DE\u590D" : "\u5F53\u524D\u72B6\u6001\u4E3A\u667A\u80FD\u52A9\u624B\u6A21\u5F0F\u3002\u60A8\u53D1\u9001\u7684\u95EE\u9898\u5C06\u53D1\u9001\u7ED9\u667A\u80FD\u52A9\u624B\uFF0C\u667A\u80FD\u52A9\u624B\u5C06\u56DE\u590D\u60A8",
|
|
1756
|
+
shape: "round",
|
|
1757
|
+
icon: /* @__PURE__ */ jsx(UserSwitchOutlined, {}),
|
|
1758
|
+
color: chatMessage?.speakHuman ? "primary" : "default",
|
|
1759
|
+
variant: "filled",
|
|
1760
|
+
onClick: () => {
|
|
1761
|
+
chatStore.setSpeakHuman?.(!chatMessage?.speakHuman);
|
|
1762
|
+
},
|
|
1763
|
+
children: "\u5411\u4E13\u5BB6\u54A8\u8BE2"
|
|
1764
|
+
}
|
|
1765
|
+
),
|
|
1766
|
+
/* @__PURE__ */ jsx(RenderWrapper, { control: extraBtn })
|
|
1767
|
+
] }),
|
|
1768
|
+
extraHeader: /* @__PURE__ */ jsx(
|
|
1769
|
+
Sender.Header,
|
|
1728
1770
|
{
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1771
|
+
title: /* @__PURE__ */ jsxs(Flex, { gap: 4, children: [
|
|
1772
|
+
/* @__PURE__ */ jsx(EnterOutlined, {}),
|
|
1773
|
+
/* @__PURE__ */ jsx(Typography.Text, { type: "secondary", ellipsis: true, children: chatMessage?.references?.content?.name })
|
|
1774
|
+
] }),
|
|
1775
|
+
open: !!chatMessage?.references?.content?.name,
|
|
1776
|
+
onOpenChange: () => chatStore.setReferences(),
|
|
1777
|
+
classNames: {
|
|
1778
|
+
header: styles_module_default2.nsSenderReferenceHeaderTitle,
|
|
1779
|
+
content: shouldRender(referencesBtn) ? "" : styles_module_default2.nsSenderReferenceHeaderContent
|
|
1780
|
+
},
|
|
1781
|
+
children: /* @__PURE__ */ jsx(
|
|
1782
|
+
RenderWrapper,
|
|
1783
|
+
{
|
|
1784
|
+
control: referencesBtn,
|
|
1785
|
+
DefaultComponent: /* @__PURE__ */ jsx(Flex, { gap: 8, children: ["\u6DF1\u5EA6\u89E3\u8BFB", "\u6982\u8981\u89E3\u8BFB"].map((con) => /* @__PURE__ */ jsxs(Button, { color: "primary", variant: "filled", onClick: () => referenceHandle(con), children: [
|
|
1786
|
+
con,
|
|
1787
|
+
" \u2192"
|
|
1788
|
+
] }, con)) })
|
|
1789
|
+
}
|
|
1790
|
+
)
|
|
1734
1791
|
}
|
|
1735
1792
|
)
|
|
1736
1793
|
}
|
|
1737
1794
|
)
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1795
|
+
] });
|
|
1796
|
+
}
|
|
1797
|
+
);
|
|
1741
1798
|
|
|
1742
1799
|
// src/ui/common/ConversationListHeader.tsx
|
|
1743
1800
|
init_Context();
|
|
@@ -1770,45 +1827,6 @@ var ConversationListPanel_default = ({ header }) => {
|
|
|
1770
1827
|
] });
|
|
1771
1828
|
};
|
|
1772
1829
|
|
|
1773
|
-
// src/ui/common/SenderPromptsItems.tsx
|
|
1774
|
-
init_Context();
|
|
1775
|
-
var SenderPromptsItems_default = () => {
|
|
1776
|
-
const chatStore = useChatStore();
|
|
1777
|
-
const receiverState = useSnapshot(chatStore.receiver);
|
|
1778
|
-
const component = useMemo(
|
|
1779
|
-
() => receiverState.active.config?.labels?.length > 0 && /* @__PURE__ */ jsxs(Flex, { gap: 4, className: "overflow-hidden", children: [
|
|
1780
|
-
/* @__PURE__ */ jsx(Button, { disabled: true, color: "default", variant: "text", children: "\u968F\u4FBF\u804A\u804A" }),
|
|
1781
|
-
receiverState.active.config.labels.map((question) => /* @__PURE__ */ jsx(
|
|
1782
|
-
Popover,
|
|
1783
|
-
{
|
|
1784
|
-
content: /* @__PURE__ */ jsx(
|
|
1785
|
-
List,
|
|
1786
|
-
{
|
|
1787
|
-
itemLayout: "horizontal",
|
|
1788
|
-
split: false,
|
|
1789
|
-
className: styles_module_default2.senderList,
|
|
1790
|
-
dataSource: question.items,
|
|
1791
|
-
renderItem: (item) => /* @__PURE__ */ jsx(List.Item, { onClick: () => chatStore.sendMessage(item.question), className: styles_module_default2.senderListItem, children: item.question }),
|
|
1792
|
-
footer: /* @__PURE__ */ jsx(Flex, { justify: "end", className: styles_module_default2.senderListFooter, children: "(\u60A8\u53EF\u70B9\u51FB\u4EE5\u4E0A\u95EE\u9898\u5F00\u542FAI\u4F53\u9A8C)" })
|
|
1793
|
-
}
|
|
1794
|
-
),
|
|
1795
|
-
title: /* @__PURE__ */ jsx(
|
|
1796
|
-
"div",
|
|
1797
|
-
{
|
|
1798
|
-
className: classNames7(styles_module_default2.senderListTitle, "text-ellipsis"),
|
|
1799
|
-
children: `${receiverState.active.name}\u5F00\u59CB\u5173\u6CE8${question.name}\u5185\u5BB9\uFF01`
|
|
1800
|
-
}
|
|
1801
|
-
),
|
|
1802
|
-
children: /* @__PURE__ */ jsx(Button, { color: "default", variant: "filled", children: question.name })
|
|
1803
|
-
},
|
|
1804
|
-
question.id
|
|
1805
|
-
))
|
|
1806
|
-
] }),
|
|
1807
|
-
[receiverState.active.config?.labels]
|
|
1808
|
-
);
|
|
1809
|
-
return component;
|
|
1810
|
-
};
|
|
1811
|
-
|
|
1812
1830
|
// src/ui/layouts/styles.module.less
|
|
1813
1831
|
var styles_module_default4 = {
|
|
1814
1832
|
nsPreviewHeader: "styles_module_nsPreviewHeader",
|
|
@@ -1819,6 +1837,7 @@ var styles_module_default4 = {
|
|
|
1819
1837
|
};
|
|
1820
1838
|
var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, config }, ref) => {
|
|
1821
1839
|
const chatStore = useMemo(() => createChatStore(), []);
|
|
1840
|
+
const senderRef = useRef();
|
|
1822
1841
|
useDeepEffect(() => {
|
|
1823
1842
|
if (config?.conversationId) {
|
|
1824
1843
|
chatStore.switchConversation(config.conversationId);
|
|
@@ -1835,7 +1854,7 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
|
|
|
1835
1854
|
chatStore.setLayout(layout, config?.receiverType);
|
|
1836
1855
|
}, [layout, config?.receiverType]);
|
|
1837
1856
|
useEffect(() => {
|
|
1838
|
-
chatStore.
|
|
1857
|
+
chatStore.setParams(params);
|
|
1839
1858
|
}, [params]);
|
|
1840
1859
|
useEffect(() => {
|
|
1841
1860
|
chatStore.setHooks(hooks);
|
|
@@ -1851,7 +1870,11 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
|
|
|
1851
1870
|
createConversation: chatStore.createConversation,
|
|
1852
1871
|
setReferences: chatStore.setReferences,
|
|
1853
1872
|
setMessage: chatStore.setContent,
|
|
1854
|
-
setFiles: chatStore.setFileList
|
|
1873
|
+
setFiles: chatStore.setFileList,
|
|
1874
|
+
setParams: chatStore.setParams,
|
|
1875
|
+
senderFocus: (options) => {
|
|
1876
|
+
senderRef.current?.focus(options);
|
|
1877
|
+
}
|
|
1855
1878
|
}),
|
|
1856
1879
|
[]
|
|
1857
1880
|
);
|
|
@@ -1947,14 +1970,7 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
|
|
|
1947
1970
|
] })
|
|
1948
1971
|
}
|
|
1949
1972
|
),
|
|
1950
|
-
/* @__PURE__ */ jsx(
|
|
1951
|
-
RenderWrapper,
|
|
1952
|
-
{
|
|
1953
|
-
control: configState.layout.senderPrompts,
|
|
1954
|
-
DefaultComponent: SenderPromptsItems_default
|
|
1955
|
-
}
|
|
1956
|
-
),
|
|
1957
|
-
/* @__PURE__ */ jsx(RenderWrapper, { control: configState.layout.sender, DefaultComponent: ChatSender_default2 }),
|
|
1973
|
+
/* @__PURE__ */ jsx(RenderWrapper, { ref: senderRef, control: configState.layout.sender, DefaultComponent: ChatSender_default2 }),
|
|
1958
1974
|
/* @__PURE__ */ jsx(
|
|
1959
1975
|
RenderWrapper,
|
|
1960
1976
|
{
|