dsh-composer-quill 0.31.7 → 0.31.9
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/client.js +24 -2
- package/index.js +52 -1
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -26,7 +26,7 @@ window.__ModuleLoader__.load({
|
|
|
26
26
|
const h = React.createElement
|
|
27
27
|
|
|
28
28
|
const NS = 'composer-quill'
|
|
29
|
-
const BUILD = '0.31.
|
|
29
|
+
const BUILD = '0.31.9'
|
|
30
30
|
const ROUTE = '/composer-quill/predict'
|
|
31
31
|
const BEACON = '/composer-quill/beacon'
|
|
32
32
|
/** The browser's own language, used when the Host has no style profile. */
|
|
@@ -781,6 +781,20 @@ const COVERED_DEBOUNCE_MS = 1200
|
|
|
781
781
|
return left !== '' && right !== '' && left === right
|
|
782
782
|
}
|
|
783
783
|
|
|
784
|
+
/**
|
|
785
|
+
* Does a request already in flight still cover this draft?
|
|
786
|
+
*
|
|
787
|
+
* The tail it is producing is appended to `requested`, so a draft that only
|
|
788
|
+
* grew keeps that tail valid — cancelling it and starting over is what made
|
|
789
|
+
* the ghost flicker on every keystroke. A draft that shrank or diverged is
|
|
790
|
+
* not covered: that request can no longer be pasted anywhere.
|
|
791
|
+
*/
|
|
792
|
+
function inFlightCovers(requested, draft) {
|
|
793
|
+
if (typeof requested !== 'string' || requested === '') return false
|
|
794
|
+
if (typeof draft !== 'string') return false
|
|
795
|
+
return draft.length >= requested.length && draft.startsWith(requested)
|
|
796
|
+
}
|
|
797
|
+
|
|
784
798
|
/**
|
|
785
799
|
* The Host joins on a trimmed base. A reply that echoes the untrimmed draft
|
|
786
800
|
* must not put a stray newline into the proposal.
|
|
@@ -1388,6 +1402,13 @@ const COVERED_DEBOUNCE_MS = 1200
|
|
|
1388
1402
|
if (mode === 'compose') {
|
|
1389
1403
|
if (live.running || draftNow.trim().length < MIN_DRAFT_CHARS) return
|
|
1390
1404
|
if (dismissedDraft.current === draftNow) return
|
|
1405
|
+
// The draft only grew since the in-flight request started: its tail
|
|
1406
|
+
// still applies, so keep streaming it instead of cancelling.
|
|
1407
|
+
const inFlight = ghost.getSnapshot()
|
|
1408
|
+
if (inFlight.phase === 'loading' && inFlightCovers(inFlight.requested, draftNow)) {
|
|
1409
|
+
report('reuse', { sessionId: live.sessionId, draftLength: draftNow.length, detail: 'in-flight' })
|
|
1410
|
+
return
|
|
1411
|
+
}
|
|
1391
1412
|
}
|
|
1392
1413
|
const kind = mode === 'next' ? 'next' : 'compose'
|
|
1393
1414
|
|
|
@@ -2252,7 +2273,7 @@ const COVERED_DEBOUNCE_MS = 1200
|
|
|
2252
2273
|
}
|
|
2253
2274
|
|
|
2254
2275
|
report('module', { detail: String((window.location && window.location.pathname) || '') })
|
|
2255
|
-
return { inject, apply, __test: { followRemainder, bestHistoryMatch, normalizeConfig, saveSuggestion, loadSuggestion, readSuggestions, clearSessionSuggestions, streamRoute, featuresOf, rankByLearning, recordOutcome, learningSummary, proposalIsStale, transcriptVersion, epochOf, bumpEpoch, syncEpoch } }
|
|
2276
|
+
return { inject, apply, __test: { followRemainder, bestHistoryMatch, normalizeConfig, saveSuggestion, loadSuggestion, readSuggestions, clearSessionSuggestions, streamRoute, featuresOf, rankByLearning, recordOutcome, learningSummary, proposalIsStale, inFlightCovers, transcriptVersion, epochOf, bumpEpoch, syncEpoch } }
|
|
2256
2277
|
},
|
|
2257
2278
|
})
|
|
2258
2279
|
|
|
@@ -2322,5 +2343,6 @@ const COVERED_DEBOUNCE_MS = 1200
|
|
|
2322
2343
|
|
|
2323
2344
|
|
|
2324
2345
|
|
|
2346
|
+
|
|
2325
2347
|
|
|
2326
2348
|
|
package/index.js
CHANGED
|
@@ -453,6 +453,40 @@ function groundedness(candidate, contextText) {
|
|
|
453
453
|
return shared / candidateGrams.size
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
+
/** Shorter than this and a "repeat" is just a short phrase both sides share. */
|
|
457
|
+
const REPEAT_MIN_CHARS = 8
|
|
458
|
+
|
|
459
|
+
/** Every user message already in the transcript, in comparable form. */
|
|
460
|
+
function priorUserMessages(events) {
|
|
461
|
+
const seen = []
|
|
462
|
+
for (const event of events ?? []) {
|
|
463
|
+
if (event?.type !== 'user/message') continue
|
|
464
|
+
const text = normalizeForCompare(textOfBlocks(event?.data?.content ?? event?.data?.message?.content))
|
|
465
|
+
if (text.length >= REPEAT_MIN_CHARS) seen.push(text)
|
|
466
|
+
}
|
|
467
|
+
return seen
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Is this candidate something the user already sent?
|
|
472
|
+
*
|
|
473
|
+
* Groundedness cannot answer that: a recycled earlier question matches the
|
|
474
|
+
* transcript perfectly and scores ~1.0, which is exactly the report "the
|
|
475
|
+
* suggestion is content from many turns ago". A prediction has to be new.
|
|
476
|
+
*/
|
|
477
|
+
function repeatsEarlierUser(candidate, priorNormalised) {
|
|
478
|
+
const value = normalizeForCompare(candidate)
|
|
479
|
+
if (value.length < REPEAT_MIN_CHARS) return false
|
|
480
|
+
for (const other of priorNormalised ?? []) {
|
|
481
|
+
if (other === value) return true
|
|
482
|
+
// One containing the other means the same question asked again with a prefix
|
|
483
|
+
// or a trailing clause — near-duplicates count as repeats.
|
|
484
|
+
if (other.length >= REPEAT_MIN_CHARS && value.includes(other)) return true
|
|
485
|
+
if (value.length >= REPEAT_MIN_CHARS && other.includes(value)) return true
|
|
486
|
+
}
|
|
487
|
+
return false
|
|
488
|
+
}
|
|
489
|
+
|
|
456
490
|
/**
|
|
457
491
|
* A next-message that touches none of the conversation's wording is almost always
|
|
458
492
|
* about something else entirely (the "this has nothing to do with the session"
|
|
@@ -1390,6 +1424,22 @@ async function computePrediction(ctx, { session, events, hasTurns, kind, cleanDr
|
|
|
1390
1424
|
const lastUser = [...events].reverse().find((event) => event?.type === 'user/message')
|
|
1391
1425
|
const lastUserText = textOfBlocks(lastUser?.data?.content ?? lastUser?.data?.message?.content)
|
|
1392
1426
|
let candidates = rankCandidates(parseCandidates(text), { profile, lastAssistant: assistant, lastUser: lastUserText, locale, forced })
|
|
1427
|
+
// A prediction that repeats an earlier user message is not a prediction: the
|
|
1428
|
+
// conversation has moved on. Drop those before the grounding gate, which would
|
|
1429
|
+
// otherwise score them highest precisely because they already exist.
|
|
1430
|
+
if (kind === 'next' && candidates.length > 0) {
|
|
1431
|
+
const prior = priorUserMessages(events)
|
|
1432
|
+
const fresh = candidates.filter((candidate) => !repeatsEarlierUser(candidate, prior))
|
|
1433
|
+
if (fresh.length !== candidates.length) {
|
|
1434
|
+
trace('next-repeated', {
|
|
1435
|
+
kept: fresh.length,
|
|
1436
|
+
dropped: candidates.length - fresh.length,
|
|
1437
|
+
candidates: candidates.length,
|
|
1438
|
+
priorMessages: prior.length,
|
|
1439
|
+
})
|
|
1440
|
+
candidates = fresh
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1393
1443
|
// Grounding check: only for the next-message prediction, where an off-topic
|
|
1394
1444
|
// guess has no anchor at all. A completion always has the draft to anchor on.
|
|
1395
1445
|
if (kind === 'next' && candidates.length > 0 && context !== '[]') {
|
|
@@ -1811,7 +1861,8 @@ export function apply(ctx) {
|
|
|
1811
1861
|
}
|
|
1812
1862
|
|
|
1813
1863
|
/** Pure helpers exposed for the offline smoke test. */
|
|
1814
|
-
export const __test = { cacheFile, loadCache, rotateLog, LOG_MAX_BYTES, buildShortDraftPrompt, eventsOf, resolveLanguage, wrongLanguage, latinShareOf, groundedness, MIN_GROUNDEDNESS, styleProfile, rankCandidates, looksLikeMeta, isPunctuationOnly, scriptOf, sessionDigest, size: () => cache.size, shorten, parseCandidates, parseComposed, parseComposeReply, parseSentence, joinSentence, transcriptOf, historyOf, maskSecrets, cleanLine, authorized }
|
|
1864
|
+
export const __test = { cacheFile, loadCache, rotateLog, LOG_MAX_BYTES, buildShortDraftPrompt, eventsOf, resolveLanguage, wrongLanguage, latinShareOf, groundedness, MIN_GROUNDEDNESS, priorUserMessages, repeatsEarlierUser, REPEAT_MIN_CHARS, styleProfile, rankCandidates, looksLikeMeta, isPunctuationOnly, scriptOf, sessionDigest, size: () => cache.size, shorten, parseCandidates, parseComposed, parseComposeReply, parseSentence, joinSentence, transcriptOf, historyOf, maskSecrets, cleanLine, authorized }
|
|
1865
|
+
|
|
1815
1866
|
|
|
1816
1867
|
|
|
1817
1868
|
|
package/package.json
CHANGED