@5minds/node-red-dashboard-2-processcube-chat 0.1.2 → 0.1.3-develop-949973-mfeevugh
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"
|
|
@@ -59,6 +60,13 @@ export default {
|
|
|
59
60
|
};
|
|
60
61
|
},
|
|
61
62
|
},
|
|
63
|
+
mounted() {
|
|
64
|
+
console.log('mounted');
|
|
65
|
+
this.$socket.on('msg-input:' + this.id, (msg) => {
|
|
66
|
+
console.log(JSON.stringify(msg));
|
|
67
|
+
this.handleNodeREDResponse(msg);
|
|
68
|
+
});
|
|
69
|
+
},
|
|
62
70
|
beforeUnmount() {
|
|
63
71
|
this.$socket.off('msg-input:' + this.id);
|
|
64
72
|
},
|
|
@@ -85,9 +93,22 @@ export default {
|
|
|
85
93
|
}
|
|
86
94
|
|
|
87
95
|
// Process files if present
|
|
88
|
-
if (files.length > 0
|
|
89
|
-
const
|
|
90
|
-
|
|
96
|
+
if (files.length > 0) {
|
|
97
|
+
const processedFiles = await this.processFiles(files);
|
|
98
|
+
|
|
99
|
+
if (newMessages.length > 0) {
|
|
100
|
+
// Add files to existing message
|
|
101
|
+
const lastMessage = newMessages[newMessages.length - 1];
|
|
102
|
+
lastMessage.files = processedFiles;
|
|
103
|
+
} else {
|
|
104
|
+
// Create new message for files only
|
|
105
|
+
newMessages.push({
|
|
106
|
+
role: 'user',
|
|
107
|
+
text: '', // Empty text when only files are sent
|
|
108
|
+
files: processedFiles,
|
|
109
|
+
});
|
|
110
|
+
console.log('lus777', newMessages);
|
|
111
|
+
}
|
|
91
112
|
}
|
|
92
113
|
} else if (body.messages) {
|
|
93
114
|
newMessages = body.messages;
|
|
@@ -101,7 +122,7 @@ export default {
|
|
|
101
122
|
this.sendToNodeRED(payload, signals);
|
|
102
123
|
} catch (error) {
|
|
103
124
|
console.error('Error in handleConnection:', error);
|
|
104
|
-
this.sendErrorResponse(
|
|
125
|
+
this.sendErrorResponse('Sorry, there was an error processing your message.');
|
|
105
126
|
}
|
|
106
127
|
},
|
|
107
128
|
|
|
@@ -306,13 +327,9 @@ export default {
|
|
|
306
327
|
|
|
307
328
|
sendToNodeRED(payload, signals, fallbackMessage = null) {
|
|
308
329
|
this.$socket.emit('widget-action', this.id, { payload });
|
|
309
|
-
|
|
310
|
-
this.$socket.once('msg-input:' + this.id, (msg) => {
|
|
311
|
-
this.handleNodeREDResponse(msg, signals);
|
|
312
|
-
});
|
|
313
330
|
},
|
|
314
331
|
|
|
315
|
-
handleNodeREDResponse(msg
|
|
332
|
+
handleNodeREDResponse(msg) {
|
|
316
333
|
try {
|
|
317
334
|
// Store the complete ChatGPT response in conversation
|
|
318
335
|
const fullResponse = msg.payload;
|
|
@@ -336,30 +353,28 @@ export default {
|
|
|
336
353
|
// For the chat display, show appropriate response
|
|
337
354
|
if (fullResponse.message?.tool_calls) {
|
|
338
355
|
// If ChatGPT wants to call tools, show a message
|
|
339
|
-
|
|
356
|
+
this.$refs.deepChat.addMessage({
|
|
340
357
|
text: 'Function call requested...',
|
|
341
358
|
role: 'ai',
|
|
342
359
|
});
|
|
343
360
|
} else if (fullResponse.message?.content || fullResponse.content) {
|
|
344
361
|
// Normal text response
|
|
345
|
-
|
|
362
|
+
this.$refs.deepChat.addMessage({
|
|
346
363
|
text: fullResponse.message?.content || fullResponse.content,
|
|
347
364
|
role: 'ai',
|
|
348
365
|
});
|
|
349
366
|
}
|
|
350
367
|
} catch (error) {
|
|
351
368
|
console.error('Error handling response:', error);
|
|
352
|
-
this.sendErrorResponse(
|
|
369
|
+
this.sendErrorResponse('Error processing response');
|
|
353
370
|
}
|
|
354
371
|
},
|
|
355
372
|
|
|
356
|
-
sendErrorResponse(
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
});
|
|
362
|
-
}
|
|
373
|
+
sendErrorResponse(message) {
|
|
374
|
+
this.$refs.deepChat.addMessage({
|
|
375
|
+
text: message,
|
|
376
|
+
role: 'ai',
|
|
377
|
+
});
|
|
363
378
|
},
|
|
364
379
|
},
|
|
365
380
|
};
|