@dexto/core 1.5.3 → 1.5.5

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.
Files changed (143) hide show
  1. package/dist/agent/DextoAgent.cjs +190 -1
  2. package/dist/agent/DextoAgent.d.ts +71 -0
  3. package/dist/agent/DextoAgent.d.ts.map +1 -1
  4. package/dist/agent/DextoAgent.js +181 -1
  5. package/dist/agent/schemas.d.ts +51 -21
  6. package/dist/agent/schemas.d.ts.map +1 -1
  7. package/dist/context/compaction/overflow.cjs +6 -10
  8. package/dist/context/compaction/overflow.d.ts +14 -11
  9. package/dist/context/compaction/overflow.d.ts.map +1 -1
  10. package/dist/context/compaction/overflow.js +6 -10
  11. package/dist/context/compaction/providers/reactive-overflow-provider.cjs +15 -0
  12. package/dist/context/compaction/providers/reactive-overflow-provider.d.ts +15 -0
  13. package/dist/context/compaction/providers/reactive-overflow-provider.d.ts.map +1 -1
  14. package/dist/context/compaction/providers/reactive-overflow-provider.js +15 -0
  15. package/dist/context/compaction/schemas.cjs +22 -2
  16. package/dist/context/compaction/schemas.d.ts +45 -0
  17. package/dist/context/compaction/schemas.d.ts.map +1 -1
  18. package/dist/context/compaction/schemas.js +22 -2
  19. package/dist/context/compaction/strategies/reactive-overflow.cjs +168 -26
  20. package/dist/context/compaction/strategies/reactive-overflow.d.ts +22 -0
  21. package/dist/context/compaction/strategies/reactive-overflow.d.ts.map +1 -1
  22. package/dist/context/compaction/strategies/reactive-overflow.js +168 -26
  23. package/dist/context/compaction/types.d.ts +13 -1
  24. package/dist/context/compaction/types.d.ts.map +1 -1
  25. package/dist/context/manager.cjs +278 -31
  26. package/dist/context/manager.d.ts +192 -5
  27. package/dist/context/manager.d.ts.map +1 -1
  28. package/dist/context/manager.js +285 -32
  29. package/dist/context/types.d.ts +6 -0
  30. package/dist/context/types.d.ts.map +1 -1
  31. package/dist/context/utils.cjs +77 -11
  32. package/dist/context/utils.d.ts +86 -8
  33. package/dist/context/utils.d.ts.map +1 -1
  34. package/dist/context/utils.js +71 -11
  35. package/dist/errors/types.cjs +0 -2
  36. package/dist/errors/types.d.ts +1 -5
  37. package/dist/errors/types.d.ts.map +1 -1
  38. package/dist/errors/types.js +0 -2
  39. package/dist/events/index.cjs +2 -0
  40. package/dist/events/index.d.ts +21 -6
  41. package/dist/events/index.d.ts.map +1 -1
  42. package/dist/events/index.js +2 -0
  43. package/dist/llm/executor/stream-processor.cjs +104 -28
  44. package/dist/llm/executor/stream-processor.d.ts +7 -0
  45. package/dist/llm/executor/stream-processor.d.ts.map +1 -1
  46. package/dist/llm/executor/stream-processor.js +104 -28
  47. package/dist/llm/executor/turn-executor.cjs +147 -30
  48. package/dist/llm/executor/turn-executor.d.ts +28 -10
  49. package/dist/llm/executor/turn-executor.d.ts.map +1 -1
  50. package/dist/llm/executor/turn-executor.js +147 -30
  51. package/dist/llm/formatters/vercel.cjs +36 -28
  52. package/dist/llm/formatters/vercel.d.ts.map +1 -1
  53. package/dist/llm/formatters/vercel.js +36 -28
  54. package/dist/llm/services/factory.cjs +3 -2
  55. package/dist/llm/services/factory.d.ts +3 -1
  56. package/dist/llm/services/factory.d.ts.map +1 -1
  57. package/dist/llm/services/factory.js +3 -2
  58. package/dist/llm/services/vercel.cjs +31 -6
  59. package/dist/llm/services/vercel.d.ts +18 -3
  60. package/dist/llm/services/vercel.d.ts.map +1 -1
  61. package/dist/llm/services/vercel.js +31 -6
  62. package/dist/session/chat-session.cjs +29 -13
  63. package/dist/session/chat-session.d.ts +6 -4
  64. package/dist/session/chat-session.d.ts.map +1 -1
  65. package/dist/session/chat-session.js +29 -13
  66. package/dist/session/session-manager.cjs +11 -0
  67. package/dist/session/session-manager.d.ts +7 -0
  68. package/dist/session/session-manager.d.ts.map +1 -1
  69. package/dist/session/session-manager.js +11 -0
  70. package/dist/session/title-generator.cjs +2 -2
  71. package/dist/session/title-generator.js +2 -2
  72. package/dist/systemPrompt/in-built-prompts.cjs +36 -0
  73. package/dist/systemPrompt/in-built-prompts.d.ts +18 -1
  74. package/dist/systemPrompt/in-built-prompts.d.ts.map +1 -1
  75. package/dist/systemPrompt/in-built-prompts.js +25 -0
  76. package/dist/systemPrompt/manager.cjs +22 -0
  77. package/dist/systemPrompt/manager.d.ts +10 -0
  78. package/dist/systemPrompt/manager.d.ts.map +1 -1
  79. package/dist/systemPrompt/manager.js +22 -0
  80. package/dist/systemPrompt/registry.cjs +2 -1
  81. package/dist/systemPrompt/registry.d.ts +1 -1
  82. package/dist/systemPrompt/registry.d.ts.map +1 -1
  83. package/dist/systemPrompt/registry.js +2 -1
  84. package/dist/systemPrompt/schemas.cjs +7 -0
  85. package/dist/systemPrompt/schemas.d.ts +13 -13
  86. package/dist/systemPrompt/schemas.d.ts.map +1 -1
  87. package/dist/systemPrompt/schemas.js +7 -0
  88. package/dist/telemetry/telemetry.cjs +12 -5
  89. package/dist/telemetry/telemetry.d.ts.map +1 -1
  90. package/dist/telemetry/telemetry.js +12 -5
  91. package/dist/utils/index.cjs +3 -1
  92. package/dist/utils/index.d.ts +1 -0
  93. package/dist/utils/index.d.ts.map +1 -1
  94. package/dist/utils/index.js +1 -0
  95. package/package.json +15 -5
  96. package/dist/filesystem/error-codes.cjs +0 -53
  97. package/dist/filesystem/error-codes.d.ts +0 -31
  98. package/dist/filesystem/error-codes.d.ts.map +0 -1
  99. package/dist/filesystem/error-codes.js +0 -30
  100. package/dist/filesystem/errors.cjs +0 -303
  101. package/dist/filesystem/errors.d.ts +0 -109
  102. package/dist/filesystem/errors.d.ts.map +0 -1
  103. package/dist/filesystem/errors.js +0 -280
  104. package/dist/filesystem/filesystem-service.cjs +0 -534
  105. package/dist/filesystem/filesystem-service.d.ts +0 -97
  106. package/dist/filesystem/filesystem-service.d.ts.map +0 -1
  107. package/dist/filesystem/filesystem-service.js +0 -501
  108. package/dist/filesystem/index.cjs +0 -37
  109. package/dist/filesystem/index.d.ts +0 -11
  110. package/dist/filesystem/index.d.ts.map +0 -1
  111. package/dist/filesystem/index.js +0 -11
  112. package/dist/filesystem/path-validator.cjs +0 -250
  113. package/dist/filesystem/path-validator.d.ts +0 -103
  114. package/dist/filesystem/path-validator.d.ts.map +0 -1
  115. package/dist/filesystem/path-validator.js +0 -217
  116. package/dist/filesystem/types.cjs +0 -16
  117. package/dist/filesystem/types.d.ts +0 -175
  118. package/dist/filesystem/types.d.ts.map +0 -1
  119. package/dist/filesystem/types.js +0 -0
  120. package/dist/process/command-validator.cjs +0 -554
  121. package/dist/process/command-validator.d.ts +0 -49
  122. package/dist/process/command-validator.d.ts.map +0 -1
  123. package/dist/process/command-validator.js +0 -531
  124. package/dist/process/error-codes.cjs +0 -47
  125. package/dist/process/error-codes.d.ts +0 -25
  126. package/dist/process/error-codes.d.ts.map +0 -1
  127. package/dist/process/error-codes.js +0 -24
  128. package/dist/process/errors.cjs +0 -244
  129. package/dist/process/errors.d.ts +0 -87
  130. package/dist/process/errors.d.ts.map +0 -1
  131. package/dist/process/errors.js +0 -221
  132. package/dist/process/index.cjs +0 -37
  133. package/dist/process/index.d.ts +0 -11
  134. package/dist/process/index.d.ts.map +0 -1
  135. package/dist/process/index.js +0 -11
  136. package/dist/process/process-service.cjs +0 -497
  137. package/dist/process/process-service.d.ts +0 -69
  138. package/dist/process/process-service.d.ts.map +0 -1
  139. package/dist/process/process-service.js +0 -464
  140. package/dist/process/types.cjs +0 -16
  141. package/dist/process/types.d.ts +0 -107
  142. package/dist/process/types.d.ts.map +0 -1
  143. package/dist/process/types.js +0 -0
