@axiom-lattice/pg-stores 1.0.66 → 1.0.67

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @axiom-lattice/pg-stores@1.0.66 build /home/runner/work/agentic/agentic/packages/pg-stores
2
+ > @axiom-lattice/pg-stores@1.0.67 build /home/runner/work/agentic/agentic/packages/pg-stores
3
3
  > tsup src/index.ts --format cjs,esm --dts --sourcemap
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,13 +8,13 @@
8
8
  CLI Target: es2020
9
9
  CJS Build start
10
10
  ESM Build start
11
- CJS dist/index.js 203.86 KB
12
- CJS dist/index.js.map 375.22 KB
13
- CJS ⚡️ Build success in 411ms
14
- ESM dist/index.mjs 198.84 KB
15
- ESM dist/index.mjs.map 375.06 KB
16
- ESM ⚡️ Build success in 434ms
11
+ CJS dist/index.js 204.37 KB
12
+ CJS dist/index.js.map 377.59 KB
13
+ CJS ⚡️ Build success in 505ms
14
+ ESM dist/index.mjs 199.35 KB
15
+ ESM dist/index.mjs.map 377.44 KB
16
+ ESM ⚡️ Build success in 509ms
17
17
  DTS Build start
18
- DTS ⚡️ Build success in 12103ms
19
- DTS dist/index.d.ts 47.54 KB
20
- DTS dist/index.d.mts 47.54 KB
18
+ DTS ⚡️ Build success in 12714ms
19
+ DTS dist/index.d.ts 48.13 KB
20
+ DTS dist/index.d.mts 48.13 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @axiom-lattice/pg-stores
2
2
 
3
+ ## 1.0.67
4
+
5
+ ### Patch Changes
6
+
7
+ - 6ff5bd5: fix issue
8
+ - Updated dependencies [6ff5bd5]
9
+ - @axiom-lattice/core@2.1.76
10
+ - @axiom-lattice/protocols@2.1.39
11
+
3
12
  ## 1.0.66
4
13
 
5
14
  ### Patch Changes
package/README.md CHANGED
@@ -1,341 +1,108 @@
1
1
  # @axiom-lattice/pg-stores
2
2
 
3
- PostgreSQL stores implementation for the Axiom Lattice framework.
3
+ PostgreSQL store implementations for the Axiom Lattice framework.
4
4
 
5
- ## Overview
6
-
7
- This package provides PostgreSQL-based store implementations that conform to the store interfaces. It can be used with the `StoreLatticeManager` from `@axiom-lattice/core` to register and manage PostgreSQL-based store services.
8
-
9
- ## Features
10
-
11
- - **ThreadStore**: PostgreSQL implementation for thread management
12
- - **AssistantStore**: PostgreSQL implementation for assistant management
13
- - **Migration System**: Automatic schema migration with version tracking
14
- - **Type Safety**: Full TypeScript support with proper type definitions
15
-
16
- ## Installation
17
-
18
- ```bash
19
- pnpm add @axiom-lattice/pg-stores
20
- ```
21
-
22
- ## Prerequisites
23
-
24
- - PostgreSQL database (version 12 or higher)
25
- - Node.js 18 or higher
26
-
27
- ## Usage
28
-
29
- ### Basic Usage - Register ThreadStore
5
+ ## Quick Start
30
6
 
