@nlxai/core 1.2.4-alpha.5 → 1.2.4-alpha.8
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/README.md +137 -0
- package/lib/index.cjs +162 -18
- package/lib/index.d.ts +68 -0
- package/lib/index.esm.js +162 -19
- package/lib/index.umd.js +2 -2
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -440,6 +440,101 @@ sendTextWrapped("Hello").then((response) => {
|
|
|
440
440
|
});
|
|
441
441
|
```
|
|
442
442
|
|
|
443
|
+
---
|
|
444
|
+
|
|
445
|
+
### sendVoicePlusStep()
|
|
446
|
+
|
|
447
|
+
```ts
|
|
448
|
+
function sendVoicePlusStep(configuration): Promise<void>;
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
Use this function when using **Voice+ scripts** to advance the conversation to the step specified.
|
|
452
|
+
|
|
453
|
+
This functionality is orthogonal from other usage of the core SDK, as it may be used either using standard SDK communication channels or it can be used to provide a Voice+ script experience with for instance a telephony based channel.
|
|
454
|
+
|
|
455
|
+
#### Parameters
|
|
456
|
+
|
|
457
|
+
##### configuration
|
|
458
|
+
|
|
459
|
+
Configuration for sending the step. Many of the values can be found on the deployment modal of the Voice+ script.
|
|
460
|
+
|
|
461
|
+
###### apiKey
|
|
462
|
+
|
|
463
|
+
`string`
|
|
464
|
+
|
|
465
|
+
- the API key generated for the Voice+ script. Note that this value is different from the API key you would pass to [createConversation](#createconversation). You can control the API key on the Voice+ script settings page.
|
|
466
|
+
|
|
467
|
+
###### scriptId?
|
|
468
|
+
|
|
469
|
+
`string`
|
|
470
|
+
|
|
471
|
+
The ID of the Voice+ script.
|
|
472
|
+
|
|
473
|
+
###### workspaceId
|
|
474
|
+
|
|
475
|
+
`string`
|
|
476
|
+
|
|
477
|
+
Your workspace ID.
|
|
478
|
+
|
|
479
|
+
###### conversationId
|
|
480
|
+
|
|
481
|
+
`string`
|
|
482
|
+
|
|
483
|
+
The active conversation ID, passed from the active NLX voice application. This is what ties the script exectution to the specific Voice application.
|
|
484
|
+
|
|
485
|
+
_Note: This must be dynamically set by the voice application._ Normally, when the voice application directs the user to the webpage running this code, it will include the conversation ID as a URL parameter which you can extract and pass here.
|
|
486
|
+
|
|
487
|
+
**Example**
|
|
488
|
+
|
|
489
|
+
```typescript
|
|
490
|
+
const conversationId = new URLSearchParams(window.location.search).get("cid");
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
###### languageCode
|
|
494
|
+
|
|
495
|
+
`string`
|
|
496
|
+
|
|
497
|
+
The user's language code, consistent with the language codes defined on the Voice+ script.
|
|
498
|
+
|
|
499
|
+
###### step
|
|
500
|
+
|
|
501
|
+
[`StepInfo`](#stepinfo)
|
|
502
|
+
|
|
503
|
+
Which step to send.
|
|
504
|
+
|
|
505
|
+
###### context
|
|
506
|
+
|
|
507
|
+
[`Context`](#context)
|
|
508
|
+
|
|
509
|
+
Any context.
|
|
510
|
+
|
|
511
|
+
###### debug?
|
|
512
|
+
|
|
513
|
+
`boolean` = `false`
|
|
514
|
+
|
|
515
|
+
Set to `true` to help debug issues or errors. Defaults to `false`.
|
|
516
|
+
|
|
517
|
+
#### Returns
|
|
518
|
+
|
|
519
|
+
`Promise`\<`void`\>
|
|
520
|
+
|
|
521
|
+
#### Example
|
|
522
|
+
|
|
523
|
+
```typescript
|
|
524
|
+
import { sendVoicePlusStep } from "@nlxai/core";
|
|
525
|
+
|
|
526
|
+
await sendVoicePlusStep({
|
|
527
|
+
// hard-coded params
|
|
528
|
+
apiKey: "REPLACE_WITH_API_KEY",
|
|
529
|
+
workspaceId: "REPLACE_WITH_WORKSPACE_ID",
|
|
530
|
+
scriptId: "REPLACE_WITH_SCRIPT_ID",
|
|
531
|
+
step: "REPLACE_WITH_STEP_ID",
|
|
532
|
+
// dynamic params
|
|
533
|
+
conversationId: "REPLACE_WITH_CONVERSATION_ID",
|
|
534
|
+
languageCode: "en-US",
|
|
535
|
+
});
|
|
536
|
+
```
|
|
537
|
+
|
|
443
538
|
## Variables
|
|
444
539
|
|
|
445
540
|
### version
|
|
@@ -2155,3 +2250,45 @@ The callback function for listening to all responses.
|
|
|
2155
2250
|
|
|
2156
2251
|
`void`
|
|
2157
2252
|
|
|
2253
|
+
---
|
|
2254
|
+
|
|
2255
|
+
### StepInfo
|
|
2256
|
+
|
|
2257
|
+
```ts
|
|
2258
|
+
type StepInfo =
|
|
2259
|
+
| string
|
|
2260
|
+
| {
|
|
2261
|
+
stepId: string;
|
|
2262
|
+
stepTriggerDescription?: string;
|
|
2263
|
+
};
|
|
2264
|
+
```
|
|
2265
|
+
|
|
2266
|
+
Step information, either a step ID as a single string or an object
|
|
2267
|
+
|
|
2268
|
+
#### Type Declaration
|
|
2269
|
+
|
|
2270
|
+
`string`
|
|
2271
|
+
|
|
2272
|
+
```ts
|
|
2273
|
+
{
|
|
2274
|
+
stepId: string;
|
|
2275
|
+
stepTriggerDescription?: string;
|
|
2276
|
+
}
|
|
2277
|
+
```
|
|
2278
|
+
|
|
2279
|
+
##### stepId
|
|
2280
|
+
|
|
2281
|
+
```ts
|
|
2282
|
+
stepId: string;
|
|
2283
|
+
```
|
|
2284
|
+
|
|
2285
|
+
Step ID
|
|
2286
|
+
|
|
2287
|
+
##### stepTriggerDescription?
|
|
2288
|
+
|
|
2289
|
+
```ts
|
|
2290
|
+
optional stepTriggerDescription: string;
|
|
2291
|
+
```
|
|
2292
|
+
|
|
2293
|
+
Step trigger description
|
|
2294
|
+
|
package/lib/index.cjs
CHANGED
|
@@ -5,9 +5,82 @@ var ramda = require('ramda');
|
|
|
5
5
|
var ReconnectingWebSocket = require('reconnecting-websocket');
|
|
6
6
|
var uuid = require('uuid');
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var name = "@nlxai/core";
|
|
9
|
+
var version$1 = "1.2.4-alpha.8";
|
|
10
|
+
var description = "Low-level SDK for building NLX experiences";
|
|
11
|
+
var type = "module";
|
|
12
|
+
var main = "lib/index.cjs";
|
|
13
|
+
var module$1 = "lib/index.esm.js";
|
|
14
|
+
var browser = "lib/index.umd.js";
|
|
15
|
+
var types = "lib/index.d.ts";
|
|
16
|
+
var exports$1 = {
|
|
17
|
+
".": {
|
|
18
|
+
types: "./lib/index.d.ts",
|
|
19
|
+
"import": "./lib/index.esm.js",
|
|
20
|
+
require: "./lib/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var scripts = {
|
|
24
|
+
build: "rm -rf lib && rollup -c --configPlugin typescript --configImportAttributesKey with",
|
|
25
|
+
"lint:check": "eslint src/ --ext .ts,.tsx,.js,.jsx --max-warnings 0",
|
|
26
|
+
lint: "eslint src/ --ext .ts,.tsx,.js,.jsx --fix",
|
|
27
|
+
prepublish: "npm run build",
|
|
28
|
+
test: "typedoc --emit none",
|
|
29
|
+
tsc: "tsc",
|
|
30
|
+
"update-readme:docs": "rm -rf docs/ && typedoc",
|
|
31
|
+
"update-readme:merge": "../../scripts/transclude-markdown.js",
|
|
32
|
+
"update-readme": "npm run update-readme:docs && npm run update-readme:merge"
|
|
33
|
+
};
|
|
34
|
+
var author = "Peter Szerzo <peter@nlx.ai>";
|
|
35
|
+
var license = "MIT";
|
|
36
|
+
var devDependencies = {
|
|
37
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
38
|
+
"@rollup/plugin-json": "^6.0.1",
|
|
39
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
40
|
+
"@rollup/plugin-replace": "^5.0.5",
|
|
41
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
42
|
+
"@rollup/plugin-typescript": "^11.1.5",
|
|
43
|
+
"@types/isomorphic-fetch": "^0.0.39",
|
|
44
|
+
"@types/node": "^24.10.1",
|
|
45
|
+
"@types/ramda": "0.31.1",
|
|
46
|
+
"@types/uuid": "^9.0.7",
|
|
47
|
+
"eslint-config-nlx": "*",
|
|
48
|
+
prettier: "^3.1.0",
|
|
49
|
+
rollup: "^4.3.0",
|
|
50
|
+
"rollup-config-nlx": "*",
|
|
51
|
+
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
52
|
+
typedoc: "^0.28.14",
|
|
53
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
54
|
+
typescript: "^5.5.4"
|
|
55
|
+
};
|
|
56
|
+
var dependencies = {
|
|
57
|
+
"isomorphic-fetch": "^3.0.0",
|
|
58
|
+
ramda: "^0.32.0",
|
|
59
|
+
"reconnecting-websocket": "^4.4.0",
|
|
60
|
+
uuid: "^9.0.1"
|
|
61
|
+
};
|
|
62
|
+
var publishConfig = {
|
|
63
|
+
access: "public"
|
|
64
|
+
};
|
|
65
|
+
var gitHead = "42d1a368a8d42b34b1a4782c477f6bca3f660e4c";
|
|
9
66
|
var packageJson = {
|
|
10
|
-
|
|
67
|
+
name: name,
|
|
68
|
+
version: version$1,
|
|
69
|
+
description: description,
|
|
70
|
+
type: type,
|
|
71
|
+
main: main,
|
|
72
|
+
module: module$1,
|
|
73
|
+
browser: browser,
|
|
74
|
+
types: types,
|
|
75
|
+
exports: exports$1,
|
|
76
|
+
scripts: scripts,
|
|
77
|
+
author: author,
|
|
78
|
+
license: license,
|
|
79
|
+
devDependencies: devDependencies,
|
|
80
|
+
dependencies: dependencies,
|
|
81
|
+
publishConfig: publishConfig,
|
|
82
|
+
gitHead: gitHead
|
|
83
|
+
};
|
|
11
84
|
|
|
12
85
|
/**
|
|
13
86
|
* Package version
|
|
@@ -104,7 +177,9 @@ const fetchUserMessage = async ({ fullApplicationUrl, headers, body, stream, eve
|
|
|
104
177
|
headers: {
|
|
105
178
|
...headers,
|
|
106
179
|
"Content-Type": "application/json",
|
|
180
|
+
// Legacy header
|
|
107
181
|
"nlx-sdk-version": packageJson.version,
|
|
182
|
+
"nlx-core-version": packageJson.version,
|
|
108
183
|
},
|
|
109
184
|
body: JSON.stringify({ ...body, stream: true }),
|
|
110
185
|
});
|
|
@@ -165,7 +240,18 @@ const fetchUserMessage = async ({ fullApplicationUrl, headers, body, stream, eve
|
|
|
165
240
|
eventListeners.interimMessage.forEach((listener) => {
|
|
166
241
|
listener(undefined);
|
|
167
242
|
});
|
|
168
|
-
return {
|
|
243
|
+
return {
|
|
244
|
+
...finalResponse,
|
|
245
|
+
messages: [
|
|
246
|
+
...messages,
|
|
247
|
+
...(finalResponse.messages ?? []).map((json) => ({
|
|
248
|
+
text: json.text,
|
|
249
|
+
choices: json.choices ?? [],
|
|
250
|
+
messageId: json.messageId,
|
|
251
|
+
metadata: json.metadata,
|
|
252
|
+
})),
|
|
253
|
+
],
|
|
254
|
+
};
|
|
169
255
|
};
|
|
170
256
|
if (stream) {
|
|
171
257
|
return await streamRequest(body);
|
|
@@ -177,7 +263,9 @@ const fetchUserMessage = async ({ fullApplicationUrl, headers, body, stream, eve
|
|
|
177
263
|
...(headers ?? {}),
|
|
178
264
|
Accept: "application/json",
|
|
179
265
|
"Content-Type": "application/json",
|
|
266
|
+
// Legacy header
|
|
180
267
|
"nlx-sdk-version": packageJson.version,
|
|
268
|
+
"nlx-core-version": packageJson.version,
|
|
181
269
|
},
|
|
182
270
|
body: JSON.stringify(body),
|
|
183
271
|
});
|
|
@@ -379,21 +467,6 @@ function createConversation(configuration) {
|
|
|
379
467
|
messageResponseHandler(safeJsonParse(e.data));
|
|
380
468
|
}
|
|
381
469
|
};
|
|
382
|
-
url.searchParams.set("voice-plus", "true");
|
|
383
|
-
voicePlusSocket = new ReconnectingWebSocket(url.href);
|
|
384
|
-
voicePlusSocketMessageQueueCheckInterval = setInterval(() => {
|
|
385
|
-
checkVoicePlusSocketQueue();
|
|
386
|
-
}, 500);
|
|
387
|
-
voicePlusSocket.onmessage = (e) => {
|
|
388
|
-
if (typeof e?.data === "string") {
|
|
389
|
-
const command = safeJsonParse(e.data);
|
|
390
|
-
if (command != null) {
|
|
391
|
-
eventListeners.voicePlusCommand.forEach((listener) => {
|
|
392
|
-
listener(command);
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
};
|
|
397
470
|
};
|
|
398
471
|
const setupCommandWebsocket = () => {
|
|
399
472
|
// If the socket is already set up, tear it down first
|
|
@@ -556,7 +629,9 @@ function createConversation(configuration) {
|
|
|
556
629
|
Accept: "application/json",
|
|
557
630
|
"Content-Type": "application/json",
|
|
558
631
|
"nlx-conversation-id": state.conversationId,
|
|
632
|
+
// Legacy header
|
|
559
633
|
"nlx-sdk-version": packageJson.version,
|
|
634
|
+
"nlx-core-version": packageJson.version,
|
|
560
635
|
},
|
|
561
636
|
body: JSON.stringify({
|
|
562
637
|
languageCode: state.languageCode,
|
|
@@ -654,7 +729,9 @@ function createConversation(configuration) {
|
|
|
654
729
|
Accept: "application/json",
|
|
655
730
|
"Content-Type": "application/json",
|
|
656
731
|
"nlx-conversation-id": state.conversationId,
|
|
732
|
+
// Legacy header
|
|
657
733
|
"nlx-sdk-version": packageJson.version,
|
|
734
|
+
"nlx-core-version": packageJson.version,
|
|
658
735
|
},
|
|
659
736
|
body: JSON.stringify({
|
|
660
737
|
languageCode: state.languageCode,
|
|
@@ -810,10 +887,77 @@ function promisify(fn, convo, timeout = 10000) {
|
|
|
810
887
|
});
|
|
811
888
|
};
|
|
812
889
|
}
|
|
890
|
+
/**
|
|
891
|
+
* Use this function when using **Voice+ scripts** to advance the conversation to the step specified.
|
|
892
|
+
*
|
|
893
|
+
* This functionality is orthogonal from other usage of the core SDK, as it may be used either using standard SDK communication channels or it can be used to provide a Voice+ script experience with for instance a telephony based channel.
|
|
894
|
+
* @example
|
|
895
|
+
* ```typescript
|
|
896
|
+
* import { sendVoicePlusStep } from "@nlxai/core";
|
|
897
|
+
*
|
|
898
|
+
* await sendVoicePlusStep({
|
|
899
|
+
* // hard-coded params
|
|
900
|
+
* apiKey: "REPLACE_WITH_API_KEY",
|
|
901
|
+
* workspaceId: "REPLACE_WITH_WORKSPACE_ID",
|
|
902
|
+
* scriptId: "REPLACE_WITH_SCRIPT_ID",
|
|
903
|
+
* step: "REPLACE_WITH_STEP_ID",
|
|
904
|
+
* // dynamic params
|
|
905
|
+
* conversationId: "REPLACE_WITH_CONVERSATION_ID",
|
|
906
|
+
* languageCode: "en-US",
|
|
907
|
+
* });
|
|
908
|
+
* ```
|
|
909
|
+
* @param configuration - Configuration for sending the step. Many of the values can be found on the deployment modal of the Voice+ script.
|
|
910
|
+
*/
|
|
911
|
+
const sendVoicePlusStep = async ({ apiKey, workspaceId, conversationId, scriptId, languageCode, step, context, debug = false, dev = false, }) => {
|
|
912
|
+
if (scriptId == null) {
|
|
913
|
+
throw new Error("Voice+ scriptId is not defined.");
|
|
914
|
+
}
|
|
915
|
+
if (typeof conversationId !== "string" || conversationId.length === 0) {
|
|
916
|
+
throw new Error("Voice+ conversationId is not defined.");
|
|
917
|
+
}
|
|
918
|
+
const [stepId, stepTriggerDescription] = typeof step === "string"
|
|
919
|
+
? [step, undefined]
|
|
920
|
+
: [step.stepId, step.stepTriggerDescription];
|
|
921
|
+
if (!stepIdRegex.test(stepId)) {
|
|
922
|
+
throw new Error("Invalid stepId. It should be formatted as a UUID.");
|
|
923
|
+
}
|
|
924
|
+
const payload = {
|
|
925
|
+
stepId,
|
|
926
|
+
context,
|
|
927
|
+
conversationId,
|
|
928
|
+
journeyId: scriptId,
|
|
929
|
+
languageCode,
|
|
930
|
+
stepTriggerDescription,
|
|
931
|
+
};
|
|
932
|
+
try {
|
|
933
|
+
await fetch(`https://${dev ? "dev." : ""}mm.nlx.ai/v1/track`, {
|
|
934
|
+
method: "POST",
|
|
935
|
+
headers: {
|
|
936
|
+
"x-api-key": apiKey,
|
|
937
|
+
"x-nlx-id": workspaceId,
|
|
938
|
+
"Content-Type": "application/json",
|
|
939
|
+
"nlx-sdk-version": packageJson.version,
|
|
940
|
+
"nlx-core-version": packageJson.version,
|
|
941
|
+
},
|
|
942
|
+
body: JSON.stringify(payload),
|
|
943
|
+
});
|
|
944
|
+
if (debug) {
|
|
945
|
+
Console.info(`✓ step: ${stepId}`, payload);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
catch (err) {
|
|
949
|
+
if (debug) {
|
|
950
|
+
Console.error(`× step: ${stepId}`, err, payload);
|
|
951
|
+
}
|
|
952
|
+
throw err;
|
|
953
|
+
}
|
|
954
|
+
};
|
|
955
|
+
const stepIdRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
813
956
|
|
|
814
957
|
exports.createConversation = createConversation;
|
|
815
958
|
exports.getCurrentExpirationTimestamp = getCurrentExpirationTimestamp;
|
|
816
959
|
exports.isConfigValid = isConfigValid;
|
|
817
960
|
exports.promisify = promisify;
|
|
961
|
+
exports.sendVoicePlusStep = sendVoicePlusStep;
|
|
818
962
|
exports.shouldReinitialize = shouldReinitialize;
|
|
819
963
|
exports.version = version;
|
package/lib/index.d.ts
CHANGED
|
@@ -890,3 +890,71 @@ export declare const getCurrentExpirationTimestamp: (responses: Response[]) => n
|
|
|
890
890
|
* @returns A promise-wrapped version of the function. The function, when called, returns a promise that resolves to the Conversation's next response.
|
|
891
891
|
*/
|
|
892
892
|
export declare function promisify<Params>(fn: (payload: Params) => void, convo: ConversationHandler, timeout?: number): (payload: Params) => Promise<Response | null>;
|
|
893
|
+
/**
|
|
894
|
+
* @inline @hidden
|
|
895
|
+
*/
|
|
896
|
+
export interface VoicePlusStepConfig {
|
|
897
|
+
/** * the API key generated for the Voice+ script. Note that this value is different from the API key you would pass to {@link createConversation}. You can control the API key on the Voice+ script settings page. */
|
|
898
|
+
apiKey: string;
|
|
899
|
+
/** The ID of the Voice+ script. */
|
|
900
|
+
scriptId?: string;
|
|
901
|
+
/** Your workspace ID. */
|
|
902
|
+
workspaceId: string;
|
|
903
|
+
/**
|
|
904
|
+
* The active conversation ID, passed from the active NLX voice application. This is what ties the script exectution to the specific Voice application.
|
|
905
|
+
*
|
|
906
|
+
* _Note: This must be dynamically set by the voice application._ Normally, when the voice application directs the user to the webpage running this code, it will include the conversation ID as a URL parameter which you can extract and pass here.
|
|
907
|
+
* @example
|
|
908
|
+
* ```typescript
|
|
909
|
+
* const conversationId = new URLSearchParams(window.location.search).get("cid");
|
|
910
|
+
* ```
|
|
911
|
+
*/
|
|
912
|
+
conversationId: string;
|
|
913
|
+
/**
|
|
914
|
+
* The user's language code, consistent with the language codes defined on the Voice+ script.
|
|
915
|
+
*/
|
|
916
|
+
languageCode: string;
|
|
917
|
+
/** Which step to send. */
|
|
918
|
+
step: StepInfo;
|
|
919
|
+
/** Any context. */
|
|
920
|
+
context: Context;
|
|
921
|
+
/** Set to `true` to help debug issues or errors. Defaults to `false`. */
|
|
922
|
+
debug?: boolean;
|
|
923
|
+
/** Used for library testing @internal @hidden */
|
|
924
|
+
dev?: boolean;
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Step information, either a step ID as a single string or an object
|
|
928
|
+
*/
|
|
929
|
+
export type StepInfo = string | {
|
|
930
|
+
/**
|
|
931
|
+
* Step ID
|
|
932
|
+
*/
|
|
933
|
+
stepId: string;
|
|
934
|
+
/**
|
|
935
|
+
* Step trigger description
|
|
936
|
+
*/
|
|
937
|
+
stepTriggerDescription?: string;
|
|
938
|
+
};
|
|
939
|
+
/**
|
|
940
|
+
* Use this function when using **Voice+ scripts** to advance the conversation to the step specified.
|
|
941
|
+
*
|
|
942
|
+
* This functionality is orthogonal from other usage of the core SDK, as it may be used either using standard SDK communication channels or it can be used to provide a Voice+ script experience with for instance a telephony based channel.
|
|
943
|
+
* @example
|
|
944
|
+
* ```typescript
|
|
945
|
+
* import { sendVoicePlusStep } from "@nlxai/core";
|
|
946
|
+
*
|
|
947
|
+
* await sendVoicePlusStep({
|
|
948
|
+
* // hard-coded params
|
|
949
|
+
* apiKey: "REPLACE_WITH_API_KEY",
|
|
950
|
+
* workspaceId: "REPLACE_WITH_WORKSPACE_ID",
|
|
951
|
+
* scriptId: "REPLACE_WITH_SCRIPT_ID",
|
|
952
|
+
* step: "REPLACE_WITH_STEP_ID",
|
|
953
|
+
* // dynamic params
|
|
954
|
+
* conversationId: "REPLACE_WITH_CONVERSATION_ID",
|
|
955
|
+
* languageCode: "en-US",
|
|
956
|
+
* });
|
|
957
|
+
* ```
|
|
958
|
+
* @param configuration - Configuration for sending the step. Many of the values can be found on the deployment modal of the Voice+ script.
|
|
959
|
+
*/
|
|
960
|
+
export declare const sendVoicePlusStep: ({ apiKey, workspaceId, conversationId, scriptId, languageCode, step, context, debug, dev, }: VoicePlusStepConfig) => Promise<void>;
|
package/lib/index.esm.js
CHANGED
|
@@ -3,9 +3,82 @@ import { equals, adjust } from 'ramda';
|
|
|
3
3
|
import ReconnectingWebSocket from 'reconnecting-websocket';
|
|
4
4
|
import { v4 } from 'uuid';
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var name = "@nlxai/core";
|
|
7
|
+
var version$1 = "1.2.4-alpha.8";
|
|
8
|
+
var description = "Low-level SDK for building NLX experiences";
|
|
9
|
+
var type = "module";
|
|
10
|
+
var main = "lib/index.cjs";
|
|
11
|
+
var module = "lib/index.esm.js";
|
|
12
|
+
var browser = "lib/index.umd.js";
|
|
13
|
+
var types = "lib/index.d.ts";
|
|
14
|
+
var exports = {
|
|
15
|
+
".": {
|
|
16
|
+
types: "./lib/index.d.ts",
|
|
17
|
+
"import": "./lib/index.esm.js",
|
|
18
|
+
require: "./lib/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var scripts = {
|
|
22
|
+
build: "rm -rf lib && rollup -c --configPlugin typescript --configImportAttributesKey with",
|
|
23
|
+
"lint:check": "eslint src/ --ext .ts,.tsx,.js,.jsx --max-warnings 0",
|
|
24
|
+
lint: "eslint src/ --ext .ts,.tsx,.js,.jsx --fix",
|
|
25
|
+
prepublish: "npm run build",
|
|
26
|
+
test: "typedoc --emit none",
|
|
27
|
+
tsc: "tsc",
|
|
28
|
+
"update-readme:docs": "rm -rf docs/ && typedoc",
|
|
29
|
+
"update-readme:merge": "../../scripts/transclude-markdown.js",
|
|
30
|
+
"update-readme": "npm run update-readme:docs && npm run update-readme:merge"
|
|
31
|
+
};
|
|
32
|
+
var author = "Peter Szerzo <peter@nlx.ai>";
|
|
33
|
+
var license = "MIT";
|
|
34
|
+
var devDependencies = {
|
|
35
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
36
|
+
"@rollup/plugin-json": "^6.0.1",
|
|
37
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
38
|
+
"@rollup/plugin-replace": "^5.0.5",
|
|
39
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
40
|
+
"@rollup/plugin-typescript": "^11.1.5",
|
|
41
|
+
"@types/isomorphic-fetch": "^0.0.39",
|
|
42
|
+
"@types/node": "^24.10.1",
|
|
43
|
+
"@types/ramda": "0.31.1",
|
|
44
|
+
"@types/uuid": "^9.0.7",
|
|
45
|
+
"eslint-config-nlx": "*",
|
|
46
|
+
prettier: "^3.1.0",
|
|
47
|
+
rollup: "^4.3.0",
|
|
48
|
+
"rollup-config-nlx": "*",
|
|
49
|
+
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
50
|
+
typedoc: "^0.28.14",
|
|
51
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
52
|
+
typescript: "^5.5.4"
|
|
53
|
+
};
|
|
54
|
+
var dependencies = {
|
|
55
|
+
"isomorphic-fetch": "^3.0.0",
|
|
56
|
+
ramda: "^0.32.0",
|
|
57
|
+
"reconnecting-websocket": "^4.4.0",
|
|
58
|
+
uuid: "^9.0.1"
|
|
59
|
+
};
|
|
60
|
+
var publishConfig = {
|
|
61
|
+
access: "public"
|
|
62
|
+
};
|
|
63
|
+
var gitHead = "42d1a368a8d42b34b1a4782c477f6bca3f660e4c";
|
|
7
64
|
var packageJson = {
|
|
8
|
-
|
|
65
|
+
name: name,
|
|
66
|
+
version: version$1,
|
|
67
|
+
description: description,
|
|
68
|
+
type: type,
|
|
69
|
+
main: main,
|
|
70
|
+
module: module,
|
|
71
|
+
browser: browser,
|
|
72
|
+
types: types,
|
|
73
|
+
exports: exports,
|
|
74
|
+
scripts: scripts,
|
|
75
|
+
author: author,
|
|
76
|
+
license: license,
|
|
77
|
+
devDependencies: devDependencies,
|
|
78
|
+
dependencies: dependencies,
|
|
79
|
+
publishConfig: publishConfig,
|
|
80
|
+
gitHead: gitHead
|
|
81
|
+
};
|
|
9
82
|
|
|
10
83
|
/**
|
|
11
84
|
* Package version
|
|
@@ -102,7 +175,9 @@ const fetchUserMessage = async ({ fullApplicationUrl, headers, body, stream, eve
|
|
|
102
175
|
headers: {
|
|
103
176
|
...headers,
|
|
104
177
|
"Content-Type": "application/json",
|
|
178
|
+
// Legacy header
|
|
105
179
|
"nlx-sdk-version": packageJson.version,
|
|
180
|
+
"nlx-core-version": packageJson.version,
|
|
106
181
|
},
|
|
107
182
|
body: JSON.stringify({ ...body, stream: true }),
|
|
108
183
|
});
|
|
@@ -163,7 +238,18 @@ const fetchUserMessage = async ({ fullApplicationUrl, headers, body, stream, eve
|
|
|
163
238
|
eventListeners.interimMessage.forEach((listener) => {
|
|
164
239
|
listener(undefined);
|
|
165
240
|
});
|
|
166
|
-
return {
|
|
241
|
+
return {
|
|
242
|
+
...finalResponse,
|
|
243
|
+
messages: [
|
|
244
|
+
...messages,
|
|
245
|
+
...(finalResponse.messages ?? []).map((json) => ({
|
|
246
|
+
text: json.text,
|
|
247
|
+
choices: json.choices ?? [],
|
|
248
|
+
messageId: json.messageId,
|
|
249
|
+
metadata: json.metadata,
|
|
250
|
+
})),
|
|
251
|
+
],
|
|
252
|
+
};
|
|
167
253
|
};
|
|
168
254
|
if (stream) {
|
|
169
255
|
return await streamRequest(body);
|
|
@@ -175,7 +261,9 @@ const fetchUserMessage = async ({ fullApplicationUrl, headers, body, stream, eve
|
|
|
175
261
|
...(headers ?? {}),
|
|
176
262
|
Accept: "application/json",
|
|
177
263
|
"Content-Type": "application/json",
|
|
264
|
+
// Legacy header
|
|
178
265
|
"nlx-sdk-version": packageJson.version,
|
|
266
|
+
"nlx-core-version": packageJson.version,
|
|
179
267
|
},
|
|
180
268
|
body: JSON.stringify(body),
|
|
181
269
|
});
|
|
@@ -377,21 +465,6 @@ function createConversation(configuration) {
|
|
|
377
465
|
messageResponseHandler(safeJsonParse(e.data));
|
|
378
466
|
}
|
|
379
467
|
};
|
|
380
|
-
url.searchParams.set("voice-plus", "true");
|
|
381
|
-
voicePlusSocket = new ReconnectingWebSocket(url.href);
|
|
382
|
-
voicePlusSocketMessageQueueCheckInterval = setInterval(() => {
|
|
383
|
-
checkVoicePlusSocketQueue();
|
|
384
|
-
}, 500);
|
|
385
|
-
voicePlusSocket.onmessage = (e) => {
|
|
386
|
-
if (typeof e?.data === "string") {
|
|
387
|
-
const command = safeJsonParse(e.data);
|
|
388
|
-
if (command != null) {
|
|
389
|
-
eventListeners.voicePlusCommand.forEach((listener) => {
|
|
390
|
-
listener(command);
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
468
|
};
|
|
396
469
|
const setupCommandWebsocket = () => {
|
|
397
470
|
// If the socket is already set up, tear it down first
|
|
@@ -554,7 +627,9 @@ function createConversation(configuration) {
|
|
|
554
627
|
Accept: "application/json",
|
|
555
628
|
"Content-Type": "application/json",
|
|
556
629
|
"nlx-conversation-id": state.conversationId,
|
|
630
|
+
// Legacy header
|
|
557
631
|
"nlx-sdk-version": packageJson.version,
|
|
632
|
+
"nlx-core-version": packageJson.version,
|
|
558
633
|
},
|
|
559
634
|
body: JSON.stringify({
|
|
560
635
|
languageCode: state.languageCode,
|
|
@@ -652,7 +727,9 @@ function createConversation(configuration) {
|
|
|
652
727
|
Accept: "application/json",
|
|
653
728
|
"Content-Type": "application/json",
|
|
654
729
|
"nlx-conversation-id": state.conversationId,
|
|
730
|
+
// Legacy header
|
|
655
731
|
"nlx-sdk-version": packageJson.version,
|
|
732
|
+
"nlx-core-version": packageJson.version,
|
|
656
733
|
},
|
|
657
734
|
body: JSON.stringify({
|
|
658
735
|
languageCode: state.languageCode,
|
|
@@ -808,5 +885,71 @@ function promisify(fn, convo, timeout = 10000) {
|
|
|
808
885
|
});
|
|
809
886
|
};
|
|
810
887
|
}
|
|
888
|
+
/**
|
|
889
|
+
* Use this function when using **Voice+ scripts** to advance the conversation to the step specified.
|
|
890
|
+
*
|
|
891
|
+
* This functionality is orthogonal from other usage of the core SDK, as it may be used either using standard SDK communication channels or it can be used to provide a Voice+ script experience with for instance a telephony based channel.
|
|
892
|
+
* @example
|
|
893
|
+
* ```typescript
|
|
894
|
+
* import { sendVoicePlusStep } from "@nlxai/core";
|
|
895
|
+
*
|
|
896
|
+
* await sendVoicePlusStep({
|
|
897
|
+
* // hard-coded params
|
|
898
|
+
* apiKey: "REPLACE_WITH_API_KEY",
|
|
899
|
+
* workspaceId: "REPLACE_WITH_WORKSPACE_ID",
|
|
900
|
+
* scriptId: "REPLACE_WITH_SCRIPT_ID",
|
|
901
|
+
* step: "REPLACE_WITH_STEP_ID",
|
|
902
|
+
* // dynamic params
|
|
903
|
+
* conversationId: "REPLACE_WITH_CONVERSATION_ID",
|
|
904
|
+
* languageCode: "en-US",
|
|
905
|
+
* });
|
|
906
|
+
* ```
|
|
907
|
+
* @param configuration - Configuration for sending the step. Many of the values can be found on the deployment modal of the Voice+ script.
|
|
908
|
+
*/
|
|
909
|
+
const sendVoicePlusStep = async ({ apiKey, workspaceId, conversationId, scriptId, languageCode, step, context, debug = false, dev = false, }) => {
|
|
910
|
+
if (scriptId == null) {
|
|
911
|
+
throw new Error("Voice+ scriptId is not defined.");
|
|
912
|
+
}
|
|
913
|
+
if (typeof conversationId !== "string" || conversationId.length === 0) {
|
|
914
|
+
throw new Error("Voice+ conversationId is not defined.");
|
|
915
|
+
}
|
|
916
|
+
const [stepId, stepTriggerDescription] = typeof step === "string"
|
|
917
|
+
? [step, undefined]
|
|
918
|
+
: [step.stepId, step.stepTriggerDescription];
|
|
919
|
+
if (!stepIdRegex.test(stepId)) {
|
|
920
|
+
throw new Error("Invalid stepId. It should be formatted as a UUID.");
|
|
921
|
+
}
|
|
922
|
+
const payload = {
|
|
923
|
+
stepId,
|
|
924
|
+
context,
|
|
925
|
+
conversationId,
|
|
926
|
+
journeyId: scriptId,
|
|
927
|
+
languageCode,
|
|
928
|
+
stepTriggerDescription,
|
|
929
|
+
};
|
|
930
|
+
try {
|
|
931
|
+
await fetch(`https://${dev ? "dev." : ""}mm.nlx.ai/v1/track`, {
|
|
932
|
+
method: "POST",
|
|
933
|
+
headers: {
|
|
934
|
+
"x-api-key": apiKey,
|
|
935
|
+
"x-nlx-id": workspaceId,
|
|
936
|
+
"Content-Type": "application/json",
|
|
937
|
+
"nlx-sdk-version": packageJson.version,
|
|
938
|
+
"nlx-core-version": packageJson.version,
|
|
939
|
+
},
|
|
940
|
+
body: JSON.stringify(payload),
|
|
941
|
+
});
|
|
942
|
+
if (debug) {
|
|
943
|
+
Console.info(`✓ step: ${stepId}`, payload);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
catch (err) {
|
|
947
|
+
if (debug) {
|
|
948
|
+
Console.error(`× step: ${stepId}`, err, payload);
|
|
949
|
+
}
|
|
950
|
+
throw err;
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
const stepIdRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
811
954
|
|
|
812
|
-
export { ResponseType, createConversation, getCurrentExpirationTimestamp, isConfigValid, promisify, shouldReinitialize, version };
|
|
955
|
+
export { ResponseType, createConversation, getCurrentExpirationTimestamp, isConfigValid, promisify, sendVoicePlusStep, shouldReinitialize, version };
|
package/lib/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).nlx={})}(this,(function(e){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||"undefined"!=typeof global&&global||{},r="URLSearchParams"in n,o="Symbol"in n&&"iterator"in Symbol,s="FileReader"in n&&"Blob"in n&&function(){try{return new Blob,!0}catch(e){return!1}}(),i="FormData"in n,a="ArrayBuffer"in n;if(a)var c=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(e){return e&&c.indexOf(Object.prototype.toString.call(e))>-1};function l(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||""===e)throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function d(e){return"string"!=typeof e&&(e=String(e)),e}function f(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return o&&(t[Symbol.iterator]=function(){return t}),t}function p(e){this.map={},e instanceof p?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){if(2!=e.length)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+e.length);this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function h(e){if(!e._noBody)return e.bodyUsed?Promise.reject(new TypeError("Already read")):void(e.bodyUsed=!0)}function y(e){return new Promise((function(t,n){e.onload=function(){t(e.result)},e.onerror=function(){n(e.error)}}))}function m(e){var t=new FileReader,n=y(t);return t.readAsArrayBuffer(e),n}function g(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function b(){return this.bodyUsed=!1,this._initBody=function(e){var t;this.bodyUsed=this.bodyUsed,this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:s&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:i&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:r&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a&&s&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=g(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(e)||u(e))?this._bodyArrayBuffer=g(e):this._bodyText=e=Object.prototype.toString.call(e):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s&&(this.blob=function(){var e=h(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var e=h(this);return e||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}if(s)return this.blob().then(m);throw new Error("could not read as ArrayBuffer")},this.text=function(){var e,t,n,r,o,s=h(this);if(s)return s;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,n=y(t),r=/charset=([A-Za-z0-9_-]+)/.exec(e.type),o=r?r[1]:"utf-8",t.readAsText(e,o),n;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),n=new Array(t.length),r=0;r<t.length;r++)n[r]=String.fromCharCode(t[r]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(w)}),this.json=function(){return this.text().then(JSON.parse)},this}p.prototype.append=function(e,t){e=l(e),t=d(t);var n=this.map[e];this.map[e]=n?n+", "+t:t},p.prototype.delete=function(e){delete this.map[l(e)]},p.prototype.get=function(e){return e=l(e),this.has(e)?this.map[e]:null},p.prototype.has=function(e){return this.map.hasOwnProperty(l(e))},p.prototype.set=function(e,t){this.map[l(e)]=d(t)},p.prototype.forEach=function(e,t){for(var n in this.map)this.map.hasOwnProperty(n)&&e.call(t,this.map[n],n,this)},p.prototype.keys=function(){var e=[];return this.forEach((function(t,n){e.push(n)})),f(e)},p.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),f(e)},p.prototype.entries=function(){var e=[];return this.forEach((function(t,n){e.push([n,t])})),f(e)},o&&(p.prototype[Symbol.iterator]=p.prototype.entries);var v=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function _(e,t){if(!(this instanceof _))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var r,o,s=(t=t||{}).body;if(e instanceof _){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new p(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,s||null==e._bodyInit||(s=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new p(t.headers)),this.method=(r=t.method||this.method||"GET",o=r.toUpperCase(),v.indexOf(o)>-1?o:r),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal||function(){if("AbortController"in n)return(new AbortController).signal}(),this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&s)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(s),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==t.cache&&"no-cache"!==t.cache)){var i=/([?&])_=[^&]*/;if(i.test(this.url))this.url=this.url.replace(i,"$1_="+(new Date).getTime());else{this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}}function w(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var n=e.split("="),r=n.shift().replace(/\+/g," "),o=n.join("=").replace(/\+/g," ");t.append(decodeURIComponent(r),decodeURIComponent(o))}})),t}function T(e,t){if(!(this instanceof T))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=void 0===t.statusText?"":""+t.statusText,this.headers=new p(t.headers),this.url=t.url||"",this._initBody(e)}_.prototype.clone=function(){return new _(this,{body:this._bodyInit})},b.call(_.prototype),b.call(T.prototype),T.prototype.clone=function(){return new T(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new p(this.headers),url:this.url})},T.error=function(){var e=new T(null,{status:200,statusText:""});return e.ok=!1,e.status=0,e.type="error",e};var E=[301,302,303,307,308];T.redirect=function(e,t){if(-1===E.indexOf(t))throw new RangeError("Invalid status code");return new T(null,{status:t,headers:{location:e}})};var O=n.DOMException;try{new O}catch(e){(O=function(e,t){this.message=e,this.name=t;var n=Error(e);this.stack=n.stack}).prototype=Object.create(Error.prototype),O.prototype.constructor=O}function x(e,t){return new Promise((function(r,o){var i=new _(e,t);if(i.signal&&i.signal.aborted)return o(new O("Aborted","AbortError"));var c=new XMLHttpRequest;function u(){c.abort()}if(c.onload=function(){var e,t,n={statusText:c.statusText,headers:(e=c.getAllResponseHeaders()||"",t=new p,e.replace(/\r?\n[\t ]+/g," ").split("\r").map((function(e){return 0===e.indexOf("\n")?e.substr(1,e.length):e})).forEach((function(e){var n=e.split(":"),r=n.shift().trim();if(r){var o=n.join(":").trim();try{t.append(r,o)}catch(e){console.warn("Response "+e.message)}}})),t)};0===i.url.indexOf("file://")&&(c.status<200||c.status>599)?n.status=200:n.status=c.status,n.url="responseURL"in c?c.responseURL:n.headers.get("X-Request-URL");var o="response"in c?c.response:c.responseText;setTimeout((function(){r(new T(o,n))}),0)},c.onerror=function(){setTimeout((function(){o(new TypeError("Network request failed"))}),0)},c.ontimeout=function(){setTimeout((function(){o(new TypeError("Network request timed out"))}),0)},c.onabort=function(){setTimeout((function(){o(new O("Aborted","AbortError"))}),0)},c.open(i.method,function(e){try{return""===e&&n.location.href?n.location.href:e}catch(t){return e}}(i.url),!0),"include"===i.credentials?c.withCredentials=!0:"omit"===i.credentials&&(c.withCredentials=!1),"responseType"in c&&(s?c.responseType="blob":a&&(c.responseType="arraybuffer")),t&&"object"==typeof t.headers&&!(t.headers instanceof p||n.Headers&&t.headers instanceof n.Headers)){var f=[];Object.getOwnPropertyNames(t.headers).forEach((function(e){f.push(l(e)),c.setRequestHeader(e,d(t.headers[e]))})),i.headers.forEach((function(e,t){-1===f.indexOf(t)&&c.setRequestHeader(t,e)}))}else i.headers.forEach((function(e,t){c.setRequestHeader(t,e)}));i.signal&&(i.signal.addEventListener("abort",u),c.onreadystatechange=function(){4===c.readyState&&i.signal.removeEventListener("abort",u)}),c.send(void 0===i._bodyInit?null:i._bodyInit)}))}x.polyfill=!0,n.fetch||(n.fetch=x,n.Headers=p,n.Request=_,n.Response=T);var C=t(self.fetch.bind(self));function A(e){return null!=e&&"object"==typeof e&&!0===e["@@functional/placeholder"]}function I(e){return function t(n){return 0===arguments.length||A(n)?t:e.apply(this,arguments)}}function P(e){return function t(n,r){switch(arguments.length){case 0:return t;case 1:return A(n)?t:I((function(t){return e(n,t)}));default:return A(n)&&A(r)?t:A(n)?I((function(t){return e(t,r)})):A(r)?I((function(t){return e(n,t)})):e(n,r)}}}function S(e){return function t(n,r,o){switch(arguments.length){case 0:return t;case 1:return A(n)?t:P((function(t,r){return e(n,t,r)}));case 2:return A(n)&&A(r)?t:A(n)?P((function(t,n){return e(t,r,n)})):A(r)?P((function(t,r){return e(n,t,r)})):I((function(t){return e(n,r,t)}));default:return A(n)&&A(r)&&A(o)?t:A(n)&&A(r)?P((function(t,n){return e(t,n,o)})):A(n)&&A(o)?P((function(t,n){return e(t,r,n)})):A(r)&&A(o)?P((function(t,r){return e(n,t,r)})):A(n)?I((function(t){return e(t,r,o)})):A(r)?I((function(t){return e(n,t,o)})):A(o)?I((function(t){return e(n,r,t)})):e(n,r,o)}}}var R=S((function(e,t,n){var r=n.length;if(e>=r||e<-r)return n;var o=(r+e)%r,s=function(e,t){var n;t=t||[];var r=(e=e||[]).length,o=t.length,s=[];for(n=0;n<r;)s[s.length]=e[n],n+=1;for(n=0;n<o;)s[s.length]=t[n],n+=1;return s}(n);return s[o]=t(n[o]),s}));function U(e){for(var t,n=[];!(t=e.next()).done;)n.push(t.value);return n}function j(e,t,n){for(var r=0,o=n.length;r<o;){if(e(t,n[r]))return!0;r+=1}return!1}function L(e,t){return Object.prototype.hasOwnProperty.call(t,e)}var D="function"==typeof Object.is?Object.is:function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t},N=Object.prototype.toString,B=function(){return"[object Arguments]"===N.call(arguments)?function(e){return"[object Arguments]"===N.call(e)}:function(e){return L("callee",e)}}(),q=!{toString:null}.propertyIsEnumerable("toString"),k=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],F=function(){return arguments.propertyIsEnumerable("length")}(),$=function(e,t){for(var n=0;n<e.length;){if(e[n]===t)return!0;n+=1}return!1},M="function"!=typeof Object.keys||F?I((function(e){if(Object(e)!==e)return[];var t,n,r=[],o=F&&B(e);for(t in e)!L(t,e)||o&&"length"===t||(r[r.length]=t);if(q)for(n=k.length-1;n>=0;)L(t=k[n],e)&&!$(r,t)&&(r[r.length]=t),n-=1;return r})):I((function(e){return Object(e)!==e?[]:Object.keys(e)})),H=I((function(e){return null===e?"Null":void 0===e?"Undefined":Object.prototype.toString.call(e).slice(8,-1)}));function G(e,t,n,r){var o=U(e);function s(e,t){return W(e,t,n.slice(),r.slice())}return!j((function(e,t){return!j(s,t,e)}),U(t),o)}function W(e,t,n,r){if(D(e,t))return!0;var o,s,i=H(e);if(i!==H(t))return!1;if("function"==typeof e["fantasy-land/equals"]||"function"==typeof t["fantasy-land/equals"])return"function"==typeof e["fantasy-land/equals"]&&e["fantasy-land/equals"](t)&&"function"==typeof t["fantasy-land/equals"]&&t["fantasy-land/equals"](e);if("function"==typeof e.equals||"function"==typeof t.equals)return"function"==typeof e.equals&&e.equals(t)&&"function"==typeof t.equals&&t.equals(e);switch(i){case"Arguments":case"Array":case"Object":if("function"==typeof e.constructor&&"Promise"===(o=e.constructor,null==(s=String(o).match(/^function (\w*)/))?"":s[1]))return e===t;break;case"Boolean":case"Number":case"String":if(typeof e!=typeof t||!D(e.valueOf(),t.valueOf()))return!1;break;case"Date":if(!D(e.valueOf(),t.valueOf()))return!1;break;case"Error":return e.name===t.name&&e.message===t.message;case"RegExp":if(e.source!==t.source||e.global!==t.global||e.ignoreCase!==t.ignoreCase||e.multiline!==t.multiline||e.sticky!==t.sticky||e.unicode!==t.unicode)return!1}for(var a=n.length-1;a>=0;){if(n[a]===e)return r[a]===t;a-=1}switch(i){case"Map":return e.size===t.size&&G(e.entries(),t.entries(),n.concat([e]),r.concat([t]));case"Set":return e.size===t.size&&G(e.values(),t.values(),n.concat([e]),r.concat([t]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var c=M(e);if(c.length!==M(t).length)return!1;var u=n.concat([e]),l=r.concat([t]);for(a=c.length-1;a>=0;){var d=c[a];if(!L(d,t)||!W(t[d],e[d],u,l))return!1;a-=1}return!0}var K=P((function(e,t){return W(e,t,[],[])})),J=function(e,t){return J=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},J(e,t)};
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).nlx={})}(this,(function(e){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||"undefined"!=typeof global&&global||{},r="URLSearchParams"in n,o="Symbol"in n&&"iterator"in Symbol,s="FileReader"in n&&"Blob"in n&&function(){try{return new Blob,!0}catch(e){return!1}}(),i="FormData"in n,a="ArrayBuffer"in n;if(a)var c=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(e){return e&&c.indexOf(Object.prototype.toString.call(e))>-1};function l(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||""===e)throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function d(e){return"string"!=typeof e&&(e=String(e)),e}function p(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return o&&(t[Symbol.iterator]=function(){return t}),t}function f(e){this.map={},e instanceof f?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){if(2!=e.length)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+e.length);this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function h(e){if(!e._noBody)return e.bodyUsed?Promise.reject(new TypeError("Already read")):void(e.bodyUsed=!0)}function y(e){return new Promise((function(t,n){e.onload=function(){t(e.result)},e.onerror=function(){n(e.error)}}))}function g(e){var t=new FileReader,n=y(t);return t.readAsArrayBuffer(e),n}function m(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function b(){return this.bodyUsed=!1,this._initBody=function(e){var t;this.bodyUsed=this.bodyUsed,this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:s&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:i&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:r&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a&&s&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=m(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(e)||u(e))?this._bodyArrayBuffer=m(e):this._bodyText=e=Object.prototype.toString.call(e):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s&&(this.blob=function(){var e=h(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var e=h(this);return e||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}if(s)return this.blob().then(g);throw new Error("could not read as ArrayBuffer")},this.text=function(){var e,t,n,r,o,s=h(this);if(s)return s;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,n=y(t),r=/charset=([A-Za-z0-9_-]+)/.exec(e.type),o=r?r[1]:"utf-8",t.readAsText(e,o),n;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),n=new Array(t.length),r=0;r<t.length;r++)n[r]=String.fromCharCode(t[r]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(w)}),this.json=function(){return this.text().then(JSON.parse)},this}f.prototype.append=function(e,t){e=l(e),t=d(t);var n=this.map[e];this.map[e]=n?n+", "+t:t},f.prototype.delete=function(e){delete this.map[l(e)]},f.prototype.get=function(e){return e=l(e),this.has(e)?this.map[e]:null},f.prototype.has=function(e){return this.map.hasOwnProperty(l(e))},f.prototype.set=function(e,t){this.map[l(e)]=d(t)},f.prototype.forEach=function(e,t){for(var n in this.map)this.map.hasOwnProperty(n)&&e.call(t,this.map[n],n,this)},f.prototype.keys=function(){var e=[];return this.forEach((function(t,n){e.push(n)})),p(e)},f.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),p(e)},f.prototype.entries=function(){var e=[];return this.forEach((function(t,n){e.push([n,t])})),p(e)},o&&(f.prototype[Symbol.iterator]=f.prototype.entries);var v=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function _(e,t){if(!(this instanceof _))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var r,o,s=(t=t||{}).body;if(e instanceof _){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new f(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,s||null==e._bodyInit||(s=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new f(t.headers)),this.method=(r=t.method||this.method||"GET",o=r.toUpperCase(),v.indexOf(o)>-1?o:r),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal||function(){if("AbortController"in n)return(new AbortController).signal}(),this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&s)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(s),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==t.cache&&"no-cache"!==t.cache)){var i=/([?&])_=[^&]*/;if(i.test(this.url))this.url=this.url.replace(i,"$1_="+(new Date).getTime());else{this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}}function w(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var n=e.split("="),r=n.shift().replace(/\+/g," "),o=n.join("=").replace(/\+/g," ");t.append(decodeURIComponent(r),decodeURIComponent(o))}})),t}function T(e,t){if(!(this instanceof T))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=void 0===t.statusText?"":""+t.statusText,this.headers=new f(t.headers),this.url=t.url||"",this._initBody(e)}_.prototype.clone=function(){return new _(this,{body:this._bodyInit})},b.call(_.prototype),b.call(T.prototype),T.prototype.clone=function(){return new T(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},T.error=function(){var e=new T(null,{status:200,statusText:""});return e.ok=!1,e.status=0,e.type="error",e};var x=[301,302,303,307,308];T.redirect=function(e,t){if(-1===x.indexOf(t))throw new RangeError("Invalid status code");return new T(null,{status:t,headers:{location:e}})};var E=n.DOMException;try{new E}catch(e){E=function(e,t){this.message=e,this.name=t;var n=Error(e);this.stack=n.stack},E.prototype=Object.create(Error.prototype),E.prototype.constructor=E}function O(e,t){return new Promise((function(r,o){var i=new _(e,t);if(i.signal&&i.signal.aborted)return o(new E("Aborted","AbortError"));var c=new XMLHttpRequest;function u(){c.abort()}if(c.onload=function(){var e,t,n={statusText:c.statusText,headers:(e=c.getAllResponseHeaders()||"",t=new f,e.replace(/\r?\n[\t ]+/g," ").split("\r").map((function(e){return 0===e.indexOf("\n")?e.substr(1,e.length):e})).forEach((function(e){var n=e.split(":"),r=n.shift().trim();if(r){var o=n.join(":").trim();try{t.append(r,o)}catch(e){console.warn("Response "+e.message)}}})),t)};0===i.url.indexOf("file://")&&(c.status<200||c.status>599)?n.status=200:n.status=c.status,n.url="responseURL"in c?c.responseURL:n.headers.get("X-Request-URL");var o="response"in c?c.response:c.responseText;setTimeout((function(){r(new T(o,n))}),0)},c.onerror=function(){setTimeout((function(){o(new TypeError("Network request failed"))}),0)},c.ontimeout=function(){setTimeout((function(){o(new TypeError("Network request timed out"))}),0)},c.onabort=function(){setTimeout((function(){o(new E("Aborted","AbortError"))}),0)},c.open(i.method,function(e){try{return""===e&&n.location.href?n.location.href:e}catch(t){return e}}(i.url),!0),"include"===i.credentials?c.withCredentials=!0:"omit"===i.credentials&&(c.withCredentials=!1),"responseType"in c&&(s?c.responseType="blob":a&&(c.responseType="arraybuffer")),t&&"object"==typeof t.headers&&!(t.headers instanceof f||n.Headers&&t.headers instanceof n.Headers)){var p=[];Object.getOwnPropertyNames(t.headers).forEach((function(e){p.push(l(e)),c.setRequestHeader(e,d(t.headers[e]))})),i.headers.forEach((function(e,t){-1===p.indexOf(t)&&c.setRequestHeader(t,e)}))}else i.headers.forEach((function(e,t){c.setRequestHeader(t,e)}));i.signal&&(i.signal.addEventListener("abort",u),c.onreadystatechange=function(){4===c.readyState&&i.signal.removeEventListener("abort",u)}),c.send(void 0===i._bodyInit?null:i._bodyInit)}))}O.polyfill=!0,n.fetch||(n.fetch=O,n.Headers=f,n.Request=_,n.Response=T);var I=t(self.fetch.bind(self));function A(e){return null!=e&&"object"==typeof e&&!0===e["@@functional/placeholder"]}function C(e){return function t(n){return 0===arguments.length||A(n)?t:e.apply(this,arguments)}}function P(e){return function t(n,r){switch(arguments.length){case 0:return t;case 1:return A(n)?t:C((function(t){return e(n,t)}));default:return A(n)&&A(r)?t:A(n)?C((function(t){return e(t,r)})):A(r)?C((function(t){return e(n,t)})):e(n,r)}}}function S(e){return function t(n,r,o){switch(arguments.length){case 0:return t;case 1:return A(n)?t:P((function(t,r){return e(n,t,r)}));case 2:return A(n)&&A(r)?t:A(n)?P((function(t,n){return e(t,r,n)})):A(r)?P((function(t,r){return e(n,t,r)})):C((function(t){return e(n,r,t)}));default:return A(n)&&A(r)&&A(o)?t:A(n)&&A(r)?P((function(t,n){return e(t,n,o)})):A(n)&&A(o)?P((function(t,n){return e(t,r,n)})):A(r)&&A(o)?P((function(t,r){return e(n,t,r)})):A(n)?C((function(t){return e(t,r,o)})):A(r)?C((function(t){return e(n,t,o)})):A(o)?C((function(t){return e(n,r,t)})):e(n,r,o)}}}var R=S((function(e,t,n){var r=n.length;if(e>=r||e<-r)return n;var o=(r+e)%r,s=function(e,t){var n;t=t||[];var r=(e=e||[]).length,o=t.length,s=[];for(n=0;n<r;)s[s.length]=e[n],n+=1;for(n=0;n<o;)s[s.length]=t[n],n+=1;return s}(n);return s[o]=t(n[o]),s}));function U(e){for(var t,n=[];!(t=e.next()).done;)n.push(t.value);return n}function j(e,t,n){for(var r=0,o=n.length;r<o;){if(e(t,n[r]))return!0;r+=1}return!1}function L(e,t){return Object.prototype.hasOwnProperty.call(t,e)}var D="function"==typeof Object.is?Object.is:function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t},N=Object.prototype.toString,B=function(){return"[object Arguments]"===N.call(arguments)?function(e){return"[object Arguments]"===N.call(e)}:function(e){return L("callee",e)}}(),k=!{toString:null}.propertyIsEnumerable("toString"),q=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],F=function(){return arguments.propertyIsEnumerable("length")}(),$=function(e,t){for(var n=0;n<e.length;){if(e[n]===t)return!0;n+=1}return!1},M="function"!=typeof Object.keys||F?C((function(e){if(Object(e)!==e)return[];var t,n,r=[],o=F&&B(e);for(t in e)!L(t,e)||o&&"length"===t||(r[r.length]=t);if(k)for(n=q.length-1;n>=0;)L(t=q[n],e)&&!$(r,t)&&(r[r.length]=t),n-=1;return r})):C((function(e){return Object(e)!==e?[]:Object.keys(e)})),H=C((function(e){return null===e?"Null":void 0===e?"Undefined":Object.prototype.toString.call(e).slice(8,-1)}));function G(e,t,n,r){var o=U(e);function s(e,t){return W(e,t,n.slice(),r.slice())}return!j((function(e,t){return!j(s,t,e)}),U(t),o)}function W(e,t,n,r){if(D(e,t))return!0;var o,s,i=H(e);if(i!==H(t))return!1;if("function"==typeof e["fantasy-land/equals"]||"function"==typeof t["fantasy-land/equals"])return"function"==typeof e["fantasy-land/equals"]&&e["fantasy-land/equals"](t)&&"function"==typeof t["fantasy-land/equals"]&&t["fantasy-land/equals"](e);if("function"==typeof e.equals||"function"==typeof t.equals)return"function"==typeof e.equals&&e.equals(t)&&"function"==typeof t.equals&&t.equals(e);switch(i){case"Arguments":case"Array":case"Object":if("function"==typeof e.constructor&&"Promise"===(o=e.constructor,null==(s=String(o).match(/^function (\w*)/))?"":s[1]))return e===t;break;case"Boolean":case"Number":case"String":if(typeof e!=typeof t||!D(e.valueOf(),t.valueOf()))return!1;break;case"Date":if(!D(e.valueOf(),t.valueOf()))return!1;break;case"Error":return e.name===t.name&&e.message===t.message;case"RegExp":if(e.source!==t.source||e.global!==t.global||e.ignoreCase!==t.ignoreCase||e.multiline!==t.multiline||e.sticky!==t.sticky||e.unicode!==t.unicode)return!1}for(var a=n.length-1;a>=0;){if(n[a]===e)return r[a]===t;a-=1}switch(i){case"Map":return e.size===t.size&&G(e.entries(),t.entries(),n.concat([e]),r.concat([t]));case"Set":return e.size===t.size&&G(e.values(),t.values(),n.concat([e]),r.concat([t]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var c=M(e);if(c.length!==M(t).length)return!1;var u=n.concat([e]),l=r.concat([t]);for(a=c.length-1;a>=0;){var d=c[a];if(!L(d,t)||!W(t[d],e[d],u,l))return!1;a-=1}return!0}var K=P((function(e,t){return W(e,t,[],[])})),V=function(e,t){return V=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},V(e,t)};
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
|
|
13
13
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
14
|
and limitations under the License.
|
|
15
|
-
***************************************************************************** */function z(e,t){function n(){this.constructor=e}J(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function V(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,s=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=s.next()).done;)i.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=s.return)&&n.call(s)}finally{if(o)throw o.error}}return i}var Q=function(e,t){this.target=t,this.type=e},X=function(e){function t(t,n){var r=e.call(this,"error",n)||this;return r.message=t.message,r.error=t,r}return z(t,e),t}(Q),Z=function(e){function t(t,n,r){void 0===t&&(t=1e3),void 0===n&&(n="");var o=e.call(this,"close",r)||this;return o.wasClean=!0,o.code=t,o.reason=n,o}return z(t,e),t}(Q),Y=function(){if("undefined"!=typeof WebSocket)return WebSocket},ee={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+4e3*Math.random(),minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0},te=function(){function e(e,t,n){var r=this;void 0===n&&(n={}),this._listeners={error:[],message:[],open:[],close:[]},this._retryCount=-1,this._shouldReconnect=!0,this._connectLock=!1,this._binaryType="blob",this._closeCalled=!1,this._messageQueue=[],this.onclose=null,this.onerror=null,this.onmessage=null,this.onopen=null,this._handleOpen=function(e){r._debug("open event");var t=r._options.minUptime,n=void 0===t?ee.minUptime:t;clearTimeout(r._connectTimeout),r._uptimeTimeout=setTimeout((function(){return r._acceptOpen()}),n),r._ws.binaryType=r._binaryType,r._messageQueue.forEach((function(e){return r._ws.send(e)})),r._messageQueue=[],r.onopen&&r.onopen(e),r._listeners.open.forEach((function(t){return r._callEventListener(e,t)}))},this._handleMessage=function(e){r._debug("message event"),r.onmessage&&r.onmessage(e),r._listeners.message.forEach((function(t){return r._callEventListener(e,t)}))},this._handleError=function(e){r._debug("error event",e.message),r._disconnect(void 0,"TIMEOUT"===e.message?"timeout":void 0),r.onerror&&r.onerror(e),r._debug("exec error listeners"),r._listeners.error.forEach((function(t){return r._callEventListener(e,t)})),r._connect()},this._handleClose=function(e){r._debug("close event"),r._clearTimeouts(),r._shouldReconnect&&r._connect(),r.onclose&&r.onclose(e),r._listeners.close.forEach((function(t){return r._callEventListener(e,t)}))},this._url=e,this._protocols=t,this._options=n,this._options.startClosed&&(this._shouldReconnect=!1),this._connect()}return Object.defineProperty(e,"CONNECTING",{get:function(){return 0},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OPEN",{get:function(){return 1},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSING",{get:function(){return 2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSED",{get:function(){return 3},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CONNECTING",{get:function(){return e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"OPEN",{get:function(){return e.OPEN},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSING",{get:function(){return e.CLOSING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSED",{get:function(){return e.CLOSED},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"binaryType",{get:function(){return this._ws?this._ws.binaryType:this._binaryType},set:function(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"retryCount",{get:function(){return Math.max(this._retryCount,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bufferedAmount",{get:function(){return this._messageQueue.reduce((function(e,t){return"string"==typeof t?e+=t.length:t instanceof Blob?e+=t.size:e+=t.byteLength,e}),0)+(this._ws?this._ws.bufferedAmount:0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"extensions",{get:function(){return this._ws?this._ws.extensions:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"protocol",{get:function(){return this._ws?this._ws.protocol:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"readyState",{get:function(){return this._ws?this._ws.readyState:this._options.startClosed?e.CLOSED:e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"url",{get:function(){return this._ws?this._ws.url:""},enumerable:!0,configurable:!0}),e.prototype.close=function(e,t){void 0===e&&(e=1e3),this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),this._ws?this._ws.readyState!==this.CLOSED?this._ws.close(e,t):this._debug("close: already closed"):this._debug("close enqueued: no ws instance")},e.prototype.reconnect=function(e,t){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,this._ws&&this._ws.readyState!==this.CLOSED?(this._disconnect(e,t),this._connect()):this._connect()},e.prototype.send=function(e){if(this._ws&&this._ws.readyState===this.OPEN)this._debug("send",e),this._ws.send(e);else{var t=this._options.maxEnqueuedMessages,n=void 0===t?ee.maxEnqueuedMessages:t;this._messageQueue.length<n&&(this._debug("enqueue",e),this._messageQueue.push(e))}},e.prototype.addEventListener=function(e,t){this._listeners[e]&&this._listeners[e].push(t)},e.prototype.dispatchEvent=function(e){var t,n,r=this._listeners[e.type];if(r)try{for(var o=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}(r),s=o.next();!s.done;s=o.next()){var i=s.value;this._callEventListener(e,i)}}catch(e){t={error:e}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}return!0},e.prototype.removeEventListener=function(e,t){this._listeners[e]&&(this._listeners[e]=this._listeners[e].filter((function(e){return e!==t})))},e.prototype._debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._options.debug&&console.log.apply(console,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(V(arguments[t]));return e}(["RWS>"],e))},e.prototype._getNextDelay=function(){var e=this._options,t=e.reconnectionDelayGrowFactor,n=void 0===t?ee.reconnectionDelayGrowFactor:t,r=e.minReconnectionDelay,o=void 0===r?ee.minReconnectionDelay:r,s=e.maxReconnectionDelay,i=void 0===s?ee.maxReconnectionDelay:s,a=0;return this._retryCount>0&&(a=o*Math.pow(n,this._retryCount-1))>i&&(a=i),this._debug("next delay",a),a},e.prototype._wait=function(){var e=this;return new Promise((function(t){setTimeout(t,e._getNextDelay())}))},e.prototype._getNextUrl=function(e){if("string"==typeof e)return Promise.resolve(e);if("function"==typeof e){var t=e();if("string"==typeof t)return Promise.resolve(t);if(t.then)return t}throw Error("Invalid URL")},e.prototype._connect=function(){var e=this;if(!this._connectLock&&this._shouldReconnect){this._connectLock=!0;var t=this._options,n=t.maxRetries,r=void 0===n?ee.maxRetries:n,o=t.connectionTimeout,s=void 0===o?ee.connectionTimeout:o,i=t.WebSocket,a=void 0===i?Y():i;if(this._retryCount>=r)this._debug("max retries reached",this._retryCount,">=",r);else{if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),void 0===(c=a)||!c||2!==c.CLOSING)throw Error("No valid WebSocket class provided");var c;this._wait().then((function(){return e._getNextUrl(e._url)})).then((function(t){e._closeCalled||(e._debug("connect",{url:t,protocols:e._protocols}),e._ws=e._protocols?new a(t,e._protocols):new a(t),e._ws.binaryType=e._binaryType,e._connectLock=!1,e._addListeners(),e._connectTimeout=setTimeout((function(){return e._handleTimeout()}),s))}))}}},e.prototype._handleTimeout=function(){this._debug("timeout event"),this._handleError(new X(Error("TIMEOUT"),this))},e.prototype._disconnect=function(e,t){if(void 0===e&&(e=1e3),this._clearTimeouts(),this._ws){this._removeListeners();try{this._ws.close(e,t),this._handleClose(new Z(e,t,this))}catch(e){}}},e.prototype._acceptOpen=function(){this._debug("accept open"),this._retryCount=0},e.prototype._callEventListener=function(e,t){"handleEvent"in t?t.handleEvent(e):t(e)},e.prototype._removeListeners=function(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError))},e.prototype._addListeners=function(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))},e.prototype._clearTimeouts=function(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)},e}();let ne;const re=new Uint8Array(16);function oe(){if(!ne&&(ne="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ne))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ne(re)}const se=[];for(let e=0;e<256;++e)se.push((e+256).toString(16).slice(1));var ie={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ae(e,t,n){if(ie.randomUUID&&!e)return ie.randomUUID();const r=(e=e||{}).random||(e.rng||oe)();return r[6]=15&r[6]|64,r[8]=63&r[8]|128,function(e,t=0){return se[e[t+0]]+se[e[t+1]]+se[e[t+2]]+se[e[t+3]]+"-"+se[e[t+4]]+se[e[t+5]]+"-"+se[e[t+6]]+se[e[t+7]]+"-"+se[e[t+8]]+se[e[t+9]]+"-"+se[e[t+10]]+se[e[t+11]]+se[e[t+12]]+se[e[t+13]]+se[e[t+14]]+se[e[t+15]]}(r)}var ce="1.2.4-alpha.5";const ue=ce,le=console;var de;e.ResponseType=void 0,(de=e.ResponseType||(e.ResponseType={})).Application="bot",de.User="user",de.Failure="failure";const fe="NLX.Welcome",pe=e=>Array.isArray(e)?e:Object.entries(e).map((([e,t])=>({slotId:e,value:t}))),he=e=>({...e,intentId:e.flowId??e.intentId,slots:null!=e.slots?pe(e.slots):e.slots}),ye=e=>e.responses,me=e=>{try{return JSON.parse(e)}catch(e){return null}},ge=e=>e.match(/(bots\.dev\.studio\.nlx\.ai|bots\.studio\.nlx\.ai|apps\.nlx\.ai|dev\.apps\.nlx\.ai)/g)?.[0]??"apps.nlx.ai",be=e=>{if(!ve(e))return e;const t=ge(e),n=new URL(e),r=new URLSearchParams(n.search),o=r.get("channelKey");return`https://${t}/c/${r.get("deploymentKey")}/${o}`},ve=e=>0===e.indexOf("wss://"),_e=async({fullApplicationUrl:e,headers:t,body:n,stream:r,eventListeners:o})=>{if(r)return await(async n=>{const r=await C(e,{method:"POST",headers:{...t,"Content-Type":"application/json","nlx-sdk-version":ce},body:JSON.stringify({...n,stream:!0})});if(!r.ok||null==r.body)throw new Error(`HTTP Error: ${r.status}`);const s=r.body.getReader(),i=new TextDecoder;let a="";const c=[];let u={};for(;;){const{done:e,value:t}=await s.read();if(e)break;for(a+=i.decode(t,{stream:!0});;){const e=a.indexOf("{");if(-1===e)break;let t=!1;for(let n=0;n<a.length;n++)if("}"===a[n]){const r=a.substring(e,n+1);try{const e=JSON.parse(r);if("interim"===e.type){const t=e.text;"string"==typeof t&&o.interimMessage.forEach((e=>{e(t)}))}else"message"===e.type?c.push({text:e.text,choices:e.choices??[],messageId:e.messageId,metadata:e.metadata}):"final_response"===e.type&&(u=e.data);a=a.substring(n+1),t=!0;break}catch(e){}}if(!t)break}}return o.interimMessage.forEach((e=>{e(void 0)})),{...u,messages:c}})(n);{const r=await C(e,{method:"POST",headers:{...t??{},Accept:"application/json","Content-Type":"application/json","nlx-sdk-version":ce},body:JSON.stringify(n)});if(!r.ok||null==r.body)throw new Error(`HTTP Error: ${r.status}`);return await r.json()}};e.createConversation=function(t){let n,r,o=[],s=null,i=[],a=null;const c=t.applicationUrl??"";/[-|_][a-z]{2,}[-|_][A-Z]{2,}$/.test(c)&&le.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.");const u={voicePlusCommand:[],interimMessage:[]},l=t.conversationId??ae();let d={responses:t.responses??[],languageCode:t.languageCode,userId:t.userId,conversationId:l};const f=()=>`${be(c)}${!0===t.experimental?.completeApplicationUrl?"":`-${d.languageCode}`}`,p=(e,t)=>{d={...d,...e},v.forEach((e=>{e(ye(d),t)}))},h=()=>{const n={type:e.ResponseType.Failure,receivedAt:(new Date).getTime(),payload:{text:t.failureMessage??"We encountered an issue. Please try again soon."}};p({responses:[...d.responses,n]},n)},y=t=>{if(t?.messages.length>0){const n={type:e.ResponseType.Application,receivedAt:(new Date).getTime(),payload:{...t,messages:t.messages.map((e=>({nodeId:e.nodeId,messageId:e.messageId,text:e.text,choices:e.choices??[]})))}};p({responses:[...d.responses,n]},n),t.metadata.hasPendingDataRequest&&(x({poll:!0}),setTimeout((()=>{b({request:{structured:{poll:!0}}})}),1500))}else le.warn("Invalid message structure, expected object with field 'messages'."),h()};let m;const g=e=>{1===r?.readyState?r.send(JSON.stringify(e)):i=[...i,e]},b=async r=>{if(null!=m)return void m(r,(t=>{le.warn("Using the second argument in `setRequestOverride` is deprecated. Use `conversationHandler.appendMessageToTranscript` instead.");const n={type:e.ResponseType.Application,receivedAt:(new Date).getTime(),payload:t};p({responses:[...d.responses,n]},n)}));const s={userId:d.userId,conversationId:d.conversationId,...r,languageCode:d.languageCode,channelType:t.experimental?.channelType,environment:t.environment};if(ve(c))1===n?.readyState?n.send(JSON.stringify(s)):o=[...o,s];else try{const e=await _e({fullApplicationUrl:f(),headers:t.headers??{},stream:t.experimental?.streamHttp??!0,eventListeners:u,body:s});y(e)}catch(e){le.warn(e),h()}};let v=[];const _=()=>{1===r?.readyState&&null!=i[0]&&(g(i[0]),i=i.slice(1))},w=()=>{E();const e=new URL(c);!0!==t.experimental?.completeApplicationUrl&&(e.searchParams.set("languageCode",d.languageCode),e.searchParams.set("channelKey",`${e.searchParams.get("channelKey")??""}-${d.languageCode}`)),e.searchParams.set("conversationId",d.conversationId),n=new te(e.href),s=setInterval((()=>{(async()=>{1===n?.readyState&&null!=o[0]&&(await b(o[0]),o=o.slice(1))})()}),500),n.onmessage=function(e){"string"==typeof e?.data&&y(me(e.data))},e.searchParams.set("voice-plus","true"),r=new te(e.href),a=setInterval((()=>{_()}),500),r.onmessage=e=>{if("string"==typeof e?.data){const t=me(e.data);null!=t&&u.voicePlusCommand.forEach((e=>{e(t)}))}}},T=()=>{if(O(),!0!==t.bidirectional)return;const e=new URL((e=>{if(ve(e))return e;const t=ge(e),n=new URL(e).pathname.split("/");return`wss://us-east-1-ws.${t}?deploymentKey=${n[2]}&channelKey=${n[3]}`})(c));!0!==t.experimental?.completeApplicationUrl&&(e.searchParams.set("languageCode",d.languageCode),e.searchParams.set("channelKey",`${e.searchParams.get("channelKey")??""}-${d.languageCode}`)),e.searchParams.set("conversationId",d.conversationId),e.searchParams.set("type","voice-plus");const n=t.headers["nlx-api-key"];ve(c)||null==n||e.searchParams.set("apiKey",n),r=new te(e.href),a=setInterval((()=>{_()}),500),r.onmessage=e=>{if("string"==typeof e?.data){const t=me(e.data);null!=t&&u.voicePlusCommand.forEach((e=>{e(t)}))}}},E=()=>{null!=s&&clearInterval(s),null!=n&&(n.onmessage=null,n.close(),n=void 0)},O=()=>{null!=a&&clearInterval(a),null!=r&&(r.onmessage=null,r.close(),r=void 0)};ve(c)&&w(),T();const x=(t,n)=>{const r={type:e.ResponseType.User,receivedAt:(new Date).getTime(),payload:{type:"structured",...he(t),context:n}};p({responses:[...d.responses,r]},r)},A=(e,t)=>{x({intentId:e},t),b({context:t,request:{structured:{intentId:e}}})},I=e=>{v=v.filter((t=>t!==e))};return{sendText:(t,n)=>{const r={type:e.ResponseType.User,receivedAt:(new Date).getTime(),payload:{type:"text",text:t,context:n}};p({responses:[...d.responses,r]},r),b({context:n,request:{unstructured:{text:t}}})},sendContext:async e=>{const n=await C(`${f()}/context`,{method:"POST",headers:{...t.headers??{},Accept:"application/json","Content-Type":"application/json","nlx-conversation-id":d.conversationId,"nlx-sdk-version":ce},body:JSON.stringify({languageCode:d.languageCode,conversationId:d.conversationId,userId:d.userId,context:e})});if(n.status>=400)throw new Error(`Responded with ${n.status}`)},appendMessageToTranscript:e=>{const t={...e,receivedAt:e.receivedAt??(new Date).getTime()};p({responses:[...d.responses,t]},t)},sendStructured:(e,t)=>{x(e,t),b({context:t,request:{structured:he(e)}})},sendSlots:(e,t)=>{x({slots:e},t),b({context:t,request:{structured:{slots:pe(e)}}})},sendFlow:A,sendIntent:(e,t)=>{le.warn("Calling `sendIntent` is deprecated and will be removed in a future version of the SDK. Use `sendFlow` instead."),A(e,t)},sendWelcomeFlow:e=>{A(fe,e)},sendWelcomeIntent:e=>{le.warn("Calling `sendWelcomeIntent` is deprecated and will be removed in a future version of the SDK. Use `sendWelcomeFlow` instead."),A(fe,e)},sendChoice:(t,n,r)=>{let o=[...d.responses];const s={type:e.ResponseType.User,receivedAt:(new Date).getTime(),payload:{type:"choice",choiceId:t}},i=r?.responseIndex??-1,a=r?.messageIndex??-1;i>-1&&a>-1&&(o=R(i,(n=>n.type===e.ResponseType.Application?{...n,payload:{...n.payload,messages:R(a,(e=>({...e,selectedChoiceId:t})),n.payload.messages)}}:n),o)),o=[...o,s],p({responses:o},s),b({context:n,request:{structured:{nodeId:r?.nodeId,intentId:r?.intentId,choiceId:t}}})},submitFeedback:async(e,t)=>{const n=await C(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({languageCode:d.languageCode,conversationId:d.conversationId,userId:d.userId,...t})});if(n.status>=400)throw new Error(`Responded with ${n.status}`)},currentConversationId:()=>d.conversationId,setLanguageCode:e=>{e!==d.languageCode?(ve(c)&&w(),T(),p({languageCode:e})):le.warn("Attempted to set language code to the one already active.")},currentLanguageCode:()=>d.languageCode,getVoiceCredentials:async(e,n)=>{const r=be(c),o=await C(`${r}-${d.languageCode}/requestToken`,{method:"POST",headers:{...t.headers??{},Accept:"application/json","Content-Type":"application/json","nlx-conversation-id":d.conversationId,"nlx-sdk-version":ce},body:JSON.stringify({languageCode:d.languageCode,conversationId:d.conversationId,userId:d.userId,requestToken:!0,context:e,autoTriggerWelcomeFlow:n?.autoTriggerWelcomeFlow??!0})});if(o.status>=400)throw new Error(`Responded with ${o.status}`);const s=await o.json();if(null==s?.url)throw new Error("Invalid response");return s},subscribe:e=>(v=[...v,e],e(ye(d)),()=>{I(e)}),unsubscribe:I,unsubscribeAll:()=>{v=[]},reset:e=>{p({conversationId:ae(),responses:!0===e?.clearResponses?[]:d.responses}),ve(c)&&w(),T()},destroy:()=>{v=[],ve(c)&&E(),O()},setRequestOverride:e=>{m=e},addEventListener:(e,t)=>{u[e]=[...u[e],t]},removeEventListener:(e,t)=>{u[e]=u[e].filter((e=>e!==t))},sendVoicePlusContext:e=>{g({context:e})}}},e.getCurrentExpirationTimestamp=t=>{let n=null;return t.forEach((t=>{t.type===e.ResponseType.Application&&null!=t.payload.expirationTimestamp&&(n=t.payload.expirationTimestamp)})),n},e.isConfigValid=e=>(e.applicationUrl??"").length>0,e.promisify=function(t,n,r=1e4){return async o=>await new Promise(((s,i)=>{const a=setTimeout((()=>{i(new Error("The request timed out.")),n.unsubscribe(c)}),r),c=(t,r)=>{r?.type!==e.ResponseType.Application&&r?.type!==e.ResponseType.Failure||(clearTimeout(a),n.unsubscribe(c),s(r))};n.subscribe(c),t(o)}))},e.shouldReinitialize=(e,t)=>!K(e,t),e.version=ue}));
|
|
15
|
+
***************************************************************************** */function J(e,t){function n(){this.constructor=e}V(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function z(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,s=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=s.next()).done;)i.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=s.return)&&n.call(s)}finally{if(o)throw o.error}}return i}var Q=function(e,t){this.target=t,this.type=e},X=function(e){function t(t,n){var r=e.call(this,"error",n)||this;return r.message=t.message,r.error=t,r}return J(t,e),t}(Q),Z=function(e){function t(t,n,r){void 0===t&&(t=1e3),void 0===n&&(n="");var o=e.call(this,"close",r)||this;return o.wasClean=!0,o.code=t,o.reason=n,o}return J(t,e),t}(Q),Y=function(){if("undefined"!=typeof WebSocket)return WebSocket},ee={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+4e3*Math.random(),minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0},te=function(){function e(e,t,n){var r=this;void 0===n&&(n={}),this._listeners={error:[],message:[],open:[],close:[]},this._retryCount=-1,this._shouldReconnect=!0,this._connectLock=!1,this._binaryType="blob",this._closeCalled=!1,this._messageQueue=[],this.onclose=null,this.onerror=null,this.onmessage=null,this.onopen=null,this._handleOpen=function(e){r._debug("open event");var t=r._options.minUptime,n=void 0===t?ee.minUptime:t;clearTimeout(r._connectTimeout),r._uptimeTimeout=setTimeout((function(){return r._acceptOpen()}),n),r._ws.binaryType=r._binaryType,r._messageQueue.forEach((function(e){return r._ws.send(e)})),r._messageQueue=[],r.onopen&&r.onopen(e),r._listeners.open.forEach((function(t){return r._callEventListener(e,t)}))},this._handleMessage=function(e){r._debug("message event"),r.onmessage&&r.onmessage(e),r._listeners.message.forEach((function(t){return r._callEventListener(e,t)}))},this._handleError=function(e){r._debug("error event",e.message),r._disconnect(void 0,"TIMEOUT"===e.message?"timeout":void 0),r.onerror&&r.onerror(e),r._debug("exec error listeners"),r._listeners.error.forEach((function(t){return r._callEventListener(e,t)})),r._connect()},this._handleClose=function(e){r._debug("close event"),r._clearTimeouts(),r._shouldReconnect&&r._connect(),r.onclose&&r.onclose(e),r._listeners.close.forEach((function(t){return r._callEventListener(e,t)}))},this._url=e,this._protocols=t,this._options=n,this._options.startClosed&&(this._shouldReconnect=!1),this._connect()}return Object.defineProperty(e,"CONNECTING",{get:function(){return 0},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OPEN",{get:function(){return 1},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSING",{get:function(){return 2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSED",{get:function(){return 3},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CONNECTING",{get:function(){return e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"OPEN",{get:function(){return e.OPEN},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSING",{get:function(){return e.CLOSING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSED",{get:function(){return e.CLOSED},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"binaryType",{get:function(){return this._ws?this._ws.binaryType:this._binaryType},set:function(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"retryCount",{get:function(){return Math.max(this._retryCount,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bufferedAmount",{get:function(){return this._messageQueue.reduce((function(e,t){return"string"==typeof t?e+=t.length:t instanceof Blob?e+=t.size:e+=t.byteLength,e}),0)+(this._ws?this._ws.bufferedAmount:0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"extensions",{get:function(){return this._ws?this._ws.extensions:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"protocol",{get:function(){return this._ws?this._ws.protocol:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"readyState",{get:function(){return this._ws?this._ws.readyState:this._options.startClosed?e.CLOSED:e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"url",{get:function(){return this._ws?this._ws.url:""},enumerable:!0,configurable:!0}),e.prototype.close=function(e,t){void 0===e&&(e=1e3),this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),this._ws?this._ws.readyState!==this.CLOSED?this._ws.close(e,t):this._debug("close: already closed"):this._debug("close enqueued: no ws instance")},e.prototype.reconnect=function(e,t){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,this._ws&&this._ws.readyState!==this.CLOSED?(this._disconnect(e,t),this._connect()):this._connect()},e.prototype.send=function(e){if(this._ws&&this._ws.readyState===this.OPEN)this._debug("send",e),this._ws.send(e);else{var t=this._options.maxEnqueuedMessages,n=void 0===t?ee.maxEnqueuedMessages:t;this._messageQueue.length<n&&(this._debug("enqueue",e),this._messageQueue.push(e))}},e.prototype.addEventListener=function(e,t){this._listeners[e]&&this._listeners[e].push(t)},e.prototype.dispatchEvent=function(e){var t,n,r=this._listeners[e.type];if(r)try{for(var o=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}(r),s=o.next();!s.done;s=o.next()){var i=s.value;this._callEventListener(e,i)}}catch(e){t={error:e}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}return!0},e.prototype.removeEventListener=function(e,t){this._listeners[e]&&(this._listeners[e]=this._listeners[e].filter((function(e){return e!==t})))},e.prototype._debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._options.debug&&console.log.apply(console,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(z(arguments[t]));return e}(["RWS>"],e))},e.prototype._getNextDelay=function(){var e=this._options,t=e.reconnectionDelayGrowFactor,n=void 0===t?ee.reconnectionDelayGrowFactor:t,r=e.minReconnectionDelay,o=void 0===r?ee.minReconnectionDelay:r,s=e.maxReconnectionDelay,i=void 0===s?ee.maxReconnectionDelay:s,a=0;return this._retryCount>0&&(a=o*Math.pow(n,this._retryCount-1))>i&&(a=i),this._debug("next delay",a),a},e.prototype._wait=function(){var e=this;return new Promise((function(t){setTimeout(t,e._getNextDelay())}))},e.prototype._getNextUrl=function(e){if("string"==typeof e)return Promise.resolve(e);if("function"==typeof e){var t=e();if("string"==typeof t)return Promise.resolve(t);if(t.then)return t}throw Error("Invalid URL")},e.prototype._connect=function(){var e=this;if(!this._connectLock&&this._shouldReconnect){this._connectLock=!0;var t=this._options,n=t.maxRetries,r=void 0===n?ee.maxRetries:n,o=t.connectionTimeout,s=void 0===o?ee.connectionTimeout:o,i=t.WebSocket,a=void 0===i?Y():i;if(this._retryCount>=r)this._debug("max retries reached",this._retryCount,">=",r);else{if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),void 0===(c=a)||!c||2!==c.CLOSING)throw Error("No valid WebSocket class provided");var c;this._wait().then((function(){return e._getNextUrl(e._url)})).then((function(t){e._closeCalled||(e._debug("connect",{url:t,protocols:e._protocols}),e._ws=e._protocols?new a(t,e._protocols):new a(t),e._ws.binaryType=e._binaryType,e._connectLock=!1,e._addListeners(),e._connectTimeout=setTimeout((function(){return e._handleTimeout()}),s))}))}}},e.prototype._handleTimeout=function(){this._debug("timeout event"),this._handleError(new X(Error("TIMEOUT"),this))},e.prototype._disconnect=function(e,t){if(void 0===e&&(e=1e3),this._clearTimeouts(),this._ws){this._removeListeners();try{this._ws.close(e,t),this._handleClose(new Z(e,t,this))}catch(e){}}},e.prototype._acceptOpen=function(){this._debug("accept open"),this._retryCount=0},e.prototype._callEventListener=function(e,t){"handleEvent"in t?t.handleEvent(e):t(e)},e.prototype._removeListeners=function(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError))},e.prototype._addListeners=function(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))},e.prototype._clearTimeouts=function(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)},e}();let ne;const re=new Uint8Array(16);function oe(){if(!ne&&(ne="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ne))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ne(re)}const se=[];for(let e=0;e<256;++e)se.push((e+256).toString(16).slice(1));var ie={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ae(e,t,n){if(ie.randomUUID&&!e)return ie.randomUUID();const r=(e=e||{}).random||(e.rng||oe)();return r[6]=15&r[6]|64,r[8]=63&r[8]|128,function(e,t=0){return se[e[t+0]]+se[e[t+1]]+se[e[t+2]]+se[e[t+3]]+"-"+se[e[t+4]]+se[e[t+5]]+"-"+se[e[t+6]]+se[e[t+7]]+"-"+se[e[t+8]]+se[e[t+9]]+"-"+se[e[t+10]]+se[e[t+11]]+se[e[t+12]]+se[e[t+13]]+se[e[t+14]]+se[e[t+15]]}(r)}var ce="1.2.4-alpha.8";const ue=ce,le=console;var de;e.ResponseType=void 0,(de=e.ResponseType||(e.ResponseType={})).Application="bot",de.User="user",de.Failure="failure";const pe="NLX.Welcome",fe=e=>Array.isArray(e)?e:Object.entries(e).map((([e,t])=>({slotId:e,value:t}))),he=e=>({...e,intentId:e.flowId??e.intentId,slots:null!=e.slots?fe(e.slots):e.slots}),ye=e=>e.responses,ge=e=>{try{return JSON.parse(e)}catch(e){return null}},me=e=>e.match(/(bots\.dev\.studio\.nlx\.ai|bots\.studio\.nlx\.ai|apps\.nlx\.ai|dev\.apps\.nlx\.ai)/g)?.[0]??"apps.nlx.ai",be=e=>{if(!ve(e))return e;const t=me(e),n=new URL(e),r=new URLSearchParams(n.search),o=r.get("channelKey");return`https://${t}/c/${r.get("deploymentKey")}/${o}`},ve=e=>0===e.indexOf("wss://"),_e=async({fullApplicationUrl:e,headers:t,body:n,stream:r,eventListeners:o})=>{if(r)return await(async n=>{const r=await I(e,{method:"POST",headers:{...t,"Content-Type":"application/json","nlx-sdk-version":ce,"nlx-core-version":ce},body:JSON.stringify({...n,stream:!0})});if(!r.ok||null==r.body)throw new Error(`HTTP Error: ${r.status}`);const s=r.body.getReader(),i=new TextDecoder;let a="";const c=[];let u={};for(;;){const{done:e,value:t}=await s.read();if(e)break;for(a+=i.decode(t,{stream:!0});;){const e=a.indexOf("{");if(-1===e)break;let t=!1;for(let n=0;n<a.length;n++)if("}"===a[n]){const r=a.substring(e,n+1);try{const e=JSON.parse(r);if("interim"===e.type){const t=e.text;"string"==typeof t&&o.interimMessage.forEach((e=>{e(t)}))}else"message"===e.type?c.push({text:e.text,choices:e.choices??[],messageId:e.messageId,metadata:e.metadata}):"final_response"===e.type&&(u=e.data);a=a.substring(n+1),t=!0;break}catch(e){}}if(!t)break}}return o.interimMessage.forEach((e=>{e(void 0)})),{...u,messages:[...c,...(u.messages??[]).map((e=>({text:e.text,choices:e.choices??[],messageId:e.messageId,metadata:e.metadata})))]}})(n);{const r=await I(e,{method:"POST",headers:{...t??{},Accept:"application/json","Content-Type":"application/json","nlx-sdk-version":ce,"nlx-core-version":ce},body:JSON.stringify(n)});if(!r.ok||null==r.body)throw new Error(`HTTP Error: ${r.status}`);return await r.json()}};const we=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;e.createConversation=function(t){let n,r,o=[],s=null,i=[],a=null;const c=t.applicationUrl??"";/[-|_][a-z]{2,}[-|_][A-Z]{2,}$/.test(c)&&le.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.");const u={voicePlusCommand:[],interimMessage:[]},l=t.conversationId??ae();let d={responses:t.responses??[],languageCode:t.languageCode,userId:t.userId,conversationId:l};const p=()=>`${be(c)}${!0===t.experimental?.completeApplicationUrl?"":`-${d.languageCode}`}`,f=(e,t)=>{d={...d,...e},v.forEach((e=>{e(ye(d),t)}))},h=()=>{const n={type:e.ResponseType.Failure,receivedAt:(new Date).getTime(),payload:{text:t.failureMessage??"We encountered an issue. Please try again soon."}};f({responses:[...d.responses,n]},n)},y=t=>{if(t?.messages.length>0){const n={type:e.ResponseType.Application,receivedAt:(new Date).getTime(),payload:{...t,messages:t.messages.map((e=>({nodeId:e.nodeId,messageId:e.messageId,text:e.text,choices:e.choices??[]})))}};f({responses:[...d.responses,n]},n),t.metadata.hasPendingDataRequest&&(E({poll:!0}),setTimeout((()=>{b({request:{structured:{poll:!0}}})}),1500))}else le.warn("Invalid message structure, expected object with field 'messages'."),h()};let g;const m=e=>{1===r?.readyState?r.send(JSON.stringify(e)):i=[...i,e]},b=async r=>{if(null!=g)return void g(r,(t=>{le.warn("Using the second argument in `setRequestOverride` is deprecated. Use `conversationHandler.appendMessageToTranscript` instead.");const n={type:e.ResponseType.Application,receivedAt:(new Date).getTime(),payload:t};f({responses:[...d.responses,n]},n)}));const s={userId:d.userId,conversationId:d.conversationId,...r,languageCode:d.languageCode,channelType:t.experimental?.channelType,environment:t.environment};if(ve(c))1===n?.readyState?n.send(JSON.stringify(s)):o=[...o,s];else try{const e=await _e({fullApplicationUrl:p(),headers:t.headers??{},stream:t.experimental?.streamHttp??!0,eventListeners:u,body:s});y(e)}catch(e){le.warn(e),h()}};let v=[];const _=()=>{T();const e=new URL(c);!0!==t.experimental?.completeApplicationUrl&&(e.searchParams.set("languageCode",d.languageCode),e.searchParams.set("channelKey",`${e.searchParams.get("channelKey")??""}-${d.languageCode}`)),e.searchParams.set("conversationId",d.conversationId),n=new te(e.href),s=setInterval((()=>{(async()=>{1===n?.readyState&&null!=o[0]&&(await b(o[0]),o=o.slice(1))})()}),500),n.onmessage=function(e){"string"==typeof e?.data&&y(ge(e.data))}},w=()=>{if(x(),!0!==t.bidirectional)return;const e=new URL((e=>{if(ve(e))return e;const t=me(e),n=new URL(e).pathname.split("/");return`wss://us-east-1-ws.${t}?deploymentKey=${n[2]}&channelKey=${n[3]}`})(c));!0!==t.experimental?.completeApplicationUrl&&(e.searchParams.set("languageCode",d.languageCode),e.searchParams.set("channelKey",`${e.searchParams.get("channelKey")??""}-${d.languageCode}`)),e.searchParams.set("conversationId",d.conversationId),e.searchParams.set("type","voice-plus");const n=t.headers["nlx-api-key"];ve(c)||null==n||e.searchParams.set("apiKey",n),r=new te(e.href),a=setInterval((()=>{1===r?.readyState&&null!=i[0]&&(m(i[0]),i=i.slice(1))}),500),r.onmessage=e=>{if("string"==typeof e?.data){const t=ge(e.data);null!=t&&u.voicePlusCommand.forEach((e=>{e(t)}))}}},T=()=>{null!=s&&clearInterval(s),null!=n&&(n.onmessage=null,n.close(),n=void 0)},x=()=>{null!=a&&clearInterval(a),null!=r&&(r.onmessage=null,r.close(),r=void 0)};ve(c)&&_(),w();const E=(t,n)=>{const r={type:e.ResponseType.User,receivedAt:(new Date).getTime(),payload:{type:"structured",...he(t),context:n}};f({responses:[...d.responses,r]},r)},O=(e,t)=>{E({intentId:e},t),b({context:t,request:{structured:{intentId:e}}})},A=e=>{v=v.filter((t=>t!==e))};return{sendText:(t,n)=>{const r={type:e.ResponseType.User,receivedAt:(new Date).getTime(),payload:{type:"text",text:t,context:n}};f({responses:[...d.responses,r]},r),b({context:n,request:{unstructured:{text:t}}})},sendContext:async e=>{const n=await I(`${p()}/context`,{method:"POST",headers:{...t.headers??{},Accept:"application/json","Content-Type":"application/json","nlx-conversation-id":d.conversationId,"nlx-sdk-version":ce,"nlx-core-version":ce},body:JSON.stringify({languageCode:d.languageCode,conversationId:d.conversationId,userId:d.userId,context:e})});if(n.status>=400)throw new Error(`Responded with ${n.status}`)},appendMessageToTranscript:e=>{const t={...e,receivedAt:e.receivedAt??(new Date).getTime()};f({responses:[...d.responses,t]},t)},sendStructured:(e,t)=>{E(e,t),b({context:t,request:{structured:he(e)}})},sendSlots:(e,t)=>{E({slots:e},t),b({context:t,request:{structured:{slots:fe(e)}}})},sendFlow:O,sendIntent:(e,t)=>{le.warn("Calling `sendIntent` is deprecated and will be removed in a future version of the SDK. Use `sendFlow` instead."),O(e,t)},sendWelcomeFlow:e=>{O(pe,e)},sendWelcomeIntent:e=>{le.warn("Calling `sendWelcomeIntent` is deprecated and will be removed in a future version of the SDK. Use `sendWelcomeFlow` instead."),O(pe,e)},sendChoice:(t,n,r)=>{let o=[...d.responses];const s={type:e.ResponseType.User,receivedAt:(new Date).getTime(),payload:{type:"choice",choiceId:t}},i=r?.responseIndex??-1,a=r?.messageIndex??-1;i>-1&&a>-1&&(o=R(i,(n=>n.type===e.ResponseType.Application?{...n,payload:{...n.payload,messages:R(a,(e=>({...e,selectedChoiceId:t})),n.payload.messages)}}:n),o)),o=[...o,s],f({responses:o},s),b({context:n,request:{structured:{nodeId:r?.nodeId,intentId:r?.intentId,choiceId:t}}})},submitFeedback:async(e,t)=>{const n=await I(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({languageCode:d.languageCode,conversationId:d.conversationId,userId:d.userId,...t})});if(n.status>=400)throw new Error(`Responded with ${n.status}`)},currentConversationId:()=>d.conversationId,setLanguageCode:e=>{e!==d.languageCode?(ve(c)&&_(),w(),f({languageCode:e})):le.warn("Attempted to set language code to the one already active.")},currentLanguageCode:()=>d.languageCode,getVoiceCredentials:async(e,n)=>{const r=be(c),o=await I(`${r}-${d.languageCode}/requestToken`,{method:"POST",headers:{...t.headers??{},Accept:"application/json","Content-Type":"application/json","nlx-conversation-id":d.conversationId,"nlx-sdk-version":ce,"nlx-core-version":ce},body:JSON.stringify({languageCode:d.languageCode,conversationId:d.conversationId,userId:d.userId,requestToken:!0,context:e,autoTriggerWelcomeFlow:n?.autoTriggerWelcomeFlow??!0})});if(o.status>=400)throw new Error(`Responded with ${o.status}`);const s=await o.json();if(null==s?.url)throw new Error("Invalid response");return s},subscribe:e=>(v=[...v,e],e(ye(d)),()=>{A(e)}),unsubscribe:A,unsubscribeAll:()=>{v=[]},reset:e=>{f({conversationId:ae(),responses:!0===e?.clearResponses?[]:d.responses}),ve(c)&&_(),w()},destroy:()=>{v=[],ve(c)&&T(),x()},setRequestOverride:e=>{g=e},addEventListener:(e,t)=>{u[e]=[...u[e],t]},removeEventListener:(e,t)=>{u[e]=u[e].filter((e=>e!==t))},sendVoicePlusContext:e=>{m({context:e})}}},e.getCurrentExpirationTimestamp=t=>{let n=null;return t.forEach((t=>{t.type===e.ResponseType.Application&&null!=t.payload.expirationTimestamp&&(n=t.payload.expirationTimestamp)})),n},e.isConfigValid=e=>(e.applicationUrl??"").length>0,e.promisify=function(t,n,r=1e4){return async o=>await new Promise(((s,i)=>{const a=setTimeout((()=>{i(new Error("The request timed out.")),n.unsubscribe(c)}),r),c=(t,r)=>{r?.type!==e.ResponseType.Application&&r?.type!==e.ResponseType.Failure||(clearTimeout(a),n.unsubscribe(c),s(r))};n.subscribe(c),t(o)}))},e.sendVoicePlusStep=async({apiKey:e,workspaceId:t,conversationId:n,scriptId:r,languageCode:o,step:s,context:i,debug:a=!1,dev:c=!1})=>{if(null==r)throw new Error("Voice+ scriptId is not defined.");if("string"!=typeof n||0===n.length)throw new Error("Voice+ conversationId is not defined.");const[u,l]="string"==typeof s?[s,void 0]:[s.stepId,s.stepTriggerDescription];if(!we.test(u))throw new Error("Invalid stepId. It should be formatted as a UUID.");const d={stepId:u,context:i,conversationId:n,journeyId:r,languageCode:o,stepTriggerDescription:l};try{await I(`https://${c?"dev.":""}mm.nlx.ai/v1/track`,{method:"POST",headers:{"x-api-key":e,"x-nlx-id":t,"Content-Type":"application/json","nlx-sdk-version":ce,"nlx-core-version":ce},body:JSON.stringify(d)}),a&&le.info(`✓ step: ${u}`,d)}catch(e){throw a&&le.error(`× step: ${u}`,e,d),e}},e.shouldReinitialize=(e,t)=>!K(e,t),e.version=ue}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nlxai/core",
|
|
3
|
-
"version": "1.2.4-alpha.
|
|
3
|
+
"version": "1.2.4-alpha.8",
|
|
4
4
|
"description": "Low-level SDK for building NLX experiences",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
@@ -28,14 +28,21 @@
|
|
|
28
28
|
"author": "Peter Szerzo <peter@nlx.ai>",
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"devDependencies": {
|
|
31
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
32
|
+
"@rollup/plugin-json": "^6.0.1",
|
|
33
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
34
|
+
"@rollup/plugin-replace": "^5.0.5",
|
|
35
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
36
|
+
"@rollup/plugin-typescript": "^11.1.5",
|
|
31
37
|
"@types/isomorphic-fetch": "^0.0.39",
|
|
32
38
|
"@types/node": "^24.10.1",
|
|
33
39
|
"@types/ramda": "0.31.1",
|
|
34
40
|
"@types/uuid": "^9.0.7",
|
|
35
|
-
"concat-md": "^0.5.1",
|
|
36
41
|
"eslint-config-nlx": "*",
|
|
37
42
|
"prettier": "^3.1.0",
|
|
43
|
+
"rollup": "^4.3.0",
|
|
38
44
|
"rollup-config-nlx": "*",
|
|
45
|
+
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
39
46
|
"typedoc": "^0.28.14",
|
|
40
47
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
41
48
|
"typescript": "^5.5.4"
|
|
@@ -49,5 +56,5 @@
|
|
|
49
56
|
"publishConfig": {
|
|
50
57
|
"access": "public"
|
|
51
58
|
},
|
|
52
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "42d1a368a8d42b34b1a4782c477f6bca3f660e4c"
|
|
53
60
|
}
|