convo-ai-sdk 1.1.6 → 1.1.7
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 +1 -0
- package/dist/index.js +15 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare class ChatClient {
|
|
|
15
15
|
private _loadHistory;
|
|
16
16
|
on<T>(event: ChatEvent, callback: (data: T) => void): void;
|
|
17
17
|
connect(sessionToken?: string): Promise<void>;
|
|
18
|
+
submitDataMessage(submitType: string | undefined, data: Record<string, any>): Promise<void>;
|
|
18
19
|
requestWidget(widgetType: string, widgetData: any): Promise<void>;
|
|
19
20
|
sendToolResult(toolCallId: string, toolCallName: any, result: any): Promise<void>;
|
|
20
21
|
sendMessage(text: string): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -182,6 +182,14 @@ export class ChatClient {
|
|
|
182
182
|
}
|
|
183
183
|
this._setStatus('connected');
|
|
184
184
|
}
|
|
185
|
+
async submitDataMessage(submitType = 'form_submitted', data) {
|
|
186
|
+
if (this.status !== 'connected') {
|
|
187
|
+
console.error('Cannot submit data, not connected.');
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const submitMessageContent = `<${submitType}>${JSON.stringify(data)}<{/${submitType}>`;
|
|
191
|
+
await this.sendMessage(submitMessageContent);
|
|
192
|
+
}
|
|
185
193
|
async requestWidget(widgetType, widgetData) {
|
|
186
194
|
if (this.status !== 'connected') {
|
|
187
195
|
console.error('Cannot request widget, not connected.');
|
|
@@ -189,10 +197,12 @@ export class ChatClient {
|
|
|
189
197
|
}
|
|
190
198
|
const widgetMessage = {
|
|
191
199
|
id: `widget-${Date.now()}`,
|
|
192
|
-
data: { widgetType: widgetType, widgetData: widgetData },
|
|
200
|
+
data: { content: JSON.stringify({ widgetType: widgetType, widgetData: widgetData }) },
|
|
193
201
|
from: 'widget',
|
|
194
202
|
timestamp: Date.now(),
|
|
195
203
|
};
|
|
204
|
+
this._addMessage(widgetMessage);
|
|
205
|
+
this._emit('messageDone', widgetMessage);
|
|
196
206
|
await this.sendStreamMessage(widgetMessage);
|
|
197
207
|
}
|
|
198
208
|
async sendToolResult(toolCallId, toolCallName, result) {
|
|
@@ -240,7 +250,7 @@ export class ChatClient {
|
|
|
240
250
|
input.toolName = message.data.toolCallName;
|
|
241
251
|
}
|
|
242
252
|
if (message.from === 'widget') {
|
|
243
|
-
input.content =
|
|
253
|
+
input.content = message.data.content;
|
|
244
254
|
}
|
|
245
255
|
const response = await fetch(this.config.streamApiEndpoint + 'conversation', {
|
|
246
256
|
method: 'POST',
|
|
@@ -261,6 +271,9 @@ export class ChatClient {
|
|
|
261
271
|
const decoder = new TextDecoder('utf-8');
|
|
262
272
|
let buffer = '';
|
|
263
273
|
let currentMessage = null;
|
|
274
|
+
if (message.from === 'widget') {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
264
277
|
while (true) {
|
|
265
278
|
const { done, value } = await reader.read();
|
|
266
279
|
if (done) {
|