wingbot 3.73.3 → 3.73.5

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.73.3",
3
+ "version": "3.73.5",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -127,6 +127,13 @@ const DUMMY_ROUTE = { id: 0, path: null, resolvers: [] };
127
127
  * @returns {string}
128
128
  */
129
129
 
130
+ /**
131
+ * @typedef {object} ILogger
132
+ * @prop {Function} log
133
+ * @prop {Function} warn
134
+ * @prop {Function} error
135
+ */
136
+
130
137
  /**
131
138
  * @template {BaseConfiguration} [C=object]
132
139
  * @typedef {object} BuildRouterContext
@@ -135,6 +142,8 @@ const DUMMY_ROUTE = { id: 0, path: null, resolvers: [] };
135
142
  * @prop {boolean} [allowForbiddenSnippetWords] - disable security rule
136
143
  * @prop {Middleware} [defaultPlugin] - to be able to test configurations without plugins
137
144
  * @prop {RouteConfig[]} [routeConfigs] - list of disabled routes
145
+ * @prop {boolean|keyof ILogger} [canaryLogs]
146
+ * @prop {ILogger} [log]
138
147
  * @prop {C} [configuration] - context data
139
148
  */
140
149
 
package/src/LLM.js CHANGED
@@ -103,6 +103,7 @@ const Ai = require('./Ai');
103
103
  * @prop {boolean} [transcriptAnonymize]
104
104
  * @prop {Persona|string|null} [persona]
105
105
  * @prop {LLMLogger} [logger]
106
+ * @prop {boolean} [disableLLM]
106
107
  */
107
108
 
108
109
  /**
@@ -219,6 +220,14 @@ class LLM {
219
220
  return this._configuration;
220
221
  }
221
222
 
223
+ /**
224
+ *
225
+ * @param {Partial<LLMConfiguration>} override
226
+ */
227
+ setSessionConfig (override) {
228
+ Object.assign(this._configuration, override);
229
+ }
230
+
222
231
  /**
223
232
  *
224
233
  * @param {Transcript[]} chat
package/src/Plugins.js CHANGED
@@ -131,9 +131,22 @@ class Plugins {
131
131
  name,
132
132
  paramsData = {},
133
133
  items = new Map(),
134
- context = { isLastIndex: true, configuration: {} }
134
+ context = {}
135
135
  ) {
136
136
  let useItems = items;
137
+ const {
138
+ isLastIndex = true,
139
+ configuration = {},
140
+ router = new Router(),
141
+ ...rest
142
+ } = context;
143
+
144
+ const ctx = {
145
+ isLastIndex,
146
+ configuration,
147
+ router,
148
+ ...rest
149
+ };
137
150
 
138
151
  if (!(items instanceof Map)) {
139
152
  // @ts-ignore
@@ -156,15 +169,15 @@ class Plugins {
156
169
  );
157
170
  }
158
171
 
159
- const cleanParams = Object.entries(paramsData)
160
- .filter(([, e]) => e !== null && e !== undefined)
161
- .map(([k, e]) => ({ [k]: e }))
162
- .reduce(Object.assign, {});
172
+ const cleanParams = Object.fromEntries(
173
+ Object.entries(paramsData)
174
+ .filter(([, e]) => e !== null && e !== undefined)
175
+ );
163
176
 
164
177
  const customFn = this.getPluginFactory(
165
178
  name,
166
179
  cleanParams,
167
- context.configuration,
180
+ configuration,
168
181
  context.defaultPlugin
169
182
  );
170
183
 
@@ -174,9 +187,7 @@ class Plugins {
174
187
  return new RouterWrap(customFn, useItems, cleanParams);
175
188
  }
176
189
 
177
- const { router = new Router() } = context;
178
-
179
- return wrapPluginFunction(customFn, cleanParams, useItems, context, router);
190
+ return wrapPluginFunction(customFn, cleanParams, useItems, ctx, router);
180
191
  }
181
192
 
182
193
  code (name, factoryFn = null) {
package/src/Tester.js CHANGED
@@ -651,8 +651,13 @@ class Tester {
651
651
  debug (full = false, showPrivateKeys = false) {
652
652
  // eslint-disable-next-line no-console
653
653
  console.log(
654
- '\n===== actions =====\n',
655
- this._actionsDebug(true),
654
+ '\n====== state ======\n',
655
+ Object.fromEntries(
656
+ Object.entries(this.getState().state)
657
+ .filter((e) => showPrivateKeys || !e[0].startsWith('_'))
658
+ ),
659
+ '\n------- LLM -------\n',
660
+ ...PromptAssert.debug(this.prompts, full, true),
656
661
  '\n---- responses ----\n',
657
662
  inspect(
658
663
  this.responses.map(({ messaging_type: m, recipient, ...o }) => o),
@@ -660,13 +665,8 @@ class Tester {
660
665
  null,
661
666
  true
662
667
  ),
663
- '\n------ state ------\n',
664
- Object.fromEntries(
665
- Object.entries(this.getState().state)
666
- .filter((e) => showPrivateKeys || !e[0].startsWith('_'))
667
- ),
668
- '\n------- LLM -------\n',
669
- ...PromptAssert.debug(this.prompts, full, true),
668
+ '\n----- actions -----\n',
669
+ this._actionsDebug(true),
670
670
  '\n===================\n'
671
671
  );
672
672
  }
@@ -21,6 +21,7 @@ const {
21
21
  } = require('../features');
22
22
  const { vars, VAR_TYPES } = require('../utils/stateVariables');
23
23
  const LLM = require('../LLM');
24
+ const canaryLog = require('../utils/canaryLog');
24
25
 
25
26
  /** @typedef {import('../Responder').VoiceControl} VoiceControl */
