acp-kernel 0.0.82-pr.233.214 → 0.0.82-pr.235.211

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.
@@ -42,8 +42,8 @@ export declare function resolveBoundaries(input: ResolveBoundariesInput): Resolv
42
42
  * active block whose raws were pruned becomes unresolvable and cannot be
43
43
  * promoted (dog/billion-context-pi#195).
44
44
  */
45
- export declare function visibleBlockAnchor(block: CompressionBlock, indexByMessageId: Map<string, number>): number | null;
46
- export declare function blockVisibleInRange(block: CompressionBlock, indexByMessageId: Map<string, number>, startIndex: number, endIndex: number): boolean;
47
- export declare function earliestIndexOfIds(ids: string[], indexByMessageId: Map<string, number>): number | null;
45
+ export declare function visibleBlockAnchor(block: CompressionBlock, indexByMessageId: Map<string, number>, baseIndexById?: Map<string, number>): number | null;
46
+ export declare function blockVisibleInRange(block: CompressionBlock, indexByMessageId: Map<string, number>, startIndex: number, endIndex: number, baseIndexById?: Map<string, number>): boolean;
47
+ export declare function earliestIndexOfIds(ids: string[], indexByMessageId: Map<string, number>, baseIndexById?: Map<string, number>): number | null;
48
48
  export declare function toResolvedBoundary(range: ResolvedRange): ResolvedBoundary;
49
49
  //# sourceMappingURL=boundaries.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"boundaries.d.ts","sourceRoot":"","sources":["../src/boundaries.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,OAAO,CAAC;AAE/C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;CACb;AAKD,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAehE;AAED;;;;;;GAMG;AACH,qBA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AAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,2BAA2B,CACvC,QAAQ,EAAE,WAAW,EAAE,EACvB,sBAAsB,EAAE,GAAG,CAAC,MAAM,CAAC,EACnC,KAAK,EAAE,gBAAgB,GACxB,qBAAqB,CAgCvB;AAED,MAAM,WAAW,sBAAsB;IACnC,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,6GAA6G;IAC7G,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IAClC,kKAAkK;IAClK,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CAC/B,KAAK,EAAE,gBAAgB,EACvB,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,WAAW,EAAE,EACvB,OAAO,GAAE,qBAA0B,GACpC,sBAAsB,CA0CxB"}
package/dist/index.js CHANGED
@@ -496,14 +496,20 @@ function resolveBoundaries(input) {
496
496
  );
497
497
  }
498
498
  const indexByMessageId = /* @__PURE__ */ new Map();
499
- input.messages.forEach(
500
- (message, index) => indexByMessageId.set(message.id, index)
501
- );
499
+ const baseIndexById = /* @__PURE__ */ new Map();
500
+ input.messages.forEach((message, index) => {
501
+ indexByMessageId.set(message.id, index);
502
+ const base = baseIdOf(message.id);
503
+ const existing = baseIndexById.get(base);
504
+ if (existing === void 0 || index < existing)
505
+ baseIndexById.set(base, index);
506
+ });
502
507
  let snappedBoundaries = [];
503
508
  const startAnchor = resolveAnchorIndex(
504
509
  start,
505
510
  input.state,
506
511
  indexByMessageId,
512
+ baseIndexById,
507
513
  "start"
508
514
  );
509
515
  if (startAnchor.snapped) snappedBoundaries.push(startAnchor.snapped);
@@ -511,6 +517,7 @@ function resolveBoundaries(input) {
511
517
  end,
512
518
  input.state,
513
519
  indexByMessageId,
520
+ baseIndexById,
514
521
  "end"
515
522
  );
516
523
  if (endAnchor.snapped) snappedBoundaries.push(endAnchor.snapped);
