mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-05 14:52:09 +03:00
v3.8.40 cycle integration → main. All test gates green (Unit/Integration/Coverage/Node-compat/Quality-Ratchet). The only red check, 'PR Test Policy', is the test-masking heuristic firing on the cumulative ~57-commit release diff (legitimate assert consolidations already reviewed per-PR — Gemini CLI removal #5246, retired GPT models #5280, provider catalog refreshes); overridden with --admin per the documented release-PR convention. CodeQL/SonarQube advisory scans non-blocking; #5278's code already passed CodeQL on main. Homologated on VPS 192.168.0.15 (v3.8.40 healthy).
45 lines
3.0 KiB
TypeScript
45 lines
3.0 KiB
TypeScript
"use client";
|
|
import { useCallback, useState } from "react";
|
|
import { previewToRunModel, type CompressionRunModel, type PreviewResponse } from "@/app/(dashboard)/dashboard/compression/studio/compressionFlowModel";
|
|
export interface PreviewMessage { role: string; content: unknown; }
|
|
export interface Lane { engine: string; run: CompressionRunModel | null; error: string | null; }
|
|
export interface PreviewBatch { lanes: Lane[]; combined: CompressionRunModel | null; diff: PreviewResponse["diff"] | null; riskGate: PreviewResponse["riskGate"] | null; heatmap: PreviewResponse["heatmap"] | null; }
|
|
export interface RunPreviewArgs { messages: PreviewMessage[]; laneEngines: string[]; activeEngines: string[]; language?: string; fidelityGate?: boolean; fuzzyDedup?: boolean; riskGate?: boolean; quantumLock?: boolean; heatmap?: "ultra" | "universal"; }
|
|
async function postPreview(payload: Record<string, unknown>): Promise<PreviewResponse> {
|
|
const res = await fetch("/api/compression/preview", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) });
|
|
const data = await res.json();
|
|
if (!res.ok) throw new Error(data.error ?? "Preview failed");
|
|
return data as PreviewResponse;
|
|
}
|
|
export async function runPreviewBatch(args: RunPreviewArgs): Promise<PreviewBatch> {
|
|
const { messages, laneEngines, activeEngines, fidelityGate, fuzzyDedup, riskGate, quantumLock, heatmap } = args;
|
|
const extra = {
|
|
...(fidelityGate ? { fidelityGate: { enabled: true } } : {}),
|
|
...(fuzzyDedup ? { fuzzyDedup: { enabled: true } } : {}),
|
|
...(riskGate ? { riskGate: { enabled: true } } : {}),
|
|
...(quantumLock ? { quantumLock: { enabled: true } } : {}),
|
|
...(heatmap ? { heatmap } : {}),
|
|
};
|
|
const lanes: Lane[] = await Promise.all(
|
|
laneEngines.map(async (engine): Promise<Lane> => {
|
|
try { const res = await postPreview({ messages, engineId: engine, ...extra }); return { engine, run: previewToRunModel(res, engine), error: null }; }
|
|
catch (e) { return { engine, run: null, error: e instanceof Error ? e.message : "error" }; }
|
|
})
|
|
);
|
|
let combined: CompressionRunModel | null = null;
|
|
let diff: PreviewResponse["diff"] | null = null;
|
|
let riskGateStats: PreviewResponse["riskGate"] | null = null;
|
|
let heatmapResult: PreviewResponse["heatmap"] | null = null;
|
|
if (activeEngines.length > 0) {
|
|
try { const res = await postPreview({ messages, pipeline: activeEngines, ...extra }); combined = previewToRunModel(res, activeEngines.join(" → ")); diff = res.diff; riskGateStats = res.riskGate ?? null; heatmapResult = res.heatmap ?? null; }
|
|
catch { combined = null; }
|
|
}
|
|
return { lanes, combined, diff, riskGate: riskGateStats, heatmap: heatmapResult };
|
|
}
|
|
export function usePreviewCompression() {
|
|
const [batch, setBatch] = useState<PreviewBatch | null>(null);
|
|
const [loading, setLoading] = useState(false);
|
|
const run = useCallback(async (args: RunPreviewArgs) => { setLoading(true); try { setBatch(await runPreviewBatch(args)); } finally { setLoading(false); } }, []);
|
|
return { batch, loading, run };
|
|
}
|