wingbot 3.72.1 → 3.73.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 (153) hide show
  1. package/.babelrc +0 -0
  2. package/.github/workflows/deploy.yml +0 -0
  3. package/.github/workflows/pullRequest.yml +0 -0
  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 +2 -4
  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 +0 -0
  39. package/src/AiMatching.js +0 -0
  40. package/src/BatchConversationTester.js +0 -0
  41. package/src/BotApp.js +0 -0
  42. package/src/BotAppSender.js +4 -6
  43. package/src/BuildRouter.js +0 -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 +19 -3
  48. package/src/LLMMockProvider.js +0 -0
  49. package/src/LLMSession.js +0 -0
  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 -0
  54. package/src/ReducerWrapper.js +0 -0
  55. package/src/Request.js +0 -0
  56. package/src/Responder.js +0 -0
  57. package/src/ReturnSender.js +0 -0
  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 +0 -0
  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 +1 -34
  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 +1 -1
  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 +0 -0
  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 +0 -0
  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 +0 -0
  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 +22 -0
  119. package/src/testTools/ResponseAssert.js +0 -0
  120. package/src/testTools/asserts.js +0 -0
  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 +0 -0
  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 +0 -0
  139. package/src/utils/getUpdate.js +0 -0
  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 +0 -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
  153. package/src/graphApi/gqlRules.js +0 -87
package/.babelrc CHANGED
File without changes
File without changes
File without changes
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
File without changes
package/index.js CHANGED
File without changes
package/jsconfig.json CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot",
3
- "version": "3.72.1",
3
+ "version": "3.73.0",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -58,9 +58,7 @@
58
58
  "compress-json": "^3.0.0",
59
59
  "deep-extend": "^0.6.0",
60
60
  "form-data": "^4.0.0",
61
- "graphql": "^16.11.0",
62
- "graphql-depth-limit": "^1.1.0",
63
- "graphql-query-complexity": "^1.1.0",
61
+ "graphql": "^16.8.1",
64
62
  "jsonwebtoken": "^9.0.2",
65
63
  "node-fetch": "^2.6.7",
