@llmops/core 0.1.9 → 0.2.0-beta.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.
- package/dist/{bun-sqlite-dialect-BsBCR8hT.cjs → bun-sqlite-dialect-BxlwYxpt.cjs} +1 -1
- package/dist/db/index.cjs +2 -1
- package/dist/db/index.d.cts +2 -2
- package/dist/db/index.d.mts +2 -2
- package/dist/db/index.mjs +2 -2
- package/dist/{db-BokBhuLo.mjs → db-BCHs_i6m.mjs} +1565 -1003
- package/dist/{db-1Ar4ItM_.cjs → db-BdclKAD3.cjs} +1573 -1005
- package/dist/{index-Dn5KseQM.d.cts → index-CJI8-6PV.d.mts} +105 -2
- package/dist/{index-BTE44_Jz.d.mts → index-zQzOuWsM.d.cts} +136 -33
- package/dist/index.cjs +97 -25
- package/dist/index.d.cts +451 -715
- package/dist/index.d.mts +451 -715
- package/dist/index.mjs +96 -26
- package/dist/{node-sqlite-dialect-BnUFpWfa.cjs → node-sqlite-dialect-DjW-cdIu.cjs} +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as literal, C as variantsSchema, D as any, E as _enum, F as union, I as unknown, M as object, N as record, O as array, P as string, S as variantVersionsSchema, T as zod_default, _ as environmentsSchema, a as matchType, b as schemas, c as logger, d as validatePartialTableData, f as validateTableData, g as environmentSecretsSchema, h as configsSchema, i as getMigrations, j as number, k as boolean, l as parsePartialTableData, m as configVariantsSchema, n as createDatabaseFromConnection, o as runAutoMigrations, p as SCHEMA_METADATA, r as detectDatabaseType, s as getAuthClientOptions, t as createDatabase, u as parseTableData, v as llmRequestsSchema, w as workspaceSettingsSchema, x as targetingRulesSchema, y as providerConfigsSchema } from "./db-BCHs_i6m.mjs";
|
|
2
2
|
import gateway from "@llmops/gateway";
|
|
3
3
|
import { sql } from "kysely";
|
|
4
4
|
import * as fs from "node:fs/promises";
|
|
@@ -418,33 +418,9 @@ const variantJsonDataSchema = object({
|
|
|
418
418
|
|
|
419
419
|
//#endregion
|
|
420
420
|
//#region src/schemas/config.ts
|
|
421
|
-
/**
|
|
422
|
-
* Provider configuration schema
|
|
423
|
-
*
|
|
424
|
-
* This is a flexible schema that allows any provider configuration.
|
|
425
|
-
* The actual provider validation happens at the gateway level.
|
|
426
|
-
* Uses passthrough() to allow provider-specific options.
|
|
427
|
-
*/
|
|
428
|
-
const providerConfigSchema = object({
|
|
429
|
-
apiKey: string().min(1, "API key is required"),
|
|
430
|
-
customHost: string().optional(),
|
|
431
|
-
requestTimeout: number().optional(),
|
|
432
|
-
forwardHeaders: array(string()).optional()
|
|
433
|
-
}).passthrough();
|
|
434
|
-
/**
|
|
435
|
-
* Build a partial object schema from SupportedProviders enum
|
|
436
|
-
* Each provider key is optional, allowing users to configure only the providers they need
|
|
437
|
-
*/
|
|
438
|
-
const providerEntries = Object.values(SupportedProviders).map((provider) => [provider, providerConfigSchema.optional()]);
|
|
439
|
-
/**
|
|
440
|
-
* Providers configuration - maps supported provider names to their configs
|
|
441
|
-
* All providers are optional, but at least one must be configured
|
|
442
|
-
*/
|
|
443
|
-
const providersSchema = object(Object.fromEntries(providerEntries)).refine((providers) => Object.values(providers).some((v) => v !== void 0 && v !== null), "At least one provider must be configured");
|
|
444
421
|
const llmopsConfigSchema = object({
|
|
445
422
|
database: any(),
|
|
446
423
|
basePath: string().min(1, "Base path is required and cannot be empty").refine((path$1) => path$1.startsWith("/"), "Base path must start with a forward slash"),
|
|
447
|
-
providers: providersSchema,
|
|
448
424
|
schema: string().optional().default("llmops")
|
|
449
425
|
});
|
|
450
426
|
function validateLLMOpsConfig(config) {
|
|
@@ -1784,6 +1760,99 @@ const createLLMRequestsDataLayer = (db) => {
|
|
|
1784
1760
|
};
|
|
1785
1761
|
};
|
|
1786
1762
|
|
|
1763
|
+
//#endregion
|
|
1764
|
+
//#region src/datalayer/providerConfigs.ts
|
|
1765
|
+
const createProviderConfig = zod_default.object({
|
|
1766
|
+
providerId: zod_default.string().min(1),
|
|
1767
|
+
config: zod_default.record(zod_default.string(), zod_default.unknown()),
|
|
1768
|
+
enabled: zod_default.boolean().optional().default(true)
|
|
1769
|
+
});
|
|
1770
|
+
const updateProviderConfig = zod_default.object({
|
|
1771
|
+
id: zod_default.uuidv4(),
|
|
1772
|
+
config: zod_default.record(zod_default.string(), zod_default.unknown()).optional(),
|
|
1773
|
+
enabled: zod_default.boolean().optional()
|
|
1774
|
+
});
|
|
1775
|
+
const getProviderConfigById = zod_default.object({ id: zod_default.uuidv4() });
|
|
1776
|
+
const getProviderConfigByProviderId = zod_default.object({ providerId: zod_default.string().min(1) });
|
|
1777
|
+
const deleteProviderConfig = zod_default.object({ id: zod_default.uuidv4() });
|
|
1778
|
+
const listProviderConfigs = zod_default.object({
|
|
1779
|
+
limit: zod_default.number().int().positive().optional(),
|
|
1780
|
+
offset: zod_default.number().int().nonnegative().optional()
|
|
1781
|
+
});
|
|
1782
|
+
const createProviderConfigsDataLayer = (db) => {
|
|
1783
|
+
return {
|
|
1784
|
+
createProviderConfig: async (params) => {
|
|
1785
|
+
const value = await createProviderConfig.safeParseAsync(params);
|
|
1786
|
+
if (!value.success) throw new LLMOpsError(`Invalid parameters: ${value.error.message}`);
|
|
1787
|
+
const { providerId, config, enabled } = value.data;
|
|
1788
|
+
return db.insertInto("provider_configs").values({
|
|
1789
|
+
id: randomUUID(),
|
|
1790
|
+
providerId,
|
|
1791
|
+
config: JSON.stringify(config),
|
|
1792
|
+
enabled,
|
|
1793
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1794
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1795
|
+
}).returningAll().executeTakeFirst();
|
|
1796
|
+
},
|
|
1797
|
+
updateProviderConfig: async (params) => {
|
|
1798
|
+
const value = await updateProviderConfig.safeParseAsync(params);
|
|
1799
|
+
if (!value.success) throw new LLMOpsError(`Invalid parameters: ${value.error.message}`);
|
|
1800
|
+
const { id, config, enabled } = value.data;
|
|
1801
|
+
const updateData = { updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
1802
|
+
if (config !== void 0) updateData.config = JSON.stringify(config);
|
|
1803
|
+
if (enabled !== void 0) updateData.enabled = enabled;
|
|
1804
|
+
return db.updateTable("provider_configs").set(updateData).where("id", "=", id).returningAll().executeTakeFirst();
|
|
1805
|
+
},
|
|
1806
|
+
getProviderConfigById: async (params) => {
|
|
1807
|
+
const value = await getProviderConfigById.safeParseAsync(params);
|
|
1808
|
+
if (!value.success) throw new LLMOpsError(`Invalid parameters: ${value.error.message}`);
|
|
1809
|
+
const { id } = value.data;
|
|
1810
|
+
return db.selectFrom("provider_configs").selectAll().where("id", "=", id).executeTakeFirst();
|
|
1811
|
+
},
|
|
1812
|
+
getProviderConfigByProviderId: async (params) => {
|
|
1813
|
+
const value = await getProviderConfigByProviderId.safeParseAsync(params);
|
|
1814
|
+
if (!value.success) throw new LLMOpsError(`Invalid parameters: ${value.error.message}`);
|
|
1815
|
+
const { providerId } = value.data;
|
|
1816
|
+
return db.selectFrom("provider_configs").selectAll().where("providerId", "=", providerId).executeTakeFirst();
|
|
1817
|
+
},
|
|
1818
|
+
deleteProviderConfig: async (params) => {
|
|
1819
|
+
const value = await deleteProviderConfig.safeParseAsync(params);
|
|
1820
|
+
if (!value.success) throw new LLMOpsError(`Invalid parameters: ${value.error.message}`);
|
|
1821
|
+
const { id } = value.data;
|
|
1822
|
+
return db.deleteFrom("provider_configs").where("id", "=", id).returningAll().executeTakeFirst();
|
|
1823
|
+
},
|
|
1824
|
+
listProviderConfigs: async (params) => {
|
|
1825
|
+
const value = await listProviderConfigs.safeParseAsync(params || {});
|
|
1826
|
+
if (!value.success) throw new LLMOpsError(`Invalid parameters: ${value.error.message}`);
|
|
1827
|
+
const { limit = 100, offset = 0 } = value.data;
|
|
1828
|
+
return db.selectFrom("provider_configs").selectAll().orderBy("createdAt", "desc").limit(limit).offset(offset).execute();
|
|
1829
|
+
},
|
|
1830
|
+
countProviderConfigs: async () => {
|
|
1831
|
+
const result = await db.selectFrom("provider_configs").select(db.fn.countAll().as("count")).executeTakeFirst();
|
|
1832
|
+
return Number(result?.count ?? 0);
|
|
1833
|
+
},
|
|
1834
|
+
upsertProviderConfig: async (params) => {
|
|
1835
|
+
const value = await createProviderConfig.safeParseAsync(params);
|
|
1836
|
+
if (!value.success) throw new LLMOpsError(`Invalid parameters: ${value.error.message}`);
|
|
1837
|
+
const { providerId, config, enabled } = value.data;
|
|
1838
|
+
const existing = await db.selectFrom("provider_configs").selectAll().where("providerId", "=", providerId).executeTakeFirst();
|
|
1839
|
+
if (existing) return db.updateTable("provider_configs").set({
|
|
1840
|
+
config: JSON.stringify(config),
|
|
1841
|
+
enabled,
|
|
1842
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1843
|
+
}).where("id", "=", existing.id).returningAll().executeTakeFirst();
|
|
1844
|
+
return db.insertInto("provider_configs").values({
|
|
1845
|
+
id: randomUUID(),
|
|
1846
|
+
providerId,
|
|
1847
|
+
config: JSON.stringify(config),
|
|
1848
|
+
enabled,
|
|
1849
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1850
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1851
|
+
}).returningAll().executeTakeFirst();
|
|
1852
|
+
}
|
|
1853
|
+
};
|
|
1854
|
+
};
|
|
1855
|
+
|
|
1787
1856
|
//#endregion
|
|
1788
1857
|
//#region src/datalayer/targetingRules.ts
|
|
1789
1858
|
const createTargetingRule = zod_default.object({
|
|
@@ -2258,6 +2327,7 @@ const createDataLayer = async (db) => {
|
|
|
2258
2327
|
...createEnvironmentDataLayer(db),
|
|
2259
2328
|
...createEnvironmentSecretDataLayer(db),
|
|
2260
2329
|
...createLLMRequestsDataLayer(db),
|
|
2330
|
+
...createProviderConfigsDataLayer(db),
|
|
2261
2331
|
...createTargetingRulesDataLayer(db),
|
|
2262
2332
|
...createVariantDataLayer(db),
|
|
2263
2333
|
...createVariantVersionsDataLayer(db),
|
|
@@ -2469,4 +2539,4 @@ function getDefaultPricingProvider() {
|
|
|
2469
2539
|
}
|
|
2470
2540
|
|
|
2471
2541
|
//#endregion
|
|
2472
|
-
export { CacheService, FileCacheBackend, MS, MemoryCacheBackend, ModelsDevPricingProvider, SCHEMA_METADATA, SupportedProviders, calculateCost, chatCompletionCreateParamsBaseSchema, configVariantsSchema, configsSchema, createDataLayer, createDatabase, createDatabaseFromConnection, createLLMRequestsDataLayer, createWorkspaceSettingsDataLayer, detectDatabaseType, dollarsToMicroDollars, environmentSecretsSchema, environmentsSchema, formatCost, gateway, generateId, getAuthClientOptions, getDefaultPricingProvider, getMigrations, llmRequestsSchema, llmopsConfigSchema, logger, matchType, microDollarsToDollars, parsePartialTableData, parseTableData, runAutoMigrations, schemas, targetingRulesSchema, validateLLMOpsConfig, validatePartialTableData, validateTableData, variantJsonDataSchema, variantVersionsSchema, variantsSchema, workspaceSettingsSchema };
|
|
2542
|
+
export { CacheService, FileCacheBackend, MS, MemoryCacheBackend, ModelsDevPricingProvider, SCHEMA_METADATA, SupportedProviders, calculateCost, chatCompletionCreateParamsBaseSchema, configVariantsSchema, configsSchema, createDataLayer, createDatabase, createDatabaseFromConnection, createLLMRequestsDataLayer, createProviderConfigsDataLayer, createWorkspaceSettingsDataLayer, detectDatabaseType, dollarsToMicroDollars, environmentSecretsSchema, environmentsSchema, formatCost, gateway, generateId, getAuthClientOptions, getDefaultPricingProvider, getMigrations, llmRequestsSchema, llmopsConfigSchema, logger, matchType, microDollarsToDollars, parsePartialTableData, parseTableData, providerConfigsSchema, runAutoMigrations, schemas, targetingRulesSchema, validateLLMOpsConfig, validatePartialTableData, validateTableData, variantJsonDataSchema, variantVersionsSchema, variantsSchema, workspaceSettingsSchema };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llmops/core",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.0-beta.1",
|
|
4
4
|
"description": "Core LLMOps functionality and utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"hono": "^4.10.7",
|
|
53
53
|
"kysely": "^0.28.8",
|
|
54
54
|
"pino": "^10.1.0",
|
|
55
|
-
"@llmops/gateway": "^0.1
|
|
55
|
+
"@llmops/gateway": "^0.2.0-beta.1"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsdown",
|