convo-ai-sdk 1.1.1 → 1.1.3

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 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
+ requestWidget(widgetType: string, widgetData: any): Promise<void>;
18
19
  sendToolResult(toolCallId: string, toolCallName: any, result: any): Promise<void>;
19
20
  sendMessage(text: string): Promise<void>;
20
21
  toolCall(tool_call: any): Promise<void>;
package/dist/index.js CHANGED
@@ -177,8 +177,26 @@ export class ChatClient {
177
177
  if (sessionToken && conversationId && !sessionInitiated) {
178
178
  await this._loadHistory(conversationId, sessionToken);
179
179
  }
180
+ else {
181
+ this._setConversationStatus('started');
182
+ }
180
183
  this._setStatus('connected');
181
184
  }
185
+ async requestWidget(widgetType, widgetData) {
186
+ if (this.status !== 'connected') {
187
+ console.error('Cannot request widget, not connected.');
188
+ return;
189
+ }
190
+ const widgetMessage = {
191
+ id: `widget-${Date.now()}`,
192
+ data: { widgetType: widgetType, content: widgetData },
193
+ from: 'widget',
194
+ timestamp: Date.now(),
195
+ };
196
+ this._addMessage(widgetMessage);
197
+ this._emit('message', widgetMessage);
198
+ await this.sendStreamMessage(widgetMessage);
199
+ }
182
200
  async sendToolResult(toolCallId, toolCallName, result) {
183
201
  if (this.status !== 'connected') {
184
202
  console.error('Cannot send tool result, not connected.');
@@ -289,6 +307,12 @@ export class ChatClient {
289
307
  currentMessage = null;
290
308
  break;
291
309
  }
310
+ else if (line.startsWith('status: ')) {
311
+ const data = JSON.parse(line.substring(8));
312
+ if (data.value) {
313
+ this._setConversationStatus(data.value);
314
+ }
315
+ }
292
316
  else if (line.startsWith('done') && currentMessage) {
293
317
  this._addMessage(currentMessage);
294
318
  this._emit('messageDone', currentMessage);
package/dist/types.d.ts CHANGED
@@ -3,7 +3,7 @@ export type ConversationStatus = 'started' | 'awaiting_user' | 'ended_by_system'
3
3
  export interface ChatMessage {
4
4
  id: string | number;
5
5
  data: any;
6
- from: 'user' | 'assistant' | 'system' | 'tool';
6
+ from: 'user' | 'assistant' | 'system' | 'tool' | 'widget';
7
7
  timestamp: number;
8
8
  }
9
9
  export interface ChatConfig {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "convo-ai-sdk",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",