mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
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.
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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<string, RegistryModel[]> = {
|
||||
};
|
||||
|
||||
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()}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -503,6 +503,7 @@ interface ConnectionRowConnection {
|
||||
providerSpecificData?: Record<string, unknown>;
|
||||
expiresAt?: string;
|
||||
tokenExpiresAt?: string;
|
||||
maxConcurrent?: number | null;
|
||||
}
|
||||
|
||||
interface ConnectionRowProps {
|
||||
|
||||
@@ -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<string, any> | 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<string, any> | null;
|
||||
if (!connection) {
|
||||
return NextResponse.json({ error: "Connection not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
@@ -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."
|
||||
|
||||
Reference in New Issue
Block a user