convo-ai-sdk 1.2.9 → 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 CHANGED
@@ -14,7 +14,8 @@ export class ChatClient {
14
14
  testAgentId: options.testAgentId || '',
15
15
  identifier: options.identifier || '',
16
16
  dynamicVariables: options.dynamicVariables || {},
17
- httpApiEndpoint: options.httpApiEndpoint || DEFAULT_HTTP_ENDPOINT
17
+ httpApiEndpoint: options.httpApiEndpoint || DEFAULT_HTTP_ENDPOINT,
18
+ threadId: options.threadId || '',
18
19
  };
19
20
  }
20
21
  _emit(event, data) {
@@ -75,14 +76,23 @@ export class ChatClient {
75
76
  }
76
77
  const responseData = await response.json();
77
78
  let history = [];
78
- if (Array.isArray(responseData)) {
79
- history = responseData;
80
- }
81
- else if (responseData && Array.isArray(responseData.messages)) {
82
- history = responseData.messages;
79
+ // Handle conversation status first — if expired, emit and bail early
80
+ if (responseData && typeof responseData === 'object' && !Array.isArray(responseData)) {
83
81
  if (responseData.status) {
84
82
  this._setConversationStatus(responseData.status);
85
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;
86
96
  }
87
97
  const newMessages = history.map((msg) => ({
88
98
  id: msg.messageId,
@@ -95,6 +105,8 @@ export class ChatClient {
95
105
  }
96
106
  catch (error) {
97
107
  console.error('Chat SDK Error:', error);
108
+ // Still emit historyLoaded so the UI can react
109
+ this._emit('historyLoaded', this.messages);
98
110
  this._setStatus('disconnected');
99
111
  }
100
112
  }
@@ -139,6 +151,7 @@ export class ChatClient {
139
151
  const headers = {
140
152
  'Content-Type': 'application/json',
141
153
  'x-identifier': this.options.identifier || '',
154
+ ...(this.options.threadId ? { 'x-thread-id': this.options.threadId } : {}),
142
155
  };
143
156
  if (this.options.testAgentId) {
144
157
  headers['x-test-agent-id'] = this.options.testAgentId;
package/dist/types.d.ts CHANGED
@@ -19,5 +19,6 @@ export interface ClientOptions {
19
19
  httpApiEndpoint?: string;
20
20
  identifier?: string;
21
21
  dynamicVariables?: Record<string, any>;
22
+ threadId?: string;
22
23
  }
23
24
  export type ChatEvent = 'statusChange' | 'conversationStatusChange' | 'bubbleSuggestionsChange' | 'message' | 'configLoaded' | 'historyLoaded' | 'messageStart' | 'messageData' | 'messageDone' | 'messageError' | 'paymentError' | 'toolCall' | 'thought' | 'reset' | 'awaitingResponse';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "convo-ai-sdk",
3
- "version": "1.2.9",
3
+ "version": "1.3.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",