dsh-boost 0.1.3 → 0.1.4
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/README.en.md +113 -62
- package/README.md +84 -45
- package/dist/admission/usage.js +12 -2
- package/dist/admission/usage.js.map +1 -1
- package/dist/hooks/llm-stream.js +18 -1
- package/dist/hooks/llm-stream.js.map +1 -1
- package/dist/hooks/post-execute.js +27 -13
- package/dist/hooks/post-execute.js.map +1 -1
- package/dist/projection/apply.js +11 -2
- package/dist/projection/apply.js.map +1 -1
- package/dist/projection/truncate.js +27 -10
- package/dist/projection/truncate.js.map +1 -1
- package/package.json +3 -2
|
@@ -119,6 +119,9 @@ const SELECTOR_RECEIPT_MAX_CHARS = 1_200;
|
|
|
119
119
|
/** Skip reasons that mean the projection machinery degraded, not "nothing to cut". */
|
|
120
120
|
const PROJECTION_DEGRADATIONS = new Set([
|
|
121
121
|
'no-spill',
|
|
122
|
+
// `no-owner` is emitted by `projectApply`'s direct-call contract, not by this
|
|
123
|
+
// hook (design §5.4): the hook only calls it once an owner is known. Kept so
|
|
124
|
+
// a future caller cannot silently lose the mapping.
|
|
122
125
|
'no-owner',
|
|
123
126
|
'projection-skipped:no-footer',
|
|
124
127
|
'spill-failed',
|
|
@@ -206,10 +209,8 @@ function pendingAnchorsOf(deps, sessionId) {
|
|
|
206
209
|
* (`llm/stream`, 23c), where the compared text is the anchored receipt's current
|
|
207
210
|
* body in the outgoing messages.
|
|
208
211
|
*/
|
|
209
|
-
function markerResetOf(
|
|
212
|
+
function markerResetOf(receiptText) {
|
|
210
213
|
try {
|
|
211
|
-
if (pending == null)
|
|
212
|
-
return undefined;
|
|
213
214
|
return looksPruned(receiptText) ? 'pruned-reset' : undefined;
|
|
214
215
|
}
|
|
215
216
|
catch {
|
|
@@ -615,23 +616,25 @@ async function recordProjectionRetrieval(deps, exec, sessionId, pending, visible
|
|
|
615
616
|
// Admission and the decision branch
|
|
616
617
|
// ---------------------------------------------------------------------------
|
|
617
618
|
/**
|
|
618
|
-
* The
|
|
619
|
-
*
|
|
619
|
+
* The saving of skipping one model step: the last real request's `totalTokens`
|
|
620
|
+
* (`input + cacheRead + output`), which is what design §5.3 defines it as.
|
|
620
621
|
*
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
622
|
+
* All three parts are skipped when the model does not run: the replayed context
|
|
623
|
+
* is not sent and the response is not generated. The context only grows as
|
|
624
|
+
* receipts enter it, so the last request is a lower bound. A missing ledger or
|
|
625
|
+
* sample is 0, never an interpolation, so admission falls back to the model when
|
|
626
|
+
* it cannot measure (design §5.3: measured, not estimated).
|
|
625
627
|
*/
|
|
626
628
|
function savedTokensOf(deps, sessionId) {
|
|
627
629
|
try {
|
|
628
630
|
const last = sessionUsage(deps, sessionId)?.last();
|
|
629
631
|
if (last === undefined)
|
|
630
632
|
return 0;
|
|
631
|
-
const { input, cacheRead } = last;
|
|
632
|
-
|
|
633
|
+
const { input, cacheRead, output } = last;
|
|
634
|
+
const parts = [input, cacheRead, output];
|
|
635
|
+
if (parts.some((part) => !Number.isFinite(part) || part < 0))
|
|
633
636
|
return 0;
|
|
634
|
-
const total = input + cacheRead;
|
|
637
|
+
const total = input + cacheRead + output;
|
|
635
638
|
return Number.isFinite(total) ? total : 0;
|
|
636
639
|
}
|
|
637
640
|
catch {
|
|
@@ -1621,6 +1624,13 @@ async function projectDecision(deps, receipt, decision, ctx) {
|
|
|
1621
1624
|
before,
|
|
1622
1625
|
after,
|
|
1623
1626
|
saved_projection_tokens: before - after,
|
|
1627
|
+
// How much the projection cut, in the units the footer names. Without
|
|
1628
|
+
// it a reader of the ledger cannot tell a 2 KB cut from a 200 KB one
|
|
1629
|
+
// (review cod#3: these fields had no consumer).
|
|
1630
|
+
...(outcome.omittedBytes === undefined ? {} : { omitted_bytes: outcome.omittedBytes }),
|
|
1631
|
+
...(outcome.omittedCodePoints === undefined
|
|
1632
|
+
? {}
|
|
1633
|
+
: { omitted_code_points: outcome.omittedCodePoints }),
|
|
1624
1634
|
estimate: deps.estimateKind ?? 'unknown',
|
|
1625
1635
|
}));
|
|
1626
1636
|
}
|
|
@@ -1629,6 +1639,10 @@ async function projectDecision(deps, receipt, decision, ctx) {
|
|
|
1629
1639
|
unit: 'raw',
|
|
1630
1640
|
horizon_steps: projectionHorizonOf(deps, ctx.sessionId),
|
|
1631
1641
|
...(ctx.retrievalCall === true ? { call_was_retrieval: true } : {}),
|
|
1642
|
+
...(outcome.omittedBytes === undefined ? {} : { omitted_bytes: outcome.omittedBytes }),
|
|
1643
|
+
...(outcome.omittedCodePoints === undefined
|
|
1644
|
+
? {}
|
|
1645
|
+
: { omitted_code_points: outcome.omittedCodePoints }),
|
|
1632
1646
|
estimate: 'unknown',
|
|
1633
1647
|
}));
|
|
1634
1648
|
}
|
|
@@ -1871,7 +1885,7 @@ async function postExecute(deps, state, exec, result, next) {
|
|
|
1871
1885
|
// `!= null` rather than `!== undefined`: a foreign store can hand back a
|
|
1872
1886
|
// null, and dereferencing it would throw out of the hook.
|
|
1873
1887
|
if (pending != null) {
|
|
1874
|
-
const reset = markerResetOf(
|
|
1888
|
+
const reset = markerResetOf(receipt.text);
|
|
1875
1889
|
if (reset !== undefined) {
|
|
1876
1890
|
await resetInvalidatedPending(deps, exec, sessionId, turn, pending, reset);
|
|
1877
1891
|
if (retrieval !== undefined) {
|