@dudousxd/nestjs-agent-store-drizzle 0.23.0 → 0.24.0
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 +48 -9
- package/dist/index.cjs +1100 -605
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4802 -17
- package/dist/index.d.ts +4802 -17
- package/dist/index.js +1076 -585
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -16,15 +16,33 @@ pnpm add @dudousxd/nestjs-agent-store-drizzle drizzle-orm
|
|
|
16
16
|
## Use
|
|
17
17
|
|
|
18
18
|
The host app owns the connection and passes in an already-opened Drizzle handle — this module never
|
|
19
|
-
opens one itself.
|
|
19
|
+
opens one itself. **SQLite, Postgres and MySQL** all work — CI runs every store suite on
|
|
20
|
+
better-sqlite3, node-postgres (Postgres 16) and mysql2 (MySQL 8.4), and the other Drizzle drivers of
|
|
21
|
+
each dialect speak the same query builder. Build the handle with the schema object for your dialect;
|
|
22
|
+
every store reads the dialect off the handle.
|
|
20
23
|
|
|
21
24
|
```ts
|
|
25
|
+
// SQLite
|
|
22
26
|
import Database from 'better-sqlite3';
|
|
23
27
|
import { drizzle } from 'drizzle-orm/better-sqlite3';
|
|
24
|
-
import {
|
|
25
|
-
|
|
28
|
+
import { agentSchema } from '@dudousxd/nestjs-agent-store-drizzle';
|
|
26
29
|
const db = drizzle(new Database('app.db'), { schema: agentSchema });
|
|
27
|
-
|
|
30
|
+
|
|
31
|
+
// Postgres
|
|
32
|
+
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
33
|
+
import { pgAgentSchema } from '@dudousxd/nestjs-agent-store-drizzle';
|
|
34
|
+
const db = drizzle(pool, { schema: pgAgentSchema });
|
|
35
|
+
|
|
36
|
+
// MySQL (8.0+)
|
|
37
|
+
import { drizzle } from 'drizzle-orm/mysql2';
|
|
38
|
+
import { mysqlAgentSchema } from '@dudousxd/nestjs-agent-store-drizzle';
|
|
39
|
+
const db = drizzle(pool, { schema: mysqlAgentSchema, mode: 'default' });
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { DrizzleAgentStoreModule, ensureAgentSchema } from '@dudousxd/nestjs-agent-store-drizzle';
|
|
44
|
+
|
|
45
|
+
await ensureAgentSchema(db); // idempotent: creates what is missing — or run your own migrations
|
|
28
46
|
|
|
29
47
|
@Module({
|
|
30
48
|
imports: [
|
|
@@ -35,10 +53,31 @@ await ensureAgentSchema(db); // idempotent CREATE TABLE IF NOT EXISTS — or run
|
|
|
35
53
|
export class AppModule {}
|
|
36
54
|
```
|
|
37
55
|
|
|
38
|
-
The package ships the `agentSchema`
|
|
39
|
-
|
|
40
|
-
`DrizzleRagIngestionLog`. For production,
|
|
41
|
-
|
|
56
|
+
The package ships the tables for each dialect (`agentSchema` · `pgAgentSchema` · `mysqlAgentSchema`
|
|
57
|
+
— same table, column and property names), `ensureAgentSchema` (a non-destructive DDL helper),
|
|
58
|
+
`DrizzleAgentStore`, `DrizzleGovernanceQueries`, and `DrizzleRagIngestionLog`. For production, prefer
|
|
59
|
+
your normal drizzle-kit migrations over the `ensureAgentSchema` helper: point drizzle-kit at the
|
|
60
|
+
schema object for your dialect.
|
|
61
|
+
|
|
62
|
+
### What each dialect stores
|
|
63
|
+
|
|
64
|
+
| | SQLite | Postgres | MySQL |
|
|
65
|
+
|---|---|---|---|
|
|
66
|
+
| JSON columns | `text` (JSON) | `jsonb` | `json` |
|
|
67
|
+
| timestamps | epoch-ms `integer` | `timestamptz(3)` | `datetime(3)`, UTC |
|
|
68
|
+
| long text (content, reasoning, errors) | `text` | `text` | `longtext` |
|
|
69
|
+
| keys and labels | `text` | `text` | `varchar(255)` |
|
|
70
|
+
| prices / costs | `real` | `double precision` | `double` |
|
|
71
|
+
| id / actor comparison | exact | exact | exact (`utf8mb4_bin`) |
|
|
72
|
+
|
|
73
|
+
`ensureAgentSchema` renders its DDL from these schema objects, creates missing tables, columns and
|
|
74
|
+
indexes, and never drops or alters anything. On Postgres and MySQL it holds a cross-replica lock
|
|
75
|
+
(`pg_advisory_xact_lock` / `get_lock`) for the duration, so replicas booting an empty database at
|
|
76
|
+
once do not race their `CREATE TABLE`s.
|
|
77
|
+
|
|
78
|
+
Messages carry a per-thread `seq`, assigned on append, which is what orders a transcript — two
|
|
79
|
+
messages of one turn routinely share a timestamp. A row written before the column existed has none
|
|
80
|
+
and sorts first, by `created_at`, as before.
|
|
42
81
|
|
|
43
82
|
## The read a turn makes
|
|
44
83
|
|
|
@@ -56,7 +95,7 @@ a client rendering a transcript.
|
|
|
56
95
|
## Memory
|
|
57
96
|
|
|
58
97
|
`DrizzleMemoryProvider` is a `MemoryProvider` over `agent_memory`, a table `ensureAgentSchema`
|
|
59
|
-
creates alongside the other
|
|
98
|
+
creates alongside the other agent tables.
|
|
60
99
|
|
|
61
100
|
```ts
|
|
62
101
|
import { DrizzleAgentStoreModule, DrizzleMemoryProvider } from '@dudousxd/nestjs-agent-store-drizzle';
|