@simulacra-ai/session 0.0.2 → 0.0.4
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/README.md +31 -34
- package/dist/index.cjs +614 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +364 -0
- package/dist/index.d.ts +364 -5
- package/dist/index.js +574 -3
- package/dist/index.js.map +1 -1
- package/package.json +11 -5
- package/dist/file-session-store.d.ts +0 -60
- package/dist/file-session-store.d.ts.map +0 -1
- package/dist/file-session-store.js +0 -166
- package/dist/file-session-store.js.map +0 -1
- package/dist/in-memory-session-store.d.ts +0 -62
- package/dist/in-memory-session-store.d.ts.map +0 -1
- package/dist/in-memory-session-store.js +0 -73
- package/dist/in-memory-session-store.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/session-manager.d.ts +0 -131
- package/dist/session-manager.d.ts.map +0 -1
- package/dist/session-manager.js +0 -366
- package/dist/session-manager.js.map +0 -1
- package/dist/types.d.ts +0 -114
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,575 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// src/session-manager.ts
|
|
2
|
+
import { randomUUID } from "crypto";
|
|
3
|
+
import EventEmitter from "events";
|
|
4
|
+
var SessionManager = class _SessionManager {
|
|
5
|
+
#store;
|
|
6
|
+
#conversation;
|
|
7
|
+
#auto_save;
|
|
8
|
+
#auto_slug;
|
|
9
|
+
#event_emitter = new EventEmitter();
|
|
10
|
+
#child_sessions = [];
|
|
11
|
+
#session_id;
|
|
12
|
+
#fork_offset = 0;
|
|
13
|
+
#has_label = false;
|
|
14
|
+
#disposed = false;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new SessionManager instance.
|
|
17
|
+
*
|
|
18
|
+
* @param store - The storage backend to use for persisting sessions.
|
|
19
|
+
* @param conversation - The conversation instance to manage.
|
|
20
|
+
* @param options - Optional configuration for session management behavior.
|
|
21
|
+
*/
|
|
22
|
+
constructor(store, conversation, options) {
|
|
23
|
+
this.#store = store;
|
|
24
|
+
this.#conversation = conversation;
|
|
25
|
+
this.#auto_save = options?.auto_save ?? true;
|
|
26
|
+
this.#auto_slug = options?.auto_slug ?? true;
|
|
27
|
+
if (this.#auto_save) {
|
|
28
|
+
this.#conversation.on("message_complete", this.#on_message_complete);
|
|
29
|
+
}
|
|
30
|
+
this.#conversation.on("create_child", this.#on_create_child);
|
|
31
|
+
this.#conversation.once("dispose", this.#on_conversation_dispose);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The ID of the currently active session.
|
|
35
|
+
*
|
|
36
|
+
* @returns The session ID if a session is active, otherwise undefined.
|
|
37
|
+
*/
|
|
38
|
+
get current_session_id() {
|
|
39
|
+
return this.#session_id;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Whether a session is currently loaded.
|
|
43
|
+
*
|
|
44
|
+
* @returns True if a session is active, false otherwise.
|
|
45
|
+
*/
|
|
46
|
+
get is_loaded() {
|
|
47
|
+
return !!this.#session_id;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Disposes of the SessionManager and cleans up resources.
|
|
51
|
+
*
|
|
52
|
+
* This method removes event listeners, disposes child sessions, and emits the dispose event.
|
|
53
|
+
* It is called automatically when the associated conversation is disposed or when using
|
|
54
|
+
* explicit resource management.
|
|
55
|
+
*/
|
|
56
|
+
[Symbol.dispose]() {
|
|
57
|
+
if (this.#disposed) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
this.#disposed = true;
|
|
61
|
+
for (const child of this.#child_sessions) {
|
|
62
|
+
child[Symbol.dispose]();
|
|
63
|
+
}
|
|
64
|
+
this.#child_sessions.length = 0;
|
|
65
|
+
this.#conversation.off("message_complete", this.#on_message_complete);
|
|
66
|
+
this.#conversation.off("create_child", this.#on_create_child);
|
|
67
|
+
this.#conversation.off("dispose", this.#on_conversation_dispose);
|
|
68
|
+
this.#event_emitter.emit("dispose");
|
|
69
|
+
this.#event_emitter.removeAllListeners();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Starts a new session with a freshly generated ID.
|
|
73
|
+
*
|
|
74
|
+
* This method clears the conversation history and creates a new session. If auto_save
|
|
75
|
+
* is enabled or a label is provided, the session is immediately saved to the store.
|
|
76
|
+
*
|
|
77
|
+
* @param label - Optional label to assign to the new session.
|
|
78
|
+
* @returns The generated session ID.
|
|
79
|
+
*/
|
|
80
|
+
start_new(label) {
|
|
81
|
+
this.#session_id = randomUUID();
|
|
82
|
+
this.#fork_offset = 0;
|
|
83
|
+
this.#has_label = !!label;
|
|
84
|
+
if (this.#conversation.messages.length > 0) {
|
|
85
|
+
this.#conversation.clear();
|
|
86
|
+
}
|
|
87
|
+
if (label || this.#auto_save) {
|
|
88
|
+
this.save({ label }).catch((error) => {
|
|
89
|
+
this.#event_emitter.emit("lifecycle_error", {
|
|
90
|
+
error,
|
|
91
|
+
operation: "save",
|
|
92
|
+
context: { session_id: this.#session_id }
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return this.#session_id;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new session as a fork of an existing parent session.
|
|
100
|
+
*
|
|
101
|
+
* A fork creates a new session that inherits messages from the parent session up to
|
|
102
|
+
* the fork point. If detached, the fork does not inherit any messages from the parent
|
|
103
|
+
* but still maintains a parent reference for organizational purposes.
|
|
104
|
+
*
|
|
105
|
+
* @param parent_session_id - The ID of the session to fork from.
|
|
106
|
+
* @param options - Optional configuration for the fork operation.
|
|
107
|
+
* @param options.detached - Whether to create a detached fork that does not inherit parent messages.
|
|
108
|
+
* @returns A promise that resolves to the generated session ID for the fork.
|
|
109
|
+
*/
|
|
110
|
+
async fork(parent_session_id, options) {
|
|
111
|
+
const detached = options?.detached ?? false;
|
|
112
|
+
this.#session_id = randomUUID();
|
|
113
|
+
this.#has_label = false;
|
|
114
|
+
if (!detached) {
|
|
115
|
+
this.#conversation.clear();
|
|
116
|
+
}
|
|
117
|
+
let fork_message_id;
|
|
118
|
+
if (!detached) {
|
|
119
|
+
const messages = await this.#resolve_messages(parent_session_id);
|
|
120
|
+
if (messages.length > 0) {
|
|
121
|
+
this.#conversation.load(messages);
|
|
122
|
+
this.#fork_offset = messages.length;
|
|
123
|
+
fork_message_id = messages.at(-1)?.id;
|
|
124
|
+
} else {
|
|
125
|
+
this.#fork_offset = 0;
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
this.#fork_offset = 0;
|
|
129
|
+
}
|
|
130
|
+
const parent_result = await this.#store.load(parent_session_id);
|
|
131
|
+
if (parent_result?.metadata.checkpoint_state) {
|
|
132
|
+
this.#conversation.checkpoint_state = parent_result.metadata.checkpoint_state;
|
|
133
|
+
}
|
|
134
|
+
await this.save({
|
|
135
|
+
parent_id: parent_session_id,
|
|
136
|
+
fork_message_id,
|
|
137
|
+
detached
|
|
138
|
+
});
|
|
139
|
+
return this.#session_id;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Loads a session by ID or loads the most recent session if no ID is provided.
|
|
143
|
+
*
|
|
144
|
+
* If no session ID is provided and no sessions exist in the store, this method
|
|
145
|
+
* starts a new session automatically. Loading a session resolves its full message
|
|
146
|
+
* history by recursively following parent references.
|
|
147
|
+
*
|
|
148
|
+
* @param id - The ID of the session to load, or undefined to load the most recent session.
|
|
149
|
+
* @returns A promise that resolves when the session is loaded.
|
|
150
|
+
* @throws {Error} If the specified session ID is not found in the store.
|
|
151
|
+
*/
|
|
152
|
+
async load(id) {
|
|
153
|
+
if (id) {
|
|
154
|
+
const messages = await this.#resolve_messages(id);
|
|
155
|
+
const result = await this.#store.load(id);
|
|
156
|
+
if (!result) {
|
|
157
|
+
throw new Error(`session not found: ${id}`);
|
|
158
|
+
}
|
|
159
|
+
this.#session_id = id;
|
|
160
|
+
this.#has_label = !!result.metadata.label;
|
|
161
|
+
this.#conversation.clear();
|
|
162
|
+
this.#fork_offset = messages.length - result.messages.length;
|
|
163
|
+
this.#conversation.load(messages);
|
|
164
|
+
this.#conversation.checkpoint_state = result.metadata.checkpoint_state;
|
|
165
|
+
this.#emit_load(messages);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const sessions = await this.#store.list();
|
|
169
|
+
if (!sessions.length) {
|
|
170
|
+
this.start_new();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const latest = sessions[0];
|
|
174
|
+
return this.load(latest.id);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Saves the current session to the store.
|
|
178
|
+
*
|
|
179
|
+
* This method persists only the messages owned by this session, excluding any messages
|
|
180
|
+
* inherited from parent sessions. If auto_slug is enabled and no label has been set,
|
|
181
|
+
* a label is automatically generated from the first user message.
|
|
182
|
+
*
|
|
183
|
+
* @param metadata - Optional partial metadata to update on the session.
|
|
184
|
+
* @returns A promise that resolves when the save operation is complete.
|
|
185
|
+
* @throws {Error} If no session is currently active.
|
|
186
|
+
*/
|
|
187
|
+
async save(metadata) {
|
|
188
|
+
if (!this.#session_id) {
|
|
189
|
+
throw new Error("no active session");
|
|
190
|
+
}
|
|
191
|
+
const all_messages = this.#conversation.messages;
|
|
192
|
+
const owned_messages = [...all_messages].slice(this.#fork_offset);
|
|
193
|
+
if (this.#auto_slug && !metadata?.label && !this.#has_label) {
|
|
194
|
+
const slug = _SessionManager.#derive_slug(all_messages);
|
|
195
|
+
if (slug) {
|
|
196
|
+
metadata = { ...metadata, label: slug };
|
|
197
|
+
this.#has_label = true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const conversation_metadata = { ...metadata };
|
|
201
|
+
if (this.#conversation.is_checkpoint) {
|
|
202
|
+
conversation_metadata.is_checkpoint = true;
|
|
203
|
+
}
|
|
204
|
+
const checkpoint_state = this.#conversation.checkpoint_state;
|
|
205
|
+
if (checkpoint_state) {
|
|
206
|
+
conversation_metadata.checkpoint_state = { ...checkpoint_state };
|
|
207
|
+
}
|
|
208
|
+
await this.#store.save(this.#session_id, owned_messages, conversation_metadata);
|
|
209
|
+
this.#event_emitter.emit("save", {
|
|
210
|
+
id: this.#session_id,
|
|
211
|
+
messages: Object.freeze([...all_messages])
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Lists all sessions stored in the store.
|
|
216
|
+
*
|
|
217
|
+
* @returns A promise that resolves to an array of session metadata, typically sorted by last update time.
|
|
218
|
+
*/
|
|
219
|
+
async list() {
|
|
220
|
+
return this.#store.list();
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Deletes a session from the store.
|
|
224
|
+
*
|
|
225
|
+
* If the deleted session is currently active, the conversation is cleared and the
|
|
226
|
+
* current session is unset.
|
|
227
|
+
*
|
|
228
|
+
* @param id - The ID of the session to delete.
|
|
229
|
+
* @returns A promise that resolves to true if the session was deleted, false if it was not found.
|
|
230
|
+
*/
|
|
231
|
+
async delete(id) {
|
|
232
|
+
if (id === this.#session_id) {
|
|
233
|
+
this.#session_id = void 0;
|
|
234
|
+
this.#conversation.clear();
|
|
235
|
+
}
|
|
236
|
+
return this.#store.delete(id);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Renames a session by updating its label.
|
|
240
|
+
*
|
|
241
|
+
* @param id - The ID of the session to rename.
|
|
242
|
+
* @param label - The new label to assign to the session.
|
|
243
|
+
* @returns A promise that resolves when the rename operation is complete.
|
|
244
|
+
* @throws {Error} If the specified session ID is not found in the store.
|
|
245
|
+
*/
|
|
246
|
+
async rename(id, label) {
|
|
247
|
+
const result = await this.#store.load(id);
|
|
248
|
+
if (!result) {
|
|
249
|
+
throw new Error(`session not found: ${id}`);
|
|
250
|
+
}
|
|
251
|
+
await this.#store.save(id, result.messages, { label });
|
|
252
|
+
if (id === this.#session_id) {
|
|
253
|
+
this.#has_label = true;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Registers an event listener for the specified event.
|
|
258
|
+
*
|
|
259
|
+
* @param event - The name of the event to listen for.
|
|
260
|
+
* @param listener - The callback function to invoke when the event is emitted.
|
|
261
|
+
* @returns This SessionManager instance for method chaining.
|
|
262
|
+
*/
|
|
263
|
+
on(event, listener) {
|
|
264
|
+
this.#event_emitter.on(event, listener);
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Removes an event listener for the specified event.
|
|
269
|
+
*
|
|
270
|
+
* @param event - The name of the event to stop listening for.
|
|
271
|
+
* @param listener - The callback function to remove.
|
|
272
|
+
* @returns This SessionManager instance for method chaining.
|
|
273
|
+
*/
|
|
274
|
+
off(event, listener) {
|
|
275
|
+
this.#event_emitter.off(event, listener);
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
#emit_load(messages) {
|
|
279
|
+
this.#event_emitter.emit("load", {
|
|
280
|
+
id: this.#session_id,
|
|
281
|
+
messages: Object.freeze([...messages])
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
async #resolve_messages(id) {
|
|
285
|
+
const result = await this.#store.load(id);
|
|
286
|
+
if (!result) {
|
|
287
|
+
return [];
|
|
288
|
+
}
|
|
289
|
+
const { metadata, messages } = result;
|
|
290
|
+
if (metadata.parent_id && !metadata.detached) {
|
|
291
|
+
const parent_messages = await this.#resolve_messages(metadata.parent_id);
|
|
292
|
+
if (metadata.fork_message_id) {
|
|
293
|
+
const cut = parent_messages.findIndex((m) => m.id === metadata.fork_message_id);
|
|
294
|
+
if (cut >= 0) {
|
|
295
|
+
return [...parent_messages.slice(0, cut + 1), ...messages];
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return [...parent_messages, ...messages];
|
|
299
|
+
}
|
|
300
|
+
return messages;
|
|
301
|
+
}
|
|
302
|
+
static #derive_slug(messages) {
|
|
303
|
+
const first_user = messages.find((m) => m.role === "user");
|
|
304
|
+
if (!first_user) {
|
|
305
|
+
return void 0;
|
|
306
|
+
}
|
|
307
|
+
const text_content = first_user.content.find((c) => c.type === "text");
|
|
308
|
+
if (!text_content || text_content.type !== "text" || !text_content.text) {
|
|
309
|
+
return void 0;
|
|
310
|
+
}
|
|
311
|
+
const raw = text_content.text.trim();
|
|
312
|
+
if (!raw) {
|
|
313
|
+
return void 0;
|
|
314
|
+
}
|
|
315
|
+
const truncated = raw.slice(0, 60);
|
|
316
|
+
const at_boundary = truncated.replace(/\s+\S*$/, "");
|
|
317
|
+
return (at_boundary || truncated).slice(0, 50);
|
|
318
|
+
}
|
|
319
|
+
#on_create_child = (child) => {
|
|
320
|
+
if (!this.#session_id) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const child_session = new _SessionManager(this.#store, child, {
|
|
324
|
+
auto_save: this.#auto_save,
|
|
325
|
+
auto_slug: !child.is_checkpoint && this.#auto_slug
|
|
326
|
+
});
|
|
327
|
+
child_session.fork(this.#session_id, { detached: true }).catch((error) => {
|
|
328
|
+
this.#event_emitter.emit("lifecycle_error", { error, operation: "fork" });
|
|
329
|
+
});
|
|
330
|
+
this.#child_sessions.push(child_session);
|
|
331
|
+
child.once("dispose", () => {
|
|
332
|
+
child_session[Symbol.dispose]();
|
|
333
|
+
const idx = this.#child_sessions.indexOf(child_session);
|
|
334
|
+
if (idx >= 0) {
|
|
335
|
+
this.#child_sessions.splice(idx, 1);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
#on_message_complete = () => {
|
|
340
|
+
if (this.#session_id) {
|
|
341
|
+
this.save().catch((error) => {
|
|
342
|
+
this.#event_emitter.emit("lifecycle_error", {
|
|
343
|
+
error,
|
|
344
|
+
operation: "save",
|
|
345
|
+
context: { session_id: this.#session_id }
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
#on_conversation_dispose = () => this[Symbol.dispose]();
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// src/file-session-store.ts
|
|
354
|
+
import fs from "fs/promises";
|
|
355
|
+
import path from "path";
|
|
356
|
+
var FileSessionStore = class {
|
|
357
|
+
#root;
|
|
358
|
+
/**
|
|
359
|
+
* Creates a new FileSessionStore instance.
|
|
360
|
+
*
|
|
361
|
+
* @param root - The absolute path to the directory where session files will be stored.
|
|
362
|
+
*/
|
|
363
|
+
constructor(root) {
|
|
364
|
+
this.#root = root;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Lists all sessions stored in the file system.
|
|
368
|
+
*
|
|
369
|
+
* Reads all JSON files from the root directory and parses their metadata.
|
|
370
|
+
*
|
|
371
|
+
* @returns A promise that resolves to an array of session metadata, sorted by most recently updated first.
|
|
372
|
+
*/
|
|
373
|
+
async list() {
|
|
374
|
+
await this.#ensure_dir();
|
|
375
|
+
const sessions = [];
|
|
376
|
+
const entries = await fs.readdir(this.#root, { withFileTypes: true });
|
|
377
|
+
for (const entry of entries) {
|
|
378
|
+
if (!entry.isFile() || !entry.name.endsWith(".json")) {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const session = await this.#read_session(
|
|
382
|
+
path.join(this.#root, entry.name),
|
|
383
|
+
entry.name.replace(/\.json$/, "")
|
|
384
|
+
);
|
|
385
|
+
if (session) {
|
|
386
|
+
sessions.push(session);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return sessions.sort((a, b) => b.updated_at.localeCompare(a.updated_at));
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Loads a session from the file system.
|
|
393
|
+
*
|
|
394
|
+
* @param id - The unique identifier of the session to load.
|
|
395
|
+
* @returns A promise that resolves to the session metadata and messages, or undefined if not found.
|
|
396
|
+
*/
|
|
397
|
+
async load(id) {
|
|
398
|
+
return this.#read_file(path.join(this.#root, `${id}.json`), id);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Saves a session to the file system.
|
|
402
|
+
*
|
|
403
|
+
* Creates a new session file if the ID does not exist, or updates an existing file.
|
|
404
|
+
* Automatically updates the updated_at timestamp and message_count. If the session
|
|
405
|
+
* has a parent, creates a hard link in the parent's fork directory for efficient querying.
|
|
406
|
+
*
|
|
407
|
+
* @param id - The unique identifier of the session.
|
|
408
|
+
* @param messages - The messages to store for this session.
|
|
409
|
+
* @param metadata - Optional partial metadata to merge with existing metadata.
|
|
410
|
+
* @returns A promise that resolves when the save operation is complete.
|
|
411
|
+
*/
|
|
412
|
+
async save(id, messages, metadata) {
|
|
413
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
414
|
+
await this.#ensure_dir();
|
|
415
|
+
const file_path = path.join(this.#root, `${id}.json`);
|
|
416
|
+
const existing = await this.#read_file(file_path, id);
|
|
417
|
+
const existing_metadata = existing?.metadata ?? {};
|
|
418
|
+
const parent_id = metadata?.parent_id ?? existing_metadata.parent_id;
|
|
419
|
+
const file = {
|
|
420
|
+
metadata: {
|
|
421
|
+
...existing_metadata,
|
|
422
|
+
created_at: existing_metadata.created_at ?? now,
|
|
423
|
+
updated_at: now,
|
|
424
|
+
message_count: messages.length,
|
|
425
|
+
...metadata
|
|
426
|
+
},
|
|
427
|
+
messages
|
|
428
|
+
};
|
|
429
|
+
await fs.writeFile(file_path, JSON.stringify(file, null, 2), "utf8");
|
|
430
|
+
if (parent_id) {
|
|
431
|
+
await this.#ensure_fork_link(parent_id, id);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Deletes a session from the file system.
|
|
436
|
+
*
|
|
437
|
+
* Removes the session file, any hard links in parent fork directories, and the session's
|
|
438
|
+
* own fork directory if it exists.
|
|
439
|
+
*
|
|
440
|
+
* @param id - The unique identifier of the session to delete.
|
|
441
|
+
* @returns A promise that resolves to true if the session was deleted, false if it was not found.
|
|
442
|
+
*/
|
|
443
|
+
async delete(id) {
|
|
444
|
+
const file_path = path.join(this.#root, `${id}.json`);
|
|
445
|
+
try {
|
|
446
|
+
const result = await this.#read_file(file_path, id);
|
|
447
|
+
await fs.unlink(file_path);
|
|
448
|
+
if (result?.metadata.parent_id) {
|
|
449
|
+
const link = path.join(this.#root, `${result.metadata.parent_id}-forks`, `${id}.json`);
|
|
450
|
+
try {
|
|
451
|
+
await fs.unlink(link);
|
|
452
|
+
} catch {
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
const fork_dir = path.join(this.#root, `${id}-forks`);
|
|
456
|
+
try {
|
|
457
|
+
await fs.rm(fork_dir, { recursive: true });
|
|
458
|
+
} catch {
|
|
459
|
+
}
|
|
460
|
+
return true;
|
|
461
|
+
} catch {
|
|
462
|
+
return false;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
async #ensure_fork_link(parent_id, fork_id) {
|
|
466
|
+
const fork_dir = path.join(this.#root, `${parent_id}-forks`);
|
|
467
|
+
await fs.mkdir(fork_dir, { recursive: true });
|
|
468
|
+
const canonical = path.join(this.#root, `${fork_id}.json`);
|
|
469
|
+
const link = path.join(fork_dir, `${fork_id}.json`);
|
|
470
|
+
try {
|
|
471
|
+
await fs.unlink(link);
|
|
472
|
+
} catch {
|
|
473
|
+
}
|
|
474
|
+
try {
|
|
475
|
+
await fs.link(canonical, link);
|
|
476
|
+
} catch {
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
async #read_file(file_path, id) {
|
|
480
|
+
try {
|
|
481
|
+
const content = await fs.readFile(file_path, "utf8");
|
|
482
|
+
const data = JSON.parse(content);
|
|
483
|
+
return {
|
|
484
|
+
metadata: { id, ...data.metadata },
|
|
485
|
+
messages: data.messages
|
|
486
|
+
};
|
|
487
|
+
} catch {
|
|
488
|
+
return void 0;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
async #read_session(file_path, id) {
|
|
492
|
+
try {
|
|
493
|
+
const content = await fs.readFile(file_path, "utf8");
|
|
494
|
+
const data = JSON.parse(content);
|
|
495
|
+
return { id, ...data.metadata };
|
|
496
|
+
} catch {
|
|
497
|
+
return void 0;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
async #ensure_dir() {
|
|
501
|
+
await fs.mkdir(this.#root, { recursive: true });
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
// src/in-memory-session-store.ts
|
|
506
|
+
var InMemorySessionStore = class {
|
|
507
|
+
#sessions = /* @__PURE__ */ new Map();
|
|
508
|
+
/**
|
|
509
|
+
* Lists all sessions stored in memory.
|
|
510
|
+
*
|
|
511
|
+
* @returns A promise that resolves to an array of session metadata, sorted by most recently updated first.
|
|
512
|
+
*/
|
|
513
|
+
async list() {
|
|
514
|
+
return [...this.#sessions.values()].map((s) => s.metadata).sort((a, b) => b.updated_at.localeCompare(a.updated_at));
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Loads a session from memory.
|
|
518
|
+
*
|
|
519
|
+
* Returns a deep clone of the stored data to prevent external mutations.
|
|
520
|
+
*
|
|
521
|
+
* @param id - The unique identifier of the session to load.
|
|
522
|
+
* @returns A promise that resolves to the session metadata and messages, or undefined if not found.
|
|
523
|
+
*/
|
|
524
|
+
async load(id) {
|
|
525
|
+
const entry = this.#sessions.get(id);
|
|
526
|
+
if (!entry) {
|
|
527
|
+
return void 0;
|
|
528
|
+
}
|
|
529
|
+
return {
|
|
530
|
+
metadata: { ...entry.metadata },
|
|
531
|
+
messages: structuredClone(entry.messages)
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Saves a session to memory.
|
|
536
|
+
*
|
|
537
|
+
* Creates a new session if the ID does not exist, or updates an existing session.
|
|
538
|
+
* Automatically updates the updated_at timestamp and message_count.
|
|
539
|
+
*
|
|
540
|
+
* @param id - The unique identifier of the session.
|
|
541
|
+
* @param messages - The messages to store for this session.
|
|
542
|
+
* @param metadata - Optional partial metadata to merge with existing metadata.
|
|
543
|
+
* @returns A promise that resolves when the save operation is complete.
|
|
544
|
+
*/
|
|
545
|
+
async save(id, messages, metadata) {
|
|
546
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
547
|
+
const existing = this.#sessions.get(id);
|
|
548
|
+
this.#sessions.set(id, {
|
|
549
|
+
metadata: {
|
|
550
|
+
id,
|
|
551
|
+
...existing?.metadata,
|
|
552
|
+
created_at: existing?.metadata.created_at ?? now,
|
|
553
|
+
updated_at: now,
|
|
554
|
+
message_count: messages.length,
|
|
555
|
+
...metadata
|
|
556
|
+
},
|
|
557
|
+
messages: structuredClone(messages)
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Deletes a session from memory.
|
|
562
|
+
*
|
|
563
|
+
* @param id - The unique identifier of the session to delete.
|
|
564
|
+
* @returns A promise that resolves to true if the session was deleted, false if it was not found.
|
|
565
|
+
*/
|
|
566
|
+
async delete(id) {
|
|
567
|
+
return this.#sessions.delete(id);
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
export {
|
|
571
|
+
FileSessionStore,
|
|
572
|
+
InMemorySessionStore,
|
|
573
|
+
SessionManager
|
|
574
|
+
};
|
|
4
575
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/session-manager.ts","../src/file-session-store.ts","../src/in-memory-session-store.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport EventEmitter from \"node:events\";\nimport type { Conversation, Message } from \"@simulacra-ai/core\";\nimport type {\n SessionMetadata,\n SessionStore,\n SessionManagerOptions,\n SessionManagerEvents,\n} from \"./types.ts\";\n\n/**\n * Manages conversation sessions including creation, loading, saving, and forking.\n *\n * The SessionManager acts as a bridge between a Conversation instance and a SessionStore,\n * handling session lifecycle, automatic saving, and session tree management through forking.\n * It supports disposable resource management and event emission for session operations.\n */\nexport class SessionManager {\n readonly #store: SessionStore;\n readonly #conversation: Conversation;\n readonly #auto_save: boolean;\n readonly #auto_slug: boolean;\n readonly #event_emitter = new EventEmitter<SessionManagerEvents>();\n readonly #child_sessions: SessionManager[] = [];\n\n #session_id?: string;\n #fork_offset = 0;\n #has_label = false;\n #disposed = false;\n\n /**\n * Creates a new SessionManager instance.\n *\n * @param store - The storage backend to use for persisting sessions.\n * @param conversation - The conversation instance to manage.\n * @param options - Optional configuration for session management behavior.\n */\n constructor(store: SessionStore, conversation: Conversation, options?: SessionManagerOptions) {\n this.#store = store;\n this.#conversation = conversation;\n this.#auto_save = options?.auto_save ?? true;\n this.#auto_slug = options?.auto_slug ?? true;\n\n if (this.#auto_save) {\n this.#conversation.on(\"message_complete\", this.#on_message_complete);\n }\n this.#conversation.on(\"create_child\", this.#on_create_child);\n this.#conversation.once(\"dispose\", this.#on_conversation_dispose);\n }\n\n /**\n * The ID of the currently active session.\n *\n * @returns The session ID if a session is active, otherwise undefined.\n */\n get current_session_id() {\n return this.#session_id;\n }\n\n /**\n * Whether a session is currently loaded.\n *\n * @returns True if a session is active, false otherwise.\n */\n get is_loaded() {\n return !!this.#session_id;\n }\n\n /**\n * Disposes of the SessionManager and cleans up resources.\n *\n * This method removes event listeners, disposes child sessions, and emits the dispose event.\n * It is called automatically when the associated conversation is disposed or when using\n * explicit resource management.\n */\n [Symbol.dispose]() {\n if (this.#disposed) {\n return;\n }\n this.#disposed = true;\n\n for (const child of this.#child_sessions) {\n child[Symbol.dispose]();\n }\n this.#child_sessions.length = 0;\n\n this.#conversation.off(\"message_complete\", this.#on_message_complete);\n this.#conversation.off(\"create_child\", this.#on_create_child);\n this.#conversation.off(\"dispose\", this.#on_conversation_dispose);\n this.#event_emitter.emit(\"dispose\");\n this.#event_emitter.removeAllListeners();\n }\n\n /**\n * Starts a new session with a freshly generated ID.\n *\n * This method clears the conversation history and creates a new session. If auto_save\n * is enabled or a label is provided, the session is immediately saved to the store.\n *\n * @param label - Optional label to assign to the new session.\n * @returns The generated session ID.\n */\n start_new(label?: string): string {\n this.#session_id = randomUUID();\n this.#fork_offset = 0;\n this.#has_label = !!label;\n if (this.#conversation.messages.length > 0) {\n this.#conversation.clear();\n }\n if (label || this.#auto_save) {\n this.save({ label }).catch((error) => {\n this.#event_emitter.emit(\"lifecycle_error\", {\n error,\n operation: \"save\",\n context: { session_id: this.#session_id },\n });\n });\n }\n return this.#session_id;\n }\n\n /**\n * Creates a new session as a fork of an existing parent session.\n *\n * A fork creates a new session that inherits messages from the parent session up to\n * the fork point. If detached, the fork does not inherit any messages from the parent\n * but still maintains a parent reference for organizational purposes.\n *\n * @param parent_session_id - The ID of the session to fork from.\n * @param options - Optional configuration for the fork operation.\n * @param options.detached - Whether to create a detached fork that does not inherit parent messages.\n * @returns A promise that resolves to the generated session ID for the fork.\n */\n async fork(parent_session_id: string, options?: { detached?: boolean }): Promise<string> {\n const detached = options?.detached ?? false;\n this.#session_id = randomUUID();\n this.#has_label = false;\n if (!detached) {\n this.#conversation.clear();\n }\n\n let fork_message_id: string | undefined;\n\n if (!detached) {\n const messages = await this.#resolve_messages(parent_session_id);\n if (messages.length > 0) {\n this.#conversation.load(messages);\n this.#fork_offset = messages.length;\n fork_message_id = messages.at(-1)?.id;\n } else {\n this.#fork_offset = 0;\n }\n } else {\n this.#fork_offset = 0;\n }\n\n const parent_result = await this.#store.load(parent_session_id);\n if (parent_result?.metadata.checkpoint_state) {\n this.#conversation.checkpoint_state = parent_result.metadata.checkpoint_state;\n }\n\n await this.save({\n parent_id: parent_session_id,\n fork_message_id,\n detached,\n });\n\n return this.#session_id;\n }\n\n /**\n * Loads a session by ID or loads the most recent session if no ID is provided.\n *\n * If no session ID is provided and no sessions exist in the store, this method\n * starts a new session automatically. Loading a session resolves its full message\n * history by recursively following parent references.\n *\n * @param id - The ID of the session to load, or undefined to load the most recent session.\n * @returns A promise that resolves when the session is loaded.\n * @throws {Error} If the specified session ID is not found in the store.\n */\n async load(id?: string): Promise<void> {\n if (id) {\n const messages = await this.#resolve_messages(id);\n const result = await this.#store.load(id);\n if (!result) {\n throw new Error(`session not found: ${id}`);\n }\n this.#session_id = id;\n this.#has_label = !!result.metadata.label;\n this.#conversation.clear();\n this.#fork_offset = messages.length - result.messages.length;\n this.#conversation.load(messages);\n this.#conversation.checkpoint_state = result.metadata.checkpoint_state;\n this.#emit_load(messages);\n return;\n }\n\n const sessions = await this.#store.list();\n if (!sessions.length) {\n this.start_new();\n return;\n }\n\n const latest = sessions[0];\n return this.load(latest.id);\n }\n\n /**\n * Saves the current session to the store.\n *\n * This method persists only the messages owned by this session, excluding any messages\n * inherited from parent sessions. If auto_slug is enabled and no label has been set,\n * a label is automatically generated from the first user message.\n *\n * @param metadata - Optional partial metadata to update on the session.\n * @returns A promise that resolves when the save operation is complete.\n * @throws {Error} If no session is currently active.\n */\n async save(\n metadata?: Partial<\n Pick<\n SessionMetadata,\n \"label\" | \"provider\" | \"model\" | \"parent_id\" | \"fork_message_id\" | \"detached\"\n >\n >,\n ) {\n if (!this.#session_id) {\n throw new Error(\"no active session\");\n }\n const all_messages = this.#conversation.messages;\n const owned_messages = [...all_messages].slice(this.#fork_offset);\n\n if (this.#auto_slug && !metadata?.label && !this.#has_label) {\n const slug = SessionManager.#derive_slug(all_messages);\n if (slug) {\n metadata = { ...metadata, label: slug };\n this.#has_label = true;\n }\n }\n\n const conversation_metadata: Partial<SessionMetadata> = { ...metadata };\n if (this.#conversation.is_checkpoint) {\n conversation_metadata.is_checkpoint = true;\n }\n const checkpoint_state = this.#conversation.checkpoint_state;\n if (checkpoint_state) {\n conversation_metadata.checkpoint_state = { ...checkpoint_state };\n }\n\n await this.#store.save(this.#session_id, owned_messages, conversation_metadata);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this.#event_emitter as any).emit(\"save\", {\n id: this.#session_id,\n messages: Object.freeze([...all_messages]),\n });\n }\n\n /**\n * Lists all sessions stored in the store.\n *\n * @returns A promise that resolves to an array of session metadata, typically sorted by last update time.\n */\n async list() {\n return this.#store.list();\n }\n\n /**\n * Deletes a session from the store.\n *\n * If the deleted session is currently active, the conversation is cleared and the\n * current session is unset.\n *\n * @param id - The ID of the session to delete.\n * @returns A promise that resolves to true if the session was deleted, false if it was not found.\n */\n async delete(id: string) {\n if (id === this.#session_id) {\n this.#session_id = undefined;\n this.#conversation.clear();\n }\n return this.#store.delete(id);\n }\n\n /**\n * Renames a session by updating its label.\n *\n * @param id - The ID of the session to rename.\n * @param label - The new label to assign to the session.\n * @returns A promise that resolves when the rename operation is complete.\n * @throws {Error} If the specified session ID is not found in the store.\n */\n async rename(id: string, label: string) {\n const result = await this.#store.load(id);\n if (!result) {\n throw new Error(`session not found: ${id}`);\n }\n await this.#store.save(id, result.messages, { label });\n if (id === this.#session_id) {\n this.#has_label = true;\n }\n }\n\n /**\n * Registers an event listener for the specified event.\n *\n * @param event - The name of the event to listen for.\n * @param listener - The callback function to invoke when the event is emitted.\n * @returns This SessionManager instance for method chaining.\n */\n on<E extends keyof SessionManagerEvents>(\n event: E,\n listener: (...args: SessionManagerEvents[E]) => void,\n ): this {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this.#event_emitter as any).on(event, listener);\n return this;\n }\n\n /**\n * Removes an event listener for the specified event.\n *\n * @param event - The name of the event to stop listening for.\n * @param listener - The callback function to remove.\n * @returns This SessionManager instance for method chaining.\n */\n off<E extends keyof SessionManagerEvents>(\n event: E,\n listener: (...args: SessionManagerEvents[E]) => void,\n ): this {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this.#event_emitter as any).off(event, listener);\n return this;\n }\n\n #emit_load(messages: Readonly<Message[]>) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this.#event_emitter as any).emit(\"load\", {\n id: this.#session_id,\n messages: Object.freeze([...messages]),\n });\n }\n\n async #resolve_messages(id: string): Promise<Message[]> {\n const result = await this.#store.load(id);\n if (!result) {\n return [];\n }\n\n const { metadata, messages } = result;\n\n if (metadata.parent_id && !metadata.detached) {\n const parent_messages = await this.#resolve_messages(metadata.parent_id);\n if (metadata.fork_message_id) {\n const cut = parent_messages.findIndex((m) => m.id === metadata.fork_message_id);\n if (cut >= 0) {\n return [...parent_messages.slice(0, cut + 1), ...messages];\n }\n }\n return [...parent_messages, ...messages];\n }\n\n return messages;\n }\n\n static #derive_slug(messages: readonly Readonly<Message>[]): string | undefined {\n const first_user = messages.find((m) => m.role === \"user\");\n if (!first_user) {\n return undefined;\n }\n\n const text_content = first_user.content.find((c) => c.type === \"text\");\n if (!text_content || text_content.type !== \"text\" || !text_content.text) {\n return undefined;\n }\n\n const raw = text_content.text.trim();\n if (!raw) {\n return undefined;\n }\n\n const truncated = raw.slice(0, 60);\n const at_boundary = truncated.replace(/\\s+\\S*$/, \"\");\n return (at_boundary || truncated).slice(0, 50);\n }\n\n #on_create_child = (child: Conversation) => {\n if (!this.#session_id) {\n return;\n }\n\n const child_session = new SessionManager(this.#store, child, {\n auto_save: this.#auto_save,\n auto_slug: !child.is_checkpoint && this.#auto_slug,\n });\n child_session.fork(this.#session_id, { detached: true }).catch((error) => {\n this.#event_emitter.emit(\"lifecycle_error\", { error, operation: \"fork\" });\n });\n this.#child_sessions.push(child_session);\n\n child.once(\"dispose\", () => {\n child_session[Symbol.dispose]();\n const idx = this.#child_sessions.indexOf(child_session);\n if (idx >= 0) {\n this.#child_sessions.splice(idx, 1);\n }\n });\n };\n\n #on_message_complete = () => {\n if (this.#session_id) {\n this.save().catch((error) => {\n this.#event_emitter.emit(\"lifecycle_error\", {\n error,\n operation: \"save\",\n context: { session_id: this.#session_id },\n });\n });\n }\n };\n\n #on_conversation_dispose = () => this[Symbol.dispose]();\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { Message } from \"@simulacra-ai/core\";\nimport type { SessionMetadata, SessionStore } from \"./types.ts\";\n\ninterface SessionFile {\n metadata: Omit<SessionMetadata, \"id\">;\n messages: Message[];\n}\n\n/**\n * A file-based implementation of SessionStore.\n *\n * This store persists sessions as JSON files in a specified directory. Each session\n * is stored in a separate file named with its session ID. The store also maintains\n * hard links for fork relationships to enable efficient querying of session trees.\n */\nexport class FileSessionStore implements SessionStore {\n readonly #root: string;\n\n /**\n * Creates a new FileSessionStore instance.\n *\n * @param root - The absolute path to the directory where session files will be stored.\n */\n constructor(root: string) {\n this.#root = root;\n }\n\n /**\n * Lists all sessions stored in the file system.\n *\n * Reads all JSON files from the root directory and parses their metadata.\n *\n * @returns A promise that resolves to an array of session metadata, sorted by most recently updated first.\n */\n async list(): Promise<SessionMetadata[]> {\n await this.#ensure_dir();\n const sessions: SessionMetadata[] = [];\n\n const entries = await fs.readdir(this.#root, { withFileTypes: true });\n for (const entry of entries) {\n if (!entry.isFile() || !entry.name.endsWith(\".json\")) {\n continue;\n }\n const session = await this.#read_session(\n path.join(this.#root, entry.name),\n entry.name.replace(/\\.json$/, \"\"),\n );\n if (session) {\n sessions.push(session);\n }\n }\n\n return sessions.sort((a, b) => b.updated_at.localeCompare(a.updated_at));\n }\n\n /**\n * Loads a session from the file system.\n *\n * @param id - The unique identifier of the session to load.\n * @returns A promise that resolves to the session metadata and messages, or undefined if not found.\n */\n async load(id: string) {\n return this.#read_file(path.join(this.#root, `${id}.json`), id);\n }\n\n /**\n * Saves a session to the file system.\n *\n * Creates a new session file if the ID does not exist, or updates an existing file.\n * Automatically updates the updated_at timestamp and message_count. If the session\n * has a parent, creates a hard link in the parent's fork directory for efficient querying.\n *\n * @param id - The unique identifier of the session.\n * @param messages - The messages to store for this session.\n * @param metadata - Optional partial metadata to merge with existing metadata.\n * @returns A promise that resolves when the save operation is complete.\n */\n async save(id: string, messages: Message[], metadata?: Partial<SessionMetadata>) {\n const now = new Date().toISOString();\n await this.#ensure_dir();\n\n const file_path = path.join(this.#root, `${id}.json`);\n const existing = await this.#read_file(file_path, id);\n const existing_metadata: Partial<SessionMetadata> = existing?.metadata ?? {};\n const parent_id = metadata?.parent_id ?? existing_metadata.parent_id;\n\n const file: SessionFile = {\n metadata: {\n ...existing_metadata,\n created_at: existing_metadata.created_at ?? now,\n updated_at: now,\n message_count: messages.length,\n ...metadata,\n },\n messages,\n };\n\n await fs.writeFile(file_path, JSON.stringify(file, null, 2), \"utf8\");\n\n if (parent_id) {\n await this.#ensure_fork_link(parent_id, id);\n }\n }\n\n /**\n * Deletes a session from the file system.\n *\n * Removes the session file, any hard links in parent fork directories, and the session's\n * own fork directory if it exists.\n *\n * @param id - The unique identifier of the session to delete.\n * @returns A promise that resolves to true if the session was deleted, false if it was not found.\n */\n async delete(id: string) {\n const file_path = path.join(this.#root, `${id}.json`);\n try {\n const result = await this.#read_file(file_path, id);\n await fs.unlink(file_path);\n\n if (result?.metadata.parent_id) {\n const link = path.join(this.#root, `${result.metadata.parent_id}-forks`, `${id}.json`);\n try {\n await fs.unlink(link);\n } catch {\n /* link may not exist */\n }\n }\n\n const fork_dir = path.join(this.#root, `${id}-forks`);\n try {\n await fs.rm(fork_dir, { recursive: true });\n } catch {\n /* no forks */\n }\n\n return true;\n } catch {\n return false;\n }\n }\n\n async #ensure_fork_link(parent_id: string, fork_id: string) {\n const fork_dir = path.join(this.#root, `${parent_id}-forks`);\n await fs.mkdir(fork_dir, { recursive: true });\n\n const canonical = path.join(this.#root, `${fork_id}.json`);\n const link = path.join(fork_dir, `${fork_id}.json`);\n\n try {\n await fs.unlink(link);\n } catch {\n /* doesn't exist yet */\n }\n\n try {\n await fs.link(canonical, link);\n } catch {\n // hard links can fail across filesystems — fall back to no index\n }\n }\n\n async #read_file(file_path: string, id: string) {\n try {\n const content = await fs.readFile(file_path, \"utf8\");\n const data: SessionFile = JSON.parse(content);\n return {\n metadata: { id, ...data.metadata } as SessionMetadata,\n messages: data.messages,\n };\n } catch {\n return undefined;\n }\n }\n\n async #read_session(file_path: string, id: string): Promise<SessionMetadata | undefined> {\n try {\n const content = await fs.readFile(file_path, \"utf8\");\n const data: SessionFile = JSON.parse(content);\n return { id, ...data.metadata };\n } catch {\n return undefined;\n }\n }\n\n async #ensure_dir() {\n await fs.mkdir(this.#root, { recursive: true });\n }\n}\n","import type { Message } from \"@simulacra-ai/core\";\nimport type { SessionMetadata, SessionStore } from \"./types.ts\";\n\n/**\n * An in-memory implementation of SessionStore.\n *\n * This store keeps all session data in memory using a Map. Data is not persisted\n * across process restarts. Useful for testing or scenarios where persistence is not required.\n */\nexport class InMemorySessionStore implements SessionStore {\n readonly #sessions = new Map<string, { metadata: SessionMetadata; messages: Message[] }>();\n\n /**\n * Lists all sessions stored in memory.\n *\n * @returns A promise that resolves to an array of session metadata, sorted by most recently updated first.\n */\n async list(): Promise<SessionMetadata[]> {\n return [...this.#sessions.values()]\n .map((s) => s.metadata)\n .sort((a, b) => b.updated_at.localeCompare(a.updated_at));\n }\n\n /**\n * Loads a session from memory.\n *\n * Returns a deep clone of the stored data to prevent external mutations.\n *\n * @param id - The unique identifier of the session to load.\n * @returns A promise that resolves to the session metadata and messages, or undefined if not found.\n */\n async load(id: string) {\n const entry = this.#sessions.get(id);\n if (!entry) {\n return undefined;\n }\n return {\n metadata: { ...entry.metadata },\n messages: structuredClone(entry.messages),\n };\n }\n\n /**\n * Saves a session to memory.\n *\n * Creates a new session if the ID does not exist, or updates an existing session.\n * Automatically updates the updated_at timestamp and message_count.\n *\n * @param id - The unique identifier of the session.\n * @param messages - The messages to store for this session.\n * @param metadata - Optional partial metadata to merge with existing metadata.\n * @returns A promise that resolves when the save operation is complete.\n */\n async save(id: string, messages: Message[], metadata?: Partial<SessionMetadata>) {\n const now = new Date().toISOString();\n const existing = this.#sessions.get(id);\n\n this.#sessions.set(id, {\n metadata: {\n id,\n ...existing?.metadata,\n created_at: existing?.metadata.created_at ?? now,\n updated_at: now,\n message_count: messages.length,\n ...metadata,\n },\n messages: structuredClone(messages),\n });\n }\n\n /**\n * Deletes a session from memory.\n *\n * @param id - The unique identifier of the session to delete.\n * @returns A promise that resolves to true if the session was deleted, false if it was not found.\n */\n async delete(id: string) {\n return this.#sessions.delete(id);\n }\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,OAAO,kBAAkB;AAgBlB,IAAM,iBAAN,MAAM,gBAAe;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,iBAAiB,IAAI,aAAmC;AAAA,EACxD,kBAAoC,CAAC;AAAA,EAE9C;AAAA,EACA,eAAe;AAAA,EACf,aAAa;AAAA,EACb,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASZ,YAAY,OAAqB,cAA4B,SAAiC;AAC5F,SAAK,SAAS;AACd,SAAK,gBAAgB;AACrB,SAAK,aAAa,SAAS,aAAa;AACxC,SAAK,aAAa,SAAS,aAAa;AAExC,QAAI,KAAK,YAAY;AACnB,WAAK,cAAc,GAAG,oBAAoB,KAAK,oBAAoB;AAAA,IACrE;AACA,SAAK,cAAc,GAAG,gBAAgB,KAAK,gBAAgB;AAC3D,SAAK,cAAc,KAAK,WAAW,KAAK,wBAAwB;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,qBAAqB;AACvB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,YAAY;AACd,WAAO,CAAC,CAAC,KAAK;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,CAAC,OAAO,OAAO,IAAI;AACjB,QAAI,KAAK,WAAW;AAClB;AAAA,IACF;AACA,SAAK,YAAY;AAEjB,eAAW,SAAS,KAAK,iBAAiB;AACxC,YAAM,OAAO,OAAO,EAAE;AAAA,IACxB;AACA,SAAK,gBAAgB,SAAS;AAE9B,SAAK,cAAc,IAAI,oBAAoB,KAAK,oBAAoB;AACpE,SAAK,c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AY;AACrB,UAAM,QAAQ,KAAK,UAAU,IAAI,EAAE;AACnC,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AACA,WAAO;AAAA,MACL,UAAU,EAAE,GAAG,MAAM,SAAS;AAAA,MAC9B,UAAU,gBAAgB,MAAM,QAAQ;AAAA,IAC1C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAM,KAAK,IAAY,UAAqB,UAAqC;AAC/E,UAAM,OAAM,oBAAI,KAAK,GAAE,YAAY;AACnC,UAAM,WAAW,KAAK,UAAU,IAAI,EAAE;AAEtC,SAAK,UAAU,IAAI,IAAI;AAAA,MACrB,UAAU;AAAA,QACR;AAAA,QACA,GAAG,UAAU;AAAA,QACb,YAAY,UAAU,SAAS,cAAc;AAAA,QAC7C,YAAY;AAAA,QACZ,eAAe,SAAS;AAAA,QACxB,GAAG;AAAA,MACL;AAAA,MACA,UAAU,gBAAgB,QAAQ;AAAA,IACpC,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,OAAO,IAAY;AACvB,WAAO,KAAK,UAAU,OAAO,EAAE;AAAA,EACjC;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simulacra-ai/session",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Session persistence for the Simulacra conversation engine with pluggable file and in-memory storage",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
"
|
|
9
|
-
|
|
8
|
+
"require": {
|
|
9
|
+
"types": "./dist/index.d.cts",
|
|
10
|
+
"default": "./dist/index.cjs"
|
|
11
|
+
},
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
10
16
|
}
|
|
11
17
|
},
|
|
12
18
|
"files": [
|
|
13
19
|
"dist"
|
|
14
20
|
],
|
|
15
21
|
"scripts": {
|
|
16
|
-
"build": "
|
|
22
|
+
"build": "tsup",
|
|
17
23
|
"clean": "rm -rf dist *.tsbuildinfo"
|
|
18
24
|
},
|
|
19
25
|
"peerDependencies": {
|
|
20
|
-
"@simulacra-ai/core": "0.0.
|
|
26
|
+
"@simulacra-ai/core": "0.0.4"
|
|
21
27
|
},
|
|
22
28
|
"repository": {
|
|
23
29
|
"type": "git",
|