wingbot 3.70.1 → 3.70.3

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.70.1",
3
+ "version": "3.70.3",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -138,6 +138,11 @@ const DUMMY_ROUTE = { id: 0, path: null, resolvers: [] };
138
138
  * @prop {C} [configuration] - context data
139
139
  */
140
140
 
141
+ /**
142
+ * @callback NestedLinksMapFactory
143
+ * @returns {LinksMap}
144
+ */
145
+
141
146
  /**
142
147
  * @typedef {object} BotContextExtention
143
148
  * @prop {BlockMap} [nestedBlocksByStaticId]
@@ -155,6 +160,7 @@ const DUMMY_ROUTE = { id: 0, path: null, resolvers: [] };
155
160
  * @prop {boolean} [isRoot]
156
161
  * @prop {string} [staticBlockId]
157
162
  * @prop {Block[]} [blocks]
163
+ * @prop {NestedLinksMapFactory} [nestedLinksMapFactory]
158
164
  * @prop {object} [BuildRouter]
159
165
  * @prop {string|number} [resolverId] - only for text messages with random characters
160
166
  */
@@ -226,6 +232,9 @@ class BuildRouter extends Router {
226
232
  /** @type {LinksMap} */
227
233
  this._linksMap = new Map();
228
234
 
235
+ /** @type {LinksMap} */
236
+ this._nestedLinksMap = null;
237
+
229
238
  this._loadBotUrl = null;
230
239
 
231
240
  this._loadBotAuthorization = null;
@@ -512,7 +521,10 @@ class BuildRouter extends Router {
512
521
  buildWithSnapshot (blocks, setConfigTimestamp = Number.MAX_SAFE_INTEGER, lastmod = '-') {
513
522
  this._validateBlocks(blocks);
514
523
 
515
- Object.assign(this._resolvedContext, { blocks });
524
+ Object.assign(this._resolvedContext, {
525
+ blocks,
526
+ nestedBlocksByStaticId: null
527
+ });
516
528
 
517
529
  const rootBlock = blocks.find((block) => block.isRoot);
518
530
 
@@ -573,6 +585,7 @@ class BuildRouter extends Router {
573
585
  const [linksMap, nestedBlocksByStaticId] = this._createLinksMap(block);
574
586
  // @ts-ignore
575
587
  this._linksMap = linksMap;
588
+ this._nestedLinksMap = null;
576
589
 
577
590
  // @ts-ignore
578
591
  this._buildRoutes(block.routes, nestedBlocksByStaticId);
@@ -583,6 +596,20 @@ class BuildRouter extends Router {
583
596
  this.emit('rebuild');
584
597
  }
585
598
 
599
+ _getNestedLinksMap () {
600
+ if (!this._nestedLinksMap) {
601
+ /** @type {LinksMap} */
602
+ const linksMap = new Map();
603
+
604
+ for (const [from, to] of this._linksMap.entries()) {
605
+ linksMap.set(from, `../${to}`); // this._joinPaths('..', to)
606
+ }
607
+
608
+ this._nestedLinksMap = linksMap;
609
+ }
610
+ return this._nestedLinksMap;
611
+ }
612
+
586
613
  /**
587
614
  *
588
615
  * returns {[LinksMap, BlockMap]}
@@ -590,12 +617,18 @@ class BuildRouter extends Router {
590
617
  * @param {Block} block
591
618
  */
592
619
  _createLinksMap (block) {
593
- const { linksMap: prevLinksMap, blocks = [] } = this._resolvedContext;
620
+ const {
621
+ linksMap: prevLinksMap,
622
+ blocks = [],
623
+ nestedLinksMapFactory
624
+ } = this._resolvedContext;
594
625
 
595
626
  /** @type {LinksMap} */
596
- const linksMap = new Map();
627
+ const linksMap = nestedLinksMapFactory
628
+ ? new Map(nestedLinksMapFactory())
629
+ : new Map();
597
630
 
598
- if (prevLinksMap) {
631
+ if (prevLinksMap && !nestedLinksMapFactory) {
599
632
  for (const [from, to] of prevLinksMap.entries()) {
600
633
  linksMap.set(from, `../${to}`); // this._joinPaths('..', to)
601
634
  }
@@ -900,6 +933,7 @@ class BuildRouter extends Router {
900
933
  isLastMessage: lastMessageIndex === i && !buildInfo.notLastMessage,
901
934
  router: this,
902
935
  linksMap: this._linksMap,
936
+ nestedLinksMapFactory: this._getNestedLinksMap.bind(this),
903
937
  path: ctxPath,
904
938
  isFallback,
905
939
  isResponder,
package/src/ChatGpt.js CHANGED
@@ -180,10 +180,10 @@ class ChatGpt {
180
180
  /** @type {Required<DefaultRequestOptions>} */
181
181
  this._options = {
182
182
  requestTokens: 256,
183
- tokensLimit: 4096,
183
+ tokensLimit: 128000,
184
184
  presencePenalty: 0.0, // -2.0-2.0
185
185
  temperature: 1.0,
186
- model: 'gpt-3.5-turbo',
186
+ model: 'gpt-4o-mini',
187
187
  transcriptLength: -5,
188
188
  ...rest
189
189
  };
@@ -278,7 +278,6 @@ class ChatGpt {
278
278
  };
279
279
 
280
280
  let messages = chat;
281
- const maxTokens = Math.min(requestTokens, tokensLimit);
282
281
 
283
282
  let body;
284
283
  try {
@@ -309,7 +308,7 @@ class ChatGpt {
309
308
  model,
310
309
  frequency_penalty: 0,
311
310
  presence_penalty: presencePenalty,
312
- max_tokens: maxTokens,
311
+ max_tokens: requestTokens,
313
312
  temperature,
314
313
  messages
315
314
  };
package/src/LLM.js CHANGED
@@ -141,8 +141,9 @@ class LLM {
141
141
  static toMessages (result) {
142
142
  let filtered = result.content
143
143
  .replace(/\n\n+/g, '\n')
144
- .split(/\n+(?!-)/g)
145
- .map((t) => t.trim())
144
+ .split(/\n+(?!\s*-)/g)
145
+ .map((t) => t.replace(/\n\s+/g, '\n')
146
+ .trim())
146
147
  .filter((t) => !!t);
147
148
 
148
149
  if (result.finishReason === 'length' && filtered.length <= 0) {