31
7
  ```typescript
32
- import { PostgreSQLThreadStore } from "@axiom-lattice/pg-stores";
33
- import { registerStoreLattice, getStoreLattice } from "@axiom-lattice/core";
34
-
35
- // Create and initialize ThreadStore with connection string
36
- const threadStore = new PostgreSQLThreadStore({
37
- poolConfig: process.env.DATABASE_URL || "postgresql://localhost:5432/mydb",
38
- });
8
+ import { configureStores } from "@axiom-lattice/core";
9
+ import { createPgStoreConfig } from "@axiom-lattice/pg-stores";
10
+ import { PostgresSaver } from "@langchain/langgraph-checkpoint-postgres";
39
11
 
40
- // Ensure initialization (migrations run automatically)
41
- await threadStore.initialize();
12
+ // One connection string creates all PG stores
13
+ const stores = createPgStoreConfig(process.env.DATABASE_URL);
42
14
 
43
- // Register to StoreLatticeManager
44
- registerStoreLattice("threads", "thread", threadStore);
45
-
46
- // Or use PoolConfig object
47
- const threadStore2 = new PostgreSQLThreadStore({
48
- poolConfig: {
49
- host: process.env.DB_HOST || "localhost",
50
- port: parseInt(process.env.DB_PORT || "5432"),
51
- database: process.env.DB_NAME || "mydb",
52
- user: process.env.DB_USER,
53
- password: process.env.DB_PASSWORD,
54
- },
15
+ // Register all stores in one call
16
+ await configureStores({
17
+ ...stores,
18
+ checkpoint: PostgresSaver.fromConnString(process.env.DATABASE_URL),
55
19
  });
56
-
57
- await threadStore2.initialize();
58
- registerStoreLattice("threads", "thread", threadStore2);
59
20
  ```
60
21
 
61
- ### Basic Usage - Register AssistantStore
62
-
63
- ```typescript
64
- import { PostgreSQLAssistantStore } from "@axiom-lattice/pg-stores";
65
- import { registerStoreLattice, getStoreLattice } from "@axiom-lattice/core";
66
-
67
- // Create and initialize AssistantStore with connection string
68
- const assistantStore = new PostgreSQLAssistantStore({
69
- poolConfig: process.env.DATABASE_URL || "postgresql://localhost:5432/mydb",
70
- });
71
-
72
- // Ensure initialization (migrations run automatically)
73
- await assistantStore.initialize();
74
-
75
- // Register to StoreLatticeManager
76
- registerStoreLattice("assistants", "assistant", assistantStore);
77
-
78
- // Get and use the store (with type safety)
79
- const storeLattice = getStoreLattice("assistants", "assistant");
80
- const assistantStoreInstance = storeLattice.store; // TypeScript knows this is AssistantStore
81
-
82
- // Create an assistant
83
- const assistant = await assistantStoreInstance.createAssistant(
84
- "assistant-123",
85
- {
86
- name: "My Assistant",
87
- description: "A helpful assistant",
88
- graphDefinition: {
89
- /* ... */
90
- },
91
- }
92
- );
93
-
94
- // Get all assistants
95
- const assistants = await assistantStoreInstance.getAllAssistants();
22
+ ## `createPgStoreConfig`
96
23
 
97
- // Get a specific assistant
98
- const foundAssistant = await assistantStoreInstance.getAssistantById(
99
- "assistant-123"
100
- );
24
+ Factory function that creates all PG store instances from a single connection string. Returns an object ready to spread into `configureStores()`.
101
25
 
102
- // Update assistant
103
- const updatedAssistant = await assistantStoreInstance.updateAssistant(
104
- "assistant-123",
105
- {
106
- name: "Updated Name",
107
- }
108
- );
109
-
110
- // Delete assistant
111
- await assistantStoreInstance.deleteAssistant("assistant-123");
26
+ ```typescript
27
+ function createPgStoreConfig(connectionString: string): {
28
+ workspace: PostgreSQLWorkspaceStore;
29
+ project: PostgreSQLProjectStore;
30
+ eval: PostgreSQLEvalStore;
31
+ user: PostgreSQLUserStore;
32
+ tenant: PostgreSQLTenantStore;
33
+ userTenantLink: PostgreSQLUserTenantLinkStore;
34
+ channelBinding: ChannelBindingStore;
35
+ channelInstallation: PostgreSQLChannelInstallationStore;
36
+ thread: PostgreSQLThreadStore;
37
+ database: PostgreSQLDatabaseConfigStore;
38
+ metrics: PostgreSQLMetricsServerConfigStore;
39
+ mcp: PostgreSQLMcpServerConfigStore;
40
+ assistant: PostgreSQLAssistantStore;
41
+ workflowTracking: PostgreSQLWorkflowTrackingStore;
42
+ threadMessageQueue: ThreadMessageQueueStore;
43
+ schedule: PostgreSQLScheduleStorage;
44
+ }
112
45
  ```
113
46
 
114
- // Get and use the store (with type safety)
115
- const storeLattice = getStoreLattice("threads", "thread");
116
- const threadStore = storeLattice.store; // TypeScript knows this is ThreadStore
117
-
118
- // Create a thread
119
- const thread = await threadStore.createThread("assistant-123", "thread-456", {
120
- metadata: { title: "My Thread" },
121
- });
122
-
123
- // Get threads by assistant
124
- const threads = await threadStore.getThreadsByAssistantId("assistant-123");
47
+ Stores with `autoMigrate: true`: eval, channelBinding, channelInstallation, workflowTracking, threadMessageQueue.
48
+ All others use `autoMigrate: false` (manual `initialize()` via `configureStores`).
125
49
 
126
- // Get a specific thread
127
- const foundThread = await threadStore.getThreadById(
128
- "assistant-123",
129
- "thread-456"
130
- );
50
+ ## Individual Store Usage
131
51
 
132
- // Update thread
133
- const updatedThread = await threadStore.updateThread(
134
- "assistant-123",
135
- "thread-456",
136
- { metadata: { title: "Updated Title" } }
137
- );
138
-
139
- // Delete thread
140
- await threadStore.deleteThread("assistant-123", "thread-456");
141
-
142
- ````
143
-
144
- ### Direct Usage (Without Registration)
52
+ If you only need specific stores, construct them directly:
145
53
 
146
54
  ```typescript
