@touchvue/chat 1.0.0-beta.41 → 1.0.0-beta.43

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.
Files changed (151) hide show
  1. package/es/package.json.css +1 -1
  2. package/es/package.json.mjs +1 -1
  3. package/es/packages/components/touchchat/component/AiRobot/HelloChat.vue2.mjs.map +1 -1
  4. package/es/packages/components/touchchat/component/AiRobot/letter.vue.mjs +1 -1
  5. package/es/packages/components/touchchat/component/AiRobot/letter.vue2.mjs +15 -3
  6. package/es/packages/components/touchchat/component/AiRobot/letter.vue2.mjs.map +1 -1
  7. package/es/packages/components/touchchat/component/FileContent.vue2.mjs +3 -3
  8. package/es/packages/components/touchchat/component/FileContent.vue2.mjs.map +1 -1
  9. package/es/packages/components/touchchat/component/FileView.vue2.mjs +2 -2
  10. package/es/packages/components/touchchat/component/FileView.vue2.mjs.map +1 -1
  11. package/es/packages/components/touchchat/component/HelloChat.vue2.mjs.map +1 -1
  12. package/es/packages/components/touchchat/component/ImageFile.vue2.mjs +6 -6
  13. package/es/packages/components/touchchat/component/ImageFile.vue2.mjs.map +1 -1
  14. package/es/packages/components/touchchat/component/ImageView.vue2.mjs +1 -1
  15. package/es/packages/components/touchchat/component/ImageView.vue2.mjs.map +1 -1
  16. package/es/packages/components/touchchat/component/LinkView.vue2.mjs +4 -4
  17. package/es/packages/components/touchchat/component/LinkView.vue2.mjs.map +1 -1
  18. package/es/packages/components/touchchat/component/MarkLayer.vue2.mjs +1 -1
  19. package/es/packages/components/touchchat/component/MarkLayer.vue2.mjs.map +1 -1
  20. package/es/packages/components/touchchat/component/ModuleSelect.vue2.mjs +2 -2
  21. package/es/packages/components/touchchat/component/ModuleSelect.vue2.mjs.map +1 -1
  22. package/es/packages/components/touchchat/component/PDFFile.vue2.mjs +8 -8
  23. package/es/packages/components/touchchat/component/PDFFile.vue2.mjs.map +1 -1
  24. package/es/packages/components/touchchat/component/RealtimeVoice.vue2.mjs +1 -1
  25. package/es/packages/components/touchchat/component/RealtimeVoice.vue2.mjs.map +1 -1
  26. package/es/packages/components/touchchat/component/Screenshot.vue2.mjs +11 -2
  27. package/es/packages/components/touchchat/component/Screenshot.vue2.mjs.map +1 -1
  28. package/es/packages/components/touchchat/component/UploadView.vue2.mjs +10 -7
  29. package/es/packages/components/touchchat/component/UploadView.vue2.mjs.map +1 -1
  30. package/es/packages/components/touchchat/component/VoiceView.vue2.mjs +1 -1
  31. package/es/packages/components/touchchat/component/VoiceView.vue2.mjs.map +1 -1
  32. package/es/packages/components/touchchat/src/AiChat/AgentsView.vue2.mjs +1 -1
  33. package/es/packages/components/touchchat/src/AiChat/AgentsView.vue2.mjs.map +1 -1
  34. package/es/packages/components/touchchat/src/AiChat/AiMessage.vue2.mjs +22 -22
  35. package/es/packages/components/touchchat/src/AiChat/AiMessage.vue2.mjs.map +1 -1
  36. package/es/packages/components/touchchat/src/AiChat/Chat/scriptMatcher.mjs +145 -0
  37. package/es/packages/components/touchchat/src/AiChat/Chat/scriptMatcher.mjs.map +1 -0
  38. package/es/packages/components/touchchat/src/AiChat/Chat/types.mjs +18 -0
  39. package/es/packages/components/touchchat/src/AiChat/Chat/types.mjs.map +1 -0
  40. package/es/packages/components/touchchat/src/AiChat/Chat/useChat.mjs +672 -0
  41. package/es/packages/components/touchchat/src/AiChat/Chat/useChat.mjs.map +1 -0
  42. package/es/packages/components/touchchat/src/AiChat/Chat/useCopy.mjs +55 -0
  43. package/es/packages/components/touchchat/src/AiChat/Chat/useCopy.mjs.map +1 -0
  44. package/es/packages/components/touchchat/src/AiChat/Chat/useMessageRender.mjs +155 -0
  45. package/es/packages/components/touchchat/src/AiChat/Chat/useMessageRender.mjs.map +1 -0
  46. package/es/packages/components/touchchat/src/AiChat/Chat/useSSE.mjs +352 -0
  47. package/es/packages/components/touchchat/src/AiChat/Chat/useSSE.mjs.map +1 -0
  48. package/es/packages/components/touchchat/src/AiChat/Chat/useScroll.mjs +74 -0
  49. package/es/packages/components/touchchat/src/AiChat/Chat/useScroll.mjs.map +1 -0
  50. package/es/packages/components/touchchat/src/AiChat/ChatInput.vue2.mjs +8 -7
  51. package/es/packages/components/touchchat/src/AiChat/ChatInput.vue2.mjs.map +1 -1
  52. package/es/packages/components/touchchat/src/AiChat/HistoryList.vue2.mjs +1 -1
  53. package/es/packages/components/touchchat/src/AiChat/HistoryList.vue2.mjs.map +1 -1
  54. package/es/packages/components/touchchat/src/AiChat/HistorySidebar.vue2.mjs +3 -3
  55. package/es/packages/components/touchchat/src/AiChat/HistorySidebar.vue2.mjs.map +1 -1
  56. package/es/packages/components/touchchat/src/AiChat/MessageActions.vue2.mjs +11 -11
  57. package/es/packages/components/touchchat/src/AiChat/MessageActions.vue2.mjs.map +1 -1
  58. package/es/packages/components/touchchat/src/AiChat/SiderBarView.vue2.mjs +3 -3
  59. package/es/packages/components/touchchat/src/AiChat/SiderBarView.vue2.mjs.map +1 -1
  60. package/es/packages/components/touchchat/src/AiChat/TouchAgent.vue2.mjs +33 -29
  61. package/es/packages/components/touchchat/src/AiChat/TouchAgent.vue2.mjs.map +1 -1
  62. package/es/packages/components/touchchat/src/AiChat/TouchChat.vue2.mjs +179 -1332
  63. package/es/packages/components/touchchat/src/AiChat/TouchChat.vue2.mjs.map +1 -1
  64. package/es/packages/components/touchchat/src/AiChat/TouchHistory.vue2.mjs +19 -6
  65. package/es/packages/components/touchchat/src/AiChat/TouchHistory.vue2.mjs.map +1 -1
  66. package/es/packages/components/touchchat/src/AiChat/UserMessage.vue2.mjs +14 -14
  67. package/es/packages/components/touchchat/src/AiChat/UserMessage.vue2.mjs.map +1 -1
  68. package/es/packages/components/touchchat/src/index.vue2.mjs +3 -3
  69. package/es/packages/components/touchchat/src/index.vue2.mjs.map +1 -1
  70. package/es/packages/components/touchchat/utils/a2aService.mjs +3 -2
  71. package/es/packages/components/touchchat/utils/a2aService.mjs.map +1 -1
  72. package/es/packages/components/touchchat/utils/fetchStream.mjs +2 -1
  73. package/es/packages/components/touchchat/utils/fetchStream.mjs.map +1 -1
  74. package/es/packages/components/touchchat/utils/markdown.mjs +30 -12
  75. package/es/packages/components/touchchat/utils/markdown.mjs.map +1 -1
  76. package/lib/package.json.css +1 -1
  77. package/lib/package.json.js +1 -1
  78. package/lib/packages/components/touchchat/component/AiRobot/HelloChat.vue2.js.map +1 -1
  79. package/lib/packages/components/touchchat/component/AiRobot/letter.vue.js +1 -1
  80. package/lib/packages/components/touchchat/component/AiRobot/letter.vue2.js +15 -3
  81. package/lib/packages/components/touchchat/component/AiRobot/letter.vue2.js.map +1 -1
  82. package/lib/packages/components/touchchat/component/FileContent.vue2.js +3 -3
  83. package/lib/packages/components/touchchat/component/FileContent.vue2.js.map +1 -1
  84. package/lib/packages/components/touchchat/component/FileView.vue2.js +2 -2
  85. package/lib/packages/components/touchchat/component/FileView.vue2.js.map +1 -1
  86. package/lib/packages/components/touchchat/component/HelloChat.vue2.js.map +1 -1
  87. package/lib/packages/components/touchchat/component/ImageFile.vue2.js +6 -6
  88. package/lib/packages/components/touchchat/component/ImageFile.vue2.js.map +1 -1
  89. package/lib/packages/components/touchchat/component/ImageView.vue2.js +1 -1
  90. package/lib/packages/components/touchchat/component/ImageView.vue2.js.map +1 -1
  91. package/lib/packages/components/touchchat/component/LinkView.vue2.js +4 -4
  92. package/lib/packages/components/touchchat/component/LinkView.vue2.js.map +1 -1
  93. package/lib/packages/components/touchchat/component/MarkLayer.vue2.js +1 -1
  94. package/lib/packages/components/touchchat/component/MarkLayer.vue2.js.map +1 -1
  95. package/lib/packages/components/touchchat/component/ModuleSelect.vue2.js +2 -2
  96. package/lib/packages/components/touchchat/component/ModuleSelect.vue2.js.map +1 -1
  97. package/lib/packages/components/touchchat/component/PDFFile.vue2.js +8 -8
  98. package/lib/packages/components/touchchat/component/PDFFile.vue2.js.map +1 -1
  99. package/lib/packages/components/touchchat/component/RealtimeVoice.vue2.js +1 -1
  100. package/lib/packages/components/touchchat/component/RealtimeVoice.vue2.js.map +1 -1
  101. package/lib/packages/components/touchchat/component/Screenshot.vue2.js +11 -2
  102. package/lib/packages/components/touchchat/component/Screenshot.vue2.js.map +1 -1
  103. package/lib/packages/components/touchchat/component/UploadView.vue2.js +10 -7
  104. package/lib/packages/components/touchchat/component/UploadView.vue2.js.map +1 -1
  105. package/lib/packages/components/touchchat/component/VoiceView.vue2.js +1 -1
  106. package/lib/packages/components/touchchat/component/VoiceView.vue2.js.map +1 -1
  107. package/lib/packages/components/touchchat/src/AiChat/AgentsView.vue2.js +1 -1
  108. package/lib/packages/components/touchchat/src/AiChat/AgentsView.vue2.js.map +1 -1
  109. package/lib/packages/components/touchchat/src/AiChat/AiMessage.vue2.js +22 -22
  110. package/lib/packages/components/touchchat/src/AiChat/AiMessage.vue2.js.map +1 -1
  111. package/lib/packages/components/touchchat/src/AiChat/Chat/scriptMatcher.js +147 -0
  112. package/lib/packages/components/touchchat/src/AiChat/Chat/scriptMatcher.js.map +1 -0
  113. package/lib/packages/components/touchchat/src/AiChat/Chat/types.js +21 -0
  114. package/lib/packages/components/touchchat/src/AiChat/Chat/types.js.map +1 -0
  115. package/lib/packages/components/touchchat/src/AiChat/Chat/useChat.js +674 -0
  116. package/lib/packages/components/touchchat/src/AiChat/Chat/useChat.js.map +1 -0
  117. package/lib/packages/components/touchchat/src/AiChat/Chat/useCopy.js +57 -0
  118. package/lib/packages/components/touchchat/src/AiChat/Chat/useCopy.js.map +1 -0
  119. package/lib/packages/components/touchchat/src/AiChat/Chat/useMessageRender.js +157 -0
  120. package/lib/packages/components/touchchat/src/AiChat/Chat/useMessageRender.js.map +1 -0
  121. package/lib/packages/components/touchchat/src/AiChat/Chat/useSSE.js +354 -0
  122. package/lib/packages/components/touchchat/src/AiChat/Chat/useSSE.js.map +1 -0
  123. package/lib/packages/components/touchchat/src/AiChat/Chat/useScroll.js +76 -0
  124. package/lib/packages/components/touchchat/src/AiChat/Chat/useScroll.js.map +1 -0
  125. package/lib/packages/components/touchchat/src/AiChat/ChatInput.vue2.js +8 -7
  126. package/lib/packages/components/touchchat/src/AiChat/ChatInput.vue2.js.map +1 -1
  127. package/lib/packages/components/touchchat/src/AiChat/HistoryList.vue2.js +1 -1
  128. package/lib/packages/components/touchchat/src/AiChat/HistoryList.vue2.js.map +1 -1
  129. package/lib/packages/components/touchchat/src/AiChat/HistorySidebar.vue2.js +3 -3
  130. package/lib/packages/components/touchchat/src/AiChat/HistorySidebar.vue2.js.map +1 -1
  131. package/lib/packages/components/touchchat/src/AiChat/MessageActions.vue2.js +11 -11
  132. package/lib/packages/components/touchchat/src/AiChat/MessageActions.vue2.js.map +1 -1
  133. package/lib/packages/components/touchchat/src/AiChat/SiderBarView.vue2.js +3 -3
  134. package/lib/packages/components/touchchat/src/AiChat/SiderBarView.vue2.js.map +1 -1
  135. package/lib/packages/components/touchchat/src/AiChat/TouchAgent.vue2.js +49 -45
  136. package/lib/packages/components/touchchat/src/AiChat/TouchAgent.vue2.js.map +1 -1
  137. package/lib/packages/components/touchchat/src/AiChat/TouchChat.vue2.js +179 -1332
  138. package/lib/packages/components/touchchat/src/AiChat/TouchChat.vue2.js.map +1 -1
  139. package/lib/packages/components/touchchat/src/AiChat/TouchHistory.vue2.js +19 -6
  140. package/lib/packages/components/touchchat/src/AiChat/TouchHistory.vue2.js.map +1 -1
  141. package/lib/packages/components/touchchat/src/AiChat/UserMessage.vue2.js +14 -14
  142. package/lib/packages/components/touchchat/src/AiChat/UserMessage.vue2.js.map +1 -1
  143. package/lib/packages/components/touchchat/src/index.vue2.js +3 -3
  144. package/lib/packages/components/touchchat/src/index.vue2.js.map +1 -1
  145. package/lib/packages/components/touchchat/utils/a2aService.js +3 -2
  146. package/lib/packages/components/touchchat/utils/a2aService.js.map +1 -1
  147. package/lib/packages/components/touchchat/utils/fetchStream.js +2 -1
  148. package/lib/packages/components/touchchat/utils/fetchStream.js.map +1 -1
  149. package/lib/packages/components/touchchat/utils/markdown.js +30 -12
  150. package/lib/packages/components/touchchat/utils/markdown.js.map +1 -1
  151. package/package.json +1 -1
