mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-10-03 17:15:19 -07:00
fix(ui): keep a first line that fits whole instead of re-cutting it at a sentence end
This commit is contained in:
committed by
capy-ai-staging[bot]
parent
872121c0f7
commit
e440b44ae7
@@ -69,15 +69,15 @@ export function condenseError(raw: string | null | undefined): CondensedError {
|
|||||||
// A traceback's first line is nearly always the message; prefer it whenever
|
// A traceback's first line is nearly always the message; prefer it whenever
|
||||||
// it fits, since a newline is a stronger boundary than any punctuation.
|
// it fits, since a newline is a stronger boundary than any punctuation.
|
||||||
const firstLine = text.split('\n', 1)[0].trim();
|
const firstLine = text.split('\n', 1)[0].trim();
|
||||||
let head =
|
const useFirstLine = firstLine.length > 0 && firstLine.length <= HEAD_BUDGET;
|
||||||
firstLine.length > 0 && firstLine.length <= HEAD_BUDGET
|
let head = useFirstLine ? firstLine : text.slice(0, HEAD_BUDGET);
|
||||||
? firstLine
|
|
||||||
: text.slice(0, HEAD_BUDGET);
|
|
||||||
|
|
||||||
if (head.length < text.length && head === text.slice(0, head.length)) {
|
if (!useFirstLine) {
|
||||||
// Back off to the last sentence end inside the budget so the text does not
|
// A raw slice can stop mid-word, so back off to the last sentence end
|
||||||
// stop mid-word. Only accept it if it keeps most of the budget — otherwise
|
// inside the budget. A first line that fit already ends at a newline, the
|
||||||
// a stray early period would throw away usable context.
|
// stronger boundary, and is kept whole. Only accept the backoff if it
|
||||||
|
// keeps most of the budget — otherwise a stray early period would throw
|
||||||
|
// away usable context.
|
||||||
const lastStop = Math.max(head.lastIndexOf('. '), head.lastIndexOf('? '));
|
const lastStop = Math.max(head.lastIndexOf('. '), head.lastIndexOf('? '));
|
||||||
if (lastStop > HEAD_BUDGET * 0.4) {
|
if (lastStop > HEAD_BUDGET * 0.4) {
|
||||||
head = head.slice(0, lastStop + 1);
|
head = head.slice(0, lastStop + 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user