wingbot 3.71.5 → 3.72.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.
Files changed (152) hide show
  1. package/.babelrc +0 -0
  2. package/.github/workflows/deploy.yml +2 -2
  3. package/.github/workflows/pullRequest.yml +2 -2
  4. package/LICENSE +0 -0
  5. package/README.md +0 -0
  6. package/index.js +0 -0
  7. package/jsconfig.json +0 -0
  8. package/package.json +1 -1
  9. package/plugins/ai.wingbot.clearMessageSequences/plugin.js +0 -0
  10. package/plugins/ai.wingbot.conditionIfGoBackPossible/plugin.js +0 -0
  11. package/plugins/ai.wingbot.disambiguation/plugin.js +0 -0
  12. package/plugins/ai.wingbot.goBack/plugin.js +0 -0
  13. package/plugins/ai.wingbot.goToLastBreadcrumb/plugin.js +0 -0
  14. package/plugins/ai.wingbot.ifImageDetected/plugin.js +0 -0
  15. package/plugins/ai.wingbot.ifStickerDetected/plugin.js +0 -0
  16. package/plugins/ai.wingbot.jumpBack/plugin.js +0 -0
  17. package/plugins/ai.wingbot.jumpTo/plugin.js +0 -0
  18. package/plugins/ai.wingbot.keepInInteraction/plugin.js +0 -0
  19. package/plugins/ai.wingbot.keepInInteractionJustOnce/plugin.js +0 -0
  20. package/plugins/ai.wingbot.keepPreviousHandlers/plugin.js +0 -0
  21. package/plugins/ai.wingbot.keepPreviousHandlersJustOnce/plugin.js +0 -0
  22. package/plugins/ai.wingbot.oneTimeNotificationRequest/plugin.js +0 -0
  23. package/plugins/ai.wingbot.openai/plugin.js +0 -0
  24. package/plugins/ai.wingbot.passThreadToBot/plugin.js +0 -0
  25. package/plugins/ai.wingbot.persona/plugin.js +0 -0
  26. package/plugins/ai.wingbot.putABreadcrumb/plugin.js +0 -0
  27. package/plugins/ai.wingbot.regexp/plugin.js +0 -0
  28. package/plugins/ai.wingbot.setState/plugin.js +0 -0
  29. package/plugins/ai.wingbot.setStateFromInput/plugin.js +0 -0
  30. package/plugins/ai.wingbot.slotsContinue/plugin.js +0 -0
  31. package/plugins/ai.wingbot.slotsRegister/plugin.js +0 -0
  32. package/plugins/ai.wingbot.stopResponding/plugin.js +0 -0
  33. package/plugins/ai.wingbot.trackingEvent/plugin.js +0 -0
  34. package/plugins/ai.wingbot.upload/plugin.js +0 -0
  35. package/plugins/ai.wingbot.waitASecond/plugin.js +0 -0
  36. package/plugins/index.js +0 -0
  37. package/plugins/plugins.json +0 -0
  38. package/src/Ai.js +44 -3
  39. package/src/AiMatching.js +66 -40
  40. package/src/BatchConversationTester.js +0 -0
  41. package/src/BotApp.js +0 -0
  42. package/src/BotAppSender.js +0 -0
  43. package/src/BuildRouter.js +2 -0
  44. package/src/CallbackAuditLog.js +0 -0
  45. package/src/ChatGpt.js +0 -0
  46. package/src/ConversationTester.js +0 -0
  47. package/src/LLM.js +184 -3
  48. package/src/LLMMockProvider.js +0 -0
  49. package/src/LLMSession.js +90 -3
  50. package/src/MockAiModel.js +0 -0
  51. package/src/OrchestratorClient.js +0 -0
  52. package/src/Plugins.js +0 -0
  53. package/src/Processor.js +1 -1
  54. package/src/ReducerWrapper.js +0 -0
  55. package/src/Request.js +0 -0
  56. package/src/Responder.js +142 -11
  57. package/src/ReturnSender.js +4 -4
  58. package/src/Router.js +0 -0
  59. package/src/RouterWrap.js +0 -0
  60. package/src/SecurityMiddleware.js +0 -0
  61. package/src/Tester.js +44 -2
  62. package/src/analytics/GA4.js +0 -0
  63. package/src/analytics/consts.js +0 -0
  64. package/src/analytics/onInteractionHandler.js +0 -0
  65. package/src/defaultResourceMap.js +0 -0
  66. package/src/features.js +0 -0
  67. package/src/flags.js +0 -0
  68. package/src/fuzzy/factoryFuzzySearch.js +0 -0
  69. package/src/fuzzy/fuzzyUtils.js +0 -0
  70. package/src/fuzzy/index.js +0 -0
  71. package/src/fuzzy/levenshtein.js +0 -0
  72. package/src/fuzzy/normalize.js +0 -0
  73. package/src/fuzzy/prepareFuzzyIndex.js +0 -0
  74. package/src/graphApi/GraphApi.js +0 -0
  75. package/src/graphApi/WingbotApiConnector.js +0 -0
  76. package/src/graphApi/apiAuthorizer.js +0 -0
  77. package/src/graphApi/conversationTestApi.js +0 -0
  78. package/src/graphApi/conversationsApi.js +0 -0
  79. package/src/graphApi/index.js +0 -0
  80. package/src/graphApi/postBackApi.js +0 -0
  81. package/src/graphApi/schema.gql +0 -0
  82. package/src/graphApi/validateBotApi.js +0 -0
  83. package/src/notifications/Notifications.js +0 -0
  84. package/src/notifications/NotificationsStorage.js +0 -0
  85. package/src/notifications/api/index.js +0 -0
  86. package/src/notifications/api/notificationsApiFactory.js +0 -0
  87. package/src/notifications/index.js +0 -0
  88. package/src/resolvers/bounce.js +0 -0
  89. package/src/resolvers/button.js +0 -0
  90. package/src/resolvers/carousel.js +0 -0
  91. package/src/resolvers/contextMessage.js +21 -4
  92. package/src/resolvers/expected.js +0 -0
  93. package/src/resolvers/expectedInput.js +0 -0
  94. package/src/resolvers/hbs.js +0 -0
  95. package/src/resolvers/include.js +0 -0
  96. package/src/resolvers/index.js +0 -0
  97. package/src/resolvers/media.js +0 -0
  98. package/src/resolvers/message.js +54 -4
  99. package/src/resolvers/passThread.js +0 -0
  100. package/src/resolvers/path.js +0 -0
  101. package/src/resolvers/plugin.js +0 -0
  102. package/src/resolvers/postback.js +0 -0
  103. package/src/resolvers/resolverTags.js +0 -0
  104. package/src/resolvers/setState.js +0 -0
  105. package/src/resolvers/skip.js +0 -0
  106. package/src/resolvers/subscribtions.js +0 -0
  107. package/src/resolvers/utils.js +14 -5
  108. package/src/systemEntities/email.js +0 -0
  109. package/src/systemEntities/index.js +0 -0
  110. package/src/systemEntities/phone.js +0 -0
  111. package/src/systemEntities/regexps.js +0 -0
  112. package/src/templates/BaseTemplate.js +0 -0
  113. package/src/templates/ButtonTemplate.js +0 -0
  114. package/src/templates/GenericTemplate.js +0 -0
  115. package/src/templates/ListTemplate.js +0 -0
  116. package/src/templates/ReceiptTemplate.js +0 -0
  117. package/src/testTools/AnyResponseAssert.js +0 -0
  118. package/src/testTools/PromptAssert.js +184 -0
  119. package/src/testTools/ResponseAssert.js +0 -0
  120. package/src/testTools/asserts.js +42 -4
  121. package/src/testTools/index.js +0 -0
  122. package/src/tools/MemoryBotConfigStorage.js +0 -0
  123. package/src/tools/MemoryChatLogStorage.js +0 -0
  124. package/src/tools/MemoryStateStorage.js +0 -0
  125. package/src/tools/bufferloader.js +0 -0
  126. package/src/tools/index.js +0 -0
  127. package/src/tools/routeToEvents.js +0 -0
  128. package/src/transcript/extractText.js +0 -0
  129. package/src/transcript/textBodyFromTranscript.js +0 -0
  130. package/src/transcript/transcriptFromHistory.js +0 -0
  131. package/src/utils/ai.js +0 -0
  132. package/src/utils/compileWithState.js +0 -0
  133. package/src/utils/customCondition.js +14 -1
  134. package/src/utils/customFn.js +0 -0
  135. package/src/utils/datetime.js +0 -0
  136. package/src/utils/deepMapTools.js +0 -0
  137. package/src/utils/generateToken.js +0 -0
  138. package/src/utils/getCondition.js +16 -4
  139. package/src/utils/getUpdate.js +4 -4
  140. package/src/utils/headersToAuditMeta.js +0 -0
  141. package/src/utils/index.js +0 -0
  142. package/src/utils/pathUtils.js +0 -0
  143. package/src/utils/quickReplies.js +0 -0
  144. package/src/utils/slots.js +0 -0
  145. package/src/utils/stateData.js +2 -0
  146. package/src/utils/stateVariables.js +0 -0
  147. package/src/utils/tokenizer.js +0 -0
  148. package/src/utils/wrapPluginFunction.js +0 -0
  149. package/src/wingbot/CachedModel.js +0 -0
  150. package/src/wingbot/CustomEntityDetectionModel.js +0 -0
  151. package/src/wingbot/WingbotModel.js +0 -0
  152. package/src/wingbot/index.js +0 -0
