From 238cfe012568f7736a2f6df33521908b010ae186 Mon Sep 17 00:00:00 2001 From: Daniel Kim Date: Fri, 23 Oct 2026 14:51:04 -0700 Subject: [PATCH 1/2] Retry OpenCode plugin activation during catalog discovery --- src/local/harness/opencode_v2.rs | 276 +++++++++++++++++++++++++++++-- 1 file changed, 266 insertions(+), 10 deletions(-) diff --git a/src/local/harness/opencode_v2.rs b/src/local/harness/opencode_v2.rs index ddea85fd0..86eec771d 100644 --- a/src/local/harness/opencode_v2.rs +++ b/src/local/harness/opencode_v2.rs @@ -849,20 +849,63 @@ pub(super) async fn detect( } async fn discover_models(endpoint: &AgentEndpoint) -> Result<(Value, Value)> { + discover_models_with_timeout(endpoint, Duration::from_secs(30)).await +} + +async fn catalog_get(endpoint: &AgentEndpoint, path: &str) -> Result> { + let response = endpoint + .client + .get(format!("{}{path}", endpoint.base_url)) + .send() + .await?; + let status = response.status(); + let text = response.text().await?; + let body = serde_json::from_str::(&text); + if status == reqwest::StatusCode::SERVICE_UNAVAILABLE + && body.as_ref().is_ok_and(|body| { + body["_tag"] == "ServiceUnavailableError" && body["service"] == "plugin" + }) + { + return Ok(None); + } + if !status.is_success() { + return Err(anyhow!( + "OpenCode {path} returned {status}: {}", + crate::local::harness::one_line(&text, 300) + )); + } + let body = body?; + if !body["data"].is_array() { + return Err(anyhow!("OpenCode {path} returned an invalid catalog")); + } + Ok(Some(body)) +} + +async fn discover_models_with_timeout( + endpoint: &AgentEndpoint, + timeout: Duration, +) -> Result<(Value, Value)> { let mut catalog = None; - let result = tokio::time::timeout(Duration::from_secs(30), async { + let mut plugins_pending = false; + let result = tokio::time::timeout(timeout, async { if endpoint.legacy_v2_api { post(endpoint, "/api/plugin/await-activation", &json!({})).await?; } loop { - let models = get(endpoint, "/api/model").await?; - let integrations = get(endpoint, "/api/integration").await?; - let ready = models["data"] - .as_array() - .is_some_and(|models| !models.is_empty()); - catalog = Some((models, integrations)); - if endpoint.legacy_v2_api || ready { - return Ok::<_, anyhow::Error>(()); + let models = catalog_get(endpoint, "/api/model").await?; + plugins_pending = models.is_none(); + if let Some(models) = models { + let integrations = catalog_get(endpoint, "/api/integration").await?; + plugins_pending = integrations.is_none(); + if let Some(integrations) = integrations { + let ready = models["data"] + .as_array() + .is_some_and(|models| !models.is_empty()); + catalog = Some((models, integrations)); + if endpoint.legacy_v2_api || ready { + return Ok::<_, anyhow::Error>(()); + } + } } // OpenCode 2.0.4 removed await-activation; cold catalogs can initially be empty. tokio::time::sleep(Duration::from_millis(200)).await; @@ -872,7 +915,16 @@ async fn discover_models(endpoint: &AgentEndpoint) -> Result<(Value, Value)> { if let Ok(result) = result { result?; } - catalog.ok_or_else(|| anyhow!("OpenCode model discovery timed out")) + catalog.ok_or_else(|| { + if plugins_pending { + anyhow!( + "OpenCode plugins did not finish activating within {} seconds. Re-check OpenCode.", + timeout.as_secs() + ) + } else { + anyhow!("OpenCode model discovery timed out") + } + }) } pub(super) async fn generate( @@ -1133,6 +1185,210 @@ mod tests { server.abort(); } + async fn catalog_server( + app: axum::Router, + legacy: bool, + ) -> (AgentEndpoint, tokio::task::JoinHandle<()>) { + let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); + let endpoint = AgentEndpoint { + base_url: format!("http://{}", listener.local_addr().unwrap()), + client: crate::net::loopback_client().build().unwrap(), + protocol: crate::local::opencode::Protocol::V2, + legacy_v2_api: legacy, + }; + let server = tokio::spawn(async move { axum::serve(listener, app).await.unwrap() }); + (endpoint, server) + } + + fn plugin_pending() -> Value { + json!({"_tag":"ServiceUnavailableError", "service":"plugin", "message":"fixture", "extra":true}) + } + + #[tokio::test] + async fn discovery_retries_plugin_activation_on_both_catalog_routes() { + use axum::{http::StatusCode, routing::get, routing::post, Json, Router}; + use std::sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }; + + for legacy in [false, true] { + for pending_path in ["/api/model", "/api/integration"] { + let polls = Arc::new(AtomicUsize::new(0)); + let activations = Arc::new(AtomicUsize::new(0)); + let count = activations.clone(); + let mut app = Router::new().route( + "/api/plugin/await-activation", + post(move || { + count.fetch_add(1, Ordering::SeqCst); + async { Json(json!({})) } + }), + ); + for path in ["/api/model", "/api/integration"] { + let count = polls.clone(); + app = app.route( + path, + get(move || { + let count = count.clone(); + async move { + if path == pending_path && count.fetch_add(1, Ordering::SeqCst) == 0 + { + (StatusCode::SERVICE_UNAVAILABLE, Json(plugin_pending())) + } else { + (StatusCode::OK, Json(json!({"data":[{"id":path}]}))) + } + } + }), + ); + } + let (endpoint, server) = catalog_server(app, legacy).await; + let result = discover_models_with_timeout(&endpoint, Duration::from_secs(2)).await; + server.abort(); + let (models, integrations) = result.unwrap(); + assert_eq!(models["data"][0]["id"], "/api/model"); + assert_eq!(integrations["data"][0]["id"], "/api/integration"); + assert_eq!(polls.load(Ordering::SeqCst), 2); + assert_eq!(activations.load(Ordering::SeqCst), usize::from(legacy)); + } + } + } + + #[tokio::test] + async fn discovery_does_not_retry_other_errors_or_invalid_catalogs() { + use axum::{http::StatusCode, routing::get, Router}; + use std::sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }; + + for (status, body, diagnostic) in [ + ( + StatusCode::SERVICE_UNAVAILABLE, + "{\"_tag\":\"ServiceUnavailableError\",\"service\":\"storage\"}", + "storage", + ), + ( + StatusCode::SERVICE_UNAVAILABLE, + "{\"_tag\":\"OtherError\",\"service\":\"plugin\"}", + "OtherError", + ), + ( + StatusCode::SERVICE_UNAVAILABLE, + "not JSON\nserver unavailable", + "not JSON server unavailable", + ), + (StatusCode::UNAUTHORIZED, "not signed in", "not signed in"), + (StatusCode::NOT_FOUND, "missing route", "missing route"), + ( + StatusCode::INTERNAL_SERVER_ERROR, + "broken config", + "broken config", + ), + (StatusCode::OK, "not JSON", "expected"), + (StatusCode::OK, "{\"data\":null}", "invalid catalog"), + ] { + for path in ["/api/model", "/api/integration"] { + let polls = Arc::new(AtomicUsize::new(0)); + let count = polls.clone(); + let mut app = Router::new(); + if path == "/api/integration" { + app = app.route("/api/model", get(|| async { "{\"data\":[]}" })); + } + app = app.route( + path, + get(move || { + count.fetch_add(1, Ordering::SeqCst); + async move { (status, body) } + }), + ); + let (endpoint, server) = catalog_server(app, false).await; + let result = discover_models_with_timeout(&endpoint, Duration::from_secs(1)).await; + server.abort(); + let error = result.unwrap_err().to_string(); + assert!(error.contains(diagnostic), "{error}"); + if !status.is_success() { + assert!(error.contains(&status.to_string()), "{error}"); + } + assert_eq!(polls.load(Ordering::SeqCst), 1); + } + } + } + + #[tokio::test] + async fn discovery_deadline_bounds_pending_plugins_and_stalled_requests() { + use axum::{http::StatusCode, routing::get, Json, Router}; + + for stalled in [false, true] { + let app = Router::new().route( + "/api/model", + get(move || async move { + if stalled { + std::future::pending::<()>().await; + } + (StatusCode::SERVICE_UNAVAILABLE, Json(plugin_pending())) + }), + ); + let (endpoint, server) = catalog_server(app, false).await; + let result = tokio::time::timeout( + Duration::from_secs(2), + discover_models_with_timeout(&endpoint, Duration::from_secs(1)), + ) + .await; + server.abort(); + let error = result.unwrap().unwrap_err().to_string(); + if stalled { + assert_eq!(error, "OpenCode model discovery timed out"); + } else { + assert_eq!(error, "OpenCode plugins did not finish activating within 1 seconds. Re-check OpenCode."); + } + } + } + + #[tokio::test] + async fn discovery_timeout_preserves_only_the_last_complete_catalog() { + use axum::{http::StatusCode, routing::get, Json, Router}; + use std::sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }; + + let polls = Arc::new(AtomicUsize::new(0)); + let count = polls.clone(); + let app = Router::new() + .route( + "/api/model", + get(move || { + let count = count.clone(); + async move { + Json(if count.fetch_add(1, Ordering::SeqCst) == 0 { + json!({"data":[]}) + } else { + json!({"data":[{"id":"incomplete"}]}) + }) + } + }), + ) + .route( + "/api/integration", + get(move || { + let count = polls.clone(); + async move { + if count.load(Ordering::SeqCst) == 1 { + (StatusCode::OK, Json(json!({"data":[{"id":"complete"}]}))) + } else { + (StatusCode::SERVICE_UNAVAILABLE, Json(plugin_pending())) + } + } + }), + ); + let (endpoint, server) = catalog_server(app, false).await; + let result = discover_models_with_timeout(&endpoint, Duration::from_secs(1)).await; + server.abort(); + let (models, integrations) = result.unwrap(); + assert_eq!(models, json!({"data":[]})); + assert_eq!(integrations["data"][0]["id"], "complete"); + } + #[test] fn free_text_and_numeric_notes_survive_form_replies_and_reload() { let note = "a custom answer".to_string(); From a1fe974b07dcbf4d8c5e5bdf8097692e3a20ed8b Mon Sep 17 00:00:00 2001 From: Daniel Kim Date: Sun, 25 Oct 2026 16:57:57 -0700 Subject: [PATCH 2/2] Keep failed OpenCode checks visible and simplify regression fixtures --- src/local/harness/opencode_v2.rs | 132 ++++++------------ ...iew-C7B2nDXs.js => PdfPreview-DhcTOsJE.js} | 2 +- .../{index-Ba-ecrFp.js => index-CLzhh7UW.js} | 6 +- ui/dist/index.html | 2 +- ui/src/components/SettingsPage.tsx | 4 + ui/tests/queryConsumers.test.mjs | 65 ++++++--- 6 files changed, 96 insertions(+), 115 deletions(-) rename ui/dist/assets/{PdfPreview-C7B2nDXs.js => PdfPreview-DhcTOsJE.js} (99%) rename ui/dist/assets/{index-Ba-ecrFp.js => index-CLzhh7UW.js} (97%) diff --git a/src/local/harness/opencode_v2.rs b/src/local/harness/opencode_v2.rs index 86eec771d..3b0249390 100644 --- a/src/local/harness/opencode_v2.rs +++ b/src/local/harness/opencode_v2.rs @@ -1138,53 +1138,6 @@ mod tests { } } - #[tokio::test] - async fn discovery_waits_for_a_cold_v2_catalog_without_generation() { - use axum::{routing::get, Json, Router}; - use std::sync::atomic::{AtomicUsize, Ordering}; - use std::sync::Arc; - - let requests = Arc::new(AtomicUsize::new(0)); - let count = requests.clone(); - let app = Router::new() - .route( - "/api/model", - get(move || { - let count = count.clone(); - async move { - Json(if count.fetch_add(1, Ordering::SeqCst) == 0 { - json!({"data":[]}) - } else { - json!({"data":[{"id":"fixture"}]}) - }) - } - }), - ) - .route( - "/api/integration", - get(|| async { Json(json!({"data":[]})) }), - ) - .layer(axum::middleware::from_fn( - |request: axum::extract::Request, next: axum::middleware::Next| async move { - assert_eq!(request.method(), reqwest::Method::GET); - assert!(["/api/model", "/api/integration"].contains(&request.uri().path())); - next.run(request).await - }, - )); - let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); - let endpoint = AgentEndpoint { - base_url: format!("http://{}", listener.local_addr().unwrap()), - client: crate::net::loopback_client().build().unwrap(), - protocol: crate::local::opencode::Protocol::V2, - legacy_v2_api: false, - }; - let server = tokio::spawn(async move { axum::serve(listener, app).await.unwrap() }); - let (models, _) = discover_models(&endpoint).await.unwrap(); - assert_eq!(models["data"][0]["id"], "fixture"); - assert_eq!(requests.load(Ordering::SeqCst), 2); - server.abort(); - } - async fn catalog_server( app: axum::Router, legacy: bool, @@ -1278,12 +1231,6 @@ mod tests { "not JSON server unavailable", ), (StatusCode::UNAUTHORIZED, "not signed in", "not signed in"), - (StatusCode::NOT_FOUND, "missing route", "missing route"), - ( - StatusCode::INTERNAL_SERVER_ERROR, - "broken config", - "broken config", - ), (StatusCode::OK, "not JSON", "expected"), (StatusCode::OK, "{\"data\":null}", "invalid catalog"), ] { @@ -1345,48 +1292,57 @@ mod tests { } #[tokio::test] - async fn discovery_timeout_preserves_only_the_last_complete_catalog() { + async fn discovery_polls_cold_catalogs_and_keeps_the_last_complete_pair() { use axum::{http::StatusCode, routing::get, Json, Router}; use std::sync::{ atomic::{AtomicUsize, Ordering}, Arc, }; - let polls = Arc::new(AtomicUsize::new(0)); - let count = polls.clone(); - let app = Router::new() - .route( - "/api/model", - get(move || { - let count = count.clone(); - async move { - Json(if count.fetch_add(1, Ordering::SeqCst) == 0 { - json!({"data":[]}) - } else { - json!({"data":[{"id":"incomplete"}]}) - }) - } - }), - ) - .route( - "/api/integration", - get(move || { - let count = polls.clone(); - async move { - if count.load(Ordering::SeqCst) == 1 { - (StatusCode::OK, Json(json!({"data":[{"id":"complete"}]}))) - } else { - (StatusCode::SERVICE_UNAVAILABLE, Json(plugin_pending())) + for plugins_reload in [false, true] { + let polls = Arc::new(AtomicUsize::new(0)); + let count = polls.clone(); + let seen = polls.clone(); + let app = Router::new() + .route( + "/api/model", + get(move || { + let count = count.clone(); + async move { + Json(if count.fetch_add(1, Ordering::SeqCst) == 0 { + json!({"data":[]}) + } else { + json!({"data":[{"id":"fixture"}]}) + }) } - } - }), - ); - let (endpoint, server) = catalog_server(app, false).await; - let result = discover_models_with_timeout(&endpoint, Duration::from_secs(1)).await; - server.abort(); - let (models, integrations) = result.unwrap(); - assert_eq!(models, json!({"data":[]})); - assert_eq!(integrations["data"][0]["id"], "complete"); + }), + ) + .route( + "/api/integration", + get(move || { + let seen = seen.clone(); + async move { + if plugins_reload && seen.load(Ordering::SeqCst) > 1 { + (StatusCode::SERVICE_UNAVAILABLE, Json(plugin_pending())) + } else { + (StatusCode::OK, Json(json!({"data":[{"id":"complete"}]}))) + } + } + }), + ); + let (endpoint, server) = catalog_server(app, false).await; + let result = discover_models_with_timeout(&endpoint, Duration::from_secs(1)).await; + server.abort(); + let (models, integrations) = result.unwrap(); + let expected = if plugins_reload { + json!([]) + } else { + json!([{"id":"fixture"}]) + }; + assert_eq!(models["data"], expected); + assert_eq!(integrations["data"][0]["id"], "complete"); + assert!(polls.load(Ordering::SeqCst) >= 2); + } } #[test] diff --git a/ui/dist/assets/PdfPreview-C7B2nDXs.js b/ui/dist/assets/PdfPreview-DhcTOsJE.js similarity index 99% rename from ui/dist/assets/PdfPreview-C7B2nDXs.js rename to ui/dist/assets/PdfPreview-DhcTOsJE.js index 6cbc1fe24..f2e2cc58d 100644 --- a/ui/dist/assets/PdfPreview-C7B2nDXs.js +++ b/ui/dist/assets/PdfPreview-DhcTOsJE.js @@ -1,4 +1,4 @@ -var a1=Object.defineProperty;var cw=h=>{throw TypeError(h)};var o1=(h,e,t)=>e in h?a1(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t;var L=(h,e,t)=>o1(h,typeof e!="symbol"?e+"":e,t),By=(h,e,t)=>e.has(h)||cw("Cannot "+t);var a=(h,e,t)=>(By(h,e,"read from private field"),t?t.call(h):e.get(h)),b=(h,e,t)=>e.has(h)?cw("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(h):e.set(h,t),g=(h,e,t,n)=>(By(h,e,"write to private field"),n?n.call(h,t):e.set(h,t),t),y=(h,e,t)=>(By(h,e,"access private method"),t);var Zt=(h,e,t,n)=>({set _(i){g(h,e,i,t)},get _(){return a(h,e,n)}});import{g as vy,c as LA,r as gi,M as l1,j as fe,f as ku,I as Bu,a as c1,i as hw,P as h1,b as dw,S as d1,d as u1,C as f1,e as p1,h as g1}from"./index-Ba-ecrFp.js";const m1=()=>"Find in document",v1=()=>"在文档中查找",y1=()=>"جست‌وجو در سند",b1=()=>"البحث في المستند",E1=()=>"Buscar en el documento",w1=()=>"दस्तावेज़ में खोजें",A1=()=>"문서에서 찾기",x1=()=>"文書内を検索",S1=()=>"Znajdź w dokumencie",uw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?v1():t==="fa"?y1():t==="ar"?b1():t==="es"?E1():t==="hi"?w1():t==="ko"?A1():t==="ja"?x1():t==="pl"?S1():m1()}),T1=()=>"Fit to width",C1=()=>"适应宽度",P1=()=>"متناسب با عرض",I1=()=>"ملاءمة العرض",R1=()=>"Ajustar al ancho",O1=()=>"चौड़ाई में फ़िट करें",M1=()=>"너비에 맞추기",D1=()=>"幅に合わせる",L1=()=>"Dopasuj do szerokości",fw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?C1():t==="fa"?P1():t==="ar"?I1():t==="es"?R1():t==="hi"?O1():t==="ko"?M1():t==="ja"?D1():t==="pl"?L1():T1()}),N1=()=>"Next match",F1=()=>"下一个匹配项",k1=()=>"مورد بعدی",B1=()=>"التطابق التالي",j1=()=>"Coincidencia siguiente",U1=()=>"अगला मिलान",$1=()=>"다음 일치 항목",H1=()=>"次の一致",V1=()=>"Następne dopasowanie",pw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?F1():t==="fa"?k1():t==="ar"?B1():t==="es"?j1():t==="hi"?U1():t==="ko"?$1():t==="ja"?H1():t==="pl"?V1():N1()}),z1=()=>"Previous match",W1=()=>"上一个匹配项",G1=()=>"مورد قبلی",_1=()=>"التطابق السابق",X1=()=>"Coincidencia anterior",Y1=()=>"पिछला मिलान",K1=()=>"이전 일치 항목",J1=()=>"前の一致",Z1=()=>"Poprzednie dopasowanie",gw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?W1():t==="fa"?G1():t==="ar"?_1():t==="es"?X1():t==="hi"?Y1():t==="ko"?K1():t==="ja"?J1():t==="pl"?Z1():z1()});/** +var a1=Object.defineProperty;var cw=h=>{throw TypeError(h)};var o1=(h,e,t)=>e in h?a1(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t;var L=(h,e,t)=>o1(h,typeof e!="symbol"?e+"":e,t),By=(h,e,t)=>e.has(h)||cw("Cannot "+t);var a=(h,e,t)=>(By(h,e,"read from private field"),t?t.call(h):e.get(h)),b=(h,e,t)=>e.has(h)?cw("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(h):e.set(h,t),g=(h,e,t,n)=>(By(h,e,"write to private field"),n?n.call(h,t):e.set(h,t),t),y=(h,e,t)=>(By(h,e,"access private method"),t);var Zt=(h,e,t,n)=>({set _(i){g(h,e,i,t)},get _(){return a(h,e,n)}});import{g as vy,c as LA,r as gi,M as l1,j as fe,f as ku,I as Bu,a as c1,i as hw,P as h1,b as dw,S as d1,d as u1,C as f1,e as p1,h as g1}from"./index-CLzhh7UW.js";const m1=()=>"Find in document",v1=()=>"在文档中查找",y1=()=>"جست‌وجو در سند",b1=()=>"البحث في المستند",E1=()=>"Buscar en el documento",w1=()=>"दस्तावेज़ में खोजें",A1=()=>"문서에서 찾기",x1=()=>"文書内を検索",S1=()=>"Znajdź w dokumencie",uw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?v1():t==="fa"?y1():t==="ar"?b1():t==="es"?E1():t==="hi"?w1():t==="ko"?A1():t==="ja"?x1():t==="pl"?S1():m1()}),T1=()=>"Fit to width",C1=()=>"适应宽度",P1=()=>"متناسب با عرض",I1=()=>"ملاءمة العرض",R1=()=>"Ajustar al ancho",O1=()=>"चौड़ाई में फ़िट करें",M1=()=>"너비에 맞추기",D1=()=>"幅に合わせる",L1=()=>"Dopasuj do szerokości",fw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?C1():t==="fa"?P1():t==="ar"?I1():t==="es"?R1():t==="hi"?O1():t==="ko"?M1():t==="ja"?D1():t==="pl"?L1():T1()}),N1=()=>"Next match",F1=()=>"下一个匹配项",k1=()=>"مورد بعدی",B1=()=>"التطابق التالي",j1=()=>"Coincidencia siguiente",U1=()=>"अगला मिलान",$1=()=>"다음 일치 항목",H1=()=>"次の一致",V1=()=>"Następne dopasowanie",pw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?F1():t==="fa"?k1():t==="ar"?B1():t==="es"?j1():t==="hi"?U1():t==="ko"?$1():t==="ja"?H1():t==="pl"?V1():N1()}),z1=()=>"Previous match",W1=()=>"上一个匹配项",G1=()=>"مورد قبلی",_1=()=>"التطابق السابق",X1=()=>"Coincidencia anterior",Y1=()=>"पिछला मिलान",K1=()=>"이전 일치 항목",J1=()=>"前の一致",Z1=()=>"Poprzednie dopasowanie",gw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?W1():t==="fa"?G1():t==="ar"?_1():t==="es"?X1():t==="hi"?Y1():t==="ko"?K1():t==="ja"?J1():t==="pl"?Z1():z1()});/** * @license lucide-react v1.23.0 - ISC * * This source code is licensed under the ISC license. diff --git a/ui/dist/assets/index-Ba-ecrFp.js b/ui/dist/assets/index-CLzhh7UW.js similarity index 97% rename from ui/dist/assets/index-Ba-ecrFp.js rename to ui/dist/assets/index-CLzhh7UW.js index daf379d41..8922cfe1f 100644 --- a/ui/dist/assets/index-Ba-ecrFp.js +++ b/ui/dist/assets/index-CLzhh7UW.js @@ -1,4 +1,4 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PdfPreview-C7B2nDXs.js","assets/PdfPreview-DNMWzGmA.css"])))=>i.map(i=>d[i]); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PdfPreview-DhcTOsJE.js","assets/PdfPreview-DNMWzGmA.css"])))=>i.map(i=>d[i]); var JV=Object.defineProperty;var c9=e=>{throw TypeError(e)};var eQ=(e,r,t)=>r in e?JV(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var Ao=(e,r,t)=>eQ(e,typeof r!="symbol"?r+"":r,t),Hw=(e,r,t)=>r.has(e)||c9("Cannot "+t);var ue=(e,r,t)=>(Hw(e,r,"read from private field"),t?t.call(e):r.get(e)),vt=(e,r,t)=>r.has(e)?c9("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(e):r.set(e,t),We=(e,r,t,n)=>(Hw(e,r,"write to private field"),n?n.call(e,t):r.set(e,t),t),Yt=(e,r,t)=>(Hw(e,r,"access private method"),t);var Mm=(e,r,t,n)=>({set _(s){We(e,r,s,t)},get _(){return ue(e,r,n)}});(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))n(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const a of o.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&n(a)}).observe(document,{childList:!0,subtree:!0});function t(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function n(s){if(s.ep)return;s.ep=!0;const o=t(s);fetch(s.href,o)}})();function A0(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var qw={exports:{}},Om={};/** * @license React * react-jsx-runtime.production.js @@ -1153,7 +1153,7 @@ l0,-`+(t+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7, } <\/script>`:""),partial:v})).then(y=>{m||i(y)}),()=>{m=!0,w.abort()}},[e,r,t,s,o]),a===null?l.jsxs("div",{className:"file-view-note flex items-center gap-2 py-2.5 px-4 text-sm text-muted",children:[l.jsx($t,{})," ",SS()]}):l.jsxs("div",{className:o?"relative flex flex-col":"flex h-full min-h-0 flex-col",children:[a.partial&&l.jsx("div",{className:"file-view-note shrink-0 border-b border-b-border-variant py-2 px-4 text-sm text-muted",children:Yxt()}),f&&f.choices.length>1&&l.jsx("div",{className:"absolute z-10",style:{left:f.left,top:f.top,width:f.width},children:l.jsx(ea,{choices:f.choices,value:f.value,variant:"field",floating:!0,dropDown:!0,onSelect:m=>{var w,y;return(y=(w=c.current)==null?void 0:w.contentWindow)==null?void 0:y.postMessage({type:"orx-chart-metric",value:m},"*")}})}),l.jsx("iframe",{ref:c,style:o?{height:_}:void 0,className:`block min-h-0 w-full border-0 bg-white ${o?"shrink-0":"flex-1"}`,title:i2t({name:Ae(n)}),sandbox:"allow-scripts allow-popups allow-downloads",referrerPolicy:"no-referrer",srcDoc:a.source})]})}function Pns({candidates:e,name:r}){var a;const[t,n]=A.useState(null),[s,o]=A.useState(!1);return A.useEffect(()=>{const i=new AbortController;n(null),o(!1);async function c(){var _;for(const d of e)try{const f=await fetch(d.url,{signal:i.signal});if(!f.ok||!((_=f.headers.get("content-type"))!=null&&_.startsWith("text/html")))continue;const p=await f.text();i.signal.aborted||n({...d,html:p});return}catch{if(i.signal.aborted)return}i.signal.aborted||o(!0)}return c(),()=>i.abort()},[e]),l.jsx("div",{className:"inline-html-figure my-2 w-full min-w-0",children:t?l.jsx(DU,{html:t.html,truncated:!1,url:t.url,name:r,resolveSrc:t.resolveAsset,fitContent:!0}):l.jsx("div",{className:"flex h-90 items-center justify-center text-sm text-subtext",children:s?l.jsx("a",{href:(a=e[0])==null?void 0:a.url,target:"_blank",rel:"noopener noreferrer",children:T5()}):SS()})})}const HC=A.createContext(null);function Bns({children:e}){const r=A.Children.toArray(e).filter(A.isValidElement),[t,n]=A.useState(0),[s,o]=A.useState(!1),[a,i]=A.useState(1),c=A.useRef(null),_=Math.min(t,r.length-1);return l.jsx(HC,{value:{zoom:a,setZoom:i,expanded:s,setExpanded:d=>{o(d),d||requestAnimationFrame(()=>{var f;return(f=c.current)==null?void 0:f.focus()})}},children:l.jsxs("div",{ref:c,className:"mt-6 mb-3 outline-none",role:"region",tabIndex:0,"aria-label":LOt(),onKeyDown:d=>{(d.key==="ArrowLeft"||d.key==="ArrowRight")&&(d.preventDefault(),d.stopPropagation(),n(Math.max(0,Math.min(r.length-1,_+(d.key==="ArrowRight"?1:-1)))),s||d.currentTarget.focus())},children:[l.jsx("div",{className:"flex h-100 items-center justify-center overflow-auto [&>p]:m-0 [&>figure]:m-0 [&_img]:max-h-100 [&_img]:mx-auto [&_img]:my-0 [&_img]:object-contain",children:r[_]}),l.jsxs("div",{className:"flex items-center justify-center gap-3 mt-6",children:[l.jsx(xt,{size:"small",disabled:_===0,"aria-label":r$t(),onClick:()=>n(_-1),children:l.jsx(QS,{size:16})}),l.jsxs("span",{className:"text-sm text-subtext tabular-nums","aria-live":"polite",children:[_+1," / ",r.length]}),l.jsx(xt,{size:"small",disabled:_===r.length-1,"aria-label":WOt(),onClick:()=>n(_+1),children:l.jsx(mo,{size:16})})]})]})})}function Fns(e,r,t,n){const s=r*(t===1?16:t===2?n:1);return Math.max(.25,Math.min(4,e*Math.exp(-s*.002)))}const IU=A.createContext(void 0);function PU({projectId:e,sessionId:r,children:t}){const n=A.useMemo(()=>{const s=o=>(o.source==="absolute"?QI(o.path):o.source==="artifact"?hd(e,o.path):G5(e,o.path,{sessionId:r??void 0}))+o.hash;return o=>/^(https?:)?\/\//i.test(o)?[{url:o,resolveAsset:()=>null}]:sYn(o).map(a=>({url:s(a),resolveAsset:i=>{const c=py(i);if((c==null?void 0:c.source)==="absolute")return s(c);const _=FH(a.path,i,!0);return _?s({...a,path:_.path,hash:_.hash}):null}}))},[e,r]);return l.jsx(IU,{value:n,children:t})}function Hns({src:e,alt:r,name:t,onClose:n}){const s=A.useRef(null),o=A.useRef(null),[a,i]=A.useState(1),c=A.useContext(HC),_=(c==null?void 0:c.zoom)??a,d=(c==null?void 0:c.setZoom)??i,[f,p]=A.useState({width:0,height:0}),[m,w]=A.useState({width:0,height:0});A.useEffect(()=>{const v=s.current;v==null||v.showModal(),v==null||v.focus();const x=o.current,k=new ResizeObserver(([S])=>{p({width:S.contentRect.width,height:S.contentRect.height})}),b=S=>{S.preventDefault(),d(C=>Fns(C,S.deltaY,S.deltaMode,(x==null?void 0:x.clientHeight)??0))};return x&&(k.observe(x),x.addEventListener("wheel",b,{passive:!1})),()=>{x==null||x.removeEventListener("wheel",b),k.disconnect(),v==null||v.close()}},[]);const y=m.width&&f.width?Math.min(1,f.width*.9/m.width,f.height*.9/m.height):1;return to.createPortal(l.jsxs("dialog",{ref:s,tabIndex:-1,"aria-label":r||zD(),onCancel:v=>{v.preventDefault(),n()},className:"fixed inset-0 m-0 max-w-none max-h-none w-full h-dvh border-0 outline-none bg-transparent p-0 text-text backdrop:bg-image-backdrop",onClick:v=>{v.stopPropagation(),v.target===v.currentTarget&&n()},children:[l.jsx("div",{ref:o,className:"absolute inset-x-4 sm:inset-x-12 top-16 bottom-32 overflow-auto overscroll-contain",onClick:v=>{v.target===v.currentTarget&&n()},children:l.jsx("div",{className:"flex min-h-full min-w-full w-max pointer-events-none",children:l.jsx("img",{src:e,alt:r,onLoad:v=>w({width:v.currentTarget.naturalWidth,height:v.currentTarget.naturalHeight}),style:m.width?{width:m.width*y*_,height:m.height*y*_}:void 0,className:`pointer-events-auto block m-auto shrink-0 max-w-none rounded-lg shadow-modal ${m.width&&f.width?"visible":"invisible"}`})})}),l.jsxs("div",{className:"absolute top-5 right-5 flex gap-2",children:[l.jsx($p,{shape:"circle",href:e,download:t||!0,"aria-label":R5(),title:R5(),className:"bg-background shadow-popover",children:l.jsx(ix,{size:16})}),l.jsx(xt,{shape:"circle",onClick:n,"aria-label":yp(),title:yp(),className:"bg-background shadow-popover",children:l.jsx(hn,{size:16})})]}),l.jsxs("div",{className:"absolute bottom-6 inset-x-6 flex flex-col items-center gap-3 pointer-events-none",children:[r&&l.jsx("div",{className:"max-w-xl line-clamp-2 rounded-xl bg-background px-4 py-2 text-center text-sm leading-snug shadow-popover",children:r}),l.jsxs("div",{className:"pointer-events-auto flex items-center gap-1 rounded-full bg-background p-1.5 shadow-popover",children:[l.jsx(xt,{shape:"circle",disabled:_<=.25,onClick:()=>d(v=>Math.max(.25,v-.25)),"aria-label":Ub(),title:Ub(),children:l.jsx(rB,{size:16})}),l.jsxs(Se,{variant:"ghost",className:"min-w-16 tabular-nums",onClick:()=>d(1),title:yN(),"aria-label":yN(),children:[Math.round(_*100),"%"]}),l.jsx(xt,{shape:"circle",disabled:_>=4,onClick:()=>d(v=>Math.min(4,v+.25)),"aria-label":qb(),title:qb(),children:l.jsx(Bi,{size:16})})]})]})]}),document.body)}function qns({sources:e,downloadName:r,alt:t="",...n}){const[s,o]=A.useState(0),[a,i]=A.useState(!1),c=A.useContext(HC),_=(c==null?void 0:c.setExpanded)??i,d=e[s];return l.jsxs(l.Fragment,{children:[l.jsx("img",{...n,src:d,alt:t,role:"button",tabIndex:0,"aria-haspopup":"dialog",onClick:f=>{f.preventDefault(),f.stopPropagation(),_(!0)},onKeyDown:f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),f.stopPropagation(),_(!0))},onError:s+1o(s+1):void 0}),((c==null?void 0:c.expanded)??a)&&d&&l.jsx(Hns,{src:d,alt:t,name:r,onClose:()=>_(!1)})]})}const Uns=1e5;function Gns({code:e,lang:r}){const[t,n]=A.useState(!1),s=()=>{var o;(o=navigator.clipboard)==null||o.writeText(e).then(()=>{n(!0),setTimeout(()=>n(!1),1500)})};return l.jsxs("div",{className:"md-code relative my-2.5 mx-0 [&_pre]:m-0 [&:hover_.md-code-copy]:opacity-100",children:[l.jsx(xt,{size:"small",className:"md-code-copy absolute top-1.5 end-1.5 bg-background opacity-0",title:NS(),"aria-label":gOt(),onClick:s,children:t?l.jsx(eo,{size:14}):l.jsx(Md,{size:14})}),l.jsx("pre",{children:l.jsx("code",{children:nqn(e,r,Uns)})})]})}function Wns(e){const r={};for(const t of e.matchAll(/([\w-]+)=(["'])(.*?)\2/g)){const n=t[1];n&&(r[n.toLowerCase()]=t[3]??"")}return r}function WM(e,r,t){let n=r.line,s=r.column;for(let o=0;o]*?)\/?>/gi,n=[];let s=0,o=!1;for(const a of r.matchAll(t)){const i=(a[1]??"").toLowerCase(),c=Wns(a[2]??"");if(!c[i==="run"?"id":"path"])continue;o=!0,a.index>s&&n.push({type:"text",value:r.slice(s,a.index),position:b4(e,s,a.index)});const d=a.index+a[0].length;n.push({children:[],data:{hName:i==="run"?"run-mention":"file-mention",hProperties:c},position:b4(e,a.index,d),type:i==="run"?"runMention":"fileMention"}),s=d}return o?(sBU(e)}function VM({path:e,line:r,exp:t,onOpenFile:n}){const s=e.split("/").pop()||e,o=r!=null?`${s}:${r}`:s;return l.jsxs("button",{className:"file-chip",title:n?Rte({path:Ae(e)}):e,...pn(a=>n==null?void 0:n(e,r,t,void 0,a)),disabled:!n,children:[l.jsx(YP,{size:12}),l.jsx("span",{className:"file-chip-label",children:o})]})}function Vns({id:e,label:r,onOpenRun:t}){return l.jsxs("button",{className:"file-chip run-chip",title:t?mre({id:Ae(e)}):Fne({id:Ae(e)}),...pn(n=>t==null?void 0:t(e,n)),disabled:!t,children:[l.jsx(ux,{size:12}),l.jsx("span",{className:"file-chip-label",children:r||BI()})]})}const FU={singleDollarTextMath:!0},Qns=Bx().use(Dx).use(MU).use(OU,FU).use(xns).use(Kns).use(hy).use(oYn).use(cU);function Xns(e){return bC(e)?!0:!(/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith("#")||e.startsWith("//"))}const HU={code:({node:e,className:r,children:t,...n})=>{const s=r??"",o=/language-(\w+)/.exec(s),a=String(t??"").replace(/\n$/,"");if(!(o!=null||a.includes(` -`)))return l.jsx("code",{className:s,...n,children:t});const c=o?x3(o[1]):null;return l.jsx(Gns,{code:a,lang:c})},pre:({children:e})=>l.jsx(l.Fragment,{children:e})};function Yns({children:e}){return l.jsx("figure",{className:"my-6 mx-auto max-w-full text-left [&_img]:mx-auto [&_img]:my-0 [&_img]:w-auto [&_img]:h-auto [&_img]:max-h-[min(480px,60vh)] [&_img]:object-contain [&_img]:border-0 [&_img]:rounded-none",children:e})}const Zns={figure:({children:e})=>l.jsx(Yns,{children:e}),figcaption:({children:e})=>l.jsx("figcaption",{className:"mt-3 text-sm italic leading-relaxed text-text",children:e}),th:({node:e,...r})=>l.jsx("th",{dir:"auto",...r}),td:({node:e,...r})=>l.jsx("td",{dir:"auto",...r})},xc=A.memo(function({text:r,onOpenFile:t,onOpenRun:n,resolveFilePath:s,resolveImageSrc:o,predict:a=!1}){Cu();const i=A.useContext(IU),c=o??i,_=A.useMemo(()=>function({node:p,src:m,alt:w,className:y,...v}){var b,S,C;const x=A.useMemo(()=>typeof m=="string"&&m?(c==null?void 0:c(m))??[{url:m,resolveAsset:()=>null}]:[],[m,c]),k=(b=x[0])==null?void 0:b.url;return k?c&&((S=py(m))!=null&&S.path.match(/\.html?$/i))?l.jsx(Pns,{candidates:x,name:w||m},k):A.createElement(qns,{...v,key:k,downloadName:(C=m.split(/[\\/]/).pop())==null?void 0:C.split(/[?#]/)[0],sources:x.map(N=>N.url),alt:w??"",loading:"lazy",className:`block max-w-full h-auto my-3 rounded-sm border border-border cursor-zoom-in focus-visible:outline-2 focus-visible:outline-focus ${y??""}`}):null},[c]),d=A.useMemo(()=>({"image-carousel":({children:f})=>l.jsx(Bns,{children:f}),"file-mention":f=>{const p=G3(f.path),m=f.lines&&nYn(f.lines)||p.line;return l.jsx(VM,{path:p.path,line:m,exp:f.exp,onOpenFile:t})},"run-mention":f=>l.jsx(Vns,{id:f.id,label:f.label,onOpenRun:n}),a:({node:f,href:p,children:m,"data-figure-src":w,"data-cited-href":y,...v})=>{const x=typeof w=="string"?py(w):null;if(x&&t){const S=x.source==="artifact"?`artifacts/${x.path}`:x.path,C=s?s(eYn(S)):S;if(C)return l.jsx("button",{type:"button",className:"file-link cursor-pointer text-start",...pn(N=>t(C,void 0,void 0,void 0,N)),children:m})}const k=typeof y=="string"?y:p,b=k?G3(k):null;if(b&&Xns(b.path)){const S=tYn(b.path,s);return S&&t?l.jsx(VM,{path:S,line:b.line,onOpenFile:t}):l.jsx("span",{children:m})}return p?l.jsx("a",{href:p,target:"_blank",rel:"noopener noreferrer",...v,children:m}):l.jsx("span",{children:m})},...Zns,img:_,...HU}),[t,n,s,_]);return l.jsx("div",{dir:"auto","data-streaming":a||void 0,className:"md min-w-0 wrap-anywhere text-text leading-relaxed [&_>_*:first-child]:mt-0 [&_>_*:last-child]:mb-0 [&_p]:my-2.5 [&_p]:mx-0 [&_strong]:text-text [&_strong]:font-semibold [&_pre]:bg-surface [&_pre]:border [&_pre]:border-border-muted [&_pre]:rounded-md [&_pre]:py-2 [&_pre]:px-3 [&_pre]:overflow-x-auto [&_pre]:text-sm [&_pre]:text-text [&_code]:font-mono [&_code]:text-sm [&_code]:font-normal [&_code]:text-text [&_code]:bg-surface [&_code]:border [&_code]:border-border-variant [&_code]:rounded-xs [&_code]:py-px [&_code]:px-1 [&_.katex]:text-prose-emphasis [&_.katex-display]:my-3 [&_.katex-display]:mx-0 [&_.katex-display]:overflow-x-auto [&_.katex-display]:overflow-y-hidden [&_.katex-display]:py-0.5 [&_.katex-display]:px-0 [&_.file-chip]:inline-flex [&_.file-chip]:items-center [&_.file-chip]:gap-1 [&_.file-chip]:max-w-full [&_.file-chip]:my-0 [&_.file-chip]:mx-px [&_.file-chip]:py-0 [&_.file-chip]:px-1.5 [&_.file-chip]:align-baseline [&_.file-chip]:font-mono [&_.file-chip]:text-sm [&_.file-chip]:font-medium [&_.file-chip]:text-text [&_.file-chip]:bg-panel [&_.file-chip]:border [&_.file-chip]:border-border-variant [&_.file-chip]:rounded-xs [&_.file-chip]:cursor-pointer [&_.file-chip:hover:not(:disabled)]:bg-surface [&_.file-chip_svg]:flex-none [&_.file-chip_svg]:opacity-60 [&_.file-chip-label]:min-w-0 [&_.file-chip-label]:overflow-hidden [&_.file-chip-label]:text-ellipsis [&_.file-chip-label]:whitespace-nowrap [&_.run-chip_svg]:opacity-100 [&_.run-chip_svg]:text-subtext [&_pre_code]:bg-none [&_pre_code]:bg-transparent [&_pre_code]:border-0 [&_pre_code]:text-inherit [&_pre_code]:p-0 [&_pre_code]:font-normal [&_h1]:text-text [&_h1]:text-prose-emphasis [&_h1]:font-semibold [&_h1]:mt-3 [&_h1]:mx-0 [&_h1]:mb-1.5 [&_h2]:text-text [&_h2]:text-prose-emphasis [&_h2]:font-semibold [&_h2]:mt-3 [&_h2]:mx-0 [&_h2]:mb-1.5 [&_h3]:text-text [&_h3]:text-prose-emphasis [&_h3]:font-semibold [&_h3]:mt-3 [&_h3]:mx-0 [&_h3]:mb-1.5 [&_h4]:text-text [&_h4]:text-prose-emphasis [&_h4]:font-semibold [&_h4]:mt-3 [&_h4]:mx-0 [&_h4]:mb-1.5 [&_ul]:my-1.5 [&_ul]:mx-0 [&_ul]:ps-5.5 [&_ol]:my-1.5 [&_ol]:mx-0 [&_ol]:ps-5.5 [&_li::marker]:text-text [&_table]:border-collapse [&_table]:block [&_table]:w-max [&_table]:max-w-full [&_table]:text-sm [&_table]:my-2.5 [&_table]:mx-0 [&_table]:border [&_table]:border-border [&_table]:rounded-md [&_table]:overflow-x-auto [&_th]:border-b [&_th]:border-b-border-variant [&_th]:py-2 [&_th]:px-3.5 [&_th]:text-start [&_th]:text-text [&_th]:break-normal [&_th]:break-words [&_td]:border-b [&_td]:border-b-border-variant [&_td]:py-2 [&_td]:px-3.5 [&_td]:text-start [&_td]:text-text [&_td]:break-normal [&_td]:break-words [&_tr:last-child_td]:border-b-0 [&_thead_th]:bg-surface [&_thead_th]:font-medium [&_thead_th]:text-text [&_thead_th]:border-b [&_thead_th]:border-b-border [&_tbody_tr:hover_td]:bg-surface [&_blockquote]:my-1.5 [&_blockquote]:mx-0 [&_blockquote]:pt-0.5 [&_blockquote]:pe-0 [&_blockquote]:pb-0.5 [&_blockquote]:ps-2.5 [&_blockquote]:border-s-[3px] [&_blockquote]:border-s-border [&_blockquote]:text-subtext [:is(&,_.openresearch-diff,_.file-view)_.token.comment]:italic [:is(&,_.openresearch-diff,_.file-view)_.token.prolog]:italic [:is(&,_.openresearch-diff,_.file-view)_.token.cdata]:italic [:is(&,_.openresearch-diff,_.file-view)_.token.operator]:text-syntax-cyan [:is(&,_.openresearch-diff,_.file-view)_.token.entity]:text-syntax-cyan [:is(&,_.openresearch-diff,_.file-view)_.token.url]:text-syntax-cyan [:is(&,_.openresearch-diff,_.file-view)_.token.comment]:text-syntax-comment [:is(&,_.openresearch-diff,_.file-view)_.token.prolog]:text-syntax-comment [:is(&,_.openresearch-diff,_.file-view)_.token.cdata]:text-syntax-comment [:is(&,_.openresearch-diff,_.file-view)_.token.punctuation]:text-syntax-text [:is(&,_.openresearch-diff,_.file-view)_.token.property]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.tag]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.deleted]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.constant]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.symbol]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.boolean]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.number]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.selector]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.attr-name]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.char]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.inserted]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.string]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.builtin]:text-syntax-yellow [:is(&,_.openresearch-diff,_.file-view)_.token.atrule]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.attr-value]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.keyword]:text-syntax-purple [:is(&,_.openresearch-diff,_.file-view)_.token.function]:text-syntax-blue [:is(&,_.openresearch-diff,_.file-view)_.token.decorator]:text-syntax-blue [:is(&,_.openresearch-diff,_.file-view)_.token.def]:text-syntax-blue [:is(&,_.openresearch-diff,_.file-view)_.token.class-name]:text-syntax-yellow [:is(&,_.openresearch-diff,_.file-view)_.token.namespace]:text-syntax-yellow [:is(&,_.openresearch-diff,_.file-view)_.token.regex]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.important]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.variable]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.parameter]:text-syntax-text",children:l.jsx(MZn,{content:LU(r,{predictMath:a}),processor:Qns,components:d,predict:a})})}),QM="prompt-actions plan-strip-actions flex flex-wrap justify-end gap-x-2 gap-y-1.5";function Jns({synthesized:e,agentLabel:r,onView:t,onApprove:n,showResumeModes:s,onReject:o,onRevise:a}){const[i,c]=A.useState(!1),_=A.useRef(null),[d,f]=A.useState(!1),[p,m]=A.useState(""),w=A.useRef(null);A.useEffect(()=>{if(!i)return;const v=x=>{_.current&&!_.current.contains(x.target)&&c(!1)};return window.addEventListener("pointerdown",v),()=>window.removeEventListener("pointerdown",v)},[i]),A.useEffect(()=>{var v;d&&((v=w.current)==null||v.focus())},[d]);const y=()=>{a(p.trim()||"no specific feedback — use your judgment"),m(""),f(!1)};return l.jsxs("div",{className:"plan-strip relative w-full mt-0 mx-0 mb-2.5 py-3 px-3.5 flex flex-col items-stretch gap-2.5 border border-accent-blue-border rounded-lg bg-accent-blue-subtle",children:[l.jsxs("div",{className:"plan-strip-info flex items-baseline gap-2 min-w-0",children:[l.jsx(ux,{size:14,className:"plan-strip-icon text-accent-blue shrink-0 self-center"}),l.jsx("span",{dir:"auto",className:"plan-strip-title text-sm font-semibold whitespace-nowrap",children:e?Zdr({agent:Ae(r)}):Hdr({agent:Ae(r)})}),l.jsx("button",{className:"plan-strip-open ms-auto p-0 border-0 bg-none bg-transparent text-accent-blue text-sm cursor-pointer whitespace-nowrap shrink-0 [&:hover]:underline",...pn(t),children:zhr()})]}),d?l.jsxs(l.Fragment,{children:[l.jsx("textarea",{dir:"auto",writingsuggestions:"false",ref:w,className:"plan-strip-revise-input w-full resize-none border border-border rounded-md py-2 px-3 text-sm font-[inherit] bg-background text-text [&:focus]:border-focus-border",placeholder:dpr(),rows:2,value:p,onChange:v=>m(v.target.value),onKeyDown:v=>{if(v.nativeEvent.isComposing||v.nativeEvent.keyCode===229){v.stopPropagation();return}v.key==="Escape"?(v.preventDefault(),m(""),f(!1)):v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),y())}}),l.jsxs("div",{className:QM,children:[l.jsx(Se,{size:"small",onClick:()=>{m(""),f(!1)},children:tI()}),l.jsx("span",{className:"plan-strip-spacer flex-1"}),l.jsxs(Se,{size:"small",variant:"primary",onClick:y,children:[Khr(),l.jsx(XP,{size:14})]})]})]}):l.jsxs("div",{className:QM,children:[l.jsx(Se,{size:"small",onClick:o,children:Dhr()}),l.jsx(Se,{size:"small",onClick:()=>f(!0),children:npr()}),l.jsx("span",{className:"plan-strip-spacer flex-1"}),s?l.jsxs("div",{className:"plan-strip-approve relative flex",ref:_,children:[l.jsx(Se,{size:"small",variant:"primary",className:"rounded-e-none",onClick:()=>n("auto"),children:fdr()}),l.jsx(Se,{size:"small",variant:"primary",className:"rounded-s-none border-s-plan-caret px-1.5","aria-label":ghr(),onClick:()=>c(v=>!v),children:l.jsx(kc,{size:14})}),i&&l.jsx("div",{className:"plan-strip-menu absolute end-0 bottom-[calc(100%_+_4px)] flex min-w-47.5 flex-col rounded-md border border-border bg-background p-1 shadow-menu z-6",children:l.jsx(cr,{onClick:()=>{c(!1),n("bypassPermissions")},children:wdr()})})]}):l.jsx(Se,{size:"small",variant:"primary",onClick:()=>n(),children:Rdr()})]})]})}const XM="mb-2.5 rounded-lg border border-border bg-accent-green-subtle px-3 py-2.5 text-sm text-text";function YM({item:e,onOpenRun:r,className:t=""}){const{run:n,experimentName:s}=e;return r?l.jsx("button",{className:`tool-target experiment-run-link ${t}`,...pn(o=>r(n.id,o)),children:s||n.experimentId}):l.jsx("span",{className:t,children:s||n.experimentId})}function ess({runs:e,onOpenRun:r}){const t=e[0];return t?e.length===1?l.jsxs("div",{role:"status",className:`${XM} flex items-center gap-2`,children:[l.jsx(H_,{size:16,className:"shrink-0 text-accent-green","aria-hidden":"true"}),l.jsx("span",{className:"shrink-0 font-medium",children:t.run.cancelRequested?i8e():t.run.status==="starting"?C8e():E5()}),l.jsx("span",{"aria-hidden":"true",children:"·"}),l.jsx(YM,{item:t,onOpenRun:r,className:"min-w-0 truncate"})]}):l.jsxs("details",{className:`${XM} [&[open]_.experiment-chevron]:rotate-90`,children:[l.jsxs("summary",{className:"flex cursor-pointer list-none items-center gap-2 rounded-sm focus-visible:outline-2 focus-visible:outline-focus [&::-webkit-details-marker]:hidden",children:[l.jsx(H_,{size:16,className:"shrink-0 text-accent-green","aria-hidden":"true"}),l.jsx("span",{className:"font-medium",children:W8e({count:e.length})}),l.jsx(mo,{size:14,className:"experiment-chevron ms-auto shrink-0 text-subtext","aria-hidden":"true"})]}),l.jsx("div",{className:"mt-2 max-h-48 overflow-y-auto ps-6 leading-relaxed",children:e.map((n,s)=>l.jsxs("span",{children:[s>0&&l.jsx("span",{className:"text-subtext",children:" · "}),l.jsx(YM,{item:n,onOpenRun:r})]},n.run.id))})]}):null}function ZM({save:e,onSaved:r,placeholder:t,createHref:n,createLabel:s}){const[o,a]=A.useState(""),[i,c]=A.useState(!1),[_,d]=A.useState(null);async function f(p){if(p.preventDefault(),!(i||!o.trim())){c(!0),d(null);try{r(await e(o.trim())),a("")}catch(m){d(m instanceof Error?m.message:String(m))}finally{c(!1)}}}return l.jsxs("form",{className:"onb-token-form flex items-center flex-wrap gap-2 mt-2 [&_input]:flex-1 [&_input]:min-w-55 [&_input]:text-sm [&_a]:text-sm [&_a]:text-subtext [&_a]:whitespace-nowrap [&_.error]:basis-full [&_.error]:text-accent-red [&_.error]:text-sm [&_.error]:whitespace-pre-wrap",onSubmit:f,children:[l.jsx("input",{type:"password",value:o,onChange:p=>a(p.target.value),placeholder:t,autoComplete:"off"}),l.jsx(Se,{type:"submit",disabled:i||!o.trim(),children:i?Pi():Ii()}),l.jsx("a",{href:n,target:"_blank",rel:"noreferrer",children:s??s6t()}),_&&l.jsx("div",{className:"error",children:_})]})}function qU({value:e,max:r,label:t,caption:n,fillColor:s}){const o=r>0?Math.min(100,Math.round(e/r*100)):0;return l.jsxs("div",{className:"progress mt-3 mx-0 mb-1",role:"progressbar","aria-valuenow":o,"aria-valuemin":0,"aria-valuemax":100,children:[l.jsx("div",{className:"progress-track h-2 rounded-full bg-panel border border-border overflow-hidden",children:l.jsx("div",{className:"progress-fill h-full bg-subtext rounded-full transition-[width] duration-200 ease-standard",style:{width:`${o}%`,background:s}})}),(t!==void 0||n!==void 0)&&l.jsxs("div",{className:"progress-caption flex justify-between mt-1.5 text-sm text-muted",children:[l.jsx("span",{children:t??`${o}%`}),n]})]})}function tss({settings:e}){const[r,t]=A.useState(!1);return l.jsxs("label",{className:"inline-flex max-w-full flex-wrap items-center gap-2 text-sm text-subtext",children:[Exn(),l.jsx("span",{className:"inline-block w-max max-w-full",children:l.jsx(ea,{variant:"field",dropDown:!0,value:e.defaultHost??"",disabled:r,choices:[{id:"",label:pI()},...e.defaultHost&&!e.hosts.some(n=>n.host===e.defaultHost)?[{id:e.defaultHost,label:e.defaultHost}]:[],...e.hosts.map(n=>({id:n.host,label:n.host}))],onSelect:n=>{t(!0),gOn(n||null).catch(s=>{Kt(s instanceof Error?s.message:String(s),"error")}).finally(()=>t(!1))}})})]})}function rss({host:e,connecting:r,reference:t,onChange:n}){const s=A.useId(),o=pr({mutationFn:mOn,scope:{id:`ssh-settings-${e.host}`}});function a(i){n(i),o.reset(),!(i!==null&&!i.trim())&&o.mutate({host:e.host,container:(i==null?void 0:i.trim())??null})}return l.jsxs("details",{className:"pb-3",children:[l.jsx("summary",{className:"w-fit cursor-pointer rounded-sm text-sm text-subtext focus-visible:outline-2 focus-visible:outline-focus",children:GD()}),l.jsxs("div",{className:"mt-3 grid max-w-xl gap-3",children:[l.jsxs("label",{className:"text-sm text-subtext",children:[s2n(),l.jsx(ea,{variant:"field",dropDown:!0,value:t!==null?"container":"host",disabled:r,choices:[{id:"host",label:Ixn()},{id:"container",label:Vxn()}],onSelect:i=>a(i==="container"?"":null)})]}),t!==null&&l.jsxs("label",{className:"text-sm text-subtext",htmlFor:`${s}-container`,children:[vxn(),l.jsx(yn,{id:`${s}-container`,value:t,disabled:r,required:!0,onChange:i=>a(i.target.value)})]}),o.error&&l.jsx("p",{className:"m-0 text-sm text-accent-red",role:"status",children:o.error.message})]})]})}const Di=["settings-card [&_>_.error]:text-accent-red [&_>_.error]:text-base","[&_>_.error]:whitespace-pre-wrap bg-background border border-border","rounded-lg py-4 px-4.5 mb-4 [&_h3]:mt-0 [&_h3]:mx-0 [&_h3]:mb-2.5","[&_h3]:text-base [&_h3]:font-semibold [&_h3]:text-text","[&_.settings-sub]:mb-3 [&_.kv]:gap-y-1.5 [&_.kv]:gap-x-4.5","[&_>_.project-default-row:first-child]:pt-0 [&_>_.project-default-row:first-child]:border-t-0"].join(" "),t2=["kv grid grid-cols-[auto_1fr] items-baseline gap-y-1 gap-x-3.5 text-base","[&_.k]:text-sm [&_.k]:text-subtext [&_.v]:text-base [&_.v]:text-text","[&_.v]:break-all"].join(" "),nss=["grid grid-cols-[9rem_minmax(0,1fr)] items-center gap-x-5 gap-y-2.5 font-sans text-base text-text","[&_.k]:font-medium [&_.k]:text-sm [&_.k]:text-text","[&_.v]:min-w-0 [&_.v]:flex [&_.v]:items-center [&_.v]:flex-wrap [&_.v]:gap-2","[&_.v]:font-sans [&_.v]:text-base [&_.v]:text-text [&_.v]:break-words"].join(" "),Z0="mt-3 mx-0 mb-0 ps-3 border-s-2 border-s-accent-red font-sans text-base leading-relaxed text-text whitespace-pre-wrap",Sa=["settings-note mt-2.5 mx-0 mb-0 text-base py-2 px-2.5","border border-accent-amber rounded-md bg-accent-amber-subtle","text-accent-amber font-medium"].join(" "),qC=["form font-sans text-sm text-text [&_.form-seg]:self-start [&_.form-seg]:mb-0.5","[&_.form-seg_button]:py-[5px] [&_.form-seg_button]:px-3","[&_.repo-hint]:font-normal [&_.repo-hint]:text-sm","[&_.repo-hint]:text-muted [&_.repo-hint.ok]:text-accent-teal","[&_.folder-picker-control]:flex [&_.folder-picker-control]:items-center","[&_.folder-picker-control]:gap-2 [&_.folder-picker-control]:w-full","[&_.folder-picker-control]:min-w-0 [&_.folder-picker-control]:py-2 [&_.folder-picker-control]:px-2.5","[&_.folder-picker-control]:overflow-hidden [&_.folder-picker-control]:bg-background","[&_.folder-picker-control]:border [&_.folder-picker-control]:border-border","[&_.folder-picker-control]:rounded-md [&_.folder-picker-control]:cursor-pointer","[&_.folder-picker-control]:text-start","[&_.folder-picker-control]:transition-[border-color,box-shadow] [&_.folder-picker-control]:duration-120 [&_.folder-picker-control]:ease-standard","[&_.folder-picker-control:hover:not(:disabled)]:border-muted","[&_.folder-picker-control:hover:not(:disabled)]:shadow-control-subtle","[&_.folder-picker-control:focus-visible]:outline-2 [&_.folder-picker-control:focus-visible]:outline-solid [&_.folder-picker-control:focus-visible]:outline-focus","[&_.folder-picker-control:focus-visible]:outline-offset-2 [&_.folder-picker-control_span]:flex-1","[&_.folder-picker-control_span]:min-w-0 [&_.folder-picker-control_span]:overflow-hidden","[&_.folder-picker-control_span]:text-ellipsis [&_.folder-picker-control_span]:whitespace-nowrap","[&_.folder-picker-control_.placeholder]:text-muted [&_.folder-picker-icon]:flex-none","[&_.folder-picker-icon]:text-current [&_.folder-picker-chevron]:flex-none","[&_.folder-picker-chevron]:text-muted","[&_.folder-picker-control:hover:not(:disabled)_.folder-picker-chevron]:text-subtext","[&_.folder-picker-hint]:text-subtext [&_.folder-picker-hint]:text-sm","[&_.folder-picker-hint]:font-normal [&_.folder-picker-hint]:leading-snug","[&_.project-location-field]:flex [&_.project-location-field]:flex-col","[&_.project-location-field]:gap-2 [&_.project-location-label]:text-text","[&_.project-location-label]:text-base","[&_.project-location-label]:font-medium [&_.project-field-label]:text-text","[&_.project-field-label]:text-base [&_.project-field-label]:font-medium","[&_.folder-picker-control:disabled]:cursor-default [&_.folder-picker-control:disabled]:opacity-65","[&_.paper-destination]:flex [&_.paper-destination]:items-center","[&_.paper-destination]:gap-2.5 [&_.paper-destination]:pt-2 [&_.paper-destination]:pe-2 [&_.paper-destination]:pb-2 [&_.paper-destination]:ps-3","[&_.paper-destination]:border [&_.paper-destination]:border-border [&_.paper-destination]:rounded-md","[&_.paper-destination]:bg-background [&_.paper-destination_code]:flex-1","[&_.paper-destination_code]:min-w-0 [&_.paper-destination_code]:overflow-hidden","[&_.paper-destination_code]:text-text [&_.paper-destination_code]:text-sm","[&_.paper-destination_code]:font-normal","[&_.paper-destination_code]:text-ellipsis [&_.paper-destination_code]:whitespace-nowrap","[&_.paper-destination_.btn]:flex-none [&_.project-path-notice]:py-2 [&_.project-path-notice]:px-3","[&_.project-path-notice]:border [&_.project-path-notice]:border-border-variant","[&_.project-path-notice]:rounded-sm [&_.project-path-notice]:bg-surface","[&_.project-path-notice]:text-base [&_.project-path-notice]:text-text","[&_.project-path-notice]:leading-snug","[&_.project-path-notice.error]:border-danger-notice-border","[&_.paper-results]:flex [&_.paper-results]:flex-col","[&_.paper-results]:border [&_.paper-results]:border-border [&_.paper-results]:rounded-md","[&_.paper-results]:max-h-60 [&_.paper-results]:overflow-y-auto","[&_.paper-results_button]:flex [&_.paper-results_button]:flex-col","[&_.paper-results_button]:items-start [&_.paper-results_button]:gap-0.5","[&_.paper-results_button]:py-2 [&_.paper-results_button]:px-2.5 [&_.paper-results_button]:bg-none [&_.paper-results_button]:bg-transparent","[&_.paper-results_button]:border-0","[&_.paper-results_button]:border-b [&_.paper-results_button]:border-b-border-variant","[&_.paper-results_button]:text-start [&_.paper-results_button]:[font:inherit]","[&_.paper-results_button]:text-text [&_.paper-results_button]:cursor-pointer","[&_.paper-results_button:last-child]:border-b-0","[&_.paper-results_button:hover]:bg-surface [&_.paper-results_.title]:text-sm","[&_.paper-results_.title]:font-medium","[&_.paper-results_.id]:text-xs [&_.paper-results_.id]:text-muted","[&_.paper-pick_.id]:text-xs","[&_.paper-pick_.id]:text-muted [&_.paper-pick]:flex [&_.paper-pick]:items-center","[&_.paper-pick]:justify-between [&_.paper-pick]:gap-2.5 [&_.paper-pick]:py-2.5 [&_.paper-pick]:px-3","[&_.paper-pick]:border [&_.paper-pick]:border-border [&_.paper-pick]:rounded-md","[&_.paper-pick]:bg-surface [&_.paper-pick_.meta]:min-w-0","[&_.paper-pick_.title]:text-sm [&_.paper-pick_.title]:font-medium","flex flex-col gap-2.5 [&_label]:flex [&_label]:flex-col","[&_label]:gap-1 [&_label]:text-sm [&_label]:text-text","[&_label]:font-medium [&_.row2]:grid [&_.row2]:grid-cols-2","[&_input]:font-sans [&_input]:text-sm [&_input]:font-normal [&_input]:text-text [&_input::placeholder]:text-subtext","[&_select]:font-sans [&_select]:text-sm [&_select]:font-normal [&_select]:text-text","[&_.row2]:gap-2.5 [&_.actions]:flex [&_.actions]:justify-end","[&_.actions]:gap-2.5 [&_.actions]:mt-1.5 [&_.new-project-actions]:justify-start","[&_.new-project-actions]:mt-2.5","[&_.error]:text-accent-red [&_.error]:text-base [&_.error]:whitespace-pre-wrap","settings-form mt-3.5 pt-3.5 border-t border-t-border"].join(" "),R_=["project-default-row flex items-center justify-between gap-6 [.project-default-row+&]:mt-3.5","pt-3.5 border-t border-t-border-variant [&_p]:mt-1 [&_p]:mx-0 [&_p]:mb-0","[&_.project-default-title]:text-base [&_p]:text-sm [&_p]:leading-relaxed [&_p]:text-text"].join(" "),Tf=["settings-stack-section [&_+_.settings-stack-section]:mt-6 [&_>_:last-child]:mb-0","[&_>_h2]:mt-0 [&_>_h2]:mx-0 [&_>_h2]:mb-1.5 [&_>_h2]:text-xl"].join(" "),sss=new Set(["gh auth login","hf auth login","claude auth status"]);function UU(e){return sss.has(e)?`/api/settings/commands/run?command=${encodeURIComponent(e)}`:void 0}function UC(){const[e,r]=A.useState(null);return{run:e,start:(n,s,o)=>r(a=>({command:n,path:s,owner:o,attempt:((a==null?void 0:a.attempt)??0)+1})),clear:()=>r(null)}}function GC({note:e,className:r,disabled:t,resolve:n=UU,onRun:s}){return e?l.jsx("p",{className:r,children:U_(e,{canRun:o=>!t&&n(o)!==void 0,onRun:o=>{const a=n(o);a&&s(o,a)}})}):null}function WC({run:e,onComplete:r,onClose:t}){return e?l.jsx(dB,{path:e.path,label:e.command,onComplete:r,onError:n=>Kt(n,"error"),onClose:t},`${e.command}-${e.attempt}`):null}function Lv(e){return e.catalogPending?{cls:"warn",variant:"warning",label:dd()}:e.authCheckFailed?{cls:"warn",variant:"warning",label:Wb()}:e.id.startsWith("acp:")&&e.authState==="needsLogin"?{cls:"warn",variant:"warning",label:uD()}:e.id.startsWith("acp:")&&e.authState==="ready"?{cls:"ok",variant:"success",label:_D()}:e.agentReady&&!e.authenticated&&e.authMethod!=="local"?{cls:"warn",variant:"warning",label:WD()}:e.agentReady?{cls:"ok",variant:"success",label:e.authMethod==="thirdParty"||H0(e)?D0():e.authMethod==="local"?AS():WJr()}:e.installed?e.installBroken?{cls:"warn",variant:"warning",label:$Hr()}:e.authMethod==="local"?{cls:"warn",variant:"warning",label:KD()}:e.needsConfigRepair||e.authState==="unknown"?{cls:"warn",variant:"warning",label:Wb()}:e.authState==="unsupported"?{cls:"warn",variant:"warning",label:Brn()}:{cls:"warn",variant:"warning",label:mI()}:{cls:"warn",variant:"warning",label:DVr()}}function oss({h:e}){if(e.id==="opencode"&&e.agentReady&&!e.authenticated&&!e.authMethod)return l.jsx(l.Fragment,{children:o8r()});const r=H0(e);return r?l.jsx(l.Fragment,{children:r}):e.authMethod?e.authMethod==="local"?l.jsx(l.Fragment,{children:P5()}):e.authMethod==="thirdParty"?l.jsx(l.Fragment,{children:kI()}):l.jsx(l.Fragment,{children:e.authMethod==="oauth"?$Mr():Jy()}):l.jsx(l.Fragment,{children:"—"})}function GU(e,r,t){if(!r)return;const n=r.installUrl!==void 0&&t.includes(r.installUrl),s=t===r.login?"login":t===r.install?"install":t===r.update?"update":n?"install":null;if(s&&!(s!=="install"&&(!e.installed||e.installBroken)))return`/api/harnesses/setup?${new URLSearchParams({harness:e.id,action:s,shell:"true"})}`}function ass({remote:e}){var N,T;const r=hl(),{data:t=null}=nt(r),[n,s]=A.useState(null),[o,a]=A.useState(!1),i=UC(),[c,_]=A.useState(null),[d,f]=A.useState(null),p=nt(HS()),m=nt({queryKey:kt("getAcpHarnesses"),queryFn:o$n}),[w,y]=A.useState(null),v=()=>{m.refetch(),k(!0)},x=async E=>{try{await c$n(E),v()}catch(R){Kt(R instanceof Error?R.message:String(R),"error")}},k=(E,R=!1)=>{a(!0),I_(E,R).catch(()=>{}).finally(()=>a(!1))},b=[...t??[]].sort((E,R)=>Number(R.agentReady)-Number(E.agentReady)),S=b.find(E=>E.id===n)??b[0],C=(N=m.data)==null?void 0:N.find(E=>E.id===(S==null?void 0:S.id));return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:H5()}),w&&l.jsx(IB,{definition:w==="new"?void 0:w,onClose:()=>y(null),onSaved:v}),d&&l.jsx(NB,{remote:e,harness:d,onClose:()=>f(null)}),!e&&c&&p.data&&l.jsx(PB,{harness:c,commands:p.data[c.id],onClose:()=>_(null)}),l.jsxs("div",{className:"mt-3 mb-3.5 flex w-full flex-wrap items-center justify-between gap-3 [&_.option-menu]:w-max",children:[l.jsx("div",{className:"w-96 max-w-full",children:l.jsx(ea,{variant:"field",dropDown:!0,title:H5(),choices:b.map(E=>({id:E.id,label:E.name})),value:(S==null?void 0:S.id)??null,onSelect:E=>{const R=b.find($=>$.id===E);R&&s(R.id)},renderIcon:E=>{const R=b.find($=>$.id===E.id);return R&&l.jsx(gd,{harness:R.id,logo:R.logo})},renderLabel:E=>{const R=b.find(L=>L.id===E.id),$=R&&Lv(R);return l.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[E.label,$&&l.jsxs(l.Fragment,{children:[l.jsx("span",{"aria-hidden":"true",className:`size-1.5 shrink-0 rounded-full bg-muted [&.ok]:bg-accent-green [&.err]:bg-accent-red [&.warn]:bg-accent-amber ${$.cls}`}),l.jsx("span",{className:"sr-only",children:$.label})]})]})}})}),l.jsxs(Se,{className:"ms-auto shrink-0",onClick:()=>y("new"),"aria-haspopup":"dialog",children:[l.jsx(Bi,{size:14}),gS()]})]}),t?S?l.jsxs("div",{className:Di,children:[l.jsxs("div",{className:"settings-card-head flex items-center gap-2.5 mb-3",children:[S.id.startsWith("acp:")&&l.jsx("span",{className:"text-sm text-subtext",children:pD()}),l.jsx(tr,{variant:Lv(S).variant,children:S.adapterMissing?lD():Lv(S).label}),l.jsx("div",{className:"spacer flex-1"}),!e&&S.adapterMissing&&l.jsxs(Se,{size:"small",onClick:()=>_(S),disabled:!((T=p.data)!=null&&T[S.id]),"aria-haspopup":"dialog",children:[l.jsx(q_,{size:14}),Bb()]}),S.id.startsWith("acp:")&&!S.adapterMissing&&!S.agentReady&&!S.catalogPending&&l.jsx(Se,{size:"small",onClick:()=>f(S),"aria-haspopup":"dialog",children:Lv(S).label}),C&&l.jsxs(l.Fragment,{children:[l.jsx(Se,{size:"small",onClick:()=>y(C),children:vS()}),l.jsx(Se,{size:"small",onClick:()=>void x(C.id),children:kD()})]}),!S.id.startsWith("acp:")&&!e&&!S.catalogPending&&S.installed&&!S.installBroken&&!S.authenticated&&!S.needsConfigRepair&&(S.id==="claude-code"?S.loginEligible:S.authMethod!=="local"&&S.authMethod!=="apiKey"&&S.authState!=="unsupported")&&l.jsxs(Se,{size:"small",onClick:()=>_(S),disabled:!p.data,"aria-haspopup":"dialog",children:[l.jsx(q_,{size:14})," ",CS()]}),l.jsxs(Se,{size:"small",onClick:()=>k(!0,!0),disabled:o,children:[l.jsx(Fi,{size:12,className:o?"animate-[spin_0.9s_linear_infinite]":""})," ",I0()]})]}),l.jsxs("div",{className:Ln(t2,"[&_.v]:text-sm"),children:[l.jsx("span",{className:"k",children:C?fD():yLr()}),l.jsx("span",{className:"v",children:C?g3(C.executable,C.arguments):S.binPath??aMr()}),l.jsx("span",{className:"k",children:wI()}),l.jsx("span",{className:"v",children:S.version??"—"}),(S.authMethod==="apiKey"||S.authMethod==="thirdParty"||S.authMethod==="local"||H0(S))&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"k",children:$$r()}),l.jsx("span",{className:"v",children:l.jsx(oss,{h:S})})]}),S.account&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"k",children:S.id==="opencode"?kI():MS()}),l.jsx("span",{className:"v",children:S.account})]}),S.org&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"k",children:pXr()}),l.jsx("span",{className:"v",children:S.org})]}),l.jsx("span",{className:"k",children:m$r()}),l.jsx("span",{className:"v",children:S.catalogPending?dd():S.models.length>0?jTr({count:fr(S.models.length)}):S.agentReady?_g():BRr()})]}),C?S.agentNote||!S.agentReady?l.jsx("p",{className:Ln(Sa,"text-sm"),children:S.agentNote??hD()}):null:l.jsx(GC,{note:S.agentNote,className:Ln(Sa,"text-sm"),disabled:e,resolve:E=>{var R;return GU(S,(R=p.data)==null?void 0:R[S.id],E)??UU(E)},onRun:(E,R)=>i.start(E,R,S.id)}),!S.installed&&S.needsConnectionAdapter&&l.jsx("p",{className:Ln(Sa,"text-sm"),children:cD({name:S.name})}),i.run&&l.jsx("div",{hidden:i.run.owner!==S.id,children:l.jsx(WC,{run:i.run,onComplete:()=>k(!0,!0),onClose:i.clear})}),S.id==="opencode"&&l.jsx($B,{installed:S.installed})]}):null:l.jsxs(ys,{children:[l.jsx($t,{})," ",EBr()]})]})}function iss({s:e}){const r=e.preflight;return r.kubectlFound?r.reachable?r.canCreateJobs?l.jsx(tr,{variant:"success",children:uI()}):l.jsx(tr,{variant:"error",children:dKr()}):l.jsx(tr,{variant:"error",children:JDr()}):l.jsx(tr,{variant:"error",children:Bqr()})}function css({onEditState:e}){var T;const r=pr({mutationFn:iOn}),t=dA(),n=nt(t),s=n.data??null,o=E=>{fs(t.queryKey,R=>(typeof E=="function"?E(R??null):E)??void 0)},a=s?null:((T=n.error)==null?void 0:T.message)??null,[i,c]=A.useState(""),[_,d]=A.useState(""),[f,p]=A.useState(!1),[m,w]=A.useState(!1),[y,v]=A.useState(null),x=E=>{o(E),c(E.context??""),d(E.namespace)},k=A.useRef(null);A.useEffect(()=>{const E=k.current;k.current=s,s&&(!E||i===(E.context??"")&&_.trim()===E.namespace)&&(c(s.context??""),d(s.namespace??""))},[s,i,_]);const b=s!==null&&i===(s.context??"")&&_.trim()===s.namespace,S=s!==null&&!b;A.useEffect(()=>{e==null||e({dirty:S,saving:f})},[S,f,e]);async function C(){if(!(m||f||!b)){w(!0);try{await Xe.fetchQuery({...dA(),staleTime:0})}catch(E){Kt(E instanceof Error?E.message:String(E),"error")}finally{w(!1)}}}async function N(E){if(E.preventDefault(),!(f||m)){p(!0),v(null);try{x(await r.mutateAsync({context:i,namespace:_.trim()}))}catch(R){v(R instanceof Error?R.message:String(R))}finally{p(!1)}}}return l.jsx(l.Fragment,{children:a?l.jsx("p",{className:"m-0 text-sm text-accent-red whitespace-pre-wrap break-words",children:a}):s?l.jsxs(l.Fragment,{children:[l.jsxs("dl",{className:"m-0 flex items-center justify-between gap-4 text-sm",children:[l.jsx("dt",{className:"text-subtext",children:Op()}),l.jsx("dd",{className:"m-0",children:m||f?l.jsx(tr,{children:Ea()}):S?l.jsx(tr,{children:$D()}):l.jsx(iss,{s})})]}),b&&!m&&!f&&s.preflight.error&&l.jsx("p",{className:`${Z0} break-words`,children:s.preflight.error}),l.jsxs("form",{className:"mt-5 flex flex-col gap-4",onSubmit:N,children:[l.jsxs("label",{className:"flex flex-col gap-2 text-sm font-medium text-subtext",children:[DIr(),l.jsx(ea,{choices:[{id:"",label:s.currentContext?HNr({context:Ae(s.currentContext)}):RNr()},...i&&!s.contexts.includes(i)?[{id:i,label:mMr({context:Ae(i)})}]:[],...s.contexts.map(E=>({id:E,label:E}))],value:i,variant:"field",dropDown:!0,disabled:f||m,onSelect:c})]}),l.jsxs("label",{className:"flex flex-col gap-2 text-sm font-medium text-subtext",children:[YGr(),l.jsx(yn,{type:"text",value:_,disabled:f||m,onChange:E=>d(E.target.value),placeholder:qPr(),autoComplete:"off",spellCheck:!1})]}),y&&l.jsx("p",{className:"m-0 text-sm text-accent-red whitespace-pre-wrap break-words",children:y}),l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsxs(Se,{type:"button",onClick:()=>void C(),disabled:f||m||!b,children:[l.jsx(Fi,{size:14})," ",m?Ea():$0()]}),l.jsx(Se,{variant:"primary",type:"submit",disabled:f||m||b,children:f?Pi():Ii()})]})]})]}):l.jsxs(ys,{children:[l.jsx($t,{})," ",oDr()]})})}function lss(){var b;const e=pr({mutationFn:S=>lOn(...S)}),r=hA(),t=nt(r),n=t.data??null,s=S=>{fs(r.queryKey,C=>(typeof S=="function"?S(C??null):S)??void 0)},[o,a]=A.useState(null),i=o??((b=t.error)==null?void 0:b.message)??null,[c,_]=A.useState(""),[d,f]=A.useState(""),[p,m]=A.useState(!1),w=t.isPending||p,[y,v]=A.useState(!1);async function x(){if(!(w||y)){m(!0),a(null);try{await Xe.fetchQuery({...hA(),staleTime:0})}catch(S){a(S instanceof Error?S.message:String(S))}finally{m(!1)}}}async function k(S){if(S.preventDefault(),!(!c.trim()||!d.trim()||w||y||n!=null&&n.processEnv)){v(!0),a(null);try{s(await e.mutateAsync([c.trim(),d.trim()])),_(""),f("")}catch(C){a(C instanceof Error?C.message:String(C))}finally{v(!1)}}}return l.jsxs(l.Fragment,{children:[!n&&w?l.jsxs(ys,{children:[l.jsx($t,{})," ",pDr()]}):n&&l.jsxs("dl",{className:"m-0 flex items-center justify-between gap-4 text-sm",children:[l.jsx("dt",{className:"font-medium text-subtext",children:Op()}),l.jsx("dd",{className:"m-0",children:l.jsx(tr,{variant:n.tokenConfigured?"success":"warning",children:n.tokenConfigured?D0():ex()})})]}),(n==null?void 0:n.processEnv)&&l.jsx("p",{className:"mt-2 mb-0 text-sm text-subtext",children:vAr()}),l.jsxs("form",{className:"mt-5 flex flex-col gap-4",onSubmit:k,children:[l.jsxs("label",{className:"flex flex-col gap-2 text-sm font-medium text-subtext",children:[n!=null&&n.tokenConfigured?EAr():sTr(),l.jsx(yn,{type:"password",value:c,onChange:S=>_(S.target.value),placeholder:(n==null?void 0:n.maskedTokenId)??"ak-…",autoComplete:"new-password",disabled:n==null?void 0:n.processEnv})]}),l.jsxs("label",{className:"flex flex-col gap-2 text-sm font-medium text-subtext",children:[n!=null&&n.tokenConfigured?IAr():hTr(),l.jsx(yn,{type:"password",value:d,onChange:S=>f(S.target.value),placeholder:(n==null?void 0:n.maskedTokenSecret)??"as-…",autoComplete:"new-password",disabled:n==null?void 0:n.processEnv})]}),l.jsx("a",{className:"self-start text-sm text-subtext underline",href:"https://modal.com/docs/sdk/py/latest/config",target:"_blank",rel:"noreferrer",children:VAr()}),i&&l.jsx("p",{className:"m-0 text-sm text-accent-red",children:i}),l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsxs(Se,{type:"button",disabled:w||y,onClick:()=>void x(),children:[l.jsx(Fi,{size:14})," ",I0()]}),l.jsx(Se,{variant:"primary",type:"submit",disabled:!c.trim()||!d.trim()||w||y||(n==null?void 0:n.processEnv),children:y?Pi():Ii()})]})]})]})}const WU="rounded-sm border-border-strong bg-surface text-subtext",KU="rounded-sm border-accent-blue bg-accent-blue-subtle text-accent-blue",uss=5e3;function VU(e){const r=li(),t=e.map(a=>pA(a)),n=gL({queries:t.map(a=>({...a,refetchInterval:uss}))});return[Object.fromEntries(e.flatMap((a,i)=>n[i].data?[[a,n[i].data.running]]:[])),a=>{Br(r)&&fs(pA(a).queryKey,{running:!0})}]}function _ss({test:e,connecting:r,masterRunning:t,containerFailed:n=!1}){if(r)return l.jsx("span",{role:"status",children:l.jsx(tr,{className:KU,children:RS()})});if(e===void 0)return l.jsx(tr,{className:WU,children:hI()});const s=e.missingTools??[],o=e.reachable&&e.toolsFound&&t===!1,a=!e.reachable||n?l.jsx(tr,{className:"rounded-sm",variant:"error",children:OS()}):e.toolsFound?o?l.jsx(tr,{className:"rounded-sm",variant:"warning",children:iI()}):l.jsx(tr,{className:"rounded-sm",variant:"success",children:L0()}):l.jsx(tr,{className:"rounded-sm",variant:"error",children:s.length===1?OTr({tool:Ae(s[0])}):UTr()});return l.jsxs("div",{className:"flex items-center gap-4",role:"status",children:[a,!o&&l.jsx("span",{className:"ssh-tested-at whitespace-nowrap text-xs text-subtext",children:$i(e.testedAt)})]})}function fss(){var $;const e=uP(),r=nt(e),t=(($=r.data)==null?void 0:$.hosts)??(r.isError?[]:null),[n,s]=A.useState(!1),[o,a]=A.useState({}),[i,c]=A.useState({}),_=A.useRef(0),[d,f]=A.useState(!1),[p,m]=A.useState({}),[w,y]=A.useState(null),[v,x]=A.useState(!1),[k,b]=A.useState(0),S=(t==null?void 0:t.filter(L=>{const I=o[L.host]??L.lastTest;return(I==null?void 0:I.reachable)&&I.toolsFound}).map(L=>L.host))??[],[C,N]=VU(S);function T(L){_.current+=1,f(!1),x(!1),b(I=>I+1),y(L),m(I=>({...I,[L]:!0}))}function E(){_.current+=1,f(!1),x(!1),y(null)}function R(L,I){m(P=>({...P,[L]:!I}))}return l.jsxs(l.Fragment,{children:[r.error&&l.jsx("p",{className:"text-sm text-accent-red",children:r.error.message}),l.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-3",children:[r.data&&l.jsx(tss,{settings:r.data}),l.jsxs(Se,{variant:"ghost",className:"ms-auto",onClick:()=>s(!0),children:[l.jsx(_x,{size:14})," ",TI()]})]}),t===null?l.jsxs(ys,{children:[l.jsx($t,{})," ",vI()]}):t.length===0?l.jsx("p",{className:"settings-empty mt-1 mx-0 mb-0 text-base text-subtext",children:nKr()}):l.jsx("div",{className:"border-y border-border-variant divide-y divide-border-variant",children:t.map(L=>{var W,ce,_e;const I=i[L.host]===void 0?L.container??null:i[L.host],P=o[L.host],B=I!==null&&((W=P==null?void 0:P.container)==null?void 0:W.reference)===I.trim()?P:void 0,K=I!==null?B:P!=null&&P.container?L.lastTest:P??L.lastTest,U=(ce=B==null?void 0:B.container)==null?void 0:ce.error,J=((_e=B==null?void 0:B.container)==null?void 0:_e.ready)===!1,te=(K==null?void 0:K.error)||U,F=w===L.host,D=p[L.host]??!1,q=F||!!te,Q=`${L.user?`${L.user}@`:""}${L.hostname??L.host}${L.port?`:${L.port}`:""}`;return l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-3 py-3",children:[l.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2.5",children:l.jsxs("div",{className:"min-w-0",children:[l.jsx("div",{className:"truncate text-base font-medium text-text",title:L.host,children:L.host}),l.jsx("div",{className:"mt-1 truncate text-sm text-subtext",title:Q,children:Q})]})}),l.jsxs("div",{className:"grid flex-none grid-cols-[8.5rem_5rem] items-center gap-x-12",children:[l.jsxs("div",{className:"flex items-center gap-2 text-start",children:[l.jsx(_ss,{test:K,connecting:F&&!v,masterRunning:C[L.host],containerFailed:J}),q&&l.jsx("button",{type:"button",className:"flex-none inline-flex items-center p-0.5 rounded-sm [&:hover]:bg-panel","aria-expanded":D,"aria-label":D?dJ({name:Ae(L.host)}):gee({name:Ae(L.host)}),onClick:ae=>{ae.stopPropagation(),R(L.host,D)},children:l.jsx(kc,{size:18,className:`text-muted transition-transform duration-120 ease-standard${D?" rotate-180":""}`})})]}),l.jsx(Se,{size:"small",type:"button",className:"justify-self-end",onClick:ae=>{ae.stopPropagation(),F&&!v?E():T(L.host)},disabled:!F&&(w!==null&&!v||I!==null&&!I.trim()),children:F?v?_s():xu():(K==null?void 0:K.reachable)===!1||J?_s():K?jI():bp()})]})]}),l.jsx(rss,{host:L,connecting:F&&!v,reference:I,onChange:ae=>{F&&E(),c(ee=>({...ee,[L.host]:ae})),a(ee=>{const G={...ee};return delete G[L.host],G})}}),q&&(D||F)&&l.jsxs("div",{className:`border-t border-t-border-variant py-3${D?"":" hidden"}`,children:[!F&&te&&l.jsx(pFn,{host:L.host,transcript:te}),F&&!d&&l.jsx(n6,{host:L.host,backend:"ssh",active:D,onComplete:ae=>{if(ae.backend!=="ssh")return;N(L.host);const ee=_.current;if(I===null){a(G=>({...G,[L.host]:{...ae.result,container:null}})),x(!1),y(null);return}f(!0),vOn(L.host,I.trim()).then(G=>{_.current===ee&&a(ne=>({...ne,[L.host]:{...G,container:G.container??{reference:I.trim(),ready:!1,error:G.error??null}}}))}).catch(G=>{_.current===ee&&a(ne=>({...ne,[L.host]:{...ae.result,container:{reference:I.trim(),ready:!1,error:G instanceof Error?G.message:String(G)}}}))}).finally(()=>{_.current===ee&&(f(!1),x(!1),y(null))})},onError:ae=>{x(!0),a(ee=>({...ee,[L.host]:{container:I===null?null:{reference:I.trim(),ready:!1,error:ae},reachable:!1,toolsFound:!1,missingTools:[],error:ae,testedAt:Date.now()}}))}},k)]})]},L.host)})}),n&&l.jsx(dF,{onClose:()=>s(!1)})]})}function dss({test:e,connecting:r,masterRunning:t}){return r?l.jsx(tr,{className:KU,children:RS()}):e===null?l.jsx(tr,{className:WU,children:hI()}):e.reachable?e.slurmFound?e.toolsFound?t===!1?l.jsx(tr,{className:"rounded-sm",variant:"warning",children:iI()}):l.jsx(tr,{className:"rounded-sm",variant:"success",children:L0()}):l.jsx(tr,{className:"rounded-sm",variant:"error",children:_Gr()}):l.jsx(tr,{className:"rounded-sm",variant:"error",children:JKr()}):l.jsx(tr,{className:"rounded-sm",variant:"error",children:OS()})}function hss(){var Q;const e=pr({mutationFn:NOn}),r=Q$n(),t=nt(r),n=t.data??null,s=W=>{fs(r.queryKey,ce=>(typeof W=="function"?W(ce??null):W)??void 0)},o=n?null:((Q=t.error)==null?void 0:Q.message)??null,[a,i]=A.useState(""),[c,_]=A.useState(""),[d,f]=A.useState(""),[p,m]=A.useState(""),[w,y]=A.useState(""),[v,x]=A.useState(""),[k,b]=A.useState(!1),[S,C]=A.useState(null),[N,T]=A.useState(null),[E,R]=A.useState(!1),[$,L]=A.useState(!1),[I,P]=A.useState(0),B=a&&(N!=null&&N.reachable)&&N.slurmFound&&N.toolsFound?[a]:[],[K,U]=VU(B);function J(){L(!1),P(W=>W+1),R(!0)}const te=W=>{s(W),i(W.host??""),_(W.partition??""),f(W.account??""),m(W.timeLimit??""),y(W.cpusPerTask===null?"":String(W.cpusPerTask)),x(W.mem??"")},F=A.useRef(null);A.useEffect(()=>{const W=F.current;F.current=n,n&&(!W||a===(W.host??"")&&c.trim()===(W.partition??"")&&d.trim()===(W.account??"")&&p.trim()===(W.timeLimit??"")&&w.trim()===(W.cpusPerTask===null?"":String(W.cpusPerTask))&&v.trim()===(W.mem??""))&&(i(n.host??""),_(n.partition??""),f(n.account??""),m(n.timeLimit??""),y(n.cpusPerTask===null?"":String(n.cpusPerTask)),x(n.mem??""))},[n,a,c,d,p,w,v]);const D=n!==null&&a===(n.host??"")&&c.trim()===(n.partition??"")&&d.trim()===(n.account??"")&&p.trim()===(n.timeLimit??"")&&w.trim()===(n.cpusPerTask===null?"":String(n.cpusPerTask))&&v.trim()===(n.mem??"");async function q(W){if(W.preventDefault(),!k){b(!0),C(null);try{te(await e.mutateAsync({host:a,partition:c.trim(),account:d.trim(),timeLimit:p.trim(),cpusPerTask:Number(w.trim())||0,mem:v.trim()}))}catch(ce){C(ce instanceof Error?ce.message:String(ce))}finally{b(!1)}}}return l.jsx(l.Fragment,{children:o?l.jsx("div",{className:"error",children:o}):n?l.jsxs(l.Fragment,{children:[!E&&(N==null?void 0:N.error)&&l.jsx("p",{className:Z0,children:N.error}),l.jsxs("form",{className:qC,onSubmit:q,children:[l.jsx("div",{className:"max-w-xl",children:l.jsxs("label",{children:[tGr(),l.jsx(ea,{choices:[{id:"",label:pI()},...a&&!n.hosts.some(W=>W.host===a)?[{id:a,label:`${a} (not in ~/.ssh/config)`}]:[],...n.hosts.map(W=>({id:W.host,label:W.host}))],value:a,variant:"field",dropDown:!0,disabled:k||E,onSelect:W=>{i(W),T(null),R(!1),L(!1)}})]})}),l.jsxs("div",{className:"actions",children:[l.jsx(Se,{type:"button",onClick:()=>{E&&!$?(L(!1),R(!1)):J()},disabled:!a,title:a?void 0:Jnn(),children:E?$?_s():xu():N?jI():bp()}),l.jsx("span",{role:"status",children:l.jsx(dss,{test:N,connecting:E&&!$,masterRunning:K[a]})})]}),l.jsxs("div",{className:"mt-5 border-t border-border pt-5",children:[l.jsxs("div",{className:"row2",children:[l.jsxs("label",{children:[bYr(),l.jsx(yn,{type:"text",list:"slurm-partitions",value:c,onChange:W=>_(W.target.value),placeholder:XN(),autoComplete:"off",spellCheck:!1}),l.jsx("datalist",{id:"slurm-partitions",children:N==null?void 0:N.partitions.map(W=>l.jsx("option",{value:W},W))})]}),l.jsxs("label",{children:[MS(),l.jsx(yn,{type:"text",value:d,onChange:W=>f(W.target.value),placeholder:XN(),autoComplete:"off",spellCheck:!1})]})]}),l.jsxs("label",{className:"mt-3 block max-w-xl",children:[frn(),l.jsx(yn,{type:"text",value:p,onChange:W=>m(W.target.value),placeholder:qDr(),autoComplete:"off",spellCheck:!1})]}),l.jsxs("div",{className:"row2 mt-3",children:[l.jsxs("label",{children:[tin(),l.jsx(yn,{type:"number",min:1,value:w,onChange:W=>y(W.target.value),placeholder:_in(),autoComplete:"off"})]}),l.jsxs("label",{children:[xin(),l.jsx(yn,{type:"text",value:v,onChange:W=>x(W.target.value),placeholder:Tin(),autoComplete:"off",spellCheck:!1})]})]})]}),S&&l.jsx("div",{className:"error",children:S}),l.jsx("div",{className:"actions",children:l.jsx(Se,{variant:"primary",type:"submit",disabled:k||D||E,children:k?Pi():Ii()})})]}),E&&l.jsx(n6,{host:a,backend:"slurm",onComplete:W=>{W.backend==="slurm"&&(T(W.result),U(a),L(!1),R(!1))},onError:W=>{L(!0),T({reachable:!1,slurmFound:!1,toolsFound:!1,partitions:[],error:W})}},I)]}):l.jsxs(ys,{children:[l.jsx($t,{})," ",SUr()]})})}function pss(){var S;const e=pr({mutationFn:TOn}),r=X$n(),t=nt(r),n=t.data??null,s=C=>{fs(r.queryKey,N=>(typeof C=="function"?C(N??null):C)??void 0)},o=n?null:((S=t.error)==null?void 0:S.message)??null,[a,i]=A.useState(""),[c,_]=A.useState(!1),[d,f]=A.useState(null),[p,m]=A.useState(null),w=p!==null&&p!=="testing"?p:null,y=C=>{s(C),i(C.address??"")},v=A.useRef(null);A.useEffect(()=>{const C=v.current;v.current=n,n&&(!C||a===(C.address??""))&&i(n.address??"")},[n,a]);const x=n!==null&&a===(n.address??"");async function k(C){if(C.preventDefault(),!c){_(!0),f(null);try{y(await e.mutateAsync({address:a}))}catch(N){f(N instanceof Error?N.message:String(N))}finally{_(!1)}}}async function b(){m("testing");try{m(await ROn(a.trim()||void 0))}catch(C){m({reachable:!1,address:a.trim()||"(unknown)",rayVersion:null,error:C instanceof Error?C.message:String(C)})}}return l.jsx(l.Fragment,{children:o?l.jsx("div",{className:"error",children:o}):n?l.jsxs(l.Fragment,{children:[(w==null?void 0:w.error)&&l.jsx("p",{className:Z0,children:w.error}),l.jsxs("form",{className:qC,onSubmit:k,children:[l.jsxs("label",{children:[Aqr(),l.jsx(yn,{type:"text",value:a,onChange:C=>{i(C.target.value),m(null)},placeholder:"http://127.0.0.1:8265",autoComplete:"off",spellCheck:!1})]}),l.jsxs("p",{className:"m-0 text-sm text-subtext",children:[VBr(),": ",Ae(n.resolvedAddress)," · ",bI(),": ",n.source]}),d&&l.jsx("div",{className:"error",children:d}),l.jsxs("div",{className:"actions",children:[l.jsx(Se,{variant:"primary",type:"submit",disabled:c||x,children:c?Pi():Ii()}),l.jsx(Se,{type:"button",onClick:()=>void b(),disabled:p==="testing",children:mtn()}),l.jsx(QU,{test:p})]}),(w==null?void 0:w.reachable)&&w.rayVersion&&l.jsxs("p",{className:"m-0 text-sm text-subtext",children:[PYr(),": ",w.rayVersion]})]})]}):l.jsxs(ys,{children:[l.jsx($t,{})," ",pUr()]})})}function QU({test:e}){return e===null?null:e==="testing"?l.jsx(tr,{children:Ctn()}):e.reachable?l.jsx(tr,{variant:"success",children:QYr()}):l.jsx(tr,{variant:"error",children:OS()})}function mss(e){const r=e.chip??`${e.os}/${e.arch}`,t=e.memBytes===null?null:du(e.memBytes),n=e.gpus.length===0?null:B9r({count:e.gpus.length});return[r,e.cpuCount>0?tzr({count:e.cpuCount}):null,t,n].filter(Boolean).join(" · ")}function gss({remote:e}){var p;const r=nt(Z$n()),t=r.data,n=(p=r.error)==null?void 0:p.message,s=r.isFetching,[o,a]=A.useState(0),[i,c]=A.useState(!0),[_,d]=A.useState(!1),f=()=>r.refetch();return l.jsxs(l.Fragment,{children:[n&&!t?l.jsx("div",{className:"error",children:n}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:nss,children:[l.jsx("span",{className:"k",children:Op()}),l.jsx("span",{className:"v",children:!t&&s||_?l.jsxs(tr,{className:"gap-1.5",role:"status",children:[l.jsx($t,{}),_?tOr():Ea()]}):n?l.jsx(tr,{variant:"warning",children:Wb()}):t?t.loggedIn?t.sshKeyStatus==="matched"?l.jsx(tr,{variant:"success",children:L0()}):t.sshKeyStatus==="unknown"?l.jsx(tr,{variant:"warning",children:Wb()}):l.jsx(tr,{variant:"warning",children:ex()}):l.jsx(tr,{variant:"warning",children:mI()}):null}),l.jsx("span",{className:"k",children:SXr()}),l.jsx("span",{className:"v",children:t!=null&&t.loggedIn&&t.orgs.length>0?t.orgs.join(", "):"—"}),l.jsx("span",{className:"k",children:_en()}),l.jsx("span",{className:"v",children:t!=null&&t.loggedIn?t.sshKeyStatus==="matched"?l.jsx(tr,{variant:"success",children:xQr()}):t.sshKeyStatus==="no_local_match"?l.jsx(tr,{variant:"warning",children:KVr()}):t.sshKeyStatus==="none_registered"?l.jsx(tr,{variant:"error",children:lVr()}):l.jsx(tr,{children:yI()}):"—"})]}),e&&t&&!t.loggedIn&&l.jsx("p",{className:"mt-4 mb-0 text-sm text-subtext",children:cAr({command:Ae("orx login")})}),!e&&o>0&&l.jsx(hFn,{login:i,onComplete:()=>{d(!1),a(0),f()},onError:m=>{d(!1),Kt(m,"error")}},o),e&&(t==null?void 0:t.loggedIn)&&t.sshKeyStatus==="none_registered"&&(t.sshKeyPath?l.jsxs("p",{dir:"auto",className:Sa,children:[XOr()," ",l.jsxs("code",{children:["orx ssh-key add ",t.sshKeyPath]}),"."]}):l.jsxs("p",{dir:"auto",className:Sa,children:[qKr()," ",l.jsx("code",{children:"ssh-keygen -t ed25519"}),Ltn()," ",l.jsx("code",{children:"orx ssh-key add"}),"."]})),e&&(t==null?void 0:t.loggedIn)&&t.sshKeyStatus==="no_local_match"&&(t.sshKeyPath?l.jsx("p",{dir:"auto",className:Sa,children:zsn({register:Ae(`orx ssh-key add ${t.sshKeyPath}`),load:Ae("ssh-add")})}):l.jsxs("p",{dir:"auto",className:Sa,children:[MKr()," ",l.jsx("code",{children:"ssh-add"}),oXr()," ",l.jsx("code",{children:"ssh-keygen -t ed25519"}),"."]})),!s&&(n||(t==null?void 0:t.error))&&l.jsx("p",{dir:"auto",className:"mt-4 mb-0 text-sm text-accent-red whitespace-pre-wrap break-words",children:n||(t==null?void 0:t.error)})]}),l.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[l.jsxs(Se,{onClick:()=>void f(),disabled:s||_,children:[l.jsx(Fi,{size:14})," ",s?Ea():$0()]}),!e&&t&&(!t.loggedIn||t.sshKeyStatus!=="matched")&&l.jsxs(Se,{variant:"primary",disabled:s||_,onClick:()=>{c(!t.loggedIn),d(!0),a(m=>m+1)},children:[_?l.jsx($t,{}):l.jsx(q_,{size:14})," ",t.loggedIn?Lan():CI()]})]})]})}const vss={local:pot,ssh:_at,tinker:xat,hf:Qst,modal:Sot,k8s:oot,slurm:tat,ray:Got,openresearch:$ot},r2={local:"local_job",tinker:"tinker_job",hf:"hf_job",modal:"modal_job",k8s:"k8s_job",ssh:"ssh_job",slurm:"slurm_job",ray:"ray_job",openresearch:"openresearch_job"},JM=["hf","modal","slurm","ray","openresearch"],y4=["hf","modal","openresearch"],XU={hf:["cpu-basic","t4-small","a10g-small","a10g-large","a100-large","h100","h200"],modal:["cpu","t4","l4","a10g","a100","a100-80gb","l40s","h100","h100:2"],slurm:["gpu","h100:1","h100:2","a100:4"],ray:["cpu","cpu:2","gpu","gpu:1","gpu:1,cpu:4","gpu:1,mem:8GiB"],openresearch:["h100_sxm","h100_sxm:2","cpu5c","cpu5g","cpu5m"]},gj=["tinker","hf","modal","ray","k8s"],bss={tinker:Hct,hf:fct,modal:wct,openresearch:Rct},eO="__custom__";function Vm(e,r){return!!(r&&!(XU[e]??[]).includes(r))}function yss({settings:e,projectId:r,onSaved:t}){const n=pr({mutationFn:LOn}),s=e.configuredDefaultBackend??e.defaultBackend??"local",o=e.defaultFlavor??"",[a,i]=A.useState(s),[c,_]=A.useState(o),[d,f]=A.useState(Vm(s,o)),[p,m]=A.useState(!1),[w,y]=A.useState(null),v=e.targets.find(I=>I.id===a),x=e.targets.filter(I=>I.configured||I.id===s),k=JM.includes(a),b=y4.includes(a),S=XU[a]??[],C=a===s&&(!k||c.trim()===o),N=vd[a](),T=bss[a],E=p?H_n():b&&!c.trim()?rCr({destination:N}):a==="ssh"?uRr():eRr({destination:N});A.useEffect(()=>{i(s),_(o),f(Vm(s,o))},[s,o]);async function R(I,P){const B=JM.includes(I);if(!(p||y4.includes(I)&&!P.trim())){m(!0),y(null);try{t(await n.mutateAsync({backend:I,flavor:B&&P.trim()||null,projectId:r}))}catch(K){y(K instanceof Error?K.message:String(K)),i(s),_(o),f(Vm(s,o))}finally{m(!1)}}}function $(I){const P=e.targets.find(K=>K.id===I);if(!P)return;i(P.id);const B=P.id===s?o:"";_(B),f(Vm(P.id,B)),y4.includes(P.id)||R(P.id,B)}function L(I){if(I===eO){f(!0);return}f(!1),_(I),(!b||I)&&R(a,I)}return l.jsxs("section",{className:"mb-8",children:[l.jsx("h2",{className:"mt-0 mx-0 mb-2 text-lg",children:cBr()}),l.jsxs("div",{children:[l.jsxs("form",{className:"grid grid-cols-[minmax(12rem,18rem)_minmax(12rem,18rem)] items-start gap-3",onSubmit:I=>{I.preventDefault(),C||R(a,c)},children:[l.jsx(ea,{choices:x.map(I=>({id:I.id,label:vd[I.id]()})),value:a,variant:"field",dropDown:!0,disabled:p,renderIcon:I=>{const P=e.targets.find(B=>B.id===I.id);return P?l.jsx(Hp,{kind:r2[P.id],size:16}):null},onSelect:$}),k&&l.jsx("div",{children:d?l.jsxs("div",{className:"relative",children:[l.jsx("input",{className:"h-9 w-full rounded-md border border-border bg-background py-0 pe-10 ps-3 font-sans text-sm text-text outline-none focus:border-focus-border focus:ring-3 focus:ring-focus-ring",type:"text",value:c,onChange:I=>_(I.target.value),onBlur:()=>{if(b&&!c.trim()){a===s&&(_(o),f(Vm(s,o)));return}C||R(a,c)},placeholder:dPr(),autoFocus:!0,autoComplete:"off",spellCheck:!1,disabled:p}),l.jsx("button",{type:"button",className:"absolute inset-y-0 end-0 inline-flex w-9 items-center justify-center text-muted hover:text-text","aria-label":QN(),title:QN(),onMouseDown:I=>I.preventDefault(),onClick:()=>f(!1),children:l.jsx(kc,{size:12})})]}):l.jsx(ea,{choices:[{id:"",label:b?W6r():ARr()},...c&&!S.includes(c)?[{id:c,label:xzr({value:Ae(c)})}]:[],...S.map(I=>({id:I,label:I})),{id:eO,label:kPr()}],value:c,variant:"field",dropDown:!0,disabled:p,onSelect:L})})]}),w&&l.jsx("div",{className:"error mt-2.5",children:w}),v&&!v.configured&&l.jsx("p",{className:Sa,children:Wtn()})]}),l.jsx("p",{className:"mt-2 mb-0 text-sm leading-relaxed text-subtext",children:E}),T&&l.jsx("p",{className:"mt-1 mb-0 text-sm leading-relaxed text-subtext",children:T()})]})}function xss({target:e,isDefault:r,summary:t,onOpen:n,onOpenEnvironment:s}){const o=`compute-${e.id}-summary`,a=e.unverified?C6r():e.id==="openresearch"?CI():e.id==="ray"?bp():Can();return l.jsxs("div",{className:`group relative flex min-h-41 w-full flex-col items-start rounded-lg border border-border bg-background p-5 text-start font-sans ${n&&e.enabled?"transition-colors duration-120 ease-standard hover:border-border-hover-strong hover:bg-surface":""} ${e.enabled?"":"opacity-52"}`,children:[n&&l.jsx("button",{type:"button",className:"absolute inset-0 z-10 rounded-lg focus-visible:outline-2 focus-visible:outline-focus focus-visible:outline-offset-2 disabled:cursor-default",onClick:n,disabled:!e.enabled,"aria-label":vd[e.id](),"aria-describedby":o,"aria-haspopup":gj.includes(e.id)?"dialog":void 0}),l.jsx("span",{className:"flex h-16 w-40 flex-none items-center justify-start",children:l.jsx(Hp,{kind:r2[e.id],size:48})}),l.jsx("span",{className:"mt-5 text-lg font-semibold text-text",children:vd[e.id]()}),l.jsx("span",{className:"mt-1 line-clamp-2 min-h-9 text-sm leading-normal text-text",children:vss[e.id]()}),l.jsx("span",{id:o,className:"mt-2 line-clamp-2 min-h-8 text-xs leading-normal text-subtext",children:e.fromEnvironmentTab?l.jsxs(l.Fragment,{children:[e.id==="tinker"?wNr():Bln()," ",l.jsx("button",{type:"button",className:"relative z-20 text-accent-blue-strong underline-offset-2 hover:underline",onClick:s,children:Qzr()})]}):t??e.summary}),l.jsxs("span",{className:"mt-auto flex w-full items-center justify-between gap-3 pt-3 text-sm",children:[l.jsx("span",{className:r?"font-medium text-text":"text-subtext",children:r?_I():e.configured?!n||gj.includes(e.id)?D0():ifn():a}),n&&l.jsx("span",{className:"text-subtext transition-transform duration-120 ease-standard group-hover:translate-x-0.5","aria-hidden":"true",children:l.jsx(cb,{size:16})})]})]})}function wss({target:e,isDefault:r,onBack:t,remote:n}){return l.jsxs(l.Fragment,{children:[l.jsxs("button",{type:"button",className:"settings-back mb-6 inline-flex items-center gap-2 text-sm font-medium text-subtext hover:text-text",onClick:t,children:[l.jsx(ty,{size:16})," ",cI()]}),l.jsxs("div",{className:"flex items-center justify-between gap-6",children:[l.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[l.jsx("span",{className:"flex h-10 w-10 flex-none items-center justify-center",children:l.jsx(Hp,{kind:r2[e.id],size:36})}),l.jsx("h1",{className:"m-0 min-w-0 text-2xl",children:vd[e.id]()})]}),r&&l.jsx(tr,{className:"flex-none",children:_I()})]}),l.jsxs("div",{className:"mt-6 font-sans text-base text-text [&_.settings-card]:mb-0 [&_.settings-form]:mt-6 [&_.settings-form]:border-t-0 [&_.settings-form]:pt-0 [&>.settings-form:first-child]:mt-0 [&>div:first-child]:border-t-0",children:[e.id==="ssh"&&l.jsx(fss,{}),e.id==="slurm"&&l.jsx(hss,{}),e.id==="openresearch"&&l.jsx(gss,{remote:n})]})]})}function kss({target:e,remote:r,onClose:t}){const n=A.useRef(null),[s,o]=A.useState({dirty:!1,saving:!1});A.useEffect(()=>{const i=n.current;return i==null||i.showModal(),()=>i==null?void 0:i.close()},[]);const a=()=>{s.saving||s.dirty&&!window.confirm(fNr())||t()};return l.jsxs("dialog",{ref:n,className:"m-auto w-140 max-w-[calc(100vw_-_40px)] max-h-[calc(100vh_-_40px)] overflow-y-auto rounded-xl border border-border bg-background p-5 text-text shadow-modal backdrop:bg-modal-backdrop-light","aria-labelledby":"compute-quick-setup-title",onKeyDown:i=>{i.key==="Escape"&&(i.preventDefault(),a())},onCancel:i=>{i.preventDefault(),a()},children:[l.jsxs("div",{className:"mb-5 flex items-center justify-between gap-4",children:[l.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[l.jsx(Hp,{kind:r2[e.id],size:32}),l.jsx("h2",{id:"compute-quick-setup-title",className:"m-0 text-xl font-medium text-text",children:vd[e.id]()})]}),l.jsx(xt,{title:Rg(),"aria-label":Rg(),onClick:a,disabled:s.saving,children:l.jsx(hn,{size:14})})]}),e.id==="tinker"&&l.jsx(Sss,{target:e}),e.id==="hf"&&l.jsx(zss,{remote:r}),e.id==="modal"&&l.jsx(lss,{}),e.id==="ray"&&l.jsx(pss,{}),e.id==="k8s"&&l.jsx(css,{onEditState:o})]})}function jss({project:e,onViewHistory:r,onOpenEnvironment:t,remote:n}){var R,$;const s=cP(e==null?void 0:e.id),o=nt(s),a=o.data??null,i=L=>{fs(s.queryKey,I=>(typeof L=="function"?L(I??null):L)??void 0)},c=a?null:((R=o.error)==null?void 0:R.message)??null,[_,d]=A.useState(null),[f,p]=A.useState(null),m=Y$n(),w=nt(m),y=w.data??null,v=(($=w.error)==null?void 0:$.message)??null;A.useEffect(()=>{d(null),p(null)},[e==null?void 0:e.id]);const x=L=>{i(L),p(null)},k=a?a.targets:null,b=(a==null?void 0:a.configuredDefaultBackend)??(a==null?void 0:a.defaultBackend),S=k?[...k].sort((L,I)=>+(I.id===b)-+(L.id===b)):null,C=(S==null?void 0:S.filter(L=>L.configured))??[],N=(S==null?void 0:S.filter(L=>!L.configured))??[],T=L=>l.jsx(xss,{target:L,isDefault:b===L.id,summary:L.id==="local"?y?mss(y):v??vBr():void 0,onOpen:L.id==="local"?void 0:()=>d(L.id),onOpenEnvironment:t},`${(e==null?void 0:e.id)??"none"}:${L.id}`),E=_?a==null?void 0:a.targets.find(L=>L.id===_):null;return E&&!gj.includes(E.id)?l.jsx(wss,{target:E,isDefault:b===E.id,onBack:()=>d(null),remote:n}):l.jsxs(l.Fragment,{children:[l.jsx("h1",{children:lI()}),l.jsx("p",{className:"settings-sub mt-0 mx-0 mb-4.5 text-base leading-relaxed text-text",children:vIr()}),l.jsx(Wss,{projectId:e==null?void 0:e.id,onViewHistory:r}),c?l.jsx("div",{className:"error",children:c}):a?l.jsxs(l.Fragment,{children:[f&&l.jsx("div",{className:"error",children:f}),l.jsx(yss,{settings:a,projectId:e==null?void 0:e.id,onSaved:x}),l.jsxs("section",{className:"mb-8",children:[l.jsx("h2",{className:"mt-0 mx-0 mb-2 text-lg",children:D0()}),l.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3",children:C.map(T)})]}),N.length>0&&l.jsxs("section",{className:"mb-3.5",children:[l.jsx("h2",{className:"mt-0 mx-0 mb-2 text-lg",children:xGr()}),l.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3",children:N.map(T)})]}),E&&l.jsx(kss,{target:E,remote:n,onClose:()=>d(null)})]}):l.jsxs(ys,{children:[l.jsx($t,{})," ",QLr()]})]})}function Sss({target:e}){var k;const r=pr({mutationFn:eOn}),[t,n]=A.useState(""),[s,o]=A.useState(!1),[a,i]=A.useState(null),c=fA(),_=nt(c),d=_.data??null,f=a??((k=_.error)==null?void 0:k.message)??null,p=b=>{fs(c.queryKey,S=>(typeof b=="function"?b(S??null):b)??void 0)},[m,w]=A.useState(!1),y=_.isPending||m;async function v(){if(!(y||s)){w(!0),i(null);try{await Xe.fetchQuery({...fA(),staleTime:0})}catch(b){i(b instanceof Error?b.message:String(b))}finally{w(!1)}}}async function x(b){if(b.preventDefault(),!(!t.trim()||s||y)){o(!0),i(null);try{p(await r.mutateAsync(t.trim())),n("")}catch(S){i(S instanceof Error?S.message:String(S))}finally{o(!1)}}}return l.jsxs(l.Fragment,{children:[!d&&y?l.jsxs(ys,{children:[l.jsx($t,{})," ",Ea()]}):d&&l.jsxs("dl",{className:"m-0 flex items-center justify-between gap-4 text-sm",children:[l.jsx("dt",{className:"font-medium text-subtext",children:Op()}),l.jsx("dd",{className:"m-0",children:l.jsx(tr,{variant:d.validationStatus==="valid"?"success":d.validationStatus==="invalid"?"error":"warning",children:d.validationStatus==="valid"?L0():d.validationStatus==="invalid"?Aln():d.validationStatus==="billingRequired"?uln():ex()})})]}),(d==null?void 0:d.validationStatus)==="billingRequired"&&l.jsx("p",{className:"mt-2 mb-0 text-sm text-subtext",children:l.jsx("a",{className:"underline",href:"https://tinker.thinkingmachines.ai/",target:"_blank",rel:"noreferrer",children:eln()})}),(d==null?void 0:d.processEnv)&&l.jsx("p",{className:"mt-2 mb-0 text-sm text-subtext",children:yln()}),l.jsxs("form",{className:"mt-5 flex flex-col gap-4",onSubmit:x,children:[l.jsxs("label",{className:"flex flex-col gap-2 text-sm font-medium text-subtext",children:[e.configured||d!==null&&d.validationStatus!=="missing"?Ton():Jy(),l.jsx(yn,{type:"password",value:t,placeholder:(d==null?void 0:d.maskedKey)??"",onChange:b=>n(b.target.value),autoComplete:"new-password"})]}),f&&l.jsx("p",{className:"m-0 text-sm text-accent-red",children:f}),l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsxs(Se,{type:"button",disabled:s||y,onClick:()=>void v(),children:[l.jsx(Fi,{size:14})," ",y?Ea():$0()]}),l.jsx(Se,{variant:"primary",type:"submit",disabled:!t.trim()||s||y,children:s?EI():Ii()})]})]})]})}function Css({settings:e}){return e.validationStatus==="missing"?l.jsx(tr,{variant:"warning",children:ex()}):e.validationStatus==="invalid"?l.jsx(tr,{variant:"error",children:yqr()}):e.validationStatus!=="valid"?null:e.jobsWrite===!0?l.jsx(tr,{variant:"success",children:L0()}):e.jobsWrite===!1?l.jsxs("span",{className:"inline-flex items-center gap-2",children:[l.jsx(tr,{variant:"warning",children:kKr()}),l.jsx(Lo,{content:aEr(),className:"text-subtext",children:l.jsx(ZS,{size:16})})]}):null}function zss({remote:e}){var k;const r=pr({mutationFn:ZMn}),t=_A(),n=nt(t),s=n.data??null,o=b=>{fs(t.queryKey,S=>(typeof b=="function"?b(S??null):b)??void 0)},a=s?null:((k=n.error)==null?void 0:k.message)??null,[i,c]=A.useState(""),[_,d]=A.useState(!1),[f,p]=A.useState(!1),[m,w]=A.useState(null),y=UC();async function v(){if(!(_||f||!s&&!a)){p(!0),w(null);try{await Xe.fetchQuery({..._A(),staleTime:0})}catch(b){w(b instanceof Error?b.message:String(b))}finally{p(!1)}}}async function x(b){if(b.preventDefault(),!(!i.trim()||_||f||!s&&!a)){d(!0),w(null);try{const S=await r.mutateAsync(i.trim());o(S),w(null),c("")}catch(S){w(S instanceof Error?S.message:String(S))}finally{d(!1)}}}return l.jsxs(l.Fragment,{children:[a?l.jsx("div",{className:"error",children:a}):s?l.jsxs(l.Fragment,{children:[l.jsxs("dl",{className:"m-0 flex flex-col gap-3 text-sm",children:[s.username&&l.jsxs("div",{className:"flex items-center justify-between gap-4",children:[l.jsx("dt",{className:"font-medium text-subtext",children:MS()}),l.jsx("dd",{className:"m-0 text-text",children:s.username})]}),(s.validationStatus==="missing"||s.validationStatus==="invalid"||s.validationStatus==="valid"&&s.jobsWrite!==null)&&l.jsxs("div",{className:"flex items-center justify-between gap-4",children:[l.jsx("dt",{className:"font-medium text-subtext",children:Op()}),l.jsx("dd",{className:"m-0 text-text",children:l.jsx(Css,{settings:s})})]})]}),s.validationStatus==="unreachable"&&s.validationError&&l.jsx("p",{className:Z0,children:s.validationError}),s.source==="env"&&l.jsx("p",{className:Sa,children:aHr()}),s.validationStatus==="valid"&&s.jobsWrite===null&&l.jsx(GC,{note:X9r({login:"`hf auth login`",url:Ae("huggingface.co/settings/tokens")}),className:Sa,disabled:e,onRun:y.start}),l.jsx(WC,{run:y.run,onComplete:()=>void n.refetch(),onClose:y.clear})]}):l.jsxs(ys,{children:[l.jsx($t,{})," ",$Ur()]}),l.jsxs("form",{className:"mt-5 flex flex-col gap-4",onSubmit:x,children:[l.jsxs("label",{className:"flex flex-col gap-2 text-sm font-medium text-subtext",children:[s!=null&&s.configured?Fon():yRr(),l.jsx(yn,{type:"password",value:i,onChange:b=>c(b.target.value),placeholder:(s==null?void 0:s.maskedToken)??XFr(),autoComplete:"off"})]}),m&&l.jsx("div",{className:"error",children:m}),l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsxs(Se,{type:"button",disabled:_||f||!s&&!a,onClick:()=>void v(),children:[l.jsx(Fi,{size:14})," ",f?Ea():$0()]}),l.jsx(Se,{variant:"primary",type:"submit",disabled:!i.trim()||_||f||!s&&!a,children:_?EI():Ii()})]})]})]})}const YU=/^hf_[A-Za-z0-9]{10,}$/;function ZU(){return l.jsx("tr",{children:l.jsx("td",{colSpan:3,children:l.jsxs("p",{dir:"auto",className:Sa,children:[rrn()," ",l.jsx("code",{children:"HF_TOKEN"}),zJr()]})})})}const tO=["TINKER_API_KEY","HF_TOKEN","WANDB_API_KEY"];function vj(e,r){const t=r instanceof Error?r.message:String(r);Kt(t.includes(e)?t:`${e}: ${t}`,"error")}function Ess({name:e,entry:r,onVars:t}){const n=pr({mutationFn:w=>BS(...w)}),s=pr({mutationFn:_On}),o=(r==null?void 0:r.value)!=null,a=(r==null?void 0:r.value)??"",[i,c]=A.useState(a),[_,d]=A.useState(!1);A.useEffect(()=>c(a),[a]);const f=i.trim()!==a;async function p(){var w;if(!(!i.trim()||_||o&&!f)){d(!0);try{const y=await n.mutateAsync([e,i.trim()]);t(y),c(o?((w=y.find(v=>v.key===e))==null?void 0:w.value)??"":"")}catch(y){vj(e,y)}finally{d(!1)}}}async function m(){if(!_){d(!0);try{t(await s.mutateAsync(e))}catch(w){vj(e,w)}finally{d(!1)}}}return l.jsxs(l.Fragment,{children:[l.jsxs("tr",{children:[l.jsx("td",{className:"font-mono text-sm",children:e}),l.jsxs("td",{className:"text-base text-subtext",children:[r&&!o?l.jsxs(l.Fragment,{children:[r.maskedValue,r.inProcessEnv&&l.jsx(tr,{children:q5()})]}):l.jsx(yn,{variant:"inline",className:"text-base",type:o?"text":"password",value:i,onChange:w=>c(w.target.value),onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),p()),w.key==="Escape"&&!_&&c(a)},placeholder:xI(),"aria-label":Lse({name:Ae(e)}),autoComplete:o?"off":"new-password",disabled:_}),o&&(r==null?void 0:r.inProcessEnv)&&l.jsx(tr,{children:q5()})]}),l.jsx("td",{children:r&&!(o&&f&&i.trim())?l.jsx(xt,{className:"[&:hover:not(:disabled)]:text-accent-red",title:_E({name:Ae(e)}),"aria-label":_E({name:Ae(e)}),onClick:()=>void m(),disabled:_,children:l.jsx(ef,{size:14})}):i.trim()&&l.jsx(Se,{size:"small",onClick:()=>void p(),disabled:_,children:_?Pi():Ii()})})]}),!r&&e!=="HF_TOKEN"&&YU.test(i.trim())&&l.jsx(ZU,{})]})}function Nss({onVars:e,onDone:r}){const t=pr({mutationFn:f=>BS(...f)}),[n,s]=A.useState(""),[o,a]=A.useState(""),[i,c]=A.useState(!1);async function _(){if(!(!n.trim()||!o.trim()||i)){c(!0);try{e(await t.mutateAsync([n.trim(),o.trim()])),r()}catch(f){vj(n.trim(),f)}finally{c(!1)}}}const d=f=>{f.key==="Enter"&&(f.preventDefault(),_()),f.key==="Escape"&&!i&&r()};return l.jsxs(l.Fragment,{children:[l.jsxs("tr",{children:[l.jsx("td",{children:l.jsx(yn,{autoFocus:!0,variant:"inline",className:"font-mono text-sm",type:"text",value:n,onChange:f=>s(f.target.value),onKeyDown:d,placeholder:"MY_API_KEY","aria-label":zWr(),autoComplete:"off",spellCheck:!1,disabled:i})}),l.jsx("td",{children:l.jsx(yn,{variant:"inline",className:"text-base",type:"password",value:o,onChange:f=>a(f.target.value),onKeyDown:d,placeholder:xI(),"aria-label":DWr(),autoComplete:"new-password",disabled:i})}),l.jsxs("td",{children:[l.jsx(Se,{size:"small",onClick:()=>void _(),disabled:i||!n.trim()||!o.trim(),children:i?Pi():Ii()}),l.jsx(xt,{title:xu(),"aria-label":PLr(),onClick:r,disabled:i,children:l.jsx(hn,{size:14})})]})]}),n.trim()!=="HF_TOKEN"&&YU.test(o.trim())&&l.jsx(ZU,{})]})}function Ass(){var _;const e=lP(),r=nt(e),t=r.data??null,n=d=>{fs(e.queryKey,f=>(typeof d=="function"?d(f??null):d)??void 0)},s=t?null:((_=r.error)==null?void 0:_.message)??null,[o,a]=A.useState(!1),i=t===null?[]:t.map(d=>d.key).filter(d=>!tO.includes(d)),c=[...tO,...i];return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"mb-4.5 flex items-center justify-between gap-4",children:[l.jsx("p",{className:"m-0 text-base leading-relaxed text-text",children:jnn()}),l.jsxs(Se,{size:"small",className:"shrink-0",onClick:()=>a(!0),disabled:o||t===null,children:[l.jsx(Bi,{size:12})," ",a$r()]})]}),l.jsxs("div",{className:Di,children:[s?l.jsx("div",{className:"error",children:s}):t===null?l.jsxs(ys,{children:[l.jsx($t,{})," ",wu()]}):l.jsx("table",{className:"env-table w-full table-fixed border-collapse text-base [&_td:first-child]:w-[32%] [&_td:first-child]:wrap-anywhere [&_.badge]:ms-2 [&_td]:h-12 [&_td]:pt-0 [&_td]:pe-2.5 [&_td]:pb-0 [&_td]:ps-0 [&_td]:align-middle [&_td]:border-b [&_td]:border-b-border-variant [&_tr:last-child_td]:border-b-0 [&_td:last-child]:w-29 [&_td:last-child]:whitespace-nowrap [&_td:last-child]:text-end [&_td[colspan]]:whitespace-normal [&_td[colspan]]:text-start [&_.icon-btn]:ms-2 [&_.icon-btn]:align-middle",children:l.jsxs("tbody",{children:[c.map(d=>l.jsx(Ess,{name:d,entry:t.find(f=>f.key===d),onVars:n},d)),o&&l.jsx(Nss,{onVars:n,onDone:()=>a(!1)})]})}),(t==null?void 0:t.some(d=>d.key==="TRACKIO_SERVER_URL"||d.key==="TRACKIO_SPACE_ID"))&&l.jsx(Tss,{space:t.some(d=>d.key==="TRACKIO_SPACE_ID")},t.filter(d=>d.key.startsWith("TRACKIO_")).map(d=>`${d.key}=${d.value??d.maskedValue}`).join())]})]})}function Tss({space:e}){const[r,t]=A.useState(null);async function n(){t("testing");try{t(await OOn())}catch(a){t({reachable:!1,version:null,writeAccess:null,spaceStage:null,error:a instanceof Error?a.message:String(a)})}}const s=r===null||r==="testing"?null:r,o=s?[s.version&&Lun({version:Ae(s.version)}),s.spaceStage&&s.spaceStage!=="RUNNING"&&mun({stage:Ae(s.spaceStage)}),s.writeAccess===!0&&(e?Xln():Wun()),s.writeAccess===!1&&(e?aun():r_n())].filter(Boolean):[];return l.jsxs("div",{className:"mt-3",children:[l.jsxs("div",{className:"flex items-center gap-2.5",children:[l.jsx(Se,{type:"button",size:"small",onClick:()=>void n(),disabled:r==="testing",children:Cun()}),l.jsx(QU,{test:r})]}),o.length>0&&l.jsx("p",{className:"m-0 mt-2 text-sm text-subtext",children:o.join(" · ")}),(s==null?void 0:s.error)&&l.jsx("p",{className:Z0,children:s.error})]})}const Qm=[{value:"system",label:Ucn,icon:nB},{value:"light",label:Ocn,icon:BBn},{value:"dark",label:pcn,icon:dBn}],Rss=[{id:"en",label:"English"},{id:"zh-CN",label:"简体中文"},{id:"fa",label:"فارسی"},{id:"ar",label:"العربية"},{id:"es",label:"Español"},{id:"hi",label:"हिन्दी"},{id:"ko",label:"한국어"},{id:"ja",label:"日本語"},{id:"pl",label:"Polski"}];function Mss(){const e=Cu(),[r,t]=SP(),n=s=>{var d;const o=s.key==="ArrowRight"||s.key==="ArrowDown"?1:s.key==="ArrowLeft"||s.key==="ArrowUp"?-1:0;if(!o)return;s.preventDefault();const a=[...s.currentTarget.querySelectorAll('[role="radio"]')],i=a.findIndex(f=>f===document.activeElement),_=((i===-1?Qm.findIndex(f=>f.value===r):i)+o+Qm.length)%Qm.length;t(Qm[_].value),(d=a[_])==null||d.focus()};return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:TSr()}),l.jsxs("div",{className:`${Di} mt-3`,children:[l.jsxs("div",{className:R_,children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:sA()}),l.jsx("div",{className:`${ox} theme-segmented flex-none`,role:"radiogroup","aria-label":sA(),onKeyDown:n,children:Qm.map(({value:s,label:o,icon:a})=>l.jsxs("button",{type:"button",role:"radio","aria-checked":r===s,tabIndex:r===s?0:-1,className:`theme-segment ${r===s?"active":""}`,onClick:()=>t(s),children:[l.jsx(a,{size:14}),o()]},s))})]}),l.jsxs("div",{className:R_,children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:ZNr()}),l.jsx("div",{className:"w-52 flex-none",children:l.jsx(ea,{choices:Rss,value:e,variant:"field",dropDown:!0,onSelect:s=>{nD(s)&&xP(s)}})})]})]})]})}const Oss={installer:fEn,"app-bundle":C9n,appimage:L9n,portable:REn,cargo:W9n,homebrew:rEn,nix:wEn,unknown:HEn},x4={cargo:ZEn,homebrew:cNn,nix:vNn};function $ss(){var f;const e=pr({mutationFn:p=>sOn(...p)}),{status:r,error:t,apply:n}=H6(),[s,o]=A.useState(null),[a,i]=A.useState(null),c=mF(r),_=s!==null||c.restarting;if(!r)return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:tA()}),t?l.jsx("div",{className:Di,children:l.jsx("div",{className:"error",children:t})}):l.jsxs(ys,{children:[l.jsx($t,{})," ",wu()]})]});const d=async(p,m)=>{o(p),i(null);try{await m()}catch(w){i(w instanceof Error?w.message:String(w))}finally{o(null)}};return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:tA()}),l.jsxs("div",{className:`${Di} mt-3`,children:[l.jsxs("div",{className:`${t2} pb-3.5`,children:[l.jsx("div",{className:"k",children:wI()}),l.jsx("div",{className:"v",children:r.current}),l.jsx("div",{className:"k",children:Xqr()}),l.jsx("div",{className:"v",children:r.latest??"—"}),l.jsx("div",{className:"k",children:dI()}),l.jsx("div",{className:"v",children:Oss[r.channel]()})]}),r.restartRequired&&l.jsxs("div",{className:R_,children:[l.jsxs("div",{children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:YZr()}),l.jsx("p",{children:c.error?HI({error:c.error}):Yon({installed:Ae(r.installedVersion??"—"),current:Ae(r.current??r.installedVersion??"—")})})]}),r.canRestart&&l.jsx(Se,{size:"small",type:"button",disabled:_,onClick:c.restart,children:c.restarting?qI():FI()})]}),r.selfUpdates?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:R_,children:[l.jsxs("div",{children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:ZN()}),l.jsxs("p",{children:[gWr(),r.envDisabled&&R_n()]})]}),l.jsx(VS,{type:"button",checked:r.autoUpdate,"aria-label":ZN(),disabled:_,onClick:()=>void d("auto",()=>e.mutateAsync([!r.autoUpdate]).then(n))})]}),l.jsxs("div",{className:R_,children:[l.jsxs("div",{children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:r.updateAvailable?w_n({version:Ae(r.latest??"—")}):a6r()}),l.jsxs("p",{children:[r.updateAvailable?rNr():L6r(),r.updateAvailable&&r.latestTag&&l.jsxs(l.Fragment,{children:[" ",l.jsx("a",{href:pF(r.latestTag),target:"_blank",rel:"noreferrer",className:"underline",children:SI()})]})]})]}),l.jsx(Se,{size:"small",type:"button",disabled:_,onClick:()=>void d("apply",()=>rOn().then(n)),children:s==="apply"?xS():r.updateAvailable?f_n():m6r()})]})]}):l.jsx("div",{className:R_,children:l.jsxs("div",{children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:$Xr()}),l.jsx("p",{children:((f=x4[r.channel])==null?void 0:f.call(x4))??Dsn()})]})}),r.channel==="app-bundle"&&l.jsx(Dss,{busy:s,disabled:_,run:d}),a&&l.jsx("div",{className:"error",children:a})]})]})}function Lss(){var f;const e=pr({mutationFn:r$n}),r=aLn(),t=nt(r),n=t.data??null,s=p=>{fs(r.queryKey,m=>(typeof p=="function"?p(m??null):p)??void 0)},[o,a]=A.useState(!1),[i,c]=A.useState(null),_=i??((f=t.error)==null?void 0:f.message)??null,d=()=>{!n||o||(a(!0),c(null),e.mutateAsync(!n.preferenceEnabled).then(s).catch(p=>c(p instanceof Error?p.message:String(p))).finally(()=>a(!1)))};return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:onn()}),n?l.jsxs("div",{className:`${Di} mt-3`,children:[l.jsxs("div",{className:R_,children:[l.jsxs("div",{children:[l.jsxs("div",{className:"project-default-title inline-flex items-center gap-1.5 text-base font-medium",children:[VN(),n.locked&&n.reason&&l.jsx(Lo,{content:`${nPr()} ${n.reason}.`,className:"text-subtext",children:l.jsx(ZS,{size:16})})]}),l.jsx("p",{children:KWr()})]}),l.jsx(VS,{type:"button",checked:n.enabled,"aria-label":VN(),disabled:o||n.locked,onClick:d})]}),_&&l.jsx("div",{className:"error",children:_})]}):_?l.jsx("div",{className:"error",children:_}):l.jsxs(ys,{children:[l.jsx($t,{})," ",wu()]})]})}function Dss({busy:e,disabled:r,run:t}){const n=pr({mutationFn:oOn}),[s,o]=A.useState(null),[a,i]=A.useState(!1),c=_=>void t("cli",()=>n.mutateAsync(_).then(d=>{o(d),i(!1)}).catch(d=>{throw i(!_&&String((d==null?void 0:d.message)??d).includes("--force")),d}));return l.jsxs("div",{className:R_,children:[l.jsxs("div",{children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:LEr({command:Ae("orx")})}),s?l.jsxs("p",{children:[s.alreadyCurrent?fCr({link:Ae(s.link)}):wCr({link:Ae(s.link)}),!s.onPath&&xSr({directory:Ae(s.dir)})]}):l.jsx("p",{children:CEr({command:Ae("orx")})})]}),l.jsx(Se,{size:"small",type:"button",disabled:r,onClick:()=>c(a),children:e==="cli"?xS():a?xon():s?ron():mEr()})]})}function Iss({remote:e,onProjectUpdate:r}){var b,S;const t=nt(P_()),[n,s]=A.useState(""),o=(b=t.data)==null?void 0:b.find(C=>C.id===n),a=pr({mutationFn:C=>XOn(...C)}),i=_P(),c=nt(i),_=c.data??null;nt({...Jb(),enabled:!!(_!=null&&_.githubAuthenticated)}),nt({...o3(),enabled:!!(_!=null&&_.githubAuthenticated)});const d=C=>{fs(i.queryKey,N=>(typeof C=="function"?C(N??null):C)??void 0)},[f,p]=A.useState(!1),[m,w]=A.useState(null),y=m??((S=c.error)==null?void 0:S.message)??null,v=async()=>{await c.refetch({cancelRefetch:!1}),n&&await Xe.invalidateQueries(fP(n)),await Promise.all([Xe.invalidateQueries(Jb()),Xe.invalidateQueries(o3())])},x=UC(),k=()=>{if(!_||f)return;const C=!_.githubForNewProjects;p(!0),w(null),a.mutateAsync([C,!0]).then(d).catch(N=>w(N instanceof Error?N.message:String(N))).finally(()=>p(!1))};return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:TFr()}),_?l.jsxs("div",{className:`${Di} mt-3`,children:[l.jsx("div",{className:"mb-4 flex justify-start",children:l.jsx(tr,{variant:_.githubAuthenticated?"success":_.ghInstalled?"warning":"error",children:_.githubAuthenticated?L7r():XRr()})}),l.jsxs("div",{className:"flex items-center justify-between gap-6 [&_p]:mt-1 [&_p]:mb-0 [&_p]:text-sm [&_p]:leading-relaxed",children:[l.jsxs("div",{children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:YN()}),l.jsx("p",{children:qnn()})]}),l.jsx(VS,{type:"button",checked:_.githubForNewProjects,"aria-label":YN(),disabled:f||!_.githubAuthenticated&&!_.githubForNewProjects,onClick:k})]}),!_.githubAuthenticated&&l.jsx("div",{className:"mt-4",children:l.jsx(Pss,{ghInstalled:_.ghInstalled,remote:e,onCheck:v,onRun:x.start})}),l.jsx(WC,{run:x.run,onComplete:()=>void v(),onClose:x.clear}),y&&l.jsx("div",{className:"error",children:y}),l.jsxs("div",{className:"mt-6",children:[l.jsx("div",{className:"mb-2 text-sm font-medium",children:KN()}),l.jsx(ea,{variant:"field",dropDown:!0,title:KN(),value:n,choices:[{id:"",label:$8r()},...(t.data??[]).map(C=>({id:C.id,label:C.name}))],onSelect:s}),t.error&&l.jsxs("div",{className:"mt-2 text-sm text-text",children:[l.jsx("p",{className:"m-0",children:t.error.message}),l.jsx(Se,{size:"small",onClick:()=>void t.refetch(),children:_s()})]}),o&&l.jsx(Fss,{project:o,onProjectUpdate:r},o.id)]})]}):y?l.jsx("div",{className:"error",children:y}):l.jsx("div",{className:`${Di} mt-3`,role:"status","aria-label":wu(),"aria-busy":"true",children:l.jsxs("div",{"aria-hidden":"true",className:"motion-safe:animate-pulse",children:[l.jsx("div",{className:"mb-4 flex justify-start",children:l.jsx("div",{className:"h-6 w-48 rounded-full bg-surface"})}),l.jsxs("div",{className:"flex items-center justify-between gap-6",children:[l.jsxs("div",{className:"flex-1 space-y-2",children:[l.jsx("div",{className:"h-5 w-2/3 rounded-xs bg-surface"}),l.jsx("div",{className:"h-4 rounded-xs bg-surface"}),l.jsx("div",{className:"h-4 w-3/4 rounded-xs bg-surface"})]}),l.jsx("div",{className:"h-6 w-10 shrink-0 rounded-full bg-surface"})]}),l.jsx("div",{className:"mt-6 h-4 w-44 rounded-xs bg-surface"}),l.jsx("div",{className:"mt-2 h-8 rounded-xs bg-surface"})]})})]})}function Pss({ghInstalled:e,remote:r,onCheck:t,onRun:n}){const[s,o]=A.useState(!1),a=()=>{o(!0),t().finally(()=>o(!1))};return l.jsxs(l.Fragment,{children:[l.jsx(GC,{note:e?ian():WEr(),className:"git-card-helper m-0 text-sm leading-relaxed text-text",disabled:r||!e,onRun:n}),l.jsxs("div",{className:"flex flex-wrap gap-2 mt-2.5",children:[!e&&l.jsxs(B_,{variant:"primary",href:"https://cli.github.com/",target:"_blank",rel:"noreferrer",children:[GHr()," ",l.jsx(F_,{size:12})]}),l.jsx(Se,{type:"button",variant:e?"warning":"default",disabled:s,onClick:a,children:s?Ea():$0()})]})]})}function Bss(){var p,m,w,y,v,x;const e=pr({mutationFn:IMn}),r=pr({mutationFn:PMn}),t=gqn(),n=nt(t),[s,o]=A.useState(!1),[a,i]=A.useState(!1),[c,_]=A.useState(null),d=k=>fs(t.queryKey,b=>b&&{...b,...k}),f=async k=>{_(k);try{d(await(k==="token"?e.mutateAsync():r.mutateAsync()))}catch(b){Kt(b instanceof Error?b.message:String(b),"error")}finally{_(null)}};return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:gI()}),l.jsx("p",{className:"mt-1 mb-3 text-sm text-text",children:xOr()}),l.jsxs("div",{className:`${Di} space-y-5`,children:[l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between gap-4",children:[l.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[l.jsx("span",{className:"text-base font-medium",children:_Or()}),l.jsx(tr,{variant:(p=n.data)!=null&&p.hasToken?"success":"default",children:n.isPending?Ea():n.data?n.data.hasToken?nA():F5():Ri()})]}),(m=n.data)!=null&&m.hasToken?l.jsx(Se,{size:"small",disabled:c!==null,onClick:()=>void f("token"),children:c==="token"?rA():$g()}):l.jsx(Se,{size:"small",disabled:!n.data,"aria-expanded":s,onClick:()=>o(!s),children:s?yp():bp()})]}),s&&!((w=n.data)!=null&&w.hasToken)&&l.jsxs("div",{className:"mt-3",children:[l.jsx("p",{className:"mt-0 mb-2 text-sm leading-relaxed text-text",children:eI()}),l.jsx(ZM,{save:YI,onSaved:k=>{d(k),o(!1)},placeholder:eYr(),createHref:"https://www.overleaf.com/user/settings"})]})]}),l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between gap-4",children:[l.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[l.jsx("span",{className:"text-base font-medium",children:TOr()}),l.jsx(tr,{variant:(y=n.data)!=null&&y.hasSession?"success":"default",children:n.isPending?Ea():n.data?n.data.hasSession?nA():F5():Ri()})]}),(v=n.data)!=null&&v.hasSession?l.jsx(Se,{size:"small",disabled:c!==null,onClick:()=>void f("session"),children:c==="session"?rA():$g()}):l.jsx(Se,{size:"small",disabled:!n.data,"aria-expanded":a,onClick:()=>i(!a),children:a?yp():bp()})]}),a&&!((x=n.data)!=null&&x.hasSession)&&l.jsxs("div",{className:"mt-3",children:[l.jsx("p",{className:"mt-0 mb-2 text-sm leading-relaxed text-text",children:ZD()}),l.jsx(ZM,{save:ZI,onSaved:k=>{d(k),i(!1)},placeholder:D5(),createHref:"https://www.overleaf.com/project",createLabel:_cr()})]})]}),n.error&&l.jsx("div",{className:"error",children:n.error.message})]})]})}function Fss({project:e,onProjectUpdate:r}){var T,E,R,$,L,I;const t={...fP((e==null?void 0:e.id)??""),enabled:!!e},n=nt(t),s=n.data??null,o=P=>{fs(t.queryKey,B=>(typeof P=="function"?P(B??null):P)??void 0)},[a,i]=A.useState(!1),[c,_]=A.useState(null),d=c??((T=n.error)==null?void 0:T.message)??null,f=!!(s!=null&&s.github.owner&&s.github.repo),p=nt({...a3((s==null?void 0:s.github.owner)??"",(s==null?void 0:s.github.repo)??""),enabled:f&&!!(s!=null&&s.github.authenticated)&&!(s!=null&&s.github.enabled)}),m=f&&!p.data&&!p.error,w=f&&!!((E=p.data)!=null&&E.canPush),y=A.useRef(null),v=Na(y),x=nt({...Jb(),enabled:v.open}),k=nt({...o3(),enabled:v.open}),b=((R=x.data)==null?void 0:R.login)??null,S=[...b?[b]:[],...(($=k.data)==null?void 0:$.organizations)??[]],C=P=>{const B=P instanceof Error?P.message:String(P);return B.startsWith("GitHub denied repository creation")?B:B.toLowerCase().includes("archived")?S8r():B.includes("(fetch first)")||B.includes("non-fast-forward")?t9r():B.includes("403")||B.toLowerCase().includes("permission denied")?A9r():B},N=P=>{v.setOpen(!1),e&&(i(!0),_(null),JOn(e.id,P===b?void 0:P).then(B=>{o(B.git),r(B.project)}).catch(B=>_(C(B))).finally(()=>i(!1)))};return l.jsx(l.Fragment,{children:e?d&&!s?l.jsx("div",{className:"error",children:d}):s?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"mt-4 min-h-22",children:[!s.initialized&&l.jsx("div",{className:"flex flex-wrap gap-2 mt-3.5",children:l.jsx(Se,{variant:"primary",onClick:()=>void ZOn(e.id).then(o).catch(P=>_(String(P))),children:mHr()})}),l.jsxs("div",{className:t2,children:[l.jsx("span",{className:"k",children:NYr()}),l.jsx("span",{className:"v",children:f?l.jsxs(l.Fragment,{children:[l.jsxs("span",{children:[s.github.owner,"/",s.github.repo]}),!s.github.enabled&&l.jsx(tr,{children:atn()})]}):l.jsx(tr,{children:GUr()})}),s.github.enabled&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"k",children:Xen()}),l.jsx("span",{className:"v",children:s.github.syncStatus})]})]}),s.github.authenticated&&!s.github.enabled&&l.jsxs("div",{className:"flex flex-wrap gap-2 mt-3.5",children:[f&&s.github.url&&l.jsxs(B_,{href:s.github.url,target:"_blank",rel:"noreferrer",children:[eA()," ",l.jsx(F_,{size:12})]}),l.jsxs("div",{ref:v.ref,className:"relative",children:[l.jsxs(Se,{variant:"primary",disabled:a||m||!!p.error,"aria-expanded":v.open,"aria-haspopup":w?void 0:"menu",onClick:P=>{y.current=P.currentTarget,w?N():v.setOpen(!v.open)},children:[a?i5r():m?Ea():Y4r()," ",!w&&!m&&l.jsx(kc,{size:14})]}),v.open&&l.jsxs("div",{role:"menu","aria-label":y9r(),className:"absolute start-0 top-full z-50 mt-2 w-72 max-w-[calc(100vw-2rem)] max-h-64 overflow-y-auto rounded-lg border border-border bg-background p-2 shadow-modal",children:[l.jsx("div",{className:"px-2 py-1 text-sm font-medium text-subtext",children:G8r()}),f&&l.jsx("p",{className:"px-2 py-1 m-0 text-sm text-text",children:_zr()}),S.map(P=>l.jsx(cr,{role:"menuitem",onClick:()=>N(P),children:P},P)),!S.length&&(x.isFetching||k.isFetching)&&l.jsx("div",{role:"status","aria-label":wu(),"aria-busy":"true",className:"px-2 py-2",children:l.jsxs("div",{"aria-hidden":"true",className:"space-y-3 motion-safe:animate-pulse",children:[l.jsx("div",{className:"h-4 w-28 rounded-xs bg-surface"}),l.jsx("div",{className:"h-4 w-36 rounded-xs bg-surface"})]})}),(x.error||k.error||!b&&!x.isFetching)&&l.jsxs("div",{className:"px-2 py-1 text-sm text-text",children:[l.jsx("p",{className:"m-0",children:((L=x.error)==null?void 0:L.message)??((I=k.error)==null?void 0:I.message)??p8r()}),l.jsx(Se,{size:"small",className:"mt-2",onClick:()=>{x.refetch(),k.refetch()},children:_s()})]})]})]}),p.error&&l.jsxs("div",{className:"basis-full text-sm text-text",children:[l.jsx("p",{className:"mt-2 mb-0",children:p.error.message}),l.jsx(Se,{size:"small",className:"mt-2",onClick:()=>void p.refetch(),children:_s()})]})]}),s.github.enabled&&l.jsxs(l.Fragment,{children:[l.jsx("p",{className:"git-card-helper mt-3.5 mx-0 mb-0 text-sm leading-relaxed text-text",children:IBr()}),l.jsxs("div",{className:"flex flex-wrap gap-2 mt-3.5",children:[s.github.url&&l.jsxs(B_,{href:s.github.url,target:"_blank",rel:"noreferrer",children:[eA()," ",l.jsx(F_,{size:12})]}),l.jsx(Se,{disabled:a,onClick:()=>{i(!0),e$n(e.id).then(P=>{o(P.git),r(P.project)}).catch(P=>_(P instanceof Error?P.message:String(P))).finally(()=>i(!1))},children:a?g5r():F4r()})]})]})]}),d&&l.jsx("div",{className:"error",children:C(d)})]}):l.jsx("div",{className:"mt-4 min-h-22",role:"status","aria-label":wu(),"aria-busy":"true",children:l.jsxs("div",{"aria-hidden":"true",className:"motion-safe:animate-pulse",children:[l.jsxs("div",{className:"flex items-center gap-4",children:[l.jsx("div",{className:"h-4 w-16 rounded-xs bg-surface"}),l.jsx("div",{className:"h-6 w-24 rounded-full bg-surface"})]}),l.jsx("div",{className:"mt-3.5 h-8 w-48 rounded-xs bg-surface"})]})}):l.jsx("div",{className:Di,children:l.jsx("p",{className:Sa,children:TQr()})})})}const Hss={env:z4n,config:D4n,xdg:K4n,default:g4n},w4={preparing:Ykn,copying:Gwn,verifying:n5n,finalizing:tkn},qss=e=>{var r;return((r=w4[e])==null?void 0:r.call(w4))??e};function Uss(){var b;const e=eLn(),r=nt(e),t=r.data??null,n=t?null:((b=r.error)==null?void 0:b.message)??null,[s,o]=A.useState(""),[a,i]=A.useState(!1),[c,_]=A.useState(null),[d,f]=A.useState({kind:"idle"}),[p,m]=A.useState(null);A.useEffect(()=>{t&&o(S=>S||t.current)},[t]),A.useEffect(()=>hP(S=>{S.type==="progress"?f(C=>{const N=C.kind==="moving"?C.total:0;return{kind:"moving",phase:S.phase,copied:S.copiedBytes,total:S.totalBytes||N}}):S.type==="done"?(f({kind:"done",oldPathLeft:S.oldPathLeft}),_(null),o("")):S.type==="error"&&f({kind:"error",message:S.error})}),[]);const w=(t==null?void 0:t.source)==="env",y=s.trim(),v=t!==null&&y===t.current;async function x(){if(!(a||!y)){i(!0),m(null),_(null);try{_(await dOn(y))}catch(S){m(S instanceof Error?S.message:String(S))}finally{i(!1)}}}async function k(S){if(S.preventDefault(),!(d.kind==="moving"||!y||v)&&(m(null),!!window.confirm(xkn({path:Ae(y)})))){f({kind:"moving",phase:"preparing",copied:0,total:(c==null?void 0:c.treeBytes)??0});try{await hOn(y)}catch(C){f({kind:"idle"}),m(C instanceof Error?C.message:String(C))}}}return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:Ben()}),l.jsx("p",{className:"settings-sub mt-0 mx-0 mb-4.5 text-sm leading-relaxed text-subtext",children:Xin()}),n?l.jsx("div",{className:Di,children:l.jsx("div",{className:"error",children:n})}):t?l.jsxs("div",{className:Di,children:[l.jsx("div",{className:"settings-card-head mb-3",children:l.jsx("h3",{children:MPr()})}),l.jsxs("div",{className:t2,children:[l.jsx("span",{className:"k",children:KIr()}),l.jsx("span",{className:"v",children:t.current}),l.jsx("span",{className:"k",children:bI()}),l.jsx("span",{className:"v",children:Hss[t.source]()})]}),!w&&l.jsxs("form",{className:qC,onSubmit:k,children:[l.jsxs("label",{children:[iWr(),l.jsx("input",{className:"text-sm",type:"text",value:s,onChange:S=>{o(S.target.value),_(null)},placeholder:"/absolute/path/to/openresearch",autoComplete:"off",spellCheck:!1,disabled:d.kind==="moving"})]}),c&&!c.error&&c.ok&&l.jsxs("p",{className:Sa,children:[kZr()," ",du(c.treeBytes??0),c.freeBytes!=null&&` — ${_kn({size:Ae(du(c.freeBytes))})}`,c.sameFilesystem?i4n():"","."]}),c&&c.ok===!1&&c.error&&l.jsx("div",{className:"error",children:c.error}),p&&l.jsx("div",{className:"error",children:p}),d.kind==="moving"&&l.jsx(qU,{value:d.copied,max:d.total,label:qss(d.phase),caption:d.total>0?l.jsxs("span",{className:"text-sm",children:[du(d.copied)," / ",du(d.total)]}):void 0}),d.kind==="done"&&l.jsxs("p",{className:Sa,children:[FGr(),d.oldPathLeft&&l.jsxs(l.Fragment,{children:[" ",GMr({path:Ae(d.oldPathLeft)})]})]}),d.kind==="error"&&l.jsxs("div",{className:"error",children:[TGr()," ",d.message]}),l.jsxs("div",{className:"actions",children:[l.jsx(Se,{type:"button",onClick:x,disabled:a||!y||v||d.kind==="moving",children:a?Ea():FSr()}),l.jsx(Se,{variant:"primary",type:"submit",disabled:!y||v||d.kind==="moving",children:d.kind==="moving"?Fkn():Tkn()})]})]})]}):l.jsxs(ys,{children:[l.jsx($t,{})," ",wu()]})]})}const bj=e=>e==="running"||e==="starting";function Gss(e){return bj(e.status)?Lg(Date.now()-e.createdAt):e.endedAt?Lg(e.endedAt-e.createdAt):"—"}function JU({instances:e,emptyLabel:r}){return e.length===0?l.jsx("p",{className:"instances-empty m-0 rounded-lg border border-border bg-background py-3.5 px-4 text-base text-subtext",children:r}):l.jsx("div",{className:"instances-table-wrap overflow-x-auto",children:l.jsxs("table",{className:"runs-table w-full border-collapse bg-background text-base [&_th]:text-start [&_th]:text-text [&_th]:text-sm [&_th]:font-medium [&_th]:py-2 [&_th]:px-3 [&_th]:border-b [&_th]:border-b-border [&_th]:sticky [&_th]:top-0 [&_th]:bg-background [&_th]:z-1 [&_td]:py-2 [&_td]:px-3 [&_td]:border-b [&_td]:border-b-divider-faint [&_td]:whitespace-nowrap [&_tr:last-child_td]:border-b-0 [&_tr.clickable]:cursor-pointer [&_tr.clickable:hover_td]:bg-surface",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:uLr()}),l.jsx("th",{children:Op()}),l.jsx("th",{children:xen()}),l.jsx("th",{children:gJr()})]})}),l.jsx("tbody",{children:e.map(t=>{var s;const n=typeof((s=t.backend)==null?void 0:s.url)=="string"?t.backend.url:void 0;return l.jsxs("tr",{children:[l.jsx("td",{children:l.jsxs("span",{className:"backend-cell inline-flex items-center gap-0.5",children:[l.jsx(oC,{backend:t.backend}),n&&l.jsx($p,{size:"small",href:n,target:"_blank",rel:"noreferrer",title:JN(),"aria-label":JN(),onClick:o=>o.stopPropagation(),children:l.jsx(F_,{size:12})})]})}),l.jsx("td",{children:l.jsx(vu,{status:za(t)})}),l.jsx("td",{children:$i(t.createdAt)}),l.jsx("td",{children:Gss(t)})]},t.id)})})]})})}function Wss({projectId:e,onViewHistory:r}){var f;const t=nt({...hu(e??""),enabled:!!e,subscribed:!!e}),n=e?t.data??(t.error?[]:null):[],s=(f=t.error)==null?void 0:f.message,o=t.isFetching,[,a]=A.useState(0);A.useEffect(()=>{const p=setInterval(()=>a(m=>m+1),3e4);return()=>clearInterval(p)},[]);const i=()=>{e&&t.refetch()},c=(p,m)=>m.createdAt-p.createdAt,_=n==null?void 0:n.filter(p=>bj(p.status)).sort(c),d=n==null?void 0:n.filter(p=>!bj(p.status)).sort(c);return l.jsxs("section",{className:"compute-activity [&_.count-badge]:inline-flex [&_.count-badge]:items-center [&_.count-badge]:justify-center [&_.count-badge]:min-w-4.5 [&_.count-badge]:h-4.5 [&_.count-badge]:py-0 [&_.count-badge]:px-1 [&_.count-badge]:rounded-md [&_.count-badge]:bg-surface [&_.count-badge]:border [&_.count-badge]:border-border [&_.count-badge]:text-xs [&_.count-badge]:font-medium [&_.count-badge]:text-text mt-5.5 mx-0 mb-8",children:[l.jsxs("div",{className:"compute-activity-head flex items-start justify-between gap-5 mb-3.5 [&_h2]:flex [&_h2]:items-center [&_h2]:gap-2 [&_h2]:m-0 [&_h2]:text-lg [@media((max-width:_640px))]:items-stretch [@media((max-width:_640px))]:flex-col",children:[l.jsx("div",{children:l.jsxs("h2",{children:[iJr(),_&&_.length>0&&l.jsx("span",{className:"count-badge",children:_.length})]})}),l.jsxs("div",{className:"compute-activity-actions flex gap-2 flex-none [@media((max-width:_640px))]:justify-start",children:[l.jsxs(Se,{size:"small",onClick:i,disabled:o,children:[l.jsx(Fi,{size:12,className:o?"animate-[spin_0.9s_linear_infinite]":""})," ",I0()]}),l.jsx(Se,{size:"small",onClick:r,children:d!=null&&d.length?NAt({count:fr(d.length)}):bAt()})]})]}),s&&l.jsx("div",{className:"error",children:s}),!_||!d?l.jsxs(ys,{children:[l.jsx($t,{})," ",wu()]}):l.jsx(JU,{instances:_,emptyLabel:e?qNt():lAt()})]})}function Kss({projectId:e,onBack:r}){var c;const t=nt({...hu(e??""),enabled:!!e,subscribed:!!e}),n=e?t.data??(t.error?[]:null):[],s=(c=t.error)==null?void 0:c.message,o=t.isFetching,[,a]=A.useState(0);A.useEffect(()=>{const _=setInterval(()=>a(d=>d+1),3e4);return()=>clearInterval(_)},[]);const i=()=>{e&&t.refetch()};return l.jsxs(l.Fragment,{children:[l.jsxs("button",{type:"button",className:"settings-back inline-flex items-center gap-1.5 mt-0 mx-0 mb-4.5 text-subtext text-sm font-medium [&:hover]:text-text",onClick:r,children:[l.jsx(ty,{size:14})," ",cI()]}),l.jsxs("div",{className:"settings-head-row flex items-center justify-between gap-2.5 [&_h1]:m-0",children:[l.jsx("h1",{children:uqr()}),l.jsxs(Se,{size:"small",onClick:i,disabled:o,children:[l.jsx(Fi,{size:12,className:o?"animate-[spin_0.9s_linear_infinite]":""})," ",I0()]})]}),s&&l.jsx("div",{className:"error",children:s}),n?l.jsx(JU,{instances:[...n].sort((_,d)=>d.createdAt-_.createdAt),emptyLabel:e?MNt():JNt()}):l.jsxs(ys,{children:[l.jsx($t,{})," ",wu()]})]})}const eG=["projects","harnesses","storage"],Vss=[{id:"compute",label:lI,icon:l.jsx(YS,{size:16}),activeTabs:["compute","instances"]},{id:"environment",label:fI,icon:l.jsx(q_,{size:16}),activeTabs:["environment"]},{id:"settings",label:$S,icon:l.jsx(_x,{size:16}),activeTabs:["settings",...eG]}];function Qss(e){return eG.includes(e)}function Xss({tab:e,project:r,onProjectUpdate:t,onSelectTab:n,remote:s=!1}){const o=e==="settings"||Qss(e),a=A.useRef(null);return A.useLayoutEffect(()=>{const i=a.current,c=i==null?void 0:i.parentElement;if(!i||!c)return;const _=()=>i.scrollIntoView({block:"start"}),d=new ResizeObserver(_);d.observe(c),_();const f=()=>d.disconnect(),p=["wheel","touchstart","pointerdown","keydown"];for(const m of p)window.addEventListener(m,f,{passive:!0});return()=>{f();for(const m of p)window.removeEventListener(m,f)}},[e,r==null?void 0:r.id]),l.jsxs("div",{className:"settings-view max-w-readable my-0 mx-auto pt-6 px-8 pb-15 [&_h1]:mt-0 [&_h1]:mx-0 [&_h1]:mb-1.5 [&_h1]:text-3xl [&_>_.error]:text-accent-red [&_>_.error]:text-base [&_>_.error]:whitespace-pre-wrap [&_>_.error]:mt-0 [&_>_.error]:mx-0 [&_>_.error]:mb-3",children:[o&&l.jsxs(l.Fragment,{children:[l.jsx("h1",{children:$S()}),l.jsxs("div",{className:"settings-stack mt-4.5",children:[l.jsx("section",{className:Tf,children:l.jsx(Mss,{})}),l.jsx("section",{ref:e==="projects"?a:void 0,className:Tf,children:l.jsx(Iss,{remote:s,onProjectUpdate:t})}),l.jsx("section",{ref:e==="harnesses"?a:void 0,className:Tf,children:l.jsx(ass,{remote:s})}),l.jsx("section",{className:Tf,children:l.jsx(Bss,{})}),!s&&l.jsx("section",{ref:e==="storage"?a:void 0,className:Tf,children:l.jsx(Uss,{})}),l.jsx("section",{className:Tf,children:l.jsx(Lss,{})}),!s&&l.jsx("section",{className:Tf,children:l.jsx($ss,{})})]})]}),e==="compute"&&l.jsx(jss,{project:r,onViewHistory:()=>n("instances"),onOpenEnvironment:()=>n("environment"),remote:s}),e==="instances"&&l.jsx(Kss,{projectId:r==null?void 0:r.id,onBack:()=>n("compute")}),e==="environment"&&l.jsxs(l.Fragment,{children:[l.jsx("h1",{children:fI()}),l.jsx(Ass,{})]})]})}function n0(e){const r=e.split("@")[0].replace(/[~^]$/,"");return r.charAt(0).toUpperCase()+r.slice(1).replaceAll("-"," ")}function KC(e){return e.replace(/@personal$|\^$/,"@u").replace(/@project$|~$/,"@p")}function yj(e){return`${e.plugin?`${n0(e.plugin)}: `:""}${n0(e.name)}`}const tG=["plan","goal","new","resume","model","compact","copy","export","side"],Yss={plan:()=>rdr(),goal:()=>ID(),new:()=>VPt(),resume:()=>z5r(),model:()=>w$t(),compact:()=>Pst(),copy:()=>Ilt(),export:()=>o1t(),side:()=>ahn()};function Zss(e,r){const t=e==="compact"&&!r;return{name:e,disabled:t,get description(){return t?W7e():Yss[e]()},source:"command"}}function n2(e){return tG.some(r=>r===e)}const jy={clear:"new",summarize:"compact"};function xj(e){const r=e.toLowerCase();return n2(r)?r:Object.hasOwn(jy,r)?jy[r]:null}function rG(e){return Object.keys(jy).filter(r=>jy[r]===e)}function Jss(e,r){return e.name.toLowerCase().startsWith(r)||e.plugin&&`${e.plugin}:${e.name}`.toLowerCase().startsWith(r)?!0:e.source==="command"&&n2(e.name)&&rG(e.name).some(t=>t.startsWith(r))}function k4(e,r){if(r<0||r>e.length)return null;let t=r;for(;t>0&&!/\s/.test(e[t-1]);)t-=1;if(e[t]!=="/")return null;let n=r;for(;nl.jsx(l.Fragment,{children:e})};function Yns({children:e}){return l.jsx("figure",{className:"my-6 mx-auto max-w-full text-left [&_img]:mx-auto [&_img]:my-0 [&_img]:w-auto [&_img]:h-auto [&_img]:max-h-[min(480px,60vh)] [&_img]:object-contain [&_img]:border-0 [&_img]:rounded-none",children:e})}const Zns={figure:({children:e})=>l.jsx(Yns,{children:e}),figcaption:({children:e})=>l.jsx("figcaption",{className:"mt-3 text-sm italic leading-relaxed text-text",children:e}),th:({node:e,...r})=>l.jsx("th",{dir:"auto",...r}),td:({node:e,...r})=>l.jsx("td",{dir:"auto",...r})},xc=A.memo(function({text:r,onOpenFile:t,onOpenRun:n,resolveFilePath:s,resolveImageSrc:o,predict:a=!1}){Cu();const i=A.useContext(IU),c=o??i,_=A.useMemo(()=>function({node:p,src:m,alt:w,className:y,...v}){var b,S,C;const x=A.useMemo(()=>typeof m=="string"&&m?(c==null?void 0:c(m))??[{url:m,resolveAsset:()=>null}]:[],[m,c]),k=(b=x[0])==null?void 0:b.url;return k?c&&((S=py(m))!=null&&S.path.match(/\.html?$/i))?l.jsx(Pns,{candidates:x,name:w||m},k):A.createElement(qns,{...v,key:k,downloadName:(C=m.split(/[\\/]/).pop())==null?void 0:C.split(/[?#]/)[0],sources:x.map(N=>N.url),alt:w??"",loading:"lazy",className:`block max-w-full h-auto my-3 rounded-sm border border-border cursor-zoom-in focus-visible:outline-2 focus-visible:outline-focus ${y??""}`}):null},[c]),d=A.useMemo(()=>({"image-carousel":({children:f})=>l.jsx(Bns,{children:f}),"file-mention":f=>{const p=G3(f.path),m=f.lines&&nYn(f.lines)||p.line;return l.jsx(VM,{path:p.path,line:m,exp:f.exp,onOpenFile:t})},"run-mention":f=>l.jsx(Vns,{id:f.id,label:f.label,onOpenRun:n}),a:({node:f,href:p,children:m,"data-figure-src":w,"data-cited-href":y,...v})=>{const x=typeof w=="string"?py(w):null;if(x&&t){const S=x.source==="artifact"?`artifacts/${x.path}`:x.path,C=s?s(eYn(S)):S;if(C)return l.jsx("button",{type:"button",className:"file-link cursor-pointer text-start",...pn(N=>t(C,void 0,void 0,void 0,N)),children:m})}const k=typeof y=="string"?y:p,b=k?G3(k):null;if(b&&Xns(b.path)){const S=tYn(b.path,s);return S&&t?l.jsx(VM,{path:S,line:b.line,onOpenFile:t}):l.jsx("span",{children:m})}return p?l.jsx("a",{href:p,target:"_blank",rel:"noopener noreferrer",...v,children:m}):l.jsx("span",{children:m})},...Zns,img:_,...HU}),[t,n,s,_]);return l.jsx("div",{dir:"auto","data-streaming":a||void 0,className:"md min-w-0 wrap-anywhere text-text leading-relaxed [&_>_*:first-child]:mt-0 [&_>_*:last-child]:mb-0 [&_p]:my-2.5 [&_p]:mx-0 [&_strong]:text-text [&_strong]:font-semibold [&_pre]:bg-surface [&_pre]:border [&_pre]:border-border-muted [&_pre]:rounded-md [&_pre]:py-2 [&_pre]:px-3 [&_pre]:overflow-x-auto [&_pre]:text-sm [&_pre]:text-text [&_code]:font-mono [&_code]:text-sm [&_code]:font-normal [&_code]:text-text [&_code]:bg-surface [&_code]:border [&_code]:border-border-variant [&_code]:rounded-xs [&_code]:py-px [&_code]:px-1 [&_.katex]:text-prose-emphasis [&_.katex-display]:my-3 [&_.katex-display]:mx-0 [&_.katex-display]:overflow-x-auto [&_.katex-display]:overflow-y-hidden [&_.katex-display]:py-0.5 [&_.katex-display]:px-0 [&_.file-chip]:inline-flex [&_.file-chip]:items-center [&_.file-chip]:gap-1 [&_.file-chip]:max-w-full [&_.file-chip]:my-0 [&_.file-chip]:mx-px [&_.file-chip]:py-0 [&_.file-chip]:px-1.5 [&_.file-chip]:align-baseline [&_.file-chip]:font-mono [&_.file-chip]:text-sm [&_.file-chip]:font-medium [&_.file-chip]:text-text [&_.file-chip]:bg-panel [&_.file-chip]:border [&_.file-chip]:border-border-variant [&_.file-chip]:rounded-xs [&_.file-chip]:cursor-pointer [&_.file-chip:hover:not(:disabled)]:bg-surface [&_.file-chip_svg]:flex-none [&_.file-chip_svg]:opacity-60 [&_.file-chip-label]:min-w-0 [&_.file-chip-label]:overflow-hidden [&_.file-chip-label]:text-ellipsis [&_.file-chip-label]:whitespace-nowrap [&_.run-chip_svg]:opacity-100 [&_.run-chip_svg]:text-subtext [&_pre_code]:bg-none [&_pre_code]:bg-transparent [&_pre_code]:border-0 [&_pre_code]:text-inherit [&_pre_code]:p-0 [&_pre_code]:font-normal [&_h1]:text-text [&_h1]:text-prose-emphasis [&_h1]:font-semibold [&_h1]:mt-3 [&_h1]:mx-0 [&_h1]:mb-1.5 [&_h2]:text-text [&_h2]:text-prose-emphasis [&_h2]:font-semibold [&_h2]:mt-3 [&_h2]:mx-0 [&_h2]:mb-1.5 [&_h3]:text-text [&_h3]:text-prose-emphasis [&_h3]:font-semibold [&_h3]:mt-3 [&_h3]:mx-0 [&_h3]:mb-1.5 [&_h4]:text-text [&_h4]:text-prose-emphasis [&_h4]:font-semibold [&_h4]:mt-3 [&_h4]:mx-0 [&_h4]:mb-1.5 [&_ul]:my-1.5 [&_ul]:mx-0 [&_ul]:ps-5.5 [&_ol]:my-1.5 [&_ol]:mx-0 [&_ol]:ps-5.5 [&_li::marker]:text-text [&_table]:border-collapse [&_table]:block [&_table]:w-max [&_table]:max-w-full [&_table]:text-sm [&_table]:my-2.5 [&_table]:mx-0 [&_table]:border [&_table]:border-border [&_table]:rounded-md [&_table]:overflow-x-auto [&_th]:border-b [&_th]:border-b-border-variant [&_th]:py-2 [&_th]:px-3.5 [&_th]:text-start [&_th]:text-text [&_th]:break-normal [&_th]:break-words [&_td]:border-b [&_td]:border-b-border-variant [&_td]:py-2 [&_td]:px-3.5 [&_td]:text-start [&_td]:text-text [&_td]:break-normal [&_td]:break-words [&_tr:last-child_td]:border-b-0 [&_thead_th]:bg-surface [&_thead_th]:font-medium [&_thead_th]:text-text [&_thead_th]:border-b [&_thead_th]:border-b-border [&_tbody_tr:hover_td]:bg-surface [&_blockquote]:my-1.5 [&_blockquote]:mx-0 [&_blockquote]:pt-0.5 [&_blockquote]:pe-0 [&_blockquote]:pb-0.5 [&_blockquote]:ps-2.5 [&_blockquote]:border-s-[3px] [&_blockquote]:border-s-border [&_blockquote]:text-subtext [:is(&,_.openresearch-diff,_.file-view)_.token.comment]:italic [:is(&,_.openresearch-diff,_.file-view)_.token.prolog]:italic [:is(&,_.openresearch-diff,_.file-view)_.token.cdata]:italic [:is(&,_.openresearch-diff,_.file-view)_.token.operator]:text-syntax-cyan [:is(&,_.openresearch-diff,_.file-view)_.token.entity]:text-syntax-cyan [:is(&,_.openresearch-diff,_.file-view)_.token.url]:text-syntax-cyan [:is(&,_.openresearch-diff,_.file-view)_.token.comment]:text-syntax-comment [:is(&,_.openresearch-diff,_.file-view)_.token.prolog]:text-syntax-comment [:is(&,_.openresearch-diff,_.file-view)_.token.cdata]:text-syntax-comment [:is(&,_.openresearch-diff,_.file-view)_.token.punctuation]:text-syntax-text [:is(&,_.openresearch-diff,_.file-view)_.token.property]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.tag]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.deleted]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.constant]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.symbol]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.boolean]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.number]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.selector]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.attr-name]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.char]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.inserted]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.string]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.builtin]:text-syntax-yellow [:is(&,_.openresearch-diff,_.file-view)_.token.atrule]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.attr-value]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.keyword]:text-syntax-purple [:is(&,_.openresearch-diff,_.file-view)_.token.function]:text-syntax-blue [:is(&,_.openresearch-diff,_.file-view)_.token.decorator]:text-syntax-blue [:is(&,_.openresearch-diff,_.file-view)_.token.def]:text-syntax-blue [:is(&,_.openresearch-diff,_.file-view)_.token.class-name]:text-syntax-yellow [:is(&,_.openresearch-diff,_.file-view)_.token.namespace]:text-syntax-yellow [:is(&,_.openresearch-diff,_.file-view)_.token.regex]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.important]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.variable]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.parameter]:text-syntax-text",children:l.jsx(MZn,{content:LU(r,{predictMath:a}),processor:Qns,components:d,predict:a})})}),QM="prompt-actions plan-strip-actions flex flex-wrap justify-end gap-x-2 gap-y-1.5";function Jns({synthesized:e,agentLabel:r,onView:t,onApprove:n,showResumeModes:s,onReject:o,onRevise:a}){const[i,c]=A.useState(!1),_=A.useRef(null),[d,f]=A.useState(!1),[p,m]=A.useState(""),w=A.useRef(null);A.useEffect(()=>{if(!i)return;const v=x=>{_.current&&!_.current.contains(x.target)&&c(!1)};return window.addEventListener("pointerdown",v),()=>window.removeEventListener("pointerdown",v)},[i]),A.useEffect(()=>{var v;d&&((v=w.current)==null||v.focus())},[d]);const y=()=>{a(p.trim()||"no specific feedback — use your judgment"),m(""),f(!1)};return l.jsxs("div",{className:"plan-strip relative w-full mt-0 mx-0 mb-2.5 py-3 px-3.5 flex flex-col items-stretch gap-2.5 border border-accent-blue-border rounded-lg bg-accent-blue-subtle",children:[l.jsxs("div",{className:"plan-strip-info flex items-baseline gap-2 min-w-0",children:[l.jsx(ux,{size:14,className:"plan-strip-icon text-accent-blue shrink-0 self-center"}),l.jsx("span",{dir:"auto",className:"plan-strip-title text-sm font-semibold whitespace-nowrap",children:e?Zdr({agent:Ae(r)}):Hdr({agent:Ae(r)})}),l.jsx("button",{className:"plan-strip-open ms-auto p-0 border-0 bg-none bg-transparent text-accent-blue text-sm cursor-pointer whitespace-nowrap shrink-0 [&:hover]:underline",...pn(t),children:zhr()})]}),d?l.jsxs(l.Fragment,{children:[l.jsx("textarea",{dir:"auto",writingsuggestions:"false",ref:w,className:"plan-strip-revise-input w-full resize-none border border-border rounded-md py-2 px-3 text-sm font-[inherit] bg-background text-text [&:focus]:border-focus-border",placeholder:dpr(),rows:2,value:p,onChange:v=>m(v.target.value),onKeyDown:v=>{if(v.nativeEvent.isComposing||v.nativeEvent.keyCode===229){v.stopPropagation();return}v.key==="Escape"?(v.preventDefault(),m(""),f(!1)):v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),y())}}),l.jsxs("div",{className:QM,children:[l.jsx(Se,{size:"small",onClick:()=>{m(""),f(!1)},children:tI()}),l.jsx("span",{className:"plan-strip-spacer flex-1"}),l.jsxs(Se,{size:"small",variant:"primary",onClick:y,children:[Khr(),l.jsx(XP,{size:14})]})]})]}):l.jsxs("div",{className:QM,children:[l.jsx(Se,{size:"small",onClick:o,children:Dhr()}),l.jsx(Se,{size:"small",onClick:()=>f(!0),children:npr()}),l.jsx("span",{className:"plan-strip-spacer flex-1"}),s?l.jsxs("div",{className:"plan-strip-approve relative flex",ref:_,children:[l.jsx(Se,{size:"small",variant:"primary",className:"rounded-e-none",onClick:()=>n("auto"),children:fdr()}),l.jsx(Se,{size:"small",variant:"primary",className:"rounded-s-none border-s-plan-caret px-1.5","aria-label":ghr(),onClick:()=>c(v=>!v),children:l.jsx(kc,{size:14})}),i&&l.jsx("div",{className:"plan-strip-menu absolute end-0 bottom-[calc(100%_+_4px)] flex min-w-47.5 flex-col rounded-md border border-border bg-background p-1 shadow-menu z-6",children:l.jsx(cr,{onClick:()=>{c(!1),n("bypassPermissions")},children:wdr()})})]}):l.jsx(Se,{size:"small",variant:"primary",onClick:()=>n(),children:Rdr()})]})]})}const XM="mb-2.5 rounded-lg border border-border bg-accent-green-subtle px-3 py-2.5 text-sm text-text";function YM({item:e,onOpenRun:r,className:t=""}){const{run:n,experimentName:s}=e;return r?l.jsx("button",{className:`tool-target experiment-run-link ${t}`,...pn(o=>r(n.id,o)),children:s||n.experimentId}):l.jsx("span",{className:t,children:s||n.experimentId})}function ess({runs:e,onOpenRun:r}){const t=e[0];return t?e.length===1?l.jsxs("div",{role:"status",className:`${XM} flex items-center gap-2`,children:[l.jsx(H_,{size:16,className:"shrink-0 text-accent-green","aria-hidden":"true"}),l.jsx("span",{className:"shrink-0 font-medium",children:t.run.cancelRequested?i8e():t.run.status==="starting"?C8e():E5()}),l.jsx("span",{"aria-hidden":"true",children:"·"}),l.jsx(YM,{item:t,onOpenRun:r,className:"min-w-0 truncate"})]}):l.jsxs("details",{className:`${XM} [&[open]_.experiment-chevron]:rotate-90`,children:[l.jsxs("summary",{className:"flex cursor-pointer list-none items-center gap-2 rounded-sm focus-visible:outline-2 focus-visible:outline-focus [&::-webkit-details-marker]:hidden",children:[l.jsx(H_,{size:16,className:"shrink-0 text-accent-green","aria-hidden":"true"}),l.jsx("span",{className:"font-medium",children:W8e({count:e.length})}),l.jsx(mo,{size:14,className:"experiment-chevron ms-auto shrink-0 text-subtext","aria-hidden":"true"})]}),l.jsx("div",{className:"mt-2 max-h-48 overflow-y-auto ps-6 leading-relaxed",children:e.map((n,s)=>l.jsxs("span",{children:[s>0&&l.jsx("span",{className:"text-subtext",children:" · "}),l.jsx(YM,{item:n,onOpenRun:r})]},n.run.id))})]}):null}function ZM({save:e,onSaved:r,placeholder:t,createHref:n,createLabel:s}){const[o,a]=A.useState(""),[i,c]=A.useState(!1),[_,d]=A.useState(null);async function f(p){if(p.preventDefault(),!(i||!o.trim())){c(!0),d(null);try{r(await e(o.trim())),a("")}catch(m){d(m instanceof Error?m.message:String(m))}finally{c(!1)}}}return l.jsxs("form",{className:"onb-token-form flex items-center flex-wrap gap-2 mt-2 [&_input]:flex-1 [&_input]:min-w-55 [&_input]:text-sm [&_a]:text-sm [&_a]:text-subtext [&_a]:whitespace-nowrap [&_.error]:basis-full [&_.error]:text-accent-red [&_.error]:text-sm [&_.error]:whitespace-pre-wrap",onSubmit:f,children:[l.jsx("input",{type:"password",value:o,onChange:p=>a(p.target.value),placeholder:t,autoComplete:"off"}),l.jsx(Se,{type:"submit",disabled:i||!o.trim(),children:i?Pi():Ii()}),l.jsx("a",{href:n,target:"_blank",rel:"noreferrer",children:s??s6t()}),_&&l.jsx("div",{className:"error",children:_})]})}function qU({value:e,max:r,label:t,caption:n,fillColor:s}){const o=r>0?Math.min(100,Math.round(e/r*100)):0;return l.jsxs("div",{className:"progress mt-3 mx-0 mb-1",role:"progressbar","aria-valuenow":o,"aria-valuemin":0,"aria-valuemax":100,children:[l.jsx("div",{className:"progress-track h-2 rounded-full bg-panel border border-border overflow-hidden",children:l.jsx("div",{className:"progress-fill h-full bg-subtext rounded-full transition-[width] duration-200 ease-standard",style:{width:`${o}%`,background:s}})}),(t!==void 0||n!==void 0)&&l.jsxs("div",{className:"progress-caption flex justify-between mt-1.5 text-sm text-muted",children:[l.jsx("span",{children:t??`${o}%`}),n]})]})}function tss({settings:e}){const[r,t]=A.useState(!1);return l.jsxs("label",{className:"inline-flex max-w-full flex-wrap items-center gap-2 text-sm text-subtext",children:[Exn(),l.jsx("span",{className:"inline-block w-max max-w-full",children:l.jsx(ea,{variant:"field",dropDown:!0,value:e.defaultHost??"",disabled:r,choices:[{id:"",label:pI()},...e.defaultHost&&!e.hosts.some(n=>n.host===e.defaultHost)?[{id:e.defaultHost,label:e.defaultHost}]:[],...e.hosts.map(n=>({id:n.host,label:n.host}))],onSelect:n=>{t(!0),gOn(n||null).catch(s=>{Kt(s instanceof Error?s.message:String(s),"error")}).finally(()=>t(!1))}})})]})}function rss({host:e,connecting:r,reference:t,onChange:n}){const s=A.useId(),o=pr({mutationFn:mOn,scope:{id:`ssh-settings-${e.host}`}});function a(i){n(i),o.reset(),!(i!==null&&!i.trim())&&o.mutate({host:e.host,container:(i==null?void 0:i.trim())??null})}return l.jsxs("details",{className:"pb-3",children:[l.jsx("summary",{className:"w-fit cursor-pointer rounded-sm text-sm text-subtext focus-visible:outline-2 focus-visible:outline-focus",children:GD()}),l.jsxs("div",{className:"mt-3 grid max-w-xl gap-3",children:[l.jsxs("label",{className:"text-sm text-subtext",children:[s2n(),l.jsx(ea,{variant:"field",dropDown:!0,value:t!==null?"container":"host",disabled:r,choices:[{id:"host",label:Ixn()},{id:"container",label:Vxn()}],onSelect:i=>a(i==="container"?"":null)})]}),t!==null&&l.jsxs("label",{className:"text-sm text-subtext",htmlFor:`${s}-container`,children:[vxn(),l.jsx(yn,{id:`${s}-container`,value:t,disabled:r,required:!0,onChange:i=>a(i.target.value)})]}),o.error&&l.jsx("p",{className:"m-0 text-sm text-accent-red",role:"status",children:o.error.message})]})]})}const Di=["settings-card [&_>_.error]:text-accent-red [&_>_.error]:text-base","[&_>_.error]:whitespace-pre-wrap bg-background border border-border","rounded-lg py-4 px-4.5 mb-4 [&_h3]:mt-0 [&_h3]:mx-0 [&_h3]:mb-2.5","[&_h3]:text-base [&_h3]:font-semibold [&_h3]:text-text","[&_.settings-sub]:mb-3 [&_.kv]:gap-y-1.5 [&_.kv]:gap-x-4.5","[&_>_.project-default-row:first-child]:pt-0 [&_>_.project-default-row:first-child]:border-t-0"].join(" "),t2=["kv grid grid-cols-[auto_1fr] items-baseline gap-y-1 gap-x-3.5 text-base","[&_.k]:text-sm [&_.k]:text-subtext [&_.v]:text-base [&_.v]:text-text","[&_.v]:break-all"].join(" "),nss=["grid grid-cols-[9rem_minmax(0,1fr)] items-center gap-x-5 gap-y-2.5 font-sans text-base text-text","[&_.k]:font-medium [&_.k]:text-sm [&_.k]:text-text","[&_.v]:min-w-0 [&_.v]:flex [&_.v]:items-center [&_.v]:flex-wrap [&_.v]:gap-2","[&_.v]:font-sans [&_.v]:text-base [&_.v]:text-text [&_.v]:break-words"].join(" "),Z0="mt-3 mx-0 mb-0 ps-3 border-s-2 border-s-accent-red font-sans text-base leading-relaxed text-text whitespace-pre-wrap",Sa=["settings-note mt-2.5 mx-0 mb-0 text-base py-2 px-2.5","border border-accent-amber rounded-md bg-accent-amber-subtle","text-accent-amber font-medium"].join(" "),qC=["form font-sans text-sm text-text [&_.form-seg]:self-start [&_.form-seg]:mb-0.5","[&_.form-seg_button]:py-[5px] [&_.form-seg_button]:px-3","[&_.repo-hint]:font-normal [&_.repo-hint]:text-sm","[&_.repo-hint]:text-muted [&_.repo-hint.ok]:text-accent-teal","[&_.folder-picker-control]:flex [&_.folder-picker-control]:items-center","[&_.folder-picker-control]:gap-2 [&_.folder-picker-control]:w-full","[&_.folder-picker-control]:min-w-0 [&_.folder-picker-control]:py-2 [&_.folder-picker-control]:px-2.5","[&_.folder-picker-control]:overflow-hidden [&_.folder-picker-control]:bg-background","[&_.folder-picker-control]:border [&_.folder-picker-control]:border-border","[&_.folder-picker-control]:rounded-md [&_.folder-picker-control]:cursor-pointer","[&_.folder-picker-control]:text-start","[&_.folder-picker-control]:transition-[border-color,box-shadow] [&_.folder-picker-control]:duration-120 [&_.folder-picker-control]:ease-standard","[&_.folder-picker-control:hover:not(:disabled)]:border-muted","[&_.folder-picker-control:hover:not(:disabled)]:shadow-control-subtle","[&_.folder-picker-control:focus-visible]:outline-2 [&_.folder-picker-control:focus-visible]:outline-solid [&_.folder-picker-control:focus-visible]:outline-focus","[&_.folder-picker-control:focus-visible]:outline-offset-2 [&_.folder-picker-control_span]:flex-1","[&_.folder-picker-control_span]:min-w-0 [&_.folder-picker-control_span]:overflow-hidden","[&_.folder-picker-control_span]:text-ellipsis [&_.folder-picker-control_span]:whitespace-nowrap","[&_.folder-picker-control_.placeholder]:text-muted [&_.folder-picker-icon]:flex-none","[&_.folder-picker-icon]:text-current [&_.folder-picker-chevron]:flex-none","[&_.folder-picker-chevron]:text-muted","[&_.folder-picker-control:hover:not(:disabled)_.folder-picker-chevron]:text-subtext","[&_.folder-picker-hint]:text-subtext [&_.folder-picker-hint]:text-sm","[&_.folder-picker-hint]:font-normal [&_.folder-picker-hint]:leading-snug","[&_.project-location-field]:flex [&_.project-location-field]:flex-col","[&_.project-location-field]:gap-2 [&_.project-location-label]:text-text","[&_.project-location-label]:text-base","[&_.project-location-label]:font-medium [&_.project-field-label]:text-text","[&_.project-field-label]:text-base [&_.project-field-label]:font-medium","[&_.folder-picker-control:disabled]:cursor-default [&_.folder-picker-control:disabled]:opacity-65","[&_.paper-destination]:flex [&_.paper-destination]:items-center","[&_.paper-destination]:gap-2.5 [&_.paper-destination]:pt-2 [&_.paper-destination]:pe-2 [&_.paper-destination]:pb-2 [&_.paper-destination]:ps-3","[&_.paper-destination]:border [&_.paper-destination]:border-border [&_.paper-destination]:rounded-md","[&_.paper-destination]:bg-background [&_.paper-destination_code]:flex-1","[&_.paper-destination_code]:min-w-0 [&_.paper-destination_code]:overflow-hidden","[&_.paper-destination_code]:text-text [&_.paper-destination_code]:text-sm","[&_.paper-destination_code]:font-normal","[&_.paper-destination_code]:text-ellipsis [&_.paper-destination_code]:whitespace-nowrap","[&_.paper-destination_.btn]:flex-none [&_.project-path-notice]:py-2 [&_.project-path-notice]:px-3","[&_.project-path-notice]:border [&_.project-path-notice]:border-border-variant","[&_.project-path-notice]:rounded-sm [&_.project-path-notice]:bg-surface","[&_.project-path-notice]:text-base [&_.project-path-notice]:text-text","[&_.project-path-notice]:leading-snug","[&_.project-path-notice.error]:border-danger-notice-border","[&_.paper-results]:flex [&_.paper-results]:flex-col","[&_.paper-results]:border [&_.paper-results]:border-border [&_.paper-results]:rounded-md","[&_.paper-results]:max-h-60 [&_.paper-results]:overflow-y-auto","[&_.paper-results_button]:flex [&_.paper-results_button]:flex-col","[&_.paper-results_button]:items-start [&_.paper-results_button]:gap-0.5","[&_.paper-results_button]:py-2 [&_.paper-results_button]:px-2.5 [&_.paper-results_button]:bg-none [&_.paper-results_button]:bg-transparent","[&_.paper-results_button]:border-0","[&_.paper-results_button]:border-b [&_.paper-results_button]:border-b-border-variant","[&_.paper-results_button]:text-start [&_.paper-results_button]:[font:inherit]","[&_.paper-results_button]:text-text [&_.paper-results_button]:cursor-pointer","[&_.paper-results_button:last-child]:border-b-0","[&_.paper-results_button:hover]:bg-surface [&_.paper-results_.title]:text-sm","[&_.paper-results_.title]:font-medium","[&_.paper-results_.id]:text-xs [&_.paper-results_.id]:text-muted","[&_.paper-pick_.id]:text-xs","[&_.paper-pick_.id]:text-muted [&_.paper-pick]:flex [&_.paper-pick]:items-center","[&_.paper-pick]:justify-between [&_.paper-pick]:gap-2.5 [&_.paper-pick]:py-2.5 [&_.paper-pick]:px-3","[&_.paper-pick]:border [&_.paper-pick]:border-border [&_.paper-pick]:rounded-md","[&_.paper-pick]:bg-surface [&_.paper-pick_.meta]:min-w-0","[&_.paper-pick_.title]:text-sm [&_.paper-pick_.title]:font-medium","flex flex-col gap-2.5 [&_label]:flex [&_label]:flex-col","[&_label]:gap-1 [&_label]:text-sm [&_label]:text-text","[&_label]:font-medium [&_.row2]:grid [&_.row2]:grid-cols-2","[&_input]:font-sans [&_input]:text-sm [&_input]:font-normal [&_input]:text-text [&_input::placeholder]:text-subtext","[&_select]:font-sans [&_select]:text-sm [&_select]:font-normal [&_select]:text-text","[&_.row2]:gap-2.5 [&_.actions]:flex [&_.actions]:justify-end","[&_.actions]:gap-2.5 [&_.actions]:mt-1.5 [&_.new-project-actions]:justify-start","[&_.new-project-actions]:mt-2.5","[&_.error]:text-accent-red [&_.error]:text-base [&_.error]:whitespace-pre-wrap","settings-form mt-3.5 pt-3.5 border-t border-t-border"].join(" "),R_=["project-default-row flex items-center justify-between gap-6 [.project-default-row+&]:mt-3.5","pt-3.5 border-t border-t-border-variant [&_p]:mt-1 [&_p]:mx-0 [&_p]:mb-0","[&_.project-default-title]:text-base [&_p]:text-sm [&_p]:leading-relaxed [&_p]:text-text"].join(" "),Tf=["settings-stack-section [&_+_.settings-stack-section]:mt-6 [&_>_:last-child]:mb-0","[&_>_h2]:mt-0 [&_>_h2]:mx-0 [&_>_h2]:mb-1.5 [&_>_h2]:text-xl"].join(" "),sss=new Set(["gh auth login","hf auth login","claude auth status"]);function UU(e){return sss.has(e)?`/api/settings/commands/run?command=${encodeURIComponent(e)}`:void 0}function UC(){const[e,r]=A.useState(null);return{run:e,start:(n,s,o)=>r(a=>({command:n,path:s,owner:o,attempt:((a==null?void 0:a.attempt)??0)+1})),clear:()=>r(null)}}function GC({note:e,className:r,disabled:t,resolve:n=UU,onRun:s}){return e?l.jsx("p",{className:r,children:U_(e,{canRun:o=>!t&&n(o)!==void 0,onRun:o=>{const a=n(o);a&&s(o,a)}})}):null}function WC({run:e,onComplete:r,onClose:t}){return e?l.jsx(dB,{path:e.path,label:e.command,onComplete:r,onError:n=>Kt(n,"error"),onClose:t},`${e.command}-${e.attempt}`):null}function Lv(e){return e.catalogPending?{cls:"warn",variant:"warning",label:dd()}:e.authCheckFailed?{cls:"warn",variant:"warning",label:Wb()}:e.id.startsWith("acp:")&&e.authState==="needsLogin"?{cls:"warn",variant:"warning",label:uD()}:e.id.startsWith("acp:")&&e.authState==="ready"?{cls:"ok",variant:"success",label:_D()}:e.agentReady&&!e.authenticated&&e.authMethod!=="local"?{cls:"warn",variant:"warning",label:WD()}:e.agentReady?{cls:"ok",variant:"success",label:e.authMethod==="thirdParty"||H0(e)?D0():e.authMethod==="local"?AS():WJr()}:e.installed?e.installBroken?{cls:"warn",variant:"warning",label:$Hr()}:e.authMethod==="local"?{cls:"warn",variant:"warning",label:KD()}:e.needsConfigRepair||e.authState==="unknown"?{cls:"warn",variant:"warning",label:Wb()}:e.authState==="unsupported"?{cls:"warn",variant:"warning",label:Brn()}:{cls:"warn",variant:"warning",label:mI()}:{cls:"warn",variant:"warning",label:DVr()}}function oss({h:e}){if(e.id==="opencode"&&e.agentReady&&!e.authenticated&&!e.authMethod)return l.jsx(l.Fragment,{children:o8r()});const r=H0(e);return r?l.jsx(l.Fragment,{children:r}):e.authMethod?e.authMethod==="local"?l.jsx(l.Fragment,{children:P5()}):e.authMethod==="thirdParty"?l.jsx(l.Fragment,{children:kI()}):l.jsx(l.Fragment,{children:e.authMethod==="oauth"?$Mr():Jy()}):l.jsx(l.Fragment,{children:"—"})}function GU(e,r,t){if(!r)return;const n=r.installUrl!==void 0&&t.includes(r.installUrl),s=t===r.login?"login":t===r.install?"install":t===r.update?"update":n?"install":null;if(s&&!(s!=="install"&&(!e.installed||e.installBroken)))return`/api/harnesses/setup?${new URLSearchParams({harness:e.id,action:s,shell:"true"})}`}function ass({remote:e}){var N,T;const r=hl(),{data:t=null}=nt(r),[n,s]=A.useState(null),[o,a]=A.useState(!1),i=UC(),[c,_]=A.useState(null),[d,f]=A.useState(null),p=nt(HS()),m=nt({queryKey:kt("getAcpHarnesses"),queryFn:o$n}),[w,y]=A.useState(null),v=()=>{m.refetch(),k(!0)},x=async E=>{try{await c$n(E),v()}catch(R){Kt(R instanceof Error?R.message:String(R),"error")}},k=(E,R=!1)=>{a(!0),I_(E,R).catch(()=>{}).finally(()=>a(!1))},b=[...t??[]].sort((E,R)=>Number(R.agentReady)-Number(E.agentReady)),S=b.find(E=>E.id===n)??b[0];A.useEffect(()=>{S&&n!==S.id&&!b.some(E=>E.catalogPending)&&s(S.id)},[S,n,b]);const C=(N=m.data)==null?void 0:N.find(E=>E.id===(S==null?void 0:S.id));return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:H5()}),w&&l.jsx(IB,{definition:w==="new"?void 0:w,onClose:()=>y(null),onSaved:v}),d&&l.jsx(NB,{remote:e,harness:d,onClose:()=>f(null)}),!e&&c&&p.data&&l.jsx(PB,{harness:c,commands:p.data[c.id],onClose:()=>_(null)}),l.jsxs("div",{className:"mt-3 mb-3.5 flex w-full flex-wrap items-center justify-between gap-3 [&_.option-menu]:w-max",children:[l.jsx("div",{className:"w-96 max-w-full",children:l.jsx(ea,{variant:"field",dropDown:!0,title:H5(),choices:b.map(E=>({id:E.id,label:E.name})),value:(S==null?void 0:S.id)??null,onSelect:E=>{const R=b.find($=>$.id===E);R&&s(R.id)},renderIcon:E=>{const R=b.find($=>$.id===E.id);return R&&l.jsx(gd,{harness:R.id,logo:R.logo})},renderLabel:E=>{const R=b.find(L=>L.id===E.id),$=R&&Lv(R);return l.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[E.label,$&&l.jsxs(l.Fragment,{children:[l.jsx("span",{"aria-hidden":"true",className:`size-1.5 shrink-0 rounded-full bg-muted [&.ok]:bg-accent-green [&.err]:bg-accent-red [&.warn]:bg-accent-amber ${$.cls}`}),l.jsx("span",{className:"sr-only",children:$.label})]})]})}})}),l.jsxs(Se,{className:"ms-auto shrink-0",onClick:()=>y("new"),"aria-haspopup":"dialog",children:[l.jsx(Bi,{size:14}),gS()]})]}),t?S?l.jsxs("div",{className:Di,children:[l.jsxs("div",{className:"settings-card-head flex items-center gap-2.5 mb-3",children:[S.id.startsWith("acp:")&&l.jsx("span",{className:"text-sm text-subtext",children:pD()}),l.jsx(tr,{variant:Lv(S).variant,children:S.adapterMissing?lD():Lv(S).label}),l.jsx("div",{className:"spacer flex-1"}),!e&&S.adapterMissing&&l.jsxs(Se,{size:"small",onClick:()=>_(S),disabled:!((T=p.data)!=null&&T[S.id]),"aria-haspopup":"dialog",children:[l.jsx(q_,{size:14}),Bb()]}),S.id.startsWith("acp:")&&!S.adapterMissing&&!S.agentReady&&!S.catalogPending&&l.jsx(Se,{size:"small",onClick:()=>f(S),"aria-haspopup":"dialog",children:Lv(S).label}),C&&l.jsxs(l.Fragment,{children:[l.jsx(Se,{size:"small",onClick:()=>y(C),children:vS()}),l.jsx(Se,{size:"small",onClick:()=>void x(C.id),children:kD()})]}),!S.id.startsWith("acp:")&&!e&&!S.catalogPending&&S.installed&&!S.installBroken&&!S.authenticated&&!S.needsConfigRepair&&(S.id==="claude-code"?S.loginEligible:S.authMethod!=="local"&&S.authMethod!=="apiKey"&&S.authState!=="unsupported")&&l.jsxs(Se,{size:"small",onClick:()=>_(S),disabled:!p.data,"aria-haspopup":"dialog",children:[l.jsx(q_,{size:14})," ",CS()]}),l.jsxs(Se,{size:"small",onClick:()=>k(!0,!0),disabled:o,children:[l.jsx(Fi,{size:12,className:o?"animate-[spin_0.9s_linear_infinite]":""})," ",I0()]})]}),l.jsxs("div",{className:Ln(t2,"[&_.v]:text-sm"),children:[l.jsx("span",{className:"k",children:C?fD():yLr()}),l.jsx("span",{className:"v",children:C?g3(C.executable,C.arguments):S.binPath??aMr()}),l.jsx("span",{className:"k",children:wI()}),l.jsx("span",{className:"v",children:S.version??"—"}),(S.authMethod==="apiKey"||S.authMethod==="thirdParty"||S.authMethod==="local"||H0(S))&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"k",children:$$r()}),l.jsx("span",{className:"v",children:l.jsx(oss,{h:S})})]}),S.account&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"k",children:S.id==="opencode"?kI():MS()}),l.jsx("span",{className:"v",children:S.account})]}),S.org&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"k",children:pXr()}),l.jsx("span",{className:"v",children:S.org})]}),l.jsx("span",{className:"k",children:m$r()}),l.jsx("span",{className:"v",children:S.catalogPending?dd():S.models.length>0?jTr({count:fr(S.models.length)}):S.agentReady?_g():BRr()})]}),C?S.agentNote||!S.agentReady?l.jsx("p",{className:Ln(Sa,"text-sm"),children:S.agentNote??hD()}):null:l.jsx(GC,{note:S.agentNote,className:Ln(Sa,"text-sm"),disabled:e,resolve:E=>{var R;return GU(S,(R=p.data)==null?void 0:R[S.id],E)??UU(E)},onRun:(E,R)=>i.start(E,R,S.id)}),!S.installed&&S.needsConnectionAdapter&&l.jsx("p",{className:Ln(Sa,"text-sm"),children:cD({name:S.name})}),i.run&&l.jsx("div",{hidden:i.run.owner!==S.id,children:l.jsx(WC,{run:i.run,onComplete:()=>k(!0,!0),onClose:i.clear})}),S.id==="opencode"&&l.jsx($B,{installed:S.installed})]}):null:l.jsxs(ys,{children:[l.jsx($t,{})," ",EBr()]})]})}function iss({s:e}){const r=e.preflight;return r.kubectlFound?r.reachable?r.canCreateJobs?l.jsx(tr,{variant:"success",children:uI()}):l.jsx(tr,{variant:"error",children:dKr()}):l.jsx(tr,{variant:"error",children:JDr()}):l.jsx(tr,{variant:"error",children:Bqr()})}function css({onEditState:e}){var T;const r=pr({mutationFn:iOn}),t=dA(),n=nt(t),s=n.data??null,o=E=>{fs(t.queryKey,R=>(typeof E=="function"?E(R??null):E)??void 0)},a=s?null:((T=n.error)==null?void 0:T.message)??null,[i,c]=A.useState(""),[_,d]=A.useState(""),[f,p]=A.useState(!1),[m,w]=A.useState(!1),[y,v]=A.useState(null),x=E=>{o(E),c(E.context??""),d(E.namespace)},k=A.useRef(null);A.useEffect(()=>{const E=k.current;k.current=s,s&&(!E||i===(E.context??"")&&_.trim()===E.namespace)&&(c(s.context??""),d(s.namespace??""))},[s,i,_]);const b=s!==null&&i===(s.context??"")&&_.trim()===s.namespace,S=s!==null&&!b;A.useEffect(()=>{e==null||e({dirty:S,saving:f})},[S,f,e]);async function C(){if(!(m||f||!b)){w(!0);try{await Xe.fetchQuery({...dA(),staleTime:0})}catch(E){Kt(E instanceof Error?E.message:String(E),"error")}finally{w(!1)}}}async function N(E){if(E.preventDefault(),!(f||m)){p(!0),v(null);try{x(await r.mutateAsync({context:i,namespace:_.trim()}))}catch(R){v(R instanceof Error?R.message:String(R))}finally{p(!1)}}}return l.jsx(l.Fragment,{children:a?l.jsx("p",{className:"m-0 text-sm text-accent-red whitespace-pre-wrap break-words",children:a}):s?l.jsxs(l.Fragment,{children:[l.jsxs("dl",{className:"m-0 flex items-center justify-between gap-4 text-sm",children:[l.jsx("dt",{className:"text-subtext",children:Op()}),l.jsx("dd",{className:"m-0",children:m||f?l.jsx(tr,{children:Ea()}):S?l.jsx(tr,{children:$D()}):l.jsx(iss,{s})})]}),b&&!m&&!f&&s.preflight.error&&l.jsx("p",{className:`${Z0} break-words`,children:s.preflight.error}),l.jsxs("form",{className:"mt-5 flex flex-col gap-4",onSubmit:N,children:[l.jsxs("label",{className:"flex flex-col gap-2 text-sm font-medium text-subtext",children:[DIr(),l.jsx(ea,{choices:[{id:"",label:s.currentContext?HNr({context:Ae(s.currentContext)}):RNr()},...i&&!s.contexts.includes(i)?[{id:i,label:mMr({context:Ae(i)})}]:[],...s.contexts.map(E=>({id:E,label:E}))],value:i,variant:"field",dropDown:!0,disabled:f||m,onSelect:c})]}),l.jsxs("label",{className:"flex flex-col gap-2 text-sm font-medium text-subtext",children:[YGr(),l.jsx(yn,{type:"text",value:_,disabled:f||m,onChange:E=>d(E.target.value),placeholder:qPr(),autoComplete:"off",spellCheck:!1})]}),y&&l.jsx("p",{className:"m-0 text-sm text-accent-red whitespace-pre-wrap break-words",children:y}),l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsxs(Se,{type:"button",onClick:()=>void C(),disabled:f||m||!b,children:[l.jsx(Fi,{size:14})," ",m?Ea():$0()]}),l.jsx(Se,{variant:"primary",type:"submit",disabled:f||m||b,children:f?Pi():Ii()})]})]})]}):l.jsxs(ys,{children:[l.jsx($t,{})," ",oDr()]})})}function lss(){var b;const e=pr({mutationFn:S=>lOn(...S)}),r=hA(),t=nt(r),n=t.data??null,s=S=>{fs(r.queryKey,C=>(typeof S=="function"?S(C??null):S)??void 0)},[o,a]=A.useState(null),i=o??((b=t.error)==null?void 0:b.message)??null,[c,_]=A.useState(""),[d,f]=A.useState(""),[p,m]=A.useState(!1),w=t.isPending||p,[y,v]=A.useState(!1);async function x(){if(!(w||y)){m(!0),a(null);try{await Xe.fetchQuery({...hA(),staleTime:0})}catch(S){a(S instanceof Error?S.message:String(S))}finally{m(!1)}}}async function k(S){if(S.preventDefault(),!(!c.trim()||!d.trim()||w||y||n!=null&&n.processEnv)){v(!0),a(null);try{s(await e.mutateAsync([c.trim(),d.trim()])),_(""),f("")}catch(C){a(C instanceof Error?C.message:String(C))}finally{v(!1)}}}return l.jsxs(l.Fragment,{children:[!n&&w?l.jsxs(ys,{children:[l.jsx($t,{})," ",pDr()]}):n&&l.jsxs("dl",{className:"m-0 flex items-center justify-between gap-4 text-sm",children:[l.jsx("dt",{className:"font-medium text-subtext",children:Op()}),l.jsx("dd",{className:"m-0",children:l.jsx(tr,{variant:n.tokenConfigured?"success":"warning",children:n.tokenConfigured?D0():ex()})})]}),(n==null?void 0:n.processEnv)&&l.jsx("p",{className:"mt-2 mb-0 text-sm text-subtext",children:vAr()}),l.jsxs("form",{className:"mt-5 flex flex-col gap-4",onSubmit:k,children:[l.jsxs("label",{className:"flex flex-col gap-2 text-sm font-medium text-subtext",children:[n!=null&&n.tokenConfigured?EAr():sTr(),l.jsx(yn,{type:"password",value:c,onChange:S=>_(S.target.value),placeholder:(n==null?void 0:n.maskedTokenId)??"ak-…",autoComplete:"new-password",disabled:n==null?void 0:n.processEnv})]}),l.jsxs("label",{className:"flex flex-col gap-2 text-sm font-medium text-subtext",children:[n!=null&&n.tokenConfigured?IAr():hTr(),l.jsx(yn,{type:"password",value:d,onChange:S=>f(S.target.value),placeholder:(n==null?void 0:n.maskedTokenSecret)??"as-…",autoComplete:"new-password",disabled:n==null?void 0:n.processEnv})]}),l.jsx("a",{className:"self-start text-sm text-subtext underline",href:"https://modal.com/docs/sdk/py/latest/config",target:"_blank",rel:"noreferrer",children:VAr()}),i&&l.jsx("p",{className:"m-0 text-sm text-accent-red",children:i}),l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsxs(Se,{type:"button",disabled:w||y,onClick:()=>void x(),children:[l.jsx(Fi,{size:14})," ",I0()]}),l.jsx(Se,{variant:"primary",type:"submit",disabled:!c.trim()||!d.trim()||w||y||(n==null?void 0:n.processEnv),children:y?Pi():Ii()})]})]})]})}const WU="rounded-sm border-border-strong bg-surface text-subtext",KU="rounded-sm border-accent-blue bg-accent-blue-subtle text-accent-blue",uss=5e3;function VU(e){const r=li(),t=e.map(a=>pA(a)),n=gL({queries:t.map(a=>({...a,refetchInterval:uss}))});return[Object.fromEntries(e.flatMap((a,i)=>n[i].data?[[a,n[i].data.running]]:[])),a=>{Br(r)&&fs(pA(a).queryKey,{running:!0})}]}function _ss({test:e,connecting:r,masterRunning:t,containerFailed:n=!1}){if(r)return l.jsx("span",{role:"status",children:l.jsx(tr,{className:KU,children:RS()})});if(e===void 0)return l.jsx(tr,{className:WU,children:hI()});const s=e.missingTools??[],o=e.reachable&&e.toolsFound&&t===!1,a=!e.reachable||n?l.jsx(tr,{className:"rounded-sm",variant:"error",children:OS()}):e.toolsFound?o?l.jsx(tr,{className:"rounded-sm",variant:"warning",children:iI()}):l.jsx(tr,{className:"rounded-sm",variant:"success",children:L0()}):l.jsx(tr,{className:"rounded-sm",variant:"error",children:s.length===1?OTr({tool:Ae(s[0])}):UTr()});return l.jsxs("div",{className:"flex items-center gap-4",role:"status",children:[a,!o&&l.jsx("span",{className:"ssh-tested-at whitespace-nowrap text-xs text-subtext",children:$i(e.testedAt)})]})}function fss(){var $;const e=uP(),r=nt(e),t=(($=r.data)==null?void 0:$.hosts)??(r.isError?[]:null),[n,s]=A.useState(!1),[o,a]=A.useState({}),[i,c]=A.useState({}),_=A.useRef(0),[d,f]=A.useState(!1),[p,m]=A.useState({}),[w,y]=A.useState(null),[v,x]=A.useState(!1),[k,b]=A.useState(0),S=(t==null?void 0:t.filter(L=>{const I=o[L.host]??L.lastTest;return(I==null?void 0:I.reachable)&&I.toolsFound}).map(L=>L.host))??[],[C,N]=VU(S);function T(L){_.current+=1,f(!1),x(!1),b(I=>I+1),y(L),m(I=>({...I,[L]:!0}))}function E(){_.current+=1,f(!1),x(!1),y(null)}function R(L,I){m(P=>({...P,[L]:!I}))}return l.jsxs(l.Fragment,{children:[r.error&&l.jsx("p",{className:"text-sm text-accent-red",children:r.error.message}),l.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-3",children:[r.data&&l.jsx(tss,{settings:r.data}),l.jsxs(Se,{variant:"ghost",className:"ms-auto",onClick:()=>s(!0),children:[l.jsx(_x,{size:14})," ",TI()]})]}),t===null?l.jsxs(ys,{children:[l.jsx($t,{})," ",vI()]}):t.length===0?l.jsx("p",{className:"settings-empty mt-1 mx-0 mb-0 text-base text-subtext",children:nKr()}):l.jsx("div",{className:"border-y border-border-variant divide-y divide-border-variant",children:t.map(L=>{var W,ce,_e;const I=i[L.host]===void 0?L.container??null:i[L.host],P=o[L.host],B=I!==null&&((W=P==null?void 0:P.container)==null?void 0:W.reference)===I.trim()?P:void 0,K=I!==null?B:P!=null&&P.container?L.lastTest:P??L.lastTest,U=(ce=B==null?void 0:B.container)==null?void 0:ce.error,J=((_e=B==null?void 0:B.container)==null?void 0:_e.ready)===!1,te=(K==null?void 0:K.error)||U,F=w===L.host,D=p[L.host]??!1,q=F||!!te,Q=`${L.user?`${L.user}@`:""}${L.hostname??L.host}${L.port?`:${L.port}`:""}`;return l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-3 py-3",children:[l.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2.5",children:l.jsxs("div",{className:"min-w-0",children:[l.jsx("div",{className:"truncate text-base font-medium text-text",title:L.host,children:L.host}),l.jsx("div",{className:"mt-1 truncate text-sm text-subtext",title:Q,children:Q})]})}),l.jsxs("div",{className:"grid flex-none grid-cols-[8.5rem_5rem] items-center gap-x-12",children:[l.jsxs("div",{className:"flex items-center gap-2 text-start",children:[l.jsx(_ss,{test:K,connecting:F&&!v,masterRunning:C[L.host],containerFailed:J}),q&&l.jsx("button",{type:"button",className:"flex-none inline-flex items-center p-0.5 rounded-sm [&:hover]:bg-panel","aria-expanded":D,"aria-label":D?dJ({name:Ae(L.host)}):gee({name:Ae(L.host)}),onClick:ae=>{ae.stopPropagation(),R(L.host,D)},children:l.jsx(kc,{size:18,className:`text-muted transition-transform duration-120 ease-standard${D?" rotate-180":""}`})})]}),l.jsx(Se,{size:"small",type:"button",className:"justify-self-end",onClick:ae=>{ae.stopPropagation(),F&&!v?E():T(L.host)},disabled:!F&&(w!==null&&!v||I!==null&&!I.trim()),children:F?v?_s():xu():(K==null?void 0:K.reachable)===!1||J?_s():K?jI():bp()})]})]}),l.jsx(rss,{host:L,connecting:F&&!v,reference:I,onChange:ae=>{F&&E(),c(ee=>({...ee,[L.host]:ae})),a(ee=>{const G={...ee};return delete G[L.host],G})}}),q&&(D||F)&&l.jsxs("div",{className:`border-t border-t-border-variant py-3${D?"":" hidden"}`,children:[!F&&te&&l.jsx(pFn,{host:L.host,transcript:te}),F&&!d&&l.jsx(n6,{host:L.host,backend:"ssh",active:D,onComplete:ae=>{if(ae.backend!=="ssh")return;N(L.host);const ee=_.current;if(I===null){a(G=>({...G,[L.host]:{...ae.result,container:null}})),x(!1),y(null);return}f(!0),vOn(L.host,I.trim()).then(G=>{_.current===ee&&a(ne=>({...ne,[L.host]:{...G,container:G.container??{reference:I.trim(),ready:!1,error:G.error??null}}}))}).catch(G=>{_.current===ee&&a(ne=>({...ne,[L.host]:{...ae.result,container:{reference:I.trim(),ready:!1,error:G instanceof Error?G.message:String(G)}}}))}).finally(()=>{_.current===ee&&(f(!1),x(!1),y(null))})},onError:ae=>{x(!0),a(ee=>({...ee,[L.host]:{container:I===null?null:{reference:I.trim(),ready:!1,error:ae},reachable:!1,toolsFound:!1,missingTools:[],error:ae,testedAt:Date.now()}}))}},k)]})]},L.host)})}),n&&l.jsx(dF,{onClose:()=>s(!1)})]})}function dss({test:e,connecting:r,masterRunning:t}){return r?l.jsx(tr,{className:KU,children:RS()}):e===null?l.jsx(tr,{className:WU,children:hI()}):e.reachable?e.slurmFound?e.toolsFound?t===!1?l.jsx(tr,{className:"rounded-sm",variant:"warning",children:iI()}):l.jsx(tr,{className:"rounded-sm",variant:"success",children:L0()}):l.jsx(tr,{className:"rounded-sm",variant:"error",children:_Gr()}):l.jsx(tr,{className:"rounded-sm",variant:"error",children:JKr()}):l.jsx(tr,{className:"rounded-sm",variant:"error",children:OS()})}function hss(){var Q;const e=pr({mutationFn:NOn}),r=Q$n(),t=nt(r),n=t.data??null,s=W=>{fs(r.queryKey,ce=>(typeof W=="function"?W(ce??null):W)??void 0)},o=n?null:((Q=t.error)==null?void 0:Q.message)??null,[a,i]=A.useState(""),[c,_]=A.useState(""),[d,f]=A.useState(""),[p,m]=A.useState(""),[w,y]=A.useState(""),[v,x]=A.useState(""),[k,b]=A.useState(!1),[S,C]=A.useState(null),[N,T]=A.useState(null),[E,R]=A.useState(!1),[$,L]=A.useState(!1),[I,P]=A.useState(0),B=a&&(N!=null&&N.reachable)&&N.slurmFound&&N.toolsFound?[a]:[],[K,U]=VU(B);function J(){L(!1),P(W=>W+1),R(!0)}const te=W=>{s(W),i(W.host??""),_(W.partition??""),f(W.account??""),m(W.timeLimit??""),y(W.cpusPerTask===null?"":String(W.cpusPerTask)),x(W.mem??"")},F=A.useRef(null);A.useEffect(()=>{const W=F.current;F.current=n,n&&(!W||a===(W.host??"")&&c.trim()===(W.partition??"")&&d.trim()===(W.account??"")&&p.trim()===(W.timeLimit??"")&&w.trim()===(W.cpusPerTask===null?"":String(W.cpusPerTask))&&v.trim()===(W.mem??""))&&(i(n.host??""),_(n.partition??""),f(n.account??""),m(n.timeLimit??""),y(n.cpusPerTask===null?"":String(n.cpusPerTask)),x(n.mem??""))},[n,a,c,d,p,w,v]);const D=n!==null&&a===(n.host??"")&&c.trim()===(n.partition??"")&&d.trim()===(n.account??"")&&p.trim()===(n.timeLimit??"")&&w.trim()===(n.cpusPerTask===null?"":String(n.cpusPerTask))&&v.trim()===(n.mem??"");async function q(W){if(W.preventDefault(),!k){b(!0),C(null);try{te(await e.mutateAsync({host:a,partition:c.trim(),account:d.trim(),timeLimit:p.trim(),cpusPerTask:Number(w.trim())||0,mem:v.trim()}))}catch(ce){C(ce instanceof Error?ce.message:String(ce))}finally{b(!1)}}}return l.jsx(l.Fragment,{children:o?l.jsx("div",{className:"error",children:o}):n?l.jsxs(l.Fragment,{children:[!E&&(N==null?void 0:N.error)&&l.jsx("p",{className:Z0,children:N.error}),l.jsxs("form",{className:qC,onSubmit:q,children:[l.jsx("div",{className:"max-w-xl",children:l.jsxs("label",{children:[tGr(),l.jsx(ea,{choices:[{id:"",label:pI()},...a&&!n.hosts.some(W=>W.host===a)?[{id:a,label:`${a} (not in ~/.ssh/config)`}]:[],...n.hosts.map(W=>({id:W.host,label:W.host}))],value:a,variant:"field",dropDown:!0,disabled:k||E,onSelect:W=>{i(W),T(null),R(!1),L(!1)}})]})}),l.jsxs("div",{className:"actions",children:[l.jsx(Se,{type:"button",onClick:()=>{E&&!$?(L(!1),R(!1)):J()},disabled:!a,title:a?void 0:Jnn(),children:E?$?_s():xu():N?jI():bp()}),l.jsx("span",{role:"status",children:l.jsx(dss,{test:N,connecting:E&&!$,masterRunning:K[a]})})]}),l.jsxs("div",{className:"mt-5 border-t border-border pt-5",children:[l.jsxs("div",{className:"row2",children:[l.jsxs("label",{children:[bYr(),l.jsx(yn,{type:"text",list:"slurm-partitions",value:c,onChange:W=>_(W.target.value),placeholder:XN(),autoComplete:"off",spellCheck:!1}),l.jsx("datalist",{id:"slurm-partitions",children:N==null?void 0:N.partitions.map(W=>l.jsx("option",{value:W},W))})]}),l.jsxs("label",{children:[MS(),l.jsx(yn,{type:"text",value:d,onChange:W=>f(W.target.value),placeholder:XN(),autoComplete:"off",spellCheck:!1})]})]}),l.jsxs("label",{className:"mt-3 block max-w-xl",children:[frn(),l.jsx(yn,{type:"text",value:p,onChange:W=>m(W.target.value),placeholder:qDr(),autoComplete:"off",spellCheck:!1})]}),l.jsxs("div",{className:"row2 mt-3",children:[l.jsxs("label",{children:[tin(),l.jsx(yn,{type:"number",min:1,value:w,onChange:W=>y(W.target.value),placeholder:_in(),autoComplete:"off"})]}),l.jsxs("label",{children:[xin(),l.jsx(yn,{type:"text",value:v,onChange:W=>x(W.target.value),placeholder:Tin(),autoComplete:"off",spellCheck:!1})]})]})]}),S&&l.jsx("div",{className:"error",children:S}),l.jsx("div",{className:"actions",children:l.jsx(Se,{variant:"primary",type:"submit",disabled:k||D||E,children:k?Pi():Ii()})})]}),E&&l.jsx(n6,{host:a,backend:"slurm",onComplete:W=>{W.backend==="slurm"&&(T(W.result),U(a),L(!1),R(!1))},onError:W=>{L(!0),T({reachable:!1,slurmFound:!1,toolsFound:!1,partitions:[],error:W})}},I)]}):l.jsxs(ys,{children:[l.jsx($t,{})," ",SUr()]})})}function pss(){var S;const e=pr({mutationFn:TOn}),r=X$n(),t=nt(r),n=t.data??null,s=C=>{fs(r.queryKey,N=>(typeof C=="function"?C(N??null):C)??void 0)},o=n?null:((S=t.error)==null?void 0:S.message)??null,[a,i]=A.useState(""),[c,_]=A.useState(!1),[d,f]=A.useState(null),[p,m]=A.useState(null),w=p!==null&&p!=="testing"?p:null,y=C=>{s(C),i(C.address??"")},v=A.useRef(null);A.useEffect(()=>{const C=v.current;v.current=n,n&&(!C||a===(C.address??""))&&i(n.address??"")},[n,a]);const x=n!==null&&a===(n.address??"");async function k(C){if(C.preventDefault(),!c){_(!0),f(null);try{y(await e.mutateAsync({address:a}))}catch(N){f(N instanceof Error?N.message:String(N))}finally{_(!1)}}}async function b(){m("testing");try{m(await ROn(a.trim()||void 0))}catch(C){m({reachable:!1,address:a.trim()||"(unknown)",rayVersion:null,error:C instanceof Error?C.message:String(C)})}}return l.jsx(l.Fragment,{children:o?l.jsx("div",{className:"error",children:o}):n?l.jsxs(l.Fragment,{children:[(w==null?void 0:w.error)&&l.jsx("p",{className:Z0,children:w.error}),l.jsxs("form",{className:qC,onSubmit:k,children:[l.jsxs("label",{children:[Aqr(),l.jsx(yn,{type:"text",value:a,onChange:C=>{i(C.target.value),m(null)},placeholder:"http://127.0.0.1:8265",autoComplete:"off",spellCheck:!1})]}),l.jsxs("p",{className:"m-0 text-sm text-subtext",children:[VBr(),": ",Ae(n.resolvedAddress)," · ",bI(),": ",n.source]}),d&&l.jsx("div",{className:"error",children:d}),l.jsxs("div",{className:"actions",children:[l.jsx(Se,{variant:"primary",type:"submit",disabled:c||x,children:c?Pi():Ii()}),l.jsx(Se,{type:"button",onClick:()=>void b(),disabled:p==="testing",children:mtn()}),l.jsx(QU,{test:p})]}),(w==null?void 0:w.reachable)&&w.rayVersion&&l.jsxs("p",{className:"m-0 text-sm text-subtext",children:[PYr(),": ",w.rayVersion]})]})]}):l.jsxs(ys,{children:[l.jsx($t,{})," ",pUr()]})})}function QU({test:e}){return e===null?null:e==="testing"?l.jsx(tr,{children:Ctn()}):e.reachable?l.jsx(tr,{variant:"success",children:QYr()}):l.jsx(tr,{variant:"error",children:OS()})}function mss(e){const r=e.chip??`${e.os}/${e.arch}`,t=e.memBytes===null?null:du(e.memBytes),n=e.gpus.length===0?null:B9r({count:e.gpus.length});return[r,e.cpuCount>0?tzr({count:e.cpuCount}):null,t,n].filter(Boolean).join(" · ")}function gss({remote:e}){var p;const r=nt(Z$n()),t=r.data,n=(p=r.error)==null?void 0:p.message,s=r.isFetching,[o,a]=A.useState(0),[i,c]=A.useState(!0),[_,d]=A.useState(!1),f=()=>r.refetch();return l.jsxs(l.Fragment,{children:[n&&!t?l.jsx("div",{className:"error",children:n}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:nss,children:[l.jsx("span",{className:"k",children:Op()}),l.jsx("span",{className:"v",children:!t&&s||_?l.jsxs(tr,{className:"gap-1.5",role:"status",children:[l.jsx($t,{}),_?tOr():Ea()]}):n?l.jsx(tr,{variant:"warning",children:Wb()}):t?t.loggedIn?t.sshKeyStatus==="matched"?l.jsx(tr,{variant:"success",children:L0()}):t.sshKeyStatus==="unknown"?l.jsx(tr,{variant:"warning",children:Wb()}):l.jsx(tr,{variant:"warning",children:ex()}):l.jsx(tr,{variant:"warning",children:mI()}):null}),l.jsx("span",{className:"k",children:SXr()}),l.jsx("span",{className:"v",children:t!=null&&t.loggedIn&&t.orgs.length>0?t.orgs.join(", "):"—"}),l.jsx("span",{className:"k",children:_en()}),l.jsx("span",{className:"v",children:t!=null&&t.loggedIn?t.sshKeyStatus==="matched"?l.jsx(tr,{variant:"success",children:xQr()}):t.sshKeyStatus==="no_local_match"?l.jsx(tr,{variant:"warning",children:KVr()}):t.sshKeyStatus==="none_registered"?l.jsx(tr,{variant:"error",children:lVr()}):l.jsx(tr,{children:yI()}):"—"})]}),e&&t&&!t.loggedIn&&l.jsx("p",{className:"mt-4 mb-0 text-sm text-subtext",children:cAr({command:Ae("orx login")})}),!e&&o>0&&l.jsx(hFn,{login:i,onComplete:()=>{d(!1),a(0),f()},onError:m=>{d(!1),Kt(m,"error")}},o),e&&(t==null?void 0:t.loggedIn)&&t.sshKeyStatus==="none_registered"&&(t.sshKeyPath?l.jsxs("p",{dir:"auto",className:Sa,children:[XOr()," ",l.jsxs("code",{children:["orx ssh-key add ",t.sshKeyPath]}),"."]}):l.jsxs("p",{dir:"auto",className:Sa,children:[qKr()," ",l.jsx("code",{children:"ssh-keygen -t ed25519"}),Ltn()," ",l.jsx("code",{children:"orx ssh-key add"}),"."]})),e&&(t==null?void 0:t.loggedIn)&&t.sshKeyStatus==="no_local_match"&&(t.sshKeyPath?l.jsx("p",{dir:"auto",className:Sa,children:zsn({register:Ae(`orx ssh-key add ${t.sshKeyPath}`),load:Ae("ssh-add")})}):l.jsxs("p",{dir:"auto",className:Sa,children:[MKr()," ",l.jsx("code",{children:"ssh-add"}),oXr()," ",l.jsx("code",{children:"ssh-keygen -t ed25519"}),"."]})),!s&&(n||(t==null?void 0:t.error))&&l.jsx("p",{dir:"auto",className:"mt-4 mb-0 text-sm text-accent-red whitespace-pre-wrap break-words",children:n||(t==null?void 0:t.error)})]}),l.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[l.jsxs(Se,{onClick:()=>void f(),disabled:s||_,children:[l.jsx(Fi,{size:14})," ",s?Ea():$0()]}),!e&&t&&(!t.loggedIn||t.sshKeyStatus!=="matched")&&l.jsxs(Se,{variant:"primary",disabled:s||_,onClick:()=>{c(!t.loggedIn),d(!0),a(m=>m+1)},children:[_?l.jsx($t,{}):l.jsx(q_,{size:14})," ",t.loggedIn?Lan():CI()]})]})]})}const vss={local:pot,ssh:_at,tinker:xat,hf:Qst,modal:Sot,k8s:oot,slurm:tat,ray:Got,openresearch:$ot},r2={local:"local_job",tinker:"tinker_job",hf:"hf_job",modal:"modal_job",k8s:"k8s_job",ssh:"ssh_job",slurm:"slurm_job",ray:"ray_job",openresearch:"openresearch_job"},JM=["hf","modal","slurm","ray","openresearch"],y4=["hf","modal","openresearch"],XU={hf:["cpu-basic","t4-small","a10g-small","a10g-large","a100-large","h100","h200"],modal:["cpu","t4","l4","a10g","a100","a100-80gb","l40s","h100","h100:2"],slurm:["gpu","h100:1","h100:2","a100:4"],ray:["cpu","cpu:2","gpu","gpu:1","gpu:1,cpu:4","gpu:1,mem:8GiB"],openresearch:["h100_sxm","h100_sxm:2","cpu5c","cpu5g","cpu5m"]},gj=["tinker","hf","modal","ray","k8s"],bss={tinker:Hct,hf:fct,modal:wct,openresearch:Rct},eO="__custom__";function Vm(e,r){return!!(r&&!(XU[e]??[]).includes(r))}function yss({settings:e,projectId:r,onSaved:t}){const n=pr({mutationFn:LOn}),s=e.configuredDefaultBackend??e.defaultBackend??"local",o=e.defaultFlavor??"",[a,i]=A.useState(s),[c,_]=A.useState(o),[d,f]=A.useState(Vm(s,o)),[p,m]=A.useState(!1),[w,y]=A.useState(null),v=e.targets.find(I=>I.id===a),x=e.targets.filter(I=>I.configured||I.id===s),k=JM.includes(a),b=y4.includes(a),S=XU[a]??[],C=a===s&&(!k||c.trim()===o),N=vd[a](),T=bss[a],E=p?H_n():b&&!c.trim()?rCr({destination:N}):a==="ssh"?uRr():eRr({destination:N});A.useEffect(()=>{i(s),_(o),f(Vm(s,o))},[s,o]);async function R(I,P){const B=JM.includes(I);if(!(p||y4.includes(I)&&!P.trim())){m(!0),y(null);try{t(await n.mutateAsync({backend:I,flavor:B&&P.trim()||null,projectId:r}))}catch(K){y(K instanceof Error?K.message:String(K)),i(s),_(o),f(Vm(s,o))}finally{m(!1)}}}function $(I){const P=e.targets.find(K=>K.id===I);if(!P)return;i(P.id);const B=P.id===s?o:"";_(B),f(Vm(P.id,B)),y4.includes(P.id)||R(P.id,B)}function L(I){if(I===eO){f(!0);return}f(!1),_(I),(!b||I)&&R(a,I)}return l.jsxs("section",{className:"mb-8",children:[l.jsx("h2",{className:"mt-0 mx-0 mb-2 text-lg",children:cBr()}),l.jsxs("div",{children:[l.jsxs("form",{className:"grid grid-cols-[minmax(12rem,18rem)_minmax(12rem,18rem)] items-start gap-3",onSubmit:I=>{I.preventDefault(),C||R(a,c)},children:[l.jsx(ea,{choices:x.map(I=>({id:I.id,label:vd[I.id]()})),value:a,variant:"field",dropDown:!0,disabled:p,renderIcon:I=>{const P=e.targets.find(B=>B.id===I.id);return P?l.jsx(Hp,{kind:r2[P.id],size:16}):null},onSelect:$}),k&&l.jsx("div",{children:d?l.jsxs("div",{className:"relative",children:[l.jsx("input",{className:"h-9 w-full rounded-md border border-border bg-background py-0 pe-10 ps-3 font-sans text-sm text-text outline-none focus:border-focus-border focus:ring-3 focus:ring-focus-ring",type:"text",value:c,onChange:I=>_(I.target.value),onBlur:()=>{if(b&&!c.trim()){a===s&&(_(o),f(Vm(s,o)));return}C||R(a,c)},placeholder:dPr(),autoFocus:!0,autoComplete:"off",spellCheck:!1,disabled:p}),l.jsx("button",{type:"button",className:"absolute inset-y-0 end-0 inline-flex w-9 items-center justify-center text-muted hover:text-text","aria-label":QN(),title:QN(),onMouseDown:I=>I.preventDefault(),onClick:()=>f(!1),children:l.jsx(kc,{size:12})})]}):l.jsx(ea,{choices:[{id:"",label:b?W6r():ARr()},...c&&!S.includes(c)?[{id:c,label:xzr({value:Ae(c)})}]:[],...S.map(I=>({id:I,label:I})),{id:eO,label:kPr()}],value:c,variant:"field",dropDown:!0,disabled:p,onSelect:L})})]}),w&&l.jsx("div",{className:"error mt-2.5",children:w}),v&&!v.configured&&l.jsx("p",{className:Sa,children:Wtn()})]}),l.jsx("p",{className:"mt-2 mb-0 text-sm leading-relaxed text-subtext",children:E}),T&&l.jsx("p",{className:"mt-1 mb-0 text-sm leading-relaxed text-subtext",children:T()})]})}function xss({target:e,isDefault:r,summary:t,onOpen:n,onOpenEnvironment:s}){const o=`compute-${e.id}-summary`,a=e.unverified?C6r():e.id==="openresearch"?CI():e.id==="ray"?bp():Can();return l.jsxs("div",{className:`group relative flex min-h-41 w-full flex-col items-start rounded-lg border border-border bg-background p-5 text-start font-sans ${n&&e.enabled?"transition-colors duration-120 ease-standard hover:border-border-hover-strong hover:bg-surface":""} ${e.enabled?"":"opacity-52"}`,children:[n&&l.jsx("button",{type:"button",className:"absolute inset-0 z-10 rounded-lg focus-visible:outline-2 focus-visible:outline-focus focus-visible:outline-offset-2 disabled:cursor-default",onClick:n,disabled:!e.enabled,"aria-label":vd[e.id](),"aria-describedby":o,"aria-haspopup":gj.includes(e.id)?"dialog":void 0}),l.jsx("span",{className:"flex h-16 w-40 flex-none items-center justify-start",children:l.jsx(Hp,{kind:r2[e.id],size:48})}),l.jsx("span",{className:"mt-5 text-lg font-semibold text-text",children:vd[e.id]()}),l.jsx("span",{className:"mt-1 line-clamp-2 min-h-9 text-sm leading-normal text-text",children:vss[e.id]()}),l.jsx("span",{id:o,className:"mt-2 line-clamp-2 min-h-8 text-xs leading-normal text-subtext",children:e.fromEnvironmentTab?l.jsxs(l.Fragment,{children:[e.id==="tinker"?wNr():Bln()," ",l.jsx("button",{type:"button",className:"relative z-20 text-accent-blue-strong underline-offset-2 hover:underline",onClick:s,children:Qzr()})]}):t??e.summary}),l.jsxs("span",{className:"mt-auto flex w-full items-center justify-between gap-3 pt-3 text-sm",children:[l.jsx("span",{className:r?"font-medium text-text":"text-subtext",children:r?_I():e.configured?!n||gj.includes(e.id)?D0():ifn():a}),n&&l.jsx("span",{className:"text-subtext transition-transform duration-120 ease-standard group-hover:translate-x-0.5","aria-hidden":"true",children:l.jsx(cb,{size:16})})]})]})}function wss({target:e,isDefault:r,onBack:t,remote:n}){return l.jsxs(l.Fragment,{children:[l.jsxs("button",{type:"button",className:"settings-back mb-6 inline-flex items-center gap-2 text-sm font-medium text-subtext hover:text-text",onClick:t,children:[l.jsx(ty,{size:16})," ",cI()]}),l.jsxs("div",{className:"flex items-center justify-between gap-6",children:[l.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[l.jsx("span",{className:"flex h-10 w-10 flex-none items-center justify-center",children:l.jsx(Hp,{kind:r2[e.id],size:36})}),l.jsx("h1",{className:"m-0 min-w-0 text-2xl",children:vd[e.id]()})]}),r&&l.jsx(tr,{className:"flex-none",children:_I()})]}),l.jsxs("div",{className:"mt-6 font-sans text-base text-text [&_.settings-card]:mb-0 [&_.settings-form]:mt-6 [&_.settings-form]:border-t-0 [&_.settings-form]:pt-0 [&>.settings-form:first-child]:mt-0 [&>div:first-child]:border-t-0",children:[e.id==="ssh"&&l.jsx(fss,{}),e.id==="slurm"&&l.jsx(hss,{}),e.id==="openresearch"&&l.jsx(gss,{remote:n})]})]})}function kss({target:e,remote:r,onClose:t}){const n=A.useRef(null),[s,o]=A.useState({dirty:!1,saving:!1});A.useEffect(()=>{const i=n.current;return i==null||i.showModal(),()=>i==null?void 0:i.close()},[]);const a=()=>{s.saving||s.dirty&&!window.confirm(fNr())||t()};return l.jsxs("dialog",{ref:n,className:"m-auto w-140 max-w-[calc(100vw_-_40px)] max-h-[calc(100vh_-_40px)] overflow-y-auto rounded-xl border border-border bg-background p-5 text-text shadow-modal backdrop:bg-modal-backdrop-light","aria-labelledby":"compute-quick-setup-title",onKeyDown:i=>{i.key==="Escape"&&(i.preventDefault(),a())},onCancel:i=>{i.preventDefault(),a()},children:[l.jsxs("div",{className:"mb-5 flex items-center justify-between gap-4",children:[l.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[l.jsx(Hp,{kind:r2[e.id],size:32}),l.jsx("h2",{id:"compute-quick-setup-title",className:"m-0 text-xl font-medium text-text",children:vd[e.id]()})]}),l.jsx(xt,{title:Rg(),"aria-label":Rg(),onClick:a,disabled:s.saving,children:l.jsx(hn,{size:14})})]}),e.id==="tinker"&&l.jsx(Sss,{target:e}),e.id==="hf"&&l.jsx(zss,{remote:r}),e.id==="modal"&&l.jsx(lss,{}),e.id==="ray"&&l.jsx(pss,{}),e.id==="k8s"&&l.jsx(css,{onEditState:o})]})}function jss({project:e,onViewHistory:r,onOpenEnvironment:t,remote:n}){var R,$;const s=cP(e==null?void 0:e.id),o=nt(s),a=o.data??null,i=L=>{fs(s.queryKey,I=>(typeof L=="function"?L(I??null):L)??void 0)},c=a?null:((R=o.error)==null?void 0:R.message)??null,[_,d]=A.useState(null),[f,p]=A.useState(null),m=Y$n(),w=nt(m),y=w.data??null,v=(($=w.error)==null?void 0:$.message)??null;A.useEffect(()=>{d(null),p(null)},[e==null?void 0:e.id]);const x=L=>{i(L),p(null)},k=a?a.targets:null,b=(a==null?void 0:a.configuredDefaultBackend)??(a==null?void 0:a.defaultBackend),S=k?[...k].sort((L,I)=>+(I.id===b)-+(L.id===b)):null,C=(S==null?void 0:S.filter(L=>L.configured))??[],N=(S==null?void 0:S.filter(L=>!L.configured))??[],T=L=>l.jsx(xss,{target:L,isDefault:b===L.id,summary:L.id==="local"?y?mss(y):v??vBr():void 0,onOpen:L.id==="local"?void 0:()=>d(L.id),onOpenEnvironment:t},`${(e==null?void 0:e.id)??"none"}:${L.id}`),E=_?a==null?void 0:a.targets.find(L=>L.id===_):null;return E&&!gj.includes(E.id)?l.jsx(wss,{target:E,isDefault:b===E.id,onBack:()=>d(null),remote:n}):l.jsxs(l.Fragment,{children:[l.jsx("h1",{children:lI()}),l.jsx("p",{className:"settings-sub mt-0 mx-0 mb-4.5 text-base leading-relaxed text-text",children:vIr()}),l.jsx(Wss,{projectId:e==null?void 0:e.id,onViewHistory:r}),c?l.jsx("div",{className:"error",children:c}):a?l.jsxs(l.Fragment,{children:[f&&l.jsx("div",{className:"error",children:f}),l.jsx(yss,{settings:a,projectId:e==null?void 0:e.id,onSaved:x}),l.jsxs("section",{className:"mb-8",children:[l.jsx("h2",{className:"mt-0 mx-0 mb-2 text-lg",children:D0()}),l.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3",children:C.map(T)})]}),N.length>0&&l.jsxs("section",{className:"mb-3.5",children:[l.jsx("h2",{className:"mt-0 mx-0 mb-2 text-lg",children:xGr()}),l.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3",children:N.map(T)})]}),E&&l.jsx(kss,{target:E,remote:n,onClose:()=>d(null)})]}):l.jsxs(ys,{children:[l.jsx($t,{})," ",QLr()]})]})}function Sss({target:e}){var k;const r=pr({mutationFn:eOn}),[t,n]=A.useState(""),[s,o]=A.useState(!1),[a,i]=A.useState(null),c=fA(),_=nt(c),d=_.data??null,f=a??((k=_.error)==null?void 0:k.message)??null,p=b=>{fs(c.queryKey,S=>(typeof b=="function"?b(S??null):b)??void 0)},[m,w]=A.useState(!1),y=_.isPending||m;async function v(){if(!(y||s)){w(!0),i(null);try{await Xe.fetchQuery({...fA(),staleTime:0})}catch(b){i(b instanceof Error?b.message:String(b))}finally{w(!1)}}}async function x(b){if(b.preventDefault(),!(!t.trim()||s||y)){o(!0),i(null);try{p(await r.mutateAsync(t.trim())),n("")}catch(S){i(S instanceof Error?S.message:String(S))}finally{o(!1)}}}return l.jsxs(l.Fragment,{children:[!d&&y?l.jsxs(ys,{children:[l.jsx($t,{})," ",Ea()]}):d&&l.jsxs("dl",{className:"m-0 flex items-center justify-between gap-4 text-sm",children:[l.jsx("dt",{className:"font-medium text-subtext",children:Op()}),l.jsx("dd",{className:"m-0",children:l.jsx(tr,{variant:d.validationStatus==="valid"?"success":d.validationStatus==="invalid"?"error":"warning",children:d.validationStatus==="valid"?L0():d.validationStatus==="invalid"?Aln():d.validationStatus==="billingRequired"?uln():ex()})})]}),(d==null?void 0:d.validationStatus)==="billingRequired"&&l.jsx("p",{className:"mt-2 mb-0 text-sm text-subtext",children:l.jsx("a",{className:"underline",href:"https://tinker.thinkingmachines.ai/",target:"_blank",rel:"noreferrer",children:eln()})}),(d==null?void 0:d.processEnv)&&l.jsx("p",{className:"mt-2 mb-0 text-sm text-subtext",children:yln()}),l.jsxs("form",{className:"mt-5 flex flex-col gap-4",onSubmit:x,children:[l.jsxs("label",{className:"flex flex-col gap-2 text-sm font-medium text-subtext",children:[e.configured||d!==null&&d.validationStatus!=="missing"?Ton():Jy(),l.jsx(yn,{type:"password",value:t,placeholder:(d==null?void 0:d.maskedKey)??"",onChange:b=>n(b.target.value),autoComplete:"new-password"})]}),f&&l.jsx("p",{className:"m-0 text-sm text-accent-red",children:f}),l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsxs(Se,{type:"button",disabled:s||y,onClick:()=>void v(),children:[l.jsx(Fi,{size:14})," ",y?Ea():$0()]}),l.jsx(Se,{variant:"primary",type:"submit",disabled:!t.trim()||s||y,children:s?EI():Ii()})]})]})]})}function Css({settings:e}){return e.validationStatus==="missing"?l.jsx(tr,{variant:"warning",children:ex()}):e.validationStatus==="invalid"?l.jsx(tr,{variant:"error",children:yqr()}):e.validationStatus!=="valid"?null:e.jobsWrite===!0?l.jsx(tr,{variant:"success",children:L0()}):e.jobsWrite===!1?l.jsxs("span",{className:"inline-flex items-center gap-2",children:[l.jsx(tr,{variant:"warning",children:kKr()}),l.jsx(Lo,{content:aEr(),className:"text-subtext",children:l.jsx(ZS,{size:16})})]}):null}function zss({remote:e}){var k;const r=pr({mutationFn:ZMn}),t=_A(),n=nt(t),s=n.data??null,o=b=>{fs(t.queryKey,S=>(typeof b=="function"?b(S??null):b)??void 0)},a=s?null:((k=n.error)==null?void 0:k.message)??null,[i,c]=A.useState(""),[_,d]=A.useState(!1),[f,p]=A.useState(!1),[m,w]=A.useState(null),y=UC();async function v(){if(!(_||f||!s&&!a)){p(!0),w(null);try{await Xe.fetchQuery({..._A(),staleTime:0})}catch(b){w(b instanceof Error?b.message:String(b))}finally{p(!1)}}}async function x(b){if(b.preventDefault(),!(!i.trim()||_||f||!s&&!a)){d(!0),w(null);try{const S=await r.mutateAsync(i.trim());o(S),w(null),c("")}catch(S){w(S instanceof Error?S.message:String(S))}finally{d(!1)}}}return l.jsxs(l.Fragment,{children:[a?l.jsx("div",{className:"error",children:a}):s?l.jsxs(l.Fragment,{children:[l.jsxs("dl",{className:"m-0 flex flex-col gap-3 text-sm",children:[s.username&&l.jsxs("div",{className:"flex items-center justify-between gap-4",children:[l.jsx("dt",{className:"font-medium text-subtext",children:MS()}),l.jsx("dd",{className:"m-0 text-text",children:s.username})]}),(s.validationStatus==="missing"||s.validationStatus==="invalid"||s.validationStatus==="valid"&&s.jobsWrite!==null)&&l.jsxs("div",{className:"flex items-center justify-between gap-4",children:[l.jsx("dt",{className:"font-medium text-subtext",children:Op()}),l.jsx("dd",{className:"m-0 text-text",children:l.jsx(Css,{settings:s})})]})]}),s.validationStatus==="unreachable"&&s.validationError&&l.jsx("p",{className:Z0,children:s.validationError}),s.source==="env"&&l.jsx("p",{className:Sa,children:aHr()}),s.validationStatus==="valid"&&s.jobsWrite===null&&l.jsx(GC,{note:X9r({login:"`hf auth login`",url:Ae("huggingface.co/settings/tokens")}),className:Sa,disabled:e,onRun:y.start}),l.jsx(WC,{run:y.run,onComplete:()=>void n.refetch(),onClose:y.clear})]}):l.jsxs(ys,{children:[l.jsx($t,{})," ",$Ur()]}),l.jsxs("form",{className:"mt-5 flex flex-col gap-4",onSubmit:x,children:[l.jsxs("label",{className:"flex flex-col gap-2 text-sm font-medium text-subtext",children:[s!=null&&s.configured?Fon():yRr(),l.jsx(yn,{type:"password",value:i,onChange:b=>c(b.target.value),placeholder:(s==null?void 0:s.maskedToken)??XFr(),autoComplete:"off"})]}),m&&l.jsx("div",{className:"error",children:m}),l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsxs(Se,{type:"button",disabled:_||f||!s&&!a,onClick:()=>void v(),children:[l.jsx(Fi,{size:14})," ",f?Ea():$0()]}),l.jsx(Se,{variant:"primary",type:"submit",disabled:!i.trim()||_||f||!s&&!a,children:_?EI():Ii()})]})]})]})}const YU=/^hf_[A-Za-z0-9]{10,}$/;function ZU(){return l.jsx("tr",{children:l.jsx("td",{colSpan:3,children:l.jsxs("p",{dir:"auto",className:Sa,children:[rrn()," ",l.jsx("code",{children:"HF_TOKEN"}),zJr()]})})})}const tO=["TINKER_API_KEY","HF_TOKEN","WANDB_API_KEY"];function vj(e,r){const t=r instanceof Error?r.message:String(r);Kt(t.includes(e)?t:`${e}: ${t}`,"error")}function Ess({name:e,entry:r,onVars:t}){const n=pr({mutationFn:w=>BS(...w)}),s=pr({mutationFn:_On}),o=(r==null?void 0:r.value)!=null,a=(r==null?void 0:r.value)??"",[i,c]=A.useState(a),[_,d]=A.useState(!1);A.useEffect(()=>c(a),[a]);const f=i.trim()!==a;async function p(){var w;if(!(!i.trim()||_||o&&!f)){d(!0);try{const y=await n.mutateAsync([e,i.trim()]);t(y),c(o?((w=y.find(v=>v.key===e))==null?void 0:w.value)??"":"")}catch(y){vj(e,y)}finally{d(!1)}}}async function m(){if(!_){d(!0);try{t(await s.mutateAsync(e))}catch(w){vj(e,w)}finally{d(!1)}}}return l.jsxs(l.Fragment,{children:[l.jsxs("tr",{children:[l.jsx("td",{className:"font-mono text-sm",children:e}),l.jsxs("td",{className:"text-base text-subtext",children:[r&&!o?l.jsxs(l.Fragment,{children:[r.maskedValue,r.inProcessEnv&&l.jsx(tr,{children:q5()})]}):l.jsx(yn,{variant:"inline",className:"text-base",type:o?"text":"password",value:i,onChange:w=>c(w.target.value),onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),p()),w.key==="Escape"&&!_&&c(a)},placeholder:xI(),"aria-label":Lse({name:Ae(e)}),autoComplete:o?"off":"new-password",disabled:_}),o&&(r==null?void 0:r.inProcessEnv)&&l.jsx(tr,{children:q5()})]}),l.jsx("td",{children:r&&!(o&&f&&i.trim())?l.jsx(xt,{className:"[&:hover:not(:disabled)]:text-accent-red",title:_E({name:Ae(e)}),"aria-label":_E({name:Ae(e)}),onClick:()=>void m(),disabled:_,children:l.jsx(ef,{size:14})}):i.trim()&&l.jsx(Se,{size:"small",onClick:()=>void p(),disabled:_,children:_?Pi():Ii()})})]}),!r&&e!=="HF_TOKEN"&&YU.test(i.trim())&&l.jsx(ZU,{})]})}function Nss({onVars:e,onDone:r}){const t=pr({mutationFn:f=>BS(...f)}),[n,s]=A.useState(""),[o,a]=A.useState(""),[i,c]=A.useState(!1);async function _(){if(!(!n.trim()||!o.trim()||i)){c(!0);try{e(await t.mutateAsync([n.trim(),o.trim()])),r()}catch(f){vj(n.trim(),f)}finally{c(!1)}}}const d=f=>{f.key==="Enter"&&(f.preventDefault(),_()),f.key==="Escape"&&!i&&r()};return l.jsxs(l.Fragment,{children:[l.jsxs("tr",{children:[l.jsx("td",{children:l.jsx(yn,{autoFocus:!0,variant:"inline",className:"font-mono text-sm",type:"text",value:n,onChange:f=>s(f.target.value),onKeyDown:d,placeholder:"MY_API_KEY","aria-label":zWr(),autoComplete:"off",spellCheck:!1,disabled:i})}),l.jsx("td",{children:l.jsx(yn,{variant:"inline",className:"text-base",type:"password",value:o,onChange:f=>a(f.target.value),onKeyDown:d,placeholder:xI(),"aria-label":DWr(),autoComplete:"new-password",disabled:i})}),l.jsxs("td",{children:[l.jsx(Se,{size:"small",onClick:()=>void _(),disabled:i||!n.trim()||!o.trim(),children:i?Pi():Ii()}),l.jsx(xt,{title:xu(),"aria-label":PLr(),onClick:r,disabled:i,children:l.jsx(hn,{size:14})})]})]}),n.trim()!=="HF_TOKEN"&&YU.test(o.trim())&&l.jsx(ZU,{})]})}function Ass(){var _;const e=lP(),r=nt(e),t=r.data??null,n=d=>{fs(e.queryKey,f=>(typeof d=="function"?d(f??null):d)??void 0)},s=t?null:((_=r.error)==null?void 0:_.message)??null,[o,a]=A.useState(!1),i=t===null?[]:t.map(d=>d.key).filter(d=>!tO.includes(d)),c=[...tO,...i];return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"mb-4.5 flex items-center justify-between gap-4",children:[l.jsx("p",{className:"m-0 text-base leading-relaxed text-text",children:jnn()}),l.jsxs(Se,{size:"small",className:"shrink-0",onClick:()=>a(!0),disabled:o||t===null,children:[l.jsx(Bi,{size:12})," ",a$r()]})]}),l.jsxs("div",{className:Di,children:[s?l.jsx("div",{className:"error",children:s}):t===null?l.jsxs(ys,{children:[l.jsx($t,{})," ",wu()]}):l.jsx("table",{className:"env-table w-full table-fixed border-collapse text-base [&_td:first-child]:w-[32%] [&_td:first-child]:wrap-anywhere [&_.badge]:ms-2 [&_td]:h-12 [&_td]:pt-0 [&_td]:pe-2.5 [&_td]:pb-0 [&_td]:ps-0 [&_td]:align-middle [&_td]:border-b [&_td]:border-b-border-variant [&_tr:last-child_td]:border-b-0 [&_td:last-child]:w-29 [&_td:last-child]:whitespace-nowrap [&_td:last-child]:text-end [&_td[colspan]]:whitespace-normal [&_td[colspan]]:text-start [&_.icon-btn]:ms-2 [&_.icon-btn]:align-middle",children:l.jsxs("tbody",{children:[c.map(d=>l.jsx(Ess,{name:d,entry:t.find(f=>f.key===d),onVars:n},d)),o&&l.jsx(Nss,{onVars:n,onDone:()=>a(!1)})]})}),(t==null?void 0:t.some(d=>d.key==="TRACKIO_SERVER_URL"||d.key==="TRACKIO_SPACE_ID"))&&l.jsx(Tss,{space:t.some(d=>d.key==="TRACKIO_SPACE_ID")},t.filter(d=>d.key.startsWith("TRACKIO_")).map(d=>`${d.key}=${d.value??d.maskedValue}`).join())]})]})}function Tss({space:e}){const[r,t]=A.useState(null);async function n(){t("testing");try{t(await OOn())}catch(a){t({reachable:!1,version:null,writeAccess:null,spaceStage:null,error:a instanceof Error?a.message:String(a)})}}const s=r===null||r==="testing"?null:r,o=s?[s.version&&Lun({version:Ae(s.version)}),s.spaceStage&&s.spaceStage!=="RUNNING"&&mun({stage:Ae(s.spaceStage)}),s.writeAccess===!0&&(e?Xln():Wun()),s.writeAccess===!1&&(e?aun():r_n())].filter(Boolean):[];return l.jsxs("div",{className:"mt-3",children:[l.jsxs("div",{className:"flex items-center gap-2.5",children:[l.jsx(Se,{type:"button",size:"small",onClick:()=>void n(),disabled:r==="testing",children:Cun()}),l.jsx(QU,{test:r})]}),o.length>0&&l.jsx("p",{className:"m-0 mt-2 text-sm text-subtext",children:o.join(" · ")}),(s==null?void 0:s.error)&&l.jsx("p",{className:Z0,children:s.error})]})}const Qm=[{value:"system",label:Ucn,icon:nB},{value:"light",label:Ocn,icon:BBn},{value:"dark",label:pcn,icon:dBn}],Rss=[{id:"en",label:"English"},{id:"zh-CN",label:"简体中文"},{id:"fa",label:"فارسی"},{id:"ar",label:"العربية"},{id:"es",label:"Español"},{id:"hi",label:"हिन्दी"},{id:"ko",label:"한국어"},{id:"ja",label:"日本語"},{id:"pl",label:"Polski"}];function Mss(){const e=Cu(),[r,t]=SP(),n=s=>{var d;const o=s.key==="ArrowRight"||s.key==="ArrowDown"?1:s.key==="ArrowLeft"||s.key==="ArrowUp"?-1:0;if(!o)return;s.preventDefault();const a=[...s.currentTarget.querySelectorAll('[role="radio"]')],i=a.findIndex(f=>f===document.activeElement),_=((i===-1?Qm.findIndex(f=>f.value===r):i)+o+Qm.length)%Qm.length;t(Qm[_].value),(d=a[_])==null||d.focus()};return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:TSr()}),l.jsxs("div",{className:`${Di} mt-3`,children:[l.jsxs("div",{className:R_,children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:sA()}),l.jsx("div",{className:`${ox} theme-segmented flex-none`,role:"radiogroup","aria-label":sA(),onKeyDown:n,children:Qm.map(({value:s,label:o,icon:a})=>l.jsxs("button",{type:"button",role:"radio","aria-checked":r===s,tabIndex:r===s?0:-1,className:`theme-segment ${r===s?"active":""}`,onClick:()=>t(s),children:[l.jsx(a,{size:14}),o()]},s))})]}),l.jsxs("div",{className:R_,children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:ZNr()}),l.jsx("div",{className:"w-52 flex-none",children:l.jsx(ea,{choices:Rss,value:e,variant:"field",dropDown:!0,onSelect:s=>{nD(s)&&xP(s)}})})]})]})]})}const Oss={installer:fEn,"app-bundle":C9n,appimage:L9n,portable:REn,cargo:W9n,homebrew:rEn,nix:wEn,unknown:HEn},x4={cargo:ZEn,homebrew:cNn,nix:vNn};function $ss(){var f;const e=pr({mutationFn:p=>sOn(...p)}),{status:r,error:t,apply:n}=H6(),[s,o]=A.useState(null),[a,i]=A.useState(null),c=mF(r),_=s!==null||c.restarting;if(!r)return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:tA()}),t?l.jsx("div",{className:Di,children:l.jsx("div",{className:"error",children:t})}):l.jsxs(ys,{children:[l.jsx($t,{})," ",wu()]})]});const d=async(p,m)=>{o(p),i(null);try{await m()}catch(w){i(w instanceof Error?w.message:String(w))}finally{o(null)}};return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:tA()}),l.jsxs("div",{className:`${Di} mt-3`,children:[l.jsxs("div",{className:`${t2} pb-3.5`,children:[l.jsx("div",{className:"k",children:wI()}),l.jsx("div",{className:"v",children:r.current}),l.jsx("div",{className:"k",children:Xqr()}),l.jsx("div",{className:"v",children:r.latest??"—"}),l.jsx("div",{className:"k",children:dI()}),l.jsx("div",{className:"v",children:Oss[r.channel]()})]}),r.restartRequired&&l.jsxs("div",{className:R_,children:[l.jsxs("div",{children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:YZr()}),l.jsx("p",{children:c.error?HI({error:c.error}):Yon({installed:Ae(r.installedVersion??"—"),current:Ae(r.current??r.installedVersion??"—")})})]}),r.canRestart&&l.jsx(Se,{size:"small",type:"button",disabled:_,onClick:c.restart,children:c.restarting?qI():FI()})]}),r.selfUpdates?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:R_,children:[l.jsxs("div",{children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:ZN()}),l.jsxs("p",{children:[gWr(),r.envDisabled&&R_n()]})]}),l.jsx(VS,{type:"button",checked:r.autoUpdate,"aria-label":ZN(),disabled:_,onClick:()=>void d("auto",()=>e.mutateAsync([!r.autoUpdate]).then(n))})]}),l.jsxs("div",{className:R_,children:[l.jsxs("div",{children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:r.updateAvailable?w_n({version:Ae(r.latest??"—")}):a6r()}),l.jsxs("p",{children:[r.updateAvailable?rNr():L6r(),r.updateAvailable&&r.latestTag&&l.jsxs(l.Fragment,{children:[" ",l.jsx("a",{href:pF(r.latestTag),target:"_blank",rel:"noreferrer",className:"underline",children:SI()})]})]})]}),l.jsx(Se,{size:"small",type:"button",disabled:_,onClick:()=>void d("apply",()=>rOn().then(n)),children:s==="apply"?xS():r.updateAvailable?f_n():m6r()})]})]}):l.jsx("div",{className:R_,children:l.jsxs("div",{children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:$Xr()}),l.jsx("p",{children:((f=x4[r.channel])==null?void 0:f.call(x4))??Dsn()})]})}),r.channel==="app-bundle"&&l.jsx(Dss,{busy:s,disabled:_,run:d}),a&&l.jsx("div",{className:"error",children:a})]})]})}function Lss(){var f;const e=pr({mutationFn:r$n}),r=aLn(),t=nt(r),n=t.data??null,s=p=>{fs(r.queryKey,m=>(typeof p=="function"?p(m??null):p)??void 0)},[o,a]=A.useState(!1),[i,c]=A.useState(null),_=i??((f=t.error)==null?void 0:f.message)??null,d=()=>{!n||o||(a(!0),c(null),e.mutateAsync(!n.preferenceEnabled).then(s).catch(p=>c(p instanceof Error?p.message:String(p))).finally(()=>a(!1)))};return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:onn()}),n?l.jsxs("div",{className:`${Di} mt-3`,children:[l.jsxs("div",{className:R_,children:[l.jsxs("div",{children:[l.jsxs("div",{className:"project-default-title inline-flex items-center gap-1.5 text-base font-medium",children:[VN(),n.locked&&n.reason&&l.jsx(Lo,{content:`${nPr()} ${n.reason}.`,className:"text-subtext",children:l.jsx(ZS,{size:16})})]}),l.jsx("p",{children:KWr()})]}),l.jsx(VS,{type:"button",checked:n.enabled,"aria-label":VN(),disabled:o||n.locked,onClick:d})]}),_&&l.jsx("div",{className:"error",children:_})]}):_?l.jsx("div",{className:"error",children:_}):l.jsxs(ys,{children:[l.jsx($t,{})," ",wu()]})]})}function Dss({busy:e,disabled:r,run:t}){const n=pr({mutationFn:oOn}),[s,o]=A.useState(null),[a,i]=A.useState(!1),c=_=>void t("cli",()=>n.mutateAsync(_).then(d=>{o(d),i(!1)}).catch(d=>{throw i(!_&&String((d==null?void 0:d.message)??d).includes("--force")),d}));return l.jsxs("div",{className:R_,children:[l.jsxs("div",{children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:LEr({command:Ae("orx")})}),s?l.jsxs("p",{children:[s.alreadyCurrent?fCr({link:Ae(s.link)}):wCr({link:Ae(s.link)}),!s.onPath&&xSr({directory:Ae(s.dir)})]}):l.jsx("p",{children:CEr({command:Ae("orx")})})]}),l.jsx(Se,{size:"small",type:"button",disabled:r,onClick:()=>c(a),children:e==="cli"?xS():a?xon():s?ron():mEr()})]})}function Iss({remote:e,onProjectUpdate:r}){var b,S;const t=nt(P_()),[n,s]=A.useState(""),o=(b=t.data)==null?void 0:b.find(C=>C.id===n),a=pr({mutationFn:C=>XOn(...C)}),i=_P(),c=nt(i),_=c.data??null;nt({...Jb(),enabled:!!(_!=null&&_.githubAuthenticated)}),nt({...o3(),enabled:!!(_!=null&&_.githubAuthenticated)});const d=C=>{fs(i.queryKey,N=>(typeof C=="function"?C(N??null):C)??void 0)},[f,p]=A.useState(!1),[m,w]=A.useState(null),y=m??((S=c.error)==null?void 0:S.message)??null,v=async()=>{await c.refetch({cancelRefetch:!1}),n&&await Xe.invalidateQueries(fP(n)),await Promise.all([Xe.invalidateQueries(Jb()),Xe.invalidateQueries(o3())])},x=UC(),k=()=>{if(!_||f)return;const C=!_.githubForNewProjects;p(!0),w(null),a.mutateAsync([C,!0]).then(d).catch(N=>w(N instanceof Error?N.message:String(N))).finally(()=>p(!1))};return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:TFr()}),_?l.jsxs("div",{className:`${Di} mt-3`,children:[l.jsx("div",{className:"mb-4 flex justify-start",children:l.jsx(tr,{variant:_.githubAuthenticated?"success":_.ghInstalled?"warning":"error",children:_.githubAuthenticated?L7r():XRr()})}),l.jsxs("div",{className:"flex items-center justify-between gap-6 [&_p]:mt-1 [&_p]:mb-0 [&_p]:text-sm [&_p]:leading-relaxed",children:[l.jsxs("div",{children:[l.jsx("div",{className:"project-default-title text-base font-medium",children:YN()}),l.jsx("p",{children:qnn()})]}),l.jsx(VS,{type:"button",checked:_.githubForNewProjects,"aria-label":YN(),disabled:f||!_.githubAuthenticated&&!_.githubForNewProjects,onClick:k})]}),!_.githubAuthenticated&&l.jsx("div",{className:"mt-4",children:l.jsx(Pss,{ghInstalled:_.ghInstalled,remote:e,onCheck:v,onRun:x.start})}),l.jsx(WC,{run:x.run,onComplete:()=>void v(),onClose:x.clear}),y&&l.jsx("div",{className:"error",children:y}),l.jsxs("div",{className:"mt-6",children:[l.jsx("div",{className:"mb-2 text-sm font-medium",children:KN()}),l.jsx(ea,{variant:"field",dropDown:!0,title:KN(),value:n,choices:[{id:"",label:$8r()},...(t.data??[]).map(C=>({id:C.id,label:C.name}))],onSelect:s}),t.error&&l.jsxs("div",{className:"mt-2 text-sm text-text",children:[l.jsx("p",{className:"m-0",children:t.error.message}),l.jsx(Se,{size:"small",onClick:()=>void t.refetch(),children:_s()})]}),o&&l.jsx(Fss,{project:o,onProjectUpdate:r},o.id)]})]}):y?l.jsx("div",{className:"error",children:y}):l.jsx("div",{className:`${Di} mt-3`,role:"status","aria-label":wu(),"aria-busy":"true",children:l.jsxs("div",{"aria-hidden":"true",className:"motion-safe:animate-pulse",children:[l.jsx("div",{className:"mb-4 flex justify-start",children:l.jsx("div",{className:"h-6 w-48 rounded-full bg-surface"})}),l.jsxs("div",{className:"flex items-center justify-between gap-6",children:[l.jsxs("div",{className:"flex-1 space-y-2",children:[l.jsx("div",{className:"h-5 w-2/3 rounded-xs bg-surface"}),l.jsx("div",{className:"h-4 rounded-xs bg-surface"}),l.jsx("div",{className:"h-4 w-3/4 rounded-xs bg-surface"})]}),l.jsx("div",{className:"h-6 w-10 shrink-0 rounded-full bg-surface"})]}),l.jsx("div",{className:"mt-6 h-4 w-44 rounded-xs bg-surface"}),l.jsx("div",{className:"mt-2 h-8 rounded-xs bg-surface"})]})})]})}function Pss({ghInstalled:e,remote:r,onCheck:t,onRun:n}){const[s,o]=A.useState(!1),a=()=>{o(!0),t().finally(()=>o(!1))};return l.jsxs(l.Fragment,{children:[l.jsx(GC,{note:e?ian():WEr(),className:"git-card-helper m-0 text-sm leading-relaxed text-text",disabled:r||!e,onRun:n}),l.jsxs("div",{className:"flex flex-wrap gap-2 mt-2.5",children:[!e&&l.jsxs(B_,{variant:"primary",href:"https://cli.github.com/",target:"_blank",rel:"noreferrer",children:[GHr()," ",l.jsx(F_,{size:12})]}),l.jsx(Se,{type:"button",variant:e?"warning":"default",disabled:s,onClick:a,children:s?Ea():$0()})]})]})}function Bss(){var p,m,w,y,v,x;const e=pr({mutationFn:IMn}),r=pr({mutationFn:PMn}),t=gqn(),n=nt(t),[s,o]=A.useState(!1),[a,i]=A.useState(!1),[c,_]=A.useState(null),d=k=>fs(t.queryKey,b=>b&&{...b,...k}),f=async k=>{_(k);try{d(await(k==="token"?e.mutateAsync():r.mutateAsync()))}catch(b){Kt(b instanceof Error?b.message:String(b),"error")}finally{_(null)}};return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:gI()}),l.jsx("p",{className:"mt-1 mb-3 text-sm text-text",children:xOr()}),l.jsxs("div",{className:`${Di} space-y-5`,children:[l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between gap-4",children:[l.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[l.jsx("span",{className:"text-base font-medium",children:_Or()}),l.jsx(tr,{variant:(p=n.data)!=null&&p.hasToken?"success":"default",children:n.isPending?Ea():n.data?n.data.hasToken?nA():F5():Ri()})]}),(m=n.data)!=null&&m.hasToken?l.jsx(Se,{size:"small",disabled:c!==null,onClick:()=>void f("token"),children:c==="token"?rA():$g()}):l.jsx(Se,{size:"small",disabled:!n.data,"aria-expanded":s,onClick:()=>o(!s),children:s?yp():bp()})]}),s&&!((w=n.data)!=null&&w.hasToken)&&l.jsxs("div",{className:"mt-3",children:[l.jsx("p",{className:"mt-0 mb-2 text-sm leading-relaxed text-text",children:eI()}),l.jsx(ZM,{save:YI,onSaved:k=>{d(k),o(!1)},placeholder:eYr(),createHref:"https://www.overleaf.com/user/settings"})]})]}),l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between gap-4",children:[l.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[l.jsx("span",{className:"text-base font-medium",children:TOr()}),l.jsx(tr,{variant:(y=n.data)!=null&&y.hasSession?"success":"default",children:n.isPending?Ea():n.data?n.data.hasSession?nA():F5():Ri()})]}),(v=n.data)!=null&&v.hasSession?l.jsx(Se,{size:"small",disabled:c!==null,onClick:()=>void f("session"),children:c==="session"?rA():$g()}):l.jsx(Se,{size:"small",disabled:!n.data,"aria-expanded":a,onClick:()=>i(!a),children:a?yp():bp()})]}),a&&!((x=n.data)!=null&&x.hasSession)&&l.jsxs("div",{className:"mt-3",children:[l.jsx("p",{className:"mt-0 mb-2 text-sm leading-relaxed text-text",children:ZD()}),l.jsx(ZM,{save:ZI,onSaved:k=>{d(k),i(!1)},placeholder:D5(),createHref:"https://www.overleaf.com/project",createLabel:_cr()})]})]}),n.error&&l.jsx("div",{className:"error",children:n.error.message})]})]})}function Fss({project:e,onProjectUpdate:r}){var T,E,R,$,L,I;const t={...fP((e==null?void 0:e.id)??""),enabled:!!e},n=nt(t),s=n.data??null,o=P=>{fs(t.queryKey,B=>(typeof P=="function"?P(B??null):P)??void 0)},[a,i]=A.useState(!1),[c,_]=A.useState(null),d=c??((T=n.error)==null?void 0:T.message)??null,f=!!(s!=null&&s.github.owner&&s.github.repo),p=nt({...a3((s==null?void 0:s.github.owner)??"",(s==null?void 0:s.github.repo)??""),enabled:f&&!!(s!=null&&s.github.authenticated)&&!(s!=null&&s.github.enabled)}),m=f&&!p.data&&!p.error,w=f&&!!((E=p.data)!=null&&E.canPush),y=A.useRef(null),v=Na(y),x=nt({...Jb(),enabled:v.open}),k=nt({...o3(),enabled:v.open}),b=((R=x.data)==null?void 0:R.login)??null,S=[...b?[b]:[],...(($=k.data)==null?void 0:$.organizations)??[]],C=P=>{const B=P instanceof Error?P.message:String(P);return B.startsWith("GitHub denied repository creation")?B:B.toLowerCase().includes("archived")?S8r():B.includes("(fetch first)")||B.includes("non-fast-forward")?t9r():B.includes("403")||B.toLowerCase().includes("permission denied")?A9r():B},N=P=>{v.setOpen(!1),e&&(i(!0),_(null),JOn(e.id,P===b?void 0:P).then(B=>{o(B.git),r(B.project)}).catch(B=>_(C(B))).finally(()=>i(!1)))};return l.jsx(l.Fragment,{children:e?d&&!s?l.jsx("div",{className:"error",children:d}):s?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"mt-4 min-h-22",children:[!s.initialized&&l.jsx("div",{className:"flex flex-wrap gap-2 mt-3.5",children:l.jsx(Se,{variant:"primary",onClick:()=>void ZOn(e.id).then(o).catch(P=>_(String(P))),children:mHr()})}),l.jsxs("div",{className:t2,children:[l.jsx("span",{className:"k",children:NYr()}),l.jsx("span",{className:"v",children:f?l.jsxs(l.Fragment,{children:[l.jsxs("span",{children:[s.github.owner,"/",s.github.repo]}),!s.github.enabled&&l.jsx(tr,{children:atn()})]}):l.jsx(tr,{children:GUr()})}),s.github.enabled&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"k",children:Xen()}),l.jsx("span",{className:"v",children:s.github.syncStatus})]})]}),s.github.authenticated&&!s.github.enabled&&l.jsxs("div",{className:"flex flex-wrap gap-2 mt-3.5",children:[f&&s.github.url&&l.jsxs(B_,{href:s.github.url,target:"_blank",rel:"noreferrer",children:[eA()," ",l.jsx(F_,{size:12})]}),l.jsxs("div",{ref:v.ref,className:"relative",children:[l.jsxs(Se,{variant:"primary",disabled:a||m||!!p.error,"aria-expanded":v.open,"aria-haspopup":w?void 0:"menu",onClick:P=>{y.current=P.currentTarget,w?N():v.setOpen(!v.open)},children:[a?i5r():m?Ea():Y4r()," ",!w&&!m&&l.jsx(kc,{size:14})]}),v.open&&l.jsxs("div",{role:"menu","aria-label":y9r(),className:"absolute start-0 top-full z-50 mt-2 w-72 max-w-[calc(100vw-2rem)] max-h-64 overflow-y-auto rounded-lg border border-border bg-background p-2 shadow-modal",children:[l.jsx("div",{className:"px-2 py-1 text-sm font-medium text-subtext",children:G8r()}),f&&l.jsx("p",{className:"px-2 py-1 m-0 text-sm text-text",children:_zr()}),S.map(P=>l.jsx(cr,{role:"menuitem",onClick:()=>N(P),children:P},P)),!S.length&&(x.isFetching||k.isFetching)&&l.jsx("div",{role:"status","aria-label":wu(),"aria-busy":"true",className:"px-2 py-2",children:l.jsxs("div",{"aria-hidden":"true",className:"space-y-3 motion-safe:animate-pulse",children:[l.jsx("div",{className:"h-4 w-28 rounded-xs bg-surface"}),l.jsx("div",{className:"h-4 w-36 rounded-xs bg-surface"})]})}),(x.error||k.error||!b&&!x.isFetching)&&l.jsxs("div",{className:"px-2 py-1 text-sm text-text",children:[l.jsx("p",{className:"m-0",children:((L=x.error)==null?void 0:L.message)??((I=k.error)==null?void 0:I.message)??p8r()}),l.jsx(Se,{size:"small",className:"mt-2",onClick:()=>{x.refetch(),k.refetch()},children:_s()})]})]})]}),p.error&&l.jsxs("div",{className:"basis-full text-sm text-text",children:[l.jsx("p",{className:"mt-2 mb-0",children:p.error.message}),l.jsx(Se,{size:"small",className:"mt-2",onClick:()=>void p.refetch(),children:_s()})]})]}),s.github.enabled&&l.jsxs(l.Fragment,{children:[l.jsx("p",{className:"git-card-helper mt-3.5 mx-0 mb-0 text-sm leading-relaxed text-text",children:IBr()}),l.jsxs("div",{className:"flex flex-wrap gap-2 mt-3.5",children:[s.github.url&&l.jsxs(B_,{href:s.github.url,target:"_blank",rel:"noreferrer",children:[eA()," ",l.jsx(F_,{size:12})]}),l.jsx(Se,{disabled:a,onClick:()=>{i(!0),e$n(e.id).then(P=>{o(P.git),r(P.project)}).catch(P=>_(P instanceof Error?P.message:String(P))).finally(()=>i(!1))},children:a?g5r():F4r()})]})]})]}),d&&l.jsx("div",{className:"error",children:C(d)})]}):l.jsx("div",{className:"mt-4 min-h-22",role:"status","aria-label":wu(),"aria-busy":"true",children:l.jsxs("div",{"aria-hidden":"true",className:"motion-safe:animate-pulse",children:[l.jsxs("div",{className:"flex items-center gap-4",children:[l.jsx("div",{className:"h-4 w-16 rounded-xs bg-surface"}),l.jsx("div",{className:"h-6 w-24 rounded-full bg-surface"})]}),l.jsx("div",{className:"mt-3.5 h-8 w-48 rounded-xs bg-surface"})]})}):l.jsx("div",{className:Di,children:l.jsx("p",{className:Sa,children:TQr()})})})}const Hss={env:z4n,config:D4n,xdg:K4n,default:g4n},w4={preparing:Ykn,copying:Gwn,verifying:n5n,finalizing:tkn},qss=e=>{var r;return((r=w4[e])==null?void 0:r.call(w4))??e};function Uss(){var b;const e=eLn(),r=nt(e),t=r.data??null,n=t?null:((b=r.error)==null?void 0:b.message)??null,[s,o]=A.useState(""),[a,i]=A.useState(!1),[c,_]=A.useState(null),[d,f]=A.useState({kind:"idle"}),[p,m]=A.useState(null);A.useEffect(()=>{t&&o(S=>S||t.current)},[t]),A.useEffect(()=>hP(S=>{S.type==="progress"?f(C=>{const N=C.kind==="moving"?C.total:0;return{kind:"moving",phase:S.phase,copied:S.copiedBytes,total:S.totalBytes||N}}):S.type==="done"?(f({kind:"done",oldPathLeft:S.oldPathLeft}),_(null),o("")):S.type==="error"&&f({kind:"error",message:S.error})}),[]);const w=(t==null?void 0:t.source)==="env",y=s.trim(),v=t!==null&&y===t.current;async function x(){if(!(a||!y)){i(!0),m(null),_(null);try{_(await dOn(y))}catch(S){m(S instanceof Error?S.message:String(S))}finally{i(!1)}}}async function k(S){if(S.preventDefault(),!(d.kind==="moving"||!y||v)&&(m(null),!!window.confirm(xkn({path:Ae(y)})))){f({kind:"moving",phase:"preparing",copied:0,total:(c==null?void 0:c.treeBytes)??0});try{await hOn(y)}catch(C){f({kind:"idle"}),m(C instanceof Error?C.message:String(C))}}}return l.jsxs(l.Fragment,{children:[l.jsx("h2",{children:Ben()}),l.jsx("p",{className:"settings-sub mt-0 mx-0 mb-4.5 text-sm leading-relaxed text-subtext",children:Xin()}),n?l.jsx("div",{className:Di,children:l.jsx("div",{className:"error",children:n})}):t?l.jsxs("div",{className:Di,children:[l.jsx("div",{className:"settings-card-head mb-3",children:l.jsx("h3",{children:MPr()})}),l.jsxs("div",{className:t2,children:[l.jsx("span",{className:"k",children:KIr()}),l.jsx("span",{className:"v",children:t.current}),l.jsx("span",{className:"k",children:bI()}),l.jsx("span",{className:"v",children:Hss[t.source]()})]}),!w&&l.jsxs("form",{className:qC,onSubmit:k,children:[l.jsxs("label",{children:[iWr(),l.jsx("input",{className:"text-sm",type:"text",value:s,onChange:S=>{o(S.target.value),_(null)},placeholder:"/absolute/path/to/openresearch",autoComplete:"off",spellCheck:!1,disabled:d.kind==="moving"})]}),c&&!c.error&&c.ok&&l.jsxs("p",{className:Sa,children:[kZr()," ",du(c.treeBytes??0),c.freeBytes!=null&&` — ${_kn({size:Ae(du(c.freeBytes))})}`,c.sameFilesystem?i4n():"","."]}),c&&c.ok===!1&&c.error&&l.jsx("div",{className:"error",children:c.error}),p&&l.jsx("div",{className:"error",children:p}),d.kind==="moving"&&l.jsx(qU,{value:d.copied,max:d.total,label:qss(d.phase),caption:d.total>0?l.jsxs("span",{className:"text-sm",children:[du(d.copied)," / ",du(d.total)]}):void 0}),d.kind==="done"&&l.jsxs("p",{className:Sa,children:[FGr(),d.oldPathLeft&&l.jsxs(l.Fragment,{children:[" ",GMr({path:Ae(d.oldPathLeft)})]})]}),d.kind==="error"&&l.jsxs("div",{className:"error",children:[TGr()," ",d.message]}),l.jsxs("div",{className:"actions",children:[l.jsx(Se,{type:"button",onClick:x,disabled:a||!y||v||d.kind==="moving",children:a?Ea():FSr()}),l.jsx(Se,{variant:"primary",type:"submit",disabled:!y||v||d.kind==="moving",children:d.kind==="moving"?Fkn():Tkn()})]})]})]}):l.jsxs(ys,{children:[l.jsx($t,{})," ",wu()]})]})}const bj=e=>e==="running"||e==="starting";function Gss(e){return bj(e.status)?Lg(Date.now()-e.createdAt):e.endedAt?Lg(e.endedAt-e.createdAt):"—"}function JU({instances:e,emptyLabel:r}){return e.length===0?l.jsx("p",{className:"instances-empty m-0 rounded-lg border border-border bg-background py-3.5 px-4 text-base text-subtext",children:r}):l.jsx("div",{className:"instances-table-wrap overflow-x-auto",children:l.jsxs("table",{className:"runs-table w-full border-collapse bg-background text-base [&_th]:text-start [&_th]:text-text [&_th]:text-sm [&_th]:font-medium [&_th]:py-2 [&_th]:px-3 [&_th]:border-b [&_th]:border-b-border [&_th]:sticky [&_th]:top-0 [&_th]:bg-background [&_th]:z-1 [&_td]:py-2 [&_td]:px-3 [&_td]:border-b [&_td]:border-b-divider-faint [&_td]:whitespace-nowrap [&_tr:last-child_td]:border-b-0 [&_tr.clickable]:cursor-pointer [&_tr.clickable:hover_td]:bg-surface",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:uLr()}),l.jsx("th",{children:Op()}),l.jsx("th",{children:xen()}),l.jsx("th",{children:gJr()})]})}),l.jsx("tbody",{children:e.map(t=>{var s;const n=typeof((s=t.backend)==null?void 0:s.url)=="string"?t.backend.url:void 0;return l.jsxs("tr",{children:[l.jsx("td",{children:l.jsxs("span",{className:"backend-cell inline-flex items-center gap-0.5",children:[l.jsx(oC,{backend:t.backend}),n&&l.jsx($p,{size:"small",href:n,target:"_blank",rel:"noreferrer",title:JN(),"aria-label":JN(),onClick:o=>o.stopPropagation(),children:l.jsx(F_,{size:12})})]})}),l.jsx("td",{children:l.jsx(vu,{status:za(t)})}),l.jsx("td",{children:$i(t.createdAt)}),l.jsx("td",{children:Gss(t)})]},t.id)})})]})})}function Wss({projectId:e,onViewHistory:r}){var f;const t=nt({...hu(e??""),enabled:!!e,subscribed:!!e}),n=e?t.data??(t.error?[]:null):[],s=(f=t.error)==null?void 0:f.message,o=t.isFetching,[,a]=A.useState(0);A.useEffect(()=>{const p=setInterval(()=>a(m=>m+1),3e4);return()=>clearInterval(p)},[]);const i=()=>{e&&t.refetch()},c=(p,m)=>m.createdAt-p.createdAt,_=n==null?void 0:n.filter(p=>bj(p.status)).sort(c),d=n==null?void 0:n.filter(p=>!bj(p.status)).sort(c);return l.jsxs("section",{className:"compute-activity [&_.count-badge]:inline-flex [&_.count-badge]:items-center [&_.count-badge]:justify-center [&_.count-badge]:min-w-4.5 [&_.count-badge]:h-4.5 [&_.count-badge]:py-0 [&_.count-badge]:px-1 [&_.count-badge]:rounded-md [&_.count-badge]:bg-surface [&_.count-badge]:border [&_.count-badge]:border-border [&_.count-badge]:text-xs [&_.count-badge]:font-medium [&_.count-badge]:text-text mt-5.5 mx-0 mb-8",children:[l.jsxs("div",{className:"compute-activity-head flex items-start justify-between gap-5 mb-3.5 [&_h2]:flex [&_h2]:items-center [&_h2]:gap-2 [&_h2]:m-0 [&_h2]:text-lg [@media((max-width:_640px))]:items-stretch [@media((max-width:_640px))]:flex-col",children:[l.jsx("div",{children:l.jsxs("h2",{children:[iJr(),_&&_.length>0&&l.jsx("span",{className:"count-badge",children:_.length})]})}),l.jsxs("div",{className:"compute-activity-actions flex gap-2 flex-none [@media((max-width:_640px))]:justify-start",children:[l.jsxs(Se,{size:"small",onClick:i,disabled:o,children:[l.jsx(Fi,{size:12,className:o?"animate-[spin_0.9s_linear_infinite]":""})," ",I0()]}),l.jsx(Se,{size:"small",onClick:r,children:d!=null&&d.length?NAt({count:fr(d.length)}):bAt()})]})]}),s&&l.jsx("div",{className:"error",children:s}),!_||!d?l.jsxs(ys,{children:[l.jsx($t,{})," ",wu()]}):l.jsx(JU,{instances:_,emptyLabel:e?qNt():lAt()})]})}function Kss({projectId:e,onBack:r}){var c;const t=nt({...hu(e??""),enabled:!!e,subscribed:!!e}),n=e?t.data??(t.error?[]:null):[],s=(c=t.error)==null?void 0:c.message,o=t.isFetching,[,a]=A.useState(0);A.useEffect(()=>{const _=setInterval(()=>a(d=>d+1),3e4);return()=>clearInterval(_)},[]);const i=()=>{e&&t.refetch()};return l.jsxs(l.Fragment,{children:[l.jsxs("button",{type:"button",className:"settings-back inline-flex items-center gap-1.5 mt-0 mx-0 mb-4.5 text-subtext text-sm font-medium [&:hover]:text-text",onClick:r,children:[l.jsx(ty,{size:14})," ",cI()]}),l.jsxs("div",{className:"settings-head-row flex items-center justify-between gap-2.5 [&_h1]:m-0",children:[l.jsx("h1",{children:uqr()}),l.jsxs(Se,{size:"small",onClick:i,disabled:o,children:[l.jsx(Fi,{size:12,className:o?"animate-[spin_0.9s_linear_infinite]":""})," ",I0()]})]}),s&&l.jsx("div",{className:"error",children:s}),n?l.jsx(JU,{instances:[...n].sort((_,d)=>d.createdAt-_.createdAt),emptyLabel:e?MNt():JNt()}):l.jsxs(ys,{children:[l.jsx($t,{})," ",wu()]})]})}const eG=["projects","harnesses","storage"],Vss=[{id:"compute",label:lI,icon:l.jsx(YS,{size:16}),activeTabs:["compute","instances"]},{id:"environment",label:fI,icon:l.jsx(q_,{size:16}),activeTabs:["environment"]},{id:"settings",label:$S,icon:l.jsx(_x,{size:16}),activeTabs:["settings",...eG]}];function Qss(e){return eG.includes(e)}function Xss({tab:e,project:r,onProjectUpdate:t,onSelectTab:n,remote:s=!1}){const o=e==="settings"||Qss(e),a=A.useRef(null);return A.useLayoutEffect(()=>{const i=a.current,c=i==null?void 0:i.parentElement;if(!i||!c)return;const _=()=>i.scrollIntoView({block:"start"}),d=new ResizeObserver(_);d.observe(c),_();const f=()=>d.disconnect(),p=["wheel","touchstart","pointerdown","keydown"];for(const m of p)window.addEventListener(m,f,{passive:!0});return()=>{f();for(const m of p)window.removeEventListener(m,f)}},[e,r==null?void 0:r.id]),l.jsxs("div",{className:"settings-view max-w-readable my-0 mx-auto pt-6 px-8 pb-15 [&_h1]:mt-0 [&_h1]:mx-0 [&_h1]:mb-1.5 [&_h1]:text-3xl [&_>_.error]:text-accent-red [&_>_.error]:text-base [&_>_.error]:whitespace-pre-wrap [&_>_.error]:mt-0 [&_>_.error]:mx-0 [&_>_.error]:mb-3",children:[o&&l.jsxs(l.Fragment,{children:[l.jsx("h1",{children:$S()}),l.jsxs("div",{className:"settings-stack mt-4.5",children:[l.jsx("section",{className:Tf,children:l.jsx(Mss,{})}),l.jsx("section",{ref:e==="projects"?a:void 0,className:Tf,children:l.jsx(Iss,{remote:s,onProjectUpdate:t})}),l.jsx("section",{ref:e==="harnesses"?a:void 0,className:Tf,children:l.jsx(ass,{remote:s})}),l.jsx("section",{className:Tf,children:l.jsx(Bss,{})}),!s&&l.jsx("section",{ref:e==="storage"?a:void 0,className:Tf,children:l.jsx(Uss,{})}),l.jsx("section",{className:Tf,children:l.jsx(Lss,{})}),!s&&l.jsx("section",{className:Tf,children:l.jsx($ss,{})})]})]}),e==="compute"&&l.jsx(jss,{project:r,onViewHistory:()=>n("instances"),onOpenEnvironment:()=>n("environment"),remote:s}),e==="instances"&&l.jsx(Kss,{projectId:r==null?void 0:r.id,onBack:()=>n("compute")}),e==="environment"&&l.jsxs(l.Fragment,{children:[l.jsx("h1",{children:fI()}),l.jsx(Ass,{})]})]})}function n0(e){const r=e.split("@")[0].replace(/[~^]$/,"");return r.charAt(0).toUpperCase()+r.slice(1).replaceAll("-"," ")}function KC(e){return e.replace(/@personal$|\^$/,"@u").replace(/@project$|~$/,"@p")}function yj(e){return`${e.plugin?`${n0(e.plugin)}: `:""}${n0(e.name)}`}const tG=["plan","goal","new","resume","model","compact","copy","export","side"],Yss={plan:()=>rdr(),goal:()=>ID(),new:()=>VPt(),resume:()=>z5r(),model:()=>w$t(),compact:()=>Pst(),copy:()=>Ilt(),export:()=>o1t(),side:()=>ahn()};function Zss(e,r){const t=e==="compact"&&!r;return{name:e,disabled:t,get description(){return t?W7e():Yss[e]()},source:"command"}}function n2(e){return tG.some(r=>r===e)}const jy={clear:"new",summarize:"compact"};function xj(e){const r=e.toLowerCase();return n2(r)?r:Object.hasOwn(jy,r)?jy[r]:null}function rG(e){return Object.keys(jy).filter(r=>jy[r]===e)}function Jss(e,r){return e.name.toLowerCase().startsWith(r)||e.plugin&&`${e.plugin}:${e.name}`.toLowerCase().startsWith(r)?!0:e.source==="command"&&n2(e.name)&&rG(e.name).some(t=>t.startsWith(r))}function k4(e,r){if(r<0||r>e.length)return null;let t=r;for(;t>0&&!/\s/.test(e[t-1]);)t-=1;if(e[t]!=="/")return null;let n=r;for(;n=n?d:s}${a.slice(d.length)}`:s+a}const i=((_=/^[ \t]+/.exec(a))==null?void 0:_[0].length)??0;return{text:`${o}/${t}${a}`,cursor:o.length+t.length+1+i}}function rO(e,r){let t=e.slice(0,r.start),n=e.slice(r.end);return t?n?/\s$/.test(t)&&/^\s/.test(n)&&(n=n.slice(1)):t=t.replace(/\s$/,""):n=n.replace(/^\s/,""),{text:t+n,cursor:t.length}}function nG(e){return tG.filter(r=>r!=="plan"||e)}function ros(e,r,t=!1){const n=e.filter(s=>!xj(s.name));for(const s of nG(r))n.push(Zss(s,t));return n.sort((s,o)=>+(o.source==="command")-+(s.source==="command")||yj(s).localeCompare(yj(o),void 0,{sensitivity:"base"}))}function j4(e){return e==="plan"||e==="goal"||e==="side"}function nos(e,r){for(const t of nG(r).sort((n,s)=>+(n==="plan")-+(s==="plan"))){const n=[t,...rG(t)].join("|");if(t==="plan"){const s=new RegExp(`(^|\\s)\\/(?:${n})(?=\\s|$)`,"gi");if(s.test(e))return{name:t,prompt:e.replace(s,"").trim()}}else if(t==="goal"||t==="side"){const s=new RegExp(`^\\/(?:${n})(?=\\s|$)`,"i");if(s.test(e.trim()))return{name:t,prompt:e.trim().replace(s,"").trim()}}else if(new RegExp(`^\\/(?:${n})$`,"i").test(e.trim()))return{name:t,prompt:""}}return null}function S4(e,r,t){if(e==="command")return r!==void 0?r:t??void 0}const sos=["font-family","font-size","font-weight","font-style","font-variant","line-height","letter-spacing","word-spacing","text-transform","direction","unicode-bidi","tab-size","padding-top","padding-right","padding-bottom","padding-left","border-top-width","border-right-width","border-bottom-width","border-left-width"];let oos=null;function nO(e,r){const t=oos??(oos=document.createElement("canvas").getContext("2d"));if(!t||!r)return 6;const n=getComputedStyle(r);t.font=`${n.fontStyle} ${n.fontWeight} ${n.fontSize} ${n.fontFamily}`;const s=20+t.measureText(n0(e)).width-t.measureText(`/${e}`).width;return Math.max(1,Math.ceil((s+6)/t.measureText(" ").width))}const aos={plan:eBn,goal:JP,new:DBn,resume:WPn,model:YS,compact:SPn,copy:Md,export:ix,side:Ig};function sG({name:e,className:r}){const t=n2(e)?aos[e]:XBn;return l.jsx(t,{size:16,strokeWidth:1.5,className:r,"aria-hidden":"true"})}function oG({name:e}){return l.jsxs(l.Fragment,{children:[l.jsx(sG,{name:e,className:"me-1 inline-block align-middle"}),n0(e)]})}function aG(e,r,t,n,s,o=!1){let a=0;return eos(e,r).map((i,c,_)=>{var m,w;const d=a+i.text.length;a=d;const f=i.text.slice(1).toLowerCase();if(i.command&&s)return s(i.text,f,d,c);let p=i.text;return o||((m=_[c-1])!=null&&m.command&&(p=p.replace(/^[ \t]+/," ")),(w=_[c+1])!=null&&w.command&&(p=p.replace(/[ \t]+$/," "))),i.command?l.jsx("span",{className:t,onMouseDown:void 0,children:l.jsx(oG,{name:f})},c):o?l.jsx("span",{"aria-hidden":"true",children:i.text},c):l.jsx(A.Fragment,{children:p},c)})}function ios({label:e,name:r,end:t,skill:n,projectId:s,textareaRef:o}){const a=A.useRef(null),i=A.useRef(null),c=A.useRef(null),_=A.useId(),[d,f]=A.useState(!1),p=nt({...cLn(r,s,n.harness),enabled:d,subscribed:d}),m=p.data??null,w=p.isFetching,[y,v]=A.useState({}),x=()=>{c.current!==null&&window.clearTimeout(c.current),c.current=null},k=()=>{const C=a.current;if(!C)return;const N=C.getBoundingClientRect(),T=Math.min(420,window.innerWidth-32),E=Math.max(16,Math.min(N.left-4,window.innerWidth-T-16));v(N.top>300?{bottom:window.innerHeight-N.top+12,left:E,width:T}:{left:E,top:N.bottom+12,width:T})},b=()=>{x(),k(),f(!0)},S=()=>{x(),c.current=window.setTimeout(()=>f(!1),120)};return A.useEffect(()=>()=>x(),[]),A.useEffect(()=>{if(!d)return;const C=()=>k();return window.addEventListener("resize",C),window.addEventListener("scroll",C,!0),()=>{window.removeEventListener("resize",C),window.removeEventListener("scroll",C,!0)}},[d]),l.jsxs(A.Fragment,{children:[l.jsxs("span",{ref:a,role:"button",tabIndex:0,"aria-controls":_,"aria-expanded":d,"aria-label":Lre({name:r}),className:"composer-chip group/skill pointer-events-auto relative z-1 inline-grid align-baseline cursor-text rounded-md bg-background text-skill-blue",onMouseEnter:b,onMouseLeave:S,onFocus:b,onBlur:S,onKeyDown:C=>{var N,T;if(C.key==="Escape"){f(!1);return}if(C.key==="Enter"||C.key===" "){C.preventDefault(),b();return}d&&(C.key==="ArrowDown"||C.key==="PageDown")&&(C.preventDefault(),(N=i.current)==null||N.scrollBy({top:C.key==="PageDown"?240:48,behavior:"smooth"})),d&&(C.key==="ArrowUp"||C.key==="PageUp")&&(C.preventDefault(),(T=i.current)==null||T.scrollBy({top:C.key==="PageUp"?-240:-48,behavior:"smooth"}))},onMouseDown:C=>{var N,T;C.preventDefault(),(N=o.current)==null||N.focus(),(T=o.current)==null||T.setSelectionRange(t,t),x()},children:[l.jsx("span",{className:"invisible col-start-1 row-start-1","aria-hidden":"true",children:e}),l.jsx("span",{className:"relative z-1 col-start-1 row-start-1 w-0 whitespace-nowrap",children:l.jsxs("span",{className:"relative inline-block",children:[l.jsx("span",{className:"pointer-events-none absolute -inset-[7px] rounded-md bg-skill-blue-subtle opacity-0 transition-opacity group-hover/skill:opacity-100"}),l.jsx("span",{className:"relative text-skill-blue",children:l.jsx(oG,{name:r})})]})})]}),d&&to.createPortal(l.jsxs("div",{id:_,ref:i,role:"dialog","aria-label":gse({name:r}),style:{...y,maxHeight:"min(28rem, calc(100vh - 2rem))"},className:"fixed z-100 overflow-y-auto rounded-lg border border-border bg-background shadow-dropdown",onMouseEnter:x,onMouseLeave:S,onFocus:x,onBlur:S,onMouseDown:C=>C.stopPropagation(),children:[l.jsxs("div",{className:"sticky top-0 z-1 flex items-center gap-2 border-b border-border-variant bg-background px-4 py-3",children:[l.jsx("span",{className:"text-sm font-medium text-muted",children:n0(r)}),l.jsx(tr,{className:"h-5 border-border-variant bg-surface px-1.5 tracking-wider",children:cmn()})]}),l.jsx("div",{className:"p-4 text-sm text-text",children:w&&m===null?l.jsx("span",{className:"text-muted",children:vmn()}):l.jsx(xc,{text:m??n.description})})]}),document.body)]})}function cos({text:e,isCommand:r}){return l.jsx(l.Fragment,{children:aG(e,r,"skill-chip me-0.5 whitespace-nowrap font-normal text-skill-blue")})}function los({text:e,editingTokenEnd:r,isCommand:t,skills:n,projectId:s,textareaRef:o}){const a=A.useRef(null);return A.useLayoutEffect(()=>{const i=o.current,c=a.current;if(!i||!c)return;const _=()=>{const f=getComputedStyle(i);for(const p of sos)c.style.setProperty(p,f.getPropertyValue(p));c.style.width=`${i.clientWidth+parseFloat(f.borderLeftWidth)+parseFloat(f.borderRightWidth)}px`};_();const d=new ResizeObserver(_);return d.observe(i),()=>d.disconnect()},[e,o]),A.useLayoutEffect(()=>{const i=o.current;if(!i)return;const c=()=>{a.current&&(a.current.scrollTop=i.scrollTop)};return c(),i.addEventListener("scroll",c),()=>i.removeEventListener("scroll",c)},[o,e]),l.jsxs("div",{ref:a,className:"composer-chips pointer-events-none absolute inset-y-0 start-0 z-2 box-border overflow-hidden whitespace-pre-wrap break-words border-solid border-transparent text-transparent select-none",children:[aG(e,t,"",void 0,(i,c,_,d)=>{if(_===r)return l.jsx("span",{"aria-hidden":"true",children:i},`${d}:${_}`);const f=n.find(p=>p.name===KC(c));return f&&f.source!=="command"?l.jsx(ios,{label:i,name:c,end:_,skill:f,projectId:s,textareaRef:o},`${d}:${_}`):l.jsxs("span",{"aria-hidden":"true",className:"bg-background text-skill-blue",children:[l.jsx("span",{className:"text-skill-blue-slash",children:"/"}),i.slice(1)]},`${d}:${_}`)},!0),"​"]})}function uos({skills:e,activeIndex:r,onPick:t,onHover:n}){const s=A.useRef(null);return A.useLayoutEffect(()=>{var o;(o=s.current)==null||o.scrollIntoView({block:"nearest"})},[r,e]),l.jsx("div",{className:"skill-menu absolute bottom-[calc(100%_+_8px)] start-0 w-full max-h-[min(18rem,40vh)] overflow-y-auto overscroll-contain p-1.5 bg-background border border-border-variant rounded-lg shadow-control-subtle z-50",children:e.map((o,a)=>l.jsxs("button",{ref:a===r?s:void 0,type:"button",disabled:o.disabled,title:o.disabled?o.description:void 0,className:`skill-item flex items-center gap-2 w-full text-start py-1 px-2 rounded-sm text-sm font-normal text-text/80 disabled:opacity-50 disabled:cursor-not-allowed [&.active]:bg-hover-muted [&.active]:text-text ${a===r?"active":""}`,onMouseDown:i=>{i.preventDefault(),t(o)},onMouseEnter:()=>{o.disabled||n(a)},children:[l.jsx(sG,{name:o.name,className:"shrink-0"}),l.jsx("span",{className:"skill-name shrink-0",children:yj(o)}),l.jsx("span",{className:"skill-desc min-w-0 truncate text-muted",children:o.description}),o.source==="user"&&l.jsx("span",{className:"ms-auto shrink-0 ps-2 text-muted",children:Emn()}),o.source==="project"&&l.jsx("span",{className:"ms-auto shrink-0 ps-2 text-muted",children:Szt()})]},o.name))})}const iG=/\.(md|mdx|markdown)$/i,_os=/\.tex$/i,cG=/\.html?$/i,fos=/\.(apng|avif|bmp|gif|heic|heif|ico|jpe?g|jfif|jxl|pbm|pgm|png|pnm|ppm|svg|tiff?|webp)$/i;function lG(e){return iG.test(e)}function dos(e){return _os.test(e)}function hos(e){return cG.test(e)}const pos="[&.blue]:text-accent-blue [&.amber]:text-accent-amber [&.orange]:text-accent-orange [&.red]:text-accent-red [&.green]:text-accent-green [&.purple]:text-accent-purple [&.teal]:text-accent-teal [&.subtext]:text-subtext [&.muted]:text-muted",mos=[[/^\.git(ignore|attributes|modules|keep)$/i,"git","orange"],[/(\.lockb?|^package-lock\.json|^pnpm-lock\.yaml)$/i,"lock","muted"],[/^\.(env(\..+)?|envrc|python-version|nvmrc|node-version|editorconfig|prettierrc|npmrc|flake8)$/i,"config","subtext"],[/^(dockerfile(\..+)?|.+\.dockerfile|\.dockerignore|makefile|procfile)$/i,"config","blue"],[/\.(py|pyi|pyw)$/i,"python","blue"],[/\.ipynb$/i,"notebook","orange"],[iG,"markdown","blue"],[/\.(json|jsonc|jsonl|json5)$/i,"json","amber"],[/\.(toml|ini|cfg|conf|properties)$/i,"config","subtext"],[/\.ya?ml$/i,"yaml","purple"],[/\.(sh|bash|zsh|fish|ps1|bat|cmd)$/i,"shell","green"],[/\.(tsx|jsx)$/i,"react","teal"],[/\.(ts|mts|cts)$/i,"ts","blue"],[/\.(js|mjs|cjs)$/i,"js","amber"],[/\.rs$/i,"rust","orange"],[/\.(css|scss|sass|less)$/i,"css","blue"],[cG,"code","orange"],[/\.(c|h|cc|cpp|hpp|cu|cuh)$/i,"code","purple"],[/\.(go|swift|kt|java|scala|rb|php|lua|jl|r|sql|proto)$/i,"code","teal"],[fos,"image","purple"],[/\.(csv|tsv|xlsx?|ods)$/i,"spreadsheet","green"],[/\.(parquet|arrow|feather|h5|hdf5|npy|npz|pkl|pickle|pt|pth|ckpt|safetensors|gguf|bin|onnx|db|sqlite3?)$/i,"data","teal"],[/\.(7z|bz2|gz|rar|tar|tgz|xz|zip|zst)$/i,"archive","amber"],[/\.pdf$/i,"pdf","red"],[/\.(tex|bib|sty|cls)$/i,"document","teal"],[/\.(docx?|log|rtf|txt|out|err)$/i,"document","subtext"]],sO=l.jsxs(l.Fragment,{children:[l.jsx("path",{d:"M3 1.5h6l4 4v9H3v-13Z",fill:"currentColor",opacity:".2"}),l.jsx("path",{d:"M9 1.5v4h4",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]});function gos(e){switch(e){case"python":{const r="M7.9 1.5C5.6 1.5 5.2 2.5 5.2 3.6V5h3.1v.7H3.7c-1.3 0-2.2.9-2.2 2.7s.8 2.6 2.1 2.6h.8V9.4c0-1.2.9-2.1 2.1-2.1h2.9c1 0 1.8-.8 1.8-1.8V3.6c0-1.1-1-2.1-3.3-2.1Zm-1.3.9a.7.7 0 1 1 0 1.4.7.7 0 0 1 0-1.4Z";return l.jsxs(l.Fragment,{children:[l.jsx("path",{d:r,fill:"currentColor",fillRule:"evenodd"}),l.jsx("path",{d:r,className:"text-accent-amber",fill:"currentColor",fillRule:"evenodd",transform:"rotate(180 8 8)"})]})}case"notebook":return l.jsxs(l.Fragment,{children:[l.jsx("path",{d:"M2.5 6a5.8 3.2 0 0 1 11 0M2.5 10a5.8 3.2 0 0 0 11 0",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),l.jsx("circle",{cx:"12.6",cy:"2.6",r:"1.1",fill:"currentColor"}),l.jsx("circle",{cx:"3.2",cy:"13.6",r:"1.1",fill:"currentColor"})]});case"markdown":return l.jsxs(l.Fragment,{children:[l.jsx("path",{d:"M1 3h14v10H1z",fill:"currentColor",opacity:".18"}),l.jsx("path",{d:"M2.6 10.5v-5h1.2l1.6 2 1.6-2h1.2v5H6.8V7.6L5.4 9.3 4 7.6v2.9H2.6Zm8.5-5v2.4h1.3L10.5 10 8.6 7.9h1.3V5.5h1.2Z",fill:"currentColor"})]});case"json":{const r="M5.6 2.5c-1.4 0-1.8.7-1.8 1.9v1.7c0 1-.4 1.5-1.3 1.9.9.4 1.3.9 1.3 1.9v1.7c0 1.2.4 1.9 1.8 1.9";return l.jsxs(l.Fragment,{children:[l.jsx("path",{d:r,fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),l.jsx("path",{d:r,fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",transform:"matrix(-1 0 0 1 16 0)"}),l.jsx("circle",{cx:"8",cy:"8",r:"1",fill:"currentColor"})]})}case"config":return l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:"8",cy:"8",r:"3.6",fill:"none",stroke:"currentColor",strokeWidth:"2.2"}),l.jsx("path",{d:"M8 1.4v2.2M8 12.4v2.2M1.4 8h2.2M12.4 8h2.2M3.3 3.3l1.6 1.6M11.1 11.1l1.6 1.6M3.3 12.7l1.6-1.6M11.1 4.9l1.6-1.6",stroke:"currentColor",strokeWidth:"2"})]});case"lock":return l.jsxs(l.Fragment,{children:[l.jsx("path",{d:"M5 7.2V5.2a3 3 0 0 1 6 0v2",fill:"none",stroke:"currentColor",strokeWidth:"1.5"}),l.jsx("rect",{x:"3",y:"7",width:"10",height:"7.5",rx:"1.5",fill:"currentColor"})]});case"git":return l.jsxs(l.Fragment,{children:[l.jsx("path",{d:"M8 1.5 14.5 8 8 14.5 1.5 8Z",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round"}),l.jsx("path",{d:"M5.4 4.3 8 6.6v4M8 6.6l2.3 2.1",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),l.jsx("circle",{cx:"8",cy:"6.6",r:"1.1",fill:"currentColor"}),l.jsx("circle",{cx:"8",cy:"10.8",r:"1.1",fill:"currentColor"}),l.jsx("circle",{cx:"10.4",cy:"8.8",r:"1.1",fill:"currentColor"})]});case"shell":return l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5",fill:"currentColor",opacity:".18"}),l.jsx("path",{d:"m4 6 2.2 2L4 10M7.8 10.5h4",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]});case"ts":case"js":return l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"1.5",fill:"currentColor"}),l.jsx("text",{x:"13.4",y:"13.2",textAnchor:"end",fontSize:"7",fontWeight:"700",fontFamily:"system-ui, sans-serif",className:e==="ts"?"fill-white":"fill-black",children:e==="ts"?"TS":"JS"})]});case"react":return l.jsxs(l.Fragment,{children:[l.jsxs("g",{fill:"none",stroke:"currentColor",strokeWidth:"1",children:[l.jsx("ellipse",{cx:"8",cy:"8",rx:"6.5",ry:"2.5"}),l.jsx("ellipse",{cx:"8",cy:"8",rx:"6.5",ry:"2.5",transform:"rotate(60 8 8)"}),l.jsx("ellipse",{cx:"8",cy:"8",rx:"6.5",ry:"2.5",transform:"rotate(120 8 8)"})]}),l.jsx("circle",{cx:"8",cy:"8",r:"1.3",fill:"currentColor"})]});case"rust":return l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:"8",cy:"8",r:"5.6",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeDasharray:"1.5 1.013"}),l.jsx("text",{x:"8",y:"10.6",textAnchor:"middle",fontSize:"7.5",fontWeight:"700",fontFamily:"system-ui, sans-serif",fill:"currentColor",children:"R"})]});case"css":return l.jsx("path",{d:"M6.3 2.5 5 13.5M11 2.5 9.7 13.5M2.8 6h11M2.2 10h11",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"});case"code":return l.jsx("path",{d:"M6.2 3 1.8 8l4.4 5 1.3-1.2L4.2 8l3.3-3.8L6.2 3Zm3.6 0-1.3 1.2L11.8 8l-3.3 3.8 1.3 1.2 4.4-5-4.4-5Z",fill:"currentColor"});case"yaml":return l.jsxs(l.Fragment,{children:[l.jsx("path",{d:"M2.5 3.5h6M5 8h8.5M5 12.5h6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),l.jsx("circle",{cx:"3",cy:"8",r:".9",fill:"currentColor"}),l.jsx("circle",{cx:"3",cy:"12.5",r:".9",fill:"currentColor"})]});case"image":return l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:"1.5",y:"2",width:"13",height:"12",rx:"2",fill:"currentColor",opacity:".18"}),l.jsx("circle",{cx:"5",cy:"5.5",r:"1.4",fill:"currentColor"}),l.jsx("path",{d:"m2.8 12 3.3-3.5 2.2 2 2.1-2.5 2.8 4H2.8Z",fill:"currentColor"})]});case"spreadsheet":return l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:"2",y:"1.5",width:"12",height:"13",rx:"1.5",fill:"currentColor",opacity:".2"}),l.jsx("path",{d:"M3.5 4.5h9M3.5 8h9M3.5 11.5h9M7 3v10M10.5 3v10",stroke:"currentColor",strokeWidth:"1.1"})]});case"data":{const r="M2.5 3.8v8.4c0 1.2 2.5 2.3 5.5 2.3s5.5-1.1 5.5-2.3V3.8";return l.jsxs(l.Fragment,{children:[l.jsx("path",{d:r,fill:"currentColor",opacity:".2"}),l.jsx("ellipse",{cx:"8",cy:"3.8",rx:"5.5",ry:"2.3",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),l.jsx("path",{d:`${r}M2.5 8c0 1.2 2.5 2.3 5.5 2.3s5.5-1.1 5.5-2.3`,fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}case"archive":return l.jsxs(l.Fragment,{children:[l.jsx("path",{d:"M2 2h12v12H2z",fill:"currentColor",opacity:".18"}),l.jsx("path",{d:"M7 2h2v2H7V2Zm0 3h2v2H7V5Zm0 3h2v2H7V8Zm-0.5 3h3v2h-3v-2Z",fill:"currentColor"})]});case"pdf":return l.jsxs(l.Fragment,{children:[sO,l.jsx("text",{x:"8",y:"12.6",textAnchor:"middle",fontSize:"4.6",fontWeight:"800",fontFamily:"system-ui, sans-serif",fill:"currentColor",children:"PDF"})]});case"document":return l.jsxs(l.Fragment,{children:[sO,l.jsx("path",{d:"M5 8h6M5 10.5h6M5 13h4",stroke:"currentColor",strokeWidth:"1.2"})]})}}function yd({name:e}){const r=e.slice(e.lastIndexOf("/")+1),t=mos.find(([o])=>o.test(r)),n=(t==null?void 0:t[1])??"document",s=(t==null?void 0:t[2])??"subtext";return l.jsx("svg",{className:`file-tree-icon w-[15px] h-[15px] shrink-0 overflow-visible select-none ${pos} ${s}`,viewBox:"0 0 16 16","aria-hidden":"true",children:gos(n)})}function vos({matches:e,activeIndex:r,onPick:t,onHover:n}){const s=A.useRef(null);return A.useLayoutEffect(()=>{var o;(o=s.current)==null||o.scrollIntoView({block:"nearest"})},[r,e]),l.jsx("div",{className:"file-mention-menu absolute bottom-[calc(100%_+_8px)] start-0 w-full max-h-[min(18rem,40vh)] overflow-y-auto overscroll-contain p-1.5 bg-background border border-border-variant rounded-lg shadow-control-subtle z-50",children:e.map((o,a)=>{const{name:i,parent:c}=zYn(o.path);return l.jsxs("button",{ref:a===r?s:void 0,type:"button",className:`file-mention-item flex items-center gap-2 w-full text-start py-1 px-2 rounded-sm text-sm font-normal text-text/80 [&.active]:bg-hover-muted [&.active]:text-text ${a===r?"active":""}`,onMouseDown:_=>{_.preventDefault(),t(o)},onMouseEnter:()=>n(a),children:[o.directory?l.jsx(ZP,{size:16,className:"shrink-0 text-muted"}):l.jsx(yd,{name:i}),l.jsx("span",{className:"shrink-0",dir:"ltr",children:i}),c&&l.jsx("span",{className:"min-w-0 truncate text-muted",dir:"ltr",children:c})]},o.path)})})}function bos(e){return e>=95?"var(--accent-red)":e>=80?"var(--accent-amber)":"var(--subtext)"}const wj=6.5,oO=2*Math.PI*wj;function yos({usage:e}){return!e||e.usedTokens<=0?null:l.jsx(xos,{usage:e})}function xos({usage:e}){const{open:r,setOpen:t,ref:n}=Na(),{usedTokens:s,contextWindow:o}=e,a=o&&o>0?Math.min(100,Math.round(s/o*100)):null,i=a===null?"var(--subtext)":bos(a),c=a===null?"":new Intl.NumberFormat(z(),{style:"percent"}).format(a/100);return l.jsxs("div",{className:"option-picker relative inline-flex shrink-0",ref:n,children:[l.jsx("button",{type:"button",className:`${a===null?"inline-flex h-8 items-center rounded-md px-1 transition-[background,color] duration-150 ease-standard hover:bg-surface":"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-text transition-[background,color] duration-150 ease-standard hover:bg-surface"} composer-bare context-ring text-sm text-text`,title:clt(),onClick:()=>t(_=>!_),children:a===null?iv(s):l.jsxs("svg",{viewBox:"0 0 16 16",width:"16",height:"16","aria-hidden":"true",children:[l.jsx("circle",{cx:"8",cy:"8",r:wj,fill:"none",stroke:"var(--border)",strokeWidth:"2.5"}),l.jsx("circle",{cx:"8",cy:"8",r:wj,fill:"none",stroke:i,strokeWidth:"2.5",strokeLinecap:"round",strokeDasharray:`${oO*Math.max(a,2)/100} ${oO}`,transform:"rotate(-90 8 8)"})]})}),r&&l.jsxs("div",{className:"option-menu absolute bottom-[calc(100%_+_8px)] start-0 max-h-95 flex flex-col bg-background border border-border rounded-lg shadow-menu z-50 overflow-hidden min-w-47.5 [&.align-right]:start-auto [&.align-right]:end-0 [&.drop-down]:bottom-auto [&.drop-down]:top-[calc(100%_+_4px)] [&.session-menu]:start-auto [&.session-menu]:end-1.5 [&.session-menu]:top-[calc(100%_-_2px)] [&.session-menu]:min-w-35 align-right context-meter-menu w-70 pt-2.5 px-3 pb-3 [&_.progress]:mt-2 [&_.progress]:mx-0 [&_.progress]:mb-0 [&_.progress-track]:h-[5px] [&_.progress-track]:border-0 [&_.progress-track]:bg-border",children:[l.jsxs("div",{className:"context-meter-head flex justify-between items-baseline gap-3 text-sm text-muted",children:[l.jsx("span",{children:Zct()}),l.jsx("span",{className:"context-meter-value text-text tabular-nums",children:a===null?vlt({value:Ae(iv(s))}):Elt({used:Ae(iv(s)),total:Ae(iv(o)),percent:Ae(c)})})]}),a!==null&&l.jsx(qU,{value:s,max:o,fillColor:i})]})]})}function wos(e,r,t){const n=e.map(t);return r<0?n:[...n.slice(0,r),l.jsxs("div",{role:"group","aria-label":qN(),children:[l.jsx("div",{className:"px-2.5 pb-1 pt-2.5 text-sm font-medium text-subtext",children:qN()}),n.slice(r)]},"from-terminal")]}function kos({activeSessionId:e,onClose:r,onResume:t,onImport:n}){const s=A.useRef(null),o=A.useRef(null),{data:a,isPending:i,error:c}=nt(ELn()),{data:_=[]}=nt(P_()),{data:d=[]}=nt(pP()),[f,p]=A.useState(""),[m,w]=A.useState(0);Rd(s,r);const y=A.useMemo(()=>new Map(_.map(C=>[C.id,C.name])),[_]),v=A.useMemo(()=>{const C=f.trim().toLowerCase(),N=R=>!C||R.toLowerCase().includes(C),T=(a??[]).filter(R=>R.id!==e).filter(R=>N(`${R.title??""} ${y.get(R.projectId)??""} ${Hf(R.harness,R.harnessName)}`)).map(R=>({kind:"session",key:R.id,session:R})),E=d.filter(R=>N(`${R.title??""} ${R.cwd??""} ${Hf(R.harness)}`)).map(R=>({kind:"native",key:`${R.harness}:${R.nativeId}`,chat:R}));return[...T,...E]},[a,d,f,e,y]),x=A.useMemo(()=>v.findIndex(C=>C.kind==="native"),[v]),k=Math.min(m,Math.max(0,v.length-1));A.useLayoutEffect(()=>{var C;(C=o.current)==null||C.scrollIntoView({block:"nearest"})},[k,v]);const b=C=>(C==null?void 0:C.split("/").filter(Boolean).at(-1))??"",S=C=>C.kind==="native"?n(C.chat):t(C.session);return to.createPortal(l.jsx("div",{className:"fixed inset-0 z-200 flex items-start justify-center bg-modal-backdrop p-5 pt-[var(--modal-top)]",onClick:C=>{C.target===C.currentTarget&&r()},children:l.jsxs("div",{ref:s,className:"flex max-h-[calc(100vh_-_var(--modal-top)_-_1.25rem)] w-140 max-w-full flex-col rounded-xl border border-border bg-background shadow-modal",role:"dialog","aria-modal":"true","aria-label":GN(),tabIndex:-1,children:[l.jsx("div",{className:"border-b border-border p-3",children:l.jsx(yn,{"data-initial-focus":!0,value:f,placeholder:UN(),"aria-label":UN(),role:"combobox","aria-autocomplete":"list","aria-expanded":v.length>0,"aria-controls":"resume-options","aria-activedescendant":v[k]?`resume-option-${v[k].key}`:void 0,onChange:C=>{p(C.target.value),w(0)},onKeyDown:C=>{if(!C.nativeEvent.isComposing)if(C.key==="ArrowDown"||C.key==="ArrowUp"){if(C.preventDefault(),v.length===0)return;const N=C.key==="ArrowDown"?1:-1;w((k+N+v.length)%v.length)}else C.key==="Enter"&&v[k]&&(C.preventDefault(),S(v[k]))}})}),l.jsx("div",{id:"resume-options",className:"min-h-0 flex-1 overflow-y-auto p-1.5",role:v.length>0?"listbox":void 0,"aria-label":v.length>0?GN():void 0,children:i?l.jsxs(ys,{className:"px-2.5 py-2",role:"status",children:[l.jsx($t,{})," ",Yy()]}):c&&!a?l.jsx("div",{className:"px-2.5 py-2 text-sm text-accent-red",role:"alert",children:wS({error:Ae(c instanceof Error?c.message:String(c))})}):v.length===0?l.jsx("div",{className:"px-2.5 py-2 text-sm text-muted",role:"status",children:D5r()}):wos(v,x,(C,N)=>{var $;const T=C.kind==="native"?C.chat:null,E=C.kind==="session"?C.session:null;return l.jsxs(cr,{id:`resume-option-${C.key}`,ref:N===k?o:void 0,type:"button",role:"option","aria-selected":N===k,active:N===k,tabIndex:-1,className:"gap-2.5 text-text",onMouseEnter:()=>w(N),onClick:()=>S(C),children:[l.jsx(gd,{harness:(T==null?void 0:T.harness)??(E==null?void 0:E.harness)??"claude-code"}),l.jsx("span",{dir:"auto",className:"min-w-0 flex-1 truncate",children:(($=(T==null?void 0:T.title)??(E==null?void 0:E.title))==null?void 0:$.trim())||sb()}),l.jsx("span",{dir:"auto",className:"max-w-40 shrink-0 truncate text-muted",title:(T==null?void 0:T.cwd)??void 0,children:T?b(T.cwd):y.get((E==null?void 0:E.projectId)??"")??""}),l.jsx("span",{className:"shrink-0 text-muted tabular-nums",children:$i((T==null?void 0:T.updatedAt)??(E==null?void 0:E.updatedAt)??0)})]},C.key)})})]})}),document.body)}const Sy="!";function aO(e){return e.startsWith(Sy)?e.slice(Sy.length).trim():null}function jos(e){return e.startsWith(Sy)?e.slice(Sy.length):e}function Sos(e){return e.replace(/([\\`*_[\]<>$~])/g,"\\$1").replace(/(^|\n)(\s*)(#{1,6}|>|[-+]|\d+\.)\s/g,"$1$2\\$3 ").replace(/(^|\n)(\s*)(=+|-{1,2})(?=\s*(?:\n|$))/g,"$1$2\\$3").replace(/(^|\n)(\s*)(-{3,})(?=\s*(?:\n|$))/g,"$1$2\\$3")}function Cos(e){const r=Math.max(0,...Array.from(e.matchAll(/`+/g),s=>s[0].length)),t="`".repeat(r+1),n=/^[\s`]|[\s`]$/.test(e)?` ${e} `:e;return`${t}${n}${t}`}function zos(e){const r=Math.max(0,...Array.from(e.matchAll(/`+/g),n=>n[0].length)),t="`".repeat(Math.max(3,r+1));return` ${t} @@ -1219,7 +1219,7 @@ ${r.trim()} ${X.error}`:X.text,children:[X.dispatchState==="blocked"?l.jsx(e6,{size:14,className:"shrink-0 text-accent-amber"}):l.jsx(lPn,{size:14,className:"shrink-0 text-muted"}),l.jsx("span",{className:"flex-1 overflow-hidden text-ellipsis whitespace-nowrap text-text",children:X.text}),X.dispatchState!=="blocked"&&l.jsx("span",{className:"shrink-0 text-sm text-muted",children:X.dispatchState==="retrying"?KYn(X.nextRetryAt,$c):MQe()}),X.dispatchState==="blocked"?l.jsxs(l.Fragment,{children:[l.jsx("button",{onClick:()=>void fe(X.id),"aria-label":wne({text:X.text}),disabled:Ma!==null,className:"shrink-0 px-1.5 py-0.5 border border-border rounded-sm text-sm text-text bg-background cursor-pointer disabled:opacity-50 disabled:cursor-default [&:hover:not(:disabled)]:border-border-hover-strong",children:Ma===X.id?oI():_s()}),l.jsx("button",{onClick:()=>Z(X.id),"aria-label":fne({text:X.text}),disabled:Ma!==null,className:"shrink-0 px-1.5 py-0.5 border-0 text-sm text-muted bg-transparent cursor-pointer disabled:opacity-50 disabled:cursor-default [&:hover:not(:disabled)]:text-text",children:kD()}),le===Zp&&leZ(X.id),className:"shrink-0 inline-flex items-center justify-center w-4 h-4 p-0 border-0 rounded-full text-muted cursor-pointer [&:hover]:bg-text [&:hover]:text-background",children:l.jsx(hn,{size:12})})]},X.id))}),rc&&l.jsxs("div",{id:qa,role:"note",className:`composer-demo-hint ${Uas}`,children:[l.jsxs("span",{className:"flex-1",dir:"auto",children:[l.jsx(H_,{size:16,className:"inline-block align-text-bottom me-2 text-subtext"}),X$e()]}),l.jsx(xt,{size:"small","aria-label":$E(),title:$E(),onClick:()=>{var X;mn(!0),(X=Xn.current)==null||X.focus()},children:l.jsx(hn,{size:14})})]}),!$&&!Ie&&c&&l.jsx(aYn,{projects:ae,activity:ee,projectId:e,projectName:r,onNewProject:c,onSelect:X=>{X!==e&&_e({to:"/projects/$projectId/tasks/new",params:{projectId:X}})}}),l.jsxs("div",{className:`composer-box relative flex flex-col border ${Ho?"border-accent-amber":"border-border"} rounded-lg bg-background shadow-control-subtle`,"data-onboarding":"composer",children:[Qe&&!Qe.agentReady&&l.jsx("div",{className:"composer-harness-warning py-2 px-3 text-subtext text-sm leading-normal border-b border-b-border-variant [&_strong]:text-accent-amber [&_strong]:font-medium [&_code]:font-mono [&_code]:text-text",children:Qe.catalogPending?l.jsxs("span",{children:[Qe.name," — ",dd()]}):l.jsxs(l.Fragment,{children:[l.jsxs("strong",{children:[Qe.name," ",UDe()]})," ",Qe.agentNote?U_(Qe.agentNote,P&&{canRun:X=>Fd(X)!==void 0,onRun:X=>{const le=Fd(X);le&&P(X,le)}}):ZQe()]})}),Nc&&l.jsx(uos,{skills:la,activeIndex:zl,onPick:Zn,onHover:ia}),lf&&l.jsx(vos,{matches:Gi,activeIndex:Vs,onPick:Sc,onHover:Ia}),Bd&&l.jsx(kos,{activeSessionId:Ie,onClose:()=>aa(!1),onResume:X=>{aa(!1),Ke("all"),C(X.id,{projectId:X.projectId})},onImport:X=>{aa(!1),Rl(X)}}),ur.length>0&&l.jsx(Kos,{annotations:ur,onClear:()=>{xr([]),window.requestAnimationFrame(()=>{var X;return(X=Xn.current)==null?void 0:X.focus()})},onRemove:X=>{const le=ur.filter(xe=>xe.id!==X);xr(le),le.length===0&&window.requestAnimationFrame(()=>{var xe;return(xe=Xn.current)==null?void 0:xe.focus()})}}),dr.length>0&&l.jsx("div",{className:"composer-attachments flex flex-wrap gap-1.5 pt-2 px-3 pb-0",children:dr.map((X,le)=>{const xe=()=>Mr(be=>be.filter((Te,ht)=>ht!==le));return X.mediaType==="application/pdf"?l.jsxs("div",{className:"attachment-file [&_button]:absolute [&_button]:-top-[5px] [&_button]:-right-[5px] [&_button]:inline-flex [&_button]:items-center [&_button]:justify-center [&_button]:w-4 [&_button]:h-4 [&_button]:p-0 [&_button]:border [&_button]:border-border [&_button]:rounded-full [&_button]:bg-surface [&_button]:text-text [&_button]:cursor-pointer [&_button:hover]:bg-text [&_button:hover]:text-background relative inline-flex items-center gap-2 max-w-55 py-2 px-2.5 border border-border rounded-sm text-text bg-surface [&_svg]:shrink-0 [&_svg]:text-muted",title:X.name,children:[l.jsx(cx,{size:22}),l.jsx("span",{className:"attachment-file-name overflow-hidden text-ellipsis whitespace-nowrap text-sm",children:X.name??"document.pdf"}),l.jsx("button",{title:WE(),"aria-label":WE(),onClick:xe,children:l.jsx(hn,{size:12})})]},le):l.jsxs("div",{className:"attachment-thumb relative [&_img]:w-13 [&_img]:h-13 [&_img]:object-cover [&_img]:border [&_img]:border-border [&_img]:rounded-sm [&_img]:block [&_button]:absolute [&_button]:-top-[5px] [&_button]:-right-[5px] [&_button]:inline-flex [&_button]:items-center [&_button]:justify-center [&_button]:w-4 [&_button]:h-4 [&_button]:p-0 [&_button]:border [&_button]:border-border [&_button]:rounded-full [&_button]:bg-surface [&_button]:text-text [&_button]:cursor-pointer [&_button:hover]:bg-text [&_button:hover]:text-background",children:[l.jsx("img",{src:X.dataUrl,alt:zD()}),l.jsx("button",{title:KE(),"aria-label":KE(),onClick:xe,children:l.jsx(hn,{size:12})})]},le)})}),(Al??Dr)&&l.jsx("div",{className:"composer-attach-error pt-1.5 px-3 pb-0 text-sm text-accent-red",role:"alert",children:Al??Dr}),Dn&&l.jsx("div",{className:"composer-settings-error pt-1.5 px-3 pb-0 text-sm text-accent-red",role:"alert",children:Dn}),l.jsxs("div",{className:`composer-input relative flex overflow-hidden [&_textarea]:flex-1 ${Ho?"[&_textarea]:font-mono [&_textarea]:text-sm":""}`,children:[l.jsx("textarea",{dir:"auto",writingsuggestions:"false",ref:Xn,"aria-describedby":rc?qa:void 0,className:"relative z-1 min-w-0 overflow-x-hidden bg-transparent",value:qt,placeholder:xi&&Qe?cZe({harness:Ae(Qe.name),shortcut:Ae(Mn)}):ar?Qe!=null&&Qe.agentReady?zEe({harness:Ae(Hf(ar.harness,Qe==null?void 0:Qe.name))}):iEe({harness:Ae(Hf(ar.harness,Qe==null?void 0:Qe.name))}):G6e(),rows:2,onPaste:$u,onDragOver:X=>{X.dataTransfer.types.includes("Files")&&X.preventDefault()},onDrop:X=>{X.dataTransfer.files.length!==0&&(X.preventDefault(),Cc(Array.from(X.dataTransfer.files)))},onChange:X=>{const le=X.target.value,xe=X.target.selectionStart;Xr(xe);const be=xe>0&&/\s/.test(le[xe-1])&&!ps.current&&aO(le)===null?k4(le,xe-1):null,Te=be&&xj(be.query),ht=be?(le.slice(0,be.start)+le.slice(be.end)).trim():"";if(be&&Te&&(Te==="plan"||Te==="goal"||!j4(Te)&&!ht)&&Pa.some(_t=>_t.name===Te)){ws(Te,le,be);return}Gt(le),Yn(!1)},onSelect:X=>Xr(X.currentTarget.selectionStart),onCompositionStart:()=>{ps.current=!0},onCompositionEnd:()=>{ps.current=!1},onKeyDown:X=>{if(ps.current||X.nativeEvent.isComposing||X.nativeEvent.keyCode===229){X.stopPropagation();return}if(Nc){if(X.key==="ArrowDown"||X.key==="ArrowUp"){X.preventDefault();const le=X.key==="ArrowDown"?1:-1;if(zl>=0){const xe=Ac.indexOf(zl);ia(Ac[(xe+le+Ac.length)%Ac.length])}return}if((X.key==="Tab"||X.key==="Enter")&&zl>=0){X.preventDefault(),Zn(la[zl]);return}if(X.key==="Escape"){X.preventDefault(),Yn(!0);return}}if(lf){if(X.key==="ArrowDown"||X.key==="ArrowUp"){X.preventDefault();const le=X.key==="ArrowDown"?1:-1;Ia((Vs+le+Gi.length)%Gi.length);return}if(X.key==="Tab"||X.key==="Enter"&&Ui!==""&&!X.shiftKey&&!X.metaKey&&!X.ctrlKey){X.preventDefault(),Sc(Gi[Vs]);return}if(X.key==="Escape"){X.preventDefault(),Yn(!0);return}}if(X.key==="Backspace"&&Cl(X.currentTarget)){X.preventDefault();return}if(X.key==="Enter"&&!X.shiftKey){if(X.preventDefault(),Ho){Vd();return}Ic({queue:X.metaKey||X.ctrlKey})}}}),l.jsx(los,{text:qt,editingTokenEnd:ao==null?void 0:ao.end,isCommand:Or,skills:Pa,projectId:e,textareaRef:Xn})]}),l.jsxs("div",{className:"composer-actions flex min-w-0 justify-end items-center gap-2 pt-1.5 px-2 pb-2",children:[l.jsxs("div",{className:"option-picker relative inline-flex shrink-0",ref:Ds.ref,children:[l.jsx(xt,{type:"button",className:"composer-bare",title:ik(),"aria-label":ik(),"aria-haspopup":"dialog","aria-expanded":Ds.open,onClick:()=>Ds.setOpen(X=>!X),children:l.jsx(qBn,{size:16})}),Ds.open&&l.jsxs("div",{className:"composer-sources-menu absolute bottom-[calc(100%_+_8px)] start-0 z-50 flex min-w-55 flex-col gap-1 rounded-lg border border-border bg-background p-2 shadow-dropdown",children:[l.jsx("span",{className:"px-1 text-sm font-medium text-muted",children:ik()}),l.jsx(sZn,{})]})]}),l.jsx("input",{ref:or,type:"file",accept:"application/pdf,image/png,image/jpeg,image/gif,image/webp",multiple:!0,hidden:!0,onChange:X=>{Cc(Array.from(X.target.files??[])),X.target.value=""}}),l.jsx(xt,{type:"button",className:"composer-attach",title:AE(),"aria-label":AE(),onClick:()=>{var X;return(X=or.current)==null?void 0:X.click()},children:l.jsx(bBn,{size:16})}),(Ki||Tn)&&l.jsxs(Se,{type:"button",variant:"purple",active:!0,className:"group max-w-60",title:Tn?ID():OE({goal:uu(Ki)}),"aria-label":Tn?FE():OE({goal:uu(Ki)}),onClick:()=>{Xt(null),Ki&&Oc("clear")},children:[l.jsxs("span",{className:"relative size-4","aria-hidden":"true",children:[l.jsx(JP,{className:"absolute inset-0 transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0",size:16,strokeWidth:1.5}),l.jsx(hn,{className:"absolute inset-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100",size:16,strokeWidth:1.5})]}),l.jsx("span",{className:"truncate",children:FE()})]}),Mc&&l.jsxs(Se,{type:"button",variant:"amber",active:!0,className:"group",title:PE(),"aria-label":PE(),onClick:()=>void uf(),children:[l.jsxs("span",{className:"relative size-4","aria-hidden":"true",children:[l.jsx(YPn,{className:"absolute inset-0 transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0",size:16,strokeWidth:1.5}),l.jsx(hn,{className:"absolute inset-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100",size:16,strokeWidth:1.5})]}),l.jsx("span",{children:RPe()})]}),Ho&&l.jsxs(Se,{type:"button",variant:"ghost",active:!0,className:"group",title:IE(),"aria-label":IE(),onClick:Bc,children:[l.jsxs("span",{className:"relative size-4","aria-hidden":"true",children:[l.jsx(q_,{className:"absolute inset-0 transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0",size:16,strokeWidth:1.5}),l.jsx(hn,{className:"absolute inset-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100",size:16,strokeWidth:1.5})]}),l.jsx("span",{children:xD()})]}),l.jsx("div",{className:"min-w-0 flex-1"}),l.jsxs("div",{className:"flex min-w-0 items-center",children:[l.jsx(YFn,{sessionHarness:at!=null&&at.harness.startsWith("acp:")?Qe:void 0,value:ar,onSelect:Wi,onOpenSettings:()=>d("harnesses"),permissionChoices:Qe!=null&&Qe.agentReady?(ko==null?void 0:ko.permissionModes)??[]:[],defaultPermissionId:(ko==null?void 0:ko.defaultPermissionMode)??null,onSelectPermission:Tc,reasoningChoices:Qe!=null&&Qe.agentReady?Iu.choices:[],defaultReasoningId:Iu.defaultId,onSelectReasoning:Rc,autonomy:(at==null?void 0:at.autonomy)??go??E,onSelectAutonomy:Gd,lockHarness:!!at||!!L,openRequest:hs,nativeOptions:at!=null&&at.harness.startsWith("acp:")?zc.filter(X=>X.category!=="model"):[],onSelectNativeOption:(X,le)=>{at&&mk(at.id,X,le).catch(xe=>Kt(xe instanceof Error?xe.message:String(xe),"error"))}}),l.jsx(yos,{usage:at==null?void 0:at.contextUsage})]}),Yr?l.jsx(xt,{className:"send-btn",variant:"stop",title:JE(),"aria-label":JE(),onClick:Ps,children:l.jsx(hn,{size:16})}):l.jsx(xt,{className:`send-btn ${rc&&(Qe!=null&&Qe.agentReady)?"ring-2 ring-primary ring-offset-2 ring-offset-background":""}`,variant:"primary",title:Ho?QE():Fb(),"aria-label":Ho?QE():Fb(),onClick:()=>void(Ho?Vd():Ic()),disabled:Ho?!af||!Ie&&!(Qe!=null&&Qe.agentReady):!(Qe!=null&&Qe.agentReady)||!qt.trim()&&dr.length===0&&ur.length===0,children:l.jsx(XP,{size:16})})]})]})]})]})]})}const Uas="flex items-center gap-2.5 mb-2.5 py-2 ps-3.5 pe-2 rounded-lg border border-border bg-surface text-text text-sm leading-normal",Gas=[],Was=[];function xa({className:e,...r}){return l.jsx("div",{className:Ln("relative flex min-h-0 flex-1 flex-col",e),...r})}function Vh({className:e,...r}){return l.jsx("div",{className:Ln("min-h-0 flex-1 overflow-auto bg-background",e),...r})}function cl({className:e,...r}){return l.jsx("div",{className:Ln("shrink-0 border-b border-b-border-variant px-4 py-2 text-sm text-muted",e),...r})}const bO=["pane-content flex-1 min-h-0 relative subagent-tab-content overflow-y-auto","bg-background py-8 px-4"].join(" ");function Kas({projectId:e,sessionId:r,spawnPartId:t,expansionState:n,onOpenFile:s,onOpenRun:o,runExperimentName:a,onOpenExperiment:i,experimentName:c,onOpenSubagent:_}){var b,S,C,N,T,E;const d=nt(_l(r)),f=((b=d.data)==null?void 0:b.messages)??(d.isError?[]:null),p=OYn(f??[],t),m=nt({queryKey:kt("getSubagentTranscript",r,t,((C=(S=p==null?void 0:p.state)==null?void 0:S.input)==null?void 0:C.nativeTranscript)??null,((E=(T=(N=p==null?void 0:p.state)==null?void 0:N.output)==null?void 0:T.match(/\(sessionID: (ses_\w+)\)/))==null?void 0:E[1])??null),queryFn:({signal:R})=>V$n(r,t,R),refetchInterval:R=>{var $,L;return((L=($=R.state.data)==null?void 0:$.state)==null?void 0:L.status)==="running"?1500:!1},refetchIntervalInBackground:!0,refetchOnMount:"always"}),w=f===null||m.isPending,y=A.useRef(null),v=A.useRef(null),x=A.useRef(!0);if(A.useLayoutEffect(()=>{x.current=!0;const R=y.current;R&&(R.scrollTop=R.scrollHeight)},[r,t]),A.useLayoutEffect(()=>{const R=y.current;R&&x.current&&(R.scrollTop=R.scrollHeight)},[f,m.data]),A.useEffect(()=>{const R=y.current,$=v.current;if(!R||!$)return;const L=new ResizeObserver(()=>{x.current&&(R.scrollTop=R.scrollHeight)});return L.observe($),L.observe(R),()=>L.disconnect()},[w]),w)return l.jsx(xa,{children:l.jsx("div",{className:bO,children:l.jsx("div",{className:"subagent-empty p-1 text-sm text-muted",children:LI()})})});const k=m.data??p;return l.jsx(xa,{children:l.jsx("div",{className:bO,ref:y,onScroll:R=>{const $=R.currentTarget;x.current=$.scrollHeight-$.scrollTop-$.clientHeight<60},children:l.jsx("div",{ref:v,children:k?l.jsx(PU,{projectId:e,sessionId:r,children:l.jsx(Aas,{spawn:k,expansionState:n,onOpenFile:s,onOpenRun:o,runExperimentName:a,onOpenExperiment:i,experimentName:c,onOpenSubagent:_})}):l.jsx("div",{className:"subagent-empty p-1 text-sm text-muted",children:w5n()})})})})}function Vas({experiment:e}){var s;const r=nt(kF(e.id)),t=r.data,n=(s=r.error)==null?void 0:s.message;return l.jsx(Vh,{className:"branch-changes [&_>_.changes-note]:mx-4 [&_>_.changes-note]:my-3.5 [&_>_.diff-explorer]:mx-4 [&_>_.diff-explorer]:mb-0 [&_>_.diff-explorer]:mt-3.5 [&_>_.openresearch-diff]:mx-4 [&_>_.openresearch-diff]:mb-0 [&_>_.openresearch-diff]:mt-3.5 [&_>_.truncated-notice]:mx-4 [&_>_.truncated-notice]:mb-0 [&_>_.truncated-notice]:mt-3.5",children:n&&!t?l.jsxs(cl,{children:[xSe()," ",Ae(n)]}):t?t.diff.trim()?l.jsxs(l.Fragment,{children:[t.truncated&&l.jsx(cH,{bytesRead:t.bytesRead,byteLimit:t.byteLimit}),l.jsx(uH,{diff:t.diff,partial:t.truncated})]}):l.jsx("div",{className:"changes-note text-sm text-muted",children:e.parentExperimentId?FSe():_Se()}):l.jsx(cl,{children:TSe()})})}function CG({view:e,onViewChange:r,showViewToggle:t=!0,branchLabel:n,branchTitle:s,githubHref:o,githubTitle:a,refreshing:i,onRefresh:c}){return l.jsxs("div",{className:"code-tab-header flex items-center gap-2 py-1.5 px-3 border-b border-b-border-variant shrink-0",children:[t&&l.jsxs("div",{className:ox,role:"group","aria-label":dtt(),children:[l.jsx("button",{type:"button",className:e==="files"?"active":"","aria-pressed":e==="files",onClick:()=>r("files"),children:ktt()}),l.jsx("button",{type:"button",className:e==="changes"?"active":"","aria-pressed":e==="changes",onClick:()=>r("changes"),children:AD()})]}),n&&l.jsxs("span",{className:"wt-branch-chip inline-flex items-center gap-1 min-w-0 py-0.5 px-2 rounded-full bg-hover-muted text-subtext text-xs [&_>_svg]:shrink-0",title:s,children:[l.jsx(F0,{size:12}),l.jsx("span",{className:"wt-branch-name overflow-hidden text-ellipsis whitespace-nowrap",children:n})]}),o&&l.jsx($p,{href:o,target:"_blank",rel:"noopener noreferrer",title:a,"aria-label":a,children:l.jsx(sC,{size:14})}),l.jsx("span",{className:"flex-1"}),l.jsx(xt,{title:oN(),"aria-label":oN(),onClick:c,children:i?l.jsx($t,{}):l.jsx(ABn,{size:14})})]})}function zG(e,r){const t=navigator.clipboard;if(!t){Kt(jS(),"error");return}t.writeText(`${e.replace(/[\\/]+$/,"")}/${r}`).then(()=>Kt(fd(),"success")).catch(n=>Kt(n instanceof Error?n.message:String(n),"error"))}function EG({name:e,onCommit:r,onCancel:t}){const[n,s]=A.useState(e),o=A.useRef(!1),a=()=>{if(o.current)return;o.current=!0;const i=n.trim();!i||i===e?t():r(i)};return l.jsx(yn,{autoFocus:!0,variant:"inline",className:"min-w-0 flex-1",value:n,"aria-label":uvt({path:Ae(e)}),onFocus:i=>{const c=e.lastIndexOf(".");i.currentTarget.setSelectionRange(0,c>0?c:e.length)},onChange:i=>s(i.target.value),onClick:i=>i.stopPropagation(),onDoubleClick:i=>i.stopPropagation(),onBlur:a,onKeyDown:i=>{i.stopPropagation(),i.key==="Enter"?(i.preventDefault(),i.currentTarget.blur()):i.key==="Escape"&&(i.preventDefault(),o.current=!0,t())}})}function NG(e,r){const t=e.currentTarget.getBoundingClientRect(),n="clientX"in e?e.clientX:0,s="clientY"in e?e.clientY:0;return{path:r,x:n||t.left+16,y:s||t.top+t.height}}function AG({target:e,onOpen:r,onRename:t,onDuplicate:n,onCopyPath:s,onDelete:o,onClose:a}){const i=A.useRef(null),c=A.useRef(a);c.current=a;const[_,d]=A.useState({x:e.x,y:e.y});A.useLayoutEffect(()=>{var y;const m=i.current;if(!m)return;const w=document.activeElement instanceof HTMLElement?document.activeElement:null;return d({x:Math.max(8,Math.min(e.x,window.innerWidth-m.offsetWidth-8)),y:Math.max(8,Math.min(e.y,window.innerHeight-m.offsetHeight-8))}),(y=m.querySelector("button"))==null||y.focus(),()=>{m.contains(document.activeElement)&&(w==null||w.focus())}},[e]),A.useEffect(()=>{const m=()=>c.current(),w=v=>{var x;(x=i.current)!=null&&x.contains(v.target instanceof Node?v.target:null)||c.current()},y=v=>{if(v.key==="Tab"){v.preventDefault(),c.current();return}v.key==="Escape"&&(v.preventDefault(),v.stopPropagation(),c.current())};return document.addEventListener("pointerdown",w),window.addEventListener("blur",m),window.addEventListener("resize",m),window.addEventListener("scroll",m,!0),document.addEventListener("keydown",y,!0),()=>{document.removeEventListener("pointerdown",w),window.removeEventListener("blur",m),window.removeEventListener("resize",m),window.removeEventListener("scroll",m,!0),document.removeEventListener("keydown",y,!0)}},[]);const f=m=>{c.current(),m()},p=(m,w,y=!1)=>l.jsx(cr,{size:"compact",role:"menuitem",danger:y,onClick:()=>f(w),children:l.jsx("span",{children:m})});return to.createPortal(l.jsxs("div",{ref:i,role:"menu","aria-label":U1t({path:Ae(e.path)}),className:"option-menu fixed z-100 min-w-44 overflow-hidden rounded-md border border-border bg-background p-1 shadow-menu",style:{left:_.x,top:_.y},onContextMenu:m=>m.preventDefault(),onKeyDown:m=>{var x,k;if(m.key!=="ArrowDown"&&m.key!=="ArrowUp")return;m.preventDefault();const w=[...((x=i.current)==null?void 0:x.querySelectorAll("button"))??[]],y=w.indexOf(document.activeElement instanceof HTMLButtonElement?document.activeElement:w[0]),v=m.key==="ArrowDown"?1:-1;(k=w[(y+v+w.length)%w.length])==null||k.focus()},children:[p(evt(),r),t&&p(jD(),t),n&&p(O1t(),n),p(m5e(),s),o&&p(wD(),o,!0)]}),document.body)}const zj=["file-tree-row flex items-center gap-1.5 w-full py-1 px-2.5 border-0","bg-transparent text-text text-start cursor-pointer font-[inherit]","[&:hover]:bg-panel [&_>_svg]:shrink-0","[&_>_svg]:text-subtext [&_>_svg.file-tree-chevron]:text-muted"].join(" "),yO=["file-tree-chevron text-muted shrink-0 [button&]:inline-flex","[button&]:items-center [button&]:justify-center [button&]:size-3.5","[button&]:p-0 [button&]:border-0 [button&]:bg-transparent","[button&_>_svg]:transition-transform [button&_>_svg]:duration-120 [button&_>_svg]:ease-standard [button&_>_svg.open]:rotate-90"].join(" ");function xO(){return{dirs:new Map,files:[]}}function TG(e){const r=xO();for(const t of e){const n=t.split("/");let s=r;for(let o=0;oo(t),title:t,children:[p?l.jsx(kc,{size:14,className:yO}):l.jsx(mo,{size:14,className:yO}),l.jsx("span",{className:"file-tree-name flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:e})]}),p&&l.jsx(e7,{node:r,parentPath:t,depth:n+1,toggled:s,onToggle:o,onOpenFile:a,renamingPath:i,onContextMenu:c,onRename:_,onCancelRename:d})]})}function e7({node:e,parentPath:r,depth:t,toggled:n,onToggle:s,onOpenFile:o,renamingPath:a,onContextMenu:i,onRename:c,onCancelRename:_}){const d=[...e.dirs.keys()].sort((p,m)=>p.localeCompare(m)),f=[...e.files].sort((p,m)=>p.localeCompare(m));return l.jsxs(l.Fragment,{children:[d.map(p=>{const m=r?`${r}/${p}`:p;return l.jsx(Qas,{name:p,node:e.dirs.get(p),path:m,depth:t,toggled:n,onToggle:s,onOpenFile:o,renamingPath:a,onContextMenu:i,onRename:c,onCancelRename:_},`d:${m}`)}),f.map(p=>{const m=r?`${r}/${p}`:p;if(a===m&&c&&_)return l.jsxs("div",{className:zj,style:{paddingInlineStart:8+t*14},children:[l.jsx(yd,{name:p}),l.jsx(EG,{name:p,onCommit:y=>c(m,y),onCancel:_})]},`f:${m}`);const w=pn(y=>o(m,y));return l.jsxs("button",{type:"button",className:zj,style:{paddingInlineStart:8+t*14},...w,onContextMenu:y=>{i&&(y.preventDefault(),i(y,m))},onKeyDown:y=>{if(i&&(y.key==="ContextMenu"||y.shiftKey&&y.key==="F10")){y.preventDefault(),i(y,m);return}w.onKeyDown(y)},title:nte({name:Ae(m)}),children:[l.jsx(yd,{name:p}),l.jsx("span",{className:"file-tree-name flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:p})]},`f:${m}`)})]})}function Xas({projectId:e,project:r,experiment:t,view:n,toggled:s,onViewChange:o,onToggledChange:a,onOpenFile:i}){var C,N;const c=t.branchName,_=nt({...G6(e,{ref:c}),enabled:n==="files",subscribed:n==="files"}),d=nt({...iy(t.chatSessionId??""),enabled:n==="files"&&!!t.chatSessionId,subscribed:n==="files"&&!!t.chatSessionId}),f=_.data,p=(C=_.error)==null?void 0:C.message,m=_.isFetching,w=kF(t.id),y=LQ({queryKey:w.queryKey})>0,v=(N=d.data)!=null&&N.exists&&d.data.branch===c?t.chatSessionId??void 0:void 0,x=()=>{_.refetch()},k=A.useMemo(()=>f?TG(f.entries):null,[f]),b=n==="files"?m:y,S=A.useCallback(T=>{const E=new Set(s);E.has(T)?E.delete(T):E.add(T),a(E)},[s,a]);return l.jsxs("div",{className:"code-tab flex flex-col h-full min-h-0",children:[l.jsx(CG,{view:n,onViewChange:o,branchLabel:c,branchTitle:`Committed branch ${c}`,githubHref:r.githubEnabled?tx(r.githubOwner,r.githubRepo,c):void 0,githubTitle:iD({branch:Ae(c)}),refreshing:b,onRefresh:()=>n==="files"?x():void Xe.invalidateQueries(w)}),n==="changes"?l.jsx(Vas,{experiment:t},t.id):l.jsxs(l.Fragment,{children:[(f==null?void 0:f.truncated)&&l.jsx(cl,{children:Htt()}),p&&k&&l.jsxs(cl,{children:[crt()," ",Ae(p)]}),l.jsx(Vh,{children:k?k.dirs.size===0&&k.files.length===0?l.jsx(cl,{children:Ztt()}):l.jsx("div",{className:"file-tree py-1.5 px-0 text-sm",children:l.jsx(e7,{node:k,parentPath:"",depth:0,toggled:s,onToggle:S,onOpenFile:(T,E)=>v?i(T,v,void 0,E):i(T,void 0,c,E)})}):l.jsx(cl,{children:p?wS({error:Ae(p)}):Yy()})})]})]})}function t7({icon:e,title:r,description:t}){return l.jsxs("div",{className:"flex h-full w-full min-w-0 flex-1 flex-col items-center justify-center gap-1.5 bg-background p-6 text-center text-muted",children:[l.jsx(e,{size:36,strokeWidth:1.5,className:"shrink-0"}),l.jsx("h3",{className:"mt-1.5 mb-0 max-w-full wrap-anywhere text-xl font-medium text-text",children:r}),t&&l.jsx("p",{className:"m-0 w-full max-w-105 wrap-anywhere text-base leading-normal text-subtext",children:t})]})}function Yas({sessionId:e,project:r,view:t,toggled:n,onViewChange:s,onToggledChange:o,onOpenFile:a,canRenameFile:i}){var F,D,q;const c=r.id,d=((F=nt(po(c)).data)==null?void 0:F.some(Q=>Q.id===e&&Q.busy))??!1,f=nt({...iy(e??""),enabled:!!e,refetchInterval:d?5e3:!1}),p=f.data,m=e&&(p!=null&&p.exists)?{sessionId:e}:{ref:r.baselineBranch},w=nt({...G6(c,m),enabled:!e||f.isSuccess,refetchInterval:d?5e3:!1}),y=w.data,v=(D=f.error??w.error)==null?void 0:D.message,x=f.isFetching||w.isFetching,[k,b]=A.useState(null),[S,C]=A.useState(null),N=A.useCallback(()=>{e&&Xe.invalidateQueries(iy(e)),Xe.invalidateQueries({queryKey:kt("getCodeTree",c),predicate:Q=>!JL(Q)})},[e,c]),T=A.useRef(d);A.useEffect(()=>{T.current&&!d&&N(),T.current=d},[d,N]);const E=A.useMemo(()=>y?TG(y.entries):null,[y]),R=A.useCallback(Q=>{const W=new Set(n);W.has(Q)?W.delete(Q):W.add(Q),o(W)},[n,o]),$=e&&(p!=null&&p.exists)?p:null,L=($==null?void 0:$.branch)??($!=null&&$.baselineBranch?rRn({branch:Ae($.baselineBranch)}):aI()),I=((q=$==null?void 0:$.files)==null?void 0:q.length)??0,P=$?LTn({branch:Ae(`${L}${I>0?"*":""}`)}):WTn({branch:Ae(r.baselineBranch)}),B=$?$.branch:r.baselineBranch,K=(Q,W)=>$?a(Q,e,void 0,W):a(Q,void 0,r.baselineBranch,W),U=(y==null?void 0:y.root)==="worktree",J=async(Q,W)=>{try{await MMn(c,Q,W,{sessionId:e}),N()}catch(ce){Kt(ce instanceof Error?ce.message:String(ce),"error")}},te=Q=>{const W=(y==null?void 0:y.path)??r.repoPath;zG(W,Q)};return l.jsxs("div",{className:"code-tab flex flex-col h-full min-h-0 wt-tab",children:[l.jsx(CG,{view:$?t:"files",onViewChange:s,showViewToggle:!!$,branchLabel:P,branchTitle:P,githubHref:r.githubEnabled&&B?tx(r.githubOwner,r.githubRepo,B):void 0,githubTitle:B?iD({branch:Ae(B)}):void 0,refreshing:x,onRefresh:N}),v&&(p||y)&&l.jsxs(cl,{children:[ZRn()," ",Ae(v)]}),!y||e&&!p?l.jsx(Vh,{children:l.jsx(cl,{children:v?wS({error:Ae(v)}):Yy()})}):$&&t==="changes"?l.jsx(Vh,{className:"wt-changes px-4 pb-6 pt-0 [&_>_:first-child]:mt-3.5",children:I===0||!$.diff?l.jsx("div",{className:"changes-note text-sm text-muted",children:RRn()}):l.jsxs(l.Fragment,{children:[$.diff.truncated&&l.jsx(cH,{bytesRead:$.diff.bytesRead,byteLimit:$.diff.byteLimit}),l.jsx(uH,{diff:$.diff.diff,partial:$.diff.truncated})]})}):l.jsxs(Vh,{children:[y.truncated&&l.jsx(cl,{children:fRn()}),E?E.dirs.size===0&&E.files.length===0?l.jsx(t7,{icon:ui,title:HRn(),description:E3t()}):l.jsx("div",{className:"file-tree py-1.5 px-0 text-sm",children:l.jsx(e7,{node:E,parentPath:"",depth:0,toggled:n,onToggle:R,onOpenFile:K,renamingPath:S,onContextMenu:(Q,W)=>{b(NG(Q,W))},onRename:(Q,W)=>{C(null),J(Q,{action:"rename",newName:W})},onCancelRename:()=>C(null)})}):l.jsx(cl,{children:wRn()})]}),k&&l.jsx(AG,{target:k,onOpen:()=>K(k.path,"keepOpen"),onRename:U&&i(k.path)?()=>C(k.path):void 0,onDuplicate:U?()=>void J(k.path,{action:"duplicate"}):void 0,onCopyPath:()=>te(k.path),onDelete:U?()=>{window.confirm(j1t({path:Ae(k.path)}))&&J(k.path,{action:"delete"})}:void 0,onClose:()=>b(null)})]})}function RG({text:e,path:r,highlightLine:t,scrollRequest:n,onScrollRequestHandled:s}){const o=A.useMemo(()=>{if(!e)return[];const d=e.replace(/\r\n?/g,` `),f=uF(d,_6(r));return d.endsWith(` -`)?f.slice(0,-1):f},[e,r]),a=t&&o.length>0?Math.min(Math.max(Math.trunc(t),1),o.length):void 0,i=A.useRef(null);A.useEffect(()=>{var d;n!==void 0&&(a?((d=i.current)==null||d.scrollIntoView({block:"center"}),s==null||s()):o.length===0&&(s==null||s()))},[o.length,s,n,a]);const{ruleCh:c}=WB(o.length),_=A.useMemo(()=>o.map((d,f)=>l.jsxs("div",{ref:f+1===a?i:void 0,className:`file-view-line flex items-stretch ${f+1===a?"file-view-line-highlight bg-accent-blue-subtle shadow-file-line":""}`,children:[l.jsx("span",{"data-line":f+1,className:`${GB} before:content-[attr(data-line)] shrink-0 pe-[1ch]`,style:{width:`${c}ch`},"aria-hidden":"true"}),l.jsx("code",{className:`file-view-code flex-1 min-w-0 ps-[2ch] pe-4 ${oy} ${UB}`,children:_F(d)?l.jsx("br",{}):d})]},f)),[o,c,a]);return l.jsxs("div",{className:`file-view-codewrap relative py-3.5 ${oy}`,children:[o.length>0&&l.jsx("div",{className:"absolute start-0 top-0 bottom-0 border-e border-e-border-variant pointer-events-none",style:{width:`${c}ch`},"aria-hidden":"true"}),_]})}const zy=A.createContext(null);function Zas({url:e,name:r}){return l.jsx($p,{size:"small",href:e,download:r,"aria-label":Ib({name:Ae(r)}),"data-tip":Ib({name:Ae(r)}),"data-tip-align":"end",children:l.jsx(ix,{size:14})})}const Jas=A.lazy(()=>BQ(()=>import("./PdfPreview-C7B2nDXs.js"),__vite__mapDeps([0,1])).catch(e=>(console.error("PDF viewer failed to load",e),{default:OG})));function MG(e){return e==="image"||e==="audio"||e==="video"||e==="pdf"?e:null}function OG({url:e,name:r}){return l.jsxs("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:[f$t()," ",l.jsxs("a",{href:e,download:r,children:[R5()," ",Ae(r)]})]})}function Ej({kind:e,url:r,name:t,download:n=!0}){const[s,o]=A.useState(!1),a=A.useContext(zy);if(A.useEffect(()=>o(!1),[e,r]),s)return l.jsx(OG,{url:r,name:t});let i;return e==="image"?i=l.jsx("div",{className:"fpreview-image flex min-h-0 flex-1 items-start justify-center overflow-auto p-6 [&_img]:max-w-full [&_img]:h-auto [&_img]:border [&_img]:border-border [&_img]:rounded-sm",children:l.jsx("img",{src:r,alt:t,onError:()=>o(!0)})}):e==="audio"?i=l.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:l.jsx("audio",{className:"w-full max-w-160",controls:!0,preload:"metadata",src:r,"aria-label":t,onError:()=>o(!0)})}):e==="video"?i=l.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:l.jsx("video",{className:"max-h-full max-w-full rounded-sm border border-border",controls:!0,preload:"metadata",src:r,"aria-label":t,onError:()=>o(!0)})}):i=l.jsx(A.Suspense,{fallback:l.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center",children:l.jsx($t,{})}),children:l.jsx(Jas,{url:r,name:t,download:n,onError:()=>o(!0)},r)}),l.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[i,n&&e!=="pdf"&&a&&to.createPortal(l.jsx(Zas,{url:r,name:t}),a)]})}const eis=e=>({queryKey:kt("fileVersion",e),staleTime:2e3,refetchOnMount:"always",refetchOnWindowFocus:"always",refetchInterval:2e3,queryFn:async({signal:r})=>{const t=await fetch(e,{method:"HEAD",cache:"no-store",signal:r});if(t.status===404)return"missing";if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.headers.get("etag")??t.headers.get("content-length")}});function $G(e,r=!0){return nt({...eis(e),enabled:r,subscribed:r}).data??null}function tis(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith("//")}function ris(e,r,t){const n=t.indexOf("#"),s=n===-1?t:t.slice(0,n),o=n===-1?"":t.slice(n),a=s.indexOf("?"),i=a===-1?s:s.slice(0,a),c=a===-1?"":s.slice(a+1),_=i.startsWith("/")?[]:r.split("/").filter(m=>m.length>0);for(const m of i.split("/"))if(!(!m||m==="."))if(m===".."){if(_.length===0)return null;_.pop()}else _.push(m);const d=_.join("/");if(!d)return null;const f=new URLSearchParams(c);f.delete("path");const p=f.toString();return{path:d,url:`${hd(e,d)}${p?`&${p}`:""}${o}`}}function nis(e){if(!e.startsWith("---"))return e;const r=e.indexOf(` +`)?f.slice(0,-1):f},[e,r]),a=t&&o.length>0?Math.min(Math.max(Math.trunc(t),1),o.length):void 0,i=A.useRef(null);A.useEffect(()=>{var d;n!==void 0&&(a?((d=i.current)==null||d.scrollIntoView({block:"center"}),s==null||s()):o.length===0&&(s==null||s()))},[o.length,s,n,a]);const{ruleCh:c}=WB(o.length),_=A.useMemo(()=>o.map((d,f)=>l.jsxs("div",{ref:f+1===a?i:void 0,className:`file-view-line flex items-stretch ${f+1===a?"file-view-line-highlight bg-accent-blue-subtle shadow-file-line":""}`,children:[l.jsx("span",{"data-line":f+1,className:`${GB} before:content-[attr(data-line)] shrink-0 pe-[1ch]`,style:{width:`${c}ch`},"aria-hidden":"true"}),l.jsx("code",{className:`file-view-code flex-1 min-w-0 ps-[2ch] pe-4 ${oy} ${UB}`,children:_F(d)?l.jsx("br",{}):d})]},f)),[o,c,a]);return l.jsxs("div",{className:`file-view-codewrap relative py-3.5 ${oy}`,children:[o.length>0&&l.jsx("div",{className:"absolute start-0 top-0 bottom-0 border-e border-e-border-variant pointer-events-none",style:{width:`${c}ch`},"aria-hidden":"true"}),_]})}const zy=A.createContext(null);function Zas({url:e,name:r}){return l.jsx($p,{size:"small",href:e,download:r,"aria-label":Ib({name:Ae(r)}),"data-tip":Ib({name:Ae(r)}),"data-tip-align":"end",children:l.jsx(ix,{size:14})})}const Jas=A.lazy(()=>BQ(()=>import("./PdfPreview-DhcTOsJE.js"),__vite__mapDeps([0,1])).catch(e=>(console.error("PDF viewer failed to load",e),{default:OG})));function MG(e){return e==="image"||e==="audio"||e==="video"||e==="pdf"?e:null}function OG({url:e,name:r}){return l.jsxs("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:[f$t()," ",l.jsxs("a",{href:e,download:r,children:[R5()," ",Ae(r)]})]})}function Ej({kind:e,url:r,name:t,download:n=!0}){const[s,o]=A.useState(!1),a=A.useContext(zy);if(A.useEffect(()=>o(!1),[e,r]),s)return l.jsx(OG,{url:r,name:t});let i;return e==="image"?i=l.jsx("div",{className:"fpreview-image flex min-h-0 flex-1 items-start justify-center overflow-auto p-6 [&_img]:max-w-full [&_img]:h-auto [&_img]:border [&_img]:border-border [&_img]:rounded-sm",children:l.jsx("img",{src:r,alt:t,onError:()=>o(!0)})}):e==="audio"?i=l.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:l.jsx("audio",{className:"w-full max-w-160",controls:!0,preload:"metadata",src:r,"aria-label":t,onError:()=>o(!0)})}):e==="video"?i=l.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:l.jsx("video",{className:"max-h-full max-w-full rounded-sm border border-border",controls:!0,preload:"metadata",src:r,"aria-label":t,onError:()=>o(!0)})}):i=l.jsx(A.Suspense,{fallback:l.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center",children:l.jsx($t,{})}),children:l.jsx(Jas,{url:r,name:t,download:n,onError:()=>o(!0)},r)}),l.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[i,n&&e!=="pdf"&&a&&to.createPortal(l.jsx(Zas,{url:r,name:t}),a)]})}const eis=e=>({queryKey:kt("fileVersion",e),staleTime:2e3,refetchOnMount:"always",refetchOnWindowFocus:"always",refetchInterval:2e3,queryFn:async({signal:r})=>{const t=await fetch(e,{method:"HEAD",cache:"no-store",signal:r});if(t.status===404)return"missing";if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.headers.get("etag")??t.headers.get("content-length")}});function $G(e,r=!0){return nt({...eis(e),enabled:r,subscribed:r}).data??null}function tis(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith("//")}function ris(e,r,t){const n=t.indexOf("#"),s=n===-1?t:t.slice(0,n),o=n===-1?"":t.slice(n),a=s.indexOf("?"),i=a===-1?s:s.slice(0,a),c=a===-1?"":s.slice(a+1),_=i.startsWith("/")?[]:r.split("/").filter(m=>m.length>0);for(const m of i.split("/"))if(!(!m||m==="."))if(m===".."){if(_.length===0)return null;_.pop()}else _.push(m);const d=_.join("/");if(!d)return null;const f=new URLSearchParams(c);f.delete("path");const p=f.toString();return{path:d,url:`${hd(e,d)}${p?`&${p}`:""}${o}`}}function nis(e){if(!e.startsWith("---"))return e;const r=e.indexOf(` ---`,3);return r===-1?e:e.slice(r+4).replace(/^\r?\n/,"")}const LG="orx:files-tree-width",DG="orx:artifacts-collapsed:",IG=180,PG=320,sis=8,ois=280;function ais(){try{const e=Number(localStorage.getItem(LG));if(Number.isFinite(e)&&e>=IG&&e<=PG)return e}catch{}return ois}function iis(e){try{const r=localStorage.getItem(`${DG}${e}`);if(!r)return new Set;const t=JSON.parse(r);return Array.isArray(t)?new Set(t.filter(n=>typeof n=="string")):new Set}catch{return new Set}}function a0(e,r){for(const t of e){if(t.path===r)return t;if(t.isDir&&r.startsWith(t.path+"/")){const n=a0(t.children??[],r);if(n)return n}}return null}function BG({projectId:e,folder:r,markdown:t,entries:n}){const s=A.useRef(n);s.current=n;const o=A.useMemo(()=>{const a=i=>{if(tis(i))return i;const c=ris(e,r,i);if(!c)return null;const _=a0(s.current,c.path);if(!_)return c.url;const d=c.url.indexOf("#"),f=d===-1?c.url:c.url.slice(0,d),p=d===-1?"":c.url.slice(d);return`${f}&v=${_.modifiedAt}:${_.size}${p}`};return{a:({href:i,children:c,..._})=>{const d=!i||i.startsWith("#"),f=d?i:a(i);return f?l.jsx("a",{..._,href:f,...d?{}:{target:"_blank",rel:"noopener noreferrer"},children:c}):l.jsx("span",{children:c})},img:({src:i,alt:c})=>{if(!i||typeof i!="string")return null;const _=a(i);return _?l.jsxs("a",{href:_,target:"_blank",rel:"noopener noreferrer",className:"artifact-img",children:[l.jsx("img",{src:_,alt:c??"",loading:"lazy"}),c&&l.jsx("span",{className:"artifact-img-caption",children:c})]}):null},...HU}},[e,r]);return l.jsx("div",{className:"md min-w-0 wrap-anywhere text-text leading-relaxed [&_>_*:first-child]:mt-0 [&_>_*:last-child]:mb-0 [&_p]:my-2.5 [&_p]:mx-0 [&_strong]:text-text [&_strong]:font-semibold [&_pre]:bg-surface [&_pre]:border [&_pre]:border-border-muted [&_pre]:rounded-md [&_pre]:py-2 [&_pre]:px-3 [&_pre]:overflow-x-auto [&_pre]:text-sm [&_pre]:text-text [&_code]:font-mono [&_code]:text-sm [&_code]:font-normal [&_code]:text-text [&_code]:bg-surface [&_code]:border [&_code]:border-border-variant [&_code]:rounded-xs [&_code]:py-px [&_code]:px-1 [&_.katex]:text-prose-emphasis [&_.katex-display]:my-3 [&_.katex-display]:mx-0 [&_.katex-display]:overflow-x-auto [&_.katex-display]:overflow-y-hidden [&_.katex-display]:py-0.5 [&_.katex-display]:px-0 [&_.file-chip]:inline-flex [&_.file-chip]:items-center [&_.file-chip]:gap-1 [&_.file-chip]:max-w-full [&_.file-chip]:my-0 [&_.file-chip]:mx-px [&_.file-chip]:py-0 [&_.file-chip]:px-1.5 [&_.file-chip]:align-baseline [&_.file-chip]:font-mono [&_.file-chip]:text-sm [&_.file-chip]:font-medium [&_.file-chip]:text-text [&_.file-chip]:bg-panel [&_.file-chip]:border [&_.file-chip]:border-border-variant [&_.file-chip]:rounded-xs [&_.file-chip]:cursor-pointer [&_.file-chip:hover:not(:disabled)]:bg-surface [&_.file-chip_svg]:flex-none [&_.file-chip_svg]:opacity-60 [&_.file-chip-label]:max-w-65 [&_.file-chip-label]:overflow-hidden [&_.file-chip-label]:text-ellipsis [&_.file-chip-label]:whitespace-nowrap [&_.run-chip_svg]:opacity-100 [&_.run-chip_svg]:text-subtext [&_pre_code]:bg-none [&_pre_code]:bg-transparent [&_pre_code]:border-0 [&_pre_code]:text-inherit [&_pre_code]:p-0 [&_pre_code]:font-normal [&_h1]:text-text [&_h1]:font-semibold [&_h2]:text-text [&_h2]:font-semibold [&_h3]:text-text [&_h3]:font-semibold [&_h4]:text-text [&_h4]:font-semibold [&_ul]:my-1.5 [&_ul]:mx-0 [&_ul]:ps-5.5 [&_ol]:my-1.5 [&_ol]:mx-0 [&_ol]:ps-5.5 [&_li::marker]:text-subtext [&_table]:border-collapse [&_table]:text-sm [&_table]:my-2.5 [&_table]:mx-0 [&_table]:border [&_table]:border-border [&_table]:rounded-md [&_th]:border-b [&_th]:border-b-border-variant [&_th]:py-2 [&_th]:px-3.5 [&_th]:text-start [&_th]:text-text [&_th]:break-normal [&_th]:break-words [&_td]:border-b [&_td]:border-b-border-variant [&_td]:py-2 [&_td]:px-3.5 [&_td]:text-start [&_td]:text-text [&_td]:break-normal [&_td]:break-words [&_tr:last-child_td]:border-b-0 [&_thead_th]:bg-surface [&_thead_th]:font-medium [&_thead_th]:text-text [&_thead_th]:border-b [&_thead_th]:border-b-border [&_tbody_tr:hover_td]:bg-surface [&_blockquote]:my-1.5 [&_blockquote]:mx-0 [&_blockquote]:pt-0.5 [&_blockquote]:pe-0 [&_blockquote]:pb-0.5 [&_blockquote]:ps-2.5 [&_blockquote]:border-s-[3px] [&_blockquote]:border-s-border [&_blockquote]:text-subtext [:is(&,_.openresearch-diff,_.file-view)_.token.comment]:italic [:is(&,_.openresearch-diff,_.file-view)_.token.prolog]:italic [:is(&,_.openresearch-diff,_.file-view)_.token.cdata]:italic [:is(&,_.openresearch-diff,_.file-view)_.token.operator]:text-syntax-cyan [:is(&,_.openresearch-diff,_.file-view)_.token.entity]:text-syntax-cyan [:is(&,_.openresearch-diff,_.file-view)_.token.url]:text-syntax-cyan [:is(&,_.openresearch-diff,_.file-view)_.token.comment]:text-syntax-comment [:is(&,_.openresearch-diff,_.file-view)_.token.prolog]:text-syntax-comment [:is(&,_.openresearch-diff,_.file-view)_.token.cdata]:text-syntax-comment [:is(&,_.openresearch-diff,_.file-view)_.token.punctuation]:text-syntax-text [:is(&,_.openresearch-diff,_.file-view)_.token.property]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.tag]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.deleted]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.constant]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.symbol]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.boolean]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.number]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.selector]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.attr-name]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.char]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.inserted]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.string]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.builtin]:text-syntax-yellow [:is(&,_.openresearch-diff,_.file-view)_.token.atrule]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.attr-value]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.keyword]:text-syntax-purple [:is(&,_.openresearch-diff,_.file-view)_.token.function]:text-syntax-blue [:is(&,_.openresearch-diff,_.file-view)_.token.decorator]:text-syntax-blue [:is(&,_.openresearch-diff,_.file-view)_.token.def]:text-syntax-blue [:is(&,_.openresearch-diff,_.file-view)_.token.class-name]:text-syntax-yellow [:is(&,_.openresearch-diff,_.file-view)_.token.namespace]:text-syntax-yellow [:is(&,_.openresearch-diff,_.file-view)_.token.regex]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.important]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.variable]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.parameter]:text-syntax-text artifact-md text-lg [&_h1]:text-4xl [&_h1]:leading-tight [&_h1]:mt-7 [&_h1]:mx-0 [&_h1]:mb-3.5 [&_h2]:text-3xl [&_h2]:leading-tight [&_h2]:mt-7 [&_h2]:mx-0 [&_h2]:mb-2.5 [&_h3]:text-xl [&_h3]:leading-snug [&_h3]:mt-5.5 [&_h3]:mx-0 [&_h3]:mb-2 [&_h4]:text-lg [&_h4]:leading-snug [&_h4]:mt-4.5 [&_h4]:mx-0 [&_h4]:mb-1.5 [&_table]:block [&_table]:w-max [&_table]:max-w-full [&_table]:overflow-x-auto [&_.artifact-img]:block [&_.artifact-img]:my-3 [&_.artifact-img]:mx-0 [&_.artifact-img_img]:max-w-full [&_.artifact-img_img]:h-auto [&_.artifact-img_img]:border [&_.artifact-img_img]:border-border [&_.artifact-img_img]:rounded-sm [&_.artifact-img-caption]:block [&_.artifact-img-caption]:mt-1 [&_.artifact-img-caption]:text-center [&_.artifact-img-caption]:text-sm [&_.artifact-img-caption]:text-subtext",children:l.jsx(XXn,{remarkPlugins:[MU,[OU,FU]],rehypePlugins:[cU],components:o,children:LU(nis(t))})})}function cis(e){return e.presentation==="text"&&lG(e.name)?"markdown":MG(e.presentation)??(e.presentation==="text"||e.presentation==="unknown"?"text":"download")}function lis(e,r,t,n){var _;const s=t==="markdown"||t==="text"&&r.size<=rP,o=W6(e,r.path),a=nt({...o,enabled:s,subscribed:s}),i=A.useRef({projectId:e,path:r.path,modifiedAt:r.modifiedAt,size:r.size,version:n});A.useEffect(()=>{const d=i.current;i.current={projectId:e,path:r.path,modifiedAt:r.modifiedAt,size:r.size,version:n},s&&d.projectId===e&&d.path===r.path&&(d.modifiedAt!==r.modifiedAt||d.size!==r.size||d.version!==null&&d.version!==n)&&Xe.invalidateQueries({queryKey:o.queryKey,exact:!0})},[e,r.path,r.modifiedAt,r.size,n,s]);const c=a.data;return{text:c&&!c.binary?c.content:null,binary:(c==null?void 0:c.binary)??!1,truncated:(c==null?void 0:c.truncated)??!1,error:c?null:((_=a.error)==null?void 0:_.message)??(c===null?C5e():null),wantsText:s}}function uis({projectId:e,entry:r,onDelete:t,artifactEntries:n}){const s=cis(r),o=$G(hd(e,r.path)),{text:a,binary:i,truncated:c,error:_,wantsText:d}=lis(e,r,s,o),[f,p]=A.useState(!1),[m,w]=A.useState(null),y=s==="markdown",v=r.path.split("/").slice(0,-1).join("/"),x=`${hd(e,r.path)}&v=${encodeURIComponent(o??`${r.modifiedAt}:${r.size}`)}`;let k;return s==="image"||s==="audio"||s==="video"||s==="pdf"?k=l.jsx(zy.Provider,{value:m,children:l.jsx(Ej,{kind:s,url:x,name:r.name})}):s==="download"||!d||i?k=l.jsxs("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:[s==="download"||i?a5e():tSe()," ",l.jsx("a",{href:x,...s==="download"||i?{download:r.name}:{target:"_blank",rel:"noopener noreferrer"},children:s==="download"||i?OD():L5e()})]}):_?k=l.jsxs("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:[x3e()," ",Ae(_)]}):a===null?k=l.jsxs(ys,{children:[l.jsx($t,{})," ",bD()]}):y&&!f?k=l.jsx(BG,{projectId:e,folder:v,markdown:a,entries:n}):k=l.jsx(RG,{text:a,path:r.path}),l.jsxs("div",{className:"fpreview flex-1 min-w-0 bg-background file-view flex flex-col h-full min-h-0 [@container((max-width:_720px))]:hidden",children:[l.jsxs("div",{className:"fpreview-head @container flex w-full min-w-0 min-h-9 items-center gap-1 px-4 py-1 bg-background text-subtext shrink-0",children:[l.jsx(yd,{name:r.name}),l.jsx("span",{className:"fpreview-path flex-1 min-w-0 truncate text-sm text-subtext","data-tip":Ae(r.path),children:r.name}),l.jsxs("span",{dir:"auto",className:"fpreview-date text-xs text-muted whitespace-nowrap shrink-0 @max-xl:hidden",children:[mje()," ",new Date(r.modifiedAt).toLocaleString(z(),{dateStyle:"medium",timeStyle:"short"})]}),l.jsx("div",{ref:w,className:"contents"}),(s==="text"||s==="download")&&l.jsx("span",{className:"fpreview-size text-xs text-muted whitespace-nowrap shrink-0",children:du(r.size)}),y&&l.jsx(xt,{size:"small",active:f,"data-tip":f?Hb():Rh(),"data-tip-align":"end","aria-label":f?Hb():Rh(),onClick:()=>p(b=>!b),children:l.jsx(d3,{size:14})}),l.jsx($p,{size:"small",href:x,target:"_blank",rel:"noopener noreferrer","data-tip":jE(),"data-tip-align":"end","aria-label":jE(),children:l.jsx(F_,{size:14})}),l.jsx(xt,{size:"small","data-tip":kE(),"data-tip-align":"end","aria-label":kE(),onClick:()=>{window.confirm(bS({path:Ae(r.path)}))&&t(r.path)},children:l.jsx(ef,{size:14})})]}),l.jsxs("div",{className:`fpreview-body flex-1 min-h-0 overflow-auto [&.doc]:pt-4.5 [&.doc]:px-7 [&.doc]:pb-12 [&.doc_.artifact-md]:max-w-readable [&.doc_.artifact-md]:my-0 [&.doc_.artifact-md]:mx-auto ${y&&!f?"doc":""}`,children:[k,c&&l.jsx("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:T3e()})]})]})}function FG({entries:e,depth:r,collapsed:t,selected:n,onToggle:s,onSelect:o,onOpenFile:a,onDelete:i,renamingPath:c,onContextMenu:_,onRename:d,onCancelRename:f}){return l.jsx("div",{className:"flex w-full max-w-full min-w-0 flex-col items-stretch",children:e.map(p=>{var w;const m={paddingInlineStart:8+Math.min(r,sis)*14};if(p.isDir){const y=!t.has(p.path);return l.jsxs("div",{className:"min-w-0 max-w-full",children:[l.jsxs("div",{className:"file-tree-row flex w-full min-w-0 items-center gap-1.5 py-1 px-2.5 border-0 bg-transparent text-text text-start cursor-pointer font-[inherit] [&:hover]:bg-panel [&_>_svg]:shrink-0 [&_>_svg]:text-subtext [&_>_svg.file-tree-chevron]:text-muted artifact-tree-row [&.selected]:bg-panel [&.selected:hover]:bg-panel [&:hover_.ft-row-delete]:opacity-100",style:m,onClick:()=>s(p.path),children:[l.jsx("button",{className:"file-tree-chevron text-muted shrink-0 [button&]:inline-flex [button&]:items-center [button&]:justify-center [button&]:size-3.5 [button&]:p-0 [button&]:border-0 [button&]:bg-transparent [button&_>_svg]:transition-transform [button&_>_svg]:duration-120 [button&_>_svg]:ease-standard [button&_>_svg.open]:rotate-90","aria-label":y?x4e({name:Ae(p.name)}):X4e({name:Ae(p.name)}),onClick:v=>{v.stopPropagation(),s(p.path)},children:l.jsx(mo,{size:14,className:y?"open":""})}),l.jsx("span",{className:"file-tree-name flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:p.name}),l.jsx(xt,{size:"small",className:"ft-row-delete opacity-35 focus-visible:opacity-100","data-tip":_3e(),"data-tip-align":"end","aria-label":B4e({name:Ae(p.name)}),onClick:v=>{v.stopPropagation(),window.confirm(bS({path:Ae(p.path)}))&&i(p.path)},children:l.jsx(ef,{size:12})})]}),y&&(((w=p.children)==null?void 0:w.length)??0)>0&&l.jsx(FG,{entries:p.children??[],depth:r+1,collapsed:t,selected:n,onToggle:s,onSelect:o,onOpenFile:a,onDelete:i,renamingPath:c,onContextMenu:_,onRename:d,onCancelRename:f})]},p.path)}return c===p.path?l.jsxs("div",{className:"file-tree-row flex w-full min-w-0 items-center gap-1.5 py-1 px-2.5 border-0 bg-transparent text-text text-start font-[inherit] artifact-tree-row",style:m,children:[l.jsx(yd,{name:p.name}),l.jsx(EG,{name:p.name,onCommit:y=>d(p.path,y),onCancel:f})]},p.path):l.jsxs("button",{type:"button",className:`file-tree-row flex w-full min-w-0 items-center gap-1.5 py-1 px-2.5 border-0 bg-transparent text-text text-start cursor-pointer font-[inherit] [&:hover]:bg-panel [&_>_svg]:shrink-0 [&_>_svg]:text-subtext [&_>_svg.file-tree-chevron]:text-muted artifact-tree-row [&.selected]:bg-panel [&.selected:hover]:bg-panel [&:hover_.ft-row-delete]:opacity-100 ${n===p.path?"selected":""}`,style:m,title:EZ({path:Ae(p.path)}),"aria-keyshortcuts":"Space Enter","aria-pressed":n===p.path,onClick:()=>o(p.path),onDoubleClick:()=>a(p.path),onContextMenu:y=>{y.preventDefault(),o(p.path),_(y,p.path)},onAuxClick:y=>{y.button===1&&(y.preventDefault(),o(p.path),a(p.path))},onKeyDown:y=>{if(y.key==="ContextMenu"||y.shiftKey&&y.key==="F10"){y.preventDefault(),o(p.path),_(y,p.path);return}if(y.key===" "){y.preventDefault(),y.stopPropagation(),o(p.path);return}y.key==="Enter"&&(y.preventDefault(),y.stopPropagation(),o(p.path),a(p.path))},children:[l.jsx(yd,{name:p.name}),l.jsx("span",{className:"file-tree-name flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:p.name})]},p.path)})})}function _is({project:e,artifacts:r,onOpenFile:t,canRenameFile:n}){const[s,o]=A.useState(null),[a,i]=A.useState(()=>iis(e.id)),[c,_]=A.useState(ais),[d,f]=A.useState(null),[p,m]=A.useState(null),w=A.useRef(null);A.useEffect(()=>{try{localStorage.setItem(`${DG}${e.id}`,JSON.stringify([...a]))}catch{}},[e.id,a]);const y=N=>{var L;N.preventDefault(),N.currentTarget.setPointerCapture(N.pointerId);const T=(L=w.current)==null?void 0:L.getBoundingClientRect(),E=document.body.style.userSelect;document.body.style.userSelect="none";const R=I=>{const P=Math.round(I.clientX-((T==null?void 0:T.left)??0)),B=Math.min(Math.max(P,IG),PG);_(B);try{localStorage.setItem(LG,String(B))}catch{}},$=()=>{window.removeEventListener("pointermove",R),window.removeEventListener("pointerup",$),window.removeEventListener("pointercancel",$),document.body.style.userSelect=E};window.addEventListener("pointermove",R),window.addEventListener("pointerup",$),window.addEventListener("pointercancel",$)};A.useEffect(()=>{if(!s||!r)return;const N=a0(r.entries,s);(!N||N.isDir)&&o(null)},[s,r]);const v=N=>i(T=>{const E=new Set(T);return E.has(N)?E.delete(N):E.add(N),E}),x=N=>{(s===N||s!=null&&s.startsWith(N+"/"))&&o(null),BOn(e.id,N).catch(()=>{})},k=async(N,T)=>{try{await FOn(e.id,N,T),T.action==="rename"&&s===N&&o(null)}catch(E){Kt(E instanceof Error?E.message:String(E),"error")}},b=N=>{r&&zG(r.dir,N)};if(!r)return l.jsx("div",{className:"files-tab h-full min-h-0 flex bg-background",children:l.jsxs(ys,{className:"p-5",children:[l.jsx($t,{})," ",aje()]})});const S=N=>l.jsx(FG,{entries:N,depth:0,collapsed:a,selected:s,onToggle:v,onSelect:o,onOpenFile:t,onDelete:x,renamingPath:p,onContextMenu:(T,E)=>{f(NG(T,E))},onRename:(T,E)=>{m(null),k(T,{action:"rename",newName:E})},onCancelRename:()=>m(null)}),C=s?a0(r.entries,s):null;return r.entries.length===0?l.jsx(t7,{icon:JS,title:Cje(),description:Gje()}):l.jsxs("div",{className:"files-tab h-full min-h-0 flex bg-background @container",children:[l.jsxs("div",{className:"ftree-pane relative shrink-0 flex flex-col min-h-0 border-s border-s-border-variant border-e border-e-border-variant bg-background [@container((max-width:_720px))]:!w-full",ref:w,style:{width:c},children:[l.jsx("div",{className:"ftree-resizer absolute -end-[3px] top-0 bottom-0 w-1.5 cursor-col-resize z-30 [&:hover]:bg-resizer-hover [&:active]:bg-resizer-hover [@container((max-width:_720px))]:hidden",onPointerDown:y}),l.jsxs("div",{className:"ftree-scroll flex-1 min-h-0 overflow-y-auto file-tree py-1.5 px-0 text-sm",children:[S(r.entries),r.truncated&&l.jsx("p",{className:"files-truncated m-0 py-2 px-3.5 text-sm text-muted",children:F3e()})]})]}),C?l.jsx(uis,{projectId:e.id,entry:C,onDelete:x,artifactEntries:r.entries},C.path):l.jsxs("div",{className:"fpreview flex-1 min-w-0 flex flex-col min-h-0 bg-background fpreview-none items-center justify-center gap-2 text-sm text-muted [@container((max-width:_720px))]:hidden",children:[l.jsx(pBn,{size:22,strokeWidth:1.5}),l.jsx("span",{children:W5e()})]}),d&&l.jsx(AG,{target:d,onOpen:()=>t(d.path),onRename:n(d.path)?()=>m(d.path):void 0,onDuplicate:()=>void k(d.path,{action:"duplicate"}),onCopyPath:()=>b(d.path),onDelete:()=>{window.confirm(bS({path:Ae(d.path)}))&&x(d.path)},onClose:()=>f(null)})]})}const HG=20*1024*1024,qG="bg-background border border-border rounded-lg py-4 px-4.5 mb-4 [&_h3]:mt-0 [&_h3]:mx-0 [&_h3]:mb-2.5 [&_h3]:text-base [&_h3]:font-semibold [&_h3]:text-text",UG="mt-0 mx-0 mb-3 text-sm leading-relaxed text-text",fis="flex items-start gap-3 py-2.5 border-t border-t-border first:border-t-0",dis="text-sm font-normal text-text",his="mt-1 mb-0 text-sm leading-relaxed text-text";function GG(e){return new Promise((r,t)=>{const n=new FileReader;n.onload=()=>{const s=n.result;if(typeof s!="string"){t(new Error("could not read file"));return}const o=s.indexOf(",");r(o>=0?s.slice(o+1):s)},n.onerror=()=>t(n.error??new Error("could not read file")),n.readAsDataURL(e)})}function pis(e){const r=e.toLowerCase();return r.endsWith(".md")||r.endsWith(".markdown")||r.endsWith(".zip")}function WG({accept:e,busy:r,prompt:t,onFile:n}){const[s,o]=A.useState(!1),a=A.useRef(null);return l.jsxs("div",{className:`flex flex-col items-center justify-center gap-2 py-6.5 px-4.5 border-[1.5px] border-dashed rounded-md text-center text-sm text-text transition-[border-color,background] duration-120 ${r?"cursor-default":"cursor-pointer"} ${s?"border-text bg-surface text-text":"border-border-variant bg-surface [&:hover]:border-border-hover-strong"}`,onDragOver:i=>{i.preventDefault(),o(!0)},onDragLeave:()=>o(!1),onDrop:i=>{var _;if(i.preventDefault(),o(!1),r)return;const c=(_=i.dataTransfer.files)==null?void 0:_[0];c&&n(c)},onClick:()=>{var i;r||(i=a.current)==null||i.click()},role:"button",tabIndex:0,"aria-disabled":r,"aria-busy":r,onKeyDown:i=>{var c;(i.key==="Enter"||i.key===" ")&&!r&&(i.preventDefault(),(c=a.current)==null||c.click())},children:[l.jsx("input",{ref:a,type:"file",accept:e,hidden:!0,onChange:i=>{var _;const c=(_=i.target.files)==null?void 0:_[0];c&&n(c),i.target.value=""}}),r?l.jsxs(l.Fragment,{children:[l.jsx($t,{}),l.jsx("span",{children:zbn()})]}):l.jsxs(l.Fragment,{children:[l.jsx(KBn,{size:20,strokeWidth:1.5}),l.jsx("span",{children:t})]})]})}function KG({bytes:e,updatedAt:r}){return l.jsxs("div",{className:"shrink-0 text-end whitespace-nowrap pt-0.5 text-xs text-subtext",children:[du(e),r>0&&l.jsxs("span",{className:"text-muted",children:[" · ",$i(r)]})]})}function mis({skill:e,onError:r}){const t=pr({mutationFn:m$n}),n=t.isPending;return l.jsxs("div",{className:"flex items-center gap-2 py-1 border-t border-t-border first:border-t-0",children:[l.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[l.jsx("span",{className:dis,children:e.name}),e.origin&&l.jsx(tr,{size:"small",children:e.origin})]}),l.jsx(KG,{bytes:e.bytes,updatedAt:e.updatedAt}),l.jsx(xt,{size:"small","data-tip":e.origin?P0n():tvn(),"data-tip-align":"end","aria-label":e.origin?o1n({name:Ae(e.name)}):sgn({name:Ae(e.name)}),disabled:n,onClick:()=>{window.confirm(e.origin?Q0n({name:Ae(e.name)}):Vmn({name:Ae(e.name)}))&&t.mutateAsync(e.name).catch(s=>{r(s instanceof Error?s.message:String(s))})},children:l.jsx(ef,{size:14})})]})}function gis({template:e,onError:r}){const t=pr({mutationFn:d$n}),n=t.isPending,s=e.supportFiles.length;return l.jsxs("div",{className:fis,children:[l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("span",{className:"text-base font-medium text-text",children:e.name}),l.jsxs("p",{className:his,children:[e.entry,s>0&&(s===1?b0n():p1n({count:fr(s)}))]})]}),l.jsx(KG,{bytes:e.bytes,updatedAt:e.updatedAt}),l.jsx(xt,{"data-tip":_vn(),"data-tip-align":"end","aria-label":jgn({name:Ae(e.name)}),disabled:n,onClick:()=>{window.confirm(hgn({name:Ae(e.name)}))&&t.mutateAsync(e.name).catch(o=>{r(o instanceof Error?o.message:String(o))})},children:l.jsx(ef,{size:14})})]})}function vis(){var k;const e=pr({mutationFn:p$n}),r=nt(uLn()),t=r.data,n=A.useRef(null),[s,o]=A.useState(!1),[a,i]=A.useState(!1),c=A.useCallback(()=>{const b=n.current;o(!!b&&b.scrollTop>1),i(!!b&&b.scrollHeight-b.scrollTop-b.clientHeight>1)},[]);A.useLayoutEffect(()=>{c();const b=n.current;if(!b)return;const S=new ResizeObserver(c);return S.observe(b),()=>S.disconnect()},[t,c]);const _=r.isFetching,d=(k=r.error)==null?void 0:k.message,[f,p]=A.useState(!1),[m,w]=A.useState(null),y=()=>{r.refetch()},v=A.useRef(!1),x=A.useCallback(async b=>{if(!v.current){if(w(null),!pis(b.name)){w(Kbn());return}if(b.size>HG){w(AI());return}v.current=!0,p(!0);try{await e.mutateAsync({filename:b.name,contentBase64:await GG(b)})}catch(S){w(S instanceof Error?S.message:String(S))}finally{v.current=!1,p(!1)}}},[]);return l.jsxs("section",{className:qG,children:[l.jsxs("div",{className:"flex items-baseline gap-2.5",children:[l.jsx("h3",{children:gbn()}),l.jsxs(Se,{className:"ms-auto",size:"small",onClick:y,disabled:_,children:[l.jsx(Fi,{size:12,className:_?"animate-[spin_0.9s_linear_infinite]":""})," ",I0()]})]}),l.jsx("p",{className:UG,children:Ogn()}),l.jsx(WG,{accept:".md,.markdown,.zip",busy:f,prompt:l.jsxs(l.Fragment,{children:[l.jsx("span",{children:Ugn()}),l.jsx("span",{className:"block ps-4 mt-1 text-text",children:Imn()})]}),onFile:b=>void x(b)}),m&&l.jsx("div",{role:"alert",className:"mt-2.5 text-base text-accent-red whitespace-pre-wrap",children:m}),d&&l.jsxs("div",{role:"alert",className:"pt-3 text-base text-accent-red",children:[S1n()," ",d]}),t===void 0?d?null:l.jsxs("div",{className:"flex items-center gap-2 pt-3 text-sm text-subtext",children:[l.jsx($t,{})," ",Tvn()]}):t.length===0?l.jsx("div",{className:"pt-3 text-sm text-subtext",children:Yvn()}):l.jsxs("div",{className:"relative mt-1",children:[l.jsx("div",{ref:n,onScroll:c,className:"flex flex-col max-h-120 overflow-y-auto overscroll-contain",children:t.map(b=>l.jsx(mis,{skill:b,onError:w},b.name))}),s&&l.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 h-10 bg-gradient-to-b from-background to-transparent"}),a&&l.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 h-10 bg-gradient-to-t from-background to-transparent"})]})]})}function bis(){var d;const e=pr({mutationFn:f$n}),r=nt(lLn()),t=r.data,n=(d=r.error)==null?void 0:d.message,[s,o]=A.useState(!1),[a,i]=A.useState(null),c=A.useRef(!1),_=A.useCallback(async f=>{if(c.current)return;i(null);const p=f.name.toLowerCase();if(!p.endsWith(".tex")&&!p.endsWith(".zip")){i(nyn());return}if(f.size>HG){i(AI());return}c.current=!0,o(!0);try{await e.mutateAsync({filename:f.name,contentBase64:await GG(f)})}catch(m){i(m instanceof Error?m.message:String(m))}finally{c.current=!1,o(!1)}},[]);return l.jsxs("section",{className:qG,children:[l.jsx("h3",{children:xvn()}),l.jsx("p",{className:UG,children:Dbn()}),l.jsx(WG,{accept:".tex,.zip",busy:s,prompt:l.jsxs(l.Fragment,{children:[l.jsx("span",{children:e0n()}),l.jsx("span",{className:"block ps-4 mt-1 text-text",children:Z5n()})]}),onFile:f=>void _(f)}),a&&l.jsx("div",{role:"alert",className:"mt-2.5 text-base text-accent-red whitespace-pre-wrap",children:a}),n&&l.jsxs("div",{role:"alert",className:"pt-3 text-base text-accent-red",children:[$1n()," ",n]}),t===void 0?n?null:l.jsxs("div",{className:"flex items-center gap-2 pt-3 text-sm text-subtext",children:[l.jsx($t,{})," ",Fvn()]}):t.length===0?l.jsx("div",{className:"pt-3 text-sm text-subtext",children:ibn()}):l.jsx("div",{className:"flex flex-col mt-1",children:t.map(f=>l.jsx(gis,{template:f,onError:i},f.name))})]})}function yis(){return l.jsxs("div",{className:"settings-view max-w-readable my-0 mx-auto pt-6 px-8 pb-15 [&_h1]:mt-0 [&_h1]:mx-0 [&_h1]:mb-1.5 [&_h1]:text-3xl",children:[l.jsx("h1",{children:G1n()}),l.jsx("p",{className:"mt-0 mx-0 mb-5 text-base leading-relaxed text-text",children:N0n()}),l.jsx(vis,{}),l.jsx(bis,{})]})}const xis="italic [&_.tab-label_>_span]:pe-1 [&_.tab-label::after]:pe-1";function Yc({active:e,label:r,icon:t,shimmer:n=!1,preview:s=!1,onSelect:o,onPromote:a,onClose:i}){return l.jsxs("button",{className:`tab [&.closable]:max-w-60 [&.closable]:pe-1.5 [&_.tab-label]:grid [&_.tab-label]:grid-cols-[minmax(0,_1fr)] [&_.tab-label]:min-w-0 [&_.tab-label]:overflow-hidden [&_.tab-label_>_span]:[grid-area:1_/_1] [&_.tab-label_>_span]:overflow-hidden [&_.tab-label_>_span]:text-ellipsis [&_.tab-label_>_span]:whitespace-nowrap [&_.tab-label::after]:[grid-area:1_/_1] [&_.tab-label::after]:overflow-hidden [&_.tab-label::after]:text-ellipsis [&_.tab-label::after]:whitespace-nowrap [&_.tab-label::after]:content-[attr(data-label)] [&_.tab-label::after]:invisible [&_.tab-label::after]:font-medium [&_.tab-close]:inline-flex [&_.tab-close]:items-center [&_.tab-close]:justify-center [&_.tab-close]:size-5 [&_.tab-close]:rounded-sm [&_.tab-close]:text-muted [&_.tab-close]:shrink-0 [&_.tab-close:hover]:bg-hover-strong [&_.tab-close:hover]:text-text relative inline-flex items-center gap-1 h-8 py-0 px-2 border border-transparent border-b-0 rounded-[var(--radius-md)_var(--radius-md)_0_0] text-sm font-normal text-subtext whitespace-nowrap select-none min-w-0 [&:hover]:bg-surface [&:hover]:text-text [&:not(.active)_+_.tab:not(.active)::before]:content-[''] [&:not(.active)_+_.tab:not(.active)::before]:absolute [&:not(.active)_+_.tab:not(.active)::before]:top-2.5 [&:not(.active)_+_.tab:not(.active)::before]:bottom-2.5 [&:not(.active)_+_.tab:not(.active)::before]:-start-px [&:not(.active)_+_.tab:not(.active)::before]:w-px [&:not(.active)_+_.tab:not(.active)::before]:bg-border [&.active]:border-border [&.active]:bg-background [&.active]:text-text [&.active]:font-medium [&.active::after]:content-[''] [&.active::after]:absolute [&.active::after]:end-0 [&.active::after]:-bottom-px [&.active::after]:start-0 [&.active::after]:h-px [&.active::after]:bg-background closable ${e?"active":""} ${s?xis:""}`,onClick:o,onDoubleClick:a,title:s?H5n({label:r}):r,"aria-label":s?R5n({label:r}):r,children:[t,l.jsx("span",{className:"tab-label","data-label":r,children:l.jsx("span",{className:n?"tool-running-shimmer":"",children:r})}),l.jsx("span",{role:"button",className:"tab-close",title:Vet(),onPointerDown:c=>c.preventDefault(),onClick:c=>{c.stopPropagation(),i()},children:l.jsx(hn,{size:14})})]})}function wis({activeKey:e,children:r}){const t=A.useRef(null),n=A.useRef(null),[s,o]=A.useState(!1),[a,i]=A.useState(!1),c=A.useRef(!1),_=A.useRef(void 0),d=A.useRef(null),f=A.useRef(!0),p=A.useCallback(()=>{const y=t.current;if(!y)return;const v=y.clientWidth/y.scrollWidth;o(v<1);const x=n.current;x&&(x.style.width=`${y.clientWidth*v}px`,x.style.transform=`translateX(${y.scrollLeft*v}px)`)},[]),m=A.useCallback(()=>{const y=t.current,v=y==null?void 0:y.querySelector(".tab.active");!y||!v||(v.offsetLefty.scrollLeft+y.clientWidth&&(y.scrollLeft=v.offsetLeft+v.offsetWidth-y.clientWidth))},[]),w=A.useCallback(()=>{i(!0),window.clearTimeout(_.current),_.current=window.setTimeout(()=>{c.current||i(!1)},1e3)},[]);return A.useEffect(()=>()=>window.clearTimeout(_.current),[]),A.useEffect(()=>{const y=t.current,v=y==null?void 0:y.firstElementChild;if(!y||!v)return;const x=new ResizeObserver(p),k=new ResizeObserver(()=>{f.current&&m(),p()});return x.observe(y),k.observe(v),()=>{x.disconnect(),k.disconnect()}},[p,m]),A.useEffect(()=>{if(s){p(),i(c.current);return}d.current=null,window.clearTimeout(_.current),i(!1)},[s,p]),A.useEffect(()=>{f.current=!0,m()},[e,m]),l.jsxs("div",{className:"relative flex-1 min-w-0",onPointerEnter:()=>{c.current=!0,window.clearTimeout(_.current),i(!0)},onPointerLeave:()=>{c.current=!1,w()},children:[l.jsx("div",{ref:t,className:"tab-strip relative overflow-x-auto overflow-y-hidden [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",onScroll:()=>{p(),w()},onWheel:y=>{if(y.ctrlKey||(f.current=!1,Math.abs(y.deltaY)<=Math.abs(y.deltaX)))return;const v=y.currentTarget;v.scrollLeft+=y.deltaY*(y.deltaMode===1?16:y.deltaMode===2?v.clientWidth:1)},children:l.jsx("div",{className:"flex items-end w-max",children:r})}),s&&l.jsx("div",{ref:n,"aria-hidden":"true",className:`absolute start-0 -bottom-px flex items-end h-0.5 ${a?"":"pointer-events-none"}`,onPointerDown:y=>{const v=t.current;v&&(y.preventDefault(),f.current=!1,y.currentTarget.setPointerCapture(y.pointerId),d.current={x:y.clientX,scrollLeft:v.scrollLeft})},onPointerMove:y=>{const v=t.current;if(!v||!d.current)return;const x=v.scrollWidth/v.clientWidth;v.scrollLeft=d.current.scrollLeft+(y.clientX-d.current.x)*x},onLostPointerCapture:()=>{d.current=null},children:l.jsx("div",{className:`h-0.5 w-full rounded-full bg-muted transition-opacity duration-300 motion-reduce:transition-none ${a?"opacity-100":"opacity-0"}`})})]})}const wO=["files-pill inline-flex items-center gap-2 min-w-0 border border-border","rounded-md py-2 px-3 bg-background text-text","no-underline [&_code]:font-mono [&_code]:text-sm","[&_code]:overflow-hidden [&_code]:text-ellipsis [&_code]:whitespace-nowrap","[&_>_svg]:shrink-0 [&_>_svg]:text-muted [a&:hover]:border-muted"].join(" ");function kis({owner:e,repo:r,branch:t}){return!e||!r?l.jsx("span",{className:wO,children:l.jsx("code",{children:t})}):l.jsxs("a",{className:wO,href:tx(e,r,t),target:"_blank",rel:"noopener noreferrer",title:S5({name:Ae(t)}),children:[l.jsx("code",{children:t}),l.jsx(sC,{size:12})]})}function jis(e){const r=za(e);return r==="done"||r==="failed"||r==="cancelled"||r==="lost"?r:"running"}const Sis=/^([A-Z][0-9]{0,2}[a-z]?)(?:\s*[:–—-]\s*|\s+)(?=\S)/;function Cis(e){const r=(e.title||e.description||e.slug).split(/\r?\n/)[0].trim(),t=r.match(Sis),n=t?r.slice(t[0].length):r;return{code:t?t[1]:null,label:n.charAt(0).toUpperCase()+n.slice(1)}}function Ey(e,r){return e.createdAt-r.createdAt||e.id.localeCompare(r.id)}function VG(e,r){const t=new Map;for(const o of r){const a=t.get(o.experimentId);a?a.push(o):t.set(o.experimentId,[o])}const n=e.map(o=>{const a=(t.get(o.id)??[]).slice().sort((c,_)=>c.createdAt-_.createdAt||c.id.localeCompare(_.id)),i=a.at(-1)??null;return{id:o.id,experiment:o,parent:null,missingParentId:null,children:[],runs:a,latestRun:i,status:i?jis(i):"none",...Cis(o),task:o.chatSessionId??null,createdAt:o.createdAt}}),s=new Map(n.map(o=>[o.id,o]));for(const o of n){const a=o.experiment.parentExperimentId,i=a?s.get(a):void 0;i?(o.parent=i,i.children.push(o)):a&&(o.missingParentId=a)}for(const o of n)o.children.sort(Ey);return n}function zis(e){const r=[];for(let t=e.parent;t;t=t.parent)r.unshift(t);return r}function Eis(e,r=22){return e.code?e.code:e.label.length>r?e.label.slice(0,r-1).trimEnd()+"…":e.label}function Nis(e,r={}){const t=new Set(e.nodes.map(m=>m.id)),n=m=>m.children.filter(w=>t.has(w.id)),s=new Map,o=new Map,a=m=>{const w=s.get(m.id);if(w!==void 0)return w;const y=1+n(m).reduce((v,x)=>v+a(x),0);return s.set(m.id,y),y},i=m=>[...m].sort((w,y)=>c(y)-c(w)||a(y)-a(w)||Ey(y,w))[0],c=m=>{const w=o.get(m.id);if(w!==void 0)return w;const y=n(m);let v=1;if(y.length){const x=i(y),k=y.filter(b=>b!==x);v=Math.max(c(x),1+Math.max(0,...k.map(c)))}return o.set(m.id,v),v},_=m=>[m,...n(m).flatMap(_)],d=[],f=(m,w,y)=>{var k;if(y&&r.collapseFinished&&!((k=r.expanded)!=null&&k.has(m.id))){const b=_(m);if(b.length>=4&&b.every(S=>S.status==="done")&&!b.some(S=>{var C;return(C=r.keep)==null?void 0:C.has(S.id)})){d.push({kind:"collapsed",head:m,lane:w,hidden:b});return}}d.push({kind:"experiment",node:m,lane:w});const v=n(m);if(!v.length)return;const x=i(v);for(const b of v)b!==x&&f(b,w+1,!0);f(x,w,!1)},p=e.nodes.filter(m=>!m.parent||!t.has(m.parent.id));for(const m of p.sort(Ey))m.parent&&d.push({kind:"lead-in",node:m,from:m.parent,lane:0}),f(m,0,!1);return d}function Ais(e,r=!1){const t=[...e.nodes].sort(Ey);return r&&t.reverse(),t.map(n=>({kind:"experiment",node:n,lane:0}))}function QG(e){return e.reduce((r,t)=>Math.max(r,t.lane+1),0)}function Tis(e){const r=nx(e.backend);return r?[r,iP(e.backend)].filter(Boolean).join(" · "):"—"}function Ris(e){var t;const r=(t=e.backend)==null?void 0:t.jobId;return typeof r=="string"||typeof r=="number"?String(r):"—"}const Nj=14,XG=15,Ny=e=>XG+Nj/2+e*Nj,kO={done:LS,failed:MI,cancelled:RI,lost:OI,running:$I,none:h9t},Mis={done:"var(--accent-green)",failed:"var(--accent-red)",cancelled:"var(--muted)",lost:"var(--muted)",running:"var(--accent-teal)",none:"var(--muted)"},Dv="var(--lineage)",Ois=.48,O4=1;function YG({status:e,cx:r,cy:t,r:n,color:s,background:o="var(--base)"}){const a=Math.max(1.25,n*.38),i=n-a/2;if(e==="done")return l.jsx("circle",{cx:r,cy:t,r:n,fill:s});if(e==="failed"){const _=n*1.18;return l.jsx("path",{d:`M${r} ${t-_}L${r+_} ${t}L${r} ${t+_}L${r-_} ${t}Z`,fill:s})}const c=l.jsx("circle",{cx:r,cy:t,r:i,fill:o,stroke:s,strokeWidth:a});if(e==="running")return l.jsxs("g",{children:[c,l.jsx("path",{d:`M${r} ${t-i}A${i} ${i} 0 0 1 ${r} ${t+i}Z`,fill:s})]});if(e==="cancelled"||e==="lost"){const _=(n-a)*.7;return l.jsxs("g",{children:[c,l.jsx("line",{x1:r-_,y1:t+_,x2:r+_,y2:t-_,stroke:s,strokeWidth:a})]})}return c}function $is({status:e,word:r=!0,size:t=12}){return l.jsxs("span",{className:"inline-flex items-center gap-1.5 whitespace-nowrap text-sm text-text",children:[l.jsx("svg",{width:t,height:t,viewBox:`0 0 ${t} ${t}`,className:"shrink-0","aria-hidden":"true",children:l.jsx(YG,{status:e,cx:t/2,cy:t/2,r:t*.33,color:Mis[e]})}),r?kO[e]():l.jsx("span",{className:"sr-only",children:kO[e]()})]})}function Lis(e){return new Intl.DateTimeFormat(z(),{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(e)}function Dis({ms:e}){return l.jsx("span",{className:"whitespace-nowrap text-xs tabular-nums text-subtext",title:Lis(e),children:$i(e)})}function Iis(e,r){const t=Ny(e.row.lane),n=Ny(r.row.lane);if(t===n)return`M${t} ${e.y+6}V${r.y-6}`;const s=r.top-7;return`M${t} ${e.y+6}V${s}A7 7 0 0 0 ${t+7} ${s+7}H${n-7}A7 7 0 0 1 ${n} ${s+14}V${r.y-6}`}function jO(e){return e.kind==="collapsed"?e.head:e.node}function Pis({placed:e,height:r,path:t,selectedId:n}){const s=new Map;for(const c of e)c.row.kind!=="lead-in"&&s.set(jO(c.row).id,c);const o=[];for(const c of e){if(c.row.kind==="lead-in"){const f=s.get(c.row.node.id);f&&o.push({d:`M${Ny(0)} ${c.top+6}V${f.y-6}`,hot:t.has(c.row.node.id)&&t.has(c.row.from.id),dotted:!0});continue}const _=jO(c.row),d=_.parent?s.get(_.parent.id):void 0;d&&o.push({d:Iis(d,c),hot:t.has(_.id)&&t.has(_.parent.id),dotted:!1})}const a=XG+Nj*QG(e.map(c=>c.row))+8,i=(c,_)=>l.jsx("path",{d:c.d,fill:"none",stroke:c.hot?"var(--text)":Dv,strokeOpacity:c.hot?1:Ois,strokeWidth:c.hot?2:1.5,strokeLinecap:"round",strokeDasharray:c.dotted?"1.5 3.5":void 0},_);return l.jsxs("svg",{className:"pointer-events-none absolute left-0 top-0 z-10",width:a,height:r,"aria-hidden":"true",children:[o.filter(c=>!c.hot).map(i),o.filter(c=>c.hot).map(i),e.map((c,_)=>{if(c.row.kind==="lead-in")return null;const d=Ny(c.row.lane);if(c.row.kind==="collapsed")return l.jsxs("g",{children:[l.jsx("circle",{cx:d,cy:c.y+2.5,r:3.5,fill:"var(--base)",stroke:Dv,strokeOpacity:O4,strokeWidth:1.25}),l.jsx("circle",{cx:d,cy:c.y-1.5,r:3.5,fill:"var(--base)",stroke:Dv,strokeOpacity:O4,strokeWidth:1.25})]},_);const f=c.row.node,p=f.id===n,m=t.has(f.id),w=m?"var(--text)":Dv;return l.jsxs("g",{opacity:m?1:O4,children:[!f.parent&&!f.missingParentId&&l.jsx("circle",{cx:d,cy:c.y,r:7,fill:"none",stroke:w,strokeWidth:1,opacity:.7}),p&&l.jsx("circle",{cx:d,cy:c.y,r:8.5,fill:"var(--text)",fillOpacity:.18}),l.jsx(YG,{status:f.status,cx:d,cy:c.y,r:p?4.6:4,color:w,background:p?"var(--highlight)":"var(--base)"})]},_)})]})}function $4({node:e,current:r,onSelect:t}){return l.jsxs("button",{type:"button",disabled:r,"aria-current":r?"true":void 0,...pn(n=>t(e.id,n)),className:`flex min-w-0 items-center gap-2 rounded-sm px-1.5 py-1 text-start ${r?"bg-highlight":"hover:bg-hover-faint"}`,children:[l.jsx($is,{status:e.status,word:!1,size:11}),e.code&&l.jsx("span",{className:"w-7 shrink-0 font-mono text-xs text-subtext",children:e.code}),l.jsx("span",{className:`min-w-0 flex-1 truncate text-sm text-text ${r?"font-medium":""}`,children:e.label}),l.jsx(Dis,{ms:e.createdAt})]})}function Bis({node:e,onSelect:r}){const[t,n]=A.useState(!1);A.useEffect(()=>n(!1),[e.id]);const s=zis(e),o=s.slice(0,Math.max(0,s.length-4)),a=t?s:s.slice(-4);return l.jsxs("section",{className:"flex flex-col gap-2",children:[l.jsx("h2",{className:"m-0 text-sm font-semibold text-text",children:FD()}),l.jsxs("div",{className:"flex flex-col",children:[s.length>0&&l.jsx("div",{className:"mb-1 text-sm text-subtext",children:$zt()}),o.length>0&&l.jsxs("button",{type:"button","aria-expanded":t,onClick:()=>n(i=>!i),className:"flex min-w-0 items-center gap-1.5 px-1.5 py-1 text-start text-xs text-subtext hover:text-text",title:o.map(i=>i.label).join(" → "),children:[l.jsx(mo,{size:12,className:`shrink-0 ${t?"rotate-90":""}`}),l.jsx("span",{className:"truncate",children:t?Zy():_8t({count:fr(o.length),steps:o.map(i=>Eis(i,18)).join(" → ")})})]}),a.map(i=>l.jsx($4,{node:i,onSelect:r},i.id)),l.jsx($4,{node:e,current:!0,onSelect:r}),e.children.length>0&&l.jsxs("div",{className:"mt-3 flex flex-col gap-1 pt-3",children:[l.jsx("div",{className:"text-sm text-subtext",children:Gzt()}),e.children.map(i=>l.jsx($4,{node:i,onSelect:r},i.id))]})]})]})}const L4=["experiment-overview-section mt-5.5 pt-4.5 border-t border-t-border-variant","[&_h2]:mt-0 [&_h2]:mx-0 [&_h2]:mb-3.5 [&_h2]:text-text [&_h2]:text-sm","[&_h2]:font-semibold"].join(" "),SO=["experiment-overview-command block mt-3 text-text text-sm","wrap-anywhere"].join(" ");function CO(e){return new Date(e).toLocaleString(z(),{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})}function zO(e,r){return Lg((e.endedAt??r)-e.createdAt)}function Fis({experiment:e,lineageNode:r,onOpenExperiment:t,parentExperiment:n,project:s,runs:o,onOpenLogs:a,onOpenTrackio:i,onOpenCode:c,onOpenDiff:_}){const d=o[0]??null,f=WI(o),p=o.some(x=>x.status==="running"||x.status==="starting"),[m,w]=A.useState(()=>Date.now()),y=FS(e.projectId,p).data,v=d!==null&&Qb(y,d.id)!==null;return A.useEffect(()=>{if(!p)return;w(Date.now());const x=window.setInterval(()=>w(Date.now()),1e3);return()=>window.clearInterval(x)},[p]),l.jsx("div",{className:"experiment-overview absolute inset-0 overflow-y-auto bg-background [&_h1]:m-0 [&_h1]:text-text [&_h1]:text-xl [&_h1]:leading-tight",children:l.jsxs("div",{className:"experiment-overview-inner w-full max-w-230 my-0 mx-auto pt-6.5 px-7 pb-10 [@media((max-width:_720px))]:pt-5 [@media((max-width:_720px))]:px-4.5 [@media((max-width:_720px))]:pb-8",children:[l.jsxs("header",{className:"experiment-overview-head flex items-start justify-between gap-6",children:[l.jsxs("div",{className:"experiment-overview-heading min-w-0",children:[l.jsx("h1",{children:e.title||e.slug}),l.jsx("div",{className:"experiment-overview-slug mt-1 text-muted text-sm",children:e.slug})]}),l.jsx(vu,{status:d?za(d):"idle"})]}),l.jsxs("div",{className:"experiment-overview-actions flex gap-2 mt-4.5 [@media((max-width:_720px))]:flex-wrap",children:[d&&l.jsxs(Se,{...pn(x=>a(d.id,x)),children:[l.jsx(yc,{size:16}),MD()]}),d&&v&&l.jsxs(Se,{title:Pb(),...pn(x=>i(d.id,x)),children:[l.jsx(ax,{size:16}),kS()]}),l.jsxs(Se,{...pn(c),children:[l.jsx(lx,{size:16}),iht()]}),l.jsx(Lo,{interactive:!0,content:npt(),children:l.jsxs(Se,{disabled:!n,...pn(_),children:[l.jsx(FPn,{size:16}),Kht()]})})]}),e.description&&l.jsxs("section",{className:"experiment-overview-section mt-5.5 pt-4.5 border-t border-t-border-variant [&_h2]:mt-0 [&_h2]:mx-0 [&_h2]:mb-3.5 [&_h2]:text-text [&_h2]:text-sm [&_h2]:font-semibold overview-description [&_.md]:text-text [&_.md]:leading-relaxed",children:[l.jsx("h2",{children:Dht()}),l.jsx(xc,{text:e.description})]}),l.jsxs("section",{className:L4,children:[l.jsx("h2",{children:d?Ydt():Dmt()}),d&&l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"experiment-overview-meta flex items-center flex-wrap gap-y-2.5 gap-x-4.5 text-text text-sm [&_svg]:text-muted [&_.backend-badge]:text-text [&_.status-badge]:text-text [&_>_span]:inline-flex [&_>_span]:items-center [&_>_span]:gap-1 [&_code]:text-text [&_code]:text-xs",children:[l.jsx(vu,{status:za(d)}),l.jsx(oC,{backend:d.backend}),l.jsxs("span",{title:vmt(),children:[l.jsx(VIn,{size:14}),CO(d.createdAt)]}),l.jsxs("span",{title:dpt(),children:[l.jsx(iPn,{size:14}),zO(d,m)]}),d.commitSha&&l.jsxs("span",{title:ght(),children:[l.jsx(PPn,{size:14}),l.jsx("code",{children:d.commitSha.slice(0,7)})]}),d.exitCode!==null&&d.exitCode!==void 0&&d.exitCode!==0&&l.jsxs("span",{children:[kpt()," ",d.exitCode]})]}),d.command&&l.jsxs("code",{className:SO,children:["$ ",d.command]}),f&&l.jsx("p",{className:"experiment-overview-monitoring mt-4 text-accent-amber text-sm wrap-anywhere",children:f}),d.resultMarkdown&&l.jsx("div",{className:`experiment-overview-result mt-4 [&.failed]:text-accent-red ${d.status==="failed"?"failed":""}`,children:l.jsx(xc,{text:d.resultMarkdown})})]})]}),o.length>0&&l.jsxs("section",{className:`${L4} @container`,children:[l.jsx("h2",{children:cmt()}),l.jsx("div",{className:"experiment-run-history divide-y divide-border-variant [&_button]:w-full [&_button]:grid [&_button]:grid-cols-[minmax(72px,_0.7fr)_minmax(100px,_1fr)_minmax(70px,_0.7fr)_60px_16px] [&_button]:items-center [&_button]:gap-3.5 [&_button]:py-3 [&_button]:px-0.5 [&_button]:text-text [&_button]:text-start [&_button]:text-sm [&_button:hover]:bg-surface @max-lg:[&_button]:grid-cols-[48px_minmax(0,_1fr)_40px_16px] @max-lg:[&_button_>_:nth-child(3)]:hidden",children:o.map((x,k)=>l.jsxs("button",{...pn(b=>a(x.id,b)),children:[l.jsxs("span",{className:"experiment-run-number text-xs font-medium",children:[Zpt()," ",o.length-k]}),l.jsx(vu,{status:za(x),className:"min-w-0"}),l.jsx("span",{children:$i(x.createdAt)}),l.jsx("span",{children:zO(x,m)}),l.jsx(yc,{size:14})]},x.id))})]}),r&&l.jsx("div",{className:"mt-5.5 border-t border-border-variant pt-4.5",children:l.jsx(Bis,{node:r,onSelect:t})}),l.jsxs("section",{className:L4,children:[l.jsx("h2",{children:"Git"}),l.jsxs("div",{className:"experiment-overview-meta flex items-center flex-wrap text-text text-sm [&_svg]:text-muted [&_.backend-badge]:text-text [&_.status-badge]:text-text [&_>_span]:inline-flex [&_>_span]:items-center [&_>_span]:gap-1 [&_code]:text-text [&_code]:text-xs experiment-overview-git-meta gap-y-2 gap-x-3.5 [&_.files-pill]:py-1 [&_.files-pill]:px-2 [&_.files-pill]:rounded-sm [&_.files-pill_code]:text-xs",children:[l.jsx(kis,{owner:s.githubEnabled?s.githubOwner:"",repo:s.githubEnabled?s.githubRepo:"",branch:e.branchName}),n&&l.jsxs("span",{children:[Mpt()," ",l.jsx("code",{children:n.slug})]}),l.jsxs("span",{title:CO(e.createdAt),children:[zht()," ",$i(e.createdAt)]})]}),e.runCommand!==(d==null?void 0:d.command)&&l.jsxs("code",{className:SO,children:["$ ",e.runCommand]})]})]})})}function EO(e){const r=atob(e),t=new Uint8Array(r.length);for(let n=0;n{const t=r.current;if(!t)return;const{terminal:n,dispose:s}=dx(t,!0);let o=!1,a=0,i,c=!1,_=!1;async function d(){if(c){_=!0;return}c=!0;try{for(;;){const p=await zMn(e,a,i);if(o)return;if((p.offset!==a||i!==void 0&&i!==p.generation)&&n.reset(),i=p.generation,p.dataBase64&&n.write(EO(p.dataBase64)),a=p.nextOffset,p.eof)break}}catch{}finally{c=!1,_&&!o&&(_=!1,d())}}const f=hLn(e,p=>{if(o)return;if(p.generation!==void 0&&p.generation!==i){d();return}const m=EO(p.dataBase64);!c&&p.offset===a?(n.write(m),a+=m.length):p.offset+m.length>a&&d()});return d(),()=>{o=!0,f(),s()}},[e]),l.jsx("div",{ref:r,className:"h-full w-full"})}function qis({experiment:e,experiments:r,project:t,view:n,runs:s,selectedRunId:o,onSelectRun:a,parentExperiment:i,onOpenView:c,onOpenCode:_,onOpenExperiment:d}){const f=s.filter(p=>p.experimentId===e.id).sort((p,m)=>m.createdAt-p.createdAt);if(n==="overview"){const p=VG(r,s).find(m=>m.id===e.id);return l.jsx(Fis,{lineageNode:p??null,onOpenExperiment:d,experiment:e,parentExperiment:i,project:t,runs:f,onOpenLogs:(m,w)=>c("terminal",m,w),onOpenTrackio:(m,w)=>c("trackio",m,w),onOpenCode:m=>_("files",m),onOpenDiff:m=>_("changes",m)})}return l.jsx(Uis,{experiment:e,expRuns:f,view:n,selectedRunId:o,onSelectRun:a,onOpenView:c})}function Uis({experiment:e,expRuns:r,view:t,selectedRunId:n,onSelectRun:s,onOpenView:o}){var E;const[a,i]=A.useState(null),[c,_]=A.useState(null),[d,f]=A.useState(!1),p=A.useRef(null),m=n?r.find(R=>R.id===n)??null:r[0]??null,w=m?GI(m):null,y=(m==null?void 0:m.status)==="running"||(m==null?void 0:m.status)==="starting",v=WLn(),x=FS(e.projectId,y),k=x.data,b=m?Qb(k,m.id):null,S=t==="trackio"&&m?Qb(k,m.id,{theme:v}):null,C=!!(m&&y&&(m.cancelRequested||c===m.id)),N=R=>{const $=r.findIndex(L=>L.id===R);return $===-1?r.length:r.length-$};A.useEffect(()=>{if(!d)return;const R=$=>{var L;(L=p.current)!=null&&L.contains($.target)||f(!1)};return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[d]);async function T(){if(m){i(null),_(m.id);try{await VI(m.id)}catch(R){_(null),i(R instanceof Error?R.message:String(R))}}}return l.jsxs("div",{className:"term-view absolute inset-0 flex flex-col bg-background z-20",children:[l.jsxs("div",{className:"term-bar flex items-center gap-2 h-10 py-0 px-2.5 border-b border-b-border shrink-0 [&_.error]:text-sm [&_.error]:text-accent-red [&_.btn]:inline-flex [&_.btn]:items-center [&_.btn]:gap-1",children:[l.jsx("div",{className:"term-title min-w-0 text-sm font-semibold text-text overflow-hidden text-ellipsis whitespace-nowrap",title:e.title||e.slug,children:e.title||e.slug}),l.jsx("span",{className:"flex-1"}),a&&l.jsx("span",{className:"error",role:"alert",children:a}),t==="trackio"?l.jsxs(l.Fragment,{children:[b&&l.jsx(B_,{size:"small",variant:"ghost",title:fE(),"aria-label":fE(),href:b,target:"_blank",rel:"noopener noreferrer",children:l.jsx(F_,{size:14})}),l.jsxs(Se,{size:"small",variant:"ghost",...pn(R=>o("terminal",m==null?void 0:m.id,R)),children:[l.jsx(ux,{size:14}),MD()]})]}):b&&l.jsxs(Se,{size:"small",variant:"ghost",title:Pb(),...pn(R=>o("trackio",m==null?void 0:m.id,R)),children:[l.jsx(ax,{size:14}),kS()]}),y&&l.jsxs(Se,{size:"small",variant:"ghost",disabled:C,onClick:()=>void T(),children:[l.jsx(VP,{size:14}),C?vrt():TD()]}),r.length>0&&m&&l.jsxs("div",{className:"run-history relative shrink-0",ref:p,children:[l.jsxs(Se,{title:oft(),"aria-expanded":d,onClick:()=>f(R=>!R),children:[l.jsxs("span",{children:[aN()," ",N(m.id)]}),l.jsx(vu,{status:C?"cancelling":za(m)}),l.jsx(kc,{size:14,className:"run-picker-chev text-muted shrink-0"})]}),d&&l.jsx("div",{className:"history-menu absolute top-[calc(100%_+_6px)] end-0 min-w-57.5 max-h-80 overflow-y-auto bg-background border border-border rounded-lg shadow-menu p-1 z-50",children:r.map(R=>l.jsxs(cr,{className:"justify-start",active:R.id===(m==null?void 0:m.id),onClick:()=>{s(R.id),f(!1)},children:[l.jsxs("span",{className:"font-medium",children:[aN()," ",N(R.id)]}),l.jsx(vu,{status:za(R)}),l.jsx("span",{className:"ms-auto text-xs text-muted",children:$i(R.createdAt)})]},R.id))})]})]}),m&&l.jsxs("div",{className:"term-provenance","aria-label":Q_t(),children:[l.jsxs("span",{children:[y_t()," ",l.jsx("code",{children:m.id})]}),l.jsxs("span",{children:[u_t()," ",l.jsx("code",{children:m.commitSha||t8t()})]}),l.jsxs("span",{children:[e_t()," ",l.jsx("code",{children:Tis(m)})]}),l.jsxs("span",{children:[A_t()," ",l.jsx("code",{children:Ris(m)})]})]}),w&&l.jsx("p",{role:"status",className:"m-0 shrink-0 border-b border-border-variant px-3 py-2 text-sm text-accent-amber wrap-anywhere",children:w}),l.jsx("div",{className:`term-fill flex-1 min-h-0 ${t==="trackio"?"bg-background":"bg-terminal pt-1 pe-0 pb-1 ps-1.5"}`,children:S?l.jsx("iframe",{className:"block w-full h-full border-0",title:Pb(),src:S,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-popups allow-forms allow-downloads"},S):t==="trackio"?l.jsx("div",{className:"term-empty h-full flex items-center justify-center p-6 text-center text-sm text-muted",children:x.isPending?Yy():((E=x.error)==null?void 0:E.message)??pft()}):m?l.jsx(His,{runId:m.id},m.id):l.jsx("div",{className:"term-empty h-full flex items-center justify-center p-6 text-center text-sm text-muted",children:n?Ri():Uut()})})]})}let Aj=!1;function NO(e){Aj=!0;try{return window.confirm(e)}finally{Aj=!1}}const Tj=e=>e.replace(/\r\n/g,` `),AO=(e,r,t)=>{const n=Tj(r);return{path:e,draft:n,baseline:n,version:t,crlf:r.includes(`\r `),conflict:null}},ru=e=>e.draft!==e.baseline,Gis=(e,r)=>({...e,draft:r,conflict:r===e.baseline?null:e.conflict}),Wis=e=>e.crlf?e.draft.replace(/\n/g,`\r diff --git a/ui/dist/index.html b/ui/dist/index.html index 338aa00f1..1a6d04d6d 100644 --- a/ui/dist/index.html +++ b/ui/dist/index.html @@ -49,7 +49,7 @@ html { background: #ffffff; } html[data-theme="dark"] { background: #181818; } - + diff --git a/ui/src/components/SettingsPage.tsx b/ui/src/components/SettingsPage.tsx index cbb6ba84e..752308473 100644 --- a/ui/src/components/SettingsPage.tsx +++ b/ui/src/components/SettingsPage.tsx @@ -415,6 +415,10 @@ function HarnessesTab({ remote }: { remote: boolean }) { (a, b) => Number(b.agentReady) - Number(a.agentReady), ); const h = orderedHarnesses.find((x) => x.id === active) ?? orderedHarnesses[0]; + useEffect(() => { + // Pin the settled default so a failed refresh cannot switch harnesses. + if (h && active !== h.id && !orderedHarnesses.some((x) => x.catalogPending)) setActive(h.id); + }, [h, active, orderedHarnesses]); const acp = definitions.data?.find((definition) => definition.id === h?.id); return ( diff --git a/ui/tests/queryConsumers.test.mjs b/ui/tests/queryConsumers.test.mjs index 28c3d0bfa..8c0b8443a 100644 --- a/ui/tests/queryConsumers.test.mjs +++ b/ui/tests/queryConsumers.test.mjs @@ -34,35 +34,39 @@ function sendPreparation() { return prefix; } +function settingsRenderer(name, returns, bindings) { + const file = source("SettingsPage.tsx"); + const component = file.statements.find((node) => ts.isFunctionDeclaration(node) && node.name.text === name); + const statements = component.body.statements; + const prefix = statements.slice(0, statements.findIndex(ts.isReturnStatement)).map((node) => node.getText(file)).join("\n"); + const state = []; + let cursor, effects, changed; + const hook = (init) => { const index = cursor++; if (!(index in state)) state[index] = init(); return index; }; + const hooks = { + useState: (initial) => { const i = hook(() => initial); return [state[i], (next) => { const value = typeof next === "function" ? next(state[i]) : next; changed ||= !Object.is(value, state[i]); state[i] = value; }]; }, + useRef: (initial) => state[hook(() => ({ current: initial }))], + useEffect: (effect, deps) => { const i = hook(() => undefined); if (!state[i] || deps.some((value, index) => !Object.is(value, state[i][index]))) { state[i] = deps; effects.push(effect); } }, + }; + return () => { + for (let attempt = 0; attempt < 5; attempt++) { + cursor = 0; effects = []; changed = false; + const result = evaluate(`${prefix}\nreturn ${returns};`, { ...hooks, ...bindings }); + effects.forEach((effect) => effect()); + if (!changed) return result; + } + assert.fail(`${name} effects did not settle`); + }; +} + for (const [name, fields] of [["K8s", ["context", "namespace"]], ["Slurm", ["host", "partition", "account", "timeLimit"]], ["Ray", ["address"]]]) { test(`${name} settings refresh clean fields while preserving edits`, () => { - const file = source("SettingsPage.tsx"); - const component = file.statements.find((node) => ts.isFunctionDeclaration(node) && node.name.text === `${name}Section`); - const statements = component.body.statements; - const prefix = statements.slice(0, statements.findIndex(ts.isReturnStatement)).map((node) => node.getText(file)).join("\n"); - const state = []; - let cursor, effects, changed; let snapshot = Object.fromEntries(fields.map((field) => [field, "original"])); - const hook = (init) => { const index = cursor++; if (!(index in state)) state[index] = init(); return index; }; - const bindings = { - useState: (initial) => { const i = hook(() => initial); return [state[i], (next) => { const value = typeof next === "function" ? next(state[i]) : next; changed ||= !Object.is(value, state[i]); state[i] = value; }]; }, - useRef: (initial) => state[hook(() => ({ current: initial }))], - useEffect: (effect, deps) => { const i = hook(() => undefined); if (!state[i] || deps.some((value, index) => !Object.is(value, state[i][index]))) { state[i] = deps; effects.push(effect); } }, + const render = settingsRenderer(`${name}Section`, `{ values: {${fields}}, setters: {${fields.map((field) => `${field}: set${field[0].toUpperCase()}${field.slice(1)}`).join(",")}} }`, { useMutation: () => ({}), useQuery: () => ({ data: snapshot }), useSshMasterStatuses: () => [{}, () => {}], [`get${name}SettingsQuery`]: () => ({ queryKey: [] }), [`save${name}Settings`]: () => {}, remote: false, onEditState: undefined, - }; - const code = `${prefix}\nreturn { values: {${fields}}, setters: {${fields.map((field) => `${field}: set${field[0].toUpperCase()}${field.slice(1)}`).join(",")}} };`; - function render() { - for (let attempt = 0; attempt < 5; attempt++) { - cursor = 0; effects = []; changed = false; - const result = evaluate(code, bindings); - effects.forEach((effect) => effect()); - if (!changed) return result; - } - assert.fail("settings effects did not settle"); - } + }); assert.deepEqual(render().values, snapshot); snapshot = Object.fromEntries(fields.map((field) => [field, "refreshed"])); assert.deepEqual(render().values, snapshot); @@ -73,6 +77,23 @@ for (const [name, fields] of [["K8s", ["context", "namespace"]], ["Slurm", ["hos }); } +test("harness settings keep the settled selection when readiness changes", () => { + let snapshot = []; + const render = settingsRenderer("HarnessesTab", "{ h }", { + useQuery: (options) => ({ data: options.harnesses ? snapshot : [] }), + getHarnessesQuery: () => ({ harnesses: true }), + getHarnessSetupCommandsQuery: () => ({}), + useCommandRun: () => ({}), workspaceKey: () => [], listAcpHarnesses: () => {}, + }); + assert.equal(render().h, undefined); + snapshot = [{ id: "claude-code", catalogPending: true }, { id: "opencode", catalogPending: true }]; + assert.equal(render().h.id, "claude-code"); + snapshot = [{ id: "claude-code", agentReady: false }, { id: "opencode", agentReady: true }]; + assert.equal(render().h.id, "opencode"); + snapshot = [{ id: "claude-code", agentReady: true }, { id: "opencode", agentReady: false }]; + assert.equal(render().h.id, "opencode"); +}); + test("queued chat writes stop when their captured workspace retires", async () => { const file = source("ChatPanel.tsx"); let generation = 1, release, calls = 0;