convo-ai-sdk 1.3.0 → 1.3.1
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.js +16 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -76,14 +76,23 @@ export class ChatClient {
|
|
|
76
76
|
}
|
|
77
77
|
const responseData = await response.json();
|
|
78
78
|
let history = [];
|
|
79
|
-
if
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
else if (responseData && Array.isArray(responseData.messages)) {
|
|
83
|
-
history = responseData.messages;
|
|
79
|
+
// Handle conversation status first — if expired, emit and bail early
|
|
80
|
+
if (responseData && typeof responseData === 'object' && !Array.isArray(responseData)) {
|
|
84
81
|
if (responseData.status) {
|
|
85
82
|
this._setConversationStatus(responseData.status);
|
|
86
83
|
}
|
|
84
|
+
if (Array.isArray(responseData.messages)) {
|
|
85
|
+
history = responseData.messages;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (Array.isArray(responseData)) {
|
|
89
|
+
history = responseData;
|
|
90
|
+
}
|
|
91
|
+
// If conversation is terminal, emit historyLoaded with empty messages and return
|
|
92
|
+
const terminalStatuses = ['expired', 'ended_by_system', 'timeout_silence'];
|
|
93
|
+
if (terminalStatuses.includes(this.conversationStatus)) {
|
|
94
|
+
this._emit('historyLoaded', this.messages);
|
|
95
|
+
return;
|
|
87
96
|
}
|
|
88
97
|
const newMessages = history.map((msg) => ({
|
|
89
98
|
id: msg.messageId,
|
|
@@ -96,6 +105,8 @@ export class ChatClient {
|
|
|
96
105
|
}
|
|
97
106
|
catch (error) {
|
|
98
107
|
console.error('Chat SDK Error:', error);
|
|
108
|
+
// Still emit historyLoaded so the UI can react
|
|
109
|
+
this._emit('historyLoaded', this.messages);
|
|
99
110
|
this._setStatus('disconnected');
|
|
100
111
|
}
|
|
101
112
|
}
|