Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion open-sse/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export const PROVIDER_PROFILES = {
providerCooldownMs: 600000, // 10min cooldown when threshold reached
degradationThreshold: 7,
maxBackoffMultiplier: 4,
backoffEscalationCount: 3
backoffEscalationCount: 3,
},
// Local providers (localhost inference backends like Ollama, LM Studio, oMLX).
// Not yet wired into getProviderProfile() — will be used when local provider_nodes
Expand Down
6 changes: 3 additions & 3 deletions open-sse/services/accountFallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,9 @@ function configureProviderBreaker(
classifyError: classify429FromError,
}
: {}),
degradationThreshold: resolvedProfile.degradationThreshold,
maxBackoffMultiplier: resolvedProfile.maxBackoffMultiplier,
backoffEscalationCount: resolvedProfile.backoffEscalationCount,
degradationThreshold: resolvedProfile.degradationThreshold,
maxBackoffMultiplier: resolvedProfile.maxBackoffMultiplier,
backoffEscalationCount: resolvedProfile.backoffEscalationCount,
});
}

Expand Down
8 changes: 2 additions & 6 deletions open-sse/services/credentialGate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface CredentialGateResult {
export function checkCredentialGate(
connectionId: string,
provider: string,
modelStr: string,
modelStr: string
): CredentialGateResult {
// 1. Check cache (sub-millisecond)
const healthy = isCredentialHealthy(connectionId);
Expand Down Expand Up @@ -74,11 +74,7 @@ export function checkCredentialGate(
* Log a credential gate skip event.
* This emits a structured warning for observability.
*/
export function logCredentialSkip(
log: any,
modelStr: string,
reason: string,
): void {
export function logCredentialSkip(log: any, modelStr: string, reason: string): void {
if (log?.info) {
log.info("CREDENTIAL_GATE", reason);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
"use client";

import { useState, useEffect, useCallback } from "react";
import Button from "@/shared/components/Button";
import Card from "@/shared/components/Card";
import Badge from "@/shared/components/Badge";

// ── Types ────────────────────────────────────────────────────────────────────

interface TargetSimulation {
provider: string;
model: string;
strategy: string;
rank: number;
estimatedCost: number;
estimatedLatencyMs: number;
status: "available" | "no_quota" | "degraded" | "error" | "unknown";
maxTokens?: number;
contextWindow?: number;
}

interface SimulateResponse {
comboId?: string;
comboName: string;
strategy: string;
targets: TargetSimulation[];
totalEstimatedCost: number;
totalEstimatedLatencyMs: number;
warnings: string[];
errors: string[];
}

interface Combo {
id: string;
name: string;
strategy: string;
targets: string;
isActive: boolean;
}

// ── Status helpers ───────────────────────────────────────────────────────────

function StatusTag({ status }: { status: TargetSimulation["status"] }) {
const map: Record<TargetSimulation["status"], { label: string; variant: "success" | "error" | "warning" | "info" }> = {
available: { label: "Available", variant: "success" },
no_quota: { label: "No Quota", variant: "error" },
degraded: { label: "Degraded", variant: "warning" },
error: { label: "Error", variant: "error" },
unknown: { label: "Unknown", variant: "info" },
};
return <Badge variant={map[status].variant} size="sm">{map[status].label}</Badge>;
}

// ── Component ────────────────────────────────────────────────────────────────

export default function ComboPlaygroundClient() {
const [combos, setCombos] = useState<Combo[]>([]);
const [selectedComboId, setSelectedComboId] = useState("");
const [promptTokens, setPromptTokens] = useState(500);
const [loading, setLoading] = useState(false);
const [result, setResult] = useState<SimulateResponse | null>(null);

// Fetch combos on mount
useEffect(() => {
fetch("/api/combos")
.then((r) => r.json())
.then((data) => {
const list: Combo[] = Array.isArray(data) ? data : data?.combos ?? data?.data ?? [];
setCombos(list);
if (list.length > 0) setSelectedComboId(list[0].id);
})
.catch(() => {});
}, []);

const simulate = useCallback(async () => {
if (!selectedComboId) return;
setLoading(true);
setResult(null);

try {
const res = await fetch("/api/playground/simulate-route", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
comboId: selectedComboId,
promptTokens,
}),
});
const data = await res.json();
if (res.ok) setResult(data);
else setResult(data);
Comment on lines +90 to +91

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If the API request fails (e.g., 400 or 500), the returned JSON does not match the SimulateResponse interface (it lacks the targets array). Setting this as the result will cause the component to crash when attempting to map over result.targets at line 191. Handle API errors by using a safe fallback state.

      if (res.ok) {
        setResult(data);
      } else {
        setResult({
          comboName: "Error",
          strategy: "-",
          targets: [],
          totalEstimatedCost: 0,
          totalEstimatedLatencyMs: 0,
          warnings: [],
          errors: [data.error || "Unknown simulation error"],
        });
      }

} catch {
setResult({
comboName: "Error",
strategy: "-",
targets: [],
totalEstimatedCost: 0,
totalEstimatedLatencyMs: 0,
warnings: [],
errors: ["Network error during simulation"],
});
} finally {
setLoading(false);
}
}, [selectedComboId, promptTokens]);

return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-xl font-bold">Combo Playground</h1>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

User-facing strings should not be hardcoded. Use the useTranslations hook from next-intl to manage localized strings, ensuring consistency with the rest of the dashboard.

<p className="text-sm text-text-muted mt-1">
Simulate how requests will be routed through your combos
</p>
</div>
</div>

{/* Configuration Panel */}
<Card>
<div className="p-4 space-y-4">
<h2 className="text-sm font-semibold">Configuration</h2>

<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{/* Combo Selector */}
<div>
<label className="block text-sm font-medium mb-1">Combo</label>
<select
className="w-full border border-border rounded-lg px-3 py-2 bg-surface text-sm"
value={selectedComboId}
onChange={(e) => setSelectedComboId(e.target.value)}
>
{combos.length === 0 && <option value="">No combos configured</option>}
{combos.map((c) => (
<option key={c.id} value={c.id}>
{c.name} ({c.strategy}, {c.isActive ? "active" : "inactive"})
</option>
))}
</select>
</div>

{/* Prompt Tokens */}
<div>
<label className="block text-sm font-medium mb-1">
Estimated Prompt Tokens: <strong>{promptTokens}</strong>
</label>
<input
type="range"
min={100}
max={100000}
step={100}
value={promptTokens}
onChange={(e) => setPromptTokens(Number(e.target.value))}
className="w-full"
/>
<div className="flex justify-between text-xs text-text-muted mt-1">
<span>100</span>
<span>100K</span>
</div>
</div>
</div>

<Button onClick={simulate} disabled={loading || combos.length === 0}>
{loading ? "Simulating..." : "Simulate Route"}
</Button>
</div>
</Card>

{/* Results */}
{result && (
<>
{/* Combo Overview */}
<Card>
<div className="p-4 space-y-3">
<div className="flex items-center justify-between">
<h2 className="text-sm font-semibold">Routing Path</h2>
<div className="flex items-center gap-3 text-sm">
<span className="text-text-muted">
Strategy: <strong>{result.strategy}</strong>
</span>
<span className="text-text-muted">
Est. Cost: <strong>${result.totalEstimatedCost.toFixed(6)}</strong>
</span>
<span className="text-text-muted">
Est. Latency: <strong>{result.totalEstimatedLatencyMs.toFixed(0)}ms</strong>
</span>
</div>
</div>

{/* Visual Cascade */}
<div className="space-y-0">
{result.targets.map((t, i) => (
<div key={i}>
{/* Arrow between targets */}
{i > 0 && (
<div className="flex justify-center py-1">
<div className="flex flex-col items-center text-text-muted">
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 14l-7 7m0 0l-7-7m7 7V3" />
</svg>
{result.strategy === "priority" && (
<span className="text-[10px]">fallback</span>
)}
{result.strategy === "weighted" && (
<span className="text-[10px]">weight {t.rank}</span>
)}
</div>
</div>
)}

{/* Target Card */}
<div
className={`border rounded-lg p-3 ${
t.status === "available"
? "border-green-500/30 bg-green-500/5"
: t.status === "error"
? "border-red-500/30 bg-red-500/5"
: t.status === "unknown"
? "border-yellow-500/30 bg-yellow-500/5"
: "border-border bg-surface/50"
}`}
>
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<div className="flex items-center justify-center w-6 h-6 rounded-full bg-primary/10 text-primary text-xs font-bold">
{t.rank}
</div>
<div>
<div className="font-medium text-sm">{t.provider}</div>
<div className="text-xs text-text-muted font-mono">{t.model}</div>
</div>
</div>
<div className="flex items-center gap-3">
<StatusTag status={t.status} />
<span className="text-xs text-text-muted">
${t.estimatedCost.toFixed(6)}
</span>
<span className="text-xs text-text-muted">
{t.estimatedLatencyMs}ms
</span>
{t.contextWindow && (
<span className="text-xs text-text-muted">
{(t.contextWindow / 1000).toFixed(0)}K ctx
</span>
)}
</div>
</div>
</div>
</div>
))}
</div>
</div>
</Card>

{/* Warnings & Errors */}
{result.warnings.length > 0 && (
<Card>
<div className="p-4 space-y-2">
<h3 className="text-sm font-semibold text-yellow-600 dark:text-yellow-400">
Warnings ({result.warnings.length})
</h3>
{result.warnings.map((w, i) => (
<p key={i} className="text-sm text-text-muted flex items-start gap-2">
<span className="text-yellow-500 mt-0.5">⚠️</span>
{w}
</p>
))}
</div>
</Card>
)}

{result.errors.length > 0 && (
<Card>
<div className="p-4 space-y-2">
<h3 className="text-sm font-semibold text-red-600 dark:text-red-400">
Errors ({result.errors.length})
</h3>
{result.errors.map((e, i) => (
<p key={i} className="text-sm text-red-500 flex items-start gap-2">
<span className="mt-0.5">🚫</span>
{e}
</p>
))}
</div>
</Card>
)}
</>
)}

{/* Empty State */}
{!result && combos.length > 0 && (
<Card>
<div className="p-8 text-center">
<p className="text-text-muted">
Select a combo and click <strong>Simulate Route</strong> to see the routing path.
</p>
</div>
</Card>
)}

{combos.length === 0 && (
<Card>
<div className="p-8 text-center">
<p className="text-text-muted">
No combos configured yet.{' '}
<a href="/dashboard/combos" className="text-primary hover:underline">
Create one first
</a>
.
</p>
</div>
</Card>
)}
</div>
);
}
11 changes: 11 additions & 0 deletions src/app/(dashboard)/dashboard/combos/playground/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Metadata } from "next";
import ComboPlaygroundClient from "./ComboPlaygroundClient";

export const metadata: Metadata = {
title: "OmniRoute — Combo Playground",
description: "Simulate combo routing paths visually",
};

export default function ComboPlaygroundPage() {
return <ComboPlaygroundClient />;
}
3 changes: 1 addition & 2 deletions src/app/api/monitoring/health/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export async function GET() {
const { getActiveSessions, getAllActiveSessionCountsByKey } =
await import("@omniroute/open-sse/services/sessionManager.ts");

const { getCredentialHealthSummary } =
await import("@/lib/credentialHealth/cache");
const { getCredentialHealthSummary } = await import("@/lib/credentialHealth/cache");
const settings = await getSettings();
const connections = await getProviderConnections();
const circuitBreakers = getAllCircuitBreakerStatuses();
Expand Down
Loading