diff --git a/config/quality/eslint-suppressions.json b/config/quality/eslint-suppressions.json index 74a52b6a55..f865a7ba3b 100644 --- a/config/quality/eslint-suppressions.json +++ b/config/quality/eslint-suppressions.json @@ -230,11 +230,6 @@ "count": 1 } }, - "open-sse/handlers/chatCore/comboContextCache.ts": { - "no-restricted-imports": { - "count": 1 - } - }, "open-sse/handlers/chatCore/executorHelpers.ts": { "@typescript-eslint/no-unused-vars": { "count": 1 @@ -465,9 +460,6 @@ "@typescript-eslint/no-explicit-any": { "count": 17 }, - "no-restricted-imports": { - "count": 2 - }, "no-restricted-syntax": { "count": 1 } @@ -510,21 +502,11 @@ "count": 21 } }, - "open-sse/services/combo/concurrencyCaps.ts": { - "no-restricted-imports": { - "count": 1 - } - }, "open-sse/services/combo/providerWildcard.ts": { "@typescript-eslint/no-unused-vars": { "count": 1 } }, - "open-sse/services/combo/quotaExhaustionCutoff.ts": { - "no-restricted-imports": { - "count": 1 - } - }, "open-sse/services/comboAgentMiddleware.ts": { "@typescript-eslint/no-unused-vars": { "count": 1 @@ -621,11 +603,6 @@ "count": 2 } }, - "open-sse/services/keyGroupAuth.ts": { - "no-restricted-imports": { - "count": 1 - } - }, "open-sse/services/manifestAdapter.ts": { "@typescript-eslint/no-unused-vars": { "count": 3 @@ -689,9 +666,6 @@ "open-sse/services/tokenLimitCounter.ts": { "@typescript-eslint/no-unused-vars": { "count": 1 - }, - "no-restricted-imports": { - "count": 1 } }, "open-sse/services/tokenRefresh.ts": { @@ -827,11 +801,6 @@ "count": 1 } }, - "open-sse/utils/proxyFallback.ts": { - "no-restricted-imports": { - "count": 1 - } - }, "open-sse/utils/setupPolyfill.ts": { "@typescript-eslint/no-explicit-any": { "count": 5 @@ -1516,11 +1485,6 @@ "count": 1 } }, - "src/domain/quotaCache.ts": { - "no-restricted-imports": { - "count": 1 - } - }, "src/hooks/useLiveDashboard.ts": { "@typescript-eslint/no-unused-vars": { "count": 1 @@ -2035,11 +1999,6 @@ "count": 3 } }, - "src/models/index.ts": { - "no-restricted-imports": { - "count": 1 - } - }, "src/server/ws/liveServer.ts": { "@typescript-eslint/no-unused-vars": { "count": 5 @@ -2156,11 +2115,6 @@ "count": 1 } }, - "src/shared/services/apiKeyResolver.ts": { - "no-restricted-imports": { - "count": 1 - } - }, "src/shared/services/backupService.ts": { "@typescript-eslint/no-unused-vars": { "count": 1 @@ -2169,27 +2123,11 @@ "src/shared/services/cloudSyncScheduler.ts": { "@typescript-eslint/no-unused-vars": { "count": 1 - }, - "no-restricted-imports": { - "count": 1 } }, "src/shared/services/initializeCloudSync.ts": { "@typescript-eslint/no-unused-vars": { "count": 1 - }, - "no-restricted-imports": { - "count": 1 - } - }, - "src/shared/services/modelSyncScheduler.ts": { - "no-restricted-imports": { - "count": 1 - } - }, - "src/shared/utils/apiAuth.ts": { - "no-restricted-imports": { - "count": 1 } }, "src/shared/utils/apiKey.ts": { @@ -2200,9 +2138,6 @@ "src/shared/utils/apiKeyPolicy.ts": { "@typescript-eslint/no-unused-vars": { "count": 2 - }, - "no-restricted-imports": { - "count": 1 } }, "src/shared/utils/cloud.ts": { @@ -2300,11 +2235,6 @@ "count": 11 } }, - "src/sse/handlers/autoRouting.ts": { - "no-restricted-imports": { - "count": 1 - } - }, "src/sse/handlers/chat.ts": { "@typescript-eslint/no-unused-vars": { "count": 9 @@ -2313,24 +2243,6 @@ "src/sse/handlers/chatHelpers.ts": { "@typescript-eslint/no-unused-vars": { "count": 3 - }, - "no-restricted-imports": { - "count": 1 - } - }, - "src/sse/services/model.ts": { - "no-restricted-imports": { - "count": 2 - } - }, - "src/sse/services/noAuthProviderSettings.ts": { - "no-restricted-imports": { - "count": 1 - } - }, - "src/sse/services/tokenRefresh.ts": { - "no-restricted-imports": { - "count": 1 } }, "tests/benchmarks/pipeline-accuracy.test.ts": { diff --git a/open-sse/handlers/chatCore.ts b/open-sse/handlers/chatCore.ts index b82bf41cb8..d2e1785c34 100644 --- a/open-sse/handlers/chatCore.ts +++ b/open-sse/handlers/chatCore.ts @@ -1427,7 +1427,7 @@ export async function handleChatCore({ }; if ((isCombo && comboName) || routingComboId) { try { - const { getComboByName } = await import("../../src/lib/localDb"); + const { getComboByName } = await import("@/lib/db/combos"); let comboConfig = await getComboByName(comboName); if (!comboConfig && comboName?.startsWith("combo/")) { comboConfig = await getComboByName(comboName.substring(6)); @@ -1918,7 +1918,7 @@ export async function handleChatCore({ if (isCombo && comboName) { log?.info?.("CONTEXT", `Attempting to resolve combo limits for comboName=${comboName}`); try { - const { getComboByName } = await import("../../src/lib/localDb"); + const { getComboByName } = await import("@/lib/db/combos"); const { resolveComboTargets } = await import("../services/combo.ts"); let comboConfig = await getComboByName(comboName); if (!comboConfig && comboName.startsWith("combo/")) { @@ -4292,13 +4292,14 @@ export async function handleChatCore({ let quotaCooldownMs = kimiRateLimitResetAt ? Math.max(new Date(kimiRateLimitResetAt).getTime() - Date.now(), 0) : retryAfterMs || COOLDOWN_MS.rateLimit; - const deferAntigravityQuotaStateToCaller = - shouldDeferAntigravityQuotaStateToCaller( - provider, - typeof onStreamFailure === "function" - ); - const isAntigravityQuotaFamily = - shouldDeferAntigravityQuotaStateToCaller(provider, true); + const deferAntigravityQuotaStateToCaller = shouldDeferAntigravityQuotaStateToCaller( + provider, + typeof onStreamFailure === "function" + ); + const isAntigravityQuotaFamily = shouldDeferAntigravityQuotaStateToCaller( + provider, + true + ); let coreOwnedAntigravityLockout: { cooldownMs: number; failureCount: number; diff --git a/open-sse/handlers/chatCore/comboContextCache.ts b/open-sse/handlers/chatCore/comboContextCache.ts index 1a4f2c5b2c..266591b976 100644 --- a/open-sse/handlers/chatCore/comboContextCache.ts +++ b/open-sse/handlers/chatCore/comboContextCache.ts @@ -1,5 +1,4 @@ -import { getUpstreamProxyConfig } from "@/lib/localDb"; -import type { FallbackBackend } from "@/lib/db/upstreamProxy"; +import { FallbackBackend, getUpstreamProxyConfig } from "@/lib/db/upstreamProxy"; /** * Module-level cache for upstream proxy config (shared across all requests). @@ -29,7 +28,8 @@ const COMBOS_CACHE_TTL = 10_000; export async function getCombosCached(): Promise { const now = Date.now(); - const { getCombos, getCombosCacheVersion } = await import("@/lib/localDb"); + const { getCombos } = await import("@/lib/db/combos"); + const { getCombosCacheVersion } = await import("@/lib/db/readCache"); const version = getCombosCacheVersion(); // A combo write (create/update/delete/reorder) bumps the shared version via // invalidateDbCache("combos"); when it no longer matches our snapshot we drop diff --git a/open-sse/services/__tests__/volumeDetector.test.ts b/open-sse/services/__tests__/volumeDetector.test.ts index 7b71289478..37e278a82c 100644 --- a/open-sse/services/__tests__/volumeDetector.test.ts +++ b/open-sse/services/__tests__/volumeDetector.test.ts @@ -3,7 +3,7 @@ import { describe, it, expect, vi } from "vitest"; // Mock the DB so recommendStrategyOverride sees adaptiveVolumeRouting = true. // Without this the real getSettings() throws (no SQLite in test env), the // catch block fires, and the function returns noOverride before any rule runs. -vi.mock("@/lib/localDb", () => ({ +vi.mock("@/lib/db/settings", () => ({ getSettings: vi.fn().mockResolvedValue({ adaptiveVolumeRouting: true }), })); diff --git a/open-sse/services/batchProcessor.ts b/open-sse/services/batchProcessor.ts index e9fe915afd..7b242e4851 100644 --- a/open-sse/services/batchProcessor.ts +++ b/open-sse/services/batchProcessor.ts @@ -1,22 +1,20 @@ import { v4 as uuidv4 } from "uuid"; -import type { BatchItemCheckpoint, BatchRecord } from "@/lib/localDb"; import { + type BatchItemCheckpoint, + type BatchRecord, countBatchItemCheckpoints, - createFile, - deleteFile, ensureBatchItemCheckpoints, - getApiKeyById, getBatch, - getFileContent, getPendingBatches, getTerminalBatches, listBatchItemCheckpoints, - listFiles, markBatchItemError, markBatchItemProcessing, markBatchItemResult, updateBatch, -} from "@/lib/localDb"; +} from "@/lib/db/batches"; +import { createFile, deleteFile, getFileContent, listFiles } from "@/lib/db/files"; +import { getApiKeyById } from "@/lib/db/apiKeys"; import { dispatch } from "@/lib/batches/dispatch"; import type { SupportedBatchEndpoint } from "@/shared/constants/batchEndpoints"; import { DEFAULT_BATCH_EXPIRATION_SECONDS } from "@/shared/constants/batch"; diff --git a/open-sse/services/combo.ts b/open-sse/services/combo.ts index efdbd7c152..6d09b2bea1 100644 --- a/open-sse/services/combo.ts +++ b/open-sse/services/combo.ts @@ -427,7 +427,7 @@ export async function buildAutoCandidates( // apply, so auto-routing behavior is unchanged. const quotaCutoffEnabled = (resilienceSettings ?? resolveResilienceSettings(null))?.quotaPreflight?.enabled === true; - const { getPricingForModel } = await import("../../src/lib/localDb"); + const { getPricingForModel } = await import("@/lib/db/settings"); const quotaPromises = new Map>(); let historicalLatencyStats: Record = {}; try { @@ -1969,7 +1969,7 @@ async function handleComboChatInner({ const connId = effectiveConnectionId || undefined; void (async () => { try { - const { setLKGP } = await import("../../src/lib/localDb"); + const { setLKGP } = await import("@/lib/db/settings"); await Promise.all([ setLKGP(combo.name, target.executionKey, provider, connId), setLKGP(combo.name, combo.id || combo.name, provider, connId), @@ -3566,7 +3566,7 @@ async function handleRoundRobinCombo({ const connId = effectiveConnectionId || undefined; void (async () => { try { - const { setLKGP } = await import("../../src/lib/localDb"); + const { setLKGP } = await import("@/lib/db/settings"); await Promise.all([ setLKGP(combo.name, target.executionKey, provider, connId), setLKGP(combo.name, combo.id || combo.name, provider, connId), diff --git a/open-sse/services/combo/applyStrategyOrdering.ts b/open-sse/services/combo/applyStrategyOrdering.ts index e077082c5e..43fb1dd964 100644 --- a/open-sse/services/combo/applyStrategyOrdering.ts +++ b/open-sse/services/combo/applyStrategyOrdering.ts @@ -67,7 +67,7 @@ export async function applyStrategyOrdering( if (strategy === "lkgp") { try { - const { getLKGP } = await import("../../../src/lib/localDb"); + const { getLKGP } = await import("@/lib/db/settings"); const lkgpProvider = await getLKGP(combo.name, combo.id || combo.name); if (lkgpProvider) { diff --git a/open-sse/services/combo/concurrencyCaps.ts b/open-sse/services/combo/concurrencyCaps.ts index 3384352abb..f37cb3de30 100644 --- a/open-sse/services/combo/concurrencyCaps.ts +++ b/open-sse/services/combo/concurrencyCaps.ts @@ -19,7 +19,7 @@ * shrinking (Quality Gate / #3501). */ -import { getCachedProviderConnectionById } from "@/lib/localDb"; +import { getCachedProviderConnectionById } from "@/lib/db/readCache"; import { effectiveMaxConcurrency } from "./comboPredicates.ts"; import type { ResolvedComboTarget } from "./types.ts"; diff --git a/open-sse/services/combo/quotaExhaustionCutoff.ts b/open-sse/services/combo/quotaExhaustionCutoff.ts index 016e78ab63..2dc78dbe1b 100644 --- a/open-sse/services/combo/quotaExhaustionCutoff.ts +++ b/open-sse/services/combo/quotaExhaustionCutoff.ts @@ -19,7 +19,7 @@ import { type PreflightQuotaThresholds, type QuotaInfo, } from "../quotaPreflight.ts"; -import { getCachedProviderConnectionById } from "@/lib/localDb"; +import { getCachedProviderConnectionById } from "@/lib/db/readCache"; import { resolveResilienceSettings, type ResilienceSettings, @@ -109,8 +109,7 @@ export async function resolveQuotaExhaustionCutoffForTarget( let connection: Record | undefined; try { connection = (await getCachedProviderConnectionById(connectionId)) as - | Record - | undefined; + Record | undefined; } catch { connection = undefined; } diff --git a/open-sse/services/combo/resolveAutoStrategy.ts b/open-sse/services/combo/resolveAutoStrategy.ts index 45ef4b5c60..84ee43c43b 100644 --- a/open-sse/services/combo/resolveAutoStrategy.ts +++ b/open-sse/services/combo/resolveAutoStrategy.ts @@ -245,7 +245,7 @@ export async function resolveAutoStrategyOrder( let lastKnownGoodProvider: string | undefined; try { - const { getLKGP } = await import("../../../src/lib/localDb"); + const { getLKGP } = await import("@/lib/db/settings"); const lkgp = await getLKGP(combo.name, combo.id || combo.name); if (lkgp) lastKnownGoodProvider = lkgp.provider; } catch (err) { diff --git a/open-sse/services/combo/targetSorters.ts b/open-sse/services/combo/targetSorters.ts index 7ddd3e4509..384b776bf3 100644 --- a/open-sse/services/combo/targetSorters.ts +++ b/open-sse/services/combo/targetSorters.ts @@ -65,7 +65,7 @@ export function orderTargetsForWeightedFallback { try { - const { getPricingForModel } = await import("../../../src/lib/localDb"); + const { getPricingForModel } = await import("@/lib/db/settings"); const withCost = await Promise.all( models.map(async (modelStr) => { const parsed = parseModel(modelStr); diff --git a/open-sse/services/keyGroupAuth.ts b/open-sse/services/keyGroupAuth.ts index e6c34559a2..831af4d866 100644 --- a/open-sse/services/keyGroupAuth.ts +++ b/open-sse/services/keyGroupAuth.ts @@ -12,7 +12,7 @@ * - Provider-specific rules: "openai/gpt-4" */ -import { checkKeyModelAccess, getKeyGroupsForApiKey } from "@/lib/localDb"; +import { checkKeyModelAccess, getKeyGroupsForApiKey } from "@/lib/db/apiKeyGroups"; export interface KeyGroupAuthResult { /** Whether the request is authorized */ diff --git a/open-sse/services/model.ts b/open-sse/services/model.ts index 2c28b60953..ec0080ef83 100644 --- a/open-sse/services/model.ts +++ b/open-sse/services/model.ts @@ -332,7 +332,7 @@ function getProviderIdFromConnection(connection: unknown) { async function getActiveProviderSet() { try { - const { getCachedProviderConnections } = await import("@/lib/localDb"); + const { getCachedProviderConnections } = await import("@/lib/db/readCache"); const conns = (await getCachedProviderConnections()) as unknown[]; const providers = conns .map(getProviderIdFromConnection) @@ -345,7 +345,7 @@ async function getActiveProviderSet() { async function getActiveSyncedProvidersForModel(modelId: string) { try { - const { getActiveProvidersWithSyncedModel } = await import("@/lib/localDb"); + const { getActiveProvidersWithSyncedModel } = await import("@/lib/db/models"); const providers = await getActiveProvidersWithSyncedModel(modelId); return providers .map(resolveProviderAlias) @@ -403,7 +403,7 @@ function isTruthyEnv(value: string | undefined) { async function getPreferClaudeCodeForUnprefixedClaudeModels() { try { - const { getCachedSettings } = await import("@/lib/localDb"); + const { getCachedSettings } = await import("@/lib/db/readCache"); const settings = (await getCachedSettings()) as Record; if (typeof settings.preferClaudeCodeForUnprefixedClaudeModels === "boolean") { return settings.preferClaudeCodeForUnprefixedClaudeModels; diff --git a/open-sse/services/payloadRules.ts b/open-sse/services/payloadRules.ts index ad9a6415ad..651ae95f24 100644 --- a/open-sse/services/payloadRules.ts +++ b/open-sse/services/payloadRules.ts @@ -223,7 +223,7 @@ export function clearPayloadRulesConfigOverride() { // silently reverting to the (usually empty) file config. async function loadPayloadRulesFromSettings(): Promise { try { - const { getCachedSettings } = await import("@/lib/localDb"); + const { getCachedSettings } = await import("@/lib/db/readCache"); const settings = (await getCachedSettings()) as { payloadRules?: unknown }; const raw = settings?.payloadRules; if (raw === null || raw === undefined) return null; diff --git a/open-sse/services/rateLimitManager.ts b/open-sse/services/rateLimitManager.ts index bd793ae1ca..a8d99d0480 100644 --- a/open-sse/services/rateLimitManager.ts +++ b/open-sse/services/rateLimitManager.ts @@ -338,7 +338,8 @@ export async function initializeRateLimits() { applyBottleneckHeartbeatPatch(); try { - const { getCachedProviderConnections, getSettings } = await import("@/lib/localDb"); + const { getCachedProviderConnections } = await import("@/lib/db/readCache"); + const { getSettings } = await import("@/lib/db/settings"); const [connections, settings] = await Promise.all([ getCachedProviderConnections(), getSettings(), @@ -385,7 +386,7 @@ export async function applyRequestQueueSettings(nextSettings: RequestQueueSettin currentRequestQueueSettings = { ...nextSettings }; // Global policy changes invalidate snapshots from the previous generation. preservedReplacementSettings.clear(); - const { getCachedProviderConnections } = await import("@/lib/localDb"); + const { getCachedProviderConnections } = await import("@/lib/db/readCache"); const connections = await getCachedProviderConnections(); // Also discard any snapshot created while the asynchronous DB read yielded. preservedReplacementSettings.clear(); diff --git a/open-sse/services/tokenLimitCounter.ts b/open-sse/services/tokenLimitCounter.ts index cd69a9385b..707658238c 100644 --- a/open-sse/services/tokenLimitCounter.ts +++ b/open-sse/services/tokenLimitCounter.ts @@ -20,7 +20,7 @@ import { getTokenLimitsForRequest, logTokenLimitReset, type TokenLimit, -} from "@/lib/localDb"; +} from "@/lib/db/tokenLimits"; interface CacheEntry { windowStart: string; @@ -295,8 +295,7 @@ export function recordTokenUsage( ORDER BY window_start DESC LIMIT 1` ) .get(limit.id, windowStart) as - | { window_start?: string; tokens_used?: number } - | undefined; + { window_start?: string; tokens_used?: number } | undefined; const prevTokens = priorRow && typeof priorRow.tokens_used === "number" ? priorRow.tokens_used : 0; if (prevTokens > 0) { diff --git a/open-sse/services/volumeDetector.ts b/open-sse/services/volumeDetector.ts index 56a1e78450..9bb16d1335 100644 --- a/open-sse/services/volumeDetector.ts +++ b/open-sse/services/volumeDetector.ts @@ -155,7 +155,7 @@ export async function recommendStrategyOverride( // Check if adaptive routing is enabled globally try { - const { getSettings } = await import("@/lib/localDb"); + const { getSettings } = await import("@/lib/db/settings"); const settings = await getSettings(); if (!settings.adaptiveVolumeRouting) { return noOverride; diff --git a/open-sse/utils/networkProxy.ts b/open-sse/utils/networkProxy.ts index 82a95c5e0a..1499a918e6 100644 --- a/open-sse/utils/networkProxy.ts +++ b/open-sse/utils/networkProxy.ts @@ -20,7 +20,7 @@ async function getConfig() { if (_cachedConfig && now < _cacheExpiry) return _cachedConfig; try { - const { getProxyConfig } = await import("../../src/lib/localDb"); + const { getProxyConfig } = await import("@/lib/db/settings"); _cachedConfig = await getProxyConfig(); _cacheExpiry = now + 30_000; // Cache for 30s return _cachedConfig; diff --git a/open-sse/utils/proxyFallback.ts b/open-sse/utils/proxyFallback.ts index 6d7590034c..5590dbd16a 100644 --- a/open-sse/utils/proxyFallback.ts +++ b/open-sse/utils/proxyFallback.ts @@ -10,7 +10,8 @@ import { fetch as undiciFetch } from "undici"; import { createProxyDispatcher, normalizeProxyUrl } from "./proxyDispatcher.ts"; -import { resolveProxyForScopeFromRegistry, listProxies, listOneproxyProxies } from "@/lib/localDb"; +import { resolveProxyForScopeFromRegistry, listProxies } from "@/lib/db/proxies"; +import { listOneproxyProxies } from "@/lib/db/oneproxy"; import { isFeatureFlagEnabled } from "@/shared/utils/featureFlags"; // --------------------------------------------------------------------------- diff --git a/src/domain/quotaCache.ts b/src/domain/quotaCache.ts index 3d5cf1a2e5..377512ee13 100644 --- a/src/domain/quotaCache.ts +++ b/src/domain/quotaCache.ts @@ -17,7 +17,8 @@ */ import { getUsageForProvider } from "@omniroute/open-sse/services/usage.ts"; -import { getCachedProviderConnectionById, resolveProxyForConnection } from "@/lib/localDb"; +import { getCachedProviderConnectionById } from "@/lib/db/readCache"; +import { resolveProxyForConnection } from "@/lib/db/settings"; import { runWithProxyContext } from "@omniroute/open-sse/utils/proxyFetch.ts"; import { safePercentage } from "@/shared/utils/formatting"; import { diff --git a/src/models/index.ts b/src/models/index.ts index 90b3c78b11..39e8828c12 100755 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -1,4 +1,4 @@ -// Database Models - Export all from localDb +// Database Models - Export all from the owning db modules export { getProviderConnections, getProviderConnectionsCount, @@ -15,17 +15,16 @@ export { updateProviderNode, deleteProviderNode, deleteProviderConnectionsByProvider, +} from "@/lib/db/providers"; +export { getModelAliases, setModelAlias, deleteModelAlias, deleteModelAliasesForProvider, getMitmAlias, setMitmAliasAll, - getApiKeys, - createApiKey, - deleteApiKey, - validateApiKey, - isCloudEnabled, - resolveProxyForProvider, getHiddenModelsByProvider, -} from "@/lib/localDb"; +} from "@/lib/db/models"; +export { getApiKeys, createApiKey, deleteApiKey, validateApiKey } from "@/lib/db/apiKeys"; +export { isCloudEnabled } from "@/lib/db/settings"; +export { resolveProxyForProvider } from "@/lib/db/proxies"; diff --git a/src/shared/services/apiKeyResolver.ts b/src/shared/services/apiKeyResolver.ts index e79bc9bd99..003be6443f 100644 --- a/src/shared/services/apiKeyResolver.ts +++ b/src/shared/services/apiKeyResolver.ts @@ -1,4 +1,4 @@ -import { getApiKeyById, createApiKey } from "@/lib/localDb"; +import { getApiKeyById, createApiKey } from "@/lib/db/apiKeys"; import { getConsistentMachineId } from "@/shared/utils/machineId"; export async function resolveApiKey( diff --git a/src/shared/services/cloudSyncScheduler.ts b/src/shared/services/cloudSyncScheduler.ts index d56e5cd237..ec2605d0f9 100644 --- a/src/shared/services/cloudSyncScheduler.ts +++ b/src/shared/services/cloudSyncScheduler.ts @@ -1,5 +1,5 @@ import { getConsistentMachineId } from "@/shared/utils/machineId"; -import { isCloudEnabled } from "@/lib/localDb"; +import { isCloudEnabled } from "@/lib/db/settings"; import { getRuntimePorts } from "@/lib/runtime/ports"; const { dashboardPort } = getRuntimePorts(); diff --git a/src/shared/services/initializeCloudSync.ts b/src/shared/services/initializeCloudSync.ts index 78fdc7b4ad..631b4391ae 100644 --- a/src/shared/services/initializeCloudSync.ts +++ b/src/shared/services/initializeCloudSync.ts @@ -1,5 +1,6 @@ import { getCloudSyncScheduler } from "@/shared/services/cloudSyncScheduler"; -import { isCloudEnabled, cleanupProviderConnections } from "@/lib/localDb"; +import { isCloudEnabled } from "@/lib/db/settings"; +import { cleanupProviderConnections } from "@/lib/db/providers"; /** * Initialize cloud sync scheduler diff --git a/src/shared/services/modelSyncScheduler.ts b/src/shared/services/modelSyncScheduler.ts index f45bc194f4..c63a5e50ac 100644 --- a/src/shared/services/modelSyncScheduler.ts +++ b/src/shared/services/modelSyncScheduler.ts @@ -10,7 +10,7 @@ import { randomUUID } from "node:crypto"; import { Agent, buildConnector, fetch as undiciFetch, type Dispatcher } from "undici"; -import { getSettings, updateSettings } from "@/lib/localDb"; +import { getSettings, updateSettings } from "@/lib/db/settings"; import { isConnectionUnavailableToAuxiliaryActivity } from "@/lib/exclusiveLeaseIsolation"; import { getRuntimePorts } from "@/lib/runtime/ports"; @@ -151,7 +151,7 @@ async function getAutoSyncConnections(): Promise< Array<{ id: string; provider: string; name?: string }> > { try { - const { getProviderConnections } = await import("@/lib/localDb"); + const { getProviderConnections } = await import("@/lib/db/providers"); const connections = await getProviderConnections(); const autoSyncConnections: Array<{ id: string; provider: string; name?: string }> = []; for (const conn of connections) { diff --git a/src/shared/utils/apiAuth.ts b/src/shared/utils/apiAuth.ts index 8a40c493de..d53c72ea9e 100644 --- a/src/shared/utils/apiAuth.ts +++ b/src/shared/utils/apiAuth.ts @@ -9,7 +9,7 @@ import { jwtVerify } from "jose"; import { cookies } from "next/headers"; -import { getSettings } from "@/lib/localDb"; +import { getSettings } from "@/lib/db/settings"; import { isPublicApiRoute } from "@/shared/constants/publicApiRoutes"; import { extractApiKey } from "@/sse/services/auth"; diff --git a/src/shared/utils/apiKeyPolicy.ts b/src/shared/utils/apiKeyPolicy.ts index ebd23c9ead..49cb628bb0 100644 --- a/src/shared/utils/apiKeyPolicy.ts +++ b/src/shared/utils/apiKeyPolicy.ts @@ -9,12 +9,8 @@ */ import { extractApiKey } from "@/sse/services/auth"; -import { - getApiKeyMetadata, - getComboByName, - isModelAllowedForKey, - getApiKeyById, -} from "@/lib/localDb"; +import { getApiKeyMetadata, isModelAllowedForKey, getApiKeyById } from "@/lib/db/apiKeys"; +import { getComboByName } from "@/lib/db/combos"; import { isDashboardSessionAuthenticated } from "./apiAuth"; import { resolveComboForModel } from "@/lib/db/modelComboMappings"; import { checkBudget } from "@/domain/costRules"; diff --git a/src/sse/handlers/autoRouting.ts b/src/sse/handlers/autoRouting.ts index 8920c71d33..d76b1e2340 100644 --- a/src/sse/handlers/autoRouting.ts +++ b/src/sse/handlers/autoRouting.ts @@ -14,7 +14,7 @@ import { isValidModelFamily, type ModelFamily, } from "@omniroute/open-sse/services/autoCombo/modelFamily.ts"; -import { getCachedSettings } from "@/lib/localDb"; +import { getCachedSettings } from "@/lib/db/readCache"; import * as log from "../utils/logger"; export type AutoRoutingState = { diff --git a/src/sse/handlers/chatHelpers.ts b/src/sse/handlers/chatHelpers.ts index f1db55f6e8..958d934573 100644 --- a/src/sse/handlers/chatHelpers.ts +++ b/src/sse/handlers/chatHelpers.ts @@ -1,4 +1,8 @@ -import { getModelInfo, getComboForModel, getModelInfoOrRetirementResponse } from "../services/model"; +import { + getModelInfo, + getComboForModel, + getModelInfoOrRetirementResponse, +} from "../services/model"; import { clearAccountError, markAccountUnavailable } from "../services/auth"; import { connectionHasExtraKeys } from "@omniroute/open-sse/services/apiKeyRotator.ts"; import { createBuiltinAutoCombo } from "@omniroute/open-sse/services/autoCombo/builtinCatalog.ts"; @@ -26,7 +30,7 @@ import { isTlsFingerprintActive, type AppliedProxySink, } from "@omniroute/open-sse/utils/proxyFetch.ts"; -import { resolveProxyForConnection } from "@/lib/localDb"; +import { resolveProxyForConnection } from "@/lib/db/settings"; import { hasBlockingProxyAssignment } from "@/lib/db/proxies"; import { CircuitBreakerOpenError, diff --git a/src/sse/services/model.ts b/src/sse/services/model.ts index b28e3e5d2f..a1fe37f238 100644 --- a/src/sse/services/model.ts +++ b/src/sse/services/model.ts @@ -1,15 +1,9 @@ // Re-export from open-sse with localDb integration -import { - getModelAliases, - getComboByName, - getComboById, - getComboByNameInsensitive, - getCachedProviderNodes, - getCustomModels, -} from "@/lib/localDb"; +import { getModelAliases, getCustomModels } from "@/lib/db/models"; +import { getComboByName, getComboById, getComboByNameInsensitive } from "@/lib/db/combos"; +import { getCachedProviderNodes, getCachedSettings } from "@/lib/db/readCache"; import { getSyncedAutoAliases } from "@/lib/providerModels/syncedAutoAliases.ts"; -import { getCachedSettings } from "@/lib/localDb"; import { getActiveSyncedCatalog } from "@/lib/db/models/activeSyncedCatalog"; import { getModelCompatOverrides } from "@/lib/db/models/compat"; import { getNoAuthHydrationProviderIds } from "./noAuthProviderSiblings"; @@ -660,7 +654,7 @@ export async function getComboForModel(modelStr) { // 2. NEW — check model-combo mappings table (pattern match) try { - const { resolveComboForModel } = await import("@/lib/localDb"); + const { resolveComboForModel } = await import("@/lib/db/modelComboMappings"); const mapped = await resolveComboForModel(baseModelStr || modelStr); if (mapped && (mapped as any).models?.length > 0) { return mapped; diff --git a/src/sse/services/noAuthProviderSettings.ts b/src/sse/services/noAuthProviderSettings.ts index dee365c5f1..f700e2dc6f 100644 --- a/src/sse/services/noAuthProviderSettings.ts +++ b/src/sse/services/noAuthProviderSettings.ts @@ -1,4 +1,4 @@ -import { getSettings } from "@/lib/localDb"; +import { getSettings } from "@/lib/db/settings"; import { isProviderBlockedByIdOrAlias } from "@/shared/utils/noAuthProviders"; import * as log from "../utils/logger"; diff --git a/src/sse/services/tokenRefresh.ts b/src/sse/services/tokenRefresh.ts index 4955cb8247..f7e65b1173 100755 --- a/src/sse/services/tokenRefresh.ts +++ b/src/sse/services/tokenRefresh.ts @@ -1,10 +1,8 @@ // Re-export from open-sse with local logger import * as log from "../utils/logger"; -import { - updateProviderConnection, - resolveProxyForConnection, - resolveProxyForProvider, -} from "@/lib/localDb"; +import { updateProviderConnection } from "@/lib/db/providers"; +import { resolveProxyForConnection } from "@/lib/db/settings"; +import { resolveProxyForProvider } from "@/lib/db/proxies"; import { TOKEN_EXPIRY_BUFFER_MS as BUFFER_MS, getRefreshLeadMs as _getRefreshLeadMs,