@aexol/spectral 0.9.145 → 0.9.146
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compact-context.d.ts","sourceRoot":"","sources":["../../../src/memory/tools/compact-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EASN,KAAK,gBAAgB,EACrB,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAAc,KAAK,YAAY,EAAyB,MAAM,iCAAiC,CAAC;AAKvG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAY,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAErD,eAAO,MAAM,yBAAyB,oBAAoB,CAAC;AAoO3D;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,GAAE;IAC1D,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,iCAAiC,GAAG,wBAAwB,CAAC,CAAC;IACpF,MAAM,CAAC,EAAE,gBAAgB,CAAC;CACrB,GAAG,WAAW,CAAC,OAAO,uBAAuB,EAAE,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAiBrF;
|
|
1
|
+
{"version":3,"file":"compact-context.d.ts","sourceRoot":"","sources":["../../../src/memory/tools/compact-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EASN,KAAK,gBAAgB,EACrB,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAAc,KAAK,YAAY,EAAyB,MAAM,iCAAiC,CAAC;AAKvG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAY,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAErD,eAAO,MAAM,yBAAyB,oBAAoB,CAAC;AAoO3D;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,GAAE;IAC1D,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,iCAAiC,GAAG,wBAAwB,CAAC,CAAC;IACpF,MAAM,CAAC,EAAE,gBAAgB,CAAC;CACrB,GAAG,WAAW,CAAC,OAAO,uBAAuB,EAAE,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAiBrF;AAgPD,wFAAwF;AACxF,wBAAgB,sCAAsC,CACrD,eAAe,EAAE,YAAY,EAAE,EAC/B,MAAM,GAAE,gBAA4C,EACpD,gBAAgB,CAAC,EAAE,MAAM,GACvB,YAAY,EAAE,CAchB;AAsQD,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CA6SpF"}
|
|
@@ -232,6 +232,14 @@ function safeRawTokensForContext(ctx) {
|
|
|
232
232
|
return 0;
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
|
+
function rawTokensForCurrentMessages(messages) {
|
|
236
|
+
try {
|
|
237
|
+
return estimateContextTokens(messages).tokens;
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
return 0;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
235
243
|
function isOpenPhase(params) {
|
|
236
244
|
return params.phaseComplete === false ||
|
|
237
245
|
params.phaseStatus === "active" ||
|
|
@@ -368,8 +376,24 @@ function createVirtualCompactionEntry(pathEntries, result) {
|
|
|
368
376
|
};
|
|
369
377
|
}
|
|
370
378
|
function buildRequestTimePrunedMessages(ctx, request, policy, currentMessages) {
|
|
371
|
-
|
|
372
|
-
|
|
379
|
+
// During an active provider request the event payload is the source of truth.
|
|
380
|
+
// The session branch can lag behind it (notably while a tool result or the
|
|
381
|
+
// current assistant turn is still being appended), which used to make the
|
|
382
|
+
// virtual compaction appear non-shrinking and silently send the full context.
|
|
383
|
+
// Prefer an exact synthetic representation of the messages being requested;
|
|
384
|
+
// retain the persisted branch as a compatibility fallback for callers whose
|
|
385
|
+
// context event does not contain the complete session yet.
|
|
386
|
+
const currentEntries = currentMessages.map((message, index) => ({
|
|
387
|
+
type: "message",
|
|
388
|
+
id: `request-time-${index}`,
|
|
389
|
+
parentId: index > 0 ? `request-time-${index - 1}` : null,
|
|
390
|
+
timestamp: new Date(index).toISOString(),
|
|
391
|
+
message,
|
|
392
|
+
}));
|
|
393
|
+
const fromCurrentMessages = buildRequestTimePrunedMessagesFromEntries(currentEntries, request, policy, currentMessages);
|
|
394
|
+
if (fromCurrentMessages)
|
|
395
|
+
return fromCurrentMessages;
|
|
396
|
+
return buildRequestTimePrunedMessagesFromEntries(getBranchEntries(ctx), request, policy, currentMessages);
|
|
373
397
|
}
|
|
374
398
|
/** Request-time DCP adapter for isolated loops: it borrows only pure policy helpers. */
|
|
375
399
|
export function buildIsolatedRequestTimePrunedMessages(currentMessages, policy = DEFAULT_COMPACTION_POLICY, keepRecentTokens) {
|
|
@@ -664,7 +688,7 @@ export function registerCompactContextTool(ext, runtime) {
|
|
|
664
688
|
// Treat an explicit provider-preparation event as in-run even if the session
|
|
665
689
|
// state has not flipped to streaming/pending yet.
|
|
666
690
|
const autoSettings = getAutoOlderHistoryRequestSettings(policy);
|
|
667
|
-
const autoRawTokens = safeRawTokensForContext(ctx);
|
|
691
|
+
const autoRawTokens = Math.max(safeRawTokensForContext(ctx), rawTokensForCurrentMessages(_event.messages));
|
|
668
692
|
const autoUsage = ctx.getContextUsage();
|
|
669
693
|
const autoContextTokens = autoUsage?.tokens;
|
|
670
694
|
const autoPercent = autoUsage?.percent;
|