@llmops/core 0.1.0-beta.8 → 0.1.0
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/bun-sqlite-dialect-BY9UbL3J.cjs +156 -0
- package/dist/db/index.cjs +21 -0
- package/dist/db/index.d.cts +2 -0
- package/dist/db/index.d.mts +2 -2
- package/dist/db/index.mjs +2 -2
- package/dist/db-16I7_mus.cjs +13236 -0
- package/dist/{db-D9v8S6D5.mjs → db-DCfAacY7.mjs} +300 -30
- package/dist/{index-D59q8KmB.d.mts → index-9HhrwwZi.d.cts} +57 -24
- package/dist/index-BKx9C2tK.d.mts +859 -0
- package/dist/index.cjs +1383 -0
- package/dist/index.d.cts +2075 -0
- package/dist/index.d.mts +321 -310
- package/dist/index.mjs +4 -8
- package/dist/node-sqlite-dialect-CuJrXyHn.cjs +156 -0
- package/package.json +23 -5
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { A as string, C as any, D as number, E as literal, M as unknown, O as object, S as _enum, T as boolean, _ as schemas, a as matchType, b as variantsSchema, c as parsePartialTableData, d as validateTableData, f as SCHEMA_METADATA, g as environmentsSchema, h as environmentSecretsSchema, i as getMigrations, j as union, k as record, l as parseTableData, m as configsSchema, n as createDatabaseFromConnection, o as runAutoMigrations, p as configVariantsSchema, r as detectDatabaseType, s as logger, t as createDatabase, u as validatePartialTableData, v as targetingRulesSchema, w as array, x as zod_default, y as variantVersionsSchema } from "./db-DCfAacY7.mjs";
|
|
2
2
|
import gateway from "@llmops/gateway";
|
|
3
|
-
import pino from "pino";
|
|
4
3
|
import { createRandomStringGenerator } from "@better-auth/utils/random";
|
|
5
4
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
6
5
|
|
|
@@ -448,7 +447,8 @@ const llmopsConfigSchema = object({
|
|
|
448
447
|
database: any(),
|
|
449
448
|
auth: authSchema,
|
|
450
449
|
basePath: string().min(1, "Base path is required and cannot be empty").refine((path) => path.startsWith("/"), "Base path must start with a forward slash"),
|
|
451
|
-
providers: providersSchema
|
|
450
|
+
providers: providersSchema,
|
|
451
|
+
autoMigrate: union([boolean(), literal("development")]).optional().default(false)
|
|
452
452
|
});
|
|
453
453
|
function validateLLMOpsConfig(config) {
|
|
454
454
|
const result = llmopsConfigSchema.safeParse(config);
|
|
@@ -459,10 +459,6 @@ function validateLLMOpsConfig(config) {
|
|
|
459
459
|
return result.data;
|
|
460
460
|
}
|
|
461
461
|
|
|
462
|
-
//#endregion
|
|
463
|
-
//#region src/utils/logger.ts
|
|
464
|
-
const logger = pino();
|
|
465
|
-
|
|
466
462
|
//#endregion
|
|
467
463
|
//#region src/utils/id.ts
|
|
468
464
|
const generateId = (size) => {
|
|
@@ -1351,4 +1347,4 @@ const createDataLayer = async (db) => {
|
|
|
1351
1347
|
};
|
|
1352
1348
|
|
|
1353
1349
|
//#endregion
|
|
1354
|
-
export { SCHEMA_METADATA, SupportedProviders, chatCompletionCreateParamsBaseSchema, configVariantsSchema, configsSchema, createDataLayer, createDatabase, createDatabaseFromConnection, detectDatabaseType, environmentSecretsSchema, environmentsSchema, gateway, generateId, llmopsConfigSchema, logger, parsePartialTableData, parseTableData, schemas, targetingRulesSchema, validateLLMOpsConfig, validatePartialTableData, validateTableData, variantJsonDataSchema, variantVersionsSchema, variantsSchema };
|
|
1350
|
+
export { SCHEMA_METADATA, SupportedProviders, chatCompletionCreateParamsBaseSchema, configVariantsSchema, configsSchema, createDataLayer, createDatabase, createDatabaseFromConnection, detectDatabaseType, environmentSecretsSchema, environmentsSchema, gateway, generateId, getMigrations, llmopsConfigSchema, logger, matchType, parsePartialTableData, parseTableData, runAutoMigrations, schemas, targetingRulesSchema, validateLLMOpsConfig, validatePartialTableData, validateTableData, variantJsonDataSchema, variantVersionsSchema, variantsSchema };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
const require_db = require('./db-16I7_mus.cjs');
|
|
2
|
+
let kysely = require("kysely");
|
|
3
|
+
|
|
4
|
+
//#region src/db/node-sqlite-dialect.ts
|
|
5
|
+
var NodeSqliteAdapter = class {
|
|
6
|
+
get supportsCreateIfNotExists() {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
get supportsTransactionalDdl() {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
get supportsReturning() {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
async acquireMigrationLock() {}
|
|
16
|
+
async releaseMigrationLock() {}
|
|
17
|
+
get supportsOutput() {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var NodeSqliteDriver = class {
|
|
22
|
+
#config;
|
|
23
|
+
#connectionMutex = new ConnectionMutex();
|
|
24
|
+
#db;
|
|
25
|
+
#connection;
|
|
26
|
+
constructor(config) {
|
|
27
|
+
this.#config = { ...config };
|
|
28
|
+
}
|
|
29
|
+
async init() {
|
|
30
|
+
this.#db = this.#config.database;
|
|
31
|
+
this.#connection = new NodeSqliteConnection(this.#db);
|
|
32
|
+
if (this.#config.onCreateConnection) await this.#config.onCreateConnection(this.#connection);
|
|
33
|
+
}
|
|
34
|
+
async acquireConnection() {
|
|
35
|
+
await this.#connectionMutex.lock();
|
|
36
|
+
return this.#connection;
|
|
37
|
+
}
|
|
38
|
+
async beginTransaction(connection) {
|
|
39
|
+
await connection.executeQuery(kysely.CompiledQuery.raw("begin"));
|
|
40
|
+
}
|
|
41
|
+
async commitTransaction(connection) {
|
|
42
|
+
await connection.executeQuery(kysely.CompiledQuery.raw("commit"));
|
|
43
|
+
}
|
|
44
|
+
async rollbackTransaction(connection) {
|
|
45
|
+
await connection.executeQuery(kysely.CompiledQuery.raw("rollback"));
|
|
46
|
+
}
|
|
47
|
+
async releaseConnection() {
|
|
48
|
+
this.#connectionMutex.unlock();
|
|
49
|
+
}
|
|
50
|
+
async destroy() {
|
|
51
|
+
this.#db?.close();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var NodeSqliteConnection = class {
|
|
55
|
+
#db;
|
|
56
|
+
constructor(db) {
|
|
57
|
+
this.#db = db;
|
|
58
|
+
}
|
|
59
|
+
executeQuery(compiledQuery) {
|
|
60
|
+
const { sql: sql$1, parameters } = compiledQuery;
|
|
61
|
+
const rows = this.#db.prepare(sql$1).all(...parameters);
|
|
62
|
+
return Promise.resolve({ rows });
|
|
63
|
+
}
|
|
64
|
+
async *streamQuery() {
|
|
65
|
+
throw new Error("Streaming query is not supported by SQLite driver.");
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var ConnectionMutex = class {
|
|
69
|
+
#promise;
|
|
70
|
+
#resolve;
|
|
71
|
+
async lock() {
|
|
72
|
+
while (this.#promise) await this.#promise;
|
|
73
|
+
this.#promise = new Promise((resolve) => {
|
|
74
|
+
this.#resolve = resolve;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
unlock() {
|
|
78
|
+
const resolve = this.#resolve;
|
|
79
|
+
this.#promise = void 0;
|
|
80
|
+
this.#resolve = void 0;
|
|
81
|
+
resolve?.();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var NodeSqliteIntrospector = class {
|
|
85
|
+
#db;
|
|
86
|
+
constructor(db) {
|
|
87
|
+
this.#db = db;
|
|
88
|
+
}
|
|
89
|
+
async getSchemas() {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
async getTables(options = { withInternalKyselyTables: false }) {
|
|
93
|
+
let query = this.#db.selectFrom("sqlite_schema").where("type", "=", "table").where("name", "not like", "sqlite_%").select("name").$castTo();
|
|
94
|
+
if (!options.withInternalKyselyTables) query = query.where("name", "!=", kysely.DEFAULT_MIGRATION_TABLE).where("name", "!=", kysely.DEFAULT_MIGRATION_LOCK_TABLE);
|
|
95
|
+
const tables = await query.execute();
|
|
96
|
+
return Promise.all(tables.map(({ name }) => this.#getTableMetadata(name)));
|
|
97
|
+
}
|
|
98
|
+
async getMetadata(options) {
|
|
99
|
+
return { tables: await this.getTables(options) };
|
|
100
|
+
}
|
|
101
|
+
async #getTableMetadata(table) {
|
|
102
|
+
const db = this.#db;
|
|
103
|
+
const autoIncrementCol = (await db.selectFrom("sqlite_master").where("name", "=", table).select("sql").$castTo().execute())[0]?.sql?.split(/[\(\),]/)?.find((it) => it.toLowerCase().includes("autoincrement"))?.split(/\s+/)?.[0]?.replace(/["`]/g, "");
|
|
104
|
+
return {
|
|
105
|
+
name: table,
|
|
106
|
+
columns: (await db.selectFrom(kysely.sql`pragma_table_info(${table})`.as("table_info")).select([
|
|
107
|
+
"name",
|
|
108
|
+
"type",
|
|
109
|
+
"notnull",
|
|
110
|
+
"dflt_value"
|
|
111
|
+
]).execute()).map((col) => ({
|
|
112
|
+
name: col.name,
|
|
113
|
+
dataType: col.type,
|
|
114
|
+
isNullable: !col.notnull,
|
|
115
|
+
isAutoIncrementing: col.name === autoIncrementCol,
|
|
116
|
+
hasDefaultValue: col.dflt_value != null
|
|
117
|
+
})),
|
|
118
|
+
isView: true
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var NodeSqliteQueryCompiler = class extends kysely.DefaultQueryCompiler {
|
|
123
|
+
getCurrentParameterPlaceholder() {
|
|
124
|
+
return "?";
|
|
125
|
+
}
|
|
126
|
+
getLeftIdentifierWrapper() {
|
|
127
|
+
return "\"";
|
|
128
|
+
}
|
|
129
|
+
getRightIdentifierWrapper() {
|
|
130
|
+
return "\"";
|
|
131
|
+
}
|
|
132
|
+
getAutoIncrement() {
|
|
133
|
+
return "autoincrement";
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
var NodeSqliteDialect = class {
|
|
137
|
+
#config;
|
|
138
|
+
constructor(config) {
|
|
139
|
+
this.#config = { ...config };
|
|
140
|
+
}
|
|
141
|
+
createDriver() {
|
|
142
|
+
return new NodeSqliteDriver(this.#config);
|
|
143
|
+
}
|
|
144
|
+
createQueryCompiler() {
|
|
145
|
+
return new NodeSqliteQueryCompiler();
|
|
146
|
+
}
|
|
147
|
+
createAdapter() {
|
|
148
|
+
return new NodeSqliteAdapter();
|
|
149
|
+
}
|
|
150
|
+
createIntrospector(db) {
|
|
151
|
+
return new NodeSqliteIntrospector(db);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
exports.NodeSqliteDialect = NodeSqliteDialect;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llmops/core",
|
|
3
|
-
"version": "0.1.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Core LLMOps functionality and utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -17,12 +17,30 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
|
-
"main": "./dist/index.
|
|
20
|
+
"main": "./dist/index.cjs",
|
|
21
21
|
"module": "./dist/index.mjs",
|
|
22
22
|
"types": "./dist/index.d.mts",
|
|
23
23
|
"exports": {
|
|
24
|
-
".":
|
|
25
|
-
|
|
24
|
+
".": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"default": "./dist/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"default": "./dist/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"./db": {
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/db/index.d.mts",
|
|
37
|
+
"default": "./dist/db/index.mjs"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./dist/db/index.d.cts",
|
|
41
|
+
"default": "./dist/db/index.cjs"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
26
44
|
"./package.json": "./package.json"
|
|
27
45
|
},
|
|
28
46
|
"publishConfig": {
|
|
@@ -33,7 +51,7 @@
|
|
|
33
51
|
"hono": "^4.10.7",
|
|
34
52
|
"kysely": "^0.28.8",
|
|
35
53
|
"pino": "^10.1.0",
|
|
36
|
-
"@llmops/gateway": "0.1.0
|
|
54
|
+
"@llmops/gateway": "^0.1.0"
|
|
37
55
|
},
|
|
38
56
|
"scripts": {
|
|
39
57
|
"build": "tsdown",
|