wingbot 3.76.4-alpha.3 → 3.76.4-alpha.4

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.4-alpha.3",
3
+ "version": "3.76.4-alpha.4",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -260,6 +260,7 @@ class LLMDispatcher {
260
260
  ...routing,
261
261
  actionList: [],
262
262
  actionListString: '',
263
+ structuredOutput: LLMRouter.structuredOutput(),
263
264
  byAction: new Map(),
264
265
  router
265
266
  };
package/src/LLMRouter.js CHANGED
@@ -66,7 +66,8 @@ const LLMType = require('./LLMType');
66
66
  */
67
67
 
68
68
  /**
69
- * @typedef {Pick<LLMRoutingCache, 'actionList'|'actionListString'|'byAction'>} LLMRoutingInput
69
+ * @typedef {Pick<LLMRoutingCache,
70
+ * 'actionList'|'actionListString'|'byAction'|'structuredOutput'>} LLMRoutingInput
70
71
  */
71
72
 
72
73
  /**
@@ -74,6 +75,7 @@ const LLMType = require('./LLMType');
74
75
  * @prop {boolean} [keepUserInInteractionsWithBounceAllowed]
75
76
  * @prop {string} actionListString
76
77
  * @prop {LLMAction[]} actionList
78
+ * @prop {object} structuredOutput - JSON schema for the routing response
77
79
  * @prop {ILLMRouter|null} router
78
80
  * @prop {Map<string, GlobalIntentResolved>} byAction
79
81
  * @prop {GlobalIntentResolved[]} routes
@@ -142,24 +144,31 @@ class LLMRouter {
142
144
  }
143
145
 
144
146
  /**
145
- * @type {object}
147
+ * Sentinel action returned when the user did not change the conversation
148
+ * context (or when the model can't decide). Not present in `byAction`.
149
+ *
150
+ * @type {string}
146
151
  */
147
- static _cachedStructuredOutput = null;
152
+ static NOT_CHANGED = '-not-changed-';
148
153
 
149
154
  /**
155
+ * Builds the JSON schema for the routing response. The `action` field is
156
+ * constrained to an enum of the routable actions plus the `-not-changed-`
157
+ * sentinel, so the model can only return a valid routing target.
158
+ *
159
+ * Called once per router config from `_prepareRoutingInput`; the result is
160
+ * stored on the routing cache, so it is not rebuilt per request.
150
161
  *
162
+ * @param {string[]} [actions] - routable action values (e.g. `/btm/dodavatel`)
151
163
  * @returns {object}
152
164
  */
153
- static structuredOutput () {
154
- if (LLMRouter._cachedStructuredOutput === null) {
155
- LLMRouter._cachedStructuredOutput = LLMType
156
- .object({
157
- action: LLMType.string()
158
- .description('recommended action')
159
- }, 'conversation_routing_information')
160
- .toJSON();
161
- }
162
- return LLMRouter._cachedStructuredOutput;
165
+ static structuredOutput (actions = []) {
166
+ return LLMType
167
+ .object({
168
+ action: LLMType.enum([LLMRouter.NOT_CHANGED, ...actions])
169
+ .description('recommended action')
170
+ }, 'conversation_routing_information')
171
+ .toJSON();
163
172
  }
164
173
 
165
174
  /**
@@ -183,7 +192,7 @@ class LLMRouter {
183
192
 
184
193
  let res;
185
194
  try {
186
- res = await session.generateStructured(LLMRouter.structuredOutput());
195
+ res = await session.generateStructured(routing.structuredOutput);
187
196
  } catch (e) {
188
197
  // Fail closed: any error in routing classification is treated
189
198
  // as "no context change" so the user's current flow continues.
@@ -315,6 +324,7 @@ class LLMRouter {
315
324
  : {}),
316
325
  actionListString,
317
326
  actionList,
327
+ structuredOutput: LLMRouter.structuredOutput(actionList.map((a) => a.action)),
318
328
  byAction,
319
329
  router,
320
330
  routes: resolvedLlm
@@ -367,6 +377,7 @@ class LLMRouter {
367
377
  : {
368
378
  actionListString: '',
369
379
  actionList: [],
380
+ structuredOutput: LLMRouter.structuredOutput(),
370
381
  byAction: new Map(),
371
382
  router: null,
372
383
  routes: []