@@ -7,6 +7,9 @@ const assert = require('assert');
7
7
  const deepExtend = require('deep-extend');
8
8
  const { actionMatches, parseActionPayload } = require('../utils');
9
9
 
10
+ /** @typedef {import('../LLM').PromptInfo} PromptInfo */
11
+ /** @typedef {import('../LLM').LLMMessage} LLMMessage */
12
+
10
13
  /**
11
14
  * Format message
12
15
  *
@@ -29,9 +32,21 @@ function m (text, actual = null, expected = null) {
29
32
  return `${text}${result}`;
30
33
  }
31
34
 
32
- function ex (message, expected, actual) {
33
- const actuals = Array.isArray(actual) ? actual : [actual];
34
- return `${message}\n + expected: "${expected}"\n - actual: ${actuals
35
+ function ex (message, expected, actual = null) {
36
+ let actuals;
37
+ if (Array.isArray(actual)) {
38
+ actuals = actual;
39
+ } else {
40
+ actuals = actual === null ? [] : [actual];
41
+ }
42
+
43
+ const msg = `${message}\n + expected: "${expected}"`;
44
+
45
+ if (actuals.length === 0) {
46
+ return msg;
47
+ }
48
+
49
+ return `${msg}\n - actual: ${actuals
35
50
  .map((a) => `"${a}"`).join('\n ')}`;
36
51
  }
37
52
 
@@ -144,6 +159,28 @@ function contains (response, search, message = 'Should contain a text') {
144
159
  return true;
145
160
  }
146
161
 
162
+ /**
163
+ *
164
+ * @param {LLMMessage} llmMsg
165
+ * @param {string} search
166
+ * @param {string|false} message
167
+ */
168
+ function llmContains (llmMsg, search, message = 'Should contain a text') {
169
+ const text = llmMsg.content;
170
+
171
+ const typeIsText = typeof text === 'string';
172
+ if (message === false && !typeIsText) {
173
+ return false;
174
+ }
175
+ assert.ok(typeIsText, m(message, search, 'not a text message'));
176
+ const match = searchMatchesText(search, text);
177
+ if (message === false) {
178
+ return match;
179
+ }
180
+ assert.ok(match, m(message, text, search));
181
+ return true;
182
+ }
183
+
147
184
  /**
148
185
  * Checks quick response action
149
186
  *
@@ -374,5 +411,6 @@ module.exports = {
374
411
  quickReplyText,
375
412
  getText,
376
413
  parseActionPayload,
377
- ex
414
+ ex,
415
+ llmContains
378
416
  };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/src/utils/ai.js CHANGED
File without changes
File without changes
@@ -175,9 +175,22 @@ const compare = (variable, operator, value = undefined) => {
175
175
  }
176
176
  };
177
177
 
178
+ /** @typedef {'if'|'it'|'c'|'nc'|'mr'|'nmr'|'st'|'gt'|'set'|'get'|'eq'|'neq'} ConditionOperator */
179
+
180
+ /**
181
+ * @typedef {object} EditableConditionRule
182
+ * @prop {string} value
183
+ * @prop {ConditionOperator} operator
184
+ * @prop {string} variable
185
+ */
186
+
187
+ /**
188
+ * @typedef {EditableConditionRule[][]} EditableCondition
189
+ */
190
+
178
191
  /**
179
192
  *
180
- * @param {{value:string, operator:string, variable:string}[][]} condition
193
+ * @param {EditableCondition} condition
181
194
  * @param {object} configuration
182
195
  * @param {string} description
183
196
  */
