@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 +30 -1
- package/dist/index.cjs +693 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +517 -0
- package/dist/index.d.ts +517 -5
- package/dist/index.js +652 -3
- package/dist/index.js.map +1 -1
- package/package.json +26 -8
- 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/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.
|
|
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
|