@axiom-lattice/pg-stores 1.0.1

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.
@@ -0,0 +1,211 @@
1
+ import { PoolConfig, PoolClient, Pool } from 'pg';
2
+ import { ThreadStore, Thread, CreateThreadRequest, AssistantStore, Assistant, CreateAssistantRequest } from '@axiom-lattice/protocols';
3
+ export { Assistant, AssistantStore, CreateAssistantRequest, CreateThreadRequest, Thread, ThreadStore } from '@axiom-lattice/protocols';
4
+
5
+ /**
6
+ * PostgreSQL implementation of ThreadStore
7
+ */
8
+
9
+ /**
10
+ * PostgreSQL ThreadStore options
11
+ */
12
+ interface PostgreSQLThreadStoreOptions {
13
+ /**
14
+ * PostgreSQL connection pool configuration
15
+ * Can be a connection string or PoolConfig object
16
+ */
17
+ poolConfig: string | PoolConfig;
18
+ /**
19
+ * Whether to run migrations automatically on initialization
20
+ * @default true
21
+ */
22
+ autoMigrate?: boolean;
23
+ }
24
+ /**
25
+ * PostgreSQL implementation of ThreadStore
26
+ */
27
+ declare class PostgreSQLThreadStore implements ThreadStore {
28
+ private pool;
29
+ private migrationManager;
30
+ private initialized;
31
+ private ownsPool;
32
+ constructor(options: PostgreSQLThreadStoreOptions);
33
+ /**
34
+ * Dispose resources and close the connection pool
35
+ * Should be called when the store is no longer needed
36
+ */
37
+ dispose(): Promise<void>;
38
+ /**
39
+ * Initialize the store and run migrations
40
+ */
41
+ initialize(): Promise<void>;
42
+ /**
43
+ * Get all threads for a specific assistant
44
+ */
45
+ getThreadsByAssistantId(assistantId: string): Promise<Thread[]>;
46
+ /**
47
+ * Get a thread by ID for a specific assistant
48
+ */
49
+ getThreadById(assistantId: string, threadId: string): Promise<Thread | undefined>;
50
+ /**
51
+ * Create a new thread for an assistant
52
+ */
53
+ createThread(assistantId: string, threadId: string, data: CreateThreadRequest): Promise<Thread>;
54
+ /**
55
+ * Update an existing thread
56
+ */
57
+ updateThread(assistantId: string, threadId: string, updates: Partial<CreateThreadRequest>): Promise<Thread | null>;
58
+ /**
59
+ * Delete a thread by ID
60
+ */
61
+ deleteThread(assistantId: string, threadId: string): Promise<boolean>;
62
+ /**
63
+ * Check if thread exists
64
+ */
65
+ hasThread(assistantId: string, threadId: string): Promise<boolean>;
66
+ /**
67
+ * Ensure store is initialized
68
+ */
69
+ private ensureInitialized;
70
+ /**
71
+ * Map database row to Thread object
72
+ */
73
+ private mapRowToThread;
74
+ }
75
+
76
+ /**
77
+ * PostgreSQL implementation of AssistantStore
78
+ */
79
+
80
+ /**
81
+ * PostgreSQL AssistantStore options
82
+ */
83
+ interface PostgreSQLAssistantStoreOptions {
84
+ /**
85
+ * PostgreSQL connection pool configuration
86
+ * Can be a connection string or PoolConfig object
87
+ */
88
+ poolConfig: string | PoolConfig;
89
+ /**
90
+ * Whether to run migrations automatically on initialization
91
+ * @default true
92
+ */
93
+ autoMigrate?: boolean;
94
+ }
95
+ /**
96
+ * PostgreSQL implementation of AssistantStore
97
+ */
98
+ declare class PostgreSQLAssistantStore implements AssistantStore {
99
+ private pool;
100
+ private migrationManager;
101
+ private initialized;
102
+ private ownsPool;
103
+ constructor(options: PostgreSQLAssistantStoreOptions);
104
+ /**
105
+ * Initialize the store and run migrations
106
+ */
107
+ initialize(): Promise<void>;
108
+ /**
109
+ * Get all assistants
110
+ */
111
+ getAllAssistants(): Promise<Assistant[]>;
112
+ /**
113
+ * Get assistant by ID
114
+ */
115
+ getAssistantById(id: string): Promise<Assistant | null>;
116
+ /**
117
+ * Create a new assistant
118
+ */
119
+ createAssistant(id: string, data: CreateAssistantRequest): Promise<Assistant>;
120
+ /**
121
+ * Update an existing assistant
122
+ */
123
+ updateAssistant(id: string, updates: Partial<CreateAssistantRequest>): Promise<Assistant | null>;
124
+ /**
125
+ * Delete an assistant by ID
126
+ */
127
+ deleteAssistant(id: string): Promise<boolean>;
128
+ /**
129
+ * Check if assistant exists
130
+ */
131
+ hasAssistant(id: string): Promise<boolean>;
132
+ /**
133
+ * Dispose resources and close the connection pool
134
+ * Should be called when the store is no longer needed
135
+ */
136
+ dispose(): Promise<void>;
137
+ /**
138
+ * Ensure store is initialized
139
+ */
140
+ private ensureInitialized;
141
+ /**
142
+ * Map database row to Assistant object
143
+ */
144
+ private mapRowToAssistant;
145
+ }
146
+
147
+ /**
148
+ * Migration system for database schema management
149
+ */
150
+
151
+ /**
152
+ * Migration definition
153
+ */
154
+ interface Migration {
155
+ version: number;
156
+ name: string;
157
+ up: (client: PoolClient) => Promise<void>;
158
+ down?: (client: PoolClient) => Promise<void>;
159
+ }
160
+ /**
161
+ * Migration manager
162
+ */
163
+ declare class MigrationManager {
164
+ private pool;
165
+ private migrations;
166
+ constructor(pool: Pool);
167
+ /**
168
+ * Register a migration
169
+ */
170
+ register(migration: Migration): void;
171
+ /**
172
+ * Initialize migrations table if it doesn't exist
173
+ */
174
+ private ensureMigrationsTable;
175
+ /**
176
+ * Get applied migrations from database
177
+ */
178
+ private getAppliedMigrations;
179
+ /**
180
+ * Apply pending migrations
181
+ */
182
+ migrate(): Promise<void>;
183
+ /**
184
+ * Rollback last migration
185
+ */
186
+ rollback(): Promise<void>;
187
+ /**
188
+ * Get current migration version
189
+ */
190
+ getCurrentVersion(): Promise<number>;
191
+ }
192
+
193
+ /**
194
+ * Thread table migrations
195
+ */
196
+
197
+ /**
198
+ * Initial migration: Create threads table
199
+ */
200
+ declare const createThreadsTable: Migration;
201
+
202
+ /**
203
+ * Assistant table migrations
204
+ */
205
+
206
+ /**
207
+ * Initial migration: Create assistants table
208
+ */
209
+ declare const createAssistantsTable: Migration;
210
+
211
+ export { type Migration, MigrationManager, PostgreSQLAssistantStore, type PostgreSQLAssistantStoreOptions, PostgreSQLThreadStore, type PostgreSQLThreadStoreOptions, createAssistantsTable, createThreadsTable };