@@ -529,7 +536,13 @@ function resolveBoundaries(input) {
529
536
  const nestedBlockIds = [];
530
537
  const nestedSeen = /* @__PURE__ */ new Set();
531
538
  for (const block of activeBlocks(input.state)) {
532
- if (blockVisibleInRange(block, indexByMessageId, startIndex, endIndex)) {
539
+ if (blockVisibleInRange(
540
+ block,
541
+ indexByMessageId,
542
+ startIndex,
543
+ endIndex,
544
+ baseIndexById
545
+ )) {
533
546
  if (!nestedSeen.has(block.blockId)) {
534
547
  nestedSeen.add(block.blockId);
535
548
  nestedBlockIds.push(block.blockId);
@@ -547,7 +560,7 @@ function resolveBoundaries(input) {
547
560
  snappedBoundaries
548
561
  };
549
562
  }
550
- function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
563
+ function resolveAnchorIndex(boundary, state, indexByMessageId, baseIndexById, endpoint) {
551
564
  const label = endpoint === "start" ? "startId" : "endId";
552
565
  if (boundary.kind === "message") {
553
566
  const rawId = state.messageRefs.byRef[boundary.raw] ?? state.messageRefs.byRef[formatPaddedRef(boundary.numericId)];
@@ -558,11 +571,11 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
558
571
  `${label}="${boundary.raw}" does not exist in this session (typo or wrong session) \u2014 run acp_status for current refs.`
559
572
  );
560
573
  }
561
- const index = indexByMessageId.get(rawId);
574
+ const index = indexByMessageId.get(rawId) ?? baseIndexById.get(baseIdOf(rawId));
562
575
  if (index !== void 0) {
563
576
  return { index, snapped: null };
564
577
  }
565
- const owner2 = activeOwnerAnchor(state, [rawId], indexByMessageId);
578
+ const owner2 = activeOwnerAnchor(state, [rawId], indexByMessageId, baseIndexById);
566
579
  if (owner2 !== null) {
567
580
  return {
568
581
  index: owner2,
@@ -584,7 +597,7 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
584
597
  );
585
598
  }
586
599
  if (block.active) {
587
- const anchor = visibleBlockAnchor(block, indexByMessageId);
600
+ const anchor = visibleBlockAnchor(block, indexByMessageId, baseIndexById);
588
601
  if (anchor !== null) {
589
602
  return { index: anchor, snapped: null };
590
603
  }
@@ -592,7 +605,8 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
592
605
  const owner = activeOwnerAnchor(
593
606
  state,
594
607
  block.effectiveMessageIds,
595
- indexByMessageId
608
+ indexByMessageId,
609
+ baseIndexById
596
610
  );
597
611
  if (owner !== null) {
598
612
  return {
@@ -613,9 +627,10 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
613
627
  `${label}="b${boundary.numericId}" is an active block but none of its content (raw messages or rendered summary) is visible in the current context \u2014 run acp_status to verify.`
614
628
  );
615
629
  }
616
- function activeOwnerAnchor(state, ownedIds, indexByMessageId) {
630
+ function activeOwnerAnchor(state, ownedIds, indexByMessageId, baseIndexById) {
617
631
  if (ownedIds.length === 0) return null;
618
- const owned = new Set(ownedIds);
632
+ const owned = /* @__PURE__ */ new Set();
633
+ for (const id of ownedIds) owned.add(baseIdOf(id));
619
634
  let best = null;
620
635
  for (const block of state.blocks) {
621
636
  if (!block.active) continue;
@@ -628,7 +643,7 @@ function activeOwnerAnchor(state, ownedIds, indexByMessageId) {
628
643
  }
629
644
  }
630
645
  if (!ownsInherited) continue;
631
- const anchor = visibleBlockAnchor(block, indexByMessageId);
646
+ const anchor = visibleBlockAnchor(block, indexByMessageId, baseIndexById);
632
647
  if (anchor === null) continue;
633
648
  if (best === null || anchor < best) {
634
649
  best = anchor;
@@ -641,39 +656,54 @@ function inheritedContentIds(state, block) {
641
656
  for (const childId of block.directBlockIds) {
642
657
  const child = blockById(state, childId);
643
658
  if (!child) continue;
644
- for (const id of child.effectiveMessageIds) ids.add(id);
659
+ for (const id of child.effectiveMessageIds) ids.add(baseIdOf(id));
645
660
  }
646
661
  return ids;
647
662
  }
648
663
  function formatPaddedRef(index) {
649
664
  return `m${String(index).padStart(5, "0")}`;
650
665
  }
651
- function visibleBlockAnchor(block, indexByMessageId) {
666
+ function visibleBlockAnchor(block, indexByMessageId, baseIndexById) {
652
667
  const summaryIndex = indexByMessageId.get(summaryMessageId(block.blockId));
653
668
  if (summaryIndex !== void 0) return summaryIndex;
654
- return earliestIndexOfIds(block.effectiveMessageIds, indexByMessageId);
669
+ return earliestIndexOfIds(
670
+ block.effectiveMessageIds,
671
+ indexByMessageId,
672
+ baseIndexById
673
+ );
655
674
  }
656
- function blockVisibleInRange(block, indexByMessageId, startIndex, endIndex) {
675
+ function blockVisibleInRange(block, indexByMessageId, startIndex, endIndex, baseIndexById) {
657
676
  const summaryIndex = indexByMessageId.get(summaryMessageId(block.blockId));
658
677
  if (summaryIndex !== void 0 && summaryIndex >= startIndex && summaryIndex <= endIndex) {
659
678
  return true;
660
679
  }
661
680
  const rawIndex = earliestIndexOfIds(
662
681
  block.effectiveMessageIds,
663
- indexByMessageId
682
+ indexByMessageId,
683
+ baseIndexById
664
684
  );
665
685
  return rawIndex !== null && rawIndex >= startIndex && rawIndex <= endIndex;
666
686
  }
667
- function earliestIndexOfIds(ids, indexByMessageId) {
687
+ function earliestIndexOfIds(ids, indexByMessageId, baseIndexById) {
688
+ const baseIndex = baseIndexById ?? deriveBaseIndex(indexByMessageId);
668
689
  let earliest = null;
669
690
  for (const id of ids) {
670
- const index = indexByMessageId.get(id);
691
+ const index = baseIndex.get(baseIdOf(id));
671
692
  if (index !== void 0 && (earliest === null || index < earliest)) {
672
693
  earliest = index;
673
694
  }
674
695
  }
675
696
  return earliest;
676
697
  }
698
+ function deriveBaseIndex(indexByMessageId) {
699
+ const baseIndex = /* @__PURE__ */ new Map();
700
+ for (const [id, index] of indexByMessageId) {
701
+ const base = baseIdOf(id);
702
+ const existing = baseIndex.get(base);
703
+ if (existing === void 0 || index < existing) baseIndex.set(base, index);
704
+ }
705
+ return baseIndex;
706
+ }
677
707
 
678
708
  // src/truncate-tools.ts
679
709
  var TRUNCATION_MARKER = "[truncated for context space]";
@@ -2205,20 +2235,26 @@ function estimateTextTokens(text) {
2205
2235
  function isToolMessage(message) {
2206
2236
  return message.contentType === "tool-call" || message.contentType === "tool-result";
2207
2237
  }
2208
- function isSyntheticOrPruned(message, state) {
2209
- if (message.text?.startsWith("[Compressed conversation section]")) return true;
2238
+ function activeBlockCoveredBases(state) {
2239
+ const covered = /* @__PURE__ */ new Set();
2210
2240
  for (const block of state.blocks) {
2211
- if (block.active && block.effectiveMessageIds.includes(message.id)) return true;
2241
+ if (!block.active) continue;
2242
+ for (const id of block.effectiveMessageIds) covered.add(baseIdOf(id));
2212
2243
  }
2213
- return false;
2244
+ return covered;
2245
+ }
2246
+ function isSyntheticOrPruned(message, coveredBases) {
2247
+ if (message.text?.startsWith("[Compressed conversation section]")) return true;
2248
+ return coveredBases.has(baseIdOf(message.id));
2214
2249
  }
2215
2250
  function computeProtectedRefs(messages, state, config, countTokens = estimateTextTokens) {
2216
2251
  const preserveN = config.preserveRecentMessages;
2217
2252
  const preserveTokens = config.preserveRecentTokens;
2218
2253
  const result = /* @__PURE__ */ new Set();
2219
2254
  const visible = [];
2255
+ const coveredBases = activeBlockCoveredBases(state);
2220
2256
  for (const msg of messages) {
2221
- if (isSyntheticOrPruned(msg, state)) continue;
2257
+ if (isSyntheticOrPruned(msg, coveredBases)) continue;
2222
2258
  if (isNeverPreserveRecent(msg)) continue;
2223
2259
  const ref = state.messageRefs.byRaw[msg.id];
2224
2260
  if (!ref || ref === "BLOCKED") continue;
@@ -2239,7 +2275,7 @@ function computeProtectedRefs(messages, state, config, countTokens = estimateTex
2239
2275
  if (preserveN > 0) {
2240
2276
  for (let i = messages.length - 1; i >= 0; i--) {
2241
2277
  const msg = messages[i];
2242
- if (msg.role !== "user" || isSyntheticOrPruned(msg, state)) continue;
2278
+ if (msg.role !== "user" || isSyntheticOrPruned(msg, coveredBases)) continue;
2243
2279
  const ref = state.messageRefs.byRaw[msg.id];
2244
2280
  if (ref && ref !== "BLOCKED") result.add(ref);
2245
2281
  break;
@@ -2256,11 +2292,12 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
2256
2292
  let skipSinceCompressible = false;
2257
2293
  let skipSinceProtected = false;
2258
2294
  let msgIndex = -1;
2295
+ const coveredBases = activeBlockCoveredBases(state);
2259
2296
  for (const msg of messages) {
2260
2297
  msgIndex++;
2261
2298
  const ref = state.messageRefs.byRaw[msg.id];
2262
2299
  if (!ref || ref === "BLOCKED") continue;
2263
- if (isSyntheticOrPruned(msg, state)) {
2300
+ if (isSyntheticOrPruned(msg, coveredBases)) {
2264
2301
  skipSinceCompressible = true;
2265
2302
  skipSinceProtected = true;
2266
2303
  continue;
@@ -2461,16 +2498,22 @@ function refGateDiagnostics(state, requestedRanges, unknownCount) {
2461
2498
  }
2462
2499
  function danglingMessageRefs(state, messages, spec) {
2463
2500
  const visible = new Set(messages.map((m) => m.id));
2501
+ const visibleBases = /* @__PURE__ */ new Set();
2502
+ for (const id of visible) visibleBases.add(baseIdOf(id));
2503
+ const coveredBases = /* @__PURE__ */ new Set();
2504
+ for (const block of state.blocks) {
2505
+ if (!block.active) continue;
2506
+ for (const id of block.effectiveMessageIds) coveredBases.add(baseIdOf(id));
2507
+ }
2464
2508
  const dangling = [];
2465
2509
  for (const ref of [spec.startRef, spec.endRef]) {
2466
2510
  const parsed = parseBoundary(ref);
2467
2511
  if (!parsed || parsed.kind !== "message") continue;
2468
2512
  const rawId = state.messageRefs.byRef[parsed.raw] ?? state.messageRefs.byRef[indexToRef(parsed.numericId)];
2469
- if (!rawId || visible.has(rawId)) continue;
2470
- const covered = state.blocks.some(
2471
- (block) => block.active && block.effectiveMessageIds.includes(rawId)
2472
- );
2473
- if (!covered) dangling.push(parsed.raw);
2513
+ if (!rawId) continue;
2514
+ const base = baseIdOf(rawId);
2515
+ if (visible.has(rawId) || visibleBases.has(base)) continue;
2516
+ if (!coveredBases.has(base)) dangling.push(parsed.raw);
2474
2517
  }
2475
2518
  return dangling;
2476
2519
  }
@@ -2977,13 +3020,25 @@ function applySingleRange(input) {
2977
3020
  );
2978
3021
  if (rangeMessageIds.length > resolved.messageIds.length) {
2979
3022
  const indexByMessageId = /* @__PURE__ */ new Map();
2980
- input.messages.forEach((m, i) => indexByMessageId.set(m.id, i));
3023
+ const baseIndexById = /* @__PURE__ */ new Map();
3024
+ input.messages.forEach((m, i) => {
3025
+ indexByMessageId.set(m.id, i);
3026
+ const base = baseIdOf(m.id);
3027
+ const existing = baseIndexById.get(base);
3028
+ if (existing === void 0 || i < existing) baseIndexById.set(base, i);
3029
+ });
2981
3030
  const adjustedStart = rangeMessageIds.length > 0 ? indexByMessageId.get(rangeMessageIds[0]) ?? resolved.startIndex : resolved.startIndex;
2982
3031
  const adjustedEnd = rangeMessageIds.length > 0 ? indexByMessageId.get(rangeMessageIds[rangeMessageIds.length - 1]) ?? resolved.endIndex : resolved.endIndex;
2983
3032
  const nestedSeen = new Set(resolved.nestedBlockIds);
2984
3033
  for (const block2 of activeBlocks(input.state)) {
2985
3034
  if (nestedSeen.has(block2.blockId)) continue;
2986
- if (blockVisibleInRange(block2, indexByMessageId, adjustedStart, adjustedEnd)) {
3035
+ if (blockVisibleInRange(
3036
+ block2,
3037
+ indexByMessageId,
3038
+ adjustedStart,
3039
+ adjustedEnd,
3040
+ baseIndexById
3041
+ )) {
2987
3042
  nestedSeen.add(block2.blockId);
2988
3043
  resolved.nestedBlockIds.push(block2.blockId);
2989
3044
  }
@@ -3009,7 +3064,7 @@ function applySingleRange(input) {
3009
3064
  }
3010
3065
  }
3011
3066
  const directMessageIds = [...effectiveMessageIds].filter(
3012
- (id) => !input.preExistingCoverage.has(id)
3067
+ (id) => !input.preExistingCoverage.has(baseIdOf(id))
3013
3068
  );
3014
3069
  let filteredIds = filterProtectedToolMessages(
3015
3070
  directMessageIds,
@@ -3215,7 +3270,7 @@ function resolveTargetTier(state, nestedBlockIds, isBlockBoundary) {
3215
3270
  function collectCoverage(state) {
3216
3271
  const coverage = /* @__PURE__ */ new Set();
3217
3272
  for (const block of activeBlocks(state)) {
3218
- for (const id of block.effectiveMessageIds) coverage.add(id);
3273
+ for (const id of block.effectiveMessageIds) coverage.add(baseIdOf(id));
3219
3274
  }
3220
3275
  return coverage;
3221
3276
  }
@@ -3730,10 +3785,12 @@ function parseBlockIdArg(arg) {
3730
3785
  }
3731
3786
  function findBlocksOverlappingMessages(state, messageIds) {
3732
3787
  if (messageIds.size === 0) return [];
3788
+ const messageBases = /* @__PURE__ */ new Set();
3789
+ for (const id of messageIds) messageBases.add(baseIdOf(id));
3733
3790
  const matched = [];
3734
3791
  for (const block of state.blocks) {
3735
3792
  if (!block.active) continue;
3736
- if (block.effectiveMessageIds.some((id) => messageIds.has(id))) {
3793
+ if (block.effectiveMessageIds.some((id) => messageBases.has(baseIdOf(id)))) {
3737
3794
  matched.push(block);
3738
3795
  }
3739
3796
  }
@@ -3790,13 +3847,15 @@ function deactivateBlock(state, blockIds, options = {}) {
3790
3847
  return { ...state, blocks: final };
3791
3848
  }
3792
3849
  function buildRestoredContentPreview(messages, beforeActiveMessageIds, state) {
3850
+ const coveredBases = /* @__PURE__ */ new Set();
3851
+ for (const b of state.blocks) {
3852
+ if (!b.active) continue;
3853
+ for (const id of b.effectiveMessageIds) coveredBases.add(baseIdOf(id));
3854
+ }
3793
3855
  const restored = [];
3794
3856
  for (const message of messages) {
3795
3857
  if (!beforeActiveMessageIds.has(message.id)) continue;
3796
- const stillCovered = state.blocks.some(
3797
- (b) => b.active && b.effectiveMessageIds.includes(message.id)
3798
- );
3799
- if (!stillCovered) restored.push(message);
3858
+ if (!coveredBases.has(baseIdOf(message.id))) restored.push(message);
3800
3859
  }
3801
3860
  if (restored.length === 0) return { preview: "", restoredCount: 0 };
3802
3861
  const lines = [];
@@ -3815,9 +3874,10 @@ function buildRestoredContentPreview(messages, beforeActiveMessageIds, state) {
3815
3874
  }
3816
3875
  function collectBlockContent(state, block, messages, options = {}) {
3817
3876
  const full = options.full ?? false;
3818
- const targetIds = new Set(block.effectiveMessageIds);
3877
+ const targetBases = /* @__PURE__ */ new Set();
3878
+ for (const id of block.effectiveMessageIds) targetBases.add(baseIdOf(id));
3819
3879
  if (full) {
3820
- const msgs = messages.filter((m) => targetIds.has(m.id));
3880
+ const msgs = messages.filter((m) => targetBases.has(baseIdOf(m.id)));
3821
3881
  if (msgs.length === 0) return { text: "", count: 0 };
3822
3882
  return { text: msgs.map(formatMessage).join("\n\n"), count: msgs.length };
3823
3883
  }
@@ -3827,7 +3887,7 @@ function collectBlockContent(state, block, messages, options = {}) {
3827
3887
  const child = state.blocks.find((b) => b.blockId === childId);
3828
3888
  if (!child?.active) continue;
3829
3889
  nestedChildren.push(child);
3830
- for (const id of child.effectiveMessageIds) nestedCovered.add(id);
3890
+ for (const id of child.effectiveMessageIds) nestedCovered.add(baseIdOf(id));
3831
3891
  }
3832
3892
  const parts = [];
3833
3893
  for (const child of nestedChildren) {
@@ -3837,7 +3897,8 @@ ${child.summary}`);
3837
3897
  }
3838
3898
  let directCount = 0;
3839
3899
  for (const m of messages) {
3840
- if (targetIds.has(m.id) && !nestedCovered.has(m.id)) {
3900
+ const base = baseIdOf(m.id);
3901
+ if (targetBases.has(base) && !nestedCovered.has(base)) {
3841
3902
  parts.push(formatMessage(m));
3842
3903
  directCount++;
3843
3904
  }
@@ -3899,7 +3960,7 @@ function collectVisible(messages, state, countTokens) {
3899
3960
  const coveredIds = /* @__PURE__ */ new Set();
3900
3961
  for (const block of state.blocks) {
3901
3962
  if (!block.active) continue;
3902
- for (const id of block.effectiveMessageIds) coveredIds.add(id);
3963
+ for (const id of block.effectiveMessageIds) coveredIds.add(baseIdOf(id));
3903
3964
  }
3904
3965
  let summaryTokens = 0;
3905
3966
  for (const block of state.blocks) {
@@ -3913,7 +3974,7 @@ function collectVisible(messages, state, countTokens) {
3913
3974
  }
3914
3975
  }
3915
3976
  messages.forEach((message, index) => {
3916
- if (coveredIds.has(message.id)) return;
3977
+ if (coveredIds.has(baseIdOf(message.id))) return;
3917
3978
  const ref = refForRaw(state.messageRefs, message.id);
3918
3979
  if (!ref) return;
3919
3980
  const tokens = countMessageTokens(message, countTokens);