specrails-desktop 2.53.0 → 2.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/dist/assets/{ActivityFeedPage-CEWktcV8.js → ActivityFeedPage-ILXMZXcb.js} +1 -1
- package/client/dist/assets/{AgentBrowserCapture-Bnu8aoF2.js → AgentBrowserCapture-UcsupCy7.js} +1 -1
- package/client/dist/assets/{AgentModeAnalyticsPane-N0k6nlj0.js → AgentModeAnalyticsPane-CQuxYh8B.js} +2 -2
- package/client/dist/assets/{AgentModeCodePane-7s6TnZGe.js → AgentModeCodePane-zPWbW7ei.js} +2 -2
- package/client/dist/assets/{AgentModeJobsPane-Btsb5Sq4.js → AgentModeJobsPane-CInByIdl.js} +1 -1
- package/client/dist/assets/{AgentsPage-BXgiO5qZ.js → AgentsPage-BWvgxaBv.js} +1 -1
- package/client/dist/assets/{AnalyticsPage-CO8-ON4i.js → AnalyticsPage-DP3jakv-.js} +1 -1
- package/client/dist/assets/{CodePage-CMSInNsE.js → CodePage-BKXiwE5a.js} +1 -1
- package/client/dist/assets/{DesktopAnalyticsPage-1ekD8Gob.js → DesktopAnalyticsPage-DryJOaMz.js} +1 -1
- package/client/dist/assets/{DocsDialog-CZ1QztVB.js → DocsDialog-BsCG9ksG.js} +1 -1
- package/client/dist/assets/{DocsPage-DHdvuLeh.js → DocsPage-Cc-GeKYl.js} +1 -1
- package/client/dist/assets/{InteractiveJobComposer-DDYgxV10.js → InteractiveJobComposer-DfLF6N0f.js} +1 -1
- package/client/dist/assets/{JobDetailModal-DSsX48Vu.js → JobDetailModal-DHeur9YK.js} +1 -1
- package/client/dist/assets/{JobDetailPage-DbzshFhr.js → JobDetailPage-CraDKzeG.js} +1 -1
- package/client/dist/assets/{JobsPage-DY4qRt9_.js → JobsPage-CcbuSwj7.js} +1 -1
- package/client/dist/assets/{LoopBuilderPage-DTqzBtuf.js → LoopBuilderPage-BKtNp494.js} +1 -1
- package/client/dist/assets/{LoopPreviewModal-C-NbAvIZ.js → LoopPreviewModal-DbZd9isy.js} +1 -1
- package/client/dist/assets/{LoopsPage-C-RjiAxo.js → LoopsPage-DEg6sIkG.js} +1 -1
- package/client/dist/assets/{PluginsPage-BUdxGBro.js → PluginsPage-BVqSsPzL.js} +1 -1
- package/client/dist/assets/{ProjectSettingsDialog-e7y_uZIz.js → ProjectSettingsDialog-CAjLgJAZ.js} +1 -1
- package/client/dist/assets/{ReviewPacketPage-Bs_jaLbJ.js → ReviewPacketPage-D-UjTef3.js} +1 -1
- package/client/dist/assets/{TemplatePreviewModal-DoeJuvcY.js → TemplatePreviewModal-Bqs-9fhn.js} +1 -1
- package/client/dist/assets/{index-Cn-T8bgL.js → index-BfAZg5DG.js} +6 -6
- package/client/dist/index.html +1 -1
- package/docs/ci-cd.md +4 -0
- package/package.json +1 -1
- package/server/dist/agent-chat-manager.js +17 -7
- package/server/dist/agent-chat-router.js +1 -0
- package/server/dist/mobile/mobile-code.js +100 -0
- package/server/dist/mobile/mobile-missions.js +26 -4
- package/server/dist/mobile/mobile-router.js +60 -6
- package/server/dist/mobile/mobile-signal-reconnect.js +17 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/core-B3mKBIh5.js","assets/rolldown-runtime-CNC7AqOf.js","assets/event-Bt7f3wXe.js","assets/addon-image-BRmmRHgQ.js","assets/addon-ligatures-qIZUPvRV.js","assets/addon-webgl-C2d7lriQ.js","assets/JobDetailModal-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/core-B3mKBIh5.js","assets/rolldown-runtime-CNC7AqOf.js","assets/event-Bt7f3wXe.js","assets/addon-image-BRmmRHgQ.js","assets/addon-ligatures-qIZUPvRV.js","assets/addon-webgl-C2d7lriQ.js","assets/JobDetailModal-DHeur9YK.js","assets/jsx-runtime-zu2_FqZY.js","assets/react-dom-DiWzBDP9.js","assets/TicketDetailModalContext-C0jQ5yOk.js","assets/preload-helper-Czpn1I53.js","assets/chunk-KS7C4IRE-DEKu087k.js","assets/useSharedWebSocket-DcPRKR8R.js","assets/activity-DiyjsgQV.js","assets/addspec-BOvgmcgk.js","assets/agent-aiVhqFW1.js","assets/agentRuntime-bAAjw1vw.js","assets/agents-CTwbx-fb.js","assets/agentstudio-CN2pokQu.js","assets/aiedit-iIjz2_Qk.js","assets/analytics-BlypLLR6.js","assets/attachments-B53PG733.js","assets/browser-CG0PE1j_.js","assets/builder-BTiGnPT0.js","assets/chat-BGD7MXAy.js","assets/code-DaZ-ZwCT.js","assets/commands-BAWSYHjQ.js","assets/common-BrlwEnL7.js","assets/dashboard-DBAP2_SQ.js","assets/explore-DgBACn39.js","assets/integrations-mB-7zoyT.js","assets/jira-CKJg3HZd.js","assets/jobs-C9j2PuwW.js","assets/loops-B7YpGizO.js","assets/mcp-CUAN6ORK.js","assets/narration-n3hOA7LY.js","assets/nav-DhPb-Isc.js","assets/packet-DwPtJoDz.js","assets/settings-HZSu-K4l.js","assets/setup-DpqzaEEA.js","assets/specs-DfIdoU5L.js","assets/terminal-BAzpHtpY.js","assets/tickets-D41ZMQpf.js","assets/createLucideIcon-Bjbbp_KS.js","assets/Trans-DtWlCJN9.js","assets/useDesktop-CPB4cnwI.js","assets/provider-capabilities-Vi1ZGvAK.js","assets/save-B6wGWwBR.js","assets/spending-BGmZBX5B.js","assets/MinimizedChatsContext-BGtEjWsc.js","assets/sparkles-DrY8hb0X.js","assets/x-CBMI9ejn.js","assets/zap-CUOlvtT1.js","assets/circle-x-CMYsN4ZH.js","assets/download-CFHyyHcw.js","assets/file-text-CFT-xXKN.js","assets/git-branch-BRM0F5GN.js","assets/layers-eDMjG41I.js","assets/loader-circle-DcygOQpC.js","assets/pencil-C9RkrIPZ.js","assets/square-Ci-PFcFe.js","assets/plus-CsnjfkmX.js","assets/rotate-ccw-Wh4id13q.js","assets/search-Cq_gE3Ik.js","assets/trash-2-BOU3WdZZ.js","assets/triangle-alert-H9T4jAmh.js","assets/wrench-BfmNO9Vw.js","assets/dialog-xXB2q5HJ.js","assets/utils-BC4DHlz2.js","assets/clsx-CjueKrWZ.js","assets/lib-CGdyxIWg.js","assets/formatDistanceToNow-DYmvOA3R.js","assets/getTimezoneOffsetInMilliseconds-BAhW5E6V.js","assets/button-Ccc9Dc-D.js","assets/jira-api-B27Za5FP.js","assets/RepositoryScopeSelector-CAGY3xW6.js","assets/project-repositories-DixIZHTA.js","assets/InteractiveJobComposer-DfLF6N0f.js","assets/useRuntimeRuns-DEQ9HdAM.js","assets/lib-C7Mhm-gT.js","assets/job-time-BCL7wee9.js","assets/LoopPreviewModal-DbZd9isy.js","assets/TemplatePreviewModal-Bqs-9fhn.js","assets/AgentModeCodePane-zPWbW7ei.js","assets/AgentModeJobsPane-CInByIdl.js","assets/format-command-C0D9IPmV.js","assets/AgentModeAnalyticsPane-CQuxYh8B.js","assets/dist-js-CJ_2XX1Y.js","assets/ProjectSettingsDialog-CAjLgJAZ.js","assets/AgentBrowserCapture-UcsupCy7.js","assets/JobDetailPage-CraDKzeG.js","assets/ReviewPacketPage-D-UjTef3.js","assets/RepositoryDeliveries-DrcrxLe0.js","assets/JobsPage-CcbuSwj7.js","assets/ExportDropdown-ClahJdDn.js","assets/AnalyticsPage-DP3jakv-.js","assets/BarChart-nBOMNfiy.js","assets/value-s-gzBeyF.js","assets/ActivityFeedPage-ILXMZXcb.js","assets/AgentsPage-BWvgxaBv.js","assets/CodePage-BKXiwE5a.js","assets/IntegrationsPage-Bhy58lnQ.js","assets/PluginsPage-BVqSsPzL.js","assets/DesktopAnalyticsPage-DryJOaMz.js","assets/DocsPage-Cc-GeKYl.js","assets/atom-one-dark-qiGhVQxg.js","assets/atom-one-dark-B-oHczHB.css","assets/DocsDialog-BsCG9ksG.js","assets/LoopsPage-DEg6sIkG.js","assets/upload-DYMjAQ6M.js","assets/LoopBuilderPage-BKtNp494.js","assets/LoopBuilderPage-DtxX27Jz.css"])))=>i.map(i=>d[i]);
|
|
2
2
|
import{a as e,i as t,n,r,t as i}from"./rolldown-runtime-CNC7AqOf.js";import{n as a,t as o}from"./jsx-runtime-zu2_FqZY.js";import{t as s}from"./react-dom-DiWzBDP9.js";import{t as c}from"./preload-helper-Czpn1I53.js";import{a as l,c as u,f as d,i as f,l as p,n as m,o as h,r as g,s as _,t as v,u as y}from"./chunk-KS7C4IRE-DEKu087k.js";import{$ as b,A as x,B as S,C,D as w,E as T,F as E,G as D,H as O,I as k,K as A,L as j,M,N,O as P,P as F,Q as I,R as L,S as R,T as z,U as B,V,W as H,X as U,Z as W,_ as ee,_t as te,a as ne,at as re,b as ie,c as ae,ct as oe,dt as se,et as ce,ft as le,g as ue,gt as de,h as fe,ht as G,i as pe,it as me,j as he,k as ge,l as _e,lt as ve,mt as ye,n as be,nt as xe,o as Se,ot as Ce,p as we,pt as Te,r as Ee,rt as De,s as Oe,st as ke,t as Ae,tt as je,v as Me,vt as Ne,w as Pe,x as Fe,y as Ie,z as Le}from"./TicketDetailModalContext-C0jQ5yOk.js";import{C as Re,O as ze,S as Be,T as Ve,_ as He,a as Ue,b as We,d as Ge,f as Ke,g as qe,h as Je,i as Ye,l as Xe,m as Ze,n as Qe,o as $e,p as et,r as tt,s as nt,t as rt,u as it,v as at,w as ot,x as st,y as ct}from"./useSharedWebSocket-DcPRKR8R.js";import{t as lt}from"./Trans-DtWlCJN9.js";import{n as K,t as q}from"./createLucideIcon-Bjbbp_KS.js";import{a as ut,n as dt,o as ft,r as pt,s as J,t as mt}from"./useDesktop-CPB4cnwI.js";import{a as Y,n as ht,r as gt,t as _t}from"./core-B3mKBIh5.js";import{_ as vt,a as yt,d as bt,f as xt,g as St,h as Ct,i as wt,l as Tt,m as Et,n as Dt,o as Ot,p as kt,r as At,s as jt,t as Mt,u as Nt}from"./provider-capabilities-Vi1ZGvAK.js";import{C as Pt,D as Ft,E as It,O as Lt,S as Rt,T as zt,_ as Bt,a as Vt,b as Ht,c as Ut,d as Wt,f as Gt,g as Kt,h as qt,i as Jt,k as Yt,l as Xt,m as Zt,n as Qt,o as $t,p as en,r as tn,s as nn,t as rn,u as an,v as on,w as sn,x as cn,y as ln}from"./RepositoryDeliveries-DrcrxLe0.js";import{n as un,t as dn}from"./save-B6wGWwBR.js";import{a as fn,c as pn,d as mn,i as hn,l as gn,n as _n,o as vn,r as yn,s as bn,t as xn,u as Sn}from"./MinimizedChatsContext-BGtEjWsc.js";import{n as Cn,t as wn}from"./zap-CUOlvtT1.js";import{t as Tn}from"./circle-x-CMYsN4ZH.js";import{t as En}from"./download-CFHyyHcw.js";import{t as Dn}from"./file-text-CFT-xXKN.js";import{t as On}from"./git-branch-BRM0F5GN.js";import{t as kn}from"./layers-eDMjG41I.js";import{t as An}from"./loader-circle-DcygOQpC.js";import{t as jn}from"./pencil-C9RkrIPZ.js";import{n as Mn,t as Nn}from"./square-Ci-PFcFe.js";import{t as Pn}from"./plus-CsnjfkmX.js";import{t as Fn}from"./rotate-ccw-Wh4id13q.js";import{t as In}from"./search-Cq_gE3Ik.js";import{t as Ln}from"./sparkles-DrY8hb0X.js";import{t as Rn}from"./trash-2-BOU3WdZZ.js";import{t as zn}from"./triangle-alert-H9T4jAmh.js";import{t as Bn}from"./wrench-BfmNO9Vw.js";import{t as Vn}from"./x-CBMI9ejn.js";import{A as Hn,C as Un,D as Wn,E as Gn,M as Kn,O as qn,S as Jn,T as Yn,_ as Xn,a as Zn,b as Qn,c as $n,d as er,f as tr,g as nr,h as rr,i as ir,j as ar,k as or,l as sr,m as cr,n as lr,o as ur,p as dr,r as fr,s as pr,t as mr,u as hr,v as gr,w as _r,x as vr,y as yr}from"./dialog-xXB2q5HJ.js";import{t as X}from"./utils-BC4DHlz2.js";import{n as br,t as xr}from"./lib-CGdyxIWg.js";import{t as Sr}from"./getTimezoneOffsetInMilliseconds-BAhW5E6V.js";import{t as Cr}from"./formatDistanceToNow-DYmvOA3R.js";import{n as wr,t as Z}from"./button-Ccc9Dc-D.js";import{n as Tr,t as Er}from"./project-repositories-DixIZHTA.js";import{t as Dr}from"./RepositoryScopeSelector-CAGY3xW6.js";import{n as Or,t as kr}from"./useRuntimeRuns-DEQ9HdAM.js";import{a as Ar,n as jr,o as Mr,r as Nr,t as Pr}from"./event-Bt7f3wXe.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var Fr=i((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m)if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),Ir=i(((e,t)=>{t.exports=Fr()})),Lr=i((e=>{var t=Ir(),n=a(),r=s();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function o(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function c(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function l(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function u(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function d(e){if(c(e)!==e)throw Error(i(188))}function f(e){var t=e.alternate;if(!t){if(t=c(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var o=a.alternate;if(o===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===o.child){for(o=a.child;o;){if(o===n)return d(a),e;if(o===r)return d(a),t;o=o.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=o;else{for(var s=!1,l=a.child;l;){if(l===n){s=!0,n=a,r=o;break}if(l===r){s=!0,r=a,n=o;break}l=l.sibling}if(!s){for(l=o.child;l;){if(l===n){s=!0,n=o,r=a;break}if(l===r){s=!0,r=o,n=a;break}l=l.sibling}if(!s)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function p(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=p(e),t!==null)return t;e=e.sibling}return null}var m=Object.assign,h=Symbol.for(`react.element`),g=Symbol.for(`react.transitional.element`),_=Symbol.for(`react.portal`),v=Symbol.for(`react.fragment`),y=Symbol.for(`react.strict_mode`),b=Symbol.for(`react.profiler`),x=Symbol.for(`react.consumer`),S=Symbol.for(`react.context`),C=Symbol.for(`react.forward_ref`),w=Symbol.for(`react.suspense`),T=Symbol.for(`react.suspense_list`),E=Symbol.for(`react.memo`),D=Symbol.for(`react.lazy`),O=Symbol.for(`react.activity`),k=Symbol.for(`react.memo_cache_sentinel`),A=Symbol.iterator;function j(e){return typeof e!=`object`||!e?null:(e=A&&e[A]||e[`@@iterator`],typeof e==`function`?e:null)}var M=Symbol.for(`react.client.reference`);function N(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===M?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case v:return`Fragment`;case b:return`Profiler`;case y:return`StrictMode`;case w:return`Suspense`;case T:return`SuspenseList`;case O:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case _:return`Portal`;case S:return e.displayName||`Context`;case x:return(e._context.displayName||`Context`)+`.Consumer`;case C:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case E:return t=e.displayName||null,t===null?N(e.type)||`Memo`:t;case D:t=e._payload,e=e._init;try{return N(e(t))}catch{}}return null}var P=Array.isArray,F=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,I=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,L={pending:!1,data:null,method:null,action:null},R=[],z=-1;function B(e){return{current:e}}function V(e){0>z||(e.current=R[z],R[z]=null,z--)}function H(e,t){z++,R[z]=e.current,e.current=t}var U=B(null),W=B(null),ee=B(null),te=B(null);function ne(e,t){switch(H(ee,t),H(W,e),H(U,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Vd(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Vd(t),e=Hd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}V(U),H(U,e)}function re(){V(U),V(W),V(ee)}function ie(e){e.memoizedState!==null&&H(te,e);var t=U.current,n=Hd(t,e.type);t!==n&&(H(W,e),H(U,n))}function ae(e){W.current===e&&(V(U),V(W)),te.current===e&&(V(te),Qf._currentValue=L)}var oe,se;function ce(e){if(oe===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);oe=t&&t[1]||``,se=-1<e.stack.indexOf(`
|
|
3
3
|
at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
|
|
4
4
|
`+oe+e+se}var le=!1;function ue(e,t){if(!e||le)return``;le=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
|
|
@@ -30,7 +30,7 @@ Error generating stack: `+e.message+`
|
|
|
30
30
|
`).trim()}function fx(e,t=!1){if(!e.includes(sx))return{body:e,draft:null,pending:!1};let n=null,r=``,i=0;ox.lastIndex=0;let a;for(;(a=ox.exec(e))!==null;){r+=e.slice(i,a.index),i=a.index+a[0].length;let t=ux(a[1]);t&&(n=t)}r+=e.slice(i);let o=!1,s=r.indexOf(sx);if(s!==-1){let e=ux(r.slice(s+13).replace(/^[^\S\n]*\n?/,``).replace(/\s*(?:```)?\s*$/,``));e?(n=e,r=r.slice(0,s)):t&&(r=r.slice(0,s),o=!0)}return{body:dx(r),draft:n,pending:o}}var px={critical:`border-destructive/35 bg-destructive/15 text-destructive`,high:`border-accent-warning/35 bg-accent-warning/15 text-accent-warning`,medium:`border-accent-info/35 bg-accent-info/15 text-accent-info`,low:`border-border/60 bg-surface/70 text-foreground/60`},mx=X(`text-xs leading-6 text-foreground/85`,`[&_p]:my-2 [&_p:first-child]:mt-0 [&_p:last-child]:mb-0`,`[&_h2]:mt-3 [&_h2]:mb-1 [&_h2]:text-[11px] [&_h2]:font-semibold [&_h2]:uppercase [&_h2]:tracking-wider [&_h2]:text-foreground/60 [&_h2:first-child]:mt-0`,`[&_h3]:mt-2 [&_h3]:mb-1 [&_h3]:text-xs [&_h3]:font-semibold`,`[&_ul]:my-1.5 [&_ul]:list-disc [&_ul]:pl-4 [&_ol]:my-1.5 [&_ol]:list-decimal [&_ol]:pl-4 [&_li]:my-0.5`,`[&_code]:rounded [&_code]:bg-surface [&_code]:px-1 [&_code]:py-0.5 [&_code]:font-mono [&_code]:text-[0.85em] [&_code]:text-accent-info`,`[&_pre]:my-1.5 [&_pre]:overflow-x-auto [&_pre]:rounded-lg [&_pre]:bg-surface [&_pre]:p-2`,`[&_strong]:font-semibold`);function hx({draft:e}){let{t}=K(`agent`),[n,r]=(0,Q.useState)(!1),i=e.description.trim().length>0,a=e.acceptanceCriteria;return(0,$.jsxs)(`div`,{"data-testid":`agent-spec-draft-card`,className:`my-1 overflow-hidden rounded-xl border border-accent-primary/25 bg-card/80 shadow-lg backdrop-blur`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-border/40 bg-accent-primary/[0.06] px-3.5 py-2`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-widest text-accent-primary/90`,children:[(0,$.jsx)(Ln,{className:`h-3 w-3`}),t(`specDraft.heading`)]}),(0,$.jsx)(`span`,{className:X(`rounded-full border px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide`,px[e.priority]),children:t(`explore:priority.${e.priority}`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2.5 px-3.5 py-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-semibold leading-snug text-foreground`,children:e.title.trim()||t(`specDraft.untitled`)}),e.labels.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.labels.map((e,t)=>(0,$.jsx)(`span`,{className:`rounded-full border border-border/60 bg-surface/70 px-2 py-0.5 text-[10px] text-foreground/70`,children:e},`${t}-${e}`))}),i&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:X(`relative`,!n&&`max-h-28 overflow-hidden`),children:[(0,$.jsx)(`div`,{className:mx,children:(0,$.jsx)(br,{remarkPlugins:[xr],children:e.description})}),!n&&(0,$.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-x-0 bottom-0 h-10 bg-gradient-to-t from-card to-transparent`})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),"data-agent-interactive":!0,className:`mt-1 flex items-center gap-1 text-[11px] text-accent-info transition-colors hover:text-foreground`,children:[n?(0,$.jsx)(gn,{className:`h-3 w-3`}):(0,$.jsx)(Xo,{className:`h-3 w-3`}),t(n?`specDraft.collapse`:`specDraft.expand`)]})]}),a.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`mb-1 text-[10px] font-semibold uppercase tracking-wider text-foreground/50`,children:[t(`specDraft.acceptanceCriteria`),` · `,a.length]}),(0,$.jsx)(`ul`,{className:`flex flex-col gap-1`,children:a.map((e,t)=>(0,$.jsxs)(`li`,{className:`flex items-start gap-1.5 text-xs leading-5 text-foreground/85`,children:[(0,$.jsx)($o,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-success/80`}),(0,$.jsx)(`span`,{children:e})]},`${t}-${e}`))})]})]})]})}function gx(){let{t:e}=K(`agent`);return(0,$.jsxs)(`span`,{"data-testid":`agent-spec-draft-pending`,className:`inline-flex w-fit items-center gap-1.5 rounded-full border border-accent-primary/25 bg-accent-primary/10 px-2.5 py-1 text-[11px] text-accent-primary/90`,children:[(0,$.jsx)(Ln,{className:`h-3 w-3 animate-pulse`}),e(`specDraft.drafting`)]})}var _x=`pr-review-fix`,vx=4e3,yx=class extends Error{code;constructor(e,t){super(t),this.code=e,this.name=`FollowUpValidationError`}};function bx(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function xx(e,t,n,r){if(e==null)return null;if(typeof e!=`string`)throw new yx(n,`${r} must be a string`);let i=e.trim();if(!i)return null;if(i.length>t)throw new yx(n,`${r} exceeds ${t} characters`);return i}function Sx(e,t){if(e==null)return[];if(!Array.isArray(e))throw new yx(`list_too_long`,`${t} must be an array of strings`);if(e.length>20)throw new yx(`list_too_long`,`${t} has more than 20 items`);let n=[];for(let r of e){let e=xx(r,400,`item_too_long`,`${t} item`);e&&n.push(e)}return n}var Cx=/^[^\0\r\n]{1,512}$/,wx=/^[a-z0-9][a-z0-9-]{0,79}$/;function Tx(e){if(!bx(e))throw new yx(`not_object`,`followUp must be an object`);if((e.version===void 0?1:e.version)!==1)throw new yx(`unsupported_version`,`followUp.version must be 1`);if((e.kind===void 0?`pr-review-fix`:e.kind)!==`pr-review-fix`)throw new yx(`unsupported_kind`,`followUp.kind must be "${_x}"`);if(!Array.isArray(e.comments)||e.comments.length===0)throw new yx(`comments_required`,`followUp.comments must list at least one review comment`);if(e.comments.length>20)throw new yx(`too_many_comments`,`followUp.comments has more than 20 entries`);let t=new Set,n=e.comments.map((e,n)=>{if(!bx(e))throw new yx(`invalid_comment`,`followUp.comments[${n}] must be an object`);let r=xx(e.body??e.text,vx,`comment_too_long`,`followUp.comments[${n}].body`);if(!r)throw new yx(`comment_body_required`,`followUp.comments[${n}].body is required`);let i=xx(e.id,80,`invalid_comment`,`followUp.comments[${n}].id`)??`c${n+1}`;if(!/^[A-Za-z0-9_.:-]{1,80}$/.test(i))throw new yx(`invalid_comment`,`followUp.comments[${n}].id has unsupported characters`);for(;t.has(i);)i=`${i}-${n+1}`;t.add(i);let a=e.source===`github`?`github`:`user-paste`,o=xx(e.path,512,`invalid_comment`,`followUp.comments[${n}].path`);if(o&&!Cx.test(o))throw new yx(`invalid_comment`,`followUp.comments[${n}].path is not a path`);let s=e.line,c=s==null?null:typeof s==`number`&&Number.isSafeInteger(s)&&s>0?s:(()=>{throw new yx(`invalid_comment`,`followUp.comments[${n}].line must be a positive integer`)})();return{id:i,source:a,author:xx(e.author,120,`invalid_comment`,`followUp.comments[${n}].author`),path:o,line:c,body:r}}),r=bx(e.scope)?e.scope:e,i={objective:xx(r.objective,800,`objective_too_long`,`followUp.scope.objective`)??`Resolve only the selected review comments on this pull request.`,requiredOutcomes:Sx(r.requiredOutcomes,`followUp.scope.requiredOutcomes`),excludedChanges:Sx(r.excludedChanges,`followUp.scope.excludedChanges`),verification:Sx(r.verification,`followUp.scope.verification`)},a=xx(e.openspecChangeName,80,`invalid_openspec_change_name`,`followUp.openspecChangeName`);if(a&&!wx.test(a))throw new yx(`invalid_openspec_change_name`,`followUp.openspecChangeName must be a kebab-case OpenSpec change name`);return{version:1,kind:_x,comments:n,scope:i,openspecChangeName:a}}var Ex=[`implement`,`batch-implement`,`freestyle`,`loop`],Dx=/```rail-launch[^\S\n]*\n([\s\S]*?)\n[^\S\n]*```/g,Ox="```rail-launch",kx=160;function Ax(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function jx(e,t=200){if(typeof e!=`string`)return null;let n=e.trim();return n?n.slice(0,t):null}function Mx(e,t=0){if(typeof e==`number`&&Number.isInteger(e)&&e>=t)return e;if(typeof e==`string`&&/^\d+$/.test(e.trim())){let n=Number(e.trim());return n>=t?n:null}return null}function Nx(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){let e=typeof n==`number`?n:typeof n==`string`?Number(n.trim().replace(/^#/,``)):NaN;Number.isInteger(e)&&e>0&&!t.includes(e)&&t.push(e)}return t}function Px(e){let t=e.replace(/\s+/g,` `).trim();return t.length>kx?`${t.slice(0,kx-1)}…`:t}function Fx(e){if(!Ax(e))return{ok:!1,reason:`not_object`};let t=Mx(e.version,1)??Mx(e.blueprintVersion,1);if(t!==null&&t!==1)return{ok:!1,reason:`unsupported_version`};let n=Nx(e.ticketIds??e.specs??e.tickets);if(n.length===0)return{ok:!1,reason:`no_tickets`};let r=jx(e.mode)?.toLowerCase().replace(/_/g,`-`)??`implement`,i=r===`batch`?`batch-implement`:r;if(!Ex.includes(i))return{ok:!1,reason:`invalid_mode`};let a=e.newRail,o=a===!0?{name:null}:Ax(a)?{name:jx(a.name,80)}:null;return{ok:!0,proposal:{version:1,railIndex:o?null:Mx(e.railIndex,0),newRail:o,ticketIds:n,mode:i,loopId:jx(e.loopId,120),aiEngine:jx(e.aiEngine??e.provider??e.engine,80),model:jx(e.model,120),reasoningEffort:jx(e.reasoningEffort??e.reasoning_effort??e.effort,20),profileName:jx(e.profileName??e.profile,80),targetPrNumber:Mx(e.targetPrNumber,1),baseBranch:jx(e.baseBranch,200),railName:jx(e.railName??e.name,80),rationale:jx(e.rationale??e.reason??e.why,400),followUp:Ix(e.followUp)}}}function Ix(e){if(e==null)return null;try{return Tx(e)}catch{return null}}function Lx(e){return e.replace(/\n{3,}/g,`
|
|
31
31
|
|
|
32
32
|
`).trim()}function Rx(e,t=!1){let n={body:e??``,proposals:[],rejected:[],pending:!1,truncated:!1,repaired:!1};if(!e||!e.includes(Ox))return n;let r=[],i=[],a=!1,o=``,s=0;Dx.lastIndex=0;let c,l=e=>{let t=Rt(e);if(!t.ok){i.push({reason:`invalid_json`,excerpt:Px(e)});return}t.repaired&&(a=!0);let n=Fx(t.value);n.ok?r.push(n.proposal):i.push({reason:n.reason,excerpt:Px(e)})};for(;(c=Dx.exec(e))!==null;)o+=e.slice(s,c.index),s=c.index+c[0].length,l(c[1]);o+=e.slice(s);let u=!1,d=!1,f=o.indexOf(Ox);if(f!==-1){let e=o.slice(f+14).replace(/^[^\S\n]*\n?/,``).replace(/\s*(?:```)?\s*$/,``),n=e.trim()?Rt(e):null;if(n&&n.ok){n.repaired&&(a=!0);let t=Fx(n.value);t.ok?r.push(t.proposal):i.push({reason:t.reason,excerpt:Px(e)}),o=o.slice(0,f)}else t?(o=o.slice(0,f),u=!0):(o=o.slice(0,f),d=!0,i.push({reason:`invalid_json`,excerpt:Px(e)}))}return{body:Lx(o),proposals:r,rejected:i,pending:u,truncated:d,repaired:a}}var zx=new Map,Bx=new Set;function Vx(e,t){let n=new Map(zx),r=n.get(e)??[];n.set(e,[...r.filter(e=>e.proposalIndex!==t.proposalIndex),t]),zx=n;for(let e of Bx)e()}function Hx(e){return Bx.add(e),()=>{Bx.delete(e)}}function Ux(){return(0,Q.useSyncExternalStore)(Hx,()=>zx,()=>zx)}function Wx(e,t,n,r){return e.get(t)?.find(e=>e.proposalIndex===r)??n?.find(e=>e.proposalIndex===r)??null}var Gx={claude:[{value:`sonnet`,label:`Claude Sonnet`},{value:`fable`,label:`Claude Fable`},{value:`opus`,label:`Claude Opus`},{value:`haiku`,label:`Claude Haiku`}],codex:[{value:`gpt-5.5`,label:`GPT-5.5`},{value:`gpt-6-astra`,label:`GPT-6 Astra`},{value:`gpt-5.6-sol`,label:`GPT-5.6 Sol`},{value:`gpt-5.6-terra`,label:`GPT-5.6 Terra`},{value:`gpt-5.6-luna`,label:`GPT-5.6 Luna`},{value:`gpt-5.4`,label:`GPT-5.4`},{value:`gpt-5.4-mini`,label:`GPT-5.4 Mini`},{value:`gpt-5.3-codex`,label:`GPT-5.3 Codex`}],gemini:[{value:`gemini-3.5-flash`,label:`Gemini 3.5 Flash`},{value:`gemini-3.1-pro-preview`,label:`Gemini 3.1 Pro (preview)`},{value:`gemini-3.1-flash-lite`,label:`Gemini 3.1 Flash Lite`},{value:`gemini-2.5-flash-lite`,label:`Gemini 2.5 Flash Lite`}],kimi:[{value:`k3`,label:`Kimi K3`},{value:`kimi-for-coding`,label:`Kimi for Coding`},{value:`kimi-for-coding-highspeed`,label:`Kimi for Coding Highspeed`}]},Kx=new Map;function qx(e,t){if(!e)return;let n=Array.from(new Set(t.filter(e=>typeof e==`string`&&e.trim())));if(n.length===0){Kx.delete(e);return}Kx.set(e,n.map(e=>({value:e,label:e})))}function Jx(e){return e?Gx[e]??Kx.get(e)??[]:[]}function Yx(e){return Jx(e)[0]?.value??``}function Xx(e){for(let[t,n]of Object.entries(e))n?.kind===`local`&&Array.isArray(n.models)&&qx(t,n.models)}function Zx(){let[e,t]=(0,Q.useState)({detected:[],providers:{},loading:!0}),n=(0,Q.useContext)(rt);return(0,Q.useEffect)(()=>{let e=!0;return fetch(`${Xe}/api/providers/detected`).then(e=>e.ok?e.json():null).then(n=>{!e||!n||(Xx(n.providers??{}),t({detected:Array.isArray(n.detected)?n.detected:[],providers:n.providers??{},loading:!1}))}).catch(()=>{e&&t(e=>({...e,loading:!1}))}),()=>{e=!1}},[]),(0,Q.useEffect)(()=>{let e=e=>{let n=e;n.type===`providers.detected_changed`&&(Xx(n.providers??{}),window.dispatchEvent(new Event(`specrails:providers-detected-changed`)),t({detected:Array.isArray(n.detected)?n.detected:[],providers:n.providers??{},loading:!1}))};if(n)return n.registerHandler(`provider-detection`,e),()=>n.unregisterHandler(`provider-detection`)},[n]),e}var Qx={implement:`factory:implement`,"batch-implement":`factory:batch`,freestyle:`factory:freestyle`},$x=[{id:`factory:implement`,labelKey:`railControls.implement`},{id:`factory:batch`,labelKey:`railControls.batch`},{id:`factory:freestyle`,labelKey:`railControls.freestyle`,requiresFreestyle:!0},{id:`factory:sdd-quick-openspec`,labelKey:`railControls.openspec`,requiresLoops:!0}];function eS(e){return e===`loop`?``:Qx[e]}function tS(e){return e===`factory:implement`?`implement`:e===`factory:batch`?`batch-implement`:e===`factory:freestyle`?`freestyle`:`loop`}function nS(e,t){return e||eS(t)}var rS=class extends Error{errors;constructor(e){super(`Loop graph is invalid`),this.name=`LoopPublishError`,this.errors=e}},iS=`/api`;async function aS(e){if(!e.ok){let t;try{t=await e.json()}catch{t=void 0}if(e.status===422&&t&&typeof t==`object`&&`errors`in t)throw new rS(t.errors??[]);let n=t&&typeof t==`object`&&`error`in t?String(t.error):`Request failed (${e.status})`;throw Error(n)}return e.json()}async function oS(e,t,n){return aS(await fetch(`${iS}${t}`,{method:e,headers:n===void 0?void 0:{"Content-Type":`application/json`},body:n===void 0?void 0:JSON.stringify(n)}))}var sS={async list(){return(await oS(`GET`,`/loops`)).loops},async get(e){return(await oS(`GET`,`/loops/${e}`)).loop},async create(e){return(await oS(`POST`,`/loops`,e)).loop},async update(e,t){return(await oS(`PUT`,`/loops/${e}`,t)).loop},async publish(e){return(await oS(`POST`,`/loops/${e}/publish`)).loop},async unpublish(e){return(await oS(`POST`,`/loops/${e}/unpublish`)).loop},async duplicate(e,t){return(await oS(`POST`,`/loops/${e}/duplicate`,t?{name:t}:{})).loop},async remove(e){let t=await fetch(`${iS}/loops/${e}`,{method:`DELETE`});!t.ok&&t.status!==204&&await aS(t)},async templates(){return(await oS(`GET`,`/loop-templates`)).templates},async fromTemplate(e,t){return(await oS(`POST`,`/loops/from-template/${e}`,t?{name:t}:{})).loop},async factoryLoops(){return(await oS(`GET`,`/loops/factory`)).factoryLoops},async loopCommands(){return(await oS(`GET`,`/loops/commands`)).commands},async forkFactory(e,t){return(await oS(`POST`,`/loops/factory/${e}/fork`,t?{name:t}:{})).loop},async loopConstants(){return(await oS(`GET`,`/loops/constants`)).constants},async createConstant(e,t){return(await oS(`POST`,`/loops/constants`,{name:e,value:t})).constant},async updateConstant(e,t){return(await oS(`PUT`,`/loops/constants/${e}`,{value:t})).constant},async deleteConstant(e){await oS(`DELETE`,`/loops/constants/${e}`)},async importLoops(e){return oS(`POST`,`/loops/import`,{loops:e})},async previewLoop(e,t){return oS(`POST`,`/loops/preview`,{graph:e,provider:t})},async runStandalone(e,t,n={}){return aS(await fetch(`/api/projects/${e}/loop-runs`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({loopId:t,...n})}))}},cS=/\{\{\s*spec\./,lS=/\{\{\s*cmd:(implement|batch|freestyle)\b/;function uS(e){if(!e)return!1;for(let t of e.nodes){let e=[t.data?.prompt,t.data?.command,t.data?.goal].filter(e=>typeof e==`string`).join(`
|
|
33
|
-
`);if(cS.test(e)||lS.test(e))return!0}return!1}function dS(e,[t,n]){return Math.min(n,Math.max(t,e))}function fS(e){let t=pS(e),n=Q.forwardRef((e,n)=>{let{children:r,...i}=e,a=Q.Children.toArray(r),o=a.find(hS);if(o){let e=o.props.children,r=a.map(t=>t===o?Q.Children.count(e)>1?Q.Children.only(null):Q.isValidElement(e)?e.props.children:null:t);return(0,$.jsx)(t,{...i,ref:n,children:Q.isValidElement(e)?Q.cloneElement(e,void 0,r):null})}return(0,$.jsx)(t,{...i,ref:n,children:r})});return n.displayName=`${e}.Slot`,n}function pS(e){let t=Q.forwardRef((e,t)=>{let{children:n,...r}=e;if(Q.isValidElement(n)){let e=_S(n),i=gS(r,n.props);return n.type!==Q.Fragment&&(i.ref=t?or(t,e):e),Q.cloneElement(n,i)}return Q.Children.count(n)>1?Q.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var mS=Symbol(`radix.slottable`);function hS(e){return Q.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===mS}function gS(e,t){let n={...t};for(let r in t){let i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...e)=>{let t=a(...e);return i(...e),t}:i&&(n[r]=i):r===`style`?n[r]={...i,...a}:r===`className`&&(n[r]=[i,a].filter(Boolean).join(` `))}return{...e,...n}}function _S(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}function vS(e){let t=e+`CollectionProvider`,[n,r]=Wn(t),[i,a]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=e=>{let{scope:t,children:n}=e,r=Q.useRef(null),a=Q.useRef(new Map).current;return(0,$.jsx)(i,{scope:t,itemMap:a,collectionRef:r,children:n})};o.displayName=t;let s=e+`CollectionSlot`,c=fS(s),l=Q.forwardRef((e,t)=>{let{scope:n,children:r}=e,i=Hn(t,a(s,n).collectionRef);return(0,$.jsx)(c,{ref:i,children:r})});l.displayName=s;let u=e+`CollectionItemSlot`,d=`data-radix-collection-item`,f=fS(u),p=Q.forwardRef((e,t)=>{let{scope:n,children:r,...i}=e,o=Q.useRef(null),s=Hn(t,o),c=a(u,n);return Q.useEffect(()=>(c.itemMap.set(o,{ref:o,...i}),()=>void c.itemMap.delete(o))),(0,$.jsx)(f,{[d]:``,ref:s,children:r})});p.displayName=u;function m(t){let n=a(e+`CollectionConsumer`,t);return Q.useCallback(()=>{let e=n.collectionRef.current;if(!e)return[];let t=Array.from(e.querySelectorAll(`[${d}]`));return Array.from(n.itemMap.values()).sort((e,n)=>t.indexOf(e.ref.current)-t.indexOf(n.ref.current))},[n.collectionRef,n.itemMap])}return[{Provider:o,Slot:l,ItemSlot:p},m,r]}var yS=Q.createContext(void 0);function bS(e){let t=Q.useContext(yS);return e||t||`ltr`}var xS=[`top`,`right`,`bottom`,`left`],SS=Math.min,CS=Math.max,wS=Math.round,TS=Math.floor,ES=e=>({x:e,y:e}),DS={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function OS(e,t,n){return CS(e,SS(t,n))}function kS(e,t){return typeof e==`function`?e(t):e}function AS(e){return e.split(`-`)[0]}function jS(e){return e.split(`-`)[1]}function MS(e){return e===`x`?`y`:`x`}function NS(e){return e===`y`?`height`:`width`}function PS(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function FS(e){return MS(PS(e))}function IS(e,t,n){n===void 0&&(n=!1);let r=jS(e),i=FS(e),a=NS(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=GS(o)),[o,GS(o)]}function LS(e){let t=GS(e);return[RS(e),t,RS(t)]}function RS(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var zS=[`left`,`right`],BS=[`right`,`left`],VS=[`top`,`bottom`],HS=[`bottom`,`top`];function US(e,t,n){switch(e){case`top`:case`bottom`:return n?t?BS:zS:t?zS:BS;case`left`:case`right`:return t?VS:HS;default:return[]}}function WS(e,t,n,r){let i=jS(e),a=US(AS(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(RS)))),a}function GS(e){let t=AS(e);return DS[t]+e.slice(t.length)}function KS(e){return{top:0,right:0,bottom:0,left:0,...e}}function qS(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:KS(e)}function JS(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function YS(e,t,n){let{reference:r,floating:i}=e,a=PS(t),o=FS(t),s=NS(o),c=AS(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}switch(jS(t)){case`start`:p[o]-=f*(n&&l?-1:1);break;case`end`:p[o]+=f*(n&&l?-1:1);break}return p}async function XS(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=kS(t,e),p=qS(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=JS(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=JS(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var ZS=50,QS=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:XS},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=YS(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<ZS&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=YS(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},$S=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=kS(e,t)||{};if(l==null)return{};let d=qS(u),f={x:n,y:r},p=FS(i),m=NS(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l)),C=S?S[y]:0;(!C||!await(o.isElement==null?void 0:o.isElement(S)))&&(C=s.floating[y]||a.floating[m]);let w=b/2-x/2,T=C/2-h[m]/2-1,E=SS(d[_],T),D=SS(d[v],T),O=E,k=C-h[m]-D,A=C/2-h[m]/2+w,j=OS(O,A,k),M=!c.arrow&&jS(i)!=null&&A!==j&&a.reference[m]/2-(A<O?E:D)-h[m]/2<0,N=M?A<O?A-O:A-k:0;return{[p]:f[p]+N,data:{[p]:j,centerOffset:A-j-N,...M&&{alignmentOffset:N}},reset:M}}}),eC=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=kS(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=AS(r),_=PS(o),v=AS(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[GS(o)]:LS(o)),x=p!==`none`;!d&&x&&b.push(...WS(o,m,p,y));let S=[o,...b],C=await s.detectOverflow(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=IS(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(!(u===`alignment`&&_!==PS(t))||T.every(e=>PS(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=PS(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o;break}if(r!==n)return{reset:{placement:n}}}return{}}}};function tC(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function nC(e){return xS.some(t=>e[t]>=0)}var rC=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=kS(e,t);switch(i){case`referenceHidden`:{let e=tC(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:nC(e)}}}case`escaped`:{let e=tC(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:nC(e)}}}default:return{}}}}},iC=new Set([`left`,`top`]);async function aC(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=AS(n),s=jS(n),c=PS(n)===`y`,l=iC.has(o)?-1:1,u=a&&c?-1:1,d=kS(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var oC=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await aC(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},sC=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=kS(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=PS(AS(i)),p=MS(f),m=u[p],h=u[f];if(o){let e=p===`y`?`top`:`left`,t=p===`y`?`bottom`:`right`,n=m+d[e],r=m-d[t];m=OS(n,m,r)}if(s){let e=f===`y`?`top`:`left`,t=f===`y`?`bottom`:`right`,n=h+d[e],r=h-d[t];h=OS(n,h,r)}let g=c.fn({...t,[p]:m,[f]:h});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[p]:o,[f]:s}}}}}},cC=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=kS(e,t),u={x:n,y:r},d=PS(i),f=MS(d),p=u[f],m=u[d],h=kS(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:0,crossAxis:0,...h};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=iC.has(AS(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},lC=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){var n,r;let{placement:i,rects:a,platform:o,elements:s}=t,{apply:c=()=>{},...l}=kS(e,t),u=await o.detectOverflow(t,l),d=AS(i),f=jS(i),p=PS(i)===`y`,{width:m,height:h}=a.floating,g,_;d===`top`||d===`bottom`?(g=d,_=f===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?`start`:`end`)?`left`:`right`):(_=d,g=f===`end`?`top`:`bottom`);let v=h-u.top-u.bottom,y=m-u.left-u.right,b=SS(h-u[g],v),x=SS(m-u[_],y),S=!t.middlewareData.shift,C=b,w=x;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(w=y),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(C=v),S&&!f){let e=CS(u.left,0),t=CS(u.right,0),n=CS(u.top,0),r=CS(u.bottom,0);p?w=m-2*(e!==0||t!==0?e+t:CS(u.left,u.right)):C=h-2*(n!==0||r!==0?n+r:CS(u.top,u.bottom))}await c({...t,availableWidth:w,availableHeight:C});let T=await o.getDimensions(s.floating);return m!==T.width||h!==T.height?{reset:{rects:!0}}:{}}}};function uC(){return typeof window<`u`}function dC(e){return mC(e)?(e.nodeName||``).toLowerCase():`#document`}function fC(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function pC(e){return((mC(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function mC(e){return uC()?e instanceof Node||e instanceof fC(e).Node:!1}function hC(e){return uC()?e instanceof Element||e instanceof fC(e).Element:!1}function gC(e){return uC()?e instanceof HTMLElement||e instanceof fC(e).HTMLElement:!1}function _C(e){return!uC()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof fC(e).ShadowRoot}function vC(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=kC(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function yC(e){return/^(table|td|th)$/.test(dC(e))}function bC(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var xC=/transform|translate|scale|rotate|perspective|filter/,SC=/paint|layout|strict|content/,CC=e=>!!e&&e!==`none`,wC;function TC(e){let t=hC(e)?kC(e):e;return CC(t.transform)||CC(t.translate)||CC(t.scale)||CC(t.rotate)||CC(t.perspective)||!DC()&&(CC(t.backdropFilter)||CC(t.filter))||xC.test(t.willChange||``)||SC.test(t.contain||``)}function EC(e){let t=jC(e);for(;gC(t)&&!OC(t);){if(TC(t))return t;if(bC(t))return null;t=jC(t)}return null}function DC(){return wC??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),wC}function OC(e){return/^(html|body|#document)$/.test(dC(e))}function kC(e){return fC(e).getComputedStyle(e)}function AC(e){return hC(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function jC(e){if(dC(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||_C(e)&&e.host||pC(e);return _C(t)?t.host:t}function MC(e){let t=jC(e);return OC(t)?e.ownerDocument?e.ownerDocument.body:e.body:gC(t)&&vC(t)?t:MC(t)}function NC(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=MC(e),i=r===e.ownerDocument?.body,a=fC(r);if(i){let e=PC(a);return t.concat(a,a.visualViewport||[],vC(r)?r:[],e&&n?NC(e):[])}else return t.concat(r,NC(r,[],n))}function PC(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function FC(e){let t=kC(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=gC(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=wS(n)!==a||wS(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function IC(e){return hC(e)?e:e.contextElement}function LC(e){let t=IC(e);if(!gC(t))return ES(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=FC(t),o=(a?wS(n.width):n.width)/r,s=(a?wS(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var RC=ES(0);function zC(e){let t=fC(e);return!DC()||!t.visualViewport?RC:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function BC(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==fC(e)?!1:t}function VC(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=IC(e),o=ES(1);t&&(r?hC(r)&&(o=LC(r)):o=LC(e));let s=BC(a,n,r)?zC(a):ES(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a){let e=fC(a),t=r&&hC(r)?fC(r):r,n=e,i=PC(n);for(;i&&r&&t!==n;){let e=LC(i),t=i.getBoundingClientRect(),r=kC(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=fC(i),i=PC(n)}}return JS({width:u,height:d,x:c,y:l})}function HC(e,t){let n=AC(e).scrollLeft;return t?t.left+n:VC(pC(e)).left+n}function UC(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-HC(e,n),y:n.top+t.scrollTop}}function WC(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=pC(r),s=t?bC(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=ES(1),u=ES(0),d=gC(r);if((d||!d&&!a)&&((dC(r)!==`body`||vC(o))&&(c=AC(r)),d)){let e=VC(r);l=LC(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?UC(o,c):ES(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function GC(e){return Array.from(e.getClientRects())}function KC(e){let t=pC(e),n=AC(e),r=e.ownerDocument.body,i=CS(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=CS(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+HC(e),s=-n.scrollTop;return kC(r).direction===`rtl`&&(o+=CS(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}var qC=25;function JC(e,t){let n=fC(e),r=pC(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=DC();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=HC(r);if(l<=0){let e=r.ownerDocument,t=e.body,n=getComputedStyle(t),i=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,o=Math.abs(r.clientWidth-t.clientWidth-i);o<=qC&&(a-=o)}else l<=qC&&(a+=l);return{width:a,height:o,x:s,y:c}}function YC(e,t){let n=VC(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=gC(e)?LC(e):ES(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function XC(e,t,n){let r;if(t===`viewport`)r=JC(e,n);else if(t===`document`)r=KC(pC(e));else if(hC(t))r=YC(t,n);else{let n=zC(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return JS(r)}function ZC(e,t){let n=jC(e);return n===t||!hC(n)||OC(n)?!1:kC(n).position===`fixed`||ZC(n,t)}function QC(e,t){let n=t.get(e);if(n)return n;let r=NC(e,[],!1).filter(e=>hC(e)&&dC(e)!==`body`),i=null,a=kC(e).position===`fixed`,o=a?jC(e):e;for(;hC(o)&&!OC(o);){let t=kC(o),n=TC(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&(i.position===`absolute`||i.position===`fixed`)||vC(o)&&!n&&ZC(e,o))?r=r.filter(e=>e!==o):i=t,o=jC(o)}return t.set(e,r),r}function $C(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?bC(t)?[]:QC(t,this._c):[].concat(n),r],o=XC(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e<a.length;e++){let n=XC(t,a[e],i);s=CS(n.top,s),c=SS(n.right,c),l=SS(n.bottom,l),u=CS(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function ew(e){let{width:t,height:n}=FC(e);return{width:t,height:n}}function tw(e,t,n){let r=gC(t),i=pC(t),a=n===`fixed`,o=VC(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=ES(0);function l(){c.x=HC(i)}if(r||!r&&!a)if((dC(t)!==`body`||vC(i))&&(s=AC(t)),r){let e=VC(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else i&&l();a&&!r&&i&&l();let u=i&&!r&&!a?UC(i,s):ES(0);return{x:o.left+s.scrollLeft-c.x-u.x,y:o.top+s.scrollTop-c.y-u.y,width:o.width,height:o.height}}function nw(e){return kC(e).position===`static`}function rw(e,t){if(!gC(e)||kC(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return pC(e)===n&&(n=n.ownerDocument.body),n}function iw(e,t){let n=fC(e);if(bC(e))return n;if(!gC(e)){let t=jC(e);for(;t&&!OC(t);){if(hC(t)&&!nw(t))return t;t=jC(t)}return n}let r=rw(e,t);for(;r&&yC(r)&&nw(r);)r=rw(r,t);return r&&OC(r)&&nw(r)&&!TC(r)?n:r||EC(e)||n}var aw=async function(e){let t=this.getOffsetParent||iw,n=this.getDimensions,r=await n(e.floating);return{reference:tw(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function ow(e){return kC(e).direction===`rtl`}var sw={convertOffsetParentRelativeRectToViewportRelativeRect:WC,getDocumentElement:pC,getClippingRect:$C,getOffsetParent:iw,getElementRects:aw,getClientRects:GC,getDimensions:ew,getScale:LC,isElement:hC,isRTL:ow};function cw(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function lw(e,t){let n=null,r,i=pC(e);function a(){var e;clearTimeout(r),(e=n)==null||e.disconnect(),n=null}function o(s,c){s===void 0&&(s=!1),c===void 0&&(c=1),a();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(s||t(),!f||!p)return;let m=TS(d),h=TS(i.clientWidth-(u+f)),g=TS(i.clientHeight-(d+p)),_=TS(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:CS(0,SS(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(n!==c){if(!y)return o();n?o(!1,n):r=setTimeout(()=>{o(!1,1e-7)},1e3)}n===1&&!cw(l,e.getBoundingClientRect())&&o(),y=!1}try{n=new IntersectionObserver(b,{...v,root:i.ownerDocument})}catch{n=new IntersectionObserver(b,v)}n.observe(e)}return o(!0),a}function uw(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=IC(e),u=i||a?[...l?NC(l):[],...t?NC(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?lw(l,n):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?VC(e):null;c&&g();function g(){let t=VC(e);h&&!cw(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var dw=oC,fw=sC,pw=eC,mw=lC,hw=rC,gw=$S,_w=cC,vw=(e,t,n)=>{let r=new Map,i={platform:sw,...n},a={...i.platform,_c:r};return QS(e,t,{...i,platform:a})},yw=typeof document<`u`?Q.useLayoutEffect:function(){};function bw(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!bw(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!bw(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function xw(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Sw(e,t){let n=xw(e);return Math.round(t*n)/n}function Cw(e){let t=Q.useRef(e);return yw(()=>{t.current=e}),t}function ww(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=Q.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=Q.useState(r);bw(f,r)||p(r);let[m,h]=Q.useState(null),[g,_]=Q.useState(null),v=Q.useCallback(e=>{e!==S.current&&(S.current=e,h(e))},[]),y=Q.useCallback(e=>{e!==C.current&&(C.current=e,_(e))},[]),b=a||m,x=o||g,S=Q.useRef(null),C=Q.useRef(null),w=Q.useRef(u),T=c!=null,E=Cw(c),D=Cw(i),O=Cw(l),k=Q.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};D.current&&(e.platform=D.current),vw(S.current,C.current,e).then(e=>{let t={...e,isPositioned:O.current!==!1};A.current&&!bw(w.current,t)&&(w.current=t,Hb.flushSync(()=>{d(t)}))})},[f,t,n,D,O]);yw(()=>{l===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let A=Q.useRef(!1);yw(()=>(A.current=!0,()=>{A.current=!1}),[]),yw(()=>{if(b&&(S.current=b),x&&(C.current=x),b&&x){if(E.current)return E.current(b,x,k);k()}},[b,x,k,E,T]);let j=Q.useMemo(()=>({reference:S,floating:C,setReference:v,setFloating:y}),[v,y]),M=Q.useMemo(()=>({reference:b,floating:x}),[b,x]),N=Q.useMemo(()=>{let e={position:n,left:0,top:0};if(!M.floating)return e;let t=Sw(M.floating,u.x),r=Sw(M.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...xw(M.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,M.floating,u.x,u.y]);return Q.useMemo(()=>({...u,update:k,refs:j,elements:M,floatingStyles:N}),[u,k,j,M,N])}var Tw=e=>{function t(e){return{}.hasOwnProperty.call(e,`current`)}return{name:`arrow`,options:e,fn(n){let{element:r,padding:i}=typeof e==`function`?e(n):e;return r&&t(r)?r.current==null?{}:gw({element:r.current,padding:i}).fn(n):r?gw({element:r,padding:i}).fn(n):{}}}},Ew=(e,t)=>{let n=dw(e);return{name:n.name,fn:n.fn,options:[e,t]}},Dw=(e,t)=>{let n=fw(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ow=(e,t)=>({fn:_w(e).fn,options:[e,t]}),kw=(e,t)=>{let n=pw(e);return{name:n.name,fn:n.fn,options:[e,t]}},Aw=(e,t)=>{let n=mw(e);return{name:n.name,fn:n.fn,options:[e,t]}},jw=(e,t)=>{let n=hw(e);return{name:n.name,fn:n.fn,options:[e,t]}},Mw=(e,t)=>{let n=Tw(e);return{name:n.name,fn:n.fn,options:[e,t]}},Nw=`Arrow`,Pw=Q.forwardRef((e,t)=>{let{children:n,width:r=10,height:i=5,...a}=e;return(0,$.jsx)(Un.svg,{...a,ref:t,width:r,height:i,viewBox:`0 0 30 10`,preserveAspectRatio:`none`,children:e.asChild?n:(0,$.jsx)(`polygon`,{points:`0,0 30,0 15,10`})})});Pw.displayName=Nw;var Fw=Pw;function Iw(e){let[t,n]=Q.useState(void 0);return Gn(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});let t=new ResizeObserver(t=>{if(!Array.isArray(t)||!t.length)return;let r=t[0],i,a;if(`borderBoxSize`in r){let e=r.borderBoxSize,t=Array.isArray(e)?e[0]:e;i=t.inlineSize,a=t.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return t.observe(e,{box:`border-box`}),()=>t.unobserve(e)}else n(void 0)},[e]),t}var Lw=`Popper`,[Rw,zw]=Wn(Lw),[Bw,Vw]=Rw(Lw),Hw=e=>{let{__scopePopper:t,children:n}=e,[r,i]=Q.useState(null);return(0,$.jsx)(Bw,{scope:t,anchor:r,onAnchorChange:i,children:n})};Hw.displayName=Lw;var Uw=`PopperAnchor`,Ww=Q.forwardRef((e,t)=>{let{__scopePopper:n,virtualRef:r,...i}=e,a=Vw(Uw,n),o=Q.useRef(null),s=Hn(t,o),c=Q.useRef(null);return Q.useEffect(()=>{let e=c.current;c.current=r?.current||o.current,e!==c.current&&a.onAnchorChange(c.current)}),r?null:(0,$.jsx)(Un.div,{...i,ref:s})});Ww.displayName=Uw;var Gw=`PopperContent`,[Kw,qw]=Rw(Gw),Jw=Q.forwardRef((e,t)=>{let{__scopePopper:n,side:r=`bottom`,sideOffset:i=0,align:a=`center`,alignOffset:o=0,arrowPadding:s=0,avoidCollisions:c=!0,collisionBoundary:l=[],collisionPadding:u=0,sticky:d=`partial`,hideWhenDetached:f=!1,updatePositionStrategy:p=`optimized`,onPlaced:m,...h}=e,g=Vw(Gw,n),[_,v]=Q.useState(null),y=Hn(t,e=>v(e)),[b,x]=Q.useState(null),S=Iw(b),C=S?.width??0,w=S?.height??0,T=r+(a===`center`?``:`-`+a),E=typeof u==`number`?u:{top:0,right:0,bottom:0,left:0,...u},D=Array.isArray(l)?l:[l],O=D.length>0,k={padding:E,boundary:D.filter(Qw),altBoundary:O},{refs:A,floatingStyles:j,placement:M,isPositioned:N,middlewareData:P}=ww({strategy:`fixed`,placement:T,whileElementsMounted:(...e)=>uw(...e,{animationFrame:p===`always`}),elements:{reference:g.anchor},middleware:[Ew({mainAxis:i+w,alignmentAxis:o}),c&&Dw({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?Ow():void 0,...k}),c&&kw({...k}),Aw({...k,apply:({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:a}=t.reference,o=e.floating.style;o.setProperty(`--radix-popper-available-width`,`${n}px`),o.setProperty(`--radix-popper-available-height`,`${r}px`),o.setProperty(`--radix-popper-anchor-width`,`${i}px`),o.setProperty(`--radix-popper-anchor-height`,`${a}px`)}}),b&&Mw({element:b,padding:s}),$w({arrowWidth:C,arrowHeight:w}),f&&jw({strategy:`referenceHidden`,...k})]}),[F,I]=eT(M),L=Jn(m);Gn(()=>{N&&L?.()},[N,L]);let R=P.arrow?.x,z=P.arrow?.y,B=P.arrow?.centerOffset!==0,[V,H]=Q.useState();return Gn(()=>{_&&H(window.getComputedStyle(_).zIndex)},[_]),(0,$.jsx)(`div`,{ref:A.setFloating,"data-radix-popper-content-wrapper":``,style:{...j,transform:N?j.transform:`translate(0, -200%)`,minWidth:`max-content`,zIndex:V,"--radix-popper-transform-origin":[P.transformOrigin?.x,P.transformOrigin?.y].join(` `),...P.hide?.referenceHidden&&{visibility:`hidden`,pointerEvents:`none`}},dir:e.dir,children:(0,$.jsx)(Kw,{scope:n,placedSide:F,onArrowChange:x,arrowX:R,arrowY:z,shouldHideArrow:B,children:(0,$.jsx)(Un.div,{"data-side":F,"data-align":I,...h,ref:y,style:{...h.style,animation:N?void 0:`none`}})})})});Jw.displayName=Gw;var Yw=`PopperArrow`,Xw={top:`bottom`,right:`left`,bottom:`top`,left:`right`},Zw=Q.forwardRef(function(e,t){let{__scopePopper:n,...r}=e,i=qw(Yw,n),a=Xw[i.placedSide];return(0,$.jsx)(`span`,{ref:i.onArrowChange,style:{position:`absolute`,left:i.arrowX,top:i.arrowY,[a]:0,transformOrigin:{top:``,right:`0 0`,bottom:`center 0`,left:`100% 0`}[i.placedSide],transform:{top:`translateY(100%)`,right:`translateY(50%) rotate(90deg) translateX(-50%)`,bottom:`rotate(180deg)`,left:`translateY(50%) rotate(-90deg) translateX(50%)`}[i.placedSide],visibility:i.shouldHideArrow?`hidden`:void 0},children:(0,$.jsx)(Fw,{...r,ref:t,style:{...r.style,display:`block`}})})});Zw.displayName=Yw;function Qw(e){return e!==null}var $w=e=>({name:`transformOrigin`,options:e,fn(t){let{placement:n,rects:r,middlewareData:i}=t,a=i.arrow?.centerOffset!==0,o=a?0:e.arrowWidth,s=a?0:e.arrowHeight,[c,l]=eT(n),u={start:`0%`,center:`50%`,end:`100%`}[l],d=(i.arrow?.x??0)+o/2,f=(i.arrow?.y??0)+s/2,p=``,m=``;return c===`bottom`?(p=a?u:`${d}px`,m=`${-s}px`):c===`top`?(p=a?u:`${d}px`,m=`${r.floating.height+s}px`):c===`right`?(p=`${-s}px`,m=a?u:`${f}px`):c===`left`&&(p=`${r.floating.width+s}px`,m=a?u:`${f}px`),{data:{x:p,y:m}}}});function eT(e){let[t,n=`center`]=e.split(`-`);return[t,n]}var tT=Hw,nT=Ww,rT=Jw,iT=Zw;function aT(e){let t=oT(e),n=Q.forwardRef((e,n)=>{let{children:r,...i}=e,a=Q.Children.toArray(r),o=a.find(cT);if(o){let e=o.props.children,r=a.map(t=>t===o?Q.Children.count(e)>1?Q.Children.only(null):Q.isValidElement(e)?e.props.children:null:t);return(0,$.jsx)(t,{...i,ref:n,children:Q.isValidElement(e)?Q.cloneElement(e,void 0,r):null})}return(0,$.jsx)(t,{...i,ref:n,children:r})});return n.displayName=`${e}.Slot`,n}function oT(e){let t=Q.forwardRef((e,t)=>{let{children:n,...r}=e;if(Q.isValidElement(n)){let e=uT(n),i=lT(r,n.props);return n.type!==Q.Fragment&&(i.ref=t?or(t,e):e),Q.cloneElement(n,i)}return Q.Children.count(n)>1?Q.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var sT=Symbol(`radix.slottable`);function cT(e){return Q.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===sT}function lT(e,t){let n={...t};for(let r in t){let i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...e)=>{let t=a(...e);return i(...e),t}:i&&(n[r]=i):r===`style`?n[r]={...i,...a}:r===`className`&&(n[r]=[i,a].filter(Boolean).join(` `))}return{...e,...n}}function uT(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}function dT(e){let t=Q.useRef({value:e,previous:e});return Q.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var fT=Object.freeze({position:`absolute`,border:0,width:1,height:1,padding:0,margin:-1,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,wordWrap:`normal`}),pT=`VisuallyHidden`,mT=Q.forwardRef((e,t)=>(0,$.jsx)(Un.span,{...e,ref:t,style:{...fT,...e.style}}));mT.displayName=pT;var hT=mT,gT=[` `,`Enter`,`ArrowUp`,`ArrowDown`],_T=[` `,`Enter`],vT=`Select`,[yT,bT,xT]=vS(vT),[ST,CT]=Wn(vT,[xT,zw]),wT=zw(),[TT,ET]=ST(vT),[DT,OT]=ST(vT),kT=e=>{let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:a,value:o,defaultValue:s,onValueChange:c,dir:l,name:u,autoComplete:d,disabled:f,required:p,form:m}=e,h=wT(t),[g,_]=Q.useState(null),[v,y]=Q.useState(null),[b,x]=Q.useState(!1),S=bS(l),[C,w]=_r({prop:r,defaultProp:i??!1,onChange:a,caller:vT}),[T,E]=_r({prop:o,defaultProp:s,onChange:c,caller:vT}),D=Q.useRef(null),O=!g||m||!!g.closest(`form`),[k,A]=Q.useState(new Set),j=Array.from(k).map(e=>e.props.value).join(`;`);return(0,$.jsx)(tT,{...h,children:(0,$.jsxs)(TT,{required:p,scope:t,trigger:g,onTriggerChange:_,valueNode:v,onValueNodeChange:y,valueNodeHasChildren:b,onValueNodeHasChildrenChange:x,contentId:Yn(),value:T,onValueChange:E,open:C,onOpenChange:w,dir:S,triggerPointerDownPosRef:D,disabled:f,children:[(0,$.jsx)(yT.Provider,{scope:t,children:(0,$.jsx)(DT,{scope:e.__scopeSelect,onNativeOptionAdd:Q.useCallback(e=>{A(t=>new Set(t).add(e))},[]),onNativeOptionRemove:Q.useCallback(e=>{A(t=>{let n=new Set(t);return n.delete(e),n})},[]),children:n})}),O?(0,$.jsxs)(wE,{"aria-hidden":!0,required:p,tabIndex:-1,name:u,autoComplete:d,value:T,onChange:e=>E(e.target.value),disabled:f,form:m,children:[T===void 0?(0,$.jsx)(`option`,{value:``}):null,Array.from(k)]},j):null]})})};kT.displayName=vT;var AT=`SelectTrigger`,jT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,disabled:r=!1,...i}=e,a=wT(n),o=ET(AT,n),s=o.disabled||r,c=Hn(t,o.onTriggerChange),l=bT(n),u=Q.useRef(`touch`),[d,f,p]=EE(e=>{let t=l().filter(e=>!e.disabled),n=DE(t,e,t.find(e=>e.value===o.value));n!==void 0&&o.onValueChange(n.value)}),m=e=>{s||(o.onOpenChange(!0),p()),e&&(o.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})};return(0,$.jsx)(nT,{asChild:!0,...a,children:(0,$.jsx)(Un.button,{type:`button`,role:`combobox`,"aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":`none`,dir:o.dir,"data-state":o.open?`open`:`closed`,disabled:s,"data-disabled":s?``:void 0,"data-placeholder":TE(o.value)?``:void 0,...i,ref:c,onClick:qn(i.onClick,e=>{e.currentTarget.focus(),u.current!==`mouse`&&m(e)}),onPointerDown:qn(i.onPointerDown,e=>{u.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(m(e),e.preventDefault())}),onKeyDown:qn(i.onKeyDown,e=>{let t=d.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&f(e.key),!(t&&e.key===` `)&&gT.includes(e.key)&&(m(),e.preventDefault())})})})});jT.displayName=AT;var MT=`SelectValue`,NT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,children:a,placeholder:o=``,...s}=e,c=ET(MT,n),{onValueNodeHasChildrenChange:l}=c,u=a!==void 0,d=Hn(t,c.onValueNodeChange);return Gn(()=>{l(u)},[l,u]),(0,$.jsx)(Un.span,{...s,ref:d,style:{pointerEvents:`none`},children:TE(c.value)?(0,$.jsx)($.Fragment,{children:o}):a})});NT.displayName=MT;var PT=`SelectIcon`,FT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,children:r,...i}=e;return(0,$.jsx)(Un.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})});FT.displayName=PT;var IT=`SelectPortal`,LT=e=>(0,$.jsx)(yr,{asChild:!0,...e});LT.displayName=IT;var RT=`SelectContent`,zT=Q.forwardRef((e,t)=>{let n=ET(RT,e.__scopeSelect),[r,i]=Q.useState();if(Gn(()=>{i(new DocumentFragment)},[]),!n.open){let t=r;return t?Hb.createPortal((0,$.jsx)(VT,{scope:e.__scopeSelect,children:(0,$.jsx)(yT.Slot,{scope:e.__scopeSelect,children:(0,$.jsx)(`div`,{children:e.children})})}),t):null}return(0,$.jsx)(GT,{...e,ref:t})});zT.displayName=RT;var BT=10,[VT,HT]=ST(RT),UT=`SelectContentImpl`,WT=aT(`SelectContent.RemoveScroll`),GT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,position:r=`item-aligned`,onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g,..._}=e,v=ET(RT,n),[y,b]=Q.useState(null),[x,S]=Q.useState(null),C=Hn(t,e=>b(e)),[w,T]=Q.useState(null),[E,D]=Q.useState(null),O=bT(n),[k,A]=Q.useState(!1),j=Q.useRef(!1);Q.useEffect(()=>{if(y)return rr(y)},[y]),Xn();let M=Q.useCallback(e=>{let[t,...n]=O().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&x&&(x.scrollTop=0),n===r&&x&&(x.scrollTop=x.scrollHeight),n?.focus(),document.activeElement!==i))return},[O,x]),N=Q.useCallback(()=>M([w,y]),[M,w,y]);Q.useEffect(()=>{k&&N()},[k,N]);let{onOpenChange:P,triggerPointerDownPosRef:F}=v;Q.useEffect(()=>{if(y){let e={x:0,y:0},t=t=>{e={x:Math.abs(Math.round(t.pageX)-(F.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(F.current?.y??0))}},n=n=>{e.x<=10&&e.y<=10?n.preventDefault():y.contains(n.target)||P(!1),document.removeEventListener(`pointermove`,t),F.current=null};return F.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[y,P,F]),Q.useEffect(()=>{let e=()=>P(!1);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[P]);let[I,L]=EE(e=>{let t=O().filter(e=>!e.disabled),n=DE(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current.focus())}),R=Q.useCallback((e,t,n)=>{let r=!j.current&&!n;(v.value!==void 0&&v.value===t||r)&&(T(e),r&&(j.current=!0))},[v.value]),z=Q.useCallback(()=>y?.focus(),[y]),B=Q.useCallback((e,t,n)=>{let r=!j.current&&!n;(v.value!==void 0&&v.value===t||r)&&D(e)},[v.value]),V=r===`popper`?YT:qT,H=V===YT?{side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g}:{};return(0,$.jsx)(VT,{scope:n,content:y,viewport:x,onViewportChange:S,itemRefCallback:R,selectedItem:w,onItemLeave:z,itemTextRefCallback:B,focusSelectedItem:N,selectedItemText:E,position:r,isPositioned:k,searchRef:I,children:(0,$.jsx)(nr,{as:WT,allowPinchZoom:!0,children:(0,$.jsx)(Qn,{asChild:!0,trapped:v.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:qn(i,e=>{v.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,$.jsx)(vr,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>v.onOpenChange(!1),children:(0,$.jsx)(V,{role:`listbox`,id:v.contentId,"data-state":v.open?`open`:`closed`,dir:v.dir,onContextMenu:e=>e.preventDefault(),..._,...H,onPlaced:()=>A(!0),ref:C,style:{display:`flex`,flexDirection:`column`,outline:`none`,..._.style},onKeyDown:qn(_.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&L(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=O().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>M(t)),e.preventDefault()}})})})})})})});GT.displayName=UT;var KT=`SelectItemAlignedPosition`,qT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,onPlaced:r,...i}=e,a=ET(RT,n),o=HT(RT,n),[s,c]=Q.useState(null),[l,u]=Q.useState(null),d=Hn(t,e=>u(e)),f=bT(n),p=Q.useRef(!1),m=Q.useRef(!0),{viewport:h,selectedItem:g,selectedItemText:_,focusSelectedItem:v}=o,y=Q.useCallback(()=>{if(a.trigger&&a.valueNode&&s&&l&&h&&g&&_){let e=a.trigger.getBoundingClientRect(),t=l.getBoundingClientRect(),n=a.valueNode.getBoundingClientRect(),i=_.getBoundingClientRect();if(a.dir!==`rtl`){let r=i.left-t.left,a=n.left-r,o=e.left-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-BT,d=dS(a,[BT,Math.max(BT,u-l)]);s.style.minWidth=c+`px`,s.style.left=d+`px`}else{let r=t.right-i.right,a=window.innerWidth-n.right-r,o=window.innerWidth-e.right-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-BT,d=dS(a,[BT,Math.max(BT,u-l)]);s.style.minWidth=c+`px`,s.style.right=d+`px`}let o=f(),c=window.innerHeight-BT*2,u=h.scrollHeight,d=window.getComputedStyle(l),m=parseInt(d.borderTopWidth,10),v=parseInt(d.paddingTop,10),y=parseInt(d.borderBottomWidth,10),b=parseInt(d.paddingBottom,10),x=m+v+u+b+y,S=Math.min(g.offsetHeight*5,x),C=window.getComputedStyle(h),w=parseInt(C.paddingTop,10),T=parseInt(C.paddingBottom,10),E=e.top+e.height/2-BT,D=c-E,O=g.offsetHeight/2,k=g.offsetTop+O,A=m+v+k,j=x-A;if(A<=E){let e=o.length>0&&g===o[o.length-1].ref.current;s.style.bottom=`0px`;let t=l.clientHeight-h.offsetTop-h.offsetHeight,n=A+Math.max(D,O+(e?T:0)+t+y);s.style.height=n+`px`}else{let e=o.length>0&&g===o[0].ref.current;s.style.top=`0px`;let t=Math.max(E,m+h.offsetTop+(e?w:0)+O)+j;s.style.height=t+`px`,h.scrollTop=A-E+h.offsetTop}s.style.margin=`${BT}px 0`,s.style.minHeight=S+`px`,s.style.maxHeight=c+`px`,r?.(),requestAnimationFrame(()=>p.current=!0)}},[f,a.trigger,a.valueNode,s,l,h,g,_,a.dir,r]);Gn(()=>y(),[y]);let[b,x]=Q.useState();return Gn(()=>{l&&x(window.getComputedStyle(l).zIndex)},[l]),(0,$.jsx)(XT,{scope:n,contentWrapper:s,shouldExpandOnScrollRef:p,onScrollButtonChange:Q.useCallback(e=>{e&&m.current===!0&&(y(),v?.(),m.current=!1)},[y,v]),children:(0,$.jsx)(`div`,{ref:c,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:b},children:(0,$.jsx)(Un.div,{...i,ref:d,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})});qT.displayName=KT;var JT=`SelectPopperPosition`,YT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,align:r=`start`,collisionPadding:i=BT,...a}=e,o=wT(n);return(0,$.jsx)(rT,{...o,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})});YT.displayName=JT;var[XT,ZT]=ST(RT,{}),QT=`SelectViewport`,$T=Q.forwardRef((e,t)=>{let{__scopeSelect:n,nonce:r,...i}=e,a=HT(QT,n),o=ZT(QT,n),s=Hn(t,a.onViewportChange),c=Q.useRef(0);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:r}),(0,$.jsx)(yT.Slot,{scope:n,children:(0,$.jsx)(Un.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:s,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:qn(i.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=o;if(r?.current&&n){let e=Math.abs(c.current-t.scrollTop);if(e>0){let r=window.innerHeight-BT*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}c.current=t.scrollTop})})})]})});$T.displayName=QT;var eE=`SelectGroup`,[tE,nE]=ST(eE),rE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=Yn();return(0,$.jsx)(tE,{scope:n,id:i,children:(0,$.jsx)(Un.div,{role:`group`,"aria-labelledby":i,...r,ref:t})})});rE.displayName=eE;var iE=`SelectLabel`,aE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=nE(iE,n);return(0,$.jsx)(Un.div,{id:i.id,...r,ref:t})});aE.displayName=iE;var oE=`SelectItem`,[sE,cE]=ST(oE),lE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...o}=e,s=ET(oE,n),c=HT(oE,n),l=s.value===r,[u,d]=Q.useState(a??``),[f,p]=Q.useState(!1),m=Hn(t,e=>c.itemRefCallback?.(e,r,i)),h=Yn(),g=Q.useRef(`touch`),_=()=>{i||(s.onValueChange(r),s.onOpenChange(!1))};if(r===``)throw Error(`A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.`);return(0,$.jsx)(sE,{scope:n,value:r,disabled:i,textId:h,isSelected:l,onItemTextChange:Q.useCallback(e=>{d(t=>t||(e?.textContent??``).trim())},[]),children:(0,$.jsx)(yT.ItemSlot,{scope:n,value:r,disabled:i,textValue:u,children:(0,$.jsx)(Un.div,{role:`option`,"aria-labelledby":h,"data-highlighted":f?``:void 0,"aria-selected":l&&f,"data-state":l?`checked`:`unchecked`,"aria-disabled":i||void 0,"data-disabled":i?``:void 0,tabIndex:i?void 0:-1,...o,ref:m,onFocus:qn(o.onFocus,()=>p(!0)),onBlur:qn(o.onBlur,()=>p(!1)),onClick:qn(o.onClick,()=>{g.current!==`mouse`&&_()}),onPointerUp:qn(o.onPointerUp,()=>{g.current===`mouse`&&_()}),onPointerDown:qn(o.onPointerDown,e=>{g.current=e.pointerType}),onPointerMove:qn(o.onPointerMove,e=>{g.current=e.pointerType,i?c.onItemLeave?.():g.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:qn(o.onPointerLeave,e=>{e.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:qn(o.onKeyDown,e=>{c.searchRef?.current!==``&&e.key===` `||(_T.includes(e.key)&&_(),e.key===` `&&e.preventDefault())})})})})});lE.displayName=oE;var uE=`SelectItemText`,dE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,...a}=e,o=ET(uE,n),s=HT(uE,n),c=cE(uE,n),l=OT(uE,n),[u,d]=Q.useState(null),f=Hn(t,e=>d(e),c.onItemTextChange,e=>s.itemTextRefCallback?.(e,c.value,c.disabled)),p=u?.textContent,m=Q.useMemo(()=>(0,$.jsx)(`option`,{value:c.value,disabled:c.disabled,children:p},c.value),[c.disabled,c.value,p]),{onNativeOptionAdd:h,onNativeOptionRemove:g}=l;return Gn(()=>(h(m),()=>g(m)),[h,g,m]),(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Un.span,{id:c.textId,...a,ref:f}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren?Hb.createPortal(a.children,o.valueNode):null]})});dE.displayName=uE;var fE=`SelectItemIndicator`,pE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return cE(fE,n).isSelected?(0,$.jsx)(Un.span,{"aria-hidden":!0,...r,ref:t}):null});pE.displayName=fE;var mE=`SelectScrollUpButton`,hE=Q.forwardRef((e,t)=>{let n=HT(mE,e.__scopeSelect),r=ZT(mE,e.__scopeSelect),[i,a]=Q.useState(!1),o=Hn(t,r.onScrollButtonChange);return Gn(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollTop>0;a(e)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,$.jsx)(vE,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null});hE.displayName=mE;var gE=`SelectScrollDownButton`,_E=Q.forwardRef((e,t)=>{let n=HT(gE,e.__scopeSelect),r=ZT(gE,e.__scopeSelect),[i,a]=Q.useState(!1),o=Hn(t,r.onScrollButtonChange);return Gn(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollHeight-t.clientHeight,n=Math.ceil(t.scrollTop)<e;a(n)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,$.jsx)(vE,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null});_E.displayName=gE;var vE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,onAutoScroll:r,...i}=e,a=HT(`SelectScrollButton`,n),o=Q.useRef(null),s=bT(n),c=Q.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return Q.useEffect(()=>()=>c(),[c]),Gn(()=>{s().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[s]),(0,$.jsx)(Un.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:qn(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:qn(i.onPointerMove,()=>{a.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:qn(i.onPointerLeave,()=>{c()})})}),yE=`SelectSeparator`,bE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return(0,$.jsx)(Un.div,{"aria-hidden":!0,...r,ref:t})});bE.displayName=yE;var xE=`SelectArrow`,SE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=wT(n),a=ET(xE,n),o=HT(xE,n);return a.open&&o.position===`popper`?(0,$.jsx)(iT,{...i,...r,ref:t}):null});SE.displayName=xE;var CE=`SelectBubbleInput`,wE=Q.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{let i=Q.useRef(null),a=Hn(r,i),o=dT(t);return Q.useEffect(()=>{let e=i.current;if(!e)return;let n=window.HTMLSelectElement.prototype,r=Object.getOwnPropertyDescriptor(n,`value`).set;if(o!==t&&r){let n=new Event(`change`,{bubbles:!0});r.call(e,t),e.dispatchEvent(n)}},[o,t]),(0,$.jsx)(Un.select,{...n,style:{...fT,...n.style},ref:a,defaultValue:t})});wE.displayName=CE;function TE(e){return e===``||e===void 0}function EE(e){let t=Jn(e),n=Q.useRef(``),r=Q.useRef(0),i=Q.useCallback(e=>{let i=n.current+e;t(i),(function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))})(i)},[t]),a=Q.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return Q.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}function DE(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=OE(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}function OE(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var kE=kT,AE=jT,jE=NT,ME=FT,NE=LT,PE=zT,FE=$T,IE=aE,LE=lE,RE=dE,zE=pE,BE=hE,VE=_E,HE=bE,UE=`flex min-w-0 items-center gap-1.5 rounded-md px-1.5 py-1 text-sm font-medium text-foreground outline-none transition-colors hover:bg-surface/70 focus-visible:ring-2 focus-visible:ring-accent-primary/50 disabled:cursor-not-allowed disabled:opacity-50`,WE=`overflow-hidden rounded-xl border border-border/60 bg-card/95 shadow-2xl backdrop-blur-xl`,GE=`flex w-full items-center gap-2.5 px-3 py-1.5 text-left text-sm text-foreground outline-none hover:bg-surface/70 focus-visible:bg-surface/70`;function KE({label:e,value:t,options:n,icon:r,onSelect:i,placeholder:a,disabled:o=!1,testId:s}){return(0,$.jsxs)(kE,{value:t,onValueChange:i,disabled:o||n.length===0,children:[(0,$.jsxs)(AE,{"aria-label":e,title:e,"data-agent-interactive":!0,"data-testid":s,className:UE,children:[(0,$.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-accent-primary`,"aria-hidden":!0}),(0,$.jsx)(jE,{placeholder:a??e,className:`max-w-[160px] truncate`}),(0,$.jsx)(ME,{asChild:!0,children:(0,$.jsx)(Xo,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`})})]}),(0,$.jsx)(NE,{children:(0,$.jsxs)(PE,{position:`popper`,side:`top`,align:`start`,sideOffset:4,collisionPadding:8,className:`z-[80] min-w-[12rem] max-w-[20rem] ${WE} data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 data-[state=open]:zoom-in-95 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-1 data-[side=top]:slide-in-from-bottom-1`,children:[(0,$.jsx)(BE,{className:`flex items-center justify-center py-1 text-foreground/50`,children:(0,$.jsx)(gn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(FE,{className:`max-h-72 py-1`,children:n.map(e=>{let t=e.icon??r;return(0,$.jsxs)(LE,{value:e.value,className:`${GE} relative cursor-default select-none pr-9 data-[highlighted]:bg-surface/70 data-[state=checked]:font-medium`,children:[(0,$.jsx)(t,{className:`h-4 w-4 shrink-0 text-accent-primary`,"aria-hidden":!0}),(0,$.jsx)(RE,{children:(0,$.jsx)(`span`,{className:`truncate`,children:e.label})}),(0,$.jsx)(zE,{className:`absolute right-3 flex items-center`,children:(0,$.jsx)(Sn,{className:`h-3.5 w-3.5 text-accent-primary`})})]},e.value)})}),(0,$.jsx)(VE,{className:`flex items-center justify-center py-1 text-foreground/50`,children:(0,$.jsx)(Xo,{className:`h-3.5 w-3.5`})})]})})]})}var qE=`__new__`,JE=`__legacy__`,YE=`__default__`,XE=12,ZE=`specrails:focus-pr-card`,QE=(0,Q.lazy)(()=>c(()=>import(`./JobDetailModal-DSsX48Vu.js`).then(e=>({default:e.JobDetailModal})),__vite__mapDeps([6,1,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80])));function $E(e,t,n){if(e.availability)return e.availability;let r=String(e.railIndex);if(t.activeJobs?.[r]||t.activeLoopRuns?.[r])return`busy`;let i=t.prDeliveries?.[r];return i&&i.decision&&![`merged`,`discarded`,`completed`,`superseded`,`pr_ready`].includes(i.decision)?`pending_decision`:e.ticketIds.some(e=>n.find(t=>t.id===e)?.status===`on_review`)?`on_review`:`free`}function eD(e,t){let n=e(`railCard.rail`,{index:t.railIndex+1});return t.name?`${n} · ${t.name}`:n}function tD({proposal:e,proposalIndex:t,messageId:n,conversationId:r,projectId:i,intent:a,compact:o=!1}){let{t:s}=K(`agent`),c=My(),l=Zx(),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)([]),[g,_]=(0,Q.useState)([]),[v,y]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{if(!i||a)return;let e=!1,t=`${Xe}/api/projects/${encodeURIComponent(i)}`;return Promise.all([fetch(`${t}/rails`).then(e=>e.ok?e.json():Promise.reject(Error(String(e.status)))),fetch(`${t}/tickets`).then(e=>e.ok?e.json():Promise.reject(Error(String(e.status))))]).then(([t,n])=>{e||(d(t&&typeof t==`object`?t:{}),p(Array.isArray(n?.tickets)?n.tickets:[]))}).catch(()=>{e||y(!0)}),ke&&sS.list().then(t=>{e||_(t.filter(e=>e.status===`published`&&uS(e.graph)))}).catch(()=>{}),()=>{e=!0}},[i,a]);let[b,x]=(0,Q.useState)(()=>({railIndex:e.railIndex,newRail:!!e.newRail,railName:e.newRail?.name??e.railName??``,ticketIds:e.ticketIds,loopId:e.loopId??nS(null,e.mode),aiEngine:e.aiEngine,model:e.model,reasoningEffort:e.reasoningEffort,profileName:e.profileName,targetPrNumber:e.targetPrNumber,baseBranch:e.baseBranch??``,followUp:e.followUp??null})),S=(0,Q.useCallback)(e=>x(t=>({...t,...e})),[]),C=l.detected,w=!l.loading,T=(0,Q.useMemo)(()=>b.aiEngine&&(wt(b.aiEngine)||C.includes(b.aiEngine))?b.aiEngine:C[0]??null,[b.aiEngine,C]),E=!!b.aiEngine&&w&&T!==b.aiEngine,D=!!T&&wt(T),O=T&&!wt(T)?T:C[0]??null,k=(0,Q.useMemo)(()=>Jx(O),[O]),j=(0,Q.useMemo)(()=>b.model&&k.some(e=>e.value===b.model)?b.model:Yx(O)||null,[b.model,k,O]),M=!!b.model&&k.length>0&&j!==b.model,N=(0,Q.useMemo)(()=>vt(O,j),[O,j]),P=b.reasoningEffort&&N.includes(b.reasoningEffort)?b.reasoningEffort:null,F=tS(b.loopId),I=!D&&F!==`loop`&&xt(O);(0,Q.useEffect)(()=>{if(!i||a||!O||!I){h([]);return}let e=!1;return fetch(`${Xe}/api/projects/${encodeURIComponent(i)}/profiles?provider=${encodeURIComponent(O)}`).then(e=>e.ok?e.json():{profiles:[]}).then(t=>{if(e)return;let n=Array.isArray(t.profiles)?t.profiles.filter(e=>!e.provider||e.provider===O):[];h(n)}).catch(()=>{e||h([])}),()=>{e=!0}},[i,a,O,I]);let L=b.profileName&&m.some(e=>e.name===b.profileName)?b.profileName:null,R=(0,Q.useMemo)(()=>u?.rails??[],[u]),z=(0,Q.useMemo)(()=>{let e=new Map;if(!u)return e;for(let t of R)e.set(t.railIndex,$E(t,u,f??[]));return e},[R,u,f]),V=b.railIndex===null?void 0:R.find(e=>e.railIndex===b.railIndex),H=u!==null&&b.railIndex!==null&&!b.newRail&&!V,U=!!V&&!b.newRail&&z.get(V.railIndex)!==`free`&&z.get(V.railIndex)!==void 0,W=R.length>=XE,ee=R.find(e=>z.get(e.railIndex)===`free`),te=b.newRail?qE:b.railIndex!==null&&V?String(b.railIndex):ee?String(ee.railIndex):W?``:qE,ne=b.newRail||te===qE||te===``?null:Number(te),re=te===qE,ie=(0,Q.useMemo)(()=>new Map((f??[]).map(e=>[e.id,e])),[f]),ae=(0,Q.useMemo)(()=>f?b.ticketIds.filter(e=>ie.has(e)):b.ticketIds,[b.ticketIds,ie,f]),oe=f?b.ticketIds.filter(e=>!ie.has(e)):[],se=(0,Q.useMemo)(()=>ae.flatMap(e=>he(ie.get(e)?.addenda).map(t=>({ticketId:e,title:t.title}))),[ae,ie]),ce=se.length,le=se.slice(0,3).map(e=>`#${e.ticketId} ${e.title}`),ue=(0,Q.useMemo)(()=>(f??[]).filter(e=>(e.status===`todo`||e.status===`draft`)&&!b.ticketIds.includes(e.id)),[f,b.ticketIds]),de=!D&&bt(O),fe=(0,Q.useMemo)(()=>[...$x.filter(e=>(!e.requiresFreestyle||de)&&(!e.requiresLoops||ke)).map(e=>({value:e.id,label:s(`dashboard:${e.labelKey}`)})),...g.map(e=>({value:e.id,label:e.name}))],[g,de,s]),G=fe.some(e=>e.value===b.loopId)?b.loopId:fe[0]?.value??b.loopId,[pe,me]=(0,Q.useState)(null),[ge,_e]=(0,Q.useState)(null),[ve,ye]=(0,Q.useState)(null),be=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>()=>{be.current=!1},[]);let xe=a??ve,Se=i?v?s(`railCard.block.loadFailed`):ae.length===0?s(`railCard.block.noSpecs`):te===``?s(`railCard.block.railLimit`,{max:XE}):null:s(`railCard.block.noProject`),Ce=(0,Q.useCallback)(async e=>{let t=await Mo(r,n,e),i=t.ok?t.intent:{...e,at:new Date().toISOString()};Vx(n,i),be.current&&ye(i)},[r,n]),we=(0,Q.useCallback)(async()=>{if(!i||Se||pe)return;me(`launch`),_e(null);let e=`${Xe}/api/projects/${encodeURIComponent(i)}/rails`,n={"content-type":`application/json`},a=async e=>{let t={};try{t=await e.json()}catch{}return{error:typeof t.error==`string`?t.error:`HTTP ${e.status}`,detail:typeof t.detail==`string`?t.detail:void 0,action:typeof t.action==`string`?t.action:void 0}};try{let o=ne,s=b.railName.trim().slice(0,60);if(o===null){let t=await fetch(e,{method:`POST`,headers:n,body:JSON.stringify({name:s||null})});if(!t.ok){_e(await a(t));return}let r=await t.json();if(typeof r.rail?.railIndex!=`number`){_e({error:`invalid_response`});return}o=r.rail.railIndex}else if(s&&s!==(V?.name??``)){let t=await fetch(`${e}/${o}/name`,{method:`PUT`,headers:n,body:JSON.stringify({name:s})});if(!t.ok){_e(await a(t));return}}let c=T&&C.length>1?T:void 0,l=await fetch(`${e}/${o}/tickets`,{method:`PUT`,headers:n,body:JSON.stringify({ticketIds:ae,mode:F,profileName:I?L:null,...c?{aiEngine:c}:{}})});if(!l.ok){_e(await a(l));return}let u={mode:F,loopId:G,originConversationId:r,originSurface:`agent-chat`,...c?{aiEngine:c}:{},...!D&&j?{model:j}:{},...!D&&P?{reasoning_effort:P}:{},...I&&L?{profileName:L}:{},...b.targetPrNumber?{targetPrNumber:b.targetPrNumber}:{},...b.baseBranch.trim()?{baseBranch:b.baseBranch.trim()}:{},...b.followUp?{followUp:b.followUp}:{}},d=await fetch(`${e}/${o}/launch`,{method:`POST`,headers:n,body:JSON.stringify(u)});if(!d.ok){_e(await a(d));return}let f=await d.json(),p=Array.isArray(f.loopRunIds)&&f.loopRunIds.length?f.loopRunIds:Array.isArray(f.jobIds)&&f.jobIds.length?f.jobIds:f.jobId?[f.jobId]:[];Ht(i),await Ce({kind:`rail-launch`,proposalIndex:t,status:`launched`,railIndex:o,runIds:p,prDeliveryId:typeof f.prDeliveryId==`string`?f.prDeliveryId:null,config:{...u,ticketIds:ae,railName:s||null}})}catch(e){_e({error:e instanceof Error?e.message:`network`})}finally{be.current&&me(null)}},[i,Se,pe,ne,b,V,T,D,C.length,ae,F,I,L,G,j,P,r,t,Ce]),Te=(0,Q.useCallback)(async()=>{if(!pe){me(`dismiss`);try{await Ce({kind:`rail-launch`,proposalIndex:t,status:`dismissed`})}finally{be.current&&me(null)}}},[pe,Ce,t]),[Ee,De]=(0,Q.useState)(null);if(xe){let t=xe.status===`launched`,n=xe.runIds?.[0]??null;return(0,$.jsxs)(`div`,{"data-testid":t?`agent-rail-launch-stub-launched`:`agent-rail-launch-stub-dismissed`,className:X(`my-1 flex items-center gap-2 rounded-xl border px-3 py-2 text-xs backdrop-blur`,t?`border-accent-success/30 bg-accent-success/[0.06] text-foreground/80`:`border-border/50 bg-surface/40 text-foreground/50`),children:[t?(0,$.jsx)($o,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`}):(0,$.jsx)(Cn,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[t?s(`railCard.stub.launched`,{rail:typeof xe.railIndex==`number`?xe.railIndex+1:`?`}):s(`railCard.stub.dismissed`),` `,(0,$.jsx)(`span`,{className:`text-foreground/50`,children:e.ticketIds.map(e=>`#${e}`).join(` `)})]}),t&&(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`agent-rail-launch-focus-card`,title:s(`railCard.stub.goToCardTitle`),onClick:()=>{window.dispatchEvent(new CustomEvent(ZE,{detail:{prDeliveryId:xe.prDeliveryId??null,runIds:xe.runIds??[]}}))},className:`inline-flex shrink-0 items-center gap-1 rounded-md border border-border/60 bg-card/70 px-2 py-0.5 text-[11px] font-medium text-foreground/70 transition-colors hover:border-accent-primary/40 hover:text-foreground`,children:[(0,$.jsx)(oc,{className:`h-3 w-3`}),s(`railCard.stub.goToCard`)]}),t&&i&&n&&(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`agent-rail-launch-view-run`,title:s(`railCard.stub.viewRunTitle`),onClick:()=>De(n),className:`inline-flex shrink-0 items-center gap-1 rounded-md border border-accent-primary/40 bg-accent-primary/10 px-2 py-0.5 text-[11px] font-medium text-accent-primary transition-colors hover:bg-accent-primary/20`,children:[(0,$.jsx)(pn,{className:`h-3 w-3`}),s(`railCard.stub.viewRun`)]}),Ee&&i&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(QE,{jobId:Ee,projectId:i,onClose:()=>De(null)})})]})}let Oe=[...R.map(e=>{let t=z.get(e.railIndex),n=t&&t!==`free`?` · ${s(`railCard.availability.${t}`)}`:``;return{value:String(e.railIndex),label:`${eD(s,e)}${n}`}}),...W?[]:[{value:qE,label:s(`railCard.newRail`),icon:Pn}]],Ae=[...C.map(e=>({value:e,label:l.providers[e]?.displayName??jt(e)})),...C.length>1?[{value:Mt,label:s(`agents:railSelectors.rolesEngine`),icon:kn}]:[]],je=k.map(e=>({value:e.value,label:e.label??e.value})),Me=[{value:YE,label:s(`railCard.effortDefault`)},...N.map(e=>({value:e,label:s(`effort.${e}`,{defaultValue:e})}))],Ne=[{value:JE,label:s(`railCard.profileNone`)},...m.map(e=>({value:e.name,label:e.name}))],Pe=!!i&&!v&&(u===null||f===null),Fe=Pe?{tone:`border-border/60 bg-surface/60 text-foreground/50`,label:s(`railCard.status.loading`)}:Se?{tone:`border-accent-warning/40 bg-accent-warning/10 text-accent-warning`,label:s(`railCard.status.blocked`)}:{tone:`border-accent-primary/40 bg-accent-primary/10 text-accent-primary`,label:s(`railCard.status.ready`)};return(0,$.jsxs)(Ny.div,{initial:!c&&{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.22,ease:`easeOut`},"data-testid":`agent-rail-launch-card`,className:X(`my-1 overflow-hidden rounded-xl border border-accent-primary/25 bg-card/80 shadow-lg backdrop-blur`,o&&`my-0`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/40 bg-accent-primary/[0.06] px-3.5 py-2`,children:[(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1.5 text-[10px] font-semibold uppercase tracking-widest text-accent-primary/90`,children:[(0,$.jsx)(gc,{className:`h-3 w-3`}),s(`railCard.heading`)]}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-foreground/55`,children:ae.map(e=>`#${e}`).join(` `)}),(0,$.jsx)(`span`,{className:X(`inline-flex shrink-0 items-center rounded-full border px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide`,Fe.tone),children:Fe.label})]}),(0,$.jsxs)(`div`,{className:`space-y-2.5 px-3.5 py-3`,children:[e.rationale&&(0,$.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs italic text-foreground/60`,children:[(0,$.jsx)(Ln,{className:`mt-0.5 h-3 w-3 shrink-0 text-accent-primary/70`}),(0,$.jsx)(`span`,{children:e.rationale})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(KE,{label:s(`railCard.fields.rail`),icon:Mc,value:te,options:Oe,disabled:Pe||!!pe,testId:`rail-card-rail`,onSelect:e=>S(e===qE?{newRail:!0,railIndex:null}:{newRail:!1,railIndex:Number(e)})}),(re||V)&&(0,$.jsx)(`input`,{type:`text`,"data-agent-interactive":!0,"data-testid":`rail-card-name`,value:b.railName,maxLength:60,placeholder:s(re?`railCard.fields.newRailName`:`railCard.fields.railName`),onChange:e=>S({railName:e.target.value}),className:`h-7 min-w-[120px] flex-1 rounded-md border border-border/60 bg-surface/50 px-2 text-xs text-foreground outline-none placeholder:text-foreground/35 focus:border-accent-primary/50`})]}),H&&(0,$.jsx)(nD,{tone:`warning`,text:s(`railCard.notes.railMissing`,{index:(b.railIndex??0)+1})}),U&&V&&(0,$.jsx)(nD,{tone:`warning`,text:s(`railCard.notes.railBusy`,{index:V.railIndex+1,state:s(`railCard.availability.${z.get(V.railIndex)??`busy`}`)}),action:ee?{label:s(`railCard.notes.useFree`,{index:ee.railIndex+1}),onClick:()=>S({newRail:!1,railIndex:ee.railIndex})}:void 0}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,"data-testid":`rail-card-specs`,children:[ae.map(e=>{let t=ie.get(e);return(0,$.jsxs)(`span`,{title:t?.title,className:`inline-flex max-w-[220px] items-center gap-1 rounded-full border border-accent-primary/35 bg-accent-primary/10 py-0.5 pl-2 pr-1 text-[11px] font-medium text-accent-primary`,children:[(0,$.jsxs)(`span`,{className:`truncate`,children:[`#`,e,t?` ${t.title}`:``]}),(0,$.jsx)(`button`,{type:`button`,"data-agent-interactive":!0,"aria-label":s(`railCard.fields.removeSpec`,{id:e}),disabled:!!pe,onClick:()=>S({ticketIds:b.ticketIds.filter(t=>t!==e)}),className:`rounded-full p-0.5 text-accent-primary/60 hover:bg-accent-primary/20 hover:text-accent-primary`,children:(0,$.jsx)(Vn,{className:`h-3 w-3`})})]},e)}),ue.length>0&&(0,$.jsx)(KE,{label:s(`railCard.fields.addSpec`),icon:Pn,value:``,placeholder:s(`railCard.fields.addSpec`),options:ue.slice(0,40).map(e=>({value:String(e.id),label:`#${e.id} ${e.title}`})),disabled:!!pe,testId:`rail-card-add-spec`,onSelect:e=>S({ticketIds:[...b.ticketIds,Number(e)]})})]}),oe.length>0&&(0,$.jsx)(nD,{tone:`muted`,text:s(`railCard.notes.specsDropped`,{ids:oe.map(e=>`#${e}`).join(`, `)})}),ce>0&&(0,$.jsxs)(`div`,{"data-testid":`rail-card-addenda`,className:`flex items-start gap-1.5 rounded-lg border border-accent-primary/25 bg-accent-primary/[0.05] px-2.5 py-1.5 text-[11px] text-foreground/75`,children:[(0,$.jsx)(kn,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-primary/80`}),(0,$.jsxs)(`span`,{children:[s(`railCard.addenda.rides`,{count:ce}),` `,(0,$.jsx)(`span`,{className:`text-foreground/50`,children:le.join(` · `)})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-1 gap-y-1`,children:[(0,$.jsx)(KE,{label:s(`railCard.fields.loop`),icon:Lc,value:G,options:fe,disabled:!!pe,testId:`rail-card-loop`,onSelect:e=>S({loopId:e})}),Ae.length>1&&(0,$.jsx)(KE,{label:s(`railCard.fields.engine`),icon:fs,value:T??``,options:Ae,disabled:!!pe,testId:`rail-card-engine`,onSelect:e=>S({aiEngine:e,model:null,reasoningEffort:null,profileName:null})}),!D&&je.length>0&&(0,$.jsx)(KE,{label:s(`railCard.fields.model`),icon:Uo,value:j??``,options:je,disabled:!!pe,testId:`rail-card-model`,onSelect:e=>S({model:e})}),!D&&N.length>0&&(0,$.jsx)(KE,{label:s(`railCard.fields.effort`),icon:Ds,value:P??YE,options:Me,disabled:!!pe,testId:`rail-card-effort`,onSelect:e=>S({reasoningEffort:e===YE?null:e})}),I&&m.length>0&&(0,$.jsx)(KE,{label:s(`railCard.fields.profile`),icon:Nc,value:L??JE,options:Ne,disabled:!!pe,testId:`rail-card-profile`,onSelect:e=>S({profileName:e===JE?null:e})})]}),E&&(0,$.jsx)(nD,{tone:`muted`,text:s(`railCard.notes.engineStale`,{engine:b.aiEngine,fallback:T?jt(T):``})}),M&&(0,$.jsx)(nD,{tone:`muted`,text:s(`railCard.notes.modelStale`,{model:b.model,fallback:j})}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-foreground/60`,children:[(0,$.jsx)(A,{className:`h-3.5 w-3.5 text-accent-primary/70`}),(0,$.jsx)(`span`,{className:`sr-only`,children:s(`railCard.fields.targetPr`)}),(0,$.jsx)(`input`,{type:`number`,min:1,inputMode:`numeric`,"data-agent-interactive":!0,"data-testid":`rail-card-target-pr`,value:b.targetPrNumber??``,placeholder:s(`railCard.fields.targetPr`),disabled:!!pe,onChange:e=>S({targetPrNumber:e.target.value?Math.max(1,Math.floor(Number(e.target.value))):null}),className:`h-7 w-28 rounded-md border border-border/60 bg-surface/50 px-2 text-xs text-foreground outline-none placeholder:text-foreground/35 focus:border-accent-primary/50`})]}),(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-foreground/60`,children:[(0,$.jsx)(On,{className:`h-3.5 w-3.5 text-accent-primary/70`}),(0,$.jsx)(`span`,{className:`sr-only`,children:s(`railCard.fields.baseBranch`)}),(0,$.jsx)(`input`,{type:`text`,"data-agent-interactive":!0,"data-testid":`rail-card-base-branch`,value:b.baseBranch,placeholder:s(`railCard.fields.baseBranch`),disabled:!!pe,onChange:e=>S({baseBranch:e.target.value}),className:`h-7 w-40 rounded-md border border-border/60 bg-surface/50 px-2 text-xs text-foreground outline-none placeholder:text-foreground/35 focus:border-accent-primary/50`})]})]}),b.followUp&&(0,$.jsxs)(`div`,{"data-testid":`rail-card-follow-up`,className:`rounded-lg border border-accent-primary/25 bg-accent-primary/[0.05] px-2.5 py-2 text-xs`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-medium text-foreground/85`,children:[(0,$.jsx)(B,{className:`h-3.5 w-3.5 text-accent-primary/80`}),s(`railCard.followUp.title`,{count:b.followUp.comments.length})]}),(0,$.jsx)(`span`,{className:`text-foreground/55`,children:b.followUp.scope.objective})]}),(0,$.jsx)(`ul`,{className:`mt-1.5 space-y-1`,children:b.followUp.comments.map(e=>(0,$.jsxs)(`li`,{className:`flex gap-2 text-foreground/75`,children:[(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-surface/70 px-1 font-mono text-[10px] text-foreground/60`,children:e.id}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[e.path?(0,$.jsxs)(`span`,{className:`font-mono text-[11px] text-accent-info`,children:[e.path,e.line?`:${e.line}`:``,` · `]}):null,(0,$.jsx)(`span`,{className:`line-clamp-2`,children:e.body}),(0,$.jsx)(`span`,{className:`ml-1 text-[10px] text-foreground/45`,children:s(`railCard.followUp.source.${e.source===`github`?`github`:`pasted`}`)})]})]},e.id))}),b.followUp.scope.excludedChanges.length>0&&(0,$.jsxs)(`div`,{className:`mt-1.5 text-foreground/60`,children:[(0,$.jsxs)(`span`,{className:`font-medium`,children:[s(`railCard.followUp.excluded`),`:`]}),` `,b.followUp.scope.excludedChanges.join(` · `)]}),b.followUp.scope.verification.length>0&&(0,$.jsxs)(`div`,{className:`mt-1 text-foreground/60`,children:[(0,$.jsxs)(`span`,{className:`font-medium`,children:[s(`railCard.followUp.verification`),`:`]}),` `,b.followUp.scope.verification.join(` · `)]}),(0,$.jsx)(`div`,{className:`mt-1.5 text-[11px] text-foreground/45`,children:s(`railCard.followUp.specUntouched`)})]}),ge&&(0,$.jsxs)(`div`,{"data-testid":`rail-card-error`,className:`flex items-start gap-2 rounded-lg border border-destructive/35 bg-destructive/10 px-2.5 py-1.5 text-xs text-destructive`,children:[(0,$.jsx)(zn,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`font-medium`,children:s(`railCard.errors.${ge.error}`,{defaultValue:ge.error})}),ge.detail&&(0,$.jsx)(`div`,{className:`text-destructive/80`,children:ge.detail}),ge.action&&(0,$.jsx)(`div`,{className:`text-foreground/70`,children:ge.action})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-0.5`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-foreground/45`,children:Se??s(`railCard.playHint`)}),(0,$.jsx)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`rail-card-dismiss`,disabled:!!pe,onClick:()=>void Te(),className:`rounded-md px-2 py-1 text-xs text-foreground/60 transition-colors hover:bg-surface hover:text-foreground disabled:opacity-50`,children:s(`railCard.dismiss`)}),(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`rail-card-play`,disabled:!!pe||Pe||!!Se,onClick:()=>void we(),className:`inline-flex items-center gap-1.5 rounded-md bg-accent-primary px-3 py-1 text-xs font-semibold text-white shadow transition-colors hover:bg-accent-primary/90 disabled:cursor-not-allowed disabled:opacity-50`,children:[pe===`launch`?(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Mn,{className:`h-3.5 w-3.5`}),s(pe===`launch`?`railCard.launching`:`railCard.play`)]})]})]})]})}function nD({tone:e,text:t,action:n}){return(0,$.jsxs)(`div`,{className:X(`flex items-center gap-2 rounded-lg border px-2.5 py-1 text-[11px]`,e===`warning`?`border-accent-warning/35 bg-accent-warning/10 text-accent-warning`:`border-border/50 bg-surface/40 text-foreground/55`),children:[e===`warning`&&(0,$.jsx)(zn,{className:`h-3 w-3 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:t}),n&&(0,$.jsx)(`button`,{type:`button`,"data-agent-interactive":!0,onClick:n.onClick,className:`shrink-0 rounded px-1.5 py-0.5 font-medium underline-offset-2 hover:underline`,children:n.label})]})}function rD(){let{t:e}=K(`agent`);return(0,$.jsxs)(`div`,{"data-testid":`agent-rail-launch-pending`,className:`my-1 inline-flex items-center gap-1.5 rounded-full border border-accent-primary/30 bg-accent-primary/10 px-2.5 py-1 text-[11px] text-accent-primary`,children:[(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`}),e(`railCard.pending`)]})}function iD({excerpts:e}){let{t}=K(`agent`);return(0,$.jsxs)(`div`,{"data-testid":`agent-rail-launch-unreadable`,title:e.join(`
|
|
33
|
+
`);if(cS.test(e)||lS.test(e))return!0}return!1}function dS(e,[t,n]){return Math.min(n,Math.max(t,e))}function fS(e){let t=pS(e),n=Q.forwardRef((e,n)=>{let{children:r,...i}=e,a=Q.Children.toArray(r),o=a.find(hS);if(o){let e=o.props.children,r=a.map(t=>t===o?Q.Children.count(e)>1?Q.Children.only(null):Q.isValidElement(e)?e.props.children:null:t);return(0,$.jsx)(t,{...i,ref:n,children:Q.isValidElement(e)?Q.cloneElement(e,void 0,r):null})}return(0,$.jsx)(t,{...i,ref:n,children:r})});return n.displayName=`${e}.Slot`,n}function pS(e){let t=Q.forwardRef((e,t)=>{let{children:n,...r}=e;if(Q.isValidElement(n)){let e=_S(n),i=gS(r,n.props);return n.type!==Q.Fragment&&(i.ref=t?or(t,e):e),Q.cloneElement(n,i)}return Q.Children.count(n)>1?Q.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var mS=Symbol(`radix.slottable`);function hS(e){return Q.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===mS}function gS(e,t){let n={...t};for(let r in t){let i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...e)=>{let t=a(...e);return i(...e),t}:i&&(n[r]=i):r===`style`?n[r]={...i,...a}:r===`className`&&(n[r]=[i,a].filter(Boolean).join(` `))}return{...e,...n}}function _S(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}function vS(e){let t=e+`CollectionProvider`,[n,r]=Wn(t),[i,a]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=e=>{let{scope:t,children:n}=e,r=Q.useRef(null),a=Q.useRef(new Map).current;return(0,$.jsx)(i,{scope:t,itemMap:a,collectionRef:r,children:n})};o.displayName=t;let s=e+`CollectionSlot`,c=fS(s),l=Q.forwardRef((e,t)=>{let{scope:n,children:r}=e,i=Hn(t,a(s,n).collectionRef);return(0,$.jsx)(c,{ref:i,children:r})});l.displayName=s;let u=e+`CollectionItemSlot`,d=`data-radix-collection-item`,f=fS(u),p=Q.forwardRef((e,t)=>{let{scope:n,children:r,...i}=e,o=Q.useRef(null),s=Hn(t,o),c=a(u,n);return Q.useEffect(()=>(c.itemMap.set(o,{ref:o,...i}),()=>void c.itemMap.delete(o))),(0,$.jsx)(f,{[d]:``,ref:s,children:r})});p.displayName=u;function m(t){let n=a(e+`CollectionConsumer`,t);return Q.useCallback(()=>{let e=n.collectionRef.current;if(!e)return[];let t=Array.from(e.querySelectorAll(`[${d}]`));return Array.from(n.itemMap.values()).sort((e,n)=>t.indexOf(e.ref.current)-t.indexOf(n.ref.current))},[n.collectionRef,n.itemMap])}return[{Provider:o,Slot:l,ItemSlot:p},m,r]}var yS=Q.createContext(void 0);function bS(e){let t=Q.useContext(yS);return e||t||`ltr`}var xS=[`top`,`right`,`bottom`,`left`],SS=Math.min,CS=Math.max,wS=Math.round,TS=Math.floor,ES=e=>({x:e,y:e}),DS={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function OS(e,t,n){return CS(e,SS(t,n))}function kS(e,t){return typeof e==`function`?e(t):e}function AS(e){return e.split(`-`)[0]}function jS(e){return e.split(`-`)[1]}function MS(e){return e===`x`?`y`:`x`}function NS(e){return e===`y`?`height`:`width`}function PS(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function FS(e){return MS(PS(e))}function IS(e,t,n){n===void 0&&(n=!1);let r=jS(e),i=FS(e),a=NS(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=GS(o)),[o,GS(o)]}function LS(e){let t=GS(e);return[RS(e),t,RS(t)]}function RS(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var zS=[`left`,`right`],BS=[`right`,`left`],VS=[`top`,`bottom`],HS=[`bottom`,`top`];function US(e,t,n){switch(e){case`top`:case`bottom`:return n?t?BS:zS:t?zS:BS;case`left`:case`right`:return t?VS:HS;default:return[]}}function WS(e,t,n,r){let i=jS(e),a=US(AS(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(RS)))),a}function GS(e){let t=AS(e);return DS[t]+e.slice(t.length)}function KS(e){return{top:0,right:0,bottom:0,left:0,...e}}function qS(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:KS(e)}function JS(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function YS(e,t,n){let{reference:r,floating:i}=e,a=PS(t),o=FS(t),s=NS(o),c=AS(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}switch(jS(t)){case`start`:p[o]-=f*(n&&l?-1:1);break;case`end`:p[o]+=f*(n&&l?-1:1);break}return p}async function XS(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=kS(t,e),p=qS(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=JS(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=JS(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var ZS=50,QS=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:XS},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=YS(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<ZS&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=YS(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},$S=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=kS(e,t)||{};if(l==null)return{};let d=qS(u),f={x:n,y:r},p=FS(i),m=NS(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l)),C=S?S[y]:0;(!C||!await(o.isElement==null?void 0:o.isElement(S)))&&(C=s.floating[y]||a.floating[m]);let w=b/2-x/2,T=C/2-h[m]/2-1,E=SS(d[_],T),D=SS(d[v],T),O=E,k=C-h[m]-D,A=C/2-h[m]/2+w,j=OS(O,A,k),M=!c.arrow&&jS(i)!=null&&A!==j&&a.reference[m]/2-(A<O?E:D)-h[m]/2<0,N=M?A<O?A-O:A-k:0;return{[p]:f[p]+N,data:{[p]:j,centerOffset:A-j-N,...M&&{alignmentOffset:N}},reset:M}}}),eC=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=kS(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=AS(r),_=PS(o),v=AS(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[GS(o)]:LS(o)),x=p!==`none`;!d&&x&&b.push(...WS(o,m,p,y));let S=[o,...b],C=await s.detectOverflow(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=IS(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(!(u===`alignment`&&_!==PS(t))||T.every(e=>PS(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=PS(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o;break}if(r!==n)return{reset:{placement:n}}}return{}}}};function tC(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function nC(e){return xS.some(t=>e[t]>=0)}var rC=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=kS(e,t);switch(i){case`referenceHidden`:{let e=tC(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:nC(e)}}}case`escaped`:{let e=tC(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:nC(e)}}}default:return{}}}}},iC=new Set([`left`,`top`]);async function aC(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=AS(n),s=jS(n),c=PS(n)===`y`,l=iC.has(o)?-1:1,u=a&&c?-1:1,d=kS(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var oC=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await aC(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},sC=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=kS(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=PS(AS(i)),p=MS(f),m=u[p],h=u[f];if(o){let e=p===`y`?`top`:`left`,t=p===`y`?`bottom`:`right`,n=m+d[e],r=m-d[t];m=OS(n,m,r)}if(s){let e=f===`y`?`top`:`left`,t=f===`y`?`bottom`:`right`,n=h+d[e],r=h-d[t];h=OS(n,h,r)}let g=c.fn({...t,[p]:m,[f]:h});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[p]:o,[f]:s}}}}}},cC=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=kS(e,t),u={x:n,y:r},d=PS(i),f=MS(d),p=u[f],m=u[d],h=kS(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:0,crossAxis:0,...h};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=iC.has(AS(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},lC=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){var n,r;let{placement:i,rects:a,platform:o,elements:s}=t,{apply:c=()=>{},...l}=kS(e,t),u=await o.detectOverflow(t,l),d=AS(i),f=jS(i),p=PS(i)===`y`,{width:m,height:h}=a.floating,g,_;d===`top`||d===`bottom`?(g=d,_=f===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?`start`:`end`)?`left`:`right`):(_=d,g=f===`end`?`top`:`bottom`);let v=h-u.top-u.bottom,y=m-u.left-u.right,b=SS(h-u[g],v),x=SS(m-u[_],y),S=!t.middlewareData.shift,C=b,w=x;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(w=y),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(C=v),S&&!f){let e=CS(u.left,0),t=CS(u.right,0),n=CS(u.top,0),r=CS(u.bottom,0);p?w=m-2*(e!==0||t!==0?e+t:CS(u.left,u.right)):C=h-2*(n!==0||r!==0?n+r:CS(u.top,u.bottom))}await c({...t,availableWidth:w,availableHeight:C});let T=await o.getDimensions(s.floating);return m!==T.width||h!==T.height?{reset:{rects:!0}}:{}}}};function uC(){return typeof window<`u`}function dC(e){return mC(e)?(e.nodeName||``).toLowerCase():`#document`}function fC(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function pC(e){return((mC(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function mC(e){return uC()?e instanceof Node||e instanceof fC(e).Node:!1}function hC(e){return uC()?e instanceof Element||e instanceof fC(e).Element:!1}function gC(e){return uC()?e instanceof HTMLElement||e instanceof fC(e).HTMLElement:!1}function _C(e){return!uC()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof fC(e).ShadowRoot}function vC(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=kC(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function yC(e){return/^(table|td|th)$/.test(dC(e))}function bC(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var xC=/transform|translate|scale|rotate|perspective|filter/,SC=/paint|layout|strict|content/,CC=e=>!!e&&e!==`none`,wC;function TC(e){let t=hC(e)?kC(e):e;return CC(t.transform)||CC(t.translate)||CC(t.scale)||CC(t.rotate)||CC(t.perspective)||!DC()&&(CC(t.backdropFilter)||CC(t.filter))||xC.test(t.willChange||``)||SC.test(t.contain||``)}function EC(e){let t=jC(e);for(;gC(t)&&!OC(t);){if(TC(t))return t;if(bC(t))return null;t=jC(t)}return null}function DC(){return wC??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),wC}function OC(e){return/^(html|body|#document)$/.test(dC(e))}function kC(e){return fC(e).getComputedStyle(e)}function AC(e){return hC(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function jC(e){if(dC(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||_C(e)&&e.host||pC(e);return _C(t)?t.host:t}function MC(e){let t=jC(e);return OC(t)?e.ownerDocument?e.ownerDocument.body:e.body:gC(t)&&vC(t)?t:MC(t)}function NC(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=MC(e),i=r===e.ownerDocument?.body,a=fC(r);if(i){let e=PC(a);return t.concat(a,a.visualViewport||[],vC(r)?r:[],e&&n?NC(e):[])}else return t.concat(r,NC(r,[],n))}function PC(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function FC(e){let t=kC(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=gC(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=wS(n)!==a||wS(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function IC(e){return hC(e)?e:e.contextElement}function LC(e){let t=IC(e);if(!gC(t))return ES(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=FC(t),o=(a?wS(n.width):n.width)/r,s=(a?wS(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var RC=ES(0);function zC(e){let t=fC(e);return!DC()||!t.visualViewport?RC:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function BC(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==fC(e)?!1:t}function VC(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=IC(e),o=ES(1);t&&(r?hC(r)&&(o=LC(r)):o=LC(e));let s=BC(a,n,r)?zC(a):ES(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a){let e=fC(a),t=r&&hC(r)?fC(r):r,n=e,i=PC(n);for(;i&&r&&t!==n;){let e=LC(i),t=i.getBoundingClientRect(),r=kC(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=fC(i),i=PC(n)}}return JS({width:u,height:d,x:c,y:l})}function HC(e,t){let n=AC(e).scrollLeft;return t?t.left+n:VC(pC(e)).left+n}function UC(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-HC(e,n),y:n.top+t.scrollTop}}function WC(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=pC(r),s=t?bC(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=ES(1),u=ES(0),d=gC(r);if((d||!d&&!a)&&((dC(r)!==`body`||vC(o))&&(c=AC(r)),d)){let e=VC(r);l=LC(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?UC(o,c):ES(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function GC(e){return Array.from(e.getClientRects())}function KC(e){let t=pC(e),n=AC(e),r=e.ownerDocument.body,i=CS(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=CS(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+HC(e),s=-n.scrollTop;return kC(r).direction===`rtl`&&(o+=CS(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}var qC=25;function JC(e,t){let n=fC(e),r=pC(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=DC();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=HC(r);if(l<=0){let e=r.ownerDocument,t=e.body,n=getComputedStyle(t),i=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,o=Math.abs(r.clientWidth-t.clientWidth-i);o<=qC&&(a-=o)}else l<=qC&&(a+=l);return{width:a,height:o,x:s,y:c}}function YC(e,t){let n=VC(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=gC(e)?LC(e):ES(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function XC(e,t,n){let r;if(t===`viewport`)r=JC(e,n);else if(t===`document`)r=KC(pC(e));else if(hC(t))r=YC(t,n);else{let n=zC(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return JS(r)}function ZC(e,t){let n=jC(e);return n===t||!hC(n)||OC(n)?!1:kC(n).position===`fixed`||ZC(n,t)}function QC(e,t){let n=t.get(e);if(n)return n;let r=NC(e,[],!1).filter(e=>hC(e)&&dC(e)!==`body`),i=null,a=kC(e).position===`fixed`,o=a?jC(e):e;for(;hC(o)&&!OC(o);){let t=kC(o),n=TC(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&(i.position===`absolute`||i.position===`fixed`)||vC(o)&&!n&&ZC(e,o))?r=r.filter(e=>e!==o):i=t,o=jC(o)}return t.set(e,r),r}function $C(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?bC(t)?[]:QC(t,this._c):[].concat(n),r],o=XC(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e<a.length;e++){let n=XC(t,a[e],i);s=CS(n.top,s),c=SS(n.right,c),l=SS(n.bottom,l),u=CS(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function ew(e){let{width:t,height:n}=FC(e);return{width:t,height:n}}function tw(e,t,n){let r=gC(t),i=pC(t),a=n===`fixed`,o=VC(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=ES(0);function l(){c.x=HC(i)}if(r||!r&&!a)if((dC(t)!==`body`||vC(i))&&(s=AC(t)),r){let e=VC(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else i&&l();a&&!r&&i&&l();let u=i&&!r&&!a?UC(i,s):ES(0);return{x:o.left+s.scrollLeft-c.x-u.x,y:o.top+s.scrollTop-c.y-u.y,width:o.width,height:o.height}}function nw(e){return kC(e).position===`static`}function rw(e,t){if(!gC(e)||kC(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return pC(e)===n&&(n=n.ownerDocument.body),n}function iw(e,t){let n=fC(e);if(bC(e))return n;if(!gC(e)){let t=jC(e);for(;t&&!OC(t);){if(hC(t)&&!nw(t))return t;t=jC(t)}return n}let r=rw(e,t);for(;r&&yC(r)&&nw(r);)r=rw(r,t);return r&&OC(r)&&nw(r)&&!TC(r)?n:r||EC(e)||n}var aw=async function(e){let t=this.getOffsetParent||iw,n=this.getDimensions,r=await n(e.floating);return{reference:tw(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function ow(e){return kC(e).direction===`rtl`}var sw={convertOffsetParentRelativeRectToViewportRelativeRect:WC,getDocumentElement:pC,getClippingRect:$C,getOffsetParent:iw,getElementRects:aw,getClientRects:GC,getDimensions:ew,getScale:LC,isElement:hC,isRTL:ow};function cw(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function lw(e,t){let n=null,r,i=pC(e);function a(){var e;clearTimeout(r),(e=n)==null||e.disconnect(),n=null}function o(s,c){s===void 0&&(s=!1),c===void 0&&(c=1),a();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(s||t(),!f||!p)return;let m=TS(d),h=TS(i.clientWidth-(u+f)),g=TS(i.clientHeight-(d+p)),_=TS(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:CS(0,SS(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(n!==c){if(!y)return o();n?o(!1,n):r=setTimeout(()=>{o(!1,1e-7)},1e3)}n===1&&!cw(l,e.getBoundingClientRect())&&o(),y=!1}try{n=new IntersectionObserver(b,{...v,root:i.ownerDocument})}catch{n=new IntersectionObserver(b,v)}n.observe(e)}return o(!0),a}function uw(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=IC(e),u=i||a?[...l?NC(l):[],...t?NC(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?lw(l,n):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?VC(e):null;c&&g();function g(){let t=VC(e);h&&!cw(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var dw=oC,fw=sC,pw=eC,mw=lC,hw=rC,gw=$S,_w=cC,vw=(e,t,n)=>{let r=new Map,i={platform:sw,...n},a={...i.platform,_c:r};return QS(e,t,{...i,platform:a})},yw=typeof document<`u`?Q.useLayoutEffect:function(){};function bw(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!bw(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!bw(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function xw(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Sw(e,t){let n=xw(e);return Math.round(t*n)/n}function Cw(e){let t=Q.useRef(e);return yw(()=>{t.current=e}),t}function ww(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=Q.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=Q.useState(r);bw(f,r)||p(r);let[m,h]=Q.useState(null),[g,_]=Q.useState(null),v=Q.useCallback(e=>{e!==S.current&&(S.current=e,h(e))},[]),y=Q.useCallback(e=>{e!==C.current&&(C.current=e,_(e))},[]),b=a||m,x=o||g,S=Q.useRef(null),C=Q.useRef(null),w=Q.useRef(u),T=c!=null,E=Cw(c),D=Cw(i),O=Cw(l),k=Q.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};D.current&&(e.platform=D.current),vw(S.current,C.current,e).then(e=>{let t={...e,isPositioned:O.current!==!1};A.current&&!bw(w.current,t)&&(w.current=t,Hb.flushSync(()=>{d(t)}))})},[f,t,n,D,O]);yw(()=>{l===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let A=Q.useRef(!1);yw(()=>(A.current=!0,()=>{A.current=!1}),[]),yw(()=>{if(b&&(S.current=b),x&&(C.current=x),b&&x){if(E.current)return E.current(b,x,k);k()}},[b,x,k,E,T]);let j=Q.useMemo(()=>({reference:S,floating:C,setReference:v,setFloating:y}),[v,y]),M=Q.useMemo(()=>({reference:b,floating:x}),[b,x]),N=Q.useMemo(()=>{let e={position:n,left:0,top:0};if(!M.floating)return e;let t=Sw(M.floating,u.x),r=Sw(M.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...xw(M.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,M.floating,u.x,u.y]);return Q.useMemo(()=>({...u,update:k,refs:j,elements:M,floatingStyles:N}),[u,k,j,M,N])}var Tw=e=>{function t(e){return{}.hasOwnProperty.call(e,`current`)}return{name:`arrow`,options:e,fn(n){let{element:r,padding:i}=typeof e==`function`?e(n):e;return r&&t(r)?r.current==null?{}:gw({element:r.current,padding:i}).fn(n):r?gw({element:r,padding:i}).fn(n):{}}}},Ew=(e,t)=>{let n=dw(e);return{name:n.name,fn:n.fn,options:[e,t]}},Dw=(e,t)=>{let n=fw(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ow=(e,t)=>({fn:_w(e).fn,options:[e,t]}),kw=(e,t)=>{let n=pw(e);return{name:n.name,fn:n.fn,options:[e,t]}},Aw=(e,t)=>{let n=mw(e);return{name:n.name,fn:n.fn,options:[e,t]}},jw=(e,t)=>{let n=hw(e);return{name:n.name,fn:n.fn,options:[e,t]}},Mw=(e,t)=>{let n=Tw(e);return{name:n.name,fn:n.fn,options:[e,t]}},Nw=`Arrow`,Pw=Q.forwardRef((e,t)=>{let{children:n,width:r=10,height:i=5,...a}=e;return(0,$.jsx)(Un.svg,{...a,ref:t,width:r,height:i,viewBox:`0 0 30 10`,preserveAspectRatio:`none`,children:e.asChild?n:(0,$.jsx)(`polygon`,{points:`0,0 30,0 15,10`})})});Pw.displayName=Nw;var Fw=Pw;function Iw(e){let[t,n]=Q.useState(void 0);return Gn(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});let t=new ResizeObserver(t=>{if(!Array.isArray(t)||!t.length)return;let r=t[0],i,a;if(`borderBoxSize`in r){let e=r.borderBoxSize,t=Array.isArray(e)?e[0]:e;i=t.inlineSize,a=t.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return t.observe(e,{box:`border-box`}),()=>t.unobserve(e)}else n(void 0)},[e]),t}var Lw=`Popper`,[Rw,zw]=Wn(Lw),[Bw,Vw]=Rw(Lw),Hw=e=>{let{__scopePopper:t,children:n}=e,[r,i]=Q.useState(null);return(0,$.jsx)(Bw,{scope:t,anchor:r,onAnchorChange:i,children:n})};Hw.displayName=Lw;var Uw=`PopperAnchor`,Ww=Q.forwardRef((e,t)=>{let{__scopePopper:n,virtualRef:r,...i}=e,a=Vw(Uw,n),o=Q.useRef(null),s=Hn(t,o),c=Q.useRef(null);return Q.useEffect(()=>{let e=c.current;c.current=r?.current||o.current,e!==c.current&&a.onAnchorChange(c.current)}),r?null:(0,$.jsx)(Un.div,{...i,ref:s})});Ww.displayName=Uw;var Gw=`PopperContent`,[Kw,qw]=Rw(Gw),Jw=Q.forwardRef((e,t)=>{let{__scopePopper:n,side:r=`bottom`,sideOffset:i=0,align:a=`center`,alignOffset:o=0,arrowPadding:s=0,avoidCollisions:c=!0,collisionBoundary:l=[],collisionPadding:u=0,sticky:d=`partial`,hideWhenDetached:f=!1,updatePositionStrategy:p=`optimized`,onPlaced:m,...h}=e,g=Vw(Gw,n),[_,v]=Q.useState(null),y=Hn(t,e=>v(e)),[b,x]=Q.useState(null),S=Iw(b),C=S?.width??0,w=S?.height??0,T=r+(a===`center`?``:`-`+a),E=typeof u==`number`?u:{top:0,right:0,bottom:0,left:0,...u},D=Array.isArray(l)?l:[l],O=D.length>0,k={padding:E,boundary:D.filter(Qw),altBoundary:O},{refs:A,floatingStyles:j,placement:M,isPositioned:N,middlewareData:P}=ww({strategy:`fixed`,placement:T,whileElementsMounted:(...e)=>uw(...e,{animationFrame:p===`always`}),elements:{reference:g.anchor},middleware:[Ew({mainAxis:i+w,alignmentAxis:o}),c&&Dw({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?Ow():void 0,...k}),c&&kw({...k}),Aw({...k,apply:({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:a}=t.reference,o=e.floating.style;o.setProperty(`--radix-popper-available-width`,`${n}px`),o.setProperty(`--radix-popper-available-height`,`${r}px`),o.setProperty(`--radix-popper-anchor-width`,`${i}px`),o.setProperty(`--radix-popper-anchor-height`,`${a}px`)}}),b&&Mw({element:b,padding:s}),$w({arrowWidth:C,arrowHeight:w}),f&&jw({strategy:`referenceHidden`,...k})]}),[F,I]=eT(M),L=Jn(m);Gn(()=>{N&&L?.()},[N,L]);let R=P.arrow?.x,z=P.arrow?.y,B=P.arrow?.centerOffset!==0,[V,H]=Q.useState();return Gn(()=>{_&&H(window.getComputedStyle(_).zIndex)},[_]),(0,$.jsx)(`div`,{ref:A.setFloating,"data-radix-popper-content-wrapper":``,style:{...j,transform:N?j.transform:`translate(0, -200%)`,minWidth:`max-content`,zIndex:V,"--radix-popper-transform-origin":[P.transformOrigin?.x,P.transformOrigin?.y].join(` `),...P.hide?.referenceHidden&&{visibility:`hidden`,pointerEvents:`none`}},dir:e.dir,children:(0,$.jsx)(Kw,{scope:n,placedSide:F,onArrowChange:x,arrowX:R,arrowY:z,shouldHideArrow:B,children:(0,$.jsx)(Un.div,{"data-side":F,"data-align":I,...h,ref:y,style:{...h.style,animation:N?void 0:`none`}})})})});Jw.displayName=Gw;var Yw=`PopperArrow`,Xw={top:`bottom`,right:`left`,bottom:`top`,left:`right`},Zw=Q.forwardRef(function(e,t){let{__scopePopper:n,...r}=e,i=qw(Yw,n),a=Xw[i.placedSide];return(0,$.jsx)(`span`,{ref:i.onArrowChange,style:{position:`absolute`,left:i.arrowX,top:i.arrowY,[a]:0,transformOrigin:{top:``,right:`0 0`,bottom:`center 0`,left:`100% 0`}[i.placedSide],transform:{top:`translateY(100%)`,right:`translateY(50%) rotate(90deg) translateX(-50%)`,bottom:`rotate(180deg)`,left:`translateY(50%) rotate(-90deg) translateX(50%)`}[i.placedSide],visibility:i.shouldHideArrow?`hidden`:void 0},children:(0,$.jsx)(Fw,{...r,ref:t,style:{...r.style,display:`block`}})})});Zw.displayName=Yw;function Qw(e){return e!==null}var $w=e=>({name:`transformOrigin`,options:e,fn(t){let{placement:n,rects:r,middlewareData:i}=t,a=i.arrow?.centerOffset!==0,o=a?0:e.arrowWidth,s=a?0:e.arrowHeight,[c,l]=eT(n),u={start:`0%`,center:`50%`,end:`100%`}[l],d=(i.arrow?.x??0)+o/2,f=(i.arrow?.y??0)+s/2,p=``,m=``;return c===`bottom`?(p=a?u:`${d}px`,m=`${-s}px`):c===`top`?(p=a?u:`${d}px`,m=`${r.floating.height+s}px`):c===`right`?(p=`${-s}px`,m=a?u:`${f}px`):c===`left`&&(p=`${r.floating.width+s}px`,m=a?u:`${f}px`),{data:{x:p,y:m}}}});function eT(e){let[t,n=`center`]=e.split(`-`);return[t,n]}var tT=Hw,nT=Ww,rT=Jw,iT=Zw;function aT(e){let t=oT(e),n=Q.forwardRef((e,n)=>{let{children:r,...i}=e,a=Q.Children.toArray(r),o=a.find(cT);if(o){let e=o.props.children,r=a.map(t=>t===o?Q.Children.count(e)>1?Q.Children.only(null):Q.isValidElement(e)?e.props.children:null:t);return(0,$.jsx)(t,{...i,ref:n,children:Q.isValidElement(e)?Q.cloneElement(e,void 0,r):null})}return(0,$.jsx)(t,{...i,ref:n,children:r})});return n.displayName=`${e}.Slot`,n}function oT(e){let t=Q.forwardRef((e,t)=>{let{children:n,...r}=e;if(Q.isValidElement(n)){let e=uT(n),i=lT(r,n.props);return n.type!==Q.Fragment&&(i.ref=t?or(t,e):e),Q.cloneElement(n,i)}return Q.Children.count(n)>1?Q.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var sT=Symbol(`radix.slottable`);function cT(e){return Q.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===sT}function lT(e,t){let n={...t};for(let r in t){let i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...e)=>{let t=a(...e);return i(...e),t}:i&&(n[r]=i):r===`style`?n[r]={...i,...a}:r===`className`&&(n[r]=[i,a].filter(Boolean).join(` `))}return{...e,...n}}function uT(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}function dT(e){let t=Q.useRef({value:e,previous:e});return Q.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var fT=Object.freeze({position:`absolute`,border:0,width:1,height:1,padding:0,margin:-1,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,wordWrap:`normal`}),pT=`VisuallyHidden`,mT=Q.forwardRef((e,t)=>(0,$.jsx)(Un.span,{...e,ref:t,style:{...fT,...e.style}}));mT.displayName=pT;var hT=mT,gT=[` `,`Enter`,`ArrowUp`,`ArrowDown`],_T=[` `,`Enter`],vT=`Select`,[yT,bT,xT]=vS(vT),[ST,CT]=Wn(vT,[xT,zw]),wT=zw(),[TT,ET]=ST(vT),[DT,OT]=ST(vT),kT=e=>{let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:a,value:o,defaultValue:s,onValueChange:c,dir:l,name:u,autoComplete:d,disabled:f,required:p,form:m}=e,h=wT(t),[g,_]=Q.useState(null),[v,y]=Q.useState(null),[b,x]=Q.useState(!1),S=bS(l),[C,w]=_r({prop:r,defaultProp:i??!1,onChange:a,caller:vT}),[T,E]=_r({prop:o,defaultProp:s,onChange:c,caller:vT}),D=Q.useRef(null),O=!g||m||!!g.closest(`form`),[k,A]=Q.useState(new Set),j=Array.from(k).map(e=>e.props.value).join(`;`);return(0,$.jsx)(tT,{...h,children:(0,$.jsxs)(TT,{required:p,scope:t,trigger:g,onTriggerChange:_,valueNode:v,onValueNodeChange:y,valueNodeHasChildren:b,onValueNodeHasChildrenChange:x,contentId:Yn(),value:T,onValueChange:E,open:C,onOpenChange:w,dir:S,triggerPointerDownPosRef:D,disabled:f,children:[(0,$.jsx)(yT.Provider,{scope:t,children:(0,$.jsx)(DT,{scope:e.__scopeSelect,onNativeOptionAdd:Q.useCallback(e=>{A(t=>new Set(t).add(e))},[]),onNativeOptionRemove:Q.useCallback(e=>{A(t=>{let n=new Set(t);return n.delete(e),n})},[]),children:n})}),O?(0,$.jsxs)(wE,{"aria-hidden":!0,required:p,tabIndex:-1,name:u,autoComplete:d,value:T,onChange:e=>E(e.target.value),disabled:f,form:m,children:[T===void 0?(0,$.jsx)(`option`,{value:``}):null,Array.from(k)]},j):null]})})};kT.displayName=vT;var AT=`SelectTrigger`,jT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,disabled:r=!1,...i}=e,a=wT(n),o=ET(AT,n),s=o.disabled||r,c=Hn(t,o.onTriggerChange),l=bT(n),u=Q.useRef(`touch`),[d,f,p]=EE(e=>{let t=l().filter(e=>!e.disabled),n=DE(t,e,t.find(e=>e.value===o.value));n!==void 0&&o.onValueChange(n.value)}),m=e=>{s||(o.onOpenChange(!0),p()),e&&(o.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})};return(0,$.jsx)(nT,{asChild:!0,...a,children:(0,$.jsx)(Un.button,{type:`button`,role:`combobox`,"aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":`none`,dir:o.dir,"data-state":o.open?`open`:`closed`,disabled:s,"data-disabled":s?``:void 0,"data-placeholder":TE(o.value)?``:void 0,...i,ref:c,onClick:qn(i.onClick,e=>{e.currentTarget.focus(),u.current!==`mouse`&&m(e)}),onPointerDown:qn(i.onPointerDown,e=>{u.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(m(e),e.preventDefault())}),onKeyDown:qn(i.onKeyDown,e=>{let t=d.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&f(e.key),!(t&&e.key===` `)&&gT.includes(e.key)&&(m(),e.preventDefault())})})})});jT.displayName=AT;var MT=`SelectValue`,NT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,children:a,placeholder:o=``,...s}=e,c=ET(MT,n),{onValueNodeHasChildrenChange:l}=c,u=a!==void 0,d=Hn(t,c.onValueNodeChange);return Gn(()=>{l(u)},[l,u]),(0,$.jsx)(Un.span,{...s,ref:d,style:{pointerEvents:`none`},children:TE(c.value)?(0,$.jsx)($.Fragment,{children:o}):a})});NT.displayName=MT;var PT=`SelectIcon`,FT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,children:r,...i}=e;return(0,$.jsx)(Un.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})});FT.displayName=PT;var IT=`SelectPortal`,LT=e=>(0,$.jsx)(yr,{asChild:!0,...e});LT.displayName=IT;var RT=`SelectContent`,zT=Q.forwardRef((e,t)=>{let n=ET(RT,e.__scopeSelect),[r,i]=Q.useState();if(Gn(()=>{i(new DocumentFragment)},[]),!n.open){let t=r;return t?Hb.createPortal((0,$.jsx)(VT,{scope:e.__scopeSelect,children:(0,$.jsx)(yT.Slot,{scope:e.__scopeSelect,children:(0,$.jsx)(`div`,{children:e.children})})}),t):null}return(0,$.jsx)(GT,{...e,ref:t})});zT.displayName=RT;var BT=10,[VT,HT]=ST(RT),UT=`SelectContentImpl`,WT=aT(`SelectContent.RemoveScroll`),GT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,position:r=`item-aligned`,onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g,..._}=e,v=ET(RT,n),[y,b]=Q.useState(null),[x,S]=Q.useState(null),C=Hn(t,e=>b(e)),[w,T]=Q.useState(null),[E,D]=Q.useState(null),O=bT(n),[k,A]=Q.useState(!1),j=Q.useRef(!1);Q.useEffect(()=>{if(y)return rr(y)},[y]),Xn();let M=Q.useCallback(e=>{let[t,...n]=O().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&x&&(x.scrollTop=0),n===r&&x&&(x.scrollTop=x.scrollHeight),n?.focus(),document.activeElement!==i))return},[O,x]),N=Q.useCallback(()=>M([w,y]),[M,w,y]);Q.useEffect(()=>{k&&N()},[k,N]);let{onOpenChange:P,triggerPointerDownPosRef:F}=v;Q.useEffect(()=>{if(y){let e={x:0,y:0},t=t=>{e={x:Math.abs(Math.round(t.pageX)-(F.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(F.current?.y??0))}},n=n=>{e.x<=10&&e.y<=10?n.preventDefault():y.contains(n.target)||P(!1),document.removeEventListener(`pointermove`,t),F.current=null};return F.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[y,P,F]),Q.useEffect(()=>{let e=()=>P(!1);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[P]);let[I,L]=EE(e=>{let t=O().filter(e=>!e.disabled),n=DE(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current.focus())}),R=Q.useCallback((e,t,n)=>{let r=!j.current&&!n;(v.value!==void 0&&v.value===t||r)&&(T(e),r&&(j.current=!0))},[v.value]),z=Q.useCallback(()=>y?.focus(),[y]),B=Q.useCallback((e,t,n)=>{let r=!j.current&&!n;(v.value!==void 0&&v.value===t||r)&&D(e)},[v.value]),V=r===`popper`?YT:qT,H=V===YT?{side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g}:{};return(0,$.jsx)(VT,{scope:n,content:y,viewport:x,onViewportChange:S,itemRefCallback:R,selectedItem:w,onItemLeave:z,itemTextRefCallback:B,focusSelectedItem:N,selectedItemText:E,position:r,isPositioned:k,searchRef:I,children:(0,$.jsx)(nr,{as:WT,allowPinchZoom:!0,children:(0,$.jsx)(Qn,{asChild:!0,trapped:v.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:qn(i,e=>{v.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,$.jsx)(vr,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>v.onOpenChange(!1),children:(0,$.jsx)(V,{role:`listbox`,id:v.contentId,"data-state":v.open?`open`:`closed`,dir:v.dir,onContextMenu:e=>e.preventDefault(),..._,...H,onPlaced:()=>A(!0),ref:C,style:{display:`flex`,flexDirection:`column`,outline:`none`,..._.style},onKeyDown:qn(_.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&L(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=O().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>M(t)),e.preventDefault()}})})})})})})});GT.displayName=UT;var KT=`SelectItemAlignedPosition`,qT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,onPlaced:r,...i}=e,a=ET(RT,n),o=HT(RT,n),[s,c]=Q.useState(null),[l,u]=Q.useState(null),d=Hn(t,e=>u(e)),f=bT(n),p=Q.useRef(!1),m=Q.useRef(!0),{viewport:h,selectedItem:g,selectedItemText:_,focusSelectedItem:v}=o,y=Q.useCallback(()=>{if(a.trigger&&a.valueNode&&s&&l&&h&&g&&_){let e=a.trigger.getBoundingClientRect(),t=l.getBoundingClientRect(),n=a.valueNode.getBoundingClientRect(),i=_.getBoundingClientRect();if(a.dir!==`rtl`){let r=i.left-t.left,a=n.left-r,o=e.left-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-BT,d=dS(a,[BT,Math.max(BT,u-l)]);s.style.minWidth=c+`px`,s.style.left=d+`px`}else{let r=t.right-i.right,a=window.innerWidth-n.right-r,o=window.innerWidth-e.right-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-BT,d=dS(a,[BT,Math.max(BT,u-l)]);s.style.minWidth=c+`px`,s.style.right=d+`px`}let o=f(),c=window.innerHeight-BT*2,u=h.scrollHeight,d=window.getComputedStyle(l),m=parseInt(d.borderTopWidth,10),v=parseInt(d.paddingTop,10),y=parseInt(d.borderBottomWidth,10),b=parseInt(d.paddingBottom,10),x=m+v+u+b+y,S=Math.min(g.offsetHeight*5,x),C=window.getComputedStyle(h),w=parseInt(C.paddingTop,10),T=parseInt(C.paddingBottom,10),E=e.top+e.height/2-BT,D=c-E,O=g.offsetHeight/2,k=g.offsetTop+O,A=m+v+k,j=x-A;if(A<=E){let e=o.length>0&&g===o[o.length-1].ref.current;s.style.bottom=`0px`;let t=l.clientHeight-h.offsetTop-h.offsetHeight,n=A+Math.max(D,O+(e?T:0)+t+y);s.style.height=n+`px`}else{let e=o.length>0&&g===o[0].ref.current;s.style.top=`0px`;let t=Math.max(E,m+h.offsetTop+(e?w:0)+O)+j;s.style.height=t+`px`,h.scrollTop=A-E+h.offsetTop}s.style.margin=`${BT}px 0`,s.style.minHeight=S+`px`,s.style.maxHeight=c+`px`,r?.(),requestAnimationFrame(()=>p.current=!0)}},[f,a.trigger,a.valueNode,s,l,h,g,_,a.dir,r]);Gn(()=>y(),[y]);let[b,x]=Q.useState();return Gn(()=>{l&&x(window.getComputedStyle(l).zIndex)},[l]),(0,$.jsx)(XT,{scope:n,contentWrapper:s,shouldExpandOnScrollRef:p,onScrollButtonChange:Q.useCallback(e=>{e&&m.current===!0&&(y(),v?.(),m.current=!1)},[y,v]),children:(0,$.jsx)(`div`,{ref:c,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:b},children:(0,$.jsx)(Un.div,{...i,ref:d,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})});qT.displayName=KT;var JT=`SelectPopperPosition`,YT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,align:r=`start`,collisionPadding:i=BT,...a}=e,o=wT(n);return(0,$.jsx)(rT,{...o,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})});YT.displayName=JT;var[XT,ZT]=ST(RT,{}),QT=`SelectViewport`,$T=Q.forwardRef((e,t)=>{let{__scopeSelect:n,nonce:r,...i}=e,a=HT(QT,n),o=ZT(QT,n),s=Hn(t,a.onViewportChange),c=Q.useRef(0);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:r}),(0,$.jsx)(yT.Slot,{scope:n,children:(0,$.jsx)(Un.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:s,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:qn(i.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=o;if(r?.current&&n){let e=Math.abs(c.current-t.scrollTop);if(e>0){let r=window.innerHeight-BT*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}c.current=t.scrollTop})})})]})});$T.displayName=QT;var eE=`SelectGroup`,[tE,nE]=ST(eE),rE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=Yn();return(0,$.jsx)(tE,{scope:n,id:i,children:(0,$.jsx)(Un.div,{role:`group`,"aria-labelledby":i,...r,ref:t})})});rE.displayName=eE;var iE=`SelectLabel`,aE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=nE(iE,n);return(0,$.jsx)(Un.div,{id:i.id,...r,ref:t})});aE.displayName=iE;var oE=`SelectItem`,[sE,cE]=ST(oE),lE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...o}=e,s=ET(oE,n),c=HT(oE,n),l=s.value===r,[u,d]=Q.useState(a??``),[f,p]=Q.useState(!1),m=Hn(t,e=>c.itemRefCallback?.(e,r,i)),h=Yn(),g=Q.useRef(`touch`),_=()=>{i||(s.onValueChange(r),s.onOpenChange(!1))};if(r===``)throw Error(`A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.`);return(0,$.jsx)(sE,{scope:n,value:r,disabled:i,textId:h,isSelected:l,onItemTextChange:Q.useCallback(e=>{d(t=>t||(e?.textContent??``).trim())},[]),children:(0,$.jsx)(yT.ItemSlot,{scope:n,value:r,disabled:i,textValue:u,children:(0,$.jsx)(Un.div,{role:`option`,"aria-labelledby":h,"data-highlighted":f?``:void 0,"aria-selected":l&&f,"data-state":l?`checked`:`unchecked`,"aria-disabled":i||void 0,"data-disabled":i?``:void 0,tabIndex:i?void 0:-1,...o,ref:m,onFocus:qn(o.onFocus,()=>p(!0)),onBlur:qn(o.onBlur,()=>p(!1)),onClick:qn(o.onClick,()=>{g.current!==`mouse`&&_()}),onPointerUp:qn(o.onPointerUp,()=>{g.current===`mouse`&&_()}),onPointerDown:qn(o.onPointerDown,e=>{g.current=e.pointerType}),onPointerMove:qn(o.onPointerMove,e=>{g.current=e.pointerType,i?c.onItemLeave?.():g.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:qn(o.onPointerLeave,e=>{e.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:qn(o.onKeyDown,e=>{c.searchRef?.current!==``&&e.key===` `||(_T.includes(e.key)&&_(),e.key===` `&&e.preventDefault())})})})})});lE.displayName=oE;var uE=`SelectItemText`,dE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,...a}=e,o=ET(uE,n),s=HT(uE,n),c=cE(uE,n),l=OT(uE,n),[u,d]=Q.useState(null),f=Hn(t,e=>d(e),c.onItemTextChange,e=>s.itemTextRefCallback?.(e,c.value,c.disabled)),p=u?.textContent,m=Q.useMemo(()=>(0,$.jsx)(`option`,{value:c.value,disabled:c.disabled,children:p},c.value),[c.disabled,c.value,p]),{onNativeOptionAdd:h,onNativeOptionRemove:g}=l;return Gn(()=>(h(m),()=>g(m)),[h,g,m]),(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Un.span,{id:c.textId,...a,ref:f}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren?Hb.createPortal(a.children,o.valueNode):null]})});dE.displayName=uE;var fE=`SelectItemIndicator`,pE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return cE(fE,n).isSelected?(0,$.jsx)(Un.span,{"aria-hidden":!0,...r,ref:t}):null});pE.displayName=fE;var mE=`SelectScrollUpButton`,hE=Q.forwardRef((e,t)=>{let n=HT(mE,e.__scopeSelect),r=ZT(mE,e.__scopeSelect),[i,a]=Q.useState(!1),o=Hn(t,r.onScrollButtonChange);return Gn(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollTop>0;a(e)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,$.jsx)(vE,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null});hE.displayName=mE;var gE=`SelectScrollDownButton`,_E=Q.forwardRef((e,t)=>{let n=HT(gE,e.__scopeSelect),r=ZT(gE,e.__scopeSelect),[i,a]=Q.useState(!1),o=Hn(t,r.onScrollButtonChange);return Gn(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollHeight-t.clientHeight,n=Math.ceil(t.scrollTop)<e;a(n)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,$.jsx)(vE,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null});_E.displayName=gE;var vE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,onAutoScroll:r,...i}=e,a=HT(`SelectScrollButton`,n),o=Q.useRef(null),s=bT(n),c=Q.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return Q.useEffect(()=>()=>c(),[c]),Gn(()=>{s().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[s]),(0,$.jsx)(Un.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:qn(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:qn(i.onPointerMove,()=>{a.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:qn(i.onPointerLeave,()=>{c()})})}),yE=`SelectSeparator`,bE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return(0,$.jsx)(Un.div,{"aria-hidden":!0,...r,ref:t})});bE.displayName=yE;var xE=`SelectArrow`,SE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=wT(n),a=ET(xE,n),o=HT(xE,n);return a.open&&o.position===`popper`?(0,$.jsx)(iT,{...i,...r,ref:t}):null});SE.displayName=xE;var CE=`SelectBubbleInput`,wE=Q.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{let i=Q.useRef(null),a=Hn(r,i),o=dT(t);return Q.useEffect(()=>{let e=i.current;if(!e)return;let n=window.HTMLSelectElement.prototype,r=Object.getOwnPropertyDescriptor(n,`value`).set;if(o!==t&&r){let n=new Event(`change`,{bubbles:!0});r.call(e,t),e.dispatchEvent(n)}},[o,t]),(0,$.jsx)(Un.select,{...n,style:{...fT,...n.style},ref:a,defaultValue:t})});wE.displayName=CE;function TE(e){return e===``||e===void 0}function EE(e){let t=Jn(e),n=Q.useRef(``),r=Q.useRef(0),i=Q.useCallback(e=>{let i=n.current+e;t(i),(function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))})(i)},[t]),a=Q.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return Q.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}function DE(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=OE(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}function OE(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var kE=kT,AE=jT,jE=NT,ME=FT,NE=LT,PE=zT,FE=$T,IE=aE,LE=lE,RE=dE,zE=pE,BE=hE,VE=_E,HE=bE,UE=`flex min-w-0 items-center gap-1.5 rounded-md px-1.5 py-1 text-sm font-medium text-foreground outline-none transition-colors hover:bg-surface/70 focus-visible:ring-2 focus-visible:ring-accent-primary/50 disabled:cursor-not-allowed disabled:opacity-50`,WE=`overflow-hidden rounded-xl border border-border/60 bg-card/95 shadow-2xl backdrop-blur-xl`,GE=`flex w-full items-center gap-2.5 px-3 py-1.5 text-left text-sm text-foreground outline-none hover:bg-surface/70 focus-visible:bg-surface/70`;function KE({label:e,value:t,options:n,icon:r,onSelect:i,placeholder:a,disabled:o=!1,testId:s}){return(0,$.jsxs)(kE,{value:t,onValueChange:i,disabled:o||n.length===0,children:[(0,$.jsxs)(AE,{"aria-label":e,title:e,"data-agent-interactive":!0,"data-testid":s,className:UE,children:[(0,$.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-accent-primary`,"aria-hidden":!0}),(0,$.jsx)(jE,{placeholder:a??e,className:`max-w-[160px] truncate`}),(0,$.jsx)(ME,{asChild:!0,children:(0,$.jsx)(Xo,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`})})]}),(0,$.jsx)(NE,{children:(0,$.jsxs)(PE,{position:`popper`,side:`top`,align:`start`,sideOffset:4,collisionPadding:8,className:`z-[80] min-w-[12rem] max-w-[20rem] ${WE} data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 data-[state=open]:zoom-in-95 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-1 data-[side=top]:slide-in-from-bottom-1`,children:[(0,$.jsx)(BE,{className:`flex items-center justify-center py-1 text-foreground/50`,children:(0,$.jsx)(gn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(FE,{className:`max-h-72 py-1`,children:n.map(e=>{let t=e.icon??r;return(0,$.jsxs)(LE,{value:e.value,className:`${GE} relative cursor-default select-none pr-9 data-[highlighted]:bg-surface/70 data-[state=checked]:font-medium`,children:[(0,$.jsx)(t,{className:`h-4 w-4 shrink-0 text-accent-primary`,"aria-hidden":!0}),(0,$.jsx)(RE,{children:(0,$.jsx)(`span`,{className:`truncate`,children:e.label})}),(0,$.jsx)(zE,{className:`absolute right-3 flex items-center`,children:(0,$.jsx)(Sn,{className:`h-3.5 w-3.5 text-accent-primary`})})]},e.value)})}),(0,$.jsx)(VE,{className:`flex items-center justify-center py-1 text-foreground/50`,children:(0,$.jsx)(Xo,{className:`h-3.5 w-3.5`})})]})})]})}var qE=`__new__`,JE=`__legacy__`,YE=`__default__`,XE=12,ZE=`specrails:focus-pr-card`,QE=(0,Q.lazy)(()=>c(()=>import(`./JobDetailModal-DHeur9YK.js`).then(e=>({default:e.JobDetailModal})),__vite__mapDeps([6,1,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80])));function $E(e,t,n){if(e.availability)return e.availability;let r=String(e.railIndex);if(t.activeJobs?.[r]||t.activeLoopRuns?.[r])return`busy`;let i=t.prDeliveries?.[r];return i&&i.decision&&![`merged`,`discarded`,`completed`,`superseded`,`pr_ready`].includes(i.decision)?`pending_decision`:e.ticketIds.some(e=>n.find(t=>t.id===e)?.status===`on_review`)?`on_review`:`free`}function eD(e,t){let n=e(`railCard.rail`,{index:t.railIndex+1});return t.name?`${n} · ${t.name}`:n}function tD({proposal:e,proposalIndex:t,messageId:n,conversationId:r,projectId:i,intent:a,compact:o=!1}){let{t:s}=K(`agent`),c=My(),l=Zx(),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)([]),[g,_]=(0,Q.useState)([]),[v,y]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{if(!i||a)return;let e=!1,t=`${Xe}/api/projects/${encodeURIComponent(i)}`;return Promise.all([fetch(`${t}/rails`).then(e=>e.ok?e.json():Promise.reject(Error(String(e.status)))),fetch(`${t}/tickets`).then(e=>e.ok?e.json():Promise.reject(Error(String(e.status))))]).then(([t,n])=>{e||(d(t&&typeof t==`object`?t:{}),p(Array.isArray(n?.tickets)?n.tickets:[]))}).catch(()=>{e||y(!0)}),ke&&sS.list().then(t=>{e||_(t.filter(e=>e.status===`published`&&uS(e.graph)))}).catch(()=>{}),()=>{e=!0}},[i,a]);let[b,x]=(0,Q.useState)(()=>({railIndex:e.railIndex,newRail:!!e.newRail,railName:e.newRail?.name??e.railName??``,ticketIds:e.ticketIds,loopId:e.loopId??nS(null,e.mode),aiEngine:e.aiEngine,model:e.model,reasoningEffort:e.reasoningEffort,profileName:e.profileName,targetPrNumber:e.targetPrNumber,baseBranch:e.baseBranch??``,followUp:e.followUp??null})),S=(0,Q.useCallback)(e=>x(t=>({...t,...e})),[]),C=l.detected,w=!l.loading,T=(0,Q.useMemo)(()=>b.aiEngine&&(wt(b.aiEngine)||C.includes(b.aiEngine))?b.aiEngine:C[0]??null,[b.aiEngine,C]),E=!!b.aiEngine&&w&&T!==b.aiEngine,D=!!T&&wt(T),O=T&&!wt(T)?T:C[0]??null,k=(0,Q.useMemo)(()=>Jx(O),[O]),j=(0,Q.useMemo)(()=>b.model&&k.some(e=>e.value===b.model)?b.model:Yx(O)||null,[b.model,k,O]),M=!!b.model&&k.length>0&&j!==b.model,N=(0,Q.useMemo)(()=>vt(O,j),[O,j]),P=b.reasoningEffort&&N.includes(b.reasoningEffort)?b.reasoningEffort:null,F=tS(b.loopId),I=!D&&F!==`loop`&&xt(O);(0,Q.useEffect)(()=>{if(!i||a||!O||!I){h([]);return}let e=!1;return fetch(`${Xe}/api/projects/${encodeURIComponent(i)}/profiles?provider=${encodeURIComponent(O)}`).then(e=>e.ok?e.json():{profiles:[]}).then(t=>{if(e)return;let n=Array.isArray(t.profiles)?t.profiles.filter(e=>!e.provider||e.provider===O):[];h(n)}).catch(()=>{e||h([])}),()=>{e=!0}},[i,a,O,I]);let L=b.profileName&&m.some(e=>e.name===b.profileName)?b.profileName:null,R=(0,Q.useMemo)(()=>u?.rails??[],[u]),z=(0,Q.useMemo)(()=>{let e=new Map;if(!u)return e;for(let t of R)e.set(t.railIndex,$E(t,u,f??[]));return e},[R,u,f]),V=b.railIndex===null?void 0:R.find(e=>e.railIndex===b.railIndex),H=u!==null&&b.railIndex!==null&&!b.newRail&&!V,U=!!V&&!b.newRail&&z.get(V.railIndex)!==`free`&&z.get(V.railIndex)!==void 0,W=R.length>=XE,ee=R.find(e=>z.get(e.railIndex)===`free`),te=b.newRail?qE:b.railIndex!==null&&V?String(b.railIndex):ee?String(ee.railIndex):W?``:qE,ne=b.newRail||te===qE||te===``?null:Number(te),re=te===qE,ie=(0,Q.useMemo)(()=>new Map((f??[]).map(e=>[e.id,e])),[f]),ae=(0,Q.useMemo)(()=>f?b.ticketIds.filter(e=>ie.has(e)):b.ticketIds,[b.ticketIds,ie,f]),oe=f?b.ticketIds.filter(e=>!ie.has(e)):[],se=(0,Q.useMemo)(()=>ae.flatMap(e=>he(ie.get(e)?.addenda).map(t=>({ticketId:e,title:t.title}))),[ae,ie]),ce=se.length,le=se.slice(0,3).map(e=>`#${e.ticketId} ${e.title}`),ue=(0,Q.useMemo)(()=>(f??[]).filter(e=>(e.status===`todo`||e.status===`draft`)&&!b.ticketIds.includes(e.id)),[f,b.ticketIds]),de=!D&&bt(O),fe=(0,Q.useMemo)(()=>[...$x.filter(e=>(!e.requiresFreestyle||de)&&(!e.requiresLoops||ke)).map(e=>({value:e.id,label:s(`dashboard:${e.labelKey}`)})),...g.map(e=>({value:e.id,label:e.name}))],[g,de,s]),G=fe.some(e=>e.value===b.loopId)?b.loopId:fe[0]?.value??b.loopId,[pe,me]=(0,Q.useState)(null),[ge,_e]=(0,Q.useState)(null),[ve,ye]=(0,Q.useState)(null),be=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>()=>{be.current=!1},[]);let xe=a??ve,Se=i?v?s(`railCard.block.loadFailed`):ae.length===0?s(`railCard.block.noSpecs`):te===``?s(`railCard.block.railLimit`,{max:XE}):null:s(`railCard.block.noProject`),Ce=(0,Q.useCallback)(async e=>{let t=await Mo(r,n,e),i=t.ok?t.intent:{...e,at:new Date().toISOString()};Vx(n,i),be.current&&ye(i)},[r,n]),we=(0,Q.useCallback)(async()=>{if(!i||Se||pe)return;me(`launch`),_e(null);let e=`${Xe}/api/projects/${encodeURIComponent(i)}/rails`,n={"content-type":`application/json`},a=async e=>{let t={};try{t=await e.json()}catch{}return{error:typeof t.error==`string`?t.error:`HTTP ${e.status}`,detail:typeof t.detail==`string`?t.detail:void 0,action:typeof t.action==`string`?t.action:void 0}};try{let o=ne,s=b.railName.trim().slice(0,60);if(o===null){let t=await fetch(e,{method:`POST`,headers:n,body:JSON.stringify({name:s||null})});if(!t.ok){_e(await a(t));return}let r=await t.json();if(typeof r.rail?.railIndex!=`number`){_e({error:`invalid_response`});return}o=r.rail.railIndex}else if(s&&s!==(V?.name??``)){let t=await fetch(`${e}/${o}/name`,{method:`PUT`,headers:n,body:JSON.stringify({name:s})});if(!t.ok){_e(await a(t));return}}let c=T&&C.length>1?T:void 0,l=await fetch(`${e}/${o}/tickets`,{method:`PUT`,headers:n,body:JSON.stringify({ticketIds:ae,mode:F,profileName:I?L:null,...c?{aiEngine:c}:{}})});if(!l.ok){_e(await a(l));return}let u={mode:F,loopId:G,originConversationId:r,originSurface:`agent-chat`,...c?{aiEngine:c}:{},...!D&&j?{model:j}:{},...!D&&P?{reasoning_effort:P}:{},...I&&L?{profileName:L}:{},...b.targetPrNumber?{targetPrNumber:b.targetPrNumber}:{},...b.baseBranch.trim()?{baseBranch:b.baseBranch.trim()}:{},...b.followUp?{followUp:b.followUp}:{}},d=await fetch(`${e}/${o}/launch`,{method:`POST`,headers:n,body:JSON.stringify(u)});if(!d.ok){_e(await a(d));return}let f=await d.json(),p=Array.isArray(f.loopRunIds)&&f.loopRunIds.length?f.loopRunIds:Array.isArray(f.jobIds)&&f.jobIds.length?f.jobIds:f.jobId?[f.jobId]:[];Ht(i),await Ce({kind:`rail-launch`,proposalIndex:t,status:`launched`,railIndex:o,runIds:p,prDeliveryId:typeof f.prDeliveryId==`string`?f.prDeliveryId:null,config:{...u,ticketIds:ae,railName:s||null}})}catch(e){_e({error:e instanceof Error?e.message:`network`})}finally{be.current&&me(null)}},[i,Se,pe,ne,b,V,T,D,C.length,ae,F,I,L,G,j,P,r,t,Ce]),Te=(0,Q.useCallback)(async()=>{if(!pe){me(`dismiss`);try{await Ce({kind:`rail-launch`,proposalIndex:t,status:`dismissed`})}finally{be.current&&me(null)}}},[pe,Ce,t]),[Ee,De]=(0,Q.useState)(null);if(xe){let t=xe.status===`launched`,n=xe.runIds?.[0]??null;return(0,$.jsxs)(`div`,{"data-testid":t?`agent-rail-launch-stub-launched`:`agent-rail-launch-stub-dismissed`,className:X(`my-1 flex items-center gap-2 rounded-xl border px-3 py-2 text-xs backdrop-blur`,t?`border-accent-success/30 bg-accent-success/[0.06] text-foreground/80`:`border-border/50 bg-surface/40 text-foreground/50`),children:[t?(0,$.jsx)($o,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`}):(0,$.jsx)(Cn,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[t?s(`railCard.stub.launched`,{rail:typeof xe.railIndex==`number`?xe.railIndex+1:`?`}):s(`railCard.stub.dismissed`),` `,(0,$.jsx)(`span`,{className:`text-foreground/50`,children:e.ticketIds.map(e=>`#${e}`).join(` `)})]}),t&&(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`agent-rail-launch-focus-card`,title:s(`railCard.stub.goToCardTitle`),onClick:()=>{window.dispatchEvent(new CustomEvent(ZE,{detail:{prDeliveryId:xe.prDeliveryId??null,runIds:xe.runIds??[]}}))},className:`inline-flex shrink-0 items-center gap-1 rounded-md border border-border/60 bg-card/70 px-2 py-0.5 text-[11px] font-medium text-foreground/70 transition-colors hover:border-accent-primary/40 hover:text-foreground`,children:[(0,$.jsx)(oc,{className:`h-3 w-3`}),s(`railCard.stub.goToCard`)]}),t&&i&&n&&(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`agent-rail-launch-view-run`,title:s(`railCard.stub.viewRunTitle`),onClick:()=>De(n),className:`inline-flex shrink-0 items-center gap-1 rounded-md border border-accent-primary/40 bg-accent-primary/10 px-2 py-0.5 text-[11px] font-medium text-accent-primary transition-colors hover:bg-accent-primary/20`,children:[(0,$.jsx)(pn,{className:`h-3 w-3`}),s(`railCard.stub.viewRun`)]}),Ee&&i&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(QE,{jobId:Ee,projectId:i,onClose:()=>De(null)})})]})}let Oe=[...R.map(e=>{let t=z.get(e.railIndex),n=t&&t!==`free`?` · ${s(`railCard.availability.${t}`)}`:``;return{value:String(e.railIndex),label:`${eD(s,e)}${n}`}}),...W?[]:[{value:qE,label:s(`railCard.newRail`),icon:Pn}]],Ae=[...C.map(e=>({value:e,label:l.providers[e]?.displayName??jt(e)})),...C.length>1?[{value:Mt,label:s(`agents:railSelectors.rolesEngine`),icon:kn}]:[]],je=k.map(e=>({value:e.value,label:e.label??e.value})),Me=[{value:YE,label:s(`railCard.effortDefault`)},...N.map(e=>({value:e,label:s(`effort.${e}`,{defaultValue:e})}))],Ne=[{value:JE,label:s(`railCard.profileNone`)},...m.map(e=>({value:e.name,label:e.name}))],Pe=!!i&&!v&&(u===null||f===null),Fe=Pe?{tone:`border-border/60 bg-surface/60 text-foreground/50`,label:s(`railCard.status.loading`)}:Se?{tone:`border-accent-warning/40 bg-accent-warning/10 text-accent-warning`,label:s(`railCard.status.blocked`)}:{tone:`border-accent-primary/40 bg-accent-primary/10 text-accent-primary`,label:s(`railCard.status.ready`)};return(0,$.jsxs)(Ny.div,{initial:!c&&{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.22,ease:`easeOut`},"data-testid":`agent-rail-launch-card`,className:X(`my-1 overflow-hidden rounded-xl border border-accent-primary/25 bg-card/80 shadow-lg backdrop-blur`,o&&`my-0`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/40 bg-accent-primary/[0.06] px-3.5 py-2`,children:[(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1.5 text-[10px] font-semibold uppercase tracking-widest text-accent-primary/90`,children:[(0,$.jsx)(gc,{className:`h-3 w-3`}),s(`railCard.heading`)]}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-foreground/55`,children:ae.map(e=>`#${e}`).join(` `)}),(0,$.jsx)(`span`,{className:X(`inline-flex shrink-0 items-center rounded-full border px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide`,Fe.tone),children:Fe.label})]}),(0,$.jsxs)(`div`,{className:`space-y-2.5 px-3.5 py-3`,children:[e.rationale&&(0,$.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs italic text-foreground/60`,children:[(0,$.jsx)(Ln,{className:`mt-0.5 h-3 w-3 shrink-0 text-accent-primary/70`}),(0,$.jsx)(`span`,{children:e.rationale})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(KE,{label:s(`railCard.fields.rail`),icon:Mc,value:te,options:Oe,disabled:Pe||!!pe,testId:`rail-card-rail`,onSelect:e=>S(e===qE?{newRail:!0,railIndex:null}:{newRail:!1,railIndex:Number(e)})}),(re||V)&&(0,$.jsx)(`input`,{type:`text`,"data-agent-interactive":!0,"data-testid":`rail-card-name`,value:b.railName,maxLength:60,placeholder:s(re?`railCard.fields.newRailName`:`railCard.fields.railName`),onChange:e=>S({railName:e.target.value}),className:`h-7 min-w-[120px] flex-1 rounded-md border border-border/60 bg-surface/50 px-2 text-xs text-foreground outline-none placeholder:text-foreground/35 focus:border-accent-primary/50`})]}),H&&(0,$.jsx)(nD,{tone:`warning`,text:s(`railCard.notes.railMissing`,{index:(b.railIndex??0)+1})}),U&&V&&(0,$.jsx)(nD,{tone:`warning`,text:s(`railCard.notes.railBusy`,{index:V.railIndex+1,state:s(`railCard.availability.${z.get(V.railIndex)??`busy`}`)}),action:ee?{label:s(`railCard.notes.useFree`,{index:ee.railIndex+1}),onClick:()=>S({newRail:!1,railIndex:ee.railIndex})}:void 0}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,"data-testid":`rail-card-specs`,children:[ae.map(e=>{let t=ie.get(e);return(0,$.jsxs)(`span`,{title:t?.title,className:`inline-flex max-w-[220px] items-center gap-1 rounded-full border border-accent-primary/35 bg-accent-primary/10 py-0.5 pl-2 pr-1 text-[11px] font-medium text-accent-primary`,children:[(0,$.jsxs)(`span`,{className:`truncate`,children:[`#`,e,t?` ${t.title}`:``]}),(0,$.jsx)(`button`,{type:`button`,"data-agent-interactive":!0,"aria-label":s(`railCard.fields.removeSpec`,{id:e}),disabled:!!pe,onClick:()=>S({ticketIds:b.ticketIds.filter(t=>t!==e)}),className:`rounded-full p-0.5 text-accent-primary/60 hover:bg-accent-primary/20 hover:text-accent-primary`,children:(0,$.jsx)(Vn,{className:`h-3 w-3`})})]},e)}),ue.length>0&&(0,$.jsx)(KE,{label:s(`railCard.fields.addSpec`),icon:Pn,value:``,placeholder:s(`railCard.fields.addSpec`),options:ue.slice(0,40).map(e=>({value:String(e.id),label:`#${e.id} ${e.title}`})),disabled:!!pe,testId:`rail-card-add-spec`,onSelect:e=>S({ticketIds:[...b.ticketIds,Number(e)]})})]}),oe.length>0&&(0,$.jsx)(nD,{tone:`muted`,text:s(`railCard.notes.specsDropped`,{ids:oe.map(e=>`#${e}`).join(`, `)})}),ce>0&&(0,$.jsxs)(`div`,{"data-testid":`rail-card-addenda`,className:`flex items-start gap-1.5 rounded-lg border border-accent-primary/25 bg-accent-primary/[0.05] px-2.5 py-1.5 text-[11px] text-foreground/75`,children:[(0,$.jsx)(kn,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-primary/80`}),(0,$.jsxs)(`span`,{children:[s(`railCard.addenda.rides`,{count:ce}),` `,(0,$.jsx)(`span`,{className:`text-foreground/50`,children:le.join(` · `)})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-1 gap-y-1`,children:[(0,$.jsx)(KE,{label:s(`railCard.fields.loop`),icon:Lc,value:G,options:fe,disabled:!!pe,testId:`rail-card-loop`,onSelect:e=>S({loopId:e})}),Ae.length>1&&(0,$.jsx)(KE,{label:s(`railCard.fields.engine`),icon:fs,value:T??``,options:Ae,disabled:!!pe,testId:`rail-card-engine`,onSelect:e=>S({aiEngine:e,model:null,reasoningEffort:null,profileName:null})}),!D&&je.length>0&&(0,$.jsx)(KE,{label:s(`railCard.fields.model`),icon:Uo,value:j??``,options:je,disabled:!!pe,testId:`rail-card-model`,onSelect:e=>S({model:e})}),!D&&N.length>0&&(0,$.jsx)(KE,{label:s(`railCard.fields.effort`),icon:Ds,value:P??YE,options:Me,disabled:!!pe,testId:`rail-card-effort`,onSelect:e=>S({reasoningEffort:e===YE?null:e})}),I&&m.length>0&&(0,$.jsx)(KE,{label:s(`railCard.fields.profile`),icon:Nc,value:L??JE,options:Ne,disabled:!!pe,testId:`rail-card-profile`,onSelect:e=>S({profileName:e===JE?null:e})})]}),E&&(0,$.jsx)(nD,{tone:`muted`,text:s(`railCard.notes.engineStale`,{engine:b.aiEngine,fallback:T?jt(T):``})}),M&&(0,$.jsx)(nD,{tone:`muted`,text:s(`railCard.notes.modelStale`,{model:b.model,fallback:j})}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-foreground/60`,children:[(0,$.jsx)(A,{className:`h-3.5 w-3.5 text-accent-primary/70`}),(0,$.jsx)(`span`,{className:`sr-only`,children:s(`railCard.fields.targetPr`)}),(0,$.jsx)(`input`,{type:`number`,min:1,inputMode:`numeric`,"data-agent-interactive":!0,"data-testid":`rail-card-target-pr`,value:b.targetPrNumber??``,placeholder:s(`railCard.fields.targetPr`),disabled:!!pe,onChange:e=>S({targetPrNumber:e.target.value?Math.max(1,Math.floor(Number(e.target.value))):null}),className:`h-7 w-28 rounded-md border border-border/60 bg-surface/50 px-2 text-xs text-foreground outline-none placeholder:text-foreground/35 focus:border-accent-primary/50`})]}),(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-foreground/60`,children:[(0,$.jsx)(On,{className:`h-3.5 w-3.5 text-accent-primary/70`}),(0,$.jsx)(`span`,{className:`sr-only`,children:s(`railCard.fields.baseBranch`)}),(0,$.jsx)(`input`,{type:`text`,"data-agent-interactive":!0,"data-testid":`rail-card-base-branch`,value:b.baseBranch,placeholder:s(`railCard.fields.baseBranch`),disabled:!!pe,onChange:e=>S({baseBranch:e.target.value}),className:`h-7 w-40 rounded-md border border-border/60 bg-surface/50 px-2 text-xs text-foreground outline-none placeholder:text-foreground/35 focus:border-accent-primary/50`})]})]}),b.followUp&&(0,$.jsxs)(`div`,{"data-testid":`rail-card-follow-up`,className:`rounded-lg border border-accent-primary/25 bg-accent-primary/[0.05] px-2.5 py-2 text-xs`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-medium text-foreground/85`,children:[(0,$.jsx)(B,{className:`h-3.5 w-3.5 text-accent-primary/80`}),s(`railCard.followUp.title`,{count:b.followUp.comments.length})]}),(0,$.jsx)(`span`,{className:`text-foreground/55`,children:b.followUp.scope.objective})]}),(0,$.jsx)(`ul`,{className:`mt-1.5 space-y-1`,children:b.followUp.comments.map(e=>(0,$.jsxs)(`li`,{className:`flex gap-2 text-foreground/75`,children:[(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-surface/70 px-1 font-mono text-[10px] text-foreground/60`,children:e.id}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[e.path?(0,$.jsxs)(`span`,{className:`font-mono text-[11px] text-accent-info`,children:[e.path,e.line?`:${e.line}`:``,` · `]}):null,(0,$.jsx)(`span`,{className:`line-clamp-2`,children:e.body}),(0,$.jsx)(`span`,{className:`ml-1 text-[10px] text-foreground/45`,children:s(`railCard.followUp.source.${e.source===`github`?`github`:`pasted`}`)})]})]},e.id))}),b.followUp.scope.excludedChanges.length>0&&(0,$.jsxs)(`div`,{className:`mt-1.5 text-foreground/60`,children:[(0,$.jsxs)(`span`,{className:`font-medium`,children:[s(`railCard.followUp.excluded`),`:`]}),` `,b.followUp.scope.excludedChanges.join(` · `)]}),b.followUp.scope.verification.length>0&&(0,$.jsxs)(`div`,{className:`mt-1 text-foreground/60`,children:[(0,$.jsxs)(`span`,{className:`font-medium`,children:[s(`railCard.followUp.verification`),`:`]}),` `,b.followUp.scope.verification.join(` · `)]}),(0,$.jsx)(`div`,{className:`mt-1.5 text-[11px] text-foreground/45`,children:s(`railCard.followUp.specUntouched`)})]}),ge&&(0,$.jsxs)(`div`,{"data-testid":`rail-card-error`,className:`flex items-start gap-2 rounded-lg border border-destructive/35 bg-destructive/10 px-2.5 py-1.5 text-xs text-destructive`,children:[(0,$.jsx)(zn,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`font-medium`,children:s(`railCard.errors.${ge.error}`,{defaultValue:ge.error})}),ge.detail&&(0,$.jsx)(`div`,{className:`text-destructive/80`,children:ge.detail}),ge.action&&(0,$.jsx)(`div`,{className:`text-foreground/70`,children:ge.action})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-0.5`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-foreground/45`,children:Se??s(`railCard.playHint`)}),(0,$.jsx)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`rail-card-dismiss`,disabled:!!pe,onClick:()=>void Te(),className:`rounded-md px-2 py-1 text-xs text-foreground/60 transition-colors hover:bg-surface hover:text-foreground disabled:opacity-50`,children:s(`railCard.dismiss`)}),(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`rail-card-play`,disabled:!!pe||Pe||!!Se,onClick:()=>void we(),className:`inline-flex items-center gap-1.5 rounded-md bg-accent-primary px-3 py-1 text-xs font-semibold text-white shadow transition-colors hover:bg-accent-primary/90 disabled:cursor-not-allowed disabled:opacity-50`,children:[pe===`launch`?(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Mn,{className:`h-3.5 w-3.5`}),s(pe===`launch`?`railCard.launching`:`railCard.play`)]})]})]})]})}function nD({tone:e,text:t,action:n}){return(0,$.jsxs)(`div`,{className:X(`flex items-center gap-2 rounded-lg border px-2.5 py-1 text-[11px]`,e===`warning`?`border-accent-warning/35 bg-accent-warning/10 text-accent-warning`:`border-border/50 bg-surface/40 text-foreground/55`),children:[e===`warning`&&(0,$.jsx)(zn,{className:`h-3 w-3 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:t}),n&&(0,$.jsx)(`button`,{type:`button`,"data-agent-interactive":!0,onClick:n.onClick,className:`shrink-0 rounded px-1.5 py-0.5 font-medium underline-offset-2 hover:underline`,children:n.label})]})}function rD(){let{t:e}=K(`agent`);return(0,$.jsxs)(`div`,{"data-testid":`agent-rail-launch-pending`,className:`my-1 inline-flex items-center gap-1.5 rounded-full border border-accent-primary/30 bg-accent-primary/10 px-2.5 py-1 text-[11px] text-accent-primary`,children:[(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`}),e(`railCard.pending`)]})}function iD({excerpts:e}){let{t}=K(`agent`);return(0,$.jsxs)(`div`,{"data-testid":`agent-rail-launch-unreadable`,title:e.join(`
|
|
34
34
|
`),className:`my-1 inline-flex items-center gap-1.5 rounded-lg border border-border/50 bg-surface/40 px-2.5 py-1 text-[11px] text-foreground/55`,children:[(0,$.jsx)(zn,{className:`h-3 w-3 shrink-0 text-accent-warning/80`}),t(`railCard.unreadable`,{count:e.length})]})}var aD=/```problem-frame[^\S\n]*\n([\s\S]*?)\n[^\S\n]*```/g,oD="```problem-frame";function sD(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function cD(e){if(!e||typeof e!=`object`||Array.isArray(e))return null;let t=e;return typeof t.reading!=`string`||!t.reading.trim()?null:{reading:t.reading,touches:sD(t.touches)}}function lD(e){let t;try{t=JSON.parse(e)}catch{return null}if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t,r=cD(n.restated),i=cD(n.alternative);return!r||!i||typeof n.discriminator!=`string`||!n.discriminator.trim()||r.reading.trim()===i.reading.trim()?null:{restated:r,alternative:i,discriminator:n.discriminator,assumptions:sD(n.assumptions),unknowns:sD(n.unknowns)}}function uD(e){return e.replace(/\n{3,}/g,`
|
|
35
35
|
|
|
36
36
|
`).trim()}function dD(e,t=!1){if(!e.includes(oD))return{body:e,frame:null,pending:!1};let n=null,r=``,i=0;aD.lastIndex=0;let a;for(;(a=aD.exec(e))!==null;){r+=e.slice(i,a.index),i=a.index+a[0].length;let t=lD(a[1]);t&&(n=t)}r+=e.slice(i);let o=!1,s=r.indexOf(oD);if(s!==-1){let e=lD(r.slice(s+16).replace(/^[^\S\n]*\n?/,``).replace(/\s*(?:```)?\s*$/,``));e?(n=e,r=r.slice(0,s)):t&&(r=r.slice(0,s),o=!0)}return{body:uD(r),frame:n,pending:o}}var fD=`flex min-w-0 flex-col gap-1.5 rounded-lg border border-border/50 bg-surface/50 p-2.5 text-left`;function pD({label:e,value:t,testId:n,onSelect:r,disabled:i}){let{t:a}=K(`agent`),o=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground/50`,children:e}),(0,$.jsx)(`div`,{className:`text-xs leading-5 text-foreground/90`,children:t.reading}),t.touches.length>0&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 pt-0.5`,children:[(0,$.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground/40`,children:a(`problemFrame.touches`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.touches.map((e,t)=>(0,$.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1 rounded border border-border/50 bg-background-deep/40 px-1.5 py-0.5 font-mono text-[10px] text-foreground/65`,children:[(0,$.jsx)(ys,{className:`h-2.5 w-2.5 shrink-0 text-accent-info/70`}),(0,$.jsx)(`span`,{className:`truncate`,children:e})]},`${t}-${e}`))})]})]});return r?(0,$.jsxs)(`button`,{type:`button`,"data-testid":n,"data-agent-interactive":!0,disabled:i,title:a(`problemFrame.pick`),onClick:()=>r(t.reading),className:X(fD,`group/reading transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/50`,i?`cursor-default`:`cursor-pointer hover:border-accent-primary/45 hover:bg-accent-primary/[0.09]`),children:[o,(0,$.jsxs)(`span`,{"aria-hidden":!0,className:X(`mt-0.5 inline-flex items-center gap-1 text-[10px] font-medium text-accent-primary/80 transition-opacity`,i?`opacity-0`:`opacity-0 group-hover/reading:opacity-100 group-focus-visible/reading:opacity-100`),children:[(0,$.jsx)(us,{className:`h-2.5 w-2.5`}),a(`problemFrame.pick`)]})]}):(0,$.jsx)(`div`,{"data-testid":n,className:fD,children:o})}function mD({label:e,items:t}){return t.length===0?null:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground/45`,children:e}),(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:t.map((e,t)=>(0,$.jsxs)(`li`,{className:`flex items-start gap-1.5 text-[11px] leading-5 text-foreground/70`,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`mt-2 h-1 w-1 shrink-0 rounded-full bg-foreground/30`}),(0,$.jsx)(`span`,{className:`min-w-0`,children:e})]},`${t}-${e}`))})]})}function hD({frame:e,isLatest:t,isStreaming:n,onSelect:r}){let{t:i}=K(`agent`),a=e.assumptions.length>0||e.unknowns.length>0,o=r&&t?r:void 0;return(0,$.jsxs)(`div`,{"data-testid":`agent-problem-frame-card`,className:`my-1 overflow-hidden rounded-xl border border-accent-info/25 bg-card/80 shadow-lg backdrop-blur`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-border/40 bg-accent-info/[0.06] px-3.5 py-2 text-[10px] font-semibold uppercase tracking-widest text-accent-info/90`,children:[(0,$.jsx)(ss,{className:`h-3 w-3`}),i(`problemFrame.heading`)]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2.5 px-3.5 py-3`,children:[(0,$.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,$.jsx)(pD,{label:i(`problemFrame.restated`),value:e.restated,testId:`agent-problem-frame-reading-restated`,onSelect:o,disabled:n}),(0,$.jsx)(pD,{label:i(`problemFrame.alternative`),value:e.alternative,testId:`agent-problem-frame-reading-alternative`,onSelect:o,disabled:n})]}),(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-accent-primary/25 bg-accent-primary/[0.07] px-2.5 py-2`,children:[(0,$.jsx)(I,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-primary/80`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-accent-primary/80`,children:i(`problemFrame.discriminator`)}),(0,$.jsx)(`div`,{className:`mt-0.5 text-xs leading-5 text-foreground/90`,children:e.discriminator})]})]}),a&&(0,$.jsxs)(`div`,{className:`grid gap-2 border-t border-border/40 pt-2.5 sm:grid-cols-2`,children:[(0,$.jsx)(mD,{label:i(`problemFrame.assumptions`),items:e.assumptions}),(0,$.jsx)(mD,{label:i(`problemFrame.unknowns`),items:e.unknowns})]})]})]})}function gD(){let{t:e}=K(`agent`);return(0,$.jsxs)(`span`,{"data-testid":`agent-problem-frame-pending`,className:`inline-flex w-fit items-center gap-1.5 rounded-full border border-accent-info/25 bg-accent-info/10 px-2.5 py-1 text-[11px] text-accent-info/90`,children:[(0,$.jsx)(ss,{className:`h-3 w-3 animate-pulse`}),e(`problemFrame.framing`)]})}var _D=`#agentref:`;function vD(e){return e.kind===`ticket`?`${_D}ticket:${e.ticketId}`:e.kind===`pull-request`?`${_D}pr:${e.prNumber}${e.prUrl?`:${encodeURIComponent(e.prUrl)}`:``}`:e.kind===`loop`?`${_D}loop:${e.loopId}`:`${_D}job:${e.jobId}`}function yD(e){if(!e||!e.startsWith(_D))return null;let t=e.slice(10);if(t.startsWith(`ticket:`)){let e=Number.parseInt(t.slice(7),10);return Number.isInteger(e)&&e>0?{kind:`ticket`,ticketId:e}:null}if(t.startsWith(`pr:`)){let[,e,n]=/^pr:(\d+)(?::(.+))?$/.exec(t)??[],r=Number.parseInt(e??``,10);if(!Number.isInteger(r)||r<=0)return null;let i=n?decodeURIComponent(n):void 0;return i?{kind:`pull-request`,prNumber:r,prUrl:i}:{kind:`pull-request`,prNumber:r}}if(t.startsWith(`job:`)){let e=t.slice(4);return xD.test(e)?{kind:`job`,jobId:e}:null}if(t.startsWith(`loop:`)){let e=t.slice(5);return CD.test(e)||xD.test(e)?{kind:`loop`,loopId:e}:null}return null}var bD=`[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}`,xD=RegExp(`^${bD}$`),SD=`factory:(?:implement|batch|freestyle)`,CD=RegExp(`^${SD}$`),wD=/\b(jobs?|runs?|loops?|rails?|ejecuci[oó]n(?:es)?|trabajos?|bucles?)\b|(?:loop|job|run)[a-z]*id/i;function TD(e){let t=new Set;for(let n of e.split(`
|
|
@@ -41,11 +41,11 @@ Error generating stack: `+e.message+`
|
|
|
41
41
|
`),l[r]=n.length,a(t),l.push(n.length)}),i.set(e,{start:o,end:n.length,boundaries:l})};return a(e),{value:n,references:r,positions:i}}function gk(e,t,n){let r=e.positions.get(t);if(r)return r.boundaries?r.boundaries[Math.min(n,r.boundaries.length-1)]:r.atomic?n===0?r.start:r.end:Math.min(r.end,r.start+n);let i=t.parentNode;for(;i;){let t=e.positions.get(i);if(t?.atomic)return n===0?t.start:t.end;i=i.parentNode}return e.value.length}function _k(e,t){let n=e.ownerDocument.getSelection();if(!n?.anchorNode||!n.focusNode||!e.contains(n.anchorNode)||!e.contains(n.focusNode))return null;let r=gk(t,n.anchorNode,n.anchorOffset),i=gk(t,n.focusNode,n.focusOffset);return[Math.min(r,i),Math.max(r,i)]}function vk(e,t,n){let r=Math.max(0,Math.min(n,t.value.length));for(let[n,i]of t.positions)if(!(r<i.start||r>i.end)){if(n.nodeType===Node.TEXT_NODE)return[n,i.boundaries?.lastIndexOf(r)??r-i.start];if(i.atomic&&n.parentNode){let e=Array.prototype.indexOf.call(n.parentNode.childNodes,n);return r===i.end&&n.nextSibling?.nodeType===Node.TEXT_NODE&&n.nextSibling.textContent?.startsWith(mk)?[n.nextSibling,1]:[n.parentNode,e+ +(r-i.start>(i.end-i.start)/2)]}if(n!==e&&n instanceof HTMLElement&&n.tagName===`BR`&&n.parentNode){let e=Array.prototype.indexOf.call(n.parentNode.childNodes,n);return[n.parentNode,e+ +(r>i.start)]}}return[e,e.childNodes.length]}function yk(e,t,n,r){let[i,a]=vk(e,t,n),[o,s]=vk(e,t,Math.max(n,r)),c=e.ownerDocument.createRange();c.setStart(i,a),c.setEnd(o,s);let l=e.ownerDocument.getSelection();l?.removeAllRanges(),l?.addRange(c)}function bk(e,t){let n=0,r=new Set;return[...t].sort((e,t)=>e.start-t.start).filter(t=>!t.key||!Number.isInteger(t.start)||!Number.isInteger(t.end)||r.has(t.key)||t.start<n||t.end<=t.start||e.slice(t.start,t.end)!==t.chip.token?!1:(n=t.end,r.add(t.key),!0))}function xk(e,t){return e.length===t.length&&e.every((e,n)=>{let r=t[n];return e.key===r.key&&e.start===r.start&&e.end===r.end&&JSON.stringify(e.chip)===JSON.stringify(r.chip)})}function Sk(e){return e===`spec`||e===`action`?`border-accent-highlight/30 bg-accent-highlight/10 text-accent-highlight`:e===`job`||e===`trace`?`border-accent-info/30 bg-accent-info/10 text-accent-info`:e===`project`||e===`alias`?`border-accent-primary/30 bg-accent-primary/10 text-accent-primary`:e===`rail`?`border-accent-warning/30 bg-accent-warning/10 text-accent-warning`:`border-border/60 bg-surface/70 text-foreground/80`}function Ck(e,t,n,r,i){let a=e.createDocumentFragment(),o=0;for(let s of n){a.append(e.createTextNode(`${o>0?mk:``}${t.slice(o,s.start)}${mk}`));let n=e.createElement(`span`);n.setAttribute(`contenteditable`,`false`),n.dataset.inlineReference=s.key,n.dataset.token=s.chip.token,n.className=`mx-0.5 inline-flex max-w-[240px] items-center gap-1 align-middle rounded-full border px-2 py-0.5 text-[11px] select-none ${Sk(s.chip.kind)}`,n.title=[s.chip.label,s.chip.detail,s.chip.projectName,s.chip.status].filter(Boolean).join(` · `);let c=e.createElement(`span`);c.textContent=/^[#@/]/.test(s.chip.token)?s.chip.token[0]:`@`,c.setAttribute(`aria-hidden`,`true`);let l=e.createElement(`span`);if(l.className=`truncate font-medium`,l.textContent=s.chip.label,n.append(c,l),s.chip.status){let t=e.createElement(`span`);t.className=`text-foreground/40`,t.textContent=s.chip.status,n.append(t)}let u=e.createElement(`button`);u.type=`button`,u.tabIndex=-1,u.disabled=r??!1,u.dataset.removeReference=s.key,u.setAttribute(`aria-label`,i(s.chip.label)),u.className=`rounded-sm px-0.5 text-foreground/45 hover:bg-background/60 hover:text-foreground`,u.textContent=`×`,n.append(u),a.append(n),o=s.end}return a.append(e.createTextNode(`${n.length?mk:``}${t.slice(o)}`)),a}var wk=(0,Q.forwardRef)(function(e,t){let{t:n}=K(`agent`),r=(0,Q.useRef)(null),i=(0,Q.useRef)(e);i.current=e;let a=(0,Q.useRef)(new Map),o=(0,Q.useRef)(!1),s=(0,Q.useRef)(null),c=(0,Q.useRef)([e.value.length,e.value.length]),l=(0,Q.useRef)([]),u=(0,Q.useRef)(``),d=(0,Q.useRef)(null),f=(0,Q.useRef)({entries:[{value:e.value,references:bk(e.value,e.references),selection:[e.value.length,e.value.length]}],index:0,typing:null}),p=()=>hk(r.current,a.current),m=e=>{c.current=e,f.current.entries[f.current.index].selection=e},h=(e,t)=>{let n=f.current,r=n.entries[n.index];if(r.value===e.value&&xk(r.references,e.references)){r.selection=e.selection;return}r.selection=c.current;let i=Date.now(),a=t===`insertText`&&n.typing!==null&&i-n.typing.at<1e3&&r.selection[0]===r.selection[1]&&r.selection[0]===n.typing.caret&&e.selection[0]===e.selection[1]&&e.selection[0]>=r.selection[0]&&r.references.length===e.references.length&&r.references.every((t,n)=>t.key===e.references[n].key);n.entries.splice(n.index+1),a&&n.index>0?n.entries[n.index]=e:(n.entries.push(e),n.entries.length>64&&n.entries.shift(),n.index=n.entries.length-1),n.typing=t===`insertText`?{at:i,caret:e.selection[0]}:null},g=(e,t,o)=>{let s=r.current;for(let e of t)a.current.set(e.key,e.chip);s.replaceChildren(Ck(s.ownerDocument,e,t,i.current.disabled??!1,e=>n(`palette.remove`,{label:e}))),s.dataset.empty=String(e.length===0),l.current=t,u.current=b,o&&(yk(s,p(),...o),m(_k(s,p())??o))},_=e=>{let t=r.current;if(!t||i.current.disabled)return;let n=f.current;n.index=Math.max(0,Math.min(n.entries.length-1,n.index+e)),n.typing=null;let a=n.entries[n.index];t.focus(),g(a.value,a.references,a.selection),i.current.onChange(a.value,a.references,a.selection[0])},v=()=>{let e=r.current;if(!e)return;let t=_k(e,p());t&&(t[0]!==c.current[0]||t[1]!==c.current[1])&&(m(t),i.current.onSelect(...t))},y=(e=`insertText`)=>{let t=r.current;if(!t||o.current)return;if(e===`historyUndo`||e===`historyRedo`){_(e===`historyUndo`?-1:1);return}let n=p(),a=_k(t,n)??[n.value.length,n.value.length];h({value:n.value,references:n.references,selection:a},d.current??e),m(a),l.current=n.references,t.dataset.empty=String(n.value.length===0),i.current.onChange(n.value,n.references,a[0])};(0,Q.useImperativeHandle)(t,()=>({focus:()=>r.current?.focus(),setSelectionRange:(e,t)=>{r.current&&(yk(r.current,p(),e,t),m(_k(r.current,p())??[e,t]))},get selectionStart(){return r.current?(_k(r.current,p())??c.current)[0]:0},get selectionEnd(){return r.current?(_k(r.current,p())??c.current)[1]:0},get value(){return r.current?p().value:i.current.value}}));let b=n(`palette.remove`,{label:`{{label}}`});(0,Q.useLayoutEffect)(()=>{let t=r.current;if(!t||o.current)return;let n=bk(e.value,e.references),i=p();for(let e of n)a.current.set(e.key,e.chip);t.querySelectorAll(`[data-remove-reference]`).forEach(t=>{t.disabled=e.disabled??!1});let s=t.ownerDocument.activeElement===t,d=_k(t,i)??c.current;i.value===e.value&&xk(i.references,n)&&xk(l.current,n)&&u.current===b||(h({value:e.value,references:n,selection:d},`external`),g(e.value,n,s?d:null))}),(0,Q.useEffect)(()=>{let t=r.current;if(!t)return;t.ownerDocument.addEventListener(`selectionchange`,v);let n=e=>{e.inputType!==`historyUndo`&&e.inputType!==`historyRedo`||(e.preventDefault(),e.cancelable&&_(e.inputType===`historyUndo`?-1:1))};return t.addEventListener(`beforeinput`,n),e.autoFocus&&t.focus(),()=>{t.ownerDocument.removeEventListener(`selectionchange`,v),t.removeEventListener(`beforeinput`,n)}},[]);let x=(e,t)=>{let n=r.current,i=n?.ownerDocument.getSelection();if(!n||!i?.rangeCount||!i.anchorNode||!i.focusNode||!n.contains(i.anchorNode)||!n.contains(i.focusNode))return;m(_k(n,p())??c.current),d.current=t;let a=!1;try{a=n.ownerDocument.execCommand?.(e?`insertText`:`delete`,!1,e)??!1}catch{}if(!a){let t=i.getRangeAt(0);if(t.deleteContents(),e){let r=n.ownerDocument.createTextNode(e);t.insertNode(r),t.setStartAfter(r)}t.collapse(!0),i.removeAllRanges(),i.addRange(t)}y(t),d.current=null},S=e=>{let t=r.current;if(!t||i.current.disabled)return;let n=p(),a=n.references.find(t=>t.key===e);a&&(t.focus(),yk(t,n,a.start,a.end),x(``,`deleteAtomic`))},C=(e,t)=>{let n=r.current;if(!n)return;let a=p(),o=_k(n,a);!o||o[0]===o[1]||(e.preventDefault(),e.clipboardData.setData(`text/plain`,a.value.slice(...o)),t&&!i.current.disabled&&x(``,`deleteByCut`))};return(0,$.jsx)(`div`,{ref:r,role:`textbox`,"aria-label":e.ariaLabel??e.placeholder,"aria-multiline":`true`,"aria-disabled":e.disabled||void 0,"data-agent-interactive":!0,contentEditable:!e.disabled,suppressContentEditableWarning:!0,"data-placeholder":e.placeholder,"data-empty":e.value.length===0,title:e.title,className:`whitespace-pre-wrap break-words outline-none data-[empty=true]:before:pointer-events-none data-[empty=true]:before:text-foreground/35 data-[empty=true]:before:content-[attr(data-placeholder)] ${e.className??``}`,onInput:e=>y(e.nativeEvent.inputType||`insertText`),onCompositionStart:()=>{o.current=!0,s.current={value:i.current.value,references:i.current.references}},onCompositionEnd:()=>{o.current=!1;let e=s.current;s.current=null;let t=i.current;if(e&&(e.value!==t.value||!xk(e.references,t.references))){let e=bk(t.value,t.references),n=[t.value.length,t.value.length];h({value:t.value,references:e,selection:n},`external`),g(t.value,e,r.current?.ownerDocument.activeElement===r.current?n:null);return}y(`insertCompositionText`)},onKeyUp:v,onMouseUp:v,onMouseDown:e=>{e.target.closest(`[data-remove-reference]`)&&e.preventDefault()},onClick:e=>{let t=e.target.closest(`[data-remove-reference]`);t?.dataset.removeReference&&S(t.dataset.removeReference)},onKeyDown:e=>{if(!(i.current.disabled||o.current||e.nativeEvent.isComposing||e.keyCode===229)){if((e.metaKey||e.ctrlKey)&&!e.altKey&&(e.key.toLowerCase()===`z`||!e.metaKey&&e.key.toLowerCase()===`y`)){e.preventDefault(),_(e.shiftKey||e.key.toLowerCase()===`y`?1:-1);return}if(m(_k(r.current,p())??c.current),i.current.onKeyDown(e),!(e.defaultPrevented||i.current.disabled)){if(e.key===`Enter`)e.preventDefault(),x(`
|
|
42
42
|
`,`insertLineBreak`);else if(e.key===`Backspace`||e.key===`Delete`){let t=r.current,n=p(),i=_k(t,n);if(!i||i[0]!==i[1])return;let a=n.references.find(t=>e.key===`Backspace`?t.end===i[0]:t.start===i[0]);a&&(e.preventDefault(),S(a.key))}}}},onPaste:e=>{i.current.onPaste(e),!(e.defaultPrevented||i.current.disabled)&&(e.preventDefault(),x(e.clipboardData.getData(`text/plain`).replace(/\r\n?/g,`
|
|
43
43
|
`),`insertFromPaste`))},onCopy:e=>C(e,!1),onCut:e=>C(e,!0)})}),Tk=Symbol(`radix.slottable`);function Ek(e){let t=({children:e})=>(0,$.jsx)($.Fragment,{children:e});return t.displayName=`${e}.Slottable`,t.__radixId=Tk,t}var[Dk,Ok]=Wn(`Tooltip`,[zw]),kk=zw(),Ak=`TooltipProvider`,jk=700,Mk=`tooltip.open`,[Nk,Pk]=Dk(Ak),Fk=e=>{let{__scopeTooltip:t,delayDuration:n=jk,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=Q.useRef(!0),s=Q.useRef(!1),c=Q.useRef(0);return Q.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,$.jsx)(Nk,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:Q.useCallback(()=>{window.clearTimeout(c.current),o.current=!1},[]),onClose:Q.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:s,onPointerInTransitChange:Q.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})};Fk.displayName=Ak;var Ik=`Tooltip`,[Lk,Rk]=Dk(Ik),zk=e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=Pk(Ik,e.__scopeTooltip),l=kk(t),[u,d]=Q.useState(null),f=Yn(),p=Q.useRef(0),m=o??c.disableHoverableContent,h=s??c.delayDuration,g=Q.useRef(!1),[_,v]=_r({prop:r,defaultProp:i??!1,onChange:e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(Mk))):c.onClose(),a?.(e)},caller:Ik}),y=Q.useMemo(()=>_?g.current?`delayed-open`:`instant-open`:`closed`,[_]),b=Q.useCallback(()=>{window.clearTimeout(p.current),p.current=0,g.current=!1,v(!0)},[v]),x=Q.useCallback(()=>{window.clearTimeout(p.current),p.current=0,v(!1)},[v]),S=Q.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{g.current=!0,v(!0),p.current=0},h)},[h,v]);return Q.useEffect(()=>()=>{p.current&&=(window.clearTimeout(p.current),0)},[]),(0,$.jsx)(tT,{...l,children:(0,$.jsx)(Lk,{scope:t,contentId:f,open:_,stateAttribute:y,trigger:u,onTriggerChange:d,onTriggerEnter:Q.useCallback(()=>{c.isOpenDelayedRef.current?S():b()},[c.isOpenDelayedRef,S,b]),onTriggerLeave:Q.useCallback(()=>{m?x():(window.clearTimeout(p.current),p.current=0)},[x,m]),onOpen:b,onClose:x,disableHoverableContent:m,children:n})})};zk.displayName=Ik;var Bk=`TooltipTrigger`,Vk=Q.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Rk(Bk,n),a=Pk(Bk,n),o=kk(n),s=Hn(t,Q.useRef(null),i.onTriggerChange),c=Q.useRef(!1),l=Q.useRef(!1),u=Q.useCallback(()=>c.current=!1,[]);return Q.useEffect(()=>()=>document.removeEventListener(`pointerup`,u),[u]),(0,$.jsx)(nT,{asChild:!0,...o,children:(0,$.jsx)(Un.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:qn(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:qn(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:qn(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:qn(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:qn(e.onBlur,i.onClose),onClick:qn(e.onClick,i.onClose)})})});Vk.displayName=Bk;var Hk=`TooltipPortal`,[Uk,Wk]=Dk(Hk,{forceMount:void 0}),Gk=e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=Rk(Hk,t);return(0,$.jsx)(Uk,{scope:t,forceMount:n,children:(0,$.jsx)(gr,{present:n||a.open,children:(0,$.jsx)(yr,{asChild:!0,container:i,children:r})})})};Gk.displayName=Hk;var Kk=`TooltipContent`,qk=Q.forwardRef((e,t)=>{let n=Wk(Kk,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=Rk(Kk,e.__scopeTooltip);return(0,$.jsx)(gr,{present:r||o.open,children:o.disableHoverableContent?(0,$.jsx)(Qk,{side:i,...a,ref:t}):(0,$.jsx)(Jk,{side:i,...a,ref:t})})}),Jk=Q.forwardRef((e,t)=>{let n=Rk(Kk,e.__scopeTooltip),r=Pk(Kk,e.__scopeTooltip),i=Q.useRef(null),a=Hn(t,i),[o,s]=Q.useState(null),{trigger:c,onClose:l}=n,u=i.current,{onPointerInTransitChange:d}=r,f=Q.useCallback(()=>{s(null),d(!1)},[d]),p=Q.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=nA(r,tA(r,n.getBoundingClientRect())),a=rA(t.getBoundingClientRect()),o=aA([...i,...a]);s(o),d(!0)},[d]);return Q.useEffect(()=>()=>f(),[f]),Q.useEffect(()=>{if(c&&u){let e=e=>p(e,u),t=e=>p(e,c);return c.addEventListener(`pointerleave`,e),u.addEventListener(`pointerleave`,t),()=>{c.removeEventListener(`pointerleave`,e),u.removeEventListener(`pointerleave`,t)}}},[c,u,p,f]),Q.useEffect(()=>{if(o){let e=e=>{let t=e.target,n={x:e.clientX,y:e.clientY},r=c?.contains(t)||u?.contains(t),i=!iA(n,o);r?f():i&&(f(),l())};return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,$.jsx)(Qk,{...e,ref:a})}),[Yk,Xk]=Dk(Ik,{isInside:!1}),Zk=Ek(`TooltipContent`),Qk=Q.forwardRef((e,t)=>{let{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:a,onPointerDownOutside:o,...s}=e,c=Rk(Kk,n),l=kk(n),{onClose:u}=c;return Q.useEffect(()=>(document.addEventListener(Mk,u),()=>document.removeEventListener(Mk,u)),[u]),Q.useEffect(()=>{if(c.trigger){let e=e=>{e.target?.contains(c.trigger)&&u()};return window.addEventListener(`scroll`,e,{capture:!0}),()=>window.removeEventListener(`scroll`,e,{capture:!0})}},[c.trigger,u]),(0,$.jsx)(vr,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:u,children:(0,$.jsxs)(rT,{"data-state":c.stateAttribute,...l,...s,ref:t,style:{...s.style,"--radix-tooltip-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-tooltip-content-available-width":`var(--radix-popper-available-width)`,"--radix-tooltip-content-available-height":`var(--radix-popper-available-height)`,"--radix-tooltip-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-tooltip-trigger-height":`var(--radix-popper-anchor-height)`},children:[(0,$.jsx)(Zk,{children:r}),(0,$.jsx)(Yk,{scope:n,isInside:!0,children:(0,$.jsx)(hT,{id:c.contentId,role:`tooltip`,children:i||r})})]})})});qk.displayName=Kk;var $k=`TooltipArrow`,eA=Q.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=kk(n);return Xk($k,n).isInside?null:(0,$.jsx)(iT,{...i,...r,ref:t})});eA.displayName=$k;function tA(e,t){let n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),a=Math.abs(t.left-e.x);switch(Math.min(n,r,i,a)){case a:return`left`;case i:return`right`;case n:return`top`;case r:return`bottom`;default:throw Error(`unreachable`)}}function nA(e,t,n=5){let r=[];switch(t){case`top`:r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case`bottom`:r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case`left`:r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case`right`:r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function rA(e){let{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function iA(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let o=t[e],s=t[a],c=o.x,l=o.y,u=s.x,d=s.y;l>r!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}function aA(e){let t=e.slice();return t.sort((e,t)=>e.x<t.x?-1:e.x>t.x?1:e.y<t.y?-1:+(e.y>t.y)),oA(t)}function oA(e){if(e.length<=1)return e.slice();let t=[];for(let n=0;n<e.length;n++){let r=e[n];for(;t.length>=2;){let e=t[t.length-1],n=t[t.length-2];if((e.x-n.x)*(r.y-n.y)>=(e.y-n.y)*(r.x-n.x))t.pop();else break}t.push(r)}t.pop();let n=[];for(let t=e.length-1;t>=0;t--){let r=e[t];for(;n.length>=2;){let e=n[n.length-1],t=n[n.length-2];if((e.x-t.x)*(r.y-t.y)>=(e.y-t.y)*(r.x-t.x))n.pop();else break}n.push(r)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var sA=Fk,cA=zk,lA=Vk,uA=qk,dA=sA,fA=cA,pA=lA,mA=Q.forwardRef(({className:e,sideOffset:t=4,...n},r)=>(0,$.jsx)(uA,{ref:r,sideOffset:t,className:X(`z-50 overflow-hidden rounded-md border border-border bg-popover px-2.5 py-1.5 text-xs text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...n}));mA.displayName=uA.displayName;var hA={"accent-primary":`border-accent-primary/40 bg-accent-primary/10 text-accent-primary`,"accent-info":`border-accent-info/40 bg-accent-info/10 text-accent-info`,"accent-highlight":`border-accent-highlight/40 bg-accent-highlight/10 text-accent-highlight`};function gA({process:e,accentVariant:t,onKill:n,onOpen:r}){let{t:i}=K(`agent`),a=vA(e),o=_A(e),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),d=s||e.status===`stopping`&&!e.stopError&&!e.error,f=l||!!e.stopError||e.status===`stopping`&&!!e.error,p=async()=>{if(!(d||o)){c(!0),u(!1);try{await n(e)}catch{u(!0)}finally{c(!1)}}};return(0,$.jsx)(dA,{delayDuration:150,children:(0,$.jsxs)(`span`,{"data-testid":`background-process-chip`,className:`inline-flex max-w-full items-center rounded-lg border text-[11px] ${hA[t]}`,children:[(0,$.jsxs)(fA,{children:[(0,$.jsx)(pA,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(e),"aria-label":i(`backgroundProcess.open`,{command:e.command}),className:`inline-flex min-w-0 max-w-[340px] items-center gap-1.5 rounded-l-lg px-2 py-1 transition-colors hover:bg-background/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary`,children:[(0,$.jsx)(Ac,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`shrink-0 ${e.status===`failed`?`text-destructive`:`text-foreground/70`}`,children:i(`backgroundProcess.status.${d?`stopping`:e.status}`)}),(0,$.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:e.command}),(0,$.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-muted-foreground`,children:a})]})}),(0,$.jsxs)(mA,{children:[i(`backgroundProcess.open`,{command:e.command}),` · `,a]})]}),f&&(0,$.jsxs)(`span`,{role:`alert`,title:i(`backgroundProcess.stopFailed`),className:`flex shrink-0 items-center px-1 text-destructive`,children:[(0,$.jsx)(Qo,{className:`h-3 w-3`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`sr-only`,children:i(`backgroundProcess.stopFailed`)})]}),!o&&(0,$.jsx)(`button`,{type:`button`,disabled:d,"aria-label":i(`backgroundProcess.stopCommand`,{command:e.command}),title:i(`backgroundProcess.stopCommand`,{command:e.command}),onClick:e=>{e.preventDefault(),e.stopPropagation(),p()},className:`mr-1 rounded p-1 text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive disabled:opacity-50`,children:d?(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Vn,{className:`h-3 w-3`,"aria-hidden":!0})})]})})}function _A(e){return e.status===`exited`||e.status===`failed`||e.status===`killed`||e.status===`interrupted`}function vA(e){let[t,n]=(0,Q.useState)(Date.now()),r=_A(e);return(0,Q.useEffect)(()=>{if(n(Date.now()),r)return;let e=window.setInterval(()=>n(Date.now()),1e3);return()=>window.clearInterval(e)},[r,e.startedAt]),Or(Math.max(0,(e.endedAt??e.recoveredAt??t)-e.startedAt))}var yA=2e3,bA=512*1024,xA=1e3;function SA(e){return e.replace(/\x1b\][\s\S]*?(?:\x07|\x1b\\|$)/g,``).replace(/\x1b[PX^_][\s\S]*?(?:\x1b\\|$)/g,``).replace(/(?:\x1b\[|\x9b)[0-?]*[ -/]*[@-~]/g,``).replace(/\x1b[()][0-2A-Z]/g,``).replace(/\x1b[@-_]/g,``).replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g,``)}function CA(e){let t=[],n=0,r=e.length>yA;for(let i=e.length-1;i>=0&&t.length<yA;i--){let a=e[i],o=SA(a.line),s=o.slice(-4e3);if(o.length>s.length&&(r=!0),n+s.length>bA){r=!0;break}n+=s.length,t.push({...a,line:s})}return{lines:t.reverse(),truncated:r}}function wA(e){let t=new Date(e.at);return`[${Number.isNaN(t.getTime())?`—`:t.toLocaleTimeString(void 0,{hour12:!1})}] [${e.source}] ${e.line}`}function TA({process:e,onClose:t,onKill:n,onBack:r}){return(0,$.jsx)(EA,{process:e,onClose:t,onKill:n,onBack:r},dO(e))}function EA({process:e,onClose:t,onKill:n,onBack:r}){let{t:i}=K(`agent`),a=dO(e),o=(0,Q.useRef)(e);o.current=e;let[s,c]=(0,Q.useState)(e),[l,u]=(0,Q.useState)([]),[d,f]=(0,Q.useState)(!0),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(!0),[x,S]=(0,Q.useState)(``),[C,w]=(0,Q.useState)(`all`),[T,E]=(0,Q.useState)(0),[D,O]=(0,Q.useState)(!1),[k,A]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(null),N=(0,Q.useRef)(null),P=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>(P.current=!0,()=>{P.current=!1}),[]);let F=_A(e)?e:_A(s)?s:e.status===`stopping`&&s.status!==`stopping`?e:s,I=_A(F);(0,Q.useEffect)(()=>{I&&v(!1)},[I]);let L=D||F.status===`stopping`&&!F.error&&!e.stopError,R=vA(F);(0,Q.useEffect)(()=>{if(_){f(!1);return}let e=new AbortController,t,n=async()=>{try{let r=await vO(o.current,{limit:yA,signal:e.signal});if(e.signal.aborted)return;if(dO(r.process)!==a)throw Error(`Unexpected process identity`);let i=CA(r.lines);c(e=>JSON.stringify(e)===JSON.stringify(r.process)?e:r.process),u(e=>e.length===i.lines.length&&e.every((e,t)=>{let n=i.lines[t];return e.sequence===n.sequence&&e.line===n.line&&e.source===n.source&&e.at===n.at&&e.partial===n.partial})?e:i.lines),g(r.truncated||i.truncated),m(!1),f(!1),_A(r.process)||(t=setTimeout(()=>{n()},xA))}catch{if(e.signal.aborted)return;f(!1),m(!0)}};return f(!0),m(!1),n(),()=>{e.abort(),clearTimeout(t)}},[a,_,T]),(0,Q.useEffect)(()=>{if(!j)return;let e=setTimeout(()=>M(null),2500);return()=>clearTimeout(e)},[j]);let z=(0,Q.useMemo)(()=>{let e=x.toLocaleLowerCase();return l.filter(t=>(C===`all`||C===t.source)&&(!e||t.line.toLocaleLowerCase().includes(e)))},[l,x,C]),B=(0,Q.useMemo)(()=>z.map(wA).join(`
|
|
44
|
-
`),[z]);(0,Q.useEffect)(()=>{y&&!_&&N.current&&(N.current.scrollTop=N.current.scrollHeight)},[z,y,_]);let V=async()=>{if(!(L||I)){O(!0),A(!1);try{await n(o.current)}catch{P.current&&A(!0)}finally{P.current&&O(!1)}}},H=async()=>{try{await navigator.clipboard.writeText(B),P.current&&M(`copied`)}catch{P.current&&M(`failed`)}},U=()=>{let t;try{t=URL.createObjectURL(new Blob([B],{type:`text/plain;charset=utf-8`}));let n=document.createElement(`a`);n.href=t,n.download=`process-${e.pid}-${e.startedAt}.log`,document.body.appendChild(n),n.click(),n.remove()}catch{M(`failed`)}finally{t&&URL.revokeObjectURL(t)}},W=`inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-md border border-border/60 px-2 text-xs text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary disabled:cursor-not-allowed disabled:opacity-40`;return(0,$.jsx)(mr,{open:!0,onOpenChange:e=>{e||t()},children:(0,$.jsxs)($n,{children:[(0,$.jsx)(pr,{className:`z-[80]`}),(0,$.jsxs)(hr,{"data-testid":`background-process-logs-modal`,className:`fixed left-1/2 top-1/2 z-[81] flex h-[min(780px,88vh)] w-[calc(100vw-2rem)] max-w-5xl -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-border/50 bg-popover text-foreground shadow-2xl focus:outline-none`,children:[(0,$.jsxs)(`header`,{className:`flex items-start gap-3 border-b border-border/50 px-4 py-3`,children:[r&&(0,$.jsx)(`button`,{type:`button`,onClick:r,"aria-label":i(`backgroundProcess.history.back`),title:i(`backgroundProcess.history.back`),className:`rounded-md p-1 text-muted-foreground hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary`,children:(0,$.jsx)(un,{className:`h-4 w-4`,"aria-hidden":!0})}),(0,$.jsx)(Ac,{className:`mt-0.5 h-5 w-5 shrink-0 text-accent-info`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,$.jsx)(sr,{className:`text-sm font-semibold`,children:i(`backgroundProcess.logsTitle`)}),(0,$.jsx)(`span`,{"data-testid":`background-process-status`,className:`rounded-full px-2 py-0.5 text-[11px] ${F.status===`failed`?`bg-destructive/10 text-destructive`:I?`bg-muted text-muted-foreground`:`bg-accent-info/10 text-accent-info`}`,children:i(`backgroundProcess.status.${L?`stopping`:F.status}`)}),(0,$.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:R})]}),(0,$.jsx)(ir,{className:`mt-1 text-xs text-muted-foreground`,children:i(`backgroundProcess.logsDescription`)})]}),(0,$.jsx)(lr,{className:`rounded-md p-1.5 text-muted-foreground hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary`,"aria-label":i(`backgroundProcess.close`),children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 border-b border-border/50 px-4 py-3 text-xs`,children:[(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:i(`backgroundProcess.command`)}),(0,$.jsx)(`dd`,{className:`break-all font-mono`,children:SA(F.command)}),(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:i(`backgroundProcess.directory`)}),(0,$.jsx)(`dd`,{className:`break-all font-mono text-muted-foreground`,children:SA(F.cwd)}),(F.repositoryName||F.repositoryId)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:i(`backgroundProcess.repository`)}),(0,$.jsx)(`dd`,{className:`break-all text-muted-foreground`,children:SA(F.repositoryName??F.repositoryId??``)})]}),(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:`PID`}),(0,$.jsxs)(`dd`,{className:`flex flex-wrap gap-x-4 gap-y-1 font-mono text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:F.pid}),F.exitCode!=null&&(0,$.jsx)(`span`,{children:i(`backgroundProcess.exitCode`,{code:F.exitCode})}),F.signal&&(0,$.jsx)(`span`,{children:i(`backgroundProcess.signal`,{signal:F.signal})})]})]}),F.error&&(0,$.jsx)(`p`,{role:`alert`,className:`border-b border-border/40 bg-destructive/5 px-4 py-2 text-xs text-destructive`,children:SA(F.error).slice(0,1e3)}),F.status===`interrupted`&&(0,$.jsx)(`p`,{role:`status`,className:`border-b border-border/40 bg-amber-500/5 px-4 py-2 text-xs text-amber-700 dark:text-amber-300`,children:i(`backgroundProcess.interruptedHint`)}),F.persistenceError&&(0,$.jsx)(`p`,{role:`alert`,className:`border-b border-border/40 bg-amber-500/5 px-4 py-2 text-xs text-amber-700 dark:text-amber-300`,children:i(`backgroundProcess.persistenceFailed`)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-border/50 px-4 py-2.5`,children:[(0,$.jsxs)(`label`,{className:`relative min-w-[150px] flex-1`,children:[(0,$.jsx)(In,{className:`pointer-events-none absolute left-2.5 top-2 h-4 w-4 text-muted-foreground`,"aria-hidden":!0}),(0,$.jsx)(`input`,{type:`search`,value:x,onChange:e=>S(e.target.value),placeholder:i(`backgroundProcess.search`),"aria-label":i(`backgroundProcess.search`),className:`h-8 w-full rounded-md border border-border/60 bg-background/50 pl-8 pr-2 text-xs outline-none focus:border-accent-primary/60`})]}),(0,$.jsxs)(`select`,{"aria-label":i(`backgroundProcess.source`),value:C,onChange:e=>w(e.target.value),className:`h-8 rounded-md border border-border/60 bg-background px-2 text-xs outline-none focus:border-accent-primary/60`,children:[(0,$.jsx)(`option`,{value:`all`,children:i(`backgroundProcess.allSources`)}),(0,$.jsx)(`option`,{value:`stdout`,children:`stdout`}),(0,$.jsx)(`option`,{value:`stderr`,children:`stderr`})]}),!I&&(0,$.jsxs)(`button`,{type:`button`,className:W,"aria-pressed":_,onClick:()=>v(e=>!e),children:[_?(0,$.jsx)(Mn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}):(0,$.jsx)(ic,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(_?`backgroundProcess.resume`:`backgroundProcess.pause`)]}),(0,$.jsxs)(`button`,{type:`button`,className:`${W} ${y?`border-accent-info/40 text-accent-info`:``}`,"aria-pressed":y,onClick:()=>b(e=>!e),children:[(0,$.jsx)(Io,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(`backgroundProcess.follow`)]}),(0,$.jsx)(`button`,{type:`button`,className:W,disabled:!z.length,onClick:()=>void H(),"aria-label":i(`backgroundProcess.copy`),title:i(`backgroundProcess.copy`),children:j===`copied`?(0,$.jsx)(Sn,{className:`h-3.5 w-3.5`}):(0,$.jsx)(ls,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,className:W,disabled:!z.length,onClick:U,"aria-label":i(`backgroundProcess.download`),title:i(`backgroundProcess.download`),children:(0,$.jsx)(En,{className:`h-3.5 w-3.5`})}),!I&&(0,$.jsxs)(`button`,{type:`button`,className:`${W} text-destructive`,disabled:L,onClick:()=>void V(),children:[L?(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Nn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(L?`backgroundProcess.status.stopping`:`backgroundProcess.stop`)]})]}),h&&(0,$.jsx)(`p`,{role:`status`,className:`border-b border-border/40 bg-amber-500/5 px-4 py-2 text-xs text-amber-600 dark:text-amber-400`,children:i(`backgroundProcess.truncated`)}),_&&!I&&(0,$.jsx)(`p`,{role:`status`,className:`border-b border-border/40 bg-muted/20 px-4 py-2 text-xs text-muted-foreground`,children:i(`backgroundProcess.paused`)}),p&&(0,$.jsxs)(`div`,{role:`alert`,className:`flex items-center gap-2 border-b border-border/40 bg-destructive/5 px-4 py-2 text-xs text-destructive`,children:[(0,$.jsx)(Qo,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`flex-1`,children:i(`backgroundProcess.loadFailed`)}),(0,$.jsx)(`button`,{type:`button`,className:W,onClick:()=>{v(!1),E(e=>e+1)},children:i(`backgroundProcess.retry`)})]}),(k||e.stopError)&&(0,$.jsx)(`p`,{role:`alert`,className:`bg-destructive/5 px-4 py-2 text-xs text-destructive`,children:i(`backgroundProcess.stopFailed`)}),j&&(0,$.jsx)(`p`,{role:j===`failed`?`alert`:`status`,className:`px-4 py-1 text-xs text-muted-foreground`,children:i(j===`copied`?`backgroundProcess.copied`:`backgroundProcess.exportFailed`)}),(0,$.jsx)(`div`,{ref:N,"data-testid":`background-process-log-output`,"aria-label":i(`backgroundProcess.output`),role:`region`,tabIndex:0,onScroll:e=>{let t=e.currentTarget;t.scrollHeight-t.clientHeight-t.scrollTop>40&&b(!1)},className:`min-h-0 flex-1 overflow-auto bg-background/80 px-3 py-3 font-mono text-[11px] leading-5 outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-accent-primary/50`,children:d&&!l.length?(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center justify-center gap-2 py-12 text-muted-foreground`,children:[(0,$.jsx)(An,{className:`h-4 w-4 animate-spin`,"aria-hidden":!0}),i(`backgroundProcess.loading`)]}):z.length?z.map(e=>(0,$.jsxs)(`div`,{"data-log-source":e.source,className:`grid grid-cols-[auto_auto_minmax(0,1fr)] items-start gap-x-2 hover:bg-muted/20`,children:[(0,$.jsx)(`span`,{className:`select-none whitespace-nowrap text-[10px] text-muted-foreground/70`,children:new Date(e.at).toLocaleTimeString(void 0,{hour12:!1})}),(0,$.jsx)(`span`,{className:`select-none text-[10px] ${e.source===`stderr`?`text-amber-600 dark:text-amber-400`:`text-muted-foreground/60`}`,children:e.source}),(0,$.jsx)(`span`,{className:`whitespace-pre-wrap break-words [overflow-wrap:anywhere] ${e.source===`stderr`?`text-amber-700 dark:text-amber-200`:`text-foreground/90`}`,children:e.line||`\xA0`})]},e.sequence)):!p&&(0,$.jsx)(`p`,{className:`py-12 text-center font-sans text-xs text-muted-foreground`,children:i(l.length?`backgroundProcess.noMatches`:`backgroundProcess.empty`)})}),(0,$.jsxs)(`footer`,{className:`flex flex-wrap justify-between gap-1 border-t border-border/50 px-4 py-2 text-[10px] text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:i(`backgroundProcess.lineCount`,{count:z.length,total:l.length})}),(0,$.jsx)(`span`,{children:i(`backgroundProcess.exportHint`)})]})]})]})})}function DA({processes:e,loading:t,error:n,onRefresh:r,onClose:i,onKill:a}){let{t:o}=K(`agent`),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(100),[d,f]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{r()},[r]);let p=(0,Q.useMemo)(()=>{let t=s.trim().toLocaleLowerCase();return e.filter(e=>!t||[e.command,e.cwd,e.repositoryName,e.repositoryId,e.pid,o(`backgroundProcess.status.${e.status}`)].join(` `).toLocaleLowerCase().includes(t)).sort((e,t)=>Number(_A(e))-Number(_A(t))||t.startedAt-e.startedAt)},[e,s,o]);if(d)return(0,$.jsx)(TA,{process:e.find(e=>dO(e)===dO(d))??d,onClose:i,onBack:()=>f(null),onKill:a});let m=`inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-md border border-border/60 px-2 text-xs text-muted-foreground hover:bg-muted/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary disabled:opacity-40`;return(0,$.jsx)(mr,{open:!0,onOpenChange:e=>{e||i()},children:(0,$.jsxs)($n,{children:[(0,$.jsx)(pr,{className:`z-[80]`}),(0,$.jsxs)(hr,{"data-testid":`background-process-history-modal`,className:`fixed left-1/2 top-1/2 z-[81] flex max-h-[85vh] w-[calc(100vw-2rem)] max-w-3xl -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-border/50 bg-popover text-foreground shadow-2xl focus:outline-none`,children:[(0,$.jsxs)(`header`,{className:`flex items-start gap-3 border-b border-border/50 px-4 py-3`,children:[(0,$.jsx)(Ac,{className:`mt-0.5 h-5 w-5 shrink-0 text-accent-info`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(sr,{className:`text-sm font-semibold`,children:o(`backgroundProcess.history.title`)}),(0,$.jsx)(ir,{className:`mt-1 text-xs text-muted-foreground`,children:o(`backgroundProcess.history.description`)})]}),(0,$.jsx)(lr,{className:`rounded-md p-1.5 text-muted-foreground hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary`,"aria-label":o(`backgroundProcess.history.close`),children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 border-b border-border/50 px-4 py-3`,children:[(0,$.jsxs)(`label`,{className:`relative min-w-0 flex-1`,children:[(0,$.jsx)(In,{className:`pointer-events-none absolute left-2.5 top-2 h-4 w-4 text-muted-foreground`,"aria-hidden":!0}),(0,$.jsx)(`input`,{type:`search`,value:s,onChange:e=>{c(e.target.value),u(100)},placeholder:o(`backgroundProcess.history.search`),"aria-label":o(`backgroundProcess.history.search`),className:`h-8 w-full rounded-md border border-border/60 bg-background/50 pl-8 pr-2 text-xs outline-none focus:border-accent-primary/60`})]}),(0,$.jsx)(`button`,{type:`button`,className:m,disabled:t,onClick:()=>void r(),"aria-label":o(`backgroundProcess.history.refresh`),title:o(`backgroundProcess.history.refresh`),children:(0,$.jsx)(mc,{className:`h-3.5 w-3.5 ${t?`animate-spin`:``}`,"aria-hidden":!0})})]}),n&&(0,$.jsxs)(`div`,{role:`alert`,className:`flex items-center gap-2 border-b border-border/40 bg-destructive/5 px-4 py-2 text-xs text-destructive`,children:[(0,$.jsx)(Qo,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`flex-1`,children:o(`backgroundProcess.history.loadFailed`)}),(0,$.jsx)(`button`,{type:`button`,className:m,onClick:()=>void r(),children:o(`backgroundProcess.retry`)})]}),(0,$.jsxs)(`div`,{className:`min-h-[160px] overflow-y-auto p-2`,children:[p.slice(0,l).map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f(e),"aria-label":o(`backgroundProcess.open`,{command:e.command}),className:`flex w-full items-center gap-3 rounded-lg px-3 py-3 text-left hover:bg-muted/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent-primary`,children:[(0,$.jsx)(Ac,{className:`h-4 w-4 shrink-0 ${_A(e)?`text-muted-foreground`:`text-accent-info`}`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate font-mono text-xs text-foreground`,children:SA(e.command)}),(0,$.jsxs)(`span`,{className:`mt-1 block truncate text-[11px] text-muted-foreground`,children:[SA(e.repositoryName??e.cwd),` · `,new Date(e.startedAt).toLocaleString(),` · PID `,e.pid]})]}),(0,$.jsx)(`span`,{className:`max-w-[35%] shrink-0 rounded-full px-2 py-0.5 text-[10px] ${e.status===`failed`?`bg-destructive/10 text-destructive`:_A(e)?`bg-muted text-muted-foreground`:`bg-accent-info/10 text-accent-info`}`,children:o(`backgroundProcess.status.${e.status}`)}),(0,$.jsx)(Zo,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`,"aria-hidden":!0})]},dO(e))),t&&!e.length?(0,$.jsxs)(`p`,{role:`status`,className:`flex justify-center gap-2 py-12 text-xs text-muted-foreground`,children:[(0,$.jsx)(An,{className:`h-4 w-4 animate-spin`,"aria-hidden":!0}),o(`backgroundProcess.history.loading`)]}):!n&&!p.length&&(0,$.jsx)(`p`,{className:`px-4 py-12 text-center text-xs text-muted-foreground`,children:o(s.trim()?`backgroundProcess.history.noMatches`:`backgroundProcess.history.empty`)}),p.length>l&&(0,$.jsx)(`div`,{className:`py-2 text-center`,children:(0,$.jsx)(`button`,{type:`button`,className:m,onClick:()=>u(e=>e+100),children:o(`backgroundProcess.history.showMore`)})})]}),(0,$.jsx)(`footer`,{className:`border-t border-border/50 px-4 py-2 text-[10px] text-muted-foreground`,children:o(`backgroundProcess.history.count`,{count:p.length})})]})]})})}function OA(e={}){let t=e.enabled!==!1,[n,r]=(0,Q.useState)({available:{},availableIds:[],issues:{},launchDescriptors:{},labels:{},loading:!0}),[i,a]=(0,Q.useState)(0);return(0,Q.useEffect)(()=>{if(!t)return;let e=0,n=()=>{let t=Date.now();t-e<3e4||(e=t,a(e=>e+1))},r=()=>{e=0,n()};return window.addEventListener(`focus`,n),window.addEventListener(`specrails:providers-detected-changed`,r),()=>{window.removeEventListener(`focus`,n),window.removeEventListener(`specrails:providers-detected-changed`,r)}},[t]),(0,Q.useEffect)(()=>{if(!t)return;let e=!0;return fetch(`${Xe}/api/available-providers`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}).then(t=>{if(!e)return;let n={};for(let[e,r]of Object.entries(t))e===`tiers`||e===`providerIssues`||e===`launchDescriptors`||e===`labels`||typeof r==`boolean`&&(n[e]=r);let i=t.providerIssues&&typeof t.providerIssues==`object`?t.providerIssues:{},a=t.launchDescriptors&&typeof t.launchDescriptors==`object`?t.launchDescriptors:{},o={};if(t.labels&&typeof t.labels==`object`)for(let[e,n]of Object.entries(t.labels))typeof n==`string`&&(o[e]=n);r({available:n,availableIds:Object.keys(n).filter(e=>n[e]),issues:i,launchDescriptors:a,labels:o,loading:!1})}).catch(()=>{e&&r(e=>({...e,loading:!1}))}),()=>{e=!1}},[t,i]),n}function kA(e,t,n,r,i){let a=i.length-(r-n);return{text:`${e.slice(0,n)}${i}${e.slice(r)}`,references:t.flatMap(e=>e.end<=n?[e]:e.start>=r?[{...e,start:e.start+a,end:e.end+a}]:[])}}var AA=[],jA=[];function MA({autoFocus:e=!1,hideProjectSelector:t=!1,queueEditRequest:n}){let{t:r}=K(`agent`),{active:i,messages:a,conversations:o,isStreaming:s,providersReady:c,draftPinnedProjectId:l,draftProvider:u,draftModel:d,draftTierLevel:f,draftEffort:p,setEffort:m,send:h,abort:g,cycleTier:_,setProvider:v,setModel:y,setPinnedProject:b,materializeDraftConversation:x,queuedMessages:S,editQueuedMessage:C,wasQueueConsumed:w}=aP(),T=(0,Q.useMemo)(()=>S.filter(e=>e.deliveryMode!==`steer`),[S]),{pendingCaptures:E,consumePendingCaptures:D,openBrowser:O}=lO(),{processes:k,history:A=k,historyLoading:j=!1,historyError:M=null,refreshHistory:N,kill:P}=wO(),[F,I]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(null),z=(0,Q.useMemo)(()=>[...k].sort((e,t)=>Number(_A(e))-Number(_A(t))||t.startedAt-e.startedAt).slice(0,4),[k]),{projects:B,activeProjectId:V}=pt(),H=i?.pinned_project_id??l??V,U=i?.id??`__new-mission__`,W=Ci(),ee=(0,Q.useRef)(null);ee.current!==U&&(di(U),ee.current=U),Xr(U);let[te,ne]=(0,Q.useState)(null),re=te&&te.key===U?te:null,ie=re?re.text:Vr.get(U)??``,ae=re?AA:Ur.get(U)??AA,oe=Hr.get(U)??jA,se=(e,t=[])=>Zr(U,e,t),[ce,le]=(0,Q.useState)(null),ue=(e,t)=>{let n=Hr.get(e)??jA;Qr(e,typeof t==`function`?t(n):t)},[de,fe]=(0,Q.useState)(!1),[G,pe]=(0,Q.useState)(!1),me=(0,Q.useRef)(!1),he=(0,Q.useRef)(null),ge=(0,Q.useRef)(null),_e=(0,Q.useMemo)(()=>[...new Map(ae.map(({chip:e})=>[JSON.stringify([e.projectId,MO(e)]),e])).values()],[ae]),[ve,ye]=(0,Q.useState)(null),[be,xe]=(0,Q.useState)(0),[Se,Ce]=(0,Q.useState)(!1),[we,Te]=(0,Q.useState)([]),[Ee,De]=(0,Q.useState)([]),[Oe,ke]=(0,Q.useState)([]),Ae=ce!==null,je=(0,Q.useMemo)(()=>a.filter(e=>e.role===`user`).map(e=>e.content),[a]),Me=re?.queueId??null,Ne=(0,Q.useRef)(``),Pe=Me===null?-1:T.findIndex(e=>e.queueId===Me),Fe=Pe>=0?T[Pe]:null,Le=re!==null;(0,Q.useEffect)(()=>{if(de||G||Le)return Gy(U)},[U,de,G,Le]);let Re=c===!1||(i?!W.isEditable(i.id):!!W.current),ze=!Re&&!Le,Be=i?.provider??u,{availableIds:Ve,labels:He}=OA(),Ue=(0,Q.useMemo)(()=>[Be,...Ve].filter((e,t,n)=>n.indexOf(e)===t),[Be,Ve]),We=e=>r(`provider.${e}`,{defaultValue:He?.[e]??e}),Ge=i?i.pinned_project_id:l,Ke=Ge,qe=ve?.mode===`reference`?ve.query.trim():``,Je=`${Ke??``}:${qe}`,[Ye,Ze]=(0,Q.useState)({key:``,items:[]});(0,Q.useEffect)(()=>{let e=B.find(e=>e.id===Ke);if(!e||qe.length<2)return;let t=new AbortController,n=setTimeout(()=>{let n=new URLSearchParams({kind:`find`,q:qe,limit:`20`});fetch(`${Xe}/api/projects/${encodeURIComponent(e.id)}/code/discover?${n}`,{signal:t.signal}).then(async n=>{if(!n.ok)return;let r=await n.json();t.signal.aborted||Ze({key:Je,items:DO(e,r.matches??[])})}).catch(()=>{})},180);return()=>{clearTimeout(n),t.abort()}},[Ke,B,qe,Je]);let Qe=(0,Q.useMemo)(()=>({projects:B,conversations:o,activeConversation:i,pinnedProjectId:Ke,activeProjectId:V,tickets:we,jobs:Ee,rails:Oe,chips:_e}),[B,o,i,Ke,V,we,Ee,Oe,_e]),$e=(0,Q.useMemo)(()=>ve?[...JO(ve.mode,Qe),...ve.mode===`reference`&&qe.length>=2&&Ye.key===Je?Ye.items:[]]:[],[ve,Qe,Ye,Je,qe]),et=(0,Q.useMemo)(()=>{if(!ve)return[];let e=HO($e,ve.query);return e.length>0?e:YO(ve.mode,ve.query)},[$e,ve]),tt=ve!==null&&!Le,nt=ie.trim().length>0||_e.length>0,rt=[`accent-primary`,`accent-info`,`accent-highlight`],it=i?.id??null;(0,Q.useEffect)(()=>{I(null),R(null)},[it,H]),(0,Q.useEffect)(()=>{le(null),ye(null),Ce(!1),ne(null)},[it]),(0,Q.useEffect)(()=>{if(!Ke){Te([]),De([]),ke([]);return}let e=!0;return(async()=>{try{let[t,n]=await Promise.all([fetch(`${Xe}/api/projects/${encodeURIComponent(Ke)}/tickets`),fetch(`${Xe}/api/projects/${encodeURIComponent(Ke)}/jobs?limit=25`)]),r=await t.json(),i=await n.json();if(!e)return;Te(Array.isArray(r.tickets)?r.tickets:[]),De(Array.isArray(i.jobs)?i.jobs:[])}catch{if(!e)return;Te([]),De([])}try{let t=await fetch(`${Xe}/api/projects/${encodeURIComponent(Ke)}/rails`),n=t.ok?await t.json():null;if(!e)return;ke(OO(n))}catch{e&&ke([])}})(),()=>{e=!1}},[Ke]),(0,Q.useEffect)(()=>{xe(0)},[ve?.mode,ve?.query]),(0,Q.useEffect)(()=>{be>=et.length&&xe(Math.max(0,et.length-1))},[be,et.length]),(0,Q.useEffect)(()=>{if(E.length===0)return;let e=D();e.length&&ue(U,t=>[...t,...e])},[E,D,U]);let at=ok(Be),{models:ot,efforts:st,supportsImageInput:ct,customModelAliases:lt}=at,q=(i?i.model:d)??ot.find(e=>e.default)?.value??ot[0]?.value??``,ut=vt(Be,q),dt=st.filter(e=>ut.includes(e)),ft=i?i.reasoning_effort:p,mt=ft&&dt.includes(ft)?ft:Dt(Be,q)??``,Y=e=>{pi(e)},ht=async e=>{if(e.length===0)return;fe(!0);let t=i;if(!t)try{t=await x(),Y(t.id)}catch(e){J.error(e instanceof Error?e.message:r(`workspace.uploadFailed`)),fe(!1);return}for(let n of e){if(!ct&&n.type.startsWith(`image/`)){J.error(r(`imagesUnsupported`));continue}try{let e=await co(t.id,n);ue(t.id,t=>[...t,e])}catch(e){J.error(e instanceof Error?e.message:r(`workspace.uploadFailed`))}}fe(!1)},gt=async e=>{try{i&&await po(i.id,e),ue(U,t=>t.filter(t=>t.id!==e))}catch(e){J.error(e instanceof Error?e.message:`Failed to remove attachment.`)}},_t=(e,t,n=ae)=>{if(n.some(e=>t>e.start&&t<=e.end)){ye(null);return}let r=jO(e,t);ye(r),r&&Ce(!1)},yt=e=>e===`reference`?`@`:e===`trace`?`#`:`/`,bt=e=>{requestAnimationFrame(()=>{ge.current?.focus(),ge.current?.setSelectionRange(e,e)})},xt=e=>{if(Le)return;let t=yt(e),n=ge.current,r=n?.selectionStart??ie.length,i=n?.selectionEnd??r,a=kA(ie,ae,r,i,t);se(a.text,a.references),le(null),Ce(!1),ye({mode:e,trigger:t,query:``,start:r,end:r+1}),bt(r+1)},St=e=>{ge.current?.focus();let t=XO(ie,ve,e),n=ve?.start??ie.length,r=ve?.end??n,i=t.text.slice(n,t.caret),{references:a}=kA(ie,ae,n,r,i);if(e.chip){let t=n+i.indexOf(e.chip.token);a.push({key:crypto.randomUUID(),start:t,end:t+e.chip.token.length,chip:e.chip}),a.sort((e,t)=>e.start-t.start)}se(t.text,a),le(null),ye(null),Ce(!1),bt(t.caret)},Ct=e=>{let t=T[e];t&&(Ne.current=t.text,ne({key:U,queueId:t.queueId,text:t.text}))},wt=e=>{Ae&&se(``),le(null),Ct(e)};(0,Q.useEffect)(()=>{if(!n||n.conversationId!==i?.id)return;let e=T.findIndex(e=>e.queueId===n.queueId);e<0||(Le?Ct(e):wt(e),bt(T[e].text.length))},[n]);let Tt=(e,t)=>{let n=t??ie;ne(null),e===`keep`&&se(n)},Et=async()=>{let e=Fe,t=ie.trim();if(!(!e||!t))try{await C(e.queueId,t)===`saved`?Tt(`restore`):(J.info(r(`queueEdit.dispatched`)),Tt(`keep`))}catch{J.error(r(`queueEdit.saveFailed`))}};(0,Q.useEffect)(()=>{if(!re||T.some(e=>e.queueId===re.queueId))return;let e=ie!==Ne.current;w(re.queueId)&&J.info(r(`queueEdit.dispatched`)),Tt(e?`keep`:`restore`)},[Me,T,Le]);let Ot=async()=>{if(Re||!nt||me.current)return;let e=ie.trim()||_e.map(e=>e.token).join(` `),t={...oe.length?{attachmentIds:oe.map(e=>e.id)}:{},..._e.length?{contextRefs:_e.map(NO)}:{}},n=JSON.stringify([e,t]),i=Wr.get(U),a=i?.signature===n?i:{signature:n,queueId:`q-${crypto.randomUUID()}`},o={text:ie,references:ae,attachments:oe,submission:a};$r(U,a),ni(U,o),ye(null),Ce(!1),le(null),me.current=!0,pe(!0);try{let n=await h(e,{...t,queueId:a.queueId}),r=n.conversationId??U;if(!n.accepted){$r(r,a),ri(r,o);return}$r(U,null),$r(r,null)}catch(e){ri(U,o),J.error(e instanceof Error?e.message:r(`queueEdit.saveFailed`))}finally{me.current=!1,pe(!1)}},kt=e=>{if(je[e]===void 0){le(null);return}le(e),se(je[e])};return(0,$.jsxs)(`div`,{className:`shrink-0`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-2`,children:[i===null&&!t&&(0,$.jsx)(ZO,{pinnedProjectId:l,onSelect:e=>void b(e)}),(0,$.jsx)(KE,{label:r(`provider.label`),value:Be,options:Ue.map(e=>({value:e,label:We(e)})),icon:Vo,onSelect:e=>{v(e).catch(()=>J.error(r(`error.generic`)))},testId:`agent-provider-selector`}),(0,$.jsx)(ik,{models:ot,model:i?i.model:d,status:at.status,customModelAliases:lt,onSelect:e=>{y(e).catch(()=>J.error(r(`error.generic`)))}}),dt.length>0&&(0,$.jsx)(KE,{label:r(`effort.label`),value:mt,options:dt.map(e=>({value:e,label:r(`effort.${e}`)})),icon:Ds,onSelect:e=>{m(e).catch(()=>J.error(r(`error.generic`)))},testId:`agent-effort-selector`}),(0,$.jsx)(`div`,{className:`ml-auto`,children:(0,$.jsx)(ek,{level:i?.tier_level??f,onCycle:()=>void _()})})]}),Le&&Fe&&(0,$.jsxs)(`div`,{"data-testid":`queue-edit-chip`,className:`mb-1 flex items-center gap-1.5 rounded-md border border-accent-highlight/30 bg-accent-highlight/10 px-2 py-1 text-[11px] text-accent-highlight`,children:[(0,$.jsx)(jn,{className:`h-3 w-3 shrink-0`}),(0,$.jsx)(`span`,{className:`font-medium`,children:r(`queueEdit.editing`,{n:Pe+1,m:T.length})}),(0,$.jsx)(`span`,{className:`truncate text-foreground/45`,children:r(`queueEdit.hint`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>Tt(`restore`),"aria-label":r(`queueEdit.cancel`),title:r(`queueEdit.cancel`),className:`ml-auto rounded-sm p-0.5 text-foreground/50 hover:bg-muted hover:text-foreground`,children:(0,$.jsx)(Vn,{className:`h-3 w-3`})})]}),Ae&&(0,$.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5 px-1 text-[11px] text-foreground/50`,children:[(0,$.jsx)(Fs,{className:`h-3 w-3`}),r(`history.hint`)]}),oe.length>0&&(0,$.jsx)(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-1.5`,children:oe.map(e=>(0,$.jsx)(EO,{conversationId:it,attachment:e,removeLabel:r(`close`),onRemove:()=>gt(e.id)},e.id))}),(k.length>0||it&&H)&&(0,$.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-1.5`,children:[it&&H&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>R({chatId:it,projectId:H}),"aria-label":r(`backgroundProcess.history.open`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border/50 px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/40 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary`,children:[(0,$.jsx)(Ac,{className:`h-3 w-3`,"aria-hidden":!0}),r(`backgroundProcess.history.button`),A.length>0&&(0,$.jsx)(`span`,{className:`font-mono text-[10px]`,children:A.length})]}),z.map((e,t)=>(0,$.jsx)(gA,{process:e,accentVariant:rt[t%rt.length],onKill:P,onOpen:I},dO(e)))]}),(0,$.jsxs)(`div`,{className:`relative flex items-end gap-2 rounded-xl border bg-background/60 px-3 py-2 ${Le?`border-accent-highlight/50`:Ae?`border-accent-info/40`:`border-border/60`}`,onDragOver:e=>{ze&&e.preventDefault()},onDrop:e=>{if(!ze)return;e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length&&ht(t)},children:[tt&&(0,$.jsx)(dk,{items:et,mode:ve.mode,query:ve.query,activeIndex:be,onActiveIndexChange:xe,onSelect:St}),ze&&(0,$.jsx)($.Fragment,{children:(0,$.jsx)(`input`,{ref:he,type:`file`,multiple:!0,hidden:!0,onChange:e=>{let t=Array.from(e.target.files??[]);t.length&&ht(t),e.target.value=``}})}),!Le&&(0,$.jsx)(fk,{open:Se,canAttach:ze,uploading:de,onToggle:()=>{Ce(e=>!e),ye(null)},onClose:()=>Ce(!1),onOpenMode:xt,onAttachFile:()=>{Ce(!1),he.current?.click()},canBrowserCapture:Ie()&&!!(Ke??V),onOpenBrowser:()=>{Ce(!1),O()}}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsx)(wk,{ref:ge,value:ie,references:Le?[]:ae,autoFocus:e,onChange:(e,t,n)=>{if(Le){ne(t=>t&&{...t,text:e});return}Ae&&le(null),se(e,t),_t(e,n,t)},onSelect:e=>{Le||_t(ge.current?.value??ie,e)},onKeyDown:e=>{if(e.nativeEvent.isComposing)return;if(e.key===`Tab`&&e.shiftKey){e.preventDefault(),e.stopPropagation(),_();return}if(tt){if(e.key===`ArrowDown`){e.preventDefault(),et.length>0&&xe(e=>Math.min(et.length-1,e+1));return}if(e.key===`ArrowUp`){e.preventDefault(),et.length>0&&xe(e=>Math.max(0,e-1));return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let t=et[be]??et[0];t&&St(t);return}if(e.key===`Escape`){e.preventDefault(),ye(null);return}}if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),Le?Et():Ot();return}if(e.key===`Escape`&&Le){e.preventDefault(),e.stopPropagation(),Tt(`restore`);return}let t=ge.current,n=t?.selectionStart===0&&t?.selectionEnd===0,r=t?.selectionStart===ie.length&&t?.selectionEnd===ie.length;if(e.key===`ArrowUp`){if(Le){Fe!==null&&ie===Fe.text&&n&&Pe>0&&(e.preventDefault(),Ct(Pe-1));return}if(T.length>0){n&&(e.preventDefault(),wt(T.length-1));return}!Ae&&ie===``&&je.length>0?(e.preventDefault(),kt(je.length-1)):Ae&&(e.preventDefault(),kt(Math.max(0,ce-1)));return}if(e.key===`ArrowDown`){if(Le){Fe!==null&&ie===Fe.text&&r&&(e.preventDefault(),Pe<T.length-1?Ct(Pe+1):Tt(`restore`));return}if(T.length>0)return;Ae&&(e.preventDefault(),ce<je.length-1?kt(ce+1):(le(null),se(``)));return}(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&Ae&&le(null)},onPaste:e=>{if(!ze)return;let t=Array.from(e.clipboardData.files);t.length&&(e.preventDefault(),ht(t))},disabled:Re,placeholder:r(Re?`noProvider.placeholder`:s?`queue.placeholder`:`composerPlaceholder`),title:Le?r(`queueEdit.hint`):Ae?r(`history.hint`):void 0,className:`min-h-[3.25rem] max-h-64 min-w-0 w-full resize-y overflow-y-auto bg-transparent text-sm outline-none ${Ae?`italic text-foreground/50`:`text-foreground`}`},U)}),s&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>void g(),"aria-label":r(`stop`),title:r(`stop`),className:`rounded-lg bg-destructive p-1.5 text-white transition-colors hover:opacity-90`,children:(0,$.jsx)(Nn,{className:`h-4 w-4`,fill:`currentColor`})}),Le?(0,$.jsx)(`button`,{type:`button`,onClick:()=>void Et(),disabled:Re||!ie.trim(),"aria-label":r(`queueEdit.save`),title:r(`queueEdit.save`),className:`rounded-lg bg-accent-highlight p-1.5 text-white transition-opacity hover:opacity-90 disabled:opacity-40`,children:(0,$.jsx)(Sn,{className:`h-4 w-4`})}):s?(0,$.jsx)(`button`,{type:`button`,onClick:Ot,disabled:Re||!nt||G,"aria-label":r(`queue.send`),title:r(`queue.sendHint`),className:`relative rounded-lg bg-accent-info p-1.5 text-white transition-colors hover:opacity-90`,children:(0,$.jsx)(Pt,{className:`h-4 w-4`})}):(0,$.jsx)(`button`,{type:`button`,onClick:Ot,disabled:Re||!nt||G,"aria-label":r(`send`),className:`rounded-lg bg-accent-primary p-1.5 text-white transition-opacity disabled:opacity-40`,children:(0,$.jsx)(Pt,{className:`h-4 w-4`})})]}),Ge&&(0,$.jsx)(sk,{projectId:Ge}),F&&F.chatId===it&&F.projectId===H&&(0,$.jsx)(TA,{process:A.find(e=>dO(e)===dO(F))??F,onClose:()=>I(null),onKill:P}),L&&L.chatId===it&&L.projectId===H&&(0,$.jsx)(DA,{processes:A,loading:j,error:M,onRefresh:N,onClose:()=>R(null),onKill:P})]})}function NA({active:e,inset:t=-4,radius:n=`9999px`,className:r,fadeInMs:i=350,fadeOutMs:a=350}){let o=My();return(0,$.jsx)(N_,{children:e&&(0,$.jsxs)(Ny.span,{"aria-hidden":!0,"data-testid":`builder-halo`,"data-reduced-motion":o?`true`:void 0,initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1,transition:{duration:i/1e3,ease:`easeOut`}},exit:{opacity:0,scale:1.15,transition:{duration:a/1e3,ease:`easeInOut`}},style:{inset:t},className:`pointer-events-none absolute ${r??``}`,children:[(0,$.jsx)(`span`,{className:`absolute inset-0 overflow-hidden`,style:{borderRadius:n,padding:`2px`,WebkitMask:`linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)`,WebkitMaskComposite:`xor`,maskComposite:`exclude`},children:(0,$.jsx)(`span`,{className:`absolute left-1/2 top-1/2 aspect-square w-[250%] -translate-x-1/2 -translate-y-1/2 ${o?``:`animate-[builder-halo-spin_2.6s_linear_infinite]`}`,style:{background:`conic-gradient(from 0deg, transparent 0%, color-mix(in srgb, var(--color-accent-primary) 90%, transparent) 18%, color-mix(in srgb, var(--color-accent-highlight) 85%, transparent) 32%, transparent 55%)`}})}),(0,$.jsx)(`span`,{className:`absolute inset-0 opacity-60`,style:{borderRadius:n,boxShadow:`0 0 12px 2px color-mix(in srgb, var(--color-accent-primary) 45%, transparent), inset 0 0 8px 1px color-mix(in srgb, var(--color-accent-highlight) 30%, transparent)`}})]})})}var PA=`specrails-desktop:effects`,FA=`specrails:effects-changed`,IA={agentThinkingHalo:!0},LA=null;function RA(){try{let e=localStorage.getItem(PA);if(!e)return IA;let t=JSON.parse(e);return{...IA,...typeof t.agentThinkingHalo==`boolean`?{agentThinkingHalo:t.agentThinkingHalo}:{}}}catch{return IA}}function zA(){return LA||=RA(),LA}function BA(e){let t={...zA(),...e};LA=t;try{localStorage.setItem(PA,JSON.stringify(t))}catch{}try{window.dispatchEvent(new CustomEvent(FA))}catch{}return t}function VA(e){let t=()=>{LA=null,e()};return window.addEventListener(FA,t),window.addEventListener(`storage`,t),()=>{window.removeEventListener(FA,t),window.removeEventListener(`storage`,t)}}function HA(){return(0,Q.useSyncExternalStore)(VA,zA,()=>IA)}function UA({active:e,radius:t=`0.75rem`,inset:n=-3}){let{agentThinkingHalo:r}=HA();return r?(0,$.jsx)(`span`,{"data-testid":`agent-thinking-halo`,"data-active":e,className:`contents`,children:(0,$.jsx)(NA,{active:e,radius:t,inset:n,fadeInMs:450,fadeOutMs:800})}):null}var WA=e=>e===`running`||e===`queued`;function GA(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m${String(t%60).padStart(2,`0`)}s`:`${Math.floor(n/60)}h ${n%60}m`}function KA(){try{return tt()}catch{return null}}var qA=e=>{if(!e)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null};function JA(e,t,n){let{live:r}=n,[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(()=>Date.now());(0,Q.useEffect)(()=>{let n=!1;return fetch(`${Xe}/api/projects/${e}/jobs/${t}`).then(e=>e.ok?e.json():null).then(e=>{if(n)return;let t=e?.job;t&&(s(typeof t.status==`string`?t.status:null),l(qA(t.started_at)),d(qA(t.finished_at)),typeof t.total_cost_usd==`number`&&p(t.total_cost_usd),typeof t.num_turns==`number`&&h(t.num_turns),_(t.loopPaused===!0),y(typeof t.loopPauseReason==`string`?t.loopPauseReason:null)),a(!0)}).catch(()=>{n||a(!0)}),()=>{n=!0}},[e,t,r]);let S=WA(o)&&u===null,C=KA(),w=(0,Q.useId)();return(0,Q.useEffect)(()=>{if(!C||!r)return;let e=`run-vitals-${t}-${w}`;return C.registerHandler(e,e=>{let n=e;if(n?.type===`loop.run_paused`&&n.loopRunId===t){_(!0),y(typeof n.reason==`string`?n.reason:null),s(`running`),d(null);return}if((n?.type===`loop.run_resumed`||n?.type===`loop.run_completed`)&&n.loopRunId===t){_(!1),y(null);return}n?.jobId===t&&(n.type===`job.turn_done`?(typeof n.totals?.total_cost_usd==`number`&&p(n.totals.total_cost_usd),typeof n.totals?.num_turns==`number`&&h(n.totals.num_turns)):n.type===`job.finalized`&&(typeof n.totals?.total_cost_usd==`number`&&p(n.totals.total_cost_usd),typeof n.totals?.num_turns==`number`&&h(n.totals.num_turns),typeof n.status==`string`&&s(n.status),_(!1),y(null),d(qA(n.timestamp)??Date.now())))}),()=>C.unregisterHandler(e)},[C,r,t,w]),(0,Q.useEffect)(()=>{if(!r||!S||c===null)return;let e=setInterval(()=>x(Date.now()),1e3);return()=>clearInterval(e)},[r,S,c]),{status:o,paused:g,pausedReason:v,running:S,elapsedMs:c===null?null:Math.max(0,(u??b)-c),costUsd:f,numTurns:m,loaded:i}}function YA(e){return e.command.startsWith(`loop:`)?`loop-run`:e.interactive?`interactive`:`job`}var XA=15e3;function ZA(e){if(typeof AbortSignal<`u`&&typeof AbortSignal.timeout==`function`)return AbortSignal.timeout(e)}async function QA(e){let{projectId:t,jobId:n,timeoutMs:r=XA}=e,i=t?`${Xe}/api/projects/${t}`:ut(),a;try{a=await fetch(`${i}/jobs/${n}/cancel`,{method:`POST`,signal:ZA(r)})}catch(e){let t=e;return{ok:!1,error:t?.name===`TimeoutError`||t?.name===`AbortError`?`Request timed out after ${Math.round(r/1e3)}s`:t?.message||String(e),httpStatus:null}}if(a.ok){let e=`canceled`;try{let t=await a.json();t&&typeof t.status==`string`&&(e=t.status)}catch{}return{ok:!0,status:e}}let o=typeof a.status==`number`?a.status:null,s=o==null?``:` (HTTP ${o})`,c=``;try{typeof a.text==`function`?c=await a.text():typeof a.json==`function`&&(c=JSON.stringify(await a.json()))}catch{}let l=c.slice(0,200).trim();try{let e=JSON.parse(c);e&&typeof e.error==`string`&&e.error&&(l=e.error)}catch{}let u=typeof a.statusText==`string`?a.statusText:``;return{ok:!1,error:l?`${l}${s}`:`HTTP ${o??`?`}${u?` ${u}`:``}`,httpStatus:o}}var $A=null;function ej(e){$A=e}function tj(e,t){$A?.(e,t)}var nj=(0,Q.lazy)(()=>c(()=>import(`./JobDetailModal-DSsX48Vu.js`).then(e=>({default:e.JobDetailModal})),__vite__mapDeps([6,1,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]))),rj={building:On,on_review:On,pr_draft:A,pr_ready:A,no_changes:$o,completed:$o,pr_closed:Tn,superseded:A,implementation_failed:zn,pr_failed:zn,merged:ks,discarded:Tn},ij={building:`text-accent-primary/70`,on_review:`text-accent-primary`,pr_draft:`text-accent-info`,pr_ready:`text-accent-info`,no_changes:`text-accent-success`,completed:`text-accent-success`,pr_closed:`text-accent-warning`,superseded:`text-foreground/40`,implementation_failed:`text-destructive`,pr_failed:`text-destructive`,merged:`text-accent-success`,discarded:`text-foreground/40`};function aj({envelope:e}){let{t}=K(`agent`),n=It(e);return n.units.length===0&&!n.partial?null:(0,$.jsxs)(`div`,{className:`mt-2 space-y-1.5`,"data-testid":`agent-pr-unit-evidence`,children:[n.partial&&(0,$.jsx)(`p`,{className:`text-[11px] font-medium text-accent-warning`,children:t(`prCard.partialSummary`,{succeeded:n.succeededCount,failed:n.failedCount,total:n.totalCount})}),n.units.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.units.map(e=>{let n=e.implementationOutcome===`failed`||e.implementationOutcome==null&&!e.succeeded,r=e.deliveryOutcome===`no_changes`||e.changed===!1,i=e.deliveryOutcome===`blocked`,a=t(n?`prCard.unit.failed`:i?`prCard.unit.blocked`:r?`prCard.unit.noChanges`:`prCard.unit.succeeded`);return(0,$.jsxs)(`span`,{title:e.failureCode??e.branch,className:X(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[10px]`,n?`border-destructive/35 bg-destructive/10 text-destructive`:i?`border-accent-warning/35 bg-accent-warning/10 text-accent-warning`:`border-accent-success/30 bg-accent-success/10 text-accent-success`),children:[`#`,e.ticketId,` · `,a]},`${e.ticketId}-${e.runId??e.branch}`)})})]})}function oj({prDeliveryId:e,projectId:t}){let{t:n}=K(`agent`),r=y(),{activeProjectId:i,setActiveProjectId:a}=pt();return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{let n=`/review/${e}`;i!==t&&(tj(t,n),a(t)),r(n)},"data-testid":`agent-pr-open-packet`,"data-agent-interactive":!0,title:n(`prCard.openReviewTooltip`),className:`inline-flex items-center gap-1 rounded-md border border-accent-primary/40 bg-accent-primary/10 px-2 py-1 text-[11px] font-medium text-accent-primary transition-colors hover:bg-accent-primary/20`,children:[(0,$.jsx)(vs,{className:`h-3 w-3`}),n(`prCard.openReview`)]})}function sj(e,t,n){if(e.decision===`building`)return n?`paused`:t?.status===`stalled`?`stalled`:`running`;if(t?.active)return`running`;let r=e.runtime?.status;return r===`running`?`running`:r===`failed`||r===`stalled`||r===`cancelled`||r===`succeeded`?r:e.runtime?.failure?e.runtime.failure.code===`stalled`||e.runtime.failure.code===`stuck`?`stalled`:`failed`:e.decision===`implementation_failed`||e.implementationOutcome===`failed`?`failed`:e.decision===`discarded`?`cancelled`:e.decision===`completed`||e.decision===`merged`||e.decision===`on_review`||e.decision===`pr_draft`||e.decision===`pr_ready`||e.decision===`no_changes`?`succeeded`:`unknown`}var cj={running:`border-accent-info/40 bg-accent-info/10 text-accent-info`,paused:`border-accent-warning/40 bg-accent-warning/10 text-accent-warning`,succeeded:`border-accent-success/40 bg-accent-success/10 text-accent-success`,failed:`border-destructive/40 bg-destructive/10 text-destructive`,stalled:`border-accent-warning/40 bg-accent-warning/10 text-accent-warning`,cancelled:`border-border/60 bg-surface/60 text-foreground/55`,unknown:`border-border/60 bg-surface/60 text-foreground/55`};function lj({status:e}){let{t}=K(`agent`);return(0,$.jsxs)(`span`,{"data-testid":`mission-run-status`,"data-status":e,className:X(`inline-flex shrink-0 items-center gap-1 rounded-full border px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide`,cj[e]),children:[(e===`running`||e===`paused`)&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:X(`h-1.5 w-1.5 rounded-full`,e===`running`?`animate-pulse bg-accent-info`:`bg-accent-warning`)}),t(`runCard.status.${e}`)]})}function uj({envelope:e}){let{t}=K(`agent`),n=e.runtime?.failure??null,r=n?.code??e.statusCode??null,i=n?.detail??e.statusDetail??null,a=(e.units??[]).filter(e=>e.failureCode).map(e=>({ticketId:e.ticketId,code:e.failureCode}));return!r&&!i&&a.length===0?null:(0,$.jsxs)(`div`,{className:`mt-2 rounded-md border border-destructive/30 bg-destructive/[0.06] px-2.5 py-2 text-[11px]`,"data-testid":`mission-run-failure`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,$.jsx)(zn,{className:`h-3.5 w-3.5 shrink-0 text-destructive`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`font-medium text-destructive`,children:t(`runCard.failure.title`)}),r&&(0,$.jsx)(`span`,{className:`rounded-full border border-destructive/40 bg-destructive/10 px-2 py-px font-mono text-[10px] text-destructive`,"data-testid":`mission-run-failure-code`,children:r}),n?.stepId&&(0,$.jsx)(`span`,{className:`rounded-full border border-border/60 bg-surface/60 px-2 py-px font-mono text-[10px] text-foreground/60`,children:t(`runCard.failure.step`,{step:n.stepId})})]}),i&&(0,$.jsx)(`p`,{className:`mt-1 break-words leading-4 text-foreground/70`,"data-testid":`mission-run-failure-detail`,children:i}),a.length>0&&(0,$.jsx)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-[10px] text-foreground/55`,children:a.map(e=>(0,$.jsx)(`li`,{children:t(`runCard.failure.unit`,{ticket:e.ticketId,code:e.code})},`${e.ticketId}-${e.code}`))})]})}function dj(e,t){let n=e.runtime;return n?{runId:t,status:n.status,nextStep:n.currentStep,recoverableSteps:n.recoverableSteps,active:n.status===`running`,canResume:n.canResume,canCancel:n.status===`running`,...n.pendingApproval&&n.failure?.stepId?{pendingApproval:{stepId:n.failure.stepId}}:{}}:null}function fj(e){let t=/\/pull\/(\d+)/.exec(e);return t?`#${t[1]}`:null}function pj({projectId:e,runId:t,ticketLabel:n,live:r,onOpen:i,onVitals:a}){let{t:o}=K(`agent`),s=JA(e,t,{live:r}),c=n??t.slice(0,8),l=s.elapsedMs==null?null:GA(s.elapsedMs),u=s.costUsd!=null&&s.costUsd>0,d=(0,$.jsx)(`span`,{"aria-hidden":!0,className:`opacity-40`,children:`·`});return(0,Q.useEffect)(()=>{a?.(t,{paused:s.paused,pausedReason:s.pausedReason})},[a,t,s.paused,s.pausedReason]),(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`pr-run-log-chip`,onClick:e=>{e.stopPropagation(),i(t)},title:o(`prCard.viewLog`,{ref:c}),"aria-label":o(`prCard.viewLog`,{ref:c}),className:X(`inline-flex max-w-full cursor-pointer items-center gap-1 rounded-full border px-1.5 py-px align-baseline font-mono text-[0.82em] leading-[1.45] transition-all`,s.paused?`border-accent-warning/45 bg-accent-warning/10 text-accent-warning hover:-translate-y-px hover:border-accent-warning/65 hover:bg-accent-warning/15 hover:shadow-sm`:`border-accent-info/35 bg-accent-info/10 text-accent-info hover:-translate-y-px hover:border-accent-info/60 hover:bg-accent-info/15 hover:shadow-sm`),children:[(s.paused||s.running&&r)&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:X(`h-1.5 w-1.5 shrink-0 animate-pulse rounded-full`,s.paused?`bg-accent-warning`:`bg-accent-info`)}),(0,$.jsx)(`span`,{className:`max-w-[160px] truncate`,children:c}),d,(0,$.jsx)(yc,{className:`h-3 w-3 shrink-0 opacity-70`}),l&&(0,$.jsxs)($.Fragment,{children:[d,(0,$.jsx)(`span`,{className:`tabular-nums`,"aria-label":o(`prCard.runElapsedAria`,{elapsed:l}),children:l})]}),u&&(0,$.jsxs)($.Fragment,{children:[d,(0,$.jsxs)(`span`,{className:`tabular-nums`,"aria-label":o(`prCard.runCostAria`,{cost:`$${s.costUsd.toFixed(2)}`}),children:[`$`,s.costUsd.toFixed(2)]})]})]})}function mj({envelope:e,conversationId:t}){let{t:n}=K(`agent`),r=u(),{projects:i}=pt(),{applyPrDecisionSnapshot:a}=aP(),{openWebView:o,canOpenWebView:s}=Oe(),{openRef:c}=Rb(),[l,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(null),j=O??e,M=tn(j.projectId).has(j.prDeliveryId),[N,P]=(0,Q.useState)(null),[F,I]=(0,Q.useState)({}),[L,R]=(0,Q.useState)(null),{decision:z,prUrl:B,prState:V}=j,H=ve&&j.hasDelivery===!1,U=ve?j.runtime?.failure??null:null,W=(j.runIds??[])[0]??null,ee=ve&&!!W&&(z===`building`||!!U||z===`implementation_failed`||j.runtime?.status===`running`),te=kr(j.projectId,{jobId:W??void 0,enabled:ee}),ne=te.runs.find(e=>e.runId===W)??te.runs[0]??null,re=ne??(W?dj(j,W):null),[ie,ae]=(0,Q.useState)(!1),oe=(0,Q.useRef)(null),[se,ce]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{if(!ve)return;let e=e=>{let n=e.detail;rO(n,{prDeliveryId:j.prDeliveryId,runIds:j.runIds})&&(oe.current?.scrollIntoView?.({behavior:`smooth`,block:`center`}),ce(!0),t&&clearTimeout(t),t=setTimeout(()=>ce(!1),1400))},t=null;return window.addEventListener(tO,e),()=>{window.removeEventListener(tO,e),t&&clearTimeout(t)}},[j.prDeliveryId,j.runIds]);let ue=se?`ring-2 ring-accent-primary/50 ring-offset-1 ring-offset-background`:``,fe=!!j.repositoryDeliveries?.length,G=It(j),pe=Ft(j.statusCode,j.statusDetail),me=j.operation==null&&pe,he=i.find(e=>e.id===j.projectId)?.name??j.projectId,ge=z===`pr_draft`&&!B,_e=z===`building`&&V===`pr-created`&&!!j.branch,ye=j.prNumber?`#${j.prNumber}`:B?fj(B):null,be=G.terminal,xe=Lt(j.statusCode)?n(`common:prDeliveryStatus.${j.statusCode}`):null,Se=G.partial&&G.deliverableCount>0&&(z===`on_review`||z===`pr_draft`&&!B);(0,Q.useEffect)(()=>{k(null)},[e]);let Ce=(0,Q.useRef)(!1);Ce.current=l!==null||f||j.operation!=null||te.busy!==null,(0,Q.useEffect)(()=>{d(null),h(!1),_(!1),y(!1),x(!1),C(!1),T(!1),D(!1)},[z,B,j.prDeliveryId]);let we=(0,Q.useCallback)((e,t)=>{I(n=>{let r=n[e];return r?.paused===t.paused&&r?.pausedReason===t.pausedReason?n:{...n,[e]:t}})},[]),Te=async e=>{if(!L){R(e);try{let t=await QA({projectId:j.projectId,jobId:e,kind:`loop-run`});t.ok?J.info(n(`prCard.stopExecutionSent`)):J.error(n(`prCard.stopExecutionFailed`),{description:t.error})}finally{R(null)}}},Ee=async(e,r)=>{if(f||l||j.operation||fe&&!r&&[`create-pr`,`merge-local`,`publish`,`poll-merge`,`reopen`,`acknowledge-no-changes`].includes(e))return;let i=j.repositoryDeliveries?.find(e=>e.repositoryId===r),o=i?.integrationBranch??i?.baseBranch??j.baseBranch;d(e);try{let i=await Eo(j.projectId,{prDeliveryId:j.prDeliveryId,action:e,expectedDecision:z,...r?{repositoryId:r}:{},...H&&t?{conversationId:t}:{}}),s=null;if(i.snapshot){let e=Do(j,i.snapshot);s=a(e),s!==`stale`&&k(e)}if(s===`stale`){J.info(n(`prCard.alreadyResolved`));return}if(i.kind===`recovering`)J.info(n(`common:prRecovery.inProgress`));else if(i.kind===`busy`)J.info(n(`prCard.operation.${i.operation??`inProgress`}`));else if(i.kind===`stale`)J.info(n(`prCard.alreadyResolved`));else if(i.kind===`blocked`)J.warning(i.reason===`dirty`?n(`prCard.mergeLocalBlockedDirty`,{base:i.base||o}):n(`prCard.mergeLocalBlockedBranch`,{base:i.base||o,current:i.current??`?`}));else if(i.kind===`failed`)J.error(n(`prCard.actionFailed`),{description:i.detail});else if(i.kind===`ok`&&e===`recover-and-retry`)if(i.deliveryVerified){let e=(i.verifiedSha??i.snapshot?.deliverySha??``).slice(0,8);J.success(n(`prCard.recoverAndRetryVerified`,{sha:e}))}else i.recoveryUnavailable||i.snapshot?.statusCode===`recovery_unavailable`?J.info(n(`prCard.recoveryUnavailable`),{description:n(`prCard.recoveryUnavailableBody`)}):J.warning(n(`prCard.recoveryStillBlocked`),{description:i.detail??void 0});else if(i.kind===`ok`&&e===`create-pr`&&G.retryablePush&&i.deliveryVerified){let e=(i.verifiedSha??i.snapshot?.deliverySha??j.deliverySha??``).slice(0,8);J.success(n(i.pushed?`prCard.retryPushVerified`:`prCard.commitAlreadyVerified`,{sha:e}))}else if(i.kind===`ok`&&e===`create-pr`&&i.detail)J.error(n(`prCard.deliveryNeedsAttention`),{description:i.detail});else if(i.kind===`ok`&&e===`poll-merge`&&i.deliveryVerified===!1)J.warning(n(`prCard.commitMissingRetry`));else if(i.kind===`ok`&&e===`poll-merge`&&i.deliveryVerified&&!i.merged){let e=(i.verifiedSha??i.snapshot?.deliverySha??j.deliverySha??``).slice(0,8);J.success(n(`prCard.prVerifiedWaiting`,{sha:e}))}else e===`poll-merge`&&!i.merged&&i.decision!==`pr_closed`?J.info(n(`prCard.notMergedYet`)):e===`merge-local`&&i.kind===`ok`&&i.decision===`merged`&&J.success(n(`prCard.mergedLocally`,{base:o}));i.kind===`ok`&&(e===`create-pr`||e===`discard`||e===`merge-local`||e===`recover-and-retry`)&&Ht(j.projectId)}catch(e){J.error(n(`prCard.actionFailed`),{description:e instanceof Error?e.message:void 0})}finally{d(null)}},De=async e=>{if(!(fe&&!e)&&!(l||f||j.operation)){p(!0);try{let t=await(e?Oo(j.projectId,j.prDeliveryId,e):Oo(j.projectId,j.prDeliveryId));t.kind===`ok`?(J.success(n(`prCard.checkoutSuccess`,{branch:t.branch??Yt(j)??``})),t.cleanupWarnings.length>0&&J.warning(n(`prCard.cleanupIncomplete`,{count:t.cleanupWarnings.length}),{description:t.cleanupWarnings.join(`
|
|
44
|
+
`),[z]);(0,Q.useEffect)(()=>{y&&!_&&N.current&&(N.current.scrollTop=N.current.scrollHeight)},[z,y,_]);let V=async()=>{if(!(L||I)){O(!0),A(!1);try{await n(o.current)}catch{P.current&&A(!0)}finally{P.current&&O(!1)}}},H=async()=>{try{await navigator.clipboard.writeText(B),P.current&&M(`copied`)}catch{P.current&&M(`failed`)}},U=()=>{let t;try{t=URL.createObjectURL(new Blob([B],{type:`text/plain;charset=utf-8`}));let n=document.createElement(`a`);n.href=t,n.download=`process-${e.pid}-${e.startedAt}.log`,document.body.appendChild(n),n.click(),n.remove()}catch{M(`failed`)}finally{t&&URL.revokeObjectURL(t)}},W=`inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-md border border-border/60 px-2 text-xs text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary disabled:cursor-not-allowed disabled:opacity-40`;return(0,$.jsx)(mr,{open:!0,onOpenChange:e=>{e||t()},children:(0,$.jsxs)($n,{children:[(0,$.jsx)(pr,{className:`z-[80]`}),(0,$.jsxs)(hr,{"data-testid":`background-process-logs-modal`,className:`fixed left-1/2 top-1/2 z-[81] flex h-[min(780px,88vh)] w-[calc(100vw-2rem)] max-w-5xl -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-border/50 bg-popover text-foreground shadow-2xl focus:outline-none`,children:[(0,$.jsxs)(`header`,{className:`flex items-start gap-3 border-b border-border/50 px-4 py-3`,children:[r&&(0,$.jsx)(`button`,{type:`button`,onClick:r,"aria-label":i(`backgroundProcess.history.back`),title:i(`backgroundProcess.history.back`),className:`rounded-md p-1 text-muted-foreground hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary`,children:(0,$.jsx)(un,{className:`h-4 w-4`,"aria-hidden":!0})}),(0,$.jsx)(Ac,{className:`mt-0.5 h-5 w-5 shrink-0 text-accent-info`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,$.jsx)(sr,{className:`text-sm font-semibold`,children:i(`backgroundProcess.logsTitle`)}),(0,$.jsx)(`span`,{"data-testid":`background-process-status`,className:`rounded-full px-2 py-0.5 text-[11px] ${F.status===`failed`?`bg-destructive/10 text-destructive`:I?`bg-muted text-muted-foreground`:`bg-accent-info/10 text-accent-info`}`,children:i(`backgroundProcess.status.${L?`stopping`:F.status}`)}),(0,$.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:R})]}),(0,$.jsx)(ir,{className:`mt-1 text-xs text-muted-foreground`,children:i(`backgroundProcess.logsDescription`)})]}),(0,$.jsx)(lr,{className:`rounded-md p-1.5 text-muted-foreground hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary`,"aria-label":i(`backgroundProcess.close`),children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 border-b border-border/50 px-4 py-3 text-xs`,children:[(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:i(`backgroundProcess.command`)}),(0,$.jsx)(`dd`,{className:`break-all font-mono`,children:SA(F.command)}),(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:i(`backgroundProcess.directory`)}),(0,$.jsx)(`dd`,{className:`break-all font-mono text-muted-foreground`,children:SA(F.cwd)}),(F.repositoryName||F.repositoryId)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:i(`backgroundProcess.repository`)}),(0,$.jsx)(`dd`,{className:`break-all text-muted-foreground`,children:SA(F.repositoryName??F.repositoryId??``)})]}),(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:`PID`}),(0,$.jsxs)(`dd`,{className:`flex flex-wrap gap-x-4 gap-y-1 font-mono text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:F.pid}),F.exitCode!=null&&(0,$.jsx)(`span`,{children:i(`backgroundProcess.exitCode`,{code:F.exitCode})}),F.signal&&(0,$.jsx)(`span`,{children:i(`backgroundProcess.signal`,{signal:F.signal})})]})]}),F.error&&(0,$.jsx)(`p`,{role:`alert`,className:`border-b border-border/40 bg-destructive/5 px-4 py-2 text-xs text-destructive`,children:SA(F.error).slice(0,1e3)}),F.status===`interrupted`&&(0,$.jsx)(`p`,{role:`status`,className:`border-b border-border/40 bg-amber-500/5 px-4 py-2 text-xs text-amber-700 dark:text-amber-300`,children:i(`backgroundProcess.interruptedHint`)}),F.persistenceError&&(0,$.jsx)(`p`,{role:`alert`,className:`border-b border-border/40 bg-amber-500/5 px-4 py-2 text-xs text-amber-700 dark:text-amber-300`,children:i(`backgroundProcess.persistenceFailed`)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-border/50 px-4 py-2.5`,children:[(0,$.jsxs)(`label`,{className:`relative min-w-[150px] flex-1`,children:[(0,$.jsx)(In,{className:`pointer-events-none absolute left-2.5 top-2 h-4 w-4 text-muted-foreground`,"aria-hidden":!0}),(0,$.jsx)(`input`,{type:`search`,value:x,onChange:e=>S(e.target.value),placeholder:i(`backgroundProcess.search`),"aria-label":i(`backgroundProcess.search`),className:`h-8 w-full rounded-md border border-border/60 bg-background/50 pl-8 pr-2 text-xs outline-none focus:border-accent-primary/60`})]}),(0,$.jsxs)(`select`,{"aria-label":i(`backgroundProcess.source`),value:C,onChange:e=>w(e.target.value),className:`h-8 rounded-md border border-border/60 bg-background px-2 text-xs outline-none focus:border-accent-primary/60`,children:[(0,$.jsx)(`option`,{value:`all`,children:i(`backgroundProcess.allSources`)}),(0,$.jsx)(`option`,{value:`stdout`,children:`stdout`}),(0,$.jsx)(`option`,{value:`stderr`,children:`stderr`})]}),!I&&(0,$.jsxs)(`button`,{type:`button`,className:W,"aria-pressed":_,onClick:()=>v(e=>!e),children:[_?(0,$.jsx)(Mn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}):(0,$.jsx)(ic,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(_?`backgroundProcess.resume`:`backgroundProcess.pause`)]}),(0,$.jsxs)(`button`,{type:`button`,className:`${W} ${y?`border-accent-info/40 text-accent-info`:``}`,"aria-pressed":y,onClick:()=>b(e=>!e),children:[(0,$.jsx)(Io,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(`backgroundProcess.follow`)]}),(0,$.jsx)(`button`,{type:`button`,className:W,disabled:!z.length,onClick:()=>void H(),"aria-label":i(`backgroundProcess.copy`),title:i(`backgroundProcess.copy`),children:j===`copied`?(0,$.jsx)(Sn,{className:`h-3.5 w-3.5`}):(0,$.jsx)(ls,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,className:W,disabled:!z.length,onClick:U,"aria-label":i(`backgroundProcess.download`),title:i(`backgroundProcess.download`),children:(0,$.jsx)(En,{className:`h-3.5 w-3.5`})}),!I&&(0,$.jsxs)(`button`,{type:`button`,className:`${W} text-destructive`,disabled:L,onClick:()=>void V(),children:[L?(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Nn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(L?`backgroundProcess.status.stopping`:`backgroundProcess.stop`)]})]}),h&&(0,$.jsx)(`p`,{role:`status`,className:`border-b border-border/40 bg-amber-500/5 px-4 py-2 text-xs text-amber-600 dark:text-amber-400`,children:i(`backgroundProcess.truncated`)}),_&&!I&&(0,$.jsx)(`p`,{role:`status`,className:`border-b border-border/40 bg-muted/20 px-4 py-2 text-xs text-muted-foreground`,children:i(`backgroundProcess.paused`)}),p&&(0,$.jsxs)(`div`,{role:`alert`,className:`flex items-center gap-2 border-b border-border/40 bg-destructive/5 px-4 py-2 text-xs text-destructive`,children:[(0,$.jsx)(Qo,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`flex-1`,children:i(`backgroundProcess.loadFailed`)}),(0,$.jsx)(`button`,{type:`button`,className:W,onClick:()=>{v(!1),E(e=>e+1)},children:i(`backgroundProcess.retry`)})]}),(k||e.stopError)&&(0,$.jsx)(`p`,{role:`alert`,className:`bg-destructive/5 px-4 py-2 text-xs text-destructive`,children:i(`backgroundProcess.stopFailed`)}),j&&(0,$.jsx)(`p`,{role:j===`failed`?`alert`:`status`,className:`px-4 py-1 text-xs text-muted-foreground`,children:i(j===`copied`?`backgroundProcess.copied`:`backgroundProcess.exportFailed`)}),(0,$.jsx)(`div`,{ref:N,"data-testid":`background-process-log-output`,"aria-label":i(`backgroundProcess.output`),role:`region`,tabIndex:0,onScroll:e=>{let t=e.currentTarget;t.scrollHeight-t.clientHeight-t.scrollTop>40&&b(!1)},className:`min-h-0 flex-1 overflow-auto bg-background/80 px-3 py-3 font-mono text-[11px] leading-5 outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-accent-primary/50`,children:d&&!l.length?(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center justify-center gap-2 py-12 text-muted-foreground`,children:[(0,$.jsx)(An,{className:`h-4 w-4 animate-spin`,"aria-hidden":!0}),i(`backgroundProcess.loading`)]}):z.length?z.map(e=>(0,$.jsxs)(`div`,{"data-log-source":e.source,className:`grid grid-cols-[auto_auto_minmax(0,1fr)] items-start gap-x-2 hover:bg-muted/20`,children:[(0,$.jsx)(`span`,{className:`select-none whitespace-nowrap text-[10px] text-muted-foreground/70`,children:new Date(e.at).toLocaleTimeString(void 0,{hour12:!1})}),(0,$.jsx)(`span`,{className:`select-none text-[10px] ${e.source===`stderr`?`text-amber-600 dark:text-amber-400`:`text-muted-foreground/60`}`,children:e.source}),(0,$.jsx)(`span`,{className:`whitespace-pre-wrap break-words [overflow-wrap:anywhere] ${e.source===`stderr`?`text-amber-700 dark:text-amber-200`:`text-foreground/90`}`,children:e.line||`\xA0`})]},e.sequence)):!p&&(0,$.jsx)(`p`,{className:`py-12 text-center font-sans text-xs text-muted-foreground`,children:i(l.length?`backgroundProcess.noMatches`:`backgroundProcess.empty`)})}),(0,$.jsxs)(`footer`,{className:`flex flex-wrap justify-between gap-1 border-t border-border/50 px-4 py-2 text-[10px] text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:i(`backgroundProcess.lineCount`,{count:z.length,total:l.length})}),(0,$.jsx)(`span`,{children:i(`backgroundProcess.exportHint`)})]})]})]})})}function DA({processes:e,loading:t,error:n,onRefresh:r,onClose:i,onKill:a}){let{t:o}=K(`agent`),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(100),[d,f]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{r()},[r]);let p=(0,Q.useMemo)(()=>{let t=s.trim().toLocaleLowerCase();return e.filter(e=>!t||[e.command,e.cwd,e.repositoryName,e.repositoryId,e.pid,o(`backgroundProcess.status.${e.status}`)].join(` `).toLocaleLowerCase().includes(t)).sort((e,t)=>Number(_A(e))-Number(_A(t))||t.startedAt-e.startedAt)},[e,s,o]);if(d)return(0,$.jsx)(TA,{process:e.find(e=>dO(e)===dO(d))??d,onClose:i,onBack:()=>f(null),onKill:a});let m=`inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-md border border-border/60 px-2 text-xs text-muted-foreground hover:bg-muted/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary disabled:opacity-40`;return(0,$.jsx)(mr,{open:!0,onOpenChange:e=>{e||i()},children:(0,$.jsxs)($n,{children:[(0,$.jsx)(pr,{className:`z-[80]`}),(0,$.jsxs)(hr,{"data-testid":`background-process-history-modal`,className:`fixed left-1/2 top-1/2 z-[81] flex max-h-[85vh] w-[calc(100vw-2rem)] max-w-3xl -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-border/50 bg-popover text-foreground shadow-2xl focus:outline-none`,children:[(0,$.jsxs)(`header`,{className:`flex items-start gap-3 border-b border-border/50 px-4 py-3`,children:[(0,$.jsx)(Ac,{className:`mt-0.5 h-5 w-5 shrink-0 text-accent-info`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(sr,{className:`text-sm font-semibold`,children:o(`backgroundProcess.history.title`)}),(0,$.jsx)(ir,{className:`mt-1 text-xs text-muted-foreground`,children:o(`backgroundProcess.history.description`)})]}),(0,$.jsx)(lr,{className:`rounded-md p-1.5 text-muted-foreground hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary`,"aria-label":o(`backgroundProcess.history.close`),children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 border-b border-border/50 px-4 py-3`,children:[(0,$.jsxs)(`label`,{className:`relative min-w-0 flex-1`,children:[(0,$.jsx)(In,{className:`pointer-events-none absolute left-2.5 top-2 h-4 w-4 text-muted-foreground`,"aria-hidden":!0}),(0,$.jsx)(`input`,{type:`search`,value:s,onChange:e=>{c(e.target.value),u(100)},placeholder:o(`backgroundProcess.history.search`),"aria-label":o(`backgroundProcess.history.search`),className:`h-8 w-full rounded-md border border-border/60 bg-background/50 pl-8 pr-2 text-xs outline-none focus:border-accent-primary/60`})]}),(0,$.jsx)(`button`,{type:`button`,className:m,disabled:t,onClick:()=>void r(),"aria-label":o(`backgroundProcess.history.refresh`),title:o(`backgroundProcess.history.refresh`),children:(0,$.jsx)(mc,{className:`h-3.5 w-3.5 ${t?`animate-spin`:``}`,"aria-hidden":!0})})]}),n&&(0,$.jsxs)(`div`,{role:`alert`,className:`flex items-center gap-2 border-b border-border/40 bg-destructive/5 px-4 py-2 text-xs text-destructive`,children:[(0,$.jsx)(Qo,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`flex-1`,children:o(`backgroundProcess.history.loadFailed`)}),(0,$.jsx)(`button`,{type:`button`,className:m,onClick:()=>void r(),children:o(`backgroundProcess.retry`)})]}),(0,$.jsxs)(`div`,{className:`min-h-[160px] overflow-y-auto p-2`,children:[p.slice(0,l).map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f(e),"aria-label":o(`backgroundProcess.open`,{command:e.command}),className:`flex w-full items-center gap-3 rounded-lg px-3 py-3 text-left hover:bg-muted/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent-primary`,children:[(0,$.jsx)(Ac,{className:`h-4 w-4 shrink-0 ${_A(e)?`text-muted-foreground`:`text-accent-info`}`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate font-mono text-xs text-foreground`,children:SA(e.command)}),(0,$.jsxs)(`span`,{className:`mt-1 block truncate text-[11px] text-muted-foreground`,children:[SA(e.repositoryName??e.cwd),` · `,new Date(e.startedAt).toLocaleString(),` · PID `,e.pid]})]}),(0,$.jsx)(`span`,{className:`max-w-[35%] shrink-0 rounded-full px-2 py-0.5 text-[10px] ${e.status===`failed`?`bg-destructive/10 text-destructive`:_A(e)?`bg-muted text-muted-foreground`:`bg-accent-info/10 text-accent-info`}`,children:o(`backgroundProcess.status.${e.status}`)}),(0,$.jsx)(Zo,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`,"aria-hidden":!0})]},dO(e))),t&&!e.length?(0,$.jsxs)(`p`,{role:`status`,className:`flex justify-center gap-2 py-12 text-xs text-muted-foreground`,children:[(0,$.jsx)(An,{className:`h-4 w-4 animate-spin`,"aria-hidden":!0}),o(`backgroundProcess.history.loading`)]}):!n&&!p.length&&(0,$.jsx)(`p`,{className:`px-4 py-12 text-center text-xs text-muted-foreground`,children:o(s.trim()?`backgroundProcess.history.noMatches`:`backgroundProcess.history.empty`)}),p.length>l&&(0,$.jsx)(`div`,{className:`py-2 text-center`,children:(0,$.jsx)(`button`,{type:`button`,className:m,onClick:()=>u(e=>e+100),children:o(`backgroundProcess.history.showMore`)})})]}),(0,$.jsx)(`footer`,{className:`border-t border-border/50 px-4 py-2 text-[10px] text-muted-foreground`,children:o(`backgroundProcess.history.count`,{count:p.length})})]})]})})}function OA(e={}){let t=e.enabled!==!1,[n,r]=(0,Q.useState)({available:{},availableIds:[],issues:{},launchDescriptors:{},labels:{},loading:!0}),[i,a]=(0,Q.useState)(0);return(0,Q.useEffect)(()=>{if(!t)return;let e=0,n=()=>{let t=Date.now();t-e<3e4||(e=t,a(e=>e+1))},r=()=>{e=0,n()};return window.addEventListener(`focus`,n),window.addEventListener(`specrails:providers-detected-changed`,r),()=>{window.removeEventListener(`focus`,n),window.removeEventListener(`specrails:providers-detected-changed`,r)}},[t]),(0,Q.useEffect)(()=>{if(!t)return;let e=!0;return fetch(`${Xe}/api/available-providers`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}).then(t=>{if(!e)return;let n={};for(let[e,r]of Object.entries(t))e===`tiers`||e===`providerIssues`||e===`launchDescriptors`||e===`labels`||typeof r==`boolean`&&(n[e]=r);let i=t.providerIssues&&typeof t.providerIssues==`object`?t.providerIssues:{},a=t.launchDescriptors&&typeof t.launchDescriptors==`object`?t.launchDescriptors:{},o={};if(t.labels&&typeof t.labels==`object`)for(let[e,n]of Object.entries(t.labels))typeof n==`string`&&(o[e]=n);r({available:n,availableIds:Object.keys(n).filter(e=>n[e]),issues:i,launchDescriptors:a,labels:o,loading:!1})}).catch(()=>{e&&r(e=>({...e,loading:!1}))}),()=>{e=!1}},[t,i]),n}function kA(e,t,n,r,i){let a=i.length-(r-n);return{text:`${e.slice(0,n)}${i}${e.slice(r)}`,references:t.flatMap(e=>e.end<=n?[e]:e.start>=r?[{...e,start:e.start+a,end:e.end+a}]:[])}}var AA=[],jA=[];function MA({autoFocus:e=!1,hideProjectSelector:t=!1,queueEditRequest:n}){let{t:r}=K(`agent`),{active:i,messages:a,conversations:o,isStreaming:s,providersReady:c,draftPinnedProjectId:l,draftProvider:u,draftModel:d,draftTierLevel:f,draftEffort:p,setEffort:m,send:h,abort:g,cycleTier:_,setProvider:v,setModel:y,setPinnedProject:b,materializeDraftConversation:x,queuedMessages:S,editQueuedMessage:C,wasQueueConsumed:w}=aP(),T=(0,Q.useMemo)(()=>S.filter(e=>e.deliveryMode!==`steer`),[S]),{pendingCaptures:E,consumePendingCaptures:D,openBrowser:O}=lO(),{processes:k,history:A=k,historyLoading:j=!1,historyError:M=null,refreshHistory:N,kill:P}=wO(),[F,I]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(null),z=(0,Q.useMemo)(()=>[...k].sort((e,t)=>Number(_A(e))-Number(_A(t))||t.startedAt-e.startedAt).slice(0,4),[k]),{projects:B,activeProjectId:V}=pt(),H=i?.pinned_project_id??l??V,U=i?.id??`__new-mission__`,W=Ci(),ee=(0,Q.useRef)(null);ee.current!==U&&(di(U),ee.current=U),Xr(U);let[te,ne]=(0,Q.useState)(null),re=te&&te.key===U?te:null,ie=re?re.text:Vr.get(U)??``,ae=re?AA:Ur.get(U)??AA,oe=Hr.get(U)??jA,se=(e,t=[])=>Zr(U,e,t),[ce,le]=(0,Q.useState)(null),ue=(e,t)=>{let n=Hr.get(e)??jA;Qr(e,typeof t==`function`?t(n):t)},[de,fe]=(0,Q.useState)(!1),[G,pe]=(0,Q.useState)(!1),me=(0,Q.useRef)(!1),he=(0,Q.useRef)(null),ge=(0,Q.useRef)(null),_e=(0,Q.useMemo)(()=>[...new Map(ae.map(({chip:e})=>[JSON.stringify([e.projectId,MO(e)]),e])).values()],[ae]),[ve,ye]=(0,Q.useState)(null),[be,xe]=(0,Q.useState)(0),[Se,Ce]=(0,Q.useState)(!1),[we,Te]=(0,Q.useState)([]),[Ee,De]=(0,Q.useState)([]),[Oe,ke]=(0,Q.useState)([]),Ae=ce!==null,je=(0,Q.useMemo)(()=>a.filter(e=>e.role===`user`).map(e=>e.content),[a]),Me=re?.queueId??null,Ne=(0,Q.useRef)(``),Pe=Me===null?-1:T.findIndex(e=>e.queueId===Me),Fe=Pe>=0?T[Pe]:null,Le=re!==null;(0,Q.useEffect)(()=>{if(de||G||Le)return Gy(U)},[U,de,G,Le]);let Re=c===!1||(i?!W.isEditable(i.id):!!W.current),ze=!Re&&!Le,Be=i?.provider??u,{availableIds:Ve,labels:He}=OA(),Ue=(0,Q.useMemo)(()=>[Be,...Ve].filter((e,t,n)=>n.indexOf(e)===t),[Be,Ve]),We=e=>r(`provider.${e}`,{defaultValue:He?.[e]??e}),Ge=i?i.pinned_project_id:l,Ke=Ge,qe=ve?.mode===`reference`?ve.query.trim():``,Je=`${Ke??``}:${qe}`,[Ye,Ze]=(0,Q.useState)({key:``,items:[]});(0,Q.useEffect)(()=>{let e=B.find(e=>e.id===Ke);if(!e||qe.length<2)return;let t=new AbortController,n=setTimeout(()=>{let n=new URLSearchParams({kind:`find`,q:qe,limit:`20`});fetch(`${Xe}/api/projects/${encodeURIComponent(e.id)}/code/discover?${n}`,{signal:t.signal}).then(async n=>{if(!n.ok)return;let r=await n.json();t.signal.aborted||Ze({key:Je,items:DO(e,r.matches??[])})}).catch(()=>{})},180);return()=>{clearTimeout(n),t.abort()}},[Ke,B,qe,Je]);let Qe=(0,Q.useMemo)(()=>({projects:B,conversations:o,activeConversation:i,pinnedProjectId:Ke,activeProjectId:V,tickets:we,jobs:Ee,rails:Oe,chips:_e}),[B,o,i,Ke,V,we,Ee,Oe,_e]),$e=(0,Q.useMemo)(()=>ve?[...JO(ve.mode,Qe),...ve.mode===`reference`&&qe.length>=2&&Ye.key===Je?Ye.items:[]]:[],[ve,Qe,Ye,Je,qe]),et=(0,Q.useMemo)(()=>{if(!ve)return[];let e=HO($e,ve.query);return e.length>0?e:YO(ve.mode,ve.query)},[$e,ve]),tt=ve!==null&&!Le,nt=ie.trim().length>0||_e.length>0,rt=[`accent-primary`,`accent-info`,`accent-highlight`],it=i?.id??null;(0,Q.useEffect)(()=>{I(null),R(null)},[it,H]),(0,Q.useEffect)(()=>{le(null),ye(null),Ce(!1),ne(null)},[it]),(0,Q.useEffect)(()=>{if(!Ke){Te([]),De([]),ke([]);return}let e=!0;return(async()=>{try{let[t,n]=await Promise.all([fetch(`${Xe}/api/projects/${encodeURIComponent(Ke)}/tickets`),fetch(`${Xe}/api/projects/${encodeURIComponent(Ke)}/jobs?limit=25`)]),r=await t.json(),i=await n.json();if(!e)return;Te(Array.isArray(r.tickets)?r.tickets:[]),De(Array.isArray(i.jobs)?i.jobs:[])}catch{if(!e)return;Te([]),De([])}try{let t=await fetch(`${Xe}/api/projects/${encodeURIComponent(Ke)}/rails`),n=t.ok?await t.json():null;if(!e)return;ke(OO(n))}catch{e&&ke([])}})(),()=>{e=!1}},[Ke]),(0,Q.useEffect)(()=>{xe(0)},[ve?.mode,ve?.query]),(0,Q.useEffect)(()=>{be>=et.length&&xe(Math.max(0,et.length-1))},[be,et.length]),(0,Q.useEffect)(()=>{if(E.length===0)return;let e=D();e.length&&ue(U,t=>[...t,...e])},[E,D,U]);let at=ok(Be),{models:ot,efforts:st,supportsImageInput:ct,customModelAliases:lt}=at,q=(i?i.model:d)??ot.find(e=>e.default)?.value??ot[0]?.value??``,ut=vt(Be,q),dt=st.filter(e=>ut.includes(e)),ft=i?i.reasoning_effort:p,mt=ft&&dt.includes(ft)?ft:Dt(Be,q)??``,Y=e=>{pi(e)},ht=async e=>{if(e.length===0)return;fe(!0);let t=i;if(!t)try{t=await x(),Y(t.id)}catch(e){J.error(e instanceof Error?e.message:r(`workspace.uploadFailed`)),fe(!1);return}for(let n of e){if(!ct&&n.type.startsWith(`image/`)){J.error(r(`imagesUnsupported`));continue}try{let e=await co(t.id,n);ue(t.id,t=>[...t,e])}catch(e){J.error(e instanceof Error?e.message:r(`workspace.uploadFailed`))}}fe(!1)},gt=async e=>{try{i&&await po(i.id,e),ue(U,t=>t.filter(t=>t.id!==e))}catch(e){J.error(e instanceof Error?e.message:`Failed to remove attachment.`)}},_t=(e,t,n=ae)=>{if(n.some(e=>t>e.start&&t<=e.end)){ye(null);return}let r=jO(e,t);ye(r),r&&Ce(!1)},yt=e=>e===`reference`?`@`:e===`trace`?`#`:`/`,bt=e=>{requestAnimationFrame(()=>{ge.current?.focus(),ge.current?.setSelectionRange(e,e)})},xt=e=>{if(Le)return;let t=yt(e),n=ge.current,r=n?.selectionStart??ie.length,i=n?.selectionEnd??r,a=kA(ie,ae,r,i,t);se(a.text,a.references),le(null),Ce(!1),ye({mode:e,trigger:t,query:``,start:r,end:r+1}),bt(r+1)},St=e=>{ge.current?.focus();let t=XO(ie,ve,e),n=ve?.start??ie.length,r=ve?.end??n,i=t.text.slice(n,t.caret),{references:a}=kA(ie,ae,n,r,i);if(e.chip){let t=n+i.indexOf(e.chip.token);a.push({key:crypto.randomUUID(),start:t,end:t+e.chip.token.length,chip:e.chip}),a.sort((e,t)=>e.start-t.start)}se(t.text,a),le(null),ye(null),Ce(!1),bt(t.caret)},Ct=e=>{let t=T[e];t&&(Ne.current=t.text,ne({key:U,queueId:t.queueId,text:t.text}))},wt=e=>{Ae&&se(``),le(null),Ct(e)};(0,Q.useEffect)(()=>{if(!n||n.conversationId!==i?.id)return;let e=T.findIndex(e=>e.queueId===n.queueId);e<0||(Le?Ct(e):wt(e),bt(T[e].text.length))},[n]);let Tt=(e,t)=>{let n=t??ie;ne(null),e===`keep`&&se(n)},Et=async()=>{let e=Fe,t=ie.trim();if(!(!e||!t))try{await C(e.queueId,t)===`saved`?Tt(`restore`):(J.info(r(`queueEdit.dispatched`)),Tt(`keep`))}catch{J.error(r(`queueEdit.saveFailed`))}};(0,Q.useEffect)(()=>{if(!re||T.some(e=>e.queueId===re.queueId))return;let e=ie!==Ne.current;w(re.queueId)&&J.info(r(`queueEdit.dispatched`)),Tt(e?`keep`:`restore`)},[Me,T,Le]);let Ot=async()=>{if(Re||!nt||me.current)return;let e=ie.trim()||_e.map(e=>e.token).join(` `),t={...oe.length?{attachmentIds:oe.map(e=>e.id)}:{},..._e.length?{contextRefs:_e.map(NO)}:{}},n=JSON.stringify([e,t]),i=Wr.get(U),a=i?.signature===n?i:{signature:n,queueId:`q-${crypto.randomUUID()}`},o={text:ie,references:ae,attachments:oe,submission:a};$r(U,a),ni(U,o),ye(null),Ce(!1),le(null),me.current=!0,pe(!0);try{let n=await h(e,{...t,queueId:a.queueId}),r=n.conversationId??U;if(!n.accepted){$r(r,a),ri(r,o);return}$r(U,null),$r(r,null)}catch(e){ri(U,o),J.error(e instanceof Error?e.message:r(`queueEdit.saveFailed`))}finally{me.current=!1,pe(!1)}},kt=e=>{if(je[e]===void 0){le(null);return}le(e),se(je[e])};return(0,$.jsxs)(`div`,{className:`shrink-0`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-2`,children:[i===null&&!t&&(0,$.jsx)(ZO,{pinnedProjectId:l,onSelect:e=>void b(e)}),(0,$.jsx)(KE,{label:r(`provider.label`),value:Be,options:Ue.map(e=>({value:e,label:We(e)})),icon:Vo,onSelect:e=>{v(e).catch(()=>J.error(r(`error.generic`)))},testId:`agent-provider-selector`}),(0,$.jsx)(ik,{models:ot,model:i?i.model:d,status:at.status,customModelAliases:lt,onSelect:e=>{y(e).catch(()=>J.error(r(`error.generic`)))}}),dt.length>0&&(0,$.jsx)(KE,{label:r(`effort.label`),value:mt,options:dt.map(e=>({value:e,label:r(`effort.${e}`)})),icon:Ds,onSelect:e=>{m(e).catch(()=>J.error(r(`error.generic`)))},testId:`agent-effort-selector`}),(0,$.jsx)(`div`,{className:`ml-auto`,children:(0,$.jsx)(ek,{level:i?.tier_level??f,onCycle:()=>void _()})})]}),Le&&Fe&&(0,$.jsxs)(`div`,{"data-testid":`queue-edit-chip`,className:`mb-1 flex items-center gap-1.5 rounded-md border border-accent-highlight/30 bg-accent-highlight/10 px-2 py-1 text-[11px] text-accent-highlight`,children:[(0,$.jsx)(jn,{className:`h-3 w-3 shrink-0`}),(0,$.jsx)(`span`,{className:`font-medium`,children:r(`queueEdit.editing`,{n:Pe+1,m:T.length})}),(0,$.jsx)(`span`,{className:`truncate text-foreground/45`,children:r(`queueEdit.hint`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>Tt(`restore`),"aria-label":r(`queueEdit.cancel`),title:r(`queueEdit.cancel`),className:`ml-auto rounded-sm p-0.5 text-foreground/50 hover:bg-muted hover:text-foreground`,children:(0,$.jsx)(Vn,{className:`h-3 w-3`})})]}),Ae&&(0,$.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5 px-1 text-[11px] text-foreground/50`,children:[(0,$.jsx)(Fs,{className:`h-3 w-3`}),r(`history.hint`)]}),oe.length>0&&(0,$.jsx)(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-1.5`,children:oe.map(e=>(0,$.jsx)(EO,{conversationId:it,attachment:e,removeLabel:r(`close`),onRemove:()=>gt(e.id)},e.id))}),(k.length>0||it&&H)&&(0,$.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-1.5`,children:[it&&H&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>R({chatId:it,projectId:H}),"aria-label":r(`backgroundProcess.history.open`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border/50 px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/40 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary`,children:[(0,$.jsx)(Ac,{className:`h-3 w-3`,"aria-hidden":!0}),r(`backgroundProcess.history.button`),A.length>0&&(0,$.jsx)(`span`,{className:`font-mono text-[10px]`,children:A.length})]}),z.map((e,t)=>(0,$.jsx)(gA,{process:e,accentVariant:rt[t%rt.length],onKill:P,onOpen:I},dO(e)))]}),(0,$.jsxs)(`div`,{className:`relative flex items-end gap-2 rounded-xl border bg-background/60 px-3 py-2 ${Le?`border-accent-highlight/50`:Ae?`border-accent-info/40`:`border-border/60`}`,onDragOver:e=>{ze&&e.preventDefault()},onDrop:e=>{if(!ze)return;e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length&&ht(t)},children:[tt&&(0,$.jsx)(dk,{items:et,mode:ve.mode,query:ve.query,activeIndex:be,onActiveIndexChange:xe,onSelect:St}),ze&&(0,$.jsx)($.Fragment,{children:(0,$.jsx)(`input`,{ref:he,type:`file`,multiple:!0,hidden:!0,onChange:e=>{let t=Array.from(e.target.files??[]);t.length&&ht(t),e.target.value=``}})}),!Le&&(0,$.jsx)(fk,{open:Se,canAttach:ze,uploading:de,onToggle:()=>{Ce(e=>!e),ye(null)},onClose:()=>Ce(!1),onOpenMode:xt,onAttachFile:()=>{Ce(!1),he.current?.click()},canBrowserCapture:Ie()&&!!(Ke??V),onOpenBrowser:()=>{Ce(!1),O()}}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsx)(wk,{ref:ge,value:ie,references:Le?[]:ae,autoFocus:e,onChange:(e,t,n)=>{if(Le){ne(t=>t&&{...t,text:e});return}Ae&&le(null),se(e,t),_t(e,n,t)},onSelect:e=>{Le||_t(ge.current?.value??ie,e)},onKeyDown:e=>{if(e.nativeEvent.isComposing)return;if(e.key===`Tab`&&e.shiftKey){e.preventDefault(),e.stopPropagation(),_();return}if(tt){if(e.key===`ArrowDown`){e.preventDefault(),et.length>0&&xe(e=>Math.min(et.length-1,e+1));return}if(e.key===`ArrowUp`){e.preventDefault(),et.length>0&&xe(e=>Math.max(0,e-1));return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let t=et[be]??et[0];t&&St(t);return}if(e.key===`Escape`){e.preventDefault(),ye(null);return}}if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),Le?Et():Ot();return}if(e.key===`Escape`&&Le){e.preventDefault(),e.stopPropagation(),Tt(`restore`);return}let t=ge.current,n=t?.selectionStart===0&&t?.selectionEnd===0,r=t?.selectionStart===ie.length&&t?.selectionEnd===ie.length;if(e.key===`ArrowUp`){if(Le){Fe!==null&&ie===Fe.text&&n&&Pe>0&&(e.preventDefault(),Ct(Pe-1));return}if(T.length>0){n&&(e.preventDefault(),wt(T.length-1));return}!Ae&&ie===``&&je.length>0?(e.preventDefault(),kt(je.length-1)):Ae&&(e.preventDefault(),kt(Math.max(0,ce-1)));return}if(e.key===`ArrowDown`){if(Le){Fe!==null&&ie===Fe.text&&r&&(e.preventDefault(),Pe<T.length-1?Ct(Pe+1):Tt(`restore`));return}if(T.length>0)return;Ae&&(e.preventDefault(),ce<je.length-1?kt(ce+1):(le(null),se(``)));return}(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&Ae&&le(null)},onPaste:e=>{if(!ze)return;let t=Array.from(e.clipboardData.files);t.length&&(e.preventDefault(),ht(t))},disabled:Re,placeholder:r(Re?`noProvider.placeholder`:s?`queue.placeholder`:`composerPlaceholder`),title:Le?r(`queueEdit.hint`):Ae?r(`history.hint`):void 0,className:`min-h-[3.25rem] max-h-64 min-w-0 w-full resize-y overflow-y-auto bg-transparent text-sm outline-none ${Ae?`italic text-foreground/50`:`text-foreground`}`},U)}),s&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>void g(),"aria-label":r(`stop`),title:r(`stop`),className:`rounded-lg bg-destructive p-1.5 text-white transition-colors hover:opacity-90`,children:(0,$.jsx)(Nn,{className:`h-4 w-4`,fill:`currentColor`})}),Le?(0,$.jsx)(`button`,{type:`button`,onClick:()=>void Et(),disabled:Re||!ie.trim(),"aria-label":r(`queueEdit.save`),title:r(`queueEdit.save`),className:`rounded-lg bg-accent-highlight p-1.5 text-white transition-opacity hover:opacity-90 disabled:opacity-40`,children:(0,$.jsx)(Sn,{className:`h-4 w-4`})}):s?(0,$.jsx)(`button`,{type:`button`,onClick:Ot,disabled:Re||!nt||G,"aria-label":r(`queue.send`),title:r(`queue.sendHint`),className:`relative rounded-lg bg-accent-info p-1.5 text-white transition-colors hover:opacity-90`,children:(0,$.jsx)(Pt,{className:`h-4 w-4`})}):(0,$.jsx)(`button`,{type:`button`,onClick:Ot,disabled:Re||!nt||G,"aria-label":r(`send`),className:`rounded-lg bg-accent-primary p-1.5 text-white transition-opacity disabled:opacity-40`,children:(0,$.jsx)(Pt,{className:`h-4 w-4`})})]}),Ge&&(0,$.jsx)(sk,{projectId:Ge}),F&&F.chatId===it&&F.projectId===H&&(0,$.jsx)(TA,{process:A.find(e=>dO(e)===dO(F))??F,onClose:()=>I(null),onKill:P}),L&&L.chatId===it&&L.projectId===H&&(0,$.jsx)(DA,{processes:A,loading:j,error:M,onRefresh:N,onClose:()=>R(null),onKill:P})]})}function NA({active:e,inset:t=-4,radius:n=`9999px`,className:r,fadeInMs:i=350,fadeOutMs:a=350}){let o=My();return(0,$.jsx)(N_,{children:e&&(0,$.jsxs)(Ny.span,{"aria-hidden":!0,"data-testid":`builder-halo`,"data-reduced-motion":o?`true`:void 0,initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1,transition:{duration:i/1e3,ease:`easeOut`}},exit:{opacity:0,scale:1.15,transition:{duration:a/1e3,ease:`easeInOut`}},style:{inset:t},className:`pointer-events-none absolute ${r??``}`,children:[(0,$.jsx)(`span`,{className:`absolute inset-0 overflow-hidden`,style:{borderRadius:n,padding:`2px`,WebkitMask:`linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)`,WebkitMaskComposite:`xor`,maskComposite:`exclude`},children:(0,$.jsx)(`span`,{className:`absolute left-1/2 top-1/2 aspect-square w-[250%] -translate-x-1/2 -translate-y-1/2 ${o?``:`animate-[builder-halo-spin_2.6s_linear_infinite]`}`,style:{background:`conic-gradient(from 0deg, transparent 0%, color-mix(in srgb, var(--color-accent-primary) 90%, transparent) 18%, color-mix(in srgb, var(--color-accent-highlight) 85%, transparent) 32%, transparent 55%)`}})}),(0,$.jsx)(`span`,{className:`absolute inset-0 opacity-60`,style:{borderRadius:n,boxShadow:`0 0 12px 2px color-mix(in srgb, var(--color-accent-primary) 45%, transparent), inset 0 0 8px 1px color-mix(in srgb, var(--color-accent-highlight) 30%, transparent)`}})]})})}var PA=`specrails-desktop:effects`,FA=`specrails:effects-changed`,IA={agentThinkingHalo:!0},LA=null;function RA(){try{let e=localStorage.getItem(PA);if(!e)return IA;let t=JSON.parse(e);return{...IA,...typeof t.agentThinkingHalo==`boolean`?{agentThinkingHalo:t.agentThinkingHalo}:{}}}catch{return IA}}function zA(){return LA||=RA(),LA}function BA(e){let t={...zA(),...e};LA=t;try{localStorage.setItem(PA,JSON.stringify(t))}catch{}try{window.dispatchEvent(new CustomEvent(FA))}catch{}return t}function VA(e){let t=()=>{LA=null,e()};return window.addEventListener(FA,t),window.addEventListener(`storage`,t),()=>{window.removeEventListener(FA,t),window.removeEventListener(`storage`,t)}}function HA(){return(0,Q.useSyncExternalStore)(VA,zA,()=>IA)}function UA({active:e,radius:t=`0.75rem`,inset:n=-3}){let{agentThinkingHalo:r}=HA();return r?(0,$.jsx)(`span`,{"data-testid":`agent-thinking-halo`,"data-active":e,className:`contents`,children:(0,$.jsx)(NA,{active:e,radius:t,inset:n,fadeInMs:450,fadeOutMs:800})}):null}var WA=e=>e===`running`||e===`queued`;function GA(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m${String(t%60).padStart(2,`0`)}s`:`${Math.floor(n/60)}h ${n%60}m`}function KA(){try{return tt()}catch{return null}}var qA=e=>{if(!e)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null};function JA(e,t,n){let{live:r}=n,[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(()=>Date.now());(0,Q.useEffect)(()=>{let n=!1;return fetch(`${Xe}/api/projects/${e}/jobs/${t}`).then(e=>e.ok?e.json():null).then(e=>{if(n)return;let t=e?.job;t&&(s(typeof t.status==`string`?t.status:null),l(qA(t.started_at)),d(qA(t.finished_at)),typeof t.total_cost_usd==`number`&&p(t.total_cost_usd),typeof t.num_turns==`number`&&h(t.num_turns),_(t.loopPaused===!0),y(typeof t.loopPauseReason==`string`?t.loopPauseReason:null)),a(!0)}).catch(()=>{n||a(!0)}),()=>{n=!0}},[e,t,r]);let S=WA(o)&&u===null,C=KA(),w=(0,Q.useId)();return(0,Q.useEffect)(()=>{if(!C||!r)return;let e=`run-vitals-${t}-${w}`;return C.registerHandler(e,e=>{let n=e;if(n?.type===`loop.run_paused`&&n.loopRunId===t){_(!0),y(typeof n.reason==`string`?n.reason:null),s(`running`),d(null);return}if((n?.type===`loop.run_resumed`||n?.type===`loop.run_completed`)&&n.loopRunId===t){_(!1),y(null);return}n?.jobId===t&&(n.type===`job.turn_done`?(typeof n.totals?.total_cost_usd==`number`&&p(n.totals.total_cost_usd),typeof n.totals?.num_turns==`number`&&h(n.totals.num_turns)):n.type===`job.finalized`&&(typeof n.totals?.total_cost_usd==`number`&&p(n.totals.total_cost_usd),typeof n.totals?.num_turns==`number`&&h(n.totals.num_turns),typeof n.status==`string`&&s(n.status),_(!1),y(null),d(qA(n.timestamp)??Date.now())))}),()=>C.unregisterHandler(e)},[C,r,t,w]),(0,Q.useEffect)(()=>{if(!r||!S||c===null)return;let e=setInterval(()=>x(Date.now()),1e3);return()=>clearInterval(e)},[r,S,c]),{status:o,paused:g,pausedReason:v,running:S,elapsedMs:c===null?null:Math.max(0,(u??b)-c),costUsd:f,numTurns:m,loaded:i}}function YA(e){return e.command.startsWith(`loop:`)?`loop-run`:e.interactive?`interactive`:`job`}var XA=15e3;function ZA(e){if(typeof AbortSignal<`u`&&typeof AbortSignal.timeout==`function`)return AbortSignal.timeout(e)}async function QA(e){let{projectId:t,jobId:n,timeoutMs:r=XA}=e,i=t?`${Xe}/api/projects/${t}`:ut(),a;try{a=await fetch(`${i}/jobs/${n}/cancel`,{method:`POST`,signal:ZA(r)})}catch(e){let t=e;return{ok:!1,error:t?.name===`TimeoutError`||t?.name===`AbortError`?`Request timed out after ${Math.round(r/1e3)}s`:t?.message||String(e),httpStatus:null}}if(a.ok){let e=`canceled`;try{let t=await a.json();t&&typeof t.status==`string`&&(e=t.status)}catch{}return{ok:!0,status:e}}let o=typeof a.status==`number`?a.status:null,s=o==null?``:` (HTTP ${o})`,c=``;try{typeof a.text==`function`?c=await a.text():typeof a.json==`function`&&(c=JSON.stringify(await a.json()))}catch{}let l=c.slice(0,200).trim();try{let e=JSON.parse(c);e&&typeof e.error==`string`&&e.error&&(l=e.error)}catch{}let u=typeof a.statusText==`string`?a.statusText:``;return{ok:!1,error:l?`${l}${s}`:`HTTP ${o??`?`}${u?` ${u}`:``}`,httpStatus:o}}var $A=null;function ej(e){$A=e}function tj(e,t){$A?.(e,t)}var nj=(0,Q.lazy)(()=>c(()=>import(`./JobDetailModal-DHeur9YK.js`).then(e=>({default:e.JobDetailModal})),__vite__mapDeps([6,1,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]))),rj={building:On,on_review:On,pr_draft:A,pr_ready:A,no_changes:$o,completed:$o,pr_closed:Tn,superseded:A,implementation_failed:zn,pr_failed:zn,merged:ks,discarded:Tn},ij={building:`text-accent-primary/70`,on_review:`text-accent-primary`,pr_draft:`text-accent-info`,pr_ready:`text-accent-info`,no_changes:`text-accent-success`,completed:`text-accent-success`,pr_closed:`text-accent-warning`,superseded:`text-foreground/40`,implementation_failed:`text-destructive`,pr_failed:`text-destructive`,merged:`text-accent-success`,discarded:`text-foreground/40`};function aj({envelope:e}){let{t}=K(`agent`),n=It(e);return n.units.length===0&&!n.partial?null:(0,$.jsxs)(`div`,{className:`mt-2 space-y-1.5`,"data-testid":`agent-pr-unit-evidence`,children:[n.partial&&(0,$.jsx)(`p`,{className:`text-[11px] font-medium text-accent-warning`,children:t(`prCard.partialSummary`,{succeeded:n.succeededCount,failed:n.failedCount,total:n.totalCount})}),n.units.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.units.map(e=>{let n=e.implementationOutcome===`failed`||e.implementationOutcome==null&&!e.succeeded,r=e.deliveryOutcome===`no_changes`||e.changed===!1,i=e.deliveryOutcome===`blocked`,a=t(n?`prCard.unit.failed`:i?`prCard.unit.blocked`:r?`prCard.unit.noChanges`:`prCard.unit.succeeded`);return(0,$.jsxs)(`span`,{title:e.failureCode??e.branch,className:X(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[10px]`,n?`border-destructive/35 bg-destructive/10 text-destructive`:i?`border-accent-warning/35 bg-accent-warning/10 text-accent-warning`:`border-accent-success/30 bg-accent-success/10 text-accent-success`),children:[`#`,e.ticketId,` · `,a]},`${e.ticketId}-${e.runId??e.branch}`)})})]})}function oj({prDeliveryId:e,projectId:t}){let{t:n}=K(`agent`),r=y(),{activeProjectId:i,setActiveProjectId:a}=pt();return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{let n=`/review/${e}`;i!==t&&(tj(t,n),a(t)),r(n)},"data-testid":`agent-pr-open-packet`,"data-agent-interactive":!0,title:n(`prCard.openReviewTooltip`),className:`inline-flex items-center gap-1 rounded-md border border-accent-primary/40 bg-accent-primary/10 px-2 py-1 text-[11px] font-medium text-accent-primary transition-colors hover:bg-accent-primary/20`,children:[(0,$.jsx)(vs,{className:`h-3 w-3`}),n(`prCard.openReview`)]})}function sj(e,t,n){if(e.decision===`building`)return n?`paused`:t?.status===`stalled`?`stalled`:`running`;if(t?.active)return`running`;let r=e.runtime?.status;return r===`running`?`running`:r===`failed`||r===`stalled`||r===`cancelled`||r===`succeeded`?r:e.runtime?.failure?e.runtime.failure.code===`stalled`||e.runtime.failure.code===`stuck`?`stalled`:`failed`:e.decision===`implementation_failed`||e.implementationOutcome===`failed`?`failed`:e.decision===`discarded`?`cancelled`:e.decision===`completed`||e.decision===`merged`||e.decision===`on_review`||e.decision===`pr_draft`||e.decision===`pr_ready`||e.decision===`no_changes`?`succeeded`:`unknown`}var cj={running:`border-accent-info/40 bg-accent-info/10 text-accent-info`,paused:`border-accent-warning/40 bg-accent-warning/10 text-accent-warning`,succeeded:`border-accent-success/40 bg-accent-success/10 text-accent-success`,failed:`border-destructive/40 bg-destructive/10 text-destructive`,stalled:`border-accent-warning/40 bg-accent-warning/10 text-accent-warning`,cancelled:`border-border/60 bg-surface/60 text-foreground/55`,unknown:`border-border/60 bg-surface/60 text-foreground/55`};function lj({status:e}){let{t}=K(`agent`);return(0,$.jsxs)(`span`,{"data-testid":`mission-run-status`,"data-status":e,className:X(`inline-flex shrink-0 items-center gap-1 rounded-full border px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide`,cj[e]),children:[(e===`running`||e===`paused`)&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:X(`h-1.5 w-1.5 rounded-full`,e===`running`?`animate-pulse bg-accent-info`:`bg-accent-warning`)}),t(`runCard.status.${e}`)]})}function uj({envelope:e}){let{t}=K(`agent`),n=e.runtime?.failure??null,r=n?.code??e.statusCode??null,i=n?.detail??e.statusDetail??null,a=(e.units??[]).filter(e=>e.failureCode).map(e=>({ticketId:e.ticketId,code:e.failureCode}));return!r&&!i&&a.length===0?null:(0,$.jsxs)(`div`,{className:`mt-2 rounded-md border border-destructive/30 bg-destructive/[0.06] px-2.5 py-2 text-[11px]`,"data-testid":`mission-run-failure`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,$.jsx)(zn,{className:`h-3.5 w-3.5 shrink-0 text-destructive`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`font-medium text-destructive`,children:t(`runCard.failure.title`)}),r&&(0,$.jsx)(`span`,{className:`rounded-full border border-destructive/40 bg-destructive/10 px-2 py-px font-mono text-[10px] text-destructive`,"data-testid":`mission-run-failure-code`,children:r}),n?.stepId&&(0,$.jsx)(`span`,{className:`rounded-full border border-border/60 bg-surface/60 px-2 py-px font-mono text-[10px] text-foreground/60`,children:t(`runCard.failure.step`,{step:n.stepId})})]}),i&&(0,$.jsx)(`p`,{className:`mt-1 break-words leading-4 text-foreground/70`,"data-testid":`mission-run-failure-detail`,children:i}),a.length>0&&(0,$.jsx)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-[10px] text-foreground/55`,children:a.map(e=>(0,$.jsx)(`li`,{children:t(`runCard.failure.unit`,{ticket:e.ticketId,code:e.code})},`${e.ticketId}-${e.code}`))})]})}function dj(e,t){let n=e.runtime;return n?{runId:t,status:n.status,nextStep:n.currentStep,recoverableSteps:n.recoverableSteps,active:n.status===`running`,canResume:n.canResume,canCancel:n.status===`running`,...n.pendingApproval&&n.failure?.stepId?{pendingApproval:{stepId:n.failure.stepId}}:{}}:null}function fj(e){let t=/\/pull\/(\d+)/.exec(e);return t?`#${t[1]}`:null}function pj({projectId:e,runId:t,ticketLabel:n,live:r,onOpen:i,onVitals:a}){let{t:o}=K(`agent`),s=JA(e,t,{live:r}),c=n??t.slice(0,8),l=s.elapsedMs==null?null:GA(s.elapsedMs),u=s.costUsd!=null&&s.costUsd>0,d=(0,$.jsx)(`span`,{"aria-hidden":!0,className:`opacity-40`,children:`·`});return(0,Q.useEffect)(()=>{a?.(t,{paused:s.paused,pausedReason:s.pausedReason})},[a,t,s.paused,s.pausedReason]),(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`pr-run-log-chip`,onClick:e=>{e.stopPropagation(),i(t)},title:o(`prCard.viewLog`,{ref:c}),"aria-label":o(`prCard.viewLog`,{ref:c}),className:X(`inline-flex max-w-full cursor-pointer items-center gap-1 rounded-full border px-1.5 py-px align-baseline font-mono text-[0.82em] leading-[1.45] transition-all`,s.paused?`border-accent-warning/45 bg-accent-warning/10 text-accent-warning hover:-translate-y-px hover:border-accent-warning/65 hover:bg-accent-warning/15 hover:shadow-sm`:`border-accent-info/35 bg-accent-info/10 text-accent-info hover:-translate-y-px hover:border-accent-info/60 hover:bg-accent-info/15 hover:shadow-sm`),children:[(s.paused||s.running&&r)&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:X(`h-1.5 w-1.5 shrink-0 animate-pulse rounded-full`,s.paused?`bg-accent-warning`:`bg-accent-info`)}),(0,$.jsx)(`span`,{className:`max-w-[160px] truncate`,children:c}),d,(0,$.jsx)(yc,{className:`h-3 w-3 shrink-0 opacity-70`}),l&&(0,$.jsxs)($.Fragment,{children:[d,(0,$.jsx)(`span`,{className:`tabular-nums`,"aria-label":o(`prCard.runElapsedAria`,{elapsed:l}),children:l})]}),u&&(0,$.jsxs)($.Fragment,{children:[d,(0,$.jsxs)(`span`,{className:`tabular-nums`,"aria-label":o(`prCard.runCostAria`,{cost:`$${s.costUsd.toFixed(2)}`}),children:[`$`,s.costUsd.toFixed(2)]})]})]})}function mj({envelope:e,conversationId:t}){let{t:n}=K(`agent`),r=u(),{projects:i}=pt(),{applyPrDecisionSnapshot:a}=aP(),{openWebView:o,canOpenWebView:s}=Oe(),{openRef:c}=Rb(),[l,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(null),j=O??e,M=tn(j.projectId).has(j.prDeliveryId),[N,P]=(0,Q.useState)(null),[F,I]=(0,Q.useState)({}),[L,R]=(0,Q.useState)(null),{decision:z,prUrl:B,prState:V}=j,H=ve&&j.hasDelivery===!1,U=ve?j.runtime?.failure??null:null,W=(j.runIds??[])[0]??null,ee=ve&&!!W&&(z===`building`||!!U||z===`implementation_failed`||j.runtime?.status===`running`),te=kr(j.projectId,{jobId:W??void 0,enabled:ee}),ne=te.runs.find(e=>e.runId===W)??te.runs[0]??null,re=ne??(W?dj(j,W):null),[ie,ae]=(0,Q.useState)(!1),oe=(0,Q.useRef)(null),[se,ce]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{if(!ve)return;let e=e=>{let n=e.detail;rO(n,{prDeliveryId:j.prDeliveryId,runIds:j.runIds})&&(oe.current?.scrollIntoView?.({behavior:`smooth`,block:`center`}),ce(!0),t&&clearTimeout(t),t=setTimeout(()=>ce(!1),1400))},t=null;return window.addEventListener(tO,e),()=>{window.removeEventListener(tO,e),t&&clearTimeout(t)}},[j.prDeliveryId,j.runIds]);let ue=se?`ring-2 ring-accent-primary/50 ring-offset-1 ring-offset-background`:``,fe=!!j.repositoryDeliveries?.length,G=It(j),pe=Ft(j.statusCode,j.statusDetail),me=j.operation==null&&pe,he=i.find(e=>e.id===j.projectId)?.name??j.projectId,ge=z===`pr_draft`&&!B,_e=z===`building`&&V===`pr-created`&&!!j.branch,ye=j.prNumber?`#${j.prNumber}`:B?fj(B):null,be=G.terminal,xe=Lt(j.statusCode)?n(`common:prDeliveryStatus.${j.statusCode}`):null,Se=G.partial&&G.deliverableCount>0&&(z===`on_review`||z===`pr_draft`&&!B);(0,Q.useEffect)(()=>{k(null)},[e]);let Ce=(0,Q.useRef)(!1);Ce.current=l!==null||f||j.operation!=null||te.busy!==null,(0,Q.useEffect)(()=>{d(null),h(!1),_(!1),y(!1),x(!1),C(!1),T(!1),D(!1)},[z,B,j.prDeliveryId]);let we=(0,Q.useCallback)((e,t)=>{I(n=>{let r=n[e];return r?.paused===t.paused&&r?.pausedReason===t.pausedReason?n:{...n,[e]:t}})},[]),Te=async e=>{if(!L){R(e);try{let t=await QA({projectId:j.projectId,jobId:e,kind:`loop-run`});t.ok?J.info(n(`prCard.stopExecutionSent`)):J.error(n(`prCard.stopExecutionFailed`),{description:t.error})}finally{R(null)}}},Ee=async(e,r)=>{if(f||l||j.operation||fe&&!r&&[`create-pr`,`merge-local`,`publish`,`poll-merge`,`reopen`,`acknowledge-no-changes`].includes(e))return;let i=j.repositoryDeliveries?.find(e=>e.repositoryId===r),o=i?.integrationBranch??i?.baseBranch??j.baseBranch;d(e);try{let i=await Eo(j.projectId,{prDeliveryId:j.prDeliveryId,action:e,expectedDecision:z,...r?{repositoryId:r}:{},...H&&t?{conversationId:t}:{}}),s=null;if(i.snapshot){let e=Do(j,i.snapshot);s=a(e),s!==`stale`&&k(e)}if(s===`stale`){J.info(n(`prCard.alreadyResolved`));return}if(i.kind===`recovering`)J.info(n(`common:prRecovery.inProgress`));else if(i.kind===`busy`)J.info(n(`prCard.operation.${i.operation??`inProgress`}`));else if(i.kind===`stale`)J.info(n(`prCard.alreadyResolved`));else if(i.kind===`blocked`)J.warning(i.reason===`dirty`?n(`prCard.mergeLocalBlockedDirty`,{base:i.base||o}):n(`prCard.mergeLocalBlockedBranch`,{base:i.base||o,current:i.current??`?`}));else if(i.kind===`failed`)J.error(n(`prCard.actionFailed`),{description:i.detail});else if(i.kind===`ok`&&e===`recover-and-retry`)if(i.deliveryVerified){let e=(i.verifiedSha??i.snapshot?.deliverySha??``).slice(0,8);J.success(n(`prCard.recoverAndRetryVerified`,{sha:e}))}else i.recoveryUnavailable||i.snapshot?.statusCode===`recovery_unavailable`?J.info(n(`prCard.recoveryUnavailable`),{description:n(`prCard.recoveryUnavailableBody`)}):J.warning(n(`prCard.recoveryStillBlocked`),{description:i.detail??void 0});else if(i.kind===`ok`&&e===`create-pr`&&G.retryablePush&&i.deliveryVerified){let e=(i.verifiedSha??i.snapshot?.deliverySha??j.deliverySha??``).slice(0,8);J.success(n(i.pushed?`prCard.retryPushVerified`:`prCard.commitAlreadyVerified`,{sha:e}))}else if(i.kind===`ok`&&e===`create-pr`&&i.detail)J.error(n(`prCard.deliveryNeedsAttention`),{description:i.detail});else if(i.kind===`ok`&&e===`poll-merge`&&i.deliveryVerified===!1)J.warning(n(`prCard.commitMissingRetry`));else if(i.kind===`ok`&&e===`poll-merge`&&i.deliveryVerified&&!i.merged){let e=(i.verifiedSha??i.snapshot?.deliverySha??j.deliverySha??``).slice(0,8);J.success(n(`prCard.prVerifiedWaiting`,{sha:e}))}else e===`poll-merge`&&!i.merged&&i.decision!==`pr_closed`?J.info(n(`prCard.notMergedYet`)):e===`merge-local`&&i.kind===`ok`&&i.decision===`merged`&&J.success(n(`prCard.mergedLocally`,{base:o}));i.kind===`ok`&&(e===`create-pr`||e===`discard`||e===`merge-local`||e===`recover-and-retry`)&&Ht(j.projectId)}catch(e){J.error(n(`prCard.actionFailed`),{description:e instanceof Error?e.message:void 0})}finally{d(null)}},De=async e=>{if(!(fe&&!e)&&!(l||f||j.operation)){p(!0);try{let t=await(e?Oo(j.projectId,j.prDeliveryId,e):Oo(j.projectId,j.prDeliveryId));t.kind===`ok`?(J.success(n(`prCard.checkoutSuccess`,{branch:t.branch??Yt(j)??``})),t.cleanupWarnings.length>0&&J.warning(n(`prCard.cleanupIncomplete`,{count:t.cleanupWarnings.length}),{description:t.cleanupWarnings.join(`
|
|
45
45
|
`)}),Ht(j.projectId)):t.kind===`recovering`?J.info(n(`common:prRecovery.inProgress`)):t.error===`checkout_dirty`?J.warning(n(`prCard.checkoutDirtyTitle`),{description:n(`prCard.checkoutDirtyBody`)}):t.error===`checkout_not_deliverable`?J.warning(n(`prCard.checkoutNotDeliverableTitle`),{description:n(`prCard.checkoutNotDeliverableBody`)}):t.error===`checkout_safety_unknown`?J.warning(n(`prCard.checkoutSafetyUnknownTitle`),{description:n(`prCard.checkoutSafetyUnknownBody`)}):J.warning(n(`prCard.checkoutFailed`),{description:t.detail})}catch(e){J.error(n(`prCard.checkoutFailed`),{description:e instanceof Error?e.message:void 0})}finally{p(!1)}}},ke=async()=>{let e=G.recoveryWorktreePaths;if(e.length===0){J.info(n(`prCard.localResultUnavailableHere`));return}let t=e.join(`
|
|
46
46
|
`),r=!1;try{await navigator.clipboard.writeText(t),r=!0}catch{}try{de()&&await Ne(e[0])}catch{}r?J.success(n(`prCard.localResultPathCopied`),{description:t}):J.info(n(`prCard.localResultPath`),{description:t})},Ae=async()=>{if(!(ie||Ce.current)){ae(!0);try{let e=await fetch(`${Xe}/api/projects/${encodeURIComponent(j.projectId)}/rails/${j.railIndex}/launch`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...t?{originConversationId:t,originSurface:`agent-chat`}:{}})});if(e.status===202){J.success(n(`runCard.relaunchSent`,{index:j.railIndex+1})),Ht(j.projectId);return}let r=await e.json().catch(()=>({}));J.error(n(`runCard.relaunchFailed`),{description:[r.detail??r.error,r.action].filter(Boolean).join(` — `)||`HTTP ${e.status}`})}catch(e){J.error(n(`runCard.relaunchFailed`),{description:e instanceof Error?e.message:void 0})}finally{ae(!1)}}},je=(e,t)=>{s&&(e.preventDefault(),e.stopPropagation(),o(t))},Me=j.ticketIds.length>0&&(0,$.jsx)($.Fragment,{children:j.ticketIds.map(e=>(0,$.jsxs)(RD,{refTarget:{kind:`ticket`,ticketId:e},onOpen:e=>void c(j.projectId,e),children:[`#`,e]},e))}),Pe=j.runIds??[],Fe=e=>Pe.length===1&&j.ticketIds.length>1?j.ticketIds.map(e=>`#${e}`).join(` `):j.ticketIds[e]==null?null:`#${j.ticketIds[e]}`,Ie=Pe.find(e=>F[e]?.paused)??null,Re=Ie?F[Ie]?.pausedReason??null:null,ze=Pe.length>0&&(0,$.jsx)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-1.5`,"data-testid":`pr-run-log-chips`,children:Pe.map((e,t)=>(0,$.jsx)(pj,{projectId:j.projectId,runId:e,ticketLabel:Fe(t),live:z===`building`,onOpen:P,onVitals:we},e))}),Be=z===`building`&&Ie!==null,Ve=Ie?Fe(Pe.indexOf(Ie))??Ie.slice(0,8):null,He=sj(j,ne,Ie!==null),Ue=`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] font-medium transition-colors disabled:pointer-events-none disabled:opacity-50`,We=te.busy!==null||ie,Ge=ve&&re&&(0,$.jsxs)($.Fragment,{children:[re.canResume&&(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`mission-run-resume`,disabled:We||l!==null,onClick:()=>void te.act(re,`resume`),className:X(Ue,`border-accent-primary/40 bg-accent-primary/10 text-accent-primary hover:bg-accent-primary/20`),children:[te.busy===re.runId?(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`}):(0,$.jsx)(Mn,{className:`h-3 w-3`}),n(`runCard.actions.resume`)]}),re.pendingApproval&&(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`mission-run-approve`,disabled:We||l!==null,onClick:()=>void te.act(re,`approve`),className:X(Ue,`border-accent-success/40 bg-accent-success/10 text-accent-success hover:bg-accent-success/20`),children:[(0,$.jsx)(Cc,{className:`h-3 w-3`}),n(`runCard.actions.approve`)]}),re.recoverableSteps.length>0&&(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`mission-run-recover`,disabled:We||l!==null,onClick:()=>void te.act(re,`recover`),className:X(Ue,`border-accent-warning/40 bg-accent-warning/10 text-accent-warning hover:bg-accent-warning/20`),children:[(0,$.jsx)(Bn,{className:`h-3 w-3`}),n(`runCard.actions.recover`)]})]}),Ke=!!ne?.active||He===`running`||He===`paused`,qe=ve&&(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`mission-run-relaunch`,disabled:We||l!==null||Ke,title:Ke?n(`runCard.relaunchBlockedActive`):void 0,onClick:()=>void Ae(),className:X(Ue,`border-border/60 text-foreground/70 hover:border-accent-primary/40 hover:bg-accent-primary/10`),children:[ie?(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`}):(0,$.jsx)(Fn,{className:`h-3 w-3`}),n(`runCard.actions.relaunch`)]}),Je=ve&&te.error&&ee?(0,$.jsx)(`p`,{className:`mt-1 text-[10px] text-destructive/80`,"data-testid":`mission-run-runtime-error`,children:te.error}):null,Ye=ve&&ne?.nextStep?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1 truncate text-[11px] text-foreground/50`,"data-testid":`mission-run-phase`,children:[(0,$.jsx)(No,{className:`h-3 w-3 shrink-0 opacity-60`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`truncate`,children:ne.nextStep})]}):null,Ze=N&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(nj,{jobId:N,projectId:j.projectId,onClose:()=>P(null)})});if(z===`building`)return(0,$.jsxs)(`div`,{ref:oe,"data-testid":`agent-pr-decision-card`,className:X(`rounded-xl border border-border/60 bg-card/80 px-3.5 py-2.5 text-xs text-foreground/60 shadow-lg backdrop-blur-xl transition-shadow`,ue),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[Be?(0,$.jsx)(zn,{className:`h-3.5 w-3.5 text-accent-warning`}):_e?(0,$.jsx)(A,{className:`h-3.5 w-3.5 text-accent-info`}):(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin text-accent-primary/70`}),(0,$.jsx)(`span`,{className:X(`min-w-0 flex-1 truncate`,!_e&&!Be&&`animate-pulse`,Be&&`text-accent-warning`),children:n(Be?`prCard.title.paused`:_e?`prCard.title.buildingExistingPr`:`prCard.title.building`)}),ve&&(0,$.jsx)(lj,{status:He}),ve&&(0,$.jsx)(`span`,{className:`shrink-0 rounded-full border border-border/60 bg-surface/60 px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide text-foreground/60`,children:j.railName?j.railName:n(`prCard.rail`,{index:j.railIndex+1})})]}),Ye&&(0,$.jsx)(`div`,{className:`mt-1 flex items-center pl-[22px]`,children:Ye}),Me&&(0,$.jsx)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-1.5 pl-[22px]`,children:Me}),_e&&(0,$.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-1.5 pl-[22px]`,children:[B?(0,$.jsxs)(`a`,{href:B,target:`_blank`,rel:`noreferrer`,onClick:e=>je(e,B),title:B,"data-agent-interactive":!0,className:`inline-flex items-center gap-1 rounded-full border border-accent-info/40 bg-accent-info/10 px-2 py-0.5 font-mono text-[11px] text-accent-info transition-colors hover:border-accent-info/60 hover:bg-accent-info/15`,children:[(0,$.jsx)(A,{className:`h-3 w-3`}),ye??n(`prCard.openPr`),(0,$.jsx)(pn,{className:`h-2.5 w-2.5 opacity-60`})]}):(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-accent-info/40 bg-accent-info/10 px-2 py-0.5 font-mono text-[11px] text-accent-info`,children:[(0,$.jsx)(A,{className:`h-3 w-3`}),ye??n(`prCard.existingPr`)]}),(0,$.jsxs)(`span`,{title:n(`git.branch`),className:`inline-flex min-w-0 max-w-full items-center gap-1 rounded-full border border-border/60 bg-surface/60 px-2 py-0.5 font-mono text-[11px] text-foreground/70`,children:[(0,$.jsx)(On,{className:`h-3 w-3 shrink-0 text-accent-primary/70`}),(0,$.jsx)(`span`,{className:`truncate`,children:j.branch})]})]}),Be&&Ie&&(0,$.jsxs)(`div`,{className:`mt-2 flex min-w-0 flex-wrap items-center gap-1.5 rounded-md border border-accent-warning/35 bg-accent-warning/10 px-2 py-1.5 text-[11px] text-accent-warning`,"data-testid":`pr-run-paused-actions`,children:[(0,$.jsx)(zn,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,title:Re??void 0,children:[Ve?n(`prCard.pausedForRun`,{ref:Ve}):n(`prCard.paused`),Re?`: ${Re}`:``]}),(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,onClick:e=>{e.stopPropagation(),P(Ie)},className:`inline-flex items-center gap-1 rounded-md border border-accent-warning/40 bg-surface/70 px-2 py-0.5 font-medium text-accent-warning transition-colors hover:bg-accent-warning/15`,children:[(0,$.jsx)(Mn,{className:`h-3 w-3`}),n(`prCard.resume`)]}),(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,disabled:L===Ie,onClick:e=>{e.stopPropagation(),Te(Ie)},className:`inline-flex items-center gap-1 rounded-md border border-destructive/40 bg-destructive/10 px-2 py-0.5 font-medium text-destructive transition-colors hover:bg-destructive/15 disabled:cursor-default disabled:opacity-60`,children:[L===Ie?(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`}):(0,$.jsx)(Nn,{className:`h-3 w-3`}),n(`prCard.stopExecution`)]})]}),ze&&(0,$.jsx)(`div`,{className:`pl-[22px]`,children:ze}),(0,$.jsx)(`p`,{className:`mt-1 pl-[22px] text-[11px] leading-4 text-foreground/40`,children:n(H?`runCard.noDeliveryHint`:_e?`prCard.buildingExistingPrHint`:`prCard.buildingHint`)}),Je,Ze]});if(H){let e=He===`succeeded`?$o:He===`failed`||He===`stalled`?zn:He===`cancelled`?Tn:An,t=l!==null||We;return(0,$.jsxs)(`div`,{ref:oe,"data-testid":`agent-pr-decision-card`,"data-run-only":`true`,className:X(`rounded-xl border border-border/60 bg-card/80 px-3.5 py-3 shadow-lg backdrop-blur-xl transition-shadow`,He===`succeeded`&&`border-accent-success/30`,He===`cancelled`&&`opacity-70`,ue),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(e,{className:X(`h-4 w-4 shrink-0`,He===`succeeded`?`text-accent-success`:He===`failed`||He===`stalled`?`text-destructive`:`text-foreground/50`,He===`running`&&`animate-spin text-accent-primary/70`)}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-foreground`,children:n(`runCard.title.${He}`)}),(0,$.jsx)(lj,{status:He}),(0,$.jsx)(`span`,{className:`max-w-[140px] shrink-0 truncate text-[11px] text-foreground/50`,title:he,children:he}),(0,$.jsx)(`span`,{className:`shrink-0 rounded-full border border-border/60 bg-surface/60 px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide text-foreground/60`,children:j.railName?j.railName:n(`prCard.rail`,{index:j.railIndex+1})})]}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-border/60 bg-surface/60 px-2 py-0.5 text-[11px] text-foreground/70`,children:[(0,$.jsx)(Le,{className:`h-3 w-3 text-accent-secondary/80`}),n(`prCard.specCount`,{count:j.ticketIds.length})]}),Me,Ye]}),ze,(0,$.jsx)(aj,{envelope:j}),(U||He===`failed`||He===`stalled`)&&(0,$.jsx)(uj,{envelope:j}),(0,$.jsxs)(`p`,{className:`mt-2 flex items-start gap-1.5 text-[11px] leading-4 text-foreground/45`,"data-testid":`mission-run-no-delivery`,children:[(0,$.jsx)(On,{className:`mt-px h-3 w-3 shrink-0 opacity-60`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:n(`runCard.noDeliveryNote`)})]}),Je,(0,$.jsxs)(Ny.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:`easeOut`},className:`mt-2.5 flex flex-wrap items-center gap-1.5`,children:[Ge,He!==`running`&&He!==`paused`&&qe,He!==`running`&&He!==`paused`&&z!==`discarded`&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>_(!0),disabled:t,"data-agent-interactive":!0,"data-testid":`mission-run-dismiss`,className:`inline-flex items-center gap-1.5 rounded-md border border-border/60 px-2.5 py-1 text-xs text-foreground/70 transition-colors hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive disabled:cursor-default disabled:opacity-60`,children:[l===`dismiss`&&(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`}),n(`prCard.dismiss`)]})]},`${He}-${j.updatedAt??``}`),(0,$.jsx)(mr,{open:g,onOpenChange:_,children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`agent-pr-dismiss-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:n(`prCard.confirm.dismissTitle`)}),(0,$.jsx)(ir,{children:n(`prCard.confirm.dismissBody`)})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:()=>_(!1),children:n(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:t,"data-testid":`agent-pr-dismiss-confirm-btn`,onClick:()=>{_(!1),Ee(`dismiss`)},children:n(`prCard.dismiss`)})]})]})}),Ze]})}let Qe=rj[z],$e=G.superseded?n(`prCard.title.superseded`):G.noChanges?n(`prCard.title.no_changes`):G.deliveryBlocked?n(`prCard.title.delivery_blocked`):G.retryablePush?n(`prCard.title.update_failed`):G.closed?n(`prCard.title.pr_closed`):G.partial?n(`prCard.title.partial`):j.statusCode===`existing_pr_updated`?n(`prCard.title.existing_pr_updated`):n(ge?`prCard.title.pr_draft_degraded`:`prCard.title.${z}`),et=`inline-flex items-center gap-1.5 rounded-md bg-accent-primary px-2.5 py-1 text-xs font-medium text-white transition-colors hover:bg-accent-primary/90 disabled:cursor-default disabled:opacity-60`,tt=X(`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs transition-colors disabled:cursor-default disabled:opacity-60`,`border-border/60 text-foreground/70 hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive`),nt=l!==null||f||j.operation!=null,rt=!!j.operation||me||G.partial||G.deliveryBlocked||G.retryablePush||G.retryablePrCreation||G.closed||G.implementationFailed,it=(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`}),at=(e,t)=>!fe&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void Ee(e),disabled:nt,"data-agent-interactive":!0,className:et,children:[l===e&&it,t]}),ot=le&&r&&!G.terminal?(0,$.jsx)(oj,{prDeliveryId:j.prDeliveryId,projectId:j.projectId}):null,st=Yt(j),ct=st&&!fe&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void De(),disabled:nt,"data-testid":`agent-pr-checkout`,"data-agent-interactive":!0,title:n(`prCard.checkoutTooltip`,{branch:st}),className:`inline-flex items-center gap-1 rounded-md border border-border/60 px-2 py-1 text-[11px] font-medium text-foreground/70 transition-colors hover:border-accent-primary/40 hover:bg-accent-primary/10 disabled:pointer-events-none disabled:opacity-50`,children:[f?it:(0,$.jsx)(On,{className:`h-3 w-3`}),n(`prCard.checkout`)]}),lt=G.recoveryWorktreePaths.length>0&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void ke(),disabled:nt,"data-testid":`agent-pr-inspect-local-result`,"data-agent-interactive":!0,title:n(`prCard.inspectLocalResultTooltip`),className:`inline-flex items-center gap-1 rounded-md border border-border/60 px-2 py-1 text-[11px] font-medium text-foreground/70 transition-colors hover:border-accent-primary/40 hover:bg-accent-primary/10 disabled:pointer-events-none disabled:opacity-50`,children:[(0,$.jsx)(Ts,{className:`h-3 w-3`,"aria-hidden":!0}),n(`prCard.inspectLocalResult`)]}),q=G.recoveryRecheck,ut=(G.manualRecovery||q)&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>D(!0),disabled:nt,"data-testid":q?`agent-pr-recheck-recovery`:`agent-pr-recover-and-retry`,"data-agent-interactive":!0,className:q?`inline-flex items-center gap-1 rounded-md border border-border/60 px-2 py-1 text-[11px] font-medium text-foreground/70 transition-colors hover:border-accent-primary/40 hover:bg-accent-primary/10 disabled:pointer-events-none disabled:opacity-50`:et,children:[l===`recover-and-retry`?it:(0,$.jsx)(Fn,{className:`h-3 w-3`,"aria-hidden":!0}),n(q?`prCard.recheckRecovery`:`prCard.recoverAndRetry`)]}),dt=!fe&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>x(!0),disabled:nt,"data-testid":`agent-pr-merge-local`,"data-agent-interactive":!0,title:n(`prCard.mergeLocalTooltip`,{base:j.baseBranch}),className:`inline-flex items-center gap-1 rounded-md border border-accent-success/40 bg-accent-success/10 px-2 py-1 text-[11px] font-medium text-accent-success transition-colors hover:bg-accent-success/20 disabled:pointer-events-none disabled:opacity-50`,children:[l===`merge-local`&&it,n(`prCard.mergeLocal`)]}),ft=(0,$.jsxs)(`button`,{type:`button`,onClick:()=>h(!0),disabled:nt,"data-agent-interactive":!0,className:tt,children:[l===`discard`&&it,n(`prCard.discard`)]}),mt=(0,$.jsxs)(`button`,{type:`button`,onClick:()=>_(!0),disabled:nt,"data-agent-interactive":!0,className:tt,children:[l===`dismiss`&&it,n(`prCard.dismiss`)]}),Y=(0,$.jsxs)(`button`,{type:`button`,onClick:()=>y(!0),disabled:nt,"data-agent-interactive":!0,className:tt,children:[l===`discard`&&it,n(`prCard.discardLocalResult`)]}),ht=!fe&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>C(!0),disabled:nt,"data-agent-interactive":!0,className:et,children:[l===`acknowledge-no-changes`&&it,n(`prCard.markDone`)]}),gt=(0,$.jsxs)(`button`,{type:`button`,onClick:()=>T(!0),disabled:nt,"data-agent-interactive":!0,className:tt,children:[l===`discard`&&it,n(`prCard.refine`)]}),_t=B&&(0,$.jsxs)(`a`,{href:B,target:`_blank`,rel:`noreferrer`,onClick:e=>je(e,B),title:B,"data-agent-interactive":!0,className:`inline-flex items-center gap-1 rounded-full border border-border/60 bg-surface/60 px-2 py-0.5 font-mono text-[11px] text-accent-info transition-colors hover:border-accent-info/50 hover:bg-accent-info/10`,children:[(0,$.jsx)(A,{className:`h-3 w-3`}),ye??n(`prCard.openPr`),(0,$.jsx)(pn,{className:`h-2.5 w-2.5 opacity-60`})]}),vt=ve&&(!!U||z===`implementation_failed`||z===`discarded`&&(!!j.statusDetail||j.statusCode===`delivery_failed`));return(0,$.jsxs)(`div`,{ref:oe,"data-testid":`agent-pr-decision-card`,className:X(`rounded-xl border border-border/60 bg-card/80 px-3.5 py-3 shadow-lg backdrop-blur-xl transition-shadow`,z===`merged`&&`border-accent-success/30`,z===`completed`&&`border-accent-success/30`,z===`discarded`&&`opacity-70`,ue),children:[rt&&(0,$.jsx)(`span`,{role:`status`,"aria-live":`polite`,"aria-label":j.operation?n(`prCard.operation.${j.operation}`):me?n(`common:prRecovery.interrupted`):$e,className:`sr-only`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Qe,{className:X(`h-4 w-4 shrink-0`,ij[z])}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-foreground`,children:$e}),(0,$.jsx)(`span`,{className:`max-w-[140px] shrink-0 truncate text-[11px] text-foreground/50`,title:he,children:he}),(0,$.jsx)(`span`,{className:`shrink-0 rounded-full border border-border/60 bg-surface/60 px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide text-foreground/60`,children:n(`prCard.rail`,{index:j.railIndex+1})})]}),(0,$.jsx)(rn,{deliveryId:j.prDeliveryId,repositories:j.repositoryDeliveries,busy:!!l||f||!!j.operation,onAct:Ee,onCheckout:De}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,children:[!fe&&(0,$.jsxs)(`span`,{title:n(`prCard.base`),className:`inline-flex items-center gap-1 rounded-full border border-border/60 bg-surface/60 px-2 py-0.5 font-mono text-[11px] text-foreground/70`,children:[(0,$.jsx)(On,{className:`h-3 w-3 text-accent-primary/70`}),`→ `,j.baseBranch]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-border/60 bg-surface/60 px-2 py-0.5 text-[11px] text-foreground/70`,children:[(0,$.jsx)(Le,{className:`h-3 w-3 text-accent-secondary/80`}),n(`prCard.specCount`,{count:j.ticketIds.length})]}),Me,_t,j.deliverySha&&(0,$.jsxs)(`span`,{"data-testid":`agent-pr-delivery-sha`,title:j.deliverySha,className:X(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 font-mono text-[11px]`,j.deliveryOutcome===`delivered`?`border-accent-success/35 bg-accent-success/10 text-accent-success`:`border-border/60 bg-surface/60 text-foreground/65`),children:[(0,$.jsx)($o,{className:`h-3 w-3`}),n(`prCard.deliveryCommit`,{sha:j.deliverySha.slice(0,8)})]})]}),ze,j.operation&&(0,$.jsxs)(`p`,{className:`mt-2 flex items-center gap-1.5 text-[11px] font-medium text-accent-info`,"data-testid":`agent-pr-operation`,children:[(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}),n(`prCard.operation.${j.operation}`)]}),me&&(0,$.jsxs)(`p`,{className:`mt-2 flex items-start gap-1.5 text-[11px] leading-4 text-accent-info`,"data-testid":`agent-pr-recovery-interrupted`,children:[(0,$.jsx)(Fn,{className:`mt-px h-3 w-3 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:n(`common:prRecovery.interrupted`)})]}),(0,$.jsx)(aj,{envelope:j}),vt&&(0,$.jsx)(uj,{envelope:j}),Je,xe&&(0,$.jsx)(`p`,{className:`mt-2 text-[10px] font-medium uppercase tracking-wide text-foreground/45`,"data-testid":`agent-pr-status-code`,children:xe}),!be&&G.deliveryBlocked&&(0,$.jsxs)(`p`,{className:`mt-2 flex items-start gap-1.5 text-[11px] leading-4 text-accent-warning`,children:[(0,$.jsx)(zn,{className:`mt-px h-3 w-3 shrink-0`}),(0,$.jsxs)(`span`,{children:[G.recoveryUnavailable?n(`prCard.recoveryUnavailableBody`):n(G.partial?`prCard.partialDeliveryBlockedNote`:`prCard.deliveryBlockedNote`),j.statusDetail&&!pe&&!G.recoveryUnavailable?(0,$.jsx)(`span`,{className:`mt-0.5 block text-foreground/50`,children:j.statusDetail}):null]})]}),!be&&G.recoveryUnavailable&&j.statusDetail&&!pe&&(0,$.jsxs)(`details`,{className:`mt-1.5 text-[10px] leading-4 text-foreground/55`,"data-testid":`agent-pr-recovery-technical-detail`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer font-medium text-foreground/65`,children:n(`prCard.recoveryDetailSummary`)}),(0,$.jsx)(`p`,{className:`mt-1 break-words`,children:j.statusDetail})]}),!be&&G.retryablePush&&(0,$.jsxs)(`p`,{className:`mt-2 flex items-start gap-1.5 text-[11px] leading-4 text-accent-warning`,children:[(0,$.jsx)(zn,{className:`mt-px h-3 w-3 shrink-0`}),(0,$.jsxs)(`span`,{children:[n(`prCard.retryPushNote`),j.statusDetail&&!pe?(0,$.jsx)(`span`,{className:`mt-0.5 block text-foreground/50`,children:j.statusDetail}):null]})]}),j.statusDetail&&!pe&&!G.deliveryBlocked&&!G.retryablePush&&!vt&&(0,$.jsx)(`p`,{className:`mt-1 text-[10px] leading-4 text-foreground/45`,"data-testid":`agent-pr-status-detail`,children:j.statusDetail}),!be&&!B&&(V===`pushed`||V===`local-only`)&&(0,$.jsxs)(`p`,{className:`mt-2 flex items-start gap-1.5 text-[11px] leading-4 text-accent-warning`,children:[(0,$.jsx)(zn,{className:`mt-px h-3 w-3 shrink-0`}),n(V===`local-only`?`prCard.degraded.localOnly`:`prCard.degraded.pushed`)]}),G.cleanupWarnings.length>0&&(0,$.jsxs)(`div`,{className:`mt-2 rounded-md border border-accent-warning/35 bg-accent-warning/10 px-2 py-1.5 text-[11px] text-accent-warning`,"data-testid":`agent-pr-cleanup-warning`,children:[(0,$.jsx)(`p`,{className:`font-medium`,children:n(`prCard.cleanupIncomplete`,{count:G.cleanupWarnings.length})}),(0,$.jsx)(`ul`,{className:`mt-1 list-disc space-y-0.5 pl-4 text-foreground/60`,children:G.cleanupWarnings.map((e,t)=>(0,$.jsx)(`li`,{children:e},`${t}-${e}`))})]}),G.safetyArchives.length>0&&(0,$.jsxs)(`details`,{className:`mt-2 rounded-md border border-accent-info/25 bg-accent-info/5 px-2 py-1.5 text-[11px] text-foreground/65`,"data-agent-interactive":!0,"data-testid":`agent-pr-safety-archives`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer font-medium text-accent-info`,children:n(`prCard.safetyArchiveTitle`,{count:G.safetyArchives.length})}),(0,$.jsx)(`p`,{className:`mt-1 leading-4`,children:n(`prCard.safetyArchiveHint`)}),(0,$.jsx)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-[10px] text-foreground/50`,children:G.safetyArchives.map(e=>(0,$.jsx)(`li`,{className:`break-all`,children:e},e))})]}),(0,$.jsxs)(Ny.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:`easeOut`},className:`mt-2.5`,children:[G.noChanges&&!be&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs font-medium text-accent-success`,children:[(0,$.jsx)($o,{className:`h-3.5 w-3.5`}),G.continuation?n(`prCard.noChangesExisting`):n(`prCard.noChangesNote`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:G.continuation?mt:(0,$.jsxs)($.Fragment,{children:[ht,gt]})})]}),!be&&G.deliveryBlocked&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[lt,ut,G.continuation?G.hasDiscardableRecoveryResult?Y:mt:ft]}),!be&&G.retryablePush&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[ct,at(`create-pr`,n(`prCard.retryPush`)),G.continuation?mt:ft]}),!be&&G.retryablePrCreation&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[ct,at(`create-pr`,n(`prCard.retryPr`)),dt,G.continuation?mt:ft]}),!be&&G.closed&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[ct,at(`reopen`,n(`prCard.reopen`)),G.continuation?mt:ft]}),!be&&Se&&!G.deliveryBlocked&&!G.retryablePush&&!G.retryablePrCreation&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[ct,at(`create-pr`,n(`prCard.createPartialPr`,{count:G.deliverableCount})),G.continuation?mt:ft]}),z===`on_review`&&!G.noChanges&&!G.partial&&!G.deliveryBlocked&&!G.retryablePush&&!G.retryablePrCreation&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[ot,ct,at(`create-pr`,n(`prCard.createPr`)),dt,G.continuation?mt:ft]}),z===`pr_draft`&&!ge&&!G.deliveryBlocked&&!G.retryablePush&&!G.retryablePrCreation&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[ct,at(`publish`,n(`prCard.publish`)),G.continuation?mt:ft]}),ge&&!Se&&!G.deliveryBlocked&&!G.retryablePush&&!G.retryablePrCreation&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[ct,at(`create-pr`,n(`prCard.retryPr`)),dt,G.continuation?mt:ft]}),z===`pr_ready`&&!G.deliveryBlocked&&!G.retryablePush&&!G.retryablePrCreation&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[ct,at(`poll-merge`,n(`prCard.verifyPr`)),G.continuation?mt:ft]}),z===`pr_failed`&&!G.deliveryBlocked&&!G.retryablePush&&!G.retryablePrCreation&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[ct,at(`create-pr`,n(`prCard.retry`)),!B&&dt,G.continuation?mt:ft]}),z===`implementation_failed`&&G.implementationFailed&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`p`,{className:`flex items-start gap-1.5 text-[11px] leading-4 text-destructive`,children:[(0,$.jsx)(zn,{className:`mt-px h-3 w-3 shrink-0`}),n(`prCard.implementationFailedNote`)]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[Ge,qe,G.continuation?mt:ft]})]}),ve&&z===`discarded`&&j.statusCode===`delivery_failed`&&(0,$.jsx)(`div`,{className:`mb-2 flex flex-wrap items-center gap-1.5`,"data-testid":`mission-run-discarded-actions`,children:qe}),z===`merged`&&(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs font-medium text-accent-success`,children:[(0,$.jsx)($o,{className:`h-3.5 w-3.5`}),n(`prCard.mergedNote`)]}),z===`discarded`&&(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-foreground/50`,children:[(0,$.jsx)(Tn,{className:`h-3.5 w-3.5`}),n(`prCard.discardedNote`)]}),z===`completed`&&(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs font-medium text-accent-success`,children:[(0,$.jsx)($o,{className:`h-3.5 w-3.5`}),n(`prCard.completedNote`)]}),z===`superseded`&&(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-foreground/50`,children:[(0,$.jsx)(A,{className:`h-3.5 w-3.5`}),n(`prCard.supersededNote`)]})]},`${z}-${B??``}`),(0,$.jsx)(mr,{open:!fe&&b,onOpenChange:x,children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`agent-pr-merge-local-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:n(`prCard.confirm.mergeLocalTitle`)}),(0,$.jsx)(ir,{children:n(`prCard.confirm.mergeLocalBody`,{base:j.baseBranch})})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:()=>x(!1),children:n(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:nt,"data-testid":`agent-pr-merge-local-confirm-btn`,onClick:()=>{x(!1),Ee(`merge-local`)},children:n(`prCard.mergeLocal`)})]})]})}),(0,$.jsx)(mr,{open:E,onOpenChange:D,children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`agent-pr-recover-and-retry-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:n(q?`prCard.confirm.recheckRecoveryTitle`:`prCard.confirm.recoverAndRetryTitle`)}),(0,$.jsx)(ir,{children:n(q?`prCard.confirm.recheckRecoveryBody`:`prCard.confirm.recoverAndRetryBody`,{branch:j.branch??``})})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:()=>D(!1),children:n(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:nt,"data-testid":`agent-pr-recover-and-retry-confirm-btn`,onClick:()=>{D(!1),Ee(`recover-and-retry`)},children:n(q?`prCard.recheckRecovery`:`prCard.recoverAndRetry`)})]})]})}),(0,$.jsx)(mr,{open:m,onOpenChange:h,children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`agent-pr-discard-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:n(z===`implementation_failed`?`prCard.confirm.implementationFailedDiscardTitle`:`prCard.confirm.freshDiscardTitle`)}),(0,$.jsx)(ir,{children:n(z===`implementation_failed`?`prCard.confirm.implementationFailedDiscardBody`:`prCard.confirm.freshDiscardBody`)}),M&&(0,$.jsx)(`p`,{className:`mt-2 rounded-md border border-accent-warning/40 bg-accent-warning/10 px-2 py-1.5 text-xs text-accent-warning`,"data-testid":`agent-pr-discard-stacked-note`,children:n(`prCard.discardStackedNote`)})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:()=>h(!1),children:n(`common:actions.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,size:`sm`,disabled:nt,"data-testid":`agent-pr-discard-confirm-btn`,onClick:()=>{h(!1),Ee(`discard`)},children:n(`prCard.discard`)})]})]})}),(0,$.jsx)(mr,{open:g,onOpenChange:_,children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`agent-pr-dismiss-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:n(`prCard.confirm.dismissTitle`)}),(0,$.jsx)(ir,{children:n(`prCard.confirm.dismissBody`)})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:()=>_(!1),children:n(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:nt,"data-testid":`agent-pr-dismiss-confirm-btn`,onClick:()=>{_(!1),Ee(`dismiss`)},children:n(`prCard.dismiss`)})]})]})}),(0,$.jsx)(mr,{open:v,onOpenChange:y,children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`agent-pr-discard-local-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:n(`prCard.confirm.discardLocalTitle`)}),(0,$.jsx)(ir,{children:n(`prCard.confirm.discardLocalBody`)})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:()=>y(!1),children:n(`common:actions.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,size:`sm`,disabled:nt,"data-testid":`agent-pr-discard-local-confirm-btn`,onClick:()=>{y(!1),Ee(`discard`)},children:n(`prCard.discardLocalResult`)})]})]})}),(0,$.jsx)(mr,{open:!fe&&S,onOpenChange:C,children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`agent-pr-no-changes-done-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:n(`prCard.confirm.noChangesDoneTitle`)}),(0,$.jsx)(ir,{children:n(`prCard.confirm.noChangesDoneBody`)})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:()=>C(!1),children:n(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:nt,"data-testid":`agent-pr-no-changes-done-confirm-btn`,onClick:()=>{C(!1),Ee(`acknowledge-no-changes`)},children:n(`prCard.markDone`)})]})]})}),(0,$.jsx)(mr,{open:w,onOpenChange:T,children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`agent-pr-refine-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:n(`prCard.confirm.refineTitle`)}),(0,$.jsx)(ir,{children:n(`prCard.confirm.refineBody`)})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:()=>T(!1),children:n(`common:actions.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,size:`sm`,disabled:nt,"data-testid":`agent-pr-refine-confirm-btn`,onClick:()=>{T(!1),Ee(`discard`)},children:n(`prCard.refine`)})]})]})}),Ze]})}var hj={building:`border-accent-primary/40 bg-accent-primary/10 text-accent-primary`,on_review:`border-accent-primary/40 bg-accent-primary/10 text-accent-primary`,pr_draft:`border-accent-info/40 bg-accent-info/10 text-accent-info`,pr_ready:`border-accent-info/40 bg-accent-info/10 text-accent-info`,no_changes:`border-accent-success/40 bg-accent-success/10 text-accent-success`,completed:`border-accent-success/40 bg-accent-success/10 text-accent-success`,pr_closed:`border-accent-warning/40 bg-accent-warning/10 text-accent-warning`,superseded:`border-border/60 bg-surface/60 text-foreground/40`,implementation_failed:`border-destructive/40 bg-destructive/10 text-destructive`,pr_failed:`border-destructive/40 bg-destructive/10 text-destructive`,merged:`border-accent-success/40 bg-accent-success/10 text-accent-success`,discarded:`border-border/60 bg-surface/60 text-foreground/50`};function gj({decision:e}){let{t}=K(`agent`);return(0,$.jsx)(`span`,{"data-testid":`pr-decision-pill`,className:X(`inline-flex shrink-0 items-center rounded-full border px-1.5 py-px text-[10px] font-medium uppercase tracking-wide`,hj[e]),children:t(`prCard.pinned.state.${e}`)})}function _j(){let{t:e}=K(`agent`);return(0,$.jsx)(`span`,{"data-testid":`rail-proposal-pill`,className:`inline-flex shrink-0 items-center rounded-full border border-accent-primary/40 bg-accent-primary/10 px-1.5 py-px text-[10px] font-medium uppercase tracking-wide text-accent-primary`,children:e(`railCard.status.proposal`)})}var vj=e=>`specrails-desktop:agent-pr-dock-collapsed:${e}`,yj=e=>`specrails-desktop:agent-pr-dock-card-collapsed:${e}`;function bj(e){try{return sessionStorage.getItem(vj(e))===`1`}catch{return!1}}function xj(e,t){try{t?sessionStorage.setItem(vj(e),`1`):sessionStorage.removeItem(vj(e))}catch{}}function Sj(e){try{let t=sessionStorage.getItem(yj(e)),n=t?JSON.parse(t):[];return new Set(Array.isArray(n)?n.filter(e=>typeof e==`string`):[])}catch{return new Set}}function Cj(e,t){try{t.size===0?sessionStorage.removeItem(yj(e)):sessionStorage.setItem(yj(e),JSON.stringify([...t]))}catch{}}function wj({pinned:e,proposals:t=[],projectId:n=null,conversationId:r,inline:i}){let{t:a}=K(`agent`),[o,s]=(0,Q.useState)(()=>bj(r)),[c,l]=(0,Q.useState)(()=>Sj(r));(0,Q.useEffect)(()=>{s(bj(r)),l(Sj(r))},[r]);let u=e.length+t.length;if(u===0)return null;let d=e.length>0?e[e.length-1]:null,f=e=>{xj(r,e),s(e)},p=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),Cj(r,n),n})},m=e=>{let t=a(`prCard.rail`,{index:e.railIndex+1}),n=e.ticketIds.map(e=>`#${e}`).join(` `);return n?`${t} · ${n}`:t};return(0,$.jsx)(Ny.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:8},transition:{duration:.2,ease:`easeOut`},"data-testid":`agent-pr-pinned-dock`,className:X(`shrink-0`,i?`px-4 pb-2`:`px-3 pb-2`),children:(0,$.jsx)(`div`,{className:X(i&&`mx-auto w-full max-w-[680px]`),children:o?(0,$.jsxs)(`button`,{type:`button`,"data-testid":`agent-pr-dock-expand`,"data-agent-interactive":!0,onClick:()=>f(!1),"aria-label":a(`prCard.pinned.expand`),title:a(`prCard.pinned.expand`),className:`flex w-full items-center gap-2 rounded-xl border border-border/60 bg-card/80 px-3 py-1.5 text-xs text-foreground/70 shadow-lg backdrop-blur-xl transition-colors hover:border-accent-primary/40 hover:bg-surface/60`,children:[(0,$.jsx)(oc,{className:`h-3.5 w-3.5 shrink-0 text-accent-primary/70`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,children:a(`prCard.pinned.collapsed`,{count:u})}),d?(0,$.jsx)(gj,{decision:d.envelope.decision}):(0,$.jsx)(_j,{}),(0,$.jsx)(gn,{className:`h-3.5 w-3.5 shrink-0 opacity-60`})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-1`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium uppercase tracking-wide text-foreground/45`,children:[(0,$.jsx)(oc,{className:`h-3 w-3 text-accent-primary/60`}),a(`prCard.pinned.label`),u>1&&(0,$.jsx)(`span`,{className:`rounded-full border border-border/60 bg-surface/60 px-1.5 py-px text-[9px] tabular-nums text-foreground/55`,children:u})]}),(0,$.jsx)(`button`,{type:`button`,"data-testid":`agent-pr-dock-collapse`,"data-agent-interactive":!0,onClick:()=>f(!0),"aria-label":a(`prCard.pinned.collapse`),title:a(`prCard.pinned.collapse`),className:`rounded p-0.5 text-foreground/45 transition-colors hover:bg-surface hover:text-foreground`,children:(0,$.jsx)(Xo,{className:`h-3.5 w-3.5`})})]}),(0,$.jsxs)(`div`,{"data-testid":`agent-pr-dock-stack`,className:`max-h-[45vh] space-y-1.5 overflow-y-auto overscroll-contain`,children:[t.map(e=>{let t=`proposal:${e.messageId}:${e.proposalIndex}`,i=c.has(t),o=e.proposal.ticketIds.map(e=>`#${e}`).join(` `);return(0,$.jsxs)(`div`,{"data-testid":`agent-rail-launch-dock-card`,className:`space-y-1`,children:[(0,$.jsxs)(`button`,{type:`button`,"data-testid":`agent-rail-launch-dock-card-toggle`,"data-agent-interactive":!0,onClick:()=>p(t),"aria-expanded":!i,"aria-label":a(i?`prCard.pinned.expandCard`:`prCard.pinned.collapseCard`),className:X(`flex w-full items-center gap-2 rounded-lg border px-2.5 py-1 text-[11px] text-foreground/70 transition-colors`,i?`border-border/60 bg-card/80 shadow backdrop-blur-xl hover:border-accent-primary/40 hover:bg-surface/70`:`border-transparent bg-transparent hover:bg-surface/50`),children:[(0,$.jsx)(gc,{className:`h-3 w-3 shrink-0 text-accent-primary/70`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-left font-medium`,children:[a(`railCard.heading`),o?` · ${o}`:``]}),(0,$.jsx)(_j,{}),i?(0,$.jsx)(gn,{className:`h-3 w-3 shrink-0 opacity-60`}):(0,$.jsx)(Xo,{className:`h-3 w-3 shrink-0 opacity-60`})]}),!i&&(0,$.jsx)(tD,{proposal:e.proposal,proposalIndex:e.proposalIndex,messageId:e.messageId,conversationId:r,projectId:n,intent:null,compact:!0})]},t)}),e.map(e=>{let t=e.envelope.prDeliveryId,n=c.has(t);return(0,$.jsxs)(`div`,{"data-testid":`agent-pr-dock-card`,className:`space-y-1`,children:[(0,$.jsxs)(`button`,{type:`button`,"data-testid":`agent-pr-dock-card-toggle`,"data-agent-interactive":!0,onClick:()=>p(t),"aria-expanded":!n,"aria-label":a(n?`prCard.pinned.expandCard`:`prCard.pinned.collapseCard`),title:a(n?`prCard.pinned.expandCard`:`prCard.pinned.collapseCard`),className:X(`flex w-full items-center gap-2 rounded-lg border px-2.5 py-1 text-[11px] text-foreground/70 transition-colors`,n?`border-border/60 bg-card/80 shadow backdrop-blur-xl hover:border-accent-primary/40 hover:bg-surface/70`:`border-transparent bg-transparent hover:bg-surface/50`),children:[(0,$.jsx)(A,{className:`h-3 w-3 shrink-0 text-accent-primary/70`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left font-medium`,children:m(e.envelope)}),(0,$.jsx)(gj,{decision:e.envelope.decision}),n?(0,$.jsx)(gn,{className:`h-3 w-3 shrink-0 opacity-60`}):(0,$.jsx)(Xo,{className:`h-3 w-3 shrink-0 opacity-60`})]}),!n&&(0,$.jsx)(mj,{envelope:e.envelope,conversationId:r})]},e.messageId)})]})]})})})}function Tj(e){return e?e.charAt(0).toUpperCase()+e.slice(1):`Unknown`}function Ej(e,t,n,r){let i=e.title?.trim()||`Untitled mission`,a=r?.exportedAt??new Date().toISOString(),o=[`Mission: ${i}`,`Mission ID: ${e.id}`];return n?.name&&o.push(`Project: ${n.name}`),n?.path&&o.push(`Project path: ${n.path}`),o.push(`Exported at: ${a}`,``,`Messages:`),t.length===0?(o.push(`No messages loaded.`),o.join(`
|
|
47
47
|
`)):(t.forEach((e,t)=>{t>0&&o.push(``),o.push(`[${e.created_at}] ${Tj(e.role)}`,e.content)}),o.join(`
|
|
48
|
-
`))}function Dj(e,t){let n=(e??``).normalize(`NFKD`).replace(/[\u0300-\u036f]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``),r=t.trim()||`mission`;return`${n||r}.txt`}function Oj(){let{t:e}=K(`agent`),{active:t,messages:n,renameConversation:r,deleteConversation:i,startNewConversation:a,favoriteConversationIds:o,toggleFavoriteConversation:s}=aP(),{projects:c}=pt(),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(!1),y=(0,Q.useRef)(null),b=(0,Q.useRef)(null),x=t?.pinned_project_id?c.find(e=>e.id===t.pinned_project_id)??null:null,S=t?.title?.trim()||e(`header.untitled`),C=t?o.has(t.id):!1;(0,Q.useEffect)(()=>{if(!l)return;let e=e=>{y.current&&!y.current.contains(e.target)&&u(!1)},t=e=>{e.key===`Escape`&&u(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[l]),(0,Q.useEffect)(()=>{l||v(!1)},[l]),(0,Q.useEffect)(()=>{d&&(b.current?.focus(),b.current?.select())},[d]);let w=(0,Q.useCallback)(()=>{m(t?.title??``),f(!0),u(!1)},[t?.title]),T=(0,Q.useCallback)(async()=>{if(t&&(f(!1),(t.title??``)!==p.trim()))try{await r(t.id,p)}catch{J.error(e(`header.renameFailed`))}},[t,p,r,e]),E=(0,Q.useCallback)(async(t,n)=>{u(!1);try{await navigator.clipboard.writeText(t),g(n),setTimeout(()=>g(e=>e===n?null:e),1400)}catch{J.error(e(`header.copyFailed`))}},[e]),D=(0,Q.useCallback)(async()=>{if(t){u(!1);try{await navigator.clipboard.writeText(Ej(t,n,x)),g(`transcript`),J.success(e(`header.copyTranscriptSuccess`,{defaultValue:`Transcript copied`})),setTimeout(()=>g(e=>e===`transcript`?null:e),1400)}catch{J.error(e(`header.copyTranscriptFailed`,{defaultValue:`Could not copy transcript`}))}}},[t,n,x,e]),O=(0,Q.useCallback)(()=>{if(t){u(!1);try{let r=Ej(t,n,x),i=new Blob([r],{type:`text/plain;charset=utf-8`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=Dj(t.title,t.id),document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a),J.success(e(`header.exportTranscriptSuccess`,{defaultValue:`Transcript export started`}))}catch{J.error(e(`header.exportTranscriptFailed`,{defaultValue:`Could not export transcript`}))}}},[t,n,x,e]),k=(0,Q.useCallback)(async()=>{if(t){u(!1),v(!1);try{await i(t.id),a(t.pinned_project_id)}catch{J.error(e(`header.deleteFailed`))}}},[t,i,a,e]),A=(0,Q.useCallback)(()=>{t&&(s(t.id),u(!1))},[t,s]);if(!t)return null;let j=[{id:`name`,label:e(`header.copyName`),value:t.title??S},{id:`id`,label:e(`header.copyId`),value:t.id},...x?[{id:`project`,label:e(`header.copyProject`),value:x.name},{id:`path`,label:e(`header.copyProjectPath`),value:x.path}]:[]];return(0,$.jsxs)(`div`,{ref:y,"data-agent-interactive":!0,className:`relative flex h-12 shrink-0 items-center gap-2 border-b border-border px-4`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5 text-sm`,children:[x&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`max-w-[42%] shrink-0 truncate font-mono text-[12px] text-foreground/35`,title:x.path,children:x.path}),(0,$.jsx)(Zo,{className:`h-3.5 w-3.5 shrink-0 text-foreground/25`,"aria-hidden":!0})]}),d?(0,$.jsx)(`input`,{ref:b,value:p,onChange:e=>m(e.target.value),onBlur:()=>void T(),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),T()):e.key===`Escape`&&(e.preventDefault(),f(!1))},placeholder:e(`header.renamePlaceholder`),className:`min-w-0 flex-1 rounded-md border border-accent-primary/40 bg-surface/60 px-2 py-0.5 text-sm text-foreground outline-none focus:border-accent-primary/70`,maxLength:200}):(0,$.jsx)(`button`,{type:`button`,onDoubleClick:w,title:e(`header.renameHint`),className:`min-w-0 flex-1 truncate text-left font-medium text-foreground/85`,children:S})]}),(0,$.jsx)(Rc,{}),(0,$.jsx)(`button`,{type:`button`,"data-testid":`agent-conv-menu-trigger`,"aria-label":e(`header.menu`),"aria-haspopup":`menu`,"aria-expanded":l,onClick:()=>u(e=>!e),className:X(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-foreground/45 transition-colors hover:bg-surface hover:text-foreground/80`,l&&`bg-surface text-foreground/80`),children:(0,$.jsx)(gs,{className:`h-4 w-4`})}),(0,$.jsx)(N_,{children:l&&(0,$.jsx)(Ny.div,{role:`menu`,"data-testid":`agent-conv-menu`,initial:{opacity:0,y:-4,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.98},transition:{duration:.14,ease:`easeOut`},className:`absolute right-3 top-11 z-50 min-w-[220px] overflow-hidden rounded-xl border border-border/50 bg-card/95 p-1 shadow-2xl backdrop-blur-xl`,children:_?(0,$.jsxs)(`div`,{className:`p-2`,"data-testid":`agent-conv-delete-confirm`,children:[(0,$.jsx)(`p`,{className:`px-1 pb-2.5 text-xs leading-relaxed text-foreground/70`,children:e(`header.deleteConfirm`)}),(0,$.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,"data-testid":`agent-conv-delete-confirm-btn`,onClick:()=>void k(),className:`flex-1 rounded-lg bg-destructive/90 px-2.5 py-1.5 text-xs font-medium text-white transition-colors hover:bg-destructive`,children:e(`header.delete`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>v(!1),className:`flex-1 rounded-lg border border-border/60 px-2.5 py-1.5 text-xs text-foreground/80 transition-colors hover:bg-surface/80`,children:e(`common:actions.cancel`)})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":`agent-conv-rename`,onClick:w,className:`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-sm text-foreground/85 transition-colors hover:bg-surface/80`,children:[(0,$.jsx)(jn,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`}),e(`header.rename`)]}),(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":`agent-conv-favorite`,onClick:A,className:`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-sm text-foreground/85 transition-colors hover:bg-surface/80`,children:[(0,$.jsx)(Ps,{className:X(`h-3.5 w-3.5 shrink-0`,C?`text-accent-primary`:`text-foreground/50`),fill:C?`currentColor`:`none`}),e(C?`header.removeFavorite`:`header.addFavorite`)]}),(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":`agent-conv-delete`,onClick:()=>v(!0),className:`group/del flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-sm text-foreground/85 transition-colors hover:bg-destructive/10 hover:text-destructive`,children:[(0,$.jsx)(Rn,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50 group-hover/del:text-destructive`}),e(`header.delete`)]}),(0,$.jsx)(`div`,{className:`my-1 h-px bg-border/50`}),(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":`agent-conv-copy-transcript`,onClick:()=>void D(),className:`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-sm text-foreground/85 transition-colors hover:bg-surface/80`,children:[h===`transcript`?(0,$.jsx)(Sn,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`}):(0,$.jsx)(ls,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,children:e(`header.copyTranscript`,{defaultValue:`Copy transcript`})})]}),(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":`agent-conv-export-transcript`,onClick:O,className:`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-sm text-foreground/85 transition-colors hover:bg-surface/80`,children:[(0,$.jsx)(En,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,children:e(`header.exportTranscript`,{defaultValue:`Export transcript (.txt)`})})]}),j.map(e=>e===`divider`?null:(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":`agent-conv-copy-${e.id}`,onClick:()=>void E(e.value,e.id),className:`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-sm text-foreground/85 transition-colors hover:bg-surface/80`,children:[h===e.id?(0,$.jsx)(Sn,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`}):(0,$.jsx)(ls,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,children:e.label})]},e.id))]})})})]})}var kj=new Set([`building`,`on_review`,`pr_draft`,`no_changes`,`pr_closed`,`implementation_failed`,`pr_failed`]);function Aj(e){return kj.has(e)}function jj(e){return!!(Aj(e.decision)||e.phase===`launched`||e.phase===`running`||e.runtime?.failure&&e.decision!==`discarded`&&e.decision!==`superseded`)}function Mj(e){let t=[];for(let[n,r]of e.entries()){if(r.role!==`system`)continue;let e=wo(r.content);e&&t.push({messageId:r.id,envelope:e,position:n})}let n=new Map;for(let e of t){let t=n.get(e.envelope.prDeliveryId);if(!t){n.set(e.envelope.prDeliveryId,e);continue}let r=zt(t.envelope.updatedAt,e.envelope.updatedAt);(r===1||r===null&&e.position>t.position)&&n.set(e.envelope.prDeliveryId,e)}let r=new Set(t.map(({envelope:e})=>e.supersedesDeliveryId).filter(e=>!!e)),i=new Set,a=[...n.values()];for(let e of a){let t=e.envelope.restoredFromDeliveryId;if(!t)continue;let n=null;for(let t of a){if(t.envelope.supersedesDeliveryId!==e.envelope.prDeliveryId)continue;if(!n){n=t;continue}let r=zt(n.envelope.createdAt,t.envelope.createdAt);(r===1||(r===0||r===null)&&t.position>n.position)&&(n=t)}n&&n.envelope.prDeliveryId!==t||(r.delete(e.envelope.prDeliveryId),r.add(t),i.add(t))}let o=new Map;for(let e of n.values()){if(r.has(e.envelope.prDeliveryId))continue;let t=o.get(e.envelope.railIndex)??[];t.push(e),o.set(e.envelope.railIndex,t)}for(let e of o.values()){if(e.length<=1)continue;let t=e[0];for(let n of e.slice(1))zt(t.envelope.createdAt,n.envelope.createdAt)===1&&(t=n);for(let n of e)n.envelope.prDeliveryId!==t.envelope.prDeliveryId&&r.add(n.envelope.prDeliveryId)}let s=t.map(e=>r.has(e.envelope.prDeliveryId)&&(e.envelope.decision!==`superseded`||i.has(e.envelope.prDeliveryId))?{...e,envelope:{...e.envelope,decision:i.has(e.envelope.prDeliveryId)?`discarded`:`superseded`}}:e),c=new Map,l=new Set,u=[];for(let e of s){if(n.get(e.envelope.prDeliveryId)?.messageId!==e.messageId){l.add(e.messageId);continue}c.set(e.messageId,e.envelope),jj(e.envelope)&&u.push(e)}return{byMessageId:c,duplicateMessageIds:l,pinned:u}}function Nj({row:e}){let{t}=K(`agent`);return(0,$.jsxs)(`div`,{"data-testid":`agent-run-failure-marker`,className:`flex items-center gap-2 rounded-lg border border-destructive/30 bg-destructive/[0.06] px-3 py-1.5 text-[11px] text-foreground/70 backdrop-blur-sm`,children:[(0,$.jsx)(zn,{className:`h-3.5 w-3.5 shrink-0 text-destructive`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[(0,$.jsx)(`span`,{className:`font-medium text-destructive`,children:t(`runFailure.marker`,{rail:e.railIndex+1,code:e.code})}),e.detail&&(0,$.jsxs)(`span`,{className:`text-foreground/55`,children:[` · `,e.detail]})]}),(0,$.jsx)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`agent-run-failure-open`,onClick:()=>nO({prDeliveryId:e.prDeliveryId??null,runIds:[e.runId]}),className:`shrink-0 rounded-md border border-destructive/35 px-2 py-0.5 text-[10px] font-medium text-destructive transition-colors hover:bg-destructive/10`,children:t(`runFailure.openCard`)})]})}function Pj({content:e,contextRefs:t}){let{t:n}=K(`agent`),[r,i]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{"data-testid":`agent-system-briefing`,className:`flex flex-col items-end gap-1`,children:[(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,onClick:()=>i(e=>!e),"aria-expanded":r,className:X(`inline-flex items-center gap-1.5 rounded-full border border-border/50 bg-surface/50 px-2.5 py-1 text-[11px] text-foreground/60 transition-colors hover:border-accent-primary/40 hover:text-foreground/80`),children:[(0,$.jsx)(Ln,{className:`h-3 w-3 text-accent-primary/70`,"aria-hidden":!0}),n(`runFailure.briefing.title`),r?(0,$.jsx)(Xo,{className:`h-3 w-3 opacity-60`,"aria-hidden":!0}):(0,$.jsx)(Zo,{className:`h-3 w-3 opacity-60`,"aria-hidden":!0})]}),r&&(0,$.jsx)(`div`,{className:`max-w-[85%] whitespace-pre-wrap rounded-2xl rounded-tr-sm border border-border/40 bg-surface/40 px-3.5 py-2 text-xs text-foreground/70`,"data-testid":`agent-system-briefing-body`,children:(0,$.jsx)(XD,{content:e,contextRefs:t})})]})}var Fj={pinnedMessageIds:new Set,pinned:[]};function Ij(e){let t=Ux();return(0,Q.useMemo)(()=>{if(!ve)return Fj;let n=[],r=new Set;for(let i of e){if(i.role!==`assistant`||!i.content.includes("```rail-launch"))continue;let{proposals:e}=Rx(i.content,!1);e.forEach((e,a)=>{Wx(t,i.id,i.intents,a)||(n.push({messageId:i.id,proposalIndex:a,proposal:e}),r.add(i.id))})}return{pinnedMessageIds:r,pinned:n}},[e,t])}var Lj=(0,Q.lazy)(()=>c(()=>import(`./JobDetailModal-DSsX48Vu.js`).then(e=>({default:e.JobDetailModal})),__vite__mapDeps([6,1,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]))),Rj=(0,Q.lazy)(()=>c(()=>import(`./LoopPreviewModal-C-NbAvIZ.js`).then(e=>({default:e.LoopPreviewModal})),__vite__mapDeps([81,1,7,8,11,10,43,59,60,68,69,73,67,51,82,54,56]))),zj=new Set,Bj=new Set([`spec-framing.committed`]);function Vj(e){if(!e.startsWith(`{`))return!1;try{let t=JSON.parse(e);return typeof t?.kind==`string`&&Bj.has(t.kind)}catch{return!1}}function Hj({variant:e}){let{t}=K(`agent`),{active:n}=aP(),r=Ci(),i=Wy(n?.id??`__new-mission__`),a=r.transfers.find(e=>e.conversationId===n?.id);if(n&&!r.current&&a?.state===`detached`)return(0,$.jsxs)(`div`,{className:`flex h-full flex-col`,children:[e===`inline`&&(0,$.jsx)(Oj,{}),(0,$.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,$.jsx)(pn,{className:`h-8 w-8 text-accent-primary`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t(`window.detached`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{r.focus(n.id)},className:`rounded-md bg-accent-primary px-4 py-2 text-sm text-white`,children:t(`window.focus`)})]})]});let o=!!n&&!r.isEditable(n.id);return(0,$.jsx)(`div`,{className:`relative flex h-full min-h-0 flex-col`,inert:o||void 0,"aria-busy":o||void 0,children:(0,$.jsx)(Uj,{variant:e},`${n?.id??`__new-mission__`}:${i}`)})}function Uj({variant:e}){let{t}=K(`agent`),{active:n,messages:r,streamingText:i,isStreaming:a,liveTools:o,turnTools:s,queuedMessages:c,mcpEnabled:l,enablingMcp:u,enableMcpServer:d,providersReady:f,cycleTier:p,send:m}=aP(),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(),y=o.length>0?o:s,b=(0,Q.useRef)(null),x=Qy(i,a),{openRef:C,jobRef:w,closeJobRef:T,loopRef:E,closeLoopRef:D}=Rb(),O=n?.pinned_project_id??null,[k,A]=(0,Q.useState)(new Map),j=(0,Q.useMemo)(()=>{let e=new Set;for(let t of r)for(let n of t.attachment_ids??[])e.add(n);for(let t of c)for(let n of t.attachmentIds??[])e.add(n);return[...e].sort()},[r,c]).join(`\0`);(0,Q.useEffect)(()=>{let e=j?j.split(`\0`):[];if(!n?.id||e.length===0){A(new Map);return}let t=!1,r=new Set(e);return lo(n.id).then(e=>{t||A(new Map(e.filter(e=>r.has(e.id)).map(e=>[e.id,e])))}).catch(()=>{t||A(new Map)}),()=>{t=!0}},[n?.id,j]);let M=(0,Q.useMemo)(()=>O?e=>{C(O,e)}:void 0,[O,C]),N=wa().id===`code-rain`?t(`emptyTitleCodeRain`):t(`emptyTitle`),P=(0,Q.useMemo)(()=>Mj(r),[r]),F=Ij(r),I=n?Hy(n.id):null,L=(0,Q.useRef)(I?.atBottom??!0);(0,Q.useLayoutEffect)(()=>{let e=b.current;return e&&I&&(e.scrollTop=I.atBottom?e.scrollHeight:I.top),()=>{e&&n&&Vy(n.id,{top:e.scrollTop,atBottom:L.current})}},[n?.id]);let R=()=>{let e=b.current;e&&(L.current=e.scrollHeight-e.scrollTop-e.clientHeight<48,n&&Vy(n.id,{top:e.scrollTop,atBottom:L.current}))};(0,Q.useEffect)(()=>{L.current&&b.current?.scrollTo?.({top:b.current.scrollHeight,behavior:`auto`})},[r.length,x,o.length,c.length]);let z=e=>{e.shiftKey&&(e.key===`Tab`||e.code===`Tab`)&&(e.preventDefault(),e.stopPropagation(),p())},B=e===`inline`,V=B?`mx-auto flex w-full max-w-[820px] flex-1 flex-col overflow-hidden`:`flex flex-1 flex-col overflow-hidden`;return(0,$.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden `,onKeyDown:z,children:[f===!1&&(0,$.jsxs)(`div`,{className:`flex items-start gap-2 border-b border-border/50 bg-accent-warning/10 px-3 py-2 text-xs text-foreground`,children:[(0,$.jsx)(Qs,{className:`mt-0.5 h-4 w-4 shrink-0 text-accent-warning`}),(0,$.jsxs)(`div`,{className:`flex-1`,children:[(0,$.jsx)(`p`,{className:`font-medium`,children:t(`noProvider.title`)}),(0,$.jsx)(`p`,{className:`mt-0.5 text-foreground/70`,children:t(`noProvider.body`)})]})]}),f!==!1&&!l&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/50 bg-accent-warning/10 px-3 py-2 text-xs text-foreground`,children:[(0,$.jsx)(S,{className:`h-4 w-4 shrink-0 text-accent-warning`}),(0,$.jsx)(`span`,{className:`flex-1`,children:t(`degraded.body`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void d(),disabled:u,className:`rounded-md bg-accent-primary px-2 py-1 text-xs font-medium text-white disabled:opacity-60`,children:t(u?`degraded.enabling`:`degraded.enable`)})]}),B&&n&&(0,$.jsx)(Oj,{}),(0,$.jsxs)(`div`,{className:V,children:[(0,$.jsxs)(Ny.div,{ref:b,onScroll:R,initial:B?{opacity:0,y:8}:!1,animate:{opacity:1,y:0},transition:{duration:.35,ease:`easeOut`},className:`flex-1 space-y-5 overflow-y-auto px-4 py-4`,children:[r.length===0&&!a&&(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center text-center text-foreground/50`,children:[(0,$.jsx)(Vo,{className:`mb-2 h-8 w-8 text-accent-primary/60`}),(0,$.jsx)(`p`,{className:`text-sm font-medium text-foreground/70`,children:N}),(0,$.jsx)(`p`,{className:`mt-1 max-w-[280px] text-xs`,children:t(`emptyHint`)})]}),r.map((e,i)=>{if(e.role===`system`){if(Vj(e.content))return null;if(ve){let t=$D(e.content);if(t)return(0,$.jsx)(Nj,{row:t},e.id)}let n=P.byMessageId.get(e.id);return n?jj(n)?(0,$.jsxs)(`div`,{"data-testid":`agent-pr-pinned-marker`,className:`flex items-center gap-2 rounded-lg border border-border/40 bg-surface/30 px-3 py-1.5 text-[11px] text-foreground/45 backdrop-blur-sm`,children:[(0,$.jsx)(oc,{className:`h-3 w-3 shrink-0 text-accent-primary/50`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t(`prCard.pinned.marker`)}),(0,$.jsx)(gj,{decision:n.decision})]},e.id):(0,$.jsx)(mj,{envelope:n,conversationId:e.conversation_id},e.id):(P.duplicateMessageIds.has(e.id)||zj.has(e.id)||(zj.add(e.id),console.warn(`[agent-chat] skipping unrenderable system message ${e.id}`)),null)}if(ve&&eO(e))return(0,$.jsx)(Pj,{content:e.content,contextRefs:e.context_refs},e.id);let o=F.pinnedMessageIds.has(e.id);return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(ZD,{role:e.role,content:e.content,messageId:e.id,intents:e.intents??null,railProposalsPinned:o,tolerantFences:At(n?.provider),createdAt:e.created_at,isLast:!a&&i===r.length-1,isLatest:i===r.length-1,isStreaming:a,onPickOption:e=>void m(e),refsProjectId:O,onOpenRef:M,contextRefs:e.context_refs,deliveryStatus:e.delivery_status,deliveryReceipt:e.delivery_receipt,conversationId:e.conversation_id,attachments:(e.attachment_ids??[]).map(e=>k.get(e)).filter(e=>!!e)}),o&&(0,$.jsxs)(`div`,{"data-testid":`agent-rail-launch-pinned-marker`,className:`flex items-center gap-2 rounded-lg border border-border/40 bg-surface/30 px-3 py-1.5 text-[11px] text-foreground/45 backdrop-blur-sm`,children:[(0,$.jsx)(oc,{className:`h-3 w-3 shrink-0 text-accent-primary/50`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t(`railCard.pinnedMarker`)})]})]},e.id)}),a&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[x&&(0,$.jsx)(ZD,{role:`assistant`,content:x,streaming:!0,tolerantFences:At(n?.provider)}),(0,$.jsx)(Vb,{tool:o.length?o[o.length-1].tool:null,onClick:()=>g(!0)})]}),c.length>0&&(0,$.jsx)(`div`,{className:`space-y-2`,"data-testid":`agent-queued-messages`,children:c.map(e=>(0,$.jsx)(QD,{item:e,conversationId:n?.id,onEdit:e=>{n&&v(t=>({conversationId:n.id,queueId:e,revision:(t?.revision??0)+1}))},attachments:(e.attachmentIds??[]).map(e=>k.get(e)).filter(e=>!!e)},`${n?.id}:${e.queueId}`))})]}),(0,$.jsx)(N_,{initial:!1,children:n&&(P.pinned.length>0||F.pinned.length>0)&&(0,$.jsx)(wj,{pinned:P.pinned,proposals:F.pinned,projectId:O,conversationId:n.id,inline:B},`agent-pr-pinned-dock`)}),B?(0,$.jsx)(`div`,{className:`shrink-0 px-4 pb-4`,children:(0,$.jsxs)(Ny.div,{layoutId:`agent-composer-dock`,transition:{layout:{type:`spring`,stiffness:350,damping:34}},className:`relative mx-auto w-full max-w-[680px] rounded-2xl border border-border/60 bg-card/90 p-3 shadow-2xl backdrop-blur-xl`,"data-testid":`agent-composer-dock`,children:[(0,$.jsx)(UA,{active:a,radius:`1rem`,inset:-3}),(0,$.jsx)(MA,{queueEditRequest:_})]})}):(0,$.jsxs)(`div`,{className:`relative shrink-0 border-t border-border/50 bg-surface/30 p-3`,"data-testid":`agent-composer-dock`,children:[(0,$.jsx)(UA,{active:a,radius:`0.75rem`,inset:-2}),(0,$.jsx)(MA,{hideProjectSelector:!0,queueEditRequest:_})]})]}),w&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Lj,{jobId:w.jobId,projectId:w.projectId,onClose:T})}),E&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Rj,{loop:E,onClose:D})}),h&&(0,$.jsx)(Ub,{tools:y,streaming:a,onClose:()=>g(!1)})]})}var Wj=8,Gj=3e3;function Kj(){let{t:e}=K(`agent`),{conversations:t,active:n,selectConversation:r,deleteConversation:i,startNewConversation:a,streamingConversationIds:o,liveByConversation:s}=aP(),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(0),[m,h]=(0,Q.useState)(null),g=(0,Q.useRef)(null),_=(0,Q.useRef)(null),v=(0,Q.useRef)(null),y=(0,Q.useMemo)(()=>{let e=e=>{let t=Date.parse(e.updated_at);return Number.isNaN(t)?0:t};return[...t].sort((t,n)=>e(n)-e(t))},[t]),b=t.length>Wj,x=(0,Q.useMemo)(()=>{let t=u.trim().toLowerCase();if(!t)return y;let n=e(`mission.untitled`).toLowerCase();return y.filter(e=>(e.title?.trim().toLowerCase()||n).includes(t))},[y,u,e]),S=x.length+1,C=(0,Q.useCallback)(()=>{g.current&&clearTimeout(g.current),g.current=null,h(null)},[]);(0,Q.useEffect)(()=>()=>{g.current&&clearTimeout(g.current)},[]),(0,Q.useEffect)(()=>{if(!c)return;let e=e=>{_.current&&!_.current.contains(e.target)&&T()};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[c]);let w=()=>{let e=n?y.findIndex(e=>e.id===n.id):-1;p(e>=0?e+1:0),l(!0)},T=()=>{l(!1),d(``),C()},E=e=>{e!==n?.id&&r(e),T()},D=()=>{a(null),T()},O=e=>{g.current&&clearTimeout(g.current),h(e),g.current=setTimeout(()=>{h(null),g.current=null},Gj)},k=async t=>{C();let a=n?.id===t,o=y.find(e=>e.id!==t)??null;try{await i(t),a&&o&&await r(o.id)}catch{J.error(e(`mission.deleteFailed`))}},A=()=>{if(f===0)D();else{let e=x[f-1];e&&E(e.id)}},j=e=>{if(!c){e.key===`ArrowDown`&&(e.preventDefault(),w());return}if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=e.key===`ArrowDown`?1:-1;p(e=>(e+t+S)%S)}else e.key===`Home`?(e.preventDefault(),p(0)):e.key===`End`?(e.preventDefault(),p(S-1)):e.key===`Enter`?(e.preventDefault(),A()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),m?C():(T(),v.current?.focus()))},M=n?.title?.trim()||e(`mission.untitled`);return(0,$.jsxs)(`div`,{className:`relative min-w-0`,ref:_,"data-agent-interactive":!0,onKeyDown:j,children:[(0,$.jsxs)(`button`,{ref:v,type:`button`,"data-testid":`mission-trigger`,onClick:()=>c?T():w(),"aria-haspopup":`listbox`,"aria-expanded":c,"aria-controls":`agent-mission-listbox`,title:e(`mission.label`),className:`flex min-w-0 items-center gap-1.5 rounded-md px-1.5 py-1 text-sm font-medium text-foreground hover:bg-surface/70`,children:[(0,$.jsx)(bn,{className:`h-3.5 w-3.5 shrink-0 text-accent-primary`}),(0,$.jsx)(`span`,{className:`min-w-0 max-w-[150px] truncate`,children:M}),(0,$.jsx)(Xo,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`})]}),(0,$.jsx)(N_,{children:c&&(0,$.jsxs)(Ny.div,{initial:{opacity:0,y:-6,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-6,scale:.98},transition:{duration:.16,ease:`easeOut`},className:`absolute left-0 top-full z-10 mt-1 w-72 overflow-hidden rounded-xl border border-border/60 bg-card/95 shadow-2xl backdrop-blur-xl`,children:[b&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/50 px-3 py-2`,children:[(0,$.jsx)(In,{className:`h-3.5 w-3.5 text-foreground/40`}),(0,$.jsx)(`input`,{autoFocus:!0,value:u,onChange:e=>{d(e.target.value),p(0)},placeholder:e(`mission.searchPlaceholder`),className:`w-full bg-transparent text-sm text-foreground outline-none placeholder:text-foreground/40`})]}),(0,$.jsxs)(`div`,{id:`agent-mission-listbox`,role:`listbox`,"aria-label":e(`mission.label`),"aria-activedescendant":`agent-mission-opt-${f}`,className:`max-h-72 overflow-y-auto py-1`,children:[(0,$.jsxs)(Ny.div,{id:`agent-mission-opt-0`,role:`option`,"aria-selected":!1,tabIndex:-1,"data-testid":`mission-new`,onClick:D,onMouseEnter:()=>p(0),initial:{opacity:0,x:-6},animate:{opacity:1,x:0},transition:{duration:.14},className:`flex w-full cursor-pointer items-center gap-2.5 px-3 py-1.5 text-left text-sm font-medium text-foreground ${f===0?`bg-surface/70`:`hover:bg-surface/70`}`,children:[(0,$.jsx)(Pn,{className:`h-4 w-4 text-accent-primary`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e(`mission.new`)})]}),x.length>0&&(0,$.jsx)(`div`,{className:`mx-3 my-1 h-px bg-border/50`,"aria-hidden":!0}),x.length===0&&u.trim()!==``&&(0,$.jsx)(`div`,{className:`px-3 py-2 text-xs text-foreground/40`,children:e(`mission.noMatches`)}),x.map((e,t)=>(0,$.jsx)(qj,{conversation:e,index:t+1,highlighted:f===t+1,activeId:n?.id??null,streaming:o.has(e.id),queuedCount:s.get(e.id)?.queued.length??0,confirming:m===e.id,onHover:()=>p(t+1),onSelect:()=>E(e.id),onArmDelete:()=>O(e.id),onConfirmDelete:()=>void k(e.id),onCancelDelete:C},e.id))]})]})})]})}function qj({conversation:e,index:t,highlighted:n,activeId:r,streaming:i,queuedCount:a,confirming:o,onHover:s,onSelect:c,onArmDelete:l,onConfirmDelete:u,onCancelDelete:d}){let{t:f}=K(`agent`),p=e.title?.trim()||f(`mission.untitled`),m=e.id===r;return o?(0,$.jsxs)(`div`,{id:`agent-mission-opt-${t}`,role:`option`,"aria-selected":m,"data-testid":`mission-row-${e.id}`,className:`flex w-full items-center gap-2 bg-destructive/10 px-3 py-1.5 text-sm`,children:[(0,$.jsx)(Rn,{className:`h-3.5 w-3.5 shrink-0 text-destructive`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-destructive`,children:f(i?`mission.deleteLiveConfirm`:`mission.deleteConfirm`)}),(0,$.jsx)(`button`,{type:`button`,"data-testid":`mission-confirm-yes`,onClick:e=>{e.stopPropagation(),u()},"aria-label":f(`mission.confirmDelete`),className:`rounded-md p-1 text-destructive hover:bg-destructive/20`,children:(0,$.jsx)(Sn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,"data-testid":`mission-confirm-no`,onClick:e=>{e.stopPropagation(),d()},"aria-label":f(`mission.cancelDelete`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface`,children:(0,$.jsx)(Vn,{className:`h-3.5 w-3.5`})})]}):(0,$.jsxs)(Ny.div,{id:`agent-mission-opt-${t}`,role:`option`,"aria-selected":m,tabIndex:-1,"data-testid":`mission-row-${e.id}`,onClick:c,onMouseEnter:s,initial:{opacity:0,x:-6},animate:{opacity:1,x:0},transition:{duration:.14,delay:Math.min(t*.03,.18)},className:`group flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-left text-sm text-foreground ${n?`bg-surface/70`:`hover:bg-surface/70`}`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:p}),(0,$.jsx)(`span`,{className:`shrink-0 tabular-nums text-xs text-foreground/40`,title:Yb(e.updated_at),children:Jb(e.updated_at)}),i&&(0,$.jsxs)(`span`,{"data-testid":`mission-live-${e.id}`,"aria-label":f(`mission.working`),className:`relative flex h-1.5 w-1.5 shrink-0`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full bg-accent-primary opacity-60`}),(0,$.jsx)(`span`,{className:`relative inline-flex h-1.5 w-1.5 rounded-full bg-accent-primary`})]}),a>0&&(0,$.jsx)(`span`,{"data-testid":`mission-queued-${e.id}`,"aria-label":f(`mission.queuedBadge`,{n:a}),title:f(`mission.queuedBadge`,{n:a}),className:`shrink-0 rounded-full border border-border/60 bg-surface px-1.5 text-[9px] font-semibold leading-4 text-foreground/60`,children:a}),m&&(0,$.jsx)(Sn,{className:`h-3.5 w-3.5 shrink-0 text-accent-primary`}),(0,$.jsx)(`button`,{type:`button`,"data-testid":`mission-delete-${e.id}`,onClick:e=>{e.stopPropagation(),l()},"aria-label":f(`mission.delete`,{title:p}),className:`shrink-0 rounded-md p-0.5 text-foreground/50 opacity-0 transition-opacity hover:bg-surface hover:text-destructive focus-visible:opacity-100 group-focus-within:opacity-100 group-hover:opacity-100`,children:(0,$.jsx)(Rn,{className:`h-3.5 w-3.5`})})]})}var Jj=Q.forwardRef(({className:e,type:t,...n},r)=>(0,$.jsx)(`input`,{type:t,className:X(`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-xs ring-offset-background file:border-0 file:bg-transparent file:text-xs file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,e),ref:r,...n}));Jj.displayName=`Input`;var Yj=6e4,Xj={data:null,fetchedAt:0,inFlight:null,error:null},Zj=new Set;function Qj(){Zj.forEach(e=>{try{e()}catch{}})}function $j(){return Xj.data!==null&&Date.now()-Xj.fetchedAt<Yj}async function eM(e){if(Xj.inFlight)return Xj.inFlight;let t=(async()=>{let t=await fetch(`${Xe}/api/setup-prerequisites`,{signal:e});if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();if(typeof n?.ok!=`boolean`||!Array.isArray(n?.prerequisites)||!Array.isArray(n?.missingRequired))throw Error(`Malformed prerequisites response`);return Xj.data=n,Xj.fetchedAt=Date.now(),Xj.error=null,Xj.inFlight=null,Qj(),Xj.data})().catch(t=>{throw Xj.inFlight=null,e?.aborted?t:(Xj.error=t instanceof Error?t:Error(String(t)),Qj(),Xj.error)});return Xj.inFlight=t,t}var tM=!1;function nM(){tM||typeof window>`u`||(window.addEventListener(`focus`,()=>{Xj.fetchedAt=0,Xj.data=null,eM().catch(()=>{})}),tM=!0)}function rM(){let[,e]=(0,Q.useState)(0),[t,n]=(0,Q.useState)(()=>!$j()),[r,i]=(0,Q.useState)(Xj.error);(0,Q.useEffect)(()=>{nM();let t=()=>{e(e=>e+1),i(Xj.error),n(!1)};Zj.add(t);let r=new AbortController;return!$j()&&!Xj.inFlight?(n(!0),eM(r.signal).catch(e=>{r.signal.aborted||i(e instanceof Error?e:Error(String(e)))}).finally(()=>{r.signal.aborted||n(!1)})):Xj.inFlight&&Xj.inFlight.catch(()=>{}).finally(()=>{r.signal.aborted||n(!1)}),()=>{r.abort(),Zj.delete(t)}},[]);let a=(0,Q.useCallback)(async()=>{Xj.fetchedAt=0,Xj.data=null,Xj.error=null,n(!0);try{await eM()}catch(e){i(e instanceof Error?e:Error(String(e)))}finally{n(!1)}},[]);return{status:Xj.data,isLoading:t,error:r,recheck:a}}var iM={claude:{icon:`🤖`,label:`Claude`},codex:{icon:`⚡`,label:`Codex`},gemini:{icon:`✨`,label:`Gemini`},kimi:{icon:`🌙`,label:`Kimi`}};function aM(e){return e.toLowerCase().normalize(`NFKD`).replace(/[̀-ͯ]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`project`}function oM({blueprint:e,onSubmit:t,onBack:n,submitting:r,error:i,errorDetail:a}){let{t:o}=K(`builder`),{status:s}=rM(),[c,l]=(0,Q.useState)(e.product.name||``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(new Set([`claude`])),[g,_]=(0,Q.useState)({claude:!0}),[v,y]=(0,Q.useState)(!1),b=(0,Q.useMemo)(()=>`~/projects/${aM(c)}`,[c]),x=u?f:b;(0,Q.useEffect)(()=>{fetch(`/api/available-providers`).then(e=>e.json()).then(e=>{let t={};for(let[n,r]of Object.entries(e))n===`tiers`||n===`providerIssues`||n===`launchDescriptors`||typeof r==`boolean`&&(t[n]=r);_(t);let n=new Set;for(let[e,r]of Object.entries(t))r&&n.add(e);n.size>0&&h(n)}).catch(()=>{})},[]);let S=s?.prerequisites.find(e=>e.key===`gh`),C=!!(S?.installed&&S?.executable!==!1),w=C&&!!S?.authenticated,T=[`claude`,`codex`,`gemini`,`kimi`,...Object.keys(g)].filter((e,t,n)=>n.indexOf(e)===t).filter(e=>m.has(e)&&g[e]),E=c.trim()!==``&&x.trim()!==``&&T.length>0&&!r;return(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-md flex-col gap-4 p-6`,"data-testid":`commit-form`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold`,children:o(`commit.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`commit.description`)})]}),i&&(0,$.jsxs)(`div`,{className:`rounded-md bg-destructive/10 p-2 text-xs text-destructive`,"data-testid":`commit-error`,children:[(0,$.jsx)(`p`,{children:o(`commit.errors.${i}`,{defaultValue:o(`commit.errors.generic`)})}),a&&(0,$.jsx)(`p`,{className:`mt-1 opacity-80`,children:a})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium`,children:[o(`commit.nameLabel`),` `,(0,$.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,$.jsx)(Jj,{value:c,onChange:e=>l(e.target.value),"data-testid":`commit-name`})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium`,children:[o(`commit.locationLabel`),` `,(0,$.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,$.jsx)(Jj,{value:x,onChange:e=>{d(!0),p(e.target.value)},"data-testid":`commit-location`}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:o(`commit.locationHint`)})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:o(`commit.providersLabel`)}),(0,$.jsx)(`div`,{className:`flex gap-2`,children:Object.keys(g).map(e=>{let{icon:t,label:n}=iM[e]??{icon:`•`,label:e},r=g[e],i=m.has(e)&&r;return(0,$.jsxs)(`button`,{type:`button`,role:`checkbox`,"aria-checked":i,disabled:!r,"data-testid":`commit-provider-${e}`,onClick:()=>{h(t=>{let n=new Set(t);if(n.has(e)){if(n.size===1)return t;n.delete(e)}else n.add(e);return n})},className:X(`flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs transition-colors`,i?`border-accent-primary/60 bg-accent-primary/10`:`border-border/30 text-muted-foreground`,!r&&`cursor-not-allowed opacity-40`),children:[(0,$.jsx)(`span`,{children:t}),(0,$.jsx)(`span`,{className:`font-medium`,children:n})]},e)})})]}),C&&(0,$.jsxs)(`label`,{className:X(`flex items-center gap-2 rounded-md border border-border/30 px-3 py-2 text-xs`,!w&&`opacity-50`),children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:v&&w,disabled:!w,onChange:e=>y(e.target.checked),"data-testid":`commit-github`}),(0,$.jsx)(As,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{children:o(`commit.githubLabel`)}),!w&&(0,$.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:o(`commit.githubAuthHint`)})]}),(0,$.jsxs)(`div`,{className:`flex justify-between pt-2`,children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:n,disabled:r,children:o(`commit.back`)}),(0,$.jsxs)(Z,{size:`sm`,disabled:!E,"data-testid":`commit-submit`,onClick:()=>t({name:c.trim(),location:x.trim(),providers:T,createGithubRepo:v&&w}),children:[(0,$.jsx)(gc,{className:`mr-1.5 h-3.5 w-3.5`}),o(r?`commit.creating`:`commit.submit`)]})]})]})}function sM({session:e,autoFocus:t=!1}){let{t:n}=K(`builder`),{t:r}=K(`agent`),{availableIds:i,labels:a}=OA(),o=kt(e.provider),s=[e.provider,...i].filter((e,t,n)=>n.indexOf(e)===t).filter(kt),c=e=>r(`provider.${e}`,{defaultValue:a?.[e]??e}),l=()=>{!o||!e.draft.trim()||e.busy||!e.conversationReady||(e.send(e.draft),e.setDraft(``))};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 px-1`,children:[(0,$.jsx)(Ns,{className:`h-4 w-4 text-accent-primary`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground/80`,children:n(`mode.title`)})]}),(0,$.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(KE,{label:r(`provider.label`),value:e.provider,options:s.map(e=>({value:e,label:c(e)})),icon:Vo,onSelect:e.setProvider,disabled:!o||e.busy||!e.conversationReady,testId:`builder-provider-selector`}),(0,$.jsx)(ik,{models:e.models,model:e.model,onSelect:e.setModel,disabled:!o||e.busy||!e.conversationReady,testId:`builder-model-selector`}),e.efforts.length>0&&(0,$.jsx)(KE,{label:r(`effort.label`),value:e.effort,options:e.efforts.map(e=>({value:e,label:r(`effort.${e}`)})),icon:Ds,onSelect:e.setEffort,disabled:!o||e.busy||!e.conversationReady,testId:`builder-effort-selector`}),e.showSurpriseMe&&(0,$.jsxs)(`button`,{type:`button`,onClick:e.surpriseMe,disabled:!o||e.busy||!e.conversationReady,className:`ml-auto inline-flex items-center gap-1.5 rounded-full border border-accent-highlight/40 bg-accent-highlight/10 px-3 py-1 text-[11px] text-accent-highlight transition-colors hover:bg-accent-highlight/20 disabled:opacity-40`,"data-testid":`surprise-me`,children:[(0,$.jsx)(Ln,{className:`h-3 w-3`}),n(`shell.surpriseMe`)]})]}),!o&&(0,$.jsx)(`p`,{className:`mb-2 rounded-md border border-accent-warning/30 bg-accent-warning/10 px-2.5 py-2 text-xs text-accent-warning`,"data-testid":`builder-provider-unavailable`,children:n(`shell.providerUnavailable`)}),(0,$.jsxs)(`div`,{className:`relative flex items-end gap-2 rounded-xl border border-border/60 bg-background/60 px-3 py-2`,children:[(0,$.jsx)(`textarea`,{value:e.draft,disabled:!o,autoFocus:t,onChange:t=>e.setDraft(t.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),l())},rows:2,placeholder:n(`shell.inputPlaceholder`),"aria-label":n(`shell.inputPlaceholder`),"data-agent-interactive":!0,className:`min-h-[3.25rem] max-h-64 min-w-[12rem] flex-1 resize-y bg-transparent text-sm text-foreground outline-none placeholder:text-foreground/40`,"data-testid":`builder-input`}),(0,$.jsx)(`button`,{type:`button`,onClick:l,disabled:!o||e.busy||!e.draft.trim()||!e.conversationReady,"aria-label":r(`send`),className:`rounded-lg bg-accent-primary p-1.5 text-white transition-opacity disabled:opacity-40`,"data-testid":`builder-send`,children:(0,$.jsx)(Pt,{className:`h-4 w-4`})})]})]})}function cM(e){let t=Date.parse(e.includes(`T`)?e:e.replace(` `,`T`)+`Z`);return Number.isFinite(t)?Cr(new Date(t),{addSuffix:!0,locale:Ze()}):``}function lM({items:e,loading:t,disabled:n=!1,onResume:r,onDiscard:i}){let{t:a}=K(`builder`),[o,s]=(0,Q.useState)(null);return!t&&e.length===0?null:(0,$.jsxs)(Ny.section,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.24,ease:`easeOut`,delay:.08},className:`mt-4 w-full rounded-2xl border border-border/50 bg-card/70 p-3 shadow-lg backdrop-blur-xl`,"data-testid":`builder-recent`,"aria-label":a(`recent.title`),children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 px-1`,children:[(0,$.jsx)(Fs,{className:`h-3.5 w-3.5 text-accent-secondary`,"aria-hidden":!0}),(0,$.jsx)(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wider text-muted-foreground`,children:a(`recent.title`)}),t&&(0,$.jsx)(An,{className:`ml-auto h-3 w-3 animate-spin text-muted-foreground/60`,"aria-hidden":!0})]}),(0,$.jsx)(`ul`,{className:`space-y-1`,children:(0,$.jsx)(N_,{initial:!1,children:e.map(e=>{let t=e.productName||e.title||a(`recent.untitled`),c=o===e.id;return(0,$.jsxs)(Ny.li,{layout:!0,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,height:0},className:X(`group flex items-center gap-2 rounded-xl border border-transparent px-2.5 py-2 transition-colors`,`hover:border-border/60 hover:bg-surface/60`),"data-testid":`builder-recent-${e.id}`,children:[(0,$.jsxs)(`button`,{type:`button`,disabled:n,onClick:()=>r(e.id),className:`flex min-w-0 flex-1 items-center gap-2.5 text-left disabled:opacity-50`,"data-testid":`builder-recent-resume-${e.id}`,children:[(0,$.jsx)(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-accent-primary/10 text-accent-primary`,children:(0,$.jsx)(Mn,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-sm font-medium text-foreground`,children:t}),(0,$.jsxs)(`span`,{className:`mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[10px] text-muted-foreground`,children:[e.platform&&(0,$.jsx)(`span`,{children:e.platform}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,$.jsx)(kn,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),e.specCount>0?e.specsComplete?a(`recent.specsComplete`,{count:e.specCount}):a(`recent.specsInProgress`,{count:e.specCount}):a(`recent.dimensions`,{filled:e.dimensionsFilled,total:5})]}),e.pendingIssue&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-accent-warning`,"data-testid":`builder-recent-pending-issue`,children:[(0,$.jsx)(zn,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),a(`recent.pendingIssue`)]}),e.updatedAt&&(0,$.jsx)(`span`,{className:`opacity-80`,children:cM(e.updatedAt)})]})]})]}),(0,$.jsx)(`div`,{className:`flex shrink-0 items-center gap-0.5`,children:c?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>{s(null),i(e.id)},"aria-label":a(`recent.discardConfirm`),title:a(`recent.discardConfirm`),className:`rounded-md p-1 text-destructive hover:bg-destructive/10`,"data-testid":`builder-recent-discard-confirm-${e.id}`,children:(0,$.jsx)(Sn,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>s(null),"aria-label":a(`recent.discardCancel`),title:a(`recent.discardCancel`),className:`rounded-md p-1 text-muted-foreground hover:bg-surface`,"data-testid":`builder-recent-discard-cancel-${e.id}`,children:(0,$.jsx)(Vn,{className:`h-3.5 w-3.5`,"aria-hidden":!0})})]}):(0,$.jsx)(`button`,{type:`button`,onClick:()=>s(e.id),"aria-label":a(`recent.discard`),title:a(`recent.discard`),className:`rounded-md p-1 text-muted-foreground/40 opacity-0 transition-opacity hover:bg-surface hover:text-destructive focus-visible:opacity-100 group-hover:opacity-100`,"data-testid":`builder-recent-discard-${e.id}`,children:(0,$.jsx)(Rn,{className:`h-3.5 w-3.5`,"aria-hidden":!0})})})]},e.id)})})})]})}function uM({specsStarted:e,snapshot:t,maxSpecs:n=10}){let{t:r}=K(`builder`),i=t.status===`repairing`,a=t.status===`generating`?t.generation:null,o=(a&&a.total>0?a.phase===`audit`?.95:Math.min(.95,Math.max(.06,Math.max(0,a.from-1)/a.total)):null)??Math.min(.95,Math.max(.06,e/n)),s=i?Bn:Ln,c=i?r(`snapshot.repairing.${t.kind}`):a?r(`generation.phase.${a.phase}`,{from:a.from,to:a.to,total:a.total}):r(`generation.writing`);return(0,$.jsxs)(`div`,{className:`inline-flex max-w-full flex-col gap-1.5 rounded-xl border border-border/50 bg-surface/60 px-3 py-2 text-xs text-foreground/80`,"data-testid":`builder-generation-progress`,"data-phase":i?`repairing`:a?`generation-${a.phase}`:`generating`,role:`status`,"aria-live":`polite`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(An,{className:`h-3 w-3 shrink-0 animate-spin text-accent-info`,"aria-hidden":!0}),(0,$.jsx)(s,{className:`h-3 w-3 shrink-0 text-accent-primary`,"aria-hidden":!0}),(0,$.jsx)(N_,{mode:`wait`,initial:!1,children:(0,$.jsx)(Ny.span,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.16,ease:`easeOut`},className:`font-medium`,children:c},c)}),a&&a.totalTurns>0&&(0,$.jsx)(`span`,{className:`rounded-full bg-muted/60 px-2 py-px font-mono text-[10px] text-muted-foreground`,"data-testid":`builder-generation-turn`,children:r(`generation.turn`,{turn:a.turn,total:a.totalTurns})}),e>0&&(0,$.jsx)(N_,{mode:`wait`,initial:!1,children:(0,$.jsx)(Ny.span,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},transition:{duration:.14},className:`rounded-full bg-accent-primary/10 px-2 py-px font-mono text-[10px] text-accent-primary`,"data-testid":`builder-generation-count`,children:r(`generation.specCount`,{n:e})},e)})]}),(0,$.jsx)(`div`,{className:`h-1 w-56 max-w-full overflow-hidden rounded-full bg-border/40`,"aria-hidden":!0,children:(0,$.jsx)(Ny.div,{className:`h-full rounded-full bg-gradient-to-r from-accent-primary/70 to-accent-highlight/80`,initial:{width:`6%`},animate:{width:`${Math.round(o*100)}%`},transition:{type:`spring`,stiffness:120,damping:20}})})]})}var dM=`specrails-desktop:milestone-launch-mode`,fM=`specrails-desktop:milestone-sequential-plans`;function pM(){try{return localStorage.getItem(`specrails-desktop:milestone-launch-mode`)===`parallel`?`parallel`:`sequential`}catch{return`sequential`}}function mM(e){try{localStorage.setItem(dM,e)}catch{}}var hM=`specrails-desktop:milestone-auto-advance`;function gM(){try{return localStorage.getItem(hM)===`true`}catch{return!1}}function _M(e){try{localStorage.setItem(hM,e?`true`:`false`)}catch{}}function vM(){try{return localStorage.getItem(`specrails-desktop:milestone-sequential-plans`)===null?!1:(localStorage.removeItem(fM),!0)}catch{return!1}}function yM(e){return`M${e}`}function bM(e,t){return t===`chain_active`?`chain_active`:t===`no_tickets`?`no_tickets`:t===`milestone_not_found`?`milestone_not_found`:e===503?`unavailable`:`launch_rejected`}async function xM(e){try{let t=await e.json();return t&&typeof t==`object`?t:{}}catch{return{}}}async function SM(e,t,n=pM(),r={}){let i=typeof r==`function`?{fetchImpl:r}:r,a=i.fetchImpl??fetch,o=i.autoAdvance??gM(),s;try{s=await a(`/api/projects/${e}/blueprint/milestones/${t}/launch`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({mode:n,autoAdvance:o})})}catch(e){return{ok:!1,reason:`network`,error:`network`,detail:e instanceof Error?e.message:String(e)}}let c=await xM(s);if(!s.ok){let e=typeof c.error==`string`?c.error:`http_${s.status}`;return{ok:!1,reason:bM(s.status,e),error:e,...typeof c.detail==`string`?{detail:c.detail}:{},...typeof c.chainId==`string`?{chainId:c.chainId}:{}}}let l=Array.isArray(c.launched)?c.launched.filter(e=>!!e&&typeof e==`object`&&typeof e.chunk==`number`):[],u=Array.isArray(c.pending)?c.pending.filter(e=>Array.isArray(e)):[];return{ok:!0,chainId:typeof c.chainId==`string`?c.chainId:null,launched:l,pending:u,ticketCount:l.reduce((e,t)=>e+(Array.isArray(t.ticketIds)?t.ticketIds.length:0),0),skippedCount:u.reduce((e,t)=>e+t.length,0)}}async function CM(e,t,n,r){let i;try{i=await r(`/api/projects/${e}/blueprint/chains/${t}/${n}`,{method:`POST`})}catch(e){return{ok:!1,error:`network`,detail:e instanceof Error?e.message:String(e)}}let a=await xM(i);return i.ok?{ok:!0,chain:Ut(a.chain)}:{ok:!1,error:typeof a.error==`string`?a.error:`http_${i.status}`,...typeof a.detail==`string`?{detail:a.detail}:{}}}function wM(e,t,n=fetch){return CM(e,t,`resume`,n)}function TM(e,t,n=fetch){return CM(e,t,`cancel`,n)}async function EM(e,t,n,r=fetch){let i;try{i=await r(`/api/projects/${e}/blueprint/chains/${t}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({autoAdvance:n})})}catch(e){return{ok:!1,error:`network`,detail:e instanceof Error?e.message:String(e)}}let a=await xM(i);return i.ok?{ok:!0,chain:Ut(a.chain)}:{ok:!1,error:typeof a.error==`string`?a.error:`http_${i.status}`,...typeof a.detail==`string`?{detail:a.detail}:{}}}var DM=[`Problem Statement`,`Proposed Solution`,`Out of Scope`,`Technical Considerations`,`Estimated Complexity`],OM={problemMinChars:200,solutionMinChars:500,outOfScopeMinBullets:3,technicalMinBullets:5,criteriaMin:6,criteriaMax:10,criterionMinChars:20},kM=new Set([`scaffold`,`feature`,`verification`]),AM=new Set([`critical`,`high`,`medium`,`low`]),jM=/^(?:todo|tbd|n\/?a|works?|test(?: it)?|criterion|acceptance criterion)$/i;function MM(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:null}function NM(e){return e.trim().toLocaleLowerCase(`en-US`)}function PM(e){let t=[...e.matchAll(/^##[ \t]+(.+?)[ \t]*$/gm)],n=t.map(e=>e[1].trim()),r=new Map;return t.forEach((i,a)=>{let o=(i.index??0)+i[0].length,s=a+1<t.length?t[a+1].index??e.length:e.length;r.set(n[a],e.slice(o,s).trim())}),{headings:n,bodies:r}}function FM(e){return e.split(/\r?\n/).filter(e=>/^\s*[-*+]\s+\S/.test(e)).length}function IM(e,t){let n=[],r=MM(e),i=Array.isArray(r?.m1Specs)?r.m1Specs:[],a=t.milestoneLabel.trim().toUpperCase(),o=(e,t,r,i,a={})=>{n.push({specIndex:e,field:t,code:r,message:i,params:e===null?a:{n:e+1,...a}})};r?.specsComplete!==!0&&o(null,`specsComplete`,`batch_incomplete`,`Generation is not complete yet.`),(i.length<t.minSpecs||i.length>t.maxSpecs)&&o(null,`m1Specs`,`spec_count`,`The batch needs ${t.minSpecs}-${t.maxSpecs} specs.`,{min:t.minSpecs,max:t.maxSpecs,count:i.length});let s=new Map;return i.forEach((e,n)=>{let r=MM(e),i=n+1;if(!r){o(n,`spec`,`invalid_shape`,`Spec ${i} must be an object.`);return}let c=typeof r.kind==`string`?r.kind:``;kM.has(c)||o(n,`kind`,`invalid_kind`,`Spec ${i} needs a valid kind.`),t.requireScaffold&&n===0&&c!==`scaffold`&&o(n,`kind`,`scaffold_first`,`The first spec must be the project scaffold.`),t.requireScaffold&&n>0&&c===`scaffold`&&o(n,`kind`,`duplicate_scaffold`,`Spec ${i} cannot be another scaffold.`);let l=typeof r.title==`string`?r.title.trim():``;if(!l)o(n,`title`,`required`,`Spec ${i} needs a title.`);else{let e=NM(l),t=s.get(e);t===void 0?s.set(e,n):o(n,`title`,`duplicate`,`Spec ${i} duplicates spec ${t+1}.`,{other:t+1})}let u=typeof r.shortSummary==`string`?r.shortSummary.trim():``;(!u||u.length>240||/[\r\n]/.test(u))&&o(n,`shortSummary`,`summary`,`Spec ${i} needs a one-line summary under 240 characters.`);let d=typeof r.priority==`string`?r.priority:``;AM.has(d)||o(n,`priority`,`invalid_priority`,`Spec ${i} needs a valid priority.`);let f=typeof r.description==`string`?r.description.trim():``,p=PM(f);(!/^## Problem Statement(?:\r?\n|$)/.test(f)||p.headings.length!==DM.length||p.headings.some((e,t)=>e!==DM[t]))&&o(n,`description`,`canonical_sections`,`Spec ${i} is missing the canonical sections.`);for(let e of DM)(p.bodies.get(e)??``).trim()||o(n,`description`,`empty_section`,`Spec ${i} has an empty ${e} section.`,{heading:e});for(let[e,t]of[[`Problem Statement`,OM.problemMinChars],[`Proposed Solution`,OM.solutionMinChars]]){let r=(p.bodies.get(e)??``).trim();r&&r.length<t&&o(n,`description`,`section_depth`,`Spec ${i} ${e} is too thin.`,{heading:e,min:t})}for(let[e,t]of[[`Out of Scope`,OM.outOfScopeMinBullets],[`Technical Considerations`,OM.technicalMinBullets]]){let r=p.bodies.get(e)??``;r&&FM(r)<t&&o(n,`description`,`section_bullets`,`Spec ${i} needs ${t} ${e} bullets.`,{heading:e,min:t})}let m=p.bodies.get(`Estimated Complexity`)??``;m&&!/^(?:Low|Medium|High|Very High)\s*(?:[—\-:]\s*)\S/i.test(m)&&o(n,`description`,`complexity_format`,`Spec ${i} needs a justified complexity.`),t.requireScaffold&&n===0&&f&&!/\bREADME\b/i.test(f)&&o(n,`description`,`scaffold_readme`,`The scaffold spec must mention the existing README.`);let h=Array.isArray(r.acceptanceCriteria)?r.acceptanceCriteria:[];(h.length<OM.criteriaMin||h.length>OM.criteriaMax)&&o(n,`acceptanceCriteria`,`criteria_count`,`Spec ${i} needs ${OM.criteriaMin}-${OM.criteriaMax} acceptance criteria.`,{count:h.length,min:OM.criteriaMin,max:OM.criteriaMax});let g=new Set;h.forEach((e,t)=>{let r=typeof e==`string`?e.trim():``;if(r.length<OM.criterionMinChars||jM.test(r)){o(n,`acceptanceCriteria`,`criterion_quality`,`Spec ${i} criterion ${t+1} is not concrete.`,{criterion:t+1});return}let a=NM(r);g.has(a)&&o(n,`acceptanceCriteria`,`duplicate_criterion`,`Spec ${i} repeats an acceptance criterion.`,{criterion:t+1}),g.add(a)});let _=Array.isArray(r.labels)?r.labels.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean):[];new Set(_.map(e=>e.toUpperCase())).has(a)||o(n,`labels`,`milestone_label`,`Spec ${i} needs the ${a} label.`,{label:a}),_.every(e=>e.toUpperCase()===a)&&o(n,`labels`,`domain_label`,`Spec ${i} needs a domain label.`,{label:a});let v=r.dependsOnIndex;v!==void 0&&(!Number.isInteger(v)||v<0||v>=n)&&o(n,`dependsOnIndex`,`invalid_dependency`,`Spec ${i} must depend only on an earlier spec.`),t.requireScaffold&&n===0&&v!==void 0&&o(n,`dependsOnIndex`,`scaffold_dependency`,`The scaffold cannot declare a dependency.`)}),{valid:n.length===0,issues:n}}var LM=new Set([`batch_incomplete`,`spec_count`]);function RM(e,t,n,r,i={}){let a=Bt(e),o=Object.values(a).filter(Boolean).length,s=Object.keys(a).length,c=t&&typeof t==`object`&&!Array.isArray(t)?t:null,l=Array.isArray(c?.m1Specs)?c.m1Specs.length:e?.m1Specs.length??0,u=Array.isArray(c?.m1Specs)?c.m1Specs:e?.m1Specs??[],d=new Set;u.forEach((e,t)=>{let n=e&&typeof e==`object`?e:null,r=typeof n?.description==`string`?n.description.trim():``,i=Array.isArray(n?.acceptanceCriteria)?n.acceptanceCriteria:[];(r.length>0||i.length>0)&&d.add(t)});let f=d.size,p=c?c.specsComplete===!0:e?.specsComplete===!0,m=i.generating===!0&&l>0,h=!m&&l>0&&f<l&&!p,g=m?[]:n.issues.filter(e=>!LM.has(e.code)&&(!h||e.specIndex===null||d.has(e.specIndex))),_={key:`blueprint`,state:o===s?`done`:`pending`,params:{filled:o,total:s}},v;v=m?`writing`:l===0?`pending`:l<r.minSpecs||l>r.maxSpecs?`blocked`:p?`done`:`pending`;let y={key:`specs`,state:v,params:{count:l,written:f,min:r.minSpecs,max:r.maxSpecs}},b={key:`audit`,state:m?`writing`:l===0||h&&g.length===0?`pending`:g.length===0?`done`:`blocked`,params:{count:g.length}};return{ready:n.valid,steps:[_,y,b],issues:g}}function zM(e){return e.field===`shortSummary`?`quality.summary`:e.field===`title`&&e.code===`required`?`quality.title_required`:e.field===`title`&&e.code===`duplicate`?`quality.title_duplicate`:`quality.${e.code}`}function BM(e,t){let n={n:t.specIndex===null?``:t.specIndex+1,...t.params??{}};return e(zM(t),{...n,defaultValue:t.message})}var VM=new Set([`gh_not_installed`,`gh_not_authenticated`,`gh_scope`,`gh_repo_exists`,`gh_network`]);function HM(e){return`progress.githubErrors.${e&&VM.has(e)?e:`generic`}`}var UM=[`create-dir`,`git-init`,`assemble`,`blueprint`,`tickets`,`register`,`github`],WM={minSpecs:5,maxSpecs:10};function GM(e){let t=e&&typeof e==`object`?e:null;if(!t)return null;let n=t.phase;if(n!==`outline`&&n!==`details`&&n!==`audit`&&n!==`repair`)return null;let r=e=>typeof e==`number`&&Number.isFinite(e)?e:0;return{phase:n,from:r(t.from),to:r(t.to),total:r(t.total),turn:r(t.turn),totalTurns:r(t.totalTurns)}}function KM(e,t){let n=e&&typeof e==`object`?e:{},r=new Date().toISOString();if(n.continuing){let e=GM(n.generation);return e?{status:`generating`,generation:e}:t}return n.status===`accepted`?{status:`accepted`,repaired:n.repaired===!0,repairAttempted:n.repairAttempted===!0,at:r,...n.generationHalted===!0?{generationHalted:!0}:{}}:n.status===`rejected`?{status:`rejected`,reason:n.reason??`invalid_json`,detail:n.detail??``,repairAttempted:n.repairAttempted===!0,at:r}:t.status===`repairing`||t.status===`generating`?{status:`idle`}:t}function qM(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`&&typeof e.id==`string`).map(e=>({id:String(e.id),title:typeof e.title==`string`?e.title:null,productName:typeof e.productName==`string`?e.productName:null,platform:typeof e.platform==`string`?e.platform:null,provider:typeof e.provider==`string`?e.provider:`claude`,model:typeof e.model==`string`?e.model:null,updatedAt:typeof e.updated_at==`string`?e.updated_at:``,messageCount:typeof e.messageCount==`number`?e.messageCount:0,specCount:typeof e.specCount==`number`?e.specCount:0,specsComplete:e.specsComplete===!0,dimensionsFilled:typeof e.dimensionsFilled==`number`?e.dimensionsFilled:0,hasSnapshot:e.hasSnapshot===!0,pendingIssue:e.pendingIssue===`invalid_json`||e.pendingIssue===`truncated`||e.pendingIssue===`missing_version`?e.pendingIssue:null})):[]}function JM(e,t){let{t:n}=K(`builder`),{registerHandler:r,unregisterHandler:i}=tt(),{setActiveProjectId:a}=pt(),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)([]),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(`chat`),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)([]),[O,k]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(!1),[P,F]=(0,Q.useState)(!1),[I,L]=(0,Q.useState)(`claude`),[R,z]=(0,Q.useState)(null),[B,V]=(0,Q.useState)([]),[H,U]=(0,Q.useState)(``),[W,ee]=(0,Q.useState)([]),[te,ne]=(0,Q.useState)(`medium`),[re,ie]=(0,Q.useState)(``),[ae,oe]=(0,Q.useState)({status:`idle`}),[se,ce]=(0,Q.useState)([]),[le,ue]=(0,Q.useState)(!1),[de,fe]=(0,Q.useState)(!1),G=R??H,pe=(0,Q.useMemo)(()=>{let e=vt(I,G);return W.filter(t=>e.includes(t))},[G,I,W]),me=(0,Q.useRef)(null),he=(0,Q.useRef)(null),ge=(0,Q.useRef)(I),_e=(0,Q.useRef)(null),ve=(0,Q.useRef)(!1),ye=(0,Q.useRef)(te),be=(0,Q.useRef)(pe),xe=(0,Q.useRef)(R),Se=(0,Q.useRef)(!1),Ce=(0,Q.useRef)(t.onFinished);(0,Q.useEffect)(()=>{me.current=o},[o]),(0,Q.useEffect)(()=>{ge.current=I},[I]),(0,Q.useEffect)(()=>{_e.current=w},[w]),(0,Q.useEffect)(()=>{ye.current=te},[te]),(0,Q.useEffect)(()=>{be.current=pe},[pe]),(0,Q.useEffect)(()=>{xe.current=R},[R]),(0,Q.useEffect)(()=>{Ce.current=t.onFinished},[t.onFinished]);let we=(0,Q.useCallback)(async()=>{let e=me.current;if(e)return e;if(he.current)return he.current;let t=fetch(`/api/blueprint/conversations`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:ge.current,...xe.current?{model:xe.current}:{}})}).then(e=>e.json()).then(e=>e.conversation?(me.current=e.conversation.id,s(e.conversation.id),e.conversation.id):null).catch(()=>null).finally(()=>{he.current=null});return he.current=t,t},[]),Te=(0,Q.useCallback)(async()=>{ue(!0);try{let e=await(await fetch(`/api/blueprint/conversations?resumable=1`)).json();ce(qM(e.conversations))}catch{ce([])}finally{ue(!1)}},[]);(0,Q.useEffect)(()=>{e&&Te()},[e,Te]),(0,Q.useEffect)(()=>{if(!e)return;let t=!1;return V([]),U(``),ee([]),ne(``),fetch(`/api/blueprint/models?provider=${encodeURIComponent(I)}`).then(e=>e.json()).then(e=>{if(t)return;V(e.models??[]);let n=e.defaultModel??e.models?.[0]?.value??``,r=e.efforts??[],i=vt(I,n),a=r.filter(e=>i.includes(e));U(n),ee(r),ne(e=>a.includes(e)?e:Dt(I,n)??``)}).catch(()=>{}),()=>{t=!0}},[e,I]);let{availableIds:Ee}=OA({enabled:e});(0,Q.useEffect)(()=>{if(me.current||Ee.length===0||Ee.includes(I))return;let e=Ee.filter(kt);e.length!==0&&(L(Ot(e)),z(null))},[Ee,I]);let De=(0,Q.useCallback)(e=>{L(e),z(null);let t=me.current;t&&fetch(`/api/blueprint/conversations/${t}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:e})}).catch(()=>{})},[]),Oe=(0,Q.useCallback)(e=>{z(e);let t=vt(I,e),n=W.filter(e=>t.includes(e));ne(t=>n.includes(t)?t:Dt(I,e)??``);let r=me.current;r&&fetch(`/api/blueprint/conversations/${r}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({model:e})}).catch(()=>{})},[I,W]);(0,Q.useEffect)(()=>{if(!e)return;let t=`builder-session`;return r(t,e=>{let t=e,r=me.current!==null&&t.conversationId===me.current,i=_e.current!==null&&t.commitId===_e.current;if(t.type===`blueprint.stream`&&r)d(e=>(e??``)+String(t.delta??``));else if(t.type===`blueprint.repairing`&&r){let e=t.kind===`truncated`||t.kind===`quality`?t.kind:`invalid_json`;_(!0),oe({status:`repairing`,kind:e,manual:t.manual===!0,attempt:typeof t.attempt==`number`?t.attempt:1})}else if(t.type===`blueprint.generating`&&r){let e=GM(t);d(null),_(!0),e&&oe({status:`generating`,generation:e})}else if(t.type===`blueprint.done`&&r){let e=t.continuing===!0;d(null),_(e);let n=String(t.fullText??``);n.trim()&&!e&&l(e=>[...e,{role:`assistant`,content:n,createdAt:new Date().toISOString()}]);let r=qt(t.blueprint),i=t.rawBlueprint===void 0?t.blueprint:t.rawBlueprint;if(!r&&t.snapshot===void 0){let e=ln(n);r=e.blueprint,i=e.rawBlueprint}r&&(p(r),h(i)),oe(e=>t.snapshot===void 0?r?{status:`accepted`,repaired:!1,repairAttempted:!1,at:new Date().toISOString()}:e:KM(t.snapshot,e))}else if(t.type===`blueprint.error`&&r)d(null),_(!1),oe(e=>e.status===`repairing`||e.status===`generating`?{status:`idle`}:e),J.error(n(`errors.turnFailed`),{description:String(t.error??``)});else if(t.type===`blueprint.commit_progress`&&i){let e=String(t.step),r=t.status,i=typeof t.detail==`string`?t.detail:void 0,a=typeof t.code==`string`?t.code:void 0;e===`github`&&r===`warning`&&!ve.current&&(ve.current=!0,J.warning(n(HM(a)),{description:i})),D(t=>[...t.filter(t=>t.step!==e),{step:e,status:r,detail:i,code:a}])}else t.type===`blueprint.commit_done`&&i?(k(String(t.projectId)),y(`done`)):t.type===`blueprint.commit_failed`&&i&&(Se.current=!1,F(!1),J.error(n(`errors.commitFailed`),{description:String(t.error??``)}),y(`commit`),x(`commit_failed`),C(String(t.error??``)))}),()=>i(t)},[e,r,i,n]);let ke=(0,Q.useCallback)((e,t={})=>{let r=e.trim();if(!r||g||de)return;l(e=>[...e,{role:`user`,content:r,createdAt:new Date().toISOString(),...t.intent?{intent:t.intent}:{}}]),_(!0);let i=ye.current,a=be.current.includes(i);we().then(e=>{if(!e){_(!1),J.error(n(`errors.startFailed`));return}return fetch(`/api/blueprint/conversations/${e}/send`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:r,...xe.current?{model:xe.current}:{},...a?{reasoning_effort:i}:{},...t.intent?{intent:t.intent}:{}})}).then(e=>{!e.ok&&e.status!==202&&(_(!1),J.error(n(`errors.turnFailed`)))}).catch(()=>{_(!1),J.error(n(`errors.turnFailed`))})})},[g,de,we,n]),Ae=(0,Q.useCallback)(async e=>{if(!g){fe(!0);try{let t=await fetch(`/api/blueprint/conversations/${e}`);if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();if(!n.conversation)throw Error(`missing conversation`);me.current=n.conversation.id,s(n.conversation.id),n.conversation.provider&&L(n.conversation.provider),z(n.conversation.model??null),l((n.messages??[]).filter(e=>typeof e.content==`string`&&e.content.trim()!==``).map(e=>({role:e.role,content:e.content,createdAt:e.created_at??new Date().toISOString(),...e.intent===`surprise`||e.intent===`approve`?{intent:e.intent}:{}})));let r=qt(n.blueprint);p(r),h(r?n.rawBlueprint??n.blueprint:null),oe(KM(n.snapshot,{status:`idle`})),d(null),_(!1),y(`chat`),x(null),C(null),D([]),ie(``)}catch{J.error(n(`recent.resumeFailed`))}finally{fe(!1)}}},[g,n]),je=(0,Q.useCallback)(async e=>{try{let t=await fetch(`/api/blueprint/conversations/${e}`,{method:`DELETE`});if(!t.ok&&t.status!==404)throw Error(`HTTP ${t.status}`);ce(t=>t.filter(t=>t.id!==e))}catch{J.error(n(`recent.discardFailed`))}},[n]),Me=(0,Q.useCallback)(async()=>{let e=me.current;if(!(!e||g)){_(!0);try{let t=await fetch(`/api/blueprint/conversations/${e}/repair-snapshot`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(te?{reasoningEffort:te}:{})});if(t.status===202)return;let r=await t.json().catch(()=>({}));_(!1),r.error===`nothing_to_repair`?J.info(n(`snapshot.nothingToRepair`)):r.error===`no_session`?J.error(n(`snapshot.noSession`)):r.error===`streaming`?J.info(n(`snapshot.alreadyStreaming`)):J.error(n(`errors.turnFailed`))}catch{_(!1),J.error(n(`errors.turnFailed`))}}},[g,te,n]),Ne=(0,Q.useCallback)(()=>ke(n(`prompts.surpriseMe`),{intent:`surprise`}),[ke,n]),Pe=(0,Q.useCallback)(()=>ke(n(`prompts.approve`),{intent:`approve`}),[ke,n]),Fe=(0,Q.useCallback)(e=>{!f||Se.current||(Se.current=!0,F(!0),x(null),C(null),D([]),ve.current=!1,fetch(`/api/blueprint/commit`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({blueprint:m??f,...e,...me.current?{conversationId:me.current}:{}})}).then(async e=>{let t=await e.json().catch(()=>({}));e.status===202&&t.commitId?(T(t.commitId),_e.current=t.commitId,y(`progress`)):(x(t.error??`generic`),C(t.detail??null)),Se.current=!1,F(!1)}).catch(()=>{Se.current=!1,F(!1),x(`generic`),C(null)}))},[f,m]),Ie=(0,Q.useCallback)(async()=>{if(!(!O||A)){j(!0);try{let e=pM(),t=gM(),r=await SM(O,1,e,{autoAdvance:t}),i=yM(1);if(r.ok){let o=r.launched.length+r.pending.length;e===`sequential`&&r.pending.length>0?J.success(n(t?`milestoneProgress.toast.launched`:`milestoneProgress.toast.launchedCheckpoint`,{milestone:i,count:r.ticketCount,n:o})):r.skippedCount>0?J.warning(n(`milestoneProgress.toast.launchedPartial`,{milestone:i,count:r.ticketCount,skipped:r.skippedCount})):J.success(n(`milestoneProgress.toast.launchedAll`,{milestone:i,count:r.ticketCount,n:o})),a(O),N(!0)}else r.reason===`chain_active`?(J.info(n(`milestoneProgress.toast.chainActive`,{milestone:i})),a(O),N(!0)):J.error(n(`done.launchFailed`),{description:r.detail??r.error})}finally{j(!1)}}},[O,A,a,n]),Le=(0,Q.useCallback)(()=>{O&&a(O),Ce.current()},[O,a]),Re=(0,Q.useCallback)(()=>{let e=me.current;e&&fetch(`/api/blueprint/conversations/${e}/abort`,{method:`POST`}).catch(()=>{}),s(null),me.current=null,he.current=null,l([]),d(null),p(null),h(null),oe({status:`idle`}),ce([]),fe(!1),_(!1),y(`chat`),x(null),C(null),T(null),D([]),ve.current=!1,k(null),N(!1),j(!1),Se.current=!1,F(!1),L(`claude`),z(null),V([]),U(``),ee([]),ne(`medium`),ie(``)},[]),ze=Bt(f),Be=Object.values(ze).some(Boolean)||c.length>0||re.trim().length>0,Ve=(0,Q.useMemo)(()=>IM(m??f,{milestoneLabel:`M1`,minSpecs:WM.minSpecs,maxSpecs:WM.maxSpecs,requireScaffold:!0}),[f,m]),He=ae.status===`generating`,Ue=(0,Q.useMemo)(()=>RM(f,m??f,Ve,WM,{generating:He}),[f,m,Ve,He]),We=(0,Q.useMemo)(()=>{if(Ve.valid)return null;let e=Ve.issues[0];return e?BM(n,e):null},[Ve,n]),Ge=(0,Q.useMemo)(()=>on(u),[u]);return{phase:v,messages:c,streamBuffer:u,blueprint:f,busy:g,commitError:b,commitErrorDetail:S,commitSteps:E,createdProjectId:O,launching:A,launched:M,submitting:P,conversationReady:e&&!de,conversationId:o,dirty:Be,canProposeCommit:Ve.valid,specQualityDetail:We,readiness:Ue,snapshot:ae,generation:Ge,recent:se,recentLoading:le,resume:Ae,discardRecent:je,repairSnapshot:Me,showSurpriseMe:c.length<=1&&v===`chat`,provider:I,model:R,models:B,efforts:pe,effort:te,draft:re,setDraft:ie,setEffort:ne,setProvider:De,setModel:Oe,send:ke,surpriseMe:Ne,approveBlueprint:Pe,goToCommit:()=>y(`commit`),backToChat:()=>y(`chat`),submitCommit:Fe,launchM1:Ie,openProject:Le,abortAndReset:Re}}var YM={done:`bg-accent-success`,onReview:`bg-accent-warning`,inProgress:`bg-accent-info animate-pulse`,failed:`bg-destructive`,todo:`bg-muted-foreground/25`},XM={planned:`border-border/60 bg-surface/60 text-foreground/60`,committed:`border-accent-primary/40 bg-accent-primary/10 text-accent-primary`,running:`border-accent-info/40 bg-accent-info/10 text-accent-info`,delivered:`border-accent-warning/40 bg-accent-warning/10 text-accent-warning`,done:`border-accent-success/40 bg-accent-success/10 text-accent-success`};function ZM({counts:e,className:t}){let{t:n}=K(`builder`),r=en(e);return(0,$.jsx)(`div`,{className:X(`flex h-1.5 w-full overflow-hidden rounded-full bg-muted`,t),role:`img`,"aria-label":n(`milestoneProgress.counts`,{delivered:an(e),total:e.total,done:e.done}),"data-testid":`milestone-progress-bar`,children:r.map(e=>(0,$.jsx)(`div`,{"data-segment":e.key,className:X(`h-full transition-all duration-500`,YM[e.key]),style:{width:`${e.pct}%`},title:`${n(`milestoneProgress.legend.${e.key}`)} · ${e.count}`},e.key))})}function QM({state:e}){let{t}=K(`builder`);return(0,$.jsx)(`span`,{"data-testid":`milestone-state-pill`,"data-state":e,className:X(`inline-flex shrink-0 items-center rounded-full border px-1.5 py-px text-[9px] font-semibold uppercase tracking-wide`,XM[e]),children:t(`milestoneProgress.state.${e}`)})}function $M(e){let[t,n]=(0,Q.useState)(()=>Date.now());return(0,Q.useEffect)(()=>{if(!e)return;n(Date.now());let t=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(t)},[e]),t}function eN({rail:e,now:t,onReview:n,onOpenRail:r}){let{t:i}=K(`builder`),a=e.name??i(`milestoneProgress.rail.fallbackName`,{n:e.railIndex+1}),o=e.active&&e.startedAt?Math.max(0,t-Date.parse(e.startedAt)):null,s=e.delivery?.decision??null,c=s!==null&&Jt.has(s)&&e.delivery!==null;return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border/30 bg-surface/40 px-2 py-1.5`,"data-testid":`milestone-rail-row`,"data-rail-index":e.railIndex,children:[e.chunkIndex!=null&&(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-muted/70 px-1 py-px text-[9px] font-mono tabular-nums text-muted-foreground`,title:i(`milestoneProgress.rail.chunk`,{k:e.chunkIndex}),children:e.chunkIndex}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>r?.(e.railIndex),className:`min-w-0 flex-1 truncate text-left text-[11px] font-medium hover:underline`,title:i(`milestoneProgress.rail.open`),children:a}),e.active?(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-accent-info`,"data-testid":`milestone-rail-running`,children:[(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}),o==null?i(`milestoneProgress.state.running`):i(`milestoneProgress.rail.running`,{elapsed:Or(o)})]}):s?(0,$.jsx)(gj,{decision:s}):(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`milestoneProgress.rail.noDelivery`)}),c&&e.delivery&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n?.(e.delivery.id),className:`inline-flex shrink-0 items-center gap-1 rounded-md border border-accent-primary/40 bg-accent-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-accent-primary hover:bg-accent-primary/20`,"data-testid":`milestone-rail-review`,children:[(0,$.jsx)(vs,{className:`h-3 w-3`,"aria-hidden":!0}),i(`milestoneProgress.rail.review`)]})]})}function tN({checked:e,onChange:t,disabled:n=!1,compact:r=!1,testId:i=`milestone-auto-advance`}){let{t:a}=K(`builder`),o=a(e?`milestoneProgress.chain.autoAdvanceHint`:`milestoneProgress.chain.checkpointHint`);return(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e,"aria-label":a(`milestoneProgress.chain.autoAdvance`),disabled:n,onClick:()=>t(!e),title:o,className:X(`group inline-flex items-center gap-1.5 rounded-md border px-1.5 py-1 text-left text-[10px] transition-colors disabled:opacity-50`,e?`border-accent-success/40 bg-accent-success/10 text-accent-success`:`border-border/50 text-muted-foreground hover:text-foreground`,r?`py-0.5`:`w-full`),"data-testid":i,"data-checked":e,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:X(`relative inline-flex h-3 w-5 shrink-0 items-center rounded-full transition-colors`,e?`bg-accent-success/70`:`bg-muted-foreground/30`),children:(0,$.jsx)(`span`,{className:X(`absolute h-2 w-2 rounded-full bg-background shadow transition-transform`,e?`translate-x-2.5`:`translate-x-0.5`)})}),e?(0,$.jsx)(wn,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}):(0,$.jsx)(Ss,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:a(`milestoneProgress.chain.autoAdvance`)}),!r&&(0,$.jsx)(`span`,{className:`hidden truncate text-[9px] font-normal text-muted-foreground group-hover:inline`,children:o})]})}function nN({chain:e,busy:t=!1,onResume:n,onCancel:r,onSetAutoAdvance:i}){let{t:a}=K(`builder`),o=$t(e),s=e.status===`paused`,c=Vt(e),l=nn(e.pauseReason),u=s?a(`milestoneProgress.chain.reasons.${l.key}`,{detail:l.detail,defaultValue:e.pauseReason??``}):null,d=e.mode===`sequential`&&(o||s||c)&&!!i;return(0,$.jsxs)(`div`,{className:X(`rounded-md border px-2 py-1.5 text-[10px]`,s?`border-accent-warning/40 bg-accent-warning/5`:c?`border-accent-success/40 bg-accent-success/5`:o?`border-accent-info/30 bg-accent-info/5`:`border-border/30 bg-surface/40`),"data-testid":`milestone-chain-row`,"data-status":e.status,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(kn,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`font-medium`,children:e.mode===`parallel`?a(`milestoneProgress.chain.parallelTitle`):a(`milestoneProgress.chain.title`)}),(0,$.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,a(`milestoneProgress.chain.progress`,{k:Math.min(e.nextChunk,e.totalChunks),n:e.totalChunks})]}),(0,$.jsx)(`span`,{className:`flex-1`}),c&&n&&(0,$.jsxs)(`button`,{type:`button`,disabled:t,onClick:()=>n(e.id),className:`inline-flex items-center gap-1 rounded-md border border-accent-success/40 bg-accent-success/10 px-1.5 py-0.5 font-medium text-accent-success hover:bg-accent-success/20 disabled:opacity-50`,"data-testid":`milestone-chain-launch-next`,children:[t?(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Mn,{className:`h-3 w-3`,"aria-hidden":!0}),a(`milestoneProgress.chain.launchNext`)]}),s&&n&&(0,$.jsxs)(`button`,{type:`button`,disabled:t,onClick:()=>n(e.id),className:`inline-flex items-center gap-1 rounded-md border border-accent-success/40 bg-accent-success/10 px-1.5 py-0.5 font-medium text-accent-success hover:bg-accent-success/20 disabled:opacity-50`,"data-testid":`milestone-chain-resume`,children:[t?(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Mn,{className:`h-3 w-3`,"aria-hidden":!0}),a(`milestoneProgress.chain.resume`)]}),(o||s||c)&&r&&(0,$.jsx)(`button`,{type:`button`,disabled:t,onClick:()=>r(e.id),className:`inline-flex items-center gap-1 rounded-md border border-border/60 px-1.5 py-0.5 text-muted-foreground hover:text-foreground disabled:opacity-50`,title:a(`milestoneProgress.chain.cancel`),"data-testid":`milestone-chain-cancel`,children:(0,$.jsx)(Vn,{className:`h-3 w-3`,"aria-hidden":!0})})]}),(0,$.jsx)(`div`,{className:`mt-0.5 flex items-center gap-1 text-muted-foreground`,children:s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ic,{className:`h-3 w-3 shrink-0 text-accent-warning`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`text-accent-warning`,children:a(`milestoneProgress.chain.paused`,{reason:u})})]}):c?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ss,{className:`h-3 w-3 shrink-0 text-accent-success`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`text-accent-success`,"data-testid":`milestone-chain-checkpoint`,children:a(`milestoneProgress.chain.checkpoint`,{k:e.nextChunk,next:e.nextChunk+1,n:e.totalChunks})}),e.headBranch&&(0,$.jsxs)(`span`,{className:`truncate font-mono`,title:e.headBranch,children:[` · `,a(`milestoneProgress.chain.stackedOn`,{branch:e.headBranch})]})]}):e.status===`running`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ce,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:a(`milestoneProgress.chain.waiting`,{k:e.nextChunk})}),e.headBranch&&e.mode===`sequential`&&(0,$.jsxs)(`span`,{className:`truncate font-mono`,title:e.headBranch,children:[` · `,a(`milestoneProgress.chain.stackedOn`,{branch:e.headBranch})]}),e.mode===`sequential`&&!e.autoAdvance&&e.nextChunk<e.totalChunks&&(0,$.jsxs)(`span`,{className:`shrink-0`,"data-testid":`milestone-chain-checkpoint-note`,children:[` · `,a(`milestoneProgress.chain.checkpointNote`)]})]}):e.status===`completed`?(0,$.jsx)(`span`,{children:a(`milestoneProgress.chain.completed`)}):e.status===`cancelled`?(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(Cn,{className:`h-3 w-3`,"aria-hidden":!0}),a(`milestoneProgress.chain.cancelled`)]}):(0,$.jsx)(`span`,{children:a(`milestoneProgress.chain.waiting`,{k:e.nextChunk})})}),d&&i&&(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(tN,{checked:e.autoAdvance,disabled:t,onChange:t=>i(e.id,t),testId:`milestone-chain-auto-advance`})})]})}function rN({progress:e,actions:t,chainBusy:n,onReview:r,onOpenRail:i,onResume:a,onCancel:o,onSetAutoAdvance:s,className:c}){let{t:l}=K(`builder`),u=e.rails.some(e=>e.active),d=$M(u),{counts:f}=e,p=e.chain!==null&&e.chain.status!==`completed`&&e.chain.status!==`cancelled`||e.chain&&e.chain.status===`completed`&&e.rails.length>0&&u?e.chain:null;return(0,$.jsxs)(`div`,{className:X(`rounded-md border border-border/30 px-2 py-1.5`,c),"data-testid":`milestone-card`,"data-milestone":e.n,"data-state":e.state,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`rounded bg-accent-primary/10 px-1.5 py-px text-[9px] font-semibold text-accent-primary`,children:Gt(e.n)}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] font-medium`,children:e.title}),(0,$.jsx)(QM,{state:e.state})]}),f.total>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ZM,{counts:f,className:`mt-1.5`}),(0,$.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-2 text-[10px] tabular-nums text-muted-foreground`,children:[(0,$.jsx)(`span`,{"data-testid":`milestone-counts`,children:l(`milestoneProgress.counts`,{delivered:an(f),total:f.total,done:f.done})}),f.inProgress>0&&(0,$.jsxs)(`span`,{className:`text-accent-info`,children:[l(`milestoneProgress.legend.inProgress`),` · `,f.inProgress]})]}),f.failed>0&&(0,$.jsx)(`p`,{className:`mt-0.5 text-[10px] text-destructive`,"data-testid":`milestone-failed-note`,children:l(`milestoneProgress.failedNote`,{count:f.failed})})]}),t&&(0,$.jsx)(`div`,{className:`mt-2 flex flex-col gap-1.5`,children:t}),p&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(nN,{chain:p,busy:n,onResume:a,onCancel:o,onSetAutoAdvance:s})}),e.rails.length>0&&(0,$.jsx)(`div`,{className:`mt-2 space-y-1`,"data-testid":`milestone-rails`,children:e.rails.map(e=>(0,$.jsx)(eN,{rail:e,now:d,onReview:r,onOpenRail:i},e.railIndex))})]})}function iN({projectId:e}){let{t}=K(`builder`),n=y(),{setActiveProjectId:r}=pt(),{progress:i,hasBlueprint:a}=Qt(e),[o,s]=(0,Q.useState)(!1),c=i.find(e=>e.n===1)??null,l=(0,Q.useCallback)(t=>{r(e),setTimeout(()=>n(t),50)},[n,e,r]),u=(0,Q.useCallback)(async n=>{s(!0);try{let r=await wM(e,n);r.ok?J.success(t(`milestoneProgress.chain.resumed`)):J.error(t(`milestoneProgress.chain.resumeFailed`),{description:r.detail??r.error})}finally{s(!1)}},[e,t]),d=(0,Q.useCallback)(async(n,r)=>{s(!0);try{let i=await EM(e,n,r);i.ok?(_M(r),J.success(t(r?`milestoneProgress.chain.autoOn`:`milestoneProgress.chain.autoOff`))):J.error(t(`milestoneProgress.chain.autoFailed`),{description:i.detail??i.error})}finally{s(!1)}},[e,t]),f=(0,Q.useCallback)(async n=>{s(!0);try{let r=await TM(e,n);r.ok?J.success(t(`milestoneProgress.chain.cancelledToast`)):J.error(r.detail??r.error)}finally{s(!1)}},[e,t]);return a===null&&!c?(0,$.jsx)(`div`,{className:`mt-4 flex items-center justify-center gap-2 text-xs text-muted-foreground`,"data-testid":`builder-done-milestone-loading`,children:(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0})}):c?(0,$.jsx)(`div`,{className:`mt-4 text-left`,"data-testid":`builder-done-milestone`,children:(0,$.jsx)(rN,{progress:c,chainBusy:o,onReview:e=>l(le?`/review/${e}`:`/`),onOpenRail:()=>l(`/`),onResume:u,onCancel:f,onSetAutoAdvance:d,className:`bg-card/60`})}):null}var aN={surprise:Fc,approve:gc};function oN({kind:e,mode:t,onAction:n,disabled:r=!1,createdAt:i,className:a}){let{t:o}=K(`builder`),s=My(),c=t===`settled`,l=c?Sn:aN[e],u=i?sN(i):null,d=X(`group relative my-1 w-full max-w-lg overflow-hidden rounded-xl border text-left shadow-lg backdrop-blur`,c?`border-accent-success/25 bg-card/60`:`border-accent-primary/25 bg-card/80 transition-colors hover:border-accent-primary/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/50 disabled:cursor-not-allowed disabled:opacity-60`,a),f=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:X(`pointer-events-none absolute inset-0 bg-gradient-to-br via-transparent transition-opacity`,c?`from-accent-success/[0.06] to-accent-success/[0.03] opacity-100`:`from-accent-primary/[0.08] to-accent-highlight/[0.08] opacity-70 group-hover:opacity-100`)}),(0,$.jsxs)(`div`,{className:X(`relative flex items-center justify-between gap-2 border-b border-border/40 px-3.5 py-2`,c?`bg-accent-success/[0.05]`:`bg-accent-primary/[0.06]`),children:[(0,$.jsxs)(`span`,{className:X(`flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-widest`,c?`text-accent-success/90`:`text-accent-primary/90`),children:[c?(0,$.jsx)(Sn,{className:`h-3 w-3`,"aria-hidden":!0}):(0,$.jsx)(Ln,{className:`h-3 w-3`,"aria-hidden":!0}),o(c?`decisionCard.settledLabel`:`decisionCard.${e}.label`)]}),(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,"data-testid":`builder-decision-card-meta`,children:c?u:o(`decisionCard.${e}.hint`)})]}),(0,$.jsxs)(`div`,{className:`relative flex items-center gap-3.5 px-3.5 py-3`,children:[(0,$.jsx)(`span`,{className:X(`flex h-9 w-9 shrink-0 items-center justify-center rounded-full shadow-inner`,c?`bg-accent-success/15 text-accent-success`:`bg-gradient-to-br from-accent-primary/25 to-accent-highlight/25 text-accent-primary`),children:(0,$.jsx)(l,{className:`h-4 w-4`,"aria-hidden":!0})}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block text-sm font-semibold leading-snug text-foreground`,children:o(c?`decisionCard.${e}.settledTitle`:`decisionCard.${e}.title`)}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs leading-relaxed text-muted-foreground`,children:o(c?`decisionCard.${e}.settledDescription`:`decisionCard.${e}.description`)})]}),!c&&(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1 rounded-full bg-accent-primary/15 px-2.5 py-1 text-[11px] font-medium text-accent-primary transition-colors group-hover:bg-accent-primary/25`,children:[o(`decisionCard.${e}.cta`),(0,$.jsx)(ce,{className:`h-3 w-3 transition-transform group-hover:translate-x-0.5`,"aria-hidden":!0})]})]})]});return c?(0,$.jsx)(`div`,{className:d,"data-testid":`builder-decision-card`,"data-kind":e,"data-mode":`settled`,children:f}):(0,$.jsx)(Ny.button,{type:`button`,onClick:n,disabled:r,initial:s?{opacity:0}:{opacity:0,y:8},animate:{opacity:1,y:0},exit:s?{opacity:0}:{opacity:0,y:-6},transition:{duration:.22,ease:`easeOut`},whileHover:r||s?void 0:{y:-2},whileTap:r?void 0:{scale:.99},className:d,"data-testid":`builder-decision-card`,"data-kind":e,"data-mode":`offer`,"aria-label":o(`decisionCard.${e}.cta`),children:f})}function sN(e){let t=Date.parse(e);if(!Number.isFinite(t))return null;try{return Pb(t,`p`,{locale:Ze()})}catch{return null}}var cN=`w-full rounded-2xl border border-border/60 bg-card/90 p-3 shadow-2xl backdrop-blur-xl`;function lN({variant:e}){let{t}=K(`builder`),{builderMode:n}=aP(),r=n.session,[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(()=>gM()),c=(0,Q.useRef)(null),l=r.messages[r.messages.length-1],u=r.readiness.steps.find(e=>e.key===`blueprint`),d=r.readiness.steps.find(e=>e.key===`specs`),f=r.phase===`chat`&&!r.busy&&r.streamBuffer===null&&l?.role===`assistant`&&r.snapshot.status!==`generating`,p=f&&u?.state!==`done`,m=f&&u?.state===`done`&&(d===void 0||d.state===`pending`&&Number(d.params.count??0)===0)&&(r.blueprint?.m1Specs.length??0)===0;(0,Q.useEffect)(()=>{c.current?.scrollTo?.({top:c.current.scrollHeight})},[r.messages,r.streamBuffer]);let h=(0,Q.useCallback)(()=>{r.dirty&&r.phase!==`done`?a(!0):n.exit()},[r.dirty,r.phase,n]),g=(0,Q.useCallback)(e=>{e.key===`Escape`&&(e.stopPropagation(),i?a(!1):r.phase===`commit`&&!r.submitting?r.backToChat():r.phase===`chat`&&h())},[i,r,h]),_=r.messages.length===0&&r.streamBuffer===null&&!r.busy,v=e===`inline`?`mx-auto flex w-full max-w-[820px] flex-1 flex-col overflow-hidden`:`flex flex-1 flex-col overflow-hidden`;return(0,$.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,onKeyDown:g,"data-testid":`builder-conversation`,children:[r.phase===`chat`&&(_?(0,$.jsx)(`div`,{className:`relative z-10 flex h-full w-full items-center justify-center px-6`,children:(0,$.jsxs)(Ny.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.28,ease:[.34,1.56,.64,1]},className:X(`w-full`,e===`inline`?`max-w-[680px]`:`max-w-[560px]`),children:[(0,$.jsxs)(`div`,{className:`mb-4 text-center`,children:[(0,$.jsx)(Ln,{className:`mx-auto h-7 w-7 text-accent-primary/60`}),(0,$.jsx)(`p`,{className:`mt-2 text-sm font-medium`,children:t(`shell.emptyTitle`)}),(0,$.jsx)(`p`,{className:`mx-auto mt-1 max-w-sm text-xs text-muted-foreground`,children:t(`shell.emptyHint`)})]}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(NA,{active:!0,inset:-3,radius:`1rem`}),(0,$.jsx)(Ny.div,{layoutId:e===`inline`?`builder-composer-dock`:void 0,"data-testid":`builder-composer-card`,"data-composer-position":`hero`,"data-layout-id":e===`inline`?`builder-composer-dock`:void 0,transition:{layout:{type:`spring`,stiffness:350,damping:34}},className:cN,children:(0,$.jsx)(sM,{session:r,autoFocus:!0})})]}),(0,$.jsx)(lM,{items:r.recent,loading:r.recentLoading,disabled:!r.conversationReady,onResume:e=>void r.resume(e),onDiscard:e=>void r.discardRecent(e)})]})}):(0,$.jsxs)(`div`,{className:v,children:[(0,$.jsxs)(`div`,{ref:c,className:`flex-1 space-y-5 overflow-y-auto px-4 py-4`,"data-testid":`builder-messages`,children:[r.messages.map((e,t)=>e.role===`user`&&e.intent?(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(oN,{kind:e.intent,mode:`settled`,createdAt:e.createdAt})},`${t}-${e.createdAt}`):(0,$.jsx)(ZD,{role:e.role,content:e.content,createdAt:e.createdAt,isLast:r.streamBuffer===null&&!r.busy&&t===r.messages.length-1,onPickOption:e=>r.send(e)},`${t}-${e.createdAt}`)),(0,$.jsxs)(N_,{initial:!1,children:[p&&(0,$.jsx)(oN,{kind:`surprise`,mode:`offer`,onAction:r.surpriseMe,disabled:!r.conversationReady},`surprise`),m&&(0,$.jsx)(oN,{kind:`approve`,mode:`offer`,onAction:r.approveBlueprint,disabled:!r.conversationReady},`approve`)]}),(r.busy||r.streamBuffer!==null)&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[r.streamBuffer!==null&&Kt(r.streamBuffer)&&(0,$.jsx)(ZD,{role:`assistant`,content:Kt(r.streamBuffer),streaming:!0}),r.generation.generating||r.snapshot.status===`repairing`||r.snapshot.status===`generating`?(0,$.jsx)(uM,{specsStarted:r.generation.specsStarted,snapshot:r.snapshot}):(0,$.jsx)(Vb,{tool:null})]})]}),(0,$.jsx)(`div`,{className:`shrink-0 px-4 pb-4`,children:(0,$.jsx)(Ny.div,{layoutId:e===`inline`?`builder-composer-dock`:void 0,"data-testid":`builder-composer-card`,"data-composer-position":`docked`,"data-layout-id":e===`inline`?`builder-composer-dock`:void 0,transition:{layout:{type:`spring`,stiffness:350,damping:34}},className:X(cN,e===`inline`&&`mx-auto max-w-[680px]`),children:(0,$.jsx)(sM,{session:r})})})]})),r.phase===`commit`&&r.blueprint&&(0,$.jsx)(`div`,{className:`flex min-h-0 flex-1 items-start justify-center overflow-y-auto`,children:(0,$.jsx)(oM,{blueprint:r.blueprint,onSubmit:r.submitCommit,onBack:r.backToChat,submitting:r.submitting,error:r.commitError,errorDetail:r.commitErrorDetail})}),r.phase===`progress`&&(0,$.jsxs)(`div`,{className:`mx-auto mt-10 w-full max-w-md p-6`,"data-testid":`commit-progress`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold`,children:t(`progress.title`)}),(0,$.jsx)(`ul`,{className:`mt-4 space-y-2`,children:UM.map(e=>{let n=r.commitSteps.find(t=>t.step===e);return!n&&e===`github`?null:(0,$.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[!n&&(0,$.jsx)(es,{className:`h-3.5 w-3.5 text-muted-foreground/40`}),n?.status===`running`&&(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin text-accent-info`}),n?.status===`done`&&(0,$.jsx)(Sn,{className:`h-3.5 w-3.5 text-accent-success`}),n?.status===`warning`&&(0,$.jsx)(zn,{className:`h-3.5 w-3.5 text-accent-warning`}),n?.status===`failed`&&(0,$.jsx)(Vn,{className:`h-3.5 w-3.5 text-destructive`}),(0,$.jsx)(`span`,{className:X(!n&&`text-muted-foreground/50`),children:t(`progress.steps.${e}`)}),n?.status===`warning`&&e===`github`?(0,$.jsx)(`span`,{className:`truncate text-[10px] text-accent-warning`,title:n.detail,children:t(HM(n.code))}):n?.detail&&(0,$.jsx)(`span`,{className:`truncate text-[10px] text-muted-foreground`,title:n.detail,children:n.detail})]},e)})})]}),r.phase===`done`&&(0,$.jsxs)(`div`,{className:`mx-auto mt-12 w-full max-w-md p-6 text-center`,"data-testid":`commit-done`,children:[(0,$.jsx)(Sn,{className:`mx-auto h-10 w-10 rounded-full bg-accent-success/15 p-2 text-accent-success`}),(0,$.jsx)(`h2`,{className:`mt-3 text-sm font-semibold`,children:t(`done.title`)}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:t(`done.description`)}),r.launched&&r.createdProjectId&&(0,$.jsx)(iN,{projectId:r.createdProjectId}),(0,$.jsxs)(`div`,{className:`mt-5 flex flex-col gap-2`,children:[!r.launched&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Z,{onClick:()=>void r.launchM1(),disabled:r.launching,"data-testid":`launch-m1`,children:[r.launching?(0,$.jsx)(An,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(gc,{className:`mr-1.5 h-3.5 w-3.5`}),t(`done.launchM1`)]}),pM()===`sequential`&&(0,$.jsx)(tN,{checked:o,onChange:e=>{s(e),_M(e)},disabled:r.launching,testId:`done-auto-advance`})]}),(0,$.jsx)(Z,{variant:`outline`,onClick:r.openProject,"data-testid":`open-project`,children:t(`done.openProject`)})]})]}),i&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/70 backdrop-blur-sm`,"data-testid":`builder-exit-confirm`,children:(0,$.jsxs)(`div`,{className:`w-72 rounded-lg border border-border/60 bg-card p-4 shadow-xl`,role:`alertdialog`,"aria-modal":`true`,"aria-labelledby":`builder-exit-confirm-title`,children:[(0,$.jsx)(`p`,{id:`builder-exit-confirm-title`,className:`text-sm font-medium`,children:t(`mode.exitConfirmTitle`)}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:t(`mode.exitConfirmBody`)}),(0,$.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:()=>a(!1),"data-testid":`builder-exit-cancel`,children:t(`mode.exitConfirmCancel`)}),(0,$.jsx)(Z,{variant:`destructive`,size:`sm`,onClick:()=>{a(!1),n.exit()},"data-testid":`builder-exit-confirm-btn`,children:t(`mode.exitConfirmDiscard`)})]})]})})]})}var uN=X(`text-sm leading-7 text-foreground`,`[&_p]:my-3 [&_p:first-child]:mt-0 [&_p:last-child]:mb-0`,`[&_h1]:mt-4 [&_h1]:mb-2 [&_h1]:text-base [&_h1]:font-semibold`,`[&_h2]:mt-4 [&_h2]:mb-1.5 [&_h2]:text-[15px] [&_h2]:font-semibold`,`[&_h3]:mt-3 [&_h3]:mb-1 [&_h3]:text-sm [&_h3]:font-semibold`,`[&_strong]:font-semibold [&_strong]:text-foreground`,`[&_em]:italic`,`[&_a]:text-accent-info [&_a]:underline [&_a]:underline-offset-2`,`[&_ul]:my-2.5 [&_ul]:list-disc [&_ul]:pl-5 [&_ol]:my-2.5 [&_ol]:list-decimal [&_ol]:pl-5 [&_li]:my-1`,`[&_code]:rounded [&_code]:bg-surface [&_code]:px-1 [&_code]:py-0.5 [&_code]:font-mono [&_code]:text-[0.85em] [&_code]:text-accent-info`,`[&_pre]:my-2 [&_pre]:overflow-x-auto [&_pre]:rounded-lg [&_pre]:bg-surface [&_pre]:p-3`,`[&_pre_code]:bg-transparent [&_pre_code]:p-0 [&_pre_code]:text-foreground`,`[&_hr]:my-3 [&_hr]:border-border/60`),dN={critical:`border-destructive/35 bg-destructive/15 text-destructive`,high:`border-accent-warning/35 bg-accent-warning/15 text-accent-warning`,medium:`border-accent-info/35 bg-accent-info/15 text-accent-info`,low:`border-border/60 bg-surface/70 text-foreground/60`};function fN({spec:e,index:t,milestoneLabel:n=`M1`,onClose:r}){let{t:i}=K(`builder`),{t:a}=K(`tickets`),o=`blueprint-spec-summary-${t}`;return(0,Q.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.stopPropagation(),r())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]),(0,Hb.createPortal)((0,$.jsxs)(`div`,{"data-testid":`blueprint-spec-modal`,className:`fixed inset-0 z-[65] flex items-center justify-center p-4`,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:r,"aria-hidden":!0}),(0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":e.title,"aria-describedby":e.shortSummary.trim()?o:void 0,className:`relative flex max-h-[82vh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-border/40 bg-popover shadow-2xl backdrop-blur-md`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3 border-b border-border/40 px-5 py-4`,children:[(0,$.jsx)(Dn,{className:`mt-0.5 h-4 w-4 shrink-0 text-accent-primary`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:i(`specModal.eyebrow`,{milestone:n,index:t+1})}),(0,$.jsx)(`h2`,{className:`mt-0.5 text-base font-semibold text-foreground`,children:e.title}),e.shortSummary.trim()&&(0,$.jsxs)(`p`,{id:o,className:`mt-1 text-xs leading-5 text-muted-foreground`,"data-testid":`blueprint-spec-summary`,children:[(0,$.jsxs)(`span`,{className:`sr-only`,children:[i(`specModal.summary`),`: `]}),e.shortSummary]}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[(0,$.jsx)(`span`,{className:X(`rounded-full border px-1.5 py-px text-[9px] font-medium uppercase tracking-wide`,dN[e.priority]),"data-testid":`blueprint-spec-priority`,"aria-label":`${i(`specModal.priority`)}: ${a(`priority.${e.priority}`)}`,children:a(`priority.${e.priority}`)}),e.labels.map(e=>(0,$.jsx)(`span`,{className:`rounded bg-accent-primary/10 px-1.5 py-px text-[9px] text-accent-primary`,children:e},e)),e.dependsOnIndex!==void 0&&(0,$.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-px text-[9px] text-muted-foreground`,children:i(`panel.dependsOn`,{index:e.dependsOnIndex+1})})]})]}),(0,$.jsx)(`button`,{type:`button`,onClick:r,"aria-label":i(`specModal.close`),"data-agent-interactive":!0,className:`rounded-md p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground`,"data-testid":`blueprint-spec-modal-close`,children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4`,children:[(0,$.jsx)(`section`,{"aria-label":i(`specModal.description`),"data-testid":`blueprint-spec-description`,children:e.description.trim()?(0,$.jsx)(`div`,{className:uN,children:(0,$.jsx)(br,{remarkPlugins:[xr],children:e.description})}):(0,$.jsx)(`p`,{className:`text-xs italic text-muted-foreground`,children:i(`specModal.empty`)})}),(0,$.jsxs)(`section`,{"aria-labelledby":`blueprint-spec-criteria-heading`,"data-testid":`blueprint-spec-acceptance-criteria`,children:[(0,$.jsxs)(`h3`,{id:`blueprint-spec-criteria-heading`,className:`mb-2 flex items-center justify-between gap-2 text-xs font-semibold uppercase tracking-wider text-foreground/60`,children:[(0,$.jsx)(`span`,{children:i(`specModal.acceptanceCriteria`)}),(0,$.jsx)(`span`,{className:`rounded-full bg-surface px-2 py-0.5 text-[10px] tabular-nums text-muted-foreground`,children:e.acceptanceCriteria.length})]}),e.acceptanceCriteria.length>0?(0,$.jsx)(`ol`,{className:`space-y-2`,children:e.acceptanceCriteria.map((e,t)=>(0,$.jsxs)(`li`,{className:`flex items-start gap-2 text-sm leading-6 text-foreground/85`,"data-testid":`blueprint-spec-criterion-${t}`,children:[(0,$.jsx)($o,{className:`mt-1 h-4 w-4 shrink-0 text-accent-success`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:e})]},`${t}-${e}`))}):(0,$.jsx)(`p`,{className:`text-xs italic text-muted-foreground`,children:i(`specModal.criteriaEmpty`)})]})]})]})]}),document.body)}var pN={critical:`border-destructive/35 bg-destructive/15 text-destructive`,high:`border-accent-warning/35 bg-accent-warning/15 text-accent-warning`,medium:`border-accent-info/35 bg-accent-info/15 text-accent-info`,low:`border-border/60 bg-surface/70 text-foreground/60`};function mN({blueprint:e,milestoneLabel:t=`M1`,snapshot:n}){let{t:r}=K(`builder`),{t:i}=K(`tickets`),a=Bt(e),[o,s]=(0,Q.useState)(null),c=[{key:`product`,label:r(`panel.product`),value:e?.product.name??``},{key:`coreFlow`,label:r(`panel.coreFlow`),value:e?.coreFlow??``},{key:`platform`,label:r(`panel.platform`),value:e?.platform??``},{key:`stack`,label:r(`panel.stack`),value:e?[e.stack.language,e.stack.framework,e.stack.db].filter(Boolean).join(` · `):``},{key:`milestones`,label:r(`panel.milestones`),value:e&&e.milestones.length>0?r(`panel.milestonesValue`,{count:e.milestones.length}):``}];return(0,$.jsxs)(`div`,{className:`flex h-full flex-col gap-4 overflow-y-auto p-4`,"data-testid":`blueprint-panel`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`h3`,{className:`flex items-center gap-2 text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:[r(`panel.title`),n?.status===`repairing`&&(0,$.jsx)(An,{className:`h-3 w-3 animate-spin text-accent-info`,"aria-hidden":!0,"data-testid":`panel-repairing`})]}),(0,$.jsx)(`div`,{className:`space-y-1`,children:c.map(e=>(0,$.jsxs)(`div`,{className:X(`flex items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs transition-colors`,a[e.key]?`border-accent-success/30 bg-accent-success/5`:`border-border/30`),"data-testid":`dimension-${e.key}`,children:[a[e.key]?(0,$.jsx)(Sn,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`,"aria-label":`✓`}):(0,$.jsx)(Vn,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/40`,"aria-label":`✗`}),(0,$.jsx)(`span`,{className:`font-medium`,children:e.label}),e.value&&(0,$.jsx)(`span`,{className:`ml-auto truncate text-muted-foreground`,title:e.value,children:e.value})]},e.key))})]}),e&&e.assumptions.length>0&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`h4`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:r(`panel.assumptions`)}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:e.assumptions.map((e,t)=>(0,$.jsx)(`li`,{className:`text-[11px] text-muted-foreground before:mr-1.5 before:content-['·']`,children:e},t))})]}),e&&e.m1Specs.length>0&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`h4`,{className:`flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:[(0,$.jsx)(kn,{className:`h-3 w-3`}),r(`panel.m1Specs`,{count:e.m1Specs.length}),(0,$.jsx)(`span`,{className:X(`ml-auto rounded-full border px-1.5 py-px text-[9px] font-medium normal-case tracking-normal`,e.specsComplete?`border-accent-success/35 bg-accent-success/10 text-accent-success`:`border-accent-warning/35 bg-accent-warning/10 text-accent-warning`),"data-testid":`m1-specs-completeness`,children:e.specsComplete?r(`panel.specsComplete`):r(`panel.specsInProgress`)})]}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:e.m1Specs.map((e,t)=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>s(t),"data-agent-interactive":!0,className:`w-full rounded-lg border border-border/40 bg-surface/50 p-2.5 text-left shadow-sm transition-colors animate-in fade-in slide-in-from-bottom-1 hover:border-accent-primary/50 hover:bg-surface/80 focus:outline-none focus-visible:ring-1 focus-visible:ring-ring`,"data-testid":`m1-spec-card-${t}`,title:r(`specModal.open`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(Dn,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-primary`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium leading-tight`,children:e.title}),e.shortSummary.trim()&&(0,$.jsx)(`p`,{className:`mt-1 line-clamp-2 text-[11px] leading-4 text-muted-foreground`,"data-testid":`m1-spec-summary-${t}`,children:e.shortSummary}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-1`,children:[(0,$.jsx)(`span`,{className:X(`rounded-full border px-1.5 py-px text-[9px] font-medium uppercase tracking-wide`,pN[e.priority]),"data-testid":`m1-spec-priority-${t}`,children:i(`priority.${e.priority}`)}),!e.description.trim()&&e.acceptanceCriteria.length===0?(0,$.jsxs)(`span`,{className:X(`inline-flex items-center gap-1 rounded-full border px-1.5 py-px text-[9px]`,n?.status===`generating`?`border-accent-info/35 bg-accent-info/10 text-accent-info`:`border-border/50 bg-surface/70 text-muted-foreground`),"data-testid":`m1-spec-unwritten-${t}`,children:[n?.status===`generating`?(0,$.jsx)(An,{className:`h-2.5 w-2.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Ws,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),r(n?.status===`generating`?`panel.specWriting`:`panel.specPendingBody`)]}):(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-border/50 bg-surface/70 px-1.5 py-px text-[9px] text-muted-foreground`,"data-testid":`m1-spec-criteria-count-${t}`,children:[(0,$.jsx)(Ws,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),r(`panel.criteriaCount`,{count:e.acceptanceCriteria.length})]}),e.labels.map(e=>(0,$.jsx)(`span`,{className:`rounded bg-accent-primary/10 px-1.5 py-px text-[9px] text-accent-primary`,children:e},e)),e.dependsOnIndex!==void 0&&(0,$.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-px text-[9px] text-muted-foreground`,children:r(`panel.dependsOn`,{index:e.dependsOnIndex+1})})]})]})]})},`${t}-${e.title}`))})]}),e&&e.milestones.length>1&&(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`h4`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:r(`panel.laterMilestones`)}),e.milestones.slice(1).map(e=>(0,$.jsxs)(`div`,{className:`rounded-md border border-border/20 px-2.5 py-1.5`,children:[(0,$.jsx)(`p`,{className:`text-[11px] font-medium`,children:e.title}),e.plannedSpecs.length>0&&(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:e.plannedSpecs.join(` · `)})]},e.id||e.title))]}),!e&&(0,$.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground/60`,children:r(`panel.empty`)}),e&&o!==null&&e.m1Specs[o]&&(0,$.jsx)(fN,{spec:e.m1Specs[o],index:o,milestoneLabel:t,onClose:()=>s(null)})]})}var hN={done:Sn,pending:es,blocked:zn,writing:An},gN={done:`text-accent-success`,pending:`text-muted-foreground/50`,blocked:`text-accent-warning`,writing:`text-accent-info animate-spin`};function _N({readiness:e,snapshot:t,busy:n,primaryLabel:r,onPrimary:i,onRepair:a,primaryTestId:o=`builder-create-specs`,showPrimary:s=!0}){let{t:c}=K(`builder`),[l,u]=(0,Q.useState)(!1),d=t.status===`repairing`,f=t.status===`rejected`,p=t.status===`accepted`&&t.generationHalted===!0&&!n,m=e.steps.find(e=>e.key===`specs`),h=m?.state===`done`,g=!!a&&h&&e.issues.length>0,_=e.steps.find(e=>e.state!==`done`);return(0,$.jsxs)(`div`,{className:`space-y-2.5 border-t border-border/40 p-3`,"data-testid":`blueprint-readiness`,children:[(0,$.jsx)(`ol`,{className:`space-y-1`,"aria-label":c(`readiness.title`),children:e.steps.map(e=>{let t=hN[e.state];return(0,$.jsxs)(`li`,{className:`flex items-start gap-2 text-[11px] leading-4`,"data-testid":`readiness-step-${e.key}`,"data-state":e.state,children:[(0,$.jsx)(t,{className:X(`mt-px h-3.5 w-3.5 shrink-0`,gN[e.state]),"aria-hidden":!0}),(0,$.jsx)(`span`,{className:X(`font-medium`,e.state===`pending`&&`text-muted-foreground`,e.state===`writing`&&`text-accent-info`),children:c(`readiness.steps.${e.key}`)}),(0,$.jsx)(`span`,{className:`ml-auto max-w-[60%] truncate text-right text-muted-foreground`,title:c(`readiness.details.${e.key}.${e.state}`,e.params),children:c(`readiness.details.${e.key}.${e.state}`,e.params)})]},e.key)})}),(0,$.jsxs)(N_,{initial:!1,mode:`wait`,children:[d&&(0,$.jsxs)(Ny.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},className:`flex items-center gap-2 rounded-md border border-accent-info/30 bg-accent-info/10 px-2.5 py-1.5 text-[11px] text-accent-info`,"data-testid":`snapshot-repairing`,children:[(0,$.jsx)(An,{className:`h-3.5 w-3.5 shrink-0 animate-spin`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[c(`snapshot.repairing.${t.kind}`),t.manual?``:` · ${c(`snapshot.repairing.automatic`)}`]})]},`repairing`),f&&(0,$.jsxs)(Ny.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},className:`space-y-1.5 rounded-md border border-accent-warning/35 bg-accent-warning/10 p-2.5`,"data-testid":`snapshot-rejected`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] leading-4 text-accent-warning`,children:[(0,$.jsx)(zn,{className:`mt-px h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`font-medium`,children:c(`snapshot.rejected.title`)}),(0,$.jsx)(`p`,{className:`text-accent-warning/90`,children:c(`snapshot.rejected.${t.reason}`)}),t.repairAttempted&&(0,$.jsx)(`p`,{className:`mt-0.5 text-[10px] text-accent-warning/80`,children:c(`snapshot.rejected.autoRepairFailed`)})]})]}),t.detail&&(0,$.jsx)(`p`,{className:`line-clamp-2 break-all font-mono text-[10px] leading-4 text-foreground/60`,title:t.detail,"data-testid":`snapshot-rejected-detail`,children:t.detail}),a&&(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,className:`w-full`,disabled:n,onClick:a,"data-testid":`snapshot-retry`,children:[(0,$.jsx)(mc,{className:`mr-1.5 h-3 w-3`,"aria-hidden":!0}),c(`snapshot.rejected.retry`)]})]},`rejected`),p&&(0,$.jsxs)(Ny.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},className:`space-y-1.5 rounded-md border border-accent-warning/35 bg-accent-warning/10 p-2.5`,"data-testid":`snapshot-halted`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] leading-4 text-accent-warning`,children:[(0,$.jsx)(zn,{className:`mt-px h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`font-medium`,children:c(`snapshot.halted.title`)}),(0,$.jsx)(`p`,{className:`text-accent-warning/90`,children:c(`snapshot.halted.detail`,{written:m?.params?.written??0,total:m?.params?.count??0})})]})]}),a&&(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,className:`w-full`,disabled:n,onClick:a,"data-testid":`snapshot-resume`,children:[(0,$.jsx)(Ln,{className:`mr-1.5 h-3 w-3`,"aria-hidden":!0}),c(`snapshot.halted.resume`)]})]},`halted`),t.status===`accepted`&&t.repaired&&!p&&(0,$.jsxs)(Ny.p,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,"data-testid":`snapshot-repaired`,children:[(0,$.jsx)(Ln,{className:`h-3 w-3 text-accent-success`,"aria-hidden":!0}),c(`snapshot.repairedNote`)]},`repaired`)]}),e.issues.length>0&&(0,$.jsxs)(`div`,{className:`rounded-md border border-border/40 bg-surface/40`,"data-testid":`readiness-issues`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(e=>!e),"aria-expanded":l,className:`flex w-full items-center gap-1.5 px-2.5 py-1.5 text-left text-[11px] font-medium text-foreground/80 hover:bg-surface/70`,"data-testid":`readiness-issues-toggle`,children:[(0,$.jsx)(Bn,{className:`h-3 w-3 text-accent-warning`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`flex-1`,children:c(`readiness.issuesCount`,{count:e.issues.length})}),(0,$.jsx)(Xo,{className:X(`h-3.5 w-3.5 transition-transform`,l&&`rotate-180`),"aria-hidden":!0})]}),l&&(0,$.jsx)(`ul`,{className:`max-h-40 space-y-1 overflow-y-auto border-t border-border/30 px-2.5 py-2`,children:e.issues.map((e,t)=>(0,$.jsxs)(`li`,{className:`flex items-start gap-1.5 text-[10px] leading-4 text-muted-foreground`,children:[e.specIndex!==null&&(0,$.jsxs)(`span`,{className:`shrink-0 rounded bg-accent-primary/10 px-1 font-mono text-[9px] text-accent-primary`,children:[`#`,e.specIndex+1]}),(0,$.jsx)(`span`,{children:BM(c,e)})]},`${e.specIndex}-${e.field}-${e.code}-${t}`))}),g&&(0,$.jsx)(`div`,{className:`border-t border-border/30 p-2`,children:(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,className:`w-full`,disabled:n,onClick:a,"data-testid":`readiness-ask-fix`,children:[(0,$.jsx)(Bn,{className:`mr-1.5 h-3 w-3`,"aria-hidden":!0}),c(`readiness.askFix`)]})})]}),s&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(Z,{className:`w-full`,size:`sm`,disabled:!e.ready||n,onClick:i,"data-testid":o,children:[(0,$.jsx)(gc,{className:`mr-1.5 h-3.5 w-3.5`,"aria-hidden":!0}),r]}),!e.ready&&_&&!d&&!f&&!p&&(0,$.jsx)(`p`,{className:`mt-1.5 text-center text-[10px] text-muted-foreground`,"data-testid":`readiness-hint`,children:c(`readiness.hints.${_.key}.${_.state}`,_.params)})]})]})}function vN(){let{t:e}=K(`agent`),{t}=K(`builder`),{minimize:n,startNewConversation:r,cycleTier:i,active:a,draftPinnedProjectId:o,setPinnedProject:s,builderMode:c}=aP(),[l,u]=(0,Q.useState)(!1),d=c.active,f=e=>{d||e.shiftKey&&(e.key===`Tab`||e.code===`Tab`)&&(e.preventDefault(),i())},{panelRef:p,panelStyle:m,headerHandleProps:h,resizeHandles:g}=Kn({enabled:!0,allowMove:!0,minWidth:400,minHeight:420,anchorFromCurrentRect:!0,persistKey:`specrails-desktop:agent-panel-geom`});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Ny.div,{ref:p,initial:{opacity:0,scale:.85,y:8},animate:{opacity:1,scale:1,y:0},transition:{duration:.22,ease:[.34,1.56,.64,1]},style:l?{position:`fixed`,inset:12,width:`auto`,height:`auto`,maxWidth:`none`,maxHeight:`none`}:m,role:`dialog`,"aria-label":d?t(`mode.title`):e(`title`),onKeyDown:f,className:`fixed z-[60] flex flex-col overflow-hidden rounded-2xl border border-border/60 bg-card/90 shadow-2xl backdrop-blur-xl ${l?``:`bottom-4 right-4 h-[78vh] max-h-[94vh] max-w-[92vw] ${d?`w-[860px]`:`w-[520px]`}`}`,children:[(0,$.jsxs)(`div`,{...l?{}:h,onDoubleClick:()=>u(e=>!e),className:`flex shrink-0 items-center gap-2 border-b border-border/50 bg-surface/40 px-3 py-2 ${l?``:`cursor-grab`}`,children:[(0,$.jsxs)(`span`,{className:`relative flex h-5 w-5 shrink-0 items-center justify-center`,children:[(0,$.jsx)(NA,{active:d&&c.session.messages.length===0&&c.session.phase===`chat`,inset:-3}),(0,$.jsx)(Vo,{className:`h-4 w-4 shrink-0 text-accent-primary`})]}),(0,$.jsx)(`span`,{className:`shrink-0 text-sm font-medium text-foreground/80`,children:d?t(`mode.title`):e(`title`)}),!d&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ZO,{pinnedProjectId:a?a.pinned_project_id:o,onSelect:e=>void s(e)}),(0,$.jsx)(`div`,{className:`h-4 w-px shrink-0 bg-border/60`,"aria-hidden":!0}),(0,$.jsx)(Kj,{})]}),(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[!d&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>r(null),title:e(`newConversation`),"data-agent-interactive":!0,className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,$.jsx)(Pn,{className:`h-4 w-4`})}),(0,$.jsx)(Rc,{}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>u(e=>!e),"aria-label":e(l?`restore`:`maximize`),title:e(l?`restore`:`maximize`),"data-agent-interactive":!0,className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:l?(0,$.jsx)(Js,{className:`h-4 w-4`}):(0,$.jsx)(qs,{className:`h-4 w-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:n,"aria-label":e(`minimize`),title:e(`minimize`),"data-agent-interactive":!0,className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})]})]}),d?(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,$.jsx)(lN,{variant:`floating`}),(0,$.jsxs)(`aside`,{className:`flex w-72 shrink-0 flex-col border-l border-border/40 lg:w-80`,children:[(0,$.jsx)(mN,{blueprint:c.session.blueprint,snapshot:c.session.snapshot}),c.session.phase===`chat`&&(0,$.jsx)(_N,{readiness:c.session.readiness,snapshot:c.session.snapshot,busy:c.session.busy,primaryLabel:t(`shell.createSpecs`),onPrimary:c.session.goToCommit,onRepair:()=>void c.session.repairSnapshot()})]})]}):(0,$.jsx)(Hj,{variant:`floating`})]}),!l&&(0,$.jsx)(`div`,{className:`pointer-events-none fixed inset-0 z-[61] [&>*]:pointer-events-auto`,children:(0,$.jsx)(ar,{handles:g})})]})}var yN=`specrails-desktop:agent-bubble-pos`,bN=56,xN=12;function SN(){try{let e=localStorage.getItem(yN);if(!e)return null;let t=JSON.parse(e);if(typeof t?.left==`number`&&typeof t?.top==`number`)return t}catch{}return null}function CN(e){let t=Math.max(xN,window.innerWidth-bN-xN),n=Math.max(xN,window.innerHeight-bN-xN);return{left:Math.min(Math.max(xN,e.left),t),top:Math.min(Math.max(xN,e.top),n)}}function wN(){return{left:Math.round(window.innerWidth/2-bN/2),top:window.innerHeight-bN-20}}function TN(){let{t:e}=K(`agent`),{t}=K(`builder`),{open:n,isStreaming:r,active:i,builderMode:a}=aP(),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(()=>CN(SN()??wN())),u=jy(0),d=jy(0),f=(0,Q.useRef)(!1),p=a.active?a.session.busy:r;(0,Q.useEffect)(()=>{let e=()=>l(e=>CN(e));return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let m=(0,Q.useCallback)(e=>{try{localStorage.setItem(yN,JSON.stringify(e))}catch{}},[]);return(0,$.jsxs)(Ny.button,{type:`button`,onClick:()=>{if(f.current){f.current=!1;return}n()},onHoverStart:()=>s(!0),onHoverEnd:()=>s(!1),"aria-label":e(`trigger`),title:`${e(`trigger`)} (⌘⇧A)`,drag:!0,dragMomentum:!1,dragElastic:0,style:{position:`fixed`,left:c.left,top:c.top,x:u,y:d},onDragStart:()=>{f.current=!0},onDragEnd:()=>{let e=CN({left:c.left+u.get(),top:c.top+d.get()});u.set(0),d.set(0),l(e),m(e),setTimeout(()=>{f.current=!1},0)},initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.8},transition:{type:`spring`,stiffness:420,damping:28},whileHover:{scale:1.06},whileTap:{scale:.94},whileDrag:{scale:1.1,cursor:`grabbing`},className:`z-[60] flex h-14 items-center gap-2 rounded-full border border-border/60 bg-card/85 px-3 shadow-2xl backdrop-blur-xl cursor-grab`,children:[(0,$.jsxs)(`span`,{className:`relative flex h-9 w-9 items-center justify-center rounded-full bg-accent-primary/15`,children:[(0,$.jsx)(NA,{active:a.active&&a.session.messages.length===0&&a.session.phase===`chat`,inset:-4}),(0,$.jsx)(Vo,{className:`h-5 w-5 text-accent-primary`}),p&&(0,$.jsx)(Ny.span,{className:`absolute inset-0 rounded-full ring-2 ring-accent-success`,animate:{opacity:[.8,.2,.8],scale:[1,1.18,1]},transition:{duration:1.4,repeat:1/0,ease:`easeInOut`}})]}),(0,$.jsx)(N_,{initial:!1,children:(o||p)&&(0,$.jsx)(Ny.span,{initial:{opacity:0,width:0,marginRight:0},animate:{opacity:1,width:`auto`,marginRight:4},exit:{opacity:0,width:0,marginRight:0},transition:{duration:.18,ease:`easeOut`},className:`overflow-hidden whitespace-nowrap text-sm font-medium text-foreground`,children:p?e(`thinking`):a.active?t(`mode.title`):i?.title||e(`trigger`)})})]})}var EN=`specrails-desktop:uiMode`;function DN(){if(!De)return`kanban`;try{return localStorage.getItem(EN)===`kanban`?`kanban`:`agent`}catch{return`agent`}}function ON(e){try{localStorage.setItem(EN,e)}catch{}}var kN=(0,Q.createContext)(null);function AN({children:e,initialMode:t,persist:n=!0}){let[r,i]=(0,Q.useState)(()=>t??DN()),a=(0,Q.useCallback)(e=>{De&&(i(e),n&&ON(e))},[n]),o=(0,Q.useCallback)(()=>{i(e=>{if(!De)return`kanban`;let t=e===`kanban`?`agent`:`kanban`;return n&&ON(t),t})},[n]),s=(0,Q.useMemo)(()=>({uiMode:r,setUiMode:a,toggleUiMode:o}),[r,a,o]);return(0,$.jsx)(kN.Provider,{value:s,children:e})}var jN={uiMode:`kanban`,setUiMode:()=>{},toggleUiMode:()=>{}};function MN(){return(0,Q.useContext)(kN)??jN}var NN={streamingText:``,isStreaming:!1,liveTools:[],turnTools:[],queued:[]},PN=`specrails-desktop:favorite-agent-conversations`;function FN(){try{let e=localStorage.getItem(PN);if(!e)return new Set;let t=JSON.parse(e);return Array.isArray(t)?new Set(t.filter(e=>typeof e==`string`)):new Set}catch{return new Set}}function IN(e){try{localStorage.setItem(PN,JSON.stringify([...e]))}catch{}}function LN(e,t){let n=new Set(t.map(e=>e.id));return new Set([...e].filter(e=>n.has(e)))}var RN=`specrails-desktop:agent-tier-last`;function zN(){try{let e=localStorage.getItem(RN),t=e===null?0:Number.parseInt(e,10);return t===0||t===1||t===2||t===3?t:0}catch{return 0}}function BN(e){try{localStorage.setItem(RN,String(e))}catch{}}var VN=new Set([`completed`,`merged`,`discarded`,`superseded`]);function HN(e,t){return JSON.stringify(e)===JSON.stringify(t)}function UN(e){if(!e.createdAt)return null;let t=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(e.createdAt)?`${e.createdAt.replace(` `,`T`)}Z`:e.createdAt,n=Date.parse(t);return Number.isFinite(n)?n:null}function WN(e,t){if(t.supersedesDeliveryId===e.prDeliveryId)return 1;if(e.supersedesDeliveryId===t.prDeliveryId)return-1;let n=UN(e),r=UN(t);return n==null||r==null?null:r<n?-1:+(r>n)}function GN(e,t){let n=null;for(let r of e){if(r.supersedesDeliveryId!==t)continue;if(!n){n=r;continue}let e=UN(n),i=UN(r);(e==null||i==null||i>=e)&&(n=r)}return n}function KN(e,t){let n=t.restoredFromDeliveryId;if(!n)return!1;let r=GN(e,t.prDeliveryId);return!r||r.prDeliveryId===n}function qN(e,t){let n=e.filter(e=>e.role===`system`).map(e=>wo(e.content)).filter(e=>e!==null),r=[...n].reverse().find(e=>e.prDeliveryId===t.prDeliveryId),i=KN(n,t);if(r){let e=VN.has(r.decision),n=VN.has(t.decision),a=zt(r.updatedAt,t.updatedAt);if(a===-1||a===0&&!HN(r,t)||e&&!n&&!(i&&r.decision===`superseded`))return!0}let a=new Set(n.map(e=>e.supersedesDeliveryId).filter(e=>!!e));if(i)return!1;if(a.has(t.prDeliveryId)&&t.decision!==`superseded`)return!0;for(let e of n){if(e.railIndex!==t.railIndex||e.prDeliveryId===t.prDeliveryId||a.has(e.prDeliveryId))continue;let n=WN(e,t);if(n===-1||(n===0||n===null)&&!VN.has(e.decision)&&t.supersedesDeliveryId!==e.prDeliveryId)return!0}return!1}function JN(e,t){let n=t.restoredFromDeliveryId;if(!n)return e;let r=!1,i=e.map(e=>{if(e.role!==`system`)return e;let t=wo(e.content);return!t||t.prDeliveryId!==n||VN.has(t.decision)?e:(r=!0,{...e,content:JSON.stringify({...t,decision:`discarded`})})});return r?i:e}function YN(e,t){let n=e.filter(e=>e.role===`system`).map(e=>wo(e.content)).filter(e=>e!==null);if(n.some(e=>e.restoredFromDeliveryId===t.prDeliveryId&&KN(n,e)))return e;let r=!1,i=e.map(e=>{if(e.role!==`system`)return e;let n=wo(e.content);return!n||n.railIndex!==t.railIndex||n.prDeliveryId===t.prDeliveryId||VN.has(n.decision)||WN(n,t)!==1?e:(r=!0,{...e,content:JSON.stringify({...n,decision:`superseded`})})});return r?i:e}function XN(e,t,n){if(qN(e,n))return e;let r=YN(JN(e,n),n),i=JSON.stringify(n),a=r.flatMap((e,t)=>e.role===`system`&&wo(e.content)?.prDeliveryId===n.prDeliveryId?[t]:[]);if(a.length>0){let e=a[a.length-1];if(a.length===1&&r[e].content===i)return r;let t=new Set(a.slice(0,-1));return r.flatMap((n,r)=>t.has(r)?[]:[r===e?{...n,content:i}:n])}return[...r,{id:`prd-${n.prDeliveryId}`,conversation_id:t,role:`system`,content:i,created_at:new Date().toISOString()}]}var ZN=(0,Q.createContext)(null),QN=0,$N=0,eP={sent:0,received:1,read:2};function tP(e,t){return e&&(!t||eP[e]>=eP[t])?e:t}function nP(e,t){let n=[...e];for(let[e,r]of t.entries()){let i=n.findIndex(e=>e.id===r.id);if(i>=0){let e=tP(n[i].delivery_receipt,r.delivery_receipt);n[i]={...r,...e?{delivery_receipt:e}:{}}}else{let i=new Set(t.slice(e+1).map(e=>e.id)),a=n.findIndex(e=>i.has(e.id));a>=0?n.splice(a,0,r):n.push(r)}}return n}function rP({children:e}){let{registerHandler:t,unregisterHandler:n,connectionStatus:r}=tt(),{uiMode:i}=MN(),{setActiveProjectId:a,activeProjectId:o}=pt(),s=Ci(),c=(0,Q.useRef)(s);c.current=s;let l=hi(),u=e=>e?c.current.isEditable(e):!l,[d,f]=(0,Q.useState)(`hidden`),[p,m]=(0,Q.useState)([]),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)([]),y=(0,Q.useRef)(new Map),b=(0,Q.useRef)(_);b.current=_;let[x,S]=(0,Q.useState)(FN);(0,Q.useEffect)(()=>{let e=e=>{(e.key===PN||e.key===null)&&S(FN())};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]);let[C,w]=(0,Q.useState)(new Set),[T,E]=(0,Q.useState)(new Map),[D,O]=(0,Q.useState)(!0),[k,A]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(null),[N,P]=(0,Q.useState)([]),F=(0,Q.useRef)([]);F.current=N;let I=(0,Q.useRef)(!1),[L,R]=(0,Q.useState)(null),z=(0,Q.useRef)(null);z.current=L;let[B,V]=(0,Q.useState)(`claude`),[H,U]=(0,Q.useState)(null),[W,ee]=(0,Q.useState)(()=>zN()),[te,ne]=(0,Q.useState)(null),re=(0,Q.useRef)({provider:`claude`,model:null,tierLevel:0,effort:null});re.current={provider:B,model:H,tierLevel:W,effort:te};let ie=(0,Q.useRef)(null);ie.current=h?.id??null;let ae=(0,Q.useRef)(T);ae.current=T;let oe=(0,Q.useRef)(new Set),se=(0,Q.useRef)(new Set),ce=(0,Q.useRef)(new Map),le=(0,Q.useRef)(new Map),ue=e=>{let t=tP(e.delivery_receipt,ce.current.get(`${e.conversation_id}:m:${e.id}`));return t?{...e,delivery_receipt:t}:e},de=(e,t)=>{let n=tP(t.deliveryReceipt,ce.current.get(`${e}:q:${t.queueId}`));return n?{...t,deliveryReceipt:n}:t},fe=(0,Q.useRef)(new Set),G=(0,Q.useRef)(new Map),pe=(0,Q.useRef)(new Map),me=(0,Q.useRef)(new Map),he=(0,Q.useRef)(null),ge=(0,Q.useRef)(0),_e=(0,Q.useRef)(0),ve=(0,Q.useRef)(new Map),ye=(0,Q.useCallback)(e=>{let t=ie.current;if(!t)return`untracked`;if(qN(b.current,e))return`stale`;if(!b.current.some(t=>t.role===`system`&&wo(t.content)?.prDeliveryId===e.prDeliveryId))return`untracked`;ge.current++;let n=XN(b.current,t,e);return b.current=n,v(n=>{if(!n.some(t=>t.role===`system`&&wo(t.content)?.prDeliveryId===e.prDeliveryId))return b.current=n,n;let r=XN(n,t,e);return b.current=r,r}),`accepted`},[]),be=(0,Q.useCallback)((e,t)=>{E(n=>{let r=t(n.get(e)??NN),i=new Map(n);return r===null||!r.isStreaming&&!r.streamingText&&r.liveTools.length===0&&r.turnTools.length===0&&r.queued.length===0?i.delete(e):i.set(e,r),i})},[]),Se=(0,Q.useCallback)(e=>{let t=typeof document<`u`&&document.visibilityState===`hidden`;e===ie.current&&!t||w(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),Ce=(0,Q.useCallback)(e=>{w(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]);(0,Q.useEffect)(()=>{if(!xe||typeof document>`u`)return;let e=()=>{if(document.visibilityState!==`visible`)return;let e=ie.current;e&&Ce(e)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[Ce]);let we=(h?T.get(h.id):void 0)??NN,Te=we.streamingText,Ee=we.isStreaming,De=we.liveTools,Oe=we.turnTools,ke=we.queued,Ae=(0,Q.useMemo)(()=>{let e=new Set;for(let[t,n]of T)n.isStreaming&&e.add(t);return e},[T]),je=(0,Q.useCallback)(async()=>{try{let e=await eo();m(e),S(t=>{let n=LN(FN(),e);return n.size===t.size&&[...n].every(e=>t.has(e))?t:(IN(n),n)})}catch{}},[]),Me=(0,Q.useCallback)(async()=>{try{let e=await Ao();O(e.enabled)}catch{O(!1)}},[]),Ne=(0,Q.useCallback)(async()=>{try{let{any:e,installed:t}=await ko();M(e),P(Array.isArray(t)?t:[])}catch{M(!0)}},[]),[Pe,Fe]=(0,Q.useState)(0);(0,Q.useEffect)(()=>xe?(t(`agent-chat`,e=>{let t=e;if(!t)return;if(t.type===`desktop.project_recovered`){Fe(e=>e+1);return}if(typeof t.type!=`string`||!t.type.startsWith(`agent_`))return;if(t.type===`agent_title`&&t.conversationId){let e=t.title??null;m(n=>n.map(n=>n.id===t.conversationId?{...n,title:e}:n)),g(n=>n&&n.id===t.conversationId?{...n,title:e}:n);return}let n=t.conversationId;if(!n)return;G.current.set(n,(G.current.get(n)??0)+1);let r=n===ie.current,i=e=>{me.current.set(n,nP(me.current.get(n)??[],e).slice(-500)),r&&(b.current=nP(b.current,e),v(t=>nP(t,e)))};if(t.type===`agent_input_receipt`){if(t.receipt!==`received`&&t.receipt!==`read`)return;let e=`${n}:q:${t.queueId}`,a=t.messageId??le.current.get(e);if(t.queueId&&ce.current.set(e,tP(ce.current.get(e),t.receipt)),a){let e=`${n}:m:${a}`;ce.current.set(e,tP(ce.current.get(e),t.receipt));let o=(r?b.current:me.current.get(n)??[]).find(e=>e.id===a);o&&i([ue(o)])}be(n,e=>({...e,queued:e.queued.map(e=>e.queueId===t.queueId?{...e,deliveryReceipt:tP(e.deliveryReceipt,t.receipt)}:e)}))}else if(t.type===`agent_stream`)Se(n),be(n,e=>({...e,isStreaming:!0,streamingText:e.streamingText+(t.delta??``)}));else if(t.type===`agent_tool`)be(n,e=>({...e,isStreaming:!0,liveTools:[...e.liveTools,{id:`t${QN++}`,tool:t.tool??`tool`,...t.input?{input:t.input}:{},...t.toolId?{toolId:t.toolId}:{},...t.timestamp?{at:t.timestamp}:{}}].slice(-200)}));else if(t.type===`agent_tool_result`)be(n,e=>{let n=[...e.liveTools],r=t.toolId?n.findIndex(e=>e.toolId===t.toolId):-1;if(r===-1){for(let e=n.length-1;e>=0;e--)if(n[e].output===void 0){r=e;break}}return r===-1?e:(n[r]={...n[r],output:t.output??``,...t.isError?{isError:!0}:{}},{...e,liveTools:n})});else if(t.type===`agent_partial`){let e=t.fullText??``;e&&i([{id:t.messageId??`partial-${n}-${t.timestamp??Date.now()}`,conversation_id:n,role:`assistant`,content:e,created_at:t.timestamp??new Date().toISOString()}])}else if(t.type===`agent_done`){ve.current.delete(n),Se(n);let e=t.fullText??``;t.messageId&&e?i([{id:t.messageId,conversation_id:n,role:`assistant`,content:e,created_at:t.timestamp??new Date().toISOString()}]):r&&e&&v(t=>{let r=t[t.length-1];return r&&r.role===`assistant`&&r.content===e&&!r.id.startsWith(`local-`)?t:[...t,{id:`local-${Date.now()}`,conversation_id:n,role:`assistant`,content:e,created_at:new Date().toISOString()}]}),be(n,e=>({...NN,queued:e.queued,turnTools:e.liveTools.length?e.liveTools:e.turnTools}))}else if(t.type===`agent_error`){ve.current.delete(n),Se(n),be(n,e=>({...NN,queued:e.queued,turnTools:e.liveTools.length?e.liveTools:e.turnTools}));let e=t.error||`The agent turn failed.`;J.error(e),r&&v(t=>[...t,{id:`err-${Date.now()}`,conversation_id:n,role:`assistant`,content:`⚠️ ${e}`,created_at:new Date().toISOString()}])}else if(t.type===`agent_queued`){if(t.queueId&&oe.current.has(t.queueId))return;be(n,e=>{let r=tP(t.deliveryReceipt??t.delivery_receipt,ce.current.get(`${n}:q:${t.queueId}`)),i={queueId:t.queueId??`srv-${$N++}`,text:t.text??``,contextRefs:t.contextRefs,attachmentIds:t.attachmentIds,deliveryMode:t.deliveryMode,...r?{deliveryReceipt:r}:{},timestamp:t.timestamp};return t.queueId&&e.queued.some(e=>e.queueId===t.queueId)?{...e,queued:e.queued.map(e=>e.queueId===t.queueId?{...e,...i,deliveryReceipt:tP(e.deliveryReceipt,i.deliveryReceipt),deliveryMode:e.deliveryMode===`steer`?`steer`:i.deliveryMode??e.deliveryMode,attachmentIds:i.attachmentIds??e.attachmentIds,contextRefs:i.contextRefs??e.contextRefs}:e)}:{...e,queued:[...e.queued,i]}})}else if(t.type===`agent_steered`){if(!t.messageId)return;if(fe.current.has(t.messageId)){t.queueId&&oe.current.add(t.queueId),be(n,e=>({...e,queued:e.queued.filter(e=>e.queueId!==t.queueId)}));return}fe.current.add(t.messageId),t.queueId&&oe.current.add(t.queueId),le.current.set(`${n}:q:${t.queueId}`,t.messageId);let e=tP(t.delivery_receipt??t.deliveryReceipt,ce.current.get(`${n}:q:${t.queueId}`)),r=[];t.assistantSegment&&r.push({...t.assistantSegment,conversation_id:n,role:`assistant`}),r.push(ue({id:t.messageId,conversation_id:n,role:`user`,content:t.text??``,context_refs:t.contextRefs??[],attachment_ids:t.attachmentIds??[],delivery_status:t.deliveryStatus??`delivered`,...e?{delivery_receipt:e}:{},created_at:t.timestamp??new Date().toISOString()})),i(r),be(n,e=>({...e,queued:e.queued.filter(e=>e.queueId!==t.queueId),streamingText:t.assistantSegment?``:e.streamingText}))}else if(t.type===`agent_dequeued`){if(t.queueId&&oe.current.has(t.queueId))return;if(t.queueId&&oe.current.add(t.queueId),be(n,e=>({...e,queued:t.queueId?e.queued.filter(e=>e.queueId!==t.queueId):e.queued.slice(1),isStreaming:!0,streamingText:``,liveTools:[]})),t.text){t.messageId&&le.current.set(`${n}:q:${t.queueId}`,t.messageId);let e=tP(t.delivery_receipt??t.deliveryReceipt,ce.current.get(`${n}:q:${t.queueId}`));i([ue({id:t.messageId??`local-u-${Date.now()}`,conversation_id:n,role:`user`,content:t.text,context_refs:t.contextRefs??[],attachment_ids:t.attachmentIds??[],...t.messageId?{delivery_status:`delivered`}:{},...e?{delivery_receipt:e}:{},created_at:t.timestamp??new Date().toISOString()})])}}else if(t.type===`agent_queue_cleared`)pe.current.set(n,(pe.current.get(n)??0)+1),t.messages?.length&&i(t.messages),be(n,e=>({...e,queued:[]}));else if(t.type===`agent_queue_removed`){if(!t.queueId)return;oe.current.add(t.queueId),se.current.add(t.queueId),be(n,e=>({...e,queued:e.queued.filter(e=>e.queueId!==t.queueId)}))}else if(t.type===`agent_queue_edited`)be(n,e=>({...e,queued:e.queued.map(e=>t.queueId&&e.queueId===t.queueId?{...e,text:t.text??e.text,contextRefs:t.contextRefs??e.contextRefs,deliveryMode:t.deliveryMode??e.deliveryMode}:e)}));else if(t.type===`agent_run_failure`){if(Se(n),r){let{type:e,conversationId:r,messageId:i,timestamp:a,...o}=t;if(typeof i==`string`&&!b.current.some(e=>e.id===i)){let e={id:i,conversation_id:n,role:`system`,content:JSON.stringify(o),created_at:typeof a==`string`?a:new Date().toISOString()};b.current=[...b.current,e],v(t=>t.some(e=>e.id===i)?t:[...t,e])}}}else if(t.type===`agent_pr_decision`&&(Se(n),r)){let t=Co(e);if(t){ge.current++;let e=XN(b.current,n,t);b.current=e,v(e=>{let r=XN(e,n,t);return b.current=r,r})}}}),()=>n(`agent-chat`)):void 0,[t,n,be,Se]);let Ie=(0,Q.useCallback)(async(e,t)=>{let n=++_e.current,r=G.current.get(e)??0;ge.current++;let{conversation:i,messages:a,pendingMessages:o,live:s}=await io(e);if(t?.aborted)throw new DOMException(`Window transfer cancelled`,`AbortError`);if(n!==_e.current){if(t)throw new DOMException(`The mission changed during restoration`,`AbortError`);return}ge.current++;let c=nP(a,me.current.get(e)??[]).map(ue);for(let e of c)(e.delivery_status===`delivered`||e.delivery_status===`interrupted`)&&fe.current.add(e.id);g(i),b.current=c,v(c),Ce(e),r===(G.current.get(e)??0)&&(o!==void 0||s)&&be(e,t=>({...t,...s?{isStreaming:s.isStreaming,streamingText:s.streamingText}:{},queued:o?.filter(e=>!oe.current.has(e.queueId)).map(t=>de(e,t))??t.queued}))},[Ce,be]),Le=(0,Q.useCallback)(async()=>{let e=ie.current;if(!e)return;let t=ge.current,n=G.current.get(e)??0,r=y.current.get(e)??0;try{let i=await io(e);if(ie.current!==e||ge.current!==t)return;if(r===(y.current.get(e)??0)&&(g(t=>t?.id===e?i.conversation:t),m(t=>t.map(t=>t.id===e?i.conversation:t))),(i.pendingMessages!==void 0||i.live)&&n===(G.current.get(e)??0)){let t=nP(i.messages,me.current.get(e)??[]).map(ue);for(let e of t)(e.delivery_status===`delivered`||e.delivery_status===`interrupted`)&&fe.current.add(e.id);v(e=>nP(t,e.filter(e=>e.id.startsWith(`local-u-`)&&!t.some(t=>t.role===`user`&&t.content===e.content)))),be(e,t=>({...t,...i.live?{isStreaming:i.live.isStreaming,streamingText:i.live.streamingText}:{},queued:i.pendingMessages?.filter(e=>!oe.current.has(e.queueId)).map(t=>de(e,t))??t.queued}))}let a=i.messages.filter(e=>e.role===`system`).map(e=>wo(e.content)).filter(e=>e!==null);if(a.length===0)return;v(t=>{let n=a.reduce((t,n)=>XN(t,e,n),t);return b.current=n,n})}catch{}},[be]),Re=(0,Q.useCallback)(async()=>{try{let e=new Map(G.current),t=await no(),n=new Set(t.turns.map(e=>e.conversationId)),r=Date.parse(t.capturedAt),i=[...ae.current].flatMap(([t,i])=>{if(!i.isStreaming||n.has(t)||(e.get(t)??0)!==(G.current.get(t)??0))return[];let a=ve.current.get(t);return a&&Date.parse(a)>r?[]:[t]});E(i=>{let a=new Map(i);for(let[t,o]of i){if(!o.isStreaming||n.has(t)||(e.get(t)??0)!==(G.current.get(t)??0))continue;let i=ve.current.get(t);i&&Date.parse(i)>r||a.set(t,{...NN,queued:o.queued,turnTools:o.liveTools.length?o.liveTools:o.turnTools})}for(let n of t.turns){let t=n.conversationId;if((e.get(t)??0)!==(G.current.get(t)??0))continue;let r=a.get(t)??NN;a.set(t,{...r,isStreaming:!0,streamingText:n.streamingText??r.streamingText,queued:n.pendingMessages?.filter(e=>!oe.current.has(e.queueId)).map(e=>de(t,e))??r.queued})}return a});for(let e of i)ve.current.delete(e);let a=ie.current;if(a&&i.includes(a)){let e=`interrupted-${a}-${t.snapshotVersion}`;v(n=>n.some(t=>t.id===e)?n:[...n,{id:e,conversation_id:a,role:`assistant`,content:`⚠️ The agent turn was interrupted when the Specrails server reconnected. It was not retried.`,created_at:t.capturedAt}])}console.info(`[agent-chat] reconciled active turns`,{snapshotVersion:t.snapshotVersion,active:n.size,interrupted:i.length})}catch{}},[]);(0,Q.useEffect)(()=>{let e=()=>{je(),Le()};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[Le,je]),(0,Q.useEffect)(()=>{Pe&&(je(),Le())},[Pe,je,Le]);let ze=(0,Q.useRef)(r);(0,Q.useEffect)(()=>{let e=ze.current;ze.current=r,r===`connected`&&e!==`connected`&&(je(),Me(),Ne(),Le(),Re())},[r,je,Me,Ne,Le,Re]);let Be=(0,Q.useCallback)(async()=>{if(h)return h;if(l)throw Error(`This window is reserved for its mission.`);let e=await eo();if(m(e),S(t=>{let n=LN(FN(),e);return n.size===t.size&&[...n].every(e=>t.has(e))?t:(IN(n),n)}),e.length>0)return await Ie(e[0].id),e[0];let t=await ro({});return m(e=>[t,...e]),g(t),v([]),t},[h,Ie]),Ve=(0,Q.useCallback)(()=>{f(`open`),je(),Me(),Ne(),Be()},[je,Me,Ne,Be]),He=(0,Q.useCallback)(()=>f(`hidden`),[]),Ue=(0,Q.useCallback)(()=>f(`minimized`),[]),[We,Ge]=(0,Q.useState)(!1),Ke=(0,Q.useRef)(null),qe=(0,Q.useCallback)(()=>{Ke.current?.abortAndReset(),Ge(!1)},[]),Je=JM(We,{onFinished:qe});Ke.current=Je;let Ye=(0,Q.useCallback)(()=>{l||(Ge(!0),i!==`agent`&&Ve())},[i,Ve]),Xe=(0,Q.useCallback)(()=>{f(e=>e===`open`?`minimized`:`open`),d!==`open`&&(je(),Me(),Ne(),Be())},[d,je,Me,Ne,Be]),Ze=(0,Q.useCallback)(async()=>{if(!u(h?.id))throw Error(`This mission is active in another window.`);if(h)return h;if(he.current)return he.current;let e=ro({pinnedProjectId:z.current,provider:re.current.provider,model:re.current.model,tierLevel:re.current.tierLevel,reasoningEffort:re.current.effort}).then(e=>(pi(e.id),m(t=>[e,...t]),g(e),v([]),e)).finally(()=>{he.current=null});return he.current=e,e},[h]),Qe=(0,Q.useCallback)(async(e,t)=>{if(!u(h?.id))return{accepted:!1};let n=e.trim();if(!n)return{accepted:!1};let r=h??await Ze();G.current.set(r.id,(G.current.get(r.id)??0)+1);let i=G.current.get(r.id),a=pe.current.get(r.id)??0,o=t?.queueId??`q-${Date.now()}-${$N++}`,s=new Date().toISOString();ve.current.set(r.id,s),m(e=>[{...e.find(e=>e.id===r.id)??r,updated_at:s},...e.filter(e=>e.id!==r.id)]),g(e=>e&&e.id===r.id?{...e,updated_at:s}:e);let c={id:`local-u-${Date.now()}`,conversation_id:r.id,role:`user`,content:n,attachment_ids:t?.attachmentIds??[],context_refs:t?.contextRefs??[],delivery_receipt:`sent`,created_at:s},l=ae.current.get(r.id)?.isStreaming===!0,d={queueId:o,text:n,contextRefs:t?.contextRefs,attachmentIds:t?.attachmentIds,deliveryMode:`queue`,deliveryReceipt:`sent`,timestamp:s};l?be(r.id,e=>({...e,queued:e.queued.some(e=>e.queueId===o)?e.queued.map(e=>e.queueId===o?{...d,deliveryReceipt:tP(e.deliveryReceipt,d.deliveryReceipt),deliveryMode:e.deliveryMode??d.deliveryMode,timestamp:e.timestamp??d.timestamp}:e):[...e.queued,d]})):(v(e=>[...e,c]),be(r.id,e=>({...e,isStreaming:!0,streamingText:``,liveTools:[]})));let f=t?.attachmentIds&&t.attachmentIds.length?{ids:t.attachmentIds}:void 0;try{let e=t?.contextRefs&&t.contextRefs.length?t.contextRefs:void 0,s=await so(r.id,n,{tierLevel:r.tier_level,attachments:f,queueId:o,contextRefs:e});if(s.removed){oe.current.add(o),se.current.add(o);let e=!l&&i===G.current.get(r.id);return ie.current===r.id&&v(e=>e.filter(e=>e.id!==c.id)),be(r.id,t=>({...t,queued:t.queued.filter(e=>e.queueId!==o),...e?{isStreaming:!1}:{}})),e&&ve.current.delete(r.id),{accepted:!0,conversationId:r.id}}if(s.message){le.current.set(`${r.id}:q:${o}`,s.message.id);let e=tP(s.message.delivery_receipt,ce.current.get(`${r.id}:q:${o}`)),t=ue({...s.message,...e?{delivery_receipt:e}:{}});return oe.current.add(o),me.current.set(r.id,nP(me.current.get(r.id)??[],[t]).slice(-500)),ie.current===r.id&&v(e=>nP(e.filter(e=>e.id!==c.id),[t])),be(r.id,e=>({...e,queued:e.queued.filter(e=>e.queueId!==o)})),s.duplicate&&Re(),{accepted:!0,conversationId:r.id}}if(a!==(pe.current.get(r.id)??0))return v(e=>e.filter(e=>e.id!==c.id)),{accepted:!0,conversationId:r.id};let u=s?.queued===!0;return u&&!l?(v(e=>e.filter(e=>e.id!==c.id)),oe.current.has(o)||be(r.id,e=>e.queued.some(e=>e.queueId===o)?e:{...e,queued:[...e.queued,{...d,deliveryMode:s.deliveryMode??d.deliveryMode}]})):!u&&l&&!oe.current.has(o)&&(be(r.id,e=>({...e,queued:e.queued.filter(e=>e.queueId!==o),isStreaming:!0})),v(e=>[...e,c])),{accepted:!0,conversationId:r.id}}catch(e){return oe.current.has(o)||a!==(pe.current.get(r.id)??0)?{accepted:!0,conversationId:r.id}:(ve.current.delete(r.id),l?be(r.id,e=>({...e,queued:e.queued.filter(e=>e.queueId!==o)})):(be(r.id,e=>({...e,isStreaming:!1,streamingText:``,liveTools:[]})),v(e=>e.filter(e=>e.id!==c.id))),J.error(e instanceof Error?e.message:`Failed to send message.`),{accepted:!1,conversationId:r.id})}},[h,Ze,be,Re]),$e=(0,Q.useCallback)(async()=>{if(!(!h||!u(h.id)))try{await mo(h.id),pe.current.set(h.id,(pe.current.get(h.id)??0)+1),G.current.set(h.id,(G.current.get(h.id)??0)+1),be(h.id,()=>null)}catch(e){J.error(e instanceof Error?e.message:`Failed to stop the agent.`)}},[h,be]),et=(0,Q.useCallback)(async(e,t)=>{let n=h;if(!n||!u(n.id)||ae.current.get(n.id)?.queued.find(t=>t.queueId===e)?.deliveryMode===`steer`)return`conflict`;let r=await ho(n.id,e,t);return r===`saved`&&be(n.id,n=>({...n,queued:n.queued.map(n=>n.queueId===e?{...n,text:t}:n)})),r},[h,be]),nt=(0,Q.useCallback)(async e=>{let t=h,n=t&&ae.current.get(t.id)?.queued.find(t=>t.queueId===e);if(!t||!u(t.id)||!n||n.deliveryMode===`steer`)return`conflict`;let r=await go(t.id,e);return r===`saved`?(G.current.set(t.id,(G.current.get(t.id)??0)+1),be(t.id,t=>({...t,queued:t.queued.map(t=>t.queueId===e?{...t,deliveryMode:`steer`}:t)}))):ie.current===t.id&&Le(),r},[h,be,Le]),rt=(0,Q.useCallback)(async e=>{let t=h,n=t&&ae.current.get(t.id)?.queued.find(t=>t.queueId===e);if(!t||!u(t.id)||!n||n.deliveryMode===`steer`)return`conflict`;let r=await _o(t.id,e);return r===`saved`?(oe.current.add(e),se.current.add(e),G.current.set(t.id,(G.current.get(t.id)??0)+1),be(t.id,t=>({...t,queued:t.queued.filter(t=>t.queueId!==e)}))):ie.current===t.id&&Le(),r},[h,be,Le]),it=(0,Q.useCallback)(e=>oe.current.has(e)&&!se.current.has(e),[]),at=(0,Q.useCallback)(async e=>{if(!h||!u(h.id))return;let t=(y.current.get(h.id)??0)+1;y.current.set(h.id,t);let n=await ao(h.id,e);y.current.get(h.id)===t&&(g(e=>e?.id===n.id?n:e),m(e=>e.map(e=>e.id===n.id?n:e)))},[h]),ot=(0,Q.useCallback)(async e=>{u(h?.id)&&(BN(e),h?await at({tierLevel:e}):ee(e))},[h,at]),st=(0,Q.useCallback)(async()=>{let e=((h?.tier_level??W)+1)%4;await ot(e)},[h,W,ot]),ct=(0,Q.useCallback)(async e=>{h?await at({provider:e}):(I.current=!0,V(e),U(null),ne(null))},[h,at]);(0,Q.useEffect)(()=>{h||I.current||N.length===0||N.includes(B)||(V(Ot(N)),U(null),ne(null))},[h,N,B]);let lt=(0,Q.useCallback)(async e=>{h?await at({model:e}):(U(e),ne(null))},[h,at]),K=(0,Q.useCallback)(async e=>{h?await at({reasoningEffort:e}):ne(e)},[h,at]),q=(0,Q.useCallback)(async e=>{l||!u(h?.id)||(h?await at({pinnedProjectId:e}):R(e),!h&&e&&i===`agent`&&a(e))},[h,at,i,a]),ut=(0,Q.useRef)(void 0);(0,Q.useEffect)(()=>{let e=ut.current;if(ut.current=o,!(e===void 0||e===o)&&!(l||i!==`agent`||!o)){if(!h){R(o);return}b.current.length>0||h.pinned_project_id!==o&&at({pinnedProjectId:o})}},[o,i,h,at]);let dt=(0,Q.useCallback)(e=>{l||(qe(),g(null),v([]),R(e??null),I.current=!1,V(Ot(F.current)),U(null),ee(zN()),ne(null))},[qe]),ft=(0,Q.useCallback)(async e=>{if(l)return;qe();let t=await ro({pinnedProjectId:e===void 0?h?.pinned_project_id??null:e,tierLevel:zN()});m(e=>[t,...e]),g(t),v([])},[h,qe]),mt=(0,Q.useCallback)(async(e,t)=>{if(!(l&&!t?.windowRestore&&c.current.current?.conversationId!==e)&&!(!l&&!t?.windowRestore&&await c.current.focus(e))){if(t?.signal?.aborted)throw new DOMException(`Window transfer cancelled`,`AbortError`);qe(),await Ie(e,t?.signal),t?.windowRestore&&i!==`agent`&&f(`open`)}},[Ie,qe,l,i]),Y=(0,Q.useCallback)(async e=>{u(e)&&(await oo(e),await c.current.discard(e),m(t=>t.filter(t=>t.id!==e)),S(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),IN(n),n}),be(e,()=>null),ie.current===e&&(g(null),v([])))},[be]),ht=(0,Q.useCallback)(async(e,t)=>{if(!u(e))return;let n=t.trim()||null;y.current.set(e,(y.current.get(e)??0)+1);let r;m(t=>t.map(t=>t.id===e?(r=t.title,{...t,title:n}):t)),g(t=>t&&t.id===e?{...t,title:n}:t);try{await ao(e,{title:n})}catch(t){throw m(t=>t.map(t=>t.id===e?{...t,title:r??null}:t)),g(t=>t&&t.id===e?{...t,title:r??null}:t),t}},[]),gt=(0,Q.useCallback)(e=>{S(()=>{let t=new Set(FN());return t.has(e)?t.delete(e):t.add(e),IN(t),t})},[]),_t=(0,Q.useCallback)(async()=>{A(!0);try{await jo(),await Me()}catch(e){J.error(e instanceof Error?e.message:`Failed to enable MCP.`)}finally{A(!1)}},[Me]),vt=(0,Q.useMemo)(()=>({visibility:d,open:Ve,close:He,minimize:Ue,toggle:Xe,conversations:p,active:h,messages:_,streamingText:Te,isStreaming:Ee,liveTools:De,turnTools:Oe,queuedMessages:ke,streamingConversationIds:Ae,liveByConversation:T,unreadConversationIds:C,favoriteConversationIds:x,mcpEnabled:D,enablingMcp:k,enableMcpServer:_t,providersReady:j,send:Qe,abort:$e,editQueuedMessage:et,steerQueuedMessage:nt,removeQueuedMessage:rt,wasQueueConsumed:it,cycleTier:st,setTier:ot,setProvider:ct,setModel:lt,setPinnedProject:q,newConversation:ft,startNewConversation:dt,materializeDraftConversation:Ze,draftPinnedProjectId:L,draftProvider:B,draftModel:H,draftTierLevel:W,draftEffort:te,setEffort:K,selectConversation:mt,deleteConversation:Y,renameConversation:ht,toggleFavoriteConversation:gt,refreshConversations:je,applyPrDecisionSnapshot:ye,builderMode:{active:We,enter:Ye,exit:qe,session:Je}}),[d,Ve,He,Ue,Xe,We,Ye,qe,Je,p,h,_,Te,Ee,De,Oe,ke,Ae,T,C,x,D,k,_t,j,Qe,$e,et,nt,rt,it,st,ot,ct,lt,q,ft,dt,Ze,L,B,H,W,te,K,mt,Y,ht,gt,je,ye]),yt=xe&&i!==`agent`;return(0,$.jsxs)(ZN.Provider,{value:vt,children:[e,yt&&d===`open`&&(0,$.jsx)(vN,{}),yt&&d!==`open`&&(0,$.jsx)(TN,{})]})}var iP={visibility:`hidden`,open:()=>{},close:()=>{},minimize:()=>{},toggle:()=>{},conversations:[],active:null,messages:[],streamingText:``,isStreaming:!1,liveTools:[],turnTools:[],queuedMessages:[],streamingConversationIds:new Set,unreadConversationIds:new Set,liveByConversation:new Map,favoriteConversationIds:new Set,mcpEnabled:!0,enablingMcp:!1,enableMcpServer:async()=>{},providersReady:!0,send:async()=>({accepted:!1}),abort:async()=>{},editQueuedMessage:async()=>`conflict`,steerQueuedMessage:async()=>`conflict`,removeQueuedMessage:async()=>`conflict`,wasQueueConsumed:()=>!1,cycleTier:async()=>{},setTier:async()=>{},setProvider:async()=>{},setModel:async()=>{},setPinnedProject:async()=>{},newConversation:async()=>{},startNewConversation:()=>{},materializeDraftConversation:async()=>{throw Error(`AgentChatProvider is not mounted`)},draftPinnedProjectId:null,draftProvider:`claude`,draftModel:null,draftTierLevel:0,draftEffort:null,setEffort:async()=>{},selectConversation:async()=>{},deleteConversation:async()=>{},renameConversation:async()=>{},toggleFavoriteConversation:()=>{},refreshConversations:async()=>{},applyPrDecisionSnapshot:()=>`untracked`,builderMode:{active:!1,enter:()=>{},exit:()=>{},session:{phase:`chat`,messages:[],streamBuffer:null,blueprint:null,busy:!1,commitError:null,commitErrorDetail:null,commitSteps:[],createdProjectId:null,launching:!1,launched:!1,submitting:!1,conversationReady:!1,conversationId:null,dirty:!1,canProposeCommit:!1,specQualityDetail:null,readiness:{ready:!1,steps:[],issues:[]},snapshot:{status:`idle`},generation:{generating:!1,specsStarted:0},recent:[],recentLoading:!1,resume:async()=>{},discardRecent:async()=>{},repairSnapshot:async()=>{},showSurpriseMe:!0,provider:`claude`,model:null,models:[],efforts:[],effort:`medium`,draft:``,setDraft:()=>{},setEffort:()=>{},setProvider:()=>{},setModel:()=>{},send:()=>{},surpriseMe:()=>{},approveBlueprint:()=>{},goToCommit:()=>{},backToChat:()=>{},submitCommit:()=>{},launchM1:async()=>{},openProject:()=>{},abortAndReset:()=>{}}}};function aP(){return(0,Q.useContext)(ZN)??iP}var oP=new Map;function sP(){let e=aP(),t=lO(),n=pt(),r=za(),{registerHandlers:i}=Ci(),{t:a}=K(`agent`),o=(0,Q.useRef)({chat:e,workspace:t,desktop:n,terminals:r,t:a});o.current={chat:e,workspace:t,desktop:n,terminals:r,t:a};let s=(0,Q.useRef)(null),c=(0,Q.useRef)(!1);(0,Q.useLayoutEffect)(()=>{let n=e.active?.id??`__new-mission__`,r=s.current;if(c.current||r===n)return;s.current=n,r&&oP.set(r,t.captureWorkspace());let i=oP.get(n);i?t.restoreWorkspace(i):r&&t.restoreWorkspace({...t.captureWorkspace(),browserOpen:!1,browserOwnerId:null,browserUrl:null,pendingCaptures:[]})},[e.active?.id]);let[l,u]=(0,Q.useState)(null);return(0,Q.useLayoutEffect)(()=>{l&&!l.signal.aborted&&e.active?.id===l.target.conversationId&&n.activeProjectId===l.target.projectId&&(l.resolve(),u(e=>e===l?null:e))},[l,e.active?.id,n.activeProjectId]),(0,Q.useEffect)(()=>i({recover(e,t){Uy(t.conversationId,e.scroll)},capture(e){let{chat:t,workspace:n,terminals:r,t:i}=o.current;if(t.active?.id!==e.conversationId)throw Error(i(`window.wrongMission`));if(Ky(e.conversationId))throw Error(i(`window.finishPending`));return{version:1,...e,capturedAt:Date.now(),composer:si(e.conversationId),scroll:Hy(e.conversationId),workspace:{...n.captureWorkspace(),...e.projectId?{codeSelection:Fy(e.projectId,e.conversationId),terminal:(({activeId:e,visibility:t,userHeight:n})=>({activeId:e,visibility:t,userHeight:n}))(r.getState(e.projectId))}:{}}}},async restore(e,t,n){let r=()=>new DOMException(`Window transfer cancelled`,`AbortError`);if(n.aborted)throw r();let i=o.current.chat.active?.id;i&&oP.set(i,o.current.workspace.captureWorkspace()),c.current=!0;try{if(await o.current.chat.selectConversation(t.conversationId,{windowRestore:!0,signal:n}),n.aborted)throw r();if(s.current=t.conversationId,oP.set(t.conversationId,e.workspace),li(t.conversationId,e.composer),t.projectId&&(e.workspace.codeSelection&&Iy(t.projectId,t.conversationId,e.workspace.codeSelection),e.workspace.terminal)){let n=e.workspace.terminal,r=o.current.terminals;r.ensureProject(t.projectId),r.setVisibility(t.projectId,n.visibility),r.setUserHeight(t.projectId,n.userHeight),n.activeId&&r.setActive(t.projectId,n.activeId)}o.current.workspace.restoreWorkspace(e.workspace),o.current.desktop.setActiveProjectId(t.projectId),Uy(t.conversationId,e.scroll),await new Promise((e,i)=>{let a=()=>{u(e=>e?.signal===n?null:e),i(r())};n.addEventListener(`abort`,a,{once:!0}),u({target:t,signal:n,resolve:()=>{n.removeEventListener(`abort`,a),e()}})})}finally{c.current=!1}}}),[i]),null}var cP=class{constructor(...e){this.type=`Logical`,e.length===1?`Logical`in e[0]?(this.width=e[0].Logical.width,this.height=e[0].Logical.height):(this.width=e[0].width,this.height=e[0].height):(this.width=e[0],this.height=e[1])}toPhysical(e){return new lP(this.width*e,this.height*e)}[gt](){return{width:this.width,height:this.height}}toJSON(){return this[gt]()}},lP=class{constructor(...e){this.type=`Physical`,e.length===1?`Physical`in e[0]?(this.width=e[0].Physical.width,this.height=e[0].Physical.height):(this.width=e[0].width,this.height=e[0].height):(this.width=e[0],this.height=e[1])}toLogical(e){return new cP(this.width/e,this.height/e)}[gt](){return{width:this.width,height:this.height}}toJSON(){return this[gt]()}},uP=class{constructor(e){this.size=e}toLogical(e){return this.size instanceof cP?this.size:this.size.toLogical(e)}toPhysical(e){return this.size instanceof lP?this.size:this.size.toPhysical(e)}[gt](){return{[`${this.size.type}`]:{width:this.size.width,height:this.size.height}}}toJSON(){return this[gt]()}},dP=class{constructor(...e){this.type=`Logical`,e.length===1?`Logical`in e[0]?(this.x=e[0].Logical.x,this.y=e[0].Logical.y):(this.x=e[0].x,this.y=e[0].y):(this.x=e[0],this.y=e[1])}toPhysical(e){return new fP(this.x*e,this.y*e)}[gt](){return{x:this.x,y:this.y}}toJSON(){return this[gt]()}},fP=class{constructor(...e){this.type=`Physical`,e.length===1?`Physical`in e[0]?(this.x=e[0].Physical.x,this.y=e[0].Physical.y):(this.x=e[0].x,this.y=e[0].y):(this.x=e[0],this.y=e[1])}toLogical(e){return new dP(this.x/e,this.y/e)}[gt](){return{x:this.x,y:this.y}}toJSON(){return this[gt]()}},pP=class{constructor(e){this.position=e}toLogical(e){return this.position instanceof dP?this.position:this.position.toLogical(e)}toPhysical(e){return this.position instanceof fP?this.position:this.position.toPhysical(e)}[gt](){return{[`${this.position.type}`]:{x:this.position.x,y:this.position.y}}}toJSON(){return this[gt]()}},mP;(function(e){e[e.Critical=1]=`Critical`,e[e.Informational=2]=`Informational`})(mP||={});var hP=class{constructor(e){this._preventDefault=!1,this.event=e.event,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}},gP;(function(e){e.None=`none`,e.Normal=`normal`,e.Indeterminate=`indeterminate`,e.Paused=`paused`,e.Error=`error`})(gP||={});function _P(){return new bP(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}async function vP(){return Y(`plugin:window|get_all_windows`).then(e=>e.map(e=>new bP(e,{skip:!0})))}var yP=[`tauri://created`,`tauri://error`],bP=class{constructor(e,t={}){this.label=e,this.listeners=Object.create(null),t?.skip||Y(`plugin:window|create`,{options:{...t,parent:typeof t.parent==`string`?t.parent:t.parent?.label,label:e}}).then(async()=>this.emit(`tauri://created`)).catch(async e=>this.emit(`tauri://error`,e))}static async getByLabel(e){return(await vP()).find(t=>t.label===e)??null}static getCurrent(){return _P()}static async getAll(){return vP()}static async getFocusedWindow(){for(let e of await vP())if(await e.isFocused())return e;return null}async listen(e,t){return this._handleTauriEvent(e,t)?()=>{let n=this.listeners[e];n.splice(n.indexOf(t),1)}:Ar(e,t,{target:{kind:`Window`,label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?()=>{let n=this.listeners[e];n.splice(n.indexOf(t),1)}:Mr(e,t,{target:{kind:`Window`,label:this.label}})}async emit(e,t){if(yP.includes(e)){for(let n of this.listeners[e]||[])n({event:e,id:-1,payload:t});return}return jr(e,t)}async emitTo(e,t,n){if(yP.includes(t)){for(let e of this.listeners[t]||[])e({event:t,id:-1,payload:n});return}return Nr(e,t,n)}_handleTauriEvent(e,t){return yP.includes(e)?(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0):!1}async scaleFactor(){return Y(`plugin:window|scale_factor`,{label:this.label})}async innerPosition(){return Y(`plugin:window|inner_position`,{label:this.label}).then(e=>new fP(e))}async outerPosition(){return Y(`plugin:window|outer_position`,{label:this.label}).then(e=>new fP(e))}async innerSize(){return Y(`plugin:window|inner_size`,{label:this.label}).then(e=>new lP(e))}async outerSize(){return Y(`plugin:window|outer_size`,{label:this.label}).then(e=>new lP(e))}async isFullscreen(){return Y(`plugin:window|is_fullscreen`,{label:this.label})}async isMinimized(){return Y(`plugin:window|is_minimized`,{label:this.label})}async isMaximized(){return Y(`plugin:window|is_maximized`,{label:this.label})}async isFocused(){return Y(`plugin:window|is_focused`,{label:this.label})}async isDecorated(){return Y(`plugin:window|is_decorated`,{label:this.label})}async isResizable(){return Y(`plugin:window|is_resizable`,{label:this.label})}async isMaximizable(){return Y(`plugin:window|is_maximizable`,{label:this.label})}async isMinimizable(){return Y(`plugin:window|is_minimizable`,{label:this.label})}async isClosable(){return Y(`plugin:window|is_closable`,{label:this.label})}async isVisible(){return Y(`plugin:window|is_visible`,{label:this.label})}async title(){return Y(`plugin:window|title`,{label:this.label})}async theme(){return Y(`plugin:window|theme`,{label:this.label})}async isAlwaysOnTop(){return Y(`plugin:window|is_always_on_top`,{label:this.label})}async center(){return Y(`plugin:window|center`,{label:this.label})}async requestUserAttention(e){let t=null;return e&&(t=e===mP.Critical?{type:`Critical`}:{type:`Informational`}),Y(`plugin:window|request_user_attention`,{label:this.label,value:t})}async setResizable(e){return Y(`plugin:window|set_resizable`,{label:this.label,value:e})}async setEnabled(e){return Y(`plugin:window|set_enabled`,{label:this.label,value:e})}async isEnabled(){return Y(`plugin:window|is_enabled`,{label:this.label})}async setMaximizable(e){return Y(`plugin:window|set_maximizable`,{label:this.label,value:e})}async setMinimizable(e){return Y(`plugin:window|set_minimizable`,{label:this.label,value:e})}async setClosable(e){return Y(`plugin:window|set_closable`,{label:this.label,value:e})}async setTitle(e){return Y(`plugin:window|set_title`,{label:this.label,value:e})}async maximize(){return Y(`plugin:window|maximize`,{label:this.label})}async unmaximize(){return Y(`plugin:window|unmaximize`,{label:this.label})}async toggleMaximize(){return Y(`plugin:window|toggle_maximize`,{label:this.label})}async minimize(){return Y(`plugin:window|minimize`,{label:this.label})}async unminimize(){return Y(`plugin:window|unminimize`,{label:this.label})}async show(){return Y(`plugin:window|show`,{label:this.label})}async hide(){return Y(`plugin:window|hide`,{label:this.label})}async close(){return Y(`plugin:window|close`,{label:this.label})}async destroy(){return Y(`plugin:window|destroy`,{label:this.label})}async setDecorations(e){return Y(`plugin:window|set_decorations`,{label:this.label,value:e})}async setShadow(e){return Y(`plugin:window|set_shadow`,{label:this.label,value:e})}async setEffects(e){return Y(`plugin:window|set_effects`,{label:this.label,value:e})}async clearEffects(){return Y(`plugin:window|set_effects`,{label:this.label,value:null})}async setAlwaysOnTop(e){return Y(`plugin:window|set_always_on_top`,{label:this.label,value:e})}async setAlwaysOnBottom(e){return Y(`plugin:window|set_always_on_bottom`,{label:this.label,value:e})}async setContentProtected(e){return Y(`plugin:window|set_content_protected`,{label:this.label,value:e})}async setSize(e){return Y(`plugin:window|set_size`,{label:this.label,value:e instanceof uP?e:new uP(e)})}async setMinSize(e){return Y(`plugin:window|set_min_size`,{label:this.label,value:e instanceof uP?e:e?new uP(e):null})}async setMaxSize(e){return Y(`plugin:window|set_max_size`,{label:this.label,value:e instanceof uP?e:e?new uP(e):null})}async setSizeConstraints(e){function t(e){return e?{Logical:e}:null}return Y(`plugin:window|set_size_constraints`,{label:this.label,value:{minWidth:t(e?.minWidth),minHeight:t(e?.minHeight),maxWidth:t(e?.maxWidth),maxHeight:t(e?.maxHeight)}})}async setPosition(e){return Y(`plugin:window|set_position`,{label:this.label,value:e instanceof pP?e:new pP(e)})}async setFullscreen(e){return Y(`plugin:window|set_fullscreen`,{label:this.label,value:e})}async setSimpleFullscreen(e){return Y(`plugin:window|set_simple_fullscreen`,{label:this.label,value:e})}async setFocus(){return Y(`plugin:window|set_focus`,{label:this.label})}async setFocusable(e){return Y(`plugin:window|set_focusable`,{label:this.label,value:e})}async setIcon(e){return Y(`plugin:window|set_icon`,{label:this.label,value:Ea(e)})}async setSkipTaskbar(e){return Y(`plugin:window|set_skip_taskbar`,{label:this.label,value:e})}async setCursorGrab(e){return Y(`plugin:window|set_cursor_grab`,{label:this.label,value:e})}async setCursorVisible(e){return Y(`plugin:window|set_cursor_visible`,{label:this.label,value:e})}async setCursorIcon(e){return Y(`plugin:window|set_cursor_icon`,{label:this.label,value:e})}async setBackgroundColor(e){return Y(`plugin:window|set_background_color`,{color:e})}async setCursorPosition(e){return Y(`plugin:window|set_cursor_position`,{label:this.label,value:e instanceof pP?e:new pP(e)})}async setIgnoreCursorEvents(e){return Y(`plugin:window|set_ignore_cursor_events`,{label:this.label,value:e})}async startDragging(){return Y(`plugin:window|start_dragging`,{label:this.label})}async startResizeDragging(e){return Y(`plugin:window|start_resize_dragging`,{label:this.label,value:e})}async setBadgeCount(e){return Y(`plugin:window|set_badge_count`,{label:this.label,value:e})}async setBadgeLabel(e){return Y(`plugin:window|set_badge_label`,{label:this.label,value:e})}async setOverlayIcon(e){return Y(`plugin:window|set_overlay_icon`,{label:this.label,value:e?Ea(e):void 0})}async setProgressBar(e){return Y(`plugin:window|set_progress_bar`,{label:this.label,value:e})}async setVisibleOnAllWorkspaces(e){return Y(`plugin:window|set_visible_on_all_workspaces`,{label:this.label,value:e})}async setTitleBarStyle(e){return Y(`plugin:window|set_title_bar_style`,{label:this.label,value:e})}async setTheme(e){return Y(`plugin:window|set_theme`,{label:this.label,value:e})}async onResized(e){return this.listen(Pr.WINDOW_RESIZED,t=>{t.payload=new lP(t.payload),e(t)})}async onMoved(e){return this.listen(Pr.WINDOW_MOVED,t=>{t.payload=new fP(t.payload),e(t)})}async onCloseRequested(e){return this.listen(Pr.WINDOW_CLOSE_REQUESTED,async t=>{let n=new hP(t);await e(n),n.isPreventDefault()||await this.destroy()})}async onDragDropEvent(e){let t=await this.listen(Pr.DRAG_ENTER,t=>{e({...t,payload:{type:`enter`,paths:t.payload.paths,position:new fP(t.payload.position)}})}),n=await this.listen(Pr.DRAG_OVER,t=>{e({...t,payload:{type:`over`,position:new fP(t.payload.position)}})}),r=await this.listen(Pr.DRAG_DROP,t=>{e({...t,payload:{type:`drop`,paths:t.payload.paths,position:new fP(t.payload.position)}})}),i=await this.listen(Pr.DRAG_LEAVE,t=>{e({...t,payload:{type:`leave`}})});return()=>{t(),r(),n(),i()}}async onFocusChanged(e){let t=await this.listen(Pr.WINDOW_FOCUS,t=>{e({...t,payload:!0})}),n=await this.listen(Pr.WINDOW_BLUR,t=>{e({...t,payload:!1})});return()=>{t(),n()}}async onScaleChanged(e){return this.listen(Pr.WINDOW_SCALE_FACTOR_CHANGED,e)}async onThemeChanged(e){return this.listen(Pr.WINDOW_THEME_CHANGED,e)}},xP;(function(e){e.Disabled=`disabled`,e.Throttle=`throttle`,e.Suspend=`suspend`})(xP||={});var SP;(function(e){e.Default=`default`,e.FluentOverlay=`fluentOverlay`})(SP||={});var CP;(function(e){e.AppearanceBased=`appearanceBased`,e.Light=`light`,e.Dark=`dark`,e.MediumLight=`mediumLight`,e.UltraDark=`ultraDark`,e.Titlebar=`titlebar`,e.Selection=`selection`,e.Menu=`menu`,e.Popover=`popover`,e.Sidebar=`sidebar`,e.HeaderView=`headerView`,e.Sheet=`sheet`,e.WindowBackground=`windowBackground`,e.HudWindow=`hudWindow`,e.FullScreenUI=`fullScreenUI`,e.Tooltip=`tooltip`,e.ContentBackground=`contentBackground`,e.UnderWindowBackground=`underWindowBackground`,e.UnderPageBackground=`underPageBackground`,e.Mica=`mica`,e.Blur=`blur`,e.Acrylic=`acrylic`,e.Tabbed=`tabbed`,e.TabbedDark=`tabbedDark`,e.TabbedLight=`tabbedLight`})(CP||={});var wP;(function(e){e.FollowsWindowActiveState=`followsWindowActiveState`,e.Active=`active`,e.Inactive=`inactive`})(wP||={});var TP=12e-5,EP=36,DP=140,OP=1.5,kP=6;function AP(e,t){return{x:Math.random()*e,y:Math.random()*t,radius:.35+Math.random()*1.25,alpha:.22+Math.random()*.5,drift:OP+Math.random()*(kP-OP)}}function jP(e){let t=e.getBoundingClientRect(),n=t.width||e.parentElement?.clientWidth||window.innerWidth,r=t.height||e.parentElement?.clientHeight||window.innerHeight;return{width:Math.max(1,Math.floor(n)),height:Math.max(1,Math.floor(r))}}function MP(){let e=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(typeof window>`u`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return;let t=e.current;if(!t)return;let n=t.getContext(`2d`,{alpha:!0});if(!n)return;let r=t,i=n,a=[],o=0,s=0,c=0,l=0,u=0,d=!document.hidden;function f(){let e=jP(r),t=window.devicePixelRatio||1;if(e.width===o&&e.height===s&&t===c)return;let n=e.width!==o||e.height!==s;if(o=e.width,s=e.height,c=t,r.width=Math.max(1,Math.round(o*t)),r.height=Math.max(1,Math.round(s*t)),r.style.width=`100%`,r.style.height=`100%`,i.setTransform(t,0,0,t,0,0),n||a.length===0){let e=Math.min(DP,Math.max(EP,Math.floor(o*s*TP)));a=Array.from({length:e},()=>AP(o,s))}}function p(e){i.clearRect(0,0,o,s);for(let t of a)t.x+=t.drift*e,t.x>o+t.radius&&(t.x=-t.radius,t.y=Math.random()*s),i.globalAlpha=t.alpha,i.fillStyle=`hsl(213 100% 92%)`,i.beginPath(),i.arc(t.x,t.y,t.radius,0,Math.PI*2),i.fill();i.globalAlpha=1}function m(e){if(!d)return;let t=u===0?.016:Math.min(.05,(e-u)/1e3);u=e,p(t),l=requestAnimationFrame(m)}function h(){d=!document.hidden,d?(u=0,l=requestAnimationFrame(m)):cancelAnimationFrame(l)}let g=null;function _(){g&&g.removeEventListener(`change`,_),f(),v()}function v(){let e=window.devicePixelRatio||1;g=window.matchMedia(`(resolution: ${e}dppx)`),g.addEventListener(`change`,_)}f();let y=null,b=r.parentElement;return typeof ResizeObserver<`u`&&b&&(y=new ResizeObserver(()=>f()),y.observe(b)),window.addEventListener(`resize`,f),v(),document.addEventListener(`visibilitychange`,h),d&&(l=requestAnimationFrame(m)),()=>{cancelAnimationFrame(l),y&&y.disconnect(),g&&g.removeEventListener(`change`,_),window.removeEventListener(`resize`,f),document.removeEventListener(`visibilitychange`,h)}},[]),(0,$.jsx)(`canvas`,{ref:e,"aria-hidden":!0,className:`absolute inset-0 pointer-events-none`,style:{zIndex:-1}})}var NP=(0,Q.lazy)(()=>c(()=>import(`./AgentModeCodePane-7s6TnZGe.js`).then(e=>({default:e.AgentModeCodePane})),__vite__mapDeps([83,1,7,10,43,51]))),PP=(0,Q.lazy)(()=>c(()=>import(`./AgentModeJobsPane-Btsb5Sq4.js`).then(e=>({default:e.AgentModeJobsPane})),__vite__mapDeps([84,1,7,12,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,45,8,58,51,68,69,71,72,76,80,6,9,11,44,46,47,48,49,50,52,53,54,55,56,57,59,60,61,62,63,64,65,66,67,70,73,74,75,77,78,79,85]))),FP=(0,Q.lazy)(()=>c(()=>import(`./AgentModeAnalyticsPane-N0k6nlj0.js`).then(e=>({default:e.AgentModeAnalyticsPane})),__vite__mapDeps([86,1,7,10,43,58,51,68,69])));function IP(){let{t:e}=K(`agent`),{active:t,refreshConversations:n,builderMode:r}=aP(),{codePaneOpen:i,jobsPaneOpen:a,analyticsPaneOpen:o}=lO(),{activeProjectId:s}=pt(),c=Ci(),l=Wy(t?.id??`__new-mission__`),u=!c.current&&c.transfers.some(e=>e.conversationId===t?.id&&e.state===`detached`),d=wa(),f=d.id===`galaxy`,p=d.id===`code-rain`?e(`emptyTitleCodeRain`):e(`emptyTitle`);(0,Q.useEffect)(()=>{n()},[n]);let m=i&&!!s&&!u,h=a&&!!s&&!u,g=o&&!!s&&!u;return(0,$.jsx)(J_,{reducedMotion:`user`,children:(0,$.jsxs)(`div`,{"data-agent-mode-surface":!0,className:`relative z-0 flex h-full w-full overflow-hidden bg-background`,children:[f&&(0,$.jsx)(MP,{}),(0,$.jsxs)(`div`,{className:`relative flex h-full min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,$.jsx)(Ny.div,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 z-0`,animate:{opacity:+(t===null)},transition:{duration:.5,ease:`easeOut`},style:{background:`radial-gradient(60% 55% at 50% 45%, color-mix(in srgb, var(--color-accent-primary) 13%, transparent), transparent 70%)`}}),r.active?(0,$.jsx)(`div`,{className:`relative z-10 flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,$.jsx)(lN,{variant:`inline`})}):t===null?(0,$.jsx)(`div`,{className:`relative z-10 flex h-full w-full items-center justify-center px-6`,children:(0,$.jsxs)(Ny.div,{layoutId:`agent-composer-dock`,initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.28,ease:[.34,1.56,.64,1],layout:{type:`spring`,stiffness:350,damping:34}},className:`w-full max-w-[680px] rounded-2xl border border-border/60 bg-card/90 p-4 shadow-2xl backdrop-blur-xl`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 px-1`,children:[(0,$.jsx)(Vo,{className:`h-4 w-4 text-accent-primary`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground/80`,children:p})]}),(0,$.jsx)(MA,{autoFocus:!0})]})}):(0,$.jsx)(`div`,{className:`relative z-10 flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,$.jsx)(Hj,{variant:`inline`})})]}),h&&(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`w-[480px] border-l border-border`}),children:(0,$.jsx)(PP,{projectId:s})}),m&&(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`w-[520px] border-l border-border`}),children:(0,$.jsx)(NP,{projectId:s,conversationId:t?.id??`__home__`},`${t?.id}:${l}`)}),g&&(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`w-[560px] border-l border-border`}),children:(0,$.jsx)(FP,{})})]})})}var LP=(e,t,n)=>Math.min(n,Math.max(t,e)),RP=e=>`specrails-desktop:sidebar-width:${e}`;function zP(e,t){let n=RP(e),[r,i]=(0,Q.useState)(()=>{try{let e=localStorage.getItem(n),r=e?Number.parseInt(e,10):NaN;if(Number.isFinite(r))return LP(r,t.min,t.max)}catch{}return t.defaultWidth}),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null),c=(0,Q.useRef)(r);c.current=r;let l=(0,Q.useRef)(!1),u=(0,Q.useRef)(t);return u.current=t,(0,Q.useLayoutEffect)(()=>{let e=s.current;!e||l.current||(e.style.width=`${t.expanded?r:t.collapsedWidth}px`)},[r,t.expanded,t.collapsedWidth]),{width:r,dragging:a,panelRef:s,onGripPointerDown:(0,Q.useCallback)(e=>{if(e.button!==0||!u.current.expanded)return;e.preventDefault();let t=s.current;if(!t)return;let r=e.clientX,a=c.current,d=a;l.current=!0,o(!0),t.style.transition=`none`;let f=document.body.style.cursor,p=document.body.style.userSelect;document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`;try{e.target.setPointerCapture?.(e.pointerId)}catch{}let m=e=>{let n=u.current,i=e.clientX-r,o=n.side===`left`?i:-i;d=LP(a+o,n.min,n.max),t.style.width=`${d}px`},h=()=>{window.removeEventListener(`pointermove`,m),window.removeEventListener(`pointerup`,h),window.removeEventListener(`pointercancel`,h),t.style.transition=``,document.body.style.cursor=f,document.body.style.userSelect=p,l.current=!1,o(!1),i(d);try{localStorage.setItem(n,String(Math.round(d)))}catch{}};window.addEventListener(`pointermove`,m),window.addEventListener(`pointerup`,h),window.addEventListener(`pointercancel`,h)},[n]),onGripKeyDown:(0,Q.useCallback)(e=>{let t=u.current,r=e.shiftKey?24:8,a=t.side===`left`?`ArrowRight`:`ArrowLeft`,o=t.side===`left`?`ArrowLeft`:`ArrowRight`,s=null;if(e.key===a?s=LP(c.current+r,t.min,t.max):e.key===o?s=LP(c.current-r,t.min,t.max):e.key===`Home`&&(s=t.defaultWidth),s!==null){e.preventDefault(),i(s);try{localStorage.setItem(n,String(Math.round(s)))}catch{}}},[n])}}function BP({side:e,dragging:t,width:n,min:r,max:i,label:a,onPointerDown:o,onKeyDown:s}){return(0,$.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":a,"aria-valuenow":Math.round(n),"aria-valuemin":r,"aria-valuemax":i,tabIndex:0,"data-testid":`sidebar-resize-grip-${e}`,onPointerDown:o,onKeyDown:s,className:X(`group absolute inset-y-0 z-20 w-1.5 cursor-col-resize outline-none`,e===`left`?`-right-0.5`:`-left-0.5`),children:(0,$.jsx)(`div`,{className:X(`absolute inset-y-0 w-px transition-colors duration-150`,e===`left`?`right-0`:`left-0`,t?`bg-accent-primary`:`bg-transparent group-hover:bg-accent-primary/50 group-focus-visible:bg-accent-primary/70`)})})}var VP=[`pinned-open`,`pinned-collapsed`,`unpinned`],HP=`specrails-desktop:sidebar-mode:left`,UP=`specrails-desktop:sidebar-mode:right`;function WP(e){return typeof e==`string`&&VP.includes(e)}function GP(e){try{let t=window.localStorage.getItem(e);if(WP(t))return t}catch{}return`unpinned`}function KP(e,t){try{window.localStorage.setItem(e,t)}catch{}}function qP(e){switch(e){case`pinned-open`:return`pinned-collapsed`;case`pinned-collapsed`:return`unpinned`;case`unpinned`:return`pinned-open`}}var JP=(0,Q.createContext)({leftMode:`unpinned`,rightMode:`unpinned`,setLeftMode:()=>{},setRightMode:()=>{},cycleLeftMode:()=>{},cycleRightMode:()=>{}});function YP({children:e}){let[t,n]=(0,Q.useState)(()=>GP(HP)),[r,i]=(0,Q.useState)(()=>GP(UP));(0,Q.useEffect)(()=>{KP(HP,t)},[t]),(0,Q.useEffect)(()=>{KP(UP,r)},[r]);let a=(0,Q.useCallback)(e=>n(e),[]),o=(0,Q.useCallback)(e=>i(e),[]),s=(0,Q.useCallback)(()=>n(e=>qP(e)),[]),c=(0,Q.useCallback)(()=>i(e=>qP(e)),[]),l=(0,Q.useMemo)(()=>({leftMode:t,rightMode:r,setLeftMode:a,setRightMode:o,cycleLeftMode:s,cycleRightMode:c}),[t,r,a,o,s,c]);return(0,$.jsx)(JP.Provider,{value:l,children:e})}function XP(){return(0,Q.useContext)(JP)}function ZP({open:e,onClose:t,onCommitted:n,projectId:r,milestoneId:i,blueprint:a,provider:o=`claude`}){let{t:s}=K(`builder`),{registerHandler:c,unregisterHandler:l}=tt(),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(``),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)({status:`idle`}),O=(0,Q.useRef)(null),k=(0,Q.useRef)(r),A=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{O.current=u},[u]),(0,Q.useEffect)(()=>{k.current=r},[r]);let j=a.milestones.find(e=>e.id===i),M=i.toUpperCase(),N=Ct(o,`read-only`),P=(0,Q.useMemo)(()=>IM(v??g,{milestoneLabel:M,minSpecs:1,maxSpecs:10,requireScaffold:!1}),[g,v,M]),F=(0,Q.useMemo)(()=>RM(g,v??g,P,{minSpecs:1,maxSpecs:10}),[g,v,P]),I=(0,Q.useMemo)(()=>on(m),[m]);(0,Q.useEffect)(()=>{if(!e||u||!N)return;let t=!1;return fetch(`${ut()}/chat/conversations`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:`milestone`,milestone:i})}).then(e=>e.json()).then(e=>{if(t||!e.conversation)return;O.current=e.conversation.id,d(e.conversation.id);let n=j?.plannedSpecs??[],r={label:M,title:j?.title??M,planned:n.join(`; `)},i=n.length>0?s(`prompts.milestoneSeedWithPlanned`,r):s(`prompts.milestoneSeed`,r);p([{role:`user`,content:i}]),C(!0),fetch(`${ut()}/chat/conversations/${e.conversation.id}/messages`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:i})}).catch(()=>{C(!1),J.error(s(`errors.turnFailed`))})}).catch(()=>{t||J.error(s(`errors.startFailed`))}),()=>{t=!0}},[e,u,i,j,M,N,s]),(0,Q.useEffect)(()=>{if(!e)return;let t=`milestone-generate-${i}`;return c(t,e=>{let t=e;if(t.conversationId===O.current&&!(t.projectId&&t.projectId!==k.current))if(t.type===`chat_stream`)h(e=>(e??``)+String(t.delta??``));else if(t.type===`chat_done`){h(null),C(!1);let e=String(t.fullText??``),n=ln(e),r=n.stripped.trim()||(n.hadBlocks?``:e);if(r&&p(e=>[...e,{role:`assistant`,content:r}]),n.blueprint)_(n.blueprint),y(n.rawBlueprint),D({status:`accepted`,repaired:n.repaired,repairAttempted:!1,at:new Date().toISOString()});else if(n.rejected.length>0){let e=n.rejected[n.rejected.length-1];D({status:`rejected`,reason:e.reason,detail:e.detail,repairAttempted:!1,at:new Date().toISOString()})}}else t.type===`chat_error`&&(h(null),C(!1),J.error(s(`errors.turnFailed`),{description:String(t.error??``)}))}),()=>l(t)},[e,i,c,l,s]),(0,Q.useEffect)(()=>{A.current?.scrollTo?.({top:A.current.scrollHeight})},[f,m]);let L=(0,Q.useCallback)(e=>{let t=O.current,n=e.trim();!t||!n||S||(p(e=>[...e,{role:`user`,content:n}]),x(``),C(!0),fetch(`${ut()}/chat/conversations/${t}/messages`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:n})}).catch(()=>{C(!1),J.error(s(`errors.turnFailed`))}))},[S,s]),R=(0,Q.useCallback)(()=>{let e=E.status===`rejected`?s(`snapshot.rejected.${E.reason}`):s(`readiness.issuesCount`,{count:F.issues.length});L(s(`prompts.repairSnapshot`,{reason:e}))},[E,F.issues.length,L,s]),z=(0,Q.useCallback)(()=>{let e=v??g,r=e&&typeof e==`object`&&!Array.isArray(e)?e:null,a=Array.isArray(r?.m1Specs)?r.m1Specs:[];!P.valid||w||(T(!0),fetch(`${ut()}/blueprint/commit-milestone`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({milestoneId:i,specsComplete:r?.specsComplete,specs:a})}).then(async e=>{if(e.status===201){let r=await e.json();J.success(s(`milestone.commitToast`,{count:r.insertedIds.length,label:M})),n?.(),t()}else{let t=await e.json().catch(()=>({}));J.error(s(`milestone.commitFailed`),{description:t.detail??t.error})}}).catch(()=>J.error(s(`milestone.commitFailed`))).finally(()=>T(!1)))},[g,v,P.valid,w,i,M,t,n,s]);if(!e)return null;let B=g?.m1Specs.length??0;return N?(0,$.jsxs)(`div`,{className:`fixed inset-0 z-50 flex flex-col bg-background/95 backdrop-blur-sm`,"data-testid":`milestone-shell`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-border/40 px-4 py-2.5`,children:[(0,$.jsx)(Ns,{className:`h-4 w-4 text-accent-primary`}),(0,$.jsx)(`h1`,{className:`text-sm font-semibold`,children:s(`milestone.title`,{label:M})}),j&&(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:j.title}),(0,$.jsx)(`button`,{type:`button`,onClick:t,className:`ml-auto rounded-md p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":s(`shell.close`),"data-testid":`milestone-close`,children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col border-r border-border/40`,children:[(0,$.jsxs)(`div`,{ref:A,className:`min-h-0 flex-1 space-y-3 overflow-y-auto p-4`,children:[f.map((e,t)=>(0,$.jsx)(`div`,{className:X(`max-w-[85%] whitespace-pre-wrap rounded-lg px-3 py-2 text-xs leading-relaxed`,e.role===`user`?`ml-auto bg-accent-primary/15`:`bg-surface/70`),children:e.content},t)),m!==null&&(0,$.jsxs)(`div`,{className:`max-w-[85%] whitespace-pre-wrap rounded-lg bg-surface/70 px-3 py-2 text-xs leading-relaxed`,children:[Kt(m),(0,$.jsx)(`span`,{className:`ml-0.5 inline-block h-3 w-1.5 animate-pulse bg-accent-primary/70 align-middle`})]}),I.generating&&(0,$.jsx)(uM,{specsStarted:I.specsStarted,snapshot:E})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2 border-t border-border/40 p-3`,children:[(0,$.jsx)(`textarea`,{value:b,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),L(b))},rows:2,placeholder:s(`milestone.inputPlaceholder`),className:`min-h-[2.5rem] flex-1 resize-none rounded-md border border-border/40 bg-surface/50 px-3 py-2 text-xs focus:outline-none focus-visible:ring-1 focus-visible:ring-ring`}),(0,$.jsx)(Z,{size:`sm`,onClick:()=>L(b),disabled:S||!b.trim()||!u,children:S?(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(bc,{className:`h-3.5 w-3.5`})})]})]}),(0,$.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col lg:w-96`,children:[(0,$.jsx)(mN,{blueprint:g,milestoneLabel:M,snapshot:E}),(0,$.jsx)(_N,{readiness:F,snapshot:E,busy:S||w,primaryLabel:w?s(`commit.creating`):s(`milestone.commit`,{count:B,label:M}),onPrimary:z,onRepair:R,primaryTestId:`milestone-commit`})]})]})]}):(0,$.jsxs)(`div`,{className:`fixed inset-0 z-50 flex flex-col bg-background/95 backdrop-blur-sm`,"data-testid":`milestone-shell`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-border/40 px-4 py-2.5`,children:[(0,$.jsx)(Ns,{className:`h-4 w-4 text-accent-primary`}),(0,$.jsx)(`h1`,{className:`text-sm font-semibold`,children:s(`milestone.title`,{label:M})}),(0,$.jsx)(`button`,{type:`button`,onClick:t,className:`ml-auto rounded-md p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":s(`shell.close`),"data-testid":`milestone-close`,children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})]}),(0,$.jsx)(`p`,{className:`m-4 rounded-md border border-accent-warning/30 bg-accent-warning/10 p-3 text-sm text-accent-warning`,"data-testid":`milestone-provider-unavailable`,children:s(`milestone.providerUnavailable`)})]})}function QP({expanded:e}){let{t}=K(`builder`),n=y(),{activeProjectId:r,projects:i}=pt(),{blueprint:a,progress:o,hasBlueprint:s,refresh:c}=Qt(r),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(()=>pM()),[_,v]=(0,Q.useState)(()=>gM()),[b,x]=(0,Q.useState)(null),S=(0,Q.useRef)(null),C=(0,Q.useRef)(null),[w,T]=(0,Q.useState)(null);(0,Q.useLayoutEffect)(()=>{if(!l){T(null);return}let e=()=>{let e=S.current?.getBoundingClientRect();if(!e)return;let t=Math.max(8,e.left-320-8),n=Math.min(Math.max(8,e.top),Math.max(8,window.innerHeight-240));T({top:n,left:t})};return e(),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[l]),(0,Q.useEffect)(()=>{if(!l)return;let e=e=>{let t=e.target;S.current?.contains(t)||C.current?.contains(t)||u(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]);let E=(0,Q.useCallback)(async()=>{if(!(!r||d)){f(!0);try{let e=await SM(r,1,h,{autoAdvance:_}),n=yM(1);if(e.ok){let r=e.launched.length+e.pending.length;h===`sequential`&&e.pending.length>0?J.success(t(_?`milestoneProgress.toast.launched`:`milestoneProgress.toast.launchedCheckpoint`,{milestone:n,count:e.ticketCount,n:r})):e.skippedCount>0?J.warning(t(`milestoneProgress.toast.launchedPartial`,{milestone:n,count:e.ticketCount,skipped:e.skippedCount})):J.success(t(`milestoneProgress.toast.launchedAll`,{milestone:n,count:e.ticketCount,n:r})),u(!1)}else e.reason===`chain_active`?J.info(t(`milestoneProgress.toast.chainActive`,{milestone:n})):J.error(t(`done.launchFailed`),{description:e.detail??e.error})}finally{f(!1)}}},[r,_,d,h,t]),D=(0,Q.useCallback)(async(e,n)=>{if(!(!r||p)){m(!0);try{let i=await EM(r,e,n);i.ok?(v(n),_M(n),J.success(t(n?`milestoneProgress.chain.autoOn`:`milestoneProgress.chain.autoOff`))):J.error(t(`milestoneProgress.chain.autoFailed`),{description:i.detail??i.error})}finally{m(!1)}}},[r,p,t]),O=(0,Q.useCallback)(async e=>{if(!(!r||p)){m(!0);try{let n=await wM(r,e);n.ok?J.success(t(`milestoneProgress.chain.resumed`)):J.error(t(`milestoneProgress.chain.resumeFailed`),{description:n.detail??n.error})}finally{m(!1)}}},[r,p,t]),k=(0,Q.useCallback)(async e=>{if(!(!r||p)){m(!0);try{let n=await TM(r,e);n.ok?J.success(t(`milestoneProgress.chain.cancelledToast`)):J.error(n.detail??n.error)}finally{m(!1)}}},[r,p,t]),A=(0,Q.useCallback)(e=>{u(!1),n(le?`/review/${e}`:`/`)},[n]),j=(0,Q.useCallback)(()=>{u(!1),n(`/`)},[n]);if(!r||s===!1||!a)return null;let M=o.find(e=>e.n===1)??null,N=M!==null&&Wt(M),P=o.find(e=>e.state===`planned`&&e.n>1)??null,F=i.find(e=>e.id===r),I=F?.provider??F?.providers?.[0]??`claude`,L=Ct(I,`read-only`),R=N?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`flex rounded-md border border-border/40 p-0.5 text-[10px]`,role:`radiogroup`,"aria-label":t(`sequential.modeLabel`),title:t(h===`sequential`?`milestoneProgress.sequentialHint`:`milestoneProgress.parallelHint`),"data-testid":`milestone-launch-mode`,children:[`sequential`,`parallel`].map(e=>(0,$.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":h===e,onClick:()=>{g(e),mM(e)},className:X(`flex-1 rounded px-1.5 py-1 font-medium transition-colors`,h===e?`bg-accent-primary/15 text-accent-primary`:`text-muted-foreground hover:text-foreground`),children:t(`sequential.mode.${e}`)},e))}),h===`sequential`&&(0,$.jsx)(tN,{checked:_,onChange:e=>{v(e),_M(e)},testId:`sidebar-auto-advance`}),(0,$.jsxs)(`button`,{type:`button`,onClick:E,disabled:d,className:`inline-flex items-center justify-center gap-1.5 rounded-md bg-accent-primary/15 px-2 py-1.5 text-[11px] font-medium text-accent-primary transition-colors hover:bg-accent-primary/25 disabled:opacity-50`,"data-testid":`sidebar-launch-m1`,children:[d?(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`}):(0,$.jsx)(gc,{className:`h-3 w-3`}),t(`sidebar.launchM1`)]})]}):null;return(0,$.jsxs)(`div`,{ref:S,className:`relative`,"data-testid":`builder-sidebar-entry`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(e=>!e),className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,e?`px-2`:`px-0 justify-center`,l?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),title:e?void 0:t(`sidebar.title`),"data-testid":`builder-sidebar-toggle`,children:[(0,$.jsx)(Ns,{className:`w-4 h-4 flex-shrink-0`}),e&&(0,$.jsx)(`span`,{className:`text-xs truncate`,children:t(`sidebar.title`)})]}),l&&w&&(0,Hb.createPortal)((0,$.jsxs)(`div`,{ref:C,className:`fixed z-[72] w-80 max-h-[80vh] overflow-y-auto rounded-lg border border-border/50 bg-background p-3 shadow-xl`,style:{top:w.top,left:w.left},"data-testid":`builder-sidebar-panel`,children:[(0,$.jsx)(`h4`,{className:`text-xs font-semibold`,children:t(`sidebar.title`)}),(0,$.jsx)(`div`,{className:`mt-2 space-y-1.5`,children:o.map(e=>(0,$.jsx)(rN,{progress:e,actions:e.n===1?R:void 0,chainBusy:p,onReview:A,onOpenRail:j,onResume:O,onCancel:k,onSetAutoAdvance:D},e.id||e.n))}),P&&(0,$.jsx)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{L&&(x(P.id),u(!1))},disabled:!L,className:`inline-flex items-center justify-center gap-1.5 rounded-md border border-accent-highlight/40 px-2 py-1.5 text-[11px] font-medium text-accent-highlight transition-colors hover:bg-accent-highlight/10`,title:t(L?`sidebar.generateHint`:`sidebar.generateUnavailable`),"data-testid":`sidebar-generate-next`,children:[(0,$.jsx)(Ln,{className:`h-3 w-3`}),t(`sidebar.generateNext`,{n:P.n})]})})]}),document.body),b&&(0,$.jsx)(ZP,{open:!0,onClose:()=>x(null),onCommitted:()=>{c()},projectId:r,milestoneId:b,blueprint:a,provider:I})]})}var $P={"pinned-open":`sidebarPin.right.pinnedOpen`,"pinned-collapsed":`sidebarPin.right.pinnedCollapsed`,unpinned:`sidebarPin.right.unpinned`};function eF({missionOnly:e=!1}={}){let{t}=K(`agent`),{t:n}=K(`nav`),{t:r}=K(`builder`),{rightMode:i,cycleRightMode:a}=XP(),{activeProjectId:o}=pt(),s=za(),c=lO(),{builderMode:l}=aP(),[u,d]=(0,Q.useState)(!1),f=l.active||i===`pinned-open`||i===`unpinned`&&u,p=zP(`right-workspace`,{side:`right`,defaultWidth:208,min:180,max:460,collapsedWidth:44,expanded:f}),m=i!==`unpinned`,h=n($P[i]),g=!o,_=[{key:`jobs`,icon:Go,label:t(`workspace.jobs`),onClick:()=>c.toggleJobsPane(),disabled:g,disabledTitle:t(`workspace.requiresProject`)},{key:`analytics`,icon:Ko,label:t(`workspace.analytics`),onClick:()=>c.toggleAnalyticsPane(),disabled:g,disabledTitle:t(`workspace.requiresProject`)},...Ie()?[{key:`browser`,icon:D,label:t(`workspace.browser`),onClick:()=>c.openBrowser(),disabled:g,disabledTitle:t(`workspace.requiresProject`)}]:[],...Te?[{key:`terminal`,icon:Ec,label:t(`workspace.terminal`),onClick:()=>o&&s.togglePanel(o),disabled:g,disabledTitle:t(`workspace.requiresProject`)}]:[],...me?[{key:`files`,icon:ys,label:t(`workspace.files`),onClick:()=>c.toggleCodePane(),disabled:g,disabledTitle:t(`workspace.requiresProject`)}]:[]];return(0,$.jsxs)(`div`,{ref:p.panelRef,className:X(`relative flex flex-col h-full border-l border-border bg-background flex-shrink-0 overflow-hidden`,`transition-[width] duration-200 ease-in-out`),onMouseEnter:()=>{i===`unpinned`&&d(!0)},onMouseLeave:()=>{i===`unpinned`&&!p.dragging&&d(!1)},children:[f&&(0,$.jsx)(BP,{side:`right`,dragging:p.dragging,width:p.width,min:180,max:460,label:n(`sidebarPin.resize`,{defaultValue:`Resize sidebar`}),onPointerDown:p.onGripPointerDown,onKeyDown:p.onGripKeyDown}),(0,$.jsxs)(`div`,{className:X(`flex items-center h-12 border-b border-border flex-shrink-0`,f?`px-3 justify-between`:`justify-center`),children:[f&&(0,$.jsx)(`span`,{className:`font-mono text-sm font-bold whitespace-nowrap overflow-hidden text-accent-secondary`,children:t(`workspace.title`)}),(0,$.jsx)(`button`,{type:`button`,onClick:a,className:X(`flex items-center justify-center w-7 h-7 rounded-md transition-colors`,m?`text-foreground bg-muted`:`text-muted-foreground/40 hover:text-muted-foreground hover:bg-muted/50`),"aria-label":h,title:n(`sidebarPin.withShortcut`,{label:h,shortcut:`⌘B`}),children:(0,$.jsx)(nc,{className:`w-4 h-4`})})]}),l.active?(0,$.jsx)(N_,{mode:`wait`,initial:!1,children:(0,$.jsxs)(Ny.div,{initial:{opacity:0,x:24},animate:{opacity:1,x:0},exit:{opacity:0,x:24},transition:{duration:.22,ease:`easeOut`},className:`flex min-h-0 flex-1 flex-col`,"data-testid":`workspace-blueprint-panel`,children:[(0,$.jsx)(mN,{blueprint:l.session.blueprint,snapshot:l.session.snapshot}),l.session.phase===`chat`&&(0,$.jsx)(_N,{readiness:l.session.readiness,snapshot:l.session.snapshot,busy:l.session.busy,primaryLabel:r(`shell.createSpecs`),onPrimary:l.session.goToCommit,onRepair:()=>void l.session.repairSnapshot()})]},`builder-blueprint`)}):(0,$.jsxs)(`nav`,{className:`flex-1 py-2 px-1.5 space-y-0.5`,children:[!e&&(0,$.jsx)(QP,{expanded:f}),_.map(({key:e,icon:t,label:n,onClick:r,disabled:i,disabledTitle:a})=>(0,$.jsxs)(`button`,{type:`button`,onClick:r,disabled:i,className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,f?`px-2`:`px-0 justify-center`,i?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),title:i?a:f?void 0:n,children:[(0,$.jsx)(t,{className:`w-4 h-4 flex-shrink-0`}),f&&(0,$.jsx)(`span`,{className:`text-xs truncate`,children:n})]},e))]})]})}var tF=`specrails:terminal-settings-updated`;function nF(e){typeof window>`u`||window.dispatchEvent(new CustomEvent(tF,{detail:e}))}function rF(){return new oF(_P(),window.__TAURI_INTERNALS__.metadata.currentWebview.label,{skip:!0})}async function iF(){return Y(`plugin:webview|get_all_webviews`).then(e=>e.map(e=>new oF(new bP(e.windowLabel,{skip:!0}),e.label,{skip:!0})))}var aF=[`tauri://created`,`tauri://error`],oF=class{constructor(e,t,n){this.window=e,this.label=t,this.listeners=Object.create(null),n?.skip||Y(`plugin:webview|create_webview`,{windowLabel:e.label,options:{...n,label:t}}).then(async()=>this.emit(`tauri://created`)).catch(async e=>this.emit(`tauri://error`,e))}static async getByLabel(e){return(await iF()).find(t=>t.label===e)??null}static getCurrent(){return rF()}static async getAll(){return iF()}async listen(e,t){return this._handleTauriEvent(e,t)?()=>{let n=this.listeners[e];n.splice(n.indexOf(t),1)}:Ar(e,t,{target:{kind:`Webview`,label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?()=>{let n=this.listeners[e];n.splice(n.indexOf(t),1)}:Mr(e,t,{target:{kind:`Webview`,label:this.label}})}async emit(e,t){if(aF.includes(e)){for(let n of this.listeners[e]||[])n({event:e,id:-1,payload:t});return}return jr(e,t)}async emitTo(e,t,n){if(aF.includes(t)){for(let e of this.listeners[t]||[])e({event:t,id:-1,payload:n});return}return Nr(e,t,n)}_handleTauriEvent(e,t){return aF.includes(e)?(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0):!1}async position(){return Y(`plugin:webview|webview_position`,{label:this.label}).then(e=>new fP(e))}async size(){return Y(`plugin:webview|webview_size`,{label:this.label}).then(e=>new lP(e))}async close(){return Y(`plugin:webview|webview_close`,{label:this.label})}async setSize(e){return Y(`plugin:webview|set_webview_size`,{label:this.label,value:e instanceof uP?e:new uP(e)})}async setPosition(e){return Y(`plugin:webview|set_webview_position`,{label:this.label,value:e instanceof pP?e:new pP(e)})}async setFocus(){return Y(`plugin:webview|set_webview_focus`,{label:this.label})}async setAutoResize(e){return Y(`plugin:webview|set_webview_auto_resize`,{label:this.label,value:e})}async hide(){return Y(`plugin:webview|webview_hide`,{label:this.label})}async show(){return Y(`plugin:webview|webview_show`,{label:this.label})}async setZoom(e){return Y(`plugin:webview|set_webview_zoom`,{label:this.label,value:e})}async reparent(e){return Y(`plugin:webview|reparent`,{label:this.label,window:typeof e==`string`?e:e.label})}async clearAllBrowsingData(){return Y(`plugin:webview|clear_all_browsing_data`)}async setBackgroundColor(e){return Y(`plugin:webview|set_webview_background_color`,{color:e})}async onDragDropEvent(e){let t=await this.listen(Pr.DRAG_ENTER,t=>{e({...t,payload:{type:`enter`,paths:t.payload.paths,position:new fP(t.payload.position)}})}),n=await this.listen(Pr.DRAG_OVER,t=>{e({...t,payload:{type:`over`,position:new fP(t.payload.position)}})}),r=await this.listen(Pr.DRAG_DROP,t=>{e({...t,payload:{type:`drop`,paths:t.payload.paths,position:new fP(t.payload.position)}})}),i=await this.listen(Pr.DRAG_LEAVE,t=>{e({...t,payload:{type:`leave`}})});return()=>{t(),r(),n(),i()}}};function sF(e){return`'${e.replace(/'/g,`'\\''`)}'`}function cF(e){if(/[\x00-\x1f"%!]/.test(e))throw Error(`unsafe-cmd-path`);return`"`+e+`"`}function lF(e){return`'${e.replace(/'/g,`''`)}'`}function uF(e,t,n=`powershell`){return t?n===`cmd`?cF(e):lF(e):sF(e)}function dF(e,t,n=`powershell`){return e.map(e=>uF(e,t,n)).join(` `)}function fF(e){return/(?:^|[\\/])cmd(?:\.exe)?$/i.test(e??``)?`cmd`:`powershell`}async function pF(e){if(!de())return{dispose:()=>{}};let t=[];try{let n=``,r=0,i=typeof navigator<`u`&&/Win/i.test(navigator.platform||``),a=t=>{let a=t.payload;if(!a||a.type!==`drop`)return;let o=a.paths;if(!o||o.length===0)return;let s=a.position;if(!s)return;let c=`${o.join(`\0`)}@${s.x},${s.y}`,l=Date.now();if(c===n&&l-r<250)return;n=c,r=l;let u=e();if(u&&hF(s,u.viewportEl.getBoundingClientRect(),window.devicePixelRatio||1))try{u.writeText(dF(o,i,fF(u.shell)))}catch{J.error(Je.t(`terminal:errors.pathPasteUnsafe`))}},o=mF((()=>{try{return rF()}catch{return null}})());o&&t.push(await o(a));let s=mF((()=>{try{return _P()}catch{return null}})());return s&&t.push(await s(a)),t.length===0?{dispose:()=>{}}:{dispose:()=>{for(let e of t)try{e()}catch{}}}}catch{for(let e of t)try{e()}catch{}return{dispose:()=>{}}}}function mF(e){let t=e?.onDragDropEvent;return typeof t==`function`?t.bind(e):null}function hF(e,t,n){let r=Number.isFinite(n)&&n>0?n:1;return gF(e.x/r,e.y/r,t)}function gF(e,t,n){return e>=n.left&&e<=n.right&&t>=n.top&&t<=n.bottom}function _F({x:e,y:t,label:n,onSelect:r,onClose:i}){let a=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let e=e=>{a.current&&!a.current.contains(e.target)&&i()},t=e=>{e.key===`Escape`&&i()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]),(0,$.jsx)(`div`,{ref:a,role:`menu`,"data-shortcut-context-menu":!0,style:{position:`fixed`,left:typeof window<`u`&&e+220>window.innerWidth?e-220:e,top:typeof window<`u`&&t+60>window.innerHeight?t-60:t,minWidth:200},className:`bg-[#1f1f29] border border-[#44475a] rounded-md shadow-lg py-1 z-50 text-sm`,children:(0,$.jsx)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{r(),i()},className:`w-full text-left px-3 py-1.5 text-[#f8f8f2] hover:bg-[#44475a]`,children:n})})}function vF({x:e,y:t,providers:n,onSelect:r,onClose:i}){let{t:a}=K(`terminal`),o=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=e=>{o.current&&!o.current.contains(e.target)&&i()},t=e=>{e.key===`Escape`&&i()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]);let s=typeof window<`u`&&e+200>window.innerWidth?e-200:e,c=8+n.length*32;return(0,$.jsx)(`div`,{ref:o,role:`menu`,"data-cli-launch-menu":!0,style:{position:`fixed`,left:s,top:typeof window<`u`&&t+c>window.innerHeight?t-c:t,minWidth:180},className:`bg-[#1f1f29] border border-[#44475a] rounded-md shadow-lg py-1 z-50 text-sm`,children:n.map(e=>(0,$.jsx)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{r(e),i()},className:`w-full text-left px-3 py-1.5 text-[#f8f8f2] hover:bg-[#44475a]`,children:a(`cliMenu.open`,{name:jt(e)})},e))})}var yF=(0,Q.forwardRef)(function({isOpen:e,className:t,...n},r){let{t:i}=K(`terminal`);return(0,$.jsx)(`button`,{ref:r,type:`button`,"aria-label":i(e?`panelChevron.collapse`:`panelChevron.expand`),"aria-expanded":e,className:X(`panel-chevron`,`inline-flex items-center justify-center`,`h-5 w-6 mr-1.5`,`rounded text-muted-foreground`,`hover:bg-border/40 hover:text-foreground`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent-primary/60`,`transition-colors duration-120`,t),...n,children:(0,$.jsxs)(`svg`,{width:`14`,height:`10`,viewBox:`0 0 14 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,$.jsx)(`rect`,{x:`1`,y:`1`,width:`12`,height:`8`,rx:`1.5`}),e?(0,$.jsx)(`path`,{d:`M5 3.5 L7 5.5 L9 3.5`}):(0,$.jsx)(`path`,{d:`M5 6.5 L7 4.5 L9 6.5`})]})})});function bF({visibility:e,canCreate:t,hasActive:n,provider:r=`claude`,providers:i,onCreate:a,onOpenCli:o,onOpenBrowser:s,onPasteScript:c,pasteScriptDisabled:l,onConfigureBrowser:u,onConfigureScript:d,onKillActive:f,onToggleMaximize:p,onCollapse:m}){let{t:h}=K(`terminal`),g=!!i&&i.length>1,_=jt(r),v=h(`topBar.maxTerminals`,{max:10}),y=t?g?h(`topBar.openCliMulti`):h(`topBar.openCli`,{cli:_}):v;return(0,$.jsxs)(`div`,{className:X(`flex items-center justify-between h-7 px-2 shrink-0`,`bg-background/95 backdrop-blur-sm`,`border-b border-border/40`,`text-[10px] uppercase tracking-wide text-muted-foreground select-none`),children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2 pl-1`,children:(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:h(`topBar.title`)})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,$.jsx)(xF,{label:y,disabled:!t,onClick:e=>o(e?{x:e.clientX,y:e.clientY}:void 0),children:(0,$.jsx)(Ln,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(xF,{label:h(`topBar.openInBrowser`),onClick:s,onContextMenu:e=>{e.preventDefault(),u({x:e.clientX,y:e.clientY})},children:(0,$.jsx)(D,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(xF,{label:h(l?`topBar.pasteScriptNoActive`:`topBar.pasteScript`),disabled:l,onClick:c,onContextMenu:e=>{e.preventDefault(),d({x:e.clientX,y:e.clientY})},children:(0,$.jsx)(is,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(xF,{label:t?h(`topBar.newTerminal`):v,disabled:!t,onClick:a,children:(0,$.jsx)(Pn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(xF,{label:h(`topBar.killActive`),disabled:!n,onClick:f,children:(0,$.jsx)(Rn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(xF,{label:h(e===`maximized`?`topBar.restorePanel`:`topBar.maximizePanel`),onClick:p,children:e===`maximized`?(0,$.jsx)(Js,{className:`h-3.5 w-3.5`}):(0,$.jsx)(qs,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(yF,{isOpen:!0,onClick:m})]})]})}function xF({label:e,disabled:t,onClick:n,onContextMenu:r,children:i}){return(0,$.jsx)(`button`,{type:`button`,onClick:e=>n(e),onContextMenu:r,disabled:t,title:e,"aria-label":e,className:X(`inline-flex items-center justify-center h-5 w-6 rounded`,`text-muted-foreground transition-colors duration-120`,t?`opacity-40 cursor-not-allowed`:`hover:bg-border/40 hover:text-foreground`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent-primary/60`),children:i})}function SF({sessions:e,activeId:t,onActivate:n,onRename:r,onKill:i}){return(0,$.jsx)(`aside`,{className:X(`w-44 shrink-0 border-l border-border/40 bg-background/70`,`overflow-y-auto`),children:(0,$.jsx)(`ul`,{className:`py-1`,children:e.map(e=>(0,$.jsx)(CF,{session:e,active:e.id===t,onActivate:()=>n(e.id),onRename:t=>r(e.id,t),onKill:()=>i(e.id)},e.id))})})}function CF({session:e,active:t,onActivate:n,onRename:r,onKill:i}){let{t:a}=K(`terminal`),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(e.name),u=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{o&&(l(e.name),queueMicrotask(()=>{u.current?.focus(),u.current?.select()}))},[o,e.name]);function d(){let t=c.trim();t&&t!==e.name&&r(t),s(!1)}function f(){s(!0)}function p(){s(!1),l(e.name)}return(0,$.jsx)(`li`,{className:`relative group px-1`,children:(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-pressed":t,onClick:()=>{o||n()},onKeyDown:e=>{o||(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),n())},onDoubleClick:f,className:X(`flex items-center gap-2 px-2 py-1.5 rounded-md text-xs cursor-pointer select-none`,`transition-colors duration-120`,t?`bg-border/40 text-foreground border-l-2 border-accent-primary/70 pl-[calc(0.5rem-2px)]`:`text-muted-foreground hover:bg-border/20 hover:text-foreground`),children:[(0,$.jsx)(Ac,{className:`h-3 w-3 shrink-0`}),o?(0,$.jsx)(`input`,{ref:u,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),d()),e.key===`Escape`&&(e.preventDefault(),p())},onBlur:d,onClick:e=>e.stopPropagation(),maxLength:64,className:X(`flex-1 min-w-0 bg-background/60 border border-border/40 rounded px-1`,`text-xs text-foreground outline-none focus:ring-1 focus:ring-accent-primary/60`)}):(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),!o&&(0,$.jsx)(`button`,{type:`button`,"aria-label":a(`sidebar.rename`,{name:e.name}),title:a(`sidebar.rename`,{name:e.name}),onClick:e=>{e.stopPropagation(),f()},className:X(`inline-flex items-center justify-center h-4 w-4 rounded`,`text-muted-foreground opacity-0 group-hover:opacity-100`,`hover:bg-border/40 hover:text-foreground`,`transition-opacity duration-120`,t&&`opacity-70`),children:(0,$.jsx)(jn,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,"aria-label":a(`sidebar.close`,{name:e.name}),title:a(`sidebar.close`,{name:e.name}),onClick:e=>{e.stopPropagation(),i()},className:X(`inline-flex items-center justify-center h-4 w-4 rounded`,`text-muted-foreground opacity-0 group-hover:opacity-100`,`hover:bg-destructive/20 hover:text-destructive`,`transition-opacity duration-120`,t&&`opacity-70`),children:(0,$.jsx)(Vn,{className:`h-3 w-3`})})]})})}function wF({search:e,onClose:t}){let{t:n}=K(`terminal`),r=(0,Q.useRef)(null),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(null);(0,Q.useEffect)(()=>(r.current?.focus(),()=>{try{e.clearDecorations()}catch{}}),[e]),(0,Q.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.preventDefault(),t())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);function m(){return{caseSensitive:o,regex:c,wholeWord:u,decorations:{matchBackground:`#bd93f9`,matchOverviewRuler:`#bd93f9`,activeMatchBackground:`#ff79c6`,activeMatchColorOverviewRuler:`#ff79c6`}}}function h(){if(i)try{e.findNext(i,m())}catch{}}function g(){if(i)try{e.findPrevious(i,m())}catch{}}return(0,Q.useEffect)(()=>{let t=()=>{};try{let n=e.onDidChangeResults(e=>{if(!e){p(null);return}p({current:e.resultIndex+1,total:e.resultCount})});t=()=>{try{n.dispose()}catch{}}}catch{}return t},[e]),(0,$.jsxs)(`div`,{className:`absolute top-2 right-2 flex items-center gap-1 bg-[#1f1f29] border border-[#44475a] rounded-md shadow-lg px-2 py-1 z-30`,role:`search`,"data-terminal-search-overlay":!0,children:[(0,$.jsx)(`input`,{ref:r,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.shiftKey?g():h())},placeholder:n(`search.placeholder`),className:`bg-transparent text-sm outline-none text-[#f8f8f2] placeholder:text-[#6272a4] w-48`}),f&&(0,$.jsxs)(`span`,{className:`text-xs text-[#6272a4] tabular-nums`,children:[f.current,`/`,f.total]}),(0,$.jsx)(`button`,{type:`button`,title:n(`search.previous`),onClick:g,className:`text-[#f8f8f2] hover:text-white p-1`,children:(0,$.jsx)(gn,{size:14})}),(0,$.jsx)(`button`,{type:`button`,title:n(`search.next`),onClick:h,className:`text-[#f8f8f2] hover:text-white p-1`,children:(0,$.jsx)(Xo,{size:14})}),(0,$.jsx)(TF,{label:`Aa`,title:n(`search.matchCase`),active:o,onToggle:()=>s(e=>!e)}),(0,$.jsx)(TF,{label:`.*`,title:n(`search.regex`),active:c,onToggle:()=>l(e=>!e)}),(0,$.jsx)(TF,{label:`W`,title:n(`search.wholeWord`),active:u,onToggle:()=>d(e=>!e)}),(0,$.jsx)(`button`,{type:`button`,title:n(`search.close`),onClick:t,className:`text-[#f8f8f2] hover:text-white p-1`,children:(0,$.jsx)(Vn,{size:14})})]})}function TF({label:e,title:t,active:n,onToggle:r}){return(0,$.jsx)(`button`,{type:`button`,title:t,onClick:r,className:`text-xs px-1.5 py-0.5 rounded font-mono ${n?`bg-[#6272a4] text-white`:`text-[#f8f8f2] hover:bg-[#44475a]`}`,children:e})}function EF({x:e,y:t,term:n,cwd:r,hasReveal:i,onClose:a,onOpenSearch:o,onReveal:s,onSaveScrollback:c}){let{t:l}=K(`terminal`),u=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&a()},t=e=>{e.key===`Escape`&&a()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]);let d=typeof window<`u`&&e+220>window.innerWidth?e-220:e,f=typeof window<`u`&&t+260>window.innerHeight?t-260:t,p=/Mac/i.test(navigator.platform||``)?`⌘`:`Ctrl+`,m=n.getSelection(),h=m.length>0;function g(){h&&(Aa(m),a())}function _(){ka().then(e=>{if(e)try{n.paste(e)}catch{}}),a()}function v(){try{n.selectAll()}catch{}a()}function y(){try{n.clear()}catch{}a()}function b(){o(),a()}function x(){c(),a()}function S(){r&&s(r),a()}return(0,$.jsxs)(`div`,{ref:u,role:`menu`,"data-terminal-context-menu":!0,style:{position:`fixed`,left:d,top:f,minWidth:200},className:`bg-[#1f1f29] border border-[#44475a] rounded-md shadow-lg py-1 z-50 text-sm`,children:[(0,$.jsx)(DF,{onClick:g,disabled:!h,label:l(`common:actions.copy`),shortcut:p+`C`}),(0,$.jsx)(DF,{onClick:_,label:l(`contextMenu.paste`),shortcut:p+`V`}),(0,$.jsx)(DF,{onClick:v,label:l(`contextMenu.selectAll`),shortcut:p+`A`}),(0,$.jsx)(OF,{}),(0,$.jsx)(DF,{onClick:y,label:l(`contextMenu.clear`),shortcut:p+`K`}),(0,$.jsx)(DF,{onClick:b,label:l(`contextMenu.search`),shortcut:p+`F`}),(0,$.jsx)(DF,{onClick:x,label:l(`contextMenu.saveScrollback`)}),r&&i&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(OF,{}),(0,$.jsx)(DF,{onClick:S,label:l(`contextMenu.openPath`,{path:kF(r,40)})})]})]})}function DF({onClick:e,label:t,shortcut:n,disabled:r}){return(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{r||e()},disabled:r,className:`w-full text-left px-3 py-1.5 flex justify-between items-center ${r?`text-[#6272a4] cursor-not-allowed`:`text-[#f8f8f2] hover:bg-[#44475a]`}`,children:[(0,$.jsx)(`span`,{children:t}),n&&(0,$.jsx)(`span`,{className:`text-xs text-[#6272a4] tabular-nums`,children:n})]})}function OF(){return(0,$.jsx)(`div`,{className:`my-1 border-t border-[#44475a]`})}function kF(e,t){return e.length<=t?e:`…`+e.slice(e.length-t+1)}async function AF(e,t=`terminal-scrollback.txt`){let n=e.buffer.active,r=[];for(let e=0;e<n.length;e++){let t=n.getLine(e);t&&r.push(t.translateToString(!0))}let i=r.join(`
|
|
48
|
+
`))}function Dj(e,t){let n=(e??``).normalize(`NFKD`).replace(/[\u0300-\u036f]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``),r=t.trim()||`mission`;return`${n||r}.txt`}function Oj(){let{t:e}=K(`agent`),{active:t,messages:n,renameConversation:r,deleteConversation:i,startNewConversation:a,favoriteConversationIds:o,toggleFavoriteConversation:s}=aP(),{projects:c}=pt(),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(!1),y=(0,Q.useRef)(null),b=(0,Q.useRef)(null),x=t?.pinned_project_id?c.find(e=>e.id===t.pinned_project_id)??null:null,S=t?.title?.trim()||e(`header.untitled`),C=t?o.has(t.id):!1;(0,Q.useEffect)(()=>{if(!l)return;let e=e=>{y.current&&!y.current.contains(e.target)&&u(!1)},t=e=>{e.key===`Escape`&&u(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[l]),(0,Q.useEffect)(()=>{l||v(!1)},[l]),(0,Q.useEffect)(()=>{d&&(b.current?.focus(),b.current?.select())},[d]);let w=(0,Q.useCallback)(()=>{m(t?.title??``),f(!0),u(!1)},[t?.title]),T=(0,Q.useCallback)(async()=>{if(t&&(f(!1),(t.title??``)!==p.trim()))try{await r(t.id,p)}catch{J.error(e(`header.renameFailed`))}},[t,p,r,e]),E=(0,Q.useCallback)(async(t,n)=>{u(!1);try{await navigator.clipboard.writeText(t),g(n),setTimeout(()=>g(e=>e===n?null:e),1400)}catch{J.error(e(`header.copyFailed`))}},[e]),D=(0,Q.useCallback)(async()=>{if(t){u(!1);try{await navigator.clipboard.writeText(Ej(t,n,x)),g(`transcript`),J.success(e(`header.copyTranscriptSuccess`,{defaultValue:`Transcript copied`})),setTimeout(()=>g(e=>e===`transcript`?null:e),1400)}catch{J.error(e(`header.copyTranscriptFailed`,{defaultValue:`Could not copy transcript`}))}}},[t,n,x,e]),O=(0,Q.useCallback)(()=>{if(t){u(!1);try{let r=Ej(t,n,x),i=new Blob([r],{type:`text/plain;charset=utf-8`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=Dj(t.title,t.id),document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a),J.success(e(`header.exportTranscriptSuccess`,{defaultValue:`Transcript export started`}))}catch{J.error(e(`header.exportTranscriptFailed`,{defaultValue:`Could not export transcript`}))}}},[t,n,x,e]),k=(0,Q.useCallback)(async()=>{if(t){u(!1),v(!1);try{await i(t.id),a(t.pinned_project_id)}catch{J.error(e(`header.deleteFailed`))}}},[t,i,a,e]),A=(0,Q.useCallback)(()=>{t&&(s(t.id),u(!1))},[t,s]);if(!t)return null;let j=[{id:`name`,label:e(`header.copyName`),value:t.title??S},{id:`id`,label:e(`header.copyId`),value:t.id},...x?[{id:`project`,label:e(`header.copyProject`),value:x.name},{id:`path`,label:e(`header.copyProjectPath`),value:x.path}]:[]];return(0,$.jsxs)(`div`,{ref:y,"data-agent-interactive":!0,className:`relative flex h-12 shrink-0 items-center gap-2 border-b border-border px-4`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5 text-sm`,children:[x&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`max-w-[42%] shrink-0 truncate font-mono text-[12px] text-foreground/35`,title:x.path,children:x.path}),(0,$.jsx)(Zo,{className:`h-3.5 w-3.5 shrink-0 text-foreground/25`,"aria-hidden":!0})]}),d?(0,$.jsx)(`input`,{ref:b,value:p,onChange:e=>m(e.target.value),onBlur:()=>void T(),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),T()):e.key===`Escape`&&(e.preventDefault(),f(!1))},placeholder:e(`header.renamePlaceholder`),className:`min-w-0 flex-1 rounded-md border border-accent-primary/40 bg-surface/60 px-2 py-0.5 text-sm text-foreground outline-none focus:border-accent-primary/70`,maxLength:200}):(0,$.jsx)(`button`,{type:`button`,onDoubleClick:w,title:e(`header.renameHint`),className:`min-w-0 flex-1 truncate text-left font-medium text-foreground/85`,children:S})]}),(0,$.jsx)(Rc,{}),(0,$.jsx)(`button`,{type:`button`,"data-testid":`agent-conv-menu-trigger`,"aria-label":e(`header.menu`),"aria-haspopup":`menu`,"aria-expanded":l,onClick:()=>u(e=>!e),className:X(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-foreground/45 transition-colors hover:bg-surface hover:text-foreground/80`,l&&`bg-surface text-foreground/80`),children:(0,$.jsx)(gs,{className:`h-4 w-4`})}),(0,$.jsx)(N_,{children:l&&(0,$.jsx)(Ny.div,{role:`menu`,"data-testid":`agent-conv-menu`,initial:{opacity:0,y:-4,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.98},transition:{duration:.14,ease:`easeOut`},className:`absolute right-3 top-11 z-50 min-w-[220px] overflow-hidden rounded-xl border border-border/50 bg-card/95 p-1 shadow-2xl backdrop-blur-xl`,children:_?(0,$.jsxs)(`div`,{className:`p-2`,"data-testid":`agent-conv-delete-confirm`,children:[(0,$.jsx)(`p`,{className:`px-1 pb-2.5 text-xs leading-relaxed text-foreground/70`,children:e(`header.deleteConfirm`)}),(0,$.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,"data-testid":`agent-conv-delete-confirm-btn`,onClick:()=>void k(),className:`flex-1 rounded-lg bg-destructive/90 px-2.5 py-1.5 text-xs font-medium text-white transition-colors hover:bg-destructive`,children:e(`header.delete`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>v(!1),className:`flex-1 rounded-lg border border-border/60 px-2.5 py-1.5 text-xs text-foreground/80 transition-colors hover:bg-surface/80`,children:e(`common:actions.cancel`)})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":`agent-conv-rename`,onClick:w,className:`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-sm text-foreground/85 transition-colors hover:bg-surface/80`,children:[(0,$.jsx)(jn,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`}),e(`header.rename`)]}),(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":`agent-conv-favorite`,onClick:A,className:`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-sm text-foreground/85 transition-colors hover:bg-surface/80`,children:[(0,$.jsx)(Ps,{className:X(`h-3.5 w-3.5 shrink-0`,C?`text-accent-primary`:`text-foreground/50`),fill:C?`currentColor`:`none`}),e(C?`header.removeFavorite`:`header.addFavorite`)]}),(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":`agent-conv-delete`,onClick:()=>v(!0),className:`group/del flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-sm text-foreground/85 transition-colors hover:bg-destructive/10 hover:text-destructive`,children:[(0,$.jsx)(Rn,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50 group-hover/del:text-destructive`}),e(`header.delete`)]}),(0,$.jsx)(`div`,{className:`my-1 h-px bg-border/50`}),(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":`agent-conv-copy-transcript`,onClick:()=>void D(),className:`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-sm text-foreground/85 transition-colors hover:bg-surface/80`,children:[h===`transcript`?(0,$.jsx)(Sn,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`}):(0,$.jsx)(ls,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,children:e(`header.copyTranscript`,{defaultValue:`Copy transcript`})})]}),(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":`agent-conv-export-transcript`,onClick:O,className:`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-sm text-foreground/85 transition-colors hover:bg-surface/80`,children:[(0,$.jsx)(En,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,children:e(`header.exportTranscript`,{defaultValue:`Export transcript (.txt)`})})]}),j.map(e=>e===`divider`?null:(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":`agent-conv-copy-${e.id}`,onClick:()=>void E(e.value,e.id),className:`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-sm text-foreground/85 transition-colors hover:bg-surface/80`,children:[h===e.id?(0,$.jsx)(Sn,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`}):(0,$.jsx)(ls,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,children:e.label})]},e.id))]})})})]})}var kj=new Set([`building`,`on_review`,`pr_draft`,`no_changes`,`pr_closed`,`implementation_failed`,`pr_failed`]);function Aj(e){return kj.has(e)}function jj(e){return!!(Aj(e.decision)||e.phase===`launched`||e.phase===`running`||e.runtime?.failure&&e.decision!==`discarded`&&e.decision!==`superseded`)}function Mj(e){let t=[];for(let[n,r]of e.entries()){if(r.role!==`system`)continue;let e=wo(r.content);e&&t.push({messageId:r.id,envelope:e,position:n})}let n=new Map;for(let e of t){let t=n.get(e.envelope.prDeliveryId);if(!t){n.set(e.envelope.prDeliveryId,e);continue}let r=zt(t.envelope.updatedAt,e.envelope.updatedAt);(r===1||r===null&&e.position>t.position)&&n.set(e.envelope.prDeliveryId,e)}let r=new Set(t.map(({envelope:e})=>e.supersedesDeliveryId).filter(e=>!!e)),i=new Set,a=[...n.values()];for(let e of a){let t=e.envelope.restoredFromDeliveryId;if(!t)continue;let n=null;for(let t of a){if(t.envelope.supersedesDeliveryId!==e.envelope.prDeliveryId)continue;if(!n){n=t;continue}let r=zt(n.envelope.createdAt,t.envelope.createdAt);(r===1||(r===0||r===null)&&t.position>n.position)&&(n=t)}n&&n.envelope.prDeliveryId!==t||(r.delete(e.envelope.prDeliveryId),r.add(t),i.add(t))}let o=new Map;for(let e of n.values()){if(r.has(e.envelope.prDeliveryId))continue;let t=o.get(e.envelope.railIndex)??[];t.push(e),o.set(e.envelope.railIndex,t)}for(let e of o.values()){if(e.length<=1)continue;let t=e[0];for(let n of e.slice(1))zt(t.envelope.createdAt,n.envelope.createdAt)===1&&(t=n);for(let n of e)n.envelope.prDeliveryId!==t.envelope.prDeliveryId&&r.add(n.envelope.prDeliveryId)}let s=t.map(e=>r.has(e.envelope.prDeliveryId)&&(e.envelope.decision!==`superseded`||i.has(e.envelope.prDeliveryId))?{...e,envelope:{...e.envelope,decision:i.has(e.envelope.prDeliveryId)?`discarded`:`superseded`}}:e),c=new Map,l=new Set,u=[];for(let e of s){if(n.get(e.envelope.prDeliveryId)?.messageId!==e.messageId){l.add(e.messageId);continue}c.set(e.messageId,e.envelope),jj(e.envelope)&&u.push(e)}return{byMessageId:c,duplicateMessageIds:l,pinned:u}}function Nj({row:e}){let{t}=K(`agent`);return(0,$.jsxs)(`div`,{"data-testid":`agent-run-failure-marker`,className:`flex items-center gap-2 rounded-lg border border-destructive/30 bg-destructive/[0.06] px-3 py-1.5 text-[11px] text-foreground/70 backdrop-blur-sm`,children:[(0,$.jsx)(zn,{className:`h-3.5 w-3.5 shrink-0 text-destructive`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[(0,$.jsx)(`span`,{className:`font-medium text-destructive`,children:t(`runFailure.marker`,{rail:e.railIndex+1,code:e.code})}),e.detail&&(0,$.jsxs)(`span`,{className:`text-foreground/55`,children:[` · `,e.detail]})]}),(0,$.jsx)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`agent-run-failure-open`,onClick:()=>nO({prDeliveryId:e.prDeliveryId??null,runIds:[e.runId]}),className:`shrink-0 rounded-md border border-destructive/35 px-2 py-0.5 text-[10px] font-medium text-destructive transition-colors hover:bg-destructive/10`,children:t(`runFailure.openCard`)})]})}function Pj({content:e,contextRefs:t}){let{t:n}=K(`agent`),[r,i]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{"data-testid":`agent-system-briefing`,className:`flex flex-col items-end gap-1`,children:[(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,onClick:()=>i(e=>!e),"aria-expanded":r,className:X(`inline-flex items-center gap-1.5 rounded-full border border-border/50 bg-surface/50 px-2.5 py-1 text-[11px] text-foreground/60 transition-colors hover:border-accent-primary/40 hover:text-foreground/80`),children:[(0,$.jsx)(Ln,{className:`h-3 w-3 text-accent-primary/70`,"aria-hidden":!0}),n(`runFailure.briefing.title`),r?(0,$.jsx)(Xo,{className:`h-3 w-3 opacity-60`,"aria-hidden":!0}):(0,$.jsx)(Zo,{className:`h-3 w-3 opacity-60`,"aria-hidden":!0})]}),r&&(0,$.jsx)(`div`,{className:`max-w-[85%] whitespace-pre-wrap rounded-2xl rounded-tr-sm border border-border/40 bg-surface/40 px-3.5 py-2 text-xs text-foreground/70`,"data-testid":`agent-system-briefing-body`,children:(0,$.jsx)(XD,{content:e,contextRefs:t})})]})}var Fj={pinnedMessageIds:new Set,pinned:[]};function Ij(e){let t=Ux();return(0,Q.useMemo)(()=>{if(!ve)return Fj;let n=[],r=new Set;for(let i of e){if(i.role!==`assistant`||!i.content.includes("```rail-launch"))continue;let{proposals:e}=Rx(i.content,!1);e.forEach((e,a)=>{Wx(t,i.id,i.intents,a)||(n.push({messageId:i.id,proposalIndex:a,proposal:e}),r.add(i.id))})}return{pinnedMessageIds:r,pinned:n}},[e,t])}var Lj=(0,Q.lazy)(()=>c(()=>import(`./JobDetailModal-DHeur9YK.js`).then(e=>({default:e.JobDetailModal})),__vite__mapDeps([6,1,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]))),Rj=(0,Q.lazy)(()=>c(()=>import(`./LoopPreviewModal-DbZd9isy.js`).then(e=>({default:e.LoopPreviewModal})),__vite__mapDeps([81,1,7,8,11,10,43,59,60,68,69,73,67,51,82,54,56]))),zj=new Set,Bj=new Set([`spec-framing.committed`]);function Vj(e){if(!e.startsWith(`{`))return!1;try{let t=JSON.parse(e);return typeof t?.kind==`string`&&Bj.has(t.kind)}catch{return!1}}function Hj({variant:e}){let{t}=K(`agent`),{active:n}=aP(),r=Ci(),i=Wy(n?.id??`__new-mission__`),a=r.transfers.find(e=>e.conversationId===n?.id);if(n&&!r.current&&a?.state===`detached`)return(0,$.jsxs)(`div`,{className:`flex h-full flex-col`,children:[e===`inline`&&(0,$.jsx)(Oj,{}),(0,$.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,$.jsx)(pn,{className:`h-8 w-8 text-accent-primary`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t(`window.detached`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{r.focus(n.id)},className:`rounded-md bg-accent-primary px-4 py-2 text-sm text-white`,children:t(`window.focus`)})]})]});let o=!!n&&!r.isEditable(n.id);return(0,$.jsx)(`div`,{className:`relative flex h-full min-h-0 flex-col`,inert:o||void 0,"aria-busy":o||void 0,children:(0,$.jsx)(Uj,{variant:e},`${n?.id??`__new-mission__`}:${i}`)})}function Uj({variant:e}){let{t}=K(`agent`),{active:n,messages:r,streamingText:i,isStreaming:a,liveTools:o,turnTools:s,queuedMessages:c,mcpEnabled:l,enablingMcp:u,enableMcpServer:d,providersReady:f,cycleTier:p,send:m}=aP(),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(),y=o.length>0?o:s,b=(0,Q.useRef)(null),x=Qy(i,a),{openRef:C,jobRef:w,closeJobRef:T,loopRef:E,closeLoopRef:D}=Rb(),O=n?.pinned_project_id??null,[k,A]=(0,Q.useState)(new Map),j=(0,Q.useMemo)(()=>{let e=new Set;for(let t of r)for(let n of t.attachment_ids??[])e.add(n);for(let t of c)for(let n of t.attachmentIds??[])e.add(n);return[...e].sort()},[r,c]).join(`\0`);(0,Q.useEffect)(()=>{let e=j?j.split(`\0`):[];if(!n?.id||e.length===0){A(new Map);return}let t=!1,r=new Set(e);return lo(n.id).then(e=>{t||A(new Map(e.filter(e=>r.has(e.id)).map(e=>[e.id,e])))}).catch(()=>{t||A(new Map)}),()=>{t=!0}},[n?.id,j]);let M=(0,Q.useMemo)(()=>O?e=>{C(O,e)}:void 0,[O,C]),N=wa().id===`code-rain`?t(`emptyTitleCodeRain`):t(`emptyTitle`),P=(0,Q.useMemo)(()=>Mj(r),[r]),F=Ij(r),I=n?Hy(n.id):null,L=(0,Q.useRef)(I?.atBottom??!0);(0,Q.useLayoutEffect)(()=>{let e=b.current;return e&&I&&(e.scrollTop=I.atBottom?e.scrollHeight:I.top),()=>{e&&n&&Vy(n.id,{top:e.scrollTop,atBottom:L.current})}},[n?.id]);let R=()=>{let e=b.current;e&&(L.current=e.scrollHeight-e.scrollTop-e.clientHeight<48,n&&Vy(n.id,{top:e.scrollTop,atBottom:L.current}))};(0,Q.useEffect)(()=>{L.current&&b.current?.scrollTo?.({top:b.current.scrollHeight,behavior:`auto`})},[r.length,x,o.length,c.length]);let z=e=>{e.shiftKey&&(e.key===`Tab`||e.code===`Tab`)&&(e.preventDefault(),e.stopPropagation(),p())},B=e===`inline`,V=B?`mx-auto flex w-full max-w-[820px] flex-1 flex-col overflow-hidden`:`flex flex-1 flex-col overflow-hidden`;return(0,$.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden `,onKeyDown:z,children:[f===!1&&(0,$.jsxs)(`div`,{className:`flex items-start gap-2 border-b border-border/50 bg-accent-warning/10 px-3 py-2 text-xs text-foreground`,children:[(0,$.jsx)(Qs,{className:`mt-0.5 h-4 w-4 shrink-0 text-accent-warning`}),(0,$.jsxs)(`div`,{className:`flex-1`,children:[(0,$.jsx)(`p`,{className:`font-medium`,children:t(`noProvider.title`)}),(0,$.jsx)(`p`,{className:`mt-0.5 text-foreground/70`,children:t(`noProvider.body`)})]})]}),f!==!1&&!l&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/50 bg-accent-warning/10 px-3 py-2 text-xs text-foreground`,children:[(0,$.jsx)(S,{className:`h-4 w-4 shrink-0 text-accent-warning`}),(0,$.jsx)(`span`,{className:`flex-1`,children:t(`degraded.body`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void d(),disabled:u,className:`rounded-md bg-accent-primary px-2 py-1 text-xs font-medium text-white disabled:opacity-60`,children:t(u?`degraded.enabling`:`degraded.enable`)})]}),B&&n&&(0,$.jsx)(Oj,{}),(0,$.jsxs)(`div`,{className:V,children:[(0,$.jsxs)(Ny.div,{ref:b,onScroll:R,initial:B?{opacity:0,y:8}:!1,animate:{opacity:1,y:0},transition:{duration:.35,ease:`easeOut`},className:`flex-1 space-y-5 overflow-y-auto px-4 py-4`,children:[r.length===0&&!a&&(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center text-center text-foreground/50`,children:[(0,$.jsx)(Vo,{className:`mb-2 h-8 w-8 text-accent-primary/60`}),(0,$.jsx)(`p`,{className:`text-sm font-medium text-foreground/70`,children:N}),(0,$.jsx)(`p`,{className:`mt-1 max-w-[280px] text-xs`,children:t(`emptyHint`)})]}),r.map((e,i)=>{if(e.role===`system`){if(Vj(e.content))return null;if(ve){let t=$D(e.content);if(t)return(0,$.jsx)(Nj,{row:t},e.id)}let n=P.byMessageId.get(e.id);return n?jj(n)?(0,$.jsxs)(`div`,{"data-testid":`agent-pr-pinned-marker`,className:`flex items-center gap-2 rounded-lg border border-border/40 bg-surface/30 px-3 py-1.5 text-[11px] text-foreground/45 backdrop-blur-sm`,children:[(0,$.jsx)(oc,{className:`h-3 w-3 shrink-0 text-accent-primary/50`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t(`prCard.pinned.marker`)}),(0,$.jsx)(gj,{decision:n.decision})]},e.id):(0,$.jsx)(mj,{envelope:n,conversationId:e.conversation_id},e.id):(P.duplicateMessageIds.has(e.id)||zj.has(e.id)||(zj.add(e.id),console.warn(`[agent-chat] skipping unrenderable system message ${e.id}`)),null)}if(ve&&eO(e))return(0,$.jsx)(Pj,{content:e.content,contextRefs:e.context_refs},e.id);let o=F.pinnedMessageIds.has(e.id);return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(ZD,{role:e.role,content:e.content,messageId:e.id,intents:e.intents??null,railProposalsPinned:o,tolerantFences:At(n?.provider),createdAt:e.created_at,isLast:!a&&i===r.length-1,isLatest:i===r.length-1,isStreaming:a,onPickOption:e=>void m(e),refsProjectId:O,onOpenRef:M,contextRefs:e.context_refs,deliveryStatus:e.delivery_status,deliveryReceipt:e.delivery_receipt,conversationId:e.conversation_id,attachments:(e.attachment_ids??[]).map(e=>k.get(e)).filter(e=>!!e)}),o&&(0,$.jsxs)(`div`,{"data-testid":`agent-rail-launch-pinned-marker`,className:`flex items-center gap-2 rounded-lg border border-border/40 bg-surface/30 px-3 py-1.5 text-[11px] text-foreground/45 backdrop-blur-sm`,children:[(0,$.jsx)(oc,{className:`h-3 w-3 shrink-0 text-accent-primary/50`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t(`railCard.pinnedMarker`)})]})]},e.id)}),a&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[x&&(0,$.jsx)(ZD,{role:`assistant`,content:x,streaming:!0,tolerantFences:At(n?.provider)}),(0,$.jsx)(Vb,{tool:o.length?o[o.length-1].tool:null,onClick:()=>g(!0)})]}),c.length>0&&(0,$.jsx)(`div`,{className:`space-y-2`,"data-testid":`agent-queued-messages`,children:c.map(e=>(0,$.jsx)(QD,{item:e,conversationId:n?.id,onEdit:e=>{n&&v(t=>({conversationId:n.id,queueId:e,revision:(t?.revision??0)+1}))},attachments:(e.attachmentIds??[]).map(e=>k.get(e)).filter(e=>!!e)},`${n?.id}:${e.queueId}`))})]}),(0,$.jsx)(N_,{initial:!1,children:n&&(P.pinned.length>0||F.pinned.length>0)&&(0,$.jsx)(wj,{pinned:P.pinned,proposals:F.pinned,projectId:O,conversationId:n.id,inline:B},`agent-pr-pinned-dock`)}),B?(0,$.jsx)(`div`,{className:`shrink-0 px-4 pb-4`,children:(0,$.jsxs)(Ny.div,{layoutId:`agent-composer-dock`,transition:{layout:{type:`spring`,stiffness:350,damping:34}},className:`relative mx-auto w-full max-w-[680px] rounded-2xl border border-border/60 bg-card/90 p-3 shadow-2xl backdrop-blur-xl`,"data-testid":`agent-composer-dock`,children:[(0,$.jsx)(UA,{active:a,radius:`1rem`,inset:-3}),(0,$.jsx)(MA,{queueEditRequest:_})]})}):(0,$.jsxs)(`div`,{className:`relative shrink-0 border-t border-border/50 bg-surface/30 p-3`,"data-testid":`agent-composer-dock`,children:[(0,$.jsx)(UA,{active:a,radius:`0.75rem`,inset:-2}),(0,$.jsx)(MA,{hideProjectSelector:!0,queueEditRequest:_})]})]}),w&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Lj,{jobId:w.jobId,projectId:w.projectId,onClose:T})}),E&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Rj,{loop:E,onClose:D})}),h&&(0,$.jsx)(Ub,{tools:y,streaming:a,onClose:()=>g(!1)})]})}var Wj=8,Gj=3e3;function Kj(){let{t:e}=K(`agent`),{conversations:t,active:n,selectConversation:r,deleteConversation:i,startNewConversation:a,streamingConversationIds:o,liveByConversation:s}=aP(),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(0),[m,h]=(0,Q.useState)(null),g=(0,Q.useRef)(null),_=(0,Q.useRef)(null),v=(0,Q.useRef)(null),y=(0,Q.useMemo)(()=>{let e=e=>{let t=Date.parse(e.updated_at);return Number.isNaN(t)?0:t};return[...t].sort((t,n)=>e(n)-e(t))},[t]),b=t.length>Wj,x=(0,Q.useMemo)(()=>{let t=u.trim().toLowerCase();if(!t)return y;let n=e(`mission.untitled`).toLowerCase();return y.filter(e=>(e.title?.trim().toLowerCase()||n).includes(t))},[y,u,e]),S=x.length+1,C=(0,Q.useCallback)(()=>{g.current&&clearTimeout(g.current),g.current=null,h(null)},[]);(0,Q.useEffect)(()=>()=>{g.current&&clearTimeout(g.current)},[]),(0,Q.useEffect)(()=>{if(!c)return;let e=e=>{_.current&&!_.current.contains(e.target)&&T()};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[c]);let w=()=>{let e=n?y.findIndex(e=>e.id===n.id):-1;p(e>=0?e+1:0),l(!0)},T=()=>{l(!1),d(``),C()},E=e=>{e!==n?.id&&r(e),T()},D=()=>{a(null),T()},O=e=>{g.current&&clearTimeout(g.current),h(e),g.current=setTimeout(()=>{h(null),g.current=null},Gj)},k=async t=>{C();let a=n?.id===t,o=y.find(e=>e.id!==t)??null;try{await i(t),a&&o&&await r(o.id)}catch{J.error(e(`mission.deleteFailed`))}},A=()=>{if(f===0)D();else{let e=x[f-1];e&&E(e.id)}},j=e=>{if(!c){e.key===`ArrowDown`&&(e.preventDefault(),w());return}if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=e.key===`ArrowDown`?1:-1;p(e=>(e+t+S)%S)}else e.key===`Home`?(e.preventDefault(),p(0)):e.key===`End`?(e.preventDefault(),p(S-1)):e.key===`Enter`?(e.preventDefault(),A()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),m?C():(T(),v.current?.focus()))},M=n?.title?.trim()||e(`mission.untitled`);return(0,$.jsxs)(`div`,{className:`relative min-w-0`,ref:_,"data-agent-interactive":!0,onKeyDown:j,children:[(0,$.jsxs)(`button`,{ref:v,type:`button`,"data-testid":`mission-trigger`,onClick:()=>c?T():w(),"aria-haspopup":`listbox`,"aria-expanded":c,"aria-controls":`agent-mission-listbox`,title:e(`mission.label`),className:`flex min-w-0 items-center gap-1.5 rounded-md px-1.5 py-1 text-sm font-medium text-foreground hover:bg-surface/70`,children:[(0,$.jsx)(bn,{className:`h-3.5 w-3.5 shrink-0 text-accent-primary`}),(0,$.jsx)(`span`,{className:`min-w-0 max-w-[150px] truncate`,children:M}),(0,$.jsx)(Xo,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`})]}),(0,$.jsx)(N_,{children:c&&(0,$.jsxs)(Ny.div,{initial:{opacity:0,y:-6,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-6,scale:.98},transition:{duration:.16,ease:`easeOut`},className:`absolute left-0 top-full z-10 mt-1 w-72 overflow-hidden rounded-xl border border-border/60 bg-card/95 shadow-2xl backdrop-blur-xl`,children:[b&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/50 px-3 py-2`,children:[(0,$.jsx)(In,{className:`h-3.5 w-3.5 text-foreground/40`}),(0,$.jsx)(`input`,{autoFocus:!0,value:u,onChange:e=>{d(e.target.value),p(0)},placeholder:e(`mission.searchPlaceholder`),className:`w-full bg-transparent text-sm text-foreground outline-none placeholder:text-foreground/40`})]}),(0,$.jsxs)(`div`,{id:`agent-mission-listbox`,role:`listbox`,"aria-label":e(`mission.label`),"aria-activedescendant":`agent-mission-opt-${f}`,className:`max-h-72 overflow-y-auto py-1`,children:[(0,$.jsxs)(Ny.div,{id:`agent-mission-opt-0`,role:`option`,"aria-selected":!1,tabIndex:-1,"data-testid":`mission-new`,onClick:D,onMouseEnter:()=>p(0),initial:{opacity:0,x:-6},animate:{opacity:1,x:0},transition:{duration:.14},className:`flex w-full cursor-pointer items-center gap-2.5 px-3 py-1.5 text-left text-sm font-medium text-foreground ${f===0?`bg-surface/70`:`hover:bg-surface/70`}`,children:[(0,$.jsx)(Pn,{className:`h-4 w-4 text-accent-primary`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e(`mission.new`)})]}),x.length>0&&(0,$.jsx)(`div`,{className:`mx-3 my-1 h-px bg-border/50`,"aria-hidden":!0}),x.length===0&&u.trim()!==``&&(0,$.jsx)(`div`,{className:`px-3 py-2 text-xs text-foreground/40`,children:e(`mission.noMatches`)}),x.map((e,t)=>(0,$.jsx)(qj,{conversation:e,index:t+1,highlighted:f===t+1,activeId:n?.id??null,streaming:o.has(e.id),queuedCount:s.get(e.id)?.queued.length??0,confirming:m===e.id,onHover:()=>p(t+1),onSelect:()=>E(e.id),onArmDelete:()=>O(e.id),onConfirmDelete:()=>void k(e.id),onCancelDelete:C},e.id))]})]})})]})}function qj({conversation:e,index:t,highlighted:n,activeId:r,streaming:i,queuedCount:a,confirming:o,onHover:s,onSelect:c,onArmDelete:l,onConfirmDelete:u,onCancelDelete:d}){let{t:f}=K(`agent`),p=e.title?.trim()||f(`mission.untitled`),m=e.id===r;return o?(0,$.jsxs)(`div`,{id:`agent-mission-opt-${t}`,role:`option`,"aria-selected":m,"data-testid":`mission-row-${e.id}`,className:`flex w-full items-center gap-2 bg-destructive/10 px-3 py-1.5 text-sm`,children:[(0,$.jsx)(Rn,{className:`h-3.5 w-3.5 shrink-0 text-destructive`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-destructive`,children:f(i?`mission.deleteLiveConfirm`:`mission.deleteConfirm`)}),(0,$.jsx)(`button`,{type:`button`,"data-testid":`mission-confirm-yes`,onClick:e=>{e.stopPropagation(),u()},"aria-label":f(`mission.confirmDelete`),className:`rounded-md p-1 text-destructive hover:bg-destructive/20`,children:(0,$.jsx)(Sn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,"data-testid":`mission-confirm-no`,onClick:e=>{e.stopPropagation(),d()},"aria-label":f(`mission.cancelDelete`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface`,children:(0,$.jsx)(Vn,{className:`h-3.5 w-3.5`})})]}):(0,$.jsxs)(Ny.div,{id:`agent-mission-opt-${t}`,role:`option`,"aria-selected":m,tabIndex:-1,"data-testid":`mission-row-${e.id}`,onClick:c,onMouseEnter:s,initial:{opacity:0,x:-6},animate:{opacity:1,x:0},transition:{duration:.14,delay:Math.min(t*.03,.18)},className:`group flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-left text-sm text-foreground ${n?`bg-surface/70`:`hover:bg-surface/70`}`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:p}),(0,$.jsx)(`span`,{className:`shrink-0 tabular-nums text-xs text-foreground/40`,title:Yb(e.updated_at),children:Jb(e.updated_at)}),i&&(0,$.jsxs)(`span`,{"data-testid":`mission-live-${e.id}`,"aria-label":f(`mission.working`),className:`relative flex h-1.5 w-1.5 shrink-0`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full bg-accent-primary opacity-60`}),(0,$.jsx)(`span`,{className:`relative inline-flex h-1.5 w-1.5 rounded-full bg-accent-primary`})]}),a>0&&(0,$.jsx)(`span`,{"data-testid":`mission-queued-${e.id}`,"aria-label":f(`mission.queuedBadge`,{n:a}),title:f(`mission.queuedBadge`,{n:a}),className:`shrink-0 rounded-full border border-border/60 bg-surface px-1.5 text-[9px] font-semibold leading-4 text-foreground/60`,children:a}),m&&(0,$.jsx)(Sn,{className:`h-3.5 w-3.5 shrink-0 text-accent-primary`}),(0,$.jsx)(`button`,{type:`button`,"data-testid":`mission-delete-${e.id}`,onClick:e=>{e.stopPropagation(),l()},"aria-label":f(`mission.delete`,{title:p}),className:`shrink-0 rounded-md p-0.5 text-foreground/50 opacity-0 transition-opacity hover:bg-surface hover:text-destructive focus-visible:opacity-100 group-focus-within:opacity-100 group-hover:opacity-100`,children:(0,$.jsx)(Rn,{className:`h-3.5 w-3.5`})})]})}var Jj=Q.forwardRef(({className:e,type:t,...n},r)=>(0,$.jsx)(`input`,{type:t,className:X(`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-xs ring-offset-background file:border-0 file:bg-transparent file:text-xs file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,e),ref:r,...n}));Jj.displayName=`Input`;var Yj=6e4,Xj={data:null,fetchedAt:0,inFlight:null,error:null},Zj=new Set;function Qj(){Zj.forEach(e=>{try{e()}catch{}})}function $j(){return Xj.data!==null&&Date.now()-Xj.fetchedAt<Yj}async function eM(e){if(Xj.inFlight)return Xj.inFlight;let t=(async()=>{let t=await fetch(`${Xe}/api/setup-prerequisites`,{signal:e});if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();if(typeof n?.ok!=`boolean`||!Array.isArray(n?.prerequisites)||!Array.isArray(n?.missingRequired))throw Error(`Malformed prerequisites response`);return Xj.data=n,Xj.fetchedAt=Date.now(),Xj.error=null,Xj.inFlight=null,Qj(),Xj.data})().catch(t=>{throw Xj.inFlight=null,e?.aborted?t:(Xj.error=t instanceof Error?t:Error(String(t)),Qj(),Xj.error)});return Xj.inFlight=t,t}var tM=!1;function nM(){tM||typeof window>`u`||(window.addEventListener(`focus`,()=>{Xj.fetchedAt=0,Xj.data=null,eM().catch(()=>{})}),tM=!0)}function rM(){let[,e]=(0,Q.useState)(0),[t,n]=(0,Q.useState)(()=>!$j()),[r,i]=(0,Q.useState)(Xj.error);(0,Q.useEffect)(()=>{nM();let t=()=>{e(e=>e+1),i(Xj.error),n(!1)};Zj.add(t);let r=new AbortController;return!$j()&&!Xj.inFlight?(n(!0),eM(r.signal).catch(e=>{r.signal.aborted||i(e instanceof Error?e:Error(String(e)))}).finally(()=>{r.signal.aborted||n(!1)})):Xj.inFlight&&Xj.inFlight.catch(()=>{}).finally(()=>{r.signal.aborted||n(!1)}),()=>{r.abort(),Zj.delete(t)}},[]);let a=(0,Q.useCallback)(async()=>{Xj.fetchedAt=0,Xj.data=null,Xj.error=null,n(!0);try{await eM()}catch(e){i(e instanceof Error?e:Error(String(e)))}finally{n(!1)}},[]);return{status:Xj.data,isLoading:t,error:r,recheck:a}}var iM={claude:{icon:`🤖`,label:`Claude`},codex:{icon:`⚡`,label:`Codex`},gemini:{icon:`✨`,label:`Gemini`},kimi:{icon:`🌙`,label:`Kimi`}};function aM(e){return e.toLowerCase().normalize(`NFKD`).replace(/[̀-ͯ]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`project`}function oM({blueprint:e,onSubmit:t,onBack:n,submitting:r,error:i,errorDetail:a}){let{t:o}=K(`builder`),{status:s}=rM(),[c,l]=(0,Q.useState)(e.product.name||``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(new Set([`claude`])),[g,_]=(0,Q.useState)({claude:!0}),[v,y]=(0,Q.useState)(!1),b=(0,Q.useMemo)(()=>`~/projects/${aM(c)}`,[c]),x=u?f:b;(0,Q.useEffect)(()=>{fetch(`/api/available-providers`).then(e=>e.json()).then(e=>{let t={};for(let[n,r]of Object.entries(e))n===`tiers`||n===`providerIssues`||n===`launchDescriptors`||typeof r==`boolean`&&(t[n]=r);_(t);let n=new Set;for(let[e,r]of Object.entries(t))r&&n.add(e);n.size>0&&h(n)}).catch(()=>{})},[]);let S=s?.prerequisites.find(e=>e.key===`gh`),C=!!(S?.installed&&S?.executable!==!1),w=C&&!!S?.authenticated,T=[`claude`,`codex`,`gemini`,`kimi`,...Object.keys(g)].filter((e,t,n)=>n.indexOf(e)===t).filter(e=>m.has(e)&&g[e]),E=c.trim()!==``&&x.trim()!==``&&T.length>0&&!r;return(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-md flex-col gap-4 p-6`,"data-testid":`commit-form`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold`,children:o(`commit.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`commit.description`)})]}),i&&(0,$.jsxs)(`div`,{className:`rounded-md bg-destructive/10 p-2 text-xs text-destructive`,"data-testid":`commit-error`,children:[(0,$.jsx)(`p`,{children:o(`commit.errors.${i}`,{defaultValue:o(`commit.errors.generic`)})}),a&&(0,$.jsx)(`p`,{className:`mt-1 opacity-80`,children:a})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium`,children:[o(`commit.nameLabel`),` `,(0,$.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,$.jsx)(Jj,{value:c,onChange:e=>l(e.target.value),"data-testid":`commit-name`})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium`,children:[o(`commit.locationLabel`),` `,(0,$.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,$.jsx)(Jj,{value:x,onChange:e=>{d(!0),p(e.target.value)},"data-testid":`commit-location`}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:o(`commit.locationHint`)})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:o(`commit.providersLabel`)}),(0,$.jsx)(`div`,{className:`flex gap-2`,children:Object.keys(g).map(e=>{let{icon:t,label:n}=iM[e]??{icon:`•`,label:e},r=g[e],i=m.has(e)&&r;return(0,$.jsxs)(`button`,{type:`button`,role:`checkbox`,"aria-checked":i,disabled:!r,"data-testid":`commit-provider-${e}`,onClick:()=>{h(t=>{let n=new Set(t);if(n.has(e)){if(n.size===1)return t;n.delete(e)}else n.add(e);return n})},className:X(`flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs transition-colors`,i?`border-accent-primary/60 bg-accent-primary/10`:`border-border/30 text-muted-foreground`,!r&&`cursor-not-allowed opacity-40`),children:[(0,$.jsx)(`span`,{children:t}),(0,$.jsx)(`span`,{className:`font-medium`,children:n})]},e)})})]}),C&&(0,$.jsxs)(`label`,{className:X(`flex items-center gap-2 rounded-md border border-border/30 px-3 py-2 text-xs`,!w&&`opacity-50`),children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:v&&w,disabled:!w,onChange:e=>y(e.target.checked),"data-testid":`commit-github`}),(0,$.jsx)(As,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{children:o(`commit.githubLabel`)}),!w&&(0,$.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:o(`commit.githubAuthHint`)})]}),(0,$.jsxs)(`div`,{className:`flex justify-between pt-2`,children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:n,disabled:r,children:o(`commit.back`)}),(0,$.jsxs)(Z,{size:`sm`,disabled:!E,"data-testid":`commit-submit`,onClick:()=>t({name:c.trim(),location:x.trim(),providers:T,createGithubRepo:v&&w}),children:[(0,$.jsx)(gc,{className:`mr-1.5 h-3.5 w-3.5`}),o(r?`commit.creating`:`commit.submit`)]})]})]})}function sM({session:e,autoFocus:t=!1}){let{t:n}=K(`builder`),{t:r}=K(`agent`),{availableIds:i,labels:a}=OA(),o=kt(e.provider),s=[e.provider,...i].filter((e,t,n)=>n.indexOf(e)===t).filter(kt),c=e=>r(`provider.${e}`,{defaultValue:a?.[e]??e}),l=()=>{!o||!e.draft.trim()||e.busy||!e.conversationReady||(e.send(e.draft),e.setDraft(``))};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 px-1`,children:[(0,$.jsx)(Ns,{className:`h-4 w-4 text-accent-primary`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground/80`,children:n(`mode.title`)})]}),(0,$.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(KE,{label:r(`provider.label`),value:e.provider,options:s.map(e=>({value:e,label:c(e)})),icon:Vo,onSelect:e.setProvider,disabled:!o||e.busy||!e.conversationReady,testId:`builder-provider-selector`}),(0,$.jsx)(ik,{models:e.models,model:e.model,onSelect:e.setModel,disabled:!o||e.busy||!e.conversationReady,testId:`builder-model-selector`}),e.efforts.length>0&&(0,$.jsx)(KE,{label:r(`effort.label`),value:e.effort,options:e.efforts.map(e=>({value:e,label:r(`effort.${e}`)})),icon:Ds,onSelect:e.setEffort,disabled:!o||e.busy||!e.conversationReady,testId:`builder-effort-selector`}),e.showSurpriseMe&&(0,$.jsxs)(`button`,{type:`button`,onClick:e.surpriseMe,disabled:!o||e.busy||!e.conversationReady,className:`ml-auto inline-flex items-center gap-1.5 rounded-full border border-accent-highlight/40 bg-accent-highlight/10 px-3 py-1 text-[11px] text-accent-highlight transition-colors hover:bg-accent-highlight/20 disabled:opacity-40`,"data-testid":`surprise-me`,children:[(0,$.jsx)(Ln,{className:`h-3 w-3`}),n(`shell.surpriseMe`)]})]}),!o&&(0,$.jsx)(`p`,{className:`mb-2 rounded-md border border-accent-warning/30 bg-accent-warning/10 px-2.5 py-2 text-xs text-accent-warning`,"data-testid":`builder-provider-unavailable`,children:n(`shell.providerUnavailable`)}),(0,$.jsxs)(`div`,{className:`relative flex items-end gap-2 rounded-xl border border-border/60 bg-background/60 px-3 py-2`,children:[(0,$.jsx)(`textarea`,{value:e.draft,disabled:!o,autoFocus:t,onChange:t=>e.setDraft(t.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),l())},rows:2,placeholder:n(`shell.inputPlaceholder`),"aria-label":n(`shell.inputPlaceholder`),"data-agent-interactive":!0,className:`min-h-[3.25rem] max-h-64 min-w-[12rem] flex-1 resize-y bg-transparent text-sm text-foreground outline-none placeholder:text-foreground/40`,"data-testid":`builder-input`}),(0,$.jsx)(`button`,{type:`button`,onClick:l,disabled:!o||e.busy||!e.draft.trim()||!e.conversationReady,"aria-label":r(`send`),className:`rounded-lg bg-accent-primary p-1.5 text-white transition-opacity disabled:opacity-40`,"data-testid":`builder-send`,children:(0,$.jsx)(Pt,{className:`h-4 w-4`})})]})]})}function cM(e){let t=Date.parse(e.includes(`T`)?e:e.replace(` `,`T`)+`Z`);return Number.isFinite(t)?Cr(new Date(t),{addSuffix:!0,locale:Ze()}):``}function lM({items:e,loading:t,disabled:n=!1,onResume:r,onDiscard:i}){let{t:a}=K(`builder`),[o,s]=(0,Q.useState)(null);return!t&&e.length===0?null:(0,$.jsxs)(Ny.section,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.24,ease:`easeOut`,delay:.08},className:`mt-4 w-full rounded-2xl border border-border/50 bg-card/70 p-3 shadow-lg backdrop-blur-xl`,"data-testid":`builder-recent`,"aria-label":a(`recent.title`),children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 px-1`,children:[(0,$.jsx)(Fs,{className:`h-3.5 w-3.5 text-accent-secondary`,"aria-hidden":!0}),(0,$.jsx)(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wider text-muted-foreground`,children:a(`recent.title`)}),t&&(0,$.jsx)(An,{className:`ml-auto h-3 w-3 animate-spin text-muted-foreground/60`,"aria-hidden":!0})]}),(0,$.jsx)(`ul`,{className:`space-y-1`,children:(0,$.jsx)(N_,{initial:!1,children:e.map(e=>{let t=e.productName||e.title||a(`recent.untitled`),c=o===e.id;return(0,$.jsxs)(Ny.li,{layout:!0,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,height:0},className:X(`group flex items-center gap-2 rounded-xl border border-transparent px-2.5 py-2 transition-colors`,`hover:border-border/60 hover:bg-surface/60`),"data-testid":`builder-recent-${e.id}`,children:[(0,$.jsxs)(`button`,{type:`button`,disabled:n,onClick:()=>r(e.id),className:`flex min-w-0 flex-1 items-center gap-2.5 text-left disabled:opacity-50`,"data-testid":`builder-recent-resume-${e.id}`,children:[(0,$.jsx)(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-accent-primary/10 text-accent-primary`,children:(0,$.jsx)(Mn,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-sm font-medium text-foreground`,children:t}),(0,$.jsxs)(`span`,{className:`mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[10px] text-muted-foreground`,children:[e.platform&&(0,$.jsx)(`span`,{children:e.platform}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,$.jsx)(kn,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),e.specCount>0?e.specsComplete?a(`recent.specsComplete`,{count:e.specCount}):a(`recent.specsInProgress`,{count:e.specCount}):a(`recent.dimensions`,{filled:e.dimensionsFilled,total:5})]}),e.pendingIssue&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-accent-warning`,"data-testid":`builder-recent-pending-issue`,children:[(0,$.jsx)(zn,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),a(`recent.pendingIssue`)]}),e.updatedAt&&(0,$.jsx)(`span`,{className:`opacity-80`,children:cM(e.updatedAt)})]})]})]}),(0,$.jsx)(`div`,{className:`flex shrink-0 items-center gap-0.5`,children:c?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>{s(null),i(e.id)},"aria-label":a(`recent.discardConfirm`),title:a(`recent.discardConfirm`),className:`rounded-md p-1 text-destructive hover:bg-destructive/10`,"data-testid":`builder-recent-discard-confirm-${e.id}`,children:(0,$.jsx)(Sn,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>s(null),"aria-label":a(`recent.discardCancel`),title:a(`recent.discardCancel`),className:`rounded-md p-1 text-muted-foreground hover:bg-surface`,"data-testid":`builder-recent-discard-cancel-${e.id}`,children:(0,$.jsx)(Vn,{className:`h-3.5 w-3.5`,"aria-hidden":!0})})]}):(0,$.jsx)(`button`,{type:`button`,onClick:()=>s(e.id),"aria-label":a(`recent.discard`),title:a(`recent.discard`),className:`rounded-md p-1 text-muted-foreground/40 opacity-0 transition-opacity hover:bg-surface hover:text-destructive focus-visible:opacity-100 group-hover:opacity-100`,"data-testid":`builder-recent-discard-${e.id}`,children:(0,$.jsx)(Rn,{className:`h-3.5 w-3.5`,"aria-hidden":!0})})})]},e.id)})})})]})}function uM({specsStarted:e,snapshot:t,maxSpecs:n=10}){let{t:r}=K(`builder`),i=t.status===`repairing`,a=t.status===`generating`?t.generation:null,o=(a&&a.total>0?a.phase===`audit`?.95:Math.min(.95,Math.max(.06,Math.max(0,a.from-1)/a.total)):null)??Math.min(.95,Math.max(.06,e/n)),s=i?Bn:Ln,c=i?r(`snapshot.repairing.${t.kind}`):a?r(`generation.phase.${a.phase}`,{from:a.from,to:a.to,total:a.total}):r(`generation.writing`);return(0,$.jsxs)(`div`,{className:`inline-flex max-w-full flex-col gap-1.5 rounded-xl border border-border/50 bg-surface/60 px-3 py-2 text-xs text-foreground/80`,"data-testid":`builder-generation-progress`,"data-phase":i?`repairing`:a?`generation-${a.phase}`:`generating`,role:`status`,"aria-live":`polite`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(An,{className:`h-3 w-3 shrink-0 animate-spin text-accent-info`,"aria-hidden":!0}),(0,$.jsx)(s,{className:`h-3 w-3 shrink-0 text-accent-primary`,"aria-hidden":!0}),(0,$.jsx)(N_,{mode:`wait`,initial:!1,children:(0,$.jsx)(Ny.span,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.16,ease:`easeOut`},className:`font-medium`,children:c},c)}),a&&a.totalTurns>0&&(0,$.jsx)(`span`,{className:`rounded-full bg-muted/60 px-2 py-px font-mono text-[10px] text-muted-foreground`,"data-testid":`builder-generation-turn`,children:r(`generation.turn`,{turn:a.turn,total:a.totalTurns})}),e>0&&(0,$.jsx)(N_,{mode:`wait`,initial:!1,children:(0,$.jsx)(Ny.span,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},transition:{duration:.14},className:`rounded-full bg-accent-primary/10 px-2 py-px font-mono text-[10px] text-accent-primary`,"data-testid":`builder-generation-count`,children:r(`generation.specCount`,{n:e})},e)})]}),(0,$.jsx)(`div`,{className:`h-1 w-56 max-w-full overflow-hidden rounded-full bg-border/40`,"aria-hidden":!0,children:(0,$.jsx)(Ny.div,{className:`h-full rounded-full bg-gradient-to-r from-accent-primary/70 to-accent-highlight/80`,initial:{width:`6%`},animate:{width:`${Math.round(o*100)}%`},transition:{type:`spring`,stiffness:120,damping:20}})})]})}var dM=`specrails-desktop:milestone-launch-mode`,fM=`specrails-desktop:milestone-sequential-plans`;function pM(){try{return localStorage.getItem(`specrails-desktop:milestone-launch-mode`)===`parallel`?`parallel`:`sequential`}catch{return`sequential`}}function mM(e){try{localStorage.setItem(dM,e)}catch{}}var hM=`specrails-desktop:milestone-auto-advance`;function gM(){try{return localStorage.getItem(hM)===`true`}catch{return!1}}function _M(e){try{localStorage.setItem(hM,e?`true`:`false`)}catch{}}function vM(){try{return localStorage.getItem(`specrails-desktop:milestone-sequential-plans`)===null?!1:(localStorage.removeItem(fM),!0)}catch{return!1}}function yM(e){return`M${e}`}function bM(e,t){return t===`chain_active`?`chain_active`:t===`no_tickets`?`no_tickets`:t===`milestone_not_found`?`milestone_not_found`:e===503?`unavailable`:`launch_rejected`}async function xM(e){try{let t=await e.json();return t&&typeof t==`object`?t:{}}catch{return{}}}async function SM(e,t,n=pM(),r={}){let i=typeof r==`function`?{fetchImpl:r}:r,a=i.fetchImpl??fetch,o=i.autoAdvance??gM(),s;try{s=await a(`/api/projects/${e}/blueprint/milestones/${t}/launch`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({mode:n,autoAdvance:o})})}catch(e){return{ok:!1,reason:`network`,error:`network`,detail:e instanceof Error?e.message:String(e)}}let c=await xM(s);if(!s.ok){let e=typeof c.error==`string`?c.error:`http_${s.status}`;return{ok:!1,reason:bM(s.status,e),error:e,...typeof c.detail==`string`?{detail:c.detail}:{},...typeof c.chainId==`string`?{chainId:c.chainId}:{}}}let l=Array.isArray(c.launched)?c.launched.filter(e=>!!e&&typeof e==`object`&&typeof e.chunk==`number`):[],u=Array.isArray(c.pending)?c.pending.filter(e=>Array.isArray(e)):[];return{ok:!0,chainId:typeof c.chainId==`string`?c.chainId:null,launched:l,pending:u,ticketCount:l.reduce((e,t)=>e+(Array.isArray(t.ticketIds)?t.ticketIds.length:0),0),skippedCount:u.reduce((e,t)=>e+t.length,0)}}async function CM(e,t,n,r){let i;try{i=await r(`/api/projects/${e}/blueprint/chains/${t}/${n}`,{method:`POST`})}catch(e){return{ok:!1,error:`network`,detail:e instanceof Error?e.message:String(e)}}let a=await xM(i);return i.ok?{ok:!0,chain:Ut(a.chain)}:{ok:!1,error:typeof a.error==`string`?a.error:`http_${i.status}`,...typeof a.detail==`string`?{detail:a.detail}:{}}}function wM(e,t,n=fetch){return CM(e,t,`resume`,n)}function TM(e,t,n=fetch){return CM(e,t,`cancel`,n)}async function EM(e,t,n,r=fetch){let i;try{i=await r(`/api/projects/${e}/blueprint/chains/${t}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({autoAdvance:n})})}catch(e){return{ok:!1,error:`network`,detail:e instanceof Error?e.message:String(e)}}let a=await xM(i);return i.ok?{ok:!0,chain:Ut(a.chain)}:{ok:!1,error:typeof a.error==`string`?a.error:`http_${i.status}`,...typeof a.detail==`string`?{detail:a.detail}:{}}}var DM=[`Problem Statement`,`Proposed Solution`,`Out of Scope`,`Technical Considerations`,`Estimated Complexity`],OM={problemMinChars:200,solutionMinChars:500,outOfScopeMinBullets:3,technicalMinBullets:5,criteriaMin:6,criteriaMax:10,criterionMinChars:20},kM=new Set([`scaffold`,`feature`,`verification`]),AM=new Set([`critical`,`high`,`medium`,`low`]),jM=/^(?:todo|tbd|n\/?a|works?|test(?: it)?|criterion|acceptance criterion)$/i;function MM(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:null}function NM(e){return e.trim().toLocaleLowerCase(`en-US`)}function PM(e){let t=[...e.matchAll(/^##[ \t]+(.+?)[ \t]*$/gm)],n=t.map(e=>e[1].trim()),r=new Map;return t.forEach((i,a)=>{let o=(i.index??0)+i[0].length,s=a+1<t.length?t[a+1].index??e.length:e.length;r.set(n[a],e.slice(o,s).trim())}),{headings:n,bodies:r}}function FM(e){return e.split(/\r?\n/).filter(e=>/^\s*[-*+]\s+\S/.test(e)).length}function IM(e,t){let n=[],r=MM(e),i=Array.isArray(r?.m1Specs)?r.m1Specs:[],a=t.milestoneLabel.trim().toUpperCase(),o=(e,t,r,i,a={})=>{n.push({specIndex:e,field:t,code:r,message:i,params:e===null?a:{n:e+1,...a}})};r?.specsComplete!==!0&&o(null,`specsComplete`,`batch_incomplete`,`Generation is not complete yet.`),(i.length<t.minSpecs||i.length>t.maxSpecs)&&o(null,`m1Specs`,`spec_count`,`The batch needs ${t.minSpecs}-${t.maxSpecs} specs.`,{min:t.minSpecs,max:t.maxSpecs,count:i.length});let s=new Map;return i.forEach((e,n)=>{let r=MM(e),i=n+1;if(!r){o(n,`spec`,`invalid_shape`,`Spec ${i} must be an object.`);return}let c=typeof r.kind==`string`?r.kind:``;kM.has(c)||o(n,`kind`,`invalid_kind`,`Spec ${i} needs a valid kind.`),t.requireScaffold&&n===0&&c!==`scaffold`&&o(n,`kind`,`scaffold_first`,`The first spec must be the project scaffold.`),t.requireScaffold&&n>0&&c===`scaffold`&&o(n,`kind`,`duplicate_scaffold`,`Spec ${i} cannot be another scaffold.`);let l=typeof r.title==`string`?r.title.trim():``;if(!l)o(n,`title`,`required`,`Spec ${i} needs a title.`);else{let e=NM(l),t=s.get(e);t===void 0?s.set(e,n):o(n,`title`,`duplicate`,`Spec ${i} duplicates spec ${t+1}.`,{other:t+1})}let u=typeof r.shortSummary==`string`?r.shortSummary.trim():``;(!u||u.length>240||/[\r\n]/.test(u))&&o(n,`shortSummary`,`summary`,`Spec ${i} needs a one-line summary under 240 characters.`);let d=typeof r.priority==`string`?r.priority:``;AM.has(d)||o(n,`priority`,`invalid_priority`,`Spec ${i} needs a valid priority.`);let f=typeof r.description==`string`?r.description.trim():``,p=PM(f);(!/^## Problem Statement(?:\r?\n|$)/.test(f)||p.headings.length!==DM.length||p.headings.some((e,t)=>e!==DM[t]))&&o(n,`description`,`canonical_sections`,`Spec ${i} is missing the canonical sections.`);for(let e of DM)(p.bodies.get(e)??``).trim()||o(n,`description`,`empty_section`,`Spec ${i} has an empty ${e} section.`,{heading:e});for(let[e,t]of[[`Problem Statement`,OM.problemMinChars],[`Proposed Solution`,OM.solutionMinChars]]){let r=(p.bodies.get(e)??``).trim();r&&r.length<t&&o(n,`description`,`section_depth`,`Spec ${i} ${e} is too thin.`,{heading:e,min:t})}for(let[e,t]of[[`Out of Scope`,OM.outOfScopeMinBullets],[`Technical Considerations`,OM.technicalMinBullets]]){let r=p.bodies.get(e)??``;r&&FM(r)<t&&o(n,`description`,`section_bullets`,`Spec ${i} needs ${t} ${e} bullets.`,{heading:e,min:t})}let m=p.bodies.get(`Estimated Complexity`)??``;m&&!/^(?:Low|Medium|High|Very High)\s*(?:[—\-:]\s*)\S/i.test(m)&&o(n,`description`,`complexity_format`,`Spec ${i} needs a justified complexity.`),t.requireScaffold&&n===0&&f&&!/\bREADME\b/i.test(f)&&o(n,`description`,`scaffold_readme`,`The scaffold spec must mention the existing README.`);let h=Array.isArray(r.acceptanceCriteria)?r.acceptanceCriteria:[];(h.length<OM.criteriaMin||h.length>OM.criteriaMax)&&o(n,`acceptanceCriteria`,`criteria_count`,`Spec ${i} needs ${OM.criteriaMin}-${OM.criteriaMax} acceptance criteria.`,{count:h.length,min:OM.criteriaMin,max:OM.criteriaMax});let g=new Set;h.forEach((e,t)=>{let r=typeof e==`string`?e.trim():``;if(r.length<OM.criterionMinChars||jM.test(r)){o(n,`acceptanceCriteria`,`criterion_quality`,`Spec ${i} criterion ${t+1} is not concrete.`,{criterion:t+1});return}let a=NM(r);g.has(a)&&o(n,`acceptanceCriteria`,`duplicate_criterion`,`Spec ${i} repeats an acceptance criterion.`,{criterion:t+1}),g.add(a)});let _=Array.isArray(r.labels)?r.labels.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean):[];new Set(_.map(e=>e.toUpperCase())).has(a)||o(n,`labels`,`milestone_label`,`Spec ${i} needs the ${a} label.`,{label:a}),_.every(e=>e.toUpperCase()===a)&&o(n,`labels`,`domain_label`,`Spec ${i} needs a domain label.`,{label:a});let v=r.dependsOnIndex;v!==void 0&&(!Number.isInteger(v)||v<0||v>=n)&&o(n,`dependsOnIndex`,`invalid_dependency`,`Spec ${i} must depend only on an earlier spec.`),t.requireScaffold&&n===0&&v!==void 0&&o(n,`dependsOnIndex`,`scaffold_dependency`,`The scaffold cannot declare a dependency.`)}),{valid:n.length===0,issues:n}}var LM=new Set([`batch_incomplete`,`spec_count`]);function RM(e,t,n,r,i={}){let a=Bt(e),o=Object.values(a).filter(Boolean).length,s=Object.keys(a).length,c=t&&typeof t==`object`&&!Array.isArray(t)?t:null,l=Array.isArray(c?.m1Specs)?c.m1Specs.length:e?.m1Specs.length??0,u=Array.isArray(c?.m1Specs)?c.m1Specs:e?.m1Specs??[],d=new Set;u.forEach((e,t)=>{let n=e&&typeof e==`object`?e:null,r=typeof n?.description==`string`?n.description.trim():``,i=Array.isArray(n?.acceptanceCriteria)?n.acceptanceCriteria:[];(r.length>0||i.length>0)&&d.add(t)});let f=d.size,p=c?c.specsComplete===!0:e?.specsComplete===!0,m=i.generating===!0&&l>0,h=!m&&l>0&&f<l&&!p,g=m?[]:n.issues.filter(e=>!LM.has(e.code)&&(!h||e.specIndex===null||d.has(e.specIndex))),_={key:`blueprint`,state:o===s?`done`:`pending`,params:{filled:o,total:s}},v;v=m?`writing`:l===0?`pending`:l<r.minSpecs||l>r.maxSpecs?`blocked`:p?`done`:`pending`;let y={key:`specs`,state:v,params:{count:l,written:f,min:r.minSpecs,max:r.maxSpecs}},b={key:`audit`,state:m?`writing`:l===0||h&&g.length===0?`pending`:g.length===0?`done`:`blocked`,params:{count:g.length}};return{ready:n.valid,steps:[_,y,b],issues:g}}function zM(e){return e.field===`shortSummary`?`quality.summary`:e.field===`title`&&e.code===`required`?`quality.title_required`:e.field===`title`&&e.code===`duplicate`?`quality.title_duplicate`:`quality.${e.code}`}function BM(e,t){let n={n:t.specIndex===null?``:t.specIndex+1,...t.params??{}};return e(zM(t),{...n,defaultValue:t.message})}var VM=new Set([`gh_not_installed`,`gh_not_authenticated`,`gh_scope`,`gh_repo_exists`,`gh_network`]);function HM(e){return`progress.githubErrors.${e&&VM.has(e)?e:`generic`}`}var UM=[`create-dir`,`git-init`,`assemble`,`blueprint`,`tickets`,`register`,`github`],WM={minSpecs:5,maxSpecs:10};function GM(e){let t=e&&typeof e==`object`?e:null;if(!t)return null;let n=t.phase;if(n!==`outline`&&n!==`details`&&n!==`audit`&&n!==`repair`)return null;let r=e=>typeof e==`number`&&Number.isFinite(e)?e:0;return{phase:n,from:r(t.from),to:r(t.to),total:r(t.total),turn:r(t.turn),totalTurns:r(t.totalTurns)}}function KM(e,t){let n=e&&typeof e==`object`?e:{},r=new Date().toISOString();if(n.continuing){let e=GM(n.generation);return e?{status:`generating`,generation:e}:t}return n.status===`accepted`?{status:`accepted`,repaired:n.repaired===!0,repairAttempted:n.repairAttempted===!0,at:r,...n.generationHalted===!0?{generationHalted:!0}:{}}:n.status===`rejected`?{status:`rejected`,reason:n.reason??`invalid_json`,detail:n.detail??``,repairAttempted:n.repairAttempted===!0,at:r}:t.status===`repairing`||t.status===`generating`?{status:`idle`}:t}function qM(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`&&typeof e.id==`string`).map(e=>({id:String(e.id),title:typeof e.title==`string`?e.title:null,productName:typeof e.productName==`string`?e.productName:null,platform:typeof e.platform==`string`?e.platform:null,provider:typeof e.provider==`string`?e.provider:`claude`,model:typeof e.model==`string`?e.model:null,updatedAt:typeof e.updated_at==`string`?e.updated_at:``,messageCount:typeof e.messageCount==`number`?e.messageCount:0,specCount:typeof e.specCount==`number`?e.specCount:0,specsComplete:e.specsComplete===!0,dimensionsFilled:typeof e.dimensionsFilled==`number`?e.dimensionsFilled:0,hasSnapshot:e.hasSnapshot===!0,pendingIssue:e.pendingIssue===`invalid_json`||e.pendingIssue===`truncated`||e.pendingIssue===`missing_version`?e.pendingIssue:null})):[]}function JM(e,t){let{t:n}=K(`builder`),{registerHandler:r,unregisterHandler:i}=tt(),{setActiveProjectId:a}=pt(),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)([]),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(`chat`),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)([]),[O,k]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(!1),[P,F]=(0,Q.useState)(!1),[I,L]=(0,Q.useState)(`claude`),[R,z]=(0,Q.useState)(null),[B,V]=(0,Q.useState)([]),[H,U]=(0,Q.useState)(``),[W,ee]=(0,Q.useState)([]),[te,ne]=(0,Q.useState)(`medium`),[re,ie]=(0,Q.useState)(``),[ae,oe]=(0,Q.useState)({status:`idle`}),[se,ce]=(0,Q.useState)([]),[le,ue]=(0,Q.useState)(!1),[de,fe]=(0,Q.useState)(!1),G=R??H,pe=(0,Q.useMemo)(()=>{let e=vt(I,G);return W.filter(t=>e.includes(t))},[G,I,W]),me=(0,Q.useRef)(null),he=(0,Q.useRef)(null),ge=(0,Q.useRef)(I),_e=(0,Q.useRef)(null),ve=(0,Q.useRef)(!1),ye=(0,Q.useRef)(te),be=(0,Q.useRef)(pe),xe=(0,Q.useRef)(R),Se=(0,Q.useRef)(!1),Ce=(0,Q.useRef)(t.onFinished);(0,Q.useEffect)(()=>{me.current=o},[o]),(0,Q.useEffect)(()=>{ge.current=I},[I]),(0,Q.useEffect)(()=>{_e.current=w},[w]),(0,Q.useEffect)(()=>{ye.current=te},[te]),(0,Q.useEffect)(()=>{be.current=pe},[pe]),(0,Q.useEffect)(()=>{xe.current=R},[R]),(0,Q.useEffect)(()=>{Ce.current=t.onFinished},[t.onFinished]);let we=(0,Q.useCallback)(async()=>{let e=me.current;if(e)return e;if(he.current)return he.current;let t=fetch(`/api/blueprint/conversations`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:ge.current,...xe.current?{model:xe.current}:{}})}).then(e=>e.json()).then(e=>e.conversation?(me.current=e.conversation.id,s(e.conversation.id),e.conversation.id):null).catch(()=>null).finally(()=>{he.current=null});return he.current=t,t},[]),Te=(0,Q.useCallback)(async()=>{ue(!0);try{let e=await(await fetch(`/api/blueprint/conversations?resumable=1`)).json();ce(qM(e.conversations))}catch{ce([])}finally{ue(!1)}},[]);(0,Q.useEffect)(()=>{e&&Te()},[e,Te]),(0,Q.useEffect)(()=>{if(!e)return;let t=!1;return V([]),U(``),ee([]),ne(``),fetch(`/api/blueprint/models?provider=${encodeURIComponent(I)}`).then(e=>e.json()).then(e=>{if(t)return;V(e.models??[]);let n=e.defaultModel??e.models?.[0]?.value??``,r=e.efforts??[],i=vt(I,n),a=r.filter(e=>i.includes(e));U(n),ee(r),ne(e=>a.includes(e)?e:Dt(I,n)??``)}).catch(()=>{}),()=>{t=!0}},[e,I]);let{availableIds:Ee}=OA({enabled:e});(0,Q.useEffect)(()=>{if(me.current||Ee.length===0||Ee.includes(I))return;let e=Ee.filter(kt);e.length!==0&&(L(Ot(e)),z(null))},[Ee,I]);let De=(0,Q.useCallback)(e=>{L(e),z(null);let t=me.current;t&&fetch(`/api/blueprint/conversations/${t}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:e})}).catch(()=>{})},[]),Oe=(0,Q.useCallback)(e=>{z(e);let t=vt(I,e),n=W.filter(e=>t.includes(e));ne(t=>n.includes(t)?t:Dt(I,e)??``);let r=me.current;r&&fetch(`/api/blueprint/conversations/${r}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({model:e})}).catch(()=>{})},[I,W]);(0,Q.useEffect)(()=>{if(!e)return;let t=`builder-session`;return r(t,e=>{let t=e,r=me.current!==null&&t.conversationId===me.current,i=_e.current!==null&&t.commitId===_e.current;if(t.type===`blueprint.stream`&&r)d(e=>(e??``)+String(t.delta??``));else if(t.type===`blueprint.repairing`&&r){let e=t.kind===`truncated`||t.kind===`quality`?t.kind:`invalid_json`;_(!0),oe({status:`repairing`,kind:e,manual:t.manual===!0,attempt:typeof t.attempt==`number`?t.attempt:1})}else if(t.type===`blueprint.generating`&&r){let e=GM(t);d(null),_(!0),e&&oe({status:`generating`,generation:e})}else if(t.type===`blueprint.done`&&r){let e=t.continuing===!0;d(null),_(e);let n=String(t.fullText??``);n.trim()&&!e&&l(e=>[...e,{role:`assistant`,content:n,createdAt:new Date().toISOString()}]);let r=qt(t.blueprint),i=t.rawBlueprint===void 0?t.blueprint:t.rawBlueprint;if(!r&&t.snapshot===void 0){let e=ln(n);r=e.blueprint,i=e.rawBlueprint}r&&(p(r),h(i)),oe(e=>t.snapshot===void 0?r?{status:`accepted`,repaired:!1,repairAttempted:!1,at:new Date().toISOString()}:e:KM(t.snapshot,e))}else if(t.type===`blueprint.error`&&r)d(null),_(!1),oe(e=>e.status===`repairing`||e.status===`generating`?{status:`idle`}:e),J.error(n(`errors.turnFailed`),{description:String(t.error??``)});else if(t.type===`blueprint.commit_progress`&&i){let e=String(t.step),r=t.status,i=typeof t.detail==`string`?t.detail:void 0,a=typeof t.code==`string`?t.code:void 0;e===`github`&&r===`warning`&&!ve.current&&(ve.current=!0,J.warning(n(HM(a)),{description:i})),D(t=>[...t.filter(t=>t.step!==e),{step:e,status:r,detail:i,code:a}])}else t.type===`blueprint.commit_done`&&i?(k(String(t.projectId)),y(`done`)):t.type===`blueprint.commit_failed`&&i&&(Se.current=!1,F(!1),J.error(n(`errors.commitFailed`),{description:String(t.error??``)}),y(`commit`),x(`commit_failed`),C(String(t.error??``)))}),()=>i(t)},[e,r,i,n]);let ke=(0,Q.useCallback)((e,t={})=>{let r=e.trim();if(!r||g||de)return;l(e=>[...e,{role:`user`,content:r,createdAt:new Date().toISOString(),...t.intent?{intent:t.intent}:{}}]),_(!0);let i=ye.current,a=be.current.includes(i);we().then(e=>{if(!e){_(!1),J.error(n(`errors.startFailed`));return}return fetch(`/api/blueprint/conversations/${e}/send`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:r,...xe.current?{model:xe.current}:{},...a?{reasoning_effort:i}:{},...t.intent?{intent:t.intent}:{}})}).then(e=>{!e.ok&&e.status!==202&&(_(!1),J.error(n(`errors.turnFailed`)))}).catch(()=>{_(!1),J.error(n(`errors.turnFailed`))})})},[g,de,we,n]),Ae=(0,Q.useCallback)(async e=>{if(!g){fe(!0);try{let t=await fetch(`/api/blueprint/conversations/${e}`);if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();if(!n.conversation)throw Error(`missing conversation`);me.current=n.conversation.id,s(n.conversation.id),n.conversation.provider&&L(n.conversation.provider),z(n.conversation.model??null),l((n.messages??[]).filter(e=>typeof e.content==`string`&&e.content.trim()!==``).map(e=>({role:e.role,content:e.content,createdAt:e.created_at??new Date().toISOString(),...e.intent===`surprise`||e.intent===`approve`?{intent:e.intent}:{}})));let r=qt(n.blueprint);p(r),h(r?n.rawBlueprint??n.blueprint:null),oe(KM(n.snapshot,{status:`idle`})),d(null),_(!1),y(`chat`),x(null),C(null),D([]),ie(``)}catch{J.error(n(`recent.resumeFailed`))}finally{fe(!1)}}},[g,n]),je=(0,Q.useCallback)(async e=>{try{let t=await fetch(`/api/blueprint/conversations/${e}`,{method:`DELETE`});if(!t.ok&&t.status!==404)throw Error(`HTTP ${t.status}`);ce(t=>t.filter(t=>t.id!==e))}catch{J.error(n(`recent.discardFailed`))}},[n]),Me=(0,Q.useCallback)(async()=>{let e=me.current;if(!(!e||g)){_(!0);try{let t=await fetch(`/api/blueprint/conversations/${e}/repair-snapshot`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(te?{reasoningEffort:te}:{})});if(t.status===202)return;let r=await t.json().catch(()=>({}));_(!1),r.error===`nothing_to_repair`?J.info(n(`snapshot.nothingToRepair`)):r.error===`no_session`?J.error(n(`snapshot.noSession`)):r.error===`streaming`?J.info(n(`snapshot.alreadyStreaming`)):J.error(n(`errors.turnFailed`))}catch{_(!1),J.error(n(`errors.turnFailed`))}}},[g,te,n]),Ne=(0,Q.useCallback)(()=>ke(n(`prompts.surpriseMe`),{intent:`surprise`}),[ke,n]),Pe=(0,Q.useCallback)(()=>ke(n(`prompts.approve`),{intent:`approve`}),[ke,n]),Fe=(0,Q.useCallback)(e=>{!f||Se.current||(Se.current=!0,F(!0),x(null),C(null),D([]),ve.current=!1,fetch(`/api/blueprint/commit`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({blueprint:m??f,...e,...me.current?{conversationId:me.current}:{}})}).then(async e=>{let t=await e.json().catch(()=>({}));e.status===202&&t.commitId?(T(t.commitId),_e.current=t.commitId,y(`progress`)):(x(t.error??`generic`),C(t.detail??null)),Se.current=!1,F(!1)}).catch(()=>{Se.current=!1,F(!1),x(`generic`),C(null)}))},[f,m]),Ie=(0,Q.useCallback)(async()=>{if(!(!O||A)){j(!0);try{let e=pM(),t=gM(),r=await SM(O,1,e,{autoAdvance:t}),i=yM(1);if(r.ok){let o=r.launched.length+r.pending.length;e===`sequential`&&r.pending.length>0?J.success(n(t?`milestoneProgress.toast.launched`:`milestoneProgress.toast.launchedCheckpoint`,{milestone:i,count:r.ticketCount,n:o})):r.skippedCount>0?J.warning(n(`milestoneProgress.toast.launchedPartial`,{milestone:i,count:r.ticketCount,skipped:r.skippedCount})):J.success(n(`milestoneProgress.toast.launchedAll`,{milestone:i,count:r.ticketCount,n:o})),a(O),N(!0)}else r.reason===`chain_active`?(J.info(n(`milestoneProgress.toast.chainActive`,{milestone:i})),a(O),N(!0)):J.error(n(`done.launchFailed`),{description:r.detail??r.error})}finally{j(!1)}}},[O,A,a,n]),Le=(0,Q.useCallback)(()=>{O&&a(O),Ce.current()},[O,a]),Re=(0,Q.useCallback)(()=>{let e=me.current;e&&fetch(`/api/blueprint/conversations/${e}/abort`,{method:`POST`}).catch(()=>{}),s(null),me.current=null,he.current=null,l([]),d(null),p(null),h(null),oe({status:`idle`}),ce([]),fe(!1),_(!1),y(`chat`),x(null),C(null),T(null),D([]),ve.current=!1,k(null),N(!1),j(!1),Se.current=!1,F(!1),L(`claude`),z(null),V([]),U(``),ee([]),ne(`medium`),ie(``)},[]),ze=Bt(f),Be=Object.values(ze).some(Boolean)||c.length>0||re.trim().length>0,Ve=(0,Q.useMemo)(()=>IM(m??f,{milestoneLabel:`M1`,minSpecs:WM.minSpecs,maxSpecs:WM.maxSpecs,requireScaffold:!0}),[f,m]),He=ae.status===`generating`,Ue=(0,Q.useMemo)(()=>RM(f,m??f,Ve,WM,{generating:He}),[f,m,Ve,He]),We=(0,Q.useMemo)(()=>{if(Ve.valid)return null;let e=Ve.issues[0];return e?BM(n,e):null},[Ve,n]),Ge=(0,Q.useMemo)(()=>on(u),[u]);return{phase:v,messages:c,streamBuffer:u,blueprint:f,busy:g,commitError:b,commitErrorDetail:S,commitSteps:E,createdProjectId:O,launching:A,launched:M,submitting:P,conversationReady:e&&!de,conversationId:o,dirty:Be,canProposeCommit:Ve.valid,specQualityDetail:We,readiness:Ue,snapshot:ae,generation:Ge,recent:se,recentLoading:le,resume:Ae,discardRecent:je,repairSnapshot:Me,showSurpriseMe:c.length<=1&&v===`chat`,provider:I,model:R,models:B,efforts:pe,effort:te,draft:re,setDraft:ie,setEffort:ne,setProvider:De,setModel:Oe,send:ke,surpriseMe:Ne,approveBlueprint:Pe,goToCommit:()=>y(`commit`),backToChat:()=>y(`chat`),submitCommit:Fe,launchM1:Ie,openProject:Le,abortAndReset:Re}}var YM={done:`bg-accent-success`,onReview:`bg-accent-warning`,inProgress:`bg-accent-info animate-pulse`,failed:`bg-destructive`,todo:`bg-muted-foreground/25`},XM={planned:`border-border/60 bg-surface/60 text-foreground/60`,committed:`border-accent-primary/40 bg-accent-primary/10 text-accent-primary`,running:`border-accent-info/40 bg-accent-info/10 text-accent-info`,delivered:`border-accent-warning/40 bg-accent-warning/10 text-accent-warning`,done:`border-accent-success/40 bg-accent-success/10 text-accent-success`};function ZM({counts:e,className:t}){let{t:n}=K(`builder`),r=en(e);return(0,$.jsx)(`div`,{className:X(`flex h-1.5 w-full overflow-hidden rounded-full bg-muted`,t),role:`img`,"aria-label":n(`milestoneProgress.counts`,{delivered:an(e),total:e.total,done:e.done}),"data-testid":`milestone-progress-bar`,children:r.map(e=>(0,$.jsx)(`div`,{"data-segment":e.key,className:X(`h-full transition-all duration-500`,YM[e.key]),style:{width:`${e.pct}%`},title:`${n(`milestoneProgress.legend.${e.key}`)} · ${e.count}`},e.key))})}function QM({state:e}){let{t}=K(`builder`);return(0,$.jsx)(`span`,{"data-testid":`milestone-state-pill`,"data-state":e,className:X(`inline-flex shrink-0 items-center rounded-full border px-1.5 py-px text-[9px] font-semibold uppercase tracking-wide`,XM[e]),children:t(`milestoneProgress.state.${e}`)})}function $M(e){let[t,n]=(0,Q.useState)(()=>Date.now());return(0,Q.useEffect)(()=>{if(!e)return;n(Date.now());let t=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(t)},[e]),t}function eN({rail:e,now:t,onReview:n,onOpenRail:r}){let{t:i}=K(`builder`),a=e.name??i(`milestoneProgress.rail.fallbackName`,{n:e.railIndex+1}),o=e.active&&e.startedAt?Math.max(0,t-Date.parse(e.startedAt)):null,s=e.delivery?.decision??null,c=s!==null&&Jt.has(s)&&e.delivery!==null;return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border/30 bg-surface/40 px-2 py-1.5`,"data-testid":`milestone-rail-row`,"data-rail-index":e.railIndex,children:[e.chunkIndex!=null&&(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-muted/70 px-1 py-px text-[9px] font-mono tabular-nums text-muted-foreground`,title:i(`milestoneProgress.rail.chunk`,{k:e.chunkIndex}),children:e.chunkIndex}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>r?.(e.railIndex),className:`min-w-0 flex-1 truncate text-left text-[11px] font-medium hover:underline`,title:i(`milestoneProgress.rail.open`),children:a}),e.active?(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-accent-info`,"data-testid":`milestone-rail-running`,children:[(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}),o==null?i(`milestoneProgress.state.running`):i(`milestoneProgress.rail.running`,{elapsed:Or(o)})]}):s?(0,$.jsx)(gj,{decision:s}):(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`milestoneProgress.rail.noDelivery`)}),c&&e.delivery&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n?.(e.delivery.id),className:`inline-flex shrink-0 items-center gap-1 rounded-md border border-accent-primary/40 bg-accent-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-accent-primary hover:bg-accent-primary/20`,"data-testid":`milestone-rail-review`,children:[(0,$.jsx)(vs,{className:`h-3 w-3`,"aria-hidden":!0}),i(`milestoneProgress.rail.review`)]})]})}function tN({checked:e,onChange:t,disabled:n=!1,compact:r=!1,testId:i=`milestone-auto-advance`}){let{t:a}=K(`builder`),o=a(e?`milestoneProgress.chain.autoAdvanceHint`:`milestoneProgress.chain.checkpointHint`);return(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e,"aria-label":a(`milestoneProgress.chain.autoAdvance`),disabled:n,onClick:()=>t(!e),title:o,className:X(`group inline-flex items-center gap-1.5 rounded-md border px-1.5 py-1 text-left text-[10px] transition-colors disabled:opacity-50`,e?`border-accent-success/40 bg-accent-success/10 text-accent-success`:`border-border/50 text-muted-foreground hover:text-foreground`,r?`py-0.5`:`w-full`),"data-testid":i,"data-checked":e,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:X(`relative inline-flex h-3 w-5 shrink-0 items-center rounded-full transition-colors`,e?`bg-accent-success/70`:`bg-muted-foreground/30`),children:(0,$.jsx)(`span`,{className:X(`absolute h-2 w-2 rounded-full bg-background shadow transition-transform`,e?`translate-x-2.5`:`translate-x-0.5`)})}),e?(0,$.jsx)(wn,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}):(0,$.jsx)(Ss,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:a(`milestoneProgress.chain.autoAdvance`)}),!r&&(0,$.jsx)(`span`,{className:`hidden truncate text-[9px] font-normal text-muted-foreground group-hover:inline`,children:o})]})}function nN({chain:e,busy:t=!1,onResume:n,onCancel:r,onSetAutoAdvance:i}){let{t:a}=K(`builder`),o=$t(e),s=e.status===`paused`,c=Vt(e),l=nn(e.pauseReason),u=s?a(`milestoneProgress.chain.reasons.${l.key}`,{detail:l.detail,defaultValue:e.pauseReason??``}):null,d=e.mode===`sequential`&&(o||s||c)&&!!i;return(0,$.jsxs)(`div`,{className:X(`rounded-md border px-2 py-1.5 text-[10px]`,s?`border-accent-warning/40 bg-accent-warning/5`:c?`border-accent-success/40 bg-accent-success/5`:o?`border-accent-info/30 bg-accent-info/5`:`border-border/30 bg-surface/40`),"data-testid":`milestone-chain-row`,"data-status":e.status,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(kn,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`font-medium`,children:e.mode===`parallel`?a(`milestoneProgress.chain.parallelTitle`):a(`milestoneProgress.chain.title`)}),(0,$.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,a(`milestoneProgress.chain.progress`,{k:Math.min(e.nextChunk,e.totalChunks),n:e.totalChunks})]}),(0,$.jsx)(`span`,{className:`flex-1`}),c&&n&&(0,$.jsxs)(`button`,{type:`button`,disabled:t,onClick:()=>n(e.id),className:`inline-flex items-center gap-1 rounded-md border border-accent-success/40 bg-accent-success/10 px-1.5 py-0.5 font-medium text-accent-success hover:bg-accent-success/20 disabled:opacity-50`,"data-testid":`milestone-chain-launch-next`,children:[t?(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Mn,{className:`h-3 w-3`,"aria-hidden":!0}),a(`milestoneProgress.chain.launchNext`)]}),s&&n&&(0,$.jsxs)(`button`,{type:`button`,disabled:t,onClick:()=>n(e.id),className:`inline-flex items-center gap-1 rounded-md border border-accent-success/40 bg-accent-success/10 px-1.5 py-0.5 font-medium text-accent-success hover:bg-accent-success/20 disabled:opacity-50`,"data-testid":`milestone-chain-resume`,children:[t?(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Mn,{className:`h-3 w-3`,"aria-hidden":!0}),a(`milestoneProgress.chain.resume`)]}),(o||s||c)&&r&&(0,$.jsx)(`button`,{type:`button`,disabled:t,onClick:()=>r(e.id),className:`inline-flex items-center gap-1 rounded-md border border-border/60 px-1.5 py-0.5 text-muted-foreground hover:text-foreground disabled:opacity-50`,title:a(`milestoneProgress.chain.cancel`),"data-testid":`milestone-chain-cancel`,children:(0,$.jsx)(Vn,{className:`h-3 w-3`,"aria-hidden":!0})})]}),(0,$.jsx)(`div`,{className:`mt-0.5 flex items-center gap-1 text-muted-foreground`,children:s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ic,{className:`h-3 w-3 shrink-0 text-accent-warning`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`text-accent-warning`,children:a(`milestoneProgress.chain.paused`,{reason:u})})]}):c?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ss,{className:`h-3 w-3 shrink-0 text-accent-success`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`text-accent-success`,"data-testid":`milestone-chain-checkpoint`,children:a(`milestoneProgress.chain.checkpoint`,{k:e.nextChunk,next:e.nextChunk+1,n:e.totalChunks})}),e.headBranch&&(0,$.jsxs)(`span`,{className:`truncate font-mono`,title:e.headBranch,children:[` · `,a(`milestoneProgress.chain.stackedOn`,{branch:e.headBranch})]})]}):e.status===`running`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ce,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:a(`milestoneProgress.chain.waiting`,{k:e.nextChunk})}),e.headBranch&&e.mode===`sequential`&&(0,$.jsxs)(`span`,{className:`truncate font-mono`,title:e.headBranch,children:[` · `,a(`milestoneProgress.chain.stackedOn`,{branch:e.headBranch})]}),e.mode===`sequential`&&!e.autoAdvance&&e.nextChunk<e.totalChunks&&(0,$.jsxs)(`span`,{className:`shrink-0`,"data-testid":`milestone-chain-checkpoint-note`,children:[` · `,a(`milestoneProgress.chain.checkpointNote`)]})]}):e.status===`completed`?(0,$.jsx)(`span`,{children:a(`milestoneProgress.chain.completed`)}):e.status===`cancelled`?(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(Cn,{className:`h-3 w-3`,"aria-hidden":!0}),a(`milestoneProgress.chain.cancelled`)]}):(0,$.jsx)(`span`,{children:a(`milestoneProgress.chain.waiting`,{k:e.nextChunk})})}),d&&i&&(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(tN,{checked:e.autoAdvance,disabled:t,onChange:t=>i(e.id,t),testId:`milestone-chain-auto-advance`})})]})}function rN({progress:e,actions:t,chainBusy:n,onReview:r,onOpenRail:i,onResume:a,onCancel:o,onSetAutoAdvance:s,className:c}){let{t:l}=K(`builder`),u=e.rails.some(e=>e.active),d=$M(u),{counts:f}=e,p=e.chain!==null&&e.chain.status!==`completed`&&e.chain.status!==`cancelled`||e.chain&&e.chain.status===`completed`&&e.rails.length>0&&u?e.chain:null;return(0,$.jsxs)(`div`,{className:X(`rounded-md border border-border/30 px-2 py-1.5`,c),"data-testid":`milestone-card`,"data-milestone":e.n,"data-state":e.state,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`rounded bg-accent-primary/10 px-1.5 py-px text-[9px] font-semibold text-accent-primary`,children:Gt(e.n)}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] font-medium`,children:e.title}),(0,$.jsx)(QM,{state:e.state})]}),f.total>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ZM,{counts:f,className:`mt-1.5`}),(0,$.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-2 text-[10px] tabular-nums text-muted-foreground`,children:[(0,$.jsx)(`span`,{"data-testid":`milestone-counts`,children:l(`milestoneProgress.counts`,{delivered:an(f),total:f.total,done:f.done})}),f.inProgress>0&&(0,$.jsxs)(`span`,{className:`text-accent-info`,children:[l(`milestoneProgress.legend.inProgress`),` · `,f.inProgress]})]}),f.failed>0&&(0,$.jsx)(`p`,{className:`mt-0.5 text-[10px] text-destructive`,"data-testid":`milestone-failed-note`,children:l(`milestoneProgress.failedNote`,{count:f.failed})})]}),t&&(0,$.jsx)(`div`,{className:`mt-2 flex flex-col gap-1.5`,children:t}),p&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(nN,{chain:p,busy:n,onResume:a,onCancel:o,onSetAutoAdvance:s})}),e.rails.length>0&&(0,$.jsx)(`div`,{className:`mt-2 space-y-1`,"data-testid":`milestone-rails`,children:e.rails.map(e=>(0,$.jsx)(eN,{rail:e,now:d,onReview:r,onOpenRail:i},e.railIndex))})]})}function iN({projectId:e}){let{t}=K(`builder`),n=y(),{setActiveProjectId:r}=pt(),{progress:i,hasBlueprint:a}=Qt(e),[o,s]=(0,Q.useState)(!1),c=i.find(e=>e.n===1)??null,l=(0,Q.useCallback)(t=>{r(e),setTimeout(()=>n(t),50)},[n,e,r]),u=(0,Q.useCallback)(async n=>{s(!0);try{let r=await wM(e,n);r.ok?J.success(t(`milestoneProgress.chain.resumed`)):J.error(t(`milestoneProgress.chain.resumeFailed`),{description:r.detail??r.error})}finally{s(!1)}},[e,t]),d=(0,Q.useCallback)(async(n,r)=>{s(!0);try{let i=await EM(e,n,r);i.ok?(_M(r),J.success(t(r?`milestoneProgress.chain.autoOn`:`milestoneProgress.chain.autoOff`))):J.error(t(`milestoneProgress.chain.autoFailed`),{description:i.detail??i.error})}finally{s(!1)}},[e,t]),f=(0,Q.useCallback)(async n=>{s(!0);try{let r=await TM(e,n);r.ok?J.success(t(`milestoneProgress.chain.cancelledToast`)):J.error(r.detail??r.error)}finally{s(!1)}},[e,t]);return a===null&&!c?(0,$.jsx)(`div`,{className:`mt-4 flex items-center justify-center gap-2 text-xs text-muted-foreground`,"data-testid":`builder-done-milestone-loading`,children:(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0})}):c?(0,$.jsx)(`div`,{className:`mt-4 text-left`,"data-testid":`builder-done-milestone`,children:(0,$.jsx)(rN,{progress:c,chainBusy:o,onReview:e=>l(le?`/review/${e}`:`/`),onOpenRail:()=>l(`/`),onResume:u,onCancel:f,onSetAutoAdvance:d,className:`bg-card/60`})}):null}var aN={surprise:Fc,approve:gc};function oN({kind:e,mode:t,onAction:n,disabled:r=!1,createdAt:i,className:a}){let{t:o}=K(`builder`),s=My(),c=t===`settled`,l=c?Sn:aN[e],u=i?sN(i):null,d=X(`group relative my-1 w-full max-w-lg overflow-hidden rounded-xl border text-left shadow-lg backdrop-blur`,c?`border-accent-success/25 bg-card/60`:`border-accent-primary/25 bg-card/80 transition-colors hover:border-accent-primary/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/50 disabled:cursor-not-allowed disabled:opacity-60`,a),f=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:X(`pointer-events-none absolute inset-0 bg-gradient-to-br via-transparent transition-opacity`,c?`from-accent-success/[0.06] to-accent-success/[0.03] opacity-100`:`from-accent-primary/[0.08] to-accent-highlight/[0.08] opacity-70 group-hover:opacity-100`)}),(0,$.jsxs)(`div`,{className:X(`relative flex items-center justify-between gap-2 border-b border-border/40 px-3.5 py-2`,c?`bg-accent-success/[0.05]`:`bg-accent-primary/[0.06]`),children:[(0,$.jsxs)(`span`,{className:X(`flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-widest`,c?`text-accent-success/90`:`text-accent-primary/90`),children:[c?(0,$.jsx)(Sn,{className:`h-3 w-3`,"aria-hidden":!0}):(0,$.jsx)(Ln,{className:`h-3 w-3`,"aria-hidden":!0}),o(c?`decisionCard.settledLabel`:`decisionCard.${e}.label`)]}),(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,"data-testid":`builder-decision-card-meta`,children:c?u:o(`decisionCard.${e}.hint`)})]}),(0,$.jsxs)(`div`,{className:`relative flex items-center gap-3.5 px-3.5 py-3`,children:[(0,$.jsx)(`span`,{className:X(`flex h-9 w-9 shrink-0 items-center justify-center rounded-full shadow-inner`,c?`bg-accent-success/15 text-accent-success`:`bg-gradient-to-br from-accent-primary/25 to-accent-highlight/25 text-accent-primary`),children:(0,$.jsx)(l,{className:`h-4 w-4`,"aria-hidden":!0})}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block text-sm font-semibold leading-snug text-foreground`,children:o(c?`decisionCard.${e}.settledTitle`:`decisionCard.${e}.title`)}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs leading-relaxed text-muted-foreground`,children:o(c?`decisionCard.${e}.settledDescription`:`decisionCard.${e}.description`)})]}),!c&&(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1 rounded-full bg-accent-primary/15 px-2.5 py-1 text-[11px] font-medium text-accent-primary transition-colors group-hover:bg-accent-primary/25`,children:[o(`decisionCard.${e}.cta`),(0,$.jsx)(ce,{className:`h-3 w-3 transition-transform group-hover:translate-x-0.5`,"aria-hidden":!0})]})]})]});return c?(0,$.jsx)(`div`,{className:d,"data-testid":`builder-decision-card`,"data-kind":e,"data-mode":`settled`,children:f}):(0,$.jsx)(Ny.button,{type:`button`,onClick:n,disabled:r,initial:s?{opacity:0}:{opacity:0,y:8},animate:{opacity:1,y:0},exit:s?{opacity:0}:{opacity:0,y:-6},transition:{duration:.22,ease:`easeOut`},whileHover:r||s?void 0:{y:-2},whileTap:r?void 0:{scale:.99},className:d,"data-testid":`builder-decision-card`,"data-kind":e,"data-mode":`offer`,"aria-label":o(`decisionCard.${e}.cta`),children:f})}function sN(e){let t=Date.parse(e);if(!Number.isFinite(t))return null;try{return Pb(t,`p`,{locale:Ze()})}catch{return null}}var cN=`w-full rounded-2xl border border-border/60 bg-card/90 p-3 shadow-2xl backdrop-blur-xl`;function lN({variant:e}){let{t}=K(`builder`),{builderMode:n}=aP(),r=n.session,[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(()=>gM()),c=(0,Q.useRef)(null),l=r.messages[r.messages.length-1],u=r.readiness.steps.find(e=>e.key===`blueprint`),d=r.readiness.steps.find(e=>e.key===`specs`),f=r.phase===`chat`&&!r.busy&&r.streamBuffer===null&&l?.role===`assistant`&&r.snapshot.status!==`generating`,p=f&&u?.state!==`done`,m=f&&u?.state===`done`&&(d===void 0||d.state===`pending`&&Number(d.params.count??0)===0)&&(r.blueprint?.m1Specs.length??0)===0;(0,Q.useEffect)(()=>{c.current?.scrollTo?.({top:c.current.scrollHeight})},[r.messages,r.streamBuffer]);let h=(0,Q.useCallback)(()=>{r.dirty&&r.phase!==`done`?a(!0):n.exit()},[r.dirty,r.phase,n]),g=(0,Q.useCallback)(e=>{e.key===`Escape`&&(e.stopPropagation(),i?a(!1):r.phase===`commit`&&!r.submitting?r.backToChat():r.phase===`chat`&&h())},[i,r,h]),_=r.messages.length===0&&r.streamBuffer===null&&!r.busy,v=e===`inline`?`mx-auto flex w-full max-w-[820px] flex-1 flex-col overflow-hidden`:`flex flex-1 flex-col overflow-hidden`;return(0,$.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,onKeyDown:g,"data-testid":`builder-conversation`,children:[r.phase===`chat`&&(_?(0,$.jsx)(`div`,{className:`relative z-10 flex h-full w-full items-center justify-center px-6`,children:(0,$.jsxs)(Ny.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.28,ease:[.34,1.56,.64,1]},className:X(`w-full`,e===`inline`?`max-w-[680px]`:`max-w-[560px]`),children:[(0,$.jsxs)(`div`,{className:`mb-4 text-center`,children:[(0,$.jsx)(Ln,{className:`mx-auto h-7 w-7 text-accent-primary/60`}),(0,$.jsx)(`p`,{className:`mt-2 text-sm font-medium`,children:t(`shell.emptyTitle`)}),(0,$.jsx)(`p`,{className:`mx-auto mt-1 max-w-sm text-xs text-muted-foreground`,children:t(`shell.emptyHint`)})]}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(NA,{active:!0,inset:-3,radius:`1rem`}),(0,$.jsx)(Ny.div,{layoutId:e===`inline`?`builder-composer-dock`:void 0,"data-testid":`builder-composer-card`,"data-composer-position":`hero`,"data-layout-id":e===`inline`?`builder-composer-dock`:void 0,transition:{layout:{type:`spring`,stiffness:350,damping:34}},className:cN,children:(0,$.jsx)(sM,{session:r,autoFocus:!0})})]}),(0,$.jsx)(lM,{items:r.recent,loading:r.recentLoading,disabled:!r.conversationReady,onResume:e=>void r.resume(e),onDiscard:e=>void r.discardRecent(e)})]})}):(0,$.jsxs)(`div`,{className:v,children:[(0,$.jsxs)(`div`,{ref:c,className:`flex-1 space-y-5 overflow-y-auto px-4 py-4`,"data-testid":`builder-messages`,children:[r.messages.map((e,t)=>e.role===`user`&&e.intent?(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(oN,{kind:e.intent,mode:`settled`,createdAt:e.createdAt})},`${t}-${e.createdAt}`):(0,$.jsx)(ZD,{role:e.role,content:e.content,createdAt:e.createdAt,isLast:r.streamBuffer===null&&!r.busy&&t===r.messages.length-1,onPickOption:e=>r.send(e)},`${t}-${e.createdAt}`)),(0,$.jsxs)(N_,{initial:!1,children:[p&&(0,$.jsx)(oN,{kind:`surprise`,mode:`offer`,onAction:r.surpriseMe,disabled:!r.conversationReady},`surprise`),m&&(0,$.jsx)(oN,{kind:`approve`,mode:`offer`,onAction:r.approveBlueprint,disabled:!r.conversationReady},`approve`)]}),(r.busy||r.streamBuffer!==null)&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[r.streamBuffer!==null&&Kt(r.streamBuffer)&&(0,$.jsx)(ZD,{role:`assistant`,content:Kt(r.streamBuffer),streaming:!0}),r.generation.generating||r.snapshot.status===`repairing`||r.snapshot.status===`generating`?(0,$.jsx)(uM,{specsStarted:r.generation.specsStarted,snapshot:r.snapshot}):(0,$.jsx)(Vb,{tool:null})]})]}),(0,$.jsx)(`div`,{className:`shrink-0 px-4 pb-4`,children:(0,$.jsx)(Ny.div,{layoutId:e===`inline`?`builder-composer-dock`:void 0,"data-testid":`builder-composer-card`,"data-composer-position":`docked`,"data-layout-id":e===`inline`?`builder-composer-dock`:void 0,transition:{layout:{type:`spring`,stiffness:350,damping:34}},className:X(cN,e===`inline`&&`mx-auto max-w-[680px]`),children:(0,$.jsx)(sM,{session:r})})})]})),r.phase===`commit`&&r.blueprint&&(0,$.jsx)(`div`,{className:`flex min-h-0 flex-1 items-start justify-center overflow-y-auto`,children:(0,$.jsx)(oM,{blueprint:r.blueprint,onSubmit:r.submitCommit,onBack:r.backToChat,submitting:r.submitting,error:r.commitError,errorDetail:r.commitErrorDetail})}),r.phase===`progress`&&(0,$.jsxs)(`div`,{className:`mx-auto mt-10 w-full max-w-md p-6`,"data-testid":`commit-progress`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold`,children:t(`progress.title`)}),(0,$.jsx)(`ul`,{className:`mt-4 space-y-2`,children:UM.map(e=>{let n=r.commitSteps.find(t=>t.step===e);return!n&&e===`github`?null:(0,$.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[!n&&(0,$.jsx)(es,{className:`h-3.5 w-3.5 text-muted-foreground/40`}),n?.status===`running`&&(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin text-accent-info`}),n?.status===`done`&&(0,$.jsx)(Sn,{className:`h-3.5 w-3.5 text-accent-success`}),n?.status===`warning`&&(0,$.jsx)(zn,{className:`h-3.5 w-3.5 text-accent-warning`}),n?.status===`failed`&&(0,$.jsx)(Vn,{className:`h-3.5 w-3.5 text-destructive`}),(0,$.jsx)(`span`,{className:X(!n&&`text-muted-foreground/50`),children:t(`progress.steps.${e}`)}),n?.status===`warning`&&e===`github`?(0,$.jsx)(`span`,{className:`truncate text-[10px] text-accent-warning`,title:n.detail,children:t(HM(n.code))}):n?.detail&&(0,$.jsx)(`span`,{className:`truncate text-[10px] text-muted-foreground`,title:n.detail,children:n.detail})]},e)})})]}),r.phase===`done`&&(0,$.jsxs)(`div`,{className:`mx-auto mt-12 w-full max-w-md p-6 text-center`,"data-testid":`commit-done`,children:[(0,$.jsx)(Sn,{className:`mx-auto h-10 w-10 rounded-full bg-accent-success/15 p-2 text-accent-success`}),(0,$.jsx)(`h2`,{className:`mt-3 text-sm font-semibold`,children:t(`done.title`)}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:t(`done.description`)}),r.launched&&r.createdProjectId&&(0,$.jsx)(iN,{projectId:r.createdProjectId}),(0,$.jsxs)(`div`,{className:`mt-5 flex flex-col gap-2`,children:[!r.launched&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Z,{onClick:()=>void r.launchM1(),disabled:r.launching,"data-testid":`launch-m1`,children:[r.launching?(0,$.jsx)(An,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(gc,{className:`mr-1.5 h-3.5 w-3.5`}),t(`done.launchM1`)]}),pM()===`sequential`&&(0,$.jsx)(tN,{checked:o,onChange:e=>{s(e),_M(e)},disabled:r.launching,testId:`done-auto-advance`})]}),(0,$.jsx)(Z,{variant:`outline`,onClick:r.openProject,"data-testid":`open-project`,children:t(`done.openProject`)})]})]}),i&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/70 backdrop-blur-sm`,"data-testid":`builder-exit-confirm`,children:(0,$.jsxs)(`div`,{className:`w-72 rounded-lg border border-border/60 bg-card p-4 shadow-xl`,role:`alertdialog`,"aria-modal":`true`,"aria-labelledby":`builder-exit-confirm-title`,children:[(0,$.jsx)(`p`,{id:`builder-exit-confirm-title`,className:`text-sm font-medium`,children:t(`mode.exitConfirmTitle`)}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:t(`mode.exitConfirmBody`)}),(0,$.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:()=>a(!1),"data-testid":`builder-exit-cancel`,children:t(`mode.exitConfirmCancel`)}),(0,$.jsx)(Z,{variant:`destructive`,size:`sm`,onClick:()=>{a(!1),n.exit()},"data-testid":`builder-exit-confirm-btn`,children:t(`mode.exitConfirmDiscard`)})]})]})})]})}var uN=X(`text-sm leading-7 text-foreground`,`[&_p]:my-3 [&_p:first-child]:mt-0 [&_p:last-child]:mb-0`,`[&_h1]:mt-4 [&_h1]:mb-2 [&_h1]:text-base [&_h1]:font-semibold`,`[&_h2]:mt-4 [&_h2]:mb-1.5 [&_h2]:text-[15px] [&_h2]:font-semibold`,`[&_h3]:mt-3 [&_h3]:mb-1 [&_h3]:text-sm [&_h3]:font-semibold`,`[&_strong]:font-semibold [&_strong]:text-foreground`,`[&_em]:italic`,`[&_a]:text-accent-info [&_a]:underline [&_a]:underline-offset-2`,`[&_ul]:my-2.5 [&_ul]:list-disc [&_ul]:pl-5 [&_ol]:my-2.5 [&_ol]:list-decimal [&_ol]:pl-5 [&_li]:my-1`,`[&_code]:rounded [&_code]:bg-surface [&_code]:px-1 [&_code]:py-0.5 [&_code]:font-mono [&_code]:text-[0.85em] [&_code]:text-accent-info`,`[&_pre]:my-2 [&_pre]:overflow-x-auto [&_pre]:rounded-lg [&_pre]:bg-surface [&_pre]:p-3`,`[&_pre_code]:bg-transparent [&_pre_code]:p-0 [&_pre_code]:text-foreground`,`[&_hr]:my-3 [&_hr]:border-border/60`),dN={critical:`border-destructive/35 bg-destructive/15 text-destructive`,high:`border-accent-warning/35 bg-accent-warning/15 text-accent-warning`,medium:`border-accent-info/35 bg-accent-info/15 text-accent-info`,low:`border-border/60 bg-surface/70 text-foreground/60`};function fN({spec:e,index:t,milestoneLabel:n=`M1`,onClose:r}){let{t:i}=K(`builder`),{t:a}=K(`tickets`),o=`blueprint-spec-summary-${t}`;return(0,Q.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.stopPropagation(),r())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]),(0,Hb.createPortal)((0,$.jsxs)(`div`,{"data-testid":`blueprint-spec-modal`,className:`fixed inset-0 z-[65] flex items-center justify-center p-4`,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:r,"aria-hidden":!0}),(0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":e.title,"aria-describedby":e.shortSummary.trim()?o:void 0,className:`relative flex max-h-[82vh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-border/40 bg-popover shadow-2xl backdrop-blur-md`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3 border-b border-border/40 px-5 py-4`,children:[(0,$.jsx)(Dn,{className:`mt-0.5 h-4 w-4 shrink-0 text-accent-primary`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:i(`specModal.eyebrow`,{milestone:n,index:t+1})}),(0,$.jsx)(`h2`,{className:`mt-0.5 text-base font-semibold text-foreground`,children:e.title}),e.shortSummary.trim()&&(0,$.jsxs)(`p`,{id:o,className:`mt-1 text-xs leading-5 text-muted-foreground`,"data-testid":`blueprint-spec-summary`,children:[(0,$.jsxs)(`span`,{className:`sr-only`,children:[i(`specModal.summary`),`: `]}),e.shortSummary]}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[(0,$.jsx)(`span`,{className:X(`rounded-full border px-1.5 py-px text-[9px] font-medium uppercase tracking-wide`,dN[e.priority]),"data-testid":`blueprint-spec-priority`,"aria-label":`${i(`specModal.priority`)}: ${a(`priority.${e.priority}`)}`,children:a(`priority.${e.priority}`)}),e.labels.map(e=>(0,$.jsx)(`span`,{className:`rounded bg-accent-primary/10 px-1.5 py-px text-[9px] text-accent-primary`,children:e},e)),e.dependsOnIndex!==void 0&&(0,$.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-px text-[9px] text-muted-foreground`,children:i(`panel.dependsOn`,{index:e.dependsOnIndex+1})})]})]}),(0,$.jsx)(`button`,{type:`button`,onClick:r,"aria-label":i(`specModal.close`),"data-agent-interactive":!0,className:`rounded-md p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground`,"data-testid":`blueprint-spec-modal-close`,children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4`,children:[(0,$.jsx)(`section`,{"aria-label":i(`specModal.description`),"data-testid":`blueprint-spec-description`,children:e.description.trim()?(0,$.jsx)(`div`,{className:uN,children:(0,$.jsx)(br,{remarkPlugins:[xr],children:e.description})}):(0,$.jsx)(`p`,{className:`text-xs italic text-muted-foreground`,children:i(`specModal.empty`)})}),(0,$.jsxs)(`section`,{"aria-labelledby":`blueprint-spec-criteria-heading`,"data-testid":`blueprint-spec-acceptance-criteria`,children:[(0,$.jsxs)(`h3`,{id:`blueprint-spec-criteria-heading`,className:`mb-2 flex items-center justify-between gap-2 text-xs font-semibold uppercase tracking-wider text-foreground/60`,children:[(0,$.jsx)(`span`,{children:i(`specModal.acceptanceCriteria`)}),(0,$.jsx)(`span`,{className:`rounded-full bg-surface px-2 py-0.5 text-[10px] tabular-nums text-muted-foreground`,children:e.acceptanceCriteria.length})]}),e.acceptanceCriteria.length>0?(0,$.jsx)(`ol`,{className:`space-y-2`,children:e.acceptanceCriteria.map((e,t)=>(0,$.jsxs)(`li`,{className:`flex items-start gap-2 text-sm leading-6 text-foreground/85`,"data-testid":`blueprint-spec-criterion-${t}`,children:[(0,$.jsx)($o,{className:`mt-1 h-4 w-4 shrink-0 text-accent-success`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:e})]},`${t}-${e}`))}):(0,$.jsx)(`p`,{className:`text-xs italic text-muted-foreground`,children:i(`specModal.criteriaEmpty`)})]})]})]})]}),document.body)}var pN={critical:`border-destructive/35 bg-destructive/15 text-destructive`,high:`border-accent-warning/35 bg-accent-warning/15 text-accent-warning`,medium:`border-accent-info/35 bg-accent-info/15 text-accent-info`,low:`border-border/60 bg-surface/70 text-foreground/60`};function mN({blueprint:e,milestoneLabel:t=`M1`,snapshot:n}){let{t:r}=K(`builder`),{t:i}=K(`tickets`),a=Bt(e),[o,s]=(0,Q.useState)(null),c=[{key:`product`,label:r(`panel.product`),value:e?.product.name??``},{key:`coreFlow`,label:r(`panel.coreFlow`),value:e?.coreFlow??``},{key:`platform`,label:r(`panel.platform`),value:e?.platform??``},{key:`stack`,label:r(`panel.stack`),value:e?[e.stack.language,e.stack.framework,e.stack.db].filter(Boolean).join(` · `):``},{key:`milestones`,label:r(`panel.milestones`),value:e&&e.milestones.length>0?r(`panel.milestonesValue`,{count:e.milestones.length}):``}];return(0,$.jsxs)(`div`,{className:`flex h-full flex-col gap-4 overflow-y-auto p-4`,"data-testid":`blueprint-panel`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`h3`,{className:`flex items-center gap-2 text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:[r(`panel.title`),n?.status===`repairing`&&(0,$.jsx)(An,{className:`h-3 w-3 animate-spin text-accent-info`,"aria-hidden":!0,"data-testid":`panel-repairing`})]}),(0,$.jsx)(`div`,{className:`space-y-1`,children:c.map(e=>(0,$.jsxs)(`div`,{className:X(`flex items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs transition-colors`,a[e.key]?`border-accent-success/30 bg-accent-success/5`:`border-border/30`),"data-testid":`dimension-${e.key}`,children:[a[e.key]?(0,$.jsx)(Sn,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`,"aria-label":`✓`}):(0,$.jsx)(Vn,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/40`,"aria-label":`✗`}),(0,$.jsx)(`span`,{className:`font-medium`,children:e.label}),e.value&&(0,$.jsx)(`span`,{className:`ml-auto truncate text-muted-foreground`,title:e.value,children:e.value})]},e.key))})]}),e&&e.assumptions.length>0&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`h4`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:r(`panel.assumptions`)}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:e.assumptions.map((e,t)=>(0,$.jsx)(`li`,{className:`text-[11px] text-muted-foreground before:mr-1.5 before:content-['·']`,children:e},t))})]}),e&&e.m1Specs.length>0&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`h4`,{className:`flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:[(0,$.jsx)(kn,{className:`h-3 w-3`}),r(`panel.m1Specs`,{count:e.m1Specs.length}),(0,$.jsx)(`span`,{className:X(`ml-auto rounded-full border px-1.5 py-px text-[9px] font-medium normal-case tracking-normal`,e.specsComplete?`border-accent-success/35 bg-accent-success/10 text-accent-success`:`border-accent-warning/35 bg-accent-warning/10 text-accent-warning`),"data-testid":`m1-specs-completeness`,children:e.specsComplete?r(`panel.specsComplete`):r(`panel.specsInProgress`)})]}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:e.m1Specs.map((e,t)=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>s(t),"data-agent-interactive":!0,className:`w-full rounded-lg border border-border/40 bg-surface/50 p-2.5 text-left shadow-sm transition-colors animate-in fade-in slide-in-from-bottom-1 hover:border-accent-primary/50 hover:bg-surface/80 focus:outline-none focus-visible:ring-1 focus-visible:ring-ring`,"data-testid":`m1-spec-card-${t}`,title:r(`specModal.open`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(Dn,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-primary`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium leading-tight`,children:e.title}),e.shortSummary.trim()&&(0,$.jsx)(`p`,{className:`mt-1 line-clamp-2 text-[11px] leading-4 text-muted-foreground`,"data-testid":`m1-spec-summary-${t}`,children:e.shortSummary}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-1`,children:[(0,$.jsx)(`span`,{className:X(`rounded-full border px-1.5 py-px text-[9px] font-medium uppercase tracking-wide`,pN[e.priority]),"data-testid":`m1-spec-priority-${t}`,children:i(`priority.${e.priority}`)}),!e.description.trim()&&e.acceptanceCriteria.length===0?(0,$.jsxs)(`span`,{className:X(`inline-flex items-center gap-1 rounded-full border px-1.5 py-px text-[9px]`,n?.status===`generating`?`border-accent-info/35 bg-accent-info/10 text-accent-info`:`border-border/50 bg-surface/70 text-muted-foreground`),"data-testid":`m1-spec-unwritten-${t}`,children:[n?.status===`generating`?(0,$.jsx)(An,{className:`h-2.5 w-2.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Ws,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),r(n?.status===`generating`?`panel.specWriting`:`panel.specPendingBody`)]}):(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-border/50 bg-surface/70 px-1.5 py-px text-[9px] text-muted-foreground`,"data-testid":`m1-spec-criteria-count-${t}`,children:[(0,$.jsx)(Ws,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),r(`panel.criteriaCount`,{count:e.acceptanceCriteria.length})]}),e.labels.map(e=>(0,$.jsx)(`span`,{className:`rounded bg-accent-primary/10 px-1.5 py-px text-[9px] text-accent-primary`,children:e},e)),e.dependsOnIndex!==void 0&&(0,$.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-px text-[9px] text-muted-foreground`,children:r(`panel.dependsOn`,{index:e.dependsOnIndex+1})})]})]})]})},`${t}-${e.title}`))})]}),e&&e.milestones.length>1&&(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`h4`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:r(`panel.laterMilestones`)}),e.milestones.slice(1).map(e=>(0,$.jsxs)(`div`,{className:`rounded-md border border-border/20 px-2.5 py-1.5`,children:[(0,$.jsx)(`p`,{className:`text-[11px] font-medium`,children:e.title}),e.plannedSpecs.length>0&&(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:e.plannedSpecs.join(` · `)})]},e.id||e.title))]}),!e&&(0,$.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground/60`,children:r(`panel.empty`)}),e&&o!==null&&e.m1Specs[o]&&(0,$.jsx)(fN,{spec:e.m1Specs[o],index:o,milestoneLabel:t,onClose:()=>s(null)})]})}var hN={done:Sn,pending:es,blocked:zn,writing:An},gN={done:`text-accent-success`,pending:`text-muted-foreground/50`,blocked:`text-accent-warning`,writing:`text-accent-info animate-spin`};function _N({readiness:e,snapshot:t,busy:n,primaryLabel:r,onPrimary:i,onRepair:a,primaryTestId:o=`builder-create-specs`,showPrimary:s=!0}){let{t:c}=K(`builder`),[l,u]=(0,Q.useState)(!1),d=t.status===`repairing`,f=t.status===`rejected`,p=t.status===`accepted`&&t.generationHalted===!0&&!n,m=e.steps.find(e=>e.key===`specs`),h=m?.state===`done`,g=!!a&&h&&e.issues.length>0,_=e.steps.find(e=>e.state!==`done`);return(0,$.jsxs)(`div`,{className:`space-y-2.5 border-t border-border/40 p-3`,"data-testid":`blueprint-readiness`,children:[(0,$.jsx)(`ol`,{className:`space-y-1`,"aria-label":c(`readiness.title`),children:e.steps.map(e=>{let t=hN[e.state];return(0,$.jsxs)(`li`,{className:`flex items-start gap-2 text-[11px] leading-4`,"data-testid":`readiness-step-${e.key}`,"data-state":e.state,children:[(0,$.jsx)(t,{className:X(`mt-px h-3.5 w-3.5 shrink-0`,gN[e.state]),"aria-hidden":!0}),(0,$.jsx)(`span`,{className:X(`font-medium`,e.state===`pending`&&`text-muted-foreground`,e.state===`writing`&&`text-accent-info`),children:c(`readiness.steps.${e.key}`)}),(0,$.jsx)(`span`,{className:`ml-auto max-w-[60%] truncate text-right text-muted-foreground`,title:c(`readiness.details.${e.key}.${e.state}`,e.params),children:c(`readiness.details.${e.key}.${e.state}`,e.params)})]},e.key)})}),(0,$.jsxs)(N_,{initial:!1,mode:`wait`,children:[d&&(0,$.jsxs)(Ny.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},className:`flex items-center gap-2 rounded-md border border-accent-info/30 bg-accent-info/10 px-2.5 py-1.5 text-[11px] text-accent-info`,"data-testid":`snapshot-repairing`,children:[(0,$.jsx)(An,{className:`h-3.5 w-3.5 shrink-0 animate-spin`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[c(`snapshot.repairing.${t.kind}`),t.manual?``:` · ${c(`snapshot.repairing.automatic`)}`]})]},`repairing`),f&&(0,$.jsxs)(Ny.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},className:`space-y-1.5 rounded-md border border-accent-warning/35 bg-accent-warning/10 p-2.5`,"data-testid":`snapshot-rejected`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] leading-4 text-accent-warning`,children:[(0,$.jsx)(zn,{className:`mt-px h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`font-medium`,children:c(`snapshot.rejected.title`)}),(0,$.jsx)(`p`,{className:`text-accent-warning/90`,children:c(`snapshot.rejected.${t.reason}`)}),t.repairAttempted&&(0,$.jsx)(`p`,{className:`mt-0.5 text-[10px] text-accent-warning/80`,children:c(`snapshot.rejected.autoRepairFailed`)})]})]}),t.detail&&(0,$.jsx)(`p`,{className:`line-clamp-2 break-all font-mono text-[10px] leading-4 text-foreground/60`,title:t.detail,"data-testid":`snapshot-rejected-detail`,children:t.detail}),a&&(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,className:`w-full`,disabled:n,onClick:a,"data-testid":`snapshot-retry`,children:[(0,$.jsx)(mc,{className:`mr-1.5 h-3 w-3`,"aria-hidden":!0}),c(`snapshot.rejected.retry`)]})]},`rejected`),p&&(0,$.jsxs)(Ny.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},className:`space-y-1.5 rounded-md border border-accent-warning/35 bg-accent-warning/10 p-2.5`,"data-testid":`snapshot-halted`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] leading-4 text-accent-warning`,children:[(0,$.jsx)(zn,{className:`mt-px h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`font-medium`,children:c(`snapshot.halted.title`)}),(0,$.jsx)(`p`,{className:`text-accent-warning/90`,children:c(`snapshot.halted.detail`,{written:m?.params?.written??0,total:m?.params?.count??0})})]})]}),a&&(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,className:`w-full`,disabled:n,onClick:a,"data-testid":`snapshot-resume`,children:[(0,$.jsx)(Ln,{className:`mr-1.5 h-3 w-3`,"aria-hidden":!0}),c(`snapshot.halted.resume`)]})]},`halted`),t.status===`accepted`&&t.repaired&&!p&&(0,$.jsxs)(Ny.p,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,"data-testid":`snapshot-repaired`,children:[(0,$.jsx)(Ln,{className:`h-3 w-3 text-accent-success`,"aria-hidden":!0}),c(`snapshot.repairedNote`)]},`repaired`)]}),e.issues.length>0&&(0,$.jsxs)(`div`,{className:`rounded-md border border-border/40 bg-surface/40`,"data-testid":`readiness-issues`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(e=>!e),"aria-expanded":l,className:`flex w-full items-center gap-1.5 px-2.5 py-1.5 text-left text-[11px] font-medium text-foreground/80 hover:bg-surface/70`,"data-testid":`readiness-issues-toggle`,children:[(0,$.jsx)(Bn,{className:`h-3 w-3 text-accent-warning`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`flex-1`,children:c(`readiness.issuesCount`,{count:e.issues.length})}),(0,$.jsx)(Xo,{className:X(`h-3.5 w-3.5 transition-transform`,l&&`rotate-180`),"aria-hidden":!0})]}),l&&(0,$.jsx)(`ul`,{className:`max-h-40 space-y-1 overflow-y-auto border-t border-border/30 px-2.5 py-2`,children:e.issues.map((e,t)=>(0,$.jsxs)(`li`,{className:`flex items-start gap-1.5 text-[10px] leading-4 text-muted-foreground`,children:[e.specIndex!==null&&(0,$.jsxs)(`span`,{className:`shrink-0 rounded bg-accent-primary/10 px-1 font-mono text-[9px] text-accent-primary`,children:[`#`,e.specIndex+1]}),(0,$.jsx)(`span`,{children:BM(c,e)})]},`${e.specIndex}-${e.field}-${e.code}-${t}`))}),g&&(0,$.jsx)(`div`,{className:`border-t border-border/30 p-2`,children:(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,className:`w-full`,disabled:n,onClick:a,"data-testid":`readiness-ask-fix`,children:[(0,$.jsx)(Bn,{className:`mr-1.5 h-3 w-3`,"aria-hidden":!0}),c(`readiness.askFix`)]})})]}),s&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(Z,{className:`w-full`,size:`sm`,disabled:!e.ready||n,onClick:i,"data-testid":o,children:[(0,$.jsx)(gc,{className:`mr-1.5 h-3.5 w-3.5`,"aria-hidden":!0}),r]}),!e.ready&&_&&!d&&!f&&!p&&(0,$.jsx)(`p`,{className:`mt-1.5 text-center text-[10px] text-muted-foreground`,"data-testid":`readiness-hint`,children:c(`readiness.hints.${_.key}.${_.state}`,_.params)})]})]})}function vN(){let{t:e}=K(`agent`),{t}=K(`builder`),{minimize:n,startNewConversation:r,cycleTier:i,active:a,draftPinnedProjectId:o,setPinnedProject:s,builderMode:c}=aP(),[l,u]=(0,Q.useState)(!1),d=c.active,f=e=>{d||e.shiftKey&&(e.key===`Tab`||e.code===`Tab`)&&(e.preventDefault(),i())},{panelRef:p,panelStyle:m,headerHandleProps:h,resizeHandles:g}=Kn({enabled:!0,allowMove:!0,minWidth:400,minHeight:420,anchorFromCurrentRect:!0,persistKey:`specrails-desktop:agent-panel-geom`});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Ny.div,{ref:p,initial:{opacity:0,scale:.85,y:8},animate:{opacity:1,scale:1,y:0},transition:{duration:.22,ease:[.34,1.56,.64,1]},style:l?{position:`fixed`,inset:12,width:`auto`,height:`auto`,maxWidth:`none`,maxHeight:`none`}:m,role:`dialog`,"aria-label":d?t(`mode.title`):e(`title`),onKeyDown:f,className:`fixed z-[60] flex flex-col overflow-hidden rounded-2xl border border-border/60 bg-card/90 shadow-2xl backdrop-blur-xl ${l?``:`bottom-4 right-4 h-[78vh] max-h-[94vh] max-w-[92vw] ${d?`w-[860px]`:`w-[520px]`}`}`,children:[(0,$.jsxs)(`div`,{...l?{}:h,onDoubleClick:()=>u(e=>!e),className:`flex shrink-0 items-center gap-2 border-b border-border/50 bg-surface/40 px-3 py-2 ${l?``:`cursor-grab`}`,children:[(0,$.jsxs)(`span`,{className:`relative flex h-5 w-5 shrink-0 items-center justify-center`,children:[(0,$.jsx)(NA,{active:d&&c.session.messages.length===0&&c.session.phase===`chat`,inset:-3}),(0,$.jsx)(Vo,{className:`h-4 w-4 shrink-0 text-accent-primary`})]}),(0,$.jsx)(`span`,{className:`shrink-0 text-sm font-medium text-foreground/80`,children:d?t(`mode.title`):e(`title`)}),!d&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ZO,{pinnedProjectId:a?a.pinned_project_id:o,onSelect:e=>void s(e)}),(0,$.jsx)(`div`,{className:`h-4 w-px shrink-0 bg-border/60`,"aria-hidden":!0}),(0,$.jsx)(Kj,{})]}),(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[!d&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>r(null),title:e(`newConversation`),"data-agent-interactive":!0,className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,$.jsx)(Pn,{className:`h-4 w-4`})}),(0,$.jsx)(Rc,{}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>u(e=>!e),"aria-label":e(l?`restore`:`maximize`),title:e(l?`restore`:`maximize`),"data-agent-interactive":!0,className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:l?(0,$.jsx)(Js,{className:`h-4 w-4`}):(0,$.jsx)(qs,{className:`h-4 w-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:n,"aria-label":e(`minimize`),title:e(`minimize`),"data-agent-interactive":!0,className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})]})]}),d?(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,$.jsx)(lN,{variant:`floating`}),(0,$.jsxs)(`aside`,{className:`flex w-72 shrink-0 flex-col border-l border-border/40 lg:w-80`,children:[(0,$.jsx)(mN,{blueprint:c.session.blueprint,snapshot:c.session.snapshot}),c.session.phase===`chat`&&(0,$.jsx)(_N,{readiness:c.session.readiness,snapshot:c.session.snapshot,busy:c.session.busy,primaryLabel:t(`shell.createSpecs`),onPrimary:c.session.goToCommit,onRepair:()=>void c.session.repairSnapshot()})]})]}):(0,$.jsx)(Hj,{variant:`floating`})]}),!l&&(0,$.jsx)(`div`,{className:`pointer-events-none fixed inset-0 z-[61] [&>*]:pointer-events-auto`,children:(0,$.jsx)(ar,{handles:g})})]})}var yN=`specrails-desktop:agent-bubble-pos`,bN=56,xN=12;function SN(){try{let e=localStorage.getItem(yN);if(!e)return null;let t=JSON.parse(e);if(typeof t?.left==`number`&&typeof t?.top==`number`)return t}catch{}return null}function CN(e){let t=Math.max(xN,window.innerWidth-bN-xN),n=Math.max(xN,window.innerHeight-bN-xN);return{left:Math.min(Math.max(xN,e.left),t),top:Math.min(Math.max(xN,e.top),n)}}function wN(){return{left:Math.round(window.innerWidth/2-bN/2),top:window.innerHeight-bN-20}}function TN(){let{t:e}=K(`agent`),{t}=K(`builder`),{open:n,isStreaming:r,active:i,builderMode:a}=aP(),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(()=>CN(SN()??wN())),u=jy(0),d=jy(0),f=(0,Q.useRef)(!1),p=a.active?a.session.busy:r;(0,Q.useEffect)(()=>{let e=()=>l(e=>CN(e));return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let m=(0,Q.useCallback)(e=>{try{localStorage.setItem(yN,JSON.stringify(e))}catch{}},[]);return(0,$.jsxs)(Ny.button,{type:`button`,onClick:()=>{if(f.current){f.current=!1;return}n()},onHoverStart:()=>s(!0),onHoverEnd:()=>s(!1),"aria-label":e(`trigger`),title:`${e(`trigger`)} (⌘⇧A)`,drag:!0,dragMomentum:!1,dragElastic:0,style:{position:`fixed`,left:c.left,top:c.top,x:u,y:d},onDragStart:()=>{f.current=!0},onDragEnd:()=>{let e=CN({left:c.left+u.get(),top:c.top+d.get()});u.set(0),d.set(0),l(e),m(e),setTimeout(()=>{f.current=!1},0)},initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.8},transition:{type:`spring`,stiffness:420,damping:28},whileHover:{scale:1.06},whileTap:{scale:.94},whileDrag:{scale:1.1,cursor:`grabbing`},className:`z-[60] flex h-14 items-center gap-2 rounded-full border border-border/60 bg-card/85 px-3 shadow-2xl backdrop-blur-xl cursor-grab`,children:[(0,$.jsxs)(`span`,{className:`relative flex h-9 w-9 items-center justify-center rounded-full bg-accent-primary/15`,children:[(0,$.jsx)(NA,{active:a.active&&a.session.messages.length===0&&a.session.phase===`chat`,inset:-4}),(0,$.jsx)(Vo,{className:`h-5 w-5 text-accent-primary`}),p&&(0,$.jsx)(Ny.span,{className:`absolute inset-0 rounded-full ring-2 ring-accent-success`,animate:{opacity:[.8,.2,.8],scale:[1,1.18,1]},transition:{duration:1.4,repeat:1/0,ease:`easeInOut`}})]}),(0,$.jsx)(N_,{initial:!1,children:(o||p)&&(0,$.jsx)(Ny.span,{initial:{opacity:0,width:0,marginRight:0},animate:{opacity:1,width:`auto`,marginRight:4},exit:{opacity:0,width:0,marginRight:0},transition:{duration:.18,ease:`easeOut`},className:`overflow-hidden whitespace-nowrap text-sm font-medium text-foreground`,children:p?e(`thinking`):a.active?t(`mode.title`):i?.title||e(`trigger`)})})]})}var EN=`specrails-desktop:uiMode`;function DN(){if(!De)return`kanban`;try{return localStorage.getItem(EN)===`kanban`?`kanban`:`agent`}catch{return`agent`}}function ON(e){try{localStorage.setItem(EN,e)}catch{}}var kN=(0,Q.createContext)(null);function AN({children:e,initialMode:t,persist:n=!0}){let[r,i]=(0,Q.useState)(()=>t??DN()),a=(0,Q.useCallback)(e=>{De&&(i(e),n&&ON(e))},[n]),o=(0,Q.useCallback)(()=>{i(e=>{if(!De)return`kanban`;let t=e===`kanban`?`agent`:`kanban`;return n&&ON(t),t})},[n]),s=(0,Q.useMemo)(()=>({uiMode:r,setUiMode:a,toggleUiMode:o}),[r,a,o]);return(0,$.jsx)(kN.Provider,{value:s,children:e})}var jN={uiMode:`kanban`,setUiMode:()=>{},toggleUiMode:()=>{}};function MN(){return(0,Q.useContext)(kN)??jN}var NN={streamingText:``,isStreaming:!1,liveTools:[],turnTools:[],queued:[]},PN=`specrails-desktop:favorite-agent-conversations`;function FN(){try{let e=localStorage.getItem(PN);if(!e)return new Set;let t=JSON.parse(e);return Array.isArray(t)?new Set(t.filter(e=>typeof e==`string`)):new Set}catch{return new Set}}function IN(e){try{localStorage.setItem(PN,JSON.stringify([...e]))}catch{}}function LN(e,t){let n=new Set(t.map(e=>e.id));return new Set([...e].filter(e=>n.has(e)))}var RN=`specrails-desktop:agent-tier-last`;function zN(){try{let e=localStorage.getItem(RN),t=e===null?0:Number.parseInt(e,10);return t===0||t===1||t===2||t===3?t:0}catch{return 0}}function BN(e){try{localStorage.setItem(RN,String(e))}catch{}}var VN=new Set([`completed`,`merged`,`discarded`,`superseded`]);function HN(e,t){return JSON.stringify(e)===JSON.stringify(t)}function UN(e){if(!e.createdAt)return null;let t=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(e.createdAt)?`${e.createdAt.replace(` `,`T`)}Z`:e.createdAt,n=Date.parse(t);return Number.isFinite(n)?n:null}function WN(e,t){if(t.supersedesDeliveryId===e.prDeliveryId)return 1;if(e.supersedesDeliveryId===t.prDeliveryId)return-1;let n=UN(e),r=UN(t);return n==null||r==null?null:r<n?-1:+(r>n)}function GN(e,t){let n=null;for(let r of e){if(r.supersedesDeliveryId!==t)continue;if(!n){n=r;continue}let e=UN(n),i=UN(r);(e==null||i==null||i>=e)&&(n=r)}return n}function KN(e,t){let n=t.restoredFromDeliveryId;if(!n)return!1;let r=GN(e,t.prDeliveryId);return!r||r.prDeliveryId===n}function qN(e,t){let n=e.filter(e=>e.role===`system`).map(e=>wo(e.content)).filter(e=>e!==null),r=[...n].reverse().find(e=>e.prDeliveryId===t.prDeliveryId),i=KN(n,t);if(r){let e=VN.has(r.decision),n=VN.has(t.decision),a=zt(r.updatedAt,t.updatedAt);if(a===-1||a===0&&!HN(r,t)||e&&!n&&!(i&&r.decision===`superseded`))return!0}let a=new Set(n.map(e=>e.supersedesDeliveryId).filter(e=>!!e));if(i)return!1;if(a.has(t.prDeliveryId)&&t.decision!==`superseded`)return!0;for(let e of n){if(e.railIndex!==t.railIndex||e.prDeliveryId===t.prDeliveryId||a.has(e.prDeliveryId))continue;let n=WN(e,t);if(n===-1||(n===0||n===null)&&!VN.has(e.decision)&&t.supersedesDeliveryId!==e.prDeliveryId)return!0}return!1}function JN(e,t){let n=t.restoredFromDeliveryId;if(!n)return e;let r=!1,i=e.map(e=>{if(e.role!==`system`)return e;let t=wo(e.content);return!t||t.prDeliveryId!==n||VN.has(t.decision)?e:(r=!0,{...e,content:JSON.stringify({...t,decision:`discarded`})})});return r?i:e}function YN(e,t){let n=e.filter(e=>e.role===`system`).map(e=>wo(e.content)).filter(e=>e!==null);if(n.some(e=>e.restoredFromDeliveryId===t.prDeliveryId&&KN(n,e)))return e;let r=!1,i=e.map(e=>{if(e.role!==`system`)return e;let n=wo(e.content);return!n||n.railIndex!==t.railIndex||n.prDeliveryId===t.prDeliveryId||VN.has(n.decision)||WN(n,t)!==1?e:(r=!0,{...e,content:JSON.stringify({...n,decision:`superseded`})})});return r?i:e}function XN(e,t,n){if(qN(e,n))return e;let r=YN(JN(e,n),n),i=JSON.stringify(n),a=r.flatMap((e,t)=>e.role===`system`&&wo(e.content)?.prDeliveryId===n.prDeliveryId?[t]:[]);if(a.length>0){let e=a[a.length-1];if(a.length===1&&r[e].content===i)return r;let t=new Set(a.slice(0,-1));return r.flatMap((n,r)=>t.has(r)?[]:[r===e?{...n,content:i}:n])}return[...r,{id:`prd-${n.prDeliveryId}`,conversation_id:t,role:`system`,content:i,created_at:new Date().toISOString()}]}var ZN=(0,Q.createContext)(null),QN=0,$N=0,eP={sent:0,received:1,read:2};function tP(e,t){return e&&(!t||eP[e]>=eP[t])?e:t}function nP(e,t){let n=[...e];for(let[e,r]of t.entries()){let i=n.findIndex(e=>e.id===r.id);if(i>=0){let e=tP(n[i].delivery_receipt,r.delivery_receipt);n[i]={...r,...e?{delivery_receipt:e}:{}}}else{let i=new Set(t.slice(e+1).map(e=>e.id)),a=n.findIndex(e=>i.has(e.id));a>=0?n.splice(a,0,r):n.push(r)}}return n}function rP({children:e}){let{registerHandler:t,unregisterHandler:n,connectionStatus:r}=tt(),{uiMode:i}=MN(),{setActiveProjectId:a,activeProjectId:o}=pt(),s=Ci(),c=(0,Q.useRef)(s);c.current=s;let l=hi(),u=e=>e?c.current.isEditable(e):!l,[d,f]=(0,Q.useState)(`hidden`),[p,m]=(0,Q.useState)([]),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)([]),y=(0,Q.useRef)(new Map),b=(0,Q.useRef)(_);b.current=_;let[x,S]=(0,Q.useState)(FN);(0,Q.useEffect)(()=>{let e=e=>{(e.key===PN||e.key===null)&&S(FN())};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]);let[C,w]=(0,Q.useState)(new Set),[T,E]=(0,Q.useState)(new Map),[D,O]=(0,Q.useState)(!0),[k,A]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(null),[N,P]=(0,Q.useState)([]),F=(0,Q.useRef)([]);F.current=N;let I=(0,Q.useRef)(!1),[L,R]=(0,Q.useState)(null),z=(0,Q.useRef)(null);z.current=L;let[B,V]=(0,Q.useState)(`claude`),[H,U]=(0,Q.useState)(null),[W,ee]=(0,Q.useState)(()=>zN()),[te,ne]=(0,Q.useState)(null),re=(0,Q.useRef)({provider:`claude`,model:null,tierLevel:0,effort:null});re.current={provider:B,model:H,tierLevel:W,effort:te};let ie=(0,Q.useRef)(null);ie.current=h?.id??null;let ae=(0,Q.useRef)(T);ae.current=T;let oe=(0,Q.useRef)(new Set),se=(0,Q.useRef)(new Set),ce=(0,Q.useRef)(new Map),le=(0,Q.useRef)(new Map),ue=e=>{let t=tP(e.delivery_receipt,ce.current.get(`${e.conversation_id}:m:${e.id}`));return t?{...e,delivery_receipt:t}:e},de=(e,t)=>{let n=tP(t.deliveryReceipt,ce.current.get(`${e}:q:${t.queueId}`));return n?{...t,deliveryReceipt:n}:t},fe=(0,Q.useRef)(new Set),G=(0,Q.useRef)(new Map),pe=(0,Q.useRef)(new Map),me=(0,Q.useRef)(new Map),he=(0,Q.useRef)(null),ge=(0,Q.useRef)(0),_e=(0,Q.useRef)(0),ve=(0,Q.useRef)(new Map),ye=(0,Q.useCallback)(e=>{let t=ie.current;if(!t)return`untracked`;if(qN(b.current,e))return`stale`;if(!b.current.some(t=>t.role===`system`&&wo(t.content)?.prDeliveryId===e.prDeliveryId))return`untracked`;ge.current++;let n=XN(b.current,t,e);return b.current=n,v(n=>{if(!n.some(t=>t.role===`system`&&wo(t.content)?.prDeliveryId===e.prDeliveryId))return b.current=n,n;let r=XN(n,t,e);return b.current=r,r}),`accepted`},[]),be=(0,Q.useCallback)((e,t)=>{E(n=>{let r=t(n.get(e)??NN),i=new Map(n);return r===null||!r.isStreaming&&!r.streamingText&&r.liveTools.length===0&&r.turnTools.length===0&&r.queued.length===0?i.delete(e):i.set(e,r),i})},[]),Se=(0,Q.useCallback)(e=>{let t=typeof document<`u`&&document.visibilityState===`hidden`;e===ie.current&&!t||w(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),Ce=(0,Q.useCallback)(e=>{w(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]);(0,Q.useEffect)(()=>{if(!xe||typeof document>`u`)return;let e=()=>{if(document.visibilityState!==`visible`)return;let e=ie.current;e&&Ce(e)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[Ce]);let we=(h?T.get(h.id):void 0)??NN,Te=we.streamingText,Ee=we.isStreaming,De=we.liveTools,Oe=we.turnTools,ke=we.queued,Ae=(0,Q.useMemo)(()=>{let e=new Set;for(let[t,n]of T)n.isStreaming&&e.add(t);return e},[T]),je=(0,Q.useCallback)(async()=>{try{let e=await eo();m(e),S(t=>{let n=LN(FN(),e);return n.size===t.size&&[...n].every(e=>t.has(e))?t:(IN(n),n)})}catch{}},[]),Me=(0,Q.useCallback)(async()=>{try{let e=await Ao();O(e.enabled)}catch{O(!1)}},[]),Ne=(0,Q.useCallback)(async()=>{try{let{any:e,installed:t}=await ko();M(e),P(Array.isArray(t)?t:[])}catch{M(!0)}},[]),[Pe,Fe]=(0,Q.useState)(0);(0,Q.useEffect)(()=>xe?(t(`agent-chat`,e=>{let t=e;if(!t)return;if(t.type===`desktop.project_recovered`){Fe(e=>e+1);return}if(typeof t.type!=`string`||!t.type.startsWith(`agent_`))return;if(t.type===`agent_conversation_created`){je();return}if(t.type===`agent_title`&&t.conversationId){let e=t.title??null;m(n=>n.map(n=>n.id===t.conversationId?{...n,title:e}:n)),g(n=>n&&n.id===t.conversationId?{...n,title:e}:n);return}let n=t.conversationId;if(!n)return;G.current.set(n,(G.current.get(n)??0)+1);let r=n===ie.current,i=e=>{me.current.set(n,nP(me.current.get(n)??[],e).slice(-500)),r&&(b.current=nP(b.current,e),v(t=>nP(t,e)))};if(t.type===`agent_input_receipt`){if(t.receipt!==`received`&&t.receipt!==`read`)return;let e=`${n}:q:${t.queueId}`,a=t.messageId??le.current.get(e);if(t.queueId&&ce.current.set(e,tP(ce.current.get(e),t.receipt)),a){let e=`${n}:m:${a}`;ce.current.set(e,tP(ce.current.get(e),t.receipt));let o=(r?b.current:me.current.get(n)??[]).find(e=>e.id===a);o&&i([ue(o)])}be(n,e=>({...e,queued:e.queued.map(e=>e.queueId===t.queueId?{...e,deliveryReceipt:tP(e.deliveryReceipt,t.receipt)}:e)}))}else if(t.type===`agent_stream`)Se(n),be(n,e=>({...e,isStreaming:!0,streamingText:e.streamingText+(t.delta??``)}));else if(t.type===`agent_tool`)be(n,e=>({...e,isStreaming:!0,liveTools:[...e.liveTools,{id:`t${QN++}`,tool:t.tool??`tool`,...t.input?{input:t.input}:{},...t.toolId?{toolId:t.toolId}:{},...t.timestamp?{at:t.timestamp}:{}}].slice(-200)}));else if(t.type===`agent_tool_result`)be(n,e=>{let n=[...e.liveTools],r=t.toolId?n.findIndex(e=>e.toolId===t.toolId):-1;if(r===-1){for(let e=n.length-1;e>=0;e--)if(n[e].output===void 0){r=e;break}}return r===-1?e:(n[r]={...n[r],output:t.output??``,...t.isError?{isError:!0}:{}},{...e,liveTools:n})});else if(t.type===`agent_partial`){let e=t.fullText??``;e&&i([{id:t.messageId??`partial-${n}-${t.timestamp??Date.now()}`,conversation_id:n,role:`assistant`,content:e,created_at:t.timestamp??new Date().toISOString()}])}else if(t.type===`agent_done`){ve.current.delete(n),Se(n);let e=t.fullText??``;t.messageId&&e?i([{id:t.messageId,conversation_id:n,role:`assistant`,content:e,created_at:t.timestamp??new Date().toISOString()}]):r&&e&&v(t=>{let r=t[t.length-1];return r&&r.role===`assistant`&&r.content===e&&!r.id.startsWith(`local-`)?t:[...t,{id:`local-${Date.now()}`,conversation_id:n,role:`assistant`,content:e,created_at:new Date().toISOString()}]}),be(n,e=>({...NN,queued:e.queued,turnTools:e.liveTools.length?e.liveTools:e.turnTools}))}else if(t.type===`agent_error`){ve.current.delete(n),Se(n),be(n,e=>({...NN,queued:e.queued,turnTools:e.liveTools.length?e.liveTools:e.turnTools}));let e=t.error||`The agent turn failed.`;J.error(e),r&&v(t=>[...t,{id:`err-${Date.now()}`,conversation_id:n,role:`assistant`,content:`⚠️ ${e}`,created_at:new Date().toISOString()}])}else if(t.type===`agent_queued`){if(t.queueId&&oe.current.has(t.queueId))return;be(n,e=>{let r=tP(t.deliveryReceipt??t.delivery_receipt,ce.current.get(`${n}:q:${t.queueId}`)),i={queueId:t.queueId??`srv-${$N++}`,text:t.text??``,contextRefs:t.contextRefs,attachmentIds:t.attachmentIds,deliveryMode:t.deliveryMode,...r?{deliveryReceipt:r}:{},timestamp:t.timestamp};return t.queueId&&e.queued.some(e=>e.queueId===t.queueId)?{...e,queued:e.queued.map(e=>e.queueId===t.queueId?{...e,...i,deliveryReceipt:tP(e.deliveryReceipt,i.deliveryReceipt),deliveryMode:e.deliveryMode===`steer`?`steer`:i.deliveryMode??e.deliveryMode,attachmentIds:i.attachmentIds??e.attachmentIds,contextRefs:i.contextRefs??e.contextRefs}:e)}:{...e,queued:[...e.queued,i]}})}else if(t.type===`agent_steered`){if(!t.messageId)return;if(fe.current.has(t.messageId)){t.queueId&&oe.current.add(t.queueId),be(n,e=>({...e,queued:e.queued.filter(e=>e.queueId!==t.queueId)}));return}fe.current.add(t.messageId),t.queueId&&oe.current.add(t.queueId),le.current.set(`${n}:q:${t.queueId}`,t.messageId);let e=tP(t.delivery_receipt??t.deliveryReceipt,ce.current.get(`${n}:q:${t.queueId}`)),r=[];t.assistantSegment&&r.push({...t.assistantSegment,conversation_id:n,role:`assistant`}),r.push(ue({id:t.messageId,conversation_id:n,role:`user`,content:t.text??``,context_refs:t.contextRefs??[],attachment_ids:t.attachmentIds??[],delivery_status:t.deliveryStatus??`delivered`,...e?{delivery_receipt:e}:{},created_at:t.timestamp??new Date().toISOString()})),i(r),be(n,e=>({...e,queued:e.queued.filter(e=>e.queueId!==t.queueId),streamingText:t.assistantSegment?``:e.streamingText}))}else if(t.type===`agent_dequeued`||t.type===`agent_input_started`){if(r&&t.queueId&&(b.current=b.current.filter(e=>e.id!==`local-u-${t.queueId}`),v(e=>e.filter(e=>e.id!==`local-u-${t.queueId}`))),t.queueId&&oe.current.has(t.queueId))return;if(t.queueId&&oe.current.add(t.queueId),be(n,e=>({...e,queued:t.queueId?e.queued.filter(e=>e.queueId!==t.queueId):e.queued.slice(1),isStreaming:!0,streamingText:``,liveTools:[]})),t.text){t.messageId&&le.current.set(`${n}:q:${t.queueId}`,t.messageId);let e=tP(t.delivery_receipt??t.deliveryReceipt,ce.current.get(`${n}:q:${t.queueId}`));i([ue({id:t.messageId??`local-u-${Date.now()}`,conversation_id:n,role:`user`,content:t.text,context_refs:t.contextRefs??[],attachment_ids:t.attachmentIds??[],...t.messageId?{delivery_status:`delivered`}:{},...e?{delivery_receipt:e}:{},created_at:t.timestamp??new Date().toISOString()})])}}else if(t.type===`agent_queue_cleared`)pe.current.set(n,(pe.current.get(n)??0)+1),t.messages?.length&&i(t.messages),be(n,e=>({...e,queued:[]}));else if(t.type===`agent_queue_removed`){if(!t.queueId)return;oe.current.add(t.queueId),se.current.add(t.queueId),be(n,e=>({...e,queued:e.queued.filter(e=>e.queueId!==t.queueId)}))}else if(t.type===`agent_queue_edited`)be(n,e=>({...e,queued:e.queued.map(e=>t.queueId&&e.queueId===t.queueId?{...e,text:t.text??e.text,contextRefs:t.contextRefs??e.contextRefs,deliveryMode:t.deliveryMode??e.deliveryMode}:e)}));else if(t.type===`agent_run_failure`){if(Se(n),r){let{type:e,conversationId:r,messageId:i,timestamp:a,...o}=t;if(typeof i==`string`&&!b.current.some(e=>e.id===i)){let e={id:i,conversation_id:n,role:`system`,content:JSON.stringify(o),created_at:typeof a==`string`?a:new Date().toISOString()};b.current=[...b.current,e],v(t=>t.some(e=>e.id===i)?t:[...t,e])}}}else if(t.type===`agent_pr_decision`&&(Se(n),r)){let t=Co(e);if(t){ge.current++;let e=XN(b.current,n,t);b.current=e,v(e=>{let r=XN(e,n,t);return b.current=r,r})}}}),()=>n(`agent-chat`)):void 0,[t,n,be,Se,je]);let Ie=(0,Q.useCallback)(async(e,t)=>{let n=++_e.current,r=G.current.get(e)??0;ge.current++;let{conversation:i,messages:a,pendingMessages:o,live:s}=await io(e);if(t?.aborted)throw new DOMException(`Window transfer cancelled`,`AbortError`);if(n!==_e.current){if(t)throw new DOMException(`The mission changed during restoration`,`AbortError`);return}ge.current++;let c=nP(a,me.current.get(e)??[]).map(ue);for(let e of c)(e.delivery_status===`delivered`||e.delivery_status===`interrupted`)&&fe.current.add(e.id);g(i),b.current=c,v(c),Ce(e),r===(G.current.get(e)??0)&&(o!==void 0||s)&&be(e,t=>({...t,...s?{isStreaming:s.isStreaming,streamingText:s.streamingText}:{},queued:o?.filter(e=>!oe.current.has(e.queueId)).map(t=>de(e,t))??t.queued}))},[Ce,be]),Le=(0,Q.useCallback)(async()=>{let e=ie.current;if(!e)return;let t=ge.current,n=G.current.get(e)??0,r=y.current.get(e)??0;try{let i=await io(e);if(ie.current!==e||ge.current!==t)return;if(r===(y.current.get(e)??0)&&(g(t=>t?.id===e?i.conversation:t),m(t=>t.map(t=>t.id===e?i.conversation:t))),(i.pendingMessages!==void 0||i.live)&&n===(G.current.get(e)??0)){let t=nP(i.messages,me.current.get(e)??[]).map(ue);for(let e of t)(e.delivery_status===`delivered`||e.delivery_status===`interrupted`)&&fe.current.add(e.id);v(e=>nP(t,e.filter(e=>e.id.startsWith(`local-u-`)&&!t.some(t=>t.role===`user`&&t.content===e.content)))),be(e,t=>({...t,...i.live?{isStreaming:i.live.isStreaming,streamingText:i.live.streamingText}:{},queued:i.pendingMessages?.filter(e=>!oe.current.has(e.queueId)).map(t=>de(e,t))??t.queued}))}let a=i.messages.filter(e=>e.role===`system`).map(e=>wo(e.content)).filter(e=>e!==null);if(a.length===0)return;v(t=>{let n=a.reduce((t,n)=>XN(t,e,n),t);return b.current=n,n})}catch{}},[be]),Re=(0,Q.useCallback)(async()=>{try{let e=new Map(G.current),t=await no(),n=new Set(t.turns.map(e=>e.conversationId)),r=Date.parse(t.capturedAt),i=[...ae.current].flatMap(([t,i])=>{if(!i.isStreaming||n.has(t)||(e.get(t)??0)!==(G.current.get(t)??0))return[];let a=ve.current.get(t);return a&&Date.parse(a)>r?[]:[t]});E(i=>{let a=new Map(i);for(let[t,o]of i){if(!o.isStreaming||n.has(t)||(e.get(t)??0)!==(G.current.get(t)??0))continue;let i=ve.current.get(t);i&&Date.parse(i)>r||a.set(t,{...NN,queued:o.queued,turnTools:o.liveTools.length?o.liveTools:o.turnTools})}for(let n of t.turns){let t=n.conversationId;if((e.get(t)??0)!==(G.current.get(t)??0))continue;let r=a.get(t)??NN;a.set(t,{...r,isStreaming:!0,streamingText:n.streamingText??r.streamingText,queued:n.pendingMessages?.filter(e=>!oe.current.has(e.queueId)).map(e=>de(t,e))??r.queued})}return a});for(let e of i)ve.current.delete(e);let a=ie.current;if(a&&i.includes(a)){let e=`interrupted-${a}-${t.snapshotVersion}`;v(n=>n.some(t=>t.id===e)?n:[...n,{id:e,conversation_id:a,role:`assistant`,content:`⚠️ The agent turn was interrupted when the Specrails server reconnected. It was not retried.`,created_at:t.capturedAt}])}console.info(`[agent-chat] reconciled active turns`,{snapshotVersion:t.snapshotVersion,active:n.size,interrupted:i.length})}catch{}},[]);(0,Q.useEffect)(()=>{let e=()=>{je(),Le()};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[Le,je]),(0,Q.useEffect)(()=>{Pe&&(je(),Le())},[Pe,je,Le]);let ze=(0,Q.useRef)(r);(0,Q.useEffect)(()=>{let e=ze.current;ze.current=r,r===`connected`&&e!==`connected`&&(je(),Me(),Ne(),Le(),Re())},[r,je,Me,Ne,Le,Re]);let Be=(0,Q.useCallback)(async()=>{if(h)return h;if(l)throw Error(`This window is reserved for its mission.`);let e=await eo();if(m(e),S(t=>{let n=LN(FN(),e);return n.size===t.size&&[...n].every(e=>t.has(e))?t:(IN(n),n)}),e.length>0)return await Ie(e[0].id),e[0];let t=await ro({});return m(e=>[t,...e.filter(e=>e.id!==t.id)]),g(t),v([]),t},[h,Ie]),Ve=(0,Q.useCallback)(()=>{f(`open`),je(),Me(),Ne(),Be()},[je,Me,Ne,Be]),He=(0,Q.useCallback)(()=>f(`hidden`),[]),Ue=(0,Q.useCallback)(()=>f(`minimized`),[]),[We,Ge]=(0,Q.useState)(!1),Ke=(0,Q.useRef)(null),qe=(0,Q.useCallback)(()=>{Ke.current?.abortAndReset(),Ge(!1)},[]),Je=JM(We,{onFinished:qe});Ke.current=Je;let Ye=(0,Q.useCallback)(()=>{l||(Ge(!0),i!==`agent`&&Ve())},[i,Ve]),Xe=(0,Q.useCallback)(()=>{f(e=>e===`open`?`minimized`:`open`),d!==`open`&&(je(),Me(),Ne(),Be())},[d,je,Me,Ne,Be]),Ze=(0,Q.useCallback)(async()=>{if(!u(h?.id))throw Error(`This mission is active in another window.`);if(h)return h;if(he.current)return he.current;let e=ro({pinnedProjectId:z.current,provider:re.current.provider,model:re.current.model,tierLevel:re.current.tierLevel,reasoningEffort:re.current.effort}).then(e=>(pi(e.id),m(t=>[e,...t.filter(t=>t.id!==e.id)]),g(e),v([]),e)).finally(()=>{he.current=null});return he.current=e,e},[h]),Qe=(0,Q.useCallback)(async(e,t)=>{if(!u(h?.id))return{accepted:!1};let n=e.trim();if(!n)return{accepted:!1};let r=h??await Ze();G.current.set(r.id,(G.current.get(r.id)??0)+1);let i=G.current.get(r.id),a=pe.current.get(r.id)??0,o=t?.queueId??`q-${Date.now()}-${$N++}`,s=new Date().toISOString();ve.current.set(r.id,s),m(e=>[{...e.find(e=>e.id===r.id)??r,updated_at:s},...e.filter(e=>e.id!==r.id)]),g(e=>e&&e.id===r.id?{...e,updated_at:s}:e);let c={id:`local-u-${o}`,conversation_id:r.id,role:`user`,content:n,attachment_ids:t?.attachmentIds??[],context_refs:t?.contextRefs??[],delivery_receipt:`sent`,created_at:s},l=ae.current.get(r.id)?.isStreaming===!0,d={queueId:o,text:n,contextRefs:t?.contextRefs,attachmentIds:t?.attachmentIds,deliveryMode:`queue`,deliveryReceipt:`sent`,timestamp:s};l?be(r.id,e=>({...e,queued:e.queued.some(e=>e.queueId===o)?e.queued.map(e=>e.queueId===o?{...d,deliveryReceipt:tP(e.deliveryReceipt,d.deliveryReceipt),deliveryMode:e.deliveryMode??d.deliveryMode,timestamp:e.timestamp??d.timestamp}:e):[...e.queued,d]})):(v(e=>[...e,c]),be(r.id,e=>({...e,isStreaming:!0,streamingText:``,liveTools:[]})));let f=t?.attachmentIds&&t.attachmentIds.length?{ids:t.attachmentIds}:void 0;try{let e=t?.contextRefs&&t.contextRefs.length?t.contextRefs:void 0,s=await so(r.id,n,{tierLevel:r.tier_level,attachments:f,queueId:o,contextRefs:e});if(s.removed){oe.current.add(o),se.current.add(o);let e=!l&&i===G.current.get(r.id);return ie.current===r.id&&v(e=>e.filter(e=>e.id!==c.id)),be(r.id,t=>({...t,queued:t.queued.filter(e=>e.queueId!==o),...e?{isStreaming:!1}:{}})),e&&ve.current.delete(r.id),{accepted:!0,conversationId:r.id}}if(s.message){le.current.set(`${r.id}:q:${o}`,s.message.id);let e=tP(s.message.delivery_receipt,ce.current.get(`${r.id}:q:${o}`)),t=ue({...s.message,...e?{delivery_receipt:e}:{}});return oe.current.add(o),me.current.set(r.id,nP(me.current.get(r.id)??[],[t]).slice(-500)),ie.current===r.id&&v(e=>nP(e.filter(e=>e.id!==c.id),[t])),be(r.id,e=>({...e,queued:e.queued.filter(e=>e.queueId!==o)})),s.duplicate&&Re(),{accepted:!0,conversationId:r.id}}if(a!==(pe.current.get(r.id)??0))return v(e=>e.filter(e=>e.id!==c.id)),{accepted:!0,conversationId:r.id};let u=s?.queued===!0;return u&&!l?(v(e=>e.filter(e=>e.id!==c.id)),oe.current.has(o)||be(r.id,e=>e.queued.some(e=>e.queueId===o)?e:{...e,queued:[...e.queued,{...d,deliveryMode:s.deliveryMode??d.deliveryMode}]})):!u&&l&&!oe.current.has(o)&&(be(r.id,e=>({...e,queued:e.queued.filter(e=>e.queueId!==o),isStreaming:!0})),v(e=>[...e,c])),{accepted:!0,conversationId:r.id}}catch(e){return oe.current.has(o)||a!==(pe.current.get(r.id)??0)?{accepted:!0,conversationId:r.id}:(ve.current.delete(r.id),l?be(r.id,e=>({...e,queued:e.queued.filter(e=>e.queueId!==o)})):(be(r.id,e=>({...e,isStreaming:!1,streamingText:``,liveTools:[]})),v(e=>e.filter(e=>e.id!==c.id))),J.error(e instanceof Error?e.message:`Failed to send message.`),{accepted:!1,conversationId:r.id})}},[h,Ze,be,Re]),$e=(0,Q.useCallback)(async()=>{if(!(!h||!u(h.id)))try{await mo(h.id),pe.current.set(h.id,(pe.current.get(h.id)??0)+1),G.current.set(h.id,(G.current.get(h.id)??0)+1),be(h.id,()=>null)}catch(e){J.error(e instanceof Error?e.message:`Failed to stop the agent.`)}},[h,be]),et=(0,Q.useCallback)(async(e,t)=>{let n=h;if(!n||!u(n.id)||ae.current.get(n.id)?.queued.find(t=>t.queueId===e)?.deliveryMode===`steer`)return`conflict`;let r=await ho(n.id,e,t);return r===`saved`&&be(n.id,n=>({...n,queued:n.queued.map(n=>n.queueId===e?{...n,text:t}:n)})),r},[h,be]),nt=(0,Q.useCallback)(async e=>{let t=h,n=t&&ae.current.get(t.id)?.queued.find(t=>t.queueId===e);if(!t||!u(t.id)||!n||n.deliveryMode===`steer`)return`conflict`;let r=await go(t.id,e);return r===`saved`?(G.current.set(t.id,(G.current.get(t.id)??0)+1),be(t.id,t=>({...t,queued:t.queued.map(t=>t.queueId===e?{...t,deliveryMode:`steer`}:t)}))):ie.current===t.id&&Le(),r},[h,be,Le]),rt=(0,Q.useCallback)(async e=>{let t=h,n=t&&ae.current.get(t.id)?.queued.find(t=>t.queueId===e);if(!t||!u(t.id)||!n||n.deliveryMode===`steer`)return`conflict`;let r=await _o(t.id,e);return r===`saved`?(oe.current.add(e),se.current.add(e),G.current.set(t.id,(G.current.get(t.id)??0)+1),be(t.id,t=>({...t,queued:t.queued.filter(t=>t.queueId!==e)}))):ie.current===t.id&&Le(),r},[h,be,Le]),it=(0,Q.useCallback)(e=>oe.current.has(e)&&!se.current.has(e),[]),at=(0,Q.useCallback)(async e=>{if(!h||!u(h.id))return;let t=(y.current.get(h.id)??0)+1;y.current.set(h.id,t);let n=await ao(h.id,e);y.current.get(h.id)===t&&(g(e=>e?.id===n.id?n:e),m(e=>e.map(e=>e.id===n.id?n:e)))},[h]),ot=(0,Q.useCallback)(async e=>{u(h?.id)&&(BN(e),h?await at({tierLevel:e}):ee(e))},[h,at]),st=(0,Q.useCallback)(async()=>{let e=((h?.tier_level??W)+1)%4;await ot(e)},[h,W,ot]),ct=(0,Q.useCallback)(async e=>{h?await at({provider:e}):(I.current=!0,V(e),U(null),ne(null))},[h,at]);(0,Q.useEffect)(()=>{h||I.current||N.length===0||N.includes(B)||(V(Ot(N)),U(null),ne(null))},[h,N,B]);let lt=(0,Q.useCallback)(async e=>{h?await at({model:e}):(U(e),ne(null))},[h,at]),K=(0,Q.useCallback)(async e=>{h?await at({reasoningEffort:e}):ne(e)},[h,at]),q=(0,Q.useCallback)(async e=>{l||!u(h?.id)||(h?await at({pinnedProjectId:e}):R(e),!h&&e&&i===`agent`&&a(e))},[h,at,i,a]),ut=(0,Q.useRef)(void 0);(0,Q.useEffect)(()=>{let e=ut.current;if(ut.current=o,!(e===void 0||e===o)&&!(l||i!==`agent`||!o)){if(!h){R(o);return}b.current.length>0||h.pinned_project_id!==o&&at({pinnedProjectId:o})}},[o,i,h,at]);let dt=(0,Q.useCallback)(e=>{l||(qe(),g(null),v([]),R(e??null),I.current=!1,V(Ot(F.current)),U(null),ee(zN()),ne(null))},[qe]),ft=(0,Q.useCallback)(async e=>{if(l)return;qe();let t=await ro({pinnedProjectId:e===void 0?h?.pinned_project_id??null:e,tierLevel:zN()});m(e=>[t,...e.filter(e=>e.id!==t.id)]),g(t),v([])},[h,qe]),mt=(0,Q.useCallback)(async(e,t)=>{if(!(l&&!t?.windowRestore&&c.current.current?.conversationId!==e)&&!(!l&&!t?.windowRestore&&await c.current.focus(e))){if(t?.signal?.aborted)throw new DOMException(`Window transfer cancelled`,`AbortError`);qe(),await Ie(e,t?.signal),t?.windowRestore&&i!==`agent`&&f(`open`)}},[Ie,qe,l,i]),Y=(0,Q.useCallback)(async e=>{u(e)&&(await oo(e),await c.current.discard(e),m(t=>t.filter(t=>t.id!==e)),S(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),IN(n),n}),be(e,()=>null),ie.current===e&&(g(null),v([])))},[be]),ht=(0,Q.useCallback)(async(e,t)=>{if(!u(e))return;let n=t.trim()||null;y.current.set(e,(y.current.get(e)??0)+1);let r;m(t=>t.map(t=>t.id===e?(r=t.title,{...t,title:n}):t)),g(t=>t&&t.id===e?{...t,title:n}:t);try{await ao(e,{title:n})}catch(t){throw m(t=>t.map(t=>t.id===e?{...t,title:r??null}:t)),g(t=>t&&t.id===e?{...t,title:r??null}:t),t}},[]),gt=(0,Q.useCallback)(e=>{S(()=>{let t=new Set(FN());return t.has(e)?t.delete(e):t.add(e),IN(t),t})},[]),_t=(0,Q.useCallback)(async()=>{A(!0);try{await jo(),await Me()}catch(e){J.error(e instanceof Error?e.message:`Failed to enable MCP.`)}finally{A(!1)}},[Me]),vt=(0,Q.useMemo)(()=>({visibility:d,open:Ve,close:He,minimize:Ue,toggle:Xe,conversations:p,active:h,messages:_,streamingText:Te,isStreaming:Ee,liveTools:De,turnTools:Oe,queuedMessages:ke,streamingConversationIds:Ae,liveByConversation:T,unreadConversationIds:C,favoriteConversationIds:x,mcpEnabled:D,enablingMcp:k,enableMcpServer:_t,providersReady:j,send:Qe,abort:$e,editQueuedMessage:et,steerQueuedMessage:nt,removeQueuedMessage:rt,wasQueueConsumed:it,cycleTier:st,setTier:ot,setProvider:ct,setModel:lt,setPinnedProject:q,newConversation:ft,startNewConversation:dt,materializeDraftConversation:Ze,draftPinnedProjectId:L,draftProvider:B,draftModel:H,draftTierLevel:W,draftEffort:te,setEffort:K,selectConversation:mt,deleteConversation:Y,renameConversation:ht,toggleFavoriteConversation:gt,refreshConversations:je,applyPrDecisionSnapshot:ye,builderMode:{active:We,enter:Ye,exit:qe,session:Je}}),[d,Ve,He,Ue,Xe,We,Ye,qe,Je,p,h,_,Te,Ee,De,Oe,ke,Ae,T,C,x,D,k,_t,j,Qe,$e,et,nt,rt,it,st,ot,ct,lt,q,ft,dt,Ze,L,B,H,W,te,K,mt,Y,ht,gt,je,ye]),yt=xe&&i!==`agent`;return(0,$.jsxs)(ZN.Provider,{value:vt,children:[e,yt&&d===`open`&&(0,$.jsx)(vN,{}),yt&&d!==`open`&&(0,$.jsx)(TN,{})]})}var iP={visibility:`hidden`,open:()=>{},close:()=>{},minimize:()=>{},toggle:()=>{},conversations:[],active:null,messages:[],streamingText:``,isStreaming:!1,liveTools:[],turnTools:[],queuedMessages:[],streamingConversationIds:new Set,unreadConversationIds:new Set,liveByConversation:new Map,favoriteConversationIds:new Set,mcpEnabled:!0,enablingMcp:!1,enableMcpServer:async()=>{},providersReady:!0,send:async()=>({accepted:!1}),abort:async()=>{},editQueuedMessage:async()=>`conflict`,steerQueuedMessage:async()=>`conflict`,removeQueuedMessage:async()=>`conflict`,wasQueueConsumed:()=>!1,cycleTier:async()=>{},setTier:async()=>{},setProvider:async()=>{},setModel:async()=>{},setPinnedProject:async()=>{},newConversation:async()=>{},startNewConversation:()=>{},materializeDraftConversation:async()=>{throw Error(`AgentChatProvider is not mounted`)},draftPinnedProjectId:null,draftProvider:`claude`,draftModel:null,draftTierLevel:0,draftEffort:null,setEffort:async()=>{},selectConversation:async()=>{},deleteConversation:async()=>{},renameConversation:async()=>{},toggleFavoriteConversation:()=>{},refreshConversations:async()=>{},applyPrDecisionSnapshot:()=>`untracked`,builderMode:{active:!1,enter:()=>{},exit:()=>{},session:{phase:`chat`,messages:[],streamBuffer:null,blueprint:null,busy:!1,commitError:null,commitErrorDetail:null,commitSteps:[],createdProjectId:null,launching:!1,launched:!1,submitting:!1,conversationReady:!1,conversationId:null,dirty:!1,canProposeCommit:!1,specQualityDetail:null,readiness:{ready:!1,steps:[],issues:[]},snapshot:{status:`idle`},generation:{generating:!1,specsStarted:0},recent:[],recentLoading:!1,resume:async()=>{},discardRecent:async()=>{},repairSnapshot:async()=>{},showSurpriseMe:!0,provider:`claude`,model:null,models:[],efforts:[],effort:`medium`,draft:``,setDraft:()=>{},setEffort:()=>{},setProvider:()=>{},setModel:()=>{},send:()=>{},surpriseMe:()=>{},approveBlueprint:()=>{},goToCommit:()=>{},backToChat:()=>{},submitCommit:()=>{},launchM1:async()=>{},openProject:()=>{},abortAndReset:()=>{}}}};function aP(){return(0,Q.useContext)(ZN)??iP}var oP=new Map;function sP(){let e=aP(),t=lO(),n=pt(),r=za(),{registerHandlers:i}=Ci(),{t:a}=K(`agent`),o=(0,Q.useRef)({chat:e,workspace:t,desktop:n,terminals:r,t:a});o.current={chat:e,workspace:t,desktop:n,terminals:r,t:a};let s=(0,Q.useRef)(null),c=(0,Q.useRef)(!1);(0,Q.useLayoutEffect)(()=>{let n=e.active?.id??`__new-mission__`,r=s.current;if(c.current||r===n)return;s.current=n,r&&oP.set(r,t.captureWorkspace());let i=oP.get(n);i?t.restoreWorkspace(i):r&&t.restoreWorkspace({...t.captureWorkspace(),browserOpen:!1,browserOwnerId:null,browserUrl:null,pendingCaptures:[]})},[e.active?.id]);let[l,u]=(0,Q.useState)(null);return(0,Q.useLayoutEffect)(()=>{l&&!l.signal.aborted&&e.active?.id===l.target.conversationId&&n.activeProjectId===l.target.projectId&&(l.resolve(),u(e=>e===l?null:e))},[l,e.active?.id,n.activeProjectId]),(0,Q.useEffect)(()=>i({recover(e,t){Uy(t.conversationId,e.scroll)},capture(e){let{chat:t,workspace:n,terminals:r,t:i}=o.current;if(t.active?.id!==e.conversationId)throw Error(i(`window.wrongMission`));if(Ky(e.conversationId))throw Error(i(`window.finishPending`));return{version:1,...e,capturedAt:Date.now(),composer:si(e.conversationId),scroll:Hy(e.conversationId),workspace:{...n.captureWorkspace(),...e.projectId?{codeSelection:Fy(e.projectId,e.conversationId),terminal:(({activeId:e,visibility:t,userHeight:n})=>({activeId:e,visibility:t,userHeight:n}))(r.getState(e.projectId))}:{}}}},async restore(e,t,n){let r=()=>new DOMException(`Window transfer cancelled`,`AbortError`);if(n.aborted)throw r();let i=o.current.chat.active?.id;i&&oP.set(i,o.current.workspace.captureWorkspace()),c.current=!0;try{if(await o.current.chat.selectConversation(t.conversationId,{windowRestore:!0,signal:n}),n.aborted)throw r();if(s.current=t.conversationId,oP.set(t.conversationId,e.workspace),li(t.conversationId,e.composer),t.projectId&&(e.workspace.codeSelection&&Iy(t.projectId,t.conversationId,e.workspace.codeSelection),e.workspace.terminal)){let n=e.workspace.terminal,r=o.current.terminals;r.ensureProject(t.projectId),r.setVisibility(t.projectId,n.visibility),r.setUserHeight(t.projectId,n.userHeight),n.activeId&&r.setActive(t.projectId,n.activeId)}o.current.workspace.restoreWorkspace(e.workspace),o.current.desktop.setActiveProjectId(t.projectId),Uy(t.conversationId,e.scroll),await new Promise((e,i)=>{let a=()=>{u(e=>e?.signal===n?null:e),i(r())};n.addEventListener(`abort`,a,{once:!0}),u({target:t,signal:n,resolve:()=>{n.removeEventListener(`abort`,a),e()}})})}finally{c.current=!1}}}),[i]),null}var cP=class{constructor(...e){this.type=`Logical`,e.length===1?`Logical`in e[0]?(this.width=e[0].Logical.width,this.height=e[0].Logical.height):(this.width=e[0].width,this.height=e[0].height):(this.width=e[0],this.height=e[1])}toPhysical(e){return new lP(this.width*e,this.height*e)}[gt](){return{width:this.width,height:this.height}}toJSON(){return this[gt]()}},lP=class{constructor(...e){this.type=`Physical`,e.length===1?`Physical`in e[0]?(this.width=e[0].Physical.width,this.height=e[0].Physical.height):(this.width=e[0].width,this.height=e[0].height):(this.width=e[0],this.height=e[1])}toLogical(e){return new cP(this.width/e,this.height/e)}[gt](){return{width:this.width,height:this.height}}toJSON(){return this[gt]()}},uP=class{constructor(e){this.size=e}toLogical(e){return this.size instanceof cP?this.size:this.size.toLogical(e)}toPhysical(e){return this.size instanceof lP?this.size:this.size.toPhysical(e)}[gt](){return{[`${this.size.type}`]:{width:this.size.width,height:this.size.height}}}toJSON(){return this[gt]()}},dP=class{constructor(...e){this.type=`Logical`,e.length===1?`Logical`in e[0]?(this.x=e[0].Logical.x,this.y=e[0].Logical.y):(this.x=e[0].x,this.y=e[0].y):(this.x=e[0],this.y=e[1])}toPhysical(e){return new fP(this.x*e,this.y*e)}[gt](){return{x:this.x,y:this.y}}toJSON(){return this[gt]()}},fP=class{constructor(...e){this.type=`Physical`,e.length===1?`Physical`in e[0]?(this.x=e[0].Physical.x,this.y=e[0].Physical.y):(this.x=e[0].x,this.y=e[0].y):(this.x=e[0],this.y=e[1])}toLogical(e){return new dP(this.x/e,this.y/e)}[gt](){return{x:this.x,y:this.y}}toJSON(){return this[gt]()}},pP=class{constructor(e){this.position=e}toLogical(e){return this.position instanceof dP?this.position:this.position.toLogical(e)}toPhysical(e){return this.position instanceof fP?this.position:this.position.toPhysical(e)}[gt](){return{[`${this.position.type}`]:{x:this.position.x,y:this.position.y}}}toJSON(){return this[gt]()}},mP;(function(e){e[e.Critical=1]=`Critical`,e[e.Informational=2]=`Informational`})(mP||={});var hP=class{constructor(e){this._preventDefault=!1,this.event=e.event,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}},gP;(function(e){e.None=`none`,e.Normal=`normal`,e.Indeterminate=`indeterminate`,e.Paused=`paused`,e.Error=`error`})(gP||={});function _P(){return new bP(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}async function vP(){return Y(`plugin:window|get_all_windows`).then(e=>e.map(e=>new bP(e,{skip:!0})))}var yP=[`tauri://created`,`tauri://error`],bP=class{constructor(e,t={}){this.label=e,this.listeners=Object.create(null),t?.skip||Y(`plugin:window|create`,{options:{...t,parent:typeof t.parent==`string`?t.parent:t.parent?.label,label:e}}).then(async()=>this.emit(`tauri://created`)).catch(async e=>this.emit(`tauri://error`,e))}static async getByLabel(e){return(await vP()).find(t=>t.label===e)??null}static getCurrent(){return _P()}static async getAll(){return vP()}static async getFocusedWindow(){for(let e of await vP())if(await e.isFocused())return e;return null}async listen(e,t){return this._handleTauriEvent(e,t)?()=>{let n=this.listeners[e];n.splice(n.indexOf(t),1)}:Ar(e,t,{target:{kind:`Window`,label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?()=>{let n=this.listeners[e];n.splice(n.indexOf(t),1)}:Mr(e,t,{target:{kind:`Window`,label:this.label}})}async emit(e,t){if(yP.includes(e)){for(let n of this.listeners[e]||[])n({event:e,id:-1,payload:t});return}return jr(e,t)}async emitTo(e,t,n){if(yP.includes(t)){for(let e of this.listeners[t]||[])e({event:t,id:-1,payload:n});return}return Nr(e,t,n)}_handleTauriEvent(e,t){return yP.includes(e)?(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0):!1}async scaleFactor(){return Y(`plugin:window|scale_factor`,{label:this.label})}async innerPosition(){return Y(`plugin:window|inner_position`,{label:this.label}).then(e=>new fP(e))}async outerPosition(){return Y(`plugin:window|outer_position`,{label:this.label}).then(e=>new fP(e))}async innerSize(){return Y(`plugin:window|inner_size`,{label:this.label}).then(e=>new lP(e))}async outerSize(){return Y(`plugin:window|outer_size`,{label:this.label}).then(e=>new lP(e))}async isFullscreen(){return Y(`plugin:window|is_fullscreen`,{label:this.label})}async isMinimized(){return Y(`plugin:window|is_minimized`,{label:this.label})}async isMaximized(){return Y(`plugin:window|is_maximized`,{label:this.label})}async isFocused(){return Y(`plugin:window|is_focused`,{label:this.label})}async isDecorated(){return Y(`plugin:window|is_decorated`,{label:this.label})}async isResizable(){return Y(`plugin:window|is_resizable`,{label:this.label})}async isMaximizable(){return Y(`plugin:window|is_maximizable`,{label:this.label})}async isMinimizable(){return Y(`plugin:window|is_minimizable`,{label:this.label})}async isClosable(){return Y(`plugin:window|is_closable`,{label:this.label})}async isVisible(){return Y(`plugin:window|is_visible`,{label:this.label})}async title(){return Y(`plugin:window|title`,{label:this.label})}async theme(){return Y(`plugin:window|theme`,{label:this.label})}async isAlwaysOnTop(){return Y(`plugin:window|is_always_on_top`,{label:this.label})}async center(){return Y(`plugin:window|center`,{label:this.label})}async requestUserAttention(e){let t=null;return e&&(t=e===mP.Critical?{type:`Critical`}:{type:`Informational`}),Y(`plugin:window|request_user_attention`,{label:this.label,value:t})}async setResizable(e){return Y(`plugin:window|set_resizable`,{label:this.label,value:e})}async setEnabled(e){return Y(`plugin:window|set_enabled`,{label:this.label,value:e})}async isEnabled(){return Y(`plugin:window|is_enabled`,{label:this.label})}async setMaximizable(e){return Y(`plugin:window|set_maximizable`,{label:this.label,value:e})}async setMinimizable(e){return Y(`plugin:window|set_minimizable`,{label:this.label,value:e})}async setClosable(e){return Y(`plugin:window|set_closable`,{label:this.label,value:e})}async setTitle(e){return Y(`plugin:window|set_title`,{label:this.label,value:e})}async maximize(){return Y(`plugin:window|maximize`,{label:this.label})}async unmaximize(){return Y(`plugin:window|unmaximize`,{label:this.label})}async toggleMaximize(){return Y(`plugin:window|toggle_maximize`,{label:this.label})}async minimize(){return Y(`plugin:window|minimize`,{label:this.label})}async unminimize(){return Y(`plugin:window|unminimize`,{label:this.label})}async show(){return Y(`plugin:window|show`,{label:this.label})}async hide(){return Y(`plugin:window|hide`,{label:this.label})}async close(){return Y(`plugin:window|close`,{label:this.label})}async destroy(){return Y(`plugin:window|destroy`,{label:this.label})}async setDecorations(e){return Y(`plugin:window|set_decorations`,{label:this.label,value:e})}async setShadow(e){return Y(`plugin:window|set_shadow`,{label:this.label,value:e})}async setEffects(e){return Y(`plugin:window|set_effects`,{label:this.label,value:e})}async clearEffects(){return Y(`plugin:window|set_effects`,{label:this.label,value:null})}async setAlwaysOnTop(e){return Y(`plugin:window|set_always_on_top`,{label:this.label,value:e})}async setAlwaysOnBottom(e){return Y(`plugin:window|set_always_on_bottom`,{label:this.label,value:e})}async setContentProtected(e){return Y(`plugin:window|set_content_protected`,{label:this.label,value:e})}async setSize(e){return Y(`plugin:window|set_size`,{label:this.label,value:e instanceof uP?e:new uP(e)})}async setMinSize(e){return Y(`plugin:window|set_min_size`,{label:this.label,value:e instanceof uP?e:e?new uP(e):null})}async setMaxSize(e){return Y(`plugin:window|set_max_size`,{label:this.label,value:e instanceof uP?e:e?new uP(e):null})}async setSizeConstraints(e){function t(e){return e?{Logical:e}:null}return Y(`plugin:window|set_size_constraints`,{label:this.label,value:{minWidth:t(e?.minWidth),minHeight:t(e?.minHeight),maxWidth:t(e?.maxWidth),maxHeight:t(e?.maxHeight)}})}async setPosition(e){return Y(`plugin:window|set_position`,{label:this.label,value:e instanceof pP?e:new pP(e)})}async setFullscreen(e){return Y(`plugin:window|set_fullscreen`,{label:this.label,value:e})}async setSimpleFullscreen(e){return Y(`plugin:window|set_simple_fullscreen`,{label:this.label,value:e})}async setFocus(){return Y(`plugin:window|set_focus`,{label:this.label})}async setFocusable(e){return Y(`plugin:window|set_focusable`,{label:this.label,value:e})}async setIcon(e){return Y(`plugin:window|set_icon`,{label:this.label,value:Ea(e)})}async setSkipTaskbar(e){return Y(`plugin:window|set_skip_taskbar`,{label:this.label,value:e})}async setCursorGrab(e){return Y(`plugin:window|set_cursor_grab`,{label:this.label,value:e})}async setCursorVisible(e){return Y(`plugin:window|set_cursor_visible`,{label:this.label,value:e})}async setCursorIcon(e){return Y(`plugin:window|set_cursor_icon`,{label:this.label,value:e})}async setBackgroundColor(e){return Y(`plugin:window|set_background_color`,{color:e})}async setCursorPosition(e){return Y(`plugin:window|set_cursor_position`,{label:this.label,value:e instanceof pP?e:new pP(e)})}async setIgnoreCursorEvents(e){return Y(`plugin:window|set_ignore_cursor_events`,{label:this.label,value:e})}async startDragging(){return Y(`plugin:window|start_dragging`,{label:this.label})}async startResizeDragging(e){return Y(`plugin:window|start_resize_dragging`,{label:this.label,value:e})}async setBadgeCount(e){return Y(`plugin:window|set_badge_count`,{label:this.label,value:e})}async setBadgeLabel(e){return Y(`plugin:window|set_badge_label`,{label:this.label,value:e})}async setOverlayIcon(e){return Y(`plugin:window|set_overlay_icon`,{label:this.label,value:e?Ea(e):void 0})}async setProgressBar(e){return Y(`plugin:window|set_progress_bar`,{label:this.label,value:e})}async setVisibleOnAllWorkspaces(e){return Y(`plugin:window|set_visible_on_all_workspaces`,{label:this.label,value:e})}async setTitleBarStyle(e){return Y(`plugin:window|set_title_bar_style`,{label:this.label,value:e})}async setTheme(e){return Y(`plugin:window|set_theme`,{label:this.label,value:e})}async onResized(e){return this.listen(Pr.WINDOW_RESIZED,t=>{t.payload=new lP(t.payload),e(t)})}async onMoved(e){return this.listen(Pr.WINDOW_MOVED,t=>{t.payload=new fP(t.payload),e(t)})}async onCloseRequested(e){return this.listen(Pr.WINDOW_CLOSE_REQUESTED,async t=>{let n=new hP(t);await e(n),n.isPreventDefault()||await this.destroy()})}async onDragDropEvent(e){let t=await this.listen(Pr.DRAG_ENTER,t=>{e({...t,payload:{type:`enter`,paths:t.payload.paths,position:new fP(t.payload.position)}})}),n=await this.listen(Pr.DRAG_OVER,t=>{e({...t,payload:{type:`over`,position:new fP(t.payload.position)}})}),r=await this.listen(Pr.DRAG_DROP,t=>{e({...t,payload:{type:`drop`,paths:t.payload.paths,position:new fP(t.payload.position)}})}),i=await this.listen(Pr.DRAG_LEAVE,t=>{e({...t,payload:{type:`leave`}})});return()=>{t(),r(),n(),i()}}async onFocusChanged(e){let t=await this.listen(Pr.WINDOW_FOCUS,t=>{e({...t,payload:!0})}),n=await this.listen(Pr.WINDOW_BLUR,t=>{e({...t,payload:!1})});return()=>{t(),n()}}async onScaleChanged(e){return this.listen(Pr.WINDOW_SCALE_FACTOR_CHANGED,e)}async onThemeChanged(e){return this.listen(Pr.WINDOW_THEME_CHANGED,e)}},xP;(function(e){e.Disabled=`disabled`,e.Throttle=`throttle`,e.Suspend=`suspend`})(xP||={});var SP;(function(e){e.Default=`default`,e.FluentOverlay=`fluentOverlay`})(SP||={});var CP;(function(e){e.AppearanceBased=`appearanceBased`,e.Light=`light`,e.Dark=`dark`,e.MediumLight=`mediumLight`,e.UltraDark=`ultraDark`,e.Titlebar=`titlebar`,e.Selection=`selection`,e.Menu=`menu`,e.Popover=`popover`,e.Sidebar=`sidebar`,e.HeaderView=`headerView`,e.Sheet=`sheet`,e.WindowBackground=`windowBackground`,e.HudWindow=`hudWindow`,e.FullScreenUI=`fullScreenUI`,e.Tooltip=`tooltip`,e.ContentBackground=`contentBackground`,e.UnderWindowBackground=`underWindowBackground`,e.UnderPageBackground=`underPageBackground`,e.Mica=`mica`,e.Blur=`blur`,e.Acrylic=`acrylic`,e.Tabbed=`tabbed`,e.TabbedDark=`tabbedDark`,e.TabbedLight=`tabbedLight`})(CP||={});var wP;(function(e){e.FollowsWindowActiveState=`followsWindowActiveState`,e.Active=`active`,e.Inactive=`inactive`})(wP||={});var TP=12e-5,EP=36,DP=140,OP=1.5,kP=6;function AP(e,t){return{x:Math.random()*e,y:Math.random()*t,radius:.35+Math.random()*1.25,alpha:.22+Math.random()*.5,drift:OP+Math.random()*(kP-OP)}}function jP(e){let t=e.getBoundingClientRect(),n=t.width||e.parentElement?.clientWidth||window.innerWidth,r=t.height||e.parentElement?.clientHeight||window.innerHeight;return{width:Math.max(1,Math.floor(n)),height:Math.max(1,Math.floor(r))}}function MP(){let e=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(typeof window>`u`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return;let t=e.current;if(!t)return;let n=t.getContext(`2d`,{alpha:!0});if(!n)return;let r=t,i=n,a=[],o=0,s=0,c=0,l=0,u=0,d=!document.hidden;function f(){let e=jP(r),t=window.devicePixelRatio||1;if(e.width===o&&e.height===s&&t===c)return;let n=e.width!==o||e.height!==s;if(o=e.width,s=e.height,c=t,r.width=Math.max(1,Math.round(o*t)),r.height=Math.max(1,Math.round(s*t)),r.style.width=`100%`,r.style.height=`100%`,i.setTransform(t,0,0,t,0,0),n||a.length===0){let e=Math.min(DP,Math.max(EP,Math.floor(o*s*TP)));a=Array.from({length:e},()=>AP(o,s))}}function p(e){i.clearRect(0,0,o,s);for(let t of a)t.x+=t.drift*e,t.x>o+t.radius&&(t.x=-t.radius,t.y=Math.random()*s),i.globalAlpha=t.alpha,i.fillStyle=`hsl(213 100% 92%)`,i.beginPath(),i.arc(t.x,t.y,t.radius,0,Math.PI*2),i.fill();i.globalAlpha=1}function m(e){if(!d)return;let t=u===0?.016:Math.min(.05,(e-u)/1e3);u=e,p(t),l=requestAnimationFrame(m)}function h(){d=!document.hidden,d?(u=0,l=requestAnimationFrame(m)):cancelAnimationFrame(l)}let g=null;function _(){g&&g.removeEventListener(`change`,_),f(),v()}function v(){let e=window.devicePixelRatio||1;g=window.matchMedia(`(resolution: ${e}dppx)`),g.addEventListener(`change`,_)}f();let y=null,b=r.parentElement;return typeof ResizeObserver<`u`&&b&&(y=new ResizeObserver(()=>f()),y.observe(b)),window.addEventListener(`resize`,f),v(),document.addEventListener(`visibilitychange`,h),d&&(l=requestAnimationFrame(m)),()=>{cancelAnimationFrame(l),y&&y.disconnect(),g&&g.removeEventListener(`change`,_),window.removeEventListener(`resize`,f),document.removeEventListener(`visibilitychange`,h)}},[]),(0,$.jsx)(`canvas`,{ref:e,"aria-hidden":!0,className:`absolute inset-0 pointer-events-none`,style:{zIndex:-1}})}var NP=(0,Q.lazy)(()=>c(()=>import(`./AgentModeCodePane-zPWbW7ei.js`).then(e=>({default:e.AgentModeCodePane})),__vite__mapDeps([83,1,7,10,43,51]))),PP=(0,Q.lazy)(()=>c(()=>import(`./AgentModeJobsPane-CInByIdl.js`).then(e=>({default:e.AgentModeJobsPane})),__vite__mapDeps([84,1,7,12,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,45,8,58,51,68,69,71,72,76,80,6,9,11,44,46,47,48,49,50,52,53,54,55,56,57,59,60,61,62,63,64,65,66,67,70,73,74,75,77,78,79,85]))),FP=(0,Q.lazy)(()=>c(()=>import(`./AgentModeAnalyticsPane-CQuxYh8B.js`).then(e=>({default:e.AgentModeAnalyticsPane})),__vite__mapDeps([86,1,7,10,43,58,51,68,69])));function IP(){let{t:e}=K(`agent`),{active:t,refreshConversations:n,builderMode:r}=aP(),{codePaneOpen:i,jobsPaneOpen:a,analyticsPaneOpen:o}=lO(),{activeProjectId:s}=pt(),c=Ci(),l=Wy(t?.id??`__new-mission__`),u=!c.current&&c.transfers.some(e=>e.conversationId===t?.id&&e.state===`detached`),d=wa(),f=d.id===`galaxy`,p=d.id===`code-rain`?e(`emptyTitleCodeRain`):e(`emptyTitle`);(0,Q.useEffect)(()=>{n()},[n]);let m=i&&!!s&&!u,h=a&&!!s&&!u,g=o&&!!s&&!u;return(0,$.jsx)(J_,{reducedMotion:`user`,children:(0,$.jsxs)(`div`,{"data-agent-mode-surface":!0,className:`relative z-0 flex h-full w-full overflow-hidden bg-background`,children:[f&&(0,$.jsx)(MP,{}),(0,$.jsxs)(`div`,{className:`relative flex h-full min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,$.jsx)(Ny.div,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 z-0`,animate:{opacity:+(t===null)},transition:{duration:.5,ease:`easeOut`},style:{background:`radial-gradient(60% 55% at 50% 45%, color-mix(in srgb, var(--color-accent-primary) 13%, transparent), transparent 70%)`}}),r.active?(0,$.jsx)(`div`,{className:`relative z-10 flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,$.jsx)(lN,{variant:`inline`})}):t===null?(0,$.jsx)(`div`,{className:`relative z-10 flex h-full w-full items-center justify-center px-6`,children:(0,$.jsxs)(Ny.div,{layoutId:`agent-composer-dock`,initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.28,ease:[.34,1.56,.64,1],layout:{type:`spring`,stiffness:350,damping:34}},className:`w-full max-w-[680px] rounded-2xl border border-border/60 bg-card/90 p-4 shadow-2xl backdrop-blur-xl`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 px-1`,children:[(0,$.jsx)(Vo,{className:`h-4 w-4 text-accent-primary`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground/80`,children:p})]}),(0,$.jsx)(MA,{autoFocus:!0})]})}):(0,$.jsx)(`div`,{className:`relative z-10 flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,$.jsx)(Hj,{variant:`inline`})})]}),h&&(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`w-[480px] border-l border-border`}),children:(0,$.jsx)(PP,{projectId:s})}),m&&(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`w-[520px] border-l border-border`}),children:(0,$.jsx)(NP,{projectId:s,conversationId:t?.id??`__home__`},`${t?.id}:${l}`)}),g&&(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`w-[560px] border-l border-border`}),children:(0,$.jsx)(FP,{})})]})})}var LP=(e,t,n)=>Math.min(n,Math.max(t,e)),RP=e=>`specrails-desktop:sidebar-width:${e}`;function zP(e,t){let n=RP(e),[r,i]=(0,Q.useState)(()=>{try{let e=localStorage.getItem(n),r=e?Number.parseInt(e,10):NaN;if(Number.isFinite(r))return LP(r,t.min,t.max)}catch{}return t.defaultWidth}),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null),c=(0,Q.useRef)(r);c.current=r;let l=(0,Q.useRef)(!1),u=(0,Q.useRef)(t);return u.current=t,(0,Q.useLayoutEffect)(()=>{let e=s.current;!e||l.current||(e.style.width=`${t.expanded?r:t.collapsedWidth}px`)},[r,t.expanded,t.collapsedWidth]),{width:r,dragging:a,panelRef:s,onGripPointerDown:(0,Q.useCallback)(e=>{if(e.button!==0||!u.current.expanded)return;e.preventDefault();let t=s.current;if(!t)return;let r=e.clientX,a=c.current,d=a;l.current=!0,o(!0),t.style.transition=`none`;let f=document.body.style.cursor,p=document.body.style.userSelect;document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`;try{e.target.setPointerCapture?.(e.pointerId)}catch{}let m=e=>{let n=u.current,i=e.clientX-r,o=n.side===`left`?i:-i;d=LP(a+o,n.min,n.max),t.style.width=`${d}px`},h=()=>{window.removeEventListener(`pointermove`,m),window.removeEventListener(`pointerup`,h),window.removeEventListener(`pointercancel`,h),t.style.transition=``,document.body.style.cursor=f,document.body.style.userSelect=p,l.current=!1,o(!1),i(d);try{localStorage.setItem(n,String(Math.round(d)))}catch{}};window.addEventListener(`pointermove`,m),window.addEventListener(`pointerup`,h),window.addEventListener(`pointercancel`,h)},[n]),onGripKeyDown:(0,Q.useCallback)(e=>{let t=u.current,r=e.shiftKey?24:8,a=t.side===`left`?`ArrowRight`:`ArrowLeft`,o=t.side===`left`?`ArrowLeft`:`ArrowRight`,s=null;if(e.key===a?s=LP(c.current+r,t.min,t.max):e.key===o?s=LP(c.current-r,t.min,t.max):e.key===`Home`&&(s=t.defaultWidth),s!==null){e.preventDefault(),i(s);try{localStorage.setItem(n,String(Math.round(s)))}catch{}}},[n])}}function BP({side:e,dragging:t,width:n,min:r,max:i,label:a,onPointerDown:o,onKeyDown:s}){return(0,$.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":a,"aria-valuenow":Math.round(n),"aria-valuemin":r,"aria-valuemax":i,tabIndex:0,"data-testid":`sidebar-resize-grip-${e}`,onPointerDown:o,onKeyDown:s,className:X(`group absolute inset-y-0 z-20 w-1.5 cursor-col-resize outline-none`,e===`left`?`-right-0.5`:`-left-0.5`),children:(0,$.jsx)(`div`,{className:X(`absolute inset-y-0 w-px transition-colors duration-150`,e===`left`?`right-0`:`left-0`,t?`bg-accent-primary`:`bg-transparent group-hover:bg-accent-primary/50 group-focus-visible:bg-accent-primary/70`)})})}var VP=[`pinned-open`,`pinned-collapsed`,`unpinned`],HP=`specrails-desktop:sidebar-mode:left`,UP=`specrails-desktop:sidebar-mode:right`;function WP(e){return typeof e==`string`&&VP.includes(e)}function GP(e){try{let t=window.localStorage.getItem(e);if(WP(t))return t}catch{}return`unpinned`}function KP(e,t){try{window.localStorage.setItem(e,t)}catch{}}function qP(e){switch(e){case`pinned-open`:return`pinned-collapsed`;case`pinned-collapsed`:return`unpinned`;case`unpinned`:return`pinned-open`}}var JP=(0,Q.createContext)({leftMode:`unpinned`,rightMode:`unpinned`,setLeftMode:()=>{},setRightMode:()=>{},cycleLeftMode:()=>{},cycleRightMode:()=>{}});function YP({children:e}){let[t,n]=(0,Q.useState)(()=>GP(HP)),[r,i]=(0,Q.useState)(()=>GP(UP));(0,Q.useEffect)(()=>{KP(HP,t)},[t]),(0,Q.useEffect)(()=>{KP(UP,r)},[r]);let a=(0,Q.useCallback)(e=>n(e),[]),o=(0,Q.useCallback)(e=>i(e),[]),s=(0,Q.useCallback)(()=>n(e=>qP(e)),[]),c=(0,Q.useCallback)(()=>i(e=>qP(e)),[]),l=(0,Q.useMemo)(()=>({leftMode:t,rightMode:r,setLeftMode:a,setRightMode:o,cycleLeftMode:s,cycleRightMode:c}),[t,r,a,o,s,c]);return(0,$.jsx)(JP.Provider,{value:l,children:e})}function XP(){return(0,Q.useContext)(JP)}function ZP({open:e,onClose:t,onCommitted:n,projectId:r,milestoneId:i,blueprint:a,provider:o=`claude`}){let{t:s}=K(`builder`),{registerHandler:c,unregisterHandler:l}=tt(),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(``),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)({status:`idle`}),O=(0,Q.useRef)(null),k=(0,Q.useRef)(r),A=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{O.current=u},[u]),(0,Q.useEffect)(()=>{k.current=r},[r]);let j=a.milestones.find(e=>e.id===i),M=i.toUpperCase(),N=Ct(o,`read-only`),P=(0,Q.useMemo)(()=>IM(v??g,{milestoneLabel:M,minSpecs:1,maxSpecs:10,requireScaffold:!1}),[g,v,M]),F=(0,Q.useMemo)(()=>RM(g,v??g,P,{minSpecs:1,maxSpecs:10}),[g,v,P]),I=(0,Q.useMemo)(()=>on(m),[m]);(0,Q.useEffect)(()=>{if(!e||u||!N)return;let t=!1;return fetch(`${ut()}/chat/conversations`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:`milestone`,milestone:i})}).then(e=>e.json()).then(e=>{if(t||!e.conversation)return;O.current=e.conversation.id,d(e.conversation.id);let n=j?.plannedSpecs??[],r={label:M,title:j?.title??M,planned:n.join(`; `)},i=n.length>0?s(`prompts.milestoneSeedWithPlanned`,r):s(`prompts.milestoneSeed`,r);p([{role:`user`,content:i}]),C(!0),fetch(`${ut()}/chat/conversations/${e.conversation.id}/messages`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:i})}).catch(()=>{C(!1),J.error(s(`errors.turnFailed`))})}).catch(()=>{t||J.error(s(`errors.startFailed`))}),()=>{t=!0}},[e,u,i,j,M,N,s]),(0,Q.useEffect)(()=>{if(!e)return;let t=`milestone-generate-${i}`;return c(t,e=>{let t=e;if(t.conversationId===O.current&&!(t.projectId&&t.projectId!==k.current))if(t.type===`chat_stream`)h(e=>(e??``)+String(t.delta??``));else if(t.type===`chat_done`){h(null),C(!1);let e=String(t.fullText??``),n=ln(e),r=n.stripped.trim()||(n.hadBlocks?``:e);if(r&&p(e=>[...e,{role:`assistant`,content:r}]),n.blueprint)_(n.blueprint),y(n.rawBlueprint),D({status:`accepted`,repaired:n.repaired,repairAttempted:!1,at:new Date().toISOString()});else if(n.rejected.length>0){let e=n.rejected[n.rejected.length-1];D({status:`rejected`,reason:e.reason,detail:e.detail,repairAttempted:!1,at:new Date().toISOString()})}}else t.type===`chat_error`&&(h(null),C(!1),J.error(s(`errors.turnFailed`),{description:String(t.error??``)}))}),()=>l(t)},[e,i,c,l,s]),(0,Q.useEffect)(()=>{A.current?.scrollTo?.({top:A.current.scrollHeight})},[f,m]);let L=(0,Q.useCallback)(e=>{let t=O.current,n=e.trim();!t||!n||S||(p(e=>[...e,{role:`user`,content:n}]),x(``),C(!0),fetch(`${ut()}/chat/conversations/${t}/messages`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:n})}).catch(()=>{C(!1),J.error(s(`errors.turnFailed`))}))},[S,s]),R=(0,Q.useCallback)(()=>{let e=E.status===`rejected`?s(`snapshot.rejected.${E.reason}`):s(`readiness.issuesCount`,{count:F.issues.length});L(s(`prompts.repairSnapshot`,{reason:e}))},[E,F.issues.length,L,s]),z=(0,Q.useCallback)(()=>{let e=v??g,r=e&&typeof e==`object`&&!Array.isArray(e)?e:null,a=Array.isArray(r?.m1Specs)?r.m1Specs:[];!P.valid||w||(T(!0),fetch(`${ut()}/blueprint/commit-milestone`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({milestoneId:i,specsComplete:r?.specsComplete,specs:a})}).then(async e=>{if(e.status===201){let r=await e.json();J.success(s(`milestone.commitToast`,{count:r.insertedIds.length,label:M})),n?.(),t()}else{let t=await e.json().catch(()=>({}));J.error(s(`milestone.commitFailed`),{description:t.detail??t.error})}}).catch(()=>J.error(s(`milestone.commitFailed`))).finally(()=>T(!1)))},[g,v,P.valid,w,i,M,t,n,s]);if(!e)return null;let B=g?.m1Specs.length??0;return N?(0,$.jsxs)(`div`,{className:`fixed inset-0 z-50 flex flex-col bg-background/95 backdrop-blur-sm`,"data-testid":`milestone-shell`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-border/40 px-4 py-2.5`,children:[(0,$.jsx)(Ns,{className:`h-4 w-4 text-accent-primary`}),(0,$.jsx)(`h1`,{className:`text-sm font-semibold`,children:s(`milestone.title`,{label:M})}),j&&(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:j.title}),(0,$.jsx)(`button`,{type:`button`,onClick:t,className:`ml-auto rounded-md p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":s(`shell.close`),"data-testid":`milestone-close`,children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col border-r border-border/40`,children:[(0,$.jsxs)(`div`,{ref:A,className:`min-h-0 flex-1 space-y-3 overflow-y-auto p-4`,children:[f.map((e,t)=>(0,$.jsx)(`div`,{className:X(`max-w-[85%] whitespace-pre-wrap rounded-lg px-3 py-2 text-xs leading-relaxed`,e.role===`user`?`ml-auto bg-accent-primary/15`:`bg-surface/70`),children:e.content},t)),m!==null&&(0,$.jsxs)(`div`,{className:`max-w-[85%] whitespace-pre-wrap rounded-lg bg-surface/70 px-3 py-2 text-xs leading-relaxed`,children:[Kt(m),(0,$.jsx)(`span`,{className:`ml-0.5 inline-block h-3 w-1.5 animate-pulse bg-accent-primary/70 align-middle`})]}),I.generating&&(0,$.jsx)(uM,{specsStarted:I.specsStarted,snapshot:E})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2 border-t border-border/40 p-3`,children:[(0,$.jsx)(`textarea`,{value:b,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),L(b))},rows:2,placeholder:s(`milestone.inputPlaceholder`),className:`min-h-[2.5rem] flex-1 resize-none rounded-md border border-border/40 bg-surface/50 px-3 py-2 text-xs focus:outline-none focus-visible:ring-1 focus-visible:ring-ring`}),(0,$.jsx)(Z,{size:`sm`,onClick:()=>L(b),disabled:S||!b.trim()||!u,children:S?(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(bc,{className:`h-3.5 w-3.5`})})]})]}),(0,$.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col lg:w-96`,children:[(0,$.jsx)(mN,{blueprint:g,milestoneLabel:M,snapshot:E}),(0,$.jsx)(_N,{readiness:F,snapshot:E,busy:S||w,primaryLabel:w?s(`commit.creating`):s(`milestone.commit`,{count:B,label:M}),onPrimary:z,onRepair:R,primaryTestId:`milestone-commit`})]})]})]}):(0,$.jsxs)(`div`,{className:`fixed inset-0 z-50 flex flex-col bg-background/95 backdrop-blur-sm`,"data-testid":`milestone-shell`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-border/40 px-4 py-2.5`,children:[(0,$.jsx)(Ns,{className:`h-4 w-4 text-accent-primary`}),(0,$.jsx)(`h1`,{className:`text-sm font-semibold`,children:s(`milestone.title`,{label:M})}),(0,$.jsx)(`button`,{type:`button`,onClick:t,className:`ml-auto rounded-md p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":s(`shell.close`),"data-testid":`milestone-close`,children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})]}),(0,$.jsx)(`p`,{className:`m-4 rounded-md border border-accent-warning/30 bg-accent-warning/10 p-3 text-sm text-accent-warning`,"data-testid":`milestone-provider-unavailable`,children:s(`milestone.providerUnavailable`)})]})}function QP({expanded:e}){let{t}=K(`builder`),n=y(),{activeProjectId:r,projects:i}=pt(),{blueprint:a,progress:o,hasBlueprint:s,refresh:c}=Qt(r),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(()=>pM()),[_,v]=(0,Q.useState)(()=>gM()),[b,x]=(0,Q.useState)(null),S=(0,Q.useRef)(null),C=(0,Q.useRef)(null),[w,T]=(0,Q.useState)(null);(0,Q.useLayoutEffect)(()=>{if(!l){T(null);return}let e=()=>{let e=S.current?.getBoundingClientRect();if(!e)return;let t=Math.max(8,e.left-320-8),n=Math.min(Math.max(8,e.top),Math.max(8,window.innerHeight-240));T({top:n,left:t})};return e(),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[l]),(0,Q.useEffect)(()=>{if(!l)return;let e=e=>{let t=e.target;S.current?.contains(t)||C.current?.contains(t)||u(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]);let E=(0,Q.useCallback)(async()=>{if(!(!r||d)){f(!0);try{let e=await SM(r,1,h,{autoAdvance:_}),n=yM(1);if(e.ok){let r=e.launched.length+e.pending.length;h===`sequential`&&e.pending.length>0?J.success(t(_?`milestoneProgress.toast.launched`:`milestoneProgress.toast.launchedCheckpoint`,{milestone:n,count:e.ticketCount,n:r})):e.skippedCount>0?J.warning(t(`milestoneProgress.toast.launchedPartial`,{milestone:n,count:e.ticketCount,skipped:e.skippedCount})):J.success(t(`milestoneProgress.toast.launchedAll`,{milestone:n,count:e.ticketCount,n:r})),u(!1)}else e.reason===`chain_active`?J.info(t(`milestoneProgress.toast.chainActive`,{milestone:n})):J.error(t(`done.launchFailed`),{description:e.detail??e.error})}finally{f(!1)}}},[r,_,d,h,t]),D=(0,Q.useCallback)(async(e,n)=>{if(!(!r||p)){m(!0);try{let i=await EM(r,e,n);i.ok?(v(n),_M(n),J.success(t(n?`milestoneProgress.chain.autoOn`:`milestoneProgress.chain.autoOff`))):J.error(t(`milestoneProgress.chain.autoFailed`),{description:i.detail??i.error})}finally{m(!1)}}},[r,p,t]),O=(0,Q.useCallback)(async e=>{if(!(!r||p)){m(!0);try{let n=await wM(r,e);n.ok?J.success(t(`milestoneProgress.chain.resumed`)):J.error(t(`milestoneProgress.chain.resumeFailed`),{description:n.detail??n.error})}finally{m(!1)}}},[r,p,t]),k=(0,Q.useCallback)(async e=>{if(!(!r||p)){m(!0);try{let n=await TM(r,e);n.ok?J.success(t(`milestoneProgress.chain.cancelledToast`)):J.error(n.detail??n.error)}finally{m(!1)}}},[r,p,t]),A=(0,Q.useCallback)(e=>{u(!1),n(le?`/review/${e}`:`/`)},[n]),j=(0,Q.useCallback)(()=>{u(!1),n(`/`)},[n]);if(!r||s===!1||!a)return null;let M=o.find(e=>e.n===1)??null,N=M!==null&&Wt(M),P=o.find(e=>e.state===`planned`&&e.n>1)??null,F=i.find(e=>e.id===r),I=F?.provider??F?.providers?.[0]??`claude`,L=Ct(I,`read-only`),R=N?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`flex rounded-md border border-border/40 p-0.5 text-[10px]`,role:`radiogroup`,"aria-label":t(`sequential.modeLabel`),title:t(h===`sequential`?`milestoneProgress.sequentialHint`:`milestoneProgress.parallelHint`),"data-testid":`milestone-launch-mode`,children:[`sequential`,`parallel`].map(e=>(0,$.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":h===e,onClick:()=>{g(e),mM(e)},className:X(`flex-1 rounded px-1.5 py-1 font-medium transition-colors`,h===e?`bg-accent-primary/15 text-accent-primary`:`text-muted-foreground hover:text-foreground`),children:t(`sequential.mode.${e}`)},e))}),h===`sequential`&&(0,$.jsx)(tN,{checked:_,onChange:e=>{v(e),_M(e)},testId:`sidebar-auto-advance`}),(0,$.jsxs)(`button`,{type:`button`,onClick:E,disabled:d,className:`inline-flex items-center justify-center gap-1.5 rounded-md bg-accent-primary/15 px-2 py-1.5 text-[11px] font-medium text-accent-primary transition-colors hover:bg-accent-primary/25 disabled:opacity-50`,"data-testid":`sidebar-launch-m1`,children:[d?(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`}):(0,$.jsx)(gc,{className:`h-3 w-3`}),t(`sidebar.launchM1`)]})]}):null;return(0,$.jsxs)(`div`,{ref:S,className:`relative`,"data-testid":`builder-sidebar-entry`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(e=>!e),className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,e?`px-2`:`px-0 justify-center`,l?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),title:e?void 0:t(`sidebar.title`),"data-testid":`builder-sidebar-toggle`,children:[(0,$.jsx)(Ns,{className:`w-4 h-4 flex-shrink-0`}),e&&(0,$.jsx)(`span`,{className:`text-xs truncate`,children:t(`sidebar.title`)})]}),l&&w&&(0,Hb.createPortal)((0,$.jsxs)(`div`,{ref:C,className:`fixed z-[72] w-80 max-h-[80vh] overflow-y-auto rounded-lg border border-border/50 bg-background p-3 shadow-xl`,style:{top:w.top,left:w.left},"data-testid":`builder-sidebar-panel`,children:[(0,$.jsx)(`h4`,{className:`text-xs font-semibold`,children:t(`sidebar.title`)}),(0,$.jsx)(`div`,{className:`mt-2 space-y-1.5`,children:o.map(e=>(0,$.jsx)(rN,{progress:e,actions:e.n===1?R:void 0,chainBusy:p,onReview:A,onOpenRail:j,onResume:O,onCancel:k,onSetAutoAdvance:D},e.id||e.n))}),P&&(0,$.jsx)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{L&&(x(P.id),u(!1))},disabled:!L,className:`inline-flex items-center justify-center gap-1.5 rounded-md border border-accent-highlight/40 px-2 py-1.5 text-[11px] font-medium text-accent-highlight transition-colors hover:bg-accent-highlight/10`,title:t(L?`sidebar.generateHint`:`sidebar.generateUnavailable`),"data-testid":`sidebar-generate-next`,children:[(0,$.jsx)(Ln,{className:`h-3 w-3`}),t(`sidebar.generateNext`,{n:P.n})]})})]}),document.body),b&&(0,$.jsx)(ZP,{open:!0,onClose:()=>x(null),onCommitted:()=>{c()},projectId:r,milestoneId:b,blueprint:a,provider:I})]})}var $P={"pinned-open":`sidebarPin.right.pinnedOpen`,"pinned-collapsed":`sidebarPin.right.pinnedCollapsed`,unpinned:`sidebarPin.right.unpinned`};function eF({missionOnly:e=!1}={}){let{t}=K(`agent`),{t:n}=K(`nav`),{t:r}=K(`builder`),{rightMode:i,cycleRightMode:a}=XP(),{activeProjectId:o}=pt(),s=za(),c=lO(),{builderMode:l}=aP(),[u,d]=(0,Q.useState)(!1),f=l.active||i===`pinned-open`||i===`unpinned`&&u,p=zP(`right-workspace`,{side:`right`,defaultWidth:208,min:180,max:460,collapsedWidth:44,expanded:f}),m=i!==`unpinned`,h=n($P[i]),g=!o,_=[{key:`jobs`,icon:Go,label:t(`workspace.jobs`),onClick:()=>c.toggleJobsPane(),disabled:g,disabledTitle:t(`workspace.requiresProject`)},{key:`analytics`,icon:Ko,label:t(`workspace.analytics`),onClick:()=>c.toggleAnalyticsPane(),disabled:g,disabledTitle:t(`workspace.requiresProject`)},...Ie()?[{key:`browser`,icon:D,label:t(`workspace.browser`),onClick:()=>c.openBrowser(),disabled:g,disabledTitle:t(`workspace.requiresProject`)}]:[],...Te?[{key:`terminal`,icon:Ec,label:t(`workspace.terminal`),onClick:()=>o&&s.togglePanel(o),disabled:g,disabledTitle:t(`workspace.requiresProject`)}]:[],...me?[{key:`files`,icon:ys,label:t(`workspace.files`),onClick:()=>c.toggleCodePane(),disabled:g,disabledTitle:t(`workspace.requiresProject`)}]:[]];return(0,$.jsxs)(`div`,{ref:p.panelRef,className:X(`relative flex flex-col h-full border-l border-border bg-background flex-shrink-0 overflow-hidden`,`transition-[width] duration-200 ease-in-out`),onMouseEnter:()=>{i===`unpinned`&&d(!0)},onMouseLeave:()=>{i===`unpinned`&&!p.dragging&&d(!1)},children:[f&&(0,$.jsx)(BP,{side:`right`,dragging:p.dragging,width:p.width,min:180,max:460,label:n(`sidebarPin.resize`,{defaultValue:`Resize sidebar`}),onPointerDown:p.onGripPointerDown,onKeyDown:p.onGripKeyDown}),(0,$.jsxs)(`div`,{className:X(`flex items-center h-12 border-b border-border flex-shrink-0`,f?`px-3 justify-between`:`justify-center`),children:[f&&(0,$.jsx)(`span`,{className:`font-mono text-sm font-bold whitespace-nowrap overflow-hidden text-accent-secondary`,children:t(`workspace.title`)}),(0,$.jsx)(`button`,{type:`button`,onClick:a,className:X(`flex items-center justify-center w-7 h-7 rounded-md transition-colors`,m?`text-foreground bg-muted`:`text-muted-foreground/40 hover:text-muted-foreground hover:bg-muted/50`),"aria-label":h,title:n(`sidebarPin.withShortcut`,{label:h,shortcut:`⌘B`}),children:(0,$.jsx)(nc,{className:`w-4 h-4`})})]}),l.active?(0,$.jsx)(N_,{mode:`wait`,initial:!1,children:(0,$.jsxs)(Ny.div,{initial:{opacity:0,x:24},animate:{opacity:1,x:0},exit:{opacity:0,x:24},transition:{duration:.22,ease:`easeOut`},className:`flex min-h-0 flex-1 flex-col`,"data-testid":`workspace-blueprint-panel`,children:[(0,$.jsx)(mN,{blueprint:l.session.blueprint,snapshot:l.session.snapshot}),l.session.phase===`chat`&&(0,$.jsx)(_N,{readiness:l.session.readiness,snapshot:l.session.snapshot,busy:l.session.busy,primaryLabel:r(`shell.createSpecs`),onPrimary:l.session.goToCommit,onRepair:()=>void l.session.repairSnapshot()})]},`builder-blueprint`)}):(0,$.jsxs)(`nav`,{className:`flex-1 py-2 px-1.5 space-y-0.5`,children:[!e&&(0,$.jsx)(QP,{expanded:f}),_.map(({key:e,icon:t,label:n,onClick:r,disabled:i,disabledTitle:a})=>(0,$.jsxs)(`button`,{type:`button`,onClick:r,disabled:i,className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,f?`px-2`:`px-0 justify-center`,i?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),title:i?a:f?void 0:n,children:[(0,$.jsx)(t,{className:`w-4 h-4 flex-shrink-0`}),f&&(0,$.jsx)(`span`,{className:`text-xs truncate`,children:n})]},e))]})]})}var tF=`specrails:terminal-settings-updated`;function nF(e){typeof window>`u`||window.dispatchEvent(new CustomEvent(tF,{detail:e}))}function rF(){return new oF(_P(),window.__TAURI_INTERNALS__.metadata.currentWebview.label,{skip:!0})}async function iF(){return Y(`plugin:webview|get_all_webviews`).then(e=>e.map(e=>new oF(new bP(e.windowLabel,{skip:!0}),e.label,{skip:!0})))}var aF=[`tauri://created`,`tauri://error`],oF=class{constructor(e,t,n){this.window=e,this.label=t,this.listeners=Object.create(null),n?.skip||Y(`plugin:webview|create_webview`,{windowLabel:e.label,options:{...n,label:t}}).then(async()=>this.emit(`tauri://created`)).catch(async e=>this.emit(`tauri://error`,e))}static async getByLabel(e){return(await iF()).find(t=>t.label===e)??null}static getCurrent(){return rF()}static async getAll(){return iF()}async listen(e,t){return this._handleTauriEvent(e,t)?()=>{let n=this.listeners[e];n.splice(n.indexOf(t),1)}:Ar(e,t,{target:{kind:`Webview`,label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?()=>{let n=this.listeners[e];n.splice(n.indexOf(t),1)}:Mr(e,t,{target:{kind:`Webview`,label:this.label}})}async emit(e,t){if(aF.includes(e)){for(let n of this.listeners[e]||[])n({event:e,id:-1,payload:t});return}return jr(e,t)}async emitTo(e,t,n){if(aF.includes(t)){for(let e of this.listeners[t]||[])e({event:t,id:-1,payload:n});return}return Nr(e,t,n)}_handleTauriEvent(e,t){return aF.includes(e)?(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0):!1}async position(){return Y(`plugin:webview|webview_position`,{label:this.label}).then(e=>new fP(e))}async size(){return Y(`plugin:webview|webview_size`,{label:this.label}).then(e=>new lP(e))}async close(){return Y(`plugin:webview|webview_close`,{label:this.label})}async setSize(e){return Y(`plugin:webview|set_webview_size`,{label:this.label,value:e instanceof uP?e:new uP(e)})}async setPosition(e){return Y(`plugin:webview|set_webview_position`,{label:this.label,value:e instanceof pP?e:new pP(e)})}async setFocus(){return Y(`plugin:webview|set_webview_focus`,{label:this.label})}async setAutoResize(e){return Y(`plugin:webview|set_webview_auto_resize`,{label:this.label,value:e})}async hide(){return Y(`plugin:webview|webview_hide`,{label:this.label})}async show(){return Y(`plugin:webview|webview_show`,{label:this.label})}async setZoom(e){return Y(`plugin:webview|set_webview_zoom`,{label:this.label,value:e})}async reparent(e){return Y(`plugin:webview|reparent`,{label:this.label,window:typeof e==`string`?e:e.label})}async clearAllBrowsingData(){return Y(`plugin:webview|clear_all_browsing_data`)}async setBackgroundColor(e){return Y(`plugin:webview|set_webview_background_color`,{color:e})}async onDragDropEvent(e){let t=await this.listen(Pr.DRAG_ENTER,t=>{e({...t,payload:{type:`enter`,paths:t.payload.paths,position:new fP(t.payload.position)}})}),n=await this.listen(Pr.DRAG_OVER,t=>{e({...t,payload:{type:`over`,position:new fP(t.payload.position)}})}),r=await this.listen(Pr.DRAG_DROP,t=>{e({...t,payload:{type:`drop`,paths:t.payload.paths,position:new fP(t.payload.position)}})}),i=await this.listen(Pr.DRAG_LEAVE,t=>{e({...t,payload:{type:`leave`}})});return()=>{t(),r(),n(),i()}}};function sF(e){return`'${e.replace(/'/g,`'\\''`)}'`}function cF(e){if(/[\x00-\x1f"%!]/.test(e))throw Error(`unsafe-cmd-path`);return`"`+e+`"`}function lF(e){return`'${e.replace(/'/g,`''`)}'`}function uF(e,t,n=`powershell`){return t?n===`cmd`?cF(e):lF(e):sF(e)}function dF(e,t,n=`powershell`){return e.map(e=>uF(e,t,n)).join(` `)}function fF(e){return/(?:^|[\\/])cmd(?:\.exe)?$/i.test(e??``)?`cmd`:`powershell`}async function pF(e){if(!de())return{dispose:()=>{}};let t=[];try{let n=``,r=0,i=typeof navigator<`u`&&/Win/i.test(navigator.platform||``),a=t=>{let a=t.payload;if(!a||a.type!==`drop`)return;let o=a.paths;if(!o||o.length===0)return;let s=a.position;if(!s)return;let c=`${o.join(`\0`)}@${s.x},${s.y}`,l=Date.now();if(c===n&&l-r<250)return;n=c,r=l;let u=e();if(u&&hF(s,u.viewportEl.getBoundingClientRect(),window.devicePixelRatio||1))try{u.writeText(dF(o,i,fF(u.shell)))}catch{J.error(Je.t(`terminal:errors.pathPasteUnsafe`))}},o=mF((()=>{try{return rF()}catch{return null}})());o&&t.push(await o(a));let s=mF((()=>{try{return _P()}catch{return null}})());return s&&t.push(await s(a)),t.length===0?{dispose:()=>{}}:{dispose:()=>{for(let e of t)try{e()}catch{}}}}catch{for(let e of t)try{e()}catch{}return{dispose:()=>{}}}}function mF(e){let t=e?.onDragDropEvent;return typeof t==`function`?t.bind(e):null}function hF(e,t,n){let r=Number.isFinite(n)&&n>0?n:1;return gF(e.x/r,e.y/r,t)}function gF(e,t,n){return e>=n.left&&e<=n.right&&t>=n.top&&t<=n.bottom}function _F({x:e,y:t,label:n,onSelect:r,onClose:i}){let a=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let e=e=>{a.current&&!a.current.contains(e.target)&&i()},t=e=>{e.key===`Escape`&&i()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]),(0,$.jsx)(`div`,{ref:a,role:`menu`,"data-shortcut-context-menu":!0,style:{position:`fixed`,left:typeof window<`u`&&e+220>window.innerWidth?e-220:e,top:typeof window<`u`&&t+60>window.innerHeight?t-60:t,minWidth:200},className:`bg-[#1f1f29] border border-[#44475a] rounded-md shadow-lg py-1 z-50 text-sm`,children:(0,$.jsx)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{r(),i()},className:`w-full text-left px-3 py-1.5 text-[#f8f8f2] hover:bg-[#44475a]`,children:n})})}function vF({x:e,y:t,providers:n,onSelect:r,onClose:i}){let{t:a}=K(`terminal`),o=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=e=>{o.current&&!o.current.contains(e.target)&&i()},t=e=>{e.key===`Escape`&&i()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]);let s=typeof window<`u`&&e+200>window.innerWidth?e-200:e,c=8+n.length*32;return(0,$.jsx)(`div`,{ref:o,role:`menu`,"data-cli-launch-menu":!0,style:{position:`fixed`,left:s,top:typeof window<`u`&&t+c>window.innerHeight?t-c:t,minWidth:180},className:`bg-[#1f1f29] border border-[#44475a] rounded-md shadow-lg py-1 z-50 text-sm`,children:n.map(e=>(0,$.jsx)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{r(e),i()},className:`w-full text-left px-3 py-1.5 text-[#f8f8f2] hover:bg-[#44475a]`,children:a(`cliMenu.open`,{name:jt(e)})},e))})}var yF=(0,Q.forwardRef)(function({isOpen:e,className:t,...n},r){let{t:i}=K(`terminal`);return(0,$.jsx)(`button`,{ref:r,type:`button`,"aria-label":i(e?`panelChevron.collapse`:`panelChevron.expand`),"aria-expanded":e,className:X(`panel-chevron`,`inline-flex items-center justify-center`,`h-5 w-6 mr-1.5`,`rounded text-muted-foreground`,`hover:bg-border/40 hover:text-foreground`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent-primary/60`,`transition-colors duration-120`,t),...n,children:(0,$.jsxs)(`svg`,{width:`14`,height:`10`,viewBox:`0 0 14 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,$.jsx)(`rect`,{x:`1`,y:`1`,width:`12`,height:`8`,rx:`1.5`}),e?(0,$.jsx)(`path`,{d:`M5 3.5 L7 5.5 L9 3.5`}):(0,$.jsx)(`path`,{d:`M5 6.5 L7 4.5 L9 6.5`})]})})});function bF({visibility:e,canCreate:t,hasActive:n,provider:r=`claude`,providers:i,onCreate:a,onOpenCli:o,onOpenBrowser:s,onPasteScript:c,pasteScriptDisabled:l,onConfigureBrowser:u,onConfigureScript:d,onKillActive:f,onToggleMaximize:p,onCollapse:m}){let{t:h}=K(`terminal`),g=!!i&&i.length>1,_=jt(r),v=h(`topBar.maxTerminals`,{max:10}),y=t?g?h(`topBar.openCliMulti`):h(`topBar.openCli`,{cli:_}):v;return(0,$.jsxs)(`div`,{className:X(`flex items-center justify-between h-7 px-2 shrink-0`,`bg-background/95 backdrop-blur-sm`,`border-b border-border/40`,`text-[10px] uppercase tracking-wide text-muted-foreground select-none`),children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2 pl-1`,children:(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:h(`topBar.title`)})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,$.jsx)(xF,{label:y,disabled:!t,onClick:e=>o(e?{x:e.clientX,y:e.clientY}:void 0),children:(0,$.jsx)(Ln,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(xF,{label:h(`topBar.openInBrowser`),onClick:s,onContextMenu:e=>{e.preventDefault(),u({x:e.clientX,y:e.clientY})},children:(0,$.jsx)(D,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(xF,{label:h(l?`topBar.pasteScriptNoActive`:`topBar.pasteScript`),disabled:l,onClick:c,onContextMenu:e=>{e.preventDefault(),d({x:e.clientX,y:e.clientY})},children:(0,$.jsx)(is,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(xF,{label:t?h(`topBar.newTerminal`):v,disabled:!t,onClick:a,children:(0,$.jsx)(Pn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(xF,{label:h(`topBar.killActive`),disabled:!n,onClick:f,children:(0,$.jsx)(Rn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(xF,{label:h(e===`maximized`?`topBar.restorePanel`:`topBar.maximizePanel`),onClick:p,children:e===`maximized`?(0,$.jsx)(Js,{className:`h-3.5 w-3.5`}):(0,$.jsx)(qs,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(yF,{isOpen:!0,onClick:m})]})]})}function xF({label:e,disabled:t,onClick:n,onContextMenu:r,children:i}){return(0,$.jsx)(`button`,{type:`button`,onClick:e=>n(e),onContextMenu:r,disabled:t,title:e,"aria-label":e,className:X(`inline-flex items-center justify-center h-5 w-6 rounded`,`text-muted-foreground transition-colors duration-120`,t?`opacity-40 cursor-not-allowed`:`hover:bg-border/40 hover:text-foreground`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent-primary/60`),children:i})}function SF({sessions:e,activeId:t,onActivate:n,onRename:r,onKill:i}){return(0,$.jsx)(`aside`,{className:X(`w-44 shrink-0 border-l border-border/40 bg-background/70`,`overflow-y-auto`),children:(0,$.jsx)(`ul`,{className:`py-1`,children:e.map(e=>(0,$.jsx)(CF,{session:e,active:e.id===t,onActivate:()=>n(e.id),onRename:t=>r(e.id,t),onKill:()=>i(e.id)},e.id))})})}function CF({session:e,active:t,onActivate:n,onRename:r,onKill:i}){let{t:a}=K(`terminal`),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(e.name),u=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{o&&(l(e.name),queueMicrotask(()=>{u.current?.focus(),u.current?.select()}))},[o,e.name]);function d(){let t=c.trim();t&&t!==e.name&&r(t),s(!1)}function f(){s(!0)}function p(){s(!1),l(e.name)}return(0,$.jsx)(`li`,{className:`relative group px-1`,children:(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-pressed":t,onClick:()=>{o||n()},onKeyDown:e=>{o||(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),n())},onDoubleClick:f,className:X(`flex items-center gap-2 px-2 py-1.5 rounded-md text-xs cursor-pointer select-none`,`transition-colors duration-120`,t?`bg-border/40 text-foreground border-l-2 border-accent-primary/70 pl-[calc(0.5rem-2px)]`:`text-muted-foreground hover:bg-border/20 hover:text-foreground`),children:[(0,$.jsx)(Ac,{className:`h-3 w-3 shrink-0`}),o?(0,$.jsx)(`input`,{ref:u,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),d()),e.key===`Escape`&&(e.preventDefault(),p())},onBlur:d,onClick:e=>e.stopPropagation(),maxLength:64,className:X(`flex-1 min-w-0 bg-background/60 border border-border/40 rounded px-1`,`text-xs text-foreground outline-none focus:ring-1 focus:ring-accent-primary/60`)}):(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),!o&&(0,$.jsx)(`button`,{type:`button`,"aria-label":a(`sidebar.rename`,{name:e.name}),title:a(`sidebar.rename`,{name:e.name}),onClick:e=>{e.stopPropagation(),f()},className:X(`inline-flex items-center justify-center h-4 w-4 rounded`,`text-muted-foreground opacity-0 group-hover:opacity-100`,`hover:bg-border/40 hover:text-foreground`,`transition-opacity duration-120`,t&&`opacity-70`),children:(0,$.jsx)(jn,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,"aria-label":a(`sidebar.close`,{name:e.name}),title:a(`sidebar.close`,{name:e.name}),onClick:e=>{e.stopPropagation(),i()},className:X(`inline-flex items-center justify-center h-4 w-4 rounded`,`text-muted-foreground opacity-0 group-hover:opacity-100`,`hover:bg-destructive/20 hover:text-destructive`,`transition-opacity duration-120`,t&&`opacity-70`),children:(0,$.jsx)(Vn,{className:`h-3 w-3`})})]})})}function wF({search:e,onClose:t}){let{t:n}=K(`terminal`),r=(0,Q.useRef)(null),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(null);(0,Q.useEffect)(()=>(r.current?.focus(),()=>{try{e.clearDecorations()}catch{}}),[e]),(0,Q.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.preventDefault(),t())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);function m(){return{caseSensitive:o,regex:c,wholeWord:u,decorations:{matchBackground:`#bd93f9`,matchOverviewRuler:`#bd93f9`,activeMatchBackground:`#ff79c6`,activeMatchColorOverviewRuler:`#ff79c6`}}}function h(){if(i)try{e.findNext(i,m())}catch{}}function g(){if(i)try{e.findPrevious(i,m())}catch{}}return(0,Q.useEffect)(()=>{let t=()=>{};try{let n=e.onDidChangeResults(e=>{if(!e){p(null);return}p({current:e.resultIndex+1,total:e.resultCount})});t=()=>{try{n.dispose()}catch{}}}catch{}return t},[e]),(0,$.jsxs)(`div`,{className:`absolute top-2 right-2 flex items-center gap-1 bg-[#1f1f29] border border-[#44475a] rounded-md shadow-lg px-2 py-1 z-30`,role:`search`,"data-terminal-search-overlay":!0,children:[(0,$.jsx)(`input`,{ref:r,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.shiftKey?g():h())},placeholder:n(`search.placeholder`),className:`bg-transparent text-sm outline-none text-[#f8f8f2] placeholder:text-[#6272a4] w-48`}),f&&(0,$.jsxs)(`span`,{className:`text-xs text-[#6272a4] tabular-nums`,children:[f.current,`/`,f.total]}),(0,$.jsx)(`button`,{type:`button`,title:n(`search.previous`),onClick:g,className:`text-[#f8f8f2] hover:text-white p-1`,children:(0,$.jsx)(gn,{size:14})}),(0,$.jsx)(`button`,{type:`button`,title:n(`search.next`),onClick:h,className:`text-[#f8f8f2] hover:text-white p-1`,children:(0,$.jsx)(Xo,{size:14})}),(0,$.jsx)(TF,{label:`Aa`,title:n(`search.matchCase`),active:o,onToggle:()=>s(e=>!e)}),(0,$.jsx)(TF,{label:`.*`,title:n(`search.regex`),active:c,onToggle:()=>l(e=>!e)}),(0,$.jsx)(TF,{label:`W`,title:n(`search.wholeWord`),active:u,onToggle:()=>d(e=>!e)}),(0,$.jsx)(`button`,{type:`button`,title:n(`search.close`),onClick:t,className:`text-[#f8f8f2] hover:text-white p-1`,children:(0,$.jsx)(Vn,{size:14})})]})}function TF({label:e,title:t,active:n,onToggle:r}){return(0,$.jsx)(`button`,{type:`button`,title:t,onClick:r,className:`text-xs px-1.5 py-0.5 rounded font-mono ${n?`bg-[#6272a4] text-white`:`text-[#f8f8f2] hover:bg-[#44475a]`}`,children:e})}function EF({x:e,y:t,term:n,cwd:r,hasReveal:i,onClose:a,onOpenSearch:o,onReveal:s,onSaveScrollback:c}){let{t:l}=K(`terminal`),u=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&a()},t=e=>{e.key===`Escape`&&a()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]);let d=typeof window<`u`&&e+220>window.innerWidth?e-220:e,f=typeof window<`u`&&t+260>window.innerHeight?t-260:t,p=/Mac/i.test(navigator.platform||``)?`⌘`:`Ctrl+`,m=n.getSelection(),h=m.length>0;function g(){h&&(Aa(m),a())}function _(){ka().then(e=>{if(e)try{n.paste(e)}catch{}}),a()}function v(){try{n.selectAll()}catch{}a()}function y(){try{n.clear()}catch{}a()}function b(){o(),a()}function x(){c(),a()}function S(){r&&s(r),a()}return(0,$.jsxs)(`div`,{ref:u,role:`menu`,"data-terminal-context-menu":!0,style:{position:`fixed`,left:d,top:f,minWidth:200},className:`bg-[#1f1f29] border border-[#44475a] rounded-md shadow-lg py-1 z-50 text-sm`,children:[(0,$.jsx)(DF,{onClick:g,disabled:!h,label:l(`common:actions.copy`),shortcut:p+`C`}),(0,$.jsx)(DF,{onClick:_,label:l(`contextMenu.paste`),shortcut:p+`V`}),(0,$.jsx)(DF,{onClick:v,label:l(`contextMenu.selectAll`),shortcut:p+`A`}),(0,$.jsx)(OF,{}),(0,$.jsx)(DF,{onClick:y,label:l(`contextMenu.clear`),shortcut:p+`K`}),(0,$.jsx)(DF,{onClick:b,label:l(`contextMenu.search`),shortcut:p+`F`}),(0,$.jsx)(DF,{onClick:x,label:l(`contextMenu.saveScrollback`)}),r&&i&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(OF,{}),(0,$.jsx)(DF,{onClick:S,label:l(`contextMenu.openPath`,{path:kF(r,40)})})]})]})}function DF({onClick:e,label:t,shortcut:n,disabled:r}){return(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{r||e()},disabled:r,className:`w-full text-left px-3 py-1.5 flex justify-between items-center ${r?`text-[#6272a4] cursor-not-allowed`:`text-[#f8f8f2] hover:bg-[#44475a]`}`,children:[(0,$.jsx)(`span`,{children:t}),n&&(0,$.jsx)(`span`,{className:`text-xs text-[#6272a4] tabular-nums`,children:n})]})}function OF(){return(0,$.jsx)(`div`,{className:`my-1 border-t border-[#44475a]`})}function kF(e,t){return e.length<=t?e:`…`+e.slice(e.length-t+1)}async function AF(e,t=`terminal-scrollback.txt`){let n=e.buffer.active,r=[];for(let e=0;e<n.length;e++){let t=n.getLine(e);t&&r.push(t.translateToString(!0))}let i=r.join(`
|
|
49
49
|
`);if(de()){let{invoke:e}=await c(async()=>{let{invoke:e}=await import(`./core-B3mKBIh5.js`).then(e=>e.i);return{invoke:e}},__vite__mapDeps([0,1]));await e(`desktop_save_text`,{suggestedName:t,text:i});return}try{let e=new Blob([i],{type:`text/plain;charset=utf-8`}),n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}catch{}}function jF({sessionId:e}){let[t,n]=(0,Q.useState)(()=>Hi(e));return(0,Q.useEffect)(()=>Vi(e,n),[e]),t.promptRows.length===0?null:(0,$.jsx)(`div`,{"aria-hidden":`true`,"data-prompt-gutter":!0,className:`absolute left-0 top-0 bottom-0 w-1 pointer-events-none z-10`,children:(0,$.jsx)(`div`,{className:`absolute top-0 left-0 bottom-0 w-full`,style:{backgroundImage:`linear-gradient(to bottom, rgba(189,147,249,0.2), rgba(189,147,249,0.05))`}})})}function MF({sessionId:e}){let{t}=K(`terminal`),[n,r]=(0,Q.useState)(Hi(e).openPreExec?.startedAt??null),[i,a]=(0,Q.useState)(Date.now());if((0,Q.useEffect)(()=>Vi(e,e=>r(e.openPreExec?.startedAt??null)),[e]),(0,Q.useEffect)(()=>{if(n==null)return;let e=setInterval(()=>a(Date.now()),1e3);return()=>clearInterval(e)},[n]),n==null)return null;let o=i-n;return o<500?null:(0,$.jsx)(`div`,{className:`absolute top-2 left-2 px-2 py-0.5 rounded text-xs font-mono bg-[#44475a] text-[#f8f8f2] z-10 pointer-events-none`,children:NF(o,t)})}function NF(e,t){return e<6e4?t(`terminal:duration.seconds`,{seconds:(e/1e3).toFixed(1)}):t(`terminal:duration.minutesSeconds`,{minutes:Math.floor(e/6e4),seconds:Math.floor(e%6e4/1e3)})}function PF({activeId:e}){let{t}=K(`terminal`),n=(0,Q.useRef)(null),r=za(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),c=de();(0,Q.useEffect)(()=>{if(e)return r.subscribeOpenSearch(e,()=>a(!0))},[e,r]),(0,Q.useEffect)(()=>{a(!1),s(null)},[e]);let l=e?r.getSearchAddon(e):null,u=e?r.getTerminalInstance(e):null,d=e?r.getCwd(e):null,[f,p]=(0,Q.useState)(!1),m=(0,Q.useCallback)(t=>{if(!t)return!1;if(e&&r.writeToSession(e,t))return!0;if(!u)return!1;try{return u.paste(t),!0}catch{return!1}},[e,r,u]),h=(0,Q.useCallback)(n=>{if(!u||!n||n.length===0)return!1;let i=Array.from(n).map(e=>FF(e)).filter(e=>!!e);if(i.length===0)return!1;let a=typeof navigator<`u`&&/Win/i.test(navigator.platform||``);try{return m(dF(i,a,fF(e?r.getShell?.(e):null)))}catch{return J.error(t(`errors.pathPasteUnsafe`)),!1}},[u,m,e,r,t]),g=(0,Q.useCallback)(e=>{if(e.preventDefault(),!e.shiftKey&&u){let e=u.modes?.mouseTrackingMode;if(e&&e!==`none`)return}s({x:e.clientX,y:e.clientY})},[u]),_=(0,Q.useCallback)(n=>{if(!u)return;if(n.clipboardData.files&&n.clipboardData.files.length>0){let i=Array.from(n.clipboardData.files).map(e=>FF(e)).filter(e=>!!e);if(i.length>0){n.preventDefault(),n.stopPropagation();let a=typeof navigator<`u`&&/Win/i.test(navigator.platform||``);try{m(dF(i,a,fF(e?r.getShell?.(e):null)))}catch{J.error(t(`errors.pathPasteUnsafe`))}return}}let i=n.clipboardData.getData(`text/plain`);i&&(n.preventDefault(),n.stopPropagation(),m(i))},[u,m,e,r,t]),v=(0,Q.useCallback)(e=>{if(!u)return;let t=u.getSelection();t&&(e.clipboardData.setData(`text/plain`,t),e.preventDefault(),e.stopPropagation())},[u]),y=(0,Q.useCallback)(e=>{if(u&&(typeof navigator<`u`&&/Mac/i.test(navigator.platform||``)?e.metaKey:e.ctrlKey)&&(e.key===`c`||e.key===`C`)){let t=u.getSelection();if(!t)return;e.preventDefault(),e.stopPropagation(),Aa(t)}},[u]);return(0,Q.useEffect)(()=>{let t=n.current;if(!t||!e)return;let i=r.getContainer(e);if(i)return t.appendChild(i),r.notifyAdopted(e),()=>{let e=document.getElementById(`specrails-terminal-host`);e&&i.parentElement===t&&e.appendChild(i)}},[e,r]),(0,Q.useEffect)(()=>{let t=n.current;if(!t||!e)return;let i=[],a=t.parentElement;for(;a&&a!==document.body;)(a.tagName.toLowerCase()===`aside`||a.matches(`[data-sidebar]`))&&i.push(a),a=a.parentElement;if(i.length===0)return;let o=t=>{let n=t;n.propertyName!==`width`&&n.propertyName!==`height`||r.refitActive(e)};return i.forEach(e=>e.addEventListener(`transitionend`,o)),()=>{i.forEach(e=>e.removeEventListener(`transitionend`,o))}},[e,r]),(0,$.jsxs)(`div`,{ref:n,className:`flex-1 min-w-0 bg-background px-2 py-1 relative ${f?`outline outline-2 outline-accent-primary outline-offset-[-2px]`:``}`,role:`presentation`,"data-terminal-viewport":!0,onContextMenu:g,onPasteCapture:_,onCopyCapture:v,onKeyDownCapture:y,tabIndex:-1,onDragEnter:e=>{IF(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),p(!0))},onDragOver:e=>{IF(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),p(!0))},onDragLeave:()=>p(!1),onDrop:e=>{IF(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),h(e.dataTransfer.files)),p(!1)},children:[e&&(0,$.jsx)(jF,{sessionId:e}),e&&(0,$.jsx)(MF,{sessionId:e}),i&&l&&(0,$.jsx)(wF,{search:l,onClose:()=>a(!1)}),o&&u&&(0,$.jsx)(EF,{x:o.x,y:o.y,term:u,cwd:d,hasReveal:c,onClose:()=>s(null),onOpenSearch:()=>a(!0),onReveal:e=>{Ne(e).catch(()=>J.error(t(`errors.nativeActionFailed`)))},onSaveScrollback:()=>{u&&AF(u).catch(()=>J.error(t(`errors.nativeActionFailed`)))}})]})}function FF(e){let t=e.path;return typeof t==`string`&&t.length>0?t:null}function IF(e){return e?Array.from(e.types).includes(`Files`):!1}function LF({height:e,maxHeight:t,onHeightCommit:n,onHeightPreview:r,minHeight:i=120}){let{t:a}=K(`terminal`),o=(0,Q.useRef)(!1),s=(0,Q.useRef)(0),c=(0,Q.useRef)(e),l=(0,Q.useRef)(!1),u=(0,Q.useRef)(e),d=(0,Q.useCallback)(e=>e<i?i:e>t?t:Math.round(e),[i,t]);(0,Q.useEffect)(()=>{function e(e){if(!o.current)return;let t=s.current-e.clientY,n=d(c.current+t);u.current=n,l.current||(l.current=!0,requestAnimationFrame(()=>{l.current=!1,r?.(u.current)}))}function t(){o.current&&(o.current=!1,document.body.style.userSelect=``,document.body.style.cursor=``,n(u.current))}return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t),window.addEventListener(`pointercancel`,t),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t),window.removeEventListener(`pointercancel`,t)}},[d,n,r]);function f(t){o.current=!0,s.current=t.clientY,c.current=e,u.current=e,document.body.style.userSelect=`none`,document.body.style.cursor=`row-resize`;let n=t.target;if(typeof n.setPointerCapture==`function`)try{n.setPointerCapture(t.pointerId)}catch{}}return(0,$.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,"aria-label":a(`dragHandle.resize`),onPointerDown:f,className:X(`absolute top-0 left-0 right-0 h-1`,`cursor-row-resize`,`bg-transparent hover:bg-accent-primary/40`,`transition-colors duration-120`,`z-10`)})}function RF({onCreate:e}){let{t}=K(`terminal`);return(0,$.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-center px-6 bg-background-deep`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 text-muted-foreground`,children:[(0,$.jsx)(Ac,{className:`h-8 w-8 opacity-50`}),(0,$.jsx)(`p`,{className:`text-xs`,children:t(`emptyState.noTerminals`)}),(0,$.jsxs)(`button`,{type:`button`,onClick:e,className:`inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs bg-border/30 hover:bg-border/50 hover:text-foreground transition-colors`,children:[(0,$.jsx)(Pn,{className:`h-3 w-3`}),` `,t(`emptyState.newTerminal`)]})]})})}var zF=300;function BF({projectId:e,provider:t=`claude`,providers:n,state:r,viewportHeight:i,statusBarHeight:a}){let o=za(),{t:s}=K(`terminal`),c=y(),l=(0,Q.useRef)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(Pi),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),{launchDescriptors:v}=OA(),b=(0,Q.useRef)(a===0&&r.visibility!==`hidden`),[x,S]=(0,Q.useState)(()=>r.visibility===`hidden`?`hidden`:b.current?`opening`:`open`),C=(0,Q.useRef)(!1),w=n&&n.length>0?n:[t],T=w.length>1,E=(0,Q.useCallback)(async(t=()=>!1)=>{try{let n=await fetch(`/api/projects/${e}/terminal-settings`);if(!n.ok)return;let r=await n.json();!t()&&r?.resolved&&p(r.resolved)}catch{}},[e]);(0,Q.useEffect)(()=>{let e=!1;return E(()=>e),()=>{e=!0}},[E]),(0,Q.useEffect)(()=>{let t=t=>{let n=t.detail;n?.mode===`project`&&n.projectId!==e||E()};return window.addEventListener(tF,t),()=>window.removeEventListener(tF,t)},[E,e]);let D=Math.max(120,i-a-40),O=Math.min(Math.max(r.userHeight||320,120),D),k=r.visibility===`maximized`?Math.max(120,i-a):u??O,A=x===`open`,j=A?k:0,M=a===0,N=r.sessions.length<10,P=r.activeId!==null;(0,Q.useEffect)(()=>{let e=null,t=null,n=null,i=()=>{S(`opening`),t=requestAnimationFrame(()=>{n=requestAnimationFrame(()=>S(`open`))})};return C.current?(r.visibility===`hidden`?(S(`closing`),e=setTimeout(()=>S(`hidden`),zF)):i(),()=>{e&&clearTimeout(e),t!==null&&cancelAnimationFrame(t),n!==null&&cancelAnimationFrame(n)}):(C.current=!0,b.current&&i(),()=>{t!==null&&cancelAnimationFrame(t),n!==null&&cancelAnimationFrame(n)})},[r.visibility]),(0,Q.useEffect)(()=>{let e=!1,t=null;return pF(()=>{let e=l.current,t=r.activeId;return!e||!t||r.visibility===`hidden`?null:{viewportEl:e,shell:o.getShell?.(t),writeText:e=>{if(o.writeToSession(t,e))return!0;let n=o.getTerminalInstance(t);try{return n?.paste(e),!!n}catch{return!1}}}}).then(n=>{e?n.dispose():t=n}),()=>{e=!0,t?.dispose()}},[r.activeId,r.visibility,o]);let F=(0,Q.useCallback)(()=>{N&&o.create(e)},[N,e,o]),I=(0,Q.useCallback)(t=>{if(!N)return;let n=v[t]??{command:t,args:[]},i=[n.command,...n.args].join(` `)+`
|
|
50
50
|
`,a=t||`claude`,s=RegExp(`^${a} \\(\\d+\\)$`),c=r.sessions.filter(e=>e.name===a||s.test(e.name)),l=c.length===0?a:`${a} (${c.length+1})`;o.createAndType(e,i,{name:l})},[N,v,e,r.sessions,o]),L=(0,Q.useCallback)(e=>{if(N){if(T&&e){_(e);return}I(t)}},[N,T,t,I]),R=(0,Q.useCallback)(()=>{te(f.browserShortcutUrl)},[f.browserShortcutUrl]),z=(0,Q.useCallback)(()=>{r.activeId&&f.quickScript&&o.writeToSession(r.activeId,f.quickScript)},[f.quickScript,r.activeId,o]),B=(0,Q.useCallback)(e=>{h({...e,kind:`browser`})},[]),V=(0,Q.useCallback)(e=>{h({...e,kind:`script`})},[]),H=(0,Q.useCallback)(e=>{c(`/settings${e===`browser`?`#terminal-browser-shortcut-url`:`#terminal-quick-script`}`)},[c]),U=(0,Q.useCallback)(()=>{r.activeId&&o.kill(e,r.activeId)},[e,r.activeId,o]),W=(0,Q.useCallback)(()=>{o.setVisibility(e,r.visibility===`maximized`?`restored`:`maximized`)},[e,r.visibility,o]),ee=(0,Q.useCallback)(()=>{o.setVisibility(e,`hidden`)},[e,o]);return(0,Q.useEffect)(()=>{d(null)},[r.visibility]),x===`hidden`?null:(0,$.jsxs)(`div`,{ref:l,className:X(`relative flex flex-col shrink-0 overflow-hidden origin-bottom transform-gpu bg-background/95`,`border-t border-border/40`,`transition-[height,opacity,transform,clip-path] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none`),style:{height:j,opacity:+!!A,transform:A?`translateY(0) scaleY(1)`:`translateY(${M?14:8}px) scaleY(${M?.96:.985})`,clipPath:A?`inset(0 0 0 0)`:`inset(100% 0 0 0)`},"data-testid":`terminal-bottom-panel`,children:[(0,$.jsx)(LF,{height:O,maxHeight:D,onHeightPreview:e=>d(e),onHeightCommit:t=>{d(null),o.setUserHeight(e,t),r.visibility===`maximized`&&o.setVisibility(e,`restored`)}}),(0,$.jsx)(bF,{visibility:r.visibility,canCreate:N,hasActive:P,provider:t,providers:w,onCreate:F,onOpenCli:L,onOpenBrowser:R,onPasteScript:z,pasteScriptDisabled:!P||!f.quickScript,onConfigureBrowser:B,onConfigureScript:V,onKillActive:U,onToggleMaximize:W,onCollapse:ee}),m&&(0,$.jsx)(_F,{x:m.x,y:m.y,label:m.kind===`browser`?s(`shortcutMenu.configureBrowserUrl`):s(`shortcutMenu.editQuickScript`),onSelect:()=>H(m.kind),onClose:()=>h(null)}),g&&(0,$.jsx)(vF,{x:g.x,y:g.y,providers:w,onSelect:e=>I(e),onClose:()=>_(null)}),(0,$.jsx)(`div`,{className:`flex-1 flex min-h-0`,children:r.sessions.length===0?(0,$.jsx)(RF,{onCreate:F}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(PF,{activeId:r.activeId}),(0,$.jsx)(SF,{sessions:r.sessions,activeId:r.activeId,onActivate:t=>o.setActive(e,t),onRename:(t,n)=>void o.rename(e,t,n),onKill:t=>void o.kill(e,t)})]})})]})}function VF(){let{t:e}=K(`agent`),{current:t,initialized:n}=Ci(),{active:r}=aP(),{activeProjectId:i,projects:a}=pt(),o=Ba(i),s=a.find(e=>e.id===i),[c,l]=(0,Q.useState)(window.innerHeight);return(0,Q.useEffect)(()=>{!de()||!t||r?.id!==t.conversationId||_P().setTitle(`${r.title?.trim()||e(`header.untitled`)} — Specrails`).catch(()=>{})},[t?.conversationId,r?.id,r?.title,e]),(0,Q.useEffect)(()=>{let e=()=>l(window.innerHeight);return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]),!n||!t||r?.id!==t.conversationId?(0,$.jsx)(`div`,{role:`status`,className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:e(`window.loading`)}):(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 overflow-hidden`,"data-mission-window":!0,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,$.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,$.jsx)(IP,{})}),Te&&s&&i&&(0,$.jsx)(BF,{projectId:i,provider:s.provider,providers:dt(s),state:o,viewportHeight:c-36,statusBarHeight:0})]}),(0,$.jsx)(eF,{missionOnly:!0})]})}function HF(){var e=[...arguments];return(0,Q.useMemo)(()=>t=>{e.forEach(e=>e(t))},e)}var UF=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function WF(e){let t=Object.prototype.toString.call(e);return t===`[object Window]`||t===`[object global]`}function GF(e){return`nodeType`in e}function KF(e){return e?WF(e)?e:GF(e)?e.ownerDocument?.defaultView??window:window:window}function qF(e){let{Document:t}=KF(e);return e instanceof t}function JF(e){return!WF(e)&&e instanceof KF(e).HTMLElement}function YF(e){return e instanceof KF(e).SVGElement}function XF(e){return e?WF(e)?e.document:GF(e)?qF(e)?e:JF(e)||YF(e)?e.ownerDocument:document:document:document}var ZF=UF?Q.useLayoutEffect:Q.useEffect;function QF(e){let t=(0,Q.useRef)(e);return ZF(()=>{t.current=e}),(0,Q.useCallback)(function(){var e=[...arguments];return t.current==null?void 0:t.current(...e)},[])}function $F(){let e=(0,Q.useRef)(null);return[(0,Q.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,Q.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}function eI(e,t){t===void 0&&(t=[e]);let n=(0,Q.useRef)(e);return ZF(()=>{n.current!==e&&(n.current=e)},t),n}function tI(e,t){let n=(0,Q.useRef)();return(0,Q.useMemo)(()=>{let t=e(n.current);return n.current=t,t},[...t])}function nI(e){let t=QF(e),n=(0,Q.useRef)(null);return[n,(0,Q.useCallback)(e=>{e!==n.current&&t?.(e,n.current),n.current=e},[])]}function rI(e){let t=(0,Q.useRef)();return(0,Q.useEffect)(()=>{t.current=e},[e]),t.current}var iI={};function aI(e,t){return(0,Q.useMemo)(()=>{if(t)return t;let n=iI[e]==null?0:iI[e]+1;return iI[e]=n,e+`-`+n},[e,t])}function oI(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>{let r=Object.entries(n);for(let[n,i]of r){let r=t[n];r!=null&&(t[n]=r+e*i)}return t},{...t})}}var sI=oI(1),cI=oI(-1);function lI(e){return`clientX`in e&&`clientY`in e}function uI(e){if(!e)return!1;let{KeyboardEvent:t}=KF(e.target);return t&&e instanceof t}function dI(e){if(!e)return!1;let{TouchEvent:t}=KF(e.target);return t&&e instanceof t}function fI(e){if(dI(e)){if(e.touches&&e.touches.length){let{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){let{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return lI(e)?{x:e.clientX,y:e.clientY}:null}var pI=Object.freeze({Translate:{toString(e){if(!e)return;let{x:t,y:n}=e;return`translate3d(`+(t?Math.round(t):0)+`px, `+(n?Math.round(n):0)+`px, 0)`}},Scale:{toString(e){if(!e)return;let{scaleX:t,scaleY:n}=e;return`scaleX(`+t+`) scaleY(`+n+`)`}},Transform:{toString(e){if(e)return[pI.Translate.toString(e),pI.Scale.toString(e)].join(` `)}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+` `+n+`ms `+r}}}),mI=`a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]`;function hI(e){return e.matches(mI)?e:e.querySelector(mI)}var gI={display:`none`};function _I(e){let{id:t,value:n}=e;return Q.createElement(`div`,{id:t,style:gI},n)}function vI(e){let{id:t,announcement:n,ariaLiveType:r=`assertive`}=e;return Q.createElement(`div`,{id:t,style:{position:`fixed`,top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0 0 0 0)`,clipPath:`inset(100%)`,whiteSpace:`nowrap`},role:`status`,"aria-live":r,"aria-atomic":!0},n)}function yI(){let[e,t]=(0,Q.useState)(``);return{announce:(0,Q.useCallback)(e=>{e!=null&&t(e)},[]),announcement:e}}var bI=(0,Q.createContext)(null);function xI(e){let t=(0,Q.useContext)(bI);(0,Q.useEffect)(()=>{if(!t)throw Error(`useDndMonitor must be used within a children of <DndContext>`);return t(e)},[e,t])}function SI(){let[e]=(0,Q.useState)(()=>new Set),t=(0,Q.useCallback)(t=>(e.add(t),()=>e.delete(t)),[e]);return[(0,Q.useCallback)(t=>{let{type:n,event:r}=t;e.forEach(e=>e[n]?.call(e,r))},[e]),t]}var CI={draggable:`
|
|
51
51
|
To pick up a draggable item, press the space bar.
|
|
@@ -71,10 +71,10 @@ Error generating stack: `+e.message+`
|
|
|
71
71
|
`)})}finally{h.current&&m.current===n&&d(!1)}}async function N(){let e=v.recoveryWorktreePaths;if(e.length===0){J.info(i(`railPr.localResultUnavailableHere`));return}let t=e.join(`
|
|
72
72
|
`),n=!1;try{await navigator.clipboard.writeText(t),n=!0}catch{}try{de()&&await Ne(e[0])}catch{}n?J.success(i(`railPr.localResultPathCopied`),{description:t}):J.info(i(`railPr.localResultPath`),{description:t})}let P=`inline-flex items-center gap-1 rounded-full font-medium border ${T?`px-1.5 py-0.5 text-[9px]`:`px-2 py-0.5 text-[10px]`}`,F=`inline-flex items-center gap-1 rounded-md font-medium bg-accent-primary text-white hover:bg-accent-primary/90 disabled:opacity-50 disabled:pointer-events-none transition-colors ${T?`px-1.5 py-0.5 text-[9px]`:`px-2 py-0.5 text-[10px]`}`,I=`inline-flex items-center gap-1 rounded-md font-medium border border-border/60 text-foreground/70 hover:border-accent-primary/40 hover:bg-accent-primary/10 disabled:opacity-50 disabled:pointer-events-none transition-colors ${T?`px-1.5 py-0.5 text-[9px]`:`px-2 py-0.5 text-[10px]`}`,L=`inline-flex items-center gap-1 rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 disabled:opacity-50 disabled:pointer-events-none transition-colors ${T?`px-1.5 py-0.5 text-[9px]`:`px-2 py-0.5 text-[10px]`}`,R=T?`w-2.5 h-2.5`:`w-3 h-3`,z=(0,$.jsx)(An,{className:`${R} animate-spin`,"aria-hidden":!0}),B=c!==null||u||e.operation!=null,V=s.has(e.prDeliveryId),H=i(g===`implementation_failed`?`railPr.implementationFailedHint`:`railPr.discardTooltip`),U=e.prUrl?(0,$.jsxs)(`a`,{href:e.prUrl,target:`_blank`,rel:`noreferrer`,"data-testid":`rail-pr-link`,title:i(`railPr.openPrTitle`),onClick:e=>e.stopPropagation(),className:`inline-flex items-center gap-1 rounded-md font-mono border border-accent-info/30 bg-accent-info/10 text-accent-info hover:bg-accent-info/20 hover:border-accent-info/60 transition-colors ${T?`px-1 py-0.5 text-[9px]`:`px-1.5 py-0.5 text-[10px]`}`,children:[e.prNumber==null?i(`railPr.prLinkFallback`):`#${e.prNumber}`,(0,$.jsx)(pn,{className:T?`w-2 h-2`:`w-2.5 h-2.5`,"aria-hidden":!0})]}):null,W=e.branch?(0,$.jsx)(`span`,{"data-testid":`rail-pr-branch`,className:`inline-flex min-w-0 max-w-full items-center gap-1 rounded-md font-mono border border-border/60 bg-surface/60 text-foreground/70 ${T?`px-1 py-0.5 text-[9px]`:`px-1.5 py-0.5 text-[10px]`}`,children:(0,$.jsx)(`span`,{className:`truncate`,children:e.branch})}):null,ee=(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-discard`,disabled:B,title:H,onClick:e=>{e.stopPropagation(),D(`discard`)},className:L,children:[c===`discard`?z:null,i(`railPr.discard`)]}),te=!_&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-merge-local`,disabled:B,title:i(`railPr.mergeLocalTooltip`,{base:e.baseBranch}),onClick:e=>{e.stopPropagation(),D(`merge-local`)},className:`inline-flex items-center gap-1 rounded-md font-medium border border-accent-success/40 bg-accent-success/10 text-accent-success hover:bg-accent-success/20 disabled:opacity-50 disabled:pointer-events-none transition-colors ${T?`px-1.5 py-0.5 text-[9px]`:`px-2 py-0.5 text-[10px]`}`,children:[c===`merge-local`?z:(0,$.jsx)(ks,{className:R,"aria-hidden":!0}),i(`railPr.mergeLocal`)]}),ne=(e,t,n,r,i,a)=>!_&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":r,disabled:B,title:i,onClick:n=>{n.stopPropagation(),j(e,t)},className:F,children:[c===e?z:a,n]}),re=le?(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-open-packet`,title:i(`railPr.openReviewTooltip`),onClick:t=>{t.stopPropagation(),a(`/review/${e.prDeliveryId}`)},className:`inline-flex items-center gap-1 rounded-md font-medium border border-accent-primary/40 bg-accent-primary/10 text-accent-primary hover:bg-accent-primary/20 transition-colors ${T?`px-1.5 py-0.5 text-[9px]`:`px-2 py-0.5 text-[10px]`}`,children:[(0,$.jsx)(vs,{className:R,"aria-hidden":!0}),i(`railPr.openReview`)]}):null,ie=Yt(e),ae=r&&ie&&!_?(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-checkout`,disabled:B,title:i(`railPr.checkoutTooltip`,{branch:ie}),onClick:e=>{e.stopPropagation(),M()},className:`inline-flex items-center gap-1 rounded-md font-medium border border-border/60 text-foreground/70 hover:border-accent-primary/40 hover:bg-accent-primary/10 disabled:opacity-50 disabled:pointer-events-none transition-colors ${T?`px-1.5 py-0.5 text-[9px]`:`px-2 py-0.5 text-[10px]`}`,children:[u?z:(0,$.jsx)(On,{className:R,"aria-hidden":!0}),i(`railPr.checkout`)]}):null,oe=v.recoveryWorktreePaths.length>0?(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-inspect-local-result`,disabled:B,onClick:e=>{e.stopPropagation(),N()},className:I,title:i(`railPr.inspectLocalResultTooltip`),children:[(0,$.jsx)(Ts,{className:R,"aria-hidden":!0}),i(`railPr.inspectLocalResult`)]}):null,se=v.recoveryRecheck,ce=v.manualRecovery||se?(0,$.jsxs)(`button`,{type:`button`,"data-testid":se?`rail-pr-recheck-recovery`:`rail-pr-recover-and-retry`,disabled:B,onClick:e=>{e.stopPropagation(),D(`recover-and-retry`)},className:se?I:F,children:[c===`recover-and-retry`?z:(0,$.jsx)(Fn,{className:R,"aria-hidden":!0}),i(se?`railPr.recheckRecovery`:`railPr.recoverAndRetry`)]}):null,ue=(e.runIds??[]).map((t,n)=>(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-run-log`,title:i(`railPr.viewRunLog`,{ref:e.ticketIds[n]==null?t.slice(0,8):`#${e.ticketIds[n]}`}),"aria-label":i(`railPr.viewRunLog`,{ref:e.ticketIds[n]==null?t.slice(0,8):`#${e.ticketIds[n]}`}),onClick:e=>{e.stopPropagation(),a(`/jobs/${t}`)},className:`inline-flex items-center gap-1 rounded-md border border-accent-info/30 bg-accent-info/10 font-medium text-accent-info transition-colors hover:border-accent-info/55 hover:bg-accent-info/15 ${T?`px-1 py-0.5 text-[9px]`:`px-1.5 py-0.5 text-[10px]`}`,children:[(0,$.jsx)(yc,{className:R,"aria-hidden":!0}),e.ticketIds[n]==null?t.slice(0,8):`#${e.ticketIds[n]}`]},t)),fe=(e.units??[]).map(e=>{let t=e.implementationOutcome===`failed`||e.implementationOutcome==null&&!e.succeeded,n=e.deliveryOutcome===`blocked`,r=e.deliveryOutcome===`no_changes`||e.changed===!1;return(0,$.jsxs)(`span`,{"data-testid":`rail-pr-unit-evidence`,title:e.failureCode??e.branch,className:`${P} ${t?`border-destructive/30 bg-destructive/10 text-destructive`:n?`border-accent-warning/30 bg-accent-warning/10 text-accent-warning`:`border-accent-success/30 bg-accent-success/10 text-accent-success`}`,children:[`#`,e.ticketId,` · `,i(t?`railPr.unit.failed`:n?`railPr.unit.blocked`:r?`railPr.unit.noChanges`:`railPr.unit.succeeded`)]},`${e.ticketId}-${e.runId??e.branch}`)}),G=(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-dismiss`,disabled:B,onClick:e=>{e.stopPropagation(),D(`dismiss`)},className:L,children:[c===`dismiss`?z:null,i(`railPr.dismiss`)]}),pe=(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-discard-local`,disabled:B,onClick:e=>{e.stopPropagation(),D(`discard-local`)},className:L,children:[c===`discard`?z:null,i(`railPr.discardLocalResult`)]}),me=!_&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-no-changes-done`,disabled:B,onClick:e=>{e.stopPropagation(),D(`no-changes-done`)},className:F,children:[c===`acknowledge-no-changes`?z:(0,$.jsx)($o,{className:R,"aria-hidden":!0}),i(`railPr.markDone`)]}),he=(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-refine`,disabled:B,onClick:e=>{e.stopPropagation(),D(`refine`)},className:L,children:[c===`discard`?z:null,i(`railPr.refine`)]}),ge=null,_e=null;return w?(ge=(0,$.jsxs)(`span`,{className:`${P} border-accent-info/30 bg-accent-info/10 text-accent-info`,children:[(0,$.jsx)(An,{className:`${R} animate-spin`,"aria-hidden":!0}),i(`railPr.iteratingPr`)]}),_e=(0,$.jsxs)($.Fragment,{children:[U,W]})):v.noChanges?(ge=(0,$.jsxs)(`span`,{className:`${P} border-accent-success/30 bg-accent-success/10 text-accent-success`,children:[(0,$.jsx)($o,{className:R,"aria-hidden":!0}),i(`railPr.noChanges`)]}),_e=(0,$.jsxs)($.Fragment,{children:[e.prUrl?U:null,v.continuation?G:(0,$.jsxs)($.Fragment,{children:[me,he]})]})):v.partial&&!v.deliveryBlocked&&!v.retryablePush&&!v.retryablePrCreation&&!v.closed?(ge=(0,$.jsxs)(`span`,{className:`${P} border-accent-warning/30 bg-accent-warning/10 text-accent-warning`,children:[(0,$.jsx)(zn,{className:R,"aria-hidden":!0}),i(`railPr.partial`,{succeeded:v.succeededCount,total:v.totalCount})]}),_e=g===`pr_draft`&&e.prUrl?(0,$.jsxs)($.Fragment,{children:[U,ae,ne(`publish`,`pr_draft`,i(`railPr.publish`),`rail-pr-publish`,i(`railPr.publishTooltip`)),v.continuation?G:ee]}):g===`pr_ready`?(0,$.jsxs)($.Fragment,{children:[U,ae,ne(`poll-merge`,`pr_ready`,i(`railPr.verifyPr`),`rail-pr-poll`,i(`railPr.verifyPrTooltip`)),v.continuation?G:ee]}):g===`on_review`||g===`pr_draft`&&!e.prUrl?(0,$.jsxs)($.Fragment,{children:[ae,ne(`create-pr`,g,i(`railPr.createPartialPr`,{count:v.deliverableCount}),`rail-pr-create-partial`),v.continuation?G:ee]}):(0,$.jsxs)($.Fragment,{children:[U,ae,v.continuation?G:ee]})):v.deliveryBlocked?(ge=(0,$.jsxs)(`span`,{className:`${P} border-accent-warning/30 bg-accent-warning/10 text-accent-warning`,title:e.statusDetail??void 0,children:[(0,$.jsx)(zn,{className:R,"aria-hidden":!0}),i(`railPr.deliveryBlocked`)]}),_e=(0,$.jsxs)($.Fragment,{children:[U,oe,ce,v.continuation?v.hasDiscardableRecoveryResult?pe:G:ee]})):v.retryablePush?(ge=(0,$.jsxs)(`span`,{className:`${P} border-accent-warning/30 bg-accent-warning/10 text-accent-warning`,title:e.statusDetail??void 0,children:[(0,$.jsx)(zn,{className:R,"aria-hidden":!0}),i(`railPr.updateFailed`)]}),_e=(0,$.jsxs)($.Fragment,{children:[U,ae,ne(`create-pr`,g,i(`railPr.retryPush`),`rail-pr-retry-push`),v.continuation?G:ee]})):v.retryablePrCreation?(ge=(0,$.jsxs)(`span`,{className:`${P} border-accent-warning/30 bg-accent-warning/10 text-accent-warning`,title:e.statusDetail??void 0,children:[(0,$.jsx)(zn,{className:R,"aria-hidden":!0}),v.localOnly?i(`railPr.localOnly`):e.prState===`pushed`?i(`railPr.branchPushed`):i(`railPr.prFailed`)]}),_e=(0,$.jsxs)($.Fragment,{children:[ne(`create-pr`,g,i(`railPr.retryPr`),`rail-pr-create`),ae,te,v.continuation?G:ee]})):v.closed?(ge=(0,$.jsxs)(`span`,{className:`${P} border-accent-warning/30 bg-accent-warning/10 text-accent-warning`,children:[(0,$.jsx)(zn,{className:R,"aria-hidden":!0}),i(`railPr.prClosed`)]}),_e=(0,$.jsxs)($.Fragment,{children:[U,ae,ne(`reopen`,`pr_closed`,i(`railPr.reopen`),`rail-pr-reopen`,void 0,(0,$.jsx)(Fn,{className:R,"aria-hidden":!0})),v.continuation?G:ee]})):g===`on_review`?(ge=(0,$.jsxs)(`span`,{className:`${P} border-accent-warning/30 bg-accent-warning/10 text-accent-warning`,children:[(0,$.jsx)(vs,{className:R,"aria-hidden":!0}),i(`railPr.readyForReview`)]}),_e=(0,$.jsxs)($.Fragment,{children:[re,ae,ne(`create-pr`,`on_review`,i(`railPr.createPr`),`rail-pr-create`,i(`railPr.createPrTooltip`,{base:e.baseBranch}),(0,$.jsx)(A,{className:R,"aria-hidden":!0})),te,v.continuation?G:ee]})):g===`pr_draft`&&e.prUrl?(ge=(0,$.jsxs)(`span`,{className:`${P} border-accent-info/30 bg-accent-info/10 text-accent-info`,children:[(0,$.jsx)(A,{className:R,"aria-hidden":!0}),i(`railPr.draftPr`)]}),_e=(0,$.jsxs)($.Fragment,{children:[U,ae,ne(`publish`,`pr_draft`,i(`railPr.publish`),`rail-pr-publish`,i(`railPr.publishTooltip`)),v.continuation?G:ee]})):g===`pr_draft`?(ge=(0,$.jsxs)(`span`,{className:`${P} border-accent-warning/30 bg-accent-warning/10 text-accent-warning`,title:i(`railPr.branchPushedHint`),children:[(0,$.jsx)(zn,{className:R,"aria-hidden":!0}),v.localOnly?i(`railPr.localOnly`):i(`railPr.branchPushed`)]}),_e=(0,$.jsxs)($.Fragment,{children:[ne(`create-pr`,`pr_draft`,i(`railPr.retryPr`),`rail-pr-create`,i(`railPr.createPrTooltip`,{base:e.baseBranch})),ae,te,v.continuation?G:ee]})):g===`pr_ready`?(ge=(0,$.jsxs)(`span`,{className:`${P} border-accent-success/30 bg-accent-success/10 text-accent-success`,children:[(0,$.jsx)(ks,{className:R,"aria-hidden":!0}),i(`railPr.prReady`)]}),_e=(0,$.jsxs)($.Fragment,{children:[U,ae,ne(`poll-merge`,`pr_ready`,i(`railPr.verifyPr`),`rail-pr-poll`,i(`railPr.verifyPrTooltip`)),v.continuation?G:ee]})):g===`pr_failed`?(ge=(0,$.jsxs)(`span`,{className:`${P} border-destructive/30 bg-destructive/10 text-destructive`,children:[(0,$.jsx)(zn,{className:R,"aria-hidden":!0}),i(`railPr.prFailed`)]}),_e=(0,$.jsxs)($.Fragment,{children:[U,ae,ne(`create-pr`,`pr_failed`,i(`railPr.retry`),`rail-pr-create`,i(`railPr.createPrTooltip`,{base:e.baseBranch})),!e.prUrl&&te,v.continuation?G:ee]})):g===`implementation_failed`&&v.implementationFailed&&(ge=(0,$.jsxs)(`span`,{className:`${P} border-destructive/30 bg-destructive/10 text-destructive`,title:i(`railPr.implementationFailedHint`),children:[(0,$.jsx)(zn,{className:R,"aria-hidden":!0}),i(`railPr.implementationFailed`)]}),_e=(0,$.jsx)($.Fragment,{children:v.continuation?G:ee})),(0,$.jsxs)(`div`,{"data-testid":`rail-pr-strip`,"data-decision":g,className:`flex items-center flex-wrap animate-in fade-in slide-in-from-top-1 duration-200 ${T?`gap-1`:`gap-1.5`}`,onClick:e=>e.stopPropagation(),children:[C&&(0,$.jsx)(`span`,{role:`status`,"aria-live":`polite`,"aria-label":C,className:`sr-only`}),(0,$.jsx)(rn,{deliveryId:e.prDeliveryId,repositories:e.repositoryDeliveries,busy:B,onAct:(t,n)=>j(t,e.decision,e.prDeliveryId,n),onCheckout:r?M:void 0}),ge,e.operation&&(0,$.jsxs)(`span`,{className:`${P} border-accent-info/30 bg-accent-info/10 text-accent-info`,"data-testid":`rail-pr-operation`,children:[(0,$.jsx)(An,{className:`${R} animate-spin`,"aria-hidden":!0}),i(`railPr.operation.${e.operation}`)]}),_e,e.deliverySha&&(0,$.jsxs)(`span`,{className:`${P} ${e.deliveryOutcome===`delivered`?`border-accent-success/30 bg-accent-success/10 text-accent-success`:`border-border/60 bg-surface/60 text-foreground/60`} font-mono`,"data-testid":`rail-pr-delivery-sha`,title:e.deliverySha,children:[(0,$.jsx)($o,{className:R,"aria-hidden":!0}),i(`railPr.deliveryCommit`,{sha:e.deliverySha.slice(0,8)})]}),ue,fe,S&&(0,$.jsx)(`span`,{className:`${P} border-border/60 bg-surface/60 text-foreground/55`,"data-testid":`rail-pr-status-code`,children:S}),(x||v.recoveryUnavailable||!b&&e.statusDetail&&!v.recoveryUnavailable||v.cleanupWarnings.length>0)&&(0,$.jsxs)(`div`,{className:`basis-full rounded-md border border-accent-warning/30 bg-accent-warning/10 text-accent-warning ${T?`px-1.5 py-1 text-[9px]`:`px-2 py-1.5 text-[10px]`}`,"data-testid":`rail-pr-delivery-detail`,children:[x&&(0,$.jsxs)(`p`,{className:`flex items-start gap-1.5`,"data-testid":`rail-pr-recovery-interrupted`,children:[(0,$.jsx)(Fn,{className:`${R} mt-px shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:i(`common:prRecovery.interrupted`)})]}),v.recoveryUnavailable&&(0,$.jsx)(`p`,{"data-testid":`rail-pr-recovery-unavailable`,children:i(`railPr.recoveryUnavailableBody`)}),v.recoveryUnavailable&&e.statusDetail&&!b&&(0,$.jsxs)(`details`,{className:`mt-1 text-foreground/60`,"data-testid":`rail-pr-recovery-technical-detail`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer font-medium text-foreground/70`,children:i(`railPr.recoveryDetailSummary`)}),(0,$.jsx)(`p`,{className:`mt-1 break-words`,children:e.statusDetail})]}),!b&&e.statusDetail&&!v.recoveryUnavailable&&(0,$.jsx)(`p`,{children:e.statusDetail}),v.cleanupWarnings.length>0&&(0,$.jsxs)(`div`,{className:x||!b&&e.statusDetail?`mt-1`:void 0,children:[(0,$.jsx)(`p`,{className:`font-medium`,children:i(`railPr.cleanupIncomplete`,{count:v.cleanupWarnings.length})}),(0,$.jsx)(`ul`,{className:`mt-0.5 list-disc pl-4 text-foreground/60`,children:v.cleanupWarnings.map((e,t)=>(0,$.jsx)(`li`,{children:e},`${t}-${e}`))})]})]}),v.safetyArchives.length>0&&(0,$.jsxs)(`details`,{className:`basis-full rounded-md border border-accent-info/25 bg-accent-info/5 text-foreground/65 ${T?`px-1.5 py-1 text-[9px]`:`px-2 py-1.5 text-[10px]`}`,"data-testid":`rail-pr-safety-archives`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer font-medium text-accent-info`,children:i(`railPr.safetyArchiveTitle`,{count:v.safetyArchives.length})}),(0,$.jsx)(`p`,{className:`mt-1`,children:i(`railPr.safetyArchiveHint`)}),(0,$.jsx)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-[0.9em] text-foreground/55`,children:v.safetyArchives.map(e=>(0,$.jsx)(`li`,{className:`break-all`,children:e},e))})]}),(0,$.jsx)(mr,{open:E(`merge-local`),onOpenChange:e=>{e||O()},children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`rail-pr-merge-local-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:i(`railPr.mergeLocalConfirmTitle`)}),(0,$.jsx)(ir,{children:i(`railPr.mergeLocalConfirmBody`,{base:e.baseBranch})})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,children:i(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:B,"data-testid":`rail-pr-merge-local-confirm-btn`,onClick:()=>k(`merge-local`,`merge-local`),children:i(`railPr.mergeLocal`)})]})]})}),(0,$.jsx)(mr,{open:E(`discard`),onOpenChange:e=>{e||O()},children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`rail-pr-discard-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:i(g===`implementation_failed`?`railPr.implementationFailedDiscardTitle`:`railPr.discardConfirmTitle`)}),(0,$.jsx)(ir,{children:i(g===`implementation_failed`?`railPr.implementationFailedDiscardBody`:`railPr.discardConfirmBody`)}),V&&(0,$.jsx)(`p`,{className:`mt-2 rounded-md border border-accent-warning/40 bg-accent-warning/10 px-2 py-1.5 text-xs text-accent-warning`,"data-testid":`rail-pr-discard-stacked-note`,children:i(`railPr.discardStackedNote`)})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,children:i(`common:actions.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,size:`sm`,disabled:B,"data-testid":`rail-pr-discard-confirm-btn`,onClick:()=>k(`discard`,`discard`),children:i(`railPr.discard`)})]})]})}),(0,$.jsx)(mr,{open:E(`dismiss`),onOpenChange:e=>{e||O()},children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`rail-pr-dismiss-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:i(`railPr.dismissConfirmTitle`)}),(0,$.jsx)(ir,{children:i(`railPr.dismissConfirmBody`)})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,children:i(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:B,"data-testid":`rail-pr-dismiss-confirm-btn`,onClick:()=>k(`dismiss`,`dismiss`),children:i(`railPr.dismiss`)})]})]})}),(0,$.jsx)(mr,{open:E(`discard-local`),onOpenChange:e=>{e||O()},children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`rail-pr-discard-local-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:i(`railPr.discardLocalConfirmTitle`)}),(0,$.jsx)(ir,{children:i(`railPr.discardLocalConfirmBody`)})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,children:i(`common:actions.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,size:`sm`,disabled:B,"data-testid":`rail-pr-discard-local-confirm-btn`,onClick:()=>k(`discard-local`,`discard`),children:i(`railPr.discardLocalResult`)})]})]})}),(0,$.jsx)(mr,{open:E(`no-changes-done`),onOpenChange:e=>{e||O()},children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`rail-pr-no-changes-done-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:i(`railPr.markDoneConfirmTitle`)}),(0,$.jsx)(ir,{children:i(`railPr.markDoneConfirmBody`)})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,children:i(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:B,"data-testid":`rail-pr-no-changes-done-confirm-btn`,onClick:()=>k(`no-changes-done`,`acknowledge-no-changes`),children:i(`railPr.markDone`)})]})]})}),(0,$.jsx)(mr,{open:E(`refine`),onOpenChange:e=>{e||O()},children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`rail-pr-refine-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:i(`railPr.refineConfirmTitle`)}),(0,$.jsx)(ir,{children:i(`railPr.refineConfirmBody`)})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,children:i(`common:actions.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,size:`sm`,disabled:B,"data-testid":`rail-pr-refine-confirm-btn`,onClick:()=>k(`refine`,`discard`),children:i(`railPr.refine`)})]})]})}),(0,$.jsx)(mr,{open:E(`recover-and-retry`),onOpenChange:e=>{e||O()},children:(0,$.jsxs)(fr,{className:`max-w-sm`,"data-testid":`rail-pr-recover-and-retry-confirm`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:i(se?`railPr.recheckRecoveryConfirmTitle`:`railPr.recoverAndRetryConfirmTitle`)}),(0,$.jsx)(ir,{children:i(se?`railPr.recheckRecoveryConfirmBody`:`railPr.recoverAndRetryConfirmBody`,{branch:e.branch??``})})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,children:i(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:B,onClick:()=>k(`recover-and-retry`,`recover-and-retry`),children:i(se?`railPr.recheckRecovery`:`railPr.recoverAndRetry`)})]})]})})]})}function yU({railIndex:e,value:t,onChange:n}){let{t:r}=K(`dashboard`),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(``),f=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!i)return;let t=!1;return s(!0),fetch(`${ut()}/rails/${e}/pr-candidates`).then(e=>e.ok?e.json():Promise.reject(Error(`${e.status}`))).then(e=>{t||l(Array.isArray(e.candidates)?e.candidates:[])}).catch(()=>{t||l([])}).finally(()=>{t||s(!1)}),()=>{t=!0}},[i,e]),(0,Q.useEffect)(()=>{if(!i)return;function e(e){f.current&&!f.current.contains(e.target)&&a(!1)}function t(e){e.key===`Escape`&&a(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]);let p=e=>{n(e),a(!1),d(``)},m=/^\d{1,9}$/.test(u.trim())?parseInt(u.trim(),10):null;return(0,$.jsxs)(`div`,{ref:f,className:`relative inline-flex items-center`,onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-target-pr-selector`,title:r(`targetPr.chipTitle`),"aria-haspopup":`listbox`,"aria-expanded":i,onClick:()=>a(e=>!e),className:`inline-flex h-5 items-center gap-1 rounded border px-1 text-[10px] transition-colors focus:outline-none focus:ring-1 focus:ring-primary/40 ${t?`border-accent-info/50 text-accent-info hover:text-accent-info`:`border-border/50 bg-transparent text-muted-foreground hover:text-foreground`}`,children:[(0,$.jsx)(A,{className:`h-3 w-3`,"aria-hidden":!0}),t?`#${t.number}`:r(`targetPr.chipNew`)]}),t&&(0,$.jsx)(`button`,{type:`button`,"aria-label":r(`targetPr.clear`),onClick:()=>n(null),className:`ml-0.5 rounded p-0.5 text-muted-foreground hover:text-foreground`,children:(0,$.jsx)(Vn,{className:`h-2.5 w-2.5`,"aria-hidden":!0})}),i&&(0,$.jsxs)(`div`,{role:`listbox`,"aria-label":r(`targetPr.chipTitle`),className:`absolute left-0 top-6 z-50 w-72 rounded-lg border border-border bg-popover p-1.5 shadow-xl`,children:[(0,$.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":!t,onClick:()=>p(null),className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs text-foreground hover:bg-muted/60`,children:[(0,$.jsx)(A,{className:`h-3 w-3 text-muted-foreground`,"aria-hidden":!0}),r(`targetPr.newPr`)]}),(0,$.jsx)(`div`,{className:`my-1 border-t border-border/60`}),o&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 text-xs text-muted-foreground`,children:[(0,$.jsx)(An,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}),r(`targetPr.loading`)]}),!o&&c!==null&&c.length===0&&(0,$.jsx)(`div`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:r(`targetPr.none`)}),!o&&(c??[]).map(e=>(0,$.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t?.number===e.number,disabled:e.isCrossRepository,onClick:()=>p({number:e.number,title:e.title,headRefName:e.headRefName}),title:e.isCrossRepository?r(`targetPr.fork`):e.url,className:`flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-xs transition-colors ${e.isCrossRepository?`cursor-not-allowed text-muted-foreground/50`:`text-foreground hover:bg-muted/60`}`,children:[e.isCrossRepository?(0,$.jsx)(Os,{className:`mt-0.5 h-3 w-3 shrink-0`,"aria-hidden":!0}):(0,$.jsx)(A,{className:`mt-0.5 h-3 w-3 shrink-0 text-accent-info`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsxs)(`span`,{className:`block truncate font-medium`,children:[`#`,e.number,` · `,e.title]}),(0,$.jsxs)(`span`,{className:`block truncate text-[10px] text-muted-foreground`,children:[e.headRefName,e.isCrossRepository&&` — ${r(`targetPr.fork`)}`]})]})]},e.number)),(0,$.jsx)(`div`,{className:`my-1 border-t border-border/60`}),(0,$.jsxs)(`form`,{className:`flex items-center gap-1.5 px-1 py-1`,onSubmit:e=>{e.preventDefault(),m&&p({number:m})},children:[(0,$.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),inputMode:`numeric`,placeholder:r(`targetPr.manualPlaceholder`),"aria-label":r(`targetPr.manualPlaceholder`),className:`h-6 w-full rounded border border-border/60 bg-transparent px-1.5 text-xs text-foreground placeholder:text-muted-foreground/60 focus:outline-none focus:ring-1 focus:ring-primary/40`}),(0,$.jsx)(`button`,{type:`submit`,disabled:!m,className:`h-6 shrink-0 rounded border border-border/60 px-2 text-[10px] text-muted-foreground enabled:hover:text-foreground disabled:opacity-40`,children:r(`targetPr.manualUse`)})]})]})]})}function bU(e){return`rail-${e+1}`}function xU(e){let t=/^rail-(\d+)$/.exec(e);if(!t)return null;let n=parseInt(t[1],10);return!Number.isInteger(n)||n<1?null:n-1}var SU=800;function CU({id:e,label:t,tickets:n,mode:r,status:i,activeJobId:a,profileName:o,aiEngine:s,freestyleModel:c,loopModel:l,providers:u,loopAvailable:d,selectedLoopId:f,reasoningEffort:p,targetPr:m,worktreeSummary:h,prDecision:g,onPrDecision:_,onPrCheckout:v,executionMetric:y,jiggleMode:b,dragHandleListeners:x,dragHandleAttributes:S,density:C=`normal`,onModeChange:w,onProfileChange:T,onEngineChange:E,onFreestyleModelChange:D,onLoopModelChange:O,onLoopChange:k,onEffortChange:A,onTargetPrChange:j,onToggle:M,onTicketClick:N,onDelete:P,onLongPress:F,onRename:I,onTicketMoveToSpecs:L}){let{t:R}=K(`dashboard`),{activeProjectId:z}=pt(),B=xU(e),V=wt(s),H=(V?u?.[0]:s)??u?.[0]??`claude`,U=!V&&xt(H),W=!V&&bt(H),ee=!!E&&i!==`running`&&(u?.length??0)>1,te=!!T&&i!==`running`&&U&&r!==`loop`,ne=!!D&&i!==`running`&&r===`freestyle`&&W,re=!!O&&i!==`running`&&r===`loop`&&!V,ie=H,ae=Jx(ie),oe=l&&(ae.some(e=>e.value===l)||Nt(ie)&&nk(l))?l:Yx(ie),se=!V&&Et(H,oe),ce=V&&i!==`running`,le=ce?(0,$.jsxs)(`span`,{"data-testid":`rail-roles-chip`,title:R(`agents:railSelectors.rolesChipTitle`),className:`inline-flex items-center gap-1 h-5 px-1.5 text-[10px] rounded border border-accent-primary/40 bg-accent-primary/10 text-accent-primary whitespace-nowrap`,onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:[(0,$.jsx)(kn,{className:`w-3 h-3`}),R(`agents:railSelectors.rolesChip`)]}):null,ue=re&&O?(0,$.jsx)(mU,{provider:ie,value:oe,onChange:O,testId:`loop-model-selector`,ariaLabel:R(`railSelectors.loopModelTitle`)}):null,de=!!k&&i!==`running`,fe=ee||ne||re||de||ce,[G,pe]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!G)return;function e(e){e.target?.closest(`[role="menu"]`)||pe(null)}function t(e){e.key===`Escape`&&pe(null)}return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[G]);let{isOver:me,setNodeRef:he}=zR({id:e}),{active:ge}=IR(),_e=typeof ge?.id==`number`,[ve,ye]=(0,Q.useState)(0),[be,xe]=(0,Q.useState)(!1),[Se,Ce]=(0,Q.useState)(!1),[we,Te]=(0,Q.useState)(!1),[Ee,De]=(0,Q.useState)(``),Oe=(0,Q.useRef)(null),ke=(0,Q.useRef)(null),Ae=(0,Q.useRef)(null),je=(0,Q.useRef)(!1),Me=i===`running`,Ne=!Me,Pe=(0,Q.useCallback)(()=>{Ae.current&&=(clearTimeout(Ae.current),null)},[]),Fe=(0,Q.useCallback)(()=>{Ne&&(je.current=!1,Ae.current=setTimeout(()=>{je.current=!0,F(),Ae.current=null},SU))},[Ne,F]),Ie=(0,Q.useCallback)(e=>{let t=e.touches[0];ke.current={x:t.clientX,y:t.clientY},xe(!1),Ce(!1),Fe()},[Fe]),Le=(0,Q.useCallback)(e=>{if(!ke.current)return;let t=e.touches[0],n=t.clientX-ke.current.x,r=t.clientY-ke.current.y;(Math.abs(n)>10||Math.abs(r)>10)&&Pe(),Ne&&n<-10&&Math.abs(n)>Math.abs(r)*1.5&&(xe(!0),ye(Math.max(n,-150)))},[Ne,Pe]),Re=(0,Q.useCallback)(()=>{Pe(),be&&(ve<-60&&Ne?(Ce(!0),ye(-80)):(ye(0),Ce(!1)),xe(!1)),ke.current=null},[ve,be,Ne,Pe]),ze=(0,Q.useCallback)(e=>{e.target.closest(`button`)||Fe()},[Fe]),Be=(0,Q.useCallback)(()=>{Pe()},[Pe]),Ve=(0,Q.useCallback)(e=>{if(je.current){e.stopPropagation(),je.current=!1;return}Se&&(Ce(!1),ye(0))},[Se]),He=(0,Q.useCallback)(e=>{e.stopPropagation(),Ce(!1),ye(0),P()},[P]),Ue=b&&Ne?-(Array.from(e).reduce((e,t)=>e+t.charCodeAt(0),0)*53%400):void 0,We=Ue===void 0?void 0:{animationDelay:`${Ue}ms`};return C===`compact`?(0,$.jsxs)(`div`,{ref:he,"data-testid":`rail-row-compact-${e}`,"data-density":`compact`,onMouseDown:ze,onMouseUp:Be,onMouseLeave:Be,onClick:Ve,style:We,className:`group relative flex flex-col gap-1.5 rounded-xl border bg-card p-2.5 transition-all ${me?`border-accent-info/60 shadow-[0_0_0_1px_hsl(var(--accent-info)/0.35),0_0_14px_hsl(var(--accent-info)/0.18)]`:_e?`border-dashed border-accent-info/35`:Me?`border-accent-success/40 shadow-sm`:`border-border/40 hover:border-accent-info/30 hover:shadow-md`} ${b&&Ne?`animate-jiggle`:``}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,$.jsx)(`button`,{type:`button`,className:`touch-none cursor-grab active:cursor-grabbing text-muted-foreground/30 hover:text-muted-foreground/70 transition-colors shrink-0`,...x,...S,children:(0,$.jsx)(Ms,{className:`w-3 h-3`})}),(0,$.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full shrink-0 transition-all duration-300 ${Me?`bg-accent-success shadow-[0_0_4px_hsl(var(--accent-success)/0.8)] animate-pulse`:i===`failed`?`bg-accent-warning shadow-[0_0_4px_hsl(var(--accent-warning)/0.6)]`:`bg-muted-foreground/25`}`,"aria-hidden":!0}),we?(0,$.jsx)(`form`,{className:`flex items-center gap-0.5 min-w-0 flex-1`,onSubmit:e=>{e.preventDefault();let t=Ee.trim();t&&I(t),Te(!1)},children:(0,$.jsx)(`input`,{ref:Oe,type:`text`,value:Ee,onChange:e=>De(e.target.value),onBlur:()=>{let e=Ee.trim();e&&I(e),Te(!1)},onKeyDown:e=>{e.key===`Escape`&&Te(!1)},className:`flex-1 min-w-0 text-xs font-medium bg-transparent border-b border-accent-info/60 outline-none text-foreground/90 px-0.5`,autoFocus:!0})}):(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation();let n=t.startsWith(`Rail `)?t.slice(5):t;De(n),Te(!0),setTimeout(()=>Oe.current?.select(),0)},className:`flex-1 min-w-0 text-left text-xs font-medium text-foreground/90 hover:text-foreground truncate`,title:t,children:t})]}),n.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,"data-testid":`rail-row-compact-tickets-${e}`,children:n.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),N(e)},onMouseDown:t=>{t.button===2&&L&&(t.preventDefault(),t.stopPropagation(),pe({ticketId:e.id,x:t.clientX,y:t.clientY}))},onContextMenu:e=>{L&&(e.preventDefault(),e.stopPropagation())},onPointerDown:e=>e.stopPropagation(),title:`#${e.id} ${e.title}`,className:`inline-flex items-center px-1.5 py-0.5 rounded-md text-[10px] font-mono font-medium border border-accent-info/30 bg-accent-info/10 text-accent-info hover:bg-accent-info/20 hover:border-accent-info/60 transition-colors`,children:[`#`,e.id]},e.id))}),G&&L&&(0,Hb.createPortal)((0,$.jsx)(`div`,{role:`menu`,"data-testid":`rail-row-compact-context-menu-${e}`,className:`fixed z-[200] min-w-[160px] rounded-lg border border-border/60 bg-card/95 backdrop-blur shadow-xl shadow-black/40 p-1`,style:{top:Math.min(G.y,window.innerHeight-60),left:Math.min(G.x,window.innerWidth-180)},onPointerDown:e=>e.stopPropagation(),children:(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:e=>{e.stopPropagation(),L(G.ticketId),pe(null)},className:`w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left text-xs text-accent-warning hover:bg-accent-warning/10 transition-colors`,children:[(0,$.jsx)(un,{className:`w-3 h-3`,"aria-hidden":!0}),R(`railRow.moveToSpecs`)]})}),document.body),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[E&&!Me&&(0,$.jsx)(pU,{value:s??null,providers:u??[],onChange:E}),le,T&&!Me&&U&&r!==`loop`&&(0,$.jsx)(fU,{provider:H,value:o??null,onChange:T}),D&&!Me&&r===`freestyle`&&W&&(0,$.jsx)(mU,{provider:H,value:c??null,onChange:D}),ue,k&&!Me&&(0,$.jsx)(hU,{value:nS(f,r),onChange:k,freestyleAvailable:W,loopsEnabled:d}),A&&!Me&&r===`loop`&&se&&(0,$.jsx)(_U,{provider:H,model:oe,value:p??null,onChange:A}),j&&!Me&&B!==null&&(0,$.jsx)(yU,{railIndex:B,value:m??null,onChange:j}),(0,$.jsx)(uU,{mode:r,status:i,activeJobId:a,ticketCount:n.length,freestyleAvailable:W,loopAvailable:d,onModeChange:w,onToggle:M})]}),Me&&y&&(0,$.jsx)(gU,{metric:y}),h&&(h.merged>0||h.needsReview>0)&&(0,$.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-[10px]`,"data-testid":`rail-worktree-summary`,children:[h.merged>0&&(0,$.jsx)(`span`,{className:`text-accent-success`,children:R(`railControls.worktreesMerged`,{count:h.merged})}),h.needsReview>0&&(0,$.jsx)(`span`,{className:`text-accent-warning`,children:R(`railControls.worktreesNeedsReview`,{count:h.needsReview})})]}),z&&B!==null&&(0,$.jsx)(lU,{projectId:z,railIndex:B,contextual:!0}),g&&_&&(0,$.jsx)(`div`,{className:`mt-1`,children:(0,$.jsx)(vU,{decision:g,density:`compact`,act:_,checkout:v},g.prDeliveryId)}),b&&Ne&&(0,$.jsx)(`button`,{type:`button`,onClick:He,className:`absolute -top-1 -right-1 w-5 h-5 flex items-center justify-center rounded-full bg-destructive text-destructive-foreground shadow-sm hover:opacity-90 transition-opacity`,"aria-label":R(`railRow.deleteRail`,{label:t}),children:(0,$.jsx)(Rn,{className:`w-3 h-3`})})]}):(0,$.jsxs)(`div`,{className:`relative overflow-hidden rounded-xl`,onClick:Ve,onTouchStart:Ie,onTouchMove:Le,onTouchEnd:Re,onMouseDown:ze,onMouseUp:Be,onMouseLeave:Be,children:[Ne&&(Se||ve<0)&&(0,$.jsx)(`div`,{className:`absolute inset-y-0 right-0 w-20 flex items-center justify-center bg-red-500/90 rounded-r-xl z-0`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:He,className:`flex flex-col items-center gap-1 text-white`,children:[(0,$.jsx)(Rn,{className:`w-5 h-5`}),(0,$.jsx)(`span`,{className:`text-[9px] font-medium`,children:R(`common:actions.delete`)})]})}),(0,$.jsxs)(`div`,{className:`relative z-10 flex flex-col rounded-xl border overflow-hidden bg-card ${b&&Ne?`animate-jiggle`:``} ${me?`border-primary/50 shadow-[0_0_0_1px_hsl(var(--primary)/0.25),0_0_12px_hsl(var(--primary)/0.08)]`:`border-border/40 hover:border-border/60`}`,style:{transform:ve<0?`translateX(${ve}px)`:void 0,transition:be?`none`:`transform 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)`,...Ue===void 0?{}:{animationDelay:`${Ue}ms`}},children:[(0,$.jsxs)(`div`,{className:`flex flex-col border-b border-border/30 bg-gradient-to-r from-muted/30 to-transparent shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,$.jsx)(`button`,{type:`button`,className:`touch-none cursor-grab active:cursor-grabbing text-muted-foreground/30 hover:text-muted-foreground/60 transition-colors -ml-1`,...x,...S,children:(0,$.jsx)(Ms,{className:`w-3.5 h-3.5`})}),(0,$.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full shrink-0 transition-all duration-300 ${i===`running`?`bg-emerald-400 shadow-[0_0_4px_hsl(142_70%_56%/0.8)] animate-pulse`:i===`failed`?`bg-amber-400 shadow-[0_0_4px_hsl(38_92%_50%/0.6)]`:`bg-muted-foreground/25`}`}),we?(0,$.jsxs)(`form`,{className:`flex items-center gap-0.5`,onSubmit:e=>{e.preventDefault();let t=Ee.trim();t&&I(t),Te(!1)},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-foreground/50`,children:`Rail `}),(0,$.jsx)(`input`,{ref:Oe,type:`text`,value:Ee,onChange:e=>De(e.target.value),onBlur:()=>{let e=Ee.trim();e&&I(e),Te(!1)},onKeyDown:e=>{e.key===`Escape`&&Te(!1)},className:`w-24 text-xs font-medium bg-transparent border-b border-primary/50 outline-none text-foreground/80 px-0.5`,autoFocus:!0})]}):(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation();let n=t.startsWith(`Rail `)?t.slice(5):t;De(n),Te(!0),setTimeout(()=>Oe.current?.select(),0)},className:`text-xs font-medium text-foreground/80 hover:text-foreground hover:underline decoration-dotted underline-offset-2 cursor-text transition-colors`,children:t}),n.length>0&&(0,$.jsx)(`span`,{className:`text-[9px] text-muted-foreground bg-muted/30 rounded-full px-1.5 py-0.5 leading-none`,children:n.length})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[!fe&&te&&T&&(0,$.jsx)(fU,{provider:H,value:o??null,onChange:T}),(0,$.jsx)(uU,{mode:r,status:i,activeJobId:a,ticketCount:n.length,freestyleAvailable:W,loopAvailable:d,onModeChange:w,onToggle:M}),b&&Ne&&(0,$.jsx)(`button`,{type:`button`,onClick:He,className:`w-5 h-5 flex items-center justify-center rounded-full bg-red-500 text-white shadow-sm hover:bg-red-600 transition-colors`,children:(0,$.jsx)(Rn,{className:`w-3 h-3`})})]})]}),Me&&y&&(0,$.jsx)(`div`,{className:`px-3 pb-1`,children:(0,$.jsx)(gU,{metric:y})}),h&&(h.merged>0||h.needsReview>0)&&(0,$.jsxs)(`div`,{className:`px-3 pb-1 flex items-center gap-2 text-[10px]`,children:[h.merged>0&&(0,$.jsx)(`span`,{className:`text-accent-success`,children:R(`railControls.worktreesMerged`,{count:h.merged})}),h.needsReview>0&&(0,$.jsx)(`span`,{className:`text-accent-warning`,children:R(`railControls.worktreesNeedsReview`,{count:h.needsReview})})]}),z&&B!==null&&(0,$.jsx)(lU,{projectId:z,railIndex:B,contextual:!0}),g&&_&&(0,$.jsx)(`div`,{className:`px-3 pb-1.5`,children:(0,$.jsx)(vU,{decision:g,density:`normal`,act:_,checkout:v},g.prDeliveryId)}),fe&&(0,$.jsxs)(`div`,{className:`flex items-center flex-wrap gap-x-3 gap-y-1 px-3 py-1.5 border-t border-border/20 bg-background/20`,children:[ee&&E&&(0,$.jsx)(pU,{value:s??null,providers:u??[],onChange:E}),le,fe&&te&&T&&(0,$.jsx)(fU,{provider:H,value:o??null,onChange:T}),ne&&D&&(0,$.jsx)(mU,{provider:H,value:c??null,onChange:D}),ue,de&&k&&(0,$.jsx)(hU,{value:nS(f,r),onChange:k,freestyleAvailable:W,loopsEnabled:d}),r===`loop`&&!Me&&se&&A&&(0,$.jsx)(_U,{provider:H,model:oe,value:p??null,onChange:A}),j&&!Me&&B!==null&&(0,$.jsx)(yU,{railIndex:B,value:m??null,onChange:j})]})]}),(0,$.jsx)(`div`,{ref:he,"data-drop-target":_e?`available`:void 0,className:`min-h-[56px] px-3 py-2 space-y-1.5 transition-colors duration-150 ${me?`bg-accent-info/[0.06]`:_e?`bg-accent-info/[0.02]`:`bg-card/20`}`,children:n.length===0?(0,$.jsx)(`div`,{className:`h-10 flex items-center justify-center rounded-lg border border-dashed transition-all duration-150 ${me?`border-accent-info/60 text-accent-info/80 bg-accent-info/[0.06]`:_e?`border-accent-info/35 text-accent-info/60`:`border-border/25 text-muted-foreground/30`}`,children:(0,$.jsx)(`span`,{className:`text-[10px] select-none`,children:R(me?`railRow.dropHere`:_e?`railRow.dropOnThisRail`:`railRow.dragSpecsHere`)})}):(0,$.jsx)(lz,{items:n.map(e=>e.id),strategy:az,children:n.map(e=>(0,$.jsx)(`div`,{onMouseDown:t=>{t.button===2&&L&&(t.preventDefault(),t.stopPropagation(),pe({ticketId:e.id,x:t.clientX,y:t.clientY}))},onContextMenu:e=>{L&&(e.preventDefault(),e.stopPropagation())},children:(0,$.jsx)(Oz,{ticket:e,onClick:N,dragDisabled:i===`running`})},e.id))})}),G&&L&&C===`normal`&&(0,Hb.createPortal)((0,$.jsx)(`div`,{role:`menu`,"data-testid":`rail-row-normal-context-menu-${e}`,className:`fixed z-[200] min-w-[160px] rounded-lg border border-border/60 bg-card/95 backdrop-blur shadow-xl shadow-black/40 p-1`,style:{top:Math.min(G.y,window.innerHeight-60),left:Math.min(G.x,window.innerWidth-180)},onPointerDown:e=>e.stopPropagation(),children:(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:e=>{e.stopPropagation(),L(G.ticketId),pe(null)},className:`w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left text-xs text-accent-warning hover:bg-accent-warning/10 transition-colors`,children:[(0,$.jsx)(un,{className:`w-3 h-3`,"aria-hidden":!0}),R(`railRow.moveToSpecs`)]})}),document.body)]})]})}function wU(e,t,n,r){return{...e,[t]:{...e[t]??{},[n]:r}}}function TU(e){if(!e)return null;let t=Object.values(e);if(t.length===0)return null;let n=0,r=0,i=0;for(let e of t)e===`merged`?n++:e===`needs-review`?r++:e===`failed`&&i++;return{merged:n,needsReview:r,failed:i,reported:t.length}}var EU=`__rail:`;function DU(e){return`${EU}${e}`}function OU(e){return typeof e==`string`&&e.startsWith(`__rail:`)}function kU(e){return e.slice(7)}function AU(e,t,n){let r=new Set(n),i=bU(t),a=e.some(e=>e.id===i);return e.map((e,n)=>(a?e.id===i:n===t)?{...e,status:`idle`,activeJobId:void 0,ticketIds:r.size>0?e.ticketIds.filter(e=>!r.has(e)):[]}:e)}function jU({railId:e,children:t}){let{attributes:n,listeners:r,setNodeRef:i,transform:a,transition:o,isDragging:s}=_z({id:DU(e)});return(0,$.jsx)(`div`,{ref:i,style:{transform:pI.Translate.toString(a),transition:o,opacity:s?.4:void 0,position:`relative`,zIndex:s?50:void 0},children:t({listeners:r??{},attributes:n,isDragging:s})})}function MU({rails:e,ticketMap:t,railWorktrees:n,railMetrics:r,railPrDecisions:i,onPrDecision:a,onPrCheckout:o,providers:s,onModeChange:c,onProfileChange:l,onEngineChange:u,onFreestyleModelChange:d,onLoopModelChange:f,loopAvailable:p,onLoopChange:m,onEffortChange:h,onTargetPrChange:g,onToggle:_,onTicketClick:v,onAddRail:y,onDeleteRail:b,onRenameRail:x,onTicketMoveToSpecs:S,onLaunchAll:C,launchAllCount:w}){let{t:T}=K(`dashboard`),E=e.filter(e=>e.status===`running`).length,[D,O]=(0,Q.useState)(!1),k=(0,Q.useRef)(null),[A,j]=(0,Q.useState)(`normal`);(0,Q.useEffect)(()=>{if(typeof ResizeObserver>`u`)return;let e=k.current;if(!e)return;let t=new ResizeObserver(e=>{for(let t of e){let e=t.contentRect.width;j(e<320?`compact`:`normal`)}});return t.observe(e),()=>t.disconnect()},[]);let M=(0,Q.useCallback)(()=>{D&&O(!1)},[D]);(0,Q.useEffect)(()=>{if(!D)return;let e=e=>{e.key===`Escape`&&O(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[D]);let N=e.map(e=>DU(e.id));return(0,$.jsxs)(`div`,{ref:k,className:`flex flex-col h-full`,"data-density":A,onClick:M,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 h-12 border-b border-border/40 shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(kn,{className:`w-4 h-4 text-muted-foreground`}),(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-accent-secondary`,children:T(`railsBoard.title`)}),E>0&&(0,$.jsx)(`span`,{className:`text-[10px] text-emerald-400 aurora-light:text-accent-success bg-emerald-400/10 aurora-light:bg-accent-success/10 rounded-full px-1.5 py-0.5 font-medium whitespace-nowrap`,children:T(`railsBoard.runningCount`,{count:E})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[C&&(0,$.jsxs)(`button`,{type:`button`,disabled:(w??0)===0,onClick:e=>{e.stopPropagation(),C()},title:T(`railsBoard.launchAllTitle`),className:`flex items-center gap-1.5 h-7 px-2.5 text-xs font-semibold rounded-md border border-emerald-400/50 text-emerald-400 aurora-light:text-accent-success aurora-light:border-accent-success/50 bg-gradient-to-r from-emerald-400/10 to-accent-primary/10 hover:from-emerald-400/20 hover:to-accent-primary/20 transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:from-emerald-400/10 disabled:hover:to-accent-primary/10`,children:[(0,$.jsx)(gc,{className:`w-3.5 h-3.5`}),T(`railsBoard.launchAll`),(w??0)>0&&(0,$.jsx)(`span`,{className:`text-[10px] font-mono rounded-full bg-emerald-400/15 px-1.5 py-0.5 leading-none`,children:w})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),y()},className:`flex items-center gap-1 h-7 px-2.5 text-xs font-medium rounded-md border border-accent-primary/50 text-accent-primary hover:bg-accent-primary/10 transition-colors`,children:[(0,$.jsx)(Pn,{className:`w-3.5 h-3.5`}),T(`common:actions.add`)]})]})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto px-4 py-3 flex flex-col gap-2.5`,children:(0,$.jsx)(lz,{items:N,strategy:az,children:e.map((e,y)=>{let C=xU(e.id)??y;return(0,$.jsx)(jU,{railId:e.id,children:({listeners:w,attributes:T})=>(0,$.jsx)(`div`,{"data-tour":y===0?`rail-1`:void 0,children:(0,$.jsx)(CU,{id:e.id,label:e.label,tickets:e.ticketIds.map(e=>t.get(e)).filter(e=>e!==void 0),mode:e.mode,status:e.status,activeJobId:e.activeJobId,profileName:e.profileName??null,aiEngine:e.aiEngine??null,freestyleModel:e.freestyleModel??null,loopModel:e.loopModel??null,worktreeSummary:TU(n?.[C]),prDecision:i?.get(C)??null,onPrDecision:a?(e,t,n,r)=>a(C,e,t,n,r):void 0,onPrCheckout:o?(e,t)=>o(C,e,t):void 0,executionMetric:r?.[C]??null,providers:s,loopAvailable:p,selectedLoopId:e.selectedLoopId??null,reasoningEffort:e.reasoningEffort??null,targetPr:e.targetPr??null,jiggleMode:D,density:A,dragHandleListeners:w,dragHandleAttributes:T,onModeChange:t=>c(e.id,t),onProfileChange:l?t=>l(e.id,t):void 0,onEngineChange:u?t=>u(e.id,t):void 0,onFreestyleModelChange:d?t=>d(e.id,t):void 0,onLoopModelChange:f?t=>f(e.id,t):void 0,onLoopChange:m?t=>m(e.id,t):void 0,onEffortChange:h?t=>h(e.id,t):void 0,onTargetPrChange:g?t=>g(e.id,t):void 0,onToggle:()=>_(e.id),onTicketClick:v,onDelete:()=>b(e.id),onLongPress:()=>O(!0),onRename:t=>x(e.id,t),onTicketMoveToSpecs:S})})},e.id)})})})]})}var NU=new Set([`editing`,`writing`,`reading`,`searching`,`running`]);function PU(e){return e.length>40?`${e.slice(0,39)}…`:e}function FU(e){return typeof e!=`string`||e.length===0?``:PU(e.replace(/\\/g,`/`).split(`/`).filter(Boolean).pop()??``)}function IU(e){return typeof e!=`string`||e.length===0?``:PU((e.trim().split(/\s+/)[0]??``).replace(/^['"`]+/,``))}var LU=/(^|\/)(ba|z|k|da|fi)?sh$/;function RU(e){if(e.length===0||!LU.test(e[0]))return e;let t=e.slice(1).filter(e=>!e.startsWith(`-`));return t.length>0?t:e}function zU(e){return Array.isArray(e)?IU(RU(e.filter(e=>typeof e==`string`)).join(` `)):typeof e!=`string`||e.length===0?``:IU(RU(e.trim().split(/\s+/)).join(` `))}function BU(e){return Array.isArray(e)?RU(e.filter(e=>typeof e==`string`)).join(` `).trim():typeof e!=`string`||e.length===0?``:RU(e.trim().split(/\s+/)).join(` `).trim()}function VU(e){if(typeof e!=`string`)return``;try{let t=JSON.parse(e)?.command;if(Array.isArray(t)||typeof t==`string`)return zU(t)}catch{}return``}function HU(e){let t=e.toLowerCase();return[`read_file`,`read_many_files`,`readfile`,`view`].includes(t)?`read`:[`write_file`,`writefile`].includes(t)?`write`:[`replace`,`edit_file`,`apply_patch`,`file_change`,`str_replace`].includes(t)?`edit`:[`grep_search`,`list_directory`,`list_files`,`glob`,`find`].includes(t)?`search`:[`run_shell_command`,`shell`,`command_execution`,`local_shell_call`,`bash`,`terminal`].includes(t)?`bash`:e}function UU(e,t){let n=t??{},r=FU(n.file_path??n.path);switch(typeof e==`string`?e.toLowerCase():``){case`edit`:case`multiedit`:case`notebookedit`:case`update`:case`editfile`:case`strreplace`:case`searchreplace`:return{step:!0,actionKey:`editing`,actionArg:r};case`write`:case`create`:case`writefile`:return{step:!0,actionKey:`writing`,actionArg:r};case`read`:case`readfile`:case`readmediafile`:return{step:!0,actionKey:`reading`,actionArg:r};case`grep`:case`glob`:case`search`:case`websearch`:return{step:!0,actionKey:`searching`,actionArg:PU(String(n.pattern??n.query??``))};case`bash`:case`shell`:return{step:!0,actionKey:`running`,actionArg:zU(n.command)};case`task`:return{step:!0,actionKey:`delegating`,actionArg:PU(String(n.subagent_type??n.description??``).replace(/^sr-/,``))};default:return{step:!0,actionKey:`working`}}}function WU(e){if(e&&typeof e==`object`&&!Array.isArray(e))return e;if(typeof e==`string`)try{let t=JSON.parse(e);return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}catch{return}}function GU(e){let t=e.event_type,n={};try{let t=JSON.parse(e.payload);t&&typeof t==`object`&&!Array.isArray(t)&&(n=t)}catch{}if(t===`assistant`){let e=n.message?.content;if(Array.isArray(e)){let t=e.filter(e=>e?.type===`tool_use`);if(t.length>0){let e=t[t.length-1];return{...UU(e.name,e.input),stepCount:t.length}}if(e.some(e=>e?.type===`text`))return{step:!0,actionKey:`thinking`}}let t=(Array.isArray(n.tool_calls)?n.tool_calls:[]).flatMap(e=>{if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e.function;return!t||typeof t!=`object`||Array.isArray(t)?[]:[t]});if(t.length>0){let e=t[t.length-1];return{...UU(e.name,WU(e.arguments)),stepCount:t.length}}return typeof n.content==`string`||Array.isArray(n.content)&&n.content.length>0?{step:!0,actionKey:`thinking`}:{step:!0}}if(t===`tool_use`)return UU(n.name,n.input);if(t===`agent-event`){let e=n.event;if(e?.kind===`tool-start`&&typeof e.tool==`string`){let t=typeof e.detail==`string`?e.detail:void 0,n=e.tool.toLowerCase(),r=t===void 0?{}:[`bash`,`shell`].includes(n)?{command:t}:[`grep`,`glob`,`search`,`grep_search`,`websearch`].includes(n)?{pattern:t}:{file_path:t};return UU(HU(e.tool),r)}return e?.kind===`text`&&typeof e.text==`string`&&e.text.trim()?{step:!0,actionKey:`thinking`}:{step:!1}}if(t===`item.completed`){let e=n.item,t=e?.type;return t===`agent_message`?{step:!0,actionKey:`thinking`}:t===`agent_reasoning`?{step:!0,actionKey:`reasoning`}:t===`function_call`||t===`local_shell_call`||t===`command_execution`?{step:!0,actionKey:`running`,actionArg:zU(e?.command)||VU(e?.arguments)||(typeof e?.name==`string`?PU(e.name):``)||(t===`local_shell_call`?`shell`:``)}:{step:!0}}return{step:!1}}function KU(e){let t={};try{let n=JSON.parse(e.payload);n&&typeof n==`object`&&!Array.isArray(n)&&(t=n)}catch{return``}if(e.event_type===`assistant`){let e=t.message?.content;if(!Array.isArray(e))return``;for(let t of e){if(t?.type!==`tool_use`)continue;let e=t.input?.command;if(e)return BU(e)}return``}if(e.event_type===`agent-event`){let e=t.event;return e?.kind===`tool-start`&&typeof e.tool==`string`&&HU(e.tool)===`bash`&&typeof e.detail==`string`?BU(e.detail):``}if(e.event_type===`item.completed`){let e=t.item;if(!e)return``;if(e.command)return BU(e.command);if(typeof e.arguments==`string`)try{let t=JSON.parse(e.arguments);if(t?.command)return BU(t.command)}catch{return``}}return``}var qU=(0,Q.createContext)({});function JU(){return(0,Q.useContext)(qU)}function YU({activeProjectId:e,children:t}){let[n,r]=(0,Q.useState)(new Map),{registerHandler:i,unregisterHandler:a}=tt(),o=(0,Q.useRef)(e);(0,Q.useEffect)(()=>{o.current=e},[e]),(0,Q.useEffect)(()=>{if(r(new Map),!e)return;let t=!1;return fetch(`/api/projects/${e}/rails`).then(e=>e.ok?e.json():null).then(e=>{if(t||!e?.activeLoopRuns)return;let n=new Map;for(let[t,r]of Object.entries(e.activeLoopRuns))r?.loopRunId&&n.set(r.loopRunId,{railIndex:Number(t),startedAt:r.startedAt?new Date(r.startedAt).getTime():Date.now(),steps:r.steps??0,lines:r.lines??0});n.size!==0&&r(e=>{let t=new Map(e);for(let[e,r]of n)t.has(e)||t.set(e,r);return t})}).catch(()=>{}),()=>{t=!0}},[e]);let s=(0,Q.useCallback)(e=>{let t=e;if(!(!t||typeof t.type!=`string`)){if(t.type===`loop.run_started`){if(t.projectId!==o.current||!t.loopRunId)return;r(e=>{let n=new Map(e);return n.set(t.loopRunId,{railIndex:t.railIndex??0,startedAt:Date.now(),steps:0,lines:0}),n});return}if(t.type===`loop.run_completed`){r(e=>{if(!t.loopRunId||!e.has(t.loopRunId))return e;let n=new Map(e);return n.delete(t.loopRunId),n});return}if(t.type===`rail.job_started`){if(t.projectId!==o.current||!t.jobId||t.railIndex==null)return;r(e=>{let n=new Map(e);return n.set(t.jobId,{railIndex:t.railIndex,startedAt:Date.now(),steps:0,lines:0}),n});return}if(t.type===`rail.job_completed`||t.type===`rail.job_stopped`){r(e=>{if(!t.jobId||!e.has(t.jobId))return e;let n=new Map(e);return n.delete(t.jobId),n});return}if(t.type===`event`&&t.event_type&&t.jobId){let e=GU({event_type:t.event_type,payload:t.payload??``});if(!e.step)return;r(n=>{let r=n.get(t.jobId);if(!r)return n;let i=new Map(n);return i.set(t.jobId,{...r,steps:r.steps+(e.stepCount??1)}),i});return}t.type===`log`&&t.processId&&r(e=>{let n=e.get(t.processId);if(!n)return e;let r=new Map(e);return r.set(t.processId,{...n,lines:n.lines+1}),r})}},[]);(0,Q.useLayoutEffect)(()=>(i(`rail-exec-metrics`,s),()=>a(`rail-exec-metrics`)),[s,i,a]);let c=(0,Q.useMemo)(()=>{let e={};for(let t of n.values()){let n=e[t.railIndex];n?(n.startedAt=Math.min(n.startedAt,t.startedAt),n.steps+=t.steps,n.lines+=t.lines):e[t.railIndex]={startedAt:t.startedAt,steps:t.steps,lines:t.lines}}return e},[n]);return(0,$.jsx)(qU.Provider,{value:c,children:t})}var XU=(0,Q.createContext)({decisions:new Map,hydrated:!0,act:async()=>({status:0,ok:!1,error:`no_provider`}),checkout:async()=>({status:0,ok:!1,error:`no_provider`})});function ZU(){return(0,Q.useContext)(XU)}function QU(e,t){return sn(e,t)}var $U=new Set([`merged`,`discarded`,`completed`,`superseded`]),eW=new Set([`create-pr`,`publish`,`discard`,`poll-merge`,`merge-local`,`dismiss`,`reopen`,`acknowledge-no-changes`,`recover-and-retry`]);function tW(e,t){return JSON.stringify(e)===JSON.stringify(t)}function nW({activeProjectId:e,children:t}){let{t:n}=K(`dashboard`),[r,i]=(0,Q.useState)(new Map),[a,o]=(0,Q.useState)(!1),{registerHandler:s,unregisterHandler:c,connectionStatus:l}=tt(),u=(0,Q.useRef)(e);(0,Q.useEffect)(()=>{u.current=e},[e]);let d=(0,Q.useRef)(r),f=(0,Q.useRef)(new Map),p=(0,Q.useRef)(0),m=(0,Q.useRef)(new Set),h=(0,Q.useRef)(new Map),g=(0,Q.useRef)(new Set),_=(0,Q.useRef)(new Map),v=(0,Q.useCallback)((e,t=!0)=>{let r=d.current,a=r.get(e.railIndex),o=$U.has(e.decision),s=e.restoredFromDeliveryId??null,c=h.current.get(e.prDeliveryId),l=a?.supersedesDeliveryId===e.prDeliveryId?a.prDeliveryId:null,u=!!(s&&_.current.get(e.prDeliveryId)!==s&&(!c||c===s)&&(!l||l===s));if(a?.prDeliveryId===e.prDeliveryId){let t=zt(a.updatedAt,e.updatedAt);if(t===-1||t===0&&!tW(a,e))return`stale`;if(t===0&&tW(a,e))return`accepted`}if(!o&&(g.current.has(e.prDeliveryId)||m.current.has(e.prDeliveryId))&&!u)return`stale`;let p=!1;if(a&&a.prDeliveryId!==e.prDeliveryId)if(u&&a.prDeliveryId===s)p=!0;else{let t=e.supersedesDeliveryId===a.prDeliveryId,n=a.supersedesDeliveryId===e.prDeliveryId||m.current.has(e.prDeliveryId),r=e.createdAt?Date.parse(e.createdAt):NaN,i=a.createdAt?Date.parse(a.createdAt):NaN;if(n||!t&&!(Number.isFinite(r)&&Number.isFinite(i)&&r>i))return o&&g.current.add(e.prDeliveryId),e.decision===`superseded`&&m.current.add(e.prDeliveryId),o?`untracked`:`stale`;p=!0}if(u&&s&&(g.current.delete(e.prDeliveryId),m.current.delete(e.prDeliveryId),g.current.add(s),_.current.set(e.prDeliveryId,s),h.current.set(e.prDeliveryId,s)),o){if(g.current.add(e.prDeliveryId),e.decision===`superseded`&&m.current.add(e.prDeliveryId),!a||a.prDeliveryId!==e.prDeliveryId)return`untracked`;if(t){if(e.safetyArchives?.length){let t=e.safetyArchives.join(`
|
|
73
73
|
`);J.warning(n(`railPr.safetyArchiveTitle`,{count:e.safetyArchives.length}),{description:`${n(`railPr.safetyArchiveHint`)}\n${t}`,duration:1/0,action:{label:n(`railPr.copySafetyArchive`),onClick:()=>{navigator.clipboard?.writeText(t)}}})}if(e.cleanupWarnings?.length){let t=e.cleanupWarnings.join(`
|
|
74
|
-
`);J.warning(n(`railPr.cleanupIncomplete`,{count:e.cleanupWarnings.length}),{description:`${n(`railPr.cleanupIncompleteHint`)}\n${t}`,duration:1/0,action:{label:n(`railPr.copyCleanupDetails`),onClick:()=>{navigator.clipboard?.writeText(t)}}})}else e.decision===`merged`?J.success(n(`railPr.mergedToast`)):e.decision===`discarded`?J.info(n(`railPr.discardedToast`)):e.decision===`completed`&&J.success(n(`railPr.completedToast`))}}else e.supersedesDeliveryId&&(m.current.add(e.supersedesDeliveryId),h.current.set(e.supersedesDeliveryId,e.prDeliveryId)),p&&a&&m.current.add(a.prDeliveryId);let v=new Map(r);return o?v.delete(e.railIndex):v.set(e.railIndex,e),f.current.set(e.railIndex,(f.current.get(e.railIndex)??0)+1),d.current=v,i(v),`accepted`},[n]),y=(0,Q.useCallback)(async(e,t)=>{let n=++p.current,r=new Map(f.current);try{let t=await fetch(`/api/projects/${e}/rails`);if(!t.ok)return;let a=await t.json();if(n!==p.current||u.current!==e)return;let o=new Map;for(let[e,t]of Object.entries(a.prDeliveries??{})){let n=QU(t,Number(e)),r=d.current.get(n?.railIndex??Number(e)),i=n?.restoredFromDeliveryId??null,a=n?h.current.get(n.prDeliveryId):void 0,s=n&&r?.supersedesDeliveryId===n.prDeliveryId?r.prDeliveryId:null,c=!!(n&&i&&_.current.get(n.prDeliveryId)!==i&&(!a||a===i)&&(!s||s===i));n&&!$U.has(n.decision)&&(c||!g.current.has(n.prDeliveryId)&&!m.current.has(n.prDeliveryId))&&o.set(Number(e),n)}let s=d.current,c=new Map(o);for(let[e,t]of f.current){if(t===(r.get(e)??0))continue;let n=s.get(e);n?c.set(e,n):c.delete(e)}for(let e of c.values()){e.supersedesDeliveryId&&(m.current.add(e.supersedesDeliveryId),h.current.set(e.supersedesDeliveryId,e.prDeliveryId));let t=e.restoredFromDeliveryId;t&&_.current.get(e.prDeliveryId)!==t&&(!h.current.get(e.prDeliveryId)||h.current.get(e.prDeliveryId)===t)&&(g.current.delete(e.prDeliveryId),m.current.delete(e.prDeliveryId),g.current.add(t),_.current.set(e.prDeliveryId,t),h.current.set(e.prDeliveryId,t))}d.current=c,i(c)}catch{}finally{t&&n===p.current&&u.current===e&&o(!0)}},[]);(0,Q.useEffect)(()=>{u.current=e,p.current++;let t=new Map;if(d.current=t,i(t),o(!1),f.current=new Map,m.current=new Set,h.current=new Map,g.current=new Set,_.current=new Map,!e){o(!0);return}y(e,!0)},[e,y]);let b=(0,Q.useCallback)(e=>{let t=e;if(!t||t.type!==`rail.pr_state`||t.projectId!==u.current||typeof t.railIndex!=`number`||typeof t.prDeliveryId!=`string`||!t.decision)return;let n=sn(t,t.railIndex);n&&v(n)},[v]);(0,Q.useLayoutEffect)(()=>(s(`rail-pr-decision`,b),()=>c(`rail-pr-decision`)),[b,s,c]),(0,Q.useEffect)(()=>{let e=()=>{let e=u.current;e&&y(e,!1)};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[y]);let x=(0,Q.useRef)(l);(0,Q.useEffect)(()=>{let e=x.current;x.current=l;let t=u.current;t&&l===`connected`&&e!==`connected`&&y(t,!1)},[l,y]);let S=(0,Q.useCallback)(async(e,t,n,r,i)=>{let a=d.current.get(e),o=u.current;if(!a||!o)return{status:0,ok:!1,error:`no_delivery`};if(a.prDeliveryId!==r)return{status:409,ok:!1,error:`stale_decision`,current:a.decision,snapshotApplication:`stale`};try{let e=await fetch(`/api/projects/${o}/rails/pr-decision`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prDeliveryId:a.prDeliveryId,action:t,expectedDecision:n,...i?{repositoryId:i}:{}})}),r=await e.json().catch(()=>({})),s=sn(r.snapshot),c;return s&&u.current===o?c=v(s):e.status===409&&r.error===`stale_decision`&&u.current===o&&y(o,!1),{...r,snapshot:s,snapshotApplication:c,busy:e.status===409&&r.error===`operation_in_progress`,operation:s?.operation??(typeof r.operation==`string`&&eW.has(r.operation)?r.operation:null),status:e.status,ok:e.ok&&r.ok===!0}}catch(e){return{status:0,ok:!1,error:`network`,detail:e.message}}},[v,y]),C=(0,Q.useCallback)(async(e,t,n)=>{let r=d.current.get(e),i=u.current;if(!r||!i)return{status:0,ok:!1,error:`no_delivery`};if(r.prDeliveryId!==t)return{status:409,ok:!1,error:`stale_decision`,detail:`The delivery generation changed before checkout.`};try{let e=await fetch(`/api/projects/${i}/rails/pr-checkout`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prDeliveryId:r.prDeliveryId,...n?{repositoryId:n}:{}})}),t=await e.json().catch(()=>({}));return{...t,status:e.status,ok:e.ok&&t.ok===!0}}catch(e){return{status:0,ok:!1,error:`network`,detail:e.message}}},[]),w=(0,Q.useMemo)(()=>({decisions:r,hydrated:a,act:S,checkout:C}),[r,a,S,C]);return(0,$.jsx)(XU.Provider,{value:w,children:t})}function rW(e){return e?`specrails-desktop:dashboard-split:${e}`:null}function iW(e){let t=rW(e);if(!t)return null;try{let e=localStorage.getItem(t);if(!e)return null;let n=Number.parseInt(e,10);return Number.isFinite(n)&&n>0?n:null}catch{return null}}function aW(e,t){let n=rW(e);if(n)try{localStorage.setItem(n,String(Math.round(t)))}catch{}}function oW(e,t){let n=Math.max(320,t-280);return Math.min(Math.max(e,320),n)}var sW=.7;function cW(e){return oW(Math.round(e*sW),e)}function lW(e,t){let n=cW(t);return Math.abs(e-n)<=48?n:e}function uW(e,t){let[n,r]=(0,Q.useState)(()=>typeof window<`u`?window.innerWidth:1200),i=(0,Q.useRef)(n),[a,o]=(0,Q.useState)(()=>{if(typeof window>`u`)return null;let e=window.innerWidth;return e<900?null:cW(e)}),s=(0,Q.useRef)(null),c=(0,Q.useRef)(null),l=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(typeof window>`u`)return;let e=t?.current?.clientWidth||window.innerWidth;if(r(e),i.current=e,e<900){o(null);return}o(cW(e))},[e,t]),(0,Q.useEffect)(()=>{function n(t){if(r(t),t<900){i.current=t,o(null);return}let n=t-i.current;i.current=t,o(r=>{let i=r??iW(e)??cW(t),a=oW(r!==null&&Number.isFinite(n)?i+n:i,t);return a!==r&&aW(e,a),a})}let a=t?.current;if(a&&typeof ResizeObserver<`u`){let e=new ResizeObserver(e=>{let t=e[0]?.contentRect.width;typeof t==`number`&&n(t)});return e.observe(a),n(a.clientWidth||window.innerWidth),()=>e.disconnect()}function s(){n(window.innerWidth)}return window.addEventListener(`resize`,s),()=>window.removeEventListener(`resize`,s)},[e,t]);let u=(0,Q.useCallback)(()=>{if(c.current=null,l.current===null)return;let e=oW(l.current,n);l.current=null,o(e)},[n]),d=(0,Q.useCallback)(e=>{if(!s.current)return;let t=e.clientX-s.current.startClientX;l.current=s.current.startLeftWidth+t,c.current===null&&(c.current=requestAnimationFrame(u))},[u]),f=(0,Q.useCallback)(t=>{if(!s.current)return;let{pointerId:r,element:i}=s.current;try{i.releasePointerCapture(r)}catch{}s.current=null,window.removeEventListener(`pointermove`,d),window.removeEventListener(`pointerup`,f),window.removeEventListener(`pointercancel`,f),o(t=>{if(t===null)return t;let r=oW(lW(t,n),n);return aW(e,r),r})},[d,e,n]),p=(0,Q.useCallback)(e=>{let t=e.nativeEvent??e,n=e.currentTarget??t.target;try{n.setPointerCapture(t.pointerId)}catch{}s.current={pointerId:t.pointerId,element:n,startClientX:t.clientX,startLeftWidth:a??0},window.addEventListener(`pointermove`,d),window.addEventListener(`pointerup`,f),window.addEventListener(`pointercancel`,f)},[d,f,a]),m=(0,Q.useCallback)(()=>{if(typeof window>`u`)return;let n=t?.current?.clientWidth||window.innerWidth;if(n<900)return;let r=cW(n);o(r),aW(e,r)},[e,t]);return{leftWidth:a,enabled:a!==null&&n>=900,beginDrag:p,resetToDefault:m}}function dW({leftWidth:e,onPointerDown:t,onReset:n,viewport:r}){let i=(0,Q.useCallback)(t=>{let n=t.shiftKey?64:16;t.key===`ArrowLeft`&&(t.preventDefault(),e-n)},[e]);return(0,$.jsxs)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-valuenow":e,"aria-valuemin":320,"aria-valuemax":Math.max(320,r-280),tabIndex:0,onPointerDown:t,onDoubleClick:n,onKeyDown:i,className:`relative w-1.5 shrink-0 cursor-col-resize group select-none touch-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-info/60`,"data-testid":`dashboard-splitter`,children:[(0,$.jsx)(`div`,{className:`absolute inset-y-0 left-1/2 -translate-x-1/2 w-px bg-border/40 group-hover:bg-accent-info/40 group-focus-visible:bg-accent-info/60 transition-colors`}),(0,$.jsxs)(`div`,{className:`absolute inset-y-0 left-1/2 -translate-x-1/2 flex flex-col items-center justify-center gap-1 pointer-events-none opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,$.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-accent-info/60`}),(0,$.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-accent-info/60`}),(0,$.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-accent-info/60`})]})]})}function fW({open:e,allLabels:t,onClose:n,onCreate:r}){let{t:i}=K(`tickets`),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(`todo`),[d,f]=(0,Q.useState)(`medium`),[p,m]=(0,Q.useState)([]),[h,g]=(0,Q.useState)(),[_,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(!1),x=(0,Q.useRef)(null),S=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{e&&setTimeout(()=>x.current?.focus(),100)},[e]),(0,Q.useEffect)(()=>{e||(o(``),c(``),u(`todo`),f(`medium`),m([]),g(void 0),v(``))},[e]);let C=(0,Q.useMemo)(()=>{if(!_.trim())return[];let e=_.toLowerCase();return t.filter(t=>t.toLowerCase().includes(e)&&!p.includes(t)).slice(0,5)},[_,t,p]),w=(0,Q.useCallback)(e=>{let t=e.trim();t&&!p.includes(t)&&m(e=>[...e,t]),v(``)},[p]),T=(0,Q.useCallback)(async()=>{if(!a.trim())return;b(!0);let e=await r({title:a.trim(),description:s.trim()||void 0,status:l,priority:d,labels:p.length>0?p:void 0,...h?{repositoryIds:h}:{}});b(!1),e?(J.success(i(`createModal.toast.created`)),n()):J.error(i(`createModal.toast.createFailed`))},[a,s,l,d,p,h,r,n,i]);return(0,$.jsx)(mr,{open:e,onOpenChange:e=>!e&&n(),children:(0,$.jsxs)(fr,{movableResizable:!0,className:`max-w-lg glass-card`,children:[(0,$.jsx)(ur,{children:(0,$.jsx)(sr,{children:i(`createModal.title`)})}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`label`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider block mb-1`,children:[i(`fields.title`),` `,(0,$.jsx)(`span`,{className:`text-red-400 aurora-light:text-destructive`,children:`*`})]}),(0,$.jsx)(`input`,{ref:x,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a.trim()&&T()},placeholder:i(`createModal.titlePlaceholder`),className:`w-full h-8 rounded border border-border bg-input px-3 text-xs text-foreground placeholder:text-muted-foreground`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider block mb-1`,children:i(`fields.description`)}),(0,$.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),rows:4,placeholder:i(`fields.markdownPlaceholder`),className:`w-full rounded border border-border bg-input px-3 py-2 text-xs text-foreground placeholder:text-muted-foreground resize-y min-h-[80px]`}),(0,$.jsx)(`span`,{className:`text-[9px] text-muted-foreground mt-0.5 block`,children:i(`fields.supportsMarkdown`)})]}),(0,$.jsxs)(`div`,{className:`flex gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex-1`,children:[(0,$.jsx)(`label`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider block mb-1`,children:i(`fields.status`)}),(0,$.jsxs)(`select`,{value:l,onChange:e=>u(e.target.value),className:`w-full h-7 rounded border border-border bg-input px-2 text-xs text-foreground`,children:[(0,$.jsx)(`option`,{value:`todo`,children:i(`ticketStatus.todo`)}),(0,$.jsx)(`option`,{value:`in_progress`,children:i(`ticketStatus.inProgress`)}),(0,$.jsx)(`option`,{value:`done`,children:i(`ticketStatus.done`)}),(0,$.jsx)(`option`,{value:`cancelled`,children:i(`ticketStatus.cancelled`)})]})]}),(0,$.jsxs)(`div`,{className:`flex-1`,children:[(0,$.jsx)(`label`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider block mb-1`,children:i(`fields.priority`)}),(0,$.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),className:`w-full h-7 rounded border border-border bg-input px-2 text-xs text-foreground`,children:[(0,$.jsx)(`option`,{value:`critical`,children:i(`priority.critical`)}),(0,$.jsx)(`option`,{value:`high`,children:i(`priority.high`)}),(0,$.jsx)(`option`,{value:`medium`,children:i(`priority.medium`)}),(0,$.jsx)(`option`,{value:`low`,children:i(`priority.low`)})]})]})]}),(0,$.jsx)(Dr,{value:h,onChange:g,disabled:y}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider block mb-1`,children:i(`fields.labels`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-1.5`,children:p.map(e=>(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded px-1.5 py-0.5 text-[10px] font-medium bg-accent/60 text-foreground/70`,children:[e,(0,$.jsx)(`button`,{type:`button`,onClick:()=>m(t=>t.filter(t=>t!==e)),className:`text-muted-foreground hover:text-foreground transition-colors`,children:(0,$.jsx)(Tn,{className:`w-2.5 h-2.5`})})]},e))}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`input`,{ref:S,value:_,onChange:e=>v(e.target.value),onKeyDown:e=>{e.key===`Enter`&&_.trim()&&(e.preventDefault(),w(_))},placeholder:i(`createModal.labelsPlaceholder`),className:`w-full h-6 rounded border border-border bg-input px-2 text-[10px] text-foreground placeholder:text-muted-foreground`}),C.length>0&&(0,$.jsx)(`div`,{className:`absolute left-0 right-0 top-full mt-0.5 rounded border border-border/50 bg-popover shadow-lg z-10 py-0.5`,children:C.map(e=>(0,$.jsx)(`button`,{type:`button`,onMouseDown:t=>{t.preventDefault(),w(e)},className:`w-full text-left px-2 py-1 text-[10px] hover:bg-accent/50 text-foreground/80`,children:e},e))})]})]})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:n,children:i(`common:actions.cancel`)}),(0,$.jsxs)(Z,{size:`sm`,onClick:T,disabled:y||!a.trim(),children:[(0,$.jsx)(Pn,{className:`w-3.5 h-3.5 mr-1`}),i(y?`createModal.creating`:`createModal.create`)]})]})]})})}function pW({open:e,railLabel:t,specCount:n,provider:r=`claude`,model:i,onConfirm:a,onCancel:o}){let{t:s}=K(`dashboard`),c=(0,Q.useRef)(null),l=jt(r);return(0,Q.useEffect)(()=>{if(!e)return;function t(e){(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),a())}return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,a]),(0,$.jsx)(mr,{open:e,onOpenChange:e=>{e||o()},children:(0,$.jsxs)(fr,{movableResizable:!0,showCloseButton:!1,className:`max-w-md gap-5`,onOpenAutoFocus:e=>{e.preventDefault(),c.current?.focus()},children:[(0,$.jsx)(ur,{children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-xl bg-accent-highlight/15 text-accent-highlight ring-1 ring-accent-highlight/30`,children:(0,$.jsx)(Ln,{className:`h-4.5 w-4.5`})}),(0,$.jsxs)(`div`,{className:`text-left`,children:[(0,$.jsx)(sr,{className:`text-base`,children:s(`freestyleDialog.title`)}),(0,$.jsxs)(ir,{children:[s(`freestyleDialog.context`,{rail:t,count:n}),i?` · ${i}`:``]})]})]})}),(0,$.jsxs)(`ul`,{className:`space-y-2.5 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,$.jsx)(On,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-warning`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s(`freestyleDialog.noPipelineTitle`)}),` `,s(`freestyleDialog.noPipelineBody`)]})]}),(0,$.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,$.jsx)(Vo,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-info`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s(`freestyleDialog.autonomyTitle`,{provider:l})}),` `,s(`freestyleDialog.autonomyBody`,{provider:l})]})]}),(0,$.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,$.jsx)(hs,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-success`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s(`freestyleDialog.costTitle`)}),` `,s(`freestyleDialog.costBody`,{provider:l})]})]})]}),(0,$.jsxs)(Zn,{className:`gap-2 sm:gap-2`,children:[(0,$.jsx)(Z,{variant:`ghost`,className:`h-9`,onClick:o,children:s(`common:actions.cancel`)}),(0,$.jsxs)(Z,{ref:c,className:`h-9 gap-2 bg-emerald-500 text-white hover:bg-emerald-400 focus-visible:ring-emerald-400`,onClick:a,children:[s(`freestyleDialog.continue`),(0,$.jsx)(`kbd`,{className:`hidden sm:inline-flex items-center rounded border border-white/30 bg-white/10 px-1 text-[9px] font-medium leading-4`,children:`⌘↵`})]})]})]})})}function mW(e,t=typeof navigator>`u`?``:navigator.platform){return/Mac|iPhone|iPad/i.test(t)?e:e.replace(/⌥/g,`Alt+`).replace(/⌘/g,`Ctrl+`).replace(/⇧/g,`Shift+`).replace(/[⏎↵]/g,`Enter`)}function hW({open:e,railCount:t,specCount:n,onConfirm:r,onCancel:i}){let{t:a}=K(`dashboard`),o=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(!e)return;function t(e){(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),r())}return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,r]),(0,$.jsx)(mr,{open:e,onOpenChange:e=>{e||i()},children:(0,$.jsxs)(fr,{movableResizable:!0,showCloseButton:!1,className:`max-w-md gap-5`,onOpenAutoFocus:e=>{e.preventDefault(),o.current?.focus()},children:[(0,$.jsx)(ur,{children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-xl bg-accent-primary/15 text-accent-primary ring-1 ring-accent-primary/30`,children:(0,$.jsx)(gc,{className:`h-4.5 w-4.5`})}),(0,$.jsxs)(`div`,{className:`text-left`,children:[(0,$.jsx)(sr,{className:`text-base`,children:a(`launchAllDialog.title`)}),(0,$.jsxs)(ir,{children:[a(`launchAllDialog.railsCount`,{count:t}),` · `,a(`launchAllDialog.specsCount`,{count:n})]})]})]})}),(0,$.jsxs)(`ul`,{className:`space-y-2.5 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,$.jsx)(On,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-info`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:a(`launchAllDialog.isolationTitle`)}),` `,a(`launchAllDialog.isolationBody`)]})]}),(0,$.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,$.jsx)(kn,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-secondary`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:a(`launchAllDialog.pipelinesTitle`,{count:t})}),` `,a(`launchAllDialog.pipelinesBody`)]})]}),(0,$.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,$.jsx)(hs,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-success`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:a(`launchAllDialog.costTitle`)}),` `,a(`launchAllDialog.costBody`)]})]})]}),(0,$.jsxs)(Zn,{className:`gap-2 sm:gap-2`,children:[(0,$.jsx)(Z,{variant:`ghost`,className:`h-9`,onClick:i,children:a(`common:actions.cancel`)}),(0,$.jsxs)(Z,{ref:o,className:`h-9 gap-2 bg-emerald-500 text-white hover:bg-emerald-400 focus-visible:ring-emerald-400`,onClick:r,children:[a(`launchAllDialog.launch`,{count:t}),(0,$.jsx)(`kbd`,{className:`hidden sm:inline-flex items-center rounded border border-white/30 bg-white/10 px-1 text-[9px] font-medium leading-4`,children:mW(`⌘↵`)})]})]})]})})}function gW({open:e,target:t,onConfirm:n,onCancel:r}){let{t:i}=K(`dashboard`),a=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(!e)return;function t(e){(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),n())}return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,n]),t?(0,$.jsx)(mr,{open:e,onOpenChange:e=>{e||r()},children:(0,$.jsxs)(fr,{movableResizable:!0,showCloseButton:!1,className:`max-w-md gap-5`,onOpenAutoFocus:e=>{e.preventDefault(),a.current?.focus()},children:[(0,$.jsx)(ur,{children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-xl bg-accent-info/15 text-accent-info ring-1 ring-accent-info/30`,children:(0,$.jsx)(A,{className:`h-4.5 w-4.5`})}),(0,$.jsxs)(`div`,{className:`text-left`,children:[(0,$.jsx)(sr,{className:`text-base`,children:i(`targetPr.confirmTitle`)}),(0,$.jsx)(ir,{children:i(`targetPr.confirmBody`)})]})]})}),(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border/60 bg-muted/30 p-3 text-xs`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(A,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-info`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`min-w-0 font-medium text-foreground`,children:[`#`,t.number,t.title?` · ${t.title}`:``]})]}),t.headRefName&&(0,$.jsxs)(`div`,{className:`flex items-start gap-2 text-muted-foreground`,children:[(0,$.jsx)(On,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`min-w-0 truncate`,children:[i(`targetPr.confirmBranch`),`: `,(0,$.jsx)(`span`,{className:`font-mono`,children:t.headRefName})]})]})]}),(0,$.jsxs)(Zn,{className:`gap-2 sm:gap-2`,children:[(0,$.jsx)(Z,{variant:`ghost`,className:`h-9`,onClick:r,children:i(`common:actions.cancel`)}),(0,$.jsxs)(Z,{ref:a,className:`h-9 gap-2 bg-accent-info text-white hover:bg-accent-info/85 focus-visible:ring-accent-info`,onClick:n,children:[i(`targetPr.confirmLaunch`,{number:t.number}),(0,$.jsx)(`kbd`,{className:`hidden sm:inline-flex items-center rounded border border-white/30 bg-white/10 px-1 text-[9px] font-medium leading-4`,children:mW(`⌘↵`)})]})]})]})}):null}var _W=`postit`,vW=e=>`specrails-desktop:specs-view-tier:${e}`;function yW(e){return e===`row`||e===`postit`}function bW(e){if(!e)return _W;try{let t=localStorage.getItem(vW(e));if(yW(t))return t}catch{}return _W}function xW(e,t){if(e)try{localStorage.setItem(vW(e),t)}catch{}}function SW(e,t,n){if(typeof n==`number`&&n===t)return e;if(typeof n==`number`&&e.includes(n)){let r=e.indexOf(n),i=[...e];return i.splice(r,0,t),i}return[...e,t]}function CW(e,t,n,r,i){if(typeof e==`string`){if(r(e)){let n=i(e);return t.has(n)?n:null}return t.has(e)?e:null}if(typeof e==`number`){let r=n(e);return r&&t.has(r)?r:null}return null}var wW=[{id:`rail-1`,label:`Rail 1`,ticketIds:[],mode:`implement`,status:`idle`},{id:`rail-2`,label:`Rail 2`,ticketIds:[],mode:`implement`,status:`idle`},{id:`rail-3`,label:`Rail 3`,ticketIds:[],mode:`implement`,status:`idle`}],TW=e=>e===`implement`||e===`batch-implement`||e===`freestyle`||e===`loop`;function EW(e,t){if(!e||e.decision!==`pr_draft`&&e.decision!==`pr_ready`||!e.prUrl||!e.branch)return!1;let n=new Set(e.ticketIds);return t.length>0&&t.every(e=>n.has(e))}function DW(e,t){for(let n of t.values())if(EW(n,[e]))return!0;return!1}function OW(e){if(!e)return null;try{let t=localStorage.getItem(`specrails-desktop:spec-order:${e}`);if(!t)return null;let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function kW(e,t){if(e)try{t?localStorage.setItem(`specrails-desktop:spec-order:${e}`,JSON.stringify(t)):localStorage.removeItem(`specrails-desktop:spec-order:${e}`)}catch{}}function AW(e){if(!e)return null;try{let t=localStorage.getItem(`specrails-desktop:rails:${e}`);if(!t)return null;let n=JSON.parse(t);return!Array.isArray(n)||n.length===0?null:n}catch{return null}}function jW(e,t){if(e)try{localStorage.setItem(`specrails-desktop:rails:${e}`,JSON.stringify(t))}catch{}}function MW(){let{t:e}=K(`dashboard`),{activeProjectId:t,projects:n}=pt(),r=wa().id===`galaxy`,i=(()=>{let e=n.find(e=>e.id===t);return e?dt(e):[`claude`]})(),{tickets:a,isLoading:o,error:s,updateTicket:c,updateTicketStatus:l,updateTicketPriority:u,deleteTicket:d,createTicket:f,refetch:p,contractRefiningIds:m}=k(),{registerHandler:h,unregisterHandler:g,connectionStatus:_}=tt(),{specToOpen:v,clearSpecToOpen:y}=ZB(),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(null),[O,A]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{!v||v.projectId!==t||(x(v.ticket),p(),y())},[v,t,p,y]);let[j,M]=(0,Q.useState)(null),[N,P]=(0,Q.useState)(null),[F,I]=(0,Q.useState)(()=>OW(t)),[L,R]=(0,Q.useState)(()=>AW(t)??wW),[z,B]=(0,Q.useState)({}),V=JU(),{decisions:H,hydrated:U,act:W,checkout:ee}=ZU(),te=EB(t),[ne,re]=(0,Q.useState)(te.mode),[ie,ae]=(0,Q.useState)(te.dir),[oe,se]=(0,Q.useState)(()=>bW(t));(0,Q.useEffect)(()=>{I(OW(t)),R(AW(t)??wW),B({});let e=EB(t);re(e.mode),ae(e.dir),se(bW(t))},[t]);let ce=(0,Q.useCallback)((e,n)=>{re(e),ae(n),DB(t,e,n)},[t]),le=(0,Q.useCallback)(e=>{se(e),xW(t,e)},[t]);(0,Q.useEffect)(()=>{if(_!==`connected`||!t)return;let e=!1,n=AW(t)??wW,r=new Map(n.map(e=>[e.id,e]));return fetch(`${ut()}/rails`).then(e=>e.ok?e.json():null).then(n=>{if(e||!n)return;let i=n.activeJobs??{},a=n.activeLoopRuns??{},o=new Set([...Object.keys(i).map(Number),...Object.keys(a).map(Number)]),s=n.rails??[],c=new Map;for(let e of s)c.set(e.railIndex,Array.isArray(e.ticketIds)?e.ticketIds:[]);let l=new Set(s.map(e=>e.railIndex));R(e=>{let n=!1,u=new Map,d=e.map((e,t)=>{let s=xU(e.id)??t,l=a[String(s)],d=i[String(s)]?.jobId??l?.loopRunId;if(o.has(s)){if(e.status===`running`)return d&&!e.activeJobId?(n=!0,{...e,activeJobId:d}):e;if(r.get(e.id)?.status===`running`)return e;let t=c.get(s)??[],a=i[String(s)]?.mode,o=TW(a)?a:l?tS(l.loopId):void 0,f=t.length?t:e.ticketIds;return u.set(e.id,f),n=!0,{...e,status:`running`,activeJobId:d,ticketIds:f,mode:o??e.mode,...l?.loopId&&l.loopId.startsWith(`custom:`)?{selectedLoopId:l.loopId}:{}}}return e.status!==`running`||r.get(e.id)?.status!==`running`?e:(n=!0,{...e,status:`idle`,activeJobId:void 0,ticketIds:[]})}),f=new Set(d.map(e=>e.id)),p=[];for(let e of s){let t=bU(e.railIndex);if(f.has(t))continue;let r=a[String(e.railIndex)],s=i[String(e.railIndex)]?.mode,l=TW(s)?s:r?tS(r.loopId):TW(e.mode)?e.mode:`implement`,d=o.has(e.railIndex),m=c.get(e.railIndex)??[];p.push({id:t,label:e.name?`Rail ${e.name}`:`Rail ${e.railIndex+1}`,ticketIds:m,mode:l,status:d?`running`:`idle`,activeJobId:i[String(e.railIndex)]?.jobId??r?.loopRunId,...r?.loopId&&r.loopId.startsWith(`custom:`)?{selectedLoopId:r.loopId}:{}}),m.length>0&&u.set(t,m),n=!0}let m=p.length>0?[...d,...p]:d;if(s.length>0){let e=m.filter(e=>{let t=xU(e.id);return t===null||l.has(t)||!r.has(e.id)?!0:e.status===`running`||e.ticketIds.length>0});e.length!==m.length&&(m=e,n=!0)}if(!n)return e;let h=new Set([...u.values()].flat()),g=h.size?m.map(e=>{if(u.has(e.id))return e;let t=e.ticketIds.filter(e=>!h.has(e));return t.length===e.ticketIds.length?e:{...e,ticketIds:t}}):m;return jW(t,g),g})}).catch(()=>{}),()=>{e=!0}},[t,_]),(0,Q.useEffect)(()=>{if(!t)return;let e=!1;return fetch(`${ut()}/rails`).then(e=>e.ok?e.json():null).then(n=>{if(e||!n?.rails)return;let r=new Map;for(let e of n.rails)r.set(e.railIndex,e.name??null);R(e=>{let n=!1,i=e.map((e,t)=>{let i=xU(e.id)??t,a=r.get(i)??null;if(!a)return e;let o=`Rail ${a}`;return o===e.label?e:(n=!0,{...e,label:o})});return n?(jW(t,i),i):e})}).catch(()=>{}),()=>{e=!0}},[t]),(0,Q.useEffect)(()=>{let e=new Set(a.filter(e=>e.status===`done`||U&&e.status===`on_review`&&!DW(e.id,H)).map(e=>e.id));e.size!==0&&R(n=>{let r=n.map(t=>{let n=t.ticketIds.filter(t=>!e.has(t));return n.length===t.ticketIds.length?t:{...t,ticketIds:n}});return r.every((e,t)=>e===n[t])?n:(jW(t,r),r)})},[a,t,L,H,U]);let ue=(0,Q.useCallback)(e=>{I(n=>{let r=e(n);return kW(t,r),r})},[t]),de=(0,Q.useCallback)(e=>{R(n=>{let r=e(n);return jW(t,r),r})},[t]),fe=(0,Q.useMemo)(()=>{let e=new Set([`specs`,`done-specs`]);for(let t of L)e.add(t.id);return e},[L]),G=(0,Q.useCallback)(async()=>{try{let t=await fetch(`${ut()}/rails`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})});if(t.ok){let n=(await t.json()).rail?.railIndex;if(typeof n==`number`){let t=bU(n);de(e=>e.some(e=>e.id===t)?e:[...e,{id:t,label:`Rail ${n+1}`,ticketIds:[],mode:`implement`,status:`idle`}]),J.success(e(`toasts.railAdded`,{n:n+1}));return}}else{let n=await t.json().catch(()=>({error:``}));if(n.error===`rail_limit_reached`){J.error(e(`toasts.railLimitReached`,{max:n.maxRails??12}));return}}}catch{}let t=L.map(e=>xU(e.id)).filter(e=>e!==null),n=t.length>0?Math.max(...t)+2:1,r={id:`rail-${n}`,label:`Rail ${n}`,ticketIds:[],mode:`implement`,status:`idle`};de(e=>[...e,r]),J.success(e(`toasts.railAdded`,{n}))},[L,de,e]),pe=(0,Q.useCallback)(async t=>{let n=L.find(e=>e.id===t);if(!n||n.status===`running`)return;let r=()=>{n.ticketIds.length>0&&ue(e=>[...e??[],...n.ticketIds]),de(e=>e.filter(e=>e.id!==t)),J.info(e(`toasts.railRemoved`,{rail:n.label}))},i=xU(t);if(i===null){r();return}try{let t=await fetch(`${ut()}/rails/${i}`,{method:`DELETE`});if(t.ok||t.status===404){r();return}J.error(e(`toasts.railDeleteFailed`))}catch{J.error(e(`toasts.railDeleteFailed`))}},[L,de,ue,e]),me=(0,Q.useCallback)((e,t)=>{de(n=>n.map(n=>n.id===e?{...n,label:`Rail ${t}`}:n));let n=xU(e);n!==null&&fetch(`${ut()}/rails/${n}/name`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})}).catch(()=>{})},[de]),he=(0,Q.useRef)(t);(0,Q.useEffect)(()=>{he.current=t},[t]);let ge=(0,Q.useCallback)(t=>{let n=t;if(n.projectId===he.current){if(n.type===`runtime.continuation`){if(n.railIndex==null)return;let e=bU(n.railIndex);de(t=>t.map(t=>t.id===e?n.active?{...t,status:`running`,activeJobId:n.jobId}:t.activeJobId===n.jobId?{...t,status:`idle`,activeJobId:void 0}:t:t));return}if(n.type===`rail.job_started`||n.type===`loop.run_started`){if(n.railIndex==null)return;let e=bU(n.railIndex),t=n.jobId??n.loopRunId;de(n=>n.map(n=>n.id===e?{...n,status:`running`,activeJobId:t??n.activeJobId}:n));return}if(n.type===`rail.updated`){let e=n.railIndex??0,t=bU(e),r=n.ticketIds??[],i=n.name?`Rail ${n.name}`:`Rail ${e+1}`;de(e=>e.some(e=>e.id===t)?e.map(e=>e.id===t?n.changed!==`tickets`||e.status===`running`?{...e,label:i}:{...e,label:i,ticketIds:r}:e):[...e,{id:t,label:i,ticketIds:r,mode:TW(n.mode)?n.mode:`implement`,status:`idle`}]);return}if(n.type===`rail.removed`){if(n.railIndex==null)return;let e=bU(n.railIndex);de(t=>t.filter(t=>t.id!==e||t.status===`running`));return}if(n.type===`rail.worktree_progress`){let t=n.railIndex??0,r=n.ticketId,i=n.state;typeof r==`number`&&i&&(B(e=>wU(e,t,r,i)),i===`needs-review`&&J.error(e(`toasts.railWorktreeNeedsReview`,{n:t+1,ticket:r})));return}if(n.type===`rail.job_completed`){let t=n.railIndex??0;de(e=>AU(e,t,n.ticketIds??[])),n.status===`completed`?J.info(e(`toasts.railCompleted`,{n:t+1})):n.status===`failed`||n.status===`zombie_terminated`?J.error(e(`toasts.railFailed`,{n:t+1})):J.info(e(`toasts.railEnded`,{n:t+1,status:n.status??`finished`}))}if(n.type===`loop.run_completed`){let t=n.railIndex??0;de(e=>AU(e,t,n.ticketIds??[])),n.status===`success`?J.info(e(`toasts.railCompleted`,{n:t+1})):n.status===`failed`||n.status===`max-iterations`?J.error(e(`toasts.railFailed`,{n:t+1})):J.info(e(`toasts.railEnded`,{n:t+1,status:n.status??`finished`}))}}},[de,e]);(0,Q.useEffect)(()=>(h(`dashboard-rails`,ge),()=>g(`dashboard-rails`)),[ge,h,g]);let _e=kI(OI(PL,{activationConstraint:{distance:5}}),OI(kL)),ve=(0,Q.useCallback)(e=>{let t=typeof e.active.id==`string`&&OU(e.active.id),n=e.droppableContainers.filter(e=>{let n=e.id;return typeof n==`string`&&OU(n)?t:!t}),r={...e,droppableContainers:n};if(t)return zI(r);let i=UI(r);if(II(i))return i;let a=VI(r);return II(a)?a:zI(r)},[]),ye=(0,Q.useMemo)(()=>new Map(a.map(e=>[e.id,e])),[a]),be=(0,Q.useMemo)(()=>{let e=[],t=[];return L.forEach((n,r)=>{let i=xU(n.id)??r;if(n.status===`running`){t.push({rail:n,reason:`running`});return}if(n.ticketIds.length===0){t.push({rail:n,reason:`empty`});return}let a=H.get(i);if(a&&!EW(a,n.ticketIds)){t.push({rail:n,reason:`pendingDecision`});return}if(n.ticketIds.some(e=>ye.get(e)?.status===`on_review`&&(!U||!DW(e,H)))){t.push({rail:n,reason:`onReview`});return}e.push(n)}),{eligible:e,skipped:t}},[L,H,U,ye]),xe=(0,Q.useMemo)(()=>{let e=new Set;for(let t of a)for(let n of t.labels)e.add(n);return Array.from(e).sort()},[a]),Se=(0,Q.useMemo)(()=>{let e=new Set;for(let t of L)for(let n of t.ticketIds)e.add(n);return e},[L]),Ce=(0,Q.useMemo)(()=>a.filter(e=>(e.source===`propose-spec`||e.source===`product-backlog`||e.source===`get-backlog-specs`||e.source===`explore-draft`||e.source===`specs-smash`||e.source===`free-prompt`||e.source===`mcp`||e.source===`project-builder`||e.source===`manual`&&e.created_by===`project-builder`||e.source===`jira`)&&!Se.has(e.id)),[a,Se]);(0,Q.useEffect)(()=>{o||ne===`jira-key`&&!Ce.some(e=>e.jira_key)&&ce(`default`,ie)},[o,ne,ie,Ce,ce]);let we=(0,Q.useMemo)(()=>{let e=Ce.filter(e=>e.status!==`done`);if(ne!=="default")return PB(e,ne,ie);if(!F)return e;let t=new Map(e.map(e=>[e.id,e])),n=[];for(let e of F){let r=t.get(e);r&&n.push(r)}for(let t of e)F.includes(t.id)||n.push(t);return n},[Ce,F,ne,ie]),Te=(0,Q.useMemo)(()=>Ce.filter(e=>e.status===`done`),[Ce]),De=(0,Q.useMemo)(()=>{let e=new Set;if(!U)return e;for(let t of a)t.status===`on_review`&&DW(t.id,H)&&e.add(t.id);return e},[a,H,U]),Oe=(0,Q.useCallback)((t,n)=>{let r=L.find(e=>e.id===n);if(r){if(a.find(e=>e.id===t)?.status===`on_review`&&(!U||!DW(t,H))){J.info(e(`toasts.onReviewCannotMoveToRail`));return}if(r.ticketIds.includes(t)){J.info(e(`toasts.alreadyOnRail`,{rail:r.label}));return}ue(e=>(e??we.map(e=>e.id)).filter(e=>e!==t)),de(e=>e.map(e=>e.id===n?{...e,ticketIds:[...e.ticketIds.filter(e=>e!==t),t]}:e.ticketIds.includes(t)?{...e,ticketIds:e.ticketIds.filter(e=>e!==t)}:e)),J.success(e(`toasts.movedToRail`,{rail:r.label}))}},[L,a,we,de,ue,e,H,U]),Ae=(0,Q.useCallback)(t=>{let n=L.find(e=>e.ticketIds.includes(t));if(n){if(n.status===`running`){J.error(e(`toasts.railRunningStopFirst`,{rail:n.label}));return}de(e=>e.map(e=>e.id===n.id?{...e,ticketIds:e.ticketIds.filter(e=>e!==t)}:e)),ue(e=>{let n=e??we.map(e=>e.id);return n.includes(t)?n:[...n,t]}),J.success(e(`toasts.removedFromRail`,{rail:n.label}))}},[L,we,de,ue,e]),je=(0,Q.useCallback)(e=>{if(we.some(t=>t.id===e))return`specs`;if(Te.some(t=>t.id===e))return`done-specs`;for(let t of L)if(t.ticketIds.includes(e))return t.id;return null},[we,Te,L]);function Me({active:e}){if(OU(e.id)){let t=kU(e.id),n=L.find(e=>e.id===t);P(n?.label??t);return}M(e.id)}function Ne({active:n,over:r}){if(M(null),P(null),!r)return;if(OU(n.id)){if(!OU(r.id))return;let e=kU(n.id),t=kU(r.id);if(e===t)return;de(n=>{let r=n.findIndex(t=>t.id===e),i=n.findIndex(e=>e.id===t);return r===-1||i===-1?n:QR(n,r,i)});return}let i=n.id,o=r.id,s=je(i);if(!s)return;let l=CW(o,fe,je,OU,kU)??s;if(fe.has(l))if(s===l)if(l===`specs`){let e=we.map(e=>e.id),n=e.indexOf(i),r=e.indexOf(o);if(n!==-1&&r!==-1&&n!==r){let i=QR(e,n,r);ue(()=>i),ne!=="default"&&(re(`default`),DB(t,`default`,ie))}}else de(e=>e.map(e=>{if(e.id!==l)return e;let t=e.ticketIds.indexOf(i),n=e.ticketIds.indexOf(o);return t!==-1&&n!==-1&&t!==n?{...e,ticketIds:QR(e.ticketIds,t,n)}:e}));else if(s===`specs`&&l===`done-specs`){if(a.find(e=>e.id===i)?.status===`on_review`){J.info(e(`toasts.onReviewCannotMoveToRail`));return}ue(e=>(e??we.map(e=>e.id)).filter(e=>e!==i)),c(i,{status:`done`})}else if(s===`done-specs`&&l===`specs`)c(i,{status:`todo`}),ue(e=>SW(e??we.map(e=>e.id),i,o));else if(s===`specs`){if(a.find(e=>e.id===i)?.status===`on_review`&&(!U||!DW(i,H))){J.info(e(`toasts.onReviewCannotMoveToRail`));return}let t=L.find(e=>e.id===l);ue(e=>(e??we.map(e=>e.id)).filter(e=>e!==i)),de(e=>e.map(e=>e.id===l?{...e,ticketIds:SW(e.ticketIds,i,o)}:e)),t&&(t.status===`running`?J.info(e(`toasts.queuedOnRail`,{rail:t.label}),{description:e(`toasts.queuedOnRailDescription`)}):J.success(e(`toasts.movedToRail`,{rail:t.label})))}else if(l===`specs`){let t=L.find(e=>e.id===s);if(t?.status===`running`){J.error(e(`toasts.railRunningStopFirst`,{rail:t.label}));return}de(e=>e.map(e=>e.id===s?{...e,ticketIds:e.ticketIds.filter(e=>e!==i)}:e)),ue(e=>SW(e??we.map(e=>e.id),i,o)),t&&J.success(e(`toasts.removedFromRail`,{rail:t.label}))}else s===`done-specs`?(c(i,{status:`todo`}),de(e=>e.map(e=>e.id===l?{...e,ticketIds:SW(e.ticketIds,i,o)}:e))):l===`done-specs`?(de(e=>e.map(e=>e.id===s?{...e,ticketIds:e.ticketIds.filter(e=>e!==i)}:e)),c(i,{status:`done`})):de(e=>e.map(e=>e.id===s?{...e,ticketIds:e.ticketIds.filter(e=>e!==i)}:e.id===l?{...e,ticketIds:SW(e.ticketIds,i,o)}:e))}function Pe(e,t){de(n=>n.map(n=>n.id===e?{...n,mode:t}:n))}function Fe(e){let t=xU(e);return t===null?L.findIndex(t=>t.id===e):t}async function Ie(e,t){de(n=>n.map(n=>n.id===e?{...n,profileName:t}:n));let n=Fe(e);if(n!==-1)try{await fetch(`${ut()}/rails/${n}/profile`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({profileName:t})})}catch{}}function Le(e,t){de(n=>n.map(n=>n.id===e?{...n,freestyleModel:t}:n))}function Re(e,t){let n=tS(t);de(r=>r.map(r=>r.id===e?{...r,selectedLoopId:t,mode:n}:r))}function ze(e){let t=e?.aiEngine;return(wt(t)?void 0:t)??i[0]??`claude`}function Be(e,t){de(n=>n.map(n=>{if(n.id!==e)return n;let r=ze(n),i=vt(r,t);return{...n,loopModel:t,reasoningEffort:n.reasoningEffort&&i.includes(n.reasoningEffort)?n.reasoningEffort:Dt(r,t)??null}}))}function Ve(e,t){de(n=>n.map(n=>n.id===e?{...n,reasoningEffort:t}:n))}async function He(t,n){if(wt(n)){let r=L.find(e=>e.id===t);if(r&&(r.mode===`freestyle`||r.selectedLoopId===`factory:freestyle`)){J.error(e(`rail.rolesNoFreestyle`));return}de(e=>e.map(e=>e.id===t?{...e,aiEngine:n,profileName:null}:e)),await Ue(t,n);return}de(e=>e.map(e=>{if(e.id!==t)return e;let r=e.mode===`freestyle`||e.selectedLoopId===`factory:freestyle`,i=!bt(n)&&r,a=Jx(n),o=e=>!!(e&&(a.some(t=>t.value===e)||Nt(n)&&nk(e))),s=o(e.loopModel)?e.loopModel:Yx(n),c=vt(n,s);return{...e,aiEngine:n,mode:i?`implement`:e.mode,selectedLoopId:i?`factory:implement`:e.selectedLoopId,profileName:null,freestyleModel:o(e.freestyleModel)?e.freestyleModel:Yx(n),loopModel:s,reasoningEffort:e.reasoningEffort&&c.includes(e.reasoningEffort)?e.reasoningEffort:Dt(n,s)??null}})),await Ue(t,n)}async function Ue(e,t){let n=Fe(e);if(n!==-1)try{await fetch(`${ut()}/rails/${n}/engine`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({aiEngine:t})})}catch{}}function We(e,t){de(n=>n.map(n=>n.id===e?{...n,targetPr:t}:n))}async function Ge(t){let n=L.find(e=>e.id===t),r=Fe(t);if(!(!n||r===-1)){if(n.status===`running`){try{await fetch(`${ut()}/rails/${r}/stop`,{method:`POST`}),de(e=>e.map(e=>e.id===t?{...e,status:`idle`,activeJobId:void 0}:e)),J.info(e(`toasts.railStopped`,{rail:n.label}))}catch{J.error(e(`toasts.stopFailed`))}return}if(n.ticketIds.length!==0){if(n.mode===`freestyle`){T({railId:t});return}if(n.targetPr){D({railId:t});return}await Ke(t)}}}async function Ke(t,n){let r=n?.silent??!1,i=L.find(e=>e.id===t),o=Fe(t);if(!i||o===-1)return`failed`;if(i.ticketIds.length===0)return`skipped`;if(i.ticketIds.some(e=>a.find(t=>t.id===e)?.status===`on_review`&&(!U||!DW(e,H))))return r||J.info(e(`toasts.onReviewNotLaunchable`)),`skipped`;let s=nS(i.selectedLoopId,i.mode);if(!s)return r||J.error(e(`railControls.pickLoop`)),`failed`;let c=wt(i.aiEngine),l=ze(i),u=vt(l,i.loopModel??Yx(l)),d=i.reasoningEffort&&u.includes(i.reasoningEffort)?i.reasoningEffort:null,f=ut();try{await fetch(`${f}/rails/${o}/tickets`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({ticketIds:i.ticketIds})})}catch{return r||J.error(e(`toasts.syncTicketsFailed`)),`failed`}try{let n=await fetch(`${f}/rails/${o}/launch`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({mode:i.mode,...!c&&(i.aiEngine!=null||i.mode===`loop`&&(i.loopModel||d))?{runtimeProviderOverride:{provider:l,...i.mode===`loop`&&i.loopModel?{model:i.loopModel}:{},...i.mode===`loop`&&d?{effort:d}:{}}}:{},...!c&&i.profileName!==void 0?{profileName:i.profileName}:{},...i.aiEngine==null?{}:{aiEngine:i.aiEngine},...!c&&i.mode===`freestyle`&&i.freestyleModel?{model:i.freestyleModel}:{},...!c&&i.mode===`loop`&&i.loopModel?{model:i.loopModel}:{},loopId:s,...!c&&i.mode===`loop`&&d?{reasoning_effort:d}:{},...i.targetPr?{targetPrNumber:i.targetPr.number}:{}})});if(!n.ok){let t=await n.json().catch(()=>({error:``}));return n.status===409&&t.error===`pr_decision_pending`?(r||J.info(e(`railPr.decisionPending`)),`pendingDecision`):n.status===409&&t.error===`tickets_in_flight`?(r||J.info(e(`toasts.launchTicketsInFlight`)),`skipped`):n.status===400&&t.error===`rail_ticket_cap_exceeded`?(r||J.error(e(`toasts.launchTicketCap`,{max:t.max??3,count:t.ticketCount??0})),`failed`):typeof t.error==`string`&&[`invalid_target_pr`,`target_pr_requires_pr_mode`,`target_pr_not_found`,`target_pr_not_open`,`target_pr_fork`,`target_pr_invalid`,`target_pr_unfetchable`].includes(t.error)?(r||J.error(e(`targetPr.errors.${t.error}`),{description:t.detail,duration:1e4}),`failed`):(r||J.error(t.error||e(`toasts.launchFailed`)),`failed`)}let a=await n.json();!r&&a.isolationUnavailable===`no-git`?J.info(e(`toasts.railWorktreesNoGit`)):!r&&a.isolationUnavailable===`no-commits`?J.info(e(`toasts.railWorktreesNoCommits`)):!r&&a.isolationUnavailable===`error`&&J.warning(e(`toasts.railWorktreesError`),{description:a.isolationUnavailableDetail,duration:12e3});let u=a.jobId??a.loopRunIds?.[0];return de(e=>e.map(e=>e.id===t?{...e,status:`running`,activeJobId:u,targetPr:null}:e)),r||J.success(e(`toasts.railLaunched`,{rail:i.label}),{description:e(`toasts.launchDescription`,{mode:i.mode,count:i.ticketIds.length})}),`launched`}catch{return r||J.error(e(`toasts.launchNetworkError`)),`failed`}}function qe(){if(be.eligible.length===0){J.info(e(`toasts.launchAllNoneEligible`));return}A(!0)}async function Je(){A(!1);let{eligible:t,skipped:n}=be;if(t.length===0){J.info(e(`toasts.launchAllNoneEligible`));return}let r=await Promise.allSettled(t.map(e=>Ke(e.id,{silent:!0}))),i=0,a=0,o=0,s=0;for(let e of r){let t=e.status===`fulfilled`?e.value:`failed`;t===`launched`?i++:t===`pendingDecision`?o++:t===`skipped`?s++:a++}let c=new Map;for(let e of n)c.set(e.reason,(c.get(e.reason)??0)+1);o>0&&c.set(`pendingDecision`,(c.get(`pendingDecision`)??0)+o);let l={running:`launchAll.skipRunning`,empty:`launchAll.skipEmpty`,pendingDecision:`launchAll.skipPendingDecision`,onReview:`launchAll.skipOnReview`},u=[];for(let[t,n]of c)n>0&&u.push(e(l[t],{count:n}));s>0&&u.push(e(`launchAll.skipInFlight`,{count:s})),a>0&&u.push(e(`launchAll.failedCount`,{count:a}));let d=u.length>0?u.join(` · `):void 0;i>0?J.success(e(`toasts.launchAllSummary`,{count:i}),d?{description:d}:void 0):J.error(e(`toasts.launchAllFailed`),d?{description:d}:void 0)}let Ye=j===null?void 0:ye.get(j),Xe=(0,Q.useRef)(null),{leftWidth:Ze,enabled:Qe,beginDrag:$e,resetToDefault:et}=uW(t,Xe),nt=typeof window<`u`?window.innerWidth:1200;return(0,$.jsx)(Nz,{children:(0,$.jsxs)(jR,{sensors:_e,collisionDetection:ve,onDragStart:Me,onDragEnd:Ne,children:[(0,$.jsxs)(`div`,{ref:Xe,className:`relative z-0 flex h-full overflow-hidden`,children:[r&&(0,$.jsx)(MP,{}),(0,$.jsx)(`div`,{className:`relative z-10 min-w-0 flex flex-col overflow-hidden`,style:Qe&&Ze!==null?{width:`${Ze}px`,flex:`0 0 auto`}:{flex:`1 1 0%`},children:(0,$.jsx)(aU,{tickets:we,allTickets:a,doneTickets:Te,isLoading:o,error:s,onRetry:()=>{p()},onTicketClick:x,onTicketCreated:e=>{x(e),p()},onTicketDelete:e=>d(e),onTicketStatusChange:(e,t)=>{l(e,t)},onTicketPriorityChange:(e,t)=>{u(e,t)},contractRefiningIds:m,sortMode:ne,sortDir:ie,onSortChange:ce,viewTier:oe,onViewTierChange:le,rails:L,onMoveToRail:Oe,continuableReviewTicketIds:De})}),Qe&&Ze!==null&&(0,$.jsx)(dW,{leftWidth:Ze,viewport:nt,onPointerDown:$e,onReset:et}),(0,$.jsx)(`div`,{className:`relative z-10 flex-1 min-w-0 flex flex-col overflow-hidden`,children:(0,$.jsx)(MU,{rails:L,ticketMap:ye,railWorktrees:z,railMetrics:V,railPrDecisions:H,onPrDecision:W,onPrCheckout:ee,providers:i,onModeChange:Pe,onProfileChange:Ie,onEngineChange:He,onFreestyleModelChange:Le,onLoopModelChange:Be,loopAvailable:ke,onLoopChange:Re,onEffortChange:Ve,onToggle:Ge,onTargetPrChange:We,onTicketClick:x,onAddRail:()=>{G()},onDeleteRail:e=>{pe(e)},onRenameRail:me,onTicketMoveToSpecs:Ae,onLaunchAll:qe,launchAllCount:be.eligible.length})})]}),(0,$.jsx)(ZR,{dropAnimation:{duration:180,easing:`ease`},children:Ye?oe===`postit`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl border border-accent-info/40 bg-card/95 shadow-xl shadow-black/30 backdrop-blur-sm p-3 rotate-1 scale-[1.02] pointer-events-none w-[260px] min-h-[180px]`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground/60`,children:[`#`,Ye.id]}),Ye.priority&&(0,$.jsx)(`span`,{className:`h-4 px-1.5 rounded-full text-[9px] font-medium uppercase bg-muted/40 text-foreground`,children:Ye.priority})]}),(0,$.jsx)(`h3`,{className:`text-sm font-medium leading-snug line-clamp-2 text-foreground`,children:Ye.title}),Ye.short_summary&&Ye.short_summary.trim().length>0&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 leading-relaxed line-clamp-3 italic`,children:Ye.short_summary})]}):(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2.5 rounded-lg border border-primary/40 bg-card/95 shadow-xl shadow-black/20 backdrop-blur-sm rotate-1 scale-[1.03] pointer-events-none`,children:[(0,$.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground/50 shrink-0`,children:[`#`,Ye.id]}),(0,$.jsx)(`span`,{className:`flex-1 text-sm truncate max-w-[240px]`,children:Ye.title})]}):N?(0,$.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-xl border border-primary/40 bg-card/95 shadow-xl shadow-black/20 backdrop-blur-sm rotate-[0.5deg] scale-[1.02] pointer-events-none`,children:(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:N})}):null}),b&&(()=>{let e=a.find(e=>e.id===b.id)??b;return(0,$.jsx)(Ee,{ticket:e,allLabels:xe,allTickets:a,onClose:()=>x(null),onOpenTicket:e=>{let t=a.find(t=>t.id===e);t&&x(t)},onSave:c,onDelete:d,rails:L,onMoveToRail:Oe,onRemoveFromRail:Ae},e.id)})(),(0,$.jsx)(fW,{open:S,allLabels:xe,onClose:()=>C(!1),onCreate:f}),(0,$.jsx)(hW,{open:O,railCount:be.eligible.length,specCount:be.eligible.reduce((e,t)=>e+t.ticketIds.length,0),onCancel:()=>A(!1),onConfirm:()=>{Je()}}),(()=>{let e=E?L.find(e=>e.id===E.railId):void 0;return(0,$.jsx)(gW,{open:!!E&&!!e?.targetPr,target:e?.targetPr??null,onCancel:()=>D(null),onConfirm:()=>{let e=E?.railId;D(null),e&&Ke(e)}})})(),(()=>{let e=w?L.find(e=>e.id===w.railId):void 0,t=ze(e);return(0,$.jsx)(pW,{open:!!w&&!!e,railLabel:e?.label??``,specCount:e?.ticketIds.length??0,provider:t,model:e?.freestyleModel??Yx(t),onCancel:()=>T(null),onConfirm:()=>{let e=w?.railId;T(null),e&&Ke(e)}})})()]})})}var NW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:X(`rounded-lg border border-border bg-card text-card-foreground shadow-sm`,e),...t}));NW.displayName=`Card`;var PW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:X(`flex flex-col space-y-1 p-4`,e),...t}));PW.displayName=`CardHeader`;var FW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`h3`,{ref:n,className:X(`text-sm font-semibold leading-none tracking-tight`,e),...t}));FW.displayName=`CardTitle`;var IW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`p`,{ref:n,className:X(`text-xs text-muted-foreground`,e),...t}));IW.displayName=`CardDescription`;var LW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:X(`p-4 pt-0`,e),...t}));LW.displayName=`CardContent`;var RW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:X(`flex items-center p-4 pt-0`,e),...t}));RW.displayName=`CardFooter`;var zW=[`auto`,`canvas`,`webgl`];function BW({mode:e}){let{t}=K(`settings`),{activeProjectId:n}=pt(),[r,i]=(0,Q.useState)(Pi),[a,o]=(0,Q.useState)({}),[s,c]=(0,Q.useState)(Pi),[l,u]=(0,Q.useState)(Pi),[d,f]=(0,Q.useState)(new Set),[p,m]=(0,Q.useState)(!0),[h,g]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let t=!1;if(e===`project`&&!n){m(!1);return}return(async()=>{try{if(e===`desktop`){let e=await fetch(`/api/terminal-settings`);if(!e.ok)throw Error(`desktop settings fetch failed`);let n=await e.json();!t&&n&&typeof n==`object`&&`fontSize`in n&&(i(n),c(n),u(n),f(new Set)),t||m(!1)}else if(n){let e=await fetch(`/api/projects/${n}/terminal-settings`);if(!e.ok)throw Error(`project fetch failed`);let r=await e.json();!t&&r&&typeof r==`object`&&r.resolved&&r.desktopDefaults&&(i(r.desktopDefaults),o(r.override??{}),c(r.resolved),u(r.resolved),f(new Set)),t||m(!1)}}catch(e){t||(m(!1),console.error(e))}})(),()=>{t=!0}},[e,n]);let _=(0,Q.useMemo)(()=>d.size>0||Object.keys(l).some(e=>l[e]!==s[e]),[l,s,d]);function v(e,t){u(n=>({...n,[e]:t})),d.has(e)&&f(t=>{let n=new Set(t);return n.delete(e),n})}function y(t){e===`project`&&(f(e=>{let n=new Set(e);return n.add(t),n}),u(e=>({...e,[t]:r[t]})))}function b(){u(s),f(new Set)}async function x(){g(!0);try{let r={};for(let e of Object.keys(l)){if(d.has(e)){r[e]=null;continue}l[e]!==s[e]&&(r[e]=l[e])}if(Object.keys(r).length===0){J(t(`terminal.nothingToSave`)),g(!1);return}if(e===`desktop`){let e=await fetch(`/api/terminal-settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)});if(!e.ok)throw Error(await e.text()||`patch failed`);let n=await e.json();i(n),c(n),u(n),f(new Set),nF({mode:`desktop`,projectId:null}),J.success(t(`terminal.saved`))}else if(n){let e=await fetch(`/api/projects/${n}/terminal-settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)});if(!e.ok)throw Error(await e.text()||`patch failed`);let a=await e.json();i(a.desktopDefaults),o(a.override),c(a.resolved),u(a.resolved),f(new Set),nF({mode:`project`,projectId:n}),J.success(t(`terminal.saved`))}}catch(e){J.error(t(`errors.saveFailed`,{message:e.message}))}finally{g(!1)}}function S(t){return e!==`project`||d.has(t)?!1:a[t]!==void 0}return p?(0,$.jsx)(NW,{children:(0,$.jsx)(LW,{children:t(`common:states.loading`)})}):(0,$.jsxs)(NW,{children:[(0,$.jsxs)(PW,{children:[(0,$.jsx)(FW,{children:t(`terminal.title`)}),(0,$.jsx)(IW,{children:t(e===`desktop`?`terminal.desktopDescription`:`terminal.projectDescription`)})]}),(0,$.jsxs)(LW,{className:`space-y-4`,children:[(0,$.jsx)(VW,{label:t(`terminal.fontFamily`),overridden:S(`fontFamily`),onClear:()=>y(`fontFamily`),mode:e,children:(0,$.jsx)(Jj,{value:l.fontFamily,onChange:e=>v(`fontFamily`,e.target.value)})}),(0,$.jsx)(VW,{label:t(`terminal.fontSize`,{min:8,max:32}),overridden:S(`fontSize`),onClear:()=>y(`fontSize`),mode:e,children:(0,$.jsx)(Jj,{type:`number`,min:8,max:32,value:l.fontSize,onChange:e=>v(`fontSize`,parseInt(e.target.value,10)||l.fontSize)})}),(0,$.jsx)(VW,{label:t(`terminal.renderMode`),overridden:S(`renderMode`),onClear:()=>y(`renderMode`),mode:e,children:(0,$.jsx)(`select`,{value:l.renderMode,onChange:e=>v(`renderMode`,e.target.value),className:`border rounded px-2 py-1 bg-transparent`,children:zW.map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))})}),(0,$.jsx)(HW,{label:t(`terminal.copyOnSelect`),checked:l.copyOnSelect,overridden:S(`copyOnSelect`),onClear:()=>y(`copyOnSelect`),onChange:e=>v(`copyOnSelect`,e),mode:e}),(0,$.jsx)(HW,{label:t(`terminal.shellIntegration`),checked:l.shellIntegrationEnabled,overridden:S(`shellIntegrationEnabled`),onClear:()=>y(`shellIntegrationEnabled`),onChange:e=>v(`shellIntegrationEnabled`,e),mode:e}),(0,$.jsx)(HW,{label:t(`terminal.notifyLongRunning`),checked:l.notifyOnCompletion,overridden:S(`notifyOnCompletion`),onClear:()=>y(`notifyOnCompletion`),onChange:e=>v(`notifyOnCompletion`,e),mode:e}),(0,$.jsx)(VW,{label:t(`terminal.longCommandThreshold`),overridden:S(`longCommandThresholdMs`),onClear:()=>y(`longCommandThresholdMs`),mode:e,children:(0,$.jsx)(Jj,{type:`number`,min:1e3,value:l.longCommandThresholdMs,onChange:e=>v(`longCommandThresholdMs`,parseInt(e.target.value,10)||l.longCommandThresholdMs)})}),(0,$.jsx)(HW,{label:t(`terminal.imageRendering`),checked:l.imageRendering,overridden:S(`imageRendering`),onClear:()=>y(`imageRendering`),onChange:e=>v(`imageRendering`,e),mode:e}),(0,$.jsx)(VW,{id:`terminal-browser-shortcut-url`,label:t(`terminal.browserShortcutUrl`),overridden:S(`browserShortcutUrl`),onClear:()=>y(`browserShortcutUrl`),mode:e,children:(0,$.jsx)(Jj,{type:`url`,value:l.browserShortcutUrl,placeholder:`https://specrails.dev`,onChange:e=>v(`browserShortcutUrl`,e.target.value)})}),(0,$.jsx)(VW,{id:`terminal-quick-script`,label:t(`terminal.quickScript`),overridden:S(`quickScript`),onClear:()=>y(`quickScript`),mode:e,children:(0,$.jsx)(`textarea`,{value:l.quickScript,placeholder:`echo "Hello World!"`,onChange:e=>v(`quickScript`,e.target.value),rows:3,className:`w-full border rounded px-2 py-1 bg-transparent font-mono text-xs`})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 pt-2 border-t`,children:[(0,$.jsx)(Z,{onClick:x,disabled:!_||h,children:t(h?`common:states.saving`:`common:actions.save`)}),(0,$.jsx)(Z,{variant:`ghost`,onClick:b,disabled:!_||h,children:t(`terminal.reset`)}),_&&(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t(`terminal.unsavedChanges`)})]})]})]})}function VW({id:e,label:t,overridden:n,onClear:r,mode:i,children:a}){let{t:o}=K(`settings`);return(0,$.jsxs)(`div`,{id:e,"data-terminal-settings-anchor":e?``:void 0,className:e?`scroll-mt-4`:void 0,children:[(0,$.jsxs)(`div`,{className:`flex justify-between items-center mb-1`,children:[(0,$.jsx)(`label`,{className:`text-sm font-medium`,children:t}),i===`project`&&n&&(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:r,children:o(`terminal.clearOverride`)})]}),a,i===`project`&&!n&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:o(`terminal.inheritingDefault`)})]})}function HW({label:e,checked:t,overridden:n,onClear:r,onChange:i,mode:a}){let{t:o}=K(`settings`);return(0,$.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,$.jsx)(`label`,{className:`text-sm font-medium`,children:e}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a===`project`&&n&&(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:r,children:o(`terminal.clear`)}),(0,$.jsx)(`button`,{type:`button`,role:`switch`,"aria-label":e,"aria-checked":t,onClick:()=>i(!t),className:`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${t?`bg-primary`:`bg-input`}`,children:(0,$.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-background shadow-sm transition-transform ${t?`translate-x-4`:`translate-x-0.5`}`})})]})]})}function UW(){let{activeProjectId:e,projects:t,refreshProjects:n}=pt(),r=t.find(t=>t.id===e);return r?(0,$.jsx)(WW,{project:r,refreshProjects:n},r.id):null}function WW({project:e,refreshProjects:t}){let{t:n}=K(`common`),[r,i]=(0,Q.useState)(()=>Er(e)),[a,o]=(0,Q.useState)(null),[s,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(null),b=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>(b.current=!0,()=>{b.current=!1}),[]),(0,Q.useEffect)(()=>{i(Er(e))},[e]);let x=`${Tr(e.id)}/repositories`;function S(e){y(null),o(e??null),l(!e),d(e?.path??``),p(e?.name??``),h(e?.integrationBranch??``)}async function C(e,n){if(!g){_(!0),y(null);try{let r=await fetch(n?`${x}/${encodeURIComponent(n)}`:x,{method:e,headers:{"Content-Type":`application/json`},...e===`DELETE`?{}:{body:JSON.stringify({...!a||!a.isPrimary&&u.trim()!==a.path?{path:u.trim()}:{},...f.trim()?{name:f.trim()}:{},integrationBranch:m.trim()||null})}});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error??`HTTP ${r.status}`)}let s=await fetch(x,{cache:`no-store`});if(!s.ok)throw Error(`HTTP ${s.status}`);let c=await s.json();b.current&&(i(c.repositories),l(!1),o(null)),await t?.()}catch(e){b.current&&y(e instanceof Error?e.message:String(e))}finally{b.current&&_(!1)}}}return(0,$.jsxs)(NW,{children:[(0,$.jsxs)(PW,{children:[(0,$.jsxs)(FW,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ws,{className:`h-4 w-4`}),n(`repositories.title`)]}),(0,$.jsx)(IW,{children:n(`repositories.sharedBacklog`)})]}),(0,$.jsxs)(LW,{className:`space-y-4`,children:[(0,$.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-border p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.isPrimary?n(`repositories.primary`):e.kind===`folder`?n(`repositories.contextOnly`):`Git`}),e.available===!1&&(0,$.jsx)(`span`,{className:`text-xs text-destructive`,children:n(`repositories.unavailable`)}),(0,$.jsxs)(`div`,{className:`ml-auto flex gap-1`,children:[(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,disabled:g,onClick:()=>S(e),children:n(`actions.edit`)}),!e.isPrimary&&(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,disabled:g,onClick:()=>void C(`DELETE`,e.id),children:n(`repositories.detach`)})]})]}),(0,$.jsx)(`p`,{className:`break-all text-xs text-muted-foreground`,children:e.path}),e.integrationBranch&&(0,$.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[n(`repositories.integrationBranch`),`: `,e.integrationBranch]})]},e.id))}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`repositories.detachHint`)}),v&&(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:v}),s||a?(0,$.jsxs)(`form`,{className:`space-y-3 rounded-lg border border-border p-3`,onSubmit:e=>{e.preventDefault(),C(a?`PATCH`:`POST`,a?.id)},children:[(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`repositories.name`),(0,$.jsx)(Jj,{value:f,disabled:g,onChange:e=>p(e.target.value)})]}),(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`repositories.path`),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Jj,{value:u,required:!0,disabled:g||a?.isPrimary,onChange:e=>d(e.target.value)}),`__TAURI_INTERNALS__`in window&&!a?.isPrimary&&(0,$.jsx)(Z,{type:`button`,variant:`outline`,disabled:g,"aria-label":n(`repositories.browse`),onClick:async()=>{try{let{open:e}=await c(async()=>{let{open:e}=await import(`./dist-js-CJ_2XX1Y.js`);return{open:e}},__vite__mapDeps([87,0,1])),t=await e({directory:!0,multiple:!1});typeof t==`string`&&b.current&&d(t)}catch{}},children:(0,$.jsx)(Ts,{className:`h-4 w-4`})})]})]}),(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`repositories.integrationBranch`),(0,$.jsx)(Jj,{value:m,disabled:g,placeholder:n(`repositories.branchDefault`),onChange:e=>h(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Z,{type:`submit`,size:`sm`,disabled:g||!u.trim(),children:n(g?`actions.saving`:`actions.save`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:`ghost`,disabled:g,onClick:()=>{l(!1),o(null),y(null)},children:n(`actions.cancel`)})]})]}):(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,disabled:g,onClick:()=>S(),children:[(0,$.jsx)(Pn,{className:`mr-1 h-4 w-4`}),n(`repositories.addFolder`)]})]})]})}var GW=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function KW({value:e,capability:t,onChange:n}){let{t:r}=K(`agentRuntime`),i=t?.effortSupport===`supported`?t.supportedEfforts??[]:[];return(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[r(`efficiency.effort`),(0,$.jsxs)(`select`,{"aria-label":r(`efficiency.effort`),className:GW,value:e??``,onChange:e=>n(e.target.value||void 0),children:[(0,$.jsx)(`option`,{value:``,children:r(`efficiency.providerDefault`)}),i.map(e=>(0,$.jsx)(`option`,{value:e,children:e},e)),e&&!i.includes(e)&&(0,$.jsxs)(`option`,{value:e,children:[e,` — `,r(`efficiency.unconfirmed`)]})]}),(0,$.jsx)(`span`,{className:`block text-muted-foreground`,children:t?.effortSupport===`supported`?t.transport:r(`efficiency.unknownSupport`)})]})}function qW({role:e,agent:t,capabilities:n,onChange:r}){let{t:i}=K(`agentRuntime`),a=r=>n.find(n=>n.role===e&&n.tier===r&&n.provider===t.provider&&n.model===((r===`base`?t.model:t.escalation?.model)??null));return(0,$.jsxs)(`div`,{className:`mt-3 space-y-3 border-t pt-3`,children:[(0,$.jsx)(KW,{value:t.effort,capability:a(`base`),onChange:e=>r({...t,effort:e})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:!!t.escalation,disabled:!t.model,onChange:e=>r({...t,escalation:e.target.checked?{model:``}:void 0})}),i(`efficiency.escalation`)]}),(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[i(`efficiency.triggers.${e}`),` `,!t.model&&i(`efficiency.baseRequired`)]}),t.escalation&&(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[i(`efficiency.escalationModel`),(0,$.jsx)(Jj,{value:t.escalation.model,onChange:e=>r({...t,escalation:{...t.escalation,model:e.target.value,effort:void 0}})})]}),(0,$.jsx)(KW,{value:t.escalation.effort,capability:a(`escalation`),onChange:e=>r({...t,escalation:{...t.escalation,effort:e}})})]})]})}function JW({config:e,onChange:t}){let{t:n}=K(`agentRuntime`),r=e.efficiency??{schemaVersion:1};return(0,$.jsxs)(`section`,{className:`space-y-3`,"aria-label":n(`efficiency.title`),children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium`,children:n(`efficiency.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`efficiency.scope`)}),(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[`contextMode`,`reviewMode`,`planning`].map(i=>(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`efficiency.${i}`),(0,$.jsxs)(`select`,{className:GW,value:r[i]??(i===`planning`?`proportional`:`incremental`),onChange:n=>t({...e,efficiency:{...r,[i]:n.target.value}}),children:[(0,$.jsx)(`option`,{value:i===`planning`?`proportional`:`incremental`,children:n(`efficiency.adaptive`)}),(0,$.jsx)(`option`,{value:`full`,children:n(`efficiency.full`)})]})]},i))}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:r.acceptDeveloperChecks!==!1,onChange:n=>t({...e,efficiency:{...r,acceptDeveloperChecks:n.target.checked}})}),n(`efficiency.developerChecks`)]}),(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`efficiency.concurrency`),(0,$.jsx)(Jj,{type:`number`,min:`1`,max:`4`,step:`1`,value:r.verification?.maxConcurrency??1,onChange:n=>t({...e,efficiency:{...r,verification:{...r.verification,maxConcurrency:Number(n.target.value)}}})})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`efficiency.concurrencyHint`)})]})}function YW({name:e,value:t,tabs:n,onChange:r,disabled:i,ariaLabel:a}){return(0,$.jsx)(`div`,{role:`radiogroup`,"aria-label":a,className:`inline-flex max-w-full flex-wrap gap-1 rounded-lg border border-border bg-background/60 p-1`,children:n.map(n=>{let a=n.value===t;return(0,$.jsxs)(`label`,{title:n.detail?`${n.label} · ${n.detail}`:n.label,className:`relative flex cursor-pointer select-none items-center gap-1.5 rounded-md px-3 py-1.5 text-xs transition-colors ${a?`bg-primary/15 text-foreground shadow-sm ring-1 ring-primary/40`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`} ${i?`pointer-events-none opacity-50`:``}`,children:[(0,$.jsx)(`input`,{type:`radio`,className:`absolute inset-0 h-full w-full cursor-pointer appearance-none opacity-0`,"aria-label":n.name??n.label,name:e,value:n.value,checked:a,disabled:i,onChange:()=>r(n.value)}),n.local?(0,$.jsx)(xc,{className:`h-3 w-3 opacity-70`,"aria-hidden":!0}):n.value?(0,$.jsx)(fs,{className:`h-3 w-3 opacity-70`,"aria-hidden":!0}):null,(0,$.jsx)(`span`,{className:`font-medium`,children:n.label}),n.local&&n.detail&&(0,$.jsx)(`span`,{className:`hidden max-w-[12rem] truncate text-[10px] opacity-60 sm:inline`,children:n.detail})]},n.value||`__inherit`)})})}var XW=[`verifier`,`decider`],ZW=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function QW(e){let t=e?.roles;if(!t||typeof t!=`object`)return{};let n={};for(let e of XW){let r=t[e];if(r&&typeof r==`object`&&typeof r.provider==`string`){let{provider:t,model:i,effort:a}=r;n[e]={provider:t,...i?{model:i}:{},...a?{effort:a}:{}}}}return n}function $W(e){let{t}=K(`agentRuntime`),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(!1),o=(0,Q.useRef)({}),s=`${Tr(e)}/agent-runtime/loop-roles`;(0,Q.useEffect)(()=>{let e=!1;return r(null),a(!1),fetch(s,{cache:`no-store`}).then(async t=>{if(!t.ok)throw Error(`loop_roles`);let n=QW(await t.json());e||(o.current=n,r(n))}).catch(()=>{e||(r({}),a(!0))}),()=>{e=!0}},[s]);async function c(e){let n=o.current;o.current=e,r(e);try{let n=await fetch(s,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({roles:e})}),i=await n.json().catch(()=>null);if(!n.ok)throw Error(i?.message??t(`loopRoles.saveFailed`));let a=QW(i);o.current=a,r(a)}catch(e){o.current=n,r(n),J.error(e instanceof Error&&e.message?e.message:t(`loopRoles.saveFailed`))}}return{roles:n,failed:i,setRole:(e,t)=>{let n={...o.current};t?n[e]=t:delete n[e],c(n)}}}function eG(e){return e&&(e.model||Yx(e.provider))||null}function tG({role:e,engine:t,providers:n,enabled:r,onChange:i}){let{t:a}=K(`agentRuntime`),o=Zx(),s=e=>{let t=o.providers[e]?.models;return t&&t.length?t:Jx(e).map(e=>e.value)},c=t?.provider,l=At(c),u=c?Jx(c):[],d=c?Yx(c):``,f=t?.model&&!u.some(e=>e.value===t.model)?t.model:null,p=t?.model||d||null,m=c?vt(c,p):[],h=!!c&&Et(c,p);return(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`fieldset`,{className:`space-y-2 sm:col-span-2`,children:[(0,$.jsx)(`legend`,{className:`text-xs`,children:a(`agents.provider`)}),(0,$.jsx)(YW,{name:`loop-role-${e}-provider`,value:c??``,ariaLabel:a(`agents.provider`),disabled:!r,tabs:[{value:``,label:a(`loopRoles.inherit`)},...n.map(e=>({value:e,label:jt(e),detail:e,local:At(e)}))],onChange:e=>i(e?{provider:e}:null)})]}),c&&!l&&(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[a(`loopRoles.model`),(0,$.jsxs)(`select`,{className:ZW,value:t?.model??``,onChange:e=>i({provider:c,...e.target.value?{model:e.target.value}:{}}),children:[(0,$.jsx)(`option`,{value:``,children:a(`agents.defaultModel`,{model:u.find(e=>e.value===d)?.label??d})}),u.map(e=>(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value)),f&&(0,$.jsx)(`option`,{value:f,children:f})]})]}),c&&l&&(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[a(`loopRoles.model`),(0,$.jsx)(Jj,{defaultValue:t?.model??``,list:`loop-role-${e}-models-${c}`,placeholder:a(`agents.modelPlaceholder`),onBlur:e=>{let n=e.target.value.trim();(t?.model??``)!==n&&i({provider:c,...n?{model:n}:{}})}}),(0,$.jsx)(`datalist`,{id:`loop-role-${e}-models-${c}`,children:s(c).map(e=>(0,$.jsx)(`option`,{value:e},e))})]}),h&&(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[a(`loopRoles.effort`),(0,$.jsxs)(`select`,{className:ZW,value:t?.effort??``,onChange:e=>i({provider:c,...t?.model?{model:t.model}:{},...e.target.value?{effort:e.target.value}:{}}),children:[(0,$.jsx)(`option`,{value:``,children:a(`agents.defaultModel`,{model:`—`})}),m.map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))]})]})]})}var nG=[`architect`,`developer`,`verification`,`fixer`,`reviewer`,`verifier`,`decider`],rG={architect:`core`,developer:`core`,verification:`core`,fixer:`core`,reviewer:`core`,verifier:`loop`,decider:`loop`},iG=[`core`,`loop`],aG={core:nG.filter(e=>rG[e]===`core`),loop:nG.filter(e=>rG[e]===`loop`)};function oG(e){return aG[rG[e]].indexOf(e)+1}var sG={architect:ss,developer:Ns,verification:Cc,fixer:Bn,reviewer:vs,verifier:ts,decider:On};function cG({engine:e,className:t=``}){let{t:n}=K(`agentRuntime`),r=`inline-flex max-w-full items-center gap-1 rounded-md border px-1.5 py-0.5 text-[11px] leading-4 ${t}`;if(e.kind===`inherit`||e.kind===`inherit-developer`)return(0,$.jsx)(`span`,{"data-testid":`engine-chip`,className:`${r} border-border/60 bg-muted/40 text-muted-foreground`,children:n(e.kind===`inherit`?`pipeline.inherits`:`pipeline.inheritsDeveloper`)});if(e.kind===`host`)return(0,$.jsxs)(`span`,{"data-testid":`engine-chip`,className:`${r} border-accent-info/30 bg-accent-info/10 text-accent-info`,children:[(0,$.jsx)(Ac,{className:`h-3 w-3 shrink-0 opacity-80`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`truncate`,children:[n(`pipeline.host`),` · `,(0,$.jsx)(`span`,{className:`font-mono`,children:e.command||n(`pipeline.noCommand`)})]})]});let i=[e.label,e.model,e.effort].filter(e=>!!e),a=e.local?xc:fs;return(0,$.jsxs)(`span`,{"data-testid":`engine-chip`,className:`${r} border-accent-primary/30 bg-accent-primary/10 text-accent-primary`,children:[(0,$.jsx)(a,{className:`h-3 w-3 shrink-0 opacity-80`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`truncate`,children:i.join(` · `)})]})}function lG({group:e,className:t=``}){let{t:n}=K(`agentRuntime`),r=e===`loop`;return(0,$.jsxs)(`div`,{className:`space-y-0.5 ${t}`,"data-testid":`phase-group-heading-${e}`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[r&&(0,$.jsx)(hc,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`text-xs font-semibold ${r?`text-muted-foreground`:`text-foreground`}`,children:n(`pipeline.groups.${e}.title`)}),r&&(0,$.jsx)(`span`,{className:`inline-flex h-4 items-center rounded border border-border/60 bg-muted/40 px-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:n(`pipeline.groups.loop.chip`)})]}),(0,$.jsx)(`p`,{className:`text-[11px] leading-4 text-muted-foreground`,children:n(`pipeline.groups.${e}.hint`)})]})}function uG({steps:e,active:t,onSelect:n}){let{t:r}=K(`agentRuntime`);return(0,$.jsx)(`div`,{className:`flex flex-col gap-3 lg:flex-row lg:items-stretch`,"data-testid":`pipeline-stepper`,children:iG.map((i,a)=>{let o=e.filter(e=>rG[e.id]===i),s=i===`loop`;return(0,$.jsxs)(`div`,{className:`contents`,children:[a>0&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 lg:flex-col lg:justify-center lg:gap-1 lg:px-1`,"aria-hidden":!0,"data-testid":`phase-group-divider`,children:[(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border lg:h-auto lg:w-px lg:flex-1`}),(0,$.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground/70 lg:[writing-mode:vertical-rl]`,children:r(`pipeline.groups.loop.chip`)}),(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border lg:h-auto lg:w-px lg:flex-1`})]}),(0,$.jsxs)(`section`,{"aria-labelledby":`pipeline-group-${i}-title`,"data-testid":`pipeline-group-${i}`,className:`min-w-0 space-y-2 rounded-lg border p-2.5 ${s?`border-dashed border-border/70 bg-muted/20`:`border-accent-primary/25 bg-accent-primary/5`}`,children:[(0,$.jsx)(`h4`,{id:`pipeline-group-${i}-title`,className:`sr-only`,children:r(`pipeline.groups.${i}.title`)}),(0,$.jsx)(lG,{group:i}),(0,$.jsx)(`ol`,{className:`flex flex-wrap items-stretch gap-y-2`,"aria-label":r(`pipeline.groups.${i}.title`),children:o.map((e,i)=>{let a=sG[e.id],c=e.id===t;return(0,$.jsxs)(`li`,{className:`flex min-w-0 items-center`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-current":c?`step`:void 0,"aria-label":`${i+1}. ${r(`pipeline.phases.${e.id}.name`)}`,onClick:()=>n(e.id),className:`group flex w-44 min-w-0 flex-col gap-1.5 rounded-lg border p-2.5 text-left transition-colors ${c?`border-primary/40 bg-primary/10 shadow-sm ring-1 ring-primary/40`:s?`border-border/70 bg-background/40 hover:bg-muted/60`:`border-border bg-background/60 hover:bg-muted/60`}`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-[10px] font-semibold ${c?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground group-hover:text-foreground`}`,children:i+1}),(0,$.jsx)(a,{className:`h-3.5 w-3.5 shrink-0 ${c?`text-primary`:`text-muted-foreground`}`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`truncate text-xs font-medium ${s&&!c?`text-foreground/80`:``}`,children:r(`pipeline.phases.${e.id}.name`)})]}),(0,$.jsx)(`span`,{className:`line-clamp-2 text-[11px] leading-4 text-muted-foreground`,children:r(`pipeline.phases.${e.id}.purpose`)}),(0,$.jsx)(cG,{engine:e.engine})]}),i<o.length-1&&(0,$.jsx)(`span`,{className:`flex w-5 shrink-0 items-center justify-center text-muted-foreground/60`,"aria-hidden":!0,children:(0,$.jsx)(Zo,{className:`h-3.5 w-3.5`})})]},e.id)})})]})]},i)})})}var dG=(0,Q.forwardRef)(function({phase:e,engine:t,open:n,active:r,onToggle:i,children:a},o){let{t:s}=K(`agentRuntime`),c=oG(e),l=sG[e],u=s(`pipeline.phases.${e}.name`),d=`pipeline-phase-${e}-body`;return(0,$.jsxs)(`fieldset`,{ref:o,id:`pipeline-phase-${e}`,"data-testid":`phase-card-${e}`,className:`scroll-mt-4 rounded-lg border transition-shadow ${r?`border-primary/40 ring-1 ring-primary/30`:`border-border`}`,children:[(0,$.jsx)(`legend`,{className:`sr-only`,children:u}),(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":n,"aria-controls":d,"aria-label":`${s(n?`pipeline.collapse`:`pipeline.open`)}: ${c}. ${u}`,onClick:i,className:`flex w-full flex-wrap items-center gap-2 rounded-t-lg px-3 py-2 text-left hover:bg-muted/40`,children:[(0,$.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-[10px] font-semibold ${r?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground`}`,children:c}),(0,$.jsx)(l,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:u}),(0,$.jsxs)(`span`,{className:`hidden text-[11px] text-muted-foreground sm:inline`,children:[`— `,s(`pipeline.phases.${e}.purpose`)]}),(0,$.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[(0,$.jsx)(cG,{engine:t}),(0,$.jsx)(Xo,{className:`h-3.5 w-3.5 text-muted-foreground transition-transform ${n?``:`-rotate-90`}`,"aria-hidden":!0})]})]}),(0,$.jsx)(`div`,{id:d,hidden:!n,className:`space-y-2 px-3 pb-3`,children:a})]})}),fG=[`claude`,`codex`,`gemini`,`kimi`],pG=[`architect`,`developer`,`reviewer`],mG=[...pG,`fixer`];function hG(e){return e.kind===`openai-compatible`&&e.label?.trim()?e.label.trim():e.id}function gG(e){if(!e||typeof e!=`object`)return!1;let t=e;return Array.isArray(t.providers)&&t.providers.every(e=>e&&typeof e.id==`string`&&[`cli`,`openai-compatible`].includes(e.kind))&&(t.status===void 0||typeof t.status==`object`&&t.status!==null)}var _G=[`architect`,`developer`,`host`];function vG(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.supported==`boolean`&&Array.isArray(t.catalog)&&t.catalog.every(e=>e&&typeof e.id==`string`&&_G.includes(e.phase))}function yG(e,t,n){let r={...e};return n?delete r[t]:r[t]=!1,Object.keys(r).length?r:void 0}var bG=[`type_correctness`,`pattern_adherence`,`test_coverage`,`security`,`architectural_alignment`],xG=[`ask`,`proceed`],SG={minScore:70,aspects:{type_correctness:60,pattern_adherence:60,test_coverage:60,security:75,architectural_alignment:60}},CG={maxTurns:100,maxAttempts:3,timeoutMs:15*6e4};function wG(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t.config;return typeof t.configured==`boolean`&&typeof t.runtimeAvailable==`boolean`&&n?.schemaVersion===1&&typeof n.enabled==`boolean`&&Array.isArray(n.providers)&&n.providers.every(e=>e&&typeof e.id==`string`&&[`cli`,`openai-compatible`].includes(e.kind))&&Array.isArray(n.verification)&&!!n.agents&&pG.every(e=>typeof n.agents[e]?.provider==`string`)}function TG(e){if(!e||typeof e!=`object`)return!1;let t=e;return Array.isArray(t.repositories)&&Array.isArray(t.suggestions)&&t.suggestions.every(e=>e&&typeof e.repositoryId==`string`&&typeof e.command==`string`&&Array.isArray(e.args))}function EG(e,t){let n=t,r=2;for(;e.some(({id:e})=>e===n);)n=`${t}-${r++}`;return n}function DG(e){return[e.command,...e.args].map(e=>/[\s"]/.test(e)?JSON.stringify(e):e).join(` `)}function OG(e){let t=[],n=``,r=!1,i=!1;for(let a=0;a<e.length;a++){let o=e[a];if(r){if(o===`\\`&&a+1<e.length){n+=e[++a];continue}if(o===`"`){r=!1;continue}n+=o;continue}if(o===`"`){r=!0,i=!0;continue}if(/\s/.test(o)){i&&=(t.push(n),n=``,!1);continue}n+=o,i=!0}return r||(i&&t.push(n),!t.length||!t[0])?null:{command:t[0],args:t.slice(1)}}var kG={architect:ss,developer:Ns,host:Ac};function AG({projectId:e,guardrails:t,onChange:n}){let{t:r,i18n:i}=K(`agentRuntime`),[a,o]=(0,Q.useState)(!0),[s,c]=(0,Q.useState)({status:`loading`});(0,Q.useEffect)(()=>{let t=!1;return c({status:`loading`}),fetch(`${Tr(e)}/agent-runtime/guardrails`,{cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(`guardrails`);let n=await e.json();if(!vG(n))throw Error(`guardrails`);t||c({status:`ready`,supported:n.supported,catalog:n.catalog})}).catch(()=>{t||c({status:`unsupported`})}),()=>{t=!0}},[e]);let l=s.status===`ready`?s.catalog:[],u=s.status===`ready`&&s.supported,d=l.filter(e=>t?.[e.id]===!1).length,f=l.length,p=e=>i.exists(`agentRuntime:guardrails.items.${e}.title`),m=`pipeline-guardrails-body`;return(0,$.jsxs)(`fieldset`,{id:`pipeline-guardrails`,"data-testid":`phase-card-guardrails`,className:`scroll-mt-4 rounded-lg border border-border transition-shadow`,children:[(0,$.jsx)(`legend`,{className:`sr-only`,children:r(`guardrails.title`)}),(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":a,"aria-controls":m,"aria-label":`${r(a?`pipeline.collapse`:`pipeline.open`)}: ${r(`guardrails.title`)}`,onClick:()=>o(e=>!e),className:`flex w-full flex-wrap items-center gap-2 rounded-t-lg px-3 py-2 text-left hover:bg-muted/40`,children:[(0,$.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-accent-success/15 text-accent-success`,children:(0,$.jsx)(Cc,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:r(`guardrails.title`)}),(0,$.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[s.status===`ready`&&u&&(0,$.jsx)(`span`,{"data-testid":`guardrails-active`,className:X(`inline-flex items-center rounded-md border px-1.5 py-0.5 text-[11px] leading-4`,d?`border-accent-warning/40 bg-accent-warning/10 text-accent-warning`:`border-accent-success/30 bg-accent-success/10 text-accent-success`),children:r(`guardrails.active`,{on:f-d,total:f})}),(0,$.jsx)(Xo,{className:`h-3.5 w-3.5 text-muted-foreground transition-transform ${a?``:`-rotate-90`}`,"aria-hidden":!0})]})]}),(0,$.jsxs)(`div`,{id:m,hidden:!a,className:`space-y-3 px-3 pb-3`,children:[(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`guardrails.intro`)}),s.status===`loading`&&(0,$.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:r(`loading`)}),(s.status===`unsupported`||s.status===`ready`&&!u)&&(0,$.jsx)(`p`,{role:`status`,className:`rounded-md border border-accent-warning/40 p-3 text-xs text-accent-warning`,children:r(`guardrails.unsupported`)}),s.status===`ready`&&(0,$.jsxs)(`fieldset`,{disabled:!u,className:`space-y-3 disabled:opacity-60`,children:[d>0&&(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(`button`,{type:`button`,className:`text-[11px] text-accent-primary underline-offset-2 hover:underline`,onClick:()=>n(void 0),children:r(`guardrails.reset`)})}),_G.map(e=>{let i=l.filter(t=>t.phase===e);if(!i.length)return null;let a=kG[e];return(0,$.jsxs)(`div`,{className:`space-y-2`,"data-testid":`guardrails-phase-${e}`,children:[(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:[(0,$.jsx)(a,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),r(`guardrails.phases.${e}`)]}),(0,$.jsx)(`ul`,{className:`divide-y divide-border/60 rounded-md border border-border/60`,children:i.map(e=>{let i=t?.[e.id]!==!1,a=p(e.id)?r(`guardrails.items.${e.id}.title`):e.id,o=p(e.id)?r(`guardrails.items.${e.id}.description`):r(`guardrails.unknown`),s=p(e.id)?r(`guardrails.items.${e.id}.why`):null,c=`guardrail-${e.id}-title`;return(0,$.jsxs)(`li`,{className:`flex items-start gap-3 px-3 py-2`,children:[(0,$.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-labelledby":c,"data-testid":`guardrail-${e.id}`,onClick:()=>n(yG(t,e.id,!i)),className:X(`relative mt-0.5 inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors`,i?`bg-accent-primary/70`:`bg-muted-foreground/30`),children:(0,$.jsx)(`span`,{className:X(`absolute h-3 w-3 rounded-full bg-background shadow transition-transform`,i?`translate-x-3.5`:`translate-x-0.5`)})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{id:c,className:X(`text-xs font-medium`,!i&&`text-muted-foreground line-through decoration-muted-foreground/50`),children:a}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-4 text-muted-foreground`,children:o}),s&&(0,$.jsx)(`p`,{className:`mt-0.5 text-[10px] italic leading-4 text-muted-foreground/70`,children:s})]})]},e.id)})})]},e)})]})]})]})}var jG=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function MG(e){let t=e.parentElement;for(;t&&t!==document.body;){let e=getComputedStyle(t);if(/(auto|scroll)/.test(e.overflowY)&&t.scrollHeight>t.clientHeight)break;t=t.parentElement}if(!t||t===document.body){e.scrollIntoView?.({behavior:`smooth`,block:`nearest`});return}let n=e.getBoundingClientRect().top-t.getBoundingClientRect().top+t.scrollTop-12;typeof t.scrollTo==`function`?t.scrollTo({top:n,behavior:`smooth`}):t.scrollTop=n}function NG(){let{activeProjectId:e,projects:t}=pt(),n=(0,Q.useRef)(new Map),r=t.find(t=>t.id===e);return e?(0,$.jsx)(LG,{projectId:e,cache:n.current,projectProviderIds:r?.providers?.length?r.providers:r?.provider?[r.provider]:[],repositories:Er(r).map(({id:e,name:t})=>({id:e,name:t}))},e):null}function PG(e){return e.map(e=>({original:e,label:e.label,repositoryId:e.repositoryId,line:DG(e)}))}function FG(e){return e.map(e=>({repositoryId:e.repositoryId,line:DG(e),reason:e.reason}))}function IG(e){return e===void 0?``:String(Math.round(e/6e4*100)/100)}function LG({projectId:e,cache:t,repositories:n,projectProviderIds:r}){let{t:i}=K([`agentRuntime`,`agents`]),a=Zx(),o=t.get(e),[s,c]=(0,Q.useState)(o??null),[l,u]=(0,Q.useState)(o?.config??null),[d,f]=(0,Q.useState)(PG(o?.config.verification??[])),[p,m]=(0,Q.useState)([]),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(!1),[C,w]=(0,Q.useState)(null),[T,E]=(0,Q.useState)(!o),[D,O]=(0,Q.useState)(``),[k,A]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(0),[F,I]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(()=>Object.fromEntries(nG.map(e=>[e,!0]))),z=(0,Q.useRef)({}),B=$W(e),V=(0,Q.useRef)(!1),H=(0,Q.useRef)(!0),U=`${Tr(e)}/agent-runtime/config`,W=(0,Q.useRef)(0),ee=(0,Q.useRef)(l);ee.current=l;let te=JSON.stringify([e,l?.providers,l&&pG.map(e=>{let t=l.agents[e];return[e,t.provider,t.model??null,t.escalation?.model||null]}),l?.fixer?[`fixer`,l.fixer.provider,l.fixer.model??null,l.fixer.escalation?.model||null]:null]);async function ne(t){if(!ee.current)return;let n=structuredClone(ee.current);for(let e of[...Object.values(n.agents),...n.fixer?[n.fixer]:[]])e.escalation&&!e.escalation.model.trim()&&delete e.escalation;let r=++W.current;g(!0),v(!1);try{let i=await fetch(`${Tr(e)}/agent-runtime/capabilities`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n),signal:t}),a=await i.json();if(!i.ok||a.schemaVersion!==1||!Array.isArray(a.roles))throw Error(`capabilities`);H.current&&!t?.aborted&&r===W.current&&m(a.roles)}catch{H.current&&!t?.aborted&&r===W.current&&(m([]),v(!0))}finally{H.current&&!t?.aborted&&r===W.current&&g(!1)}}(0,Q.useEffect)(()=>{if(W.current++,m([]),v(!1),!ee.current||s?.efficiencyAvailable===!1){g(!1);return}let e=new AbortController;g(!0);let t=setTimeout(()=>{ne(e.signal)},250);return()=>{clearTimeout(t),e.abort(),W.current++}},[te,s?.efficiencyAvailable,N]);let re=`${Tr(e)}/agent-runtime/verification-suggestions`;async function ie(){try{let e=await fetch(re,{cache:`no-store`});if(!e.ok)return null;let t=await e.json();return TG(t)?t.suggestions:null}catch{return null}}(0,Q.useEffect)(()=>{H.current=!0;let n=!1;return fetch(U,{cache:`no-store`}).then(async r=>{if(!r.ok)throw Error(i(`loadFailed`));let a=await r.json();if(!wG(a))throw Error(i(`loadFailed`));if(!n){if(t.set(e,a),c(a),!V.current&&(u(a.config),f(PG(a.config.verification)),!a.configured&&a.config.verification.length===0)){let e=await ie();if(n||V.current)return;e?.length?(f(FG(e)),w(`some`)):e&&w(`none`)}O(``)}}).catch(()=>{n||O(i(`loadFailed`))}).finally(()=>{n||E(!1)}),()=>{n=!0,H.current=!1}},[U,e,t,N,i]);function ae(e){V.current=!0,A(!1),M(!0),u(e)}function oe(e){V.current=!0,A(!1),M(!0),f(e)}function se(e){if(e.kind===`cli`)return{value:e.id,label:i(`cliNames.${e.cli}`),detail:e.id,name:`${i(`cliNames.${e.cli}`)} (${e.id})`};let t=e.label?.trim();return{value:e.id,label:t||e.id,detail:t?`${e.id} · ${e.baseUrl}`:e.baseUrl,local:!0,name:t?`${t} (${e.id}) · ${e.baseUrl}`:`${e.id} · ${e.baseUrl}`}}function ce(e){if(e.kind!==`openai-compatible`)return[];let t=a.providers[e.id]?.models,n=t&&t.length?t:Jx(e.id).map(e=>e.value);return e.defaultModel&&!n.includes(e.defaultModel)?[e.defaultModel,...n]:n}function le(){let e=[];for(let t of d){if(!t.line.trim()&&!t.repositoryId)continue;let n=OG(t.line);if(!n||!t.repositoryId)return O(i(`verification.invalidLine`,{line:t.line||`∅`})),null;e.push({...t.original,...t.label===void 0?{}:{label:t.label.trim()||void 0},repositoryId:t.repositoryId,...n})}return e}async function ue(){S(!0),O(``);try{let e=await ie();if(!H.current)return;if(!e){O(i(`verification.detectFailed`));return}let t=new Set(d.map(e=>`${e.repositoryId}\0${e.line}`)),n=FG(e).filter(e=>!t.has(`${e.repositoryId}\0${e.line}`));oe([...d,...n]),w(e.length?`some`:`none`)}finally{H.current&&S(!1)}}async function de(){if(!l||y)return;O(``),A(!1);let n=le();if(n){b(!0);try{let r=await fetch(U,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...l,verification:n})}),a=await r.json();if(!r.ok)throw Error(a.message??a.error??i(`saveFailed`));if(!wG(a))throw Error(i(`saveFailed`));if(t.set(e,a),!H.current)return;V.current=!1,M(!1),c(a),u(a.config),f(PG(a.config.verification)),A(!0)}catch(e){H.current&&O(e instanceof Error?e.message:i(`saveFailed`))}finally{H.current&&b(!1)}}}let fe=l?.limits??{},G=(e,t,n=1)=>{if(!l)return;let r={...l.limits};t===``?delete r[e]:r[e]=e===`maxCostUsd`?Number(t):Math.round(Number(t)*n),ae({...l,limits:Object.keys(r).length?r:void 0})},pe=l?.review??{},me=(e,t)=>{if(!l)return;let n=t===``?void 0:Number(t),r={...pe.aspects};e!==`minScore`&&(n===void 0?delete r[e]:r[e]=n);let i={},a=e===`minScore`?n:pe.minScore;a!==void 0&&(i.minScore=a),Object.keys(r).length&&(i.aspects=r),ae({...l,review:Object.keys(i).length?i:void 0})},he=e=>{l&&ae({...l,architect:e?{onLowConfidence:e}:void 0})},ge=r.length?r:(l?.providers??[]).map(e=>e.id),_e=!!l?.enabled&&s?.runtimeAvailable!==!1;function ve(e){if(!l)return{kind:`inherit`};if(e===`verification`)return{kind:`host`,command:d.find(e=>e.line.trim())?.line.trim()??null};if(e===`verifier`||e===`decider`){let t=B.roles?.[e];return t?{kind:`ai`,label:jt(t.provider),model:eG(t),effort:t.effort??null,local:At(t.provider)}:{kind:`inherit`}}if(e===`fixer`&&!l.fixer)return{kind:`inherit-developer`};let t=e===`fixer`?l.fixer:l.agents[e],n=l.providers.find(e=>e.id===t.provider),r=n?se(n).label:t.provider,i=n?.kind===`openai-compatible`;return{kind:`ai`,label:r,model:t.model??(n?.kind===`cli`?Yx(n.cli):n?.defaultModel)??null,effort:t.effort??null,local:i}}let ye=nG.map(e=>({id:e,engine:ve(e)}));function be(e){I(e),R(t=>({...t,[e]:!0}));let t=z.current[e];t&&MG(t)}function xe(e){I(e),R(t=>({...t,[e]:!t[e]}))}function Se(e){if(!l)return null;let t=e===`fixer`?l.fixer:l.agents[e];if(!t)return null;let n=l.providers.find(e=>e.id===t.provider),r=t=>ae(e===`fixer`?{...l,fixer:t}:{...l,agents:{...l.agents,[e]:t}}),a=n?.kind===`cli`?Jx(n.cli):[],o=n?.kind===`cli`?Yx(n.cli):``,c=t.model&&!a.some(e=>e.value===t.model)?t.model:null;return(0,$.jsxs)($.Fragment,{children:[e!==`fixer`&&(0,$.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:i(`roleHints.${e}`)}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,$.jsxs)(`fieldset`,{className:`space-y-2 sm:col-span-3`,children:[(0,$.jsx)(`legend`,{className:`text-xs`,children:i(`agents.provider`)}),(0,$.jsx)(YW,{name:`runtime-${e}-provider`,value:t.provider,ariaLabel:i(`agents.provider`),tabs:l.providers.map(e=>se(e)),onChange:e=>r({...t,provider:e,model:void 0,effort:void 0,thinking:void 0,escalation:void 0})})]}),n?.kind===`cli`?(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`agents.model`),(0,$.jsxs)(`select`,{className:jG,value:t.model??``,onChange:e=>r({...t,model:e.target.value||void 0}),children:[(0,$.jsx)(`option`,{value:``,children:i(`agents.defaultModel`,{model:a.find(e=>e.value===o)?.label??o})}),a.map(e=>(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value)),c&&(0,$.jsx)(`option`,{value:c,children:c})]})]}):(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`agents.model`),(0,$.jsx)(Jj,{value:t.model??``,list:n?`runtime-${e}-models-${n.id}`:void 0,placeholder:n?.kind===`openai-compatible`&&n.defaultModel?i(`agents.defaultModel`,{model:n.defaultModel}):i(`agents.modelPlaceholder`),onChange:e=>r({...t,model:e.target.value||void 0})}),n&&(0,$.jsx)(`datalist`,{id:`runtime-${e}-models-${n.id}`,"data-testid":`runtime-${e}-models`,children:ce(n).map(e=>(0,$.jsx)(`option`,{value:e},e))})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`agents.maxTurns`,{turns:CG.maxTurns}),(0,$.jsx)(Jj,{type:`number`,min:`1`,step:`1`,placeholder:String(CG.maxTurns),value:t.maxTurns??``,onChange:e=>r({...t,maxTurns:e.target.value===``?void 0:Number(e.target.value)})})]}),n?.kind===`openai-compatible`&&(0,$.jsxs)(`fieldset`,{className:`space-y-1 text-xs`,children:[(0,$.jsx)(`legend`,{className:`text-xs`,children:i(`agents.thinking`)}),(0,$.jsx)(`div`,{role:`radiogroup`,"aria-label":i(`agents.thinking`),"data-testid":`runtime-${e}-thinking`,className:`flex w-full max-w-[12rem] rounded-lg border border-border bg-background/60 p-0.5`,children:[`off`,`on`].map(n=>{let a=(t.thinking??`off`)===n;return(0,$.jsxs)(`label`,{className:`relative flex min-w-0 flex-1 cursor-pointer items-center justify-center rounded-md px-3 py-1.5 transition-colors ${a?`bg-primary text-primary-foreground shadow-sm`:`text-muted-foreground hover:bg-muted/60`}`,children:[(0,$.jsx)(`input`,{type:`radio`,name:`runtime-${e}-thinking`,className:`absolute inset-0 h-full w-full cursor-pointer appearance-none opacity-0`,value:n,checked:a,onChange:()=>{let e={...t};n===`on`?e.thinking=`on`:delete e.thinking,r(e)}}),(0,$.jsx)(`span`,{className:`truncate`,children:i(`agents.thinking_${n}`)})]},n)})}),(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:i(`agents.thinkingHint`)})]})]}),(0,$.jsx)(`fieldset`,{disabled:s?.efficiencyAvailable===!1,children:(0,$.jsx)(qW,{role:e,agent:t,capabilities:p,onChange:r})})]})}function Ce(){if(!l)return null;let e=!!l.fixer,t=t=>{if(t===`own`===e)return;if(t===`inherit`){let e={...l};delete e.fixer,ae(e);return}let n=l.agents.developer;ae({...l,fixer:{provider:n.provider,...n.model?{model:n.model}:{}}})},n=(n,r)=>{let i=n===`own`===e;return(0,$.jsxs)(`label`,{className:`relative flex min-w-0 flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-md px-3 py-1.5 text-xs transition-colors ${i?`bg-primary text-primary-foreground shadow-sm`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`}`,children:[(0,$.jsx)(`input`,{type:`radio`,name:`runtime-fixer-mode`,className:`absolute inset-0 h-full w-full cursor-pointer appearance-none opacity-0`,value:n,checked:i,onChange:()=>t(n)}),n===`own`&&(0,$.jsx)(Bn,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`truncate`,children:r})]})};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:i(`fixer.hint`)}),(0,$.jsxs)(`fieldset`,{className:`mb-3 space-y-2`,children:[(0,$.jsx)(`legend`,{className:`text-xs`,children:i(`fixer.title`)}),(0,$.jsxs)(`div`,{role:`radiogroup`,"aria-label":i(`fixer.title`),"data-testid":`fixer-mode`,className:`flex w-full max-w-sm rounded-lg border border-border bg-background/60 p-0.5`,children:[n(`inherit`,i(`fixer.inherit`)),n(`own`,i(`fixer.own`))]})]}),e&&Se(`fixer`)]})}function we(){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`verification.hint`)}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,disabled:x,onClick:()=>void ue(),children:i(x?`verification.detecting`:`verification.detect`)})]}),C===`some`&&!d.some(e=>!e.reason)&&(0,$.jsx)(`p`,{role:`status`,className:`text-xs text-accent-success`,children:i(`verification.detected`)}),C===`none`&&d.length===0&&(0,$.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:i(`verification.nothingDetected`)}),d.map((e,t)=>(0,$.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-[minmax(8rem,1fr)_2fr_auto]`,children:[(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`verification.repository`),n.length?(0,$.jsxs)(`select`,{className:jG,value:e.repositoryId,onChange:e=>oe(d.map((n,r)=>r===t?{...n,repositoryId:e.target.value}:n)),children:[!n.some(t=>t.id===e.repositoryId)&&(0,$.jsx)(`option`,{value:e.repositoryId,children:e.repositoryId||`—`}),n.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id))]}):(0,$.jsx)(Jj,{value:e.repositoryId,onChange:e=>oe(d.map((n,r)=>r===t?{...n,repositoryId:e.target.value}:n))})]}),(0,$.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,$.jsxs)(`label`,{className:`block space-y-1`,children:[i(`verification.command`),(0,$.jsx)(Jj,{className:`font-mono`,spellCheck:!1,placeholder:`npm test`,value:e.line,onChange:e=>oe(d.map((n,r)=>r===t?{...n,line:e.target.value,reason:void 0}:n))})]}),(0,$.jsxs)(`label`,{className:`block space-y-1`,children:[i(`verification.label`),(0,$.jsx)(Jj,{maxLength:256,value:e.label??``,onChange:e=>oe(d.map((n,r)=>r===t?{...n,label:e.target.value}:n))})]}),e.reason&&(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:i(`verification.reason`,{reason:e.reason})})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-1`,children:[(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,"aria-label":`${i(`verification.moveUp`)} ${t+1}`,disabled:t===0,onClick:()=>{let e=[...d];[e[t-1],e[t]]=[e[t],e[t-1]],oe(e)},children:`↑`}),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,"aria-label":`${i(`verification.moveDown`)} ${t+1}`,disabled:t===d.length-1,onClick:()=>{let e=[...d];[e[t+1],e[t]]=[e[t],e[t+1]],oe(e)},children:`↓`}),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,onClick:()=>oe(d.filter((e,n)=>n!==t)),children:i(`verification.remove`)})]})]},t)),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,onClick:()=>oe([...d,{repositoryId:n[0]?.id??``,line:``}]),children:i(`verification.add`)})]})}function Te(e){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:i(`loopRoles.${e}Hint`)}),!_e&&(0,$.jsx)(`p`,{role:`status`,className:`rounded-md border border-accent-warning/40 p-3 text-xs text-accent-warning`,children:i(`loopRoles.disabled`)}),B.failed&&(0,$.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:i(`loadFailed`)}),B.roles===null&&!B.failed&&(0,$.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:i(`loading`)}),B.roles&&(0,$.jsx)(`fieldset`,{disabled:!_e,className:`disabled:opacity-60`,children:(0,$.jsx)(tG,{role:e,engine:B.roles[e],providers:ge,enabled:_e,onChange:t=>B.setRole(e,t)})})]})}return(0,$.jsxs)(NW,{id:`agent-runtime-settings`,children:[(0,$.jsxs)(PW,{children:[(0,$.jsx)(FW,{children:i(`title`)}),(0,$.jsx)(IW,{children:i(`description`)})]}),(0,$.jsxs)(LW,{className:`space-y-6`,children:[T&&(0,$.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:i(`loading`)}),D&&(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:D}),!l&&!T&&(0,$.jsx)(Z,{variant:`secondary`,onClick:()=>{E(!0),P(e=>e+1)},children:i(`retry`)}),l&&(0,$.jsxs)(`fieldset`,{disabled:y,className:`space-y-6 disabled:opacity-70`,children:[(0,$.jsx)(`div`,{className:`space-y-2`,children:s?.runtimeAvailable===!1&&(0,$.jsx)(`p`,{className:`rounded-md border border-accent-warning/40 p-3 text-xs text-accent-warning`,children:i(`unavailable`)})}),(0,$.jsxs)(`section`,{className:`space-y-4`,"aria-labelledby":`agent-runtime-pipeline`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`h3`,{id:`agent-runtime-pipeline`,className:`text-sm font-medium`,children:i(`pipeline.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`agents.hint`,{turns:CG.maxTurns})})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start gap-2 rounded-lg border border-accent-primary/30 bg-accent-primary/5 p-3 text-xs`,"data-testid":`pipeline-explainer`,children:[(0,$.jsxs)(`span`,{className:`inline-flex h-5 shrink-0 items-center gap-1 rounded border border-accent-primary/40 bg-accent-primary/10 px-1.5 text-[10px] text-accent-primary whitespace-nowrap`,title:i(`agents:railSelectors.rolesChipTitle`),children:[(0,$.jsx)(kn,{className:`h-3 w-3`,"aria-hidden":!0}),i(`agents:railSelectors.rolesChip`)]}),(0,$.jsx)(`p`,{className:`min-w-0 flex-1 text-muted-foreground`,children:i(`pipeline.explainer`,{roles:i(`agents:railSelectors.rolesChip`)})})]}),(0,$.jsx)(uG,{steps:ye,active:F,onSelect:be}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,disabled:h||s?.efficiencyAvailable===!1,onClick:()=>void ne(),children:i(`efficiency.checkCapabilities`)}),h&&(0,$.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:i(`loading`)}),_&&(0,$.jsx)(`p`,{className:`text-xs text-destructive`,children:i(`efficiency.capabilitiesFailed`)})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[iG.map(e=>(0,$.jsxs)(`div`,{className:`space-y-3`,"data-testid":`phase-cards-${e}`,children:[(0,$.jsx)(lG,{group:e,className:e===`loop`?`border-t border-border/60 pt-3`:``}),aG[e].map(e=>(0,$.jsx)(dG,{ref:t=>{z.current[e]=t},phase:e,engine:ve(e),open:L[e],active:F===e,onToggle:()=>xe(e),children:e===`verification`?we():e===`fixer`?Ce():e===`verifier`||e===`decider`?Te(e):Se(e)},e))]},e)),(0,$.jsx)(AG,{projectId:e,guardrails:l.guardrails,onChange:e=>{let t={...l,guardrails:e};e||delete t.guardrails,ae(t)}})]})]}),s?.efficiencyAvailable===!1&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`efficiency.capabilitiesFailed`)}),(0,$.jsx)(`fieldset`,{disabled:s?.efficiencyAvailable===!1,children:(0,$.jsx)(JW,{config:l,onChange:ae})}),(0,$.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,$.jsx)(`legend`,{className:`text-sm font-medium`,children:i(`limits.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`limits.hint`,{attempts:CG.maxAttempts,minutes:CG.timeoutMs/6e4})}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`limits.maxAttempts`,{attempts:CG.maxAttempts}),(0,$.jsx)(Jj,{type:`number`,min:`1`,step:`1`,placeholder:String(CG.maxAttempts),value:fe.maxAttempts??``,onChange:e=>G(`maxAttempts`,e.target.value)})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`limits.timeoutMinutes`,{minutes:CG.timeoutMs/6e4}),(0,$.jsx)(Jj,{type:`number`,min:`1`,step:`1`,placeholder:String(CG.timeoutMs/6e4),value:IG(fe.timeoutMs),onChange:e=>G(`timeoutMs`,e.target.value,6e4)})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`limits.maxTokens`),(0,$.jsx)(Jj,{type:`number`,min:`1`,step:`1`,placeholder:i(`limits.unlimited`),value:fe.maxTokens??``,onChange:e=>G(`maxTokens`,e.target.value)})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`limits.maxCostUsd`),(0,$.jsx)(Jj,{type:`number`,min:`0.000001`,step:`any`,placeholder:i(`limits.unlimited`),value:fe.maxCostUsd??``,onChange:e=>G(`maxCostUsd`,e.target.value)})]})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-3 text-xs`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:l.approvalBeforeArchive??!1,onChange:e=>ae({...l,approvalBeforeArchive:e.target.checked})}),i(`approvalBeforeArchive`)]})]}),(0,$.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,$.jsx)(`legend`,{className:`text-sm font-medium`,children:i(`review.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`review.hint`,{score:SG.minScore,security:SG.aspects.security,aspect:SG.aspects.type_correctness})}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`review.minScore`,{score:SG.minScore}),(0,$.jsx)(Jj,{type:`number`,min:SG.minScore,max:`100`,step:`1`,placeholder:String(SG.minScore),value:pe.minScore??``,onChange:e=>me(`minScore`,e.target.value)})]}),bG.map(e=>(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`review.aspects.${e}`,{score:SG.aspects[e]}),(0,$.jsx)(Jj,{type:`number`,min:SG.aspects[e],max:`100`,step:`1`,placeholder:String(SG.aspects[e]),value:pe.aspects?.[e]??``,onChange:t=>me(e,t.target.value)})]},e))]})]}),(0,$.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,$.jsx)(`legend`,{className:`text-sm font-medium`,children:i(`architect.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`architect.hint`)}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs sm:w-1/2`,children:[i(`architect.onLowConfidence`),(0,$.jsxs)(`select`,{className:jG,value:l.architect?.onLowConfidence??``,onChange:e=>he(e.target.value),children:[(0,$.jsx)(`option`,{value:``,children:i(`agents.defaultModel`,{model:i(`architect.ask`)})}),xG.map(e=>(0,$.jsx)(`option`,{value:e,children:i(`architect.${e}`)},e))]})]})]}),(0,$.jsx)(`div`,{className:`sticky bottom-3 z-20 flex justify-end pointer-events-none`,"data-testid":`runtime-save-pill`,"data-unsaved":j,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto flex items-center gap-3 rounded-full border px-3 py-1.5 shadow-lg backdrop-blur transition-colors ${j?`border-accent-warning/40 bg-card/95`:`border-border/60 bg-card/80`}`,children:[j&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-accent-warning`,children:[(0,$.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-accent-warning`,"aria-hidden":!0}),i(`unsavedChanges`)]}),k&&!j&&(0,$.jsx)(`p`,{role:`status`,className:`text-xs text-accent-success`,children:i(`saved`)}),(0,$.jsx)(Z,{size:`sm`,className:`rounded-full`,disabled:y,onClick:()=>void de(),children:i(y?`saving`:`save`)})]})})]})]})]})}function RG(){return(0,$.jsx)(`div`,{className:`h-32 animate-pulse rounded-lg bg-muted/30`,"data-testid":`section-skeleton`})}function zG(){let{t:e}=K(`settings`),{activeProjectId:t}=pt(),[n,r]=(0,Q.useState)(!0),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!1);if((0,Q.useEffect)(()=>{if(!t)return;let e=!1;return s(!1),fetch(`${ut()}/settings`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&r(t.pipelineTelemetryEnabled??!0)}).catch(()=>{}).finally(()=>{e||s(!0)}),()=>{e=!0}},[t]),!o)return(0,$.jsx)(RG,{});async function c(t){a(!0);let i=n;r(t);try{if(!(await fetch(`${ut()}/settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pipelineTelemetryEnabled:t})})).ok)throw Error(`Failed to save`);J.success(e(t?`telemetry.enabled`:`telemetry.disabled`))}catch(t){r(i),J.error(e(`telemetry.saveFailed`),{description:t.message})}finally{a(!1)}}return(0,$.jsxs)(NW,{children:[(0,$.jsxs)(PW,{children:[(0,$.jsx)(FW,{children:e(`telemetry.title`)}),(0,$.jsx)(IW,{children:e(`telemetry.description`)})]}),(0,$.jsx)(LW,{className:`space-y-4`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium`,children:e(`telemetry.toggleLabel`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:(0,$.jsx)(lt,{ns:`settings`,i18nKey:`telemetry.toggleDescription`,components:{mono:(0,$.jsx)(`span`,{className:`font-mono`})}})})]}),(0,$.jsx)(`button`,{type:`button`,role:`switch`,"aria-label":e(`telemetry.toggleLabel`),"aria-checked":n,disabled:i,onClick:()=>c(!n),className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 ${n?`bg-primary`:`bg-input`}`,children:(0,$.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-background shadow-sm transition-transform ${n?`translate-x-4`:`translate-x-0.5`}`})})]})})]})}function BG(){let{t:e}=K(`settings`),{activeProjectId:t}=pt(),[n,r]=(0,Q.useState)(``),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1);async function u(e){let t=await fetch(`${ut()}/integration-branch`).then(e=>e.ok?e.json():null).catch(()=>null);e?.current||t&&(r(t.configured??``),t.branch&&a({branch:t.branch,source:t.source??``}))}if((0,Q.useEffect)(()=>{if(!t)return;let e={current:!1};return l(!1),u(e).finally(()=>{e.current||l(!0)}),()=>{e.current=!0}},[t]),!c)return(0,$.jsx)(RG,{});async function d(){s(!0);try{let t=await fetch(`${ut()}/settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({integrationBranch:n.trim()})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Failed to save`)}J.success(e(`integrationBranch.saved`)),await u()}catch(t){J.error(e(`integrationBranch.saveFailed`),{description:t.message})}finally{s(!1)}}return(0,$.jsxs)(NW,{children:[(0,$.jsxs)(PW,{children:[(0,$.jsx)(FW,{children:e(`integrationBranch.title`)}),(0,$.jsx)(IW,{children:e(`integrationBranch.description`)})]}),(0,$.jsxs)(LW,{className:`space-y-3`,children:[(0,$.jsx)(Jj,{value:n,onChange:e=>r(e.target.value),placeholder:e(`integrationBranch.placeholder`),"data-testid":`integration-branch-input`}),i&&(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,"data-testid":`integration-branch-resolved`,children:(0,$.jsx)(lt,{ns:`settings`,i18nKey:`integrationBranch.resolved`,values:{branch:i.branch},components:{mono:(0,$.jsx)(`span`,{className:`font-mono`})}})}),(0,$.jsx)(Z,{size:`sm`,onClick:d,disabled:o,"data-testid":`integration-branch-save`,children:e(`integrationBranch.save`)})]})]})}var VG=/^[A-Za-z_][A-Za-z0-9_]*$/,HG=[`NODE_AUTH_TOKEN`,`NPM_TOKEN`,`AWS_PROFILE`];function UG(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}function WG(){let{t:e}=K(`settings`),{activeProjectId:t}=pt(),[n,r]=(0,Q.useState)([]),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1);if((0,Q.useEffect)(()=>{if(!t)return;let e=!1;return d(!1),s(``),fetch(`${ut()}/settings`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&r(Array.isArray(t.worktreeEnvPassthrough)?t.worktreeEnvPassthrough:[])}).catch(()=>{}).finally(()=>{e||d(!0)}),()=>{e=!0}},[t]),!u)return(0,$.jsx)(RG,{});function f(t){let i=UG(t);if(i.length===0)return;let o=[...n];for(let t of i){if(t.includes(`=`)){s(e(`worktreeEnv.noValues`));return}if(!VG.test(t)){s(e(`worktreeEnv.invalidName`,{name:t}));return}o.includes(t)||o.push(t)}r(o),a(``),s(``)}async function p(){l(!0);try{let t=await fetch(`${ut()}/settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({worktreeEnvPassthrough:n})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Failed to save`)}let i=await t.json();r(i.settings?.worktreeEnvPassthrough??n),J.success(e(`worktreeEnv.saved`))}catch(t){J.error(e(`worktreeEnv.saveFailed`),{description:t.message})}finally{l(!1)}}return(0,$.jsxs)(NW,{children:[(0,$.jsxs)(PW,{children:[(0,$.jsx)(FW,{children:e(`worktreeEnv.title`)}),(0,$.jsx)(IW,{children:e(`worktreeEnv.description`)})]}),(0,$.jsxs)(LW,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`label`,{htmlFor:`worktree-env-name`,className:`text-xs font-medium`,children:e(`worktreeEnv.label`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Jj,{id:`worktree-env-name`,value:i,onChange:e=>{a(e.target.value),s(``)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f(i))},placeholder:e(`worktreeEnv.placeholder`),"aria-invalid":!!o,"data-testid":`worktree-env-input`}),(0,$.jsxs)(Z,{type:`button`,size:`sm`,variant:`secondary`,className:`h-9 shrink-0`,onClick:()=>f(i),disabled:!i.trim(),"data-testid":`worktree-env-add`,children:[(0,$.jsx)(Pn,{className:`w-3.5 h-3.5`}),e(`worktreeEnv.add`)]})]}),o?(0,$.jsx)(`p`,{className:`text-[10px] text-destructive`,"data-testid":`worktree-env-error`,children:o}):(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:e(`worktreeEnv.helper`)})]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:HG.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>f(e),className:`rounded-md border border-border bg-muted/30 px-2 py-1 font-mono text-[10px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:e},e))}),n.length>0?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,"data-testid":`worktree-env-list`,children:n.map(t=>(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1 font-mono text-[11px]`,children:[t,(0,$.jsx)(`button`,{type:`button`,onClick:()=>r(n.filter(e=>e!==t)),className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":e(`worktreeEnv.remove`,{name:t}),children:(0,$.jsx)(Vn,{className:`w-3 h-3`})})]},t))}):(0,$.jsx)(`p`,{className:`rounded-md border border-dashed border-border bg-muted/20 px-3 py-2 text-xs text-muted-foreground`,children:e(`worktreeEnv.empty`)}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(Z,{size:`sm`,onClick:p,disabled:c,"data-testid":`worktree-env-save`,children:e(c?`common:states.saving`:`worktreeEnv.save`)})})]})]})}function GG({value:e,onChange:t,onSave:n,isSaving:r,fieldId:i,i18nRoot:a}){let{t:o}=K(`settings`);return(0,$.jsxs)(NW,{children:[(0,$.jsxs)(PW,{children:[(0,$.jsx)(FW,{children:o(`${a}.title`)}),(0,$.jsx)(IW,{children:o(`${a}.description`)})]}),(0,$.jsxs)(LW,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`label`,{htmlFor:i,className:`text-xs font-medium`,children:o(`${a}.label`)}),(0,$.jsx)(`textarea`,{id:i,value:e,onChange:e=>t(e.target.value),placeholder:o(`${a}.placeholder`),className:`min-h-32 w-full rounded-md border border-input bg-background px-3 py-2 text-sm shadow-sm outline-none transition-colors focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/20`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`${a}.helper`)})]}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs`,disabled:r,onClick:n,children:o(r?`common:states.saving`:`${a}.saveButton`)})})]})]})}function KG(){let{t:e}=K(`settings`),{activeProjectId:t}=pt(),[n,r]=(0,Q.useState)(``),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),f=(0,Q.useRef)({pre:!1,freestyle:!1});(0,Q.useEffect)(()=>{if(!t)return;let e=!1;return d(!1),f.current={pre:!1,freestyle:!1},fetch(`${ut()}/settings`).then(e=>e.ok?e.json():null).then(t=>{e||!t||(f.current.pre||r(t.prePrompt??``),f.current.freestyle||s(t.freestylePrePrompt??``))}).catch(()=>{}).finally(()=>{e||d(!0)}),()=>{e=!0}},[t]);async function p(){a(!0);try{let t=await fetch(`${ut()}/settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prePrompt:n})});if(!t.ok)throw Error(`Failed to save`);let i=(await t.json()).settings?.prePrompt??``;r(i),J.success(i.trim()===``?e(`prePrompt.cleared`):e(`prePrompt.saved`))}catch(t){J.error(e(`prePrompt.saveFailed`),{description:t.message})}finally{a(!1)}}async function m(){l(!0);try{let t=await fetch(`${ut()}/settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({freestylePrePrompt:o})});if(!t.ok)throw Error(`Failed to save`);let n=(await t.json()).settings?.freestylePrePrompt??``;s(n),J.success(n.trim()===``?e(`freestylePrePrompt.resetToDefault`):e(`freestylePrePrompt.saved`))}catch(t){J.error(e(`freestylePrePrompt.saveFailed`),{description:t.message})}finally{l(!1)}}return u?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(GG,{value:n,onChange:e=>{f.current.pre=!0,r(e)},onSave:p,isSaving:i,fieldId:`project-pre-prompt`,i18nRoot:`prePrompt`}),(0,$.jsx)(GG,{value:o,onChange:e=>{f.current.freestyle=!0,s(e)},onSave:m,isSaving:c,fieldId:`project-freestyle-pre-prompt`,i18nRoot:`freestylePrePrompt`})]}):(0,$.jsx)(RG,{})}function qG(){let{t:e}=K(`settings`),{activeProjectId:t}=pt(),[n,r]=(0,Q.useState)(``),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),f=(0,Q.useRef)({daily:!1,perJob:!1});(0,Q.useEffect)(()=>{if(!t)return;let e=!1;return d(!1),f.current={daily:!1,perJob:!1},fetch(`${ut()}/budget`).then(e=>e.ok?e.json():null).then(t=>{e||!t||(f.current.daily||r(t.dailyBudgetUsd==null?``:String(t.dailyBudgetUsd)),f.current.perJob||s(t.jobCostThresholdUsd==null?``:String(t.jobCostThresholdUsd)))}).catch(()=>{}).finally(()=>{e||d(!0)}),()=>{e=!0}},[t]);async function p(t,n,r,i){i(!0);try{if(!(await fetch(`${ut()}/budget`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)})).ok)throw Error(`Failed to save`);J.success(n)}catch(t){J.error(e(r),{description:t.message})}finally{i(!1)}}function m(t){let n=t.trim()===``?null:parseFloat(t);if(n!==null&&(isNaN(n)||n<=0)){J.error(e(`budget.invalidNumber`));return}return n}function h(){let t=m(n);t!==void 0&&p({dailyBudgetUsd:t},t==null?e(`budget.dailyRemoved`):e(`budget.dailySet`,{amount:t}),`budget.saveBudgetFailed`,a)}function g(){let t=m(o);t!==void 0&&p({jobCostThresholdUsd:t},t==null?e(`budget.perJobAlertDisabled`):e(`budget.alertSet`,{amount:t}),`budget.saveThresholdFailed`,l)}return u?(0,$.jsxs)(NW,{children:[(0,$.jsxs)(PW,{children:[(0,$.jsx)(FW,{children:e(`budget.title`)}),(0,$.jsx)(IW,{children:e(`budget.description`)})]}),(0,$.jsx)(LW,{children:(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`text-xs font-medium`,children:e(`budget.dailyLabel`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`budget.dailyHelper`)})]}),(0,$.jsx)(Jj,{type:`number`,min:`0`,step:`0.01`,value:n,onChange:e=>{f.current.daily=!0,r(e.target.value)},placeholder:e(`budget.dailyPlaceholder`),className:`h-8 text-xs font-mono`}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs`,disabled:i,onClick:h,children:e(i?`common:states.saving`:`common:actions.save`)})})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`text-xs font-medium`,children:e(`budget.perJobLabel`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`budget.perJobHelper`)})]}),(0,$.jsx)(Jj,{type:`number`,min:`0`,step:`0.01`,value:o,onChange:e=>{f.current.perJob=!0,s(e.target.value)},placeholder:e(`budget.perJobPlaceholder`),className:`h-8 text-xs font-mono`}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs`,disabled:c,onClick:g,children:e(c?`common:states.saving`:`common:actions.save`)})})]})]})})]}):(0,$.jsx)(RG,{})}function JG(){let{t:e}=K(`settings`),{activeProjectId:t}=pt(),n=p(),r=t!==null;(0,Q.useEffect)(()=>{if(!n.hash)return;let e=n.hash.slice(1),t=!1,r=Date.now()+3e3,i=()=>{if(t)return;let n=document.getElementById(e);if(n){n.scrollIntoView({behavior:`smooth`,block:`center`}),n.classList.add(`ring-2`,`ring-accent-primary/60`,`rounded`),window.setTimeout(()=>{n.classList.remove(`ring-2`,`ring-accent-primary/60`,`rounded`)},1800);return}Date.now()<r&&window.setTimeout(i,80)};return i(),()=>{t=!0}},[n.hash,n.key]);let[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(!0),c=(0,Q.useRef)(new Map);return(0,Q.useEffect)(()=>{if(t){let e=c.current.get(t);e?(a(e),s(!1)):s(!0)}async function e(){try{let e=await fetch(`${ut()}/config`);if(!e.ok)return;let n=await e.json();a(n),t&&c.current.set(t,n)}catch{}finally{s(!1)}}e()},[t]),o?(0,$.jsx)(`div`,{className:`max-w-2xl mx-auto px-4 py-6 space-y-3`,children:[0,1,2].map(e=>(0,$.jsx)(`div`,{className:`h-32 bg-muted/30 rounded-lg animate-pulse`},e))}):(0,$.jsxs)(`div`,{className:`max-w-2xl mx-auto px-4 py-6 space-y-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-base font-semibold`,children:e(`page.title`)}),i&&(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:[i.project.name,i.project.repo&&` · ${i.project.repo}`]})]}),r&&(0,$.jsx)(zG,{}),(0,$.jsx)(KG,{}),(0,$.jsx)(UW,{}),(0,$.jsx)(NG,{}),(0,$.jsx)(BG,{}),(0,$.jsx)(WG,{}),(0,$.jsx)(qG,{}),(0,$.jsx)(BW,{mode:`project`})]})}function YG(){let{t:e}=K(`agentRuntime`),[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)({}),[a,o]=(0,Q.useState)(`architect`),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(0);(0,Q.useEffect)(()=>{let t=!1;return c(``),fetch(`/api/runtime-role-prompts`).then(async r=>{let a=await r.json();if(!r.ok||!pG.every(e=>typeof a.defaults?.[e]==`string`))throw Error(a.message??e(`loadFailed`));t||(n(a),i(a.overrides),f(!1))}).catch(e=>{t||c(e.message)}),()=>{t=!0}},[e,p]);let h=t&&typeof t.defaults.fixer==`string`?mG:pG,g=(e,n)=>e[n]??t.defaults[n]??``,_=!!(t&&h.some(e=>r[e]!==t.overrides[e])),v=!!(t&&h.some(e=>{let t=g(r,e);return!t.trim()||t.length>2e4||t.includes(`\0`)}));function y(e,n){i(r=>{let i={...r};return n===t.defaults[e]?delete i[e]:i[e]=n,i}),f(!1)}async function b(){u(!0),c(``),f(!1);try{let t=await fetch(`/api/runtime-role-prompts`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({overrides:r})}),a=await t.json();if(!t.ok)throw Error(a.message??e(`saveFailed`));n(a),i(a.overrides),f(!0)}catch(e){c(e.message)}finally{u(!1)}}return(0,$.jsxs)(`section`,{className:`space-y-4 border-t border-border pt-6`,"aria-label":e(`prompts.title`),children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-base font-medium`,children:e(`prompts.title`)}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e(`prompts.description`)})]}),s&&(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:s}),!t&&(s?(0,$.jsx)(Z,{variant:`secondary`,onClick:()=>m(e=>e+1),children:e(`retry`)}):(0,$.jsx)(`p`,{role:`status`,children:e(`loading`)})),t&&(0,$.jsxs)(`fieldset`,{disabled:l,className:`min-w-0 space-y-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{role:`tablist`,"aria-label":e(`prompts.title`),className:`inline-flex flex-wrap gap-1 rounded-lg border border-border bg-muted p-1`,children:h.map((t,n)=>(0,$.jsx)(`button`,{type:`button`,role:`tab`,id:`role-tab-${t}`,"aria-controls":`role-panel-${t}`,"aria-selected":a===t,tabIndex:a===t?0:-1,className:`rounded-md px-3 py-1.5 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ${a===t?`bg-background font-medium shadow-sm`:`text-muted-foreground`}`,onClick:()=>o(t),onKeyDown:e=>{let t=e.key===`ArrowRight`?(n+1)%h.length:e.key===`ArrowLeft`?(n+h.length-1)%h.length:e.key===`Home`?0:e.key===`End`?h.length-1:-1;t<0||(e.preventDefault(),o(h[t]),e.currentTarget.parentElement?.querySelectorAll(`[role="tab"]`)[t]?.focus())},children:e(`roles.${t}`)},t))}),h.filter(e=>e===a).map(n=>(0,$.jsxs)(`div`,{role:`tabpanel`,id:`role-panel-${n}`,"aria-labelledby":`role-tab-${n}`,className:`mt-3 space-y-3`,children:[n===`fixer`&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`prompts.fixerHint`)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(`label`,{htmlFor:`role-prompt-${n}`,className:`text-sm font-medium`,children:e(`prompts.definition`,{role:e(`roles.${n}`)})}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(r[n]===void 0?`prompts.default`:`prompts.custom`)})]}),(0,$.jsx)(`textarea`,{id:`role-prompt-${n}`,value:g(r,n),onChange:e=>y(n,e.target.value),rows:18,maxLength:2e4,spellCheck:!1,className:`block max-h-[420px] min-h-64 w-full resize-y rounded-md border border-input bg-background p-3 font-mono text-xs leading-relaxed focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`span`,{children:[g(r,n).length.toLocaleString(),` / 20,000`]}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,disabled:r[n]===void 0,onClick:()=>y(n,t.defaults[n]??``),children:e(`prompts.restore`)})]})]},n))]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`prompts.contracts`)}),v&&(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:e(`prompts.invalid`)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-3`,children:[d&&(0,$.jsx)(`p`,{role:`status`,className:`text-sm text-accent-success`,children:e(`prompts.saved`)}),_&&(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`prompts.unsaved`)}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,disabled:!_,onClick:()=>{i(t.overrides),c(``),f(!1)},children:e(`prompts.discard`)}),(0,$.jsx)(Z,{type:`button`,disabled:l||!_||v,onClick:()=>void b(),children:e(l?`saving`:`prompts.save`)})]})]})]})}function XG(){let{t:e}=K(`settings`),t=HA();return(0,$.jsxs)(`div`,{className:`space-y-2`,"data-testid":`effects-section`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e(`effects.heading`)}),(0,$.jsxs)(`div`,{className:`rounded-md border border-border p-3 space-y-3`,children:[(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:e(`effects.description`)}),(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t.agentThinkingHalo,onClick:()=>BA({agentThinkingHalo:!t.agentThinkingHalo}),className:X(`relative mt-0.5 inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors`,t.agentThinkingHalo?`bg-accent-primary/70`:`bg-muted-foreground/30`),"data-testid":`effects-thinking-halo-toggle`,children:(0,$.jsx)(`span`,{className:X(`absolute h-3 w-3 rounded-full bg-background shadow transition-transform`,t.agentThinkingHalo?`translate-x-3.5`:`translate-x-0.5`)})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs font-medium`,children:[(0,$.jsx)(Ln,{className:`h-3.5 w-3.5 text-accent-primary`,"aria-hidden":!0}),e(`effects.thinkingHalo.label`)]}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[10px] text-muted-foreground`,children:e(`effects.thinkingHalo.description`)}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[10px] text-muted-foreground/80`,children:e(`effects.reducedMotion`)}),(0,$.jsxs)(`div`,{className:`mt-3`,children:[(0,$.jsx)(`p`,{className:`mb-1.5 text-[10px] uppercase tracking-wider text-muted-foreground`,children:e(`effects.preview`)}),(0,$.jsxs)(`div`,{className:`relative max-w-sm rounded-xl border border-border/60 bg-background/60 px-3 py-2`,"data-testid":`effects-thinking-halo-preview`,"data-active":t.agentThinkingHalo,children:[(0,$.jsx)(NA,{active:t.agentThinkingHalo,radius:`0.75rem`,inset:-3,fadeInMs:450,fadeOutMs:800}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`span`,{className:`inline-flex gap-0.5`,"aria-hidden":!0,children:[(0,$.jsx)(`span`,{className:`h-1 w-1 animate-pulse rounded-full bg-accent-primary`}),(0,$.jsx)(`span`,{className:`h-1 w-1 animate-pulse rounded-full bg-accent-primary [animation-delay:150ms]`}),(0,$.jsx)(`span`,{className:`h-1 w-1 animate-pulse rounded-full bg-accent-primary [animation-delay:300ms]`})]}),e(`effects.previewThinking`)]})]})]})]})]})]})]})}function ZG(){let{t:e}=K(`settings`),t=Ca();if(!t)return null;let{themeId:n,setTheme:r,isUpdating:i}=t;async function a(t){if(t!==n)try{await r(t)}catch(t){J.error(e(`appearance.updateFailed`),{description:t instanceof Error?t.message:void 0})}}return(0,$.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-2`,role:`radiogroup`,"aria-label":e(`appearance.themeGroupLabel`),children:Xi.map(t=>{let r=da[t],o=t===n;return(0,$.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":o,disabled:i,onClick:()=>void a(t),className:`group relative overflow-hidden rounded-lg border text-left transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/60 disabled:opacity-60 disabled:cursor-not-allowed `+(o?`border-accent-primary ring-1 ring-accent-primary shadow-[0_0_0_1px_var(--color-accent-primary)] `:`border-border hover:border-accent-primary/40 hover:shadow-md `),"data-testid":`theme-card-${t}`,"data-selected":o?`true`:`false`,children:[(0,$.jsx)(`div`,{className:`h-20 w-full flex items-end gap-1 p-2`,style:{background:`linear-gradient(135deg, ${r.previewSwatches.background} 0%, ${r.previewSwatches.background} 60%, color-mix(in srgb, ${r.previewSwatches.accents[0]} 18%, ${r.previewSwatches.background}) 100%)`},"aria-hidden":`true`,children:r.previewSwatches.accents.map((e,t)=>(0,$.jsx)(`span`,{className:`h-3 w-3 rounded-full ring-1 ring-black/10`,style:{background:e}},t))}),(0,$.jsxs)(`div`,{className:`p-3 space-y-1 bg-card`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`p`,{className:`text-xs font-semibold`,children:r.displayName}),o&&(0,$.jsx)(Sn,{className:`w-3.5 h-3.5 text-accent-primary shrink-0`,"aria-label":e(`appearance.currentlyActive`)})]}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground leading-tight`,children:e(`appearance.taglines.${t}`,{defaultValue:r.tagline})})]})]},t)})})}function QG(){let{t:e}=K(`settings`);return Ca()?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e(`appearance.heading`)}),(0,$.jsx)(ZG,{})]}):null}function $G(e={}){let t={...e},n=Ye();return n&&(t[`X-Desktop-Token`]=n),t}var eK=(0,Q.createContext)(null);function tK(e){if(!(typeof localStorage>`u`))try{localStorage.setItem(Ke,e)}catch{}}function nK(){if(!(typeof localStorage>`u`))try{localStorage.removeItem(Ke)}catch{}}function rK({children:e,endpoint:t=`/api/language`}){let[n,r]=(0,Q.useState)(()=>et()),[i,a]=(0,Q.useState)(!1),o=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{if(o.current)return;o.current=!0;let e=!1;return(async()=>{try{let n=await fetch(t,{headers:$G()});if(!n.ok)return;let i=await n.json();if(e)return;He(i.language)&&i.language!==et()&&(await at(i.language),tK(i.language),e||r(i.language))}catch{}})(),()=>{e=!0}},[t]);let s=(0,Q.useCallback)(async e=>{if(e===n)return;let i=n,o=typeof localStorage<`u`&&He(localStorage.getItem(`specrails-desktop:ui-language`));await at(e),tK(e),r(e),a(!0);try{let n=await fetch(t,{method:`PATCH`,headers:$G({"Content-Type":`application/json`}),body:JSON.stringify({language:e})});if(!n.ok)throw Error(`server rejected language: ${n.status}`)}catch(e){throw await at(i),o?tK(i):nK(),r(i),e}finally{a(!1)}},[n,t]),c=(0,Q.useMemo)(()=>({languageId:n,language:it[n],setLanguage:s,isUpdating:i}),[n,s,i]);return(0,$.jsx)(eK.Provider,{value:c,children:e})}function iK(){return(0,Q.useContext)(eK)}function aK(){let{t:e}=K(`settings`),t=iK();if(!t)return null;let{languageId:n,setLanguage:r,isUpdating:i}=t;async function a(t){if(t!==n)try{await r(t)}catch(t){J.error(e(`language.updateFailed`),{description:t instanceof Error?t.message:void 0})}}return(0,$.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,role:`radiogroup`,"aria-label":e(`language.selectLabel`),children:Ge.map(e=>{let t=it[e],r=e===n;return(0,$.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":r,disabled:i,onClick:()=>void a(e),className:`flex items-center justify-between gap-2 rounded-lg border bg-card px-3 py-2 text-left transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/60 disabled:opacity-60 disabled:cursor-not-allowed `+(r?`border-accent-primary ring-1 ring-accent-primary `:`border-border hover:border-accent-primary/40 hover:shadow-md `),"data-testid":`language-card-${e}`,"data-selected":r?`true`:`false`,children:[(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block text-xs font-semibold truncate`,children:t.nativeName}),(0,$.jsx)(`span`,{className:`block text-[10px] text-muted-foreground truncate`,children:t.englishName})]}),r&&(0,$.jsx)(Sn,{className:`w-3.5 h-3.5 text-accent-primary shrink-0`,"aria-hidden":`true`})]},e)})})}function oK(){let{t:e}=K(`settings`);return iK()?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e(`language.title`)}),(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e(`language.description`)}),(0,$.jsx)(aK,{})]}):null}function sK(){if(!me)return null;let{t:e}=K(`settings`),[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=!1;return fetch(`/api/code-explorer-settings`).then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(t=>{e||n(t)}).catch(()=>{e||n({language:`en`,monthlyBudgetUsd:5})}),()=>{e=!0}},[]);async function a(r){if(!t)return;let a={...t,...r};n(a),i(!0);try{let e=await fetch(`/api/code-explorer-settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)});if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();n(t)}catch(r){J.error(e(`errors.saveFailed`,{message:r.message})),n(t)}finally{i(!1)}}return t?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e(`codeSection.heading`)}),(0,$.jsxs)(`div`,{className:`rounded-md border border-border p-3 space-y-3`,children:[(0,$.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-xs`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e(`codeSection.summaryLanguage`)}),(0,$.jsxs)(`select`,{value:t.language,disabled:r,onChange:e=>a({language:e.target.value}),className:`bg-background border border-border rounded px-2 py-1 text-xs`,children:[(0,$.jsx)(`option`,{value:`en`,children:`English`}),(0,$.jsx)(`option`,{value:`es`,children:`Español`})]})]}),(0,$.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-xs`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e(`codeSection.monthlyBudget`)}),(0,$.jsx)(`input`,{type:`number`,min:0,step:.5,value:t.monthlyBudgetUsd,disabled:r,onChange:e=>{let t=parseFloat(e.target.value);!isNaN(t)&&t>=0&&a({monthlyBudgetUsd:t})},className:`bg-background border border-border rounded px-2 py-1 text-xs w-24 text-right`})]}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground/70`,children:e(`codeSection.budgetHelper`)})]})]}):(0,$.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`})}var cK=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function lK({provider:e,onChange:t,onRemove:n}){let{t:r}=K(`agentRuntime`),i=e.kind===`openai-compatible`,a=i?xc:Ec;return(0,$.jsxs)(`fieldset`,{className:`rounded-xl border border-border/70 bg-card/60 p-4 shadow-sm transition-colors hover:border-border`,"data-testid":`connection-row-${e.id}`,children:[(0,$.jsxs)(`legend`,{className:`flex items-center gap-2 px-1.5 text-sm font-medium`,children:[(0,$.jsx)(a,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":!0}),hG(e),(0,$.jsx)(`span`,{className:`rounded-full border border-border bg-muted/40 px-2 py-px text-[10px] font-normal uppercase tracking-wide text-muted-foreground`,children:r(i?`providers.localBadge`:`providers.cliBadge`)})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[r(`providers.id`),(0,$.jsx)(Jj,{value:e.id,onChange:n=>t({...e,id:n.target.value})})]}),e.kind===`cli`?(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[r(`providers.command`),(0,$.jsx)(`select`,{className:cK,value:e.cli,onChange:n=>t({...e,cli:n.target.value}),children:fG.map(e=>(0,$.jsx)(`option`,{value:e,children:r(`cliNames.${e}`)},e))})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[r(`providers.baseUrl`),(0,$.jsx)(Jj,{type:`url`,value:e.baseUrl,onChange:n=>t({...e,baseUrl:n.target.value})})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[r(`providers.apiKeyEnv`),(0,$.jsx)(Jj,{value:e.apiKeyEnv??``,onChange:n=>t({...e,apiKeyEnv:n.target.value||void 0})})]})]})]}),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:n,children:r(`providers.remove`)})]})]})}function uK(e,t=!1){if(t)return`probing`;if(!e)return`untested`;let n=e.reachable??e.installed;return n===void 0?`untested`:n?e.authState===`unauthenticated`?`unauthorized`:`reachable`:`unreachable`}var dK={probing:{dot:`bg-accent-info animate-pulse`,pill:`border-accent-info/30 bg-accent-info/10 text-accent-info`},reachable:{dot:`bg-accent-success`,pill:`border-accent-success/30 bg-accent-success/10 text-accent-success`},unauthorized:{dot:`bg-accent-warning`,pill:`border-accent-warning/30 bg-accent-warning/10 text-accent-warning`},unreachable:{dot:`bg-destructive`,pill:`border-destructive/30 bg-destructive/10 text-destructive`},untested:{dot:`bg-muted-foreground/50`,pill:`border-border bg-muted/40 text-muted-foreground`}};function fK({state:e,latencyMs:t,className:n}){let{t:r}=K(`agentRuntime`),i=dK[e];return(0,$.jsxs)(`span`,{"data-testid":`connection-status-pill`,"data-state":e,role:`status`,className:X(`inline-flex h-6 items-center gap-1.5 rounded-full border px-2.5 text-[11px] font-medium transition-colors`,i.pill,n),children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:X(`h-1.5 w-1.5 rounded-full`,i.dot)}),r(`providers.status.${e}`),e===`reachable`&&typeof t==`number`&&(0,$.jsxs)(`span`,{className:`text-[10px] font-normal opacity-70 tabular-nums`,children:[`· `,t,` ms`]})]})}function pK({label:e,items:t,trigger:n,triggerClassName:r,align:i=`right`}){let[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null),c=(0,Q.useId)();return(0,Q.useEffect)(()=>{if(!a)return;function e(e){s.current&&!s.current.contains(e.target)&&o(!1)}function t(e){if(e.key===`Escape`){o(!1);return}if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let t=Array.from(s.current?.querySelectorAll(`[role="menuitem"]`)??[]);if(!t.length)return;e.preventDefault();let n=t.indexOf(document.activeElement);t[e.key===`ArrowDown`?(n+1)%t.length:(n-1+t.length)%t.length]?.focus()}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]),(0,$.jsxs)(`div`,{ref:s,className:`relative`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":n?void 0:e,title:n?void 0:e,"aria-haspopup":`menu`,"aria-expanded":a,"aria-controls":a?c:void 0,onClick:()=>o(e=>!e),className:X(`inline-flex h-7 items-center justify-center gap-1.5 rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,n?`px-2 text-xs`:`w-7`,a&&`bg-accent text-foreground`,r),children:n??(0,$.jsx)(_s,{className:`h-4 w-4`,"aria-hidden":!0})}),a&&(0,$.jsx)(`div`,{id:c,role:`menu`,"aria-label":e,className:X(`absolute top-full z-30 mt-1 min-w-40 overflow-hidden rounded-lg border border-border bg-card p-1 shadow-lg`,i===`right`?`right-0`:`left-0`),children:t.map(e=>(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{o(!1),e.onSelect()},className:X(`flex w-full items-center gap-2 rounded-md px-2.5 py-1.5 text-left text-xs transition-colors hover:bg-accent focus-visible:bg-accent focus-visible:outline-none`,e.destructive?`text-destructive`:`text-foreground`),children:[e.icon,e.label]},e.id))})]})}function mK({provider:e,status:t,onRemove:n}){let{t:r}=K(`agentRuntime`),i=!!t;return(0,$.jsxs)(`li`,{"data-testid":`connection-row-${e.id}`,"data-kind":`cli`,className:X(`flex min-h-11 items-center gap-3 px-3 py-1.5 transition-colors`,i?`hover:bg-muted/30`:`opacity-55`),children:[(0,$.jsx)(`span`,{className:X(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md border`,i?`border-accent-info/30 bg-accent-info/10 text-accent-info`:`border-border bg-muted/40 text-muted-foreground`),children:(0,$.jsx)(Ec,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:r(`cliNames.${e.cli}`)}),t?.version&&(0,$.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground tabular-nums`,children:[`v`,t.version]}),(0,$.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground/60`,children:e.id})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[i?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(fK,{state:uK(t)}),(0,$.jsx)(`span`,{className:X(`hidden text-[11px] sm:inline`,t?.authState===`authenticated`?`text-muted-foreground`:`text-accent-warning`),children:r(`providers.auth.${t.authState}`)})]}):(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:r(`providers.notDetected`)}),(0,$.jsx)(pK,{label:r(`providers.overflow`),items:[{id:`remove`,label:r(`providers.remove`),icon:(0,$.jsx)(Rn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),destructive:!0,onSelect:n}]})]})]})}function hK(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.reachable==`boolean`&&typeof t.authState==`string`}function gK({baseUrl:e,apiKeyEnv:t,disabled:n,onStart:r,onResult:i,onError:a}){let{t:o}=K(`agentRuntime`),[s,c]=(0,Q.useState)(!1);async function l(){c(!0),r?.();try{let n=await fetch(`/api/runtime-providers/test`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({baseUrl:e,...t?{apiKeyEnv:t}:{}})}),r=await n.json().catch(()=>null);if(!n.ok||!hK(r))throw Error(r?.message??o(`providers.testFailed`));i({...r,models:Array.isArray(r.models)?r.models:[]})}catch(e){a(e.message||o(`providers.testFailed`))}finally{c(!1)}}return(0,$.jsxs)(Z,{type:`button`,variant:`secondary`,size:`sm`,disabled:n||s||!e.trim(),onClick:()=>void l(),className:`gap-1.5`,children:[s?(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(cc,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),o(s?`providers.testing`:`providers.test`)]})}function _K(e){return(e.agentLoop??`compact`)===`compact`&&e.supportsReasoningEffort===!0&&(e.contextWindowTokens??0)>=32768}var vK=`__custom__`,yK=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`,bK=`space-y-1 text-xs text-muted-foreground`;function xK(e){return e===void 0?``:String(e)}function SK(e){if(e.trim()===``)return null;let t=Number(e);return Number.isFinite(t)&&t>=0?t:NaN}function CK({provider:e,status:t,persisted:n,onChange:r,onStatus:i,onValidity:a,onRemove:o}){let{t:s}=K(`agentRuntime`),c=(0,Q.useId)(),[l,u]=(0,Q.useState)(!n),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)({input:xK(e.rates?.inputPer1M),output:xK(e.rates?.outputPer1M)}),[_,v]=(0,Q.useState)(!1),y=t?.models??[],b=!e.defaultModel||y.includes(e.defaultModel),x=_||!b,S=SK(h.input),C=SK(h.output),w=Number.isNaN(S)||Number.isNaN(C)||S===null!=(C===null);(0,Q.useEffect)(()=>{a(!w)},[w,a]);function T(t,n){let i={...h,[t]:n};g(i);let a=SK(i.input),o=SK(i.output);a===null&&o===null?r({...e,rates:void 0}):a!==null&&o!==null&&!Number.isNaN(a)&&!Number.isNaN(o)&&r({...e,rates:{inputPer1M:a,outputPer1M:o}})}function E(t){f(!1),m(``),i({reachable:t.reachable,authState:t.authState,models:t.models,latencyMs:t.latencyMs,error:t.error,apiKeyEnvMissing:t.apiKeyEnvMissing}),t.models.length&&qx(e.id,t.models)}let D=uK(t,d);return(0,$.jsxs)(`div`,{className:`space-y-4`,"data-testid":`local-connection-${e.id}`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(fK,{state:D,latencyMs:t?.latencyMs}),t?.error&&D!==`reachable`&&(0,$.jsx)(`span`,{className:`truncate text-[11px] text-destructive/90`,title:t.error,children:t.error}),(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,$.jsx)(gK,{baseUrl:e.baseUrl,apiKeyEnv:e.apiKeyEnv,onStart:()=>{f(!0),m(``)},onResult:E,onError:e=>{f(!1),m(e)}}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:o,children:s(`providers.remove`)})]})]}),p&&(0,$.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:p}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:bK,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`label`,{htmlFor:`${c}-id`,children:s(`providers.id`)}),n&&!l&&(0,$.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 text-[11px] text-accent-primary hover:underline`,onClick:()=>u(!0),children:[(0,$.jsx)(jn,{className:`h-3 w-3`,"aria-hidden":!0}),s(`providers.rename`)]})]}),(0,$.jsx)(Jj,{id:`${c}-id`,value:e.id,readOnly:!l,"aria-readonly":!l,title:l?void 0:s(`providers.idLocked`),className:X(!l&&`text-muted-foreground`),onChange:t=>r({...e,id:t.target.value})}),l&&n&&(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80`,children:s(`providers.renameHint`)})]}),(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-label`,children:[s(`providers.label`),(0,$.jsx)(Jj,{id:`${c}-label`,value:e.label??``,placeholder:s(`providers.labelPlaceholder`),onChange:t=>r({...e,label:t.target.value||void 0})})]}),(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-url`,children:[s(`providers.baseUrl`),(0,$.jsx)(Jj,{id:`${c}-url`,type:`url`,value:e.baseUrl,onChange:t=>r({...e,baseUrl:t.target.value})})]}),(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-env`,children:[s(`providers.apiKeyEnv`),(0,$.jsx)(Jj,{id:`${c}-env`,value:e.apiKeyEnv??``,onChange:t=>r({...e,apiKeyEnv:t.target.value||void 0})}),t?.apiKeyEnvMissing&&e.apiKeyEnv&&(0,$.jsxs)(`span`,{role:`note`,className:`flex items-center gap-1 text-[11px] text-accent-warning`,children:[(0,$.jsx)(zn,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}),s(`providers.apiKeyEnvMissing`,{name:e.apiKeyEnv})]})]})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:s(`providers.discoveredModels`)}),y.length===0?(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70`,children:s(`providers.noModels`)}):(0,$.jsx)(`ul`,{className:`flex flex-wrap gap-1.5`,"aria-label":s(`providers.discoveredModels`),children:y.map(t=>(0,$.jsx)(`li`,{children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>{v(!1),r({...e,defaultModel:t})},className:X(`rounded-full border px-2.5 py-0.5 font-mono text-[11px] transition-colors`,e.defaultModel===t?`border-accent-primary/50 bg-accent-primary/10 text-foreground`:`border-border bg-muted/30 text-muted-foreground hover:text-foreground`),"aria-pressed":e.defaultModel===t,children:t})},t))}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-default`,children:[s(`providers.defaultModel`),(0,$.jsxs)(`select`,{id:`${c}-default`,className:yK,value:x?vK:e.defaultModel??``,onChange:t=>{if(t.target.value===vK){v(!0);return}v(!1),r({...e,defaultModel:t.target.value||void 0})},children:[(0,$.jsx)(`option`,{value:``,children:s(`providers.defaultModelNone`)}),y.map(e=>(0,$.jsx)(`option`,{value:e,children:e},e)),(0,$.jsx)(`option`,{value:vK,children:s(`providers.customModel`)})]})]}),x&&(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-custom`,children:[s(`providers.customModel`),(0,$.jsx)(Jj,{id:`${c}-custom`,value:e.defaultModel??``,placeholder:s(`providers.defaultModelPlaceholder`),onChange:t=>r({...e,defaultModel:t.target.value||void 0})})]})]})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[s(`providers.rates`),` `,(0,$.jsxs)(`span`,{className:`text-muted-foreground/60`,children:[`· `,s(`providers.ratesHint`)]})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-in`,children:[s(`providers.inputRate`),(0,$.jsx)(Jj,{id:`${c}-in`,type:`number`,min:`0`,step:`0.01`,inputMode:`decimal`,value:h.input,onChange:e=>T(`input`,e.target.value),"aria-invalid":w})]}),(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-out`,children:[s(`providers.outputRate`),(0,$.jsx)(Jj,{id:`${c}-out`,type:`number`,min:`0`,step:`0.01`,inputMode:`decimal`,value:h.output,onChange:e=>T(`output`,e.target.value),"aria-invalid":w})]})]}),w&&(0,$.jsx)(`p`,{role:`alert`,className:`text-[11px] text-destructive`,children:s(`providers.ratesInvalid`)})]}),(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-xs`,htmlFor:`${c}-effort`,children:[(0,$.jsx)(`input`,{id:`${c}-effort`,type:`checkbox`,role:`switch`,"aria-checked":!!e.supportsReasoningEffort,className:`mt-0.5 accent-accent-primary`,checked:!!e.supportsReasoningEffort,onChange:t=>r({...e,supportsReasoningEffort:t.target.checked||void 0})}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-foreground`,children:s(`providers.reasoningEffort`)}),(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:s(`providers.reasoningEffortHint`)}),!e.supportsReasoningEffort&&(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground/70`,children:s(`providers.reasoningEffortRailHint`)})]})]}),(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border/60 bg-background/40 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:s(`providers.presetTitle`)}),(0,$.jsxs)(Z,{type:`button`,variant:`secondary`,size:`sm`,disabled:_K(e),title:s(`providers.presetSmallModelHint`),onClick:()=>r({...e,agentLoop:void 0,supportsReasoningEffort:!0,contextWindowTokens:e.contextWindowTokens??32768}),children:[(0,$.jsx)(Ln,{className:`mr-1 h-3.5 w-3.5`,"aria-hidden":!0}),_K(e)?s(`providers.presetSmallModelApplied`):s(`providers.presetSmallModel`)]})]}),(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70`,children:s(`providers.presetSmallModelHint`)})]}),(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border/60 bg-background/40 p-3`,children:[(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[s(`providers.agentLoop`),` `,(0,$.jsxs)(`span`,{className:`text-muted-foreground/60`,children:[`· `,s(`providers.agentLoopHint`)]})]}),(0,$.jsx)(`div`,{role:`radiogroup`,"aria-label":s(`providers.agentLoop`),className:`grid grid-cols-2 gap-1 rounded-md bg-muted/40 p-1`,children:[`compact`,`free`].map(t=>{let n=(e.agentLoop??`compact`)===t;return(0,$.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,className:X(`rounded px-2 py-1.5 text-xs transition-colors`,n?`bg-accent-primary/15 text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),onClick:()=>r({...e,agentLoop:t===`compact`?void 0:t}),children:[(0,$.jsx)(`span`,{className:`block font-medium`,children:s(`providers.agentLoop_${t}`)}),(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:s(`providers.agentLoop_${t}Hint`)})]},t)})}),(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-ctx`,children:[s(`providers.contextWindow`),(0,$.jsx)(Jj,{id:`${c}-ctx`,type:`number`,min:4096,step:1024,inputMode:`numeric`,placeholder:`32768`,value:e.contextWindowTokens??``,"aria-invalid":e.contextWindowTokens!==void 0&&e.contextWindowTokens<4096,onChange:t=>{let n=Number.parseInt(t.target.value,10);r({...e,contextWindowTokens:Number.isFinite(n)&&t.target.value!==``?n:void 0})}}),(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:s(`providers.contextWindowHint`)})]}),(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-out`,children:[s(`providers.maxOutput`),(0,$.jsx)(Jj,{id:`${c}-out`,type:`number`,min:1024,step:1024,inputMode:`numeric`,placeholder:`8192`,value:e.maxOutputTokens??``,"aria-invalid":e.maxOutputTokens!==void 0&&e.maxOutputTokens<1024,onChange:t=>{let n=Number.parseInt(t.target.value,10);r({...e,maxOutputTokens:Number.isFinite(n)&&t.target.value!==``?n:void 0})}}),(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:s(`providers.maxOutputHint`)})]})]})]})}function wK(e){let t=e??32768;return t>=1024&&t%1024==0?`${t/1024}k`:t.toLocaleString()}function TK({provider:e,status:t,persisted:n,invalid:r=!1,onChange:i,onStatus:a,onValidity:o,onRemove:s}){let{t:c}=K(`agentRuntime`),[l,u]=(0,Q.useState)(!n),d=l||r,f=t?.models?.length??0,p=e.agentLoop??`compact`,m=hG(e),h=`local-engine-editor-${e.id||`new`}`;return(0,$.jsxs)(`div`,{"data-testid":`connection-row-${e.id}`,"data-kind":`local`,"data-expanded":d,className:X(`rounded-xl border bg-card/60 shadow-sm transition-colors`,d?`border-accent-primary/30`:`border-border/70 hover:border-border`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5`,children:[(0,$.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg border border-accent-highlight/30 bg-accent-highlight/10 text-accent-highlight`,children:(0,$.jsx)(xc,{className:`h-4 w-4`,"aria-hidden":!0})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,$.jsx)(`span`,{className:`truncate text-sm font-medium text-foreground`,children:m}),e.label?.trim()&&(0,$.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground/60`,children:e.id}),(0,$.jsx)(fK,{state:uK(t),latencyMs:t?.latencyMs})]}),(0,$.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`truncate font-mono`,children:e.baseUrl||`—`}),(0,$.jsx)(`span`,{"aria-hidden":!0,className:`text-muted-foreground/40`,children:`·`}),(0,$.jsx)(`span`,{className:`tabular-nums`,children:c(`providers.models`,{count:f})}),(0,$.jsx)(`span`,{"aria-hidden":!0,className:`text-muted-foreground/40`,children:`·`}),(0,$.jsx)(`span`,{className:X(`rounded-full border px-1.5 py-px text-[10px] font-medium`,p===`compact`?`border-accent-secondary/30 bg-accent-secondary/10 text-accent-secondary`:`border-border bg-muted/40 text-muted-foreground`),"data-testid":`agent-loop-chip`,children:c(`providers.agentLoop_${p}`)}),(0,$.jsxs)(`span`,{className:`tabular-nums`,title:c(`providers.contextWindow`),children:[wK(e.contextWindowTokens),` ctx`]})]})]}),(0,$.jsx)(`button`,{type:`button`,"aria-expanded":d,"aria-controls":h,"aria-label":c(d?`providers.collapse`:`providers.expand`),title:c(d?`providers.collapse`:`providers.expand`),disabled:r,onClick:()=>u(!d),className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-40`,children:(0,$.jsx)(Xo,{className:X(`h-4 w-4 transition-transform duration-200`,d&&`rotate-180`),"aria-hidden":!0})})]}),d&&(0,$.jsx)(`div`,{id:h,className:`border-t border-border/60 px-4 pb-4 pt-3`,children:(0,$.jsx)(CK,{provider:e,status:t,persisted:n,onChange:i,onStatus:a,onValidity:o,onRemove:s})})]})}var EK=1;function DK(e,t){return e.map(e=>({key:EK++,provider:e,persisted:t}))}function OK({children:e}){let{t}=K(`agentRuntime`),n=!ye(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)({}),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(()=>new Set),[h,g]=(0,Q.useState)(!0),_=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>{_.current=!0;let e=!1;return fetch(`/api/runtime-providers`).then(async n=>{let r=await n.json();if(!n.ok||!gG(r))throw Error(r?.message??t(`loadFailed`));e||(i(DK(r.providers,!0)),o(r.providers),c(r.status??{}))}).catch(t=>{e||u(t.message)}),()=>{e=!0,_.current=!1}},[t]);let v=(0,Q.useMemo)(()=>r?.map(e=>e.provider)??null,[r]),y=v!==null&&a!==null&&JSON.stringify(v)!==JSON.stringify(a),b=p.size>0,x=(0,Q.useCallback)((e,t)=>{i(n=>n?.map(n=>n.key===e?{...n,provider:t}:n)??n)},[]),S=(0,Q.useCallback)(e=>{i(t=>t?.filter(t=>t.key!==e)??t),m(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),C=(0,Q.useCallback)((e,t)=>{m(n=>{if(n.has(e)===!t)return n;let r=new Set(n);return t?r.delete(e):r.add(e),r})},[]),w=(0,Q.useCallback)((e,t)=>{c(n=>{let r={...n};return t?r[e]=t:delete r[e],r})},[]);function T(){if(!r)return;let e={id:EG(r.map(e=>e.provider),`local`),kind:`openai-compatible`,baseUrl:`http://127.0.0.1:11434/v1`};i([...r,{key:EK++,provider:e,persisted:!1}])}function E(e){if(!r)return;let t=r.map(e=>e.provider),n=e&&!t.some(t=>t.id===e)?{id:e,kind:`cli`,cli:e}:{id:EG(t,`cli`),kind:`cli`,cli:e??`claude`};i([...r,{key:EK++,provider:n,persisted:!1}])}async function D(){if(v){f(!0),u(``);try{let e=await fetch(`/api/runtime-providers`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({providers:v})}),n=await e.json().catch(()=>null);if(!e.ok||!gG(n))throw Error(n?.message??t(`saveFailed`));if(!_.current)return;i(DK(n.providers,!0)),o(n.providers),c(n.status??{}),m(new Set),J.success(t(`saved`))}catch(e){let n=e.message||t(`saveFailed`);_.current&&u(n),J.error(t(`saveFailed`),{description:n})}finally{_.current&&f(!1)}}}let O=r?.filter(e=>e.provider.kind===`cli`)??[],k=r?.filter(e=>e.provider.kind===`openai-compatible`)??[],A=fG.filter(e=>!O.some(t=>t.provider.cli===e)),j=(0,$.jsxs)(Z,{size:`sm`,className:`gap-1.5`,onClick:T,"data-testid":`add-local-engine`,children:[(0,$.jsx)(Pn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`providers.addLocalHero`)]});return(0,$.jsxs)(`section`,{className:`space-y-6`,"aria-labelledby":`provider-connections-title`,"data-testid":`provider-connections-card`,children:[(0,$.jsx)(`div`,{className:`flex flex-wrap items-start justify-between gap-4`,children:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(`span`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border border-accent-primary/30 bg-accent-primary/10 text-accent-primary shadow-sm`,children:(0,$.jsx)(fs,{className:`h-5 w-5`,"aria-hidden":!0})}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`h2`,{id:`provider-connections-title`,className:`text-base font-semibold tracking-tight`,children:t(`providers.globalTitle`)}),(0,$.jsx)(`p`,{className:`mt-1 max-w-2xl text-sm text-muted-foreground`,children:t(`providers.globalHint`)})]})]})}),l&&(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:l}),!r&&!l&&(0,$.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:t(`loading`)}),r&&n&&(0,$.jsxs)(`fieldset`,{disabled:d,className:`space-y-3 disabled:opacity-70`,children:[r.length===0&&(0,$.jsx)(`p`,{className:`rounded-xl border border-dashed border-border p-4 text-center text-xs text-muted-foreground`,children:t(`providers.empty`)}),r.map(e=>(0,$.jsx)(lK,{provider:e.provider,onChange:t=>x(e.key,t),onRemove:()=>S(e.key)},e.key)),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsxs)(Z,{variant:`secondary`,size:`sm`,className:`gap-1.5`,onClick:()=>E(),children:[(0,$.jsx)(Pn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`providers.addCli`)]}),(0,$.jsxs)(Z,{variant:`secondary`,size:`sm`,className:`gap-1.5`,onClick:T,children:[(0,$.jsx)(Pn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`providers.addLocal`)]})]})]}),r&&!n&&(0,$.jsxs)(`fieldset`,{disabled:d,className:`space-y-6 disabled:opacity-70`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,"data-testid":`cli-group`,children:[(0,$.jsx)(kK,{icon:(0,$.jsx)(Ec,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),title:t(`providers.cliGroup`),hint:t(`providers.cliGroupHint`),count:O.length,action:A.length>0&&(0,$.jsx)(pK,{label:t(`providers.addCli`),align:`right`,trigger:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Pn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`providers.addCli`)]}),items:A.map(e=>({id:e,label:t(`cliNames.${e}`),icon:(0,$.jsx)(Ec,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":!0}),onSelect:()=>E(e)}))})}),O.length===0?(0,$.jsx)(`p`,{className:`rounded-xl border border-dashed border-border p-4 text-center text-xs text-muted-foreground`,children:t(`providers.notDetected`)}):(0,$.jsx)(`ul`,{className:`divide-y divide-border/60 overflow-hidden rounded-xl border border-border/70 bg-card/60 shadow-sm`,"aria-label":t(`providers.cliGroup`),children:O.map(e=>(0,$.jsx)(mK,{provider:e.provider,status:s[e.provider.id],onRemove:()=>S(e.key)},e.key))})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,"data-testid":`local-group`,children:[(0,$.jsx)(kK,{icon:(0,$.jsx)(xc,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),title:t(`providers.localGroup`),hint:t(`providers.localGroupHint`),count:k.length,action:k.length>0?j:void 0}),k.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 rounded-xl border border-dashed border-border bg-card/30 px-4 py-8 text-center`,"data-testid":`local-empty`,children:[(0,$.jsx)(`span`,{className:`flex h-10 w-10 items-center justify-center rounded-xl border border-accent-highlight/30 bg-accent-highlight/10 text-accent-highlight`,children:(0,$.jsx)(xc,{className:`h-5 w-5`,"aria-hidden":!0})}),(0,$.jsx)(`p`,{className:`max-w-md text-xs text-muted-foreground`,children:t(`providers.emptyLocalPitch`)}),j]}):(0,$.jsx)(`div`,{className:`space-y-3`,children:k.map(e=>(0,$.jsx)(TK,{provider:e.provider,status:s[e.provider.id],persisted:e.persisted,invalid:p.has(e.key),onChange:t=>x(e.key,t),onStatus:t=>w(e.provider.id,t),onValidity:t=>C(e.key,t),onRemove:()=>S(e.key)},e.key))})]})]}),r&&(0,$.jsxs)(`div`,{className:X(`flex flex-wrap items-center justify-end gap-3 rounded-xl px-3 py-2 transition-all`,y&&`sticky bottom-0 z-20 border border-accent-warning/30 bg-card/95 shadow-lg backdrop-blur`),"data-testid":`provider-save-bar`,"data-sticky":y,children:[y&&(0,$.jsxs)(`span`,{className:`mr-auto inline-flex h-6 items-center gap-1.5 rounded-full border border-accent-warning/30 bg-accent-warning/10 px-2.5 text-[11px] font-medium text-accent-warning`,role:`status`,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-full bg-accent-warning`}),t(`providers.unsaved`)]}),b&&(0,$.jsx)(`p`,{className:`text-xs text-destructive`,children:t(`providers.fixBeforeSave`)}),(0,$.jsxs)(Z,{disabled:d||b||!y,className:`gap-1.5`,onClick:()=>void D(),children:[(0,$.jsx)(dn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(d?`saving`:`save`)]})]}),e&&(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/40`,"data-testid":`provider-defaults`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":h,"aria-controls":`provider-defaults-body`,onClick:()=>g(e=>!e),className:`flex w-full items-center gap-2 px-4 py-3 text-left transition-colors hover:bg-muted/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-xl`,children:[(0,$.jsx)(wc,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:t(`providers.defaultsGroup`)}),(0,$.jsx)(Xo,{className:X(`ml-auto h-4 w-4 text-muted-foreground transition-transform duration-200`,h&&`rotate-180`),"aria-hidden":!0})]}),h&&(0,$.jsx)(`div`,{id:`provider-defaults-body`,className:`px-4 pb-4 [&>section]:border-t-0 [&>section]:pt-1`,children:e})]})]})}function kK({icon:e,title:t,hint:n,count:r,action:i}){return(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-2 px-0.5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:[e,t,(0,$.jsx)(`span`,{className:`rounded-full border border-border bg-muted/40 px-1.5 py-px text-[10px] font-medium tabular-nums`,children:r})]}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[11px] text-muted-foreground/80`,children:n})]}),i]})}function AK(){let{t:e}=K(`settings`),{registerHandler:t,unregisterHandler:n}=tt(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(!1),d=(0,Q.useRef)(0),f=(0,Q.useRef)(null),p=(0,Q.useCallback)(async()=>{let e=++d.current;try{let t=await fetch(`/api/core-update/status`);if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();return e===d.current?(i(n),u(!1),n.updating||c(null),n):null}catch{return e===d.current&&u(!0),null}},[]);(0,Q.useEffect)(()=>{p();let e=()=>{p()};return window.addEventListener(`focus`,e),()=>{d.current++,window.removeEventListener(`focus`,e)}},[p]);let m=(0,Q.useRef)(p);m.current=p,(0,Q.useEffect)(()=>(t(`core-update`,t=>{let n=t;if(n.type===`framework.updated`){m.current();return}if(n.type!==`core_update.progress`)return;let r=n.phase;c(r),r===`done`?(J.success(e(`coreUpdate.toastDone`,{version:String(n.version??``)})),m.current(),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>c(null),2500)):r===`error`&&(J.error(e(`coreUpdate.toastError`,{message:String(n.message??``)})),m.current(),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>c(null),4e3))}),()=>{n(`core-update`),f.current&&clearTimeout(f.current)}),[t,n,e]);let h=(0,Q.useCallback)(async()=>{let t=++d.current;o(!0);try{let n=await fetch(`/api/core-update/check`,{method:`POST`});if(!n.ok)throw Error(`HTTP ${n.status}`);let r=await n.json();if(t!==d.current)return;i(r),r.updateAvailable||J.success(e(`coreUpdate.toastUpToDate`))}catch(t){J.error(e(`coreUpdate.toastCheckFailed`,{message:t.message}))}finally{o(!1)}},[e]),g=s===`downloading`||s===`materializing`||!!r?.updating;(0,Q.useEffect)(()=>{if(!g)return;let e=setInterval(()=>{p()},1500);return()=>clearInterval(e)},[g,p]);let _=(0,Q.useCallback)(async()=>{c(`downloading`);try{let e=await fetch(`/api/core-update/update`,{method:`POST`,headers:{"Content-Type":`application/json`},body:`{}`});if(e.status!==202){let t=await e.json().catch(()=>({}));throw Error(t.message??`HTTP ${e.status}`)}}catch(t){c(null),J.error(e(`coreUpdate.toastError`,{message:t.message}))}},[e]);if(!r)return l?(0,$.jsx)(`button`,{type:`button`,onClick:()=>{p()},className:`text-xs text-destructive`,children:e(`coreUpdate.loadFailed`)}):(0,$.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`});let v=r.currentVersion??`—`,y=r.pendingVersion??r.latestVersion;return(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e(`coreUpdate.heading`)}),(0,$.jsx)(`div`,{className:`rounded-md border border-border p-3 space-y-3`,children:r.available?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`p`,{className:`text-xs text-foreground`,children:[e(`coreUpdate.installed`),` `,(0,$.jsx)(`span`,{className:`font-semibold tabular-nums`,children:v})]}),r.runtimeVersion&&(0,$.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[e(`coreUpdate.runtime`,{version:r.runtimeVersion}),r.runtimeSource?` · ${e(`coreUpdate.sources.${r.runtimeSource}`)}`:``]}),r.bundledVersion&&r.bundledVersion!==r.runtimeVersion&&(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:e(`coreUpdate.bundled`,{version:r.bundledVersion})}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground/70 truncate`,children:r.updateAvailable&&r.latestVersion?e(`coreUpdate.updateAvailable`,{version:r.latestVersion}):r.lastCheckedAt?e(`coreUpdate.upToDate`):e(`coreUpdate.neverChecked`)})]}),r.updateAvailable&&y?(0,$.jsxs)(`button`,{type:`button`,onClick:_,disabled:g,className:`inline-flex h-7 shrink-0 items-center gap-1.5 rounded-lg border border-accent-primary/45 bg-accent-primary/15 px-3 text-[11px] font-semibold text-accent-primary disabled:opacity-50`,children:[g?(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(En,{className:`h-3.5 w-3.5`}),g?e(s===`materializing`?`coreUpdate.materializing`:`coreUpdate.downloading`):r.pendingVersion?e(`coreUpdate.repair`,{version:y}):e(`coreUpdate.update`,{version:y})]}):(0,$.jsxs)(`button`,{type:`button`,onClick:h,disabled:a||g,className:`inline-flex h-7 shrink-0 items-center gap-1.5 rounded-lg border border-border bg-background px-3 text-[11px] font-medium text-muted-foreground hover:text-foreground disabled:opacity-50`,children:[a?(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`}):s===`done`?(0,$.jsx)($o,{className:`h-3.5 w-3.5 text-accent-success`}):(0,$.jsx)(mc,{className:`h-3.5 w-3.5`}),e(a?`coreUpdate.checking`:`coreUpdate.check`)]})]}),r.runtimeError&&(0,$.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:r.runtimeError}),r.migrationError&&(0,$.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:r.migrationError}),l&&(0,$.jsx)(`button`,{type:`button`,className:`text-xs text-destructive`,onClick:()=>{p()},children:e(`coreUpdate.loadFailed`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground/70`,children:e(`coreUpdate.affectsAll`)})]}):(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e(`coreUpdate.unavailable`)})})]})}var jK=class extends ht{constructor(e){super(e.rid),this.available=!0,this.currentVersion=e.currentVersion,this.version=e.version,this.date=e.date,this.body=e.body,this.rawJson=e.rawJson}async download(e,t){NK(t);let n=new _t;e&&(n.onmessage=e);let r=await Y(`plugin:updater|download`,{onEvent:n,rid:this.rid,...t});this.downloadedBytes=new ht(r)}async install(){if(!this.downloadedBytes)throw Error(`Update.install called before Update.download`);await Y(`plugin:updater|install`,{updateRid:this.rid,bytesRid:this.downloadedBytes.rid}),this.downloadedBytes=void 0}async downloadAndInstall(e,t){NK(t);let n=new _t;e&&(n.onmessage=e),await Y(`plugin:updater|download_and_install`,{onEvent:n,rid:this.rid,...t})}async close(){await this.downloadedBytes?.close(),await super.close()}};async function MK(e){NK(e);let t=await Y(`plugin:updater|check`,{...e});return t?new jK(t):null}function NK(e){e?.headers&&(e.headers=Array.from(new Headers(e.headers).entries()))}var PK;(function(e){e.Nsis=`nsis`,e.Msi=`msi`,e.Deb=`deb`,e.Rpm=`rpm`,e.AppImage=`appimage`,e.App=`app`})(PK||={});async function FK(){return Y(`plugin:app|version`)}async function IK(){await Y(`plugin:process|restart`)}var LK=`specrails-desktop:dismissedDesktopUpdateVersion`,RK=`specrails-desktop-desktop-update`,zK=360*60*1e3;function BK(){return typeof window<`u`&&`__TAURI_INTERNALS__`in window}function VK(){return{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1}.VITE_MOCK_DESKTOP_UPDATE===`true`}function HK(){return{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1}.VITE_MOCK_DESKTOP_UPDATE_VERSION||`99.0.0-test`}function UK(e){return new Promise(t=>setTimeout(t,e))}function WK(){return{currentVersion:`1.40.1`,version:HK(),isMock:!0,async downloadAndInstall(e){e({event:`Started`,data:{contentLength:18874368}});for(let t=0;t<12;t+=1)await UK(180),e({event:`Progress`,data:{chunkLength:1572864}});e({event:`Finished`})}}}function GK(e){return e<1024*1024?Je.t(`commands:update.units.kb`,{value:Math.max(1,Math.round(e/1024))}):Je.t(`commands:update.units.mb`,{value:(e/(1024*1024)).toFixed(1)})}function KK(){try{return localStorage.getItem(LK)}catch{return null}}function qK(e){try{localStorage.setItem(LK,e)}catch{}J.dismiss(RK)}function JK(e){switch(e){case`downloading`:return`var(--color-accent-info)`;case`ready`:return`var(--color-accent-success)`;default:return`var(--color-accent-primary)`}}function YK({state:e}){let t=`h-[15px] w-[15px]`;return e===`installing`?(0,$.jsx)(as,{className:`${t} u-spin`,"aria-hidden":!0}):e===`ready`?(0,$.jsx)(Sn,{className:`${t} u-check`,"aria-hidden":!0}):e===`error`?(0,$.jsx)(zn,{className:t,"aria-hidden":!0}):(0,$.jsx)(rs,{className:t,"aria-hidden":!0})}function XK({state:e,progress:t}){let n=e===`downloading`&&t!=null,r=e===`installing`||e===`downloading`&&t==null,i=e===`ready`;return(0,$.jsxs)(`div`,{className:`relative h-1.5 w-full overflow-hidden rounded-full border border-border/30 bg-background/70`,children:[n&&(0,$.jsx)(`div`,{className:`relative h-full overflow-hidden rounded-full bg-[color:var(--u-accent)] transition-[width] duration-300 ease-out`,style:{width:`${t}%`},role:`progressbar`,"aria-valuenow":t??0,"aria-valuemin":0,"aria-valuemax":100,children:(0,$.jsx)(`span`,{className:`u-shimmer`,"aria-hidden":!0})}),r&&(0,$.jsx)(`span`,{className:`u-indeterminate`,"aria-hidden":!0}),i&&(0,$.jsx)(`div`,{className:`h-full w-full rounded-full bg-[color:var(--u-accent)]/80`,"aria-hidden":!0})]})}function ZK({update:e,onClose:t}){let{t:n}=K(`commands`),[r,i]=(0,Q.useState)(`available`),[a,o]=(0,Q.useState)(0),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null);async function d(){try{i(`downloading`),o(0),c(null),u(null),await e.downloadAndInstall(e=>{if(e.event===`Started`){c(e.data.contentLength??null),o(0);return}if(e.event===`Progress`){o(t=>t+e.data.chunkLength);return}i(`installing`)}),i(`ready`)}catch(e){u(e.message||n(`update.errors.installFailed`)),i(`error`)}}function f(){if(e.isMock){J.success(n(`update.mockReady`),{duration:2500}),J.dismiss(RK),t?.();return}Y(`restart_app`).catch(()=>{IK()})}let p=s&&s>0?Math.min(100,Math.round(a/s*100)):null,m=JK(r),h=r===`downloading`||r===`installing`,g=n(r===`downloading`?`update.title.downloading`:r===`installing`?`update.title.installing`:r===`ready`?`update.title.ready`:r===`error`?`update.title.error`:`update.title.available`),_=r===`available`?n(`update.desc.available`):r===`downloading`?p==null?n(`update.desc.fetching`,{size:GK(a)}):n(`update.desc.progress`,{percent:p,downloaded:GK(a),total:GK(s??0)}):r===`installing`?n(`update.desc.installing`):r===`ready`?n(`update.desc.ready`,{version:e.version}):l&&l.length<=80?l:n(`update.desc.errorFallback`),v=r===`available`?`${e.currentVersion} → ${e.version}`:r===`downloading`?n(`update.pill.downloading`):r===`installing`?n(`update.pill.installing`):r===`ready`?n(`update.pill.ready`):null;return(0,$.jsxs)(`div`,{className:`u-update-card relative flex w-full flex-col gap-2 overflow-hidden`,style:{"--u-accent":m},role:r===`error`?`alert`:`status`,"aria-live":r===`error`?`assertive`:`polite`,"data-state":r,children:[(0,$.jsx)(`span`,{className:`u-glow`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(`span`,{className:`u-badge grid h-7 w-7 shrink-0 place-items-center rounded-lg border border-border/50 bg-background/60 text-[color:var(--u-accent)]`,"aria-hidden":!0,children:(0,$.jsx)(YK,{state:r})}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] font-semibold leading-tight text-foreground`,children:g}),v!=null&&(0,$.jsx)(`span`,{className:`shrink-0 whitespace-nowrap rounded-md border border-border/40 bg-background/60 px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-muted-foreground`,style:r===`available`?void 0:{color:`var(--u-accent)`},children:v})]}),(0,$.jsx)(`p`,{className:`h-4 truncate text-[11px] leading-4 text-muted-foreground`,"data-testid":`update-description`,children:_}),(0,$.jsx)(XK,{state:r,progress:p}),(0,$.jsx)(`div`,{className:`flex items-center justify-end gap-1.5`,children:r===`ready`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,className:`inline-grid h-7 min-w-[64px] place-items-center rounded-lg border border-[color:var(--u-accent)]/45 bg-[color:var(--u-accent)]/15 px-3 text-[11px] font-semibold leading-none text-foreground transition-colors hover:bg-[color:var(--u-accent)]/25`,onClick:f,children:n(`update.actions.restart`)}),(0,$.jsx)(`button`,{type:`button`,className:`h-7 rounded-lg px-2.5 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-background/70 hover:text-foreground`,onClick:()=>{J.dismiss(RK),t?.()},children:n(`update.actions.later`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,className:`inline-grid h-7 min-w-[64px] place-items-center rounded-lg border border-[color:var(--u-accent)]/45 bg-[color:var(--u-accent)]/15 px-3 text-[11px] font-semibold leading-none text-foreground transition-colors hover:bg-[color:var(--u-accent)]/25 disabled:cursor-not-allowed disabled:opacity-50`,disabled:h,onClick:()=>void d(),children:n(r===`installing`?`update.actions.installing`:r===`error`?`update.actions.tryAgain`:`update.actions.update`)}),(0,$.jsx)(`button`,{type:`button`,className:`h-7 rounded-lg px-2.5 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-background/70 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,disabled:h,onClick:()=>{qK(e.version),t?.()},children:n(`update.actions.dismiss`)})]})})]})}function QK(e){J.custom(()=>(0,$.jsx)(ZK,{update:e}),{id:RK,duration:1/0,dismissible:!1,unstyled:!0,closeButton:!1})}function $K(){(0,Q.useEffect)(()=>{let e=VK();if(!e&&!BK())return;let t=!1,n={current:!1};async function r(){if(!(t||n.current))try{let r=e?WK():await MK();if(t||!r||KK()===r.version)return;n.current=!0,J.custom(()=>(0,$.jsx)(ZK,{update:r,onClose:()=>{n.current=!1}}),{id:RK,duration:1/0,dismissible:!1,unstyled:!0,closeButton:!1,onDismiss:()=>{n.current=!1},onAutoClose:()=>{n.current=!1}})}catch(e){console.warn(`[desktop-update] update check failed:`,e)}}r();let i=setInterval(()=>void r(),zK);return()=>{t=!0,clearInterval(i)}},[])}function eq(){let{t:e}=K(`settings`),t=VK(),n=BK()||t,[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!BK())return;let e=!0;return FK().then(t=>{e&&i(t)}).catch(()=>{}),()=>{e=!1}},[]);let d=(0,Q.useCallback)(async()=>{o(!0),c(null);try{let n=t?WK():await MK();n?(c(`update-available`),u(n.version),QK(n)):(c(`up-to-date`),J.success(e(`appUpdate.toastUpToDate`)))}catch(t){J.error(e(`appUpdate.toastCheckFailed`,{message:t.message}))}finally{o(!1)}},[t,e]);return(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e(`appUpdate.heading`)}),(0,$.jsx)(`div`,{className:`rounded-md border border-border p-3 space-y-3`,children:n?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`p`,{className:`text-xs text-foreground`,children:[e(`appUpdate.installed`),` `,(0,$.jsx)(`span`,{className:`font-semibold tabular-nums`,children:r??`—`})]}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground/70 truncate`,children:s===`update-available`&&l?e(`appUpdate.updateAvailable`,{version:l}):e(s===`up-to-date`?`appUpdate.upToDate`:`appUpdate.autoHint`)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void d(),disabled:a,className:`inline-flex h-7 shrink-0 items-center gap-1.5 rounded-lg border border-border bg-background px-3 text-[11px] font-medium text-muted-foreground hover:text-foreground disabled:opacity-50`,children:[a?(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`}):s===`up-to-date`?(0,$.jsx)($o,{className:`h-3.5 w-3.5 text-accent-success`}):(0,$.jsx)(mc,{className:`h-3.5 w-3.5`}),e(a?`appUpdate.checking`:`appUpdate.check`)]})]})}):(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e(`appUpdate.unavailable`)})})]})}var tq=Object.defineProperty,nq=Object.getOwnPropertySymbols,rq=Object.prototype.hasOwnProperty,iq=Object.prototype.propertyIsEnumerable,aq=(e,t,n)=>t in e?tq(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,oq=(e,t)=>{for(var n in t||={})rq.call(t,n)&&aq(e,n,t[n]);if(nq)for(var n of nq(t))iq.call(t,n)&&aq(e,n,t[n]);return e},sq=(e,t)=>{var n={};for(var r in e)rq.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&nq)for(var r of nq(e))t.indexOf(r)<0&&iq.call(e,r)&&(n[r]=e[r]);return n},cq;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e<this.size;e++)o.push(!1);for(let e=0;e<this.size;e++)this.modules.push(o.slice()),this.isFunction.push(o.slice());this.drawFunctionPatterns();let s=this.addEccAndInterleave(r);if(this.drawCodewords(s),a==-1){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);let n=this.getPenaltyScore();n<e&&(a=t,e=n),this.applyMask(t)}}i(0<=a&&a<=7),this.mask=a,this.applyMask(a),this.drawFormatBits(a),this.isFunction=[]}static encodeText(n,r){let i=e.QrSegment.makeSegments(n);return t.encodeSegments(i,r)}static encodeBinary(n,r){let i=e.QrSegment.makeBytes(n);return t.encodeSegments([i],r)}static encodeSegments(e,r,a=1,s=40,c=-1,l=!0){if(!(t.MIN_VERSION<=a&&a<=s&&s<=t.MAX_VERSION)||c<-1||c>7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.length<p;e^=253)n(e,8,f);let m=[];for(;m.length*8<f.length;)m.push(0);return f.forEach((e,t)=>m[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e<this.size&&0<=t&&t<this.size&&this.modules[t][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let e=0;e<this.size;e++)this.setFunctionModule(6,e,e%2==0),this.setFunctionModule(e,6,e%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)n==0&&r==0||n==0&&r==t-1||n==t-1&&r==0||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){let t=this.errorCorrectionLevel.formatBits<<3|e,n=t;for(let e=0;e<10;e++)n=n<<1^(n>>>9)*1335;let a=(t<<10|n)^21522;i(a>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(t>>>18==0);for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a<this.size&&0<=o&&o<this.size&&this.setFunctionModule(a,o,i!=2&&i!=4)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,Math.max(Math.abs(r),Math.abs(n))!=1)}setFunctionModule(e,t,n){this.modules[t][e]=n,this.isFunction[t][e]=!0}addEccAndInterleave(e){let n=this.version,r=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(n,r))throw RangeError(`Invalid argument`);let a=t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][n],o=t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][n],s=Math.floor(t.getNumRawDataModules(n)/8),c=a-s%a,l=Math.floor(s/a),u=[],d=t.reedSolomonComputeDivisor(o);for(let n=0,r=0;n<a;n++){let i=e.slice(r,r+l-o+(n<c?0:1));r+=i.length;let a=t.reedSolomonComputeRemainder(i,d);n<c&&i.push(0),u.push(i.concat(a))}let f=[];for(let e=0;e<u[0].length;e++)u.forEach((t,n)=>{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i<this.size;i++)for(let a=0;a<2;a++){let o=t-a,s=t+1&2?i:this.size-1-i;!this.isFunction[s][o]&&n<e.length*8&&(this.modules[s][o]=r(e[n>>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw Error(`Unreachable`)}!this.isFunction[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[n][o]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[o][n]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size-1;n++)for(let r=0;r<this.size-1;r++){let i=this.modules[n][r];i==this.modules[n][r+1]&&i==this.modules[n+1][r]&&i==this.modules[n+1][r+1]&&(e+=t.PENALTY_N2)}let n=0;for(let e of this.modules)n=e.reduce((e,t)=>e+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}static getNumRawDataModules(e){if(e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t<e-1;t++)n.push(0);n.push(1);let r=1;for(let i=0;i<e;i++){for(let e=0;e<n.length;e++)n[e]=t.reedSolomonMultiply(n[e],r),e+1<n.length&&(n[e]^=n[e+1]);r=t.reedSolomonMultiply(r,2)}return n}static reedSolomonComputeRemainder(e,n){let r=n.map(e=>0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(n>>>8==0),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e<t.length;){let i=Math.min(t.length-e,3);n(parseInt(t.substring(e,e+i),10),i*3+1,r),e+=i}return new e(e.Mode.NUMERIC,t.length,r)}static makeAlphanumeric(t){if(!e.isAlphanumeric(t))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let r=[],i;for(i=0;i+2<=t.length;i+=2){let a=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i))*45;a+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i+1)),n(a,11,r)}return i<t.length&&n(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i)),6,r),new e(e.Mode.ALPHANUMERIC,t.length,r)}static makeSegments(t){return t==``?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]}static makeEci(t){let r=[];if(t<0)throw RangeError(`ECI assignment value out of range`);if(t<128)n(t,8,r);else if(t<16384)n(2,2,r),n(t,14,r);else if(t<1e6)n(6,3,r),n(t,21,r);else throw RangeError(`ECI assignment value out of range`);return new e(e.Mode.ECI,0,r)}static isNumeric(t){return e.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return e.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(e,t){let n=0;for(let r of e){let e=r.mode.numCharCountBits(t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}static toUtf8ByteArray(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)e.charAt(n)==`%`?(t.push(parseInt(e.substring(n+1,n+3),16)),n+=2):t.push(e.charCodeAt(n));return t}};a.NUMERIC_REGEX=/^[0-9]*$/,a.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,a.ALPHANUMERIC_CHARSET=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`;let o=a;e.QrSegment=a})(cq||={}),(e=>{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(cq||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(cq||={});var lq=cq,uq={L:lq.QrCode.Ecc.LOW,M:lq.QrCode.Ecc.MEDIUM,Q:lq.QrCode.Ecc.QUARTILE,H:lq.QrCode.Ecc.HIGH},dq=128,fq=`L`,pq=`#FFFFFF`,mq=`#000000`,hq=!1,gq=1,_q=4,vq=0,yq=.1;function bq(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function xq(e,t){return e.slice().map((e,n)=>n<t.y||n>=t.y+t.h?e:e.map((e,n)=>n<t.x||n>=t.x+t.w?e:!1))}function Sq(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*yq),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function Cq(e,t){return t==null?e?_q:vq:Math.max(Math.floor(t),0)}function wq({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=Q.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...lq.QrSegment.makeSegments(t)),e),[]);return lq.QrCode.encodeSegments(r,uq[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=Q.useMemo(()=>{let e=c.getModules(),t=Cq(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:Sq(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var Tq=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),Eq=Q.forwardRef(function(e,t){let n=e,{value:r,size:i=dq,level:a=fq,bgColor:o=pq,fgColor:s=mq,includeMargin:c=hq,minVersion:l=gq,boostLevel:u,marginSize:d,imageSettings:f}=n,p=sq(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=sq(p,[`style`]),g=f?.src,_=Q.useRef(null),v=Q.useRef(null),y=Q.useCallback(e=>{_.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[b,x]=Q.useState(!1),{margin:S,cells:C,numCells:w,calculatedImageSettings:T}=wq({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});Q.useEffect(()=>{if(_.current!=null){let e=_.current,t=e.getContext(`2d`);if(!t)return;let n=C,r=v.current,a=T!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&T.excavation!=null&&(n=xq(C,T.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/w*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,w,w),t.fillStyle=s,Tq?t.fill(new Path2D(bq(n,S))):C.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+S,n+S,1,1)})}),T&&(t.globalAlpha=T.opacity),a&&t.drawImage(r,T.x+S,T.y+S,T.w,T.h)}}),Q.useEffect(()=>{x(!1)},[g]);let E=oq({height:i,width:i},m),D=null;return g!=null&&(D=Q.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{x(!0)},ref:v,crossOrigin:T?.crossOrigin})),Q.createElement(Q.Fragment,null,Q.createElement(`canvas`,oq({style:E,height:i,width:i,ref:y,role:`img`},h)),D)});Eq.displayName=`QRCodeCanvas`;var Dq=Q.forwardRef(function(e,t){let n=e,{value:r,size:i=dq,level:a=fq,bgColor:o=pq,fgColor:s=mq,includeMargin:c=hq,minVersion:l=gq,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=sq(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=wq({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),y=g,b=null;p!=null&&v!=null&&(v.excavation!=null&&(y=xq(g,v.excavation)),b=Q.createElement(`image`,{href:p.src,height:v.h,width:v.w,x:v.x+h,y:v.y+h,preserveAspectRatio:`none`,opacity:v.opacity,crossOrigin:v.crossOrigin}));let x=bq(y,h);return Q.createElement(`svg`,oq({height:i,width:i,viewBox:`0 0 ${_} ${_}`,ref:t,role:`img`},m),!!d&&Q.createElement(`title`,null,d),Q.createElement(`path`,{fill:o,d:`M0,0 h${_}v${_}H0z`,shapeRendering:`crispEdges`}),Q.createElement(`path`,{fill:s,d:x,shapeRendering:`crispEdges`}),b)});Dq.displayName=`QRCodeSVG`;var Oq=e(i(((e,t)=>{(function(n,r){typeof e==`object`&&typeof t==`object`?t.exports=r():typeof define==`function`&&define.amd?define([],r):typeof e==`object`?e.jsQR=r():n.jsQR=r()})(typeof self<`u`?self:e,function(){return(function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,`a`,t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=``,n(n.s=3)})([(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.BitMatrix=function(){function e(e,t){this.width=t,this.height=e.length/t,this.data=e}return e.createEmpty=function(t,n){return new e(new Uint8ClampedArray(t*n),t)},e.prototype.get=function(e,t){return e<0||e>=this.width||t<0||t>=this.height?!1:!!this.data[t*this.width+e]},e.prototype.set=function(e,t,n){this.data[t*this.width+e]=+!!n},e.prototype.setRegion=function(e,t,n,r,i){for(var a=t;a<t+r;a++)for(var o=e;o<e+n;o++)this.set(o,a,!!i)},e}()}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);function i(e,t){return e^t}t.addOrSubtractGF=i,t.default=function(){function e(e,t,n){this.primitive=e,this.size=t,this.generatorBase=n,this.expTable=Array(this.size),this.logTable=Array(this.size);for(var i=1,a=0;a<this.size;a++)this.expTable[a]=i,i*=2,i>=this.size&&(i=(i^this.primitive)&this.size-1);for(var a=0;a<this.size-1;a++)this.logTable[this.expTable[a]]=a;this.zero=new r.default(this,Uint8ClampedArray.from([0])),this.one=new r.default(this,Uint8ClampedArray.from([1]))}return e.prototype.multiply=function(e,t){return e===0||t===0?0:this.expTable[(this.logTable[e]+this.logTable[t])%(this.size-1)]},e.prototype.inverse=function(e){if(e===0)throw Error(`Can't invert 0`);return this.expTable[this.size-this.logTable[e]-1]},e.prototype.buildMonomial=function(e,t){if(e<0)throw Error(`Invalid monomial degree less than 0`);if(t===0)return this.zero;var n=new Uint8ClampedArray(e+1);return n[0]=t,new r.default(this,n)},e.prototype.log=function(e){if(e===0)throw Error(`Can't take log(0)`);return this.logTable[e]},e.prototype.exp=function(e){return this.expTable[e]},e}()}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(1);t.default=function(){function e(e,t){if(t.length===0)throw Error(`No coefficients.`);this.field=e;var n=t.length;if(n>1&&t[0]===0){for(var r=1;r<n&&t[r]===0;)r++;if(r===n)this.coefficients=e.zero.coefficients;else{this.coefficients=new Uint8ClampedArray(n-r);for(var i=0;i<this.coefficients.length;i++)this.coefficients[i]=t[r+i]}}else this.coefficients=t}return e.prototype.degree=function(){return this.coefficients.length-1},e.prototype.isZero=function(){return this.coefficients[0]===0},e.prototype.getCoefficient=function(e){return this.coefficients[this.coefficients.length-1-e]},e.prototype.addOrSubtract=function(t){var n;if(this.isZero())return t;if(t.isZero())return this;var i=this.coefficients,a=t.coefficients;i.length>a.length&&(n=[a,i],i=n[0],a=n[1]);for(var o=new Uint8ClampedArray(a.length),s=a.length-i.length,c=0;c<s;c++)o[c]=a[c];for(var c=s;c<a.length;c++)o[c]=r.addOrSubtractGF(i[c-s],a[c]);return new e(this.field,o)},e.prototype.multiply=function(t){if(t===0)return this.field.zero;if(t===1)return this;for(var n=this.coefficients.length,r=new Uint8ClampedArray(n),i=0;i<n;i++)r[i]=this.field.multiply(this.coefficients[i],t);return new e(this.field,r)},e.prototype.multiplyPoly=function(t){if(this.isZero()||t.isZero())return this.field.zero;for(var n=this.coefficients,i=n.length,a=t.coefficients,o=a.length,s=new Uint8ClampedArray(i+o-1),c=0;c<i;c++)for(var l=n[c],u=0;u<o;u++)s[c+u]=r.addOrSubtractGF(s[c+u],this.field.multiply(l,a[u]));return new e(this.field,s)},e.prototype.multiplyByMonomial=function(t,n){if(t<0)throw Error(`Invalid degree less than 0`);if(n===0)return this.field.zero;for(var r=this.coefficients.length,i=new Uint8ClampedArray(r+t),a=0;a<r;a++)i[a]=this.field.multiply(this.coefficients[a],n);return new e(this.field,i)},e.prototype.evaluateAt=function(e){var t=0;if(e===0)return this.getCoefficient(0);var n=this.coefficients.length;if(e===1)return this.coefficients.forEach(function(e){t=r.addOrSubtractGF(t,e)}),t;t=this.coefficients[0];for(var i=1;i<n;i++)t=r.addOrSubtractGF(this.field.multiply(e,t),this.coefficients[i]);return t},e}()}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(4),i=n(5),a=n(11),o=n(12);function s(e){var t=o.locate(e);if(!t)return null;for(var n=0,r=t;n<r.length;n++){var s=r[n],c=a.extract(e,s),l=i.decode(c.matrix);if(l)return{binaryData:l.bytes,data:l.text,chunks:l.chunks,version:l.version,location:{topRightCorner:c.mappingFunction(s.dimension,0),topLeftCorner:c.mappingFunction(0,0),bottomRightCorner:c.mappingFunction(s.dimension,s.dimension),bottomLeftCorner:c.mappingFunction(0,s.dimension),topRightFinderPattern:s.topRight,topLeftFinderPattern:s.topLeft,bottomLeftFinderPattern:s.bottomLeft,bottomRightAlignmentPattern:s.alignmentPattern}}}return null}var c={inversionAttempts:`attemptBoth`};function l(e,t,n,i){i===void 0&&(i={});var a=c;Object.keys(a||{}).forEach(function(e){a[e]=i[e]||a[e]});var o=a.inversionAttempts===`attemptBoth`||a.inversionAttempts===`invertFirst`,l=a.inversionAttempts===`onlyInvert`||a.inversionAttempts===`invertFirst`,u=r.binarize(e,t,n,o),d=u.binarized,f=u.inverted,p=s(l?f:d);return!p&&(a.inversionAttempts===`attemptBoth`||a.inversionAttempts===`invertFirst`)&&(p=s(l?d:f)),p}l.default=l,t.default=l}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(0),i=8,a=24;function o(e,t,n){return e<t?t:e>n?n:e}var s=function(){function e(e,t){this.width=e,this.data=new Uint8ClampedArray(e*t)}return e.prototype.get=function(e,t){return this.data[t*this.width+e]},e.prototype.set=function(e,t,n){this.data[t*this.width+e]=n},e}();function c(e,t,n,c){if(e.length!==t*n*4)throw Error(`Malformed data passed to binarizer.`);for(var l=new s(t,n),u=0;u<t;u++)for(var d=0;d<n;d++){var f=e[(d*t+u)*4+0],p=e[(d*t+u)*4+1],m=e[(d*t+u)*4+2];l.set(u,d,.2126*f+.7152*p+.0722*m)}for(var h=Math.ceil(t/i),g=Math.ceil(n/i),_=new s(h,g),v=0;v<g;v++)for(var y=0;y<h;y++){for(var b=0,x=1/0,S=0,d=0;d<i;d++)for(var u=0;u<i;u++){var C=l.get(y*i+u,v*i+d);b+=C,x=Math.min(x,C),S=Math.max(S,C)}var w=b/i**2;if(S-x<=a&&(w=x/2,v>0&&y>0)){var T=(_.get(y,v-1)+2*_.get(y-1,v)+_.get(y-1,v-1))/4;x<T&&(w=T)}_.set(y,v,w)}var E=r.BitMatrix.createEmpty(t,n),D=null;c&&(D=r.BitMatrix.createEmpty(t,n));for(var v=0;v<g;v++)for(var y=0;y<h;y++){for(var O=o(y,2,h-3),k=o(v,2,g-3),b=0,A=-2;A<=2;A++)for(var j=-2;j<=2;j++)b+=_.get(O+A,k+j);for(var M=b/25,A=0;A<i;A++)for(var j=0;j<i;j++){var u=y*i+A,d=v*i+j,N=l.get(u,d);E.set(u,d,N<=M),c&&D.set(u,d,!(N<=M))}}return c?{binarized:E,inverted:D}:{binarized:E}}t.binarize=c}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(0),i=n(6),a=n(9),o=n(10);function s(e,t){for(var n=e^t,r=0;n;)r++,n&=n-1;return r}function c(e,t){return t<<1|e}var l=[{bits:21522,formatInfo:{errorCorrectionLevel:1,dataMask:0}},{bits:20773,formatInfo:{errorCorrectionLevel:1,dataMask:1}},{bits:24188,formatInfo:{errorCorrectionLevel:1,dataMask:2}},{bits:23371,formatInfo:{errorCorrectionLevel:1,dataMask:3}},{bits:17913,formatInfo:{errorCorrectionLevel:1,dataMask:4}},{bits:16590,formatInfo:{errorCorrectionLevel:1,dataMask:5}},{bits:20375,formatInfo:{errorCorrectionLevel:1,dataMask:6}},{bits:19104,formatInfo:{errorCorrectionLevel:1,dataMask:7}},{bits:30660,formatInfo:{errorCorrectionLevel:0,dataMask:0}},{bits:29427,formatInfo:{errorCorrectionLevel:0,dataMask:1}},{bits:32170,formatInfo:{errorCorrectionLevel:0,dataMask:2}},{bits:30877,formatInfo:{errorCorrectionLevel:0,dataMask:3}},{bits:26159,formatInfo:{errorCorrectionLevel:0,dataMask:4}},{bits:25368,formatInfo:{errorCorrectionLevel:0,dataMask:5}},{bits:27713,formatInfo:{errorCorrectionLevel:0,dataMask:6}},{bits:26998,formatInfo:{errorCorrectionLevel:0,dataMask:7}},{bits:5769,formatInfo:{errorCorrectionLevel:3,dataMask:0}},{bits:5054,formatInfo:{errorCorrectionLevel:3,dataMask:1}},{bits:7399,formatInfo:{errorCorrectionLevel:3,dataMask:2}},{bits:6608,formatInfo:{errorCorrectionLevel:3,dataMask:3}},{bits:1890,formatInfo:{errorCorrectionLevel:3,dataMask:4}},{bits:597,formatInfo:{errorCorrectionLevel:3,dataMask:5}},{bits:3340,formatInfo:{errorCorrectionLevel:3,dataMask:6}},{bits:2107,formatInfo:{errorCorrectionLevel:3,dataMask:7}},{bits:13663,formatInfo:{errorCorrectionLevel:2,dataMask:0}},{bits:12392,formatInfo:{errorCorrectionLevel:2,dataMask:1}},{bits:16177,formatInfo:{errorCorrectionLevel:2,dataMask:2}},{bits:14854,formatInfo:{errorCorrectionLevel:2,dataMask:3}},{bits:9396,formatInfo:{errorCorrectionLevel:2,dataMask:4}},{bits:8579,formatInfo:{errorCorrectionLevel:2,dataMask:5}},{bits:11994,formatInfo:{errorCorrectionLevel:2,dataMask:6}},{bits:11245,formatInfo:{errorCorrectionLevel:2,dataMask:7}}],u=[function(e){return(e.y+e.x)%2==0},function(e){return e.y%2==0},function(e){return e.x%3==0},function(e){return(e.y+e.x)%3==0},function(e){return(Math.floor(e.y/2)+Math.floor(e.x/3))%2==0},function(e){return e.x*e.y%2+e.x*e.y%3==0},function(e){return(e.y*e.x%2+e.y*e.x%3)%2==0},function(e){return((e.y+e.x)%2+e.y*e.x%3)%2==0}];function d(e){var t=17+4*e.versionNumber,n=r.BitMatrix.createEmpty(t,t);n.setRegion(0,0,9,9,!0),n.setRegion(t-8,0,8,9,!0),n.setRegion(0,t-8,9,8,!0);for(var i=0,a=e.alignmentPatternCenters;i<a.length;i++)for(var o=a[i],s=0,c=e.alignmentPatternCenters;s<c.length;s++){var l=c[s];o===6&&l===6||o===6&&l===t-7||o===t-7&&l===6||n.setRegion(o-2,l-2,5,5,!0)}return n.setRegion(6,9,1,t-17,!0),n.setRegion(9,6,t-17,1,!0),e.versionNumber>6&&(n.setRegion(t-11,0,3,6,!0),n.setRegion(0,t-11,6,3,!0)),n}function f(e,t,n){for(var r=u[n.dataMask],i=e.height,a=d(t),o=[],s=0,l=0,f=!0,p=i-1;p>0;p-=2){p===6&&p--;for(var m=0;m<i;m++)for(var h=f?i-1-m:m,g=0;g<2;g++){var _=p-g;if(!a.get(_,h)){l++;var v=e.get(_,h);r({y:h,x:_})&&(v=!v),s=c(v,s),l===8&&(o.push(s),l=0,s=0)}}f=!f}return o}function p(e){var t=e.height,n=Math.floor((t-17)/4);if(n<=6)return o.VERSIONS[n-1];for(var r=0,i=5;i>=0;i--)for(var a=t-9;a>=t-11;a--)r=c(e.get(a,i),r);for(var l=0,a=5;a>=0;a--)for(var i=t-9;i>=t-11;i--)l=c(e.get(a,i),l);for(var u=1/0,d,f=0,p=o.VERSIONS;f<p.length;f++){var m=p[f];if(m.infoBits===r||m.infoBits===l)return m;var h=s(r,m.infoBits);h<u&&(d=m,u=h),h=s(l,m.infoBits),h<u&&(d=m,u=h)}if(u<=3)return d}function m(e){for(var t=0,n=0;n<=8;n++)n!==6&&(t=c(e.get(n,8),t));for(var r=7;r>=0;r--)r!==6&&(t=c(e.get(8,r),t));for(var i=e.height,a=0,r=i-1;r>=i-7;r--)a=c(e.get(8,r),a);for(var n=i-8;n<i;n++)a=c(e.get(n,8),a);for(var o=1/0,u=null,d=0,f=l;d<f.length;d++){var p=f[d],m=p.bits,h=p.formatInfo;if(m===t||m===a)return h;var g=s(t,m);g<o&&(u=h,o=g),t!==a&&(g=s(a,m),g<o&&(u=h,o=g))}return o<=3?u:null}function h(e,t,n){var r=t.errorCorrectionLevels[n],i=[],a=0;if(r.ecBlocks.forEach(function(e){for(var t=0;t<e.numBlocks;t++)i.push({numDataCodewords:e.dataCodewordsPerBlock,codewords:[]}),a+=e.dataCodewordsPerBlock+r.ecCodewordsPerBlock}),e.length<a)return null;e=e.slice(0,a);for(var o=r.ecBlocks[0].dataCodewordsPerBlock,s=0;s<o;s++)for(var c=0,l=i;c<l.length;c++){var u=l[c];u.codewords.push(e.shift())}if(r.ecBlocks.length>1)for(var d=r.ecBlocks[0].numBlocks,f=r.ecBlocks[1].numBlocks,s=0;s<f;s++)i[d+s].codewords.push(e.shift());for(;e.length>0;)for(var p=0,m=i;p<m.length;p++){var u=m[p];u.codewords.push(e.shift())}return i}function g(e){var t=p(e);if(!t)return null;var n=m(e);if(!n)return null;var r=h(f(e,t,n),t,n.errorCorrectionLevel);if(!r)return null;for(var o=r.reduce(function(e,t){return e+t.numDataCodewords},0),s=new Uint8ClampedArray(o),c=0,l=0,u=r;l<u.length;l++){var d=u[l],g=a.decode(d.codewords,d.codewords.length-d.numDataCodewords);if(!g)return null;for(var _=0;_<d.numDataCodewords;_++)s[c++]=g[_]}try{return i.decode(s,t.versionNumber)}catch{return null}}function _(e){if(e==null)return null;var t=g(e);if(t)return t;for(var n=0;n<e.width;n++)for(var r=n+1;r<e.height;r++)e.get(n,r)!==e.get(r,n)&&(e.set(n,r,!e.get(n,r)),e.set(r,n,!e.get(r,n)));return g(e)}t.decode=_}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(7),i=n(8),a;(function(e){e.Numeric=`numeric`,e.Alphanumeric=`alphanumeric`,e.Byte=`byte`,e.Kanji=`kanji`,e.ECI=`eci`})(a=t.Mode||={});var o;(function(e){e[e.Terminator=0]=`Terminator`,e[e.Numeric=1]=`Numeric`,e[e.Alphanumeric=2]=`Alphanumeric`,e[e.Byte=4]=`Byte`,e[e.Kanji=8]=`Kanji`,e[e.ECI=7]=`ECI`})(o||={});function s(e,t){for(var n=[],r=``,i=[10,12,14][t],a=e.readBits(i);a>=3;){var o=e.readBits(10);if(o>=1e3)throw Error(`Invalid numeric value above 999`);var s=Math.floor(o/100),c=Math.floor(o/10)%10,l=o%10;n.push(48+s,48+c,48+l),r+=s.toString()+c.toString()+l.toString(),a-=3}if(a===2){var o=e.readBits(7);if(o>=100)throw Error(`Invalid numeric value above 99`);var s=Math.floor(o/10),c=o%10;n.push(48+s,48+c),r+=s.toString()+c.toString()}else if(a===1){var o=e.readBits(4);if(o>=10)throw Error(`Invalid numeric value above 9`);n.push(48+o),r+=o.toString()}return{bytes:n,text:r}}var c=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`.split(``);function l(e,t){for(var n=[],r=``,i=[9,11,13][t],a=e.readBits(i);a>=2;){var o=e.readBits(11),s=Math.floor(o/45),l=o%45;n.push(c[s].charCodeAt(0),c[l].charCodeAt(0)),r+=c[s]+c[l],a-=2}if(a===1){var s=e.readBits(6);n.push(c[s].charCodeAt(0)),r+=c[s]}return{bytes:n,text:r}}function u(e,t){for(var n=[],r=``,i=[8,16,16][t],a=e.readBits(i),o=0;o<a;o++){var s=e.readBits(8);n.push(s)}try{r+=decodeURIComponent(n.map(function(e){return`%`+(`0`+e.toString(16)).substr(-2)}).join(``))}catch{}return{bytes:n,text:r}}function d(e,t){for(var n=[],r=``,a=[8,10,12][t],o=e.readBits(a),s=0;s<o;s++){var c=e.readBits(13),l=Math.floor(c/192)<<8|c%192;l<7936?l+=33088:l+=49472,n.push(l>>8,l&255),r+=String.fromCharCode(i.shiftJISTable[l])}return{bytes:n,text:r}}function f(e,t){for(var n,i,c,f,p=new r.BitStream(e),m=t<=9?0:t<=26?1:2,h={text:``,bytes:[],chunks:[],version:t};p.available()>=4;){var g=p.readBits(4);if(g===o.Terminator)return h;if(g===o.ECI)p.readBits(1)===0?h.chunks.push({type:a.ECI,assignmentNumber:p.readBits(7)}):p.readBits(1)===0?h.chunks.push({type:a.ECI,assignmentNumber:p.readBits(14)}):p.readBits(1)===0?h.chunks.push({type:a.ECI,assignmentNumber:p.readBits(21)}):h.chunks.push({type:a.ECI,assignmentNumber:-1});else if(g===o.Numeric){var _=s(p,m);h.text+=_.text,(n=h.bytes).push.apply(n,_.bytes),h.chunks.push({type:a.Numeric,text:_.text})}else if(g===o.Alphanumeric){var v=l(p,m);h.text+=v.text,(i=h.bytes).push.apply(i,v.bytes),h.chunks.push({type:a.Alphanumeric,text:v.text})}else if(g===o.Byte){var y=u(p,m);h.text+=y.text,(c=h.bytes).push.apply(c,y.bytes),h.chunks.push({type:a.Byte,bytes:y.bytes,text:y.text})}else if(g===o.Kanji){var b=d(p,m);h.text+=b.text,(f=h.bytes).push.apply(f,b.bytes),h.chunks.push({type:a.Kanji,bytes:b.bytes,text:b.text})}}if(p.available()===0||p.readBits(p.available())===0)return h}t.decode=f}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.BitStream=function(){function e(e){this.byteOffset=0,this.bitOffset=0,this.bytes=e}return e.prototype.readBits=function(e){if(e<1||e>32||e>this.available())throw Error(`Cannot read `+e.toString()+` bits`);var t=0;if(this.bitOffset>0){var n=8-this.bitOffset,r=e<n?e:n,i=n-r,a=255>>8-r<<i;t=(this.bytes[this.byteOffset]&a)>>i,e-=r,this.bitOffset+=r,this.bitOffset===8&&(this.bitOffset=0,this.byteOffset++)}if(e>0){for(;e>=8;)t=t<<8|this.bytes[this.byteOffset]&255,this.byteOffset++,e-=8;if(e>0){var i=8-e,a=255>>i<<i;t=t<<e|(this.bytes[this.byteOffset]&a)>>i,this.bitOffset+=e}}return t},e.prototype.available=function(){return 8*(this.bytes.length-this.byteOffset)-this.bitOffset},e}()}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.shiftJISTable={32:32,33:33,34:34,35:35,36:36,37:37,38:38,39:39,40:40,41:41,42:42,43:43,44:44,45:45,46:46,47:47,48:48,49:49,50:50,51:51,52:52,53:53,54:54,55:55,56:56,57:57,58:58,59:59,60:60,61:61,62:62,63:63,64:64,65:65,66:66,67:67,68:68,69:69,70:70,71:71,72:72,73:73,74:74,75:75,76:76,77:77,78:78,79:79,80:80,81:81,82:82,83:83,84:84,85:85,86:86,87:87,88:88,89:89,90:90,91:91,92:165,93:93,94:94,95:95,96:96,97:97,98:98,99:99,100:100,101:101,102:102,103:103,104:104,105:105,106:106,107:107,108:108,109:109,110:110,111:111,112:112,113:113,114:114,115:115,116:116,117:117,118:118,119:119,120:120,121:121,122:122,123:123,124:124,125:125,126:8254,33088:12288,33089:12289,33090:12290,33091:65292,33092:65294,33093:12539,33094:65306,33095:65307,33096:65311,33097:65281,33098:12443,33099:12444,33100:180,33101:65344,33102:168,33103:65342,33104:65507,33105:65343,33106:12541,33107:12542,33108:12445,33109:12446,33110:12291,33111:20189,33112:12293,33113:12294,33114:12295,33115:12540,33116:8213,33117:8208,33118:65295,33119:92,33120:12316,33121:8214,33122:65372,33123:8230,33124:8229,33125:8216,33126:8217,33127:8220,33128:8221,33129:65288,33130:65289,33131:12308,33132:12309,33133:65339,33134:65341,33135:65371,33136:65373,33137:12296,33138:12297,33139:12298,33140:12299,33141:12300,33142:12301,33143:12302,33144:12303,33145:12304,33146:12305,33147:65291,33148:8722,33149:177,33150:215,33152:247,33153:65309,33154:8800,33155:65308,33156:65310,33157:8806,33158:8807,33159:8734,33160:8756,33161:9794,33162:9792,33163:176,33164:8242,33165:8243,33166:8451,33167:65509,33168:65284,33169:162,33170:163,33171:65285,33172:65283,33173:65286,33174:65290,33175:65312,33176:167,33177:9734,33178:9733,33179:9675,33180:9679,33181:9678,33182:9671,33183:9670,33184:9633,33185:9632,33186:9651,33187:9650,33188:9661,33189:9660,33190:8251,33191:12306,33192:8594,33193:8592,33194:8593,33195:8595,33196:12307,33208:8712,33209:8715,33210:8838,33211:8839,33212:8834,33213:8835,33214:8746,33215:8745,33224:8743,33225:8744,33226:172,33227:8658,33228:8660,33229:8704,33230:8707,33242:8736,33243:8869,33244:8978,33245:8706,33246:8711,33247:8801,33248:8786,33249:8810,33250:8811,33251:8730,33252:8765,33253:8733,33254:8757,33255:8747,33256:8748,33264:8491,33265:8240,33266:9839,33267:9837,33268:9834,33269:8224,33270:8225,33271:182,33276:9711,33359:65296,33360:65297,33361:65298,33362:65299,33363:65300,33364:65301,33365:65302,33366:65303,33367:65304,33368:65305,33376:65313,33377:65314,33378:65315,33379:65316,33380:65317,33381:65318,33382:65319,33383:65320,33384:65321,33385:65322,33386:65323,33387:65324,33388:65325,33389:65326,33390:65327,33391:65328,33392:65329,33393:65330,33394:65331,33395:65332,33396:65333,33397:65334,33398:65335,33399:65336,33400:65337,33401:65338,33409:65345,33410:65346,33411:65347,33412:65348,33413:65349,33414:65350,33415:65351,33416:65352,33417:65353,33418:65354,33419:65355,33420:65356,33421:65357,33422:65358,33423:65359,33424:65360,33425:65361,33426:65362,33427:65363,33428:65364,33429:65365,33430:65366,33431:65367,33432:65368,33433:65369,33434:65370,33439:12353,33440:12354,33441:12355,33442:12356,33443:12357,33444:12358,33445:12359,33446:12360,33447:12361,33448:12362,33449:12363,33450:12364,33451:12365,33452:12366,33453:12367,33454:12368,33455:12369,33456:12370,33457:12371,33458:12372,33459:12373,33460:12374,33461:12375,33462:12376,33463:12377,33464:12378,33465:12379,33466:12380,33467:12381,33468:12382,33469:12383,33470:12384,33471:12385,33472:12386,33473:12387,33474:12388,33475:12389,33476:12390,33477:12391,33478:12392,33479:12393,33480:12394,33481:12395,33482:12396,33483:12397,33484:12398,33485:12399,33486:12400,33487:12401,33488:12402,33489:12403,33490:12404,33491:12405,33492:12406,33493:12407,33494:12408,33495:12409,33496:12410,33497:12411,33498:12412,33499:12413,33500:12414,33501:12415,33502:12416,33503:12417,33504:12418,33505:12419,33506:12420,33507:12421,33508:12422,33509:12423,33510:12424,33511:12425,33512:12426,33513:12427,33514:12428,33515:12429,33516:12430,33517:12431,33518:12432,33519:12433,33520:12434,33521:12435,33600:12449,33601:12450,33602:12451,33603:12452,33604:12453,33605:12454,33606:12455,33607:12456,33608:12457,33609:12458,33610:12459,33611:12460,33612:12461,33613:12462,33614:12463,33615:12464,33616:12465,33617:12466,33618:12467,33619:12468,33620:12469,33621:12470,33622:12471,33623:12472,33624:12473,33625:12474,33626:12475,33627:12476,33628:12477,33629:12478,33630:12479,33631:12480,33632:12481,33633:12482,33634:12483,33635:12484,33636:12485,33637:12486,33638:12487,33639:12488,33640:12489,33641:12490,33642:12491,33643:12492,33644:12493,33645:12494,33646:12495,33647:12496,33648:12497,33649:12498,33650:12499,33651:12500,33652:12501,33653:12502,33654:12503,33655:12504,33656:12505,33657:12506,33658:12507,33659:12508,33660:12509,33661:12510,33662:12511,33664:12512,33665:12513,33666:12514,33667:12515,33668:12516,33669:12517,33670:12518,33671:12519,33672:12520,33673:12521,33674:12522,33675:12523,33676:12524,33677:12525,33678:12526,33679:12527,33680:12528,33681:12529,33682:12530,33683:12531,33684:12532,33685:12533,33686:12534,33695:913,33696:914,33697:915,33698:916,33699:917,33700:918,33701:919,33702:920,33703:921,33704:922,33705:923,33706:924,33707:925,33708:926,33709:927,33710:928,33711:929,33712:931,33713:932,33714:933,33715:934,33716:935,33717:936,33718:937,33727:945,33728:946,33729:947,33730:948,33731:949,33732:950,33733:951,33734:952,33735:953,33736:954,33737:955,33738:956,33739:957,33740:958,33741:959,33742:960,33743:961,33744:963,33745:964,33746:965,33747:966,33748:967,33749:968,33750:969,33856:1040,33857:1041,33858:1042,33859:1043,33860:1044,33861:1045,33862:1025,33863:1046,33864:1047,33865:1048,33866:1049,33867:1050,33868:1051,33869:1052,33870:1053,33871:1054,33872:1055,33873:1056,33874:1057,33875:1058,33876:1059,33877:1060,33878:1061,33879:1062,33880:1063,33881:1064,33882:1065,33883:1066,33884:1067,33885:1068,33886:1069,33887:1070,33888:1071,33904:1072,33905:1073,33906:1074,33907:1075,33908:1076,33909:1077,33910:1105,33911:1078,33912:1079,33913:1080,33914:1081,33915:1082,33916:1083,33917:1084,33918:1085,33920:1086,33921:1087,33922:1088,33923:1089,33924:1090,33925:1091,33926:1092,33927:1093,33928:1094,33929:1095,33930:1096,33931:1097,33932:1098,33933:1099,33934:1100,33935:1101,33936:1102,33937:1103,33951:9472,33952:9474,33953:9484,33954:9488,33955:9496,33956:9492,33957:9500,33958:9516,33959:9508,33960:9524,33961:9532,33962:9473,33963:9475,33964:9487,33965:9491,33966:9499,33967:9495,33968:9507,33969:9523,33970:9515,33971:9531,33972:9547,33973:9504,33974:9519,33975:9512,33976:9527,33977:9535,33978:9501,33979:9520,33980:9509,33981:9528,33982:9538,34975:20124,34976:21782,34977:23043,34978:38463,34979:21696,34980:24859,34981:25384,34982:23030,34983:36898,34984:33909,34985:33564,34986:31312,34987:24746,34988:25569,34989:28197,34990:26093,34991:33894,34992:33446,34993:39925,34994:26771,34995:22311,34996:26017,34997:25201,34998:23451,34999:22992,35e3:34427,35001:39156,35002:32098,35003:32190,35004:39822,35005:25110,35006:31903,35007:34999,35008:23433,35009:24245,35010:25353,35011:26263,35012:26696,35013:38343,35014:38797,35015:26447,35016:20197,35017:20234,35018:20301,35019:20381,35020:20553,35021:22258,35022:22839,35023:22996,35024:23041,35025:23561,35026:24799,35027:24847,35028:24944,35029:26131,35030:26885,35031:28858,35032:30031,35033:30064,35034:31227,35035:32173,35036:32239,35037:32963,35038:33806,35039:34915,35040:35586,35041:36949,35042:36986,35043:21307,35044:20117,35045:20133,35046:22495,35047:32946,35048:37057,35049:30959,35050:19968,35051:22769,35052:28322,35053:36920,35054:31282,35055:33576,35056:33419,35057:39983,35058:20801,35059:21360,35060:21693,35061:21729,35062:22240,35063:23035,35064:24341,35065:39154,35066:28139,35067:32996,35068:34093,35136:38498,35137:38512,35138:38560,35139:38907,35140:21515,35141:21491,35142:23431,35143:28879,35144:32701,35145:36802,35146:38632,35147:21359,35148:40284,35149:31418,35150:19985,35151:30867,35152:33276,35153:28198,35154:22040,35155:21764,35156:27421,35157:34074,35158:39995,35159:23013,35160:21417,35161:28006,35162:29916,35163:38287,35164:22082,35165:20113,35166:36939,35167:38642,35168:33615,35169:39180,35170:21473,35171:21942,35172:23344,35173:24433,35174:26144,35175:26355,35176:26628,35177:27704,35178:27891,35179:27945,35180:29787,35181:30408,35182:31310,35183:38964,35184:33521,35185:34907,35186:35424,35187:37613,35188:28082,35189:30123,35190:30410,35191:39365,35192:24742,35193:35585,35194:36234,35195:38322,35196:27022,35197:21421,35198:20870,35200:22290,35201:22576,35202:22852,35203:23476,35204:24310,35205:24616,35206:25513,35207:25588,35208:27839,35209:28436,35210:28814,35211:28948,35212:29017,35213:29141,35214:29503,35215:32257,35216:33398,35217:33489,35218:34199,35219:36960,35220:37467,35221:40219,35222:22633,35223:26044,35224:27738,35225:29989,35226:20985,35227:22830,35228:22885,35229:24448,35230:24540,35231:25276,35232:26106,35233:27178,35234:27431,35235:27572,35236:29579,35237:32705,35238:35158,35239:40236,35240:40206,35241:40644,35242:23713,35243:27798,35244:33659,35245:20740,35246:23627,35247:25014,35248:33222,35249:26742,35250:29281,35251:20057,35252:20474,35253:21368,35254:24681,35255:28201,35256:31311,35257:38899,35258:19979,35259:21270,35260:20206,35261:20309,35262:20285,35263:20385,35264:20339,35265:21152,35266:21487,35267:22025,35268:22799,35269:23233,35270:23478,35271:23521,35272:31185,35273:26247,35274:26524,35275:26550,35276:27468,35277:27827,35278:28779,35279:29634,35280:31117,35281:31166,35282:31292,35283:31623,35284:33457,35285:33499,35286:33540,35287:33655,35288:33775,35289:33747,35290:34662,35291:35506,35292:22057,35293:36008,35294:36838,35295:36942,35296:38686,35297:34442,35298:20420,35299:23784,35300:25105,35301:29273,35302:30011,35303:33253,35304:33469,35305:34558,35306:36032,35307:38597,35308:39187,35309:39381,35310:20171,35311:20250,35312:35299,35313:22238,35314:22602,35315:22730,35316:24315,35317:24555,35318:24618,35319:24724,35320:24674,35321:25040,35322:25106,35323:25296,35324:25913,35392:39745,35393:26214,35394:26800,35395:28023,35396:28784,35397:30028,35398:30342,35399:32117,35400:33445,35401:34809,35402:38283,35403:38542,35404:35997,35405:20977,35406:21182,35407:22806,35408:21683,35409:23475,35410:23830,35411:24936,35412:27010,35413:28079,35414:30861,35415:33995,35416:34903,35417:35442,35418:37799,35419:39608,35420:28012,35421:39336,35422:34521,35423:22435,35424:26623,35425:34510,35426:37390,35427:21123,35428:22151,35429:21508,35430:24275,35431:25313,35432:25785,35433:26684,35434:26680,35435:27579,35436:29554,35437:30906,35438:31339,35439:35226,35440:35282,35441:36203,35442:36611,35443:37101,35444:38307,35445:38548,35446:38761,35447:23398,35448:23731,35449:27005,35450:38989,35451:38990,35452:25499,35453:31520,35454:27179,35456:27263,35457:26806,35458:39949,35459:28511,35460:21106,35461:21917,35462:24688,35463:25324,35464:27963,35465:28167,35466:28369,35467:33883,35468:35088,35469:36676,35470:19988,35471:39993,35472:21494,35473:26907,35474:27194,35475:38788,35476:26666,35477:20828,35478:31427,35479:33970,35480:37340,35481:37772,35482:22107,35483:40232,35484:26658,35485:33541,35486:33841,35487:31909,35488:21e3,35489:33477,35490:29926,35491:20094,35492:20355,35493:20896,35494:23506,35495:21002,35496:21208,35497:21223,35498:24059,35499:21914,35500:22570,35501:23014,35502:23436,35503:23448,35504:23515,35505:24178,35506:24185,35507:24739,35508:24863,35509:24931,35510:25022,35511:25563,35512:25954,35513:26577,35514:26707,35515:26874,35516:27454,35517:27475,35518:27735,35519:28450,35520:28567,35521:28485,35522:29872,35523:29976,35524:30435,35525:30475,35526:31487,35527:31649,35528:31777,35529:32233,35530:32566,35531:32752,35532:32925,35533:33382,35534:33694,35535:35251,35536:35532,35537:36011,35538:36996,35539:37969,35540:38291,35541:38289,35542:38306,35543:38501,35544:38867,35545:39208,35546:33304,35547:20024,35548:21547,35549:23736,35550:24012,35551:29609,35552:30284,35553:30524,35554:23721,35555:32747,35556:36107,35557:38593,35558:38929,35559:38996,35560:39e3,35561:20225,35562:20238,35563:21361,35564:21916,35565:22120,35566:22522,35567:22855,35568:23305,35569:23492,35570:23696,35571:24076,35572:24190,35573:24524,35574:25582,35575:26426,35576:26071,35577:26082,35578:26399,35579:26827,35580:26820,35648:27231,35649:24112,35650:27589,35651:27671,35652:27773,35653:30079,35654:31048,35655:23395,35656:31232,35657:32e3,35658:24509,35659:35215,35660:35352,35661:36020,35662:36215,35663:36556,35664:36637,35665:39138,35666:39438,35667:39740,35668:20096,35669:20605,35670:20736,35671:22931,35672:23452,35673:25135,35674:25216,35675:25836,35676:27450,35677:29344,35678:30097,35679:31047,35680:32681,35681:34811,35682:35516,35683:35696,35684:25516,35685:33738,35686:38816,35687:21513,35688:21507,35689:21931,35690:26708,35691:27224,35692:35440,35693:30759,35694:26485,35695:40653,35696:21364,35697:23458,35698:33050,35699:34384,35700:36870,35701:19992,35702:20037,35703:20167,35704:20241,35705:21450,35706:21560,35707:23470,35708:24339,35709:24613,35710:25937,35712:26429,35713:27714,35714:27762,35715:27875,35716:28792,35717:29699,35718:31350,35719:31406,35720:31496,35721:32026,35722:31998,35723:32102,35724:26087,35725:29275,35726:21435,35727:23621,35728:24040,35729:25298,35730:25312,35731:25369,35732:28192,35733:34394,35734:35377,35735:36317,35736:37624,35737:28417,35738:31142,35739:39770,35740:20136,35741:20139,35742:20140,35743:20379,35744:20384,35745:20689,35746:20807,35747:31478,35748:20849,35749:20982,35750:21332,35751:21281,35752:21375,35753:21483,35754:21932,35755:22659,35756:23777,35757:24375,35758:24394,35759:24623,35760:24656,35761:24685,35762:25375,35763:25945,35764:27211,35765:27841,35766:29378,35767:29421,35768:30703,35769:33016,35770:33029,35771:33288,35772:34126,35773:37111,35774:37857,35775:38911,35776:39255,35777:39514,35778:20208,35779:20957,35780:23597,35781:26241,35782:26989,35783:23616,35784:26354,35785:26997,35786:29577,35787:26704,35788:31873,35789:20677,35790:21220,35791:22343,35792:24062,35793:37670,35794:26020,35795:27427,35796:27453,35797:29748,35798:31105,35799:31165,35800:31563,35801:32202,35802:33465,35803:33740,35804:34943,35805:35167,35806:35641,35807:36817,35808:37329,35809:21535,35810:37504,35811:20061,35812:20534,35813:21477,35814:21306,35815:29399,35816:29590,35817:30697,35818:33510,35819:36527,35820:39366,35821:39368,35822:39378,35823:20855,35824:24858,35825:34398,35826:21936,35827:31354,35828:20598,35829:23507,35830:36935,35831:38533,35832:20018,35833:27355,35834:37351,35835:23633,35836:23624,35904:25496,35905:31391,35906:27795,35907:38772,35908:36705,35909:31402,35910:29066,35911:38536,35912:31874,35913:26647,35914:32368,35915:26705,35916:37740,35917:21234,35918:21531,35919:34219,35920:35347,35921:32676,35922:36557,35923:37089,35924:21350,35925:34952,35926:31041,35927:20418,35928:20670,35929:21009,35930:20804,35931:21843,35932:22317,35933:29674,35934:22411,35935:22865,35936:24418,35937:24452,35938:24693,35939:24950,35940:24935,35941:25001,35942:25522,35943:25658,35944:25964,35945:26223,35946:26690,35947:28179,35948:30054,35949:31293,35950:31995,35951:32076,35952:32153,35953:32331,35954:32619,35955:33550,35956:33610,35957:34509,35958:35336,35959:35427,35960:35686,35961:36605,35962:38938,35963:40335,35964:33464,35965:36814,35966:39912,35968:21127,35969:25119,35970:25731,35971:28608,35972:38553,35973:26689,35974:20625,35975:27424,35976:27770,35977:28500,35978:31348,35979:32080,35980:34880,35981:35363,35982:26376,35983:20214,35984:20537,35985:20518,35986:20581,35987:20860,35988:21048,35989:21091,35990:21927,35991:22287,35992:22533,35993:23244,35994:24314,35995:25010,35996:25080,35997:25331,35998:25458,35999:26908,36e3:27177,36001:29309,36002:29356,36003:29486,36004:30740,36005:30831,36006:32121,36007:30476,36008:32937,36009:35211,36010:35609,36011:36066,36012:36562,36013:36963,36014:37749,36015:38522,36016:38997,36017:39443,36018:40568,36019:20803,36020:21407,36021:21427,36022:24187,36023:24358,36024:28187,36025:28304,36026:29572,36027:29694,36028:32067,36029:33335,36030:35328,36031:35578,36032:38480,36033:20046,36034:20491,36035:21476,36036:21628,36037:22266,36038:22993,36039:23396,36040:24049,36041:24235,36042:24359,36043:25144,36044:25925,36045:26543,36046:28246,36047:29392,36048:31946,36049:34996,36050:32929,36051:32993,36052:33776,36053:34382,36054:35463,36055:36328,36056:37431,36057:38599,36058:39015,36059:40723,36060:20116,36061:20114,36062:20237,36063:21320,36064:21577,36065:21566,36066:23087,36067:24460,36068:24481,36069:24735,36070:26791,36071:27278,36072:29786,36073:30849,36074:35486,36075:35492,36076:35703,36077:37264,36078:20062,36079:39881,36080:20132,36081:20348,36082:20399,36083:20505,36084:20502,36085:20809,36086:20844,36087:21151,36088:21177,36089:21246,36090:21402,36091:21475,36092:21521,36160:21518,36161:21897,36162:22353,36163:22434,36164:22909,36165:23380,36166:23389,36167:23439,36168:24037,36169:24039,36170:24055,36171:24184,36172:24195,36173:24218,36174:24247,36175:24344,36176:24658,36177:24908,36178:25239,36179:25304,36180:25511,36181:25915,36182:26114,36183:26179,36184:26356,36185:26477,36186:26657,36187:26775,36188:27083,36189:27743,36190:27946,36191:28009,36192:28207,36193:28317,36194:30002,36195:30343,36196:30828,36197:31295,36198:31968,36199:32005,36200:32024,36201:32094,36202:32177,36203:32789,36204:32771,36205:32943,36206:32945,36207:33108,36208:33167,36209:33322,36210:33618,36211:34892,36212:34913,36213:35611,36214:36002,36215:36092,36216:37066,36217:37237,36218:37489,36219:30783,36220:37628,36221:38308,36222:38477,36224:38917,36225:39321,36226:39640,36227:40251,36228:21083,36229:21163,36230:21495,36231:21512,36232:22741,36233:25335,36234:28640,36235:35946,36236:36703,36237:40633,36238:20811,36239:21051,36240:21578,36241:22269,36242:31296,36243:37239,36244:40288,36245:40658,36246:29508,36247:28425,36248:33136,36249:29969,36250:24573,36251:24794,36252:39592,36253:29403,36254:36796,36255:27492,36256:38915,36257:20170,36258:22256,36259:22372,36260:22718,36261:23130,36262:24680,36263:25031,36264:26127,36265:26118,36266:26681,36267:26801,36268:28151,36269:30165,36270:32058,36271:33390,36272:39746,36273:20123,36274:20304,36275:21449,36276:21766,36277:23919,36278:24038,36279:24046,36280:26619,36281:27801,36282:29811,36283:30722,36284:35408,36285:37782,36286:35039,36287:22352,36288:24231,36289:25387,36290:20661,36291:20652,36292:20877,36293:26368,36294:21705,36295:22622,36296:22971,36297:23472,36298:24425,36299:25165,36300:25505,36301:26685,36302:27507,36303:28168,36304:28797,36305:37319,36306:29312,36307:30741,36308:30758,36309:31085,36310:25998,36311:32048,36312:33756,36313:35009,36314:36617,36315:38555,36316:21092,36317:22312,36318:26448,36319:32618,36320:36001,36321:20916,36322:22338,36323:38442,36324:22586,36325:27018,36326:32948,36327:21682,36328:23822,36329:22524,36330:30869,36331:40442,36332:20316,36333:21066,36334:21643,36335:25662,36336:26152,36337:26388,36338:26613,36339:31364,36340:31574,36341:32034,36342:37679,36343:26716,36344:39853,36345:31545,36346:21273,36347:20874,36348:21047,36416:23519,36417:25334,36418:25774,36419:25830,36420:26413,36421:27578,36422:34217,36423:38609,36424:30352,36425:39894,36426:25420,36427:37638,36428:39851,36429:30399,36430:26194,36431:19977,36432:20632,36433:21442,36434:23665,36435:24808,36436:25746,36437:25955,36438:26719,36439:29158,36440:29642,36441:29987,36442:31639,36443:32386,36444:34453,36445:35715,36446:36059,36447:37240,36448:39184,36449:26028,36450:26283,36451:27531,36452:20181,36453:20180,36454:20282,36455:20351,36456:21050,36457:21496,36458:21490,36459:21987,36460:22235,36461:22763,36462:22987,36463:22985,36464:23039,36465:23376,36466:23629,36467:24066,36468:24107,36469:24535,36470:24605,36471:25351,36472:25903,36473:23388,36474:26031,36475:26045,36476:26088,36477:26525,36478:27490,36480:27515,36481:27663,36482:29509,36483:31049,36484:31169,36485:31992,36486:32025,36487:32043,36488:32930,36489:33026,36490:33267,36491:35222,36492:35422,36493:35433,36494:35430,36495:35468,36496:35566,36497:36039,36498:36060,36499:38604,36500:39164,36501:27503,36502:20107,36503:20284,36504:20365,36505:20816,36506:23383,36507:23546,36508:24904,36509:25345,36510:26178,36511:27425,36512:28363,36513:27835,36514:29246,36515:29885,36516:30164,36517:30913,36518:31034,36519:32780,36520:32819,36521:33258,36522:33940,36523:36766,36524:27728,36525:40575,36526:24335,36527:35672,36528:40235,36529:31482,36530:36600,36531:23437,36532:38635,36533:19971,36534:21489,36535:22519,36536:22833,36537:23241,36538:23460,36539:24713,36540:28287,36541:28422,36542:30142,36543:36074,36544:23455,36545:34048,36546:31712,36547:20594,36548:26612,36549:33437,36550:23649,36551:34122,36552:32286,36553:33294,36554:20889,36555:23556,36556:25448,36557:36198,36558:26012,36559:29038,36560:31038,36561:32023,36562:32773,36563:35613,36564:36554,36565:36974,36566:34503,36567:37034,36568:20511,36569:21242,36570:23610,36571:26451,36572:28796,36573:29237,36574:37196,36575:37320,36576:37675,36577:33509,36578:23490,36579:24369,36580:24825,36581:20027,36582:21462,36583:23432,36584:25163,36585:26417,36586:27530,36587:29417,36588:29664,36589:31278,36590:33131,36591:36259,36592:37202,36593:39318,36594:20754,36595:21463,36596:21610,36597:23551,36598:25480,36599:27193,36600:32172,36601:38656,36602:22234,36603:21454,36604:21608,36672:23447,36673:23601,36674:24030,36675:20462,36676:24833,36677:25342,36678:27954,36679:31168,36680:31179,36681:32066,36682:32333,36683:32722,36684:33261,36685:33311,36686:33936,36687:34886,36688:35186,36689:35728,36690:36468,36691:36655,36692:36913,36693:37195,36694:37228,36695:38598,36696:37276,36697:20160,36698:20303,36699:20805,36700:21313,36701:24467,36702:25102,36703:26580,36704:27713,36705:28171,36706:29539,36707:32294,36708:37325,36709:37507,36710:21460,36711:22809,36712:23487,36713:28113,36714:31069,36715:32302,36716:31899,36717:22654,36718:29087,36719:20986,36720:34899,36721:36848,36722:20426,36723:23803,36724:26149,36725:30636,36726:31459,36727:33308,36728:39423,36729:20934,36730:24490,36731:26092,36732:26991,36733:27529,36734:28147,36736:28310,36737:28516,36738:30462,36739:32020,36740:24033,36741:36981,36742:37255,36743:38918,36744:20966,36745:21021,36746:25152,36747:26257,36748:26329,36749:28186,36750:24246,36751:32210,36752:32626,36753:26360,36754:34223,36755:34295,36756:35576,36757:21161,36758:21465,36759:22899,36760:24207,36761:24464,36762:24661,36763:37604,36764:38500,36765:20663,36766:20767,36767:21213,36768:21280,36769:21319,36770:21484,36771:21736,36772:21830,36773:21809,36774:22039,36775:22888,36776:22974,36777:23100,36778:23477,36779:23558,36780:23567,36781:23569,36782:23578,36783:24196,36784:24202,36785:24288,36786:24432,36787:25215,36788:25220,36789:25307,36790:25484,36791:25463,36792:26119,36793:26124,36794:26157,36795:26230,36796:26494,36797:26786,36798:27167,36799:27189,36800:27836,36801:28040,36802:28169,36803:28248,36804:28988,36805:28966,36806:29031,36807:30151,36808:30465,36809:30813,36810:30977,36811:31077,36812:31216,36813:31456,36814:31505,36815:31911,36816:32057,36817:32918,36818:33750,36819:33931,36820:34121,36821:34909,36822:35059,36823:35359,36824:35388,36825:35412,36826:35443,36827:35937,36828:36062,36829:37284,36830:37478,36831:37758,36832:37912,36833:38556,36834:38808,36835:19978,36836:19976,36837:19998,36838:20055,36839:20887,36840:21104,36841:22478,36842:22580,36843:22732,36844:23330,36845:24120,36846:24773,36847:25854,36848:26465,36849:26454,36850:27972,36851:29366,36852:30067,36853:31331,36854:33976,36855:35698,36856:37304,36857:37664,36858:22065,36859:22516,36860:39166,36928:25325,36929:26893,36930:27542,36931:29165,36932:32340,36933:32887,36934:33394,36935:35302,36936:39135,36937:34645,36938:36785,36939:23611,36940:20280,36941:20449,36942:20405,36943:21767,36944:23072,36945:23517,36946:23529,36947:24515,36948:24910,36949:25391,36950:26032,36951:26187,36952:26862,36953:27035,36954:28024,36955:28145,36956:30003,36957:30137,36958:30495,36959:31070,36960:31206,36961:32051,36962:33251,36963:33455,36964:34218,36965:35242,36966:35386,36967:36523,36968:36763,36969:36914,36970:37341,36971:38663,36972:20154,36973:20161,36974:20995,36975:22645,36976:22764,36977:23563,36978:29978,36979:23613,36980:33102,36981:35338,36982:36805,36983:38499,36984:38765,36985:31525,36986:35535,36987:38920,36988:37218,36989:22259,36990:21416,36992:36887,36993:21561,36994:22402,36995:24101,36996:25512,36997:27700,36998:28810,36999:30561,37e3:31883,37001:32736,37002:34928,37003:36930,37004:37204,37005:37648,37006:37656,37007:38543,37008:29790,37009:39620,37010:23815,37011:23913,37012:25968,37013:26530,37014:36264,37015:38619,37016:25454,37017:26441,37018:26905,37019:33733,37020:38935,37021:38592,37022:35070,37023:28548,37024:25722,37025:23544,37026:19990,37027:28716,37028:30045,37029:26159,37030:20932,37031:21046,37032:21218,37033:22995,37034:24449,37035:24615,37036:25104,37037:25919,37038:25972,37039:26143,37040:26228,37041:26866,37042:26646,37043:27491,37044:28165,37045:29298,37046:29983,37047:30427,37048:31934,37049:32854,37050:22768,37051:35069,37052:35199,37053:35488,37054:35475,37055:35531,37056:36893,37057:37266,37058:38738,37059:38745,37060:25993,37061:31246,37062:33030,37063:38587,37064:24109,37065:24796,37066:25114,37067:26021,37068:26132,37069:26512,37070:30707,37071:31309,37072:31821,37073:32318,37074:33034,37075:36012,37076:36196,37077:36321,37078:36447,37079:30889,37080:20999,37081:25305,37082:25509,37083:25666,37084:25240,37085:35373,37086:31363,37087:31680,37088:35500,37089:38634,37090:32118,37091:33292,37092:34633,37093:20185,37094:20808,37095:21315,37096:21344,37097:23459,37098:23554,37099:23574,37100:24029,37101:25126,37102:25159,37103:25776,37104:26643,37105:26676,37106:27849,37107:27973,37108:27927,37109:26579,37110:28508,37111:29006,37112:29053,37113:26059,37114:31359,37115:31661,37116:32218,37184:32330,37185:32680,37186:33146,37187:33307,37188:33337,37189:34214,37190:35438,37191:36046,37192:36341,37193:36984,37194:36983,37195:37549,37196:37521,37197:38275,37198:39854,37199:21069,37200:21892,37201:28472,37202:28982,37203:20840,37204:31109,37205:32341,37206:33203,37207:31950,37208:22092,37209:22609,37210:23720,37211:25514,37212:26366,37213:26365,37214:26970,37215:29401,37216:30095,37217:30094,37218:30990,37219:31062,37220:31199,37221:31895,37222:32032,37223:32068,37224:34311,37225:35380,37226:38459,37227:36961,37228:40736,37229:20711,37230:21109,37231:21452,37232:21474,37233:20489,37234:21930,37235:22766,37236:22863,37237:29245,37238:23435,37239:23652,37240:21277,37241:24803,37242:24819,37243:25436,37244:25475,37245:25407,37246:25531,37248:25805,37249:26089,37250:26361,37251:24035,37252:27085,37253:27133,37254:28437,37255:29157,37256:20105,37257:30185,37258:30456,37259:31379,37260:31967,37261:32207,37262:32156,37263:32865,37264:33609,37265:33624,37266:33900,37267:33980,37268:34299,37269:35013,37270:36208,37271:36865,37272:36973,37273:37783,37274:38684,37275:39442,37276:20687,37277:22679,37278:24974,37279:33235,37280:34101,37281:36104,37282:36896,37283:20419,37284:20596,37285:21063,37286:21363,37287:24687,37288:25417,37289:26463,37290:28204,37291:36275,37292:36895,37293:20439,37294:23646,37295:36042,37296:26063,37297:32154,37298:21330,37299:34966,37300:20854,37301:25539,37302:23384,37303:23403,37304:23562,37305:25613,37306:26449,37307:36956,37308:20182,37309:22810,37310:22826,37311:27760,37312:35409,37313:21822,37314:22549,37315:22949,37316:24816,37317:25171,37318:26561,37319:33333,37320:26965,37321:38464,37322:39364,37323:39464,37324:20307,37325:22534,37326:23550,37327:32784,37328:23729,37329:24111,37330:24453,37331:24608,37332:24907,37333:25140,37334:26367,37335:27888,37336:28382,37337:32974,37338:33151,37339:33492,37340:34955,37341:36024,37342:36864,37343:36910,37344:38538,37345:40667,37346:39899,37347:20195,37348:21488,37349:22823,37350:31532,37351:37261,37352:38988,37353:40441,37354:28381,37355:28711,37356:21331,37357:21828,37358:23429,37359:25176,37360:25246,37361:25299,37362:27810,37363:28655,37364:29730,37365:35351,37366:37944,37367:28609,37368:35582,37369:33592,37370:20967,37371:34552,37372:21482,37440:21481,37441:20294,37442:36948,37443:36784,37444:22890,37445:33073,37446:24061,37447:31466,37448:36799,37449:26842,37450:35895,37451:29432,37452:40008,37453:27197,37454:35504,37455:20025,37456:21336,37457:22022,37458:22374,37459:25285,37460:25506,37461:26086,37462:27470,37463:28129,37464:28251,37465:28845,37466:30701,37467:31471,37468:31658,37469:32187,37470:32829,37471:32966,37472:34507,37473:35477,37474:37723,37475:22243,37476:22727,37477:24382,37478:26029,37479:26262,37480:27264,37481:27573,37482:30007,37483:35527,37484:20516,37485:30693,37486:22320,37487:24347,37488:24677,37489:26234,37490:27744,37491:30196,37492:31258,37493:32622,37494:33268,37495:34584,37496:36933,37497:39347,37498:31689,37499:30044,37500:31481,37501:31569,37502:33988,37504:36880,37505:31209,37506:31378,37507:33590,37508:23265,37509:30528,37510:20013,37511:20210,37512:23449,37513:24544,37514:25277,37515:26172,37516:26609,37517:27880,37518:34411,37519:34935,37520:35387,37521:37198,37522:37619,37523:39376,37524:27159,37525:28710,37526:29482,37527:33511,37528:33879,37529:36015,37530:19969,37531:20806,37532:20939,37533:21899,37534:23541,37535:24086,37536:24115,37537:24193,37538:24340,37539:24373,37540:24427,37541:24500,37542:25074,37543:25361,37544:26274,37545:26397,37546:28526,37547:29266,37548:30010,37549:30522,37550:32884,37551:33081,37552:33144,37553:34678,37554:35519,37555:35548,37556:36229,37557:36339,37558:37530,37559:38263,37560:38914,37561:40165,37562:21189,37563:25431,37564:30452,37565:26389,37566:27784,37567:29645,37568:36035,37569:37806,37570:38515,37571:27941,37572:22684,37573:26894,37574:27084,37575:36861,37576:37786,37577:30171,37578:36890,37579:22618,37580:26626,37581:25524,37582:27131,37583:20291,37584:28460,37585:26584,37586:36795,37587:34086,37588:32180,37589:37716,37590:26943,37591:28528,37592:22378,37593:22775,37594:23340,37595:32044,37596:29226,37597:21514,37598:37347,37599:40372,37600:20141,37601:20302,37602:20572,37603:20597,37604:21059,37605:35998,37606:21576,37607:22564,37608:23450,37609:24093,37610:24213,37611:24237,37612:24311,37613:24351,37614:24716,37615:25269,37616:25402,37617:25552,37618:26799,37619:27712,37620:30855,37621:31118,37622:31243,37623:32224,37624:33351,37625:35330,37626:35558,37627:36420,37628:36883,37696:37048,37697:37165,37698:37336,37699:40718,37700:27877,37701:25688,37702:25826,37703:25973,37704:28404,37705:30340,37706:31515,37707:36969,37708:37841,37709:28346,37710:21746,37711:24505,37712:25764,37713:36685,37714:36845,37715:37444,37716:20856,37717:22635,37718:22825,37719:23637,37720:24215,37721:28155,37722:32399,37723:29980,37724:36028,37725:36578,37726:39003,37727:28857,37728:20253,37729:27583,37730:28593,37731:3e4,37732:38651,37733:20814,37734:21520,37735:22581,37736:22615,37737:22956,37738:23648,37739:24466,37740:26007,37741:26460,37742:28193,37743:30331,37744:33759,37745:36077,37746:36884,37747:37117,37748:37709,37749:30757,37750:30778,37751:21162,37752:24230,37753:22303,37754:22900,37755:24594,37756:20498,37757:20826,37758:20908,37760:20941,37761:20992,37762:21776,37763:22612,37764:22616,37765:22871,37766:23445,37767:23798,37768:23947,37769:24764,37770:25237,37771:25645,37772:26481,37773:26691,37774:26812,37775:26847,37776:30423,37777:28120,37778:28271,37779:28059,37780:28783,37781:29128,37782:24403,37783:30168,37784:31095,37785:31561,37786:31572,37787:31570,37788:31958,37789:32113,37790:21040,37791:33891,37792:34153,37793:34276,37794:35342,37795:35588,37796:35910,37797:36367,37798:36867,37799:36879,37800:37913,37801:38518,37802:38957,37803:39472,37804:38360,37805:20685,37806:21205,37807:21516,37808:22530,37809:23566,37810:24999,37811:25758,37812:27934,37813:30643,37814:31461,37815:33012,37816:33796,37817:36947,37818:37509,37819:23776,37820:40199,37821:21311,37822:24471,37823:24499,37824:28060,37825:29305,37826:30563,37827:31167,37828:31716,37829:27602,37830:29420,37831:35501,37832:26627,37833:27233,37834:20984,37835:31361,37836:26932,37837:23626,37838:40182,37839:33515,37840:23493,37841:37193,37842:28702,37843:22136,37844:23663,37845:24775,37846:25958,37847:27788,37848:35930,37849:36929,37850:38931,37851:21585,37852:26311,37853:37389,37854:22856,37855:37027,37856:20869,37857:20045,37858:20970,37859:34201,37860:35598,37861:28760,37862:25466,37863:37707,37864:26978,37865:39348,37866:32260,37867:30071,37868:21335,37869:26976,37870:36575,37871:38627,37872:27741,37873:20108,37874:23612,37875:24336,37876:36841,37877:21250,37878:36049,37879:32905,37880:34425,37881:24319,37882:26085,37883:20083,37884:20837,37952:22914,37953:23615,37954:38894,37955:20219,37956:22922,37957:24525,37958:35469,37959:28641,37960:31152,37961:31074,37962:23527,37963:33905,37964:29483,37965:29105,37966:24180,37967:24565,37968:25467,37969:25754,37970:29123,37971:31896,37972:20035,37973:24316,37974:20043,37975:22492,37976:22178,37977:24745,37978:28611,37979:32013,37980:33021,37981:33075,37982:33215,37983:36786,37984:35223,37985:34468,37986:24052,37987:25226,37988:25773,37989:35207,37990:26487,37991:27874,37992:27966,37993:29750,37994:30772,37995:23110,37996:32629,37997:33453,37998:39340,37999:20467,38e3:24259,38001:25309,38002:25490,38003:25943,38004:26479,38005:30403,38006:29260,38007:32972,38008:32954,38009:36649,38010:37197,38011:20493,38012:22521,38013:23186,38014:26757,38016:26995,38017:29028,38018:29437,38019:36023,38020:22770,38021:36064,38022:38506,38023:36889,38024:34687,38025:31204,38026:30695,38027:33833,38028:20271,38029:21093,38030:21338,38031:25293,38032:26575,38033:27850,38034:30333,38035:31636,38036:31893,38037:33334,38038:34180,38039:36843,38040:26333,38041:28448,38042:29190,38043:32283,38044:33707,38045:39361,38046:40614,38047:20989,38048:31665,38049:30834,38050:31672,38051:32903,38052:31560,38053:27368,38054:24161,38055:32908,38056:30033,38057:30048,38058:20843,38059:37474,38060:28300,38061:30330,38062:37271,38063:39658,38064:20240,38065:32624,38066:25244,38067:31567,38068:38309,38069:40169,38070:22138,38071:22617,38072:34532,38073:38588,38074:20276,38075:21028,38076:21322,38077:21453,38078:21467,38079:24070,38080:25644,38081:26001,38082:26495,38083:27710,38084:27726,38085:29256,38086:29359,38087:29677,38088:30036,38089:32321,38090:33324,38091:34281,38092:36009,38093:31684,38094:37318,38095:29033,38096:38930,38097:39151,38098:25405,38099:26217,38100:30058,38101:30436,38102:30928,38103:34115,38104:34542,38105:21290,38106:21329,38107:21542,38108:22915,38109:24199,38110:24444,38111:24754,38112:25161,38113:25209,38114:25259,38115:26e3,38116:27604,38117:27852,38118:30130,38119:30382,38120:30865,38121:31192,38122:32203,38123:32631,38124:32933,38125:34987,38126:35513,38127:36027,38128:36991,38129:38750,38130:39131,38131:27147,38132:31800,38133:20633,38134:23614,38135:24494,38136:26503,38137:27608,38138:29749,38139:30473,38140:32654,38208:40763,38209:26570,38210:31255,38211:21305,38212:30091,38213:39661,38214:24422,38215:33181,38216:33777,38217:32920,38218:24380,38219:24517,38220:30050,38221:31558,38222:36924,38223:26727,38224:23019,38225:23195,38226:32016,38227:30334,38228:35628,38229:20469,38230:24426,38231:27161,38232:27703,38233:28418,38234:29922,38235:31080,38236:34920,38237:35413,38238:35961,38239:24287,38240:25551,38241:30149,38242:31186,38243:33495,38244:37672,38245:37618,38246:33948,38247:34541,38248:39981,38249:21697,38250:24428,38251:25996,38252:27996,38253:28693,38254:36007,38255:36051,38256:38971,38257:25935,38258:29942,38259:19981,38260:20184,38261:22496,38262:22827,38263:23142,38264:23500,38265:20904,38266:24067,38267:24220,38268:24598,38269:25206,38270:25975,38272:26023,38273:26222,38274:28014,38275:29238,38276:31526,38277:33104,38278:33178,38279:33433,38280:35676,38281:36e3,38282:36070,38283:36212,38284:38428,38285:38468,38286:20398,38287:25771,38288:27494,38289:33310,38290:33889,38291:34154,38292:37096,38293:23553,38294:26963,38295:39080,38296:33914,38297:34135,38298:20239,38299:21103,38300:24489,38301:24133,38302:26381,38303:31119,38304:33145,38305:35079,38306:35206,38307:28149,38308:24343,38309:25173,38310:27832,38311:20175,38312:29289,38313:39826,38314:20998,38315:21563,38316:22132,38317:22707,38318:24996,38319:25198,38320:28954,38321:22894,38322:31881,38323:31966,38324:32027,38325:38640,38326:25991,38327:32862,38328:19993,38329:20341,38330:20853,38331:22592,38332:24163,38333:24179,38334:24330,38335:26564,38336:20006,38337:34109,38338:38281,38339:38491,38340:31859,38341:38913,38342:20731,38343:22721,38344:30294,38345:30887,38346:21029,38347:30629,38348:34065,38349:31622,38350:20559,38351:22793,38352:29255,38353:31687,38354:32232,38355:36794,38356:36820,38357:36941,38358:20415,38359:21193,38360:23081,38361:24321,38362:38829,38363:20445,38364:33303,38365:37610,38366:22275,38367:25429,38368:27497,38369:29995,38370:35036,38371:36628,38372:31298,38373:21215,38374:22675,38375:24917,38376:25098,38377:26286,38378:27597,38379:31807,38380:33769,38381:20515,38382:20472,38383:21253,38384:21574,38385:22577,38386:22857,38387:23453,38388:23792,38389:23791,38390:23849,38391:24214,38392:25265,38393:25447,38394:25918,38395:26041,38396:26379,38464:27861,38465:27873,38466:28921,38467:30770,38468:32299,38469:32990,38470:33459,38471:33804,38472:34028,38473:34562,38474:35090,38475:35370,38476:35914,38477:37030,38478:37586,38479:39165,38480:40179,38481:40300,38482:20047,38483:20129,38484:20621,38485:21078,38486:22346,38487:22952,38488:24125,38489:24536,38490:24537,38491:25151,38492:26292,38493:26395,38494:26576,38495:26834,38496:20882,38497:32033,38498:32938,38499:33192,38500:35584,38501:35980,38502:36031,38503:37502,38504:38450,38505:21536,38506:38956,38507:21271,38508:20693,38509:21340,38510:22696,38511:25778,38512:26420,38513:29287,38514:30566,38515:31302,38516:37350,38517:21187,38518:27809,38519:27526,38520:22528,38521:24140,38522:22868,38523:26412,38524:32763,38525:20961,38526:30406,38528:25705,38529:30952,38530:39764,38531:40635,38532:22475,38533:22969,38534:26151,38535:26522,38536:27598,38537:21737,38538:27097,38539:24149,38540:33180,38541:26517,38542:39850,38543:26622,38544:40018,38545:26717,38546:20134,38547:20451,38548:21448,38549:25273,38550:26411,38551:27819,38552:36804,38553:20397,38554:32365,38555:40639,38556:19975,38557:24930,38558:28288,38559:28459,38560:34067,38561:21619,38562:26410,38563:39749,38564:24051,38565:31637,38566:23724,38567:23494,38568:34588,38569:28234,38570:34001,38571:31252,38572:33032,38573:22937,38574:31885,38575:27665,38576:30496,38577:21209,38578:22818,38579:28961,38580:29279,38581:30683,38582:38695,38583:40289,38584:26891,38585:23167,38586:23064,38587:20901,38588:21517,38589:21629,38590:26126,38591:30431,38592:36855,38593:37528,38594:40180,38595:23018,38596:29277,38597:28357,38598:20813,38599:26825,38600:32191,38601:32236,38602:38754,38603:40634,38604:25720,38605:27169,38606:33538,38607:22916,38608:23391,38609:27611,38610:29467,38611:30450,38612:32178,38613:32791,38614:33945,38615:20786,38616:26408,38617:40665,38618:30446,38619:26466,38620:21247,38621:39173,38622:23588,38623:25147,38624:31870,38625:36016,38626:21839,38627:24758,38628:32011,38629:38272,38630:21249,38631:20063,38632:20918,38633:22812,38634:29242,38635:32822,38636:37326,38637:24357,38638:30690,38639:21380,38640:24441,38641:32004,38642:34220,38643:35379,38644:36493,38645:38742,38646:26611,38647:34222,38648:37971,38649:24841,38650:24840,38651:27833,38652:30290,38720:35565,38721:36664,38722:21807,38723:20305,38724:20778,38725:21191,38726:21451,38727:23461,38728:24189,38729:24736,38730:24962,38731:25558,38732:26377,38733:26586,38734:28263,38735:28044,38736:29494,38737:29495,38738:30001,38739:31056,38740:35029,38741:35480,38742:36938,38743:37009,38744:37109,38745:38596,38746:34701,38747:22805,38748:20104,38749:20313,38750:19982,38751:35465,38752:36671,38753:38928,38754:20653,38755:24188,38756:22934,38757:23481,38758:24248,38759:25562,38760:25594,38761:25793,38762:26332,38763:26954,38764:27096,38765:27915,38766:28342,38767:29076,38768:29992,38769:31407,38770:32650,38771:32768,38772:33865,38773:33993,38774:35201,38775:35617,38776:36362,38777:36965,38778:38525,38779:39178,38780:24958,38781:25233,38782:27442,38784:27779,38785:28020,38786:32716,38787:32764,38788:28096,38789:32645,38790:34746,38791:35064,38792:26469,38793:33713,38794:38972,38795:38647,38796:27931,38797:32097,38798:33853,38799:37226,38800:20081,38801:21365,38802:23888,38803:27396,38804:28651,38805:34253,38806:34349,38807:35239,38808:21033,38809:21519,38810:23653,38811:26446,38812:26792,38813:29702,38814:29827,38815:30178,38816:35023,38817:35041,38818:37324,38819:38626,38820:38520,38821:24459,38822:29575,38823:31435,38824:33870,38825:25504,38826:30053,38827:21129,38828:27969,38829:28316,38830:29705,38831:30041,38832:30827,38833:31890,38834:38534,38835:31452,38836:40845,38837:20406,38838:24942,38839:26053,38840:34396,38841:20102,38842:20142,38843:20698,38844:20001,38845:20940,38846:23534,38847:26009,38848:26753,38849:28092,38850:29471,38851:30274,38852:30637,38853:31260,38854:31975,38855:33391,38856:35538,38857:36988,38858:37327,38859:38517,38860:38936,38861:21147,38862:32209,38863:20523,38864:21400,38865:26519,38866:28107,38867:29136,38868:29747,38869:33256,38870:36650,38871:38563,38872:40023,38873:40607,38874:29792,38875:22593,38876:28057,38877:32047,38878:39006,38879:20196,38880:20278,38881:20363,38882:20919,38883:21169,38884:23994,38885:24604,38886:29618,38887:31036,38888:33491,38889:37428,38890:38583,38891:38646,38892:38666,38893:40599,38894:40802,38895:26278,38896:27508,38897:21015,38898:21155,38899:28872,38900:35010,38901:24265,38902:24651,38903:24976,38904:28451,38905:29001,38906:31806,38907:32244,38908:32879,38976:34030,38977:36899,38978:37676,38979:21570,38980:39791,38981:27347,38982:28809,38983:36034,38984:36335,38985:38706,38986:21172,38987:23105,38988:24266,38989:24324,38990:26391,38991:27004,38992:27028,38993:28010,38994:28431,38995:29282,38996:29436,38997:31725,38998:32769,38999:32894,39e3:34635,39001:37070,39002:20845,39003:40595,39004:31108,39005:32907,39006:37682,39007:35542,39008:20525,39009:21644,39010:35441,39011:27498,39012:36036,39013:33031,39014:24785,39015:26528,39016:40434,39017:20121,39018:20120,39019:39952,39020:35435,39021:34241,39022:34152,39023:26880,39024:28286,39025:30871,39026:33109,39071:24332,39072:19984,39073:19989,39074:20010,39075:20017,39076:20022,39077:20028,39078:20031,39079:20034,39080:20054,39081:20056,39082:20098,39083:20101,39084:35947,39085:20106,39086:33298,39087:24333,39088:20110,39089:20126,39090:20127,39091:20128,39092:20130,39093:20144,39094:20147,39095:20150,39096:20174,39097:20173,39098:20164,39099:20166,39100:20162,39101:20183,39102:20190,39103:20205,39104:20191,39105:20215,39106:20233,39107:20314,39108:20272,39109:20315,39110:20317,39111:20311,39112:20295,39113:20342,39114:20360,39115:20367,39116:20376,39117:20347,39118:20329,39119:20336,39120:20369,39121:20335,39122:20358,39123:20374,39124:20760,39125:20436,39126:20447,39127:20430,39128:20440,39129:20443,39130:20433,39131:20442,39132:20432,39133:20452,39134:20453,39135:20506,39136:20520,39137:20500,39138:20522,39139:20517,39140:20485,39141:20252,39142:20470,39143:20513,39144:20521,39145:20524,39146:20478,39147:20463,39148:20497,39149:20486,39150:20547,39151:20551,39152:26371,39153:20565,39154:20560,39155:20552,39156:20570,39157:20566,39158:20588,39159:20600,39160:20608,39161:20634,39162:20613,39163:20660,39164:20658,39232:20681,39233:20682,39234:20659,39235:20674,39236:20694,39237:20702,39238:20709,39239:20717,39240:20707,39241:20718,39242:20729,39243:20725,39244:20745,39245:20737,39246:20738,39247:20758,39248:20757,39249:20756,39250:20762,39251:20769,39252:20794,39253:20791,39254:20796,39255:20795,39256:20799,39257:20800,39258:20818,39259:20812,39260:20820,39261:20834,39262:31480,39263:20841,39264:20842,39265:20846,39266:20864,39267:20866,39268:22232,39269:20876,39270:20873,39271:20879,39272:20881,39273:20883,39274:20885,39275:20886,39276:20900,39277:20902,39278:20898,39279:20905,39280:20906,39281:20907,39282:20915,39283:20913,39284:20914,39285:20912,39286:20917,39287:20925,39288:20933,39289:20937,39290:20955,39291:20960,39292:34389,39293:20969,39294:20973,39296:20976,39297:20981,39298:20990,39299:20996,39300:21003,39301:21012,39302:21006,39303:21031,39304:21034,39305:21038,39306:21043,39307:21049,39308:21071,39309:21060,39310:21067,39311:21068,39312:21086,39313:21076,39314:21098,39315:21108,39316:21097,39317:21107,39318:21119,39319:21117,39320:21133,39321:21140,39322:21138,39323:21105,39324:21128,39325:21137,39326:36776,39327:36775,39328:21164,39329:21165,39330:21180,39331:21173,39332:21185,39333:21197,39334:21207,39335:21214,39336:21219,39337:21222,39338:39149,39339:21216,39340:21235,39341:21237,39342:21240,39343:21241,39344:21254,39345:21256,39346:30008,39347:21261,39348:21264,39349:21263,39350:21269,39351:21274,39352:21283,39353:21295,39354:21297,39355:21299,39356:21304,39357:21312,39358:21318,39359:21317,39360:19991,39361:21321,39362:21325,39363:20950,39364:21342,39365:21353,39366:21358,39367:22808,39368:21371,39369:21367,39370:21378,39371:21398,39372:21408,39373:21414,39374:21413,39375:21422,39376:21424,39377:21430,39378:21443,39379:31762,39380:38617,39381:21471,39382:26364,39383:29166,39384:21486,39385:21480,39386:21485,39387:21498,39388:21505,39389:21565,39390:21568,39391:21548,39392:21549,39393:21564,39394:21550,39395:21558,39396:21545,39397:21533,39398:21582,39399:21647,39400:21621,39401:21646,39402:21599,39403:21617,39404:21623,39405:21616,39406:21650,39407:21627,39408:21632,39409:21622,39410:21636,39411:21648,39412:21638,39413:21703,39414:21666,39415:21688,39416:21669,39417:21676,39418:21700,39419:21704,39420:21672,39488:21675,39489:21698,39490:21668,39491:21694,39492:21692,39493:21720,39494:21733,39495:21734,39496:21775,39497:21780,39498:21757,39499:21742,39500:21741,39501:21754,39502:21730,39503:21817,39504:21824,39505:21859,39506:21836,39507:21806,39508:21852,39509:21829,39510:21846,39511:21847,39512:21816,39513:21811,39514:21853,39515:21913,39516:21888,39517:21679,39518:21898,39519:21919,39520:21883,39521:21886,39522:21912,39523:21918,39524:21934,39525:21884,39526:21891,39527:21929,39528:21895,39529:21928,39530:21978,39531:21957,39532:21983,39533:21956,39534:21980,39535:21988,39536:21972,39537:22036,39538:22007,39539:22038,39540:22014,39541:22013,39542:22043,39543:22009,39544:22094,39545:22096,39546:29151,39547:22068,39548:22070,39549:22066,39550:22072,39552:22123,39553:22116,39554:22063,39555:22124,39556:22122,39557:22150,39558:22144,39559:22154,39560:22176,39561:22164,39562:22159,39563:22181,39564:22190,39565:22198,39566:22196,39567:22210,39568:22204,39569:22209,39570:22211,39571:22208,39572:22216,39573:22222,39574:22225,39575:22227,39576:22231,39577:22254,39578:22265,39579:22272,39580:22271,39581:22276,39582:22281,39583:22280,39584:22283,39585:22285,39586:22291,39587:22296,39588:22294,39589:21959,39590:22300,39591:22310,39592:22327,39593:22328,39594:22350,39595:22331,39596:22336,39597:22351,39598:22377,39599:22464,39600:22408,39601:22369,39602:22399,39603:22409,39604:22419,39605:22432,39606:22451,39607:22436,39608:22442,39609:22448,39610:22467,39611:22470,39612:22484,39613:22482,39614:22483,39615:22538,39616:22486,39617:22499,39618:22539,39619:22553,39620:22557,39621:22642,39622:22561,39623:22626,39624:22603,39625:22640,39626:27584,39627:22610,39628:22589,39629:22649,39630:22661,39631:22713,39632:22687,39633:22699,39634:22714,39635:22750,39636:22715,39637:22712,39638:22702,39639:22725,39640:22739,39641:22737,39642:22743,39643:22745,39644:22744,39645:22757,39646:22748,39647:22756,39648:22751,39649:22767,39650:22778,39651:22777,39652:22779,39653:22780,39654:22781,39655:22786,39656:22794,39657:22800,39658:22811,39659:26790,39660:22821,39661:22828,39662:22829,39663:22834,39664:22840,39665:22846,39666:31442,39667:22869,39668:22864,39669:22862,39670:22874,39671:22872,39672:22882,39673:22880,39674:22887,39675:22892,39676:22889,39744:22904,39745:22913,39746:22941,39747:20318,39748:20395,39749:22947,39750:22962,39751:22982,39752:23016,39753:23004,39754:22925,39755:23001,39756:23002,39757:23077,39758:23071,39759:23057,39760:23068,39761:23049,39762:23066,39763:23104,39764:23148,39765:23113,39766:23093,39767:23094,39768:23138,39769:23146,39770:23194,39771:23228,39772:23230,39773:23243,39774:23234,39775:23229,39776:23267,39777:23255,39778:23270,39779:23273,39780:23254,39781:23290,39782:23291,39783:23308,39784:23307,39785:23318,39786:23346,39787:23248,39788:23338,39789:23350,39790:23358,39791:23363,39792:23365,39793:23360,39794:23377,39795:23381,39796:23386,39797:23387,39798:23397,39799:23401,39800:23408,39801:23411,39802:23413,39803:23416,39804:25992,39805:23418,39806:23424,39808:23427,39809:23462,39810:23480,39811:23491,39812:23495,39813:23497,39814:23508,39815:23504,39816:23524,39817:23526,39818:23522,39819:23518,39820:23525,39821:23531,39822:23536,39823:23542,39824:23539,39825:23557,39826:23559,39827:23560,39828:23565,39829:23571,39830:23584,39831:23586,39832:23592,39833:23608,39834:23609,39835:23617,39836:23622,39837:23630,39838:23635,39839:23632,39840:23631,39841:23409,39842:23660,39843:23662,39844:20066,39845:23670,39846:23673,39847:23692,39848:23697,39849:23700,39850:22939,39851:23723,39852:23739,39853:23734,39854:23740,39855:23735,39856:23749,39857:23742,39858:23751,39859:23769,39860:23785,39861:23805,39862:23802,39863:23789,39864:23948,39865:23786,39866:23819,39867:23829,39868:23831,39869:23900,39870:23839,39871:23835,39872:23825,39873:23828,39874:23842,39875:23834,39876:23833,39877:23832,39878:23884,39879:23890,39880:23886,39881:23883,39882:23916,39883:23923,39884:23926,39885:23943,39886:23940,39887:23938,39888:23970,39889:23965,39890:23980,39891:23982,39892:23997,39893:23952,39894:23991,39895:23996,39896:24009,39897:24013,39898:24019,39899:24018,39900:24022,39901:24027,39902:24043,39903:24050,39904:24053,39905:24075,39906:24090,39907:24089,39908:24081,39909:24091,39910:24118,39911:24119,39912:24132,39913:24131,39914:24128,39915:24142,39916:24151,39917:24148,39918:24159,39919:24162,39920:24164,39921:24135,39922:24181,39923:24182,39924:24186,39925:40636,39926:24191,39927:24224,39928:24257,39929:24258,39930:24264,39931:24272,39932:24271,4e4:24278,40001:24291,40002:24285,40003:24282,40004:24283,40005:24290,40006:24289,40007:24296,40008:24297,40009:24300,40010:24305,40011:24307,40012:24304,40013:24308,40014:24312,40015:24318,40016:24323,40017:24329,40018:24413,40019:24412,40020:24331,40021:24337,40022:24342,40023:24361,40024:24365,40025:24376,40026:24385,40027:24392,40028:24396,40029:24398,40030:24367,40031:24401,40032:24406,40033:24407,40034:24409,40035:24417,40036:24429,40037:24435,40038:24439,40039:24451,40040:24450,40041:24447,40042:24458,40043:24456,40044:24465,40045:24455,40046:24478,40047:24473,40048:24472,40049:24480,40050:24488,40051:24493,40052:24508,40053:24534,40054:24571,40055:24548,40056:24568,40057:24561,40058:24541,40059:24755,40060:24575,40061:24609,40062:24672,40064:24601,40065:24592,40066:24617,40067:24590,40068:24625,40069:24603,40070:24597,40071:24619,40072:24614,40073:24591,40074:24634,40075:24666,40076:24641,40077:24682,40078:24695,40079:24671,40080:24650,40081:24646,40082:24653,40083:24675,40084:24643,40085:24676,40086:24642,40087:24684,40088:24683,40089:24665,40090:24705,40091:24717,40092:24807,40093:24707,40094:24730,40095:24708,40096:24731,40097:24726,40098:24727,40099:24722,40100:24743,40101:24715,40102:24801,40103:24760,40104:24800,40105:24787,40106:24756,40107:24560,40108:24765,40109:24774,40110:24757,40111:24792,40112:24909,40113:24853,40114:24838,40115:24822,40116:24823,40117:24832,40118:24820,40119:24826,40120:24835,40121:24865,40122:24827,40123:24817,40124:24845,40125:24846,40126:24903,40127:24894,40128:24872,40129:24871,40130:24906,40131:24895,40132:24892,40133:24876,40134:24884,40135:24893,40136:24898,40137:24900,40138:24947,40139:24951,40140:24920,40141:24921,40142:24922,40143:24939,40144:24948,40145:24943,40146:24933,40147:24945,40148:24927,40149:24925,40150:24915,40151:24949,40152:24985,40153:24982,40154:24967,40155:25004,40156:24980,40157:24986,40158:24970,40159:24977,40160:25003,40161:25006,40162:25036,40163:25034,40164:25033,40165:25079,40166:25032,40167:25027,40168:25030,40169:25018,40170:25035,40171:32633,40172:25037,40173:25062,40174:25059,40175:25078,40176:25082,40177:25076,40178:25087,40179:25085,40180:25084,40181:25086,40182:25088,40183:25096,40184:25097,40185:25101,40186:25100,40187:25108,40188:25115,40256:25118,40257:25121,40258:25130,40259:25134,40260:25136,40261:25138,40262:25139,40263:25153,40264:25166,40265:25182,40266:25187,40267:25179,40268:25184,40269:25192,40270:25212,40271:25218,40272:25225,40273:25214,40274:25234,40275:25235,40276:25238,40277:25300,40278:25219,40279:25236,40280:25303,40281:25297,40282:25275,40283:25295,40284:25343,40285:25286,40286:25812,40287:25288,40288:25308,40289:25292,40290:25290,40291:25282,40292:25287,40293:25243,40294:25289,40295:25356,40296:25326,40297:25329,40298:25383,40299:25346,40300:25352,40301:25327,40302:25333,40303:25424,40304:25406,40305:25421,40306:25628,40307:25423,40308:25494,40309:25486,40310:25472,40311:25515,40312:25462,40313:25507,40314:25487,40315:25481,40316:25503,40317:25525,40318:25451,40320:25449,40321:25534,40322:25577,40323:25536,40324:25542,40325:25571,40326:25545,40327:25554,40328:25590,40329:25540,40330:25622,40331:25652,40332:25606,40333:25619,40334:25638,40335:25654,40336:25885,40337:25623,40338:25640,40339:25615,40340:25703,40341:25711,40342:25718,40343:25678,40344:25898,40345:25749,40346:25747,40347:25765,40348:25769,40349:25736,40350:25788,40351:25818,40352:25810,40353:25797,40354:25799,40355:25787,40356:25816,40357:25794,40358:25841,40359:25831,40360:33289,40361:25824,40362:25825,40363:25260,40364:25827,40365:25839,40366:25900,40367:25846,40368:25844,40369:25842,40370:25850,40371:25856,40372:25853,40373:25880,40374:25884,40375:25861,40376:25892,40377:25891,40378:25899,40379:25908,40380:25909,40381:25911,40382:25910,40383:25912,40384:30027,40385:25928,40386:25942,40387:25941,40388:25933,40389:25944,40390:25950,40391:25949,40392:25970,40393:25976,40394:25986,40395:25987,40396:35722,40397:26011,40398:26015,40399:26027,40400:26039,40401:26051,40402:26054,40403:26049,40404:26052,40405:26060,40406:26066,40407:26075,40408:26073,40409:26080,40410:26081,40411:26097,40412:26482,40413:26122,40414:26115,40415:26107,40416:26483,40417:26165,40418:26166,40419:26164,40420:26140,40421:26191,40422:26180,40423:26185,40424:26177,40425:26206,40426:26205,40427:26212,40428:26215,40429:26216,40430:26207,40431:26210,40432:26224,40433:26243,40434:26248,40435:26254,40436:26249,40437:26244,40438:26264,40439:26269,40440:26305,40441:26297,40442:26313,40443:26302,40444:26300,40512:26308,40513:26296,40514:26326,40515:26330,40516:26336,40517:26175,40518:26342,40519:26345,40520:26352,40521:26357,40522:26359,40523:26383,40524:26390,40525:26398,40526:26406,40527:26407,40528:38712,40529:26414,40530:26431,40531:26422,40532:26433,40533:26424,40534:26423,40535:26438,40536:26462,40537:26464,40538:26457,40539:26467,40540:26468,40541:26505,40542:26480,40543:26537,40544:26492,40545:26474,40546:26508,40547:26507,40548:26534,40549:26529,40550:26501,40551:26551,40552:26607,40553:26548,40554:26604,40555:26547,40556:26601,40557:26552,40558:26596,40559:26590,40560:26589,40561:26594,40562:26606,40563:26553,40564:26574,40565:26566,40566:26599,40567:27292,40568:26654,40569:26694,40570:26665,40571:26688,40572:26701,40573:26674,40574:26702,40576:26803,40577:26667,40578:26713,40579:26723,40580:26743,40581:26751,40582:26783,40583:26767,40584:26797,40585:26772,40586:26781,40587:26779,40588:26755,40589:27310,40590:26809,40591:26740,40592:26805,40593:26784,40594:26810,40595:26895,40596:26765,40597:26750,40598:26881,40599:26826,40600:26888,40601:26840,40602:26914,40603:26918,40604:26849,40605:26892,40606:26829,40607:26836,40608:26855,40609:26837,40610:26934,40611:26898,40612:26884,40613:26839,40614:26851,40615:26917,40616:26873,40617:26848,40618:26863,40619:26920,40620:26922,40621:26906,40622:26915,40623:26913,40624:26822,40625:27001,40626:26999,40627:26972,40628:27e3,40629:26987,40630:26964,40631:27006,40632:26990,40633:26937,40634:26996,40635:26941,40636:26969,40637:26928,40638:26977,40639:26974,40640:26973,40641:27009,40642:26986,40643:27058,40644:27054,40645:27088,40646:27071,40647:27073,40648:27091,40649:27070,40650:27086,40651:23528,40652:27082,40653:27101,40654:27067,40655:27075,40656:27047,40657:27182,40658:27025,40659:27040,40660:27036,40661:27029,40662:27060,40663:27102,40664:27112,40665:27138,40666:27163,40667:27135,40668:27402,40669:27129,40670:27122,40671:27111,40672:27141,40673:27057,40674:27166,40675:27117,40676:27156,40677:27115,40678:27146,40679:27154,40680:27329,40681:27171,40682:27155,40683:27204,40684:27148,40685:27250,40686:27190,40687:27256,40688:27207,40689:27234,40690:27225,40691:27238,40692:27208,40693:27192,40694:27170,40695:27280,40696:27277,40697:27296,40698:27268,40699:27298,40700:27299,40768:27287,40769:34327,40770:27323,40771:27331,40772:27330,40773:27320,40774:27315,40775:27308,40776:27358,40777:27345,40778:27359,40779:27306,40780:27354,40781:27370,40782:27387,40783:27397,40784:34326,40785:27386,40786:27410,40787:27414,40788:39729,40789:27423,40790:27448,40791:27447,40792:30428,40793:27449,40794:39150,40795:27463,40796:27459,40797:27465,40798:27472,40799:27481,40800:27476,40801:27483,40802:27487,40803:27489,40804:27512,40805:27513,40806:27519,40807:27520,40808:27524,40809:27523,40810:27533,40811:27544,40812:27541,40813:27550,40814:27556,40815:27562,40816:27563,40817:27567,40818:27570,40819:27569,40820:27571,40821:27575,40822:27580,40823:27590,40824:27595,40825:27603,40826:27615,40827:27628,40828:27627,40829:27635,40830:27631,40832:40638,40833:27656,40834:27667,40835:27668,40836:27675,40837:27684,40838:27683,40839:27742,40840:27733,40841:27746,40842:27754,40843:27778,40844:27789,40845:27802,40846:27777,40847:27803,40848:27774,40849:27752,40850:27763,40851:27794,40852:27792,40853:27844,40854:27889,40855:27859,40856:27837,40857:27863,40858:27845,40859:27869,40860:27822,40861:27825,40862:27838,40863:27834,40864:27867,40865:27887,40866:27865,40867:27882,40868:27935,40869:34893,40870:27958,40871:27947,40872:27965,40873:27960,40874:27929,40875:27957,40876:27955,40877:27922,40878:27916,40879:28003,40880:28051,40881:28004,40882:27994,40883:28025,40884:27993,40885:28046,40886:28053,40887:28644,40888:28037,40889:28153,40890:28181,40891:28170,40892:28085,40893:28103,40894:28134,40895:28088,40896:28102,40897:28140,40898:28126,40899:28108,40900:28136,40901:28114,40902:28101,40903:28154,40904:28121,40905:28132,40906:28117,40907:28138,40908:28142,40909:28205,40910:28270,40911:28206,40912:28185,40913:28274,40914:28255,40915:28222,40916:28195,40917:28267,40918:28203,40919:28278,40920:28237,40921:28191,40922:28227,40923:28218,40924:28238,40925:28196,40926:28415,40927:28189,40928:28216,40929:28290,40930:28330,40931:28312,40932:28361,40933:28343,40934:28371,40935:28349,40936:28335,40937:28356,40938:28338,40939:28372,40940:28373,40941:28303,40942:28325,40943:28354,40944:28319,40945:28481,40946:28433,40947:28748,40948:28396,40949:28408,40950:28414,40951:28479,40952:28402,40953:28465,40954:28399,40955:28466,40956:28364,161:65377,162:65378,163:65379,164:65380,165:65381,166:65382,167:65383,168:65384,169:65385,170:65386,171:65387,172:65388,173:65389,174:65390,175:65391,176:65392,177:65393,178:65394,179:65395,180:65396,181:65397,182:65398,183:65399,184:65400,185:65401,186:65402,187:65403,188:65404,189:65405,190:65406,191:65407,192:65408,193:65409,194:65410,195:65411,196:65412,197:65413,198:65414,199:65415,200:65416,201:65417,202:65418,203:65419,204:65420,205:65421,206:65422,207:65423,208:65424,209:65425,210:65426,211:65427,212:65428,213:65429,214:65430,215:65431,216:65432,217:65433,218:65434,219:65435,220:65436,221:65437,222:65438,223:65439,57408:28478,57409:28435,57410:28407,57411:28550,57412:28538,57413:28536,57414:28545,57415:28544,57416:28527,57417:28507,57418:28659,57419:28525,57420:28546,57421:28540,57422:28504,57423:28558,57424:28561,57425:28610,57426:28518,57427:28595,57428:28579,57429:28577,57430:28580,57431:28601,57432:28614,57433:28586,57434:28639,57435:28629,57436:28652,57437:28628,57438:28632,57439:28657,57440:28654,57441:28635,57442:28681,57443:28683,57444:28666,57445:28689,57446:28673,57447:28687,57448:28670,57449:28699,57450:28698,57451:28532,57452:28701,57453:28696,57454:28703,57455:28720,57456:28734,57457:28722,57458:28753,57459:28771,57460:28825,57461:28818,57462:28847,57463:28913,57464:28844,57465:28856,57466:28851,57467:28846,57468:28895,57469:28875,57470:28893,57472:28889,57473:28937,57474:28925,57475:28956,57476:28953,57477:29029,57478:29013,57479:29064,57480:29030,57481:29026,57482:29004,57483:29014,57484:29036,57485:29071,57486:29179,57487:29060,57488:29077,57489:29096,57490:29100,57491:29143,57492:29113,57493:29118,57494:29138,57495:29129,57496:29140,57497:29134,57498:29152,57499:29164,57500:29159,57501:29173,57502:29180,57503:29177,57504:29183,57505:29197,57506:29200,57507:29211,57508:29224,57509:29229,57510:29228,57511:29232,57512:29234,57513:29243,57514:29244,57515:29247,57516:29248,57517:29254,57518:29259,57519:29272,57520:29300,57521:29310,57522:29314,57523:29313,57524:29319,57525:29330,57526:29334,57527:29346,57528:29351,57529:29369,57530:29362,57531:29379,57532:29382,57533:29380,57534:29390,57535:29394,57536:29410,57537:29408,57538:29409,57539:29433,57540:29431,57541:20495,57542:29463,57543:29450,57544:29468,57545:29462,57546:29469,57547:29492,57548:29487,57549:29481,57550:29477,57551:29502,57552:29518,57553:29519,57554:40664,57555:29527,57556:29546,57557:29544,57558:29552,57559:29560,57560:29557,57561:29563,57562:29562,57563:29640,57564:29619,57565:29646,57566:29627,57567:29632,57568:29669,57569:29678,57570:29662,57571:29858,57572:29701,57573:29807,57574:29733,57575:29688,57576:29746,57577:29754,57578:29781,57579:29759,57580:29791,57581:29785,57582:29761,57583:29788,57584:29801,57585:29808,57586:29795,57587:29802,57588:29814,57589:29822,57590:29835,57591:29854,57592:29863,57593:29898,57594:29903,57595:29908,57596:29681,57664:29920,57665:29923,57666:29927,57667:29929,57668:29934,57669:29938,57670:29936,57671:29937,57672:29944,57673:29943,57674:29956,57675:29955,57676:29957,57677:29964,57678:29966,57679:29965,57680:29973,57681:29971,57682:29982,57683:29990,57684:29996,57685:30012,57686:30020,57687:30029,57688:30026,57689:30025,57690:30043,57691:30022,57692:30042,57693:30057,57694:30052,57695:30055,57696:30059,57697:30061,57698:30072,57699:30070,57700:30086,57701:30087,57702:30068,57703:30090,57704:30089,57705:30082,57706:30100,57707:30106,57708:30109,57709:30117,57710:30115,57711:30146,57712:30131,57713:30147,57714:30133,57715:30141,57716:30136,57717:30140,57718:30129,57719:30157,57720:30154,57721:30162,57722:30169,57723:30179,57724:30174,57725:30206,57726:30207,57728:30204,57729:30209,57730:30192,57731:30202,57732:30194,57733:30195,57734:30219,57735:30221,57736:30217,57737:30239,57738:30247,57739:30240,57740:30241,57741:30242,57742:30244,57743:30260,57744:30256,57745:30267,57746:30279,57747:30280,57748:30278,57749:30300,57750:30296,57751:30305,57752:30306,57753:30312,57754:30313,57755:30314,57756:30311,57757:30316,57758:30320,57759:30322,57760:30326,57761:30328,57762:30332,57763:30336,57764:30339,57765:30344,57766:30347,57767:30350,57768:30358,57769:30355,57770:30361,57771:30362,57772:30384,57773:30388,57774:30392,57775:30393,57776:30394,57777:30402,57778:30413,57779:30422,57780:30418,57781:30430,57782:30433,57783:30437,57784:30439,57785:30442,57786:34351,57787:30459,57788:30472,57789:30471,57790:30468,57791:30505,57792:30500,57793:30494,57794:30501,57795:30502,57796:30491,57797:30519,57798:30520,57799:30535,57800:30554,57801:30568,57802:30571,57803:30555,57804:30565,57805:30591,57806:30590,57807:30585,57808:30606,57809:30603,57810:30609,57811:30624,57812:30622,57813:30640,57814:30646,57815:30649,57816:30655,57817:30652,57818:30653,57819:30651,57820:30663,57821:30669,57822:30679,57823:30682,57824:30684,57825:30691,57826:30702,57827:30716,57828:30732,57829:30738,57830:31014,57831:30752,57832:31018,57833:30789,57834:30862,57835:30836,57836:30854,57837:30844,57838:30874,57839:30860,57840:30883,57841:30901,57842:30890,57843:30895,57844:30929,57845:30918,57846:30923,57847:30932,57848:30910,57849:30908,57850:30917,57851:30922,57852:30956,57920:30951,57921:30938,57922:30973,57923:30964,57924:30983,57925:30994,57926:30993,57927:31001,57928:31020,57929:31019,57930:31040,57931:31072,57932:31063,57933:31071,57934:31066,57935:31061,57936:31059,57937:31098,57938:31103,57939:31114,57940:31133,57941:31143,57942:40779,57943:31146,57944:31150,57945:31155,57946:31161,57947:31162,57948:31177,57949:31189,57950:31207,57951:31212,57952:31201,57953:31203,57954:31240,57955:31245,57956:31256,57957:31257,57958:31264,57959:31263,57960:31104,57961:31281,57962:31291,57963:31294,57964:31287,57965:31299,57966:31319,57967:31305,57968:31329,57969:31330,57970:31337,57971:40861,57972:31344,57973:31353,57974:31357,57975:31368,57976:31383,57977:31381,57978:31384,57979:31382,57980:31401,57981:31432,57982:31408,57984:31414,57985:31429,57986:31428,57987:31423,57988:36995,57989:31431,57990:31434,57991:31437,57992:31439,57993:31445,57994:31443,57995:31449,57996:31450,57997:31453,57998:31457,57999:31458,58e3:31462,58001:31469,58002:31472,58003:31490,58004:31503,58005:31498,58006:31494,58007:31539,58008:31512,58009:31513,58010:31518,58011:31541,58012:31528,58013:31542,58014:31568,58015:31610,58016:31492,58017:31565,58018:31499,58019:31564,58020:31557,58021:31605,58022:31589,58023:31604,58024:31591,58025:31600,58026:31601,58027:31596,58028:31598,58029:31645,58030:31640,58031:31647,58032:31629,58033:31644,58034:31642,58035:31627,58036:31634,58037:31631,58038:31581,58039:31641,58040:31691,58041:31681,58042:31692,58043:31695,58044:31668,58045:31686,58046:31709,58047:31721,58048:31761,58049:31764,58050:31718,58051:31717,58052:31840,58053:31744,58054:31751,58055:31763,58056:31731,58057:31735,58058:31767,58059:31757,58060:31734,58061:31779,58062:31783,58063:31786,58064:31775,58065:31799,58066:31787,58067:31805,58068:31820,58069:31811,58070:31828,58071:31823,58072:31808,58073:31824,58074:31832,58075:31839,58076:31844,58077:31830,58078:31845,58079:31852,58080:31861,58081:31875,58082:31888,58083:31908,58084:31917,58085:31906,58086:31915,58087:31905,58088:31912,58089:31923,58090:31922,58091:31921,58092:31918,58093:31929,58094:31933,58095:31936,58096:31941,58097:31938,58098:31960,58099:31954,58100:31964,58101:31970,58102:39739,58103:31983,58104:31986,58105:31988,58106:31990,58107:31994,58108:32006,58176:32002,58177:32028,58178:32021,58179:32010,58180:32069,58181:32075,58182:32046,58183:32050,58184:32063,58185:32053,58186:32070,58187:32115,58188:32086,58189:32078,58190:32114,58191:32104,58192:32110,58193:32079,58194:32099,58195:32147,58196:32137,58197:32091,58198:32143,58199:32125,58200:32155,58201:32186,58202:32174,58203:32163,58204:32181,58205:32199,58206:32189,58207:32171,58208:32317,58209:32162,58210:32175,58211:32220,58212:32184,58213:32159,58214:32176,58215:32216,58216:32221,58217:32228,58218:32222,58219:32251,58220:32242,58221:32225,58222:32261,58223:32266,58224:32291,58225:32289,58226:32274,58227:32305,58228:32287,58229:32265,58230:32267,58231:32290,58232:32326,58233:32358,58234:32315,58235:32309,58236:32313,58237:32323,58238:32311,58240:32306,58241:32314,58242:32359,58243:32349,58244:32342,58245:32350,58246:32345,58247:32346,58248:32377,58249:32362,58250:32361,58251:32380,58252:32379,58253:32387,58254:32213,58255:32381,58256:36782,58257:32383,58258:32392,58259:32393,58260:32396,58261:32402,58262:32400,58263:32403,58264:32404,58265:32406,58266:32398,58267:32411,58268:32412,58269:32568,58270:32570,58271:32581,58272:32588,58273:32589,58274:32590,58275:32592,58276:32593,58277:32597,58278:32596,58279:32600,58280:32607,58281:32608,58282:32616,58283:32617,58284:32615,58285:32632,58286:32642,58287:32646,58288:32643,58289:32648,58290:32647,58291:32652,58292:32660,58293:32670,58294:32669,58295:32666,58296:32675,58297:32687,58298:32690,58299:32697,58300:32686,58301:32694,58302:32696,58303:35697,58304:32709,58305:32710,58306:32714,58307:32725,58308:32724,58309:32737,58310:32742,58311:32745,58312:32755,58313:32761,58314:39132,58315:32774,58316:32772,58317:32779,58318:32786,58319:32792,58320:32793,58321:32796,58322:32801,58323:32808,58324:32831,58325:32827,58326:32842,58327:32838,58328:32850,58329:32856,58330:32858,58331:32863,58332:32866,58333:32872,58334:32883,58335:32882,58336:32880,58337:32886,58338:32889,58339:32893,58340:32895,58341:32900,58342:32902,58343:32901,58344:32923,58345:32915,58346:32922,58347:32941,58348:20880,58349:32940,58350:32987,58351:32997,58352:32985,58353:32989,58354:32964,58355:32986,58356:32982,58357:33033,58358:33007,58359:33009,58360:33051,58361:33065,58362:33059,58363:33071,58364:33099,58432:38539,58433:33094,58434:33086,58435:33107,58436:33105,58437:33020,58438:33137,58439:33134,58440:33125,58441:33126,58442:33140,58443:33155,58444:33160,58445:33162,58446:33152,58447:33154,58448:33184,58449:33173,58450:33188,58451:33187,58452:33119,58453:33171,58454:33193,58455:33200,58456:33205,58457:33214,58458:33208,58459:33213,58460:33216,58461:33218,58462:33210,58463:33225,58464:33229,58465:33233,58466:33241,58467:33240,58468:33224,58469:33242,58470:33247,58471:33248,58472:33255,58473:33274,58474:33275,58475:33278,58476:33281,58477:33282,58478:33285,58479:33287,58480:33290,58481:33293,58482:33296,58483:33302,58484:33321,58485:33323,58486:33336,58487:33331,58488:33344,58489:33369,58490:33368,58491:33373,58492:33370,58493:33375,58494:33380,58496:33378,58497:33384,58498:33386,58499:33387,58500:33326,58501:33393,58502:33399,58503:33400,58504:33406,58505:33421,58506:33426,58507:33451,58508:33439,58509:33467,58510:33452,58511:33505,58512:33507,58513:33503,58514:33490,58515:33524,58516:33523,58517:33530,58518:33683,58519:33539,58520:33531,58521:33529,58522:33502,58523:33542,58524:33500,58525:33545,58526:33497,58527:33589,58528:33588,58529:33558,58530:33586,58531:33585,58532:33600,58533:33593,58534:33616,58535:33605,58536:33583,58537:33579,58538:33559,58539:33560,58540:33669,58541:33690,58542:33706,58543:33695,58544:33698,58545:33686,58546:33571,58547:33678,58548:33671,58549:33674,58550:33660,58551:33717,58552:33651,58553:33653,58554:33696,58555:33673,58556:33704,58557:33780,58558:33811,58559:33771,58560:33742,58561:33789,58562:33795,58563:33752,58564:33803,58565:33729,58566:33783,58567:33799,58568:33760,58569:33778,58570:33805,58571:33826,58572:33824,58573:33725,58574:33848,58575:34054,58576:33787,58577:33901,58578:33834,58579:33852,58580:34138,58581:33924,58582:33911,58583:33899,58584:33965,58585:33902,58586:33922,58587:33897,58588:33862,58589:33836,58590:33903,58591:33913,58592:33845,58593:33994,58594:33890,58595:33977,58596:33983,58597:33951,58598:34009,58599:33997,58600:33979,58601:34010,58602:34e3,58603:33985,58604:33990,58605:34006,58606:33953,58607:34081,58608:34047,58609:34036,58610:34071,58611:34072,58612:34092,58613:34079,58614:34069,58615:34068,58616:34044,58617:34112,58618:34147,58619:34136,58620:34120,58688:34113,58689:34306,58690:34123,58691:34133,58692:34176,58693:34212,58694:34184,58695:34193,58696:34186,58697:34216,58698:34157,58699:34196,58700:34203,58701:34282,58702:34183,58703:34204,58704:34167,58705:34174,58706:34192,58707:34249,58708:34234,58709:34255,58710:34233,58711:34256,58712:34261,58713:34269,58714:34277,58715:34268,58716:34297,58717:34314,58718:34323,58719:34315,58720:34302,58721:34298,58722:34310,58723:34338,58724:34330,58725:34352,58726:34367,58727:34381,58728:20053,58729:34388,58730:34399,58731:34407,58732:34417,58733:34451,58734:34467,58735:34473,58736:34474,58737:34443,58738:34444,58739:34486,58740:34479,58741:34500,58742:34502,58743:34480,58744:34505,58745:34851,58746:34475,58747:34516,58748:34526,58749:34537,58750:34540,58752:34527,58753:34523,58754:34543,58755:34578,58756:34566,58757:34568,58758:34560,58759:34563,58760:34555,58761:34577,58762:34569,58763:34573,58764:34553,58765:34570,58766:34612,58767:34623,58768:34615,58769:34619,58770:34597,58771:34601,58772:34586,58773:34656,58774:34655,58775:34680,58776:34636,58777:34638,58778:34676,58779:34647,58780:34664,58781:34670,58782:34649,58783:34643,58784:34659,58785:34666,58786:34821,58787:34722,58788:34719,58789:34690,58790:34735,58791:34763,58792:34749,58793:34752,58794:34768,58795:38614,58796:34731,58797:34756,58798:34739,58799:34759,58800:34758,58801:34747,58802:34799,58803:34802,58804:34784,58805:34831,58806:34829,58807:34814,58808:34806,58809:34807,58810:34830,58811:34770,58812:34833,58813:34838,58814:34837,58815:34850,58816:34849,58817:34865,58818:34870,58819:34873,58820:34855,58821:34875,58822:34884,58823:34882,58824:34898,58825:34905,58826:34910,58827:34914,58828:34923,58829:34945,58830:34942,58831:34974,58832:34933,58833:34941,58834:34997,58835:34930,58836:34946,58837:34967,58838:34962,58839:34990,58840:34969,58841:34978,58842:34957,58843:34980,58844:34992,58845:35007,58846:34993,58847:35011,58848:35012,58849:35028,58850:35032,58851:35033,58852:35037,58853:35065,58854:35074,58855:35068,58856:35060,58857:35048,58858:35058,58859:35076,58860:35084,58861:35082,58862:35091,58863:35139,58864:35102,58865:35109,58866:35114,58867:35115,58868:35137,58869:35140,58870:35131,58871:35126,58872:35128,58873:35148,58874:35101,58875:35168,58876:35166,58944:35174,58945:35172,58946:35181,58947:35178,58948:35183,58949:35188,58950:35191,58951:35198,58952:35203,58953:35208,58954:35210,58955:35219,58956:35224,58957:35233,58958:35241,58959:35238,58960:35244,58961:35247,58962:35250,58963:35258,58964:35261,58965:35263,58966:35264,58967:35290,58968:35292,58969:35293,58970:35303,58971:35316,58972:35320,58973:35331,58974:35350,58975:35344,58976:35340,58977:35355,58978:35357,58979:35365,58980:35382,58981:35393,58982:35419,58983:35410,58984:35398,58985:35400,58986:35452,58987:35437,58988:35436,58989:35426,58990:35461,58991:35458,58992:35460,58993:35496,58994:35489,58995:35473,58996:35493,58997:35494,58998:35482,58999:35491,59e3:35524,59001:35533,59002:35522,59003:35546,59004:35563,59005:35571,59006:35559,59008:35556,59009:35569,59010:35604,59011:35552,59012:35554,59013:35575,59014:35550,59015:35547,59016:35596,59017:35591,59018:35610,59019:35553,59020:35606,59021:35600,59022:35607,59023:35616,59024:35635,59025:38827,59026:35622,59027:35627,59028:35646,59029:35624,59030:35649,59031:35660,59032:35663,59033:35662,59034:35657,59035:35670,59036:35675,59037:35674,59038:35691,59039:35679,59040:35692,59041:35695,59042:35700,59043:35709,59044:35712,59045:35724,59046:35726,59047:35730,59048:35731,59049:35734,59050:35737,59051:35738,59052:35898,59053:35905,59054:35903,59055:35912,59056:35916,59057:35918,59058:35920,59059:35925,59060:35938,59061:35948,59062:35960,59063:35962,59064:35970,59065:35977,59066:35973,59067:35978,59068:35981,59069:35982,59070:35988,59071:35964,59072:35992,59073:25117,59074:36013,59075:36010,59076:36029,59077:36018,59078:36019,59079:36014,59080:36022,59081:36040,59082:36033,59083:36068,59084:36067,59085:36058,59086:36093,59087:36090,59088:36091,59089:36100,59090:36101,59091:36106,59092:36103,59093:36111,59094:36109,59095:36112,59096:40782,59097:36115,59098:36045,59099:36116,59100:36118,59101:36199,59102:36205,59103:36209,59104:36211,59105:36225,59106:36249,59107:36290,59108:36286,59109:36282,59110:36303,59111:36314,59112:36310,59113:36300,59114:36315,59115:36299,59116:36330,59117:36331,59118:36319,59119:36323,59120:36348,59121:36360,59122:36361,59123:36351,59124:36381,59125:36382,59126:36368,59127:36383,59128:36418,59129:36405,59130:36400,59131:36404,59132:36426,59200:36423,59201:36425,59202:36428,59203:36432,59204:36424,59205:36441,59206:36452,59207:36448,59208:36394,59209:36451,59210:36437,59211:36470,59212:36466,59213:36476,59214:36481,59215:36487,59216:36485,59217:36484,59218:36491,59219:36490,59220:36499,59221:36497,59222:36500,59223:36505,59224:36522,59225:36513,59226:36524,59227:36528,59228:36550,59229:36529,59230:36542,59231:36549,59232:36552,59233:36555,59234:36571,59235:36579,59236:36604,59237:36603,59238:36587,59239:36606,59240:36618,59241:36613,59242:36629,59243:36626,59244:36633,59245:36627,59246:36636,59247:36639,59248:36635,59249:36620,59250:36646,59251:36659,59252:36667,59253:36665,59254:36677,59255:36674,59256:36670,59257:36684,59258:36681,59259:36678,59260:36686,59261:36695,59262:36700,59264:36706,59265:36707,59266:36708,59267:36764,59268:36767,59269:36771,59270:36781,59271:36783,59272:36791,59273:36826,59274:36837,59275:36834,59276:36842,59277:36847,59278:36999,59279:36852,59280:36869,59281:36857,59282:36858,59283:36881,59284:36885,59285:36897,59286:36877,59287:36894,59288:36886,59289:36875,59290:36903,59291:36918,59292:36917,59293:36921,59294:36856,59295:36943,59296:36944,59297:36945,59298:36946,59299:36878,59300:36937,59301:36926,59302:36950,59303:36952,59304:36958,59305:36968,59306:36975,59307:36982,59308:38568,59309:36978,59310:36994,59311:36989,59312:36993,59313:36992,59314:37002,59315:37001,59316:37007,59317:37032,59318:37039,59319:37041,59320:37045,59321:37090,59322:37092,59323:25160,59324:37083,59325:37122,59326:37138,59327:37145,59328:37170,59329:37168,59330:37194,59331:37206,59332:37208,59333:37219,59334:37221,59335:37225,59336:37235,59337:37234,59338:37259,59339:37257,59340:37250,59341:37282,59342:37291,59343:37295,59344:37290,59345:37301,59346:37300,59347:37306,59348:37312,59349:37313,59350:37321,59351:37323,59352:37328,59353:37334,59354:37343,59355:37345,59356:37339,59357:37372,59358:37365,59359:37366,59360:37406,59361:37375,59362:37396,59363:37420,59364:37397,59365:37393,59366:37470,59367:37463,59368:37445,59369:37449,59370:37476,59371:37448,59372:37525,59373:37439,59374:37451,59375:37456,59376:37532,59377:37526,59378:37523,59379:37531,59380:37466,59381:37583,59382:37561,59383:37559,59384:37609,59385:37647,59386:37626,59387:37700,59388:37678,59456:37657,59457:37666,59458:37658,59459:37667,59460:37690,59461:37685,59462:37691,59463:37724,59464:37728,59465:37756,59466:37742,59467:37718,59468:37808,59469:37804,59470:37805,59471:37780,59472:37817,59473:37846,59474:37847,59475:37864,59476:37861,59477:37848,59478:37827,59479:37853,59480:37840,59481:37832,59482:37860,59483:37914,59484:37908,59485:37907,59486:37891,59487:37895,59488:37904,59489:37942,59490:37931,59491:37941,59492:37921,59493:37946,59494:37953,59495:37970,59496:37956,59497:37979,59498:37984,59499:37986,59500:37982,59501:37994,59502:37417,59503:38e3,59504:38005,59505:38007,59506:38013,59507:37978,59508:38012,59509:38014,59510:38017,59511:38015,59512:38274,59513:38279,59514:38282,59515:38292,59516:38294,59517:38296,59518:38297,59520:38304,59521:38312,59522:38311,59523:38317,59524:38332,59525:38331,59526:38329,59527:38334,59528:38346,59529:28662,59530:38339,59531:38349,59532:38348,59533:38357,59534:38356,59535:38358,59536:38364,59537:38369,59538:38373,59539:38370,59540:38433,59541:38440,59542:38446,59543:38447,59544:38466,59545:38476,59546:38479,59547:38475,59548:38519,59549:38492,59550:38494,59551:38493,59552:38495,59553:38502,59554:38514,59555:38508,59556:38541,59557:38552,59558:38549,59559:38551,59560:38570,59561:38567,59562:38577,59563:38578,59564:38576,59565:38580,59566:38582,59567:38584,59568:38585,59569:38606,59570:38603,59571:38601,59572:38605,59573:35149,59574:38620,59575:38669,59576:38613,59577:38649,59578:38660,59579:38662,59580:38664,59581:38675,59582:38670,59583:38673,59584:38671,59585:38678,59586:38681,59587:38692,59588:38698,59589:38704,59590:38713,59591:38717,59592:38718,59593:38724,59594:38726,59595:38728,59596:38722,59597:38729,59598:38748,59599:38752,59600:38756,59601:38758,59602:38760,59603:21202,59604:38763,59605:38769,59606:38777,59607:38789,59608:38780,59609:38785,59610:38778,59611:38790,59612:38795,59613:38799,59614:38800,59615:38812,59616:38824,59617:38822,59618:38819,59619:38835,59620:38836,59621:38851,59622:38854,59623:38856,59624:38859,59625:38876,59626:38893,59627:40783,59628:38898,59629:31455,59630:38902,59631:38901,59632:38927,59633:38924,59634:38968,59635:38948,59636:38945,59637:38967,59638:38973,59639:38982,59640:38991,59641:38987,59642:39019,59643:39023,59644:39024,59712:39025,59713:39028,59714:39027,59715:39082,59716:39087,59717:39089,59718:39094,59719:39108,59720:39107,59721:39110,59722:39145,59723:39147,59724:39171,59725:39177,59726:39186,59727:39188,59728:39192,59729:39201,59730:39197,59731:39198,59732:39204,59733:39200,59734:39212,59735:39214,59736:39229,59737:39230,59738:39234,59739:39241,59740:39237,59741:39248,59742:39243,59743:39249,59744:39250,59745:39244,59746:39253,59747:39319,59748:39320,59749:39333,59750:39341,59751:39342,59752:39356,59753:39391,59754:39387,59755:39389,59756:39384,59757:39377,59758:39405,59759:39406,59760:39409,59761:39410,59762:39419,59763:39416,59764:39425,59765:39439,59766:39429,59767:39394,59768:39449,59769:39467,59770:39479,59771:39493,59772:39490,59773:39488,59774:39491,59776:39486,59777:39509,59778:39501,59779:39515,59780:39511,59781:39519,59782:39522,59783:39525,59784:39524,59785:39529,59786:39531,59787:39530,59788:39597,59789:39600,59790:39612,59791:39616,59792:39631,59793:39633,59794:39635,59795:39636,59796:39646,59797:39647,59798:39650,59799:39651,59800:39654,59801:39663,59802:39659,59803:39662,59804:39668,59805:39665,59806:39671,59807:39675,59808:39686,59809:39704,59810:39706,59811:39711,59812:39714,59813:39715,59814:39717,59815:39719,59816:39720,59817:39721,59818:39722,59819:39726,59820:39727,59821:39730,59822:39748,59823:39747,59824:39759,59825:39757,59826:39758,59827:39761,59828:39768,59829:39796,59830:39827,59831:39811,59832:39825,59833:39830,59834:39831,59835:39839,59836:39840,59837:39848,59838:39860,59839:39872,59840:39882,59841:39865,59842:39878,59843:39887,59844:39889,59845:39890,59846:39907,59847:39906,59848:39908,59849:39892,59850:39905,59851:39994,59852:39922,59853:39921,59854:39920,59855:39957,59856:39956,59857:39945,59858:39955,59859:39948,59860:39942,59861:39944,59862:39954,59863:39946,59864:39940,59865:39982,59866:39963,59867:39973,59868:39972,59869:39969,59870:39984,59871:40007,59872:39986,59873:40006,59874:39998,59875:40026,59876:40032,59877:40039,59878:40054,59879:40056,59880:40167,59881:40172,59882:40176,59883:40201,59884:40200,59885:40171,59886:40195,59887:40198,59888:40234,59889:40230,59890:40367,59891:40227,59892:40223,59893:40260,59894:40213,59895:40210,59896:40257,59897:40255,59898:40254,59899:40262,59900:40264,59968:40285,59969:40286,59970:40292,59971:40273,59972:40272,59973:40281,59974:40306,59975:40329,59976:40327,59977:40363,59978:40303,59979:40314,59980:40346,59981:40356,59982:40361,59983:40370,59984:40388,59985:40385,59986:40379,59987:40376,59988:40378,59989:40390,59990:40399,59991:40386,59992:40409,59993:40403,59994:40440,59995:40422,59996:40429,59997:40431,59998:40445,59999:40474,6e4:40475,60001:40478,60002:40565,60003:40569,60004:40573,60005:40577,60006:40584,60007:40587,60008:40588,60009:40594,60010:40597,60011:40593,60012:40605,60013:40613,60014:40617,60015:40632,60016:40618,60017:40621,60018:38753,60019:40652,60020:40654,60021:40655,60022:40656,60023:40660,60024:40668,60025:40670,60026:40669,60027:40672,60028:40677,60029:40680,60030:40687,60032:40692,60033:40694,60034:40695,60035:40697,60036:40699,60037:40700,60038:40701,60039:40711,60040:40712,60041:30391,60042:40725,60043:40737,60044:40748,60045:40766,60046:40778,60047:40786,60048:40788,60049:40803,60050:40799,60051:40800,60052:40801,60053:40806,60054:40807,60055:40812,60056:40810,60057:40823,60058:40818,60059:40822,60060:40853,60061:40860,60062:40864,60063:22575,60064:27079,60065:36953,60066:29796,60067:20956,60068:29081}}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(1),i=n(2);function a(e,t,n,r){var i;t.degree()<n.degree()&&(i=[n,t],t=i[0],n=i[1]);for(var a=t,o=n,s=e.zero,c=e.one;o.degree()>=r/2;){var l=a,u=s;if(a=o,s=c,a.isZero())return null;o=l;for(var d=e.zero,f=a.getCoefficient(a.degree()),p=e.inverse(f);o.degree()>=a.degree()&&!o.isZero();){var m=o.degree()-a.degree(),h=e.multiply(o.getCoefficient(o.degree()),p);d=d.addOrSubtract(e.buildMonomial(m,h)),o=o.addOrSubtract(a.multiplyByMonomial(m,h))}if(c=d.multiplyPoly(s).addOrSubtract(u),o.degree()>=a.degree())return null}var g=c.getCoefficient(0);if(g===0)return null;var _=e.inverse(g);return[c.multiply(_),o.multiply(_)]}function o(e,t){var n=t.degree();if(n===1)return[t.getCoefficient(1)];for(var r=Array(n),i=0,a=1;a<e.size&&i<n;a++)t.evaluateAt(a)===0&&(r[i]=e.inverse(a),i++);return i===n?r:null}function s(e,t,n){for(var i=n.length,a=Array(i),o=0;o<i;o++){for(var s=e.inverse(n[o]),c=1,l=0;l<i;l++)o!==l&&(c=e.multiply(c,r.addOrSubtractGF(1,e.multiply(n[l],s))));a[o]=e.multiply(t.evaluateAt(s),e.inverse(c)),e.generatorBase!==0&&(a[o]=e.multiply(a[o],s))}return a}function c(e,t){var n=new Uint8ClampedArray(e.length);n.set(e);for(var c=new r.default(285,256,0),l=new i.default(c,n),u=new Uint8ClampedArray(t),d=!1,f=0;f<t;f++){var p=l.evaluateAt(c.exp(f+c.generatorBase));u[u.length-1-f]=p,p!==0&&(d=!0)}if(!d)return n;var m=new i.default(c,u),h=a(c,c.buildMonomial(t,1),m,t);if(h===null)return null;var g=o(c,h[0]);if(g==null)return null;for(var _=s(c,h[1],g),v=0;v<g.length;v++){var y=n.length-1-c.log(g[v]);if(y<0)return null;n[y]=r.addOrSubtractGF(n[y],_[v])}return n}t.decode=c}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.VERSIONS=[{infoBits:null,versionNumber:1,alignmentPatternCenters:[],errorCorrectionLevels:[{ecCodewordsPerBlock:7,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:19}]},{ecCodewordsPerBlock:10,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:16}]},{ecCodewordsPerBlock:13,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:13}]},{ecCodewordsPerBlock:17,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:9}]}]},{infoBits:null,versionNumber:2,alignmentPatternCenters:[6,18],errorCorrectionLevels:[{ecCodewordsPerBlock:10,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:34}]},{ecCodewordsPerBlock:16,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:28}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:22}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:16}]}]},{infoBits:null,versionNumber:3,alignmentPatternCenters:[6,22],errorCorrectionLevels:[{ecCodewordsPerBlock:15,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:55}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:44}]},{ecCodewordsPerBlock:18,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:17}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:13}]}]},{infoBits:null,versionNumber:4,alignmentPatternCenters:[6,26],errorCorrectionLevels:[{ecCodewordsPerBlock:20,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:80}]},{ecCodewordsPerBlock:18,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:32}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:24}]},{ecCodewordsPerBlock:16,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:9}]}]},{infoBits:null,versionNumber:5,alignmentPatternCenters:[6,30],errorCorrectionLevels:[{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:108}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:43}]},{ecCodewordsPerBlock:18,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:15},{numBlocks:2,dataCodewordsPerBlock:16}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:11},{numBlocks:2,dataCodewordsPerBlock:12}]}]},{infoBits:null,versionNumber:6,alignmentPatternCenters:[6,34],errorCorrectionLevels:[{ecCodewordsPerBlock:18,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:68}]},{ecCodewordsPerBlock:16,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:27}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:19}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:15}]}]},{infoBits:31892,versionNumber:7,alignmentPatternCenters:[6,22,38],errorCorrectionLevels:[{ecCodewordsPerBlock:20,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:78}]},{ecCodewordsPerBlock:18,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:31}]},{ecCodewordsPerBlock:18,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:14},{numBlocks:4,dataCodewordsPerBlock:15}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:13},{numBlocks:1,dataCodewordsPerBlock:14}]}]},{infoBits:34236,versionNumber:8,alignmentPatternCenters:[6,24,42],errorCorrectionLevels:[{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:97}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:38},{numBlocks:2,dataCodewordsPerBlock:39}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:18},{numBlocks:2,dataCodewordsPerBlock:19}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:14},{numBlocks:2,dataCodewordsPerBlock:15}]}]},{infoBits:39577,versionNumber:9,alignmentPatternCenters:[6,26,46],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:116}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:36},{numBlocks:2,dataCodewordsPerBlock:37}]},{ecCodewordsPerBlock:20,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:16},{numBlocks:4,dataCodewordsPerBlock:17}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:12},{numBlocks:4,dataCodewordsPerBlock:13}]}]},{infoBits:42195,versionNumber:10,alignmentPatternCenters:[6,28,50],errorCorrectionLevels:[{ecCodewordsPerBlock:18,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:68},{numBlocks:2,dataCodewordsPerBlock:69}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:43},{numBlocks:1,dataCodewordsPerBlock:44}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:6,dataCodewordsPerBlock:19},{numBlocks:2,dataCodewordsPerBlock:20}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:6,dataCodewordsPerBlock:15},{numBlocks:2,dataCodewordsPerBlock:16}]}]},{infoBits:48118,versionNumber:11,alignmentPatternCenters:[6,30,54],errorCorrectionLevels:[{ecCodewordsPerBlock:20,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:81}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:50},{numBlocks:4,dataCodewordsPerBlock:51}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:22},{numBlocks:4,dataCodewordsPerBlock:23}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:12},{numBlocks:8,dataCodewordsPerBlock:13}]}]},{infoBits:51042,versionNumber:12,alignmentPatternCenters:[6,32,58],errorCorrectionLevels:[{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:92},{numBlocks:2,dataCodewordsPerBlock:93}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:6,dataCodewordsPerBlock:36},{numBlocks:2,dataCodewordsPerBlock:37}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:20},{numBlocks:6,dataCodewordsPerBlock:21}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:7,dataCodewordsPerBlock:14},{numBlocks:4,dataCodewordsPerBlock:15}]}]},{infoBits:55367,versionNumber:13,alignmentPatternCenters:[6,34,62],errorCorrectionLevels:[{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:107}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:8,dataCodewordsPerBlock:37},{numBlocks:1,dataCodewordsPerBlock:38}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:8,dataCodewordsPerBlock:20},{numBlocks:4,dataCodewordsPerBlock:21}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:12,dataCodewordsPerBlock:11},{numBlocks:4,dataCodewordsPerBlock:12}]}]},{infoBits:58893,versionNumber:14,alignmentPatternCenters:[6,26,46,66],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:115},{numBlocks:1,dataCodewordsPerBlock:116}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:40},{numBlocks:5,dataCodewordsPerBlock:41}]},{ecCodewordsPerBlock:20,ecBlocks:[{numBlocks:11,dataCodewordsPerBlock:16},{numBlocks:5,dataCodewordsPerBlock:17}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:11,dataCodewordsPerBlock:12},{numBlocks:5,dataCodewordsPerBlock:13}]}]},{infoBits:63784,versionNumber:15,alignmentPatternCenters:[6,26,48,70],errorCorrectionLevels:[{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:5,dataCodewordsPerBlock:87},{numBlocks:1,dataCodewordsPerBlock:88}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:5,dataCodewordsPerBlock:41},{numBlocks:5,dataCodewordsPerBlock:42}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:5,dataCodewordsPerBlock:24},{numBlocks:7,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:11,dataCodewordsPerBlock:12},{numBlocks:7,dataCodewordsPerBlock:13}]}]},{infoBits:68472,versionNumber:16,alignmentPatternCenters:[6,26,50,74],errorCorrectionLevels:[{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:5,dataCodewordsPerBlock:98},{numBlocks:1,dataCodewordsPerBlock:99}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:7,dataCodewordsPerBlock:45},{numBlocks:3,dataCodewordsPerBlock:46}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:15,dataCodewordsPerBlock:19},{numBlocks:2,dataCodewordsPerBlock:20}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:15},{numBlocks:13,dataCodewordsPerBlock:16}]}]},{infoBits:70749,versionNumber:17,alignmentPatternCenters:[6,30,54,78],errorCorrectionLevels:[{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:107},{numBlocks:5,dataCodewordsPerBlock:108}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:10,dataCodewordsPerBlock:46},{numBlocks:1,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:22},{numBlocks:15,dataCodewordsPerBlock:23}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:14},{numBlocks:17,dataCodewordsPerBlock:15}]}]},{infoBits:76311,versionNumber:18,alignmentPatternCenters:[6,30,56,82],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:5,dataCodewordsPerBlock:120},{numBlocks:1,dataCodewordsPerBlock:121}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:9,dataCodewordsPerBlock:43},{numBlocks:4,dataCodewordsPerBlock:44}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:22},{numBlocks:1,dataCodewordsPerBlock:23}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:14},{numBlocks:19,dataCodewordsPerBlock:15}]}]},{infoBits:79154,versionNumber:19,alignmentPatternCenters:[6,30,58,86],errorCorrectionLevels:[{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:113},{numBlocks:4,dataCodewordsPerBlock:114}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:44},{numBlocks:11,dataCodewordsPerBlock:45}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:21},{numBlocks:4,dataCodewordsPerBlock:22}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:9,dataCodewordsPerBlock:13},{numBlocks:16,dataCodewordsPerBlock:14}]}]},{infoBits:84390,versionNumber:20,alignmentPatternCenters:[6,34,62,90],errorCorrectionLevels:[{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:107},{numBlocks:5,dataCodewordsPerBlock:108}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:41},{numBlocks:13,dataCodewordsPerBlock:42}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:15,dataCodewordsPerBlock:24},{numBlocks:5,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:15,dataCodewordsPerBlock:15},{numBlocks:10,dataCodewordsPerBlock:16}]}]},{infoBits:87683,versionNumber:21,alignmentPatternCenters:[6,28,50,72,94],errorCorrectionLevels:[{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:116},{numBlocks:4,dataCodewordsPerBlock:117}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:42}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:22},{numBlocks:6,dataCodewordsPerBlock:23}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:19,dataCodewordsPerBlock:16},{numBlocks:6,dataCodewordsPerBlock:17}]}]},{infoBits:92361,versionNumber:22,alignmentPatternCenters:[6,26,50,74,98],errorCorrectionLevels:[{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:111},{numBlocks:7,dataCodewordsPerBlock:112}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:46}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:7,dataCodewordsPerBlock:24},{numBlocks:16,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:34,dataCodewordsPerBlock:13}]}]},{infoBits:96236,versionNumber:23,alignmentPatternCenters:[6,30,54,74,102],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:121},{numBlocks:5,dataCodewordsPerBlock:122}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:47},{numBlocks:14,dataCodewordsPerBlock:48}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:11,dataCodewordsPerBlock:24},{numBlocks:14,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:16,dataCodewordsPerBlock:15},{numBlocks:14,dataCodewordsPerBlock:16}]}]},{infoBits:102084,versionNumber:24,alignmentPatternCenters:[6,28,54,80,106],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:6,dataCodewordsPerBlock:117},{numBlocks:4,dataCodewordsPerBlock:118}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:6,dataCodewordsPerBlock:45},{numBlocks:14,dataCodewordsPerBlock:46}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:11,dataCodewordsPerBlock:24},{numBlocks:16,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:30,dataCodewordsPerBlock:16},{numBlocks:2,dataCodewordsPerBlock:17}]}]},{infoBits:102881,versionNumber:25,alignmentPatternCenters:[6,32,58,84,110],errorCorrectionLevels:[{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:8,dataCodewordsPerBlock:106},{numBlocks:4,dataCodewordsPerBlock:107}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:8,dataCodewordsPerBlock:47},{numBlocks:13,dataCodewordsPerBlock:48}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:7,dataCodewordsPerBlock:24},{numBlocks:22,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:22,dataCodewordsPerBlock:15},{numBlocks:13,dataCodewordsPerBlock:16}]}]},{infoBits:110507,versionNumber:26,alignmentPatternCenters:[6,30,58,86,114],errorCorrectionLevels:[{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:10,dataCodewordsPerBlock:114},{numBlocks:2,dataCodewordsPerBlock:115}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:19,dataCodewordsPerBlock:46},{numBlocks:4,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:28,dataCodewordsPerBlock:22},{numBlocks:6,dataCodewordsPerBlock:23}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:33,dataCodewordsPerBlock:16},{numBlocks:4,dataCodewordsPerBlock:17}]}]},{infoBits:110734,versionNumber:27,alignmentPatternCenters:[6,34,62,90,118],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:8,dataCodewordsPerBlock:122},{numBlocks:4,dataCodewordsPerBlock:123}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:22,dataCodewordsPerBlock:45},{numBlocks:3,dataCodewordsPerBlock:46}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:8,dataCodewordsPerBlock:23},{numBlocks:26,dataCodewordsPerBlock:24}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:12,dataCodewordsPerBlock:15},{numBlocks:28,dataCodewordsPerBlock:16}]}]},{infoBits:117786,versionNumber:28,alignmentPatternCenters:[6,26,50,74,98,122],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:117},{numBlocks:10,dataCodewordsPerBlock:118}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:45},{numBlocks:23,dataCodewordsPerBlock:46}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:24},{numBlocks:31,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:11,dataCodewordsPerBlock:15},{numBlocks:31,dataCodewordsPerBlock:16}]}]},{infoBits:119615,versionNumber:29,alignmentPatternCenters:[6,30,54,78,102,126],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:7,dataCodewordsPerBlock:116},{numBlocks:7,dataCodewordsPerBlock:117}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:21,dataCodewordsPerBlock:45},{numBlocks:7,dataCodewordsPerBlock:46}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:23},{numBlocks:37,dataCodewordsPerBlock:24}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:19,dataCodewordsPerBlock:15},{numBlocks:26,dataCodewordsPerBlock:16}]}]},{infoBits:126325,versionNumber:30,alignmentPatternCenters:[6,26,52,78,104,130],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:5,dataCodewordsPerBlock:115},{numBlocks:10,dataCodewordsPerBlock:116}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:19,dataCodewordsPerBlock:47},{numBlocks:10,dataCodewordsPerBlock:48}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:15,dataCodewordsPerBlock:24},{numBlocks:25,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:23,dataCodewordsPerBlock:15},{numBlocks:25,dataCodewordsPerBlock:16}]}]},{infoBits:127568,versionNumber:31,alignmentPatternCenters:[6,30,56,82,108,134],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:13,dataCodewordsPerBlock:115},{numBlocks:3,dataCodewordsPerBlock:116}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:46},{numBlocks:29,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:42,dataCodewordsPerBlock:24},{numBlocks:1,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:23,dataCodewordsPerBlock:15},{numBlocks:28,dataCodewordsPerBlock:16}]}]},{infoBits:133589,versionNumber:32,alignmentPatternCenters:[6,34,60,86,112,138],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:115}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:10,dataCodewordsPerBlock:46},{numBlocks:23,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:10,dataCodewordsPerBlock:24},{numBlocks:35,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:19,dataCodewordsPerBlock:15},{numBlocks:35,dataCodewordsPerBlock:16}]}]},{infoBits:136944,versionNumber:33,alignmentPatternCenters:[6,30,58,86,114,142],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:115},{numBlocks:1,dataCodewordsPerBlock:116}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:14,dataCodewordsPerBlock:46},{numBlocks:21,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:29,dataCodewordsPerBlock:24},{numBlocks:19,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:11,dataCodewordsPerBlock:15},{numBlocks:46,dataCodewordsPerBlock:16}]}]},{infoBits:141498,versionNumber:34,alignmentPatternCenters:[6,34,62,90,118,146],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:13,dataCodewordsPerBlock:115},{numBlocks:6,dataCodewordsPerBlock:116}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:14,dataCodewordsPerBlock:46},{numBlocks:23,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:44,dataCodewordsPerBlock:24},{numBlocks:7,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:59,dataCodewordsPerBlock:16},{numBlocks:1,dataCodewordsPerBlock:17}]}]},{infoBits:145311,versionNumber:35,alignmentPatternCenters:[6,30,54,78,102,126,150],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:12,dataCodewordsPerBlock:121},{numBlocks:7,dataCodewordsPerBlock:122}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:12,dataCodewordsPerBlock:47},{numBlocks:26,dataCodewordsPerBlock:48}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:39,dataCodewordsPerBlock:24},{numBlocks:14,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:22,dataCodewordsPerBlock:15},{numBlocks:41,dataCodewordsPerBlock:16}]}]},{infoBits:150283,versionNumber:36,alignmentPatternCenters:[6,24,50,76,102,128,154],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:6,dataCodewordsPerBlock:121},{numBlocks:14,dataCodewordsPerBlock:122}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:6,dataCodewordsPerBlock:47},{numBlocks:34,dataCodewordsPerBlock:48}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:46,dataCodewordsPerBlock:24},{numBlocks:10,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:15},{numBlocks:64,dataCodewordsPerBlock:16}]}]},{infoBits:152622,versionNumber:37,alignmentPatternCenters:[6,28,54,80,106,132,158],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:122},{numBlocks:4,dataCodewordsPerBlock:123}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:29,dataCodewordsPerBlock:46},{numBlocks:14,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:49,dataCodewordsPerBlock:24},{numBlocks:10,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:24,dataCodewordsPerBlock:15},{numBlocks:46,dataCodewordsPerBlock:16}]}]},{infoBits:158308,versionNumber:38,alignmentPatternCenters:[6,32,58,84,110,136,162],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:122},{numBlocks:18,dataCodewordsPerBlock:123}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:13,dataCodewordsPerBlock:46},{numBlocks:32,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:48,dataCodewordsPerBlock:24},{numBlocks:14,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:42,dataCodewordsPerBlock:15},{numBlocks:32,dataCodewordsPerBlock:16}]}]},{infoBits:161089,versionNumber:39,alignmentPatternCenters:[6,26,54,82,110,138,166],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:20,dataCodewordsPerBlock:117},{numBlocks:4,dataCodewordsPerBlock:118}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:40,dataCodewordsPerBlock:47},{numBlocks:7,dataCodewordsPerBlock:48}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:43,dataCodewordsPerBlock:24},{numBlocks:22,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:10,dataCodewordsPerBlock:15},{numBlocks:67,dataCodewordsPerBlock:16}]}]},{infoBits:167017,versionNumber:40,alignmentPatternCenters:[6,30,58,86,114,142,170],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:19,dataCodewordsPerBlock:118},{numBlocks:6,dataCodewordsPerBlock:119}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:18,dataCodewordsPerBlock:47},{numBlocks:31,dataCodewordsPerBlock:48}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:34,dataCodewordsPerBlock:24},{numBlocks:34,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:20,dataCodewordsPerBlock:15},{numBlocks:61,dataCodewordsPerBlock:16}]}]}]}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(0);function i(e,t,n,r){var i=e.x-t.x+n.x-r.x,a=e.y-t.y+n.y-r.y;if(i===0&&a===0)return{a11:t.x-e.x,a12:t.y-e.y,a13:0,a21:n.x-t.x,a22:n.y-t.y,a23:0,a31:e.x,a32:e.y,a33:1};var o=t.x-n.x,s=r.x-n.x,c=t.y-n.y,l=r.y-n.y,u=o*l-s*c,d=(i*l-s*a)/u,f=(o*a-i*c)/u;return{a11:t.x-e.x+d*t.x,a12:t.y-e.y+d*t.y,a13:d,a21:r.x-e.x+f*r.x,a22:r.y-e.y+f*r.y,a23:f,a31:e.x,a32:e.y,a33:1}}function a(e,t,n,r){var a=i(e,t,n,r);return{a11:a.a22*a.a33-a.a23*a.a32,a12:a.a13*a.a32-a.a12*a.a33,a13:a.a12*a.a23-a.a13*a.a22,a21:a.a23*a.a31-a.a21*a.a33,a22:a.a11*a.a33-a.a13*a.a31,a23:a.a13*a.a21-a.a11*a.a23,a31:a.a21*a.a32-a.a22*a.a31,a32:a.a12*a.a31-a.a11*a.a32,a33:a.a11*a.a22-a.a12*a.a21}}function o(e,t){return{a11:e.a11*t.a11+e.a21*t.a12+e.a31*t.a13,a12:e.a12*t.a11+e.a22*t.a12+e.a32*t.a13,a13:e.a13*t.a11+e.a23*t.a12+e.a33*t.a13,a21:e.a11*t.a21+e.a21*t.a22+e.a31*t.a23,a22:e.a12*t.a21+e.a22*t.a22+e.a32*t.a23,a23:e.a13*t.a21+e.a23*t.a22+e.a33*t.a23,a31:e.a11*t.a31+e.a21*t.a32+e.a31*t.a33,a32:e.a12*t.a31+e.a22*t.a32+e.a32*t.a33,a33:e.a13*t.a31+e.a23*t.a32+e.a33*t.a33}}function s(e,t){for(var n=a({x:3.5,y:3.5},{x:t.dimension-3.5,y:3.5},{x:t.dimension-6.5,y:t.dimension-6.5},{x:3.5,y:t.dimension-3.5}),s=o(i(t.topLeft,t.topRight,t.alignmentPattern,t.bottomLeft),n),c=r.BitMatrix.createEmpty(t.dimension,t.dimension),l=function(e,t){var n=s.a13*e+s.a23*t+s.a33;return{x:(s.a11*e+s.a21*t+s.a31)/n,y:(s.a12*e+s.a22*t+s.a32)/n}},u=0;u<t.dimension;u++)for(var d=0;d<t.dimension;d++){var f=l(d+.5,u+.5);c.set(d,u,e.get(Math.floor(f.x),Math.floor(f.y)))}return{matrix:c,mappingFunction:l}}t.extract=s}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=4,i=.5,a=1.5,o=function(e,t){return Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2)};function s(e){return e.reduce(function(e,t){return e+t})}function c(e,t,n){var r,i,a,s,c=o(e,t),l=o(t,n),u=o(e,n),d,f,p;return l>=c&&l>=u?(r=[t,e,n],d=r[0],f=r[1],p=r[2]):u>=l&&u>=c?(i=[e,t,n],d=i[0],f=i[1],p=i[2]):(a=[e,n,t],d=a[0],f=a[1],p=a[2]),(p.x-f.x)*(d.y-f.y)-(p.y-f.y)*(d.x-f.x)<0&&(s=[p,d],d=s[0],p=s[1]),{bottomLeft:d,topLeft:f,topRight:p}}function l(e,t,n,r){var i=(s(d(e,n,r,5))/7+s(d(e,t,r,5))/7+s(d(n,e,r,5))/7+s(d(t,e,r,5))/7)/4;if(i<1)throw Error(`Invalid module size`);var a=Math.round(o(e,t)/i),c=Math.round(o(e,n)/i),l=Math.floor((a+c)/2)+7;switch(l%4){case 0:l++;break;case 2:l--;break}return{dimension:l,moduleSize:i}}function u(e,t,n,r){var i=[{x:Math.floor(e.x),y:Math.floor(e.y)}],a=Math.abs(t.y-e.y)>Math.abs(t.x-e.x),s,c,l,u;a?(s=Math.floor(e.y),c=Math.floor(e.x),l=Math.floor(t.y),u=Math.floor(t.x)):(s=Math.floor(e.x),c=Math.floor(e.y),l=Math.floor(t.x),u=Math.floor(t.y));for(var d=Math.abs(l-s),f=Math.abs(u-c),p=Math.floor(-d/2),m=s<l?1:-1,h=c<u?1:-1,g=!0,_=s,v=c;_!==l+m;_+=m){var y=a?v:_,b=a?_:v;if(n.get(y,b)!==g&&(g=!g,i.push({x:y,y:b}),i.length===r+1))break;if(p+=f,p>0){if(v===u)break;v+=h,p-=d}}for(var x=[],S=0;S<r;S++)i[S]&&i[S+1]?x.push(o(i[S],i[S+1])):x.push(0);return x}function d(e,t,n,r){var i,a=t.y-e.y,o=t.x-e.x,s=u(e,t,n,Math.ceil(r/2)),c=u(e,{x:e.x-o,y:e.y-a},n,Math.ceil(r/2)),l=s.shift()+c.shift()-1;return(i=c.concat(l)).concat.apply(i,s)}function f(e,t){var n=s(e)/s(t),r=0;return t.forEach(function(t,i){r+=(e[i]-t*n)**2}),{averageSize:n,error:r}}function p(e,t,n){try{var r=d(e,{x:-1,y:e.y},n,t.length),i=d(e,{x:e.x,y:-1},n,t.length),a=d(e,{x:Math.max(0,e.x-e.y)-1,y:Math.max(0,e.y-e.x)-1},n,t.length),o=d(e,{x:Math.min(n.width,e.x+e.y)+1,y:Math.min(n.height,e.y+e.x)+1},n,t.length),s=f(r,t),c=f(i,t),l=f(a,t),u=f(o,t),p=Math.sqrt(s.error*s.error+c.error*c.error+l.error*l.error+u.error*u.error),m=(s.averageSize+c.averageSize+l.averageSize+u.averageSize)/4;return p+((s.averageSize-m)**2+(c.averageSize-m)**2+(l.averageSize-m)**2+(u.averageSize-m)**2)/m}catch{return 1/0}}function m(e,t){for(var n=Math.round(t.x);e.get(n,Math.round(t.y));)n--;for(var r=Math.round(t.x);e.get(r,Math.round(t.y));)r++;for(var i=(n+r)/2,a=Math.round(t.y);e.get(Math.round(i),a);)a--;for(var o=Math.round(t.y);e.get(Math.round(i),o);)o++;return{x:i,y:(a+o)/2}}function h(e){for(var t=[],n=[],o=[],l=[],u=function(r){for(var c=0,u=!1,d=[0,0,0,0,0],f=function(t){var o=e.get(t,r);if(o===u)c++;else{d=[d[1],d[2],d[3],d[4],c],c=1,u=o;var f=s(d)/7,p=Math.abs(d[0]-f)<f&&Math.abs(d[1]-f)<f&&Math.abs(d[2]-3*f)<3*f&&Math.abs(d[3]-f)<f&&Math.abs(d[4]-f)<f&&!o,m=s(d.slice(-3))/3,h=Math.abs(d[2]-m)<m&&Math.abs(d[3]-m)<m&&Math.abs(d[4]-m)<m&&o;if(p){var g=t-d[3]-d[4],_=g-d[2],v={startX:_,endX:g,y:r},y=n.filter(function(e){return _>=e.bottom.startX&&_<=e.bottom.endX||g>=e.bottom.startX&&_<=e.bottom.endX||_<=e.bottom.startX&&g>=e.bottom.endX&&d[2]/(e.bottom.endX-e.bottom.startX)<a&&d[2]/(e.bottom.endX-e.bottom.startX)>i});y.length>0?y[0].bottom=v:n.push({top:v,bottom:v})}if(h){var b=t-d[4],x=b-d[3],v={startX:x,y:r,endX:b},y=l.filter(function(e){return x>=e.bottom.startX&&x<=e.bottom.endX||b>=e.bottom.startX&&x<=e.bottom.endX||x<=e.bottom.startX&&b>=e.bottom.endX&&d[2]/(e.bottom.endX-e.bottom.startX)<a&&d[2]/(e.bottom.endX-e.bottom.startX)>i});y.length>0?y[0].bottom=v:l.push({top:v,bottom:v})}}},p=-1;p<=e.width;p++)f(p);t.push.apply(t,n.filter(function(e){return e.bottom.y!==r&&e.bottom.y-e.top.y>=2})),n=n.filter(function(e){return e.bottom.y===r}),o.push.apply(o,l.filter(function(e){return e.bottom.y!==r})),l=l.filter(function(e){return e.bottom.y===r})},d=0;d<=e.height;d++)u(d);t.push.apply(t,n.filter(function(e){return e.bottom.y-e.top.y>=2})),o.push.apply(o,l);var f=t.filter(function(e){return e.bottom.y-e.top.y>=2}).map(function(t){var n=(t.top.startX+t.top.endX+t.bottom.startX+t.bottom.endX)/4,r=(t.top.y+t.bottom.y+1)/2;if(e.get(Math.round(n),Math.round(r))){var i=[t.top.endX-t.top.startX,t.bottom.endX-t.bottom.startX,t.bottom.y-t.top.y+1],a=s(i)/i.length;return{score:p({x:Math.round(n),y:Math.round(r)},[1,1,3,1,1],e),x:n,y:r,size:a}}}).filter(function(e){return!!e}).sort(function(e,t){return e.score-t.score}).map(function(e,t,n){if(t>r)return null;var i=n.filter(function(e,n){return t!==n}).map(function(t){return{x:t.x,y:t.y,score:t.score+(t.size-e.size)**2/e.size,size:t.size}}).sort(function(e,t){return e.score-t.score});if(i.length<2)return null;var a=e.score+i[0].score+i[1].score;return{points:[e].concat(i.slice(0,2)),score:a}}).filter(function(e){return!!e}).sort(function(e,t){return e.score-t.score});if(f.length===0)return null;var h=c(f[0].points[0],f[0].points[1],f[0].points[2]),_=h.topRight,v=h.topLeft,y=h.bottomLeft,b=g(e,o,_,v,y),x=[];b&&x.push({alignmentPattern:{x:b.alignmentPattern.x,y:b.alignmentPattern.y},bottomLeft:{x:y.x,y:y.y},dimension:b.dimension,topLeft:{x:v.x,y:v.y},topRight:{x:_.x,y:_.y}});var S=m(e,_),C=m(e,v),w=m(e,y),T=g(e,o,S,C,w);return T&&x.push({alignmentPattern:{x:T.alignmentPattern.x,y:T.alignmentPattern.y},bottomLeft:{x:w.x,y:w.y},topLeft:{x:C.x,y:C.y},topRight:{x:S.x,y:S.y},dimension:T.dimension}),x.length===0?null:x}t.locate=h;function g(e,t,n,r,i){var a,c,u;try{a=l(r,n,i,e),c=a.dimension,u=a.moduleSize}catch{return null}var d={x:n.x-r.x+i.x,y:n.y-r.y+i.y},f=(o(r,i)+o(r,n))/2/u,m=1-3/f,h={x:r.x+m*(d.x-r.x),y:r.y+m*(d.y-r.y)},g=t.map(function(t){var n=(t.top.startX+t.top.endX+t.bottom.startX+t.bottom.endX)/4,r=(t.top.y+t.bottom.y+1)/2;if(e.get(Math.floor(n),Math.floor(r))){var i=[t.top.endX-t.top.startX,t.bottom.endX-t.bottom.startX,t.bottom.y-t.top.y+1];return s(i)/i.length,{x:n,y:r,score:p({x:Math.floor(n),y:Math.floor(r)},[1,1,1],e)+o({x:n,y:r},h)}}}).filter(function(e){return!!e}).sort(function(e,t){return e.score-t.score});return{alignmentPattern:f>=15&&g.length?g[0]:h,dimension:c}}})]).default})}))(),1);function kq(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function Aq(e){let t=e.length%4,n=(e+(t?`=`.repeat(4-t):``)).replace(/-/g,`+`).replace(/_/g,`/`),r=atob(n),i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return i}async function jq(e,t){let n=t.writable.getWriter();n.write(e),n.close();let r=t.readable.getReader(),i=[],a=0;for(;;){let{value:e,done:t}=await r.read();if(t)break;e&&(i.push(e),a+=e.length)}let o=new Uint8Array(a),s=0;for(let e of i)o.set(e,s),s+=e.length;return o}async function Mq(e){let t=new TextEncoder().encode(e),n=await jq(t,new CompressionStream(`deflate-raw`));return n.length<t.length?`D`+kq(n):`R`+kq(t)}async function Nq(e){let t=e.trim();if(!t)throw Error(`empty signal token`);let n=Aq(t.slice(1));if(t[0]===`D`)return new TextDecoder().decode(await jq(n,new DecompressionStream(`deflate-raw`)));if(t[0]===`R`)return new TextDecoder().decode(n);throw Error(`unknown signal codec tag: ${t[0]}`)}async function Pq(e){return Mq(JSON.stringify({k:`offer`,v:2,hub:e.hubInstanceId,name:e.hubName,sdp:e.sdp,sec:e.secret,language:e.language}))}async function Fq(e){try{let t=JSON.parse(await Nq(e.trim()));return t.k!==`answer`||typeof t.sdp!=`string`?null:{sdp:t.sdp,deviceName:typeof t.dev==`string`?t.dev:`Mobile device`,platform:typeof t.plat==`string`?t.plat:`web`,secret:typeof t.sec==`string`?t.sec:``}}catch{return null}}function Iq({open:e,onClose:t,onPaired:n}){let{t:r}=K(`settings`),[i,a]=(0,Q.useState)(`loading`),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(null),u=(0,Q.useRef)(null),d=(0,Q.useRef)(null),f=(0,Q.useRef)(null),p=(0,Q.useCallback)(()=>{f.current!=null&&(cancelAnimationFrame(f.current),f.current=null),d.current?.getTracks().forEach(e=>e.stop()),d.current=null},[]),m=(0,Q.useCallback)(()=>{p(),a(`loading`),s(``),l(null),t()},[t,p]),h=(0,Q.useCallback)(async e=>{let t=await Fq(e);if(!t){J.error(r(`pairWeb.notAnswer`));return}p(),a(`connecting`);try{let e=await fetch(`/api/mobile/webrtc/answer`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sdp:t.sdp})}),i=await e.json().catch(()=>({}));if(!e.ok||!i.ok)throw Error(`rejected`);a(`paired`),J.success(r(`pairWeb.pairedToast`)),n();let o=0,s=setInterval(()=>{n(),++o>=3&&(clearInterval(s),m())},1500)}catch{l(r(`pairWeb.answerRejected`)),a(`offer`)}},[r,p,n,m]);(0,Q.useEffect)(()=>{if(!e)return;let t=!1;return l(null),a(`loading`),(async()=>{try{let e=await fetch(`/api/mobile/webrtc/offer`,{method:`POST`});if(!e.ok)throw Error(`HTTP ${e.status}`);let n=await e.json(),r=await Pq({language:et(),hubInstanceId:n.hubInstanceId,hubName:n.hubName,sdp:n.sdp,secret:n.secret});t||(s(r),a(`offer`))}catch(e){t||(l(e.message),a(`offer`))}})(),()=>{t=!0}},[e]),(0,Q.useEffect)(()=>{if(i!==`scanning`)return;let e=d.current,t=u.current;if(!e||!t)return;t.srcObject=e,t.play().catch(()=>{});let n=document.createElement(`canvas`),r=n.getContext(`2d`,{willReadFrequently:!0});if(!r)return;let a=()=>{if(d.current){if(t.videoWidth){n.width=t.videoWidth,n.height=t.videoHeight,r.drawImage(t,0,0);let e=r.getImageData(0,0,n.width,n.height),i=(0,Oq.default)(e.data,e.width,e.height);if(i){h(i.data);return}}f.current=requestAnimationFrame(a)}};f.current=requestAnimationFrame(a)},[i,h]),(0,Q.useEffect)(()=>()=>p(),[p]);async function g(){if(l(null),!navigator.mediaDevices?.getUserMedia){J.error(r(`pairWeb.cameraFailed`,{message:`unsupported`}));return}try{d.current=await navigator.mediaDevices.getUserMedia({video:{facingMode:`environment`}}),a(`scanning`)}catch(e){J.error(r(`pairWeb.cameraFailed`,{message:e.message})),a(`offer`)}}return(0,$.jsx)(mr,{open:e,onOpenChange:e=>{e||m()},children:(0,$.jsxs)(fr,{movableResizable:!0,className:`max-w-md`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:r(`pairWeb.title`)}),(0,$.jsx)(ir,{children:r(`pairWeb.description`)})]}),c&&(0,$.jsx)(`p`,{className:`text-sm text-destructive`,children:r(`pairWeb.startFailed`,{error:c})}),i===`loading`&&(0,$.jsx)(`div`,{className:`h-56 bg-muted/30 rounded-lg animate-pulse`}),i===`offer`&&o&&(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-2`,children:[(0,$.jsx)(`div`,{className:`bg-white p-3 rounded-lg`,children:(0,$.jsx)(Dq,{value:o,size:220})}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:r(`pairWeb.showThenScan`)}),(0,$.jsx)(Z,{onClick:()=>void g(),className:`gap-2`,children:r(`pairWeb.scanAnswer`)}),(0,$.jsx)(`button`,{type:`button`,className:`text-xs text-accent-info underline`,onClick:()=>{navigator.clipboard?.writeText(o),J.success(r(`pairWeb.codeCopied`))},children:r(`pairWeb.copyCode`)})]}),i===`scanning`&&(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-2`,children:[(0,$.jsx)(`video`,{ref:u,playsInline:!0,className:`w-full max-h-72 rounded-lg bg-black`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:r(`pairWeb.scanning`)}),(0,$.jsx)(Z,{variant:`outline`,onClick:()=>{p(),a(`offer`)},children:r(`pairWeb.cancel`)})]}),i===`connecting`&&(0,$.jsx)(`p`,{className:`py-6 text-center text-muted-foreground`,children:r(`pairWeb.connecting`)}),i===`paired`&&(0,$.jsx)(`p`,{className:`py-6 text-center text-accent-success font-medium`,children:r(`pairWeb.paired`)})]})})}var Lq=typeof navigator<`u`&&/Win/i.test(navigator.platform);function Rq(e){return!e||e.length<16?e??`—`:`${e.slice(0,8)}…${e.slice(-8)}`}function zq(){let{t:e}=K(`settings`),[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(!1),l=(0,Q.useCallback)(async()=>{try{let e=await fetch(`/api/mobile/status`);e.ok&&n(await e.json())}catch{}},[]),u=(0,Q.useCallback)(async()=>{try{let e=await fetch(`/api/mobile/devices`);e.ok&&i((await e.json()).devices)}catch{}},[]);(0,Q.useEffect)(()=>{l(),u()},[l,u]);let{registerHandler:d,unregisterHandler:f}=tt();(0,Q.useEffect)(()=>{let e=`mobile-access-devices`;return d(e,e=>{let t=e?.type;(t===`mobile.device_paired`||t===`mobile.device_revoked`)&&u()}),()=>f(e)},[d,f,u]);async function p(){if(t){o(!0);try{let e=t.enabled?`disable`:`enable`,r=await fetch(`/api/mobile/${e}`,{method:`POST`});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error??`HTTP ${r.status}`)}n(await r.json())}catch(n){J.error(t.enabled?e(`mobile.disableFailed`,{message:n.message}):e(`mobile.enableFailed`,{message:n.message}))}finally{o(!1)}}}async function m(e){await fetch(`/api/mobile/devices/${e}`,{method:`DELETE`}).catch(()=>{}),u()}async function h(){if(window.confirm(e(`mobile.resetConfirm`))){o(!0);try{let t=await fetch(`/api/mobile/cert/rotate`,{method:`POST`});t.ok&&n(await t.json()),u(),J.success(e(`mobile.identityReset`))}finally{o(!1)}}}return t?(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:[(0,$.jsx)(Tc,{className:`h-3.5 w-3.5`}),` `,e(`mobile.heading`)]}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`mobile.description`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-border p-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium`,children:t.enabled?e(`mobile.accessOn`):e(`mobile.accessOff`)}),(0,$.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t.running?e(`mobile.listeningOnPort`,{port:t.port}):e(`mobile.notListening`)})]}),(0,$.jsx)(Z,{variant:t.enabled?`outline`:`default`,disabled:a,onClick:p,children:t.enabled?e(`mobile.turnOff`):e(`mobile.turnOn`)})]}),t.enabled&&t.running&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsxs)(Z,{onClick:()=>c(!0),className:`gap-2`,children:[(0,$.jsx)(D,{className:`h-4 w-4`}),` `,e(`mobile.pairWebDevice`)]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,$.jsx)(Cc,{className:`h-3.5 w-3.5 text-accent-success`}),(0,$.jsx)(`span`,{title:t.certFingerprint??``,children:Rq(t.certFingerprint)}),(0,$.jsx)(`button`,{type:`button`,className:`underline`,onClick:h,disabled:a,children:e(`mobile.reset`)})]})]}),Lq&&(0,$.jsx)(`p`,{className:`text-xs text-accent-warning`,children:e(`mobile.windowsFirewall`)}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground`,children:e(`mobile.pairedDevices`)}),r.filter(e=>!e.revoked).length===0?(0,$.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e(`mobile.noDevices`)}):r.filter(e=>!e.revoked).map(t=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between rounded-md bg-muted/30 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`text-sm`,children:[t.name,` `,(0,$.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`· `,t.platform]})]}),(0,$.jsx)(`button`,{type:`button`,"aria-label":e(`mobile.revokeDevice`,{name:t.name}),className:`text-muted-foreground hover:text-destructive`,onClick:()=>m(t.id),children:(0,$.jsx)(Rn,{className:`h-4 w-4`})})]},t.id))]})]}),(0,$.jsx)(Iq,{open:s,onClose:()=>c(!1),onPaired:u})]}):(0,$.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`})}var Bq=[`claude`,`codex`,`gemini`,`kimi`],Vq=[`claude`,`gemini`,`kimi`],Hq=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;function Uq(e){return`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[10px] font-medium transition-all duration-150 disabled:opacity-50 ${e?`border-accent-primary/50 bg-accent-primary/15 text-accent-primary shadow-[0_0_8px_-2px] shadow-accent-primary/30`:`border-border/60 bg-transparent text-muted-foreground/70 hover:border-border hover:text-foreground hover:bg-muted/30`}`}function Wq(){let{t:e}=K(`mcp`),[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)([]),[h,g]=(0,Q.useState)({}),[_,v]=(0,Q.useState)(null),y=(0,Q.useCallback)(async()=>{try{let e=await fetch(`${Xe}/api/external-mcp`);if(!e.ok)return;let t=await e.json();t?.settings?.servers&&t?.discovered?.orphanIds&&n(t)}catch{}},[]);(0,Q.useEffect)(()=>{y()},[y]);let b=(0,Q.useCallback)(async r=>{if(!t)return;let a=t;n({...t,settings:{version:1,servers:r}}),i(!0);try{let e=await fetch(`${Xe}/api/external-mcp`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({servers:r})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`HTTP ${e.status}`)}let t=await e.json();return t?.settings?.servers&&t?.discovered?.orphanIds&&n(t),!0}catch(t){n(a);let r=t.message;return J.error(e([`external.errors.${r}`,`external.updateFailed`])),!1}finally{i(!1)}},[t,e]),x=(0,Q.useMemo)(()=>{if(!t)return[];let{settings:e,discovered:n}=t,r=[],i=new Set(Object.keys(e.servers));for(let[t,i]of Object.entries(e.servers))r.push({id:t,name:i.name,source:i.source,sourceProvider:i.sourceProvider,providers:i.providers,orphan:n.orphanIds.includes(t),stored:!0});for(let e of Vq)for(let t of n[e])i.has(t.id)||r.push({id:t.id,name:t.name,source:`discovered`,sourceProvider:e,providers:{},orphan:!1,stored:!1});return r.sort((e,t)=>e.name.localeCompare(t.name)||e.id.localeCompare(t.id))},[t]),S=(0,Q.useCallback)((e,n)=>{if(!t)return;let r={...t.settings.servers},i=r[e.id],a={...i?.providers??{}};a[n]?delete a[n]:a[n]=!0,e.source===`discovered`&&Object.keys(a).length===0?delete r[e.id]:r[e.id]=i?{...i,providers:a}:{source:`discovered`,sourceProvider:e.sourceProvider,name:e.name,providers:a},b(r)},[t,b]),C=(0,Q.useCallback)(e=>{if(!t)return;let n={...t.settings.servers};delete n[e],b(n)},[t,b]),w=s.trim(),T=w!==``&&(!Hq.test(w)||w===`specrails`),E=w!==``&&!T&&`c:${w}`!==_&&!!t?.settings.servers[`c:${w}`],O=w!==``&&!T&&!E&&l.trim()!==``,k=(0,Q.useCallback)(()=>{o(!1),v(null),c(``),u(``),f(``),m([]),g({})},[]),A=(0,Q.useCallback)(()=>{v(null),c(``),u(``),f(``),m([]),g({}),o(!0)},[]),j=(0,Q.useCallback)(e=>{let n=t?.settings.servers[e];!n||n.source!==`custom`||!n.transport||(v(e),c(n.name),u(n.transport.command),f(n.transport.args.join(` `)),m(Object.entries(n.transport.env).map(([e,t])=>({key:e,value:t}))),g({...n.providers}),o(!0))},[t]),M=(0,Q.useCallback)(async()=>{if(!t||!O)return;let e=w,n={};for(let e of p){let t=e.key.trim();t&&(n[t]=e.value)}let r={};for(let[e,t]of Object.entries(h))t&&(r[e]=!0);let i={...t.settings.servers};_&&_!==`c:${e}`&&delete i[_],i[`c:${e}`]={source:`custom`,name:e,providers:r,transport:{command:l.trim(),args:d.trim()?d.trim().split(/\s+/):[],env:n}},await b(i)&&k()},[t,O,w,l,d,p,h,_,b,k]);return t?(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border p-3`,"data-testid":`external-mcp-card`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`text-xs font-semibold text-foreground flex items-center gap-1.5`,children:[(0,$.jsx)(D,{className:`h-3.5 w-3.5`}),` `,e(`external.heading`)]}),(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,className:`h-7 text-[11px]`,disabled:r,onClick:()=>a&&!_?o(!1):A(),"data-testid":`external-mcp-add`,children:[(0,$.jsx)(Pn,{className:`h-3 w-3`}),` `,e(`external.addCustom`)]})]}),(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80`,children:e(`external.description`)}),(0,$.jsxs)(`p`,{className:`flex items-start gap-1.5 text-[11px] text-accent-warning`,children:[(0,$.jsx)(zn,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),e(`external.warning`)]}),a&&(0,$.jsxs)(`div`,{className:`space-y-2.5 rounded-md border border-border/70 bg-muted/20 p-3`,"data-testid":`external-mcp-form`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{htmlFor:`ext-mcp-name`,className:`block text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e(`external.form.nameLabel`)}),(0,$.jsx)(`input`,{id:`ext-mcp-name`,autoFocus:!0,value:s,onChange:e=>c(e.target.value),placeholder:e(`external.form.name`),className:`w-full rounded-md border bg-background px-2 py-1 text-xs transition-colors ${T||E?`border-destructive/60 focus:outline-destructive`:`border-border`}`}),(T||E)&&(0,$.jsx)(`p`,{className:`text-[10px] text-destructive`,"data-testid":`external-mcp-name-hint`,children:e(T?`external.form.nameInvalid`:`external.form.nameTaken`)})]}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{htmlFor:`ext-mcp-command`,className:`block text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e(`external.form.commandLabel`)}),(0,$.jsx)(`input`,{id:`ext-mcp-command`,value:l,onChange:e=>u(e.target.value),placeholder:e(`external.form.command`),className:`w-full rounded-md border border-border bg-background px-2 py-1 text-xs font-mono`})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{htmlFor:`ext-mcp-args`,className:`block text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e(`external.form.argsLabel`)}),(0,$.jsx)(`input`,{id:`ext-mcp-args`,value:d,onChange:e=>f(e.target.value),placeholder:e(`external.form.args`),className:`w-full rounded-md border border-border bg-background px-2 py-1 text-xs font-mono`})]}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e(`external.form.envLabel`)}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>m(e=>[...e,{key:``,value:``}]),className:`inline-flex items-center gap-1 text-[10px] font-medium text-muted-foreground hover:text-foreground transition-colors`,"data-testid":`external-mcp-env-add`,children:[(0,$.jsx)(Pn,{className:`h-2.5 w-2.5`}),` `,e(`external.form.addVar`)]})]}),p.map((t,n)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`input`,{value:t.key,onChange:e=>m(t=>t.map((t,r)=>r===n?{...t,key:e.target.value}:t)),placeholder:e(`external.form.envKey`),"aria-label":`${e(`external.form.envKey`)} ${n+1}`,className:`w-2/5 rounded-md border border-border bg-background px-2 py-1 text-xs font-mono`}),(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`=`}),(0,$.jsx)(`input`,{value:t.value,onChange:e=>m(t=>t.map((t,r)=>r===n?{...t,value:e.target.value}:t)),placeholder:e(`external.form.envValue`),"aria-label":`${e(`external.form.envValue`)} ${n+1}`,className:`flex-1 rounded-md border border-border bg-background px-2 py-1 text-xs font-mono`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>m(e=>e.filter((e,t)=>t!==n)),className:`text-muted-foreground hover:text-destructive transition-colors`,"aria-label":`${e(`external.remove`)} ${n+1}`,children:(0,$.jsx)(Rn,{className:`h-3 w-3`})})]},n))]}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`span`,{className:`block text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e(`external.form.enableFor`)}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:Bq.map(e=>{let t=h[e]===!0;return(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":t,"aria-label":`custom · ${e}`,onClick:()=>g(t=>({...t,[e]:!t[e]})),className:Uq(t),"data-testid":`external-mcp-form-provider-${e}`,children:[t&&(0,$.jsx)(Sn,{className:`h-2.5 w-2.5`,strokeWidth:3}),e]},e)})})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-1.5 pt-0.5`,children:[(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,className:`h-7 text-[11px]`,onClick:k,children:e(`external.form.cancel`)}),(0,$.jsx)(Z,{size:`sm`,className:`h-7 text-[11px]`,disabled:r||!O,onClick:()=>void M(),"data-testid":`external-mcp-form-save`,children:e(`external.form.save`)})]})]}),x.length===0&&t.discovered.codexNative.length===0?(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground py-1`,children:e(`external.empty`)}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[x.map(t=>(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 rounded-md border border-border/60 px-2 py-1.5`,"data-testid":`external-mcp-row-${t.id}`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-foreground min-w-0 truncate`,children:t.name}),(0,$.jsx)(`span`,{className:`rounded-full bg-muted/60 px-1.5 py-px text-[10px] text-muted-foreground`,children:t.source===`custom`?e(`external.sourceCustom`):e(`external.sourceDiscovered`,{provider:t.sourceProvider})}),t.orphan&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-accent-warning/15 px-1.5 py-px text-[10px] text-accent-warning`,"data-testid":`external-mcp-orphan`,children:[(0,$.jsx)(zn,{className:`h-2.5 w-2.5`}),` `,e(`external.orphan`)]}),(0,$.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`flex items-center gap-1`,children:Bq.map(e=>{let n=t.providers[e]===!0;return(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":`${t.name} · ${e}`,disabled:r,onClick:()=>S(t,e),className:Uq(n),children:[n&&(0,$.jsx)(Sn,{className:`h-2.5 w-2.5`,strokeWidth:3}),e]},e)})}),t.stored&&t.source===`custom`&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>j(t.id),disabled:r,className:`text-muted-foreground hover:text-foreground`,"aria-label":e(`external.edit`),"data-testid":`external-mcp-edit-${t.id}`,children:(0,$.jsx)(jn,{className:`h-3 w-3`})}),t.stored&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>C(t.id),disabled:r,className:`text-muted-foreground hover:text-destructive`,"aria-label":e(`external.remove`),"data-testid":`external-mcp-remove-${t.id}`,children:(0,$.jsx)(Rn,{className:`h-3 w-3`})})]})]},t.id)),t.discovered.codexNative.map(t=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-md border border-border/40 px-2 py-1.5 opacity-70`,"data-testid":`external-mcp-codex-${t}`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-foreground min-w-0 truncate`,children:t}),(0,$.jsx)(`span`,{className:`rounded-full bg-muted/60 px-1.5 py-px text-[10px] text-muted-foreground`,children:e(`external.codexNative`)})]},`codex:${t}`))]})]}):(0,$.jsx)(`div`,{className:`h-16 bg-muted/30 rounded-lg animate-pulse`,"data-testid":`external-mcp-skeleton`})}async function Gq(e){try{if(navigator.clipboard&&typeof navigator.clipboard.writeText==`function`)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function Kq(e){return JSON.stringify({mcpServers:{specrails:{command:e.bridgeCommand}}},null,2)}function qq(){let{t:e}=K(`mcp`),[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),l=(0,Q.useCallback)(async()=>{try{let e=await fetch(`${Xe}/api/mcp-admin/status`);e.ok&&n(await e.json())}catch{}},[]),u=(0,Q.useCallback)(async()=>{try{let e=await fetch(`${Xe}/api/mcp-admin/config`);e.ok&&i(await e.json())}catch{}},[]);(0,Q.useEffect)(()=>{l(),u()},[l,u]);let d=(0,Q.useCallback)(async()=>{if(t){o(!0);try{let e=t.enabled?`disable`:`enable`,n=await fetch(`${Xe}/api/mcp-admin/${e}`,{method:`POST`});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}await l()}catch(n){J.error(t.enabled?e(`enable.disableFailed`,{message:n.message}):e(`enable.enableFailed`,{message:n.message}))}finally{o(!1)}}},[t,l,e]),f=(0,Q.useCallback)(async r=>{if(!t)return;o(!0);let i=!t.tiers[r];try{let e=await fetch(`${Xe}/api/mcp-admin/tiers`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({[r]:i})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`HTTP ${e.status}`)}let t=await e.json();n(e=>e&&{...e,tiers:t.tiers})}catch(t){J.error(e(`tiers.updateFailed`,{message:t.message}))}finally{o(!1)}},[t,e]),p=(0,Q.useCallback)(async()=>{r&&(await Gq(Kq(r))?(c(`config`),window.setTimeout(()=>c(e=>e===`config`?null:e),1500)):J.error(e(`config.copyFailed`)))},[r,e]),m=(0,Q.useCallback)(async()=>{try{let t=await fetch(`${Xe}/api/mcp-admin/token`);if(!t.ok)throw Error(`HTTP ${t.status}`);let{token:n}=await t.json();await Gq(n)?(c(`token`),window.setTimeout(()=>c(e=>e===`token`?null:e),1500)):J.error(e(`config.copyFailed`))}catch{J.error(e(`config.copyFailed`))}},[e]),h=(0,Q.useCallback)(async()=>{if(window.confirm(e(`token.regenerateConfirm`))){o(!0);try{let t=await fetch(`${Xe}/api/mcp-admin/regenerate-token`,{method:`POST`});if(!t.ok)throw Error(`HTTP ${t.status}`);await l(),J.success(e(`token.regenerated`))}catch(t){J.error(e(`token.regenerateFailed`,{message:t.message}))}finally{o(!1)}}},[l,e]);if(!t)return(0,$.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`});let g=[{key:`write`,label:e(`tiers.write`),help:e(`tiers.writeHelp`)},{key:`aiSpawn`,label:e(`tiers.aiSpawn`),help:e(`tiers.aiSpawnHelp`)},{key:`destructive`,label:e(`tiers.destructive`),help:e(`tiers.destructiveHelp`)}];return(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:[(0,$.jsx)(lc,{className:`h-3.5 w-3.5`}),` `,e(`heading`)]}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`explainer.what`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80`,children:e(`explainer.how`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-border p-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium`,children:t.enabled?e(`enable.on`):e(`enable.off`)}),(0,$.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[t.running?e(`enable.running`,{count:t.toolCount}):e(`enable.stopped`),t.enabled&&t.activeSessions>0&&(0,$.jsxs)($.Fragment,{children:[` · `,e(`enable.activeSessions`,{count:t.activeSessions})]})]})]}),(0,$.jsx)(Z,{variant:t.enabled?`outline`:`default`,disabled:a,onClick:()=>void d(),children:t.enabled?e(`enable.turnOff`):e(`enable.turnOn`)})]}),t.enabled&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border p-3`,children:[(0,$.jsx)(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`tiers.heading`)}),(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80`,children:e(`explainer.grants`)}),(0,$.jsxs)(`label`,{className:`flex items-start gap-2 opacity-70`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:!0,disabled:!0,className:`mt-0.5`,"aria-label":e(`tiers.read`)}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:e(`tiers.read`)}),(0,$.jsx)(`span`,{className:`block text-[10px] text-muted-foreground`,children:e(`tiers.readHelp`)})]})]}),g.map(e=>(0,$.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:t.tiers[e.key],disabled:a,onChange:()=>void f(e.key),className:`mt-0.5`,"aria-label":e.label}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:e.label}),(0,$.jsx)(`span`,{className:`block text-[10px] text-muted-foreground`,children:e.help})]})]},e.key))]}),r&&(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`config.heading`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void p(),className:`inline-flex h-7 items-center gap-1.5 rounded-lg border border-border bg-background px-2.5 text-[11px] font-medium text-muted-foreground hover:text-foreground`,"data-testid":`mcp-copy-config`,children:s===`config`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Sn,{className:`h-3 w-3 text-accent-success`}),` `,e(`config.configCopied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ls,{className:`h-3 w-3`}),` `,e(`config.copyConfig`)]})})]}),(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80`,children:e(`config.description`)}),(0,$.jsx)(`pre`,{className:`overflow-x-auto rounded-md bg-muted/40 p-2 text-[10px] leading-relaxed text-foreground`,children:Kq(r)})]}),(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border p-3`,children:[(0,$.jsx)(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`token.heading`)}),(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80`,children:e(`token.description`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground tabular-nums`,children:e(`token.hint`,{hint:t.tokenHint})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>void m(),className:`inline-flex h-7 items-center gap-1.5 rounded-lg border border-border bg-background px-2.5 text-[11px] font-medium text-muted-foreground hover:text-foreground`,"data-testid":`mcp-copy-token`,children:s===`token`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Sn,{className:`h-3 w-3 text-accent-success`}),` `,e(`token.tokenCopied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ls,{className:`h-3 w-3`}),` `,e(`token.copyToken`)]})}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void h(),disabled:a,className:`inline-flex h-7 items-center gap-1.5 rounded-lg border border-border bg-background px-2.5 text-[11px] font-medium text-muted-foreground hover:text-foreground disabled:opacity-50`,"data-testid":`mcp-regenerate-token`,children:[(0,$.jsx)(mc,{className:`h-3 w-3`}),` `,e(`token.regenerate`)]})]})]})]})]}),(0,$.jsx)(Wq,{})]})}var Jq=`specrails-os-notifications`,Yq={enabled:!0,filter:`all`};function Xq(){try{let e=localStorage.getItem(Jq);if(!e)return Yq;let t=JSON.parse(e);return{enabled:typeof t.enabled==`boolean`?t.enabled:Yq.enabled,filter:t.filter===`completed`||t.filter===`failed`?t.filter:Yq.filter}}catch{return Yq}}function Zq(e){localStorage.setItem(Jq,JSON.stringify(e))}function Qq({setActiveProjectId:e,projectsById:t}={}){let n=y(),r=(0,Q.useRef)(n);(0,Q.useEffect)(()=>{r.current=n},[n]);let i=(0,Q.useRef)(e);(0,Q.useEffect)(()=>{i.current=e},[e]);let{uiMode:a}=MN(),o=(0,Q.useRef)(a);(0,Q.useEffect)(()=>{o.current=a},[a]);let s=(0,Q.useCallback)((e,t)=>{if(o.current===`agent`){e&&i.current&&i.current(e),aO({projectId:e,jobId:t});return}e&&i.current?(i.current(e),setTimeout(()=>{r.current(`/jobs/${t}`)},100)):r.current(`/jobs/${t}`)},[]),c=(0,Q.useRef)(t);(0,Q.useEffect)(()=>{c.current=t},[t]);let l=(0,Q.useRef)(new Map),u=(0,Q.useRef)(new Map),{registerHandler:d,unregisterHandler:f}=tt(),p=(0,Q.useCallback)(e=>{let t=e;if(!t)return;if(t.type===`job.stuck`&&typeof t.jobId==`string`){let e=Array.isArray(t.actions)?t.actions.filter(e=>e===`stop`):[];h(t.jobId,t.projectId??null,t.staleMs??0,e);return}if(t.type===`loop.provider_limit`&&typeof t.runId==`string`){m(t.runId,t.projectId??null,typeof t.provider==`string`?t.provider:``,typeof t.resetsAt==`string`&&t.resetsAt?t.resetsAt:null,typeof t.message==`string`?t.message:``);return}if(t.type!==`queue`||!Array.isArray(t.jobs))return;let n=t.projectId??null;for(let e of t.jobs){let t=l.current.get(e.id),r=e.status;n&&u.current.set(e.id,n),t===`running`&&(r===`completed`||r===`failed`)&&_(e,n),l.current.set(e.id,r)}},[]);function m(e,t,n,r,i){let a=Xq();if(!a.enabled||a.filter===`completed`)return;let o=t?c.current?.get(t)??``:``,s=n?n.charAt(0).toUpperCase()+n.slice(1):`AI`,l=r?Je.t(`commands:notifications.providerLimitBody`,{provider:s,resetsAt:r}):Je.t(`commands:notifications.providerLimitBodyNoReset`,{provider:s}),u=Je.t(`commands:notifications.providerLimit`);J.error(u,{id:`provider-limit:${e}`,description:`${o?`[${o}] `:``}${l}${i?` · ${i}`:``}`,duration:6e4}),!(typeof Notification>`u`)&&Notification.permission===`granted`&&(()=>{let t=new Notification(u,{body:o?`[${o}] ${l}`:l,tag:`specrails-provider-limit:${e}`});t.onclick=()=>{window.focus(),t.close()}})()}function h(e,t,n,r=[]){let i=Xq();if(!i.enabled||i.filter===`completed`)return;let a=Math.max(1,Math.round(n/6e4)),o=t?c.current?.get(t)??``:``,l=Je.t(`commands:notifications.jobStuckBody`,{count:a});if(t&&r.includes(`stop`)&&J.warning(Je.t(`commands:notifications.jobStuck`),{id:`job-stuck:${e}`,description:o?`[${o}] ${l}`:l,duration:2e4,action:{label:Je.t(`commands:notifications.jobStuckStop`),onClick:()=>{g(t,e)}}}),typeof Notification>`u`)return;function u(){let n=new Notification(Je.t(`commands:notifications.jobStuck`),{body:o?`[${o}] ${l}`:l,tag:`specrails-job-stuck:${e}`});n.onclick=()=>{window.focus(),s(t,e),n.close()}}Notification.permission===`granted`?u():Notification.permission==="default"&&Notification.requestPermission().then(e=>{e===`granted`&&u()})}async function g(e,t){try{let n=await fetch(`/api/projects/${e}/jobs/${t}/cancel`,{method:`POST`});if(!n.ok)throw Error(`HTTP ${n.status}`);J.success(Je.t(`commands:notifications.jobStuckStopped`),{id:`job-stuck:${t}`})}catch{J.error(Je.t(`commands:notifications.jobStuckStopFailed`),{id:`job-stuck:${t}`})}}function _(e,t){if(typeof Notification>`u`||typeof document<`u`&&!document.hidden)return;let n=Xq();if(!n.enabled||n.filter===`completed`&&e.status!==`completed`||n.filter===`failed`&&e.status!==`failed`)return;function r(){let n=e.status===`completed`?Je.t(`commands:notifications.jobCompleted`):Je.t(`commands:notifications.jobFailed`),r=t?c.current?.get(t)??``:``,i=e.command?e.command.slice(0,80):Je.t(`commands:notifications.unknownCommand`),a=r?`[${r}] ${i}`:i,o=new Notification(n,{body:a,tag:`specrails-job:${e.id}:${e.status}`}),l=e.id,u=t;o.onclick=()=>{window.focus(),s(u,l),o.close()}}Notification.permission===`granted`?r():Notification.permission==="default"&&Notification.requestPermission().then(e=>{e===`granted`&&r()})}(0,Q.useLayoutEffect)(()=>(d(`os-notifications`,p),()=>f(`os-notifications`)),[p,d,f])}var $q=[{value:`job.completed`,labelKey:`webhooks.eventJobCompleted`},{value:`job.failed`,labelKey:`webhooks.eventJobFailed`},{value:`daily_budget_exceeded`,labelKey:`webhooks.eventDailyBudgetExceeded`}];function eJ({project:e,onRemove:t}){let{t:n}=K(`settings`);return(0,$.jsxs)(`div`,{className:`flex items-center gap-3 p-2.5 rounded-md border border-border`,children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium truncate`,children:e.name}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground truncate`,children:e.path})]}),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,className:`h-6 px-2 text-[10px] text-muted-foreground hover:text-destructive shrink-0`,onClick:()=>t(e.id),children:n(`common:actions.remove`)})]})}var tJ=[{id:`appearance`,icon:ec,labelKey:`desktop.nav.appearance`},{id:`effects`,icon:Ln,labelKey:`desktop.nav.effects`},{id:`specrailsAgents`,icon:fs,labelKey:`desktop.nav.specrailsAgents`},{id:`code`,icon:is,labelKey:`desktop.nav.code`},{id:`terminal`,icon:Ec,labelKey:`desktop.nav.terminal`},{id:`updates`,icon:mc,labelKey:`desktop.nav.updates`},{id:`mobile`,icon:Tc,labelKey:`desktop.nav.mobile`},{id:`mcp`,icon:Vo,labelKey:`desktop.nav.mcp`},{id:`projects`,icon:Ts,labelKey:`desktop.nav.projects`},{id:`advanced`,icon:wc,labelKey:`desktop.nav.advanced`},{id:`webhooks`,icon:Ic,labelKey:`desktop.nav.webhooks`},{id:`about`,icon:Rs,labelKey:`desktop.nav.about`}];function nJ({open:e,onClose:t,onOpenOnboarding:n,initialSection:r=`appearance`}){let{t:i}=K(`settings`),{projects:a,removeProject:o}=pt(),[s,c]=(0,Q.useState)(`appearance`);(0,Q.useEffect)(()=>{e&&c(r)},[e,r]);let l=e=>X(`space-y-5`,s===e?``:`hidden`),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!0),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)([]),[w,T]=(0,Q.useState)(``),[E,D]=(0,Q.useState)(``),[O,k]=(0,Q.useState)([`job.completed`,`job.failed`]),[A,j]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(()=>Xq().enabled),[P,F]=(0,Q.useState)(()=>Xq().filter);function I(e){N(e),Zq({enabled:e,filter:P}),J.success(i(e?`notifications.enabledToast`:`notifications.disabledToast`))}function L(e){F(e),Zq({enabled:M,filter:e})}let R=(0,Q.useCallback)(async()=>{try{let e=await fetch(`/api/webhooks`);if(e.ok){let t=await e.json();C(t.webhooks)}}catch{}},[]);(0,Q.useEffect)(()=>{if(!e)return;p(!0);async function t(){try{let e=await fetch(`/api/settings`);if(e.ok){let t=await e.json();d(t),h(t.costAlertThresholdUsd==null?``:String(t.costAlertThresholdUsd))}}catch{}finally{p(!1)}}t(),R()},[e,R]),(0,Q.useEffect)(()=>{e&&fetch(`/api/budget`).then(e=>e.json()).then(e=>{e.desktopDailyBudgetUsd==null?y(``):y(String(e.desktopDailyBudgetUsd))}).catch(()=>{})},[e]);async function z(){_(!0);try{let e=m.trim()===``?null:parseFloat(m);if(e!==null&&(isNaN(e)||e<=0)){J.error(i(`budget.invalidNumber`));return}(await fetch(`/api/settings`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({costAlertThresholdUsd:e})})).ok?J.success(e==null?i(`desktop.costAlertsDisabled`):i(`budget.alertSet`,{amount:e})):J.error(i(`budget.saveThresholdFailed`))}catch{J.error(i(`budget.saveThresholdFailed`))}finally{_(!1)}}async function B(){x(!0);try{let e=v.trim()===``?null:parseFloat(v);if(e!==null&&(isNaN(e)||e<=0)){J.error(i(`budget.invalidNumber`));return}(await fetch(`/api/budget`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({desktopDailyBudgetUsd:e})})).ok?J.success(e==null?i(`desktop.dailyBudgetRemoved`):i(`desktop.dailyBudgetSet`,{amount:e})):J.error(i(`desktop.dailyBudgetSaveFailed`))}catch{J.error(i(`desktop.dailyBudgetSaveFailed`))}finally{x(!1)}}async function V(e){try{await o(e),J.success(i(`desktop.projectRemoved`))}catch(e){J.error(i(`desktop.projectRemoveFailed`),{description:e.message})}}async function H(){if(!w.trim()){J.error(i(`webhooks.urlRequired`));return}if(O.length===0){J.error(i(`webhooks.selectEvent`));return}j(!0);try{let e=await fetch(`/api/webhooks`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({url:w.trim(),secret:E.trim(),events:O})});if(e.ok)J.success(i(`webhooks.added`)),T(``),D(``),k([`job.completed`,`job.failed`]),await R();else{let t=await e.json();J.error(t.error??i(`webhooks.addFailed`))}}catch{J.error(i(`webhooks.addFailed`))}finally{j(!1)}}async function U(e,t){try{await fetch(`/api/webhooks/${e}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:t})}),await R()}catch{J.error(i(`webhooks.updateFailed`))}}async function W(e){try{(await fetch(`/api/webhooks/${e}`,{method:`DELETE`})).ok&&(J.success(i(`webhooks.removed`)),await R())}catch{J.error(i(`webhooks.removeFailed`))}}async function ee(e){try{(await fetch(`/api/webhooks/${e}/test`,{method:`POST`})).ok&&J.success(i(`webhooks.testPingSent`))}catch{J.error(i(`webhooks.testPingFailed`))}}function te(e){k(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}return(0,$.jsx)(mr,{open:e,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(fr,{movableResizable:!0,className:`flex max-w-5xl w-[92vw] h-[82vh] flex-col overflow-hidden`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsxs)(sr,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Sc,{className:`w-4 h-4`}),i(`desktop.title`)]}),(0,$.jsx)(ir,{children:i(`desktop.description`)})]}),f?(0,$.jsxs)(`div`,{className:`space-y-3 py-2`,children:[(0,$.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`}),(0,$.jsx)(`div`,{className:`h-16 bg-muted/30 rounded-lg animate-pulse`})]}):(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-5 py-2`,children:[(0,$.jsx)(`nav`,{className:`w-40 shrink-0 space-y-0.5 overflow-y-auto border-r border-border pr-2`,children:tJ.map(e=>{if(e.id===`mcp`&&!oe)return null;let t=e.icon;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>c(e.id),className:X(`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left text-xs transition-colors`,s===e.id?`bg-accent-primary/15 font-medium text-foreground`:`text-muted-foreground hover:bg-muted/40 hover:text-foreground`),children:[(0,$.jsx)(t,{className:`w-3.5 h-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:i(e.labelKey)})]},e.id)})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-y-auto pr-1`,children:[(0,$.jsxs)(`div`,{className:l(`appearance`),children:[(0,$.jsx)(QG,{}),(0,$.jsx)(oK,{})]}),(0,$.jsx)(`div`,{className:l(`effects`),children:(0,$.jsx)(XG,{})}),(0,$.jsx)(`div`,{className:l(`specrailsAgents`),children:(0,$.jsx)(OK,{children:(0,$.jsx)(YG,{})})}),(0,$.jsx)(`div`,{className:l(`code`),children:(0,$.jsx)(sK,{})}),(0,$.jsxs)(`div`,{className:l(`updates`),children:[(0,$.jsx)(eq,{}),(0,$.jsx)(AK,{})]}),(0,$.jsx)(`div`,{className:l(`mobile`),children:(0,$.jsx)(zq,{})}),oe&&(0,$.jsx)(`div`,{className:l(`mcp`),children:(0,$.jsx)(qq,{})}),(0,$.jsx)(`div`,{className:l(`projects`),children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:i(`desktop.registeredProjects`)}),a.length===0?(0,$.jsx)(`div`,{className:`rounded-md border border-dashed border-border p-4 text-center`,children:(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`desktop.noProjects`)})}):(0,$.jsx)(`div`,{className:`space-y-1.5`,children:a.map(e=>(0,$.jsx)(eJ,{project:e,onRemove:V},e.id))})]})}),(0,$.jsxs)(`div`,{className:l(`advanced`),children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:i(`desktop.budgetAlertsHeading`)}),(0,$.jsxs)(`div`,{className:`rounded-md border border-border p-3 space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium`,children:i(`desktop.dailyBudgetLabel`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:i(`desktop.dailyBudgetHelper`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Jj,{type:`number`,min:`0`,step:`0.01`,value:v,onChange:e=>y(e.target.value),placeholder:i(`desktop.dailyBudgetPlaceholder`),className:`h-7 text-xs font-mono`}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs shrink-0`,disabled:b,onClick:()=>void B(),children:i(`common:actions.save`)})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium`,children:i(`budget.perJobLabel`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:i(`desktop.perJobHelper`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Jj,{type:`number`,min:`0`,step:`0.01`,value:m,onChange:e=>h(e.target.value),placeholder:i(`budget.perJobPlaceholder`),className:`h-7 text-xs font-mono`}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs shrink-0`,disabled:g,onClick:z,children:i(`common:actions.save`)})]})]})]})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:i(`notifications.heading`)}),(0,$.jsxs)(`div`,{className:`rounded-md border border-border p-3 space-y-3`,children:[(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:i(`notifications.description`)}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:M,onChange:e=>I(e.target.checked),className:`w-3.5 h-3.5`,"data-testid":`notif-toggle`}),(0,$.jsx)(zo,{className:`w-3.5 h-3.5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`text-xs`,children:i(`notifications.enableLabel`)})]}),M&&(0,$.jsxs)(`div`,{className:`space-y-1.5 pl-6`,children:[(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:i(`notifications.notifyOn`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:[{value:`all`,label:i(`notifications.filterAll`)},{value:`completed`,label:i(`notifications.filterCompleted`)},{value:`failed`,label:i(`notifications.filterFailed`)}].map(({value:e,label:t})=>(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[10px] cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`radio`,name:`notif-filter`,checked:P===e,onChange:()=>L(e),className:`w-3 h-3`}),t]},e))})]})]})]})]}),(0,$.jsx)(`div`,{className:l(`webhooks`),children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:i(`webhooks.heading`)}),(0,$.jsxs)(`div`,{className:`rounded-md border border-border p-3 space-y-3`,children:[(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:(0,$.jsx)(lt,{ns:`settings`,i18nKey:`webhooks.description`,components:{code:(0,$.jsx)(`code`,{className:`font-mono`})}})}),S.length>0&&(0,$.jsx)(`div`,{className:`space-y-1.5`,children:S.map(e=>{let t=(()=>{try{return JSON.parse(e.events)}catch{return[]}})();return(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-border p-2`,children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 space-y-0.5`,children:[(0,$.jsx)(`p`,{className:`text-xs font-mono truncate`,children:e.url}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:t.join(`, `)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,$.jsx)(`button`,{onClick:()=>void U(e.id,!e.enabled),className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${e.enabled?`bg-green-500/10 aurora-light:bg-accent-success/10 text-green-600 aurora-light:text-accent-success dark:text-green-400`:`bg-muted text-muted-foreground`}`,title:e.enabled?i(`webhooks.disable`):i(`webhooks.enable`),children:e.enabled?i(`webhooks.statusOn`):i(`webhooks.statusOff`)}),(0,$.jsx)(`button`,{onClick:()=>void ee(e.id),className:`text-muted-foreground hover:text-foreground p-0.5`,title:i(`webhooks.sendTestPing`),children:(0,$.jsx)(wn,{className:`w-3 h-3`})}),(0,$.jsx)(`button`,{onClick:()=>void W(e.id),className:`text-muted-foreground hover:text-destructive p-0.5`,title:i(`common:actions.remove`),children:(0,$.jsx)(Rn,{className:`w-3 h-3`})})]})]},e.id)})}),(0,$.jsxs)(`div`,{className:`space-y-2 border-t border-border pt-2`,children:[(0,$.jsx)(`p`,{className:`text-[10px] font-medium text-muted-foreground`,children:i(`webhooks.addHeading`)}),(0,$.jsx)(Jj,{value:w,onChange:e=>T(e.target.value),placeholder:`https://hooks.example.com/...`,className:`h-7 text-xs font-mono`}),(0,$.jsx)(Jj,{value:E,onChange:e=>D(e.target.value),placeholder:i(`webhooks.secretPlaceholder`),className:`h-7 text-xs font-mono`}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:$q.map(({value:e,labelKey:t})=>(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[10px] cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:O.includes(e),onChange:()=>te(e),className:`w-3 h-3`}),i(t)]},e))}),(0,$.jsxs)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs w-full`,disabled:A||!w.trim(),onClick:()=>void H(),children:[(0,$.jsx)(Pn,{className:`w-3 h-3 mr-1`}),i(`webhooks.addButton`)]})]})]})]})}),(0,$.jsx)(`div`,{className:l(`about`),children:n&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:i(`desktop.onboardingHeading`)}),(0,$.jsx)(`div`,{className:`rounded-md border border-border p-3`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium`,children:i(`desktop.platformTour`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:i(`desktop.platformTourDescription`)})]}),(0,$.jsxs)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs shrink-0`,onClick:n,"data-testid":`replay-onboarding`,children:[(0,$.jsx)(js,{className:`w-3 h-3 mr-1`}),i(`desktop.replayTour`)]})]})})]})}),(0,$.jsx)(`div`,{className:l(`terminal`),children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:i(`desktop.terminalPanelHeading`)}),(0,$.jsx)(BW,{mode:`desktop`})]})}),(0,$.jsx)(`div`,{className:l(`about`),children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:i(`desktop.infoHeading`)}),(0,$.jsxs)(`div`,{className:`rounded-md border border-border p-3 space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i(`desktop.infoPort`)}),(0,$.jsx)(`span`,{className:`font-mono`,children:u?.port??4200})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i(`desktop.infoProjects`)}),(0,$.jsx)(`span`,{className:`font-mono`,children:a.length})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i(`desktop.infoDb`)}),(0,$.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:`~/.specrails/desktop.sqlite`})]})]})]})})]})]})]})})}var rJ=[{keys:`?`,descriptionKey:`shortcuts.items.showCheatsheet`,category:`general`},{keys:`Esc`,descriptionKey:`shortcuts.items.closeModal`,category:`general`},{keys:`⌘B`,descriptionKey:`shortcuts.items.toggleRightSidebar`,category:`general`},{keys:`⌥⌘B`,descriptionKey:`shortcuts.items.toggleLeftSidebar`,category:`general`},{keys:`⌘J`,descriptionKey:`shortcuts.items.toggleTerminal`,category:`general`},...xe?[{keys:`⌘⇧A`,descriptionKey:`shortcuts.items.toggleAgent`,category:`general`}]:[],{keys:je?`⌘1–5`:`⌘1–4`,descriptionKey:je?`shortcuts.items.navigateProjectPageWithAgents`:`shortcuts.items.navigateProjectPage`,category:`general`},{keys:`⌥⌘1–9`,descriptionKey:`shortcuts.items.switchProject`,category:`general`},{keys:`G D`,descriptionKey:`shortcuts.items.goDashboard`,category:`navigation`},{keys:`G J`,descriptionKey:`shortcuts.items.goActivity`,category:`navigation`},{keys:`G A`,descriptionKey:`shortcuts.items.goAnalytics`,category:`navigation`},{keys:`G S`,descriptionKey:`shortcuts.items.goSettings`,category:`navigation`},{keys:`J`,descriptionKey:`shortcuts.items.nextItem`,category:`actions`},{keys:`K`,descriptionKey:`shortcuts.items.prevItem`,category:`actions`}];function iJ(e){let t=e.target;if(!t)return!1;let n=t.tagName;return!!(n===`INPUT`||n===`TEXTAREA`||n===`SELECT`||t.isContentEditable)}function aJ(e){let t=e.target;return!t||typeof t.closest!=`function`?!1:!!t.closest(`[role="dialog"]`)}function oJ(e){let t=e.target;return!t||typeof t.closest!=`function`?!1:!!t.closest(`.specrails-xterm-container, .xterm`)}function sJ({onOpenCheatsheet:e,onListNavigate:t,onToggleLeftSidebar:n,onToggleRightSidebar:r,onSwitchProject:i,onSwitchProjectPage:a,onToggleTerminalPanel:o,onToggleAgentChat:s}){let c=y(),l=p(),u=(0,Q.useRef)(null),d=(0,Q.useRef)(null),f=(0,Q.useRef)(e);f.current=e;let m=(0,Q.useRef)(t);m.current=t;let h=(0,Q.useRef)(n);h.current=n;let g=(0,Q.useRef)(r);g.current=r;let _=(0,Q.useRef)(i);_.current=i;let v=(0,Q.useRef)(a);v.current=a;let b=(0,Q.useRef)(o);b.current=o;let x=(0,Q.useRef)(s);x.current=s;let S=(0,Q.useRef)(l);S.current=l,(0,Q.useEffect)(()=>{function e(e){if((e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&e.code===`KeyJ`){if(aJ(e))return;e.preventDefault(),b.current?.();return}if((e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&e.code===`KeyA`){if(aJ(e))return;e.preventDefault(),x.current?.();return}if(iJ(e)||oJ(e)||aJ(e))return;if((e.metaKey||e.ctrlKey)&&!e.altKey&&e.code===`KeyB`){e.preventDefault(),g.current?.();return}if((e.metaKey||e.ctrlKey)&&e.altKey&&e.code===`KeyB`){e.preventDefault(),h.current?.();return}if((e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey){let t=e.code.match(/^Digit([1-9])$/);if(t){e.preventDefault(),v.current?.(parseInt(t[1],10));return}}if((e.metaKey||e.ctrlKey)&&e.altKey&&!e.shiftKey){let t=e.code.match(/^Digit([1-9])$/);if(t){e.preventDefault(),_.current?.(parseInt(t[1],10));return}}if(e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key;if(u.current===`g`){d.current&&clearTimeout(d.current),u.current=null;let n=t.toUpperCase(),r={D:`/`,P:`/`,J:`/activity`,A:`/analytics`,S:`/settings`};if(r[n]){e.preventDefault(),c(r[n]);return}return}if(t===`?`){e.preventDefault(),f.current();return}if(t===`g`){e.preventDefault(),u.current=`g`,d.current=setTimeout(()=>{u.current=null},800);return}if(t===`j`){m.current?.(`down`);return}if(t===`k`){m.current?.(`up`);return}}return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e),d.current&&clearTimeout(d.current)}},[c])}function cJ(){let[e,t]=(0,Q.useState)(!1);return{cheatsheetOpen:e,setCheatsheetOpen:t,openCheatsheet:(0,Q.useCallback)(()=>t(!0),[]),closeCheatsheet:(0,Q.useCallback)(()=>t(!1),[])}}var lJ={general:`shortcuts.categories.general`,navigation:`shortcuts.categories.navigation`,actions:`shortcuts.categories.actions`},uJ=[`general`,`navigation`,`actions`];function dJ({children:e}){return(0,$.jsx)(`kbd`,{className:`inline-flex items-center justify-center min-w-[1.5rem] h-6 px-1.5 rounded border border-border/50 bg-card/80 font-mono text-xs text-foreground`,children:e})}function fJ({shortcut:e}){let{t}=K(`commands`),n=mW(e.keys).split(` `);return(0,$.jsxs)(`div`,{className:`flex items-center justify-between py-1.5`,children:[(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:t(e.descriptionKey)}),(0,$.jsx)(`div`,{className:`flex items-center gap-1 ml-4 shrink-0`,children:n.map((e,t)=>(0,$.jsx)(dJ,{children:e},t))})]})}function pJ({open:e,onOpenChange:t}){let{t:n}=K(`commands`),r=uJ.map(e=>({category:e,label:n(lJ[e]),shortcuts:rJ.filter(t=>t.category===e)})).filter(e=>e.shortcuts.length>0);return(0,$.jsx)(mr,{open:e,onOpenChange:t,children:(0,$.jsxs)(fr,{movableResizable:!0,className:`max-w-md`,"data-testid":`shortcuts-cheatsheet`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:n(`shortcuts.title`)}),(0,$.jsx)(ir,{children:(0,$.jsxs)(lt,{i18nKey:`shortcuts.subtitle`,ns:`commands`,children:[`Press `,(0,$.jsx)(dJ,{children:`?`}),` anywhere to toggle this panel`]})})]}),(0,$.jsx)(`div`,{className:`space-y-4 mt-2`,children:r.map(e=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wider text-accent-primary mb-2`,children:e.label}),(0,$.jsx)(`div`,{className:`divide-y divide-border/30`,children:e.shortcuts.map(e=>(0,$.jsx)(fJ,{shortcut:e},e.keys))})]},e.category))})]})})}function mJ(){return typeof window<`u`&&`__TAURI_INTERNALS__`in window}function hJ(){return mJ()&&/mac/i.test(navigator.platform)}function gJ({onClick:e,icon:t,hoverColor:n=`var(--color-accent)`,hoverTextColor:r=`var(--color-accent-foreground)`,ariaLabel:i}){let[a,o]=(0,Q.useState)(!1);return(0,$.jsx)(`button`,{onClick:e,"aria-label":i,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{width:34,height:28,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:7,border:`none`,cursor:`pointer`,background:a?n:`transparent`,color:a?r:`var(--color-muted-foreground)`,transition:`background 0.12s ease, color 0.12s ease`,WebkitAppRegion:`no-drag`},children:t})}function _J({projectName:e,hidden:t=!1}){let{t:n}=K(`nav`),[r,i]=(0,Q.useState)(!1);function a(){window.dispatchEvent(new KeyboardEvent(`keydown`,{key:`k`,metaKey:!0,bubbles:!0}))}return(0,$.jsxs)(`button`,{onClick:a,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),"aria-label":n(`titleBar.searchShortcut`),"aria-hidden":t||void 0,tabIndex:t?-1:void 0,style:{position:`absolute`,left:`50%`,top:`50%`,transform:`translate(-50%, -50%) scale(${t?.96:1})`,width:`40%`,maxWidth:360,minWidth:160,height:20,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:5,paddingLeft:8,paddingRight:8,borderRadius:9999,border:`1px solid color-mix(in srgb, var(--color-border) 70%, transparent)`,cursor:`pointer`,background:r?`color-mix(in srgb, var(--color-accent) 82%, transparent)`:`color-mix(in srgb, var(--color-surface) 72%, transparent)`,color:e?`var(--color-foreground)`:`var(--color-muted-foreground)`,fontSize:12,fontWeight:400,letterSpacing:0,opacity:+!t,pointerEvents:t?`none`:`auto`,transition:`background 0.12s ease, opacity 0.22s ease, transform 0.22s ease`,WebkitAppRegion:`no-drag`,overflow:`hidden`,whiteSpace:`nowrap`},children:[(0,$.jsx)(In,{size:11,style:{flexShrink:0,opacity:e?.72:.48}}),(0,$.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e??n(`titleBar.searchPlaceholder`)})]})}function vJ(){return mJ()?hJ()?(0,$.jsx)(yJ,{}):(0,$.jsx)(bJ,{}):null}function yJ(){let{projects:e,activeProjectId:t}=pt(),{uiMode:n}=MN();return(0,$.jsx)(`div`,{"data-tauri-drag-region":!0,style:{position:`relative`,height:28,minHeight:28,background:`var(--color-background-deep)`,display:`flex`,alignItems:`center`,userSelect:`none`,flexShrink:0,borderBottom:`1px solid var(--color-border)`},children:(0,$.jsx)(_J,{projectName:(e.find(e=>e.id===t)??null)?.name??null,hidden:n===`agent`})})}function bJ(){let{t:e}=K(`nav`),{projects:t,activeProjectId:n}=pt(),{uiMode:r}=MN(),i=t.find(e=>e.id===n)??null,a=(0,Q.useMemo)(()=>_P(),[]),[o,s]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=!1,t=0,n,r=async()=>{let n=++t;try{let r=await a.isMaximized?.();!e&&n===t&&s(r===!0)}catch{}};return r(),a.onResized?.(()=>{r()}).then(t=>{e?t():n=t}).catch(()=>{}),()=>{e=!0,n?.()}},[a]);let c=(0,Q.useCallback)(()=>{a.minimize()},[a]),l=(0,Q.useCallback)(()=>{a.toggleMaximize()},[a]),u=(0,Q.useCallback)(()=>{a.close()},[a]);return(0,$.jsxs)(`div`,{"data-tauri-drag-region":!0,style:{position:`relative`,height:36,minHeight:36,background:`var(--color-background-deep)`,display:`flex`,alignItems:`center`,justifyContent:`space-between`,padding:`0 10px`,userSelect:`none`,flexShrink:0,borderBottom:`1px solid var(--color-border)`},children:[(0,$.jsx)(_J,{projectName:i?.name??null,hidden:r===`agent`}),(0,$.jsx)(`div`,{"data-tauri-drag-region":!0,style:{minWidth:116,height:`100%`}}),(0,$.jsxs)(`div`,{style:{minWidth:116,display:`flex`,justifyContent:`flex-end`,gap:2,alignItems:`center`,WebkitAppRegion:`no-drag`},children:[(0,$.jsx)(gJ,{onClick:c,icon:(0,$.jsx)(Ys,{size:14,strokeWidth:1.8}),ariaLabel:e(`titleBar.minimizeWindow`)}),(0,$.jsx)(gJ,{onClick:l,icon:o?(0,$.jsx)(ls,{size:12,strokeWidth:1.8}):(0,$.jsx)(Nn,{size:12,strokeWidth:1.8}),ariaLabel:e(o?`titleBar.restoreWindow`:`titleBar.maximizeWindow`)}),(0,$.jsx)(gJ,{onClick:u,icon:(0,$.jsx)(Vn,{size:15,strokeWidth:1.8}),hoverColor:`var(--color-destructive)`,hoverTextColor:`var(--color-destructive-foreground)`,ariaLabel:e(`titleBar.closeWindow`)})]})]})}var xJ=`アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン0123456789ABCDEF`,SJ=16,CJ=SJ,wJ=SJ*1.1,TJ=180,EJ=340,DJ=.07,OJ=.22,kJ=18,AJ=600,jJ=48,MJ=160,NJ=360;function PJ(){return xJ[Math.floor(Math.random()*61)]??` `}function FJ(e){return{head:-Math.random()*Math.max(e,12),speed:DJ+Math.random()*(OJ-DJ),glyphs:Array.from({length:kJ},()=>PJ()),nextSwapAt:0}}function IJ(){let e=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(typeof window>`u`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return;let t=e.current;if(!t)return;let n=t.getContext(`2d`,{alpha:!0});if(!n)return;let r=t,i=n,a=[],o=null,s=[],c=0,l=0,u=!document.hidden;function d(){let e=window.devicePixelRatio||1,t=window.innerWidth,n=window.innerHeight;r.width=Math.max(1,Math.floor(t*e)),r.height=Math.max(1,Math.floor(n*e)),r.style.width=`${t}px`,r.style.height=`${n}px`,i.setTransform(e,0,0,e,0,0),i.font=`${SJ}px "DM Mono", "JetBrains Mono", "Fira Code", ui-monospace, monospace`,i.textBaseline=`top`;let o=Math.ceil(t/CJ),s=Math.ceil(n/wJ);if(a.length===0)a=Array.from({length:o},()=>FJ(s));else if(a.length<o){let e=Array.from({length:o-a.length},()=>FJ(s));a=a.concat(e)}else a.length>o&&(a=a.slice(0,o))}function f(e){let t=performance.now();o&&(Math.abs(o.x-e.clientX)>=2||Math.abs(o.y-e.clientY)>=2)&&(s.push({x:o.x,y:o.y,t}),s.length>jJ&&s.splice(0,s.length-jJ)),o={x:e.clientX,y:e.clientY}}function p(){o=null}function m(){u=!document.hidden,u?(l=0,c=requestAnimationFrame(h)):cancelAnimationFrame(c)}function h(e){if(!u)return;let t=l===0?1:Math.min(2.5,(e-l)/16.67);l=e;let n=performance.now();for(;s.length>0&&n-s[0].t>AJ;)s.shift();let r=window.innerWidth,d=window.innerHeight;i.clearRect(0,0,r,d);let f=Math.ceil(d/wJ),p=o!==null||s.length>0;for(let r=0;r<a.length;r++){let c=a[r];if(c.head+=c.speed*t,c.head-kJ>f+4&&(c.head=-Math.random()*12,c.speed=DJ+Math.random()*(OJ-DJ)),e>c.nextSwapAt&&(c.glyphs[Math.floor(Math.random()*kJ)]=PJ(),c.nextSwapAt=e+MJ+Math.random()*NJ),!p)continue;let l=r*CJ+CJ/2,u=o===null?1/0:Math.abs(l-o.x);for(let e of s){let t=Math.abs(l-e.x);if(t<u&&(u=t),u===0)break}if(!(u>EJ))for(let e=0;e<kJ;e++){let t=c.head-e;if(t<-1||t>f+2)continue;let a=t*wJ,u=0;if(o!==null){let e=l-o.x,t=a-o.y,n=Math.sqrt(e*e+t*t);if(n<=EJ){let e=n<TJ?1:1-(n-TJ)/(EJ-TJ);e>u&&(u=e)}}if(u<.999)for(let e of s){let t=l-e.x,r=a-e.y,i=Math.sqrt(t*t+r*r);if(i>EJ)continue;let o=i<TJ?1:1-(i-TJ)/(EJ-TJ),s=n-e.t,c=o*(s>AJ?0:1-s/AJ);if(c>u&&(u=c),u>=.999)break}if(u<.02)continue;let d=1-e/kJ,p=u*d*.85;p<.02||(i.fillStyle=e===0?`hsla(150, 100%, 92%, ${p.toFixed(3)})`:`hsla(144, 100%, 55%, ${p.toFixed(3)})`,i.fillText(c.glyphs[e],r*CJ,a))}}c=requestAnimationFrame(h)}return d(),window.addEventListener(`resize`,d),window.addEventListener(`pointermove`,f),document.addEventListener(`mouseleave`,p),document.addEventListener(`visibilitychange`,m),c=requestAnimationFrame(h),()=>{cancelAnimationFrame(c),window.removeEventListener(`resize`,d),window.removeEventListener(`pointermove`,f),document.removeEventListener(`mouseleave`,p),document.removeEventListener(`visibilitychange`,m)}},[]),(0,$.jsx)(`canvas`,{ref:e,"aria-hidden":!0,className:`fixed inset-0 pointer-events-none`,style:{zIndex:-1}})}var LJ=24,RJ=200,zJ=3.5,BJ=10,VJ=`hsl(210, 60%, 96%)`,HJ=`hsl(212, 100%, 62%)`;function UJ(){let e=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(typeof window>`u`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return;let t=e.current;if(!t)return;let n=t.getContext(`2d`,{alpha:!0});if(!n)return;let r=t,i=n,a=[],o=0,s=!document.hidden;function c(){let e=window.devicePixelRatio||1,t=window.innerWidth,n=window.innerHeight;r.width=Math.max(1,Math.floor(t*e)),r.height=Math.max(1,Math.floor(n*e)),r.style.width=`${t}px`,r.style.height=`${n}px`,i.setTransform(e,0,0,e,0,0)}function l(e){let t=performance.now();a.push({x:e.clientX,y:e.clientY,t}),a.length>LJ&&a.splice(0,a.length-LJ)}function u(){a=[]}function d(){s=!document.hidden,s?o=requestAnimationFrame(f):cancelAnimationFrame(o)}function f(){if(!s)return;let e=performance.now();for(;a.length>0&&e-a[0].t>RJ;)a.shift();let t=window.innerWidth,n=window.innerHeight;if(i.clearRect(0,0,t,n),a.length>=2){i.lineCap=`round`,i.lineJoin=`round`,i.shadowColor=HJ;for(let t=1;t<a.length;t++){let n=a[t-1],r=a[t],o=e-r.t,s=Math.max(0,1-o/RJ);if(s<=0)continue;let c=t/a.length;i.globalAlpha=s*(.25+.75*c),i.lineWidth=Math.max(.5,zJ*c),i.shadowBlur=BJ*c,i.strokeStyle=c>.6?VJ:HJ,i.beginPath(),i.moveTo(n.x,n.y),i.lineTo(r.x,r.y),i.stroke()}i.globalAlpha=1,i.shadowBlur=0}o=requestAnimationFrame(f)}return c(),window.addEventListener(`resize`,c),window.addEventListener(`pointermove`,l),document.addEventListener(`mouseleave`,u),document.addEventListener(`visibilitychange`,d),o=requestAnimationFrame(f),()=>{cancelAnimationFrame(o),window.removeEventListener(`resize`,c),window.removeEventListener(`pointermove`,l),document.removeEventListener(`mouseleave`,u),document.removeEventListener(`visibilitychange`,d)}},[]),(0,$.jsx)(`canvas`,{ref:e,"aria-hidden":!0,className:`fixed inset-0 pointer-events-none`,style:{zIndex:-1}})}var WJ={"code-rain":IJ,galaxy:UJ};function GJ(){let e=WJ[wa().id];return e?(0,$.jsx)(e,{}):null}function KJ({project:e}){let{t}=K(`nav`),n=$V(),{registerHandler:r,unregisterHandler:i}=tt(),[a,o]=(0,Q.useState)(null),s=(0,Q.useRef)(e.id);return s.current=e.id,(0,Q.useEffect)(()=>{let n=`cost-alerts-${e.id}`;return r(n,e=>{let n=e;n.projectId!==void 0&&n.projectId!==``&&n.projectId!==s.current||(n.type===`cost_alert`?J.warning(t(`costAlerts.costAlertTitle`),{description:t(`costAlerts.costAlertDescription`,{cost:(n.cost??0).toFixed(4),threshold:(n.threshold??0).toFixed(2)})}):n.type===`daily_budget_exceeded`?(J.error(t(`costAlerts.dailyBudgetTitle`),{description:t(`costAlerts.dailyBudgetDescription`,{spent:(n.dailySpend??0).toFixed(2),budget:(n.budget??0).toFixed(2)}),duration:1/0}),o({dailySpend:n.dailySpend??0,budget:n.budget??0})):n.type===`desktop_daily_budget_exceeded`&&J.error(t(`costAlerts.desktopBudgetTitle`),{description:t(`costAlerts.desktopBudgetDescription`,{spent:(n.desktopDailySpend??0).toFixed(2),budget:(n.desktopBudget??0).toFixed(2)}),duration:1/0}))}),()=>i(n)},[e.id,r,i,t]),(0,$.jsx)(dA,{delayDuration:400,children:(0,$.jsx)(ZV.Provider,{value:n,children:(0,$.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[a&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 bg-destructive/10 border-b border-destructive/20 text-xs`,children:[(0,$.jsx)(`span`,{className:`text-destructive font-medium`,children:t(`costAlerts.bannerMessage`,{spent:a.dailySpend.toFixed(2),budget:a.budget.toFixed(2)})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>o(null),className:`text-muted-foreground hover:text-foreground ml-4 shrink-0`,children:t(`costAlerts.dismiss`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-1 overflow-hidden min-h-0`,children:[(0,$.jsx)(`main`,{className:`flex-1 overflow-auto`,children:(0,$.jsx)(l,{})}),!1]})]})})})}function qJ({projectName:e,errorMessage:t,onRetry:n}){let{t:r}=K(`nav`);return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 p-8`,children:[(0,$.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,$.jsx)(`h2`,{className:`text-base font-semibold`,children:r(`errorBoundary.title`)}),e&&(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:(0,$.jsx)(lt,{ns:`nav`,i18nKey:`errorBoundary.occurredIn`,values:{name:e},components:{strong:(0,$.jsx)(`span`,{className:`font-medium`})}})}),t&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/60 font-mono`,children:t})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:n,className:`flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,children:[(0,$.jsx)(mc,{className:`w-3.5 h-3.5`}),r(`common:actions.retry`)]})]})}var JJ=class extends Q.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`[ProjectErrorBoundary]`,e,t.componentStack)}handleRetry=()=>{this.setState({hasError:!1,error:null})};render(){return this.state.hasError?(0,$.jsx)(qJ,{projectName:this.props.projectName,errorMessage:this.state.error?.message??null,onRetry:this.handleRetry}):this.props.children}};function YJ({onAddProject:e}){let{t}=K(`setup`);return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full min-h-[400px] gap-6 px-8 text-center`,children:[(0,$.jsx)(`div`,{className:`w-14 h-14 rounded-2xl bg-muted/50 flex items-center justify-center`,children:(0,$.jsx)(Ac,{className:`w-7 h-7 text-muted-foreground`})}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h2`,{className:`text-base font-semibold`,children:(0,$.jsx)(lt,{t,i18nKey:`welcome.title`,components:{spec:(0,$.jsx)(`span`,{className:`text-accent-primary`}),rails:(0,$.jsx)(`span`,{className:`text-accent-secondary`})}})}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-sm`,children:t(`welcome.description`)}),re&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 max-w-sm`,children:t(`welcome.jiraHint`)}),oe&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 max-w-sm`,children:t(`welcome.mcpHint`)}),xe&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 max-w-sm`,children:t(`welcome.agentChatHint`)}),Ce&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 max-w-sm`,children:t(`welcome.localEnginesHint`)})]}),(0,$.jsxs)(Z,{onClick:e,size:`sm`,className:`gap-2`,children:[(0,$.jsx)(Ts,{className:`w-3.5 h-3.5`}),t(`welcome.addFirstProject`)]})]})}var XJ=`https://specrails.dev/companion-app/`,ZJ=`specrails-desktop:onboarding-dismissed`;function QJ(){try{return localStorage.getItem(ZJ)===`true`}catch{return!1}}function $J(){try{localStorage.setItem(ZJ,`true`)}catch{}}var eY=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform||``),tY=eY?`⌘`:`Ctrl`,nY=eY?`⌥`:`Alt`,rY={primary:{text:`text-accent-primary`,bar:`bg-accent-primary`,glow:`glow-primary`,btn:`bg-accent-primary hover:bg-accent-primary/90 text-primary-foreground`,softBorder:`border-accent-primary/30`,softBg:`bg-accent-primary/5`,chipBg:`bg-accent-primary/10 text-accent-primary`},info:{text:`text-accent-info`,bar:`bg-accent-info`,glow:`glow-info`,btn:`bg-accent-info hover:bg-accent-info/90 text-primary-foreground`,softBorder:`border-accent-info/30`,softBg:`bg-accent-info/5`,chipBg:`bg-accent-info/10 text-accent-info`},success:{text:`text-accent-success`,bar:`bg-accent-success`,glow:`glow-success`,btn:`bg-accent-success hover:bg-accent-success/90 text-primary-foreground`,softBorder:`border-accent-success/30`,softBg:`bg-accent-success/5`,chipBg:`bg-accent-success/10 text-accent-success`},secondary:{text:`text-accent-secondary`,bar:`bg-accent-secondary`,glow:`glow-secondary`,btn:`bg-accent-secondary hover:bg-accent-secondary/90 text-primary-foreground`,softBorder:`border-accent-secondary/30`,softBg:`bg-accent-secondary/5`,chipBg:`bg-accent-secondary/10 text-accent-secondary`},warning:{text:`text-accent-warning`,bar:`bg-accent-warning`,glow:`glow-warning`,btn:`bg-accent-warning hover:bg-accent-warning/90 text-primary-foreground`,softBorder:`border-accent-warning/30`,softBg:`bg-accent-warning/5`,chipBg:`bg-accent-warning/10 text-accent-warning`},highlight:{text:`text-accent-highlight`,bar:`bg-accent-highlight`,glow:`glow-highlight`,btn:`bg-accent-highlight hover:bg-accent-highlight/90 text-primary-foreground`,softBorder:`border-accent-highlight/30`,softBg:`bg-accent-highlight/5`,chipBg:`bg-accent-highlight/10 text-accent-highlight`}};function iY({children:e}){return(0,$.jsx)(`kbd`,{className:`inline-flex items-center justify-center min-w-[1.5rem] h-5 px-1.5 rounded border border-border/60 bg-card/80 font-mono text-[11px] text-foreground shadow-sm`,children:e})}function aY({icon:e,label:t,children:n,accent:r}){return(0,$.jsxs)(`div`,{className:`flex gap-3 items-start`,children:[(0,$.jsx)(`div`,{className:X(`mt-0.5 shrink-0 grid place-items-center w-7 h-7 rounded-md border border-border/40`,r.softBg,r.text),children:e}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-[13px] font-semibold text-foreground leading-tight`,children:t}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground leading-relaxed`,children:n})]})]})}function oY({accent:e,label:t,children:n}){return(0,$.jsxs)(`div`,{className:X(`rounded-lg border p-3`,e.softBorder,e.softBg),children:[t&&(0,$.jsx)(`p`,{className:X(`text-[10px] font-semibold uppercase tracking-wider mb-1.5`,e.text),children:t}),(0,$.jsx)(`div`,{className:`text-xs text-foreground/90 leading-relaxed`,children:n})]})}function sY({steps:e}){return(0,$.jsx)(`div`,{className:`flex items-center gap-2 flex-wrap text-[13px] font-medium`,children:e.map((t,n)=>(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:t.cls,children:t.label}),n<e.length-1&&(0,$.jsx)(ce,{className:`w-3.5 h-3.5 text-muted-foreground`})]},t.label))})}function cY(){let{t:e}=K(`setup`);return(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:e(`onboarding.language.intro`)}),(0,$.jsx)(aK,{}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:e(`onboarding.language.note`)})]})}function lY(){let{t:e}=K(`setup`);return(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:e(`onboarding.theme.intro`)}),(0,$.jsx)(ZG,{}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:e(`onboarding.theme.note`)})]})}function uY({icon:e,url:t,label:n,testId:r}){return(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border border-border/40 bg-card/40 p-3`,children:[(0,$.jsx)(`div`,{className:`shrink-0 rounded-md bg-white p-1.5`,"aria-hidden":`true`,children:(0,$.jsx)(Dq,{value:t,size:72})}),(0,$.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[13px] font-semibold text-foreground leading-tight`,children:[e,n]}),(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,"data-testid":r,"aria-label":n,className:`inline-flex items-center gap-1 text-xs text-accent-info hover:underline break-all`,children:[t.replace(`https://`,``),(0,$.jsx)(pn,{className:`w-3 h-3 shrink-0`,"aria-hidden":`true`})]})]})]})}function dY(){let{t:e}=K(`setup`);return(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.companion.intro`,components:{b:(0,$.jsx)(`span`,{className:`text-foreground font-medium`})}})}),(0,$.jsx)(oY,{accent:rY.success,label:e(`onboarding.companion.localLabel`),children:e(`onboarding.companion.localBody`)}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`p`,{className:`text-[13px] font-semibold text-foreground`,children:e(`onboarding.companion.downloadLabel`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`onboarding.companion.downloadHint`)}),(0,$.jsx)(uY,{icon:(0,$.jsx)(Tc,{className:`w-4 h-4 shrink-0`,"aria-hidden":`true`}),url:XJ,label:e(`onboarding.companion.open`),testId:`companion-web-link`})]}),(0,$.jsx)(aY,{icon:(0,$.jsx)(dc,{className:`w-4 h-4`}),label:e(`onboarding.companion.pairLabel`),accent:rY.success,children:e(`onboarding.companion.pairBody`)})]})}function fY(e){let t={b:(0,$.jsx)(`span`,{className:`text-foreground font-medium`})};return[{navLabel:e(`onboarding.language.nav`),icon:(0,$.jsx)(Bs,{className:`w-6 h-6`}),accent:rY.info,title:e(`onboarding.language.title`),subtitle:e(`onboarding.language.subtitle`),content:(0,$.jsx)(cY,{})},{navLabel:e(`onboarding.theme.nav`),icon:(0,$.jsx)(ec,{className:`w-6 h-6`}),accent:rY.highlight,title:e(`onboarding.theme.title`),subtitle:e(`onboarding.theme.subtitle`),content:(0,$.jsx)(lY,{})},{navLabel:e(`onboarding.welcome.nav`),icon:(0,$.jsx)(Ln,{className:`w-6 h-6`}),accent:rY.primary,title:e(`onboarding.welcome.title`),subtitle:e(`onboarding.welcome.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.welcome.intro`,components:t})}),(0,$.jsxs)(oY,{accent:rY.primary,label:e(`onboarding.welcome.coreLoopLabel`),children:[(0,$.jsx)(sY,{steps:[{label:e(`onboarding.flow.describe`),cls:`text-accent-info`},{label:e(`onboarding.flow.specs`),cls:`text-accent-success`},{label:e(`onboarding.flow.rails`),cls:`text-accent-warning`},{label:e(`onboarding.flow.review`),cls:`text-accent-secondary`}]}),(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.welcome.flowCaption`,components:t})})]}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-4`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(Vo,{className:`w-4 h-4`}),label:e(`onboarding.welcome.missionLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.welcome.missionBody`,components:t})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Vs,{className:`w-4 h-4`}),label:e(`onboarding.welcome.boardLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.welcome.boardBody`,components:t})})]}),(0,$.jsxs)(`div`,{className:`flex gap-3 items-start`,children:[(0,$.jsx)(Cc,{className:`w-4 h-4 mt-0.5 shrink-0 text-accent-success`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.welcome.localNote`,components:{...t,i:(0,$.jsx)(`span`,{className:`italic`})}})})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:e(`onboarding.welcome.tourNote`)})]})},...xe?[{navLabel:e(`onboarding.mission.nav`),icon:(0,$.jsx)(Vo,{className:`w-6 h-6`}),accent:rY.primary,title:e(`onboarding.mission.title`),subtitle:e(`onboarding.mission.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.mission.intro`,components:t})}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-4`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(O,{className:`w-4 h-4`}),label:e(`onboarding.mission.missionsLabel`),accent:rY.primary,children:e(`onboarding.mission.missionsBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Cc,{className:`w-4 h-4`}),label:e(`onboarding.mission.levelsLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.mission.levelsBody`,components:{...t,shift:(0,$.jsx)(iY,{children:`Shift`}),tab:(0,$.jsx)(iY,{children:`Tab`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(kn,{className:`w-4 h-4`}),label:e(`onboarding.mission.cardsLabel`),accent:rY.primary,children:e(`onboarding.mission.cardsBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Ho,{className:`w-4 h-4`}),label:e(`onboarding.mission.workspaceLabel`),accent:rY.primary,children:e(`onboarding.mission.workspaceBody`)})]}),(0,$.jsx)(oY,{accent:rY.primary,label:e(`onboarding.mission.mcpLabel`),children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.mission.mcpBody`,components:t})})]})}]:[],...se?[{navLabel:e(`onboarding.builder.nav`),icon:(0,$.jsx)(Ns,{className:`w-6 h-6`}),accent:rY.highlight,title:e(`onboarding.builder.title`),subtitle:e(`onboarding.builder.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.builder.intro`,components:t})}),(0,$.jsxs)(oY,{accent:rY.highlight,label:e(`onboarding.builder.flowLabel`),children:[(0,$.jsx)(sY,{steps:[{label:e(`onboarding.flow.blueprint`),cls:`text-accent-info`},{label:e(`onboarding.flow.approve`),cls:`text-accent-success`},{label:e(`onboarding.flow.m1Specs`),cls:`text-accent-warning`},{label:e(`onboarding.flow.milestones`),cls:`text-accent-secondary`}]}),(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:e(`onboarding.builder.flowCaption`)})]}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-4`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(Fc,{className:`w-4 h-4`}),label:e(`onboarding.builder.cardsLabel`),accent:rY.highlight,children:e(`onboarding.builder.cardsBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(bs,{className:`w-4 h-4`}),label:e(`onboarding.builder.specsLabel`),accent:rY.highlight,children:e(`onboarding.builder.specsBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(gc,{className:`w-4 h-4`}),label:e(`onboarding.builder.milestonesLabel`),accent:rY.highlight,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.builder.milestonesBody`,components:t})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Ds,{className:`w-4 h-4`}),label:e(`onboarding.builder.progressLabel`),accent:rY.highlight,children:e(`onboarding.builder.progressBody`)})]})]})}]:[],{navLabel:e(`onboarding.authorSpecs.nav`),icon:(0,$.jsx)(O,{className:`w-6 h-6`}),accent:rY.info,title:e(`onboarding.authorSpecs.title`),subtitle:e(`onboarding.authorSpecs.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.authorSpecs.intro`,components:t})}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-4`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(Vo,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.agentLabel`),accent:rY.info,children:e(`onboarding.authorSpecs.agentBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(O,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.exploreLabel`),accent:rY.info,children:e(`onboarding.authorSpecs.exploreBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(wn,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.quickLabel`),accent:rY.info,children:e(`onboarding.authorSpecs.quickBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(D,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.websiteLabel`),accent:rY.info,children:e(`onboarding.authorSpecs.websiteBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(vc,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.smashLabel`),accent:rY.info,children:e(`onboarding.authorSpecs.smashBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(dn,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.draftsLabel`),accent:rY.info,children:e(`onboarding.authorSpecs.draftsBody`)})]}),re&&(0,$.jsx)(oY,{accent:rY.info,label:e(`onboarding.jira.label`),children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.jira.body`,components:t})})]})},{navLabel:e(`onboarding.rails.nav`),icon:(0,$.jsx)(Lc,{className:`w-6 h-6`}),accent:rY.success,title:e(`onboarding.rails.title`),subtitle:e(`onboarding.rails.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.rails.intro`,components:{...t,play:(0,$.jsx)(`span`,{className:`text-accent-warning font-medium`})}})}),(0,$.jsxs)(oY,{accent:rY.success,label:e(`onboarding.rails.jobLabel`),children:[(0,$.jsx)(sY,{steps:[{label:e(`onboarding.flow.architect`),cls:`text-accent-info`},{label:e(`onboarding.flow.developer`),cls:`text-accent-success`},{label:e(`onboarding.flow.reviewer`),cls:`text-accent-warning`},{label:e(`onboarding.flow.yourReview`),cls:`text-accent-secondary`}]}),(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:e(`onboarding.rails.flowCaption`)})]}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-4`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(On,{className:`w-4 h-4`}),label:e(`onboarding.rails.reviewLabel`),accent:rY.success,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.rails.reviewBody`,components:t})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(vs,{className:`w-4 h-4`}),label:e(`onboarding.rails.packetLabel`),accent:rY.success,children:e(`onboarding.rails.packetBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(O,{className:`w-4 h-4`}),label:e(`onboarding.rails.steerLabel`),accent:rY.success,children:e(`onboarding.rails.steerBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(hc,{className:`w-4 h-4`}),label:e(`onboarding.rails.loopsLabel`),accent:rY.success,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.rails.loopsBody`,components:t})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Vo,{className:`w-4 h-4`}),label:e(`onboarding.rails.profilesLabel`),accent:rY.success,children:e(`onboarding.rails.profilesBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Ts,{className:`w-4 h-4`}),label:e(`onboarding.rails.isolationLabel`),accent:rY.success,children:e(`onboarding.rails.isolationBody`)})]})]})},{navLabel:e(`onboarding.providers.nav`),icon:(0,$.jsx)(Vo,{className:`w-6 h-6`}),accent:rY.secondary,title:e(`onboarding.providers.title`),subtitle:e(`onboarding.providers.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.providers.intro`,components:t})}),(0,$.jsxs)(`div`,{className:`rounded-lg border border-border/40 overflow-hidden text-xs`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-[1.4fr_1fr_1fr_1fr_1fr] bg-card/40`,children:[(0,$.jsx)(`div`,{className:`px-3 py-2 font-semibold text-muted-foreground`,children:e(`onboarding.providers.table.capability`)}),(0,$.jsx)(`div`,{className:`px-3 py-2 font-semibold text-accent-secondary text-center`,children:`Claude Code`}),(0,$.jsx)(`div`,{className:`px-3 py-2 font-semibold text-accent-success text-center`,children:`Codex CLI`}),(0,$.jsx)(`div`,{className:`px-3 py-2 font-semibold text-accent-info text-center`,children:`Gemini CLI`}),(0,$.jsx)(`div`,{className:`px-3 py-2 font-semibold text-purple-300 text-center`,children:`Kimi Code`})]}),[[e(`onboarding.providers.table.streamingResume`),e(`onboarding.providers.table.native`),e(`onboarding.providers.table.native`),e(`onboarding.providers.table.native`),e(`onboarding.providers.table.native`)],[e(`onboarding.providers.table.costReporting`),e(`onboarding.providers.table.providerBilled`),e(`onboarding.providers.table.estimated`),e(`onboarding.providers.table.estimated`),e(`onboarding.providers.table.unavailable`)],[e(`onboarding.providers.table.telemetry`),e(`onboarding.providers.table.native`),e(`onboarding.providers.table.synthesized`),e(`onboarding.providers.table.native`),e(`onboarding.providers.table.synthesized`)],[e(`onboarding.providers.table.agentProfiles`),e(`common:states.yes`),`—`,`—`,e(`common:states.yes`)]].map(e=>(0,$.jsxs)(`div`,{className:`grid grid-cols-[1.4fr_1fr_1fr_1fr_1fr] border-t border-border/30`,children:[(0,$.jsx)(`div`,{className:`px-3 py-2 text-foreground/90`,children:e[0]}),(0,$.jsx)(`div`,{className:`px-3 py-2 text-center text-muted-foreground`,children:e[1]}),(0,$.jsx)(`div`,{className:`px-3 py-2 text-center text-muted-foreground`,children:e[2]}),(0,$.jsx)(`div`,{className:`px-3 py-2 text-center text-muted-foreground`,children:e[3]}),(0,$.jsx)(`div`,{className:`px-3 py-2 text-center text-muted-foreground`,children:e[4]})]},e[0]))]}),(0,$.jsx)(oY,{accent:rY.secondary,label:e(`onboarding.providers.calloutLabel`),children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.providers.calloutBody`,components:{...t,mono:(0,$.jsx)(`span`,{className:`font-mono`})}})})]})},{navLabel:e(`onboarding.cost.nav`),icon:(0,$.jsx)(os,{className:`w-6 h-6`}),accent:rY.warning,title:e(`onboarding.cost.title`),subtitle:e(`onboarding.cost.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.cost.intro`,components:t})}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-4`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(Ds,{className:`w-4 h-4`}),label:e(`onboarding.cost.analyticsLabel`),accent:rY.warning,children:e(`onboarding.cost.analyticsBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(pc,{className:`w-4 h-4`}),label:e(`onboarding.cost.perTicketLabel`),accent:rY.warning,children:e(`onboarding.cost.perTicketBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(hs,{className:`w-4 h-4`}),label:e(`onboarding.cost.honestLabel`),accent:rY.warning,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.cost.honestBody`,components:{mono:(0,$.jsx)(`span`,{className:`font-mono`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Pc,{className:`w-4 h-4`}),label:e(`onboarding.cost.budgetsLabel`),accent:rY.warning,children:e(`onboarding.cost.budgetsBody`)})]})]})},{navLabel:e(`onboarding.workspace.nav`),icon:(0,$.jsx)(Ho,{className:`w-6 h-6`}),accent:rY.highlight,title:e(`onboarding.workspace.title`),subtitle:e(`onboarding.workspace.subtitle`),content:(0,$.jsx)(`div`,{className:`space-y-4`,children:(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-4`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(Ac,{className:`w-4 h-4`}),label:e(`onboarding.workspace.terminalLabel`),accent:rY.highlight,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.workspace.terminalBody`,values:{mod:tY},components:{mod:(0,$.jsx)(iY,{children:tY}),j:(0,$.jsx)(iY,{children:`J`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(bs,{className:`w-4 h-4`}),label:e(`onboarding.workspace.codeLabel`),accent:rY.highlight,children:e(`onboarding.workspace.codeBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(D,{className:`w-4 h-4`}),label:e(`onboarding.workspace.browserLabel`),accent:rY.highlight,children:e(`onboarding.workspace.browserBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(lc,{className:`w-4 h-4`}),label:e(`onboarding.workspace.integrationsLabel`),accent:rY.highlight,children:e(`onboarding.workspace.integrationsBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(ec,{className:`w-4 h-4`}),label:e(`onboarding.workspace.themesLabel`),accent:rY.highlight,children:e(`onboarding.workspace.themesBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(kn,{className:`w-4 h-4`}),label:e(`onboarding.workspace.chatsLabel`),accent:rY.highlight,children:e(`onboarding.workspace.chatsBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(U,{className:`w-4 h-4`}),label:e(`onboarding.workspace.compareLabel`),accent:rY.highlight,children:e(`onboarding.workspace.compareBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(gc,{className:`w-4 h-4`}),label:e(`onboarding.workspace.desktopLabel`),accent:rY.highlight,children:e(`onboarding.workspace.desktopBody`)})]})})},{navLabel:e(`onboarding.companion.nav`),icon:(0,$.jsx)(Tc,{className:`w-6 h-6`}),accent:rY.success,title:e(`onboarding.companion.title`),subtitle:e(`onboarding.companion.subtitle`),content:(0,$.jsx)(dY,{})},{navLabel:e(`onboarding.moveFast.nav`),icon:(0,$.jsx)(cs,{className:`w-6 h-6`}),accent:rY.primary,title:e(`onboarding.moveFast.title`),subtitle:e(`onboarding.moveFast.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(oY,{accent:rY.primary,label:e(`onboarding.moveFast.paletteLabel`),children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.paletteShortcut`,values:{mod:tY},components:{f:(0,$.jsx)(`span`,{className:`text-foreground`}),m:(0,$.jsx)(`span`,{className:`text-muted-foreground`}),mod:(0,$.jsx)(iY,{children:tY}),k:(0,$.jsx)(iY,{children:`K`})}})}),e(`onboarding.moveFast.paletteBody`)]}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-3`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(Vo,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.agentLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.agentBody`,values:{mod:tY},components:{mod:(0,$.jsx)(iY,{children:tY}),shift:(0,$.jsx)(iY,{children:`Shift`}),a:(0,$.jsx)(iY,{children:`A`}),tab:(0,$.jsx)(iY,{children:`Tab`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Ac,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.terminalLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.terminalBody`,values:{mod:tY},components:{mod:(0,$.jsx)(iY,{children:tY}),j:(0,$.jsx)(iY,{children:`J`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(zs,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.shortcutsLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.shortcutsBody`,components:{q:(0,$.jsx)(iY,{children:`?`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(O,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.chatLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.chatBody`,values:{mod:tY},components:{mod:(0,$.jsx)(iY,{children:tY}),bkey:(0,$.jsx)(iY,{children:`B`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Ts,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.projectsLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.projectsBody`,values:{alt:nY,mod:tY},components:{alt:(0,$.jsx)(iY,{children:nY}),mod:(0,$.jsx)(iY,{children:tY}),bkey:(0,$.jsx)(iY,{children:`B`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(cs,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.pagesLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.pagesBody`,values:{alt:nY,mod:tY},components:{alt:(0,$.jsx)(iY,{children:nY}),mod:(0,$.jsx)(iY,{children:tY}),n:(0,$.jsx)(iY,{children:`1–9`})}})})]}),(0,$.jsx)(oY,{accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.outro`,components:t})})]})}]}function pY({open:e,onClose:t}){let{t:n}=K(`setup`),[r,i]=(0,Q.useState)(0),[a,o]=(0,Q.useState)(!1),s=(0,Q.useMemo)(()=>fY(n),[n]),c=s[r],l=r===0,u=r===s.length-1,d=(0,Q.useCallback)(()=>{a&&$J(),i(0),t()},[a,t]),f=(0,Q.useCallback)(()=>{$J(),i(0),t()},[t]),p=(0,Q.useCallback)(()=>{u?f():i(e=>e+1)},[u,f]),m=(0,Q.useCallback)(()=>i(e=>Math.max(0,e-1)),[]);return(0,$.jsx)(dr,{open:e,onOpenChange:e=>{e||d()},children:(0,$.jsxs)(tr,{children:[(0,$.jsx)(er,{className:`fixed inset-0 z-50 bg-black/70 backdrop-blur-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`}),(0,$.jsxs)(hr,{className:`fixed left-[50%] top-[50%] z-50 flex flex-col w-[calc(100vw-2rem)] max-w-5xl h-[min(88vh,820px)] translate-x-[-50%] translate-y-[-50%] overflow-hidden border border-border/30 bg-popover shadow-2xl backdrop-blur-xl sm:rounded-2xl duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95`,"data-testid":`onboarding-wizard`,"aria-describedby":`onboarding-description`,children:[(0,$.jsx)(`div`,{className:X(`h-1 w-full shrink-0 transition-all duration-500`,c.accent.bar)}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,$.jsxs)(`nav`,{className:`hidden md:flex w-60 shrink-0 flex-col border-r border-border/30 bg-card/20 p-4`,children:[(0,$.jsxs)(`div`,{className:`px-2 mb-5`,children:[(0,$.jsxs)(`p`,{className:`text-sm font-bold tracking-tight`,children:[(0,$.jsx)(`span`,{className:`text-accent-primary`,children:`spec`}),(0,$.jsx)(`span`,{className:`text-accent-secondary`,children:`rails`})]}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:n(`onboarding.productTour`)})]}),(0,$.jsx)(`ol`,{className:`space-y-0.5 min-h-0 overflow-y-auto`,children:s.map((e,t)=>{let a=t===r,o=t<r;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(t),"aria-label":n(`onboarding.goToStep`,{step:t+1,label:e.navLabel}),"aria-current":a?`step`:void 0,className:X(`w-full flex items-center gap-2.5 rounded-lg px-2.5 py-2 text-left transition-colors`,a?X(`bg-card/70`,e.accent.text):`text-muted-foreground hover:bg-card/40 hover:text-foreground`),children:[(0,$.jsx)(`span`,{className:X(`grid place-items-center w-5 h-5 shrink-0 rounded-full text-[10px] font-bold border`,a?X(e.accent.bar,`text-primary-foreground border-transparent`):o?`bg-accent-success/15 text-accent-success border-accent-success/30`:`border-border/50 text-muted-foreground`),children:o?(0,$.jsx)(Sn,{className:`w-3 h-3`}):t+1}),(0,$.jsx)(`span`,{className:`text-xs font-medium truncate`,children:e.navLabel})]})},e.navLabel)})}),(0,$.jsx)(`div`,{className:`mt-auto px-2.5 pt-4 text-[10px] text-muted-foreground`,children:n(`onboarding.stepCount`,{current:r+1,total:s.length})})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6 sm:p-7`,children:[(0,$.jsxs)(`div`,{className:X(`flex items-center gap-3.5 mb-5`,c.accent.text),children:[(0,$.jsx)(`div`,{className:X(`grid place-items-center w-12 h-12 shrink-0 rounded-xl border border-border/30 bg-card/40`,c.accent.glow),children:c.icon}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(cr,{className:`text-lg font-bold leading-tight text-foreground`,children:c.title}),(0,$.jsx)(`p`,{id:`onboarding-description`,className:`text-xs text-muted-foreground mt-0.5`,children:c.subtitle})]})]}),(0,$.jsx)(`div`,{className:`md:hidden flex items-center gap-1.5 mb-5`,children:s.map((e,t)=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>i(t),"aria-label":n(`onboarding.stepLabel`,{step:t+1}),"aria-current":t===r?`step`:void 0,className:X(`h-1.5 rounded-full transition-all`,t===r?X(`w-6`,e.accent.bar):`w-1.5 bg-muted-foreground/30`)},e.navLabel))}),(0,$.jsx)(`div`,{className:`min-h-[300px]`,children:c.content})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-border/30 px-6 sm:px-7 py-3.5`,children:[(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:l&&(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-2 cursor-pointer group`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(e.target.checked),className:`w-3.5 h-3.5 rounded`,"data-testid":`onboarding-dismiss-checkbox`}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground group-hover:text-foreground transition-colors`,children:n(`onboarding.dontShowAgain`)})]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[l?(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:d,className:`text-xs text-muted-foreground`,"data-testid":`onboarding-skip`,children:n(`onboarding.skipTour`)}):(0,$.jsxs)(Z,{variant:`ghost`,size:`sm`,onClick:m,className:`text-xs`,"data-testid":`onboarding-back`,children:[(0,$.jsx)(un,{className:`w-3.5 h-3.5 mr-1`}),n(`common:actions.back`)]}),(0,$.jsxs)(Z,{size:`sm`,onClick:p,className:X(`text-xs`,c.accent.btn),"data-testid":`onboarding-next`,children:[n(u?`onboarding.getStarted`:`common:actions.next`),!u&&(0,$.jsx)(ce,{className:`w-3.5 h-3.5 ml-1`})]})]})]})]})]})]})]})})}function mY(){let[e,t]=(0,Q.useState)(new Map),n=(0,Q.useContext)(rt);return(0,Q.useEffect)(()=>n?(n.registerHandler(`assemble-progress`,e=>{let n=e;if(n.type!==`project.assemble_progress`||typeof n.projectId!=`string`||typeof n.provider!=`string`)return;let{projectId:r,provider:i,status:a}=n;t(e=>{let t=new Map(e),n=t.get(r)?{running:new Set(t.get(r).running),failed:new Set(t.get(r).failed)}:{running:new Set,failed:new Set};return a===`running`?(n.running.add(i),n.failed.delete(i)):a===`done`?(n.running.delete(i),n.failed.delete(i)):a===`failed`&&(n.running.delete(i),n.failed.add(i)),t.set(r,n),t})}),()=>n.unregisterHandler(`assemble-progress`)):void 0,[n]),{statusFor:(0,Q.useCallback)(t=>{let n=e.get(t);return n?n.running.size>0?`assembling`:n.failed.size>0?`failed`:`ready`:`ready`},[e]),retry:(0,Q.useCallback)(async e=>{await fetch(`${Xe}/api/projects/${e}/assemble-retry`,{method:`POST`})},[])}}var hY=(0,Q.lazy)(()=>c(()=>import(`./ProjectSettingsDialog-e7y_uZIz.js`).then(e=>({default:e.ProjectSettingsDialog})),__vite__mapDeps([88,1,7,43,45,8,12,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,56,67,51,68,69]))),gY=`specrails-desktop:agentTreeExpanded`;function _Y(){try{let e=localStorage.getItem(gY);if(!e)return new Set;let t=JSON.parse(e);return Array.isArray(t)?new Set(t.filter(e=>typeof e==`string`)):new Set}catch{return new Set}}function vY(e){try{localStorage.setItem(gY,JSON.stringify([...e]))}catch{}}function yY(){window.dispatchEvent(new KeyboardEvent(`keydown`,{key:`k`,metaKey:!0,ctrlKey:!0,bubbles:!0}))}var bY=`__home__`,xY=`__favorites__`;function SY({conversation:e,active:t,expanded:n,streaming:r=!1,unread:i=!1,favorite:a=!1,onSelect:o,onToggleFavorite:s,onDelete:c}){let{t:l}=K(`agent`),u=e.title?.trim()||l(`untitled`),[d,f]=(0,Q.useState)(!1),p=(0,Q.useRef)(null),[m,h]=(0,Q.useState)(!1),g=(0,Q.useRef)(r);(0,Q.useEffect)(()=>{if(g.current&&!r){h(!0);let e=setTimeout(()=>h(!1),900);return g.current=r,()=>clearTimeout(e)}g.current=r},[r]),(0,Q.useEffect)(()=>()=>{p.current&&clearTimeout(p.current)},[]);function _(e){e.stopPropagation(),d?(p.current&&clearTimeout(p.current),f(!1),c()):(f(!0),p.current=setTimeout(()=>{f(!1),p.current=null},3e3))}function v(e){e.stopPropagation(),s?.()}function y(e){e.target===e.currentTarget&&(e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),o()))}return(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:o,onKeyDown:y,className:X(`group relative flex items-center gap-2 w-full h-7 rounded-md transition-colors`,n?`pl-7 pr-2`:`px-0 justify-center`,t?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),title:n?void 0:u,"aria-current":t?`true`:void 0,children:[(0,$.jsx)(O,{className:X(`w-3.5 h-3.5 flex-shrink-0`,t&&`text-accent-primary`,r&&!i&&`text-accent-primary animate-pulse`,i&&`text-destructive conversation-unread-glow`)}),n&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`relative text-[11px] truncate flex-1 text-left`,children:[u,(r||m)&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:X(`title-shimmer pointer-events-none absolute inset-0 truncate transition-opacity duration-700`,r?`opacity-100`:`opacity-0`),children:u})]}),(0,$.jsx)(`span`,{className:X(`flex-shrink-0 text-[10px] tabular-nums text-muted-foreground/45`,d?`hidden`:`group-hover:hidden`),title:Yb(e.updated_at),children:Jb(e.updated_at)}),(0,$.jsx)(`button`,{type:`button`,onClick:v,className:X(`flex-shrink-0 items-center justify-center rounded-sm transition-colors hover:bg-muted`,a?`flex w-3.5 h-3.5 text-accent-primary hover:text-accent-primary`:`hidden group-hover:flex w-3.5 h-3.5 text-muted-foreground/60 hover:text-accent-primary`),"aria-label":l(a?`removeFavoriteConversation`:`addFavoriteConversation`,{title:u}),title:l(a?`removeFavoriteConversation`:`addFavoriteConversation`,{title:u}),children:(0,$.jsx)(Ps,{className:`w-2.5 h-2.5`,fill:a?`currentColor`:`none`})}),(0,$.jsx)(`button`,{type:`button`,onClick:_,className:X(`flex-shrink-0 items-center justify-center rounded-sm transition-colors hover:bg-muted`,d?`flex px-1 h-4 text-[10px] text-destructive bg-destructive/10 hover:bg-destructive/20`:`hidden group-hover:flex w-3.5 h-3.5 text-muted-foreground/60 hover:text-foreground`),"aria-label":l(d?`confirmDeleteConversation`:`deleteConversation`,{title:u}),children:d?l(`confirmShort`):(0,$.jsx)(Vn,{className:`w-2.5 h-2.5`})})]})]})}function CY({project:e,isActive:t,expanded:n,onSelect:r,onRemove:i,agentMode:a=!1,hasTree:o=!1,treeOpen:s=!1,onToggleTree:c,conversations:l=[],activeConversationId:u=null,streamingConversationIds:d,unreadConversationIds:f,onSelectConversation:p,onToggleConversationFavorite:m,onDeleteConversation:h,onOpenProjectSettings:g,assembleStatus:_=`ready`,onRetryAssemble:v}){let{t:y}=K(`nav`),[b,x]=(0,Q.useState)(!1),S=(0,Q.useRef)(null);(0,Q.useEffect)(()=>()=>{S.current&&clearTimeout(S.current)},[]);function C(e){e.stopPropagation(),b?(S.current&&clearTimeout(S.current),x(!1),i()):(x(!0),S.current=setTimeout(()=>{x(!1),S.current=null},3e3))}function w(e){e.target===e.currentTarget&&(e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),r()))}let T=a&&o&&n,E=(0,$.jsx)(Ts,{className:X(`flex-shrink-0 w-4 h-4`,t&&`text-accent-primary`)});return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:r,onKeyDown:w,className:X(`group relative flex items-center gap-2 w-full h-8 rounded-md transition-colors`,n?`px-2`:`px-0 justify-center`,t?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),title:n?void 0:e.name,"aria-current":t?`page`:void 0,children:[T?(0,$.jsxs)(`span`,{className:`relative flex h-4 w-4 flex-shrink-0 items-center justify-center`,children:[(0,$.jsx)(`span`,{className:`flex transition-opacity group-hover:opacity-0 group-focus-within:opacity-0`,children:E}),(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c?.()},className:`absolute inset-0 hidden items-center justify-center rounded-sm hover:bg-muted group-hover:flex group-focus-within:flex`,"aria-label":y(s?`projects.collapse`:`projects.expand`,{name:e.name}),"aria-expanded":s,children:s?(0,$.jsx)(Xo,{className:`w-3.5 h-3.5`}):(0,$.jsx)(Zo,{className:`w-3.5 h-3.5`})})]}):E,n&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-xs truncate flex-1 text-left`,children:e.name}),_===`assembling`&&(0,$.jsx)(`span`,{className:`flex-shrink-0 h-1.5 w-1.5 rounded-full bg-accent-info animate-pulse`,title:y(`projects.assembling`),"data-testid":`assemble-indicator`,"aria-label":y(`projects.assembling`)}),_===`failed`&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),v?.()},className:`flex-shrink-0 h-2 w-2 rounded-full bg-accent-warning hover:ring-2 hover:ring-accent-warning/40 transition-shadow`,title:y(`projects.assembleFailed`),"data-testid":`assemble-retry`,"aria-label":y(`projects.assembleFailed`)}),g&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),g()},className:X(`flex-shrink-0 flex items-center justify-center rounded-sm transition-all w-3.5 h-3.5`,`opacity-0 group-hover:opacity-50 hover:!opacity-100 hover:bg-muted`),"aria-label":y(`projects.settings`,{name:e.name}),title:y(`projects.settings`,{name:e.name}),children:(0,$.jsx)(Sc,{className:`w-2.5 h-2.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:C,className:X(`flex-shrink-0 flex items-center justify-center rounded-sm transition-all`,`opacity-0 group-hover:opacity-50 hover:!opacity-100 hover:bg-muted`,b?`opacity-100 px-1 h-4 text-[10px] text-destructive bg-destructive/10 hover:bg-destructive/20`:`w-3.5 h-3.5`),"aria-label":y(b?`projects.confirmRemove`:`projects.remove`,{name:e.name}),children:b?y(`projects.confirmShort`):(0,$.jsx)(Vn,{className:`w-2.5 h-2.5`})})]})]}),a&&s&&n&&l.length>0&&(0,$.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:l.map(e=>(0,$.jsx)(SY,{conversation:e,active:e.id===u,streaming:d?.has(e.id)??!1,unread:f?.has(e.id)??!1,expanded:n,onSelect:()=>p?.(e.id),onToggleFavorite:()=>m?.(e.id),onDelete:()=>h?.(e.id)},e.id))})]})}var wY={"pinned-open":`sidebarPin.left.pinnedOpen`,"pinned-collapsed":`sidebarPin.left.pinnedCollapsed`,unpinned:`sidebarPin.left.unpinned`};function TY({onAddProject:e,onOpenLoops:t,onOpenPlugins:n,onOpenAnalytics:r,onOpenDocs:i,onOpenSettings:a,onOpenCompanion:o}){let{t:s}=K(`nav`),{t:c}=K(`agent`),{projects:l,activeProjectId:u,setActiveProjectId:d,removeProject:f}=pt(),m=mY(),h=y(),g=p(),_=g.pathname.startsWith(`/loops`),v=g.pathname.startsWith(`/plugins`),b=_||v||g.pathname.startsWith(`/docs`),{leftMode:x,cycleLeftMode:S}=XP(),{uiMode:C,toggleUiMode:w}=MN(),T=aP(),E=C===`agent`,D=(0,Q.useMemo)(()=>{let e=new Map,t=new Set(l.map(e=>e.id));for(let n of T.conversations){if(T.favoriteConversationIds.has(n.id))continue;let r=n.pinned_project_id&&t.has(n.pinned_project_id)?n.pinned_project_id:bY,i=e.get(r);i?i.push(n):e.set(r,[n])}return e},[T.conversations,T.favoriteConversationIds,l]),O=(0,Q.useMemo)(()=>T.conversations.filter(e=>T.favoriteConversationIds.has(e.id)),[T.conversations,T.favoriteConversationIds]),k=D.get(bY)??[],[A,j]=(0,Q.useState)(_Y),M=A.has(xY),[N,P]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{!E||!u||j(e=>{if(e.has(u))return e;let t=new Set(e);return t.add(u),vY(t),t})},[E,u]);let F=e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),vY(n),n})},I=e=>{T.selectConversation(e),b&&h(`/`)},L=e=>{T.deleteConversation(e).catch(()=>{})},R=e=>{T.toggleFavoriteConversation(e)};function z(e){if(E){d(e),F(e);return}if(e===u){b&&h(`/`);return}d(e)}let[B,V]=(0,Q.useState)(!1),H=x===`pinned-open`||x===`unpinned`&&B,U=zP(`left-arc`,{side:`left`,defaultWidth:240,min:200,max:460,collapsedWidth:44,expanded:H}),W=x!==`unpinned`,ee=s(wY[x]),te=[{label:s(`arcSidebar.docs`),icon:Bo,action:i},{label:s(`arcSidebar.analytics`),icon:qo,action:r},...o?[{label:s(`arcSidebar.companion`),icon:Tc,action:o}]:[],{label:s(`arcSidebar.settings`),icon:Sc,action:a}];async function ne(e){try{await f(e.id)}catch{}}return(0,$.jsxs)(`div`,{ref:U.panelRef,className:X(`relative flex flex-col h-full border-r border-border bg-background flex-shrink-0 overflow-hidden`,`transition-[width] duration-200 ease-in-out`),onMouseEnter:()=>{x===`unpinned`&&V(!0)},onMouseLeave:()=>{x===`unpinned`&&!U.dragging&&V(!1)},children:[H&&(0,$.jsx)(BP,{side:`left`,dragging:U.dragging,width:U.width,min:200,max:460,label:s(`arcSidebar.resize`,{defaultValue:`Resize sidebar`}),onPointerDown:U.onGripPointerDown,onKeyDown:U.onGripKeyDown}),(0,$.jsxs)(`div`,{className:X(`flex items-center h-12 border-b border-border flex-shrink-0`,H?`px-3 justify-between`:`justify-center`),children:[H&&(0,$.jsx)(`span`,{className:`font-mono text-sm font-bold whitespace-nowrap overflow-hidden text-accent-primary`,children:s(`arcSidebar.desktopTitle`)}),(0,$.jsx)(`button`,{type:`button`,onClick:S,className:X(`flex items-center justify-center w-7 h-7 rounded-md transition-colors flex-shrink-0`,W?`text-foreground bg-muted`:`text-muted-foreground/40 hover:text-muted-foreground hover:bg-muted/50`),"aria-label":ee,title:s(`sidebarPin.withShortcut`,{label:ee,shortcut:mW(`⌥⌘B`)}),children:(0,$.jsx)(tc,{className:`w-4 h-4`})})]}),De&&(0,$.jsxs)(`div`,{className:`py-2 px-1.5 space-y-0.5 border-b border-border`,children:[E&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{T.startNewConversation(u),b&&h(`/`)},className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,`bg-accent-primary/15 text-accent-primary hover:bg-accent-primary/25`,H?`px-2`:`px-0 justify-center`),"aria-label":c(`newAgent`),title:H?void 0:c(`newAgent`),children:[(0,$.jsx)(Pn,{className:`w-4 h-4 flex-shrink-0`}),H&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:c(`newAgent`)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:w,className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,`text-muted-foreground hover:text-foreground hover:bg-muted/50`,H?`px-2`:`px-0 justify-center`),"aria-label":c(E?`switchToKanban`:`switchToAgent`),title:c(E?`switchToKanban`:`switchToAgent`),children:[E?(0,$.jsx)(Vs,{className:`w-4 h-4 flex-shrink-0`}):(0,$.jsx)(Vo,{className:`w-4 h-4 flex-shrink-0 text-accent-primary`}),H&&(0,$.jsx)(`span`,{className:`min-w-0 truncate text-xs`,children:c(E?`switchToKanban`:`switchToAgent`)})]}),E&&(0,$.jsxs)(`button`,{type:`button`,onClick:yY,className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,`text-muted-foreground hover:text-foreground hover:bg-muted/50`,H?`px-2`:`px-0 justify-center`),"aria-label":c(`search`),title:H?void 0:c(`search`),children:[(0,$.jsx)(In,{className:`w-4 h-4 flex-shrink-0`}),H&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:c(`search`)})]})]}),ke&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`py-2 px-1.5`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:t,className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,H?`px-2`:`px-0 justify-center`,_?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),"aria-label":s(`arcSidebar.loops`),"aria-current":_?`page`:void 0,title:H?void 0:s(`arcSidebar.loops`),children:[(0,$.jsx)(Lc,{className:X(`w-4 h-4 flex-shrink-0`,_&&`text-accent-primary`)}),H&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:s(`arcSidebar.loops`)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:n,className:X(`mt-0.5 flex items-center gap-2 w-full h-8 rounded-md transition-colors`,H?`px-2`:`px-0 justify-center`,v?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),"aria-label":s(`arcSidebar.plugins`),"aria-current":v?`page`:void 0,title:H?void 0:s(`arcSidebar.plugins`),children:[(0,$.jsx)(uc,{className:X(`w-4 h-4 flex-shrink-0`,v&&`text-accent-primary`)}),H&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:s(`arcSidebar.plugins`)})]})]}),(0,$.jsx)(`div`,{className:`border-t border-border`,"aria-hidden":!0})]}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto py-2 px-1.5 space-y-0.5`,children:[E&&O.length>0&&(0,$.jsxs)(`div`,{className:`mb-2 space-y-0.5 border-b border-border/70 pb-2`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>F(xY),className:X(`group flex items-center gap-2 w-full h-8 rounded-md transition-colors`,`text-muted-foreground hover:text-foreground hover:bg-muted/50`,H?`px-2`:`px-0 justify-center`),"aria-label":c(`favoriteMissions`),"aria-expanded":M,title:H?void 0:c(`favoriteMissions`),children:[H?(0,$.jsxs)(`span`,{className:`relative flex h-4 w-4 flex-shrink-0 items-center justify-center`,children:[(0,$.jsx)(Ps,{className:`h-4 w-4 fill-current text-accent-primary transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0`}),(0,$.jsx)(`span`,{className:`absolute inset-0 hidden items-center justify-center group-hover:flex group-focus-visible:flex`,children:M?(0,$.jsx)(Xo,{className:`w-3.5 h-3.5`}):(0,$.jsx)(Zo,{className:`w-3.5 h-3.5`})})]}):(0,$.jsx)(Ps,{className:`w-4 h-4 flex-shrink-0 fill-current text-accent-primary`}),H&&(0,$.jsx)(`span`,{className:`text-xs truncate flex-1 text-left`,children:c(`favoriteMissions`)})]}),M&&H&&(0,$.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:O.map(e=>(0,$.jsx)(SY,{conversation:e,active:e.id===T.active?.id,streaming:T.streamingConversationIds.has(e.id),unread:T.unreadConversationIds.has(e.id),favorite:!0,expanded:H,onSelect:()=>I(e.id),onToggleFavorite:()=>R(e.id),onDelete:()=>L(e.id)},e.id))})]}),E&&k.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>F(bY),className:X(`group flex items-center gap-2 w-full h-8 rounded-md transition-colors`,`text-muted-foreground hover:text-foreground hover:bg-muted/50`,H?`px-2`:`px-0 justify-center`),"aria-label":c(`home`),"aria-expanded":A.has(bY),title:H?void 0:c(`home`),children:[H?(0,$.jsxs)(`span`,{className:`relative flex h-4 w-4 flex-shrink-0 items-center justify-center`,children:[(0,$.jsx)(Is,{className:`h-4 w-4 transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0`}),(0,$.jsx)(`span`,{className:`absolute inset-0 hidden items-center justify-center group-hover:flex group-focus-visible:flex`,children:A.has(bY)?(0,$.jsx)(Xo,{className:`w-3.5 h-3.5`}):(0,$.jsx)(Zo,{className:`w-3.5 h-3.5`})})]}):(0,$.jsx)(Is,{className:`w-4 h-4 flex-shrink-0`}),H&&(0,$.jsx)(`span`,{className:`text-xs truncate flex-1 text-left`,children:c(`home`)})]}),A.has(bY)&&H&&(0,$.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:k.map(e=>(0,$.jsx)(SY,{conversation:e,active:e.id===T.active?.id,streaming:T.streamingConversationIds.has(e.id),unread:T.unreadConversationIds.has(e.id),expanded:H,onSelect:()=>I(e.id),onToggleFavorite:()=>R(e.id),onDelete:()=>L(e.id)},e.id))})]}),l.map(e=>{let t=D.get(e.id)??[];return(0,$.jsx)(CY,{project:e,isActive:e.id===u&&!b,expanded:H,onSelect:()=>z(e.id),onRemove:()=>ne(e),agentMode:E,hasTree:t.length>0,treeOpen:A.has(e.id),onToggleTree:()=>F(e.id),conversations:t,activeConversationId:T.active?.id??null,streamingConversationIds:T.streamingConversationIds,unreadConversationIds:T.unreadConversationIds,onSelectConversation:I,onToggleConversationFavorite:R,onDeleteConversation:L,assembleStatus:m.statusFor(e.id),onRetryAssemble:()=>{m.retry(e.id)},onOpenProjectSettings:E?()=>{d(e.id),P(!0)}:void 0},e.id)}),(0,$.jsxs)(`button`,{type:`button`,onClick:e,className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,`text-muted-foreground hover:text-foreground hover:bg-muted/50`,H?`px-2`:`px-0 justify-center`),"aria-label":s(`projects.addProject`),title:H?void 0:s(`projects.addProject`),children:[(0,$.jsx)(Pn,{className:`w-4 h-4 flex-shrink-0`}),H&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:s(`projects.addProject`)})]})]}),(0,$.jsx)(`div`,{className:`border-t border-border py-2 px-1.5 space-y-0.5`,children:te.map(({label:e,icon:t,action:n})=>(0,$.jsxs)(`button`,{type:`button`,onClick:n,className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,`text-muted-foreground hover:text-foreground hover:bg-muted/50`,H?`px-2`:`px-0 justify-center`),"aria-label":e,title:H?void 0:e,children:[(0,$.jsx)(t,{className:`w-4 h-4 flex-shrink-0`}),H&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:e})]},e))}),N&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(hY,{open:!0,onClose:()=>P(!1)})})]})}var EY={"pinned-open":`sidebarPin.right.pinnedOpen`,"pinned-collapsed":`sidebarPin.right.pinnedCollapsed`,unpinned:`sidebarPin.right.unpinned`};function DY(){let{t:e}=K(`nav`),{rightMode:t,cycleRightMode:n}=XP(),[r,i]=(0,Q.useState)(!1),a=t===`pinned-open`||t===`unpinned`&&r,o=t!==`unpinned`,s=e(EY[t]),c=[{to:`/`,end:!0,icon:Hs,label:e(`rightSidebar.dashboard`)},{to:`/jobs`,end:!1,icon:Go,label:e(`rightSidebar.jobs`)},{to:`/analytics`,end:!1,icon:Ko,label:e(`rightSidebar.analytics`)},...me?[{to:`/code`,end:!1,icon:is,label:e(`rightSidebar.code`)}]:[],{to:`/settings`,end:!1,icon:Sc,label:e(`rightSidebar.settings`)}];return(0,$.jsxs)(`div`,{className:X(`relative flex flex-col h-full border-l border-border bg-background flex-shrink-0`,`transition-all duration-200 ease-in-out overflow-hidden`,a?`w-44`:`w-11`),onMouseEnter:()=>{t===`unpinned`&&i(!0)},onMouseLeave:()=>{t===`unpinned`&&i(!1)},children:[(0,$.jsxs)(`div`,{className:X(`flex items-center h-12 border-b border-border flex-shrink-0`,a?`px-3 justify-between`:`justify-center`),children:[a&&(0,$.jsx)(`span`,{className:`font-mono text-sm font-bold whitespace-nowrap overflow-hidden text-accent-secondary`,children:e(`rightSidebar.projectTitle`)}),(0,$.jsx)(`button`,{type:`button`,onClick:n,className:X(`flex items-center justify-center w-7 h-7 rounded-md transition-colors`,o?`text-foreground bg-muted`:`text-muted-foreground/40 hover:text-muted-foreground hover:bg-muted/50`),"aria-label":s,title:e(`sidebarPin.withShortcut`,{label:s,shortcut:mW(`⌘B`)}),children:(0,$.jsx)(nc,{className:`w-4 h-4`})})]}),(0,$.jsxs)(`nav`,{className:`flex-1 py-2 px-1.5 space-y-0.5`,children:[(0,$.jsx)(QP,{expanded:a}),c.map(({to:e,end:t,icon:n,label:r})=>(0,$.jsxs)(g,{to:e,end:t,className:({isActive:e})=>X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,a?`px-2`:`px-0 justify-center`,e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),title:a?void 0:r,children:[(0,$.jsx)(n,{className:`w-4 h-4 flex-shrink-0`}),a&&(0,$.jsx)(`span`,{className:`text-xs truncate`,children:r})]},e))]})]})}function OY(e,t){return e.error===`corrupted-bundle`?t(`setup:prerequisites.corruptedBundle`):e.installed?e.executable===!1?e.resolvedPath&&e.executionError?t(`setup:prerequisites.failedToExecuteAtWithError`,{path:e.resolvedPath,error:e.executionError}):e.resolvedPath?t(`setup:prerequisites.failedToExecuteAt`,{path:e.resolvedPath}):e.executionError?t(`setup:prerequisites.failedToExecuteWithError`,{error:e.executionError}):t(`setup:prerequisites.failedToExecute`):!e.meetsMinimum&&e.minVersion?t(`setup:prerequisites.needsMinimum`,{version:e.version??t(`setup:prerequisites.unknownVersion`),minVersion:e.minVersion}):e.version??t(`setup:prerequisites.installedLabel`):t(`setup:prerequisites.notInstalled`)}function kY({status:e,isLoading:t,error:n,onRefresh:r,onMoreInfo:i}){let{t:a}=K(`setup`);if(t&&!e)return(0,$.jsx)(`div`,{"data-testid":`prerequisites-panel`,"data-state":`loading`,className:`rounded-lg border border-border/30 bg-background/30 px-3 py-2`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-muted-foreground/20 animate-pulse`}),(0,$.jsx)(`div`,{className:`h-3 w-32 rounded bg-muted-foreground/15 animate-pulse`})]})});if(n&&!e)return(0,$.jsx)(`div`,{"data-testid":`prerequisites-panel`,"data-state":`error`,className:`rounded-lg border border-border/40 bg-background/40 px-3 py-2`,children:(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:a(`prerequisites.verifyError`)})});if(!e)return null;if(e.ok)return(0,$.jsx)(`div`,{"data-testid":`prerequisites-panel`,"data-state":`ok`,className:`rounded-lg border border-accent-success/25 bg-accent-success/5 px-3 py-2`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,$.jsx)($o,{className:`w-4 h-4 text-accent-success flex-shrink-0`}),(0,$.jsx)(`p`,{className:`text-xs font-medium text-foreground`,children:a(`prerequisites.allDetected`)})]}),r&&(0,$.jsxs)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:r,disabled:t,className:`h-7 px-2 gap-1.5 text-[11px] flex-shrink-0`,children:[(0,$.jsx)(mc,{className:X(`w-3 h-3`,t&&`animate-spin`)}),a(`common:actions.refresh`)]})]})});let o=e.missingRequired?.length??0,s=o>0&&(e.missingRequired??[]).every(e=>e.error===`corrupted-bundle`),c=(e.missingRequired??[]).some(e=>e.error===`corrupted-bundle`);return(0,$.jsxs)(`div`,{"data-testid":`prerequisites-panel`,"data-state":`missing`,className:X(`rounded-lg border px-3 py-2`,c?`border-destructive/40 bg-destructive/10`:`border-accent-primary/40 bg-accent-primary/10`),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,$.jsx)(zn,{className:X(`w-4 h-4 flex-shrink-0`,c?`text-destructive`:`text-accent-primary`)}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-foreground`,children:s?a(`prerequisites.bundleCorruptedTitle`):a(`prerequisites.toolsRequired`,{count:o})}),(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:a(s?`prerequisites.reinstallHint`:`prerequisites.installMissingHint`)})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[i&&!s&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:i,className:`h-7 px-2 gap-1.5 text-[11px]`,"data-testid":`prerequisites-more-info`,children:a(`prerequisites.moreInfo`)}),r&&(0,$.jsxs)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:r,disabled:t,className:`h-7 px-2 gap-1.5 text-[11px]`,children:[(0,$.jsx)(mc,{className:X(`w-3 h-3`,t&&`animate-spin`)}),a(`common:actions.refresh`)]})]})]}),(0,$.jsx)(`ul`,{className:`mt-2 space-y-1`,children:e.prerequisites.map(e=>{let t=e.error===`corrupted-bundle`,n=e.bundled===!0&&e.executable===!0&&!t,r=!t&&e.installed&&e.meetsMinimum,i=e.key===`gh`||e.key===`uv`,o=!r&&!t&&i;return(0,$.jsxs)(`li`,{"data-testid":`prereq-row-${e.key}`,"data-ok":r?`true`:`false`,"data-bundled":e.bundled?`true`:void 0,"data-corrupted":t?`true`:void 0,className:X(`flex items-center gap-2 rounded-md border px-2 py-1.5 text-[11px]`,t?`border-destructive/40 bg-destructive/10 text-foreground`:r||o?`border-border/30 bg-background/30 text-muted-foreground`:`border-accent-primary/30 bg-background/50 text-foreground`),children:[t?(0,$.jsx)(Tn,{className:`w-3.5 h-3.5 text-destructive flex-shrink-0`}):n||r?(0,$.jsx)($o,{className:`w-3.5 h-3.5 text-accent-success flex-shrink-0`}):o?(0,$.jsx)(Tn,{className:`w-3.5 h-3.5 text-muted-foreground/60 flex-shrink-0`}):(0,$.jsx)(Tn,{className:`w-3.5 h-3.5 text-accent-primary flex-shrink-0`}),(0,$.jsx)(`span`,{className:`font-medium`,children:e.label}),i&&(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:a(`prerequisites.optional`)}),e.key===`gh`&&e.executable&&e.authenticated===!1&&(0,$.jsx)(`span`,{"data-testid":`prereq-gh-noauth`,className:`inline-flex items-center rounded px-1 py-0.5 text-[10px] font-medium bg-accent-warning/15 text-accent-warning border border-accent-warning/30`,children:a(`prerequisites.ghNoAuth`)}),n&&(0,$.jsxs)(`span`,{"data-testid":`prereq-bundled-badge-${e.key}`,className:`inline-flex items-center gap-0.5 rounded px-1 py-0.5 text-[10px] font-medium bg-accent-secondary/20 text-accent-secondary border border-accent-secondary/30`,children:[(0,$.jsx)($s,{className:`w-2.5 h-2.5`}),a(`prerequisites.bundledBadge`)]}),(0,$.jsxs)(`span`,{className:X(`text-muted-foreground`,t&&`text-destructive/80`),children:[`— `,OY(e,a)]})]},e.key)})})]})}function AY(e){return{darwin:{title:`macOS`,intro:e(`setup:instructions.darwin.intro`),commands:[{label:e(`setup:instructions.darwin.installNodeGit`),command:`brew install node git`}],links:[{label:e(`setup:instructions.links.nodeOfficial`),url:`https://nodejs.org/en/download`},{label:e(`setup:instructions.links.gitOfficial`),url:`https://git-scm.com/downloads`},{label:`Homebrew`,url:`https://brew.sh`}]},win32:{title:`Windows`,intro:e(`setup:instructions.win32.intro`),commands:[{label:e(`setup:instructions.win32.installNode`),command:`winget install OpenJS.NodeJS.LTS`},{label:e(`setup:instructions.win32.installGit`),command:`winget install Git.Git`}],links:[{label:e(`setup:instructions.links.nodeOfficial`),url:`https://nodejs.org/en/download`},{label:e(`setup:instructions.links.gitWindows`),url:`https://git-scm.com/download/win`}],note:e(`setup:instructions.win32.note`)},linux:{title:`Linux`,intro:e(`setup:instructions.linux.intro`),commands:[{label:e(`setup:instructions.linux.debian`),command:`sudo apt install -y nodejs npm git`},{label:e(`setup:instructions.linux.fedora`),command:`sudo dnf install -y nodejs npm git`}],links:[{label:e(`setup:instructions.links.nodeOfficial`),url:`https://nodejs.org/en/download`},{label:e(`setup:instructions.links.gitOfficial`),url:`https://git-scm.com/downloads`}]}}}var jY=[`darwin`,`win32`,`linux`];async function MY(e){try{if(navigator.clipboard&&typeof navigator.clipboard.writeText==`function`)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function NY({command:e}){let{t}=K(`setup`),[n,r]=(0,Q.useState)(!1);return(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:async()=>{await MY(e)&&(r(!0),window.setTimeout(()=>r(!1),1500))},className:`h-7 px-2 gap-1.5 text-[11px]`,"data-testid":`install-copy-button`,children:n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Sn,{className:`w-3 h-3`}),t(`common:actions.copied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ls,{className:`w-3 h-3`}),t(`common:actions.copy`)]})})}function PY({platform:e,primary:t}){let{t:n}=K(`setup`),r=AY(n)[e];return(0,$.jsxs)(`section`,{"data-testid":`install-section-${e}`,className:X(`rounded-lg border px-3 py-3`,t?`border-border/40 bg-background/40`:`border-border/20 bg-background/20`),children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:r.title}),r.intro&&(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:r.intro}),(0,$.jsx)(`div`,{className:`mt-2 space-y-2`,children:r.commands.map(e=>(0,$.jsxs)(`div`,{className:`rounded-md border border-border/30 bg-background/60 px-2 py-2`,children:[(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-1`,children:e.label}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`code`,{className:`text-xs text-foreground font-mono break-all`,children:e.command}),(0,$.jsx)(NY,{command:e.command})]})]},e.command))}),r.links.length>0&&(0,$.jsx)(`ul`,{className:`mt-2 flex flex-wrap gap-x-3 gap-y-1`,children:r.links.map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-[11px] text-accent-info hover:underline`,children:[e.label,(0,$.jsx)(pn,{className:`w-3 h-3`})]})},e.url))}),r.note&&(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-accent-highlight`,children:r.note})]})}function FY(){let{t:e}=K(`setup`),[t,n]=(0,Q.useState)(`idle`);return(0,$.jsxs)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:async()=>{n(`copying`);try{let e=await fetch(`${Xe}/api/setup-prerequisites?diagnostic=1`);if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();await navigator.clipboard.writeText(JSON.stringify(t,null,2)),n(`copied`),setTimeout(()=>n(`idle`),1800)}catch{n(`error`),setTimeout(()=>n(`idle`),2400)}},disabled:t===`copying`,className:`gap-1.5 text-[11px]`,"data-testid":`copy-diagnostics-button`,children:[t===`copied`?(0,$.jsx)(Sn,{className:`w-3 h-3 text-accent-success`}):(0,$.jsx)(ns,{className:`w-3 h-3`}),e(t===`copied`?`instructions.diagnostics.copied`:t===`error`?`instructions.diagnostics.failed`:`instructions.diagnostics.copy`)]})}function IY({open:e,onClose:t,status:n,onRecheck:r,isRechecking:i}){let{t:a}=K(`setup`),[o,s]=(0,Q.useState)(!1),c=n?.platform??`darwin`,l=jY.filter(e=>e!==c);return n?.missingRequired?.some(e=>e.error===`corrupted-bundle`)??!1?(0,$.jsx)(mr,{open:e,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(fr,{movableResizable:!0,className:`max-w-xl`,"data-testid":`install-modal-corrupted-bundle`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:a(`instructions.corrupted.title`)}),(0,$.jsx)(ir,{children:a(`instructions.corrupted.description`)})]}),(0,$.jsx)(`p`,{className:`text-sm text-foreground`,children:a(`instructions.corrupted.body`)}),(0,$.jsx)(`div`,{className:`flex justify-end mt-2`,children:(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,"data-testid":`install-corrupted-close-button`,children:a(`common:actions.close`)})})]})}):(0,$.jsx)(mr,{open:e,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(fr,{movableResizable:!0,className:`max-w-xl`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:a(`instructions.title`)}),(0,$.jsx)(ir,{children:a(`instructions.description`)})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(PY,{platform:c,primary:!0}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:`text-[11px] text-muted-foreground hover:text-foreground underline-offset-2 hover:underline`,"data-testid":`install-toggle-others`,children:a(o?`instructions.hideOtherPlatforms`:`instructions.showOtherPlatforms`)}),o&&(0,$.jsx)(`div`,{className:`space-y-3`,children:l.map(e=>(0,$.jsx)(PY,{platform:e,primary:!1},e))})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mt-2`,children:[(0,$.jsx)(FY,{}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,children:a(`common:actions.close`)}),(0,$.jsxs)(Z,{type:`button`,variant:`default`,size:`sm`,onClick:r,disabled:i,className:`gap-1.5`,"data-testid":`install-recheck-button`,children:[(0,$.jsx)(mc,{className:X(`w-3 h-3`,i&&`animate-spin`)}),a(`instructions.recheck`)]})]})]})]})})}var LY=typeof window<`u`&&`__TAURI_INTERNALS__`in window;function RY({open:e,onClose:t,onOpenBuilder:n}){let r=se&&!!n,[i,a]=(0,Q.useState)(r?`choose`:`existing`),[o,s]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)([]),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)({claude:!0}),[_,v]=(0,Q.useState)(!1),{t:y}=K(`setup`),{addProject:b}=pt(),{status:x,isLoading:S,error:C,recheck:w}=rM(),T=(0,Q.useMemo)(()=>{if(!x||x.ok)return null;let e=x.missingRequired.map(e=>e.label);return e.length===0?null:y(`addProject.toolsRequired`,{tools:e.join(`, `),count:e.length})},[x,y]),E=x!==null&&!x.ok&&!C;(0,Q.useEffect)(()=>{e&&fetch(`/api/available-providers`).then(e=>e.json()).then(e=>{let t={};for(let[n,r]of Object.entries(e))n===`tiers`||n===`providerIssues`||n===`launchDescriptors`||typeof r==`boolean`&&(t[n]=r);g(t)}).catch(()=>{})},[e]);async function D(){let e=o.trim();if(!e){J.error(y(`addProject.errors.pathRequired`));return}m(!0);try{let t=d.map(e=>({path:e.trim()})).filter(e=>e.path),n=t.length?await b(e,l.trim()||void 0,void 0,t):await b(e,l.trim()||void 0);if(!n)return;J.success(y(`addProject.toasts.registered`,{name:n.project.name})),O()}catch(e){J.error(y(`addProject.errors.addFailed`),{description:e.message})}finally{m(!1)}}function O(){s(``),u(``),f([]),a(r?`choose`:`existing`),t()}function k(e){e||O()}let A=!Object.values(h).some(Boolean);return i===`choose`?(0,$.jsx)(mr,{open:e,onOpenChange:k,children:(0,$.jsxs)(fr,{className:`max-w-md`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsxs)(sr,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Ts,{className:`w-4 h-4`}),y(`addProject.title`)]}),(0,$.jsx)(ir,{children:y(`addProject.chooser.description`)})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 py-2`,children:[(0,$.jsxs)(`button`,{type:`button`,"data-testid":`chooser-existing`,onClick:()=>a(`existing`),className:`flex flex-col items-start gap-2 rounded-lg border border-border/40 p-4 text-left transition-colors hover:border-accent-primary/50 hover:bg-accent-primary/5 focus:outline-none focus-visible:ring-1 focus-visible:ring-ring`,children:[(0,$.jsx)(ws,{className:`h-5 w-5 text-accent-info`}),(0,$.jsx)(`span`,{className:`text-sm font-medium`,children:y(`addProject.chooser.existingTitle`)}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:y(`addProject.chooser.existingDescription`)})]}),(0,$.jsxs)(`button`,{type:`button`,"data-testid":`chooser-new`,onClick:()=>{O(),n?.()},className:`flex flex-col items-start gap-2 rounded-lg border border-border/40 p-4 text-left transition-colors hover:border-accent-highlight/50 hover:bg-accent-highlight/5 focus:outline-none focus-visible:ring-1 focus-visible:ring-ring`,children:[(0,$.jsx)(Ln,{className:`h-5 w-5 text-accent-highlight`}),(0,$.jsx)(`span`,{className:`text-sm font-medium`,children:y(`addProject.chooser.newTitle`)}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:y(`addProject.chooser.newDescription`)})]})]})]})}):(0,$.jsx)(mr,{open:e,onOpenChange:k,children:(0,$.jsxs)(fr,{movableResizable:!0,className:`max-h-[calc(100vh-2rem)] w-[calc(100vw-2rem)] max-w-2xl overflow-x-hidden`,"data-testid":`existing-project-dialog`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsxs)(sr,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Ts,{className:`w-4 h-4`}),y(`addProject.title`)]}),(0,$.jsx)(ir,{children:y(`addProject.description`)})]}),A&&(0,$.jsx)(`p`,{className:`text-xs text-destructive bg-destructive/10 rounded-md p-2`,children:y(`addProject.noProviderDetected`)}),(0,$.jsx)(kY,{status:x,isLoading:S,error:C,onMoreInfo:()=>v(!0),onRefresh:w}),(0,$.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium`,children:[y(`addProject.pathLabel`),` `,(0,$.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Jj,{placeholder:y(`addProject.pathPlaceholder`),value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&D()},autoFocus:!0,className:`flex-1`}),LY&&(0,$.jsx)(Z,{type:`button`,variant:`outline`,size:`icon`,className:`shrink-0`,title:y(`addProject.browseForFolder`),onClick:async()=>{try{let{open:e}=await c(async()=>{let{open:e}=await import(`./dist-js-CJ_2XX1Y.js`);return{open:e}},__vite__mapDeps([87,0,1])),t=await e({directory:!0,multiple:!1,title:y(`addProject.selectProjectFolder`)});typeof t==`string`&&t&&(s(t),l||u(t.split(`/`).filter(Boolean).pop()??``))}catch{}},children:(0,$.jsx)(Ts,{className:`w-4 h-4`})})]}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:y(`addProject.pathHint`)})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium`,children:[y(`addProject.nameLabel`),` `,(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:y(`addProject.optional`)})]}),(0,$.jsx)(Jj,{placeholder:y(`addProject.namePlaceholder`),value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&D()}}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:y(`addProject.nameHint`)})]}),(0,$.jsxs)(`fieldset`,{className:`space-y-2`,disabled:p,children:[(0,$.jsx)(`legend`,{className:`text-xs font-medium`,children:y(`common:repositories.additional`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:y(`common:repositories.sharedBacklog`)}),d.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Jj,{"aria-label":y(`common:repositories.folderNumber`,{number:t+2}),value:e,placeholder:y(`addProject.pathPlaceholder`),onChange:e=>f(n=>n.map((n,r)=>r===t?e.target.value:n))}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":y(`common:repositories.removeFolder`),onClick:()=>f(e=>e.filter((e,n)=>n!==t)),children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})]},t)),(0,$.jsxs)(Z,{type:`button`,variant:`outline`,size:`sm`,onClick:async()=>{if(LY)try{let{open:e}=await c(async()=>{let{open:e}=await import(`./dist-js-CJ_2XX1Y.js`);return{open:e}},__vite__mapDeps([87,0,1])),t=await e({directory:!0,multiple:!0});t&&f(e=>[...e,...Array.isArray(t)?t:[t]]);return}catch{}f(e=>[...e,``])},children:[(0,$.jsx)(Pn,{className:`mr-1 h-3.5 w-3.5`}),y(`common:repositories.addFolder`)]})]})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,disabled:p,children:y(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,onClick:D,disabled:p||!o.trim()||E||S,title:E?T??void 0:void 0,"data-testid":`add-project-submit`,children:y(p?`addProject.adding`:`addProject.submit`)})]}),(0,$.jsx)(IY,{open:_,onClose:()=>v(!1),status:x,onRecheck:w,isRechecking:S})]})})}var zY=1,BY=.9,VY=.8,HY=.17,UY=.1,WY=.999,GY=.9999,KY=.99,qY=/[\\\/_+.#"@\[\(\{&]/,JY=/[\\\/_+.#"@\[\(\{&]/g,YY=/[\s-]/,XY=/[\s-]/g;function ZY(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?zY:KY;var s=`${i},${a}`;if(o[s]!==void 0)return o[s];for(var c=r.charAt(a),l=n.indexOf(c,i),u=0,d,f,p,m;l>=0;)d=ZY(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=zY:qY.test(e.charAt(l-1))?(d*=VY,p=e.slice(i,l-1).match(JY),p&&i>0&&(d*=WY**+p.length)):YY.test(e.charAt(l-1))?(d*=BY,m=e.slice(i,l-1).match(XY),m&&i>0&&(d*=WY**+m.length)):(d*=HY,i>0&&(d*=WY**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=GY)),(d<UY&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=ZY(e,t,n,r,l+1,a+2,o),f*UY>d&&(d=f*UY)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function QY(e){return e.toLowerCase().replace(XY,` `)}function $Y(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,ZY(e,t,QY(e),QY(t),0,0,{})}var eX=`[cmdk-group=""]`,tX=`[cmdk-group-items=""]`,nX=`[cmdk-group-heading=""]`,rX=`[cmdk-item=""]`,iX=`${rX}:not([aria-disabled="true"])`,aX=`cmdk-item-select`,oX=`data-value`,sX=(e,t,n)=>$Y(e,t,n),cX=Q.createContext(void 0),lX=()=>Q.useContext(cX),uX=Q.createContext(void 0),dX=()=>Q.useContext(uX),fX=Q.createContext(void 0),pX=Q.forwardRef((e,t)=>{let n=DX(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=DX(()=>new Set),i=DX(()=>new Map),a=DX(()=>new Map),o=DX(()=>new Set),s=TX(e),{label:c,children:l,value:u,onValueChange:d,filter:f,shouldFilter:p,loop:m,disablePointerSelection:h=!1,vimBindings:g=!0,..._}=e,v=Yn(),y=Yn(),b=Yn(),x=Q.useRef(null),S=AX();EX(()=>{if(u!==void 0){let e=u.trim();n.current.value=e,C.emit()}},[u]),EX(()=>{S(6,k)},[]);let C=Q.useMemo(()=>({subscribe:e=>(o.current.add(e),()=>o.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,a,o;if(!Object.is(n.current[e],t)){if(n.current[e]=t,e===`search`)O(),E(),S(1,D);else if(e===`value`){if(document.activeElement.hasAttribute(`cmdk-input`)||document.activeElement.hasAttribute(`cmdk-root`)){let e=document.getElementById(b);e?e.focus():(i=document.getElementById(v))==null||i.focus()}if(S(7,()=>{n.current.selectedItemId=A()?.id,C.emit()}),r||S(5,k),s.current?.value!==void 0){let e=t??``;(o=(a=s.current).onValueChange)==null||o.call(a,e);return}}C.emit()}},emit:()=>{o.current.forEach(e=>e())}}),[]),w=Q.useMemo(()=>({value:(e,t,r)=>{t!==a.current.get(e)?.value&&(a.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,T(t,r)),S(2,()=>{E(),C.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),S(3,()=>{O(),E(),n.current.value||D(),C.emit()}),()=>{a.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=A();S(4,()=>{O(),t?.getAttribute(`id`)===e&&D(),C.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{a.current.delete(e),i.current.delete(e)}),filter:()=>s.current.shouldFilter,label:c||e[`aria-label`],getDisablePointerSelection:()=>s.current.disablePointerSelection,listId:v,inputId:b,labelId:y,listInnerRef:x}),[]);function T(e,t){let r=s.current?.filter??sX;return e?r(e,n.current.search,t):0}function E(){if(!n.current.search||s.current.shouldFilter===!1)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),a=0;r.forEach(t=>{let n=e.get(t);a=Math.max(n,a)}),t.push([n,a])});let r=x.current;j().sort((t,n)=>{let r=t.getAttribute(`id`),i=n.getAttribute(`id`);return(e.get(i)??0)-(e.get(r)??0)}).forEach(e=>{let t=e.closest(tX);t?t.appendChild(e.parentElement===t?e:e.closest(`${tX} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${tX} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=x.current?.querySelector(`${eX}[${oX}="${encodeURIComponent(e[0])}"]`);t?.parentElement.appendChild(t)})}function D(){let e=j().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(oX);C.setState(`value`,e||void 0)}function O(){if(!n.current.search||s.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let e=0;for(let t of r.current){let r=T(a.current.get(t)?.value??``,a.current.get(t)?.keywords??[]);n.current.filtered.items.set(t,r),r>0&&e++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=e}function k(){var e;let t=A();t&&(t.parentElement?.firstChild===t&&((e=t.closest(eX)?.querySelector(nX))==null||e.scrollIntoView({block:`nearest`})),t.scrollIntoView({block:`nearest`}))}function A(){return x.current?.querySelector(`${rX}[aria-selected="true"]`)}function j(){return Array.from(x.current?.querySelectorAll(iX)||[])}function M(e){let t=j()[e];t&&C.setState(`value`,t.getAttribute(oX))}function N(e){var t;let n=A(),r=j(),i=r.findIndex(e=>e===n),a=r[i+e];(t=s.current)!=null&&t.loop&&(a=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),a&&C.setState(`value`,a.getAttribute(oX))}function P(e){let t=A()?.closest(eX),n;for(;t&&!n;)t=e>0?CX(t,eX):wX(t,eX),n=t?.querySelector(iX);n?C.setState(`value`,n.getAttribute(oX)):N(e)}let F=()=>M(j().length-1),I=e=>{e.preventDefault(),e.metaKey?F():e.altKey?P(1):N(1)},L=e=>{e.preventDefault(),e.metaKey?M(0):e.altKey?P(-1):N(-1)};return Q.createElement(Un.div,{ref:t,tabIndex:-1,..._,"cmdk-root":``,onKeyDown:e=>{var t;(t=_.onKeyDown)==null||t.call(_,e);let n=e.nativeEvent.isComposing||e.keyCode===229;if(!(e.defaultPrevented||n))switch(e.key){case`n`:case`j`:g&&e.ctrlKey&&I(e);break;case`ArrowDown`:I(e);break;case`p`:case`k`:g&&e.ctrlKey&&L(e);break;case`ArrowUp`:L(e);break;case`Home`:e.preventDefault(),M(0);break;case`End`:e.preventDefault(),F();break;case`Enter`:{e.preventDefault();let t=A();if(t){let e=new Event(aX);t.dispatchEvent(e)}}}}},Q.createElement(`label`,{"cmdk-label":``,htmlFor:w.inputId,id:w.labelId,style:NX},c),MX(e,e=>Q.createElement(uX.Provider,{value:C},Q.createElement(cX.Provider,{value:w},e))))}),mX=Q.forwardRef((e,t)=>{let n=Yn(),r=Q.useRef(null),i=Q.useContext(fX),a=lX(),o=TX(e),s=o.current?.forceMount??i?.forceMount;EX(()=>{if(!s)return a.item(n,i?.id)},[s]);let c=kX(n,r,[e.value,e.children,r],e.keywords),l=dX(),u=OX(e=>e.value&&e.value===c.current),d=OX(e=>s||a.filter()===!1?!0:!e.search||e.filtered.items.get(n)>0);Q.useEffect(()=>{let t=r.current;if(!(!t||e.disabled))return t.addEventListener(aX,f),()=>t.removeEventListener(aX,f)},[d,e.onSelect,e.disabled]);function f(){var e,t;p(),(t=(e=o.current).onSelect)==null||t.call(e,c.current)}function p(){l.setState(`value`,c.current,!0)}if(!d)return null;let{disabled:m,value:h,onSelect:g,forceMount:_,keywords:v,...y}=e;return Q.createElement(Un.div,{ref:or(r,t),...y,id:n,"cmdk-item":``,role:`option`,"aria-disabled":!!m,"aria-selected":!!u,"data-disabled":!!m,"data-selected":!!u,onPointerMove:m||a.getDisablePointerSelection()?void 0:p,onClick:m?void 0:f},e.children)}),hX=Q.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...a}=e,o=Yn(),s=Q.useRef(null),c=Q.useRef(null),l=Yn(),u=lX(),d=OX(e=>i||u.filter()===!1?!0:!e.search||e.filtered.groups.has(o));EX(()=>u.group(o),[]),kX(o,s,[e.value,e.heading,c]);let f=Q.useMemo(()=>({id:o,forceMount:i}),[i]);return Q.createElement(Un.div,{ref:or(s,t),...a,"cmdk-group":``,role:`presentation`,hidden:!d||void 0},n&&Q.createElement(`div`,{ref:c,"cmdk-group-heading":``,"aria-hidden":!0,id:l},n),MX(e,e=>Q.createElement(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?l:void 0},Q.createElement(fX.Provider,{value:f},e))))}),gX=Q.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=Q.useRef(null),a=OX(e=>!e.search);return!n&&!a?null:Q.createElement(Un.div,{ref:or(i,t),...r,"cmdk-separator":``,role:`separator`})}),_X=Q.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=e.value!=null,a=dX(),o=OX(e=>e.search),s=OX(e=>e.selectedItemId),c=lX();return Q.useEffect(()=>{e.value!=null&&a.setState(`search`,e.value)},[e.value]),Q.createElement(Un.input,{ref:t,...r,"cmdk-input":``,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,"aria-autocomplete":`list`,role:`combobox`,"aria-expanded":!0,"aria-controls":c.listId,"aria-labelledby":c.labelId,"aria-activedescendant":s,id:c.inputId,type:`text`,value:i?e.value:o,onChange:e=>{i||a.setState(`search`,e.target.value),n?.(e.target.value)}})}),vX=Q.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...i}=e,a=Q.useRef(null),o=Q.useRef(null),s=OX(e=>e.selectedItemId),c=lX();return Q.useEffect(()=>{if(o.current&&a.current){let e=o.current,t=a.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty(`--cmdk-list-height`,n.toFixed(1)+`px`)})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),Q.createElement(Un.div,{ref:or(a,t),...i,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:c.listId},MX(e,e=>Q.createElement(`div`,{ref:or(o,c.listInnerRef),"cmdk-list-sizer":``},e)))}),yX=Q.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return Q.createElement(dr,{open:n,onOpenChange:r},Q.createElement(tr,{container:o},Q.createElement(er,{"cmdk-overlay":``,className:i}),Q.createElement(hr,{"aria-label":e.label,"cmdk-dialog":``,className:a},Q.createElement(pX,{ref:t,...s}))))}),bX=Q.forwardRef((e,t)=>OX(e=>e.filtered.count===0)?Q.createElement(Un.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),xX=Q.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return Q.createElement(Un.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},MX(e,e=>Q.createElement(`div`,{"aria-hidden":!0},e)))}),SX=Object.assign(pX,{List:vX,Item:mX,Input:_X,Group:hX,Separator:gX,Dialog:yX,Empty:bX,Loading:xX});function CX(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function wX(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function TX(e){let t=Q.useRef(e);return EX(()=>{t.current=e}),t}var EX=typeof window>`u`?Q.useEffect:Q.useLayoutEffect;function DX(e){let t=Q.useRef();return t.current===void 0&&(t.current=e()),t}function OX(e){let t=dX(),n=()=>e(t.snapshot());return Q.useSyncExternalStore(t.subscribe,n,n)}function kX(e,t,n,r=[]){let i=Q.useRef(),a=lX();return EX(()=>{var o;let s=(()=>{for(let e of n){if(typeof e==`string`)return e.trim();if(typeof e==`object`&&`current`in e)return e.current?e.current.textContent?.trim():i.current}})(),c=r.map(e=>e.trim());a.value(e,s,c),(o=t.current)==null||o.setAttribute(oX,s),i.current=s}),i}var AX=()=>{let[e,t]=Q.useState(),n=DX(()=>new Map);return EX(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function jX(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function MX({asChild:e,children:t},n){return e&&Q.isValidElement(t)?Q.cloneElement(jX(t),{ref:t.ref},n(t.props.children)):n(t)}var NX={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`};function PX(e){return e.normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).toLowerCase()}function FX(e,t,n=[]){let r=PX(e.trim());return!r||PX(t).includes(r)?!0:n.some(e=>e&&PX(e).includes(r))}function IX(e,t){return Kb(t.updated_at)-Kb(e.updated_at)}function LX(e,t=8){return[...e].sort(IX).slice(0,Math.max(0,t)).map(e=>({conversation:e,match:`recent`,messageId:null,snippet:null}))}function RX(e,t,n,r=20){let i=PX(t.trim());if(!i)return[];let a=PX(n);return[...e].sort(IX).filter(e=>PX(e.title?.trim()||``).includes(i)||!e.title?.trim()&&a.includes(i)).slice(0,Math.max(0,r)).map(e=>({conversation:e,match:`title`,messageId:null,snippet:null}))}function zX(e,t,n=20){let r=new Map;for(let e of t)r.has(e.conversation.id)||r.set(e.conversation.id,e);let i=[],a=new Set;for(let t of e){let e=r.get(t.conversation.id);i.push(e?{conversation:e.conversation,match:`title`,messageId:e.messageId,snippet:e.snippet}:t),a.add(t.conversation.id)}for(let e of[`title`,`content`])for(let n of t)n.match!==e||a.has(n.conversation.id)||(a.add(n.conversation.id),i.push({conversation:n.conversation,match:n.match,messageId:n.messageId,snippet:n.snippet}));return i.slice(0,Math.max(0,n))}function BX(e){return e===`agent`?[`missions`,`projects`,`spec`,`jobs`,`navigation`]:[`projects`,`missions`,`spec`,`jobs`,`navigation`]}var VX=[];function HX(e){let t=[],n=0;return e.ranges.forEach(([r,i],a)=>{r>n&&t.push(e.text.slice(n,r)),t.push((0,$.jsx)(`mark`,{className:`rounded-sm bg-accent-primary/20 px-0.5 text-foreground`,children:e.text.slice(r,i)},a)),n=i}),n<e.text.length&&t.push(e.text.slice(n)),t}function UX({onOpenSettings:e,onOpenAnalytics:t,onOpenDocs:n}){let{t:r}=K(`commands`),{t:i}=K(`agent`),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)([]),[d,f]=(0,Q.useState)([]),[p,m]=(0,Q.useState)({query:``,hits:VX}),{projects:h,activeProjectId:g,setActiveProjectId:_}=pt(),{leftMode:v,rightMode:b,cycleLeftMode:x,cycleRightMode:S}=XP(),{uiMode:C}=MN(),{conversations:w,liveByConversation:T,selectConversation:E,open:D}=aP(),O=r(v===`pinned-open`?`palette.sidebar.collapseLeftKeepPinned`:v===`pinned-collapsed`?`palette.sidebar.unpinLeft`:`palette.sidebar.pinLeftOpen`),k=r(b===`pinned-open`?`palette.sidebar.collapseRightKeepPinned`:b===`pinned-collapsed`?`palette.sidebar.unpinRight`:`palette.sidebar.pinRightOpen`),A=y(),j=(0,Q.useRef)(!1),M=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{function e(e){e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),o(e=>!e))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,Q.useEffect)(()=>{if(!a){j.current=!1,c(``);return}if(j.current)return;j.current=!0;async function e(){try{let[e,t]=await Promise.all([fetch(`${ut()}/config`),fetch(`${ut()}/jobs?limit=10`)]);if(e.ok){let t=await e.json();u(t.commands)}if(t.ok){let e=await t.json();f(e.jobs)}}catch{}}e()},[a]),(0,Q.useEffect)(()=>{let e=s.trim(),t=++M.current;if(!a||!e)return;let n=new AbortController,r=setTimeout(()=>{to(e,20,n.signal).then(n=>{t===M.current&&m({query:e,hits:n})}).catch(()=>{})},80);return()=>{clearTimeout(r),n.abort()}},[s,a]);let N=i(`mission.untitled`),P=(0,Q.useMemo)(()=>{let e=s.trim();return e?zX(RX(w,e,N),p.query===e?p.hits:VX):LX(w)},[w,s,p,N]),F=(0,Q.useMemo)(()=>new Map(h.map(e=>[e.id,e.name])),[h]),I=(0,Q.useCallback)(e=>{_(e),o(!1)},[_]),L=(0,Q.useCallback)(e=>{o(!1),E(e),C!==`agent`&&D()},[E,D,C]),R=(0,Q.useCallback)(async e=>{o(!1);try{let t=await fetch(`${ut()}/spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({command:`/specrails:${e}`})}),n=await t.json();if(!t.ok)throw Error(n.error??r(`errors.spawnFailed`));J.success(r(`toasts.queued`,{name:e})),A(`/jobs/${n.jobId}`)}catch(e){J.error(e instanceof Error?e.message:r(`errors.spawnFailed`))}},[A,r]),z=(0,Q.useCallback)(e=>{o(!1),A(`/jobs/${e}`)},[A]),B=(0,Q.useCallback)(e=>{o(!1),A(e)},[A]),V=(0,Q.useCallback)(e=>{e&&(o(!1),e())},[]),H=`flex items-center gap-3 px-3 py-2 rounded-lg cursor-pointer text-sm data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground`,U=h.filter(e=>FX(s,e.name,[e.slug])),W=l.filter(e=>FX(s,e.name,[e.slug,e.description??``])),ee=d.filter(e=>FX(s,`${e.command} ${e.id}`,[e.status])),te=[{key:`dashboard`,label:r(`palette.nav.dashboard`),keywords:[`home`],icon:(0,$.jsx)(Hs,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>B(`/`)},...t?[{key:`desktopAnalytics`,label:r(`palette.nav.desktopAnalytics`),keywords:[`cross-project`,`desktop`],icon:(0,$.jsx)(Jo,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>V(t)}]:[],{key:`projectAnalytics`,label:r(`palette.nav.projectAnalytics`),keywords:[`metrics`],icon:(0,$.jsx)(Ko,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>B(`/analytics`)},{key:`activityFeed`,label:r(`palette.nav.activityFeed`),keywords:[`log`],icon:(0,$.jsx)(No,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>B(`/activity`)},{key:`desktopSettings`,label:r(`palette.nav.desktopSettings`),keywords:[`configuration`],icon:(0,$.jsx)(Sc,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>e?V(e):B(`/settings`)},{key:`docs`,label:r(`palette.nav.docs`),keywords:[`documentation`],icon:(0,$.jsx)(Dn,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>n?V(n):B(`/docs`)},{key:`leftSidebar`,label:O,keywords:[`sidebar`,`panel`,`left`,`pin`,`collapse`,`unpin`,`cycle`],icon:(0,$.jsx)(tc,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>{x(),o(!1)}},{key:`rightSidebar`,label:k,keywords:[`sidebar`,`panel`,`right`,`nav`,`pin`,`collapse`,`unpin`,`cycle`],icon:(0,$.jsx)(nc,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>{S(),o(!1)}}].filter(e=>FX(s,e.label,e.keywords)),ne={missions:P.length>0&&(0,$.jsx)(SX.Group,{heading:r(`palette.groups.missions`),"data-testid":`palette-group-missions`,children:P.map(e=>{let{conversation:t}=e,n=T.get(t.id)?.isStreaming===!0,a=t.pinned_project_id?F.get(t.pinned_project_id)??null:null;return(0,$.jsxs)(SX.Item,{value:`mission:${t.id}`,onSelect:()=>L(t.id),className:X(H,`items-start`),"data-testid":`palette-mission-${t.id}`,children:[(0,$.jsx)(bn,{className:`w-4 h-4 mt-0.5 text-accent-primary shrink-0`}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:t.title?.trim()||N}),n&&(0,$.jsxs)(`span`,{"aria-label":i(`mission.working`),"data-testid":`palette-mission-live-${t.id}`,className:`relative flex h-1.5 w-1.5 shrink-0`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full bg-accent-primary opacity-60`}),(0,$.jsx)(`span`,{className:`relative inline-flex h-1.5 w-1.5 rounded-full bg-accent-primary`})]}),(0,$.jsx)(`span`,{className:`ml-auto shrink-0 text-[10px] tabular-nums text-muted-foreground/60`,title:Yb(t.updated_at),children:Jb(t.updated_at)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 text-[11px] text-muted-foreground/60`,children:[(0,$.jsx)(`span`,{className:`shrink-0`,children:a??r(`palette.missions.home`)}),e.snippet&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,$.jsx)(`span`,{className:`truncate`,"data-testid":`palette-mission-snippet-${t.id}`,children:HX(e.snippet)})]})]})]})]},t.id)})},`missions`),projects:U.length>0&&(0,$.jsx)(SX.Group,{heading:r(`palette.groups.projects`),"data-testid":`palette-group-projects`,children:U.map(e=>(0,$.jsxs)(SX.Item,{value:e.name,keywords:[e.slug],onSelect:()=>I(e.id),className:X(H,e.id===g&&`text-accent-primary`),children:[(0,$.jsx)(Ts,{className:`w-4 h-4 text-muted-foreground shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),e.id===g&&(0,$.jsx)(`span`,{className:`text-[10px] text-accent-primary font-medium`,children:r(`palette.activeBadge`)})]},e.id))},`projects`),spec:W.length>0&&(0,$.jsx)(SX.Group,{heading:r(`palette.groups.spec`),children:W.map(e=>(0,$.jsxs)(SX.Item,{value:e.name,keywords:[e.slug,e.description??``],onSelect:()=>R(e.slug),className:H,children:[(0,$.jsx)(wn,{className:`w-4 h-4 text-accent-info shrink-0`}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:e.name}),e.description&&(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground/60 ml-2 truncate`,children:e.description})]})]},e.id))},`spec`),jobs:ee.length>0&&(0,$.jsx)(SX.Group,{heading:r(`palette.groups.jobs`),children:ee.map(e=>(0,$.jsxs)(SX.Item,{value:`${e.command} ${e.id}`,keywords:[e.status],onSelect:()=>z(e.id),className:H,children:[(0,$.jsx)(Go,{className:`w-4 h-4 text-muted-foreground shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.command}),(0,$.jsx)(`span`,{className:X(`text-[10px] font-medium`,e.status===`completed`&&`text-accent-success`,e.status===`failed`&&`text-destructive`,e.status===`running`&&`text-accent-info`,e.status===`queued`&&`text-muted-foreground`),children:r(`common:status.${e.status}`,{defaultValue:e.status})})]},e.id))},`jobs`),navigation:te.length>0&&(0,$.jsx)(SX.Group,{heading:r(`palette.groups.navigation`),children:te.map(e=>(0,$.jsxs)(SX.Item,{value:e.label,keywords:e.keywords,onSelect:e.onSelect,className:H,children:[e.icon,(0,$.jsx)(`span`,{children:e.label})]},e.key))},`navigation`)};return(0,$.jsxs)(SX.Dialog,{open:a,onOpenChange:o,shouldFilter:!1,label:r(`palette.label`),className:X(`fixed left-[50%] top-[50%] z-50 w-full max-w-lg translate-x-[-50%] translate-y-[-50%]`,`border border-border/30 bg-popover shadow-2xl backdrop-blur-md rounded-xl overflow-hidden`),children:[(0,$.jsx)(`span`,{className:`sr-only`,children:r(`palette.label`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 border-b border-border/30`,children:[(0,$.jsx)(In,{className:`w-4 h-4 text-muted-foreground shrink-0`}),(0,$.jsx)(SX.Input,{value:s,onValueChange:c,placeholder:r(C===`agent`?`palette.searchPlaceholderAgent`:`palette.searchPlaceholder`),className:`flex-1 h-11 bg-transparent text-sm outline-none placeholder:text-muted-foreground/50`}),(0,$.jsx)(`kbd`,{className:`hidden sm:inline-flex items-center gap-0.5 rounded border border-border/50 bg-muted/30 px-1.5 py-0.5 text-[10px] text-muted-foreground font-mono`,children:`esc`})]}),(0,$.jsxs)(SX.List,{className:`max-h-80 overflow-y-auto p-2`,children:[(0,$.jsx)(SX.Empty,{className:`py-8 text-center text-sm text-muted-foreground`,children:r(`palette.noResults`)}),BX(C).map(e=>ne[e])]}),(0,$.jsx)(`div`,{className:`flex items-center justify-between px-3 py-2 border-t border-border/30 text-[10px] text-muted-foreground/50`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`kbd`,{className:`font-mono`,children:`↑↓`}),` `,r(`palette.footer.navigate`)]}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`kbd`,{className:`font-mono`,children:`↵`}),` `,r(`palette.footer.select`)]}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`kbd`,{className:`font-mono`,children:`esc`}),` `,r(`palette.footer.close`)]})]})})]})}var WX=`
|
|
74
|
+
`);J.warning(n(`railPr.cleanupIncomplete`,{count:e.cleanupWarnings.length}),{description:`${n(`railPr.cleanupIncompleteHint`)}\n${t}`,duration:1/0,action:{label:n(`railPr.copyCleanupDetails`),onClick:()=>{navigator.clipboard?.writeText(t)}}})}else e.decision===`merged`?J.success(n(`railPr.mergedToast`)):e.decision===`discarded`?J.info(n(`railPr.discardedToast`)):e.decision===`completed`&&J.success(n(`railPr.completedToast`))}}else e.supersedesDeliveryId&&(m.current.add(e.supersedesDeliveryId),h.current.set(e.supersedesDeliveryId,e.prDeliveryId)),p&&a&&m.current.add(a.prDeliveryId);let v=new Map(r);return o?v.delete(e.railIndex):v.set(e.railIndex,e),f.current.set(e.railIndex,(f.current.get(e.railIndex)??0)+1),d.current=v,i(v),`accepted`},[n]),y=(0,Q.useCallback)(async(e,t)=>{let n=++p.current,r=new Map(f.current);try{let t=await fetch(`/api/projects/${e}/rails`);if(!t.ok)return;let a=await t.json();if(n!==p.current||u.current!==e)return;let o=new Map;for(let[e,t]of Object.entries(a.prDeliveries??{})){let n=QU(t,Number(e)),r=d.current.get(n?.railIndex??Number(e)),i=n?.restoredFromDeliveryId??null,a=n?h.current.get(n.prDeliveryId):void 0,s=n&&r?.supersedesDeliveryId===n.prDeliveryId?r.prDeliveryId:null,c=!!(n&&i&&_.current.get(n.prDeliveryId)!==i&&(!a||a===i)&&(!s||s===i));n&&!$U.has(n.decision)&&(c||!g.current.has(n.prDeliveryId)&&!m.current.has(n.prDeliveryId))&&o.set(Number(e),n)}let s=d.current,c=new Map(o);for(let[e,t]of f.current){if(t===(r.get(e)??0))continue;let n=s.get(e);n?c.set(e,n):c.delete(e)}for(let e of c.values()){e.supersedesDeliveryId&&(m.current.add(e.supersedesDeliveryId),h.current.set(e.supersedesDeliveryId,e.prDeliveryId));let t=e.restoredFromDeliveryId;t&&_.current.get(e.prDeliveryId)!==t&&(!h.current.get(e.prDeliveryId)||h.current.get(e.prDeliveryId)===t)&&(g.current.delete(e.prDeliveryId),m.current.delete(e.prDeliveryId),g.current.add(t),_.current.set(e.prDeliveryId,t),h.current.set(e.prDeliveryId,t))}d.current=c,i(c)}catch{}finally{t&&n===p.current&&u.current===e&&o(!0)}},[]);(0,Q.useEffect)(()=>{u.current=e,p.current++;let t=new Map;if(d.current=t,i(t),o(!1),f.current=new Map,m.current=new Set,h.current=new Map,g.current=new Set,_.current=new Map,!e){o(!0);return}y(e,!0)},[e,y]);let b=(0,Q.useCallback)(e=>{let t=e;if(!t||t.type!==`rail.pr_state`||t.projectId!==u.current||typeof t.railIndex!=`number`||typeof t.prDeliveryId!=`string`||!t.decision)return;let n=sn(t,t.railIndex);n&&v(n)},[v]);(0,Q.useLayoutEffect)(()=>(s(`rail-pr-decision`,b),()=>c(`rail-pr-decision`)),[b,s,c]),(0,Q.useEffect)(()=>{let e=()=>{let e=u.current;e&&y(e,!1)};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[y]);let x=(0,Q.useRef)(l);(0,Q.useEffect)(()=>{let e=x.current;x.current=l;let t=u.current;t&&l===`connected`&&e!==`connected`&&y(t,!1)},[l,y]);let S=(0,Q.useCallback)(async(e,t,n,r,i)=>{let a=d.current.get(e),o=u.current;if(!a||!o)return{status:0,ok:!1,error:`no_delivery`};if(a.prDeliveryId!==r)return{status:409,ok:!1,error:`stale_decision`,current:a.decision,snapshotApplication:`stale`};try{let e=await fetch(`/api/projects/${o}/rails/pr-decision`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prDeliveryId:a.prDeliveryId,action:t,expectedDecision:n,...i?{repositoryId:i}:{}})}),r=await e.json().catch(()=>({})),s=sn(r.snapshot),c;return s&&u.current===o?c=v(s):e.status===409&&r.error===`stale_decision`&&u.current===o&&y(o,!1),{...r,snapshot:s,snapshotApplication:c,busy:e.status===409&&r.error===`operation_in_progress`,operation:s?.operation??(typeof r.operation==`string`&&eW.has(r.operation)?r.operation:null),status:e.status,ok:e.ok&&r.ok===!0}}catch(e){return{status:0,ok:!1,error:`network`,detail:e.message}}},[v,y]),C=(0,Q.useCallback)(async(e,t,n)=>{let r=d.current.get(e),i=u.current;if(!r||!i)return{status:0,ok:!1,error:`no_delivery`};if(r.prDeliveryId!==t)return{status:409,ok:!1,error:`stale_decision`,detail:`The delivery generation changed before checkout.`};try{let e=await fetch(`/api/projects/${i}/rails/pr-checkout`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prDeliveryId:r.prDeliveryId,...n?{repositoryId:n}:{}})}),t=await e.json().catch(()=>({}));return{...t,status:e.status,ok:e.ok&&t.ok===!0}}catch(e){return{status:0,ok:!1,error:`network`,detail:e.message}}},[]),w=(0,Q.useMemo)(()=>({decisions:r,hydrated:a,act:S,checkout:C}),[r,a,S,C]);return(0,$.jsx)(XU.Provider,{value:w,children:t})}function rW(e){return e?`specrails-desktop:dashboard-split:${e}`:null}function iW(e){let t=rW(e);if(!t)return null;try{let e=localStorage.getItem(t);if(!e)return null;let n=Number.parseInt(e,10);return Number.isFinite(n)&&n>0?n:null}catch{return null}}function aW(e,t){let n=rW(e);if(n)try{localStorage.setItem(n,String(Math.round(t)))}catch{}}function oW(e,t){let n=Math.max(320,t-280);return Math.min(Math.max(e,320),n)}var sW=.7;function cW(e){return oW(Math.round(e*sW),e)}function lW(e,t){let n=cW(t);return Math.abs(e-n)<=48?n:e}function uW(e,t){let[n,r]=(0,Q.useState)(()=>typeof window<`u`?window.innerWidth:1200),i=(0,Q.useRef)(n),[a,o]=(0,Q.useState)(()=>{if(typeof window>`u`)return null;let e=window.innerWidth;return e<900?null:cW(e)}),s=(0,Q.useRef)(null),c=(0,Q.useRef)(null),l=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(typeof window>`u`)return;let e=t?.current?.clientWidth||window.innerWidth;if(r(e),i.current=e,e<900){o(null);return}o(cW(e))},[e,t]),(0,Q.useEffect)(()=>{function n(t){if(r(t),t<900){i.current=t,o(null);return}let n=t-i.current;i.current=t,o(r=>{let i=r??iW(e)??cW(t),a=oW(r!==null&&Number.isFinite(n)?i+n:i,t);return a!==r&&aW(e,a),a})}let a=t?.current;if(a&&typeof ResizeObserver<`u`){let e=new ResizeObserver(e=>{let t=e[0]?.contentRect.width;typeof t==`number`&&n(t)});return e.observe(a),n(a.clientWidth||window.innerWidth),()=>e.disconnect()}function s(){n(window.innerWidth)}return window.addEventListener(`resize`,s),()=>window.removeEventListener(`resize`,s)},[e,t]);let u=(0,Q.useCallback)(()=>{if(c.current=null,l.current===null)return;let e=oW(l.current,n);l.current=null,o(e)},[n]),d=(0,Q.useCallback)(e=>{if(!s.current)return;let t=e.clientX-s.current.startClientX;l.current=s.current.startLeftWidth+t,c.current===null&&(c.current=requestAnimationFrame(u))},[u]),f=(0,Q.useCallback)(t=>{if(!s.current)return;let{pointerId:r,element:i}=s.current;try{i.releasePointerCapture(r)}catch{}s.current=null,window.removeEventListener(`pointermove`,d),window.removeEventListener(`pointerup`,f),window.removeEventListener(`pointercancel`,f),o(t=>{if(t===null)return t;let r=oW(lW(t,n),n);return aW(e,r),r})},[d,e,n]),p=(0,Q.useCallback)(e=>{let t=e.nativeEvent??e,n=e.currentTarget??t.target;try{n.setPointerCapture(t.pointerId)}catch{}s.current={pointerId:t.pointerId,element:n,startClientX:t.clientX,startLeftWidth:a??0},window.addEventListener(`pointermove`,d),window.addEventListener(`pointerup`,f),window.addEventListener(`pointercancel`,f)},[d,f,a]),m=(0,Q.useCallback)(()=>{if(typeof window>`u`)return;let n=t?.current?.clientWidth||window.innerWidth;if(n<900)return;let r=cW(n);o(r),aW(e,r)},[e,t]);return{leftWidth:a,enabled:a!==null&&n>=900,beginDrag:p,resetToDefault:m}}function dW({leftWidth:e,onPointerDown:t,onReset:n,viewport:r}){let i=(0,Q.useCallback)(t=>{let n=t.shiftKey?64:16;t.key===`ArrowLeft`&&(t.preventDefault(),e-n)},[e]);return(0,$.jsxs)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-valuenow":e,"aria-valuemin":320,"aria-valuemax":Math.max(320,r-280),tabIndex:0,onPointerDown:t,onDoubleClick:n,onKeyDown:i,className:`relative w-1.5 shrink-0 cursor-col-resize group select-none touch-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-info/60`,"data-testid":`dashboard-splitter`,children:[(0,$.jsx)(`div`,{className:`absolute inset-y-0 left-1/2 -translate-x-1/2 w-px bg-border/40 group-hover:bg-accent-info/40 group-focus-visible:bg-accent-info/60 transition-colors`}),(0,$.jsxs)(`div`,{className:`absolute inset-y-0 left-1/2 -translate-x-1/2 flex flex-col items-center justify-center gap-1 pointer-events-none opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,$.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-accent-info/60`}),(0,$.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-accent-info/60`}),(0,$.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-accent-info/60`})]})]})}function fW({open:e,allLabels:t,onClose:n,onCreate:r}){let{t:i}=K(`tickets`),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(`todo`),[d,f]=(0,Q.useState)(`medium`),[p,m]=(0,Q.useState)([]),[h,g]=(0,Q.useState)(),[_,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(!1),x=(0,Q.useRef)(null),S=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{e&&setTimeout(()=>x.current?.focus(),100)},[e]),(0,Q.useEffect)(()=>{e||(o(``),c(``),u(`todo`),f(`medium`),m([]),g(void 0),v(``))},[e]);let C=(0,Q.useMemo)(()=>{if(!_.trim())return[];let e=_.toLowerCase();return t.filter(t=>t.toLowerCase().includes(e)&&!p.includes(t)).slice(0,5)},[_,t,p]),w=(0,Q.useCallback)(e=>{let t=e.trim();t&&!p.includes(t)&&m(e=>[...e,t]),v(``)},[p]),T=(0,Q.useCallback)(async()=>{if(!a.trim())return;b(!0);let e=await r({title:a.trim(),description:s.trim()||void 0,status:l,priority:d,labels:p.length>0?p:void 0,...h?{repositoryIds:h}:{}});b(!1),e?(J.success(i(`createModal.toast.created`)),n()):J.error(i(`createModal.toast.createFailed`))},[a,s,l,d,p,h,r,n,i]);return(0,$.jsx)(mr,{open:e,onOpenChange:e=>!e&&n(),children:(0,$.jsxs)(fr,{movableResizable:!0,className:`max-w-lg glass-card`,children:[(0,$.jsx)(ur,{children:(0,$.jsx)(sr,{children:i(`createModal.title`)})}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`label`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider block mb-1`,children:[i(`fields.title`),` `,(0,$.jsx)(`span`,{className:`text-red-400 aurora-light:text-destructive`,children:`*`})]}),(0,$.jsx)(`input`,{ref:x,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a.trim()&&T()},placeholder:i(`createModal.titlePlaceholder`),className:`w-full h-8 rounded border border-border bg-input px-3 text-xs text-foreground placeholder:text-muted-foreground`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider block mb-1`,children:i(`fields.description`)}),(0,$.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),rows:4,placeholder:i(`fields.markdownPlaceholder`),className:`w-full rounded border border-border bg-input px-3 py-2 text-xs text-foreground placeholder:text-muted-foreground resize-y min-h-[80px]`}),(0,$.jsx)(`span`,{className:`text-[9px] text-muted-foreground mt-0.5 block`,children:i(`fields.supportsMarkdown`)})]}),(0,$.jsxs)(`div`,{className:`flex gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex-1`,children:[(0,$.jsx)(`label`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider block mb-1`,children:i(`fields.status`)}),(0,$.jsxs)(`select`,{value:l,onChange:e=>u(e.target.value),className:`w-full h-7 rounded border border-border bg-input px-2 text-xs text-foreground`,children:[(0,$.jsx)(`option`,{value:`todo`,children:i(`ticketStatus.todo`)}),(0,$.jsx)(`option`,{value:`in_progress`,children:i(`ticketStatus.inProgress`)}),(0,$.jsx)(`option`,{value:`done`,children:i(`ticketStatus.done`)}),(0,$.jsx)(`option`,{value:`cancelled`,children:i(`ticketStatus.cancelled`)})]})]}),(0,$.jsxs)(`div`,{className:`flex-1`,children:[(0,$.jsx)(`label`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider block mb-1`,children:i(`fields.priority`)}),(0,$.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),className:`w-full h-7 rounded border border-border bg-input px-2 text-xs text-foreground`,children:[(0,$.jsx)(`option`,{value:`critical`,children:i(`priority.critical`)}),(0,$.jsx)(`option`,{value:`high`,children:i(`priority.high`)}),(0,$.jsx)(`option`,{value:`medium`,children:i(`priority.medium`)}),(0,$.jsx)(`option`,{value:`low`,children:i(`priority.low`)})]})]})]}),(0,$.jsx)(Dr,{value:h,onChange:g,disabled:y}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider block mb-1`,children:i(`fields.labels`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-1.5`,children:p.map(e=>(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded px-1.5 py-0.5 text-[10px] font-medium bg-accent/60 text-foreground/70`,children:[e,(0,$.jsx)(`button`,{type:`button`,onClick:()=>m(t=>t.filter(t=>t!==e)),className:`text-muted-foreground hover:text-foreground transition-colors`,children:(0,$.jsx)(Tn,{className:`w-2.5 h-2.5`})})]},e))}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`input`,{ref:S,value:_,onChange:e=>v(e.target.value),onKeyDown:e=>{e.key===`Enter`&&_.trim()&&(e.preventDefault(),w(_))},placeholder:i(`createModal.labelsPlaceholder`),className:`w-full h-6 rounded border border-border bg-input px-2 text-[10px] text-foreground placeholder:text-muted-foreground`}),C.length>0&&(0,$.jsx)(`div`,{className:`absolute left-0 right-0 top-full mt-0.5 rounded border border-border/50 bg-popover shadow-lg z-10 py-0.5`,children:C.map(e=>(0,$.jsx)(`button`,{type:`button`,onMouseDown:t=>{t.preventDefault(),w(e)},className:`w-full text-left px-2 py-1 text-[10px] hover:bg-accent/50 text-foreground/80`,children:e},e))})]})]})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:n,children:i(`common:actions.cancel`)}),(0,$.jsxs)(Z,{size:`sm`,onClick:T,disabled:y||!a.trim(),children:[(0,$.jsx)(Pn,{className:`w-3.5 h-3.5 mr-1`}),i(y?`createModal.creating`:`createModal.create`)]})]})]})})}function pW({open:e,railLabel:t,specCount:n,provider:r=`claude`,model:i,onConfirm:a,onCancel:o}){let{t:s}=K(`dashboard`),c=(0,Q.useRef)(null),l=jt(r);return(0,Q.useEffect)(()=>{if(!e)return;function t(e){(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),a())}return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,a]),(0,$.jsx)(mr,{open:e,onOpenChange:e=>{e||o()},children:(0,$.jsxs)(fr,{movableResizable:!0,showCloseButton:!1,className:`max-w-md gap-5`,onOpenAutoFocus:e=>{e.preventDefault(),c.current?.focus()},children:[(0,$.jsx)(ur,{children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-xl bg-accent-highlight/15 text-accent-highlight ring-1 ring-accent-highlight/30`,children:(0,$.jsx)(Ln,{className:`h-4.5 w-4.5`})}),(0,$.jsxs)(`div`,{className:`text-left`,children:[(0,$.jsx)(sr,{className:`text-base`,children:s(`freestyleDialog.title`)}),(0,$.jsxs)(ir,{children:[s(`freestyleDialog.context`,{rail:t,count:n}),i?` · ${i}`:``]})]})]})}),(0,$.jsxs)(`ul`,{className:`space-y-2.5 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,$.jsx)(On,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-warning`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s(`freestyleDialog.noPipelineTitle`)}),` `,s(`freestyleDialog.noPipelineBody`)]})]}),(0,$.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,$.jsx)(Vo,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-info`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s(`freestyleDialog.autonomyTitle`,{provider:l})}),` `,s(`freestyleDialog.autonomyBody`,{provider:l})]})]}),(0,$.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,$.jsx)(hs,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-success`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s(`freestyleDialog.costTitle`)}),` `,s(`freestyleDialog.costBody`,{provider:l})]})]})]}),(0,$.jsxs)(Zn,{className:`gap-2 sm:gap-2`,children:[(0,$.jsx)(Z,{variant:`ghost`,className:`h-9`,onClick:o,children:s(`common:actions.cancel`)}),(0,$.jsxs)(Z,{ref:c,className:`h-9 gap-2 bg-emerald-500 text-white hover:bg-emerald-400 focus-visible:ring-emerald-400`,onClick:a,children:[s(`freestyleDialog.continue`),(0,$.jsx)(`kbd`,{className:`hidden sm:inline-flex items-center rounded border border-white/30 bg-white/10 px-1 text-[9px] font-medium leading-4`,children:`⌘↵`})]})]})]})})}function mW(e,t=typeof navigator>`u`?``:navigator.platform){return/Mac|iPhone|iPad/i.test(t)?e:e.replace(/⌥/g,`Alt+`).replace(/⌘/g,`Ctrl+`).replace(/⇧/g,`Shift+`).replace(/[⏎↵]/g,`Enter`)}function hW({open:e,railCount:t,specCount:n,onConfirm:r,onCancel:i}){let{t:a}=K(`dashboard`),o=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(!e)return;function t(e){(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),r())}return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,r]),(0,$.jsx)(mr,{open:e,onOpenChange:e=>{e||i()},children:(0,$.jsxs)(fr,{movableResizable:!0,showCloseButton:!1,className:`max-w-md gap-5`,onOpenAutoFocus:e=>{e.preventDefault(),o.current?.focus()},children:[(0,$.jsx)(ur,{children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-xl bg-accent-primary/15 text-accent-primary ring-1 ring-accent-primary/30`,children:(0,$.jsx)(gc,{className:`h-4.5 w-4.5`})}),(0,$.jsxs)(`div`,{className:`text-left`,children:[(0,$.jsx)(sr,{className:`text-base`,children:a(`launchAllDialog.title`)}),(0,$.jsxs)(ir,{children:[a(`launchAllDialog.railsCount`,{count:t}),` · `,a(`launchAllDialog.specsCount`,{count:n})]})]})]})}),(0,$.jsxs)(`ul`,{className:`space-y-2.5 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,$.jsx)(On,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-info`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:a(`launchAllDialog.isolationTitle`)}),` `,a(`launchAllDialog.isolationBody`)]})]}),(0,$.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,$.jsx)(kn,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-secondary`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:a(`launchAllDialog.pipelinesTitle`,{count:t})}),` `,a(`launchAllDialog.pipelinesBody`)]})]}),(0,$.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,$.jsx)(hs,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-success`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:a(`launchAllDialog.costTitle`)}),` `,a(`launchAllDialog.costBody`)]})]})]}),(0,$.jsxs)(Zn,{className:`gap-2 sm:gap-2`,children:[(0,$.jsx)(Z,{variant:`ghost`,className:`h-9`,onClick:i,children:a(`common:actions.cancel`)}),(0,$.jsxs)(Z,{ref:o,className:`h-9 gap-2 bg-emerald-500 text-white hover:bg-emerald-400 focus-visible:ring-emerald-400`,onClick:r,children:[a(`launchAllDialog.launch`,{count:t}),(0,$.jsx)(`kbd`,{className:`hidden sm:inline-flex items-center rounded border border-white/30 bg-white/10 px-1 text-[9px] font-medium leading-4`,children:mW(`⌘↵`)})]})]})]})})}function gW({open:e,target:t,onConfirm:n,onCancel:r}){let{t:i}=K(`dashboard`),a=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(!e)return;function t(e){(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),n())}return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,n]),t?(0,$.jsx)(mr,{open:e,onOpenChange:e=>{e||r()},children:(0,$.jsxs)(fr,{movableResizable:!0,showCloseButton:!1,className:`max-w-md gap-5`,onOpenAutoFocus:e=>{e.preventDefault(),a.current?.focus()},children:[(0,$.jsx)(ur,{children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-xl bg-accent-info/15 text-accent-info ring-1 ring-accent-info/30`,children:(0,$.jsx)(A,{className:`h-4.5 w-4.5`})}),(0,$.jsxs)(`div`,{className:`text-left`,children:[(0,$.jsx)(sr,{className:`text-base`,children:i(`targetPr.confirmTitle`)}),(0,$.jsx)(ir,{children:i(`targetPr.confirmBody`)})]})]})}),(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border/60 bg-muted/30 p-3 text-xs`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(A,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-info`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`min-w-0 font-medium text-foreground`,children:[`#`,t.number,t.title?` · ${t.title}`:``]})]}),t.headRefName&&(0,$.jsxs)(`div`,{className:`flex items-start gap-2 text-muted-foreground`,children:[(0,$.jsx)(On,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`min-w-0 truncate`,children:[i(`targetPr.confirmBranch`),`: `,(0,$.jsx)(`span`,{className:`font-mono`,children:t.headRefName})]})]})]}),(0,$.jsxs)(Zn,{className:`gap-2 sm:gap-2`,children:[(0,$.jsx)(Z,{variant:`ghost`,className:`h-9`,onClick:r,children:i(`common:actions.cancel`)}),(0,$.jsxs)(Z,{ref:a,className:`h-9 gap-2 bg-accent-info text-white hover:bg-accent-info/85 focus-visible:ring-accent-info`,onClick:n,children:[i(`targetPr.confirmLaunch`,{number:t.number}),(0,$.jsx)(`kbd`,{className:`hidden sm:inline-flex items-center rounded border border-white/30 bg-white/10 px-1 text-[9px] font-medium leading-4`,children:mW(`⌘↵`)})]})]})]})}):null}var _W=`postit`,vW=e=>`specrails-desktop:specs-view-tier:${e}`;function yW(e){return e===`row`||e===`postit`}function bW(e){if(!e)return _W;try{let t=localStorage.getItem(vW(e));if(yW(t))return t}catch{}return _W}function xW(e,t){if(e)try{localStorage.setItem(vW(e),t)}catch{}}function SW(e,t,n){if(typeof n==`number`&&n===t)return e;if(typeof n==`number`&&e.includes(n)){let r=e.indexOf(n),i=[...e];return i.splice(r,0,t),i}return[...e,t]}function CW(e,t,n,r,i){if(typeof e==`string`){if(r(e)){let n=i(e);return t.has(n)?n:null}return t.has(e)?e:null}if(typeof e==`number`){let r=n(e);return r&&t.has(r)?r:null}return null}var wW=[{id:`rail-1`,label:`Rail 1`,ticketIds:[],mode:`implement`,status:`idle`},{id:`rail-2`,label:`Rail 2`,ticketIds:[],mode:`implement`,status:`idle`},{id:`rail-3`,label:`Rail 3`,ticketIds:[],mode:`implement`,status:`idle`}],TW=e=>e===`implement`||e===`batch-implement`||e===`freestyle`||e===`loop`;function EW(e,t){if(!e||e.decision!==`pr_draft`&&e.decision!==`pr_ready`||!e.prUrl||!e.branch)return!1;let n=new Set(e.ticketIds);return t.length>0&&t.every(e=>n.has(e))}function DW(e,t){for(let n of t.values())if(EW(n,[e]))return!0;return!1}function OW(e){if(!e)return null;try{let t=localStorage.getItem(`specrails-desktop:spec-order:${e}`);if(!t)return null;let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function kW(e,t){if(e)try{t?localStorage.setItem(`specrails-desktop:spec-order:${e}`,JSON.stringify(t)):localStorage.removeItem(`specrails-desktop:spec-order:${e}`)}catch{}}function AW(e){if(!e)return null;try{let t=localStorage.getItem(`specrails-desktop:rails:${e}`);if(!t)return null;let n=JSON.parse(t);return!Array.isArray(n)||n.length===0?null:n}catch{return null}}function jW(e,t){if(e)try{localStorage.setItem(`specrails-desktop:rails:${e}`,JSON.stringify(t))}catch{}}function MW(){let{t:e}=K(`dashboard`),{activeProjectId:t,projects:n}=pt(),r=wa().id===`galaxy`,i=(()=>{let e=n.find(e=>e.id===t);return e?dt(e):[`claude`]})(),{tickets:a,isLoading:o,error:s,updateTicket:c,updateTicketStatus:l,updateTicketPriority:u,deleteTicket:d,createTicket:f,refetch:p,contractRefiningIds:m}=k(),{registerHandler:h,unregisterHandler:g,connectionStatus:_}=tt(),{specToOpen:v,clearSpecToOpen:y}=ZB(),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(null),[O,A]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{!v||v.projectId!==t||(x(v.ticket),p(),y())},[v,t,p,y]);let[j,M]=(0,Q.useState)(null),[N,P]=(0,Q.useState)(null),[F,I]=(0,Q.useState)(()=>OW(t)),[L,R]=(0,Q.useState)(()=>AW(t)??wW),[z,B]=(0,Q.useState)({}),V=JU(),{decisions:H,hydrated:U,act:W,checkout:ee}=ZU(),te=EB(t),[ne,re]=(0,Q.useState)(te.mode),[ie,ae]=(0,Q.useState)(te.dir),[oe,se]=(0,Q.useState)(()=>bW(t));(0,Q.useEffect)(()=>{I(OW(t)),R(AW(t)??wW),B({});let e=EB(t);re(e.mode),ae(e.dir),se(bW(t))},[t]);let ce=(0,Q.useCallback)((e,n)=>{re(e),ae(n),DB(t,e,n)},[t]),le=(0,Q.useCallback)(e=>{se(e),xW(t,e)},[t]);(0,Q.useEffect)(()=>{if(_!==`connected`||!t)return;let e=!1,n=AW(t)??wW,r=new Map(n.map(e=>[e.id,e]));return fetch(`${ut()}/rails`).then(e=>e.ok?e.json():null).then(n=>{if(e||!n)return;let i=n.activeJobs??{},a=n.activeLoopRuns??{},o=new Set([...Object.keys(i).map(Number),...Object.keys(a).map(Number)]),s=n.rails??[],c=new Map;for(let e of s)c.set(e.railIndex,Array.isArray(e.ticketIds)?e.ticketIds:[]);let l=new Set(s.map(e=>e.railIndex));R(e=>{let n=!1,u=new Map,d=e.map((e,t)=>{let s=xU(e.id)??t,l=a[String(s)],d=i[String(s)]?.jobId??l?.loopRunId;if(o.has(s)){if(e.status===`running`)return d&&!e.activeJobId?(n=!0,{...e,activeJobId:d}):e;if(r.get(e.id)?.status===`running`)return e;let t=c.get(s)??[],a=i[String(s)]?.mode,o=TW(a)?a:l?tS(l.loopId):void 0,f=t.length?t:e.ticketIds;return u.set(e.id,f),n=!0,{...e,status:`running`,activeJobId:d,ticketIds:f,mode:o??e.mode,...l?.loopId&&l.loopId.startsWith(`custom:`)?{selectedLoopId:l.loopId}:{}}}return e.status!==`running`||r.get(e.id)?.status!==`running`?e:(n=!0,{...e,status:`idle`,activeJobId:void 0,ticketIds:[]})}),f=new Set(d.map(e=>e.id)),p=[];for(let e of s){let t=bU(e.railIndex);if(f.has(t))continue;let r=a[String(e.railIndex)],s=i[String(e.railIndex)]?.mode,l=TW(s)?s:r?tS(r.loopId):TW(e.mode)?e.mode:`implement`,d=o.has(e.railIndex),m=c.get(e.railIndex)??[];p.push({id:t,label:e.name?`Rail ${e.name}`:`Rail ${e.railIndex+1}`,ticketIds:m,mode:l,status:d?`running`:`idle`,activeJobId:i[String(e.railIndex)]?.jobId??r?.loopRunId,...r?.loopId&&r.loopId.startsWith(`custom:`)?{selectedLoopId:r.loopId}:{}}),m.length>0&&u.set(t,m),n=!0}let m=p.length>0?[...d,...p]:d;if(s.length>0){let e=m.filter(e=>{let t=xU(e.id);return t===null||l.has(t)||!r.has(e.id)?!0:e.status===`running`||e.ticketIds.length>0});e.length!==m.length&&(m=e,n=!0)}if(!n)return e;let h=new Set([...u.values()].flat()),g=h.size?m.map(e=>{if(u.has(e.id))return e;let t=e.ticketIds.filter(e=>!h.has(e));return t.length===e.ticketIds.length?e:{...e,ticketIds:t}}):m;return jW(t,g),g})}).catch(()=>{}),()=>{e=!0}},[t,_]),(0,Q.useEffect)(()=>{if(!t)return;let e=!1;return fetch(`${ut()}/rails`).then(e=>e.ok?e.json():null).then(n=>{if(e||!n?.rails)return;let r=new Map;for(let e of n.rails)r.set(e.railIndex,e.name??null);R(e=>{let n=!1,i=e.map((e,t)=>{let i=xU(e.id)??t,a=r.get(i)??null;if(!a)return e;let o=`Rail ${a}`;return o===e.label?e:(n=!0,{...e,label:o})});return n?(jW(t,i),i):e})}).catch(()=>{}),()=>{e=!0}},[t]),(0,Q.useEffect)(()=>{let e=new Set(a.filter(e=>e.status===`done`||U&&e.status===`on_review`&&!DW(e.id,H)).map(e=>e.id));e.size!==0&&R(n=>{let r=n.map(t=>{let n=t.ticketIds.filter(t=>!e.has(t));return n.length===t.ticketIds.length?t:{...t,ticketIds:n}});return r.every((e,t)=>e===n[t])?n:(jW(t,r),r)})},[a,t,L,H,U]);let ue=(0,Q.useCallback)(e=>{I(n=>{let r=e(n);return kW(t,r),r})},[t]),de=(0,Q.useCallback)(e=>{R(n=>{let r=e(n);return jW(t,r),r})},[t]),fe=(0,Q.useMemo)(()=>{let e=new Set([`specs`,`done-specs`]);for(let t of L)e.add(t.id);return e},[L]),G=(0,Q.useCallback)(async()=>{try{let t=await fetch(`${ut()}/rails`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})});if(t.ok){let n=(await t.json()).rail?.railIndex;if(typeof n==`number`){let t=bU(n);de(e=>e.some(e=>e.id===t)?e:[...e,{id:t,label:`Rail ${n+1}`,ticketIds:[],mode:`implement`,status:`idle`}]),J.success(e(`toasts.railAdded`,{n:n+1}));return}}else{let n=await t.json().catch(()=>({error:``}));if(n.error===`rail_limit_reached`){J.error(e(`toasts.railLimitReached`,{max:n.maxRails??12}));return}}}catch{}let t=L.map(e=>xU(e.id)).filter(e=>e!==null),n=t.length>0?Math.max(...t)+2:1,r={id:`rail-${n}`,label:`Rail ${n}`,ticketIds:[],mode:`implement`,status:`idle`};de(e=>[...e,r]),J.success(e(`toasts.railAdded`,{n}))},[L,de,e]),pe=(0,Q.useCallback)(async t=>{let n=L.find(e=>e.id===t);if(!n||n.status===`running`)return;let r=()=>{n.ticketIds.length>0&&ue(e=>[...e??[],...n.ticketIds]),de(e=>e.filter(e=>e.id!==t)),J.info(e(`toasts.railRemoved`,{rail:n.label}))},i=xU(t);if(i===null){r();return}try{let t=await fetch(`${ut()}/rails/${i}`,{method:`DELETE`});if(t.ok||t.status===404){r();return}J.error(e(`toasts.railDeleteFailed`))}catch{J.error(e(`toasts.railDeleteFailed`))}},[L,de,ue,e]),me=(0,Q.useCallback)((e,t)=>{de(n=>n.map(n=>n.id===e?{...n,label:`Rail ${t}`}:n));let n=xU(e);n!==null&&fetch(`${ut()}/rails/${n}/name`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})}).catch(()=>{})},[de]),he=(0,Q.useRef)(t);(0,Q.useEffect)(()=>{he.current=t},[t]);let ge=(0,Q.useCallback)(t=>{let n=t;if(n.projectId===he.current){if(n.type===`runtime.continuation`){if(n.railIndex==null)return;let e=bU(n.railIndex);de(t=>t.map(t=>t.id===e?n.active?{...t,status:`running`,activeJobId:n.jobId}:t.activeJobId===n.jobId?{...t,status:`idle`,activeJobId:void 0}:t:t));return}if(n.type===`rail.job_started`||n.type===`loop.run_started`){if(n.railIndex==null)return;let e=bU(n.railIndex),t=n.jobId??n.loopRunId;de(n=>n.map(n=>n.id===e?{...n,status:`running`,activeJobId:t??n.activeJobId}:n));return}if(n.type===`rail.updated`){let e=n.railIndex??0,t=bU(e),r=n.ticketIds??[],i=n.name?`Rail ${n.name}`:`Rail ${e+1}`;de(e=>e.some(e=>e.id===t)?e.map(e=>e.id===t?n.changed!==`tickets`||e.status===`running`?{...e,label:i}:{...e,label:i,ticketIds:r}:e):[...e,{id:t,label:i,ticketIds:r,mode:TW(n.mode)?n.mode:`implement`,status:`idle`}]);return}if(n.type===`rail.removed`){if(n.railIndex==null)return;let e=bU(n.railIndex);de(t=>t.filter(t=>t.id!==e||t.status===`running`));return}if(n.type===`rail.worktree_progress`){let t=n.railIndex??0,r=n.ticketId,i=n.state;typeof r==`number`&&i&&(B(e=>wU(e,t,r,i)),i===`needs-review`&&J.error(e(`toasts.railWorktreeNeedsReview`,{n:t+1,ticket:r})));return}if(n.type===`rail.job_completed`){let t=n.railIndex??0;de(e=>AU(e,t,n.ticketIds??[])),n.status===`completed`?J.info(e(`toasts.railCompleted`,{n:t+1})):n.status===`failed`||n.status===`zombie_terminated`?J.error(e(`toasts.railFailed`,{n:t+1})):J.info(e(`toasts.railEnded`,{n:t+1,status:n.status??`finished`}))}if(n.type===`loop.run_completed`){let t=n.railIndex??0;de(e=>AU(e,t,n.ticketIds??[])),n.status===`success`?J.info(e(`toasts.railCompleted`,{n:t+1})):n.status===`failed`||n.status===`max-iterations`?J.error(e(`toasts.railFailed`,{n:t+1})):J.info(e(`toasts.railEnded`,{n:t+1,status:n.status??`finished`}))}}},[de,e]);(0,Q.useEffect)(()=>(h(`dashboard-rails`,ge),()=>g(`dashboard-rails`)),[ge,h,g]);let _e=kI(OI(PL,{activationConstraint:{distance:5}}),OI(kL)),ve=(0,Q.useCallback)(e=>{let t=typeof e.active.id==`string`&&OU(e.active.id),n=e.droppableContainers.filter(e=>{let n=e.id;return typeof n==`string`&&OU(n)?t:!t}),r={...e,droppableContainers:n};if(t)return zI(r);let i=UI(r);if(II(i))return i;let a=VI(r);return II(a)?a:zI(r)},[]),ye=(0,Q.useMemo)(()=>new Map(a.map(e=>[e.id,e])),[a]),be=(0,Q.useMemo)(()=>{let e=[],t=[];return L.forEach((n,r)=>{let i=xU(n.id)??r;if(n.status===`running`){t.push({rail:n,reason:`running`});return}if(n.ticketIds.length===0){t.push({rail:n,reason:`empty`});return}let a=H.get(i);if(a&&!EW(a,n.ticketIds)){t.push({rail:n,reason:`pendingDecision`});return}if(n.ticketIds.some(e=>ye.get(e)?.status===`on_review`&&(!U||!DW(e,H)))){t.push({rail:n,reason:`onReview`});return}e.push(n)}),{eligible:e,skipped:t}},[L,H,U,ye]),xe=(0,Q.useMemo)(()=>{let e=new Set;for(let t of a)for(let n of t.labels)e.add(n);return Array.from(e).sort()},[a]),Se=(0,Q.useMemo)(()=>{let e=new Set;for(let t of L)for(let n of t.ticketIds)e.add(n);return e},[L]),Ce=(0,Q.useMemo)(()=>a.filter(e=>(e.source===`propose-spec`||e.source===`product-backlog`||e.source===`get-backlog-specs`||e.source===`explore-draft`||e.source===`specs-smash`||e.source===`free-prompt`||e.source===`mcp`||e.source===`project-builder`||e.source===`manual`&&e.created_by===`project-builder`||e.source===`jira`)&&!Se.has(e.id)),[a,Se]);(0,Q.useEffect)(()=>{o||ne===`jira-key`&&!Ce.some(e=>e.jira_key)&&ce(`default`,ie)},[o,ne,ie,Ce,ce]);let we=(0,Q.useMemo)(()=>{let e=Ce.filter(e=>e.status!==`done`);if(ne!=="default")return PB(e,ne,ie);if(!F)return e;let t=new Map(e.map(e=>[e.id,e])),n=[];for(let e of F){let r=t.get(e);r&&n.push(r)}for(let t of e)F.includes(t.id)||n.push(t);return n},[Ce,F,ne,ie]),Te=(0,Q.useMemo)(()=>Ce.filter(e=>e.status===`done`),[Ce]),De=(0,Q.useMemo)(()=>{let e=new Set;if(!U)return e;for(let t of a)t.status===`on_review`&&DW(t.id,H)&&e.add(t.id);return e},[a,H,U]),Oe=(0,Q.useCallback)((t,n)=>{let r=L.find(e=>e.id===n);if(r){if(a.find(e=>e.id===t)?.status===`on_review`&&(!U||!DW(t,H))){J.info(e(`toasts.onReviewCannotMoveToRail`));return}if(r.ticketIds.includes(t)){J.info(e(`toasts.alreadyOnRail`,{rail:r.label}));return}ue(e=>(e??we.map(e=>e.id)).filter(e=>e!==t)),de(e=>e.map(e=>e.id===n?{...e,ticketIds:[...e.ticketIds.filter(e=>e!==t),t]}:e.ticketIds.includes(t)?{...e,ticketIds:e.ticketIds.filter(e=>e!==t)}:e)),J.success(e(`toasts.movedToRail`,{rail:r.label}))}},[L,a,we,de,ue,e,H,U]),Ae=(0,Q.useCallback)(t=>{let n=L.find(e=>e.ticketIds.includes(t));if(n){if(n.status===`running`){J.error(e(`toasts.railRunningStopFirst`,{rail:n.label}));return}de(e=>e.map(e=>e.id===n.id?{...e,ticketIds:e.ticketIds.filter(e=>e!==t)}:e)),ue(e=>{let n=e??we.map(e=>e.id);return n.includes(t)?n:[...n,t]}),J.success(e(`toasts.removedFromRail`,{rail:n.label}))}},[L,we,de,ue,e]),je=(0,Q.useCallback)(e=>{if(we.some(t=>t.id===e))return`specs`;if(Te.some(t=>t.id===e))return`done-specs`;for(let t of L)if(t.ticketIds.includes(e))return t.id;return null},[we,Te,L]);function Me({active:e}){if(OU(e.id)){let t=kU(e.id),n=L.find(e=>e.id===t);P(n?.label??t);return}M(e.id)}function Ne({active:n,over:r}){if(M(null),P(null),!r)return;if(OU(n.id)){if(!OU(r.id))return;let e=kU(n.id),t=kU(r.id);if(e===t)return;de(n=>{let r=n.findIndex(t=>t.id===e),i=n.findIndex(e=>e.id===t);return r===-1||i===-1?n:QR(n,r,i)});return}let i=n.id,o=r.id,s=je(i);if(!s)return;let l=CW(o,fe,je,OU,kU)??s;if(fe.has(l))if(s===l)if(l===`specs`){let e=we.map(e=>e.id),n=e.indexOf(i),r=e.indexOf(o);if(n!==-1&&r!==-1&&n!==r){let i=QR(e,n,r);ue(()=>i),ne!=="default"&&(re(`default`),DB(t,`default`,ie))}}else de(e=>e.map(e=>{if(e.id!==l)return e;let t=e.ticketIds.indexOf(i),n=e.ticketIds.indexOf(o);return t!==-1&&n!==-1&&t!==n?{...e,ticketIds:QR(e.ticketIds,t,n)}:e}));else if(s===`specs`&&l===`done-specs`){if(a.find(e=>e.id===i)?.status===`on_review`){J.info(e(`toasts.onReviewCannotMoveToRail`));return}ue(e=>(e??we.map(e=>e.id)).filter(e=>e!==i)),c(i,{status:`done`})}else if(s===`done-specs`&&l===`specs`)c(i,{status:`todo`}),ue(e=>SW(e??we.map(e=>e.id),i,o));else if(s===`specs`){if(a.find(e=>e.id===i)?.status===`on_review`&&(!U||!DW(i,H))){J.info(e(`toasts.onReviewCannotMoveToRail`));return}let t=L.find(e=>e.id===l);ue(e=>(e??we.map(e=>e.id)).filter(e=>e!==i)),de(e=>e.map(e=>e.id===l?{...e,ticketIds:SW(e.ticketIds,i,o)}:e)),t&&(t.status===`running`?J.info(e(`toasts.queuedOnRail`,{rail:t.label}),{description:e(`toasts.queuedOnRailDescription`)}):J.success(e(`toasts.movedToRail`,{rail:t.label})))}else if(l===`specs`){let t=L.find(e=>e.id===s);if(t?.status===`running`){J.error(e(`toasts.railRunningStopFirst`,{rail:t.label}));return}de(e=>e.map(e=>e.id===s?{...e,ticketIds:e.ticketIds.filter(e=>e!==i)}:e)),ue(e=>SW(e??we.map(e=>e.id),i,o)),t&&J.success(e(`toasts.removedFromRail`,{rail:t.label}))}else s===`done-specs`?(c(i,{status:`todo`}),de(e=>e.map(e=>e.id===l?{...e,ticketIds:SW(e.ticketIds,i,o)}:e))):l===`done-specs`?(de(e=>e.map(e=>e.id===s?{...e,ticketIds:e.ticketIds.filter(e=>e!==i)}:e)),c(i,{status:`done`})):de(e=>e.map(e=>e.id===s?{...e,ticketIds:e.ticketIds.filter(e=>e!==i)}:e.id===l?{...e,ticketIds:SW(e.ticketIds,i,o)}:e))}function Pe(e,t){de(n=>n.map(n=>n.id===e?{...n,mode:t}:n))}function Fe(e){let t=xU(e);return t===null?L.findIndex(t=>t.id===e):t}async function Ie(e,t){de(n=>n.map(n=>n.id===e?{...n,profileName:t}:n));let n=Fe(e);if(n!==-1)try{await fetch(`${ut()}/rails/${n}/profile`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({profileName:t})})}catch{}}function Le(e,t){de(n=>n.map(n=>n.id===e?{...n,freestyleModel:t}:n))}function Re(e,t){let n=tS(t);de(r=>r.map(r=>r.id===e?{...r,selectedLoopId:t,mode:n}:r))}function ze(e){let t=e?.aiEngine;return(wt(t)?void 0:t)??i[0]??`claude`}function Be(e,t){de(n=>n.map(n=>{if(n.id!==e)return n;let r=ze(n),i=vt(r,t);return{...n,loopModel:t,reasoningEffort:n.reasoningEffort&&i.includes(n.reasoningEffort)?n.reasoningEffort:Dt(r,t)??null}}))}function Ve(e,t){de(n=>n.map(n=>n.id===e?{...n,reasoningEffort:t}:n))}async function He(t,n){if(wt(n)){let r=L.find(e=>e.id===t);if(r&&(r.mode===`freestyle`||r.selectedLoopId===`factory:freestyle`)){J.error(e(`rail.rolesNoFreestyle`));return}de(e=>e.map(e=>e.id===t?{...e,aiEngine:n,profileName:null}:e)),await Ue(t,n);return}de(e=>e.map(e=>{if(e.id!==t)return e;let r=e.mode===`freestyle`||e.selectedLoopId===`factory:freestyle`,i=!bt(n)&&r,a=Jx(n),o=e=>!!(e&&(a.some(t=>t.value===e)||Nt(n)&&nk(e))),s=o(e.loopModel)?e.loopModel:Yx(n),c=vt(n,s);return{...e,aiEngine:n,mode:i?`implement`:e.mode,selectedLoopId:i?`factory:implement`:e.selectedLoopId,profileName:null,freestyleModel:o(e.freestyleModel)?e.freestyleModel:Yx(n),loopModel:s,reasoningEffort:e.reasoningEffort&&c.includes(e.reasoningEffort)?e.reasoningEffort:Dt(n,s)??null}})),await Ue(t,n)}async function Ue(e,t){let n=Fe(e);if(n!==-1)try{await fetch(`${ut()}/rails/${n}/engine`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({aiEngine:t})})}catch{}}function We(e,t){de(n=>n.map(n=>n.id===e?{...n,targetPr:t}:n))}async function Ge(t){let n=L.find(e=>e.id===t),r=Fe(t);if(!(!n||r===-1)){if(n.status===`running`){try{await fetch(`${ut()}/rails/${r}/stop`,{method:`POST`}),de(e=>e.map(e=>e.id===t?{...e,status:`idle`,activeJobId:void 0}:e)),J.info(e(`toasts.railStopped`,{rail:n.label}))}catch{J.error(e(`toasts.stopFailed`))}return}if(n.ticketIds.length!==0){if(n.mode===`freestyle`){T({railId:t});return}if(n.targetPr){D({railId:t});return}await Ke(t)}}}async function Ke(t,n){let r=n?.silent??!1,i=L.find(e=>e.id===t),o=Fe(t);if(!i||o===-1)return`failed`;if(i.ticketIds.length===0)return`skipped`;if(i.ticketIds.some(e=>a.find(t=>t.id===e)?.status===`on_review`&&(!U||!DW(e,H))))return r||J.info(e(`toasts.onReviewNotLaunchable`)),`skipped`;let s=nS(i.selectedLoopId,i.mode);if(!s)return r||J.error(e(`railControls.pickLoop`)),`failed`;let c=wt(i.aiEngine),l=ze(i),u=vt(l,i.loopModel??Yx(l)),d=i.reasoningEffort&&u.includes(i.reasoningEffort)?i.reasoningEffort:null,f=ut();try{await fetch(`${f}/rails/${o}/tickets`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({ticketIds:i.ticketIds})})}catch{return r||J.error(e(`toasts.syncTicketsFailed`)),`failed`}try{let n=await fetch(`${f}/rails/${o}/launch`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({mode:i.mode,...!c&&(i.aiEngine!=null||i.mode===`loop`&&(i.loopModel||d))?{runtimeProviderOverride:{provider:l,...i.mode===`loop`&&i.loopModel?{model:i.loopModel}:{},...i.mode===`loop`&&d?{effort:d}:{}}}:{},...!c&&i.profileName!==void 0?{profileName:i.profileName}:{},...i.aiEngine==null?{}:{aiEngine:i.aiEngine},...!c&&i.mode===`freestyle`&&i.freestyleModel?{model:i.freestyleModel}:{},...!c&&i.mode===`loop`&&i.loopModel?{model:i.loopModel}:{},loopId:s,...!c&&i.mode===`loop`&&d?{reasoning_effort:d}:{},...i.targetPr?{targetPrNumber:i.targetPr.number}:{}})});if(!n.ok){let t=await n.json().catch(()=>({error:``}));return n.status===409&&t.error===`pr_decision_pending`?(r||J.info(e(`railPr.decisionPending`)),`pendingDecision`):n.status===409&&t.error===`tickets_in_flight`?(r||J.info(e(`toasts.launchTicketsInFlight`)),`skipped`):n.status===400&&t.error===`rail_ticket_cap_exceeded`?(r||J.error(e(`toasts.launchTicketCap`,{max:t.max??3,count:t.ticketCount??0})),`failed`):typeof t.error==`string`&&[`invalid_target_pr`,`target_pr_requires_pr_mode`,`target_pr_not_found`,`target_pr_not_open`,`target_pr_fork`,`target_pr_invalid`,`target_pr_unfetchable`].includes(t.error)?(r||J.error(e(`targetPr.errors.${t.error}`),{description:t.detail,duration:1e4}),`failed`):(r||J.error(t.error||e(`toasts.launchFailed`)),`failed`)}let a=await n.json();!r&&a.isolationUnavailable===`no-git`?J.info(e(`toasts.railWorktreesNoGit`)):!r&&a.isolationUnavailable===`no-commits`?J.info(e(`toasts.railWorktreesNoCommits`)):!r&&a.isolationUnavailable===`error`&&J.warning(e(`toasts.railWorktreesError`),{description:a.isolationUnavailableDetail,duration:12e3});let u=a.jobId??a.loopRunIds?.[0];return de(e=>e.map(e=>e.id===t?{...e,status:`running`,activeJobId:u,targetPr:null}:e)),r||J.success(e(`toasts.railLaunched`,{rail:i.label}),{description:e(`toasts.launchDescription`,{mode:i.mode,count:i.ticketIds.length})}),`launched`}catch{return r||J.error(e(`toasts.launchNetworkError`)),`failed`}}function qe(){if(be.eligible.length===0){J.info(e(`toasts.launchAllNoneEligible`));return}A(!0)}async function Je(){A(!1);let{eligible:t,skipped:n}=be;if(t.length===0){J.info(e(`toasts.launchAllNoneEligible`));return}let r=await Promise.allSettled(t.map(e=>Ke(e.id,{silent:!0}))),i=0,a=0,o=0,s=0;for(let e of r){let t=e.status===`fulfilled`?e.value:`failed`;t===`launched`?i++:t===`pendingDecision`?o++:t===`skipped`?s++:a++}let c=new Map;for(let e of n)c.set(e.reason,(c.get(e.reason)??0)+1);o>0&&c.set(`pendingDecision`,(c.get(`pendingDecision`)??0)+o);let l={running:`launchAll.skipRunning`,empty:`launchAll.skipEmpty`,pendingDecision:`launchAll.skipPendingDecision`,onReview:`launchAll.skipOnReview`},u=[];for(let[t,n]of c)n>0&&u.push(e(l[t],{count:n}));s>0&&u.push(e(`launchAll.skipInFlight`,{count:s})),a>0&&u.push(e(`launchAll.failedCount`,{count:a}));let d=u.length>0?u.join(` · `):void 0;i>0?J.success(e(`toasts.launchAllSummary`,{count:i}),d?{description:d}:void 0):J.error(e(`toasts.launchAllFailed`),d?{description:d}:void 0)}let Ye=j===null?void 0:ye.get(j),Xe=(0,Q.useRef)(null),{leftWidth:Ze,enabled:Qe,beginDrag:$e,resetToDefault:et}=uW(t,Xe),nt=typeof window<`u`?window.innerWidth:1200;return(0,$.jsx)(Nz,{children:(0,$.jsxs)(jR,{sensors:_e,collisionDetection:ve,onDragStart:Me,onDragEnd:Ne,children:[(0,$.jsxs)(`div`,{ref:Xe,className:`relative z-0 flex h-full overflow-hidden`,children:[r&&(0,$.jsx)(MP,{}),(0,$.jsx)(`div`,{className:`relative z-10 min-w-0 flex flex-col overflow-hidden`,style:Qe&&Ze!==null?{width:`${Ze}px`,flex:`0 0 auto`}:{flex:`1 1 0%`},children:(0,$.jsx)(aU,{tickets:we,allTickets:a,doneTickets:Te,isLoading:o,error:s,onRetry:()=>{p()},onTicketClick:x,onTicketCreated:e=>{x(e),p()},onTicketDelete:e=>d(e),onTicketStatusChange:(e,t)=>{l(e,t)},onTicketPriorityChange:(e,t)=>{u(e,t)},contractRefiningIds:m,sortMode:ne,sortDir:ie,onSortChange:ce,viewTier:oe,onViewTierChange:le,rails:L,onMoveToRail:Oe,continuableReviewTicketIds:De})}),Qe&&Ze!==null&&(0,$.jsx)(dW,{leftWidth:Ze,viewport:nt,onPointerDown:$e,onReset:et}),(0,$.jsx)(`div`,{className:`relative z-10 flex-1 min-w-0 flex flex-col overflow-hidden`,children:(0,$.jsx)(MU,{rails:L,ticketMap:ye,railWorktrees:z,railMetrics:V,railPrDecisions:H,onPrDecision:W,onPrCheckout:ee,providers:i,onModeChange:Pe,onProfileChange:Ie,onEngineChange:He,onFreestyleModelChange:Le,onLoopModelChange:Be,loopAvailable:ke,onLoopChange:Re,onEffortChange:Ve,onToggle:Ge,onTargetPrChange:We,onTicketClick:x,onAddRail:()=>{G()},onDeleteRail:e=>{pe(e)},onRenameRail:me,onTicketMoveToSpecs:Ae,onLaunchAll:qe,launchAllCount:be.eligible.length})})]}),(0,$.jsx)(ZR,{dropAnimation:{duration:180,easing:`ease`},children:Ye?oe===`postit`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl border border-accent-info/40 bg-card/95 shadow-xl shadow-black/30 backdrop-blur-sm p-3 rotate-1 scale-[1.02] pointer-events-none w-[260px] min-h-[180px]`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground/60`,children:[`#`,Ye.id]}),Ye.priority&&(0,$.jsx)(`span`,{className:`h-4 px-1.5 rounded-full text-[9px] font-medium uppercase bg-muted/40 text-foreground`,children:Ye.priority})]}),(0,$.jsx)(`h3`,{className:`text-sm font-medium leading-snug line-clamp-2 text-foreground`,children:Ye.title}),Ye.short_summary&&Ye.short_summary.trim().length>0&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 leading-relaxed line-clamp-3 italic`,children:Ye.short_summary})]}):(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2.5 rounded-lg border border-primary/40 bg-card/95 shadow-xl shadow-black/20 backdrop-blur-sm rotate-1 scale-[1.03] pointer-events-none`,children:[(0,$.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground/50 shrink-0`,children:[`#`,Ye.id]}),(0,$.jsx)(`span`,{className:`flex-1 text-sm truncate max-w-[240px]`,children:Ye.title})]}):N?(0,$.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-xl border border-primary/40 bg-card/95 shadow-xl shadow-black/20 backdrop-blur-sm rotate-[0.5deg] scale-[1.02] pointer-events-none`,children:(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:N})}):null}),b&&(()=>{let e=a.find(e=>e.id===b.id)??b;return(0,$.jsx)(Ee,{ticket:e,allLabels:xe,allTickets:a,onClose:()=>x(null),onOpenTicket:e=>{let t=a.find(t=>t.id===e);t&&x(t)},onSave:c,onDelete:d,rails:L,onMoveToRail:Oe,onRemoveFromRail:Ae},e.id)})(),(0,$.jsx)(fW,{open:S,allLabels:xe,onClose:()=>C(!1),onCreate:f}),(0,$.jsx)(hW,{open:O,railCount:be.eligible.length,specCount:be.eligible.reduce((e,t)=>e+t.ticketIds.length,0),onCancel:()=>A(!1),onConfirm:()=>{Je()}}),(()=>{let e=E?L.find(e=>e.id===E.railId):void 0;return(0,$.jsx)(gW,{open:!!E&&!!e?.targetPr,target:e?.targetPr??null,onCancel:()=>D(null),onConfirm:()=>{let e=E?.railId;D(null),e&&Ke(e)}})})(),(()=>{let e=w?L.find(e=>e.id===w.railId):void 0,t=ze(e);return(0,$.jsx)(pW,{open:!!w&&!!e,railLabel:e?.label??``,specCount:e?.ticketIds.length??0,provider:t,model:e?.freestyleModel??Yx(t),onCancel:()=>T(null),onConfirm:()=>{let e=w?.railId;T(null),e&&Ke(e)}})})()]})})}var NW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:X(`rounded-lg border border-border bg-card text-card-foreground shadow-sm`,e),...t}));NW.displayName=`Card`;var PW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:X(`flex flex-col space-y-1 p-4`,e),...t}));PW.displayName=`CardHeader`;var FW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`h3`,{ref:n,className:X(`text-sm font-semibold leading-none tracking-tight`,e),...t}));FW.displayName=`CardTitle`;var IW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`p`,{ref:n,className:X(`text-xs text-muted-foreground`,e),...t}));IW.displayName=`CardDescription`;var LW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:X(`p-4 pt-0`,e),...t}));LW.displayName=`CardContent`;var RW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:X(`flex items-center p-4 pt-0`,e),...t}));RW.displayName=`CardFooter`;var zW=[`auto`,`canvas`,`webgl`];function BW({mode:e}){let{t}=K(`settings`),{activeProjectId:n}=pt(),[r,i]=(0,Q.useState)(Pi),[a,o]=(0,Q.useState)({}),[s,c]=(0,Q.useState)(Pi),[l,u]=(0,Q.useState)(Pi),[d,f]=(0,Q.useState)(new Set),[p,m]=(0,Q.useState)(!0),[h,g]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let t=!1;if(e===`project`&&!n){m(!1);return}return(async()=>{try{if(e===`desktop`){let e=await fetch(`/api/terminal-settings`);if(!e.ok)throw Error(`desktop settings fetch failed`);let n=await e.json();!t&&n&&typeof n==`object`&&`fontSize`in n&&(i(n),c(n),u(n),f(new Set)),t||m(!1)}else if(n){let e=await fetch(`/api/projects/${n}/terminal-settings`);if(!e.ok)throw Error(`project fetch failed`);let r=await e.json();!t&&r&&typeof r==`object`&&r.resolved&&r.desktopDefaults&&(i(r.desktopDefaults),o(r.override??{}),c(r.resolved),u(r.resolved),f(new Set)),t||m(!1)}}catch(e){t||(m(!1),console.error(e))}})(),()=>{t=!0}},[e,n]);let _=(0,Q.useMemo)(()=>d.size>0||Object.keys(l).some(e=>l[e]!==s[e]),[l,s,d]);function v(e,t){u(n=>({...n,[e]:t})),d.has(e)&&f(t=>{let n=new Set(t);return n.delete(e),n})}function y(t){e===`project`&&(f(e=>{let n=new Set(e);return n.add(t),n}),u(e=>({...e,[t]:r[t]})))}function b(){u(s),f(new Set)}async function x(){g(!0);try{let r={};for(let e of Object.keys(l)){if(d.has(e)){r[e]=null;continue}l[e]!==s[e]&&(r[e]=l[e])}if(Object.keys(r).length===0){J(t(`terminal.nothingToSave`)),g(!1);return}if(e===`desktop`){let e=await fetch(`/api/terminal-settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)});if(!e.ok)throw Error(await e.text()||`patch failed`);let n=await e.json();i(n),c(n),u(n),f(new Set),nF({mode:`desktop`,projectId:null}),J.success(t(`terminal.saved`))}else if(n){let e=await fetch(`/api/projects/${n}/terminal-settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)});if(!e.ok)throw Error(await e.text()||`patch failed`);let a=await e.json();i(a.desktopDefaults),o(a.override),c(a.resolved),u(a.resolved),f(new Set),nF({mode:`project`,projectId:n}),J.success(t(`terminal.saved`))}}catch(e){J.error(t(`errors.saveFailed`,{message:e.message}))}finally{g(!1)}}function S(t){return e!==`project`||d.has(t)?!1:a[t]!==void 0}return p?(0,$.jsx)(NW,{children:(0,$.jsx)(LW,{children:t(`common:states.loading`)})}):(0,$.jsxs)(NW,{children:[(0,$.jsxs)(PW,{children:[(0,$.jsx)(FW,{children:t(`terminal.title`)}),(0,$.jsx)(IW,{children:t(e===`desktop`?`terminal.desktopDescription`:`terminal.projectDescription`)})]}),(0,$.jsxs)(LW,{className:`space-y-4`,children:[(0,$.jsx)(VW,{label:t(`terminal.fontFamily`),overridden:S(`fontFamily`),onClear:()=>y(`fontFamily`),mode:e,children:(0,$.jsx)(Jj,{value:l.fontFamily,onChange:e=>v(`fontFamily`,e.target.value)})}),(0,$.jsx)(VW,{label:t(`terminal.fontSize`,{min:8,max:32}),overridden:S(`fontSize`),onClear:()=>y(`fontSize`),mode:e,children:(0,$.jsx)(Jj,{type:`number`,min:8,max:32,value:l.fontSize,onChange:e=>v(`fontSize`,parseInt(e.target.value,10)||l.fontSize)})}),(0,$.jsx)(VW,{label:t(`terminal.renderMode`),overridden:S(`renderMode`),onClear:()=>y(`renderMode`),mode:e,children:(0,$.jsx)(`select`,{value:l.renderMode,onChange:e=>v(`renderMode`,e.target.value),className:`border rounded px-2 py-1 bg-transparent`,children:zW.map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))})}),(0,$.jsx)(HW,{label:t(`terminal.copyOnSelect`),checked:l.copyOnSelect,overridden:S(`copyOnSelect`),onClear:()=>y(`copyOnSelect`),onChange:e=>v(`copyOnSelect`,e),mode:e}),(0,$.jsx)(HW,{label:t(`terminal.shellIntegration`),checked:l.shellIntegrationEnabled,overridden:S(`shellIntegrationEnabled`),onClear:()=>y(`shellIntegrationEnabled`),onChange:e=>v(`shellIntegrationEnabled`,e),mode:e}),(0,$.jsx)(HW,{label:t(`terminal.notifyLongRunning`),checked:l.notifyOnCompletion,overridden:S(`notifyOnCompletion`),onClear:()=>y(`notifyOnCompletion`),onChange:e=>v(`notifyOnCompletion`,e),mode:e}),(0,$.jsx)(VW,{label:t(`terminal.longCommandThreshold`),overridden:S(`longCommandThresholdMs`),onClear:()=>y(`longCommandThresholdMs`),mode:e,children:(0,$.jsx)(Jj,{type:`number`,min:1e3,value:l.longCommandThresholdMs,onChange:e=>v(`longCommandThresholdMs`,parseInt(e.target.value,10)||l.longCommandThresholdMs)})}),(0,$.jsx)(HW,{label:t(`terminal.imageRendering`),checked:l.imageRendering,overridden:S(`imageRendering`),onClear:()=>y(`imageRendering`),onChange:e=>v(`imageRendering`,e),mode:e}),(0,$.jsx)(VW,{id:`terminal-browser-shortcut-url`,label:t(`terminal.browserShortcutUrl`),overridden:S(`browserShortcutUrl`),onClear:()=>y(`browserShortcutUrl`),mode:e,children:(0,$.jsx)(Jj,{type:`url`,value:l.browserShortcutUrl,placeholder:`https://specrails.dev`,onChange:e=>v(`browserShortcutUrl`,e.target.value)})}),(0,$.jsx)(VW,{id:`terminal-quick-script`,label:t(`terminal.quickScript`),overridden:S(`quickScript`),onClear:()=>y(`quickScript`),mode:e,children:(0,$.jsx)(`textarea`,{value:l.quickScript,placeholder:`echo "Hello World!"`,onChange:e=>v(`quickScript`,e.target.value),rows:3,className:`w-full border rounded px-2 py-1 bg-transparent font-mono text-xs`})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 pt-2 border-t`,children:[(0,$.jsx)(Z,{onClick:x,disabled:!_||h,children:t(h?`common:states.saving`:`common:actions.save`)}),(0,$.jsx)(Z,{variant:`ghost`,onClick:b,disabled:!_||h,children:t(`terminal.reset`)}),_&&(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t(`terminal.unsavedChanges`)})]})]})]})}function VW({id:e,label:t,overridden:n,onClear:r,mode:i,children:a}){let{t:o}=K(`settings`);return(0,$.jsxs)(`div`,{id:e,"data-terminal-settings-anchor":e?``:void 0,className:e?`scroll-mt-4`:void 0,children:[(0,$.jsxs)(`div`,{className:`flex justify-between items-center mb-1`,children:[(0,$.jsx)(`label`,{className:`text-sm font-medium`,children:t}),i===`project`&&n&&(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:r,children:o(`terminal.clearOverride`)})]}),a,i===`project`&&!n&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:o(`terminal.inheritingDefault`)})]})}function HW({label:e,checked:t,overridden:n,onClear:r,onChange:i,mode:a}){let{t:o}=K(`settings`);return(0,$.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,$.jsx)(`label`,{className:`text-sm font-medium`,children:e}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a===`project`&&n&&(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:r,children:o(`terminal.clear`)}),(0,$.jsx)(`button`,{type:`button`,role:`switch`,"aria-label":e,"aria-checked":t,onClick:()=>i(!t),className:`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${t?`bg-primary`:`bg-input`}`,children:(0,$.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-background shadow-sm transition-transform ${t?`translate-x-4`:`translate-x-0.5`}`})})]})]})}function UW(){let{activeProjectId:e,projects:t,refreshProjects:n}=pt(),r=t.find(t=>t.id===e);return r?(0,$.jsx)(WW,{project:r,refreshProjects:n},r.id):null}function WW({project:e,refreshProjects:t}){let{t:n}=K(`common`),[r,i]=(0,Q.useState)(()=>Er(e)),[a,o]=(0,Q.useState)(null),[s,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(null),b=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>(b.current=!0,()=>{b.current=!1}),[]),(0,Q.useEffect)(()=>{i(Er(e))},[e]);let x=`${Tr(e.id)}/repositories`;function S(e){y(null),o(e??null),l(!e),d(e?.path??``),p(e?.name??``),h(e?.integrationBranch??``)}async function C(e,n){if(!g){_(!0),y(null);try{let r=await fetch(n?`${x}/${encodeURIComponent(n)}`:x,{method:e,headers:{"Content-Type":`application/json`},...e===`DELETE`?{}:{body:JSON.stringify({...!a||!a.isPrimary&&u.trim()!==a.path?{path:u.trim()}:{},...f.trim()?{name:f.trim()}:{},integrationBranch:m.trim()||null})}});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error??`HTTP ${r.status}`)}let s=await fetch(x,{cache:`no-store`});if(!s.ok)throw Error(`HTTP ${s.status}`);let c=await s.json();b.current&&(i(c.repositories),l(!1),o(null)),await t?.()}catch(e){b.current&&y(e instanceof Error?e.message:String(e))}finally{b.current&&_(!1)}}}return(0,$.jsxs)(NW,{children:[(0,$.jsxs)(PW,{children:[(0,$.jsxs)(FW,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ws,{className:`h-4 w-4`}),n(`repositories.title`)]}),(0,$.jsx)(IW,{children:n(`repositories.sharedBacklog`)})]}),(0,$.jsxs)(LW,{className:`space-y-4`,children:[(0,$.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-border p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.isPrimary?n(`repositories.primary`):e.kind===`folder`?n(`repositories.contextOnly`):`Git`}),e.available===!1&&(0,$.jsx)(`span`,{className:`text-xs text-destructive`,children:n(`repositories.unavailable`)}),(0,$.jsxs)(`div`,{className:`ml-auto flex gap-1`,children:[(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,disabled:g,onClick:()=>S(e),children:n(`actions.edit`)}),!e.isPrimary&&(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,disabled:g,onClick:()=>void C(`DELETE`,e.id),children:n(`repositories.detach`)})]})]}),(0,$.jsx)(`p`,{className:`break-all text-xs text-muted-foreground`,children:e.path}),e.integrationBranch&&(0,$.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[n(`repositories.integrationBranch`),`: `,e.integrationBranch]})]},e.id))}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`repositories.detachHint`)}),v&&(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:v}),s||a?(0,$.jsxs)(`form`,{className:`space-y-3 rounded-lg border border-border p-3`,onSubmit:e=>{e.preventDefault(),C(a?`PATCH`:`POST`,a?.id)},children:[(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`repositories.name`),(0,$.jsx)(Jj,{value:f,disabled:g,onChange:e=>p(e.target.value)})]}),(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`repositories.path`),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Jj,{value:u,required:!0,disabled:g||a?.isPrimary,onChange:e=>d(e.target.value)}),`__TAURI_INTERNALS__`in window&&!a?.isPrimary&&(0,$.jsx)(Z,{type:`button`,variant:`outline`,disabled:g,"aria-label":n(`repositories.browse`),onClick:async()=>{try{let{open:e}=await c(async()=>{let{open:e}=await import(`./dist-js-CJ_2XX1Y.js`);return{open:e}},__vite__mapDeps([87,0,1])),t=await e({directory:!0,multiple:!1});typeof t==`string`&&b.current&&d(t)}catch{}},children:(0,$.jsx)(Ts,{className:`h-4 w-4`})})]})]}),(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`repositories.integrationBranch`),(0,$.jsx)(Jj,{value:m,disabled:g,placeholder:n(`repositories.branchDefault`),onChange:e=>h(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Z,{type:`submit`,size:`sm`,disabled:g||!u.trim(),children:n(g?`actions.saving`:`actions.save`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:`ghost`,disabled:g,onClick:()=>{l(!1),o(null),y(null)},children:n(`actions.cancel`)})]})]}):(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,disabled:g,onClick:()=>S(),children:[(0,$.jsx)(Pn,{className:`mr-1 h-4 w-4`}),n(`repositories.addFolder`)]})]})]})}var GW=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function KW({value:e,capability:t,onChange:n}){let{t:r}=K(`agentRuntime`),i=t?.effortSupport===`supported`?t.supportedEfforts??[]:[];return(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[r(`efficiency.effort`),(0,$.jsxs)(`select`,{"aria-label":r(`efficiency.effort`),className:GW,value:e??``,onChange:e=>n(e.target.value||void 0),children:[(0,$.jsx)(`option`,{value:``,children:r(`efficiency.providerDefault`)}),i.map(e=>(0,$.jsx)(`option`,{value:e,children:e},e)),e&&!i.includes(e)&&(0,$.jsxs)(`option`,{value:e,children:[e,` — `,r(`efficiency.unconfirmed`)]})]}),(0,$.jsx)(`span`,{className:`block text-muted-foreground`,children:t?.effortSupport===`supported`?t.transport:r(`efficiency.unknownSupport`)})]})}function qW({role:e,agent:t,capabilities:n,onChange:r}){let{t:i}=K(`agentRuntime`),a=r=>n.find(n=>n.role===e&&n.tier===r&&n.provider===t.provider&&n.model===((r===`base`?t.model:t.escalation?.model)??null));return(0,$.jsxs)(`div`,{className:`mt-3 space-y-3 border-t pt-3`,children:[(0,$.jsx)(KW,{value:t.effort,capability:a(`base`),onChange:e=>r({...t,effort:e})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:!!t.escalation,disabled:!t.model,onChange:e=>r({...t,escalation:e.target.checked?{model:``}:void 0})}),i(`efficiency.escalation`)]}),(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[i(`efficiency.triggers.${e}`),` `,!t.model&&i(`efficiency.baseRequired`)]}),t.escalation&&(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[i(`efficiency.escalationModel`),(0,$.jsx)(Jj,{value:t.escalation.model,onChange:e=>r({...t,escalation:{...t.escalation,model:e.target.value,effort:void 0}})})]}),(0,$.jsx)(KW,{value:t.escalation.effort,capability:a(`escalation`),onChange:e=>r({...t,escalation:{...t.escalation,effort:e}})})]})]})}function JW({config:e,onChange:t}){let{t:n}=K(`agentRuntime`),r=e.efficiency??{schemaVersion:1};return(0,$.jsxs)(`section`,{className:`space-y-3`,"aria-label":n(`efficiency.title`),children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium`,children:n(`efficiency.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`efficiency.scope`)}),(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[`contextMode`,`reviewMode`,`planning`].map(i=>(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`efficiency.${i}`),(0,$.jsxs)(`select`,{className:GW,value:r[i]??(i===`planning`?`proportional`:`incremental`),onChange:n=>t({...e,efficiency:{...r,[i]:n.target.value}}),children:[(0,$.jsx)(`option`,{value:i===`planning`?`proportional`:`incremental`,children:n(`efficiency.adaptive`)}),(0,$.jsx)(`option`,{value:`full`,children:n(`efficiency.full`)})]})]},i))}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:r.acceptDeveloperChecks!==!1,onChange:n=>t({...e,efficiency:{...r,acceptDeveloperChecks:n.target.checked}})}),n(`efficiency.developerChecks`)]}),(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`efficiency.concurrency`),(0,$.jsx)(Jj,{type:`number`,min:`1`,max:`4`,step:`1`,value:r.verification?.maxConcurrency??1,onChange:n=>t({...e,efficiency:{...r,verification:{...r.verification,maxConcurrency:Number(n.target.value)}}})})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`efficiency.concurrencyHint`)})]})}function YW({name:e,value:t,tabs:n,onChange:r,disabled:i,ariaLabel:a}){return(0,$.jsx)(`div`,{role:`radiogroup`,"aria-label":a,className:`inline-flex max-w-full flex-wrap gap-1 rounded-lg border border-border bg-background/60 p-1`,children:n.map(n=>{let a=n.value===t;return(0,$.jsxs)(`label`,{title:n.detail?`${n.label} · ${n.detail}`:n.label,className:`relative flex cursor-pointer select-none items-center gap-1.5 rounded-md px-3 py-1.5 text-xs transition-colors ${a?`bg-primary/15 text-foreground shadow-sm ring-1 ring-primary/40`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`} ${i?`pointer-events-none opacity-50`:``}`,children:[(0,$.jsx)(`input`,{type:`radio`,className:`absolute inset-0 h-full w-full cursor-pointer appearance-none opacity-0`,"aria-label":n.name??n.label,name:e,value:n.value,checked:a,disabled:i,onChange:()=>r(n.value)}),n.local?(0,$.jsx)(xc,{className:`h-3 w-3 opacity-70`,"aria-hidden":!0}):n.value?(0,$.jsx)(fs,{className:`h-3 w-3 opacity-70`,"aria-hidden":!0}):null,(0,$.jsx)(`span`,{className:`font-medium`,children:n.label}),n.local&&n.detail&&(0,$.jsx)(`span`,{className:`hidden max-w-[12rem] truncate text-[10px] opacity-60 sm:inline`,children:n.detail})]},n.value||`__inherit`)})})}var XW=[`verifier`,`decider`],ZW=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function QW(e){let t=e?.roles;if(!t||typeof t!=`object`)return{};let n={};for(let e of XW){let r=t[e];if(r&&typeof r==`object`&&typeof r.provider==`string`){let{provider:t,model:i,effort:a}=r;n[e]={provider:t,...i?{model:i}:{},...a?{effort:a}:{}}}}return n}function $W(e){let{t}=K(`agentRuntime`),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(!1),o=(0,Q.useRef)({}),s=`${Tr(e)}/agent-runtime/loop-roles`;(0,Q.useEffect)(()=>{let e=!1;return r(null),a(!1),fetch(s,{cache:`no-store`}).then(async t=>{if(!t.ok)throw Error(`loop_roles`);let n=QW(await t.json());e||(o.current=n,r(n))}).catch(()=>{e||(r({}),a(!0))}),()=>{e=!0}},[s]);async function c(e){let n=o.current;o.current=e,r(e);try{let n=await fetch(s,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({roles:e})}),i=await n.json().catch(()=>null);if(!n.ok)throw Error(i?.message??t(`loopRoles.saveFailed`));let a=QW(i);o.current=a,r(a)}catch(e){o.current=n,r(n),J.error(e instanceof Error&&e.message?e.message:t(`loopRoles.saveFailed`))}}return{roles:n,failed:i,setRole:(e,t)=>{let n={...o.current};t?n[e]=t:delete n[e],c(n)}}}function eG(e){return e&&(e.model||Yx(e.provider))||null}function tG({role:e,engine:t,providers:n,enabled:r,onChange:i}){let{t:a}=K(`agentRuntime`),o=Zx(),s=e=>{let t=o.providers[e]?.models;return t&&t.length?t:Jx(e).map(e=>e.value)},c=t?.provider,l=At(c),u=c?Jx(c):[],d=c?Yx(c):``,f=t?.model&&!u.some(e=>e.value===t.model)?t.model:null,p=t?.model||d||null,m=c?vt(c,p):[],h=!!c&&Et(c,p);return(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`fieldset`,{className:`space-y-2 sm:col-span-2`,children:[(0,$.jsx)(`legend`,{className:`text-xs`,children:a(`agents.provider`)}),(0,$.jsx)(YW,{name:`loop-role-${e}-provider`,value:c??``,ariaLabel:a(`agents.provider`),disabled:!r,tabs:[{value:``,label:a(`loopRoles.inherit`)},...n.map(e=>({value:e,label:jt(e),detail:e,local:At(e)}))],onChange:e=>i(e?{provider:e}:null)})]}),c&&!l&&(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[a(`loopRoles.model`),(0,$.jsxs)(`select`,{className:ZW,value:t?.model??``,onChange:e=>i({provider:c,...e.target.value?{model:e.target.value}:{}}),children:[(0,$.jsx)(`option`,{value:``,children:a(`agents.defaultModel`,{model:u.find(e=>e.value===d)?.label??d})}),u.map(e=>(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value)),f&&(0,$.jsx)(`option`,{value:f,children:f})]})]}),c&&l&&(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[a(`loopRoles.model`),(0,$.jsx)(Jj,{defaultValue:t?.model??``,list:`loop-role-${e}-models-${c}`,placeholder:a(`agents.modelPlaceholder`),onBlur:e=>{let n=e.target.value.trim();(t?.model??``)!==n&&i({provider:c,...n?{model:n}:{}})}}),(0,$.jsx)(`datalist`,{id:`loop-role-${e}-models-${c}`,children:s(c).map(e=>(0,$.jsx)(`option`,{value:e},e))})]}),h&&(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[a(`loopRoles.effort`),(0,$.jsxs)(`select`,{className:ZW,value:t?.effort??``,onChange:e=>i({provider:c,...t?.model?{model:t.model}:{},...e.target.value?{effort:e.target.value}:{}}),children:[(0,$.jsx)(`option`,{value:``,children:a(`agents.defaultModel`,{model:`—`})}),m.map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))]})]})]})}var nG=[`architect`,`developer`,`verification`,`fixer`,`reviewer`,`verifier`,`decider`],rG={architect:`core`,developer:`core`,verification:`core`,fixer:`core`,reviewer:`core`,verifier:`loop`,decider:`loop`},iG=[`core`,`loop`],aG={core:nG.filter(e=>rG[e]===`core`),loop:nG.filter(e=>rG[e]===`loop`)};function oG(e){return aG[rG[e]].indexOf(e)+1}var sG={architect:ss,developer:Ns,verification:Cc,fixer:Bn,reviewer:vs,verifier:ts,decider:On};function cG({engine:e,className:t=``}){let{t:n}=K(`agentRuntime`),r=`inline-flex max-w-full items-center gap-1 rounded-md border px-1.5 py-0.5 text-[11px] leading-4 ${t}`;if(e.kind===`inherit`||e.kind===`inherit-developer`)return(0,$.jsx)(`span`,{"data-testid":`engine-chip`,className:`${r} border-border/60 bg-muted/40 text-muted-foreground`,children:n(e.kind===`inherit`?`pipeline.inherits`:`pipeline.inheritsDeveloper`)});if(e.kind===`host`)return(0,$.jsxs)(`span`,{"data-testid":`engine-chip`,className:`${r} border-accent-info/30 bg-accent-info/10 text-accent-info`,children:[(0,$.jsx)(Ac,{className:`h-3 w-3 shrink-0 opacity-80`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`truncate`,children:[n(`pipeline.host`),` · `,(0,$.jsx)(`span`,{className:`font-mono`,children:e.command||n(`pipeline.noCommand`)})]})]});let i=[e.label,e.model,e.effort].filter(e=>!!e),a=e.local?xc:fs;return(0,$.jsxs)(`span`,{"data-testid":`engine-chip`,className:`${r} border-accent-primary/30 bg-accent-primary/10 text-accent-primary`,children:[(0,$.jsx)(a,{className:`h-3 w-3 shrink-0 opacity-80`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`truncate`,children:i.join(` · `)})]})}function lG({group:e,className:t=``}){let{t:n}=K(`agentRuntime`),r=e===`loop`;return(0,$.jsxs)(`div`,{className:`space-y-0.5 ${t}`,"data-testid":`phase-group-heading-${e}`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[r&&(0,$.jsx)(hc,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`text-xs font-semibold ${r?`text-muted-foreground`:`text-foreground`}`,children:n(`pipeline.groups.${e}.title`)}),r&&(0,$.jsx)(`span`,{className:`inline-flex h-4 items-center rounded border border-border/60 bg-muted/40 px-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:n(`pipeline.groups.loop.chip`)})]}),(0,$.jsx)(`p`,{className:`text-[11px] leading-4 text-muted-foreground`,children:n(`pipeline.groups.${e}.hint`)})]})}function uG({steps:e,active:t,onSelect:n}){let{t:r}=K(`agentRuntime`);return(0,$.jsx)(`div`,{className:`flex flex-col gap-3 lg:flex-row lg:items-stretch`,"data-testid":`pipeline-stepper`,children:iG.map((i,a)=>{let o=e.filter(e=>rG[e.id]===i),s=i===`loop`;return(0,$.jsxs)(`div`,{className:`contents`,children:[a>0&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 lg:flex-col lg:justify-center lg:gap-1 lg:px-1`,"aria-hidden":!0,"data-testid":`phase-group-divider`,children:[(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border lg:h-auto lg:w-px lg:flex-1`}),(0,$.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground/70 lg:[writing-mode:vertical-rl]`,children:r(`pipeline.groups.loop.chip`)}),(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border lg:h-auto lg:w-px lg:flex-1`})]}),(0,$.jsxs)(`section`,{"aria-labelledby":`pipeline-group-${i}-title`,"data-testid":`pipeline-group-${i}`,className:`min-w-0 space-y-2 rounded-lg border p-2.5 ${s?`border-dashed border-border/70 bg-muted/20`:`border-accent-primary/25 bg-accent-primary/5`}`,children:[(0,$.jsx)(`h4`,{id:`pipeline-group-${i}-title`,className:`sr-only`,children:r(`pipeline.groups.${i}.title`)}),(0,$.jsx)(lG,{group:i}),(0,$.jsx)(`ol`,{className:`flex flex-wrap items-stretch gap-y-2`,"aria-label":r(`pipeline.groups.${i}.title`),children:o.map((e,i)=>{let a=sG[e.id],c=e.id===t;return(0,$.jsxs)(`li`,{className:`flex min-w-0 items-center`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-current":c?`step`:void 0,"aria-label":`${i+1}. ${r(`pipeline.phases.${e.id}.name`)}`,onClick:()=>n(e.id),className:`group flex w-44 min-w-0 flex-col gap-1.5 rounded-lg border p-2.5 text-left transition-colors ${c?`border-primary/40 bg-primary/10 shadow-sm ring-1 ring-primary/40`:s?`border-border/70 bg-background/40 hover:bg-muted/60`:`border-border bg-background/60 hover:bg-muted/60`}`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-[10px] font-semibold ${c?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground group-hover:text-foreground`}`,children:i+1}),(0,$.jsx)(a,{className:`h-3.5 w-3.5 shrink-0 ${c?`text-primary`:`text-muted-foreground`}`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`truncate text-xs font-medium ${s&&!c?`text-foreground/80`:``}`,children:r(`pipeline.phases.${e.id}.name`)})]}),(0,$.jsx)(`span`,{className:`line-clamp-2 text-[11px] leading-4 text-muted-foreground`,children:r(`pipeline.phases.${e.id}.purpose`)}),(0,$.jsx)(cG,{engine:e.engine})]}),i<o.length-1&&(0,$.jsx)(`span`,{className:`flex w-5 shrink-0 items-center justify-center text-muted-foreground/60`,"aria-hidden":!0,children:(0,$.jsx)(Zo,{className:`h-3.5 w-3.5`})})]},e.id)})})]})]},i)})})}var dG=(0,Q.forwardRef)(function({phase:e,engine:t,open:n,active:r,onToggle:i,children:a},o){let{t:s}=K(`agentRuntime`),c=oG(e),l=sG[e],u=s(`pipeline.phases.${e}.name`),d=`pipeline-phase-${e}-body`;return(0,$.jsxs)(`fieldset`,{ref:o,id:`pipeline-phase-${e}`,"data-testid":`phase-card-${e}`,className:`scroll-mt-4 rounded-lg border transition-shadow ${r?`border-primary/40 ring-1 ring-primary/30`:`border-border`}`,children:[(0,$.jsx)(`legend`,{className:`sr-only`,children:u}),(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":n,"aria-controls":d,"aria-label":`${s(n?`pipeline.collapse`:`pipeline.open`)}: ${c}. ${u}`,onClick:i,className:`flex w-full flex-wrap items-center gap-2 rounded-t-lg px-3 py-2 text-left hover:bg-muted/40`,children:[(0,$.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-[10px] font-semibold ${r?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground`}`,children:c}),(0,$.jsx)(l,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:u}),(0,$.jsxs)(`span`,{className:`hidden text-[11px] text-muted-foreground sm:inline`,children:[`— `,s(`pipeline.phases.${e}.purpose`)]}),(0,$.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[(0,$.jsx)(cG,{engine:t}),(0,$.jsx)(Xo,{className:`h-3.5 w-3.5 text-muted-foreground transition-transform ${n?``:`-rotate-90`}`,"aria-hidden":!0})]})]}),(0,$.jsx)(`div`,{id:d,hidden:!n,className:`space-y-2 px-3 pb-3`,children:a})]})}),fG=[`claude`,`codex`,`gemini`,`kimi`],pG=[`architect`,`developer`,`reviewer`],mG=[...pG,`fixer`];function hG(e){return e.kind===`openai-compatible`&&e.label?.trim()?e.label.trim():e.id}function gG(e){if(!e||typeof e!=`object`)return!1;let t=e;return Array.isArray(t.providers)&&t.providers.every(e=>e&&typeof e.id==`string`&&[`cli`,`openai-compatible`].includes(e.kind))&&(t.status===void 0||typeof t.status==`object`&&t.status!==null)}var _G=[`architect`,`developer`,`host`];function vG(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.supported==`boolean`&&Array.isArray(t.catalog)&&t.catalog.every(e=>e&&typeof e.id==`string`&&_G.includes(e.phase))}function yG(e,t,n){let r={...e};return n?delete r[t]:r[t]=!1,Object.keys(r).length?r:void 0}var bG=[`type_correctness`,`pattern_adherence`,`test_coverage`,`security`,`architectural_alignment`],xG=[`ask`,`proceed`],SG={minScore:70,aspects:{type_correctness:60,pattern_adherence:60,test_coverage:60,security:75,architectural_alignment:60}},CG={maxTurns:100,maxAttempts:3,timeoutMs:15*6e4};function wG(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t.config;return typeof t.configured==`boolean`&&typeof t.runtimeAvailable==`boolean`&&n?.schemaVersion===1&&typeof n.enabled==`boolean`&&Array.isArray(n.providers)&&n.providers.every(e=>e&&typeof e.id==`string`&&[`cli`,`openai-compatible`].includes(e.kind))&&Array.isArray(n.verification)&&!!n.agents&&pG.every(e=>typeof n.agents[e]?.provider==`string`)}function TG(e){if(!e||typeof e!=`object`)return!1;let t=e;return Array.isArray(t.repositories)&&Array.isArray(t.suggestions)&&t.suggestions.every(e=>e&&typeof e.repositoryId==`string`&&typeof e.command==`string`&&Array.isArray(e.args))}function EG(e,t){let n=t,r=2;for(;e.some(({id:e})=>e===n);)n=`${t}-${r++}`;return n}function DG(e){return[e.command,...e.args].map(e=>/[\s"]/.test(e)?JSON.stringify(e):e).join(` `)}function OG(e){let t=[],n=``,r=!1,i=!1;for(let a=0;a<e.length;a++){let o=e[a];if(r){if(o===`\\`&&a+1<e.length){n+=e[++a];continue}if(o===`"`){r=!1;continue}n+=o;continue}if(o===`"`){r=!0,i=!0;continue}if(/\s/.test(o)){i&&=(t.push(n),n=``,!1);continue}n+=o,i=!0}return r||(i&&t.push(n),!t.length||!t[0])?null:{command:t[0],args:t.slice(1)}}var kG={architect:ss,developer:Ns,host:Ac};function AG({projectId:e,guardrails:t,onChange:n}){let{t:r,i18n:i}=K(`agentRuntime`),[a,o]=(0,Q.useState)(!0),[s,c]=(0,Q.useState)({status:`loading`});(0,Q.useEffect)(()=>{let t=!1;return c({status:`loading`}),fetch(`${Tr(e)}/agent-runtime/guardrails`,{cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(`guardrails`);let n=await e.json();if(!vG(n))throw Error(`guardrails`);t||c({status:`ready`,supported:n.supported,catalog:n.catalog})}).catch(()=>{t||c({status:`unsupported`})}),()=>{t=!0}},[e]);let l=s.status===`ready`?s.catalog:[],u=s.status===`ready`&&s.supported,d=l.filter(e=>t?.[e.id]===!1).length,f=l.length,p=e=>i.exists(`agentRuntime:guardrails.items.${e}.title`),m=`pipeline-guardrails-body`;return(0,$.jsxs)(`fieldset`,{id:`pipeline-guardrails`,"data-testid":`phase-card-guardrails`,className:`scroll-mt-4 rounded-lg border border-border transition-shadow`,children:[(0,$.jsx)(`legend`,{className:`sr-only`,children:r(`guardrails.title`)}),(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":a,"aria-controls":m,"aria-label":`${r(a?`pipeline.collapse`:`pipeline.open`)}: ${r(`guardrails.title`)}`,onClick:()=>o(e=>!e),className:`flex w-full flex-wrap items-center gap-2 rounded-t-lg px-3 py-2 text-left hover:bg-muted/40`,children:[(0,$.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-accent-success/15 text-accent-success`,children:(0,$.jsx)(Cc,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:r(`guardrails.title`)}),(0,$.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[s.status===`ready`&&u&&(0,$.jsx)(`span`,{"data-testid":`guardrails-active`,className:X(`inline-flex items-center rounded-md border px-1.5 py-0.5 text-[11px] leading-4`,d?`border-accent-warning/40 bg-accent-warning/10 text-accent-warning`:`border-accent-success/30 bg-accent-success/10 text-accent-success`),children:r(`guardrails.active`,{on:f-d,total:f})}),(0,$.jsx)(Xo,{className:`h-3.5 w-3.5 text-muted-foreground transition-transform ${a?``:`-rotate-90`}`,"aria-hidden":!0})]})]}),(0,$.jsxs)(`div`,{id:m,hidden:!a,className:`space-y-3 px-3 pb-3`,children:[(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`guardrails.intro`)}),s.status===`loading`&&(0,$.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:r(`loading`)}),(s.status===`unsupported`||s.status===`ready`&&!u)&&(0,$.jsx)(`p`,{role:`status`,className:`rounded-md border border-accent-warning/40 p-3 text-xs text-accent-warning`,children:r(`guardrails.unsupported`)}),s.status===`ready`&&(0,$.jsxs)(`fieldset`,{disabled:!u,className:`space-y-3 disabled:opacity-60`,children:[d>0&&(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(`button`,{type:`button`,className:`text-[11px] text-accent-primary underline-offset-2 hover:underline`,onClick:()=>n(void 0),children:r(`guardrails.reset`)})}),_G.map(e=>{let i=l.filter(t=>t.phase===e);if(!i.length)return null;let a=kG[e];return(0,$.jsxs)(`div`,{className:`space-y-2`,"data-testid":`guardrails-phase-${e}`,children:[(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:[(0,$.jsx)(a,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),r(`guardrails.phases.${e}`)]}),(0,$.jsx)(`ul`,{className:`divide-y divide-border/60 rounded-md border border-border/60`,children:i.map(e=>{let i=t?.[e.id]!==!1,a=p(e.id)?r(`guardrails.items.${e.id}.title`):e.id,o=p(e.id)?r(`guardrails.items.${e.id}.description`):r(`guardrails.unknown`),s=p(e.id)?r(`guardrails.items.${e.id}.why`):null,c=`guardrail-${e.id}-title`;return(0,$.jsxs)(`li`,{className:`flex items-start gap-3 px-3 py-2`,children:[(0,$.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-labelledby":c,"data-testid":`guardrail-${e.id}`,onClick:()=>n(yG(t,e.id,!i)),className:X(`relative mt-0.5 inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors`,i?`bg-accent-primary/70`:`bg-muted-foreground/30`),children:(0,$.jsx)(`span`,{className:X(`absolute h-3 w-3 rounded-full bg-background shadow transition-transform`,i?`translate-x-3.5`:`translate-x-0.5`)})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{id:c,className:X(`text-xs font-medium`,!i&&`text-muted-foreground line-through decoration-muted-foreground/50`),children:a}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-4 text-muted-foreground`,children:o}),s&&(0,$.jsx)(`p`,{className:`mt-0.5 text-[10px] italic leading-4 text-muted-foreground/70`,children:s})]})]},e.id)})})]},e)})]})]})]})}var jG=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function MG(e){let t=e.parentElement;for(;t&&t!==document.body;){let e=getComputedStyle(t);if(/(auto|scroll)/.test(e.overflowY)&&t.scrollHeight>t.clientHeight)break;t=t.parentElement}if(!t||t===document.body){e.scrollIntoView?.({behavior:`smooth`,block:`nearest`});return}let n=e.getBoundingClientRect().top-t.getBoundingClientRect().top+t.scrollTop-12;typeof t.scrollTo==`function`?t.scrollTo({top:n,behavior:`smooth`}):t.scrollTop=n}function NG(){let{activeProjectId:e,projects:t}=pt(),n=(0,Q.useRef)(new Map),r=t.find(t=>t.id===e);return e?(0,$.jsx)(LG,{projectId:e,cache:n.current,projectProviderIds:r?.providers?.length?r.providers:r?.provider?[r.provider]:[],repositories:Er(r).map(({id:e,name:t})=>({id:e,name:t}))},e):null}function PG(e){return e.map(e=>({original:e,label:e.label,repositoryId:e.repositoryId,line:DG(e)}))}function FG(e){return e.map(e=>({repositoryId:e.repositoryId,line:DG(e),reason:e.reason}))}function IG(e){return e===void 0?``:String(Math.round(e/6e4*100)/100)}function LG({projectId:e,cache:t,repositories:n,projectProviderIds:r}){let{t:i}=K([`agentRuntime`,`agents`]),a=Zx(),o=t.get(e),[s,c]=(0,Q.useState)(o??null),[l,u]=(0,Q.useState)(o?.config??null),[d,f]=(0,Q.useState)(PG(o?.config.verification??[])),[p,m]=(0,Q.useState)([]),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(!1),[C,w]=(0,Q.useState)(null),[T,E]=(0,Q.useState)(!o),[D,O]=(0,Q.useState)(``),[k,A]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(0),[F,I]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(()=>Object.fromEntries(nG.map(e=>[e,!0]))),z=(0,Q.useRef)({}),B=$W(e),V=(0,Q.useRef)(!1),H=(0,Q.useRef)(!0),U=`${Tr(e)}/agent-runtime/config`,W=(0,Q.useRef)(0),ee=(0,Q.useRef)(l);ee.current=l;let te=JSON.stringify([e,l?.providers,l&&pG.map(e=>{let t=l.agents[e];return[e,t.provider,t.model??null,t.escalation?.model||null]}),l?.fixer?[`fixer`,l.fixer.provider,l.fixer.model??null,l.fixer.escalation?.model||null]:null]);async function ne(t){if(!ee.current)return;let n=structuredClone(ee.current);for(let e of[...Object.values(n.agents),...n.fixer?[n.fixer]:[]])e.escalation&&!e.escalation.model.trim()&&delete e.escalation;let r=++W.current;g(!0),v(!1);try{let i=await fetch(`${Tr(e)}/agent-runtime/capabilities`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n),signal:t}),a=await i.json();if(!i.ok||a.schemaVersion!==1||!Array.isArray(a.roles))throw Error(`capabilities`);H.current&&!t?.aborted&&r===W.current&&m(a.roles)}catch{H.current&&!t?.aborted&&r===W.current&&(m([]),v(!0))}finally{H.current&&!t?.aborted&&r===W.current&&g(!1)}}(0,Q.useEffect)(()=>{if(W.current++,m([]),v(!1),!ee.current||s?.efficiencyAvailable===!1){g(!1);return}let e=new AbortController;g(!0);let t=setTimeout(()=>{ne(e.signal)},250);return()=>{clearTimeout(t),e.abort(),W.current++}},[te,s?.efficiencyAvailable,N]);let re=`${Tr(e)}/agent-runtime/verification-suggestions`;async function ie(){try{let e=await fetch(re,{cache:`no-store`});if(!e.ok)return null;let t=await e.json();return TG(t)?t.suggestions:null}catch{return null}}(0,Q.useEffect)(()=>{H.current=!0;let n=!1;return fetch(U,{cache:`no-store`}).then(async r=>{if(!r.ok)throw Error(i(`loadFailed`));let a=await r.json();if(!wG(a))throw Error(i(`loadFailed`));if(!n){if(t.set(e,a),c(a),!V.current&&(u(a.config),f(PG(a.config.verification)),!a.configured&&a.config.verification.length===0)){let e=await ie();if(n||V.current)return;e?.length?(f(FG(e)),w(`some`)):e&&w(`none`)}O(``)}}).catch(()=>{n||O(i(`loadFailed`))}).finally(()=>{n||E(!1)}),()=>{n=!0,H.current=!1}},[U,e,t,N,i]);function ae(e){V.current=!0,A(!1),M(!0),u(e)}function oe(e){V.current=!0,A(!1),M(!0),f(e)}function se(e){if(e.kind===`cli`)return{value:e.id,label:i(`cliNames.${e.cli}`),detail:e.id,name:`${i(`cliNames.${e.cli}`)} (${e.id})`};let t=e.label?.trim();return{value:e.id,label:t||e.id,detail:t?`${e.id} · ${e.baseUrl}`:e.baseUrl,local:!0,name:t?`${t} (${e.id}) · ${e.baseUrl}`:`${e.id} · ${e.baseUrl}`}}function ce(e){if(e.kind!==`openai-compatible`)return[];let t=a.providers[e.id]?.models,n=t&&t.length?t:Jx(e.id).map(e=>e.value);return e.defaultModel&&!n.includes(e.defaultModel)?[e.defaultModel,...n]:n}function le(){let e=[];for(let t of d){if(!t.line.trim()&&!t.repositoryId)continue;let n=OG(t.line);if(!n||!t.repositoryId)return O(i(`verification.invalidLine`,{line:t.line||`∅`})),null;e.push({...t.original,...t.label===void 0?{}:{label:t.label.trim()||void 0},repositoryId:t.repositoryId,...n})}return e}async function ue(){S(!0),O(``);try{let e=await ie();if(!H.current)return;if(!e){O(i(`verification.detectFailed`));return}let t=new Set(d.map(e=>`${e.repositoryId}\0${e.line}`)),n=FG(e).filter(e=>!t.has(`${e.repositoryId}\0${e.line}`));oe([...d,...n]),w(e.length?`some`:`none`)}finally{H.current&&S(!1)}}async function de(){if(!l||y)return;O(``),A(!1);let n=le();if(n){b(!0);try{let r=await fetch(U,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...l,verification:n})}),a=await r.json();if(!r.ok)throw Error(a.message??a.error??i(`saveFailed`));if(!wG(a))throw Error(i(`saveFailed`));if(t.set(e,a),!H.current)return;V.current=!1,M(!1),c(a),u(a.config),f(PG(a.config.verification)),A(!0)}catch(e){H.current&&O(e instanceof Error?e.message:i(`saveFailed`))}finally{H.current&&b(!1)}}}let fe=l?.limits??{},G=(e,t,n=1)=>{if(!l)return;let r={...l.limits};t===``?delete r[e]:r[e]=e===`maxCostUsd`?Number(t):Math.round(Number(t)*n),ae({...l,limits:Object.keys(r).length?r:void 0})},pe=l?.review??{},me=(e,t)=>{if(!l)return;let n=t===``?void 0:Number(t),r={...pe.aspects};e!==`minScore`&&(n===void 0?delete r[e]:r[e]=n);let i={},a=e===`minScore`?n:pe.minScore;a!==void 0&&(i.minScore=a),Object.keys(r).length&&(i.aspects=r),ae({...l,review:Object.keys(i).length?i:void 0})},he=e=>{l&&ae({...l,architect:e?{onLowConfidence:e}:void 0})},ge=r.length?r:(l?.providers??[]).map(e=>e.id),_e=!!l?.enabled&&s?.runtimeAvailable!==!1;function ve(e){if(!l)return{kind:`inherit`};if(e===`verification`)return{kind:`host`,command:d.find(e=>e.line.trim())?.line.trim()??null};if(e===`verifier`||e===`decider`){let t=B.roles?.[e];return t?{kind:`ai`,label:jt(t.provider),model:eG(t),effort:t.effort??null,local:At(t.provider)}:{kind:`inherit`}}if(e===`fixer`&&!l.fixer)return{kind:`inherit-developer`};let t=e===`fixer`?l.fixer:l.agents[e],n=l.providers.find(e=>e.id===t.provider),r=n?se(n).label:t.provider,i=n?.kind===`openai-compatible`;return{kind:`ai`,label:r,model:t.model??(n?.kind===`cli`?Yx(n.cli):n?.defaultModel)??null,effort:t.effort??null,local:i}}let ye=nG.map(e=>({id:e,engine:ve(e)}));function be(e){I(e),R(t=>({...t,[e]:!0}));let t=z.current[e];t&&MG(t)}function xe(e){I(e),R(t=>({...t,[e]:!t[e]}))}function Se(e){if(!l)return null;let t=e===`fixer`?l.fixer:l.agents[e];if(!t)return null;let n=l.providers.find(e=>e.id===t.provider),r=t=>ae(e===`fixer`?{...l,fixer:t}:{...l,agents:{...l.agents,[e]:t}}),a=n?.kind===`cli`?Jx(n.cli):[],o=n?.kind===`cli`?Yx(n.cli):``,c=t.model&&!a.some(e=>e.value===t.model)?t.model:null;return(0,$.jsxs)($.Fragment,{children:[e!==`fixer`&&(0,$.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:i(`roleHints.${e}`)}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,$.jsxs)(`fieldset`,{className:`space-y-2 sm:col-span-3`,children:[(0,$.jsx)(`legend`,{className:`text-xs`,children:i(`agents.provider`)}),(0,$.jsx)(YW,{name:`runtime-${e}-provider`,value:t.provider,ariaLabel:i(`agents.provider`),tabs:l.providers.map(e=>se(e)),onChange:e=>r({...t,provider:e,model:void 0,effort:void 0,thinking:void 0,escalation:void 0})})]}),n?.kind===`cli`?(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`agents.model`),(0,$.jsxs)(`select`,{className:jG,value:t.model??``,onChange:e=>r({...t,model:e.target.value||void 0}),children:[(0,$.jsx)(`option`,{value:``,children:i(`agents.defaultModel`,{model:a.find(e=>e.value===o)?.label??o})}),a.map(e=>(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value)),c&&(0,$.jsx)(`option`,{value:c,children:c})]})]}):(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`agents.model`),(0,$.jsx)(Jj,{value:t.model??``,list:n?`runtime-${e}-models-${n.id}`:void 0,placeholder:n?.kind===`openai-compatible`&&n.defaultModel?i(`agents.defaultModel`,{model:n.defaultModel}):i(`agents.modelPlaceholder`),onChange:e=>r({...t,model:e.target.value||void 0})}),n&&(0,$.jsx)(`datalist`,{id:`runtime-${e}-models-${n.id}`,"data-testid":`runtime-${e}-models`,children:ce(n).map(e=>(0,$.jsx)(`option`,{value:e},e))})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`agents.maxTurns`,{turns:CG.maxTurns}),(0,$.jsx)(Jj,{type:`number`,min:`1`,step:`1`,placeholder:String(CG.maxTurns),value:t.maxTurns??``,onChange:e=>r({...t,maxTurns:e.target.value===``?void 0:Number(e.target.value)})})]}),n?.kind===`openai-compatible`&&(0,$.jsxs)(`fieldset`,{className:`space-y-1 text-xs`,children:[(0,$.jsx)(`legend`,{className:`text-xs`,children:i(`agents.thinking`)}),(0,$.jsx)(`div`,{role:`radiogroup`,"aria-label":i(`agents.thinking`),"data-testid":`runtime-${e}-thinking`,className:`flex w-full max-w-[12rem] rounded-lg border border-border bg-background/60 p-0.5`,children:[`off`,`on`].map(n=>{let a=(t.thinking??`off`)===n;return(0,$.jsxs)(`label`,{className:`relative flex min-w-0 flex-1 cursor-pointer items-center justify-center rounded-md px-3 py-1.5 transition-colors ${a?`bg-primary text-primary-foreground shadow-sm`:`text-muted-foreground hover:bg-muted/60`}`,children:[(0,$.jsx)(`input`,{type:`radio`,name:`runtime-${e}-thinking`,className:`absolute inset-0 h-full w-full cursor-pointer appearance-none opacity-0`,value:n,checked:a,onChange:()=>{let e={...t};n===`on`?e.thinking=`on`:delete e.thinking,r(e)}}),(0,$.jsx)(`span`,{className:`truncate`,children:i(`agents.thinking_${n}`)})]},n)})}),(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:i(`agents.thinkingHint`)})]})]}),(0,$.jsx)(`fieldset`,{disabled:s?.efficiencyAvailable===!1,children:(0,$.jsx)(qW,{role:e,agent:t,capabilities:p,onChange:r})})]})}function Ce(){if(!l)return null;let e=!!l.fixer,t=t=>{if(t===`own`===e)return;if(t===`inherit`){let e={...l};delete e.fixer,ae(e);return}let n=l.agents.developer;ae({...l,fixer:{provider:n.provider,...n.model?{model:n.model}:{}}})},n=(n,r)=>{let i=n===`own`===e;return(0,$.jsxs)(`label`,{className:`relative flex min-w-0 flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-md px-3 py-1.5 text-xs transition-colors ${i?`bg-primary text-primary-foreground shadow-sm`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`}`,children:[(0,$.jsx)(`input`,{type:`radio`,name:`runtime-fixer-mode`,className:`absolute inset-0 h-full w-full cursor-pointer appearance-none opacity-0`,value:n,checked:i,onChange:()=>t(n)}),n===`own`&&(0,$.jsx)(Bn,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`truncate`,children:r})]})};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:i(`fixer.hint`)}),(0,$.jsxs)(`fieldset`,{className:`mb-3 space-y-2`,children:[(0,$.jsx)(`legend`,{className:`text-xs`,children:i(`fixer.title`)}),(0,$.jsxs)(`div`,{role:`radiogroup`,"aria-label":i(`fixer.title`),"data-testid":`fixer-mode`,className:`flex w-full max-w-sm rounded-lg border border-border bg-background/60 p-0.5`,children:[n(`inherit`,i(`fixer.inherit`)),n(`own`,i(`fixer.own`))]})]}),e&&Se(`fixer`)]})}function we(){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`verification.hint`)}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,disabled:x,onClick:()=>void ue(),children:i(x?`verification.detecting`:`verification.detect`)})]}),C===`some`&&!d.some(e=>!e.reason)&&(0,$.jsx)(`p`,{role:`status`,className:`text-xs text-accent-success`,children:i(`verification.detected`)}),C===`none`&&d.length===0&&(0,$.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:i(`verification.nothingDetected`)}),d.map((e,t)=>(0,$.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-[minmax(8rem,1fr)_2fr_auto]`,children:[(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`verification.repository`),n.length?(0,$.jsxs)(`select`,{className:jG,value:e.repositoryId,onChange:e=>oe(d.map((n,r)=>r===t?{...n,repositoryId:e.target.value}:n)),children:[!n.some(t=>t.id===e.repositoryId)&&(0,$.jsx)(`option`,{value:e.repositoryId,children:e.repositoryId||`—`}),n.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id))]}):(0,$.jsx)(Jj,{value:e.repositoryId,onChange:e=>oe(d.map((n,r)=>r===t?{...n,repositoryId:e.target.value}:n))})]}),(0,$.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,$.jsxs)(`label`,{className:`block space-y-1`,children:[i(`verification.command`),(0,$.jsx)(Jj,{className:`font-mono`,spellCheck:!1,placeholder:`npm test`,value:e.line,onChange:e=>oe(d.map((n,r)=>r===t?{...n,line:e.target.value,reason:void 0}:n))})]}),(0,$.jsxs)(`label`,{className:`block space-y-1`,children:[i(`verification.label`),(0,$.jsx)(Jj,{maxLength:256,value:e.label??``,onChange:e=>oe(d.map((n,r)=>r===t?{...n,label:e.target.value}:n))})]}),e.reason&&(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:i(`verification.reason`,{reason:e.reason})})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-1`,children:[(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,"aria-label":`${i(`verification.moveUp`)} ${t+1}`,disabled:t===0,onClick:()=>{let e=[...d];[e[t-1],e[t]]=[e[t],e[t-1]],oe(e)},children:`↑`}),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,"aria-label":`${i(`verification.moveDown`)} ${t+1}`,disabled:t===d.length-1,onClick:()=>{let e=[...d];[e[t+1],e[t]]=[e[t],e[t+1]],oe(e)},children:`↓`}),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,onClick:()=>oe(d.filter((e,n)=>n!==t)),children:i(`verification.remove`)})]})]},t)),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,onClick:()=>oe([...d,{repositoryId:n[0]?.id??``,line:``}]),children:i(`verification.add`)})]})}function Te(e){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:i(`loopRoles.${e}Hint`)}),!_e&&(0,$.jsx)(`p`,{role:`status`,className:`rounded-md border border-accent-warning/40 p-3 text-xs text-accent-warning`,children:i(`loopRoles.disabled`)}),B.failed&&(0,$.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:i(`loadFailed`)}),B.roles===null&&!B.failed&&(0,$.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:i(`loading`)}),B.roles&&(0,$.jsx)(`fieldset`,{disabled:!_e,className:`disabled:opacity-60`,children:(0,$.jsx)(tG,{role:e,engine:B.roles[e],providers:ge,enabled:_e,onChange:t=>B.setRole(e,t)})})]})}return(0,$.jsxs)(NW,{id:`agent-runtime-settings`,children:[(0,$.jsxs)(PW,{children:[(0,$.jsx)(FW,{children:i(`title`)}),(0,$.jsx)(IW,{children:i(`description`)})]}),(0,$.jsxs)(LW,{className:`space-y-6`,children:[T&&(0,$.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:i(`loading`)}),D&&(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:D}),!l&&!T&&(0,$.jsx)(Z,{variant:`secondary`,onClick:()=>{E(!0),P(e=>e+1)},children:i(`retry`)}),l&&(0,$.jsxs)(`fieldset`,{disabled:y,className:`space-y-6 disabled:opacity-70`,children:[(0,$.jsx)(`div`,{className:`space-y-2`,children:s?.runtimeAvailable===!1&&(0,$.jsx)(`p`,{className:`rounded-md border border-accent-warning/40 p-3 text-xs text-accent-warning`,children:i(`unavailable`)})}),(0,$.jsxs)(`section`,{className:`space-y-4`,"aria-labelledby":`agent-runtime-pipeline`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`h3`,{id:`agent-runtime-pipeline`,className:`text-sm font-medium`,children:i(`pipeline.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`agents.hint`,{turns:CG.maxTurns})})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start gap-2 rounded-lg border border-accent-primary/30 bg-accent-primary/5 p-3 text-xs`,"data-testid":`pipeline-explainer`,children:[(0,$.jsxs)(`span`,{className:`inline-flex h-5 shrink-0 items-center gap-1 rounded border border-accent-primary/40 bg-accent-primary/10 px-1.5 text-[10px] text-accent-primary whitespace-nowrap`,title:i(`agents:railSelectors.rolesChipTitle`),children:[(0,$.jsx)(kn,{className:`h-3 w-3`,"aria-hidden":!0}),i(`agents:railSelectors.rolesChip`)]}),(0,$.jsx)(`p`,{className:`min-w-0 flex-1 text-muted-foreground`,children:i(`pipeline.explainer`,{roles:i(`agents:railSelectors.rolesChip`)})})]}),(0,$.jsx)(uG,{steps:ye,active:F,onSelect:be}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,disabled:h||s?.efficiencyAvailable===!1,onClick:()=>void ne(),children:i(`efficiency.checkCapabilities`)}),h&&(0,$.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:i(`loading`)}),_&&(0,$.jsx)(`p`,{className:`text-xs text-destructive`,children:i(`efficiency.capabilitiesFailed`)})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[iG.map(e=>(0,$.jsxs)(`div`,{className:`space-y-3`,"data-testid":`phase-cards-${e}`,children:[(0,$.jsx)(lG,{group:e,className:e===`loop`?`border-t border-border/60 pt-3`:``}),aG[e].map(e=>(0,$.jsx)(dG,{ref:t=>{z.current[e]=t},phase:e,engine:ve(e),open:L[e],active:F===e,onToggle:()=>xe(e),children:e===`verification`?we():e===`fixer`?Ce():e===`verifier`||e===`decider`?Te(e):Se(e)},e))]},e)),(0,$.jsx)(AG,{projectId:e,guardrails:l.guardrails,onChange:e=>{let t={...l,guardrails:e};e||delete t.guardrails,ae(t)}})]})]}),s?.efficiencyAvailable===!1&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`efficiency.capabilitiesFailed`)}),(0,$.jsx)(`fieldset`,{disabled:s?.efficiencyAvailable===!1,children:(0,$.jsx)(JW,{config:l,onChange:ae})}),(0,$.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,$.jsx)(`legend`,{className:`text-sm font-medium`,children:i(`limits.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`limits.hint`,{attempts:CG.maxAttempts,minutes:CG.timeoutMs/6e4})}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`limits.maxAttempts`,{attempts:CG.maxAttempts}),(0,$.jsx)(Jj,{type:`number`,min:`1`,step:`1`,placeholder:String(CG.maxAttempts),value:fe.maxAttempts??``,onChange:e=>G(`maxAttempts`,e.target.value)})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`limits.timeoutMinutes`,{minutes:CG.timeoutMs/6e4}),(0,$.jsx)(Jj,{type:`number`,min:`1`,step:`1`,placeholder:String(CG.timeoutMs/6e4),value:IG(fe.timeoutMs),onChange:e=>G(`timeoutMs`,e.target.value,6e4)})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`limits.maxTokens`),(0,$.jsx)(Jj,{type:`number`,min:`1`,step:`1`,placeholder:i(`limits.unlimited`),value:fe.maxTokens??``,onChange:e=>G(`maxTokens`,e.target.value)})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`limits.maxCostUsd`),(0,$.jsx)(Jj,{type:`number`,min:`0.000001`,step:`any`,placeholder:i(`limits.unlimited`),value:fe.maxCostUsd??``,onChange:e=>G(`maxCostUsd`,e.target.value)})]})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-3 text-xs`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:l.approvalBeforeArchive??!1,onChange:e=>ae({...l,approvalBeforeArchive:e.target.checked})}),i(`approvalBeforeArchive`)]})]}),(0,$.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,$.jsx)(`legend`,{className:`text-sm font-medium`,children:i(`review.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`review.hint`,{score:SG.minScore,security:SG.aspects.security,aspect:SG.aspects.type_correctness})}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`review.minScore`,{score:SG.minScore}),(0,$.jsx)(Jj,{type:`number`,min:SG.minScore,max:`100`,step:`1`,placeholder:String(SG.minScore),value:pe.minScore??``,onChange:e=>me(`minScore`,e.target.value)})]}),bG.map(e=>(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`review.aspects.${e}`,{score:SG.aspects[e]}),(0,$.jsx)(Jj,{type:`number`,min:SG.aspects[e],max:`100`,step:`1`,placeholder:String(SG.aspects[e]),value:pe.aspects?.[e]??``,onChange:t=>me(e,t.target.value)})]},e))]})]}),(0,$.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,$.jsx)(`legend`,{className:`text-sm font-medium`,children:i(`architect.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`architect.hint`)}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs sm:w-1/2`,children:[i(`architect.onLowConfidence`),(0,$.jsxs)(`select`,{className:jG,value:l.architect?.onLowConfidence??``,onChange:e=>he(e.target.value),children:[(0,$.jsx)(`option`,{value:``,children:i(`agents.defaultModel`,{model:i(`architect.ask`)})}),xG.map(e=>(0,$.jsx)(`option`,{value:e,children:i(`architect.${e}`)},e))]})]})]}),(0,$.jsx)(`div`,{className:`sticky bottom-3 z-20 flex justify-end pointer-events-none`,"data-testid":`runtime-save-pill`,"data-unsaved":j,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto flex items-center gap-3 rounded-full border px-3 py-1.5 shadow-lg backdrop-blur transition-colors ${j?`border-accent-warning/40 bg-card/95`:`border-border/60 bg-card/80`}`,children:[j&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-accent-warning`,children:[(0,$.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-accent-warning`,"aria-hidden":!0}),i(`unsavedChanges`)]}),k&&!j&&(0,$.jsx)(`p`,{role:`status`,className:`text-xs text-accent-success`,children:i(`saved`)}),(0,$.jsx)(Z,{size:`sm`,className:`rounded-full`,disabled:y,onClick:()=>void de(),children:i(y?`saving`:`save`)})]})})]})]})]})}function RG(){return(0,$.jsx)(`div`,{className:`h-32 animate-pulse rounded-lg bg-muted/30`,"data-testid":`section-skeleton`})}function zG(){let{t:e}=K(`settings`),{activeProjectId:t}=pt(),[n,r]=(0,Q.useState)(!0),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!1);if((0,Q.useEffect)(()=>{if(!t)return;let e=!1;return s(!1),fetch(`${ut()}/settings`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&r(t.pipelineTelemetryEnabled??!0)}).catch(()=>{}).finally(()=>{e||s(!0)}),()=>{e=!0}},[t]),!o)return(0,$.jsx)(RG,{});async function c(t){a(!0);let i=n;r(t);try{if(!(await fetch(`${ut()}/settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pipelineTelemetryEnabled:t})})).ok)throw Error(`Failed to save`);J.success(e(t?`telemetry.enabled`:`telemetry.disabled`))}catch(t){r(i),J.error(e(`telemetry.saveFailed`),{description:t.message})}finally{a(!1)}}return(0,$.jsxs)(NW,{children:[(0,$.jsxs)(PW,{children:[(0,$.jsx)(FW,{children:e(`telemetry.title`)}),(0,$.jsx)(IW,{children:e(`telemetry.description`)})]}),(0,$.jsx)(LW,{className:`space-y-4`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium`,children:e(`telemetry.toggleLabel`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:(0,$.jsx)(lt,{ns:`settings`,i18nKey:`telemetry.toggleDescription`,components:{mono:(0,$.jsx)(`span`,{className:`font-mono`})}})})]}),(0,$.jsx)(`button`,{type:`button`,role:`switch`,"aria-label":e(`telemetry.toggleLabel`),"aria-checked":n,disabled:i,onClick:()=>c(!n),className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 ${n?`bg-primary`:`bg-input`}`,children:(0,$.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-background shadow-sm transition-transform ${n?`translate-x-4`:`translate-x-0.5`}`})})]})})]})}function BG(){let{t:e}=K(`settings`),{activeProjectId:t}=pt(),[n,r]=(0,Q.useState)(``),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1);async function u(e){let t=await fetch(`${ut()}/integration-branch`).then(e=>e.ok?e.json():null).catch(()=>null);e?.current||t&&(r(t.configured??``),t.branch&&a({branch:t.branch,source:t.source??``}))}if((0,Q.useEffect)(()=>{if(!t)return;let e={current:!1};return l(!1),u(e).finally(()=>{e.current||l(!0)}),()=>{e.current=!0}},[t]),!c)return(0,$.jsx)(RG,{});async function d(){s(!0);try{let t=await fetch(`${ut()}/settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({integrationBranch:n.trim()})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Failed to save`)}J.success(e(`integrationBranch.saved`)),await u()}catch(t){J.error(e(`integrationBranch.saveFailed`),{description:t.message})}finally{s(!1)}}return(0,$.jsxs)(NW,{children:[(0,$.jsxs)(PW,{children:[(0,$.jsx)(FW,{children:e(`integrationBranch.title`)}),(0,$.jsx)(IW,{children:e(`integrationBranch.description`)})]}),(0,$.jsxs)(LW,{className:`space-y-3`,children:[(0,$.jsx)(Jj,{value:n,onChange:e=>r(e.target.value),placeholder:e(`integrationBranch.placeholder`),"data-testid":`integration-branch-input`}),i&&(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,"data-testid":`integration-branch-resolved`,children:(0,$.jsx)(lt,{ns:`settings`,i18nKey:`integrationBranch.resolved`,values:{branch:i.branch},components:{mono:(0,$.jsx)(`span`,{className:`font-mono`})}})}),(0,$.jsx)(Z,{size:`sm`,onClick:d,disabled:o,"data-testid":`integration-branch-save`,children:e(`integrationBranch.save`)})]})]})}var VG=/^[A-Za-z_][A-Za-z0-9_]*$/,HG=[`NODE_AUTH_TOKEN`,`NPM_TOKEN`,`AWS_PROFILE`];function UG(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}function WG(){let{t:e}=K(`settings`),{activeProjectId:t}=pt(),[n,r]=(0,Q.useState)([]),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1);if((0,Q.useEffect)(()=>{if(!t)return;let e=!1;return d(!1),s(``),fetch(`${ut()}/settings`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&r(Array.isArray(t.worktreeEnvPassthrough)?t.worktreeEnvPassthrough:[])}).catch(()=>{}).finally(()=>{e||d(!0)}),()=>{e=!0}},[t]),!u)return(0,$.jsx)(RG,{});function f(t){let i=UG(t);if(i.length===0)return;let o=[...n];for(let t of i){if(t.includes(`=`)){s(e(`worktreeEnv.noValues`));return}if(!VG.test(t)){s(e(`worktreeEnv.invalidName`,{name:t}));return}o.includes(t)||o.push(t)}r(o),a(``),s(``)}async function p(){l(!0);try{let t=await fetch(`${ut()}/settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({worktreeEnvPassthrough:n})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Failed to save`)}let i=await t.json();r(i.settings?.worktreeEnvPassthrough??n),J.success(e(`worktreeEnv.saved`))}catch(t){J.error(e(`worktreeEnv.saveFailed`),{description:t.message})}finally{l(!1)}}return(0,$.jsxs)(NW,{children:[(0,$.jsxs)(PW,{children:[(0,$.jsx)(FW,{children:e(`worktreeEnv.title`)}),(0,$.jsx)(IW,{children:e(`worktreeEnv.description`)})]}),(0,$.jsxs)(LW,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`label`,{htmlFor:`worktree-env-name`,className:`text-xs font-medium`,children:e(`worktreeEnv.label`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Jj,{id:`worktree-env-name`,value:i,onChange:e=>{a(e.target.value),s(``)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f(i))},placeholder:e(`worktreeEnv.placeholder`),"aria-invalid":!!o,"data-testid":`worktree-env-input`}),(0,$.jsxs)(Z,{type:`button`,size:`sm`,variant:`secondary`,className:`h-9 shrink-0`,onClick:()=>f(i),disabled:!i.trim(),"data-testid":`worktree-env-add`,children:[(0,$.jsx)(Pn,{className:`w-3.5 h-3.5`}),e(`worktreeEnv.add`)]})]}),o?(0,$.jsx)(`p`,{className:`text-[10px] text-destructive`,"data-testid":`worktree-env-error`,children:o}):(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:e(`worktreeEnv.helper`)})]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:HG.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>f(e),className:`rounded-md border border-border bg-muted/30 px-2 py-1 font-mono text-[10px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:e},e))}),n.length>0?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,"data-testid":`worktree-env-list`,children:n.map(t=>(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1 font-mono text-[11px]`,children:[t,(0,$.jsx)(`button`,{type:`button`,onClick:()=>r(n.filter(e=>e!==t)),className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":e(`worktreeEnv.remove`,{name:t}),children:(0,$.jsx)(Vn,{className:`w-3 h-3`})})]},t))}):(0,$.jsx)(`p`,{className:`rounded-md border border-dashed border-border bg-muted/20 px-3 py-2 text-xs text-muted-foreground`,children:e(`worktreeEnv.empty`)}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(Z,{size:`sm`,onClick:p,disabled:c,"data-testid":`worktree-env-save`,children:e(c?`common:states.saving`:`worktreeEnv.save`)})})]})]})}function GG({value:e,onChange:t,onSave:n,isSaving:r,fieldId:i,i18nRoot:a}){let{t:o}=K(`settings`);return(0,$.jsxs)(NW,{children:[(0,$.jsxs)(PW,{children:[(0,$.jsx)(FW,{children:o(`${a}.title`)}),(0,$.jsx)(IW,{children:o(`${a}.description`)})]}),(0,$.jsxs)(LW,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`label`,{htmlFor:i,className:`text-xs font-medium`,children:o(`${a}.label`)}),(0,$.jsx)(`textarea`,{id:i,value:e,onChange:e=>t(e.target.value),placeholder:o(`${a}.placeholder`),className:`min-h-32 w-full rounded-md border border-input bg-background px-3 py-2 text-sm shadow-sm outline-none transition-colors focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/20`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`${a}.helper`)})]}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs`,disabled:r,onClick:n,children:o(r?`common:states.saving`:`${a}.saveButton`)})})]})]})}function KG(){let{t:e}=K(`settings`),{activeProjectId:t}=pt(),[n,r]=(0,Q.useState)(``),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),f=(0,Q.useRef)({pre:!1,freestyle:!1});(0,Q.useEffect)(()=>{if(!t)return;let e=!1;return d(!1),f.current={pre:!1,freestyle:!1},fetch(`${ut()}/settings`).then(e=>e.ok?e.json():null).then(t=>{e||!t||(f.current.pre||r(t.prePrompt??``),f.current.freestyle||s(t.freestylePrePrompt??``))}).catch(()=>{}).finally(()=>{e||d(!0)}),()=>{e=!0}},[t]);async function p(){a(!0);try{let t=await fetch(`${ut()}/settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prePrompt:n})});if(!t.ok)throw Error(`Failed to save`);let i=(await t.json()).settings?.prePrompt??``;r(i),J.success(i.trim()===``?e(`prePrompt.cleared`):e(`prePrompt.saved`))}catch(t){J.error(e(`prePrompt.saveFailed`),{description:t.message})}finally{a(!1)}}async function m(){l(!0);try{let t=await fetch(`${ut()}/settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({freestylePrePrompt:o})});if(!t.ok)throw Error(`Failed to save`);let n=(await t.json()).settings?.freestylePrePrompt??``;s(n),J.success(n.trim()===``?e(`freestylePrePrompt.resetToDefault`):e(`freestylePrePrompt.saved`))}catch(t){J.error(e(`freestylePrePrompt.saveFailed`),{description:t.message})}finally{l(!1)}}return u?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(GG,{value:n,onChange:e=>{f.current.pre=!0,r(e)},onSave:p,isSaving:i,fieldId:`project-pre-prompt`,i18nRoot:`prePrompt`}),(0,$.jsx)(GG,{value:o,onChange:e=>{f.current.freestyle=!0,s(e)},onSave:m,isSaving:c,fieldId:`project-freestyle-pre-prompt`,i18nRoot:`freestylePrePrompt`})]}):(0,$.jsx)(RG,{})}function qG(){let{t:e}=K(`settings`),{activeProjectId:t}=pt(),[n,r]=(0,Q.useState)(``),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),f=(0,Q.useRef)({daily:!1,perJob:!1});(0,Q.useEffect)(()=>{if(!t)return;let e=!1;return d(!1),f.current={daily:!1,perJob:!1},fetch(`${ut()}/budget`).then(e=>e.ok?e.json():null).then(t=>{e||!t||(f.current.daily||r(t.dailyBudgetUsd==null?``:String(t.dailyBudgetUsd)),f.current.perJob||s(t.jobCostThresholdUsd==null?``:String(t.jobCostThresholdUsd)))}).catch(()=>{}).finally(()=>{e||d(!0)}),()=>{e=!0}},[t]);async function p(t,n,r,i){i(!0);try{if(!(await fetch(`${ut()}/budget`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)})).ok)throw Error(`Failed to save`);J.success(n)}catch(t){J.error(e(r),{description:t.message})}finally{i(!1)}}function m(t){let n=t.trim()===``?null:parseFloat(t);if(n!==null&&(isNaN(n)||n<=0)){J.error(e(`budget.invalidNumber`));return}return n}function h(){let t=m(n);t!==void 0&&p({dailyBudgetUsd:t},t==null?e(`budget.dailyRemoved`):e(`budget.dailySet`,{amount:t}),`budget.saveBudgetFailed`,a)}function g(){let t=m(o);t!==void 0&&p({jobCostThresholdUsd:t},t==null?e(`budget.perJobAlertDisabled`):e(`budget.alertSet`,{amount:t}),`budget.saveThresholdFailed`,l)}return u?(0,$.jsxs)(NW,{children:[(0,$.jsxs)(PW,{children:[(0,$.jsx)(FW,{children:e(`budget.title`)}),(0,$.jsx)(IW,{children:e(`budget.description`)})]}),(0,$.jsx)(LW,{children:(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`text-xs font-medium`,children:e(`budget.dailyLabel`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`budget.dailyHelper`)})]}),(0,$.jsx)(Jj,{type:`number`,min:`0`,step:`0.01`,value:n,onChange:e=>{f.current.daily=!0,r(e.target.value)},placeholder:e(`budget.dailyPlaceholder`),className:`h-8 text-xs font-mono`}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs`,disabled:i,onClick:h,children:e(i?`common:states.saving`:`common:actions.save`)})})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`text-xs font-medium`,children:e(`budget.perJobLabel`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`budget.perJobHelper`)})]}),(0,$.jsx)(Jj,{type:`number`,min:`0`,step:`0.01`,value:o,onChange:e=>{f.current.perJob=!0,s(e.target.value)},placeholder:e(`budget.perJobPlaceholder`),className:`h-8 text-xs font-mono`}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs`,disabled:c,onClick:g,children:e(c?`common:states.saving`:`common:actions.save`)})})]})]})})]}):(0,$.jsx)(RG,{})}function JG(){let{t:e}=K(`settings`),{activeProjectId:t}=pt(),n=p(),r=t!==null;(0,Q.useEffect)(()=>{if(!n.hash)return;let e=n.hash.slice(1),t=!1,r=Date.now()+3e3,i=()=>{if(t)return;let n=document.getElementById(e);if(n){n.scrollIntoView({behavior:`smooth`,block:`center`}),n.classList.add(`ring-2`,`ring-accent-primary/60`,`rounded`),window.setTimeout(()=>{n.classList.remove(`ring-2`,`ring-accent-primary/60`,`rounded`)},1800);return}Date.now()<r&&window.setTimeout(i,80)};return i(),()=>{t=!0}},[n.hash,n.key]);let[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(!0),c=(0,Q.useRef)(new Map);return(0,Q.useEffect)(()=>{if(t){let e=c.current.get(t);e?(a(e),s(!1)):s(!0)}async function e(){try{let e=await fetch(`${ut()}/config`);if(!e.ok)return;let n=await e.json();a(n),t&&c.current.set(t,n)}catch{}finally{s(!1)}}e()},[t]),o?(0,$.jsx)(`div`,{className:`max-w-2xl mx-auto px-4 py-6 space-y-3`,children:[0,1,2].map(e=>(0,$.jsx)(`div`,{className:`h-32 bg-muted/30 rounded-lg animate-pulse`},e))}):(0,$.jsxs)(`div`,{className:`max-w-2xl mx-auto px-4 py-6 space-y-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-base font-semibold`,children:e(`page.title`)}),i&&(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:[i.project.name,i.project.repo&&` · ${i.project.repo}`]})]}),r&&(0,$.jsx)(zG,{}),(0,$.jsx)(KG,{}),(0,$.jsx)(UW,{}),(0,$.jsx)(NG,{}),(0,$.jsx)(BG,{}),(0,$.jsx)(WG,{}),(0,$.jsx)(qG,{}),(0,$.jsx)(BW,{mode:`project`})]})}function YG(){let{t:e}=K(`agentRuntime`),[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)({}),[a,o]=(0,Q.useState)(`architect`),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(0);(0,Q.useEffect)(()=>{let t=!1;return c(``),fetch(`/api/runtime-role-prompts`).then(async r=>{let a=await r.json();if(!r.ok||!pG.every(e=>typeof a.defaults?.[e]==`string`))throw Error(a.message??e(`loadFailed`));t||(n(a),i(a.overrides),f(!1))}).catch(e=>{t||c(e.message)}),()=>{t=!0}},[e,p]);let h=t&&typeof t.defaults.fixer==`string`?mG:pG,g=(e,n)=>e[n]??t.defaults[n]??``,_=!!(t&&h.some(e=>r[e]!==t.overrides[e])),v=!!(t&&h.some(e=>{let t=g(r,e);return!t.trim()||t.length>2e4||t.includes(`\0`)}));function y(e,n){i(r=>{let i={...r};return n===t.defaults[e]?delete i[e]:i[e]=n,i}),f(!1)}async function b(){u(!0),c(``),f(!1);try{let t=await fetch(`/api/runtime-role-prompts`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({overrides:r})}),a=await t.json();if(!t.ok)throw Error(a.message??e(`saveFailed`));n(a),i(a.overrides),f(!0)}catch(e){c(e.message)}finally{u(!1)}}return(0,$.jsxs)(`section`,{className:`space-y-4 border-t border-border pt-6`,"aria-label":e(`prompts.title`),children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-base font-medium`,children:e(`prompts.title`)}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e(`prompts.description`)})]}),s&&(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:s}),!t&&(s?(0,$.jsx)(Z,{variant:`secondary`,onClick:()=>m(e=>e+1),children:e(`retry`)}):(0,$.jsx)(`p`,{role:`status`,children:e(`loading`)})),t&&(0,$.jsxs)(`fieldset`,{disabled:l,className:`min-w-0 space-y-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{role:`tablist`,"aria-label":e(`prompts.title`),className:`inline-flex flex-wrap gap-1 rounded-lg border border-border bg-muted p-1`,children:h.map((t,n)=>(0,$.jsx)(`button`,{type:`button`,role:`tab`,id:`role-tab-${t}`,"aria-controls":`role-panel-${t}`,"aria-selected":a===t,tabIndex:a===t?0:-1,className:`rounded-md px-3 py-1.5 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ${a===t?`bg-background font-medium shadow-sm`:`text-muted-foreground`}`,onClick:()=>o(t),onKeyDown:e=>{let t=e.key===`ArrowRight`?(n+1)%h.length:e.key===`ArrowLeft`?(n+h.length-1)%h.length:e.key===`Home`?0:e.key===`End`?h.length-1:-1;t<0||(e.preventDefault(),o(h[t]),e.currentTarget.parentElement?.querySelectorAll(`[role="tab"]`)[t]?.focus())},children:e(`roles.${t}`)},t))}),h.filter(e=>e===a).map(n=>(0,$.jsxs)(`div`,{role:`tabpanel`,id:`role-panel-${n}`,"aria-labelledby":`role-tab-${n}`,className:`mt-3 space-y-3`,children:[n===`fixer`&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`prompts.fixerHint`)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(`label`,{htmlFor:`role-prompt-${n}`,className:`text-sm font-medium`,children:e(`prompts.definition`,{role:e(`roles.${n}`)})}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(r[n]===void 0?`prompts.default`:`prompts.custom`)})]}),(0,$.jsx)(`textarea`,{id:`role-prompt-${n}`,value:g(r,n),onChange:e=>y(n,e.target.value),rows:18,maxLength:2e4,spellCheck:!1,className:`block max-h-[420px] min-h-64 w-full resize-y rounded-md border border-input bg-background p-3 font-mono text-xs leading-relaxed focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`span`,{children:[g(r,n).length.toLocaleString(),` / 20,000`]}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,disabled:r[n]===void 0,onClick:()=>y(n,t.defaults[n]??``),children:e(`prompts.restore`)})]})]},n))]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`prompts.contracts`)}),v&&(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:e(`prompts.invalid`)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-3`,children:[d&&(0,$.jsx)(`p`,{role:`status`,className:`text-sm text-accent-success`,children:e(`prompts.saved`)}),_&&(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`prompts.unsaved`)}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,disabled:!_,onClick:()=>{i(t.overrides),c(``),f(!1)},children:e(`prompts.discard`)}),(0,$.jsx)(Z,{type:`button`,disabled:l||!_||v,onClick:()=>void b(),children:e(l?`saving`:`prompts.save`)})]})]})]})}function XG(){let{t:e}=K(`settings`),t=HA();return(0,$.jsxs)(`div`,{className:`space-y-2`,"data-testid":`effects-section`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e(`effects.heading`)}),(0,$.jsxs)(`div`,{className:`rounded-md border border-border p-3 space-y-3`,children:[(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:e(`effects.description`)}),(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t.agentThinkingHalo,onClick:()=>BA({agentThinkingHalo:!t.agentThinkingHalo}),className:X(`relative mt-0.5 inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors`,t.agentThinkingHalo?`bg-accent-primary/70`:`bg-muted-foreground/30`),"data-testid":`effects-thinking-halo-toggle`,children:(0,$.jsx)(`span`,{className:X(`absolute h-3 w-3 rounded-full bg-background shadow transition-transform`,t.agentThinkingHalo?`translate-x-3.5`:`translate-x-0.5`)})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs font-medium`,children:[(0,$.jsx)(Ln,{className:`h-3.5 w-3.5 text-accent-primary`,"aria-hidden":!0}),e(`effects.thinkingHalo.label`)]}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[10px] text-muted-foreground`,children:e(`effects.thinkingHalo.description`)}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[10px] text-muted-foreground/80`,children:e(`effects.reducedMotion`)}),(0,$.jsxs)(`div`,{className:`mt-3`,children:[(0,$.jsx)(`p`,{className:`mb-1.5 text-[10px] uppercase tracking-wider text-muted-foreground`,children:e(`effects.preview`)}),(0,$.jsxs)(`div`,{className:`relative max-w-sm rounded-xl border border-border/60 bg-background/60 px-3 py-2`,"data-testid":`effects-thinking-halo-preview`,"data-active":t.agentThinkingHalo,children:[(0,$.jsx)(NA,{active:t.agentThinkingHalo,radius:`0.75rem`,inset:-3,fadeInMs:450,fadeOutMs:800}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`span`,{className:`inline-flex gap-0.5`,"aria-hidden":!0,children:[(0,$.jsx)(`span`,{className:`h-1 w-1 animate-pulse rounded-full bg-accent-primary`}),(0,$.jsx)(`span`,{className:`h-1 w-1 animate-pulse rounded-full bg-accent-primary [animation-delay:150ms]`}),(0,$.jsx)(`span`,{className:`h-1 w-1 animate-pulse rounded-full bg-accent-primary [animation-delay:300ms]`})]}),e(`effects.previewThinking`)]})]})]})]})]})]})]})}function ZG(){let{t:e}=K(`settings`),t=Ca();if(!t)return null;let{themeId:n,setTheme:r,isUpdating:i}=t;async function a(t){if(t!==n)try{await r(t)}catch(t){J.error(e(`appearance.updateFailed`),{description:t instanceof Error?t.message:void 0})}}return(0,$.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-2`,role:`radiogroup`,"aria-label":e(`appearance.themeGroupLabel`),children:Xi.map(t=>{let r=da[t],o=t===n;return(0,$.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":o,disabled:i,onClick:()=>void a(t),className:`group relative overflow-hidden rounded-lg border text-left transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/60 disabled:opacity-60 disabled:cursor-not-allowed `+(o?`border-accent-primary ring-1 ring-accent-primary shadow-[0_0_0_1px_var(--color-accent-primary)] `:`border-border hover:border-accent-primary/40 hover:shadow-md `),"data-testid":`theme-card-${t}`,"data-selected":o?`true`:`false`,children:[(0,$.jsx)(`div`,{className:`h-20 w-full flex items-end gap-1 p-2`,style:{background:`linear-gradient(135deg, ${r.previewSwatches.background} 0%, ${r.previewSwatches.background} 60%, color-mix(in srgb, ${r.previewSwatches.accents[0]} 18%, ${r.previewSwatches.background}) 100%)`},"aria-hidden":`true`,children:r.previewSwatches.accents.map((e,t)=>(0,$.jsx)(`span`,{className:`h-3 w-3 rounded-full ring-1 ring-black/10`,style:{background:e}},t))}),(0,$.jsxs)(`div`,{className:`p-3 space-y-1 bg-card`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`p`,{className:`text-xs font-semibold`,children:r.displayName}),o&&(0,$.jsx)(Sn,{className:`w-3.5 h-3.5 text-accent-primary shrink-0`,"aria-label":e(`appearance.currentlyActive`)})]}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground leading-tight`,children:e(`appearance.taglines.${t}`,{defaultValue:r.tagline})})]})]},t)})})}function QG(){let{t:e}=K(`settings`);return Ca()?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e(`appearance.heading`)}),(0,$.jsx)(ZG,{})]}):null}function $G(e={}){let t={...e},n=Ye();return n&&(t[`X-Desktop-Token`]=n),t}var eK=(0,Q.createContext)(null);function tK(e){if(!(typeof localStorage>`u`))try{localStorage.setItem(Ke,e)}catch{}}function nK(){if(!(typeof localStorage>`u`))try{localStorage.removeItem(Ke)}catch{}}function rK({children:e,endpoint:t=`/api/language`}){let[n,r]=(0,Q.useState)(()=>et()),[i,a]=(0,Q.useState)(!1),o=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{if(o.current)return;o.current=!0;let e=!1;return(async()=>{try{let n=await fetch(t,{headers:$G()});if(!n.ok)return;let i=await n.json();if(e)return;He(i.language)&&i.language!==et()&&(await at(i.language),tK(i.language),e||r(i.language))}catch{}})(),()=>{e=!0}},[t]);let s=(0,Q.useCallback)(async e=>{if(e===n)return;let i=n,o=typeof localStorage<`u`&&He(localStorage.getItem(`specrails-desktop:ui-language`));await at(e),tK(e),r(e),a(!0);try{let n=await fetch(t,{method:`PATCH`,headers:$G({"Content-Type":`application/json`}),body:JSON.stringify({language:e})});if(!n.ok)throw Error(`server rejected language: ${n.status}`)}catch(e){throw await at(i),o?tK(i):nK(),r(i),e}finally{a(!1)}},[n,t]),c=(0,Q.useMemo)(()=>({languageId:n,language:it[n],setLanguage:s,isUpdating:i}),[n,s,i]);return(0,$.jsx)(eK.Provider,{value:c,children:e})}function iK(){return(0,Q.useContext)(eK)}function aK(){let{t:e}=K(`settings`),t=iK();if(!t)return null;let{languageId:n,setLanguage:r,isUpdating:i}=t;async function a(t){if(t!==n)try{await r(t)}catch(t){J.error(e(`language.updateFailed`),{description:t instanceof Error?t.message:void 0})}}return(0,$.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,role:`radiogroup`,"aria-label":e(`language.selectLabel`),children:Ge.map(e=>{let t=it[e],r=e===n;return(0,$.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":r,disabled:i,onClick:()=>void a(e),className:`flex items-center justify-between gap-2 rounded-lg border bg-card px-3 py-2 text-left transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/60 disabled:opacity-60 disabled:cursor-not-allowed `+(r?`border-accent-primary ring-1 ring-accent-primary `:`border-border hover:border-accent-primary/40 hover:shadow-md `),"data-testid":`language-card-${e}`,"data-selected":r?`true`:`false`,children:[(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block text-xs font-semibold truncate`,children:t.nativeName}),(0,$.jsx)(`span`,{className:`block text-[10px] text-muted-foreground truncate`,children:t.englishName})]}),r&&(0,$.jsx)(Sn,{className:`w-3.5 h-3.5 text-accent-primary shrink-0`,"aria-hidden":`true`})]},e)})})}function oK(){let{t:e}=K(`settings`);return iK()?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e(`language.title`)}),(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e(`language.description`)}),(0,$.jsx)(aK,{})]}):null}function sK(){if(!me)return null;let{t:e}=K(`settings`),[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=!1;return fetch(`/api/code-explorer-settings`).then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(t=>{e||n(t)}).catch(()=>{e||n({language:`en`,monthlyBudgetUsd:5})}),()=>{e=!0}},[]);async function a(r){if(!t)return;let a={...t,...r};n(a),i(!0);try{let e=await fetch(`/api/code-explorer-settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)});if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();n(t)}catch(r){J.error(e(`errors.saveFailed`,{message:r.message})),n(t)}finally{i(!1)}}return t?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e(`codeSection.heading`)}),(0,$.jsxs)(`div`,{className:`rounded-md border border-border p-3 space-y-3`,children:[(0,$.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-xs`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e(`codeSection.summaryLanguage`)}),(0,$.jsxs)(`select`,{value:t.language,disabled:r,onChange:e=>a({language:e.target.value}),className:`bg-background border border-border rounded px-2 py-1 text-xs`,children:[(0,$.jsx)(`option`,{value:`en`,children:`English`}),(0,$.jsx)(`option`,{value:`es`,children:`Español`})]})]}),(0,$.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-xs`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e(`codeSection.monthlyBudget`)}),(0,$.jsx)(`input`,{type:`number`,min:0,step:.5,value:t.monthlyBudgetUsd,disabled:r,onChange:e=>{let t=parseFloat(e.target.value);!isNaN(t)&&t>=0&&a({monthlyBudgetUsd:t})},className:`bg-background border border-border rounded px-2 py-1 text-xs w-24 text-right`})]}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground/70`,children:e(`codeSection.budgetHelper`)})]})]}):(0,$.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`})}var cK=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function lK({provider:e,onChange:t,onRemove:n}){let{t:r}=K(`agentRuntime`),i=e.kind===`openai-compatible`,a=i?xc:Ec;return(0,$.jsxs)(`fieldset`,{className:`rounded-xl border border-border/70 bg-card/60 p-4 shadow-sm transition-colors hover:border-border`,"data-testid":`connection-row-${e.id}`,children:[(0,$.jsxs)(`legend`,{className:`flex items-center gap-2 px-1.5 text-sm font-medium`,children:[(0,$.jsx)(a,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":!0}),hG(e),(0,$.jsx)(`span`,{className:`rounded-full border border-border bg-muted/40 px-2 py-px text-[10px] font-normal uppercase tracking-wide text-muted-foreground`,children:r(i?`providers.localBadge`:`providers.cliBadge`)})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[r(`providers.id`),(0,$.jsx)(Jj,{value:e.id,onChange:n=>t({...e,id:n.target.value})})]}),e.kind===`cli`?(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[r(`providers.command`),(0,$.jsx)(`select`,{className:cK,value:e.cli,onChange:n=>t({...e,cli:n.target.value}),children:fG.map(e=>(0,$.jsx)(`option`,{value:e,children:r(`cliNames.${e}`)},e))})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[r(`providers.baseUrl`),(0,$.jsx)(Jj,{type:`url`,value:e.baseUrl,onChange:n=>t({...e,baseUrl:n.target.value})})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[r(`providers.apiKeyEnv`),(0,$.jsx)(Jj,{value:e.apiKeyEnv??``,onChange:n=>t({...e,apiKeyEnv:n.target.value||void 0})})]})]})]}),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:n,children:r(`providers.remove`)})]})]})}function uK(e,t=!1){if(t)return`probing`;if(!e)return`untested`;let n=e.reachable??e.installed;return n===void 0?`untested`:n?e.authState===`unauthenticated`?`unauthorized`:`reachable`:`unreachable`}var dK={probing:{dot:`bg-accent-info animate-pulse`,pill:`border-accent-info/30 bg-accent-info/10 text-accent-info`},reachable:{dot:`bg-accent-success`,pill:`border-accent-success/30 bg-accent-success/10 text-accent-success`},unauthorized:{dot:`bg-accent-warning`,pill:`border-accent-warning/30 bg-accent-warning/10 text-accent-warning`},unreachable:{dot:`bg-destructive`,pill:`border-destructive/30 bg-destructive/10 text-destructive`},untested:{dot:`bg-muted-foreground/50`,pill:`border-border bg-muted/40 text-muted-foreground`}};function fK({state:e,latencyMs:t,className:n}){let{t:r}=K(`agentRuntime`),i=dK[e];return(0,$.jsxs)(`span`,{"data-testid":`connection-status-pill`,"data-state":e,role:`status`,className:X(`inline-flex h-6 items-center gap-1.5 rounded-full border px-2.5 text-[11px] font-medium transition-colors`,i.pill,n),children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:X(`h-1.5 w-1.5 rounded-full`,i.dot)}),r(`providers.status.${e}`),e===`reachable`&&typeof t==`number`&&(0,$.jsxs)(`span`,{className:`text-[10px] font-normal opacity-70 tabular-nums`,children:[`· `,t,` ms`]})]})}function pK({label:e,items:t,trigger:n,triggerClassName:r,align:i=`right`}){let[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null),c=(0,Q.useId)();return(0,Q.useEffect)(()=>{if(!a)return;function e(e){s.current&&!s.current.contains(e.target)&&o(!1)}function t(e){if(e.key===`Escape`){o(!1);return}if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let t=Array.from(s.current?.querySelectorAll(`[role="menuitem"]`)??[]);if(!t.length)return;e.preventDefault();let n=t.indexOf(document.activeElement);t[e.key===`ArrowDown`?(n+1)%t.length:(n-1+t.length)%t.length]?.focus()}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]),(0,$.jsxs)(`div`,{ref:s,className:`relative`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":n?void 0:e,title:n?void 0:e,"aria-haspopup":`menu`,"aria-expanded":a,"aria-controls":a?c:void 0,onClick:()=>o(e=>!e),className:X(`inline-flex h-7 items-center justify-center gap-1.5 rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,n?`px-2 text-xs`:`w-7`,a&&`bg-accent text-foreground`,r),children:n??(0,$.jsx)(_s,{className:`h-4 w-4`,"aria-hidden":!0})}),a&&(0,$.jsx)(`div`,{id:c,role:`menu`,"aria-label":e,className:X(`absolute top-full z-30 mt-1 min-w-40 overflow-hidden rounded-lg border border-border bg-card p-1 shadow-lg`,i===`right`?`right-0`:`left-0`),children:t.map(e=>(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{o(!1),e.onSelect()},className:X(`flex w-full items-center gap-2 rounded-md px-2.5 py-1.5 text-left text-xs transition-colors hover:bg-accent focus-visible:bg-accent focus-visible:outline-none`,e.destructive?`text-destructive`:`text-foreground`),children:[e.icon,e.label]},e.id))})]})}function mK({provider:e,status:t,onRemove:n}){let{t:r}=K(`agentRuntime`),i=!!t;return(0,$.jsxs)(`li`,{"data-testid":`connection-row-${e.id}`,"data-kind":`cli`,className:X(`flex min-h-11 items-center gap-3 px-3 py-1.5 transition-colors`,i?`hover:bg-muted/30`:`opacity-55`),children:[(0,$.jsx)(`span`,{className:X(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md border`,i?`border-accent-info/30 bg-accent-info/10 text-accent-info`:`border-border bg-muted/40 text-muted-foreground`),children:(0,$.jsx)(Ec,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:r(`cliNames.${e.cli}`)}),t?.version&&(0,$.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground tabular-nums`,children:[`v`,t.version]}),(0,$.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground/60`,children:e.id})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[i?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(fK,{state:uK(t)}),(0,$.jsx)(`span`,{className:X(`hidden text-[11px] sm:inline`,t?.authState===`authenticated`?`text-muted-foreground`:`text-accent-warning`),children:r(`providers.auth.${t.authState}`)})]}):(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:r(`providers.notDetected`)}),(0,$.jsx)(pK,{label:r(`providers.overflow`),items:[{id:`remove`,label:r(`providers.remove`),icon:(0,$.jsx)(Rn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),destructive:!0,onSelect:n}]})]})]})}function hK(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.reachable==`boolean`&&typeof t.authState==`string`}function gK({baseUrl:e,apiKeyEnv:t,disabled:n,onStart:r,onResult:i,onError:a}){let{t:o}=K(`agentRuntime`),[s,c]=(0,Q.useState)(!1);async function l(){c(!0),r?.();try{let n=await fetch(`/api/runtime-providers/test`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({baseUrl:e,...t?{apiKeyEnv:t}:{}})}),r=await n.json().catch(()=>null);if(!n.ok||!hK(r))throw Error(r?.message??o(`providers.testFailed`));i({...r,models:Array.isArray(r.models)?r.models:[]})}catch(e){a(e.message||o(`providers.testFailed`))}finally{c(!1)}}return(0,$.jsxs)(Z,{type:`button`,variant:`secondary`,size:`sm`,disabled:n||s||!e.trim(),onClick:()=>void l(),className:`gap-1.5`,children:[s?(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(cc,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),o(s?`providers.testing`:`providers.test`)]})}function _K(e){return(e.agentLoop??`compact`)===`compact`&&e.supportsReasoningEffort===!0&&(e.contextWindowTokens??0)>=32768}var vK=`__custom__`,yK=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`,bK=`space-y-1 text-xs text-muted-foreground`;function xK(e){return e===void 0?``:String(e)}function SK(e){if(e.trim()===``)return null;let t=Number(e);return Number.isFinite(t)&&t>=0?t:NaN}function CK({provider:e,status:t,persisted:n,onChange:r,onStatus:i,onValidity:a,onRemove:o}){let{t:s}=K(`agentRuntime`),c=(0,Q.useId)(),[l,u]=(0,Q.useState)(!n),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)({input:xK(e.rates?.inputPer1M),output:xK(e.rates?.outputPer1M)}),[_,v]=(0,Q.useState)(!1),y=t?.models??[],b=!e.defaultModel||y.includes(e.defaultModel),x=_||!b,S=SK(h.input),C=SK(h.output),w=Number.isNaN(S)||Number.isNaN(C)||S===null!=(C===null);(0,Q.useEffect)(()=>{a(!w)},[w,a]);function T(t,n){let i={...h,[t]:n};g(i);let a=SK(i.input),o=SK(i.output);a===null&&o===null?r({...e,rates:void 0}):a!==null&&o!==null&&!Number.isNaN(a)&&!Number.isNaN(o)&&r({...e,rates:{inputPer1M:a,outputPer1M:o}})}function E(t){f(!1),m(``),i({reachable:t.reachable,authState:t.authState,models:t.models,latencyMs:t.latencyMs,error:t.error,apiKeyEnvMissing:t.apiKeyEnvMissing}),t.models.length&&qx(e.id,t.models)}let D=uK(t,d);return(0,$.jsxs)(`div`,{className:`space-y-4`,"data-testid":`local-connection-${e.id}`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(fK,{state:D,latencyMs:t?.latencyMs}),t?.error&&D!==`reachable`&&(0,$.jsx)(`span`,{className:`truncate text-[11px] text-destructive/90`,title:t.error,children:t.error}),(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,$.jsx)(gK,{baseUrl:e.baseUrl,apiKeyEnv:e.apiKeyEnv,onStart:()=>{f(!0),m(``)},onResult:E,onError:e=>{f(!1),m(e)}}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:o,children:s(`providers.remove`)})]})]}),p&&(0,$.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:p}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:bK,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`label`,{htmlFor:`${c}-id`,children:s(`providers.id`)}),n&&!l&&(0,$.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 text-[11px] text-accent-primary hover:underline`,onClick:()=>u(!0),children:[(0,$.jsx)(jn,{className:`h-3 w-3`,"aria-hidden":!0}),s(`providers.rename`)]})]}),(0,$.jsx)(Jj,{id:`${c}-id`,value:e.id,readOnly:!l,"aria-readonly":!l,title:l?void 0:s(`providers.idLocked`),className:X(!l&&`text-muted-foreground`),onChange:t=>r({...e,id:t.target.value})}),l&&n&&(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80`,children:s(`providers.renameHint`)})]}),(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-label`,children:[s(`providers.label`),(0,$.jsx)(Jj,{id:`${c}-label`,value:e.label??``,placeholder:s(`providers.labelPlaceholder`),onChange:t=>r({...e,label:t.target.value||void 0})})]}),(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-url`,children:[s(`providers.baseUrl`),(0,$.jsx)(Jj,{id:`${c}-url`,type:`url`,value:e.baseUrl,onChange:t=>r({...e,baseUrl:t.target.value})})]}),(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-env`,children:[s(`providers.apiKeyEnv`),(0,$.jsx)(Jj,{id:`${c}-env`,value:e.apiKeyEnv??``,onChange:t=>r({...e,apiKeyEnv:t.target.value||void 0})}),t?.apiKeyEnvMissing&&e.apiKeyEnv&&(0,$.jsxs)(`span`,{role:`note`,className:`flex items-center gap-1 text-[11px] text-accent-warning`,children:[(0,$.jsx)(zn,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}),s(`providers.apiKeyEnvMissing`,{name:e.apiKeyEnv})]})]})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:s(`providers.discoveredModels`)}),y.length===0?(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70`,children:s(`providers.noModels`)}):(0,$.jsx)(`ul`,{className:`flex flex-wrap gap-1.5`,"aria-label":s(`providers.discoveredModels`),children:y.map(t=>(0,$.jsx)(`li`,{children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>{v(!1),r({...e,defaultModel:t})},className:X(`rounded-full border px-2.5 py-0.5 font-mono text-[11px] transition-colors`,e.defaultModel===t?`border-accent-primary/50 bg-accent-primary/10 text-foreground`:`border-border bg-muted/30 text-muted-foreground hover:text-foreground`),"aria-pressed":e.defaultModel===t,children:t})},t))}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-default`,children:[s(`providers.defaultModel`),(0,$.jsxs)(`select`,{id:`${c}-default`,className:yK,value:x?vK:e.defaultModel??``,onChange:t=>{if(t.target.value===vK){v(!0);return}v(!1),r({...e,defaultModel:t.target.value||void 0})},children:[(0,$.jsx)(`option`,{value:``,children:s(`providers.defaultModelNone`)}),y.map(e=>(0,$.jsx)(`option`,{value:e,children:e},e)),(0,$.jsx)(`option`,{value:vK,children:s(`providers.customModel`)})]})]}),x&&(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-custom`,children:[s(`providers.customModel`),(0,$.jsx)(Jj,{id:`${c}-custom`,value:e.defaultModel??``,placeholder:s(`providers.defaultModelPlaceholder`),onChange:t=>r({...e,defaultModel:t.target.value||void 0})})]})]})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[s(`providers.rates`),` `,(0,$.jsxs)(`span`,{className:`text-muted-foreground/60`,children:[`· `,s(`providers.ratesHint`)]})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-in`,children:[s(`providers.inputRate`),(0,$.jsx)(Jj,{id:`${c}-in`,type:`number`,min:`0`,step:`0.01`,inputMode:`decimal`,value:h.input,onChange:e=>T(`input`,e.target.value),"aria-invalid":w})]}),(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-out`,children:[s(`providers.outputRate`),(0,$.jsx)(Jj,{id:`${c}-out`,type:`number`,min:`0`,step:`0.01`,inputMode:`decimal`,value:h.output,onChange:e=>T(`output`,e.target.value),"aria-invalid":w})]})]}),w&&(0,$.jsx)(`p`,{role:`alert`,className:`text-[11px] text-destructive`,children:s(`providers.ratesInvalid`)})]}),(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-xs`,htmlFor:`${c}-effort`,children:[(0,$.jsx)(`input`,{id:`${c}-effort`,type:`checkbox`,role:`switch`,"aria-checked":!!e.supportsReasoningEffort,className:`mt-0.5 accent-accent-primary`,checked:!!e.supportsReasoningEffort,onChange:t=>r({...e,supportsReasoningEffort:t.target.checked||void 0})}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-foreground`,children:s(`providers.reasoningEffort`)}),(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:s(`providers.reasoningEffortHint`)}),!e.supportsReasoningEffort&&(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground/70`,children:s(`providers.reasoningEffortRailHint`)})]})]}),(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border/60 bg-background/40 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:s(`providers.presetTitle`)}),(0,$.jsxs)(Z,{type:`button`,variant:`secondary`,size:`sm`,disabled:_K(e),title:s(`providers.presetSmallModelHint`),onClick:()=>r({...e,agentLoop:void 0,supportsReasoningEffort:!0,contextWindowTokens:e.contextWindowTokens??32768}),children:[(0,$.jsx)(Ln,{className:`mr-1 h-3.5 w-3.5`,"aria-hidden":!0}),_K(e)?s(`providers.presetSmallModelApplied`):s(`providers.presetSmallModel`)]})]}),(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70`,children:s(`providers.presetSmallModelHint`)})]}),(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border/60 bg-background/40 p-3`,children:[(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[s(`providers.agentLoop`),` `,(0,$.jsxs)(`span`,{className:`text-muted-foreground/60`,children:[`· `,s(`providers.agentLoopHint`)]})]}),(0,$.jsx)(`div`,{role:`radiogroup`,"aria-label":s(`providers.agentLoop`),className:`grid grid-cols-2 gap-1 rounded-md bg-muted/40 p-1`,children:[`compact`,`free`].map(t=>{let n=(e.agentLoop??`compact`)===t;return(0,$.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,className:X(`rounded px-2 py-1.5 text-xs transition-colors`,n?`bg-accent-primary/15 text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),onClick:()=>r({...e,agentLoop:t===`compact`?void 0:t}),children:[(0,$.jsx)(`span`,{className:`block font-medium`,children:s(`providers.agentLoop_${t}`)}),(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:s(`providers.agentLoop_${t}Hint`)})]},t)})}),(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-ctx`,children:[s(`providers.contextWindow`),(0,$.jsx)(Jj,{id:`${c}-ctx`,type:`number`,min:4096,step:1024,inputMode:`numeric`,placeholder:`32768`,value:e.contextWindowTokens??``,"aria-invalid":e.contextWindowTokens!==void 0&&e.contextWindowTokens<4096,onChange:t=>{let n=Number.parseInt(t.target.value,10);r({...e,contextWindowTokens:Number.isFinite(n)&&t.target.value!==``?n:void 0})}}),(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:s(`providers.contextWindowHint`)})]}),(0,$.jsxs)(`label`,{className:bK,htmlFor:`${c}-out`,children:[s(`providers.maxOutput`),(0,$.jsx)(Jj,{id:`${c}-out`,type:`number`,min:1024,step:1024,inputMode:`numeric`,placeholder:`8192`,value:e.maxOutputTokens??``,"aria-invalid":e.maxOutputTokens!==void 0&&e.maxOutputTokens<1024,onChange:t=>{let n=Number.parseInt(t.target.value,10);r({...e,maxOutputTokens:Number.isFinite(n)&&t.target.value!==``?n:void 0})}}),(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:s(`providers.maxOutputHint`)})]})]})]})}function wK(e){let t=e??32768;return t>=1024&&t%1024==0?`${t/1024}k`:t.toLocaleString()}function TK({provider:e,status:t,persisted:n,invalid:r=!1,onChange:i,onStatus:a,onValidity:o,onRemove:s}){let{t:c}=K(`agentRuntime`),[l,u]=(0,Q.useState)(!n),d=l||r,f=t?.models?.length??0,p=e.agentLoop??`compact`,m=hG(e),h=`local-engine-editor-${e.id||`new`}`;return(0,$.jsxs)(`div`,{"data-testid":`connection-row-${e.id}`,"data-kind":`local`,"data-expanded":d,className:X(`rounded-xl border bg-card/60 shadow-sm transition-colors`,d?`border-accent-primary/30`:`border-border/70 hover:border-border`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5`,children:[(0,$.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg border border-accent-highlight/30 bg-accent-highlight/10 text-accent-highlight`,children:(0,$.jsx)(xc,{className:`h-4 w-4`,"aria-hidden":!0})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,$.jsx)(`span`,{className:`truncate text-sm font-medium text-foreground`,children:m}),e.label?.trim()&&(0,$.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground/60`,children:e.id}),(0,$.jsx)(fK,{state:uK(t),latencyMs:t?.latencyMs})]}),(0,$.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`truncate font-mono`,children:e.baseUrl||`—`}),(0,$.jsx)(`span`,{"aria-hidden":!0,className:`text-muted-foreground/40`,children:`·`}),(0,$.jsx)(`span`,{className:`tabular-nums`,children:c(`providers.models`,{count:f})}),(0,$.jsx)(`span`,{"aria-hidden":!0,className:`text-muted-foreground/40`,children:`·`}),(0,$.jsx)(`span`,{className:X(`rounded-full border px-1.5 py-px text-[10px] font-medium`,p===`compact`?`border-accent-secondary/30 bg-accent-secondary/10 text-accent-secondary`:`border-border bg-muted/40 text-muted-foreground`),"data-testid":`agent-loop-chip`,children:c(`providers.agentLoop_${p}`)}),(0,$.jsxs)(`span`,{className:`tabular-nums`,title:c(`providers.contextWindow`),children:[wK(e.contextWindowTokens),` ctx`]})]})]}),(0,$.jsx)(`button`,{type:`button`,"aria-expanded":d,"aria-controls":h,"aria-label":c(d?`providers.collapse`:`providers.expand`),title:c(d?`providers.collapse`:`providers.expand`),disabled:r,onClick:()=>u(!d),className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-40`,children:(0,$.jsx)(Xo,{className:X(`h-4 w-4 transition-transform duration-200`,d&&`rotate-180`),"aria-hidden":!0})})]}),d&&(0,$.jsx)(`div`,{id:h,className:`border-t border-border/60 px-4 pb-4 pt-3`,children:(0,$.jsx)(CK,{provider:e,status:t,persisted:n,onChange:i,onStatus:a,onValidity:o,onRemove:s})})]})}var EK=1;function DK(e,t){return e.map(e=>({key:EK++,provider:e,persisted:t}))}function OK({children:e}){let{t}=K(`agentRuntime`),n=!ye(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)({}),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(()=>new Set),[h,g]=(0,Q.useState)(!0),_=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>{_.current=!0;let e=!1;return fetch(`/api/runtime-providers`).then(async n=>{let r=await n.json();if(!n.ok||!gG(r))throw Error(r?.message??t(`loadFailed`));e||(i(DK(r.providers,!0)),o(r.providers),c(r.status??{}))}).catch(t=>{e||u(t.message)}),()=>{e=!0,_.current=!1}},[t]);let v=(0,Q.useMemo)(()=>r?.map(e=>e.provider)??null,[r]),y=v!==null&&a!==null&&JSON.stringify(v)!==JSON.stringify(a),b=p.size>0,x=(0,Q.useCallback)((e,t)=>{i(n=>n?.map(n=>n.key===e?{...n,provider:t}:n)??n)},[]),S=(0,Q.useCallback)(e=>{i(t=>t?.filter(t=>t.key!==e)??t),m(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),C=(0,Q.useCallback)((e,t)=>{m(n=>{if(n.has(e)===!t)return n;let r=new Set(n);return t?r.delete(e):r.add(e),r})},[]),w=(0,Q.useCallback)((e,t)=>{c(n=>{let r={...n};return t?r[e]=t:delete r[e],r})},[]);function T(){if(!r)return;let e={id:EG(r.map(e=>e.provider),`local`),kind:`openai-compatible`,baseUrl:`http://127.0.0.1:11434/v1`};i([...r,{key:EK++,provider:e,persisted:!1}])}function E(e){if(!r)return;let t=r.map(e=>e.provider),n=e&&!t.some(t=>t.id===e)?{id:e,kind:`cli`,cli:e}:{id:EG(t,`cli`),kind:`cli`,cli:e??`claude`};i([...r,{key:EK++,provider:n,persisted:!1}])}async function D(){if(v){f(!0),u(``);try{let e=await fetch(`/api/runtime-providers`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({providers:v})}),n=await e.json().catch(()=>null);if(!e.ok||!gG(n))throw Error(n?.message??t(`saveFailed`));if(!_.current)return;i(DK(n.providers,!0)),o(n.providers),c(n.status??{}),m(new Set),J.success(t(`saved`))}catch(e){let n=e.message||t(`saveFailed`);_.current&&u(n),J.error(t(`saveFailed`),{description:n})}finally{_.current&&f(!1)}}}let O=r?.filter(e=>e.provider.kind===`cli`)??[],k=r?.filter(e=>e.provider.kind===`openai-compatible`)??[],A=fG.filter(e=>!O.some(t=>t.provider.cli===e)),j=(0,$.jsxs)(Z,{size:`sm`,className:`gap-1.5`,onClick:T,"data-testid":`add-local-engine`,children:[(0,$.jsx)(Pn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`providers.addLocalHero`)]});return(0,$.jsxs)(`section`,{className:`space-y-6`,"aria-labelledby":`provider-connections-title`,"data-testid":`provider-connections-card`,children:[(0,$.jsx)(`div`,{className:`flex flex-wrap items-start justify-between gap-4`,children:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(`span`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border border-accent-primary/30 bg-accent-primary/10 text-accent-primary shadow-sm`,children:(0,$.jsx)(fs,{className:`h-5 w-5`,"aria-hidden":!0})}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`h2`,{id:`provider-connections-title`,className:`text-base font-semibold tracking-tight`,children:t(`providers.globalTitle`)}),(0,$.jsx)(`p`,{className:`mt-1 max-w-2xl text-sm text-muted-foreground`,children:t(`providers.globalHint`)})]})]})}),l&&(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:l}),!r&&!l&&(0,$.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:t(`loading`)}),r&&n&&(0,$.jsxs)(`fieldset`,{disabled:d,className:`space-y-3 disabled:opacity-70`,children:[r.length===0&&(0,$.jsx)(`p`,{className:`rounded-xl border border-dashed border-border p-4 text-center text-xs text-muted-foreground`,children:t(`providers.empty`)}),r.map(e=>(0,$.jsx)(lK,{provider:e.provider,onChange:t=>x(e.key,t),onRemove:()=>S(e.key)},e.key)),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsxs)(Z,{variant:`secondary`,size:`sm`,className:`gap-1.5`,onClick:()=>E(),children:[(0,$.jsx)(Pn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`providers.addCli`)]}),(0,$.jsxs)(Z,{variant:`secondary`,size:`sm`,className:`gap-1.5`,onClick:T,children:[(0,$.jsx)(Pn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`providers.addLocal`)]})]})]}),r&&!n&&(0,$.jsxs)(`fieldset`,{disabled:d,className:`space-y-6 disabled:opacity-70`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,"data-testid":`cli-group`,children:[(0,$.jsx)(kK,{icon:(0,$.jsx)(Ec,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),title:t(`providers.cliGroup`),hint:t(`providers.cliGroupHint`),count:O.length,action:A.length>0&&(0,$.jsx)(pK,{label:t(`providers.addCli`),align:`right`,trigger:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Pn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`providers.addCli`)]}),items:A.map(e=>({id:e,label:t(`cliNames.${e}`),icon:(0,$.jsx)(Ec,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":!0}),onSelect:()=>E(e)}))})}),O.length===0?(0,$.jsx)(`p`,{className:`rounded-xl border border-dashed border-border p-4 text-center text-xs text-muted-foreground`,children:t(`providers.notDetected`)}):(0,$.jsx)(`ul`,{className:`divide-y divide-border/60 overflow-hidden rounded-xl border border-border/70 bg-card/60 shadow-sm`,"aria-label":t(`providers.cliGroup`),children:O.map(e=>(0,$.jsx)(mK,{provider:e.provider,status:s[e.provider.id],onRemove:()=>S(e.key)},e.key))})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,"data-testid":`local-group`,children:[(0,$.jsx)(kK,{icon:(0,$.jsx)(xc,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),title:t(`providers.localGroup`),hint:t(`providers.localGroupHint`),count:k.length,action:k.length>0?j:void 0}),k.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 rounded-xl border border-dashed border-border bg-card/30 px-4 py-8 text-center`,"data-testid":`local-empty`,children:[(0,$.jsx)(`span`,{className:`flex h-10 w-10 items-center justify-center rounded-xl border border-accent-highlight/30 bg-accent-highlight/10 text-accent-highlight`,children:(0,$.jsx)(xc,{className:`h-5 w-5`,"aria-hidden":!0})}),(0,$.jsx)(`p`,{className:`max-w-md text-xs text-muted-foreground`,children:t(`providers.emptyLocalPitch`)}),j]}):(0,$.jsx)(`div`,{className:`space-y-3`,children:k.map(e=>(0,$.jsx)(TK,{provider:e.provider,status:s[e.provider.id],persisted:e.persisted,invalid:p.has(e.key),onChange:t=>x(e.key,t),onStatus:t=>w(e.provider.id,t),onValidity:t=>C(e.key,t),onRemove:()=>S(e.key)},e.key))})]})]}),r&&(0,$.jsxs)(`div`,{className:X(`flex flex-wrap items-center justify-end gap-3 rounded-xl px-3 py-2 transition-all`,y&&`sticky bottom-0 z-20 border border-accent-warning/30 bg-card/95 shadow-lg backdrop-blur`),"data-testid":`provider-save-bar`,"data-sticky":y,children:[y&&(0,$.jsxs)(`span`,{className:`mr-auto inline-flex h-6 items-center gap-1.5 rounded-full border border-accent-warning/30 bg-accent-warning/10 px-2.5 text-[11px] font-medium text-accent-warning`,role:`status`,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-full bg-accent-warning`}),t(`providers.unsaved`)]}),b&&(0,$.jsx)(`p`,{className:`text-xs text-destructive`,children:t(`providers.fixBeforeSave`)}),(0,$.jsxs)(Z,{disabled:d||b||!y,className:`gap-1.5`,onClick:()=>void D(),children:[(0,$.jsx)(dn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(d?`saving`:`save`)]})]}),e&&(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/40`,"data-testid":`provider-defaults`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":h,"aria-controls":`provider-defaults-body`,onClick:()=>g(e=>!e),className:`flex w-full items-center gap-2 px-4 py-3 text-left transition-colors hover:bg-muted/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-xl`,children:[(0,$.jsx)(wc,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:t(`providers.defaultsGroup`)}),(0,$.jsx)(Xo,{className:X(`ml-auto h-4 w-4 text-muted-foreground transition-transform duration-200`,h&&`rotate-180`),"aria-hidden":!0})]}),h&&(0,$.jsx)(`div`,{id:`provider-defaults-body`,className:`px-4 pb-4 [&>section]:border-t-0 [&>section]:pt-1`,children:e})]})]})}function kK({icon:e,title:t,hint:n,count:r,action:i}){return(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-2 px-0.5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:[e,t,(0,$.jsx)(`span`,{className:`rounded-full border border-border bg-muted/40 px-1.5 py-px text-[10px] font-medium tabular-nums`,children:r})]}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[11px] text-muted-foreground/80`,children:n})]}),i]})}function AK(){let{t:e}=K(`settings`),{registerHandler:t,unregisterHandler:n}=tt(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(!1),d=(0,Q.useRef)(0),f=(0,Q.useRef)(null),p=(0,Q.useCallback)(async()=>{let e=++d.current;try{let t=await fetch(`/api/core-update/status`);if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();return e===d.current?(i(n),u(!1),n.updating||c(null),n):null}catch{return e===d.current&&u(!0),null}},[]);(0,Q.useEffect)(()=>{p();let e=()=>{p()};return window.addEventListener(`focus`,e),()=>{d.current++,window.removeEventListener(`focus`,e)}},[p]);let m=(0,Q.useRef)(p);m.current=p,(0,Q.useEffect)(()=>(t(`core-update`,t=>{let n=t;if(n.type===`framework.updated`){m.current();return}if(n.type!==`core_update.progress`)return;let r=n.phase;c(r),r===`done`?(J.success(e(`coreUpdate.toastDone`,{version:String(n.version??``)})),m.current(),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>c(null),2500)):r===`error`&&(J.error(e(`coreUpdate.toastError`,{message:String(n.message??``)})),m.current(),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>c(null),4e3))}),()=>{n(`core-update`),f.current&&clearTimeout(f.current)}),[t,n,e]);let h=(0,Q.useCallback)(async()=>{let t=++d.current;o(!0);try{let n=await fetch(`/api/core-update/check`,{method:`POST`});if(!n.ok)throw Error(`HTTP ${n.status}`);let r=await n.json();if(t!==d.current)return;i(r),r.updateAvailable||J.success(e(`coreUpdate.toastUpToDate`))}catch(t){J.error(e(`coreUpdate.toastCheckFailed`,{message:t.message}))}finally{o(!1)}},[e]),g=s===`downloading`||s===`materializing`||!!r?.updating;(0,Q.useEffect)(()=>{if(!g)return;let e=setInterval(()=>{p()},1500);return()=>clearInterval(e)},[g,p]);let _=(0,Q.useCallback)(async()=>{c(`downloading`);try{let e=await fetch(`/api/core-update/update`,{method:`POST`,headers:{"Content-Type":`application/json`},body:`{}`});if(e.status!==202){let t=await e.json().catch(()=>({}));throw Error(t.message??`HTTP ${e.status}`)}}catch(t){c(null),J.error(e(`coreUpdate.toastError`,{message:t.message}))}},[e]);if(!r)return l?(0,$.jsx)(`button`,{type:`button`,onClick:()=>{p()},className:`text-xs text-destructive`,children:e(`coreUpdate.loadFailed`)}):(0,$.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`});let v=r.currentVersion??`—`,y=r.pendingVersion??r.latestVersion;return(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e(`coreUpdate.heading`)}),(0,$.jsx)(`div`,{className:`rounded-md border border-border p-3 space-y-3`,children:r.available?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`p`,{className:`text-xs text-foreground`,children:[e(`coreUpdate.installed`),` `,(0,$.jsx)(`span`,{className:`font-semibold tabular-nums`,children:v})]}),r.runtimeVersion&&(0,$.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[e(`coreUpdate.runtime`,{version:r.runtimeVersion}),r.runtimeSource?` · ${e(`coreUpdate.sources.${r.runtimeSource}`)}`:``]}),r.bundledVersion&&r.bundledVersion!==r.runtimeVersion&&(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:e(`coreUpdate.bundled`,{version:r.bundledVersion})}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground/70 truncate`,children:r.updateAvailable&&r.latestVersion?e(`coreUpdate.updateAvailable`,{version:r.latestVersion}):r.lastCheckedAt?e(`coreUpdate.upToDate`):e(`coreUpdate.neverChecked`)})]}),r.updateAvailable&&y?(0,$.jsxs)(`button`,{type:`button`,onClick:_,disabled:g,className:`inline-flex h-7 shrink-0 items-center gap-1.5 rounded-lg border border-accent-primary/45 bg-accent-primary/15 px-3 text-[11px] font-semibold text-accent-primary disabled:opacity-50`,children:[g?(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(En,{className:`h-3.5 w-3.5`}),g?e(s===`materializing`?`coreUpdate.materializing`:`coreUpdate.downloading`):r.pendingVersion?e(`coreUpdate.repair`,{version:y}):e(`coreUpdate.update`,{version:y})]}):(0,$.jsxs)(`button`,{type:`button`,onClick:h,disabled:a||g,className:`inline-flex h-7 shrink-0 items-center gap-1.5 rounded-lg border border-border bg-background px-3 text-[11px] font-medium text-muted-foreground hover:text-foreground disabled:opacity-50`,children:[a?(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`}):s===`done`?(0,$.jsx)($o,{className:`h-3.5 w-3.5 text-accent-success`}):(0,$.jsx)(mc,{className:`h-3.5 w-3.5`}),e(a?`coreUpdate.checking`:`coreUpdate.check`)]})]}),r.runtimeError&&(0,$.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:r.runtimeError}),r.migrationError&&(0,$.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:r.migrationError}),l&&(0,$.jsx)(`button`,{type:`button`,className:`text-xs text-destructive`,onClick:()=>{p()},children:e(`coreUpdate.loadFailed`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground/70`,children:e(`coreUpdate.affectsAll`)})]}):(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e(`coreUpdate.unavailable`)})})]})}var jK=class extends ht{constructor(e){super(e.rid),this.available=!0,this.currentVersion=e.currentVersion,this.version=e.version,this.date=e.date,this.body=e.body,this.rawJson=e.rawJson}async download(e,t){NK(t);let n=new _t;e&&(n.onmessage=e);let r=await Y(`plugin:updater|download`,{onEvent:n,rid:this.rid,...t});this.downloadedBytes=new ht(r)}async install(){if(!this.downloadedBytes)throw Error(`Update.install called before Update.download`);await Y(`plugin:updater|install`,{updateRid:this.rid,bytesRid:this.downloadedBytes.rid}),this.downloadedBytes=void 0}async downloadAndInstall(e,t){NK(t);let n=new _t;e&&(n.onmessage=e),await Y(`plugin:updater|download_and_install`,{onEvent:n,rid:this.rid,...t})}async close(){await this.downloadedBytes?.close(),await super.close()}};async function MK(e){NK(e);let t=await Y(`plugin:updater|check`,{...e});return t?new jK(t):null}function NK(e){e?.headers&&(e.headers=Array.from(new Headers(e.headers).entries()))}var PK;(function(e){e.Nsis=`nsis`,e.Msi=`msi`,e.Deb=`deb`,e.Rpm=`rpm`,e.AppImage=`appimage`,e.App=`app`})(PK||={});async function FK(){return Y(`plugin:app|version`)}async function IK(){await Y(`plugin:process|restart`)}var LK=`specrails-desktop:dismissedDesktopUpdateVersion`,RK=`specrails-desktop-desktop-update`,zK=360*60*1e3;function BK(){return typeof window<`u`&&`__TAURI_INTERNALS__`in window}function VK(){return{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1}.VITE_MOCK_DESKTOP_UPDATE===`true`}function HK(){return{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1}.VITE_MOCK_DESKTOP_UPDATE_VERSION||`99.0.0-test`}function UK(e){return new Promise(t=>setTimeout(t,e))}function WK(){return{currentVersion:`1.40.1`,version:HK(),isMock:!0,async downloadAndInstall(e){e({event:`Started`,data:{contentLength:18874368}});for(let t=0;t<12;t+=1)await UK(180),e({event:`Progress`,data:{chunkLength:1572864}});e({event:`Finished`})}}}function GK(e){return e<1024*1024?Je.t(`commands:update.units.kb`,{value:Math.max(1,Math.round(e/1024))}):Je.t(`commands:update.units.mb`,{value:(e/(1024*1024)).toFixed(1)})}function KK(){try{return localStorage.getItem(LK)}catch{return null}}function qK(e){try{localStorage.setItem(LK,e)}catch{}J.dismiss(RK)}function JK(e){switch(e){case`downloading`:return`var(--color-accent-info)`;case`ready`:return`var(--color-accent-success)`;default:return`var(--color-accent-primary)`}}function YK({state:e}){let t=`h-[15px] w-[15px]`;return e===`installing`?(0,$.jsx)(as,{className:`${t} u-spin`,"aria-hidden":!0}):e===`ready`?(0,$.jsx)(Sn,{className:`${t} u-check`,"aria-hidden":!0}):e===`error`?(0,$.jsx)(zn,{className:t,"aria-hidden":!0}):(0,$.jsx)(rs,{className:t,"aria-hidden":!0})}function XK({state:e,progress:t}){let n=e===`downloading`&&t!=null,r=e===`installing`||e===`downloading`&&t==null,i=e===`ready`;return(0,$.jsxs)(`div`,{className:`relative h-1.5 w-full overflow-hidden rounded-full border border-border/30 bg-background/70`,children:[n&&(0,$.jsx)(`div`,{className:`relative h-full overflow-hidden rounded-full bg-[color:var(--u-accent)] transition-[width] duration-300 ease-out`,style:{width:`${t}%`},role:`progressbar`,"aria-valuenow":t??0,"aria-valuemin":0,"aria-valuemax":100,children:(0,$.jsx)(`span`,{className:`u-shimmer`,"aria-hidden":!0})}),r&&(0,$.jsx)(`span`,{className:`u-indeterminate`,"aria-hidden":!0}),i&&(0,$.jsx)(`div`,{className:`h-full w-full rounded-full bg-[color:var(--u-accent)]/80`,"aria-hidden":!0})]})}function ZK({update:e,onClose:t}){let{t:n}=K(`commands`),[r,i]=(0,Q.useState)(`available`),[a,o]=(0,Q.useState)(0),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null);async function d(){try{i(`downloading`),o(0),c(null),u(null),await e.downloadAndInstall(e=>{if(e.event===`Started`){c(e.data.contentLength??null),o(0);return}if(e.event===`Progress`){o(t=>t+e.data.chunkLength);return}i(`installing`)}),i(`ready`)}catch(e){u(e.message||n(`update.errors.installFailed`)),i(`error`)}}function f(){if(e.isMock){J.success(n(`update.mockReady`),{duration:2500}),J.dismiss(RK),t?.();return}Y(`restart_app`).catch(()=>{IK()})}let p=s&&s>0?Math.min(100,Math.round(a/s*100)):null,m=JK(r),h=r===`downloading`||r===`installing`,g=n(r===`downloading`?`update.title.downloading`:r===`installing`?`update.title.installing`:r===`ready`?`update.title.ready`:r===`error`?`update.title.error`:`update.title.available`),_=r===`available`?n(`update.desc.available`):r===`downloading`?p==null?n(`update.desc.fetching`,{size:GK(a)}):n(`update.desc.progress`,{percent:p,downloaded:GK(a),total:GK(s??0)}):r===`installing`?n(`update.desc.installing`):r===`ready`?n(`update.desc.ready`,{version:e.version}):l&&l.length<=80?l:n(`update.desc.errorFallback`),v=r===`available`?`${e.currentVersion} → ${e.version}`:r===`downloading`?n(`update.pill.downloading`):r===`installing`?n(`update.pill.installing`):r===`ready`?n(`update.pill.ready`):null;return(0,$.jsxs)(`div`,{className:`u-update-card relative flex w-full flex-col gap-2 overflow-hidden`,style:{"--u-accent":m},role:r===`error`?`alert`:`status`,"aria-live":r===`error`?`assertive`:`polite`,"data-state":r,children:[(0,$.jsx)(`span`,{className:`u-glow`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(`span`,{className:`u-badge grid h-7 w-7 shrink-0 place-items-center rounded-lg border border-border/50 bg-background/60 text-[color:var(--u-accent)]`,"aria-hidden":!0,children:(0,$.jsx)(YK,{state:r})}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] font-semibold leading-tight text-foreground`,children:g}),v!=null&&(0,$.jsx)(`span`,{className:`shrink-0 whitespace-nowrap rounded-md border border-border/40 bg-background/60 px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-muted-foreground`,style:r===`available`?void 0:{color:`var(--u-accent)`},children:v})]}),(0,$.jsx)(`p`,{className:`h-4 truncate text-[11px] leading-4 text-muted-foreground`,"data-testid":`update-description`,children:_}),(0,$.jsx)(XK,{state:r,progress:p}),(0,$.jsx)(`div`,{className:`flex items-center justify-end gap-1.5`,children:r===`ready`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,className:`inline-grid h-7 min-w-[64px] place-items-center rounded-lg border border-[color:var(--u-accent)]/45 bg-[color:var(--u-accent)]/15 px-3 text-[11px] font-semibold leading-none text-foreground transition-colors hover:bg-[color:var(--u-accent)]/25`,onClick:f,children:n(`update.actions.restart`)}),(0,$.jsx)(`button`,{type:`button`,className:`h-7 rounded-lg px-2.5 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-background/70 hover:text-foreground`,onClick:()=>{J.dismiss(RK),t?.()},children:n(`update.actions.later`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,className:`inline-grid h-7 min-w-[64px] place-items-center rounded-lg border border-[color:var(--u-accent)]/45 bg-[color:var(--u-accent)]/15 px-3 text-[11px] font-semibold leading-none text-foreground transition-colors hover:bg-[color:var(--u-accent)]/25 disabled:cursor-not-allowed disabled:opacity-50`,disabled:h,onClick:()=>void d(),children:n(r===`installing`?`update.actions.installing`:r===`error`?`update.actions.tryAgain`:`update.actions.update`)}),(0,$.jsx)(`button`,{type:`button`,className:`h-7 rounded-lg px-2.5 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-background/70 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,disabled:h,onClick:()=>{qK(e.version),t?.()},children:n(`update.actions.dismiss`)})]})})]})}function QK(e){J.custom(()=>(0,$.jsx)(ZK,{update:e}),{id:RK,duration:1/0,dismissible:!1,unstyled:!0,closeButton:!1})}function $K(){(0,Q.useEffect)(()=>{let e=VK();if(!e&&!BK())return;let t=!1,n={current:!1};async function r(){if(!(t||n.current))try{let r=e?WK():await MK();if(t||!r||KK()===r.version)return;n.current=!0,J.custom(()=>(0,$.jsx)(ZK,{update:r,onClose:()=>{n.current=!1}}),{id:RK,duration:1/0,dismissible:!1,unstyled:!0,closeButton:!1,onDismiss:()=>{n.current=!1},onAutoClose:()=>{n.current=!1}})}catch(e){console.warn(`[desktop-update] update check failed:`,e)}}r();let i=setInterval(()=>void r(),zK);return()=>{t=!0,clearInterval(i)}},[])}function eq(){let{t:e}=K(`settings`),t=VK(),n=BK()||t,[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!BK())return;let e=!0;return FK().then(t=>{e&&i(t)}).catch(()=>{}),()=>{e=!1}},[]);let d=(0,Q.useCallback)(async()=>{o(!0),c(null);try{let n=t?WK():await MK();n?(c(`update-available`),u(n.version),QK(n)):(c(`up-to-date`),J.success(e(`appUpdate.toastUpToDate`)))}catch(t){J.error(e(`appUpdate.toastCheckFailed`,{message:t.message}))}finally{o(!1)}},[t,e]);return(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e(`appUpdate.heading`)}),(0,$.jsx)(`div`,{className:`rounded-md border border-border p-3 space-y-3`,children:n?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`p`,{className:`text-xs text-foreground`,children:[e(`appUpdate.installed`),` `,(0,$.jsx)(`span`,{className:`font-semibold tabular-nums`,children:r??`—`})]}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground/70 truncate`,children:s===`update-available`&&l?e(`appUpdate.updateAvailable`,{version:l}):e(s===`up-to-date`?`appUpdate.upToDate`:`appUpdate.autoHint`)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void d(),disabled:a,className:`inline-flex h-7 shrink-0 items-center gap-1.5 rounded-lg border border-border bg-background px-3 text-[11px] font-medium text-muted-foreground hover:text-foreground disabled:opacity-50`,children:[a?(0,$.jsx)(An,{className:`h-3.5 w-3.5 animate-spin`}):s===`up-to-date`?(0,$.jsx)($o,{className:`h-3.5 w-3.5 text-accent-success`}):(0,$.jsx)(mc,{className:`h-3.5 w-3.5`}),e(a?`appUpdate.checking`:`appUpdate.check`)]})]})}):(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e(`appUpdate.unavailable`)})})]})}var tq=Object.defineProperty,nq=Object.getOwnPropertySymbols,rq=Object.prototype.hasOwnProperty,iq=Object.prototype.propertyIsEnumerable,aq=(e,t,n)=>t in e?tq(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,oq=(e,t)=>{for(var n in t||={})rq.call(t,n)&&aq(e,n,t[n]);if(nq)for(var n of nq(t))iq.call(t,n)&&aq(e,n,t[n]);return e},sq=(e,t)=>{var n={};for(var r in e)rq.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&nq)for(var r of nq(e))t.indexOf(r)<0&&iq.call(e,r)&&(n[r]=e[r]);return n},cq;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e<this.size;e++)o.push(!1);for(let e=0;e<this.size;e++)this.modules.push(o.slice()),this.isFunction.push(o.slice());this.drawFunctionPatterns();let s=this.addEccAndInterleave(r);if(this.drawCodewords(s),a==-1){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);let n=this.getPenaltyScore();n<e&&(a=t,e=n),this.applyMask(t)}}i(0<=a&&a<=7),this.mask=a,this.applyMask(a),this.drawFormatBits(a),this.isFunction=[]}static encodeText(n,r){let i=e.QrSegment.makeSegments(n);return t.encodeSegments(i,r)}static encodeBinary(n,r){let i=e.QrSegment.makeBytes(n);return t.encodeSegments([i],r)}static encodeSegments(e,r,a=1,s=40,c=-1,l=!0){if(!(t.MIN_VERSION<=a&&a<=s&&s<=t.MAX_VERSION)||c<-1||c>7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.length<p;e^=253)n(e,8,f);let m=[];for(;m.length*8<f.length;)m.push(0);return f.forEach((e,t)=>m[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e<this.size&&0<=t&&t<this.size&&this.modules[t][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let e=0;e<this.size;e++)this.setFunctionModule(6,e,e%2==0),this.setFunctionModule(e,6,e%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)n==0&&r==0||n==0&&r==t-1||n==t-1&&r==0||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){let t=this.errorCorrectionLevel.formatBits<<3|e,n=t;for(let e=0;e<10;e++)n=n<<1^(n>>>9)*1335;let a=(t<<10|n)^21522;i(a>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(t>>>18==0);for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a<this.size&&0<=o&&o<this.size&&this.setFunctionModule(a,o,i!=2&&i!=4)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,Math.max(Math.abs(r),Math.abs(n))!=1)}setFunctionModule(e,t,n){this.modules[t][e]=n,this.isFunction[t][e]=!0}addEccAndInterleave(e){let n=this.version,r=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(n,r))throw RangeError(`Invalid argument`);let a=t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][n],o=t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][n],s=Math.floor(t.getNumRawDataModules(n)/8),c=a-s%a,l=Math.floor(s/a),u=[],d=t.reedSolomonComputeDivisor(o);for(let n=0,r=0;n<a;n++){let i=e.slice(r,r+l-o+(n<c?0:1));r+=i.length;let a=t.reedSolomonComputeRemainder(i,d);n<c&&i.push(0),u.push(i.concat(a))}let f=[];for(let e=0;e<u[0].length;e++)u.forEach((t,n)=>{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i<this.size;i++)for(let a=0;a<2;a++){let o=t-a,s=t+1&2?i:this.size-1-i;!this.isFunction[s][o]&&n<e.length*8&&(this.modules[s][o]=r(e[n>>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw Error(`Unreachable`)}!this.isFunction[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[n][o]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[o][n]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size-1;n++)for(let r=0;r<this.size-1;r++){let i=this.modules[n][r];i==this.modules[n][r+1]&&i==this.modules[n+1][r]&&i==this.modules[n+1][r+1]&&(e+=t.PENALTY_N2)}let n=0;for(let e of this.modules)n=e.reduce((e,t)=>e+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}static getNumRawDataModules(e){if(e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t<e-1;t++)n.push(0);n.push(1);let r=1;for(let i=0;i<e;i++){for(let e=0;e<n.length;e++)n[e]=t.reedSolomonMultiply(n[e],r),e+1<n.length&&(n[e]^=n[e+1]);r=t.reedSolomonMultiply(r,2)}return n}static reedSolomonComputeRemainder(e,n){let r=n.map(e=>0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(n>>>8==0),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e<t.length;){let i=Math.min(t.length-e,3);n(parseInt(t.substring(e,e+i),10),i*3+1,r),e+=i}return new e(e.Mode.NUMERIC,t.length,r)}static makeAlphanumeric(t){if(!e.isAlphanumeric(t))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let r=[],i;for(i=0;i+2<=t.length;i+=2){let a=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i))*45;a+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i+1)),n(a,11,r)}return i<t.length&&n(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i)),6,r),new e(e.Mode.ALPHANUMERIC,t.length,r)}static makeSegments(t){return t==``?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]}static makeEci(t){let r=[];if(t<0)throw RangeError(`ECI assignment value out of range`);if(t<128)n(t,8,r);else if(t<16384)n(2,2,r),n(t,14,r);else if(t<1e6)n(6,3,r),n(t,21,r);else throw RangeError(`ECI assignment value out of range`);return new e(e.Mode.ECI,0,r)}static isNumeric(t){return e.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return e.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(e,t){let n=0;for(let r of e){let e=r.mode.numCharCountBits(t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}static toUtf8ByteArray(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)e.charAt(n)==`%`?(t.push(parseInt(e.substring(n+1,n+3),16)),n+=2):t.push(e.charCodeAt(n));return t}};a.NUMERIC_REGEX=/^[0-9]*$/,a.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,a.ALPHANUMERIC_CHARSET=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`;let o=a;e.QrSegment=a})(cq||={}),(e=>{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(cq||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(cq||={});var lq=cq,uq={L:lq.QrCode.Ecc.LOW,M:lq.QrCode.Ecc.MEDIUM,Q:lq.QrCode.Ecc.QUARTILE,H:lq.QrCode.Ecc.HIGH},dq=128,fq=`L`,pq=`#FFFFFF`,mq=`#000000`,hq=!1,gq=1,_q=4,vq=0,yq=.1;function bq(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function xq(e,t){return e.slice().map((e,n)=>n<t.y||n>=t.y+t.h?e:e.map((e,n)=>n<t.x||n>=t.x+t.w?e:!1))}function Sq(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*yq),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function Cq(e,t){return t==null?e?_q:vq:Math.max(Math.floor(t),0)}function wq({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=Q.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...lq.QrSegment.makeSegments(t)),e),[]);return lq.QrCode.encodeSegments(r,uq[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=Q.useMemo(()=>{let e=c.getModules(),t=Cq(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:Sq(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var Tq=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),Eq=Q.forwardRef(function(e,t){let n=e,{value:r,size:i=dq,level:a=fq,bgColor:o=pq,fgColor:s=mq,includeMargin:c=hq,minVersion:l=gq,boostLevel:u,marginSize:d,imageSettings:f}=n,p=sq(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=sq(p,[`style`]),g=f?.src,_=Q.useRef(null),v=Q.useRef(null),y=Q.useCallback(e=>{_.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[b,x]=Q.useState(!1),{margin:S,cells:C,numCells:w,calculatedImageSettings:T}=wq({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});Q.useEffect(()=>{if(_.current!=null){let e=_.current,t=e.getContext(`2d`);if(!t)return;let n=C,r=v.current,a=T!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&T.excavation!=null&&(n=xq(C,T.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/w*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,w,w),t.fillStyle=s,Tq?t.fill(new Path2D(bq(n,S))):C.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+S,n+S,1,1)})}),T&&(t.globalAlpha=T.opacity),a&&t.drawImage(r,T.x+S,T.y+S,T.w,T.h)}}),Q.useEffect(()=>{x(!1)},[g]);let E=oq({height:i,width:i},m),D=null;return g!=null&&(D=Q.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{x(!0)},ref:v,crossOrigin:T?.crossOrigin})),Q.createElement(Q.Fragment,null,Q.createElement(`canvas`,oq({style:E,height:i,width:i,ref:y,role:`img`},h)),D)});Eq.displayName=`QRCodeCanvas`;var Dq=Q.forwardRef(function(e,t){let n=e,{value:r,size:i=dq,level:a=fq,bgColor:o=pq,fgColor:s=mq,includeMargin:c=hq,minVersion:l=gq,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=sq(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=wq({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),y=g,b=null;p!=null&&v!=null&&(v.excavation!=null&&(y=xq(g,v.excavation)),b=Q.createElement(`image`,{href:p.src,height:v.h,width:v.w,x:v.x+h,y:v.y+h,preserveAspectRatio:`none`,opacity:v.opacity,crossOrigin:v.crossOrigin}));let x=bq(y,h);return Q.createElement(`svg`,oq({height:i,width:i,viewBox:`0 0 ${_} ${_}`,ref:t,role:`img`},m),!!d&&Q.createElement(`title`,null,d),Q.createElement(`path`,{fill:o,d:`M0,0 h${_}v${_}H0z`,shapeRendering:`crispEdges`}),Q.createElement(`path`,{fill:s,d:x,shapeRendering:`crispEdges`}),b)});Dq.displayName=`QRCodeSVG`;var Oq=e(i(((e,t)=>{(function(n,r){typeof e==`object`&&typeof t==`object`?t.exports=r():typeof define==`function`&&define.amd?define([],r):typeof e==`object`?e.jsQR=r():n.jsQR=r()})(typeof self<`u`?self:e,function(){return(function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,`a`,t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=``,n(n.s=3)})([(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.BitMatrix=function(){function e(e,t){this.width=t,this.height=e.length/t,this.data=e}return e.createEmpty=function(t,n){return new e(new Uint8ClampedArray(t*n),t)},e.prototype.get=function(e,t){return e<0||e>=this.width||t<0||t>=this.height?!1:!!this.data[t*this.width+e]},e.prototype.set=function(e,t,n){this.data[t*this.width+e]=+!!n},e.prototype.setRegion=function(e,t,n,r,i){for(var a=t;a<t+r;a++)for(var o=e;o<e+n;o++)this.set(o,a,!!i)},e}()}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);function i(e,t){return e^t}t.addOrSubtractGF=i,t.default=function(){function e(e,t,n){this.primitive=e,this.size=t,this.generatorBase=n,this.expTable=Array(this.size),this.logTable=Array(this.size);for(var i=1,a=0;a<this.size;a++)this.expTable[a]=i,i*=2,i>=this.size&&(i=(i^this.primitive)&this.size-1);for(var a=0;a<this.size-1;a++)this.logTable[this.expTable[a]]=a;this.zero=new r.default(this,Uint8ClampedArray.from([0])),this.one=new r.default(this,Uint8ClampedArray.from([1]))}return e.prototype.multiply=function(e,t){return e===0||t===0?0:this.expTable[(this.logTable[e]+this.logTable[t])%(this.size-1)]},e.prototype.inverse=function(e){if(e===0)throw Error(`Can't invert 0`);return this.expTable[this.size-this.logTable[e]-1]},e.prototype.buildMonomial=function(e,t){if(e<0)throw Error(`Invalid monomial degree less than 0`);if(t===0)return this.zero;var n=new Uint8ClampedArray(e+1);return n[0]=t,new r.default(this,n)},e.prototype.log=function(e){if(e===0)throw Error(`Can't take log(0)`);return this.logTable[e]},e.prototype.exp=function(e){return this.expTable[e]},e}()}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(1);t.default=function(){function e(e,t){if(t.length===0)throw Error(`No coefficients.`);this.field=e;var n=t.length;if(n>1&&t[0]===0){for(var r=1;r<n&&t[r]===0;)r++;if(r===n)this.coefficients=e.zero.coefficients;else{this.coefficients=new Uint8ClampedArray(n-r);for(var i=0;i<this.coefficients.length;i++)this.coefficients[i]=t[r+i]}}else this.coefficients=t}return e.prototype.degree=function(){return this.coefficients.length-1},e.prototype.isZero=function(){return this.coefficients[0]===0},e.prototype.getCoefficient=function(e){return this.coefficients[this.coefficients.length-1-e]},e.prototype.addOrSubtract=function(t){var n;if(this.isZero())return t;if(t.isZero())return this;var i=this.coefficients,a=t.coefficients;i.length>a.length&&(n=[a,i],i=n[0],a=n[1]);for(var o=new Uint8ClampedArray(a.length),s=a.length-i.length,c=0;c<s;c++)o[c]=a[c];for(var c=s;c<a.length;c++)o[c]=r.addOrSubtractGF(i[c-s],a[c]);return new e(this.field,o)},e.prototype.multiply=function(t){if(t===0)return this.field.zero;if(t===1)return this;for(var n=this.coefficients.length,r=new Uint8ClampedArray(n),i=0;i<n;i++)r[i]=this.field.multiply(this.coefficients[i],t);return new e(this.field,r)},e.prototype.multiplyPoly=function(t){if(this.isZero()||t.isZero())return this.field.zero;for(var n=this.coefficients,i=n.length,a=t.coefficients,o=a.length,s=new Uint8ClampedArray(i+o-1),c=0;c<i;c++)for(var l=n[c],u=0;u<o;u++)s[c+u]=r.addOrSubtractGF(s[c+u],this.field.multiply(l,a[u]));return new e(this.field,s)},e.prototype.multiplyByMonomial=function(t,n){if(t<0)throw Error(`Invalid degree less than 0`);if(n===0)return this.field.zero;for(var r=this.coefficients.length,i=new Uint8ClampedArray(r+t),a=0;a<r;a++)i[a]=this.field.multiply(this.coefficients[a],n);return new e(this.field,i)},e.prototype.evaluateAt=function(e){var t=0;if(e===0)return this.getCoefficient(0);var n=this.coefficients.length;if(e===1)return this.coefficients.forEach(function(e){t=r.addOrSubtractGF(t,e)}),t;t=this.coefficients[0];for(var i=1;i<n;i++)t=r.addOrSubtractGF(this.field.multiply(e,t),this.coefficients[i]);return t},e}()}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(4),i=n(5),a=n(11),o=n(12);function s(e){var t=o.locate(e);if(!t)return null;for(var n=0,r=t;n<r.length;n++){var s=r[n],c=a.extract(e,s),l=i.decode(c.matrix);if(l)return{binaryData:l.bytes,data:l.text,chunks:l.chunks,version:l.version,location:{topRightCorner:c.mappingFunction(s.dimension,0),topLeftCorner:c.mappingFunction(0,0),bottomRightCorner:c.mappingFunction(s.dimension,s.dimension),bottomLeftCorner:c.mappingFunction(0,s.dimension),topRightFinderPattern:s.topRight,topLeftFinderPattern:s.topLeft,bottomLeftFinderPattern:s.bottomLeft,bottomRightAlignmentPattern:s.alignmentPattern}}}return null}var c={inversionAttempts:`attemptBoth`};function l(e,t,n,i){i===void 0&&(i={});var a=c;Object.keys(a||{}).forEach(function(e){a[e]=i[e]||a[e]});var o=a.inversionAttempts===`attemptBoth`||a.inversionAttempts===`invertFirst`,l=a.inversionAttempts===`onlyInvert`||a.inversionAttempts===`invertFirst`,u=r.binarize(e,t,n,o),d=u.binarized,f=u.inverted,p=s(l?f:d);return!p&&(a.inversionAttempts===`attemptBoth`||a.inversionAttempts===`invertFirst`)&&(p=s(l?d:f)),p}l.default=l,t.default=l}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(0),i=8,a=24;function o(e,t,n){return e<t?t:e>n?n:e}var s=function(){function e(e,t){this.width=e,this.data=new Uint8ClampedArray(e*t)}return e.prototype.get=function(e,t){return this.data[t*this.width+e]},e.prototype.set=function(e,t,n){this.data[t*this.width+e]=n},e}();function c(e,t,n,c){if(e.length!==t*n*4)throw Error(`Malformed data passed to binarizer.`);for(var l=new s(t,n),u=0;u<t;u++)for(var d=0;d<n;d++){var f=e[(d*t+u)*4+0],p=e[(d*t+u)*4+1],m=e[(d*t+u)*4+2];l.set(u,d,.2126*f+.7152*p+.0722*m)}for(var h=Math.ceil(t/i),g=Math.ceil(n/i),_=new s(h,g),v=0;v<g;v++)for(var y=0;y<h;y++){for(var b=0,x=1/0,S=0,d=0;d<i;d++)for(var u=0;u<i;u++){var C=l.get(y*i+u,v*i+d);b+=C,x=Math.min(x,C),S=Math.max(S,C)}var w=b/i**2;if(S-x<=a&&(w=x/2,v>0&&y>0)){var T=(_.get(y,v-1)+2*_.get(y-1,v)+_.get(y-1,v-1))/4;x<T&&(w=T)}_.set(y,v,w)}var E=r.BitMatrix.createEmpty(t,n),D=null;c&&(D=r.BitMatrix.createEmpty(t,n));for(var v=0;v<g;v++)for(var y=0;y<h;y++){for(var O=o(y,2,h-3),k=o(v,2,g-3),b=0,A=-2;A<=2;A++)for(var j=-2;j<=2;j++)b+=_.get(O+A,k+j);for(var M=b/25,A=0;A<i;A++)for(var j=0;j<i;j++){var u=y*i+A,d=v*i+j,N=l.get(u,d);E.set(u,d,N<=M),c&&D.set(u,d,!(N<=M))}}return c?{binarized:E,inverted:D}:{binarized:E}}t.binarize=c}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(0),i=n(6),a=n(9),o=n(10);function s(e,t){for(var n=e^t,r=0;n;)r++,n&=n-1;return r}function c(e,t){return t<<1|e}var l=[{bits:21522,formatInfo:{errorCorrectionLevel:1,dataMask:0}},{bits:20773,formatInfo:{errorCorrectionLevel:1,dataMask:1}},{bits:24188,formatInfo:{errorCorrectionLevel:1,dataMask:2}},{bits:23371,formatInfo:{errorCorrectionLevel:1,dataMask:3}},{bits:17913,formatInfo:{errorCorrectionLevel:1,dataMask:4}},{bits:16590,formatInfo:{errorCorrectionLevel:1,dataMask:5}},{bits:20375,formatInfo:{errorCorrectionLevel:1,dataMask:6}},{bits:19104,formatInfo:{errorCorrectionLevel:1,dataMask:7}},{bits:30660,formatInfo:{errorCorrectionLevel:0,dataMask:0}},{bits:29427,formatInfo:{errorCorrectionLevel:0,dataMask:1}},{bits:32170,formatInfo:{errorCorrectionLevel:0,dataMask:2}},{bits:30877,formatInfo:{errorCorrectionLevel:0,dataMask:3}},{bits:26159,formatInfo:{errorCorrectionLevel:0,dataMask:4}},{bits:25368,formatInfo:{errorCorrectionLevel:0,dataMask:5}},{bits:27713,formatInfo:{errorCorrectionLevel:0,dataMask:6}},{bits:26998,formatInfo:{errorCorrectionLevel:0,dataMask:7}},{bits:5769,formatInfo:{errorCorrectionLevel:3,dataMask:0}},{bits:5054,formatInfo:{errorCorrectionLevel:3,dataMask:1}},{bits:7399,formatInfo:{errorCorrectionLevel:3,dataMask:2}},{bits:6608,formatInfo:{errorCorrectionLevel:3,dataMask:3}},{bits:1890,formatInfo:{errorCorrectionLevel:3,dataMask:4}},{bits:597,formatInfo:{errorCorrectionLevel:3,dataMask:5}},{bits:3340,formatInfo:{errorCorrectionLevel:3,dataMask:6}},{bits:2107,formatInfo:{errorCorrectionLevel:3,dataMask:7}},{bits:13663,formatInfo:{errorCorrectionLevel:2,dataMask:0}},{bits:12392,formatInfo:{errorCorrectionLevel:2,dataMask:1}},{bits:16177,formatInfo:{errorCorrectionLevel:2,dataMask:2}},{bits:14854,formatInfo:{errorCorrectionLevel:2,dataMask:3}},{bits:9396,formatInfo:{errorCorrectionLevel:2,dataMask:4}},{bits:8579,formatInfo:{errorCorrectionLevel:2,dataMask:5}},{bits:11994,formatInfo:{errorCorrectionLevel:2,dataMask:6}},{bits:11245,formatInfo:{errorCorrectionLevel:2,dataMask:7}}],u=[function(e){return(e.y+e.x)%2==0},function(e){return e.y%2==0},function(e){return e.x%3==0},function(e){return(e.y+e.x)%3==0},function(e){return(Math.floor(e.y/2)+Math.floor(e.x/3))%2==0},function(e){return e.x*e.y%2+e.x*e.y%3==0},function(e){return(e.y*e.x%2+e.y*e.x%3)%2==0},function(e){return((e.y+e.x)%2+e.y*e.x%3)%2==0}];function d(e){var t=17+4*e.versionNumber,n=r.BitMatrix.createEmpty(t,t);n.setRegion(0,0,9,9,!0),n.setRegion(t-8,0,8,9,!0),n.setRegion(0,t-8,9,8,!0);for(var i=0,a=e.alignmentPatternCenters;i<a.length;i++)for(var o=a[i],s=0,c=e.alignmentPatternCenters;s<c.length;s++){var l=c[s];o===6&&l===6||o===6&&l===t-7||o===t-7&&l===6||n.setRegion(o-2,l-2,5,5,!0)}return n.setRegion(6,9,1,t-17,!0),n.setRegion(9,6,t-17,1,!0),e.versionNumber>6&&(n.setRegion(t-11,0,3,6,!0),n.setRegion(0,t-11,6,3,!0)),n}function f(e,t,n){for(var r=u[n.dataMask],i=e.height,a=d(t),o=[],s=0,l=0,f=!0,p=i-1;p>0;p-=2){p===6&&p--;for(var m=0;m<i;m++)for(var h=f?i-1-m:m,g=0;g<2;g++){var _=p-g;if(!a.get(_,h)){l++;var v=e.get(_,h);r({y:h,x:_})&&(v=!v),s=c(v,s),l===8&&(o.push(s),l=0,s=0)}}f=!f}return o}function p(e){var t=e.height,n=Math.floor((t-17)/4);if(n<=6)return o.VERSIONS[n-1];for(var r=0,i=5;i>=0;i--)for(var a=t-9;a>=t-11;a--)r=c(e.get(a,i),r);for(var l=0,a=5;a>=0;a--)for(var i=t-9;i>=t-11;i--)l=c(e.get(a,i),l);for(var u=1/0,d,f=0,p=o.VERSIONS;f<p.length;f++){var m=p[f];if(m.infoBits===r||m.infoBits===l)return m;var h=s(r,m.infoBits);h<u&&(d=m,u=h),h=s(l,m.infoBits),h<u&&(d=m,u=h)}if(u<=3)return d}function m(e){for(var t=0,n=0;n<=8;n++)n!==6&&(t=c(e.get(n,8),t));for(var r=7;r>=0;r--)r!==6&&(t=c(e.get(8,r),t));for(var i=e.height,a=0,r=i-1;r>=i-7;r--)a=c(e.get(8,r),a);for(var n=i-8;n<i;n++)a=c(e.get(n,8),a);for(var o=1/0,u=null,d=0,f=l;d<f.length;d++){var p=f[d],m=p.bits,h=p.formatInfo;if(m===t||m===a)return h;var g=s(t,m);g<o&&(u=h,o=g),t!==a&&(g=s(a,m),g<o&&(u=h,o=g))}return o<=3?u:null}function h(e,t,n){var r=t.errorCorrectionLevels[n],i=[],a=0;if(r.ecBlocks.forEach(function(e){for(var t=0;t<e.numBlocks;t++)i.push({numDataCodewords:e.dataCodewordsPerBlock,codewords:[]}),a+=e.dataCodewordsPerBlock+r.ecCodewordsPerBlock}),e.length<a)return null;e=e.slice(0,a);for(var o=r.ecBlocks[0].dataCodewordsPerBlock,s=0;s<o;s++)for(var c=0,l=i;c<l.length;c++){var u=l[c];u.codewords.push(e.shift())}if(r.ecBlocks.length>1)for(var d=r.ecBlocks[0].numBlocks,f=r.ecBlocks[1].numBlocks,s=0;s<f;s++)i[d+s].codewords.push(e.shift());for(;e.length>0;)for(var p=0,m=i;p<m.length;p++){var u=m[p];u.codewords.push(e.shift())}return i}function g(e){var t=p(e);if(!t)return null;var n=m(e);if(!n)return null;var r=h(f(e,t,n),t,n.errorCorrectionLevel);if(!r)return null;for(var o=r.reduce(function(e,t){return e+t.numDataCodewords},0),s=new Uint8ClampedArray(o),c=0,l=0,u=r;l<u.length;l++){var d=u[l],g=a.decode(d.codewords,d.codewords.length-d.numDataCodewords);if(!g)return null;for(var _=0;_<d.numDataCodewords;_++)s[c++]=g[_]}try{return i.decode(s,t.versionNumber)}catch{return null}}function _(e){if(e==null)return null;var t=g(e);if(t)return t;for(var n=0;n<e.width;n++)for(var r=n+1;r<e.height;r++)e.get(n,r)!==e.get(r,n)&&(e.set(n,r,!e.get(n,r)),e.set(r,n,!e.get(r,n)));return g(e)}t.decode=_}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(7),i=n(8),a;(function(e){e.Numeric=`numeric`,e.Alphanumeric=`alphanumeric`,e.Byte=`byte`,e.Kanji=`kanji`,e.ECI=`eci`})(a=t.Mode||={});var o;(function(e){e[e.Terminator=0]=`Terminator`,e[e.Numeric=1]=`Numeric`,e[e.Alphanumeric=2]=`Alphanumeric`,e[e.Byte=4]=`Byte`,e[e.Kanji=8]=`Kanji`,e[e.ECI=7]=`ECI`})(o||={});function s(e,t){for(var n=[],r=``,i=[10,12,14][t],a=e.readBits(i);a>=3;){var o=e.readBits(10);if(o>=1e3)throw Error(`Invalid numeric value above 999`);var s=Math.floor(o/100),c=Math.floor(o/10)%10,l=o%10;n.push(48+s,48+c,48+l),r+=s.toString()+c.toString()+l.toString(),a-=3}if(a===2){var o=e.readBits(7);if(o>=100)throw Error(`Invalid numeric value above 99`);var s=Math.floor(o/10),c=o%10;n.push(48+s,48+c),r+=s.toString()+c.toString()}else if(a===1){var o=e.readBits(4);if(o>=10)throw Error(`Invalid numeric value above 9`);n.push(48+o),r+=o.toString()}return{bytes:n,text:r}}var c=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`.split(``);function l(e,t){for(var n=[],r=``,i=[9,11,13][t],a=e.readBits(i);a>=2;){var o=e.readBits(11),s=Math.floor(o/45),l=o%45;n.push(c[s].charCodeAt(0),c[l].charCodeAt(0)),r+=c[s]+c[l],a-=2}if(a===1){var s=e.readBits(6);n.push(c[s].charCodeAt(0)),r+=c[s]}return{bytes:n,text:r}}function u(e,t){for(var n=[],r=``,i=[8,16,16][t],a=e.readBits(i),o=0;o<a;o++){var s=e.readBits(8);n.push(s)}try{r+=decodeURIComponent(n.map(function(e){return`%`+(`0`+e.toString(16)).substr(-2)}).join(``))}catch{}return{bytes:n,text:r}}function d(e,t){for(var n=[],r=``,a=[8,10,12][t],o=e.readBits(a),s=0;s<o;s++){var c=e.readBits(13),l=Math.floor(c/192)<<8|c%192;l<7936?l+=33088:l+=49472,n.push(l>>8,l&255),r+=String.fromCharCode(i.shiftJISTable[l])}return{bytes:n,text:r}}function f(e,t){for(var n,i,c,f,p=new r.BitStream(e),m=t<=9?0:t<=26?1:2,h={text:``,bytes:[],chunks:[],version:t};p.available()>=4;){var g=p.readBits(4);if(g===o.Terminator)return h;if(g===o.ECI)p.readBits(1)===0?h.chunks.push({type:a.ECI,assignmentNumber:p.readBits(7)}):p.readBits(1)===0?h.chunks.push({type:a.ECI,assignmentNumber:p.readBits(14)}):p.readBits(1)===0?h.chunks.push({type:a.ECI,assignmentNumber:p.readBits(21)}):h.chunks.push({type:a.ECI,assignmentNumber:-1});else if(g===o.Numeric){var _=s(p,m);h.text+=_.text,(n=h.bytes).push.apply(n,_.bytes),h.chunks.push({type:a.Numeric,text:_.text})}else if(g===o.Alphanumeric){var v=l(p,m);h.text+=v.text,(i=h.bytes).push.apply(i,v.bytes),h.chunks.push({type:a.Alphanumeric,text:v.text})}else if(g===o.Byte){var y=u(p,m);h.text+=y.text,(c=h.bytes).push.apply(c,y.bytes),h.chunks.push({type:a.Byte,bytes:y.bytes,text:y.text})}else if(g===o.Kanji){var b=d(p,m);h.text+=b.text,(f=h.bytes).push.apply(f,b.bytes),h.chunks.push({type:a.Kanji,bytes:b.bytes,text:b.text})}}if(p.available()===0||p.readBits(p.available())===0)return h}t.decode=f}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.BitStream=function(){function e(e){this.byteOffset=0,this.bitOffset=0,this.bytes=e}return e.prototype.readBits=function(e){if(e<1||e>32||e>this.available())throw Error(`Cannot read `+e.toString()+` bits`);var t=0;if(this.bitOffset>0){var n=8-this.bitOffset,r=e<n?e:n,i=n-r,a=255>>8-r<<i;t=(this.bytes[this.byteOffset]&a)>>i,e-=r,this.bitOffset+=r,this.bitOffset===8&&(this.bitOffset=0,this.byteOffset++)}if(e>0){for(;e>=8;)t=t<<8|this.bytes[this.byteOffset]&255,this.byteOffset++,e-=8;if(e>0){var i=8-e,a=255>>i<<i;t=t<<e|(this.bytes[this.byteOffset]&a)>>i,this.bitOffset+=e}}return t},e.prototype.available=function(){return 8*(this.bytes.length-this.byteOffset)-this.bitOffset},e}()}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.shiftJISTable={32:32,33:33,34:34,35:35,36:36,37:37,38:38,39:39,40:40,41:41,42:42,43:43,44:44,45:45,46:46,47:47,48:48,49:49,50:50,51:51,52:52,53:53,54:54,55:55,56:56,57:57,58:58,59:59,60:60,61:61,62:62,63:63,64:64,65:65,66:66,67:67,68:68,69:69,70:70,71:71,72:72,73:73,74:74,75:75,76:76,77:77,78:78,79:79,80:80,81:81,82:82,83:83,84:84,85:85,86:86,87:87,88:88,89:89,90:90,91:91,92:165,93:93,94:94,95:95,96:96,97:97,98:98,99:99,100:100,101:101,102:102,103:103,104:104,105:105,106:106,107:107,108:108,109:109,110:110,111:111,112:112,113:113,114:114,115:115,116:116,117:117,118:118,119:119,120:120,121:121,122:122,123:123,124:124,125:125,126:8254,33088:12288,33089:12289,33090:12290,33091:65292,33092:65294,33093:12539,33094:65306,33095:65307,33096:65311,33097:65281,33098:12443,33099:12444,33100:180,33101:65344,33102:168,33103:65342,33104:65507,33105:65343,33106:12541,33107:12542,33108:12445,33109:12446,33110:12291,33111:20189,33112:12293,33113:12294,33114:12295,33115:12540,33116:8213,33117:8208,33118:65295,33119:92,33120:12316,33121:8214,33122:65372,33123:8230,33124:8229,33125:8216,33126:8217,33127:8220,33128:8221,33129:65288,33130:65289,33131:12308,33132:12309,33133:65339,33134:65341,33135:65371,33136:65373,33137:12296,33138:12297,33139:12298,33140:12299,33141:12300,33142:12301,33143:12302,33144:12303,33145:12304,33146:12305,33147:65291,33148:8722,33149:177,33150:215,33152:247,33153:65309,33154:8800,33155:65308,33156:65310,33157:8806,33158:8807,33159:8734,33160:8756,33161:9794,33162:9792,33163:176,33164:8242,33165:8243,33166:8451,33167:65509,33168:65284,33169:162,33170:163,33171:65285,33172:65283,33173:65286,33174:65290,33175:65312,33176:167,33177:9734,33178:9733,33179:9675,33180:9679,33181:9678,33182:9671,33183:9670,33184:9633,33185:9632,33186:9651,33187:9650,33188:9661,33189:9660,33190:8251,33191:12306,33192:8594,33193:8592,33194:8593,33195:8595,33196:12307,33208:8712,33209:8715,33210:8838,33211:8839,33212:8834,33213:8835,33214:8746,33215:8745,33224:8743,33225:8744,33226:172,33227:8658,33228:8660,33229:8704,33230:8707,33242:8736,33243:8869,33244:8978,33245:8706,33246:8711,33247:8801,33248:8786,33249:8810,33250:8811,33251:8730,33252:8765,33253:8733,33254:8757,33255:8747,33256:8748,33264:8491,33265:8240,33266:9839,33267:9837,33268:9834,33269:8224,33270:8225,33271:182,33276:9711,33359:65296,33360:65297,33361:65298,33362:65299,33363:65300,33364:65301,33365:65302,33366:65303,33367:65304,33368:65305,33376:65313,33377:65314,33378:65315,33379:65316,33380:65317,33381:65318,33382:65319,33383:65320,33384:65321,33385:65322,33386:65323,33387:65324,33388:65325,33389:65326,33390:65327,33391:65328,33392:65329,33393:65330,33394:65331,33395:65332,33396:65333,33397:65334,33398:65335,33399:65336,33400:65337,33401:65338,33409:65345,33410:65346,33411:65347,33412:65348,33413:65349,33414:65350,33415:65351,33416:65352,33417:65353,33418:65354,33419:65355,33420:65356,33421:65357,33422:65358,33423:65359,33424:65360,33425:65361,33426:65362,33427:65363,33428:65364,33429:65365,33430:65366,33431:65367,33432:65368,33433:65369,33434:65370,33439:12353,33440:12354,33441:12355,33442:12356,33443:12357,33444:12358,33445:12359,33446:12360,33447:12361,33448:12362,33449:12363,33450:12364,33451:12365,33452:12366,33453:12367,33454:12368,33455:12369,33456:12370,33457:12371,33458:12372,33459:12373,33460:12374,33461:12375,33462:12376,33463:12377,33464:12378,33465:12379,33466:12380,33467:12381,33468:12382,33469:12383,33470:12384,33471:12385,33472:12386,33473:12387,33474:12388,33475:12389,33476:12390,33477:12391,33478:12392,33479:12393,33480:12394,33481:12395,33482:12396,33483:12397,33484:12398,33485:12399,33486:12400,33487:12401,33488:12402,33489:12403,33490:12404,33491:12405,33492:12406,33493:12407,33494:12408,33495:12409,33496:12410,33497:12411,33498:12412,33499:12413,33500:12414,33501:12415,33502:12416,33503:12417,33504:12418,33505:12419,33506:12420,33507:12421,33508:12422,33509:12423,33510:12424,33511:12425,33512:12426,33513:12427,33514:12428,33515:12429,33516:12430,33517:12431,33518:12432,33519:12433,33520:12434,33521:12435,33600:12449,33601:12450,33602:12451,33603:12452,33604:12453,33605:12454,33606:12455,33607:12456,33608:12457,33609:12458,33610:12459,33611:12460,33612:12461,33613:12462,33614:12463,33615:12464,33616:12465,33617:12466,33618:12467,33619:12468,33620:12469,33621:12470,33622:12471,33623:12472,33624:12473,33625:12474,33626:12475,33627:12476,33628:12477,33629:12478,33630:12479,33631:12480,33632:12481,33633:12482,33634:12483,33635:12484,33636:12485,33637:12486,33638:12487,33639:12488,33640:12489,33641:12490,33642:12491,33643:12492,33644:12493,33645:12494,33646:12495,33647:12496,33648:12497,33649:12498,33650:12499,33651:12500,33652:12501,33653:12502,33654:12503,33655:12504,33656:12505,33657:12506,33658:12507,33659:12508,33660:12509,33661:12510,33662:12511,33664:12512,33665:12513,33666:12514,33667:12515,33668:12516,33669:12517,33670:12518,33671:12519,33672:12520,33673:12521,33674:12522,33675:12523,33676:12524,33677:12525,33678:12526,33679:12527,33680:12528,33681:12529,33682:12530,33683:12531,33684:12532,33685:12533,33686:12534,33695:913,33696:914,33697:915,33698:916,33699:917,33700:918,33701:919,33702:920,33703:921,33704:922,33705:923,33706:924,33707:925,33708:926,33709:927,33710:928,33711:929,33712:931,33713:932,33714:933,33715:934,33716:935,33717:936,33718:937,33727:945,33728:946,33729:947,33730:948,33731:949,33732:950,33733:951,33734:952,33735:953,33736:954,33737:955,33738:956,33739:957,33740:958,33741:959,33742:960,33743:961,33744:963,33745:964,33746:965,33747:966,33748:967,33749:968,33750:969,33856:1040,33857:1041,33858:1042,33859:1043,33860:1044,33861:1045,33862:1025,33863:1046,33864:1047,33865:1048,33866:1049,33867:1050,33868:1051,33869:1052,33870:1053,33871:1054,33872:1055,33873:1056,33874:1057,33875:1058,33876:1059,33877:1060,33878:1061,33879:1062,33880:1063,33881:1064,33882:1065,33883:1066,33884:1067,33885:1068,33886:1069,33887:1070,33888:1071,33904:1072,33905:1073,33906:1074,33907:1075,33908:1076,33909:1077,33910:1105,33911:1078,33912:1079,33913:1080,33914:1081,33915:1082,33916:1083,33917:1084,33918:1085,33920:1086,33921:1087,33922:1088,33923:1089,33924:1090,33925:1091,33926:1092,33927:1093,33928:1094,33929:1095,33930:1096,33931:1097,33932:1098,33933:1099,33934:1100,33935:1101,33936:1102,33937:1103,33951:9472,33952:9474,33953:9484,33954:9488,33955:9496,33956:9492,33957:9500,33958:9516,33959:9508,33960:9524,33961:9532,33962:9473,33963:9475,33964:9487,33965:9491,33966:9499,33967:9495,33968:9507,33969:9523,33970:9515,33971:9531,33972:9547,33973:9504,33974:9519,33975:9512,33976:9527,33977:9535,33978:9501,33979:9520,33980:9509,33981:9528,33982:9538,34975:20124,34976:21782,34977:23043,34978:38463,34979:21696,34980:24859,34981:25384,34982:23030,34983:36898,34984:33909,34985:33564,34986:31312,34987:24746,34988:25569,34989:28197,34990:26093,34991:33894,34992:33446,34993:39925,34994:26771,34995:22311,34996:26017,34997:25201,34998:23451,34999:22992,35e3:34427,35001:39156,35002:32098,35003:32190,35004:39822,35005:25110,35006:31903,35007:34999,35008:23433,35009:24245,35010:25353,35011:26263,35012:26696,35013:38343,35014:38797,35015:26447,35016:20197,35017:20234,35018:20301,35019:20381,35020:20553,35021:22258,35022:22839,35023:22996,35024:23041,35025:23561,35026:24799,35027:24847,35028:24944,35029:26131,35030:26885,35031:28858,35032:30031,35033:30064,35034:31227,35035:32173,35036:32239,35037:32963,35038:33806,35039:34915,35040:35586,35041:36949,35042:36986,35043:21307,35044:20117,35045:20133,35046:22495,35047:32946,35048:37057,35049:30959,35050:19968,35051:22769,35052:28322,35053:36920,35054:31282,35055:33576,35056:33419,35057:39983,35058:20801,35059:21360,35060:21693,35061:21729,35062:22240,35063:23035,35064:24341,35065:39154,35066:28139,35067:32996,35068:34093,35136:38498,35137:38512,35138:38560,35139:38907,35140:21515,35141:21491,35142:23431,35143:28879,35144:32701,35145:36802,35146:38632,35147:21359,35148:40284,35149:31418,35150:19985,35151:30867,35152:33276,35153:28198,35154:22040,35155:21764,35156:27421,35157:34074,35158:39995,35159:23013,35160:21417,35161:28006,35162:29916,35163:38287,35164:22082,35165:20113,35166:36939,35167:38642,35168:33615,35169:39180,35170:21473,35171:21942,35172:23344,35173:24433,35174:26144,35175:26355,35176:26628,35177:27704,35178:27891,35179:27945,35180:29787,35181:30408,35182:31310,35183:38964,35184:33521,35185:34907,35186:35424,35187:37613,35188:28082,35189:30123,35190:30410,35191:39365,35192:24742,35193:35585,35194:36234,35195:38322,35196:27022,35197:21421,35198:20870,35200:22290,35201:22576,35202:22852,35203:23476,35204:24310,35205:24616,35206:25513,35207:25588,35208:27839,35209:28436,35210:28814,35211:28948,35212:29017,35213:29141,35214:29503,35215:32257,35216:33398,35217:33489,35218:34199,35219:36960,35220:37467,35221:40219,35222:22633,35223:26044,35224:27738,35225:29989,35226:20985,35227:22830,35228:22885,35229:24448,35230:24540,35231:25276,35232:26106,35233:27178,35234:27431,35235:27572,35236:29579,35237:32705,35238:35158,35239:40236,35240:40206,35241:40644,35242:23713,35243:27798,35244:33659,35245:20740,35246:23627,35247:25014,35248:33222,35249:26742,35250:29281,35251:20057,35252:20474,35253:21368,35254:24681,35255:28201,35256:31311,35257:38899,35258:19979,35259:21270,35260:20206,35261:20309,35262:20285,35263:20385,35264:20339,35265:21152,35266:21487,35267:22025,35268:22799,35269:23233,35270:23478,35271:23521,35272:31185,35273:26247,35274:26524,35275:26550,35276:27468,35277:27827,35278:28779,35279:29634,35280:31117,35281:31166,35282:31292,35283:31623,35284:33457,35285:33499,35286:33540,35287:33655,35288:33775,35289:33747,35290:34662,35291:35506,35292:22057,35293:36008,35294:36838,35295:36942,35296:38686,35297:34442,35298:20420,35299:23784,35300:25105,35301:29273,35302:30011,35303:33253,35304:33469,35305:34558,35306:36032,35307:38597,35308:39187,35309:39381,35310:20171,35311:20250,35312:35299,35313:22238,35314:22602,35315:22730,35316:24315,35317:24555,35318:24618,35319:24724,35320:24674,35321:25040,35322:25106,35323:25296,35324:25913,35392:39745,35393:26214,35394:26800,35395:28023,35396:28784,35397:30028,35398:30342,35399:32117,35400:33445,35401:34809,35402:38283,35403:38542,35404:35997,35405:20977,35406:21182,35407:22806,35408:21683,35409:23475,35410:23830,35411:24936,35412:27010,35413:28079,35414:30861,35415:33995,35416:34903,35417:35442,35418:37799,35419:39608,35420:28012,35421:39336,35422:34521,35423:22435,35424:26623,35425:34510,35426:37390,35427:21123,35428:22151,35429:21508,35430:24275,35431:25313,35432:25785,35433:26684,35434:26680,35435:27579,35436:29554,35437:30906,35438:31339,35439:35226,35440:35282,35441:36203,35442:36611,35443:37101,35444:38307,35445:38548,35446:38761,35447:23398,35448:23731,35449:27005,35450:38989,35451:38990,35452:25499,35453:31520,35454:27179,35456:27263,35457:26806,35458:39949,35459:28511,35460:21106,35461:21917,35462:24688,35463:25324,35464:27963,35465:28167,35466:28369,35467:33883,35468:35088,35469:36676,35470:19988,35471:39993,35472:21494,35473:26907,35474:27194,35475:38788,35476:26666,35477:20828,35478:31427,35479:33970,35480:37340,35481:37772,35482:22107,35483:40232,35484:26658,35485:33541,35486:33841,35487:31909,35488:21e3,35489:33477,35490:29926,35491:20094,35492:20355,35493:20896,35494:23506,35495:21002,35496:21208,35497:21223,35498:24059,35499:21914,35500:22570,35501:23014,35502:23436,35503:23448,35504:23515,35505:24178,35506:24185,35507:24739,35508:24863,35509:24931,35510:25022,35511:25563,35512:25954,35513:26577,35514:26707,35515:26874,35516:27454,35517:27475,35518:27735,35519:28450,35520:28567,35521:28485,35522:29872,35523:29976,35524:30435,35525:30475,35526:31487,35527:31649,35528:31777,35529:32233,35530:32566,35531:32752,35532:32925,35533:33382,35534:33694,35535:35251,35536:35532,35537:36011,35538:36996,35539:37969,35540:38291,35541:38289,35542:38306,35543:38501,35544:38867,35545:39208,35546:33304,35547:20024,35548:21547,35549:23736,35550:24012,35551:29609,35552:30284,35553:30524,35554:23721,35555:32747,35556:36107,35557:38593,35558:38929,35559:38996,35560:39e3,35561:20225,35562:20238,35563:21361,35564:21916,35565:22120,35566:22522,35567:22855,35568:23305,35569:23492,35570:23696,35571:24076,35572:24190,35573:24524,35574:25582,35575:26426,35576:26071,35577:26082,35578:26399,35579:26827,35580:26820,35648:27231,35649:24112,35650:27589,35651:27671,35652:27773,35653:30079,35654:31048,35655:23395,35656:31232,35657:32e3,35658:24509,35659:35215,35660:35352,35661:36020,35662:36215,35663:36556,35664:36637,35665:39138,35666:39438,35667:39740,35668:20096,35669:20605,35670:20736,35671:22931,35672:23452,35673:25135,35674:25216,35675:25836,35676:27450,35677:29344,35678:30097,35679:31047,35680:32681,35681:34811,35682:35516,35683:35696,35684:25516,35685:33738,35686:38816,35687:21513,35688:21507,35689:21931,35690:26708,35691:27224,35692:35440,35693:30759,35694:26485,35695:40653,35696:21364,35697:23458,35698:33050,35699:34384,35700:36870,35701:19992,35702:20037,35703:20167,35704:20241,35705:21450,35706:21560,35707:23470,35708:24339,35709:24613,35710:25937,35712:26429,35713:27714,35714:27762,35715:27875,35716:28792,35717:29699,35718:31350,35719:31406,35720:31496,35721:32026,35722:31998,35723:32102,35724:26087,35725:29275,35726:21435,35727:23621,35728:24040,35729:25298,35730:25312,35731:25369,35732:28192,35733:34394,35734:35377,35735:36317,35736:37624,35737:28417,35738:31142,35739:39770,35740:20136,35741:20139,35742:20140,35743:20379,35744:20384,35745:20689,35746:20807,35747:31478,35748:20849,35749:20982,35750:21332,35751:21281,35752:21375,35753:21483,35754:21932,35755:22659,35756:23777,35757:24375,35758:24394,35759:24623,35760:24656,35761:24685,35762:25375,35763:25945,35764:27211,35765:27841,35766:29378,35767:29421,35768:30703,35769:33016,35770:33029,35771:33288,35772:34126,35773:37111,35774:37857,35775:38911,35776:39255,35777:39514,35778:20208,35779:20957,35780:23597,35781:26241,35782:26989,35783:23616,35784:26354,35785:26997,35786:29577,35787:26704,35788:31873,35789:20677,35790:21220,35791:22343,35792:24062,35793:37670,35794:26020,35795:27427,35796:27453,35797:29748,35798:31105,35799:31165,35800:31563,35801:32202,35802:33465,35803:33740,35804:34943,35805:35167,35806:35641,35807:36817,35808:37329,35809:21535,35810:37504,35811:20061,35812:20534,35813:21477,35814:21306,35815:29399,35816:29590,35817:30697,35818:33510,35819:36527,35820:39366,35821:39368,35822:39378,35823:20855,35824:24858,35825:34398,35826:21936,35827:31354,35828:20598,35829:23507,35830:36935,35831:38533,35832:20018,35833:27355,35834:37351,35835:23633,35836:23624,35904:25496,35905:31391,35906:27795,35907:38772,35908:36705,35909:31402,35910:29066,35911:38536,35912:31874,35913:26647,35914:32368,35915:26705,35916:37740,35917:21234,35918:21531,35919:34219,35920:35347,35921:32676,35922:36557,35923:37089,35924:21350,35925:34952,35926:31041,35927:20418,35928:20670,35929:21009,35930:20804,35931:21843,35932:22317,35933:29674,35934:22411,35935:22865,35936:24418,35937:24452,35938:24693,35939:24950,35940:24935,35941:25001,35942:25522,35943:25658,35944:25964,35945:26223,35946:26690,35947:28179,35948:30054,35949:31293,35950:31995,35951:32076,35952:32153,35953:32331,35954:32619,35955:33550,35956:33610,35957:34509,35958:35336,35959:35427,35960:35686,35961:36605,35962:38938,35963:40335,35964:33464,35965:36814,35966:39912,35968:21127,35969:25119,35970:25731,35971:28608,35972:38553,35973:26689,35974:20625,35975:27424,35976:27770,35977:28500,35978:31348,35979:32080,35980:34880,35981:35363,35982:26376,35983:20214,35984:20537,35985:20518,35986:20581,35987:20860,35988:21048,35989:21091,35990:21927,35991:22287,35992:22533,35993:23244,35994:24314,35995:25010,35996:25080,35997:25331,35998:25458,35999:26908,36e3:27177,36001:29309,36002:29356,36003:29486,36004:30740,36005:30831,36006:32121,36007:30476,36008:32937,36009:35211,36010:35609,36011:36066,36012:36562,36013:36963,36014:37749,36015:38522,36016:38997,36017:39443,36018:40568,36019:20803,36020:21407,36021:21427,36022:24187,36023:24358,36024:28187,36025:28304,36026:29572,36027:29694,36028:32067,36029:33335,36030:35328,36031:35578,36032:38480,36033:20046,36034:20491,36035:21476,36036:21628,36037:22266,36038:22993,36039:23396,36040:24049,36041:24235,36042:24359,36043:25144,36044:25925,36045:26543,36046:28246,36047:29392,36048:31946,36049:34996,36050:32929,36051:32993,36052:33776,36053:34382,36054:35463,36055:36328,36056:37431,36057:38599,36058:39015,36059:40723,36060:20116,36061:20114,36062:20237,36063:21320,36064:21577,36065:21566,36066:23087,36067:24460,36068:24481,36069:24735,36070:26791,36071:27278,36072:29786,36073:30849,36074:35486,36075:35492,36076:35703,36077:37264,36078:20062,36079:39881,36080:20132,36081:20348,36082:20399,36083:20505,36084:20502,36085:20809,36086:20844,36087:21151,36088:21177,36089:21246,36090:21402,36091:21475,36092:21521,36160:21518,36161:21897,36162:22353,36163:22434,36164:22909,36165:23380,36166:23389,36167:23439,36168:24037,36169:24039,36170:24055,36171:24184,36172:24195,36173:24218,36174:24247,36175:24344,36176:24658,36177:24908,36178:25239,36179:25304,36180:25511,36181:25915,36182:26114,36183:26179,36184:26356,36185:26477,36186:26657,36187:26775,36188:27083,36189:27743,36190:27946,36191:28009,36192:28207,36193:28317,36194:30002,36195:30343,36196:30828,36197:31295,36198:31968,36199:32005,36200:32024,36201:32094,36202:32177,36203:32789,36204:32771,36205:32943,36206:32945,36207:33108,36208:33167,36209:33322,36210:33618,36211:34892,36212:34913,36213:35611,36214:36002,36215:36092,36216:37066,36217:37237,36218:37489,36219:30783,36220:37628,36221:38308,36222:38477,36224:38917,36225:39321,36226:39640,36227:40251,36228:21083,36229:21163,36230:21495,36231:21512,36232:22741,36233:25335,36234:28640,36235:35946,36236:36703,36237:40633,36238:20811,36239:21051,36240:21578,36241:22269,36242:31296,36243:37239,36244:40288,36245:40658,36246:29508,36247:28425,36248:33136,36249:29969,36250:24573,36251:24794,36252:39592,36253:29403,36254:36796,36255:27492,36256:38915,36257:20170,36258:22256,36259:22372,36260:22718,36261:23130,36262:24680,36263:25031,36264:26127,36265:26118,36266:26681,36267:26801,36268:28151,36269:30165,36270:32058,36271:33390,36272:39746,36273:20123,36274:20304,36275:21449,36276:21766,36277:23919,36278:24038,36279:24046,36280:26619,36281:27801,36282:29811,36283:30722,36284:35408,36285:37782,36286:35039,36287:22352,36288:24231,36289:25387,36290:20661,36291:20652,36292:20877,36293:26368,36294:21705,36295:22622,36296:22971,36297:23472,36298:24425,36299:25165,36300:25505,36301:26685,36302:27507,36303:28168,36304:28797,36305:37319,36306:29312,36307:30741,36308:30758,36309:31085,36310:25998,36311:32048,36312:33756,36313:35009,36314:36617,36315:38555,36316:21092,36317:22312,36318:26448,36319:32618,36320:36001,36321:20916,36322:22338,36323:38442,36324:22586,36325:27018,36326:32948,36327:21682,36328:23822,36329:22524,36330:30869,36331:40442,36332:20316,36333:21066,36334:21643,36335:25662,36336:26152,36337:26388,36338:26613,36339:31364,36340:31574,36341:32034,36342:37679,36343:26716,36344:39853,36345:31545,36346:21273,36347:20874,36348:21047,36416:23519,36417:25334,36418:25774,36419:25830,36420:26413,36421:27578,36422:34217,36423:38609,36424:30352,36425:39894,36426:25420,36427:37638,36428:39851,36429:30399,36430:26194,36431:19977,36432:20632,36433:21442,36434:23665,36435:24808,36436:25746,36437:25955,36438:26719,36439:29158,36440:29642,36441:29987,36442:31639,36443:32386,36444:34453,36445:35715,36446:36059,36447:37240,36448:39184,36449:26028,36450:26283,36451:27531,36452:20181,36453:20180,36454:20282,36455:20351,36456:21050,36457:21496,36458:21490,36459:21987,36460:22235,36461:22763,36462:22987,36463:22985,36464:23039,36465:23376,36466:23629,36467:24066,36468:24107,36469:24535,36470:24605,36471:25351,36472:25903,36473:23388,36474:26031,36475:26045,36476:26088,36477:26525,36478:27490,36480:27515,36481:27663,36482:29509,36483:31049,36484:31169,36485:31992,36486:32025,36487:32043,36488:32930,36489:33026,36490:33267,36491:35222,36492:35422,36493:35433,36494:35430,36495:35468,36496:35566,36497:36039,36498:36060,36499:38604,36500:39164,36501:27503,36502:20107,36503:20284,36504:20365,36505:20816,36506:23383,36507:23546,36508:24904,36509:25345,36510:26178,36511:27425,36512:28363,36513:27835,36514:29246,36515:29885,36516:30164,36517:30913,36518:31034,36519:32780,36520:32819,36521:33258,36522:33940,36523:36766,36524:27728,36525:40575,36526:24335,36527:35672,36528:40235,36529:31482,36530:36600,36531:23437,36532:38635,36533:19971,36534:21489,36535:22519,36536:22833,36537:23241,36538:23460,36539:24713,36540:28287,36541:28422,36542:30142,36543:36074,36544:23455,36545:34048,36546:31712,36547:20594,36548:26612,36549:33437,36550:23649,36551:34122,36552:32286,36553:33294,36554:20889,36555:23556,36556:25448,36557:36198,36558:26012,36559:29038,36560:31038,36561:32023,36562:32773,36563:35613,36564:36554,36565:36974,36566:34503,36567:37034,36568:20511,36569:21242,36570:23610,36571:26451,36572:28796,36573:29237,36574:37196,36575:37320,36576:37675,36577:33509,36578:23490,36579:24369,36580:24825,36581:20027,36582:21462,36583:23432,36584:25163,36585:26417,36586:27530,36587:29417,36588:29664,36589:31278,36590:33131,36591:36259,36592:37202,36593:39318,36594:20754,36595:21463,36596:21610,36597:23551,36598:25480,36599:27193,36600:32172,36601:38656,36602:22234,36603:21454,36604:21608,36672:23447,36673:23601,36674:24030,36675:20462,36676:24833,36677:25342,36678:27954,36679:31168,36680:31179,36681:32066,36682:32333,36683:32722,36684:33261,36685:33311,36686:33936,36687:34886,36688:35186,36689:35728,36690:36468,36691:36655,36692:36913,36693:37195,36694:37228,36695:38598,36696:37276,36697:20160,36698:20303,36699:20805,36700:21313,36701:24467,36702:25102,36703:26580,36704:27713,36705:28171,36706:29539,36707:32294,36708:37325,36709:37507,36710:21460,36711:22809,36712:23487,36713:28113,36714:31069,36715:32302,36716:31899,36717:22654,36718:29087,36719:20986,36720:34899,36721:36848,36722:20426,36723:23803,36724:26149,36725:30636,36726:31459,36727:33308,36728:39423,36729:20934,36730:24490,36731:26092,36732:26991,36733:27529,36734:28147,36736:28310,36737:28516,36738:30462,36739:32020,36740:24033,36741:36981,36742:37255,36743:38918,36744:20966,36745:21021,36746:25152,36747:26257,36748:26329,36749:28186,36750:24246,36751:32210,36752:32626,36753:26360,36754:34223,36755:34295,36756:35576,36757:21161,36758:21465,36759:22899,36760:24207,36761:24464,36762:24661,36763:37604,36764:38500,36765:20663,36766:20767,36767:21213,36768:21280,36769:21319,36770:21484,36771:21736,36772:21830,36773:21809,36774:22039,36775:22888,36776:22974,36777:23100,36778:23477,36779:23558,36780:23567,36781:23569,36782:23578,36783:24196,36784:24202,36785:24288,36786:24432,36787:25215,36788:25220,36789:25307,36790:25484,36791:25463,36792:26119,36793:26124,36794:26157,36795:26230,36796:26494,36797:26786,36798:27167,36799:27189,36800:27836,36801:28040,36802:28169,36803:28248,36804:28988,36805:28966,36806:29031,36807:30151,36808:30465,36809:30813,36810:30977,36811:31077,36812:31216,36813:31456,36814:31505,36815:31911,36816:32057,36817:32918,36818:33750,36819:33931,36820:34121,36821:34909,36822:35059,36823:35359,36824:35388,36825:35412,36826:35443,36827:35937,36828:36062,36829:37284,36830:37478,36831:37758,36832:37912,36833:38556,36834:38808,36835:19978,36836:19976,36837:19998,36838:20055,36839:20887,36840:21104,36841:22478,36842:22580,36843:22732,36844:23330,36845:24120,36846:24773,36847:25854,36848:26465,36849:26454,36850:27972,36851:29366,36852:30067,36853:31331,36854:33976,36855:35698,36856:37304,36857:37664,36858:22065,36859:22516,36860:39166,36928:25325,36929:26893,36930:27542,36931:29165,36932:32340,36933:32887,36934:33394,36935:35302,36936:39135,36937:34645,36938:36785,36939:23611,36940:20280,36941:20449,36942:20405,36943:21767,36944:23072,36945:23517,36946:23529,36947:24515,36948:24910,36949:25391,36950:26032,36951:26187,36952:26862,36953:27035,36954:28024,36955:28145,36956:30003,36957:30137,36958:30495,36959:31070,36960:31206,36961:32051,36962:33251,36963:33455,36964:34218,36965:35242,36966:35386,36967:36523,36968:36763,36969:36914,36970:37341,36971:38663,36972:20154,36973:20161,36974:20995,36975:22645,36976:22764,36977:23563,36978:29978,36979:23613,36980:33102,36981:35338,36982:36805,36983:38499,36984:38765,36985:31525,36986:35535,36987:38920,36988:37218,36989:22259,36990:21416,36992:36887,36993:21561,36994:22402,36995:24101,36996:25512,36997:27700,36998:28810,36999:30561,37e3:31883,37001:32736,37002:34928,37003:36930,37004:37204,37005:37648,37006:37656,37007:38543,37008:29790,37009:39620,37010:23815,37011:23913,37012:25968,37013:26530,37014:36264,37015:38619,37016:25454,37017:26441,37018:26905,37019:33733,37020:38935,37021:38592,37022:35070,37023:28548,37024:25722,37025:23544,37026:19990,37027:28716,37028:30045,37029:26159,37030:20932,37031:21046,37032:21218,37033:22995,37034:24449,37035:24615,37036:25104,37037:25919,37038:25972,37039:26143,37040:26228,37041:26866,37042:26646,37043:27491,37044:28165,37045:29298,37046:29983,37047:30427,37048:31934,37049:32854,37050:22768,37051:35069,37052:35199,37053:35488,37054:35475,37055:35531,37056:36893,37057:37266,37058:38738,37059:38745,37060:25993,37061:31246,37062:33030,37063:38587,37064:24109,37065:24796,37066:25114,37067:26021,37068:26132,37069:26512,37070:30707,37071:31309,37072:31821,37073:32318,37074:33034,37075:36012,37076:36196,37077:36321,37078:36447,37079:30889,37080:20999,37081:25305,37082:25509,37083:25666,37084:25240,37085:35373,37086:31363,37087:31680,37088:35500,37089:38634,37090:32118,37091:33292,37092:34633,37093:20185,37094:20808,37095:21315,37096:21344,37097:23459,37098:23554,37099:23574,37100:24029,37101:25126,37102:25159,37103:25776,37104:26643,37105:26676,37106:27849,37107:27973,37108:27927,37109:26579,37110:28508,37111:29006,37112:29053,37113:26059,37114:31359,37115:31661,37116:32218,37184:32330,37185:32680,37186:33146,37187:33307,37188:33337,37189:34214,37190:35438,37191:36046,37192:36341,37193:36984,37194:36983,37195:37549,37196:37521,37197:38275,37198:39854,37199:21069,37200:21892,37201:28472,37202:28982,37203:20840,37204:31109,37205:32341,37206:33203,37207:31950,37208:22092,37209:22609,37210:23720,37211:25514,37212:26366,37213:26365,37214:26970,37215:29401,37216:30095,37217:30094,37218:30990,37219:31062,37220:31199,37221:31895,37222:32032,37223:32068,37224:34311,37225:35380,37226:38459,37227:36961,37228:40736,37229:20711,37230:21109,37231:21452,37232:21474,37233:20489,37234:21930,37235:22766,37236:22863,37237:29245,37238:23435,37239:23652,37240:21277,37241:24803,37242:24819,37243:25436,37244:25475,37245:25407,37246:25531,37248:25805,37249:26089,37250:26361,37251:24035,37252:27085,37253:27133,37254:28437,37255:29157,37256:20105,37257:30185,37258:30456,37259:31379,37260:31967,37261:32207,37262:32156,37263:32865,37264:33609,37265:33624,37266:33900,37267:33980,37268:34299,37269:35013,37270:36208,37271:36865,37272:36973,37273:37783,37274:38684,37275:39442,37276:20687,37277:22679,37278:24974,37279:33235,37280:34101,37281:36104,37282:36896,37283:20419,37284:20596,37285:21063,37286:21363,37287:24687,37288:25417,37289:26463,37290:28204,37291:36275,37292:36895,37293:20439,37294:23646,37295:36042,37296:26063,37297:32154,37298:21330,37299:34966,37300:20854,37301:25539,37302:23384,37303:23403,37304:23562,37305:25613,37306:26449,37307:36956,37308:20182,37309:22810,37310:22826,37311:27760,37312:35409,37313:21822,37314:22549,37315:22949,37316:24816,37317:25171,37318:26561,37319:33333,37320:26965,37321:38464,37322:39364,37323:39464,37324:20307,37325:22534,37326:23550,37327:32784,37328:23729,37329:24111,37330:24453,37331:24608,37332:24907,37333:25140,37334:26367,37335:27888,37336:28382,37337:32974,37338:33151,37339:33492,37340:34955,37341:36024,37342:36864,37343:36910,37344:38538,37345:40667,37346:39899,37347:20195,37348:21488,37349:22823,37350:31532,37351:37261,37352:38988,37353:40441,37354:28381,37355:28711,37356:21331,37357:21828,37358:23429,37359:25176,37360:25246,37361:25299,37362:27810,37363:28655,37364:29730,37365:35351,37366:37944,37367:28609,37368:35582,37369:33592,37370:20967,37371:34552,37372:21482,37440:21481,37441:20294,37442:36948,37443:36784,37444:22890,37445:33073,37446:24061,37447:31466,37448:36799,37449:26842,37450:35895,37451:29432,37452:40008,37453:27197,37454:35504,37455:20025,37456:21336,37457:22022,37458:22374,37459:25285,37460:25506,37461:26086,37462:27470,37463:28129,37464:28251,37465:28845,37466:30701,37467:31471,37468:31658,37469:32187,37470:32829,37471:32966,37472:34507,37473:35477,37474:37723,37475:22243,37476:22727,37477:24382,37478:26029,37479:26262,37480:27264,37481:27573,37482:30007,37483:35527,37484:20516,37485:30693,37486:22320,37487:24347,37488:24677,37489:26234,37490:27744,37491:30196,37492:31258,37493:32622,37494:33268,37495:34584,37496:36933,37497:39347,37498:31689,37499:30044,37500:31481,37501:31569,37502:33988,37504:36880,37505:31209,37506:31378,37507:33590,37508:23265,37509:30528,37510:20013,37511:20210,37512:23449,37513:24544,37514:25277,37515:26172,37516:26609,37517:27880,37518:34411,37519:34935,37520:35387,37521:37198,37522:37619,37523:39376,37524:27159,37525:28710,37526:29482,37527:33511,37528:33879,37529:36015,37530:19969,37531:20806,37532:20939,37533:21899,37534:23541,37535:24086,37536:24115,37537:24193,37538:24340,37539:24373,37540:24427,37541:24500,37542:25074,37543:25361,37544:26274,37545:26397,37546:28526,37547:29266,37548:30010,37549:30522,37550:32884,37551:33081,37552:33144,37553:34678,37554:35519,37555:35548,37556:36229,37557:36339,37558:37530,37559:38263,37560:38914,37561:40165,37562:21189,37563:25431,37564:30452,37565:26389,37566:27784,37567:29645,37568:36035,37569:37806,37570:38515,37571:27941,37572:22684,37573:26894,37574:27084,37575:36861,37576:37786,37577:30171,37578:36890,37579:22618,37580:26626,37581:25524,37582:27131,37583:20291,37584:28460,37585:26584,37586:36795,37587:34086,37588:32180,37589:37716,37590:26943,37591:28528,37592:22378,37593:22775,37594:23340,37595:32044,37596:29226,37597:21514,37598:37347,37599:40372,37600:20141,37601:20302,37602:20572,37603:20597,37604:21059,37605:35998,37606:21576,37607:22564,37608:23450,37609:24093,37610:24213,37611:24237,37612:24311,37613:24351,37614:24716,37615:25269,37616:25402,37617:25552,37618:26799,37619:27712,37620:30855,37621:31118,37622:31243,37623:32224,37624:33351,37625:35330,37626:35558,37627:36420,37628:36883,37696:37048,37697:37165,37698:37336,37699:40718,37700:27877,37701:25688,37702:25826,37703:25973,37704:28404,37705:30340,37706:31515,37707:36969,37708:37841,37709:28346,37710:21746,37711:24505,37712:25764,37713:36685,37714:36845,37715:37444,37716:20856,37717:22635,37718:22825,37719:23637,37720:24215,37721:28155,37722:32399,37723:29980,37724:36028,37725:36578,37726:39003,37727:28857,37728:20253,37729:27583,37730:28593,37731:3e4,37732:38651,37733:20814,37734:21520,37735:22581,37736:22615,37737:22956,37738:23648,37739:24466,37740:26007,37741:26460,37742:28193,37743:30331,37744:33759,37745:36077,37746:36884,37747:37117,37748:37709,37749:30757,37750:30778,37751:21162,37752:24230,37753:22303,37754:22900,37755:24594,37756:20498,37757:20826,37758:20908,37760:20941,37761:20992,37762:21776,37763:22612,37764:22616,37765:22871,37766:23445,37767:23798,37768:23947,37769:24764,37770:25237,37771:25645,37772:26481,37773:26691,37774:26812,37775:26847,37776:30423,37777:28120,37778:28271,37779:28059,37780:28783,37781:29128,37782:24403,37783:30168,37784:31095,37785:31561,37786:31572,37787:31570,37788:31958,37789:32113,37790:21040,37791:33891,37792:34153,37793:34276,37794:35342,37795:35588,37796:35910,37797:36367,37798:36867,37799:36879,37800:37913,37801:38518,37802:38957,37803:39472,37804:38360,37805:20685,37806:21205,37807:21516,37808:22530,37809:23566,37810:24999,37811:25758,37812:27934,37813:30643,37814:31461,37815:33012,37816:33796,37817:36947,37818:37509,37819:23776,37820:40199,37821:21311,37822:24471,37823:24499,37824:28060,37825:29305,37826:30563,37827:31167,37828:31716,37829:27602,37830:29420,37831:35501,37832:26627,37833:27233,37834:20984,37835:31361,37836:26932,37837:23626,37838:40182,37839:33515,37840:23493,37841:37193,37842:28702,37843:22136,37844:23663,37845:24775,37846:25958,37847:27788,37848:35930,37849:36929,37850:38931,37851:21585,37852:26311,37853:37389,37854:22856,37855:37027,37856:20869,37857:20045,37858:20970,37859:34201,37860:35598,37861:28760,37862:25466,37863:37707,37864:26978,37865:39348,37866:32260,37867:30071,37868:21335,37869:26976,37870:36575,37871:38627,37872:27741,37873:20108,37874:23612,37875:24336,37876:36841,37877:21250,37878:36049,37879:32905,37880:34425,37881:24319,37882:26085,37883:20083,37884:20837,37952:22914,37953:23615,37954:38894,37955:20219,37956:22922,37957:24525,37958:35469,37959:28641,37960:31152,37961:31074,37962:23527,37963:33905,37964:29483,37965:29105,37966:24180,37967:24565,37968:25467,37969:25754,37970:29123,37971:31896,37972:20035,37973:24316,37974:20043,37975:22492,37976:22178,37977:24745,37978:28611,37979:32013,37980:33021,37981:33075,37982:33215,37983:36786,37984:35223,37985:34468,37986:24052,37987:25226,37988:25773,37989:35207,37990:26487,37991:27874,37992:27966,37993:29750,37994:30772,37995:23110,37996:32629,37997:33453,37998:39340,37999:20467,38e3:24259,38001:25309,38002:25490,38003:25943,38004:26479,38005:30403,38006:29260,38007:32972,38008:32954,38009:36649,38010:37197,38011:20493,38012:22521,38013:23186,38014:26757,38016:26995,38017:29028,38018:29437,38019:36023,38020:22770,38021:36064,38022:38506,38023:36889,38024:34687,38025:31204,38026:30695,38027:33833,38028:20271,38029:21093,38030:21338,38031:25293,38032:26575,38033:27850,38034:30333,38035:31636,38036:31893,38037:33334,38038:34180,38039:36843,38040:26333,38041:28448,38042:29190,38043:32283,38044:33707,38045:39361,38046:40614,38047:20989,38048:31665,38049:30834,38050:31672,38051:32903,38052:31560,38053:27368,38054:24161,38055:32908,38056:30033,38057:30048,38058:20843,38059:37474,38060:28300,38061:30330,38062:37271,38063:39658,38064:20240,38065:32624,38066:25244,38067:31567,38068:38309,38069:40169,38070:22138,38071:22617,38072:34532,38073:38588,38074:20276,38075:21028,38076:21322,38077:21453,38078:21467,38079:24070,38080:25644,38081:26001,38082:26495,38083:27710,38084:27726,38085:29256,38086:29359,38087:29677,38088:30036,38089:32321,38090:33324,38091:34281,38092:36009,38093:31684,38094:37318,38095:29033,38096:38930,38097:39151,38098:25405,38099:26217,38100:30058,38101:30436,38102:30928,38103:34115,38104:34542,38105:21290,38106:21329,38107:21542,38108:22915,38109:24199,38110:24444,38111:24754,38112:25161,38113:25209,38114:25259,38115:26e3,38116:27604,38117:27852,38118:30130,38119:30382,38120:30865,38121:31192,38122:32203,38123:32631,38124:32933,38125:34987,38126:35513,38127:36027,38128:36991,38129:38750,38130:39131,38131:27147,38132:31800,38133:20633,38134:23614,38135:24494,38136:26503,38137:27608,38138:29749,38139:30473,38140:32654,38208:40763,38209:26570,38210:31255,38211:21305,38212:30091,38213:39661,38214:24422,38215:33181,38216:33777,38217:32920,38218:24380,38219:24517,38220:30050,38221:31558,38222:36924,38223:26727,38224:23019,38225:23195,38226:32016,38227:30334,38228:35628,38229:20469,38230:24426,38231:27161,38232:27703,38233:28418,38234:29922,38235:31080,38236:34920,38237:35413,38238:35961,38239:24287,38240:25551,38241:30149,38242:31186,38243:33495,38244:37672,38245:37618,38246:33948,38247:34541,38248:39981,38249:21697,38250:24428,38251:25996,38252:27996,38253:28693,38254:36007,38255:36051,38256:38971,38257:25935,38258:29942,38259:19981,38260:20184,38261:22496,38262:22827,38263:23142,38264:23500,38265:20904,38266:24067,38267:24220,38268:24598,38269:25206,38270:25975,38272:26023,38273:26222,38274:28014,38275:29238,38276:31526,38277:33104,38278:33178,38279:33433,38280:35676,38281:36e3,38282:36070,38283:36212,38284:38428,38285:38468,38286:20398,38287:25771,38288:27494,38289:33310,38290:33889,38291:34154,38292:37096,38293:23553,38294:26963,38295:39080,38296:33914,38297:34135,38298:20239,38299:21103,38300:24489,38301:24133,38302:26381,38303:31119,38304:33145,38305:35079,38306:35206,38307:28149,38308:24343,38309:25173,38310:27832,38311:20175,38312:29289,38313:39826,38314:20998,38315:21563,38316:22132,38317:22707,38318:24996,38319:25198,38320:28954,38321:22894,38322:31881,38323:31966,38324:32027,38325:38640,38326:25991,38327:32862,38328:19993,38329:20341,38330:20853,38331:22592,38332:24163,38333:24179,38334:24330,38335:26564,38336:20006,38337:34109,38338:38281,38339:38491,38340:31859,38341:38913,38342:20731,38343:22721,38344:30294,38345:30887,38346:21029,38347:30629,38348:34065,38349:31622,38350:20559,38351:22793,38352:29255,38353:31687,38354:32232,38355:36794,38356:36820,38357:36941,38358:20415,38359:21193,38360:23081,38361:24321,38362:38829,38363:20445,38364:33303,38365:37610,38366:22275,38367:25429,38368:27497,38369:29995,38370:35036,38371:36628,38372:31298,38373:21215,38374:22675,38375:24917,38376:25098,38377:26286,38378:27597,38379:31807,38380:33769,38381:20515,38382:20472,38383:21253,38384:21574,38385:22577,38386:22857,38387:23453,38388:23792,38389:23791,38390:23849,38391:24214,38392:25265,38393:25447,38394:25918,38395:26041,38396:26379,38464:27861,38465:27873,38466:28921,38467:30770,38468:32299,38469:32990,38470:33459,38471:33804,38472:34028,38473:34562,38474:35090,38475:35370,38476:35914,38477:37030,38478:37586,38479:39165,38480:40179,38481:40300,38482:20047,38483:20129,38484:20621,38485:21078,38486:22346,38487:22952,38488:24125,38489:24536,38490:24537,38491:25151,38492:26292,38493:26395,38494:26576,38495:26834,38496:20882,38497:32033,38498:32938,38499:33192,38500:35584,38501:35980,38502:36031,38503:37502,38504:38450,38505:21536,38506:38956,38507:21271,38508:20693,38509:21340,38510:22696,38511:25778,38512:26420,38513:29287,38514:30566,38515:31302,38516:37350,38517:21187,38518:27809,38519:27526,38520:22528,38521:24140,38522:22868,38523:26412,38524:32763,38525:20961,38526:30406,38528:25705,38529:30952,38530:39764,38531:40635,38532:22475,38533:22969,38534:26151,38535:26522,38536:27598,38537:21737,38538:27097,38539:24149,38540:33180,38541:26517,38542:39850,38543:26622,38544:40018,38545:26717,38546:20134,38547:20451,38548:21448,38549:25273,38550:26411,38551:27819,38552:36804,38553:20397,38554:32365,38555:40639,38556:19975,38557:24930,38558:28288,38559:28459,38560:34067,38561:21619,38562:26410,38563:39749,38564:24051,38565:31637,38566:23724,38567:23494,38568:34588,38569:28234,38570:34001,38571:31252,38572:33032,38573:22937,38574:31885,38575:27665,38576:30496,38577:21209,38578:22818,38579:28961,38580:29279,38581:30683,38582:38695,38583:40289,38584:26891,38585:23167,38586:23064,38587:20901,38588:21517,38589:21629,38590:26126,38591:30431,38592:36855,38593:37528,38594:40180,38595:23018,38596:29277,38597:28357,38598:20813,38599:26825,38600:32191,38601:32236,38602:38754,38603:40634,38604:25720,38605:27169,38606:33538,38607:22916,38608:23391,38609:27611,38610:29467,38611:30450,38612:32178,38613:32791,38614:33945,38615:20786,38616:26408,38617:40665,38618:30446,38619:26466,38620:21247,38621:39173,38622:23588,38623:25147,38624:31870,38625:36016,38626:21839,38627:24758,38628:32011,38629:38272,38630:21249,38631:20063,38632:20918,38633:22812,38634:29242,38635:32822,38636:37326,38637:24357,38638:30690,38639:21380,38640:24441,38641:32004,38642:34220,38643:35379,38644:36493,38645:38742,38646:26611,38647:34222,38648:37971,38649:24841,38650:24840,38651:27833,38652:30290,38720:35565,38721:36664,38722:21807,38723:20305,38724:20778,38725:21191,38726:21451,38727:23461,38728:24189,38729:24736,38730:24962,38731:25558,38732:26377,38733:26586,38734:28263,38735:28044,38736:29494,38737:29495,38738:30001,38739:31056,38740:35029,38741:35480,38742:36938,38743:37009,38744:37109,38745:38596,38746:34701,38747:22805,38748:20104,38749:20313,38750:19982,38751:35465,38752:36671,38753:38928,38754:20653,38755:24188,38756:22934,38757:23481,38758:24248,38759:25562,38760:25594,38761:25793,38762:26332,38763:26954,38764:27096,38765:27915,38766:28342,38767:29076,38768:29992,38769:31407,38770:32650,38771:32768,38772:33865,38773:33993,38774:35201,38775:35617,38776:36362,38777:36965,38778:38525,38779:39178,38780:24958,38781:25233,38782:27442,38784:27779,38785:28020,38786:32716,38787:32764,38788:28096,38789:32645,38790:34746,38791:35064,38792:26469,38793:33713,38794:38972,38795:38647,38796:27931,38797:32097,38798:33853,38799:37226,38800:20081,38801:21365,38802:23888,38803:27396,38804:28651,38805:34253,38806:34349,38807:35239,38808:21033,38809:21519,38810:23653,38811:26446,38812:26792,38813:29702,38814:29827,38815:30178,38816:35023,38817:35041,38818:37324,38819:38626,38820:38520,38821:24459,38822:29575,38823:31435,38824:33870,38825:25504,38826:30053,38827:21129,38828:27969,38829:28316,38830:29705,38831:30041,38832:30827,38833:31890,38834:38534,38835:31452,38836:40845,38837:20406,38838:24942,38839:26053,38840:34396,38841:20102,38842:20142,38843:20698,38844:20001,38845:20940,38846:23534,38847:26009,38848:26753,38849:28092,38850:29471,38851:30274,38852:30637,38853:31260,38854:31975,38855:33391,38856:35538,38857:36988,38858:37327,38859:38517,38860:38936,38861:21147,38862:32209,38863:20523,38864:21400,38865:26519,38866:28107,38867:29136,38868:29747,38869:33256,38870:36650,38871:38563,38872:40023,38873:40607,38874:29792,38875:22593,38876:28057,38877:32047,38878:39006,38879:20196,38880:20278,38881:20363,38882:20919,38883:21169,38884:23994,38885:24604,38886:29618,38887:31036,38888:33491,38889:37428,38890:38583,38891:38646,38892:38666,38893:40599,38894:40802,38895:26278,38896:27508,38897:21015,38898:21155,38899:28872,38900:35010,38901:24265,38902:24651,38903:24976,38904:28451,38905:29001,38906:31806,38907:32244,38908:32879,38976:34030,38977:36899,38978:37676,38979:21570,38980:39791,38981:27347,38982:28809,38983:36034,38984:36335,38985:38706,38986:21172,38987:23105,38988:24266,38989:24324,38990:26391,38991:27004,38992:27028,38993:28010,38994:28431,38995:29282,38996:29436,38997:31725,38998:32769,38999:32894,39e3:34635,39001:37070,39002:20845,39003:40595,39004:31108,39005:32907,39006:37682,39007:35542,39008:20525,39009:21644,39010:35441,39011:27498,39012:36036,39013:33031,39014:24785,39015:26528,39016:40434,39017:20121,39018:20120,39019:39952,39020:35435,39021:34241,39022:34152,39023:26880,39024:28286,39025:30871,39026:33109,39071:24332,39072:19984,39073:19989,39074:20010,39075:20017,39076:20022,39077:20028,39078:20031,39079:20034,39080:20054,39081:20056,39082:20098,39083:20101,39084:35947,39085:20106,39086:33298,39087:24333,39088:20110,39089:20126,39090:20127,39091:20128,39092:20130,39093:20144,39094:20147,39095:20150,39096:20174,39097:20173,39098:20164,39099:20166,39100:20162,39101:20183,39102:20190,39103:20205,39104:20191,39105:20215,39106:20233,39107:20314,39108:20272,39109:20315,39110:20317,39111:20311,39112:20295,39113:20342,39114:20360,39115:20367,39116:20376,39117:20347,39118:20329,39119:20336,39120:20369,39121:20335,39122:20358,39123:20374,39124:20760,39125:20436,39126:20447,39127:20430,39128:20440,39129:20443,39130:20433,39131:20442,39132:20432,39133:20452,39134:20453,39135:20506,39136:20520,39137:20500,39138:20522,39139:20517,39140:20485,39141:20252,39142:20470,39143:20513,39144:20521,39145:20524,39146:20478,39147:20463,39148:20497,39149:20486,39150:20547,39151:20551,39152:26371,39153:20565,39154:20560,39155:20552,39156:20570,39157:20566,39158:20588,39159:20600,39160:20608,39161:20634,39162:20613,39163:20660,39164:20658,39232:20681,39233:20682,39234:20659,39235:20674,39236:20694,39237:20702,39238:20709,39239:20717,39240:20707,39241:20718,39242:20729,39243:20725,39244:20745,39245:20737,39246:20738,39247:20758,39248:20757,39249:20756,39250:20762,39251:20769,39252:20794,39253:20791,39254:20796,39255:20795,39256:20799,39257:20800,39258:20818,39259:20812,39260:20820,39261:20834,39262:31480,39263:20841,39264:20842,39265:20846,39266:20864,39267:20866,39268:22232,39269:20876,39270:20873,39271:20879,39272:20881,39273:20883,39274:20885,39275:20886,39276:20900,39277:20902,39278:20898,39279:20905,39280:20906,39281:20907,39282:20915,39283:20913,39284:20914,39285:20912,39286:20917,39287:20925,39288:20933,39289:20937,39290:20955,39291:20960,39292:34389,39293:20969,39294:20973,39296:20976,39297:20981,39298:20990,39299:20996,39300:21003,39301:21012,39302:21006,39303:21031,39304:21034,39305:21038,39306:21043,39307:21049,39308:21071,39309:21060,39310:21067,39311:21068,39312:21086,39313:21076,39314:21098,39315:21108,39316:21097,39317:21107,39318:21119,39319:21117,39320:21133,39321:21140,39322:21138,39323:21105,39324:21128,39325:21137,39326:36776,39327:36775,39328:21164,39329:21165,39330:21180,39331:21173,39332:21185,39333:21197,39334:21207,39335:21214,39336:21219,39337:21222,39338:39149,39339:21216,39340:21235,39341:21237,39342:21240,39343:21241,39344:21254,39345:21256,39346:30008,39347:21261,39348:21264,39349:21263,39350:21269,39351:21274,39352:21283,39353:21295,39354:21297,39355:21299,39356:21304,39357:21312,39358:21318,39359:21317,39360:19991,39361:21321,39362:21325,39363:20950,39364:21342,39365:21353,39366:21358,39367:22808,39368:21371,39369:21367,39370:21378,39371:21398,39372:21408,39373:21414,39374:21413,39375:21422,39376:21424,39377:21430,39378:21443,39379:31762,39380:38617,39381:21471,39382:26364,39383:29166,39384:21486,39385:21480,39386:21485,39387:21498,39388:21505,39389:21565,39390:21568,39391:21548,39392:21549,39393:21564,39394:21550,39395:21558,39396:21545,39397:21533,39398:21582,39399:21647,39400:21621,39401:21646,39402:21599,39403:21617,39404:21623,39405:21616,39406:21650,39407:21627,39408:21632,39409:21622,39410:21636,39411:21648,39412:21638,39413:21703,39414:21666,39415:21688,39416:21669,39417:21676,39418:21700,39419:21704,39420:21672,39488:21675,39489:21698,39490:21668,39491:21694,39492:21692,39493:21720,39494:21733,39495:21734,39496:21775,39497:21780,39498:21757,39499:21742,39500:21741,39501:21754,39502:21730,39503:21817,39504:21824,39505:21859,39506:21836,39507:21806,39508:21852,39509:21829,39510:21846,39511:21847,39512:21816,39513:21811,39514:21853,39515:21913,39516:21888,39517:21679,39518:21898,39519:21919,39520:21883,39521:21886,39522:21912,39523:21918,39524:21934,39525:21884,39526:21891,39527:21929,39528:21895,39529:21928,39530:21978,39531:21957,39532:21983,39533:21956,39534:21980,39535:21988,39536:21972,39537:22036,39538:22007,39539:22038,39540:22014,39541:22013,39542:22043,39543:22009,39544:22094,39545:22096,39546:29151,39547:22068,39548:22070,39549:22066,39550:22072,39552:22123,39553:22116,39554:22063,39555:22124,39556:22122,39557:22150,39558:22144,39559:22154,39560:22176,39561:22164,39562:22159,39563:22181,39564:22190,39565:22198,39566:22196,39567:22210,39568:22204,39569:22209,39570:22211,39571:22208,39572:22216,39573:22222,39574:22225,39575:22227,39576:22231,39577:22254,39578:22265,39579:22272,39580:22271,39581:22276,39582:22281,39583:22280,39584:22283,39585:22285,39586:22291,39587:22296,39588:22294,39589:21959,39590:22300,39591:22310,39592:22327,39593:22328,39594:22350,39595:22331,39596:22336,39597:22351,39598:22377,39599:22464,39600:22408,39601:22369,39602:22399,39603:22409,39604:22419,39605:22432,39606:22451,39607:22436,39608:22442,39609:22448,39610:22467,39611:22470,39612:22484,39613:22482,39614:22483,39615:22538,39616:22486,39617:22499,39618:22539,39619:22553,39620:22557,39621:22642,39622:22561,39623:22626,39624:22603,39625:22640,39626:27584,39627:22610,39628:22589,39629:22649,39630:22661,39631:22713,39632:22687,39633:22699,39634:22714,39635:22750,39636:22715,39637:22712,39638:22702,39639:22725,39640:22739,39641:22737,39642:22743,39643:22745,39644:22744,39645:22757,39646:22748,39647:22756,39648:22751,39649:22767,39650:22778,39651:22777,39652:22779,39653:22780,39654:22781,39655:22786,39656:22794,39657:22800,39658:22811,39659:26790,39660:22821,39661:22828,39662:22829,39663:22834,39664:22840,39665:22846,39666:31442,39667:22869,39668:22864,39669:22862,39670:22874,39671:22872,39672:22882,39673:22880,39674:22887,39675:22892,39676:22889,39744:22904,39745:22913,39746:22941,39747:20318,39748:20395,39749:22947,39750:22962,39751:22982,39752:23016,39753:23004,39754:22925,39755:23001,39756:23002,39757:23077,39758:23071,39759:23057,39760:23068,39761:23049,39762:23066,39763:23104,39764:23148,39765:23113,39766:23093,39767:23094,39768:23138,39769:23146,39770:23194,39771:23228,39772:23230,39773:23243,39774:23234,39775:23229,39776:23267,39777:23255,39778:23270,39779:23273,39780:23254,39781:23290,39782:23291,39783:23308,39784:23307,39785:23318,39786:23346,39787:23248,39788:23338,39789:23350,39790:23358,39791:23363,39792:23365,39793:23360,39794:23377,39795:23381,39796:23386,39797:23387,39798:23397,39799:23401,39800:23408,39801:23411,39802:23413,39803:23416,39804:25992,39805:23418,39806:23424,39808:23427,39809:23462,39810:23480,39811:23491,39812:23495,39813:23497,39814:23508,39815:23504,39816:23524,39817:23526,39818:23522,39819:23518,39820:23525,39821:23531,39822:23536,39823:23542,39824:23539,39825:23557,39826:23559,39827:23560,39828:23565,39829:23571,39830:23584,39831:23586,39832:23592,39833:23608,39834:23609,39835:23617,39836:23622,39837:23630,39838:23635,39839:23632,39840:23631,39841:23409,39842:23660,39843:23662,39844:20066,39845:23670,39846:23673,39847:23692,39848:23697,39849:23700,39850:22939,39851:23723,39852:23739,39853:23734,39854:23740,39855:23735,39856:23749,39857:23742,39858:23751,39859:23769,39860:23785,39861:23805,39862:23802,39863:23789,39864:23948,39865:23786,39866:23819,39867:23829,39868:23831,39869:23900,39870:23839,39871:23835,39872:23825,39873:23828,39874:23842,39875:23834,39876:23833,39877:23832,39878:23884,39879:23890,39880:23886,39881:23883,39882:23916,39883:23923,39884:23926,39885:23943,39886:23940,39887:23938,39888:23970,39889:23965,39890:23980,39891:23982,39892:23997,39893:23952,39894:23991,39895:23996,39896:24009,39897:24013,39898:24019,39899:24018,39900:24022,39901:24027,39902:24043,39903:24050,39904:24053,39905:24075,39906:24090,39907:24089,39908:24081,39909:24091,39910:24118,39911:24119,39912:24132,39913:24131,39914:24128,39915:24142,39916:24151,39917:24148,39918:24159,39919:24162,39920:24164,39921:24135,39922:24181,39923:24182,39924:24186,39925:40636,39926:24191,39927:24224,39928:24257,39929:24258,39930:24264,39931:24272,39932:24271,4e4:24278,40001:24291,40002:24285,40003:24282,40004:24283,40005:24290,40006:24289,40007:24296,40008:24297,40009:24300,40010:24305,40011:24307,40012:24304,40013:24308,40014:24312,40015:24318,40016:24323,40017:24329,40018:24413,40019:24412,40020:24331,40021:24337,40022:24342,40023:24361,40024:24365,40025:24376,40026:24385,40027:24392,40028:24396,40029:24398,40030:24367,40031:24401,40032:24406,40033:24407,40034:24409,40035:24417,40036:24429,40037:24435,40038:24439,40039:24451,40040:24450,40041:24447,40042:24458,40043:24456,40044:24465,40045:24455,40046:24478,40047:24473,40048:24472,40049:24480,40050:24488,40051:24493,40052:24508,40053:24534,40054:24571,40055:24548,40056:24568,40057:24561,40058:24541,40059:24755,40060:24575,40061:24609,40062:24672,40064:24601,40065:24592,40066:24617,40067:24590,40068:24625,40069:24603,40070:24597,40071:24619,40072:24614,40073:24591,40074:24634,40075:24666,40076:24641,40077:24682,40078:24695,40079:24671,40080:24650,40081:24646,40082:24653,40083:24675,40084:24643,40085:24676,40086:24642,40087:24684,40088:24683,40089:24665,40090:24705,40091:24717,40092:24807,40093:24707,40094:24730,40095:24708,40096:24731,40097:24726,40098:24727,40099:24722,40100:24743,40101:24715,40102:24801,40103:24760,40104:24800,40105:24787,40106:24756,40107:24560,40108:24765,40109:24774,40110:24757,40111:24792,40112:24909,40113:24853,40114:24838,40115:24822,40116:24823,40117:24832,40118:24820,40119:24826,40120:24835,40121:24865,40122:24827,40123:24817,40124:24845,40125:24846,40126:24903,40127:24894,40128:24872,40129:24871,40130:24906,40131:24895,40132:24892,40133:24876,40134:24884,40135:24893,40136:24898,40137:24900,40138:24947,40139:24951,40140:24920,40141:24921,40142:24922,40143:24939,40144:24948,40145:24943,40146:24933,40147:24945,40148:24927,40149:24925,40150:24915,40151:24949,40152:24985,40153:24982,40154:24967,40155:25004,40156:24980,40157:24986,40158:24970,40159:24977,40160:25003,40161:25006,40162:25036,40163:25034,40164:25033,40165:25079,40166:25032,40167:25027,40168:25030,40169:25018,40170:25035,40171:32633,40172:25037,40173:25062,40174:25059,40175:25078,40176:25082,40177:25076,40178:25087,40179:25085,40180:25084,40181:25086,40182:25088,40183:25096,40184:25097,40185:25101,40186:25100,40187:25108,40188:25115,40256:25118,40257:25121,40258:25130,40259:25134,40260:25136,40261:25138,40262:25139,40263:25153,40264:25166,40265:25182,40266:25187,40267:25179,40268:25184,40269:25192,40270:25212,40271:25218,40272:25225,40273:25214,40274:25234,40275:25235,40276:25238,40277:25300,40278:25219,40279:25236,40280:25303,40281:25297,40282:25275,40283:25295,40284:25343,40285:25286,40286:25812,40287:25288,40288:25308,40289:25292,40290:25290,40291:25282,40292:25287,40293:25243,40294:25289,40295:25356,40296:25326,40297:25329,40298:25383,40299:25346,40300:25352,40301:25327,40302:25333,40303:25424,40304:25406,40305:25421,40306:25628,40307:25423,40308:25494,40309:25486,40310:25472,40311:25515,40312:25462,40313:25507,40314:25487,40315:25481,40316:25503,40317:25525,40318:25451,40320:25449,40321:25534,40322:25577,40323:25536,40324:25542,40325:25571,40326:25545,40327:25554,40328:25590,40329:25540,40330:25622,40331:25652,40332:25606,40333:25619,40334:25638,40335:25654,40336:25885,40337:25623,40338:25640,40339:25615,40340:25703,40341:25711,40342:25718,40343:25678,40344:25898,40345:25749,40346:25747,40347:25765,40348:25769,40349:25736,40350:25788,40351:25818,40352:25810,40353:25797,40354:25799,40355:25787,40356:25816,40357:25794,40358:25841,40359:25831,40360:33289,40361:25824,40362:25825,40363:25260,40364:25827,40365:25839,40366:25900,40367:25846,40368:25844,40369:25842,40370:25850,40371:25856,40372:25853,40373:25880,40374:25884,40375:25861,40376:25892,40377:25891,40378:25899,40379:25908,40380:25909,40381:25911,40382:25910,40383:25912,40384:30027,40385:25928,40386:25942,40387:25941,40388:25933,40389:25944,40390:25950,40391:25949,40392:25970,40393:25976,40394:25986,40395:25987,40396:35722,40397:26011,40398:26015,40399:26027,40400:26039,40401:26051,40402:26054,40403:26049,40404:26052,40405:26060,40406:26066,40407:26075,40408:26073,40409:26080,40410:26081,40411:26097,40412:26482,40413:26122,40414:26115,40415:26107,40416:26483,40417:26165,40418:26166,40419:26164,40420:26140,40421:26191,40422:26180,40423:26185,40424:26177,40425:26206,40426:26205,40427:26212,40428:26215,40429:26216,40430:26207,40431:26210,40432:26224,40433:26243,40434:26248,40435:26254,40436:26249,40437:26244,40438:26264,40439:26269,40440:26305,40441:26297,40442:26313,40443:26302,40444:26300,40512:26308,40513:26296,40514:26326,40515:26330,40516:26336,40517:26175,40518:26342,40519:26345,40520:26352,40521:26357,40522:26359,40523:26383,40524:26390,40525:26398,40526:26406,40527:26407,40528:38712,40529:26414,40530:26431,40531:26422,40532:26433,40533:26424,40534:26423,40535:26438,40536:26462,40537:26464,40538:26457,40539:26467,40540:26468,40541:26505,40542:26480,40543:26537,40544:26492,40545:26474,40546:26508,40547:26507,40548:26534,40549:26529,40550:26501,40551:26551,40552:26607,40553:26548,40554:26604,40555:26547,40556:26601,40557:26552,40558:26596,40559:26590,40560:26589,40561:26594,40562:26606,40563:26553,40564:26574,40565:26566,40566:26599,40567:27292,40568:26654,40569:26694,40570:26665,40571:26688,40572:26701,40573:26674,40574:26702,40576:26803,40577:26667,40578:26713,40579:26723,40580:26743,40581:26751,40582:26783,40583:26767,40584:26797,40585:26772,40586:26781,40587:26779,40588:26755,40589:27310,40590:26809,40591:26740,40592:26805,40593:26784,40594:26810,40595:26895,40596:26765,40597:26750,40598:26881,40599:26826,40600:26888,40601:26840,40602:26914,40603:26918,40604:26849,40605:26892,40606:26829,40607:26836,40608:26855,40609:26837,40610:26934,40611:26898,40612:26884,40613:26839,40614:26851,40615:26917,40616:26873,40617:26848,40618:26863,40619:26920,40620:26922,40621:26906,40622:26915,40623:26913,40624:26822,40625:27001,40626:26999,40627:26972,40628:27e3,40629:26987,40630:26964,40631:27006,40632:26990,40633:26937,40634:26996,40635:26941,40636:26969,40637:26928,40638:26977,40639:26974,40640:26973,40641:27009,40642:26986,40643:27058,40644:27054,40645:27088,40646:27071,40647:27073,40648:27091,40649:27070,40650:27086,40651:23528,40652:27082,40653:27101,40654:27067,40655:27075,40656:27047,40657:27182,40658:27025,40659:27040,40660:27036,40661:27029,40662:27060,40663:27102,40664:27112,40665:27138,40666:27163,40667:27135,40668:27402,40669:27129,40670:27122,40671:27111,40672:27141,40673:27057,40674:27166,40675:27117,40676:27156,40677:27115,40678:27146,40679:27154,40680:27329,40681:27171,40682:27155,40683:27204,40684:27148,40685:27250,40686:27190,40687:27256,40688:27207,40689:27234,40690:27225,40691:27238,40692:27208,40693:27192,40694:27170,40695:27280,40696:27277,40697:27296,40698:27268,40699:27298,40700:27299,40768:27287,40769:34327,40770:27323,40771:27331,40772:27330,40773:27320,40774:27315,40775:27308,40776:27358,40777:27345,40778:27359,40779:27306,40780:27354,40781:27370,40782:27387,40783:27397,40784:34326,40785:27386,40786:27410,40787:27414,40788:39729,40789:27423,40790:27448,40791:27447,40792:30428,40793:27449,40794:39150,40795:27463,40796:27459,40797:27465,40798:27472,40799:27481,40800:27476,40801:27483,40802:27487,40803:27489,40804:27512,40805:27513,40806:27519,40807:27520,40808:27524,40809:27523,40810:27533,40811:27544,40812:27541,40813:27550,40814:27556,40815:27562,40816:27563,40817:27567,40818:27570,40819:27569,40820:27571,40821:27575,40822:27580,40823:27590,40824:27595,40825:27603,40826:27615,40827:27628,40828:27627,40829:27635,40830:27631,40832:40638,40833:27656,40834:27667,40835:27668,40836:27675,40837:27684,40838:27683,40839:27742,40840:27733,40841:27746,40842:27754,40843:27778,40844:27789,40845:27802,40846:27777,40847:27803,40848:27774,40849:27752,40850:27763,40851:27794,40852:27792,40853:27844,40854:27889,40855:27859,40856:27837,40857:27863,40858:27845,40859:27869,40860:27822,40861:27825,40862:27838,40863:27834,40864:27867,40865:27887,40866:27865,40867:27882,40868:27935,40869:34893,40870:27958,40871:27947,40872:27965,40873:27960,40874:27929,40875:27957,40876:27955,40877:27922,40878:27916,40879:28003,40880:28051,40881:28004,40882:27994,40883:28025,40884:27993,40885:28046,40886:28053,40887:28644,40888:28037,40889:28153,40890:28181,40891:28170,40892:28085,40893:28103,40894:28134,40895:28088,40896:28102,40897:28140,40898:28126,40899:28108,40900:28136,40901:28114,40902:28101,40903:28154,40904:28121,40905:28132,40906:28117,40907:28138,40908:28142,40909:28205,40910:28270,40911:28206,40912:28185,40913:28274,40914:28255,40915:28222,40916:28195,40917:28267,40918:28203,40919:28278,40920:28237,40921:28191,40922:28227,40923:28218,40924:28238,40925:28196,40926:28415,40927:28189,40928:28216,40929:28290,40930:28330,40931:28312,40932:28361,40933:28343,40934:28371,40935:28349,40936:28335,40937:28356,40938:28338,40939:28372,40940:28373,40941:28303,40942:28325,40943:28354,40944:28319,40945:28481,40946:28433,40947:28748,40948:28396,40949:28408,40950:28414,40951:28479,40952:28402,40953:28465,40954:28399,40955:28466,40956:28364,161:65377,162:65378,163:65379,164:65380,165:65381,166:65382,167:65383,168:65384,169:65385,170:65386,171:65387,172:65388,173:65389,174:65390,175:65391,176:65392,177:65393,178:65394,179:65395,180:65396,181:65397,182:65398,183:65399,184:65400,185:65401,186:65402,187:65403,188:65404,189:65405,190:65406,191:65407,192:65408,193:65409,194:65410,195:65411,196:65412,197:65413,198:65414,199:65415,200:65416,201:65417,202:65418,203:65419,204:65420,205:65421,206:65422,207:65423,208:65424,209:65425,210:65426,211:65427,212:65428,213:65429,214:65430,215:65431,216:65432,217:65433,218:65434,219:65435,220:65436,221:65437,222:65438,223:65439,57408:28478,57409:28435,57410:28407,57411:28550,57412:28538,57413:28536,57414:28545,57415:28544,57416:28527,57417:28507,57418:28659,57419:28525,57420:28546,57421:28540,57422:28504,57423:28558,57424:28561,57425:28610,57426:28518,57427:28595,57428:28579,57429:28577,57430:28580,57431:28601,57432:28614,57433:28586,57434:28639,57435:28629,57436:28652,57437:28628,57438:28632,57439:28657,57440:28654,57441:28635,57442:28681,57443:28683,57444:28666,57445:28689,57446:28673,57447:28687,57448:28670,57449:28699,57450:28698,57451:28532,57452:28701,57453:28696,57454:28703,57455:28720,57456:28734,57457:28722,57458:28753,57459:28771,57460:28825,57461:28818,57462:28847,57463:28913,57464:28844,57465:28856,57466:28851,57467:28846,57468:28895,57469:28875,57470:28893,57472:28889,57473:28937,57474:28925,57475:28956,57476:28953,57477:29029,57478:29013,57479:29064,57480:29030,57481:29026,57482:29004,57483:29014,57484:29036,57485:29071,57486:29179,57487:29060,57488:29077,57489:29096,57490:29100,57491:29143,57492:29113,57493:29118,57494:29138,57495:29129,57496:29140,57497:29134,57498:29152,57499:29164,57500:29159,57501:29173,57502:29180,57503:29177,57504:29183,57505:29197,57506:29200,57507:29211,57508:29224,57509:29229,57510:29228,57511:29232,57512:29234,57513:29243,57514:29244,57515:29247,57516:29248,57517:29254,57518:29259,57519:29272,57520:29300,57521:29310,57522:29314,57523:29313,57524:29319,57525:29330,57526:29334,57527:29346,57528:29351,57529:29369,57530:29362,57531:29379,57532:29382,57533:29380,57534:29390,57535:29394,57536:29410,57537:29408,57538:29409,57539:29433,57540:29431,57541:20495,57542:29463,57543:29450,57544:29468,57545:29462,57546:29469,57547:29492,57548:29487,57549:29481,57550:29477,57551:29502,57552:29518,57553:29519,57554:40664,57555:29527,57556:29546,57557:29544,57558:29552,57559:29560,57560:29557,57561:29563,57562:29562,57563:29640,57564:29619,57565:29646,57566:29627,57567:29632,57568:29669,57569:29678,57570:29662,57571:29858,57572:29701,57573:29807,57574:29733,57575:29688,57576:29746,57577:29754,57578:29781,57579:29759,57580:29791,57581:29785,57582:29761,57583:29788,57584:29801,57585:29808,57586:29795,57587:29802,57588:29814,57589:29822,57590:29835,57591:29854,57592:29863,57593:29898,57594:29903,57595:29908,57596:29681,57664:29920,57665:29923,57666:29927,57667:29929,57668:29934,57669:29938,57670:29936,57671:29937,57672:29944,57673:29943,57674:29956,57675:29955,57676:29957,57677:29964,57678:29966,57679:29965,57680:29973,57681:29971,57682:29982,57683:29990,57684:29996,57685:30012,57686:30020,57687:30029,57688:30026,57689:30025,57690:30043,57691:30022,57692:30042,57693:30057,57694:30052,57695:30055,57696:30059,57697:30061,57698:30072,57699:30070,57700:30086,57701:30087,57702:30068,57703:30090,57704:30089,57705:30082,57706:30100,57707:30106,57708:30109,57709:30117,57710:30115,57711:30146,57712:30131,57713:30147,57714:30133,57715:30141,57716:30136,57717:30140,57718:30129,57719:30157,57720:30154,57721:30162,57722:30169,57723:30179,57724:30174,57725:30206,57726:30207,57728:30204,57729:30209,57730:30192,57731:30202,57732:30194,57733:30195,57734:30219,57735:30221,57736:30217,57737:30239,57738:30247,57739:30240,57740:30241,57741:30242,57742:30244,57743:30260,57744:30256,57745:30267,57746:30279,57747:30280,57748:30278,57749:30300,57750:30296,57751:30305,57752:30306,57753:30312,57754:30313,57755:30314,57756:30311,57757:30316,57758:30320,57759:30322,57760:30326,57761:30328,57762:30332,57763:30336,57764:30339,57765:30344,57766:30347,57767:30350,57768:30358,57769:30355,57770:30361,57771:30362,57772:30384,57773:30388,57774:30392,57775:30393,57776:30394,57777:30402,57778:30413,57779:30422,57780:30418,57781:30430,57782:30433,57783:30437,57784:30439,57785:30442,57786:34351,57787:30459,57788:30472,57789:30471,57790:30468,57791:30505,57792:30500,57793:30494,57794:30501,57795:30502,57796:30491,57797:30519,57798:30520,57799:30535,57800:30554,57801:30568,57802:30571,57803:30555,57804:30565,57805:30591,57806:30590,57807:30585,57808:30606,57809:30603,57810:30609,57811:30624,57812:30622,57813:30640,57814:30646,57815:30649,57816:30655,57817:30652,57818:30653,57819:30651,57820:30663,57821:30669,57822:30679,57823:30682,57824:30684,57825:30691,57826:30702,57827:30716,57828:30732,57829:30738,57830:31014,57831:30752,57832:31018,57833:30789,57834:30862,57835:30836,57836:30854,57837:30844,57838:30874,57839:30860,57840:30883,57841:30901,57842:30890,57843:30895,57844:30929,57845:30918,57846:30923,57847:30932,57848:30910,57849:30908,57850:30917,57851:30922,57852:30956,57920:30951,57921:30938,57922:30973,57923:30964,57924:30983,57925:30994,57926:30993,57927:31001,57928:31020,57929:31019,57930:31040,57931:31072,57932:31063,57933:31071,57934:31066,57935:31061,57936:31059,57937:31098,57938:31103,57939:31114,57940:31133,57941:31143,57942:40779,57943:31146,57944:31150,57945:31155,57946:31161,57947:31162,57948:31177,57949:31189,57950:31207,57951:31212,57952:31201,57953:31203,57954:31240,57955:31245,57956:31256,57957:31257,57958:31264,57959:31263,57960:31104,57961:31281,57962:31291,57963:31294,57964:31287,57965:31299,57966:31319,57967:31305,57968:31329,57969:31330,57970:31337,57971:40861,57972:31344,57973:31353,57974:31357,57975:31368,57976:31383,57977:31381,57978:31384,57979:31382,57980:31401,57981:31432,57982:31408,57984:31414,57985:31429,57986:31428,57987:31423,57988:36995,57989:31431,57990:31434,57991:31437,57992:31439,57993:31445,57994:31443,57995:31449,57996:31450,57997:31453,57998:31457,57999:31458,58e3:31462,58001:31469,58002:31472,58003:31490,58004:31503,58005:31498,58006:31494,58007:31539,58008:31512,58009:31513,58010:31518,58011:31541,58012:31528,58013:31542,58014:31568,58015:31610,58016:31492,58017:31565,58018:31499,58019:31564,58020:31557,58021:31605,58022:31589,58023:31604,58024:31591,58025:31600,58026:31601,58027:31596,58028:31598,58029:31645,58030:31640,58031:31647,58032:31629,58033:31644,58034:31642,58035:31627,58036:31634,58037:31631,58038:31581,58039:31641,58040:31691,58041:31681,58042:31692,58043:31695,58044:31668,58045:31686,58046:31709,58047:31721,58048:31761,58049:31764,58050:31718,58051:31717,58052:31840,58053:31744,58054:31751,58055:31763,58056:31731,58057:31735,58058:31767,58059:31757,58060:31734,58061:31779,58062:31783,58063:31786,58064:31775,58065:31799,58066:31787,58067:31805,58068:31820,58069:31811,58070:31828,58071:31823,58072:31808,58073:31824,58074:31832,58075:31839,58076:31844,58077:31830,58078:31845,58079:31852,58080:31861,58081:31875,58082:31888,58083:31908,58084:31917,58085:31906,58086:31915,58087:31905,58088:31912,58089:31923,58090:31922,58091:31921,58092:31918,58093:31929,58094:31933,58095:31936,58096:31941,58097:31938,58098:31960,58099:31954,58100:31964,58101:31970,58102:39739,58103:31983,58104:31986,58105:31988,58106:31990,58107:31994,58108:32006,58176:32002,58177:32028,58178:32021,58179:32010,58180:32069,58181:32075,58182:32046,58183:32050,58184:32063,58185:32053,58186:32070,58187:32115,58188:32086,58189:32078,58190:32114,58191:32104,58192:32110,58193:32079,58194:32099,58195:32147,58196:32137,58197:32091,58198:32143,58199:32125,58200:32155,58201:32186,58202:32174,58203:32163,58204:32181,58205:32199,58206:32189,58207:32171,58208:32317,58209:32162,58210:32175,58211:32220,58212:32184,58213:32159,58214:32176,58215:32216,58216:32221,58217:32228,58218:32222,58219:32251,58220:32242,58221:32225,58222:32261,58223:32266,58224:32291,58225:32289,58226:32274,58227:32305,58228:32287,58229:32265,58230:32267,58231:32290,58232:32326,58233:32358,58234:32315,58235:32309,58236:32313,58237:32323,58238:32311,58240:32306,58241:32314,58242:32359,58243:32349,58244:32342,58245:32350,58246:32345,58247:32346,58248:32377,58249:32362,58250:32361,58251:32380,58252:32379,58253:32387,58254:32213,58255:32381,58256:36782,58257:32383,58258:32392,58259:32393,58260:32396,58261:32402,58262:32400,58263:32403,58264:32404,58265:32406,58266:32398,58267:32411,58268:32412,58269:32568,58270:32570,58271:32581,58272:32588,58273:32589,58274:32590,58275:32592,58276:32593,58277:32597,58278:32596,58279:32600,58280:32607,58281:32608,58282:32616,58283:32617,58284:32615,58285:32632,58286:32642,58287:32646,58288:32643,58289:32648,58290:32647,58291:32652,58292:32660,58293:32670,58294:32669,58295:32666,58296:32675,58297:32687,58298:32690,58299:32697,58300:32686,58301:32694,58302:32696,58303:35697,58304:32709,58305:32710,58306:32714,58307:32725,58308:32724,58309:32737,58310:32742,58311:32745,58312:32755,58313:32761,58314:39132,58315:32774,58316:32772,58317:32779,58318:32786,58319:32792,58320:32793,58321:32796,58322:32801,58323:32808,58324:32831,58325:32827,58326:32842,58327:32838,58328:32850,58329:32856,58330:32858,58331:32863,58332:32866,58333:32872,58334:32883,58335:32882,58336:32880,58337:32886,58338:32889,58339:32893,58340:32895,58341:32900,58342:32902,58343:32901,58344:32923,58345:32915,58346:32922,58347:32941,58348:20880,58349:32940,58350:32987,58351:32997,58352:32985,58353:32989,58354:32964,58355:32986,58356:32982,58357:33033,58358:33007,58359:33009,58360:33051,58361:33065,58362:33059,58363:33071,58364:33099,58432:38539,58433:33094,58434:33086,58435:33107,58436:33105,58437:33020,58438:33137,58439:33134,58440:33125,58441:33126,58442:33140,58443:33155,58444:33160,58445:33162,58446:33152,58447:33154,58448:33184,58449:33173,58450:33188,58451:33187,58452:33119,58453:33171,58454:33193,58455:33200,58456:33205,58457:33214,58458:33208,58459:33213,58460:33216,58461:33218,58462:33210,58463:33225,58464:33229,58465:33233,58466:33241,58467:33240,58468:33224,58469:33242,58470:33247,58471:33248,58472:33255,58473:33274,58474:33275,58475:33278,58476:33281,58477:33282,58478:33285,58479:33287,58480:33290,58481:33293,58482:33296,58483:33302,58484:33321,58485:33323,58486:33336,58487:33331,58488:33344,58489:33369,58490:33368,58491:33373,58492:33370,58493:33375,58494:33380,58496:33378,58497:33384,58498:33386,58499:33387,58500:33326,58501:33393,58502:33399,58503:33400,58504:33406,58505:33421,58506:33426,58507:33451,58508:33439,58509:33467,58510:33452,58511:33505,58512:33507,58513:33503,58514:33490,58515:33524,58516:33523,58517:33530,58518:33683,58519:33539,58520:33531,58521:33529,58522:33502,58523:33542,58524:33500,58525:33545,58526:33497,58527:33589,58528:33588,58529:33558,58530:33586,58531:33585,58532:33600,58533:33593,58534:33616,58535:33605,58536:33583,58537:33579,58538:33559,58539:33560,58540:33669,58541:33690,58542:33706,58543:33695,58544:33698,58545:33686,58546:33571,58547:33678,58548:33671,58549:33674,58550:33660,58551:33717,58552:33651,58553:33653,58554:33696,58555:33673,58556:33704,58557:33780,58558:33811,58559:33771,58560:33742,58561:33789,58562:33795,58563:33752,58564:33803,58565:33729,58566:33783,58567:33799,58568:33760,58569:33778,58570:33805,58571:33826,58572:33824,58573:33725,58574:33848,58575:34054,58576:33787,58577:33901,58578:33834,58579:33852,58580:34138,58581:33924,58582:33911,58583:33899,58584:33965,58585:33902,58586:33922,58587:33897,58588:33862,58589:33836,58590:33903,58591:33913,58592:33845,58593:33994,58594:33890,58595:33977,58596:33983,58597:33951,58598:34009,58599:33997,58600:33979,58601:34010,58602:34e3,58603:33985,58604:33990,58605:34006,58606:33953,58607:34081,58608:34047,58609:34036,58610:34071,58611:34072,58612:34092,58613:34079,58614:34069,58615:34068,58616:34044,58617:34112,58618:34147,58619:34136,58620:34120,58688:34113,58689:34306,58690:34123,58691:34133,58692:34176,58693:34212,58694:34184,58695:34193,58696:34186,58697:34216,58698:34157,58699:34196,58700:34203,58701:34282,58702:34183,58703:34204,58704:34167,58705:34174,58706:34192,58707:34249,58708:34234,58709:34255,58710:34233,58711:34256,58712:34261,58713:34269,58714:34277,58715:34268,58716:34297,58717:34314,58718:34323,58719:34315,58720:34302,58721:34298,58722:34310,58723:34338,58724:34330,58725:34352,58726:34367,58727:34381,58728:20053,58729:34388,58730:34399,58731:34407,58732:34417,58733:34451,58734:34467,58735:34473,58736:34474,58737:34443,58738:34444,58739:34486,58740:34479,58741:34500,58742:34502,58743:34480,58744:34505,58745:34851,58746:34475,58747:34516,58748:34526,58749:34537,58750:34540,58752:34527,58753:34523,58754:34543,58755:34578,58756:34566,58757:34568,58758:34560,58759:34563,58760:34555,58761:34577,58762:34569,58763:34573,58764:34553,58765:34570,58766:34612,58767:34623,58768:34615,58769:34619,58770:34597,58771:34601,58772:34586,58773:34656,58774:34655,58775:34680,58776:34636,58777:34638,58778:34676,58779:34647,58780:34664,58781:34670,58782:34649,58783:34643,58784:34659,58785:34666,58786:34821,58787:34722,58788:34719,58789:34690,58790:34735,58791:34763,58792:34749,58793:34752,58794:34768,58795:38614,58796:34731,58797:34756,58798:34739,58799:34759,58800:34758,58801:34747,58802:34799,58803:34802,58804:34784,58805:34831,58806:34829,58807:34814,58808:34806,58809:34807,58810:34830,58811:34770,58812:34833,58813:34838,58814:34837,58815:34850,58816:34849,58817:34865,58818:34870,58819:34873,58820:34855,58821:34875,58822:34884,58823:34882,58824:34898,58825:34905,58826:34910,58827:34914,58828:34923,58829:34945,58830:34942,58831:34974,58832:34933,58833:34941,58834:34997,58835:34930,58836:34946,58837:34967,58838:34962,58839:34990,58840:34969,58841:34978,58842:34957,58843:34980,58844:34992,58845:35007,58846:34993,58847:35011,58848:35012,58849:35028,58850:35032,58851:35033,58852:35037,58853:35065,58854:35074,58855:35068,58856:35060,58857:35048,58858:35058,58859:35076,58860:35084,58861:35082,58862:35091,58863:35139,58864:35102,58865:35109,58866:35114,58867:35115,58868:35137,58869:35140,58870:35131,58871:35126,58872:35128,58873:35148,58874:35101,58875:35168,58876:35166,58944:35174,58945:35172,58946:35181,58947:35178,58948:35183,58949:35188,58950:35191,58951:35198,58952:35203,58953:35208,58954:35210,58955:35219,58956:35224,58957:35233,58958:35241,58959:35238,58960:35244,58961:35247,58962:35250,58963:35258,58964:35261,58965:35263,58966:35264,58967:35290,58968:35292,58969:35293,58970:35303,58971:35316,58972:35320,58973:35331,58974:35350,58975:35344,58976:35340,58977:35355,58978:35357,58979:35365,58980:35382,58981:35393,58982:35419,58983:35410,58984:35398,58985:35400,58986:35452,58987:35437,58988:35436,58989:35426,58990:35461,58991:35458,58992:35460,58993:35496,58994:35489,58995:35473,58996:35493,58997:35494,58998:35482,58999:35491,59e3:35524,59001:35533,59002:35522,59003:35546,59004:35563,59005:35571,59006:35559,59008:35556,59009:35569,59010:35604,59011:35552,59012:35554,59013:35575,59014:35550,59015:35547,59016:35596,59017:35591,59018:35610,59019:35553,59020:35606,59021:35600,59022:35607,59023:35616,59024:35635,59025:38827,59026:35622,59027:35627,59028:35646,59029:35624,59030:35649,59031:35660,59032:35663,59033:35662,59034:35657,59035:35670,59036:35675,59037:35674,59038:35691,59039:35679,59040:35692,59041:35695,59042:35700,59043:35709,59044:35712,59045:35724,59046:35726,59047:35730,59048:35731,59049:35734,59050:35737,59051:35738,59052:35898,59053:35905,59054:35903,59055:35912,59056:35916,59057:35918,59058:35920,59059:35925,59060:35938,59061:35948,59062:35960,59063:35962,59064:35970,59065:35977,59066:35973,59067:35978,59068:35981,59069:35982,59070:35988,59071:35964,59072:35992,59073:25117,59074:36013,59075:36010,59076:36029,59077:36018,59078:36019,59079:36014,59080:36022,59081:36040,59082:36033,59083:36068,59084:36067,59085:36058,59086:36093,59087:36090,59088:36091,59089:36100,59090:36101,59091:36106,59092:36103,59093:36111,59094:36109,59095:36112,59096:40782,59097:36115,59098:36045,59099:36116,59100:36118,59101:36199,59102:36205,59103:36209,59104:36211,59105:36225,59106:36249,59107:36290,59108:36286,59109:36282,59110:36303,59111:36314,59112:36310,59113:36300,59114:36315,59115:36299,59116:36330,59117:36331,59118:36319,59119:36323,59120:36348,59121:36360,59122:36361,59123:36351,59124:36381,59125:36382,59126:36368,59127:36383,59128:36418,59129:36405,59130:36400,59131:36404,59132:36426,59200:36423,59201:36425,59202:36428,59203:36432,59204:36424,59205:36441,59206:36452,59207:36448,59208:36394,59209:36451,59210:36437,59211:36470,59212:36466,59213:36476,59214:36481,59215:36487,59216:36485,59217:36484,59218:36491,59219:36490,59220:36499,59221:36497,59222:36500,59223:36505,59224:36522,59225:36513,59226:36524,59227:36528,59228:36550,59229:36529,59230:36542,59231:36549,59232:36552,59233:36555,59234:36571,59235:36579,59236:36604,59237:36603,59238:36587,59239:36606,59240:36618,59241:36613,59242:36629,59243:36626,59244:36633,59245:36627,59246:36636,59247:36639,59248:36635,59249:36620,59250:36646,59251:36659,59252:36667,59253:36665,59254:36677,59255:36674,59256:36670,59257:36684,59258:36681,59259:36678,59260:36686,59261:36695,59262:36700,59264:36706,59265:36707,59266:36708,59267:36764,59268:36767,59269:36771,59270:36781,59271:36783,59272:36791,59273:36826,59274:36837,59275:36834,59276:36842,59277:36847,59278:36999,59279:36852,59280:36869,59281:36857,59282:36858,59283:36881,59284:36885,59285:36897,59286:36877,59287:36894,59288:36886,59289:36875,59290:36903,59291:36918,59292:36917,59293:36921,59294:36856,59295:36943,59296:36944,59297:36945,59298:36946,59299:36878,59300:36937,59301:36926,59302:36950,59303:36952,59304:36958,59305:36968,59306:36975,59307:36982,59308:38568,59309:36978,59310:36994,59311:36989,59312:36993,59313:36992,59314:37002,59315:37001,59316:37007,59317:37032,59318:37039,59319:37041,59320:37045,59321:37090,59322:37092,59323:25160,59324:37083,59325:37122,59326:37138,59327:37145,59328:37170,59329:37168,59330:37194,59331:37206,59332:37208,59333:37219,59334:37221,59335:37225,59336:37235,59337:37234,59338:37259,59339:37257,59340:37250,59341:37282,59342:37291,59343:37295,59344:37290,59345:37301,59346:37300,59347:37306,59348:37312,59349:37313,59350:37321,59351:37323,59352:37328,59353:37334,59354:37343,59355:37345,59356:37339,59357:37372,59358:37365,59359:37366,59360:37406,59361:37375,59362:37396,59363:37420,59364:37397,59365:37393,59366:37470,59367:37463,59368:37445,59369:37449,59370:37476,59371:37448,59372:37525,59373:37439,59374:37451,59375:37456,59376:37532,59377:37526,59378:37523,59379:37531,59380:37466,59381:37583,59382:37561,59383:37559,59384:37609,59385:37647,59386:37626,59387:37700,59388:37678,59456:37657,59457:37666,59458:37658,59459:37667,59460:37690,59461:37685,59462:37691,59463:37724,59464:37728,59465:37756,59466:37742,59467:37718,59468:37808,59469:37804,59470:37805,59471:37780,59472:37817,59473:37846,59474:37847,59475:37864,59476:37861,59477:37848,59478:37827,59479:37853,59480:37840,59481:37832,59482:37860,59483:37914,59484:37908,59485:37907,59486:37891,59487:37895,59488:37904,59489:37942,59490:37931,59491:37941,59492:37921,59493:37946,59494:37953,59495:37970,59496:37956,59497:37979,59498:37984,59499:37986,59500:37982,59501:37994,59502:37417,59503:38e3,59504:38005,59505:38007,59506:38013,59507:37978,59508:38012,59509:38014,59510:38017,59511:38015,59512:38274,59513:38279,59514:38282,59515:38292,59516:38294,59517:38296,59518:38297,59520:38304,59521:38312,59522:38311,59523:38317,59524:38332,59525:38331,59526:38329,59527:38334,59528:38346,59529:28662,59530:38339,59531:38349,59532:38348,59533:38357,59534:38356,59535:38358,59536:38364,59537:38369,59538:38373,59539:38370,59540:38433,59541:38440,59542:38446,59543:38447,59544:38466,59545:38476,59546:38479,59547:38475,59548:38519,59549:38492,59550:38494,59551:38493,59552:38495,59553:38502,59554:38514,59555:38508,59556:38541,59557:38552,59558:38549,59559:38551,59560:38570,59561:38567,59562:38577,59563:38578,59564:38576,59565:38580,59566:38582,59567:38584,59568:38585,59569:38606,59570:38603,59571:38601,59572:38605,59573:35149,59574:38620,59575:38669,59576:38613,59577:38649,59578:38660,59579:38662,59580:38664,59581:38675,59582:38670,59583:38673,59584:38671,59585:38678,59586:38681,59587:38692,59588:38698,59589:38704,59590:38713,59591:38717,59592:38718,59593:38724,59594:38726,59595:38728,59596:38722,59597:38729,59598:38748,59599:38752,59600:38756,59601:38758,59602:38760,59603:21202,59604:38763,59605:38769,59606:38777,59607:38789,59608:38780,59609:38785,59610:38778,59611:38790,59612:38795,59613:38799,59614:38800,59615:38812,59616:38824,59617:38822,59618:38819,59619:38835,59620:38836,59621:38851,59622:38854,59623:38856,59624:38859,59625:38876,59626:38893,59627:40783,59628:38898,59629:31455,59630:38902,59631:38901,59632:38927,59633:38924,59634:38968,59635:38948,59636:38945,59637:38967,59638:38973,59639:38982,59640:38991,59641:38987,59642:39019,59643:39023,59644:39024,59712:39025,59713:39028,59714:39027,59715:39082,59716:39087,59717:39089,59718:39094,59719:39108,59720:39107,59721:39110,59722:39145,59723:39147,59724:39171,59725:39177,59726:39186,59727:39188,59728:39192,59729:39201,59730:39197,59731:39198,59732:39204,59733:39200,59734:39212,59735:39214,59736:39229,59737:39230,59738:39234,59739:39241,59740:39237,59741:39248,59742:39243,59743:39249,59744:39250,59745:39244,59746:39253,59747:39319,59748:39320,59749:39333,59750:39341,59751:39342,59752:39356,59753:39391,59754:39387,59755:39389,59756:39384,59757:39377,59758:39405,59759:39406,59760:39409,59761:39410,59762:39419,59763:39416,59764:39425,59765:39439,59766:39429,59767:39394,59768:39449,59769:39467,59770:39479,59771:39493,59772:39490,59773:39488,59774:39491,59776:39486,59777:39509,59778:39501,59779:39515,59780:39511,59781:39519,59782:39522,59783:39525,59784:39524,59785:39529,59786:39531,59787:39530,59788:39597,59789:39600,59790:39612,59791:39616,59792:39631,59793:39633,59794:39635,59795:39636,59796:39646,59797:39647,59798:39650,59799:39651,59800:39654,59801:39663,59802:39659,59803:39662,59804:39668,59805:39665,59806:39671,59807:39675,59808:39686,59809:39704,59810:39706,59811:39711,59812:39714,59813:39715,59814:39717,59815:39719,59816:39720,59817:39721,59818:39722,59819:39726,59820:39727,59821:39730,59822:39748,59823:39747,59824:39759,59825:39757,59826:39758,59827:39761,59828:39768,59829:39796,59830:39827,59831:39811,59832:39825,59833:39830,59834:39831,59835:39839,59836:39840,59837:39848,59838:39860,59839:39872,59840:39882,59841:39865,59842:39878,59843:39887,59844:39889,59845:39890,59846:39907,59847:39906,59848:39908,59849:39892,59850:39905,59851:39994,59852:39922,59853:39921,59854:39920,59855:39957,59856:39956,59857:39945,59858:39955,59859:39948,59860:39942,59861:39944,59862:39954,59863:39946,59864:39940,59865:39982,59866:39963,59867:39973,59868:39972,59869:39969,59870:39984,59871:40007,59872:39986,59873:40006,59874:39998,59875:40026,59876:40032,59877:40039,59878:40054,59879:40056,59880:40167,59881:40172,59882:40176,59883:40201,59884:40200,59885:40171,59886:40195,59887:40198,59888:40234,59889:40230,59890:40367,59891:40227,59892:40223,59893:40260,59894:40213,59895:40210,59896:40257,59897:40255,59898:40254,59899:40262,59900:40264,59968:40285,59969:40286,59970:40292,59971:40273,59972:40272,59973:40281,59974:40306,59975:40329,59976:40327,59977:40363,59978:40303,59979:40314,59980:40346,59981:40356,59982:40361,59983:40370,59984:40388,59985:40385,59986:40379,59987:40376,59988:40378,59989:40390,59990:40399,59991:40386,59992:40409,59993:40403,59994:40440,59995:40422,59996:40429,59997:40431,59998:40445,59999:40474,6e4:40475,60001:40478,60002:40565,60003:40569,60004:40573,60005:40577,60006:40584,60007:40587,60008:40588,60009:40594,60010:40597,60011:40593,60012:40605,60013:40613,60014:40617,60015:40632,60016:40618,60017:40621,60018:38753,60019:40652,60020:40654,60021:40655,60022:40656,60023:40660,60024:40668,60025:40670,60026:40669,60027:40672,60028:40677,60029:40680,60030:40687,60032:40692,60033:40694,60034:40695,60035:40697,60036:40699,60037:40700,60038:40701,60039:40711,60040:40712,60041:30391,60042:40725,60043:40737,60044:40748,60045:40766,60046:40778,60047:40786,60048:40788,60049:40803,60050:40799,60051:40800,60052:40801,60053:40806,60054:40807,60055:40812,60056:40810,60057:40823,60058:40818,60059:40822,60060:40853,60061:40860,60062:40864,60063:22575,60064:27079,60065:36953,60066:29796,60067:20956,60068:29081}}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(1),i=n(2);function a(e,t,n,r){var i;t.degree()<n.degree()&&(i=[n,t],t=i[0],n=i[1]);for(var a=t,o=n,s=e.zero,c=e.one;o.degree()>=r/2;){var l=a,u=s;if(a=o,s=c,a.isZero())return null;o=l;for(var d=e.zero,f=a.getCoefficient(a.degree()),p=e.inverse(f);o.degree()>=a.degree()&&!o.isZero();){var m=o.degree()-a.degree(),h=e.multiply(o.getCoefficient(o.degree()),p);d=d.addOrSubtract(e.buildMonomial(m,h)),o=o.addOrSubtract(a.multiplyByMonomial(m,h))}if(c=d.multiplyPoly(s).addOrSubtract(u),o.degree()>=a.degree())return null}var g=c.getCoefficient(0);if(g===0)return null;var _=e.inverse(g);return[c.multiply(_),o.multiply(_)]}function o(e,t){var n=t.degree();if(n===1)return[t.getCoefficient(1)];for(var r=Array(n),i=0,a=1;a<e.size&&i<n;a++)t.evaluateAt(a)===0&&(r[i]=e.inverse(a),i++);return i===n?r:null}function s(e,t,n){for(var i=n.length,a=Array(i),o=0;o<i;o++){for(var s=e.inverse(n[o]),c=1,l=0;l<i;l++)o!==l&&(c=e.multiply(c,r.addOrSubtractGF(1,e.multiply(n[l],s))));a[o]=e.multiply(t.evaluateAt(s),e.inverse(c)),e.generatorBase!==0&&(a[o]=e.multiply(a[o],s))}return a}function c(e,t){var n=new Uint8ClampedArray(e.length);n.set(e);for(var c=new r.default(285,256,0),l=new i.default(c,n),u=new Uint8ClampedArray(t),d=!1,f=0;f<t;f++){var p=l.evaluateAt(c.exp(f+c.generatorBase));u[u.length-1-f]=p,p!==0&&(d=!0)}if(!d)return n;var m=new i.default(c,u),h=a(c,c.buildMonomial(t,1),m,t);if(h===null)return null;var g=o(c,h[0]);if(g==null)return null;for(var _=s(c,h[1],g),v=0;v<g.length;v++){var y=n.length-1-c.log(g[v]);if(y<0)return null;n[y]=r.addOrSubtractGF(n[y],_[v])}return n}t.decode=c}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.VERSIONS=[{infoBits:null,versionNumber:1,alignmentPatternCenters:[],errorCorrectionLevels:[{ecCodewordsPerBlock:7,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:19}]},{ecCodewordsPerBlock:10,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:16}]},{ecCodewordsPerBlock:13,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:13}]},{ecCodewordsPerBlock:17,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:9}]}]},{infoBits:null,versionNumber:2,alignmentPatternCenters:[6,18],errorCorrectionLevels:[{ecCodewordsPerBlock:10,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:34}]},{ecCodewordsPerBlock:16,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:28}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:22}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:16}]}]},{infoBits:null,versionNumber:3,alignmentPatternCenters:[6,22],errorCorrectionLevels:[{ecCodewordsPerBlock:15,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:55}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:44}]},{ecCodewordsPerBlock:18,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:17}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:13}]}]},{infoBits:null,versionNumber:4,alignmentPatternCenters:[6,26],errorCorrectionLevels:[{ecCodewordsPerBlock:20,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:80}]},{ecCodewordsPerBlock:18,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:32}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:24}]},{ecCodewordsPerBlock:16,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:9}]}]},{infoBits:null,versionNumber:5,alignmentPatternCenters:[6,30],errorCorrectionLevels:[{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:108}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:43}]},{ecCodewordsPerBlock:18,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:15},{numBlocks:2,dataCodewordsPerBlock:16}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:11},{numBlocks:2,dataCodewordsPerBlock:12}]}]},{infoBits:null,versionNumber:6,alignmentPatternCenters:[6,34],errorCorrectionLevels:[{ecCodewordsPerBlock:18,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:68}]},{ecCodewordsPerBlock:16,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:27}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:19}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:15}]}]},{infoBits:31892,versionNumber:7,alignmentPatternCenters:[6,22,38],errorCorrectionLevels:[{ecCodewordsPerBlock:20,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:78}]},{ecCodewordsPerBlock:18,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:31}]},{ecCodewordsPerBlock:18,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:14},{numBlocks:4,dataCodewordsPerBlock:15}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:13},{numBlocks:1,dataCodewordsPerBlock:14}]}]},{infoBits:34236,versionNumber:8,alignmentPatternCenters:[6,24,42],errorCorrectionLevels:[{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:97}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:38},{numBlocks:2,dataCodewordsPerBlock:39}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:18},{numBlocks:2,dataCodewordsPerBlock:19}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:14},{numBlocks:2,dataCodewordsPerBlock:15}]}]},{infoBits:39577,versionNumber:9,alignmentPatternCenters:[6,26,46],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:116}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:36},{numBlocks:2,dataCodewordsPerBlock:37}]},{ecCodewordsPerBlock:20,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:16},{numBlocks:4,dataCodewordsPerBlock:17}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:12},{numBlocks:4,dataCodewordsPerBlock:13}]}]},{infoBits:42195,versionNumber:10,alignmentPatternCenters:[6,28,50],errorCorrectionLevels:[{ecCodewordsPerBlock:18,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:68},{numBlocks:2,dataCodewordsPerBlock:69}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:43},{numBlocks:1,dataCodewordsPerBlock:44}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:6,dataCodewordsPerBlock:19},{numBlocks:2,dataCodewordsPerBlock:20}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:6,dataCodewordsPerBlock:15},{numBlocks:2,dataCodewordsPerBlock:16}]}]},{infoBits:48118,versionNumber:11,alignmentPatternCenters:[6,30,54],errorCorrectionLevels:[{ecCodewordsPerBlock:20,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:81}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:50},{numBlocks:4,dataCodewordsPerBlock:51}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:22},{numBlocks:4,dataCodewordsPerBlock:23}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:12},{numBlocks:8,dataCodewordsPerBlock:13}]}]},{infoBits:51042,versionNumber:12,alignmentPatternCenters:[6,32,58],errorCorrectionLevels:[{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:92},{numBlocks:2,dataCodewordsPerBlock:93}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:6,dataCodewordsPerBlock:36},{numBlocks:2,dataCodewordsPerBlock:37}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:20},{numBlocks:6,dataCodewordsPerBlock:21}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:7,dataCodewordsPerBlock:14},{numBlocks:4,dataCodewordsPerBlock:15}]}]},{infoBits:55367,versionNumber:13,alignmentPatternCenters:[6,34,62],errorCorrectionLevels:[{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:107}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:8,dataCodewordsPerBlock:37},{numBlocks:1,dataCodewordsPerBlock:38}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:8,dataCodewordsPerBlock:20},{numBlocks:4,dataCodewordsPerBlock:21}]},{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:12,dataCodewordsPerBlock:11},{numBlocks:4,dataCodewordsPerBlock:12}]}]},{infoBits:58893,versionNumber:14,alignmentPatternCenters:[6,26,46,66],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:115},{numBlocks:1,dataCodewordsPerBlock:116}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:40},{numBlocks:5,dataCodewordsPerBlock:41}]},{ecCodewordsPerBlock:20,ecBlocks:[{numBlocks:11,dataCodewordsPerBlock:16},{numBlocks:5,dataCodewordsPerBlock:17}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:11,dataCodewordsPerBlock:12},{numBlocks:5,dataCodewordsPerBlock:13}]}]},{infoBits:63784,versionNumber:15,alignmentPatternCenters:[6,26,48,70],errorCorrectionLevels:[{ecCodewordsPerBlock:22,ecBlocks:[{numBlocks:5,dataCodewordsPerBlock:87},{numBlocks:1,dataCodewordsPerBlock:88}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:5,dataCodewordsPerBlock:41},{numBlocks:5,dataCodewordsPerBlock:42}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:5,dataCodewordsPerBlock:24},{numBlocks:7,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:11,dataCodewordsPerBlock:12},{numBlocks:7,dataCodewordsPerBlock:13}]}]},{infoBits:68472,versionNumber:16,alignmentPatternCenters:[6,26,50,74],errorCorrectionLevels:[{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:5,dataCodewordsPerBlock:98},{numBlocks:1,dataCodewordsPerBlock:99}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:7,dataCodewordsPerBlock:45},{numBlocks:3,dataCodewordsPerBlock:46}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:15,dataCodewordsPerBlock:19},{numBlocks:2,dataCodewordsPerBlock:20}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:15},{numBlocks:13,dataCodewordsPerBlock:16}]}]},{infoBits:70749,versionNumber:17,alignmentPatternCenters:[6,30,54,78],errorCorrectionLevels:[{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:107},{numBlocks:5,dataCodewordsPerBlock:108}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:10,dataCodewordsPerBlock:46},{numBlocks:1,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:22},{numBlocks:15,dataCodewordsPerBlock:23}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:14},{numBlocks:17,dataCodewordsPerBlock:15}]}]},{infoBits:76311,versionNumber:18,alignmentPatternCenters:[6,30,56,82],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:5,dataCodewordsPerBlock:120},{numBlocks:1,dataCodewordsPerBlock:121}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:9,dataCodewordsPerBlock:43},{numBlocks:4,dataCodewordsPerBlock:44}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:22},{numBlocks:1,dataCodewordsPerBlock:23}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:14},{numBlocks:19,dataCodewordsPerBlock:15}]}]},{infoBits:79154,versionNumber:19,alignmentPatternCenters:[6,30,58,86],errorCorrectionLevels:[{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:113},{numBlocks:4,dataCodewordsPerBlock:114}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:44},{numBlocks:11,dataCodewordsPerBlock:45}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:21},{numBlocks:4,dataCodewordsPerBlock:22}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:9,dataCodewordsPerBlock:13},{numBlocks:16,dataCodewordsPerBlock:14}]}]},{infoBits:84390,versionNumber:20,alignmentPatternCenters:[6,34,62,90],errorCorrectionLevels:[{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:107},{numBlocks:5,dataCodewordsPerBlock:108}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:41},{numBlocks:13,dataCodewordsPerBlock:42}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:15,dataCodewordsPerBlock:24},{numBlocks:5,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:15,dataCodewordsPerBlock:15},{numBlocks:10,dataCodewordsPerBlock:16}]}]},{infoBits:87683,versionNumber:21,alignmentPatternCenters:[6,28,50,72,94],errorCorrectionLevels:[{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:116},{numBlocks:4,dataCodewordsPerBlock:117}]},{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:42}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:22},{numBlocks:6,dataCodewordsPerBlock:23}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:19,dataCodewordsPerBlock:16},{numBlocks:6,dataCodewordsPerBlock:17}]}]},{infoBits:92361,versionNumber:22,alignmentPatternCenters:[6,26,50,74,98],errorCorrectionLevels:[{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:111},{numBlocks:7,dataCodewordsPerBlock:112}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:46}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:7,dataCodewordsPerBlock:24},{numBlocks:16,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:24,ecBlocks:[{numBlocks:34,dataCodewordsPerBlock:13}]}]},{infoBits:96236,versionNumber:23,alignmentPatternCenters:[6,30,54,74,102],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:121},{numBlocks:5,dataCodewordsPerBlock:122}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:47},{numBlocks:14,dataCodewordsPerBlock:48}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:11,dataCodewordsPerBlock:24},{numBlocks:14,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:16,dataCodewordsPerBlock:15},{numBlocks:14,dataCodewordsPerBlock:16}]}]},{infoBits:102084,versionNumber:24,alignmentPatternCenters:[6,28,54,80,106],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:6,dataCodewordsPerBlock:117},{numBlocks:4,dataCodewordsPerBlock:118}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:6,dataCodewordsPerBlock:45},{numBlocks:14,dataCodewordsPerBlock:46}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:11,dataCodewordsPerBlock:24},{numBlocks:16,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:30,dataCodewordsPerBlock:16},{numBlocks:2,dataCodewordsPerBlock:17}]}]},{infoBits:102881,versionNumber:25,alignmentPatternCenters:[6,32,58,84,110],errorCorrectionLevels:[{ecCodewordsPerBlock:26,ecBlocks:[{numBlocks:8,dataCodewordsPerBlock:106},{numBlocks:4,dataCodewordsPerBlock:107}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:8,dataCodewordsPerBlock:47},{numBlocks:13,dataCodewordsPerBlock:48}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:7,dataCodewordsPerBlock:24},{numBlocks:22,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:22,dataCodewordsPerBlock:15},{numBlocks:13,dataCodewordsPerBlock:16}]}]},{infoBits:110507,versionNumber:26,alignmentPatternCenters:[6,30,58,86,114],errorCorrectionLevels:[{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:10,dataCodewordsPerBlock:114},{numBlocks:2,dataCodewordsPerBlock:115}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:19,dataCodewordsPerBlock:46},{numBlocks:4,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:28,dataCodewordsPerBlock:22},{numBlocks:6,dataCodewordsPerBlock:23}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:33,dataCodewordsPerBlock:16},{numBlocks:4,dataCodewordsPerBlock:17}]}]},{infoBits:110734,versionNumber:27,alignmentPatternCenters:[6,34,62,90,118],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:8,dataCodewordsPerBlock:122},{numBlocks:4,dataCodewordsPerBlock:123}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:22,dataCodewordsPerBlock:45},{numBlocks:3,dataCodewordsPerBlock:46}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:8,dataCodewordsPerBlock:23},{numBlocks:26,dataCodewordsPerBlock:24}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:12,dataCodewordsPerBlock:15},{numBlocks:28,dataCodewordsPerBlock:16}]}]},{infoBits:117786,versionNumber:28,alignmentPatternCenters:[6,26,50,74,98,122],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:117},{numBlocks:10,dataCodewordsPerBlock:118}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:3,dataCodewordsPerBlock:45},{numBlocks:23,dataCodewordsPerBlock:46}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:24},{numBlocks:31,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:11,dataCodewordsPerBlock:15},{numBlocks:31,dataCodewordsPerBlock:16}]}]},{infoBits:119615,versionNumber:29,alignmentPatternCenters:[6,30,54,78,102,126],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:7,dataCodewordsPerBlock:116},{numBlocks:7,dataCodewordsPerBlock:117}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:21,dataCodewordsPerBlock:45},{numBlocks:7,dataCodewordsPerBlock:46}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:1,dataCodewordsPerBlock:23},{numBlocks:37,dataCodewordsPerBlock:24}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:19,dataCodewordsPerBlock:15},{numBlocks:26,dataCodewordsPerBlock:16}]}]},{infoBits:126325,versionNumber:30,alignmentPatternCenters:[6,26,52,78,104,130],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:5,dataCodewordsPerBlock:115},{numBlocks:10,dataCodewordsPerBlock:116}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:19,dataCodewordsPerBlock:47},{numBlocks:10,dataCodewordsPerBlock:48}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:15,dataCodewordsPerBlock:24},{numBlocks:25,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:23,dataCodewordsPerBlock:15},{numBlocks:25,dataCodewordsPerBlock:16}]}]},{infoBits:127568,versionNumber:31,alignmentPatternCenters:[6,30,56,82,108,134],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:13,dataCodewordsPerBlock:115},{numBlocks:3,dataCodewordsPerBlock:116}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:46},{numBlocks:29,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:42,dataCodewordsPerBlock:24},{numBlocks:1,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:23,dataCodewordsPerBlock:15},{numBlocks:28,dataCodewordsPerBlock:16}]}]},{infoBits:133589,versionNumber:32,alignmentPatternCenters:[6,34,60,86,112,138],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:115}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:10,dataCodewordsPerBlock:46},{numBlocks:23,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:10,dataCodewordsPerBlock:24},{numBlocks:35,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:19,dataCodewordsPerBlock:15},{numBlocks:35,dataCodewordsPerBlock:16}]}]},{infoBits:136944,versionNumber:33,alignmentPatternCenters:[6,30,58,86,114,142],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:115},{numBlocks:1,dataCodewordsPerBlock:116}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:14,dataCodewordsPerBlock:46},{numBlocks:21,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:29,dataCodewordsPerBlock:24},{numBlocks:19,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:11,dataCodewordsPerBlock:15},{numBlocks:46,dataCodewordsPerBlock:16}]}]},{infoBits:141498,versionNumber:34,alignmentPatternCenters:[6,34,62,90,118,146],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:13,dataCodewordsPerBlock:115},{numBlocks:6,dataCodewordsPerBlock:116}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:14,dataCodewordsPerBlock:46},{numBlocks:23,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:44,dataCodewordsPerBlock:24},{numBlocks:7,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:59,dataCodewordsPerBlock:16},{numBlocks:1,dataCodewordsPerBlock:17}]}]},{infoBits:145311,versionNumber:35,alignmentPatternCenters:[6,30,54,78,102,126,150],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:12,dataCodewordsPerBlock:121},{numBlocks:7,dataCodewordsPerBlock:122}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:12,dataCodewordsPerBlock:47},{numBlocks:26,dataCodewordsPerBlock:48}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:39,dataCodewordsPerBlock:24},{numBlocks:14,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:22,dataCodewordsPerBlock:15},{numBlocks:41,dataCodewordsPerBlock:16}]}]},{infoBits:150283,versionNumber:36,alignmentPatternCenters:[6,24,50,76,102,128,154],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:6,dataCodewordsPerBlock:121},{numBlocks:14,dataCodewordsPerBlock:122}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:6,dataCodewordsPerBlock:47},{numBlocks:34,dataCodewordsPerBlock:48}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:46,dataCodewordsPerBlock:24},{numBlocks:10,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:2,dataCodewordsPerBlock:15},{numBlocks:64,dataCodewordsPerBlock:16}]}]},{infoBits:152622,versionNumber:37,alignmentPatternCenters:[6,28,54,80,106,132,158],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:17,dataCodewordsPerBlock:122},{numBlocks:4,dataCodewordsPerBlock:123}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:29,dataCodewordsPerBlock:46},{numBlocks:14,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:49,dataCodewordsPerBlock:24},{numBlocks:10,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:24,dataCodewordsPerBlock:15},{numBlocks:46,dataCodewordsPerBlock:16}]}]},{infoBits:158308,versionNumber:38,alignmentPatternCenters:[6,32,58,84,110,136,162],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:4,dataCodewordsPerBlock:122},{numBlocks:18,dataCodewordsPerBlock:123}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:13,dataCodewordsPerBlock:46},{numBlocks:32,dataCodewordsPerBlock:47}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:48,dataCodewordsPerBlock:24},{numBlocks:14,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:42,dataCodewordsPerBlock:15},{numBlocks:32,dataCodewordsPerBlock:16}]}]},{infoBits:161089,versionNumber:39,alignmentPatternCenters:[6,26,54,82,110,138,166],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:20,dataCodewordsPerBlock:117},{numBlocks:4,dataCodewordsPerBlock:118}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:40,dataCodewordsPerBlock:47},{numBlocks:7,dataCodewordsPerBlock:48}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:43,dataCodewordsPerBlock:24},{numBlocks:22,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:10,dataCodewordsPerBlock:15},{numBlocks:67,dataCodewordsPerBlock:16}]}]},{infoBits:167017,versionNumber:40,alignmentPatternCenters:[6,30,58,86,114,142,170],errorCorrectionLevels:[{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:19,dataCodewordsPerBlock:118},{numBlocks:6,dataCodewordsPerBlock:119}]},{ecCodewordsPerBlock:28,ecBlocks:[{numBlocks:18,dataCodewordsPerBlock:47},{numBlocks:31,dataCodewordsPerBlock:48}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:34,dataCodewordsPerBlock:24},{numBlocks:34,dataCodewordsPerBlock:25}]},{ecCodewordsPerBlock:30,ecBlocks:[{numBlocks:20,dataCodewordsPerBlock:15},{numBlocks:61,dataCodewordsPerBlock:16}]}]}]}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(0);function i(e,t,n,r){var i=e.x-t.x+n.x-r.x,a=e.y-t.y+n.y-r.y;if(i===0&&a===0)return{a11:t.x-e.x,a12:t.y-e.y,a13:0,a21:n.x-t.x,a22:n.y-t.y,a23:0,a31:e.x,a32:e.y,a33:1};var o=t.x-n.x,s=r.x-n.x,c=t.y-n.y,l=r.y-n.y,u=o*l-s*c,d=(i*l-s*a)/u,f=(o*a-i*c)/u;return{a11:t.x-e.x+d*t.x,a12:t.y-e.y+d*t.y,a13:d,a21:r.x-e.x+f*r.x,a22:r.y-e.y+f*r.y,a23:f,a31:e.x,a32:e.y,a33:1}}function a(e,t,n,r){var a=i(e,t,n,r);return{a11:a.a22*a.a33-a.a23*a.a32,a12:a.a13*a.a32-a.a12*a.a33,a13:a.a12*a.a23-a.a13*a.a22,a21:a.a23*a.a31-a.a21*a.a33,a22:a.a11*a.a33-a.a13*a.a31,a23:a.a13*a.a21-a.a11*a.a23,a31:a.a21*a.a32-a.a22*a.a31,a32:a.a12*a.a31-a.a11*a.a32,a33:a.a11*a.a22-a.a12*a.a21}}function o(e,t){return{a11:e.a11*t.a11+e.a21*t.a12+e.a31*t.a13,a12:e.a12*t.a11+e.a22*t.a12+e.a32*t.a13,a13:e.a13*t.a11+e.a23*t.a12+e.a33*t.a13,a21:e.a11*t.a21+e.a21*t.a22+e.a31*t.a23,a22:e.a12*t.a21+e.a22*t.a22+e.a32*t.a23,a23:e.a13*t.a21+e.a23*t.a22+e.a33*t.a23,a31:e.a11*t.a31+e.a21*t.a32+e.a31*t.a33,a32:e.a12*t.a31+e.a22*t.a32+e.a32*t.a33,a33:e.a13*t.a31+e.a23*t.a32+e.a33*t.a33}}function s(e,t){for(var n=a({x:3.5,y:3.5},{x:t.dimension-3.5,y:3.5},{x:t.dimension-6.5,y:t.dimension-6.5},{x:3.5,y:t.dimension-3.5}),s=o(i(t.topLeft,t.topRight,t.alignmentPattern,t.bottomLeft),n),c=r.BitMatrix.createEmpty(t.dimension,t.dimension),l=function(e,t){var n=s.a13*e+s.a23*t+s.a33;return{x:(s.a11*e+s.a21*t+s.a31)/n,y:(s.a12*e+s.a22*t+s.a32)/n}},u=0;u<t.dimension;u++)for(var d=0;d<t.dimension;d++){var f=l(d+.5,u+.5);c.set(d,u,e.get(Math.floor(f.x),Math.floor(f.y)))}return{matrix:c,mappingFunction:l}}t.extract=s}),(function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=4,i=.5,a=1.5,o=function(e,t){return Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2)};function s(e){return e.reduce(function(e,t){return e+t})}function c(e,t,n){var r,i,a,s,c=o(e,t),l=o(t,n),u=o(e,n),d,f,p;return l>=c&&l>=u?(r=[t,e,n],d=r[0],f=r[1],p=r[2]):u>=l&&u>=c?(i=[e,t,n],d=i[0],f=i[1],p=i[2]):(a=[e,n,t],d=a[0],f=a[1],p=a[2]),(p.x-f.x)*(d.y-f.y)-(p.y-f.y)*(d.x-f.x)<0&&(s=[p,d],d=s[0],p=s[1]),{bottomLeft:d,topLeft:f,topRight:p}}function l(e,t,n,r){var i=(s(d(e,n,r,5))/7+s(d(e,t,r,5))/7+s(d(n,e,r,5))/7+s(d(t,e,r,5))/7)/4;if(i<1)throw Error(`Invalid module size`);var a=Math.round(o(e,t)/i),c=Math.round(o(e,n)/i),l=Math.floor((a+c)/2)+7;switch(l%4){case 0:l++;break;case 2:l--;break}return{dimension:l,moduleSize:i}}function u(e,t,n,r){var i=[{x:Math.floor(e.x),y:Math.floor(e.y)}],a=Math.abs(t.y-e.y)>Math.abs(t.x-e.x),s,c,l,u;a?(s=Math.floor(e.y),c=Math.floor(e.x),l=Math.floor(t.y),u=Math.floor(t.x)):(s=Math.floor(e.x),c=Math.floor(e.y),l=Math.floor(t.x),u=Math.floor(t.y));for(var d=Math.abs(l-s),f=Math.abs(u-c),p=Math.floor(-d/2),m=s<l?1:-1,h=c<u?1:-1,g=!0,_=s,v=c;_!==l+m;_+=m){var y=a?v:_,b=a?_:v;if(n.get(y,b)!==g&&(g=!g,i.push({x:y,y:b}),i.length===r+1))break;if(p+=f,p>0){if(v===u)break;v+=h,p-=d}}for(var x=[],S=0;S<r;S++)i[S]&&i[S+1]?x.push(o(i[S],i[S+1])):x.push(0);return x}function d(e,t,n,r){var i,a=t.y-e.y,o=t.x-e.x,s=u(e,t,n,Math.ceil(r/2)),c=u(e,{x:e.x-o,y:e.y-a},n,Math.ceil(r/2)),l=s.shift()+c.shift()-1;return(i=c.concat(l)).concat.apply(i,s)}function f(e,t){var n=s(e)/s(t),r=0;return t.forEach(function(t,i){r+=(e[i]-t*n)**2}),{averageSize:n,error:r}}function p(e,t,n){try{var r=d(e,{x:-1,y:e.y},n,t.length),i=d(e,{x:e.x,y:-1},n,t.length),a=d(e,{x:Math.max(0,e.x-e.y)-1,y:Math.max(0,e.y-e.x)-1},n,t.length),o=d(e,{x:Math.min(n.width,e.x+e.y)+1,y:Math.min(n.height,e.y+e.x)+1},n,t.length),s=f(r,t),c=f(i,t),l=f(a,t),u=f(o,t),p=Math.sqrt(s.error*s.error+c.error*c.error+l.error*l.error+u.error*u.error),m=(s.averageSize+c.averageSize+l.averageSize+u.averageSize)/4;return p+((s.averageSize-m)**2+(c.averageSize-m)**2+(l.averageSize-m)**2+(u.averageSize-m)**2)/m}catch{return 1/0}}function m(e,t){for(var n=Math.round(t.x);e.get(n,Math.round(t.y));)n--;for(var r=Math.round(t.x);e.get(r,Math.round(t.y));)r++;for(var i=(n+r)/2,a=Math.round(t.y);e.get(Math.round(i),a);)a--;for(var o=Math.round(t.y);e.get(Math.round(i),o);)o++;return{x:i,y:(a+o)/2}}function h(e){for(var t=[],n=[],o=[],l=[],u=function(r){for(var c=0,u=!1,d=[0,0,0,0,0],f=function(t){var o=e.get(t,r);if(o===u)c++;else{d=[d[1],d[2],d[3],d[4],c],c=1,u=o;var f=s(d)/7,p=Math.abs(d[0]-f)<f&&Math.abs(d[1]-f)<f&&Math.abs(d[2]-3*f)<3*f&&Math.abs(d[3]-f)<f&&Math.abs(d[4]-f)<f&&!o,m=s(d.slice(-3))/3,h=Math.abs(d[2]-m)<m&&Math.abs(d[3]-m)<m&&Math.abs(d[4]-m)<m&&o;if(p){var g=t-d[3]-d[4],_=g-d[2],v={startX:_,endX:g,y:r},y=n.filter(function(e){return _>=e.bottom.startX&&_<=e.bottom.endX||g>=e.bottom.startX&&_<=e.bottom.endX||_<=e.bottom.startX&&g>=e.bottom.endX&&d[2]/(e.bottom.endX-e.bottom.startX)<a&&d[2]/(e.bottom.endX-e.bottom.startX)>i});y.length>0?y[0].bottom=v:n.push({top:v,bottom:v})}if(h){var b=t-d[4],x=b-d[3],v={startX:x,y:r,endX:b},y=l.filter(function(e){return x>=e.bottom.startX&&x<=e.bottom.endX||b>=e.bottom.startX&&x<=e.bottom.endX||x<=e.bottom.startX&&b>=e.bottom.endX&&d[2]/(e.bottom.endX-e.bottom.startX)<a&&d[2]/(e.bottom.endX-e.bottom.startX)>i});y.length>0?y[0].bottom=v:l.push({top:v,bottom:v})}}},p=-1;p<=e.width;p++)f(p);t.push.apply(t,n.filter(function(e){return e.bottom.y!==r&&e.bottom.y-e.top.y>=2})),n=n.filter(function(e){return e.bottom.y===r}),o.push.apply(o,l.filter(function(e){return e.bottom.y!==r})),l=l.filter(function(e){return e.bottom.y===r})},d=0;d<=e.height;d++)u(d);t.push.apply(t,n.filter(function(e){return e.bottom.y-e.top.y>=2})),o.push.apply(o,l);var f=t.filter(function(e){return e.bottom.y-e.top.y>=2}).map(function(t){var n=(t.top.startX+t.top.endX+t.bottom.startX+t.bottom.endX)/4,r=(t.top.y+t.bottom.y+1)/2;if(e.get(Math.round(n),Math.round(r))){var i=[t.top.endX-t.top.startX,t.bottom.endX-t.bottom.startX,t.bottom.y-t.top.y+1],a=s(i)/i.length;return{score:p({x:Math.round(n),y:Math.round(r)},[1,1,3,1,1],e),x:n,y:r,size:a}}}).filter(function(e){return!!e}).sort(function(e,t){return e.score-t.score}).map(function(e,t,n){if(t>r)return null;var i=n.filter(function(e,n){return t!==n}).map(function(t){return{x:t.x,y:t.y,score:t.score+(t.size-e.size)**2/e.size,size:t.size}}).sort(function(e,t){return e.score-t.score});if(i.length<2)return null;var a=e.score+i[0].score+i[1].score;return{points:[e].concat(i.slice(0,2)),score:a}}).filter(function(e){return!!e}).sort(function(e,t){return e.score-t.score});if(f.length===0)return null;var h=c(f[0].points[0],f[0].points[1],f[0].points[2]),_=h.topRight,v=h.topLeft,y=h.bottomLeft,b=g(e,o,_,v,y),x=[];b&&x.push({alignmentPattern:{x:b.alignmentPattern.x,y:b.alignmentPattern.y},bottomLeft:{x:y.x,y:y.y},dimension:b.dimension,topLeft:{x:v.x,y:v.y},topRight:{x:_.x,y:_.y}});var S=m(e,_),C=m(e,v),w=m(e,y),T=g(e,o,S,C,w);return T&&x.push({alignmentPattern:{x:T.alignmentPattern.x,y:T.alignmentPattern.y},bottomLeft:{x:w.x,y:w.y},topLeft:{x:C.x,y:C.y},topRight:{x:S.x,y:S.y},dimension:T.dimension}),x.length===0?null:x}t.locate=h;function g(e,t,n,r,i){var a,c,u;try{a=l(r,n,i,e),c=a.dimension,u=a.moduleSize}catch{return null}var d={x:n.x-r.x+i.x,y:n.y-r.y+i.y},f=(o(r,i)+o(r,n))/2/u,m=1-3/f,h={x:r.x+m*(d.x-r.x),y:r.y+m*(d.y-r.y)},g=t.map(function(t){var n=(t.top.startX+t.top.endX+t.bottom.startX+t.bottom.endX)/4,r=(t.top.y+t.bottom.y+1)/2;if(e.get(Math.floor(n),Math.floor(r))){var i=[t.top.endX-t.top.startX,t.bottom.endX-t.bottom.startX,t.bottom.y-t.top.y+1];return s(i)/i.length,{x:n,y:r,score:p({x:Math.floor(n),y:Math.floor(r)},[1,1,1],e)+o({x:n,y:r},h)}}}).filter(function(e){return!!e}).sort(function(e,t){return e.score-t.score});return{alignmentPattern:f>=15&&g.length?g[0]:h,dimension:c}}})]).default})}))(),1);function kq(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function Aq(e){let t=e.length%4,n=(e+(t?`=`.repeat(4-t):``)).replace(/-/g,`+`).replace(/_/g,`/`),r=atob(n),i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return i}async function jq(e,t){let n=t.writable.getWriter();n.write(e),n.close();let r=t.readable.getReader(),i=[],a=0;for(;;){let{value:e,done:t}=await r.read();if(t)break;e&&(i.push(e),a+=e.length)}let o=new Uint8Array(a),s=0;for(let e of i)o.set(e,s),s+=e.length;return o}async function Mq(e){let t=new TextEncoder().encode(e),n=await jq(t,new CompressionStream(`deflate-raw`));return n.length<t.length?`D`+kq(n):`R`+kq(t)}async function Nq(e){let t=e.trim();if(!t)throw Error(`empty signal token`);let n=Aq(t.slice(1));if(t[0]===`D`)return new TextDecoder().decode(await jq(n,new DecompressionStream(`deflate-raw`)));if(t[0]===`R`)return new TextDecoder().decode(n);throw Error(`unknown signal codec tag: ${t[0]}`)}async function Pq(e){return Mq(JSON.stringify({k:`offer`,v:2,hub:e.hubInstanceId,name:e.hubName,sdp:e.sdp,sec:e.secret,language:e.language}))}async function Fq(e){try{let t=JSON.parse(await Nq(e.trim()));return t.k!==`answer`||typeof t.sdp!=`string`?null:{sdp:t.sdp,deviceName:typeof t.dev==`string`?t.dev:`Mobile device`,platform:typeof t.plat==`string`?t.plat:`web`,secret:typeof t.sec==`string`?t.sec:``}}catch{return null}}function Iq({open:e,onClose:t,onPaired:n}){let{t:r}=K(`settings`),[i,a]=(0,Q.useState)(`loading`),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(null),u=(0,Q.useRef)(null),d=(0,Q.useRef)(null),f=(0,Q.useRef)(null),p=(0,Q.useCallback)(()=>{f.current!=null&&(cancelAnimationFrame(f.current),f.current=null),d.current?.getTracks().forEach(e=>e.stop()),d.current=null},[]),m=(0,Q.useCallback)(()=>{p(),a(`loading`),s(``),l(null),t()},[t,p]),h=(0,Q.useCallback)(async e=>{let t=await Fq(e);if(!t){J.error(r(`pairWeb.notAnswer`));return}p(),a(`connecting`);try{let e=await fetch(`/api/mobile/webrtc/answer`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sdp:t.sdp})}),i=await e.json().catch(()=>({}));if(!e.ok||!i.ok)throw Error(`rejected`);a(`paired`),J.success(r(`pairWeb.pairedToast`)),n();let o=0,s=setInterval(()=>{n(),++o>=3&&(clearInterval(s),m())},1500)}catch{l(r(`pairWeb.answerRejected`)),a(`offer`)}},[r,p,n,m]);(0,Q.useEffect)(()=>{if(!e)return;let t=!1;return l(null),a(`loading`),(async()=>{try{let e=await fetch(`/api/mobile/webrtc/offer`,{method:`POST`});if(!e.ok)throw Error(`HTTP ${e.status}`);let n=await e.json(),r=await Pq({language:et(),hubInstanceId:n.hubInstanceId,hubName:n.hubName,sdp:n.sdp,secret:n.secret});t||(s(r),a(`offer`))}catch(e){t||(l(e.message),a(`offer`))}})(),()=>{t=!0}},[e]),(0,Q.useEffect)(()=>{if(i!==`scanning`)return;let e=d.current,t=u.current;if(!e||!t)return;t.srcObject=e,t.play().catch(()=>{});let n=document.createElement(`canvas`),r=n.getContext(`2d`,{willReadFrequently:!0});if(!r)return;let a=()=>{if(d.current){if(t.videoWidth){n.width=t.videoWidth,n.height=t.videoHeight,r.drawImage(t,0,0);let e=r.getImageData(0,0,n.width,n.height),i=(0,Oq.default)(e.data,e.width,e.height);if(i){h(i.data);return}}f.current=requestAnimationFrame(a)}};f.current=requestAnimationFrame(a)},[i,h]),(0,Q.useEffect)(()=>()=>p(),[p]);async function g(){if(l(null),!navigator.mediaDevices?.getUserMedia){J.error(r(`pairWeb.cameraFailed`,{message:`unsupported`}));return}try{d.current=await navigator.mediaDevices.getUserMedia({video:{facingMode:`environment`}}),a(`scanning`)}catch(e){J.error(r(`pairWeb.cameraFailed`,{message:e.message})),a(`offer`)}}return(0,$.jsx)(mr,{open:e,onOpenChange:e=>{e||m()},children:(0,$.jsxs)(fr,{movableResizable:!0,className:`max-w-md`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:r(`pairWeb.title`)}),(0,$.jsx)(ir,{children:r(`pairWeb.description`)})]}),c&&(0,$.jsx)(`p`,{className:`text-sm text-destructive`,children:r(`pairWeb.startFailed`,{error:c})}),i===`loading`&&(0,$.jsx)(`div`,{className:`h-56 bg-muted/30 rounded-lg animate-pulse`}),i===`offer`&&o&&(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-2`,children:[(0,$.jsx)(`div`,{className:`bg-white p-3 rounded-lg`,children:(0,$.jsx)(Dq,{value:o,size:220})}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:r(`pairWeb.showThenScan`)}),(0,$.jsx)(Z,{onClick:()=>void g(),className:`gap-2`,children:r(`pairWeb.scanAnswer`)}),(0,$.jsx)(`button`,{type:`button`,className:`text-xs text-accent-info underline`,onClick:()=>{navigator.clipboard?.writeText(o),J.success(r(`pairWeb.codeCopied`))},children:r(`pairWeb.copyCode`)})]}),i===`scanning`&&(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-2`,children:[(0,$.jsx)(`video`,{ref:u,playsInline:!0,className:`w-full max-h-72 rounded-lg bg-black`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:r(`pairWeb.scanning`)}),(0,$.jsx)(Z,{variant:`outline`,onClick:()=>{p(),a(`offer`)},children:r(`pairWeb.cancel`)})]}),i===`connecting`&&(0,$.jsx)(`p`,{className:`py-6 text-center text-muted-foreground`,children:r(`pairWeb.connecting`)}),i===`paired`&&(0,$.jsx)(`p`,{className:`py-6 text-center text-accent-success font-medium`,children:r(`pairWeb.paired`)})]})})}var Lq=typeof navigator<`u`&&/Win/i.test(navigator.platform);function Rq(e){return!e||e.length<16?e??`—`:`${e.slice(0,8)}…${e.slice(-8)}`}function zq(){let{t:e}=K(`settings`),[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(!1),l=(0,Q.useCallback)(async()=>{try{let e=await fetch(`/api/mobile/status`);e.ok&&n(await e.json())}catch{}},[]),u=(0,Q.useCallback)(async()=>{try{let e=await fetch(`/api/mobile/devices`);e.ok&&i((await e.json()).devices)}catch{}},[]);(0,Q.useEffect)(()=>{l(),u()},[l,u]);let{registerHandler:d,unregisterHandler:f}=tt();(0,Q.useEffect)(()=>{let e=`mobile-access-devices`;return d(e,e=>{let t=e?.type;(t===`mobile.device_paired`||t===`mobile.device_revoked`)&&u()}),()=>f(e)},[d,f,u]);async function p(){if(t){o(!0);try{let e=t.enabled?`disable`:`enable`,r=await fetch(`/api/mobile/${e}`,{method:`POST`});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error??`HTTP ${r.status}`)}n(await r.json())}catch(n){J.error(t.enabled?e(`mobile.disableFailed`,{message:n.message}):e(`mobile.enableFailed`,{message:n.message}))}finally{o(!1)}}}async function m(e){await fetch(`/api/mobile/devices/${e}`,{method:`DELETE`}).catch(()=>{}),u()}async function h(){if(window.confirm(e(`mobile.resetConfirm`))){o(!0);try{let t=await fetch(`/api/mobile/cert/rotate`,{method:`POST`});t.ok&&n(await t.json()),u(),J.success(e(`mobile.identityReset`))}finally{o(!1)}}}return t?(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:[(0,$.jsx)(Tc,{className:`h-3.5 w-3.5`}),` `,e(`mobile.heading`)]}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`mobile.description`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-border p-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium`,children:t.enabled?e(`mobile.accessOn`):e(`mobile.accessOff`)}),(0,$.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t.running?e(`mobile.listeningOnPort`,{port:t.port}):e(`mobile.notListening`)})]}),(0,$.jsx)(Z,{variant:t.enabled?`outline`:`default`,disabled:a,onClick:p,children:t.enabled?e(`mobile.turnOff`):e(`mobile.turnOn`)})]}),t.enabled&&t.running&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsxs)(Z,{onClick:()=>c(!0),className:`gap-2`,children:[(0,$.jsx)(D,{className:`h-4 w-4`}),` `,e(`mobile.pairWebDevice`)]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,$.jsx)(Cc,{className:`h-3.5 w-3.5 text-accent-success`}),(0,$.jsx)(`span`,{title:t.certFingerprint??``,children:Rq(t.certFingerprint)}),(0,$.jsx)(`button`,{type:`button`,className:`underline`,onClick:h,disabled:a,children:e(`mobile.reset`)})]})]}),Lq&&(0,$.jsx)(`p`,{className:`text-xs text-accent-warning`,children:e(`mobile.windowsFirewall`)}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground`,children:e(`mobile.pairedDevices`)}),r.filter(e=>!e.revoked).length===0?(0,$.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e(`mobile.noDevices`)}):r.filter(e=>!e.revoked).map(t=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between rounded-md bg-muted/30 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`text-sm`,children:[t.name,` `,(0,$.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`· `,t.platform]})]}),(0,$.jsx)(`button`,{type:`button`,"aria-label":e(`mobile.revokeDevice`,{name:t.name}),className:`text-muted-foreground hover:text-destructive`,onClick:()=>m(t.id),children:(0,$.jsx)(Rn,{className:`h-4 w-4`})})]},t.id))]})]}),(0,$.jsx)(Iq,{open:s,onClose:()=>c(!1),onPaired:u})]}):(0,$.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`})}var Bq=[`claude`,`codex`,`gemini`,`kimi`],Vq=[`claude`,`gemini`,`kimi`],Hq=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;function Uq(e){return`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[10px] font-medium transition-all duration-150 disabled:opacity-50 ${e?`border-accent-primary/50 bg-accent-primary/15 text-accent-primary shadow-[0_0_8px_-2px] shadow-accent-primary/30`:`border-border/60 bg-transparent text-muted-foreground/70 hover:border-border hover:text-foreground hover:bg-muted/30`}`}function Wq(){let{t:e}=K(`mcp`),[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)([]),[h,g]=(0,Q.useState)({}),[_,v]=(0,Q.useState)(null),y=(0,Q.useCallback)(async()=>{try{let e=await fetch(`${Xe}/api/external-mcp`);if(!e.ok)return;let t=await e.json();t?.settings?.servers&&t?.discovered?.orphanIds&&n(t)}catch{}},[]);(0,Q.useEffect)(()=>{y()},[y]);let b=(0,Q.useCallback)(async r=>{if(!t)return;let a=t;n({...t,settings:{version:1,servers:r}}),i(!0);try{let e=await fetch(`${Xe}/api/external-mcp`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({servers:r})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`HTTP ${e.status}`)}let t=await e.json();return t?.settings?.servers&&t?.discovered?.orphanIds&&n(t),!0}catch(t){n(a);let r=t.message;return J.error(e([`external.errors.${r}`,`external.updateFailed`])),!1}finally{i(!1)}},[t,e]),x=(0,Q.useMemo)(()=>{if(!t)return[];let{settings:e,discovered:n}=t,r=[],i=new Set(Object.keys(e.servers));for(let[t,i]of Object.entries(e.servers))r.push({id:t,name:i.name,source:i.source,sourceProvider:i.sourceProvider,providers:i.providers,orphan:n.orphanIds.includes(t),stored:!0});for(let e of Vq)for(let t of n[e])i.has(t.id)||r.push({id:t.id,name:t.name,source:`discovered`,sourceProvider:e,providers:{},orphan:!1,stored:!1});return r.sort((e,t)=>e.name.localeCompare(t.name)||e.id.localeCompare(t.id))},[t]),S=(0,Q.useCallback)((e,n)=>{if(!t)return;let r={...t.settings.servers},i=r[e.id],a={...i?.providers??{}};a[n]?delete a[n]:a[n]=!0,e.source===`discovered`&&Object.keys(a).length===0?delete r[e.id]:r[e.id]=i?{...i,providers:a}:{source:`discovered`,sourceProvider:e.sourceProvider,name:e.name,providers:a},b(r)},[t,b]),C=(0,Q.useCallback)(e=>{if(!t)return;let n={...t.settings.servers};delete n[e],b(n)},[t,b]),w=s.trim(),T=w!==``&&(!Hq.test(w)||w===`specrails`),E=w!==``&&!T&&`c:${w}`!==_&&!!t?.settings.servers[`c:${w}`],O=w!==``&&!T&&!E&&l.trim()!==``,k=(0,Q.useCallback)(()=>{o(!1),v(null),c(``),u(``),f(``),m([]),g({})},[]),A=(0,Q.useCallback)(()=>{v(null),c(``),u(``),f(``),m([]),g({}),o(!0)},[]),j=(0,Q.useCallback)(e=>{let n=t?.settings.servers[e];!n||n.source!==`custom`||!n.transport||(v(e),c(n.name),u(n.transport.command),f(n.transport.args.join(` `)),m(Object.entries(n.transport.env).map(([e,t])=>({key:e,value:t}))),g({...n.providers}),o(!0))},[t]),M=(0,Q.useCallback)(async()=>{if(!t||!O)return;let e=w,n={};for(let e of p){let t=e.key.trim();t&&(n[t]=e.value)}let r={};for(let[e,t]of Object.entries(h))t&&(r[e]=!0);let i={...t.settings.servers};_&&_!==`c:${e}`&&delete i[_],i[`c:${e}`]={source:`custom`,name:e,providers:r,transport:{command:l.trim(),args:d.trim()?d.trim().split(/\s+/):[],env:n}},await b(i)&&k()},[t,O,w,l,d,p,h,_,b,k]);return t?(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border p-3`,"data-testid":`external-mcp-card`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`text-xs font-semibold text-foreground flex items-center gap-1.5`,children:[(0,$.jsx)(D,{className:`h-3.5 w-3.5`}),` `,e(`external.heading`)]}),(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,className:`h-7 text-[11px]`,disabled:r,onClick:()=>a&&!_?o(!1):A(),"data-testid":`external-mcp-add`,children:[(0,$.jsx)(Pn,{className:`h-3 w-3`}),` `,e(`external.addCustom`)]})]}),(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80`,children:e(`external.description`)}),(0,$.jsxs)(`p`,{className:`flex items-start gap-1.5 text-[11px] text-accent-warning`,children:[(0,$.jsx)(zn,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),e(`external.warning`)]}),a&&(0,$.jsxs)(`div`,{className:`space-y-2.5 rounded-md border border-border/70 bg-muted/20 p-3`,"data-testid":`external-mcp-form`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{htmlFor:`ext-mcp-name`,className:`block text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e(`external.form.nameLabel`)}),(0,$.jsx)(`input`,{id:`ext-mcp-name`,autoFocus:!0,value:s,onChange:e=>c(e.target.value),placeholder:e(`external.form.name`),className:`w-full rounded-md border bg-background px-2 py-1 text-xs transition-colors ${T||E?`border-destructive/60 focus:outline-destructive`:`border-border`}`}),(T||E)&&(0,$.jsx)(`p`,{className:`text-[10px] text-destructive`,"data-testid":`external-mcp-name-hint`,children:e(T?`external.form.nameInvalid`:`external.form.nameTaken`)})]}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{htmlFor:`ext-mcp-command`,className:`block text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e(`external.form.commandLabel`)}),(0,$.jsx)(`input`,{id:`ext-mcp-command`,value:l,onChange:e=>u(e.target.value),placeholder:e(`external.form.command`),className:`w-full rounded-md border border-border bg-background px-2 py-1 text-xs font-mono`})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{htmlFor:`ext-mcp-args`,className:`block text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e(`external.form.argsLabel`)}),(0,$.jsx)(`input`,{id:`ext-mcp-args`,value:d,onChange:e=>f(e.target.value),placeholder:e(`external.form.args`),className:`w-full rounded-md border border-border bg-background px-2 py-1 text-xs font-mono`})]}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e(`external.form.envLabel`)}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>m(e=>[...e,{key:``,value:``}]),className:`inline-flex items-center gap-1 text-[10px] font-medium text-muted-foreground hover:text-foreground transition-colors`,"data-testid":`external-mcp-env-add`,children:[(0,$.jsx)(Pn,{className:`h-2.5 w-2.5`}),` `,e(`external.form.addVar`)]})]}),p.map((t,n)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`input`,{value:t.key,onChange:e=>m(t=>t.map((t,r)=>r===n?{...t,key:e.target.value}:t)),placeholder:e(`external.form.envKey`),"aria-label":`${e(`external.form.envKey`)} ${n+1}`,className:`w-2/5 rounded-md border border-border bg-background px-2 py-1 text-xs font-mono`}),(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`=`}),(0,$.jsx)(`input`,{value:t.value,onChange:e=>m(t=>t.map((t,r)=>r===n?{...t,value:e.target.value}:t)),placeholder:e(`external.form.envValue`),"aria-label":`${e(`external.form.envValue`)} ${n+1}`,className:`flex-1 rounded-md border border-border bg-background px-2 py-1 text-xs font-mono`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>m(e=>e.filter((e,t)=>t!==n)),className:`text-muted-foreground hover:text-destructive transition-colors`,"aria-label":`${e(`external.remove`)} ${n+1}`,children:(0,$.jsx)(Rn,{className:`h-3 w-3`})})]},n))]}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`span`,{className:`block text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e(`external.form.enableFor`)}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:Bq.map(e=>{let t=h[e]===!0;return(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":t,"aria-label":`custom · ${e}`,onClick:()=>g(t=>({...t,[e]:!t[e]})),className:Uq(t),"data-testid":`external-mcp-form-provider-${e}`,children:[t&&(0,$.jsx)(Sn,{className:`h-2.5 w-2.5`,strokeWidth:3}),e]},e)})})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-1.5 pt-0.5`,children:[(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,className:`h-7 text-[11px]`,onClick:k,children:e(`external.form.cancel`)}),(0,$.jsx)(Z,{size:`sm`,className:`h-7 text-[11px]`,disabled:r||!O,onClick:()=>void M(),"data-testid":`external-mcp-form-save`,children:e(`external.form.save`)})]})]}),x.length===0&&t.discovered.codexNative.length===0?(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground py-1`,children:e(`external.empty`)}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[x.map(t=>(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 rounded-md border border-border/60 px-2 py-1.5`,"data-testid":`external-mcp-row-${t.id}`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-foreground min-w-0 truncate`,children:t.name}),(0,$.jsx)(`span`,{className:`rounded-full bg-muted/60 px-1.5 py-px text-[10px] text-muted-foreground`,children:t.source===`custom`?e(`external.sourceCustom`):e(`external.sourceDiscovered`,{provider:t.sourceProvider})}),t.orphan&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-accent-warning/15 px-1.5 py-px text-[10px] text-accent-warning`,"data-testid":`external-mcp-orphan`,children:[(0,$.jsx)(zn,{className:`h-2.5 w-2.5`}),` `,e(`external.orphan`)]}),(0,$.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`flex items-center gap-1`,children:Bq.map(e=>{let n=t.providers[e]===!0;return(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":`${t.name} · ${e}`,disabled:r,onClick:()=>S(t,e),className:Uq(n),children:[n&&(0,$.jsx)(Sn,{className:`h-2.5 w-2.5`,strokeWidth:3}),e]},e)})}),t.stored&&t.source===`custom`&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>j(t.id),disabled:r,className:`text-muted-foreground hover:text-foreground`,"aria-label":e(`external.edit`),"data-testid":`external-mcp-edit-${t.id}`,children:(0,$.jsx)(jn,{className:`h-3 w-3`})}),t.stored&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>C(t.id),disabled:r,className:`text-muted-foreground hover:text-destructive`,"aria-label":e(`external.remove`),"data-testid":`external-mcp-remove-${t.id}`,children:(0,$.jsx)(Rn,{className:`h-3 w-3`})})]})]},t.id)),t.discovered.codexNative.map(t=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-md border border-border/40 px-2 py-1.5 opacity-70`,"data-testid":`external-mcp-codex-${t}`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-foreground min-w-0 truncate`,children:t}),(0,$.jsx)(`span`,{className:`rounded-full bg-muted/60 px-1.5 py-px text-[10px] text-muted-foreground`,children:e(`external.codexNative`)})]},`codex:${t}`))]})]}):(0,$.jsx)(`div`,{className:`h-16 bg-muted/30 rounded-lg animate-pulse`,"data-testid":`external-mcp-skeleton`})}async function Gq(e){try{if(navigator.clipboard&&typeof navigator.clipboard.writeText==`function`)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function Kq(e){return JSON.stringify({mcpServers:{specrails:{command:e.bridgeCommand}}},null,2)}function qq(){let{t:e}=K(`mcp`),[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),l=(0,Q.useCallback)(async()=>{try{let e=await fetch(`${Xe}/api/mcp-admin/status`);e.ok&&n(await e.json())}catch{}},[]),u=(0,Q.useCallback)(async()=>{try{let e=await fetch(`${Xe}/api/mcp-admin/config`);e.ok&&i(await e.json())}catch{}},[]);(0,Q.useEffect)(()=>{l(),u()},[l,u]);let d=(0,Q.useCallback)(async()=>{if(t){o(!0);try{let e=t.enabled?`disable`:`enable`,n=await fetch(`${Xe}/api/mcp-admin/${e}`,{method:`POST`});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}await l()}catch(n){J.error(t.enabled?e(`enable.disableFailed`,{message:n.message}):e(`enable.enableFailed`,{message:n.message}))}finally{o(!1)}}},[t,l,e]),f=(0,Q.useCallback)(async r=>{if(!t)return;o(!0);let i=!t.tiers[r];try{let e=await fetch(`${Xe}/api/mcp-admin/tiers`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({[r]:i})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`HTTP ${e.status}`)}let t=await e.json();n(e=>e&&{...e,tiers:t.tiers})}catch(t){J.error(e(`tiers.updateFailed`,{message:t.message}))}finally{o(!1)}},[t,e]),p=(0,Q.useCallback)(async()=>{r&&(await Gq(Kq(r))?(c(`config`),window.setTimeout(()=>c(e=>e===`config`?null:e),1500)):J.error(e(`config.copyFailed`)))},[r,e]),m=(0,Q.useCallback)(async()=>{try{let t=await fetch(`${Xe}/api/mcp-admin/token`);if(!t.ok)throw Error(`HTTP ${t.status}`);let{token:n}=await t.json();await Gq(n)?(c(`token`),window.setTimeout(()=>c(e=>e===`token`?null:e),1500)):J.error(e(`config.copyFailed`))}catch{J.error(e(`config.copyFailed`))}},[e]),h=(0,Q.useCallback)(async()=>{if(window.confirm(e(`token.regenerateConfirm`))){o(!0);try{let t=await fetch(`${Xe}/api/mcp-admin/regenerate-token`,{method:`POST`});if(!t.ok)throw Error(`HTTP ${t.status}`);await l(),J.success(e(`token.regenerated`))}catch(t){J.error(e(`token.regenerateFailed`,{message:t.message}))}finally{o(!1)}}},[l,e]);if(!t)return(0,$.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`});let g=[{key:`write`,label:e(`tiers.write`),help:e(`tiers.writeHelp`)},{key:`aiSpawn`,label:e(`tiers.aiSpawn`),help:e(`tiers.aiSpawnHelp`)},{key:`destructive`,label:e(`tiers.destructive`),help:e(`tiers.destructiveHelp`)}];return(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:[(0,$.jsx)(lc,{className:`h-3.5 w-3.5`}),` `,e(`heading`)]}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`explainer.what`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80`,children:e(`explainer.how`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-border p-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium`,children:t.enabled?e(`enable.on`):e(`enable.off`)}),(0,$.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[t.running?e(`enable.running`,{count:t.toolCount}):e(`enable.stopped`),t.enabled&&t.activeSessions>0&&(0,$.jsxs)($.Fragment,{children:[` · `,e(`enable.activeSessions`,{count:t.activeSessions})]})]})]}),(0,$.jsx)(Z,{variant:t.enabled?`outline`:`default`,disabled:a,onClick:()=>void d(),children:t.enabled?e(`enable.turnOff`):e(`enable.turnOn`)})]}),t.enabled&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border p-3`,children:[(0,$.jsx)(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`tiers.heading`)}),(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80`,children:e(`explainer.grants`)}),(0,$.jsxs)(`label`,{className:`flex items-start gap-2 opacity-70`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:!0,disabled:!0,className:`mt-0.5`,"aria-label":e(`tiers.read`)}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:e(`tiers.read`)}),(0,$.jsx)(`span`,{className:`block text-[10px] text-muted-foreground`,children:e(`tiers.readHelp`)})]})]}),g.map(e=>(0,$.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:t.tiers[e.key],disabled:a,onChange:()=>void f(e.key),className:`mt-0.5`,"aria-label":e.label}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:e.label}),(0,$.jsx)(`span`,{className:`block text-[10px] text-muted-foreground`,children:e.help})]})]},e.key))]}),r&&(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`config.heading`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void p(),className:`inline-flex h-7 items-center gap-1.5 rounded-lg border border-border bg-background px-2.5 text-[11px] font-medium text-muted-foreground hover:text-foreground`,"data-testid":`mcp-copy-config`,children:s===`config`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Sn,{className:`h-3 w-3 text-accent-success`}),` `,e(`config.configCopied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ls,{className:`h-3 w-3`}),` `,e(`config.copyConfig`)]})})]}),(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80`,children:e(`config.description`)}),(0,$.jsx)(`pre`,{className:`overflow-x-auto rounded-md bg-muted/40 p-2 text-[10px] leading-relaxed text-foreground`,children:Kq(r)})]}),(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border p-3`,children:[(0,$.jsx)(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`token.heading`)}),(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80`,children:e(`token.description`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground tabular-nums`,children:e(`token.hint`,{hint:t.tokenHint})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>void m(),className:`inline-flex h-7 items-center gap-1.5 rounded-lg border border-border bg-background px-2.5 text-[11px] font-medium text-muted-foreground hover:text-foreground`,"data-testid":`mcp-copy-token`,children:s===`token`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Sn,{className:`h-3 w-3 text-accent-success`}),` `,e(`token.tokenCopied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ls,{className:`h-3 w-3`}),` `,e(`token.copyToken`)]})}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void h(),disabled:a,className:`inline-flex h-7 items-center gap-1.5 rounded-lg border border-border bg-background px-2.5 text-[11px] font-medium text-muted-foreground hover:text-foreground disabled:opacity-50`,"data-testid":`mcp-regenerate-token`,children:[(0,$.jsx)(mc,{className:`h-3 w-3`}),` `,e(`token.regenerate`)]})]})]})]})]}),(0,$.jsx)(Wq,{})]})}var Jq=`specrails-os-notifications`,Yq={enabled:!0,filter:`all`};function Xq(){try{let e=localStorage.getItem(Jq);if(!e)return Yq;let t=JSON.parse(e);return{enabled:typeof t.enabled==`boolean`?t.enabled:Yq.enabled,filter:t.filter===`completed`||t.filter===`failed`?t.filter:Yq.filter}}catch{return Yq}}function Zq(e){localStorage.setItem(Jq,JSON.stringify(e))}function Qq({setActiveProjectId:e,projectsById:t}={}){let n=y(),r=(0,Q.useRef)(n);(0,Q.useEffect)(()=>{r.current=n},[n]);let i=(0,Q.useRef)(e);(0,Q.useEffect)(()=>{i.current=e},[e]);let{uiMode:a}=MN(),o=(0,Q.useRef)(a);(0,Q.useEffect)(()=>{o.current=a},[a]);let s=(0,Q.useCallback)((e,t)=>{if(o.current===`agent`){e&&i.current&&i.current(e),aO({projectId:e,jobId:t});return}e&&i.current?(i.current(e),setTimeout(()=>{r.current(`/jobs/${t}`)},100)):r.current(`/jobs/${t}`)},[]),c=(0,Q.useRef)(t);(0,Q.useEffect)(()=>{c.current=t},[t]);let l=(0,Q.useRef)(new Map),u=(0,Q.useRef)(new Map),{registerHandler:d,unregisterHandler:f}=tt(),p=(0,Q.useCallback)(e=>{let t=e;if(!t)return;if(t.type===`job.stuck`&&typeof t.jobId==`string`){let e=Array.isArray(t.actions)?t.actions.filter(e=>e===`stop`):[];h(t.jobId,t.projectId??null,t.staleMs??0,e);return}if(t.type===`loop.provider_limit`&&typeof t.runId==`string`){m(t.runId,t.projectId??null,typeof t.provider==`string`?t.provider:``,typeof t.resetsAt==`string`&&t.resetsAt?t.resetsAt:null,typeof t.message==`string`?t.message:``);return}if(t.type!==`queue`||!Array.isArray(t.jobs))return;let n=t.projectId??null;for(let e of t.jobs){let t=l.current.get(e.id),r=e.status;n&&u.current.set(e.id,n),t===`running`&&(r===`completed`||r===`failed`)&&_(e,n),l.current.set(e.id,r)}},[]);function m(e,t,n,r,i){let a=Xq();if(!a.enabled||a.filter===`completed`)return;let o=t?c.current?.get(t)??``:``,s=n?n.charAt(0).toUpperCase()+n.slice(1):`AI`,l=r?Je.t(`commands:notifications.providerLimitBody`,{provider:s,resetsAt:r}):Je.t(`commands:notifications.providerLimitBodyNoReset`,{provider:s}),u=Je.t(`commands:notifications.providerLimit`);J.error(u,{id:`provider-limit:${e}`,description:`${o?`[${o}] `:``}${l}${i?` · ${i}`:``}`,duration:6e4}),!(typeof Notification>`u`)&&Notification.permission===`granted`&&(()=>{let t=new Notification(u,{body:o?`[${o}] ${l}`:l,tag:`specrails-provider-limit:${e}`});t.onclick=()=>{window.focus(),t.close()}})()}function h(e,t,n,r=[]){let i=Xq();if(!i.enabled||i.filter===`completed`)return;let a=Math.max(1,Math.round(n/6e4)),o=t?c.current?.get(t)??``:``,l=Je.t(`commands:notifications.jobStuckBody`,{count:a});if(t&&r.includes(`stop`)&&J.warning(Je.t(`commands:notifications.jobStuck`),{id:`job-stuck:${e}`,description:o?`[${o}] ${l}`:l,duration:2e4,action:{label:Je.t(`commands:notifications.jobStuckStop`),onClick:()=>{g(t,e)}}}),typeof Notification>`u`)return;function u(){let n=new Notification(Je.t(`commands:notifications.jobStuck`),{body:o?`[${o}] ${l}`:l,tag:`specrails-job-stuck:${e}`});n.onclick=()=>{window.focus(),s(t,e),n.close()}}Notification.permission===`granted`?u():Notification.permission==="default"&&Notification.requestPermission().then(e=>{e===`granted`&&u()})}async function g(e,t){try{let n=await fetch(`/api/projects/${e}/jobs/${t}/cancel`,{method:`POST`});if(!n.ok)throw Error(`HTTP ${n.status}`);J.success(Je.t(`commands:notifications.jobStuckStopped`),{id:`job-stuck:${t}`})}catch{J.error(Je.t(`commands:notifications.jobStuckStopFailed`),{id:`job-stuck:${t}`})}}function _(e,t){if(typeof Notification>`u`||typeof document<`u`&&!document.hidden)return;let n=Xq();if(!n.enabled||n.filter===`completed`&&e.status!==`completed`||n.filter===`failed`&&e.status!==`failed`)return;function r(){let n=e.status===`completed`?Je.t(`commands:notifications.jobCompleted`):Je.t(`commands:notifications.jobFailed`),r=t?c.current?.get(t)??``:``,i=e.command?e.command.slice(0,80):Je.t(`commands:notifications.unknownCommand`),a=r?`[${r}] ${i}`:i,o=new Notification(n,{body:a,tag:`specrails-job:${e.id}:${e.status}`}),l=e.id,u=t;o.onclick=()=>{window.focus(),s(u,l),o.close()}}Notification.permission===`granted`?r():Notification.permission==="default"&&Notification.requestPermission().then(e=>{e===`granted`&&r()})}(0,Q.useLayoutEffect)(()=>(d(`os-notifications`,p),()=>f(`os-notifications`)),[p,d,f])}var $q=[{value:`job.completed`,labelKey:`webhooks.eventJobCompleted`},{value:`job.failed`,labelKey:`webhooks.eventJobFailed`},{value:`daily_budget_exceeded`,labelKey:`webhooks.eventDailyBudgetExceeded`}];function eJ({project:e,onRemove:t}){let{t:n}=K(`settings`);return(0,$.jsxs)(`div`,{className:`flex items-center gap-3 p-2.5 rounded-md border border-border`,children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium truncate`,children:e.name}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground truncate`,children:e.path})]}),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,className:`h-6 px-2 text-[10px] text-muted-foreground hover:text-destructive shrink-0`,onClick:()=>t(e.id),children:n(`common:actions.remove`)})]})}var tJ=[{id:`appearance`,icon:ec,labelKey:`desktop.nav.appearance`},{id:`effects`,icon:Ln,labelKey:`desktop.nav.effects`},{id:`specrailsAgents`,icon:fs,labelKey:`desktop.nav.specrailsAgents`},{id:`code`,icon:is,labelKey:`desktop.nav.code`},{id:`terminal`,icon:Ec,labelKey:`desktop.nav.terminal`},{id:`updates`,icon:mc,labelKey:`desktop.nav.updates`},{id:`mobile`,icon:Tc,labelKey:`desktop.nav.mobile`},{id:`mcp`,icon:Vo,labelKey:`desktop.nav.mcp`},{id:`projects`,icon:Ts,labelKey:`desktop.nav.projects`},{id:`advanced`,icon:wc,labelKey:`desktop.nav.advanced`},{id:`webhooks`,icon:Ic,labelKey:`desktop.nav.webhooks`},{id:`about`,icon:Rs,labelKey:`desktop.nav.about`}];function nJ({open:e,onClose:t,onOpenOnboarding:n,initialSection:r=`appearance`}){let{t:i}=K(`settings`),{projects:a,removeProject:o}=pt(),[s,c]=(0,Q.useState)(`appearance`);(0,Q.useEffect)(()=>{e&&c(r)},[e,r]);let l=e=>X(`space-y-5`,s===e?``:`hidden`),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!0),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)([]),[w,T]=(0,Q.useState)(``),[E,D]=(0,Q.useState)(``),[O,k]=(0,Q.useState)([`job.completed`,`job.failed`]),[A,j]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(()=>Xq().enabled),[P,F]=(0,Q.useState)(()=>Xq().filter);function I(e){N(e),Zq({enabled:e,filter:P}),J.success(i(e?`notifications.enabledToast`:`notifications.disabledToast`))}function L(e){F(e),Zq({enabled:M,filter:e})}let R=(0,Q.useCallback)(async()=>{try{let e=await fetch(`/api/webhooks`);if(e.ok){let t=await e.json();C(t.webhooks)}}catch{}},[]);(0,Q.useEffect)(()=>{if(!e)return;p(!0);async function t(){try{let e=await fetch(`/api/settings`);if(e.ok){let t=await e.json();d(t),h(t.costAlertThresholdUsd==null?``:String(t.costAlertThresholdUsd))}}catch{}finally{p(!1)}}t(),R()},[e,R]),(0,Q.useEffect)(()=>{e&&fetch(`/api/budget`).then(e=>e.json()).then(e=>{e.desktopDailyBudgetUsd==null?y(``):y(String(e.desktopDailyBudgetUsd))}).catch(()=>{})},[e]);async function z(){_(!0);try{let e=m.trim()===``?null:parseFloat(m);if(e!==null&&(isNaN(e)||e<=0)){J.error(i(`budget.invalidNumber`));return}(await fetch(`/api/settings`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({costAlertThresholdUsd:e})})).ok?J.success(e==null?i(`desktop.costAlertsDisabled`):i(`budget.alertSet`,{amount:e})):J.error(i(`budget.saveThresholdFailed`))}catch{J.error(i(`budget.saveThresholdFailed`))}finally{_(!1)}}async function B(){x(!0);try{let e=v.trim()===``?null:parseFloat(v);if(e!==null&&(isNaN(e)||e<=0)){J.error(i(`budget.invalidNumber`));return}(await fetch(`/api/budget`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({desktopDailyBudgetUsd:e})})).ok?J.success(e==null?i(`desktop.dailyBudgetRemoved`):i(`desktop.dailyBudgetSet`,{amount:e})):J.error(i(`desktop.dailyBudgetSaveFailed`))}catch{J.error(i(`desktop.dailyBudgetSaveFailed`))}finally{x(!1)}}async function V(e){try{await o(e),J.success(i(`desktop.projectRemoved`))}catch(e){J.error(i(`desktop.projectRemoveFailed`),{description:e.message})}}async function H(){if(!w.trim()){J.error(i(`webhooks.urlRequired`));return}if(O.length===0){J.error(i(`webhooks.selectEvent`));return}j(!0);try{let e=await fetch(`/api/webhooks`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({url:w.trim(),secret:E.trim(),events:O})});if(e.ok)J.success(i(`webhooks.added`)),T(``),D(``),k([`job.completed`,`job.failed`]),await R();else{let t=await e.json();J.error(t.error??i(`webhooks.addFailed`))}}catch{J.error(i(`webhooks.addFailed`))}finally{j(!1)}}async function U(e,t){try{await fetch(`/api/webhooks/${e}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:t})}),await R()}catch{J.error(i(`webhooks.updateFailed`))}}async function W(e){try{(await fetch(`/api/webhooks/${e}`,{method:`DELETE`})).ok&&(J.success(i(`webhooks.removed`)),await R())}catch{J.error(i(`webhooks.removeFailed`))}}async function ee(e){try{(await fetch(`/api/webhooks/${e}/test`,{method:`POST`})).ok&&J.success(i(`webhooks.testPingSent`))}catch{J.error(i(`webhooks.testPingFailed`))}}function te(e){k(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}return(0,$.jsx)(mr,{open:e,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(fr,{movableResizable:!0,className:`flex max-w-5xl w-[92vw] h-[82vh] flex-col overflow-hidden`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsxs)(sr,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Sc,{className:`w-4 h-4`}),i(`desktop.title`)]}),(0,$.jsx)(ir,{children:i(`desktop.description`)})]}),f?(0,$.jsxs)(`div`,{className:`space-y-3 py-2`,children:[(0,$.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`}),(0,$.jsx)(`div`,{className:`h-16 bg-muted/30 rounded-lg animate-pulse`})]}):(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-5 py-2`,children:[(0,$.jsx)(`nav`,{className:`w-40 shrink-0 space-y-0.5 overflow-y-auto border-r border-border pr-2`,children:tJ.map(e=>{if(e.id===`mcp`&&!oe)return null;let t=e.icon;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>c(e.id),className:X(`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left text-xs transition-colors`,s===e.id?`bg-accent-primary/15 font-medium text-foreground`:`text-muted-foreground hover:bg-muted/40 hover:text-foreground`),children:[(0,$.jsx)(t,{className:`w-3.5 h-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:i(e.labelKey)})]},e.id)})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-y-auto pr-1`,children:[(0,$.jsxs)(`div`,{className:l(`appearance`),children:[(0,$.jsx)(QG,{}),(0,$.jsx)(oK,{})]}),(0,$.jsx)(`div`,{className:l(`effects`),children:(0,$.jsx)(XG,{})}),(0,$.jsx)(`div`,{className:l(`specrailsAgents`),children:(0,$.jsx)(OK,{children:(0,$.jsx)(YG,{})})}),(0,$.jsx)(`div`,{className:l(`code`),children:(0,$.jsx)(sK,{})}),(0,$.jsxs)(`div`,{className:l(`updates`),children:[(0,$.jsx)(eq,{}),(0,$.jsx)(AK,{})]}),(0,$.jsx)(`div`,{className:l(`mobile`),children:(0,$.jsx)(zq,{})}),oe&&(0,$.jsx)(`div`,{className:l(`mcp`),children:(0,$.jsx)(qq,{})}),(0,$.jsx)(`div`,{className:l(`projects`),children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:i(`desktop.registeredProjects`)}),a.length===0?(0,$.jsx)(`div`,{className:`rounded-md border border-dashed border-border p-4 text-center`,children:(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`desktop.noProjects`)})}):(0,$.jsx)(`div`,{className:`space-y-1.5`,children:a.map(e=>(0,$.jsx)(eJ,{project:e,onRemove:V},e.id))})]})}),(0,$.jsxs)(`div`,{className:l(`advanced`),children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:i(`desktop.budgetAlertsHeading`)}),(0,$.jsxs)(`div`,{className:`rounded-md border border-border p-3 space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium`,children:i(`desktop.dailyBudgetLabel`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:i(`desktop.dailyBudgetHelper`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Jj,{type:`number`,min:`0`,step:`0.01`,value:v,onChange:e=>y(e.target.value),placeholder:i(`desktop.dailyBudgetPlaceholder`),className:`h-7 text-xs font-mono`}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs shrink-0`,disabled:b,onClick:()=>void B(),children:i(`common:actions.save`)})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium`,children:i(`budget.perJobLabel`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:i(`desktop.perJobHelper`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Jj,{type:`number`,min:`0`,step:`0.01`,value:m,onChange:e=>h(e.target.value),placeholder:i(`budget.perJobPlaceholder`),className:`h-7 text-xs font-mono`}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs shrink-0`,disabled:g,onClick:z,children:i(`common:actions.save`)})]})]})]})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:i(`notifications.heading`)}),(0,$.jsxs)(`div`,{className:`rounded-md border border-border p-3 space-y-3`,children:[(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:i(`notifications.description`)}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:M,onChange:e=>I(e.target.checked),className:`w-3.5 h-3.5`,"data-testid":`notif-toggle`}),(0,$.jsx)(zo,{className:`w-3.5 h-3.5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`text-xs`,children:i(`notifications.enableLabel`)})]}),M&&(0,$.jsxs)(`div`,{className:`space-y-1.5 pl-6`,children:[(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:i(`notifications.notifyOn`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:[{value:`all`,label:i(`notifications.filterAll`)},{value:`completed`,label:i(`notifications.filterCompleted`)},{value:`failed`,label:i(`notifications.filterFailed`)}].map(({value:e,label:t})=>(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[10px] cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`radio`,name:`notif-filter`,checked:P===e,onChange:()=>L(e),className:`w-3 h-3`}),t]},e))})]})]})]})]}),(0,$.jsx)(`div`,{className:l(`webhooks`),children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:i(`webhooks.heading`)}),(0,$.jsxs)(`div`,{className:`rounded-md border border-border p-3 space-y-3`,children:[(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:(0,$.jsx)(lt,{ns:`settings`,i18nKey:`webhooks.description`,components:{code:(0,$.jsx)(`code`,{className:`font-mono`})}})}),S.length>0&&(0,$.jsx)(`div`,{className:`space-y-1.5`,children:S.map(e=>{let t=(()=>{try{return JSON.parse(e.events)}catch{return[]}})();return(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-border p-2`,children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 space-y-0.5`,children:[(0,$.jsx)(`p`,{className:`text-xs font-mono truncate`,children:e.url}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:t.join(`, `)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,$.jsx)(`button`,{onClick:()=>void U(e.id,!e.enabled),className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${e.enabled?`bg-green-500/10 aurora-light:bg-accent-success/10 text-green-600 aurora-light:text-accent-success dark:text-green-400`:`bg-muted text-muted-foreground`}`,title:e.enabled?i(`webhooks.disable`):i(`webhooks.enable`),children:e.enabled?i(`webhooks.statusOn`):i(`webhooks.statusOff`)}),(0,$.jsx)(`button`,{onClick:()=>void ee(e.id),className:`text-muted-foreground hover:text-foreground p-0.5`,title:i(`webhooks.sendTestPing`),children:(0,$.jsx)(wn,{className:`w-3 h-3`})}),(0,$.jsx)(`button`,{onClick:()=>void W(e.id),className:`text-muted-foreground hover:text-destructive p-0.5`,title:i(`common:actions.remove`),children:(0,$.jsx)(Rn,{className:`w-3 h-3`})})]})]},e.id)})}),(0,$.jsxs)(`div`,{className:`space-y-2 border-t border-border pt-2`,children:[(0,$.jsx)(`p`,{className:`text-[10px] font-medium text-muted-foreground`,children:i(`webhooks.addHeading`)}),(0,$.jsx)(Jj,{value:w,onChange:e=>T(e.target.value),placeholder:`https://hooks.example.com/...`,className:`h-7 text-xs font-mono`}),(0,$.jsx)(Jj,{value:E,onChange:e=>D(e.target.value),placeholder:i(`webhooks.secretPlaceholder`),className:`h-7 text-xs font-mono`}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:$q.map(({value:e,labelKey:t})=>(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[10px] cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:O.includes(e),onChange:()=>te(e),className:`w-3 h-3`}),i(t)]},e))}),(0,$.jsxs)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs w-full`,disabled:A||!w.trim(),onClick:()=>void H(),children:[(0,$.jsx)(Pn,{className:`w-3 h-3 mr-1`}),i(`webhooks.addButton`)]})]})]})]})}),(0,$.jsx)(`div`,{className:l(`about`),children:n&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:i(`desktop.onboardingHeading`)}),(0,$.jsx)(`div`,{className:`rounded-md border border-border p-3`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium`,children:i(`desktop.platformTour`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:i(`desktop.platformTourDescription`)})]}),(0,$.jsxs)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs shrink-0`,onClick:n,"data-testid":`replay-onboarding`,children:[(0,$.jsx)(js,{className:`w-3 h-3 mr-1`}),i(`desktop.replayTour`)]})]})})]})}),(0,$.jsx)(`div`,{className:l(`terminal`),children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:i(`desktop.terminalPanelHeading`)}),(0,$.jsx)(BW,{mode:`desktop`})]})}),(0,$.jsx)(`div`,{className:l(`about`),children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:i(`desktop.infoHeading`)}),(0,$.jsxs)(`div`,{className:`rounded-md border border-border p-3 space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i(`desktop.infoPort`)}),(0,$.jsx)(`span`,{className:`font-mono`,children:u?.port??4200})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i(`desktop.infoProjects`)}),(0,$.jsx)(`span`,{className:`font-mono`,children:a.length})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i(`desktop.infoDb`)}),(0,$.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:`~/.specrails/desktop.sqlite`})]})]})]})})]})]})]})})}var rJ=[{keys:`?`,descriptionKey:`shortcuts.items.showCheatsheet`,category:`general`},{keys:`Esc`,descriptionKey:`shortcuts.items.closeModal`,category:`general`},{keys:`⌘B`,descriptionKey:`shortcuts.items.toggleRightSidebar`,category:`general`},{keys:`⌥⌘B`,descriptionKey:`shortcuts.items.toggleLeftSidebar`,category:`general`},{keys:`⌘J`,descriptionKey:`shortcuts.items.toggleTerminal`,category:`general`},...xe?[{keys:`⌘⇧A`,descriptionKey:`shortcuts.items.toggleAgent`,category:`general`}]:[],{keys:je?`⌘1–5`:`⌘1–4`,descriptionKey:je?`shortcuts.items.navigateProjectPageWithAgents`:`shortcuts.items.navigateProjectPage`,category:`general`},{keys:`⌥⌘1–9`,descriptionKey:`shortcuts.items.switchProject`,category:`general`},{keys:`G D`,descriptionKey:`shortcuts.items.goDashboard`,category:`navigation`},{keys:`G J`,descriptionKey:`shortcuts.items.goActivity`,category:`navigation`},{keys:`G A`,descriptionKey:`shortcuts.items.goAnalytics`,category:`navigation`},{keys:`G S`,descriptionKey:`shortcuts.items.goSettings`,category:`navigation`},{keys:`J`,descriptionKey:`shortcuts.items.nextItem`,category:`actions`},{keys:`K`,descriptionKey:`shortcuts.items.prevItem`,category:`actions`}];function iJ(e){let t=e.target;if(!t)return!1;let n=t.tagName;return!!(n===`INPUT`||n===`TEXTAREA`||n===`SELECT`||t.isContentEditable)}function aJ(e){let t=e.target;return!t||typeof t.closest!=`function`?!1:!!t.closest(`[role="dialog"]`)}function oJ(e){let t=e.target;return!t||typeof t.closest!=`function`?!1:!!t.closest(`.specrails-xterm-container, .xterm`)}function sJ({onOpenCheatsheet:e,onListNavigate:t,onToggleLeftSidebar:n,onToggleRightSidebar:r,onSwitchProject:i,onSwitchProjectPage:a,onToggleTerminalPanel:o,onToggleAgentChat:s}){let c=y(),l=p(),u=(0,Q.useRef)(null),d=(0,Q.useRef)(null),f=(0,Q.useRef)(e);f.current=e;let m=(0,Q.useRef)(t);m.current=t;let h=(0,Q.useRef)(n);h.current=n;let g=(0,Q.useRef)(r);g.current=r;let _=(0,Q.useRef)(i);_.current=i;let v=(0,Q.useRef)(a);v.current=a;let b=(0,Q.useRef)(o);b.current=o;let x=(0,Q.useRef)(s);x.current=s;let S=(0,Q.useRef)(l);S.current=l,(0,Q.useEffect)(()=>{function e(e){if((e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&e.code===`KeyJ`){if(aJ(e))return;e.preventDefault(),b.current?.();return}if((e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&e.code===`KeyA`){if(aJ(e))return;e.preventDefault(),x.current?.();return}if(iJ(e)||oJ(e)||aJ(e))return;if((e.metaKey||e.ctrlKey)&&!e.altKey&&e.code===`KeyB`){e.preventDefault(),g.current?.();return}if((e.metaKey||e.ctrlKey)&&e.altKey&&e.code===`KeyB`){e.preventDefault(),h.current?.();return}if((e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey){let t=e.code.match(/^Digit([1-9])$/);if(t){e.preventDefault(),v.current?.(parseInt(t[1],10));return}}if((e.metaKey||e.ctrlKey)&&e.altKey&&!e.shiftKey){let t=e.code.match(/^Digit([1-9])$/);if(t){e.preventDefault(),_.current?.(parseInt(t[1],10));return}}if(e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key;if(u.current===`g`){d.current&&clearTimeout(d.current),u.current=null;let n=t.toUpperCase(),r={D:`/`,P:`/`,J:`/activity`,A:`/analytics`,S:`/settings`};if(r[n]){e.preventDefault(),c(r[n]);return}return}if(t===`?`){e.preventDefault(),f.current();return}if(t===`g`){e.preventDefault(),u.current=`g`,d.current=setTimeout(()=>{u.current=null},800);return}if(t===`j`){m.current?.(`down`);return}if(t===`k`){m.current?.(`up`);return}}return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e),d.current&&clearTimeout(d.current)}},[c])}function cJ(){let[e,t]=(0,Q.useState)(!1);return{cheatsheetOpen:e,setCheatsheetOpen:t,openCheatsheet:(0,Q.useCallback)(()=>t(!0),[]),closeCheatsheet:(0,Q.useCallback)(()=>t(!1),[])}}var lJ={general:`shortcuts.categories.general`,navigation:`shortcuts.categories.navigation`,actions:`shortcuts.categories.actions`},uJ=[`general`,`navigation`,`actions`];function dJ({children:e}){return(0,$.jsx)(`kbd`,{className:`inline-flex items-center justify-center min-w-[1.5rem] h-6 px-1.5 rounded border border-border/50 bg-card/80 font-mono text-xs text-foreground`,children:e})}function fJ({shortcut:e}){let{t}=K(`commands`),n=mW(e.keys).split(` `);return(0,$.jsxs)(`div`,{className:`flex items-center justify-between py-1.5`,children:[(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:t(e.descriptionKey)}),(0,$.jsx)(`div`,{className:`flex items-center gap-1 ml-4 shrink-0`,children:n.map((e,t)=>(0,$.jsx)(dJ,{children:e},t))})]})}function pJ({open:e,onOpenChange:t}){let{t:n}=K(`commands`),r=uJ.map(e=>({category:e,label:n(lJ[e]),shortcuts:rJ.filter(t=>t.category===e)})).filter(e=>e.shortcuts.length>0);return(0,$.jsx)(mr,{open:e,onOpenChange:t,children:(0,$.jsxs)(fr,{movableResizable:!0,className:`max-w-md`,"data-testid":`shortcuts-cheatsheet`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:n(`shortcuts.title`)}),(0,$.jsx)(ir,{children:(0,$.jsxs)(lt,{i18nKey:`shortcuts.subtitle`,ns:`commands`,children:[`Press `,(0,$.jsx)(dJ,{children:`?`}),` anywhere to toggle this panel`]})})]}),(0,$.jsx)(`div`,{className:`space-y-4 mt-2`,children:r.map(e=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wider text-accent-primary mb-2`,children:e.label}),(0,$.jsx)(`div`,{className:`divide-y divide-border/30`,children:e.shortcuts.map(e=>(0,$.jsx)(fJ,{shortcut:e},e.keys))})]},e.category))})]})})}function mJ(){return typeof window<`u`&&`__TAURI_INTERNALS__`in window}function hJ(){return mJ()&&/mac/i.test(navigator.platform)}function gJ({onClick:e,icon:t,hoverColor:n=`var(--color-accent)`,hoverTextColor:r=`var(--color-accent-foreground)`,ariaLabel:i}){let[a,o]=(0,Q.useState)(!1);return(0,$.jsx)(`button`,{onClick:e,"aria-label":i,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{width:34,height:28,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:7,border:`none`,cursor:`pointer`,background:a?n:`transparent`,color:a?r:`var(--color-muted-foreground)`,transition:`background 0.12s ease, color 0.12s ease`,WebkitAppRegion:`no-drag`},children:t})}function _J({projectName:e,hidden:t=!1}){let{t:n}=K(`nav`),[r,i]=(0,Q.useState)(!1);function a(){window.dispatchEvent(new KeyboardEvent(`keydown`,{key:`k`,metaKey:!0,bubbles:!0}))}return(0,$.jsxs)(`button`,{onClick:a,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),"aria-label":n(`titleBar.searchShortcut`),"aria-hidden":t||void 0,tabIndex:t?-1:void 0,style:{position:`absolute`,left:`50%`,top:`50%`,transform:`translate(-50%, -50%) scale(${t?.96:1})`,width:`40%`,maxWidth:360,minWidth:160,height:20,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:5,paddingLeft:8,paddingRight:8,borderRadius:9999,border:`1px solid color-mix(in srgb, var(--color-border) 70%, transparent)`,cursor:`pointer`,background:r?`color-mix(in srgb, var(--color-accent) 82%, transparent)`:`color-mix(in srgb, var(--color-surface) 72%, transparent)`,color:e?`var(--color-foreground)`:`var(--color-muted-foreground)`,fontSize:12,fontWeight:400,letterSpacing:0,opacity:+!t,pointerEvents:t?`none`:`auto`,transition:`background 0.12s ease, opacity 0.22s ease, transform 0.22s ease`,WebkitAppRegion:`no-drag`,overflow:`hidden`,whiteSpace:`nowrap`},children:[(0,$.jsx)(In,{size:11,style:{flexShrink:0,opacity:e?.72:.48}}),(0,$.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e??n(`titleBar.searchPlaceholder`)})]})}function vJ(){return mJ()?hJ()?(0,$.jsx)(yJ,{}):(0,$.jsx)(bJ,{}):null}function yJ(){let{projects:e,activeProjectId:t}=pt(),{uiMode:n}=MN();return(0,$.jsx)(`div`,{"data-tauri-drag-region":!0,style:{position:`relative`,height:28,minHeight:28,background:`var(--color-background-deep)`,display:`flex`,alignItems:`center`,userSelect:`none`,flexShrink:0,borderBottom:`1px solid var(--color-border)`},children:(0,$.jsx)(_J,{projectName:(e.find(e=>e.id===t)??null)?.name??null,hidden:n===`agent`})})}function bJ(){let{t:e}=K(`nav`),{projects:t,activeProjectId:n}=pt(),{uiMode:r}=MN(),i=t.find(e=>e.id===n)??null,a=(0,Q.useMemo)(()=>_P(),[]),[o,s]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=!1,t=0,n,r=async()=>{let n=++t;try{let r=await a.isMaximized?.();!e&&n===t&&s(r===!0)}catch{}};return r(),a.onResized?.(()=>{r()}).then(t=>{e?t():n=t}).catch(()=>{}),()=>{e=!0,n?.()}},[a]);let c=(0,Q.useCallback)(()=>{a.minimize()},[a]),l=(0,Q.useCallback)(()=>{a.toggleMaximize()},[a]),u=(0,Q.useCallback)(()=>{a.close()},[a]);return(0,$.jsxs)(`div`,{"data-tauri-drag-region":!0,style:{position:`relative`,height:36,minHeight:36,background:`var(--color-background-deep)`,display:`flex`,alignItems:`center`,justifyContent:`space-between`,padding:`0 10px`,userSelect:`none`,flexShrink:0,borderBottom:`1px solid var(--color-border)`},children:[(0,$.jsx)(_J,{projectName:i?.name??null,hidden:r===`agent`}),(0,$.jsx)(`div`,{"data-tauri-drag-region":!0,style:{minWidth:116,height:`100%`}}),(0,$.jsxs)(`div`,{style:{minWidth:116,display:`flex`,justifyContent:`flex-end`,gap:2,alignItems:`center`,WebkitAppRegion:`no-drag`},children:[(0,$.jsx)(gJ,{onClick:c,icon:(0,$.jsx)(Ys,{size:14,strokeWidth:1.8}),ariaLabel:e(`titleBar.minimizeWindow`)}),(0,$.jsx)(gJ,{onClick:l,icon:o?(0,$.jsx)(ls,{size:12,strokeWidth:1.8}):(0,$.jsx)(Nn,{size:12,strokeWidth:1.8}),ariaLabel:e(o?`titleBar.restoreWindow`:`titleBar.maximizeWindow`)}),(0,$.jsx)(gJ,{onClick:u,icon:(0,$.jsx)(Vn,{size:15,strokeWidth:1.8}),hoverColor:`var(--color-destructive)`,hoverTextColor:`var(--color-destructive-foreground)`,ariaLabel:e(`titleBar.closeWindow`)})]})]})}var xJ=`アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン0123456789ABCDEF`,SJ=16,CJ=SJ,wJ=SJ*1.1,TJ=180,EJ=340,DJ=.07,OJ=.22,kJ=18,AJ=600,jJ=48,MJ=160,NJ=360;function PJ(){return xJ[Math.floor(Math.random()*61)]??` `}function FJ(e){return{head:-Math.random()*Math.max(e,12),speed:DJ+Math.random()*(OJ-DJ),glyphs:Array.from({length:kJ},()=>PJ()),nextSwapAt:0}}function IJ(){let e=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(typeof window>`u`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return;let t=e.current;if(!t)return;let n=t.getContext(`2d`,{alpha:!0});if(!n)return;let r=t,i=n,a=[],o=null,s=[],c=0,l=0,u=!document.hidden;function d(){let e=window.devicePixelRatio||1,t=window.innerWidth,n=window.innerHeight;r.width=Math.max(1,Math.floor(t*e)),r.height=Math.max(1,Math.floor(n*e)),r.style.width=`${t}px`,r.style.height=`${n}px`,i.setTransform(e,0,0,e,0,0),i.font=`${SJ}px "DM Mono", "JetBrains Mono", "Fira Code", ui-monospace, monospace`,i.textBaseline=`top`;let o=Math.ceil(t/CJ),s=Math.ceil(n/wJ);if(a.length===0)a=Array.from({length:o},()=>FJ(s));else if(a.length<o){let e=Array.from({length:o-a.length},()=>FJ(s));a=a.concat(e)}else a.length>o&&(a=a.slice(0,o))}function f(e){let t=performance.now();o&&(Math.abs(o.x-e.clientX)>=2||Math.abs(o.y-e.clientY)>=2)&&(s.push({x:o.x,y:o.y,t}),s.length>jJ&&s.splice(0,s.length-jJ)),o={x:e.clientX,y:e.clientY}}function p(){o=null}function m(){u=!document.hidden,u?(l=0,c=requestAnimationFrame(h)):cancelAnimationFrame(c)}function h(e){if(!u)return;let t=l===0?1:Math.min(2.5,(e-l)/16.67);l=e;let n=performance.now();for(;s.length>0&&n-s[0].t>AJ;)s.shift();let r=window.innerWidth,d=window.innerHeight;i.clearRect(0,0,r,d);let f=Math.ceil(d/wJ),p=o!==null||s.length>0;for(let r=0;r<a.length;r++){let c=a[r];if(c.head+=c.speed*t,c.head-kJ>f+4&&(c.head=-Math.random()*12,c.speed=DJ+Math.random()*(OJ-DJ)),e>c.nextSwapAt&&(c.glyphs[Math.floor(Math.random()*kJ)]=PJ(),c.nextSwapAt=e+MJ+Math.random()*NJ),!p)continue;let l=r*CJ+CJ/2,u=o===null?1/0:Math.abs(l-o.x);for(let e of s){let t=Math.abs(l-e.x);if(t<u&&(u=t),u===0)break}if(!(u>EJ))for(let e=0;e<kJ;e++){let t=c.head-e;if(t<-1||t>f+2)continue;let a=t*wJ,u=0;if(o!==null){let e=l-o.x,t=a-o.y,n=Math.sqrt(e*e+t*t);if(n<=EJ){let e=n<TJ?1:1-(n-TJ)/(EJ-TJ);e>u&&(u=e)}}if(u<.999)for(let e of s){let t=l-e.x,r=a-e.y,i=Math.sqrt(t*t+r*r);if(i>EJ)continue;let o=i<TJ?1:1-(i-TJ)/(EJ-TJ),s=n-e.t,c=o*(s>AJ?0:1-s/AJ);if(c>u&&(u=c),u>=.999)break}if(u<.02)continue;let d=1-e/kJ,p=u*d*.85;p<.02||(i.fillStyle=e===0?`hsla(150, 100%, 92%, ${p.toFixed(3)})`:`hsla(144, 100%, 55%, ${p.toFixed(3)})`,i.fillText(c.glyphs[e],r*CJ,a))}}c=requestAnimationFrame(h)}return d(),window.addEventListener(`resize`,d),window.addEventListener(`pointermove`,f),document.addEventListener(`mouseleave`,p),document.addEventListener(`visibilitychange`,m),c=requestAnimationFrame(h),()=>{cancelAnimationFrame(c),window.removeEventListener(`resize`,d),window.removeEventListener(`pointermove`,f),document.removeEventListener(`mouseleave`,p),document.removeEventListener(`visibilitychange`,m)}},[]),(0,$.jsx)(`canvas`,{ref:e,"aria-hidden":!0,className:`fixed inset-0 pointer-events-none`,style:{zIndex:-1}})}var LJ=24,RJ=200,zJ=3.5,BJ=10,VJ=`hsl(210, 60%, 96%)`,HJ=`hsl(212, 100%, 62%)`;function UJ(){let e=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(typeof window>`u`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return;let t=e.current;if(!t)return;let n=t.getContext(`2d`,{alpha:!0});if(!n)return;let r=t,i=n,a=[],o=0,s=!document.hidden;function c(){let e=window.devicePixelRatio||1,t=window.innerWidth,n=window.innerHeight;r.width=Math.max(1,Math.floor(t*e)),r.height=Math.max(1,Math.floor(n*e)),r.style.width=`${t}px`,r.style.height=`${n}px`,i.setTransform(e,0,0,e,0,0)}function l(e){let t=performance.now();a.push({x:e.clientX,y:e.clientY,t}),a.length>LJ&&a.splice(0,a.length-LJ)}function u(){a=[]}function d(){s=!document.hidden,s?o=requestAnimationFrame(f):cancelAnimationFrame(o)}function f(){if(!s)return;let e=performance.now();for(;a.length>0&&e-a[0].t>RJ;)a.shift();let t=window.innerWidth,n=window.innerHeight;if(i.clearRect(0,0,t,n),a.length>=2){i.lineCap=`round`,i.lineJoin=`round`,i.shadowColor=HJ;for(let t=1;t<a.length;t++){let n=a[t-1],r=a[t],o=e-r.t,s=Math.max(0,1-o/RJ);if(s<=0)continue;let c=t/a.length;i.globalAlpha=s*(.25+.75*c),i.lineWidth=Math.max(.5,zJ*c),i.shadowBlur=BJ*c,i.strokeStyle=c>.6?VJ:HJ,i.beginPath(),i.moveTo(n.x,n.y),i.lineTo(r.x,r.y),i.stroke()}i.globalAlpha=1,i.shadowBlur=0}o=requestAnimationFrame(f)}return c(),window.addEventListener(`resize`,c),window.addEventListener(`pointermove`,l),document.addEventListener(`mouseleave`,u),document.addEventListener(`visibilitychange`,d),o=requestAnimationFrame(f),()=>{cancelAnimationFrame(o),window.removeEventListener(`resize`,c),window.removeEventListener(`pointermove`,l),document.removeEventListener(`mouseleave`,u),document.removeEventListener(`visibilitychange`,d)}},[]),(0,$.jsx)(`canvas`,{ref:e,"aria-hidden":!0,className:`fixed inset-0 pointer-events-none`,style:{zIndex:-1}})}var WJ={"code-rain":IJ,galaxy:UJ};function GJ(){let e=WJ[wa().id];return e?(0,$.jsx)(e,{}):null}function KJ({project:e}){let{t}=K(`nav`),n=$V(),{registerHandler:r,unregisterHandler:i}=tt(),[a,o]=(0,Q.useState)(null),s=(0,Q.useRef)(e.id);return s.current=e.id,(0,Q.useEffect)(()=>{let n=`cost-alerts-${e.id}`;return r(n,e=>{let n=e;n.projectId!==void 0&&n.projectId!==``&&n.projectId!==s.current||(n.type===`cost_alert`?J.warning(t(`costAlerts.costAlertTitle`),{description:t(`costAlerts.costAlertDescription`,{cost:(n.cost??0).toFixed(4),threshold:(n.threshold??0).toFixed(2)})}):n.type===`daily_budget_exceeded`?(J.error(t(`costAlerts.dailyBudgetTitle`),{description:t(`costAlerts.dailyBudgetDescription`,{spent:(n.dailySpend??0).toFixed(2),budget:(n.budget??0).toFixed(2)}),duration:1/0}),o({dailySpend:n.dailySpend??0,budget:n.budget??0})):n.type===`desktop_daily_budget_exceeded`&&J.error(t(`costAlerts.desktopBudgetTitle`),{description:t(`costAlerts.desktopBudgetDescription`,{spent:(n.desktopDailySpend??0).toFixed(2),budget:(n.desktopBudget??0).toFixed(2)}),duration:1/0}))}),()=>i(n)},[e.id,r,i,t]),(0,$.jsx)(dA,{delayDuration:400,children:(0,$.jsx)(ZV.Provider,{value:n,children:(0,$.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[a&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 bg-destructive/10 border-b border-destructive/20 text-xs`,children:[(0,$.jsx)(`span`,{className:`text-destructive font-medium`,children:t(`costAlerts.bannerMessage`,{spent:a.dailySpend.toFixed(2),budget:a.budget.toFixed(2)})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>o(null),className:`text-muted-foreground hover:text-foreground ml-4 shrink-0`,children:t(`costAlerts.dismiss`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-1 overflow-hidden min-h-0`,children:[(0,$.jsx)(`main`,{className:`flex-1 overflow-auto`,children:(0,$.jsx)(l,{})}),!1]})]})})})}function qJ({projectName:e,errorMessage:t,onRetry:n}){let{t:r}=K(`nav`);return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 p-8`,children:[(0,$.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,$.jsx)(`h2`,{className:`text-base font-semibold`,children:r(`errorBoundary.title`)}),e&&(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:(0,$.jsx)(lt,{ns:`nav`,i18nKey:`errorBoundary.occurredIn`,values:{name:e},components:{strong:(0,$.jsx)(`span`,{className:`font-medium`})}})}),t&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/60 font-mono`,children:t})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:n,className:`flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,children:[(0,$.jsx)(mc,{className:`w-3.5 h-3.5`}),r(`common:actions.retry`)]})]})}var JJ=class extends Q.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`[ProjectErrorBoundary]`,e,t.componentStack)}handleRetry=()=>{this.setState({hasError:!1,error:null})};render(){return this.state.hasError?(0,$.jsx)(qJ,{projectName:this.props.projectName,errorMessage:this.state.error?.message??null,onRetry:this.handleRetry}):this.props.children}};function YJ({onAddProject:e}){let{t}=K(`setup`);return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full min-h-[400px] gap-6 px-8 text-center`,children:[(0,$.jsx)(`div`,{className:`w-14 h-14 rounded-2xl bg-muted/50 flex items-center justify-center`,children:(0,$.jsx)(Ac,{className:`w-7 h-7 text-muted-foreground`})}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h2`,{className:`text-base font-semibold`,children:(0,$.jsx)(lt,{t,i18nKey:`welcome.title`,components:{spec:(0,$.jsx)(`span`,{className:`text-accent-primary`}),rails:(0,$.jsx)(`span`,{className:`text-accent-secondary`})}})}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-sm`,children:t(`welcome.description`)}),re&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 max-w-sm`,children:t(`welcome.jiraHint`)}),oe&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 max-w-sm`,children:t(`welcome.mcpHint`)}),xe&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 max-w-sm`,children:t(`welcome.agentChatHint`)}),Ce&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 max-w-sm`,children:t(`welcome.localEnginesHint`)})]}),(0,$.jsxs)(Z,{onClick:e,size:`sm`,className:`gap-2`,children:[(0,$.jsx)(Ts,{className:`w-3.5 h-3.5`}),t(`welcome.addFirstProject`)]})]})}var XJ=`https://specrails.dev/companion-app/`,ZJ=`specrails-desktop:onboarding-dismissed`;function QJ(){try{return localStorage.getItem(ZJ)===`true`}catch{return!1}}function $J(){try{localStorage.setItem(ZJ,`true`)}catch{}}var eY=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform||``),tY=eY?`⌘`:`Ctrl`,nY=eY?`⌥`:`Alt`,rY={primary:{text:`text-accent-primary`,bar:`bg-accent-primary`,glow:`glow-primary`,btn:`bg-accent-primary hover:bg-accent-primary/90 text-primary-foreground`,softBorder:`border-accent-primary/30`,softBg:`bg-accent-primary/5`,chipBg:`bg-accent-primary/10 text-accent-primary`},info:{text:`text-accent-info`,bar:`bg-accent-info`,glow:`glow-info`,btn:`bg-accent-info hover:bg-accent-info/90 text-primary-foreground`,softBorder:`border-accent-info/30`,softBg:`bg-accent-info/5`,chipBg:`bg-accent-info/10 text-accent-info`},success:{text:`text-accent-success`,bar:`bg-accent-success`,glow:`glow-success`,btn:`bg-accent-success hover:bg-accent-success/90 text-primary-foreground`,softBorder:`border-accent-success/30`,softBg:`bg-accent-success/5`,chipBg:`bg-accent-success/10 text-accent-success`},secondary:{text:`text-accent-secondary`,bar:`bg-accent-secondary`,glow:`glow-secondary`,btn:`bg-accent-secondary hover:bg-accent-secondary/90 text-primary-foreground`,softBorder:`border-accent-secondary/30`,softBg:`bg-accent-secondary/5`,chipBg:`bg-accent-secondary/10 text-accent-secondary`},warning:{text:`text-accent-warning`,bar:`bg-accent-warning`,glow:`glow-warning`,btn:`bg-accent-warning hover:bg-accent-warning/90 text-primary-foreground`,softBorder:`border-accent-warning/30`,softBg:`bg-accent-warning/5`,chipBg:`bg-accent-warning/10 text-accent-warning`},highlight:{text:`text-accent-highlight`,bar:`bg-accent-highlight`,glow:`glow-highlight`,btn:`bg-accent-highlight hover:bg-accent-highlight/90 text-primary-foreground`,softBorder:`border-accent-highlight/30`,softBg:`bg-accent-highlight/5`,chipBg:`bg-accent-highlight/10 text-accent-highlight`}};function iY({children:e}){return(0,$.jsx)(`kbd`,{className:`inline-flex items-center justify-center min-w-[1.5rem] h-5 px-1.5 rounded border border-border/60 bg-card/80 font-mono text-[11px] text-foreground shadow-sm`,children:e})}function aY({icon:e,label:t,children:n,accent:r}){return(0,$.jsxs)(`div`,{className:`flex gap-3 items-start`,children:[(0,$.jsx)(`div`,{className:X(`mt-0.5 shrink-0 grid place-items-center w-7 h-7 rounded-md border border-border/40`,r.softBg,r.text),children:e}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-[13px] font-semibold text-foreground leading-tight`,children:t}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground leading-relaxed`,children:n})]})]})}function oY({accent:e,label:t,children:n}){return(0,$.jsxs)(`div`,{className:X(`rounded-lg border p-3`,e.softBorder,e.softBg),children:[t&&(0,$.jsx)(`p`,{className:X(`text-[10px] font-semibold uppercase tracking-wider mb-1.5`,e.text),children:t}),(0,$.jsx)(`div`,{className:`text-xs text-foreground/90 leading-relaxed`,children:n})]})}function sY({steps:e}){return(0,$.jsx)(`div`,{className:`flex items-center gap-2 flex-wrap text-[13px] font-medium`,children:e.map((t,n)=>(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:t.cls,children:t.label}),n<e.length-1&&(0,$.jsx)(ce,{className:`w-3.5 h-3.5 text-muted-foreground`})]},t.label))})}function cY(){let{t:e}=K(`setup`);return(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:e(`onboarding.language.intro`)}),(0,$.jsx)(aK,{}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:e(`onboarding.language.note`)})]})}function lY(){let{t:e}=K(`setup`);return(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:e(`onboarding.theme.intro`)}),(0,$.jsx)(ZG,{}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:e(`onboarding.theme.note`)})]})}function uY({icon:e,url:t,label:n,testId:r}){return(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border border-border/40 bg-card/40 p-3`,children:[(0,$.jsx)(`div`,{className:`shrink-0 rounded-md bg-white p-1.5`,"aria-hidden":`true`,children:(0,$.jsx)(Dq,{value:t,size:72})}),(0,$.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[13px] font-semibold text-foreground leading-tight`,children:[e,n]}),(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,"data-testid":r,"aria-label":n,className:`inline-flex items-center gap-1 text-xs text-accent-info hover:underline break-all`,children:[t.replace(`https://`,``),(0,$.jsx)(pn,{className:`w-3 h-3 shrink-0`,"aria-hidden":`true`})]})]})]})}function dY(){let{t:e}=K(`setup`);return(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.companion.intro`,components:{b:(0,$.jsx)(`span`,{className:`text-foreground font-medium`})}})}),(0,$.jsx)(oY,{accent:rY.success,label:e(`onboarding.companion.localLabel`),children:e(`onboarding.companion.localBody`)}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`p`,{className:`text-[13px] font-semibold text-foreground`,children:e(`onboarding.companion.downloadLabel`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`onboarding.companion.downloadHint`)}),(0,$.jsx)(uY,{icon:(0,$.jsx)(Tc,{className:`w-4 h-4 shrink-0`,"aria-hidden":`true`}),url:XJ,label:e(`onboarding.companion.open`),testId:`companion-web-link`})]}),(0,$.jsx)(aY,{icon:(0,$.jsx)(dc,{className:`w-4 h-4`}),label:e(`onboarding.companion.pairLabel`),accent:rY.success,children:e(`onboarding.companion.pairBody`)})]})}function fY(e){let t={b:(0,$.jsx)(`span`,{className:`text-foreground font-medium`})};return[{navLabel:e(`onboarding.language.nav`),icon:(0,$.jsx)(Bs,{className:`w-6 h-6`}),accent:rY.info,title:e(`onboarding.language.title`),subtitle:e(`onboarding.language.subtitle`),content:(0,$.jsx)(cY,{})},{navLabel:e(`onboarding.theme.nav`),icon:(0,$.jsx)(ec,{className:`w-6 h-6`}),accent:rY.highlight,title:e(`onboarding.theme.title`),subtitle:e(`onboarding.theme.subtitle`),content:(0,$.jsx)(lY,{})},{navLabel:e(`onboarding.welcome.nav`),icon:(0,$.jsx)(Ln,{className:`w-6 h-6`}),accent:rY.primary,title:e(`onboarding.welcome.title`),subtitle:e(`onboarding.welcome.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.welcome.intro`,components:t})}),(0,$.jsxs)(oY,{accent:rY.primary,label:e(`onboarding.welcome.coreLoopLabel`),children:[(0,$.jsx)(sY,{steps:[{label:e(`onboarding.flow.describe`),cls:`text-accent-info`},{label:e(`onboarding.flow.specs`),cls:`text-accent-success`},{label:e(`onboarding.flow.rails`),cls:`text-accent-warning`},{label:e(`onboarding.flow.review`),cls:`text-accent-secondary`}]}),(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.welcome.flowCaption`,components:t})})]}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-4`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(Vo,{className:`w-4 h-4`}),label:e(`onboarding.welcome.missionLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.welcome.missionBody`,components:t})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Vs,{className:`w-4 h-4`}),label:e(`onboarding.welcome.boardLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.welcome.boardBody`,components:t})})]}),(0,$.jsxs)(`div`,{className:`flex gap-3 items-start`,children:[(0,$.jsx)(Cc,{className:`w-4 h-4 mt-0.5 shrink-0 text-accent-success`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.welcome.localNote`,components:{...t,i:(0,$.jsx)(`span`,{className:`italic`})}})})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:e(`onboarding.welcome.tourNote`)})]})},...xe?[{navLabel:e(`onboarding.mission.nav`),icon:(0,$.jsx)(Vo,{className:`w-6 h-6`}),accent:rY.primary,title:e(`onboarding.mission.title`),subtitle:e(`onboarding.mission.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.mission.intro`,components:t})}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-4`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(O,{className:`w-4 h-4`}),label:e(`onboarding.mission.missionsLabel`),accent:rY.primary,children:e(`onboarding.mission.missionsBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Cc,{className:`w-4 h-4`}),label:e(`onboarding.mission.levelsLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.mission.levelsBody`,components:{...t,shift:(0,$.jsx)(iY,{children:`Shift`}),tab:(0,$.jsx)(iY,{children:`Tab`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(kn,{className:`w-4 h-4`}),label:e(`onboarding.mission.cardsLabel`),accent:rY.primary,children:e(`onboarding.mission.cardsBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Ho,{className:`w-4 h-4`}),label:e(`onboarding.mission.workspaceLabel`),accent:rY.primary,children:e(`onboarding.mission.workspaceBody`)})]}),(0,$.jsx)(oY,{accent:rY.primary,label:e(`onboarding.mission.mcpLabel`),children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.mission.mcpBody`,components:t})})]})}]:[],...se?[{navLabel:e(`onboarding.builder.nav`),icon:(0,$.jsx)(Ns,{className:`w-6 h-6`}),accent:rY.highlight,title:e(`onboarding.builder.title`),subtitle:e(`onboarding.builder.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.builder.intro`,components:t})}),(0,$.jsxs)(oY,{accent:rY.highlight,label:e(`onboarding.builder.flowLabel`),children:[(0,$.jsx)(sY,{steps:[{label:e(`onboarding.flow.blueprint`),cls:`text-accent-info`},{label:e(`onboarding.flow.approve`),cls:`text-accent-success`},{label:e(`onboarding.flow.m1Specs`),cls:`text-accent-warning`},{label:e(`onboarding.flow.milestones`),cls:`text-accent-secondary`}]}),(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:e(`onboarding.builder.flowCaption`)})]}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-4`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(Fc,{className:`w-4 h-4`}),label:e(`onboarding.builder.cardsLabel`),accent:rY.highlight,children:e(`onboarding.builder.cardsBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(bs,{className:`w-4 h-4`}),label:e(`onboarding.builder.specsLabel`),accent:rY.highlight,children:e(`onboarding.builder.specsBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(gc,{className:`w-4 h-4`}),label:e(`onboarding.builder.milestonesLabel`),accent:rY.highlight,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.builder.milestonesBody`,components:t})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Ds,{className:`w-4 h-4`}),label:e(`onboarding.builder.progressLabel`),accent:rY.highlight,children:e(`onboarding.builder.progressBody`)})]})]})}]:[],{navLabel:e(`onboarding.authorSpecs.nav`),icon:(0,$.jsx)(O,{className:`w-6 h-6`}),accent:rY.info,title:e(`onboarding.authorSpecs.title`),subtitle:e(`onboarding.authorSpecs.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.authorSpecs.intro`,components:t})}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-4`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(Vo,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.agentLabel`),accent:rY.info,children:e(`onboarding.authorSpecs.agentBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(O,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.exploreLabel`),accent:rY.info,children:e(`onboarding.authorSpecs.exploreBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(wn,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.quickLabel`),accent:rY.info,children:e(`onboarding.authorSpecs.quickBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(D,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.websiteLabel`),accent:rY.info,children:e(`onboarding.authorSpecs.websiteBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(vc,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.smashLabel`),accent:rY.info,children:e(`onboarding.authorSpecs.smashBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(dn,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.draftsLabel`),accent:rY.info,children:e(`onboarding.authorSpecs.draftsBody`)})]}),re&&(0,$.jsx)(oY,{accent:rY.info,label:e(`onboarding.jira.label`),children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.jira.body`,components:t})})]})},{navLabel:e(`onboarding.rails.nav`),icon:(0,$.jsx)(Lc,{className:`w-6 h-6`}),accent:rY.success,title:e(`onboarding.rails.title`),subtitle:e(`onboarding.rails.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.rails.intro`,components:{...t,play:(0,$.jsx)(`span`,{className:`text-accent-warning font-medium`})}})}),(0,$.jsxs)(oY,{accent:rY.success,label:e(`onboarding.rails.jobLabel`),children:[(0,$.jsx)(sY,{steps:[{label:e(`onboarding.flow.architect`),cls:`text-accent-info`},{label:e(`onboarding.flow.developer`),cls:`text-accent-success`},{label:e(`onboarding.flow.reviewer`),cls:`text-accent-warning`},{label:e(`onboarding.flow.yourReview`),cls:`text-accent-secondary`}]}),(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:e(`onboarding.rails.flowCaption`)})]}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-4`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(On,{className:`w-4 h-4`}),label:e(`onboarding.rails.reviewLabel`),accent:rY.success,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.rails.reviewBody`,components:t})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(vs,{className:`w-4 h-4`}),label:e(`onboarding.rails.packetLabel`),accent:rY.success,children:e(`onboarding.rails.packetBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(O,{className:`w-4 h-4`}),label:e(`onboarding.rails.steerLabel`),accent:rY.success,children:e(`onboarding.rails.steerBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(hc,{className:`w-4 h-4`}),label:e(`onboarding.rails.loopsLabel`),accent:rY.success,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.rails.loopsBody`,components:t})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Vo,{className:`w-4 h-4`}),label:e(`onboarding.rails.profilesLabel`),accent:rY.success,children:e(`onboarding.rails.profilesBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Ts,{className:`w-4 h-4`}),label:e(`onboarding.rails.isolationLabel`),accent:rY.success,children:e(`onboarding.rails.isolationBody`)})]})]})},{navLabel:e(`onboarding.providers.nav`),icon:(0,$.jsx)(Vo,{className:`w-6 h-6`}),accent:rY.secondary,title:e(`onboarding.providers.title`),subtitle:e(`onboarding.providers.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.providers.intro`,components:t})}),(0,$.jsxs)(`div`,{className:`rounded-lg border border-border/40 overflow-hidden text-xs`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-[1.4fr_1fr_1fr_1fr_1fr] bg-card/40`,children:[(0,$.jsx)(`div`,{className:`px-3 py-2 font-semibold text-muted-foreground`,children:e(`onboarding.providers.table.capability`)}),(0,$.jsx)(`div`,{className:`px-3 py-2 font-semibold text-accent-secondary text-center`,children:`Claude Code`}),(0,$.jsx)(`div`,{className:`px-3 py-2 font-semibold text-accent-success text-center`,children:`Codex CLI`}),(0,$.jsx)(`div`,{className:`px-3 py-2 font-semibold text-accent-info text-center`,children:`Gemini CLI`}),(0,$.jsx)(`div`,{className:`px-3 py-2 font-semibold text-purple-300 text-center`,children:`Kimi Code`})]}),[[e(`onboarding.providers.table.streamingResume`),e(`onboarding.providers.table.native`),e(`onboarding.providers.table.native`),e(`onboarding.providers.table.native`),e(`onboarding.providers.table.native`)],[e(`onboarding.providers.table.costReporting`),e(`onboarding.providers.table.providerBilled`),e(`onboarding.providers.table.estimated`),e(`onboarding.providers.table.estimated`),e(`onboarding.providers.table.unavailable`)],[e(`onboarding.providers.table.telemetry`),e(`onboarding.providers.table.native`),e(`onboarding.providers.table.synthesized`),e(`onboarding.providers.table.native`),e(`onboarding.providers.table.synthesized`)],[e(`onboarding.providers.table.agentProfiles`),e(`common:states.yes`),`—`,`—`,e(`common:states.yes`)]].map(e=>(0,$.jsxs)(`div`,{className:`grid grid-cols-[1.4fr_1fr_1fr_1fr_1fr] border-t border-border/30`,children:[(0,$.jsx)(`div`,{className:`px-3 py-2 text-foreground/90`,children:e[0]}),(0,$.jsx)(`div`,{className:`px-3 py-2 text-center text-muted-foreground`,children:e[1]}),(0,$.jsx)(`div`,{className:`px-3 py-2 text-center text-muted-foreground`,children:e[2]}),(0,$.jsx)(`div`,{className:`px-3 py-2 text-center text-muted-foreground`,children:e[3]}),(0,$.jsx)(`div`,{className:`px-3 py-2 text-center text-muted-foreground`,children:e[4]})]},e[0]))]}),(0,$.jsx)(oY,{accent:rY.secondary,label:e(`onboarding.providers.calloutLabel`),children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.providers.calloutBody`,components:{...t,mono:(0,$.jsx)(`span`,{className:`font-mono`})}})})]})},{navLabel:e(`onboarding.cost.nav`),icon:(0,$.jsx)(os,{className:`w-6 h-6`}),accent:rY.warning,title:e(`onboarding.cost.title`),subtitle:e(`onboarding.cost.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.cost.intro`,components:t})}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-4`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(Ds,{className:`w-4 h-4`}),label:e(`onboarding.cost.analyticsLabel`),accent:rY.warning,children:e(`onboarding.cost.analyticsBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(pc,{className:`w-4 h-4`}),label:e(`onboarding.cost.perTicketLabel`),accent:rY.warning,children:e(`onboarding.cost.perTicketBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(hs,{className:`w-4 h-4`}),label:e(`onboarding.cost.honestLabel`),accent:rY.warning,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.cost.honestBody`,components:{mono:(0,$.jsx)(`span`,{className:`font-mono`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Pc,{className:`w-4 h-4`}),label:e(`onboarding.cost.budgetsLabel`),accent:rY.warning,children:e(`onboarding.cost.budgetsBody`)})]})]})},{navLabel:e(`onboarding.workspace.nav`),icon:(0,$.jsx)(Ho,{className:`w-6 h-6`}),accent:rY.highlight,title:e(`onboarding.workspace.title`),subtitle:e(`onboarding.workspace.subtitle`),content:(0,$.jsx)(`div`,{className:`space-y-4`,children:(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-4`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(Ac,{className:`w-4 h-4`}),label:e(`onboarding.workspace.terminalLabel`),accent:rY.highlight,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.workspace.terminalBody`,values:{mod:tY},components:{mod:(0,$.jsx)(iY,{children:tY}),j:(0,$.jsx)(iY,{children:`J`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(bs,{className:`w-4 h-4`}),label:e(`onboarding.workspace.codeLabel`),accent:rY.highlight,children:e(`onboarding.workspace.codeBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(D,{className:`w-4 h-4`}),label:e(`onboarding.workspace.browserLabel`),accent:rY.highlight,children:e(`onboarding.workspace.browserBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(lc,{className:`w-4 h-4`}),label:e(`onboarding.workspace.integrationsLabel`),accent:rY.highlight,children:e(`onboarding.workspace.integrationsBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(ec,{className:`w-4 h-4`}),label:e(`onboarding.workspace.themesLabel`),accent:rY.highlight,children:e(`onboarding.workspace.themesBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(kn,{className:`w-4 h-4`}),label:e(`onboarding.workspace.chatsLabel`),accent:rY.highlight,children:e(`onboarding.workspace.chatsBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(U,{className:`w-4 h-4`}),label:e(`onboarding.workspace.compareLabel`),accent:rY.highlight,children:e(`onboarding.workspace.compareBody`)}),(0,$.jsx)(aY,{icon:(0,$.jsx)(gc,{className:`w-4 h-4`}),label:e(`onboarding.workspace.desktopLabel`),accent:rY.highlight,children:e(`onboarding.workspace.desktopBody`)})]})})},{navLabel:e(`onboarding.companion.nav`),icon:(0,$.jsx)(Tc,{className:`w-6 h-6`}),accent:rY.success,title:e(`onboarding.companion.title`),subtitle:e(`onboarding.companion.subtitle`),content:(0,$.jsx)(dY,{})},{navLabel:e(`onboarding.moveFast.nav`),icon:(0,$.jsx)(cs,{className:`w-6 h-6`}),accent:rY.primary,title:e(`onboarding.moveFast.title`),subtitle:e(`onboarding.moveFast.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(oY,{accent:rY.primary,label:e(`onboarding.moveFast.paletteLabel`),children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.paletteShortcut`,values:{mod:tY},components:{f:(0,$.jsx)(`span`,{className:`text-foreground`}),m:(0,$.jsx)(`span`,{className:`text-muted-foreground`}),mod:(0,$.jsx)(iY,{children:tY}),k:(0,$.jsx)(iY,{children:`K`})}})}),e(`onboarding.moveFast.paletteBody`)]}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-3`,children:[(0,$.jsx)(aY,{icon:(0,$.jsx)(Vo,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.agentLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.agentBody`,values:{mod:tY},components:{mod:(0,$.jsx)(iY,{children:tY}),shift:(0,$.jsx)(iY,{children:`Shift`}),a:(0,$.jsx)(iY,{children:`A`}),tab:(0,$.jsx)(iY,{children:`Tab`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Ac,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.terminalLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.terminalBody`,values:{mod:tY},components:{mod:(0,$.jsx)(iY,{children:tY}),j:(0,$.jsx)(iY,{children:`J`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(zs,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.shortcutsLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.shortcutsBody`,components:{q:(0,$.jsx)(iY,{children:`?`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(O,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.chatLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.chatBody`,values:{mod:tY},components:{mod:(0,$.jsx)(iY,{children:tY}),bkey:(0,$.jsx)(iY,{children:`B`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(Ts,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.projectsLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.projectsBody`,values:{alt:nY,mod:tY},components:{alt:(0,$.jsx)(iY,{children:nY}),mod:(0,$.jsx)(iY,{children:tY}),bkey:(0,$.jsx)(iY,{children:`B`})}})}),(0,$.jsx)(aY,{icon:(0,$.jsx)(cs,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.pagesLabel`),accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.pagesBody`,values:{alt:nY,mod:tY},components:{alt:(0,$.jsx)(iY,{children:nY}),mod:(0,$.jsx)(iY,{children:tY}),n:(0,$.jsx)(iY,{children:`1–9`})}})})]}),(0,$.jsx)(oY,{accent:rY.primary,children:(0,$.jsx)(lt,{t:e,i18nKey:`onboarding.moveFast.outro`,components:t})})]})}]}function pY({open:e,onClose:t}){let{t:n}=K(`setup`),[r,i]=(0,Q.useState)(0),[a,o]=(0,Q.useState)(!1),s=(0,Q.useMemo)(()=>fY(n),[n]),c=s[r],l=r===0,u=r===s.length-1,d=(0,Q.useCallback)(()=>{a&&$J(),i(0),t()},[a,t]),f=(0,Q.useCallback)(()=>{$J(),i(0),t()},[t]),p=(0,Q.useCallback)(()=>{u?f():i(e=>e+1)},[u,f]),m=(0,Q.useCallback)(()=>i(e=>Math.max(0,e-1)),[]);return(0,$.jsx)(dr,{open:e,onOpenChange:e=>{e||d()},children:(0,$.jsxs)(tr,{children:[(0,$.jsx)(er,{className:`fixed inset-0 z-50 bg-black/70 backdrop-blur-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`}),(0,$.jsxs)(hr,{className:`fixed left-[50%] top-[50%] z-50 flex flex-col w-[calc(100vw-2rem)] max-w-5xl h-[min(88vh,820px)] translate-x-[-50%] translate-y-[-50%] overflow-hidden border border-border/30 bg-popover shadow-2xl backdrop-blur-xl sm:rounded-2xl duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95`,"data-testid":`onboarding-wizard`,"aria-describedby":`onboarding-description`,children:[(0,$.jsx)(`div`,{className:X(`h-1 w-full shrink-0 transition-all duration-500`,c.accent.bar)}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,$.jsxs)(`nav`,{className:`hidden md:flex w-60 shrink-0 flex-col border-r border-border/30 bg-card/20 p-4`,children:[(0,$.jsxs)(`div`,{className:`px-2 mb-5`,children:[(0,$.jsxs)(`p`,{className:`text-sm font-bold tracking-tight`,children:[(0,$.jsx)(`span`,{className:`text-accent-primary`,children:`spec`}),(0,$.jsx)(`span`,{className:`text-accent-secondary`,children:`rails`})]}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:n(`onboarding.productTour`)})]}),(0,$.jsx)(`ol`,{className:`space-y-0.5 min-h-0 overflow-y-auto`,children:s.map((e,t)=>{let a=t===r,o=t<r;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(t),"aria-label":n(`onboarding.goToStep`,{step:t+1,label:e.navLabel}),"aria-current":a?`step`:void 0,className:X(`w-full flex items-center gap-2.5 rounded-lg px-2.5 py-2 text-left transition-colors`,a?X(`bg-card/70`,e.accent.text):`text-muted-foreground hover:bg-card/40 hover:text-foreground`),children:[(0,$.jsx)(`span`,{className:X(`grid place-items-center w-5 h-5 shrink-0 rounded-full text-[10px] font-bold border`,a?X(e.accent.bar,`text-primary-foreground border-transparent`):o?`bg-accent-success/15 text-accent-success border-accent-success/30`:`border-border/50 text-muted-foreground`),children:o?(0,$.jsx)(Sn,{className:`w-3 h-3`}):t+1}),(0,$.jsx)(`span`,{className:`text-xs font-medium truncate`,children:e.navLabel})]})},e.navLabel)})}),(0,$.jsx)(`div`,{className:`mt-auto px-2.5 pt-4 text-[10px] text-muted-foreground`,children:n(`onboarding.stepCount`,{current:r+1,total:s.length})})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6 sm:p-7`,children:[(0,$.jsxs)(`div`,{className:X(`flex items-center gap-3.5 mb-5`,c.accent.text),children:[(0,$.jsx)(`div`,{className:X(`grid place-items-center w-12 h-12 shrink-0 rounded-xl border border-border/30 bg-card/40`,c.accent.glow),children:c.icon}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(cr,{className:`text-lg font-bold leading-tight text-foreground`,children:c.title}),(0,$.jsx)(`p`,{id:`onboarding-description`,className:`text-xs text-muted-foreground mt-0.5`,children:c.subtitle})]})]}),(0,$.jsx)(`div`,{className:`md:hidden flex items-center gap-1.5 mb-5`,children:s.map((e,t)=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>i(t),"aria-label":n(`onboarding.stepLabel`,{step:t+1}),"aria-current":t===r?`step`:void 0,className:X(`h-1.5 rounded-full transition-all`,t===r?X(`w-6`,e.accent.bar):`w-1.5 bg-muted-foreground/30`)},e.navLabel))}),(0,$.jsx)(`div`,{className:`min-h-[300px]`,children:c.content})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-border/30 px-6 sm:px-7 py-3.5`,children:[(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:l&&(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-2 cursor-pointer group`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(e.target.checked),className:`w-3.5 h-3.5 rounded`,"data-testid":`onboarding-dismiss-checkbox`}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground group-hover:text-foreground transition-colors`,children:n(`onboarding.dontShowAgain`)})]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[l?(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:d,className:`text-xs text-muted-foreground`,"data-testid":`onboarding-skip`,children:n(`onboarding.skipTour`)}):(0,$.jsxs)(Z,{variant:`ghost`,size:`sm`,onClick:m,className:`text-xs`,"data-testid":`onboarding-back`,children:[(0,$.jsx)(un,{className:`w-3.5 h-3.5 mr-1`}),n(`common:actions.back`)]}),(0,$.jsxs)(Z,{size:`sm`,onClick:p,className:X(`text-xs`,c.accent.btn),"data-testid":`onboarding-next`,children:[n(u?`onboarding.getStarted`:`common:actions.next`),!u&&(0,$.jsx)(ce,{className:`w-3.5 h-3.5 ml-1`})]})]})]})]})]})]})]})})}function mY(){let[e,t]=(0,Q.useState)(new Map),n=(0,Q.useContext)(rt);return(0,Q.useEffect)(()=>n?(n.registerHandler(`assemble-progress`,e=>{let n=e;if(n.type!==`project.assemble_progress`||typeof n.projectId!=`string`||typeof n.provider!=`string`)return;let{projectId:r,provider:i,status:a}=n;t(e=>{let t=new Map(e),n=t.get(r)?{running:new Set(t.get(r).running),failed:new Set(t.get(r).failed)}:{running:new Set,failed:new Set};return a===`running`?(n.running.add(i),n.failed.delete(i)):a===`done`?(n.running.delete(i),n.failed.delete(i)):a===`failed`&&(n.running.delete(i),n.failed.add(i)),t.set(r,n),t})}),()=>n.unregisterHandler(`assemble-progress`)):void 0,[n]),{statusFor:(0,Q.useCallback)(t=>{let n=e.get(t);return n?n.running.size>0?`assembling`:n.failed.size>0?`failed`:`ready`:`ready`},[e]),retry:(0,Q.useCallback)(async e=>{await fetch(`${Xe}/api/projects/${e}/assemble-retry`,{method:`POST`})},[])}}var hY=(0,Q.lazy)(()=>c(()=>import(`./ProjectSettingsDialog-CAjLgJAZ.js`).then(e=>({default:e.ProjectSettingsDialog})),__vite__mapDeps([88,1,7,43,45,8,12,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,56,67,51,68,69]))),gY=`specrails-desktop:agentTreeExpanded`;function _Y(){try{let e=localStorage.getItem(gY);if(!e)return new Set;let t=JSON.parse(e);return Array.isArray(t)?new Set(t.filter(e=>typeof e==`string`)):new Set}catch{return new Set}}function vY(e){try{localStorage.setItem(gY,JSON.stringify([...e]))}catch{}}function yY(){window.dispatchEvent(new KeyboardEvent(`keydown`,{key:`k`,metaKey:!0,ctrlKey:!0,bubbles:!0}))}var bY=`__home__`,xY=`__favorites__`;function SY({conversation:e,active:t,expanded:n,streaming:r=!1,unread:i=!1,favorite:a=!1,onSelect:o,onToggleFavorite:s,onDelete:c}){let{t:l}=K(`agent`),u=e.title?.trim()||l(`untitled`),[d,f]=(0,Q.useState)(!1),p=(0,Q.useRef)(null),[m,h]=(0,Q.useState)(!1),g=(0,Q.useRef)(r);(0,Q.useEffect)(()=>{if(g.current&&!r){h(!0);let e=setTimeout(()=>h(!1),900);return g.current=r,()=>clearTimeout(e)}g.current=r},[r]),(0,Q.useEffect)(()=>()=>{p.current&&clearTimeout(p.current)},[]);function _(e){e.stopPropagation(),d?(p.current&&clearTimeout(p.current),f(!1),c()):(f(!0),p.current=setTimeout(()=>{f(!1),p.current=null},3e3))}function v(e){e.stopPropagation(),s?.()}function y(e){e.target===e.currentTarget&&(e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),o()))}return(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:o,onKeyDown:y,className:X(`group relative flex items-center gap-2 w-full h-7 rounded-md transition-colors`,n?`pl-7 pr-2`:`px-0 justify-center`,t?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),title:n?void 0:u,"aria-current":t?`true`:void 0,children:[(0,$.jsx)(O,{className:X(`w-3.5 h-3.5 flex-shrink-0`,t&&`text-accent-primary`,r&&!i&&`text-accent-primary animate-pulse`,i&&`text-destructive conversation-unread-glow`)}),n&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`relative text-[11px] truncate flex-1 text-left`,children:[u,(r||m)&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:X(`title-shimmer pointer-events-none absolute inset-0 truncate transition-opacity duration-700`,r?`opacity-100`:`opacity-0`),children:u})]}),(0,$.jsx)(`span`,{className:X(`flex-shrink-0 text-[10px] tabular-nums text-muted-foreground/45`,d?`hidden`:`group-hover:hidden`),title:Yb(e.updated_at),children:Jb(e.updated_at)}),(0,$.jsx)(`button`,{type:`button`,onClick:v,className:X(`flex-shrink-0 items-center justify-center rounded-sm transition-colors hover:bg-muted`,a?`flex w-3.5 h-3.5 text-accent-primary hover:text-accent-primary`:`hidden group-hover:flex w-3.5 h-3.5 text-muted-foreground/60 hover:text-accent-primary`),"aria-label":l(a?`removeFavoriteConversation`:`addFavoriteConversation`,{title:u}),title:l(a?`removeFavoriteConversation`:`addFavoriteConversation`,{title:u}),children:(0,$.jsx)(Ps,{className:`w-2.5 h-2.5`,fill:a?`currentColor`:`none`})}),(0,$.jsx)(`button`,{type:`button`,onClick:_,className:X(`flex-shrink-0 items-center justify-center rounded-sm transition-colors hover:bg-muted`,d?`flex px-1 h-4 text-[10px] text-destructive bg-destructive/10 hover:bg-destructive/20`:`hidden group-hover:flex w-3.5 h-3.5 text-muted-foreground/60 hover:text-foreground`),"aria-label":l(d?`confirmDeleteConversation`:`deleteConversation`,{title:u}),children:d?l(`confirmShort`):(0,$.jsx)(Vn,{className:`w-2.5 h-2.5`})})]})]})}function CY({project:e,isActive:t,expanded:n,onSelect:r,onRemove:i,agentMode:a=!1,hasTree:o=!1,treeOpen:s=!1,onToggleTree:c,conversations:l=[],activeConversationId:u=null,streamingConversationIds:d,unreadConversationIds:f,onSelectConversation:p,onToggleConversationFavorite:m,onDeleteConversation:h,onOpenProjectSettings:g,assembleStatus:_=`ready`,onRetryAssemble:v}){let{t:y}=K(`nav`),[b,x]=(0,Q.useState)(!1),S=(0,Q.useRef)(null);(0,Q.useEffect)(()=>()=>{S.current&&clearTimeout(S.current)},[]);function C(e){e.stopPropagation(),b?(S.current&&clearTimeout(S.current),x(!1),i()):(x(!0),S.current=setTimeout(()=>{x(!1),S.current=null},3e3))}function w(e){e.target===e.currentTarget&&(e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),r()))}let T=a&&o&&n,E=(0,$.jsx)(Ts,{className:X(`flex-shrink-0 w-4 h-4`,t&&`text-accent-primary`)});return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:r,onKeyDown:w,className:X(`group relative flex items-center gap-2 w-full h-8 rounded-md transition-colors`,n?`px-2`:`px-0 justify-center`,t?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),title:n?void 0:e.name,"aria-current":t?`page`:void 0,children:[T?(0,$.jsxs)(`span`,{className:`relative flex h-4 w-4 flex-shrink-0 items-center justify-center`,children:[(0,$.jsx)(`span`,{className:`flex transition-opacity group-hover:opacity-0 group-focus-within:opacity-0`,children:E}),(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c?.()},className:`absolute inset-0 hidden items-center justify-center rounded-sm hover:bg-muted group-hover:flex group-focus-within:flex`,"aria-label":y(s?`projects.collapse`:`projects.expand`,{name:e.name}),"aria-expanded":s,children:s?(0,$.jsx)(Xo,{className:`w-3.5 h-3.5`}):(0,$.jsx)(Zo,{className:`w-3.5 h-3.5`})})]}):E,n&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-xs truncate flex-1 text-left`,children:e.name}),_===`assembling`&&(0,$.jsx)(`span`,{className:`flex-shrink-0 h-1.5 w-1.5 rounded-full bg-accent-info animate-pulse`,title:y(`projects.assembling`),"data-testid":`assemble-indicator`,"aria-label":y(`projects.assembling`)}),_===`failed`&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),v?.()},className:`flex-shrink-0 h-2 w-2 rounded-full bg-accent-warning hover:ring-2 hover:ring-accent-warning/40 transition-shadow`,title:y(`projects.assembleFailed`),"data-testid":`assemble-retry`,"aria-label":y(`projects.assembleFailed`)}),g&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),g()},className:X(`flex-shrink-0 flex items-center justify-center rounded-sm transition-all w-3.5 h-3.5`,`opacity-0 group-hover:opacity-50 hover:!opacity-100 hover:bg-muted`),"aria-label":y(`projects.settings`,{name:e.name}),title:y(`projects.settings`,{name:e.name}),children:(0,$.jsx)(Sc,{className:`w-2.5 h-2.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:C,className:X(`flex-shrink-0 flex items-center justify-center rounded-sm transition-all`,`opacity-0 group-hover:opacity-50 hover:!opacity-100 hover:bg-muted`,b?`opacity-100 px-1 h-4 text-[10px] text-destructive bg-destructive/10 hover:bg-destructive/20`:`w-3.5 h-3.5`),"aria-label":y(b?`projects.confirmRemove`:`projects.remove`,{name:e.name}),children:b?y(`projects.confirmShort`):(0,$.jsx)(Vn,{className:`w-2.5 h-2.5`})})]})]}),a&&s&&n&&l.length>0&&(0,$.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:l.map(e=>(0,$.jsx)(SY,{conversation:e,active:e.id===u,streaming:d?.has(e.id)??!1,unread:f?.has(e.id)??!1,expanded:n,onSelect:()=>p?.(e.id),onToggleFavorite:()=>m?.(e.id),onDelete:()=>h?.(e.id)},e.id))})]})}var wY={"pinned-open":`sidebarPin.left.pinnedOpen`,"pinned-collapsed":`sidebarPin.left.pinnedCollapsed`,unpinned:`sidebarPin.left.unpinned`};function TY({onAddProject:e,onOpenLoops:t,onOpenPlugins:n,onOpenAnalytics:r,onOpenDocs:i,onOpenSettings:a,onOpenCompanion:o}){let{t:s}=K(`nav`),{t:c}=K(`agent`),{projects:l,activeProjectId:u,setActiveProjectId:d,removeProject:f}=pt(),m=mY(),h=y(),g=p(),_=g.pathname.startsWith(`/loops`),v=g.pathname.startsWith(`/plugins`),b=_||v||g.pathname.startsWith(`/docs`),{leftMode:x,cycleLeftMode:S}=XP(),{uiMode:C,toggleUiMode:w}=MN(),T=aP(),E=C===`agent`,D=(0,Q.useMemo)(()=>{let e=new Map,t=new Set(l.map(e=>e.id));for(let n of T.conversations){if(T.favoriteConversationIds.has(n.id))continue;let r=n.pinned_project_id&&t.has(n.pinned_project_id)?n.pinned_project_id:bY,i=e.get(r);i?i.push(n):e.set(r,[n])}return e},[T.conversations,T.favoriteConversationIds,l]),O=(0,Q.useMemo)(()=>T.conversations.filter(e=>T.favoriteConversationIds.has(e.id)),[T.conversations,T.favoriteConversationIds]),k=D.get(bY)??[],[A,j]=(0,Q.useState)(_Y),M=A.has(xY),[N,P]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{!E||!u||j(e=>{if(e.has(u))return e;let t=new Set(e);return t.add(u),vY(t),t})},[E,u]);let F=e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),vY(n),n})},I=e=>{T.selectConversation(e),b&&h(`/`)},L=e=>{T.deleteConversation(e).catch(()=>{})},R=e=>{T.toggleFavoriteConversation(e)};function z(e){if(E){d(e),F(e);return}if(e===u){b&&h(`/`);return}d(e)}let[B,V]=(0,Q.useState)(!1),H=x===`pinned-open`||x===`unpinned`&&B,U=zP(`left-arc`,{side:`left`,defaultWidth:240,min:200,max:460,collapsedWidth:44,expanded:H}),W=x!==`unpinned`,ee=s(wY[x]),te=[{label:s(`arcSidebar.docs`),icon:Bo,action:i},{label:s(`arcSidebar.analytics`),icon:qo,action:r},...o?[{label:s(`arcSidebar.companion`),icon:Tc,action:o}]:[],{label:s(`arcSidebar.settings`),icon:Sc,action:a}];async function ne(e){try{await f(e.id)}catch{}}return(0,$.jsxs)(`div`,{ref:U.panelRef,className:X(`relative flex flex-col h-full border-r border-border bg-background flex-shrink-0 overflow-hidden`,`transition-[width] duration-200 ease-in-out`),onMouseEnter:()=>{x===`unpinned`&&V(!0)},onMouseLeave:()=>{x===`unpinned`&&!U.dragging&&V(!1)},children:[H&&(0,$.jsx)(BP,{side:`left`,dragging:U.dragging,width:U.width,min:200,max:460,label:s(`arcSidebar.resize`,{defaultValue:`Resize sidebar`}),onPointerDown:U.onGripPointerDown,onKeyDown:U.onGripKeyDown}),(0,$.jsxs)(`div`,{className:X(`flex items-center h-12 border-b border-border flex-shrink-0`,H?`px-3 justify-between`:`justify-center`),children:[H&&(0,$.jsx)(`span`,{className:`font-mono text-sm font-bold whitespace-nowrap overflow-hidden text-accent-primary`,children:s(`arcSidebar.desktopTitle`)}),(0,$.jsx)(`button`,{type:`button`,onClick:S,className:X(`flex items-center justify-center w-7 h-7 rounded-md transition-colors flex-shrink-0`,W?`text-foreground bg-muted`:`text-muted-foreground/40 hover:text-muted-foreground hover:bg-muted/50`),"aria-label":ee,title:s(`sidebarPin.withShortcut`,{label:ee,shortcut:mW(`⌥⌘B`)}),children:(0,$.jsx)(tc,{className:`w-4 h-4`})})]}),De&&(0,$.jsxs)(`div`,{className:`py-2 px-1.5 space-y-0.5 border-b border-border`,children:[E&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{T.startNewConversation(u),b&&h(`/`)},className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,`bg-accent-primary/15 text-accent-primary hover:bg-accent-primary/25`,H?`px-2`:`px-0 justify-center`),"aria-label":c(`newAgent`),title:H?void 0:c(`newAgent`),children:[(0,$.jsx)(Pn,{className:`w-4 h-4 flex-shrink-0`}),H&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:c(`newAgent`)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:w,className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,`text-muted-foreground hover:text-foreground hover:bg-muted/50`,H?`px-2`:`px-0 justify-center`),"aria-label":c(E?`switchToKanban`:`switchToAgent`),title:c(E?`switchToKanban`:`switchToAgent`),children:[E?(0,$.jsx)(Vs,{className:`w-4 h-4 flex-shrink-0`}):(0,$.jsx)(Vo,{className:`w-4 h-4 flex-shrink-0 text-accent-primary`}),H&&(0,$.jsx)(`span`,{className:`min-w-0 truncate text-xs`,children:c(E?`switchToKanban`:`switchToAgent`)})]}),E&&(0,$.jsxs)(`button`,{type:`button`,onClick:yY,className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,`text-muted-foreground hover:text-foreground hover:bg-muted/50`,H?`px-2`:`px-0 justify-center`),"aria-label":c(`search`),title:H?void 0:c(`search`),children:[(0,$.jsx)(In,{className:`w-4 h-4 flex-shrink-0`}),H&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:c(`search`)})]})]}),ke&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`py-2 px-1.5`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:t,className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,H?`px-2`:`px-0 justify-center`,_?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),"aria-label":s(`arcSidebar.loops`),"aria-current":_?`page`:void 0,title:H?void 0:s(`arcSidebar.loops`),children:[(0,$.jsx)(Lc,{className:X(`w-4 h-4 flex-shrink-0`,_&&`text-accent-primary`)}),H&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:s(`arcSidebar.loops`)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:n,className:X(`mt-0.5 flex items-center gap-2 w-full h-8 rounded-md transition-colors`,H?`px-2`:`px-0 justify-center`,v?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),"aria-label":s(`arcSidebar.plugins`),"aria-current":v?`page`:void 0,title:H?void 0:s(`arcSidebar.plugins`),children:[(0,$.jsx)(uc,{className:X(`w-4 h-4 flex-shrink-0`,v&&`text-accent-primary`)}),H&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:s(`arcSidebar.plugins`)})]})]}),(0,$.jsx)(`div`,{className:`border-t border-border`,"aria-hidden":!0})]}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto py-2 px-1.5 space-y-0.5`,children:[E&&O.length>0&&(0,$.jsxs)(`div`,{className:`mb-2 space-y-0.5 border-b border-border/70 pb-2`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>F(xY),className:X(`group flex items-center gap-2 w-full h-8 rounded-md transition-colors`,`text-muted-foreground hover:text-foreground hover:bg-muted/50`,H?`px-2`:`px-0 justify-center`),"aria-label":c(`favoriteMissions`),"aria-expanded":M,title:H?void 0:c(`favoriteMissions`),children:[H?(0,$.jsxs)(`span`,{className:`relative flex h-4 w-4 flex-shrink-0 items-center justify-center`,children:[(0,$.jsx)(Ps,{className:`h-4 w-4 fill-current text-accent-primary transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0`}),(0,$.jsx)(`span`,{className:`absolute inset-0 hidden items-center justify-center group-hover:flex group-focus-visible:flex`,children:M?(0,$.jsx)(Xo,{className:`w-3.5 h-3.5`}):(0,$.jsx)(Zo,{className:`w-3.5 h-3.5`})})]}):(0,$.jsx)(Ps,{className:`w-4 h-4 flex-shrink-0 fill-current text-accent-primary`}),H&&(0,$.jsx)(`span`,{className:`text-xs truncate flex-1 text-left`,children:c(`favoriteMissions`)})]}),M&&H&&(0,$.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:O.map(e=>(0,$.jsx)(SY,{conversation:e,active:e.id===T.active?.id,streaming:T.streamingConversationIds.has(e.id),unread:T.unreadConversationIds.has(e.id),favorite:!0,expanded:H,onSelect:()=>I(e.id),onToggleFavorite:()=>R(e.id),onDelete:()=>L(e.id)},e.id))})]}),E&&k.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>F(bY),className:X(`group flex items-center gap-2 w-full h-8 rounded-md transition-colors`,`text-muted-foreground hover:text-foreground hover:bg-muted/50`,H?`px-2`:`px-0 justify-center`),"aria-label":c(`home`),"aria-expanded":A.has(bY),title:H?void 0:c(`home`),children:[H?(0,$.jsxs)(`span`,{className:`relative flex h-4 w-4 flex-shrink-0 items-center justify-center`,children:[(0,$.jsx)(Is,{className:`h-4 w-4 transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0`}),(0,$.jsx)(`span`,{className:`absolute inset-0 hidden items-center justify-center group-hover:flex group-focus-visible:flex`,children:A.has(bY)?(0,$.jsx)(Xo,{className:`w-3.5 h-3.5`}):(0,$.jsx)(Zo,{className:`w-3.5 h-3.5`})})]}):(0,$.jsx)(Is,{className:`w-4 h-4 flex-shrink-0`}),H&&(0,$.jsx)(`span`,{className:`text-xs truncate flex-1 text-left`,children:c(`home`)})]}),A.has(bY)&&H&&(0,$.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:k.map(e=>(0,$.jsx)(SY,{conversation:e,active:e.id===T.active?.id,streaming:T.streamingConversationIds.has(e.id),unread:T.unreadConversationIds.has(e.id),expanded:H,onSelect:()=>I(e.id),onToggleFavorite:()=>R(e.id),onDelete:()=>L(e.id)},e.id))})]}),l.map(e=>{let t=D.get(e.id)??[];return(0,$.jsx)(CY,{project:e,isActive:e.id===u&&!b,expanded:H,onSelect:()=>z(e.id),onRemove:()=>ne(e),agentMode:E,hasTree:t.length>0,treeOpen:A.has(e.id),onToggleTree:()=>F(e.id),conversations:t,activeConversationId:T.active?.id??null,streamingConversationIds:T.streamingConversationIds,unreadConversationIds:T.unreadConversationIds,onSelectConversation:I,onToggleConversationFavorite:R,onDeleteConversation:L,assembleStatus:m.statusFor(e.id),onRetryAssemble:()=>{m.retry(e.id)},onOpenProjectSettings:E?()=>{d(e.id),P(!0)}:void 0},e.id)}),(0,$.jsxs)(`button`,{type:`button`,onClick:e,className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,`text-muted-foreground hover:text-foreground hover:bg-muted/50`,H?`px-2`:`px-0 justify-center`),"aria-label":s(`projects.addProject`),title:H?void 0:s(`projects.addProject`),children:[(0,$.jsx)(Pn,{className:`w-4 h-4 flex-shrink-0`}),H&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:s(`projects.addProject`)})]})]}),(0,$.jsx)(`div`,{className:`border-t border-border py-2 px-1.5 space-y-0.5`,children:te.map(({label:e,icon:t,action:n})=>(0,$.jsxs)(`button`,{type:`button`,onClick:n,className:X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,`text-muted-foreground hover:text-foreground hover:bg-muted/50`,H?`px-2`:`px-0 justify-center`),"aria-label":e,title:H?void 0:e,children:[(0,$.jsx)(t,{className:`w-4 h-4 flex-shrink-0`}),H&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:e})]},e))}),N&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(hY,{open:!0,onClose:()=>P(!1)})})]})}var EY={"pinned-open":`sidebarPin.right.pinnedOpen`,"pinned-collapsed":`sidebarPin.right.pinnedCollapsed`,unpinned:`sidebarPin.right.unpinned`};function DY(){let{t:e}=K(`nav`),{rightMode:t,cycleRightMode:n}=XP(),[r,i]=(0,Q.useState)(!1),a=t===`pinned-open`||t===`unpinned`&&r,o=t!==`unpinned`,s=e(EY[t]),c=[{to:`/`,end:!0,icon:Hs,label:e(`rightSidebar.dashboard`)},{to:`/jobs`,end:!1,icon:Go,label:e(`rightSidebar.jobs`)},{to:`/analytics`,end:!1,icon:Ko,label:e(`rightSidebar.analytics`)},...me?[{to:`/code`,end:!1,icon:is,label:e(`rightSidebar.code`)}]:[],{to:`/settings`,end:!1,icon:Sc,label:e(`rightSidebar.settings`)}];return(0,$.jsxs)(`div`,{className:X(`relative flex flex-col h-full border-l border-border bg-background flex-shrink-0`,`transition-all duration-200 ease-in-out overflow-hidden`,a?`w-44`:`w-11`),onMouseEnter:()=>{t===`unpinned`&&i(!0)},onMouseLeave:()=>{t===`unpinned`&&i(!1)},children:[(0,$.jsxs)(`div`,{className:X(`flex items-center h-12 border-b border-border flex-shrink-0`,a?`px-3 justify-between`:`justify-center`),children:[a&&(0,$.jsx)(`span`,{className:`font-mono text-sm font-bold whitespace-nowrap overflow-hidden text-accent-secondary`,children:e(`rightSidebar.projectTitle`)}),(0,$.jsx)(`button`,{type:`button`,onClick:n,className:X(`flex items-center justify-center w-7 h-7 rounded-md transition-colors`,o?`text-foreground bg-muted`:`text-muted-foreground/40 hover:text-muted-foreground hover:bg-muted/50`),"aria-label":s,title:e(`sidebarPin.withShortcut`,{label:s,shortcut:mW(`⌘B`)}),children:(0,$.jsx)(nc,{className:`w-4 h-4`})})]}),(0,$.jsxs)(`nav`,{className:`flex-1 py-2 px-1.5 space-y-0.5`,children:[(0,$.jsx)(QP,{expanded:a}),c.map(({to:e,end:t,icon:n,label:r})=>(0,$.jsxs)(g,{to:e,end:t,className:({isActive:e})=>X(`flex items-center gap-2 w-full h-8 rounded-md transition-colors`,a?`px-2`:`px-0 justify-center`,e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),title:a?void 0:r,children:[(0,$.jsx)(n,{className:`w-4 h-4 flex-shrink-0`}),a&&(0,$.jsx)(`span`,{className:`text-xs truncate`,children:r})]},e))]})]})}function OY(e,t){return e.error===`corrupted-bundle`?t(`setup:prerequisites.corruptedBundle`):e.installed?e.executable===!1?e.resolvedPath&&e.executionError?t(`setup:prerequisites.failedToExecuteAtWithError`,{path:e.resolvedPath,error:e.executionError}):e.resolvedPath?t(`setup:prerequisites.failedToExecuteAt`,{path:e.resolvedPath}):e.executionError?t(`setup:prerequisites.failedToExecuteWithError`,{error:e.executionError}):t(`setup:prerequisites.failedToExecute`):!e.meetsMinimum&&e.minVersion?t(`setup:prerequisites.needsMinimum`,{version:e.version??t(`setup:prerequisites.unknownVersion`),minVersion:e.minVersion}):e.version??t(`setup:prerequisites.installedLabel`):t(`setup:prerequisites.notInstalled`)}function kY({status:e,isLoading:t,error:n,onRefresh:r,onMoreInfo:i}){let{t:a}=K(`setup`);if(t&&!e)return(0,$.jsx)(`div`,{"data-testid":`prerequisites-panel`,"data-state":`loading`,className:`rounded-lg border border-border/30 bg-background/30 px-3 py-2`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-muted-foreground/20 animate-pulse`}),(0,$.jsx)(`div`,{className:`h-3 w-32 rounded bg-muted-foreground/15 animate-pulse`})]})});if(n&&!e)return(0,$.jsx)(`div`,{"data-testid":`prerequisites-panel`,"data-state":`error`,className:`rounded-lg border border-border/40 bg-background/40 px-3 py-2`,children:(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:a(`prerequisites.verifyError`)})});if(!e)return null;if(e.ok)return(0,$.jsx)(`div`,{"data-testid":`prerequisites-panel`,"data-state":`ok`,className:`rounded-lg border border-accent-success/25 bg-accent-success/5 px-3 py-2`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,$.jsx)($o,{className:`w-4 h-4 text-accent-success flex-shrink-0`}),(0,$.jsx)(`p`,{className:`text-xs font-medium text-foreground`,children:a(`prerequisites.allDetected`)})]}),r&&(0,$.jsxs)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:r,disabled:t,className:`h-7 px-2 gap-1.5 text-[11px] flex-shrink-0`,children:[(0,$.jsx)(mc,{className:X(`w-3 h-3`,t&&`animate-spin`)}),a(`common:actions.refresh`)]})]})});let o=e.missingRequired?.length??0,s=o>0&&(e.missingRequired??[]).every(e=>e.error===`corrupted-bundle`),c=(e.missingRequired??[]).some(e=>e.error===`corrupted-bundle`);return(0,$.jsxs)(`div`,{"data-testid":`prerequisites-panel`,"data-state":`missing`,className:X(`rounded-lg border px-3 py-2`,c?`border-destructive/40 bg-destructive/10`:`border-accent-primary/40 bg-accent-primary/10`),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,$.jsx)(zn,{className:X(`w-4 h-4 flex-shrink-0`,c?`text-destructive`:`text-accent-primary`)}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-foreground`,children:s?a(`prerequisites.bundleCorruptedTitle`):a(`prerequisites.toolsRequired`,{count:o})}),(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:a(s?`prerequisites.reinstallHint`:`prerequisites.installMissingHint`)})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[i&&!s&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:i,className:`h-7 px-2 gap-1.5 text-[11px]`,"data-testid":`prerequisites-more-info`,children:a(`prerequisites.moreInfo`)}),r&&(0,$.jsxs)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:r,disabled:t,className:`h-7 px-2 gap-1.5 text-[11px]`,children:[(0,$.jsx)(mc,{className:X(`w-3 h-3`,t&&`animate-spin`)}),a(`common:actions.refresh`)]})]})]}),(0,$.jsx)(`ul`,{className:`mt-2 space-y-1`,children:e.prerequisites.map(e=>{let t=e.error===`corrupted-bundle`,n=e.bundled===!0&&e.executable===!0&&!t,r=!t&&e.installed&&e.meetsMinimum,i=e.key===`gh`||e.key===`uv`,o=!r&&!t&&i;return(0,$.jsxs)(`li`,{"data-testid":`prereq-row-${e.key}`,"data-ok":r?`true`:`false`,"data-bundled":e.bundled?`true`:void 0,"data-corrupted":t?`true`:void 0,className:X(`flex items-center gap-2 rounded-md border px-2 py-1.5 text-[11px]`,t?`border-destructive/40 bg-destructive/10 text-foreground`:r||o?`border-border/30 bg-background/30 text-muted-foreground`:`border-accent-primary/30 bg-background/50 text-foreground`),children:[t?(0,$.jsx)(Tn,{className:`w-3.5 h-3.5 text-destructive flex-shrink-0`}):n||r?(0,$.jsx)($o,{className:`w-3.5 h-3.5 text-accent-success flex-shrink-0`}):o?(0,$.jsx)(Tn,{className:`w-3.5 h-3.5 text-muted-foreground/60 flex-shrink-0`}):(0,$.jsx)(Tn,{className:`w-3.5 h-3.5 text-accent-primary flex-shrink-0`}),(0,$.jsx)(`span`,{className:`font-medium`,children:e.label}),i&&(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:a(`prerequisites.optional`)}),e.key===`gh`&&e.executable&&e.authenticated===!1&&(0,$.jsx)(`span`,{"data-testid":`prereq-gh-noauth`,className:`inline-flex items-center rounded px-1 py-0.5 text-[10px] font-medium bg-accent-warning/15 text-accent-warning border border-accent-warning/30`,children:a(`prerequisites.ghNoAuth`)}),n&&(0,$.jsxs)(`span`,{"data-testid":`prereq-bundled-badge-${e.key}`,className:`inline-flex items-center gap-0.5 rounded px-1 py-0.5 text-[10px] font-medium bg-accent-secondary/20 text-accent-secondary border border-accent-secondary/30`,children:[(0,$.jsx)($s,{className:`w-2.5 h-2.5`}),a(`prerequisites.bundledBadge`)]}),(0,$.jsxs)(`span`,{className:X(`text-muted-foreground`,t&&`text-destructive/80`),children:[`— `,OY(e,a)]})]},e.key)})})]})}function AY(e){return{darwin:{title:`macOS`,intro:e(`setup:instructions.darwin.intro`),commands:[{label:e(`setup:instructions.darwin.installNodeGit`),command:`brew install node git`}],links:[{label:e(`setup:instructions.links.nodeOfficial`),url:`https://nodejs.org/en/download`},{label:e(`setup:instructions.links.gitOfficial`),url:`https://git-scm.com/downloads`},{label:`Homebrew`,url:`https://brew.sh`}]},win32:{title:`Windows`,intro:e(`setup:instructions.win32.intro`),commands:[{label:e(`setup:instructions.win32.installNode`),command:`winget install OpenJS.NodeJS.LTS`},{label:e(`setup:instructions.win32.installGit`),command:`winget install Git.Git`}],links:[{label:e(`setup:instructions.links.nodeOfficial`),url:`https://nodejs.org/en/download`},{label:e(`setup:instructions.links.gitWindows`),url:`https://git-scm.com/download/win`}],note:e(`setup:instructions.win32.note`)},linux:{title:`Linux`,intro:e(`setup:instructions.linux.intro`),commands:[{label:e(`setup:instructions.linux.debian`),command:`sudo apt install -y nodejs npm git`},{label:e(`setup:instructions.linux.fedora`),command:`sudo dnf install -y nodejs npm git`}],links:[{label:e(`setup:instructions.links.nodeOfficial`),url:`https://nodejs.org/en/download`},{label:e(`setup:instructions.links.gitOfficial`),url:`https://git-scm.com/downloads`}]}}}var jY=[`darwin`,`win32`,`linux`];async function MY(e){try{if(navigator.clipboard&&typeof navigator.clipboard.writeText==`function`)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function NY({command:e}){let{t}=K(`setup`),[n,r]=(0,Q.useState)(!1);return(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:async()=>{await MY(e)&&(r(!0),window.setTimeout(()=>r(!1),1500))},className:`h-7 px-2 gap-1.5 text-[11px]`,"data-testid":`install-copy-button`,children:n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Sn,{className:`w-3 h-3`}),t(`common:actions.copied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ls,{className:`w-3 h-3`}),t(`common:actions.copy`)]})})}function PY({platform:e,primary:t}){let{t:n}=K(`setup`),r=AY(n)[e];return(0,$.jsxs)(`section`,{"data-testid":`install-section-${e}`,className:X(`rounded-lg border px-3 py-3`,t?`border-border/40 bg-background/40`:`border-border/20 bg-background/20`),children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:r.title}),r.intro&&(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:r.intro}),(0,$.jsx)(`div`,{className:`mt-2 space-y-2`,children:r.commands.map(e=>(0,$.jsxs)(`div`,{className:`rounded-md border border-border/30 bg-background/60 px-2 py-2`,children:[(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-1`,children:e.label}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`code`,{className:`text-xs text-foreground font-mono break-all`,children:e.command}),(0,$.jsx)(NY,{command:e.command})]})]},e.command))}),r.links.length>0&&(0,$.jsx)(`ul`,{className:`mt-2 flex flex-wrap gap-x-3 gap-y-1`,children:r.links.map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-[11px] text-accent-info hover:underline`,children:[e.label,(0,$.jsx)(pn,{className:`w-3 h-3`})]})},e.url))}),r.note&&(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-accent-highlight`,children:r.note})]})}function FY(){let{t:e}=K(`setup`),[t,n]=(0,Q.useState)(`idle`);return(0,$.jsxs)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:async()=>{n(`copying`);try{let e=await fetch(`${Xe}/api/setup-prerequisites?diagnostic=1`);if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();await navigator.clipboard.writeText(JSON.stringify(t,null,2)),n(`copied`),setTimeout(()=>n(`idle`),1800)}catch{n(`error`),setTimeout(()=>n(`idle`),2400)}},disabled:t===`copying`,className:`gap-1.5 text-[11px]`,"data-testid":`copy-diagnostics-button`,children:[t===`copied`?(0,$.jsx)(Sn,{className:`w-3 h-3 text-accent-success`}):(0,$.jsx)(ns,{className:`w-3 h-3`}),e(t===`copied`?`instructions.diagnostics.copied`:t===`error`?`instructions.diagnostics.failed`:`instructions.diagnostics.copy`)]})}function IY({open:e,onClose:t,status:n,onRecheck:r,isRechecking:i}){let{t:a}=K(`setup`),[o,s]=(0,Q.useState)(!1),c=n?.platform??`darwin`,l=jY.filter(e=>e!==c);return n?.missingRequired?.some(e=>e.error===`corrupted-bundle`)??!1?(0,$.jsx)(mr,{open:e,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(fr,{movableResizable:!0,className:`max-w-xl`,"data-testid":`install-modal-corrupted-bundle`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:a(`instructions.corrupted.title`)}),(0,$.jsx)(ir,{children:a(`instructions.corrupted.description`)})]}),(0,$.jsx)(`p`,{className:`text-sm text-foreground`,children:a(`instructions.corrupted.body`)}),(0,$.jsx)(`div`,{className:`flex justify-end mt-2`,children:(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,"data-testid":`install-corrupted-close-button`,children:a(`common:actions.close`)})})]})}):(0,$.jsx)(mr,{open:e,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(fr,{movableResizable:!0,className:`max-w-xl`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsx)(sr,{children:a(`instructions.title`)}),(0,$.jsx)(ir,{children:a(`instructions.description`)})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(PY,{platform:c,primary:!0}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:`text-[11px] text-muted-foreground hover:text-foreground underline-offset-2 hover:underline`,"data-testid":`install-toggle-others`,children:a(o?`instructions.hideOtherPlatforms`:`instructions.showOtherPlatforms`)}),o&&(0,$.jsx)(`div`,{className:`space-y-3`,children:l.map(e=>(0,$.jsx)(PY,{platform:e,primary:!1},e))})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mt-2`,children:[(0,$.jsx)(FY,{}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,children:a(`common:actions.close`)}),(0,$.jsxs)(Z,{type:`button`,variant:`default`,size:`sm`,onClick:r,disabled:i,className:`gap-1.5`,"data-testid":`install-recheck-button`,children:[(0,$.jsx)(mc,{className:X(`w-3 h-3`,i&&`animate-spin`)}),a(`instructions.recheck`)]})]})]})]})})}var LY=typeof window<`u`&&`__TAURI_INTERNALS__`in window;function RY({open:e,onClose:t,onOpenBuilder:n}){let r=se&&!!n,[i,a]=(0,Q.useState)(r?`choose`:`existing`),[o,s]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)([]),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)({claude:!0}),[_,v]=(0,Q.useState)(!1),{t:y}=K(`setup`),{addProject:b}=pt(),{status:x,isLoading:S,error:C,recheck:w}=rM(),T=(0,Q.useMemo)(()=>{if(!x||x.ok)return null;let e=x.missingRequired.map(e=>e.label);return e.length===0?null:y(`addProject.toolsRequired`,{tools:e.join(`, `),count:e.length})},[x,y]),E=x!==null&&!x.ok&&!C;(0,Q.useEffect)(()=>{e&&fetch(`/api/available-providers`).then(e=>e.json()).then(e=>{let t={};for(let[n,r]of Object.entries(e))n===`tiers`||n===`providerIssues`||n===`launchDescriptors`||typeof r==`boolean`&&(t[n]=r);g(t)}).catch(()=>{})},[e]);async function D(){let e=o.trim();if(!e){J.error(y(`addProject.errors.pathRequired`));return}m(!0);try{let t=d.map(e=>({path:e.trim()})).filter(e=>e.path),n=t.length?await b(e,l.trim()||void 0,void 0,t):await b(e,l.trim()||void 0);if(!n)return;J.success(y(`addProject.toasts.registered`,{name:n.project.name})),O()}catch(e){J.error(y(`addProject.errors.addFailed`),{description:e.message})}finally{m(!1)}}function O(){s(``),u(``),f([]),a(r?`choose`:`existing`),t()}function k(e){e||O()}let A=!Object.values(h).some(Boolean);return i===`choose`?(0,$.jsx)(mr,{open:e,onOpenChange:k,children:(0,$.jsxs)(fr,{className:`max-w-md`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsxs)(sr,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Ts,{className:`w-4 h-4`}),y(`addProject.title`)]}),(0,$.jsx)(ir,{children:y(`addProject.chooser.description`)})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 py-2`,children:[(0,$.jsxs)(`button`,{type:`button`,"data-testid":`chooser-existing`,onClick:()=>a(`existing`),className:`flex flex-col items-start gap-2 rounded-lg border border-border/40 p-4 text-left transition-colors hover:border-accent-primary/50 hover:bg-accent-primary/5 focus:outline-none focus-visible:ring-1 focus-visible:ring-ring`,children:[(0,$.jsx)(ws,{className:`h-5 w-5 text-accent-info`}),(0,$.jsx)(`span`,{className:`text-sm font-medium`,children:y(`addProject.chooser.existingTitle`)}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:y(`addProject.chooser.existingDescription`)})]}),(0,$.jsxs)(`button`,{type:`button`,"data-testid":`chooser-new`,onClick:()=>{O(),n?.()},className:`flex flex-col items-start gap-2 rounded-lg border border-border/40 p-4 text-left transition-colors hover:border-accent-highlight/50 hover:bg-accent-highlight/5 focus:outline-none focus-visible:ring-1 focus-visible:ring-ring`,children:[(0,$.jsx)(Ln,{className:`h-5 w-5 text-accent-highlight`}),(0,$.jsx)(`span`,{className:`text-sm font-medium`,children:y(`addProject.chooser.newTitle`)}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:y(`addProject.chooser.newDescription`)})]})]})]})}):(0,$.jsx)(mr,{open:e,onOpenChange:k,children:(0,$.jsxs)(fr,{movableResizable:!0,className:`max-h-[calc(100vh-2rem)] w-[calc(100vw-2rem)] max-w-2xl overflow-x-hidden`,"data-testid":`existing-project-dialog`,children:[(0,$.jsxs)(ur,{children:[(0,$.jsxs)(sr,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Ts,{className:`w-4 h-4`}),y(`addProject.title`)]}),(0,$.jsx)(ir,{children:y(`addProject.description`)})]}),A&&(0,$.jsx)(`p`,{className:`text-xs text-destructive bg-destructive/10 rounded-md p-2`,children:y(`addProject.noProviderDetected`)}),(0,$.jsx)(kY,{status:x,isLoading:S,error:C,onMoreInfo:()=>v(!0),onRefresh:w}),(0,$.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium`,children:[y(`addProject.pathLabel`),` `,(0,$.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Jj,{placeholder:y(`addProject.pathPlaceholder`),value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&D()},autoFocus:!0,className:`flex-1`}),LY&&(0,$.jsx)(Z,{type:`button`,variant:`outline`,size:`icon`,className:`shrink-0`,title:y(`addProject.browseForFolder`),onClick:async()=>{try{let{open:e}=await c(async()=>{let{open:e}=await import(`./dist-js-CJ_2XX1Y.js`);return{open:e}},__vite__mapDeps([87,0,1])),t=await e({directory:!0,multiple:!1,title:y(`addProject.selectProjectFolder`)});typeof t==`string`&&t&&(s(t),l||u(t.split(`/`).filter(Boolean).pop()??``))}catch{}},children:(0,$.jsx)(Ts,{className:`w-4 h-4`})})]}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:y(`addProject.pathHint`)})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium`,children:[y(`addProject.nameLabel`),` `,(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:y(`addProject.optional`)})]}),(0,$.jsx)(Jj,{placeholder:y(`addProject.namePlaceholder`),value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&D()}}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:y(`addProject.nameHint`)})]}),(0,$.jsxs)(`fieldset`,{className:`space-y-2`,disabled:p,children:[(0,$.jsx)(`legend`,{className:`text-xs font-medium`,children:y(`common:repositories.additional`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:y(`common:repositories.sharedBacklog`)}),d.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Jj,{"aria-label":y(`common:repositories.folderNumber`,{number:t+2}),value:e,placeholder:y(`addProject.pathPlaceholder`),onChange:e=>f(n=>n.map((n,r)=>r===t?e.target.value:n))}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":y(`common:repositories.removeFolder`),onClick:()=>f(e=>e.filter((e,n)=>n!==t)),children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})]},t)),(0,$.jsxs)(Z,{type:`button`,variant:`outline`,size:`sm`,onClick:async()=>{if(LY)try{let{open:e}=await c(async()=>{let{open:e}=await import(`./dist-js-CJ_2XX1Y.js`);return{open:e}},__vite__mapDeps([87,0,1])),t=await e({directory:!0,multiple:!0});t&&f(e=>[...e,...Array.isArray(t)?t:[t]]);return}catch{}f(e=>[...e,``])},children:[(0,$.jsx)(Pn,{className:`mr-1 h-3.5 w-3.5`}),y(`common:repositories.addFolder`)]})]})]}),(0,$.jsxs)(Zn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,disabled:p,children:y(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,onClick:D,disabled:p||!o.trim()||E||S,title:E?T??void 0:void 0,"data-testid":`add-project-submit`,children:y(p?`addProject.adding`:`addProject.submit`)})]}),(0,$.jsx)(IY,{open:_,onClose:()=>v(!1),status:x,onRecheck:w,isRechecking:S})]})})}var zY=1,BY=.9,VY=.8,HY=.17,UY=.1,WY=.999,GY=.9999,KY=.99,qY=/[\\\/_+.#"@\[\(\{&]/,JY=/[\\\/_+.#"@\[\(\{&]/g,YY=/[\s-]/,XY=/[\s-]/g;function ZY(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?zY:KY;var s=`${i},${a}`;if(o[s]!==void 0)return o[s];for(var c=r.charAt(a),l=n.indexOf(c,i),u=0,d,f,p,m;l>=0;)d=ZY(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=zY:qY.test(e.charAt(l-1))?(d*=VY,p=e.slice(i,l-1).match(JY),p&&i>0&&(d*=WY**+p.length)):YY.test(e.charAt(l-1))?(d*=BY,m=e.slice(i,l-1).match(XY),m&&i>0&&(d*=WY**+m.length)):(d*=HY,i>0&&(d*=WY**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=GY)),(d<UY&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=ZY(e,t,n,r,l+1,a+2,o),f*UY>d&&(d=f*UY)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function QY(e){return e.toLowerCase().replace(XY,` `)}function $Y(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,ZY(e,t,QY(e),QY(t),0,0,{})}var eX=`[cmdk-group=""]`,tX=`[cmdk-group-items=""]`,nX=`[cmdk-group-heading=""]`,rX=`[cmdk-item=""]`,iX=`${rX}:not([aria-disabled="true"])`,aX=`cmdk-item-select`,oX=`data-value`,sX=(e,t,n)=>$Y(e,t,n),cX=Q.createContext(void 0),lX=()=>Q.useContext(cX),uX=Q.createContext(void 0),dX=()=>Q.useContext(uX),fX=Q.createContext(void 0),pX=Q.forwardRef((e,t)=>{let n=DX(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=DX(()=>new Set),i=DX(()=>new Map),a=DX(()=>new Map),o=DX(()=>new Set),s=TX(e),{label:c,children:l,value:u,onValueChange:d,filter:f,shouldFilter:p,loop:m,disablePointerSelection:h=!1,vimBindings:g=!0,..._}=e,v=Yn(),y=Yn(),b=Yn(),x=Q.useRef(null),S=AX();EX(()=>{if(u!==void 0){let e=u.trim();n.current.value=e,C.emit()}},[u]),EX(()=>{S(6,k)},[]);let C=Q.useMemo(()=>({subscribe:e=>(o.current.add(e),()=>o.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,a,o;if(!Object.is(n.current[e],t)){if(n.current[e]=t,e===`search`)O(),E(),S(1,D);else if(e===`value`){if(document.activeElement.hasAttribute(`cmdk-input`)||document.activeElement.hasAttribute(`cmdk-root`)){let e=document.getElementById(b);e?e.focus():(i=document.getElementById(v))==null||i.focus()}if(S(7,()=>{n.current.selectedItemId=A()?.id,C.emit()}),r||S(5,k),s.current?.value!==void 0){let e=t??``;(o=(a=s.current).onValueChange)==null||o.call(a,e);return}}C.emit()}},emit:()=>{o.current.forEach(e=>e())}}),[]),w=Q.useMemo(()=>({value:(e,t,r)=>{t!==a.current.get(e)?.value&&(a.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,T(t,r)),S(2,()=>{E(),C.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),S(3,()=>{O(),E(),n.current.value||D(),C.emit()}),()=>{a.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=A();S(4,()=>{O(),t?.getAttribute(`id`)===e&&D(),C.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{a.current.delete(e),i.current.delete(e)}),filter:()=>s.current.shouldFilter,label:c||e[`aria-label`],getDisablePointerSelection:()=>s.current.disablePointerSelection,listId:v,inputId:b,labelId:y,listInnerRef:x}),[]);function T(e,t){let r=s.current?.filter??sX;return e?r(e,n.current.search,t):0}function E(){if(!n.current.search||s.current.shouldFilter===!1)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),a=0;r.forEach(t=>{let n=e.get(t);a=Math.max(n,a)}),t.push([n,a])});let r=x.current;j().sort((t,n)=>{let r=t.getAttribute(`id`),i=n.getAttribute(`id`);return(e.get(i)??0)-(e.get(r)??0)}).forEach(e=>{let t=e.closest(tX);t?t.appendChild(e.parentElement===t?e:e.closest(`${tX} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${tX} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=x.current?.querySelector(`${eX}[${oX}="${encodeURIComponent(e[0])}"]`);t?.parentElement.appendChild(t)})}function D(){let e=j().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(oX);C.setState(`value`,e||void 0)}function O(){if(!n.current.search||s.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let e=0;for(let t of r.current){let r=T(a.current.get(t)?.value??``,a.current.get(t)?.keywords??[]);n.current.filtered.items.set(t,r),r>0&&e++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=e}function k(){var e;let t=A();t&&(t.parentElement?.firstChild===t&&((e=t.closest(eX)?.querySelector(nX))==null||e.scrollIntoView({block:`nearest`})),t.scrollIntoView({block:`nearest`}))}function A(){return x.current?.querySelector(`${rX}[aria-selected="true"]`)}function j(){return Array.from(x.current?.querySelectorAll(iX)||[])}function M(e){let t=j()[e];t&&C.setState(`value`,t.getAttribute(oX))}function N(e){var t;let n=A(),r=j(),i=r.findIndex(e=>e===n),a=r[i+e];(t=s.current)!=null&&t.loop&&(a=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),a&&C.setState(`value`,a.getAttribute(oX))}function P(e){let t=A()?.closest(eX),n;for(;t&&!n;)t=e>0?CX(t,eX):wX(t,eX),n=t?.querySelector(iX);n?C.setState(`value`,n.getAttribute(oX)):N(e)}let F=()=>M(j().length-1),I=e=>{e.preventDefault(),e.metaKey?F():e.altKey?P(1):N(1)},L=e=>{e.preventDefault(),e.metaKey?M(0):e.altKey?P(-1):N(-1)};return Q.createElement(Un.div,{ref:t,tabIndex:-1,..._,"cmdk-root":``,onKeyDown:e=>{var t;(t=_.onKeyDown)==null||t.call(_,e);let n=e.nativeEvent.isComposing||e.keyCode===229;if(!(e.defaultPrevented||n))switch(e.key){case`n`:case`j`:g&&e.ctrlKey&&I(e);break;case`ArrowDown`:I(e);break;case`p`:case`k`:g&&e.ctrlKey&&L(e);break;case`ArrowUp`:L(e);break;case`Home`:e.preventDefault(),M(0);break;case`End`:e.preventDefault(),F();break;case`Enter`:{e.preventDefault();let t=A();if(t){let e=new Event(aX);t.dispatchEvent(e)}}}}},Q.createElement(`label`,{"cmdk-label":``,htmlFor:w.inputId,id:w.labelId,style:NX},c),MX(e,e=>Q.createElement(uX.Provider,{value:C},Q.createElement(cX.Provider,{value:w},e))))}),mX=Q.forwardRef((e,t)=>{let n=Yn(),r=Q.useRef(null),i=Q.useContext(fX),a=lX(),o=TX(e),s=o.current?.forceMount??i?.forceMount;EX(()=>{if(!s)return a.item(n,i?.id)},[s]);let c=kX(n,r,[e.value,e.children,r],e.keywords),l=dX(),u=OX(e=>e.value&&e.value===c.current),d=OX(e=>s||a.filter()===!1?!0:!e.search||e.filtered.items.get(n)>0);Q.useEffect(()=>{let t=r.current;if(!(!t||e.disabled))return t.addEventListener(aX,f),()=>t.removeEventListener(aX,f)},[d,e.onSelect,e.disabled]);function f(){var e,t;p(),(t=(e=o.current).onSelect)==null||t.call(e,c.current)}function p(){l.setState(`value`,c.current,!0)}if(!d)return null;let{disabled:m,value:h,onSelect:g,forceMount:_,keywords:v,...y}=e;return Q.createElement(Un.div,{ref:or(r,t),...y,id:n,"cmdk-item":``,role:`option`,"aria-disabled":!!m,"aria-selected":!!u,"data-disabled":!!m,"data-selected":!!u,onPointerMove:m||a.getDisablePointerSelection()?void 0:p,onClick:m?void 0:f},e.children)}),hX=Q.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...a}=e,o=Yn(),s=Q.useRef(null),c=Q.useRef(null),l=Yn(),u=lX(),d=OX(e=>i||u.filter()===!1?!0:!e.search||e.filtered.groups.has(o));EX(()=>u.group(o),[]),kX(o,s,[e.value,e.heading,c]);let f=Q.useMemo(()=>({id:o,forceMount:i}),[i]);return Q.createElement(Un.div,{ref:or(s,t),...a,"cmdk-group":``,role:`presentation`,hidden:!d||void 0},n&&Q.createElement(`div`,{ref:c,"cmdk-group-heading":``,"aria-hidden":!0,id:l},n),MX(e,e=>Q.createElement(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?l:void 0},Q.createElement(fX.Provider,{value:f},e))))}),gX=Q.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=Q.useRef(null),a=OX(e=>!e.search);return!n&&!a?null:Q.createElement(Un.div,{ref:or(i,t),...r,"cmdk-separator":``,role:`separator`})}),_X=Q.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=e.value!=null,a=dX(),o=OX(e=>e.search),s=OX(e=>e.selectedItemId),c=lX();return Q.useEffect(()=>{e.value!=null&&a.setState(`search`,e.value)},[e.value]),Q.createElement(Un.input,{ref:t,...r,"cmdk-input":``,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,"aria-autocomplete":`list`,role:`combobox`,"aria-expanded":!0,"aria-controls":c.listId,"aria-labelledby":c.labelId,"aria-activedescendant":s,id:c.inputId,type:`text`,value:i?e.value:o,onChange:e=>{i||a.setState(`search`,e.target.value),n?.(e.target.value)}})}),vX=Q.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...i}=e,a=Q.useRef(null),o=Q.useRef(null),s=OX(e=>e.selectedItemId),c=lX();return Q.useEffect(()=>{if(o.current&&a.current){let e=o.current,t=a.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty(`--cmdk-list-height`,n.toFixed(1)+`px`)})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),Q.createElement(Un.div,{ref:or(a,t),...i,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:c.listId},MX(e,e=>Q.createElement(`div`,{ref:or(o,c.listInnerRef),"cmdk-list-sizer":``},e)))}),yX=Q.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return Q.createElement(dr,{open:n,onOpenChange:r},Q.createElement(tr,{container:o},Q.createElement(er,{"cmdk-overlay":``,className:i}),Q.createElement(hr,{"aria-label":e.label,"cmdk-dialog":``,className:a},Q.createElement(pX,{ref:t,...s}))))}),bX=Q.forwardRef((e,t)=>OX(e=>e.filtered.count===0)?Q.createElement(Un.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),xX=Q.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return Q.createElement(Un.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},MX(e,e=>Q.createElement(`div`,{"aria-hidden":!0},e)))}),SX=Object.assign(pX,{List:vX,Item:mX,Input:_X,Group:hX,Separator:gX,Dialog:yX,Empty:bX,Loading:xX});function CX(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function wX(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function TX(e){let t=Q.useRef(e);return EX(()=>{t.current=e}),t}var EX=typeof window>`u`?Q.useEffect:Q.useLayoutEffect;function DX(e){let t=Q.useRef();return t.current===void 0&&(t.current=e()),t}function OX(e){let t=dX(),n=()=>e(t.snapshot());return Q.useSyncExternalStore(t.subscribe,n,n)}function kX(e,t,n,r=[]){let i=Q.useRef(),a=lX();return EX(()=>{var o;let s=(()=>{for(let e of n){if(typeof e==`string`)return e.trim();if(typeof e==`object`&&`current`in e)return e.current?e.current.textContent?.trim():i.current}})(),c=r.map(e=>e.trim());a.value(e,s,c),(o=t.current)==null||o.setAttribute(oX,s),i.current=s}),i}var AX=()=>{let[e,t]=Q.useState(),n=DX(()=>new Map);return EX(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function jX(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function MX({asChild:e,children:t},n){return e&&Q.isValidElement(t)?Q.cloneElement(jX(t),{ref:t.ref},n(t.props.children)):n(t)}var NX={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`};function PX(e){return e.normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).toLowerCase()}function FX(e,t,n=[]){let r=PX(e.trim());return!r||PX(t).includes(r)?!0:n.some(e=>e&&PX(e).includes(r))}function IX(e,t){return Kb(t.updated_at)-Kb(e.updated_at)}function LX(e,t=8){return[...e].sort(IX).slice(0,Math.max(0,t)).map(e=>({conversation:e,match:`recent`,messageId:null,snippet:null}))}function RX(e,t,n,r=20){let i=PX(t.trim());if(!i)return[];let a=PX(n);return[...e].sort(IX).filter(e=>PX(e.title?.trim()||``).includes(i)||!e.title?.trim()&&a.includes(i)).slice(0,Math.max(0,r)).map(e=>({conversation:e,match:`title`,messageId:null,snippet:null}))}function zX(e,t,n=20){let r=new Map;for(let e of t)r.has(e.conversation.id)||r.set(e.conversation.id,e);let i=[],a=new Set;for(let t of e){let e=r.get(t.conversation.id);i.push(e?{conversation:e.conversation,match:`title`,messageId:e.messageId,snippet:e.snippet}:t),a.add(t.conversation.id)}for(let e of[`title`,`content`])for(let n of t)n.match!==e||a.has(n.conversation.id)||(a.add(n.conversation.id),i.push({conversation:n.conversation,match:n.match,messageId:n.messageId,snippet:n.snippet}));return i.slice(0,Math.max(0,n))}function BX(e){return e===`agent`?[`missions`,`projects`,`spec`,`jobs`,`navigation`]:[`projects`,`missions`,`spec`,`jobs`,`navigation`]}var VX=[];function HX(e){let t=[],n=0;return e.ranges.forEach(([r,i],a)=>{r>n&&t.push(e.text.slice(n,r)),t.push((0,$.jsx)(`mark`,{className:`rounded-sm bg-accent-primary/20 px-0.5 text-foreground`,children:e.text.slice(r,i)},a)),n=i}),n<e.text.length&&t.push(e.text.slice(n)),t}function UX({onOpenSettings:e,onOpenAnalytics:t,onOpenDocs:n}){let{t:r}=K(`commands`),{t:i}=K(`agent`),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)([]),[d,f]=(0,Q.useState)([]),[p,m]=(0,Q.useState)({query:``,hits:VX}),{projects:h,activeProjectId:g,setActiveProjectId:_}=pt(),{leftMode:v,rightMode:b,cycleLeftMode:x,cycleRightMode:S}=XP(),{uiMode:C}=MN(),{conversations:w,liveByConversation:T,selectConversation:E,open:D}=aP(),O=r(v===`pinned-open`?`palette.sidebar.collapseLeftKeepPinned`:v===`pinned-collapsed`?`palette.sidebar.unpinLeft`:`palette.sidebar.pinLeftOpen`),k=r(b===`pinned-open`?`palette.sidebar.collapseRightKeepPinned`:b===`pinned-collapsed`?`palette.sidebar.unpinRight`:`palette.sidebar.pinRightOpen`),A=y(),j=(0,Q.useRef)(!1),M=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{function e(e){e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),o(e=>!e))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,Q.useEffect)(()=>{if(!a){j.current=!1,c(``);return}if(j.current)return;j.current=!0;async function e(){try{let[e,t]=await Promise.all([fetch(`${ut()}/config`),fetch(`${ut()}/jobs?limit=10`)]);if(e.ok){let t=await e.json();u(t.commands)}if(t.ok){let e=await t.json();f(e.jobs)}}catch{}}e()},[a]),(0,Q.useEffect)(()=>{let e=s.trim(),t=++M.current;if(!a||!e)return;let n=new AbortController,r=setTimeout(()=>{to(e,20,n.signal).then(n=>{t===M.current&&m({query:e,hits:n})}).catch(()=>{})},80);return()=>{clearTimeout(r),n.abort()}},[s,a]);let N=i(`mission.untitled`),P=(0,Q.useMemo)(()=>{let e=s.trim();return e?zX(RX(w,e,N),p.query===e?p.hits:VX):LX(w)},[w,s,p,N]),F=(0,Q.useMemo)(()=>new Map(h.map(e=>[e.id,e.name])),[h]),I=(0,Q.useCallback)(e=>{_(e),o(!1)},[_]),L=(0,Q.useCallback)(e=>{o(!1),E(e),C!==`agent`&&D()},[E,D,C]),R=(0,Q.useCallback)(async e=>{o(!1);try{let t=await fetch(`${ut()}/spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({command:`/specrails:${e}`})}),n=await t.json();if(!t.ok)throw Error(n.error??r(`errors.spawnFailed`));J.success(r(`toasts.queued`,{name:e})),A(`/jobs/${n.jobId}`)}catch(e){J.error(e instanceof Error?e.message:r(`errors.spawnFailed`))}},[A,r]),z=(0,Q.useCallback)(e=>{o(!1),A(`/jobs/${e}`)},[A]),B=(0,Q.useCallback)(e=>{o(!1),A(e)},[A]),V=(0,Q.useCallback)(e=>{e&&(o(!1),e())},[]),H=`flex items-center gap-3 px-3 py-2 rounded-lg cursor-pointer text-sm data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground`,U=h.filter(e=>FX(s,e.name,[e.slug])),W=l.filter(e=>FX(s,e.name,[e.slug,e.description??``])),ee=d.filter(e=>FX(s,`${e.command} ${e.id}`,[e.status])),te=[{key:`dashboard`,label:r(`palette.nav.dashboard`),keywords:[`home`],icon:(0,$.jsx)(Hs,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>B(`/`)},...t?[{key:`desktopAnalytics`,label:r(`palette.nav.desktopAnalytics`),keywords:[`cross-project`,`desktop`],icon:(0,$.jsx)(Jo,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>V(t)}]:[],{key:`projectAnalytics`,label:r(`palette.nav.projectAnalytics`),keywords:[`metrics`],icon:(0,$.jsx)(Ko,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>B(`/analytics`)},{key:`activityFeed`,label:r(`palette.nav.activityFeed`),keywords:[`log`],icon:(0,$.jsx)(No,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>B(`/activity`)},{key:`desktopSettings`,label:r(`palette.nav.desktopSettings`),keywords:[`configuration`],icon:(0,$.jsx)(Sc,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>e?V(e):B(`/settings`)},{key:`docs`,label:r(`palette.nav.docs`),keywords:[`documentation`],icon:(0,$.jsx)(Dn,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>n?V(n):B(`/docs`)},{key:`leftSidebar`,label:O,keywords:[`sidebar`,`panel`,`left`,`pin`,`collapse`,`unpin`,`cycle`],icon:(0,$.jsx)(tc,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>{x(),o(!1)}},{key:`rightSidebar`,label:k,keywords:[`sidebar`,`panel`,`right`,`nav`,`pin`,`collapse`,`unpin`,`cycle`],icon:(0,$.jsx)(nc,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>{S(),o(!1)}}].filter(e=>FX(s,e.label,e.keywords)),ne={missions:P.length>0&&(0,$.jsx)(SX.Group,{heading:r(`palette.groups.missions`),"data-testid":`palette-group-missions`,children:P.map(e=>{let{conversation:t}=e,n=T.get(t.id)?.isStreaming===!0,a=t.pinned_project_id?F.get(t.pinned_project_id)??null:null;return(0,$.jsxs)(SX.Item,{value:`mission:${t.id}`,onSelect:()=>L(t.id),className:X(H,`items-start`),"data-testid":`palette-mission-${t.id}`,children:[(0,$.jsx)(bn,{className:`w-4 h-4 mt-0.5 text-accent-primary shrink-0`}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:t.title?.trim()||N}),n&&(0,$.jsxs)(`span`,{"aria-label":i(`mission.working`),"data-testid":`palette-mission-live-${t.id}`,className:`relative flex h-1.5 w-1.5 shrink-0`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full bg-accent-primary opacity-60`}),(0,$.jsx)(`span`,{className:`relative inline-flex h-1.5 w-1.5 rounded-full bg-accent-primary`})]}),(0,$.jsx)(`span`,{className:`ml-auto shrink-0 text-[10px] tabular-nums text-muted-foreground/60`,title:Yb(t.updated_at),children:Jb(t.updated_at)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 text-[11px] text-muted-foreground/60`,children:[(0,$.jsx)(`span`,{className:`shrink-0`,children:a??r(`palette.missions.home`)}),e.snippet&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,$.jsx)(`span`,{className:`truncate`,"data-testid":`palette-mission-snippet-${t.id}`,children:HX(e.snippet)})]})]})]})]},t.id)})},`missions`),projects:U.length>0&&(0,$.jsx)(SX.Group,{heading:r(`palette.groups.projects`),"data-testid":`palette-group-projects`,children:U.map(e=>(0,$.jsxs)(SX.Item,{value:e.name,keywords:[e.slug],onSelect:()=>I(e.id),className:X(H,e.id===g&&`text-accent-primary`),children:[(0,$.jsx)(Ts,{className:`w-4 h-4 text-muted-foreground shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),e.id===g&&(0,$.jsx)(`span`,{className:`text-[10px] text-accent-primary font-medium`,children:r(`palette.activeBadge`)})]},e.id))},`projects`),spec:W.length>0&&(0,$.jsx)(SX.Group,{heading:r(`palette.groups.spec`),children:W.map(e=>(0,$.jsxs)(SX.Item,{value:e.name,keywords:[e.slug,e.description??``],onSelect:()=>R(e.slug),className:H,children:[(0,$.jsx)(wn,{className:`w-4 h-4 text-accent-info shrink-0`}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:e.name}),e.description&&(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground/60 ml-2 truncate`,children:e.description})]})]},e.id))},`spec`),jobs:ee.length>0&&(0,$.jsx)(SX.Group,{heading:r(`palette.groups.jobs`),children:ee.map(e=>(0,$.jsxs)(SX.Item,{value:`${e.command} ${e.id}`,keywords:[e.status],onSelect:()=>z(e.id),className:H,children:[(0,$.jsx)(Go,{className:`w-4 h-4 text-muted-foreground shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.command}),(0,$.jsx)(`span`,{className:X(`text-[10px] font-medium`,e.status===`completed`&&`text-accent-success`,e.status===`failed`&&`text-destructive`,e.status===`running`&&`text-accent-info`,e.status===`queued`&&`text-muted-foreground`),children:r(`common:status.${e.status}`,{defaultValue:e.status})})]},e.id))},`jobs`),navigation:te.length>0&&(0,$.jsx)(SX.Group,{heading:r(`palette.groups.navigation`),children:te.map(e=>(0,$.jsxs)(SX.Item,{value:e.label,keywords:e.keywords,onSelect:e.onSelect,className:H,children:[e.icon,(0,$.jsx)(`span`,{children:e.label})]},e.key))},`navigation`)};return(0,$.jsxs)(SX.Dialog,{open:a,onOpenChange:o,shouldFilter:!1,label:r(`palette.label`),className:X(`fixed left-[50%] top-[50%] z-50 w-full max-w-lg translate-x-[-50%] translate-y-[-50%]`,`border border-border/30 bg-popover shadow-2xl backdrop-blur-md rounded-xl overflow-hidden`),children:[(0,$.jsx)(`span`,{className:`sr-only`,children:r(`palette.label`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 border-b border-border/30`,children:[(0,$.jsx)(In,{className:`w-4 h-4 text-muted-foreground shrink-0`}),(0,$.jsx)(SX.Input,{value:s,onValueChange:c,placeholder:r(C===`agent`?`palette.searchPlaceholderAgent`:`palette.searchPlaceholder`),className:`flex-1 h-11 bg-transparent text-sm outline-none placeholder:text-muted-foreground/50`}),(0,$.jsx)(`kbd`,{className:`hidden sm:inline-flex items-center gap-0.5 rounded border border-border/50 bg-muted/30 px-1.5 py-0.5 text-[10px] text-muted-foreground font-mono`,children:`esc`})]}),(0,$.jsxs)(SX.List,{className:`max-h-80 overflow-y-auto p-2`,children:[(0,$.jsx)(SX.Empty,{className:`py-8 text-center text-sm text-muted-foreground`,children:r(`palette.noResults`)}),BX(C).map(e=>ne[e])]}),(0,$.jsx)(`div`,{className:`flex items-center justify-between px-3 py-2 border-t border-border/30 text-[10px] text-muted-foreground/50`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`kbd`,{className:`font-mono`,children:`↑↓`}),` `,r(`palette.footer.navigate`)]}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`kbd`,{className:`font-mono`,children:`↵`}),` `,r(`palette.footer.select`)]}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`kbd`,{className:`font-mono`,children:`esc`}),` `,r(`palette.footer.close`)]})]})})]})}var WX=`
|
|
75
75
|
|
|
76
76
|
---
|
|
77
77
|
|
|
78
78
|
## Contract Layer
|
|
79
79
|
|
|
80
|
-
`;function GX(e){return`contract-refine:${e}`}async function KX(e,t){try{let n=await fetch(`${Xe}/api/projects/${e}/tickets/${t}/contract-refine`,{method:`POST`});if(n.ok)J.loading(Je.t(`activity:contractRefine.refining`),{id:GX(t)});else{let e=await n.json().catch(()=>({}));J.error(e.error?Je.t(`activity:contractRefine.retryRejectedWithError`,{error:e.error}):Je.t(`activity:contractRefine.retryRejected`),{id:GX(t)})}}catch(e){J.error(Je.t(`activity:contractRefine.retryFailed`,{message:e.message}),{id:GX(t)})}}function qX({children:e}){let{registerHandler:t,unregisterHandler:n}=tt(),r=(0,Q.useRef)(new Map),i=(0,Q.useCallback)(e=>{let t=e;if(!t||t.type!==`explore.contract_refine_failed`)return;let n=t.ticketId,i=t.projectId,a=typeof t.provider==`string`?t.provider:void 0,o=t.reason??`unknown`;if(typeof n!=`number`||!i)return;r.current.set(n,i);let s=Tt(a)?{label:Je.t(`common:actions.retry`),onClick:()=>void KX(i,n)}:void 0;J.error(Je.t(`activity:contractRefine.skipped`),{id:GX(n),description:Je.t(`activity:contractRefine.reason`,{reason:o}),...s?{action:s}:{},duration:15e3})},[]),a=(0,Q.useCallback)(e=>{let t=e;if(!t||t.type!==`ticket_updated`)return;let n=t.ticket;n&&typeof n.description==`string`&&n.description.includes(WX)&&J.success(Je.t(`activity:contractRefine.added`,{title:n.title||`#${n.id}`}),{id:GX(n.id),duration:3500})},[]);return(0,Q.useLayoutEffect)(()=>(t(`_contract_refine_failed`,i),t(`_contract_refine_ticket_updated`,a),()=>{n(`_contract_refine_failed`),n(`_contract_refine_ticket_updated`)}),[t,n,i,a]),(0,Q.useEffect)(()=>()=>r.current.clear(),[]),(0,$.jsx)($.Fragment,{children:e})}function JX(){return typeof window<`u`&&`__TAURI_INTERNALS__`in window}function YX(){let{t:e}=K(`mcp`),t=iK()?.languageId;(0,Q.useEffect)(()=>{JX()&&Y(`set_tray_labels`,{open:e(`tray.open`),exit:e(`tray.exit`)}).catch(()=>{})},[e,t])}var XX=`input, textarea, select, [contenteditable="true"], [contenteditable=""], .monaco-editor, .xterm, [data-native-menu]`;function ZX(e){return e instanceof Element&&e.closest(XX)!==null}function QX(e){ZX(e.target)||e.preventDefault()}function $X(){(0,Q.useEffect)(()=>(document.addEventListener(`contextmenu`,QX),()=>document.removeEventListener(`contextmenu`,QX)),[])}var eZ={jobs:[],activeJobId:null,paused:!1};function tZ(e){let[t,n]=(0,Q.useState)([]),[r,i]=(0,Q.useState)({}),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)([]),[l,u]=(0,Q.useState)([]),[d,f]=(0,Q.useState)(eZ),[p,m]=(0,Q.useState)(0),h=(0,Q.useRef)(e);h.current=e;let g=(0,Q.useRef)(new Map),_=(0,Q.useRef)(void 0);(0,Q.useEffect)(()=>{if(_.current&&_.current,_.current=e,e){let t=g.current.get(e);t?(n(t.phaseDefinitions),i(t.phases),o(t.projectName),u(t.recentJobs),f(t.queueState)):(n([]),i({}),o(``),u([]),f(eZ))}c([])},[e]);let v=(0,Q.useCallback)(e=>{let t=e;if(!t||typeof t.type!=`string`)return;let r=h.current;if(!(r&&t.projectId&&t.projectId!==r))if(t.type===`desktop.project_recovered`)t.projectId===r&&m(e=>e+1);else if(t.type===`init`){let e=t.projectName??``,a=t.phaseDefinitions??[],s={};for(let e of a)s[e.key]=t.phases?.[e.key]??`idle`;let l=t.recentJobs??[],d=t.queue??eZ;o(e),n(a),i(s),c(t.logBuffer??[]),u(l),f(d),r&&g.current.set(r,{phaseDefinitions:a,phases:s,projectName:e,recentJobs:l,queueState:d})}else t.type===`phase`?i(e=>({...e,[t.phase]:t.state})):t.type===`log`?c(e=>[...e,{source:t.source,line:t.line,timestamp:t.timestamp,processId:t.processId}]):t.type===`queue`&&f({jobs:t.jobs??[],activeJobId:t.activeJobId??null,paused:t.paused??!1})},[]),{registerHandler:y,unregisterHandler:b,connectionStatus:x}=tt();return(0,Q.useLayoutEffect)(()=>(y(`pipeline`,v),()=>b(`pipeline`)),[v,y,b]),(0,Q.useEffect)(()=>{if(!e)return;let t=!1;async function r(){try{let e=await fetch(`${ut()}/state`);if(t||!e.ok)return;let r=await e.json();if(t)return;if(r.projectName&&o(r.projectName),r.phaseDefinitions){n(r.phaseDefinitions);let e={};for(let t of r.phaseDefinitions)e[t.key]=r.phases?.[t.key]??`idle`;i(e)}r.recentJobs&&u(r.recentJobs),r.queue&&f(r.queue)}catch{}}return r(),()=>{t=!0}},[e,p]),{phases:r,phaseDefinitions:t,projectName:a,logLines:s,connectionStatus:x,recentJobs:l,queueState:d}}function nZ({connectionStatus:e,rightSlot:t,minimal:n=!1}){let{t:r}=K(`nav`),{t:i}=K(`analytics`),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!1),l=(0,Q.useRef)(`connecting`),u=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>{let t=l.current;if(e===`connected`&&!u.current&&t!==`connected`){J.success(r(`statusBar.connectionRestored`)),c(!0);let e=setTimeout(()=>c(!1),2e3);return()=>clearTimeout(e)}u.current&&e===`connected`&&(u.current=!1),l.current=e},[e]),(0,Q.useEffect)(()=>{u.current&&=!1},[]),(0,Q.useEffect)(()=>{if(n)return;async function e(){try{let e=await fetch(`${ut()}/stats`);if(e.ok){let t=await e.json();o(t)}}catch{}}e();let t=setInterval(e,3e4);return()=>clearInterval(t)},[e,n]);let d=!n||e!==`connected`||s;return(0,$.jsxs)(`footer`,{className:`h-7 flex items-center justify-between px-4 border-t border-border/30 bg-background/80 backdrop-blur-sm text-[10px] text-muted-foreground`,children:[(0,$.jsxs)(`div`,{className:X(`flex items-center gap-1.5 transition-opacity duration-300`,!d&&`opacity-0`),"aria-hidden":!d||void 0,children:[(0,$.jsx)(`span`,{className:X(`w-1.5 h-1.5 rounded-full transition-colors`,e===`connected`&&!s&&`bg-accent-success`,e===`connected`&&s&&`bg-accent-info animate-pulse`,e===`connecting`&&`bg-accent-warning animate-[pulse_0.75s_ease-in-out_infinite]`,e===`disconnected`&&`bg-destructive`)}),(0,$.jsxs)(`span`,{className:X(`transition-colors`,e===`connected`&&!s&&`text-accent-success`,e===`connected`&&s&&`text-accent-info`,e===`connecting`&&`text-accent-warning`,e===`disconnected`&&`text-destructive`),children:[e===`connected`&&!s&&r(`statusBar.connected`),e===`connected`&&s&&r(`statusBar.syncing`),e===`connecting`&&r(`statusBar.reconnecting`),e===`disconnected`&&r(`statusBar.disconnected`)]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!n&&a&&(a.totalCostUsd>0||(a.unpricedRuns??0)>0)&&(()=>{let e=a.includesEstimated??((a.estimatedCostUsd??0)>0||(a.estimatedCostToday??0)>0),t=a.unpricedRuns??0,n=a.pricedRuns??Math.max(0,(a.totalJobs??0)-t),r=a.totalCostUsd===0&&t>0&&n===0,o=t>0&&(n>0||a.totalCostUsd>0);return(0,$.jsx)(`span`,{"data-estimated":e?`true`:void 0,"data-testid":r?`statusbar-cost-unavailable`:void 0,title:r?i(`desktop.costUnavailable`):o?i(`desktop.costPartiallyUnavailable`,{count:t}):e?i(`desktop.statusBarEstimatedTooltip`):void 0,children:r?i(`desktop.costUnavailableShort`):`${e?`~`:``}${o?`≥`:``}$${a.totalCostUsd.toFixed(2)}`})})(),t]})]})}var rZ=(0,Q.lazy)(()=>c(()=>import(`./AgentBrowserCapture-Bnu8aoF2.js`).then(e=>({default:e.AgentBrowserCapture})),__vite__mapDeps([89,1,7,9,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76])));function iZ(){let{browserOpen:e}=lO(),{active:t}=aP(),n=Ci(),r=!n.current&&n.transfers.some(e=>e.conversationId===t?.id&&e.state===`detached`),{activeProjectId:i}=pt();return!e||!i||r?null:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(rZ,{projectId:i,conversationId:t?.id??null})})}function aZ(){let{state:e,openTicketDetail:t,enterSplit:n,setComparedTicket:r}=be(),{tickets:i}=k(),a=p(),o=y(),s=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{if(s.current||i.length===0||new URLSearchParams(a.search).get(`compare`)&&typeof window<`u`&&window.innerWidth<900)return;s.current=!0;let e=new URLSearchParams(a.search),c=e.get(`compare`),l=e.get(`compareSide`);if(!c)return;let u=Number.parseInt(c,10),d=l===`right`?`right`:`left`;if(!i.some(e=>e.id===u)){let e=new URLSearchParams(a.search);e.delete(`compare`),e.delete(`compareSide`);let t=e.toString();o({pathname:a.pathname,search:t?`?${t}`:``},{replace:!0});return}let f=e.get(`compareOrigin`);if(f){let e=Number.parseInt(f,10);if(i.some(t=>t.id===e)){t(e),n(d),r(u,d===`left`?`right`:`left`);return}}t(u)},[i,a.search,a.pathname,o,t,n,r]),(0,Q.useEffect)(()=>{if(!s.current)return;let t=new URLSearchParams(a.search),n=t.has(`compare`);if(e.originSide===null){if(n){t.delete(`compare`),t.delete(`compareSide`),t.delete(`compareOrigin`);let e=t.toString();o({pathname:a.pathname,search:e?`?${e}`:``},{replace:!0})}return}let r=e.originSide===`left`?e.leftId:e.rightId,i=e.originSide===`left`?e.rightId:e.leftId;if(r==null||e.originSide==null)return;let c=new URLSearchParams(a.search);c.set(`compareSide`,e.originSide),c.set(`compareOrigin`,String(r)),i==null?c.delete(`compare`):c.set(`compare`,String(i));let l=c.toString();l!==(a.search.startsWith(`?`)?a.search.slice(1):a.search)&&o({pathname:a.pathname,search:l?`?${l}`:``},{replace:!0})},[e,a.search,a.pathname,o])}function oZ(e){let{key:t,detail:n}=nn(e);return[`chunk_failed`,`chunk_stalled`,`chunk_stopped`,`provider_limit`,`launch_rejected`,`head_missing`,`head_discarded`,`run_lost`].includes(t)?Je.t(`builder:milestoneProgress.chain.reasons.${t}`,{detail:n}):e??``}function sZ({setActiveProjectId:e}={}){let t=y(),n=(0,Q.useRef)(t);(0,Q.useEffect)(()=>{n.current=t},[t]);let r=(0,Q.useRef)(e);(0,Q.useEffect)(()=>{r.current=e},[e]);let i=(0,Q.useRef)(new Map),a=(0,Q.useRef)(new Map),{registerHandler:o,unregisterHandler:s}=tt();(0,Q.useEffect)(()=>{let e=`milestone-notifications`;return o(e,e=>{let t=e;if(!t||typeof t.projectId!=`string`)return;let o=t.projectId;if(t.type===`milestone.chain_changed`){let e=Ut(t.chain);if(!e)return;let n=i.current.get(e.id);i.current.set(e.id,e);let r=Gt(e.milestoneN);if(e.status===`running`&&e.nextChunk>1&&(!n||n.nextChunk<e.nextChunk)&&J.success(Je.t(`builder:milestoneProgress.toast.chunkLaunched`,{milestone:r,k:e.nextChunk,n:e.totalChunks}),{id:`chain-launch:${e.id}:${e.nextChunk}`}),e.status===`awaiting_approval`&&(!n||n.status!==`awaiting_approval`||n.nextChunk!==e.nextChunk)){let t=`chain-checkpoint:${e.id}:${e.nextChunk}`;J.success(Je.t(`builder:milestoneProgress.toast.checkpoint`,{milestone:r,k:e.nextChunk,n:e.totalChunks}),{id:t,duration:6e4,action:{label:Je.t(`builder:milestoneProgress.toast.launchNext`),onClick:()=>{wM(o,e.id).then(e=>{e.ok?J.success(Je.t(`builder:milestoneProgress.chain.nextLaunched`),{id:t}):J.error(Je.t(`builder:milestoneProgress.chain.resumeFailed`),{id:t,description:e.detail??e.error})})}},cancel:{label:Je.t(`builder:milestoneProgress.toast.autoContinue`),onClick:()=>{EM(o,e.id,!0).then(e=>{e.ok?J.success(Je.t(`builder:milestoneProgress.chain.autoOn`),{id:t}):J.error(Je.t(`builder:milestoneProgress.chain.autoFailed`),{id:t,description:e.detail??e.error})})}}})}e.status===`paused`&&(!n||n.status!==`paused`||n.pauseReason!==e.pauseReason)&&J.warning(Je.t(`builder:milestoneProgress.toast.paused`,{milestone:r,reason:oZ(e.pauseReason)}),{id:`chain-paused:${e.id}`,duration:3e4,action:{label:Je.t(`builder:milestoneProgress.toast.resume`),onClick:()=>{wM(o,e.id).then(t=>{t.ok?J.success(Je.t(`builder:milestoneProgress.chain.resumed`),{id:`chain-paused:${e.id}`}):J.error(Je.t(`builder:milestoneProgress.chain.resumeFailed`),{id:`chain-paused:${e.id}`,description:t.detail??t.error})})}}});return}if(t.type===`blueprint.milestone_progress`){for(let e of Xt(t.progress)){let t=`${o}:${e.id}`,i=a.current.get(t);if(a.current.set(t,e.state),!(i===void 0||i===e.state)&&e.state===`delivered`){let i=Zt(e);J.success(Je.t(`builder:milestoneProgress.toast.delivered`,{milestone:Gt(e.n),count:e.counts.onReview}),{id:`milestone-delivered:${t}`,duration:3e4,...i?{action:{label:Je.t(`builder:milestoneProgress.toast.review`),onClick:()=>{r.current?.(o);let e=le?`/review/${i.id}`:`/`;setTimeout(()=>{n.current(e)},50)}}}:{}})}}return}t.type===`blueprint.milestone_completed`&&typeof t.n==`number`&&J.success(Je.t(`builder:milestoneProgress.toast.completed`,{milestone:Gt(t.n)}),{id:`milestone-completed:${o}:${t.milestoneId??t.n}`,duration:15e3})}),()=>s(e)},[o,s])}function cZ(e){return e.startsWith(`/loops`)?`loops`:e.startsWith(`/plugins`)?`plugins`:lZ(e)?`review`:null}function lZ(e){let t=/^\/review\/([^/]+)\/?$/.exec(e);return t?decodeURIComponent(t[1]):null}function uZ(e){let t=/^\/loops\/([^/]+)\/edit\/?$/.exec(e);return t?decodeURIComponent(t[1]):null}function dZ({uiMode:e,pathname:t,loopsOpen:n,pluginsOpen:r,reviewOpen:i=null}){if(e===`agent`){let e=cZ(t);if(!e)return null;if(e===`review`)return{kind:`modalize`,surface:e,backgroundPath:`/`,reviewDeliveryId:lZ(t)??void 0};let n=e===`loops`?uZ(t):null;return n?{kind:`modalize`,surface:e,backgroundPath:`/`,loopBuilderId:n}:{kind:`modalize`,surface:e,backgroundPath:`/`}}return n?{kind:`route`,surface:`loops`,path:`/loops`}:r?{kind:`route`,surface:`plugins`,path:`/plugins`}:i?{kind:`route`,surface:`review`,path:`/review/${encodeURIComponent(i)}`}:null}var fZ=(0,Q.lazy)(()=>c(()=>import(`./JobDetailPage-DbzshFhr.js`),__vite__mapDeps([90,1,7,11,10,9,8,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,85]))),pZ=(0,Q.lazy)(()=>c(()=>import(`./ReviewPacketPage-Bs_jaLbJ.js`),__vite__mapDeps([91,1,7,11,10,9,8,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,92]))),mZ=(0,Q.lazy)(()=>c(()=>import(`./JobsPage-DY4qRt9_.js`),__vite__mapDeps([93,1,7,11,10,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,45,8,53,64,65,51,67,68,69,70,71,72,73,80,85,94,54]))),hZ=(0,Q.lazy)(()=>c(()=>import(`./AnalyticsPage-CO8-ON4i.js`),__vite__mapDeps([95,1,7,11,10,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,8,46,48,69,71,72,94,54,96,97]))),gZ=(0,Q.lazy)(()=>c(()=>import(`./ActivityFeedPage-CEWktcV8.js`),__vite__mapDeps([98,1,7,12,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,45,8,52,53,58]))),_Z=(0,Q.lazy)(()=>c(()=>import(`./AgentsPage-BXgiO5qZ.js`),__vite__mapDeps([99,1,7,8,12,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,49,11,50,51,55,58,59,61,63,64,65,67,68,69,73,85]))),vZ=(0,Q.lazy)(()=>c(()=>import(`./CodePage-CMSInNsE.js`),__vite__mapDeps([100,1,7,8,10,11,9,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76]))),yZ=(0,Q.lazy)(()=>c(()=>import(`./IntegrationsPage-Bhy58lnQ.js`),__vite__mapDeps([101,7,1,11,10]))),bZ=(0,Q.lazy)(()=>c(()=>import(`./PluginsPage-BUdxGBro.js`),__vite__mapDeps([102,1,7,12,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,45,8,46,54,58,63,64,65,66,67,51,68,69,73,74]))),xZ=(0,Q.lazy)(()=>c(()=>import(`./DesktopAnalyticsPage-1ekD8Gob.js`),__vite__mapDeps([103,1,7,12,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,69,68,96,8,97]))),SZ=(0,Q.lazy)(()=>c(()=>import(`./DocsPage-DHdvuLeh.js`),__vite__mapDeps([104,1,7,11,10,43,55,58,68,69,70,79,105,106]))),CZ=(0,Q.lazy)(()=>c(()=>import(`./DocsDialog-CZ1QztVB.js`),__vite__mapDeps([107,1,7,43,55,58,67,8,51,68,69,70,79,105,106]))),wZ=(0,Q.lazy)(()=>c(()=>import(`./LoopsPage-C-RjiAxo.js`),__vite__mapDeps([108,1,7,11,10,43,45,8,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,46,54,59,60,61,50,64,109,67,51,68,69,73,75,76,82,56]))),TZ=(0,Q.lazy)(()=>c(()=>import(`./LoopBuilderPage-DTqzBtuf.js`),__vite__mapDeps([110,1,7,8,11,10,43,45,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,47,56,60,61,62,64,65,109,67,51,68,69,73,76,97,111]))),EZ=28;function DZ({surface:e,onClose:t}){let{t:n}=K(`nav`),r=n(e===`loops`?`arcSidebar.loops`:e===`review`?`arcSidebar.review`:`arcSidebar.plugins`);return(0,$.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center justify-between gap-3 border-b border-border bg-popover/95 px-3`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`grid h-7 w-7 shrink-0 place-items-center rounded-md border border-accent-primary/20 bg-accent-primary/10 text-accent-primary`,children:(0,$.jsx)(e===`loops`?Lc:e===`review`?vs:uc,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:`truncate text-xs font-medium text-foreground`,children:r})]}),(0,$.jsx)(`div`,{className:`flex shrink-0 items-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:t,className:`grid h-7 w-7 place-items-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-popover`,"aria-label":n(`common:actions.close`),children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})})]})}var OZ=new Set([`/settings`,`/loops`,`/plugins`]);function kZ(e){return OZ.has(e)||e.startsWith(`/loops`)||e.startsWith(`/plugins`)||e.startsWith(`/docs`)}var AZ=`specrails-desktop:routeMemory`;try{localStorage.removeItem(AZ)}catch{}function jZ(e){let t=p(),n=y(),r=(0,Q.useRef)(new Map),i=(0,Q.useRef)(null),a=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{ej((e,t)=>{r.current.set(e,t)})},[]),(0,Q.useEffect)(()=>{a.current||(a.current=!0,t.pathname!==`/`&&n(`/`,{replace:!0}))},[]),(0,Q.useEffect)(()=>{if(i.current&&i.current!==e&&!kZ(t.pathname)&&r.current.set(i.current,t.pathname),e&&e!==i.current){let i=r.current.get(e),a=i&&!kZ(i)?i:`/`;t.pathname!==a&&n(a,{replace:!0})}i.current=e},[e,t.pathname,n]),(0,Q.useEffect)(()=>{e&&t.pathname!==`/`&&!kZ(t.pathname)&&r.current.set(e,t.pathname)},[e,t.pathname])}function MZ(){let{t:e}=K(`common`),{projects:t,activeProjectId:n,isLoading:r,isSwitchingProject:i,setActiveProjectId:a}=pt(),{cycleLeftMode:o,cycleRightMode:s}=XP(),c=y(),l=p(),u=za(),d=aP(),{startNewConversation:m}=d,{uiMode:g}=MN();aZ();let[v,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(`appearance`),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(!1),[k,A]=(0,Q.useState)(null),[j,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(null),[F,I]=(0,Q.useState)(!1),L=(0,Q.useCallback)(()=>I(!1),[]),[R,z]=(0,Q.useState)(()=>!QJ());jZ(n),YX();let{cheatsheetOpen:B,setCheatsheetOpen:V,openCheatsheet:H}=cJ(),U=[`/`,`/jobs`,`/analytics`,...je?[`/agents`]:[],...me?[`/code`]:[],`/integrations`,`/settings`];sJ({onOpenCheatsheet:H,onToggleLeftSidebar:o,onToggleRightSidebar:s,onSwitchProject:e=>{let n=t[e-1];n&&a(n.id)},onSwitchProjectPage:e=>{let t=U[e-1];t&&c(t)},onToggleTerminalPanel:Te?()=>{n&&(u.togglePanel(n),u.getState(n).visibility===`hidden`?queueMicrotask(()=>u.focusActive(n)):u.focusActive(n))}:void 0,onToggleAgentChat:xe&&g!==`agent`?()=>d.toggle():void 0}),Qq({setActiveProjectId:a,projectsById:(0,Q.useMemo)(()=>new Map(t.map(e=>[e.id,e.name])),[t])}),sZ({setActiveProjectId:a}),(0,Q.useEffect)(()=>{vM()},[]);let W=t.find(e=>e.id===n),ee=l.pathname.startsWith(`/loops`),te=l.pathname.startsWith(`/plugins`),ne=l.pathname.startsWith(`/docs`)||g!==`agent`&&(ee||te);(0,Q.useLayoutEffect)(()=>{let e=dZ({uiMode:g,pathname:l.pathname,loopsOpen:D,pluginsOpen:j,reviewOpen:N});if(e){if(e.kind===`modalize`){if(e.surface===`review`){e.reviewDeliveryId&&P(e.reviewDeliveryId),l.pathname!==e.backgroundPath&&c(e.backgroundPath,{replace:!0});return}e.surface===`loops`?(M(!1),O(!0),e.loopBuilderId&&A(e.loopBuilderId)):(O(!1),M(!0)),m(n),l.pathname!==e.backgroundPath&&c(e.backgroundPath,{replace:!0});return}O(!1),M(!1),P(null),l.pathname!==e.path&&c(e.path,{replace:!0})}},[n,l.pathname,D,c,j,N,m,g]);let{connectionStatus:re}=tZ(),ie=Ba(n),ae=g===`agent`?0:EZ,oe=(0,Q.useRef)(null),[se,ce]=(0,Q.useState)(typeof window<`u`?window.innerHeight:820);(0,Q.useLayoutEffect)(()=>{if(!Te)return;let e=oe.current;if(!e)return;let t=()=>ce(e.clientHeight);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[r]),(0,Q.useEffect)(()=>{!Te||!n||u.ensureProject(n)},[n,u]);let ue=Te&&g===`kanban`&&ie.visibility===`hidden`?(0,$.jsx)(yF,{isOpen:!1,onClick:()=>n&&u.setVisibility(n,`restored`)}):null;return r?(0,$.jsxs)(`div`,{className:`flex h-full`,children:[(0,$.jsx)(`div`,{className:`w-11 border-r border-border bg-card/50 animate-pulse flex-shrink-0`}),(0,$.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`states.loading`)})})]}):(0,$.jsxs)(`div`,{className:`flex h-full overflow-hidden font-sans`,children:[(0,$.jsx)(TY,{onOpenCompanion:()=>{S(`mobile`),w(!0)},onAddProject:()=>b(!0),onOpenLoops:()=>{g===`agent`?O(!0):c(`/loops`)},onOpenPlugins:()=>{g===`agent`?M(!0):c(`/plugins`)},onOpenAnalytics:()=>E(!0),onOpenDocs:()=>I(!0),onOpenSettings:()=>{S(`appearance`),w(!0)}}),(0,$.jsxs)(`div`,{ref:oe,className:`flex flex-col flex-1 overflow-hidden`,children:[i&&(0,$.jsx)(`div`,{className:`h-0.5 w-full bg-accent-primary/70 animate-pulse shrink-0`,"data-testid":`project-switching-bar`}),(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:g===`agent`&&!ne?(0,$.jsx)(IP,{}):(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`states.loading`)})}),children:(0,$.jsxs)(_,{children:[(0,$.jsx)(h,{path:`/docs`,element:(0,$.jsx)(SZ,{})}),(0,$.jsx)(h,{path:`/docs/:category/:slug`,element:(0,$.jsx)(SZ,{})}),ke&&(0,$.jsx)(h,{path:`/loops`,element:(0,$.jsx)(wZ,{})}),ke&&(0,$.jsx)(h,{path:`/loops/:id/edit`,element:(0,$.jsx)(TZ,{})}),(0,$.jsx)(h,{path:`/plugins`,element:(0,$.jsx)(bZ,{})}),t.length===0?(0,$.jsx)(h,{path:`*`,element:(0,$.jsx)(YJ,{onAddProject:()=>b(!0)})}):W?(0,$.jsxs)(h,{element:(0,$.jsx)(JJ,{projectName:W.name,children:(0,$.jsx)(KJ,{project:W})},W.id),children:[(0,$.jsx)(h,{path:`/`,element:(0,$.jsx)(MW,{})}),(0,$.jsx)(h,{path:`/jobs`,element:(0,$.jsx)(mZ,{})}),(0,$.jsx)(h,{path:`/jobs/:id`,element:(0,$.jsx)(fZ,{})}),le&&(0,$.jsx)(h,{path:`/review/:prDeliveryId`,element:(0,$.jsx)(pZ,{})}),(0,$.jsx)(h,{path:`/analytics`,element:(0,$.jsx)(hZ,{})}),(0,$.jsx)(h,{path:`/activity`,element:(0,$.jsx)(gZ,{})}),(0,$.jsx)(h,{path:`/agents`,element:(0,$.jsx)(_Z,{})}),(0,$.jsx)(h,{path:`/code`,element:me?(0,$.jsx)(vZ,{}):(0,$.jsx)(f,{to:`/`,replace:!0})}),(0,$.jsx)(h,{path:`/integrations`,element:(0,$.jsx)(yZ,{})}),(0,$.jsx)(h,{path:`/settings`,element:(0,$.jsx)(JG,{})}),(0,$.jsx)(h,{path:`*`,element:(0,$.jsx)(f,{to:`/`,replace:!0})})]}):(0,$.jsx)(h,{path:`*`,element:(0,$.jsx)(YJ,{onAddProject:()=>b(!0)})})]})})}),Te&&n&&W&&(0,$.jsx)(BF,{projectId:n,provider:W.provider,providers:dt(W),state:ie,viewportHeight:se,statusBarHeight:ae}),g!==`agent`&&(0,$.jsx)(nZ,{connectionStatus:re,rightSlot:ue})]}),g===`agent`?!ne&&(0,$.jsx)(eF,{}):W&&!ne&&(0,$.jsx)(DY,{}),(0,$.jsx)(RY,{open:v,onClose:()=>b(!1),onOpenBuilder:()=>d.builderMode.enter()}),(0,$.jsx)(nJ,{initialSection:x,open:C,onClose:()=>w(!1),onOpenOnboarding:()=>{w(!1),z(!0)}}),(0,$.jsx)(mr,{open:T,onOpenChange:E,children:(0,$.jsx)(fr,{className:`max-w-5xl max-h-[90vh] overflow-hidden p-0 flex flex-col`,children:(0,$.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`flex items-center justify-center h-40`,children:(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`states.loading`)})}),children:(0,$.jsx)(xZ,{})})})})}),(0,$.jsx)(mr,{open:D,onOpenChange:e=>{O(e),e||A(null)},children:(0,$.jsxs)(fr,{showCloseButton:!1,className:`max-w-[96vw] w-[96vw] h-[92vh] max-h-[92vh] overflow-hidden p-0 flex flex-col`,children:[(0,$.jsx)(sr,{className:`sr-only`,children:e(`nav:arcSidebar.loops`)}),(0,$.jsx)(ir,{className:`sr-only`,children:e(`nav:globalSurfaceModal.loopsDescription`)}),(0,$.jsx)(DZ,{surface:`loops`,onClose:()=>{O(!1),A(null)}}),(0,$.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`flex items-center justify-center h-40`,children:(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`states.loading`)})}),children:k?(0,$.jsx)(`div`,{className:`h-full`,children:(0,$.jsx)(TZ,{loopId:k,onExit:()=>A(null)})}):(0,$.jsx)(wZ,{onOpenBuilder:A})})})]})}),le&&(0,$.jsx)(mr,{open:N!==null,onOpenChange:e=>{e||P(null)},children:(0,$.jsxs)(fr,{showCloseButton:!1,className:`max-w-[96vw] w-[96vw] h-[92vh] max-h-[92vh] overflow-hidden p-0 flex flex-col`,"data-testid":`review-packet-modal`,children:[(0,$.jsx)(sr,{className:`sr-only`,children:e(`nav:arcSidebar.review`)}),(0,$.jsx)(ir,{className:`sr-only`,children:e(`nav:globalSurfaceModal.reviewDescription`)}),(0,$.jsx)(DZ,{surface:`review`,onClose:()=>P(null)}),(0,$.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`flex items-center justify-center h-40`,children:(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`states.loading`)})}),children:N&&(0,$.jsx)(pZ,{prDeliveryId:N,onClose:()=>P(null)})})})]})}),(0,$.jsx)(mr,{open:j,onOpenChange:M,children:(0,$.jsxs)(fr,{showCloseButton:!1,className:`max-w-[96vw] w-[96vw] h-[92vh] max-h-[92vh] overflow-hidden p-0 flex flex-col`,children:[(0,$.jsx)(sr,{className:`sr-only`,children:e(`nav:arcSidebar.plugins`)}),(0,$.jsx)(ir,{className:`sr-only`,children:e(`nav:globalSurfaceModal.pluginsDescription`)}),(0,$.jsx)(DZ,{surface:`plugins`,onClose:()=>M(!1)}),(0,$.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`flex items-center justify-center h-40`,children:(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`states.loading`)})}),children:(0,$.jsx)(bZ,{})})})]})}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(CZ,{open:F,onClose:L})}),(0,$.jsx)(UX,{onOpenSettings:()=>{S(`appearance`),w(!0)},onOpenAnalytics:()=>E(!0),onOpenDocs:()=>I(!0)}),(0,$.jsx)(pJ,{open:B,onOpenChange:V}),(0,$.jsx)(pY,{open:R,onClose:()=>z(!1)})]})}function NZ({children:e}){let{activeProjectId:t}=pt();return(0,$.jsx)(La,{activeProjectId:t,children:e})}function PZ({children:e}){let{activeProjectId:t}=pt();return(0,$.jsx)(YU,{activeProjectId:t,children:e})}function FZ({children:e}){let{activeProjectId:t}=pt();return(0,$.jsx)(nW,{activeProjectId:t,children:e})}function IZ(){return(0,$.jsx)(`span`,{"aria-hidden":!0,style:{display:`none`}})}function LZ(){let{theme:e}=Sa(),t=e.previewSwatches.accents[0],n=e.status.completed,r=e.status.failed,i=e.status.canceled,a=e.status.running;return(0,Hb.createPortal)((0,$.jsx)(ft,{position:`bottom-right`,className:`specrails-toaster`,theme:e.scheme,gap:8,closeButton:!0,visibleToasts:6,icons:{loading:(0,$.jsx)(IZ,{})},style:{"--accent":t,"--toast-success-border":`color-mix(in srgb, ${n} 38%, transparent)`,"--toast-error-border":`color-mix(in srgb, ${r} 38%, transparent)`,"--toast-warning-border":`color-mix(in srgb, ${i} 38%, transparent)`,"--toast-info-border":`color-mix(in srgb, ${a} 38%, transparent)`},toastOptions:{unstyled:!0,classNames:{toast:`glass-card border border-border/30 text-foreground text-xs p-3 rounded-lg flex items-start gap-2 w-[356px] max-w-[356px] overflow-hidden shadow-lg`,content:`flex-1 min-w-0 flex flex-col gap-0.5`,icon:`shrink-0 mt-[2px] flex items-center justify-center`,title:`font-medium text-sm`,description:`text-muted-foreground mt-0.5`,actionButton:`text-[11px] px-2.5 py-1 rounded-md bg-accent-primary text-white hover:bg-accent-primary/90 whitespace-nowrap shrink-0 self-start`,cancelButton:`text-[11px] px-2.5 py-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent/50 whitespace-nowrap shrink-0 self-start`,closeButton:`text-muted-foreground hover:text-foreground rounded-md p-0.5`,success:`border-l-4 border-l-[var(--toast-success-border)]`,error:`border-l-4 border-l-[var(--toast-error-border)]`,warning:`border-l-4 border-l-[var(--toast-warning-border)]`,info:`border-l-4 border-l-[var(--toast-info-border)]`,loading:``}}}),document.body)}function RZ(){return $K(),null}function zZ(){let e=hi();return $X(),(0,$.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100vh`,overflow:`hidden`},children:(0,$.jsx)(`div`,{style:{flex:1,overflow:`hidden`,display:`flex`,flexDirection:`column`},children:(0,$.jsx)(Qe,{url:G,children:(0,$.jsx)(xa,{children:(0,$.jsxs)(rK,{children:[(0,$.jsx)(GJ,{}),(0,$.jsx)(mt,{isolated:e,children:(0,$.jsxs)(AN,{initialMode:e?`agent`:void 0,persist:!e,children:[!e&&(0,$.jsx)(RZ,{}),(0,$.jsx)(vJ,{}),(0,$.jsx)(YB,{children:(0,$.jsx)(qX,{children:(0,$.jsx)(ne,{children:(0,$.jsx)(YP,{children:(0,$.jsx)(NZ,{children:(0,$.jsx)(PZ,{children:(0,$.jsx)(FZ,{children:(0,$.jsx)(xn,{children:(0,$.jsx)(sO,{children:(0,$.jsx)(Si,{secondary:e,children:(0,$.jsx)(rP,{children:(0,$.jsx)(CO,{children:(0,$.jsx)(Ae,{children:(0,$.jsxs)(Se,{children:[(0,$.jsx)(sP,{}),(0,$.jsx)(zc,{}),e?(0,$.jsx)(VF,{}):(0,$.jsx)(MZ,{}),(0,$.jsx)(iZ,{}),(0,$.jsx)(LZ,{})]})})})})})})})})})})})})})})]})})]})})})})})}async function BZ(){await $e(),nt(),await qe(),(0,zr.createRoot)(document.getElementById(`root`)).render((0,$.jsx)(Q.StrictMode,{children:(0,$.jsx)(v,{children:(0,$.jsx)(zZ,{})})}));let e=document.getElementById(`specrails-splash`);e&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.classList.add(`is-hidden`),setTimeout(()=>e.remove(),300)})})}BZ();export{Pb as $,OI as A,Ss as At,pA as B,Go as Bt,xz as C,Us as Ct,kL as D,Ms as Dt,jR as E,Fs as Et,QA as F,$o as Ft,yD as G,No as Gt,nk as H,Vo as Ht,YA as I,Qo as It,rS as J,Ci as Jt,ND as K,co as Kt,fA as L,Zo as Lt,pI as M,vs as Mt,aP as N,ls as Nt,PL as O,Es as Ot,Jj as P,ns as Pt,Rb as Q,mA as R,Xo as Rt,QR as S,Ks as St,az as T,Is as Tt,lO as U,Bo as Ut,rk as V,Uo as Vt,vD as W,Lo as Wt,Yx as X,sS as Y,Jx as Z,sU as _,cc as _t,zG as a,Fc as at,Tz as b,Js as bt,UW as c,kc as ct,ZU as d,Cc as dt,Gy as et,NU as f,Sc as ft,cU as g,uc as gt,lU as h,mc as ht,KG as i,Lc as it,kI as j,xs as jt,RI as k,Ts as kt,BW as l,Ec as lt,GU as m,hc as mt,qG as n,Iy as nt,WG as o,Pc as ot,KU as p,bc as pt,uS as q,wa as qt,BG as r,Wy as rt,NG as s,Ac as st,tZ as t,Fy as tt,mW as u,wc as ut,ZH as v,oc as vt,_z as w,Rs as wt,lz as x,qs as xt,IV as y,Ys as yt,dA as z,Ko as zt};
|
|
80
|
+
`;function GX(e){return`contract-refine:${e}`}async function KX(e,t){try{let n=await fetch(`${Xe}/api/projects/${e}/tickets/${t}/contract-refine`,{method:`POST`});if(n.ok)J.loading(Je.t(`activity:contractRefine.refining`),{id:GX(t)});else{let e=await n.json().catch(()=>({}));J.error(e.error?Je.t(`activity:contractRefine.retryRejectedWithError`,{error:e.error}):Je.t(`activity:contractRefine.retryRejected`),{id:GX(t)})}}catch(e){J.error(Je.t(`activity:contractRefine.retryFailed`,{message:e.message}),{id:GX(t)})}}function qX({children:e}){let{registerHandler:t,unregisterHandler:n}=tt(),r=(0,Q.useRef)(new Map),i=(0,Q.useCallback)(e=>{let t=e;if(!t||t.type!==`explore.contract_refine_failed`)return;let n=t.ticketId,i=t.projectId,a=typeof t.provider==`string`?t.provider:void 0,o=t.reason??`unknown`;if(typeof n!=`number`||!i)return;r.current.set(n,i);let s=Tt(a)?{label:Je.t(`common:actions.retry`),onClick:()=>void KX(i,n)}:void 0;J.error(Je.t(`activity:contractRefine.skipped`),{id:GX(n),description:Je.t(`activity:contractRefine.reason`,{reason:o}),...s?{action:s}:{},duration:15e3})},[]),a=(0,Q.useCallback)(e=>{let t=e;if(!t||t.type!==`ticket_updated`)return;let n=t.ticket;n&&typeof n.description==`string`&&n.description.includes(WX)&&J.success(Je.t(`activity:contractRefine.added`,{title:n.title||`#${n.id}`}),{id:GX(n.id),duration:3500})},[]);return(0,Q.useLayoutEffect)(()=>(t(`_contract_refine_failed`,i),t(`_contract_refine_ticket_updated`,a),()=>{n(`_contract_refine_failed`),n(`_contract_refine_ticket_updated`)}),[t,n,i,a]),(0,Q.useEffect)(()=>()=>r.current.clear(),[]),(0,$.jsx)($.Fragment,{children:e})}function JX(){return typeof window<`u`&&`__TAURI_INTERNALS__`in window}function YX(){let{t:e}=K(`mcp`),t=iK()?.languageId;(0,Q.useEffect)(()=>{JX()&&Y(`set_tray_labels`,{open:e(`tray.open`),exit:e(`tray.exit`)}).catch(()=>{})},[e,t])}var XX=`input, textarea, select, [contenteditable="true"], [contenteditable=""], .monaco-editor, .xterm, [data-native-menu]`;function ZX(e){return e instanceof Element&&e.closest(XX)!==null}function QX(e){ZX(e.target)||e.preventDefault()}function $X(){(0,Q.useEffect)(()=>(document.addEventListener(`contextmenu`,QX),()=>document.removeEventListener(`contextmenu`,QX)),[])}var eZ={jobs:[],activeJobId:null,paused:!1};function tZ(e){let[t,n]=(0,Q.useState)([]),[r,i]=(0,Q.useState)({}),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)([]),[l,u]=(0,Q.useState)([]),[d,f]=(0,Q.useState)(eZ),[p,m]=(0,Q.useState)(0),h=(0,Q.useRef)(e);h.current=e;let g=(0,Q.useRef)(new Map),_=(0,Q.useRef)(void 0);(0,Q.useEffect)(()=>{if(_.current&&_.current,_.current=e,e){let t=g.current.get(e);t?(n(t.phaseDefinitions),i(t.phases),o(t.projectName),u(t.recentJobs),f(t.queueState)):(n([]),i({}),o(``),u([]),f(eZ))}c([])},[e]);let v=(0,Q.useCallback)(e=>{let t=e;if(!t||typeof t.type!=`string`)return;let r=h.current;if(!(r&&t.projectId&&t.projectId!==r))if(t.type===`desktop.project_recovered`)t.projectId===r&&m(e=>e+1);else if(t.type===`init`){let e=t.projectName??``,a=t.phaseDefinitions??[],s={};for(let e of a)s[e.key]=t.phases?.[e.key]??`idle`;let l=t.recentJobs??[],d=t.queue??eZ;o(e),n(a),i(s),c(t.logBuffer??[]),u(l),f(d),r&&g.current.set(r,{phaseDefinitions:a,phases:s,projectName:e,recentJobs:l,queueState:d})}else t.type===`phase`?i(e=>({...e,[t.phase]:t.state})):t.type===`log`?c(e=>[...e,{source:t.source,line:t.line,timestamp:t.timestamp,processId:t.processId}]):t.type===`queue`&&f({jobs:t.jobs??[],activeJobId:t.activeJobId??null,paused:t.paused??!1})},[]),{registerHandler:y,unregisterHandler:b,connectionStatus:x}=tt();return(0,Q.useLayoutEffect)(()=>(y(`pipeline`,v),()=>b(`pipeline`)),[v,y,b]),(0,Q.useEffect)(()=>{if(!e)return;let t=!1;async function r(){try{let e=await fetch(`${ut()}/state`);if(t||!e.ok)return;let r=await e.json();if(t)return;if(r.projectName&&o(r.projectName),r.phaseDefinitions){n(r.phaseDefinitions);let e={};for(let t of r.phaseDefinitions)e[t.key]=r.phases?.[t.key]??`idle`;i(e)}r.recentJobs&&u(r.recentJobs),r.queue&&f(r.queue)}catch{}}return r(),()=>{t=!0}},[e,p]),{phases:r,phaseDefinitions:t,projectName:a,logLines:s,connectionStatus:x,recentJobs:l,queueState:d}}function nZ({connectionStatus:e,rightSlot:t,minimal:n=!1}){let{t:r}=K(`nav`),{t:i}=K(`analytics`),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!1),l=(0,Q.useRef)(`connecting`),u=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>{let t=l.current;if(e===`connected`&&!u.current&&t!==`connected`){J.success(r(`statusBar.connectionRestored`)),c(!0);let e=setTimeout(()=>c(!1),2e3);return()=>clearTimeout(e)}u.current&&e===`connected`&&(u.current=!1),l.current=e},[e]),(0,Q.useEffect)(()=>{u.current&&=!1},[]),(0,Q.useEffect)(()=>{if(n)return;async function e(){try{let e=await fetch(`${ut()}/stats`);if(e.ok){let t=await e.json();o(t)}}catch{}}e();let t=setInterval(e,3e4);return()=>clearInterval(t)},[e,n]);let d=!n||e!==`connected`||s;return(0,$.jsxs)(`footer`,{className:`h-7 flex items-center justify-between px-4 border-t border-border/30 bg-background/80 backdrop-blur-sm text-[10px] text-muted-foreground`,children:[(0,$.jsxs)(`div`,{className:X(`flex items-center gap-1.5 transition-opacity duration-300`,!d&&`opacity-0`),"aria-hidden":!d||void 0,children:[(0,$.jsx)(`span`,{className:X(`w-1.5 h-1.5 rounded-full transition-colors`,e===`connected`&&!s&&`bg-accent-success`,e===`connected`&&s&&`bg-accent-info animate-pulse`,e===`connecting`&&`bg-accent-warning animate-[pulse_0.75s_ease-in-out_infinite]`,e===`disconnected`&&`bg-destructive`)}),(0,$.jsxs)(`span`,{className:X(`transition-colors`,e===`connected`&&!s&&`text-accent-success`,e===`connected`&&s&&`text-accent-info`,e===`connecting`&&`text-accent-warning`,e===`disconnected`&&`text-destructive`),children:[e===`connected`&&!s&&r(`statusBar.connected`),e===`connected`&&s&&r(`statusBar.syncing`),e===`connecting`&&r(`statusBar.reconnecting`),e===`disconnected`&&r(`statusBar.disconnected`)]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!n&&a&&(a.totalCostUsd>0||(a.unpricedRuns??0)>0)&&(()=>{let e=a.includesEstimated??((a.estimatedCostUsd??0)>0||(a.estimatedCostToday??0)>0),t=a.unpricedRuns??0,n=a.pricedRuns??Math.max(0,(a.totalJobs??0)-t),r=a.totalCostUsd===0&&t>0&&n===0,o=t>0&&(n>0||a.totalCostUsd>0);return(0,$.jsx)(`span`,{"data-estimated":e?`true`:void 0,"data-testid":r?`statusbar-cost-unavailable`:void 0,title:r?i(`desktop.costUnavailable`):o?i(`desktop.costPartiallyUnavailable`,{count:t}):e?i(`desktop.statusBarEstimatedTooltip`):void 0,children:r?i(`desktop.costUnavailableShort`):`${e?`~`:``}${o?`≥`:``}$${a.totalCostUsd.toFixed(2)}`})})(),t]})]})}var rZ=(0,Q.lazy)(()=>c(()=>import(`./AgentBrowserCapture-UcsupCy7.js`).then(e=>({default:e.AgentBrowserCapture})),__vite__mapDeps([89,1,7,9,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76])));function iZ(){let{browserOpen:e}=lO(),{active:t}=aP(),n=Ci(),r=!n.current&&n.transfers.some(e=>e.conversationId===t?.id&&e.state===`detached`),{activeProjectId:i}=pt();return!e||!i||r?null:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(rZ,{projectId:i,conversationId:t?.id??null})})}function aZ(){let{state:e,openTicketDetail:t,enterSplit:n,setComparedTicket:r}=be(),{tickets:i}=k(),a=p(),o=y(),s=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{if(s.current||i.length===0||new URLSearchParams(a.search).get(`compare`)&&typeof window<`u`&&window.innerWidth<900)return;s.current=!0;let e=new URLSearchParams(a.search),c=e.get(`compare`),l=e.get(`compareSide`);if(!c)return;let u=Number.parseInt(c,10),d=l===`right`?`right`:`left`;if(!i.some(e=>e.id===u)){let e=new URLSearchParams(a.search);e.delete(`compare`),e.delete(`compareSide`);let t=e.toString();o({pathname:a.pathname,search:t?`?${t}`:``},{replace:!0});return}let f=e.get(`compareOrigin`);if(f){let e=Number.parseInt(f,10);if(i.some(t=>t.id===e)){t(e),n(d),r(u,d===`left`?`right`:`left`);return}}t(u)},[i,a.search,a.pathname,o,t,n,r]),(0,Q.useEffect)(()=>{if(!s.current)return;let t=new URLSearchParams(a.search),n=t.has(`compare`);if(e.originSide===null){if(n){t.delete(`compare`),t.delete(`compareSide`),t.delete(`compareOrigin`);let e=t.toString();o({pathname:a.pathname,search:e?`?${e}`:``},{replace:!0})}return}let r=e.originSide===`left`?e.leftId:e.rightId,i=e.originSide===`left`?e.rightId:e.leftId;if(r==null||e.originSide==null)return;let c=new URLSearchParams(a.search);c.set(`compareSide`,e.originSide),c.set(`compareOrigin`,String(r)),i==null?c.delete(`compare`):c.set(`compare`,String(i));let l=c.toString();l!==(a.search.startsWith(`?`)?a.search.slice(1):a.search)&&o({pathname:a.pathname,search:l?`?${l}`:``},{replace:!0})},[e,a.search,a.pathname,o])}function oZ(e){let{key:t,detail:n}=nn(e);return[`chunk_failed`,`chunk_stalled`,`chunk_stopped`,`provider_limit`,`launch_rejected`,`head_missing`,`head_discarded`,`run_lost`].includes(t)?Je.t(`builder:milestoneProgress.chain.reasons.${t}`,{detail:n}):e??``}function sZ({setActiveProjectId:e}={}){let t=y(),n=(0,Q.useRef)(t);(0,Q.useEffect)(()=>{n.current=t},[t]);let r=(0,Q.useRef)(e);(0,Q.useEffect)(()=>{r.current=e},[e]);let i=(0,Q.useRef)(new Map),a=(0,Q.useRef)(new Map),{registerHandler:o,unregisterHandler:s}=tt();(0,Q.useEffect)(()=>{let e=`milestone-notifications`;return o(e,e=>{let t=e;if(!t||typeof t.projectId!=`string`)return;let o=t.projectId;if(t.type===`milestone.chain_changed`){let e=Ut(t.chain);if(!e)return;let n=i.current.get(e.id);i.current.set(e.id,e);let r=Gt(e.milestoneN);if(e.status===`running`&&e.nextChunk>1&&(!n||n.nextChunk<e.nextChunk)&&J.success(Je.t(`builder:milestoneProgress.toast.chunkLaunched`,{milestone:r,k:e.nextChunk,n:e.totalChunks}),{id:`chain-launch:${e.id}:${e.nextChunk}`}),e.status===`awaiting_approval`&&(!n||n.status!==`awaiting_approval`||n.nextChunk!==e.nextChunk)){let t=`chain-checkpoint:${e.id}:${e.nextChunk}`;J.success(Je.t(`builder:milestoneProgress.toast.checkpoint`,{milestone:r,k:e.nextChunk,n:e.totalChunks}),{id:t,duration:6e4,action:{label:Je.t(`builder:milestoneProgress.toast.launchNext`),onClick:()=>{wM(o,e.id).then(e=>{e.ok?J.success(Je.t(`builder:milestoneProgress.chain.nextLaunched`),{id:t}):J.error(Je.t(`builder:milestoneProgress.chain.resumeFailed`),{id:t,description:e.detail??e.error})})}},cancel:{label:Je.t(`builder:milestoneProgress.toast.autoContinue`),onClick:()=>{EM(o,e.id,!0).then(e=>{e.ok?J.success(Je.t(`builder:milestoneProgress.chain.autoOn`),{id:t}):J.error(Je.t(`builder:milestoneProgress.chain.autoFailed`),{id:t,description:e.detail??e.error})})}}})}e.status===`paused`&&(!n||n.status!==`paused`||n.pauseReason!==e.pauseReason)&&J.warning(Je.t(`builder:milestoneProgress.toast.paused`,{milestone:r,reason:oZ(e.pauseReason)}),{id:`chain-paused:${e.id}`,duration:3e4,action:{label:Je.t(`builder:milestoneProgress.toast.resume`),onClick:()=>{wM(o,e.id).then(t=>{t.ok?J.success(Je.t(`builder:milestoneProgress.chain.resumed`),{id:`chain-paused:${e.id}`}):J.error(Je.t(`builder:milestoneProgress.chain.resumeFailed`),{id:`chain-paused:${e.id}`,description:t.detail??t.error})})}}});return}if(t.type===`blueprint.milestone_progress`){for(let e of Xt(t.progress)){let t=`${o}:${e.id}`,i=a.current.get(t);if(a.current.set(t,e.state),!(i===void 0||i===e.state)&&e.state===`delivered`){let i=Zt(e);J.success(Je.t(`builder:milestoneProgress.toast.delivered`,{milestone:Gt(e.n),count:e.counts.onReview}),{id:`milestone-delivered:${t}`,duration:3e4,...i?{action:{label:Je.t(`builder:milestoneProgress.toast.review`),onClick:()=>{r.current?.(o);let e=le?`/review/${i.id}`:`/`;setTimeout(()=>{n.current(e)},50)}}}:{}})}}return}t.type===`blueprint.milestone_completed`&&typeof t.n==`number`&&J.success(Je.t(`builder:milestoneProgress.toast.completed`,{milestone:Gt(t.n)}),{id:`milestone-completed:${o}:${t.milestoneId??t.n}`,duration:15e3})}),()=>s(e)},[o,s])}function cZ(e){return e.startsWith(`/loops`)?`loops`:e.startsWith(`/plugins`)?`plugins`:lZ(e)?`review`:null}function lZ(e){let t=/^\/review\/([^/]+)\/?$/.exec(e);return t?decodeURIComponent(t[1]):null}function uZ(e){let t=/^\/loops\/([^/]+)\/edit\/?$/.exec(e);return t?decodeURIComponent(t[1]):null}function dZ({uiMode:e,pathname:t,loopsOpen:n,pluginsOpen:r,reviewOpen:i=null}){if(e===`agent`){let e=cZ(t);if(!e)return null;if(e===`review`)return{kind:`modalize`,surface:e,backgroundPath:`/`,reviewDeliveryId:lZ(t)??void 0};let n=e===`loops`?uZ(t):null;return n?{kind:`modalize`,surface:e,backgroundPath:`/`,loopBuilderId:n}:{kind:`modalize`,surface:e,backgroundPath:`/`}}return n?{kind:`route`,surface:`loops`,path:`/loops`}:r?{kind:`route`,surface:`plugins`,path:`/plugins`}:i?{kind:`route`,surface:`review`,path:`/review/${encodeURIComponent(i)}`}:null}var fZ=(0,Q.lazy)(()=>c(()=>import(`./JobDetailPage-CraDKzeG.js`),__vite__mapDeps([90,1,7,11,10,9,8,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,85]))),pZ=(0,Q.lazy)(()=>c(()=>import(`./ReviewPacketPage-D-UjTef3.js`),__vite__mapDeps([91,1,7,11,10,9,8,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,92]))),mZ=(0,Q.lazy)(()=>c(()=>import(`./JobsPage-CcbuSwj7.js`),__vite__mapDeps([93,1,7,11,10,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,45,8,53,64,65,51,67,68,69,70,71,72,73,80,85,94,54]))),hZ=(0,Q.lazy)(()=>c(()=>import(`./AnalyticsPage-DP3jakv-.js`),__vite__mapDeps([95,1,7,11,10,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,8,46,48,69,71,72,94,54,96,97]))),gZ=(0,Q.lazy)(()=>c(()=>import(`./ActivityFeedPage-ILXMZXcb.js`),__vite__mapDeps([98,1,7,12,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,45,8,52,53,58]))),_Z=(0,Q.lazy)(()=>c(()=>import(`./AgentsPage-BWvgxaBv.js`),__vite__mapDeps([99,1,7,8,12,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,49,11,50,51,55,58,59,61,63,64,65,67,68,69,73,85]))),vZ=(0,Q.lazy)(()=>c(()=>import(`./CodePage-BKXiwE5a.js`),__vite__mapDeps([100,1,7,8,10,11,9,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76]))),yZ=(0,Q.lazy)(()=>c(()=>import(`./IntegrationsPage-Bhy58lnQ.js`),__vite__mapDeps([101,7,1,11,10]))),bZ=(0,Q.lazy)(()=>c(()=>import(`./PluginsPage-BVqSsPzL.js`),__vite__mapDeps([102,1,7,12,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,45,8,46,54,58,63,64,65,66,67,51,68,69,73,74]))),xZ=(0,Q.lazy)(()=>c(()=>import(`./DesktopAnalyticsPage-DryJOaMz.js`),__vite__mapDeps([103,1,7,12,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,69,68,96,8,97]))),SZ=(0,Q.lazy)(()=>c(()=>import(`./DocsPage-Cc-GeKYl.js`),__vite__mapDeps([104,1,7,11,10,43,55,58,68,69,70,79,105,106]))),CZ=(0,Q.lazy)(()=>c(()=>import(`./DocsDialog-BsCG9ksG.js`),__vite__mapDeps([107,1,7,43,55,58,67,8,51,68,69,70,79,105,106]))),wZ=(0,Q.lazy)(()=>c(()=>import(`./LoopsPage-DEg6sIkG.js`),__vite__mapDeps([108,1,7,11,10,43,45,8,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,46,54,59,60,61,50,64,109,67,51,68,69,73,75,76,82,56]))),TZ=(0,Q.lazy)(()=>c(()=>import(`./LoopBuilderPage-BKtNp494.js`),__vite__mapDeps([110,1,7,8,11,10,43,45,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,47,56,60,61,62,64,65,109,67,51,68,69,73,76,97,111]))),EZ=28;function DZ({surface:e,onClose:t}){let{t:n}=K(`nav`),r=n(e===`loops`?`arcSidebar.loops`:e===`review`?`arcSidebar.review`:`arcSidebar.plugins`);return(0,$.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center justify-between gap-3 border-b border-border bg-popover/95 px-3`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`grid h-7 w-7 shrink-0 place-items-center rounded-md border border-accent-primary/20 bg-accent-primary/10 text-accent-primary`,children:(0,$.jsx)(e===`loops`?Lc:e===`review`?vs:uc,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:`truncate text-xs font-medium text-foreground`,children:r})]}),(0,$.jsx)(`div`,{className:`flex shrink-0 items-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:t,className:`grid h-7 w-7 place-items-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-popover`,"aria-label":n(`common:actions.close`),children:(0,$.jsx)(Vn,{className:`h-4 w-4`})})})]})}var OZ=new Set([`/settings`,`/loops`,`/plugins`]);function kZ(e){return OZ.has(e)||e.startsWith(`/loops`)||e.startsWith(`/plugins`)||e.startsWith(`/docs`)}var AZ=`specrails-desktop:routeMemory`;try{localStorage.removeItem(AZ)}catch{}function jZ(e){let t=p(),n=y(),r=(0,Q.useRef)(new Map),i=(0,Q.useRef)(null),a=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{ej((e,t)=>{r.current.set(e,t)})},[]),(0,Q.useEffect)(()=>{a.current||(a.current=!0,t.pathname!==`/`&&n(`/`,{replace:!0}))},[]),(0,Q.useEffect)(()=>{if(i.current&&i.current!==e&&!kZ(t.pathname)&&r.current.set(i.current,t.pathname),e&&e!==i.current){let i=r.current.get(e),a=i&&!kZ(i)?i:`/`;t.pathname!==a&&n(a,{replace:!0})}i.current=e},[e,t.pathname,n]),(0,Q.useEffect)(()=>{e&&t.pathname!==`/`&&!kZ(t.pathname)&&r.current.set(e,t.pathname)},[e,t.pathname])}function MZ(){let{t:e}=K(`common`),{projects:t,activeProjectId:n,isLoading:r,isSwitchingProject:i,setActiveProjectId:a}=pt(),{cycleLeftMode:o,cycleRightMode:s}=XP(),c=y(),l=p(),u=za(),d=aP(),{startNewConversation:m}=d,{uiMode:g}=MN();aZ();let[v,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(`appearance`),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(!1),[k,A]=(0,Q.useState)(null),[j,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(null),[F,I]=(0,Q.useState)(!1),L=(0,Q.useCallback)(()=>I(!1),[]),[R,z]=(0,Q.useState)(()=>!QJ());jZ(n),YX();let{cheatsheetOpen:B,setCheatsheetOpen:V,openCheatsheet:H}=cJ(),U=[`/`,`/jobs`,`/analytics`,...je?[`/agents`]:[],...me?[`/code`]:[],`/integrations`,`/settings`];sJ({onOpenCheatsheet:H,onToggleLeftSidebar:o,onToggleRightSidebar:s,onSwitchProject:e=>{let n=t[e-1];n&&a(n.id)},onSwitchProjectPage:e=>{let t=U[e-1];t&&c(t)},onToggleTerminalPanel:Te?()=>{n&&(u.togglePanel(n),u.getState(n).visibility===`hidden`?queueMicrotask(()=>u.focusActive(n)):u.focusActive(n))}:void 0,onToggleAgentChat:xe&&g!==`agent`?()=>d.toggle():void 0}),Qq({setActiveProjectId:a,projectsById:(0,Q.useMemo)(()=>new Map(t.map(e=>[e.id,e.name])),[t])}),sZ({setActiveProjectId:a}),(0,Q.useEffect)(()=>{vM()},[]);let W=t.find(e=>e.id===n),ee=l.pathname.startsWith(`/loops`),te=l.pathname.startsWith(`/plugins`),ne=l.pathname.startsWith(`/docs`)||g!==`agent`&&(ee||te);(0,Q.useLayoutEffect)(()=>{let e=dZ({uiMode:g,pathname:l.pathname,loopsOpen:D,pluginsOpen:j,reviewOpen:N});if(e){if(e.kind===`modalize`){if(e.surface===`review`){e.reviewDeliveryId&&P(e.reviewDeliveryId),l.pathname!==e.backgroundPath&&c(e.backgroundPath,{replace:!0});return}e.surface===`loops`?(M(!1),O(!0),e.loopBuilderId&&A(e.loopBuilderId)):(O(!1),M(!0)),m(n),l.pathname!==e.backgroundPath&&c(e.backgroundPath,{replace:!0});return}O(!1),M(!1),P(null),l.pathname!==e.path&&c(e.path,{replace:!0})}},[n,l.pathname,D,c,j,N,m,g]);let{connectionStatus:re}=tZ(),ie=Ba(n),ae=g===`agent`?0:EZ,oe=(0,Q.useRef)(null),[se,ce]=(0,Q.useState)(typeof window<`u`?window.innerHeight:820);(0,Q.useLayoutEffect)(()=>{if(!Te)return;let e=oe.current;if(!e)return;let t=()=>ce(e.clientHeight);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[r]),(0,Q.useEffect)(()=>{!Te||!n||u.ensureProject(n)},[n,u]);let ue=Te&&g===`kanban`&&ie.visibility===`hidden`?(0,$.jsx)(yF,{isOpen:!1,onClick:()=>n&&u.setVisibility(n,`restored`)}):null;return r?(0,$.jsxs)(`div`,{className:`flex h-full`,children:[(0,$.jsx)(`div`,{className:`w-11 border-r border-border bg-card/50 animate-pulse flex-shrink-0`}),(0,$.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`states.loading`)})})]}):(0,$.jsxs)(`div`,{className:`flex h-full overflow-hidden font-sans`,children:[(0,$.jsx)(TY,{onOpenCompanion:()=>{S(`mobile`),w(!0)},onAddProject:()=>b(!0),onOpenLoops:()=>{g===`agent`?O(!0):c(`/loops`)},onOpenPlugins:()=>{g===`agent`?M(!0):c(`/plugins`)},onOpenAnalytics:()=>E(!0),onOpenDocs:()=>I(!0),onOpenSettings:()=>{S(`appearance`),w(!0)}}),(0,$.jsxs)(`div`,{ref:oe,className:`flex flex-col flex-1 overflow-hidden`,children:[i&&(0,$.jsx)(`div`,{className:`h-0.5 w-full bg-accent-primary/70 animate-pulse shrink-0`,"data-testid":`project-switching-bar`}),(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:g===`agent`&&!ne?(0,$.jsx)(IP,{}):(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`states.loading`)})}),children:(0,$.jsxs)(_,{children:[(0,$.jsx)(h,{path:`/docs`,element:(0,$.jsx)(SZ,{})}),(0,$.jsx)(h,{path:`/docs/:category/:slug`,element:(0,$.jsx)(SZ,{})}),ke&&(0,$.jsx)(h,{path:`/loops`,element:(0,$.jsx)(wZ,{})}),ke&&(0,$.jsx)(h,{path:`/loops/:id/edit`,element:(0,$.jsx)(TZ,{})}),(0,$.jsx)(h,{path:`/plugins`,element:(0,$.jsx)(bZ,{})}),t.length===0?(0,$.jsx)(h,{path:`*`,element:(0,$.jsx)(YJ,{onAddProject:()=>b(!0)})}):W?(0,$.jsxs)(h,{element:(0,$.jsx)(JJ,{projectName:W.name,children:(0,$.jsx)(KJ,{project:W})},W.id),children:[(0,$.jsx)(h,{path:`/`,element:(0,$.jsx)(MW,{})}),(0,$.jsx)(h,{path:`/jobs`,element:(0,$.jsx)(mZ,{})}),(0,$.jsx)(h,{path:`/jobs/:id`,element:(0,$.jsx)(fZ,{})}),le&&(0,$.jsx)(h,{path:`/review/:prDeliveryId`,element:(0,$.jsx)(pZ,{})}),(0,$.jsx)(h,{path:`/analytics`,element:(0,$.jsx)(hZ,{})}),(0,$.jsx)(h,{path:`/activity`,element:(0,$.jsx)(gZ,{})}),(0,$.jsx)(h,{path:`/agents`,element:(0,$.jsx)(_Z,{})}),(0,$.jsx)(h,{path:`/code`,element:me?(0,$.jsx)(vZ,{}):(0,$.jsx)(f,{to:`/`,replace:!0})}),(0,$.jsx)(h,{path:`/integrations`,element:(0,$.jsx)(yZ,{})}),(0,$.jsx)(h,{path:`/settings`,element:(0,$.jsx)(JG,{})}),(0,$.jsx)(h,{path:`*`,element:(0,$.jsx)(f,{to:`/`,replace:!0})})]}):(0,$.jsx)(h,{path:`*`,element:(0,$.jsx)(YJ,{onAddProject:()=>b(!0)})})]})})}),Te&&n&&W&&(0,$.jsx)(BF,{projectId:n,provider:W.provider,providers:dt(W),state:ie,viewportHeight:se,statusBarHeight:ae}),g!==`agent`&&(0,$.jsx)(nZ,{connectionStatus:re,rightSlot:ue})]}),g===`agent`?!ne&&(0,$.jsx)(eF,{}):W&&!ne&&(0,$.jsx)(DY,{}),(0,$.jsx)(RY,{open:v,onClose:()=>b(!1),onOpenBuilder:()=>d.builderMode.enter()}),(0,$.jsx)(nJ,{initialSection:x,open:C,onClose:()=>w(!1),onOpenOnboarding:()=>{w(!1),z(!0)}}),(0,$.jsx)(mr,{open:T,onOpenChange:E,children:(0,$.jsx)(fr,{className:`max-w-5xl max-h-[90vh] overflow-hidden p-0 flex flex-col`,children:(0,$.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`flex items-center justify-center h-40`,children:(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`states.loading`)})}),children:(0,$.jsx)(xZ,{})})})})}),(0,$.jsx)(mr,{open:D,onOpenChange:e=>{O(e),e||A(null)},children:(0,$.jsxs)(fr,{showCloseButton:!1,className:`max-w-[96vw] w-[96vw] h-[92vh] max-h-[92vh] overflow-hidden p-0 flex flex-col`,children:[(0,$.jsx)(sr,{className:`sr-only`,children:e(`nav:arcSidebar.loops`)}),(0,$.jsx)(ir,{className:`sr-only`,children:e(`nav:globalSurfaceModal.loopsDescription`)}),(0,$.jsx)(DZ,{surface:`loops`,onClose:()=>{O(!1),A(null)}}),(0,$.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`flex items-center justify-center h-40`,children:(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`states.loading`)})}),children:k?(0,$.jsx)(`div`,{className:`h-full`,children:(0,$.jsx)(TZ,{loopId:k,onExit:()=>A(null)})}):(0,$.jsx)(wZ,{onOpenBuilder:A})})})]})}),le&&(0,$.jsx)(mr,{open:N!==null,onOpenChange:e=>{e||P(null)},children:(0,$.jsxs)(fr,{showCloseButton:!1,className:`max-w-[96vw] w-[96vw] h-[92vh] max-h-[92vh] overflow-hidden p-0 flex flex-col`,"data-testid":`review-packet-modal`,children:[(0,$.jsx)(sr,{className:`sr-only`,children:e(`nav:arcSidebar.review`)}),(0,$.jsx)(ir,{className:`sr-only`,children:e(`nav:globalSurfaceModal.reviewDescription`)}),(0,$.jsx)(DZ,{surface:`review`,onClose:()=>P(null)}),(0,$.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`flex items-center justify-center h-40`,children:(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`states.loading`)})}),children:N&&(0,$.jsx)(pZ,{prDeliveryId:N,onClose:()=>P(null)})})})]})}),(0,$.jsx)(mr,{open:j,onOpenChange:M,children:(0,$.jsxs)(fr,{showCloseButton:!1,className:`max-w-[96vw] w-[96vw] h-[92vh] max-h-[92vh] overflow-hidden p-0 flex flex-col`,children:[(0,$.jsx)(sr,{className:`sr-only`,children:e(`nav:arcSidebar.plugins`)}),(0,$.jsx)(ir,{className:`sr-only`,children:e(`nav:globalSurfaceModal.pluginsDescription`)}),(0,$.jsx)(DZ,{surface:`plugins`,onClose:()=>M(!1)}),(0,$.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`flex items-center justify-center h-40`,children:(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`states.loading`)})}),children:(0,$.jsx)(bZ,{})})})]})}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(CZ,{open:F,onClose:L})}),(0,$.jsx)(UX,{onOpenSettings:()=>{S(`appearance`),w(!0)},onOpenAnalytics:()=>E(!0),onOpenDocs:()=>I(!0)}),(0,$.jsx)(pJ,{open:B,onOpenChange:V}),(0,$.jsx)(pY,{open:R,onClose:()=>z(!1)})]})}function NZ({children:e}){let{activeProjectId:t}=pt();return(0,$.jsx)(La,{activeProjectId:t,children:e})}function PZ({children:e}){let{activeProjectId:t}=pt();return(0,$.jsx)(YU,{activeProjectId:t,children:e})}function FZ({children:e}){let{activeProjectId:t}=pt();return(0,$.jsx)(nW,{activeProjectId:t,children:e})}function IZ(){return(0,$.jsx)(`span`,{"aria-hidden":!0,style:{display:`none`}})}function LZ(){let{theme:e}=Sa(),t=e.previewSwatches.accents[0],n=e.status.completed,r=e.status.failed,i=e.status.canceled,a=e.status.running;return(0,Hb.createPortal)((0,$.jsx)(ft,{position:`bottom-right`,className:`specrails-toaster`,theme:e.scheme,gap:8,closeButton:!0,visibleToasts:6,icons:{loading:(0,$.jsx)(IZ,{})},style:{"--accent":t,"--toast-success-border":`color-mix(in srgb, ${n} 38%, transparent)`,"--toast-error-border":`color-mix(in srgb, ${r} 38%, transparent)`,"--toast-warning-border":`color-mix(in srgb, ${i} 38%, transparent)`,"--toast-info-border":`color-mix(in srgb, ${a} 38%, transparent)`},toastOptions:{unstyled:!0,classNames:{toast:`glass-card border border-border/30 text-foreground text-xs p-3 rounded-lg flex items-start gap-2 w-[356px] max-w-[356px] overflow-hidden shadow-lg`,content:`flex-1 min-w-0 flex flex-col gap-0.5`,icon:`shrink-0 mt-[2px] flex items-center justify-center`,title:`font-medium text-sm`,description:`text-muted-foreground mt-0.5`,actionButton:`text-[11px] px-2.5 py-1 rounded-md bg-accent-primary text-white hover:bg-accent-primary/90 whitespace-nowrap shrink-0 self-start`,cancelButton:`text-[11px] px-2.5 py-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent/50 whitespace-nowrap shrink-0 self-start`,closeButton:`text-muted-foreground hover:text-foreground rounded-md p-0.5`,success:`border-l-4 border-l-[var(--toast-success-border)]`,error:`border-l-4 border-l-[var(--toast-error-border)]`,warning:`border-l-4 border-l-[var(--toast-warning-border)]`,info:`border-l-4 border-l-[var(--toast-info-border)]`,loading:``}}}),document.body)}function RZ(){return $K(),null}function zZ(){let e=hi();return $X(),(0,$.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100vh`,overflow:`hidden`},children:(0,$.jsx)(`div`,{style:{flex:1,overflow:`hidden`,display:`flex`,flexDirection:`column`},children:(0,$.jsx)(Qe,{url:G,children:(0,$.jsx)(xa,{children:(0,$.jsxs)(rK,{children:[(0,$.jsx)(GJ,{}),(0,$.jsx)(mt,{isolated:e,children:(0,$.jsxs)(AN,{initialMode:e?`agent`:void 0,persist:!e,children:[!e&&(0,$.jsx)(RZ,{}),(0,$.jsx)(vJ,{}),(0,$.jsx)(YB,{children:(0,$.jsx)(qX,{children:(0,$.jsx)(ne,{children:(0,$.jsx)(YP,{children:(0,$.jsx)(NZ,{children:(0,$.jsx)(PZ,{children:(0,$.jsx)(FZ,{children:(0,$.jsx)(xn,{children:(0,$.jsx)(sO,{children:(0,$.jsx)(Si,{secondary:e,children:(0,$.jsx)(rP,{children:(0,$.jsx)(CO,{children:(0,$.jsx)(Ae,{children:(0,$.jsxs)(Se,{children:[(0,$.jsx)(sP,{}),(0,$.jsx)(zc,{}),e?(0,$.jsx)(VF,{}):(0,$.jsx)(MZ,{}),(0,$.jsx)(iZ,{}),(0,$.jsx)(LZ,{})]})})})})})})})})})})})})})})]})})]})})})})})}async function BZ(){await $e(),nt(),await qe(),(0,zr.createRoot)(document.getElementById(`root`)).render((0,$.jsx)(Q.StrictMode,{children:(0,$.jsx)(v,{children:(0,$.jsx)(zZ,{})})}));let e=document.getElementById(`specrails-splash`);e&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.classList.add(`is-hidden`),setTimeout(()=>e.remove(),300)})})}BZ();export{Pb as $,OI as A,Ss as At,pA as B,Go as Bt,xz as C,Us as Ct,kL as D,Ms as Dt,jR as E,Fs as Et,QA as F,$o as Ft,yD as G,No as Gt,nk as H,Vo as Ht,YA as I,Qo as It,rS as J,Ci as Jt,ND as K,co as Kt,fA as L,Zo as Lt,pI as M,vs as Mt,aP as N,ls as Nt,PL as O,Es as Ot,Jj as P,ns as Pt,Rb as Q,mA as R,Xo as Rt,QR as S,Ks as St,az as T,Is as Tt,lO as U,Bo as Ut,rk as V,Uo as Vt,vD as W,Lo as Wt,Yx as X,sS as Y,Jx as Z,sU as _,cc as _t,zG as a,Fc as at,Tz as b,Js as bt,UW as c,kc as ct,ZU as d,Cc as dt,Gy as et,NU as f,Sc as ft,cU as g,uc as gt,lU as h,mc as ht,KG as i,Lc as it,kI as j,xs as jt,RI as k,Ts as kt,BW as l,Ec as lt,GU as m,hc as mt,qG as n,Iy as nt,WG as o,Pc as ot,KU as p,bc as pt,uS as q,wa as qt,BG as r,Wy as rt,NG as s,Ac as st,tZ as t,Fy as tt,mW as u,wc as ut,ZH as v,oc as vt,_z as w,Rs as wt,lz as x,qs as xt,IV as y,Ys as yt,dA as z,Ko as zt};
|