acp-kernel 0.0.59-pr.223.75 → 0.0.59-pr.226.77
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/dist/absorb.d.ts +1 -2
- package/dist/absorb.d.ts.map +1 -1
- package/dist/{chunk-UX4LINT7.js → chunk-C4EQEGJ4.js} +14 -2
- package/dist/chunk-C4EQEGJ4.js.map +1 -0
- package/dist/compress.d.ts +7 -0
- package/dist/compress.d.ts.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/hide-consumed.d.ts.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +115 -71
- package/dist/index.js.map +1 -1
- package/dist/persist/index.js +1 -1
- package/dist/protected.d.ts +0 -17
- package/dist/protected.d.ts.map +1 -1
- package/dist/recommend.d.ts.map +1 -1
- package/dist/state.d.ts +9 -0
- package/dist/state.d.ts.map +1 -1
- package/dist/strip-reasoning.d.ts +23 -0
- package/dist/strip-reasoning.d.ts.map +1 -0
- package/dist/sync.d.ts.map +1 -1
- package/dist/types.d.ts +9 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-UX4LINT7.js.map +0 -1
package/dist/absorb.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type LatestProtected } from "./protected.js";
|
|
2
1
|
import type { AbsorbConfig, Config, CompressionState, CoreMessage } from "./types.js";
|
|
3
2
|
/**
|
|
4
3
|
* Instant tool-result absorption ("absorb") — the middle layer between
|
|
@@ -18,7 +17,7 @@ export declare function buildAbsorbPrompt(ref: string, tokens: number, toolName?
|
|
|
18
17
|
export declare function buildAbsorbSystemPrompt(toolName?: string): string;
|
|
19
18
|
/** True when a tool-result message is in scope for absorption prompting:
|
|
20
19
|
* a tool-result of a non-ACP, non-excluded, non-protected tool. */
|
|
21
|
-
export declare function isAbsorbCandidate(msg: CoreMessage, config: Config
|
|
20
|
+
export declare function isAbsorbCandidate(msg: CoreMessage, config: Config): boolean;
|
|
22
21
|
/** Drop tool-call + tool-result pairs recorded in state.absorbed. Both halves
|
|
23
22
|
* go together so the provider-visible conversation stays structurally valid;
|
|
24
23
|
* prune's orphan stripping cleans up any straddling leftovers. */
|
package/dist/absorb.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"absorb.d.ts","sourceRoot":"","sources":["../src/absorb.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"absorb.d.ts","sourceRoot":"","sources":["../src/absorb.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,YAAY,EAEZ,MAAM,EACN,gBAAgB,EAChB,WAAW,EACZ,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;GASG;AAEH,eAAO,MAAM,oBAAoB,iBAAiB,CAAC;AAEnD,eAAO,MAAM,qBAAqB,EAAE,YAMnC,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAEhE;AAQD,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,MAAyB,GAClC,MAAM,CAQR;AAED,8DAA8D;AAC9D,wBAAgB,uBAAuB,CACrC,QAAQ,GAAE,MAAyB,GAClC,MAAM,CAIR;AAWD;oEACoE;AACpE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAS3E;AAED;;mEAEmE;AACnE,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,WAAW,EAAE,EACvB,KAAK,EAAE,gBAAgB,GACtB,WAAW,EAAE,CASf;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;sEAGsE;AACtE,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,WAAW,EAAE,EACvB,KAAK,EAAE,gBAAgB,EACvB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GACpC,yBAAyB,CAmC3B;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;4DAE4D;AAC5D,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GACjC,YAAY,GAAG,IAAI,CA+BrB;AAaD,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,gBAAgB,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACxC;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,gBAAgB,CAAC;IACxB,EAAE,EAAE,OAAO,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;0DAE0D;AAC1D,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,aAAa,CAsG7D"}
|
|
@@ -33,11 +33,21 @@ function blockById(state, blockId) {
|
|
|
33
33
|
function activeBlocks(state) {
|
|
34
34
|
return state.blocks.filter((block) => block.active);
|
|
35
35
|
}
|
|
36
|
+
function baseMessageId(id) {
|
|
37
|
+
const hash = id.indexOf("#");
|
|
38
|
+
return hash === -1 ? id : id.slice(0, hash);
|
|
39
|
+
}
|
|
40
|
+
function isIdCovered(covered, id) {
|
|
41
|
+
return covered.has(id) || covered.has(baseMessageId(id));
|
|
42
|
+
}
|
|
36
43
|
function coveredMessageIds(state) {
|
|
37
44
|
const covered = /* @__PURE__ */ new Set();
|
|
38
45
|
for (const block of state.blocks) {
|
|
39
46
|
if (!block.active) continue;
|
|
40
|
-
for (const id of block.effectiveMessageIds)
|
|
47
|
+
for (const id of block.effectiveMessageIds) {
|
|
48
|
+
covered.add(id);
|
|
49
|
+
covered.add(baseMessageId(id));
|
|
50
|
+
}
|
|
41
51
|
}
|
|
42
52
|
return covered;
|
|
43
53
|
}
|
|
@@ -64,8 +74,10 @@ export {
|
|
|
64
74
|
allocateRunId,
|
|
65
75
|
blockById,
|
|
66
76
|
activeBlocks,
|
|
77
|
+
baseMessageId,
|
|
78
|
+
isIdCovered,
|
|
67
79
|
coveredMessageIds,
|
|
68
80
|
highestActiveTier,
|
|
69
81
|
advanceSurvival
|
|
70
82
|
};
|
|
71
|
-
//# sourceMappingURL=chunk-
|
|
83
|
+
//# sourceMappingURL=chunk-C4EQEGJ4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/state.ts"],"sourcesContent":["import type { CompressionBlock, CompressionState } from \"./types.js\";\n\nexport function createInitialState(): CompressionState {\n return {\n blocks: [],\n messageRefs: { byRaw: {}, byRef: {} },\n tokenSnapshot: {},\n nudge: {\n lastPerMessageNudgeTokens: 0,\n lastNudgeShownTokens: 0,\n baselineTokens: 0,\n anchors: {},\n lastShownByTier: {},\n },\n stats: { tokensCompressed: 0, compressionCount: 0, absorbedTokens: 0 },\n absorbed: [],\n nextBlockId: 1,\n nextRunId: 1,\n };\n}\n\nexport function allocateBlockId(state: CompressionState): string {\n const id = state.nextBlockId;\n state.nextBlockId = Math.max(1, id) + 1;\n return `b${id}`;\n}\n\nexport function allocateRunId(state: CompressionState): string {\n const id = state.nextRunId;\n state.nextRunId = Math.max(1, id) + 1;\n return `r${id}`;\n}\n\nexport function blockById(\n state: CompressionState,\n blockId: string,\n): CompressionBlock | undefined {\n return state.blocks.find((block) => block.blockId === blockId);\n}\n\nexport function activeBlocks(state: CompressionState): CompressionBlock[] {\n return state.blocks.filter((block) => block.active);\n}\n\n/**\n * Host projections may append a `#suffix` to a core message id (e.g.\n * `base#callId`, `base#r0`) to represent a variant of the same logical\n * message. Coverage is defined on the base id: a message is covered when any\n * sibling projection of it is covered by an active block.\n */\nexport function baseMessageId(id: string): string {\n const hash = id.indexOf(\"#\");\n return hash === -1 ? id : id.slice(0, hash);\n}\n\n/** True when `id` or any sibling projection of it is in `covered`. */\nexport function isIdCovered(covered: Set<string>, id: string): boolean {\n return covered.has(id) || covered.has(baseMessageId(id));\n}\n\nexport function coveredMessageIds(state: CompressionState): Set<string> {\n const covered = new Set<string>();\n for (const block of state.blocks) {\n if (!block.active) continue;\n for (const id of block.effectiveMessageIds) {\n covered.add(id);\n covered.add(baseMessageId(id));\n }\n }\n return covered;\n}\n\nexport function highestActiveTier(state: CompressionState): 0 | 1 | 2 | 3 {\n let highest: 0 | 1 | 2 | 3 = 0;\n for (const block of state.blocks) {\n if (block.active && block.tier > highest) highest = block.tier;\n }\n return highest;\n}\n\nexport function advanceSurvival(\n state: CompressionState,\n promotionThreshold: number,\n): void {\n for (const block of state.blocks) {\n if (!block.active) continue;\n block.survivedCount += 1;\n if (block.survivedCount >= promotionThreshold) {\n block.generation = \"old\";\n }\n }\n}\n"],"mappings":";AAEO,SAAS,qBAAuC;AACrD,SAAO;AAAA,IACL,QAAQ,CAAC;AAAA,IACT,aAAa,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,EAAE;AAAA,IACpC,eAAe,CAAC;AAAA,IAChB,OAAO;AAAA,MACL,2BAA2B;AAAA,MAC3B,sBAAsB;AAAA,MACtB,gBAAgB;AAAA,MAChB,SAAS,CAAC;AAAA,MACV,iBAAiB,CAAC;AAAA,IACpB;AAAA,IACA,OAAO,EAAE,kBAAkB,GAAG,kBAAkB,GAAG,gBAAgB,EAAE;AAAA,IACrE,UAAU,CAAC;AAAA,IACX,a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BAAiB;AACvB,QAAI,MAAM,iBAAiB,oBAAoB;AAC7C,YAAM,aAAa;AAAA,IACrB;AAAA,EACF;AACF;","names":[]}
|
package/dist/compress.d.ts
CHANGED
|
@@ -18,6 +18,13 @@ export interface ProcessTurnInput {
|
|
|
18
18
|
state: CompressionState;
|
|
19
19
|
config: Config;
|
|
20
20
|
tokenCount: number;
|
|
21
|
+
/**
|
|
22
|
+
* Host-reported context mass the kernel cannot see (wire-level replayed
|
|
23
|
+
* reasoning, system prompt, provider overhead). Folded into usage and
|
|
24
|
+
* pressure so the pressure band tracks real provider-side usage instead of
|
|
25
|
+
* only the kernel-visible view.
|
|
26
|
+
*/
|
|
27
|
+
extraTokens?: number;
|
|
21
28
|
/**
|
|
22
29
|
* Which messages get an <acp> ref tag injected into their text
|
|
23
30
|
* (the render-refs pipeline node). Refs are ALWAYS assigned regardless
|
package/dist/compress.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compress.d.ts","sourceRoot":"","sources":["../src/compress.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compress.d.ts","sourceRoot":"","sources":["../src/compress.ts"],"names":[],"mappings":"AAUA,OAAO,EAAkC,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAehF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAUvD,OAAO,EAGL,KAAK,YAAY,EAElB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAEhB,MAAM,EAEN,WAAW,EAGX,iBAAiB,EAEjB,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,KAAK;IACpB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACxC;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,iBAAiB,CAAC;IACxD,gBAAgB,CA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{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,wBAAgB,aAAa,CAC3B,iBAAiB,EAAE,MAAM,EACzB,SAAS,GAAE,OAAO,CAAC,MAAM,CAAM,GAC9B,MAAM,CAgDR;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,wBAAgB,aAAa,CAC3B,iBAAiB,EAAE,MAAM,EACzB,SAAS,GAAE,OAAO,CAAC,MAAM,CAAM,GAC9B,MAAM,CAgDR;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CA+DvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hide-consumed.d.ts","sourceRoot":"","sources":["../src/hide-consumed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAYhE,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;CAClB;
|
|
1
|
+
{"version":3,"file":"hide-consumed.d.ts","sourceRoot":"","sources":["../src/hide-consumed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAYhE,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;CAClB;AAiED,wBAAgB,yBAAyB,CACrC,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,WAAW,EAAE,GACxB,kBAAkB,CAmFpB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./types.js";
|
|
2
2
|
export { createCore } from "./compress.js";
|
|
3
3
|
export type { Ports, CompressionCore, ProcessTurnInput, ApplyCompressionInput, } from "./compress.js";
|
|
4
|
-
export { createInitialState, allocateBlockId, allocateRunId, blockById, activeBlocks, coveredMessageIds, highestActiveTier, advanceSurvival, } from "./state.js";
|
|
4
|
+
export { createInitialState, allocateBlockId, allocateRunId, blockById, activeBlocks, coveredMessageIds, highestActiveTier, advanceSurvival, baseMessageId, isIdCovered, } from "./state.js";
|
|
5
5
|
export { defaultConfig, validateConfig } from "./config.js";
|
|
6
6
|
export * from "./compress-tools.js";
|
|
7
7
|
export { assignRefs, highestUsedIndex, emptyRefMap, indexToRef, refToIndex, refForRaw, rawForRef, BLOCKED_REF, } from "./refs.js";
|
|
@@ -25,6 +25,8 @@ export { renderHandoff, renderMessage, matchSession } from "./handoff.js";
|
|
|
25
25
|
export type { HandoffInput, HandoffMeta, HandoffBlockFull } from "./handoff.js";
|
|
26
26
|
export { hideConsumedCompressCalls } from "./hide-consumed.js";
|
|
27
27
|
export type { HideConsumedResult } from "./hide-consumed.js";
|
|
28
|
+
export { stripReasoningByRound, isRealUserMessage } from "./strip-reasoning.js";
|
|
29
|
+
export type { StripReasoningResult } from "./strip-reasoning.js";
|
|
28
30
|
export { ABSORB_TOOL_NAME, ABSORB_TOOL, ABSORB_TOOL_OPENAI, } from "./compress-tools.js";
|
|
29
31
|
export { ABSORB_PROMPT_MARKER, DEFAULT_ABSORB_CONFIG, resolveAbsorbConfig, buildAbsorbPrompt, buildAbsorbSystemPrompt, isAbsorbCandidate, hideAbsorbedMessages, appendAbsorbPrompts, parseAbsorbInput, applyAbsorb, } from "./absorb.js";
|
|
30
32
|
export type { AbsorbInput, AbsorbOutcome, ParsedAbsorb, AppendAbsorbPromptsResult, } from "./absorb.js";
|
|
@@ -40,7 +42,7 @@ export { searchBlocks, searchBlocksAsync, blockDocs, messageDocs, } from "./sear
|
|
|
40
42
|
export { clearDocFeatures, docCacheInfo, docFeatures, setDocCacheCap, } from "./search.js";
|
|
41
43
|
export type { SearchResult, SearchOptions, SearchAlgorithm, AsyncSearchAlgorithm, AnySearchAlgorithm, SearchDoc, SearchDocKind, ScoredBlock, MessageRole, RoleWeights, MessageInput, } from "./search.js";
|
|
42
44
|
export { DEFAULT_ALGORITHM, DEFAULT_ROLE_WEIGHTS, registerSearchAlgorithm, getSearchAlgorithm, listSearchAlgorithms, } from "./search.js";
|
|
43
|
-
export {
|
|
45
|
+
export { isMessageProtected, matchToolPattern } from "./protected.js";
|
|
44
46
|
export { runPipeline, makeIO, type PipelineNode, type PipelineContext, type NodeIO, type NodeEffects, } from "./pipeline.js";
|
|
45
47
|
export * from "./filter/index.js";
|
|
46
48
|
export { VIABLE_RANGE_MIN_TOKENS, viableRanges } from "./viable.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EACV,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EACV,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,aA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AAiB,EACjB,cAAc,EACd,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,YAAY,EACZ,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EACL,WAAW,EACX,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,WAAW,GACjB,MAAM,eAAe,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAElC,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,11 +18,13 @@ import {
|
|
|
18
18
|
advanceSurvival,
|
|
19
19
|
allocateBlockId,
|
|
20
20
|
allocateRunId,
|
|
21
|
+
baseMessageId,
|
|
21
22
|
blockById,
|
|
22
23
|
coveredMessageIds,
|
|
23
24
|
createInitialState,
|
|
24
|
-
highestActiveTier
|
|
25
|
-
|
|
25
|
+
highestActiveTier,
|
|
26
|
+
isIdCovered
|
|
27
|
+
} from "./chunk-C4EQEGJ4.js";
|
|
26
28
|
|
|
27
29
|
// src/refs.ts
|
|
28
30
|
var REF_WIDTH = 5;
|
|
@@ -177,7 +179,7 @@ function rebuildMessages(messages, covered, firstUserIndex, anchors) {
|
|
|
177
179
|
result.push(messages[index]);
|
|
178
180
|
continue;
|
|
179
181
|
}
|
|
180
|
-
if (covered
|
|
182
|
+
if (isIdCovered(covered, messages[index].id)) continue;
|
|
181
183
|
if (isRenderedSummaryMessage(messages[index]) && anchoredSummaryIds.has(messages[index].id))
|
|
182
184
|
continue;
|
|
183
185
|
result.push(messages[index]);
|
|
@@ -243,6 +245,7 @@ function stripOrphanedReasoning(messages) {
|
|
|
243
245
|
// src/sync.ts
|
|
244
246
|
function syncBlocks(messages, state) {
|
|
245
247
|
const presentIds = new Set(messages.map((message) => message.id));
|
|
248
|
+
const presentBases = new Set(messages.map((message) => baseMessageId(message.id)));
|
|
246
249
|
const deactivated = [];
|
|
247
250
|
const result = {
|
|
248
251
|
blocks: state.blocks.map((block) => ({
|
|
@@ -289,7 +292,9 @@ function syncBlocks(messages, state) {
|
|
|
289
292
|
continue;
|
|
290
293
|
}
|
|
291
294
|
block.active = true;
|
|
292
|
-
const stillPresent = block.effectiveMessageIds.some(
|
|
295
|
+
const stillPresent = block.effectiveMessageIds.some(
|
|
296
|
+
(id) => presentIds.has(id) || presentBases.has(baseMessageId(id))
|
|
297
|
+
) || presentIds.has(summaryMessageId(block.blockId));
|
|
293
298
|
if (!stillPresent) {
|
|
294
299
|
block.active = false;
|
|
295
300
|
deactivated.push(block.blockId);
|
|
@@ -324,10 +329,10 @@ function defaultConfig(modelContextLimit, overrides = {}) {
|
|
|
324
329
|
minSummaryLength: 50
|
|
325
330
|
},
|
|
326
331
|
protectedTools: [],
|
|
327
|
-
protectedLatestTools: [],
|
|
328
332
|
preserveRecentMessages: 5,
|
|
329
333
|
preserveRecentTokens: 5e3,
|
|
330
334
|
modelContextLimit,
|
|
335
|
+
reasoningReplay: "always",
|
|
331
336
|
absorb: {
|
|
332
337
|
enabled: false,
|
|
333
338
|
toolName: "absorb",
|
|
@@ -364,6 +369,9 @@ function validateConfig(config) {
|
|
|
364
369
|
if (config.nudge.minPressureBenefitTokens !== void 0 && (!Number.isFinite(config.nudge.minPressureBenefitTokens) || config.nudge.minPressureBenefitTokens < 0)) {
|
|
365
370
|
errors.push("nudge.minPressureBenefitTokens must be finite and >= 0");
|
|
366
371
|
}
|
|
372
|
+
if (config.reasoningReplay !== void 0 && config.reasoningReplay !== "always" && config.reasoningReplay !== "open-round" && config.reasoningReplay !== "never") {
|
|
373
|
+
errors.push('reasoningReplay must be "always", "open-round", or "never"');
|
|
374
|
+
}
|
|
367
375
|
if (config.promotionThreshold < 1) {
|
|
368
376
|
errors.push("promotionThreshold must be >= 1");
|
|
369
377
|
}
|
|
@@ -667,10 +675,30 @@ var KEEP_LAST_ORPHANED = 2;
|
|
|
667
675
|
function rangeKey(startRef, endRef) {
|
|
668
676
|
return `${startRef}::${endRef}`;
|
|
669
677
|
}
|
|
678
|
+
var LT = "<";
|
|
679
|
+
var GT = ">";
|
|
680
|
+
var REF_TAG_PREFIX_RE = new RegExp(
|
|
681
|
+
"^" + LT + "acp [^" + GT + "]*" + GT + "m\\d{1,5}" + LT + "/acp" + GT + "\\n?"
|
|
682
|
+
);
|
|
683
|
+
var SUMMARY_STUB_CHARS = 200;
|
|
684
|
+
function stubSummary(entry) {
|
|
685
|
+
const summary = entry.summary;
|
|
686
|
+
if (typeof summary === "string" && summary.length > SUMMARY_STUB_CHARS) {
|
|
687
|
+
return { ...entry, summary: summary.slice(0, SUMMARY_STUB_CHARS) + "\u2026" };
|
|
688
|
+
}
|
|
689
|
+
return entry;
|
|
690
|
+
}
|
|
691
|
+
function entryRef(entry, ...fields) {
|
|
692
|
+
for (const field of fields) {
|
|
693
|
+
const value = entry[field];
|
|
694
|
+
if (typeof value === "string") return value;
|
|
695
|
+
}
|
|
696
|
+
return "";
|
|
697
|
+
}
|
|
670
698
|
function rewriteCompressText(text, liveKeys) {
|
|
671
699
|
let parsed;
|
|
672
700
|
try {
|
|
673
|
-
parsed = JSON.parse(text ?? "");
|
|
701
|
+
parsed = JSON.parse((text ?? "").replace(REF_TAG_PREFIX_RE, ""));
|
|
674
702
|
} catch {
|
|
675
703
|
return null;
|
|
676
704
|
}
|
|
@@ -680,11 +708,11 @@ function rewriteCompressText(text, liveKeys) {
|
|
|
680
708
|
if (!Array.isArray(content) || content.length === 0) return null;
|
|
681
709
|
const kept = content.filter((entry) => {
|
|
682
710
|
if (!entry || typeof entry !== "object") return false;
|
|
683
|
-
const s =
|
|
684
|
-
const e =
|
|
711
|
+
const s = entryRef(entry, "startRef", "startId", "messageId");
|
|
712
|
+
const e = entryRef(entry, "endRef", "endId", "messageId");
|
|
685
713
|
return liveKeys.has(rangeKey(s, e));
|
|
686
|
-
});
|
|
687
|
-
if (kept.length ===
|
|
714
|
+
}).map(stubSummary);
|
|
715
|
+
if (kept.length === 0) return null;
|
|
688
716
|
return JSON.stringify({ ...obj, content: kept });
|
|
689
717
|
}
|
|
690
718
|
function hideConsumedCompressCalls(state, messages) {
|
|
@@ -1192,31 +1220,6 @@ function isMessageProtectedWithPairing(msg, config, protectedCallIds) {
|
|
|
1192
1220
|
}
|
|
1193
1221
|
return false;
|
|
1194
1222
|
}
|
|
1195
|
-
function collectLatestProtected(messages, config) {
|
|
1196
|
-
const callIds = /* @__PURE__ */ new Set();
|
|
1197
|
-
const msgIds = /* @__PURE__ */ new Set();
|
|
1198
|
-
const patterns = config.protectedLatestTools ?? [];
|
|
1199
|
-
if (patterns.length === 0) return { callIds, msgIds };
|
|
1200
|
-
for (const pattern of patterns) {
|
|
1201
|
-
let last;
|
|
1202
|
-
for (const m of messages) {
|
|
1203
|
-
if (m.contentType === "tool-call" && m.toolName && matchToolPattern(m.toolName, pattern)) {
|
|
1204
|
-
last = m;
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
if (!last) continue;
|
|
1208
|
-
if (last.toolCallId) callIds.add(last.toolCallId);
|
|
1209
|
-
else msgIds.add(last.id);
|
|
1210
|
-
}
|
|
1211
|
-
return { callIds, msgIds };
|
|
1212
|
-
}
|
|
1213
|
-
function isMessageLatestProtected(msg, latest) {
|
|
1214
|
-
if (msg.contentType === "tool-call" && latest.msgIds.has(msg.id)) return true;
|
|
1215
|
-
if ((msg.contentType === "tool-call" || msg.contentType === "tool-result") && msg.toolCallId && latest.callIds.has(msg.toolCallId)) {
|
|
1216
|
-
return true;
|
|
1217
|
-
}
|
|
1218
|
-
return false;
|
|
1219
|
-
}
|
|
1220
1223
|
|
|
1221
1224
|
// src/absorb.ts
|
|
1222
1225
|
var ABSORB_PROMPT_MARKER = "[ACP absorb]";
|
|
@@ -1248,12 +1251,11 @@ function isAcpOrConfiguredTool(toolName, cfg) {
|
|
|
1248
1251
|
if (toolName === cfg.toolName) return true;
|
|
1249
1252
|
return ACP_TOOL_NAMES.has(toolName);
|
|
1250
1253
|
}
|
|
1251
|
-
function isAbsorbCandidate(msg, config
|
|
1254
|
+
function isAbsorbCandidate(msg, config) {
|
|
1252
1255
|
if (msg.contentType !== "tool-result" || !msg.toolCallId) return false;
|
|
1253
1256
|
const cfg = resolveAbsorbConfig(config);
|
|
1254
1257
|
if (isAcpOrConfiguredTool(msg.toolName, cfg)) return false;
|
|
1255
1258
|
if (isMessageProtected(msg, config)) return false;
|
|
1256
|
-
if (latest && isMessageLatestProtected(msg, latest)) return false;
|
|
1257
1259
|
for (const pattern of cfg.excludeTools) {
|
|
1258
1260
|
if (msg.toolName && matchToolPattern(msg.toolName, pattern)) return false;
|
|
1259
1261
|
}
|
|
@@ -1281,9 +1283,8 @@ function appendAbsorbPrompts(messages, state, config, tokenCount, countTokens) {
|
|
|
1281
1283
|
if (record.resultMessageId) absorbedIds.add(record.resultMessageId);
|
|
1282
1284
|
}
|
|
1283
1285
|
let promptedCount = 0;
|
|
1284
|
-
const latest = collectLatestProtected(messages, config);
|
|
1285
1286
|
const out = messages.map((msg) => {
|
|
1286
|
-
if (!isAbsorbCandidate(msg, config
|
|
1287
|
+
if (!isAbsorbCandidate(msg, config)) return msg;
|
|
1287
1288
|
if (absorbedIds.has(msg.id)) return msg;
|
|
1288
1289
|
const text = msg.text ?? "";
|
|
1289
1290
|
if (text.includes(ABSORB_PROMPT_MARKER)) return msg;
|
|
@@ -1389,10 +1390,7 @@ function applyAbsorb(input) {
|
|
|
1389
1390
|
resultText: `absorb failed: ${target.toolName} is an ACP-managed tool result \u2014 it is not absorbable.`
|
|
1390
1391
|
};
|
|
1391
1392
|
}
|
|
1392
|
-
if (isMessageProtected(target, input.config)
|
|
1393
|
-
target,
|
|
1394
|
-
collectLatestProtected(input.messages, input.config)
|
|
1395
|
-
)) {
|
|
1393
|
+
if (isMessageProtected(target, input.config)) {
|
|
1396
1394
|
return {
|
|
1397
1395
|
state: input.state,
|
|
1398
1396
|
ok: false,
|
|
@@ -1557,12 +1555,12 @@ function classifyType(message) {
|
|
|
1557
1555
|
function escapeRegex(s) {
|
|
1558
1556
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1559
1557
|
}
|
|
1560
|
-
var
|
|
1561
|
-
var
|
|
1562
|
-
var TAG_OPEN =
|
|
1563
|
-
var TAG_CLOSE =
|
|
1558
|
+
var LT2 = "<";
|
|
1559
|
+
var GT2 = ">";
|
|
1560
|
+
var TAG_OPEN = LT2 + "acp ";
|
|
1561
|
+
var TAG_CLOSE = LT2 + "/acp" + GT2;
|
|
1564
1562
|
function acpTag(ref, tokens, type) {
|
|
1565
|
-
return TAG_OPEN + 'tokens="' + formatTokens(tokens) + '" type="' + type + '"' +
|
|
1563
|
+
return TAG_OPEN + 'tokens="' + formatTokens(tokens) + '" type="' + type + '"' + GT2 + ref + TAG_CLOSE;
|
|
1566
1564
|
}
|
|
1567
1565
|
function renderMessage(message, map, countTokens, strategy, snapshot = null) {
|
|
1568
1566
|
const ref = refForRaw(map, message.id);
|
|
@@ -1572,7 +1570,7 @@ function renderMessage(message, map, countTokens, strategy, snapshot = null) {
|
|
|
1572
1570
|
return message;
|
|
1573
1571
|
}
|
|
1574
1572
|
const ownTagRe = new RegExp(
|
|
1575
|
-
"^" + escapeRegex(TAG_OPEN) + "[^>]*" +
|
|
1573
|
+
"^" + escapeRegex(TAG_OPEN) + "[^>]*" + GT2 + escapeRegex(ref) + escapeRegex(TAG_CLOSE) + "\\n?"
|
|
1576
1574
|
);
|
|
1577
1575
|
const cleanText = (message.text || "").replace(ownTagRe, "");
|
|
1578
1576
|
const tokens = snapshot ? snapshot[ref] ?? (snapshot[ref] = countTokens(cleanText)) : countTokens(cleanText);
|
|
@@ -1682,6 +1680,39 @@ function adjustBoundariesForReasoningPairs(startIndex, endIndex, messages) {
|
|
|
1682
1680
|
return { startIndex: newStartIndex, endIndex: newEndIndex };
|
|
1683
1681
|
}
|
|
1684
1682
|
|
|
1683
|
+
// src/strip-reasoning.ts
|
|
1684
|
+
function isRealUserMessage(message) {
|
|
1685
|
+
return message.role === "user" && message.contentType === "text";
|
|
1686
|
+
}
|
|
1687
|
+
function stripReasoningByRound(messages, mode) {
|
|
1688
|
+
if (mode === "always") return { messages, stripped: 0 };
|
|
1689
|
+
let cutoff;
|
|
1690
|
+
if (mode === "never") {
|
|
1691
|
+
cutoff = messages.length;
|
|
1692
|
+
} else {
|
|
1693
|
+
let lastRealUserIndex = -1;
|
|
1694
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
1695
|
+
if (isRealUserMessage(messages[i])) {
|
|
1696
|
+
lastRealUserIndex = i;
|
|
1697
|
+
break;
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
if (lastRealUserIndex === -1) return { messages, stripped: 0 };
|
|
1701
|
+
cutoff = lastRealUserIndex + 1;
|
|
1702
|
+
}
|
|
1703
|
+
let stripped = 0;
|
|
1704
|
+
const kept = [];
|
|
1705
|
+
for (let i = 0; i < messages.length; i++) {
|
|
1706
|
+
const message = messages[i];
|
|
1707
|
+
if (message.contentType === "reasoning" && i < cutoff) {
|
|
1708
|
+
stripped++;
|
|
1709
|
+
continue;
|
|
1710
|
+
}
|
|
1711
|
+
kept.push(message);
|
|
1712
|
+
}
|
|
1713
|
+
return { messages: kept, stripped };
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1685
1716
|
// src/recommend.ts
|
|
1686
1717
|
function estimateTextTokens(text) {
|
|
1687
1718
|
return Math.ceil(text.length / 4);
|
|
@@ -1691,8 +1722,12 @@ function isToolMessage(message) {
|
|
|
1691
1722
|
}
|
|
1692
1723
|
function isSyntheticOrPruned(message, state) {
|
|
1693
1724
|
if (message.text?.startsWith("[Compressed conversation section]")) return true;
|
|
1725
|
+
const base = baseMessageId(message.id);
|
|
1694
1726
|
for (const block of state.blocks) {
|
|
1695
|
-
if (block.active && block.effectiveMessageIds.
|
|
1727
|
+
if (block.active && block.effectiveMessageIds.some(
|
|
1728
|
+
(id) => id === message.id || baseMessageId(id) === base
|
|
1729
|
+
))
|
|
1730
|
+
return true;
|
|
1696
1731
|
}
|
|
1697
1732
|
return false;
|
|
1698
1733
|
}
|
|
@@ -1735,8 +1770,6 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
1735
1770
|
const compressibleMsgs = [];
|
|
1736
1771
|
const protectedMsgs = [];
|
|
1737
1772
|
const protectedCallIds = collectProtectedToolCallIds(messages, config);
|
|
1738
|
-
const latest = collectLatestProtected(messages, config);
|
|
1739
|
-
for (const id of latest.callIds) protectedCallIds.add(id);
|
|
1740
1773
|
let skipSinceCompressible = false;
|
|
1741
1774
|
let skipSinceProtected = false;
|
|
1742
1775
|
for (const msg of messages) {
|
|
@@ -1747,7 +1780,7 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
1747
1780
|
skipSinceProtected = true;
|
|
1748
1781
|
continue;
|
|
1749
1782
|
}
|
|
1750
|
-
if (isMessageProtectedWithPairing(msg, config, protectedCallIds)
|
|
1783
|
+
if (isMessageProtectedWithPairing(msg, config, protectedCallIds)) {
|
|
1751
1784
|
protectedMsgs.push({
|
|
1752
1785
|
ref,
|
|
1753
1786
|
gapBefore: skipSinceProtected,
|
|
@@ -1915,8 +1948,11 @@ function danglingMessageRefs(state, messages, spec) {
|
|
|
1915
1948
|
if (!parsed || parsed.kind !== "message") continue;
|
|
1916
1949
|
const rawId = state.messageRefs.byRef[parsed.raw] ?? state.messageRefs.byRef[indexToRef(parsed.numericId)];
|
|
1917
1950
|
if (!rawId || visible.has(rawId)) continue;
|
|
1951
|
+
const base = baseMessageId(rawId);
|
|
1918
1952
|
const covered = state.blocks.some(
|
|
1919
|
-
(block) => block.active && block.effectiveMessageIds.
|
|
1953
|
+
(block) => block.active && block.effectiveMessageIds.some(
|
|
1954
|
+
(id) => id === rawId || baseMessageId(id) === base
|
|
1955
|
+
)
|
|
1920
1956
|
);
|
|
1921
1957
|
if (!covered) dangling.push(parsed.raw);
|
|
1922
1958
|
}
|
|
@@ -1937,7 +1973,7 @@ function createCore(ports = {}) {
|
|
|
1937
1973
|
input.config,
|
|
1938
1974
|
countTokens
|
|
1939
1975
|
);
|
|
1940
|
-
const preExistingCoverage =
|
|
1976
|
+
const preExistingCoverage = coveredMessageIds(state);
|
|
1941
1977
|
const classifications = /* @__PURE__ */ new Map();
|
|
1942
1978
|
const classificationErrors = [];
|
|
1943
1979
|
const consumedRanges = [];
|
|
@@ -2101,7 +2137,7 @@ function createCore(ports = {}) {
|
|
|
2101
2137
|
}
|
|
2102
2138
|
const ctx = {
|
|
2103
2139
|
config: input.config,
|
|
2104
|
-
tokenCount: input.tokenCount,
|
|
2140
|
+
tokenCount: input.tokenCount + (input.extraTokens ?? 0),
|
|
2105
2141
|
countTokens
|
|
2106
2142
|
};
|
|
2107
2143
|
const initial = {
|
|
@@ -2147,6 +2183,7 @@ function createCore(ports = {}) {
|
|
|
2147
2183
|
const base = [
|
|
2148
2184
|
assignRefsNode,
|
|
2149
2185
|
syncBlocksNode,
|
|
2186
|
+
stripReasoningNode,
|
|
2150
2187
|
pruneNode,
|
|
2151
2188
|
absorbHideNode,
|
|
2152
2189
|
absorbPromptNode,
|
|
@@ -2171,9 +2208,8 @@ function createCore(ports = {}) {
|
|
|
2171
2208
|
var assignRefsNode = {
|
|
2172
2209
|
name: "assign-refs",
|
|
2173
2210
|
run(io, ctx) {
|
|
2174
|
-
const hasProtection = ctx.config.protectedTools.length > 0 || !!ctx.config.isToolProtected
|
|
2175
|
-
const
|
|
2176
|
-
const protectedFn = hasProtection ? (m) => isMessageProtected(m, ctx.config) || (latest ? isMessageLatestProtected(m, latest) : false) : void 0;
|
|
2211
|
+
const hasProtection = ctx.config.protectedTools.length > 0 || !!ctx.config.isToolProtected;
|
|
2212
|
+
const protectedFn = hasProtection ? (m) => isMessageProtected(m, ctx.config) : void 0;
|
|
2177
2213
|
const refResult = assignRefs(io.messages, {
|
|
2178
2214
|
existing: io.state.messageRefs,
|
|
2179
2215
|
nextIndex: highestUsedIndex(io.state.messageRefs) + 1,
|
|
@@ -2190,6 +2226,21 @@ var syncBlocksNode = {
|
|
|
2190
2226
|
return { ...io, state: synced.state };
|
|
2191
2227
|
}
|
|
2192
2228
|
};
|
|
2229
|
+
var stripReasoningNode = {
|
|
2230
|
+
name: "strip-reasoning",
|
|
2231
|
+
enabled: (_io, ctx) => ctx.config.reasoningReplay === "open-round" || ctx.config.reasoningReplay === "never",
|
|
2232
|
+
run(io, ctx) {
|
|
2233
|
+
const { messages, stripped } = stripReasoningByRound(
|
|
2234
|
+
io.messages,
|
|
2235
|
+
ctx.config.reasoningReplay
|
|
2236
|
+
);
|
|
2237
|
+
return {
|
|
2238
|
+
...io,
|
|
2239
|
+
messages,
|
|
2240
|
+
effects: { ...io.effects, reasoningStrippedCount: stripped }
|
|
2241
|
+
};
|
|
2242
|
+
}
|
|
2243
|
+
};
|
|
2193
2244
|
var pruneNode = {
|
|
2194
2245
|
name: "prune",
|
|
2195
2246
|
run(io) {
|
|
@@ -2514,8 +2565,6 @@ function validateCompressionRange(input, directMessageIds, consumedBlockCount) {
|
|
|
2514
2565
|
function filterProtectedToolMessages(directMessageIds, messages, config) {
|
|
2515
2566
|
const protectedCallIds = /* @__PURE__ */ new Set();
|
|
2516
2567
|
const removedIds = /* @__PURE__ */ new Set();
|
|
2517
|
-
const latest = collectLatestProtected(messages, config);
|
|
2518
|
-
for (const id of latest.callIds) protectedCallIds.add(id);
|
|
2519
2568
|
for (const msg of messages) {
|
|
2520
2569
|
if (isMessageProtected(msg, config) && msg.toolCallId) {
|
|
2521
2570
|
protectedCallIds.add(msg.toolCallId);
|
|
@@ -2524,7 +2573,7 @@ function filterProtectedToolMessages(directMessageIds, messages, config) {
|
|
|
2524
2573
|
for (const id of directMessageIds) {
|
|
2525
2574
|
const msg = messages.find((m) => m.id === id);
|
|
2526
2575
|
if (!msg) continue;
|
|
2527
|
-
if (isMessageProtected(msg, config)
|
|
2576
|
+
if (isMessageProtected(msg, config)) {
|
|
2528
2577
|
removedIds.add(id);
|
|
2529
2578
|
if (msg.toolCallId) protectedCallIds.add(msg.toolCallId);
|
|
2530
2579
|
}
|
|
@@ -2549,13 +2598,6 @@ function resolveTargetTier(state, nestedBlockIds, isBlockBoundary) {
|
|
|
2549
2598
|
}
|
|
2550
2599
|
return minTier;
|
|
2551
2600
|
}
|
|
2552
|
-
function collectCoverage(state) {
|
|
2553
|
-
const coverage = /* @__PURE__ */ new Set();
|
|
2554
|
-
for (const block of activeBlocks(state)) {
|
|
2555
|
-
for (const id of block.effectiveMessageIds) coverage.add(id);
|
|
2556
|
-
}
|
|
2557
|
-
return coverage;
|
|
2558
|
-
}
|
|
2559
2601
|
function resolveAdaptiveGrowth(modelContextLimit, nudge) {
|
|
2560
2602
|
if (!modelContextLimit || modelContextLimit <= 0) return nudge.growthFloor;
|
|
2561
2603
|
return Math.min(
|
|
@@ -4096,6 +4138,7 @@ export {
|
|
|
4096
4138
|
applyAbsorb,
|
|
4097
4139
|
applyMessageFilters,
|
|
4098
4140
|
assignRefs,
|
|
4141
|
+
baseMessageId,
|
|
4099
4142
|
blockById,
|
|
4100
4143
|
blockDocs,
|
|
4101
4144
|
blockVisibleInRange,
|
|
@@ -4110,7 +4153,6 @@ export {
|
|
|
4110
4153
|
clearDocFeatures,
|
|
4111
4154
|
clearMessageFilters,
|
|
4112
4155
|
collectBlockContent,
|
|
4113
|
-
collectLatestProtected,
|
|
4114
4156
|
coveredMessageIds,
|
|
4115
4157
|
createBpeTokenizer,
|
|
4116
4158
|
createCore,
|
|
@@ -4135,8 +4177,9 @@ export {
|
|
|
4135
4177
|
highestUsedIndex,
|
|
4136
4178
|
indexToRef,
|
|
4137
4179
|
isAbsorbCandidate,
|
|
4138
|
-
|
|
4180
|
+
isIdCovered,
|
|
4139
4181
|
isMessageProtected,
|
|
4182
|
+
isRealUserMessage,
|
|
4140
4183
|
isRenderedSummaryMessage,
|
|
4141
4184
|
isSummaryMessageId,
|
|
4142
4185
|
listMessageFilters,
|
|
@@ -4170,6 +4213,7 @@ export {
|
|
|
4170
4213
|
searchBlocks,
|
|
4171
4214
|
searchBlocksAsync,
|
|
4172
4215
|
setDocCacheCap,
|
|
4216
|
+
stripReasoningByRound,
|
|
4173
4217
|
summaryMessageId,
|
|
4174
4218
|
syncBlocks,
|
|
4175
4219
|
truncateLargeToolOutputs,
|