File without changes
File without changes
File without changes
File without changes
@@ -7,11 +7,23 @@ const customCondition = require('./customCondition');
7
7
  const customFn = require('./customFn');
8
8
 
9
9
  /** @typedef {import('../BuildRouter').BotContext} BotContext */
10
+ /** @typedef {import('./customCondition').EditableCondition} EditableCondition */
11
+
12
+ // eslint-disable-next-line max-len
13
+ /** @typedef {Pick<BotContext,'configuration'|'allowForbiddenSnippetWords'|'linksMap'|'ai'>} ConditionContext */
14
+
15
+ /**
16
+ * @typedef {object} ConditionDefinition
17
+ * @prop {boolean} [hasCondition]
18
+ * @prop {string} [conditionFn]
19
+ * @prop {boolean} [hasEditableCondition]
20
+ * @prop {EditableCondition} [editableCondition]
21
+ */
10
22
 
11
23
  /**
12
24
  *
13
- * @param {object} params
14
- * @param {BotContext} context
25
+ * @param {ConditionDefinition} params
26
+ * @param {ConditionContext} context
15
27
  * @param {string} description
16
28
  * @returns {Function}
17
29
  */
@@ -27,7 +39,7 @@ module.exports = function getCondition (params, context, description = '') {
27
39
  editableCondition = []
28
40
  } = params;
