osborn 0.9.283 → 0.9.285
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.
|
@@ -49,4 +49,5 @@ export declare function resolveFastBrainProvider(): {
|
|
|
49
49
|
} | null;
|
|
50
50
|
export declare function clearPipelineFastBrainSession(): void;
|
|
51
51
|
export declare function prewarmBM25Index(_sessionId: string, _workingDir: string): Promise<void>;
|
|
52
|
+
export declare const isHandOff: (text: string) => boolean;
|
|
52
53
|
export declare function askPipelineFastBrain(workingDir: string, sessionId: string, question: string, opts?: PipelineFastBrainOptions): Promise<PipelineFastBrainResult>;
|
|
@@ -345,6 +345,29 @@ async function callOpenRouter(messages, tools, apiKey) {
|
|
|
345
345
|
// ============================================================
|
|
346
346
|
// MAIN FUNCTION
|
|
347
347
|
// ============================================================
|
|
348
|
+
// The fast brain stating its own limits is a hand-off (the main agent has those tools);
|
|
349
|
+
// recall that mentions a tool or an inability stays an answer (see the guard test).
|
|
350
|
+
const CAPABILITY_DENIAL = new RegExp([
|
|
351
|
+
/(?:\bI(?:'m| am)?|\bsorry,?)\s+(?:not able to|unable to|can't|cannot|can not|(?:don't|do not) have (?:the ability|a way|any way) to)\s+(?:actually\s+|directly\s+)?/.source +
|
|
352
|
+
/(?:browse|record (?:a |the )?(?:video|audio|screen|clip|page)|take (?:a )?screenshots?|edit|build|run|execute|open|visit|fetch|download|access)\b(?!\s+(?:through|over|down)\b)/.source,
|
|
353
|
+
/\bI(?:'m| am)?\s+(?:not able to|unable to|don't|do not|can't|cannot|can not|have no|lack)\b(?!\s+(?:find|see|locate|recall|spot|remember|know|tell|wait|record|details)\b)/.source +
|
|
354
|
+
/[^.!?\n]{0,60}?\b(?:browser|bash|shell|terminal|internet)\b(?!\s+(?:output|logs?|command|script|session|history)\b)/.source,
|
|
355
|
+
].join('|'), 'i');
|
|
356
|
+
export const isHandOff = (text) => text.includes('[RESEARCH_NEEDED]') || CAPABILITY_DENIAL.test(text.replace(/[\u2018\u2019]/g, "'"));
|
|
357
|
+
/** Every exit that carries model text: sanitise, then answer or hand off. A hand-off
|
|
358
|
+
* carries no text (nothing for a consumer to post) and is not kept in the fast
|
|
359
|
+
* brain's own history, so a suppressed denial cannot prime the next turn. */
|
|
360
|
+
function finish(question, raw, toolsUsed) {
|
|
361
|
+
const text = sanitizeFastBrainAnswer((raw || '').trim());
|
|
362
|
+
persistentMessages.push({ role: 'user', content: question });
|
|
363
|
+
console.log(`🧠⚡ [pipeline-fb] ${toolsUsed.length} searches, answer: "${text.substring(0, 80)}"`);
|
|
364
|
+
if (isHandOff(text))
|
|
365
|
+
return { script: '', type: 'research_needed', toolsUsed };
|
|
366
|
+
if (!text)
|
|
367
|
+
return { script: "I didn't find that in the session history.", type: 'answer', toolsUsed };
|
|
368
|
+
persistentMessages.push({ role: 'assistant', content: text });
|
|
369
|
+
return { script: text, type: 'answer', toolsUsed };
|
|
370
|
+
}
|
|
348
371
|
/**
|
|
349
372
|
* Strip internal recall provenance the fast brain may echo into its answer so
|
|
350
373
|
* the user never sees it: citation headers like
|
|
@@ -407,6 +430,7 @@ export async function askPipelineFastBrain(workingDir, sessionId, question, opts
|
|
|
407
430
|
...persistentMessages,
|
|
408
431
|
{ role: 'user', content: turnContext ? `${turnContext}${question}` : question },
|
|
409
432
|
];
|
|
433
|
+
const turnStart = messages.length; // this turn's replies only: never an earlier answer
|
|
410
434
|
try {
|
|
411
435
|
let rounds = 0;
|
|
412
436
|
// Overall wall-clock cap. The per-request fetch timeout doesn't bound the whole
|
|
@@ -437,24 +461,7 @@ export async function askPipelineFastBrain(workingDir, sessionId, question, opts
|
|
|
437
461
|
messages.push(msg);
|
|
438
462
|
const calls = msg.tool_calls;
|
|
439
463
|
if (!calls || calls.length === 0) {
|
|
440
|
-
|
|
441
|
-
// may have echoed (citation headers / line numbers / bare timestamps) —
|
|
442
|
-
// those leak as ugly "[main L550 · tool_result · both] 2026-…" lines in
|
|
443
|
-
// the chat bubble. Defense-in-depth alongside the system-prompt rule.
|
|
444
|
-
const text = sanitizeFastBrainAnswer((msg.content || '').trim());
|
|
445
|
-
// Update persistent history with this exchange
|
|
446
|
-
persistentMessages.push({ role: 'user', content: question });
|
|
447
|
-
if (text)
|
|
448
|
-
persistentMessages.push({ role: 'assistant', content: text });
|
|
449
|
-
console.log(`🧠⚡ [pipeline-fb] ${toolsUsed.length} searches, answer: "${text.substring(0, 80)}"`);
|
|
450
|
-
if (!text)
|
|
451
|
-
return { script: "I didn't find that in the session history.", type: 'answer', toolsUsed };
|
|
452
|
-
// A claimed inability ("I don't have a browser / Bash tool") is a hand-off too:
|
|
453
|
-
// the main agent has those, so it must never reach the chat as an answer.
|
|
454
|
-
if (text.includes('[RESEARCH_NEEDED]') || /\b(?:don't|do not|can't|cannot|unable to)\b[^.]{0,40}\b(?:browser|bash|shell|screenshot|terminal|run (?:shell|commands?)|open (?:the )?(?:url|site|page|website))/i.test(text)) {
|
|
455
|
-
return { script: text.replace('[RESEARCH_NEEDED]', '').trim() || 'This needs deeper research.', type: 'research_needed', toolsUsed };
|
|
456
|
-
}
|
|
457
|
-
return { script: text, type: 'answer', toolsUsed };
|
|
464
|
+
return finish(question, msg.content, toolsUsed);
|
|
458
465
|
}
|
|
459
466
|
// Execute tool calls
|
|
460
467
|
for (const call of calls) {
|
|
@@ -474,13 +481,9 @@ export async function askPipelineFastBrain(workingDir, sessionId, question, opts
|
|
|
474
481
|
});
|
|
475
482
|
}
|
|
476
483
|
}
|
|
477
|
-
// Max rounds hit —
|
|
478
|
-
const lastAssistant =
|
|
479
|
-
|
|
480
|
-
persistentMessages.push({ role: 'user', content: question });
|
|
481
|
-
if (fallback)
|
|
482
|
-
persistentMessages.push({ role: 'assistant', content: fallback });
|
|
483
|
-
return { script: fallback, type: 'answer', toolsUsed };
|
|
484
|
+
// Max rounds or deadline hit — whatever text we have, classified the same way.
|
|
485
|
+
const lastAssistant = messages.slice(turnStart).reverse().find(m => m.role === 'assistant' && m.content);
|
|
486
|
+
return finish(question, lastAssistant?.content, toolsUsed);
|
|
484
487
|
}
|
|
485
488
|
catch (err) {
|
|
486
489
|
if (err?.name === 'TimeoutError' || err?.message?.includes('timeout')) {
|