Update AI response parsing for JSON reasoning

This commit is contained in:
Jordan Wages 2026-01-07 03:32:29 -06:00
commit 42d013fccd
Notes: Jordan Wages 2026-01-07 13:52:38 -06:00
Generalizes parsing of response messages to account for multiple model response formats. Related to #1.
7 changed files with 114 additions and 18 deletions

View file

@ -118,8 +118,17 @@ async function clearError() {
}
function recordError(context, err) {
const message = err instanceof Error ? err.message : String(err || 'Unknown error');
const detail = err instanceof Error ? err.stack : '';
let message = 'Unknown error';
let detail = '';
if (err instanceof Error) {
message = err.message;
detail = err.stack || '';
} else if (err && typeof err === 'object') {
message = typeof err.message === 'string' ? err.message : String(err || 'Unknown error');
detail = typeof err.detail === 'string' ? err.detail : '';
} else {
message = String(err || 'Unknown error');
}
errorLog.unshift({
time: Date.now(),
context,
@ -741,6 +750,9 @@ async function clearCacheForMessages(idsInput) {
return { count: queuedCount + (processing ? 1 : 0) };
} else if (msg?.type === "sortana:getErrorLog") {
return { errors: errorLog.slice() };
} else if (msg?.type === "sortana:recordError") {
recordError(msg.context || "Sortana Error", { message: msg.message, detail: msg.detail });
return { ok: true };
} else if (msg?.type === "sortana:getTiming") {
const t = timingStats;
const std = t.count > 1 ? Math.sqrt(t.m2 / (t.count - 1)) : 0;