@simulacra-ai/session 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -84,7 +84,7 @@ Checkpoint children have `auto_slug` disabled since their sessions are internal.
84
84
 
85
85
  ## Session Storage
86
86
 
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.
87
+ A `SessionStore` is the storage backend that a `SessionManager` reads from and writes to. The store handles listing, loading, saving, and deleting sessions. Three stores are included out of the box.
88
88
 
89
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.
90
90
 
@@ -98,6 +98,35 @@ const store = new FileSessionStore("./data/sessions");
98
98
  const store = new InMemorySessionStore();
99
99
  ```
100
100
 
101
+ **DrizzleSessionStore** persists sessions in a relational database using Drizzle ORM. It works with any database that Drizzle supports (PostgreSQL, MySQL, SQLite). The store does not import `drizzle-orm` itself. Instead, it accepts an adapter object with `list`, `load`, `upsert`, and `delete` functions that wrap Drizzle queries against the application's table.
102
+
103
+ ```typescript
104
+ import { DrizzleSessionStore } from "@simulacra-ai/session";
105
+
106
+ const store = new DrizzleSessionStore({
107
+ list: () =>
108
+ db.select().from(sessionsTable).orderBy(desc(sessionsTable.updated_at)),
109
+ load: async (id) => {
110
+ const [row] = await db
111
+ .select({ metadata: sessionsTable.metadata, messages: sessionsTable.messages })
112
+ .from(sessionsTable)
113
+ .where(eq(sessionsTable.id, id));
114
+ return row;
115
+ },
116
+ upsert: (row) =>
117
+ db.insert(sessionsTable).values(row).onConflictDoUpdate({
118
+ target: sessionsTable.id,
119
+ set: { metadata: row.metadata, messages: row.messages, updated_at: row.updated_at },
120
+ }),
121
+ delete: async (id) => {
122
+ const result = await db.delete(sessionsTable).where(eq(sessionsTable.id, id));
123
+ return result.rowCount > 0;
124
+ },
125
+ });
126
+ ```
127
+
128
+ The `DrizzleSessionRow` and `DrizzleSessionAdapter` types are exported for reference when defining a table schema and adapter. See the JSDoc on `DrizzleSessionRow` for example PostgreSQL and SQLite table definitions.
129
+
101
130
  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.
102
131
 
103
132
  ## License