26
27
  /** @typedef {import('../BuildRouter').LinksMap} LinksMap */
@@ -445,7 +446,7 @@ function message (params, context = {}) {
445
446
  };
446
447
  }
447
448
 
448
- if (params.type === 'prompt') {
449
+ if (params.type === 'prompt' && !res.llm.configuration.disableLLM) {
449
450
  res.typingOn()
450
451
  .wait(1000);
451
452
  const session = await res.llmSessionWithHistory(params.llmContextType);
@@ -456,6 +457,10 @@ function message (params, context = {}) {
456
457
  const evaluation = await res.llmEvaluate(session, params.llmContextType);
457
458
 
458
459
  if (evaluation.discard) {
460
+ canaryLog(context.log, context.canaryLogs, 'LLM discarded', {
461
+ evaluation,
462
+ session
463
+ });
459
464
  if (isLastMessage && !req.actionData()._resolverTag) {
460
465
  res.finalMessageSent = true;
461
466
  }
@@ -13,6 +13,8 @@
13
13
  /**
14
14
  * @typedef {object} StateCondition
15
15
  * @prop {string} [search]
16
+ * @prop {string[]} [senderIds]
17
+ * @prop {string} [pageId]
16
18
  */
17
19
 
18
20
  /**
@@ -114,13 +116,22 @@ class MemoryStateStorage {
114
116
  // const matches = conditionKeys
115
117
  // .every(k => state[k] === condition[k]);
116
118
 
117
- const matches = !condition.search
118
- || condition.search === state.senderId;
119
+ let matches = true;
119
120
 
120
- if (!matches) {
121
- return false;
121
+ if (condition.search) {
122
+ matches = matches && condition.search === state.senderId;
123
+ }
124
+
125
+ if (Array.isArray(condition.senderIds)) {
126
+ matches = matches && condition.senderIds.includes(state.senderId);
122
127
  }
123
128
 
129
+ if (typeof condition.pageId === 'string') {
130
+ matches = matches && condition.pageId === state.pageId;
131
+ }
132
+
133
+ if (!matches) return false;
134
+
124
135
  if (limit !== null && filtered >= limit) {
125
136
  hasNext = true;
126
137
  return false;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @author David Menger
3
+ */
4
+ 'use strict';
5
+
6
+ /**
7
+ * @typedef {object} ILogger
8
+ * @prop {Function} log
9
+ * @prop {Function} warn
10
+ * @prop {Function} error
11
+ */
12
+
13
+ /**
14
+ *
15
+ * @param {ILogger} logger
16
+ * @param {boolean|keyof ILogger} setting
17
+ * @param {string} message
18
+ * @param {...*} args
19
+ * @returns {void}
20
+ */
21
+ function canaryLog (logger, setting, message, ...args) {
22
+ if (setting) {
23
+ const key = typeof setting === 'boolean'
24
+ ? 'error'
25
+ : setting;
26
+ (logger || console)[key](`#CANARY: ${message}`, ...args);
27
+ }
28
+ }
29
+
30
+ module.exports = canaryLog;