wingbot 3.75.9-alpha.2 → 3.75.9-alpha.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/.claude/settings.local.json +2 -1
- package/jsconfig.json +1 -1
- package/package.json +1 -1
- package/src/ChatGpt.js +2 -1
- package/src/LLMRouter.js +31 -5
- package/src/LLMSession.js +8 -1
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
"Bash(npx mocha:*)",
|
|
5
5
|
"Bash(npx tsc *)",
|
|
6
6
|
"Bash(npm test *)",
|
|
7
|
-
"Bash(node -e \"const p = require\\('./bot/plugins/BTMLLM'\\); console.log\\('factory type:', typeof p\\); console.log\\('factory name:', p.name\\);\")"
|
|
7
|
+
"Bash(node -e \"const p = require\\('./bot/plugins/BTMLLM'\\); console.log\\('factory type:', typeof p\\); console.log\\('factory name:', p.name\\);\")",
|
|
8
|
+
"Bash(grep -n \"prompt\\\\`\\\\|tagged\\\\|render\\\\|compile\\\\|hbs\" /Users/ondrejveres/Wingbot/wingbot-llm/src/prompt.js)"
|
|
8
9
|
]
|
|
9
10
|
}
|
|
10
11
|
}
|
package/jsconfig.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"module": "commonjs",
|
|
4
|
-
"lib": ["es2019", "es2020.promise", "es2020.bigint", "es2020.string", "dom"],
|
|
4
|
+
"lib": ["es2019", "es2020.promise", "es2020.bigint", "es2020.string", "es2022.error", "dom"],
|
|
5
5
|
"target": "ESNext",
|
|
6
6
|
"allowSyntheticDefaultImports": true,
|
|
7
7
|
"checkJs": true,
|
package/package.json
CHANGED
package/src/ChatGpt.js
CHANGED
package/src/LLMRouter.js
CHANGED
|
@@ -143,7 +143,7 @@ class LLMRouter {
|
|
|
143
143
|
.object({
|
|
144
144
|
action: LLMType.string()
|
|
145
145
|
.description('recommended action')
|
|
146
|
-
}, '
|
|
146
|
+
}, 'conversation_routing_information')
|
|
147
147
|
.toJSON();
|
|
148
148
|
}
|
|
149
149
|
return LLMRouter._cachedStructuredOutput;
|
|
@@ -159,12 +159,34 @@ class LLMRouter {
|
|
|
159
159
|
static defaultRoute (prompt) {
|
|
160
160
|
/** @type {RouterResolver} */
|
|
161
161
|
const route = async (llm, req, routing) => {
|
|
162
|
-
const
|
|
162
|
+
const session = llm.session('routing')
|
|
163
163
|
.setData(routing)
|
|
164
|
-
.systemPrompt(prompt)
|
|
165
|
-
.generateStructured(LLMRouter.structuredOutput());
|
|
164
|
+
.systemPrompt(prompt);
|
|
166
165
|
|
|
167
|
-
|
|
166
|
+
const userText = typeof req?.text === 'function' ? req.text() : null;
|
|
167
|
+
if (userText) {
|
|
168
|
+
session.user(userText);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
let res;
|
|
172
|
+
try {
|
|
173
|
+
res = await session.generateStructured(LLMRouter.structuredOutput());
|
|
174
|
+
} catch (e) {
|
|
175
|
+
// Fail closed: any error in routing classification is treated
|
|
176
|
+
// as "no context change" so the user's current flow continues.
|
|
177
|
+
// Surfaces to Sentry via the host-configured logger.
|
|
178
|
+
llm.log?.error('LLMRouter classification failed', e, {
|
|
179
|
+
// userText,
|
|
180
|
+
candidateActions: routing?.byAction
|
|
181
|
+
? Array.from(routing.byAction.keys())
|
|
182
|
+
: [],
|
|
183
|
+
senderId: req?.senderId ?? null,
|
|
184
|
+
pageId: req?.pageId ?? null
|
|
185
|
+
});
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (!res || !routing.byAction.has(LLMRouter._normByAction(res.action))) {
|
|
168
190
|
return null;
|
|
169
191
|
}
|
|
170
192
|
|
|
@@ -226,6 +248,10 @@ class LLMRouter {
|
|
|
226
248
|
});
|
|
227
249
|
}
|
|
228
250
|
|
|
251
|
+
/**
|
|
252
|
+
* @param {string} act
|
|
253
|
+
* @returns {string}
|
|
254
|
+
*/
|
|
229
255
|
static _normByAction (act) {
|
|
230
256
|
return act.replace(/^\/|\/$/g, '');
|
|
231
257
|
}
|
package/src/LLMSession.js
CHANGED
|
@@ -842,7 +842,14 @@ class LLMSession {
|
|
|
842
842
|
responseFormat
|
|
843
843
|
}, logOptions);
|
|
844
844
|
|
|
845
|
-
|
|
845
|
+
try {
|
|
846
|
+
return JSON.parse(result.content);
|
|
847
|
+
} catch (e) {
|
|
848
|
+
throw new Error(
|
|
849
|
+
`LLM structured output is not valid JSON: ${e.message}. Raw content: ${JSON.stringify(result.content)}`,
|
|
850
|
+
{ cause: e }
|
|
851
|
+
);
|
|
852
|
+
}
|
|
846
853
|
});
|
|
847
854
|
return this;
|
|
848
855
|
}
|