hume 0.8.1-beta4 → 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/dist/wrapper/fetchAccessToken.d.ts +23 -0
- package/dist/wrapper/fetchAccessToken.js +51 -0
- package/dist/wrapper/index.d.ts +1 -0
- package/dist/wrapper/index.js +3 -1
- package/package.json +1 -1
- package/wrapper/fetchAccessToken.d.ts +23 -0
- package/wrapper/fetchAccessToken.js +51 -0
- package/wrapper/index.d.ts +1 -0
- package/wrapper/index.js +3 -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",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetches a new access token from the Hume API using the provided API key and Secret key.
|
|
3
|
+
*
|
|
4
|
+
* @param args - The arguments for the request.
|
|
5
|
+
* @returns Promise that resolves to the new access token.
|
|
6
|
+
* @throws If the base64 encoding fails.
|
|
7
|
+
* @throws If the network request fails.
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* async function getToken() {
|
|
11
|
+
* const accessToken = await fetchAccessToken({
|
|
12
|
+
* apiKey: 'test',
|
|
13
|
+
* secretKey: 'test',
|
|
14
|
+
* });
|
|
15
|
+
* console.log(accessToken); // Outputs the access token
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const fetchAccessToken: (args: {
|
|
20
|
+
apiKey: string;
|
|
21
|
+
secretKey: string;
|
|
22
|
+
host?: string;
|
|
23
|
+
}) => Promise<string>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.fetchAccessToken = void 0;
|
|
13
|
+
const base64Encode_1 = require("./base64Encode");
|
|
14
|
+
/**
|
|
15
|
+
* Fetches a new access token from the Hume API using the provided API key and Secret key.
|
|
16
|
+
*
|
|
17
|
+
* @param args - The arguments for the request.
|
|
18
|
+
* @returns Promise that resolves to the new access token.
|
|
19
|
+
* @throws If the base64 encoding fails.
|
|
20
|
+
* @throws If the network request fails.
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* async function getToken() {
|
|
24
|
+
* const accessToken = await fetchAccessToken({
|
|
25
|
+
* apiKey: 'test',
|
|
26
|
+
* secretKey: 'test',
|
|
27
|
+
* });
|
|
28
|
+
* console.log(accessToken); // Outputs the access token
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const fetchAccessToken = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
const { apiKey, secretKey, host = 'api.hume.ai' } = args;
|
|
34
|
+
const authString = `${apiKey}:${secretKey}`;
|
|
35
|
+
const encoded = (0, base64Encode_1.base64Encode)(authString);
|
|
36
|
+
const res = yield fetch(`https://${host}/oauth2-cc/token`, {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
headers: {
|
|
39
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
40
|
+
Authorization: `Basic ${encoded}`,
|
|
41
|
+
},
|
|
42
|
+
body: new URLSearchParams({
|
|
43
|
+
grant_type: 'client_credentials',
|
|
44
|
+
}).toString(),
|
|
45
|
+
cache: 'no-cache',
|
|
46
|
+
});
|
|
47
|
+
const data = (yield res.json());
|
|
48
|
+
const accessToken = String(data['access_token']);
|
|
49
|
+
return accessToken;
|
|
50
|
+
});
|
|
51
|
+
exports.fetchAccessToken = fetchAccessToken;
|
package/dist/wrapper/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { convertBase64ToBlob } from "./convertBase64ToBlob";
|
|
|
4
4
|
export { convertBlobToBase64 } from "./convertBlobToBase64";
|
|
5
5
|
export { ensureSingleValidAudioTrack } from "./ensureSingleValidAudioTrack";
|
|
6
6
|
export { checkForAudioTracks } from "./checkForAudioTracks";
|
|
7
|
+
export { fetchAccessToken } from "./fetchAccessToken";
|
|
7
8
|
export { getAudioStream } from "./getAudioStream";
|
|
8
9
|
export { MimeType, getBrowserSupportedMimeType } from "./getBrowserSupportedMimeType";
|
|
9
10
|
export { HumeClient } from "./HumeClient";
|
package/dist/wrapper/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HumeClient = exports.getBrowserSupportedMimeType = exports.MimeType = exports.getAudioStream = exports.checkForAudioTracks = exports.ensureSingleValidAudioTrack = exports.convertBlobToBase64 = exports.convertBase64ToBlob = exports.base64Encode = exports.base64Decode = void 0;
|
|
3
|
+
exports.HumeClient = exports.getBrowserSupportedMimeType = exports.MimeType = exports.getAudioStream = exports.fetchAccessToken = exports.checkForAudioTracks = exports.ensureSingleValidAudioTrack = exports.convertBlobToBase64 = exports.convertBase64ToBlob = exports.base64Encode = exports.base64Decode = void 0;
|
|
4
4
|
var base64Decode_1 = require("./base64Decode");
|
|
5
5
|
Object.defineProperty(exports, "base64Decode", { enumerable: true, get: function () { return base64Decode_1.base64Decode; } });
|
|
6
6
|
var base64Encode_1 = require("./base64Encode");
|
|
@@ -13,6 +13,8 @@ var ensureSingleValidAudioTrack_1 = require("./ensureSingleValidAudioTrack");
|
|
|
13
13
|
Object.defineProperty(exports, "ensureSingleValidAudioTrack", { enumerable: true, get: function () { return ensureSingleValidAudioTrack_1.ensureSingleValidAudioTrack; } });
|
|
14
14
|
var checkForAudioTracks_1 = require("./checkForAudioTracks");
|
|
15
15
|
Object.defineProperty(exports, "checkForAudioTracks", { enumerable: true, get: function () { return checkForAudioTracks_1.checkForAudioTracks; } });
|
|
16
|
+
var fetchAccessToken_1 = require("./fetchAccessToken");
|
|
17
|
+
Object.defineProperty(exports, "fetchAccessToken", { enumerable: true, get: function () { return fetchAccessToken_1.fetchAccessToken; } });
|
|
16
18
|
var getAudioStream_1 = require("./getAudioStream");
|
|
17
19
|
Object.defineProperty(exports, "getAudioStream", { enumerable: true, get: function () { return getAudioStream_1.getAudioStream; } });
|
|
18
20
|
var getBrowserSupportedMimeType_1 = require("./getBrowserSupportedMimeType");
|
package/package.json
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetches a new access token from the Hume API using the provided API key and Secret key.
|
|
3
|
+
*
|
|
4
|
+
* @param args - The arguments for the request.
|
|
5
|
+
* @returns Promise that resolves to the new access token.
|
|
6
|
+
* @throws If the base64 encoding fails.
|
|
7
|
+
* @throws If the network request fails.
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* async function getToken() {
|
|
11
|
+
* const accessToken = await fetchAccessToken({
|
|
12
|
+
* apiKey: 'test',
|
|
13
|
+
* secretKey: 'test',
|
|
14
|
+
* });
|
|
15
|
+
* console.log(accessToken); // Outputs the access token
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const fetchAccessToken: (args: {
|
|
20
|
+
apiKey: string;
|
|
21
|
+
secretKey: string;
|
|
22
|
+
host?: string;
|
|
23
|
+
}) => Promise<string>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.fetchAccessToken = void 0;
|
|
13
|
+
const base64Encode_1 = require("./base64Encode");
|
|
14
|
+
/**
|
|
15
|
+
* Fetches a new access token from the Hume API using the provided API key and Secret key.
|
|
16
|
+
*
|
|
17
|
+
* @param args - The arguments for the request.
|
|
18
|
+
* @returns Promise that resolves to the new access token.
|
|
19
|
+
* @throws If the base64 encoding fails.
|
|
20
|
+
* @throws If the network request fails.
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* async function getToken() {
|
|
24
|
+
* const accessToken = await fetchAccessToken({
|
|
25
|
+
* apiKey: 'test',
|
|
26
|
+
* secretKey: 'test',
|
|
27
|
+
* });
|
|
28
|
+
* console.log(accessToken); // Outputs the access token
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const fetchAccessToken = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
const { apiKey, secretKey, host = 'api.hume.ai' } = args;
|
|
34
|
+
const authString = `${apiKey}:${secretKey}`;
|
|
35
|
+
const encoded = (0, base64Encode_1.base64Encode)(authString);
|
|
36
|
+
const res = yield fetch(`https://${host}/oauth2-cc/token`, {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
headers: {
|
|
39
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
40
|
+
Authorization: `Basic ${encoded}`,
|
|
41
|
+
},
|
|
42
|
+
body: new URLSearchParams({
|
|
43
|
+
grant_type: 'client_credentials',
|
|
44
|
+
}).toString(),
|
|
45
|
+
cache: 'no-cache',
|
|
46
|
+
});
|
|
47
|
+
const data = (yield res.json());
|
|
48
|
+
const accessToken = String(data['access_token']);
|
|
49
|
+
return accessToken;
|
|
50
|
+
});
|
|
51
|
+
exports.fetchAccessToken = fetchAccessToken;
|
package/wrapper/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { convertBase64ToBlob } from "./convertBase64ToBlob";
|
|
|
4
4
|
export { convertBlobToBase64 } from "./convertBlobToBase64";
|
|
5
5
|
export { ensureSingleValidAudioTrack } from "./ensureSingleValidAudioTrack";
|
|
6
6
|
export { checkForAudioTracks } from "./checkForAudioTracks";
|
|
7
|
+
export { fetchAccessToken } from "./fetchAccessToken";
|
|
7
8
|
export { getAudioStream } from "./getAudioStream";
|
|
8
9
|
export { MimeType, getBrowserSupportedMimeType } from "./getBrowserSupportedMimeType";
|
|
9
10
|
export { HumeClient } from "./HumeClient";
|
package/wrapper/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HumeClient = exports.getBrowserSupportedMimeType = exports.MimeType = exports.getAudioStream = exports.checkForAudioTracks = exports.ensureSingleValidAudioTrack = exports.convertBlobToBase64 = exports.convertBase64ToBlob = exports.base64Encode = exports.base64Decode = void 0;
|
|
3
|
+
exports.HumeClient = exports.getBrowserSupportedMimeType = exports.MimeType = exports.getAudioStream = exports.fetchAccessToken = exports.checkForAudioTracks = exports.ensureSingleValidAudioTrack = exports.convertBlobToBase64 = exports.convertBase64ToBlob = exports.base64Encode = exports.base64Decode = void 0;
|
|
4
4
|
var base64Decode_1 = require("./base64Decode");
|
|
5
5
|
Object.defineProperty(exports, "base64Decode", { enumerable: true, get: function () { return base64Decode_1.base64Decode; } });
|
|
6
6
|
var base64Encode_1 = require("./base64Encode");
|
|
@@ -13,6 +13,8 @@ var ensureSingleValidAudioTrack_1 = require("./ensureSingleValidAudioTrack");
|
|
|
13
13
|
Object.defineProperty(exports, "ensureSingleValidAudioTrack", { enumerable: true, get: function () { return ensureSingleValidAudioTrack_1.ensureSingleValidAudioTrack; } });
|
|
14
14
|
var checkForAudioTracks_1 = require("./checkForAudioTracks");
|
|
15
15
|
Object.defineProperty(exports, "checkForAudioTracks", { enumerable: true, get: function () { return checkForAudioTracks_1.checkForAudioTracks; } });
|
|
16
|
+
var fetchAccessToken_1 = require("./fetchAccessToken");
|
|
17
|
+
Object.defineProperty(exports, "fetchAccessToken", { enumerable: true, get: function () { return fetchAccessToken_1.fetchAccessToken; } });
|
|
16
18
|
var getAudioStream_1 = require("./getAudioStream");
|
|
17
19
|
Object.defineProperty(exports, "getAudioStream", { enumerable: true, get: function () { return getAudioStream_1.getAudioStream; } });
|
|
18
20
|
var getBrowserSupportedMimeType_1 = require("./getBrowserSupportedMimeType");
|