diff --git a/ui/packages/ai/AiCopilot.vue b/ui/packages/ai/AiCopilot.vue
index 15631b0f..e2485bb6 100644
--- a/ui/packages/ai/AiCopilot.vue
+++ b/ui/packages/ai/AiCopilot.vue
@@ -5,6 +5,7 @@ import {mapState} from "vuex";
import AiDrag from "../basic/AiDrag.vue";
import AiLocateDialog from "../tools/AiLocateDialog.vue";
import AiUploader from "../basic/AiUploader.vue";
+import {$checkJson} from "../../lib/js/utils";
export default {
name: "AiCopilot",
@@ -137,8 +138,8 @@ export default {
else this.$message.error("最多上传一个文件")
},
sendMessage(message, isSSE = false) {
- if (isSSE) {
- const {content, sdkFileUrl} = message
+ if (isSSE || localStorage.getItem("isSSE")) {
+ const {content, sdkFileUrl, appId} = message
const body = {
inputs: {},
query: content,
@@ -149,21 +150,29 @@ export default {
return new Promise(resolve => this.http.post("/sse/chat-messages", body, {
withoutToken: 1, headers: {
Accept: 'text/event-stream',
- Authorization: "Bearer app-DRXYELe63911kx7F9RvKUonf"
+ Authorization: `Bearer ${appId}`
},
onDownloadProgress: evt => {
- evt.target.responseText.split("data:").forEach(data => {
- if (data.trim()) {
+ evt.target.responseText.split(/(data|event):/).forEach(data => {
+ if ($checkJson(data.trim())) {
const res = JSON.parse(data.trim())
+ if (this.history.at(-1).userType != 1) {
+ this.history.push({userType: 1, content: "", workflow: []})
+ }
+ const last = this.history.at(-1)
+ if (res.event == "node_started") {
+ last.workflow = ["el-icon-loading", res.data.title]
+ } else if (res.event == "node_finished") {
+ last.workflow = ["el-icon-finished", res.data.title]
+ }
const chunk = res.answer?.trim()
if (!!chunk) {
- if (this.history.at(-1).userType != 1) {
- this.history.push({userType: 1, content: chunk})
- } else if (!this.history.at(-1).content?.includes(chunk)) {
- this.history.at(-1).content += chunk
- }
+ if (!last.content?.includes(chunk)) last.content += chunk
+ }
+ if (res.event == "message_end") {
+ last.workflow = ""
+ resolve()
}
- if (res.event == "message_end") resolve()
}
})
}
diff --git a/ui/packages/ai/components/chatContent.vue b/ui/packages/ai/components/chatContent.vue
index 783d4b30..ad3287c5 100644
--- a/ui/packages/ai/components/chatContent.vue
+++ b/ui/packages/ai/components/chatContent.vue
@@ -5,6 +5,10 @@