@simulacra-ai/session 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +31 -34
  2. package/package.json +14 -3
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Simulacra Session
2
2
 
3
- Session persistence for the Simulacra conversation engine. Manages saving, loading, and labeling conversation sessions with pluggable storage backends.
3
+ The session package makes Simulacra conversations durable. Conversations are stateful, but that state lives in memory and disappears when the process exits. The session manager handles saving, loading, and labeling sessions with pluggable storage backends. Sessions can be resumed across process restarts, forked into branches, and automatically saved as the conversation progresses.
4
4
 
5
5
  ## Installation
6
6
 
@@ -11,26 +11,37 @@ npm install @simulacra-ai/core @simulacra-ai/session
11
11
  ## Quick Start
12
12
 
13
13
  ```typescript
14
- import { SessionManager, FileSessionStore } from "@simulacra-ai/session";
14
+ import { Conversation } from "@simulacra-ai/core";
15
+ import { FileSessionStore, SessionManager } from "@simulacra-ai/session";
15
16
 
17
+ // assuming provider is already configured
18
+
19
+ // create a conversation
20
+ using conversation = new Conversation(provider);
21
+
22
+ // create a session manager backed by the filesystem
16
23
  const store = new FileSessionStore("./sessions");
17
- const session = new SessionManager(store, conversation);
24
+ using session = new SessionManager(store, conversation);
18
25
 
26
+ // start a new session
19
27
  session.start_new("my first session");
20
- // ... conversation happens ...
21
- await session.save();
28
+
29
+ // conversation happens, messages are saved automatically
30
+ await conversation.prompt("Hello!");
22
31
  ```
23
32
 
24
- With `auto_save` (default `true`), messages are saved automatically after each model response.
33
+ With `auto_save` (default `true`), messages are persisted after each model response without any manual save calls.
25
34
 
26
35
  ## SessionManager
27
36
 
28
- `SessionManager` coordinates a conversation with a storage backend and handles the lifecycle of sessions: creation, loading, saving, and disposal.
37
+ The `SessionManager` coordinates a conversation with a storage backend. It handles the full lifecycle of sessions, from creation through saving to disposal.
29
38
 
30
39
  ```typescript
31
40
  new SessionManager(store, conversation, options?)
32
41
  ```
33
42
 
43
+ The constructor accepts the following options.
44
+
34
45
  Option|Type|Default|Description
35
46
  -|-|-|-
36
47
  `auto_save`|`boolean`|`true`|Save after every `message_complete` event
@@ -38,70 +49,56 @@ Option|Type|Default|Description
38
49
 
39
50
  ### Methods
40
51
 
52
+ The session manager exposes the following methods.
53
+
41
54
  Method|Description
42
55
  -|-
43
56
  `start_new(label?)`|Begin a new session, returns the session ID
44
57
  `load(id?)`|Load a session by ID, or the most recent if omitted
45
58
  `save(metadata?)`|Persist current messages and metadata
46
- `fork(parent_id, options?)`|Create a child session branching from a parent
59
+ `fork(parent_id, options?)`|Create a child session branching from a parent, returns the new session ID
47
60
  `list()`|List all sessions from the store
48
61
  `delete(id)`|Remove a session
49
62
  `rename(id, label)`|Change a session's label
50
63
 
51
64
  ### Events
52
65
 
66
+ The session manager emits events as sessions are loaded and saved.
67
+
53
68
  Event|Payload|When
54
69
  -|-|-
55
70
  `load`|`{ id, messages }`|Session loaded from store
56
71
  `save`|`{ id, messages }`|Session written to store
72
+ `lifecycle_error`|`{ error, operation, context? }`|Infrastructure or lifecycle failure
57
73
  `dispose`|(none)|Manager disposed
58
74
 
59
75
  ### Auto-Slug
60
76
 
61
- When `auto_slug` is enabled, `SessionManager` derives a label from the first ~50 characters of the first user message (trimmed to a word boundary). This runs once on the first save; explicitly setting a label via `start_new(label)` or `rename()` takes precedence.
77
+ When `auto_slug` is enabled, the session manager derives a label from the first ~50 characters of the first user message, trimmed to a word boundary. This runs once on the first save. Explicitly setting a label via `start_new(label)` or `rename()` takes precedence.
62
78
 
