stentor-response 1.60.52 → 1.60.53
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.
|
@@ -2,7 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeTemplate = executeTemplate;
|
|
4
4
|
exports.replacePlaceholders = replacePlaceholders;
|
|
5
|
-
const
|
|
5
|
+
const compileTemplate_1 = require("./compileTemplate");
|
|
6
|
+
function _replace(s, data) {
|
|
7
|
+
if (!s) {
|
|
8
|
+
return s;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const compiled = (0, compileTemplate_1.compileTemplate)(s);
|
|
12
|
+
const result = compiled(data);
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
console.error(error);
|
|
17
|
+
}
|
|
18
|
+
// return the original in case of error
|
|
19
|
+
return s;
|
|
20
|
+
}
|
|
6
21
|
/**
|
|
7
22
|
* Convert the template to an actual response.
|
|
8
23
|
*
|
|
@@ -20,34 +35,16 @@ function executeTemplate(templatedResponse) {
|
|
|
20
35
|
// and then execute the template
|
|
21
36
|
return new Promise((resolve) => {
|
|
22
37
|
const { data } = templatedResponse;
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const textToSpeech = textToSpeechBuilder(data);
|
|
27
|
-
const displayTextBuilder = template(templatedResponse.displayText);
|
|
28
|
-
const displayText = displayTextBuilder(data);
|
|
38
|
+
const ssml = _replace(templatedResponse.ssml, data);
|
|
39
|
+
const textToSpeech = _replace(templatedResponse.textToSpeech, data);
|
|
40
|
+
const displayText = _replace(templatedResponse.displayText, data);
|
|
29
41
|
resolve({
|
|
30
42
|
ssml,
|
|
31
43
|
textToSpeech,
|
|
32
|
-
displayText
|
|
44
|
+
displayText,
|
|
33
45
|
});
|
|
34
46
|
});
|
|
35
47
|
}
|
|
36
|
-
function _replace(s, data) {
|
|
37
|
-
if (!s) {
|
|
38
|
-
return s;
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
const compiled = template(s);
|
|
42
|
-
const result = compiled(data);
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
console.error(error);
|
|
47
|
-
}
|
|
48
|
-
// return the original in case of error
|
|
49
|
-
return s;
|
|
50
|
-
}
|
|
51
48
|
/**
|
|
52
49
|
* Replaces the placeholders in template
|
|
53
50
|
*
|
|
@@ -67,8 +64,8 @@ function replacePlaceholders(template, request, context) {
|
|
|
67
64
|
storage: context.storage,
|
|
68
65
|
pii: context.pii,
|
|
69
66
|
session: context.session.getStore(),
|
|
70
|
-
request
|
|
71
|
-
}
|
|
67
|
+
request,
|
|
68
|
+
},
|
|
72
69
|
};
|
|
73
70
|
if ("string" === typeof template) {
|
|
74
71
|
return _replace(template, data);
|
|
@@ -77,7 +74,7 @@ function replacePlaceholders(template, request, context) {
|
|
|
77
74
|
const result = {
|
|
78
75
|
ssml: _replace(template.ssml, data),
|
|
79
76
|
displayText: _replace(template.displayText, data),
|
|
80
|
-
textToSpeech: _replace(template.textToSpeech, data)
|
|
77
|
+
textToSpeech: _replace(template.textToSpeech, data),
|
|
81
78
|
};
|
|
82
79
|
return result;
|
|
83
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplatedResponseOutput.js","sourceRoot":"","sources":["../src/TemplatedResponseOutput.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"TemplatedResponseOutput.js","sourceRoot":"","sources":["../src/TemplatedResponseOutput.ts"],"names":[],"mappings":";;AAqCA,0CAmBC;AAYD,kDA6BC;AA9FD,uDAAoD;AAMpD,SAAS,QAAQ,CAAC,CAAS,EAAE,IAAS;IACpC,IAAI,CAAC,CAAC,EAAE,CAAC;QACP,OAAO,CAAC,CAAC;IACX,CAAC;IAED,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,IAAA,iCAAe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AAC,QAAkB,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC;SAAM,CAAC;QACN,MAAM,MAAM,GAAmB;YAC7B,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;YACnC,WAAW,EAAE,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;YACjD,YAAY,EAAE,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC;SACpD,CAAC;QAEF,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*! Copyright (c) 2025, XAPP AI */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.compileTemplate = compileTemplate;
|
|
5
|
+
function compileTemplate(str) {
|
|
6
|
+
return (data) => {
|
|
7
|
+
try {
|
|
8
|
+
// Use Function constructor to safely interpolate values
|
|
9
|
+
return new Function("data", "with (data) { return `" + str.replace(/\\/g, "\\\\").replace(/`/g, "\\`") + "`; }")(data);
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
console.error("Template compilation error:", e);
|
|
13
|
+
return str;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=compileTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compileTemplate.js","sourceRoot":"","sources":["../src/compileTemplate.ts"],"names":[],"mappings":";AAAA,kCAAkC;;AAIlC,0CAUC;AAVD,SAAgB,eAAe,CAAC,GAAW;IACzC,OAAO,CAAC,IAAkB,EAAE,EAAE;QAC5B,IAAI,CAAC;YACH,wDAAwD;YACxD,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,wBAAwB,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;QACzH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,CAAC,CAAC,CAAC;YAChD,OAAO,GAAG,CAAC;QACb,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.60.
|
|
7
|
+
"version": "1.60.53",
|
|
8
8
|
"description": "Response for stentor",
|
|
9
9
|
"types": "lib/index",
|
|
10
10
|
"main": "lib/index",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@xapp/patterns": "2.0.2",
|
|
32
|
-
"lodash.template": "4.5.0",
|
|
33
32
|
"stentor-determiner": "1.60.52",
|
|
34
33
|
"stentor-locales": "1.60.52",
|
|
35
34
|
"stentor-media": "1.60.52",
|
|
@@ -43,5 +42,5 @@
|
|
|
43
42
|
"clean": "rm -rf ./lib/* ",
|
|
44
43
|
"test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
|
|
45
44
|
},
|
|
46
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "c774fdb8767f0e05e4619d2ff529992458f90baf"
|
|
47
46
|
}
|