feat(antigravity): integrate Antigravity tool with MITM support and update CLI tools

This commit is contained in:
decolua 2026-02-08 16:28:13 +07:00
parent 18712b24cf
commit 2e854bd4c9
21 changed files with 1680 additions and 20 deletions

View file

@ -0,0 +1,41 @@
"use server";
import { NextResponse } from "next/server";
import { getMitmAlias, setMitmAliasAll } from "@/models";
// GET - Get MITM aliases for a tool
export async function GET(request) {
try {
const { searchParams } = new URL(request.url);
const toolName = searchParams.get("tool");
const aliases = await getMitmAlias(toolName || undefined);
return NextResponse.json({ aliases });
} catch (error) {
console.log("Error fetching MITM aliases:", error.message);
return NextResponse.json({ error: "Failed to fetch aliases" }, { status: 500 });
}
}
// PUT - Save MITM aliases for a specific tool
export async function PUT(request) {
try {
const { tool, mappings } = await request.json();
if (!tool || !mappings || typeof mappings !== "object") {
return NextResponse.json({ error: "tool and mappings required" }, { status: 400 });
}
const filtered = {};
for (const [alias, model] of Object.entries(mappings)) {
if (model && model.trim()) {
filtered[alias] = model.trim();
}
}
await setMitmAliasAll(tool, filtered);
return NextResponse.json({ success: true, aliases: filtered });
} catch (error) {
console.log("Error saving MITM aliases:", error.message);
return NextResponse.json({ error: "Failed to save aliases" }, { status: 500 });
}
}

View file

@ -0,0 +1,70 @@
"use server";
import { NextResponse } from "next/server";
import { getMitmStatus, startMitm, stopMitm, getCachedPassword, setCachedPassword } from "@/mitm/manager";
// GET - Check MITM status
export async function GET() {
try {
const status = await getMitmStatus();
return NextResponse.json({
running: status.running,
pid: status.pid || null,
dnsConfigured: status.dnsConfigured || false,
certExists: status.certExists || false,
hasCachedPassword: !!getCachedPassword(),
});
} catch (error) {
console.log("Error getting MITM status:", error.message);
return NextResponse.json({ error: "Failed to get MITM status" }, { status: 500 });
}
}
// POST - Start MITM proxy
export async function POST(request) {
try {
const { apiKey, sudoPassword } = await request.json();
const isWin = process.platform === "win32";
const pwd = sudoPassword || getCachedPassword() || "";
if (!apiKey || (!isWin && !pwd)) {
return NextResponse.json(
{ error: isWin ? "Missing apiKey" : "Missing apiKey or sudoPassword" },
{ status: 400 }
);
}
const result = await startMitm(apiKey, pwd);
if (!isWin) setCachedPassword(pwd);
return NextResponse.json({
success: true,
running: result.running,
pid: result.pid,
});
} catch (error) {
console.log("Error starting MITM:", error.message);
return NextResponse.json({ error: error.message || "Failed to start MITM proxy" }, { status: 500 });
}
}
// DELETE - Stop MITM proxy
export async function DELETE(request) {
try {
const { sudoPassword } = await request.json();
const isWin = process.platform === "win32";
const pwd = sudoPassword || getCachedPassword() || "";
if (!isWin && !pwd) {
return NextResponse.json({ error: "Missing sudoPassword" }, { status: 400 });
}
await stopMitm(pwd);
if (!isWin && sudoPassword) setCachedPassword(sudoPassword);
return NextResponse.json({ success: true, running: false });
} catch (error) {
console.log("Error stopping MITM:", error.message);
return NextResponse.json({ error: error.message || "Failed to stop MITM proxy" }, { status: 500 });
}
}

View file

@ -24,22 +24,6 @@ export async function PUT(request) {
return NextResponse.json({ error: "Model and alias required" }, { status: 400 });
}
const aliases = await getModelAliases();
// Check if alias already used by different model
const existingModel = aliases[alias];
if (existingModel && existingModel !== model) {
return NextResponse.json({
error: `Alias '${alias}' already in use for model '${existingModel}'`
}, { status: 400 });
}
// Delete old alias for this model (if exists and different from new alias)
const oldAlias = Object.entries(aliases).find(([a, m]) => m === model && a !== alias)?.[0];
if (oldAlias) {
await deleteModelAlias(oldAlias);
}
await setModelAlias(alias, model);
await syncToCloudIfEnabled();