From 01092fa349794dbd94db3fc77b2143c3a8c96bca Mon Sep 17 00:00:00 2001 From: diegosouzapw Date: Fri, 1 May 2026 22:00:04 -0300 Subject: [PATCH] fix: resolve runtime metadata and migration directory lookup Export shared runtime platform and architecture helpers so provider registry header generation uses the same process-based detection logic as header profiles instead of direct os module calls. Improve migration directory resolution by searching upward through common project layouts and checking multiple candidate paths before falling back to OMNIROUTE_MIGRATIONS_DIR errors. --- open-sse/config/providerHeaderProfiles.ts | 10 +++--- open-sse/config/providerRegistry.ts | 11 +++--- .../dashboard/providers/[id]/page.tsx | 1 + src/app/api/providers/[id]/route.ts | 4 +-- src/lib/db/migrationRunner.ts | 36 +++++++++++++------ 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/open-sse/config/providerHeaderProfiles.ts b/open-sse/config/providerHeaderProfiles.ts index 69c591652d..abeba69013 100644 --- a/open-sse/config/providerHeaderProfiles.ts +++ b/open-sse/config/providerHeaderProfiles.ts @@ -46,25 +46,25 @@ export function getGitHubCopilotChatHeaders( }; } -function getRuntimePlatform(): string { +export function getRuntimePlatform(): string { return typeof process !== "undefined" && typeof process.platform === "string" ? process.platform : "unknown"; } -function getRuntimeArch(): string { +export function getRuntimeArch(): string { return typeof process !== "undefined" && typeof process.arch === "string" ? process.arch : "unknown"; } -function getRuntimeVersion(): string { +export function getRuntimeVersion(): string { return typeof process !== "undefined" && typeof process.version === "string" ? process.version : "unknown"; } -function normalizeStainlessPlatform(platform: string = getRuntimePlatform()): string { +export function normalizeStainlessPlatform(platform: string = getRuntimePlatform()): string { const normalized = platform.toLowerCase(); if (normalized.includes("ios")) return "iOS"; if (normalized === "android") return "Android"; @@ -76,7 +76,7 @@ function normalizeStainlessPlatform(platform: string = getRuntimePlatform()): st return normalized ? `Other:${normalized}` : "Unknown"; } -function normalizeStainlessArch(arch: string = getRuntimeArch()): string { +export function normalizeStainlessArch(arch: string = getRuntimeArch()): string { if (arch === "x32") return "x32"; if (arch === "x86_64" || arch === "x64") return "x64"; if (arch === "arm") return "arm"; diff --git a/open-sse/config/providerRegistry.ts b/open-sse/config/providerRegistry.ts index c65d7f8f64..8265f3376f 100644 --- a/open-sse/config/providerRegistry.ts +++ b/open-sse/config/providerRegistry.ts @@ -6,7 +6,6 @@ * is auto-generated from this registry. */ -import { platform, arch } from "os"; import { ANTIGRAVITY_BASE_URLS } from "./antigravityUpstream.ts"; import { ANTIGRAVITY_PUBLIC_MODELS } from "./antigravityModelAliases.ts"; import { @@ -33,6 +32,8 @@ import { getKiroServiceHeaders, getQoderDefaultHeaders, getQwenOauthHeaders, + getRuntimePlatform, + getRuntimeArch, } from "./providerHeaderProfiles.ts"; import type { ProviderRequestDefaults } from "../services/providerRequestDefaults.ts"; @@ -245,7 +246,7 @@ const CHAT_OPENAI_COMPAT_MODELS: Record = { }; function mapStainlessOs() { - switch (platform()) { + switch (getRuntimePlatform()) { case "darwin": return "MacOS"; case "win32": @@ -253,12 +254,12 @@ function mapStainlessOs() { case "linux": return "Linux"; default: - return `Other::${platform()}`; + return `Other::${getRuntimePlatform()}`; } } function mapStainlessArch() { - switch (arch()) { + switch (getRuntimeArch()) { case "x64": return "x64"; case "arm64": @@ -266,7 +267,7 @@ function mapStainlessArch() { case "ia32": return "x86"; default: - return `other::${arch()}`; + return `other::${getRuntimeArch()}`; } } diff --git a/src/app/(dashboard)/dashboard/providers/[id]/page.tsx b/src/app/(dashboard)/dashboard/providers/[id]/page.tsx index 5e118a8764..d9095ee893 100644 --- a/src/app/(dashboard)/dashboard/providers/[id]/page.tsx +++ b/src/app/(dashboard)/dashboard/providers/[id]/page.tsx @@ -503,6 +503,7 @@ interface ConnectionRowConnection { providerSpecificData?: Record; expiresAt?: string; tokenExpiresAt?: string; + maxConcurrent?: number | null; } interface ConnectionRowProps { diff --git a/src/app/api/providers/[id]/route.ts b/src/app/api/providers/[id]/route.ts index 37f1f8ec90..f4fe213a9b 100644 --- a/src/app/api/providers/[id]/route.ts +++ b/src/app/api/providers/[id]/route.ts @@ -129,7 +129,7 @@ export async function PUT(request: Request, { params }: { params: Promise<{ id: providerSpecificData: incomingPsd, } = body; - const existing = await getProviderConnectionById(id); + const existing = (await getProviderConnectionById(id)) as Record | null; if (!existing) { return NextResponse.json({ error: "Connection not found" }, { status: 404 }); } @@ -244,7 +244,7 @@ export async function DELETE(request: Request, { params }: { params: Promise<{ i const { id } = await params; // Fetch connection before deleting to check provider type - const connection = await getProviderConnectionById(id); + const connection = (await getProviderConnectionById(id)) as Record | null; if (!connection) { return NextResponse.json({ error: "Connection not found" }, { status: 404 }); } diff --git a/src/lib/db/migrationRunner.ts b/src/lib/db/migrationRunner.ts index f3484dc214..ad2123c902 100644 --- a/src/lib/db/migrationRunner.ts +++ b/src/lib/db/migrationRunner.ts @@ -30,8 +30,25 @@ function resolveMigrationsDir(): string { return path.resolve(configuredDir); } + const checkLocations = (basePath: string) => { + const locations = [ + path.join(basePath, "migrations"), + path.join(basePath, "src", "lib", "db", "migrations"), + path.join(basePath, "app", "src", "lib", "db", "migrations"), + ]; + for (const loc of locations) { + if (fs.existsSync(loc)) return loc; + } + return null; + }; + try { - return path.join(path.dirname(fileURLToPath(import.meta.url)), "migrations"); + let currentDir = path.dirname(fileURLToPath(import.meta.url)); + while (currentDir !== path.dirname(currentDir)) { + const found = checkLocations(currentDir); + if (found) return found; + currentDir = path.dirname(currentDir); + } } catch { // Fall through to more defensive URL parsing below. } @@ -46,21 +63,20 @@ function resolveMigrationsDir(): string { const rawPath = decodeURIComponent( metaUrl.replace(/^file:\/\/\//, "/").replace(/^file:\/\//, "") ); - return path.join(path.dirname(path.resolve(rawPath)), "migrations"); + let currentDir = path.dirname(path.resolve(rawPath)); + while (currentDir !== path.dirname(currentDir)) { + const found = checkLocations(currentDir); + if (found) return found; + currentDir = path.dirname(currentDir); + } } catch { // Fall through to process.cwd fallback } } // Last resort: use process.cwd to find migrations relative to the app root - const cwdFallback = path.join(process.cwd(), "src", "lib", "db", "migrations"); - if (fs.existsSync(cwdFallback)) { - return cwdFallback; - } - const appFallback = path.join(process.cwd(), "app", "src", "lib", "db", "migrations"); - if (fs.existsSync(appFallback)) { - return appFallback; - } + const fromCwd = checkLocations(process.cwd()); + if (fromCwd) return fromCwd; throw new Error( "[Migration] Could not resolve migrations directory. Set OMNIROUTE_MIGRATIONS_DIR."