29
41
 
30
- let condition = null;
42
+ let condition;
31
43
 
32
44
  if (hasCondition) {
33
45
  if (hasEditableCondition) {
@@ -36,7 +48,7 @@ module.exports = function getCondition (params, context, description = '') {
36
48
  condition = customFn(conditionFn, description, allowForbiddenSnippetWords);
37
49
  }
38
50
  } else {
39
- condition = customFn('(req,res)=>true', description, allowForbiddenSnippetWords);
51
+ condition = () => true;
40
52
  }
41
53
  return condition;
42
54
  };
@@ -88,7 +88,7 @@ function toArray (previousValue) {
88
88
  const ENTITY_HBS_REGEXP = /^\s*\{\{\[?@([^@[\]{}\s]+)(\])?\}\}\s*$/;
89
89
  const VARIABLE_HBS_REGEXP = /^\s*\{\{\[?([^$@[\]{}\s]+)\]?\}\}\s*$/;
90
90
 
91
- function getSetState (setState, req, res = null, useState = null, configuration = null) {
91
+ function getSetState (setState, req, res = null, stateOverride = null, configuration = null) {
92
92
  if (!setState) {
93
93
  return {};
94
94
  }
@@ -96,7 +96,7 @@ function getSetState (setState, req, res = null, useState = null, configuration
96
96
  .filter((k) => k !== '_');
97
97
 
98
98
  let obj = {};
99
- let state = stateData(req, res, configuration, useState);
99
+ let state = stateData(req, res, configuration, stateOverride);
100
100
 
101
101
  keys.forEach((k) => {
102
102
  const val = setState[k];
@@ -166,8 +166,8 @@ function getSetState (setState, req, res = null, useState = null, configuration
166
166
  if (entity && (!rear || req.entities.some((e) => e.entity === entity))) {
167
167
  values = req.entities.filter((e) => e.entity === entity)
168
168
  .map((e) => e.value);
169
- if (values.length === 0 && useState && useState[`@${entity}`]) {
170
- values = [useState[`@${entity}`]];
169
+ if (values.length === 0 && stateOverride && stateOverride[`@${entity}`]) {
170
+ values = [stateOverride[`@${entity}`]];
171
171
  }
172
172
  } else if (variable) {
173
173
  values = toArray(getValue(variable, state));
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -16,6 +16,7 @@ const { dateToISO8601String, zeroHourDate } = require('./datetime');
16
16
  * @prop {object} [configuration]
17
17
  * @prop {Function} text
18
18
  * @prop {Function} [actionData]
19
+ * @prop {Function} [isConfidentInput]
19
20
  */
20
21
 
21
22
  /**
@@ -68,6 +69,7 @@ module.exports = function stateData (
68
69
  $today,
69
70
  $tomorrow,
70
71
  $yesterday,
72
+ $llmResult: res?.llm?.lastResult?.content,
71
73
  // yes - res because of circular dependency
72
74
  ...(res && req && req.actionData()),
73
75
  ...(res ? res.data : {}),
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes