@llmops/sdk 1.0.0-beta.2 → 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,8 +1,52 @@
1
1
  let __llmops_core = require("@llmops/core");
2
2
 
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
3
46
  Object.defineProperty(exports, 'pgStore', {
4
47
  enumerable: true,
5
48
  get: function () {
6
49
  return __llmops_core.createPgStore;
7
50
  }
8
- });
51
+ });
52
+ exports.runMigrations = runMigrations;
@@ -1,2 +1,17 @@
1
1
  import { PgStore, createPgStore as pgStore } from "@llmops/core";
2
- export { type PgStore, pgStore };
2
+ import { Pool } from "pg";
3
+
4
+ //#region src/store/pg/migrate.d.ts
5
+
6
+ /**
7
+ * Run pending migrations against the database.
8
+ *
9
+ * - Creates the _llmops_migrations tracking table if it doesn't exist
10
+ * - Skips already-applied migrations
11
+ * - Applies new migrations in order
12
+ */
13
+ declare function runMigrations(pool: Pool, schema: string): Promise<{
14
+ applied: string[];
15
+ }>;
16
+ //#endregion
17
+ export { type PgStore, pgStore, runMigrations };
@@ -1,2 +1,17 @@
1
1
  import { PgStore, createPgStore as pgStore } from "@llmops/core";
2
- export { type PgStore, pgStore };
2
+ import { Pool } from "pg";
3
+
4
+ //#region src/store/pg/migrate.d.ts
5
+
6
+ /**
7
+ * Run pending migrations against the database.
8
+ *
9
+ * - Creates the _llmops_migrations tracking table if it doesn't exist
10
+ * - Skips already-applied migrations
11
+ * - Applies new migrations in order
12
+ */
13
+ declare function runMigrations(pool: Pool, schema: string): Promise<{
14
+ applied: string[];
15
+ }>;
16
+ //#endregion
17
+ export { type PgStore, pgStore, runMigrations };
package/dist/store/pg.mjs CHANGED
@@ -1,3 +1,46 @@
1
1
  import { createPgStore as pgStore } from "@llmops/core";
2
2
 
3
- export { 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.2",
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,11 +104,22 @@
104
104
  "access": "public"
105
105
  },
106
106
  "dependencies": {
107
- "@llmops/app": "^1.0.0-beta.2",
108
- "@llmops/core": "^1.0.0-beta.2"
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": {
119
+ "@tsqx/cli": "^0.0.4",
120
+ "@tsqx/kit": "^0.0.4",
111
121
  "@types/express": "^5.0.6",
122
+ "@types/pg": "^8.15.6",
112
123
  "hono": "^4.7.0"
113
124
  },
114
125
  "scripts": {