@nlxai/core 1.2.4 → 1.2.7-alpha.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/eslint.config.js +5 -0
- package/lib/index.cjs +50 -32
- package/lib/index.d.ts +9 -0
- package/lib/index.esm.js +54 -36
- package/lib/index.umd.js +12 -12
- package/package.json +10 -15
- package/rollup.config.ts +3 -3
- package/tsdoc.json +19 -2
- package/.eslintrc.cjs +0 -5
- package/docs/README.md +0 -2133
package/eslint.config.js
ADDED
package/lib/index.cjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var fetch = require('isomorphic-fetch');
|
|
4
3
|
var ramda = require('ramda');
|
|
5
4
|
var ReconnectingWebSocket = require('reconnecting-websocket');
|
|
6
5
|
var uuid = require('uuid');
|
|
7
6
|
|
|
8
7
|
var name = "@nlxai/core";
|
|
9
|
-
var version$1 = "1.2.
|
|
8
|
+
var version$1 = "1.2.7-alpha.1";
|
|
10
9
|
var description = "Low-level SDK for building NLX experiences";
|
|
11
10
|
var type = "module";
|
|
12
11
|
var main = "lib/index.cjs";
|
|
@@ -22,8 +21,8 @@ var exports$1 = {
|
|
|
22
21
|
};
|
|
23
22
|
var scripts = {
|
|
24
23
|
build: "rm -rf lib && rollup -c --configPlugin typescript --configImportAttributesKey with",
|
|
25
|
-
"lint:check": "eslint src/
|
|
26
|
-
lint: "eslint src/ --
|
|
24
|
+
"lint:check": "eslint src/",
|
|
25
|
+
lint: "eslint src/ --fix",
|
|
27
26
|
prepublish: "npm run build",
|
|
28
27
|
test: "typedoc --emit none",
|
|
29
28
|
tsc: "tsc",
|
|
@@ -34,36 +33,31 @@ var scripts = {
|
|
|
34
33
|
var author = "Peter Szerzo <peter@nlx.ai>";
|
|
35
34
|
var license = "MIT";
|
|
36
35
|
var devDependencies = {
|
|
37
|
-
"@
|
|
36
|
+
"@nlxai/eslint-config": "*",
|
|
37
|
+
"@nlxai/rollup-config": "*",
|
|
38
38
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
39
|
-
"@rollup/plugin-json": "^6.0
|
|
39
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
40
40
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
41
41
|
"@rollup/plugin-replace": "^5.0.5",
|
|
42
42
|
"@rollup/plugin-terser": "^0.4.4",
|
|
43
|
-
"@rollup/plugin-typescript": "^11.1.
|
|
44
|
-
"@types/isomorphic-fetch": "^0.0.39",
|
|
43
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
45
44
|
"@types/node": "^24.10.1",
|
|
46
45
|
"@types/ramda": "0.31.1",
|
|
47
|
-
"@types/uuid": "^9.0.7",
|
|
48
|
-
"eslint-config-nlx": "*",
|
|
49
46
|
prettier: "^3.1.0",
|
|
50
|
-
rollup: "^4.
|
|
51
|
-
"rollup-config-nlx": "*",
|
|
52
|
-
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
47
|
+
rollup: "^4.59.0",
|
|
53
48
|
typedoc: "^0.28.14",
|
|
54
49
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
55
50
|
typescript: "^5.5.4"
|
|
56
51
|
};
|
|
57
52
|
var dependencies = {
|
|
58
|
-
"isomorphic-fetch": "^3.0.0",
|
|
59
53
|
ramda: "^0.32.0",
|
|
60
54
|
"reconnecting-websocket": "^4.4.0",
|
|
61
|
-
uuid: "^
|
|
55
|
+
uuid: "^14.0.0"
|
|
62
56
|
};
|
|
63
57
|
var publishConfig = {
|
|
64
58
|
access: "public"
|
|
65
59
|
};
|
|
66
|
-
var gitHead = "
|
|
60
|
+
var gitHead = "548c2c6c876cf86572aeb63a6810ed87c9b0382a";
|
|
67
61
|
var packageJson = {
|
|
68
62
|
name: name,
|
|
69
63
|
version: version$1,
|
|
@@ -94,6 +88,10 @@ const Console = console;
|
|
|
94
88
|
*/
|
|
95
89
|
exports.Protocol = void 0;
|
|
96
90
|
(function (Protocol) {
|
|
91
|
+
/**
|
|
92
|
+
* Supported for development purposes only
|
|
93
|
+
*/
|
|
94
|
+
Protocol["Http"] = "http";
|
|
97
95
|
/**
|
|
98
96
|
* Regular encrypted HTTPS, without support for post-escalation message handling, interim messages and other streaming features.
|
|
99
97
|
*/
|
|
@@ -196,14 +194,15 @@ const parseConnection = (config) => {
|
|
|
196
194
|
return null;
|
|
197
195
|
}
|
|
198
196
|
// `applicationUrl`-based definition: http case
|
|
199
|
-
const
|
|
197
|
+
const urlObject = new URL(applicationUrl);
|
|
198
|
+
const host = urlObject.host;
|
|
200
199
|
const parseResult = new URLPattern({
|
|
201
200
|
pathname: "/c/:deploymentKey/:channelKey",
|
|
202
201
|
}).exec(applicationUrl);
|
|
203
202
|
if (parseResult?.pathname.groups.channelKey != null &&
|
|
204
203
|
parseResult?.pathname.groups.deploymentKey != null) {
|
|
205
204
|
return {
|
|
206
|
-
protocol,
|
|
205
|
+
protocol: urlObject.protocol === "http:" ? exports.Protocol.Http : protocol,
|
|
207
206
|
channelKey: parseResult.pathname.groups.channelKey,
|
|
208
207
|
deploymentKey: parseResult.pathname.groups.deploymentKey,
|
|
209
208
|
host,
|
|
@@ -216,13 +215,16 @@ const toWebsocketUrl = (connection) => {
|
|
|
216
215
|
return `wss://us-east-1-ws.${connection.host}?deploymentKey=${connection.deploymentKey}&channelKey=${connection.channelKey}&apiKey=${connection.apiKey}`;
|
|
217
216
|
};
|
|
218
217
|
const toHttpUrl = (connection) => {
|
|
219
|
-
return
|
|
218
|
+
return `${connection.protocol === exports.Protocol.Http ? "http" : "https"}://${connection.host}/c/${connection.deploymentKey}/${connection.channelKey}`;
|
|
220
219
|
};
|
|
221
220
|
const isWebsocketUrl = (url) => {
|
|
222
221
|
return url.indexOf("wss://") === 0;
|
|
223
222
|
};
|
|
224
223
|
const fetchUserMessage = async ({ fullApplicationUrl, apiKey, headers, body, stream, eventListeners, }) => {
|
|
225
224
|
const streamRequest = async (body) => {
|
|
225
|
+
eventListeners.interimMessage.forEach((listener) => {
|
|
226
|
+
listener("Thinking...");
|
|
227
|
+
});
|
|
226
228
|
const response = await fetch(fullApplicationUrl, {
|
|
227
229
|
method: "POST",
|
|
228
230
|
headers: {
|
|
@@ -280,7 +282,7 @@ const fetchUserMessage = async ({ fullApplicationUrl, apiKey, headers, body, str
|
|
|
280
282
|
foundObject = true;
|
|
281
283
|
break;
|
|
282
284
|
}
|
|
283
|
-
catch (
|
|
285
|
+
catch (_e) {
|
|
284
286
|
/* keep scanning */
|
|
285
287
|
}
|
|
286
288
|
}
|
|
@@ -354,16 +356,28 @@ function createConversation(configuration) {
|
|
|
354
356
|
let voicePlusSocketMessageQueue = [];
|
|
355
357
|
let voicePlusSocketMessageQueueCheckInterval = null;
|
|
356
358
|
const connection = parseConnection(configuration);
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
359
|
+
const complete = configuration.experimental?.completeApplicationUrl === true;
|
|
360
|
+
const websocketApplicationUrl = complete && isWebsocketUrl(configuration.applicationUrl ?? "")
|
|
361
|
+
? (configuration.applicationUrl ?? "")
|
|
362
|
+
: connection != null
|
|
363
|
+
? toWebsocketUrl(connection)
|
|
364
|
+
: (configuration.applicationUrl ?? "");
|
|
365
|
+
const httpApplicationUrl = complete && !isWebsocketUrl(configuration.applicationUrl ?? "")
|
|
366
|
+
? (configuration.applicationUrl ?? "")
|
|
367
|
+
: connection != null
|
|
368
|
+
? toHttpUrl(connection)
|
|
369
|
+
: (configuration.applicationUrl ?? "");
|
|
363
370
|
// Check if the application URL has a language code appended to it
|
|
364
371
|
if (/[-|_][a-z]{2,}[-|_][A-Z]{2,}$/.test(httpApplicationUrl)) {
|
|
365
372
|
Console.warn("Since v1.0.0, the language code is no longer added at the end of the application URL. Please remove the modifier (e.g. '-en-US') from the URL, and specify it in the `languageCode` parameter instead.");
|
|
366
373
|
}
|
|
374
|
+
const protocol = connection != null
|
|
375
|
+
? connection.protocol
|
|
376
|
+
: isWebsocketUrl(configuration.applicationUrl ?? "")
|
|
377
|
+
? exports.Protocol.Websocket
|
|
378
|
+
: configuration.experimental?.streamHttp === false
|
|
379
|
+
? exports.Protocol.Https
|
|
380
|
+
: exports.Protocol.HttpsWithStreaming;
|
|
367
381
|
const eventListeners = {
|
|
368
382
|
voicePlusCommand: [],
|
|
369
383
|
interimMessage: [],
|
|
@@ -375,9 +389,7 @@ function createConversation(configuration) {
|
|
|
375
389
|
userId: configuration.userId,
|
|
376
390
|
conversationId: initialConversationId,
|
|
377
391
|
};
|
|
378
|
-
const fullApplicationHttpUrl = () => `${httpApplicationUrl}${
|
|
379
|
-
? ""
|
|
380
|
-
: `-${state.languageCode}`}`;
|
|
392
|
+
const fullApplicationHttpUrl = () => `${httpApplicationUrl}${complete ? "" : `-${state.languageCode}`}`;
|
|
381
393
|
const setState = (change,
|
|
382
394
|
// Optionally send the response that causes the current state change, to be sent to subscribers
|
|
383
395
|
newResponse) => {
|
|
@@ -446,6 +458,11 @@ function createConversation(configuration) {
|
|
|
446
458
|
voicePlusSocketMessageQueue = [...voicePlusSocketMessageQueue, message];
|
|
447
459
|
}
|
|
448
460
|
};
|
|
461
|
+
const setInterimMessage = (message) => {
|
|
462
|
+
eventListeners.interimMessage.forEach((listener) => {
|
|
463
|
+
listener(message);
|
|
464
|
+
});
|
|
465
|
+
};
|
|
449
466
|
const sendToApplication = async (body) => {
|
|
450
467
|
if (requestOverride != null) {
|
|
451
468
|
requestOverride(body, (payload) => {
|
|
@@ -469,7 +486,7 @@ function createConversation(configuration) {
|
|
|
469
486
|
channelType: configuration.experimental?.channelType,
|
|
470
487
|
environment: configuration.environment,
|
|
471
488
|
};
|
|
472
|
-
if (
|
|
489
|
+
if (protocol === exports.Protocol.Websocket) {
|
|
473
490
|
if (socket?.readyState === 1) {
|
|
474
491
|
socket.send(JSON.stringify(bodyWithContext));
|
|
475
492
|
}
|
|
@@ -483,7 +500,7 @@ function createConversation(configuration) {
|
|
|
483
500
|
fullApplicationUrl: fullApplicationHttpUrl(),
|
|
484
501
|
apiKey: connection?.apiKey ?? "",
|
|
485
502
|
headers: configuration.headers ?? {},
|
|
486
|
-
stream:
|
|
503
|
+
stream: protocol === exports.Protocol.HttpsWithStreaming,
|
|
487
504
|
eventListeners,
|
|
488
505
|
body: bodyWithContext,
|
|
489
506
|
});
|
|
@@ -579,7 +596,7 @@ function createConversation(configuration) {
|
|
|
579
596
|
voicePlusSocket = undefined;
|
|
580
597
|
}
|
|
581
598
|
};
|
|
582
|
-
if (
|
|
599
|
+
if (protocol === exports.Protocol.Websocket) {
|
|
583
600
|
setupWebsocket();
|
|
584
601
|
}
|
|
585
602
|
setupCommandWebsocket();
|
|
@@ -713,6 +730,7 @@ function createConversation(configuration) {
|
|
|
713
730
|
responses: [...state.responses, newResponseWithTimestamp],
|
|
714
731
|
}, newResponseWithTimestamp);
|
|
715
732
|
},
|
|
733
|
+
setInterimMessage,
|
|
716
734
|
sendStructured: (structured, context) => {
|
|
717
735
|
appendStructuredUserResponse(structured, context);
|
|
718
736
|
void sendToApplication({
|
package/lib/index.d.ts
CHANGED
|
@@ -235,6 +235,11 @@ export interface ConversationHandler {
|
|
|
235
235
|
* @internal
|
|
236
236
|
*/
|
|
237
237
|
sendVoicePlusContext: (context: VoicePlusContext) => void;
|
|
238
|
+
/**
|
|
239
|
+
* Set interim message. Setting `undefined` clears the current interim message.
|
|
240
|
+
* @param message - interim message.
|
|
241
|
+
*/
|
|
242
|
+
setInterimMessage: (message?: string) => void;
|
|
238
243
|
}
|
|
239
244
|
/**
|
|
240
245
|
* [Context](https://docs.nlx.ai/platform/nlx-platform-guide/flows-and-building-blocks/advanced/context-variables) for usage later in the flow.
|
|
@@ -260,6 +265,10 @@ export interface SlotValue {
|
|
|
260
265
|
* The protocol used to communicate with the application
|
|
261
266
|
*/
|
|
262
267
|
export declare enum Protocol {
|
|
268
|
+
/**
|
|
269
|
+
* Supported for development purposes only
|
|
270
|
+
*/
|
|
271
|
+
Http = "http",
|
|
263
272
|
/**
|
|
264
273
|
* Regular encrypted HTTPS, without support for post-escalation message handling, interim messages and other streaming features.
|
|
265
274
|
*/
|
package/lib/index.esm.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import fetch from 'isomorphic-fetch';
|
|
2
1
|
import { equals, adjust } from 'ramda';
|
|
3
2
|
import ReconnectingWebSocket from 'reconnecting-websocket';
|
|
4
3
|
import { v4 } from 'uuid';
|
|
5
4
|
|
|
6
5
|
var name = "@nlxai/core";
|
|
7
|
-
var version$1 = "1.2.
|
|
6
|
+
var version$1 = "1.2.7-alpha.1";
|
|
8
7
|
var description = "Low-level SDK for building NLX experiences";
|
|
9
8
|
var type = "module";
|
|
10
9
|
var main = "lib/index.cjs";
|
|
11
|
-
var module = "lib/index.esm.js";
|
|
10
|
+
var module$1 = "lib/index.esm.js";
|
|
12
11
|
var browser = "lib/index.umd.js";
|
|
13
12
|
var types = "lib/index.d.ts";
|
|
14
|
-
var exports = {
|
|
13
|
+
var exports$1 = {
|
|
15
14
|
".": {
|
|
16
15
|
types: "./lib/index.d.ts",
|
|
17
16
|
"import": "./lib/index.esm.js",
|
|
@@ -20,8 +19,8 @@ var exports = {
|
|
|
20
19
|
};
|
|
21
20
|
var scripts = {
|
|
22
21
|
build: "rm -rf lib && rollup -c --configPlugin typescript --configImportAttributesKey with",
|
|
23
|
-
"lint:check": "eslint src/
|
|
24
|
-
lint: "eslint src/ --
|
|
22
|
+
"lint:check": "eslint src/",
|
|
23
|
+
lint: "eslint src/ --fix",
|
|
25
24
|
prepublish: "npm run build",
|
|
26
25
|
test: "typedoc --emit none",
|
|
27
26
|
tsc: "tsc",
|
|
@@ -32,46 +31,41 @@ var scripts = {
|
|
|
32
31
|
var author = "Peter Szerzo <peter@nlx.ai>";
|
|
33
32
|
var license = "MIT";
|
|
34
33
|
var devDependencies = {
|
|
35
|
-
"@
|
|
34
|
+
"@nlxai/eslint-config": "*",
|
|
35
|
+
"@nlxai/rollup-config": "*",
|
|
36
36
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
37
|
-
"@rollup/plugin-json": "^6.0
|
|
37
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
38
38
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
39
39
|
"@rollup/plugin-replace": "^5.0.5",
|
|
40
40
|
"@rollup/plugin-terser": "^0.4.4",
|
|
41
|
-
"@rollup/plugin-typescript": "^11.1.
|
|
42
|
-
"@types/isomorphic-fetch": "^0.0.39",
|
|
41
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
43
42
|
"@types/node": "^24.10.1",
|
|
44
43
|
"@types/ramda": "0.31.1",
|
|
45
|
-
"@types/uuid": "^9.0.7",
|
|
46
|
-
"eslint-config-nlx": "*",
|
|
47
44
|
prettier: "^3.1.0",
|
|
48
|
-
rollup: "^4.
|
|
49
|
-
"rollup-config-nlx": "*",
|
|
50
|
-
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
45
|
+
rollup: "^4.59.0",
|
|
51
46
|
typedoc: "^0.28.14",
|
|
52
47
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
53
48
|
typescript: "^5.5.4"
|
|
54
49
|
};
|
|
55
50
|
var dependencies = {
|
|
56
|
-
"isomorphic-fetch": "^3.0.0",
|
|
57
51
|
ramda: "^0.32.0",
|
|
58
52
|
"reconnecting-websocket": "^4.4.0",
|
|
59
|
-
uuid: "^
|
|
53
|
+
uuid: "^14.0.0"
|
|
60
54
|
};
|
|
61
55
|
var publishConfig = {
|
|
62
56
|
access: "public"
|
|
63
57
|
};
|
|
64
|
-
var gitHead = "
|
|
58
|
+
var gitHead = "548c2c6c876cf86572aeb63a6810ed87c9b0382a";
|
|
65
59
|
var packageJson = {
|
|
66
60
|
name: name,
|
|
67
61
|
version: version$1,
|
|
68
62
|
description: description,
|
|
69
63
|
type: type,
|
|
70
64
|
main: main,
|
|
71
|
-
module: module,
|
|
65
|
+
module: module$1,
|
|
72
66
|
browser: browser,
|
|
73
67
|
types: types,
|
|
74
|
-
exports: exports,
|
|
68
|
+
exports: exports$1,
|
|
75
69
|
scripts: scripts,
|
|
76
70
|
author: author,
|
|
77
71
|
license: license,
|
|
@@ -92,6 +86,10 @@ const Console = console;
|
|
|
92
86
|
*/
|
|
93
87
|
var Protocol;
|
|
94
88
|
(function (Protocol) {
|
|
89
|
+
/**
|
|
90
|
+
* Supported for development purposes only
|
|
91
|
+
*/
|
|
92
|
+
Protocol["Http"] = "http";
|
|
95
93
|
/**
|
|
96
94
|
* Regular encrypted HTTPS, without support for post-escalation message handling, interim messages and other streaming features.
|
|
97
95
|
*/
|
|
@@ -194,14 +192,15 @@ const parseConnection = (config) => {
|
|
|
194
192
|
return null;
|
|
195
193
|
}
|
|
196
194
|
// `applicationUrl`-based definition: http case
|
|
197
|
-
const
|
|
195
|
+
const urlObject = new URL(applicationUrl);
|
|
196
|
+
const host = urlObject.host;
|
|
198
197
|
const parseResult = new URLPattern({
|
|
199
198
|
pathname: "/c/:deploymentKey/:channelKey",
|
|
200
199
|
}).exec(applicationUrl);
|
|
201
200
|
if (parseResult?.pathname.groups.channelKey != null &&
|
|
202
201
|
parseResult?.pathname.groups.deploymentKey != null) {
|
|
203
202
|
return {
|
|
204
|
-
protocol,
|
|
203
|
+
protocol: urlObject.protocol === "http:" ? Protocol.Http : protocol,
|
|
205
204
|
channelKey: parseResult.pathname.groups.channelKey,
|
|
206
205
|
deploymentKey: parseResult.pathname.groups.deploymentKey,
|
|
207
206
|
host,
|
|
@@ -214,13 +213,16 @@ const toWebsocketUrl = (connection) => {
|
|
|
214
213
|
return `wss://us-east-1-ws.${connection.host}?deploymentKey=${connection.deploymentKey}&channelKey=${connection.channelKey}&apiKey=${connection.apiKey}`;
|
|
215
214
|
};
|
|
216
215
|
const toHttpUrl = (connection) => {
|
|
217
|
-
return
|
|
216
|
+
return `${connection.protocol === Protocol.Http ? "http" : "https"}://${connection.host}/c/${connection.deploymentKey}/${connection.channelKey}`;
|
|
218
217
|
};
|
|
219
218
|
const isWebsocketUrl = (url) => {
|
|
220
219
|
return url.indexOf("wss://") === 0;
|
|
221
220
|
};
|
|
222
221
|
const fetchUserMessage = async ({ fullApplicationUrl, apiKey, headers, body, stream, eventListeners, }) => {
|
|
223
222
|
const streamRequest = async (body) => {
|
|
223
|
+
eventListeners.interimMessage.forEach((listener) => {
|
|
224
|
+
listener("Thinking...");
|
|
225
|
+
});
|
|
224
226
|
const response = await fetch(fullApplicationUrl, {
|
|
225
227
|
method: "POST",
|
|
226
228
|
headers: {
|
|
@@ -278,7 +280,7 @@ const fetchUserMessage = async ({ fullApplicationUrl, apiKey, headers, body, str
|
|
|
278
280
|
foundObject = true;
|
|
279
281
|
break;
|
|
280
282
|
}
|
|
281
|
-
catch (
|
|
283
|
+
catch (_e) {
|
|
282
284
|
/* keep scanning */
|
|
283
285
|
}
|
|
284
286
|
}
|
|
@@ -352,16 +354,28 @@ function createConversation(configuration) {
|
|
|
352
354
|
let voicePlusSocketMessageQueue = [];
|
|
353
355
|
let voicePlusSocketMessageQueueCheckInterval = null;
|
|
354
356
|
const connection = parseConnection(configuration);
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
357
|
+
const complete = configuration.experimental?.completeApplicationUrl === true;
|
|
358
|
+
const websocketApplicationUrl = complete && isWebsocketUrl(configuration.applicationUrl ?? "")
|
|
359
|
+
? (configuration.applicationUrl ?? "")
|
|
360
|
+
: connection != null
|
|
361
|
+
? toWebsocketUrl(connection)
|
|
362
|
+
: (configuration.applicationUrl ?? "");
|
|
363
|
+
const httpApplicationUrl = complete && !isWebsocketUrl(configuration.applicationUrl ?? "")
|
|
364
|
+
? (configuration.applicationUrl ?? "")
|
|
365
|
+
: connection != null
|
|
366
|
+
? toHttpUrl(connection)
|
|
367
|
+
: (configuration.applicationUrl ?? "");
|
|
361
368
|
// Check if the application URL has a language code appended to it
|
|
362
369
|
if (/[-|_][a-z]{2,}[-|_][A-Z]{2,}$/.test(httpApplicationUrl)) {
|
|
363
370
|
Console.warn("Since v1.0.0, the language code is no longer added at the end of the application URL. Please remove the modifier (e.g. '-en-US') from the URL, and specify it in the `languageCode` parameter instead.");
|
|
364
371
|
}
|
|
372
|
+
const protocol = connection != null
|
|
373
|
+
? connection.protocol
|
|
374
|
+
: isWebsocketUrl(configuration.applicationUrl ?? "")
|
|
375
|
+
? Protocol.Websocket
|
|
376
|
+
: configuration.experimental?.streamHttp === false
|
|
377
|
+
? Protocol.Https
|
|
378
|
+
: Protocol.HttpsWithStreaming;
|
|
365
379
|
const eventListeners = {
|
|
366
380
|
voicePlusCommand: [],
|
|
367
381
|
interimMessage: [],
|
|
@@ -373,9 +387,7 @@ function createConversation(configuration) {
|
|
|
373
387
|
userId: configuration.userId,
|
|
374
388
|
conversationId: initialConversationId,
|
|
375
389
|
};
|
|
376
|
-
const fullApplicationHttpUrl = () => `${httpApplicationUrl}${
|
|
377
|
-
? ""
|
|
378
|
-
: `-${state.languageCode}`}`;
|
|
390
|
+
const fullApplicationHttpUrl = () => `${httpApplicationUrl}${complete ? "" : `-${state.languageCode}`}`;
|
|
379
391
|
const setState = (change,
|
|
380
392
|
// Optionally send the response that causes the current state change, to be sent to subscribers
|
|
381
393
|
newResponse) => {
|
|
@@ -444,6 +456,11 @@ function createConversation(configuration) {
|
|
|
444
456
|
voicePlusSocketMessageQueue = [...voicePlusSocketMessageQueue, message];
|
|
445
457
|
}
|
|
446
458
|
};
|
|
459
|
+
const setInterimMessage = (message) => {
|
|
460
|
+
eventListeners.interimMessage.forEach((listener) => {
|
|
461
|
+
listener(message);
|
|
462
|
+
});
|
|
463
|
+
};
|
|
447
464
|
const sendToApplication = async (body) => {
|
|
448
465
|
if (requestOverride != null) {
|
|
449
466
|
requestOverride(body, (payload) => {
|
|
@@ -467,7 +484,7 @@ function createConversation(configuration) {
|
|
|
467
484
|
channelType: configuration.experimental?.channelType,
|
|
468
485
|
environment: configuration.environment,
|
|
469
486
|
};
|
|
470
|
-
if (
|
|
487
|
+
if (protocol === Protocol.Websocket) {
|
|
471
488
|
if (socket?.readyState === 1) {
|
|
472
489
|
socket.send(JSON.stringify(bodyWithContext));
|
|
473
490
|
}
|
|
@@ -481,7 +498,7 @@ function createConversation(configuration) {
|
|
|
481
498
|
fullApplicationUrl: fullApplicationHttpUrl(),
|
|
482
499
|
apiKey: connection?.apiKey ?? "",
|
|
483
500
|
headers: configuration.headers ?? {},
|
|
484
|
-
stream:
|
|
501
|
+
stream: protocol === Protocol.HttpsWithStreaming,
|
|
485
502
|
eventListeners,
|
|
486
503
|
body: bodyWithContext,
|
|
487
504
|
});
|
|
@@ -577,7 +594,7 @@ function createConversation(configuration) {
|
|
|
577
594
|
voicePlusSocket = undefined;
|
|
578
595
|
}
|
|
579
596
|
};
|
|
580
|
-
if (
|
|
597
|
+
if (protocol === Protocol.Websocket) {
|
|
581
598
|
setupWebsocket();
|
|
582
599
|
}
|
|
583
600
|
setupCommandWebsocket();
|
|
@@ -711,6 +728,7 @@ function createConversation(configuration) {
|
|
|
711
728
|
responses: [...state.responses, newResponseWithTimestamp],
|
|
712
729
|
}, newResponseWithTimestamp);
|
|
713
730
|
},
|
|
731
|
+
setInterimMessage,
|
|
714
732
|
sendStructured: (structured, context) => {
|
|
715
733
|
appendStructuredUserResponse(structured, context);
|
|
716
734
|
void sendToApplication({
|