convo-ai-sdk 1.2.8 → 1.3.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.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +20 -3
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare class ChatClient {
|
|
|
4
4
|
private listeners;
|
|
5
5
|
status: ConnectionStatus;
|
|
6
6
|
conversationStatus: ConversationStatus;
|
|
7
|
+
bubbleSuggestions: string[];
|
|
7
8
|
awaitingResponse: boolean;
|
|
8
9
|
messages: ChatMessage[];
|
|
9
10
|
config: Partial<ChatConfig>;
|
|
@@ -11,6 +12,7 @@ export declare class ChatClient {
|
|
|
11
12
|
private _emit;
|
|
12
13
|
private _setStatus;
|
|
13
14
|
private _setConversationStatus;
|
|
15
|
+
private _setBubbleSuggestions;
|
|
14
16
|
private _setAwaitingResponse;
|
|
15
17
|
private _addMessage;
|
|
16
18
|
private _loadGreeting;
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export class ChatClient {
|
|
|
4
4
|
listeners = {};
|
|
5
5
|
status = 'disconnected';
|
|
6
6
|
conversationStatus = 'started';
|
|
7
|
+
bubbleSuggestions = [];
|
|
7
8
|
awaitingResponse = false;
|
|
8
9
|
messages = [];
|
|
9
10
|
config = {};
|
|
@@ -13,7 +14,8 @@ export class ChatClient {
|
|
|
13
14
|
testAgentId: options.testAgentId || '',
|
|
14
15
|
identifier: options.identifier || '',
|
|
15
16
|
dynamicVariables: options.dynamicVariables || {},
|
|
16
|
-
httpApiEndpoint: options.httpApiEndpoint || DEFAULT_HTTP_ENDPOINT
|
|
17
|
+
httpApiEndpoint: options.httpApiEndpoint || DEFAULT_HTTP_ENDPOINT,
|
|
18
|
+
threadId: options.threadId || '',
|
|
17
19
|
};
|
|
18
20
|
}
|
|
19
21
|
_emit(event, data) {
|
|
@@ -29,6 +31,10 @@ export class ChatClient {
|
|
|
29
31
|
this.conversationStatus = newStatus;
|
|
30
32
|
this._emit('conversationStatusChange', this.conversationStatus);
|
|
31
33
|
}
|
|
34
|
+
_setBubbleSuggestions(suggestions) {
|
|
35
|
+
this.bubbleSuggestions = suggestions;
|
|
36
|
+
this._emit('bubbleSuggestionsChange', this.bubbleSuggestions);
|
|
37
|
+
}
|
|
32
38
|
_setAwaitingResponse(awaiting) {
|
|
33
39
|
this.awaitingResponse = awaiting;
|
|
34
40
|
this._emit('awaitingResponse', this.awaitingResponse);
|
|
@@ -134,6 +140,7 @@ export class ChatClient {
|
|
|
134
140
|
const headers = {
|
|
135
141
|
'Content-Type': 'application/json',
|
|
136
142
|
'x-identifier': this.options.identifier || '',
|
|
143
|
+
...(this.options.threadId ? { 'x-thread-id': this.options.threadId } : {}),
|
|
137
144
|
};
|
|
138
145
|
if (this.options.testAgentId) {
|
|
139
146
|
headers['x-test-agent-id'] = this.options.testAgentId;
|
|
@@ -148,9 +155,13 @@ export class ChatClient {
|
|
|
148
155
|
dynamicVariables: this.options.dynamicVariables,
|
|
149
156
|
}),
|
|
150
157
|
});
|
|
151
|
-
if (!response.ok)
|
|
152
|
-
throw new Error('Failed to initiate session or fetch config');
|
|
153
158
|
const responseData = await response.json();
|
|
159
|
+
if (!response.ok) {
|
|
160
|
+
if (response.status === 402) {
|
|
161
|
+
this._emit('paymentError', { error: { message: responseData?.error, code: responseData?.code } });
|
|
162
|
+
}
|
|
163
|
+
throw new Error('Failed to initiate session or fetch config');
|
|
164
|
+
}
|
|
154
165
|
sessionToken = responseData.sessionToken;
|
|
155
166
|
this.config = {
|
|
156
167
|
sessionToken,
|
|
@@ -421,6 +432,12 @@ export class ChatClient {
|
|
|
421
432
|
this._setConversationStatus(data.value);
|
|
422
433
|
}
|
|
423
434
|
}
|
|
435
|
+
else if (line.startsWith('bubble_suggestions: ')) {
|
|
436
|
+
const data = JSON.parse(line.substring(20));
|
|
437
|
+
if (data.suggestions) {
|
|
438
|
+
this._setBubbleSuggestions(data.suggestions);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
424
441
|
else if (line.startsWith('done') && currentMessage) {
|
|
425
442
|
this._addMessage(currentMessage);
|
|
426
443
|
this._emit('messageDone', currentMessage);
|
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
|
-
export type ChatEvent = 'statusChange' | 'conversationStatusChange' | 'message' | 'configLoaded' | 'historyLoaded' | 'messageStart' | 'messageData' | 'messageDone' | 'messageError' | 'toolCall' | 'thought' | 'reset' | 'awaitingResponse';
|
|
24
|
+
export type ChatEvent = 'statusChange' | 'conversationStatusChange' | 'bubbleSuggestionsChange' | 'message' | 'configLoaded' | 'historyLoaded' | 'messageStart' | 'messageData' | 'messageDone' | 'messageError' | 'paymentError' | 'toolCall' | 'thought' | 'reset' | 'awaitingResponse';
|