@@ -3,7 +3,13 @@ import { randomUUID } from "crypto";
3
3
  import { isSystemMessage, isUserMessage, isAssistantMessage, isToolMessage } from "./types.js";
4
4
  import { DextoLogComponent } from "../logger/v2/types.js";
5
5
  import { eventBus } from "../events/index.js";
6
- import { expandBlobReferences, isLikelyBase64String, filterCompacted } from "./utils.js";
6
+ import {
7
+ expandBlobReferences,
8
+ isLikelyBase64String,
9
+ filterCompacted,
10
+ estimateContextTokens,
11
+ estimateMessagesTokens
12
+ } from "./utils.js";
7
13
  import { ContextError } from "./errors.js";
8
14
  class ContextManager {
9
15
  /**
@@ -22,6 +28,23 @@ class ContextManager {
22
28
  * Maximum number of tokens allowed in the conversation (if specified)
23
29
  */
24
30
  maxInputTokens;
31
+ /**
32
+ * Last known actual input token count from the LLM API response.
33
+ * Updated after each LLM call. Used by /context for accurate reporting.
34
+ */
35
+ lastActualInputTokens = null;
36
+ /**
37
+ * Last known actual output token count from the LLM API response.
38
+ * Updated after each LLM call. Used in the context estimation formula:
39
+ * estimatedNextInput = lastInputTokens + lastOutputTokens + newMessagesEstimate
40
+ */
41
+ lastActualOutputTokens = null;
42
+ /**
43
+ * Message count at the time of the last LLM call.
44
+ * Used to identify which messages are "new" since the last call.
45
+ * Messages after this index are estimated with length/4 heuristic.
46
+ */
47
+ lastCallMessageCount = null;
25
48
  historyProvider;
26
49
  sessionId;
27
50
  /**
@@ -120,6 +143,119 @@ class ContextManager {
120
143
  getMaxInputTokens() {
121
144
  return this.maxInputTokens;
122
145
  }
146
+ /**
147
+ * Returns the last known actual input token count from the LLM API.
148
+ * Returns null if no LLM call has been made yet.
149
+ */
150
+ getLastActualInputTokens() {
151
+ return this.lastActualInputTokens;
152
+ }
153
+ /**
154
+ * Updates the last known actual input token count.
155
+ * Called after each LLM response with the actual usage from the API.
156
+ */
157
+ setLastActualInputTokens(tokens) {
158
+ this.lastActualInputTokens = tokens;
159
+ this.logger.debug(`Updated lastActualInputTokens: ${tokens}`);
160
+ }
161
+ /**
162
+ * Returns the last known actual output token count from the LLM API.
163
+ * Returns null if no LLM call has been made yet.
164
+ */
165
+ getLastActualOutputTokens() {
166
+ return this.lastActualOutputTokens;
167
+ }
168
+ /**
169
+ * Updates the last known actual output token count.
170
+ * Called after each LLM response with the actual usage from the API.
171
+ */
172
+ setLastActualOutputTokens(tokens) {
173
+ this.lastActualOutputTokens = tokens;
174
+ this.logger.debug(`Updated lastActualOutputTokens: ${tokens}`);
175
+ }
176
+ /**
177
+ * Returns the message count at the time of the last LLM call.
178
+ * Returns null if no LLM call has been made yet.
179
+ */
180
+ getLastCallMessageCount() {
181
+ return this.lastCallMessageCount;
182
+ }
183
+ /**
184
+ * Records the current message count after an LLM call completes.
185
+ * This marks the boundary for "new messages" calculation.
186
+ */
187
+ async recordLastCallMessageCount() {
188
+ const history = await this.historyProvider.getHistory();
189
+ this.lastCallMessageCount = history.length;
190
+ this.logger.debug(`Recorded lastCallMessageCount: ${this.lastCallMessageCount}`);
191
+ }
192
+ /**
193
+ * Resets the actual token tracking state.
194
+ * Called after compaction since the context has fundamentally changed.
195
+ */
196
+ resetActualTokenTracking() {
197
+ this.lastActualInputTokens = null;
198
+ this.lastActualOutputTokens = null;
199
+ this.lastCallMessageCount = null;
200
+ this.logger.debug("Reset actual token tracking state (after compaction)");
201
+ }
202
+ // ============= HISTORY PREPARATION =============
203
+ /**
204
+ * Placeholder text used when tool outputs are pruned.
205
+ * Shared constant to ensure consistency between preparation and estimation.
206
+ */
207
+ static PRUNED_TOOL_PLACEHOLDER = "[Old tool result content cleared]";
208
+ /**
209
+ * Prepares conversation history for LLM consumption.
210
+ * This is the single source of truth for history transformation logic.
211
+ *
212
+ * Transformations applied:
213
+ * 1. filterCompacted - Remove pre-summary messages (messages before the most recent summary)
214
+ * 2. Transform pruned tool messages - Replace compactedAt messages with placeholder text
215
+ *
216
+ * Used by both:
217
+ * - getFormattedMessagesForLLM() - For actual LLM calls
218
+ * - getContextTokenEstimate() - For /context command estimation
219
+ *
220
+ * @returns Prepared history and statistics about the transformations
221
+ */
222
+ async prepareHistory() {
223
+ const fullHistory = await this.historyProvider.getHistory();
224
+ const originalCount = fullHistory.length;
225
+ let history = filterCompacted(fullHistory);
226
+ const filteredCount = history.length;
227
+ if (filteredCount < originalCount) {
228
+ this.logger.debug(
229
+ `prepareHistory: filterCompacted reduced from ${originalCount} to ${filteredCount} messages`
230
+ );
231
+ }
232
+ let prunedToolCount = 0;
233
+ history = history.map((msg) => {
234
+ if (msg.role === "tool" && msg.compactedAt) {
235
+ prunedToolCount++;
236
+ return {
237
+ ...msg,
238
+ content: [
239
+ { type: "text", text: ContextManager.PRUNED_TOOL_PLACEHOLDER }
240
+ ]
241
+ };
242
+ }
243
+ return msg;
244
+ });
245
+ if (prunedToolCount > 0) {
246
+ this.logger.debug(
247
+ `prepareHistory: Transformed ${prunedToolCount} pruned tool messages to placeholders`
248
+ );
249
+ }
250
+ return {
251
+ preparedHistory: history,
252
+ stats: {
253
+ originalCount,
254
+ filteredCount,
255
+ prunedToolCount
256
+ }
257
+ };
258
+ }
123
259
  /**
124
260
  * Assembles and returns the current system prompt by invoking the SystemPromptManager.
125
261
  */
@@ -168,6 +304,7 @@ ${prompt}`);
168
304
  }
169
305
  };
170
306
  await this.addMessage(clearMarker);
307
+ this.resetActualTokenTracking();
171
308
  this.logger.debug(`Context cleared for session: ${this.sessionId}`);
172
309
  }
173
310
  /**
@@ -539,51 +676,166 @@ ${prompt}`);
539
676
  /**
540
677
  * Gets the conversation ready for LLM consumption with proper flow:
541
678
  * 1. Get system prompt
542
- * 2. Get history and filter (exclude pre-summary messages)
543
- * 3. Format messages
544
- * This method implements the correct ordering to avoid circular dependencies.
679
+ * 2. Prepare history (filter + transform pruned messages)
680
+ * 3. Format messages for LLM API
545
681
  *
546
682
  * @param contributorContext The DynamicContributorContext for system prompt contributors and formatting
547
683
  * @param llmContext The llmContext for the formatter to decide which messages to include based on the model's capabilities
548
- * @returns Object containing formatted messages and system prompt
684
+ * @returns Object containing formatted messages, system prompt, and prepared history
549
685
  */
