@ai-setting/roy-agent-core 1.5.13-test → 1.5.15-test
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/package.json +1 -1
- package/dist/config/index.d.ts +0 -1250
- package/dist/config/index.js +0 -32
- package/dist/env/agent/index.d.ts +0 -2279
- package/dist/env/agent/index.js +0 -24
- package/dist/env/commands/index.d.ts +0 -1131
- package/dist/env/commands/index.js +0 -14
- package/dist/env/debug/formatters/index.d.ts +0 -236
- package/dist/env/debug/formatters/index.js +0 -11
- package/dist/env/debug/index.d.ts +0 -1652
- package/dist/env/debug/index.js +0 -26
- package/dist/env/hook/index.d.ts +0 -279
- package/dist/env/hook/index.js +0 -29
- package/dist/env/index.d.ts +0 -3481
- package/dist/env/index.js +0 -82
- package/dist/env/llm/index.d.ts +0 -1760
- package/dist/env/llm/index.js +0 -40
- package/dist/env/log-trace/index.d.ts +0 -1574
- package/dist/env/log-trace/index.js +0 -83
- package/dist/env/mcp/index.d.ts +0 -1331
- package/dist/env/mcp/index.js +0 -39
- package/dist/env/mcp/tool/index.d.ts +0 -183
- package/dist/env/mcp/tool/index.js +0 -14
- package/dist/env/memory/built-in/index.d.ts +0 -232
- package/dist/env/memory/built-in/index.js +0 -11
- package/dist/env/memory/index.d.ts +0 -1799
- package/dist/env/memory/index.js +0 -56
- package/dist/env/memory/plugin/index.d.ts +0 -747
- package/dist/env/memory/plugin/index.js +0 -36
- package/dist/env/prompt/index.d.ts +0 -1164
- package/dist/env/prompt/index.js +0 -20
- package/dist/env/session/index.d.ts +0 -1908
- package/dist/env/session/index.js +0 -25
- package/dist/env/session/storage/index.d.ts +0 -564
- package/dist/env/session/storage/index.js +0 -18
- package/dist/env/skill/index.d.ts +0 -1266
- package/dist/env/skill/index.js +0 -34
- package/dist/env/skill/tool/index.d.ts +0 -193
- package/dist/env/skill/tool/index.js +0 -9
- package/dist/env/task/delegate/index.d.ts +0 -1612
- package/dist/env/task/delegate/index.js +0 -18
- package/dist/env/task/events/index.d.ts +0 -171
- package/dist/env/task/events/index.js +0 -7
- package/dist/env/task/hooks/index.d.ts +0 -624
- package/dist/env/task/hooks/index.js +0 -7
- package/dist/env/task/index.d.ts +0 -1553
- package/dist/env/task/index.js +0 -34
- package/dist/env/task/plugins/index.d.ts +0 -466
- package/dist/env/task/plugins/index.js +0 -23
- package/dist/env/task/storage/index.d.ts +0 -241
- package/dist/env/task/storage/index.js +0 -14
- package/dist/env/task/tools/index.d.ts +0 -1485
- package/dist/env/task/tools/index.js +0 -17
- package/dist/env/task/tools/operation/index.d.ts +0 -1484
- package/dist/env/task/tools/operation/index.js +0 -15
- package/dist/env/tool/built-in/index.d.ts +0 -218
- package/dist/env/tool/built-in/index.js +0 -25
- package/dist/env/tool/index.d.ts +0 -1396
- package/dist/env/tool/index.js +0 -39
- package/dist/env/workflow/decorators/index.d.ts +0 -2161
- package/dist/env/workflow/decorators/index.js +0 -27
- package/dist/env/workflow/engine/index.d.ts +0 -3453
- package/dist/env/workflow/engine/index.js +0 -28
- package/dist/env/workflow/index.d.ts +0 -3546
- package/dist/env/workflow/index.js +0 -136
- package/dist/env/workflow/nodes/index.d.ts +0 -2092
- package/dist/env/workflow/nodes/index.js +0 -19
- package/dist/env/workflow/service/index.d.ts +0 -227
- package/dist/env/workflow/service/index.js +0 -13
- package/dist/env/workflow/storage/index.d.ts +0 -165
- package/dist/env/workflow/storage/index.js +0 -27
- package/dist/env/workflow/tools/index.d.ts +0 -416
- package/dist/env/workflow/tools/index.js +0 -159
- package/dist/env/workflow/types/index.d.ts +0 -2255
- package/dist/env/workflow/types/index.js +0 -98
- package/dist/env/workflow/utils/index.d.ts +0 -2031
- package/dist/env/workflow/utils/index.js +0 -637
- package/dist/index.d.ts +0 -7858
- package/dist/index.js +0 -399
- package/dist/shared/@ai-setting/roy-agent-core-0rtxwr28.js +0 -258
- package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +0 -36
- package/dist/shared/@ai-setting/roy-agent-core-1akcqxj9.js +0 -349
- package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +0 -117
- package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +0 -11
- package/dist/shared/@ai-setting/roy-agent-core-3jywqmdd.js +0 -393
- package/dist/shared/@ai-setting/roy-agent-core-3rr5k71j.js +0 -200
- package/dist/shared/@ai-setting/roy-agent-core-44hnfb02.js +0 -299
- package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +0 -206
- package/dist/shared/@ai-setting/roy-agent-core-4txzpsbt.js +0 -393
- package/dist/shared/@ai-setting/roy-agent-core-5x94xmt6.js +0 -350
- package/dist/shared/@ai-setting/roy-agent-core-69jskqjg.js +0 -180
- package/dist/shared/@ai-setting/roy-agent-core-6kvtahqv.js +0 -408
- package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +0 -284
- package/dist/shared/@ai-setting/roy-agent-core-81w1963m.js +0 -762
- package/dist/shared/@ai-setting/roy-agent-core-8gxth0eh.js +0 -10
- package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +0 -14
- package/dist/shared/@ai-setting/roy-agent-core-93zfb3r1.js +0 -922
- package/dist/shared/@ai-setting/roy-agent-core-9yxb3ty9.js +0 -15
- package/dist/shared/@ai-setting/roy-agent-core-b0x5dda6.js +0 -1130
- package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +0 -14
- package/dist/shared/@ai-setting/roy-agent-core-bvr1761x.js +0 -653
- package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +0 -93
- package/dist/shared/@ai-setting/roy-agent-core-d7cyjkf7.js +0 -872
- package/dist/shared/@ai-setting/roy-agent-core-dh9d7a3m.js +0 -11
- package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +0 -64
- package/dist/shared/@ai-setting/roy-agent-core-eajcvp4e.js +0 -378
- package/dist/shared/@ai-setting/roy-agent-core-f7q2x5z6.js +0 -492
- package/dist/shared/@ai-setting/roy-agent-core-fs0mn2jk.js +0 -52
- package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +0 -171
- package/dist/shared/@ai-setting/roy-agent-core-g99pxzn5.js +0 -862
- package/dist/shared/@ai-setting/roy-agent-core-gbqcyegm.js +0 -1387
- package/dist/shared/@ai-setting/roy-agent-core-gjq1yk68.js +0 -208
- package/dist/shared/@ai-setting/roy-agent-core-gq20wsgv.js +0 -139
- package/dist/shared/@ai-setting/roy-agent-core-gwc4h96n.js +0 -534
- package/dist/shared/@ai-setting/roy-agent-core-jfh9q2qh.js +0 -204
- package/dist/shared/@ai-setting/roy-agent-core-jvatggbb.js +0 -603
- package/dist/shared/@ai-setting/roy-agent-core-kkbwepqb.js +0 -97
- package/dist/shared/@ai-setting/roy-agent-core-pjr12nnd.js +0 -587
- package/dist/shared/@ai-setting/roy-agent-core-psv4v63c.js +0 -176
- package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +0 -60
- package/dist/shared/@ai-setting/roy-agent-core-qqceba6k.js +0 -442
- package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +0 -57
- package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +0 -66
- package/dist/shared/@ai-setting/roy-agent-core-r9ezzemr.js +0 -10
- package/dist/shared/@ai-setting/roy-agent-core-rhmtwnw1.js +0 -267
- package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +0 -584
- package/dist/shared/@ai-setting/roy-agent-core-rvxg1wps.js +0 -102
- package/dist/shared/@ai-setting/roy-agent-core-satmq6sh.js +0 -549
- package/dist/shared/@ai-setting/roy-agent-core-sx7wsvnn.js +0 -15
- package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +0 -213
- package/dist/shared/@ai-setting/roy-agent-core-vf215qfv.js +0 -812
- package/dist/shared/@ai-setting/roy-agent-core-vkz81f7v.js +0 -1316
- package/dist/shared/@ai-setting/roy-agent-core-vn2bc59q.js +0 -1205
- package/dist/shared/@ai-setting/roy-agent-core-wa1kzqky.js +0 -328
- package/dist/shared/@ai-setting/roy-agent-core-wft9ra24.js +0 -20
- package/dist/shared/@ai-setting/roy-agent-core-wrcy0h6z.js +0 -2098
- package/dist/shared/@ai-setting/roy-agent-core-xq8hhqb8.js +0 -419
- package/dist/shared/@ai-setting/roy-agent-core-xs5rsgat.js +0 -368
- package/dist/shared/@ai-setting/roy-agent-core-zbkpc41z.js +0 -377
- package/dist/shared/@ai-setting/roy-agent-core-zgypchmt.js +0 -172
- package/dist/shared/@ai-setting/roy-agent-core-zpn0bqa8.js +0 -103
|
@@ -1,762 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
init_search_query_parser,
|
|
3
|
-
matchesQuery,
|
|
4
|
-
parseSearchQuery
|
|
5
|
-
} from "./roy-agent-core-rvxg1wps.js";
|
|
6
|
-
import {
|
|
7
|
-
SummaryAgent
|
|
8
|
-
} from "./roy-agent-core-eajcvp4e.js";
|
|
9
|
-
import {
|
|
10
|
-
envKeyToConfigKey
|
|
11
|
-
} from "./roy-agent-core-qxhq8ven.js";
|
|
12
|
-
import {
|
|
13
|
-
BaseComponent
|
|
14
|
-
} from "./roy-agent-core-kkbwepqb.js";
|
|
15
|
-
import {
|
|
16
|
-
MemorySessionStore,
|
|
17
|
-
SQLiteSessionStore
|
|
18
|
-
} from "./roy-agent-core-d7cyjkf7.js";
|
|
19
|
-
import {
|
|
20
|
-
TracedAs,
|
|
21
|
-
init_decorator
|
|
22
|
-
} from "./roy-agent-core-zgypchmt.js";
|
|
23
|
-
import {
|
|
24
|
-
createLogger,
|
|
25
|
-
init_logger
|
|
26
|
-
} from "./roy-agent-core-44hnfb02.js";
|
|
27
|
-
import {
|
|
28
|
-
__legacyDecorateClassTS
|
|
29
|
-
} from "./roy-agent-core-fs0mn2jk.js";
|
|
30
|
-
|
|
31
|
-
// src/env/session/session-component.ts
|
|
32
|
-
init_logger();
|
|
33
|
-
init_decorator();
|
|
34
|
-
|
|
35
|
-
// src/env/session/session-config-registration.ts
|
|
36
|
-
var SESSION_DEFAULTS = {
|
|
37
|
-
"session.defaultDirectory": "/tmp",
|
|
38
|
-
"session.defaultTitleTemplate": "Session - {date}",
|
|
39
|
-
"session.maxMessages": 100,
|
|
40
|
-
"session.compactionThreshold": 80,
|
|
41
|
-
"session.autoCompact": true,
|
|
42
|
-
"session.storage.type": "sqlite",
|
|
43
|
-
"session.storage.dbPath": undefined,
|
|
44
|
-
"session.checkpoint.enabled": false,
|
|
45
|
-
"session.contextLimit": 1e5,
|
|
46
|
-
"session.maxSessions": 100
|
|
47
|
-
};
|
|
48
|
-
var SESSION_CONFIG_REGISTRATION = {
|
|
49
|
-
name: "session",
|
|
50
|
-
sources: [
|
|
51
|
-
{ type: "env", envPrefix: "SESSION", priority: 20, watch: false }
|
|
52
|
-
],
|
|
53
|
-
keys: [
|
|
54
|
-
{ key: "session.defaultDirectory", sources: ["env", "file"] },
|
|
55
|
-
{ key: "session.defaultTitleTemplate", sources: ["env", "file"] },
|
|
56
|
-
{ key: "session.maxMessages", sources: ["env", "file"] },
|
|
57
|
-
{ key: "session.compactionThreshold", sources: ["env", "file"] },
|
|
58
|
-
{ key: "session.autoCompact", sources: ["env", "file"] },
|
|
59
|
-
{ key: "session.storage.type", sources: ["env", "file"] },
|
|
60
|
-
{ key: "session.storage.dbPath", sources: ["env", "file"] },
|
|
61
|
-
{ key: "session.checkpoint.enabled", sources: ["env", "file"] },
|
|
62
|
-
{ key: "session.contextLimit", sources: ["env", "file"] },
|
|
63
|
-
{ key: "session.maxSessions", sources: ["env", "file"] }
|
|
64
|
-
]
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// src/env/session/session-component.ts
|
|
68
|
-
init_search_query_parser();
|
|
69
|
-
import path from "path";
|
|
70
|
-
var logger = createLogger("session");
|
|
71
|
-
|
|
72
|
-
class SessionComponent extends BaseComponent {
|
|
73
|
-
name = "session";
|
|
74
|
-
version = "1.1.0";
|
|
75
|
-
config;
|
|
76
|
-
store;
|
|
77
|
-
activeSessionId;
|
|
78
|
-
hooksConfig = {};
|
|
79
|
-
configComponent;
|
|
80
|
-
configWatcher;
|
|
81
|
-
summaryAgent;
|
|
82
|
-
promptComponent;
|
|
83
|
-
llmComponent;
|
|
84
|
-
constructor() {
|
|
85
|
-
super();
|
|
86
|
-
}
|
|
87
|
-
async init(config) {
|
|
88
|
-
await super.init(config);
|
|
89
|
-
const options = config?.options;
|
|
90
|
-
if (!options?.configComponent) {
|
|
91
|
-
throw new Error("ConfigComponent is required for SessionComponent initialization");
|
|
92
|
-
}
|
|
93
|
-
this.configComponent = options.configComponent;
|
|
94
|
-
await this.registerConfig(options);
|
|
95
|
-
const storageConfig = this.config?.storage;
|
|
96
|
-
if (storageConfig?.type === "sqlite") {
|
|
97
|
-
this.store = new SQLiteSessionStore(storageConfig.dbPath);
|
|
98
|
-
logger.info(`[SessionComponent] Using SQLite storage: ${storageConfig.dbPath || "default path"}`);
|
|
99
|
-
} else {
|
|
100
|
-
this.store = new MemorySessionStore;
|
|
101
|
-
logger.info("[SessionComponent] Using memory storage");
|
|
102
|
-
}
|
|
103
|
-
this.setStatus("running");
|
|
104
|
-
logger.info("[SessionComponent] Initialized");
|
|
105
|
-
}
|
|
106
|
-
getDefaultSessionDbPath() {
|
|
107
|
-
const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
108
|
-
return path.join(home, ".local", "share", "roy-agent", "sessions.db");
|
|
109
|
-
}
|
|
110
|
-
async registerConfig(options) {
|
|
111
|
-
const configComponent = options.configComponent;
|
|
112
|
-
if (!configComponent)
|
|
113
|
-
return;
|
|
114
|
-
const { configPath, envPrefix, config } = options;
|
|
115
|
-
const prefix = envPrefix !== undefined ? envPrefix : "SESSION";
|
|
116
|
-
configComponent.registerComponent(SESSION_CONFIG_REGISTRATION);
|
|
117
|
-
if (configPath) {
|
|
118
|
-
configComponent.registerSource({
|
|
119
|
-
type: "file",
|
|
120
|
-
relativePath: configPath,
|
|
121
|
-
optional: true,
|
|
122
|
-
watch: false
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
configComponent.registerSource({
|
|
126
|
-
type: "env",
|
|
127
|
-
envPrefix: prefix,
|
|
128
|
-
priority: 20,
|
|
129
|
-
watch: false
|
|
130
|
-
});
|
|
131
|
-
await configComponent.load("session");
|
|
132
|
-
for (const envKey of Object.keys(process.env)) {
|
|
133
|
-
const configKey = envKeyToConfigKey(envKey, prefix, "session");
|
|
134
|
-
if (!configKey)
|
|
135
|
-
continue;
|
|
136
|
-
const value = process.env[envKey];
|
|
137
|
-
if (value !== undefined) {
|
|
138
|
-
await configComponent.set(configKey, value);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
for (const [key, value] of Object.entries(SESSION_DEFAULTS)) {
|
|
142
|
-
if (configComponent.get(key) === undefined) {
|
|
143
|
-
await configComponent.set(key, value);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (configComponent.get("session.storage.dbPath") === undefined) {
|
|
147
|
-
await configComponent.set("session.storage.dbPath", this.getDefaultSessionDbPath());
|
|
148
|
-
}
|
|
149
|
-
if (config) {
|
|
150
|
-
const flatConfig = this.flattenConfig(config);
|
|
151
|
-
for (const [key, value] of Object.entries(flatConfig)) {
|
|
152
|
-
await configComponent.set(key, value);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
this.registerConfigWatcher(configComponent);
|
|
156
|
-
this.config = this.buildConfig(configComponent);
|
|
157
|
-
}
|
|
158
|
-
buildConfig(configComponent) {
|
|
159
|
-
return {
|
|
160
|
-
defaultDirectory: configComponent.get("session.defaultDirectory"),
|
|
161
|
-
defaultTitleTemplate: configComponent.get("session.defaultTitleTemplate"),
|
|
162
|
-
maxMessages: configComponent.get("session.maxMessages"),
|
|
163
|
-
compactionThreshold: configComponent.get("session.compactionThreshold"),
|
|
164
|
-
autoCompact: configComponent.get("session.autoCompact"),
|
|
165
|
-
storage: {
|
|
166
|
-
type: configComponent.get("session.storage.type"),
|
|
167
|
-
dbPath: configComponent.get("session.storage.dbPath")
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
flattenConfig(obj, prefix = "session") {
|
|
172
|
-
const result = {};
|
|
173
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
174
|
-
const fullKey = `${prefix}.${key}`;
|
|
175
|
-
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
176
|
-
Object.assign(result, this.flattenConfig(value, fullKey));
|
|
177
|
-
} else {
|
|
178
|
-
result[fullKey] = value;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return result;
|
|
182
|
-
}
|
|
183
|
-
registerConfigWatcher(configComponent) {
|
|
184
|
-
if (typeof configComponent.watch !== "function") {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
this.configWatcher = configComponent.watch("session.*", (event) => {
|
|
188
|
-
this.onConfigChange(event);
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
onConfigChange(event) {
|
|
192
|
-
logger.info(`Session config changed: ${event.key}`, {
|
|
193
|
-
oldValue: event.oldValue,
|
|
194
|
-
newValue: event.newValue
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
async onStart() {
|
|
198
|
-
logger.info("[SessionComponent] Started");
|
|
199
|
-
}
|
|
200
|
-
async onStop() {
|
|
201
|
-
this.configWatcher?.();
|
|
202
|
-
this.configWatcher = undefined;
|
|
203
|
-
await this.store?.close();
|
|
204
|
-
this.store = undefined;
|
|
205
|
-
this.setStatus("stopped");
|
|
206
|
-
logger.info("[SessionComponent] Stopped");
|
|
207
|
-
}
|
|
208
|
-
async create(options = {}) {
|
|
209
|
-
await this.executeBeforeHooks("create", { options });
|
|
210
|
-
const title = options.title ?? this.generateTitle();
|
|
211
|
-
const session = await this.store.create({
|
|
212
|
-
...options,
|
|
213
|
-
title
|
|
214
|
-
});
|
|
215
|
-
logger.info(`[SessionComponent] Created session: ${session.id}`, { title });
|
|
216
|
-
await this.executeAfterHooks("create", { session, options });
|
|
217
|
-
return session;
|
|
218
|
-
}
|
|
219
|
-
async get(id) {
|
|
220
|
-
await this.executeBeforeHooks("session.get", { id });
|
|
221
|
-
const session = await this.store?.get(id);
|
|
222
|
-
await this.executeAfterHooks("session.get", { session });
|
|
223
|
-
return session;
|
|
224
|
-
}
|
|
225
|
-
async getSession(id) {
|
|
226
|
-
const session = await this.get(id);
|
|
227
|
-
if (!session) {
|
|
228
|
-
return null;
|
|
229
|
-
}
|
|
230
|
-
const messages = await this.getMessages(id);
|
|
231
|
-
return {
|
|
232
|
-
sessionId: session.id,
|
|
233
|
-
title: session.title || "Untitled",
|
|
234
|
-
messages: messages.map((m) => ({
|
|
235
|
-
role: m.role,
|
|
236
|
-
content: m.content,
|
|
237
|
-
timestamp: m.timestamp
|
|
238
|
-
}))
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
async searchSessions(query, options) {
|
|
242
|
-
const limit = options?.limit ?? 20;
|
|
243
|
-
if (options?.session_id) {
|
|
244
|
-
const session = await this.get(options.session_id);
|
|
245
|
-
if (session) {
|
|
246
|
-
const messages = await this.getMessages(options.session_id);
|
|
247
|
-
const lastMessage = messages[messages.length - 1];
|
|
248
|
-
return [{
|
|
249
|
-
sessionId: session.id,
|
|
250
|
-
title: session.title || "Untitled",
|
|
251
|
-
preview: lastMessage?.content?.substring(0, 200) || "",
|
|
252
|
-
timestamp: session.updatedAt || session.createdAt
|
|
253
|
-
}];
|
|
254
|
-
}
|
|
255
|
-
return [];
|
|
256
|
-
}
|
|
257
|
-
const sessions = await this.list({ limit });
|
|
258
|
-
const results = [];
|
|
259
|
-
for (const session of sessions) {
|
|
260
|
-
if (results.length >= limit)
|
|
261
|
-
break;
|
|
262
|
-
const messages = await this.getMessages(session.id);
|
|
263
|
-
const lastMessage = messages[messages.length - 1];
|
|
264
|
-
const preview = lastMessage?.content?.substring(0, 200) || "";
|
|
265
|
-
if (query) {
|
|
266
|
-
const lowerQuery = query.toLowerCase();
|
|
267
|
-
const titleMatch = (session.title || "").toLowerCase().includes(lowerQuery);
|
|
268
|
-
const previewMatch = preview.toLowerCase().includes(lowerQuery);
|
|
269
|
-
if (!titleMatch && !previewMatch) {
|
|
270
|
-
continue;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
results.push({
|
|
274
|
-
sessionId: session.id,
|
|
275
|
-
title: session.title || "Untitled",
|
|
276
|
-
preview,
|
|
277
|
-
timestamp: session.updatedAt || session.createdAt
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
return results;
|
|
281
|
-
}
|
|
282
|
-
async list(options) {
|
|
283
|
-
await this.executeBeforeHooks("session.list", { options });
|
|
284
|
-
const sessions = await this.store?.list(options) ?? [];
|
|
285
|
-
await this.executeAfterHooks("session.list", { sessions });
|
|
286
|
-
return sessions;
|
|
287
|
-
}
|
|
288
|
-
async getCount() {
|
|
289
|
-
return await this.store?.getCount() ?? 0;
|
|
290
|
-
}
|
|
291
|
-
async update(id, updates) {
|
|
292
|
-
await this.executeBeforeHooks("session.update", { id, updates });
|
|
293
|
-
const success = await this.store?.update(id, updates);
|
|
294
|
-
if (success) {
|
|
295
|
-
logger.info(`[SessionComponent] Updated session: ${id}`, { updates });
|
|
296
|
-
await this.executeAfterHooks("session.update", { id, updates });
|
|
297
|
-
}
|
|
298
|
-
return success ?? false;
|
|
299
|
-
}
|
|
300
|
-
async delete(id) {
|
|
301
|
-
await this.executeBeforeHooks("session.delete", { id });
|
|
302
|
-
const success = await this.store?.delete(id);
|
|
303
|
-
if (success) {
|
|
304
|
-
if (this.activeSessionId === id) {
|
|
305
|
-
this.activeSessionId = undefined;
|
|
306
|
-
}
|
|
307
|
-
logger.info(`[SessionComponent] Deleted session: ${id}`);
|
|
308
|
-
await this.executeAfterHooks("session.delete", { id });
|
|
309
|
-
}
|
|
310
|
-
return success ?? false;
|
|
311
|
-
}
|
|
312
|
-
getActiveSession() {
|
|
313
|
-
if (!this.activeSessionId)
|
|
314
|
-
return;
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
getActiveSessionId() {
|
|
318
|
-
return this.activeSessionId;
|
|
319
|
-
}
|
|
320
|
-
async setActiveSession(id) {
|
|
321
|
-
const session = await this.store?.get(id);
|
|
322
|
-
if (!session)
|
|
323
|
-
return false;
|
|
324
|
-
this.activeSessionId = id;
|
|
325
|
-
logger.info(`[SessionComponent] Active session set: ${id}`);
|
|
326
|
-
return true;
|
|
327
|
-
}
|
|
328
|
-
async addMessage(sessionId, message) {
|
|
329
|
-
const contentPreview = typeof message.content === "string" ? message.content.substring(0, 100) : JSON.stringify(message.content).substring(0, 100);
|
|
330
|
-
logger.info(`[SessionComponent.addMessage] sessionId=${sessionId}, role=${message.role}, content="${contentPreview}"`);
|
|
331
|
-
try {
|
|
332
|
-
const messageId = await this.store?.addMessage(sessionId, message);
|
|
333
|
-
logger.info(`[SessionComponent.addMessage] Success: messageId=${messageId}`);
|
|
334
|
-
return messageId;
|
|
335
|
-
} catch (error) {
|
|
336
|
-
logger.error(`[SessionComponent] Failed to add message: ${error}`);
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
async getMessages(sessionId, options) {
|
|
341
|
-
const messages = await this.store?.getMessages(sessionId, options?.offset, options?.limit);
|
|
342
|
-
return messages ?? [];
|
|
343
|
-
}
|
|
344
|
-
async getMessageCount(sessionId, includeArchived) {
|
|
345
|
-
return this.store?.getMessageCount(sessionId, includeArchived) ?? 0;
|
|
346
|
-
}
|
|
347
|
-
async getMessageIndexes(sessionId, role) {
|
|
348
|
-
return this.store?.getMessageIndexes(sessionId, role) ?? [];
|
|
349
|
-
}
|
|
350
|
-
async executeBeforeHooks(operation, context) {
|
|
351
|
-
const hookKey = `before.session.${operation}`;
|
|
352
|
-
const hooks = this.hooksConfig[hookKey] ?? [];
|
|
353
|
-
const hookContext = context;
|
|
354
|
-
for (const hook of hooks) {
|
|
355
|
-
if (hook.before) {
|
|
356
|
-
await hook.before(hookContext);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
const options = context.options;
|
|
360
|
-
if (options?.hooks) {
|
|
361
|
-
const hookArray = options.hooks[hookKey] ?? [];
|
|
362
|
-
for (const hook of hookArray) {
|
|
363
|
-
if (hook.before) {
|
|
364
|
-
await hook.before(hookContext);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
async executeAfterHooks(operation, context) {
|
|
370
|
-
const hookKey = `after.session.${operation}`;
|
|
371
|
-
const hooks = this.hooksConfig[hookKey] ?? [];
|
|
372
|
-
const hookContext = context;
|
|
373
|
-
for (const hook of hooks) {
|
|
374
|
-
if (hook.after) {
|
|
375
|
-
await hook.after(hookContext);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
const options = context.options;
|
|
379
|
-
if (options?.hooks) {
|
|
380
|
-
const hookArray = options.hooks[hookKey] ?? [];
|
|
381
|
-
for (const hook of hookArray) {
|
|
382
|
-
if (hook.after) {
|
|
383
|
-
await hook.after(hookContext);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
generateTitle() {
|
|
389
|
-
const template = this.config?.defaultTitleTemplate ?? "Session - {date}";
|
|
390
|
-
const date = new Date().toISOString().replace("T", " ").substring(0, 19);
|
|
391
|
-
return template.replace("{date}", date);
|
|
392
|
-
}
|
|
393
|
-
setSummaryComponents(promptComponent, llmComponent) {
|
|
394
|
-
this.promptComponent = promptComponent;
|
|
395
|
-
this.llmComponent = llmComponent;
|
|
396
|
-
this.summaryAgent = new SummaryAgent(promptComponent, llmComponent);
|
|
397
|
-
}
|
|
398
|
-
ensureSummaryAgent() {
|
|
399
|
-
if (!this.summaryAgent) {
|
|
400
|
-
if (!this.promptComponent || !this.llmComponent) {
|
|
401
|
-
throw new Error("SummaryAgent components not initialized. Call setSummaryComponents() first.");
|
|
402
|
-
}
|
|
403
|
-
this.summaryAgent = new SummaryAgent(this.promptComponent, this.llmComponent);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
async generateCompactHint(sessionId) {
|
|
407
|
-
const session = await this.get(sessionId);
|
|
408
|
-
if (!session) {
|
|
409
|
-
throw new Error(`Session not found: ${sessionId}`);
|
|
410
|
-
}
|
|
411
|
-
const latestCheckpoint = this.getLatestCheckpoint(session);
|
|
412
|
-
const startIndex = latestCheckpoint?.messageIndex ?? 0;
|
|
413
|
-
const MAX_SAFE_MESSAGES = Number.MAX_SAFE_INTEGER;
|
|
414
|
-
const messages = await this.store.getMessages(sessionId, startIndex, MAX_SAFE_MESSAGES, { includeArchived: false });
|
|
415
|
-
if (messages.length < 3) {
|
|
416
|
-
logger.warn("[SessionComponent] Not enough messages for hint generation");
|
|
417
|
-
return "";
|
|
418
|
-
}
|
|
419
|
-
this.ensureSummaryAgent();
|
|
420
|
-
const result = await this.summaryAgent.generateCompactHint({
|
|
421
|
-
messages: messages.map((m) => ({ role: m.role, content: m.content })),
|
|
422
|
-
sessionContext: {}
|
|
423
|
-
});
|
|
424
|
-
logger.info("[SessionComponent] Compact hint generated", {
|
|
425
|
-
sessionId,
|
|
426
|
-
hintLength: result.hint.length
|
|
427
|
-
});
|
|
428
|
-
return result.hint;
|
|
429
|
-
}
|
|
430
|
-
async compact(sessionId, options) {
|
|
431
|
-
const session = await this.get(sessionId);
|
|
432
|
-
if (!session) {
|
|
433
|
-
throw new Error(`Session not found: ${sessionId}`);
|
|
434
|
-
}
|
|
435
|
-
const latestCheckpoint = this.getLatestCheckpoint(session);
|
|
436
|
-
const startIndex = latestCheckpoint?.messageIndex ?? 0;
|
|
437
|
-
const MAX_SAFE_MESSAGES = Number.MAX_SAFE_INTEGER;
|
|
438
|
-
const messages = await this.store.getMessages(sessionId, startIndex, MAX_SAFE_MESSAGES, { includeArchived: false });
|
|
439
|
-
if (messages.length < 3) {
|
|
440
|
-
throw new Error("Not enough messages to compact (minimum 3 required)");
|
|
441
|
-
}
|
|
442
|
-
const recentMessages = this.extractRecentMessages(messages, 2);
|
|
443
|
-
this.ensureSummaryAgent();
|
|
444
|
-
await this.executeBeforeHooks("compact", { session, options });
|
|
445
|
-
const summaryResult = await this.summaryAgent.run({
|
|
446
|
-
messages: messages.map((m) => ({ role: m.role, content: m.content })),
|
|
447
|
-
userContext: options?.summary,
|
|
448
|
-
outputFormat: "json",
|
|
449
|
-
scenarioHint: options?.scenarioHint
|
|
450
|
-
});
|
|
451
|
-
const checkpointId = `cp_${Date.now().toString(36)}_${Math.random().toString(36).substring(2, 8)}`;
|
|
452
|
-
const checkpoint = {
|
|
453
|
-
id: checkpointId,
|
|
454
|
-
messageIndex: startIndex,
|
|
455
|
-
title: summaryResult.title,
|
|
456
|
-
summary: [
|
|
457
|
-
`Process: ${summaryResult.processKeyPoints.join("; ")}`,
|
|
458
|
-
`State: ${summaryResult.currentState}`
|
|
459
|
-
].join(`
|
|
460
|
-
`),
|
|
461
|
-
processKeyPoints: summaryResult.processKeyPoints,
|
|
462
|
-
currentState: summaryResult.currentState,
|
|
463
|
-
nextSteps: summaryResult.nextSteps,
|
|
464
|
-
userIntents: summaryResult.userIntents,
|
|
465
|
-
messageCountBefore: messages.length,
|
|
466
|
-
createdAt: Date.now(),
|
|
467
|
-
type: "compact",
|
|
468
|
-
recentMessages
|
|
469
|
-
};
|
|
470
|
-
await this.store.saveCheckpoint(sessionId, checkpoint);
|
|
471
|
-
await this.store.archiveMessages(sessionId, checkpointId, messages.length);
|
|
472
|
-
const checkpointMessage = this.createCheckpointMessage(checkpoint);
|
|
473
|
-
await this.store.addMessage(sessionId, checkpointMessage);
|
|
474
|
-
const updatedSession = await this.get(sessionId);
|
|
475
|
-
const remainingMessageCount = updatedSession?.messageCount ?? 0;
|
|
476
|
-
const checkpointCount = updatedSession?.metadata?.checkpoints?.checkpoints?.length ?? 0;
|
|
477
|
-
logger.info(`[SessionComponent] Compacted session: ${sessionId}`, {
|
|
478
|
-
checkpointId,
|
|
479
|
-
archivedCount: messages.length,
|
|
480
|
-
remainingCount: remainingMessageCount,
|
|
481
|
-
hasScenarioHint: !!options?.scenarioHint,
|
|
482
|
-
recentMessagesCount: recentMessages.length
|
|
483
|
-
});
|
|
484
|
-
await this.executeAfterHooks("compact", { session, checkpoint, options });
|
|
485
|
-
return {
|
|
486
|
-
checkpoint,
|
|
487
|
-
deletedMessageCount: messages.length,
|
|
488
|
-
remainingMessageCount,
|
|
489
|
-
checkpointCount
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
extractRecentMessages(messages, turnCount = 2) {
|
|
493
|
-
const recentMessages = [];
|
|
494
|
-
let turnsExtracted = 0;
|
|
495
|
-
let i = messages.length - 1;
|
|
496
|
-
while (i >= 0 && turnsExtracted < turnCount) {
|
|
497
|
-
const msg = messages[i];
|
|
498
|
-
if (msg.metadata?.isCheckpoint) {
|
|
499
|
-
i--;
|
|
500
|
-
continue;
|
|
501
|
-
}
|
|
502
|
-
const hasToolParts = msg.parts?.some((p) => p.type === "tool-call" || p.type === "tool-result");
|
|
503
|
-
if (msg.role === "assistant" && !hasToolParts && msg.content.trim()) {
|
|
504
|
-
recentMessages.unshift({
|
|
505
|
-
role: "assistant",
|
|
506
|
-
content: msg.content
|
|
507
|
-
});
|
|
508
|
-
let j = i - 1;
|
|
509
|
-
while (j >= 0) {
|
|
510
|
-
const prevMsg = messages[j];
|
|
511
|
-
if (prevMsg.metadata?.isCheckpoint) {
|
|
512
|
-
j--;
|
|
513
|
-
continue;
|
|
514
|
-
}
|
|
515
|
-
if (prevMsg.role === "user") {
|
|
516
|
-
recentMessages.unshift({
|
|
517
|
-
role: "user",
|
|
518
|
-
content: prevMsg.content
|
|
519
|
-
});
|
|
520
|
-
turnsExtracted++;
|
|
521
|
-
break;
|
|
522
|
-
}
|
|
523
|
-
j--;
|
|
524
|
-
}
|
|
525
|
-
i = j;
|
|
526
|
-
} else {
|
|
527
|
-
i--;
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
logger.debug("[SessionComponent] Extracted recent messages", {
|
|
531
|
-
turnCount,
|
|
532
|
-
messagesExtracted: recentMessages.length
|
|
533
|
-
});
|
|
534
|
-
return recentMessages;
|
|
535
|
-
}
|
|
536
|
-
async previewCompact(sessionId) {
|
|
537
|
-
const session = await this.get(sessionId);
|
|
538
|
-
if (!session) {
|
|
539
|
-
throw new Error(`Session not found: ${sessionId}`);
|
|
540
|
-
}
|
|
541
|
-
const latestCheckpoint = this.getLatestCheckpoint(session);
|
|
542
|
-
const startIndex = latestCheckpoint?.messageIndex ?? 0;
|
|
543
|
-
const MAX_SAFE_MESSAGES = Number.MAX_SAFE_INTEGER;
|
|
544
|
-
const messages = await this.store.getMessages(sessionId, startIndex, MAX_SAFE_MESSAGES, { includeArchived: false });
|
|
545
|
-
const estimatedTokens = messages.reduce((sum, m) => sum + m.content.length * 0.25, 0);
|
|
546
|
-
return {
|
|
547
|
-
messageCountToCompact: messages.length,
|
|
548
|
-
estimatedCheckpointTokens: Math.round(estimatedTokens * 0.1),
|
|
549
|
-
wouldTrigger: messages.length >= (this.config?.maxMessages ?? 50)
|
|
550
|
-
};
|
|
551
|
-
}
|
|
552
|
-
async getCheckpoints(sessionId) {
|
|
553
|
-
return await this.store.getCheckpoints(sessionId);
|
|
554
|
-
}
|
|
555
|
-
async getCheckpoint(sessionId, checkpointId) {
|
|
556
|
-
return await this.store.getCheckpoint(sessionId, checkpointId);
|
|
557
|
-
}
|
|
558
|
-
async deleteCheckpoint(sessionId, checkpointId) {
|
|
559
|
-
await this.executeBeforeHooks("deleteCheckpoint", { sessionId, checkpointId });
|
|
560
|
-
const success = await this.store.deleteCheckpoint(sessionId, checkpointId);
|
|
561
|
-
if (success) {
|
|
562
|
-
logger.info(`[SessionComponent] Deleted checkpoint: ${checkpointId}`);
|
|
563
|
-
await this.executeAfterHooks("deleteCheckpoint", { sessionId, checkpointId });
|
|
564
|
-
}
|
|
565
|
-
return success;
|
|
566
|
-
}
|
|
567
|
-
async getContext(sessionId, options) {
|
|
568
|
-
const session = await this.get(sessionId);
|
|
569
|
-
if (!session) {
|
|
570
|
-
throw new Error(`Session not found`);
|
|
571
|
-
}
|
|
572
|
-
let contextMessages = [];
|
|
573
|
-
let startCheckpoint;
|
|
574
|
-
if (options?.fullHistory) {
|
|
575
|
-
const MAX_SAFE_MESSAGES = Number.MAX_SAFE_INTEGER;
|
|
576
|
-
contextMessages = await this.store.getMessages(sessionId, 0, MAX_SAFE_MESSAGES, {
|
|
577
|
-
includeArchived: true
|
|
578
|
-
});
|
|
579
|
-
} else {
|
|
580
|
-
const latestCheckpointId = session.metadata?.checkpoints?.latestCheckpointId;
|
|
581
|
-
if (latestCheckpointId) {
|
|
582
|
-
startCheckpoint = await this.store.getCheckpoint(sessionId, latestCheckpointId);
|
|
583
|
-
if (startCheckpoint) {
|
|
584
|
-
const MAX_SAFE_MESSAGES = Number.MAX_SAFE_INTEGER;
|
|
585
|
-
contextMessages = await this.store.getMessages(sessionId, startCheckpoint.messageIndex, MAX_SAFE_MESSAGES, { includeArchived: false });
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
if (contextMessages.length === 0) {
|
|
589
|
-
const MAX_SAFE_MESSAGES = Number.MAX_SAFE_INTEGER;
|
|
590
|
-
contextMessages = await this.store.getMessages(sessionId, 0, MAX_SAFE_MESSAGES, {
|
|
591
|
-
includeArchived: false
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
if (options?.minUserMessages && options.minUserMessages > 0) {
|
|
596
|
-
const userIndexes = [];
|
|
597
|
-
for (let i = 0;i < contextMessages.length; i++) {
|
|
598
|
-
if (contextMessages[i].role === "user") {
|
|
599
|
-
userIndexes.push(i);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
if (userIndexes.length > options.minUserMessages) {
|
|
603
|
-
const targetIndex = userIndexes[userIndexes.length - options.minUserMessages];
|
|
604
|
-
contextMessages = contextMessages.slice(targetIndex);
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
if (options?.messageLimit) {
|
|
608
|
-
contextMessages = contextMessages.slice(-options.messageLimit);
|
|
609
|
-
}
|
|
610
|
-
const checkpoints = contextMessages.filter((m) => m.metadata?.isCheckpoint).map((m) => m.metadata.checkpointMeta);
|
|
611
|
-
const estimatedTokens = contextMessages.reduce((sum, m) => sum + m.content.length * 0.25, 0);
|
|
612
|
-
return {
|
|
613
|
-
session,
|
|
614
|
-
checkpoints,
|
|
615
|
-
startCheckpoint: startCheckpoint ?? checkpoints[checkpoints.length - 1],
|
|
616
|
-
messages: contextMessages,
|
|
617
|
-
totalMessageCount: contextMessages.length,
|
|
618
|
-
activeMessageCount: contextMessages.filter((m) => !m.isArchived).length,
|
|
619
|
-
archivedMessageCount: contextMessages.filter((m) => m.isArchived).length,
|
|
620
|
-
estimatedTokens: Math.round(estimatedTokens)
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
async shouldCompact(sessionId) {
|
|
624
|
-
const session = await this.get(sessionId);
|
|
625
|
-
if (!session)
|
|
626
|
-
return false;
|
|
627
|
-
const preview = await this.previewCompact(sessionId);
|
|
628
|
-
return preview.wouldTrigger;
|
|
629
|
-
}
|
|
630
|
-
async searchMessages(options) {
|
|
631
|
-
const {
|
|
632
|
-
query,
|
|
633
|
-
sessionId,
|
|
634
|
-
limit = 10,
|
|
635
|
-
maxResults = 100,
|
|
636
|
-
beforeTime,
|
|
637
|
-
afterTime,
|
|
638
|
-
includeArchived = false,
|
|
639
|
-
includeContext = false,
|
|
640
|
-
contextLines = 2
|
|
641
|
-
} = options;
|
|
642
|
-
if (!this.store) {
|
|
643
|
-
return [];
|
|
644
|
-
}
|
|
645
|
-
let sessions;
|
|
646
|
-
if (sessionId) {
|
|
647
|
-
const session = await this.get(sessionId);
|
|
648
|
-
sessions = session ? [session] : [];
|
|
649
|
-
} else {
|
|
650
|
-
sessions = await this.list({ limit: 1000 });
|
|
651
|
-
}
|
|
652
|
-
const results = [];
|
|
653
|
-
let totalMatches = 0;
|
|
654
|
-
for (const session of sessions) {
|
|
655
|
-
if (beforeTime && session.updatedAt > beforeTime)
|
|
656
|
-
continue;
|
|
657
|
-
if (afterTime && session.updatedAt < afterTime)
|
|
658
|
-
continue;
|
|
659
|
-
const messages = await this.store.getMessages(session.id, 0, 1000, { includeArchived });
|
|
660
|
-
const queryTerms = parseSearchQuery(query);
|
|
661
|
-
const matches = [];
|
|
662
|
-
for (const msg of messages) {
|
|
663
|
-
if (beforeTime && msg.timestamp > beforeTime)
|
|
664
|
-
continue;
|
|
665
|
-
if (afterTime && msg.timestamp < afterTime)
|
|
666
|
-
continue;
|
|
667
|
-
if (matchesQuery(msg.content, queryTerms)) {
|
|
668
|
-
const match = {
|
|
669
|
-
messageId: msg.id,
|
|
670
|
-
sessionId: session.id,
|
|
671
|
-
role: msg.role,
|
|
672
|
-
content: msg.content,
|
|
673
|
-
timestamp: msg.timestamp
|
|
674
|
-
};
|
|
675
|
-
if (includeContext) {
|
|
676
|
-
const msgIndex = messages.indexOf(msg);
|
|
677
|
-
const beforeMsgs = messages.slice(Math.max(0, msgIndex - contextLines), msgIndex);
|
|
678
|
-
const afterMsgs = messages.slice(msgIndex + 1, msgIndex + 1 + contextLines);
|
|
679
|
-
match.contextBefore = beforeMsgs.map((m) => m.content).join(`
|
|
680
|
-
`);
|
|
681
|
-
match.contextAfter = afterMsgs.map((m) => m.content).join(`
|
|
682
|
-
`);
|
|
683
|
-
}
|
|
684
|
-
matches.push(match);
|
|
685
|
-
if (matches.length >= limit)
|
|
686
|
-
break;
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
if (matches.length > 0) {
|
|
690
|
-
results.push({
|
|
691
|
-
sessionId: session.id,
|
|
692
|
-
sessionTitle: session.title,
|
|
693
|
-
sessionDirectory: session.directory,
|
|
694
|
-
updatedAt: session.updatedAt,
|
|
695
|
-
messageCount: session.messageCount,
|
|
696
|
-
matches
|
|
697
|
-
});
|
|
698
|
-
totalMatches += matches.length;
|
|
699
|
-
if (totalMatches >= maxResults)
|
|
700
|
-
break;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
return results;
|
|
704
|
-
}
|
|
705
|
-
getLatestCheckpoint(session) {
|
|
706
|
-
const latestId = session.metadata?.checkpoints?.latestCheckpointId;
|
|
707
|
-
if (!latestId)
|
|
708
|
-
return;
|
|
709
|
-
return session.metadata?.checkpointDetails?.[latestId];
|
|
710
|
-
}
|
|
711
|
-
createCheckpointMessage(checkpoint) {
|
|
712
|
-
const lines = [
|
|
713
|
-
`# Checkpoint: ${checkpoint.title}`,
|
|
714
|
-
"",
|
|
715
|
-
"## Process Key Points",
|
|
716
|
-
...checkpoint.processKeyPoints.map((p, i) => `${i + 1}. ${p}`),
|
|
717
|
-
"",
|
|
718
|
-
"## Current State",
|
|
719
|
-
checkpoint.currentState,
|
|
720
|
-
""
|
|
721
|
-
];
|
|
722
|
-
if (checkpoint.nextSteps?.length) {
|
|
723
|
-
lines.push("## Next Steps");
|
|
724
|
-
checkpoint.nextSteps.forEach((s, i) => lines.push(`${i + 1}. ${s}`));
|
|
725
|
-
lines.push("");
|
|
726
|
-
}
|
|
727
|
-
lines.push("## Messages Compacted");
|
|
728
|
-
lines.push(`${checkpoint.messageCountBefore} messages compacted at ${new Date(checkpoint.createdAt).toISOString()}`);
|
|
729
|
-
const content = lines.join(`
|
|
730
|
-
`);
|
|
731
|
-
return {
|
|
732
|
-
role: "user",
|
|
733
|
-
content,
|
|
734
|
-
parts: [{
|
|
735
|
-
type: "checkpoint",
|
|
736
|
-
checkpointId: checkpoint.id,
|
|
737
|
-
content,
|
|
738
|
-
title: checkpoint.title,
|
|
739
|
-
processKeyPoints: checkpoint.processKeyPoints,
|
|
740
|
-
currentState: checkpoint.currentState,
|
|
741
|
-
nextSteps: checkpoint.nextSteps,
|
|
742
|
-
messageCountBefore: checkpoint.messageCountBefore,
|
|
743
|
-
createdAt: checkpoint.createdAt
|
|
744
|
-
}],
|
|
745
|
-
metadata: {
|
|
746
|
-
isCheckpoint: true,
|
|
747
|
-
checkpointId: checkpoint.id,
|
|
748
|
-
checkpointMeta: checkpoint
|
|
749
|
-
}
|
|
750
|
-
};
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
__legacyDecorateClassTS([
|
|
754
|
-
TracedAs("session.generateCompactHint")
|
|
755
|
-
], SessionComponent.prototype, "generateCompactHint", null);
|
|
756
|
-
__legacyDecorateClassTS([
|
|
757
|
-
TracedAs("session.compact", { recordParams: true, recordResult: true })
|
|
758
|
-
], SessionComponent.prototype, "compact", null);
|
|
759
|
-
__legacyDecorateClassTS([
|
|
760
|
-
TracedAs("session.extractRecentMessages")
|
|
761
|
-
], SessionComponent.prototype, "extractRecentMessages", null);
|
|
762
|
-
export { SessionComponent };
|