@dexto/core 1.5.4 → 1.5.6
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/logger/logger.cjs +6 -7
- package/dist/logger/logger.d.ts +1 -0
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.js +6 -7
- 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/dist/tools/schemas.cjs +2 -2
- package/dist/tools/schemas.js +2 -2
- 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
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var compaction_service_exports = {};
|
|
30
|
-
__export(compaction_service_exports, {
|
|
31
|
-
SessionCompactionService: () => SessionCompactionService
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(compaction_service_exports);
|
|
34
|
-
var import_types = require("../logger/v2/types.js");
|
|
35
|
-
var import_utils = require("../context/utils.js");
|
|
36
|
-
class SessionCompactionService {
|
|
37
|
-
constructor(sessionManager, compactionStrategy, logger) {
|
|
38
|
-
this.sessionManager = sessionManager;
|
|
39
|
-
this.compactionStrategy = compactionStrategy;
|
|
40
|
-
this.logger = logger.createChild(import_types.DextoLogComponent.SESSION);
|
|
41
|
-
}
|
|
42
|
-
logger;
|
|
43
|
-
/**
|
|
44
|
-
* Perform session-native compaction.
|
|
45
|
-
*
|
|
46
|
-
* This creates a new continuation session with the summary as initial context,
|
|
47
|
-
* then marks the old session as compacted.
|
|
48
|
-
*
|
|
49
|
-
* @param currentSession The session to compact
|
|
50
|
-
* @param options Compaction options
|
|
51
|
-
* @returns CompactionResult with new session, or null if compaction not needed/possible
|
|
52
|
-
*/
|
|
53
|
-
async compact(currentSession, options) {
|
|
54
|
-
const { reason, eventBus } = options;
|
|
55
|
-
const currentSessionId = currentSession.id;
|
|
56
|
-
this.logger.info(
|
|
57
|
-
`SessionCompactionService: Starting compaction for session ${currentSessionId} (reason: ${reason})`
|
|
58
|
-
);
|
|
59
|
-
const history = await currentSession.getHistory();
|
|
60
|
-
if (history.length <= 2) {
|
|
61
|
-
this.logger.debug("SessionCompactionService: History too short for compaction");
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
const summaryMessages = await this.compactionStrategy.compact(history);
|
|
65
|
-
if (summaryMessages.length === 0) {
|
|
66
|
-
this.logger.debug("SessionCompactionService: Strategy returned no summary");
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
const strategySummary = summaryMessages[0];
|
|
70
|
-
if (!strategySummary || !strategySummary.content) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
const summaryText = this.extractTextContent(strategySummary.content);
|
|
74
|
-
if (!summaryText.trim()) {
|
|
75
|
-
this.logger.debug("SessionCompactionService: Empty summary text; skipping compaction");
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
const summaryMessage = {
|
|
79
|
-
role: "assistant",
|
|
80
|
-
content: [{ type: "text", text: summaryText }],
|
|
81
|
-
timestamp: Date.now(),
|
|
82
|
-
metadata: {
|
|
83
|
-
isSessionSummary: true,
|
|
84
|
-
// New marker for session-native compaction
|
|
85
|
-
continuedFrom: currentSessionId,
|
|
86
|
-
summarizedAt: Date.now(),
|
|
87
|
-
originalMessageCount: history.length,
|
|
88
|
-
originalFirstTimestamp: history[0]?.timestamp,
|
|
89
|
-
originalLastTimestamp: history[history.length - 1]?.timestamp
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
const summaryTokens = (0, import_utils.estimateMessagesTokens)([summaryMessage]);
|
|
93
|
-
const { sessionId: newSessionId, session: newSession } = await this.sessionManager.createContinuationSession(currentSessionId);
|
|
94
|
-
const contextManager = newSession.getContextManager();
|
|
95
|
-
await contextManager.addMessage(summaryMessage);
|
|
96
|
-
await this.sessionManager.markSessionCompacted(currentSessionId, newSessionId);
|
|
97
|
-
this.logger.info(
|
|
98
|
-
`SessionCompactionService: Compaction complete. ${currentSessionId} \u2192 ${newSessionId}, ${history.length} messages \u2192 summary (~${summaryTokens} tokens)`
|
|
99
|
-
);
|
|
100
|
-
if (eventBus) {
|
|
101
|
-
const llmConfig = newSession.getLLMService().getConfig();
|
|
102
|
-
const modelId = typeof llmConfig.model === "string" ? llmConfig.model : llmConfig.model.modelId;
|
|
103
|
-
const { getModelDisplayName } = await import("../llm/registry.js");
|
|
104
|
-
const modelDisplayName = getModelDisplayName(modelId, llmConfig.provider);
|
|
105
|
-
eventBus.emit("session:continued", {
|
|
106
|
-
previousSessionId: currentSessionId,
|
|
107
|
-
newSessionId,
|
|
108
|
-
summaryTokens,
|
|
109
|
-
originalMessages: history.length,
|
|
110
|
-
reason,
|
|
111
|
-
sessionId: newSessionId,
|
|
112
|
-
// For consistency with other streaming events
|
|
113
|
-
model: modelId,
|
|
114
|
-
modelDisplayName
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
previousSessionId: currentSessionId,
|
|
119
|
-
newSessionId,
|
|
120
|
-
newSession,
|
|
121
|
-
summary: summaryMessage,
|
|
122
|
-
summaryTokens,
|
|
123
|
-
originalMessages: history.length
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Extract text content from message content.
|
|
128
|
-
*/
|
|
129
|
-
extractTextContent(content) {
|
|
130
|
-
if (typeof content === "string") {
|
|
131
|
-
return content;
|
|
132
|
-
}
|
|
133
|
-
return content.filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
137
|
-
0 && (module.exports = {
|
|
138
|
-
SessionCompactionService
|
|
139
|
-
});
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session Compaction Service
|
|
3
|
-
*
|
|
4
|
-
* Handles session-native compaction where compacting a session creates a new
|
|
5
|
-
* continuation session with the summary as initial context. This provides
|
|
6
|
-
* clean session isolation with linking for traceability.
|
|
7
|
-
*
|
|
8
|
-
* ## Architecture
|
|
9
|
-
*
|
|
10
|
-
* Session A (compacted) --continuedTo--> Session B (active)
|
|
11
|
-
* ^ |
|
|
12
|
-
* +--------continuedFrom-----------------+
|
|
13
|
-
*
|
|
14
|
-
* When compaction triggers:
|
|
15
|
-
* 1. Generate summary of old messages via compaction strategy
|
|
16
|
-
* 2. Create new session with summary as first message (isSessionSummary marker)
|
|
17
|
-
* 3. Mark old session as compacted (continuedTo, compactedAt)
|
|
18
|
-
* 4. Emit session:continued event
|
|
19
|
-
* 5. Return new session for caller to switch to
|
|
20
|
-
*/
|
|
21
|
-
import type { ICompactionStrategy } from '../context/compaction/types.js';
|
|
22
|
-
import type { IDextoLogger } from '../logger/v2/types.js';
|
|
23
|
-
import type { SessionManager } from './session-manager.js';
|
|
24
|
-
import type { ChatSession } from './chat-session.js';
|
|
25
|
-
import type { InternalMessage } from '../context/types.js';
|
|
26
|
-
import type { AgentEventBus } from '../events/index.js';
|
|
27
|
-
/**
|
|
28
|
-
* Result returned when compaction creates a new continuation session.
|
|
29
|
-
*/
|
|
30
|
-
export interface CompactionResult {
|
|
31
|
-
/** The session that was compacted */
|
|
32
|
-
previousSessionId: string;
|
|
33
|
-
/** The new session created for continuation */
|
|
34
|
-
newSessionId: string;
|
|
35
|
-
/** The ChatSession instance for the new session */
|
|
36
|
-
newSession: ChatSession;
|
|
37
|
-
/** The summary message added to the new session */
|
|
38
|
-
summary: InternalMessage;
|
|
39
|
-
/** Estimated tokens in the summary */
|
|
40
|
-
summaryTokens: number;
|
|
41
|
-
/** Number of messages that were summarized */
|
|
42
|
-
originalMessages: number;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Options for performing compaction.
|
|
46
|
-
*/
|
|
47
|
-
export interface CompactOptions {
|
|
48
|
-
/** Why the compaction was triggered */
|
|
49
|
-
reason: 'overflow' | 'manual';
|
|
50
|
-
/** Optional AgentEventBus to emit session:continued event */
|
|
51
|
-
eventBus?: AgentEventBus;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Service for performing session-native compaction.
|
|
55
|
-
*
|
|
56
|
-
* Instead of adding a summary message to the same session and filtering at read-time,
|
|
57
|
-
* this service creates a new session with the summary as the first message.
|
|
58
|
-
* This provides cleaner session isolation while maintaining traceability via linking.
|
|
59
|
-
*/
|
|
60
|
-
export declare class SessionCompactionService {
|
|
61
|
-
private readonly sessionManager;
|
|
62
|
-
private readonly compactionStrategy;
|
|
63
|
-
private readonly logger;
|
|
64
|
-
constructor(sessionManager: SessionManager, compactionStrategy: ICompactionStrategy, logger: IDextoLogger);
|
|
65
|
-
/**
|
|
66
|
-
* Perform session-native compaction.
|
|
67
|
-
*
|
|
68
|
-
* This creates a new continuation session with the summary as initial context,
|
|
69
|
-
* then marks the old session as compacted.
|
|
70
|
-
*
|
|
71
|
-
* @param currentSession The session to compact
|
|
72
|
-
* @param options Compaction options
|
|
73
|
-
* @returns CompactionResult with new session, or null if compaction not needed/possible
|
|
74
|
-
*/
|
|
75
|
-
compact(currentSession: ChatSession, options: CompactOptions): Promise<CompactionResult | null>;
|
|
76
|
-
/**
|
|
77
|
-
* Extract text content from message content.
|
|
78
|
-
*/
|
|
79
|
-
private extractTextContent;
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=compaction-service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compaction-service.d.ts","sourceRoot":"","sources":["../../src/session/compaction-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,qBAAqB,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAIxD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,qCAAqC;IACrC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,+CAA+C;IAC/C,YAAY,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,UAAU,EAAE,WAAW,CAAC;IACxB,mDAAmD;IACnD,OAAO,EAAE,eAAe,CAAC;IACzB,sCAAsC;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,8CAA8C;IAC9C,gBAAgB,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,uCAAuC;IACvC,MAAM,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC9B,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,qBAAa,wBAAwB;IAI7B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IAJvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;gBAGjB,cAAc,EAAE,cAAc,EAC9B,kBAAkB,EAAE,mBAAmB,EACxD,MAAM,EAAE,YAAY;IAKxB;;;;;;;;;OASG;IACG,OAAO,CACT,cAAc,EAAE,WAAW,EAC3B,OAAO,EAAE,cAAc,GACxB,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IA6GnC;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAS7B"}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import "../chunk-PTJYTZNU.js";
|
|
2
|
-
import { DextoLogComponent } from "../logger/v2/types.js";
|
|
3
|
-
import { estimateMessagesTokens } from "../context/utils.js";
|
|
4
|
-
class SessionCompactionService {
|
|
5
|
-
constructor(sessionManager, compactionStrategy, logger) {
|
|
6
|
-
this.sessionManager = sessionManager;
|
|
7
|
-
this.compactionStrategy = compactionStrategy;
|
|
8
|
-
this.logger = logger.createChild(DextoLogComponent.SESSION);
|
|
9
|
-
}
|
|
10
|
-
logger;
|
|
11
|
-
/**
|
|
12
|
-
* Perform session-native compaction.
|
|
13
|
-
*
|
|
14
|
-
* This creates a new continuation session with the summary as initial context,
|
|
15
|
-
* then marks the old session as compacted.
|
|
16
|
-
*
|
|
17
|
-
* @param currentSession The session to compact
|
|
18
|
-
* @param options Compaction options
|
|
19
|
-
* @returns CompactionResult with new session, or null if compaction not needed/possible
|
|
20
|
-
*/
|
|
21
|
-
async compact(currentSession, options) {
|
|
22
|
-
const { reason, eventBus } = options;
|
|
23
|
-
const currentSessionId = currentSession.id;
|
|
24
|
-
this.logger.info(
|
|
25
|
-
`SessionCompactionService: Starting compaction for session ${currentSessionId} (reason: ${reason})`
|
|
26
|
-
);
|
|
27
|
-
const history = await currentSession.getHistory();
|
|
28
|
-
if (history.length <= 2) {
|
|
29
|
-
this.logger.debug("SessionCompactionService: History too short for compaction");
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
const summaryMessages = await this.compactionStrategy.compact(history);
|
|
33
|
-
if (summaryMessages.length === 0) {
|
|
34
|
-
this.logger.debug("SessionCompactionService: Strategy returned no summary");
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
const strategySummary = summaryMessages[0];
|
|
38
|
-
if (!strategySummary || !strategySummary.content) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
const summaryText = this.extractTextContent(strategySummary.content);
|
|
42
|
-
if (!summaryText.trim()) {
|
|
43
|
-
this.logger.debug("SessionCompactionService: Empty summary text; skipping compaction");
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
const summaryMessage = {
|
|
47
|
-
role: "assistant",
|
|
48
|
-
content: [{ type: "text", text: summaryText }],
|
|
49
|
-
timestamp: Date.now(),
|
|
50
|
-
metadata: {
|
|
51
|
-
isSessionSummary: true,
|
|
52
|
-
// New marker for session-native compaction
|
|
53
|
-
continuedFrom: currentSessionId,
|
|
54
|
-
summarizedAt: Date.now(),
|
|
55
|
-
originalMessageCount: history.length,
|
|
56
|
-
originalFirstTimestamp: history[0]?.timestamp,
|
|
57
|
-
originalLastTimestamp: history[history.length - 1]?.timestamp
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const summaryTokens = estimateMessagesTokens([summaryMessage]);
|
|
61
|
-
const { sessionId: newSessionId, session: newSession } = await this.sessionManager.createContinuationSession(currentSessionId);
|
|
62
|
-
const contextManager = newSession.getContextManager();
|
|
63
|
-
await contextManager.addMessage(summaryMessage);
|
|
64
|
-
await this.sessionManager.markSessionCompacted(currentSessionId, newSessionId);
|
|
65
|
-
this.logger.info(
|
|
66
|
-
`SessionCompactionService: Compaction complete. ${currentSessionId} \u2192 ${newSessionId}, ${history.length} messages \u2192 summary (~${summaryTokens} tokens)`
|
|
67
|
-
);
|
|
68
|
-
if (eventBus) {
|
|
69
|
-
const llmConfig = newSession.getLLMService().getConfig();
|
|
70
|
-
const modelId = typeof llmConfig.model === "string" ? llmConfig.model : llmConfig.model.modelId;
|
|
71
|
-
const { getModelDisplayName } = await import("../llm/registry.js");
|
|
72
|
-
const modelDisplayName = getModelDisplayName(modelId, llmConfig.provider);
|
|
73
|
-
eventBus.emit("session:continued", {
|
|
74
|
-
previousSessionId: currentSessionId,
|
|
75
|
-
newSessionId,
|
|
76
|
-
summaryTokens,
|
|
77
|
-
originalMessages: history.length,
|
|
78
|
-
reason,
|
|
79
|
-
sessionId: newSessionId,
|
|
80
|
-
// For consistency with other streaming events
|
|
81
|
-
model: modelId,
|
|
82
|
-
modelDisplayName
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
previousSessionId: currentSessionId,
|
|
87
|
-
newSessionId,
|
|
88
|
-
newSession,
|
|
89
|
-
summary: summaryMessage,
|
|
90
|
-
summaryTokens,
|
|
91
|
-
originalMessages: history.length
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Extract text content from message content.
|
|
96
|
-
*/
|
|
97
|
-
extractTextContent(content) {
|
|
98
|
-
if (typeof content === "string") {
|
|
99
|
-
return content;
|
|
100
|
-
}
|
|
101
|
-
return content.filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
export {
|
|
105
|
-
SessionCompactionService
|
|
106
|
-
};
|