@dexto/core 1.5.4 → 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.
- package/dist/agent/DextoAgent.cjs +61 -155
- package/dist/agent/DextoAgent.d.ts +11 -54
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +61 -155
- package/dist/context/compaction/strategies/reactive-overflow.cjs +5 -3
- package/dist/context/compaction/strategies/reactive-overflow.d.ts +1 -0
- package/dist/context/compaction/strategies/reactive-overflow.d.ts.map +1 -1
- package/dist/context/compaction/strategies/reactive-overflow.js +5 -3
- package/dist/context/compaction/types.d.ts +13 -1
- package/dist/context/compaction/types.d.ts.map +1 -1
- package/dist/errors/types.cjs +0 -2
- package/dist/errors/types.d.ts +1 -5
- package/dist/errors/types.d.ts.map +1 -1
- package/dist/errors/types.js +0 -2
- package/dist/events/index.cjs +0 -2
- package/dist/events/index.d.ts +6 -25
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +0 -2
- package/dist/llm/executor/stream-processor.cjs +85 -27
- package/dist/llm/executor/stream-processor.d.ts +4 -0
- package/dist/llm/executor/stream-processor.d.ts.map +1 -1
- package/dist/llm/executor/stream-processor.js +85 -27
- package/dist/llm/executor/turn-executor.cjs +58 -130
- package/dist/llm/executor/turn-executor.d.ts +9 -43
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +58 -130
- package/dist/llm/executor/types.d.ts +0 -28
- package/dist/llm/executor/types.d.ts.map +1 -1
- package/dist/llm/services/vercel.cjs +2 -5
- package/dist/llm/services/vercel.d.ts +1 -6
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +2 -5
- package/dist/session/chat-session.cjs +19 -12
- package/dist/session/chat-session.d.ts +3 -6
- package/dist/session/chat-session.d.ts.map +1 -1
- package/dist/session/chat-session.js +19 -12
- package/dist/session/session-manager.cjs +0 -135
- package/dist/session/session-manager.d.ts +0 -43
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +0 -135
- package/dist/telemetry/telemetry.cjs +12 -5
- package/dist/telemetry/telemetry.d.ts.map +1 -1
- package/dist/telemetry/telemetry.js +12 -5
- package/package.json +15 -5
- package/dist/filesystem/error-codes.cjs +0 -53
- package/dist/filesystem/error-codes.d.ts +0 -31
- package/dist/filesystem/error-codes.d.ts.map +0 -1
- package/dist/filesystem/error-codes.js +0 -30
- package/dist/filesystem/errors.cjs +0 -303
- package/dist/filesystem/errors.d.ts +0 -109
- package/dist/filesystem/errors.d.ts.map +0 -1
- package/dist/filesystem/errors.js +0 -280
- package/dist/filesystem/filesystem-service.cjs +0 -534
- package/dist/filesystem/filesystem-service.d.ts +0 -97
- package/dist/filesystem/filesystem-service.d.ts.map +0 -1
- package/dist/filesystem/filesystem-service.js +0 -501
- package/dist/filesystem/index.cjs +0 -37
- package/dist/filesystem/index.d.ts +0 -11
- package/dist/filesystem/index.d.ts.map +0 -1
- package/dist/filesystem/index.js +0 -11
- package/dist/filesystem/path-validator.cjs +0 -250
- package/dist/filesystem/path-validator.d.ts +0 -103
- package/dist/filesystem/path-validator.d.ts.map +0 -1
- package/dist/filesystem/path-validator.js +0 -217
- package/dist/filesystem/types.cjs +0 -16
- package/dist/filesystem/types.d.ts +0 -175
- package/dist/filesystem/types.d.ts.map +0 -1
- package/dist/filesystem/types.js +0 -0
- package/dist/process/command-validator.cjs +0 -554
- package/dist/process/command-validator.d.ts +0 -49
- package/dist/process/command-validator.d.ts.map +0 -1
- package/dist/process/command-validator.js +0 -531
- package/dist/process/error-codes.cjs +0 -47
- package/dist/process/error-codes.d.ts +0 -25
- package/dist/process/error-codes.d.ts.map +0 -1
- package/dist/process/error-codes.js +0 -24
- package/dist/process/errors.cjs +0 -244
- package/dist/process/errors.d.ts +0 -87
- package/dist/process/errors.d.ts.map +0 -1
- package/dist/process/errors.js +0 -221
- package/dist/process/index.cjs +0 -37
- package/dist/process/index.d.ts +0 -11
- package/dist/process/index.d.ts.map +0 -1
- package/dist/process/index.js +0 -11
- package/dist/process/process-service.cjs +0 -497
- package/dist/process/process-service.d.ts +0 -69
- package/dist/process/process-service.d.ts.map +0 -1
- package/dist/process/process-service.js +0 -464
- package/dist/process/types.cjs +0 -16
- package/dist/process/types.d.ts +0 -107
- package/dist/process/types.d.ts.map +0 -1
- package/dist/process/types.js +0 -0
- package/dist/session/compaction-service.cjs +0 -139
- package/dist/session/compaction-service.d.ts +0 -81
- package/dist/session/compaction-service.d.ts.map +0 -1
- package/dist/session/compaction-service.js +0 -106
|
@@ -47,23 +47,6 @@ export declare class TurnExecutor {
|
|
|
47
47
|
* Used to pass approval info from tool execution to result persistence.
|
|
48
48
|
*/
|
|
49
49
|
private approvalMetadata;
|
|
50
|
-
/**
|
|
51
|
-
* Tracks whether compaction occurred during this turn.
|
|
52
|
-
* Used to signal to the caller that session continuation may be needed.
|
|
53
|
-
*/
|
|
54
|
-
private compactionOccurred;
|
|
55
|
-
/**
|
|
56
|
-
* Compaction data captured during this turn.
|
|
57
|
-
* Contains summary text and preserved messages for session continuation.
|
|
58
|
-
* This data is passed up the call chain (NOT persisted to original session).
|
|
59
|
-
*/
|
|
60
|
-
private compactionData;
|
|
61
|
-
/**
|
|
62
|
-
* Virtual context for remaining iterations after compaction.
|
|
63
|
-
* When set, the main loop uses this instead of calling getFormattedMessagesForLLM().
|
|
64
|
-
* This provides reduced context to the LLM without persisting to the original session.
|
|
65
|
-
*/
|
|
66
|
-
private virtualContext;
|
|
67
50
|
constructor(model: LanguageModel, toolManager: ToolManager, contextManager: ContextManager<ModelMessage>, eventBus: SessionEventBus, resourceManager: ResourceManager, sessionId: string, config: {
|
|
68
51
|
maxSteps?: number | undefined;
|
|
69
52
|
maxOutputTokens?: number | undefined;
|
|
@@ -178,40 +161,23 @@ export declare class TurnExecutor {
|
|
|
178
161
|
*/
|
|
179
162
|
private shouldCompactFromActual;
|
|
180
163
|
/**
|
|
181
|
-
* Compact context
|
|
164
|
+
* Compact context by generating a summary and adding it to the same session.
|
|
182
165
|
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* The original session remains UNTOUCHED - no messages are added or modified.
|
|
166
|
+
* The summary message is added to the conversation history with `isSummary: true` metadata.
|
|
167
|
+
* When the context is loaded via getFormattedMessagesForLLM(), filterCompacted() will
|
|
168
|
+
* exclude all messages before the summary, effectively compacting the context.
|
|
188
169
|
*
|
|
189
170
|
* @param originalTokens The estimated input token count that triggered overflow
|
|
171
|
+
* @param contributorContext Context for system prompt contributors (needed for accurate token estimation)
|
|
172
|
+
* @param tools Tool definitions (needed for accurate token estimation)
|
|
173
|
+
* @returns true if compaction occurred, false if skipped
|
|
190
174
|
*/
|
|
191
|
-
private
|
|
192
|
-
/**
|
|
193
|
-
* Extract the summary text from a summary message.
|
|
194
|
-
*/
|
|
195
|
-
private extractSummaryText;
|
|
196
|
-
/**
|
|
197
|
-
* Build formatted messages from virtual context (after compaction).
|
|
198
|
-
*
|
|
199
|
-
* This creates LLM-ready messages using:
|
|
200
|
-
* - System prompt (same as normal flow)
|
|
201
|
-
* - Summary message (as first message)
|
|
202
|
-
* - Preserved messages (formatted for LLM)
|
|
203
|
-
*
|
|
204
|
-
* Uses the same formatting pipeline as getFormattedMessagesForLLM()
|
|
205
|
-
* but with our virtual history instead of the stored history.
|
|
206
|
-
*
|
|
207
|
-
* @param contributorContext Context for system prompt contributors
|
|
208
|
-
* @returns Formatted messages ready for LLM call, matching getFormattedMessagesForLLM return type
|
|
209
|
-
*/
|
|
210
|
-
private buildMessagesFromVirtualContext;
|
|
175
|
+
private compactContext;
|
|
211
176
|
/**
|
|
212
177
|
* Set telemetry span attributes for token usage.
|
|
213
178
|
*/
|
|
214
179
|
private setTelemetryAttributes;
|
|
180
|
+
private getContextInputTokens;
|
|
215
181
|
/**
|
|
216
182
|
* Map provider errors to DextoRuntimeError.
|
|
217
183
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turn-executor.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/turn-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EAMb,KAAK,YAAY,EAEpB,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"turn-executor.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/turn-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EAMb,KAAK,YAAY,EAEpB,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,uBAAuB,CAAC;AAC9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,UAAU,EAAoB,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAQ1E,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAEpF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAc7E;;;;;;;;;;;GAWG;AACH,qBAAa,YAAY;IAkBjB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,MAAM;IAQd,OAAO,CAAC,UAAU;I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MG;YACW,mBAAmB;IA0EjC;;;;;;;OAOG;YACW,WAAW;IA0GzB;;;;;OAKG;IACH,OAAO,CAAC,sBAAsB;IAuF9B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAyBxB;;OAEG;IACH,OAAO,CAAC,eAAe;IAavB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAS5B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAU;IAC/C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAU;IAE/C;;;;;;;;;;;OAWG;YACW,mBAAmB;IAkDjC;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAgB1B;;;OAGG;IACH,OAAO,CAAC,OAAO;IAYf;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAYrB;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;IAY/B;;;;;;;;;;;OAWG;YACW,cAAc;IAoF5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAoB9B,OAAO,CAAC,qBAAqB;IAK7B;;OAEG;IACH,OAAO,CAAC,gBAAgB;CA0D3B"}
|
|
@@ -56,23 +56,6 @@ class TurnExecutor {
|
|
|
56
56
|
* Used to pass approval info from tool execution to result persistence.
|
|
57
57
|
*/
|
|
58
58
|
approvalMetadata = /* @__PURE__ */ new Map();
|
|
59
|
-
/**
|
|
60
|
-
* Tracks whether compaction occurred during this turn.
|
|
61
|
-
* Used to signal to the caller that session continuation may be needed.
|
|
62
|
-
*/
|
|
63
|
-
compactionOccurred = false;
|
|
64
|
-
/**
|
|
65
|
-
* Compaction data captured during this turn.
|
|
66
|
-
* Contains summary text and preserved messages for session continuation.
|
|
67
|
-
* This data is passed up the call chain (NOT persisted to original session).
|
|
68
|
-
*/
|
|
69
|
-
compactionData = null;
|
|
70
|
-
/**
|
|
71
|
-
* Virtual context for remaining iterations after compaction.
|
|
72
|
-
* When set, the main loop uses this instead of calling getFormattedMessagesForLLM().
|
|
73
|
-
* This provides reduced context to the LLM without persisting to the original session.
|
|
74
|
-
*/
|
|
75
|
-
virtualContext = null;
|
|
76
59
|
/**
|
|
77
60
|
* Get StreamProcessor config from TurnExecutor state.
|
|
78
61
|
* @param estimatedInputTokens Optional estimated input tokens for analytics
|
|
@@ -138,7 +121,7 @@ class TurnExecutor {
|
|
|
138
121
|
await this.injectQueuedMessages(coalesced);
|
|
139
122
|
}
|
|
140
123
|
await this.pruneOldToolOutputs();
|
|
141
|
-
let prepared =
|
|
124
|
+
let prepared = await this.contextManager.getFormattedMessagesForLLM(
|
|
142
125
|
contributorContext,
|
|
143
126
|
this.llmContext
|
|
144
127
|
);
|
|
@@ -152,9 +135,16 @@ class TurnExecutor {
|
|
|
152
135
|
this.logger.debug(
|
|
153
136
|
`Pre-check: estimated ${estimatedTokens} tokens exceeds threshold, compacting`
|
|
154
137
|
);
|
|
155
|
-
await this.
|
|
156
|
-
|
|
157
|
-
|
|
138
|
+
const didCompact = await this.compactContext(
|
|
139
|
+
estimatedTokens,
|
|
140
|
+
contributorContext,
|
|
141
|
+
toolDefinitions
|
|
142
|
+
);
|
|
143
|
+
if (didCompact) {
|
|
144
|
+
prepared = await this.contextManager.getFormattedMessagesForLLM(
|
|
145
|
+
contributorContext,
|
|
146
|
+
this.llmContext
|
|
147
|
+
);
|
|
158
148
|
estimatedTokens = await this.contextManager.getEstimatedNextInputTokens(
|
|
159
149
|
prepared.systemPrompt,
|
|
160
150
|
prepared.preparedHistory,
|
|
@@ -216,22 +206,29 @@ class TurnExecutor {
|
|
|
216
206
|
`Context estimation (cancelled): keeping last known actuals, partial response (${result.text.length} chars) will be estimated`
|
|
217
207
|
);
|
|
218
208
|
} else if (result.usage?.inputTokens !== void 0) {
|
|
219
|
-
const
|
|
220
|
-
const
|
|
209
|
+
const contextInputTokens2 = this.getContextInputTokens(result.usage);
|
|
210
|
+
const actualInputTokens = contextInputTokens2 ?? result.usage.inputTokens;
|
|
211
|
+
const diff = estimatedTokens - actualInputTokens;
|
|
212
|
+
const diffPercent = actualInputTokens > 0 ? (diff / actualInputTokens * 100).toFixed(1) : "0.0";
|
|
221
213
|
this.logger.info(
|
|
222
|
-
`Context estimation accuracy: estimated=${estimatedTokens}, actual=${
|
|
214
|
+
`Context estimation accuracy: estimated=${estimatedTokens}, actual=${actualInputTokens}, error=${diff} (${diffPercent}%)`
|
|
223
215
|
);
|
|
224
|
-
this.contextManager.setLastActualInputTokens(
|
|
216
|
+
this.contextManager.setLastActualInputTokens(actualInputTokens);
|
|
225
217
|
if (result.usage?.outputTokens !== void 0) {
|
|
226
218
|
this.contextManager.setLastActualOutputTokens(result.usage.outputTokens);
|
|
227
219
|
}
|
|
228
220
|
await this.contextManager.recordLastCallMessageCount();
|
|
229
221
|
}
|
|
230
|
-
|
|
222
|
+
const contextInputTokens = result.usage ? this.getContextInputTokens(result.usage) : null;
|
|
223
|
+
if (contextInputTokens && this.shouldCompactFromActual(contextInputTokens)) {
|
|
231
224
|
this.logger.debug(
|
|
232
|
-
`Post-response: actual ${
|
|
225
|
+
`Post-response: actual ${contextInputTokens} tokens exceeds threshold, compacting`
|
|
226
|
+
);
|
|
227
|
+
await this.compactContext(
|
|
228
|
+
contextInputTokens,
|
|
229
|
+
contributorContext,
|
|
230
|
+
toolDefinitions
|
|
233
231
|
);
|
|
234
|
-
await this.compactToVirtualContext(result.usage.inputTokens);
|
|
235
232
|
}
|
|
236
233
|
if (result.finishReason !== "tool-calls") {
|
|
237
234
|
const queuedOnTerminate = this.messageQueue.dequeueAll();
|
|
@@ -285,14 +282,7 @@ class TurnExecutor {
|
|
|
285
282
|
text: lastText,
|
|
286
283
|
stepCount,
|
|
287
284
|
usage: lastStepTokens,
|
|
288
|
-
finishReason: lastFinishReason
|
|
289
|
-
// Signal to caller that compaction occurred during this turn
|
|
290
|
-
// Caller can use this to trigger session-native continuation
|
|
291
|
-
didCompact: this.compactionOccurred,
|
|
292
|
-
// Pass compaction data up the chain (NOT persisted to original session)
|
|
293
|
-
// Caller uses this to create the continuation session with summary
|
|
294
|
-
// Use spread to conditionally include only when data exists (exactOptionalPropertyTypes)
|
|
295
|
-
...this.compactionData && { compaction: this.compactionData }
|
|
285
|
+
finishReason: lastFinishReason
|
|
296
286
|
};
|
|
297
287
|
} catch (_2) {
|
|
298
288
|
var _error = _2, _hasError = true;
|
|
@@ -693,27 +683,31 @@ class TurnExecutor {
|
|
|
693
683
|
);
|
|
694
684
|
}
|
|
695
685
|
/**
|
|
696
|
-
* Compact context
|
|
697
|
-
*
|
|
698
|
-
* Key design: Creates a virtual context (summary + preserved messages) that will be used
|
|
699
|
-
* for the remaining iterations of this turn. The compaction data is passed up the call chain
|
|
700
|
-
* so the caller can create a continuation session with the summary.
|
|
686
|
+
* Compact context by generating a summary and adding it to the same session.
|
|
701
687
|
*
|
|
702
|
-
* The
|
|
688
|
+
* The summary message is added to the conversation history with `isSummary: true` metadata.
|
|
689
|
+
* When the context is loaded via getFormattedMessagesForLLM(), filterCompacted() will
|
|
690
|
+
* exclude all messages before the summary, effectively compacting the context.
|
|
703
691
|
*
|
|
704
692
|
* @param originalTokens The estimated input token count that triggered overflow
|
|
693
|
+
* @param contributorContext Context for system prompt contributors (needed for accurate token estimation)
|
|
694
|
+
* @param tools Tool definitions (needed for accurate token estimation)
|
|
695
|
+
* @returns true if compaction occurred, false if skipped
|
|
705
696
|
*/
|
|
706
|
-
async
|
|
697
|
+
async compactContext(originalTokens, contributorContext, tools) {
|
|
707
698
|
if (!this.compactionStrategy) {
|
|
708
|
-
return;
|
|
699
|
+
return false;
|
|
709
700
|
}
|
|
710
701
|
this.logger.info(
|
|
711
702
|
`Context overflow detected (${originalTokens} tokens), checking if compression is possible`
|
|
712
703
|
);
|
|
713
704
|
const history = await this.contextManager.getHistory();
|
|
705
|
+
const { filterCompacted } = await import("../../context/utils.js");
|
|
706
|
+
const originalFiltered = filterCompacted(history);
|
|
707
|
+
const originalMessages = originalFiltered.length;
|
|
714
708
|
if (history.length < 4) {
|
|
715
709
|
this.logger.debug("Compaction skipped: history too short to summarize");
|
|
716
|
-
return;
|
|
710
|
+
return false;
|
|
717
711
|
}
|
|
718
712
|
this.eventBus.emit("context:compacting", {
|
|
719
713
|
estimatedTokens: originalTokens
|
|
@@ -727,106 +721,36 @@ class TurnExecutor {
|
|
|
727
721
|
originalTokens,
|
|
728
722
|
compactedTokens: originalTokens,
|
|
729
723
|
// No change
|
|
730
|
-
originalMessages
|
|
731
|
-
compactedMessages:
|
|
724
|
+
originalMessages,
|
|
725
|
+
compactedMessages: originalMessages,
|
|
732
726
|
// No change
|
|
733
727
|
strategy: this.compactionStrategy.name,
|
|
734
728
|
reason: "overflow"
|
|
735
729
|
});
|
|
736
|
-
return;
|
|
737
|
-
}
|
|
738
|
-
const summaryMessage = summaryMessages[0];
|
|
739
|
-
if (!summaryMessage) {
|
|
740
|
-
this.logger.warn("Compaction returned empty summary message array");
|
|
741
|
-
return;
|
|
730
|
+
return false;
|
|
742
731
|
}
|
|
743
|
-
const
|
|
744
|
-
|
|
745
|
-
let existingSummaryIndex = -1;
|
|
746
|
-
for (let i = history.length - 1; i >= 0; i--) {
|
|
747
|
-
const msg = history[i];
|
|
748
|
-
if (msg?.metadata?.isSummary === true || msg?.metadata?.isSessionSummary === true) {
|
|
749
|
-
existingSummaryIndex = i;
|
|
750
|
-
break;
|
|
751
|
-
}
|
|
732
|
+
for (const summary of summaryMessages) {
|
|
733
|
+
await this.contextManager.addMessage(summary);
|
|
752
734
|
}
|
|
753
|
-
const baseIndex = existingSummaryIndex >= 0 ? existingSummaryIndex + 1 : 0;
|
|
754
|
-
const preservedMessages = history.slice(baseIndex + summarizedCount);
|
|
755
|
-
const firstTimestamp = summaryMessage.metadata?.originalFirstTimestamp;
|
|
756
|
-
const lastTimestamp = summaryMessage.metadata?.originalLastTimestamp;
|
|
757
|
-
this.compactionData = {
|
|
758
|
-
summaryText,
|
|
759
|
-
preservedMessages: [...preservedMessages],
|
|
760
|
-
// Copy to avoid mutation
|
|
761
|
-
summarizedCount,
|
|
762
|
-
...firstTimestamp !== void 0 && { originalFirstTimestamp: firstTimestamp },
|
|
763
|
-
...lastTimestamp !== void 0 && { originalLastTimestamp: lastTimestamp }
|
|
764
|
-
};
|
|
765
|
-
this.virtualContext = {
|
|
766
|
-
summaryMessage,
|
|
767
|
-
preservedMessages: [...preservedMessages]
|
|
768
|
-
};
|
|
769
|
-
this.compactionOccurred = true;
|
|
770
735
|
this.contextManager.resetActualTokenTracking();
|
|
771
|
-
const
|
|
772
|
-
|
|
773
|
-
|
|
736
|
+
const afterEstimate = await this.contextManager.getContextTokenEstimate(
|
|
737
|
+
contributorContext,
|
|
738
|
+
tools
|
|
739
|
+
);
|
|
740
|
+
const compactedTokens = afterEstimate.estimated;
|
|
741
|
+
const compactedMessages = afterEstimate.stats.filteredMessageCount;
|
|
774
742
|
this.eventBus.emit("context:compacted", {
|
|
775
743
|
originalTokens,
|
|
776
744
|
compactedTokens,
|
|
777
|
-
originalMessages
|
|
778
|
-
compactedMessages
|
|
745
|
+
originalMessages,
|
|
746
|
+
compactedMessages,
|
|
779
747
|
strategy: this.compactionStrategy.name,
|
|
780
748
|
reason: "overflow"
|
|
781
749
|
});
|
|
782
750
|
this.logger.info(
|
|
783
|
-
`Compaction complete
|
|
751
|
+
`Compaction complete: ${originalTokens} \u2192 ~${compactedTokens} tokens (${originalMessages} \u2192 ${compactedMessages} messages after filtering)`
|
|
784
752
|
);
|
|
785
|
-
|
|
786
|
-
/**
|
|
787
|
-
* Extract the summary text from a summary message.
|
|
788
|
-
*/
|
|
789
|
-
extractSummaryText(summaryMessage) {
|
|
790
|
-
if (typeof summaryMessage.content === "string") {
|
|
791
|
-
return summaryMessage.content;
|
|
792
|
-
}
|
|
793
|
-
if (Array.isArray(summaryMessage.content)) {
|
|
794
|
-
return summaryMessage.content.filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
795
|
-
}
|
|
796
|
-
return "";
|
|
797
|
-
}
|
|
798
|
-
/**
|
|
799
|
-
* Build formatted messages from virtual context (after compaction).
|
|
800
|
-
*
|
|
801
|
-
* This creates LLM-ready messages using:
|
|
802
|
-
* - System prompt (same as normal flow)
|
|
803
|
-
* - Summary message (as first message)
|
|
804
|
-
* - Preserved messages (formatted for LLM)
|
|
805
|
-
*
|
|
806
|
-
* Uses the same formatting pipeline as getFormattedMessagesForLLM()
|
|
807
|
-
* but with our virtual history instead of the stored history.
|
|
808
|
-
*
|
|
809
|
-
* @param contributorContext Context for system prompt contributors
|
|
810
|
-
* @returns Formatted messages ready for LLM call, matching getFormattedMessagesForLLM return type
|
|
811
|
-
*/
|
|
812
|
-
async buildMessagesFromVirtualContext(contributorContext) {
|
|
813
|
-
if (!this.virtualContext) {
|
|
814
|
-
throw new Error("buildMessagesFromVirtualContext called without virtual context");
|
|
815
|
-
}
|
|
816
|
-
const { summaryMessage, preservedMessages } = this.virtualContext;
|
|
817
|
-
const systemPrompt = await this.contextManager.getSystemPrompt(contributorContext);
|
|
818
|
-
const virtualHistory = [summaryMessage, ...preservedMessages];
|
|
819
|
-
const formattedMessages = await this.contextManager.getFormattedMessages(
|
|
820
|
-
contributorContext,
|
|
821
|
-
this.llmContext,
|
|
822
|
-
systemPrompt,
|
|
823
|
-
virtualHistory
|
|
824
|
-
);
|
|
825
|
-
return {
|
|
826
|
-
formattedMessages,
|
|
827
|
-
systemPrompt,
|
|
828
|
-
preparedHistory: virtualHistory
|
|
829
|
-
};
|
|
753
|
+
return true;
|
|
830
754
|
}
|
|
831
755
|
/**
|
|
832
756
|
* Set telemetry span attributes for token usage.
|
|
@@ -849,6 +773,10 @@ class TurnExecutor {
|
|
|
849
773
|
activeSpan.setAttribute("gen_ai.usage.reasoning_tokens", usage.reasoningTokens);
|
|
850
774
|
}
|
|
851
775
|
}
|
|
776
|
+
getContextInputTokens(usage) {
|
|
777
|
+
if (usage.inputTokens === void 0) return null;
|
|
778
|
+
return usage.inputTokens + (usage.cacheReadTokens ?? 0) + (usage.cacheWriteTokens ?? 0);
|
|
779
|
+
}
|
|
852
780
|
/**
|
|
853
781
|
* Map provider errors to DextoRuntimeError.
|
|
854
782
|
*/
|
|
@@ -1,23 +1,5 @@
|
|
|
1
|
-
import type { InternalMessage } from '../../context/types.js';
|
|
2
1
|
import { TokenUsage } from '../types.js';
|
|
3
2
|
import { LLMFinishReason } from '../../events/index.js';
|
|
4
|
-
/**
|
|
5
|
-
* Data captured during context compaction for session-native continuation.
|
|
6
|
-
* This is passed through the call chain so the new session can be created
|
|
7
|
-
* with the summary and preserved messages.
|
|
8
|
-
*/
|
|
9
|
-
export interface CompactionData {
|
|
10
|
-
/** The generated summary text */
|
|
11
|
-
summaryText: string;
|
|
12
|
-
/** Messages preserved (not summarized) - typically last N turns */
|
|
13
|
-
preservedMessages: InternalMessage[];
|
|
14
|
-
/** Number of messages that were summarized */
|
|
15
|
-
summarizedCount: number;
|
|
16
|
-
/** Timestamp of first summarized message */
|
|
17
|
-
originalFirstTimestamp?: number;
|
|
18
|
-
/** Timestamp of last summarized message */
|
|
19
|
-
originalLastTimestamp?: number;
|
|
20
|
-
}
|
|
21
3
|
export interface ExecutorResult {
|
|
22
4
|
/**
|
|
23
5
|
* The accumulated text from assistant responses.
|
|
@@ -31,16 +13,6 @@ export interface ExecutorResult {
|
|
|
31
13
|
usage: TokenUsage | null;
|
|
32
14
|
/** Reason the execution finished */
|
|
33
15
|
finishReason: LLMFinishReason;
|
|
34
|
-
/**
|
|
35
|
-
* Set to true if context compaction occurred during this turn.
|
|
36
|
-
* Caller can use this to trigger session-native continuation (create new session).
|
|
37
|
-
*/
|
|
38
|
-
didCompact: boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Compaction data when didCompact is true.
|
|
41
|
-
* Contains the summary text and preserved messages for creating the continuation session.
|
|
42
|
-
*/
|
|
43
|
-
compaction?: CompactionData;
|
|
44
16
|
}
|
|
45
17
|
export interface StreamProcessorResult {
|
|
46
18
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/types.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,WAAW,cAAc;IAC3B;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IACzB,oCAAoC;IACpC,YAAY,EAAE,eAAe,CAAC;CACjC;AAED,MAAM,WAAW,qBAAqB;IAClC;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,eAAe,CAAC;IAC9B,KAAK,EAAE,UAAU,CAAC;CACrB"}
|
|
@@ -178,7 +178,7 @@ class VercelLLMService {
|
|
|
178
178
|
*
|
|
179
179
|
* @param content - String or ContentPart[] (text, images, files)
|
|
180
180
|
* @param options - { signal?: AbortSignal }
|
|
181
|
-
* @returns Object with text response
|
|
181
|
+
* @returns Object with text response
|
|
182
182
|
*/
|
|
183
183
|
async stream(content, options) {
|
|
184
184
|
const activeSpan = import_api.trace.getActiveSpan();
|
|
@@ -209,10 +209,7 @@ class VercelLLMService {
|
|
|
209
209
|
const contributorContext = { mcpManager: this.toolManager.getMcpManager() };
|
|
210
210
|
const result = await executor.execute(contributorContext, true);
|
|
211
211
|
return {
|
|
212
|
-
text: result.text ?? ""
|
|
213
|
-
didCompact: result.didCompact,
|
|
214
|
-
// Use spread to conditionally include compaction (exactOptionalPropertyTypes)
|
|
215
|
-
...result.compaction && { compaction: result.compaction }
|
|
212
|
+
text: result.text ?? ""
|
|
216
213
|
};
|
|
217
214
|
});
|
|
218
215
|
}
|
|
@@ -9,7 +9,6 @@ import type { SessionEventBus } from '../../events/index.js';
|
|
|
9
9
|
import type { IConversationHistoryProvider } from '../../session/history/types.js';
|
|
10
10
|
import type { SystemPromptManager } from '../../systemPrompt/manager.js';
|
|
11
11
|
import type { ValidatedLLMConfig } from '../schemas.js';
|
|
12
|
-
import type { CompactionData } from '../executor/types.js';
|
|
13
12
|
import { MessageQueueService } from '../../session/message-queue.js';
|
|
14
13
|
import type { ResourceManager } from '../../resources/index.js';
|
|
15
14
|
import type { ContentInput } from '../../agent/types.js';
|
|
@@ -55,8 +54,6 @@ export declare class VercelLLMService {
|
|
|
55
54
|
*/
|
|
56
55
|
static StreamResult: {
|
|
57
56
|
text: string;
|
|
58
|
-
didCompact: boolean;
|
|
59
|
-
compaction?: CompactionData;
|
|
60
57
|
};
|
|
61
58
|
/**
|
|
62
59
|
* Stream a response for the given content.
|
|
@@ -64,14 +61,12 @@ export declare class VercelLLMService {
|
|
|
64
61
|
*
|
|
65
62
|
* @param content - String or ContentPart[] (text, images, files)
|
|
66
63
|
* @param options - { signal?: AbortSignal }
|
|
67
|
-
* @returns Object with text response
|
|
64
|
+
* @returns Object with text response
|
|
68
65
|
*/
|
|
69
66
|
stream(content: ContentInput, options?: {
|
|
70
67
|
signal?: AbortSignal;
|
|
71
68
|
}): Promise<{
|
|
72
69
|
text: string;
|
|
73
|
-
didCompact: boolean;
|
|
74
|
-
compaction?: CompactionData;
|
|
75
70
|
}>;
|
|
76
71
|
/**
|
|
77
72
|
* Get configuration information about the LLM service
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vercel.d.ts","sourceRoot":"","sources":["../../../src/llm/services/vercel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAqB,MAAM,IAAI,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OA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7B;;OAEG;IACH,iBAAiB,IAAI,cAAc,CAAC,OAAO,CAAC;IAI5C;;OAEG;IACH,eAAe,IAAI,mBAAmB;IAItC;;OAEG;IACH,qBAAqB,IACf,OAAO,mCAAmC,EAAE,mBAAmB,GAC/D,IAAI;CAGb"}
|
|
@@ -115,7 +115,7 @@ class VercelLLMService {
|
|
|
115
115
|
*
|
|
116
116
|
* @param content - String or ContentPart[] (text, images, files)
|
|
117
117
|
* @param options - { signal?: AbortSignal }
|
|
118
|
-
* @returns Object with text response
|
|
118
|
+
* @returns Object with text response
|
|
119
119
|
*/
|
|
120
120
|
async stream(content, options) {
|
|
121
121
|
const activeSpan = trace.getActiveSpan();
|
|
@@ -146,10 +146,7 @@ class VercelLLMService {
|
|
|
146
146
|
const contributorContext = { mcpManager: this.toolManager.getMcpManager() };
|
|
147
147
|
const result = await executor.execute(contributorContext, true);
|
|
148
148
|
return {
|
|
149
|
-
text: result.text ?? ""
|
|
150
|
-
didCompact: result.didCompact,
|
|
151
|
-
// Use spread to conditionally include compaction (exactOptionalPropertyTypes)
|
|
152
|
-
...result.compaction && { compaction: result.compaction }
|
|
149
|
+
text: result.text ?? ""
|
|
153
150
|
};
|
|
154
151
|
});
|
|
155
152
|
}
|
|
@@ -212,15 +212,15 @@ class ChatSession {
|
|
|
212
212
|
*
|
|
213
213
|
* @param content - String or ContentPart[] (text, images, files)
|
|
214
214
|
* @param options - { signal?: AbortSignal }
|
|
215
|
-
* @returns Promise that resolves to object with text
|
|
215
|
+
* @returns Promise that resolves to object with text response
|
|
216
216
|
*
|
|
217
217
|
* @example
|
|
218
218
|
* ```typescript
|
|
219
219
|
* // Text only
|
|
220
|
-
* const { text
|
|
220
|
+
* const { text } = await session.stream('What is the weather?');
|
|
221
221
|
*
|
|
222
222
|
* // Multiple images
|
|
223
|
-
* const { text
|
|
223
|
+
* const { text } = await session.stream([
|
|
224
224
|
* { type: 'text', text: 'Compare these images' },
|
|
225
225
|
* { type: 'image', image: base64Data1, mimeType: 'image/png' },
|
|
226
226
|
* { type: 'image', image: base64Data2, mimeType: 'image/png' }
|
|
@@ -298,10 +298,7 @@ class ChatSession {
|
|
|
298
298
|
}
|
|
299
299
|
);
|
|
300
300
|
return {
|
|
301
|
-
text: modifiedResponsePayload.content
|
|
302
|
-
didCompact: streamResult.didCompact,
|
|
303
|
-
// Use spread to conditionally include compaction (exactOptionalPropertyTypes)
|
|
304
|
-
...streamResult.compaction && { compaction: streamResult.compaction }
|
|
301
|
+
text: modifiedResponsePayload.content
|
|
305
302
|
};
|
|
306
303
|
} catch (error) {
|
|
307
304
|
const aborted = error instanceof Error && error.name === "AbortError" || typeof error === "object" && error !== null && error.aborted === true;
|
|
@@ -314,13 +311,23 @@ class ChatSession {
|
|
|
314
311
|
try {
|
|
315
312
|
const history = await this.getHistory();
|
|
316
313
|
const lastAssistant = history.filter((m) => m.role === "assistant").pop();
|
|
317
|
-
if (lastAssistant
|
|
318
|
-
|
|
314
|
+
if (lastAssistant) {
|
|
315
|
+
if (typeof lastAssistant.content === "string") {
|
|
316
|
+
return { text: lastAssistant.content };
|
|
317
|
+
}
|
|
318
|
+
if (Array.isArray(lastAssistant.content)) {
|
|
319
|
+
const text = lastAssistant.content.filter(
|
|
320
|
+
(part) => part.type === "text"
|
|
321
|
+
).map((part) => part.text).join("");
|
|
322
|
+
if (text) {
|
|
323
|
+
return { text };
|
|
324
|
+
}
|
|
325
|
+
}
|
|
319
326
|
}
|
|
320
327
|
} catch {
|
|
321
328
|
this.logger.debug("Failed to retrieve partial response from history on cancel");
|
|
322
329
|
}
|
|
323
|
-
return { text: ""
|
|
330
|
+
return { text: "" };
|
|
324
331
|
}
|
|
325
332
|
if (error instanceof import_errors.DextoRuntimeError && error.code === import_error_codes.PluginErrorCode.PLUGIN_BLOCKED_EXECUTION && error.scope === import_errors.ErrorScope.PLUGIN && error.type === import_errors.ErrorType.FORBIDDEN) {
|
|
326
333
|
const textContent = parts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
|
|
@@ -334,7 +341,7 @@ class ChatSession {
|
|
|
334
341
|
`Failed to save blocked interaction to history: ${saveError instanceof Error ? saveError.message : String(saveError)}`
|
|
335
342
|
);
|
|
336
343
|
}
|
|
337
|
-
return { text: error.message
|
|
344
|
+
return { text: error.message };
|
|
338
345
|
}
|
|
339
346
|
this.logger.error(
|
|
340
347
|
`Error in ChatSession.stream: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -403,7 +410,7 @@ class ChatSession {
|
|
|
403
410
|
* @see {@link ContextManager.resetConversation} for the underlying implementation
|
|
404
411
|
*/
|
|
405
412
|
async reset() {
|
|
406
|
-
await this.
|
|
413
|
+
await this.llmService.getContextManager().resetConversation();
|
|
407
414
|
this.services.agentEventBus.emit("session:reset", {
|
|
408
415
|
sessionId: this.id
|
|
409
416
|
});
|
|
@@ -12,7 +12,6 @@ import type { IDextoLogger } from '../logger/v2/types.js';
|
|
|
12
12
|
import type { InternalMessage } from '../context/types.js';
|
|
13
13
|
import type { UserMessageInput } from './message-queue.js';
|
|
14
14
|
import type { ContentInput } from '../agent/types.js';
|
|
15
|
-
import type { CompactionData } from '../llm/executor/types.js';
|
|
16
15
|
/**
|
|
17
16
|
* Represents an isolated conversation session within a Dexto agent.
|
|
18
17
|
*
|
|
@@ -163,15 +162,15 @@ export declare class ChatSession {
|
|
|
163
162
|
*
|
|
164
163
|
* @param content - String or ContentPart[] (text, images, files)
|
|
165
164
|
* @param options - { signal?: AbortSignal }
|
|
166
|
-
* @returns Promise that resolves to object with text
|
|
165
|
+
* @returns Promise that resolves to object with text response
|
|
167
166
|
*
|
|
168
167
|
* @example
|
|
169
168
|
* ```typescript
|
|
170
169
|
* // Text only
|
|
171
|
-
* const { text
|
|
170
|
+
* const { text } = await session.stream('What is the weather?');
|
|
172
171
|
*
|
|
173
172
|
* // Multiple images
|
|
174
|
-
* const { text
|
|
173
|
+
* const { text } = await session.stream([
|
|
175
174
|
* { type: 'text', text: 'Compare these images' },
|
|
176
175
|
* { type: 'image', image: base64Data1, mimeType: 'image/png' },
|
|
177
176
|
* { type: 'image', image: base64Data2, mimeType: 'image/png' }
|
|
@@ -182,8 +181,6 @@ export declare class ChatSession {
|
|
|
182
181
|
signal?: AbortSignal;
|
|
183
182
|
}): Promise<{
|
|
184
183
|
text: string;
|
|
185
|
-
didCompact: boolean;
|
|
186
|
-
compaction?: CompactionData;
|
|
187
184
|
}>;
|
|
188
185
|
/**
|
|
189
186
|
* Combine multiple abort signals into one.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-session.d.ts","sourceRoot":"","sources":["../../src/session/chat-session.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EACH,eAAe,EACf,aAAa,EAIhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAI1D,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,qBAAqB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version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