66
64
  "path-to-regexp": "^6.3.0",
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
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
File without changes
File without changes
package/plugins/index.js CHANGED
File without changes
File without changes
package/src/Ai.js CHANGED
File without changes
package/src/AiMatching.js CHANGED
File without changes
File without changes
package/src/BotApp.js CHANGED
File without changes
@@ -41,12 +41,12 @@ class BotAppSender extends ReturnSender {
41
41
  /**
42
42
  *
43
43
  * @param {SenderOptions} options
44
- * @param {string} senderId
44
+ * @param {string} userId
45
45
  * @param {object} incommingMessage
46
46
  * @param {ChatLogStorage} logger - console like logger
47
47
  */
48
- constructor (options, senderId, incommingMessage, logger = null) {
49
- super(options, senderId, incommingMessage, logger);
48
+ constructor (options, userId, incommingMessage, logger = null) {
49
+ super(options, userId, incommingMessage, logger);
50
50
 
51
51
  this.waits = true;
52
52
 
@@ -98,16 +98,14 @@ class BotAppSender extends ReturnSender {
98
98
  * @param {Buffer} data
99
99
  * @param {string} contentType
100
100
  * @param {string} fileName
101
- * @param {string} [senderId]
102
101
  * @returns {Promise<UploadResult>}
103
102
  */
104
- async upload (data, contentType, fileName, senderId = this._senderId) {
103
+ async upload (data, contentType, fileName) {
105
104
  const formData = new FormData();
106
105
 
107
106
  const nonce = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(36).padEnd(11, '0');
108
107
 
109
108
  formData.append('nonce', nonce);
110
- formData.append('senderId', senderId || '');
111
109
  formData.append('f0', data, { filename: fileName, contentType });
112
110
 
113
111
  const [token, agent] = await Promise.all([
File without changes
File without changes
package/src/ChatGpt.js CHANGED
File without changes
File without changes
package/src/LLM.js CHANGED
@@ -110,6 +110,7 @@ const Ai = require('./Ai');
110
110
  * @typedef {object} PromptInfo
111
111
  * @prop {LLMMessage[]} prompt
112
112
  * @prop {LLMMessage} result
113
+ * @prop {VectorSearchResult} [vectorSearchResult]
113
114
  */
114
115
 
115
116
  /**
@@ -122,6 +123,20 @@ const Ai = require('./Ai');
122
123
  * @prop {LogPrompt} logPrompt
123
124
  */
124
125
 
126
+ /**
127
+ * @typedef {object} VectorSearchDocument
128
+ * @property {string} id
129
+ * @property {string} name
130
+ * @property {string} text
131
+ * @property {number} cosineDistance
132
+ * @property {boolean} excludedByCosineDistanceThreshold
133
+ */
134
+ /**
135
+ * @typedef {object} VectorSearchResult
136
+ * @property {number} maximalCosineDistanceThreshold
137
+ * @property {number} nearestNeighbourCount
138
+ * @property {VectorSearchDocument[]} resultDocuments
139
+ */
125
140
  /**
126
141
  * @class LLM
127
142
  */
@@ -233,7 +248,7 @@ class LLM {
233
248
 
234
249
  const prompt = session.toArray(true);
235
250
  const result = await this._provider.requestChat(prompt, opts);
236
- this._logPrompt(prompt, result);
251
+ this.logPrompt(prompt, result);
237
252
  return result;
238
253
  }
239
254
 
@@ -241,11 +256,12 @@ class LLM {
241
256
  *
242
257
  * @param {LLMMessage[]} prompt
243
258
  * @param {LLMMessage} result
259
+ * @param {VectorSearchResult} [vectorSearchResult]
244
260
  */
245
- _logPrompt (prompt, result) {
261
+ logPrompt (prompt, result, vectorSearchResult) {
246
262
  this._lastResult = result;
247
263
  this._configuration.logger.logPrompt({
248
- prompt, result
264
+ prompt, result, vectorSearchResult
249
265
  });
250
266
  }
251
267
 
File without changes
package/src/LLMSession.js CHANGED
File without changes
File without changes
File without changes
package/src/Plugins.js CHANGED
File without changes
package/src/Processor.js CHANGED
@@ -405,6 +405,7 @@ class Processor extends EventEmitter {
405
405
  return { status: 304 };
406
406
  }
407
407
 
408
+ /** @type {LLMConfiguration} */
408
409
  const llmOptions = {
409
410
  provider: new LLMMockProvider(),
410
411
  ...this.options.llm
File without changes
package/src/Request.js CHANGED
File without changes
package/src/Responder.js CHANGED
File without changes
File without changes
package/src/Router.js CHANGED
File without changes
package/src/RouterWrap.js CHANGED
File without changes
File without changes
package/src/Tester.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
package/src/features.js CHANGED
File without changes
package/src/flags.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -8,7 +8,6 @@ const WingbotApiConnector = require('./WingbotApiConnector');
8
8
  // @ts-ignore
9
9
  const packageJson = require('../../package.json');
10
10
  const headersToAuditMeta = require('../utils/headersToAuditMeta');
11
- const gqlRules = require('./gqlRules');
12
11
 
13
12
  const DEFAULT_GROUPS = ['botEditor', 'botAdmin', 'appToken'];
14
13
  const KEYS_URL = 'https://api.wingbot.ai/keys';
@@ -28,15 +27,6 @@ const DEFAULT_CACHE = 86400000; // 24 hours
28
27
  /** @typedef {import('../CallbackAuditLog')} AuditLog */
29
28
  /** @typedef {import('graphql')} GqlLib */
30
29
 
31
- /**
32
- * @typedef {object} Logger
33
- * @prop {Function} log
34
- * @prop {Function} error
35
- */
36
-
37
- /**
38
- * Experimental chatbot API
39
- */
40
30
  class GraphApi {
41
31
 
42
32
  /**
@@ -48,11 +38,8 @@ class GraphApi {
48
38
  * @param {string[]} [options.groups] - list of allowed bot groups
49
39
  * @param {boolean} [options.useBundledGql] - uses library bundled graphql definition
50
40
  * @param {AuditLog} [options.auditLog]
51
- * @param {boolean} [options.isProduction]
52
- * @param {boolean} [options.hideVerboseErrors]
53
- * @param {Logger} [log=console]
54
41
  */
55
- constructor (apis, options, log = console) {
42
+ constructor (apis, options) {
56
43
  this._root = {
57
44
  version () {
58
45
  return packageJson.version;
@@ -75,13 +62,6 @@ class GraphApi {
75
62
  }
76
63
  };
77
64
 
78
- this._log = log;
79
- this._options = {
80
- hideVerboseErrors: true,
81
- isProduction: true,
82
- ...options
83
- };
84
-
85
65
  Object.assign(opts, options);
86
66
 
87
67
  apis.forEach((api) => Object.assign(this._root, api));
@@ -169,19 +149,6 @@ class GraphApi {
169
149
 
170
150
  const schema = await this._schema();
171
151
 
172
- const { isProduction = true, hideVerboseErrors } = this._options;
173
- const ast = this._gql.parse(body.query);
174
- const errors = this._gql.validate(
175
- schema,
176
- ast,
177
- gqlRules(body.variables, isProduction, hideVerboseErrors, this._log)
178
- );
179
-
180
- if (errors.length > 0) {
181
- this._log.error('GQL failed', errors);
182
- return { errors };
183
- }
184
-
185
152
  const ctx = {
186
153
  token,
187
154
  groups: this._defaultGroups,
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -355,4 +355,4 @@ type Mutation {
355
355
 
356
356
  "subscribe with metadata"
357
357
  subscribeWithData (subscriptions: [SubscriptionData!]!): Boolean
358
- }
358
+ }
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
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
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -59,6 +59,18 @@ class PromptAssert {
59
59
  return this;
60
60
  }
61
61
 
62
+ /**
63
+ * Check if vector search documents contain selected string
64
+ *
65
+ * @param {string} search
66
+ * @returns {this}
67
+ */
68
+ vectorSearchContains (search) {
69
+ const documents = this._flatVectorSearchDocuments();
70
+ this._promptContains(search, documents, false, 'in vector search documents');
71
+ return this;
72
+ }
73
+
62
74
  /**
63
75
  *
64
76
  * @param {(value: LLMMessage, index: number, array: LLMMessage[]) => unknown} filter
@@ -79,6 +91,16 @@ class PromptAssert {
79
91
  .map((prompt) => prompt.result);
80
92
  }
81
93
 
94
+ /**
95
+ *
96
+ * @returns {LLMMessage[]}
97
+ */
98
+ _flatVectorSearchDocuments () {
99
+ return this._prompts
100
+ .flatMap((prompt) => prompt.vectorSearchResult?.resultDocuments || [])
101
+ .map((doc) => ({ role: 'system', content: doc.text }));
102
+ }
103
+
82
104
  _promptContains (search, messages, notContains = false, addMessage = 'No LLM message found') {
83
105
  if (messages.length === 0) {
84
106
  PromptAssert.debug(this._prompts, true);
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
File without changes
File without changes
package/src/utils/ai.js CHANGED
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
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
File without changes
File without changes
@@ -1,87 +0,0 @@
1
- /* eslint-disable global-require */
2
- /**
3
- * @author David Menger
4
- */
5
- 'use strict';
6
-
7
- /** @typedef {import('graphql').ValidationRule} ValidationRule */
8
-
9
- /**
10
- * @typedef {object} Logger
11
- * @prop {Function} log
12
- * @prop {Function} error
13
- */
14
-
15
- /**
16
- *
17
- * @param {object} variables
18
- * @param {boolean} isProduction
19
- * @param {boolean} hideVerboseErrors
20
- * @param {Logger} [log=console]
21
- * @returns {ValidationRule[]}
22
- */
23
- function gqlRules (variables, isProduction, hideVerboseErrors, log = console) {
24
- // OPTIMIZATION FOR LAMBDA PERFORMANCE
25
- const { GraphQLError, NoSchemaIntrospectionCustomRule } = require('graphql');
26
- const { createComplexityRule, simpleEstimator } = require('graphql-query-complexity');
27
- const depthLimit = require('graphql-depth-limit');
28
-
29
- return [
30
- ...(hideVerboseErrors ? [NoSchemaIntrospectionCustomRule] : []),
31
- depthLimit(10),
32
- createComplexityRule({
33
- // The maximum allowed query complexity, queries above this threshold will be rejected
34
- maximumComplexity: 1000,
35
-
36
- // The query variables. This is needed because the variables are not available
37
- // in the visitor of the graphql-js library
38
- variables,
39
-
40
- // The context object for the request (optional)
41
- context: {},
42
-
43
- // The maximum number of query nodes to evaluate (fields, fragments, composite types).
44
- // If a query contains more than the specified number of nodes, the complexity rule will
45
- // throw an error, regardless of the complexity of the query.
46
- //
47
- // Default: 10_000
48
- maxQueryNodes: 10000,
49
-
50
- // Optional callback function to retrieve the determined query complexity
51
- // Will be invoked whether the query is rejected or not
52
- // This can be used for logging or to implement rate limiting
53
- onComplete: (complexity) => {
54
- if (!isProduction) {
55
- log.log('Determined query complexity: ', complexity);
56
- }
57
- },
58
-
59
- // Optional function to create a custom error
60
- createError: (max, actual) => {
61
- const msg = `GQL Query too complex: ${actual}. Maximum allowed: ${max}`;
62
-
63
- if (hideVerboseErrors) {
64
- log.error(msg);
65
- return new GraphQLError('');
66
- }
67
- log.log(msg);
68
- return new GraphQLError(`Query is too complex: ${actual}. Maximum allowed complexity: ${max}`);
69
- },
70
-
71
- // Add any number of estimators. The estimators are invoked in order, the first
72
- // numeric value that is being returned by an estimator is used as the field complexity.
73
- // If no estimator returns a value, an exception is raised.
74
- estimators: [
75
- // Add more estimators here...
76
-
77
- // This will assign each field a complexity of 1 if no other estimator
78
- // returned a value.
79
- simpleEstimator({
80
- defaultComplexity: 1
81
- })
82
- ]
83
- })
84
- ];
85
- }
86
-
87
- module.exports = gqlRules;