63
79
  ### Child Sessions
64
80
 
65
- `SessionManager` listens for the conversation's `create_child` event. When a child conversation is spawned via orchestration, checkpoints, or `spawn_child` the session manager automatically creates a child session backed by a detached fork. Child sessions auto-save independently and are disposed when the child conversation ends.
81
+ When a child conversation is spawned (via orchestration, checkpoints, or `spawn_child`), the session manager automatically creates a child session backed by a detached fork. Child sessions auto-save independently and are disposed when the child conversation ends. This means orchestration subagents, checkpoint summaries, and other child conversations all get their own persistent session history without any manual setup.
66
82
 
67
83
  Checkpoint children have `auto_slug` disabled since their sessions are internal.
68
84
 
69
- ## Built-in Stores
85
+ ## Session Storage
70
86
 
71
- ### FileSessionStore
87
+ A `SessionStore` is the storage backend that a `SessionManager` reads from and writes to. The store handles listing, loading, saving, and deleting sessions. Two stores are included out of the box.
72
88
 
73
- Persists sessions as JSON files on disk. Each session is a single `{id}.json` file.
89
+ **FileSessionStore** persists sessions as JSON files on disk. Each session is a single `{id}.json` file. Child session relationships are indexed using hard links under `{parent-id}-forks/` directories.
74
90
 
75
91
  ```typescript
76
- import { FileSessionStore } from "@simulacra-ai/session";
77
-
78
92
  const store = new FileSessionStore("./data/sessions");
79
93
  ```
80
94
 
81
- Child session relationships are indexed using hard links under `{parent-id}-forks/` directories.
82
-
83
- ### InMemorySessionStore
84
-
85
- Non-persistent store for testing. Sessions live in a `Map` and are lost on process exit.
95
+ **InMemorySessionStore** is a non-persistent store for testing and development. Sessions live in a `Map` and are lost on process exit.
86
96
 
87
97
  ```typescript
88
- import { InMemorySessionStore } from "@simulacra-ai/session";
89
-
90
98
  const store = new InMemorySessionStore();
91
99
  ```
92
100
 
93
- ## SessionStore Interface
94
-
95
- Custom storage backends implement the `SessionStore` interface. See the [extensibility guide](EXTENSIBILITY.md) for implementation details and examples.
96
-
97
- ```typescript
98
- interface SessionStore {
99
- list(): Promise<SessionMetadata[]>;
100
- load(id: string): Promise<{ metadata: SessionMetadata; messages: Message[] } | undefined>;
101
- save(id: string, messages: Message[], metadata?: Partial<SessionMetadata>): Promise<void>;
102
- delete(id: string): Promise<boolean>;
103
- }
104
- ```
101
+ Custom storage backends (databases, cloud storage, key-value stores) can be built by implementing the `SessionStore` interface. The [extensibility guide](EXTENSIBILITY.md) covers the interface, implementation notes, and includes a full example.
105
102
 
106
103
  ## License
107
104
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simulacra-ai/session",
3
- "version": "0.0.1",
4
- "description": "Session persistence for the Simulacra conversation engine pluggable storage with file and in-memory providers",
3
+ "version": "0.0.3",
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
  ".": {
@@ -17,7 +17,18 @@
17
17
  "clean": "rm -rf dist *.tsbuildinfo"
18
18
  },
19
19
  "peerDependencies": {
20
- "@simulacra-ai/core": "0.0.1"
20
+ "@simulacra-ai/core": "0.0.3"
21
21
  },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/simulacra-ai/simulacra.git",
25
+ "directory": "packages/session"
26
+ },
27
+ "homepage": "https://github.com/simulacra-ai/simulacra",
28
+ "keywords": [
29
+ "ai",
30
+ "llm",
31
+ "agent"
32
+ ],
22
33
  "license": "MIT"
23
34
  }