@@ -1,13 +1,11 @@
1
- import { defineComponent, inject, ref, watch, nextTick, onMounted, onBeforeUnmount, provide, openBlock, createElementBlock, withModifiers, createElementVNode, renderSlot, createVNode, createCommentVNode, Fragment, renderList, createBlock, unref, withCtx } from 'vue';
1
+ import { defineComponent, inject, ref, computed, provide, onMounted, watch, onBeforeUnmount, openBlock, createElementBlock, withModifiers, unref, createElementVNode, renderSlot, createVNode, createCommentVNode, Fragment, renderList, createBlock, withCtx, isRef } from 'vue';
2
2
  import UserMessage from './UserMessage.vue.mjs';
3
3
  import AiMessage from './AiMessage.vue.mjs';
4
4
  import ChatInput from './ChatInput.vue.mjs';
5
5
  import HelloChat from '../../component/HelloChat.vue.mjs';
6
- import { throttle } from '../../../../../node_modules/.pnpm/throttle-debounce@5.0.2/node_modules/throttle-debounce/esm/index.mjs';
7
- import { FetchStream } from '../../utils/fetchStream.mjs';
8
- import markdown from '../../utils/markdown.mjs';
9
- import { showToast } from '../../utils/tools.mjs';
10
- import { MessageAction, ThinkStatus } from './Chat/TouchChat.mjs';
6
+ import { MessageAction } from './Chat/types.mjs';
7
+ import { useChat } from './Chat/useChat.mjs';
8
+ import { useCopy } from './Chat/useCopy.mjs';
11
9
 
