sandboxy 0.0.6__py3-none-any.whl → 0.0.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sandboxy/api/app.py +13 -0
- sandboxy/api/routes/local.py +12 -2
- sandboxy/cli/main.py +3 -1
- sandboxy/providers/__init__.py +2 -0
- sandboxy/providers/registry.py +26 -5
- sandboxy/ui/dist/assets/{index-BZFjoK-_.js → index-DfKu4uXt.js} +1 -1
- sandboxy/ui/dist/index.html +1 -1
- {sandboxy-0.0.6.dist-info → sandboxy-0.0.7.dist-info}/METADATA +1 -1
- {sandboxy-0.0.6.dist-info → sandboxy-0.0.7.dist-info}/RECORD +12 -12
- {sandboxy-0.0.6.dist-info → sandboxy-0.0.7.dist-info}/WHEEL +0 -0
- {sandboxy-0.0.6.dist-info → sandboxy-0.0.7.dist-info}/entry_points.txt +0 -0
- {sandboxy-0.0.6.dist-info → sandboxy-0.0.7.dist-info}/licenses/LICENSE +0 -0
sandboxy/api/app.py
CHANGED
|
@@ -36,6 +36,19 @@ def create_local_app(
|
|
|
36
36
|
root_dir: Working directory for scenarios/tools/agents.
|
|
37
37
|
local_ui_path: Path to local UI static files.
|
|
38
38
|
"""
|
|
39
|
+
# Load .env from root_dir to pick up API keys from the project directory
|
|
40
|
+
# This is important when root_dir differs from cwd
|
|
41
|
+
env_file = root_dir / ".env"
|
|
42
|
+
if env_file.exists():
|
|
43
|
+
load_dotenv(env_file, override=True)
|
|
44
|
+
logger.info(f"Loaded environment from {env_file}")
|
|
45
|
+
|
|
46
|
+
# Reset provider registry so it picks up the newly loaded API keys
|
|
47
|
+
from sandboxy.providers.registry import reset_registry
|
|
48
|
+
|
|
49
|
+
reset_registry()
|
|
50
|
+
logger.info("Provider registry reset after loading project .env")
|
|
51
|
+
|
|
39
52
|
from sandboxy.local.context import LocalContext, set_local_context
|
|
40
53
|
|
|
41
54
|
ctx = LocalContext(root_dir=root_dir)
|
sandboxy/api/routes/local.py
CHANGED
|
@@ -493,7 +493,10 @@ async def run_scenario(request: RunScenarioRequest) -> RunScenarioResponse:
|
|
|
493
493
|
experiment_name=mlflow_config.experiment,
|
|
494
494
|
)
|
|
495
495
|
|
|
496
|
-
|
|
496
|
+
# Short run name - just the model (scenario is in experiment name)
|
|
497
|
+
run_name = request.model.split("/")[-1] if "/" in request.model else request.model
|
|
498
|
+
|
|
499
|
+
with mlflow_run_context(mlflow_config, run_name=run_name) as run_id:
|
|
497
500
|
result = await runner.run(
|
|
498
501
|
scenario=spec,
|
|
499
502
|
model=request.model,
|
|
@@ -633,12 +636,17 @@ async def compare_models(request: CompareModelsRequest) -> CompareModelsResponse
|
|
|
633
636
|
scenario_name=spec.name,
|
|
634
637
|
)
|
|
635
638
|
exporter = MLflowExporter(config)
|
|
639
|
+
|
|
640
|
+
# Short run name - just the model
|
|
641
|
+
run_name = result.model.split("/")[-1] if "/" in result.model else result.model
|
|
642
|
+
|
|
636
643
|
exporter.export(
|
|
637
644
|
result=result.to_dict(),
|
|
638
645
|
scenario_path=scenario_path,
|
|
639
646
|
scenario_name=spec.name,
|
|
640
647
|
scenario_id=spec.id,
|
|
641
648
|
agent_name=result.model,
|
|
649
|
+
run_name=run_name,
|
|
642
650
|
)
|
|
643
651
|
except ImportError:
|
|
644
652
|
logger.warning("MLflow not installed, skipping export")
|
|
@@ -1513,7 +1521,9 @@ async def run_with_dataset(request: RunDatasetRequest) -> RunDatasetResponse:
|
|
|
1513
1521
|
if mlflow_config and mlflow_config.enabled:
|
|
1514
1522
|
from sandboxy.mlflow import mlflow_run_context
|
|
1515
1523
|
|
|
1516
|
-
|
|
1524
|
+
# Short run name - model + dataset
|
|
1525
|
+
model_short = request.model.split("/")[-1] if "/" in request.model else request.model
|
|
1526
|
+
run_name = f"{model_short} ({request.dataset_id})"
|
|
1517
1527
|
with mlflow_run_context(mlflow_config, run_name=run_name) as run_id:
|
|
1518
1528
|
result = await run_dataset_benchmark()
|
|
1519
1529
|
|
sandboxy/cli/main.py
CHANGED
|
@@ -833,7 +833,9 @@ def scenario(
|
|
|
833
833
|
)
|
|
834
834
|
|
|
835
835
|
# Start run, execute scenario, then log metrics - all connected
|
|
836
|
-
|
|
836
|
+
# Short run name - just the model
|
|
837
|
+
run_name = model_id.split("/")[-1] if "/" in model_id else model_id
|
|
838
|
+
with mlflow_run_context(mlflow_config, run_name=run_name) as run_id:
|
|
837
839
|
runner = ScenarioRunner(scenario=spec, agent=agent)
|
|
838
840
|
result = runner.run(max_turns=max_turns)
|
|
839
841
|
|
sandboxy/providers/__init__.py
CHANGED
|
@@ -40,6 +40,7 @@ from sandboxy.providers.registry import (
|
|
|
40
40
|
get_provider,
|
|
41
41
|
get_registry,
|
|
42
42
|
reload_local_providers,
|
|
43
|
+
reset_registry,
|
|
43
44
|
)
|
|
44
45
|
|
|
45
46
|
__all__ = [
|
|
@@ -53,6 +54,7 @@ __all__ = [
|
|
|
53
54
|
"get_provider",
|
|
54
55
|
"get_registry",
|
|
55
56
|
"reload_local_providers",
|
|
57
|
+
"reset_registry",
|
|
56
58
|
# Local provider
|
|
57
59
|
"LocalProvider",
|
|
58
60
|
"LocalProviderConnectionError",
|
sandboxy/providers/registry.py
CHANGED
|
@@ -154,23 +154,34 @@ class ProviderRegistry:
|
|
|
154
154
|
if "/" in model_id:
|
|
155
155
|
provider_name, model_name = model_id.split("/", 1)
|
|
156
156
|
|
|
157
|
-
# Check for
|
|
157
|
+
# Priority 1: Check for LOCAL provider with matching name
|
|
158
|
+
# Local providers take precedence over cloud providers
|
|
158
159
|
if provider_name in self.providers:
|
|
159
160
|
provider = self.providers[provider_name]
|
|
160
|
-
#
|
|
161
|
-
if hasattr(provider, "config")
|
|
161
|
+
# Only use if it's a local provider (has config attribute)
|
|
162
|
+
if hasattr(provider, "config"):
|
|
162
163
|
return provider
|
|
163
164
|
|
|
164
|
-
# OpenRouter format (e.g., "openai/gpt-4o")
|
|
165
|
+
# Priority 2: OpenRouter for provider/model format (e.g., "openai/gpt-4o")
|
|
165
166
|
if "openrouter" in self.providers:
|
|
166
167
|
return self.providers["openrouter"]
|
|
167
168
|
|
|
168
|
-
# Fallback to direct provider if
|
|
169
|
+
# Priority 3: Fallback to direct cloud provider if available
|
|
169
170
|
if provider_name == "openai" and "openai" in self.providers:
|
|
170
171
|
return self.providers["openai"]
|
|
171
172
|
if provider_name == "anthropic" and "anthropic" in self.providers:
|
|
172
173
|
return self.providers["anthropic"]
|
|
173
174
|
|
|
175
|
+
# No valid provider found for prefixed model - raise clear error
|
|
176
|
+
available = list(self.providers.keys())
|
|
177
|
+
raise ProviderError(
|
|
178
|
+
f"No provider available for model '{model_id}'. "
|
|
179
|
+
f"The '{provider_name}/' prefix requires OpenRouter (set OPENROUTER_API_KEY) "
|
|
180
|
+
f"or a local provider named '{provider_name}'. "
|
|
181
|
+
f"Available providers: {available}",
|
|
182
|
+
provider="registry",
|
|
183
|
+
)
|
|
184
|
+
|
|
174
185
|
# No prefix - use direct providers
|
|
175
186
|
model_lower = model_id.lower()
|
|
176
187
|
|
|
@@ -280,6 +291,16 @@ def get_registry() -> ProviderRegistry:
|
|
|
280
291
|
return _registry
|
|
281
292
|
|
|
282
293
|
|
|
294
|
+
def reset_registry() -> None:
|
|
295
|
+
"""Reset the global provider registry.
|
|
296
|
+
|
|
297
|
+
Forces re-initialization on next get_registry() call.
|
|
298
|
+
Useful after loading new environment variables.
|
|
299
|
+
"""
|
|
300
|
+
global _registry
|
|
301
|
+
_registry = None
|
|
302
|
+
|
|
303
|
+
|
|
283
304
|
def get_provider(model_id: str) -> BaseProvider:
|
|
284
305
|
"""Get a provider for a model (convenience function).
|
|
285
306
|
|
|
@@ -283,7 +283,7 @@ Please change the parent <Route path="${h}"> to <Route path="${h==="/"?"*":`${h}
|
|
|
283
283
|
*
|
|
284
284
|
* This source code is licensed under the ISC license.
|
|
285
285
|
* See the LICENSE file in the root directory of this source tree.
|
|
286
|
-
*/const bn=W("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]),Dg=[{path:"/",label:"Dashboard",icon:Pg},{path:"/results",label:"Results",icon:Hr},{path:"/builder",label:"Builder",icon:wn},{path:"/datasets",label:"Datasets",icon:sn}];function Ig(){const e=Ft(),[t,n]=x.useState(()=>typeof window<"u"?localStorage.getItem("theme")==="light":!1);return x.useEffect(()=>{t?(document.documentElement.classList.add("light"),localStorage.setItem("theme","light")):(document.documentElement.classList.remove("light"),localStorage.setItem("theme","dark"))},[t]),l.jsxs("div",{className:"app-shell",children:[l.jsxs("aside",{className:"sidebar",children:[l.jsx("div",{className:"p-5 border-b border-slate-800/70",children:l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx("h1",{className:"text-xl font-semibold",style:{color:"var(--app-text)"},children:"Sandboxy Local"}),l.jsx("p",{className:"text-sm",style:{color:"var(--app-muted)"},children:"Development Server"})]}),l.jsx("button",{onClick:()=>n(!t),className:"p-2 rounded-lg transition-colors hover:bg-slate-500/20",title:t?"Switch to dark mode":"Switch to light mode",children:t?l.jsx(Ag,{size:20,style:{color:"var(--app-muted)"}}):l.jsx(zg,{size:20,style:{color:"var(--app-muted)"}})})]})}),l.jsx("nav",{className:"p-4",children:l.jsx("ul",{className:"space-y-2",children:Dg.map(({path:s,label:r,icon:a})=>l.jsx("li",{children:l.jsxs(de,{to:s,"data-active":e.pathname===s,className:"nav-link",children:[l.jsx(a,{size:20}),r]})},s))})})]}),l.jsx("main",{className:"flex-1 overflow-auto",children:l.jsx(Uh,{})})]})}const $g="/api/v1";class Ug{async fetch(t,n){const s=await fetch(`${$g}${t}`,{...n,headers:{"Content-Type":"application/json",...n==null?void 0:n.headers}});if(!s.ok){const r=await s.json().catch(()=>({detail:"Unknown error"}));throw new Error(r.detail||`HTTP ${s.status}`)}return s.json()}async getStatus(){return this.fetch("/local/status")}async listScenarios(){return this.fetch("/local/scenarios")}async getScenario(t){return this.fetch(`/local/scenarios/${encodeURIComponent(t)}`)}async getScenarioGoals(t){return this.fetch(`/local/scenarios/${encodeURIComponent(t)}/goals`)}async getScenarioTools(t){return this.fetch(`/local/scenarios/${encodeURIComponent(t)}/tools`)}async listTools(){return this.fetch("/local/tools")}async getTool(t){return this.fetch(`/local/tools/${encodeURIComponent(t)}`)}async listAgents(){return this.fetch("/local/agents")}async getAgent(t){return this.fetch(`/local/agents/${encodeURIComponent(t)}`)}async listModels(){return this.fetch("/local/models")}async listRuns(){return this.fetch("/local/runs")}async getRun(t){return this.fetch(`/local/runs/${encodeURIComponent(t)}`)}async runScenario(t){return this.fetch("/local/run",{method:"POST",body:JSON.stringify(t)})}async compareModels(t){return this.fetch("/local/compare",{method:"POST",body:JSON.stringify(t)})}async listDatasets(){return this.fetch("/local/datasets")}async getDataset(t){return this.fetch(`/local/datasets/${encodeURIComponent(t)}`)}async saveDataset(t,n){return this.fetch("/local/datasets",{method:"POST",body:JSON.stringify({id:t,content:n})})}async updateDataset(t,n){return this.fetch(`/local/datasets/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify({id:t,content:n})})}async deleteDataset(t){return this.fetch(`/local/datasets/${encodeURIComponent(t)}`,{method:"DELETE"})}async runDataset(t){return this.fetch("/local/run-dataset",{method:"POST",body:JSON.stringify(t)})}}class Bg extends Ug{async listProviders(){return(await this.fetch("/providers")).providers}async addProvider(t){return this.fetch("/providers",{method:"POST",body:JSON.stringify(t)})}async getProvider(t){return this.fetch(`/providers/${encodeURIComponent(t)}`)}async deleteProvider(t){await this.fetch(`/providers/${encodeURIComponent(t)}`,{method:"DELETE"})}async testProvider(t){return this.fetch(`/providers/${encodeURIComponent(t)}/test`,{method:"POST"})}}const Z=new Bg;function Hg(){const[e,t]=x.useState(null),[n,s]=x.useState(!0),[r,a]=x.useState(null),[i,o]=x.useState([]),[c,u]=x.useState(!0),[m,f]=x.useState(!1),[g,y]=x.useState(null),[j,v]=x.useState({}),[N,p]=x.useState({name:"",type:"ollama",base_url:"http://localhost:11434/v1"}),[d,h]=x.useState(null),[k,w]=x.useState(!1),R=async()=>{try{const A=await Z.listProviders();o(A)}catch{o([])}finally{u(!1)}},P=async A=>{A.preventDefault(),h(null),w(!0);try{await Z.addProvider(N),await R(),f(!1),p({name:"",type:"ollama",base_url:"http://localhost:11434/v1"})}catch(L){h(L instanceof Error?L.message:"Failed to add provider")}finally{w(!1)}},M=async A=>{y(A);try{const L=await Z.testProvider(A);v(U=>({...U,[A]:{success:L.success,message:L.success?`Connected! Found ${L.models_found.length} models (${L.latency_ms}ms)`:L.error||"Connection failed"}}))}catch(L){v(U=>({...U,[A]:{success:!1,message:L instanceof Error?L.message:"Test failed"}}))}finally{y(null)}},O=async A=>{if(confirm(`Delete provider "${A}"?`))try{await Z.deleteProvider(A),await R(),v(L=>{const U={...L};return delete U[A],U})}catch(L){alert(L instanceof Error?L.message:"Failed to delete provider")}},z=A=>{switch(A){case"ollama":return"http://localhost:11434/v1";case"lmstudio":return"http://localhost:1234/v1";case"vllm":return"http://localhost:8000/v1";default:return"http://localhost:8000/v1"}};return x.useEffect(()=>{fetch("/api/v1/local/status").then(A=>{if(!A.ok)throw new Error("Failed to fetch status");return A.json()}).then(t).catch(A=>a(A.message)).finally(()=>s(!1)),R()},[]),n?l.jsx("div",{className:"p-8 page",children:l.jsx("div",{className:"text-slate-400",children:"Loading..."})}):r?l.jsx("div",{className:"p-8 page",children:l.jsxs("div",{className:"text-red-400",children:["Error: ",r]})}):e?l.jsxs("div",{className:"p-8 page",children:[l.jsxs("div",{className:"mb-8",children:[l.jsx("h1",{className:"text-2xl font-semibold text-slate-100 mb-2",children:"Dashboard"}),l.jsxs("p",{className:"text-slate-400",children:["Root: ",l.jsx("code",{className:"panel-subtle px-2 py-1 rounded",children:e.root_dir})]})]}),l.jsxs("section",{className:"mb-8",children:[l.jsxs("div",{className:"flex items-center justify-between mb-4",children:[l.jsxs("h2",{className:"text-lg font-semibold text-slate-100 flex items-center gap-2",children:[l.jsx(hp,{size:20}),"Scenarios (",e.scenarios.length,")"]}),l.jsxs(de,{to:"/builder",className:"flex items-center gap-1 px-3 py-1.5 bg-orange-400 hover:bg-orange-300 text-slate-900 rounded-lg text-sm font-semibold",children:[l.jsx(Ne,{size:16}),"Create Scenario"]})]}),e.scenarios.length===0?l.jsx("p",{className:"text-slate-400",children:"No scenarios found in scenarios/"}):l.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:e.scenarios.map(A=>l.jsxs("div",{className:"panel-card p-4 hover:border-slate-600 transition-colors",children:[l.jsxs(de,{to:`/scenario/${A.id}`,className:"block mb-3",children:[l.jsxs("div",{className:"flex items-start justify-between",children:[l.jsx("h3",{className:"font-medium text-slate-100 mb-1 hover:text-orange-400 transition-colors",children:A.name}),l.jsx(ge,{size:16,className:"text-slate-600 mt-1 flex-shrink-0"})]}),l.jsx("p",{className:"text-sm text-slate-400 line-clamp-2",children:A.description||"No description"})]}),l.jsxs("div",{className:"flex justify-between items-center pt-2 border-t border-slate-700/40",children:[l.jsx("span",{className:"text-xs text-slate-500",children:A.relative_path}),l.jsxs(de,{to:`/run/${A.id}`,className:"flex items-center gap-1 px-3 py-1 bg-orange-400 text-slate-900 rounded hover:bg-orange-300 transition-colors text-sm font-medium",children:[l.jsx(Xt,{size:14}),"Run"]})]})]},A.id))})]}),l.jsxs("section",{className:"mb-8",children:[l.jsxs("div",{className:"flex items-center justify-between mb-4",children:[l.jsxs("h2",{className:"text-lg font-semibold text-slate-100 flex items-center gap-2",children:[l.jsx(wn,{size:20}),"Tools (",e.tools.length,")"]}),l.jsxs(de,{to:"/tool-builder",className:"flex items-center gap-1 px-3 py-1.5 bg-emerald-400 hover:bg-emerald-300 text-slate-900 rounded-lg text-sm font-semibold",children:[l.jsx(Ne,{size:16}),"Create Tool"]})]}),e.tools.length===0?l.jsx("p",{className:"text-slate-400",children:"No tools found in tools/"}):l.jsx("div",{className:"flex flex-wrap gap-2",children:e.tools.map(A=>l.jsx("span",{className:"px-3 py-1 panel-subtle rounded-full text-sm text-slate-200 border border-slate-700/60",children:A.name},A.id))})]}),l.jsxs("section",{className:"mb-8",children:[l.jsxs("div",{className:"flex items-center justify-between mb-4",children:[l.jsxs("h2",{className:"text-lg font-semibold text-slate-100 flex items-center gap-2",children:[l.jsx(Ao,{size:20}),"Local Providers (",i.length,")"]}),l.jsxs("button",{onClick:()=>f(!m),className:"flex items-center gap-1 px-3 py-1.5 bg-purple-500 hover:bg-purple-400 text-white rounded-lg text-sm font-semibold",children:[l.jsx(Ne,{size:16}),"Add Provider"]})]}),m&&l.jsxs("div",{className:"panel-card p-4 mb-4",children:[l.jsx("h3",{className:"text-sm font-semibold text-slate-200 mb-3",children:"Add Local Provider"}),l.jsxs("form",{onSubmit:P,className:"space-y-3",children:[l.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-slate-400 mb-1",children:"Name"}),l.jsx("input",{type:"text",value:N.name,onChange:A=>p({...N,name:A.target.value}),placeholder:"ollama-local",className:"w-full px-3 py-1.5 bg-slate-800 border border-slate-700 rounded text-sm text-slate-100 placeholder-slate-500",required:!0})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-slate-400 mb-1",children:"Type"}),l.jsxs("select",{value:N.type,onChange:A=>{const L=A.target.value;p({...N,type:L,base_url:z(L)})},className:"w-full px-3 py-1.5 bg-slate-800 border border-slate-700 rounded text-sm text-slate-100",children:[l.jsx("option",{value:"ollama",children:"Ollama"}),l.jsx("option",{value:"lmstudio",children:"LM Studio"}),l.jsx("option",{value:"vllm",children:"vLLM"}),l.jsx("option",{value:"openai-compatible",children:"OpenAI Compatible"})]})]})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-slate-400 mb-1",children:"Base URL"}),l.jsx("input",{type:"url",value:N.base_url,onChange:A=>p({...N,base_url:A.target.value}),placeholder:"http://localhost:11434/v1",className:"w-full px-3 py-1.5 bg-slate-800 border border-slate-700 rounded text-sm text-slate-100 placeholder-slate-500",required:!0})]}),d&&l.jsx("p",{className:"text-red-400 text-xs",children:d}),l.jsxs("div",{className:"flex gap-2 justify-end",children:[l.jsx("button",{type:"button",onClick:()=>f(!1),className:"px-3 py-1.5 text-slate-400 hover:text-slate-200 text-sm",children:"Cancel"}),l.jsx("button",{type:"submit",disabled:k,className:"px-3 py-1.5 bg-purple-500 hover:bg-purple-400 text-white rounded text-sm font-medium disabled:opacity-50",children:k?"Adding...":"Add Provider"})]})]})]}),c?l.jsx("p",{className:"text-slate-400",children:"Loading providers..."}):i.length===0?l.jsxs("div",{className:"text-slate-400",children:[l.jsx("p",{className:"mb-2",children:"No local providers configured."}),l.jsx("p",{className:"text-sm",children:"Add a provider to use local models like Ollama, LM Studio, or vLLM."})]}):l.jsx("div",{className:"grid gap-3",children:i.map(A=>{var L,U;return l.jsxs("div",{className:"panel-card p-4 flex items-center justify-between",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[A.status==="connected"?l.jsx(fl,{size:18,className:"text-green-400"}):A.status==="error"?l.jsx(Eo,{size:18,className:"text-red-400"}):l.jsx(nn,{size:18,className:"text-slate-500"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"font-medium text-slate-100",children:A.name}),l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-slate-700 rounded text-slate-300",children:A.type}),A.enabled&&l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-green-900/50 text-green-400 rounded",children:"enabled"})]}),l.jsx("div",{className:"text-xs text-slate-400 mt-0.5",children:A.base_url}),((L=A.models)==null?void 0:L.length)>0&&l.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:A.models.map(B=>l.jsx("span",{className:"text-xs px-2 py-0.5 bg-emerald-900/40 border border-emerald-700/50 rounded text-emerald-300",children:B},B))}),(((U=A.models)==null?void 0:U.length)===0||!A.models)&&A.status==="connected"&&l.jsx("div",{className:"text-xs text-slate-500 mt-1",children:"No models available"}),j[A.name]&&l.jsx("div",{className:`text-xs mt-1 ${j[A.name].success?"text-green-400":"text-red-400"}`,children:j[A.name].message})]})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("button",{onClick:()=>M(A.name),disabled:g===A.name,className:"p-1.5 text-slate-400 hover:text-slate-200 hover:bg-slate-700 rounded disabled:opacity-50",title:"Test connection",children:l.jsx(Mg,{size:16,className:g===A.name?"animate-spin":""})}),l.jsx("button",{onClick:()=>O(A.name),className:"p-1.5 text-slate-400 hover:text-red-400 hover:bg-slate-700 rounded",title:"Delete provider",children:l.jsx(Ae,{size:16})})]})]},A.name)})})]})]}):null}function Vg(){const{scenarioId:e}=rp(),[t,n]=x.useState(null),[s,r]=x.useState([]),[a,i]=x.useState([]),[o,c]=x.useState(!0),[u,m]=x.useState(null),[f,g]=x.useState(new Set(["tools","evaluation","interaction"])),y=L=>{g(U=>{const B=new Set(U);return B.has(L)?B.delete(L):B.add(L),B})};if(x.useEffect(()=>{e&&(c(!0),Promise.all([Z.getScenario(e),Z.getScenarioGoals(e).catch(()=>[]),Z.getScenarioTools(e).catch(()=>[])]).then(([L,U,B])=>{n(L),r(U),i(B)}).catch(L=>m(L.message)).finally(()=>c(!1)))},[e]),o)return l.jsx("div",{className:"p-8 page",children:l.jsx("div",{className:"text-slate-400",children:"Loading scenario..."})});if(u||!t)return l.jsxs("div",{className:"p-8 page",children:[l.jsxs("div",{className:"text-red-400",children:["Error: ",u||"Scenario not found"]}),l.jsx(de,{to:"/",className:"text-orange-400 hover:underline mt-4 inline-block",children:"← Back to Dashboard"})]});const j=t.content||{},v=j.steps||[],N=j.mcp_servers||[],p=j.tools||{},d=j.tools_from||[],h=j.evaluation?j.evaluation.judge:null,k=j.evaluation,w=k==null?void 0:k.goals,R=k?k.max_score||((w==null?void 0:w.reduce((L,U)=>L+(U.points||0),0))??0):null,P=t.variables||[],M=v.length>0,O=j.category||null,z=j.tags||[],A=a.length>0?a.length:Object.keys(p).length;return l.jsxs("div",{className:"p-8 page max-w-5xl",children:[l.jsxs(de,{to:"/",className:"inline-flex items-center gap-1 text-slate-400 hover:text-slate-200 mb-6 text-sm",children:[l.jsx(Gs,{size:16}),"Back to Dashboard"]}),l.jsxs("div",{className:"panel-card p-6 mb-6",children:[l.jsxs("div",{className:"flex items-start justify-between",children:[l.jsxs("div",{className:"flex-1",children:[l.jsx("h1",{className:"text-2xl font-semibold text-slate-100 mb-2",children:t.name}),l.jsx("p",{className:"text-slate-400 mb-4",children:t.description}),l.jsxs("div",{className:"flex flex-wrap gap-2",children:[O&&l.jsx("span",{className:"px-2 py-1 bg-purple-900/40 border border-purple-700/50 rounded text-xs text-purple-300",children:O}),z.map(L=>l.jsx("span",{className:"px-2 py-1 bg-slate-700/50 border border-slate-600/50 rounded text-xs text-slate-300",children:L},L))]})]}),l.jsxs("div",{className:"flex gap-2 ml-4",children:[l.jsxs(de,{to:`/builder?scenario=${e}`,className:"flex items-center gap-1.5 px-3 py-2 bg-slate-700 hover:bg-slate-600 text-slate-200 rounded-lg text-sm font-medium transition-colors",children:[l.jsx(Lg,{size:16}),"Edit"]}),l.jsxs(de,{to:`/run/${e}`,className:"flex items-center gap-1.5 px-4 py-2 bg-orange-400 hover:bg-orange-300 text-slate-900 rounded-lg text-sm font-semibold transition-colors",children:[l.jsx(Xt,{size:16}),"Run"]})]})]}),l.jsxs("div",{className:"flex gap-6 mt-6 pt-4 border-t border-slate-700/60",children:[l.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[l.jsx(vr,{size:16,className:"text-slate-500"}),l.jsx("span",{className:"text-slate-400",children:M?`Multi-turn (${v.length} steps)`:"Single-turn"})]}),l.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[l.jsx(wn,{size:16,className:"text-slate-500"}),l.jsx("span",{className:"text-slate-400",children:N.length>0&&A===0?`${N.length} MCP server${N.length!==1?"s":""}`:`${A} tool${A!==1?"s":""}${N.length>0?` + ${N.length} MCP`:""}`})]}),l.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[l.jsx(yi,{size:16,className:"text-slate-500"}),l.jsxs("span",{className:"text-slate-400",children:[s.length," goal",s.length!==1?"s":"",R&&` (${R} pt${R!==1?"s":""})`]})]}),P.length>0&&l.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[l.jsx(ji,{size:16,className:"text-slate-500"}),l.jsxs("span",{className:"text-slate-400",children:[P.length," variables"]})]})]})]}),l.jsxs("div",{className:"panel-card mb-4",children:[l.jsxs("button",{onClick:()=>y("tools"),className:"w-full flex items-center justify-between p-4 text-left hover:bg-slate-800/30 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(wn,{size:18,className:"text-emerald-400"}),l.jsxs("h2",{className:"font-semibold text-slate-100",children:["Tools",N.length>0&&A===0?l.jsxs("span",{className:"ml-2 text-sm font-normal text-slate-400",children:["(",N.length," MCP server",N.length>1?"s":"",")"]}):l.jsxs("span",{className:"ml-2 text-sm font-normal text-slate-400",children:["(",A,N.length>0?` + ${N.length} MCP`:"",")"]})]})]}),f.has("tools")?l.jsx(pe,{size:18,className:"text-slate-500"}):l.jsx(ge,{size:18,className:"text-slate-500"})]}),f.has("tools")&&l.jsxs("div",{className:"px-4 pb-4 space-y-4",children:[N.length>0&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-2",children:"MCP Servers"}),N.map(L=>{var U;return l.jsxs("div",{className:"p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg mb-2",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[l.jsx(Ao,{size:14,className:"text-cyan-400"}),l.jsx("span",{className:"font-medium text-slate-200",children:L.name}),l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-cyan-900/40 text-cyan-300 rounded",children:"MCP"})]}),l.jsx("div",{className:"text-xs text-slate-500 mb-2",children:L.url?l.jsx("span",{className:"font-mono",children:L.url}):L.command?l.jsxs("span",{className:"font-mono",children:[L.command," ",(U=L.args)==null?void 0:U.join(" ")]}):null}),a.length>0&&l.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.map(B=>l.jsx("span",{className:"text-xs px-2 py-1 bg-emerald-900/30 border border-emerald-700/40 rounded text-emerald-300",title:B.description,children:B.name},B.name))})]},L.name)})]}),d.length>0&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-2",children:"Tool Libraries"}),l.jsx("div",{className:"flex flex-wrap gap-2",children:d.map(L=>l.jsx("span",{className:"px-3 py-1.5 bg-slate-800/50 border border-slate-700/60 rounded text-sm text-slate-300",children:L},L))})]}),Object.keys(p).length>0&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-2",children:"Inline Tools (Mock)"}),l.jsx("div",{className:"space-y-2",children:Object.entries(p).map(([L,U])=>{const B=U,C=B.actions,E=C?Object.keys(C):[];return l.jsxs("div",{className:"p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsx(bn,{size:14,className:"text-yellow-400"}),l.jsx("span",{className:"font-medium text-slate-200",children:L}),l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-yellow-900/40 text-yellow-300 rounded",children:"Mock"})]}),typeof B.description=="string"&&B.description&&l.jsx("p",{className:"text-xs text-slate-500 mb-2",children:B.description}),E.length>0&&l.jsx("div",{className:"flex flex-wrap gap-1.5",children:E.map(_=>l.jsx("span",{className:"text-xs px-2 py-1 bg-slate-700/50 rounded text-slate-400",children:_},_))})]},L)})})]}),N.length===0&&d.length===0&&Object.keys(p).length===0&&l.jsx("p",{className:"text-slate-500 text-sm",children:"No tools configured"})]})]}),l.jsxs("div",{className:"panel-card mb-4",children:[l.jsxs("button",{onClick:()=>y("evaluation"),className:"w-full flex items-center justify-between p-4 text-left hover:bg-slate-800/30 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(yi,{size:18,className:"text-orange-400"}),l.jsxs("h2",{className:"font-semibold text-slate-100",children:["Evaluation",R&&l.jsxs("span",{className:"ml-2 text-sm font-normal text-slate-400",children:["(",R," pts max)"]})]})]}),f.has("evaluation")?l.jsx(pe,{size:18,className:"text-slate-500"}):l.jsx(ge,{size:18,className:"text-slate-500"})]}),f.has("evaluation")&&l.jsxs("div",{className:"px-4 pb-4 space-y-4",children:[s.length>0&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-3",children:"Goals"}),l.jsx("div",{className:"space-y-2",children:s.map(L=>{const U=j.evaluation,B=U==null?void 0:U.goals,C=B==null?void 0:B.find(S=>S.id===L.id),E=C==null?void 0:C.detection,_=E==null?void 0:E.type,b=C==null?void 0:C.points;return l.jsxs("div",{className:"flex items-start gap-3 p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg",children:[l.jsx(fl,{size:16,className:"text-slate-600 mt-0.5 flex-shrink-0"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsx("span",{className:"font-medium text-slate-200",children:L.name}),L.outcome&&l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-blue-900/40 text-blue-300 rounded",children:"outcome"})]}),L.description&&l.jsx("p",{className:"text-xs text-slate-500",children:L.description})]}),l.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[_&&l.jsx("span",{className:"text-xs px-2 py-1 bg-slate-700/50 rounded text-slate-400 font-mono",children:_}),b!==void 0&&l.jsxs("span",{className:"text-sm font-semibold text-orange-400",children:[b," pts"]})]})]},L.id)})})]}),h&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-3",children:"Judge"}),l.jsxs("div",{className:"p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[l.jsx(Fg,{size:14,className:"text-purple-400"}),l.jsxs("span",{className:"font-medium text-slate-200 capitalize",children:[h.type," Judge"]}),h.model&&l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-purple-900/40 text-purple-300 rounded",children:h.model})]}),h.pass_threshold!==void 0&&l.jsxs("p",{className:"text-xs text-slate-500 mb-2",children:["Pass threshold: ",(h.pass_threshold*100).toFixed(0),"%"]}),h.rubric&&l.jsxs("details",{className:"text-xs",children:[l.jsx("summary",{className:"text-slate-400 cursor-pointer hover:text-slate-300",children:"View rubric"}),l.jsx("pre",{className:"mt-2 p-2 bg-slate-900 rounded text-slate-400 overflow-auto max-h-48 whitespace-pre-wrap",children:h.rubric})]})]})]}),s.length===0&&!h&&l.jsx("p",{className:"text-slate-500 text-sm",children:"No evaluation configured"})]})]}),l.jsxs("div",{className:"panel-card mb-4",children:[l.jsxs("button",{onClick:()=>y("interaction"),className:"w-full flex items-center justify-between p-4 text-left hover:bg-slate-800/30 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(vr,{size:18,className:"text-blue-400"}),l.jsxs("h2",{className:"font-semibold text-slate-100",children:["Interaction",l.jsxs("span",{className:"ml-2 text-sm font-normal text-slate-400",children:["(",M?"Multi-turn":"Single-turn",")"]})]})]}),f.has("interaction")?l.jsx(pe,{size:18,className:"text-slate-500"}):l.jsx(ge,{size:18,className:"text-slate-500"})]}),f.has("interaction")&&l.jsxs("div",{className:"px-4 pb-4 space-y-4",children:[typeof j.system_prompt=="string"&&j.system_prompt&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-2",children:"System Prompt"}),l.jsx("pre",{className:"p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg text-xs text-slate-300 overflow-auto max-h-48 whitespace-pre-wrap",children:j.system_prompt})]}),M&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-3",children:"Steps"}),l.jsx("div",{className:"space-y-2",children:v.map((L,U)=>{var B;return l.jsxs("div",{className:"flex items-start gap-3 p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg",children:[l.jsx("div",{className:"w-6 h-6 rounded-full bg-blue-900/40 border border-blue-700/50 flex items-center justify-center text-xs text-blue-300 flex-shrink-0",children:U+1}),l.jsxs("div",{className:"flex-1",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsx("span",{className:"font-medium text-slate-200",children:L.id}),l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-slate-700/50 text-slate-400 rounded font-mono",children:L.action})]}),typeof((B=L.params)==null?void 0:B.content)=="string"&&L.params.content&&l.jsxs("p",{className:"text-xs text-slate-500 line-clamp-2",children:[L.params.content.substring(0,100),L.params.content.length>100&&"..."]})]})]},L.id)})})]}),!M&&typeof j.prompt=="string"&&j.prompt&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-2",children:"Prompt"}),l.jsx("pre",{className:"p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg text-xs text-slate-300 overflow-auto max-h-48 whitespace-pre-wrap",children:j.prompt})]})]})]}),P.length>0&&l.jsxs("div",{className:"panel-card mb-4",children:[l.jsxs("button",{onClick:()=>y("variables"),className:"w-full flex items-center justify-between p-4 text-left hover:bg-slate-800/30 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(ji,{size:18,className:"text-indigo-400"}),l.jsxs("h2",{className:"font-semibold text-slate-100",children:["Variables (",P.length,")"]})]}),f.has("variables")?l.jsx(pe,{size:18,className:"text-slate-500"}):l.jsx(ge,{size:18,className:"text-slate-500"})]}),f.has("variables")&&l.jsx("div",{className:"px-4 pb-4",children:l.jsx("div",{className:"grid gap-2",children:P.map(L=>l.jsxs("div",{className:"flex items-center justify-between p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("code",{className:"text-sm font-mono text-indigo-300",children:`{{${L.name}}}`}),l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-slate-700/50 text-slate-400 rounded",children:L.type}),L.required&&l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-red-900/40 text-red-300 rounded",children:"required"})]}),L.default!==void 0&&l.jsxs("span",{className:"text-xs text-slate-500",children:["default: ",JSON.stringify(L.default)]})]},L.name))})})]}),l.jsxs("div",{className:"panel-card",children:[l.jsxs("button",{onClick:()=>y("file"),className:"w-full flex items-center justify-between p-4 text-left hover:bg-slate-800/30 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Hr,{size:18,className:"text-slate-500"}),l.jsx("h2",{className:"font-semibold text-slate-100",children:"File"})]}),f.has("file")?l.jsx(pe,{size:18,className:"text-slate-500"}):l.jsx(ge,{size:18,className:"text-slate-500"})]}),f.has("file")&&l.jsx("div",{className:"px-4 pb-4",children:l.jsx("p",{className:"text-xs text-slate-500 font-mono",children:t.path})})]})]})}function Wg(){const[e,t]=x.useState("idle"),[n,s]=x.useState(null),[r,a]=x.useState(null),[i,o]=x.useState(null),c=x.useCallback(()=>{t("idle"),s(null),a(null),o(null)},[]),u=x.useCallback(async(f,g,y,j)=>{c(),t("running");try{const v=await Z.runScenario({scenario_id:f,model:g,variables:y,mlflow_export:j==null?void 0:j.enabled,mlflow_tracking_uri:j==null?void 0:j.trackingUri,mlflow_experiment:j==null?void 0:j.experiment,mlflow_tracing:j==null?void 0:j.tracing});v.error?(t("error"),o(v.error)):(t("completed"),s(v))}catch(v){t("error"),o(v instanceof Error?v.message:"Unknown error")}},[c]),m=x.useCallback(async(f,g,y=1,j,v)=>{c(),t("running");try{const N=await Z.compareModels({scenario_id:f,models:g,runs_per_model:y,variables:j,mlflow_export:v==null?void 0:v.enabled,mlflow_tracking_uri:v==null?void 0:v.trackingUri,mlflow_experiment:v==null?void 0:v.experiment,mlflow_tracing:v==null?void 0:v.tracing});t("completed"),a(N)}catch(N){t("error"),o(N instanceof Error?N.message:"Unknown error")}},[c]);return{state:e,result:n,comparison:r,error:i,runScenario:u,compareModels:m,reset:c}}function jp(e){return e==null?"-":e<1e-4?"<$0.0001":e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(3)}`}function Mo({result:e}){var s,r,a;const[t,n]=x.useState(!1);return l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3",children:[e.evaluation&&l.jsxs("div",{className:"panel-card p-4 col-span-2 md:col-span-1",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(Lo,{className:"w-4 h-4"}),"Score"]}),l.jsxs("div",{className:"text-2xl font-bold text-slate-100",children:[e.evaluation.percentage.toFixed(0),"%"]}),l.jsxs("div",{className:"text-xs text-slate-500",children:[e.evaluation.total_score.toFixed(0)," / ",e.evaluation.max_score.toFixed(0)," pts"]})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(_o,{className:"w-4 h-4"}),"Latency"]}),l.jsxs("div",{className:"text-2xl font-bold text-slate-100",children:[((e.latency_ms||0)/1e3).toFixed(1),"s"]})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(vr,{className:"w-4 h-4"}),"Messages"]}),l.jsx("div",{className:"text-2xl font-bold text-slate-100",children:((s=e.history)==null?void 0:s.length)||0})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(bn,{className:"w-4 h-4"}),"Tool Calls"]}),l.jsx("div",{className:"text-2xl font-bold text-slate-100",children:((r=e.tool_calls)==null?void 0:r.length)||0})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(Tg,{className:"w-4 h-4"}),"Tokens"]}),l.jsx("div",{className:"text-2xl font-bold text-slate-100",children:((e.input_tokens||0)+(e.output_tokens||0)).toLocaleString()}),l.jsxs("div",{className:"text-xs text-slate-500",children:[(e.input_tokens||0).toLocaleString()," in / ",(e.output_tokens||0).toLocaleString()," out"]})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(To,{className:"w-4 h-4"}),"Cost"]}),l.jsx("div",{className:"text-2xl font-bold text-emerald-300",children:jp(e.cost_usd)})]})]}),e.evaluation&&e.evaluation.goals&&e.evaluation.goals.length>0&&l.jsxs("div",{className:"panel-card p-6",children:[l.jsx("h3",{className:"text-lg font-semibold text-slate-100 mb-4",children:"Goals"}),l.jsx("div",{className:"space-y-3",children:e.evaluation.goals.map(i=>l.jsxs("div",{className:`flex items-center justify-between p-3 rounded-lg border ${i.achieved?"bg-emerald-500/10 border-emerald-400/40":"bg-slate-950/40 border-slate-800/70"}`,children:[l.jsxs("div",{className:"flex items-center gap-3",children:[i.achieved?l.jsx(fl,{className:"w-5 h-5 text-emerald-400"}):l.jsx(Eo,{className:"w-5 h-5 text-slate-500"}),l.jsxs("div",{children:[l.jsx("div",{className:"font-medium text-slate-100",children:i.name||i.id}),i.reason&&l.jsx("div",{className:"text-sm text-slate-400",children:i.reason})]})]}),l.jsxs("div",{className:`font-bold ${i.achieved?"text-emerald-300":"text-slate-500"}`,children:[i.achieved?`+${i.points}`:"0"," pts"]})]},i.id))})]}),((a=e.evaluation)==null?void 0:a.judge)&&l.jsxs("div",{className:"panel-card p-6",children:[l.jsx("h3",{className:"text-lg font-semibold text-slate-100 mb-4",children:"Judge Evaluation"}),l.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[l.jsxs("div",{className:`text-3xl font-bold ${e.evaluation.judge.passed?"text-emerald-300":"text-red-400"}`,children:[(e.evaluation.judge.score*100).toFixed(0),"%"]}),l.jsx("div",{className:`px-3 py-1 rounded-full text-sm ${e.evaluation.judge.passed?"bg-emerald-500/15 text-emerald-300":"bg-red-900/50 text-red-400"}`,children:e.evaluation.judge.passed?"Passed":"Failed"})]}),l.jsx("p",{className:"text-slate-400",children:e.evaluation.judge.reasoning})]}),e.response&&l.jsxs("div",{className:"panel-card p-6",children:[l.jsx("h3",{className:"text-lg font-semibold text-slate-100 mb-4",children:"Response"}),l.jsx("div",{className:"panel-subtle rounded-lg p-4 whitespace-pre-wrap text-slate-200",children:e.response||"(No response)"})]}),e.history&&e.history.length>0&&l.jsxs("div",{className:"panel-card",children:[l.jsxs("button",{onClick:()=>n(!t),className:"w-full p-4 text-left flex items-center justify-between hover:bg-slate-800/60 transition-colors rounded-lg",children:[l.jsxs("span",{className:"font-semibold text-slate-100",children:["Conversation History (",e.history.length," messages)"]}),l.jsx("span",{className:"text-slate-400",children:t?"Hide":"Show"})]}),t&&l.jsx("div",{className:"px-6 pb-6 space-y-4",children:e.history.map((i,o)=>l.jsxs("div",{className:`p-3 rounded-lg ${i.role==="user"?"bg-orange-500/10 border border-orange-400/40":i.role==="assistant"?"panel-subtle":i.role==="tool"?"bg-amber-500/10 border border-amber-400/40":"panel-subtle"}`,children:[l.jsx("div",{className:"text-xs font-medium text-slate-500 mb-1 uppercase",children:i.role}),l.jsx("div",{className:"text-slate-200 whitespace-pre-wrap text-sm",children:i.content||"(empty)"})]},o))})]}),e.tool_calls&&e.tool_calls.length>0&&l.jsxs("div",{className:"panel-card p-6",children:[l.jsxs("h3",{className:"text-lg font-semibold text-slate-100 mb-4",children:["Tool Calls (",e.tool_calls.length,")"]}),l.jsx("div",{className:"space-y-3",children:e.tool_calls.map((i,o)=>l.jsx(Yg,{call:i},o))})]}),e.error&&l.jsxs("div",{className:"panel-card p-4 border-l-4 border-l-red-500 bg-red-950/30",children:[l.jsxs("div",{className:"flex items-center gap-2 text-red-400 mb-1",children:[l.jsx(nn,{className:"w-4 h-4"}),l.jsx("span",{className:"font-medium",children:"Error"})]}),l.jsx("p",{className:"text-sm text-red-300",children:e.error})]})]})}function uu(e){if(typeof e=="string")try{const t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}return JSON.stringify(e,null,2)}function Yg({call:e}){const[t,n]=x.useState(!1),s=e.result!==void 0&&e.result!==null,r=e.error!==void 0&&e.error!==null;return l.jsxs("div",{className:`panel-subtle rounded-lg overflow-hidden ${e.success?"":"border border-red-500/30"}`,children:[l.jsxs("button",{onClick:()=>n(!t),className:"w-full p-4 text-left flex items-center justify-between hover:bg-slate-800/40 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[t?l.jsx(pe,{className:"w-4 h-4 text-slate-500"}):l.jsx(ge,{className:"w-4 h-4 text-slate-500"}),l.jsxs("code",{className:"text-orange-300",children:[e.tool,".",e.action,"()"]})]}),l.jsx("span",{className:`text-sm ${e.success?"text-emerald-300":"text-red-400"}`,children:e.success?"✓ Success":"✗ Failed"})]}),t&&l.jsxs("div",{className:"px-4 pb-4 space-y-3",children:[l.jsxs("div",{children:[l.jsx("div",{className:"text-xs font-medium text-slate-500 mb-1",children:"Arguments"}),l.jsx("pre",{className:"text-xs text-slate-400 overflow-auto bg-slate-950/50 rounded p-2",children:uu(e.args)})]}),s&&l.jsxs("div",{children:[l.jsx("div",{className:"text-xs font-medium text-emerald-400 mb-1",children:"Result"}),l.jsx("pre",{className:"text-xs text-slate-400 overflow-auto bg-emerald-950/30 rounded p-2 max-h-48",children:uu(e.result)})]}),r&&l.jsxs("div",{children:[l.jsx("div",{className:"text-xs font-medium text-red-400 mb-1",children:"Error"}),l.jsx("pre",{className:"text-xs text-red-300 overflow-auto bg-red-950/30 rounded p-2",children:e.error})]})]})]})}function Qg(e){var o;const t=e.ranking||[],n=[];for(const c of t){const u=(o=e.stats)==null?void 0:o[c];if(!u)continue;const m=u.avg_score||0,f=u.avg_cost_usd||0,g=u.avg_latency_ms||0,y=f>0?m/(f*100):m>0?1/0:0;n.push({modelId:c,score:m,cost:f,latency:g,efficiency:y,badges:[]})}if(n.length===0)return n;const s=n.reduce((c,u)=>c.score>u.score?c:u),r=n.reduce((c,u)=>c.efficiency>u.efficiency?c:u),a=n.filter(c=>c.score>=s.score*.7),i=a.length>0?a.reduce((c,u)=>c.latency<u.latency?c:u):null;for(const c of n)c.modelId===s.modelId&&c.badges.push("quality"),c.modelId===r.modelId&&r.cost>0&&c.badges.push("value"),i&&c.modelId===i.modelId&&c.badges.push("fast");return n}function qg({type:e}){switch(e){case"quality":return l.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-amber-500/20 text-amber-300 border border-amber-500/30",children:[l.jsx(Lo,{className:"w-3 h-3"})," Best Quality"]});case"value":return l.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-emerald-500/20 text-emerald-300 border border-emerald-500/30",children:[l.jsx(To,{className:"w-3 h-3"})," Best Value"]});case"fast":return l.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-blue-500/20 text-blue-300 border border-blue-500/30",children:[l.jsx(bn,{className:"w-3 h-3"})," Fastest"]});default:return null}}function Jg({run:e,onClose:t}){return l.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/70",onClick:t,children:l.jsxs("div",{className:"bg-slate-900 rounded-xl max-w-4xl w-full max-h-[90vh] overflow-hidden flex flex-col",onClick:n=>n.stopPropagation(),children:[l.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-800",children:[l.jsxs("div",{children:[l.jsx("h2",{className:"text-lg font-semibold text-slate-100",children:"Run Details"}),l.jsx("p",{className:"text-sm text-slate-400",children:e.model})]}),l.jsx("button",{onClick:t,className:"p-2 text-slate-400 hover:text-slate-100 hover:bg-slate-800 rounded-lg",children:l.jsx(Nt,{className:"w-5 h-5"})})]}),l.jsx("div",{className:"overflow-auto p-4",children:l.jsx(Mo,{result:e})})]})})}function Np({comparison:e}){var m,f,g,y,j,v,N,p;const[t,n]=x.useState(null),[s,r]=x.useState(null),a=e.ranking||[],i=Qg(e),o=new Map(i.map(d=>[d.modelId,d])),c=new Map;if(e.results)for(const d of e.results){const h=c.get(d.model)||[];h.push(d),c.set(d.model,h)}const u=e.results&&e.results.length>0;return l.jsxs(l.Fragment,{children:[s&&l.jsx(Jg,{run:s,onClose:()=>r(null)}),l.jsxs("div",{className:"space-y-6",children:[i.length>0&&l.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[i.find(d=>d.badges.includes("quality"))&&l.jsxs("div",{className:"panel-card p-4 border-l-4 border-l-amber-400",children:[l.jsxs("div",{className:"flex items-center gap-2 text-amber-300 mb-1",children:[l.jsx(Lo,{className:"w-4 h-4"}),l.jsx("span",{className:"text-sm font-medium",children:"Best Quality"})]}),l.jsx("div",{className:"text-lg font-semibold text-slate-100",children:((m=i.find(d=>d.badges.includes("quality")))==null?void 0:m.modelId.split("/")[1])||((f=i.find(d=>d.badges.includes("quality")))==null?void 0:f.modelId)}),l.jsxs("div",{className:"text-xs text-slate-400 mt-1",children:["Highest score: ",(g=i.find(d=>d.badges.includes("quality")))==null?void 0:g.score.toFixed(1)," pts"]})]}),i.find(d=>d.badges.includes("value"))&&l.jsxs("div",{className:"panel-card p-4 border-l-4 border-l-emerald-400",children:[l.jsxs("div",{className:"flex items-center gap-2 text-emerald-300 mb-1",children:[l.jsx(To,{className:"w-4 h-4"}),l.jsx("span",{className:"text-sm font-medium",children:"Best Value"})]}),l.jsx("div",{className:"text-lg font-semibold text-slate-100",children:((y=i.find(d=>d.badges.includes("value")))==null?void 0:y.modelId.split("/")[1])||((j=i.find(d=>d.badges.includes("value")))==null?void 0:j.modelId)}),l.jsx("div",{className:"text-xs text-slate-400 mt-1",children:(()=>{const d=i.find(R=>R.badges.includes("value")),h=i.find(R=>R.badges.includes("quality"));if(!d||!h)return"";if(d.cost===0)return"Free!";if(d.modelId===h.modelId)return"Also the best quality!";const k=Math.round(d.score/h.score*100),w=h.cost>0?Math.round(d.cost/h.cost*100):0;return w===0?`${k}% quality, nearly free`:`${k}% quality at ${w}% cost`})()})]}),i.find(d=>d.badges.includes("fast"))&&l.jsxs("div",{className:"panel-card p-4 border-l-4 border-l-blue-400",children:[l.jsxs("div",{className:"flex items-center gap-2 text-blue-300 mb-1",children:[l.jsx(bn,{className:"w-4 h-4"}),l.jsx("span",{className:"text-sm font-medium",children:"Fastest"})]}),l.jsx("div",{className:"text-lg font-semibold text-slate-100",children:((v=i.find(d=>d.badges.includes("fast")))==null?void 0:v.modelId.split("/")[1])||((N=i.find(d=>d.badges.includes("fast")))==null?void 0:N.modelId)}),l.jsxs("div",{className:"text-xs text-slate-400 mt-1",children:[((((p=i.find(d=>d.badges.includes("fast")))==null?void 0:p.latency)||0)/1e3).toFixed(1),"s avg latency"]})]})]}),l.jsxs("div",{className:"panel-card overflow-hidden",children:[l.jsxs("div",{className:"p-4 border-b border-slate-800/70",children:[l.jsx("h3",{className:"text-lg font-semibold text-slate-100",children:"Model Comparison"}),l.jsxs("p",{className:"text-sm text-slate-400",children:[e.runs_per_model," run(s) per model"]})]}),l.jsx("div",{className:"overflow-x-auto",children:l.jsxs("table",{className:"w-full",children:[l.jsx("thead",{className:"bg-slate-950/70",children:l.jsxs("tr",{children:[l.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium text-slate-400",children:"Rank"}),l.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium text-slate-400",children:"Model"}),l.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium text-slate-400",children:"Score"}),l.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium text-slate-400",children:"Judge"}),l.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium text-slate-400",children:"Latency"}),l.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium text-slate-400",children:"Tokens"}),l.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium text-slate-400",children:"Cost"})]})}),l.jsx("tbody",{children:a.map((d,h)=>{var M,O;const k=(M=e.stats)==null?void 0:M[d],w=o.get(d),R=c.get(d)||[],P=t===d;return k?l.jsxs(l.Fragment,{children:[l.jsxs("tr",{className:`border-t border-slate-800/70 hover:bg-slate-900/40 ${u?"cursor-pointer":""}`,onClick:()=>u&&n(P?null:d),children:[l.jsx("td",{className:"px-4 py-3",children:l.jsxs("div",{className:"flex items-center gap-2",children:[u&&(P?l.jsx(pe,{className:"w-4 h-4 text-slate-500"}):l.jsx(ge,{className:"w-4 h-4 text-slate-500"})),l.jsxs("span",{className:`font-bold ${h===0?"text-amber-300":"text-slate-400"}`,children:["#",h+1]})]})}),l.jsxs("td",{className:"px-4 py-3",children:[l.jsx("div",{className:"text-slate-100 font-medium",children:d}),w&&w.badges.length>0&&l.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:w.badges.map(z=>l.jsx(qg,{type:z},z))})]}),l.jsx("td",{className:"px-4 py-3 text-right text-slate-100 font-semibold",children:((O=k.avg_score)==null?void 0:O.toFixed(1))||"0"}),l.jsx("td",{className:"px-4 py-3 text-right text-slate-400",children:k.avg_judge_score!=null?`${(k.avg_judge_score*100).toFixed(0)}%`:"-"}),l.jsxs("td",{className:"px-4 py-3 text-right text-slate-400",children:[((k.avg_latency_ms||0)/1e3).toFixed(1),"s"]}),l.jsx("td",{className:"px-4 py-3 text-right text-slate-400",children:((k.total_input_tokens||0)+(k.total_output_tokens||0)).toLocaleString()}),l.jsx("td",{className:"px-4 py-3 text-right text-emerald-300 font-medium",children:jp(k.avg_cost_usd)})]},d),P&&R.length>0&&l.jsx("tr",{children:l.jsx("td",{colSpan:7,className:"px-4 py-2 bg-slate-950/50",children:l.jsxs("div",{className:"ml-8 space-y-2",children:[l.jsxs("div",{className:"text-sm font-medium text-slate-400 mb-2",children:["Individual Runs (",R.length,")"]}),R.map((z,A)=>{var L,U,B;return l.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-slate-900/50 border border-slate-800/50 hover:bg-slate-800/50 cursor-pointer",onClick:C=>{C.stopPropagation(),r(z)},children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsxs("span",{className:"text-slate-500 text-sm",children:["Run ",A+1]}),l.jsxs("span",{className:"text-slate-100 font-medium",children:[((U=(L=z.evaluation)==null?void 0:L.percentage)==null?void 0:U.toFixed(0))||0,"%"]}),((B=z.evaluation)==null?void 0:B.judge)&&l.jsx("span",{className:`text-sm ${z.evaluation.judge.passed?"text-emerald-300":"text-red-400"}`,children:z.evaluation.judge.passed?"✓ Passed":"✗ Failed"}),z.error&&l.jsxs("span",{className:"text-sm text-red-400 flex items-center gap-1",children:[l.jsx(nn,{className:"w-3 h-3"})," Error"]})]}),l.jsxs("button",{className:"flex items-center gap-1 text-sm text-orange-300 hover:text-orange-200",onClick:C=>{C.stopPropagation(),r(z)},children:[l.jsx(xp,{className:"w-4 h-4"}),"View Details"]})]},A)})]})})},`${d}-runs`)]}):null})})]})})]}),e.stats&&Object.values(e.stats).some(d=>d.goal_rates&&Object.keys(d.goal_rates).length>0)&&l.jsxs("div",{className:"panel-card p-6",children:[l.jsx("h3",{className:"text-lg font-semibold text-slate-100 mb-4",children:"Goal Achievement Rates"}),(()=>{const d=new Set;return Object.values(e.stats).forEach(h=>{h.goal_rates&&Object.keys(h.goal_rates).forEach(k=>d.add(k))}),l.jsx("div",{className:"overflow-x-auto",children:l.jsxs("table",{className:"w-full",children:[l.jsx("thead",{className:"bg-slate-950/70",children:l.jsxs("tr",{children:[l.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium text-slate-400",children:"Model"}),Array.from(d).map(h=>l.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium text-slate-400",children:h},h))]})}),l.jsx("tbody",{children:a.map(h=>{var w;const k=(w=e.stats)==null?void 0:w[h];return k?l.jsxs("tr",{className:"border-t border-slate-800/70",children:[l.jsx("td",{className:"px-4 py-3 text-slate-100 font-medium",children:h}),Array.from(d).map(R=>{var M;const P=((M=k.goal_rates)==null?void 0:M[R])??0;return l.jsx("td",{className:"px-4 py-3 text-right",children:l.jsxs("span",{className:P>=100?"text-emerald-300":P>=50?"text-amber-300":"text-red-400",children:[P.toFixed(0),"%"]})},R)})]},h):null})})]})})})()]})]})]})}function As(){return l.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 bg-emerald-500/20 border border-emerald-500/40 rounded text-xs text-emerald-400",children:[l.jsx(gp,{size:10}),"Local"]})}function du({models:e,value:t,onChange:n,disabled:s,placeholder:r="Select a model..."}){const[a,i]=x.useState(!1),[o,c]=x.useState(""),u=x.useRef(null),m=x.useRef(null),f=e.find(p=>p.id===t);x.useEffect(()=>{const p=d=>{u.current&&!u.current.contains(d.target)&&i(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[]),x.useEffect(()=>{a&&m.current&&m.current.focus()},[a]);const g=e.filter(p=>p.name.toLowerCase().includes(o.toLowerCase())||p.id.toLowerCase().includes(o.toLowerCase())),y=g.reduce((p,d)=>{const h=d.provider_name||d.id.split("/")[0]||"other";return p[h]||(p[h]=[]),p[h].push(d),p},{}),j=["openai","anthropic","google","x-ai","deepseek","meta-llama","mistralai","qwen","perplexity"],v=p=>{var d;return(d=y[p])==null?void 0:d.some(h=>h.is_local)},N=Object.keys(y).sort((p,d)=>{const h=v(p),k=v(d);if(h&&!k)return-1;if(!h&&k)return 1;const w=j.indexOf(p),R=j.indexOf(d);return w===-1&&R===-1?p.localeCompare(d):w===-1?1:R===-1?-1:w-R});return l.jsxs("div",{ref:u,className:"relative",children:[l.jsxs("button",{type:"button",onClick:()=>!s&&i(!a),disabled:s,className:`w-full flex items-center justify-between gap-2 px-4 py-2.5 panel-subtle text-left transition-colors ${s?"opacity-50 cursor-not-allowed":"hover:bg-slate-800 cursor-pointer"} ${a?"ring-2 ring-orange-400":""}`,children:[f?l.jsxs("div",{className:"flex items-center justify-between flex-1 min-w-0 gap-2",children:[l.jsx("span",{className:"text-slate-100 truncate",children:f.name}),f.is_local&&l.jsx(As,{}),l.jsx("span",{className:"text-xs text-slate-500 shrink-0",children:f.price})]}):l.jsx("span",{className:"text-slate-500",children:r}),l.jsx(pe,{size:18,className:`text-slate-400 shrink-0 transition-transform ${a?"rotate-180":""}`})]}),a&&l.jsxs("div",{className:"absolute z-50 w-full mt-1 panel-card border border-slate-700/80 dark:border-slate-700/80 shadow-xl max-h-[28rem] overflow-hidden flex flex-col",children:[l.jsx("div",{className:"p-2 border-b border-slate-800/70",children:l.jsxs("div",{className:"relative",children:[l.jsx(Po,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),l.jsx("input",{ref:m,type:"text",value:o,onChange:p=>c(p.target.value),placeholder:"Search models...",className:"w-full pl-9 pr-3 py-2 bg-slate-900 border border-slate-800/70 rounded text-sm text-slate-100 placeholder-slate-500 focus:outline-none focus:border-orange-400/60"})]})}),l.jsxs("div",{className:"overflow-y-auto flex-1",children:[N.map(p=>l.jsxs("div",{children:[l.jsxs("div",{className:"px-3 py-1.5 text-xs font-medium text-slate-500 uppercase bg-slate-900 sticky top-0 flex items-center gap-2",children:[p,v(p)&&l.jsx(As,{})]}),y[p].map(d=>l.jsxs("button",{type:"button",onClick:()=>{n(d.id),i(!1),c("")},className:`w-full flex items-center gap-3 px-3 py-2 text-left transition-colors ${d.id===t?"bg-orange-500/20 text-orange-300":"hover:bg-slate-800 text-slate-100"}`,children:[l.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[l.jsx("div",{className:"truncate",children:d.name}),d.is_local&&!v(p)&&l.jsx(As,{})]}),l.jsx("span",{className:"text-xs text-slate-500 shrink-0",children:d.price}),d.id===t&&l.jsx(Xs,{size:16,className:"text-orange-400 shrink-0"})]},d.id))]},p)),g.length===0&&l.jsx("div",{className:"px-3 py-4 text-center text-slate-500 text-sm",children:"No models found"})]})]})]})}function Kg({models:e,selected:t,onChange:n,disabled:s}){const[r,a]=x.useState(!1),[i,o]=x.useState(""),c=x.useRef(null),u=x.useRef(null);x.useEffect(()=>{const p=d=>{c.current&&!c.current.contains(d.target)&&a(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[]),x.useEffect(()=>{r&&u.current&&u.current.focus()},[r]);const m=p=>{t.includes(p)?n(t.filter(d=>d!==p)):n([...t,p])},f=(p,d)=>{d.stopPropagation(),n(t.filter(h=>h!==p))},g=e.filter(p=>p.name.toLowerCase().includes(i.toLowerCase())||p.id.toLowerCase().includes(i.toLowerCase())),y=g.reduce((p,d)=>{const h=d.provider_name||d.id.split("/")[0]||"other";return p[h]||(p[h]=[]),p[h].push(d),p},{}),j=["openai","anthropic","google","x-ai","deepseek","meta-llama","mistralai","qwen","perplexity"],v=p=>{var d;return(d=y[p])==null?void 0:d.some(h=>h.is_local)},N=Object.keys(y).sort((p,d)=>{const h=v(p),k=v(d);if(h&&!k)return-1;if(!h&&k)return 1;const w=j.indexOf(p),R=j.indexOf(d);return w===-1&&R===-1?p.localeCompare(d):w===-1?1:R===-1?-1:w-R});return l.jsxs("div",{ref:c,className:"relative",children:[t.length>0&&l.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:t.map(p=>{const d=e.find(h=>h.id===p);return l.jsxs("span",{className:`flex items-center gap-1.5 px-2.5 py-1 rounded-full text-sm text-slate-100 ${d!=null&&d.is_local?"bg-emerald-500/20 border border-emerald-400/40":"bg-orange-500/20 border border-orange-400/40"}`,children:[(d==null?void 0:d.is_local)&&l.jsx(gp,{size:12,className:"text-emerald-400"}),(d==null?void 0:d.name)||p,l.jsx("button",{type:"button",onClick:h=>f(p,h),className:"hover:text-red-400 transition-colors",disabled:s,children:l.jsx(Nt,{size:14})})]},p)})}),l.jsxs("button",{type:"button",onClick:()=>!s&&a(!r),disabled:s,className:`w-full flex items-center justify-between gap-2 px-4 py-2.5 panel-subtle text-left transition-colors ${s?"opacity-50 cursor-not-allowed":"hover:bg-slate-800 cursor-pointer"} ${r?"ring-2 ring-orange-400":""}`,children:[l.jsx("span",{className:"text-slate-500",children:t.length===0?"Click to add models...":"Add more models..."}),l.jsx(pe,{size:18,className:`text-slate-400 shrink-0 transition-transform ${r?"rotate-180":""}`})]}),r&&l.jsxs("div",{className:"absolute z-50 w-full mt-1 panel-card border border-slate-700/80 dark:border-slate-700/80 shadow-xl max-h-[28rem] overflow-hidden flex flex-col",children:[l.jsx("div",{className:"p-2 border-b border-slate-800/70",children:l.jsxs("div",{className:"relative",children:[l.jsx(Po,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),l.jsx("input",{ref:u,type:"text",value:i,onChange:p=>o(p.target.value),placeholder:"Search models...",className:"w-full pl-9 pr-3 py-2 bg-slate-900 border border-slate-800/70 rounded text-sm text-slate-100 placeholder-slate-500 focus:outline-none focus:border-orange-400/60"})]})}),l.jsxs("div",{className:"overflow-y-auto flex-1",children:[N.map(p=>l.jsxs("div",{children:[l.jsxs("div",{className:"px-3 py-1.5 text-xs font-medium text-slate-500 uppercase bg-slate-900 sticky top-0 flex items-center gap-2",children:[p,v(p)&&l.jsx(As,{})]}),y[p].map(d=>{const h=t.includes(d.id);return l.jsxs("button",{type:"button",onClick:()=>m(d.id),className:`w-full flex items-center gap-3 px-3 py-2 text-left transition-colors ${h?"bg-orange-500/20 text-orange-300":"hover:bg-slate-800 text-slate-100"}`,children:[l.jsx("div",{className:`w-4 h-4 rounded border flex items-center justify-center shrink-0 ${h?"bg-orange-400 border-orange-400":"border-slate-600"}`,children:h&&l.jsx(Xs,{size:12,className:"text-slate-900"})}),l.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[l.jsx("div",{className:"truncate",children:d.name}),d.is_local&&!v(p)&&l.jsx(As,{})]}),l.jsx("span",{className:"text-xs text-slate-500 shrink-0",children:d.price})]},d.id)})]},p)),g.length===0&&l.jsx("div",{className:"px-3 py-4 text-center text-slate-500 text-sm",children:"No models found"})]})]})]})}function fu(){var Ho;const{scenarioId:e}=rp(),[t]=yg(),n=t.get("dataset"),s=parseInt(t.get("parallel")||"5"),[r,a]=x.useState([]),[i,o]=x.useState(null),[c,u]=x.useState(e||""),[m,f]=x.useState([]),[g,y]=x.useState(""),[j,v]=x.useState([]),[N,p]=x.useState(n?"dataset":"single"),[d,h]=x.useState(1),[k,w]=x.useState({}),[R,P]=x.useState(!0),[M,O]=x.useState(null),[z,A]=x.useState([]),[L,U]=x.useState(n||""),[B,C]=x.useState(null),[E,_]=x.useState(!1),[b,S]=x.useState(s),[T,D]=x.useState(!1),[H,te]=x.useState(!1),[X,lt]=x.useState(""),[Fe,rt]=x.useState(""),[Cn,pl]=x.useState(!0),{state:ae,result:Ot,comparison:Uo,error:Bo,runScenario:dm,compareModels:fm}=Wg();x.useEffect(()=>{(async()=>{try{const[Oe,He,xm]=await Promise.all([Z.listScenarios(),Z.listModels(),Z.listDatasets()]);if(a(Oe),f(He),A(xm),He.length>0&&y(He[0].id),e){u(e);const Vo=await Z.getScenario(e);o(Vo);const Wo={};for(const Yo of Vo.variables||[])Wo[Yo.name]=Yo.default??"";w(Wo)}}catch(Oe){O(Oe instanceof Error?Oe.message:"Failed to load data")}finally{P(!1)}})()},[e]),x.useEffect(()=>{c&&c!==e&&Z.getScenario(c).then(V=>{o(V);const Oe={};for(const He of V.variables||[])Oe[He.name]=He.default??"";w(Oe)}).catch(V=>O(V.message))},[c,e]);const pm=async()=>{const V=c||e;if(!V)return;const Oe=T?{enabled:!0,trackingUri:X||void 0,experiment:Fe||void 0,tracing:Cn}:void 0;if(N==="dataset"){if(!L||!g)return;_(!0),C(null);try{const He=await Z.runDataset({scenario_id:V,dataset_id:L,model:g,parallel:b,mlflow_enabled:T,mlflow_experiment:Fe||void 0});C(He)}catch(He){O(He instanceof Error?He.message:"Dataset run failed")}finally{_(!1)}}else if(N==="single"){if(!g)return;await dm(V,g,k,Oe)}else{if(j.length===0)return;await fm(V,j,d,k,Oe)}},mm=(V,Oe)=>{w(He=>({...He,[V]:Oe}))};return R?l.jsx("div",{className:"flex items-center justify-center h-full",children:l.jsx(cu,{className:"w-8 h-8 animate-spin text-orange-400"})}):M?l.jsx("div",{className:"p-8 page",children:l.jsx("div",{className:"panel-solid p-4 text-red-400 border border-red-700/60",children:M})}):l.jsxs("div",{className:"p-8 max-w-6xl mx-auto page",children:[l.jsxs(de,{to:"/",className:"flex items-center gap-2 text-slate-400 hover:text-slate-100 mb-6",children:[l.jsx(Gs,{size:20}),"Back to Dashboard"]}),l.jsxs("div",{className:"mb-8",children:[l.jsx("h1",{className:"text-2xl font-semibold text-slate-100 mb-2",children:(i==null?void 0:i.name)||e}),(i==null?void 0:i.description)&&l.jsx("p",{className:"text-slate-400",children:i.description})]}),l.jsxs("div",{className:"panel-card p-6 mb-6",children:[l.jsxs("div",{className:"flex items-center justify-between mb-4",children:[l.jsx("h2",{className:"text-lg font-semibold text-slate-100",children:"Run Configuration"}),l.jsxs(de,{to:"/builder",className:"flex items-center gap-2 text-slate-400 hover:text-slate-100 text-sm",children:[l.jsx(Og,{size:16}),"Edit Scenario"]})]}),!e&&l.jsxs("div",{className:"mb-6",children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Scenario"}),l.jsxs("select",{value:c,onChange:V=>u(V.target.value),disabled:ae==="running"||E,className:"w-full panel-subtle px-4 py-2 text-slate-100 focus:outline-none focus:ring-2 focus:ring-orange-400",children:[l.jsx("option",{value:"",children:"Select a scenario..."}),r.map(V=>l.jsx("option",{value:V.id,children:V.name},V.id))]})]}),l.jsxs("div",{className:"mb-6",children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Mode"}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("button",{onClick:()=>p("single"),disabled:ae==="running"||E,className:`px-4 py-2 rounded-lg transition-colors ${N==="single"?"bg-orange-400 text-slate-900":"bg-slate-800 text-slate-300 hover:bg-slate-700"}`,children:"Single Model"}),l.jsx("button",{onClick:()=>p("compare"),disabled:ae==="running"||E,className:`px-4 py-2 rounded-lg transition-colors ${N==="compare"?"bg-orange-400 text-slate-900":"bg-slate-800 text-slate-300 hover:bg-slate-700"}`,children:"Compare Models"}),l.jsxs("button",{onClick:()=>p("dataset"),disabled:ae==="running"||E||z.length===0,className:`flex items-center gap-2 px-4 py-2 rounded-lg transition-colors ${N==="dataset"?"bg-blue-500 text-white":"bg-slate-800 text-slate-300 hover:bg-slate-700"}`,children:[l.jsx(sn,{size:16}),"Dataset Benchmark"]})]})]}),N==="single"?l.jsxs("div",{className:"mb-6",children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Model"}),l.jsx(du,{models:m,value:g,onChange:y,disabled:ae==="running"})]}):N==="compare"?l.jsxs("div",{className:"space-y-4 mb-6",children:[l.jsxs("div",{children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Models to Compare"}),l.jsx(Kg,{models:m,selected:j,onChange:v,disabled:ae==="running"})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Runs per Model"}),l.jsx("input",{type:"number",min:1,max:10,value:d,onChange:V=>h(Math.max(1,Math.min(10,parseInt(V.target.value)||1))),disabled:ae==="running",className:"w-32 panel-subtle px-4 py-2 text-slate-100 focus:outline-none focus:ring-2 focus:ring-orange-400"}),l.jsx("p",{className:"mt-1 text-xs text-slate-500",children:"More runs = more statistical significance"})]})]}):l.jsxs("div",{className:"space-y-4 mb-6",children:[l.jsxs("div",{children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Dataset"}),l.jsxs("select",{value:L,onChange:V=>U(V.target.value),disabled:E,className:"w-full panel-subtle px-4 py-2 text-slate-100 focus:outline-none focus:ring-2 focus:ring-blue-400",children:[l.jsx("option",{value:"",children:"Select a dataset..."}),z.map(V=>l.jsxs("option",{value:V.id,children:[V.name," (",V.case_count," cases)"]},V.id))]}),z.length===0&&l.jsxs("p",{className:"mt-1 text-xs text-slate-500",children:["No datasets found. ",l.jsx(de,{to:"/datasets",className:"text-blue-400 hover:underline",children:"Create one"})]})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Model"}),l.jsx(du,{models:m,value:g,onChange:y,disabled:E})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Parallel Runs"}),l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("input",{type:"number",min:1,max:20,value:b,onChange:V=>S(Math.max(1,Math.min(20,parseInt(V.target.value)||1))),disabled:E,className:"w-20 panel-subtle px-3 py-2 text-slate-100 focus:outline-none focus:ring-2 focus:ring-blue-400"}),l.jsx("span",{className:"text-sm text-slate-500",children:"concurrent cases"})]}),l.jsx("p",{className:"mt-1 text-xs text-slate-500",children:"Higher = faster, but may hit rate limits"})]})]}),i&&i.variables&&i.variables.length>0&&l.jsxs("div",{className:"mb-6 p-4 panel-subtle",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[l.jsx(yp,{size:18,className:"text-slate-400"}),l.jsx("h3",{className:"font-medium text-slate-100",children:"Variables"})]}),l.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:i.variables.map(V=>l.jsx(Xg,{variable:V,value:k[V.name],onChange:Oe=>mm(V.name,Oe),disabled:ae==="running"},V.name))})]}),l.jsxs("div",{className:"mb-6 p-4 panel-subtle",children:[l.jsxs("button",{onClick:()=>te(!H),className:"flex items-center gap-2 w-full text-left",children:[H?l.jsx(pe,{size:18}):l.jsx(ge,{size:18}),l.jsx("span",{className:"font-medium text-slate-100",children:"MLflow Tracking"}),T&&l.jsx("span",{className:"ml-2 px-2 py-0.5 text-xs bg-green-500/20 text-green-400 rounded",children:"Enabled"})]}),H&&l.jsxs("div",{className:"mt-4 space-y-4",children:[l.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[l.jsx("input",{type:"checkbox",checked:T,onChange:V=>D(V.target.checked),disabled:ae==="running"||E,className:"w-4 h-4 rounded border-slate-600 text-orange-400 focus:ring-orange-400"}),l.jsx("span",{className:"text-slate-200",children:"Enable MLflow tracking"})]}),T&&l.jsxs(l.Fragment,{children:[N!=="dataset"&&l.jsxs("div",{children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-1",children:"Tracking URI"}),l.jsx("input",{type:"text",value:X,onChange:V=>lt(V.target.value),disabled:ae==="running",placeholder:"http://127.0.0.1:5000 (uses MLFLOW_TRACKING_URI if empty)",className:"w-full panel-subtle px-3 py-2 text-slate-100 text-sm focus:outline-none focus:ring-2 focus:ring-orange-400"})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-1",children:"Experiment Name"}),l.jsx("input",{type:"text",value:Fe,onChange:V=>rt(V.target.value),disabled:ae==="running"||E,placeholder:N==="dataset"?`${(i==null?void 0:i.name)||"scenario"}-dataset`:(i==null?void 0:i.name)||"Defaults to scenario name",className:"w-full panel-subtle px-3 py-2 text-slate-100 text-sm focus:outline-none focus:ring-2 focus:ring-orange-400"})]}),N!=="dataset"&&l.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[l.jsx("input",{type:"checkbox",checked:Cn,onChange:V=>pl(V.target.checked),disabled:ae==="running",className:"w-4 h-4 rounded border-slate-600 text-orange-400 focus:ring-orange-400"}),l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-200",children:"Enable LLM Tracing"}),l.jsx("p",{className:"text-xs text-slate-500",children:"Capture detailed traces of each LLM call"})]})]}),l.jsxs("p",{className:"text-xs text-slate-500 flex items-center gap-1",children:[l.jsx(_g,{size:12}),"View results at your MLflow server after the run completes"]})]})]})]}),l.jsx("button",{onClick:pm,disabled:ae==="running"||E||!c||(N==="single"?!g:N==="compare"?j.length===0:!L||!g),className:`flex items-center gap-2 ${N==="dataset"?"bg-blue-500 hover:bg-blue-400":"bg-orange-400 hover:bg-orange-300"} disabled:bg-slate-700 disabled:text-slate-400 disabled:cursor-not-allowed text-slate-900 px-6 py-2 rounded-lg transition-colors font-semibold`,children:ae==="running"||E?l.jsxs(l.Fragment,{children:[l.jsx(cu,{className:"w-4 h-4 animate-spin"}),"Running..."]}):l.jsxs(l.Fragment,{children:[N==="dataset"?l.jsx(sn,{className:"w-4 h-4"}):l.jsx(Xt,{className:"w-4 h-4"}),N==="single"?"Run Scenario":N==="compare"?`Compare ${j.length} Models`:`Run ${((Ho=z.find(V=>V.id===L))==null?void 0:Ho.case_count)||0} Cases`]})})]}),Bo&&l.jsx("div",{className:"panel-solid border border-red-700/60 p-4 mb-6 text-red-400",children:l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Eo,{className:"w-5 h-5"}),l.jsx("span",{children:Bo})]})}),Ot&&l.jsx(Mo,{result:Ot}),Uo&&l.jsx(Np,{comparison:Uo}),B&&l.jsx(Gg,{result:B})]})}function Gg({result:e}){const[t,n]=x.useState(new Set),s=r=>{const a=new Set(t);a.has(r)?a.delete(r):a.add(r),n(a)};return l.jsxs("div",{className:"panel-card p-6",children:[l.jsxs("h2",{className:"text-xl font-semibold text-slate-100 mb-4 flex items-center gap-2",children:[l.jsx(sn,{size:20}),"Dataset Benchmark Results"]}),l.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[l.jsxs("div",{className:"panel-subtle p-4 rounded-lg",children:[l.jsxs("div",{className:"text-2xl font-bold text-slate-100",children:[e.passed_cases,"/",e.total_cases]}),l.jsx("div",{className:"text-sm text-slate-400",children:"Cases Passed"})]}),l.jsxs("div",{className:"panel-subtle p-4 rounded-lg",children:[l.jsxs("div",{className:`text-2xl font-bold ${e.pass_rate>=.9?"text-green-400":e.pass_rate>=.7?"text-yellow-400":"text-red-400"}`,children:[(e.pass_rate*100).toFixed(1),"%"]}),l.jsx("div",{className:"text-sm text-slate-400",children:"Pass Rate"})]}),l.jsxs("div",{className:"panel-subtle p-4 rounded-lg",children:[l.jsxs("div",{className:"text-2xl font-bold text-slate-100",children:[e.avg_percentage.toFixed(1),"%"]}),l.jsx("div",{className:"text-sm text-slate-400",children:"Avg Score"})]}),l.jsxs("div",{className:"panel-subtle p-4 rounded-lg",children:[l.jsxs("div",{className:"text-2xl font-bold text-slate-100",children:[(e.total_time_ms/1e3).toFixed(1),"s"]}),l.jsx("div",{className:"text-sm text-slate-400",children:"Total Time"})]})]}),Object.keys(e.by_expected).length>0&&l.jsxs("div",{className:"mb-6",children:[l.jsx("h3",{className:"font-medium text-slate-300 mb-3",children:"By Expected Outcome"}),l.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-2",children:Object.entries(e.by_expected).map(([r,a])=>{const i=a.passed+a.failed,o=i>0?a.passed/i:0;return l.jsxs("div",{className:"panel-subtle p-3 rounded",children:[l.jsx("div",{className:"font-medium text-slate-200",children:r}),l.jsxs("div",{className:"text-sm text-slate-400",children:[a.passed,"/",i," (",(o*100).toFixed(0),"%)"]})]},r)})})]}),l.jsxs("div",{children:[l.jsxs("h3",{className:"font-medium text-slate-300 mb-3",children:["Case Results (",e.failed_cases," failed)"]}),l.jsx("div",{className:"space-y-2 max-h-[40vh] overflow-y-auto",children:e.case_results.map(r=>l.jsxs("div",{className:`panel-subtle rounded-lg overflow-hidden ${r.passed?"":"border border-red-500/30"}`,children:[l.jsxs("button",{onClick:()=>s(r.case_id),className:"w-full px-4 py-3 flex items-center gap-3 text-left hover:bg-slate-700/50 transition-colors",children:[r.passed?l.jsx(Xs,{size:16,className:"text-green-400"}):l.jsx(Nt,{size:16,className:"text-red-400"}),l.jsx("span",{className:"font-medium text-slate-200",children:r.case_id}),r.expected&&l.jsxs("span",{className:"text-sm text-slate-400",children:["expected: ",r.expected]}),l.jsxs("span",{className:"ml-auto text-sm text-slate-400",children:[r.percentage.toFixed(0),"% | ",r.latency_ms,"ms"]})]}),t.has(r.case_id)&&l.jsxs("div",{className:"px-4 pb-3 pt-1 border-t border-slate-700",children:[r.failure_reason&&l.jsx("div",{className:"text-red-400 text-sm mb-2",children:r.failure_reason}),l.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-400",children:"Expected:"})," ",l.jsx("span",{className:"text-slate-200",children:r.expected||"N/A"})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-400",children:"Actual:"})," ",l.jsx("span",{className:"text-slate-200",children:r.actual_outcome||"None"})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-400",children:"Score:"})," ",l.jsxs("span",{className:"text-slate-200",children:[r.goal_score,"/",r.max_score]})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-400",children:"Latency:"})," ",l.jsxs("span",{className:"text-slate-200",children:[r.latency_ms,"ms"]})]})]})]})]},r.case_id))})]})]})}function Xg({variable:e,value:t,onChange:n,disabled:s}){const r="w-full panel-subtle px-3 py-2 text-slate-100 text-sm focus:outline-none focus:ring-2 focus:ring-orange-400 disabled:opacity-50";return l.jsxs("div",{children:[l.jsxs("label",{className:"block text-sm font-medium text-slate-400 mb-1",children:[e.label,e.required&&l.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),e.type==="select"&&e.options.length>0?l.jsxs("select",{value:String(t??""),onChange:a=>n(a.target.value),disabled:s,className:r,children:[l.jsx("option",{value:"",children:"Select..."}),e.options.map(a=>l.jsx("option",{value:a,children:a},a))]}):e.type==="boolean"?l.jsxs("select",{value:String(t??""),onChange:a=>n(a.target.value==="true"),disabled:s,className:r,children:[l.jsx("option",{value:"",children:"Select..."}),l.jsx("option",{value:"true",children:"True"}),l.jsx("option",{value:"false",children:"False"})]}):e.type==="number"?l.jsx("input",{type:"number",value:String(t??""),onChange:a=>n(a.target.value?Number(a.target.value):""),disabled:s,placeholder:e.default!==null?`Default: ${e.default}`:"",className:r}):l.jsx("input",{type:"text",value:String(t??""),onChange:a=>n(a.target.value),disabled:s,placeholder:e.default!==null?`Default: ${e.default}`:"",className:r})]})}const pu=e=>e.scenario_id.endsWith("_comparison")||e.filename.includes("_comparison_"),mu=e=>e.scenario_id.includes("_dataset_")||e.filename.includes("_dataset_"),Al=e=>e.replace(/_comparison$/,"").replace(/_dataset_.*$/,"");function Zg(){const[e,t]=x.useState([]),[n,s]=x.useState(!0),[r,a]=x.useState(null),[i,o]=x.useState(null),[c,u]=x.useState(null),[m,f]=x.useState(!1),[g,y]=x.useState(!1),[j,v]=x.useState(""),[N,p]=x.useState("all"),[d,h]=x.useState(new Set),k=C=>{h(E=>{const _=new Set(E);return _.has(C)?_.delete(C):_.add(C),_})},{filteredResults:w,groupedResults:R,scenarioOrder:P}=x.useMemo(()=>{let C=e.filter(b=>{if(j){const S=j.toLowerCase();if(!b.scenario_id.toLowerCase().includes(S))return!1}if(N!=="all"){const S=pu(b),T=mu(b);if(N==="comparison"&&!S||N==="dataset"&&!T||N==="single"&&(S||T))return!1}return!0});C=C.sort((b,S)=>new Date(S.timestamp).getTime()-new Date(b.timestamp).getTime());const E={},_=[];for(const b of C){const S=Al(b.scenario_id);E[S]||(E[S]=[],_.push(S)),E[S].push(b)}return{filteredResults:C,groupedResults:E,scenarioOrder:_}},[e,j,N]);x.useEffect(()=>{fetch("/api/v1/local/runs").then(C=>{if(!C.ok)throw new Error("Failed to fetch results");return C.json()}).then(t).catch(C=>a(C.message)).finally(()=>s(!1))},[]);const M=async C=>{try{const E=await fetch(`/api/v1/local/runs/${encodeURIComponent(C)}`);if(!E.ok)throw new Error("Failed to fetch result");const _=await E.json();o(_),u(C),f(!1)}catch(E){console.error("Error fetching result:",E)}},O=async()=>{if(i)try{await navigator.clipboard.writeText(JSON.stringify(i,null,2)),y(!0),setTimeout(()=>y(!1),2e3)}catch(C){console.error("Failed to copy:",C)}},z=C=>{var D,H,te,X,lt;if(!C)return"unknown";const E=C.case_results||((D=C.result)==null?void 0:D.case_results),_=C.dataset_id||((H=C.result)==null?void 0:H.dataset_id);if(E||_)return"dataset";if(C.ranking||((te=C.result)==null?void 0:te.ranking))return"comparison";const S=C.model||((X=C.result)==null?void 0:X.model),T=C.response||((lt=C.result)==null?void 0:lt.response);return S||T!==void 0?"single":"unknown"},A=C=>{const E=C.result||C;return{id:E.id||"",scenario_id:E.scenario_id||C.scenario_id||"",model:E.model||"",response:E.response||"",history:E.history||[],tool_calls:E.tool_calls||[],final_state:E.final_state||{},evaluation:E.evaluation||null,latency_ms:E.latency_ms||0,input_tokens:E.input_tokens||0,output_tokens:E.output_tokens||0,cost_usd:E.cost_usd||null,error:E.error||null}},L=C=>{const E=C.result||C;return{scenario_id:E.scenario_id||C.scenario_id||"",scenario_name:E.scenario_name||C.scenario_id||"",models:E.models||[],runs_per_model:E.runs_per_model||1,stats:E.stats||{},ranking:E.ranking||[],winner:E.winner||null,results:E.results||[]}},U=C=>{const E=C.result||C;return{scenario_id:E.scenario_id||C.scenario_id||"",model:E.model||"",dataset_id:E.dataset_id||"",total_cases:E.total_cases||0,passed_cases:E.passed_cases||0,failed_cases:E.failed_cases||0,pass_rate:E.pass_rate||0,avg_score:E.avg_score||0,avg_percentage:E.avg_percentage||0,by_expected:E.by_expected||{},total_time_ms:E.total_time_ms||0,case_results:E.case_results||[]}};if(n)return l.jsx("div",{className:"p-8 page",children:l.jsx("div",{className:"text-slate-400",children:"Loading..."})});if(r)return l.jsx("div",{className:"p-8 page",children:l.jsxs("div",{className:"text-red-400",children:["Error: ",r]})});const B=z(i);return l.jsxs("div",{className:"p-8 page",children:[l.jsx("h1",{className:"text-2xl font-semibold text-slate-100 mb-6",children:"Run Results"}),e.length===0?l.jsxs("div",{className:"panel-card p-6 text-center",children:[l.jsx(Hr,{size:48,className:"mx-auto text-slate-600 mb-4"}),l.jsx("p",{className:"text-slate-400 mb-2",children:"No run results found"}),l.jsx("p",{className:"text-slate-500 text-sm mb-4",children:"Run a scenario to see results here."}),l.jsxs(de,{to:"/",className:"inline-flex items-center gap-2 text-orange-300 hover:text-orange-200",children:[l.jsx(Xt,{size:16}),"Go to Dashboard"]})]}):l.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[l.jsxs("div",{className:"lg:col-span-1 space-y-4",children:[l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"relative",children:[l.jsx(Po,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),l.jsx("input",{type:"text",placeholder:"Search scenarios...",value:j,onChange:C=>v(C.target.value),className:"w-full bg-slate-900/60 border border-slate-700/50 rounded-lg pl-10 pr-4 py-2 text-sm text-slate-100 placeholder-slate-500 focus:outline-none focus:border-orange-400/50"})]}),l.jsxs("div",{className:"flex flex-wrap gap-1 p-1 bg-slate-900/60 rounded-lg border border-slate-700/50",children:[l.jsx("button",{onClick:()=>p("all"),className:`flex-1 min-w-0 px-2 py-1.5 text-xs font-medium rounded-md transition-colors ${N==="all"?"bg-slate-700/80 text-slate-100":"text-slate-400 hover:text-slate-200"}`,children:"All"}),l.jsxs("button",{onClick:()=>p("single"),className:`flex-1 min-w-0 px-2 py-1.5 text-xs font-medium rounded-md transition-colors flex items-center justify-center gap-1 ${N==="single"?"bg-slate-700/80 text-slate-100":"text-slate-400 hover:text-slate-200"}`,children:[l.jsx(bn,{size:12}),"Single"]}),l.jsxs("button",{onClick:()=>p("comparison"),className:`flex-1 min-w-0 px-2 py-1.5 text-xs font-medium rounded-md transition-colors flex items-center justify-center gap-1 ${N==="comparison"?"bg-slate-700/80 text-slate-100":"text-slate-400 hover:text-slate-200"}`,children:[l.jsx(ou,{size:12}),"Compare"]}),l.jsxs("button",{onClick:()=>p("dataset"),className:`flex-1 min-w-0 px-2 py-1.5 text-xs font-medium rounded-md transition-colors flex items-center justify-center gap-1 ${N==="dataset"?"bg-blue-600/80 text-slate-100":"text-slate-400 hover:text-slate-200"}`,children:[l.jsx(sn,{size:12}),"Dataset"]})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("h2",{className:"text-sm font-medium text-slate-400",children:[w.length," result",w.length!==1?"s":""," in ",P.length," scenario",P.length!==1?"s":""]}),j&&l.jsx("button",{onClick:()=>v(""),className:"text-xs text-slate-500 hover:text-slate-300",children:"Clear"})]}),l.jsx("div",{className:"space-y-2 max-h-[70vh] overflow-y-auto pr-2",children:P.length===0?l.jsxs("div",{className:"text-center py-8 text-slate-500",children:[l.jsx(Rg,{size:24,className:"mx-auto mb-2 opacity-50"}),l.jsx("p",{className:"text-sm",children:"No results match your filters"})]}):P.map(C=>{const E=R[C],_=d.has(C);return l.jsxs("div",{className:"panel-card overflow-hidden",children:[l.jsxs("button",{onClick:()=>k(C),className:"w-full flex items-center justify-between p-3 hover:bg-slate-800/40 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[_?l.jsx(ge,{size:16,className:"text-slate-500"}):l.jsx(pe,{size:16,className:"text-slate-500"}),l.jsx("span",{className:"font-medium text-slate-200 text-sm",children:C})]}),l.jsx("span",{className:"text-xs text-slate-500 bg-slate-800/60 px-2 py-0.5 rounded",children:E.length})]}),!_&&l.jsx("div",{className:"border-t border-slate-800/50",children:E.map(b=>{const S=pu(b),T=mu(b);return l.jsxs("div",{className:`flex items-center justify-between p-3 cursor-pointer transition-colors border-l-2 ${c===b.filename?"bg-slate-800/60 border-l-orange-400":"hover:bg-slate-800/40 border-l-transparent"}`,onClick:()=>M(b.filename),children:[l.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[T?l.jsx(sn,{size:14,className:"text-blue-400 flex-shrink-0"}):S?l.jsx(ou,{size:14,className:"text-purple-400 flex-shrink-0"}):l.jsx(bn,{size:14,className:"text-orange-400 flex-shrink-0"}),l.jsx("div",{className:"min-w-0",children:l.jsxs("p",{className:"text-xs text-slate-400 flex items-center gap-1",children:[l.jsx(_o,{size:10}),new Date(b.timestamp).toLocaleString()]})})]}),l.jsx(de,{to:`/run/${Al(b.scenario_id)}`,onClick:D=>D.stopPropagation(),className:"p-1.5 text-slate-500 hover:text-orange-300 hover:bg-slate-700/60 rounded flex-shrink-0",title:"Run again",children:l.jsx(Xt,{size:12})})]},b.filename)})})]},C)})})]}),l.jsx("div",{className:"lg:col-span-2",children:i?l.jsxs("div",{className:"space-y-4",children:[l.jsx("div",{className:"panel-card p-4",children:l.jsxs("div",{className:"flex items-center justify-between gap-4",children:[l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsx("h2",{className:"font-semibold text-slate-100 truncate",children:Al(i.scenario_id)}),B==="single"&&A(i).model&&l.jsxs("p",{className:"text-sm text-slate-400 mt-1",children:["Model: ",A(i).model]}),B==="comparison"&&l.jsx("p",{className:"text-sm text-slate-400 mt-1",children:"Model Comparison"}),B==="dataset"&&l.jsxs("p",{className:"text-sm text-slate-400 mt-1",children:["Dataset: ",U(i).dataset_id," | Model: ",U(i).model]})]}),l.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[l.jsxs("button",{onClick:O,className:`flex items-center gap-1 text-xs px-2 py-1 border rounded whitespace-nowrap transition-colors ${g?"text-emerald-400 border-emerald-500/50 bg-emerald-500/10":"text-slate-400 hover:text-slate-100 border-slate-700/70"}`,children:[l.jsx(mp,{size:12}),g?"Copied!":"Copy JSON"]}),l.jsx("button",{onClick:()=>f(!m),className:"text-xs text-slate-400 hover:text-slate-100 px-2 py-1 border border-slate-700/70 rounded whitespace-nowrap",children:m?"View Details":"View JSON"}),l.jsxs(de,{to:`/run/${Al(i.scenario_id)}`,className:"flex items-center gap-1 bg-orange-400 hover:bg-orange-300 text-slate-900 px-3 py-1 rounded text-sm font-semibold whitespace-nowrap",children:[l.jsx(Xt,{size:14}),"Run Again"]})]})]})}),m?l.jsx("div",{className:"panel-card p-4",children:l.jsx("pre",{className:"text-xs text-slate-300 bg-slate-950/70 p-3 rounded overflow-auto max-h-[70vh]",children:JSON.stringify(i,null,2)})}):l.jsxs(l.Fragment,{children:[B==="single"&&l.jsx(Mo,{result:A(i)}),B==="comparison"&&l.jsx(Np,{comparison:L(i)}),B==="dataset"&&l.jsx(ev,{result:U(i)}),B==="unknown"&&l.jsx("div",{className:"panel-card p-6 text-center",children:l.jsx("p",{className:"text-slate-500",children:'Could not parse result format. Click "View JSON" to see raw data.'})})]})]}):l.jsxs("div",{className:"panel-card p-8 text-center",children:[l.jsx(xp,{size:32,className:"mx-auto text-slate-600 mb-3"}),l.jsx("p",{className:"text-slate-400",children:"Select a result to view details"})]})})]})]})}function ev({result:e}){const[t,n]=x.useState(new Set),s=o=>{const c=new Set(t);c.has(o)?c.delete(o):c.add(o),n(c)},r=e.passed_cases,a=e.total_cases,i=e.pass_rate;return l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(sn,{className:"w-4 h-4"}),"Cases Passed"]}),l.jsxs("div",{className:`text-2xl font-bold ${i>=.9?"text-emerald-300":i>=.7?"text-amber-300":"text-red-400"}`,children:[r,"/",a]}),l.jsxs("div",{className:"text-xs text-slate-500",children:[(i*100).toFixed(1),"% pass rate"]})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(Xs,{className:"w-4 h-4"}),"Avg Score"]}),l.jsxs("div",{className:"text-2xl font-bold text-slate-100",children:[e.avg_percentage.toFixed(1),"%"]}),l.jsxs("div",{className:"text-xs text-slate-500",children:[e.avg_score.toFixed(1)," points"]})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(_o,{className:"w-4 h-4"}),"Total Time"]}),l.jsxs("div",{className:"text-2xl font-bold text-slate-100",children:[(e.total_time_ms/1e3).toFixed(1),"s"]}),l.jsxs("div",{className:"text-xs text-slate-500",children:[Math.round(e.total_time_ms/Math.max(a,1)),"ms/case"]})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(Nt,{className:"w-4 h-4"}),"Failed"]}),l.jsx("div",{className:"text-2xl font-bold text-red-400",children:e.failed_cases}),l.jsxs("div",{className:"text-xs text-slate-500",children:[a-r," case",a-r!==1?"s":""," failed"]})]})]}),Object.keys(e.by_expected).length>0&&l.jsxs("div",{className:"panel-card p-6",children:[l.jsx("h3",{className:"font-semibold text-slate-100 mb-4",children:"By Expected Outcome"}),l.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:Object.entries(e.by_expected).map(([o,c])=>{const u=c.passed+c.failed,m=u>0?c.passed/u:0;return l.jsxs("div",{className:"panel-subtle p-3 rounded-lg",children:[l.jsx("div",{className:"font-medium text-slate-200",children:o}),l.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[l.jsxs("div",{className:`text-lg font-semibold ${m>=.9?"text-emerald-300":m>=.7?"text-amber-300":"text-red-400"}`,children:[c.passed,"/",u]}),l.jsxs("span",{className:"text-xs text-slate-500",children:["(",(m*100).toFixed(0),"%)"]})]})]},o)})})]}),l.jsxs("div",{className:"panel-card p-6",children:[l.jsxs("h3",{className:"font-semibold text-slate-100 mb-4",children:["Case Results (",e.failed_cases," failed, ",e.passed_cases," passed)"]}),l.jsx("div",{className:"space-y-2 max-h-[50vh] overflow-y-auto",children:e.case_results.map(o=>l.jsxs("div",{className:`panel-subtle rounded-lg overflow-hidden ${o.passed?"":"border border-red-500/30"}`,children:[l.jsxs("button",{onClick:()=>s(o.case_id),className:"w-full px-4 py-3 flex items-center gap-3 text-left hover:bg-slate-700/50 transition-colors",children:[o.passed?l.jsx(Xs,{size:16,className:"text-emerald-400 flex-shrink-0"}):l.jsx(Nt,{size:16,className:"text-red-400 flex-shrink-0"}),l.jsx("span",{className:"font-medium text-slate-200",children:o.case_id}),o.expected&&o.expected.length>0&&l.jsxs("span",{className:"text-sm text-slate-400",children:["expected: ",o.expected.join(" or ")]}),l.jsxs("span",{className:"ml-auto text-sm text-slate-400 flex-shrink-0",children:[o.percentage.toFixed(0),"% | ",o.latency_ms,"ms"]}),t.has(o.case_id)?l.jsx(pe,{size:14,className:"text-slate-500 flex-shrink-0"}):l.jsx(ge,{size:14,className:"text-slate-500 flex-shrink-0"})]}),t.has(o.case_id)&&l.jsxs("div",{className:"px-4 pb-3 pt-1 border-t border-slate-700",children:[o.failure_reason&&l.jsx("div",{className:"text-red-400 text-sm mb-2 p-2 bg-red-950/30 rounded",children:o.failure_reason}),l.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-500",children:"Expected:"})," ",l.jsx("span",{className:"text-slate-200",children:o.expected&&o.expected.length>0?o.expected.join(" or "):"N/A"})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-500",children:"Actual:"})," ",l.jsx("span",{className:"text-slate-200",children:o.actual_outcome||"None"})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-500",children:"Score:"})," ",l.jsxs("span",{className:"text-slate-200",children:[o.goal_score,"/",o.max_score]})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-500",children:"Latency:"})," ",l.jsxs("span",{className:"text-slate-200",children:[o.latency_ms,"ms"]})]})]})]})]},o.case_id))})]})]})}/*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT */function wp(e){return typeof e>"u"||e===null}function tv(e){return typeof e=="object"&&e!==null}function nv(e){return Array.isArray(e)?e:wp(e)?[]:[e]}function sv(e,t){var n,s,r,a;if(t)for(a=Object.keys(t),n=0,s=a.length;n<s;n+=1)r=a[n],e[r]=t[r];return e}function lv(e,t){var n="",s;for(s=0;s<t;s+=1)n+=e;return n}function rv(e){return e===0&&Number.NEGATIVE_INFINITY===1/e}var av=wp,iv=tv,ov=nv,cv=lv,uv=rv,dv=sv,me={isNothing:av,isObject:iv,toArray:ov,repeat:cv,isNegativeZero:uv,extend:dv};function bp(e,t){var n="",s=e.reason||"(unknown reason)";return e.mark?(e.mark.name&&(n+='in "'+e.mark.name+'" '),n+="("+(e.mark.line+1)+":"+(e.mark.column+1)+")",!t&&e.mark.snippet&&(n+=`
|
|
286
|
+
*/const bn=W("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]),Dg=[{path:"/",label:"Dashboard",icon:Pg},{path:"/results",label:"Results",icon:Hr},{path:"/builder",label:"Builder",icon:wn},{path:"/datasets",label:"Datasets",icon:sn}];function Ig(){const e=Ft(),[t,n]=x.useState(()=>typeof window<"u"?localStorage.getItem("theme")==="light":!1);return x.useEffect(()=>{t?(document.documentElement.classList.add("light"),localStorage.setItem("theme","light")):(document.documentElement.classList.remove("light"),localStorage.setItem("theme","dark"))},[t]),l.jsxs("div",{className:"app-shell",children:[l.jsxs("aside",{className:"sidebar",children:[l.jsx("div",{className:"p-5 border-b border-slate-800/70",children:l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx("h1",{className:"text-xl font-semibold",style:{color:"var(--app-text)"},children:"Sandboxy Local"}),l.jsx("p",{className:"text-sm",style:{color:"var(--app-muted)"},children:"Development Server"})]}),l.jsx("button",{onClick:()=>n(!t),className:"p-2 rounded-lg transition-colors hover:bg-slate-500/20",title:t?"Switch to dark mode":"Switch to light mode",children:t?l.jsx(Ag,{size:20,style:{color:"var(--app-muted)"}}):l.jsx(zg,{size:20,style:{color:"var(--app-muted)"}})})]})}),l.jsx("nav",{className:"p-4",children:l.jsx("ul",{className:"space-y-2",children:Dg.map(({path:s,label:r,icon:a})=>l.jsx("li",{children:l.jsxs(de,{to:s,"data-active":e.pathname===s,className:"nav-link",children:[l.jsx(a,{size:20}),r]})},s))})})]}),l.jsx("main",{className:"flex-1 overflow-auto",children:l.jsx(Uh,{})})]})}const $g="/api/v1";class Ug{async fetch(t,n){const s=await fetch(`${$g}${t}`,{...n,headers:{"Content-Type":"application/json",...n==null?void 0:n.headers}});if(!s.ok){const r=await s.json().catch(()=>({detail:"Unknown error"}));throw new Error(r.detail||`HTTP ${s.status}`)}return s.json()}async getStatus(){return this.fetch("/local/status")}async listScenarios(){return this.fetch("/local/scenarios")}async getScenario(t){return this.fetch(`/local/scenarios/${encodeURIComponent(t)}`)}async getScenarioGoals(t){return this.fetch(`/local/scenarios/${encodeURIComponent(t)}/goals`)}async getScenarioTools(t){return this.fetch(`/local/scenarios/${encodeURIComponent(t)}/tools`)}async listTools(){return this.fetch("/local/tools")}async getTool(t){return this.fetch(`/local/tools/${encodeURIComponent(t)}`)}async listAgents(){return this.fetch("/local/agents")}async getAgent(t){return this.fetch(`/local/agents/${encodeURIComponent(t)}`)}async listModels(){return this.fetch("/local/models")}async listRuns(){return this.fetch("/local/runs")}async getRun(t){return this.fetch(`/local/runs/${encodeURIComponent(t)}`)}async runScenario(t){return this.fetch("/local/run",{method:"POST",body:JSON.stringify(t)})}async compareModels(t){return this.fetch("/local/compare",{method:"POST",body:JSON.stringify(t)})}async listDatasets(){return this.fetch("/local/datasets")}async getDataset(t){return this.fetch(`/local/datasets/${encodeURIComponent(t)}`)}async saveDataset(t,n){return this.fetch("/local/datasets",{method:"POST",body:JSON.stringify({id:t,content:n})})}async updateDataset(t,n){return this.fetch(`/local/datasets/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify({id:t,content:n})})}async deleteDataset(t){return this.fetch(`/local/datasets/${encodeURIComponent(t)}`,{method:"DELETE"})}async runDataset(t){return this.fetch("/local/run-dataset",{method:"POST",body:JSON.stringify(t)})}}class Bg extends Ug{async listProviders(){return(await this.fetch("/providers")).providers}async addProvider(t){return this.fetch("/providers",{method:"POST",body:JSON.stringify(t)})}async getProvider(t){return this.fetch(`/providers/${encodeURIComponent(t)}`)}async deleteProvider(t){await this.fetch(`/providers/${encodeURIComponent(t)}`,{method:"DELETE"})}async testProvider(t){return this.fetch(`/providers/${encodeURIComponent(t)}/test`,{method:"POST"})}}const Z=new Bg;function Hg(){const[e,t]=x.useState(null),[n,s]=x.useState(!0),[r,a]=x.useState(null),[i,o]=x.useState([]),[c,u]=x.useState(!0),[m,f]=x.useState(!1),[g,y]=x.useState(null),[j,v]=x.useState({}),[N,p]=x.useState({name:"",type:"ollama",base_url:"http://localhost:11434/v1"}),[d,h]=x.useState(null),[k,w]=x.useState(!1),R=async()=>{try{const A=await Z.listProviders();o(A)}catch{o([])}finally{u(!1)}},P=async A=>{A.preventDefault(),h(null),w(!0);try{await Z.addProvider(N),await R(),f(!1),p({name:"",type:"ollama",base_url:"http://localhost:11434/v1"})}catch(L){h(L instanceof Error?L.message:"Failed to add provider")}finally{w(!1)}},M=async A=>{y(A);try{const L=await Z.testProvider(A);v(U=>({...U,[A]:{success:L.success,message:L.success?`Connected! Found ${L.models_found.length} models (${L.latency_ms}ms)`:L.error||"Connection failed"}}))}catch(L){v(U=>({...U,[A]:{success:!1,message:L instanceof Error?L.message:"Test failed"}}))}finally{y(null)}},O=async A=>{if(confirm(`Delete provider "${A}"?`))try{await Z.deleteProvider(A),await R(),v(L=>{const U={...L};return delete U[A],U})}catch(L){alert(L instanceof Error?L.message:"Failed to delete provider")}},z=A=>{switch(A){case"ollama":return"http://localhost:11434/v1";case"lmstudio":return"http://localhost:1234/v1";case"vllm":return"http://localhost:8000/v1";default:return"http://localhost:8000/v1"}};return x.useEffect(()=>{fetch("/api/v1/local/status").then(A=>{if(!A.ok)throw new Error("Failed to fetch status");return A.json()}).then(t).catch(A=>a(A.message)).finally(()=>s(!1)),R()},[]),n?l.jsx("div",{className:"p-8 page",children:l.jsx("div",{className:"text-slate-400",children:"Loading..."})}):r?l.jsx("div",{className:"p-8 page",children:l.jsxs("div",{className:"text-red-400",children:["Error: ",r]})}):e?l.jsxs("div",{className:"p-8 page",children:[l.jsxs("div",{className:"mb-8",children:[l.jsx("h1",{className:"text-2xl font-semibold text-slate-100 mb-2",children:"Dashboard"}),l.jsxs("p",{className:"text-slate-400",children:["Root: ",l.jsx("code",{className:"panel-subtle px-2 py-1 rounded",children:e.root_dir})]})]}),l.jsxs("section",{className:"mb-8",children:[l.jsxs("div",{className:"flex items-center justify-between mb-4",children:[l.jsxs("h2",{className:"text-lg font-semibold text-slate-100 flex items-center gap-2",children:[l.jsx(hp,{size:20}),"Scenarios (",e.scenarios.length,")"]}),l.jsxs(de,{to:"/builder",className:"flex items-center gap-1 px-3 py-1.5 bg-orange-400 hover:bg-orange-300 text-slate-900 rounded-lg text-sm font-semibold",children:[l.jsx(Ne,{size:16}),"Create Scenario"]})]}),e.scenarios.length===0?l.jsx("p",{className:"text-slate-400",children:"No scenarios found in scenarios/"}):l.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:e.scenarios.map(A=>l.jsxs("div",{className:"panel-card p-4 hover:border-slate-600 transition-colors",children:[l.jsxs(de,{to:`/scenario/${A.id}`,className:"block mb-3",children:[l.jsxs("div",{className:"flex items-start justify-between",children:[l.jsx("h3",{className:"font-medium text-slate-100 mb-1 hover:text-orange-400 transition-colors",children:A.name}),l.jsx(ge,{size:16,className:"text-slate-600 mt-1 flex-shrink-0"})]}),l.jsx("p",{className:"text-sm text-slate-400 line-clamp-2",children:A.description||"No description"})]}),l.jsxs("div",{className:"flex justify-between items-center pt-2 border-t border-slate-700/40",children:[l.jsx("span",{className:"text-xs text-slate-500",children:A.relative_path}),l.jsxs(de,{to:`/run/${A.id}`,className:"flex items-center gap-1 px-3 py-1 bg-orange-400 text-slate-900 rounded hover:bg-orange-300 transition-colors text-sm font-medium",children:[l.jsx(Xt,{size:14}),"Run"]})]})]},A.id))})]}),l.jsxs("section",{className:"mb-8",children:[l.jsxs("div",{className:"flex items-center justify-between mb-4",children:[l.jsxs("h2",{className:"text-lg font-semibold text-slate-100 flex items-center gap-2",children:[l.jsx(wn,{size:20}),"Tools (",e.tools.length,")"]}),l.jsxs(de,{to:"/tool-builder",className:"flex items-center gap-1 px-3 py-1.5 bg-emerald-400 hover:bg-emerald-300 text-slate-900 rounded-lg text-sm font-semibold",children:[l.jsx(Ne,{size:16}),"Create Tool"]})]}),e.tools.length===0?l.jsx("p",{className:"text-slate-400",children:"No tools found in tools/"}):l.jsx("div",{className:"flex flex-wrap gap-2",children:e.tools.map(A=>l.jsx("span",{className:"px-3 py-1 panel-subtle rounded-full text-sm text-slate-200 border border-slate-700/60",children:A.name},A.id))})]}),l.jsxs("section",{className:"mb-8",children:[l.jsxs("div",{className:"flex items-center justify-between mb-4",children:[l.jsxs("h2",{className:"text-lg font-semibold text-slate-100 flex items-center gap-2",children:[l.jsx(Ao,{size:20}),"Local Providers (",i.length,")"]}),l.jsxs("button",{onClick:()=>f(!m),className:"flex items-center gap-1 px-3 py-1.5 bg-purple-500 hover:bg-purple-400 text-white rounded-lg text-sm font-semibold",children:[l.jsx(Ne,{size:16}),"Add Provider"]})]}),m&&l.jsxs("div",{className:"panel-card p-4 mb-4",children:[l.jsx("h3",{className:"text-sm font-semibold text-slate-200 mb-3",children:"Add Local Provider"}),l.jsxs("form",{onSubmit:P,className:"space-y-3",children:[l.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-slate-400 mb-1",children:"Name"}),l.jsx("input",{type:"text",value:N.name,onChange:A=>p({...N,name:A.target.value}),placeholder:"ollama-local",className:"w-full px-3 py-1.5 bg-slate-800 border border-slate-700 rounded text-sm text-slate-100 placeholder-slate-500",required:!0})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-slate-400 mb-1",children:"Type"}),l.jsxs("select",{value:N.type,onChange:A=>{const L=A.target.value;p({...N,type:L,base_url:z(L)})},className:"w-full px-3 py-1.5 bg-slate-800 border border-slate-700 rounded text-sm text-slate-100",children:[l.jsx("option",{value:"ollama",children:"Ollama"}),l.jsx("option",{value:"lmstudio",children:"LM Studio"}),l.jsx("option",{value:"vllm",children:"vLLM"}),l.jsx("option",{value:"openai-compatible",children:"OpenAI Compatible"})]})]})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-slate-400 mb-1",children:"Base URL"}),l.jsx("input",{type:"url",value:N.base_url,onChange:A=>p({...N,base_url:A.target.value}),placeholder:"http://localhost:11434/v1",className:"w-full px-3 py-1.5 bg-slate-800 border border-slate-700 rounded text-sm text-slate-100 placeholder-slate-500",required:!0})]}),d&&l.jsx("p",{className:"text-red-400 text-xs",children:d}),l.jsxs("div",{className:"flex gap-2 justify-end",children:[l.jsx("button",{type:"button",onClick:()=>f(!1),className:"px-3 py-1.5 text-slate-400 hover:text-slate-200 text-sm",children:"Cancel"}),l.jsx("button",{type:"submit",disabled:k,className:"px-3 py-1.5 bg-purple-500 hover:bg-purple-400 text-white rounded text-sm font-medium disabled:opacity-50",children:k?"Adding...":"Add Provider"})]})]})]}),c?l.jsx("p",{className:"text-slate-400",children:"Loading providers..."}):i.length===0?l.jsxs("div",{className:"text-slate-400",children:[l.jsx("p",{className:"mb-2",children:"No local providers configured."}),l.jsx("p",{className:"text-sm",children:"Add a provider to use local models like Ollama, LM Studio, or vLLM."})]}):l.jsx("div",{className:"grid gap-3",children:i.map(A=>{var L,U;return l.jsxs("div",{className:"panel-card p-4 flex items-center justify-between",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[A.status==="connected"?l.jsx(fl,{size:18,className:"text-green-400"}):A.status==="error"?l.jsx(Eo,{size:18,className:"text-red-400"}):l.jsx(nn,{size:18,className:"text-slate-500"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"font-medium text-slate-100",children:A.name}),l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-slate-700 rounded text-slate-300",children:A.type}),A.enabled&&l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-green-900/50 text-green-400 rounded",children:"enabled"})]}),l.jsx("div",{className:"text-xs text-slate-400 mt-0.5",children:A.base_url}),((L=A.models)==null?void 0:L.length)>0&&l.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:A.models.map(B=>l.jsx("span",{className:"text-xs px-2 py-0.5 bg-emerald-900/40 border border-emerald-700/50 rounded text-emerald-300",children:B},B))}),(((U=A.models)==null?void 0:U.length)===0||!A.models)&&A.status==="connected"&&l.jsx("div",{className:"text-xs text-slate-500 mt-1",children:"No models available"}),j[A.name]&&l.jsx("div",{className:`text-xs mt-1 ${j[A.name].success?"text-green-400":"text-red-400"}`,children:j[A.name].message})]})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("button",{onClick:()=>M(A.name),disabled:g===A.name,className:"p-1.5 text-slate-400 hover:text-slate-200 hover:bg-slate-700 rounded disabled:opacity-50",title:"Test connection",children:l.jsx(Mg,{size:16,className:g===A.name?"animate-spin":""})}),l.jsx("button",{onClick:()=>O(A.name),className:"p-1.5 text-slate-400 hover:text-red-400 hover:bg-slate-700 rounded",title:"Delete provider",children:l.jsx(Ae,{size:16})})]})]},A.name)})})]})]}):null}function Vg(){const{scenarioId:e}=rp(),[t,n]=x.useState(null),[s,r]=x.useState([]),[a,i]=x.useState([]),[o,c]=x.useState(!0),[u,m]=x.useState(null),[f,g]=x.useState(new Set(["tools","evaluation","interaction"])),y=L=>{g(U=>{const B=new Set(U);return B.has(L)?B.delete(L):B.add(L),B})};if(x.useEffect(()=>{e&&(c(!0),Promise.all([Z.getScenario(e),Z.getScenarioGoals(e).catch(()=>[]),Z.getScenarioTools(e).catch(()=>[])]).then(([L,U,B])=>{n(L),r(U),i(B)}).catch(L=>m(L.message)).finally(()=>c(!1)))},[e]),o)return l.jsx("div",{className:"p-8 page",children:l.jsx("div",{className:"text-slate-400",children:"Loading scenario..."})});if(u||!t)return l.jsxs("div",{className:"p-8 page",children:[l.jsxs("div",{className:"text-red-400",children:["Error: ",u||"Scenario not found"]}),l.jsx(de,{to:"/",className:"text-orange-400 hover:underline mt-4 inline-block",children:"← Back to Dashboard"})]});const j=t.content||{},v=j.steps||[],N=j.mcp_servers||[],p=j.tools||{},d=j.tools_from||[],h=j.evaluation?j.evaluation.judge:null,k=j.evaluation,w=k==null?void 0:k.goals,R=k?k.max_score||((w==null?void 0:w.reduce((L,U)=>L+(U.points||0),0))??0):null,P=t.variables||[],M=v.length>0,O=j.category||null,z=j.tags||[],A=a.length>0?a.length:Object.keys(p).length;return l.jsxs("div",{className:"p-8 page max-w-5xl",children:[l.jsxs(de,{to:"/",className:"inline-flex items-center gap-1 text-slate-400 hover:text-slate-200 mb-6 text-sm",children:[l.jsx(Gs,{size:16}),"Back to Dashboard"]}),l.jsxs("div",{className:"panel-card p-6 mb-6",children:[l.jsxs("div",{className:"flex items-start justify-between",children:[l.jsxs("div",{className:"flex-1",children:[l.jsx("h1",{className:"text-2xl font-semibold text-slate-100 mb-2",children:t.name}),l.jsx("p",{className:"text-slate-400 mb-4",children:t.description}),l.jsxs("div",{className:"flex flex-wrap gap-2",children:[O&&l.jsx("span",{className:"px-2 py-1 bg-purple-900/40 border border-purple-700/50 rounded text-xs text-purple-300",children:O}),z.map(L=>l.jsx("span",{className:"px-2 py-1 bg-slate-700/50 border border-slate-600/50 rounded text-xs text-slate-300",children:L},L))]})]}),l.jsxs("div",{className:"flex gap-2 ml-4",children:[l.jsxs(de,{to:`/builder?scenario=${e}`,className:"flex items-center gap-1.5 px-3 py-2 bg-slate-700 hover:bg-slate-600 text-slate-200 rounded-lg text-sm font-medium transition-colors",children:[l.jsx(Lg,{size:16}),"Edit"]}),l.jsxs(de,{to:`/run/${e}`,className:"flex items-center gap-1.5 px-4 py-2 bg-orange-400 hover:bg-orange-300 text-slate-900 rounded-lg text-sm font-semibold transition-colors",children:[l.jsx(Xt,{size:16}),"Run"]})]})]}),l.jsxs("div",{className:"flex gap-6 mt-6 pt-4 border-t border-slate-700/60",children:[l.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[l.jsx(vr,{size:16,className:"text-slate-500"}),l.jsx("span",{className:"text-slate-400",children:M?`Multi-turn (${v.length} steps)`:"Single-turn"})]}),l.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[l.jsx(wn,{size:16,className:"text-slate-500"}),l.jsx("span",{className:"text-slate-400",children:N.length>0&&A===0?`${N.length} MCP server${N.length!==1?"s":""}`:`${A} tool${A!==1?"s":""}${N.length>0?` + ${N.length} MCP`:""}`})]}),l.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[l.jsx(yi,{size:16,className:"text-slate-500"}),l.jsxs("span",{className:"text-slate-400",children:[s.length," goal",s.length!==1?"s":"",R&&` (${R} pt${R!==1?"s":""})`]})]}),P.length>0&&l.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[l.jsx(ji,{size:16,className:"text-slate-500"}),l.jsxs("span",{className:"text-slate-400",children:[P.length," variables"]})]})]})]}),l.jsxs("div",{className:"panel-card mb-4",children:[l.jsxs("button",{onClick:()=>y("tools"),className:"w-full flex items-center justify-between p-4 text-left hover:bg-slate-800/30 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(wn,{size:18,className:"text-emerald-400"}),l.jsxs("h2",{className:"font-semibold text-slate-100",children:["Tools",N.length>0&&A===0?l.jsxs("span",{className:"ml-2 text-sm font-normal text-slate-400",children:["(",N.length," MCP server",N.length>1?"s":"",")"]}):l.jsxs("span",{className:"ml-2 text-sm font-normal text-slate-400",children:["(",A,N.length>0?` + ${N.length} MCP`:"",")"]})]})]}),f.has("tools")?l.jsx(pe,{size:18,className:"text-slate-500"}):l.jsx(ge,{size:18,className:"text-slate-500"})]}),f.has("tools")&&l.jsxs("div",{className:"px-4 pb-4 space-y-4",children:[N.length>0&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-2",children:"MCP Servers"}),N.map(L=>{var U;return l.jsxs("div",{className:"p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg mb-2",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[l.jsx(Ao,{size:14,className:"text-cyan-400"}),l.jsx("span",{className:"font-medium text-slate-200",children:L.name}),l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-cyan-900/40 text-cyan-300 rounded",children:"MCP"})]}),l.jsx("div",{className:"text-xs text-slate-500 mb-2",children:L.url?l.jsx("span",{className:"font-mono",children:L.url}):L.command?l.jsxs("span",{className:"font-mono",children:[L.command," ",(U=L.args)==null?void 0:U.join(" ")]}):null}),a.length>0&&l.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.map(B=>l.jsx("span",{className:"text-xs px-2 py-1 bg-emerald-900/30 border border-emerald-700/40 rounded text-emerald-300",title:B.description,children:B.name},B.name))})]},L.name)})]}),d.length>0&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-2",children:"Tool Libraries"}),l.jsx("div",{className:"flex flex-wrap gap-2",children:d.map(L=>l.jsx("span",{className:"px-3 py-1.5 bg-slate-800/50 border border-slate-700/60 rounded text-sm text-slate-300",children:L},L))})]}),Object.keys(p).length>0&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-2",children:"Inline Tools (Mock)"}),l.jsx("div",{className:"space-y-2",children:Object.entries(p).map(([L,U])=>{const B=U,C=B.actions,E=C?Object.keys(C):[];return l.jsxs("div",{className:"p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsx(bn,{size:14,className:"text-yellow-400"}),l.jsx("span",{className:"font-medium text-slate-200",children:L}),l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-yellow-900/40 text-yellow-300 rounded",children:"Mock"})]}),typeof B.description=="string"&&B.description&&l.jsx("p",{className:"text-xs text-slate-500 mb-2",children:B.description}),E.length>0&&l.jsx("div",{className:"flex flex-wrap gap-1.5",children:E.map(_=>l.jsx("span",{className:"text-xs px-2 py-1 bg-slate-700/50 rounded text-slate-400",children:_},_))})]},L)})})]}),N.length===0&&d.length===0&&Object.keys(p).length===0&&l.jsx("p",{className:"text-slate-500 text-sm",children:"No tools configured"})]})]}),l.jsxs("div",{className:"panel-card mb-4",children:[l.jsxs("button",{onClick:()=>y("evaluation"),className:"w-full flex items-center justify-between p-4 text-left hover:bg-slate-800/30 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(yi,{size:18,className:"text-orange-400"}),l.jsxs("h2",{className:"font-semibold text-slate-100",children:["Evaluation",R&&l.jsxs("span",{className:"ml-2 text-sm font-normal text-slate-400",children:["(",R," pts max)"]})]})]}),f.has("evaluation")?l.jsx(pe,{size:18,className:"text-slate-500"}):l.jsx(ge,{size:18,className:"text-slate-500"})]}),f.has("evaluation")&&l.jsxs("div",{className:"px-4 pb-4 space-y-4",children:[s.length>0&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-3",children:"Goals"}),l.jsx("div",{className:"space-y-2",children:s.map(L=>{const U=j.evaluation,B=U==null?void 0:U.goals,C=B==null?void 0:B.find(S=>S.id===L.id),E=C==null?void 0:C.detection,_=E==null?void 0:E.type,b=C==null?void 0:C.points;return l.jsxs("div",{className:"flex items-start gap-3 p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg",children:[l.jsx(fl,{size:16,className:"text-slate-600 mt-0.5 flex-shrink-0"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsx("span",{className:"font-medium text-slate-200",children:L.name}),L.outcome&&l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-blue-900/40 text-blue-300 rounded",children:"outcome"})]}),L.description&&l.jsx("p",{className:"text-xs text-slate-500",children:L.description})]}),l.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[_&&l.jsx("span",{className:"text-xs px-2 py-1 bg-slate-700/50 rounded text-slate-400 font-mono",children:_}),b!==void 0&&l.jsxs("span",{className:"text-sm font-semibold text-orange-400",children:[b," pts"]})]})]},L.id)})})]}),h&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-3",children:"Judge"}),l.jsxs("div",{className:"p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[l.jsx(Fg,{size:14,className:"text-purple-400"}),l.jsxs("span",{className:"font-medium text-slate-200 capitalize",children:[h.type," Judge"]}),h.model&&l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-purple-900/40 text-purple-300 rounded",children:h.model})]}),h.pass_threshold!==void 0&&l.jsxs("p",{className:"text-xs text-slate-500 mb-2",children:["Pass threshold: ",(h.pass_threshold*100).toFixed(0),"%"]}),h.rubric&&l.jsxs("details",{className:"text-xs",children:[l.jsx("summary",{className:"text-slate-400 cursor-pointer hover:text-slate-300",children:"View rubric"}),l.jsx("pre",{className:"mt-2 p-2 bg-slate-900 rounded text-slate-400 overflow-auto max-h-48 whitespace-pre-wrap",children:h.rubric})]})]})]}),s.length===0&&!h&&l.jsx("p",{className:"text-slate-500 text-sm",children:"No evaluation configured"})]})]}),l.jsxs("div",{className:"panel-card mb-4",children:[l.jsxs("button",{onClick:()=>y("interaction"),className:"w-full flex items-center justify-between p-4 text-left hover:bg-slate-800/30 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(vr,{size:18,className:"text-blue-400"}),l.jsxs("h2",{className:"font-semibold text-slate-100",children:["Interaction",l.jsxs("span",{className:"ml-2 text-sm font-normal text-slate-400",children:["(",M?"Multi-turn":"Single-turn",")"]})]})]}),f.has("interaction")?l.jsx(pe,{size:18,className:"text-slate-500"}):l.jsx(ge,{size:18,className:"text-slate-500"})]}),f.has("interaction")&&l.jsxs("div",{className:"px-4 pb-4 space-y-4",children:[typeof j.system_prompt=="string"&&j.system_prompt&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-2",children:"System Prompt"}),l.jsx("pre",{className:"p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg text-xs text-slate-300 overflow-auto max-h-48 whitespace-pre-wrap",children:j.system_prompt})]}),M&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-3",children:"Steps"}),l.jsx("div",{className:"space-y-2",children:v.map((L,U)=>{var B;return l.jsxs("div",{className:"flex items-start gap-3 p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg",children:[l.jsx("div",{className:"w-6 h-6 rounded-full bg-blue-900/40 border border-blue-700/50 flex items-center justify-center text-xs text-blue-300 flex-shrink-0",children:U+1}),l.jsxs("div",{className:"flex-1",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsx("span",{className:"font-medium text-slate-200",children:L.id}),l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-slate-700/50 text-slate-400 rounded font-mono",children:L.action})]}),typeof((B=L.params)==null?void 0:B.content)=="string"&&L.params.content&&l.jsxs("p",{className:"text-xs text-slate-500 line-clamp-2",children:[L.params.content.substring(0,100),L.params.content.length>100&&"..."]})]})]},L.id)})})]}),!M&&typeof j.prompt=="string"&&j.prompt&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-2",children:"Prompt"}),l.jsx("pre",{className:"p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg text-xs text-slate-300 overflow-auto max-h-48 whitespace-pre-wrap",children:j.prompt})]})]})]}),P.length>0&&l.jsxs("div",{className:"panel-card mb-4",children:[l.jsxs("button",{onClick:()=>y("variables"),className:"w-full flex items-center justify-between p-4 text-left hover:bg-slate-800/30 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(ji,{size:18,className:"text-indigo-400"}),l.jsxs("h2",{className:"font-semibold text-slate-100",children:["Variables (",P.length,")"]})]}),f.has("variables")?l.jsx(pe,{size:18,className:"text-slate-500"}):l.jsx(ge,{size:18,className:"text-slate-500"})]}),f.has("variables")&&l.jsx("div",{className:"px-4 pb-4",children:l.jsx("div",{className:"grid gap-2",children:P.map(L=>l.jsxs("div",{className:"flex items-center justify-between p-3 bg-slate-800/50 border border-slate-700/60 rounded-lg",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("code",{className:"text-sm font-mono text-indigo-300",children:`{{${L.name}}}`}),l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-slate-700/50 text-slate-400 rounded",children:L.type}),L.required&&l.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-red-900/40 text-red-300 rounded",children:"required"})]}),L.default!==void 0&&l.jsxs("span",{className:"text-xs text-slate-500",children:["default: ",JSON.stringify(L.default)]})]},L.name))})})]}),l.jsxs("div",{className:"panel-card",children:[l.jsxs("button",{onClick:()=>y("file"),className:"w-full flex items-center justify-between p-4 text-left hover:bg-slate-800/30 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Hr,{size:18,className:"text-slate-500"}),l.jsx("h2",{className:"font-semibold text-slate-100",children:"File"})]}),f.has("file")?l.jsx(pe,{size:18,className:"text-slate-500"}):l.jsx(ge,{size:18,className:"text-slate-500"})]}),f.has("file")&&l.jsx("div",{className:"px-4 pb-4",children:l.jsx("p",{className:"text-xs text-slate-500 font-mono",children:t.path})})]})]})}function Wg(){const[e,t]=x.useState("idle"),[n,s]=x.useState(null),[r,a]=x.useState(null),[i,o]=x.useState(null),c=x.useCallback(()=>{t("idle"),s(null),a(null),o(null)},[]),u=x.useCallback(async(f,g,y,j)=>{c(),t("running");try{const v=await Z.runScenario({scenario_id:f,model:g,variables:y,mlflow_export:j==null?void 0:j.enabled,mlflow_tracking_uri:j==null?void 0:j.trackingUri,mlflow_experiment:j==null?void 0:j.experiment,mlflow_tracing:j==null?void 0:j.tracing});v.error?(t("error"),o(v.error)):(t("completed"),s(v))}catch(v){t("error"),o(v instanceof Error?v.message:"Unknown error")}},[c]),m=x.useCallback(async(f,g,y=1,j,v)=>{c(),t("running");try{const N=await Z.compareModels({scenario_id:f,models:g,runs_per_model:y,variables:j,mlflow_export:v==null?void 0:v.enabled,mlflow_tracking_uri:v==null?void 0:v.trackingUri,mlflow_experiment:v==null?void 0:v.experiment,mlflow_tracing:v==null?void 0:v.tracing});t("completed"),a(N)}catch(N){t("error"),o(N instanceof Error?N.message:"Unknown error")}},[c]);return{state:e,result:n,comparison:r,error:i,runScenario:u,compareModels:m,reset:c}}function jp(e,t){return e==null?"-":t===!0||e===0?"Local":e<1e-4?"<$0.0001":e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(3)}`}function Mo({result:e}){var s,r,a;const[t,n]=x.useState(!1);return l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3",children:[e.evaluation&&l.jsxs("div",{className:"panel-card p-4 col-span-2 md:col-span-1",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(Lo,{className:"w-4 h-4"}),"Score"]}),l.jsxs("div",{className:"text-2xl font-bold text-slate-100",children:[e.evaluation.percentage.toFixed(0),"%"]}),l.jsxs("div",{className:"text-xs text-slate-500",children:[e.evaluation.total_score.toFixed(0)," / ",e.evaluation.max_score.toFixed(0)," pts"]})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(_o,{className:"w-4 h-4"}),"Latency"]}),l.jsxs("div",{className:"text-2xl font-bold text-slate-100",children:[((e.latency_ms||0)/1e3).toFixed(1),"s"]})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(vr,{className:"w-4 h-4"}),"Messages"]}),l.jsx("div",{className:"text-2xl font-bold text-slate-100",children:((s=e.history)==null?void 0:s.length)||0})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(bn,{className:"w-4 h-4"}),"Tool Calls"]}),l.jsx("div",{className:"text-2xl font-bold text-slate-100",children:((r=e.tool_calls)==null?void 0:r.length)||0})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(Tg,{className:"w-4 h-4"}),"Tokens"]}),l.jsx("div",{className:"text-2xl font-bold text-slate-100",children:((e.input_tokens||0)+(e.output_tokens||0)).toLocaleString()}),l.jsxs("div",{className:"text-xs text-slate-500",children:[(e.input_tokens||0).toLocaleString()," in / ",(e.output_tokens||0).toLocaleString()," out"]})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(To,{className:"w-4 h-4"}),"Cost"]}),l.jsx("div",{className:"text-2xl font-bold text-emerald-300",children:jp(e.cost_usd,e.is_local)})]})]}),e.evaluation&&e.evaluation.goals&&e.evaluation.goals.length>0&&l.jsxs("div",{className:"panel-card p-6",children:[l.jsx("h3",{className:"text-lg font-semibold text-slate-100 mb-4",children:"Goals"}),l.jsx("div",{className:"space-y-3",children:e.evaluation.goals.map(i=>l.jsxs("div",{className:`flex items-center justify-between p-3 rounded-lg border ${i.achieved?"bg-emerald-500/10 border-emerald-400/40":"bg-slate-950/40 border-slate-800/70"}`,children:[l.jsxs("div",{className:"flex items-center gap-3",children:[i.achieved?l.jsx(fl,{className:"w-5 h-5 text-emerald-400"}):l.jsx(Eo,{className:"w-5 h-5 text-slate-500"}),l.jsxs("div",{children:[l.jsx("div",{className:"font-medium text-slate-100",children:i.name||i.id}),i.reason&&l.jsx("div",{className:"text-sm text-slate-400",children:i.reason})]})]}),l.jsxs("div",{className:`font-bold ${i.achieved?"text-emerald-300":"text-slate-500"}`,children:[i.achieved?`+${i.points}`:"0"," pts"]})]},i.id))})]}),((a=e.evaluation)==null?void 0:a.judge)&&l.jsxs("div",{className:"panel-card p-6",children:[l.jsx("h3",{className:"text-lg font-semibold text-slate-100 mb-4",children:"Judge Evaluation"}),l.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[l.jsxs("div",{className:`text-3xl font-bold ${e.evaluation.judge.passed?"text-emerald-300":"text-red-400"}`,children:[(e.evaluation.judge.score*100).toFixed(0),"%"]}),l.jsx("div",{className:`px-3 py-1 rounded-full text-sm ${e.evaluation.judge.passed?"bg-emerald-500/15 text-emerald-300":"bg-red-900/50 text-red-400"}`,children:e.evaluation.judge.passed?"Passed":"Failed"})]}),l.jsx("p",{className:"text-slate-400",children:e.evaluation.judge.reasoning})]}),e.response&&l.jsxs("div",{className:"panel-card p-6",children:[l.jsx("h3",{className:"text-lg font-semibold text-slate-100 mb-4",children:"Response"}),l.jsx("div",{className:"panel-subtle rounded-lg p-4 whitespace-pre-wrap text-slate-200",children:e.response||"(No response)"})]}),e.history&&e.history.length>0&&l.jsxs("div",{className:"panel-card",children:[l.jsxs("button",{onClick:()=>n(!t),className:"w-full p-4 text-left flex items-center justify-between hover:bg-slate-800/60 transition-colors rounded-lg",children:[l.jsxs("span",{className:"font-semibold text-slate-100",children:["Conversation History (",e.history.length," messages)"]}),l.jsx("span",{className:"text-slate-400",children:t?"Hide":"Show"})]}),t&&l.jsx("div",{className:"px-6 pb-6 space-y-4",children:e.history.map((i,o)=>l.jsxs("div",{className:`p-3 rounded-lg ${i.role==="user"?"bg-orange-500/10 border border-orange-400/40":i.role==="assistant"?"panel-subtle":i.role==="tool"?"bg-amber-500/10 border border-amber-400/40":"panel-subtle"}`,children:[l.jsx("div",{className:"text-xs font-medium text-slate-500 mb-1 uppercase",children:i.role}),l.jsx("div",{className:"text-slate-200 whitespace-pre-wrap text-sm",children:i.content||"(empty)"})]},o))})]}),e.tool_calls&&e.tool_calls.length>0&&l.jsxs("div",{className:"panel-card p-6",children:[l.jsxs("h3",{className:"text-lg font-semibold text-slate-100 mb-4",children:["Tool Calls (",e.tool_calls.length,")"]}),l.jsx("div",{className:"space-y-3",children:e.tool_calls.map((i,o)=>l.jsx(Yg,{call:i},o))})]}),e.error&&l.jsxs("div",{className:"panel-card p-4 border-l-4 border-l-red-500 bg-red-950/30",children:[l.jsxs("div",{className:"flex items-center gap-2 text-red-400 mb-1",children:[l.jsx(nn,{className:"w-4 h-4"}),l.jsx("span",{className:"font-medium",children:"Error"})]}),l.jsx("p",{className:"text-sm text-red-300",children:e.error})]})]})}function uu(e){if(typeof e=="string")try{const t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}return JSON.stringify(e,null,2)}function Yg({call:e}){const[t,n]=x.useState(!1),s=e.result!==void 0&&e.result!==null,r=e.error!==void 0&&e.error!==null;return l.jsxs("div",{className:`panel-subtle rounded-lg overflow-hidden ${e.success?"":"border border-red-500/30"}`,children:[l.jsxs("button",{onClick:()=>n(!t),className:"w-full p-4 text-left flex items-center justify-between hover:bg-slate-800/40 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[t?l.jsx(pe,{className:"w-4 h-4 text-slate-500"}):l.jsx(ge,{className:"w-4 h-4 text-slate-500"}),l.jsxs("code",{className:"text-orange-300",children:[e.tool,".",e.action,"()"]})]}),l.jsx("span",{className:`text-sm ${e.success?"text-emerald-300":"text-red-400"}`,children:e.success?"✓ Success":"✗ Failed"})]}),t&&l.jsxs("div",{className:"px-4 pb-4 space-y-3",children:[l.jsxs("div",{children:[l.jsx("div",{className:"text-xs font-medium text-slate-500 mb-1",children:"Arguments"}),l.jsx("pre",{className:"text-xs text-slate-400 overflow-auto bg-slate-950/50 rounded p-2",children:uu(e.args)})]}),s&&l.jsxs("div",{children:[l.jsx("div",{className:"text-xs font-medium text-emerald-400 mb-1",children:"Result"}),l.jsx("pre",{className:"text-xs text-slate-400 overflow-auto bg-emerald-950/30 rounded p-2 max-h-48",children:uu(e.result)})]}),r&&l.jsxs("div",{children:[l.jsx("div",{className:"text-xs font-medium text-red-400 mb-1",children:"Error"}),l.jsx("pre",{className:"text-xs text-red-300 overflow-auto bg-red-950/30 rounded p-2",children:e.error})]})]})]})}function Qg(e){var o;const t=e.ranking||[],n=[];for(const c of t){const u=(o=e.stats)==null?void 0:o[c];if(!u)continue;const m=u.avg_score||0,f=u.avg_cost_usd||0,g=u.avg_latency_ms||0,y=f>0?m/(f*100):m>0?1/0:0;n.push({modelId:c,score:m,cost:f,latency:g,efficiency:y,badges:[]})}if(n.length===0)return n;const s=n.reduce((c,u)=>c.score>u.score?c:u),r=n.reduce((c,u)=>c.efficiency>u.efficiency?c:u),a=n.filter(c=>c.score>=s.score*.7),i=a.length>0?a.reduce((c,u)=>c.latency<u.latency?c:u):null;for(const c of n)c.modelId===s.modelId&&c.badges.push("quality"),c.modelId===r.modelId&&r.cost>0&&c.badges.push("value"),i&&c.modelId===i.modelId&&c.badges.push("fast");return n}function qg({type:e}){switch(e){case"quality":return l.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-amber-500/20 text-amber-300 border border-amber-500/30",children:[l.jsx(Lo,{className:"w-3 h-3"})," Best Quality"]});case"value":return l.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-emerald-500/20 text-emerald-300 border border-emerald-500/30",children:[l.jsx(To,{className:"w-3 h-3"})," Best Value"]});case"fast":return l.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-blue-500/20 text-blue-300 border border-blue-500/30",children:[l.jsx(bn,{className:"w-3 h-3"})," Fastest"]});default:return null}}function Jg({run:e,onClose:t}){return l.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/70",onClick:t,children:l.jsxs("div",{className:"bg-slate-900 rounded-xl max-w-4xl w-full max-h-[90vh] overflow-hidden flex flex-col",onClick:n=>n.stopPropagation(),children:[l.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-800",children:[l.jsxs("div",{children:[l.jsx("h2",{className:"text-lg font-semibold text-slate-100",children:"Run Details"}),l.jsx("p",{className:"text-sm text-slate-400",children:e.model})]}),l.jsx("button",{onClick:t,className:"p-2 text-slate-400 hover:text-slate-100 hover:bg-slate-800 rounded-lg",children:l.jsx(Nt,{className:"w-5 h-5"})})]}),l.jsx("div",{className:"overflow-auto p-4",children:l.jsx(Mo,{result:e})})]})})}function Np({comparison:e}){var m,f,g,y,j,v,N,p;const[t,n]=x.useState(null),[s,r]=x.useState(null),a=e.ranking||[],i=Qg(e),o=new Map(i.map(d=>[d.modelId,d])),c=new Map;if(e.results)for(const d of e.results){const h=c.get(d.model)||[];h.push(d),c.set(d.model,h)}const u=e.results&&e.results.length>0;return l.jsxs(l.Fragment,{children:[s&&l.jsx(Jg,{run:s,onClose:()=>r(null)}),l.jsxs("div",{className:"space-y-6",children:[i.length>0&&l.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[i.find(d=>d.badges.includes("quality"))&&l.jsxs("div",{className:"panel-card p-4 border-l-4 border-l-amber-400",children:[l.jsxs("div",{className:"flex items-center gap-2 text-amber-300 mb-1",children:[l.jsx(Lo,{className:"w-4 h-4"}),l.jsx("span",{className:"text-sm font-medium",children:"Best Quality"})]}),l.jsx("div",{className:"text-lg font-semibold text-slate-100",children:((m=i.find(d=>d.badges.includes("quality")))==null?void 0:m.modelId.split("/")[1])||((f=i.find(d=>d.badges.includes("quality")))==null?void 0:f.modelId)}),l.jsxs("div",{className:"text-xs text-slate-400 mt-1",children:["Highest score: ",(g=i.find(d=>d.badges.includes("quality")))==null?void 0:g.score.toFixed(1)," pts"]})]}),i.find(d=>d.badges.includes("value"))&&l.jsxs("div",{className:"panel-card p-4 border-l-4 border-l-emerald-400",children:[l.jsxs("div",{className:"flex items-center gap-2 text-emerald-300 mb-1",children:[l.jsx(To,{className:"w-4 h-4"}),l.jsx("span",{className:"text-sm font-medium",children:"Best Value"})]}),l.jsx("div",{className:"text-lg font-semibold text-slate-100",children:((y=i.find(d=>d.badges.includes("value")))==null?void 0:y.modelId.split("/")[1])||((j=i.find(d=>d.badges.includes("value")))==null?void 0:j.modelId)}),l.jsx("div",{className:"text-xs text-slate-400 mt-1",children:(()=>{const d=i.find(R=>R.badges.includes("value")),h=i.find(R=>R.badges.includes("quality"));if(!d||!h)return"";if(d.cost===0)return"Free!";if(d.modelId===h.modelId)return"Also the best quality!";const k=Math.round(d.score/h.score*100),w=h.cost>0?Math.round(d.cost/h.cost*100):0;return w===0?`${k}% quality, nearly free`:`${k}% quality at ${w}% cost`})()})]}),i.find(d=>d.badges.includes("fast"))&&l.jsxs("div",{className:"panel-card p-4 border-l-4 border-l-blue-400",children:[l.jsxs("div",{className:"flex items-center gap-2 text-blue-300 mb-1",children:[l.jsx(bn,{className:"w-4 h-4"}),l.jsx("span",{className:"text-sm font-medium",children:"Fastest"})]}),l.jsx("div",{className:"text-lg font-semibold text-slate-100",children:((v=i.find(d=>d.badges.includes("fast")))==null?void 0:v.modelId.split("/")[1])||((N=i.find(d=>d.badges.includes("fast")))==null?void 0:N.modelId)}),l.jsxs("div",{className:"text-xs text-slate-400 mt-1",children:[((((p=i.find(d=>d.badges.includes("fast")))==null?void 0:p.latency)||0)/1e3).toFixed(1),"s avg latency"]})]})]}),l.jsxs("div",{className:"panel-card overflow-hidden",children:[l.jsxs("div",{className:"p-4 border-b border-slate-800/70",children:[l.jsx("h3",{className:"text-lg font-semibold text-slate-100",children:"Model Comparison"}),l.jsxs("p",{className:"text-sm text-slate-400",children:[e.runs_per_model," run(s) per model"]})]}),l.jsx("div",{className:"overflow-x-auto",children:l.jsxs("table",{className:"w-full",children:[l.jsx("thead",{className:"bg-slate-950/70",children:l.jsxs("tr",{children:[l.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium text-slate-400",children:"Rank"}),l.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium text-slate-400",children:"Model"}),l.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium text-slate-400",children:"Score"}),l.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium text-slate-400",children:"Judge"}),l.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium text-slate-400",children:"Latency"}),l.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium text-slate-400",children:"Tokens"}),l.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium text-slate-400",children:"Cost"})]})}),l.jsx("tbody",{children:a.map((d,h)=>{var M,O;const k=(M=e.stats)==null?void 0:M[d],w=o.get(d),R=c.get(d)||[],P=t===d;return k?l.jsxs(l.Fragment,{children:[l.jsxs("tr",{className:`border-t border-slate-800/70 hover:bg-slate-900/40 ${u?"cursor-pointer":""}`,onClick:()=>u&&n(P?null:d),children:[l.jsx("td",{className:"px-4 py-3",children:l.jsxs("div",{className:"flex items-center gap-2",children:[u&&(P?l.jsx(pe,{className:"w-4 h-4 text-slate-500"}):l.jsx(ge,{className:"w-4 h-4 text-slate-500"})),l.jsxs("span",{className:`font-bold ${h===0?"text-amber-300":"text-slate-400"}`,children:["#",h+1]})]})}),l.jsxs("td",{className:"px-4 py-3",children:[l.jsx("div",{className:"text-slate-100 font-medium",children:d}),w&&w.badges.length>0&&l.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:w.badges.map(z=>l.jsx(qg,{type:z},z))})]}),l.jsx("td",{className:"px-4 py-3 text-right text-slate-100 font-semibold",children:((O=k.avg_score)==null?void 0:O.toFixed(1))||"0"}),l.jsx("td",{className:"px-4 py-3 text-right text-slate-400",children:k.avg_judge_score!=null?`${(k.avg_judge_score*100).toFixed(0)}%`:"-"}),l.jsxs("td",{className:"px-4 py-3 text-right text-slate-400",children:[((k.avg_latency_ms||0)/1e3).toFixed(1),"s"]}),l.jsx("td",{className:"px-4 py-3 text-right text-slate-400",children:((k.total_input_tokens||0)+(k.total_output_tokens||0)).toLocaleString()}),l.jsx("td",{className:"px-4 py-3 text-right text-emerald-300 font-medium",children:jp(k.avg_cost_usd)})]},d),P&&R.length>0&&l.jsx("tr",{children:l.jsx("td",{colSpan:7,className:"px-4 py-2 bg-slate-950/50",children:l.jsxs("div",{className:"ml-8 space-y-2",children:[l.jsxs("div",{className:"text-sm font-medium text-slate-400 mb-2",children:["Individual Runs (",R.length,")"]}),R.map((z,A)=>{var L,U,B;return l.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-slate-900/50 border border-slate-800/50 hover:bg-slate-800/50 cursor-pointer",onClick:C=>{C.stopPropagation(),r(z)},children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsxs("span",{className:"text-slate-500 text-sm",children:["Run ",A+1]}),l.jsxs("span",{className:"text-slate-100 font-medium",children:[((U=(L=z.evaluation)==null?void 0:L.percentage)==null?void 0:U.toFixed(0))||0,"%"]}),((B=z.evaluation)==null?void 0:B.judge)&&l.jsx("span",{className:`text-sm ${z.evaluation.judge.passed?"text-emerald-300":"text-red-400"}`,children:z.evaluation.judge.passed?"✓ Passed":"✗ Failed"}),z.error&&l.jsxs("span",{className:"text-sm text-red-400 flex items-center gap-1",children:[l.jsx(nn,{className:"w-3 h-3"})," Error"]})]}),l.jsxs("button",{className:"flex items-center gap-1 text-sm text-orange-300 hover:text-orange-200",onClick:C=>{C.stopPropagation(),r(z)},children:[l.jsx(xp,{className:"w-4 h-4"}),"View Details"]})]},A)})]})})},`${d}-runs`)]}):null})})]})})]}),e.stats&&Object.values(e.stats).some(d=>d.goal_rates&&Object.keys(d.goal_rates).length>0)&&l.jsxs("div",{className:"panel-card p-6",children:[l.jsx("h3",{className:"text-lg font-semibold text-slate-100 mb-4",children:"Goal Achievement Rates"}),(()=>{const d=new Set;return Object.values(e.stats).forEach(h=>{h.goal_rates&&Object.keys(h.goal_rates).forEach(k=>d.add(k))}),l.jsx("div",{className:"overflow-x-auto",children:l.jsxs("table",{className:"w-full",children:[l.jsx("thead",{className:"bg-slate-950/70",children:l.jsxs("tr",{children:[l.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium text-slate-400",children:"Model"}),Array.from(d).map(h=>l.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium text-slate-400",children:h},h))]})}),l.jsx("tbody",{children:a.map(h=>{var w;const k=(w=e.stats)==null?void 0:w[h];return k?l.jsxs("tr",{className:"border-t border-slate-800/70",children:[l.jsx("td",{className:"px-4 py-3 text-slate-100 font-medium",children:h}),Array.from(d).map(R=>{var M;const P=((M=k.goal_rates)==null?void 0:M[R])??0;return l.jsx("td",{className:"px-4 py-3 text-right",children:l.jsxs("span",{className:P>=100?"text-emerald-300":P>=50?"text-amber-300":"text-red-400",children:[P.toFixed(0),"%"]})},R)})]},h):null})})]})})})()]})]})]})}function As(){return l.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 bg-emerald-500/20 border border-emerald-500/40 rounded text-xs text-emerald-400",children:[l.jsx(gp,{size:10}),"Local"]})}function du({models:e,value:t,onChange:n,disabled:s,placeholder:r="Select a model..."}){const[a,i]=x.useState(!1),[o,c]=x.useState(""),u=x.useRef(null),m=x.useRef(null),f=e.find(p=>p.id===t);x.useEffect(()=>{const p=d=>{u.current&&!u.current.contains(d.target)&&i(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[]),x.useEffect(()=>{a&&m.current&&m.current.focus()},[a]);const g=e.filter(p=>p.name.toLowerCase().includes(o.toLowerCase())||p.id.toLowerCase().includes(o.toLowerCase())),y=g.reduce((p,d)=>{const h=d.provider_name||d.id.split("/")[0]||"other";return p[h]||(p[h]=[]),p[h].push(d),p},{}),j=["openai","anthropic","google","x-ai","deepseek","meta-llama","mistralai","qwen","perplexity"],v=p=>{var d;return(d=y[p])==null?void 0:d.some(h=>h.is_local)},N=Object.keys(y).sort((p,d)=>{const h=v(p),k=v(d);if(h&&!k)return-1;if(!h&&k)return 1;const w=j.indexOf(p),R=j.indexOf(d);return w===-1&&R===-1?p.localeCompare(d):w===-1?1:R===-1?-1:w-R});return l.jsxs("div",{ref:u,className:"relative",children:[l.jsxs("button",{type:"button",onClick:()=>!s&&i(!a),disabled:s,className:`w-full flex items-center justify-between gap-2 px-4 py-2.5 panel-subtle text-left transition-colors ${s?"opacity-50 cursor-not-allowed":"hover:bg-slate-800 cursor-pointer"} ${a?"ring-2 ring-orange-400":""}`,children:[f?l.jsxs("div",{className:"flex items-center justify-between flex-1 min-w-0 gap-2",children:[l.jsx("span",{className:"text-slate-100 truncate",children:f.name}),f.is_local&&l.jsx(As,{}),l.jsx("span",{className:"text-xs text-slate-500 shrink-0",children:f.price})]}):l.jsx("span",{className:"text-slate-500",children:r}),l.jsx(pe,{size:18,className:`text-slate-400 shrink-0 transition-transform ${a?"rotate-180":""}`})]}),a&&l.jsxs("div",{className:"absolute z-50 w-full mt-1 panel-card border border-slate-700/80 dark:border-slate-700/80 shadow-xl max-h-[28rem] overflow-hidden flex flex-col",children:[l.jsx("div",{className:"p-2 border-b border-slate-800/70",children:l.jsxs("div",{className:"relative",children:[l.jsx(Po,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),l.jsx("input",{ref:m,type:"text",value:o,onChange:p=>c(p.target.value),placeholder:"Search models...",className:"w-full pl-9 pr-3 py-2 bg-slate-900 border border-slate-800/70 rounded text-sm text-slate-100 placeholder-slate-500 focus:outline-none focus:border-orange-400/60"})]})}),l.jsxs("div",{className:"overflow-y-auto flex-1",children:[N.map(p=>l.jsxs("div",{children:[l.jsxs("div",{className:"px-3 py-1.5 text-xs font-medium text-slate-500 uppercase bg-slate-900 sticky top-0 flex items-center gap-2",children:[p,v(p)&&l.jsx(As,{})]}),y[p].map(d=>l.jsxs("button",{type:"button",onClick:()=>{n(d.id),i(!1),c("")},className:`w-full flex items-center gap-3 px-3 py-2 text-left transition-colors ${d.id===t?"bg-orange-500/20 text-orange-300":"hover:bg-slate-800 text-slate-100"}`,children:[l.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[l.jsx("div",{className:"truncate",children:d.name}),d.is_local&&!v(p)&&l.jsx(As,{})]}),l.jsx("span",{className:"text-xs text-slate-500 shrink-0",children:d.price}),d.id===t&&l.jsx(Xs,{size:16,className:"text-orange-400 shrink-0"})]},d.id))]},p)),g.length===0&&l.jsx("div",{className:"px-3 py-4 text-center text-slate-500 text-sm",children:"No models found"})]})]})]})}function Kg({models:e,selected:t,onChange:n,disabled:s}){const[r,a]=x.useState(!1),[i,o]=x.useState(""),c=x.useRef(null),u=x.useRef(null);x.useEffect(()=>{const p=d=>{c.current&&!c.current.contains(d.target)&&a(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[]),x.useEffect(()=>{r&&u.current&&u.current.focus()},[r]);const m=p=>{t.includes(p)?n(t.filter(d=>d!==p)):n([...t,p])},f=(p,d)=>{d.stopPropagation(),n(t.filter(h=>h!==p))},g=e.filter(p=>p.name.toLowerCase().includes(i.toLowerCase())||p.id.toLowerCase().includes(i.toLowerCase())),y=g.reduce((p,d)=>{const h=d.provider_name||d.id.split("/")[0]||"other";return p[h]||(p[h]=[]),p[h].push(d),p},{}),j=["openai","anthropic","google","x-ai","deepseek","meta-llama","mistralai","qwen","perplexity"],v=p=>{var d;return(d=y[p])==null?void 0:d.some(h=>h.is_local)},N=Object.keys(y).sort((p,d)=>{const h=v(p),k=v(d);if(h&&!k)return-1;if(!h&&k)return 1;const w=j.indexOf(p),R=j.indexOf(d);return w===-1&&R===-1?p.localeCompare(d):w===-1?1:R===-1?-1:w-R});return l.jsxs("div",{ref:c,className:"relative",children:[t.length>0&&l.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:t.map(p=>{const d=e.find(h=>h.id===p);return l.jsxs("span",{className:`flex items-center gap-1.5 px-2.5 py-1 rounded-full text-sm text-slate-100 ${d!=null&&d.is_local?"bg-emerald-500/20 border border-emerald-400/40":"bg-orange-500/20 border border-orange-400/40"}`,children:[(d==null?void 0:d.is_local)&&l.jsx(gp,{size:12,className:"text-emerald-400"}),(d==null?void 0:d.name)||p,l.jsx("button",{type:"button",onClick:h=>f(p,h),className:"hover:text-red-400 transition-colors",disabled:s,children:l.jsx(Nt,{size:14})})]},p)})}),l.jsxs("button",{type:"button",onClick:()=>!s&&a(!r),disabled:s,className:`w-full flex items-center justify-between gap-2 px-4 py-2.5 panel-subtle text-left transition-colors ${s?"opacity-50 cursor-not-allowed":"hover:bg-slate-800 cursor-pointer"} ${r?"ring-2 ring-orange-400":""}`,children:[l.jsx("span",{className:"text-slate-500",children:t.length===0?"Click to add models...":"Add more models..."}),l.jsx(pe,{size:18,className:`text-slate-400 shrink-0 transition-transform ${r?"rotate-180":""}`})]}),r&&l.jsxs("div",{className:"absolute z-50 w-full mt-1 panel-card border border-slate-700/80 dark:border-slate-700/80 shadow-xl max-h-[28rem] overflow-hidden flex flex-col",children:[l.jsx("div",{className:"p-2 border-b border-slate-800/70",children:l.jsxs("div",{className:"relative",children:[l.jsx(Po,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),l.jsx("input",{ref:u,type:"text",value:i,onChange:p=>o(p.target.value),placeholder:"Search models...",className:"w-full pl-9 pr-3 py-2 bg-slate-900 border border-slate-800/70 rounded text-sm text-slate-100 placeholder-slate-500 focus:outline-none focus:border-orange-400/60"})]})}),l.jsxs("div",{className:"overflow-y-auto flex-1",children:[N.map(p=>l.jsxs("div",{children:[l.jsxs("div",{className:"px-3 py-1.5 text-xs font-medium text-slate-500 uppercase bg-slate-900 sticky top-0 flex items-center gap-2",children:[p,v(p)&&l.jsx(As,{})]}),y[p].map(d=>{const h=t.includes(d.id);return l.jsxs("button",{type:"button",onClick:()=>m(d.id),className:`w-full flex items-center gap-3 px-3 py-2 text-left transition-colors ${h?"bg-orange-500/20 text-orange-300":"hover:bg-slate-800 text-slate-100"}`,children:[l.jsx("div",{className:`w-4 h-4 rounded border flex items-center justify-center shrink-0 ${h?"bg-orange-400 border-orange-400":"border-slate-600"}`,children:h&&l.jsx(Xs,{size:12,className:"text-slate-900"})}),l.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[l.jsx("div",{className:"truncate",children:d.name}),d.is_local&&!v(p)&&l.jsx(As,{})]}),l.jsx("span",{className:"text-xs text-slate-500 shrink-0",children:d.price})]},d.id)})]},p)),g.length===0&&l.jsx("div",{className:"px-3 py-4 text-center text-slate-500 text-sm",children:"No models found"})]})]})]})}function fu(){var Ho;const{scenarioId:e}=rp(),[t]=yg(),n=t.get("dataset"),s=parseInt(t.get("parallel")||"5"),[r,a]=x.useState([]),[i,o]=x.useState(null),[c,u]=x.useState(e||""),[m,f]=x.useState([]),[g,y]=x.useState(""),[j,v]=x.useState([]),[N,p]=x.useState(n?"dataset":"single"),[d,h]=x.useState(1),[k,w]=x.useState({}),[R,P]=x.useState(!0),[M,O]=x.useState(null),[z,A]=x.useState([]),[L,U]=x.useState(n||""),[B,C]=x.useState(null),[E,_]=x.useState(!1),[b,S]=x.useState(s),[T,D]=x.useState(!1),[H,te]=x.useState(!1),[X,lt]=x.useState(""),[Fe,rt]=x.useState(""),[Cn,pl]=x.useState(!0),{state:ae,result:Ot,comparison:Uo,error:Bo,runScenario:dm,compareModels:fm}=Wg();x.useEffect(()=>{(async()=>{try{const[Oe,He,xm]=await Promise.all([Z.listScenarios(),Z.listModels(),Z.listDatasets()]);if(a(Oe),f(He),A(xm),He.length>0&&y(He[0].id),e){u(e);const Vo=await Z.getScenario(e);o(Vo);const Wo={};for(const Yo of Vo.variables||[])Wo[Yo.name]=Yo.default??"";w(Wo)}}catch(Oe){O(Oe instanceof Error?Oe.message:"Failed to load data")}finally{P(!1)}})()},[e]),x.useEffect(()=>{c&&c!==e&&Z.getScenario(c).then(V=>{o(V);const Oe={};for(const He of V.variables||[])Oe[He.name]=He.default??"";w(Oe)}).catch(V=>O(V.message))},[c,e]);const pm=async()=>{const V=c||e;if(!V)return;const Oe=T?{enabled:!0,trackingUri:X||void 0,experiment:Fe||void 0,tracing:Cn}:void 0;if(N==="dataset"){if(!L||!g)return;_(!0),C(null);try{const He=await Z.runDataset({scenario_id:V,dataset_id:L,model:g,parallel:b,mlflow_enabled:T,mlflow_experiment:Fe||void 0});C(He)}catch(He){O(He instanceof Error?He.message:"Dataset run failed")}finally{_(!1)}}else if(N==="single"){if(!g)return;await dm(V,g,k,Oe)}else{if(j.length===0)return;await fm(V,j,d,k,Oe)}},mm=(V,Oe)=>{w(He=>({...He,[V]:Oe}))};return R?l.jsx("div",{className:"flex items-center justify-center h-full",children:l.jsx(cu,{className:"w-8 h-8 animate-spin text-orange-400"})}):M?l.jsx("div",{className:"p-8 page",children:l.jsx("div",{className:"panel-solid p-4 text-red-400 border border-red-700/60",children:M})}):l.jsxs("div",{className:"p-8 max-w-6xl mx-auto page",children:[l.jsxs(de,{to:"/",className:"flex items-center gap-2 text-slate-400 hover:text-slate-100 mb-6",children:[l.jsx(Gs,{size:20}),"Back to Dashboard"]}),l.jsxs("div",{className:"mb-8",children:[l.jsx("h1",{className:"text-2xl font-semibold text-slate-100 mb-2",children:(i==null?void 0:i.name)||e}),(i==null?void 0:i.description)&&l.jsx("p",{className:"text-slate-400",children:i.description})]}),l.jsxs("div",{className:"panel-card p-6 mb-6",children:[l.jsxs("div",{className:"flex items-center justify-between mb-4",children:[l.jsx("h2",{className:"text-lg font-semibold text-slate-100",children:"Run Configuration"}),l.jsxs(de,{to:"/builder",className:"flex items-center gap-2 text-slate-400 hover:text-slate-100 text-sm",children:[l.jsx(Og,{size:16}),"Edit Scenario"]})]}),!e&&l.jsxs("div",{className:"mb-6",children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Scenario"}),l.jsxs("select",{value:c,onChange:V=>u(V.target.value),disabled:ae==="running"||E,className:"w-full panel-subtle px-4 py-2 text-slate-100 focus:outline-none focus:ring-2 focus:ring-orange-400",children:[l.jsx("option",{value:"",children:"Select a scenario..."}),r.map(V=>l.jsx("option",{value:V.id,children:V.name},V.id))]})]}),l.jsxs("div",{className:"mb-6",children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Mode"}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("button",{onClick:()=>p("single"),disabled:ae==="running"||E,className:`px-4 py-2 rounded-lg transition-colors ${N==="single"?"bg-orange-400 text-slate-900":"bg-slate-800 text-slate-300 hover:bg-slate-700"}`,children:"Single Model"}),l.jsx("button",{onClick:()=>p("compare"),disabled:ae==="running"||E,className:`px-4 py-2 rounded-lg transition-colors ${N==="compare"?"bg-orange-400 text-slate-900":"bg-slate-800 text-slate-300 hover:bg-slate-700"}`,children:"Compare Models"}),l.jsxs("button",{onClick:()=>p("dataset"),disabled:ae==="running"||E||z.length===0,className:`flex items-center gap-2 px-4 py-2 rounded-lg transition-colors ${N==="dataset"?"bg-blue-500 text-white":"bg-slate-800 text-slate-300 hover:bg-slate-700"}`,children:[l.jsx(sn,{size:16}),"Dataset Benchmark"]})]})]}),N==="single"?l.jsxs("div",{className:"mb-6",children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Model"}),l.jsx(du,{models:m,value:g,onChange:y,disabled:ae==="running"})]}):N==="compare"?l.jsxs("div",{className:"space-y-4 mb-6",children:[l.jsxs("div",{children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Models to Compare"}),l.jsx(Kg,{models:m,selected:j,onChange:v,disabled:ae==="running"})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Runs per Model"}),l.jsx("input",{type:"number",min:1,max:10,value:d,onChange:V=>h(Math.max(1,Math.min(10,parseInt(V.target.value)||1))),disabled:ae==="running",className:"w-32 panel-subtle px-4 py-2 text-slate-100 focus:outline-none focus:ring-2 focus:ring-orange-400"}),l.jsx("p",{className:"mt-1 text-xs text-slate-500",children:"More runs = more statistical significance"})]})]}):l.jsxs("div",{className:"space-y-4 mb-6",children:[l.jsxs("div",{children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Dataset"}),l.jsxs("select",{value:L,onChange:V=>U(V.target.value),disabled:E,className:"w-full panel-subtle px-4 py-2 text-slate-100 focus:outline-none focus:ring-2 focus:ring-blue-400",children:[l.jsx("option",{value:"",children:"Select a dataset..."}),z.map(V=>l.jsxs("option",{value:V.id,children:[V.name," (",V.case_count," cases)"]},V.id))]}),z.length===0&&l.jsxs("p",{className:"mt-1 text-xs text-slate-500",children:["No datasets found. ",l.jsx(de,{to:"/datasets",className:"text-blue-400 hover:underline",children:"Create one"})]})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Model"}),l.jsx(du,{models:m,value:g,onChange:y,disabled:E})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-2",children:"Parallel Runs"}),l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("input",{type:"number",min:1,max:20,value:b,onChange:V=>S(Math.max(1,Math.min(20,parseInt(V.target.value)||1))),disabled:E,className:"w-20 panel-subtle px-3 py-2 text-slate-100 focus:outline-none focus:ring-2 focus:ring-blue-400"}),l.jsx("span",{className:"text-sm text-slate-500",children:"concurrent cases"})]}),l.jsx("p",{className:"mt-1 text-xs text-slate-500",children:"Higher = faster, but may hit rate limits"})]})]}),i&&i.variables&&i.variables.length>0&&l.jsxs("div",{className:"mb-6 p-4 panel-subtle",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[l.jsx(yp,{size:18,className:"text-slate-400"}),l.jsx("h3",{className:"font-medium text-slate-100",children:"Variables"})]}),l.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:i.variables.map(V=>l.jsx(Xg,{variable:V,value:k[V.name],onChange:Oe=>mm(V.name,Oe),disabled:ae==="running"},V.name))})]}),l.jsxs("div",{className:"mb-6 p-4 panel-subtle",children:[l.jsxs("button",{onClick:()=>te(!H),className:"flex items-center gap-2 w-full text-left",children:[H?l.jsx(pe,{size:18}):l.jsx(ge,{size:18}),l.jsx("span",{className:"font-medium text-slate-100",children:"MLflow Tracking"}),T&&l.jsx("span",{className:"ml-2 px-2 py-0.5 text-xs bg-green-500/20 text-green-400 rounded",children:"Enabled"})]}),H&&l.jsxs("div",{className:"mt-4 space-y-4",children:[l.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[l.jsx("input",{type:"checkbox",checked:T,onChange:V=>D(V.target.checked),disabled:ae==="running"||E,className:"w-4 h-4 rounded border-slate-600 text-orange-400 focus:ring-orange-400"}),l.jsx("span",{className:"text-slate-200",children:"Enable MLflow tracking"})]}),T&&l.jsxs(l.Fragment,{children:[N!=="dataset"&&l.jsxs("div",{children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-1",children:"Tracking URI"}),l.jsx("input",{type:"text",value:X,onChange:V=>lt(V.target.value),disabled:ae==="running",placeholder:"http://127.0.0.1:5000 (uses MLFLOW_TRACKING_URI if empty)",className:"w-full panel-subtle px-3 py-2 text-slate-100 text-sm focus:outline-none focus:ring-2 focus:ring-orange-400"})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-sm font-medium text-slate-400 mb-1",children:"Experiment Name"}),l.jsx("input",{type:"text",value:Fe,onChange:V=>rt(V.target.value),disabled:ae==="running"||E,placeholder:N==="dataset"?`${(i==null?void 0:i.name)||"scenario"}-dataset`:(i==null?void 0:i.name)||"Defaults to scenario name",className:"w-full panel-subtle px-3 py-2 text-slate-100 text-sm focus:outline-none focus:ring-2 focus:ring-orange-400"})]}),N!=="dataset"&&l.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[l.jsx("input",{type:"checkbox",checked:Cn,onChange:V=>pl(V.target.checked),disabled:ae==="running",className:"w-4 h-4 rounded border-slate-600 text-orange-400 focus:ring-orange-400"}),l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-200",children:"Enable LLM Tracing"}),l.jsx("p",{className:"text-xs text-slate-500",children:"Capture detailed traces of each LLM call"})]})]}),l.jsxs("p",{className:"text-xs text-slate-500 flex items-center gap-1",children:[l.jsx(_g,{size:12}),"View results at your MLflow server after the run completes"]})]})]})]}),l.jsx("button",{onClick:pm,disabled:ae==="running"||E||!c||(N==="single"?!g:N==="compare"?j.length===0:!L||!g),className:`flex items-center gap-2 ${N==="dataset"?"bg-blue-500 hover:bg-blue-400":"bg-orange-400 hover:bg-orange-300"} disabled:bg-slate-700 disabled:text-slate-400 disabled:cursor-not-allowed text-slate-900 px-6 py-2 rounded-lg transition-colors font-semibold`,children:ae==="running"||E?l.jsxs(l.Fragment,{children:[l.jsx(cu,{className:"w-4 h-4 animate-spin"}),"Running..."]}):l.jsxs(l.Fragment,{children:[N==="dataset"?l.jsx(sn,{className:"w-4 h-4"}):l.jsx(Xt,{className:"w-4 h-4"}),N==="single"?"Run Scenario":N==="compare"?`Compare ${j.length} Models`:`Run ${((Ho=z.find(V=>V.id===L))==null?void 0:Ho.case_count)||0} Cases`]})})]}),Bo&&l.jsx("div",{className:"panel-solid border border-red-700/60 p-4 mb-6 text-red-400",children:l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Eo,{className:"w-5 h-5"}),l.jsx("span",{children:Bo})]})}),Ot&&l.jsx(Mo,{result:Ot}),Uo&&l.jsx(Np,{comparison:Uo}),B&&l.jsx(Gg,{result:B})]})}function Gg({result:e}){const[t,n]=x.useState(new Set),s=r=>{const a=new Set(t);a.has(r)?a.delete(r):a.add(r),n(a)};return l.jsxs("div",{className:"panel-card p-6",children:[l.jsxs("h2",{className:"text-xl font-semibold text-slate-100 mb-4 flex items-center gap-2",children:[l.jsx(sn,{size:20}),"Dataset Benchmark Results"]}),l.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[l.jsxs("div",{className:"panel-subtle p-4 rounded-lg",children:[l.jsxs("div",{className:"text-2xl font-bold text-slate-100",children:[e.passed_cases,"/",e.total_cases]}),l.jsx("div",{className:"text-sm text-slate-400",children:"Cases Passed"})]}),l.jsxs("div",{className:"panel-subtle p-4 rounded-lg",children:[l.jsxs("div",{className:`text-2xl font-bold ${e.pass_rate>=.9?"text-green-400":e.pass_rate>=.7?"text-yellow-400":"text-red-400"}`,children:[(e.pass_rate*100).toFixed(1),"%"]}),l.jsx("div",{className:"text-sm text-slate-400",children:"Pass Rate"})]}),l.jsxs("div",{className:"panel-subtle p-4 rounded-lg",children:[l.jsxs("div",{className:"text-2xl font-bold text-slate-100",children:[e.avg_percentage.toFixed(1),"%"]}),l.jsx("div",{className:"text-sm text-slate-400",children:"Avg Score"})]}),l.jsxs("div",{className:"panel-subtle p-4 rounded-lg",children:[l.jsxs("div",{className:"text-2xl font-bold text-slate-100",children:[(e.total_time_ms/1e3).toFixed(1),"s"]}),l.jsx("div",{className:"text-sm text-slate-400",children:"Total Time"})]})]}),Object.keys(e.by_expected).length>0&&l.jsxs("div",{className:"mb-6",children:[l.jsx("h3",{className:"font-medium text-slate-300 mb-3",children:"By Expected Outcome"}),l.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-2",children:Object.entries(e.by_expected).map(([r,a])=>{const i=a.passed+a.failed,o=i>0?a.passed/i:0;return l.jsxs("div",{className:"panel-subtle p-3 rounded",children:[l.jsx("div",{className:"font-medium text-slate-200",children:r}),l.jsxs("div",{className:"text-sm text-slate-400",children:[a.passed,"/",i," (",(o*100).toFixed(0),"%)"]})]},r)})})]}),l.jsxs("div",{children:[l.jsxs("h3",{className:"font-medium text-slate-300 mb-3",children:["Case Results (",e.failed_cases," failed)"]}),l.jsx("div",{className:"space-y-2 max-h-[40vh] overflow-y-auto",children:e.case_results.map(r=>l.jsxs("div",{className:`panel-subtle rounded-lg overflow-hidden ${r.passed?"":"border border-red-500/30"}`,children:[l.jsxs("button",{onClick:()=>s(r.case_id),className:"w-full px-4 py-3 flex items-center gap-3 text-left hover:bg-slate-700/50 transition-colors",children:[r.passed?l.jsx(Xs,{size:16,className:"text-green-400"}):l.jsx(Nt,{size:16,className:"text-red-400"}),l.jsx("span",{className:"font-medium text-slate-200",children:r.case_id}),r.expected&&l.jsxs("span",{className:"text-sm text-slate-400",children:["expected: ",r.expected]}),l.jsxs("span",{className:"ml-auto text-sm text-slate-400",children:[r.percentage.toFixed(0),"% | ",r.latency_ms,"ms"]})]}),t.has(r.case_id)&&l.jsxs("div",{className:"px-4 pb-3 pt-1 border-t border-slate-700",children:[r.failure_reason&&l.jsx("div",{className:"text-red-400 text-sm mb-2",children:r.failure_reason}),l.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-400",children:"Expected:"})," ",l.jsx("span",{className:"text-slate-200",children:r.expected||"N/A"})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-400",children:"Actual:"})," ",l.jsx("span",{className:"text-slate-200",children:r.actual_outcome||"None"})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-400",children:"Score:"})," ",l.jsxs("span",{className:"text-slate-200",children:[r.goal_score,"/",r.max_score]})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-400",children:"Latency:"})," ",l.jsxs("span",{className:"text-slate-200",children:[r.latency_ms,"ms"]})]})]})]})]},r.case_id))})]})]})}function Xg({variable:e,value:t,onChange:n,disabled:s}){const r="w-full panel-subtle px-3 py-2 text-slate-100 text-sm focus:outline-none focus:ring-2 focus:ring-orange-400 disabled:opacity-50";return l.jsxs("div",{children:[l.jsxs("label",{className:"block text-sm font-medium text-slate-400 mb-1",children:[e.label,e.required&&l.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),e.type==="select"&&e.options.length>0?l.jsxs("select",{value:String(t??""),onChange:a=>n(a.target.value),disabled:s,className:r,children:[l.jsx("option",{value:"",children:"Select..."}),e.options.map(a=>l.jsx("option",{value:a,children:a},a))]}):e.type==="boolean"?l.jsxs("select",{value:String(t??""),onChange:a=>n(a.target.value==="true"),disabled:s,className:r,children:[l.jsx("option",{value:"",children:"Select..."}),l.jsx("option",{value:"true",children:"True"}),l.jsx("option",{value:"false",children:"False"})]}):e.type==="number"?l.jsx("input",{type:"number",value:String(t??""),onChange:a=>n(a.target.value?Number(a.target.value):""),disabled:s,placeholder:e.default!==null?`Default: ${e.default}`:"",className:r}):l.jsx("input",{type:"text",value:String(t??""),onChange:a=>n(a.target.value),disabled:s,placeholder:e.default!==null?`Default: ${e.default}`:"",className:r})]})}const pu=e=>e.scenario_id.endsWith("_comparison")||e.filename.includes("_comparison_"),mu=e=>e.scenario_id.includes("_dataset_")||e.filename.includes("_dataset_"),Al=e=>e.replace(/_comparison$/,"").replace(/_dataset_.*$/,"");function Zg(){const[e,t]=x.useState([]),[n,s]=x.useState(!0),[r,a]=x.useState(null),[i,o]=x.useState(null),[c,u]=x.useState(null),[m,f]=x.useState(!1),[g,y]=x.useState(!1),[j,v]=x.useState(""),[N,p]=x.useState("all"),[d,h]=x.useState(new Set),k=C=>{h(E=>{const _=new Set(E);return _.has(C)?_.delete(C):_.add(C),_})},{filteredResults:w,groupedResults:R,scenarioOrder:P}=x.useMemo(()=>{let C=e.filter(b=>{if(j){const S=j.toLowerCase();if(!b.scenario_id.toLowerCase().includes(S))return!1}if(N!=="all"){const S=pu(b),T=mu(b);if(N==="comparison"&&!S||N==="dataset"&&!T||N==="single"&&(S||T))return!1}return!0});C=C.sort((b,S)=>new Date(S.timestamp).getTime()-new Date(b.timestamp).getTime());const E={},_=[];for(const b of C){const S=Al(b.scenario_id);E[S]||(E[S]=[],_.push(S)),E[S].push(b)}return{filteredResults:C,groupedResults:E,scenarioOrder:_}},[e,j,N]);x.useEffect(()=>{fetch("/api/v1/local/runs").then(C=>{if(!C.ok)throw new Error("Failed to fetch results");return C.json()}).then(t).catch(C=>a(C.message)).finally(()=>s(!1))},[]);const M=async C=>{try{const E=await fetch(`/api/v1/local/runs/${encodeURIComponent(C)}`);if(!E.ok)throw new Error("Failed to fetch result");const _=await E.json();o(_),u(C),f(!1)}catch(E){console.error("Error fetching result:",E)}},O=async()=>{if(i)try{await navigator.clipboard.writeText(JSON.stringify(i,null,2)),y(!0),setTimeout(()=>y(!1),2e3)}catch(C){console.error("Failed to copy:",C)}},z=C=>{var D,H,te,X,lt;if(!C)return"unknown";const E=C.case_results||((D=C.result)==null?void 0:D.case_results),_=C.dataset_id||((H=C.result)==null?void 0:H.dataset_id);if(E||_)return"dataset";if(C.ranking||((te=C.result)==null?void 0:te.ranking))return"comparison";const S=C.model||((X=C.result)==null?void 0:X.model),T=C.response||((lt=C.result)==null?void 0:lt.response);return S||T!==void 0?"single":"unknown"},A=C=>{const E=C.result||C;return{id:E.id||"",scenario_id:E.scenario_id||C.scenario_id||"",model:E.model||"",response:E.response||"",history:E.history||[],tool_calls:E.tool_calls||[],final_state:E.final_state||{},evaluation:E.evaluation||null,latency_ms:E.latency_ms||0,input_tokens:E.input_tokens||0,output_tokens:E.output_tokens||0,cost_usd:E.cost_usd||null,error:E.error||null}},L=C=>{const E=C.result||C;return{scenario_id:E.scenario_id||C.scenario_id||"",scenario_name:E.scenario_name||C.scenario_id||"",models:E.models||[],runs_per_model:E.runs_per_model||1,stats:E.stats||{},ranking:E.ranking||[],winner:E.winner||null,results:E.results||[]}},U=C=>{const E=C.result||C;return{scenario_id:E.scenario_id||C.scenario_id||"",model:E.model||"",dataset_id:E.dataset_id||"",total_cases:E.total_cases||0,passed_cases:E.passed_cases||0,failed_cases:E.failed_cases||0,pass_rate:E.pass_rate||0,avg_score:E.avg_score||0,avg_percentage:E.avg_percentage||0,by_expected:E.by_expected||{},total_time_ms:E.total_time_ms||0,case_results:E.case_results||[]}};if(n)return l.jsx("div",{className:"p-8 page",children:l.jsx("div",{className:"text-slate-400",children:"Loading..."})});if(r)return l.jsx("div",{className:"p-8 page",children:l.jsxs("div",{className:"text-red-400",children:["Error: ",r]})});const B=z(i);return l.jsxs("div",{className:"p-8 page",children:[l.jsx("h1",{className:"text-2xl font-semibold text-slate-100 mb-6",children:"Run Results"}),e.length===0?l.jsxs("div",{className:"panel-card p-6 text-center",children:[l.jsx(Hr,{size:48,className:"mx-auto text-slate-600 mb-4"}),l.jsx("p",{className:"text-slate-400 mb-2",children:"No run results found"}),l.jsx("p",{className:"text-slate-500 text-sm mb-4",children:"Run a scenario to see results here."}),l.jsxs(de,{to:"/",className:"inline-flex items-center gap-2 text-orange-300 hover:text-orange-200",children:[l.jsx(Xt,{size:16}),"Go to Dashboard"]})]}):l.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[l.jsxs("div",{className:"lg:col-span-1 space-y-4",children:[l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"relative",children:[l.jsx(Po,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),l.jsx("input",{type:"text",placeholder:"Search scenarios...",value:j,onChange:C=>v(C.target.value),className:"w-full bg-slate-900/60 border border-slate-700/50 rounded-lg pl-10 pr-4 py-2 text-sm text-slate-100 placeholder-slate-500 focus:outline-none focus:border-orange-400/50"})]}),l.jsxs("div",{className:"flex flex-wrap gap-1 p-1 bg-slate-900/60 rounded-lg border border-slate-700/50",children:[l.jsx("button",{onClick:()=>p("all"),className:`flex-1 min-w-0 px-2 py-1.5 text-xs font-medium rounded-md transition-colors ${N==="all"?"bg-slate-700/80 text-slate-100":"text-slate-400 hover:text-slate-200"}`,children:"All"}),l.jsxs("button",{onClick:()=>p("single"),className:`flex-1 min-w-0 px-2 py-1.5 text-xs font-medium rounded-md transition-colors flex items-center justify-center gap-1 ${N==="single"?"bg-slate-700/80 text-slate-100":"text-slate-400 hover:text-slate-200"}`,children:[l.jsx(bn,{size:12}),"Single"]}),l.jsxs("button",{onClick:()=>p("comparison"),className:`flex-1 min-w-0 px-2 py-1.5 text-xs font-medium rounded-md transition-colors flex items-center justify-center gap-1 ${N==="comparison"?"bg-slate-700/80 text-slate-100":"text-slate-400 hover:text-slate-200"}`,children:[l.jsx(ou,{size:12}),"Compare"]}),l.jsxs("button",{onClick:()=>p("dataset"),className:`flex-1 min-w-0 px-2 py-1.5 text-xs font-medium rounded-md transition-colors flex items-center justify-center gap-1 ${N==="dataset"?"bg-blue-600/80 text-slate-100":"text-slate-400 hover:text-slate-200"}`,children:[l.jsx(sn,{size:12}),"Dataset"]})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("h2",{className:"text-sm font-medium text-slate-400",children:[w.length," result",w.length!==1?"s":""," in ",P.length," scenario",P.length!==1?"s":""]}),j&&l.jsx("button",{onClick:()=>v(""),className:"text-xs text-slate-500 hover:text-slate-300",children:"Clear"})]}),l.jsx("div",{className:"space-y-2 max-h-[70vh] overflow-y-auto pr-2",children:P.length===0?l.jsxs("div",{className:"text-center py-8 text-slate-500",children:[l.jsx(Rg,{size:24,className:"mx-auto mb-2 opacity-50"}),l.jsx("p",{className:"text-sm",children:"No results match your filters"})]}):P.map(C=>{const E=R[C],_=d.has(C);return l.jsxs("div",{className:"panel-card overflow-hidden",children:[l.jsxs("button",{onClick:()=>k(C),className:"w-full flex items-center justify-between p-3 hover:bg-slate-800/40 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[_?l.jsx(ge,{size:16,className:"text-slate-500"}):l.jsx(pe,{size:16,className:"text-slate-500"}),l.jsx("span",{className:"font-medium text-slate-200 text-sm",children:C})]}),l.jsx("span",{className:"text-xs text-slate-500 bg-slate-800/60 px-2 py-0.5 rounded",children:E.length})]}),!_&&l.jsx("div",{className:"border-t border-slate-800/50",children:E.map(b=>{const S=pu(b),T=mu(b);return l.jsxs("div",{className:`flex items-center justify-between p-3 cursor-pointer transition-colors border-l-2 ${c===b.filename?"bg-slate-800/60 border-l-orange-400":"hover:bg-slate-800/40 border-l-transparent"}`,onClick:()=>M(b.filename),children:[l.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[T?l.jsx(sn,{size:14,className:"text-blue-400 flex-shrink-0"}):S?l.jsx(ou,{size:14,className:"text-purple-400 flex-shrink-0"}):l.jsx(bn,{size:14,className:"text-orange-400 flex-shrink-0"}),l.jsx("div",{className:"min-w-0",children:l.jsxs("p",{className:"text-xs text-slate-400 flex items-center gap-1",children:[l.jsx(_o,{size:10}),new Date(b.timestamp).toLocaleString()]})})]}),l.jsx(de,{to:`/run/${Al(b.scenario_id)}`,onClick:D=>D.stopPropagation(),className:"p-1.5 text-slate-500 hover:text-orange-300 hover:bg-slate-700/60 rounded flex-shrink-0",title:"Run again",children:l.jsx(Xt,{size:12})})]},b.filename)})})]},C)})})]}),l.jsx("div",{className:"lg:col-span-2",children:i?l.jsxs("div",{className:"space-y-4",children:[l.jsx("div",{className:"panel-card p-4",children:l.jsxs("div",{className:"flex items-center justify-between gap-4",children:[l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsx("h2",{className:"font-semibold text-slate-100 truncate",children:Al(i.scenario_id)}),B==="single"&&A(i).model&&l.jsxs("p",{className:"text-sm text-slate-400 mt-1",children:["Model: ",A(i).model]}),B==="comparison"&&l.jsx("p",{className:"text-sm text-slate-400 mt-1",children:"Model Comparison"}),B==="dataset"&&l.jsxs("p",{className:"text-sm text-slate-400 mt-1",children:["Dataset: ",U(i).dataset_id," | Model: ",U(i).model]})]}),l.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[l.jsxs("button",{onClick:O,className:`flex items-center gap-1 text-xs px-2 py-1 border rounded whitespace-nowrap transition-colors ${g?"text-emerald-400 border-emerald-500/50 bg-emerald-500/10":"text-slate-400 hover:text-slate-100 border-slate-700/70"}`,children:[l.jsx(mp,{size:12}),g?"Copied!":"Copy JSON"]}),l.jsx("button",{onClick:()=>f(!m),className:"text-xs text-slate-400 hover:text-slate-100 px-2 py-1 border border-slate-700/70 rounded whitespace-nowrap",children:m?"View Details":"View JSON"}),l.jsxs(de,{to:`/run/${Al(i.scenario_id)}`,className:"flex items-center gap-1 bg-orange-400 hover:bg-orange-300 text-slate-900 px-3 py-1 rounded text-sm font-semibold whitespace-nowrap",children:[l.jsx(Xt,{size:14}),"Run Again"]})]})]})}),m?l.jsx("div",{className:"panel-card p-4",children:l.jsx("pre",{className:"text-xs text-slate-300 bg-slate-950/70 p-3 rounded overflow-auto max-h-[70vh]",children:JSON.stringify(i,null,2)})}):l.jsxs(l.Fragment,{children:[B==="single"&&l.jsx(Mo,{result:A(i)}),B==="comparison"&&l.jsx(Np,{comparison:L(i)}),B==="dataset"&&l.jsx(ev,{result:U(i)}),B==="unknown"&&l.jsx("div",{className:"panel-card p-6 text-center",children:l.jsx("p",{className:"text-slate-500",children:'Could not parse result format. Click "View JSON" to see raw data.'})})]})]}):l.jsxs("div",{className:"panel-card p-8 text-center",children:[l.jsx(xp,{size:32,className:"mx-auto text-slate-600 mb-3"}),l.jsx("p",{className:"text-slate-400",children:"Select a result to view details"})]})})]})]})}function ev({result:e}){const[t,n]=x.useState(new Set),s=o=>{const c=new Set(t);c.has(o)?c.delete(o):c.add(o),n(c)},r=e.passed_cases,a=e.total_cases,i=e.pass_rate;return l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(sn,{className:"w-4 h-4"}),"Cases Passed"]}),l.jsxs("div",{className:`text-2xl font-bold ${i>=.9?"text-emerald-300":i>=.7?"text-amber-300":"text-red-400"}`,children:[r,"/",a]}),l.jsxs("div",{className:"text-xs text-slate-500",children:[(i*100).toFixed(1),"% pass rate"]})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(Xs,{className:"w-4 h-4"}),"Avg Score"]}),l.jsxs("div",{className:"text-2xl font-bold text-slate-100",children:[e.avg_percentage.toFixed(1),"%"]}),l.jsxs("div",{className:"text-xs text-slate-500",children:[e.avg_score.toFixed(1)," points"]})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(_o,{className:"w-4 h-4"}),"Total Time"]}),l.jsxs("div",{className:"text-2xl font-bold text-slate-100",children:[(e.total_time_ms/1e3).toFixed(1),"s"]}),l.jsxs("div",{className:"text-xs text-slate-500",children:[Math.round(e.total_time_ms/Math.max(a,1)),"ms/case"]})]}),l.jsxs("div",{className:"panel-card p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[l.jsx(Nt,{className:"w-4 h-4"}),"Failed"]}),l.jsx("div",{className:"text-2xl font-bold text-red-400",children:e.failed_cases}),l.jsxs("div",{className:"text-xs text-slate-500",children:[a-r," case",a-r!==1?"s":""," failed"]})]})]}),Object.keys(e.by_expected).length>0&&l.jsxs("div",{className:"panel-card p-6",children:[l.jsx("h3",{className:"font-semibold text-slate-100 mb-4",children:"By Expected Outcome"}),l.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:Object.entries(e.by_expected).map(([o,c])=>{const u=c.passed+c.failed,m=u>0?c.passed/u:0;return l.jsxs("div",{className:"panel-subtle p-3 rounded-lg",children:[l.jsx("div",{className:"font-medium text-slate-200",children:o}),l.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[l.jsxs("div",{className:`text-lg font-semibold ${m>=.9?"text-emerald-300":m>=.7?"text-amber-300":"text-red-400"}`,children:[c.passed,"/",u]}),l.jsxs("span",{className:"text-xs text-slate-500",children:["(",(m*100).toFixed(0),"%)"]})]})]},o)})})]}),l.jsxs("div",{className:"panel-card p-6",children:[l.jsxs("h3",{className:"font-semibold text-slate-100 mb-4",children:["Case Results (",e.failed_cases," failed, ",e.passed_cases," passed)"]}),l.jsx("div",{className:"space-y-2 max-h-[50vh] overflow-y-auto",children:e.case_results.map(o=>l.jsxs("div",{className:`panel-subtle rounded-lg overflow-hidden ${o.passed?"":"border border-red-500/30"}`,children:[l.jsxs("button",{onClick:()=>s(o.case_id),className:"w-full px-4 py-3 flex items-center gap-3 text-left hover:bg-slate-700/50 transition-colors",children:[o.passed?l.jsx(Xs,{size:16,className:"text-emerald-400 flex-shrink-0"}):l.jsx(Nt,{size:16,className:"text-red-400 flex-shrink-0"}),l.jsx("span",{className:"font-medium text-slate-200",children:o.case_id}),o.expected&&o.expected.length>0&&l.jsxs("span",{className:"text-sm text-slate-400",children:["expected: ",o.expected.join(" or ")]}),l.jsxs("span",{className:"ml-auto text-sm text-slate-400 flex-shrink-0",children:[o.percentage.toFixed(0),"% | ",o.latency_ms,"ms"]}),t.has(o.case_id)?l.jsx(pe,{size:14,className:"text-slate-500 flex-shrink-0"}):l.jsx(ge,{size:14,className:"text-slate-500 flex-shrink-0"})]}),t.has(o.case_id)&&l.jsxs("div",{className:"px-4 pb-3 pt-1 border-t border-slate-700",children:[o.failure_reason&&l.jsx("div",{className:"text-red-400 text-sm mb-2 p-2 bg-red-950/30 rounded",children:o.failure_reason}),l.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-500",children:"Expected:"})," ",l.jsx("span",{className:"text-slate-200",children:o.expected&&o.expected.length>0?o.expected.join(" or "):"N/A"})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-500",children:"Actual:"})," ",l.jsx("span",{className:"text-slate-200",children:o.actual_outcome||"None"})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-500",children:"Score:"})," ",l.jsxs("span",{className:"text-slate-200",children:[o.goal_score,"/",o.max_score]})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-slate-500",children:"Latency:"})," ",l.jsxs("span",{className:"text-slate-200",children:[o.latency_ms,"ms"]})]})]})]})]},o.case_id))})]})]})}/*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT */function wp(e){return typeof e>"u"||e===null}function tv(e){return typeof e=="object"&&e!==null}function nv(e){return Array.isArray(e)?e:wp(e)?[]:[e]}function sv(e,t){var n,s,r,a;if(t)for(a=Object.keys(t),n=0,s=a.length;n<s;n+=1)r=a[n],e[r]=t[r];return e}function lv(e,t){var n="",s;for(s=0;s<t;s+=1)n+=e;return n}function rv(e){return e===0&&Number.NEGATIVE_INFINITY===1/e}var av=wp,iv=tv,ov=nv,cv=lv,uv=rv,dv=sv,me={isNothing:av,isObject:iv,toArray:ov,repeat:cv,isNegativeZero:uv,extend:dv};function bp(e,t){var n="",s=e.reason||"(unknown reason)";return e.mark?(e.mark.name&&(n+='in "'+e.mark.name+'" '),n+="("+(e.mark.line+1)+":"+(e.mark.column+1)+")",!t&&e.mark.snippet&&(n+=`
|
|
287
287
|
|
|
288
288
|
`+e.mark.snippet),s+" "+n):s}function Zs(e,t){Error.call(this),this.name="YAMLException",this.reason=e,this.mark=t,this.message=bp(this,!1),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack||""}Zs.prototype=Object.create(Error.prototype);Zs.prototype.constructor=Zs;Zs.prototype.toString=function(t){return this.name+": "+bp(this,t)};var Te=Zs;function ja(e,t,n,s,r){var a="",i="",o=Math.floor(r/2)-1;return s-t>o&&(a=" ... ",t=s-o+a.length),n-s>o&&(i=" ...",n=s+o-i.length),{str:a+e.slice(t,n).replace(/\t/g,"→")+i,pos:s-t+a.length}}function Na(e,t){return me.repeat(" ",t-e.length)+e}function fv(e,t){if(t=Object.create(t||null),!e.buffer)return null;t.maxLength||(t.maxLength=79),typeof t.indent!="number"&&(t.indent=1),typeof t.linesBefore!="number"&&(t.linesBefore=3),typeof t.linesAfter!="number"&&(t.linesAfter=2);for(var n=/\r?\n|\r|\0/g,s=[0],r=[],a,i=-1;a=n.exec(e.buffer);)r.push(a.index),s.push(a.index+a[0].length),e.position<=a.index&&i<0&&(i=s.length-2);i<0&&(i=s.length-1);var o="",c,u,m=Math.min(e.line+t.linesAfter,r.length).toString().length,f=t.maxLength-(t.indent+m+3);for(c=1;c<=t.linesBefore&&!(i-c<0);c++)u=ja(e.buffer,s[i-c],r[i-c],e.position-(s[i]-s[i-c]),f),o=me.repeat(" ",t.indent)+Na((e.line-c+1).toString(),m)+" | "+u.str+`
|
|
289
289
|
`+o;for(u=ja(e.buffer,s[i],r[i],e.position,f),o+=me.repeat(" ",t.indent)+Na((e.line+1).toString(),m)+" | "+u.str+`
|
sandboxy/ui/dist/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>Sandboxy Local</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-DfKu4uXt.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index-Qf7gGJk_.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sandboxy
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
4
4
|
Summary: Open-source agent simulation and benchmarking platform
|
|
5
5
|
Project-URL: Homepage, https://github.com/sandboxy-ai/sandboxy
|
|
6
6
|
Project-URL: Repository, https://github.com/sandboxy-ai/sandboxy
|
|
@@ -7,14 +7,14 @@ sandboxy/agents/base.py,sha256=LQQCb0nSoh9ubrDhj5_wsDuwZxA2lz7w3x4Vfk7EPiw,1828
|
|
|
7
7
|
sandboxy/agents/llm_prompt.py,sha256=yIPIztjxl8yqMkHVo3V0PRSCoCsye1K6sF7cUUk_Ik8,13174
|
|
8
8
|
sandboxy/agents/loader.py,sha256=iZJpsrI1o-2lmpWcRnq1gjCYmvCn19mJkhx8U3Y4B3c,6839
|
|
9
9
|
sandboxy/api/__init__.py,sha256=3zw70CGbz3j8rK-8XcuGDx8KNibLfuFuvVEG02OIhek,119
|
|
10
|
-
sandboxy/api/app.py,sha256=
|
|
10
|
+
sandboxy/api/app.py,sha256=lbEFKRJUdrgCtkMbshJvDFMXk1zwSG6pFueUbuVGsXE,2716
|
|
11
11
|
sandboxy/api/routes/__init__.py,sha256=CZS3yxK1CtW80ER3mbPqXbGN19HahbLC0Lu4A-8dw8o,31
|
|
12
12
|
sandboxy/api/routes/agents.py,sha256=6LWJT_IAZrRRhBAzReSNsAI9eAp2oCKP7-5LvkZyeGw,2511
|
|
13
|
-
sandboxy/api/routes/local.py,sha256=
|
|
13
|
+
sandboxy/api/routes/local.py,sha256=lbvlIO-Tp4n9LFc_0iP9x3qqyvq8PCRWnfq23DfynQ8,50759
|
|
14
14
|
sandboxy/api/routes/providers.py,sha256=PZ5dWcog63iR-BoPQ7IME5VnIy5DqKZpQjLCtlPltrk,10894
|
|
15
15
|
sandboxy/api/routes/tools.py,sha256=TPhHBIyo7NNSHWDaaanDfAF1bzqYHT_k1NJ96w8Dw0c,3308
|
|
16
16
|
sandboxy/cli/__init__.py,sha256=WMN-u5rqs1uFuWArGP3crwz2_BXnZg_n6ShWZSSt68g,56
|
|
17
|
-
sandboxy/cli/main.py,sha256=
|
|
17
|
+
sandboxy/cli/main.py,sha256=549QVPGr3JxHdRVCU3QHuk7it6NbFCdnA8oXFEhy97E,63526
|
|
18
18
|
sandboxy/cli/type_detector.py,sha256=WH_xxtmeqeqoYH6oy3voa0_pVL4kjbuRPb3oamaIG-k,1352
|
|
19
19
|
sandboxy/core/__init__.py,sha256=OiBPYPUHF1Jw7qzYHHWqVubTijrQ9D_kazmdYnclHG0,62
|
|
20
20
|
sandboxy/core/async_runner.py,sha256=YsAg3WHnMDwyhenpEl5udLxpVcvkAvYEYH1PAMo70JI,28878
|
|
@@ -37,7 +37,7 @@ sandboxy/mlflow/exporter.py,sha256=u5QvEsVI23ENWlSVWHG9iTgS23kZgYkihACCviBOxMk,1
|
|
|
37
37
|
sandboxy/mlflow/metrics.py,sha256=JHrXQ8dHVGrmdNigTwUFDxf3C-3C5KorDowBuJn2Sw0,3263
|
|
38
38
|
sandboxy/mlflow/tags.py,sha256=KIABLNoKekLv90AeUkVNDTfNVsnGPawKo2YFCiY7Of8,3779
|
|
39
39
|
sandboxy/mlflow/tracing.py,sha256=aYr1ONFK2YNT4C0-qT9IwhsOZAJcDfFSCUJkT4eNOyw,3407
|
|
40
|
-
sandboxy/providers/__init__.py,sha256=
|
|
40
|
+
sandboxy/providers/__init__.py,sha256=VEaRpxZutP_3cBubJpDLQVOLCfnpoFpzR0_aG6--IZU,1755
|
|
41
41
|
sandboxy/providers/anthropic_provider.py,sha256=vwUBd_wRZGlu-R1w4iXkpphpwwS53h0KxoqRdMk_tgk,8779
|
|
42
42
|
sandboxy/providers/base.py,sha256=a3umHX2Jz_pYlvrgaTdWJzd_wk1LS4bu0XXf9g4omrM,3215
|
|
43
43
|
sandboxy/providers/config.py,sha256=XckJjkG_AO016__ySGi2w7n9fpHv0U6bXUV4_BU6xvY,7013
|
|
@@ -45,7 +45,7 @@ sandboxy/providers/http_client.py,sha256=9iFfXG-XeqDm6iKNSzxvmjWkTcffnpkTnct--Tk
|
|
|
45
45
|
sandboxy/providers/local.py,sha256=ytv7WIyS-SseQucef_p9eLxvKCY-XfNsy7u_4VMYRt4,16482
|
|
46
46
|
sandboxy/providers/openai_provider.py,sha256=G2HKW_GV5jXCMXFb7m1zCiW4JHbcstlN1e5P-trFEg4,8676
|
|
47
47
|
sandboxy/providers/openrouter.py,sha256=cQ9ddfrCNYlXMgiggVQN2BsMTUPtK_ulqoMBJQYvhu4,31932
|
|
48
|
-
sandboxy/providers/registry.py,sha256=
|
|
48
|
+
sandboxy/providers/registry.py,sha256=kpnzRkB6qRrmGCaZpA4ptkHBxRuYZ_Ma4l9gyBbnM64,10930
|
|
49
49
|
sandboxy/scenarios/__init__.py,sha256=B8gOx-bCsl8TEFEcI1r9PC490NepprWE7_MauwDs5IQ,308
|
|
50
50
|
sandboxy/scenarios/comparison.py,sha256=DaRmnACdltRdvSEb-VRKT-Wgj-f_bDotiBomUaC7wvw,16426
|
|
51
51
|
sandboxy/scenarios/loader.py,sha256=YFqxV-87ngxqSog7kxxViqMqrMqPi4e49HCIH8dfMG0,9193
|
|
@@ -58,13 +58,13 @@ sandboxy/tools/base.py,sha256=LD7lygRk42MwOEHGf0pCOwFYsfuxOhkKhy3omdjF8fU,3728
|
|
|
58
58
|
sandboxy/tools/loader.py,sha256=9QSqsexIYtRYcHWp6iyq551mYdODtYhKgR7Ld7vc_vM,8228
|
|
59
59
|
sandboxy/tools/yaml_tools.py,sha256=CPJcVclGfUIERLqXO6KgJhEQudmr4UJIGbwQzAkaB0s,24184
|
|
60
60
|
sandboxy/ui/__init__.py,sha256=iSb6TFb3CjM7chzVl--4cmPaIEOLtXghXChxaR0FJ_Y,608
|
|
61
|
-
sandboxy/ui/dist/index.html,sha256=
|
|
62
|
-
sandboxy/ui/dist/assets/index-
|
|
61
|
+
sandboxy/ui/dist/index.html,sha256=yrXTkaNJWUVDKTrL7dMuud_cPsDgNB-zeomybPbtILc,461
|
|
62
|
+
sandboxy/ui/dist/assets/index-DfKu4uXt.js,sha256=4fuf7nK9K6yfT-n19z4zOudC8ITskNud1OxK9Wgc3Qk,415258
|
|
63
63
|
sandboxy/ui/dist/assets/index-Qf7gGJk_.css,sha256=QDuvLJqf7qe5HySqaBcixPBx6EOfWpC9CzhU8U29Wzg,31191
|
|
64
64
|
sandboxy/utils/__init__.py,sha256=lT3hC8XALceDRwUHPInw7bRGodueKQ8JHMgQebPCIxw,61
|
|
65
65
|
sandboxy/utils/time.py,sha256=9w5JEBA_t4mTdThUFBnY4gxzwSYIXcy0QWDIy8j-Xy4,511
|
|
66
|
-
sandboxy-0.0.
|
|
67
|
-
sandboxy-0.0.
|
|
68
|
-
sandboxy-0.0.
|
|
69
|
-
sandboxy-0.0.
|
|
70
|
-
sandboxy-0.0.
|
|
66
|
+
sandboxy-0.0.7.dist-info/METADATA,sha256=7kX_dk4r7SknMxM8633hSHOX1B182hRoWqCyHcTif0Y,8646
|
|
67
|
+
sandboxy-0.0.7.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
68
|
+
sandboxy-0.0.7.dist-info/entry_points.txt,sha256=RkY2kImLhO74KTbwWB58DO_7pisdAx3GZBoY1BJ1VdE,98
|
|
69
|
+
sandboxy-0.0.7.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
70
|
+
sandboxy-0.0.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|