147
- import { PostgreSQLThreadStore } from "@axiom-lattice/pg-stores";
55
+ import { configureStores } from "@axiom-lattice/core";
56
+ import { PostgreSQLThreadStore, PostgreSQLAssistantStore } from "@axiom-lattice/pg-stores";
148
57
 
149
- // Create store instance with connection string (migrations run automatically)
150
- const threadStore = new PostgreSQLThreadStore({
151
- poolConfig: process.env.DATABASE_URL || "postgresql://localhost:5432/mydb",
152
- autoMigrate: true, // Default: true
58
+ await configureStores({
59
+ thread: new PostgreSQLThreadStore({ poolConfig: process.env.DATABASE_URL }),
60
+ assistant: new PostgreSQLAssistantStore({ poolConfig: process.env.DATABASE_URL }),
153
61
  });
62
+ ```
154
63
 
155
- // Ensure initialization
156
- await threadStore.initialize();
157
-
158
- // When done, dispose the store to close connections
159
- // await threadStore.dispose();
160
-
161
- // Use the store
162
- const threads = await threadStore.getThreadsByAssistantId("assistant-123");
163
- ````
164
-
165
- ### Manual Migration Control
64
+ ## Available Stores
65
+
66
+ | Store | Class | Description |
67
+ |-------|-------|-------------|
68
+ | thread | `PostgreSQLThreadStore` | Thread CRUD |
69
+ | assistant | `PostgreSQLAssistantStore` | Assistant CRUD |
70
+ | skill | `PostgreSQLSkillStore` | Skill storage |
71
+ | workspace | `PostgreSQLWorkspaceStore` | Workspace management |
72
+ | project | `PostgreSQLProjectStore` | Project management |
73
+ | database | `PostgreSQLDatabaseConfigStore` | DB connection configs |
74
+ | metrics | `PostgreSQLMetricsServerConfigStore` | Metrics server configs |
75
+ | mcp | `PostgreSQLMcpServerConfigStore` | MCP server configs |
76
+ | user | `PostgreSQLUserStore` | User storage |
77
+ | tenant | `PostgreSQLTenantStore` | Tenant storage |
78
+ | userTenantLink | `PostgreSQLUserTenantLinkStore` | User-tenant links |
79
+ | threadMessageQueue | `ThreadMessageQueueStore` | Message queue persistence |
80
+ | workflowTracking | `PostgreSQLWorkflowTrackingStore` | Workflow run tracking |
81
+ | eval | `PostgreSQLEvalStore` | Evaluation storage |
82
+ | channelInstallation | `PostgreSQLChannelInstallationStore` | Channel installations |
83
+ | channelBinding | `ChannelBindingStore` | Sender-to-agent bindings |
84
+ | schedule | `PostgreSQLScheduleStorage` | Scheduled task persistence |
85
+
86
+ ## Constructor Options
87
+
88
+ All stores accept the same options pattern:
166
89
 
167
90
  ```typescript
168
- import { PostgreSQLThreadStore } from "@axiom-lattice/pg-stores";
169
-
170
- // Create store without auto-migration
171
- const threadStore = new PostgreSQLThreadStore({
172
- poolConfig: process.env.DATABASE_URL || "postgresql://localhost:5432/mydb",
173
- autoMigrate: false,
174
- });
175
-
176
- // Manually run migrations when ready
177
- await threadStore.initialize();
91
+ interface StoreOptions {
92
+ poolConfig: string | PoolConfig; // Connection string or PoolConfig object
93
+ autoMigrate?: boolean; // Run migrations automatically (default: true)
94
+ }
178
95
  ```
179
96
 
180
97
  ## Migration System
181
98
 
182
- The package includes a migration system that automatically:
183
-
184
- 1. Creates the `lattice_schema_migrations` table to track applied migrations
185
- 2. Applies pending migrations in order
186
- 3. Tracks migration versions to prevent duplicate applications
187
-
188
- ### How Migrations Work
189
-
190
- Migrations run automatically when you create a store instance (unless `autoMigrate: false`):
99
+ Each store manages its own schema migrations via `MigrationManager`. Migrations run during `initialize()`.
191
100
 
192
101
  ```typescript
193
- // Migrations run automatically on initialization
194
- const threadStore = new PostgreSQLThreadStore({
102
+ // Manual control
103
+ const store = new PostgreSQLThreadStore({
195
104
  poolConfig: process.env.DATABASE_URL,
196
- autoMigrate: true, // Default: true
105
+ autoMigrate: false,
197
106
  });
198
-
199
- await threadStore.initialize(); // Migrations are applied here
107
+ await store.initialize(); // Migrations applied here
200
108
  ```
201
-
202
- ### Migration Structure
203
-
204
- Migrations are defined with:
205
-
206
- - **version**: Sequential version number (must be unique)
207
- - **name**: Descriptive migration name
208
- - **up**: Migration function to apply changes (creates/modifies tables)
209
- - **down**: Optional rollback function (for undoing migrations)
210
-
211
- ### Using MigrationManager Directly
212
-
213
- For more control, you can use `MigrationManager` directly:
214
-
215
- ```typescript
216
- import { Pool } from "pg";
217
- import { MigrationManager } from "@axiom-lattice/pg-stores";
218
- import { createThreadsTable } from "@axiom-lattice/pg-stores";
219
-
220
- const pool = new Pool({ connectionString: process.env.DATABASE_URL });
221
- const migrationManager = new MigrationManager(pool);
222
-
223
- // Register migrations
224
- migrationManager.register(createThreadsTable);
225
-
226
- // Apply pending migrations
227
- await migrationManager.migrate();
228
-
229
- // Check current version
230
- const version = await migrationManager.getCurrentVersion();
231
-
232
- // Rollback last migration (if down migration exists)
233
- await migrationManager.rollback();
234
- ```
235
-
236
- ### Current Migrations
237
-
238
- - **ThreadStore Version 1**: `create_threads_table` - Creates the threads table with indexes
239
- - **AssistantStore Version 1**: `create_assistants_table` - Creates the assistants table with indexes
240
-
241
- For detailed migration usage, see [MIGRATION_GUIDE.md](./MIGRATION_GUIDE.md).
242
-
243
- ## Database Schema
244
-
245
- ### lattice_threads Table
246
-
247
- ```sql
248
- CREATE TABLE lattice_threads (
249
- id VARCHAR(255) NOT NULL,
250
- assistant_id VARCHAR(255) NOT NULL,
251
- metadata JSONB DEFAULT '{}',
252
- created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
253
- updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
254
- PRIMARY KEY (id, assistant_id)
255
- );
256
-
257
- CREATE INDEX idx_lattice_threads_assistant_id ON lattice_threads(assistant_id);
258
- CREATE INDEX idx_lattice_threads_created_at ON lattice_threads(created_at DESC);
259
- ```
260
-
261
- ### lattice_assistants Table
262
-
263
- ```sql
264
- CREATE TABLE lattice_assistants (
265
- id VARCHAR(255) PRIMARY KEY,
266
- name VARCHAR(255) NOT NULL,
267
- description TEXT,
268
- graph_definition JSONB NOT NULL,
269
- created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
270
- updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
271
- );
272
-
273
- CREATE INDEX idx_lattice_assistants_name ON lattice_assistants(name);
274
- CREATE INDEX idx_lattice_assistants_created_at ON lattice_assistants(created_at DESC);
275
- ```
276
-
277
- ## Configuration
278
-
279
- The PostgreSQL store can be configured via:
280
-
281
- 1. **Constructor options**: Pass `poolConfig` (connection string or PoolConfig object) and `autoMigrate` directly
282
- 2. **Environment variables**:
283
- - `DATABASE_URL` - PostgreSQL connection string (recommended)
284
- - `DB_HOST` - Database host (if using PoolConfig object)
285
- - `DB_PORT` - Database port (if using PoolConfig object)
286
- - `DB_USER` - Database user (if using PoolConfig object)
287
- - `DB_PASSWORD` - Database password (if using PoolConfig object)
288
- - `DB_NAME` - Database name (if using PoolConfig object)
289
-
290
- ### PoolConfig Options
291
-
292
- You can pass either:
293
-
294
- - **Connection string**: `"postgresql://user:password@host:port/database"`
295
- - **PoolConfig object**: `{ host, port, database, user, password, ... }` (see [pg PoolConfig](https://node-postgres.com/api/pool) for all options)
296
-
297
- ## API Reference
298
-
299
- ### ThreadStore Interface
300
-
301
- ```typescript
302
- interface ThreadStore {
303
- getThreadsByAssistantId(assistantId: string): Promise<Thread[]>;
304
- getThreadById(
305
- assistantId: string,
306
- threadId: string
307
- ): Promise<Thread | undefined>;
308
- createThread(
309
- assistantId: string,
310
- threadId: string,
311
- data: CreateThreadRequest
312
- ): Promise<Thread>;
313
- updateThread(
314
- assistantId: string,
315
- threadId: string,
316
- updates: Partial<CreateThreadRequest>
317
- ): Promise<Thread | null>;
318
- deleteThread(assistantId: string, threadId: string): Promise<boolean>;
319
- hasThread(assistantId: string, threadId: string): Promise<boolean>;
320
- }
321
- ```
322
-
323
- ### AssistantStore Interface
324
-
325
- ```typescript
326
- interface AssistantStore {
327
- getAllAssistants(): Promise<Assistant[]>;
328
- getAssistantById(id: string): Promise<Assistant | undefined>;
329
- createAssistant(id: string, data: CreateAssistantRequest): Promise<Assistant>;
330
- updateAssistant(
331
- id: string,
332
- updates: Partial<CreateAssistantRequest>
333
- ): Promise<Assistant | null>;
334
- deleteAssistant(id: string): Promise<boolean>;
335
- hasAssistant(id: string): Promise<boolean>;
336
- }
337
- ```
338
-
339
- ## License
340
-
341
- MIT