@botonic/plugin-flow-builder 0.26.1 → 0.27.0-alpha.0
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/lib/cjs/action/index.js +39 -19
- package/lib/cjs/action/index.js.map +1 -1
- package/lib/cjs/action/knowledge-bases.js +14 -4
- package/lib/cjs/action/knowledge-bases.js.map +1 -1
- package/lib/cjs/api.d.ts +4 -6
- package/lib/cjs/api.js +7 -33
- package/lib/cjs/api.js.map +1 -1
- package/lib/cjs/constants.d.ts +1 -0
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/content-fields/flow-button.d.ts +0 -1
- package/lib/cjs/content-fields/flow-button.js +0 -10
- package/lib/cjs/content-fields/flow-button.js.map +1 -1
- package/lib/cjs/content-fields/flow-handoff.js +7 -19
- package/lib/cjs/content-fields/flow-handoff.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/button.d.ts +1 -2
- package/lib/cjs/content-fields/index.d.ts +1 -0
- package/lib/cjs/content-fields/index.js +3 -1
- package/lib/cjs/content-fields/index.js.map +1 -1
- package/lib/cjs/functions/conditional-queue-status.d.ts +7 -1
- package/lib/cjs/functions/conditional-queue-status.js +34 -12
- package/lib/cjs/functions/conditional-queue-status.js.map +1 -1
- package/lib/cjs/index.d.ts +7 -1
- package/lib/cjs/index.js +29 -6
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/tracking.d.ts +18 -14
- package/lib/cjs/tracking.js +27 -20
- package/lib/cjs/tracking.js.map +1 -1
- package/lib/cjs/types.d.ts +14 -1
- package/lib/cjs/types.js.map +1 -1
- package/lib/cjs/user-input/index.d.ts +2 -1
- package/lib/cjs/user-input/index.js +9 -3
- package/lib/cjs/user-input/index.js.map +1 -1
- package/lib/cjs/user-input/intent.js +12 -8
- package/lib/cjs/user-input/intent.js.map +1 -1
- package/lib/cjs/user-input/keyword.d.ts +21 -1
- package/lib/cjs/user-input/keyword.js +68 -13
- package/lib/cjs/user-input/keyword.js.map +1 -1
- package/lib/cjs/user-input/smart-intent.d.ts +18 -1
- package/lib/cjs/user-input/smart-intent.js +46 -29
- package/lib/cjs/user-input/smart-intent.js.map +1 -1
- package/lib/esm/action/index.js +39 -19
- package/lib/esm/action/index.js.map +1 -1
- package/lib/esm/action/knowledge-bases.js +15 -5
- package/lib/esm/action/knowledge-bases.js.map +1 -1
- package/lib/esm/api.d.ts +4 -6
- package/lib/esm/api.js +8 -34
- package/lib/esm/api.js.map +1 -1
- package/lib/esm/constants.d.ts +1 -0
- package/lib/esm/constants.js +1 -0
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/content-fields/flow-button.d.ts +0 -1
- package/lib/esm/content-fields/flow-button.js +0 -10
- package/lib/esm/content-fields/flow-button.js.map +1 -1
- package/lib/esm/content-fields/flow-handoff.js +7 -19
- package/lib/esm/content-fields/flow-handoff.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/button.d.ts +1 -2
- package/lib/esm/content-fields/index.d.ts +1 -0
- package/lib/esm/content-fields/index.js +1 -0
- package/lib/esm/content-fields/index.js.map +1 -1
- package/lib/esm/functions/conditional-queue-status.d.ts +7 -1
- package/lib/esm/functions/conditional-queue-status.js +32 -11
- package/lib/esm/functions/conditional-queue-status.js.map +1 -1
- package/lib/esm/index.d.ts +7 -1
- package/lib/esm/index.js +30 -7
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/tracking.d.ts +18 -14
- package/lib/esm/tracking.js +25 -19
- package/lib/esm/tracking.js.map +1 -1
- package/lib/esm/types.d.ts +14 -1
- package/lib/esm/types.js.map +1 -1
- package/lib/esm/user-input/index.d.ts +2 -1
- package/lib/esm/user-input/index.js +11 -5
- package/lib/esm/user-input/index.js.map +1 -1
- package/lib/esm/user-input/intent.js +13 -9
- package/lib/esm/user-input/intent.js.map +1 -1
- package/lib/esm/user-input/keyword.d.ts +21 -1
- package/lib/esm/user-input/keyword.js +67 -12
- package/lib/esm/user-input/keyword.js.map +1 -1
- package/lib/esm/user-input/smart-intent.d.ts +18 -1
- package/lib/esm/user-input/smart-intent.js +44 -27
- package/lib/esm/user-input/smart-intent.js.map +1 -1
- package/package.json +3 -3
- package/src/action/index.tsx +58 -24
- package/src/action/knowledge-bases.ts +16 -5
- package/src/api.ts +12 -55
- package/src/constants.ts +1 -0
- package/src/content-fields/flow-button.tsx +0 -10
- package/src/content-fields/flow-handoff.tsx +8 -28
- package/src/content-fields/hubtype-fields/button.ts +1 -7
- package/src/content-fields/index.ts +1 -0
- package/src/functions/conditional-queue-status.ts +36 -13
- package/src/index.ts +48 -7
- package/src/tracking.ts +25 -14
- package/src/types.ts +13 -1
- package/src/user-input/index.ts +13 -7
- package/src/user-input/intent.ts +17 -10
- package/src/user-input/keyword.ts +93 -14
- package/src/user-input/smart-intent.ts +57 -30
package/lib/cjs/index.js
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FlowBuilderJSONVersion = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const uuid_1 = require("uuid");
|
|
5
6
|
const api_1 = require("./api");
|
|
6
7
|
const constants_1 = require("./constants");
|
|
7
8
|
const content_fields_1 = require("./content-fields");
|
|
8
9
|
const flow_whatsapp_cta_url_button_1 = require("./content-fields/flow-whatsapp-cta-url-button");
|
|
9
10
|
const hubtype_fields_1 = require("./content-fields/hubtype-fields");
|
|
10
11
|
const functions_1 = require("./functions");
|
|
12
|
+
const tracking_1 = require("./tracking");
|
|
11
13
|
const types_1 = require("./types");
|
|
12
14
|
const user_input_1 = require("./user-input");
|
|
13
15
|
const utils_1 = require("./utils");
|
|
@@ -22,11 +24,11 @@ class BotonicPluginFlowBuilder {
|
|
|
22
24
|
this.getAccessToken = (0, utils_1.resolveGetAccessToken)(options);
|
|
23
25
|
this.trackEvent = options.trackEvent;
|
|
24
26
|
this.getKnowledgeBaseResponse = options.getKnowledgeBaseResponse;
|
|
27
|
+
this.smartIntentsConfig = Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.smartIntentsConfig), { useLatest: jsonVersion === types_1.FlowBuilderJSONVersion.LATEST });
|
|
25
28
|
const customFunctions = options.customFunctions || {};
|
|
26
29
|
this.functions = Object.assign(Object.assign({}, functions_1.DEFAULT_FUNCTIONS), customFunctions);
|
|
27
30
|
}
|
|
28
31
|
pre(request) {
|
|
29
|
-
var _a;
|
|
30
32
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
31
33
|
this.currentRequest = request;
|
|
32
34
|
this.cmsApi = yield api_1.FlowBuilderApi.create({
|
|
@@ -41,14 +43,28 @@ class BotonicPluginFlowBuilder {
|
|
|
41
43
|
if (checkUserTextInput) {
|
|
42
44
|
const locale = this.getLocale(request.session);
|
|
43
45
|
const resolvedLocale = this.cmsApi.getResolvedLocale(locale);
|
|
44
|
-
const nodeByUserInput = yield (0, user_input_1.getNodeByUserInput)(this.cmsApi, resolvedLocale, request);
|
|
46
|
+
const nodeByUserInput = yield (0, user_input_1.getNodeByUserInput)(this.cmsApi, resolvedLocale, request, this.smartIntentsConfig);
|
|
45
47
|
request.input.payload = this.cmsApi.getPayload(nodeByUserInput === null || nodeByUserInput === void 0 ? void 0 : nodeByUserInput.target);
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
request.input.payload = (_a = request.input.payload) === null || _a === void 0 ? void 0 : _a.split(constants_1.SOURCE_INFO_SEPARATOR)[0];
|
|
49
|
-
}
|
|
49
|
+
this.updateRequestBeforeRoutes(request);
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
+
updateRequestBeforeRoutes(request) {
|
|
53
|
+
if (request.input.payload) {
|
|
54
|
+
request.input.payload = this.removeSourceSufix(request.input.payload);
|
|
55
|
+
if (request.input.payload.startsWith(constants_1.BOT_ACTION_PAYLOAD_PREFIX)) {
|
|
56
|
+
request.input.payload = this.replacePayload(request.input.payload);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
removeSourceSufix(payload) {
|
|
61
|
+
return payload.split(constants_1.SOURCE_INFO_SEPARATOR)[0];
|
|
62
|
+
}
|
|
63
|
+
replacePayload(payload) {
|
|
64
|
+
const botActionId = payload.split(constants_1.SEPARATOR)[1];
|
|
65
|
+
const botActionNode = this.cmsApi.getNodeById(botActionId);
|
|
66
|
+
return this.cmsApi.createPayloadWithParams(botActionNode);
|
|
67
|
+
}
|
|
52
68
|
getContentsByContentID(contentID, locale, prevContents) {
|
|
53
69
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
54
70
|
const node = this.cmsApi.getNodeByContentID(contentID);
|
|
@@ -67,8 +83,12 @@ class BotonicPluginFlowBuilder {
|
|
|
67
83
|
}
|
|
68
84
|
getStartContents(locale) {
|
|
69
85
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const resolvedLocale = this.cmsApi.getResolvedLocale(locale);
|
|
70
87
|
const startNode = this.cmsApi.getStartNode();
|
|
71
|
-
|
|
88
|
+
this.currentRequest.session.flow_thread_id = (0, uuid_1.v4)();
|
|
89
|
+
const eventArgs = (0, tracking_1.getNodeEventArgs)(this.currentRequest, startNode);
|
|
90
|
+
yield (0, tracking_1.trackEvent)(this.currentRequest, tracking_1.EventAction.flowNode, eventArgs);
|
|
91
|
+
return yield this.getContentsByNode(startNode, resolvedLocale);
|
|
72
92
|
});
|
|
73
93
|
}
|
|
74
94
|
getContentsByNode(node, locale, prevContents) {
|
|
@@ -146,6 +166,9 @@ class BotonicPluginFlowBuilder {
|
|
|
146
166
|
const payloadParams = JSON.parse(payload.split(constants_1.SEPARATOR)[1] || '{}');
|
|
147
167
|
return payloadParams;
|
|
148
168
|
}
|
|
169
|
+
getFlowName(flowId) {
|
|
170
|
+
return this.cmsApi.getFlowName(flowId);
|
|
171
|
+
}
|
|
149
172
|
}
|
|
150
173
|
exports.default = BotonicPluginFlowBuilder;
|
|
151
174
|
tslib_1.__exportStar(require("./action"), exports);
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAEA,+BAAiC;AAEjC,+BAAsC;AACtC,2CAKoB;AACpB,qDAQyB;AACzB,gGAA4F;AAC5F,oEASwC;AACxC,2CAA+C;AAC/C,yCAAsE;AACtE,mCAKgB;AAChB,6CAAiD;AAEjD,mCAA+C;AAC/C,MAAqB,wBAAwB;IAkB3C,YAAqB,OAAwC;QAAxC,YAAO,GAAP,OAAO,CAAiC;QAC3D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,qCAAyB,CAAA;QAC1D,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,8BAAsB,CAAC,MAAM,CAAA;QACxE,IAAI,CAAC,OAAO,GAAG,GAAG,MAAM,SAAS,WAAW,EAAE,CAAA;QAC9C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,IAAI,CAAC,cAAc,GAAG,IAAA,6BAAqB,EAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAA;QACpC,IAAI,CAAC,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,CAAA;QAChE,IAAI,CAAC,kBAAkB,mCAClB,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,kBAAkB,KAC9B,SAAS,EAAE,WAAW,KAAK,8BAAsB,CAAC,MAAM,GACzD,CAAA;QACD,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,EAAE,CAAA;QACrD,IAAI,CAAC,SAAS,mCAAQ,6BAAiB,GAAK,eAAe,CAAE,CAAA;IAC/D,CAAC;IAEK,G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AAA;aAC5C;SACF;QAED,OAAO,eAAe,CAAA;IACxB,CAAC;IAED,gBAAgB,CAA8B,OAAe;QAC3D,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,qBAAS,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAA;QACrE,OAAO,aAAa,CAAA;IACtB,CAAC;IAED,WAAW,CAAC,MAAc;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IACxC,CAAC;CACF;AAhPD,2CAgPC;AAED,mDAAwB;AACxB,2DAAgC;AAChC,iCAIgB;AAFd,+GAAA,sBAAsB,OAAA;AAGxB,oDAAyB"}
|
package/lib/cjs/tracking.d.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { ActionRequest } from '@botonic/react';
|
|
2
|
-
|
|
3
|
-
export declare
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
fallback = "fallback",
|
|
2
|
+
import { HtNodeWithContent } from './content-fields/hubtype-fields';
|
|
3
|
+
export declare function trackEvent(request: ActionRequest, eventAction: EventAction, args?: Record<string, any>): Promise<void>;
|
|
4
|
+
export declare function getNodeEventArgs(request: ActionRequest, node: HtNodeWithContent): {
|
|
5
|
+
flowThreadId: string | undefined;
|
|
6
|
+
flowId: string;
|
|
7
|
+
flowName: string;
|
|
8
|
+
flowNodeId: string;
|
|
9
|
+
flowNodeContentId: string;
|
|
10
|
+
flowNodeIsMeaningful: undefined;
|
|
11
|
+
};
|
|
12
|
+
export declare enum EventAction {
|
|
13
|
+
flowNode = "flow_node",
|
|
15
14
|
handoffOption = "handoff_option",
|
|
16
15
|
handoffSuccess = "handoff_success",
|
|
17
|
-
handoffFail = "handoff_fail"
|
|
16
|
+
handoffFail = "handoff_fail",
|
|
17
|
+
keyword = "nlu_keyword",
|
|
18
|
+
intent = "nlu_intent",
|
|
19
|
+
intentSmart = "nlu_intent_smart",
|
|
20
|
+
knowledgebase = "knowledgebase",
|
|
21
|
+
fallback = "fallback"
|
|
18
22
|
}
|
package/lib/cjs/tracking.js
CHANGED
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.EventAction = exports.getNodeEventArgs = exports.trackEvent = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const helpers_1 = require("./helpers");
|
|
6
|
-
function trackEvent(request,
|
|
6
|
+
function trackEvent(request, eventAction, args) {
|
|
7
7
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
8
8
|
const flowBuilderPlugin = (0, helpers_1.getFlowBuilderPlugin)(request.plugins);
|
|
9
9
|
if (flowBuilderPlugin.trackEvent) {
|
|
10
|
-
yield flowBuilderPlugin.trackEvent(request,
|
|
10
|
+
yield flowBuilderPlugin.trackEvent(request, eventAction, args);
|
|
11
11
|
}
|
|
12
12
|
return;
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
exports.trackEvent = trackEvent;
|
|
16
|
-
|
|
17
|
-
(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
function getNodeEventArgs(request, node) {
|
|
17
|
+
const flowBuilderPlugin = (0, helpers_1.getFlowBuilderPlugin)(request.plugins);
|
|
18
|
+
return {
|
|
19
|
+
flowThreadId: request.session.flow_thread_id,
|
|
20
|
+
flowId: node.flow_id,
|
|
21
|
+
flowName: flowBuilderPlugin.getFlowName(node.flow_id),
|
|
22
|
+
flowNodeId: node.id,
|
|
23
|
+
flowNodeContentId: node.code,
|
|
24
|
+
flowNodeIsMeaningful: undefined, //node?.isMeaningful,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.getNodeEventArgs = getNodeEventArgs;
|
|
28
|
+
var EventAction;
|
|
29
|
+
(function (EventAction) {
|
|
30
|
+
EventAction["flowNode"] = "flow_node";
|
|
31
|
+
EventAction["handoffOption"] = "handoff_option";
|
|
32
|
+
EventAction["handoffSuccess"] = "handoff_success";
|
|
33
|
+
EventAction["handoffFail"] = "handoff_fail";
|
|
34
|
+
EventAction["keyword"] = "nlu_keyword";
|
|
35
|
+
EventAction["intent"] = "nlu_intent";
|
|
36
|
+
EventAction["intentSmart"] = "nlu_intent_smart";
|
|
37
|
+
EventAction["knowledgebase"] = "knowledgebase";
|
|
38
|
+
EventAction["fallback"] = "fallback";
|
|
39
|
+
})(EventAction = exports.EventAction || (exports.EventAction = {}));
|
|
33
40
|
//# sourceMappingURL=tracking.js.map
|
package/lib/cjs/tracking.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracking.js","sourceRoot":"","sources":["../../src/tracking.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"tracking.js","sourceRoot":"","sources":["../../src/tracking.ts"],"names":[],"mappings":";;;;AAGA,uCAAgD;AAEhD,SAAsB,UAAU,CAC9B,OAAsB,EACtB,WAAwB,EACxB,IAA0B;;QAE1B,MAAM,iBAAiB,GAAG,IAAA,8BAAoB,EAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC/D,IAAI,iBAAiB,CAAC,UAAU,EAAE;YAChC,MAAM,iBAAiB,CAAC,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,CAAA;SAC/D;QACD,OAAM;IACR,CAAC;CAAA;AAVD,gCAUC;AAED,SAAgB,gBAAgB,CAC9B,OAAsB,EACtB,IAAuB;IAEvB,MAAM,iBAAiB,GAAG,IAAA,8BAAoB,EAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/D,OAAO;QACL,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC,cAAc;QAC5C,MAAM,EAAE,IAAI,CAAC,OAAO;QACpB,QAAQ,EAAE,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC;QACrD,UAAU,EAAE,IAAI,CAAC,EAAE;QACnB,iBAAiB,EAAE,IAAI,CAAC,IAAI;QAC5B,oBAAoB,EAAE,SAAS,EAAE,qBAAqB;KACvD,CAAA;AACH,CAAC;AAbD,4CAaC;AAED,IAAY,WAUX;AAVD,WAAY,WAAW;IACrB,qCAAsB,CAAA;IACtB,+CAAgC,CAAA;IAChC,iDAAkC,CAAA;IAClC,2CAA4B,CAAA;IAC5B,sCAAuB,CAAA;IACvB,oCAAqB,CAAA;IACrB,+CAAgC,CAAA;IAChC,8CAA+B,CAAA;IAC/B,oCAAqB,CAAA;AACvB,CAAC,EAVW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAUtB"}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -8,8 +8,11 @@ export interface BotonicPluginFlowBuilderOptions {
|
|
|
8
8
|
customFunctions?: Record<any, any>;
|
|
9
9
|
getLocale: (session: Session) => string;
|
|
10
10
|
getAccessToken: () => string;
|
|
11
|
-
trackEvent?: (request: ActionRequest,
|
|
11
|
+
trackEvent?: (request: ActionRequest, eventAction: string, args?: Record<string, any>) => Promise<void>;
|
|
12
12
|
getKnowledgeBaseResponse?: (request: ActionRequest) => Promise<KnowledgeBaseResponse>;
|
|
13
|
+
smartIntentsConfig?: {
|
|
14
|
+
numSmartIntentsToUse: number;
|
|
15
|
+
};
|
|
13
16
|
}
|
|
14
17
|
export interface FlowBuilderApiOptions {
|
|
15
18
|
url: string;
|
|
@@ -33,6 +36,16 @@ export interface KnowledgeBaseResponse {
|
|
|
33
36
|
page?: number;
|
|
34
37
|
}[];
|
|
35
38
|
}
|
|
39
|
+
export interface SmartIntentResponse {
|
|
40
|
+
data: {
|
|
41
|
+
smart_intent_title: string;
|
|
42
|
+
text: string;
|
|
43
|
+
smart_intents_used: {
|
|
44
|
+
title: string;
|
|
45
|
+
description: string;
|
|
46
|
+
}[];
|
|
47
|
+
};
|
|
48
|
+
}
|
|
36
49
|
export interface PayloadParamsBase {
|
|
37
50
|
followUpContentID?: string;
|
|
38
51
|
}
|
package/lib/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AA8BA,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,+CAAyB,CAAA;IACzB,iDAA2B,CAAA;AAC7B,CAAC,EAHW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAG7B;AAED,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,yCAAe,CAAA;IACf,2CAAiB,CAAA;AACnB,CAAC,EAHW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAGjC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ActionRequest } from '@botonic/react';
|
|
2
2
|
import { FlowBuilderApi } from '../api';
|
|
3
3
|
import { HtIntentNode, HtKeywordNode, HtSmartIntentNode } from '../content-fields/hubtype-fields';
|
|
4
|
-
|
|
4
|
+
import { SmartIntentsInferenceConfig } from './smart-intent';
|
|
5
|
+
export declare function getNodeByUserInput(cmsApi: FlowBuilderApi, locale: string, request: ActionRequest, smartIntentsConfig: SmartIntentsInferenceConfig): Promise<HtSmartIntentNode | HtIntentNode | HtKeywordNode | undefined>;
|
|
@@ -5,13 +5,19 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const intent_1 = require("./intent");
|
|
6
6
|
const keyword_1 = require("./keyword");
|
|
7
7
|
const smart_intent_1 = require("./smart-intent");
|
|
8
|
-
function getNodeByUserInput(cmsApi, locale, request) {
|
|
8
|
+
function getNodeByUserInput(cmsApi, locale, request, smartIntentsConfig) {
|
|
9
9
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
10
10
|
if (request.input.data) {
|
|
11
|
-
const
|
|
11
|
+
const keywordMatcher = new keyword_1.KeywordMatcher({
|
|
12
|
+
cmsApi,
|
|
13
|
+
locale,
|
|
14
|
+
request,
|
|
15
|
+
});
|
|
16
|
+
const keywordNode = yield keywordMatcher.getNodeByInput(request.input.data);
|
|
12
17
|
if (keywordNode)
|
|
13
18
|
return keywordNode;
|
|
14
|
-
const
|
|
19
|
+
const smartIntentsApi = new smart_intent_1.SmartIntentsApi(cmsApi, request, smartIntentsConfig);
|
|
20
|
+
const smartIntentNode = smartIntentsApi.getNodeByInput();
|
|
15
21
|
if (smartIntentNode)
|
|
16
22
|
return smartIntentNode;
|
|
17
23
|
const intentNode = yield (0, intent_1.getIntentNodeByInput)(cmsApi, locale, request);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/user-input/index.ts"],"names":[],"mappings":";;;;AAQA,qCAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/user-input/index.ts"],"names":[],"mappings":";;;;AAQA,qCAA+C;AAC/C,uCAA0C;AAC1C,iDAA6E;AAE7E,SAAsB,kBAAkB,CACtC,MAAsB,EACtB,MAAc,EACd,OAAsB,EACtB,kBAA+C;;QAE/C,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE;YACtB,MAAM,cAAc,GAAG,IAAI,wBAAc,CAAC;gBACxC,MAAM;gBACN,MAAM;gBACN,OAAO;aACR,CAAC,CAAA;YACF,MAAM,WAAW,GAAG,MAAM,cAAc,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YAC3E,IAAI,WAAW;gBAAE,OAAO,WAAW,CAAA;YAEnC,MAAM,eAAe,GAAG,IAAI,8BAAe,CACzC,MAAM,EACN,OAAO,EACP,kBAAkB,CACnB,CAAA;YACD,MAAM,eAAe,GAAG,eAAe,CAAC,cAAc,EAAE,CAAA;YACxD,IAAI,eAAe;gBAAE,OAAO,eAAe,CAAA;YAE3C,MAAM,UAAU,GAAG,MAAM,IAAA,6BAAoB,EAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;YACtE,IAAI,UAAU;gBAAE,OAAO,UAAU,CAAA;SAClC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;CAAA;AA3BD,gDA2BC"}
|
|
@@ -6,23 +6,27 @@ const tracking_1 = require("../tracking");
|
|
|
6
6
|
function getIntentNodeByInput(cmsApi, locale, request) {
|
|
7
7
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
8
8
|
const intentNode = cmsApi.getIntentNode(request.input, locale);
|
|
9
|
-
const eventArgs = {
|
|
10
|
-
intent: request.input.intent,
|
|
11
|
-
confidence: request.input.confidence,
|
|
12
|
-
confidence_successful: true,
|
|
13
|
-
};
|
|
14
9
|
if (request.input.confidence && request.input.intent && intentNode) {
|
|
10
|
+
yield trackIntentEvent(request, intentNode);
|
|
15
11
|
if (isIntentValid(intentNode, request, cmsApi)) {
|
|
16
|
-
yield (0, tracking_1.trackEvent)(request, tracking_1.EventName.botAiModel, eventArgs);
|
|
17
12
|
return intentNode;
|
|
18
13
|
}
|
|
19
|
-
eventArgs.confidence_successful = false;
|
|
20
|
-
yield (0, tracking_1.trackEvent)(request, tracking_1.EventName.botAiModel, eventArgs);
|
|
21
14
|
}
|
|
22
15
|
return undefined;
|
|
23
16
|
});
|
|
24
17
|
}
|
|
25
18
|
exports.getIntentNodeByInput = getIntentNodeByInput;
|
|
19
|
+
function trackIntentEvent(request, intentNode) {
|
|
20
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const eventArgs = {
|
|
22
|
+
nluIntentLabel: request.input.intent,
|
|
23
|
+
nluIntentConfidence: request.input.confidence,
|
|
24
|
+
nluIntentThreshold: intentNode === null || intentNode === void 0 ? void 0 : intentNode.content.confidence,
|
|
25
|
+
nluIntentMessageId: request.input.message_id,
|
|
26
|
+
};
|
|
27
|
+
yield (0, tracking_1.trackEvent)(request, tracking_1.EventAction.intent, eventArgs);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
26
30
|
function isIntentValid(intentNode, request, cmsApi) {
|
|
27
31
|
return (request.input.confidence &&
|
|
28
32
|
cmsApi.hasMetConfidenceThreshold(intentNode, request.input.confidence));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent.js","sourceRoot":"","sources":["../../../src/user-input/intent.ts"],"names":[],"mappings":";;;;AAIA,
|
|
1
|
+
{"version":3,"file":"intent.js","sourceRoot":"","sources":["../../../src/user-input/intent.ts"],"names":[],"mappings":";;;;AAIA,0CAAqD;AAErD,SAAsB,oBAAoB,CACxC,MAAsB,EACtB,MAAc,EACd,OAAsB;;QAEtB,MAAM,UAAU,GAAG,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAE9D,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,IAAI,UAAU,EAAE;YAClE,MAAM,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;YAE3C,IAAI,aAAa,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE;gBAC9C,OAAO,UAAU,CAAA;aAClB;SACF;QAED,OAAO,SAAS,CAAA;IAClB,CAAC;CAAA;AAhBD,oDAgBC;AAED,SAAe,gBAAgB,CAC7B,OAAsB,EACtB,UAAwB;;QAExB,MAAM,SAAS,GAAG;YAChB,cAAc,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM;YACpC,mBAAmB,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU;YAC7C,kBAAkB,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,CAAC,UAAU;YAClD,kBAAkB,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU;SAC7C,CAAA;QACD,MAAM,IAAA,qBAAU,EAAC,OAAO,EAAE,sBAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAC1D,CAAC;CAAA;AAED,SAAS,aAAa,CACpB,UAAwB,EACxB,OAAsB,EACtB,MAAsB;IAEtB,OAAO,CACL,OAAO,CAAC,KAAK,CAAC,UAAU;QACxB,MAAM,CAAC,yBAAyB,CAAC,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CACvE,CAAA;AACH,CAAC"}
|
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
import { ActionRequest } from '@botonic/react';
|
|
2
2
|
import { FlowBuilderApi } from '../api';
|
|
3
3
|
import { HtKeywordNode } from '../content-fields/hubtype-fields';
|
|
4
|
-
|
|
4
|
+
interface KeywordProps {
|
|
5
|
+
cmsApi: FlowBuilderApi;
|
|
6
|
+
locale: string;
|
|
7
|
+
request: ActionRequest;
|
|
8
|
+
}
|
|
9
|
+
export declare class KeywordMatcher {
|
|
10
|
+
cmsApi: FlowBuilderApi;
|
|
11
|
+
locale: string;
|
|
12
|
+
request: ActionRequest;
|
|
13
|
+
isRegExp: boolean;
|
|
14
|
+
matchedKeyword?: string;
|
|
15
|
+
keywordNodeId?: string;
|
|
16
|
+
constructor({ cmsApi, locale, request }: KeywordProps);
|
|
17
|
+
getNodeByInput(userInput: string): Promise<HtKeywordNode | undefined>;
|
|
18
|
+
private getNodeByKeyword;
|
|
19
|
+
private matchKeywords;
|
|
20
|
+
private inputMatchesAnyKeyword;
|
|
21
|
+
private resolveKeywordAsRegExp;
|
|
22
|
+
private trackKeywordEvent;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -1,20 +1,75 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.KeywordMatcher = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
5
6
|
const tracking_1 = require("../tracking");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
class KeywordMatcher {
|
|
8
|
+
constructor({ cmsApi, locale, request }) {
|
|
9
|
+
this.cmsApi = cmsApi;
|
|
10
|
+
this.locale = locale;
|
|
11
|
+
this.request = request;
|
|
12
|
+
this.isRegExp = false;
|
|
13
|
+
}
|
|
14
|
+
getNodeByInput(userInput) {
|
|
15
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const keywordNodes = this.cmsApi.getKeywordNodes();
|
|
17
|
+
const keywordNode = this.getNodeByKeyword(userInput, keywordNodes);
|
|
18
|
+
if (!keywordNode) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
this.trackKeywordEvent();
|
|
22
|
+
return keywordNode;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
getNodeByKeyword(userInput, keywordNodes) {
|
|
26
|
+
const matchedKeywordNodes = keywordNodes.filter(node => this.matchKeywords(userInput, node));
|
|
27
|
+
if (matchedKeywordNodes.length > 0 && matchedKeywordNodes[0].target) {
|
|
28
|
+
return matchedKeywordNodes[0];
|
|
11
29
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
matchKeywords(userInput, node) {
|
|
33
|
+
const result = node.content.keywords.find(keywords => {
|
|
34
|
+
if (keywords.locale === this.locale) {
|
|
35
|
+
this.keywordNodeId = node.id;
|
|
36
|
+
return this.inputMatchesAnyKeyword(userInput, keywords.values);
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
});
|
|
40
|
+
return Boolean(result);
|
|
41
|
+
}
|
|
42
|
+
inputMatchesAnyKeyword(userInput, keywords) {
|
|
43
|
+
return keywords.some(keyword => {
|
|
44
|
+
const regExpMatchArray = keyword.match(constants_1.REG_EXP_PATTERN);
|
|
45
|
+
if (regExpMatchArray) {
|
|
46
|
+
const keywordAsRegExp = this.resolveKeywordAsRegExp(regExpMatchArray);
|
|
47
|
+
const match = userInput.match(keywordAsRegExp);
|
|
48
|
+
this.isRegExp = true;
|
|
49
|
+
this.matchedKeyword = match ? match[0] : undefined;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this.isRegExp = false;
|
|
53
|
+
this.matchedKeyword = userInput.includes(keyword) ? keyword : undefined;
|
|
54
|
+
}
|
|
55
|
+
return this.matchedKeyword !== undefined;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
resolveKeywordAsRegExp(regExpMatchArray) {
|
|
59
|
+
const [, pattern, flags] = regExpMatchArray;
|
|
60
|
+
return new RegExp(pattern, flags);
|
|
61
|
+
}
|
|
62
|
+
trackKeywordEvent() {
|
|
63
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const eventArgs = {
|
|
65
|
+
nluKeywordId: this.keywordNodeId,
|
|
66
|
+
nluKeywordName: this.matchedKeyword,
|
|
67
|
+
nluKeywordIsRegex: this.isRegExp,
|
|
68
|
+
nluKeywordMessageId: this.request.input.message_id,
|
|
69
|
+
};
|
|
70
|
+
yield (0, tracking_1.trackEvent)(this.request, tracking_1.EventAction.keyword, eventArgs);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
18
73
|
}
|
|
19
|
-
exports.
|
|
74
|
+
exports.KeywordMatcher = KeywordMatcher;
|
|
20
75
|
//# sourceMappingURL=keyword.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyword.js","sourceRoot":"","sources":["../../../src/user-input/keyword.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"keyword.js","sourceRoot":"","sources":["../../../src/user-input/keyword.ts"],"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BACnC,iBAAiB,EAAE,IAAI,CAAC,QAAQ;gBAChC,mBAAmB,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU;aACnD,CAAA;YACD,MAAM,IAAA,qBAAU,EAAC,IAAI,CAAC,OAAO,EAAE,sBAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;QAChE,CAAC;KAAA;CACF;AAxFD,wCAwFC"}
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { ActionRequest } from '@botonic/react';
|
|
2
2
|
import { FlowBuilderApi } from '../api';
|
|
3
3
|
import { HtSmartIntentNode } from '../content-fields/hubtype-fields/smart-intent';
|
|
4
|
-
export
|
|
4
|
+
export interface SmartIntentsInferenceParams {
|
|
5
|
+
bot_id: string;
|
|
6
|
+
text: string;
|
|
7
|
+
num_smart_intents_to_use?: number;
|
|
8
|
+
use_latest: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface SmartIntentsInferenceConfig {
|
|
11
|
+
useLatest: boolean;
|
|
12
|
+
numSmartIntentsToUse?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare class SmartIntentsApi {
|
|
15
|
+
cmsApi: FlowBuilderApi;
|
|
16
|
+
currentRequest: ActionRequest;
|
|
17
|
+
smartIntentsConfig: SmartIntentsInferenceConfig;
|
|
18
|
+
constructor(cmsApi: FlowBuilderApi, currentRequest: ActionRequest, smartIntentsConfig: SmartIntentsInferenceConfig);
|
|
19
|
+
getNodeByInput(): Promise<HtSmartIntentNode | undefined>;
|
|
20
|
+
private getInference;
|
|
21
|
+
}
|
|
@@ -1,43 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SmartIntentsApi = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
const tracking_1 = require("../tracking");
|
|
7
|
+
class SmartIntentsApi {
|
|
8
|
+
constructor(cmsApi, currentRequest, smartIntentsConfig) {
|
|
9
|
+
this.cmsApi = cmsApi;
|
|
10
|
+
this.currentRequest = currentRequest;
|
|
11
|
+
this.smartIntentsConfig = smartIntentsConfig;
|
|
12
|
+
}
|
|
13
|
+
getNodeByInput() {
|
|
14
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
if (!this.currentRequest.input.data)
|
|
16
|
+
return undefined;
|
|
17
|
+
const smartIntentNodes = this.cmsApi.getSmartIntentNodes();
|
|
18
|
+
if (!smartIntentNodes.length)
|
|
19
|
+
return undefined;
|
|
20
|
+
const params = {
|
|
21
|
+
bot_id: this.currentRequest.session.bot.id,
|
|
22
|
+
text: this.currentRequest.input.data,
|
|
23
|
+
num_smart_intents_to_use: this.smartIntentsConfig.numSmartIntentsToUse,
|
|
24
|
+
use_latest: this.smartIntentsConfig.useLatest,
|
|
16
25
|
};
|
|
26
|
+
try {
|
|
27
|
+
const response = yield this.getInference(params);
|
|
28
|
+
const smartIntentNode = smartIntentNodes.find(smartIntentNode => smartIntentNode.content.title === response.data.smart_intent_title);
|
|
29
|
+
if (smartIntentNode) {
|
|
30
|
+
(0, tracking_1.trackEvent)(this.currentRequest, tracking_1.EventAction.intentSmart, {
|
|
31
|
+
nluIntentSmartTitle: response.data.smart_intent_title,
|
|
32
|
+
nluIntentSmartNumUsed: response.data.smart_intents_used,
|
|
33
|
+
nluIntentSmartMessageId: this.currentRequest.input.message_id,
|
|
34
|
+
});
|
|
35
|
+
return smartIntentNode;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
console.error(e);
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
17
42
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const response = yield (0, axios_1.default)({
|
|
43
|
+
}
|
|
44
|
+
getInference(inferenceParams) {
|
|
45
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
return yield (0, axios_1.default)({
|
|
24
47
|
method: 'POST',
|
|
25
|
-
url: `${process.env.HUBTYPE_API_URL}/external/
|
|
48
|
+
url: `${process.env.HUBTYPE_API_URL}/external/v2/ai/smart_intents/inference/`,
|
|
26
49
|
headers: {
|
|
27
|
-
Authorization: `Bearer ${
|
|
50
|
+
Authorization: `Bearer ${this.currentRequest.session._access_token}`,
|
|
28
51
|
'Content-Type': 'application/json',
|
|
29
52
|
},
|
|
30
|
-
data:
|
|
53
|
+
data: inferenceParams,
|
|
31
54
|
timeout: 10000,
|
|
32
55
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
console.error(e);
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
41
58
|
}
|
|
42
|
-
exports.
|
|
59
|
+
exports.SmartIntentsApi = SmartIntentsApi;
|
|
43
60
|
//# sourceMappingURL=smart-intent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smart-intent.js","sourceRoot":"","sources":["../../../src/user-input/smart-intent.ts"],"names":[],"mappings":";;;;AACA,0DAAyB;
|
|
1
|
+
{"version":3,"file":"smart-intent.js","sourceRoot":"","sources":["../../../src/user-input/smart-intent.ts"],"names":[],"mappings":";;;;AACA,0DAAyB;AAIzB,0CAAqD;AAerD,MAAa,eAAe;IAC1B,YACS,MAAsB,EACtB,cAA6B,EAC7B,kBAA+C;QAF/C,WAAM,GAAN,MAAM,CAAgB;QACtB,mBAAc,GAAd,cAAc,CAAe;QAC7B,uBAAkB,GAAlB,kBAAkB,CAA6B;IACrD,CAAC;IAEE,cAAc;;YAClB,IAAI,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