550
- async getFormattedMessagesWithCompression(contributorContext, llmContext) {
686
+ async getFormattedMessagesForLLM(contributorContext, llmContext) {
551
687
  const systemPrompt = await this.getSystemPrompt(contributorContext);
552
- const fullHistory = await this.historyProvider.getHistory();
553
- let history = filterCompacted(fullHistory);
554
- if (history.length < fullHistory.length) {
555
- this.logger.debug(
556
- `filterCompacted: Reduced history from ${fullHistory.length} to ${history.length} messages (summary present)`
557
- );
558
- }
559
- const compactedCount = history.filter((m) => m.role === "tool" && m.compactedAt).length;
560
- if (compactedCount > 0) {
561
- history = history.map((msg) => {
562
- if (msg.role === "tool" && msg.compactedAt) {
563
- return {
564
- ...msg,
565
- content: [
566
- { type: "text", text: "[Old tool result content cleared]" }
567
- ]
568
- };
569
- }
570
- return msg;
571
- });
572
- this.logger.debug(
573
- `Transformed ${compactedCount} compacted tool messages to placeholders`
574
- );
575
- }
688
+ const { preparedHistory } = await this.prepareHistory();
576
689
  const formattedMessages = await this.getFormattedMessages(
577
690
  contributorContext,
578
691
  llmContext,
579
692
  systemPrompt,
580
- history
693
+ preparedHistory
581
694
  );
582
695
  return {
583
696
  formattedMessages,
584
- systemPrompt
697
+ systemPrompt,
698
+ preparedHistory
699
+ };
700
+ }
701
+ /**
702
+ * Estimates context token usage for the /context command and compaction decisions.
703
+ * Uses the same prepareHistory() logic as getFormattedMessagesForLLM() to ensure consistency.
704
+ *
705
+ * When actuals are available from previous LLM calls:
706
+ * estimatedNextInput = lastInputTokens + lastOutputTokens + newMessagesEstimate
707
+ *
708
+ * This formula is more accurate because:
709
+ * - lastInputTokens: exactly what the API processed (ground truth)
710
+ * - lastOutputTokens: exactly what the LLM returned (ground truth)
711
+ * - newMessagesEstimate: only estimate the delta (tool results, new user messages)
712
+ *
713
+ * When no LLM call has been made yet (or after compaction), falls back to pure estimation.
714
+ *
715
+ * @param contributorContext Context for building the system prompt
716
+ * @param tools Tool definitions to include in the estimate
717
+ * @returns Token estimates with breakdown and comparison to actual (if available)
718
+ */
719
+ async getContextTokenEstimate(contributorContext, tools) {
720
+ const systemPrompt = await this.getSystemPrompt(contributorContext);
721
+ const { preparedHistory, stats } = await this.prepareHistory();
722
+ const lastInput = this.lastActualInputTokens;
723
+ const lastOutput = this.lastActualOutputTokens;
724
+ const lastMsgCount = this.lastCallMessageCount;
725
+ const currentHistory = await this.historyProvider.getHistory();
726
+ const pureEstimate = estimateContextTokens(systemPrompt, preparedHistory, tools);
727
+ let total;
728
+ let calculationBasis;
729
+ if (lastInput !== null && lastOutput !== null && lastMsgCount !== null) {
730
+ const newMessages = currentHistory.slice(lastMsgCount);
731
+ const newMessagesEstimate = estimateMessagesTokens(newMessages);
732
+ total = lastInput + lastOutput + newMessagesEstimate;
733
+ calculationBasis = {
734
+ method: "actuals",
735
+ lastInputTokens: lastInput,
736
+ lastOutputTokens: lastOutput,
737
+ newMessagesEstimate
738
+ };
739
+ this.logger.info(
740
+ `Context estimate (actuals-based): lastInput=${lastInput}, lastOutput=${lastOutput}, newMsgs=${newMessagesEstimate} (${newMessages.length} messages), total=${total}`
741
+ );
742
+ } else {
743
+ total = pureEstimate.total;
744
+ calculationBasis = {
745
+ method: "estimate"
746
+ };
747
+ this.logger.debug(
748
+ `Context estimate (pure estimate): total=${total} (no actuals available yet)`
749
+ );
750
+ }
751
+ const systemPromptTokens = pureEstimate.breakdown.systemPrompt;
752
+ const toolsTokens = pureEstimate.breakdown.tools;
753
+ const messagesDisplay = Math.max(0, total - systemPromptTokens - toolsTokens.total);
754
+ if (lastInput !== null) {
755
+ const pureTotal = pureEstimate.total;
756
+ const diff = pureTotal - lastInput;
757
+ const diffPercent = lastInput > 0 ? (diff / lastInput * 100).toFixed(1) : "0.0";
758
+ this.logger.info(
759
+ `Context token calibration: pureEstimate=${pureTotal}, lastActual=${lastInput}, diff=${diff} (${diffPercent}%)`
760
+ );
761
+ }
762
+ return {
763
+ estimated: total,
764
+ actual: lastInput,
765
+ breakdown: {
766
+ systemPrompt: systemPromptTokens,
767
+ tools: toolsTokens,
768
+ messages: messagesDisplay
769
+ },
770
+ stats: {
771
+ originalMessageCount: stats.originalCount,
772
+ filteredMessageCount: stats.filteredCount,
773
+ prunedToolCount: stats.prunedToolCount
774
+ },
775
+ calculationBasis
585
776
  };
586
777
  }
778
+ /**
779
+ * Estimates the next input token count using actual token data from the previous LLM call.
780
+ * This is a lightweight version for compaction pre-checks that only returns the total.
781
+ *
782
+ * ## Formula (when actuals are available):
783
+ * estimatedNextInput = lastInputTokens + lastOutputTokens + newMessagesEstimate
784
+ *
785
+ * ## Why this formula works:
786
+ *
787
+ * Consider two consecutive LLM calls:
788
+ *
789
+ * ```
790
+ * Call N:
791
+ * Input sent: system + tools + [user1] = lastInput tokens
792
+ * Output received: assistant response = lastOutput tokens
793
+ *
794
+ * Call N+1:
795
+ * Input will be: system + tools + [user1, assistant1, user2, ...]
796
+ * ≈ lastInput + assistant1_as_input + new_messages
797
+ * ≈ lastInput + lastOutput + newMessagesEstimate
798
+ * ```
799
+ *
800
+ * The assistant's response (lastOutput) becomes part of the next input as conversation
801
+ * history. Text tokenizes similarly whether sent as input or received as output.
802
+ *
803
+ * ## No double-counting:
804
+ *
805
+ * The assistant message is added to history DURING streaming (before this method runs),
806
+ * and recordLastCallMessageCount() captures the count INCLUDING that message.
807
+ * Therefore, newMessages = history.slice(lastMsgCount) EXCLUDES the assistant message,
808
+ * so lastOutput and newMessages don't overlap.
809
+ *
810
+ * ## Pruning caveat:
811
+ *
812
+ * If tool output pruning occurs between calls, lastInput may be stale (higher than
813
+ * actual). This causes OVERESTIMATION, which is SAFE - we'd trigger compaction
814
+ * earlier rather than risk context overflow.
815
+ *
816
+ * @param systemPrompt The system prompt string
817
+ * @param preparedHistory Message history AFTER filterCompacted and pruning
818
+ * @param tools Tool definitions
819
+ * @returns Estimated total input tokens for the next LLM call
820
+ */
821
+ async getEstimatedNextInputTokens(systemPrompt, preparedHistory, tools) {
822
+ const lastInput = this.lastActualInputTokens;
823
+ const lastOutput = this.lastActualOutputTokens;
824
+ const lastMsgCount = this.lastCallMessageCount;
825
+ const currentHistory = await this.historyProvider.getHistory();
826
+ if (lastInput !== null && lastOutput !== null && lastMsgCount !== null) {
827
+ const newMessages = currentHistory.slice(lastMsgCount);
828
+ const newMessagesEstimate = estimateMessagesTokens(newMessages);
829
+ const total = lastInput + lastOutput + newMessagesEstimate;
830
+ this.logger.debug(
831
+ `Estimated next input (actuals-based): ${lastInput} + ${lastOutput} + ${newMessagesEstimate} = ${total}`
832
+ );
833
+ return total;
834
+ }
835
+ const pureEstimate = estimateContextTokens(systemPrompt, preparedHistory, tools);
836
+ this.logger.debug(`Estimated next input (pure estimate): ${pureEstimate.total}`);
837
+ return pureEstimate.total;
838
+ }
587
839
  /**
588
840
  * Gets the system prompt formatted for the target LLM provider
589
841
  * Some providers handle system prompts differently
@@ -600,6 +852,7 @@ ${prompt}`);
600
852
  */
601
853
  async resetConversation() {
602
854
  await this.historyProvider.clearHistory();
855
+ this.resetActualTokenTracking();
603
856
  this.logger.debug(
604
857
  `ContextManager: Conversation history cleared for session ${this.sessionId}`
605
858
  );
@@ -186,6 +186,12 @@ export interface AssistantMessage extends MessageBase {
186
186
  * Present when the provider supports reasoning and returns a final reasoning trace.
187
187
  */
188
188
  reasoning?: string;
189
+ /**
190
+ * Provider-specific metadata for reasoning, used for round-tripping.
191
+ * Contains opaque tokens (e.g., OpenAI itemId, Gemini thought signatures)
192
+ * that must be passed back to the provider on subsequent requests.
193
+ */
194
+ reasoningMetadata?: Record<string, unknown>;
189
195
  /** Token usage accounting for this response */
190
196
  tokenUsage?: TokenUsage;
191
197
  /** Model identifier that generated this response */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/context/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAMjE;;;GAGG;AACH,MAAM,WAAW,SAAS;IACtB,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,WAAW,GAAG,GAAG,CAAC;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,WAAW,GAAG,GAAG,CAAC;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,C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-18,7 +18,13 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var utils_exports = {};
20
20
  __export(utils_exports, {
21
+ estimateContentPartTokens: () => estimateContentPartTokens,
22
+ estimateContextTokens: () => estimateContextTokens,
23
+ estimateFileTokens: () => estimateFileTokens,
24
+ estimateImageTokens: () => estimateImageTokens,
21
25
  estimateMessagesTokens: () => estimateMessagesTokens,
26
+ estimateStringTokens: () => estimateStringTokens,
27
+ estimateToolsTokens: () => estimateToolsTokens,
22
28
  expandBlobReferences: () => expandBlobReferences,
23
29
  fileTypesToMimePatterns: () => fileTypesToMimePatterns,
24
30
  filterCompacted: () => filterCompacted,
@@ -322,17 +328,66 @@ async function resolveBlobReferenceToParts(resourceUri, resourceManager, logger,
322
328
  return [{ type: "text", text: `[Attachment unavailable: ${resourceUri}]` }];
323
329
  }
324
330
  }
331
+ function estimateStringTokens(text) {
332
+ if (!text) return 0;
333
+ return Math.round(text.length / 4);
334
+ }
335
+ function estimateImageTokens() {
336
+ return 1e3;
337
+ }
338
+ function estimateFileTokens(content) {
339
+ if (content) {
340
+ return estimateStringTokens(content);
341
+ }
342
+ return 1e3;
343
+ }
344
+ function estimateContentPartTokens(part) {
345
+ if (part.type === "text") {
346
+ return estimateStringTokens(part.text);
347
+ }
348
+ if (part.type === "image") {
349
+ return estimateImageTokens();
350
+ }
351
+ if (part.type === "file") {
352
+ return 1e3;
353
+ }
354
+ return 0;
355
+ }
325
356
  function estimateMessagesTokens(messages) {
326
- return messages.reduce((sum, msg) => {
327
- if (Array.isArray(msg.content)) {
328
- return sum + msg.content.reduce((partSum, part) => {
329
- if (part.type === "text") return partSum + Math.ceil(part.text.length / 4);
330
- if (part.type === "image" || part.type === "file") return partSum + 1e3;
331
- return partSum;
332
- }, 0);
357
+ let total = 0;
358
+ for (const msg of messages) {
359
+ if (!Array.isArray(msg.content)) continue;
360
+ for (const part of msg.content) {
361
+ total += estimateContentPartTokens(part);
362
+ }
363
+ }
364
+ return total;
365
+ }
366
+ function estimateToolsTokens(tools) {
367
+ const perTool = [];
368
+ let total = 0;
369
+ for (const [key, tool] of Object.entries(tools)) {
370
+ const toolName = tool.name || key;
371
+ const toolDescription = tool.description || "";
372
+ const toolSchema = JSON.stringify(tool.parameters || {});
373
+ const tokens = estimateStringTokens(toolName + toolDescription + toolSchema);
374
+ perTool.push({ name: toolName, tokens });
375
+ total += tokens;
376
+ }
377
+ return { total, perTool };
378
+ }
379
+ function estimateContextTokens(systemPrompt, preparedHistory, tools) {
380
+ const systemPromptTokens = estimateStringTokens(systemPrompt);
381
+ const messagesTokens = estimateMessagesTokens(preparedHistory);
382
+ const toolsEstimate = tools ? estimateToolsTokens(tools) : { total: 0, perTool: [] };
383
+ return {
384
+ total: systemPromptTokens + toolsEstimate.total + messagesTokens,
385
+ breakdown: {
386
+ systemPrompt: systemPromptTokens,
387
+ messages: messagesTokens,
388
+ tools: toolsEstimate
333
389
  }
334
- return sum;
335
- }, 0);
390
+ };
336
391
  }
337
392
  function getImageData(imagePart, logger) {
338
393
  const { image } = imagePart;
@@ -1210,7 +1265,7 @@ function filterCompacted(history) {
1210
1265
  let summaryIndex = -1;
1211
1266
  for (let i = history.length - 1; i >= 0; i--) {
1212
1267
  const msg = history[i];
1213
- if (msg?.metadata?.isSummary === true) {
1268
+ if (msg?.metadata?.isSummary === true || msg?.metadata?.isSessionSummary === true) {
1214
1269
  summaryIndex = i;
1215
1270
  break;
1216
1271
  }
@@ -1218,7 +1273,12 @@ function filterCompacted(history) {
1218
1273
  if (summaryIndex === -1) {
1219
1274
  return history.slice();
1220
1275
  }
1221
- return history.slice(summaryIndex);
1276
+ const summaryMessage = history[summaryIndex];
1277
+ const rawCount = summaryMessage.metadata?.originalMessageCount;
1278
+ const originalMessageCount = typeof rawCount === "number" && rawCount >= 0 && rawCount <= summaryIndex ? rawCount : summaryIndex;
1279
+ const preservedMessages = history.slice(originalMessageCount, summaryIndex);
1280
+ const messagesAfterSummary = history.slice(summaryIndex + 1);
1281
+ return [summaryMessage, ...preservedMessages, ...messagesAfterSummary];
1222
1282
  }
1223
1283
  function formatToolOutputForDisplay(message) {
1224
1284
  if ((0, import_types.isToolMessage)(message) && message.compactedAt) {
@@ -1234,7 +1294,13 @@ function formatToolOutputForDisplay(message) {
1234
1294
  }
1235
1295
  // Annotate the CommonJS export names for ESM import in node:
1236
1296
  0 && (module.exports = {
1297
+ estimateContentPartTokens,
1298
+ estimateContextTokens,
1299
+ estimateFileTokens,
1300
+ estimateImageTokens,
1237
1301
  estimateMessagesTokens,
1302
+ estimateStringTokens,
1303
+ estimateToolsTokens,
1238
1304
  expandBlobReferences,
1239
1305
  fileTypesToMimePatterns,
1240
1306
  filterCompacted,
@@ -31,13 +31,86 @@ interface PersistToolMediaResult {
31
31
  resources?: SanitizedToolResult['resources'];
32
32
  }
33
33
  /**
34
- * Simple token estimation using length/4 heuristic.
34
+ * Estimate tokens for a text string.
35
+ * Uses the common heuristic of ~4 characters per token.
36
+ */
37
+ export declare function estimateStringTokens(text: string): number;
38
+ /**
39
+ * Estimate tokens for an image.
40
+ * Images use a fixed token budget regardless of dimensions.
41
+ * Based on typical LLM pricing (~1000 tokens per image).
42
+ */
43
+ export declare function estimateImageTokens(): number;
44
+ /**
45
+ * Estimate tokens for a file based on its content.
46
+ * If content is available, estimates based on text length.
47
+ * Falls back to a default estimate if no content provided.
48
+ */
49
+ export declare function estimateFileTokens(content?: string): number;
50
+ /**
51
+ * Estimate tokens for a content part (text, image, or file).
52
+ */
53
+ export declare function estimateContentPartTokens(part: ContentPart): number;
54
+ /**
55
+ * Estimate tokens for an array of messages.
35
56
  * Used for telemetry/logging only - actual token counts come from the LLM API.
36
- *
37
- * @param messages Messages to estimate tokens for
38
- * @returns Estimated token count
39
57
  */
40
58
  export declare function estimateMessagesTokens(messages: readonly InternalMessage[]): number;
59
+ /**
60
+ * Tool definition interface for token estimation.
61
+ * Matches the structure used by both ToolManager and getContextTokenEstimate.
62
+ */
63
+ export interface ToolDefinition {
64
+ name?: string;
65
+ description?: string;
66
+ parameters?: unknown;
67
+ }
68
+ /**
69
+ * Estimate tokens for tool definitions.
70
+ * Returns both total and per-tool breakdown for UI display.
71
+ */
72
+ export declare function estimateToolsTokens(tools: Record<string, ToolDefinition>): {
73
+ total: number;
74
+ perTool: Array<{
75
+ name: string;
76
+ tokens: number;
77
+ }>;
78
+ };
79
+ /**
80
+ * Result of context token estimation with breakdown.
81
+ */
82
+ export interface ContextTokenEstimate {
83
+ /** Total estimated tokens */
84
+ total: number;
85
+ /** Breakdown by category */
86
+ breakdown: {
87
+ systemPrompt: number;
88
+ messages: number;
89
+ tools: {
90
+ total: number;
91
+ perTool: Array<{
92
+ name: string;
93
+ tokens: number;
94
+ }>;
95
+ };
96
+ };
97
+ }
98
+ /**
99
+ * Estimate total context tokens for LLM calls.
100
+ * This is the single source of truth for context token estimation,
101
+ * used by both /context overlay and compaction pre-check.
102
+ *
103
+ * IMPORTANT: The `preparedHistory` parameter must be the result of
104
+ * `ContextManager.prepareHistory()` or `getFormattedMessagesForLLM()`.
105
+ * This ensures messages are properly filtered (compacted messages removed)
106
+ * and pruned tool outputs are replaced with placeholders.
107
+ *
108
+ * @param systemPrompt The system prompt string
109
+ * @param preparedHistory Message history AFTER filterCompacted and pruning
110
+ * @param tools Optional tool definitions - if not provided, tools are not counted
111
+ * @returns Token estimate with total and breakdown
112
+ */
113
+ export declare function estimateContextTokens(systemPrompt: string, preparedHistory: readonly InternalMessage[], tools?: Record<string, ToolDefinition>): ContextTokenEstimate;
41
114
  /**
42
115
  * Extracts image data (base64 or URL) from an ImagePart or raw buffer.
43
116
  * @param imagePart The image part containing image data
@@ -171,11 +244,16 @@ export declare function summarizeToolContentForText(content: InternalMessage['co
171
244
  export declare function toTextForToolMessage(content: InternalMessage['content']): string;
172
245
  /**
173
246
  * Filter history to exclude messages before the most recent summary.
174
- * This implements read-time compression.
247
+ * This implements read-time compression for inline compaction.
248
+ *
249
+ * Used by:
250
+ * - TurnExecutor for inline compaction during agentic turns (overflow handling)
251
+ * - DextoAgent.getContextStats() for accurate token/message counts
175
252
  *
176
- * When a summary message exists (with metadata.isSummary === true),
177
- * this function returns only the summary message and everything after it.
178
- * This effectively hides old messages from the LLM while preserving them in storage.
253
+ * When a summary message exists (with metadata.isSummary === true or
254
+ * metadata.isSessionSummary === true), this function returns only the
255
+ * summary message and everything after it. This effectively hides old
256
+ * messages from the LLM while preserving them in storage.
179
257
  *
180
258
  * @param history The full conversation history
181
259
  * @returns Filtered history starting from the most recent summary (or full history if no summary)
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/context/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,cAAc,EACd,WAAW,EACX,mBAAmB,EAEtB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAMvE,KAAK,qBAAqB,GAAG;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAIF,KAAK,eAAe,GAAG,OAAO,GAAG,MAAM,CAAC;AAExC,KAAK,eAAe,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,eAAe,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACjC,KAAK,EAAE,KAAK,CAAC,QAAQ,GAAG,SA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