@llmops/sdk 1.0.0-beta.3 → 1.0.0-beta.4
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/dist/store/pg.cjs +43 -439
- package/dist/store/pg.d.cts +15 -569
- package/dist/store/pg.d.mts +15 -569
- package/dist/store/pg.mjs +44 -431
- package/package.json +11 -3
package/dist/store/pg.mjs
CHANGED
|
@@ -1,433 +1,46 @@
|
|
|
1
1
|
import { createPgStore as pgStore } from "@llmops/core";
|
|
2
2
|
|
|
3
|
-
//#region src/store/pg/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"cacheSavings": { "type": "integer" },
|
|
48
|
-
"inputCost": { "type": "integer" },
|
|
49
|
-
"outputCost": { "type": "integer" },
|
|
50
|
-
"endpoint": {
|
|
51
|
-
"type": "string",
|
|
52
|
-
"maxLength": 255
|
|
53
|
-
},
|
|
54
|
-
"statusCode": { "type": "integer" },
|
|
55
|
-
"latencyMs": { "type": "integer" },
|
|
56
|
-
"isStreaming": { "type": "boolean" },
|
|
57
|
-
"userId": {
|
|
58
|
-
"type": ["string", "null"],
|
|
59
|
-
"maxLength": 255
|
|
60
|
-
},
|
|
61
|
-
"tags": { "type": "object" },
|
|
62
|
-
"guardrailResults": { "type": ["object", "null"] },
|
|
63
|
-
"traceId": {
|
|
64
|
-
"type": ["string", "null"],
|
|
65
|
-
"maxLength": 255
|
|
66
|
-
},
|
|
67
|
-
"spanId": {
|
|
68
|
-
"type": ["string", "null"],
|
|
69
|
-
"maxLength": 255
|
|
70
|
-
},
|
|
71
|
-
"parentSpanId": {
|
|
72
|
-
"type": ["string", "null"],
|
|
73
|
-
"maxLength": 255
|
|
74
|
-
},
|
|
75
|
-
"sessionId": {
|
|
76
|
-
"type": ["string", "null"],
|
|
77
|
-
"maxLength": 255
|
|
78
|
-
},
|
|
79
|
-
"createdAt": {
|
|
80
|
-
"type": "string",
|
|
81
|
-
"format": "date-time"
|
|
82
|
-
},
|
|
83
|
-
"updatedAt": {
|
|
84
|
-
"type": "string",
|
|
85
|
-
"format": "date-time"
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
"required": [
|
|
89
|
-
"id",
|
|
90
|
-
"requestId",
|
|
91
|
-
"provider",
|
|
92
|
-
"model",
|
|
93
|
-
"promptTokens",
|
|
94
|
-
"completionTokens",
|
|
95
|
-
"totalTokens",
|
|
96
|
-
"cachedTokens",
|
|
97
|
-
"cacheCreationTokens",
|
|
98
|
-
"cost",
|
|
99
|
-
"cacheSavings",
|
|
100
|
-
"inputCost",
|
|
101
|
-
"outputCost",
|
|
102
|
-
"endpoint",
|
|
103
|
-
"statusCode",
|
|
104
|
-
"latencyMs",
|
|
105
|
-
"isStreaming",
|
|
106
|
-
"tags",
|
|
107
|
-
"createdAt",
|
|
108
|
-
"updatedAt"
|
|
109
|
-
],
|
|
110
|
-
"additionalProperties": false
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
//#endregion
|
|
114
|
-
//#region src/store/pg/generated/span_events.ts
|
|
115
|
-
const SpanEventsSchema = {
|
|
116
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
117
|
-
"title": "SpanEvents",
|
|
118
|
-
"type": "object",
|
|
119
|
-
"properties": {
|
|
120
|
-
"id": {
|
|
121
|
-
"type": "string",
|
|
122
|
-
"format": "uuid"
|
|
123
|
-
},
|
|
124
|
-
"traceId": {
|
|
125
|
-
"type": "string",
|
|
126
|
-
"maxLength": 255
|
|
127
|
-
},
|
|
128
|
-
"spanId": {
|
|
129
|
-
"type": "string",
|
|
130
|
-
"maxLength": 255
|
|
131
|
-
},
|
|
132
|
-
"name": {
|
|
133
|
-
"type": "string",
|
|
134
|
-
"maxLength": 255
|
|
135
|
-
},
|
|
136
|
-
"timestamp": {
|
|
137
|
-
"type": "string",
|
|
138
|
-
"format": "date-time"
|
|
139
|
-
},
|
|
140
|
-
"attributes": { "type": "object" },
|
|
141
|
-
"createdAt": {
|
|
142
|
-
"type": "string",
|
|
143
|
-
"format": "date-time"
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
"required": [
|
|
147
|
-
"id",
|
|
148
|
-
"traceId",
|
|
149
|
-
"spanId",
|
|
150
|
-
"name",
|
|
151
|
-
"timestamp",
|
|
152
|
-
"attributes",
|
|
153
|
-
"createdAt"
|
|
154
|
-
],
|
|
155
|
-
"additionalProperties": false
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
//#endregion
|
|
159
|
-
//#region src/store/pg/generated/spans.ts
|
|
160
|
-
const SpansSchema = {
|
|
161
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
162
|
-
"title": "Spans",
|
|
163
|
-
"type": "object",
|
|
164
|
-
"properties": {
|
|
165
|
-
"id": {
|
|
166
|
-
"type": "string",
|
|
167
|
-
"format": "uuid"
|
|
168
|
-
},
|
|
169
|
-
"traceId": {
|
|
170
|
-
"type": "string",
|
|
171
|
-
"maxLength": 255
|
|
172
|
-
},
|
|
173
|
-
"spanId": {
|
|
174
|
-
"type": "string",
|
|
175
|
-
"maxLength": 255
|
|
176
|
-
},
|
|
177
|
-
"parentSpanId": {
|
|
178
|
-
"type": ["string", "null"],
|
|
179
|
-
"maxLength": 255
|
|
180
|
-
},
|
|
181
|
-
"name": {
|
|
182
|
-
"type": "string",
|
|
183
|
-
"maxLength": 255
|
|
184
|
-
},
|
|
185
|
-
"kind": { "type": "integer" },
|
|
186
|
-
"status": { "type": "integer" },
|
|
187
|
-
"statusMessage": { "type": ["string", "null"] },
|
|
188
|
-
"startTime": {
|
|
189
|
-
"type": "string",
|
|
190
|
-
"format": "date-time"
|
|
191
|
-
},
|
|
192
|
-
"endTime": {
|
|
193
|
-
"type": ["string", "null"],
|
|
194
|
-
"format": "date-time"
|
|
195
|
-
},
|
|
196
|
-
"durationMs": { "type": ["integer", "null"] },
|
|
197
|
-
"provider": {
|
|
198
|
-
"type": ["string", "null"],
|
|
199
|
-
"maxLength": 255
|
|
200
|
-
},
|
|
201
|
-
"model": {
|
|
202
|
-
"type": ["string", "null"],
|
|
203
|
-
"maxLength": 255
|
|
204
|
-
},
|
|
205
|
-
"promptTokens": { "type": "integer" },
|
|
206
|
-
"completionTokens": { "type": "integer" },
|
|
207
|
-
"totalTokens": { "type": "integer" },
|
|
208
|
-
"cost": { "type": "integer" },
|
|
209
|
-
"configId": {
|
|
210
|
-
"type": ["string", "null"],
|
|
211
|
-
"format": "uuid"
|
|
212
|
-
},
|
|
213
|
-
"variantId": {
|
|
214
|
-
"type": ["string", "null"],
|
|
215
|
-
"format": "uuid"
|
|
216
|
-
},
|
|
217
|
-
"environmentId": {
|
|
218
|
-
"type": ["string", "null"],
|
|
219
|
-
"format": "uuid"
|
|
220
|
-
},
|
|
221
|
-
"providerConfigId": {
|
|
222
|
-
"type": ["string", "null"],
|
|
223
|
-
"format": "uuid"
|
|
224
|
-
},
|
|
225
|
-
"requestId": {
|
|
226
|
-
"type": ["string", "null"],
|
|
227
|
-
"format": "uuid"
|
|
228
|
-
},
|
|
229
|
-
"source": {
|
|
230
|
-
"type": "string",
|
|
231
|
-
"maxLength": 50
|
|
232
|
-
},
|
|
233
|
-
"input": { "type": ["object", "null"] },
|
|
234
|
-
"output": { "type": ["object", "null"] },
|
|
235
|
-
"attributes": { "type": "object" },
|
|
236
|
-
"createdAt": {
|
|
237
|
-
"type": "string",
|
|
238
|
-
"format": "date-time"
|
|
239
|
-
},
|
|
240
|
-
"updatedAt": {
|
|
241
|
-
"type": "string",
|
|
242
|
-
"format": "date-time"
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
"required": [
|
|
246
|
-
"id",
|
|
247
|
-
"traceId",
|
|
248
|
-
"spanId",
|
|
249
|
-
"name",
|
|
250
|
-
"kind",
|
|
251
|
-
"status",
|
|
252
|
-
"startTime",
|
|
253
|
-
"promptTokens",
|
|
254
|
-
"completionTokens",
|
|
255
|
-
"totalTokens",
|
|
256
|
-
"cost",
|
|
257
|
-
"source",
|
|
258
|
-
"attributes",
|
|
259
|
-
"createdAt",
|
|
260
|
-
"updatedAt"
|
|
261
|
-
],
|
|
262
|
-
"additionalProperties": false
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
//#endregion
|
|
266
|
-
//#region src/store/pg/generated/traces.ts
|
|
267
|
-
const TracesSchema = {
|
|
268
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
269
|
-
"title": "Traces",
|
|
270
|
-
"type": "object",
|
|
271
|
-
"properties": {
|
|
272
|
-
"id": {
|
|
273
|
-
"type": "string",
|
|
274
|
-
"format": "uuid"
|
|
275
|
-
},
|
|
276
|
-
"traceId": {
|
|
277
|
-
"type": "string",
|
|
278
|
-
"maxLength": 255
|
|
279
|
-
},
|
|
280
|
-
"name": {
|
|
281
|
-
"type": ["string", "null"],
|
|
282
|
-
"maxLength": 255
|
|
283
|
-
},
|
|
284
|
-
"sessionId": {
|
|
285
|
-
"type": ["string", "null"],
|
|
286
|
-
"maxLength": 255
|
|
287
|
-
},
|
|
288
|
-
"userId": {
|
|
289
|
-
"type": ["string", "null"],
|
|
290
|
-
"maxLength": 255
|
|
291
|
-
},
|
|
292
|
-
"status": {
|
|
293
|
-
"type": "string",
|
|
294
|
-
"maxLength": 50
|
|
295
|
-
},
|
|
296
|
-
"startTime": {
|
|
297
|
-
"type": "string",
|
|
298
|
-
"format": "date-time"
|
|
299
|
-
},
|
|
300
|
-
"endTime": {
|
|
301
|
-
"type": ["string", "null"],
|
|
302
|
-
"format": "date-time"
|
|
303
|
-
},
|
|
304
|
-
"durationMs": { "type": ["integer", "null"] },
|
|
305
|
-
"spanCount": { "type": "integer" },
|
|
306
|
-
"totalInputTokens": { "type": "integer" },
|
|
307
|
-
"totalOutputTokens": { "type": "integer" },
|
|
308
|
-
"totalTokens": { "type": "integer" },
|
|
309
|
-
"totalCost": { "type": "integer" },
|
|
310
|
-
"tags": { "type": "object" },
|
|
311
|
-
"metadata": { "type": "object" },
|
|
312
|
-
"createdAt": {
|
|
313
|
-
"type": "string",
|
|
314
|
-
"format": "date-time"
|
|
315
|
-
},
|
|
316
|
-
"updatedAt": {
|
|
317
|
-
"type": "string",
|
|
318
|
-
"format": "date-time"
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
"required": [
|
|
322
|
-
"id",
|
|
323
|
-
"traceId",
|
|
324
|
-
"status",
|
|
325
|
-
"startTime",
|
|
326
|
-
"spanCount",
|
|
327
|
-
"totalInputTokens",
|
|
328
|
-
"totalOutputTokens",
|
|
329
|
-
"totalTokens",
|
|
330
|
-
"totalCost",
|
|
331
|
-
"tags",
|
|
332
|
-
"metadata",
|
|
333
|
-
"createdAt",
|
|
334
|
-
"updatedAt"
|
|
335
|
-
],
|
|
336
|
-
"additionalProperties": false
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
//#endregion
|
|
340
|
-
//#region src/store/pg/queries/gen/getCostByModel.ts
|
|
341
|
-
const GetCostByModelParamsSchema = {
|
|
342
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
343
|
-
"title": "GetCostByModelParams",
|
|
344
|
-
"type": "object",
|
|
345
|
-
"properties": {
|
|
346
|
-
"start_date": { "type": "string" },
|
|
347
|
-
"end_date": { "type": "string" }
|
|
348
|
-
},
|
|
349
|
-
"required": ["start_date", "end_date"],
|
|
350
|
-
"additionalProperties": false
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
//#endregion
|
|
354
|
-
//#region src/store/pg/queries/gen/getCostByProvider.ts
|
|
355
|
-
const GetCostByProviderParamsSchema = {
|
|
356
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
357
|
-
"title": "GetCostByProviderParams",
|
|
358
|
-
"type": "object",
|
|
359
|
-
"properties": {
|
|
360
|
-
"start_date": { "type": "string" },
|
|
361
|
-
"end_date": { "type": "string" }
|
|
362
|
-
},
|
|
363
|
-
"required": ["start_date", "end_date"],
|
|
364
|
-
"additionalProperties": false
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
//#endregion
|
|
368
|
-
//#region src/store/pg/queries/gen/getDailyCosts.ts
|
|
369
|
-
const GetDailyCostsParamsSchema = {
|
|
370
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
371
|
-
"title": "GetDailyCostsParams",
|
|
372
|
-
"type": "object",
|
|
373
|
-
"properties": {
|
|
374
|
-
"start_date": { "type": "string" },
|
|
375
|
-
"end_date": { "type": "string" }
|
|
376
|
-
},
|
|
377
|
-
"required": ["start_date", "end_date"],
|
|
378
|
-
"additionalProperties": false
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
//#endregion
|
|
382
|
-
//#region src/store/pg/queries/gen/getRequestByRequestId.ts
|
|
383
|
-
const GetRequestByRequestIdParamsSchema = {
|
|
384
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
385
|
-
"title": "GetRequestByRequestIdParams",
|
|
386
|
-
"type": "object",
|
|
387
|
-
"properties": { "request_id": { "type": "string" } },
|
|
388
|
-
"required": ["request_id"],
|
|
389
|
-
"additionalProperties": false
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
//#endregion
|
|
393
|
-
//#region src/store/pg/queries/gen/getRequestStats.ts
|
|
394
|
-
const GetRequestStatsParamsSchema = {
|
|
395
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
396
|
-
"title": "GetRequestStatsParams",
|
|
397
|
-
"type": "object",
|
|
398
|
-
"properties": {
|
|
399
|
-
"start_date": { "type": "string" },
|
|
400
|
-
"end_date": { "type": "string" },
|
|
401
|
-
"config_id": { "type": "string" },
|
|
402
|
-
"variant_id": { "type": "string" },
|
|
403
|
-
"environment_id": { "type": "string" }
|
|
404
|
-
},
|
|
405
|
-
"required": [
|
|
406
|
-
"start_date",
|
|
407
|
-
"end_date",
|
|
408
|
-
"config_id",
|
|
409
|
-
"variant_id",
|
|
410
|
-
"environment_id"
|
|
411
|
-
],
|
|
412
|
-
"additionalProperties": false
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
//#endregion
|
|
416
|
-
//#region src/store/pg/queries/gen/getTotalCost.ts
|
|
417
|
-
const GetTotalCostParamsSchema = {
|
|
418
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
419
|
-
"title": "GetTotalCostParams",
|
|
420
|
-
"type": "object",
|
|
421
|
-
"properties": {
|
|
422
|
-
"start_date": { "type": "string" },
|
|
423
|
-
"end_date": {
|
|
424
|
-
"type": "string",
|
|
425
|
-
"format": "date-time"
|
|
426
|
-
}
|
|
427
|
-
},
|
|
428
|
-
"required": ["start_date", "end_date"],
|
|
429
|
-
"additionalProperties": false
|
|
430
|
-
};
|
|
431
|
-
|
|
432
|
-
//#endregion
|
|
433
|
-
export { GetCostByModelParamsSchema, GetCostByProviderParamsSchema, GetDailyCostsParamsSchema, GetRequestByRequestIdParamsSchema, GetRequestStatsParamsSchema, GetTotalCostParamsSchema, LlmRequestsSchema, SpanEventsSchema, SpansSchema, TracesSchema, pgStore };
|
|
3
|
+
//#region src/store/pg/migrations/000001_2191b051.sql
|
|
4
|
+
var _000001_2191b051_default = "BEGIN;\n\nCREATE TABLE llm_requests (\n id UUID PRIMARY KEY,\n \"requestId\" UUID NOT NULL,\n \"configId\" UUID,\n \"variantId\" UUID,\n \"environmentId\" UUID,\n \"providerConfigId\" UUID,\n provider VARCHAR(255) NOT NULL,\n model VARCHAR(255) NOT NULL,\n \"promptTokens\" INTEGER NOT NULL DEFAULT 0,\n \"completionTokens\" INTEGER NOT NULL DEFAULT 0,\n \"totalTokens\" INTEGER NOT NULL DEFAULT 0,\n \"cachedTokens\" INTEGER NOT NULL DEFAULT 0,\n \"cacheCreationTokens\" INTEGER NOT NULL DEFAULT 0,\n cost INTEGER NOT NULL DEFAULT 0,\n \"cacheSavings\" INTEGER NOT NULL DEFAULT 0,\n \"inputCost\" INTEGER NOT NULL DEFAULT 0,\n \"outputCost\" INTEGER NOT NULL DEFAULT 0,\n endpoint VARCHAR(255) NOT NULL,\n \"statusCode\" INTEGER NOT NULL,\n \"latencyMs\" INTEGER NOT NULL DEFAULT 0,\n \"isStreaming\" BOOLEAN NOT NULL DEFAULT false,\n \"userId\" VARCHAR(255),\n tags JSONB NOT NULL DEFAULT '{}'::jsonb,\n \"guardrailResults\" JSONB,\n \"traceId\" VARCHAR(255),\n \"spanId\" VARCHAR(255),\n \"parentSpanId\" VARCHAR(255),\n \"sessionId\" VARCHAR(255),\n \"createdAt\" TIMESTAMP NOT NULL DEFAULT NOW(),\n \"updatedAt\" TIMESTAMP NOT NULL DEFAULT NOW()\n);\n\nCREATE TABLE span_events (\n id UUID PRIMARY KEY,\n \"traceId\" VARCHAR(255) NOT NULL,\n \"spanId\" VARCHAR(255) NOT NULL,\n name VARCHAR(255) NOT NULL,\n timestamp TIMESTAMP NOT NULL,\n attributes JSONB NOT NULL DEFAULT '{}'::jsonb,\n \"createdAt\" TIMESTAMP NOT NULL DEFAULT NOW()\n);\n\nCREATE TABLE spans (\n id UUID PRIMARY KEY,\n \"traceId\" VARCHAR(255) NOT NULL,\n \"spanId\" VARCHAR(255) NOT NULL UNIQUE,\n \"parentSpanId\" VARCHAR(255),\n name VARCHAR(255) NOT NULL,\n kind INTEGER NOT NULL DEFAULT 1,\n status INTEGER NOT NULL DEFAULT 0,\n \"statusMessage\" TEXT,\n \"startTime\" TIMESTAMP NOT NULL,\n \"endTime\" TIMESTAMP,\n \"durationMs\" INTEGER,\n provider VARCHAR(255),\n model VARCHAR(255),\n \"promptTokens\" INTEGER NOT NULL DEFAULT 0,\n \"completionTokens\" INTEGER NOT NULL DEFAULT 0,\n \"totalTokens\" INTEGER NOT NULL DEFAULT 0,\n cost INTEGER NOT NULL DEFAULT 0,\n \"configId\" UUID,\n \"variantId\" UUID,\n \"environmentId\" UUID,\n \"providerConfigId\" UUID,\n \"requestId\" UUID,\n source VARCHAR(50) NOT NULL DEFAULT 'gateway',\n input JSONB,\n output JSONB,\n attributes JSONB NOT NULL DEFAULT '{}'::jsonb,\n \"createdAt\" TIMESTAMP NOT NULL DEFAULT NOW(),\n \"updatedAt\" TIMESTAMP NOT NULL DEFAULT NOW()\n);\n\nCREATE TABLE traces (\n id UUID PRIMARY KEY,\n \"traceId\" VARCHAR(255) NOT NULL UNIQUE,\n name VARCHAR(255),\n \"sessionId\" VARCHAR(255),\n \"userId\" VARCHAR(255),\n status VARCHAR(50) NOT NULL DEFAULT 'unset',\n \"startTime\" TIMESTAMP NOT NULL,\n \"endTime\" TIMESTAMP,\n \"durationMs\" INTEGER,\n \"spanCount\" INTEGER NOT NULL DEFAULT 0,\n \"totalInputTokens\" INTEGER NOT NULL DEFAULT 0,\n \"totalOutputTokens\" INTEGER NOT NULL DEFAULT 0,\n \"totalTokens\" INTEGER NOT NULL DEFAULT 0,\n \"totalCost\" INTEGER NOT NULL DEFAULT 0,\n tags JSONB NOT NULL DEFAULT '{}'::jsonb,\n metadata JSONB NOT NULL DEFAULT '{}'::jsonb,\n \"createdAt\" TIMESTAMP NOT NULL DEFAULT NOW(),\n \"updatedAt\" TIMESTAMP NOT NULL DEFAULT NOW()\n);\n\nCOMMIT;\n";
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/store/pg/migrations/index.ts
|
|
8
|
+
/**
|
|
9
|
+
* Migration registry — imports are inlined at build time by the sql-loader plugin.
|
|
10
|
+
* Each entry is a [name, sql] tuple, ordered by filename.
|
|
11
|
+
*/
|
|
12
|
+
const migrations = [["000001_2191b051", _000001_2191b051_default]];
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/store/pg/migrate.ts
|
|
16
|
+
const MIGRATIONS_TABLE = `
|
|
17
|
+
CREATE TABLE IF NOT EXISTS _llmops_migrations (
|
|
18
|
+
name TEXT PRIMARY KEY,
|
|
19
|
+
applied_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
20
|
+
)
|
|
21
|
+
`;
|
|
22
|
+
/**
|
|
23
|
+
* Run pending migrations against the database.
|
|
24
|
+
*
|
|
25
|
+
* - Creates the _llmops_migrations tracking table if it doesn't exist
|
|
26
|
+
* - Skips already-applied migrations
|
|
27
|
+
* - Applies new migrations in order
|
|
28
|
+
*/
|
|
29
|
+
async function runMigrations(pool, schema) {
|
|
30
|
+
await pool.query(`CREATE SCHEMA IF NOT EXISTS "${schema}"`);
|
|
31
|
+
await pool.query(`SET search_path TO "${schema}"`);
|
|
32
|
+
await pool.query(MIGRATIONS_TABLE);
|
|
33
|
+
const { rows } = await pool.query("SELECT name FROM _llmops_migrations ORDER BY name");
|
|
34
|
+
const applied = new Set(rows.map((r) => r.name));
|
|
35
|
+
const newlyApplied = [];
|
|
36
|
+
for (const [name, sql] of migrations) {
|
|
37
|
+
if (applied.has(name)) continue;
|
|
38
|
+
await pool.query(sql);
|
|
39
|
+
await pool.query("INSERT INTO _llmops_migrations (name) VALUES ($1)", [name]);
|
|
40
|
+
newlyApplied.push(name);
|
|
41
|
+
}
|
|
42
|
+
return { applied: newlyApplied };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { pgStore, runMigrations };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llmops/sdk",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.4",
|
|
4
4
|
"description": "An LLMOps toolkit for TypeScript applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -104,8 +104,16 @@
|
|
|
104
104
|
"access": "public"
|
|
105
105
|
},
|
|
106
106
|
"dependencies": {
|
|
107
|
-
"@llmops/
|
|
108
|
-
"@llmops/
|
|
107
|
+
"@llmops/app": "^1.0.0-beta.4",
|
|
108
|
+
"@llmops/core": "^1.0.0-beta.4"
|
|
109
|
+
},
|
|
110
|
+
"peerDependencies": {
|
|
111
|
+
"pg": "*"
|
|
112
|
+
},
|
|
113
|
+
"peerDependenciesMeta": {
|
|
114
|
+
"pg": {
|
|
115
|
+
"optional": true
|
|
116
|
+
}
|
|
109
117
|
},
|
|
110
118
|
"devDependencies": {
|
|
111
119
|
"@tsqx/cli": "^0.0.4",
|