@xapp/stentor-service-lex 1.77.2 → 1.78.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.
@@ -0,0 +1,26 @@
1
+ /// <reference types="node" />
2
+ /*! Copyright (c) 2020, XAPPmedia */
3
+ import { LexModelsV2 } from "aws-sdk/clients/all";
4
+ import { LexServiceBaseV2, LexServiceV2Config } from "./LexServiceBaseV2";
5
+ /**
6
+ * Bulk import service (WIP). We may never use it.
7
+ *
8
+ */
9
+ export declare class LexServiceImporterV2 extends LexServiceBaseV2 {
10
+ constructor(props?: LexServiceV2Config);
11
+ /**
12
+ * Start import into LEX V2 from a zip at the specified path.
13
+ *
14
+ * Note: This only supports importing resourceType "BOT"
15
+ *
16
+ * @param buffer - A buffer of the zip with a single JSON file.
17
+ * @param mergeStrategy - Defaults to FAIL_ON_CONFLICT, other option is OVERWRITE_LATEST
18
+ */
19
+ startImport(buffer: Buffer, mergeStrategy?: LexModelsV2.MergeStrategy): Promise<LexModelsV2.StartImportResponse>;
20
+ /**
21
+ * Get the status of an import after calling {@link startImport}
22
+ *
23
+ * @param importId - Import ID provided by {@link startImport}
24
+ */
25
+ getImport(importId: string): Promise<LexModelsV2.DescribeImportResponse>;
26
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LexServiceImporterV2 = void 0;
13
+ const LexServiceBaseV2_1 = require("./LexServiceBaseV2");
14
+ // export { DescribeImportResponse as DescribeImportResponseV2 };
15
+ // export { StartImportResponse as StartImportResponseV2 };
16
+ const request = require("request");
17
+ /**
18
+ * Bulk import service (WIP). We may never use it.
19
+ *
20
+ */
21
+ class LexServiceImporterV2 extends LexServiceBaseV2_1.LexServiceBaseV2 {
22
+ constructor(props) {
23
+ super(props);
24
+ }
25
+ /**
26
+ * Start import into LEX V2 from a zip at the specified path.
27
+ *
28
+ * Note: This only supports importing resourceType "BOT"
29
+ *
30
+ * @param buffer - A buffer of the zip with a single JSON file.
31
+ * @param mergeStrategy - Defaults to FAIL_ON_CONFLICT, other option is OVERWRITE_LATEST
32
+ */
33
+ startImport(buffer, mergeStrategy = "FAIL_ON_CONFLICT") {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const lexManagement = yield this.lexManagement;
36
+ // Store buff into tmp s3 bucket
37
+ const signedUploadUrlResponse = yield lexManagement.createUploadUrl().promise();
38
+ const params = {
39
+ importId: signedUploadUrlResponse.importId,
40
+ mergeStrategy,
41
+ resourceSpecification: {
42
+ botImportSpecification: {
43
+ botName: this.config.botName,
44
+ dataPrivacy: {
45
+ childDirected: this.config.childDirected
46
+ },
47
+ roleArn: this.config.credentials.role.arn,
48
+ idleSessionTTLInSeconds: this.config.idleSessionTTLInSeconds
49
+ },
50
+ botLocaleImportSpecification: {
51
+ botId: this.config.botId,
52
+ botVersion: this.config.botVersion,
53
+ localeId: this.config.localeId,
54
+ nluIntentConfidenceThreshold: this.config.nluConfidenceThreshold,
55
+ voiceSettings: {
56
+ voiceId: this.config.voiceId
57
+ }
58
+ }
59
+ }
60
+ };
61
+ const options = {
62
+ method: "PUT",
63
+ url: signedUploadUrlResponse.uploadUrl,
64
+ headers: {
65
+ "Content-Type": 'image/png'
66
+ },
67
+ body: buffer
68
+ };
69
+ return new Promise((resolve, reject) => {
70
+ // Upload buffer
71
+ request(options, (error1) => {
72
+ if (error1) {
73
+ reject(error1);
74
+ }
75
+ // start import
76
+ lexManagement.startImport(params, (error2, data) => {
77
+ if (error2) {
78
+ reject(error2);
79
+ }
80
+ resolve(data);
81
+ });
82
+ });
83
+ });
84
+ });
85
+ }
86
+ /**
87
+ * Get the status of an import after calling {@link startImport}
88
+ *
89
+ * @param importId - Import ID provided by {@link startImport}
90
+ */
91
+ getImport(importId) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const lexManagement = yield this.lexManagement;
94
+ return new Promise((resolve, reject) => {
95
+ lexManagement.describeImport({ importId }, (error, data) => {
96
+ if (error) {
97
+ reject(error);
98
+ }
99
+ resolve(data);
100
+ });
101
+ });
102
+ });
103
+ }
104
+ }
105
+ exports.LexServiceImporterV2 = LexServiceImporterV2;
106
+ //# sourceMappingURL=LexServiceImporterV2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LexServiceImporterV2.js","sourceRoot":"","sources":["../../../src/LexV2/services/LexServiceImporterV2.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,yDAA0E;AAE1E,iEAAiE;AACjE,2DAA2D;AAE3D,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAEnC;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,mCAAgB;IACtD,YAAY,KAA0B;QAClC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IAED;;;;;;;OAOG;IACG,WAAW,CAAC,MAAc,EAAE,gBAA2C,kBAAkB;;YAC3F,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC;YAE/C,gCAAgC;YAChC,MAAM,uBAAuB,GAAG,MAAM,aAAa,CAAC,eAAe,EAAE,CAAC,OAAO,EAAE,CAAC;YAEhF,MAAM,MAAM,GAAmC;gBAC3C,QAAQ,EAAE,uBAAuB,CAAC,QAAQ;gBAC1C,aAAa;gBACb,qBAAqB,EAAE;oBACnB,sBAAsB,EAAE;wBACpB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;wBAC5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QAAgB;;YAC5B,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC;YAC/C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACnC,aAAa,CAAC,cAAc,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;oBACvD,IAAI,KAAK,EAAE;wBACP,MAAM,CAAC,KAAK,CAAC,CAAC;qBACjB;oBACD,OAAO,CAAC,IAAI,CAAC,CAAC;gBAClB,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;QACP,CAAC;KAAA;CACJ;AAzFD,oDAyFC"}
@@ -0,0 +1,18 @@
1
+ /*! Copyright (c) 2020, XAPPmedia */
2
+ import { LexServiceBaseV2, LexServiceV2Config } from "./LexServiceBaseV2";
3
+ import { NLUService, NLUQueryResponse } from "stentor-models";
4
+ /**
5
+ * Service to communicate with AWS LEX V2 runtime.
6
+ *
7
+ */
8
+ export declare class LexServiceV2 extends LexServiceBaseV2 implements NLUService {
9
+ constructor(props?: LexServiceV2Config);
10
+ /**
11
+ * Convert raw text to intent and entities.
12
+ *
13
+ * @param q - Raw text
14
+ * @param userId
15
+ * @param sessionId
16
+ */
17
+ query(q: string, userId?: string, sessionId?: string): Promise<NLUQueryResponse>;
18
+ }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2020, XAPPmedia */
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.LexServiceV2 = void 0;
14
+ const uuid_1 = require("uuid");
15
+ const stentor_alexa_lib_1 = require("@xapp/stentor-alexa-lib");
16
+ const stentor_constants_1 = require("stentor-constants");
17
+ const models_1 = require("../models");
18
+ const LexServiceBaseV2_1 = require("./LexServiceBaseV2");
19
+ const stentor_logger_1 = require("stentor-logger");
20
+ /**
21
+ * Service to communicate with AWS LEX V2 runtime.
22
+ *
23
+ */
24
+ class LexServiceV2 extends LexServiceBaseV2_1.LexServiceBaseV2 {
25
+ constructor(props) {
26
+ super(props);
27
+ }
28
+ /**
29
+ * Convert raw text to intent and entities.
30
+ *
31
+ * @param q - Raw text
32
+ * @param userId
33
+ * @param sessionId
34
+ */
35
+ query(q, userId, sessionId) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const lexRuntime = yield this.lexRuntime;
38
+ return new Promise((resolve, reject) => {
39
+ // Do some quick validation
40
+ if (!this.config.botAlias) {
41
+ reject(Error("Bot Alias is required to query LEX V2 NLU"));
42
+ return;
43
+ }
44
+ if (!this.config.botId) {
45
+ reject(Error("Bot Id is required to query LEX V2 NLU"));
46
+ return;
47
+ }
48
+ const uniqueTag = (0, uuid_1.v4)();
49
+ if (!userId) {
50
+ userId = `query.${uniqueTag}`;
51
+ }
52
+ const params = {
53
+ botId: this.config.botId,
54
+ botAliasId: this.config.botAlias,
55
+ localeId: this.config.localeId,
56
+ sessionId: sessionId || `lex-v2-session-${uniqueTag}`,
57
+ sessionState: {
58
+ sessionAttributes: {
59
+ channel: "widget"
60
+ },
61
+ activeContexts: []
62
+ },
63
+ text: q
64
+ };
65
+ lexRuntime.recognizeText(params, (error, data) => {
66
+ if (error) {
67
+ reject(error);
68
+ return;
69
+ }
70
+ (0, stentor_logger_1.log)().debug(`LEX V2 NLU says: ${JSON.stringify(data, undefined, 2)}`);
71
+ const type = new stentor_alexa_lib_1.TranslateAlexaIntentType({ translateFor: "LEX", postFix: this.postFix });
72
+ // Fish out the intent with highest confidence
73
+ const intent = data.interpretations[0].intent;
74
+ // It may have a tag (suffix)
75
+ intent.name = (0, models_1.untagIntent)(intent.name);
76
+ // Translate the data
77
+ const nluQueryResponse = {
78
+ type: "INTENT_REQUEST",
79
+ intentId: type.translate(intent.name),
80
+ slots: {}
81
+ };
82
+ if (!nluQueryResponse.intentId || nluQueryResponse.intentId === stentor_constants_1.INPUT_UNKNOWN_ID) {
83
+ // Couldn't match, it is an InputUnknown
84
+ nluQueryResponse.type = "INPUT_UNKNOWN_REQUEST";
85
+ nluQueryResponse.intentId = stentor_constants_1.INPUT_UNKNOWN_ID;
86
+ }
87
+ if (typeof intent.slots === "object") {
88
+ // Iterate through the keys.
89
+ Object.keys(intent.slots).forEach((slotName) => {
90
+ var _a, _b;
91
+ const slot = intent.slots[slotName];
92
+ if (slot === null || slot === void 0 ? void 0 : slot.value) {
93
+ nluQueryResponse.slots[slotName] = {
94
+ name: slotName,
95
+ value: ((_a = slot === null || slot === void 0 ? void 0 : slot.value) === null || _a === void 0 ? void 0 : _a.interpretedValue) || ((_b = slot === null || slot === void 0 ? void 0 : slot.value) === null || _b === void 0 ? void 0 : _b.originalValue),
96
+ };
97
+ }
98
+ });
99
+ }
100
+ resolve(nluQueryResponse);
101
+ });
102
+ });
103
+ });
104
+ }
105
+ }
106
+ exports.LexServiceV2 = LexServiceV2;
107
+ //# sourceMappingURL=LexServiceNluV2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LexServiceNluV2.js","sourceRoot":"","sources":["../../../src/LexV2/services/LexServiceNluV2.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;AAIpC,+BAAoC;AAEpC,+DAAmE;AACnE,yDAAqD;AACrD,sCAAwC;AAExC,yDAA0E;AAM1E,mDAAqC;AAErC;;;GAGG;AACH,MAAa,YAAa,SAAQ,mCAAgB;IAC9C,YAAY,KAA0B;QAClC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IAED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,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,0CAAE,aAAa,CAAA;iCACrE,CAAC;6BACL;wBACL,CAAC,CAAC,CAAC;qBACN;oBAED,OAAO,CAAC,gBAAgB,CAAC,CAAC;gBAC9B,CAAC,CACJ,CAAC;YACN,CAAC,CAAC,CAAC;QACP,CAAC;KAAA;CACJ;AAlGD,oCAkGC"}
@@ -0,0 +1,24 @@
1
+ /*! Copyright (c) 2020, XAPPmedia */
2
+ import { Entity as OvaiEntity, Handler as OvaiHandler, Intent as OvaiIntent } from "stentor-models";
3
+ import { LexSyncStatusV2 } from "../models";
4
+ import { LexServiceBaseV2, LexServiceV2Config } from "./LexServiceBaseV2";
5
+ /**
6
+ * Service to communicate with AWS LEX V2 runtime.
7
+ *
8
+ */
9
+ export declare class LexServiceSyncV2 extends LexServiceBaseV2 {
10
+ private syncStatus;
11
+ constructor(props?: {
12
+ config: LexServiceV2Config;
13
+ });
14
+ /**
15
+ * Sync the OVAI model to Lex V2
16
+ *
17
+ * @param ovaiApp
18
+ * @param ovaiIntents
19
+ * @param ovaiEntities
20
+ */
21
+ sync(ovaiApp: string, ovaiIntents: (OvaiIntent | OvaiHandler)[], ovaiEntities: OvaiEntity[]): Promise<LexSyncStatusV2>;
22
+ delete(ovaiApp: string, ovaiIntents: (OvaiIntent | OvaiHandler)[], ovaiEntities: OvaiEntity[]): Promise<LexSyncStatusV2>;
23
+ getStatus(): LexSyncStatusV2;
24
+ }
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LexServiceSyncV2 = void 0;
13
+ const translators_1 = require("../translators");
14
+ const LexResourceListerV2_1 = require("./LexResourceListerV2");
15
+ const LexResourceWaiterV2_1 = require("./LexResourceWaiterV2");
16
+ const LexServiceBaseV2_1 = require("./LexServiceBaseV2");
17
+ const stentor_logger_1 = require("stentor-logger");
18
+ /**
19
+ * Service to communicate with AWS LEX V2 runtime.
20
+ *
21
+ */
22
+ class LexServiceSyncV2 extends LexServiceBaseV2_1.LexServiceBaseV2 {
23
+ constructor(props) {
24
+ super(props.config);
25
+ this.syncStatus = { botId: this.config.botId, state: "COMPLETE" };
26
+ }
27
+ /**
28
+ * Sync the OVAI model to Lex V2
29
+ *
30
+ * @param ovaiApp
31
+ * @param ovaiIntents
32
+ * @param ovaiEntities
33
+ */
34
+ sync(ovaiApp, ovaiIntents, ovaiEntities) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ let lexBots;
37
+ let botId;
38
+ try {
39
+ lexBots = new translators_1.TranslateToLexRequest(this.config).translate({ ovaiApp, ovaiIntents, ovaiEntities });
40
+ // log.info(`BOT Tree: ${JSON.stringify(lexBots)}`);
41
+ const lexManagement = yield this.lexManagement;
42
+ // Fill in the ids for existing
43
+ const lexLister = new LexResourceListerV2_1.LexResourceListerV2(lexManagement);
44
+ yield lexLister.init(lexBots);
45
+ const waiter = new LexResourceWaiterV2_1.LexResourceWaiterV2(lexManagement, lexLister);
46
+ // Bots (1)
47
+ for (const botName of Object.keys(lexBots)) {
48
+ const botRequest = lexBots[botName].botRequest;
49
+ const botLocales = lexBots[botName].botLocales;
50
+ // Create bot
51
+ botId = yield waiter.waitForBot(botRequest);
52
+ // Locales
53
+ for (const localeName of Object.keys(botLocales)) {
54
+ const botLocaleRequest = botLocales[localeName].botLocalRequest;
55
+ const intents = botLocales[localeName].intents;
56
+ const slotTypes = botLocales[localeName].slotTypes;
57
+ // Create locale
58
+ botLocaleRequest.botId = botId; // set parent id
59
+ const localeId = yield waiter.waitForBotLocale(botLocaleRequest);
60
+ // Slot types
61
+ for (const slotTypeName of Object.keys(slotTypes)) {
62
+ const slotTypeRequest = slotTypes[slotTypeName].slotTypeRequest;
63
+ // Set parent ids
64
+ slotTypeRequest.botId = botId;
65
+ slotTypeRequest.localeId = localeId;
66
+ // Create slot type
67
+ yield waiter.waitForSlotType(slotTypeRequest);
68
+ }
69
+ // Intents
70
+ for (const intentName of Object.keys(intents)) {
71
+ const intentRequest = intents[intentName].intentRequest;
72
+ const slots = intents[intentName].slots;
73
+ // Set parent ids
74
+ intentRequest.botId = botId;
75
+ intentRequest.localeId = localeId;
76
+ // Create intent
77
+ const intentId = yield waiter.waitForIntent(intentRequest);
78
+ intentRequest.slotPriorities = [];
79
+ let priority = 1;
80
+ // Slots
81
+ for (const slotName of Object.keys(slots)) {
82
+ const slotRequest = slots[slotName].slotRequest;
83
+ // Set parent ids
84
+ slotRequest.intentId = intentId;
85
+ slotRequest.botId = botId;
86
+ slotRequest.localeId = localeId;
87
+ // Create slot
88
+ const slotId = yield waiter.waitForSlot(slotRequest);
89
+ intentRequest.slotPriorities.push({
90
+ priority,
91
+ slotId
92
+ });
93
+ priority++;
94
+ }
95
+ // Update with slot priorities
96
+ if (intentRequest.slotPriorities.length > 0) {
97
+ intentRequest.intentId = intentId;
98
+ yield waiter.waitForIntent(intentRequest);
99
+ }
100
+ }
101
+ // Create/Update locale
102
+ const botAliasRequest = lexBots[botName].botAliasRequest;
103
+ botAliasRequest.botId = botId; // set parent id]
104
+ botAliasRequest.botVersion = botLocaleRequest.botVersion;
105
+ // Nuke the messing ones
106
+ yield waiter.deleteUnused({ botId, localeId, botVersion: botLocaleRequest.botVersion });
107
+ // This will set the fulfillment ARN
108
+ yield waiter.waitForBotAlias(botAliasRequest);
109
+ // Build
110
+ yield waiter.waitForBuild(botLocaleRequest);
111
+ }
112
+ }
113
+ }
114
+ catch (err) {
115
+ // log.error(`LEX Sync failed. BOT Tree:\n${JSON.stringify(lexBots, null, 2)}`);
116
+ if (err.stack) {
117
+ stentor_logger_1.default.error(err.stack);
118
+ }
119
+ this.syncStatus = { botId, state: "FAILED", message: err.message };
120
+ }
121
+ return this.syncStatus;
122
+ });
123
+ }
124
+ delete(ovaiApp, ovaiIntents, ovaiEntities) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ try {
127
+ const lexManagement = yield this.lexManagement;
128
+ const waiter = new LexResourceWaiterV2_1.LexResourceWaiterV2(lexManagement);
129
+ const botName = translators_1.TranslateToLexBotRequest.generateBotName(ovaiApp);
130
+ yield waiter.waitForBotDelete(botName);
131
+ }
132
+ catch (err) {
133
+ this.syncStatus = { botId: undefined, state: "FAILED", message: err.message };
134
+ }
135
+ return this.syncStatus;
136
+ });
137
+ }
138
+ getStatus() {
139
+ return this.syncStatus;
140
+ }
141
+ }
142
+ exports.LexServiceSyncV2 = LexServiceSyncV2;
143
+ //# sourceMappingURL=LexServiceSyncV2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LexServiceSyncV2.js","sourceRoot":"","sources":["../../../src/LexV2/services/LexServiceSyncV2.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,gDAAiF;AACjF,+DAA4D;AAC5D,+DAA4D;AAC5D,yDAA0E;AAE1E,mDAAiC;AAEjC;;;GAGG;AACH,MAAa,gBAAiB,SAAQ,mCAAgB;IAGlD,YAAY,KAAsC;QAC9C,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAEpB,IAAI,CAAC,UAAU,GAAG,EAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAC,CAAC;IACpE,CAAC;IAED;;;;;;OAMG;IACU,IAAI,CAAC,OAAe,EAAE,WAAyC,EAAE,YAA0B;;YACpG,IAAI,OAAO,CAAC;YACZ,IAAI,KAAK,CAAC;YAEV,IAAI;gBACA,OAAO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B,CAAC,aAAa,CAAC,CAAC;gBAEtD,MAAM,OAAO,GAAG,sCAAwB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;gBAElE,MAAM,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;aAC1C;YAAC,OAAO,GAAG,EAAE;gBACV,IAAI,CAAC,UAAU,GAAG,EAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAC,CAAC;aAC/E;YAED,OAAO,IAAI,CAAC,UAAU,CAAC;QAC3B,CAAC;KAAA;IAEM,SAAS;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;CACJ;AAzJD,4CAyJC"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "1.77.2",
7
+ "version": "1.78.0",
8
8
  "description": "Service to communicate with AWS LEX for :mega: stentor",
