@llmops/core 0.2.14 → 0.3.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/db/index.d.cts +1 -1
- package/dist/{index-Dm1Gi0cH.d.cts → index-DX05tkNg.d.cts} +35 -35
- package/dist/index.cjs +347 -4
- package/dist/index.d.cts +465 -272
- package/dist/index.d.mts +194 -1
- package/dist/index.mjs +344 -5
- package/package.json +4 -2
package/dist/db/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as variantsSchema, A as ProviderConfig, B as VariantVersionsTable, C as Environment, D as Insertable, E as EnvironmentsTable, F as TargetingRule, G as configsSchema, H as WorkspaceSettings, I as TargetingRulesTable, J as llmRequestsSchema, K as environmentSecretsSchema, L as Updateable, M as SCHEMA_METADATA, N as Selectable, O as LLMRequest, P as TableName, Q as variantVersionsSchema, R as Variant, S as Database, T as EnvironmentSecretsTable, U as WorkspaceSettingsTable, V as VariantsTable, W as configVariantsSchema, X as schemas, Y as providerConfigsSchema, Z as targetingRulesSchema, _ as validateTableData, a as createDatabaseFromConnection, b as ConfigVariantsTable, c as executeWithSchema, d as getMigrations, et as workspaceSettingsSchema, f as matchType, g as validatePartialTableData, h as parseTableData, i as createDatabase, j as ProviderConfigsTable, k as LLMRequestsTable, l as MigrationOptions, m as parsePartialTableData, n as DatabaseOptions, o as detectDatabaseType, p as runAutoMigrations, q as environmentsSchema, r as DatabaseType, s as createNeonDialect, t as DatabaseConnection, u as MigrationResult, v as Config, w as EnvironmentSecret, x as ConfigsTable, y as ConfigVariant, z as VariantVersion } from "../index-
|
|
1
|
+
import { $ as variantsSchema, A as ProviderConfig, B as VariantVersionsTable, C as Environment, D as Insertable, E as EnvironmentsTable, F as TargetingRule, G as configsSchema, H as WorkspaceSettings, I as TargetingRulesTable, J as llmRequestsSchema, K as environmentSecretsSchema, L as Updateable, M as SCHEMA_METADATA, N as Selectable, O as LLMRequest, P as TableName, Q as variantVersionsSchema, R as Variant, S as Database, T as EnvironmentSecretsTable, U as WorkspaceSettingsTable, V as VariantsTable, W as configVariantsSchema, X as schemas, Y as providerConfigsSchema, Z as targetingRulesSchema, _ as validateTableData, a as createDatabaseFromConnection, b as ConfigVariantsTable, c as executeWithSchema, d as getMigrations, et as workspaceSettingsSchema, f as matchType, g as validatePartialTableData, h as parseTableData, i as createDatabase, j as ProviderConfigsTable, k as LLMRequestsTable, l as MigrationOptions, m as parsePartialTableData, n as DatabaseOptions, o as detectDatabaseType, p as runAutoMigrations, q as environmentsSchema, r as DatabaseType, s as createNeonDialect, t as DatabaseConnection, u as MigrationResult, v as Config, w as EnvironmentSecret, x as ConfigsTable, y as ConfigVariant, z as VariantVersion } from "../index-DX05tkNg.cjs";
|
|
2
2
|
export { Config, ConfigVariant, ConfigVariantsTable, ConfigsTable, Database, DatabaseConnection, DatabaseOptions, DatabaseType, Environment, EnvironmentSecret, EnvironmentSecretsTable, EnvironmentsTable, Insertable, LLMRequest, LLMRequestsTable, MigrationOptions, MigrationResult, ProviderConfig, ProviderConfigsTable, SCHEMA_METADATA, Selectable, TableName, TargetingRule, TargetingRulesTable, Updateable, Variant, VariantVersion, VariantVersionsTable, VariantsTable, WorkspaceSettings, WorkspaceSettingsTable, configVariantsSchema, configsSchema, createDatabase, createDatabaseFromConnection, createNeonDialect, detectDatabaseType, environmentSecretsSchema, environmentsSchema, executeWithSchema, getMigrations, llmRequestsSchema, matchType, parsePartialTableData, parseTableData, providerConfigsSchema, runAutoMigrations, schemas, targetingRulesSchema, validatePartialTableData, validateTableData, variantVersionsSchema, variantsSchema, workspaceSettingsSchema };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ColumnType, Dialect, Generated, Kysely, MssqlDialect, MysqlDialect, PostgresDialect, SqliteDialect } from "kysely";
|
|
2
|
-
import * as
|
|
2
|
+
import * as zod0 from "zod";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { NeonQueryFunction } from "@neondatabase/serverless";
|
|
5
5
|
|
|
@@ -866,29 +866,29 @@ declare const schemas: {
|
|
|
866
866
|
* Validate data against table schema
|
|
867
867
|
* Useful for runtime validation before inserting/updating
|
|
868
868
|
*/
|
|
869
|
-
declare function validateTableData<T extends TableName>(table: T, data: unknown):
|
|
869
|
+
declare function validateTableData<T extends TableName>(table: T, data: unknown): zod0.ZodSafeParseSuccess<{
|
|
870
870
|
slug: string;
|
|
871
871
|
id: string;
|
|
872
872
|
createdAt: Date;
|
|
873
873
|
updatedAt: Date;
|
|
874
874
|
name?: string | undefined;
|
|
875
|
-
}> |
|
|
875
|
+
}> | zod0.ZodSafeParseError<{
|
|
876
876
|
slug: string;
|
|
877
877
|
id: string;
|
|
878
878
|
createdAt: Date;
|
|
879
879
|
updatedAt: Date;
|
|
880
880
|
name?: string | undefined;
|
|
881
|
-
}> |
|
|
881
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
882
882
|
name: string;
|
|
883
883
|
id: string;
|
|
884
884
|
createdAt: Date;
|
|
885
885
|
updatedAt: Date;
|
|
886
|
-
}> |
|
|
886
|
+
}> | zod0.ZodSafeParseError<{
|
|
887
887
|
name: string;
|
|
888
888
|
id: string;
|
|
889
889
|
createdAt: Date;
|
|
890
890
|
updatedAt: Date;
|
|
891
|
-
}> |
|
|
891
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
892
892
|
variantId: string;
|
|
893
893
|
version: number;
|
|
894
894
|
provider: string;
|
|
@@ -897,7 +897,7 @@ declare function validateTableData<T extends TableName>(table: T, data: unknown)
|
|
|
897
897
|
id: string;
|
|
898
898
|
createdAt: Date;
|
|
899
899
|
updatedAt: Date;
|
|
900
|
-
}> |
|
|
900
|
+
}> | zod0.ZodSafeParseError<{
|
|
901
901
|
variantId: string;
|
|
902
902
|
version: number;
|
|
903
903
|
provider: string;
|
|
@@ -906,33 +906,33 @@ declare function validateTableData<T extends TableName>(table: T, data: unknown)
|
|
|
906
906
|
id: string;
|
|
907
907
|
createdAt: Date;
|
|
908
908
|
updatedAt: Date;
|
|
909
|
-
}> |
|
|
909
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
910
910
|
environmentId: string;
|
|
911
911
|
keyName: string;
|
|
912
912
|
keyValue: string;
|
|
913
913
|
id: string;
|
|
914
914
|
createdAt: Date;
|
|
915
915
|
updatedAt: Date;
|
|
916
|
-
}> |
|
|
916
|
+
}> | zod0.ZodSafeParseError<{
|
|
917
917
|
environmentId: string;
|
|
918
918
|
keyName: string;
|
|
919
919
|
keyValue: string;
|
|
920
920
|
id: string;
|
|
921
921
|
createdAt: Date;
|
|
922
922
|
updatedAt: Date;
|
|
923
|
-
}> |
|
|
923
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
924
924
|
configId: string;
|
|
925
925
|
variantId: string;
|
|
926
926
|
id: string;
|
|
927
927
|
createdAt: Date;
|
|
928
928
|
updatedAt: Date;
|
|
929
|
-
}> |
|
|
929
|
+
}> | zod0.ZodSafeParseError<{
|
|
930
930
|
configId: string;
|
|
931
931
|
variantId: string;
|
|
932
932
|
id: string;
|
|
933
933
|
createdAt: Date;
|
|
934
934
|
updatedAt: Date;
|
|
935
|
-
}> |
|
|
935
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
936
936
|
environmentId: string;
|
|
937
937
|
configId: string;
|
|
938
938
|
configVariantId: string;
|
|
@@ -944,7 +944,7 @@ declare function validateTableData<T extends TableName>(table: T, data: unknown)
|
|
|
944
944
|
createdAt: Date;
|
|
945
945
|
updatedAt: Date;
|
|
946
946
|
variantVersionId?: string | null | undefined;
|
|
947
|
-
}> |
|
|
947
|
+
}> | zod0.ZodSafeParseError<{
|
|
948
948
|
environmentId: string;
|
|
949
949
|
configId: string;
|
|
950
950
|
configVariantId: string;
|
|
@@ -956,21 +956,21 @@ declare function validateTableData<T extends TableName>(table: T, data: unknown)
|
|
|
956
956
|
createdAt: Date;
|
|
957
957
|
updatedAt: Date;
|
|
958
958
|
variantVersionId?: string | null | undefined;
|
|
959
|
-
}> |
|
|
959
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
960
960
|
setupComplete: boolean;
|
|
961
961
|
id: string;
|
|
962
962
|
createdAt: Date;
|
|
963
963
|
updatedAt: Date;
|
|
964
964
|
name?: string | null | undefined;
|
|
965
965
|
superAdminId?: string | null | undefined;
|
|
966
|
-
}> |
|
|
966
|
+
}> | zod0.ZodSafeParseError<{
|
|
967
967
|
setupComplete: boolean;
|
|
968
968
|
id: string;
|
|
969
969
|
createdAt: Date;
|
|
970
970
|
updatedAt: Date;
|
|
971
971
|
name?: string | null | undefined;
|
|
972
972
|
superAdminId?: string | null | undefined;
|
|
973
|
-
}> |
|
|
973
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
974
974
|
providerId: string;
|
|
975
975
|
config: Record<string, unknown>;
|
|
976
976
|
enabled: boolean;
|
|
@@ -979,7 +979,7 @@ declare function validateTableData<T extends TableName>(table: T, data: unknown)
|
|
|
979
979
|
updatedAt: Date;
|
|
980
980
|
slug?: string | null | undefined;
|
|
981
981
|
name?: string | null | undefined;
|
|
982
|
-
}> |
|
|
982
|
+
}> | zod0.ZodSafeParseError<{
|
|
983
983
|
providerId: string;
|
|
984
984
|
config: Record<string, unknown>;
|
|
985
985
|
enabled: boolean;
|
|
@@ -988,7 +988,7 @@ declare function validateTableData<T extends TableName>(table: T, data: unknown)
|
|
|
988
988
|
updatedAt: Date;
|
|
989
989
|
slug?: string | null | undefined;
|
|
990
990
|
name?: string | null | undefined;
|
|
991
|
-
}> |
|
|
991
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
992
992
|
requestId: string;
|
|
993
993
|
provider: string;
|
|
994
994
|
model: string;
|
|
@@ -1012,7 +1012,7 @@ declare function validateTableData<T extends TableName>(table: T, data: unknown)
|
|
|
1012
1012
|
environmentId?: string | null | undefined;
|
|
1013
1013
|
providerConfigId?: string | null | undefined;
|
|
1014
1014
|
userId?: string | null | undefined;
|
|
1015
|
-
}> |
|
|
1015
|
+
}> | zod0.ZodSafeParseError<{
|
|
1016
1016
|
requestId: string;
|
|
1017
1017
|
provider: string;
|
|
1018
1018
|
model: string;
|
|
@@ -1040,17 +1040,17 @@ declare function validateTableData<T extends TableName>(table: T, data: unknown)
|
|
|
1040
1040
|
/**
|
|
1041
1041
|
* Validate partial data (for updates)
|
|
1042
1042
|
*/
|
|
1043
|
-
declare function validatePartialTableData<T extends TableName>(table: T, data: unknown):
|
|
1043
|
+
declare function validatePartialTableData<T extends TableName>(table: T, data: unknown): zod0.ZodSafeParseSuccess<{
|
|
1044
1044
|
name?: string | undefined;
|
|
1045
1045
|
id?: string | undefined;
|
|
1046
1046
|
createdAt?: Date | undefined;
|
|
1047
1047
|
updatedAt?: Date | undefined;
|
|
1048
|
-
}> |
|
|
1048
|
+
}> | zod0.ZodSafeParseError<{
|
|
1049
1049
|
name?: string | undefined;
|
|
1050
1050
|
id?: string | undefined;
|
|
1051
1051
|
createdAt?: Date | undefined;
|
|
1052
1052
|
updatedAt?: Date | undefined;
|
|
1053
|
-
}> |
|
|
1053
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
1054
1054
|
variantId?: string | undefined;
|
|
1055
1055
|
version?: number | undefined;
|
|
1056
1056
|
provider?: string | undefined;
|
|
@@ -1059,7 +1059,7 @@ declare function validatePartialTableData<T extends TableName>(table: T, data: u
|
|
|
1059
1059
|
id?: string | undefined;
|
|
1060
1060
|
createdAt?: Date | undefined;
|
|
1061
1061
|
updatedAt?: Date | undefined;
|
|
1062
|
-
}> |
|
|
1062
|
+
}> | zod0.ZodSafeParseError<{
|
|
1063
1063
|
variantId?: string | undefined;
|
|
1064
1064
|
version?: number | undefined;
|
|
1065
1065
|
provider?: string | undefined;
|
|
@@ -1068,33 +1068,33 @@ declare function validatePartialTableData<T extends TableName>(table: T, data: u
|
|
|
1068
1068
|
id?: string | undefined;
|
|
1069
1069
|
createdAt?: Date | undefined;
|
|
1070
1070
|
updatedAt?: Date | undefined;
|
|
1071
|
-
}> |
|
|
1071
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
1072
1072
|
environmentId?: string | undefined;
|
|
1073
1073
|
keyName?: string | undefined;
|
|
1074
1074
|
keyValue?: string | undefined;
|
|
1075
1075
|
id?: string | undefined;
|
|
1076
1076
|
createdAt?: Date | undefined;
|
|
1077
1077
|
updatedAt?: Date | undefined;
|
|
1078
|
-
}> |
|
|
1078
|
+
}> | zod0.ZodSafeParseError<{
|
|
1079
1079
|
environmentId?: string | undefined;
|
|
1080
1080
|
keyName?: string | undefined;
|
|
1081
1081
|
keyValue?: string | undefined;
|
|
1082
1082
|
id?: string | undefined;
|
|
1083
1083
|
createdAt?: Date | undefined;
|
|
1084
1084
|
updatedAt?: Date | undefined;
|
|
1085
|
-
}> |
|
|
1085
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
1086
1086
|
configId?: string | undefined;
|
|
1087
1087
|
variantId?: string | undefined;
|
|
1088
1088
|
id?: string | undefined;
|
|
1089
1089
|
createdAt?: Date | undefined;
|
|
1090
1090
|
updatedAt?: Date | undefined;
|
|
1091
|
-
}> |
|
|
1091
|
+
}> | zod0.ZodSafeParseError<{
|
|
1092
1092
|
configId?: string | undefined;
|
|
1093
1093
|
variantId?: string | undefined;
|
|
1094
1094
|
id?: string | undefined;
|
|
1095
1095
|
createdAt?: Date | undefined;
|
|
1096
1096
|
updatedAt?: Date | undefined;
|
|
1097
|
-
}> |
|
|
1097
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
1098
1098
|
environmentId?: string | undefined;
|
|
1099
1099
|
configId?: string | undefined;
|
|
1100
1100
|
configVariantId?: string | undefined;
|
|
@@ -1106,7 +1106,7 @@ declare function validatePartialTableData<T extends TableName>(table: T, data: u
|
|
|
1106
1106
|
id?: string | undefined;
|
|
1107
1107
|
createdAt?: Date | undefined;
|
|
1108
1108
|
updatedAt?: Date | undefined;
|
|
1109
|
-
}> |
|
|
1109
|
+
}> | zod0.ZodSafeParseError<{
|
|
1110
1110
|
environmentId?: string | undefined;
|
|
1111
1111
|
configId?: string | undefined;
|
|
1112
1112
|
configVariantId?: string | undefined;
|
|
@@ -1118,21 +1118,21 @@ declare function validatePartialTableData<T extends TableName>(table: T, data: u
|
|
|
1118
1118
|
id?: string | undefined;
|
|
1119
1119
|
createdAt?: Date | undefined;
|
|
1120
1120
|
updatedAt?: Date | undefined;
|
|
1121
|
-
}> |
|
|
1121
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
1122
1122
|
name?: string | null | undefined;
|
|
1123
1123
|
setupComplete?: boolean | undefined;
|
|
1124
1124
|
superAdminId?: string | null | undefined;
|
|
1125
1125
|
id?: string | undefined;
|
|
1126
1126
|
createdAt?: Date | undefined;
|
|
1127
1127
|
updatedAt?: Date | undefined;
|
|
1128
|
-
}> |
|
|
1128
|
+
}> | zod0.ZodSafeParseError<{
|
|
1129
1129
|
name?: string | null | undefined;
|
|
1130
1130
|
setupComplete?: boolean | undefined;
|
|
1131
1131
|
superAdminId?: string | null | undefined;
|
|
1132
1132
|
id?: string | undefined;
|
|
1133
1133
|
createdAt?: Date | undefined;
|
|
1134
1134
|
updatedAt?: Date | undefined;
|
|
1135
|
-
}> |
|
|
1135
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
1136
1136
|
providerId?: string | undefined;
|
|
1137
1137
|
slug?: string | null | undefined;
|
|
1138
1138
|
name?: string | null | undefined;
|
|
@@ -1141,7 +1141,7 @@ declare function validatePartialTableData<T extends TableName>(table: T, data: u
|
|
|
1141
1141
|
id?: string | undefined;
|
|
1142
1142
|
createdAt?: Date | undefined;
|
|
1143
1143
|
updatedAt?: Date | undefined;
|
|
1144
|
-
}> |
|
|
1144
|
+
}> | zod0.ZodSafeParseError<{
|
|
1145
1145
|
providerId?: string | undefined;
|
|
1146
1146
|
slug?: string | null | undefined;
|
|
1147
1147
|
name?: string | null | undefined;
|
|
@@ -1150,7 +1150,7 @@ declare function validatePartialTableData<T extends TableName>(table: T, data: u
|
|
|
1150
1150
|
id?: string | undefined;
|
|
1151
1151
|
createdAt?: Date | undefined;
|
|
1152
1152
|
updatedAt?: Date | undefined;
|
|
1153
|
-
}> |
|
|
1153
|
+
}> | zod0.ZodSafeParseSuccess<{
|
|
1154
1154
|
requestId?: string | undefined;
|
|
1155
1155
|
configId?: string | null | undefined;
|
|
1156
1156
|
variantId?: string | null | undefined;
|
|
@@ -1174,7 +1174,7 @@ declare function validatePartialTableData<T extends TableName>(table: T, data: u
|
|
|
1174
1174
|
id?: string | undefined;
|
|
1175
1175
|
createdAt?: Date | undefined;
|
|
1176
1176
|
updatedAt?: Date | undefined;
|
|
1177
|
-
}> |
|
|
1177
|
+
}> | zod0.ZodSafeParseError<{
|
|
1178
1178
|
requestId?: string | undefined;
|
|
1179
1179
|
configId?: string | null | undefined;
|
|
1180
1180
|
variantId?: string | null | undefined;
|
package/dist/index.cjs
CHANGED
|
@@ -9,6 +9,8 @@ let node_path = require("node:path");
|
|
|
9
9
|
node_path = require_db.__toESM(node_path);
|
|
10
10
|
let __better_auth_utils_random = require("@better-auth/utils/random");
|
|
11
11
|
let node_crypto = require("node:crypto");
|
|
12
|
+
let json_logic_js = require("json-logic-js");
|
|
13
|
+
json_logic_js = require_db.__toESM(json_logic_js);
|
|
12
14
|
|
|
13
15
|
//#region src/providers/supported-providers.ts
|
|
14
16
|
/**
|
|
@@ -840,7 +842,10 @@ var CacheService = class {
|
|
|
840
842
|
}
|
|
841
843
|
createBackend(config) {
|
|
842
844
|
switch (config.backend) {
|
|
843
|
-
case "memory": return new MemoryCacheBackend(
|
|
845
|
+
case "memory": return new MemoryCacheBackend({
|
|
846
|
+
maxSize: config.maxSize,
|
|
847
|
+
cleanupIntervalMs: config.cleanupInterval
|
|
848
|
+
});
|
|
844
849
|
case "file": return new FileCacheBackend(config.dataDir, config.fileName, config.saveInterval, config.cleanupInterval);
|
|
845
850
|
default: throw new Error(`Unsupported cache backend: ${config.backend}`);
|
|
846
851
|
}
|
|
@@ -1229,9 +1234,9 @@ const createConfigVariantDataLayer = (db) => {
|
|
|
1229
1234
|
const value = await getVariantJsonDataForConfig.safeParseAsync(params);
|
|
1230
1235
|
if (!value.success) throw new LLMOpsError(`Invalid parameters: ${value.error.message}`);
|
|
1231
1236
|
const { configId: configIdOrSlug, envSecret } = value.data;
|
|
1232
|
-
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1237
|
+
const UUID_REGEX$1 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1233
1238
|
let resolvedConfigId;
|
|
1234
|
-
if (UUID_REGEX.test(configIdOrSlug)) resolvedConfigId = configIdOrSlug;
|
|
1239
|
+
if (UUID_REGEX$1.test(configIdOrSlug)) resolvedConfigId = configIdOrSlug;
|
|
1235
1240
|
else {
|
|
1236
1241
|
const config = await db.selectFrom("configs").select("id").where("slug", "=", configIdOrSlug).executeTakeFirst();
|
|
1237
1242
|
if (!config) throw new LLMOpsError(`Config not found: ${configIdOrSlug}`);
|
|
@@ -1267,7 +1272,7 @@ const createConfigVariantDataLayer = (db) => {
|
|
|
1267
1272
|
if (!versionData) throw new LLMOpsError(`No variant version found for variant ${configVariant.variantId}`);
|
|
1268
1273
|
let finalProvider = versionData.provider;
|
|
1269
1274
|
let providerConfigId = null;
|
|
1270
|
-
if (UUID_REGEX.test(versionData.provider)) {
|
|
1275
|
+
if (UUID_REGEX$1.test(versionData.provider)) {
|
|
1271
1276
|
const providerConfig = await db.selectFrom("provider_configs").select(["id", "providerId"]).where("id", "=", versionData.provider).executeTakeFirst();
|
|
1272
1277
|
if (providerConfig) {
|
|
1273
1278
|
finalProvider = providerConfig.providerId;
|
|
@@ -1831,6 +1836,7 @@ const updateProviderConfig = require_db.zod_default.object({
|
|
|
1831
1836
|
});
|
|
1832
1837
|
const getProviderConfigById = require_db.zod_default.object({ id: require_db.zod_default.uuidv4() });
|
|
1833
1838
|
const getProviderConfigByProviderId = require_db.zod_default.object({ providerId: require_db.zod_default.string().min(1) });
|
|
1839
|
+
const getProviderConfigBySlug = require_db.zod_default.object({ slug: require_db.zod_default.string().min(1) });
|
|
1834
1840
|
const deleteProviderConfig = require_db.zod_default.object({ id: require_db.zod_default.uuidv4() });
|
|
1835
1841
|
const listProviderConfigs = require_db.zod_default.object({
|
|
1836
1842
|
limit: require_db.zod_default.number().int().positive().optional(),
|
|
@@ -1877,6 +1883,12 @@ const createProviderConfigsDataLayer = (db) => {
|
|
|
1877
1883
|
const { providerId } = value.data;
|
|
1878
1884
|
return db.selectFrom("provider_configs").selectAll().where("providerId", "=", providerId).executeTakeFirst();
|
|
1879
1885
|
},
|
|
1886
|
+
getProviderConfigBySlug: async (params) => {
|
|
1887
|
+
const value = await getProviderConfigBySlug.safeParseAsync(params);
|
|
1888
|
+
if (!value.success) throw new LLMOpsError(`Invalid parameters: ${value.error.message}`);
|
|
1889
|
+
const { slug } = value.data;
|
|
1890
|
+
return db.selectFrom("provider_configs").selectAll().where("slug", "=", slug).executeTakeFirst();
|
|
1891
|
+
},
|
|
1880
1892
|
deleteProviderConfig: async (params) => {
|
|
1881
1893
|
const value = await deleteProviderConfig.safeParseAsync(params);
|
|
1882
1894
|
if (!value.success) throw new LLMOpsError(`Invalid parameters: ${value.error.message}`);
|
|
@@ -2608,10 +2620,341 @@ function getDefaultPricingProvider() {
|
|
|
2608
2620
|
return defaultProvider;
|
|
2609
2621
|
}
|
|
2610
2622
|
|
|
2623
|
+
//#endregion
|
|
2624
|
+
//#region src/manifest/builder.ts
|
|
2625
|
+
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
2626
|
+
/**
|
|
2627
|
+
* Builds the gateway routing manifest from database
|
|
2628
|
+
*/
|
|
2629
|
+
var ManifestBuilder = class {
|
|
2630
|
+
constructor(db) {
|
|
2631
|
+
this.db = db;
|
|
2632
|
+
}
|
|
2633
|
+
/**
|
|
2634
|
+
* Build the complete routing manifest from database
|
|
2635
|
+
*/
|
|
2636
|
+
async build() {
|
|
2637
|
+
const [configs, environments, environmentSecrets, targetingRules, configVariants, variantVersions, providerConfigs] = await Promise.all([
|
|
2638
|
+
this.db.selectFrom("configs").selectAll().execute(),
|
|
2639
|
+
this.db.selectFrom("environments").selectAll().execute(),
|
|
2640
|
+
this.db.selectFrom("environment_secrets").selectAll().execute(),
|
|
2641
|
+
this.db.selectFrom("targeting_rules").where("enabled", "=", true).selectAll().execute(),
|
|
2642
|
+
this.db.selectFrom("config_variants").selectAll().execute(),
|
|
2643
|
+
this.db.selectFrom("variant_versions").selectAll().execute(),
|
|
2644
|
+
this.db.selectFrom("provider_configs").selectAll().execute()
|
|
2645
|
+
]);
|
|
2646
|
+
const manifestConfigs = {};
|
|
2647
|
+
const configsBySlug = {};
|
|
2648
|
+
for (const config of configs) {
|
|
2649
|
+
manifestConfigs[config.id] = {
|
|
2650
|
+
id: config.id,
|
|
2651
|
+
slug: config.slug,
|
|
2652
|
+
name: config.name ?? null
|
|
2653
|
+
};
|
|
2654
|
+
configsBySlug[config.slug] = config.id;
|
|
2655
|
+
}
|
|
2656
|
+
const manifestEnvironments = {};
|
|
2657
|
+
const environmentsBySlug = {};
|
|
2658
|
+
for (const env of environments) {
|
|
2659
|
+
manifestEnvironments[env.id] = {
|
|
2660
|
+
id: env.id,
|
|
2661
|
+
slug: env.slug,
|
|
2662
|
+
name: env.name,
|
|
2663
|
+
isProd: env.isProd
|
|
2664
|
+
};
|
|
2665
|
+
environmentsBySlug[env.slug] = env.id;
|
|
2666
|
+
}
|
|
2667
|
+
const secretToEnvironment = {};
|
|
2668
|
+
for (const secret of environmentSecrets) secretToEnvironment[secret.keyValue] = secret.environmentId;
|
|
2669
|
+
const configVariantMap = new Map(configVariants.map((cv) => [cv.id, cv]));
|
|
2670
|
+
const providerConfigMap = new Map(providerConfigs.map((pc) => [pc.id, pc]));
|
|
2671
|
+
const versionsByVariant = /* @__PURE__ */ new Map();
|
|
2672
|
+
for (const vv of variantVersions) {
|
|
2673
|
+
const list = versionsByVariant.get(vv.variantId) || [];
|
|
2674
|
+
list.push(vv);
|
|
2675
|
+
versionsByVariant.set(vv.variantId, list);
|
|
2676
|
+
}
|
|
2677
|
+
for (const list of versionsByVariant.values()) list.sort((a, b) => b.version - a.version);
|
|
2678
|
+
const versionById = new Map(variantVersions.map((vv) => [vv.id, vv]));
|
|
2679
|
+
const resolveProvider = (provider) => {
|
|
2680
|
+
if (UUID_REGEX.test(provider)) {
|
|
2681
|
+
const pc = providerConfigMap.get(provider);
|
|
2682
|
+
if (pc) return {
|
|
2683
|
+
providerId: pc.providerId,
|
|
2684
|
+
providerConfigId: pc.id
|
|
2685
|
+
};
|
|
2686
|
+
}
|
|
2687
|
+
return {
|
|
2688
|
+
providerId: provider,
|
|
2689
|
+
providerConfigId: null
|
|
2690
|
+
};
|
|
2691
|
+
};
|
|
2692
|
+
const buildVersion = (vv) => {
|
|
2693
|
+
const { providerId, providerConfigId } = resolveProvider(vv.provider);
|
|
2694
|
+
const jsonData = typeof vv.jsonData === "string" ? JSON.parse(vv.jsonData) : vv.jsonData;
|
|
2695
|
+
return {
|
|
2696
|
+
id: vv.id,
|
|
2697
|
+
variantId: vv.variantId,
|
|
2698
|
+
version: vv.version,
|
|
2699
|
+
provider: providerId,
|
|
2700
|
+
providerConfigId,
|
|
2701
|
+
modelName: vv.modelName,
|
|
2702
|
+
jsonData
|
|
2703
|
+
};
|
|
2704
|
+
};
|
|
2705
|
+
const routingTable = {};
|
|
2706
|
+
for (const rule of targetingRules) {
|
|
2707
|
+
const configVariant = configVariantMap.get(rule.configVariantId);
|
|
2708
|
+
if (!configVariant) continue;
|
|
2709
|
+
const variantId = configVariant.variantId;
|
|
2710
|
+
let resolvedVersionData;
|
|
2711
|
+
if (rule.variantVersionId) resolvedVersionData = versionById.get(rule.variantVersionId);
|
|
2712
|
+
else resolvedVersionData = versionsByVariant.get(variantId)?.[0];
|
|
2713
|
+
if (!resolvedVersionData) continue;
|
|
2714
|
+
let conditions = null;
|
|
2715
|
+
if (rule.conditions) {
|
|
2716
|
+
const conditionsObj = typeof rule.conditions === "string" ? JSON.parse(rule.conditions) : rule.conditions;
|
|
2717
|
+
if (conditionsObj && Object.keys(conditionsObj).length > 0) conditions = conditionsObj;
|
|
2718
|
+
}
|
|
2719
|
+
const manifestRule = {
|
|
2720
|
+
id: rule.id,
|
|
2721
|
+
configVariantId: rule.configVariantId,
|
|
2722
|
+
variantVersionId: rule.variantVersionId,
|
|
2723
|
+
weight: rule.weight,
|
|
2724
|
+
priority: rule.priority,
|
|
2725
|
+
enabled: rule.enabled,
|
|
2726
|
+
conditions,
|
|
2727
|
+
resolvedVersion: buildVersion(resolvedVersionData)
|
|
2728
|
+
};
|
|
2729
|
+
if (!routingTable[rule.configId]) routingTable[rule.configId] = {};
|
|
2730
|
+
if (!routingTable[rule.configId][rule.environmentId]) routingTable[rule.configId][rule.environmentId] = [];
|
|
2731
|
+
routingTable[rule.configId][rule.environmentId].push(manifestRule);
|
|
2732
|
+
}
|
|
2733
|
+
for (const configRules of Object.values(routingTable)) for (const envRules of Object.values(configRules)) envRules.sort((a, b) => {
|
|
2734
|
+
if (b.priority !== a.priority) return b.priority - a.priority;
|
|
2735
|
+
return b.weight - a.weight;
|
|
2736
|
+
});
|
|
2737
|
+
return {
|
|
2738
|
+
version: Date.now(),
|
|
2739
|
+
builtAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2740
|
+
configs: manifestConfigs,
|
|
2741
|
+
configsBySlug,
|
|
2742
|
+
environments: manifestEnvironments,
|
|
2743
|
+
environmentsBySlug,
|
|
2744
|
+
routingTable,
|
|
2745
|
+
secretToEnvironment
|
|
2746
|
+
};
|
|
2747
|
+
}
|
|
2748
|
+
};
|
|
2749
|
+
|
|
2750
|
+
//#endregion
|
|
2751
|
+
//#region src/manifest/service.ts
|
|
2752
|
+
const MANIFEST_CACHE_KEY = "manifest";
|
|
2753
|
+
const MANIFEST_NAMESPACE = "gateway";
|
|
2754
|
+
const DEFAULT_TTL_MS = 300 * 1e3;
|
|
2755
|
+
const log = require_db.logger.child({ module: "ManifestService" });
|
|
2756
|
+
var ManifestService = class {
|
|
2757
|
+
builder;
|
|
2758
|
+
constructor(cache, db, ttlMs = DEFAULT_TTL_MS) {
|
|
2759
|
+
this.cache = cache;
|
|
2760
|
+
this.ttlMs = ttlMs;
|
|
2761
|
+
this.builder = new ManifestBuilder(db);
|
|
2762
|
+
log.debug({ ttlMs }, "ManifestService initialized");
|
|
2763
|
+
}
|
|
2764
|
+
/**
|
|
2765
|
+
* Get the current manifest, building if necessary
|
|
2766
|
+
*/
|
|
2767
|
+
async getManifest() {
|
|
2768
|
+
log.debug("Getting manifest from cache or building");
|
|
2769
|
+
const manifest = await this.cache.getOrSet(MANIFEST_CACHE_KEY, async () => {
|
|
2770
|
+
log.info("Building new manifest");
|
|
2771
|
+
const built = await this.builder.build();
|
|
2772
|
+
log.info({
|
|
2773
|
+
version: built.version,
|
|
2774
|
+
configCount: Object.keys(built.configs).length,
|
|
2775
|
+
environmentCount: Object.keys(built.environments).length
|
|
2776
|
+
}, "Manifest built successfully");
|
|
2777
|
+
return built;
|
|
2778
|
+
}, {
|
|
2779
|
+
namespace: MANIFEST_NAMESPACE,
|
|
2780
|
+
ttl: this.ttlMs
|
|
2781
|
+
});
|
|
2782
|
+
log.debug({ version: manifest.version }, "Manifest retrieved");
|
|
2783
|
+
return manifest;
|
|
2784
|
+
}
|
|
2785
|
+
/**
|
|
2786
|
+
* Force invalidate the manifest (called on mutations)
|
|
2787
|
+
*/
|
|
2788
|
+
async invalidate() {
|
|
2789
|
+
log.info("Invalidating manifest cache");
|
|
2790
|
+
await this.cache.delete(MANIFEST_CACHE_KEY, MANIFEST_NAMESPACE);
|
|
2791
|
+
}
|
|
2792
|
+
/**
|
|
2793
|
+
* Invalidate and immediately rebuild (atomic refresh)
|
|
2794
|
+
*/
|
|
2795
|
+
async refresh() {
|
|
2796
|
+
log.info("Refreshing manifest (invalidate + rebuild)");
|
|
2797
|
+
await this.invalidate();
|
|
2798
|
+
return this.getManifest();
|
|
2799
|
+
}
|
|
2800
|
+
/**
|
|
2801
|
+
* Get manifest version without fetching full manifest
|
|
2802
|
+
* Useful for checking if manifest is stale
|
|
2803
|
+
*/
|
|
2804
|
+
async getVersion() {
|
|
2805
|
+
const version = (await this.cache.get(MANIFEST_CACHE_KEY, MANIFEST_NAMESPACE))?.version ?? null;
|
|
2806
|
+
log.debug({ version }, "Got manifest version");
|
|
2807
|
+
return version;
|
|
2808
|
+
}
|
|
2809
|
+
/**
|
|
2810
|
+
* Check if manifest exists in cache
|
|
2811
|
+
*/
|
|
2812
|
+
async hasManifest() {
|
|
2813
|
+
const exists = await this.cache.has(MANIFEST_CACHE_KEY, MANIFEST_NAMESPACE);
|
|
2814
|
+
log.debug({ exists }, "Checked manifest existence");
|
|
2815
|
+
return exists;
|
|
2816
|
+
}
|
|
2817
|
+
};
|
|
2818
|
+
|
|
2819
|
+
//#endregion
|
|
2820
|
+
//#region src/manifest/router.ts
|
|
2821
|
+
/**
|
|
2822
|
+
* Router for evaluating the gateway manifest and selecting variants
|
|
2823
|
+
*/
|
|
2824
|
+
var ManifestRouter = class {
|
|
2825
|
+
constructor(manifest) {
|
|
2826
|
+
this.manifest = manifest;
|
|
2827
|
+
}
|
|
2828
|
+
/**
|
|
2829
|
+
* Resolve a config identifier (UUID or slug) to config ID
|
|
2830
|
+
*/
|
|
2831
|
+
resolveConfigId(configIdOrSlug) {
|
|
2832
|
+
if (this.manifest.configs[configIdOrSlug]) return configIdOrSlug;
|
|
2833
|
+
return this.manifest.configsBySlug[configIdOrSlug] ?? null;
|
|
2834
|
+
}
|
|
2835
|
+
/**
|
|
2836
|
+
* Resolve environment from secret value
|
|
2837
|
+
*/
|
|
2838
|
+
resolveEnvironmentFromSecret(secretValue) {
|
|
2839
|
+
return this.manifest.secretToEnvironment[secretValue] ?? null;
|
|
2840
|
+
}
|
|
2841
|
+
/**
|
|
2842
|
+
* Get production environment ID
|
|
2843
|
+
*/
|
|
2844
|
+
getProductionEnvironmentId() {
|
|
2845
|
+
for (const env of Object.values(this.manifest.environments)) if (env.isProd) return env.id;
|
|
2846
|
+
return null;
|
|
2847
|
+
}
|
|
2848
|
+
/**
|
|
2849
|
+
* Get environment by ID
|
|
2850
|
+
*/
|
|
2851
|
+
getEnvironment(environmentId) {
|
|
2852
|
+
return this.manifest.environments[environmentId] ?? null;
|
|
2853
|
+
}
|
|
2854
|
+
/**
|
|
2855
|
+
* Get config by ID
|
|
2856
|
+
*/
|
|
2857
|
+
getConfig(configId) {
|
|
2858
|
+
return this.manifest.configs[configId] ?? null;
|
|
2859
|
+
}
|
|
2860
|
+
/**
|
|
2861
|
+
* Route a request to the appropriate variant version (first match wins)
|
|
2862
|
+
*/
|
|
2863
|
+
route(configIdOrSlug, environmentId, context = {}) {
|
|
2864
|
+
const configId = this.resolveConfigId(configIdOrSlug);
|
|
2865
|
+
if (!configId) return null;
|
|
2866
|
+
const rules = this.manifest.routingTable[configId]?.[environmentId];
|
|
2867
|
+
if (!rules || rules.length === 0) return null;
|
|
2868
|
+
const evalContext = {
|
|
2869
|
+
...context,
|
|
2870
|
+
timestamp: context.timestamp ?? Date.now()
|
|
2871
|
+
};
|
|
2872
|
+
for (const rule of rules) {
|
|
2873
|
+
if (!rule.enabled) continue;
|
|
2874
|
+
if (rule.conditions) try {
|
|
2875
|
+
if (!json_logic_js.default.apply(rule.conditions, evalContext)) continue;
|
|
2876
|
+
} catch (error) {
|
|
2877
|
+
console.warn(`JSONLogic evaluation error for rule ${rule.id}:`, error);
|
|
2878
|
+
continue;
|
|
2879
|
+
}
|
|
2880
|
+
return {
|
|
2881
|
+
configId,
|
|
2882
|
+
environmentId,
|
|
2883
|
+
variantId: rule.resolvedVersion.variantId,
|
|
2884
|
+
version: rule.resolvedVersion,
|
|
2885
|
+
rule
|
|
2886
|
+
};
|
|
2887
|
+
}
|
|
2888
|
+
return null;
|
|
2889
|
+
}
|
|
2890
|
+
/**
|
|
2891
|
+
* Route with weighted random selection among matching rules of same priority
|
|
2892
|
+
*/
|
|
2893
|
+
routeWithWeights(configIdOrSlug, environmentId, context = {}) {
|
|
2894
|
+
const configId = this.resolveConfigId(configIdOrSlug);
|
|
2895
|
+
if (!configId) return null;
|
|
2896
|
+
const rules = this.manifest.routingTable[configId]?.[environmentId];
|
|
2897
|
+
if (!rules || rules.length === 0) return null;
|
|
2898
|
+
const evalContext = {
|
|
2899
|
+
...context,
|
|
2900
|
+
timestamp: context.timestamp ?? Date.now()
|
|
2901
|
+
};
|
|
2902
|
+
const rulesByPriority = /* @__PURE__ */ new Map();
|
|
2903
|
+
for (const rule$1 of rules) {
|
|
2904
|
+
if (!rule$1.enabled) continue;
|
|
2905
|
+
if (rule$1.conditions) try {
|
|
2906
|
+
if (!json_logic_js.default.apply(rule$1.conditions, evalContext)) continue;
|
|
2907
|
+
} catch {
|
|
2908
|
+
continue;
|
|
2909
|
+
}
|
|
2910
|
+
const list = rulesByPriority.get(rule$1.priority) || [];
|
|
2911
|
+
list.push(rule$1);
|
|
2912
|
+
rulesByPriority.set(rule$1.priority, list);
|
|
2913
|
+
}
|
|
2914
|
+
const priorities = Array.from(rulesByPriority.keys()).sort((a, b) => b - a);
|
|
2915
|
+
if (priorities.length === 0) return null;
|
|
2916
|
+
const topPriorityRules = rulesByPriority.get(priorities[0]);
|
|
2917
|
+
if (topPriorityRules.length === 1) {
|
|
2918
|
+
const rule$1 = topPriorityRules[0];
|
|
2919
|
+
return {
|
|
2920
|
+
configId,
|
|
2921
|
+
environmentId,
|
|
2922
|
+
variantId: rule$1.resolvedVersion.variantId,
|
|
2923
|
+
version: rule$1.resolvedVersion,
|
|
2924
|
+
rule: rule$1
|
|
2925
|
+
};
|
|
2926
|
+
}
|
|
2927
|
+
const totalWeight = topPriorityRules.reduce((sum, r) => sum + r.weight, 0);
|
|
2928
|
+
if (totalWeight === 0) return null;
|
|
2929
|
+
let random = Math.random() * totalWeight;
|
|
2930
|
+
for (const rule$1 of topPriorityRules) {
|
|
2931
|
+
random -= rule$1.weight;
|
|
2932
|
+
if (random <= 0) return {
|
|
2933
|
+
configId,
|
|
2934
|
+
environmentId,
|
|
2935
|
+
variantId: rule$1.resolvedVersion.variantId,
|
|
2936
|
+
version: rule$1.resolvedVersion,
|
|
2937
|
+
rule: rule$1
|
|
2938
|
+
};
|
|
2939
|
+
}
|
|
2940
|
+
const rule = topPriorityRules[0];
|
|
2941
|
+
return {
|
|
2942
|
+
configId,
|
|
2943
|
+
environmentId,
|
|
2944
|
+
variantId: rule.resolvedVersion.variantId,
|
|
2945
|
+
version: rule.resolvedVersion,
|
|
2946
|
+
rule
|
|
2947
|
+
};
|
|
2948
|
+
}
|
|
2949
|
+
};
|
|
2950
|
+
|
|
2611
2951
|
//#endregion
|
|
2612
2952
|
exports.CacheService = CacheService;
|
|
2613
2953
|
exports.FileCacheBackend = FileCacheBackend;
|
|
2614
2954
|
exports.MS = MS;
|
|
2955
|
+
exports.ManifestBuilder = ManifestBuilder;
|
|
2956
|
+
exports.ManifestRouter = ManifestRouter;
|
|
2957
|
+
exports.ManifestService = ManifestService;
|
|
2615
2958
|
exports.MemoryCacheBackend = MemoryCacheBackend;
|
|
2616
2959
|
exports.ModelsDevPricingProvider = ModelsDevPricingProvider;
|
|
2617
2960
|
exports.SCHEMA_METADATA = require_db.SCHEMA_METADATA;
|