@5minds/node-red-dashboard-2-processcube-chat 0.1.3 → 0.2.0
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="deep-chat-container">
|
|
3
3
|
<deep-chat
|
|
4
|
+
ref="deepChat"
|
|
4
5
|
:style="deepChatStyle"
|
|
5
6
|
:textInput="textInputConfig"
|
|
6
7
|
:introMessage="introMessageConfig"
|
|
@@ -26,6 +27,7 @@ export default {
|
|
|
26
27
|
data() {
|
|
27
28
|
return {
|
|
28
29
|
conversation: [],
|
|
30
|
+
signals: undefined,
|
|
29
31
|
};
|
|
30
32
|
},
|
|
31
33
|
|
|
@@ -59,12 +61,18 @@ export default {
|
|
|
59
61
|
};
|
|
60
62
|
},
|
|
61
63
|
},
|
|
64
|
+
mounted() {
|
|
65
|
+
this.$socket.on('msg-input:' + this.id, (msg) => {
|
|
66
|
+
this.handleNodeREDResponse(msg);
|
|
67
|
+
});
|
|
68
|
+
},
|
|
62
69
|
beforeUnmount() {
|
|
63
70
|
this.$socket.off('msg-input:' + this.id);
|
|
64
71
|
},
|
|
65
72
|
|
|
66
73
|
methods: {
|
|
67
74
|
async handleConnection(body, signals) {
|
|
75
|
+
this.signals = signals;
|
|
68
76
|
try {
|
|
69
77
|
// Extract messages and files from FormData
|
|
70
78
|
let newMessages = [];
|
|
@@ -114,7 +122,7 @@ export default {
|
|
|
114
122
|
this.sendToNodeRED(payload, signals);
|
|
115
123
|
} catch (error) {
|
|
116
124
|
console.error('Error in handleConnection:', error);
|
|
117
|
-
this.sendErrorResponse(
|
|
125
|
+
this.sendErrorResponse('Sorry, there was an error processing your message.');
|
|
118
126
|
}
|
|
119
127
|
},
|
|
120
128
|
|
|
@@ -319,13 +327,9 @@ export default {
|
|
|
319
327
|
|
|
320
328
|
sendToNodeRED(payload, signals, fallbackMessage = null) {
|
|
321
329
|
this.$socket.emit('widget-action', this.id, { payload });
|
|
322
|
-
|
|
323
|
-
this.$socket.once('msg-input:' + this.id, (msg) => {
|
|
324
|
-
this.handleNodeREDResponse(msg, signals);
|
|
325
|
-
});
|
|
326
330
|
},
|
|
327
331
|
|
|
328
|
-
handleNodeREDResponse(msg
|
|
332
|
+
handleNodeREDResponse(msg) {
|
|
329
333
|
try {
|
|
330
334
|
// Store the complete ChatGPT response in conversation
|
|
331
335
|
const fullResponse = msg.payload;
|
|
@@ -349,30 +353,34 @@ export default {
|
|
|
349
353
|
// For the chat display, show appropriate response
|
|
350
354
|
if (fullResponse.message?.tool_calls) {
|
|
351
355
|
// If ChatGPT wants to call tools, show a message
|
|
352
|
-
|
|
353
|
-
text: '
|
|
356
|
+
this.$refs.deepChat.addMessage({
|
|
357
|
+
text: `Tool **'${msg.payload.message.tool_calls[0].function.name}'** aufgerufen.`,
|
|
354
358
|
role: 'ai',
|
|
355
359
|
});
|
|
356
360
|
} else if (fullResponse.message?.content || fullResponse.content) {
|
|
357
|
-
|
|
358
|
-
signals.onResponse({
|
|
361
|
+
const message = {
|
|
359
362
|
text: fullResponse.message?.content || fullResponse.content,
|
|
360
363
|
role: 'ai',
|
|
361
|
-
}
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
// Normal text response
|
|
367
|
+
if (msg.payload.intermediateMessage) {
|
|
368
|
+
this.$refs.deepChat.addMessage(message);
|
|
369
|
+
} else {
|
|
370
|
+
this.signals.onResponse(message);
|
|
371
|
+
}
|
|
362
372
|
}
|
|
363
373
|
} catch (error) {
|
|
364
374
|
console.error('Error handling response:', error);
|
|
365
|
-
this.sendErrorResponse(
|
|
375
|
+
this.sendErrorResponse('Error processing response');
|
|
366
376
|
}
|
|
367
377
|
},
|
|
368
378
|
|
|
369
|
-
sendErrorResponse(
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
});
|
|
375
|
-
}
|
|
379
|
+
sendErrorResponse(message) {
|
|
380
|
+
this.$refs.deepChat.addMessage({
|
|
381
|
+
text: message,
|
|
382
|
+
role: 'ai',
|
|
383
|
+
}, true);
|
|
376
384
|
},
|
|
377
385
|
},
|
|
378
386
|
};
|