9
9
  "types": "lib/index",
10
10
  "main": "lib/index",
@@ -29,7 +29,7 @@
29
29
  "stentor-handler": "1.71.0",
30
30
  "stentor-history": "1.71.0",
31
31
  "stentor-media": "1.71.0",
32
- "stentor-models": "1.71.0",
32
+ "stentor-models": "1.72.0",
33
33
  "typescript": "5.9.3"
34
34
  },
35
35
  "dependencies": {
@@ -37,7 +37,7 @@
37
37
  "@aws-sdk/client-lex-runtime-v2": "3.1032.0",
38
38
  "@aws-sdk/client-sts": "3.1032.0",
39
39
  "@aws-sdk/credential-providers": "3.1032.0",
40
- "@xapp/stentor-alexa-lib": "1.77.2",
40
+ "@xapp/stentor-alexa-lib": "1.78.0",
41
41
  "lodash.merge": "4.6.2",
42
42
  "uuid": "11.1.0"
43
43
  },
@@ -53,5 +53,5 @@
53
53
  "clean": "rm -rf ./lib/*",
54
54
  "test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
55
55
  },
56
- "gitHead": "2ad66e5027dcf0a1aae780792cd30c7a5f284c76"
56
+ "gitHead": "7ad5a86334ecb7ae383da1aef801375cb9af71af"
57
57
  }