@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 CHANGED
@@ -1,448 +1,52 @@
1
1
  let __llmops_core = require("@llmops/core");
2
2
 
3
- //#region src/store/pg/generated/llm_requests.ts
4
- const LlmRequestsSchema = {
5
- "$schema": "https://json-schema.org/draft/2020-12/schema",
6
- "title": "LlmRequests",
7
- "type": "object",
8
- "properties": {
9
- "id": {
10
- "type": "string",
11
- "format": "uuid"
12
- },
13
- "requestId": {
14
- "type": "string",
15
- "format": "uuid"
16
- },
17
- "configId": {
18
- "type": ["string", "null"],
19
- "format": "uuid"
20
- },
21
- "variantId": {
22
- "type": ["string", "null"],
23
- "format": "uuid"
24
- },
25
- "environmentId": {
26
- "type": ["string", "null"],
27
- "format": "uuid"
28
- },
29
- "providerConfigId": {
30
- "type": ["string", "null"],
31
- "format": "uuid"
32
- },
33
- "provider": {
34
- "type": "string",
35
- "maxLength": 255
36
- },
37
- "model": {
38
- "type": "string",
39
- "maxLength": 255
40
- },
41
- "promptTokens": { "type": "integer" },
42
- "completionTokens": { "type": "integer" },
43
- "totalTokens": { "type": "integer" },
44
- "cachedTokens": { "type": "integer" },
45
- "cacheCreationTokens": { "type": "integer" },
46
- "cost": { "type": "integer" },
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
- };
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
+ }
112
44
 
113
45
  //#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
- exports.GetCostByModelParamsSchema = GetCostByModelParamsSchema;
434
- exports.GetCostByProviderParamsSchema = GetCostByProviderParamsSchema;
435
- exports.GetDailyCostsParamsSchema = GetDailyCostsParamsSchema;
436
- exports.GetRequestByRequestIdParamsSchema = GetRequestByRequestIdParamsSchema;
437
- exports.GetRequestStatsParamsSchema = GetRequestStatsParamsSchema;
438
- exports.GetTotalCostParamsSchema = GetTotalCostParamsSchema;
439
- exports.LlmRequestsSchema = LlmRequestsSchema;
440
- exports.SpanEventsSchema = SpanEventsSchema;
441
- exports.SpansSchema = SpansSchema;
442
- exports.TracesSchema = TracesSchema;
443
46
  Object.defineProperty(exports, 'pgStore', {
444
47
  enumerable: true,
445
48
  get: function () {
446
49
  return __llmops_core.createPgStore;
447
50
  }
448
- });
51
+ });
52
+ exports.runMigrations = runMigrations;