12
10
  var _sfc_main = /* @__PURE__ */ defineComponent({
13
11
  __name: "TouchChat",
@@ -20,11 +18,9 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
20
18
  emits: ["sendMessage", "toggleSidebar", "beforeSendMessage"],
21
19
  setup(__props, { expose: __expose, emit: __emit }) {
22
20
  const emit = __emit;
23
- const scripts = inject("scripts", []);
24
- const activeScript = ref(null);
25
- const resultItem = ref(null);
21
+ const scripts = inject("scripts", ref([]));
26
22
  const unmatchText = inject("unmatchText", "\u60A8\u7684\u6D88\u606F\u672A\u5339\u914D\u5230\u4EFB\u4F55\u5185\u5BB9");
27
- const modules = inject("modules", []);
23
+ const modules = inject("modules", ref([]));
28
24
  const afterSend = inject("afterSend", () => {
29
25
  console.warn("\u672A\u63D0\u4F9BafterSend\u51FD\u6570");
30
26
  });
@@ -41,746 +37,58 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
41
37
  const stop = inject("stop", () => {
42
38
  console.warn("\u672A\u63D0\u4F9Bstop\u51FD\u6570");
43
39
  });
40
+ const scriptsLength = computed(() => {
41
+ var _a;
42
+ return ((_a = scripts.value) == null ? void 0 : _a.length) || 0;
43
+ });
44
44
  const props = __props;
45
45
  const chatContainer = ref(null);
46
- const htmlContentRef = ref([]);
47
- const thinkingContentRef = ref([]);
48
- const reasoningContentRef = ref([]);
49
- const isMounted = ref(false);
50
- const isChating = ref(false);
51
- const inputValue = ref("");
52
- const enableDeepThinking = ref(false);
53
- const chatList = ref([]);
54
- const renderQueue = ref([]);
55
- const isRendering = ref(false);
56
- const currIndex = ref(0);
57
- const fetchStream = ref(null);
58
- const TouchChatRobot = ref();
59
- const isUnmounting = ref(false);
60
- const currentComponentName = ref("");
61
- const fileData = ref([]);
62
- const activeAgentsName = ref("");
63
- const moduleInfo = ref(modules[0]);
64
46
  const ChatInputRef = ref(null);
65
- const isDragging = ref(false);
66
- const typeFlag = ref("");
67
- const currentMessageProcessor = ref(null);
68
- watch(
69
- () => activeAgentsName,
70
- (val) => {
71
- if (!val) {
72
- activeAgentsName.value = localStorage.getItem("activeAgentsName");
73
- }
74
- },
75
- { immediate: true }
76
- );
77
- const messageUtils = {
78
- updateMessage: (index, updates) => {
79
- if (index < 0 || index >= chatList.value.length)
80
- return;
81
- chatList.value.splice(index, 1, { ...chatList.value[index], ...updates });
82
- nextTick(() => {
83
- const message = chatList.value[index];
84
- if (message) {
85
- renderContent(message.content, "main", index);
86
- if (message.thinkContent) {
87
- renderContent(message.thinkContent, "thinking", index);
88
- }
89
- if (message.reasoningContent) {
90
- renderContent(message.reasoningContent, "reasoning", index);
91
- }
92
- }
93
- });
94
- },
95
- deleteMessageChain: (index) => {
96
- if (index < 0 || index >= chatList.value.length)
97
- return;
98
- if (chatList.value[index].user === "u") {
99
- let deleteCount = 1;
100
- for (let i = index + 1; i < chatList.value.length; i++) {
101
- if (chatList.value[i].user === "ai") {
102
- deleteCount++;
103
- } else {
104
- break;
105
- }
106
- }
107
- chatList.value.splice(index, deleteCount);
108
- } else {
109
- chatList.value.splice(index, 1);
110
- }
111
- },
112
- createStandardMessage: (data) => {
113
- var _a, _b, _c, _d, _e;
114
- return {
115
- // chatId: data.chatId || 'ai_' + crypto.randomUUID().replace(/-/gi, ''),
116
- chatId: data.chatId || "ai_" + Math.random().toString(36).slice(2).padEnd(10, "0").slice(0, 10),
117
- user: data.user || "ai",
118
- type: data.type || "text",
119
- content: data.content || "",
120
- isChating: (_a = data.isChating) != null ? _a : false,
121
- thinkContent: data.thinkContent || "",
122
- reasoningContent: data.reasoningContent || "",
123
- isLiked: (_b = data.isLiked) != null ? _b : false,
124
- isDisliked: (_c = data.isDisliked) != null ? _c : false,
125
- isEditing: (_d = data.isEditing) != null ? _d : false,
126
- editContent: (_e = data.editContent) != null ? _e : ""
127
- };
128
- }
129
- };
130
- const update = (index, message) => {
131
- chatList.value[index] = { ...chatList.value[index], ...message };
132
- console.log("update", chatList.value[index]);
133
- };
134
- const markdownToHtml = (markdownContent) => {
135
- var _a;
136
- return ((_a = markdown) == null ? void 0 : _a.render(markdownContent, { isReasoning: false })) || "";
137
- };
138
- const updateModule = (info) => {
139
- moduleInfo.value = info;
140
- };
141
- const handleAgentSelect = (item) => {
142
- localStorage.setItem("activeAgentsName", item.name);
143
- const aiMessage = item.intro;
144
- messageUtils.updateMessage(0, {
145
- content: "",
146
- isChating: false
147
- });
148
- simulateStreamOutput(0, aiMessage);
149
- };
150
- const completeRendered = (chatId) => {
151
- console.log("completeRendered", "\u6E32\u67D3\u5B8C\u6210", chatId);
152
- if (currentMessageProcessor.value) {
153
- currentMessageProcessor.value.handleMessageComplete(chatId);
154
- }
155
- };
156
- const toggleSidebarClick = (item, index) => {
157
- emit("toggleSidebar", item, index);
158
- };
159
- const init = () => {
160
- try {
161
- if (Array.isArray(props.value) && props.value.length && !scripts.length) {
162
- chatList.value = props.value.map((item) => ({
163
- ...item,
164
- content: item.thinkContent ? item.content || "" : item.content || "",
165
- thinkContent: item.thinkContent || ""
166
- }));
167
- nextTick(() => {
168
- requestAnimationFrame(() => {
169
- if (activeAgentsName.value && chatList.value.length > 0 && chatList.value[0].user === "ai") {
170
- const aiMessage = chatList.value[0];
171
- messageUtils.updateMessage(0, {
172
- content: "",
173
- isChating: true
174
- });
175
- simulateStreamOutput(0, aiMessage.content);
176
- } else {
177
- chatList.value.forEach((item) => {
178
- if (item.thinkContent) {
179
- renderContent(item.thinkContent, "thinking");
180
- }
181
- if (item.reasoningContent) {
182
- renderContent(item.reasoningContent, "reasoning");
183
- }
184
- if (item.content) {
185
- renderContent(item.content, "main");
186
- }
187
- });
188
- nextTick(() => {
189
- scrollToBottom();
190
- });
191
- }
192
- });
193
- });
194
- }
195
- } catch (error) {
196
- console.error("\u521D\u59CB\u5316\u5931\u8D25:", error);
197
- }
198
- };
199
- const onScrollToBottom = () => {
200
- bottom();
201
- };
202
- const throttledScrollToBottom = throttle(300, onScrollToBottom);
203
- const handleScroll = () => {
204
- if (!chatContainer.value)
205
- return;
206
- const { scrollTop, scrollHeight, clientHeight } = chatContainer.value;
207
- if (scrollTop + clientHeight >= scrollHeight) {
208
- throttledScrollToBottom();
209
- }
210
- };
211
- const simulateStreamOutput = (aiIndex, msg, callback) => {
212
- const message = typeof msg === "string" ? msg : msg.content;
213
- const componentName = typeof msg === "string" ? "" : msg.needSequenceProcessing ? msg.needSequenceType : "";
214
- const isNeedSequenceProcessing = typeof msg === "string" ? false : msg.needSequenceProcessing;
215
- const fn = () => {
216
- clearInterval(interval);
217
- emit("sendMessage", [...chatList.value]);
218
- if (componentName) {
219
- chatList.value[aiIndex].componentName = componentName;
220
- }
221
- messageUtils.updateMessage(aiIndex, {
222
- isChating: false
223
- });
224
- nextTick(() => {
225
- renderContent(message, "main", aiIndex);
226
- nextTick(() => {
227
- scrollToBottom();
228
- if (!isNeedSequenceProcessing && callback) {
229
- callback();
230
- }
231
- });
232
- });
233
- };
234
- let index = 0;
235
- const interval = setInterval(() => {
236
- if (index < message.length) {
237
- const newContent = message;
238
- messageUtils.updateMessage(aiIndex, {
239
- content: newContent
240
- });
241
- nextTick(() => {
242
- renderContent(newContent, "main", aiIndex);
243
- nextTick(() => {
244
- scrollToBottom();
245
- });
246
- });
247
- index++;
248
- } else {
249
- fn();
250
- }
251
- }, 50);
252
- };
253
- const findMatchingScriptContent = (userInput) => {
254
- if (!scripts || scripts.length === 0)
255
- return null;
256
- const agentName = activeAgentsName.value ? activeAgentsName.value : localStorage.getItem("activeAgentsName") || "";
257
- if (agentName) {
258
- const agentMatchedScripts = scripts.filter((script) => {
259
- return script.content.some((item) => item.agents === agentName);
260
- });
261
- if (agentMatchedScripts.length > 0) {
262
- const fileTypeItems = agentMatchedScripts.flatMap((script) => script.content.filter((item) => item.file));
263
- const fileTypes = fileTypeItems.map((item) => item.file);
264
- const isFileTypeMatched = fileData.value.some((file) => {
265
- const nameArr = file.name.split(".");
266
- const name = nameArr[nameArr.length - 1];
267
- const isMatched = fileTypes.includes(name);
268
- return isMatched;
269
- });
270
- let matchedScriptContentIndex = -1;
271
- if (!activeScript.value && isFileTypeMatched) {
272
- activeScript.value = agentMatchedScripts[0];
273
- }
274
- if (isFileTypeMatched) {
275
- for (const script of agentMatchedScripts) {
276
- for (let i = 0; i < script.content.length; i++) {
277
- const item = script.content[i];
278
- if (item.file) {
279
- const nameArr = fileData.value.map((file) => {
280
- const fileExtArr = file.name.split(".");
281
- return fileExtArr[fileExtArr.length - 1];
282
- });
283
- if (nameArr.includes(item.file)) {
284
- matchedScriptContentIndex = i;
285
- break;
286
- }
287
- }
288
- }
289
- if (matchedScriptContentIndex !== -1) {
290
- break;
291
- }
292
- }
293
- const responses = [];
294
- const matchContent = agentMatchedScripts[0].content;
295
- for (let j = matchedScriptContentIndex + 1; j < matchContent.length; j++) {
296
- const nextItem = matchContent[j];
297
- if (nextItem.user === "i") {
298
- break;
299
- }
300
- if (nextItem.user === "ai") {
301
- if (nextItem.data && nextItem.type) {
302
- responses.push({
303
- ...nextItem,
304
- // 标记需要先流式输出文字,再调用组件
305
- needSequenceProcessing: true
306
- });
307
- } else {
308
- responses.push(nextItem);
309
- }
310
- }
311
- }
312
- const nextIndex = matchContent.findIndex((contentItem, index) => index > matchedScriptContentIndex && contentItem.user === "i");
313
- return {
314
- responses,
315
- nextIndex: nextIndex === -1 ? matchContent.length : nextIndex
316
- };
317
- }
318
- } else {
319
- return {
320
- responses: [
321
- {
322
- user: "ai",
323
- data: unmatchText
324
- }
325
- ],
326
- nextIndex: -1
327
- };
328
- }
329
- }
330
- if (activeScript.value) {
331
- const result = searchInScript(activeScript.value, userInput);
332
- if (result) {
333
- return result;
334
- }
335
- }
336
- for (const script of scripts) {
337
- const result = searchInScript(script, userInput);
338
- if (result) {
339
- activeScript.value = script;
340
- return result;
341
- }
342
- }
343
- return null;
344
- };
345
- const searchInScript = (script, userInput) => {
346
- for (let i = 0; i < script.content.length; i++) {
347
- const item = script.content[i];
348
- if (item.user === "i") {
349
- const isDataMatch = item.data && userInput.includes(item.data);
350
- let isSubDataMatch = false;
351
- if (item.alias) {
352
- if (Array.isArray(item.alias)) {
353
- isSubDataMatch = item.alias.some((subItem) => subItem === userInput);
354
- }
355
- }
356
- if (isDataMatch || isSubDataMatch) {
357
- const responses = [];
358
- for (let j = i + 1; j < script.content.length; j++) {
359
- const nextItem = script.content[j];
360
- if (nextItem.user === "i") {
361
- break;
362
- }
363
- if (nextItem.user === "ai") {
364
- if (nextItem.data && nextItem.type) {
365
- responses.push({
366
- ...nextItem,
367
- // 标记需要先流式输出文字,再调用组件
368
- needSequenceProcessing: true
369
- });
370
- } else {
371
- responses.push(nextItem);
372
- }
373
- }
374
- }
375
- const nextIndex = script.content.findIndex((contentItem, index) => index > i && contentItem.user === "i");
376
- return { responses, nextIndex: nextIndex === -1 ? script.content.length : nextIndex };
377
- }
378
- } else if (item.user === "ai") {
379
- scripts.forEach((script2) => {
380
- if (script2.content.length) {
381
- const contents = script2.content;
382
- contents.forEach((item2) => {
383
- if (item2.agents) {
384
- if (item2.agents === activeAgentsName.value) {
385
- activeScript.value = script2;
386
- }
387
- }
388
- });
389
- }
390
- });
391
- }
392
- }
393
- return null;
394
- };
395
- watch(
396
- () => props.value,
397
- (newVal, oldVal) => {
398
- if (!Array.isArray(newVal))
399
- return;
400
- if (newVal.length && JSON.stringify(newVal) !== JSON.stringify(oldVal)) {
401
- chatList.value = newVal.map((item) => ({
402
- ...item,
403
- content: item.thinkContent ? item.content || "" : item.content || "",
404
- thinkContent: item.thinkContent || ""
405
- }));
406
- nextTick(() => {
407
- requestAnimationFrame(() => {
408
- chatList.value.forEach((item) => {
409
- if (item.thinkContent) {
410
- renderContent(item.thinkContent, "thinking");
411
- }
412
- if (item.reasoningContent) {
413
- renderContent(item.reasoningContent, "reasoning");
414
- }
415
- if (item.content) {
416
- renderContent(item.content, "main");
417
- }
418
- });
419
- nextTick(() => {
420
- scrollToBottom();
421
- });
422
- });
423
- });
424
- }
425
- },
426
- { deep: true, immediate: true }
427
- );
428
- const openSSE = (userContent, insertIndex, type) => {
429
- var _a, _b, _c, _d, _e, _f, _g;
430
- try {
431
- if (isUnmounting.value)
432
- return;
433
- isChating.value = true;
434
- const currentAiMessage = chatList.value.find((item) => item.isChating);
435
- if (currentAiMessage) {
436
- currentAiMessage.isShowLike = true;
437
- currentAiMessage.isShowCopy = true;
438
- currentAiMessage.componentName = currentComponentName.value;
439
- }
440
- const chatId = (currentAiMessage == null ? void 0 : currentAiMessage.chatId) || "ai_" + Math.random().toString(36).slice(2).padEnd(10, "0").slice(0, 10);
441
- let aiContent = (currentAiMessage == null ? void 0 : currentAiMessage.content) || "";
442
- let reasoningContent = (currentAiMessage == null ? void 0 : currentAiMessage.reasoningContent) || "";
443
- let allAiContent = "";
444
- if (!currentAiMessage) {
445
- const chatItem = {
446
- chatId,
447
- user: "ai",
448
- type: "text",
449
- isChating: true,
450
- content: "",
451
- thinkContent: "",
452
- reasoningContent: "",
453
- thinkStatus: ThinkStatus.THINKING,
454
- thinkStartTime: Date.now(),
455
- isShowLike: true,
456
- isShowCopy: true,
457
- componentName: currentComponentName.value,
458
- typeFlag: typeFlag.value
459
- };
460
- if (insertIndex !== void 0 && insertIndex <= chatList.value.length) {
461
- chatList.value.splice(insertIndex, 0, chatItem);
462
- } else {
463
- chatList.value.push(chatItem);
464
- }
465
- }
466
- currIndex.value = insertIndex != null ? insertIndex : chatList.value.length - 1;
467
- const BodyConfig = (_b = (_a = moduleInfo.value) == null ? void 0 : _a.config) == null ? void 0 : _b.body();
468
- if (!inputValue.value && ((_c = BodyConfig == null ? void 0 : BodyConfig.messages) == null ? void 0 : _c.length)) {
469
- BodyConfig.messages[0].content = userContent;
470
- BodyConfig.model = enableDeepThinking.value ? "deepseek-reasoner" : "deepseek-v3";
471
- }
472
- fetchStream.value = new FetchStream({
473
- url: ((_e = (_d = moduleInfo.value) == null ? void 0 : _d.config) == null ? void 0 : _e.action) ? moduleInfo.value.config.action : "https://api.apiyi.com/v1/chat/completions",
474
- requestInit: {
475
- headers: ((_g = (_f = moduleInfo.value) == null ? void 0 : _f.config) == null ? void 0 : _g.headers) ? new Headers(moduleInfo.value.config.headers()) : new Headers({
476
- "Content-Type": "application/json",
477
- Authorization: "Bearer sk-fe9MtODvds8wpzz05f3417Fe3e9641C1926e6fC588425dEd"
478
- }),
479
- // body: moduleInfo.value?.config?.body
480
- // ? JSON.stringify(BodyConfig as Record<string, any>)
481
- // : JSON.stringify({
482
- // model: enableDeepThinking.value ? 'deepseek-reasoner' : 'deepseek-v3',
483
- // messages: [
484
- // {
485
- // role: 'user',
486
- // content: userContent
487
- // }
488
- // ],
489
- // stream: true
490
- // })
491
- body: JSON.stringify(BodyConfig)
492
- },
493
- onmessage: (line) => {
494
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h, _i, _j;
495
- if (isUnmounting.value)
496
- return;
497
- let dataString = "";
498
- if (line.length) {
499
- if (line.includes("data:")) {
500
- const match = line.match(/\{[\s\S]*\}/);
501
- dataString = match ? match[0] : "";
502
- } else if (line.startsWith("{") && line.endsWith("}")) {
503
- dataString = line;
504
- }
505
- }
506
- dataString = dataString.trim();
507
- const respoKey = (_b2 = (_a2 = moduleInfo.value) == null ? void 0 : _a2.config) == null ? void 0 : _b2.respoKey();
508
- if (dataString && (dataString.startsWith("{") && dataString.endsWith("}") || !(respoKey == null ? void 0 : respoKey.content))) {
509
- try {
510
- const result = !(respoKey == null ? void 0 : respoKey.content) && moduleInfo.value ? dataString : JSON.parse(dataString);
511
- const newAiMessage = chatList.value[currIndex.value];
512
- const deepseekFlag = ((_c2 = moduleInfo.value) == null ? void 0 : _c2.name) === "deepseek-v3";
513
- if (deepseekFlag || !moduleInfo.value) {
514
- if ((_f2 = (_e2 = (_d2 = result == null ? void 0 : result.choices) == null ? void 0 : _d2[0]) == null ? void 0 : _e2.delta) == null ? void 0 : _f2.content) {
515
- aiContent += result.choices[0].delta.content;
516
- if ((newAiMessage == null ? void 0 : newAiMessage.thinkStatus) === ThinkStatus.THINKING) {
517
- newAiMessage.thinkStatus = ThinkStatus.COMPLETED;
518
- newAiMessage.thinkTime = Date.now() - (newAiMessage.thinkStartTime || Date.now());
519
- }
520
- }
521
- if ((_i = (_h = (_g2 = result == null ? void 0 : result.choices) == null ? void 0 : _g2[0]) == null ? void 0 : _h.delta) == null ? void 0 : _i.reasoning_content) {
522
- reasoningContent += result.choices[0].delta.reasoning_content;
523
- if (!(newAiMessage == null ? void 0 : newAiMessage.thinkStatus)) {
524
- newAiMessage.thinkStatus = ThinkStatus.THINKING;
525
- newAiMessage.thinkStartTime = Date.now();
526
- }
527
- }
528
- allAiContent = reasoningContent + aiContent;
529
- } else {
530
- if (respoKey && result && result[respoKey.content] && (result[respoKey.category] === respoKey.contentCategory || !result[respoKey.category])) {
531
- aiContent += result[respoKey.content];
532
- }
533
- if (result && result[respoKey.category] === "done") {
534
- resultItem.value = result;
535
- }
536
- if (result && result[respoKey.category] === "error") {
537
- const errorMessage = (_j = result[respoKey.all]) != null ? _j : "\u5F53\u524D\u7F51\u7EDC\u5F02\u5E38";
538
- const currentAiMessage2 = chatList.value[currIndex.value];
539
- if (currentAiMessage2.chatId) {
540
- currentAiMessage2.content = `<div style="color: red; display: flex; align-items: center;"><svg xmlns="http://www.w3.org/2000/svg" width="15" height="16" viewBox="0 0 15 16" fill="none">
541
- <path fill-rule="evenodd" clip-rule="evenodd" d="M7.5 15.5C11.6421 15.5 15 12.1421 15 8C15 3.85786 11.6421 0.5 7.5 0.5C3.35786 0.5 0 3.85786 0 8C0 12.1421 3.35786 15.5 7.5 15.5ZM9.7539 4.9506L10.5494 5.7461L8.2951 8.0001L10.5494 10.2539L9.7539 11.0494L7.5001 8.7951L5.2461 11.0494L4.4506 10.2539L6.7051 8.0001L4.4506 5.7461L5.2461 4.9506L7.5001 7.2051L9.7539 4.9506Z" fill="#F93920"/>
542
- </svg>${errorMessage}</div>`;
543
- currentAiMessage2.isChating = false;
544
- currentAiMessage2.componentName = "";
545
- currentAiMessage2.isShowLike = false;
546
- currentAiMessage2.isShowCopy = false;
547
- currentAiMessage2.isError = true;
548
- nextTick(() => {
549
- emit("sendMessage", [...chatList.value]);
550
- });
551
- afterSend(result);
552
- }
553
- }
554
- if (aiContent || reasoningContent) {
555
- allAiContent = aiContent + reasoningContent;
556
- }
557
- if (respoKey && result && result[respoKey.all] && result[respoKey.category] === respoKey.allCategory) {
558
- allAiContent = result[respoKey.all];
559
- }
560
- if (respoKey && result && typeof result === "string" && result !== "[DONE]") {
561
- aiContent += result;
562
- }
563
- if (respoKey && result && typeof result === "string" && result === "[DONE]") {
564
- const index = chatList.value.findIndex((ele) => ele.chatId === chatId);
565
- if (index !== -1 && chatList.value[index]) {
566
- isChating.value = false;
567
- chatList.value[index].isChating = false;
568
- emit("sendMessage", JSON.parse(JSON.stringify(chatList.value)));
569
- }
570
- }
571
- }
572
- if (chatList.value.some((ele) => ele.chatId === chatId)) {
573
- enqueueRender({
574
- mainContent: aiContent,
575
- thinkContent: "",
576
- reasoningContent
577
- });
578
- }
579
- if (type === 1) {
580
- nextTick(() => {
581
- renderContent(aiContent, "main");
582
- renderContent(reasoningContent, "reasoning");
583
- nextTick(() => {
584
- scrollToBottom();
585
- });
586
- });
587
- }
588
- } catch (error) {
589
- console.error("\u89E3\u6790SSE\u6D88\u606F\u5931\u8D25:", error);
590
- }
591
- }
592
- },
593
- ondone: () => {
594
- nextTick(() => {
595
- isChating.value = false;
596
- if (isUnmounting.value || !isMounted.value)
597
- return;
598
- const index = chatList.value.findIndex((ele) => ele.chatId === chatId);
599
- if (index !== -1 && chatList.value[index]) {
600
- chatList.value[index].isChating = false;
601
- chatList.value[index].componentName = currentComponentName.value;
602
- chatList.value[index].html = markdownToHtml(allAiContent);
603
- if (allAiContent) {
604
- if (resultItem.value) {
605
- resultItem.value.allAiContent = allAiContent;
606
- afterSend(resultItem.value);
607
- } else {
608
- afterSend({ allAiContent });
609
- }
610
- }
611
- const waitForRenderComplete = () => {
612
- if (renderQueue.value.length === 0 && !isRendering.value) {
613
- if (chatList.value.length > 0) {
614
- emit("sendMessage", JSON.parse(JSON.stringify(chatList.value)));
615
- }
616
- } else {
617
- requestAnimationFrame(waitForRenderComplete);
618
- }
619
- };
620
- waitForRenderComplete();
621
- }
622
- });
623
- },
624
- onabort: () => {
625
- handleAbort();
626
- },
627
- onerror: (response) => {
628
- handleError(response);
629
- }
630
- });
631
- } catch (error) {
632
- console.error("OpenSSE\u9519\u8BEF:", error);
633
- isChating.value = false;
634
- chatList.value[currIndex.value].content = `<div style="color: red; display: flex; align-items: center;"><svg xmlns="http://www.w3.org/2000/svg" width="15" height="16" viewBox="0 0 15 16" fill="none">
635
- <path fill-rule="evenodd" clip-rule="evenodd" d="M7.5 15.5C11.6421 15.5 15 12.1421 15 8C15 3.85786 11.6421 0.5 7.5 0.5C3.35786 0.5 0 3.85786 0 8C0 12.1421 3.35786 15.5 7.5 15.5ZM9.7539 4.9506L10.5494 5.7461L8.2951 8.0001L10.5494 10.2539L9.7539 11.0494L7.5001 8.7951L5.2461 11.0494L4.4506 10.2539L6.7051 8.0001L4.4506 5.7461L5.2461 4.9506L7.5001 7.2051L9.7539 4.9506Z" fill="#F93920"/>
636
- </svg>${"\u8BF7\u6C42\u5931\u8D25"}</div>`;
637
- chatList.value[currIndex.value].isChating = false;
638
- chatList.value[currIndex.value].isShowCopy = false;
639
- chatList.value[currIndex.value].isShowLike = false;
640
- showToast("\u8BF7\u6C42\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5", "error", 3e3);
641
- }
642
- };
643
- const handleAbort = () => {
644
- isChating.value = false;
645
- if (isUnmounting.value)
646
- return;
647
- const currentAiMessage = chatList.value[currIndex.value];
648
- stop(chatList.value[currIndex.value], currIndex.value);
649
- const hasContent = currentAiMessage && (currentAiMessage.content || currentAiMessage.thinkContent || currentAiMessage.reasoningContent);
650
- if (currentAiMessage) {
651
- if (currentAiMessage.thinkStatus === ThinkStatus.THINKING) {
652
- currentAiMessage.thinkStatus = ThinkStatus.STOPPED;
653
- currentAiMessage.thinkTime = Date.now() - (currentAiMessage.thinkStartTime || Date.now());
654
- }
655
- if (!hasContent) {
656
- const userMessageIndex = currIndex.value - 1;
657
- if (userMessageIndex >= 0 && chatList.value[userMessageIndex].user === "u") {
658
- chatList.value.splice(currIndex.value, 1);
659
- chatList.value.splice(userMessageIndex, 1);
660
- } else {
661
- chatList.value.splice(currIndex.value, 1);
662
- }
663
- } else {
664
- const updatedAiMessage = {
665
- ...currentAiMessage,
666
- isChating: false,
667
- content: currentAiMessage.content ? currentAiMessage.content + "..." : "",
668
- thinkContent: currentAiMessage.thinkContent ? currentAiMessage.thinkContent + "..." : void 0,
669
- reasoningContent: currentAiMessage.reasoningContent ? currentAiMessage.reasoningContent + "..." : void 0,
670
- thinkStatus: currentAiMessage.thinkStatus,
671
- stop: true
672
- };
673
- chatList.value.splice(currIndex.value, 1, updatedAiMessage);
674
- nextTick(() => {
675
- renderContent(updatedAiMessage.thinkContent || "", "thinking");
676
- renderContent(updatedAiMessage.reasoningContent || "", "reasoning");
677
- renderContent(updatedAiMessage.content || "", "main");
678
- emit("sendMessage", [...chatList.value]);
679
- });
680
- return;
681
- }
682
- }
683
- if (chatList.value.length > 0) {
684
- emit("sendMessage", [...chatList.value]);
685
- }
686
- };
687
- const handleError = (response) => {
688
- if (isUnmounting.value)
689
- return;
690
- isChating.value = false;
691
- let errorMessage = "\u672A\u77E5\u9519\u8BEF";
692
- if (response instanceof Error) {
693
- console.error("API\u8BF7\u6C42\u9519\u8BEF:", response);
694
- errorMessage = response.message;
695
- } else if (response instanceof Response) {
696
- console.error("API\u8BF7\u6C42\u9519\u8BEF, \u54CD\u5E94\u72B6\u6001:", response.status, response.statusText);
697
- errorMessage = `\u8BF7\u6C42\u5931\u8D25: ${response.status} ${response.statusText}`;
698
- }
699
- const currentAiMessage = chatList.value[currIndex.value];
700
- if (currentAiMessage) {
701
- currentAiMessage.content = `<div style="color: red; display: flex; align-items: center;"><svg xmlns="http://www.w3.org/2000/svg" width="15" height="16" viewBox="0 0 15 16" fill="none">
702
- <path fill-rule="evenodd" clip-rule="evenodd" d="M7.5 15.5C11.6421 15.5 15 12.1421 15 8C15 3.85786 11.6421 0.5 7.5 0.5C3.35786 0.5 0 3.85786 0 8C0 12.1421 3.35786 15.5 7.5 15.5ZM9.7539 4.9506L10.5494 5.7461L8.2951 8.0001L10.5494 10.2539L9.7539 11.0494L7.5001 8.7951L5.2461 11.0494L4.4506 10.2539L6.7051 8.0001L4.4506 5.7461L5.2461 4.9506L7.5001 7.2051L9.7539 4.9506Z" fill="#F93920"/>
703
- </svg>${errorMessage}</div>`;
704
- currentAiMessage.isChating = false;
705
- currentAiMessage.componentName = "";
706
- currentAiMessage.isShowLike = false;
707
- currentAiMessage.isShowCopy = false;
708
- currentAiMessage.isError = true;
709
- nextTick(() => {
710
- renderContent(currentAiMessage.content || "", "main");
711
- emit("sendMessage", [...chatList.value]);
712
- });
713
- } else {
714
- showToast(errorMessage, "error", 3e3);
715
- emit("sendMessage", [...chatList.value]);
716
- }
717
- };
718
- const enqueueRender = (data) => {
719
- if (isUnmounting.value || !isMounted.value)
720
- return;
721
- if (currIndex.value < 0 || currIndex.value >= chatList.value.length)
722
- return;
723
- renderQueue.value.push(data);
724
- if (!isRendering.value) {
725
- isRendering.value = true;
726
- processRenderQueue();
727
- }
728
- };
729
- const processRenderQueue = () => {
730
- if (isUnmounting.value || !isMounted.value) {
731
- renderQueue.value = [];
732
- isRendering.value = false;
733
- return;
734
- }
735
- if (renderQueue.value.length === 0) {
736
- isRendering.value = false;
737
- return;
738
- }
739
- requestAnimationFrame(() => {
740
- const data = renderQueue.value.shift();
741
- if (data) {
742
- formatMarkdown(data);
743
- }
744
- processRenderQueue();
745
- });
746
- };
747
- const formatMarkdown = (data) => {
748
- if (!isMounted.value)
749
- return;
750
- if (currIndex.value < 0 || currIndex.value >= chatList.value.length)
751
- return;
752
- const currentItem = chatList.value[currIndex.value];
753
- if (!currentItem.isError) {
754
- currentItem.thinkContent = data.thinkContent;
755
- currentItem.content = data.mainContent;
756
- currentItem.reasoningContent = data.reasoningContent;
757
- }
758
- nextTick(() => {
759
- const thinkingContainer = thinkingContentRef.value[currIndex.value];
760
- if (thinkingContainer) {
761
- if (data.thinkContent && !currentItem.isError) {
762
- renderContent(data.thinkContent, "thinking");
763
- thinkingContainer.style.display = "block";
764
- thinkingContainer.style.visibility = "visible";
765
- } else {
766
- thinkingContainer.style.display = "none";
767
- thinkingContainer.style.visibility = "hidden";
768
- }
769
- }
770
- const reasoningContainer = reasoningContentRef.value[currIndex.value];
771
- if (reasoningContainer) {
772
- if (data.reasoningContent && !currentItem.isError) {
773
- renderContent(data.reasoningContent, "reasoning");
774
- reasoningContainer.style.display = "block";
775
- reasoningContainer.style.visibility = "visible";
776
- } else {
777
- reasoningContainer.style.display = "none";
778
- reasoningContainer.style.visibility = "hidden";
779
- }
780
- }
781
- renderContent(currentItem.isError ? currentItem.content : data.mainContent, "main");
782
- });
783
- };
47
+ const {
48
+ chatList,
49
+ isChating,
50
+ inputValue,
51
+ enableDeepThinking,
52
+ activeAgentsName,
53
+ init,
54
+ sendMessage,
55
+ handleBeforeSend,
56
+ handleSend,
57
+ handleStop,
58
+ handleMessageAction,
59
+ saveEdit,
60
+ cancelEdit,
61
+ completeRendered,
62
+ handleAgentSelect,
63
+ update,
64
+ updateModule,
65
+ handleDragEnter,
66
+ handleDragLeave,
67
+ handleDrop,
68
+ handleScroll,
69
+ onMounted: chatOnMounted,
70
+ onBeforeUnmount: chatOnBeforeUnmount
71
+ } = useChat({
72
+ props,
73
+ emit,
74
+ scripts: scripts.value,
75
+ unmatchText,
76
+ modules: modules.value,
77
+ afterSend,
78
+ sendMessageInject,
79
+ beforeSend,
80
+ bottom,
81
+ stop,
82
+ chatContainer,
83
+ chatInputRef: ChatInputRef
84
+ });
85
+ const { copyWithFeedback } = useCopy();
86
+ const modelChangeExternal = inject("modelChange", () => {
87
+ });
88
+ provide("modelChange", (item, index) => {
89
+ modelChangeExternal(item, index);
90
+ updateModule(item);
91
+ });
784
92
  const attachCopyButtons = (container) => {
785
93
  const codeBlocks = container.querySelectorAll("pre code");
786
94
  codeBlocks.forEach((codeBlock) => {
@@ -790,403 +98,23 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
790
98
  copyBtn.className = "touchchat-code-copy";
791
99
  copyBtn.addEventListener("click", () => {
792
100
  const code = codeBlock.textContent || "";
793
- navigator.clipboard.writeText(code).then(() => {
794
- showToast("\u590D\u5236\u6210\u529F", "info", 2e3);
795
- copyBtn.textContent = "\u5DF2\u590D\u5236";
796
- setTimeout(() => {
797
- copyBtn.textContent = "";
798
- }, 2e3);
799
- }).catch((err) => {
800
- console.error("\u590D\u5236\u5931\u8D25:", err);
801
- showToast("\u590D\u5236\u5931\u8D25", "error", 2e3);
802
- });
101
+ copyWithFeedback(code, copyBtn, "", "\u5DF2\u590D\u5236", 2e3);
803
102
  });
804
103
  pre.style.position = "relative";
805
104
  pre.appendChild(copyBtn);
806
105
  }
807
106
  });
808
107
  };
809
- const renderContent = (content, type, index) => {
810
- const renderIndex = index != null ? index : currIndex.value;
811
- if (renderIndex < 0 || renderIndex >= chatList.value.length)
812
- return;
813
- const refArrays = {
814
- main: htmlContentRef,
815
- thinking: thinkingContentRef,
816
- reasoning: reasoningContentRef
817
- };
818
- const processors = {
819
- main: (content2) => {
820
- var _a;
821
- return ((_a = markdown) == null ? void 0 : _a.render(content2, { isReasoning: false })) || "";
822
- },
823
- thinking: (content2) => {
824
- var _a;
825
- return ((_a = markdown) == null ? void 0 : _a.render(content2, { isReasoning: false })) || "";
826
- },
827
- reasoning: (content2) => {
828
- var _a;
829
- return ((_a = markdown) == null ? void 0 : _a.render(content2, { isReasoning: false })) || "";
830
- }
831
- };
832
- const container = refArrays[type].value[renderIndex];
833
- if (!container)
834
- return;
835
- container.innerHTML = processors[type](content || "");
836
- attachCopyButtons(container);
837
- };
838
- const sendMessage = (content, fileList, auto, type) => {
839
- inputValue.value = content || "";
840
- handleBeforeSend(content, fileList, auto, type);
841
- };
842
- const handleBeforeSend = (content, fileList, auto, type) => {
843
- fileData.value = fileList || [];
844
- if (beforeSend) {
845
- const fn = beforeSend();
846
- if (fn && typeof fn.then === "function") {
847
- Promise.resolve(fn).then((res) => {
848
- if (res.result) {
849
- currentComponentName.value = res.componentName || "";
850
- handleSend(content, fileList, auto, type);
851
- }
852
- }).catch((error) => {
853
- console.log(error);
854
- });
855
- } else {
856
- if (fn.result) {
857
- currentComponentName.value = fn.componentName || "";
858
- handleSend(content, fileList, auto, type);
859
- }
860
- }
861
- }
862
- };
863
- const handleSend = (content, fileList, auto, type) => {
864
- emit("beforeSendMessage");
865
- sendMessageInject(inputValue.value, fileData.value);
866
- typeFlag.value = type || "";
867
- if (scripts && Array.isArray(scripts) && scripts.length > 0) {
868
- const userInput = content ? content.replace(/\n/g, "") : inputValue.value.replace(/\n/g, "").trim();
869
- if (!userInput && !(fileList == null ? void 0 : fileList.length) && auto)
870
- return;
871
- const userChatId = `user_${Date.now()}`;
872
- const userMessage = {
873
- chatId: userChatId,
874
- user: "u",
875
- type: "text",
876
- content: userInput,
877
- isShowLike: false,
878
- isShowCopy: true,
879
- files: fileList || [],
880
- typeFlag: type,
881
- auto: auto || false
882
- };
883
- chatList.value.push(userMessage);
884
- emit("sendMessage", [...chatList.value]);
885
- nextTick(() => {
886
- renderContent(userMessage.content, "main", chatList.value.length - 1);
887
- nextTick(() => {
888
- scrollToBottom();
889
- });
890
- });
891
- const result = findMatchingScriptContent(userInput);
892
- if (result && result.responses.length > 0) {
893
- const newAiMessages = [];
894
- result.responses.forEach((response, idx) => {
895
- const pauseMarker = Array.isArray(response.data) ? "\u200B".repeat(20) : "";
896
- const content2 = Array.isArray(response.data) ? response.data.join(pauseMarker) : response.data;
897
- const aiChatId = `ai_${Date.now()}_${idx}`;
898
- const aiMessage = {
899
- chatId: aiChatId,
900
- user: "ai",
901
- type: "text",
902
- content: content2 || "",
903
- // componentName: response.needSequenceProcessing ? '' : response.type || '',
904
- componentName: response.type || "",
905
- isShowLike: true,
906
- isShowCopy: true,
907
- needSequenceType: response.type || "",
908
- needSequenceProcessing: response.needSequenceProcessing || false,
909
- typeFlag: type
910
- };
911
- newAiMessages.push(aiMessage);
912
- });
913
- let messageQueue = [...newAiMessages];
914
- let isProcessing = false;
915
- let currentMessage = null;
916
- const processNextMessage = () => {
917
- if (messageQueue.length > 0 && !isProcessing) {
918
- isProcessing = true;
919
- const nextMessage = messageQueue.shift();
920
- if (nextMessage) {
921
- currentMessage = nextMessage;
922
- console.log("\u5F00\u59CB\u5904\u7406\u6D88\u606F:", currentMessage.chatId);
923
- chatList.value.push(currentMessage);
924
- emit("sendMessage", [...chatList.value]);
925
- const msgIndex = chatList.value.length - 1;
926
- nextTick(() => {
927
- renderContent((currentMessage == null ? void 0 : currentMessage.content) || "", "main", msgIndex);
928
- nextTick(() => {
929
- scrollToBottom();
930
- if (currentMessage) {
931
- const messageToProcess = {
932
- ...currentMessage,
933
- needSequenceProcessing: true
934
- };
935
- simulateStreamOutput(msgIndex, messageToProcess);
936
- }
937
- });
938
- });
939
- }
940
- }
941
- };
942
- const handleMessageComplete = (chatId) => {
943
- if (currentMessage && currentMessage.chatId === chatId) {
944
- console.log("\u5E8F\u5217\u6D88\u606F\u5904\u7406\u5B8C\u6210\uFF0C\u5904\u7406\u4E0B\u4E00\u6761:", chatId);
945
- currentMessage = null;
946
- isProcessing = false;
947
- processNextMessage();
948
- }
949
- };
950
- const processorObj = {
951
- messageQueue,
952
- isProcessing,
953
- currentMessage,
954
- processNextMessage,
955
- handleMessageComplete
956
- };
957
- currentMessageProcessor.value = processorObj;
958
- processNextMessage();
959
- } else {
960
- const defaultAiChatId = `ai_${Date.now()}`;
961
- const defaultAiMessage = {
962
- chatId: defaultAiChatId,
963
- user: "ai",
964
- type: "text",
965
- content: unmatchText,
966
- isShowLike: true,
967
- isShowCopy: true
968
- };
969
- chatList.value.push(defaultAiMessage);
970
- emit("sendMessage", [...chatList.value]);
971
- nextTick(() => {
972
- const msgIndex = chatList.value.findIndex((item) => item.chatId === defaultAiChatId);
973
- if (msgIndex !== -1) {
974
- renderContent(defaultAiMessage.content, "main", msgIndex);
975
- nextTick(() => {
976
- scrollToBottom();
977
- });
978
- }
979
- });
980
- }
981
- inputValue.value = "";
982
- } else {
983
- if (content) {
984
- inputValue.value = content;
985
- }
986
- if ((isChating.value || !inputValue.value.trim() && !(fileList == null ? void 0 : fileList.length)) && !auto)
987
- return;
988
- const userChatId = "user_" + Math.random().toString(36).slice(2).padEnd(10, "0").slice(0, 10);
989
- const userMessage = {
990
- chatId: userChatId,
991
- user: "u",
992
- type: "text",
993
- content: inputValue.value,
994
- files: fileList || []
995
- };
996
- chatList.value.push(userMessage);
997
- const index = chatList.value.length - 1;
998
- nextTick(() => {
999
- renderContent(userMessage.content, "main", index);
1000
- scrollToBottom();
1001
- });
1002
- openSSE(inputValue.value, index + 1, 1);
1003
- inputValue.value = "";
1004
- }
1005
- };
1006
- const handleStop = () => {
1007
- var _a, _b;
1008
- (_a = fetchStream.value) == null ? void 0 : _a.abort();
1009
- const aiIndex = chatList.value.findIndex((item) => item.isChating);
1010
- if (aiIndex !== -1) {
1011
- const currentAiMessage = chatList.value[aiIndex];
1012
- if ((_b = currentAiMessage.content) == null ? void 0 : _b.trim()) {
1013
- nextTick(() => {
1014
- chatList.value[aiIndex] = {
1015
- ...currentAiMessage,
1016
- content: currentAiMessage.content + "...",
1017
- isChating: false
1018
- };
1019
- renderContent(chatList.value[aiIndex].content, "main", aiIndex);
1020
- emit("sendMessage", chatList.value);
1021
- });
1022
- } else {
1023
- if (aiIndex > 0) {
1024
- const userMessageIndex = aiIndex - 1;
1025
- if (chatList.value[userMessageIndex].user === "u") {
1026
- chatList.value.splice(userMessageIndex, 2);
1027
- } else {
1028
- chatList.value.splice(aiIndex, 1);
1029
- }
1030
- } else {
1031
- chatList.value.splice(aiIndex, 1);
1032
- }
1033
- }
1034
- } else {
1035
- const lastIndex = chatList.value.length - 1;
1036
- if (lastIndex >= 0 && chatList.value[lastIndex].user === "u") {
1037
- chatList.value.pop();
1038
- }
1039
- }
1040
- isChating.value = false;
1041
- };
1042
- const scrollObserver = ref(null);
1043
- const scrollToBottom = () => {
1044
- if (!isMounted.value || isUnmounting.value || !chatContainer.value)
1045
- return;
1046
- nextTick(() => {
1047
- requestAnimationFrame(() => {
1048
- const chatContainerEl = chatContainer.value;
1049
- const lastMessage = chatContainerEl.querySelector(".touchchat-dialog-content > *:last-child");
1050
- if (lastMessage) {
1051
- const { height: messageHeight } = lastMessage.getBoundingClientRect();
1052
- const containerHeight = chatContainerEl.clientHeight;
1053
- const messageBottom = lastMessage.offsetTop + lastMessage.offsetHeight;
1054
- if (messageHeight > containerHeight) {
1055
- chatContainerEl.scrollTop = lastMessage.offsetTop;
1056
- } else {
1057
- chatContainerEl.scrollTop = messageBottom - containerHeight;
1058
- }
1059
- if (scrollObserver.value) {
1060
- scrollObserver.value.disconnect();
1061
- }
1062
- scrollObserver.value = new MutationObserver(() => {
1063
- const updatedMessageBottom = lastMessage.offsetTop + lastMessage.offsetHeight;
1064
- chatContainerEl.scrollTop = Math.max(updatedMessageBottom - containerHeight, chatContainerEl.scrollTop);
1065
- });
1066
- scrollObserver.value.observe(lastMessage, {
1067
- childList: true,
1068
- subtree: true,
1069
- characterData: true,
1070
- attributes: true,
1071
- // 新增监听属性变化(如高度)
1072
- attributeFilter: ["style", "class"]
1073
- // 只监听样式相关属性
1074
- });
1075
- } else {
1076
- chatContainerEl.scrollTo({
1077
- top: chatContainerEl.scrollHeight,
1078
- behavior: "smooth"
1079
- });
1080
- }
1081
- });
1082
- });
1083
- };
1084
- const handleMessageAction = (action, index) => {
1085
- const message = chatList.value[index];
1086
- if (!message)
1087
- return;
1088
- switch (action) {
1089
- case MessageAction.COPY: {
1090
- const textContent = message.content;
1091
- navigator.clipboard.writeText(textContent).then(() => {
1092
- showToast("\u590D\u5236\u6210\u529F", "info");
1093
- }).catch((err) => {
1094
- console.error("\u590D\u5236\u5931\u8D25:", err);
1095
- showToast("\u590D\u5236\u5931\u8D25", "error");
1096
- });
1097
- break;
1098
- }
1099
- case MessageAction.EDIT:
1100
- message.isEditing = true;
1101
- message.editContent = message.content;
1102
- break;
1103
- case MessageAction.DELETE:
1104
- messageUtils.deleteMessageChain(index);
1105
- emit("sendMessage", chatList.value);
1106
- break;
1107
- case MessageAction.RETRY: {
1108
- const aiMessage = chatList.value[index];
1109
- const userMessageIndex = index - 1;
1110
- const userMessage = chatList.value[userMessageIndex];
1111
- if (userMessage && userMessage.user === "u") {
1112
- const updatedAiMessage = {
1113
- ...aiMessage,
1114
- content: "",
1115
- thinkContent: "",
1116
- reasoningContent: "",
1117
- isLiked: false,
1118
- isDisliked: false,
1119
- isChating: true,
1120
- chatId: aiMessage.chatId,
1121
- user: aiMessage.user,
1122
- type: aiMessage.type,
1123
- thinkStatus: ThinkStatus.COMPLETED,
1124
- thinkStartTime: 0,
1125
- thinkEndTime: 0
1126
- };
1127
- chatList.value.splice(index, 1, updatedAiMessage);
1128
- nextTick(() => {
1129
- if (htmlContentRef.value[index])
1130
- htmlContentRef.value[index].innerHTML = "";
1131
- if (thinkingContentRef.value[index])
1132
- thinkingContentRef.value[index].innerHTML = "";
1133
- if (reasoningContentRef.value[index])
1134
- reasoningContentRef.value[index].innerHTML = "";
1135
- setTimeout(() => {
1136
- openSSE(userMessage.content || "", index, 2);
1137
- }, 50);
1138
- });
1139
- }
1140
- break;
1141
- }
1142
- case MessageAction.LIKE:
1143
- messageUtils.updateMessage(index, {
1144
- isLiked: true,
1145
- isDisliked: false
1146
- });
1147
- break;
1148
- case MessageAction.DISLIKE:
1149
- messageUtils.updateMessage(index, {
1150
- isLiked: false,
1151
- isDisliked: true
1152
- });
1153
- break;
1154
- }
108
+ const toggleSidebarClick = (item, index) => {
109
+ emit("toggleSidebar", item, index);
1155
110
  };
1156
- const saveEdit = (index, newContent) => {
1157
- const message = chatList.value[index];
1158
- if (!message || !message.editContent)
1159
- return;
1160
- chatList.value[index] = {
1161
- ...message,
1162
- content: newContent,
1163
- isEditing: false,
1164
- editContent: void 0
1165
- };
1166
- nextTick(() => {
1167
- renderContent(message.content, "main", index);
1168
- });
1169
- if (index + 1 < chatList.value.length && chatList.value[index + 1].user === "ai") {
1170
- chatList.value.splice(index + 1, 1);
111
+ const itemUploadFile = (_item, index) => {
112
+ if (ChatInputRef.value) {
113
+ ChatInputRef.value.itemUploadFile(index, "drop");
1171
114
  }
1172
- openSSE(newContent, index + 1);
1173
- emit("sendMessage", chatList.value);
1174
- };
1175
- const cancelEdit = (index) => {
1176
- const message = chatList.value[index];
1177
- if (!message)
1178
- return;
1179
- message.isEditing = false;
1180
- message.editContent = "";
1181
- nextTick(() => {
1182
- renderContent(message.content, "main", index);
1183
- });
1184
115
  };
1185
- onMounted(async () => {
1186
- if (isMounted.value) {
1187
- init();
1188
- }
1189
- isMounted.value = true;
116
+ onMounted(() => {
117
+ chatOnMounted();
1190
118
  watch(
1191
119
  () => scripts,
1192
120
  () => {
@@ -1196,84 +124,8 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
1196
124
  );
1197
125
  });
1198
126
  onBeforeUnmount(() => {
1199
- if (!isUnmounting.value) {
1200
- isUnmounting.value = true;
1201
- if (fetchStream.value) {
1202
- fetchStream.value.abort();
1203
- fetchStream.value = null;
1204
- }
1205
- if (TouchChatRobot.value) {
1206
- TouchChatRobot.value.close();
1207
- TouchChatRobot.value = void 0;
1208
- }
1209
- isMounted.value = false;
1210
- renderQueue.value = [];
1211
- htmlContentRef.value = [];
1212
- thinkingContentRef.value = [];
1213
- reasoningContentRef.value = [];
1214
- }
1215
- if (scrollObserver.value) {
1216
- scrollObserver.value.disconnect();
1217
- scrollObserver.value = null;
1218
- }
127
+ chatOnBeforeUnmount();
1219
128
  });
1220
- const handleDragEnter = () => {
1221
- if (ChatInputRef.value) {
1222
- ChatInputRef.value.openMarkLayer();
1223
- }
1224
- isDragging.value = true;
1225
- };
1226
- const handleDragLeave = (e) => {
1227
- const rect = e.target.getBoundingClientRect();
1228
- if (e.clientX < rect.left || e.clientX > rect.right || e.clientY < rect.top || e.clientY > rect.bottom) {
1229
- isDragging.value = false;
1230
- }
1231
- };
1232
- const handleDrop = async (e) => {
1233
- var _a;
1234
- isDragging.value = false;
1235
- const files = (_a = e.dataTransfer) == null ? void 0 : _a.files;
1236
- if (files && files.length > 0) {
1237
- const fileList = await Promise.all(
1238
- Array.from(files).map(async (file) => {
1239
- let base64 = "";
1240
- if (file.type.startsWith("image/")) {
1241
- base64 = await new Promise((resolve) => {
1242
- const reader = new FileReader();
1243
- reader.onload = (e2) => {
1244
- var _a2;
1245
- resolve((_a2 = e2.target) == null ? void 0 : _a2.result);
1246
- };
1247
- reader.readAsDataURL(file);
1248
- });
1249
- }
1250
- return {
1251
- // id: crypto.randomUUID().replace(/-/gi, ''),
1252
- id: Math.random().toString(36).slice(2).padEnd(10, "0").slice(0, 10),
1253
- file,
1254
- name: file.name,
1255
- fileType: file.type,
1256
- fileSize: file.size,
1257
- lastModified: file.lastModified,
1258
- preview: URL.createObjectURL(file),
1259
- base64
1260
- };
1261
- })
1262
- );
1263
- if (ChatInputRef.value) {
1264
- ChatInputRef.value.handlePaste(fileList, "drop");
1265
- }
1266
- }
1267
- if (ChatInputRef.value) {
1268
- ChatInputRef.value.colseMarkLayer();
1269
- }
1270
- };
1271
- const itemUploadFile = (item, index) => {
1272
- console.log("itemUploadFile", item, index);
1273
- if (ChatInputRef.value) {
1274
- ChatInputRef.value.itemUploadFile(index, "drop");
1275
- }
1276
- };
1277
129
  provide("touchchat", {
1278
130
  send: sendMessage,
1279
131
  retry: handleMessageAction
@@ -1293,118 +145,112 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
1293
145
  class: "touchchat-main",
1294
146
  onDragover: withModifiers(() => {
1295
147
  }, ["prevent"]),
1296
- onDragenter: withModifiers(handleDragEnter, ["prevent"]),
1297
- onDragleave: handleDragLeave,
1298
- onDrop: withModifiers(handleDrop, ["prevent"])
148
+ onDragenter: withModifiers(unref(handleDragEnter), ["prevent"]),
149
+ onDragleave: unref(handleDragLeave),
150
+ onDrop: withModifiers(unref(handleDrop), ["prevent"])
1299
151
  }, [
1300
- createElementVNode(
1301
- "div",
1302
- {
1303
- ref_key: "chatContainer",
1304
- ref: chatContainer,
1305
- class: "touchchat-dialog",
1306
- onScroll: handleScroll
1307
- },
1308
- [
1309
- renderSlot(_ctx.$slots, "top"),
1310
- chatList.value.length === 0 ? (openBlock(), createElementBlock("div", {
1311
- key: 0,
1312
- class: "touchchat-welcome"
1313
- }, [
1314
- renderSlot(_ctx.$slots, "welcome", {}, () => [
1315
- createVNode(HelloChat, { onSendMessage: sendMessage })
1316
- ])
1317
- ])) : createCommentVNode("v-if", true),
1318
- createElementVNode("div", { class: "touchchat-dialog-content" }, [
1319
- (openBlock(true), createElementBlock(
1320
- Fragment,
1321
- null,
1322
- renderList(chatList.value, (item, index) => {
1323
- return openBlock(), createElementBlock(
1324
- Fragment,
1325
- {
1326
- key: item.chatId
1327
- },
1328
- [
1329
- item.user === "u" ? (openBlock(), createBlock(UserMessage, {
1330
- key: 0,
1331
- item,
1332
- index,
1333
- onUserMessageFileList: itemUploadFile,
1334
- onCopy: ($event) => handleMessageAction(unref(MessageAction).COPY, index),
1335
- onEdit: ($event) => handleMessageAction(unref(MessageAction).EDIT, index),
1336
- onDelete: ($event) => handleMessageAction(unref(MessageAction).DELETE, index),
1337
- onSaveEdit: saveEdit,
1338
- onCancelEdit: ($event) => cancelEdit(index)
1339
- }, {
1340
- userAvatar: withCtx(() => [
1341
- renderSlot(_ctx.$slots, "userAvatar")
1342
- ]),
1343
- fn: withCtx(() => [
1344
- renderSlot(_ctx.$slots, "fn", {
1345
- item,
1346
- index
1347
- })
1348
- ]),
1349
- _: 2
1350
- /* DYNAMIC */
1351
- }, 1032, ["item", "index", "onCopy", "onEdit", "onDelete", "onCancelEdit"])) : (openBlock(), createBlock(AiMessage, {
1352
- key: 1,
1353
- item,
1354
- index,
1355
- "enable-deep-thinking": enableDeepThinking.value,
1356
- "has-retry": activeAgentsName.value || unref(scripts).length > 0 ? false : true,
1357
- onCopy: ($event) => handleMessageAction(unref(MessageAction).COPY, index),
1358
- onRetry: ($event) => handleMessageAction(unref(MessageAction).RETRY, index),
1359
- onLike: ($event) => handleMessageAction(unref(MessageAction).LIKE, index),
1360
- onDislike: ($event) => handleMessageAction(unref(MessageAction).DISLIKE, index),
1361
- onContentRendered: attachCopyButtons,
1362
- onCompleteRendered: (chatId) => completeRendered(chatId),
1363
- onToggleSidebar: toggleSidebarClick
1364
- }, {
1365
- aimsg: withCtx(() => [
1366
- renderSlot(_ctx.$slots, "aimsg", {
1367
- item,
1368
- index
1369
- })
1370
- ]),
1371
- msg: withCtx(() => [
1372
- renderSlot(_ctx.$slots, "msg", {
1373
- item,
1374
- index
1375
- })
1376
- ]),
1377
- aiAvatar: withCtx(() => [
1378
- renderSlot(_ctx.$slots, "aiAvatar")
1379
- ]),
1380
- fn: withCtx(() => [
1381
- renderSlot(_ctx.$slots, "fn", {
1382
- item,
1383
- index
1384
- })
1385
- ]),
1386
- extendsFn: withCtx(() => [
1387
- renderSlot(_ctx.$slots, "extendsFn", {
1388
- item,
1389
- index
1390
- })
1391
- ]),
1392
- _: 2
1393
- /* DYNAMIC */
1394
- }, 1032, ["item", "index", "enable-deep-thinking", "has-retry", "onCopy", "onRetry", "onLike", "onDislike", "onCompleteRendered"]))
1395
- ],
1396
- 64
1397
- /* STABLE_FRAGMENT */
1398
- );
1399
- }),
1400
- 128
1401
- /* KEYED_FRAGMENT */
1402
- ))
152
+ createElementVNode("div", {
153
+ ref_key: "chatContainer",
154
+ ref: chatContainer,
155
+ class: "touchchat-dialog",
156
+ onScroll: unref(handleScroll)
157
+ }, [
158
+ renderSlot(_ctx.$slots, "top"),
159
+ unref(chatList).length === 0 ? (openBlock(), createElementBlock("div", {
160
+ key: 0,
161
+ class: "touchchat-welcome"
162
+ }, [
163
+ renderSlot(_ctx.$slots, "welcome", {}, () => [
164
+ createVNode(HelloChat, { onSendMessage: unref(sendMessage) }, null, 8, ["onSendMessage"])
1403
165
  ])
1404
- ],
1405
- 544
1406
- /* NEED_HYDRATION, NEED_PATCH */
1407
- ),
166
+ ])) : createCommentVNode("v-if", true),
167
+ createElementVNode("div", { class: "touchchat-dialog-content" }, [
168
+ (openBlock(true), createElementBlock(
169
+ Fragment,
170
+ null,
171
+ renderList(unref(chatList), (item, index) => {
172
+ return openBlock(), createElementBlock(
173
+ Fragment,
174
+ {
175
+ key: item.chatId
176
+ },
177
+ [
178
+ item.user === "u" ? (openBlock(), createBlock(UserMessage, {
179
+ key: 0,
180
+ item,
181
+ index,
182
+ onUserMessageFileList: itemUploadFile,
183
+ onCopy: ($event) => unref(handleMessageAction)(unref(MessageAction).COPY, index),
184
+ onEdit: ($event) => unref(handleMessageAction)(unref(MessageAction).EDIT, index),
185
+ onDelete: ($event) => unref(handleMessageAction)(unref(MessageAction).DELETE, index),
186
+ onSaveEdit: unref(saveEdit),
187
+ onCancelEdit: ($event) => unref(cancelEdit)(index)
188
+ }, {
189
+ userAvatar: withCtx(() => [
190
+ renderSlot(_ctx.$slots, "userAvatar")
191
+ ]),
192
+ fn: withCtx(() => [
193
+ renderSlot(_ctx.$slots, "fn", {
194
+ item,
195
+ index
196
+ })
197
+ ]),
198
+ _: 2
199
+ /* DYNAMIC */
200
+ }, 1032, ["item", "index", "onCopy", "onEdit", "onDelete", "onSaveEdit", "onCancelEdit"])) : (openBlock(), createBlock(AiMessage, {
201
+ key: 1,
202
+ item,
203
+ index,
204
+ "enable-deep-thinking": unref(enableDeepThinking),
205
+ "has-retry": unref(activeAgentsName) || scriptsLength.value > 0 ? false : true,
206
+ onCopy: ($event) => unref(handleMessageAction)(unref(MessageAction).COPY, index),
207
+ onRetry: ($event) => unref(handleMessageAction)(unref(MessageAction).RETRY, index),
208
+ onLike: ($event) => unref(handleMessageAction)(unref(MessageAction).LIKE, index),
209
+ onDislike: ($event) => unref(handleMessageAction)(unref(MessageAction).DISLIKE, index),
210
+ onContentRendered: attachCopyButtons,
211
+ onCompleteRendered: unref(completeRendered),
212
+ onToggleSidebar: toggleSidebarClick
213
+ }, {
214
+ aimsg: withCtx(() => [
215
+ renderSlot(_ctx.$slots, "aimsg", {
216
+ item,
217
+ index
218
+ })
219
+ ]),
220
+ msg: withCtx(() => [
221
+ renderSlot(_ctx.$slots, "msg", {
222
+ item,
223
+ index
224
+ })
225
+ ]),
226
+ aiAvatar: withCtx(() => [
227
+ renderSlot(_ctx.$slots, "aiAvatar")
228
+ ]),
229
+ fn: withCtx(() => [
230
+ renderSlot(_ctx.$slots, "fn", {
231
+ item,
232
+ index
233
+ })
234
+ ]),
235
+ extendsFn: withCtx(() => [
236
+ renderSlot(_ctx.$slots, "extendsFn", {
237
+ item,
238
+ index
239
+ })
240
+ ]),
241
+ _: 2
242
+ /* DYNAMIC */
243
+ }, 1032, ["item", "index", "enable-deep-thinking", "has-retry", "onCopy", "onRetry", "onLike", "onDislike", "onCompleteRendered"]))
244
+ ],
245
+ 64
246
+ /* STABLE_FRAGMENT */
247
+ );
248
+ }),
249
+ 128
250
+ /* KEYED_FRAGMENT */
251
+ ))
252
+ ])
253
+ ], 40, ["onScroll"]),
1408
254
  _ctx.$slots.shortcut ? (openBlock(), createElementBlock("div", {
1409
255
  key: 0,
1410
256
  class: "touchchat-edit-shortcut"
@@ -1415,15 +261,16 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
1415
261
  createVNode(ChatInput, {
1416
262
  ref_key: "ChatInputRef",
1417
263
  ref: ChatInputRef,
1418
- "input-value": inputValue.value,
1419
- "onUpdate:inputValue": ($event) => inputValue.value = $event,
1420
- "enable-deep-thinking": enableDeepThinking.value,
1421
- "onUpdate:enableDeepThinking": ($event) => enableDeepThinking.value = $event,
1422
- "is-chating": isChating.value,
1423
- onSend: handleBeforeSend,
1424
- onStop: handleStop,
264
+ "input-value": unref(inputValue),
265
+ "onUpdate:inputValue": ($event) => isRef(inputValue) ? inputValue.value = $event : null,
266
+ "enable-deep-thinking": unref(enableDeepThinking),
267
+ "onUpdate:enableDeepThinking": ($event) => isRef(enableDeepThinking) ? enableDeepThinking.value = $event : null,
268
+ "is-chating": unref(isChating),
269
+ onSend: unref(handleBeforeSend),
270
+ onStop: unref(handleStop),
1425
271
  onToggleDeepThinking: (val) => enableDeepThinking.value = val,
1426
- onModuleInfo: updateModule
272
+ onModuleInfo: (_info) => {
273
+ }
1427
274
  }, {
1428
275
  editTop: withCtx(() => [
1429
276
  renderSlot(_ctx.$slots, "editTop")
@@ -1433,9 +280,9 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
1433
280
  ]),
1434
281
  _: 3
1435
282
  /* FORWARDED */
1436
- }, 8, ["input-value", "onUpdate:inputValue", "enable-deep-thinking", "onUpdate:enableDeepThinking", "is-chating", "onToggleDeepThinking"])
283
+ }, 8, ["input-value", "onUpdate:inputValue", "enable-deep-thinking", "onUpdate:enableDeepThinking", "is-chating", "onSend", "onStop", "onToggleDeepThinking"])
1437
284
  ])
1438
- ], 40, ["onDragover"]);
285
+ ], 40, ["onDragover", "onDragenter", "onDragleave", "onDrop"]);
1439
286
  };
1440
287
  }
1441
288
  });