convo-ai-sdk 1.0.1 → 1.1.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.d.ts +3 -1
- package/dist/index.js +24 -11
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import type { ConnectionStatus, ChatMessage, ChatConfig, ClientOptions, ChatEvent } from './types';
|
|
1
|
+
import type { ConnectionStatus, ConversationStatus, ChatMessage, ChatConfig, ClientOptions, ChatEvent } from './types';
|
|
2
2
|
export declare class ChatClient {
|
|
3
3
|
private options;
|
|
4
4
|
private listeners;
|
|
5
5
|
status: ConnectionStatus;
|
|
6
|
+
conversationStatus: ConversationStatus;
|
|
6
7
|
messages: ChatMessage[];
|
|
7
8
|
config: Partial<ChatConfig>;
|
|
8
9
|
constructor(options: ClientOptions);
|
|
9
10
|
private _emit;
|
|
10
11
|
private _setStatus;
|
|
12
|
+
private _setConversationStatus;
|
|
11
13
|
private _addMessage;
|
|
12
14
|
private _loadGreeting;
|
|
13
15
|
private _loadHistory;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
const DEFAULT_HTTP_ENDPOINT = 'https://
|
|
1
|
+
const DEFAULT_HTTP_ENDPOINT = 'https://live.wizden.io';
|
|
2
2
|
export class ChatClient {
|
|
3
3
|
options;
|
|
4
4
|
listeners = {};
|
|
5
5
|
status = 'disconnected';
|
|
6
|
+
conversationStatus = 'started';
|
|
6
7
|
messages = [];
|
|
7
8
|
config = {};
|
|
8
9
|
constructor(options) {
|
|
@@ -23,6 +24,10 @@ export class ChatClient {
|
|
|
23
24
|
this.status = newStatus;
|
|
24
25
|
this._emit('statusChange', this.status);
|
|
25
26
|
}
|
|
27
|
+
_setConversationStatus(newStatus) {
|
|
28
|
+
this.conversationStatus = newStatus;
|
|
29
|
+
this._emit('conversationStatusChange', this.conversationStatus);
|
|
30
|
+
}
|
|
26
31
|
_addMessage(message) {
|
|
27
32
|
this.messages.push(message);
|
|
28
33
|
}
|
|
@@ -58,16 +63,24 @@ export class ChatClient {
|
|
|
58
63
|
console.error('Chat SDK Error: Failed to fetch history, status:', response.status);
|
|
59
64
|
throw new Error('Failed to fetch history');
|
|
60
65
|
}
|
|
61
|
-
const
|
|
62
|
-
history
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
const responseData = await response.json();
|
|
67
|
+
let history = [];
|
|
68
|
+
if (Array.isArray(responseData)) {
|
|
69
|
+
history = responseData;
|
|
70
|
+
}
|
|
71
|
+
else if (responseData && Array.isArray(responseData.messages)) {
|
|
72
|
+
history = responseData.messages;
|
|
73
|
+
if (responseData.status) {
|
|
74
|
+
this._setConversationStatus(responseData.status);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const newMessages = history.map((msg) => ({
|
|
78
|
+
id: msg.messageId,
|
|
79
|
+
data: msg.data,
|
|
80
|
+
from: msg.senderType,
|
|
81
|
+
timestamp: msg.timestamp,
|
|
82
|
+
}));
|
|
83
|
+
this.messages.push(...newMessages);
|
|
71
84
|
this._emit('historyLoaded', this.messages);
|
|
72
85
|
}
|
|
73
86
|
catch (error) {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type ConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'error';
|
|
2
|
+
export type ConversationStatus = 'started' | 'awaiting_user' | 'ended_by_system' | 'expired' | 'timeout_silence';
|
|
2
3
|
export interface ChatMessage {
|
|
3
4
|
id: string | number;
|
|
4
5
|
data: any;
|
|
@@ -18,4 +19,4 @@ export interface ClientOptions {
|
|
|
18
19
|
identifier?: string;
|
|
19
20
|
dynamicVariables?: Record<string, any>;
|
|
20
21
|
}
|
|
21
|
-
export type ChatEvent = 'statusChange' | 'message' | 'configLoaded' | 'historyLoaded' | 'messageStart' | 'messageData' | 'messageDone' | 'messageError' | 'toolCall' | 'thought' | 'reset';
|
|
22
|
+
export type ChatEvent = 'statusChange' | 'conversationStatusChange' | 'message' | 'configLoaded' | 'historyLoaded' | 'messageStart' | 'messageData' | 'messageDone' | 'messageError' | 'toolCall' | 'thought' | 'reset';
|