mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 15:22:12 +03:00
feat(cliproxyapi): add version manager service, API routes, CLI Tools UI & Docker
Part 3 of CLIProxyAPI integration (#902). Depends on PR1 + PR2. - releaseChecker.ts: GitHub releases API with 5min cache - binaryManager.ts: download, SHA256 verify, install, symlink, rollback - processManager.ts: spawn, graceful stop (SIGTERM→SIGKILL with interval cleanup), restart - healthMonitor.ts: periodic /v1/models health checks - index.ts: orchestrator (install/start/stop/restart/checkUpdates/pin/rollback) - 6 API routes under /api/version-manager/ with Zod validation - CliproxyapiToolCard: CLI Tools page card - Docker: cliproxyapi profile with sidecar service + healthcheck - 78 unit tests across 5 test files
This commit is contained in:
16
src/app/api/version-manager/check-update/route.ts
Normal file
16
src/app/api/version-manager/check-update/route.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
"use server";
|
||||
|
||||
import { NextResponse } from "next/server";
|
||||
import { checkForUpdates } from "@/lib/versionManager";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tool = searchParams.get("tool") || "cliproxyapi";
|
||||
const result = await checkForUpdates(tool);
|
||||
return NextResponse.json(result);
|
||||
} catch (error) {
|
||||
console.error("[version-manager] check-update error:", error);
|
||||
return NextResponse.json({ error: "Failed to check for updates" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
30
src/app/api/version-manager/install/route.ts
Normal file
30
src/app/api/version-manager/install/route.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
"use server";
|
||||
|
||||
import { NextResponse } from "next/server";
|
||||
import { installTool } from "@/lib/versionManager";
|
||||
import { versionManagerInstallSchema } from "@/shared/validation/schemas";
|
||||
import { isValidationFailure, validateBody } from "@/shared/validation/helpers";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
let rawBody;
|
||||
try {
|
||||
rawBody = await request.json();
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Invalid JSON body" }, { status: 400 });
|
||||
}
|
||||
|
||||
const validation = validateBody(versionManagerInstallSchema, rawBody);
|
||||
if (isValidationFailure(validation)) {
|
||||
return NextResponse.json({ error: validation.error }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const { tool, version } = validation.data;
|
||||
const result = await installTool(tool, version || undefined);
|
||||
return NextResponse.json({ success: true, ...result });
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Installation failed";
|
||||
console.error("[version-manager] install error:", message);
|
||||
return NextResponse.json({ error: message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
30
src/app/api/version-manager/restart/route.ts
Normal file
30
src/app/api/version-manager/restart/route.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
"use server";
|
||||
|
||||
import { NextResponse } from "next/server";
|
||||
import { restartTool } from "@/lib/versionManager";
|
||||
import { versionManagerToolSchema } from "@/shared/validation/schemas";
|
||||
import { isValidationFailure, validateBody } from "@/shared/validation/helpers";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
let rawBody;
|
||||
try {
|
||||
rawBody = await request.json();
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Invalid JSON body" }, { status: 400 });
|
||||
}
|
||||
|
||||
const validation = validateBody(versionManagerToolSchema, rawBody);
|
||||
if (isValidationFailure(validation)) {
|
||||
return NextResponse.json({ error: validation.error }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const { tool } = validation.data;
|
||||
const result = await restartTool(tool);
|
||||
return NextResponse.json({ success: true, ...result });
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Failed to restart";
|
||||
console.error("[version-manager] restart error:", message);
|
||||
return NextResponse.json({ error: message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
30
src/app/api/version-manager/start/route.ts
Normal file
30
src/app/api/version-manager/start/route.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
"use server";
|
||||
|
||||
import { NextResponse } from "next/server";
|
||||
import { startTool } from "@/lib/versionManager";
|
||||
import { versionManagerToolSchema } from "@/shared/validation/schemas";
|
||||
import { isValidationFailure, validateBody } from "@/shared/validation/helpers";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
let rawBody;
|
||||
try {
|
||||
rawBody = await request.json();
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Invalid JSON body" }, { status: 400 });
|
||||
}
|
||||
|
||||
const validation = validateBody(versionManagerToolSchema, rawBody);
|
||||
if (isValidationFailure(validation)) {
|
||||
return NextResponse.json({ error: validation.error }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const { tool } = validation.data;
|
||||
const result = await startTool(tool);
|
||||
return NextResponse.json({ success: true, ...result });
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Failed to start";
|
||||
console.error("[version-manager] start error:", message);
|
||||
return NextResponse.json({ error: message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
14
src/app/api/version-manager/status/route.ts
Normal file
14
src/app/api/version-manager/status/route.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
"use server";
|
||||
|
||||
import { NextResponse } from "next/server";
|
||||
import { getVersionManagerStatus } from "@/lib/versionManager";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const status = await getVersionManagerStatus();
|
||||
return NextResponse.json(status);
|
||||
} catch (error) {
|
||||
console.error("[version-manager] status error:", error);
|
||||
return NextResponse.json({ error: "Failed to get status" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
30
src/app/api/version-manager/stop/route.ts
Normal file
30
src/app/api/version-manager/stop/route.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
"use server";
|
||||
|
||||
import { NextResponse } from "next/server";
|
||||
import { stopTool } from "@/lib/versionManager";
|
||||
import { versionManagerToolSchema } from "@/shared/validation/schemas";
|
||||
import { isValidationFailure, validateBody } from "@/shared/validation/helpers";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
let rawBody;
|
||||
try {
|
||||
rawBody = await request.json();
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Invalid JSON body" }, { status: 400 });
|
||||
}
|
||||
|
||||
const validation = validateBody(versionManagerToolSchema, rawBody);
|
||||
if (isValidationFailure(validation)) {
|
||||
return NextResponse.json({ error: validation.error }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const { tool } = validation.data;
|
||||
await stopTool(tool);
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Failed to stop";
|
||||
console.error("[version-manager] stop error:", message);
|
||||
return NextResponse.json({ error: message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user