wingbot 3.76.10 → 3.76.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot",
3
- "version": "3.76.10",
3
+ "version": "3.76.12",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -183,7 +183,9 @@ class LLMDispatcher {
183
183
 
184
184
  let aiRes;
185
185
  let llmRes;
186
- if ((!res || bounceAllow) && routing?.router) {
186
+
187
+ // lets skip llm routing when user uploads an attachment
188
+ if ((!res || bounceAllow) && routing?.router && !this._req.isAttachment()) {
187
189
  aiRes = await routing.router.resolve(this._llm, this._req, routing);
188
190
  }
189
191
 
package/src/Responder.js CHANGED
@@ -911,6 +911,52 @@ class Responder {
911
911
  this.routePath = routePath;
912
912
  }
913
913
 
914
+ /**
915
+ *
916
+ * @param {Object.<string,string|QuickReply>|QuickReply[]} [replies] - quick replies
917
+ * @param {object} [messageData]
918
+ * @returns {QuickReply[]}
919
+ */
920
+ resolveQuickRepliesForAnswer (replies = null, messageData = null) {
921
+ if (!replies && this._quickReplyCollector.length === 0) {
922
+ return [];
923
+ }
924
+
925
+ const {
926
+ quickReplies: qrs, expectedKeywords, disambiguationIntents
927
+ } = makeQuickReplies(
928
+ replies,
929
+ this.path,
930
+ this._t,
931
+ this._quickReplyCollector,
932
+ Ai.ai,
933
+ this.currentAction()
934
+ );
935
+
936
+ if (!messageData) {
937
+ return qrs;
938
+ }
939
+
940
+ if (disambiguationIntents.length > 0) {
941
+ this._senderMeta = {
942
+ flag: ResponseFlag.DISAMBIGUATION_OFFERED,
943
+ disambiguationIntents
944
+ };
945
+ }
946
+
947
+ if (qrs.length > 0) {
948
+ this.finalMessageSent = true;
949
+ Object.assign(messageData.message, {
950
+ quick_replies: qrs
951
+ });
952
+
953
+ this._addExpectedIntents(expectedKeywords);
954
+ this._quickReplyCollector = [];
955
+ }
956
+
957
+ return qrs;
958
+ }
959
+
914
960
  /**
915
961
  * @typedef {object} MessageOptions
916
962
  * @prop {boolean} [disableAutoTyping]
@@ -953,27 +999,7 @@ class Responder {
953
999
 
954
1000
  this._textResponses.push(text);
955
1001
 
956
- if (replies || this._quickReplyCollector.length !== 0) {
957
- const qrc = this._quickReplyCollector;
958
- const {
959
- quickReplies: qrs, expectedKeywords, disambiguationIntents
960
- } = makeQuickReplies(replies, this.path, this._t, qrc, Ai.ai, this.currentAction());
961
-
962
- if (disambiguationIntents.length > 0) {
963
- this._senderMeta = {
964
- flag: ResponseFlag.DISAMBIGUATION_OFFERED,
965
- disambiguationIntents
966
- };
967
- }
968
-
969
- if (qrs.length > 0) {
970
- this.finalMessageSent = true;
971
- messageData.message.quick_replies = qrs;
972
-
973
- this._addExpectedIntents(expectedKeywords);
974
- this._quickReplyCollector = [];
975
- }
976
- }
1002
+ this.resolveQuickRepliesForAnswer(replies, messageData);
977
1003
 
978
1004
  if (this._features.includes(FEATURE_VOICE)
979
1005
  && (voice || this.voiceControl)) {
package/src/prompt.js CHANGED
@@ -93,7 +93,9 @@ function prompt (strings, ...args) {
93
93
 
94
94
  const renderer = async (req, res = null) => {
95
95
  const reqIsRequest = 'action' in req && typeof req.action === 'function';
96
+ const reqIsResponder = typeof req?.send === 'function';
96
97
  const data = {
98
+ ...(reqIsResponder ? stateData(null, req) : {}),
97
99
  ...(reqIsRequest ? stateData(req, res) : req),
98
100
  ...inputData
99
101
  };
@@ -446,6 +446,10 @@ function message (params, context = {}) {
446
446
  };
447
447
  }
448
448
 
449
+ res.setData({
450
+ _qRepliesToSend: sendReplies || []
451
+ });
452
+
449
453
  if (params.type === 'prompt' && !res.llm.configuration.disableLLM) {
450
454
  res.typingOn()
451
455
  .wait(1000);
@@ -122,14 +122,15 @@ function makeQuickReplies (replies, path = '', translate = (w) => w, quickReplyC
122
122
 
123
123
  let unshift = 0;
124
124
  quickReplyCollector.forEach((reply) => {
125
- if (reply._justToExisting) {
126
- delete reply._justToExisting; // eslint-disable-line no-param-reassign
125
+ const clear = { ...reply };
126
+ if (clear._justToExisting) {
127
+ delete clear._justToExisting;
127
128
  }
128
- if (reply._prepend) {
129
- delete reply._prepend; // eslint-disable-line no-param-reassign
130
- iterate.splice(unshift++, 0, reply);
129
+ if (clear._prepend) {
130
+ delete clear._prepend;
131
+ iterate.splice(unshift++, 0, clear);
131
132
  } else {
132
- iterate.push(reply);
133
+ iterate.push(clear);
133
134
  }
134
135
  });
135
136
 
@@ -56,6 +56,16 @@ module.exports = function stateData (
56
56
  state: res.options.state
57
57
  };
58
58
 
59
+ let $qrTexts;
60
+
61
+ if (typeof res?.resolveQuickRepliesForAnswer === 'function') {
62
+ $qrTexts = res?.resolveQuickRepliesForAnswer(res.data._qRepliesToSend || [])
63
+ .filter((r) => r.title)
64
+ .map((r) => r.title);
65
+ } else {
66
+ $qrTexts = [];
67
+ }
68
+
59
69
  return {
60
70
  senderId,
61
71
  pageId,
@@ -73,6 +83,7 @@ module.exports = function stateData (
73
83
  // yes - res because of circular dependency
74
84
  ...(res && req && req.actionData()),
75
85
  ...(res ? res.data : {}),
76
- $input: $this
86
+ $input: $this,
87
+ $qrTexts
77
88
  };
78
89
  };
@@ -1,11 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(npx mocha:*)",
5
- "Bash(npx tsc *)",
6
- "Bash(npm test *)",
7
- "Bash(node -e \"const p = require\\('./bot/plugins/BTMLLM'\\); console.log\\('factory type:', typeof p\\); console.log\\('factory name:', p.name\\);\")",
8
- "Bash(grep -n \"prompt\\\\`\\\\|tagged\\\\|render\\\\|compile\\\\|hbs\" /Users/ondrejveres/Wingbot/wingbot-llm/src/prompt.js)"
9
- ]
10
- }
11
- }