hume 0.8.1-beta5 → 0.8.1-beta6
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/api/resources/empathicVoice/resources/chat/client/Client.d.ts +6 -0
- package/api/resources/empathicVoice/resources/chat/client/Client.js +11 -1
- package/api/resources/empathicVoice/resources/chat/client/Socket.d.ts +7 -0
- package/api/resources/empathicVoice/resources/chat/client/Socket.js +31 -0
- package/dist/api/resources/empathicVoice/resources/chat/client/Client.d.ts +6 -0
- package/dist/api/resources/empathicVoice/resources/chat/client/Client.js +11 -1
- package/dist/api/resources/empathicVoice/resources/chat/client/Socket.d.ts +7 -0
- package/dist/api/resources/empathicVoice/resources/chat/client/Socket.js +31 -0
- package/package.json +1 -1
|
@@ -6,12 +6,18 @@ export declare namespace Chat {
|
|
|
6
6
|
accessToken?: core.Supplier<string | undefined>;
|
|
7
7
|
}
|
|
8
8
|
interface ConnectArgs {
|
|
9
|
+
/** Enable debug mode on the websocket. Defaults to false. */
|
|
10
|
+
debug?: boolean;
|
|
11
|
+
/** Number of reconnect attempts. Defaults to 30. */
|
|
12
|
+
reconnectAttempts?: number;
|
|
9
13
|
/** The ID of the configuration. */
|
|
10
14
|
configId?: string;
|
|
11
15
|
/** The version of the configuration. */
|
|
12
16
|
configVersion?: string;
|
|
13
17
|
/** The ID of a chat group, used to resume a previous chat. */
|
|
14
18
|
resumedChatGroupId?: string;
|
|
19
|
+
/** Extra query parameters sent at WebSocket connection */
|
|
20
|
+
queryParams?: Record<string, string | string[] | object | object[]>;
|
|
15
21
|
}
|
|
16
22
|
}
|
|
17
23
|
export declare class Chat {
|
|
@@ -35,6 +35,7 @@ class Chat {
|
|
|
35
35
|
this._options = _options;
|
|
36
36
|
}
|
|
37
37
|
connect(args = {}) {
|
|
38
|
+
var _a;
|
|
38
39
|
const queryParams = {};
|
|
39
40
|
if (this._options.accessToken != null) {
|
|
40
41
|
queryParams["accessToken"] = core.Supplier.get(this._options.accessToken);
|
|
@@ -51,7 +52,16 @@ class Chat {
|
|
|
51
52
|
if (args.resumedChatGroupId != null) {
|
|
52
53
|
queryParams["resumed_chat_group_id"] = args.resumedChatGroupId;
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
+
if (args.queryParams != null) {
|
|
56
|
+
for (const [name, value] of Object.entries(args.queryParams)) {
|
|
57
|
+
queryParams[name] = value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const socket = new core.ReconnectingWebSocket(`wss://api.hume.ai/v0/evi/chat?${qs_1.default.stringify(queryParams)}`, [], {
|
|
61
|
+
startClosed: true,
|
|
62
|
+
debug: (_a = args.debug) !== null && _a !== void 0 ? _a : false,
|
|
63
|
+
maxRetries: args.reconnectAttempts,
|
|
64
|
+
});
|
|
55
65
|
return new Socket_1.ChatSocket({
|
|
56
66
|
socket,
|
|
57
67
|
});
|
|
@@ -64,10 +64,17 @@ export declare class ChatSocket {
|
|
|
64
64
|
* Send text input
|
|
65
65
|
*/
|
|
66
66
|
sendUserInput(text: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* @name connect
|
|
69
|
+
* @description
|
|
70
|
+
* Connect to the websocket.
|
|
71
|
+
*/
|
|
72
|
+
connect(): ChatSocket;
|
|
67
73
|
/**
|
|
68
74
|
* Closes the underlying socket.
|
|
69
75
|
*/
|
|
70
76
|
close(): void;
|
|
77
|
+
private assertSocketIsOpen;
|
|
71
78
|
private sendJson;
|
|
72
79
|
private handleOpen;
|
|
73
80
|
private handleMessage;
|
|
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.ChatSocket = void 0;
|
|
27
|
+
const errors = __importStar(require("../../../../../../errors"));
|
|
27
28
|
const serializers = __importStar(require("../../../../../../serialization/index"));
|
|
28
29
|
class ChatSocket {
|
|
29
30
|
constructor({ socket }) {
|
|
@@ -83,63 +84,93 @@ class ChatSocket {
|
|
|
83
84
|
* Send audio input
|
|
84
85
|
*/
|
|
85
86
|
sendAudioInput(message) {
|
|
87
|
+
this.assertSocketIsOpen();
|
|
86
88
|
this.sendJson(Object.assign({ type: "audio_input" }, message));
|
|
87
89
|
}
|
|
88
90
|
/**
|
|
89
91
|
* Send session settings
|
|
90
92
|
*/
|
|
91
93
|
sendSessionSettings(message) {
|
|
94
|
+
this.assertSocketIsOpen();
|
|
92
95
|
this.sendJson(Object.assign({ type: "session_settings" }, message));
|
|
93
96
|
}
|
|
94
97
|
/**
|
|
95
98
|
* Send assistant input
|
|
96
99
|
*/
|
|
97
100
|
sendAssistantInput(message) {
|
|
101
|
+
this.assertSocketIsOpen();
|
|
98
102
|
this.sendJson(Object.assign({ type: "assistant_input" }, message));
|
|
99
103
|
}
|
|
100
104
|
/**
|
|
101
105
|
* Send pause assistant message
|
|
102
106
|
*/
|
|
103
107
|
pauseAssistant(message) {
|
|
108
|
+
this.assertSocketIsOpen();
|
|
104
109
|
this.sendJson(Object.assign({ type: "pause_assistant_message" }, message));
|
|
105
110
|
}
|
|
106
111
|
/**
|
|
107
112
|
* Send resume assistant message
|
|
108
113
|
*/
|
|
109
114
|
resumeAssistant(message) {
|
|
115
|
+
this.assertSocketIsOpen();
|
|
110
116
|
this.sendJson(Object.assign({ type: "resume_assistant_message" }, message));
|
|
111
117
|
}
|
|
112
118
|
/**
|
|
113
119
|
* Send tool response message
|
|
114
120
|
*/
|
|
115
121
|
sendToolResponseMessage(message) {
|
|
122
|
+
this.assertSocketIsOpen();
|
|
116
123
|
this.sendJson(Object.assign({ type: "tool_response" }, message));
|
|
117
124
|
}
|
|
118
125
|
/**
|
|
119
126
|
* Send tool error message
|
|
120
127
|
*/
|
|
121
128
|
sendToolErrorMessage(message) {
|
|
129
|
+
this.assertSocketIsOpen();
|
|
122
130
|
this.sendJson(Object.assign({ type: "tool_error" }, message));
|
|
123
131
|
}
|
|
124
132
|
/**
|
|
125
133
|
* Send text input
|
|
126
134
|
*/
|
|
127
135
|
sendUserInput(text) {
|
|
136
|
+
this.assertSocketIsOpen();
|
|
128
137
|
this.sendJson({
|
|
129
138
|
type: "user_input",
|
|
130
139
|
text,
|
|
131
140
|
});
|
|
132
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* @name connect
|
|
144
|
+
* @description
|
|
145
|
+
* Connect to the websocket.
|
|
146
|
+
*/
|
|
147
|
+
connect() {
|
|
148
|
+
this.socket.reconnect();
|
|
149
|
+
this.socket.addEventListener('open', this.handleOpen);
|
|
150
|
+
this.socket.addEventListener('message', this.handleMessage);
|
|
151
|
+
this.socket.addEventListener('close', this.handleClose);
|
|
152
|
+
this.socket.addEventListener('error', this.handleError);
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
133
155
|
/**
|
|
134
156
|
* Closes the underlying socket.
|
|
135
157
|
*/
|
|
136
158
|
close() {
|
|
137
159
|
this.socket.close();
|
|
160
|
+
this.handleClose({ code: 1000 });
|
|
138
161
|
this.socket.removeEventListener('open', this.handleOpen);
|
|
139
162
|
this.socket.removeEventListener('message', this.handleMessage);
|
|
140
163
|
this.socket.removeEventListener('close', this.handleClose);
|
|
141
164
|
this.socket.removeEventListener('error', this.handleError);
|
|
142
165
|
}
|
|
166
|
+
assertSocketIsOpen() {
|
|
167
|
+
if (!this.socket) {
|
|
168
|
+
throw new errors.HumeError({ message: 'Socket is not connected.' });
|
|
169
|
+
}
|
|
170
|
+
if (this.socket.readyState !== WebSocket.OPEN) {
|
|
171
|
+
throw new errors.HumeError({ message: 'Socket is not open.' });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
143
174
|
sendJson(payload) {
|
|
144
175
|
const jsonPayload = serializers.empathicVoice.PublishEvent.jsonOrThrow(payload, {
|
|
145
176
|
unrecognizedObjectKeys: "strip",
|
|
@@ -6,12 +6,18 @@ export declare namespace Chat {
|
|
|
6
6
|
accessToken?: core.Supplier<string | undefined>;
|
|
7
7
|
}
|
|
8
8
|
interface ConnectArgs {
|
|
9
|
+
/** Enable debug mode on the websocket. Defaults to false. */
|
|
10
|
+
debug?: boolean;
|
|
11
|
+
/** Number of reconnect attempts. Defaults to 30. */
|
|
12
|
+
reconnectAttempts?: number;
|
|
9
13
|
/** The ID of the configuration. */
|
|
10
14
|
configId?: string;
|
|
11
15
|
/** The version of the configuration. */
|
|
12
16
|
configVersion?: string;
|
|
13
17
|
/** The ID of a chat group, used to resume a previous chat. */
|
|
14
18
|
resumedChatGroupId?: string;
|
|
19
|
+
/** Extra query parameters sent at WebSocket connection */
|
|
20
|
+
queryParams?: Record<string, string | string[] | object | object[]>;
|
|
15
21
|
}
|
|
16
22
|
}
|
|
17
23
|
export declare class Chat {
|
|
@@ -35,6 +35,7 @@ class Chat {
|
|
|
35
35
|
this._options = _options;
|
|
36
36
|
}
|
|
37
37
|
connect(args = {}) {
|
|
38
|
+
var _a;
|
|
38
39
|
const queryParams = {};
|
|
39
40
|
if (this._options.accessToken != null) {
|
|
40
41
|
queryParams["accessToken"] = core.Supplier.get(this._options.accessToken);
|
|
@@ -51,7 +52,16 @@ class Chat {
|
|
|
51
52
|
if (args.resumedChatGroupId != null) {
|
|
52
53
|
queryParams["resumed_chat_group_id"] = args.resumedChatGroupId;
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
+
if (args.queryParams != null) {
|
|
56
|
+
for (const [name, value] of Object.entries(args.queryParams)) {
|
|
57
|
+
queryParams[name] = value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const socket = new core.ReconnectingWebSocket(`wss://api.hume.ai/v0/evi/chat?${qs_1.default.stringify(queryParams)}`, [], {
|
|
61
|
+
startClosed: true,
|
|
62
|
+
debug: (_a = args.debug) !== null && _a !== void 0 ? _a : false,
|
|
63
|
+
maxRetries: args.reconnectAttempts,
|
|
64
|
+
});
|
|
55
65
|
return new Socket_1.ChatSocket({
|
|
56
66
|
socket,
|
|
57
67
|
});
|
|
@@ -64,10 +64,17 @@ export declare class ChatSocket {
|
|
|
64
64
|
* Send text input
|
|
65
65
|
*/
|
|
66
66
|
sendUserInput(text: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* @name connect
|
|
69
|
+
* @description
|
|
70
|
+
* Connect to the websocket.
|
|
71
|
+
*/
|
|
72
|
+
connect(): ChatSocket;
|
|
67
73
|
/**
|
|
68
74
|
* Closes the underlying socket.
|
|
69
75
|
*/
|
|
70
76
|
close(): void;
|
|
77
|
+
private assertSocketIsOpen;
|
|
71
78
|
private sendJson;
|
|
72
79
|
private handleOpen;
|
|
73
80
|
private handleMessage;
|
|
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.ChatSocket = void 0;
|
|
27
|
+
const errors = __importStar(require("../../../../../../errors"));
|
|
27
28
|
const serializers = __importStar(require("../../../../../../serialization/index"));
|
|
28
29
|
class ChatSocket {
|
|
29
30
|
constructor({ socket }) {
|
|
@@ -83,63 +84,93 @@ class ChatSocket {
|
|
|
83
84
|
* Send audio input
|
|
84
85
|
*/
|
|
85
86
|
sendAudioInput(message) {
|
|
87
|
+
this.assertSocketIsOpen();
|
|
86
88
|
this.sendJson(Object.assign({ type: "audio_input" }, message));
|
|
87
89
|
}
|
|
88
90
|
/**
|
|
89
91
|
* Send session settings
|
|
90
92
|
*/
|
|
91
93
|
sendSessionSettings(message) {
|
|
94
|
+
this.assertSocketIsOpen();
|
|
92
95
|
this.sendJson(Object.assign({ type: "session_settings" }, message));
|
|
93
96
|
}
|
|
94
97
|
/**
|
|
95
98
|
* Send assistant input
|
|
96
99
|
*/
|
|
97
100
|
sendAssistantInput(message) {
|
|
101
|
+
this.assertSocketIsOpen();
|
|
98
102
|
this.sendJson(Object.assign({ type: "assistant_input" }, message));
|
|
99
103
|
}
|
|
100
104
|
/**
|
|
101
105
|
* Send pause assistant message
|
|
102
106
|
*/
|
|
103
107
|
pauseAssistant(message) {
|
|
108
|
+
this.assertSocketIsOpen();
|
|
104
109
|
this.sendJson(Object.assign({ type: "pause_assistant_message" }, message));
|
|
105
110
|
}
|
|
106
111
|
/**
|
|
107
112
|
* Send resume assistant message
|
|
108
113
|
*/
|
|
109
114
|
resumeAssistant(message) {
|
|
115
|
+
this.assertSocketIsOpen();
|
|
110
116
|
this.sendJson(Object.assign({ type: "resume_assistant_message" }, message));
|
|
111
117
|
}
|
|
112
118
|
/**
|
|
113
119
|
* Send tool response message
|
|
114
120
|
*/
|
|
115
121
|
sendToolResponseMessage(message) {
|
|
122
|
+
this.assertSocketIsOpen();
|
|
116
123
|
this.sendJson(Object.assign({ type: "tool_response" }, message));
|
|
117
124
|
}
|
|
118
125
|
/**
|
|
119
126
|
* Send tool error message
|
|
120
127
|
*/
|
|
121
128
|
sendToolErrorMessage(message) {
|
|
129
|
+
this.assertSocketIsOpen();
|
|
122
130
|
this.sendJson(Object.assign({ type: "tool_error" }, message));
|
|
123
131
|
}
|
|
124
132
|
/**
|
|
125
133
|
* Send text input
|
|
126
134
|
*/
|
|
127
135
|
sendUserInput(text) {
|
|
136
|
+
this.assertSocketIsOpen();
|
|
128
137
|
this.sendJson({
|
|
129
138
|
type: "user_input",
|
|
130
139
|
text,
|
|
131
140
|
});
|
|
132
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* @name connect
|
|
144
|
+
* @description
|
|
145
|
+
* Connect to the websocket.
|
|
146
|
+
*/
|
|
147
|
+
connect() {
|
|
148
|
+
this.socket.reconnect();
|
|
149
|
+
this.socket.addEventListener('open', this.handleOpen);
|
|
150
|
+
this.socket.addEventListener('message', this.handleMessage);
|
|
151
|
+
this.socket.addEventListener('close', this.handleClose);
|
|
152
|
+
this.socket.addEventListener('error', this.handleError);
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
133
155
|
/**
|
|
134
156
|
* Closes the underlying socket.
|
|
135
157
|
*/
|
|
136
158
|
close() {
|
|
137
159
|
this.socket.close();
|
|
160
|
+
this.handleClose({ code: 1000 });
|
|
138
161
|
this.socket.removeEventListener('open', this.handleOpen);
|
|
139
162
|
this.socket.removeEventListener('message', this.handleMessage);
|
|
140
163
|
this.socket.removeEventListener('close', this.handleClose);
|
|
141
164
|
this.socket.removeEventListener('error', this.handleError);
|
|
142
165
|
}
|
|
166
|
+
assertSocketIsOpen() {
|
|
167
|
+
if (!this.socket) {
|
|
168
|
+
throw new errors.HumeError({ message: 'Socket is not connected.' });
|
|
169
|
+
}
|
|
170
|
+
if (this.socket.readyState !== WebSocket.OPEN) {
|
|
171
|
+
throw new errors.HumeError({ message: 'Socket is not open.' });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
143
174
|
sendJson(payload) {
|
|
144
175
|
const jsonPayload = serializers.empathicVoice.PublishEvent.jsonOrThrow(payload, {
|
|
145
176
|
unrecognizedObjectKeys: "strip",
|