specrails-desktop 2.49.1 → 2.49.2

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.
Files changed (26) hide show
  1. package/client/dist/assets/{ActivityFeedPage-FdZBSmTU.js → ActivityFeedPage-CyOxof-U.js} +1 -1
  2. package/client/dist/assets/{AgentBrowserCapture-Dr8kZotA.js → AgentBrowserCapture-DBGaKW4u.js} +1 -1
  3. package/client/dist/assets/{AgentModeAnalyticsPane-DXQSjYe-.js → AgentModeAnalyticsPane-WZpPaNMa.js} +2 -2
  4. package/client/dist/assets/{AgentModeCodePane-DcVV6EBy.js → AgentModeCodePane-nHYnJUdP.js} +2 -2
  5. package/client/dist/assets/{AgentModeJobsPane-a9f-g56c.js → AgentModeJobsPane-DkhcBtoZ.js} +1 -1
  6. package/client/dist/assets/{AgentsPage-CTv4UVdp.js → AgentsPage-CX90q-nY.js} +1 -1
  7. package/client/dist/assets/{AnalyticsPage-BbXPcz3a.js → AnalyticsPage-DisrtBr7.js} +1 -1
  8. package/client/dist/assets/{CodePage-CIigb_O0.js → CodePage-ixqxftCT.js} +1 -1
  9. package/client/dist/assets/{DesktopAnalyticsPage-DZhN5jVh.js → DesktopAnalyticsPage-BFB-Pn-D.js} +1 -1
  10. package/client/dist/assets/{DocsDialog-DzrqPxuj.js → DocsDialog-BwiFrwEJ.js} +1 -1
  11. package/client/dist/assets/{DocsPage-B1AUuk0U.js → DocsPage-ByS0ZCco.js} +1 -1
  12. package/client/dist/assets/{InteractiveJobComposer-jg3xE_GX.js → InteractiveJobComposer-BEok7ntM.js} +1 -1
  13. package/client/dist/assets/{JobDetailModal-BS-htwqZ.js → JobDetailModal-BnO_V8KR.js} +1 -1
  14. package/client/dist/assets/{JobDetailPage-CKYtQV5a.js → JobDetailPage-BnS8aHKD.js} +1 -1
  15. package/client/dist/assets/{JobsPage-DFJm0bw0.js → JobsPage-BC0mq-MF.js} +1 -1
  16. package/client/dist/assets/{LoopBuilderPage-ujkA2U0T.js → LoopBuilderPage-WmqNpDw2.js} +1 -1
  17. package/client/dist/assets/{LoopPreviewModal-BYOrnmcp.js → LoopPreviewModal-BY5dDezY.js} +1 -1
  18. package/client/dist/assets/{LoopsPage-DRcT1ikP.js → LoopsPage-BcegqJyY.js} +1 -1
  19. package/client/dist/assets/{PluginsPage-BR9ZTqxR.js → PluginsPage-BhG3qPda.js} +1 -1
  20. package/client/dist/assets/{ProjectSettingsDialog-SAfCqXzC.js → ProjectSettingsDialog-JQdLwCy2.js} +1 -1
  21. package/client/dist/assets/{ReviewPacketPage-BoqahYNC.js → ReviewPacketPage-DSSi3x16.js} +1 -1
  22. package/client/dist/assets/{TemplatePreviewModal-CK5OoImj.js → TemplatePreviewModal-1AVv-hu4.js} +1 -1
  23. package/client/dist/assets/{index-CjAPu3wb.js → index-DEqG4WdV.js} +7 -7
  24. package/client/dist/index.html +1 -1
  25. package/package.json +1 -1
  26. package/server/dist/local-engine-detection.js +4 -1
@@ -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-BS-htwqZ.js","assets/jsx-runtime-zu2_FqZY.js","assets/react-dom-DiWzBDP9.js","assets/TicketDetailModalContext-D2MEhRwJ.js","assets/preload-helper-Czpn1I53.js","assets/chunk-KS7C4IRE-DEKu087k.js","assets/useSharedWebSocket-BN3Lmehi.js","assets/activity-DiyjsgQV.js","assets/addspec-BOvgmcgk.js","assets/agent-BIO4q6b0.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-Ch-zHBG5.js","assets/packet-BTRySHoQ.js","assets/settings-HZSu-K4l.js","assets/setup-DpqzaEEA.js","assets/specs-DII0C8gw.js","assets/terminal-BAzpHtpY.js","assets/tickets-W6pBmbrX.js","assets/createLucideIcon-Bjbbp_KS.js","assets/Trans-BLljsfHR.js","assets/useDesktop-BJ8IRBRt.js","assets/provider-capabilities-Vi1ZGvAK.js","assets/save-B6wGWwBR.js","assets/spending-DJBbdJyD.js","assets/MinimizedChatsContext-CX1i2kQ8.js","assets/sparkles-DrY8hb0X.js","assets/x-CBMI9ejn.js","assets/circle-x-CMYsN4ZH.js","assets/download-CFHyyHcw.js","assets/file-text-CFT-xXKN.js","assets/git-branch-BRM0F5GN.js","assets/loader-circle-DcygOQpC.js","assets/pencil-C9RkrIPZ.js","assets/square-Ci-PFcFe.js","assets/plus-CsnjfkmX.js","assets/search-Cq_gE3Ik.js","assets/trash-2-BOU3WdZZ.js","assets/triangle-alert-H9T4jAmh.js","assets/wrench-BfmNO9Vw.js","assets/zap-CHo3aCD1.js","assets/dialog-xXB2q5HJ.js","assets/utils-BC4DHlz2.js","assets/clsx-CjueKrWZ.js","assets/lib-CGdyxIWg.js","assets/formatDistanceToNow-CbQZkD8M.js","assets/getTimezoneOffsetInMilliseconds-pBVK3rJC.js","assets/button-Ccc9Dc-D.js","assets/jira-api-f-sYCIuX.js","assets/RepositoryScopeSelector-DG8KKPrm.js","assets/project-repositories-DAjJbFhm.js","assets/InteractiveJobComposer-jg3xE_GX.js","assets/useRuntimeRuns-Ch1KUc7k.js","assets/lib-C7Mhm-gT.js","assets/job-time-BCL7wee9.js","assets/LoopPreviewModal-BYOrnmcp.js","assets/TemplatePreviewModal-CK5OoImj.js","assets/AgentModeCodePane-DcVV6EBy.js","assets/AgentModeJobsPane-a9f-g56c.js","assets/format-command-C0D9IPmV.js","assets/AgentModeAnalyticsPane-DXQSjYe-.js","assets/dist-js-CJ_2XX1Y.js","assets/ProjectSettingsDialog-SAfCqXzC.js","assets/AgentBrowserCapture-Dr8kZotA.js","assets/JobDetailPage-CKYtQV5a.js","assets/ReviewPacketPage-BoqahYNC.js","assets/RepositoryDeliveries-DqmlG0Zs.js","assets/JobsPage-DFJm0bw0.js","assets/ExportDropdown-IPutNYvD.js","assets/AnalyticsPage-BbXPcz3a.js","assets/BarChart-nBOMNfiy.js","assets/value-s-gzBeyF.js","assets/ActivityFeedPage-FdZBSmTU.js","assets/AgentsPage-CTv4UVdp.js","assets/CodePage-CIigb_O0.js","assets/IntegrationsPage-Bhy58lnQ.js","assets/PluginsPage-BR9ZTqxR.js","assets/DesktopAnalyticsPage-DZhN5jVh.js","assets/DocsPage-B1AUuk0U.js","assets/atom-one-dark-qiGhVQxg.js","assets/atom-one-dark-B-oHczHB.css","assets/DocsDialog-DzrqPxuj.js","assets/LoopsPage-DRcT1ikP.js","assets/upload-DYMjAQ6M.js","assets/LoopBuilderPage-ujkA2U0T.js","assets/LoopBuilderPage-DtxX27Jz.css"])))=>i.map(i=>d[i]);
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-BnO_V8KR.js","assets/jsx-runtime-zu2_FqZY.js","assets/react-dom-DiWzBDP9.js","assets/TicketDetailModalContext-D2MEhRwJ.js","assets/preload-helper-Czpn1I53.js","assets/chunk-KS7C4IRE-DEKu087k.js","assets/useSharedWebSocket-BN3Lmehi.js","assets/activity-DiyjsgQV.js","assets/addspec-BOvgmcgk.js","assets/agent-BIO4q6b0.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-Ch-zHBG5.js","assets/packet-BTRySHoQ.js","assets/settings-HZSu-K4l.js","assets/setup-DpqzaEEA.js","assets/specs-DII0C8gw.js","assets/terminal-BAzpHtpY.js","assets/tickets-W6pBmbrX.js","assets/createLucideIcon-Bjbbp_KS.js","assets/Trans-BLljsfHR.js","assets/useDesktop-BJ8IRBRt.js","assets/provider-capabilities-Vi1ZGvAK.js","assets/save-B6wGWwBR.js","assets/spending-DJBbdJyD.js","assets/MinimizedChatsContext-CX1i2kQ8.js","assets/sparkles-DrY8hb0X.js","assets/x-CBMI9ejn.js","assets/circle-x-CMYsN4ZH.js","assets/download-CFHyyHcw.js","assets/file-text-CFT-xXKN.js","assets/git-branch-BRM0F5GN.js","assets/loader-circle-DcygOQpC.js","assets/pencil-C9RkrIPZ.js","assets/square-Ci-PFcFe.js","assets/plus-CsnjfkmX.js","assets/search-Cq_gE3Ik.js","assets/trash-2-BOU3WdZZ.js","assets/triangle-alert-H9T4jAmh.js","assets/wrench-BfmNO9Vw.js","assets/zap-CHo3aCD1.js","assets/dialog-xXB2q5HJ.js","assets/utils-BC4DHlz2.js","assets/clsx-CjueKrWZ.js","assets/lib-CGdyxIWg.js","assets/formatDistanceToNow-CbQZkD8M.js","assets/getTimezoneOffsetInMilliseconds-pBVK3rJC.js","assets/button-Ccc9Dc-D.js","assets/jira-api-f-sYCIuX.js","assets/RepositoryScopeSelector-DG8KKPrm.js","assets/project-repositories-DAjJbFhm.js","assets/InteractiveJobComposer-BEok7ntM.js","assets/useRuntimeRuns-Ch1KUc7k.js","assets/lib-C7Mhm-gT.js","assets/job-time-BCL7wee9.js","assets/LoopPreviewModal-BY5dDezY.js","assets/TemplatePreviewModal-1AVv-hu4.js","assets/AgentModeCodePane-nHYnJUdP.js","assets/AgentModeJobsPane-DkhcBtoZ.js","assets/format-command-C0D9IPmV.js","assets/AgentModeAnalyticsPane-WZpPaNMa.js","assets/dist-js-CJ_2XX1Y.js","assets/ProjectSettingsDialog-JQdLwCy2.js","assets/AgentBrowserCapture-DBGaKW4u.js","assets/JobDetailPage-BnS8aHKD.js","assets/ReviewPacketPage-DSSi3x16.js","assets/RepositoryDeliveries-DqmlG0Zs.js","assets/JobsPage-BC0mq-MF.js","assets/ExportDropdown-IPutNYvD.js","assets/AnalyticsPage-DisrtBr7.js","assets/BarChart-nBOMNfiy.js","assets/value-s-gzBeyF.js","assets/ActivityFeedPage-CyOxof-U.js","assets/AgentsPage-CX90q-nY.js","assets/CodePage-ixqxftCT.js","assets/IntegrationsPage-Bhy58lnQ.js","assets/PluginsPage-BhG3qPda.js","assets/DesktopAnalyticsPage-BFB-Pn-D.js","assets/DocsPage-ByS0ZCco.js","assets/atom-one-dark-qiGhVQxg.js","assets/atom-one-dark-B-oHczHB.css","assets/DocsDialog-BwiFrwEJ.js","assets/LoopsPage-BcegqJyY.js","assets/upload-DYMjAQ6M.js","assets/LoopBuilderPage-WmqNpDw2.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,H as D,I as O,J as k,L as A,M as j,N as M,O as N,P,Q as F,R as I,S as L,T as ee,U as R,V as z,X as B,Y as V,Z as H,_ as U,a as te,at as ne,b as re,c as ie,ct as ae,dt as oe,et as se,ft as ce,g as le,h as ue,i as de,it as fe,j as pe,k as me,l as he,lt as W,mt as ge,n as _e,nt as ve,o as ye,p as be,pt as xe,q as Se,r as G,rt as Ce,s as we,st as Te,t as Ee,tt as De,ut as Oe,v as ke,w as Ae,x as je,y as Me,z as Ne}from"./TicketDetailModalContext-D2MEhRwJ.js";import{C as Pe,O as Fe,S as Ie,T as Le,_ as Re,a as ze,b as Be,d as Ve,f as He,g as Ue,h as We,i as Ge,l as Ke,m as qe,n as Je,o as Ye,p as Xe,r as Ze,s as Qe,t as $e,u as et,v as tt,w as nt,x as rt,y as it}from"./useSharedWebSocket-BN3Lmehi.js";import{t as at}from"./Trans-BLljsfHR.js";import{n as K,t as q}from"./createLucideIcon-Bjbbp_KS.js";import{a as ot,n as st,o as ct,r as lt,s as J,t as ut}from"./useDesktop-BJ8IRBRt.js";import{a as Y,n as dt,r as ft,t as pt}from"./core-B3mKBIh5.js";import{_ as mt,a as ht,d as gt,f as _t,g as vt,h as yt,i as bt,l as xt,m as St,n as Ct,o as wt,p as Tt,r as Et,s as Dt,t as Ot,u as kt}from"./provider-capabilities-Vi1ZGvAK.js";import{C as At,D as jt,E as Mt,O as Nt,S as Pt,T as Ft,_ as It,a as Lt,b as Rt,c as zt,d as Bt,f as Vt,g as Ht,h as Ut,i as Wt,k as Gt,l as Kt,m as qt,n as Jt,o as Yt,p as Xt,r as Zt,s as Qt,t as $t,u as en,v as tn,w as nn,x as rn,y as an}from"./RepositoryDeliveries-DqmlG0Zs.js";import{n as on,t as sn}from"./save-B6wGWwBR.js";import{a as cn,c as ln,d as un,i as dn,l as fn,n as pn,o as mn,r as hn,s as gn,t as _n,u as vn}from"./MinimizedChatsContext-CX1i2kQ8.js";import{t as yn}from"./circle-x-CMYsN4ZH.js";import{t as bn}from"./download-CFHyyHcw.js";import{t as xn}from"./file-text-CFT-xXKN.js";import{t as Sn}from"./git-branch-BRM0F5GN.js";import{t as Cn}from"./loader-circle-DcygOQpC.js";import{t as wn}from"./pencil-C9RkrIPZ.js";import{n as Tn,t as En}from"./square-Ci-PFcFe.js";import{t as Dn}from"./plus-CsnjfkmX.js";import{t as On}from"./search-Cq_gE3Ik.js";import{t as kn}from"./sparkles-DrY8hb0X.js";import{t as An}from"./trash-2-BOU3WdZZ.js";import{t as jn}from"./triangle-alert-H9T4jAmh.js";import{t as Mn}from"./wrench-BfmNO9Vw.js";import{t as Nn}from"./x-CBMI9ejn.js";import{t as Pn}from"./zap-CHo3aCD1.js";import{A as Fn,C as In,D as Ln,E as Rn,M as zn,O as Bn,S as Vn,T as Hn,_ as Un,a as Wn,b as Gn,c as Kn,d as qn,f as Jn,g as Yn,h as Xn,i as Zn,j as Qn,k as $n,l as er,m as tr,n as nr,o as rr,p as ir,r as ar,s as or,t as sr,u as cr,v as lr,w as ur,x as dr,y as fr}from"./dialog-xXB2q5HJ.js";import{t as X}from"./utils-BC4DHlz2.js";import{n as pr,t as mr}from"./lib-CGdyxIWg.js";import{t as hr}from"./getTimezoneOffsetInMilliseconds-pBVK3rJC.js";import{t as gr}from"./formatDistanceToNow-CbQZkD8M.js";import{n as _r,t as Z}from"./button-Ccc9Dc-D.js";import{n as vr,t as yr}from"./project-repositories-DAjJbFhm.js";import{t as br}from"./RepositoryScopeSelector-DG8KKPrm.js";import{n as xr,t as Sr}from"./useRuntimeRuns-Ch1KUc7k.js";import{a as Cr,n as wr,o as Tr,r as Er,t as Dr}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 Or=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}}}})),kr=i(((e,t)=>{t.exports=Or()})),Ar=i((e=>{var t=kr(),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},ee=[],R=-1;function z(e){return{current:e}}function B(e){0>R||(e.current=ee[R],ee[R]=null,R--)}function V(e,t){R++,ee[R]=e.current,e.current=t}var H=z(null),U=z(null),te=z(null),ne=z(null);function re(e,t){switch(V(te,t),V(U,e),V(H,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}}B(H),V(H,e)}function ie(){B(H),B(U),B(te)}function ae(e){e.memoizedState!==null&&V(ne,e);var t=H.current,n=Hd(t,e.type);t!==n&&(V(U,e),V(H,n))}function oe(e){U.current===e&&(B(H),B(U)),ne.current===e&&(B(ne),Qf._currentValue=L)}var se,ce;function le(e){if(se===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);se=t&&t[1]||``,ce=-1<e.stack.indexOf(`
3
3
  at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
4
4
  `+se+e+ce}var ue=!1;function de(e,t){if(!e||ue)return``;ue=!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(`
@@ -29,8 +29,8 @@ Error generating stack: `+e.message+`
29
29
 
30
30
  `).trim()}function ux(e,t=!1){if(!e.includes(ax))return{body:e,draft:null,pending:!1};let n=null,r=``,i=0;ix.lastIndex=0;let a;for(;(a=ix.exec(e))!==null;){r+=e.slice(i,a.index),i=a.index+a[0].length;let t=cx(a[1]);t&&(n=t)}r+=e.slice(i);let o=!1,s=r.indexOf(ax);if(s!==-1){let e=cx(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:lx(r),draft:n,pending:o}}var dx={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`},fx=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 px({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)(kn,{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`,dx[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:fx,children:(0,$.jsx)(pr,{remarkPlugins:[mr],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)(fn,{className:`h-3 w-3`}):(0,$.jsx)(Wo,{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)(qo,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-success/80`}),(0,$.jsx)(`span`,{children:e})]},`${t}-${e}`))})]})]})]})}function mx(){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)(kn,{className:`h-3 w-3 animate-pulse`}),e(`specDraft.drafting`)]})}var hx=[`implement`,`batch-implement`,`freestyle`,`loop`],gx=/```rail-launch[^\S\n]*\n([\s\S]*?)\n[^\S\n]*```/g,_x="```rail-launch",vx=160;function yx(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function bx(e,t=200){if(typeof e!=`string`)return null;let n=e.trim();return n?n.slice(0,t):null}function xx(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 Sx(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 Cx(e){let t=e.replace(/\s+/g,` `).trim();return t.length>vx?`${t.slice(0,vx-1)}…`:t}function wx(e){if(!yx(e))return{ok:!1,reason:`not_object`};let t=xx(e.version,1)??xx(e.blueprintVersion,1);if(t!==null&&t!==1)return{ok:!1,reason:`unsupported_version`};let n=Sx(e.ticketIds??e.specs??e.tickets);if(n.length===0)return{ok:!1,reason:`no_tickets`};let r=bx(e.mode)?.toLowerCase().replace(/_/g,`-`)??`implement`,i=r===`batch`?`batch-implement`:r;if(!hx.includes(i))return{ok:!1,reason:`invalid_mode`};let a=e.newRail,o=a===!0?{name:null}:yx(a)?{name:bx(a.name,80)}:null;return{ok:!0,proposal:{version:1,railIndex:o?null:xx(e.railIndex,0),newRail:o,ticketIds:n,mode:i,loopId:bx(e.loopId,120),aiEngine:bx(e.aiEngine??e.provider??e.engine,80),model:bx(e.model,120),reasoningEffort:bx(e.reasoningEffort??e.reasoning_effort??e.effort,20),profileName:bx(e.profileName??e.profile,80),targetPrNumber:xx(e.targetPrNumber,1),baseBranch:bx(e.baseBranch,200),railName:bx(e.railName??e.name,80),rationale:bx(e.rationale??e.reason??e.why,400)}}}function Tx(e){return e.replace(/\n{3,}/g,`
31
31
 
32
- `).trim()}function Ex(e,t=!1){let n={body:e??``,proposals:[],rejected:[],pending:!1,truncated:!1,repaired:!1};if(!e||!e.includes(_x))return n;let r=[],i=[],a=!1,o=``,s=0;gx.lastIndex=0;let c,l=e=>{let t=Pt(e);if(!t.ok){i.push({reason:`invalid_json`,excerpt:Cx(e)});return}t.repaired&&(a=!0);let n=wx(t.value);n.ok?r.push(n.proposal):i.push({reason:n.reason,excerpt:Cx(e)})};for(;(c=gx.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(_x);if(f!==-1){let e=o.slice(f+14).replace(/^[^\S\n]*\n?/,``).replace(/\s*(?:```)?\s*$/,``),n=e.trim()?Pt(e):null;if(n&&n.ok){n.repaired&&(a=!0);let t=wx(n.value);t.ok?r.push(t.proposal):i.push({reason:t.reason,excerpt:Cx(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:Cx(e)}))}return{body:Tx(o),proposals:r,rejected:i,pending:u,truncated:d,repaired:a}}var Dx=new Map,Ox=new Set;function kx(e,t){let n=new Map(Dx),r=n.get(e)??[];n.set(e,[...r.filter(e=>e.proposalIndex!==t.proposalIndex),t]),Dx=n;for(let e of Ox)e()}function Ax(e){return Ox.add(e),()=>{Ox.delete(e)}}function jx(){return(0,Q.useSyncExternalStore)(Ax,()=>Dx,()=>Dx)}function Mx(e,t,n,r){return e.get(t)?.find(e=>e.proposalIndex===r)??n?.find(e=>e.proposalIndex===r)??null}var Nx={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`}]},Px=new Map;function Fx(e,t){if(!e)return;let n=Array.from(new Set(t.filter(e=>typeof e==`string`&&e.trim())));if(n.length===0){Px.delete(e);return}Px.set(e,n.map(e=>({value:e,label:e})))}function Ix(e){return e?Nx[e]??Px.get(e)??[]:[]}function Lx(e){return Ix(e)[0]?.value??``}function Rx(e){for(let[t,n]of Object.entries(e))n?.kind===`local`&&Array.isArray(n.models)&&Fx(t,n.models)}function zx(){let[e,t]=(0,Q.useState)({detected:[],providers:{},loading:!0}),n=(0,Q.useContext)($e);return(0,Q.useEffect)(()=>{let e=!0;return fetch(`${Ke}/api/providers/detected`).then(e=>e.ok?e.json():null).then(n=>{!e||!n||(Rx(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`&&(Rx(n.providers??{}),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 Bx={implement:`factory:implement`,"batch-implement":`factory:batch`,freestyle:`factory:freestyle`},Vx=[{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 Hx(e){return e===`loop`?``:Bx[e]}function Ux(e){return e===`factory:implement`?`implement`:e===`factory:batch`?`batch-implement`:e===`factory:freestyle`?`freestyle`:`loop`}function Wx(e,t){return e||Hx(t)}var Gx=class extends Error{errors;constructor(e){super(`Loop graph is invalid`),this.name=`LoopPublishError`,this.errors=e}},Kx=`/api`;async function qx(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 Gx(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 Jx(e,t,n){return qx(await fetch(`${Kx}${t}`,{method:e,headers:n===void 0?void 0:{"Content-Type":`application/json`},body:n===void 0?void 0:JSON.stringify(n)}))}var Yx={async list(){return(await Jx(`GET`,`/loops`)).loops},async get(e){return(await Jx(`GET`,`/loops/${e}`)).loop},async create(e){return(await Jx(`POST`,`/loops`,e)).loop},async update(e,t){return(await Jx(`PUT`,`/loops/${e}`,t)).loop},async publish(e){return(await Jx(`POST`,`/loops/${e}/publish`)).loop},async unpublish(e){return(await Jx(`POST`,`/loops/${e}/unpublish`)).loop},async duplicate(e,t){return(await Jx(`POST`,`/loops/${e}/duplicate`,t?{name:t}:{})).loop},async remove(e){let t=await fetch(`${Kx}/loops/${e}`,{method:`DELETE`});!t.ok&&t.status!==204&&await qx(t)},async templates(){return(await Jx(`GET`,`/loop-templates`)).templates},async fromTemplate(e,t){return(await Jx(`POST`,`/loops/from-template/${e}`,t?{name:t}:{})).loop},async factoryLoops(){return(await Jx(`GET`,`/loops/factory`)).factoryLoops},async loopCommands(){return(await Jx(`GET`,`/loops/commands`)).commands},async forkFactory(e,t){return(await Jx(`POST`,`/loops/factory/${e}/fork`,t?{name:t}:{})).loop},async loopConstants(){return(await Jx(`GET`,`/loops/constants`)).constants},async createConstant(e,t){return(await Jx(`POST`,`/loops/constants`,{name:e,value:t})).constant},async updateConstant(e,t){return(await Jx(`PUT`,`/loops/constants/${e}`,{value:t})).constant},async deleteConstant(e){await Jx(`DELETE`,`/loops/constants/${e}`)},async importLoops(e){return Jx(`POST`,`/loops/import`,{loops:e})},async previewLoop(e,t){return Jx(`POST`,`/loops/preview`,{graph:e,provider:t})},async runStandalone(e,t,n={}){return qx(await fetch(`/api/projects/${e}/loop-runs`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({loopId:t,...n})}))}},Xx=/\{\{\s*spec\./,Zx=/\{\{\s*cmd:(implement|batch|freestyle)\b/;function Qx(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(Xx.test(e)||Zx.test(e))return!0}return!1}function $x(e,[t,n]){return Math.min(n,Math.max(t,e))}function eS(e){let t=tS(e),n=Q.forwardRef((e,n)=>{let{children:r,...i}=e,a=Q.Children.toArray(r),o=a.find(rS);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 tS(e){let t=Q.forwardRef((e,t)=>{let{children:n,...r}=e;if(Q.isValidElement(n)){let e=aS(n),i=iS(r,n.props);return n.type!==Q.Fragment&&(i.ref=t?$n(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 nS=Symbol(`radix.slottable`);function rS(e){return Q.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===nS}function iS(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 aS(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 oS(e){let t=e+`CollectionProvider`,[n,r]=Ln(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=eS(s),l=Q.forwardRef((e,t)=>{let{scope:n,children:r}=e,i=Fn(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=eS(u),p=Q.forwardRef((e,t)=>{let{scope:n,children:r,...i}=e,o=Q.useRef(null),s=Fn(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 sS=Q.createContext(void 0);function cS(e){let t=Q.useContext(sS);return e||t||`ltr`}var lS=[`top`,`right`,`bottom`,`left`],uS=Math.min,dS=Math.max,fS=Math.round,pS=Math.floor,mS=e=>({x:e,y:e}),hS={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function gS(e,t,n){return dS(e,uS(t,n))}function _S(e,t){return typeof e==`function`?e(t):e}function vS(e){return e.split(`-`)[0]}function yS(e){return e.split(`-`)[1]}function bS(e){return e===`x`?`y`:`x`}function xS(e){return e===`y`?`height`:`width`}function SS(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function CS(e){return bS(SS(e))}function wS(e,t,n){n===void 0&&(n=!1);let r=yS(e),i=CS(e),a=xS(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=NS(o)),[o,NS(o)]}function TS(e){let t=NS(e);return[ES(e),t,ES(t)]}function ES(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var DS=[`left`,`right`],OS=[`right`,`left`],kS=[`top`,`bottom`],AS=[`bottom`,`top`];function jS(e,t,n){switch(e){case`top`:case`bottom`:return n?t?OS:DS:t?DS:OS;case`left`:case`right`:return t?kS:AS;default:return[]}}function MS(e,t,n,r){let i=yS(e),a=jS(vS(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(ES)))),a}function NS(e){let t=vS(e);return hS[t]+e.slice(t.length)}function PS(e){return{top:0,right:0,bottom:0,left:0,...e}}function FS(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:PS(e)}function IS(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 LS(e,t,n){let{reference:r,floating:i}=e,a=SS(t),o=CS(t),s=xS(o),c=vS(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(yS(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 RS(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}=_S(t,e),p=FS(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=IS(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=IS(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,BS=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:RS},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=LS(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}=LS(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},VS=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}=_S(e,t)||{};if(l==null)return{};let d=FS(u),f={x:n,y:r},p=CS(i),m=xS(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=uS(d[_],T),D=uS(d[v],T),O=E,k=C-h[m]-D,A=C/2-h[m]/2+w,j=gS(O,A,k),M=!c.arrow&&yS(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}}}),HS=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}=_S(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=vS(r),_=SS(o),v=vS(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[NS(o)]:TS(o)),x=p!==`none`;!d&&x&&b.push(...MS(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=wS(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`&&_!==SS(t))||T.every(e=>SS(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=SS(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 US(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function WS(e){return lS.some(t=>e[t]>=0)}var GS=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=_S(e,t);switch(i){case`referenceHidden`:{let e=US(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:WS(e)}}}case`escaped`:{let e=US(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:WS(e)}}}default:return{}}}}},KS=new Set([`left`,`top`]);async function qS(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=vS(n),s=yS(n),c=SS(n)===`y`,l=KS.has(o)?-1:1,u=a&&c?-1:1,d=_S(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 JS=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 qS(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}}}}},YS=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}=_S(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=SS(vS(i)),p=bS(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=gS(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=gS(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}}}}}},XS=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}=_S(e,t),u={x:n,y:r},d=SS(i),f=bS(d),p=u[f],m=u[d],h=_S(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=KS.has(vS(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}}}},ZS=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}=_S(e,t),u=await o.detectOverflow(t,l),d=vS(i),f=yS(i),p=SS(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=uS(h-u[g],v),x=uS(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=dS(u.left,0),t=dS(u.right,0),n=dS(u.top,0),r=dS(u.bottom,0);p?w=m-2*(e!==0||t!==0?e+t:dS(u.left,u.right)):C=h-2*(n!==0||r!==0?n+r:dS(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 QS(){return typeof window<`u`}function $S(e){return nC(e)?(e.nodeName||``).toLowerCase():`#document`}function eC(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function tC(e){return((nC(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function nC(e){return QS()?e instanceof Node||e instanceof eC(e).Node:!1}function rC(e){return QS()?e instanceof Element||e instanceof eC(e).Element:!1}function iC(e){return QS()?e instanceof HTMLElement||e instanceof eC(e).HTMLElement:!1}function aC(e){return!QS()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof eC(e).ShadowRoot}function oC(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=_C(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function sC(e){return/^(table|td|th)$/.test($S(e))}function cC(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var lC=/transform|translate|scale|rotate|perspective|filter/,uC=/paint|layout|strict|content/,dC=e=>!!e&&e!==`none`,fC;function pC(e){let t=rC(e)?_C(e):e;return dC(t.transform)||dC(t.translate)||dC(t.scale)||dC(t.rotate)||dC(t.perspective)||!hC()&&(dC(t.backdropFilter)||dC(t.filter))||lC.test(t.willChange||``)||uC.test(t.contain||``)}function mC(e){let t=yC(e);for(;iC(t)&&!gC(t);){if(pC(t))return t;if(cC(t))return null;t=yC(t)}return null}function hC(){return fC??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),fC}function gC(e){return/^(html|body|#document)$/.test($S(e))}function _C(e){return eC(e).getComputedStyle(e)}function vC(e){return rC(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function yC(e){if($S(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||aC(e)&&e.host||tC(e);return aC(t)?t.host:t}function bC(e){let t=yC(e);return gC(t)?e.ownerDocument?e.ownerDocument.body:e.body:iC(t)&&oC(t)?t:bC(t)}function xC(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=bC(e),i=r===e.ownerDocument?.body,a=eC(r);if(i){let e=SC(a);return t.concat(a,a.visualViewport||[],oC(r)?r:[],e&&n?xC(e):[])}else return t.concat(r,xC(r,[],n))}function SC(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function CC(e){let t=_C(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=iC(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=fS(n)!==a||fS(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function wC(e){return rC(e)?e:e.contextElement}function TC(e){let t=wC(e);if(!iC(t))return mS(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=CC(t),o=(a?fS(n.width):n.width)/r,s=(a?fS(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var EC=mS(0);function DC(e){let t=eC(e);return!hC()||!t.visualViewport?EC:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function OC(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==eC(e)?!1:t}function kC(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=wC(e),o=mS(1);t&&(r?rC(r)&&(o=TC(r)):o=TC(e));let s=OC(a,n,r)?DC(a):mS(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=eC(a),t=r&&rC(r)?eC(r):r,n=e,i=SC(n);for(;i&&r&&t!==n;){let e=TC(i),t=i.getBoundingClientRect(),r=_C(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=eC(i),i=SC(n)}}return IS({width:u,height:d,x:c,y:l})}function AC(e,t){let n=vC(e).scrollLeft;return t?t.left+n:kC(tC(e)).left+n}function jC(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-AC(e,n),y:n.top+t.scrollTop}}function MC(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=tC(r),s=t?cC(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=mS(1),u=mS(0),d=iC(r);if((d||!d&&!a)&&(($S(r)!==`body`||oC(o))&&(c=vC(r)),d)){let e=kC(r);l=TC(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?jC(o,c):mS(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 NC(e){return Array.from(e.getClientRects())}function PC(e){let t=tC(e),n=vC(e),r=e.ownerDocument.body,i=dS(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=dS(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+AC(e),s=-n.scrollTop;return _C(r).direction===`rtl`&&(o+=dS(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}var FC=25;function IC(e,t){let n=eC(e),r=tC(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=hC();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=AC(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<=FC&&(a-=o)}else l<=FC&&(a+=l);return{width:a,height:o,x:s,y:c}}function LC(e,t){let n=kC(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=iC(e)?TC(e):mS(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function RC(e,t,n){let r;if(t===`viewport`)r=IC(e,n);else if(t===`document`)r=PC(tC(e));else if(rC(t))r=LC(t,n);else{let n=DC(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return IS(r)}function zC(e,t){let n=yC(e);return n===t||!rC(n)||gC(n)?!1:_C(n).position===`fixed`||zC(n,t)}function BC(e,t){let n=t.get(e);if(n)return n;let r=xC(e,[],!1).filter(e=>rC(e)&&$S(e)!==`body`),i=null,a=_C(e).position===`fixed`,o=a?yC(e):e;for(;rC(o)&&!gC(o);){let t=_C(o),n=pC(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&(i.position===`absolute`||i.position===`fixed`)||oC(o)&&!n&&zC(e,o))?r=r.filter(e=>e!==o):i=t,o=yC(o)}return t.set(e,r),r}function VC(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?cC(t)?[]:BC(t,this._c):[].concat(n),r],o=RC(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=RC(t,a[e],i);s=dS(n.top,s),c=uS(n.right,c),l=uS(n.bottom,l),u=dS(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function HC(e){let{width:t,height:n}=CC(e);return{width:t,height:n}}function UC(e,t,n){let r=iC(t),i=tC(t),a=n===`fixed`,o=kC(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=mS(0);function l(){c.x=AC(i)}if(r||!r&&!a)if(($S(t)!==`body`||oC(i))&&(s=vC(t)),r){let e=kC(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?jC(i,s):mS(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 WC(e){return _C(e).position===`static`}function GC(e,t){if(!iC(e)||_C(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return tC(e)===n&&(n=n.ownerDocument.body),n}function KC(e,t){let n=eC(e);if(cC(e))return n;if(!iC(e)){let t=yC(e);for(;t&&!gC(t);){if(rC(t)&&!WC(t))return t;t=yC(t)}return n}let r=GC(e,t);for(;r&&sC(r)&&WC(r);)r=GC(r,t);return r&&gC(r)&&WC(r)&&!pC(r)?n:r||mC(e)||n}var qC=async function(e){let t=this.getOffsetParent||KC,n=this.getDimensions,r=await n(e.floating);return{reference:UC(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function JC(e){return _C(e).direction===`rtl`}var YC={convertOffsetParentRelativeRectToViewportRelativeRect:MC,getDocumentElement:tC,getClippingRect:VC,getOffsetParent:KC,getElementRects:qC,getClientRects:NC,getDimensions:HC,getScale:TC,isElement:rC,isRTL:JC};function XC(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function ZC(e,t){let n=null,r,i=tC(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=pS(d),h=pS(i.clientWidth-(u+f)),g=pS(i.clientHeight-(d+p)),_=pS(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:dS(0,uS(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&&!XC(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 QC(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=wC(e),u=i||a?[...l?xC(l):[],...t?xC(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?ZC(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?kC(e):null;c&&g();function g(){let t=kC(e);h&&!XC(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 $C=JS,ew=YS,tw=HS,nw=ZS,rw=GS,iw=VS,aw=XS,ow=(e,t,n)=>{let r=new Map,i={platform:YC,...n},a={...i.platform,_c:r};return BS(e,t,{...i,platform:a})},sw=typeof document<`u`?Q.useLayoutEffect:function(){};function cw(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(!cw(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)&&!cw(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function lw(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function uw(e,t){let n=lw(e);return Math.round(t*n)/n}function dw(e){let t=Q.useRef(e);return sw(()=>{t.current=e}),t}function fw(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);cw(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=dw(c),D=dw(i),O=dw(l),k=Q.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};D.current&&(e.platform=D.current),ow(S.current,C.current,e).then(e=>{let t={...e,isPositioned:O.current!==!1};A.current&&!cw(w.current,t)&&(w.current=t,Bb.flushSync(()=>{d(t)}))})},[f,t,n,D,O]);sw(()=>{l===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let A=Q.useRef(!1);sw(()=>(A.current=!0,()=>{A.current=!1}),[]),sw(()=>{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=uw(M.floating,u.x),r=uw(M.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...lw(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 pw=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?{}:iw({element:r.current,padding:i}).fn(n):r?iw({element:r,padding:i}).fn(n):{}}}},mw=(e,t)=>{let n=$C(e);return{name:n.name,fn:n.fn,options:[e,t]}},hw=(e,t)=>{let n=ew(e);return{name:n.name,fn:n.fn,options:[e,t]}},gw=(e,t)=>({fn:aw(e).fn,options:[e,t]}),_w=(e,t)=>{let n=tw(e);return{name:n.name,fn:n.fn,options:[e,t]}},vw=(e,t)=>{let n=nw(e);return{name:n.name,fn:n.fn,options:[e,t]}},yw=(e,t)=>{let n=rw(e);return{name:n.name,fn:n.fn,options:[e,t]}},bw=(e,t)=>{let n=pw(e);return{name:n.name,fn:n.fn,options:[e,t]}},xw=`Arrow`,Sw=Q.forwardRef((e,t)=>{let{children:n,width:r=10,height:i=5,...a}=e;return(0,$.jsx)(In.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`})})});Sw.displayName=xw;var Cw=Sw;function ww(e){let[t,n]=Q.useState(void 0);return Rn(()=>{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 Tw=`Popper`,[Ew,Dw]=Ln(Tw),[Ow,kw]=Ew(Tw),Aw=e=>{let{__scopePopper:t,children:n}=e,[r,i]=Q.useState(null);return(0,$.jsx)(Ow,{scope:t,anchor:r,onAnchorChange:i,children:n})};Aw.displayName=Tw;var jw=`PopperAnchor`,Mw=Q.forwardRef((e,t)=>{let{__scopePopper:n,virtualRef:r,...i}=e,a=kw(jw,n),o=Q.useRef(null),s=Fn(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)(In.div,{...i,ref:s})});Mw.displayName=jw;var Nw=`PopperContent`,[Pw,Fw]=Ew(Nw),Iw=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=kw(Nw,n),[_,v]=Q.useState(null),y=Fn(t,e=>v(e)),[b,x]=Q.useState(null),S=ww(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(Bw),altBoundary:O},{refs:A,floatingStyles:j,placement:M,isPositioned:N,middlewareData:P}=fw({strategy:`fixed`,placement:T,whileElementsMounted:(...e)=>QC(...e,{animationFrame:p===`always`}),elements:{reference:g.anchor},middleware:[mw({mainAxis:i+w,alignmentAxis:o}),c&&hw({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?gw():void 0,...k}),c&&_w({...k}),vw({...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&&bw({element:b,padding:s}),Vw({arrowWidth:C,arrowHeight:w}),f&&yw({strategy:`referenceHidden`,...k})]}),[F,I]=Hw(M),L=Vn(m);Rn(()=>{N&&L?.()},[N,L]);let ee=P.arrow?.x,R=P.arrow?.y,z=P.arrow?.centerOffset!==0,[B,V]=Q.useState();return Rn(()=>{_&&V(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:B,"--radix-popper-transform-origin":[P.transformOrigin?.x,P.transformOrigin?.y].join(` `),...P.hide?.referenceHidden&&{visibility:`hidden`,pointerEvents:`none`}},dir:e.dir,children:(0,$.jsx)(Pw,{scope:n,placedSide:F,onArrowChange:x,arrowX:ee,arrowY:R,shouldHideArrow:z,children:(0,$.jsx)(In.div,{"data-side":F,"data-align":I,...h,ref:y,style:{...h.style,animation:N?void 0:`none`}})})})});Iw.displayName=Nw;var Lw=`PopperArrow`,Rw={top:`bottom`,right:`left`,bottom:`top`,left:`right`},zw=Q.forwardRef(function(e,t){let{__scopePopper:n,...r}=e,i=Fw(Lw,n),a=Rw[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)(Cw,{...r,ref:t,style:{...r.style,display:`block`}})})});zw.displayName=Lw;function Bw(e){return e!==null}var Vw=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]=Hw(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 Hw(e){let[t,n=`center`]=e.split(`-`);return[t,n]}var Uw=Aw,Ww=Mw,Gw=Iw,Kw=zw;function qw(e){let t=Jw(e),n=Q.forwardRef((e,n)=>{let{children:r,...i}=e,a=Q.Children.toArray(r),o=a.find(Xw);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 Jw(e){let t=Q.forwardRef((e,t)=>{let{children:n,...r}=e;if(Q.isValidElement(n)){let e=Qw(n),i=Zw(r,n.props);return n.type!==Q.Fragment&&(i.ref=t?$n(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 Yw=Symbol(`radix.slottable`);function Xw(e){return Q.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===Yw}function Zw(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 Qw(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 $w(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 eT=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`}),tT=`VisuallyHidden`,nT=Q.forwardRef((e,t)=>(0,$.jsx)(In.span,{...e,ref:t,style:{...eT,...e.style}}));nT.displayName=tT;var rT=nT,iT=[` `,`Enter`,`ArrowUp`,`ArrowDown`],aT=[` `,`Enter`],oT=`Select`,[sT,cT,lT]=oS(oT),[uT,dT]=Ln(oT,[lT,Dw]),fT=Dw(),[pT,mT]=uT(oT),[hT,gT]=uT(oT),_T=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=fT(t),[g,_]=Q.useState(null),[v,y]=Q.useState(null),[b,x]=Q.useState(!1),S=cS(l),[C,w]=ur({prop:r,defaultProp:i??!1,onChange:a,caller:oT}),[T,E]=ur({prop:o,defaultProp:s,onChange:c,caller:oT}),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)(Uw,{...h,children:(0,$.jsxs)(pT,{required:p,scope:t,trigger:g,onTriggerChange:_,valueNode:v,onValueNodeChange:y,valueNodeHasChildren:b,onValueNodeHasChildrenChange:x,contentId:Hn(),value:T,onValueChange:E,open:C,onOpenChange:w,dir:S,triggerPointerDownPosRef:D,disabled:f,children:[(0,$.jsx)(sT.Provider,{scope:t,children:(0,$.jsx)(hT,{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)(fE,{"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]})})};_T.displayName=oT;var vT=`SelectTrigger`,yT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,disabled:r=!1,...i}=e,a=fT(n),o=mT(vT,n),s=o.disabled||r,c=Fn(t,o.onTriggerChange),l=cT(n),u=Q.useRef(`touch`),[d,f,p]=mE(e=>{let t=l().filter(e=>!e.disabled),n=hE(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)(Ww,{asChild:!0,...a,children:(0,$.jsx)(In.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":pE(o.value)?``:void 0,...i,ref:c,onClick:Bn(i.onClick,e=>{e.currentTarget.focus(),u.current!==`mouse`&&m(e)}),onPointerDown:Bn(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:Bn(i.onKeyDown,e=>{let t=d.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&f(e.key),!(t&&e.key===` `)&&iT.includes(e.key)&&(m(),e.preventDefault())})})})});yT.displayName=vT;var bT=`SelectValue`,xT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,children:a,placeholder:o=``,...s}=e,c=mT(bT,n),{onValueNodeHasChildrenChange:l}=c,u=a!==void 0,d=Fn(t,c.onValueNodeChange);return Rn(()=>{l(u)},[l,u]),(0,$.jsx)(In.span,{...s,ref:d,style:{pointerEvents:`none`},children:pE(c.value)?(0,$.jsx)($.Fragment,{children:o}):a})});xT.displayName=bT;var ST=`SelectIcon`,CT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,children:r,...i}=e;return(0,$.jsx)(In.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})});CT.displayName=ST;var wT=`SelectPortal`,TT=e=>(0,$.jsx)(fr,{asChild:!0,...e});TT.displayName=wT;var ET=`SelectContent`,DT=Q.forwardRef((e,t)=>{let n=mT(ET,e.__scopeSelect),[r,i]=Q.useState();if(Rn(()=>{i(new DocumentFragment)},[]),!n.open){let t=r;return t?Bb.createPortal((0,$.jsx)(kT,{scope:e.__scopeSelect,children:(0,$.jsx)(sT.Slot,{scope:e.__scopeSelect,children:(0,$.jsx)(`div`,{children:e.children})})}),t):null}return(0,$.jsx)(NT,{...e,ref:t})});DT.displayName=ET;var OT=10,[kT,AT]=uT(ET),jT=`SelectContentImpl`,MT=qw(`SelectContent.RemoveScroll`),NT=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=mT(ET,n),[y,b]=Q.useState(null),[x,S]=Q.useState(null),C=Fn(t,e=>b(e)),[w,T]=Q.useState(null),[E,D]=Q.useState(null),O=cT(n),[k,A]=Q.useState(!1),j=Q.useRef(!1);Q.useEffect(()=>{if(y)return Xn(y)},[y]),Un();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]=mE(e=>{let t=O().filter(e=>!e.disabled),n=hE(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current.focus())}),ee=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]),R=Q.useCallback(()=>y?.focus(),[y]),z=Q.useCallback((e,t,n)=>{let r=!j.current&&!n;(v.value!==void 0&&v.value===t||r)&&D(e)},[v.value]),B=r===`popper`?LT:FT,V=B===LT?{side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g}:{};return(0,$.jsx)(kT,{scope:n,content:y,viewport:x,onViewportChange:S,itemRefCallback:ee,selectedItem:w,onItemLeave:R,itemTextRefCallback:z,focusSelectedItem:N,selectedItemText:E,position:r,isPositioned:k,searchRef:I,children:(0,$.jsx)(Yn,{as:MT,allowPinchZoom:!0,children:(0,$.jsx)(Gn,{asChild:!0,trapped:v.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:Bn(i,e=>{v.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,$.jsx)(dr,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>v.onOpenChange(!1),children:(0,$.jsx)(B,{role:`listbox`,id:v.contentId,"data-state":v.open?`open`:`closed`,dir:v.dir,onContextMenu:e=>e.preventDefault(),..._,...V,onPlaced:()=>A(!0),ref:C,style:{display:`flex`,flexDirection:`column`,outline:`none`,..._.style},onKeyDown:Bn(_.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()}})})})})})})});NT.displayName=jT;var PT=`SelectItemAlignedPosition`,FT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,onPlaced:r,...i}=e,a=mT(ET,n),o=AT(ET,n),[s,c]=Q.useState(null),[l,u]=Q.useState(null),d=Fn(t,e=>u(e)),f=cT(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-OT,d=$x(a,[OT,Math.max(OT,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-OT,d=$x(a,[OT,Math.max(OT,u-l)]);s.style.minWidth=c+`px`,s.style.right=d+`px`}let o=f(),c=window.innerHeight-OT*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-OT,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=`${OT}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]);Rn(()=>y(),[y]);let[b,x]=Q.useState();return Rn(()=>{l&&x(window.getComputedStyle(l).zIndex)},[l]),(0,$.jsx)(RT,{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)(In.div,{...i,ref:d,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})});FT.displayName=PT;var IT=`SelectPopperPosition`,LT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,align:r=`start`,collisionPadding:i=OT,...a}=e,o=fT(n);return(0,$.jsx)(Gw,{...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)`}})});LT.displayName=IT;var[RT,zT]=uT(ET,{}),BT=`SelectViewport`,VT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,nonce:r,...i}=e,a=AT(BT,n),o=zT(BT,n),s=Fn(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)(sT.Slot,{scope:n,children:(0,$.jsx)(In.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:s,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:Bn(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-OT*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})})})]})});VT.displayName=BT;var HT=`SelectGroup`,[UT,WT]=uT(HT),GT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=Hn();return(0,$.jsx)(UT,{scope:n,id:i,children:(0,$.jsx)(In.div,{role:`group`,"aria-labelledby":i,...r,ref:t})})});GT.displayName=HT;var KT=`SelectLabel`,qT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=WT(KT,n);return(0,$.jsx)(In.div,{id:i.id,...r,ref:t})});qT.displayName=KT;var JT=`SelectItem`,[YT,XT]=uT(JT),ZT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...o}=e,s=mT(JT,n),c=AT(JT,n),l=s.value===r,[u,d]=Q.useState(a??``),[f,p]=Q.useState(!1),m=Fn(t,e=>c.itemRefCallback?.(e,r,i)),h=Hn(),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)(YT,{scope:n,value:r,disabled:i,textId:h,isSelected:l,onItemTextChange:Q.useCallback(e=>{d(t=>t||(e?.textContent??``).trim())},[]),children:(0,$.jsx)(sT.ItemSlot,{scope:n,value:r,disabled:i,textValue:u,children:(0,$.jsx)(In.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:Bn(o.onFocus,()=>p(!0)),onBlur:Bn(o.onBlur,()=>p(!1)),onClick:Bn(o.onClick,()=>{g.current!==`mouse`&&_()}),onPointerUp:Bn(o.onPointerUp,()=>{g.current===`mouse`&&_()}),onPointerDown:Bn(o.onPointerDown,e=>{g.current=e.pointerType}),onPointerMove:Bn(o.onPointerMove,e=>{g.current=e.pointerType,i?c.onItemLeave?.():g.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:Bn(o.onPointerLeave,e=>{e.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:Bn(o.onKeyDown,e=>{c.searchRef?.current!==``&&e.key===` `||(aT.includes(e.key)&&_(),e.key===` `&&e.preventDefault())})})})})});ZT.displayName=JT;var QT=`SelectItemText`,$T=Q.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,...a}=e,o=mT(QT,n),s=AT(QT,n),c=XT(QT,n),l=gT(QT,n),[u,d]=Q.useState(null),f=Fn(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 Rn(()=>(h(m),()=>g(m)),[h,g,m]),(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(In.span,{id:c.textId,...a,ref:f}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren?Bb.createPortal(a.children,o.valueNode):null]})});$T.displayName=QT;var eE=`SelectItemIndicator`,tE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return XT(eE,n).isSelected?(0,$.jsx)(In.span,{"aria-hidden":!0,...r,ref:t}):null});tE.displayName=eE;var nE=`SelectScrollUpButton`,rE=Q.forwardRef((e,t)=>{let n=AT(nE,e.__scopeSelect),r=zT(nE,e.__scopeSelect),[i,a]=Q.useState(!1),o=Fn(t,r.onScrollButtonChange);return Rn(()=>{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)(oE,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null});rE.displayName=nE;var iE=`SelectScrollDownButton`,aE=Q.forwardRef((e,t)=>{let n=AT(iE,e.__scopeSelect),r=zT(iE,e.__scopeSelect),[i,a]=Q.useState(!1),o=Fn(t,r.onScrollButtonChange);return Rn(()=>{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)(oE,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null});aE.displayName=iE;var oE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,onAutoScroll:r,...i}=e,a=AT(`SelectScrollButton`,n),o=Q.useRef(null),s=cT(n),c=Q.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return Q.useEffect(()=>()=>c(),[c]),Rn(()=>{s().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[s]),(0,$.jsx)(In.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:Bn(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:Bn(i.onPointerMove,()=>{a.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:Bn(i.onPointerLeave,()=>{c()})})}),sE=`SelectSeparator`,cE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return(0,$.jsx)(In.div,{"aria-hidden":!0,...r,ref:t})});cE.displayName=sE;var lE=`SelectArrow`,uE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=fT(n),a=mT(lE,n),o=AT(lE,n);return a.open&&o.position===`popper`?(0,$.jsx)(Kw,{...i,...r,ref:t}):null});uE.displayName=lE;var dE=`SelectBubbleInput`,fE=Q.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{let i=Q.useRef(null),a=Fn(r,i),o=$w(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)(In.select,{...n,style:{...eT,...n.style},ref:a,defaultValue:t})});fE.displayName=dE;function pE(e){return e===``||e===void 0}function mE(e){let t=Vn(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 hE(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=gE(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 gE(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var _E=_T,vE=yT,yE=xT,bE=CT,xE=TT,SE=DT,CE=VT,wE=qT,TE=ZT,EE=$T,DE=tE,OE=rE,kE=aE,AE=cE,jE=`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`,ME=`overflow-hidden rounded-xl border border-border/60 bg-card/95 shadow-2xl backdrop-blur-xl`,NE=`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 PE({label:e,value:t,options:n,icon:r,onSelect:i,placeholder:a,disabled:o=!1,testId:s}){return(0,$.jsxs)(_E,{value:t,onValueChange:i,disabled:o||n.length===0,children:[(0,$.jsxs)(vE,{"aria-label":e,title:e,"data-agent-interactive":!0,"data-testid":s,className:jE,children:[(0,$.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-accent-primary`,"aria-hidden":!0}),(0,$.jsx)(yE,{placeholder:a??e,className:`max-w-[160px] truncate`}),(0,$.jsx)(bE,{asChild:!0,children:(0,$.jsx)(Wo,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`})})]}),(0,$.jsx)(xE,{children:(0,$.jsxs)(SE,{position:`popper`,side:`top`,align:`start`,sideOffset:4,collisionPadding:8,className:`z-[80] min-w-[12rem] max-w-[20rem] ${ME} 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)(OE,{className:`flex items-center justify-center py-1 text-foreground/50`,children:(0,$.jsx)(fn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(CE,{className:`max-h-72 py-1`,children:n.map(e=>{let t=e.icon??r;return(0,$.jsxs)(TE,{value:e.value,className:`${NE} 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)(EE,{children:(0,$.jsx)(`span`,{className:`truncate`,children:e.label})}),(0,$.jsx)(DE,{className:`absolute right-3 flex items-center`,children:(0,$.jsx)(vn,{className:`h-3.5 w-3.5 text-accent-primary`})})]},e.value)})}),(0,$.jsx)(kE,{className:`flex items-center justify-center py-1 text-foreground/50`,children:(0,$.jsx)(Wo,{className:`h-3.5 w-3.5`})})]})})]})}var FE=`__new__`,IE=`__legacy__`,LE=`__default__`,RE=12,zE=`specrails:focus-pr-card`,BE=(0,Q.lazy)(()=>c(()=>import(`./JobDetailModal-BS-htwqZ.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])));function VE(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 HE(e,t){let n=e(`railCard.rail`,{index:t.railIndex+1});return t.name?`${n} · ${t.name}`:n}function UE({proposal:e,proposalIndex:t,messageId:n,conversationId:r,projectId:i,intent:a,compact:o=!1}){let{t:s}=K(`agent`),c=Ay(),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=`${Ke}/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)}),Ce&&Yx.list().then(t=>{e||_(t.filter(e=>e.status===`published`&&Qx(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??Wx(null,e.mode),aiEngine:e.aiEngine,model:e.model,reasoningEffort:e.reasoningEffort,profileName:e.profileName,targetPrNumber:e.targetPrNumber,baseBranch:e.baseBranch??``})),S=(0,Q.useCallback)(e=>x(t=>({...t,...e})),[]),C=l.detected,w=!l.loading,T=(0,Q.useMemo)(()=>b.aiEngine&&(bt(b.aiEngine)||C.includes(b.aiEngine))?b.aiEngine:C[0]??null,[b.aiEngine,C]),E=!!b.aiEngine&&w&&T!==b.aiEngine,D=!!T&&bt(T),O=T&&!bt(T)?T:C[0]??null,k=(0,Q.useMemo)(()=>Ix(O),[O]),A=(0,Q.useMemo)(()=>b.model&&k.some(e=>e.value===b.model)?b.model:Lx(O)||null,[b.model,k,O]),j=!!b.model&&k.length>0&&A!==b.model,M=(0,Q.useMemo)(()=>mt(O,A),[O,A]),N=b.reasoningEffort&&M.includes(b.reasoningEffort)?b.reasoningEffort:null,P=Ux(b.loopId),F=!D&&P!==`loop`&&_t(O);(0,Q.useEffect)(()=>{if(!i||a||!O||!F){h([]);return}let e=!1;return fetch(`${Ke}/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,F]);let I=b.profileName&&m.some(e=>e.name===b.profileName)?b.profileName:null,L=(0,Q.useMemo)(()=>u?.rails??[],[u]),ee=(0,Q.useMemo)(()=>{let e=new Map;if(!u)return e;for(let t of L)e.set(t.railIndex,VE(t,u,f??[]));return e},[L,u,f]),z=b.railIndex===null?void 0:L.find(e=>e.railIndex===b.railIndex),B=u!==null&&b.railIndex!==null&&!b.newRail&&!z,V=!!z&&!b.newRail&&ee.get(z.railIndex)!==`free`&&ee.get(z.railIndex)!==void 0,H=L.length>=RE,U=L.find(e=>ee.get(e.railIndex)===`free`),te=b.newRail?FE:b.railIndex!==null&&z?String(b.railIndex):U?String(U.railIndex):H?``:FE,ne=b.newRail||te===FE||te===``?null:Number(te),re=te===FE,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)(()=>(f??[]).filter(e=>(e.status===`todo`||e.status===`draft`)&&!b.ticketIds.includes(e.id)),[f,b.ticketIds]),ce=!D&&gt(O),le=(0,Q.useMemo)(()=>[...Vx.filter(e=>(!e.requiresFreestyle||ce)&&(!e.requiresLoops||Ce)).map(e=>({value:e.id,label:s(`dashboard:${e.labelKey}`)})),...g.map(e=>({value:e.id,label:e.name}))],[g,ce,s]),ue=le.some(e=>e.value===b.loopId)?b.loopId:le[0]?.value??b.loopId,[de,fe]=(0,Q.useState)(null),[pe,me]=(0,Q.useState)(null),[he,W]=(0,Q.useState)(null),ge=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>()=>{ge.current=!1},[]);let _e=a??he,ve=i?v?s(`railCard.block.loadFailed`):ae.length===0?s(`railCard.block.noSpecs`):te===``?s(`railCard.block.railLimit`,{max:RE}):null:s(`railCard.block.noProject`),ye=(0,Q.useCallback)(async e=>{let t=await To(r,n,e),i=t.ok?t.intent:{...e,at:new Date().toISOString()};kx(n,i),ge.current&&W(i)},[r,n]),be=(0,Q.useCallback)(async()=>{if(!i||ve||de)return;fe(`launch`),me(null);let e=`${Ke}/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){me(await a(t));return}let r=await t.json();if(typeof r.rail?.railIndex!=`number`){me({error:`invalid_response`});return}o=r.rail.railIndex}else if(s&&s!==(z?.name??``)){let t=await fetch(`${e}/${o}/name`,{method:`PUT`,headers:n,body:JSON.stringify({name:s})});if(!t.ok){me(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:P,profileName:F?I:null,...c?{aiEngine:c}:{}})});if(!l.ok){me(await a(l));return}let u={mode:P,loopId:ue,originConversationId:r,originSurface:`agent-chat`,...c?{aiEngine:c}:{},...!D&&A?{model:A}:{},...!D&&N?{reasoning_effort:N}:{},...F&&I?{profileName:I}:{},...b.targetPrNumber?{targetPrNumber:b.targetPrNumber}:{},...b.baseBranch.trim()?{baseBranch:b.baseBranch.trim()}:{}},d=await fetch(`${e}/${o}/launch`,{method:`POST`,headers:n,body:JSON.stringify(u)});if(!d.ok){me(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]:[];Rt(i),await ye({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){me({error:e instanceof Error?e.message:`network`})}finally{ge.current&&fe(null)}},[i,ve,de,ne,b,z,T,D,C.length,ae,P,F,I,ue,A,N,r,t,ye]),xe=(0,Q.useCallback)(async()=>{if(!de){fe(`dismiss`);try{await ye({kind:`rail-launch`,proposalIndex:t,status:`dismissed`})}finally{ge.current&&fe(null)}}},[de,ye,t]),[Se,G]=(0,Q.useState)(null);if(_e){let t=_e.status===`launched`,n=_e.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)(qo,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`}):(0,$.jsx)(Mo,{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 _e.railIndex==`number`?_e.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:_e.prDeliveryId??null,runIds:_e.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)(nc,{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:()=>G(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)(ln,{className:`h-3 w-3`}),s(`railCard.stub.viewRun`)]}),Se&&i&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(BE,{jobId:Se,projectId:i,onClose:()=>G(null)})})]})}let we=[...L.map(e=>{let t=ee.get(e.railIndex),n=t&&t!==`free`?` · ${s(`railCard.availability.${t}`)}`:``;return{value:String(e.railIndex),label:`${HE(s,e)}${n}`}}),...H?[]:[{value:FE,label:s(`railCard.newRail`),icon:Dn}]],Te=[...C.map(e=>({value:e,label:l.providers[e]?.displayName??Dt(e)})),...C.length>1?[{value:Ot,label:s(`agents:railSelectors.rolesEngine`),icon:Is}]:[]],Ee=k.map(e=>({value:e.value,label:e.label??e.value})),De=[{value:LE,label:s(`railCard.effortDefault`)},...M.map(e=>({value:e,label:s(`effort.${e}`,{defaultValue:e})}))],Oe=[{value:IE,label:s(`railCard.profileNone`)},...m.map(e=>({value:e.name,label:e.name}))],ke=!!i&&!v&&(u===null||f===null),Ae=ke?{tone:`border-border/60 bg-surface/60 text-foreground/50`,label:s(`railCard.status.loading`)}:ve?{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)(jy.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)(fc,{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`,Ae.tone),children:Ae.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)(kn,{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)(PE,{label:s(`railCard.fields.rail`),icon:Ac,value:te,options:we,disabled:ke||!!de,testId:`rail-card-rail`,onSelect:e=>S(e===FE?{newRail:!0,railIndex:null}:{newRail:!1,railIndex:Number(e)})}),(re||z)&&(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`})]}),B&&(0,$.jsx)(WE,{tone:`warning`,text:s(`railCard.notes.railMissing`,{index:(b.railIndex??0)+1})}),V&&z&&(0,$.jsx)(WE,{tone:`warning`,text:s(`railCard.notes.railBusy`,{index:z.railIndex+1,state:s(`railCard.availability.${ee.get(z.railIndex)??`busy`}`)}),action:U?{label:s(`railCard.notes.useFree`,{index:U.railIndex+1}),onClick:()=>S({newRail:!1,railIndex:U.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:!!de,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)(Nn,{className:`h-3 w-3`})})]},e)}),se.length>0&&(0,$.jsx)(PE,{label:s(`railCard.fields.addSpec`),icon:Dn,value:``,placeholder:s(`railCard.fields.addSpec`),options:se.slice(0,40).map(e=>({value:String(e.id),label:`#${e.id} ${e.title}`})),disabled:!!de,testId:`rail-card-add-spec`,onSelect:e=>S({ticketIds:[...b.ticketIds,Number(e)]})})]}),oe.length>0&&(0,$.jsx)(WE,{tone:`muted`,text:s(`railCard.notes.specsDropped`,{ids:oe.map(e=>`#${e}`).join(`, `)})}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-1 gap-y-1`,children:[(0,$.jsx)(PE,{label:s(`railCard.fields.loop`),icon:Fc,value:ue,options:le,disabled:!!de,testId:`rail-card-loop`,onSelect:e=>S({loopId:e})}),Te.length>1&&(0,$.jsx)(PE,{label:s(`railCard.fields.engine`),icon:ss,value:T??``,options:Te,disabled:!!de,testId:`rail-card-engine`,onSelect:e=>S({aiEngine:e,model:null,reasoningEffort:null,profileName:null})}),!D&&Ee.length>0&&(0,$.jsx)(PE,{label:s(`railCard.fields.model`),icon:Lo,value:A??``,options:Ee,disabled:!!de,testId:`rail-card-model`,onSelect:e=>S({model:e})}),!D&&M.length>0&&(0,$.jsx)(PE,{label:s(`railCard.fields.effort`),icon:Ss,value:N??LE,options:De,disabled:!!de,testId:`rail-card-effort`,onSelect:e=>S({reasoningEffort:e===LE?null:e})}),F&&m.length>0&&(0,$.jsx)(PE,{label:s(`railCard.fields.profile`),icon:jc,value:I??IE,options:Oe,disabled:!!de,testId:`rail-card-profile`,onSelect:e=>S({profileName:e===IE?null:e})})]}),E&&(0,$.jsx)(WE,{tone:`muted`,text:s(`railCard.notes.engineStale`,{engine:b.aiEngine,fallback:T?Dt(T):``})}),j&&(0,$.jsx)(WE,{tone:`muted`,text:s(`railCard.notes.modelStale`,{model:b.model,fallback:A})}),(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)(R,{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:!!de,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)(Sn,{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:!!de,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`})]})]}),pe&&(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)(jn,{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.${pe.error}`,{defaultValue:pe.error})}),pe.detail&&(0,$.jsx)(`div`,{className:`text-destructive/80`,children:pe.detail}),pe.action&&(0,$.jsx)(`div`,{className:`text-foreground/70`,children:pe.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:ve??s(`railCard.playHint`)}),(0,$.jsx)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`rail-card-dismiss`,disabled:!!de,onClick:()=>void xe(),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:!!de||ke||!!ve,onClick:()=>void be(),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:[de===`launch`?(0,$.jsx)(Cn,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Tn,{className:`h-3.5 w-3.5`}),s(de===`launch`?`railCard.launching`:`railCard.play`)]})]})]})]})}function WE({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)(jn,{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 GE(){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)(Cn,{className:`h-3 w-3 animate-spin`}),e(`railCard.pending`)]})}function KE({excerpts:e}){let{t}=K(`agent`);return(0,$.jsxs)(`div`,{"data-testid":`agent-rail-launch-unreadable`,title:e.join(`
32
+ `).trim()}function Ex(e,t=!1){let n={body:e??``,proposals:[],rejected:[],pending:!1,truncated:!1,repaired:!1};if(!e||!e.includes(_x))return n;let r=[],i=[],a=!1,o=``,s=0;gx.lastIndex=0;let c,l=e=>{let t=Pt(e);if(!t.ok){i.push({reason:`invalid_json`,excerpt:Cx(e)});return}t.repaired&&(a=!0);let n=wx(t.value);n.ok?r.push(n.proposal):i.push({reason:n.reason,excerpt:Cx(e)})};for(;(c=gx.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(_x);if(f!==-1){let e=o.slice(f+14).replace(/^[^\S\n]*\n?/,``).replace(/\s*(?:```)?\s*$/,``),n=e.trim()?Pt(e):null;if(n&&n.ok){n.repaired&&(a=!0);let t=wx(n.value);t.ok?r.push(t.proposal):i.push({reason:t.reason,excerpt:Cx(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:Cx(e)}))}return{body:Tx(o),proposals:r,rejected:i,pending:u,truncated:d,repaired:a}}var Dx=new Map,Ox=new Set;function kx(e,t){let n=new Map(Dx),r=n.get(e)??[];n.set(e,[...r.filter(e=>e.proposalIndex!==t.proposalIndex),t]),Dx=n;for(let e of Ox)e()}function Ax(e){return Ox.add(e),()=>{Ox.delete(e)}}function jx(){return(0,Q.useSyncExternalStore)(Ax,()=>Dx,()=>Dx)}function Mx(e,t,n,r){return e.get(t)?.find(e=>e.proposalIndex===r)??n?.find(e=>e.proposalIndex===r)??null}var Nx={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`}]},Px=new Map;function Fx(e,t){if(!e)return;let n=Array.from(new Set(t.filter(e=>typeof e==`string`&&e.trim())));if(n.length===0){Px.delete(e);return}Px.set(e,n.map(e=>({value:e,label:e})))}function Ix(e){return e?Nx[e]??Px.get(e)??[]:[]}function Lx(e){return Ix(e)[0]?.value??``}function Rx(e){for(let[t,n]of Object.entries(e))n?.kind===`local`&&Array.isArray(n.models)&&Fx(t,n.models)}function zx(){let[e,t]=(0,Q.useState)({detected:[],providers:{},loading:!0}),n=(0,Q.useContext)($e);return(0,Q.useEffect)(()=>{let e=!0;return fetch(`${Ke}/api/providers/detected`).then(e=>e.ok?e.json():null).then(n=>{!e||!n||(Rx(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`&&(Rx(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 Bx={implement:`factory:implement`,"batch-implement":`factory:batch`,freestyle:`factory:freestyle`},Vx=[{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 Hx(e){return e===`loop`?``:Bx[e]}function Ux(e){return e===`factory:implement`?`implement`:e===`factory:batch`?`batch-implement`:e===`factory:freestyle`?`freestyle`:`loop`}function Wx(e,t){return e||Hx(t)}var Gx=class extends Error{errors;constructor(e){super(`Loop graph is invalid`),this.name=`LoopPublishError`,this.errors=e}},Kx=`/api`;async function qx(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 Gx(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 Jx(e,t,n){return qx(await fetch(`${Kx}${t}`,{method:e,headers:n===void 0?void 0:{"Content-Type":`application/json`},body:n===void 0?void 0:JSON.stringify(n)}))}var Yx={async list(){return(await Jx(`GET`,`/loops`)).loops},async get(e){return(await Jx(`GET`,`/loops/${e}`)).loop},async create(e){return(await Jx(`POST`,`/loops`,e)).loop},async update(e,t){return(await Jx(`PUT`,`/loops/${e}`,t)).loop},async publish(e){return(await Jx(`POST`,`/loops/${e}/publish`)).loop},async unpublish(e){return(await Jx(`POST`,`/loops/${e}/unpublish`)).loop},async duplicate(e,t){return(await Jx(`POST`,`/loops/${e}/duplicate`,t?{name:t}:{})).loop},async remove(e){let t=await fetch(`${Kx}/loops/${e}`,{method:`DELETE`});!t.ok&&t.status!==204&&await qx(t)},async templates(){return(await Jx(`GET`,`/loop-templates`)).templates},async fromTemplate(e,t){return(await Jx(`POST`,`/loops/from-template/${e}`,t?{name:t}:{})).loop},async factoryLoops(){return(await Jx(`GET`,`/loops/factory`)).factoryLoops},async loopCommands(){return(await Jx(`GET`,`/loops/commands`)).commands},async forkFactory(e,t){return(await Jx(`POST`,`/loops/factory/${e}/fork`,t?{name:t}:{})).loop},async loopConstants(){return(await Jx(`GET`,`/loops/constants`)).constants},async createConstant(e,t){return(await Jx(`POST`,`/loops/constants`,{name:e,value:t})).constant},async updateConstant(e,t){return(await Jx(`PUT`,`/loops/constants/${e}`,{value:t})).constant},async deleteConstant(e){await Jx(`DELETE`,`/loops/constants/${e}`)},async importLoops(e){return Jx(`POST`,`/loops/import`,{loops:e})},async previewLoop(e,t){return Jx(`POST`,`/loops/preview`,{graph:e,provider:t})},async runStandalone(e,t,n={}){return qx(await fetch(`/api/projects/${e}/loop-runs`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({loopId:t,...n})}))}},Xx=/\{\{\s*spec\./,Zx=/\{\{\s*cmd:(implement|batch|freestyle)\b/;function Qx(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(Xx.test(e)||Zx.test(e))return!0}return!1}function $x(e,[t,n]){return Math.min(n,Math.max(t,e))}function eS(e){let t=tS(e),n=Q.forwardRef((e,n)=>{let{children:r,...i}=e,a=Q.Children.toArray(r),o=a.find(rS);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 tS(e){let t=Q.forwardRef((e,t)=>{let{children:n,...r}=e;if(Q.isValidElement(n)){let e=aS(n),i=iS(r,n.props);return n.type!==Q.Fragment&&(i.ref=t?$n(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 nS=Symbol(`radix.slottable`);function rS(e){return Q.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===nS}function iS(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 aS(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 oS(e){let t=e+`CollectionProvider`,[n,r]=Ln(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=eS(s),l=Q.forwardRef((e,t)=>{let{scope:n,children:r}=e,i=Fn(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=eS(u),p=Q.forwardRef((e,t)=>{let{scope:n,children:r,...i}=e,o=Q.useRef(null),s=Fn(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 sS=Q.createContext(void 0);function cS(e){let t=Q.useContext(sS);return e||t||`ltr`}var lS=[`top`,`right`,`bottom`,`left`],uS=Math.min,dS=Math.max,fS=Math.round,pS=Math.floor,mS=e=>({x:e,y:e}),hS={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function gS(e,t,n){return dS(e,uS(t,n))}function _S(e,t){return typeof e==`function`?e(t):e}function vS(e){return e.split(`-`)[0]}function yS(e){return e.split(`-`)[1]}function bS(e){return e===`x`?`y`:`x`}function xS(e){return e===`y`?`height`:`width`}function SS(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function CS(e){return bS(SS(e))}function wS(e,t,n){n===void 0&&(n=!1);let r=yS(e),i=CS(e),a=xS(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=NS(o)),[o,NS(o)]}function TS(e){let t=NS(e);return[ES(e),t,ES(t)]}function ES(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var DS=[`left`,`right`],OS=[`right`,`left`],kS=[`top`,`bottom`],AS=[`bottom`,`top`];function jS(e,t,n){switch(e){case`top`:case`bottom`:return n?t?OS:DS:t?DS:OS;case`left`:case`right`:return t?kS:AS;default:return[]}}function MS(e,t,n,r){let i=yS(e),a=jS(vS(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(ES)))),a}function NS(e){let t=vS(e);return hS[t]+e.slice(t.length)}function PS(e){return{top:0,right:0,bottom:0,left:0,...e}}function FS(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:PS(e)}function IS(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 LS(e,t,n){let{reference:r,floating:i}=e,a=SS(t),o=CS(t),s=xS(o),c=vS(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(yS(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 RS(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}=_S(t,e),p=FS(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=IS(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=IS(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,BS=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:RS},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=LS(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}=LS(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},VS=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}=_S(e,t)||{};if(l==null)return{};let d=FS(u),f={x:n,y:r},p=CS(i),m=xS(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=uS(d[_],T),D=uS(d[v],T),O=E,k=C-h[m]-D,A=C/2-h[m]/2+w,j=gS(O,A,k),M=!c.arrow&&yS(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}}}),HS=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}=_S(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=vS(r),_=SS(o),v=vS(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[NS(o)]:TS(o)),x=p!==`none`;!d&&x&&b.push(...MS(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=wS(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`&&_!==SS(t))||T.every(e=>SS(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=SS(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 US(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function WS(e){return lS.some(t=>e[t]>=0)}var GS=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=_S(e,t);switch(i){case`referenceHidden`:{let e=US(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:WS(e)}}}case`escaped`:{let e=US(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:WS(e)}}}default:return{}}}}},KS=new Set([`left`,`top`]);async function qS(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=vS(n),s=yS(n),c=SS(n)===`y`,l=KS.has(o)?-1:1,u=a&&c?-1:1,d=_S(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 JS=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 qS(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}}}}},YS=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}=_S(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=SS(vS(i)),p=bS(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=gS(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=gS(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}}}}}},XS=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}=_S(e,t),u={x:n,y:r},d=SS(i),f=bS(d),p=u[f],m=u[d],h=_S(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=KS.has(vS(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}}}},ZS=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}=_S(e,t),u=await o.detectOverflow(t,l),d=vS(i),f=yS(i),p=SS(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=uS(h-u[g],v),x=uS(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=dS(u.left,0),t=dS(u.right,0),n=dS(u.top,0),r=dS(u.bottom,0);p?w=m-2*(e!==0||t!==0?e+t:dS(u.left,u.right)):C=h-2*(n!==0||r!==0?n+r:dS(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 QS(){return typeof window<`u`}function $S(e){return nC(e)?(e.nodeName||``).toLowerCase():`#document`}function eC(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function tC(e){return((nC(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function nC(e){return QS()?e instanceof Node||e instanceof eC(e).Node:!1}function rC(e){return QS()?e instanceof Element||e instanceof eC(e).Element:!1}function iC(e){return QS()?e instanceof HTMLElement||e instanceof eC(e).HTMLElement:!1}function aC(e){return!QS()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof eC(e).ShadowRoot}function oC(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=_C(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function sC(e){return/^(table|td|th)$/.test($S(e))}function cC(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var lC=/transform|translate|scale|rotate|perspective|filter/,uC=/paint|layout|strict|content/,dC=e=>!!e&&e!==`none`,fC;function pC(e){let t=rC(e)?_C(e):e;return dC(t.transform)||dC(t.translate)||dC(t.scale)||dC(t.rotate)||dC(t.perspective)||!hC()&&(dC(t.backdropFilter)||dC(t.filter))||lC.test(t.willChange||``)||uC.test(t.contain||``)}function mC(e){let t=yC(e);for(;iC(t)&&!gC(t);){if(pC(t))return t;if(cC(t))return null;t=yC(t)}return null}function hC(){return fC??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),fC}function gC(e){return/^(html|body|#document)$/.test($S(e))}function _C(e){return eC(e).getComputedStyle(e)}function vC(e){return rC(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function yC(e){if($S(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||aC(e)&&e.host||tC(e);return aC(t)?t.host:t}function bC(e){let t=yC(e);return gC(t)?e.ownerDocument?e.ownerDocument.body:e.body:iC(t)&&oC(t)?t:bC(t)}function xC(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=bC(e),i=r===e.ownerDocument?.body,a=eC(r);if(i){let e=SC(a);return t.concat(a,a.visualViewport||[],oC(r)?r:[],e&&n?xC(e):[])}else return t.concat(r,xC(r,[],n))}function SC(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function CC(e){let t=_C(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=iC(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=fS(n)!==a||fS(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function wC(e){return rC(e)?e:e.contextElement}function TC(e){let t=wC(e);if(!iC(t))return mS(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=CC(t),o=(a?fS(n.width):n.width)/r,s=(a?fS(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var EC=mS(0);function DC(e){let t=eC(e);return!hC()||!t.visualViewport?EC:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function OC(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==eC(e)?!1:t}function kC(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=wC(e),o=mS(1);t&&(r?rC(r)&&(o=TC(r)):o=TC(e));let s=OC(a,n,r)?DC(a):mS(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=eC(a),t=r&&rC(r)?eC(r):r,n=e,i=SC(n);for(;i&&r&&t!==n;){let e=TC(i),t=i.getBoundingClientRect(),r=_C(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=eC(i),i=SC(n)}}return IS({width:u,height:d,x:c,y:l})}function AC(e,t){let n=vC(e).scrollLeft;return t?t.left+n:kC(tC(e)).left+n}function jC(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-AC(e,n),y:n.top+t.scrollTop}}function MC(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=tC(r),s=t?cC(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=mS(1),u=mS(0),d=iC(r);if((d||!d&&!a)&&(($S(r)!==`body`||oC(o))&&(c=vC(r)),d)){let e=kC(r);l=TC(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?jC(o,c):mS(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 NC(e){return Array.from(e.getClientRects())}function PC(e){let t=tC(e),n=vC(e),r=e.ownerDocument.body,i=dS(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=dS(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+AC(e),s=-n.scrollTop;return _C(r).direction===`rtl`&&(o+=dS(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}var FC=25;function IC(e,t){let n=eC(e),r=tC(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=hC();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=AC(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<=FC&&(a-=o)}else l<=FC&&(a+=l);return{width:a,height:o,x:s,y:c}}function LC(e,t){let n=kC(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=iC(e)?TC(e):mS(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function RC(e,t,n){let r;if(t===`viewport`)r=IC(e,n);else if(t===`document`)r=PC(tC(e));else if(rC(t))r=LC(t,n);else{let n=DC(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return IS(r)}function zC(e,t){let n=yC(e);return n===t||!rC(n)||gC(n)?!1:_C(n).position===`fixed`||zC(n,t)}function BC(e,t){let n=t.get(e);if(n)return n;let r=xC(e,[],!1).filter(e=>rC(e)&&$S(e)!==`body`),i=null,a=_C(e).position===`fixed`,o=a?yC(e):e;for(;rC(o)&&!gC(o);){let t=_C(o),n=pC(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&(i.position===`absolute`||i.position===`fixed`)||oC(o)&&!n&&zC(e,o))?r=r.filter(e=>e!==o):i=t,o=yC(o)}return t.set(e,r),r}function VC(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?cC(t)?[]:BC(t,this._c):[].concat(n),r],o=RC(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=RC(t,a[e],i);s=dS(n.top,s),c=uS(n.right,c),l=uS(n.bottom,l),u=dS(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function HC(e){let{width:t,height:n}=CC(e);return{width:t,height:n}}function UC(e,t,n){let r=iC(t),i=tC(t),a=n===`fixed`,o=kC(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=mS(0);function l(){c.x=AC(i)}if(r||!r&&!a)if(($S(t)!==`body`||oC(i))&&(s=vC(t)),r){let e=kC(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?jC(i,s):mS(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 WC(e){return _C(e).position===`static`}function GC(e,t){if(!iC(e)||_C(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return tC(e)===n&&(n=n.ownerDocument.body),n}function KC(e,t){let n=eC(e);if(cC(e))return n;if(!iC(e)){let t=yC(e);for(;t&&!gC(t);){if(rC(t)&&!WC(t))return t;t=yC(t)}return n}let r=GC(e,t);for(;r&&sC(r)&&WC(r);)r=GC(r,t);return r&&gC(r)&&WC(r)&&!pC(r)?n:r||mC(e)||n}var qC=async function(e){let t=this.getOffsetParent||KC,n=this.getDimensions,r=await n(e.floating);return{reference:UC(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function JC(e){return _C(e).direction===`rtl`}var YC={convertOffsetParentRelativeRectToViewportRelativeRect:MC,getDocumentElement:tC,getClippingRect:VC,getOffsetParent:KC,getElementRects:qC,getClientRects:NC,getDimensions:HC,getScale:TC,isElement:rC,isRTL:JC};function XC(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function ZC(e,t){let n=null,r,i=tC(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=pS(d),h=pS(i.clientWidth-(u+f)),g=pS(i.clientHeight-(d+p)),_=pS(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:dS(0,uS(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&&!XC(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 QC(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=wC(e),u=i||a?[...l?xC(l):[],...t?xC(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?ZC(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?kC(e):null;c&&g();function g(){let t=kC(e);h&&!XC(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 $C=JS,ew=YS,tw=HS,nw=ZS,rw=GS,iw=VS,aw=XS,ow=(e,t,n)=>{let r=new Map,i={platform:YC,...n},a={...i.platform,_c:r};return BS(e,t,{...i,platform:a})},sw=typeof document<`u`?Q.useLayoutEffect:function(){};function cw(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(!cw(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)&&!cw(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function lw(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function uw(e,t){let n=lw(e);return Math.round(t*n)/n}function dw(e){let t=Q.useRef(e);return sw(()=>{t.current=e}),t}function fw(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);cw(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=dw(c),D=dw(i),O=dw(l),k=Q.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};D.current&&(e.platform=D.current),ow(S.current,C.current,e).then(e=>{let t={...e,isPositioned:O.current!==!1};A.current&&!cw(w.current,t)&&(w.current=t,Bb.flushSync(()=>{d(t)}))})},[f,t,n,D,O]);sw(()=>{l===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let A=Q.useRef(!1);sw(()=>(A.current=!0,()=>{A.current=!1}),[]),sw(()=>{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=uw(M.floating,u.x),r=uw(M.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...lw(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 pw=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?{}:iw({element:r.current,padding:i}).fn(n):r?iw({element:r,padding:i}).fn(n):{}}}},mw=(e,t)=>{let n=$C(e);return{name:n.name,fn:n.fn,options:[e,t]}},hw=(e,t)=>{let n=ew(e);return{name:n.name,fn:n.fn,options:[e,t]}},gw=(e,t)=>({fn:aw(e).fn,options:[e,t]}),_w=(e,t)=>{let n=tw(e);return{name:n.name,fn:n.fn,options:[e,t]}},vw=(e,t)=>{let n=nw(e);return{name:n.name,fn:n.fn,options:[e,t]}},yw=(e,t)=>{let n=rw(e);return{name:n.name,fn:n.fn,options:[e,t]}},bw=(e,t)=>{let n=pw(e);return{name:n.name,fn:n.fn,options:[e,t]}},xw=`Arrow`,Sw=Q.forwardRef((e,t)=>{let{children:n,width:r=10,height:i=5,...a}=e;return(0,$.jsx)(In.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`})})});Sw.displayName=xw;var Cw=Sw;function ww(e){let[t,n]=Q.useState(void 0);return Rn(()=>{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 Tw=`Popper`,[Ew,Dw]=Ln(Tw),[Ow,kw]=Ew(Tw),Aw=e=>{let{__scopePopper:t,children:n}=e,[r,i]=Q.useState(null);return(0,$.jsx)(Ow,{scope:t,anchor:r,onAnchorChange:i,children:n})};Aw.displayName=Tw;var jw=`PopperAnchor`,Mw=Q.forwardRef((e,t)=>{let{__scopePopper:n,virtualRef:r,...i}=e,a=kw(jw,n),o=Q.useRef(null),s=Fn(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)(In.div,{...i,ref:s})});Mw.displayName=jw;var Nw=`PopperContent`,[Pw,Fw]=Ew(Nw),Iw=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=kw(Nw,n),[_,v]=Q.useState(null),y=Fn(t,e=>v(e)),[b,x]=Q.useState(null),S=ww(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(Bw),altBoundary:O},{refs:A,floatingStyles:j,placement:M,isPositioned:N,middlewareData:P}=fw({strategy:`fixed`,placement:T,whileElementsMounted:(...e)=>QC(...e,{animationFrame:p===`always`}),elements:{reference:g.anchor},middleware:[mw({mainAxis:i+w,alignmentAxis:o}),c&&hw({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?gw():void 0,...k}),c&&_w({...k}),vw({...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&&bw({element:b,padding:s}),Vw({arrowWidth:C,arrowHeight:w}),f&&yw({strategy:`referenceHidden`,...k})]}),[F,I]=Hw(M),L=Vn(m);Rn(()=>{N&&L?.()},[N,L]);let ee=P.arrow?.x,R=P.arrow?.y,z=P.arrow?.centerOffset!==0,[B,V]=Q.useState();return Rn(()=>{_&&V(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:B,"--radix-popper-transform-origin":[P.transformOrigin?.x,P.transformOrigin?.y].join(` `),...P.hide?.referenceHidden&&{visibility:`hidden`,pointerEvents:`none`}},dir:e.dir,children:(0,$.jsx)(Pw,{scope:n,placedSide:F,onArrowChange:x,arrowX:ee,arrowY:R,shouldHideArrow:z,children:(0,$.jsx)(In.div,{"data-side":F,"data-align":I,...h,ref:y,style:{...h.style,animation:N?void 0:`none`}})})})});Iw.displayName=Nw;var Lw=`PopperArrow`,Rw={top:`bottom`,right:`left`,bottom:`top`,left:`right`},zw=Q.forwardRef(function(e,t){let{__scopePopper:n,...r}=e,i=Fw(Lw,n),a=Rw[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)(Cw,{...r,ref:t,style:{...r.style,display:`block`}})})});zw.displayName=Lw;function Bw(e){return e!==null}var Vw=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]=Hw(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 Hw(e){let[t,n=`center`]=e.split(`-`);return[t,n]}var Uw=Aw,Ww=Mw,Gw=Iw,Kw=zw;function qw(e){let t=Jw(e),n=Q.forwardRef((e,n)=>{let{children:r,...i}=e,a=Q.Children.toArray(r),o=a.find(Xw);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 Jw(e){let t=Q.forwardRef((e,t)=>{let{children:n,...r}=e;if(Q.isValidElement(n)){let e=Qw(n),i=Zw(r,n.props);return n.type!==Q.Fragment&&(i.ref=t?$n(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 Yw=Symbol(`radix.slottable`);function Xw(e){return Q.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===Yw}function Zw(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 Qw(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 $w(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 eT=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`}),tT=`VisuallyHidden`,nT=Q.forwardRef((e,t)=>(0,$.jsx)(In.span,{...e,ref:t,style:{...eT,...e.style}}));nT.displayName=tT;var rT=nT,iT=[` `,`Enter`,`ArrowUp`,`ArrowDown`],aT=[` `,`Enter`],oT=`Select`,[sT,cT,lT]=oS(oT),[uT,dT]=Ln(oT,[lT,Dw]),fT=Dw(),[pT,mT]=uT(oT),[hT,gT]=uT(oT),_T=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=fT(t),[g,_]=Q.useState(null),[v,y]=Q.useState(null),[b,x]=Q.useState(!1),S=cS(l),[C,w]=ur({prop:r,defaultProp:i??!1,onChange:a,caller:oT}),[T,E]=ur({prop:o,defaultProp:s,onChange:c,caller:oT}),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)(Uw,{...h,children:(0,$.jsxs)(pT,{required:p,scope:t,trigger:g,onTriggerChange:_,valueNode:v,onValueNodeChange:y,valueNodeHasChildren:b,onValueNodeHasChildrenChange:x,contentId:Hn(),value:T,onValueChange:E,open:C,onOpenChange:w,dir:S,triggerPointerDownPosRef:D,disabled:f,children:[(0,$.jsx)(sT.Provider,{scope:t,children:(0,$.jsx)(hT,{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)(fE,{"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]})})};_T.displayName=oT;var vT=`SelectTrigger`,yT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,disabled:r=!1,...i}=e,a=fT(n),o=mT(vT,n),s=o.disabled||r,c=Fn(t,o.onTriggerChange),l=cT(n),u=Q.useRef(`touch`),[d,f,p]=mE(e=>{let t=l().filter(e=>!e.disabled),n=hE(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)(Ww,{asChild:!0,...a,children:(0,$.jsx)(In.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":pE(o.value)?``:void 0,...i,ref:c,onClick:Bn(i.onClick,e=>{e.currentTarget.focus(),u.current!==`mouse`&&m(e)}),onPointerDown:Bn(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:Bn(i.onKeyDown,e=>{let t=d.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&f(e.key),!(t&&e.key===` `)&&iT.includes(e.key)&&(m(),e.preventDefault())})})})});yT.displayName=vT;var bT=`SelectValue`,xT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,children:a,placeholder:o=``,...s}=e,c=mT(bT,n),{onValueNodeHasChildrenChange:l}=c,u=a!==void 0,d=Fn(t,c.onValueNodeChange);return Rn(()=>{l(u)},[l,u]),(0,$.jsx)(In.span,{...s,ref:d,style:{pointerEvents:`none`},children:pE(c.value)?(0,$.jsx)($.Fragment,{children:o}):a})});xT.displayName=bT;var ST=`SelectIcon`,CT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,children:r,...i}=e;return(0,$.jsx)(In.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})});CT.displayName=ST;var wT=`SelectPortal`,TT=e=>(0,$.jsx)(fr,{asChild:!0,...e});TT.displayName=wT;var ET=`SelectContent`,DT=Q.forwardRef((e,t)=>{let n=mT(ET,e.__scopeSelect),[r,i]=Q.useState();if(Rn(()=>{i(new DocumentFragment)},[]),!n.open){let t=r;return t?Bb.createPortal((0,$.jsx)(kT,{scope:e.__scopeSelect,children:(0,$.jsx)(sT.Slot,{scope:e.__scopeSelect,children:(0,$.jsx)(`div`,{children:e.children})})}),t):null}return(0,$.jsx)(NT,{...e,ref:t})});DT.displayName=ET;var OT=10,[kT,AT]=uT(ET),jT=`SelectContentImpl`,MT=qw(`SelectContent.RemoveScroll`),NT=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=mT(ET,n),[y,b]=Q.useState(null),[x,S]=Q.useState(null),C=Fn(t,e=>b(e)),[w,T]=Q.useState(null),[E,D]=Q.useState(null),O=cT(n),[k,A]=Q.useState(!1),j=Q.useRef(!1);Q.useEffect(()=>{if(y)return Xn(y)},[y]),Un();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]=mE(e=>{let t=O().filter(e=>!e.disabled),n=hE(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current.focus())}),ee=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]),R=Q.useCallback(()=>y?.focus(),[y]),z=Q.useCallback((e,t,n)=>{let r=!j.current&&!n;(v.value!==void 0&&v.value===t||r)&&D(e)},[v.value]),B=r===`popper`?LT:FT,V=B===LT?{side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g}:{};return(0,$.jsx)(kT,{scope:n,content:y,viewport:x,onViewportChange:S,itemRefCallback:ee,selectedItem:w,onItemLeave:R,itemTextRefCallback:z,focusSelectedItem:N,selectedItemText:E,position:r,isPositioned:k,searchRef:I,children:(0,$.jsx)(Yn,{as:MT,allowPinchZoom:!0,children:(0,$.jsx)(Gn,{asChild:!0,trapped:v.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:Bn(i,e=>{v.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,$.jsx)(dr,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>v.onOpenChange(!1),children:(0,$.jsx)(B,{role:`listbox`,id:v.contentId,"data-state":v.open?`open`:`closed`,dir:v.dir,onContextMenu:e=>e.preventDefault(),..._,...V,onPlaced:()=>A(!0),ref:C,style:{display:`flex`,flexDirection:`column`,outline:`none`,..._.style},onKeyDown:Bn(_.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()}})})})})})})});NT.displayName=jT;var PT=`SelectItemAlignedPosition`,FT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,onPlaced:r,...i}=e,a=mT(ET,n),o=AT(ET,n),[s,c]=Q.useState(null),[l,u]=Q.useState(null),d=Fn(t,e=>u(e)),f=cT(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-OT,d=$x(a,[OT,Math.max(OT,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-OT,d=$x(a,[OT,Math.max(OT,u-l)]);s.style.minWidth=c+`px`,s.style.right=d+`px`}let o=f(),c=window.innerHeight-OT*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-OT,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=`${OT}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]);Rn(()=>y(),[y]);let[b,x]=Q.useState();return Rn(()=>{l&&x(window.getComputedStyle(l).zIndex)},[l]),(0,$.jsx)(RT,{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)(In.div,{...i,ref:d,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})});FT.displayName=PT;var IT=`SelectPopperPosition`,LT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,align:r=`start`,collisionPadding:i=OT,...a}=e,o=fT(n);return(0,$.jsx)(Gw,{...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)`}})});LT.displayName=IT;var[RT,zT]=uT(ET,{}),BT=`SelectViewport`,VT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,nonce:r,...i}=e,a=AT(BT,n),o=zT(BT,n),s=Fn(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)(sT.Slot,{scope:n,children:(0,$.jsx)(In.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:s,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:Bn(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-OT*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})})})]})});VT.displayName=BT;var HT=`SelectGroup`,[UT,WT]=uT(HT),GT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=Hn();return(0,$.jsx)(UT,{scope:n,id:i,children:(0,$.jsx)(In.div,{role:`group`,"aria-labelledby":i,...r,ref:t})})});GT.displayName=HT;var KT=`SelectLabel`,qT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=WT(KT,n);return(0,$.jsx)(In.div,{id:i.id,...r,ref:t})});qT.displayName=KT;var JT=`SelectItem`,[YT,XT]=uT(JT),ZT=Q.forwardRef((e,t)=>{let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...o}=e,s=mT(JT,n),c=AT(JT,n),l=s.value===r,[u,d]=Q.useState(a??``),[f,p]=Q.useState(!1),m=Fn(t,e=>c.itemRefCallback?.(e,r,i)),h=Hn(),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)(YT,{scope:n,value:r,disabled:i,textId:h,isSelected:l,onItemTextChange:Q.useCallback(e=>{d(t=>t||(e?.textContent??``).trim())},[]),children:(0,$.jsx)(sT.ItemSlot,{scope:n,value:r,disabled:i,textValue:u,children:(0,$.jsx)(In.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:Bn(o.onFocus,()=>p(!0)),onBlur:Bn(o.onBlur,()=>p(!1)),onClick:Bn(o.onClick,()=>{g.current!==`mouse`&&_()}),onPointerUp:Bn(o.onPointerUp,()=>{g.current===`mouse`&&_()}),onPointerDown:Bn(o.onPointerDown,e=>{g.current=e.pointerType}),onPointerMove:Bn(o.onPointerMove,e=>{g.current=e.pointerType,i?c.onItemLeave?.():g.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:Bn(o.onPointerLeave,e=>{e.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:Bn(o.onKeyDown,e=>{c.searchRef?.current!==``&&e.key===` `||(aT.includes(e.key)&&_(),e.key===` `&&e.preventDefault())})})})})});ZT.displayName=JT;var QT=`SelectItemText`,$T=Q.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,...a}=e,o=mT(QT,n),s=AT(QT,n),c=XT(QT,n),l=gT(QT,n),[u,d]=Q.useState(null),f=Fn(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 Rn(()=>(h(m),()=>g(m)),[h,g,m]),(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(In.span,{id:c.textId,...a,ref:f}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren?Bb.createPortal(a.children,o.valueNode):null]})});$T.displayName=QT;var eE=`SelectItemIndicator`,tE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return XT(eE,n).isSelected?(0,$.jsx)(In.span,{"aria-hidden":!0,...r,ref:t}):null});tE.displayName=eE;var nE=`SelectScrollUpButton`,rE=Q.forwardRef((e,t)=>{let n=AT(nE,e.__scopeSelect),r=zT(nE,e.__scopeSelect),[i,a]=Q.useState(!1),o=Fn(t,r.onScrollButtonChange);return Rn(()=>{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)(oE,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null});rE.displayName=nE;var iE=`SelectScrollDownButton`,aE=Q.forwardRef((e,t)=>{let n=AT(iE,e.__scopeSelect),r=zT(iE,e.__scopeSelect),[i,a]=Q.useState(!1),o=Fn(t,r.onScrollButtonChange);return Rn(()=>{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)(oE,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null});aE.displayName=iE;var oE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,onAutoScroll:r,...i}=e,a=AT(`SelectScrollButton`,n),o=Q.useRef(null),s=cT(n),c=Q.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return Q.useEffect(()=>()=>c(),[c]),Rn(()=>{s().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[s]),(0,$.jsx)(In.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:Bn(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:Bn(i.onPointerMove,()=>{a.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:Bn(i.onPointerLeave,()=>{c()})})}),sE=`SelectSeparator`,cE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return(0,$.jsx)(In.div,{"aria-hidden":!0,...r,ref:t})});cE.displayName=sE;var lE=`SelectArrow`,uE=Q.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=fT(n),a=mT(lE,n),o=AT(lE,n);return a.open&&o.position===`popper`?(0,$.jsx)(Kw,{...i,...r,ref:t}):null});uE.displayName=lE;var dE=`SelectBubbleInput`,fE=Q.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{let i=Q.useRef(null),a=Fn(r,i),o=$w(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)(In.select,{...n,style:{...eT,...n.style},ref:a,defaultValue:t})});fE.displayName=dE;function pE(e){return e===``||e===void 0}function mE(e){let t=Vn(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 hE(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=gE(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 gE(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var _E=_T,vE=yT,yE=xT,bE=CT,xE=TT,SE=DT,CE=VT,wE=qT,TE=ZT,EE=$T,DE=tE,OE=rE,kE=aE,AE=cE,jE=`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`,ME=`overflow-hidden rounded-xl border border-border/60 bg-card/95 shadow-2xl backdrop-blur-xl`,NE=`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 PE({label:e,value:t,options:n,icon:r,onSelect:i,placeholder:a,disabled:o=!1,testId:s}){return(0,$.jsxs)(_E,{value:t,onValueChange:i,disabled:o||n.length===0,children:[(0,$.jsxs)(vE,{"aria-label":e,title:e,"data-agent-interactive":!0,"data-testid":s,className:jE,children:[(0,$.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-accent-primary`,"aria-hidden":!0}),(0,$.jsx)(yE,{placeholder:a??e,className:`max-w-[160px] truncate`}),(0,$.jsx)(bE,{asChild:!0,children:(0,$.jsx)(Wo,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`})})]}),(0,$.jsx)(xE,{children:(0,$.jsxs)(SE,{position:`popper`,side:`top`,align:`start`,sideOffset:4,collisionPadding:8,className:`z-[80] min-w-[12rem] max-w-[20rem] ${ME} 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)(OE,{className:`flex items-center justify-center py-1 text-foreground/50`,children:(0,$.jsx)(fn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(CE,{className:`max-h-72 py-1`,children:n.map(e=>{let t=e.icon??r;return(0,$.jsxs)(TE,{value:e.value,className:`${NE} 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)(EE,{children:(0,$.jsx)(`span`,{className:`truncate`,children:e.label})}),(0,$.jsx)(DE,{className:`absolute right-3 flex items-center`,children:(0,$.jsx)(vn,{className:`h-3.5 w-3.5 text-accent-primary`})})]},e.value)})}),(0,$.jsx)(kE,{className:`flex items-center justify-center py-1 text-foreground/50`,children:(0,$.jsx)(Wo,{className:`h-3.5 w-3.5`})})]})})]})}var FE=`__new__`,IE=`__legacy__`,LE=`__default__`,RE=12,zE=`specrails:focus-pr-card`,BE=(0,Q.lazy)(()=>c(()=>import(`./JobDetailModal-BnO_V8KR.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])));function VE(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 HE(e,t){let n=e(`railCard.rail`,{index:t.railIndex+1});return t.name?`${n} · ${t.name}`:n}function UE({proposal:e,proposalIndex:t,messageId:n,conversationId:r,projectId:i,intent:a,compact:o=!1}){let{t:s}=K(`agent`),c=Ay(),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=`${Ke}/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)}),Ce&&Yx.list().then(t=>{e||_(t.filter(e=>e.status===`published`&&Qx(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??Wx(null,e.mode),aiEngine:e.aiEngine,model:e.model,reasoningEffort:e.reasoningEffort,profileName:e.profileName,targetPrNumber:e.targetPrNumber,baseBranch:e.baseBranch??``})),S=(0,Q.useCallback)(e=>x(t=>({...t,...e})),[]),C=l.detected,w=!l.loading,T=(0,Q.useMemo)(()=>b.aiEngine&&(bt(b.aiEngine)||C.includes(b.aiEngine))?b.aiEngine:C[0]??null,[b.aiEngine,C]),E=!!b.aiEngine&&w&&T!==b.aiEngine,D=!!T&&bt(T),O=T&&!bt(T)?T:C[0]??null,k=(0,Q.useMemo)(()=>Ix(O),[O]),A=(0,Q.useMemo)(()=>b.model&&k.some(e=>e.value===b.model)?b.model:Lx(O)||null,[b.model,k,O]),j=!!b.model&&k.length>0&&A!==b.model,M=(0,Q.useMemo)(()=>mt(O,A),[O,A]),N=b.reasoningEffort&&M.includes(b.reasoningEffort)?b.reasoningEffort:null,P=Ux(b.loopId),F=!D&&P!==`loop`&&_t(O);(0,Q.useEffect)(()=>{if(!i||a||!O||!F){h([]);return}let e=!1;return fetch(`${Ke}/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,F]);let I=b.profileName&&m.some(e=>e.name===b.profileName)?b.profileName:null,L=(0,Q.useMemo)(()=>u?.rails??[],[u]),ee=(0,Q.useMemo)(()=>{let e=new Map;if(!u)return e;for(let t of L)e.set(t.railIndex,VE(t,u,f??[]));return e},[L,u,f]),z=b.railIndex===null?void 0:L.find(e=>e.railIndex===b.railIndex),B=u!==null&&b.railIndex!==null&&!b.newRail&&!z,V=!!z&&!b.newRail&&ee.get(z.railIndex)!==`free`&&ee.get(z.railIndex)!==void 0,H=L.length>=RE,U=L.find(e=>ee.get(e.railIndex)===`free`),te=b.newRail?FE:b.railIndex!==null&&z?String(b.railIndex):U?String(U.railIndex):H?``:FE,ne=b.newRail||te===FE||te===``?null:Number(te),re=te===FE,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)(()=>(f??[]).filter(e=>(e.status===`todo`||e.status===`draft`)&&!b.ticketIds.includes(e.id)),[f,b.ticketIds]),ce=!D&&gt(O),le=(0,Q.useMemo)(()=>[...Vx.filter(e=>(!e.requiresFreestyle||ce)&&(!e.requiresLoops||Ce)).map(e=>({value:e.id,label:s(`dashboard:${e.labelKey}`)})),...g.map(e=>({value:e.id,label:e.name}))],[g,ce,s]),ue=le.some(e=>e.value===b.loopId)?b.loopId:le[0]?.value??b.loopId,[de,fe]=(0,Q.useState)(null),[pe,me]=(0,Q.useState)(null),[he,W]=(0,Q.useState)(null),ge=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>()=>{ge.current=!1},[]);let _e=a??he,ve=i?v?s(`railCard.block.loadFailed`):ae.length===0?s(`railCard.block.noSpecs`):te===``?s(`railCard.block.railLimit`,{max:RE}):null:s(`railCard.block.noProject`),ye=(0,Q.useCallback)(async e=>{let t=await To(r,n,e),i=t.ok?t.intent:{...e,at:new Date().toISOString()};kx(n,i),ge.current&&W(i)},[r,n]),be=(0,Q.useCallback)(async()=>{if(!i||ve||de)return;fe(`launch`),me(null);let e=`${Ke}/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){me(await a(t));return}let r=await t.json();if(typeof r.rail?.railIndex!=`number`){me({error:`invalid_response`});return}o=r.rail.railIndex}else if(s&&s!==(z?.name??``)){let t=await fetch(`${e}/${o}/name`,{method:`PUT`,headers:n,body:JSON.stringify({name:s})});if(!t.ok){me(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:P,profileName:F?I:null,...c?{aiEngine:c}:{}})});if(!l.ok){me(await a(l));return}let u={mode:P,loopId:ue,originConversationId:r,originSurface:`agent-chat`,...c?{aiEngine:c}:{},...!D&&A?{model:A}:{},...!D&&N?{reasoning_effort:N}:{},...F&&I?{profileName:I}:{},...b.targetPrNumber?{targetPrNumber:b.targetPrNumber}:{},...b.baseBranch.trim()?{baseBranch:b.baseBranch.trim()}:{}},d=await fetch(`${e}/${o}/launch`,{method:`POST`,headers:n,body:JSON.stringify(u)});if(!d.ok){me(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]:[];Rt(i),await ye({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){me({error:e instanceof Error?e.message:`network`})}finally{ge.current&&fe(null)}},[i,ve,de,ne,b,z,T,D,C.length,ae,P,F,I,ue,A,N,r,t,ye]),xe=(0,Q.useCallback)(async()=>{if(!de){fe(`dismiss`);try{await ye({kind:`rail-launch`,proposalIndex:t,status:`dismissed`})}finally{ge.current&&fe(null)}}},[de,ye,t]),[Se,G]=(0,Q.useState)(null);if(_e){let t=_e.status===`launched`,n=_e.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)(qo,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`}):(0,$.jsx)(Mo,{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 _e.railIndex==`number`?_e.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:_e.prDeliveryId??null,runIds:_e.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)(nc,{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:()=>G(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)(ln,{className:`h-3 w-3`}),s(`railCard.stub.viewRun`)]}),Se&&i&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(BE,{jobId:Se,projectId:i,onClose:()=>G(null)})})]})}let we=[...L.map(e=>{let t=ee.get(e.railIndex),n=t&&t!==`free`?` · ${s(`railCard.availability.${t}`)}`:``;return{value:String(e.railIndex),label:`${HE(s,e)}${n}`}}),...H?[]:[{value:FE,label:s(`railCard.newRail`),icon:Dn}]],Te=[...C.map(e=>({value:e,label:l.providers[e]?.displayName??Dt(e)})),...C.length>1?[{value:Ot,label:s(`agents:railSelectors.rolesEngine`),icon:Is}]:[]],Ee=k.map(e=>({value:e.value,label:e.label??e.value})),De=[{value:LE,label:s(`railCard.effortDefault`)},...M.map(e=>({value:e,label:s(`effort.${e}`,{defaultValue:e})}))],Oe=[{value:IE,label:s(`railCard.profileNone`)},...m.map(e=>({value:e.name,label:e.name}))],ke=!!i&&!v&&(u===null||f===null),Ae=ke?{tone:`border-border/60 bg-surface/60 text-foreground/50`,label:s(`railCard.status.loading`)}:ve?{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)(jy.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)(fc,{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`,Ae.tone),children:Ae.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)(kn,{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)(PE,{label:s(`railCard.fields.rail`),icon:Ac,value:te,options:we,disabled:ke||!!de,testId:`rail-card-rail`,onSelect:e=>S(e===FE?{newRail:!0,railIndex:null}:{newRail:!1,railIndex:Number(e)})}),(re||z)&&(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`})]}),B&&(0,$.jsx)(WE,{tone:`warning`,text:s(`railCard.notes.railMissing`,{index:(b.railIndex??0)+1})}),V&&z&&(0,$.jsx)(WE,{tone:`warning`,text:s(`railCard.notes.railBusy`,{index:z.railIndex+1,state:s(`railCard.availability.${ee.get(z.railIndex)??`busy`}`)}),action:U?{label:s(`railCard.notes.useFree`,{index:U.railIndex+1}),onClick:()=>S({newRail:!1,railIndex:U.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:!!de,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)(Nn,{className:`h-3 w-3`})})]},e)}),se.length>0&&(0,$.jsx)(PE,{label:s(`railCard.fields.addSpec`),icon:Dn,value:``,placeholder:s(`railCard.fields.addSpec`),options:se.slice(0,40).map(e=>({value:String(e.id),label:`#${e.id} ${e.title}`})),disabled:!!de,testId:`rail-card-add-spec`,onSelect:e=>S({ticketIds:[...b.ticketIds,Number(e)]})})]}),oe.length>0&&(0,$.jsx)(WE,{tone:`muted`,text:s(`railCard.notes.specsDropped`,{ids:oe.map(e=>`#${e}`).join(`, `)})}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-1 gap-y-1`,children:[(0,$.jsx)(PE,{label:s(`railCard.fields.loop`),icon:Fc,value:ue,options:le,disabled:!!de,testId:`rail-card-loop`,onSelect:e=>S({loopId:e})}),Te.length>1&&(0,$.jsx)(PE,{label:s(`railCard.fields.engine`),icon:ss,value:T??``,options:Te,disabled:!!de,testId:`rail-card-engine`,onSelect:e=>S({aiEngine:e,model:null,reasoningEffort:null,profileName:null})}),!D&&Ee.length>0&&(0,$.jsx)(PE,{label:s(`railCard.fields.model`),icon:Lo,value:A??``,options:Ee,disabled:!!de,testId:`rail-card-model`,onSelect:e=>S({model:e})}),!D&&M.length>0&&(0,$.jsx)(PE,{label:s(`railCard.fields.effort`),icon:Ss,value:N??LE,options:De,disabled:!!de,testId:`rail-card-effort`,onSelect:e=>S({reasoningEffort:e===LE?null:e})}),F&&m.length>0&&(0,$.jsx)(PE,{label:s(`railCard.fields.profile`),icon:jc,value:I??IE,options:Oe,disabled:!!de,testId:`rail-card-profile`,onSelect:e=>S({profileName:e===IE?null:e})})]}),E&&(0,$.jsx)(WE,{tone:`muted`,text:s(`railCard.notes.engineStale`,{engine:b.aiEngine,fallback:T?Dt(T):``})}),j&&(0,$.jsx)(WE,{tone:`muted`,text:s(`railCard.notes.modelStale`,{model:b.model,fallback:A})}),(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)(R,{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:!!de,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)(Sn,{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:!!de,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`})]})]}),pe&&(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)(jn,{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.${pe.error}`,{defaultValue:pe.error})}),pe.detail&&(0,$.jsx)(`div`,{className:`text-destructive/80`,children:pe.detail}),pe.action&&(0,$.jsx)(`div`,{className:`text-foreground/70`,children:pe.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:ve??s(`railCard.playHint`)}),(0,$.jsx)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`rail-card-dismiss`,disabled:!!de,onClick:()=>void xe(),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:!!de||ke||!!ve,onClick:()=>void be(),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:[de===`launch`?(0,$.jsx)(Cn,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Tn,{className:`h-3.5 w-3.5`}),s(de===`launch`?`railCard.launching`:`railCard.play`)]})]})]})]})}function WE({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)(jn,{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 GE(){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)(Cn,{className:`h-3 w-3 animate-spin`}),e(`railCard.pending`)]})}function KE({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)(jn,{className:`h-3 w-3 shrink-0 text-accent-warning/80`}),t(`railCard.unreadable`,{count:e.length})]})}var qE=/```problem-frame[^\S\n]*\n([\s\S]*?)\n[^\S\n]*```/g,JE="```problem-frame";function YE(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function XE(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:YE(t.touches)}}function ZE(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=XE(n.restated),i=XE(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:YE(n.assumptions),unknowns:YE(n.unknowns)}}function QE(e){return e.replace(/\n{3,}/g,`
35
35
 
36
36
  `).trim()}function $E(e,t=!1){if(!e.includes(JE))return{body:e,frame:null,pending:!1};let n=null,r=``,i=0;qE.lastIndex=0;let a;for(;(a=qE.exec(e))!==null;){r+=e.slice(i,a.index),i=a.index+a[0].length;let t=ZE(a[1]);t&&(n=t)}r+=e.slice(i);let o=!1,s=r.indexOf(JE);if(s!==-1){let e=ZE(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:QE(r),frame:n,pending:o}}var eD=`flex min-w-0 flex-col gap-1.5 rounded-lg border border-border/50 bg-surface/50 p-2.5 text-left`;function tD({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)(ms,{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(eD,`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)(as,{className:`h-2.5 w-2.5`}),a(`problemFrame.pick`)]})]}):(0,$.jsx)(`div`,{"data-testid":n,className:eD,children:o})}function nD({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 rD({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)(ns,{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)(tD,{label:i(`problemFrame.restated`),value:e.restated,testId:`agent-problem-frame-reading-restated`,onSelect:o,disabled:n}),(0,$.jsx)(tD,{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)(Yo,{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)(nD,{label:i(`problemFrame.assumptions`),items:e.assumptions}),(0,$.jsx)(nD,{label:i(`problemFrame.unknowns`),items:e.unknowns})]})]})]})}function iD(){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)(ns,{className:`h-3 w-3 animate-pulse`}),e(`problemFrame.framing`)]})}var aD=`#agentref:`;function oD(e){return e.kind===`ticket`?`${aD}ticket:${e.ticketId}`:e.kind===`pull-request`?`${aD}pr:${e.prNumber}${e.prUrl?`:${encodeURIComponent(e.prUrl)}`:``}`:e.kind===`loop`?`${aD}loop:${e.loopId}`:`${aD}job:${e.jobId}`}function sD(e){if(!e||!e.startsWith(aD))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 lD.test(e)?{kind:`job`,jobId:e}:null}if(t.startsWith(`loop:`)){let e=t.slice(5);return dD.test(e)||lD.test(e)?{kind:`loop`,loopId:e}:null}return null}var cD=`[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}`,lD=RegExp(`^${cD}$`),uD=`factory:(?:implement|batch|freestyle)`,dD=RegExp(`^${uD}$`),fD=/\b(jobs?|runs?|loops?|rails?|ejecuci[oó]n(?:es)?|trabajos?|bucles?)\b|(?:loop|job|run)[a-z]*id/i;function pD(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 ik(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 ak(e,t){let n=e.ownerDocument.getSelection();if(!n?.anchorNode||!n.focusNode||!e.contains(n.anchorNode)||!e.contains(n.focusNode))return null;let r=ik(t,n.anchorNode,n.anchorOffset),i=ik(t,n.focusNode,n.focusOffset);return[Math.min(r,i),Math.max(r,i)]}function ok(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(nk)?[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 sk(e,t,n,r){let[i,a]=ok(e,t,n),[o,s]=ok(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 ck(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 lk(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 uk(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 dk(e,t,n,r,i){let a=e.createDocumentFragment(),o=0;for(let s of n){a.append(e.createTextNode(`${o>0?nk:``}${t.slice(o,s.start)}${nk}`));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 ${uk(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?nk:``}${t.slice(o)}`)),a}var fk=(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:ck(e.value,e.references),selection:[e.value.length,e.value.length]}],index:0,typing:null}),p=()=>rk(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&&lk(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(dk(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&&(sk(s,p(),...o),m(ak(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=ak(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=ak(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&&(sk(r.current,p(),e,t),m(ak(r.current,p())??[e,t]))},get selectionStart(){return r.current?(ak(r.current,p())??c.current)[0]:0},get selectionEnd(){return r.current?(ak(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=ck(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=ak(t,i)??c.current;i.value===e.value&&lk(i.references,n)&&lk(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(ak(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(),sk(t,n,a.start,a.end),x(``,`deleteAtomic`))},C=(e,t)=>{let n=r.current;if(!n)return;let a=p(),o=ak(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||!lk(e.references,t.references))){let e=ck(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(ak(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=ak(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)})}),pk=Symbol(`radix.slottable`);function mk(e){let t=({children:e})=>(0,$.jsx)($.Fragment,{children:e});return t.displayName=`${e}.Slottable`,t.__radixId=pk,t}var[hk,gk]=Ln(`Tooltip`,[Dw]),_k=Dw(),vk=`TooltipProvider`,yk=700,bk=`tooltip.open`,[xk,Sk]=hk(vk),Ck=e=>{let{__scopeTooltip:t,delayDuration:n=yk,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)(xk,{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})};Ck.displayName=vk;var wk=`Tooltip`,[Tk,Ek]=hk(wk),Dk=e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=Sk(wk,e.__scopeTooltip),l=_k(t),[u,d]=Q.useState(null),f=Hn(),p=Q.useRef(0),m=o??c.disableHoverableContent,h=s??c.delayDuration,g=Q.useRef(!1),[_,v]=ur({prop:r,defaultProp:i??!1,onChange:e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(bk))):c.onClose(),a?.(e)},caller:wk}),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)(Uw,{...l,children:(0,$.jsx)(Tk,{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})})};Dk.displayName=wk;var Ok=`TooltipTrigger`,kk=Q.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Ek(Ok,n),a=Sk(Ok,n),o=_k(n),s=Fn(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)(Ww,{asChild:!0,...o,children:(0,$.jsx)(In.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:Bn(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:Bn(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:Bn(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:Bn(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:Bn(e.onBlur,i.onClose),onClick:Bn(e.onClick,i.onClose)})})});kk.displayName=Ok;var Ak=`TooltipPortal`,[jk,Mk]=hk(Ak,{forceMount:void 0}),Nk=e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=Ek(Ak,t);return(0,$.jsx)(jk,{scope:t,forceMount:n,children:(0,$.jsx)(lr,{present:n||a.open,children:(0,$.jsx)(fr,{asChild:!0,container:i,children:r})})})};Nk.displayName=Ak;var Pk=`TooltipContent`,Fk=Q.forwardRef((e,t)=>{let n=Mk(Pk,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=Ek(Pk,e.__scopeTooltip);return(0,$.jsx)(lr,{present:r||o.open,children:o.disableHoverableContent?(0,$.jsx)(Bk,{side:i,...a,ref:t}):(0,$.jsx)(Ik,{side:i,...a,ref:t})})}),Ik=Q.forwardRef((e,t)=>{let n=Ek(Pk,e.__scopeTooltip),r=Sk(Pk,e.__scopeTooltip),i=Q.useRef(null),a=Fn(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=Wk(r,Uk(r,n.getBoundingClientRect())),a=Gk(t.getBoundingClientRect()),o=qk([...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=!Kk(n,o);r?f():i&&(f(),l())};return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,$.jsx)(Bk,{...e,ref:a})}),[Lk,Rk]=hk(wk,{isInside:!1}),zk=mk(`TooltipContent`),Bk=Q.forwardRef((e,t)=>{let{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:a,onPointerDownOutside:o,...s}=e,c=Ek(Pk,n),l=_k(n),{onClose:u}=c;return Q.useEffect(()=>(document.addEventListener(bk,u),()=>document.removeEventListener(bk,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)(dr,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:u,children:(0,$.jsxs)(Gw,{"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)(Lk,{scope:n,isInside:!0,children:(0,$.jsx)(rT,{id:c.contentId,role:`tooltip`,children:i||r})})]})})});Fk.displayName=Pk;var Vk=`TooltipArrow`,Hk=Q.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=_k(n);return Rk(Vk,n).isInside?null:(0,$.jsx)(Kw,{...i,...r,ref:t})});Hk.displayName=Vk;function Uk(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 Wk(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 Gk(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 Kk(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 qk(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)),Jk(t)}function Jk(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 Yk=Ck,Xk=Dk,Zk=kk,Qk=Fk,$k=Yk,eA=Xk,tA=Zk,nA=Q.forwardRef(({className:e,sideOffset:t=4,...n},r)=>(0,$.jsx)(Qk,{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}));nA.displayName=Qk.displayName;var rA={"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 iA({process:e,accentVariant:t,onKill:n,onOpen:r}){let{t:i}=K(`agent`),a=oA(e),o=aA(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)($k,{delayDuration:150,children:(0,$.jsxs)(`span`,{"data-testid":`background-process-chip`,className:`inline-flex max-w-full items-center rounded-lg border text-[11px] ${rA[t]}`,children:[(0,$.jsxs)(eA,{children:[(0,$.jsx)(tA,{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)(Oc,{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)(nA,{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)(Ko,{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)(Cn,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Nn,{className:`h-3 w-3`,"aria-hidden":!0})})]})})}function aA(e){return e.status===`exited`||e.status===`failed`||e.status===`killed`||e.status===`interrupted`}function oA(e){let[t,n]=(0,Q.useState)(Date.now()),r=aA(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]),xr(Math.max(0,(e.endedAt??e.recoveredAt??t)-e.startedAt))}var sA=2e3,cA=512*1024,lA=1e3;function uA(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 dA(e){let t=[],n=0,r=e.length>sA;for(let i=e.length-1;i>=0&&t.length<sA;i--){let a=e[i],o=uA(a.line),s=o.slice(-4e3);if(o.length>s.length&&(r=!0),n+s.length>cA){r=!0;break}n+=s.length,t.push({...a,line:s})}return{lines:t.reverse(),truncated:r}}function fA(e){let t=new Date(e.at);return`[${Number.isNaN(t.getTime())?`—`:t.toLocaleTimeString(void 0,{hour12:!1})}] [${e.source}] ${e.line}`}function pA({process:e,onClose:t,onKill:n,onBack:r}){return(0,$.jsx)(mA,{process:e,onClose:t,onKill:n,onBack:r},$D(e))}function mA({process:e,onClose:t,onKill:n,onBack:r}){let{t:i}=K(`agent`),a=$D(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=aA(e)?e:aA(s)?s:e.status===`stopping`&&s.status!==`stopping`?e:s,I=aA(F);(0,Q.useEffect)(()=>{I&&v(!1)},[I]);let L=D||F.status===`stopping`&&!F.error&&!e.stopError,ee=oA(F);(0,Q.useEffect)(()=>{if(_){f(!1);return}let e=new AbortController,t,n=async()=>{try{let r=await oO(o.current,{limit:sA,signal:e.signal});if(e.signal.aborted)return;if($D(r.process)!==a)throw Error(`Unexpected process identity`);let i=dA(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),aA(r.process)||(t=setTimeout(()=>{n()},lA))}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 R=(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]),z=(0,Q.useMemo)(()=>R.map(fA).join(`
44
- `),[R]);(0,Q.useEffect)(()=>{y&&!_&&N.current&&(N.current.scrollTop=N.current.scrollHeight)},[R,y,_]);let B=async()=>{if(!(L||I)){O(!0),A(!1);try{await n(o.current)}catch{P.current&&A(!0)}finally{P.current&&O(!1)}}},V=async()=>{try{await navigator.clipboard.writeText(z),P.current&&M(`copied`)}catch{P.current&&M(`failed`)}},H=()=>{let t;try{t=URL.createObjectURL(new Blob([z],{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)}},U=`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)(sr,{open:!0,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(Kn,{children:[(0,$.jsx)(or,{className:`z-[80]`}),(0,$.jsxs)(cr,{"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)(on,{className:`h-4 w-4`,"aria-hidden":!0})}),(0,$.jsx)(Oc,{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)(er,{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:ee})]}),(0,$.jsx)(Zn,{className:`mt-1 text-xs text-muted-foreground`,children:i(`backgroundProcess.logsDescription`)})]}),(0,$.jsx)(nr,{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)(Nn,{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:uA(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:uA(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:uA(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:uA(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)(On,{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:U,"aria-pressed":_,onClick:()=>v(e=>!e),children:[_?(0,$.jsx)(Tn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}):(0,$.jsx)(ec,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(_?`backgroundProcess.resume`:`backgroundProcess.pause`)]}),(0,$.jsxs)(`button`,{type:`button`,className:`${U} ${y?`border-accent-info/40 text-accent-info`:``}`,"aria-pressed":y,onClick:()=>b(e=>!e),children:[(0,$.jsx)(ko,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(`backgroundProcess.follow`)]}),(0,$.jsx)(`button`,{type:`button`,className:U,disabled:!R.length,onClick:()=>void V(),"aria-label":i(`backgroundProcess.copy`),title:i(`backgroundProcess.copy`),children:j===`copied`?(0,$.jsx)(vn,{className:`h-3.5 w-3.5`}):(0,$.jsx)(is,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,className:U,disabled:!R.length,onClick:H,"aria-label":i(`backgroundProcess.download`),title:i(`backgroundProcess.download`),children:(0,$.jsx)(bn,{className:`h-3.5 w-3.5`})}),!I&&(0,$.jsxs)(`button`,{type:`button`,className:`${U} text-destructive`,disabled:L,onClick:()=>void B(),children:[L?(0,$.jsx)(Cn,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(En,{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)(Ko,{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:U,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)(Cn,{className:`h-4 w-4 animate-spin`,"aria-hidden":!0}),i(`backgroundProcess.loading`)]}):R.length?R.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:R.length,total:l.length})}),(0,$.jsx)(`span`,{children:i(`backgroundProcess.exportHint`)})]})]})]})})}function hA({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(aA(e))-Number(aA(t))||t.startedAt-e.startedAt)},[e,s,o]);if(d)return(0,$.jsx)(pA,{process:e.find(e=>$D(e)===$D(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)(sr,{open:!0,onOpenChange:e=>{e||i()},children:(0,$.jsxs)(Kn,{children:[(0,$.jsx)(or,{className:`z-[80]`}),(0,$.jsxs)(cr,{"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)(Oc,{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)(er,{className:`text-sm font-semibold`,children:o(`backgroundProcess.history.title`)}),(0,$.jsx)(Zn,{className:`mt-1 text-xs text-muted-foreground`,children:o(`backgroundProcess.history.description`)})]}),(0,$.jsx)(nr,{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)(Nn,{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)(On,{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)(uc,{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)(Ko,{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)(Oc,{className:`h-4 w-4 shrink-0 ${aA(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:uA(e.command)}),(0,$.jsxs)(`span`,{className:`mt-1 block truncate text-[11px] text-muted-foreground`,children:[uA(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`:aA(e)?`bg-muted text-muted-foreground`:`bg-accent-info/10 text-accent-info`}`,children:o(`backgroundProcess.status.${e.status}`)}),(0,$.jsx)(Go,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`,"aria-hidden":!0})]},$D(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)(Cn,{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 gA(e={}){let t=e.enabled!==!1,[n,r]=(0,Q.useState)({available:{},availableIds:[],issues:{},launchDescriptors:{},labels:{},loading:!0});return(0,Q.useEffect)(()=>{if(!t)return;let e=!0;return fetch(`${Ke}/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]),n}function _A(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 vA=[],yA=[];function bA({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}=qN(),T=(0,Q.useMemo)(()=>S.filter(e=>e.deliveryMode!==`steer`),[S]),{pendingCaptures:E,consumePendingCaptures:D,openBrowser:O}=ZD(),{processes:k,history:A=k,historyLoading:j=!1,historyError:M=null,refreshHistory:N,kill:P}=fO(),[F,I]=(0,Q.useState)(null),[L,ee]=(0,Q.useState)(null),R=(0,Q.useMemo)(()=>[...k].sort((e,t)=>Number(aA(e))-Number(aA(t))||t.startedAt-e.startedAt).slice(0,4),[k]),{projects:z,activeProjectId:B}=lt(),V=i?.pinned_project_id??l??B,H=i?.id??`__new-mission__`,U=gi(),te=(0,Q.useRef)(null);te.current!==H&&(ii(H),te.current=H),Ur(H);let[ne,re]=(0,Q.useState)(null),ie=ne&&ne.key===H?ne:null,ae=ie?ie.text:Pr.get(H)??``,oe=ie?vA:Ir.get(H)??vA,se=Fr.get(H)??yA,ce=(e,t=[])=>Wr(H,e,t),[le,ue]=(0,Q.useState)(null),de=(e,t)=>{let n=Fr.get(e)??yA;Gr(e,typeof t==`function`?t(n):t)},[fe,pe]=(0,Q.useState)(!1),[me,he]=(0,Q.useState)(!1),W=(0,Q.useRef)(!1),ge=(0,Q.useRef)(null),_e=(0,Q.useRef)(null),ve=(0,Q.useMemo)(()=>[...new Map(oe.map(({chip:e})=>[JSON.stringify([e.projectId,bO(e)]),e])).values()],[oe]),[ye,be]=(0,Q.useState)(null),[xe,Se]=(0,Q.useState)(0),[G,Ce]=(0,Q.useState)(!1),[we,Te]=(0,Q.useState)([]),[Ee,De]=(0,Q.useState)([]),[Oe,ke]=(0,Q.useState)([]),Ae=le!==null,je=(0,Q.useMemo)(()=>a.filter(e=>e.role===`user`).map(e=>e.content),[a]),Ne=ie?.queueId??null,Pe=(0,Q.useRef)(``),Fe=Ne===null?-1:T.findIndex(e=>e.queueId===Ne),Ie=Fe>=0?T[Fe]:null,Le=ie!==null;(0,Q.useEffect)(()=>{if(fe||me||Le)return Uy(H)},[H,fe,me,Le]);let Re=c===!1||(i?!U.isEditable(i.id):!!U.current),ze=!Re&&!Le,Be=i?.provider??u,{availableIds:Ve,labels:He}=gA(),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,qe=Ge,Je=ye?.mode===`reference`?ye.query.trim():``,Ye=`${qe??``}:${Je}`,[Xe,Ze]=(0,Q.useState)({key:``,items:[]});(0,Q.useEffect)(()=>{let e=z.find(e=>e.id===qe);if(!e||Je.length<2)return;let t=new AbortController,n=setTimeout(()=>{let n=new URLSearchParams({kind:`find`,q:Je,limit:`20`});fetch(`${Ke}/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:Ye,items:hO(e,r.matches??[])})}).catch(()=>{})},180);return()=>{clearTimeout(n),t.abort()}},[qe,z,Je,Ye]);let Qe=(0,Q.useMemo)(()=>({projects:z,conversations:o,activeConversation:i,pinnedProjectId:qe,activeProjectId:B,tickets:we,jobs:Ee,rails:Oe,chips:ve}),[z,o,i,qe,B,we,Ee,Oe,ve]),$e=(0,Q.useMemo)(()=>ye?[...IO(ye.mode,Qe),...ye.mode===`reference`&&Je.length>=2&&Xe.key===Ye?Xe.items:[]]:[],[ye,Qe,Xe,Ye,Je]),et=(0,Q.useMemo)(()=>{if(!ye)return[];let e=AO($e,ye.query);return e.length>0?e:LO(ye.mode,ye.query)},[$e,ye]),tt=ye!==null&&!Le,nt=ae.trim().length>0||ve.length>0,rt=[`accent-primary`,`accent-info`,`accent-highlight`],it=i?.id??null;(0,Q.useEffect)(()=>{I(null),ee(null)},[it,V]),(0,Q.useEffect)(()=>{ue(null),be(null),Ce(!1),re(null)},[it]),(0,Q.useEffect)(()=>{if(!qe){Te([]),De([]),ke([]);return}let e=!0;return(async()=>{try{let[t,n]=await Promise.all([fetch(`${Ke}/api/projects/${encodeURIComponent(qe)}/tickets`),fetch(`${Ke}/api/projects/${encodeURIComponent(qe)}/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(`${Ke}/api/projects/${encodeURIComponent(qe)}/rails`),n=t.ok?await t.json():null;if(!e)return;ke(gO(n))}catch{e&&ke([])}})(),()=>{e=!1}},[qe]),(0,Q.useEffect)(()=>{Se(0)},[ye?.mode,ye?.query]),(0,Q.useEffect)(()=>{xe>=et.length&&Se(Math.max(0,et.length-1))},[xe,et.length]),(0,Q.useEffect)(()=>{if(E.length===0)return;let e=D();e.length&&de(H,t=>[...t,...e])},[E,D,H]);let at=JO(Be),{models:q,efforts:ot,supportsImageInput:st,customModelAliases:ct}=at,ut=(i?i.model:d)??q.find(e=>e.default)?.value??q[0]?.value??``,Y=mt(Be,ut),dt=ot.filter(e=>Y.includes(e)),ft=i?i.reasoning_effort:p,pt=ft&&dt.includes(ft)?ft:Ct(Be,ut)??``,ht=e=>{oi(e)},gt=async e=>{if(e.length===0)return;pe(!0);let t=i;if(!t)try{t=await x(),ht(t.id)}catch(e){J.error(e instanceof Error?e.message:r(`workspace.uploadFailed`)),pe(!1);return}for(let n of e){if(!st&&n.type.startsWith(`image/`)){J.error(r(`imagesUnsupported`));continue}try{let e=await to(t.id,n);de(t.id,t=>[...t,e])}catch(e){J.error(e instanceof Error?e.message:r(`workspace.uploadFailed`))}}pe(!1)},_t=async e=>{try{i&&await ao(i.id,e),de(H,t=>t.filter(t=>t.id!==e))}catch(e){J.error(e instanceof Error?e.message:`Failed to remove attachment.`)}},vt=(e,t,n=oe)=>{if(n.some(e=>t>e.start&&t<=e.end)){be(null);return}let r=yO(e,t);be(r),r&&Ce(!1)},yt=e=>e===`reference`?`@`:e===`trace`?`#`:`/`,bt=e=>{requestAnimationFrame(()=>{_e.current?.focus(),_e.current?.setSelectionRange(e,e)})},xt=e=>{if(Le)return;let t=yt(e),n=_e.current,r=n?.selectionStart??ae.length,i=n?.selectionEnd??r,a=_A(ae,oe,r,i,t);ce(a.text,a.references),ue(null),Ce(!1),be({mode:e,trigger:t,query:``,start:r,end:r+1}),bt(r+1)},St=e=>{_e.current?.focus();let t=RO(ae,ye,e),n=ye?.start??ae.length,r=ye?.end??n,i=t.text.slice(n,t.caret),{references:a}=_A(ae,oe,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)}ce(t.text,a),ue(null),be(null),Ce(!1),bt(t.caret)},wt=e=>{let t=T[e];t&&(Pe.current=t.text,re({key:H,queueId:t.queueId,text:t.text}))},Tt=e=>{Ae&&ce(``),ue(null),wt(e)};(0,Q.useEffect)(()=>{if(!n||n.conversationId!==i?.id)return;let e=T.findIndex(e=>e.queueId===n.queueId);e<0||(Le?wt(e):Tt(e),bt(T[e].text.length))},[n]);let Et=(e,t)=>{let n=t??ae;re(null),e===`keep`&&ce(n)},Dt=async()=>{let e=Ie,t=ae.trim();if(!(!e||!t))try{await C(e.queueId,t)===`saved`?Et(`restore`):(J.info(r(`queueEdit.dispatched`)),Et(`keep`))}catch{J.error(r(`queueEdit.saveFailed`))}};(0,Q.useEffect)(()=>{if(!ie||T.some(e=>e.queueId===ie.queueId))return;let e=ae!==Pe.current;w(ie.queueId)&&J.info(r(`queueEdit.dispatched`)),Et(e?`keep`:`restore`)},[Ne,T,Le]);let Ot=async()=>{if(Re||!nt||W.current)return;let e=ae.trim()||ve.map(e=>e.token).join(` `),t={...se.length?{attachmentIds:se.map(e=>e.id)}:{},...ve.length?{contextRefs:ve.map(xO)}:{}},n=JSON.stringify([e,t]),i=Lr.get(H),a=i?.signature===n?i:{signature:n,queueId:`q-${crypto.randomUUID()}`},o={text:ae,references:oe,attachments:se,submission:a};Kr(H,a),Yr(H,o),be(null),Ce(!1),ue(null),W.current=!0,he(!0);try{let n=await h(e,{...t,queueId:a.queueId}),r=n.conversationId??H;if(!n.accepted){Kr(r,a),Xr(r,o);return}Kr(H,null),Kr(r,null)}catch(e){Xr(H,o),J.error(e instanceof Error?e.message:r(`queueEdit.saveFailed`))}finally{W.current=!1,he(!1)}},kt=e=>{if(je[e]===void 0){ue(null);return}ue(e),ce(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)(PE,{label:r(`provider.label`),value:Be,options:Ue.map(e=>({value:e,label:We(e)})),icon:Fo,onSelect:e=>{v(e).catch(()=>J.error(r(`error.generic`)))},testId:`agent-provider-selector`}),(0,$.jsx)(KO,{models:q,model:i?i.model:d,status:at.status,customModelAliases:ct,onSelect:e=>{y(e).catch(()=>J.error(r(`error.generic`)))}}),dt.length>0&&(0,$.jsx)(PE,{label:r(`effort.label`),value:pt,options:dt.map(e=>({value:e,label:r(`effort.${e}`)})),icon:Ss,onSelect:e=>{m(e).catch(()=>J.error(r(`error.generic`)))},testId:`agent-effort-selector`}),(0,$.jsx)(`div`,{className:`ml-auto`,children:(0,$.jsx)(HO,{level:i?.tier_level??f,onCycle:()=>void _()})})]}),Le&&Ie&&(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)(wn,{className:`h-3 w-3 shrink-0`}),(0,$.jsx)(`span`,{className:`font-medium`,children:r(`queueEdit.editing`,{n:Fe+1,m:T.length})}),(0,$.jsx)(`span`,{className:`truncate text-foreground/45`,children:r(`queueEdit.hint`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>Et(`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)(Nn,{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)(As,{className:`h-3 w-3`}),r(`history.hint`)]}),se.length>0&&(0,$.jsx)(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-1.5`,children:se.map(e=>(0,$.jsx)(mO,{conversationId:it,attachment:e,removeLabel:r(`close`),onRemove:()=>_t(e.id)},e.id))}),(k.length>0||it&&V)&&(0,$.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-1.5`,children:[it&&V&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ee({chatId:it,projectId:V}),"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)(Oc,{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})]}),R.map((e,t)=>(0,$.jsx)(iA,{process:e,accentVariant:rt[t%rt.length],onKill:P,onOpen:I},$D(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&&gt(t)},children:[tt&&(0,$.jsx)($O,{items:et,mode:ye.mode,query:ye.query,activeIndex:xe,onActiveIndexChange:Se,onSelect:St}),ze&&(0,$.jsx)($.Fragment,{children:(0,$.jsx)(`input`,{ref:ge,type:`file`,multiple:!0,hidden:!0,onChange:e=>{let t=Array.from(e.target.files??[]);t.length&&gt(t),e.target.value=``}})}),!Le&&(0,$.jsx)(ek,{open:G,canAttach:ze,uploading:fe,onToggle:()=>{Ce(e=>!e),be(null)},onClose:()=>Ce(!1),onOpenMode:xt,onAttachFile:()=>{Ce(!1),ge.current?.click()},canBrowserCapture:Me()&&!!(qe??B),onOpenBrowser:()=>{Ce(!1),O()}}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsx)(fk,{ref:_e,value:ae,references:Le?[]:oe,autoFocus:e,onChange:(e,t,n)=>{if(Le){re(t=>t&&{...t,text:e});return}Ae&&ue(null),ce(e,t),vt(e,n,t)},onSelect:e=>{Le||vt(_e.current?.value??ae,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&&Se(e=>Math.min(et.length-1,e+1));return}if(e.key===`ArrowUp`){e.preventDefault(),et.length>0&&Se(e=>Math.max(0,e-1));return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let t=et[xe]??et[0];t&&St(t);return}if(e.key===`Escape`){e.preventDefault(),be(null);return}}if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),Le?Dt():Ot();return}if(e.key===`Escape`&&Le){e.preventDefault(),e.stopPropagation(),Et(`restore`);return}let t=_e.current,n=t?.selectionStart===0&&t?.selectionEnd===0,r=t?.selectionStart===ae.length&&t?.selectionEnd===ae.length;if(e.key===`ArrowUp`){if(Le){Ie!==null&&ae===Ie.text&&n&&Fe>0&&(e.preventDefault(),wt(Fe-1));return}if(T.length>0){n&&(e.preventDefault(),Tt(T.length-1));return}!Ae&&ae===``&&je.length>0?(e.preventDefault(),kt(je.length-1)):Ae&&(e.preventDefault(),kt(Math.max(0,le-1)));return}if(e.key===`ArrowDown`){if(Le){Ie!==null&&ae===Ie.text&&r&&(e.preventDefault(),Fe<T.length-1?wt(Fe+1):Et(`restore`));return}if(T.length>0)return;Ae&&(e.preventDefault(),le<je.length-1?kt(le+1):(ue(null),ce(``)));return}(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&Ae&&ue(null)},onPaste:e=>{if(!ze)return;let t=Array.from(e.clipboardData.files);t.length&&(e.preventDefault(),gt(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`}`},H)}),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)(En,{className:`h-4 w-4`,fill:`currentColor`})}),Le?(0,$.jsx)(`button`,{type:`button`,onClick:()=>void Dt(),disabled:Re||!ae.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)(vn,{className:`h-4 w-4`})}):s?(0,$.jsx)(`button`,{type:`button`,onClick:Ot,disabled:Re||!nt||me,"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)(At,{className:`h-4 w-4`})}):(0,$.jsx)(`button`,{type:`button`,onClick:Ot,disabled:Re||!nt||me,"aria-label":r(`send`),className:`rounded-lg bg-accent-primary p-1.5 text-white transition-opacity disabled:opacity-40`,children:(0,$.jsx)(At,{className:`h-4 w-4`})})]}),Ge&&(0,$.jsx)(YO,{projectId:Ge}),F&&F.chatId===it&&F.projectId===V&&(0,$.jsx)(pA,{process:A.find(e=>$D(e)===$D(F))??F,onClose:()=>I(null),onKill:P}),L&&L.chatId===it&&L.projectId===V&&(0,$.jsx)(hA,{processes:A,loading:j,error:M,onRefresh:N,onClose:()=>ee(null),onKill:P})]})}function xA({active:e,inset:t=-4,radius:n=`9999px`,className:r,fadeInMs:i=350,fadeOutMs:a=350}){let o=Ay();return(0,$.jsx)(j_,{children:e&&(0,$.jsxs)(jy.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 SA=`specrails-desktop:effects`,CA=`specrails:effects-changed`,wA={agentThinkingHalo:!0},TA=null;function EA(){try{let e=localStorage.getItem(SA);if(!e)return wA;let t=JSON.parse(e);return{...wA,...typeof t.agentThinkingHalo==`boolean`?{agentThinkingHalo:t.agentThinkingHalo}:{}}}catch{return wA}}function DA(){return TA||=EA(),TA}function OA(e){let t={...DA(),...e};TA=t;try{localStorage.setItem(SA,JSON.stringify(t))}catch{}try{window.dispatchEvent(new CustomEvent(CA))}catch{}return t}function kA(e){let t=()=>{TA=null,e()};return window.addEventListener(CA,t),window.addEventListener(`storage`,t),()=>{window.removeEventListener(CA,t),window.removeEventListener(`storage`,t)}}function AA(){return(0,Q.useSyncExternalStore)(kA,DA,()=>wA)}function jA({active:e,radius:t=`0.75rem`,inset:n=-3}){let{agentThinkingHalo:r}=AA();return r?(0,$.jsx)(`span`,{"data-testid":`agent-thinking-halo`,"data-active":e,className:`contents`,children:(0,$.jsx)(xA,{active:e,radius:t,inset:n,fadeInMs:450,fadeOutMs:800})}):null}var MA=e=>e===`running`||e===`queued`;function NA(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 PA(){try{return Ze()}catch{return null}}var FA=e=>{if(!e)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null};function IA(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(`${Ke}/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(FA(t.started_at)),d(FA(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=MA(o)&&u===null,C=PA(),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(FA(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 LA(e){return e.command.startsWith(`loop:`)?`loop-run`:e.interactive?`interactive`:`job`}var RA=15e3;function zA(e){if(typeof AbortSignal<`u`&&typeof AbortSignal.timeout==`function`)return AbortSignal.timeout(e)}async function BA(e){let{projectId:t,jobId:n,timeoutMs:r=RA}=e,i=t?`${Ke}/api/projects/${t}`:ot(),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 VA=null;function HA(e){VA=e}function UA(e,t){VA?.(e,t)}var WA=(0,Q.lazy)(()=>c(()=>import(`./JobDetailModal-BS-htwqZ.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]))),GA={building:Sn,on_review:Sn,pr_draft:R,pr_ready:R,no_changes:qo,completed:qo,pr_closed:yn,superseded:R,implementation_failed:jn,pr_failed:jn,merged:ws,discarded:yn},KA={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 qA({envelope:e}){let{t}=K(`agent`),n=Mt(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 JA({prDeliveryId:e,projectId:t}){let{t:n}=K(`agent`),r=y(),{activeProjectId:i,setActiveProjectId:a}=lt();return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{let n=`/review/${e}`;i!==t&&(UA(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)(ps,{className:`h-3 w-3`}),n(`prCard.openReview`)]})}function YA(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 XA={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 ZA({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`,XA[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 QA({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)(jn,{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 $A(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 ej(e){let t=/\/pull\/(\d+)/.exec(e);return t?`#${t[1]}`:null}function tj({projectId:e,runId:t,ticketLabel:n,live:r,onOpen:i,onVitals:a}){let{t:o}=K(`agent`),s=IA(e,t,{live:r}),c=n??t.slice(0,8),l=s.elapsedMs==null?null:NA(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)(gc,{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 nj({envelope:e,conversationId:t}){let{t:n}=K(`agent`),r=u(),{projects:i}=lt(),{applyPrDecisionSnapshot:a}=qN(),{openWebView:o,canOpenWebView:s}=we(),{openRef:c}=Ib(),[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),A=O??e,j=Zt(A.projectId).has(A.prDeliveryId),[M,N]=(0,Q.useState)(null),[P,F]=(0,Q.useState)({}),[L,ee]=(0,Q.useState)(null),{decision:z,prUrl:B,prState:V}=A,H=ne&&A.hasDelivery===!1,U=ne?A.runtime?.failure??null:null,te=(A.runIds??[])[0]??null,re=ne&&!!te&&(z===`building`||!!U||z===`implementation_failed`||A.runtime?.status===`running`),ie=Sr(A.projectId,{jobId:te??void 0,enabled:re}),oe=ie.runs.find(e=>e.runId===te)??ie.runs[0]??null,se=oe??(te?$A(A,te):null),[le,ue]=(0,Q.useState)(!1),de=(0,Q.useRef)(null),[fe,pe]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{if(!ne)return;let e=e=>{let n=e.detail;GD(n,{prDeliveryId:A.prDeliveryId,runIds:A.runIds})&&(de.current?.scrollIntoView?.({behavior:`smooth`,block:`center`}),pe(!0),t&&clearTimeout(t),t=setTimeout(()=>pe(!1),1400))},t=null;return window.addEventListener(UD,e),()=>{window.removeEventListener(UD,e),t&&clearTimeout(t)}},[A.prDeliveryId,A.runIds]);let me=fe?`ring-2 ring-accent-primary/50 ring-offset-1 ring-offset-background`:``,he=!!A.repositoryDeliveries?.length,W=Mt(A),_e=jt(A.statusCode,A.statusDetail),ve=A.operation==null&&_e,ye=i.find(e=>e.id===A.projectId)?.name??A.projectId,be=z===`pr_draft`&&!B,xe=z===`building`&&V===`pr-created`&&!!A.branch,Se=A.prNumber?`#${A.prNumber}`:B?ej(B):null,G=W.terminal,Ce=Nt(A.statusCode)?n(`common:prDeliveryStatus.${A.statusCode}`):null,Te=W.partial&&W.deliverableCount>0&&(z===`on_review`||z===`pr_draft`&&!B);(0,Q.useEffect)(()=>{k(null)},[e]);let Ee=(0,Q.useRef)(!1);Ee.current=l!==null||f||A.operation!=null||ie.busy!==null,(0,Q.useEffect)(()=>{d(null),h(!1),_(!1),y(!1),x(!1),C(!1),T(!1),D(!1)},[z,B,A.prDeliveryId]);let De=(0,Q.useCallback)((e,t)=>{F(n=>{let r=n[e];return r?.paused===t.paused&&r?.pausedReason===t.pausedReason?n:{...n,[e]:t}})},[]),Oe=async e=>{if(!L){ee(e);try{let t=await BA({projectId:A.projectId,jobId:e,kind:`loop-run`});t.ok?J.info(n(`prCard.stopExecutionSent`)):J.error(n(`prCard.stopExecutionFailed`),{description:t.error})}finally{ee(null)}}},ke=async(e,r)=>{if(f||l||A.operation||he&&!r&&[`create-pr`,`merge-local`,`publish`,`poll-merge`,`reopen`,`acknowledge-no-changes`].includes(e))return;let i=A.repositoryDeliveries?.find(e=>e.repositoryId===r),o=i?.integrationBranch??i?.baseBranch??A.baseBranch;d(e);try{let i=await yo(A.projectId,{prDeliveryId:A.prDeliveryId,action:e,expectedDecision:z,...r?{repositoryId:r}:{},...H&&t?{conversationId:t}:{}}),s=null;if(i.snapshot){let e=bo(A,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`&&W.retryablePush&&i.deliveryVerified){let e=(i.verifiedSha??i.snapshot?.deliverySha??A.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??A.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`)&&Rt(A.projectId)}catch(e){J.error(n(`prCard.actionFailed`),{description:e instanceof Error?e.message:void 0})}finally{d(null)}},Ae=async e=>{if(!(he&&!e)&&!(l||f||A.operation)){p(!0);try{let t=await(e?xo(A.projectId,A.prDeliveryId,e):xo(A.projectId,A.prDeliveryId));t.kind===`ok`?(J.success(n(`prCard.checkoutSuccess`,{branch:t.branch??Gt(A)??``})),t.cleanupWarnings.length>0&&J.warning(n(`prCard.cleanupIncomplete`,{count:t.cleanupWarnings.length}),{description:t.cleanupWarnings.join(`
44
+ `),[R]);(0,Q.useEffect)(()=>{y&&!_&&N.current&&(N.current.scrollTop=N.current.scrollHeight)},[R,y,_]);let B=async()=>{if(!(L||I)){O(!0),A(!1);try{await n(o.current)}catch{P.current&&A(!0)}finally{P.current&&O(!1)}}},V=async()=>{try{await navigator.clipboard.writeText(z),P.current&&M(`copied`)}catch{P.current&&M(`failed`)}},H=()=>{let t;try{t=URL.createObjectURL(new Blob([z],{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)}},U=`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)(sr,{open:!0,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(Kn,{children:[(0,$.jsx)(or,{className:`z-[80]`}),(0,$.jsxs)(cr,{"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)(on,{className:`h-4 w-4`,"aria-hidden":!0})}),(0,$.jsx)(Oc,{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)(er,{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:ee})]}),(0,$.jsx)(Zn,{className:`mt-1 text-xs text-muted-foreground`,children:i(`backgroundProcess.logsDescription`)})]}),(0,$.jsx)(nr,{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)(Nn,{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:uA(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:uA(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:uA(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:uA(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)(On,{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:U,"aria-pressed":_,onClick:()=>v(e=>!e),children:[_?(0,$.jsx)(Tn,{className:`h-3.5 w-3.5`,"aria-hidden":!0}):(0,$.jsx)(ec,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(_?`backgroundProcess.resume`:`backgroundProcess.pause`)]}),(0,$.jsxs)(`button`,{type:`button`,className:`${U} ${y?`border-accent-info/40 text-accent-info`:``}`,"aria-pressed":y,onClick:()=>b(e=>!e),children:[(0,$.jsx)(ko,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(`backgroundProcess.follow`)]}),(0,$.jsx)(`button`,{type:`button`,className:U,disabled:!R.length,onClick:()=>void V(),"aria-label":i(`backgroundProcess.copy`),title:i(`backgroundProcess.copy`),children:j===`copied`?(0,$.jsx)(vn,{className:`h-3.5 w-3.5`}):(0,$.jsx)(is,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,className:U,disabled:!R.length,onClick:H,"aria-label":i(`backgroundProcess.download`),title:i(`backgroundProcess.download`),children:(0,$.jsx)(bn,{className:`h-3.5 w-3.5`})}),!I&&(0,$.jsxs)(`button`,{type:`button`,className:`${U} text-destructive`,disabled:L,onClick:()=>void B(),children:[L?(0,$.jsx)(Cn,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(En,{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)(Ko,{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:U,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)(Cn,{className:`h-4 w-4 animate-spin`,"aria-hidden":!0}),i(`backgroundProcess.loading`)]}):R.length?R.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:R.length,total:l.length})}),(0,$.jsx)(`span`,{children:i(`backgroundProcess.exportHint`)})]})]})]})})}function hA({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(aA(e))-Number(aA(t))||t.startedAt-e.startedAt)},[e,s,o]);if(d)return(0,$.jsx)(pA,{process:e.find(e=>$D(e)===$D(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)(sr,{open:!0,onOpenChange:e=>{e||i()},children:(0,$.jsxs)(Kn,{children:[(0,$.jsx)(or,{className:`z-[80]`}),(0,$.jsxs)(cr,{"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)(Oc,{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)(er,{className:`text-sm font-semibold`,children:o(`backgroundProcess.history.title`)}),(0,$.jsx)(Zn,{className:`mt-1 text-xs text-muted-foreground`,children:o(`backgroundProcess.history.description`)})]}),(0,$.jsx)(nr,{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)(Nn,{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)(On,{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)(uc,{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)(Ko,{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)(Oc,{className:`h-4 w-4 shrink-0 ${aA(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:uA(e.command)}),(0,$.jsxs)(`span`,{className:`mt-1 block truncate text-[11px] text-muted-foreground`,children:[uA(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`:aA(e)?`bg-muted text-muted-foreground`:`bg-accent-info/10 text-accent-info`}`,children:o(`backgroundProcess.status.${e.status}`)}),(0,$.jsx)(Go,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`,"aria-hidden":!0})]},$D(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)(Cn,{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 gA(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(`${Ke}/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 _A(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 vA=[],yA=[];function bA({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}=qN(),T=(0,Q.useMemo)(()=>S.filter(e=>e.deliveryMode!==`steer`),[S]),{pendingCaptures:E,consumePendingCaptures:D,openBrowser:O}=ZD(),{processes:k,history:A=k,historyLoading:j=!1,historyError:M=null,refreshHistory:N,kill:P}=fO(),[F,I]=(0,Q.useState)(null),[L,ee]=(0,Q.useState)(null),R=(0,Q.useMemo)(()=>[...k].sort((e,t)=>Number(aA(e))-Number(aA(t))||t.startedAt-e.startedAt).slice(0,4),[k]),{projects:z,activeProjectId:B}=lt(),V=i?.pinned_project_id??l??B,H=i?.id??`__new-mission__`,U=gi(),te=(0,Q.useRef)(null);te.current!==H&&(ii(H),te.current=H),Ur(H);let[ne,re]=(0,Q.useState)(null),ie=ne&&ne.key===H?ne:null,ae=ie?ie.text:Pr.get(H)??``,oe=ie?vA:Ir.get(H)??vA,se=Fr.get(H)??yA,ce=(e,t=[])=>Wr(H,e,t),[le,ue]=(0,Q.useState)(null),de=(e,t)=>{let n=Fr.get(e)??yA;Gr(e,typeof t==`function`?t(n):t)},[fe,pe]=(0,Q.useState)(!1),[me,he]=(0,Q.useState)(!1),W=(0,Q.useRef)(!1),ge=(0,Q.useRef)(null),_e=(0,Q.useRef)(null),ve=(0,Q.useMemo)(()=>[...new Map(oe.map(({chip:e})=>[JSON.stringify([e.projectId,bO(e)]),e])).values()],[oe]),[ye,be]=(0,Q.useState)(null),[xe,Se]=(0,Q.useState)(0),[G,Ce]=(0,Q.useState)(!1),[we,Te]=(0,Q.useState)([]),[Ee,De]=(0,Q.useState)([]),[Oe,ke]=(0,Q.useState)([]),Ae=le!==null,je=(0,Q.useMemo)(()=>a.filter(e=>e.role===`user`).map(e=>e.content),[a]),Ne=ie?.queueId??null,Pe=(0,Q.useRef)(``),Fe=Ne===null?-1:T.findIndex(e=>e.queueId===Ne),Ie=Fe>=0?T[Fe]:null,Le=ie!==null;(0,Q.useEffect)(()=>{if(fe||me||Le)return Uy(H)},[H,fe,me,Le]);let Re=c===!1||(i?!U.isEditable(i.id):!!U.current),ze=!Re&&!Le,Be=i?.provider??u,{availableIds:Ve,labels:He}=gA(),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,qe=Ge,Je=ye?.mode===`reference`?ye.query.trim():``,Ye=`${qe??``}:${Je}`,[Xe,Ze]=(0,Q.useState)({key:``,items:[]});(0,Q.useEffect)(()=>{let e=z.find(e=>e.id===qe);if(!e||Je.length<2)return;let t=new AbortController,n=setTimeout(()=>{let n=new URLSearchParams({kind:`find`,q:Je,limit:`20`});fetch(`${Ke}/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:Ye,items:hO(e,r.matches??[])})}).catch(()=>{})},180);return()=>{clearTimeout(n),t.abort()}},[qe,z,Je,Ye]);let Qe=(0,Q.useMemo)(()=>({projects:z,conversations:o,activeConversation:i,pinnedProjectId:qe,activeProjectId:B,tickets:we,jobs:Ee,rails:Oe,chips:ve}),[z,o,i,qe,B,we,Ee,Oe,ve]),$e=(0,Q.useMemo)(()=>ye?[...IO(ye.mode,Qe),...ye.mode===`reference`&&Je.length>=2&&Xe.key===Ye?Xe.items:[]]:[],[ye,Qe,Xe,Ye,Je]),et=(0,Q.useMemo)(()=>{if(!ye)return[];let e=AO($e,ye.query);return e.length>0?e:LO(ye.mode,ye.query)},[$e,ye]),tt=ye!==null&&!Le,nt=ae.trim().length>0||ve.length>0,rt=[`accent-primary`,`accent-info`,`accent-highlight`],it=i?.id??null;(0,Q.useEffect)(()=>{I(null),ee(null)},[it,V]),(0,Q.useEffect)(()=>{ue(null),be(null),Ce(!1),re(null)},[it]),(0,Q.useEffect)(()=>{if(!qe){Te([]),De([]),ke([]);return}let e=!0;return(async()=>{try{let[t,n]=await Promise.all([fetch(`${Ke}/api/projects/${encodeURIComponent(qe)}/tickets`),fetch(`${Ke}/api/projects/${encodeURIComponent(qe)}/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(`${Ke}/api/projects/${encodeURIComponent(qe)}/rails`),n=t.ok?await t.json():null;if(!e)return;ke(gO(n))}catch{e&&ke([])}})(),()=>{e=!1}},[qe]),(0,Q.useEffect)(()=>{Se(0)},[ye?.mode,ye?.query]),(0,Q.useEffect)(()=>{xe>=et.length&&Se(Math.max(0,et.length-1))},[xe,et.length]),(0,Q.useEffect)(()=>{if(E.length===0)return;let e=D();e.length&&de(H,t=>[...t,...e])},[E,D,H]);let at=JO(Be),{models:q,efforts:ot,supportsImageInput:st,customModelAliases:ct}=at,ut=(i?i.model:d)??q.find(e=>e.default)?.value??q[0]?.value??``,Y=mt(Be,ut),dt=ot.filter(e=>Y.includes(e)),ft=i?i.reasoning_effort:p,pt=ft&&dt.includes(ft)?ft:Ct(Be,ut)??``,ht=e=>{oi(e)},gt=async e=>{if(e.length===0)return;pe(!0);let t=i;if(!t)try{t=await x(),ht(t.id)}catch(e){J.error(e instanceof Error?e.message:r(`workspace.uploadFailed`)),pe(!1);return}for(let n of e){if(!st&&n.type.startsWith(`image/`)){J.error(r(`imagesUnsupported`));continue}try{let e=await to(t.id,n);de(t.id,t=>[...t,e])}catch(e){J.error(e instanceof Error?e.message:r(`workspace.uploadFailed`))}}pe(!1)},_t=async e=>{try{i&&await ao(i.id,e),de(H,t=>t.filter(t=>t.id!==e))}catch(e){J.error(e instanceof Error?e.message:`Failed to remove attachment.`)}},vt=(e,t,n=oe)=>{if(n.some(e=>t>e.start&&t<=e.end)){be(null);return}let r=yO(e,t);be(r),r&&Ce(!1)},yt=e=>e===`reference`?`@`:e===`trace`?`#`:`/`,bt=e=>{requestAnimationFrame(()=>{_e.current?.focus(),_e.current?.setSelectionRange(e,e)})},xt=e=>{if(Le)return;let t=yt(e),n=_e.current,r=n?.selectionStart??ae.length,i=n?.selectionEnd??r,a=_A(ae,oe,r,i,t);ce(a.text,a.references),ue(null),Ce(!1),be({mode:e,trigger:t,query:``,start:r,end:r+1}),bt(r+1)},St=e=>{_e.current?.focus();let t=RO(ae,ye,e),n=ye?.start??ae.length,r=ye?.end??n,i=t.text.slice(n,t.caret),{references:a}=_A(ae,oe,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)}ce(t.text,a),ue(null),be(null),Ce(!1),bt(t.caret)},wt=e=>{let t=T[e];t&&(Pe.current=t.text,re({key:H,queueId:t.queueId,text:t.text}))},Tt=e=>{Ae&&ce(``),ue(null),wt(e)};(0,Q.useEffect)(()=>{if(!n||n.conversationId!==i?.id)return;let e=T.findIndex(e=>e.queueId===n.queueId);e<0||(Le?wt(e):Tt(e),bt(T[e].text.length))},[n]);let Et=(e,t)=>{let n=t??ae;re(null),e===`keep`&&ce(n)},Dt=async()=>{let e=Ie,t=ae.trim();if(!(!e||!t))try{await C(e.queueId,t)===`saved`?Et(`restore`):(J.info(r(`queueEdit.dispatched`)),Et(`keep`))}catch{J.error(r(`queueEdit.saveFailed`))}};(0,Q.useEffect)(()=>{if(!ie||T.some(e=>e.queueId===ie.queueId))return;let e=ae!==Pe.current;w(ie.queueId)&&J.info(r(`queueEdit.dispatched`)),Et(e?`keep`:`restore`)},[Ne,T,Le]);let Ot=async()=>{if(Re||!nt||W.current)return;let e=ae.trim()||ve.map(e=>e.token).join(` `),t={...se.length?{attachmentIds:se.map(e=>e.id)}:{},...ve.length?{contextRefs:ve.map(xO)}:{}},n=JSON.stringify([e,t]),i=Lr.get(H),a=i?.signature===n?i:{signature:n,queueId:`q-${crypto.randomUUID()}`},o={text:ae,references:oe,attachments:se,submission:a};Kr(H,a),Yr(H,o),be(null),Ce(!1),ue(null),W.current=!0,he(!0);try{let n=await h(e,{...t,queueId:a.queueId}),r=n.conversationId??H;if(!n.accepted){Kr(r,a),Xr(r,o);return}Kr(H,null),Kr(r,null)}catch(e){Xr(H,o),J.error(e instanceof Error?e.message:r(`queueEdit.saveFailed`))}finally{W.current=!1,he(!1)}},kt=e=>{if(je[e]===void 0){ue(null);return}ue(e),ce(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)(PE,{label:r(`provider.label`),value:Be,options:Ue.map(e=>({value:e,label:We(e)})),icon:Fo,onSelect:e=>{v(e).catch(()=>J.error(r(`error.generic`)))},testId:`agent-provider-selector`}),(0,$.jsx)(KO,{models:q,model:i?i.model:d,status:at.status,customModelAliases:ct,onSelect:e=>{y(e).catch(()=>J.error(r(`error.generic`)))}}),dt.length>0&&(0,$.jsx)(PE,{label:r(`effort.label`),value:pt,options:dt.map(e=>({value:e,label:r(`effort.${e}`)})),icon:Ss,onSelect:e=>{m(e).catch(()=>J.error(r(`error.generic`)))},testId:`agent-effort-selector`}),(0,$.jsx)(`div`,{className:`ml-auto`,children:(0,$.jsx)(HO,{level:i?.tier_level??f,onCycle:()=>void _()})})]}),Le&&Ie&&(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)(wn,{className:`h-3 w-3 shrink-0`}),(0,$.jsx)(`span`,{className:`font-medium`,children:r(`queueEdit.editing`,{n:Fe+1,m:T.length})}),(0,$.jsx)(`span`,{className:`truncate text-foreground/45`,children:r(`queueEdit.hint`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>Et(`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)(Nn,{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)(As,{className:`h-3 w-3`}),r(`history.hint`)]}),se.length>0&&(0,$.jsx)(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-1.5`,children:se.map(e=>(0,$.jsx)(mO,{conversationId:it,attachment:e,removeLabel:r(`close`),onRemove:()=>_t(e.id)},e.id))}),(k.length>0||it&&V)&&(0,$.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-1.5`,children:[it&&V&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ee({chatId:it,projectId:V}),"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)(Oc,{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})]}),R.map((e,t)=>(0,$.jsx)(iA,{process:e,accentVariant:rt[t%rt.length],onKill:P,onOpen:I},$D(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&&gt(t)},children:[tt&&(0,$.jsx)($O,{items:et,mode:ye.mode,query:ye.query,activeIndex:xe,onActiveIndexChange:Se,onSelect:St}),ze&&(0,$.jsx)($.Fragment,{children:(0,$.jsx)(`input`,{ref:ge,type:`file`,multiple:!0,hidden:!0,onChange:e=>{let t=Array.from(e.target.files??[]);t.length&&gt(t),e.target.value=``}})}),!Le&&(0,$.jsx)(ek,{open:G,canAttach:ze,uploading:fe,onToggle:()=>{Ce(e=>!e),be(null)},onClose:()=>Ce(!1),onOpenMode:xt,onAttachFile:()=>{Ce(!1),ge.current?.click()},canBrowserCapture:Me()&&!!(qe??B),onOpenBrowser:()=>{Ce(!1),O()}}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsx)(fk,{ref:_e,value:ae,references:Le?[]:oe,autoFocus:e,onChange:(e,t,n)=>{if(Le){re(t=>t&&{...t,text:e});return}Ae&&ue(null),ce(e,t),vt(e,n,t)},onSelect:e=>{Le||vt(_e.current?.value??ae,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&&Se(e=>Math.min(et.length-1,e+1));return}if(e.key===`ArrowUp`){e.preventDefault(),et.length>0&&Se(e=>Math.max(0,e-1));return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let t=et[xe]??et[0];t&&St(t);return}if(e.key===`Escape`){e.preventDefault(),be(null);return}}if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),Le?Dt():Ot();return}if(e.key===`Escape`&&Le){e.preventDefault(),e.stopPropagation(),Et(`restore`);return}let t=_e.current,n=t?.selectionStart===0&&t?.selectionEnd===0,r=t?.selectionStart===ae.length&&t?.selectionEnd===ae.length;if(e.key===`ArrowUp`){if(Le){Ie!==null&&ae===Ie.text&&n&&Fe>0&&(e.preventDefault(),wt(Fe-1));return}if(T.length>0){n&&(e.preventDefault(),Tt(T.length-1));return}!Ae&&ae===``&&je.length>0?(e.preventDefault(),kt(je.length-1)):Ae&&(e.preventDefault(),kt(Math.max(0,le-1)));return}if(e.key===`ArrowDown`){if(Le){Ie!==null&&ae===Ie.text&&r&&(e.preventDefault(),Fe<T.length-1?wt(Fe+1):Et(`restore`));return}if(T.length>0)return;Ae&&(e.preventDefault(),le<je.length-1?kt(le+1):(ue(null),ce(``)));return}(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&Ae&&ue(null)},onPaste:e=>{if(!ze)return;let t=Array.from(e.clipboardData.files);t.length&&(e.preventDefault(),gt(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`}`},H)}),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)(En,{className:`h-4 w-4`,fill:`currentColor`})}),Le?(0,$.jsx)(`button`,{type:`button`,onClick:()=>void Dt(),disabled:Re||!ae.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)(vn,{className:`h-4 w-4`})}):s?(0,$.jsx)(`button`,{type:`button`,onClick:Ot,disabled:Re||!nt||me,"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)(At,{className:`h-4 w-4`})}):(0,$.jsx)(`button`,{type:`button`,onClick:Ot,disabled:Re||!nt||me,"aria-label":r(`send`),className:`rounded-lg bg-accent-primary p-1.5 text-white transition-opacity disabled:opacity-40`,children:(0,$.jsx)(At,{className:`h-4 w-4`})})]}),Ge&&(0,$.jsx)(YO,{projectId:Ge}),F&&F.chatId===it&&F.projectId===V&&(0,$.jsx)(pA,{process:A.find(e=>$D(e)===$D(F))??F,onClose:()=>I(null),onKill:P}),L&&L.chatId===it&&L.projectId===V&&(0,$.jsx)(hA,{processes:A,loading:j,error:M,onRefresh:N,onClose:()=>ee(null),onKill:P})]})}function xA({active:e,inset:t=-4,radius:n=`9999px`,className:r,fadeInMs:i=350,fadeOutMs:a=350}){let o=Ay();return(0,$.jsx)(j_,{children:e&&(0,$.jsxs)(jy.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 SA=`specrails-desktop:effects`,CA=`specrails:effects-changed`,wA={agentThinkingHalo:!0},TA=null;function EA(){try{let e=localStorage.getItem(SA);if(!e)return wA;let t=JSON.parse(e);return{...wA,...typeof t.agentThinkingHalo==`boolean`?{agentThinkingHalo:t.agentThinkingHalo}:{}}}catch{return wA}}function DA(){return TA||=EA(),TA}function OA(e){let t={...DA(),...e};TA=t;try{localStorage.setItem(SA,JSON.stringify(t))}catch{}try{window.dispatchEvent(new CustomEvent(CA))}catch{}return t}function kA(e){let t=()=>{TA=null,e()};return window.addEventListener(CA,t),window.addEventListener(`storage`,t),()=>{window.removeEventListener(CA,t),window.removeEventListener(`storage`,t)}}function AA(){return(0,Q.useSyncExternalStore)(kA,DA,()=>wA)}function jA({active:e,radius:t=`0.75rem`,inset:n=-3}){let{agentThinkingHalo:r}=AA();return r?(0,$.jsx)(`span`,{"data-testid":`agent-thinking-halo`,"data-active":e,className:`contents`,children:(0,$.jsx)(xA,{active:e,radius:t,inset:n,fadeInMs:450,fadeOutMs:800})}):null}var MA=e=>e===`running`||e===`queued`;function NA(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 PA(){try{return Ze()}catch{return null}}var FA=e=>{if(!e)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null};function IA(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(`${Ke}/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(FA(t.started_at)),d(FA(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=MA(o)&&u===null,C=PA(),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(FA(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 LA(e){return e.command.startsWith(`loop:`)?`loop-run`:e.interactive?`interactive`:`job`}var RA=15e3;function zA(e){if(typeof AbortSignal<`u`&&typeof AbortSignal.timeout==`function`)return AbortSignal.timeout(e)}async function BA(e){let{projectId:t,jobId:n,timeoutMs:r=RA}=e,i=t?`${Ke}/api/projects/${t}`:ot(),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 VA=null;function HA(e){VA=e}function UA(e,t){VA?.(e,t)}var WA=(0,Q.lazy)(()=>c(()=>import(`./JobDetailModal-BnO_V8KR.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]))),GA={building:Sn,on_review:Sn,pr_draft:R,pr_ready:R,no_changes:qo,completed:qo,pr_closed:yn,superseded:R,implementation_failed:jn,pr_failed:jn,merged:ws,discarded:yn},KA={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 qA({envelope:e}){let{t}=K(`agent`),n=Mt(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 JA({prDeliveryId:e,projectId:t}){let{t:n}=K(`agent`),r=y(),{activeProjectId:i,setActiveProjectId:a}=lt();return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{let n=`/review/${e}`;i!==t&&(UA(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)(ps,{className:`h-3 w-3`}),n(`prCard.openReview`)]})}function YA(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 XA={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 ZA({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`,XA[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 QA({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)(jn,{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 $A(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 ej(e){let t=/\/pull\/(\d+)/.exec(e);return t?`#${t[1]}`:null}function tj({projectId:e,runId:t,ticketLabel:n,live:r,onOpen:i,onVitals:a}){let{t:o}=K(`agent`),s=IA(e,t,{live:r}),c=n??t.slice(0,8),l=s.elapsedMs==null?null:NA(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)(gc,{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 nj({envelope:e,conversationId:t}){let{t:n}=K(`agent`),r=u(),{projects:i}=lt(),{applyPrDecisionSnapshot:a}=qN(),{openWebView:o,canOpenWebView:s}=we(),{openRef:c}=Ib(),[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),A=O??e,j=Zt(A.projectId).has(A.prDeliveryId),[M,N]=(0,Q.useState)(null),[P,F]=(0,Q.useState)({}),[L,ee]=(0,Q.useState)(null),{decision:z,prUrl:B,prState:V}=A,H=ne&&A.hasDelivery===!1,U=ne?A.runtime?.failure??null:null,te=(A.runIds??[])[0]??null,re=ne&&!!te&&(z===`building`||!!U||z===`implementation_failed`||A.runtime?.status===`running`),ie=Sr(A.projectId,{jobId:te??void 0,enabled:re}),oe=ie.runs.find(e=>e.runId===te)??ie.runs[0]??null,se=oe??(te?$A(A,te):null),[le,ue]=(0,Q.useState)(!1),de=(0,Q.useRef)(null),[fe,pe]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{if(!ne)return;let e=e=>{let n=e.detail;GD(n,{prDeliveryId:A.prDeliveryId,runIds:A.runIds})&&(de.current?.scrollIntoView?.({behavior:`smooth`,block:`center`}),pe(!0),t&&clearTimeout(t),t=setTimeout(()=>pe(!1),1400))},t=null;return window.addEventListener(UD,e),()=>{window.removeEventListener(UD,e),t&&clearTimeout(t)}},[A.prDeliveryId,A.runIds]);let me=fe?`ring-2 ring-accent-primary/50 ring-offset-1 ring-offset-background`:``,he=!!A.repositoryDeliveries?.length,W=Mt(A),_e=jt(A.statusCode,A.statusDetail),ve=A.operation==null&&_e,ye=i.find(e=>e.id===A.projectId)?.name??A.projectId,be=z===`pr_draft`&&!B,xe=z===`building`&&V===`pr-created`&&!!A.branch,Se=A.prNumber?`#${A.prNumber}`:B?ej(B):null,G=W.terminal,Ce=Nt(A.statusCode)?n(`common:prDeliveryStatus.${A.statusCode}`):null,Te=W.partial&&W.deliverableCount>0&&(z===`on_review`||z===`pr_draft`&&!B);(0,Q.useEffect)(()=>{k(null)},[e]);let Ee=(0,Q.useRef)(!1);Ee.current=l!==null||f||A.operation!=null||ie.busy!==null,(0,Q.useEffect)(()=>{d(null),h(!1),_(!1),y(!1),x(!1),C(!1),T(!1),D(!1)},[z,B,A.prDeliveryId]);let De=(0,Q.useCallback)((e,t)=>{F(n=>{let r=n[e];return r?.paused===t.paused&&r?.pausedReason===t.pausedReason?n:{...n,[e]:t}})},[]),Oe=async e=>{if(!L){ee(e);try{let t=await BA({projectId:A.projectId,jobId:e,kind:`loop-run`});t.ok?J.info(n(`prCard.stopExecutionSent`)):J.error(n(`prCard.stopExecutionFailed`),{description:t.error})}finally{ee(null)}}},ke=async(e,r)=>{if(f||l||A.operation||he&&!r&&[`create-pr`,`merge-local`,`publish`,`poll-merge`,`reopen`,`acknowledge-no-changes`].includes(e))return;let i=A.repositoryDeliveries?.find(e=>e.repositoryId===r),o=i?.integrationBranch??i?.baseBranch??A.baseBranch;d(e);try{let i=await yo(A.projectId,{prDeliveryId:A.prDeliveryId,action:e,expectedDecision:z,...r?{repositoryId:r}:{},...H&&t?{conversationId:t}:{}}),s=null;if(i.snapshot){let e=bo(A,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`&&W.retryablePush&&i.deliveryVerified){let e=(i.verifiedSha??i.snapshot?.deliverySha??A.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??A.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`)&&Rt(A.projectId)}catch(e){J.error(n(`prCard.actionFailed`),{description:e instanceof Error?e.message:void 0})}finally{d(null)}},Ae=async e=>{if(!(he&&!e)&&!(l||f||A.operation)){p(!0);try{let t=await(e?xo(A.projectId,A.prDeliveryId,e):xo(A.projectId,A.prDeliveryId));t.kind===`ok`?(J.success(n(`prCard.checkoutSuccess`,{branch:t.branch??Gt(A)??``})),t.cleanupWarnings.length>0&&J.warning(n(`prCard.cleanupIncomplete`,{count:t.cleanupWarnings.length}),{description:t.cleanupWarnings.join(`
45
45
  `)}),Rt(A.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)}}},je=async()=>{let e=W.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{ce()&&await ge(e[0])}catch{}r?J.success(n(`prCard.localResultPathCopied`),{description:t}):J.info(n(`prCard.localResultPath`),{description:t})},Me=async()=>{if(!(le||Ee.current)){ue(!0);try{let e=await fetch(`${Ke}/api/projects/${encodeURIComponent(A.projectId)}/rails/${A.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:A.railIndex+1})),Rt(A.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{ue(!1)}}},Ne=(e,t)=>{s&&(e.preventDefault(),e.stopPropagation(),o(t))},Pe=A.ticketIds.length>0&&(0,$.jsx)($.Fragment,{children:A.ticketIds.map(e=>(0,$.jsxs)(ED,{refTarget:{kind:`ticket`,ticketId:e},onOpen:e=>void c(A.projectId,e),children:[`#`,e]},e))}),Fe=A.runIds??[],Ie=e=>Fe.length===1&&A.ticketIds.length>1?A.ticketIds.map(e=>`#${e}`).join(` `):A.ticketIds[e]==null?null:`#${A.ticketIds[e]}`,Le=Fe.find(e=>P[e]?.paused)??null,Re=Le?P[Le]?.pausedReason??null:null,ze=Fe.length>0&&(0,$.jsx)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-1.5`,"data-testid":`pr-run-log-chips`,children:Fe.map((e,t)=>(0,$.jsx)(tj,{projectId:A.projectId,runId:e,ticketLabel:Ie(t),live:z===`building`,onOpen:N,onVitals:De},e))}),Be=z===`building`&&Le!==null,Ve=Le?Ie(Fe.indexOf(Le))??Le.slice(0,8):null,He=YA(A,oe,Le!==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=ie.busy!==null||le,Ge=ne&&se&&(0,$.jsxs)($.Fragment,{children:[se.canResume&&(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`mission-run-resume`,disabled:We||l!==null,onClick:()=>void ie.act(se,`resume`),className:X(Ue,`border-accent-primary/40 bg-accent-primary/10 text-accent-primary hover:bg-accent-primary/20`),children:[ie.busy===se.runId?(0,$.jsx)(Cn,{className:`h-3 w-3 animate-spin`}):(0,$.jsx)(Tn,{className:`h-3 w-3`}),n(`runCard.actions.resume`)]}),se.pendingApproval&&(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`mission-run-approve`,disabled:We||l!==null,onClick:()=>void ie.act(se,`approve`),className:X(Ue,`border-accent-success/40 bg-accent-success/10 text-accent-success hover:bg-accent-success/20`),children:[(0,$.jsx)(xc,{className:`h-3 w-3`}),n(`runCard.actions.approve`)]}),se.recoverableSteps.length>0&&(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`mission-run-recover`,disabled:We||l!==null,onClick:()=>void ie.act(se,`recover`),className:X(Ue,`border-accent-warning/40 bg-accent-warning/10 text-accent-warning hover:bg-accent-warning/20`),children:[(0,$.jsx)(Mn,{className:`h-3 w-3`}),n(`runCard.actions.recover`)]})]}),qe=!!oe?.active||He===`running`||He===`paused`,Je=ne&&(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,"data-testid":`mission-run-relaunch`,disabled:We||l!==null||qe,title:qe?n(`runCard.relaunchBlockedActive`):void 0,onClick:()=>void Me(),className:X(Ue,`border-border/60 text-foreground/70 hover:border-accent-primary/40 hover:bg-accent-primary/10`),children:[le?(0,$.jsx)(Cn,{className:`h-3 w-3 animate-spin`}):(0,$.jsx)(pc,{className:`h-3 w-3`}),n(`runCard.actions.relaunch`)]}),Ye=ne&&ie.error&&re?(0,$.jsx)(`p`,{className:`mt-1 text-[10px] text-destructive/80`,"data-testid":`mission-run-runtime-error`,children:ie.error}):null,Xe=ne&&oe?.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)(Eo,{className:`h-3 w-3 shrink-0 opacity-60`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`truncate`,children:oe.nextStep})]}):null,Ze=M&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(WA,{jobId:M,projectId:A.projectId,onClose:()=>N(null)})});if(z===`building`)return(0,$.jsxs)(`div`,{ref:de,"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`,me),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[Be?(0,$.jsx)(jn,{className:`h-3.5 w-3.5 text-accent-warning`}):xe?(0,$.jsx)(R,{className:`h-3.5 w-3.5 text-accent-info`}):(0,$.jsx)(Cn,{className:`h-3.5 w-3.5 animate-spin text-accent-primary/70`}),(0,$.jsx)(`span`,{className:X(`min-w-0 flex-1 truncate`,!xe&&!Be&&`animate-pulse`,Be&&`text-accent-warning`),children:n(Be?`prCard.title.paused`:xe?`prCard.title.buildingExistingPr`:`prCard.title.building`)}),ne&&(0,$.jsx)(ZA,{status:He}),ne&&(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:A.railName?A.railName:n(`prCard.rail`,{index:A.railIndex+1})})]}),Xe&&(0,$.jsx)(`div`,{className:`mt-1 flex items-center pl-[22px]`,children:Xe}),Pe&&(0,$.jsx)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-1.5 pl-[22px]`,children:Pe}),xe&&(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=>Ne(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)(R,{className:`h-3 w-3`}),Se??n(`prCard.openPr`),(0,$.jsx)(ln,{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)(R,{className:`h-3 w-3`}),Se??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)(Sn,{className:`h-3 w-3 shrink-0 text-accent-primary/70`}),(0,$.jsx)(`span`,{className:`truncate`,children:A.branch})]})]}),Be&&Le&&(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)(jn,{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(),N(Le)},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)(Tn,{className:`h-3 w-3`}),n(`prCard.resume`)]}),(0,$.jsxs)(`button`,{type:`button`,"data-agent-interactive":!0,disabled:L===Le,onClick:e=>{e.stopPropagation(),Oe(Le)},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===Le?(0,$.jsx)(Cn,{className:`h-3 w-3 animate-spin`}):(0,$.jsx)(En,{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`:xe?`prCard.buildingExistingPrHint`:`prCard.buildingHint`)}),Ye,Ze]});if(H){let e=He===`succeeded`?qo:He===`failed`||He===`stalled`?jn:He===`cancelled`?yn:Cn,t=l!==null||We;return(0,$.jsxs)(`div`,{ref:de,"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`,me),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)(ZA,{status:He}),(0,$.jsx)(`span`,{className:`max-w-[140px] shrink-0 truncate text-[11px] text-foreground/50`,title:ye,children:ye}),(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:A.railName?A.railName:n(`prCard.rail`,{index:A.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)(I,{className:`h-3 w-3 text-accent-secondary/80`}),n(`prCard.specCount`,{count:A.ticketIds.length})]}),Pe,Xe]}),ze,(0,$.jsx)(qA,{envelope:A}),(U||He===`failed`||He===`stalled`)&&(0,$.jsx)(QA,{envelope:A}),(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)(Sn,{className:`mt-px h-3 w-3 shrink-0 opacity-60`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:n(`runCard.noDeliveryNote`)})]}),Ye,(0,$.jsxs)(jy.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`&&Je,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)(Cn,{className:`h-3 w-3 animate-spin`}),n(`prCard.dismiss`)]})]},`${He}-${A.updatedAt??``}`),(0,$.jsx)(sr,{open:g,onOpenChange:_,children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`agent-pr-dismiss-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:n(`prCard.confirm.dismissTitle`)}),(0,$.jsx)(Zn,{children:n(`prCard.confirm.dismissBody`)})]}),(0,$.jsxs)(Wn,{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),ke(`dismiss`)},children:n(`prCard.dismiss`)})]})]})}),Ze]})}let Qe=GA[z],$e=W.superseded?n(`prCard.title.superseded`):W.noChanges?n(`prCard.title.no_changes`):W.deliveryBlocked?n(`prCard.title.delivery_blocked`):W.retryablePush?n(`prCard.title.update_failed`):W.closed?n(`prCard.title.pr_closed`):W.partial?n(`prCard.title.partial`):A.statusCode===`existing_pr_updated`?n(`prCard.title.existing_pr_updated`):n(be?`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||A.operation!=null,rt=!!A.operation||ve||W.partial||W.deliveryBlocked||W.retryablePush||W.retryablePrCreation||W.closed||W.implementationFailed,it=(0,$.jsx)(Cn,{className:`h-3 w-3 animate-spin`}),at=(e,t)=>!he&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void ke(e),disabled:nt,"data-agent-interactive":!0,className:et,children:[l===e&&it,t]}),q=ae&&r&&!W.terminal?(0,$.jsx)(JA,{prDeliveryId:A.prDeliveryId,projectId:A.projectId}):null,ot=Gt(A),st=ot&&!he&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void Ae(),disabled:nt,"data-testid":`agent-pr-checkout`,"data-agent-interactive":!0,title:n(`prCard.checkoutTooltip`,{branch:ot}),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)(Sn,{className:`h-3 w-3`}),n(`prCard.checkout`)]}),ct=W.recoveryWorktreePaths.length>0&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void je(),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)(bs,{className:`h-3 w-3`,"aria-hidden":!0}),n(`prCard.inspectLocalResult`)]}),ut=W.recoveryRecheck,Y=(W.manualRecovery||ut)&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>D(!0),disabled:nt,"data-testid":ut?`agent-pr-recheck-recovery`:`agent-pr-recover-and-retry`,"data-agent-interactive":!0,className:ut?`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)(pc,{className:`h-3 w-3`,"aria-hidden":!0}),n(ut?`prCard.recheckRecovery`:`prCard.recoverAndRetry`)]}),dt=!he&&(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:A.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`)]}),pt=(0,$.jsxs)(`button`,{type:`button`,onClick:()=>_(!0),disabled:nt,"data-agent-interactive":!0,className:tt,children:[l===`dismiss`&&it,n(`prCard.dismiss`)]}),mt=(0,$.jsxs)(`button`,{type:`button`,onClick:()=>y(!0),disabled:nt,"data-agent-interactive":!0,className:tt,children:[l===`discard`&&it,n(`prCard.discardLocalResult`)]}),ht=!he&&(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=>Ne(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)(R,{className:`h-3 w-3`}),Se??n(`prCard.openPr`),(0,$.jsx)(ln,{className:`h-2.5 w-2.5 opacity-60`})]}),vt=ne&&(!!U||z===`implementation_failed`||z===`discarded`&&(!!A.statusDetail||A.statusCode===`delivery_failed`));return(0,$.jsxs)(`div`,{ref:de,"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`,me),children:[rt&&(0,$.jsx)(`span`,{role:`status`,"aria-live":`polite`,"aria-label":A.operation?n(`prCard.operation.${A.operation}`):ve?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`,KA[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:ye,children:ye}),(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:A.railIndex+1})})]}),(0,$.jsx)($t,{deliveryId:A.prDeliveryId,repositories:A.repositoryDeliveries,busy:!!l||f||!!A.operation,onAct:ke,onCheckout:Ae}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,children:[!he&&(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)(Sn,{className:`h-3 w-3 text-accent-primary/70`}),`→ `,A.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)(I,{className:`h-3 w-3 text-accent-secondary/80`}),n(`prCard.specCount`,{count:A.ticketIds.length})]}),Pe,_t,A.deliverySha&&(0,$.jsxs)(`span`,{"data-testid":`agent-pr-delivery-sha`,title:A.deliverySha,className:X(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 font-mono text-[11px]`,A.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)(qo,{className:`h-3 w-3`}),n(`prCard.deliveryCommit`,{sha:A.deliverySha.slice(0,8)})]})]}),ze,A.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)(Cn,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}),n(`prCard.operation.${A.operation}`)]}),ve&&(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)(pc,{className:`mt-px h-3 w-3 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:n(`common:prRecovery.interrupted`)})]}),(0,$.jsx)(qA,{envelope:A}),vt&&(0,$.jsx)(QA,{envelope:A}),Ye,Ce&&(0,$.jsx)(`p`,{className:`mt-2 text-[10px] font-medium uppercase tracking-wide text-foreground/45`,"data-testid":`agent-pr-status-code`,children:Ce}),!G&&W.deliveryBlocked&&(0,$.jsxs)(`p`,{className:`mt-2 flex items-start gap-1.5 text-[11px] leading-4 text-accent-warning`,children:[(0,$.jsx)(jn,{className:`mt-px h-3 w-3 shrink-0`}),(0,$.jsxs)(`span`,{children:[W.recoveryUnavailable?n(`prCard.recoveryUnavailableBody`):n(W.partial?`prCard.partialDeliveryBlockedNote`:`prCard.deliveryBlockedNote`),A.statusDetail&&!_e&&!W.recoveryUnavailable?(0,$.jsx)(`span`,{className:`mt-0.5 block text-foreground/50`,children:A.statusDetail}):null]})]}),!G&&W.recoveryUnavailable&&A.statusDetail&&!_e&&(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:A.statusDetail})]}),!G&&W.retryablePush&&(0,$.jsxs)(`p`,{className:`mt-2 flex items-start gap-1.5 text-[11px] leading-4 text-accent-warning`,children:[(0,$.jsx)(jn,{className:`mt-px h-3 w-3 shrink-0`}),(0,$.jsxs)(`span`,{children:[n(`prCard.retryPushNote`),A.statusDetail&&!_e?(0,$.jsx)(`span`,{className:`mt-0.5 block text-foreground/50`,children:A.statusDetail}):null]})]}),A.statusDetail&&!_e&&!W.deliveryBlocked&&!W.retryablePush&&!vt&&(0,$.jsx)(`p`,{className:`mt-1 text-[10px] leading-4 text-foreground/45`,"data-testid":`agent-pr-status-detail`,children:A.statusDetail}),!G&&!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)(jn,{className:`mt-px h-3 w-3 shrink-0`}),n(V===`local-only`?`prCard.degraded.localOnly`:`prCard.degraded.pushed`)]}),W.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:W.cleanupWarnings.length})}),(0,$.jsx)(`ul`,{className:`mt-1 list-disc space-y-0.5 pl-4 text-foreground/60`,children:W.cleanupWarnings.map((e,t)=>(0,$.jsx)(`li`,{children:e},`${t}-${e}`))})]}),W.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:W.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:W.safetyArchives.map(e=>(0,$.jsx)(`li`,{className:`break-all`,children:e},e))})]}),(0,$.jsxs)(jy.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:`easeOut`},className:`mt-2.5`,children:[W.noChanges&&!G&&(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)(qo,{className:`h-3.5 w-3.5`}),W.continuation?n(`prCard.noChangesExisting`):n(`prCard.noChangesNote`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:W.continuation?pt:(0,$.jsxs)($.Fragment,{children:[ht,gt]})})]}),!G&&W.deliveryBlocked&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[ct,Y,W.continuation?W.hasDiscardableRecoveryResult?mt:pt:ft]}),!G&&W.retryablePush&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[st,at(`create-pr`,n(`prCard.retryPush`)),W.continuation?pt:ft]}),!G&&W.retryablePrCreation&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[st,at(`create-pr`,n(`prCard.retryPr`)),dt,W.continuation?pt:ft]}),!G&&W.closed&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[st,at(`reopen`,n(`prCard.reopen`)),W.continuation?pt:ft]}),!G&&Te&&!W.deliveryBlocked&&!W.retryablePush&&!W.retryablePrCreation&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[st,at(`create-pr`,n(`prCard.createPartialPr`,{count:W.deliverableCount})),W.continuation?pt:ft]}),z===`on_review`&&!W.noChanges&&!W.partial&&!W.deliveryBlocked&&!W.retryablePush&&!W.retryablePrCreation&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[q,st,at(`create-pr`,n(`prCard.createPr`)),dt,W.continuation?pt:ft]}),z===`pr_draft`&&!be&&!W.deliveryBlocked&&!W.retryablePush&&!W.retryablePrCreation&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[st,at(`publish`,n(`prCard.publish`)),W.continuation?pt:ft]}),be&&!Te&&!W.deliveryBlocked&&!W.retryablePush&&!W.retryablePrCreation&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[st,at(`create-pr`,n(`prCard.retryPr`)),dt,W.continuation?pt:ft]}),z===`pr_ready`&&!W.deliveryBlocked&&!W.retryablePush&&!W.retryablePrCreation&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[st,at(`poll-merge`,n(`prCard.verifyPr`)),W.continuation?pt:ft]}),z===`pr_failed`&&!W.deliveryBlocked&&!W.retryablePush&&!W.retryablePrCreation&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[st,at(`create-pr`,n(`prCard.retry`)),!B&&dt,W.continuation?pt:ft]}),z===`implementation_failed`&&W.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)(jn,{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,Je,W.continuation?pt:ft]})]}),ne&&z===`discarded`&&A.statusCode===`delivery_failed`&&(0,$.jsx)(`div`,{className:`mb-2 flex flex-wrap items-center gap-1.5`,"data-testid":`mission-run-discarded-actions`,children:Je}),z===`merged`&&(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs font-medium text-accent-success`,children:[(0,$.jsx)(qo,{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)(yn,{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)(qo,{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)(R,{className:`h-3.5 w-3.5`}),n(`prCard.supersededNote`)]})]},`${z}-${B??``}`),(0,$.jsx)(sr,{open:!he&&b,onOpenChange:x,children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`agent-pr-merge-local-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:n(`prCard.confirm.mergeLocalTitle`)}),(0,$.jsx)(Zn,{children:n(`prCard.confirm.mergeLocalBody`,{base:A.baseBranch})})]}),(0,$.jsxs)(Wn,{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),ke(`merge-local`)},children:n(`prCard.mergeLocal`)})]})]})}),(0,$.jsx)(sr,{open:E,onOpenChange:D,children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`agent-pr-recover-and-retry-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:n(ut?`prCard.confirm.recheckRecoveryTitle`:`prCard.confirm.recoverAndRetryTitle`)}),(0,$.jsx)(Zn,{children:n(ut?`prCard.confirm.recheckRecoveryBody`:`prCard.confirm.recoverAndRetryBody`,{branch:A.branch??``})})]}),(0,$.jsxs)(Wn,{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),ke(`recover-and-retry`)},children:n(ut?`prCard.recheckRecovery`:`prCard.recoverAndRetry`)})]})]})}),(0,$.jsx)(sr,{open:m,onOpenChange:h,children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`agent-pr-discard-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:n(z===`implementation_failed`?`prCard.confirm.implementationFailedDiscardTitle`:`prCard.confirm.freshDiscardTitle`)}),(0,$.jsx)(Zn,{children:n(z===`implementation_failed`?`prCard.confirm.implementationFailedDiscardBody`:`prCard.confirm.freshDiscardBody`)}),j&&(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)(Wn,{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),ke(`discard`)},children:n(`prCard.discard`)})]})]})}),(0,$.jsx)(sr,{open:g,onOpenChange:_,children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`agent-pr-dismiss-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:n(`prCard.confirm.dismissTitle`)}),(0,$.jsx)(Zn,{children:n(`prCard.confirm.dismissBody`)})]}),(0,$.jsxs)(Wn,{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),ke(`dismiss`)},children:n(`prCard.dismiss`)})]})]})}),(0,$.jsx)(sr,{open:v,onOpenChange:y,children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`agent-pr-discard-local-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:n(`prCard.confirm.discardLocalTitle`)}),(0,$.jsx)(Zn,{children:n(`prCard.confirm.discardLocalBody`)})]}),(0,$.jsxs)(Wn,{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),ke(`discard`)},children:n(`prCard.discardLocalResult`)})]})]})}),(0,$.jsx)(sr,{open:!he&&S,onOpenChange:C,children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`agent-pr-no-changes-done-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:n(`prCard.confirm.noChangesDoneTitle`)}),(0,$.jsx)(Zn,{children:n(`prCard.confirm.noChangesDoneBody`)})]}),(0,$.jsxs)(Wn,{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),ke(`acknowledge-no-changes`)},children:n(`prCard.markDone`)})]})]})}),(0,$.jsx)(sr,{open:w,onOpenChange:T,children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`agent-pr-refine-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:n(`prCard.confirm.refineTitle`)}),(0,$.jsx)(Zn,{children:n(`prCard.confirm.refineBody`)})]}),(0,$.jsxs)(Wn,{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),ke(`discard`)},children:n(`prCard.refine`)})]})]})}),Ze]})}var rj={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 ij({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`,rj[e]),children:t(`prCard.pinned.state.${e}`)})}function aj(){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 oj=e=>`specrails-desktop:agent-pr-dock-collapsed:${e}`,sj=e=>`specrails-desktop:agent-pr-dock-card-collapsed:${e}`;function cj(e){try{return sessionStorage.getItem(oj(e))===`1`}catch{return!1}}function lj(e,t){try{t?sessionStorage.setItem(oj(e),`1`):sessionStorage.removeItem(oj(e))}catch{}}function uj(e){try{let t=sessionStorage.getItem(sj(e)),n=t?JSON.parse(t):[];return new Set(Array.isArray(n)?n.filter(e=>typeof e==`string`):[])}catch{return new Set}}function dj(e,t){try{t.size===0?sessionStorage.removeItem(sj(e)):sessionStorage.setItem(sj(e),JSON.stringify([...t]))}catch{}}function fj({pinned:e,proposals:t=[],projectId:n=null,conversationId:r,inline:i}){let{t:a}=K(`agent`),[o,s]=(0,Q.useState)(()=>cj(r)),[c,l]=(0,Q.useState)(()=>uj(r));(0,Q.useEffect)(()=>{s(cj(r)),l(uj(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=>{lj(r,e),s(e)},p=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),dj(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)(jy.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)(nc,{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)(ij,{decision:d.envelope.decision}):(0,$.jsx)(aj,{}),(0,$.jsx)(fn,{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)(nc,{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)(Wo,{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)(fc,{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)(aj,{}),i?(0,$.jsx)(fn,{className:`h-3 w-3 shrink-0 opacity-60`}):(0,$.jsx)(Wo,{className:`h-3 w-3 shrink-0 opacity-60`})]}),!i&&(0,$.jsx)(UE,{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)(R,{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)(ij,{decision:e.envelope.decision}),n?(0,$.jsx)(fn,{className:`h-3 w-3 shrink-0 opacity-60`}):(0,$.jsx)(Wo,{className:`h-3 w-3 shrink-0 opacity-60`})]}),!n&&(0,$.jsx)(nj,{envelope:e.envelope,conversationId:r})]},e.messageId)})]})]})})})}function pj(e){return e?e.charAt(0).toUpperCase()+e.slice(1):`Unknown`}function mj(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}] ${pj(e.role)}`,e.content)}),o.join(`
48
- `))}function hj(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 gj(){let{t:e}=K(`agent`),{active:t,messages:n,renameConversation:r,deleteConversation:i,startNewConversation:a,favoriteConversationIds:o,toggleFavoriteConversation:s}=qN(),{projects:c}=lt(),[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(mj(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=mj(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=hj(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)(Go,{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)(Ic,{}),(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)(ds,{className:`h-4 w-4`})}),(0,$.jsx)(j_,{children:l&&(0,$.jsx)(jy.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)(wn,{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)(ks,{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)(An,{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)(vn,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`}):(0,$.jsx)(is,{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)(bn,{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)(vn,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`}):(0,$.jsx)(is,{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 _j=new Set([`building`,`on_review`,`pr_draft`,`no_changes`,`pr_closed`,`implementation_failed`,`pr_failed`]);function vj(e){return _j.has(e)}function yj(e){return!!(vj(e.decision)||e.phase===`launched`||e.phase===`running`||e.runtime?.failure&&e.decision!==`discarded`&&e.decision!==`superseded`)}function bj(e){let t=[];for(let[n,r]of e.entries()){if(r.role!==`system`)continue;let e=_o(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=Ft(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=Ft(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))Ft(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),yj(e.envelope)&&u.push(e)}return{byMessageId:c,duplicateMessageIds:l,pinned:u}}function xj({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)(jn,{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:()=>WD({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 Sj({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)(kn,{className:`h-3 w-3 text-accent-primary/70`,"aria-hidden":!0}),n(`runFailure.briefing.title`),r?(0,$.jsx)(Wo,{className:`h-3 w-3 opacity-60`,"aria-hidden":!0}):(0,$.jsx)(Go,{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)(RD,{content:e,contextRefs:t})})]})}var Cj={pinnedMessageIds:new Set,pinned:[]};function wj(e){let t=jx();return(0,Q.useMemo)(()=>{if(!ne)return Cj;let n=[],r=new Set;for(let i of e){if(i.role!==`assistant`||!i.content.includes("```rail-launch"))continue;let{proposals:e}=Ex(i.content,!1);e.forEach((e,a)=>{Mx(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 Tj=(0,Q.lazy)(()=>c(()=>import(`./JobDetailModal-BS-htwqZ.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]))),Ej=(0,Q.lazy)(()=>c(()=>import(`./LoopPreviewModal-BYOrnmcp.js`).then(e=>({default:e.LoopPreviewModal})),__vite__mapDeps([79,1,7,8,11,10,43,57,58,66,67,71,65,51,80,53,55]))),Dj=new Set,Oj=new Set([`spec-framing.committed`]);function kj(e){if(!e.startsWith(`{`))return!1;try{let t=JSON.parse(e);return typeof t?.kind==`string`&&Oj.has(t.kind)}catch{return!1}}function Aj({variant:e}){let{t}=K(`agent`),{active:n}=qN(),r=gi(),i=Hy(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)(gj,{}),(0,$.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,$.jsx)(ln,{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)(jj,{variant:e},`${n?.id??`__new-mission__`}:${i}`)})}function jj({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}=qN(),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(),y=o.length>0?o:s,b=(0,Q.useRef)(null),x=Xy(i,a),{openRef:S,jobRef:C,closeJobRef:w,loopRef:T,closeLoopRef:E}=Ib(),D=n?.pinned_project_id??null,[O,k]=(0,Q.useState)(new Map),A=(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=A?A.split(`\0`):[];if(!n?.id||e.length===0){k(new Map);return}let t=!1,r=new Set(e);return no(n.id).then(e=>{t||k(new Map(e.filter(e=>r.has(e.id)).map(e=>[e.id,e])))}).catch(()=>{t||k(new Map)}),()=>{t=!0}},[n?.id,A]);let j=(0,Q.useMemo)(()=>D?e=>{S(D,e)}:void 0,[D,S]),M=_a().id===`code-rain`?t(`emptyTitleCodeRain`):t(`emptyTitle`),N=(0,Q.useMemo)(()=>bj(r),[r]),P=wj(r),F=n?By(n.id):null,I=(0,Q.useRef)(F?.atBottom??!0);(0,Q.useLayoutEffect)(()=>{let e=b.current;return e&&F&&(e.scrollTop=F.atBottom?e.scrollHeight:F.top),()=>{e&&n&&zy(n.id,{top:e.scrollTop,atBottom:I.current})}},[n?.id]);let L=()=>{let e=b.current;e&&(I.current=e.scrollHeight-e.scrollTop-e.clientHeight<48,n&&zy(n.id,{top:e.scrollTop,atBottom:I.current}))};(0,Q.useEffect)(()=>{I.current&&b.current?.scrollTo?.({top:b.current.scrollHeight,behavior:`auto`})},[r.length,x,o.length,c.length]);let ee=e=>{e.shiftKey&&(e.key===`Tab`||e.code===`Tab`)&&(e.preventDefault(),e.stopPropagation(),p())},R=e===`inline`,z=R?`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:ee,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)(Js,{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)(bc,{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`)})]}),R&&n&&(0,$.jsx)(gj,{}),(0,$.jsxs)(`div`,{className:z,children:[(0,$.jsxs)(jy.div,{ref:b,onScroll:L,initial:R?{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)(Fo,{className:`mb-2 h-8 w-8 text-accent-primary/60`}),(0,$.jsx)(`p`,{className:`text-sm font-medium text-foreground/70`,children:M}),(0,$.jsx)(`p`,{className:`mt-1 max-w-[280px] text-xs`,children:t(`emptyHint`)})]}),r.map((e,i)=>{if(e.role===`system`){if(kj(e.content))return null;if(ne){let t=VD(e.content);if(t)return(0,$.jsx)(xj,{row:t},e.id)}let n=N.byMessageId.get(e.id);return n?yj(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)(nc,{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)(ij,{decision:n.decision})]},e.id):(0,$.jsx)(nj,{envelope:n,conversationId:e.conversation_id},e.id):(N.duplicateMessageIds.has(e.id)||Dj.has(e.id)||(Dj.add(e.id),console.warn(`[agent-chat] skipping unrenderable system message ${e.id}`)),null)}if(ne&&HD(e))return(0,$.jsx)(Sj,{content:e.content,contextRefs:e.context_refs},e.id);let o=P.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:Et(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:D,onOpenRef:j,contextRefs:e.context_refs,deliveryStatus:e.delivery_status,deliveryReceipt:e.delivery_receipt,conversationId:e.conversation_id,attachments:(e.attachment_ids??[]).map(e=>O.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)(nc,{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:Et(n?.provider)}),(0,$.jsx)(zb,{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)(BD,{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=>O.get(e)).filter(e=>!!e)},`${n?.id}:${e.queueId}`))})]}),(0,$.jsx)(j_,{initial:!1,children:n&&(N.pinned.length>0||P.pinned.length>0)&&(0,$.jsx)(fj,{pinned:N.pinned,proposals:P.pinned,projectId:D,conversationId:n.id,inline:R},`agent-pr-pinned-dock`)}),R?(0,$.jsx)(`div`,{className:`shrink-0 px-4 pb-4`,children:(0,$.jsxs)(jy.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)(jA,{active:a,radius:`1rem`,inset:-3}),(0,$.jsx)(bA,{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)(jA,{active:a,radius:`0.75rem`,inset:-2}),(0,$.jsx)(bA,{hideProjectSelector:!0,queueEditRequest:_})]})]}),C&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Tj,{jobId:C.jobId,projectId:C.projectId,onClose:w})}),T&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Ej,{loop:T,onClose:E})}),h&&(0,$.jsx)(Vb,{tools:y,streaming:a,onClose:()=>g(!1)})]})}var Mj=8,Nj=3e3;function Pj(){let{t:e}=K(`agent`),{conversations:t,active:n,selectConversation:r,deleteConversation:i,startNewConversation:a,streamingConversationIds:o,liveByConversation:s}=qN(),[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>Mj,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},Nj)},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)(gn,{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)(Wo,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`})]}),(0,$.jsx)(j_,{children:c&&(0,$.jsxs)(jy.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)(On,{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)(jy.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)(Dn,{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)(Fj,{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 Fj({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)(An,{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)(vn,{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)(Nn,{className:`h-3.5 w-3.5`})})]}):(0,$.jsxs)(jy.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:qb(e.updated_at),children:Kb(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)(vn,{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)(An,{className:`h-3.5 w-3.5`})})]})}var Ij=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}));Ij.displayName=`Input`;var Lj=6e4,Rj={data:null,fetchedAt:0,inFlight:null,error:null},zj=new Set;function Bj(){zj.forEach(e=>{try{e()}catch{}})}function Vj(){return Rj.data!==null&&Date.now()-Rj.fetchedAt<Lj}async function Hj(e){if(Rj.inFlight)return Rj.inFlight;let t=(async()=>{let t=await fetch(`${Ke}/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 Rj.data=n,Rj.fetchedAt=Date.now(),Rj.error=null,Rj.inFlight=null,Bj(),Rj.data})().catch(t=>{throw Rj.inFlight=null,e?.aborted?t:(Rj.error=t instanceof Error?t:Error(String(t)),Bj(),Rj.error)});return Rj.inFlight=t,t}var Uj=!1;function Wj(){Uj||typeof window>`u`||(window.addEventListener(`focus`,()=>{Rj.fetchedAt=0,Rj.data=null,Hj().catch(()=>{})}),Uj=!0)}function Gj(){let[,e]=(0,Q.useState)(0),[t,n]=(0,Q.useState)(()=>!Vj()),[r,i]=(0,Q.useState)(Rj.error);(0,Q.useEffect)(()=>{Wj();let t=()=>{e(e=>e+1),i(Rj.error),n(!1)};zj.add(t);let r=new AbortController;return!Vj()&&!Rj.inFlight?(n(!0),Hj(r.signal).catch(e=>{r.signal.aborted||i(e instanceof Error?e:Error(String(e)))}).finally(()=>{r.signal.aborted||n(!1)})):Rj.inFlight&&Rj.inFlight.catch(()=>{}).finally(()=>{r.signal.aborted||n(!1)}),()=>{r.abort(),zj.delete(t)}},[]);let a=(0,Q.useCallback)(async()=>{Rj.fetchedAt=0,Rj.data=null,Rj.error=null,n(!0);try{await Hj()}catch(e){i(e instanceof Error?e:Error(String(e)))}finally{n(!1)}},[]);return{status:Rj.data,isLoading:t,error:r,recheck:a}}var Kj={claude:{icon:`🤖`,label:`Claude`},codex:{icon:`⚡`,label:`Codex`},gemini:{icon:`✨`,label:`Gemini`},kimi:{icon:`🌙`,label:`Kimi`}};function qj(e){return e.toLowerCase().normalize(`NFKD`).replace(/[̀-ͯ]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`project`}function Jj({blueprint:e,onSubmit:t,onBack:n,submitting:r,error:i,errorDetail:a}){let{t:o}=K(`builder`),{status:s}=Gj(),[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/${qj(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)(Ij,{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)(Ij,{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}=Kj[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)(Ts,{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)(fc,{className:`mr-1.5 h-3.5 w-3.5`}),o(r?`commit.creating`:`commit.submit`)]})]})]})}function Yj({session:e,autoFocus:t=!1}){let{t:n}=K(`builder`),{t:r}=K(`agent`),{availableIds:i,labels:a}=gA(),o=Tt(e.provider),s=[e.provider,...i].filter((e,t,n)=>n.indexOf(e)===t).filter(Tt),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)(Os,{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)(PE,{label:r(`provider.label`),value:e.provider,options:s.map(e=>({value:e,label:c(e)})),icon:Fo,onSelect:e.setProvider,disabled:!o||e.busy||!e.conversationReady,testId:`builder-provider-selector`}),(0,$.jsx)(KO,{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)(PE,{label:r(`effort.label`),value:e.effort,options:e.efforts.map(e=>({value:e,label:r(`effort.${e}`)})),icon:Ss,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)(kn,{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)(At,{className:`h-4 w-4`})})]})]})}function Xj(e){let t=Date.parse(e.includes(`T`)?e:e.replace(` `,`T`)+`Z`);return Number.isFinite(t)?gr(new Date(t),{addSuffix:!0,locale:qe()}):``}function Zj({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)(jy.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)(As,{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)(Cn,{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)(j_,{initial:!1,children:e.map(e=>{let t=e.productName||e.title||a(`recent.untitled`),c=o===e.id;return(0,$.jsxs)(jy.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)(Tn,{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)(Is,{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)(jn,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),a(`recent.pendingIssue`)]}),e.updatedAt&&(0,$.jsx)(`span`,{className:`opacity-80`,children:Xj(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)(vn,{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)(Nn,{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)(An,{className:`h-3.5 w-3.5`,"aria-hidden":!0})})})]},e.id)})})})]})}function Qj({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?Mn:kn,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)(Cn,{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)(j_,{mode:`wait`,initial:!1,children:(0,$.jsx)(jy.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)(j_,{mode:`wait`,initial:!1,children:(0,$.jsx)(jy.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)(jy.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 $j=`specrails-desktop:milestone-launch-mode`,eM=`specrails-desktop:milestone-sequential-plans`;function tM(){try{return localStorage.getItem(`specrails-desktop:milestone-launch-mode`)===`parallel`?`parallel`:`sequential`}catch{return`sequential`}}function nM(e){try{localStorage.setItem($j,e)}catch{}}var rM=`specrails-desktop:milestone-auto-advance`;function iM(){try{return localStorage.getItem(rM)===`true`}catch{return!1}}function aM(e){try{localStorage.setItem(rM,e?`true`:`false`)}catch{}}function oM(){try{return localStorage.getItem(`specrails-desktop:milestone-sequential-plans`)===null?!1:(localStorage.removeItem(eM),!0)}catch{return!1}}function sM(e){return`M${e}`}function cM(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 lM(e){try{let t=await e.json();return t&&typeof t==`object`?t:{}}catch{return{}}}async function uM(e,t,n=tM(),r={}){let i=typeof r==`function`?{fetchImpl:r}:r,a=i.fetchImpl??fetch,o=i.autoAdvance??iM(),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 lM(s);if(!s.ok){let e=typeof c.error==`string`?c.error:`http_${s.status}`;return{ok:!1,reason:cM(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 dM(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 lM(i);return i.ok?{ok:!0,chain:zt(a.chain)}:{ok:!1,error:typeof a.error==`string`?a.error:`http_${i.status}`,...typeof a.detail==`string`?{detail:a.detail}:{}}}function fM(e,t,n=fetch){return dM(e,t,`resume`,n)}function pM(e,t,n=fetch){return dM(e,t,`cancel`,n)}async function mM(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 lM(i);return i.ok?{ok:!0,chain:zt(a.chain)}:{ok:!1,error:typeof a.error==`string`?a.error:`http_${i.status}`,...typeof a.detail==`string`?{detail:a.detail}:{}}}var hM=[`Problem Statement`,`Proposed Solution`,`Out of Scope`,`Technical Considerations`,`Estimated Complexity`],gM={problemMinChars:200,solutionMinChars:500,outOfScopeMinBullets:3,technicalMinBullets:5,criteriaMin:6,criteriaMax:10,criterionMinChars:20},_M=new Set([`scaffold`,`feature`,`verification`]),vM=new Set([`critical`,`high`,`medium`,`low`]),yM=/^(?:todo|tbd|n\/?a|works?|test(?: it)?|criterion|acceptance criterion)$/i;function bM(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:null}function xM(e){return e.trim().toLocaleLowerCase(`en-US`)}function SM(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 CM(e){return e.split(/\r?\n/).filter(e=>/^\s*[-*+]\s+\S/.test(e)).length}function wM(e,t){let n=[],r=bM(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=bM(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:``;_M.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=xM(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:``;vM.has(d)||o(n,`priority`,`invalid_priority`,`Spec ${i} needs a valid priority.`);let f=typeof r.description==`string`?r.description.trim():``,p=SM(f);(!/^## Problem Statement(?:\r?\n|$)/.test(f)||p.headings.length!==hM.length||p.headings.some((e,t)=>e!==hM[t]))&&o(n,`description`,`canonical_sections`,`Spec ${i} is missing the canonical sections.`);for(let e of hM)(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`,gM.problemMinChars],[`Proposed Solution`,gM.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`,gM.outOfScopeMinBullets],[`Technical Considerations`,gM.technicalMinBullets]]){let r=p.bodies.get(e)??``;r&&CM(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<gM.criteriaMin||h.length>gM.criteriaMax)&&o(n,`acceptanceCriteria`,`criteria_count`,`Spec ${i} needs ${gM.criteriaMin}-${gM.criteriaMax} acceptance criteria.`,{count:h.length,min:gM.criteriaMin,max:gM.criteriaMax});let g=new Set;h.forEach((e,t)=>{let r=typeof e==`string`?e.trim():``;if(r.length<gM.criterionMinChars||yM.test(r)){o(n,`acceptanceCriteria`,`criterion_quality`,`Spec ${i} criterion ${t+1} is not concrete.`,{criterion:t+1});return}let a=xM(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 TM=new Set([`batch_incomplete`,`spec_count`]);function EM(e,t,n,r,i={}){let a=It(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=>!TM.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 DM(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 OM(e,t){let n={n:t.specIndex===null?``:t.specIndex+1,...t.params??{}};return e(DM(t),{...n,defaultValue:t.message})}var kM=new Set([`gh_not_installed`,`gh_not_authenticated`,`gh_scope`,`gh_repo_exists`,`gh_network`]);function AM(e){return`progress.githubErrors.${e&&kM.has(e)?e:`generic`}`}var jM=[`create-dir`,`git-init`,`assemble`,`blueprint`,`tickets`,`register`,`github`],MM={minSpecs:5,maxSpecs:10};function NM(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 PM(e,t){let n=e&&typeof e==`object`?e:{},r=new Date().toISOString();if(n.continuing){let e=NM(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 FM(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 IM(e,t){let{t:n}=K(`builder`),{registerHandler:r,unregisterHandler:i}=Ze(),{setActiveProjectId:a}=lt(),[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`),[ee,R]=(0,Q.useState)(null),[z,B]=(0,Q.useState)([]),[V,H]=(0,Q.useState)(``),[U,te]=(0,Q.useState)([]),[ne,re]=(0,Q.useState)(`medium`),[ie,ae]=(0,Q.useState)(``),[oe,se]=(0,Q.useState)({status:`idle`}),[ce,le]=(0,Q.useState)([]),[ue,de]=(0,Q.useState)(!1),[fe,pe]=(0,Q.useState)(!1),me=ee??V,he=(0,Q.useMemo)(()=>{let e=mt(I,me);return U.filter(t=>e.includes(t))},[me,I,U]),W=(0,Q.useRef)(null),ge=(0,Q.useRef)(null),_e=(0,Q.useRef)(I),ve=(0,Q.useRef)(null),ye=(0,Q.useRef)(!1),be=(0,Q.useRef)(ne),xe=(0,Q.useRef)(he),Se=(0,Q.useRef)(ee),G=(0,Q.useRef)(!1),Ce=(0,Q.useRef)(t.onFinished);(0,Q.useEffect)(()=>{W.current=o},[o]),(0,Q.useEffect)(()=>{_e.current=I},[I]),(0,Q.useEffect)(()=>{ve.current=w},[w]),(0,Q.useEffect)(()=>{be.current=ne},[ne]),(0,Q.useEffect)(()=>{xe.current=he},[he]),(0,Q.useEffect)(()=>{Se.current=ee},[ee]),(0,Q.useEffect)(()=>{Ce.current=t.onFinished},[t.onFinished]);let we=(0,Q.useCallback)(async()=>{let e=W.current;if(e)return e;if(ge.current)return ge.current;let t=fetch(`/api/blueprint/conversations`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:_e.current,...Se.current?{model:Se.current}:{}})}).then(e=>e.json()).then(e=>e.conversation?(W.current=e.conversation.id,s(e.conversation.id),e.conversation.id):null).catch(()=>null).finally(()=>{ge.current=null});return ge.current=t,t},[]),Te=(0,Q.useCallback)(async()=>{de(!0);try{let e=await(await fetch(`/api/blueprint/conversations?resumable=1`)).json();le(FM(e.conversations))}catch{le([])}finally{de(!1)}},[]);(0,Q.useEffect)(()=>{e&&Te()},[e,Te]),(0,Q.useEffect)(()=>{if(!e)return;let t=!1;return B([]),H(``),te([]),re(``),fetch(`/api/blueprint/models?provider=${encodeURIComponent(I)}`).then(e=>e.json()).then(e=>{if(t)return;B(e.models??[]);let n=e.defaultModel??e.models?.[0]?.value??``,r=e.efforts??[],i=mt(I,n),a=r.filter(e=>i.includes(e));H(n),te(r),re(e=>a.includes(e)?e:Ct(I,n)??``)}).catch(()=>{}),()=>{t=!0}},[e,I]);let{availableIds:Ee}=gA({enabled:e});(0,Q.useEffect)(()=>{if(W.current||Ee.length===0||Ee.includes(I))return;let e=Ee.filter(Tt);e.length!==0&&(L(wt(e)),R(null))},[Ee,I]);let De=(0,Q.useCallback)(e=>{L(e),R(null);let t=W.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=>{R(e);let t=mt(I,e),n=U.filter(e=>t.includes(e));re(t=>n.includes(t)?t:Ct(I,e)??``);let r=W.current;r&&fetch(`/api/blueprint/conversations/${r}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({model:e})}).catch(()=>{})},[I,U]);(0,Q.useEffect)(()=>{if(!e)return;let t=`builder-session`;return r(t,e=>{let t=e,r=W.current!==null&&t.conversationId===W.current,i=ve.current!==null&&t.commitId===ve.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),se({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=NM(t);d(null),_(!0),e&&se({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=Ut(t.blueprint),i=t.rawBlueprint===void 0?t.blueprint:t.rawBlueprint;if(!r&&t.snapshot===void 0){let e=an(n);r=e.blueprint,i=e.rawBlueprint}r&&(p(r),h(i)),se(e=>t.snapshot===void 0?r?{status:`accepted`,repaired:!1,repairAttempted:!1,at:new Date().toISOString()}:e:PM(t.snapshot,e))}else if(t.type===`blueprint.error`&&r)d(null),_(!1),se(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`&&!ye.current&&(ye.current=!0,J.warning(n(AM(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&&(G.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||fe)return;l(e=>[...e,{role:`user`,content:r,createdAt:new Date().toISOString(),...t.intent?{intent:t.intent}:{}}]),_(!0);let i=be.current,a=xe.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,...Se.current?{model:Se.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,fe,we,n]),Ae=(0,Q.useCallback)(async e=>{if(!g){pe(!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`);W.current=n.conversation.id,s(n.conversation.id),n.conversation.provider&&L(n.conversation.provider),R(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=Ut(n.blueprint);p(r),h(r?n.rawBlueprint??n.blueprint:null),se(PM(n.snapshot,{status:`idle`})),d(null),_(!1),y(`chat`),x(null),C(null),D([]),ae(``)}catch{J.error(n(`recent.resumeFailed`))}finally{pe(!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}`);le(t=>t.filter(t=>t.id!==e))}catch{J.error(n(`recent.discardFailed`))}},[n]),Me=(0,Q.useCallback)(async()=>{let e=W.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(ne?{reasoningEffort:ne}:{})});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,ne,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||G.current||(G.current=!0,F(!0),x(null),C(null),D([]),ye.current=!1,fetch(`/api/blueprint/commit`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({blueprint:m??f,...e,...W.current?{conversationId:W.current}:{}})}).then(async e=>{let t=await e.json().catch(()=>({}));e.status===202&&t.commitId?(T(t.commitId),ve.current=t.commitId,y(`progress`)):(x(t.error??`generic`),C(t.detail??null)),G.current=!1,F(!1)}).catch(()=>{G.current=!1,F(!1),x(`generic`),C(null)}))},[f,m]),Ie=(0,Q.useCallback)(async()=>{if(!(!O||A)){j(!0);try{let e=tM(),t=iM(),r=await uM(O,1,e,{autoAdvance:t}),i=sM(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=W.current;e&&fetch(`/api/blueprint/conversations/${e}/abort`,{method:`POST`}).catch(()=>{}),s(null),W.current=null,ge.current=null,l([]),d(null),p(null),h(null),se({status:`idle`}),le([]),pe(!1),_(!1),y(`chat`),x(null),C(null),T(null),D([]),ye.current=!1,k(null),N(!1),j(!1),G.current=!1,F(!1),L(`claude`),R(null),B([]),H(``),te([]),re(`medium`),ae(``)},[]),ze=It(f),Be=Object.values(ze).some(Boolean)||c.length>0||ie.trim().length>0,Ve=(0,Q.useMemo)(()=>wM(m??f,{milestoneLabel:`M1`,minSpecs:MM.minSpecs,maxSpecs:MM.maxSpecs,requireScaffold:!0}),[f,m]),He=oe.status===`generating`,Ue=(0,Q.useMemo)(()=>EM(f,m??f,Ve,MM,{generating:He}),[f,m,Ve,He]),We=(0,Q.useMemo)(()=>{if(Ve.valid)return null;let e=Ve.issues[0];return e?OM(n,e):null},[Ve,n]),Ge=(0,Q.useMemo)(()=>tn(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&&!fe,conversationId:o,dirty:Be,canProposeCommit:Ve.valid,specQualityDetail:We,readiness:Ue,snapshot:oe,generation:Ge,recent:ce,recentLoading:ue,resume:Ae,discardRecent:je,repairSnapshot:Me,showSurpriseMe:c.length<=1&&v===`chat`,provider:I,model:ee,models:z,efforts:he,effort:ne,draft:ie,setDraft:ae,setEffort:re,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 LM={done:`bg-accent-success`,onReview:`bg-accent-warning`,inProgress:`bg-accent-info animate-pulse`,failed:`bg-destructive`,todo:`bg-muted-foreground/25`},RM={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=Xt(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:en(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`,LM[e.key]),style:{width:`${e.pct}%`},title:`${n(`milestoneProgress.legend.${e.key}`)} · ${e.count}`},e.key))})}function BM({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`,RM[e]),children:t(`milestoneProgress.state.${e}`)})}function VM(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 HM({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&&Wt.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)(Cn,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}),o==null?i(`milestoneProgress.state.running`):i(`milestoneProgress.rail.running`,{elapsed:xr(o)})]}):s?(0,$.jsx)(ij,{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)(ps,{className:`h-3 w-3`,"aria-hidden":!0}),i(`milestoneProgress.rail.review`)]})]})}function UM({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)(Pn,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}):(0,$.jsx)(_s,{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 WM({chain:e,busy:t=!1,onResume:n,onCancel:r,onSetAutoAdvance:i}){let{t:a}=K(`builder`),o=Yt(e),s=e.status===`paused`,c=Lt(e),l=Qt(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)(Is,{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)(Cn,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Tn,{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)(Cn,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Tn,{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)(Nn,{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)(ec,{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)(_s,{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)(B,{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)(Mo,{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)(UM,{checked:e.autoAdvance,disabled:t,onChange:t=>i(e.id,t),testId:`milestone-chain-auto-advance`})})]})}function GM({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=VM(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:Vt(e.n)}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] font-medium`,children:e.title}),(0,$.jsx)(BM,{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:en(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)(WM,{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)(HM,{rail:e,now:d,onReview:r,onOpenRail:i},e.railIndex))})]})}function KM({projectId:e}){let{t}=K(`builder`),n=y(),{setActiveProjectId:r}=lt(),{progress:i,hasBlueprint:a}=Jt(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 fM(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 mM(e,n,r);i.ok?(aM(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 pM(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)(Cn,{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)(GM,{progress:c,chainBusy:o,onReview:e=>l(ae?`/review/${e}`:`/`),onOpenRail:()=>l(`/`),onResume:u,onCancel:f,onSetAutoAdvance:d,className:`bg-card/60`})}):null}var qM={surprise:Nc,approve:fc};function JM({kind:e,mode:t,onAction:n,disabled:r=!1,createdAt:i,className:a}){let{t:o}=K(`builder`),s=Ay(),c=t===`settled`,l=c?vn:qM[e],u=i?YM(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)(vn,{className:`h-3 w-3`,"aria-hidden":!0}):(0,$.jsx)(kn,{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)(B,{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)(jy.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 YM(e){let t=Date.parse(e);if(!Number.isFinite(t))return null;try{return Mb(t,`p`,{locale:qe()})}catch{return null}}var XM=`w-full rounded-2xl border border-border/60 bg-card/90 p-3 shadow-2xl backdrop-blur-xl`;function ZM({variant:e}){let{t}=K(`builder`),{builderMode:n}=qN(),r=n.session,[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(()=>iM()),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)(jy.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)(kn,{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)(xA,{active:!0,inset:-3,radius:`1rem`}),(0,$.jsx)(jy.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:XM,children:(0,$.jsx)(Yj,{session:r,autoFocus:!0})})]}),(0,$.jsx)(Zj,{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)(JM,{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)(j_,{initial:!1,children:[p&&(0,$.jsx)(JM,{kind:`surprise`,mode:`offer`,onAction:r.surpriseMe,disabled:!r.conversationReady},`surprise`),m&&(0,$.jsx)(JM,{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&&Ht(r.streamBuffer)&&(0,$.jsx)(zD,{role:`assistant`,content:Ht(r.streamBuffer),streaming:!0}),r.generation.generating||r.snapshot.status===`repairing`||r.snapshot.status===`generating`?(0,$.jsx)(Qj,{specsStarted:r.generation.specsStarted,snapshot:r.snapshot}):(0,$.jsx)(zb,{tool:null})]})]}),(0,$.jsx)(`div`,{className:`shrink-0 px-4 pb-4`,children:(0,$.jsx)(jy.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(XM,e===`inline`&&`mx-auto max-w-[680px]`),children:(0,$.jsx)(Yj,{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)(Jj,{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:jM.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)(Jo,{className:`h-3.5 w-3.5 text-muted-foreground/40`}),n?.status===`running`&&(0,$.jsx)(Cn,{className:`h-3.5 w-3.5 animate-spin text-accent-info`}),n?.status===`done`&&(0,$.jsx)(vn,{className:`h-3.5 w-3.5 text-accent-success`}),n?.status===`warning`&&(0,$.jsx)(jn,{className:`h-3.5 w-3.5 text-accent-warning`}),n?.status===`failed`&&(0,$.jsx)(Nn,{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(AM(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)(vn,{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)(KM,{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)(Cn,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(fc,{className:`mr-1.5 h-3.5 w-3.5`}),t(`done.launchM1`)]}),tM()===`sequential`&&(0,$.jsx)(UM,{checked:o,onChange:e=>{s(e),aM(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 QM=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`),$M={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 eN({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,Bb.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)(xn,{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`,$M[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)(Nn,{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:QM,children:(0,$.jsx)(pr,{remarkPlugins:[mr],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)(qo,{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 tN={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 nN({blueprint:e,milestoneLabel:t=`M1`,snapshot:n}){let{t:r}=K(`builder`),{t:i}=K(`tickets`),a=It(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)(Cn,{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)(vn,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`,"aria-label":`✓`}):(0,$.jsx)(Nn,{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)(Is,{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)(xn,{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`,tN[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)(Cn,{className:`h-2.5 w-2.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Bs,{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)(Bs,{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)(eN,{spec:e.m1Specs[o],index:o,milestoneLabel:t,onClose:()=>s(null)})]})}var rN={done:vn,pending:Jo,blocked:jn,writing:Cn},iN={done:`text-accent-success`,pending:`text-muted-foreground/50`,blocked:`text-accent-warning`,writing:`text-accent-info animate-spin`};function aN({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=rN[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`,iN[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)(j_,{initial:!1,mode:`wait`,children:[d&&(0,$.jsxs)(jy.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)(Cn,{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)(jy.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)(jn,{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)(uc,{className:`mr-1.5 h-3 w-3`,"aria-hidden":!0}),c(`snapshot.rejected.retry`)]})]},`rejected`),p&&(0,$.jsxs)(jy.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)(jn,{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)(kn,{className:`mr-1.5 h-3 w-3`,"aria-hidden":!0}),c(`snapshot.halted.resume`)]})]},`halted`),t.status===`accepted`&&t.repaired&&!p&&(0,$.jsxs)(jy.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)(kn,{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)(Mn,{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)(Wo,{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:OM(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)(Mn,{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)(fc,{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 oN(){let{t:e}=K(`agent`),{t}=K(`builder`),{minimize:n,startNewConversation:r,cycleTier:i,active:a,draftPinnedProjectId:o,setPinnedProject:s,builderMode:c}=qN(),[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}=zn({enabled:!0,allowMove:!0,minWidth:400,minHeight:420,anchorFromCurrentRect:!0,persistKey:`specrails-desktop:agent-panel-geom`});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(jy.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)(xA,{active:d&&c.session.messages.length===0&&c.session.phase===`chat`,inset:-3}),(0,$.jsx)(Fo,{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)(Pj,{})]}),(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)(Dn,{className:`h-4 w-4`})}),(0,$.jsx)(Ic,{}),(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)(Ws,{className:`h-4 w-4`}):(0,$.jsx)(Us,{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)(Nn,{className:`h-4 w-4`})})]})]}),d?(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,$.jsx)(ZM,{variant:`floating`}),(0,$.jsxs)(`aside`,{className:`flex w-72 shrink-0 flex-col border-l border-border/40 lg:w-80`,children:[(0,$.jsx)(nN,{blueprint:c.session.blueprint,snapshot:c.session.snapshot}),c.session.phase===`chat`&&(0,$.jsx)(aN,{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)(Aj,{variant:`floating`})]}),!l&&(0,$.jsx)(`div`,{className:`pointer-events-none fixed inset-0 z-[61] [&>*]:pointer-events-auto`,children:(0,$.jsx)(Qn,{handles:g})})]})}var sN=`specrails-desktop:agent-bubble-pos`,cN=56,lN=12;function uN(){try{let e=localStorage.getItem(sN);if(!e)return null;let t=JSON.parse(e);if(typeof t?.left==`number`&&typeof t?.top==`number`)return t}catch{}return null}function dN(e){let t=Math.max(lN,window.innerWidth-cN-lN),n=Math.max(lN,window.innerHeight-cN-lN);return{left:Math.min(Math.max(lN,e.left),t),top:Math.min(Math.max(lN,e.top),n)}}function fN(){return{left:Math.round(window.innerWidth/2-cN/2),top:window.innerHeight-cN-20}}function pN(){let{t:e}=K(`agent`),{t}=K(`builder`),{open:n,isStreaming:r,active:i,builderMode:a}=qN(),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(()=>dN(uN()??fN())),u=ky(0),d=ky(0),f=(0,Q.useRef)(!1),p=a.active?a.session.busy:r;(0,Q.useEffect)(()=>{let e=()=>l(e=>dN(e));return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let m=(0,Q.useCallback)(e=>{try{localStorage.setItem(sN,JSON.stringify(e))}catch{}},[]);return(0,$.jsxs)(jy.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=dN({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)(xA,{active:a.active&&a.session.messages.length===0&&a.session.phase===`chat`,inset:-4}),(0,$.jsx)(Fo,{className:`h-5 w-5 text-accent-primary`}),p&&(0,$.jsx)(jy.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)(j_,{initial:!1,children:(o||p)&&(0,$.jsx)(jy.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 mN=`specrails-desktop:uiMode`;function hN(){if(!b)return`kanban`;try{return localStorage.getItem(mN)===`kanban`?`kanban`:`agent`}catch{return`agent`}}function gN(e){try{localStorage.setItem(mN,e)}catch{}}var _N=(0,Q.createContext)(null);function vN({children:e,initialMode:t,persist:n=!0}){let[r,i]=(0,Q.useState)(()=>t??hN()),a=(0,Q.useCallback)(e=>{b&&(i(e),n&&gN(e))},[n]),o=(0,Q.useCallback)(()=>{i(e=>{if(!b)return`kanban`;let t=e===`kanban`?`agent`:`kanban`;return n&&gN(t),t})},[n]),s=(0,Q.useMemo)(()=>({uiMode:r,setUiMode:a,toggleUiMode:o}),[r,a,o]);return(0,$.jsx)(_N.Provider,{value:s,children:e})}var yN={uiMode:`kanban`,setUiMode:()=>{},toggleUiMode:()=>{}};function bN(){return(0,Q.useContext)(_N)??yN}var xN={streamingText:``,isStreaming:!1,liveTools:[],turnTools:[],queued:[]},SN=`specrails-desktop:favorite-agent-conversations`;function CN(){try{let e=localStorage.getItem(SN);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 wN(e){try{localStorage.setItem(SN,JSON.stringify([...e]))}catch{}}function TN(e,t){let n=new Set(t.map(e=>e.id));return new Set([...e].filter(e=>n.has(e)))}var EN=`specrails-desktop:agent-tier-last`;function DN(){try{let e=localStorage.getItem(EN),t=e===null?0:Number.parseInt(e,10);return t===0||t===1||t===2||t===3?t:0}catch{return 0}}function ON(e){try{localStorage.setItem(EN,String(e))}catch{}}var kN=new Set([`completed`,`merged`,`discarded`,`superseded`]);function AN(e,t){return JSON.stringify(e)===JSON.stringify(t)}function jN(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 MN(e,t){if(t.supersedesDeliveryId===e.prDeliveryId)return 1;if(e.supersedesDeliveryId===t.prDeliveryId)return-1;let n=jN(e),r=jN(t);return n==null||r==null?null:r<n?-1:+(r>n)}function NN(e,t){let n=null;for(let r of e){if(r.supersedesDeliveryId!==t)continue;if(!n){n=r;continue}let e=jN(n),i=jN(r);(e==null||i==null||i>=e)&&(n=r)}return n}function PN(e,t){let n=t.restoredFromDeliveryId;if(!n)return!1;let r=NN(e,t.prDeliveryId);return!r||r.prDeliveryId===n}function FN(e,t){let n=e.filter(e=>e.role===`system`).map(e=>_o(e.content)).filter(e=>e!==null),r=[...n].reverse().find(e=>e.prDeliveryId===t.prDeliveryId),i=PN(n,t);if(r){let e=kN.has(r.decision),n=kN.has(t.decision),a=Ft(r.updatedAt,t.updatedAt);if(a===-1||a===0&&!AN(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=MN(e,t);if(n===-1||(n===0||n===null)&&!kN.has(e.decision)&&t.supersedesDeliveryId!==e.prDeliveryId)return!0}return!1}function IN(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=_o(e.content);return!t||t.prDeliveryId!==n||kN.has(t.decision)?e:(r=!0,{...e,content:JSON.stringify({...t,decision:`discarded`})})});return r?i:e}function LN(e,t){let n=e.filter(e=>e.role===`system`).map(e=>_o(e.content)).filter(e=>e!==null);if(n.some(e=>e.restoredFromDeliveryId===t.prDeliveryId&&PN(n,e)))return e;let r=!1,i=e.map(e=>{if(e.role!==`system`)return e;let n=_o(e.content);return!n||n.railIndex!==t.railIndex||n.prDeliveryId===t.prDeliveryId||kN.has(n.decision)||MN(n,t)!==1?e:(r=!0,{...e,content:JSON.stringify({...n,decision:`superseded`})})});return r?i:e}function RN(e,t,n){if(FN(e,n))return e;let r=LN(IN(e,n),n),i=JSON.stringify(n),a=r.flatMap((e,t)=>e.role===`system`&&_o(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),BN=0,VN=0,HN={sent:0,received:1,read:2};function UN(e,t){return e&&(!t||HN[e]>=HN[t])?e:t}function WN(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=UN(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 GN({children:e}){let{registerHandler:t,unregisterHandler:n,connectionStatus:r}=Ze(),{uiMode:i}=bN(),{setActiveProjectId:a,activeProjectId:o}=lt(),s=gi(),c=(0,Q.useRef)(s);c.current=s;let l=ci(),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)(CN);(0,Q.useEffect)(()=>{let e=e=>{(e.key===SN||e.key===null)&&S(CN())};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)([]),I=(0,Q.useRef)([]);I.current=N;let[L,ee]=(0,Q.useState)(null),R=(0,Q.useRef)(null);R.current=L;let[z,B]=(0,Q.useState)(`claude`),[V,H]=(0,Q.useState)(null),[U,te]=(0,Q.useState)(()=>DN()),[ne,re]=(0,Q.useState)(null),ie=(0,Q.useRef)({provider:`claude`,model:null,tierLevel:0,effort:null});ie.current={provider:z,model:V,tierLevel:U,effort:ne};let ae=(0,Q.useRef)(null);ae.current=h?.id??null;let oe=(0,Q.useRef)(T);oe.current=T;let se=(0,Q.useRef)(new Set),ce=(0,Q.useRef)(new Set),le=(0,Q.useRef)(new Map),ue=(0,Q.useRef)(new Map),de=e=>{let t=UN(e.delivery_receipt,le.current.get(`${e.conversation_id}:m:${e.id}`));return t?{...e,delivery_receipt:t}:e},fe=(e,t)=>{let n=UN(t.deliveryReceipt,le.current.get(`${e}:q:${t.queueId}`));return n?{...t,deliveryReceipt:n}:t},pe=(0,Q.useRef)(new Set),me=(0,Q.useRef)(new Map),he=(0,Q.useRef)(new Map),W=(0,Q.useRef)(new Map),ge=(0,Q.useRef)(null),_e=(0,Q.useRef)(0),ve=(0,Q.useRef)(0),ye=(0,Q.useRef)(new Map),be=(0,Q.useCallback)(e=>{let t=ae.current;if(!t)return`untracked`;if(FN(b.current,e))return`stale`;if(!b.current.some(t=>t.role===`system`&&_o(t.content)?.prDeliveryId===e.prDeliveryId))return`untracked`;_e.current++;let n=RN(b.current,t,e);return b.current=n,v(n=>{if(!n.some(t=>t.role===`system`&&_o(t.content)?.prDeliveryId===e.prDeliveryId))return b.current=n,n;let r=RN(n,t,e);return b.current=r,r}),`accepted`},[]),xe=(0,Q.useCallback)((e,t)=>{E(n=>{let r=t(n.get(e)??xN),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===ae.current&&!t||w(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),G=(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(!F||typeof document>`u`)return;let e=()=>{if(document.visibilityState!==`visible`)return;let e=ae.current;e&&G(e)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[G]);let Ce=(h?T.get(h.id):void 0)??xN,we=Ce.streamingText,Te=Ce.isStreaming,Ee=Ce.liveTools,De=Ce.turnTools,Oe=Ce.queued,ke=(0,Q.useMemo)(()=>{let e=new Set;for(let[t,n]of T)n.isStreaming&&e.add(t);return e},[T]),Ae=(0,Q.useCallback)(async()=>{try{let e=await qa();m(e),S(t=>{let n=TN(CN(),e);return n.size===t.size&&[...n].every(e=>t.has(e))?t:(wN(n),n)})}catch{}},[]),je=(0,Q.useCallback)(async()=>{try{let e=await Co();O(e.enabled)}catch{O(!1)}},[]),Me=(0,Q.useCallback)(async()=>{try{let{any:e,installed:t}=await So();M(e),P(Array.isArray(t)?t:[])}catch{M(!0)}},[]),[Ne,Pe]=(0,Q.useState)(0);(0,Q.useEffect)(()=>F?(t(`agent-chat`,e=>{let t=e;if(!t)return;if(t.type===`desktop.project_recovered`){Pe(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;me.current.set(n,(me.current.get(n)??0)+1);let r=n===ae.current,i=e=>{W.current.set(n,WN(W.current.get(n)??[],e).slice(-500)),r&&(b.current=WN(b.current,e),v(t=>WN(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??ue.current.get(e);if(t.queueId&&le.current.set(e,UN(le.current.get(e),t.receipt)),a){let e=`${n}:m:${a}`;le.current.set(e,UN(le.current.get(e),t.receipt));let o=(r?b.current:W.current.get(n)??[]).find(e=>e.id===a);o&&i([de(o)])}xe(n,e=>({...e,queued:e.queued.map(e=>e.queueId===t.queueId?{...e,deliveryReceipt:UN(e.deliveryReceipt,t.receipt)}:e)}))}else if(t.type===`agent_stream`)Se(n),xe(n,e=>({...e,isStreaming:!0,streamingText:e.streamingText+(t.delta??``)}));else if(t.type===`agent_tool`)xe(n,e=>({...e,isStreaming:!0,liveTools:[...e.liveTools,{id:`t${BN++}`,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`)xe(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`){ye.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()}]}),xe(n,e=>({...xN,queued:e.queued,turnTools:e.liveTools.length?e.liveTools:e.turnTools}))}else if(t.type===`agent_error`){ye.current.delete(n),Se(n),xe(n,e=>({...xN,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&&se.current.has(t.queueId))return;xe(n,e=>{let r=UN(t.deliveryReceipt??t.delivery_receipt,le.current.get(`${n}:q:${t.queueId}`)),i={queueId:t.queueId??`srv-${VN++}`,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:UN(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(pe.current.has(t.messageId)){t.queueId&&se.current.add(t.queueId),xe(n,e=>({...e,queued:e.queued.filter(e=>e.queueId!==t.queueId)}));return}pe.current.add(t.messageId),t.queueId&&se.current.add(t.queueId),ue.current.set(`${n}:q:${t.queueId}`,t.messageId);let e=UN(t.delivery_receipt??t.deliveryReceipt,le.current.get(`${n}:q:${t.queueId}`)),r=[];t.assistantSegment&&r.push({...t.assistantSegment,conversation_id:n,role:`assistant`}),r.push(de({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),xe(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&&se.current.has(t.queueId))return;if(t.queueId&&se.current.add(t.queueId),xe(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&&ue.current.set(`${n}:q:${t.queueId}`,t.messageId);let e=UN(t.delivery_receipt??t.deliveryReceipt,le.current.get(`${n}:q:${t.queueId}`));i([de({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`)he.current.set(n,(he.current.get(n)??0)+1),t.messages?.length&&i(t.messages),xe(n,e=>({...e,queued:[]}));else if(t.type===`agent_queue_removed`){if(!t.queueId)return;se.current.add(t.queueId),ce.current.add(t.queueId),xe(n,e=>({...e,queued:e.queued.filter(e=>e.queueId!==t.queueId)}))}else if(t.type===`agent_queue_edited`)xe(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=go(e);if(t){_e.current++;let e=RN(b.current,n,t);b.current=e,v(e=>{let r=RN(e,n,t);return b.current=r,r})}}}),()=>n(`agent-chat`)):void 0,[t,n,xe,Se]);let Fe=(0,Q.useCallback)(async(e,t)=>{let n=++ve.current,r=me.current.get(e)??0;_e.current++;let{conversation:i,messages:a,pendingMessages:o,live:s}=await Za(e);if(t?.aborted)throw new DOMException(`Window transfer cancelled`,`AbortError`);if(n!==ve.current){if(t)throw new DOMException(`The mission changed during restoration`,`AbortError`);return}_e.current++;let c=WN(a,W.current.get(e)??[]).map(de);for(let e of c)(e.delivery_status===`delivered`||e.delivery_status===`interrupted`)&&pe.current.add(e.id);g(i),b.current=c,v(c),G(e),r===(me.current.get(e)??0)&&(o!==void 0||s)&&xe(e,t=>({...t,...s?{isStreaming:s.isStreaming,streamingText:s.streamingText}:{},queued:o?.filter(e=>!se.current.has(e.queueId)).map(t=>fe(e,t))??t.queued}))},[G,xe]),Ie=(0,Q.useCallback)(async()=>{let e=ae.current;if(!e)return;let t=_e.current,n=me.current.get(e)??0,r=y.current.get(e)??0;try{let i=await Za(e);if(ae.current!==e||_e.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===(me.current.get(e)??0)){let t=WN(i.messages,W.current.get(e)??[]).map(de);for(let e of t)(e.delivery_status===`delivered`||e.delivery_status===`interrupted`)&&pe.current.add(e.id);v(e=>WN(t,e.filter(e=>e.id.startsWith(`local-u-`)&&!t.some(t=>t.role===`user`&&t.content===e.content)))),xe(e,t=>({...t,...i.live?{isStreaming:i.live.isStreaming,streamingText:i.live.streamingText}:{},queued:i.pendingMessages?.filter(e=>!se.current.has(e.queueId)).map(t=>fe(e,t))??t.queued}))}let a=i.messages.filter(e=>e.role===`system`).map(e=>_o(e.content)).filter(e=>e!==null);if(a.length===0)return;v(t=>{let n=a.reduce((t,n)=>RN(t,e,n),t);return b.current=n,n})}catch{}},[xe]),Le=(0,Q.useCallback)(async()=>{try{let e=new Map(me.current),t=await Ya(),n=new Set(t.turns.map(e=>e.conversationId)),r=Date.parse(t.capturedAt),i=[...oe.current].flatMap(([t,i])=>{if(!i.isStreaming||n.has(t)||(e.get(t)??0)!==(me.current.get(t)??0))return[];let a=ye.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)!==(me.current.get(t)??0))continue;let i=ye.current.get(t);i&&Date.parse(i)>r||a.set(t,{...xN,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)!==(me.current.get(t)??0))continue;let r=a.get(t)??xN;a.set(t,{...r,isStreaming:!0,streamingText:n.streamingText??r.streamingText,queued:n.pendingMessages?.filter(e=>!se.current.has(e.queueId)).map(e=>fe(t,e))??r.queued})}return a});for(let e of i)ye.current.delete(e);let a=ae.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=()=>{Ae(),Ie()};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[Ie,Ae]),(0,Q.useEffect)(()=>{Ne&&(Ae(),Ie())},[Ne,Ae,Ie]);let Re=(0,Q.useRef)(r);(0,Q.useEffect)(()=>{let e=Re.current;Re.current=r,r===`connected`&&e!==`connected`&&(Ae(),je(),Me(),Ie(),Le())},[r,Ae,je,Me,Ie,Le]);let ze=(0,Q.useCallback)(async()=>{if(h)return h;if(l)throw Error(`This window is reserved for its mission.`);let e=await qa();if(m(e),S(t=>{let n=TN(CN(),e);return n.size===t.size&&[...n].every(e=>t.has(e))?t:(wN(n),n)}),e.length>0)return await Fe(e[0].id),e[0];let t=await Xa({});return m(e=>[t,...e]),g(t),v([]),t},[h,Fe]),Be=(0,Q.useCallback)(()=>{f(`open`),Ae(),je(),Me(),ze()},[Ae,je,Me,ze]),Ve=(0,Q.useCallback)(()=>f(`hidden`),[]),He=(0,Q.useCallback)(()=>f(`minimized`),[]),[Ue,We]=(0,Q.useState)(!1),Ge=(0,Q.useRef)(null),Ke=(0,Q.useCallback)(()=>{Ge.current?.abortAndReset(),We(!1)},[]),qe=IM(Ue,{onFinished:Ke});Ge.current=qe;let Je=(0,Q.useCallback)(()=>{l||(We(!0),i!==`agent`&&Be())},[i,Be]),Ye=(0,Q.useCallback)(()=>{f(e=>e===`open`?`minimized`:`open`),d!==`open`&&(Ae(),je(),Me(),ze())},[d,Ae,je,Me,ze]),Xe=(0,Q.useCallback)(async()=>{if(!u(h?.id))throw Error(`This mission is active in another window.`);if(h)return h;if(ge.current)return ge.current;let e=Xa({pinnedProjectId:R.current,provider:ie.current.provider,model:ie.current.model,tierLevel:ie.current.tierLevel,reasoningEffort:ie.current.effort}).then(e=>(oi(e.id),m(t=>[e,...t]),g(e),v([]),e)).finally(()=>{ge.current=null});return ge.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 Xe();me.current.set(r.id,(me.current.get(r.id)??0)+1);let i=me.current.get(r.id),a=he.current.get(r.id)??0,o=t?.queueId??`q-${Date.now()}-${VN++}`,s=new Date().toISOString();ye.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=oe.current.get(r.id)?.isStreaming===!0,d={queueId:o,text:n,contextRefs:t?.contextRefs,attachmentIds:t?.attachmentIds,deliveryMode:`queue`,deliveryReceipt:`sent`,timestamp:s};l?xe(r.id,e=>({...e,queued:e.queued.some(e=>e.queueId===o)?e.queued.map(e=>e.queueId===o?{...d,deliveryReceipt:UN(e.deliveryReceipt,d.deliveryReceipt),deliveryMode:e.deliveryMode??d.deliveryMode,timestamp:e.timestamp??d.timestamp}:e):[...e.queued,d]})):(v(e=>[...e,c]),xe(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 eo(r.id,n,{tierLevel:r.tier_level,attachments:f,queueId:o,contextRefs:e});if(s.removed){se.current.add(o),ce.current.add(o);let e=!l&&i===me.current.get(r.id);return ae.current===r.id&&v(e=>e.filter(e=>e.id!==c.id)),xe(r.id,t=>({...t,queued:t.queued.filter(e=>e.queueId!==o),...e?{isStreaming:!1}:{}})),e&&ye.current.delete(r.id),{accepted:!0,conversationId:r.id}}if(s.message){ue.current.set(`${r.id}:q:${o}`,s.message.id);let e=UN(s.message.delivery_receipt,le.current.get(`${r.id}:q:${o}`)),t=de({...s.message,...e?{delivery_receipt:e}:{}});return se.current.add(o),W.current.set(r.id,WN(W.current.get(r.id)??[],[t]).slice(-500)),ae.current===r.id&&v(e=>WN(e.filter(e=>e.id!==c.id),[t])),xe(r.id,e=>({...e,queued:e.queued.filter(e=>e.queueId!==o)})),s.duplicate&&Le(),{accepted:!0,conversationId:r.id}}if(a!==(he.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)),se.current.has(o)||xe(r.id,e=>e.queued.some(e=>e.queueId===o)?e:{...e,queued:[...e.queued,{...d,deliveryMode:s.deliveryMode??d.deliveryMode}]})):!u&&l&&!se.current.has(o)&&(xe(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 se.current.has(o)||a!==(he.current.get(r.id)??0)?{accepted:!0,conversationId:r.id}:(ye.current.delete(r.id),l?xe(r.id,e=>({...e,queued:e.queued.filter(e=>e.queueId!==o)})):(xe(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,Xe,xe,Le]),$e=(0,Q.useCallback)(async()=>{if(!(!h||!u(h.id)))try{await oo(h.id),he.current.set(h.id,(he.current.get(h.id)??0)+1),me.current.set(h.id,(me.current.get(h.id)??0)+1),xe(h.id,()=>null)}catch(e){J.error(e instanceof Error?e.message:`Failed to stop the agent.`)}},[h,xe]),et=(0,Q.useCallback)(async(e,t)=>{let n=h;if(!n||!u(n.id)||oe.current.get(n.id)?.queued.find(t=>t.queueId===e)?.deliveryMode===`steer`)return`conflict`;let r=await so(n.id,e,t);return r===`saved`&&xe(n.id,n=>({...n,queued:n.queued.map(n=>n.queueId===e?{...n,text:t}:n)})),r},[h,xe]),tt=(0,Q.useCallback)(async e=>{let t=h,n=t&&oe.current.get(t.id)?.queued.find(t=>t.queueId===e);if(!t||!u(t.id)||!n||n.deliveryMode===`steer`)return`conflict`;let r=await co(t.id,e);return r===`saved`?(me.current.set(t.id,(me.current.get(t.id)??0)+1),xe(t.id,t=>({...t,queued:t.queued.map(t=>t.queueId===e?{...t,deliveryMode:`steer`}:t)}))):ae.current===t.id&&Ie(),r},[h,xe,Ie]),nt=(0,Q.useCallback)(async e=>{let t=h,n=t&&oe.current.get(t.id)?.queued.find(t=>t.queueId===e);if(!t||!u(t.id)||!n||n.deliveryMode===`steer`)return`conflict`;let r=await lo(t.id,e);return r===`saved`?(se.current.add(e),ce.current.add(e),me.current.set(t.id,(me.current.get(t.id)??0)+1),xe(t.id,t=>({...t,queued:t.queued.filter(t=>t.queueId!==e)}))):ae.current===t.id&&Ie(),r},[h,xe,Ie]),rt=(0,Q.useCallback)(e=>se.current.has(e)&&!ce.current.has(e),[]),it=(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 Qa(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]),at=(0,Q.useCallback)(async e=>{u(h?.id)&&(ON(e),h?await it({tierLevel:e}):te(e))},[h,it]),K=(0,Q.useCallback)(async()=>{let e=((h?.tier_level??U)+1)%4;await at(e)},[h,U,at]),q=(0,Q.useCallback)(async e=>{h?await it({provider:e}):(B(e),H(null),re(null))},[h,it]);(0,Q.useEffect)(()=>{h||N.length===0||N.includes(z)||(B(wt(N)),H(null),re(null))},[h,N,z]);let ot=(0,Q.useCallback)(async e=>{h?await it({model:e}):(H(e),re(null))},[h,it]),st=(0,Q.useCallback)(async e=>{h?await it({reasoningEffort:e}):re(e)},[h,it]),ct=(0,Q.useCallback)(async e=>{l||!u(h?.id)||(h?await it({pinnedProjectId:e}):ee(e),!h&&e&&i===`agent`&&a(e))},[h,it,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){ee(o);return}b.current.length>0||h.pinned_project_id!==o&&it({pinnedProjectId:o})}},[o,i,h,it]);let Y=(0,Q.useCallback)(e=>{l||(Ke(),g(null),v([]),ee(e??null),B(wt(I.current)),H(null),te(DN()),re(null))},[Ke]),dt=(0,Q.useCallback)(async e=>{if(l)return;Ke();let t=await Xa({pinnedProjectId:e===void 0?h?.pinned_project_id??null:e,tierLevel:DN()});m(e=>[t,...e]),g(t),v([])},[h,Ke]),ft=(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`);Ke(),await Fe(e,t?.signal),t?.windowRestore&&i!==`agent`&&f(`open`)}},[Fe,Ke,l,i]),pt=(0,Q.useCallback)(async e=>{u(e)&&(await $a(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),wN(n),n}),xe(e,()=>null),ae.current===e&&(g(null),v([])))},[xe]),mt=(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 Qa(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}},[]),ht=(0,Q.useCallback)(e=>{S(()=>{let t=new Set(CN());return t.has(e)?t.delete(e):t.add(e),wN(t),t})},[]),gt=(0,Q.useCallback)(async()=>{A(!0);try{await wo(),await je()}catch(e){J.error(e instanceof Error?e.message:`Failed to enable MCP.`)}finally{A(!1)}},[je]),_t=(0,Q.useMemo)(()=>({visibility:d,open:Be,close:Ve,minimize:He,toggle:Ye,conversations:p,active:h,messages:_,streamingText:we,isStreaming:Te,liveTools:Ee,turnTools:De,queuedMessages:Oe,streamingConversationIds:ke,liveByConversation:T,unreadConversationIds:C,favoriteConversationIds:x,mcpEnabled:D,enablingMcp:k,enableMcpServer:gt,providersReady:j,send:Qe,abort:$e,editQueuedMessage:et,steerQueuedMessage:tt,removeQueuedMessage:nt,wasQueueConsumed:rt,cycleTier:K,setTier:at,setProvider:q,setModel:ot,setPinnedProject:ct,newConversation:dt,startNewConversation:Y,materializeDraftConversation:Xe,draftPinnedProjectId:L,draftProvider:z,draftModel:V,draftTierLevel:U,draftEffort:ne,setEffort:st,selectConversation:ft,deleteConversation:pt,renameConversation:mt,toggleFavoriteConversation:ht,refreshConversations:Ae,applyPrDecisionSnapshot:be,builderMode:{active:Ue,enter:Je,exit:Ke,session:qe}}),[d,Be,Ve,He,Ye,Ue,Je,Ke,qe,p,h,_,we,Te,Ee,De,Oe,ke,T,C,x,D,k,gt,j,Qe,$e,et,tt,nt,rt,K,at,q,ot,ct,dt,Y,Xe,L,z,V,U,ne,st,ft,pt,mt,ht,Ae,be]),vt=F&&i!==`agent`;return(0,$.jsxs)(zN.Provider,{value:_t,children:[e,vt&&d===`open`&&(0,$.jsx)(oN,{}),vt&&d!==`open`&&(0,$.jsx)(pN,{})]})}var KN={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 qN(){return(0,Q.useContext)(zN)??KN}var JN=new Map;function YN(){let e=qN(),t=ZD(),n=lt(),r=Ma(),{registerHandlers:i}=gi(),{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&&JN.set(r,t.captureWorkspace());let i=JN.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){Vy(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(Wy(e.conversationId))throw Error(i(`window.finishPending`));return{version:1,...e,capturedAt:Date.now(),composer:ei(e.conversationId),scroll:By(e.conversationId),workspace:{...n.captureWorkspace(),...e.projectId?{codeSelection:Ny(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&&JN.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,JN.set(t.conversationId,e.workspace),ni(t.conversationId,e.composer),t.projectId&&(e.workspace.codeSelection&&Py(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),Vy(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 XN=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 ZN(this.width*e,this.height*e)}[ft](){return{width:this.width,height:this.height}}toJSON(){return this[ft]()}},ZN=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 XN(this.width/e,this.height/e)}[ft](){return{width:this.width,height:this.height}}toJSON(){return this[ft]()}},QN=class{constructor(e){this.size=e}toLogical(e){return this.size instanceof XN?this.size:this.size.toLogical(e)}toPhysical(e){return this.size instanceof ZN?this.size:this.size.toPhysical(e)}[ft](){return{[`${this.size.type}`]:{width:this.size.width,height:this.size.height}}}toJSON(){return this[ft]()}},$N=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 eP(this.x*e,this.y*e)}[ft](){return{x:this.x,y:this.y}}toJSON(){return this[ft]()}},eP=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 $N(this.x/e,this.y/e)}[ft](){return{x:this.x,y:this.y}}toJSON(){return this[ft]()}},tP=class{constructor(e){this.position=e}toLogical(e){return this.position instanceof $N?this.position:this.position.toLogical(e)}toPhysical(e){return this.position instanceof eP?this.position:this.position.toPhysical(e)}[ft](){return{[`${this.position.type}`]:{x:this.position.x,y:this.position.y}}}toJSON(){return this[ft]()}},nP;(function(e){e[e.Critical=1]=`Critical`,e[e.Informational=2]=`Informational`})(nP||={});var rP=class{constructor(e){this._preventDefault=!1,this.event=e.event,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}},iP;(function(e){e.None=`none`,e.Normal=`normal`,e.Indeterminate=`indeterminate`,e.Paused=`paused`,e.Error=`error`})(iP||={});function aP(){return new cP(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}async function oP(){return Y(`plugin:window|get_all_windows`).then(e=>e.map(e=>new cP(e,{skip:!0})))}var sP=[`tauri://created`,`tauri://error`],cP=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 oP()).find(t=>t.label===e)??null}static getCurrent(){return aP()}static async getAll(){return oP()}static async getFocusedWindow(){for(let e of await oP())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)}:Cr(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)}:Tr(e,t,{target:{kind:`Window`,label:this.label}})}async emit(e,t){if(sP.includes(e)){for(let n of this.listeners[e]||[])n({event:e,id:-1,payload:t});return}return wr(e,t)}async emitTo(e,t,n){if(sP.includes(t)){for(let e of this.listeners[t]||[])e({event:t,id:-1,payload:n});return}return Er(e,t,n)}_handleTauriEvent(e,t){return sP.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 eP(e))}async outerPosition(){return Y(`plugin:window|outer_position`,{label:this.label}).then(e=>new eP(e))}async innerSize(){return Y(`plugin:window|inner_size`,{label:this.label}).then(e=>new ZN(e))}async outerSize(){return Y(`plugin:window|outer_size`,{label:this.label}).then(e=>new ZN(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===nP.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 QN?e:new QN(e)})}async setMinSize(e){return Y(`plugin:window|set_min_size`,{label:this.label,value:e instanceof QN?e:e?new QN(e):null})}async setMaxSize(e){return Y(`plugin:window|set_max_size`,{label:this.label,value:e instanceof QN?e:e?new QN(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 tP?e:new tP(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:ya(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 tP?e:new tP(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?ya(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(Dr.WINDOW_RESIZED,t=>{t.payload=new ZN(t.payload),e(t)})}async onMoved(e){return this.listen(Dr.WINDOW_MOVED,t=>{t.payload=new eP(t.payload),e(t)})}async onCloseRequested(e){return this.listen(Dr.WINDOW_CLOSE_REQUESTED,async t=>{let n=new rP(t);await e(n),n.isPreventDefault()||await this.destroy()})}async onDragDropEvent(e){let t=await this.listen(Dr.DRAG_ENTER,t=>{e({...t,payload:{type:`enter`,paths:t.payload.paths,position:new eP(t.payload.position)}})}),n=await this.listen(Dr.DRAG_OVER,t=>{e({...t,payload:{type:`over`,position:new eP(t.payload.position)}})}),r=await this.listen(Dr.DRAG_DROP,t=>{e({...t,payload:{type:`drop`,paths:t.payload.paths,position:new eP(t.payload.position)}})}),i=await this.listen(Dr.DRAG_LEAVE,t=>{e({...t,payload:{type:`leave`}})});return()=>{t(),r(),n(),i()}}async onFocusChanged(e){let t=await this.listen(Dr.WINDOW_FOCUS,t=>{e({...t,payload:!0})}),n=await this.listen(Dr.WINDOW_BLUR,t=>{e({...t,payload:!1})});return()=>{t(),n()}}async onScaleChanged(e){return this.listen(Dr.WINDOW_SCALE_FACTOR_CHANGED,e)}async onThemeChanged(e){return this.listen(Dr.WINDOW_THEME_CHANGED,e)}},lP;(function(e){e.Disabled=`disabled`,e.Throttle=`throttle`,e.Suspend=`suspend`})(lP||={});var uP;(function(e){e.Default=`default`,e.FluentOverlay=`fluentOverlay`})(uP||={});var dP;(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`})(dP||={});var fP;(function(e){e.FollowsWindowActiveState=`followsWindowActiveState`,e.Active=`active`,e.Inactive=`inactive`})(fP||={});var pP=12e-5,mP=36,hP=140,gP=1.5,_P=6;function vP(e,t){return{x:Math.random()*e,y:Math.random()*t,radius:.35+Math.random()*1.25,alpha:.22+Math.random()*.5,drift:gP+Math.random()*(_P-gP)}}function yP(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 bP(){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=yP(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(hP,Math.max(mP,Math.floor(o*s*pP)));a=Array.from({length:e},()=>vP(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 xP=(0,Q.lazy)(()=>c(()=>import(`./AgentModeCodePane-DcVV6EBy.js`).then(e=>({default:e.AgentModeCodePane})),__vite__mapDeps([81,1,7,10,43,51]))),SP=(0,Q.lazy)(()=>c(()=>import(`./AgentModeJobsPane-a9f-g56c.js`).then(e=>({default:e.AgentModeJobsPane})),__vite__mapDeps([82,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,56,51,66,67,69,70,74,78,6,9,11,44,46,47,48,49,50,52,53,54,55,57,58,59,60,61,62,63,64,65,68,71,72,73,75,76,77,83]))),CP=(0,Q.lazy)(()=>c(()=>import(`./AgentModeAnalyticsPane-DXQSjYe-.js`).then(e=>({default:e.AgentModeAnalyticsPane})),__vite__mapDeps([84,1,7,10,43,56,51,66,67])));function wP(){let{t:e}=K(`agent`),{active:t,refreshConversations:n,builderMode:r}=qN(),{codePaneOpen:i,jobsPaneOpen:a,analyticsPaneOpen:o}=ZD(),{activeProjectId:s}=lt(),c=gi(),l=Hy(t?.id??`__new-mission__`),u=!c.current&&c.transfers.some(e=>e.conversationId===t?.id&&e.state===`detached`),d=_a(),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)(K_,{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)(bP,{}),(0,$.jsxs)(`div`,{className:`relative flex h-full min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,$.jsx)(jy.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)(ZM,{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)(jy.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)(Fo,{className:`h-4 w-4 text-accent-primary`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground/80`,children:p})]}),(0,$.jsx)(bA,{autoFocus:!0})]})}):(0,$.jsx)(`div`,{className:`relative z-10 flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,$.jsx)(Aj,{variant:`inline`})})]}),h&&(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`w-[480px] border-l border-border`}),children:(0,$.jsx)(SP,{projectId:s})}),m&&(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`w-[520px] border-l border-border`}),children:(0,$.jsx)(xP,{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)(CP,{})})]})})}var TP=(e,t,n)=>Math.min(n,Math.max(t,e)),EP=e=>`specrails-desktop:sidebar-width:${e}`;function DP(e,t){let n=EP(e),[r,i]=(0,Q.useState)(()=>{try{let e=localStorage.getItem(n),r=e?Number.parseInt(e,10):NaN;if(Number.isFinite(r))return TP(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=TP(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=TP(c.current+r,t.min,t.max):e.key===o?s=TP(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 OP({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 kP=[`pinned-open`,`pinned-collapsed`,`unpinned`],AP=`specrails-desktop:sidebar-mode:left`,jP=`specrails-desktop:sidebar-mode:right`;function MP(e){return typeof e==`string`&&kP.includes(e)}function NP(e){try{let t=window.localStorage.getItem(e);if(MP(t))return t}catch{}return`unpinned`}function PP(e,t){try{window.localStorage.setItem(e,t)}catch{}}function FP(e){switch(e){case`pinned-open`:return`pinned-collapsed`;case`pinned-collapsed`:return`unpinned`;case`unpinned`:return`pinned-open`}}var IP=(0,Q.createContext)({leftMode:`unpinned`,rightMode:`unpinned`,setLeftMode:()=>{},setRightMode:()=>{},cycleLeftMode:()=>{},cycleRightMode:()=>{}});function LP({children:e}){let[t,n]=(0,Q.useState)(()=>NP(AP)),[r,i]=(0,Q.useState)(()=>NP(jP));(0,Q.useEffect)(()=>{PP(AP,t)},[t]),(0,Q.useEffect)(()=>{PP(jP,r)},[r]);let a=(0,Q.useCallback)(e=>n(e),[]),o=(0,Q.useCallback)(e=>i(e),[]),s=(0,Q.useCallback)(()=>n(e=>FP(e)),[]),c=(0,Q.useCallback)(()=>i(e=>FP(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)(IP.Provider,{value:l,children:e})}function RP(){return(0,Q.useContext)(IP)}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}=Ze(),[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=yt(o,`read-only`),P=(0,Q.useMemo)(()=>wM(v??g,{milestoneLabel:M,minSpecs:1,maxSpecs:10,requireScaffold:!1}),[g,v,M]),F=(0,Q.useMemo)(()=>EM(g,v??g,P,{minSpecs:1,maxSpecs:10}),[g,v,P]),I=(0,Q.useMemo)(()=>tn(m),[m]);(0,Q.useEffect)(()=>{if(!e||u||!N)return;let t=!1;return fetch(`${ot()}/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(`${ot()}/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=an(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(`${ot()}/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]),ee=(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]),R=(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(`${ot()}/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 z=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)(Os,{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)(Nn,{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:[Ht(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)(Qj,{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)(Cn,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(_c,{className:`h-3.5 w-3.5`})})]})]}),(0,$.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col lg:w-96`,children:[(0,$.jsx)(nN,{blueprint:g,milestoneLabel:M,snapshot:E}),(0,$.jsx)(aN,{readiness:F,snapshot:E,busy:S||w,primaryLabel:w?s(`commit.creating`):s(`milestone.commit`,{count:z,label:M}),onPrimary:R,onRepair:ee,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)(Os,{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)(Nn,{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 BP({expanded:e}){let{t}=K(`builder`),n=y(),{activeProjectId:r,projects:i}=lt(),{blueprint:a,progress:o,hasBlueprint:s,refresh:c}=Jt(r),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(()=>tM()),[_,v]=(0,Q.useState)(()=>iM()),[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 uM(r,1,h,{autoAdvance:_}),n=sM(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 mM(r,e,n);i.ok?(v(n),aM(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 fM(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 pM(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(ae?`/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&&Bt(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=yt(I,`read-only`),ee=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),nM(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)(UM,{checked:_,onChange:e=>{v(e),aM(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)(Cn,{className:`h-3 w-3 animate-spin`}):(0,$.jsx)(fc,{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)(Os,{className:`w-4 h-4 flex-shrink-0`}),e&&(0,$.jsx)(`span`,{className:`text-xs truncate`,children:t(`sidebar.title`)})]}),l&&w&&(0,Bb.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)(GM,{progress:e,actions:e.n===1?ee: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)(kn,{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 VP={"pinned-open":`sidebarPin.right.pinnedOpen`,"pinned-collapsed":`sidebarPin.right.pinnedCollapsed`,unpinned:`sidebarPin.right.unpinned`};function HP({missionOnly:e=!1}={}){let{t}=K(`agent`),{t:n}=K(`nav`),{t:r}=K(`builder`),{rightMode:i,cycleRightMode:a}=RP(),{activeProjectId:o}=lt(),s=Ma(),c=ZD(),{builderMode:l}=qN(),[u,d]=(0,Q.useState)(!1),f=l.active||i===`pinned-open`||i===`unpinned`&&u,p=DP(`right-workspace`,{side:`right`,defaultWidth:208,min:180,max:460,collapsedWidth:44,expanded:f}),m=i!==`unpinned`,h=n(VP[i]),g=!o,_=[{key:`jobs`,icon:zo,label:t(`workspace.jobs`),onClick:()=>c.toggleJobsPane(),disabled:g,disabledTitle:t(`workspace.requiresProject`)},{key:`analytics`,icon:Bo,label:t(`workspace.analytics`),onClick:()=>c.toggleAnalyticsPane(),disabled:g,disabledTitle:t(`workspace.requiresProject`)},...Me()?[{key:`browser`,icon:D,label:t(`workspace.browser`),onClick:()=>c.openBrowser(),disabled:g,disabledTitle:t(`workspace.requiresProject`)}]:[],...W?[{key:`terminal`,icon:wc,label:t(`workspace.terminal`),onClick:()=>o&&s.togglePanel(o),disabled:g,disabledTitle:t(`workspace.requiresProject`)}]:[],...se?[{key:`files`,icon:ms,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)(OP,{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)(Qs,{className:`w-4 h-4`})})]}),l.active?(0,$.jsx)(j_,{mode:`wait`,initial:!1,children:(0,$.jsxs)(jy.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)(nN,{blueprint:l.session.blueprint,snapshot:l.session.snapshot}),l.session.phase===`chat`&&(0,$.jsx)(aN,{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)(BP,{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 UP=`specrails:terminal-settings-updated`;function WP(e){typeof window>`u`||window.dispatchEvent(new CustomEvent(UP,{detail:e}))}function GP(){return new JP(aP(),window.__TAURI_INTERNALS__.metadata.currentWebview.label,{skip:!0})}async function KP(){return Y(`plugin:webview|get_all_webviews`).then(e=>e.map(e=>new JP(new cP(e.windowLabel,{skip:!0}),e.label,{skip:!0})))}var qP=[`tauri://created`,`tauri://error`],JP=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 KP()).find(t=>t.label===e)??null}static getCurrent(){return GP()}static async getAll(){return KP()}async listen(e,t){return this._handleTauriEvent(e,t)?()=>{let n=this.listeners[e];n.splice(n.indexOf(t),1)}:Cr(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)}:Tr(e,t,{target:{kind:`Webview`,label:this.label}})}async emit(e,t){if(qP.includes(e)){for(let n of this.listeners[e]||[])n({event:e,id:-1,payload:t});return}return wr(e,t)}async emitTo(e,t,n){if(qP.includes(t)){for(let e of this.listeners[t]||[])e({event:t,id:-1,payload:n});return}return Er(e,t,n)}_handleTauriEvent(e,t){return qP.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 eP(e))}async size(){return Y(`plugin:webview|webview_size`,{label:this.label}).then(e=>new ZN(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 QN?e:new QN(e)})}async setPosition(e){return Y(`plugin:webview|set_webview_position`,{label:this.label,value:e instanceof tP?e:new tP(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(Dr.DRAG_ENTER,t=>{e({...t,payload:{type:`enter`,paths:t.payload.paths,position:new eP(t.payload.position)}})}),n=await this.listen(Dr.DRAG_OVER,t=>{e({...t,payload:{type:`over`,position:new eP(t.payload.position)}})}),r=await this.listen(Dr.DRAG_DROP,t=>{e({...t,payload:{type:`drop`,paths:t.payload.paths,position:new eP(t.payload.position)}})}),i=await this.listen(Dr.DRAG_LEAVE,t=>{e({...t,payload:{type:`leave`}})});return()=>{t(),r(),n(),i()}}};function YP(e){return`'${e.replace(/'/g,`'\\''`)}'`}function XP(e){if(/[\x00-\x1f"%!]/.test(e))throw Error(`unsafe-cmd-path`);return`"`+e+`"`}function ZP(e){return`'${e.replace(/'/g,`''`)}'`}function QP(e,t,n=`powershell`){return t?n===`cmd`?XP(e):ZP(e):YP(e)}function $P(e,t,n=`powershell`){return e.map(e=>QP(e,t,n)).join(` `)}function eF(e){return/(?:^|[\\/])cmd(?:\.exe)?$/i.test(e??``)?`cmd`:`powershell`}async function tF(e){if(!ce())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&&rF(s,u.viewportEl.getBoundingClientRect(),window.devicePixelRatio||1))try{u.writeText($P(o,i,eF(u.shell)))}catch{J.error(We.t(`terminal:errors.pathPasteUnsafe`))}},o=nF((()=>{try{return GP()}catch{return null}})());o&&t.push(await o(a));let s=nF((()=>{try{return aP()}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 nF(e){let t=e?.onDragDropEvent;return typeof t==`function`?t.bind(e):null}function rF(e,t,n){let r=Number.isFinite(n)&&n>0?n:1;return iF(e.x/r,e.y/r,t)}function iF(e,t,n){return e>=n.left&&e<=n.right&&t>=n.top&&t<=n.bottom}function aF({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 oF({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:Dt(e)})},e))})}var sF=(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 cF({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,_=Dt(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)(lF,{label:y,disabled:!t,onClick:e=>o(e?{x:e.clientX,y:e.clientY}:void 0),children:(0,$.jsx)(kn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(lF,{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)(lF,{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)($o,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(lF,{label:t?h(`topBar.newTerminal`):v,disabled:!t,onClick:a,children:(0,$.jsx)(Dn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(lF,{label:h(`topBar.killActive`),disabled:!n,onClick:f,children:(0,$.jsx)(An,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(lF,{label:h(e===`maximized`?`topBar.restorePanel`:`topBar.maximizePanel`),onClick:p,children:e===`maximized`?(0,$.jsx)(Ws,{className:`h-3.5 w-3.5`}):(0,$.jsx)(Us,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(sF,{isOpen:!0,onClick:m})]})]})}function lF({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 uF({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)(dF,{session:e,active:e.id===t,onActivate:()=>n(e.id),onRename:t=>r(e.id,t),onKill:()=>i(e.id)},e.id))})})}function dF({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)(Oc,{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)(wn,{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)(Nn,{className:`h-3 w-3`})})]})})}function fF({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)(fn,{size:14})}),(0,$.jsx)(`button`,{type:`button`,title:n(`search.next`),onClick:h,className:`text-[#f8f8f2] hover:text-white p-1`,children:(0,$.jsx)(Wo,{size:14})}),(0,$.jsx)(pF,{label:`Aa`,title:n(`search.matchCase`),active:o,onToggle:()=>s(e=>!e)}),(0,$.jsx)(pF,{label:`.*`,title:n(`search.regex`),active:c,onToggle:()=>l(e=>!e)}),(0,$.jsx)(pF,{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)(Nn,{size:14})})]})}function pF({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 mF({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&&(Ca(m),a())}function _(){Sa().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)(hF,{onClick:g,disabled:!h,label:l(`common:actions.copy`),shortcut:p+`C`}),(0,$.jsx)(hF,{onClick:_,label:l(`contextMenu.paste`),shortcut:p+`V`}),(0,$.jsx)(hF,{onClick:v,label:l(`contextMenu.selectAll`),shortcut:p+`A`}),(0,$.jsx)(gF,{}),(0,$.jsx)(hF,{onClick:y,label:l(`contextMenu.clear`),shortcut:p+`K`}),(0,$.jsx)(hF,{onClick:b,label:l(`contextMenu.search`),shortcut:p+`F`}),(0,$.jsx)(hF,{onClick:x,label:l(`contextMenu.saveScrollback`)}),r&&i&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(gF,{}),(0,$.jsx)(hF,{onClick:S,label:l(`contextMenu.openPath`,{path:_F(r,40)})})]})]})}function hF({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 gF(){return(0,$.jsx)(`div`,{className:`my-1 border-t border-[#44475a]`})}function _F(e,t){return e.length<=t?e:`…`+e.slice(e.length-t+1)}async function vF(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 hj(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 gj(){let{t:e}=K(`agent`),{active:t,messages:n,renameConversation:r,deleteConversation:i,startNewConversation:a,favoriteConversationIds:o,toggleFavoriteConversation:s}=qN(),{projects:c}=lt(),[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(mj(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=mj(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=hj(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)(Go,{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)(Ic,{}),(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)(ds,{className:`h-4 w-4`})}),(0,$.jsx)(j_,{children:l&&(0,$.jsx)(jy.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)(wn,{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)(ks,{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)(An,{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)(vn,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`}):(0,$.jsx)(is,{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)(bn,{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)(vn,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`}):(0,$.jsx)(is,{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 _j=new Set([`building`,`on_review`,`pr_draft`,`no_changes`,`pr_closed`,`implementation_failed`,`pr_failed`]);function vj(e){return _j.has(e)}function yj(e){return!!(vj(e.decision)||e.phase===`launched`||e.phase===`running`||e.runtime?.failure&&e.decision!==`discarded`&&e.decision!==`superseded`)}function bj(e){let t=[];for(let[n,r]of e.entries()){if(r.role!==`system`)continue;let e=_o(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=Ft(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=Ft(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))Ft(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),yj(e.envelope)&&u.push(e)}return{byMessageId:c,duplicateMessageIds:l,pinned:u}}function xj({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)(jn,{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:()=>WD({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 Sj({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)(kn,{className:`h-3 w-3 text-accent-primary/70`,"aria-hidden":!0}),n(`runFailure.briefing.title`),r?(0,$.jsx)(Wo,{className:`h-3 w-3 opacity-60`,"aria-hidden":!0}):(0,$.jsx)(Go,{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)(RD,{content:e,contextRefs:t})})]})}var Cj={pinnedMessageIds:new Set,pinned:[]};function wj(e){let t=jx();return(0,Q.useMemo)(()=>{if(!ne)return Cj;let n=[],r=new Set;for(let i of e){if(i.role!==`assistant`||!i.content.includes("```rail-launch"))continue;let{proposals:e}=Ex(i.content,!1);e.forEach((e,a)=>{Mx(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 Tj=(0,Q.lazy)(()=>c(()=>import(`./JobDetailModal-BnO_V8KR.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]))),Ej=(0,Q.lazy)(()=>c(()=>import(`./LoopPreviewModal-BY5dDezY.js`).then(e=>({default:e.LoopPreviewModal})),__vite__mapDeps([79,1,7,8,11,10,43,57,58,66,67,71,65,51,80,53,55]))),Dj=new Set,Oj=new Set([`spec-framing.committed`]);function kj(e){if(!e.startsWith(`{`))return!1;try{let t=JSON.parse(e);return typeof t?.kind==`string`&&Oj.has(t.kind)}catch{return!1}}function Aj({variant:e}){let{t}=K(`agent`),{active:n}=qN(),r=gi(),i=Hy(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)(gj,{}),(0,$.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,$.jsx)(ln,{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)(jj,{variant:e},`${n?.id??`__new-mission__`}:${i}`)})}function jj({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}=qN(),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(),y=o.length>0?o:s,b=(0,Q.useRef)(null),x=Xy(i,a),{openRef:S,jobRef:C,closeJobRef:w,loopRef:T,closeLoopRef:E}=Ib(),D=n?.pinned_project_id??null,[O,k]=(0,Q.useState)(new Map),A=(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=A?A.split(`\0`):[];if(!n?.id||e.length===0){k(new Map);return}let t=!1,r=new Set(e);return no(n.id).then(e=>{t||k(new Map(e.filter(e=>r.has(e.id)).map(e=>[e.id,e])))}).catch(()=>{t||k(new Map)}),()=>{t=!0}},[n?.id,A]);let j=(0,Q.useMemo)(()=>D?e=>{S(D,e)}:void 0,[D,S]),M=_a().id===`code-rain`?t(`emptyTitleCodeRain`):t(`emptyTitle`),N=(0,Q.useMemo)(()=>bj(r),[r]),P=wj(r),F=n?By(n.id):null,I=(0,Q.useRef)(F?.atBottom??!0);(0,Q.useLayoutEffect)(()=>{let e=b.current;return e&&F&&(e.scrollTop=F.atBottom?e.scrollHeight:F.top),()=>{e&&n&&zy(n.id,{top:e.scrollTop,atBottom:I.current})}},[n?.id]);let L=()=>{let e=b.current;e&&(I.current=e.scrollHeight-e.scrollTop-e.clientHeight<48,n&&zy(n.id,{top:e.scrollTop,atBottom:I.current}))};(0,Q.useEffect)(()=>{I.current&&b.current?.scrollTo?.({top:b.current.scrollHeight,behavior:`auto`})},[r.length,x,o.length,c.length]);let ee=e=>{e.shiftKey&&(e.key===`Tab`||e.code===`Tab`)&&(e.preventDefault(),e.stopPropagation(),p())},R=e===`inline`,z=R?`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:ee,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)(Js,{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)(bc,{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`)})]}),R&&n&&(0,$.jsx)(gj,{}),(0,$.jsxs)(`div`,{className:z,children:[(0,$.jsxs)(jy.div,{ref:b,onScroll:L,initial:R?{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)(Fo,{className:`mb-2 h-8 w-8 text-accent-primary/60`}),(0,$.jsx)(`p`,{className:`text-sm font-medium text-foreground/70`,children:M}),(0,$.jsx)(`p`,{className:`mt-1 max-w-[280px] text-xs`,children:t(`emptyHint`)})]}),r.map((e,i)=>{if(e.role===`system`){if(kj(e.content))return null;if(ne){let t=VD(e.content);if(t)return(0,$.jsx)(xj,{row:t},e.id)}let n=N.byMessageId.get(e.id);return n?yj(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)(nc,{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)(ij,{decision:n.decision})]},e.id):(0,$.jsx)(nj,{envelope:n,conversationId:e.conversation_id},e.id):(N.duplicateMessageIds.has(e.id)||Dj.has(e.id)||(Dj.add(e.id),console.warn(`[agent-chat] skipping unrenderable system message ${e.id}`)),null)}if(ne&&HD(e))return(0,$.jsx)(Sj,{content:e.content,contextRefs:e.context_refs},e.id);let o=P.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:Et(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:D,onOpenRef:j,contextRefs:e.context_refs,deliveryStatus:e.delivery_status,deliveryReceipt:e.delivery_receipt,conversationId:e.conversation_id,attachments:(e.attachment_ids??[]).map(e=>O.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)(nc,{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:Et(n?.provider)}),(0,$.jsx)(zb,{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)(BD,{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=>O.get(e)).filter(e=>!!e)},`${n?.id}:${e.queueId}`))})]}),(0,$.jsx)(j_,{initial:!1,children:n&&(N.pinned.length>0||P.pinned.length>0)&&(0,$.jsx)(fj,{pinned:N.pinned,proposals:P.pinned,projectId:D,conversationId:n.id,inline:R},`agent-pr-pinned-dock`)}),R?(0,$.jsx)(`div`,{className:`shrink-0 px-4 pb-4`,children:(0,$.jsxs)(jy.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)(jA,{active:a,radius:`1rem`,inset:-3}),(0,$.jsx)(bA,{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)(jA,{active:a,radius:`0.75rem`,inset:-2}),(0,$.jsx)(bA,{hideProjectSelector:!0,queueEditRequest:_})]})]}),C&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Tj,{jobId:C.jobId,projectId:C.projectId,onClose:w})}),T&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Ej,{loop:T,onClose:E})}),h&&(0,$.jsx)(Vb,{tools:y,streaming:a,onClose:()=>g(!1)})]})}var Mj=8,Nj=3e3;function Pj(){let{t:e}=K(`agent`),{conversations:t,active:n,selectConversation:r,deleteConversation:i,startNewConversation:a,streamingConversationIds:o,liveByConversation:s}=qN(),[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>Mj,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},Nj)},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)(gn,{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)(Wo,{className:`h-3.5 w-3.5 shrink-0 text-foreground/50`})]}),(0,$.jsx)(j_,{children:c&&(0,$.jsxs)(jy.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)(On,{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)(jy.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)(Dn,{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)(Fj,{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 Fj({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)(An,{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)(vn,{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)(Nn,{className:`h-3.5 w-3.5`})})]}):(0,$.jsxs)(jy.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:qb(e.updated_at),children:Kb(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)(vn,{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)(An,{className:`h-3.5 w-3.5`})})]})}var Ij=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}));Ij.displayName=`Input`;var Lj=6e4,Rj={data:null,fetchedAt:0,inFlight:null,error:null},zj=new Set;function Bj(){zj.forEach(e=>{try{e()}catch{}})}function Vj(){return Rj.data!==null&&Date.now()-Rj.fetchedAt<Lj}async function Hj(e){if(Rj.inFlight)return Rj.inFlight;let t=(async()=>{let t=await fetch(`${Ke}/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 Rj.data=n,Rj.fetchedAt=Date.now(),Rj.error=null,Rj.inFlight=null,Bj(),Rj.data})().catch(t=>{throw Rj.inFlight=null,e?.aborted?t:(Rj.error=t instanceof Error?t:Error(String(t)),Bj(),Rj.error)});return Rj.inFlight=t,t}var Uj=!1;function Wj(){Uj||typeof window>`u`||(window.addEventListener(`focus`,()=>{Rj.fetchedAt=0,Rj.data=null,Hj().catch(()=>{})}),Uj=!0)}function Gj(){let[,e]=(0,Q.useState)(0),[t,n]=(0,Q.useState)(()=>!Vj()),[r,i]=(0,Q.useState)(Rj.error);(0,Q.useEffect)(()=>{Wj();let t=()=>{e(e=>e+1),i(Rj.error),n(!1)};zj.add(t);let r=new AbortController;return!Vj()&&!Rj.inFlight?(n(!0),Hj(r.signal).catch(e=>{r.signal.aborted||i(e instanceof Error?e:Error(String(e)))}).finally(()=>{r.signal.aborted||n(!1)})):Rj.inFlight&&Rj.inFlight.catch(()=>{}).finally(()=>{r.signal.aborted||n(!1)}),()=>{r.abort(),zj.delete(t)}},[]);let a=(0,Q.useCallback)(async()=>{Rj.fetchedAt=0,Rj.data=null,Rj.error=null,n(!0);try{await Hj()}catch(e){i(e instanceof Error?e:Error(String(e)))}finally{n(!1)}},[]);return{status:Rj.data,isLoading:t,error:r,recheck:a}}var Kj={claude:{icon:`🤖`,label:`Claude`},codex:{icon:`⚡`,label:`Codex`},gemini:{icon:`✨`,label:`Gemini`},kimi:{icon:`🌙`,label:`Kimi`}};function qj(e){return e.toLowerCase().normalize(`NFKD`).replace(/[̀-ͯ]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`project`}function Jj({blueprint:e,onSubmit:t,onBack:n,submitting:r,error:i,errorDetail:a}){let{t:o}=K(`builder`),{status:s}=Gj(),[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/${qj(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)(Ij,{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)(Ij,{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}=Kj[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)(Ts,{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)(fc,{className:`mr-1.5 h-3.5 w-3.5`}),o(r?`commit.creating`:`commit.submit`)]})]})]})}function Yj({session:e,autoFocus:t=!1}){let{t:n}=K(`builder`),{t:r}=K(`agent`),{availableIds:i,labels:a}=gA(),o=Tt(e.provider),s=[e.provider,...i].filter((e,t,n)=>n.indexOf(e)===t).filter(Tt),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)(Os,{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)(PE,{label:r(`provider.label`),value:e.provider,options:s.map(e=>({value:e,label:c(e)})),icon:Fo,onSelect:e.setProvider,disabled:!o||e.busy||!e.conversationReady,testId:`builder-provider-selector`}),(0,$.jsx)(KO,{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)(PE,{label:r(`effort.label`),value:e.effort,options:e.efforts.map(e=>({value:e,label:r(`effort.${e}`)})),icon:Ss,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)(kn,{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)(At,{className:`h-4 w-4`})})]})]})}function Xj(e){let t=Date.parse(e.includes(`T`)?e:e.replace(` `,`T`)+`Z`);return Number.isFinite(t)?gr(new Date(t),{addSuffix:!0,locale:qe()}):``}function Zj({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)(jy.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)(As,{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)(Cn,{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)(j_,{initial:!1,children:e.map(e=>{let t=e.productName||e.title||a(`recent.untitled`),c=o===e.id;return(0,$.jsxs)(jy.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)(Tn,{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)(Is,{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)(jn,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),a(`recent.pendingIssue`)]}),e.updatedAt&&(0,$.jsx)(`span`,{className:`opacity-80`,children:Xj(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)(vn,{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)(Nn,{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)(An,{className:`h-3.5 w-3.5`,"aria-hidden":!0})})})]},e.id)})})})]})}function Qj({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?Mn:kn,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)(Cn,{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)(j_,{mode:`wait`,initial:!1,children:(0,$.jsx)(jy.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)(j_,{mode:`wait`,initial:!1,children:(0,$.jsx)(jy.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)(jy.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 $j=`specrails-desktop:milestone-launch-mode`,eM=`specrails-desktop:milestone-sequential-plans`;function tM(){try{return localStorage.getItem(`specrails-desktop:milestone-launch-mode`)===`parallel`?`parallel`:`sequential`}catch{return`sequential`}}function nM(e){try{localStorage.setItem($j,e)}catch{}}var rM=`specrails-desktop:milestone-auto-advance`;function iM(){try{return localStorage.getItem(rM)===`true`}catch{return!1}}function aM(e){try{localStorage.setItem(rM,e?`true`:`false`)}catch{}}function oM(){try{return localStorage.getItem(`specrails-desktop:milestone-sequential-plans`)===null?!1:(localStorage.removeItem(eM),!0)}catch{return!1}}function sM(e){return`M${e}`}function cM(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 lM(e){try{let t=await e.json();return t&&typeof t==`object`?t:{}}catch{return{}}}async function uM(e,t,n=tM(),r={}){let i=typeof r==`function`?{fetchImpl:r}:r,a=i.fetchImpl??fetch,o=i.autoAdvance??iM(),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 lM(s);if(!s.ok){let e=typeof c.error==`string`?c.error:`http_${s.status}`;return{ok:!1,reason:cM(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 dM(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 lM(i);return i.ok?{ok:!0,chain:zt(a.chain)}:{ok:!1,error:typeof a.error==`string`?a.error:`http_${i.status}`,...typeof a.detail==`string`?{detail:a.detail}:{}}}function fM(e,t,n=fetch){return dM(e,t,`resume`,n)}function pM(e,t,n=fetch){return dM(e,t,`cancel`,n)}async function mM(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 lM(i);return i.ok?{ok:!0,chain:zt(a.chain)}:{ok:!1,error:typeof a.error==`string`?a.error:`http_${i.status}`,...typeof a.detail==`string`?{detail:a.detail}:{}}}var hM=[`Problem Statement`,`Proposed Solution`,`Out of Scope`,`Technical Considerations`,`Estimated Complexity`],gM={problemMinChars:200,solutionMinChars:500,outOfScopeMinBullets:3,technicalMinBullets:5,criteriaMin:6,criteriaMax:10,criterionMinChars:20},_M=new Set([`scaffold`,`feature`,`verification`]),vM=new Set([`critical`,`high`,`medium`,`low`]),yM=/^(?:todo|tbd|n\/?a|works?|test(?: it)?|criterion|acceptance criterion)$/i;function bM(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:null}function xM(e){return e.trim().toLocaleLowerCase(`en-US`)}function SM(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 CM(e){return e.split(/\r?\n/).filter(e=>/^\s*[-*+]\s+\S/.test(e)).length}function wM(e,t){let n=[],r=bM(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=bM(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:``;_M.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=xM(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:``;vM.has(d)||o(n,`priority`,`invalid_priority`,`Spec ${i} needs a valid priority.`);let f=typeof r.description==`string`?r.description.trim():``,p=SM(f);(!/^## Problem Statement(?:\r?\n|$)/.test(f)||p.headings.length!==hM.length||p.headings.some((e,t)=>e!==hM[t]))&&o(n,`description`,`canonical_sections`,`Spec ${i} is missing the canonical sections.`);for(let e of hM)(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`,gM.problemMinChars],[`Proposed Solution`,gM.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`,gM.outOfScopeMinBullets],[`Technical Considerations`,gM.technicalMinBullets]]){let r=p.bodies.get(e)??``;r&&CM(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<gM.criteriaMin||h.length>gM.criteriaMax)&&o(n,`acceptanceCriteria`,`criteria_count`,`Spec ${i} needs ${gM.criteriaMin}-${gM.criteriaMax} acceptance criteria.`,{count:h.length,min:gM.criteriaMin,max:gM.criteriaMax});let g=new Set;h.forEach((e,t)=>{let r=typeof e==`string`?e.trim():``;if(r.length<gM.criterionMinChars||yM.test(r)){o(n,`acceptanceCriteria`,`criterion_quality`,`Spec ${i} criterion ${t+1} is not concrete.`,{criterion:t+1});return}let a=xM(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 TM=new Set([`batch_incomplete`,`spec_count`]);function EM(e,t,n,r,i={}){let a=It(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=>!TM.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 DM(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 OM(e,t){let n={n:t.specIndex===null?``:t.specIndex+1,...t.params??{}};return e(DM(t),{...n,defaultValue:t.message})}var kM=new Set([`gh_not_installed`,`gh_not_authenticated`,`gh_scope`,`gh_repo_exists`,`gh_network`]);function AM(e){return`progress.githubErrors.${e&&kM.has(e)?e:`generic`}`}var jM=[`create-dir`,`git-init`,`assemble`,`blueprint`,`tickets`,`register`,`github`],MM={minSpecs:5,maxSpecs:10};function NM(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 PM(e,t){let n=e&&typeof e==`object`?e:{},r=new Date().toISOString();if(n.continuing){let e=NM(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 FM(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 IM(e,t){let{t:n}=K(`builder`),{registerHandler:r,unregisterHandler:i}=Ze(),{setActiveProjectId:a}=lt(),[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`),[ee,R]=(0,Q.useState)(null),[z,B]=(0,Q.useState)([]),[V,H]=(0,Q.useState)(``),[U,te]=(0,Q.useState)([]),[ne,re]=(0,Q.useState)(`medium`),[ie,ae]=(0,Q.useState)(``),[oe,se]=(0,Q.useState)({status:`idle`}),[ce,le]=(0,Q.useState)([]),[ue,de]=(0,Q.useState)(!1),[fe,pe]=(0,Q.useState)(!1),me=ee??V,he=(0,Q.useMemo)(()=>{let e=mt(I,me);return U.filter(t=>e.includes(t))},[me,I,U]),W=(0,Q.useRef)(null),ge=(0,Q.useRef)(null),_e=(0,Q.useRef)(I),ve=(0,Q.useRef)(null),ye=(0,Q.useRef)(!1),be=(0,Q.useRef)(ne),xe=(0,Q.useRef)(he),Se=(0,Q.useRef)(ee),G=(0,Q.useRef)(!1),Ce=(0,Q.useRef)(t.onFinished);(0,Q.useEffect)(()=>{W.current=o},[o]),(0,Q.useEffect)(()=>{_e.current=I},[I]),(0,Q.useEffect)(()=>{ve.current=w},[w]),(0,Q.useEffect)(()=>{be.current=ne},[ne]),(0,Q.useEffect)(()=>{xe.current=he},[he]),(0,Q.useEffect)(()=>{Se.current=ee},[ee]),(0,Q.useEffect)(()=>{Ce.current=t.onFinished},[t.onFinished]);let we=(0,Q.useCallback)(async()=>{let e=W.current;if(e)return e;if(ge.current)return ge.current;let t=fetch(`/api/blueprint/conversations`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:_e.current,...Se.current?{model:Se.current}:{}})}).then(e=>e.json()).then(e=>e.conversation?(W.current=e.conversation.id,s(e.conversation.id),e.conversation.id):null).catch(()=>null).finally(()=>{ge.current=null});return ge.current=t,t},[]),Te=(0,Q.useCallback)(async()=>{de(!0);try{let e=await(await fetch(`/api/blueprint/conversations?resumable=1`)).json();le(FM(e.conversations))}catch{le([])}finally{de(!1)}},[]);(0,Q.useEffect)(()=>{e&&Te()},[e,Te]),(0,Q.useEffect)(()=>{if(!e)return;let t=!1;return B([]),H(``),te([]),re(``),fetch(`/api/blueprint/models?provider=${encodeURIComponent(I)}`).then(e=>e.json()).then(e=>{if(t)return;B(e.models??[]);let n=e.defaultModel??e.models?.[0]?.value??``,r=e.efforts??[],i=mt(I,n),a=r.filter(e=>i.includes(e));H(n),te(r),re(e=>a.includes(e)?e:Ct(I,n)??``)}).catch(()=>{}),()=>{t=!0}},[e,I]);let{availableIds:Ee}=gA({enabled:e});(0,Q.useEffect)(()=>{if(W.current||Ee.length===0||Ee.includes(I))return;let e=Ee.filter(Tt);e.length!==0&&(L(wt(e)),R(null))},[Ee,I]);let De=(0,Q.useCallback)(e=>{L(e),R(null);let t=W.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=>{R(e);let t=mt(I,e),n=U.filter(e=>t.includes(e));re(t=>n.includes(t)?t:Ct(I,e)??``);let r=W.current;r&&fetch(`/api/blueprint/conversations/${r}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({model:e})}).catch(()=>{})},[I,U]);(0,Q.useEffect)(()=>{if(!e)return;let t=`builder-session`;return r(t,e=>{let t=e,r=W.current!==null&&t.conversationId===W.current,i=ve.current!==null&&t.commitId===ve.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),se({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=NM(t);d(null),_(!0),e&&se({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=Ut(t.blueprint),i=t.rawBlueprint===void 0?t.blueprint:t.rawBlueprint;if(!r&&t.snapshot===void 0){let e=an(n);r=e.blueprint,i=e.rawBlueprint}r&&(p(r),h(i)),se(e=>t.snapshot===void 0?r?{status:`accepted`,repaired:!1,repairAttempted:!1,at:new Date().toISOString()}:e:PM(t.snapshot,e))}else if(t.type===`blueprint.error`&&r)d(null),_(!1),se(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`&&!ye.current&&(ye.current=!0,J.warning(n(AM(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&&(G.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||fe)return;l(e=>[...e,{role:`user`,content:r,createdAt:new Date().toISOString(),...t.intent?{intent:t.intent}:{}}]),_(!0);let i=be.current,a=xe.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,...Se.current?{model:Se.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,fe,we,n]),Ae=(0,Q.useCallback)(async e=>{if(!g){pe(!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`);W.current=n.conversation.id,s(n.conversation.id),n.conversation.provider&&L(n.conversation.provider),R(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=Ut(n.blueprint);p(r),h(r?n.rawBlueprint??n.blueprint:null),se(PM(n.snapshot,{status:`idle`})),d(null),_(!1),y(`chat`),x(null),C(null),D([]),ae(``)}catch{J.error(n(`recent.resumeFailed`))}finally{pe(!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}`);le(t=>t.filter(t=>t.id!==e))}catch{J.error(n(`recent.discardFailed`))}},[n]),Me=(0,Q.useCallback)(async()=>{let e=W.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(ne?{reasoningEffort:ne}:{})});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,ne,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||G.current||(G.current=!0,F(!0),x(null),C(null),D([]),ye.current=!1,fetch(`/api/blueprint/commit`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({blueprint:m??f,...e,...W.current?{conversationId:W.current}:{}})}).then(async e=>{let t=await e.json().catch(()=>({}));e.status===202&&t.commitId?(T(t.commitId),ve.current=t.commitId,y(`progress`)):(x(t.error??`generic`),C(t.detail??null)),G.current=!1,F(!1)}).catch(()=>{G.current=!1,F(!1),x(`generic`),C(null)}))},[f,m]),Ie=(0,Q.useCallback)(async()=>{if(!(!O||A)){j(!0);try{let e=tM(),t=iM(),r=await uM(O,1,e,{autoAdvance:t}),i=sM(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=W.current;e&&fetch(`/api/blueprint/conversations/${e}/abort`,{method:`POST`}).catch(()=>{}),s(null),W.current=null,ge.current=null,l([]),d(null),p(null),h(null),se({status:`idle`}),le([]),pe(!1),_(!1),y(`chat`),x(null),C(null),T(null),D([]),ye.current=!1,k(null),N(!1),j(!1),G.current=!1,F(!1),L(`claude`),R(null),B([]),H(``),te([]),re(`medium`),ae(``)},[]),ze=It(f),Be=Object.values(ze).some(Boolean)||c.length>0||ie.trim().length>0,Ve=(0,Q.useMemo)(()=>wM(m??f,{milestoneLabel:`M1`,minSpecs:MM.minSpecs,maxSpecs:MM.maxSpecs,requireScaffold:!0}),[f,m]),He=oe.status===`generating`,Ue=(0,Q.useMemo)(()=>EM(f,m??f,Ve,MM,{generating:He}),[f,m,Ve,He]),We=(0,Q.useMemo)(()=>{if(Ve.valid)return null;let e=Ve.issues[0];return e?OM(n,e):null},[Ve,n]),Ge=(0,Q.useMemo)(()=>tn(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&&!fe,conversationId:o,dirty:Be,canProposeCommit:Ve.valid,specQualityDetail:We,readiness:Ue,snapshot:oe,generation:Ge,recent:ce,recentLoading:ue,resume:Ae,discardRecent:je,repairSnapshot:Me,showSurpriseMe:c.length<=1&&v===`chat`,provider:I,model:ee,models:z,efforts:he,effort:ne,draft:ie,setDraft:ae,setEffort:re,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 LM={done:`bg-accent-success`,onReview:`bg-accent-warning`,inProgress:`bg-accent-info animate-pulse`,failed:`bg-destructive`,todo:`bg-muted-foreground/25`},RM={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=Xt(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:en(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`,LM[e.key]),style:{width:`${e.pct}%`},title:`${n(`milestoneProgress.legend.${e.key}`)} · ${e.count}`},e.key))})}function BM({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`,RM[e]),children:t(`milestoneProgress.state.${e}`)})}function VM(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 HM({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&&Wt.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)(Cn,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}),o==null?i(`milestoneProgress.state.running`):i(`milestoneProgress.rail.running`,{elapsed:xr(o)})]}):s?(0,$.jsx)(ij,{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)(ps,{className:`h-3 w-3`,"aria-hidden":!0}),i(`milestoneProgress.rail.review`)]})]})}function UM({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)(Pn,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}):(0,$.jsx)(_s,{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 WM({chain:e,busy:t=!1,onResume:n,onCancel:r,onSetAutoAdvance:i}){let{t:a}=K(`builder`),o=Yt(e),s=e.status===`paused`,c=Lt(e),l=Qt(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)(Is,{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)(Cn,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Tn,{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)(Cn,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Tn,{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)(Nn,{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)(ec,{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)(_s,{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)(B,{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)(Mo,{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)(UM,{checked:e.autoAdvance,disabled:t,onChange:t=>i(e.id,t),testId:`milestone-chain-auto-advance`})})]})}function GM({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=VM(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:Vt(e.n)}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] font-medium`,children:e.title}),(0,$.jsx)(BM,{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:en(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)(WM,{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)(HM,{rail:e,now:d,onReview:r,onOpenRail:i},e.railIndex))})]})}function KM({projectId:e}){let{t}=K(`builder`),n=y(),{setActiveProjectId:r}=lt(),{progress:i,hasBlueprint:a}=Jt(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 fM(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 mM(e,n,r);i.ok?(aM(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 pM(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)(Cn,{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)(GM,{progress:c,chainBusy:o,onReview:e=>l(ae?`/review/${e}`:`/`),onOpenRail:()=>l(`/`),onResume:u,onCancel:f,onSetAutoAdvance:d,className:`bg-card/60`})}):null}var qM={surprise:Nc,approve:fc};function JM({kind:e,mode:t,onAction:n,disabled:r=!1,createdAt:i,className:a}){let{t:o}=K(`builder`),s=Ay(),c=t===`settled`,l=c?vn:qM[e],u=i?YM(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)(vn,{className:`h-3 w-3`,"aria-hidden":!0}):(0,$.jsx)(kn,{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)(B,{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)(jy.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 YM(e){let t=Date.parse(e);if(!Number.isFinite(t))return null;try{return Mb(t,`p`,{locale:qe()})}catch{return null}}var XM=`w-full rounded-2xl border border-border/60 bg-card/90 p-3 shadow-2xl backdrop-blur-xl`;function ZM({variant:e}){let{t}=K(`builder`),{builderMode:n}=qN(),r=n.session,[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(()=>iM()),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)(jy.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)(kn,{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)(xA,{active:!0,inset:-3,radius:`1rem`}),(0,$.jsx)(jy.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:XM,children:(0,$.jsx)(Yj,{session:r,autoFocus:!0})})]}),(0,$.jsx)(Zj,{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)(JM,{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)(j_,{initial:!1,children:[p&&(0,$.jsx)(JM,{kind:`surprise`,mode:`offer`,onAction:r.surpriseMe,disabled:!r.conversationReady},`surprise`),m&&(0,$.jsx)(JM,{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&&Ht(r.streamBuffer)&&(0,$.jsx)(zD,{role:`assistant`,content:Ht(r.streamBuffer),streaming:!0}),r.generation.generating||r.snapshot.status===`repairing`||r.snapshot.status===`generating`?(0,$.jsx)(Qj,{specsStarted:r.generation.specsStarted,snapshot:r.snapshot}):(0,$.jsx)(zb,{tool:null})]})]}),(0,$.jsx)(`div`,{className:`shrink-0 px-4 pb-4`,children:(0,$.jsx)(jy.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(XM,e===`inline`&&`mx-auto max-w-[680px]`),children:(0,$.jsx)(Yj,{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)(Jj,{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:jM.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)(Jo,{className:`h-3.5 w-3.5 text-muted-foreground/40`}),n?.status===`running`&&(0,$.jsx)(Cn,{className:`h-3.5 w-3.5 animate-spin text-accent-info`}),n?.status===`done`&&(0,$.jsx)(vn,{className:`h-3.5 w-3.5 text-accent-success`}),n?.status===`warning`&&(0,$.jsx)(jn,{className:`h-3.5 w-3.5 text-accent-warning`}),n?.status===`failed`&&(0,$.jsx)(Nn,{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(AM(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)(vn,{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)(KM,{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)(Cn,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(fc,{className:`mr-1.5 h-3.5 w-3.5`}),t(`done.launchM1`)]}),tM()===`sequential`&&(0,$.jsx)(UM,{checked:o,onChange:e=>{s(e),aM(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 QM=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`),$M={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 eN({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,Bb.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)(xn,{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`,$M[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)(Nn,{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:QM,children:(0,$.jsx)(pr,{remarkPlugins:[mr],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)(qo,{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 tN={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 nN({blueprint:e,milestoneLabel:t=`M1`,snapshot:n}){let{t:r}=K(`builder`),{t:i}=K(`tickets`),a=It(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)(Cn,{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)(vn,{className:`h-3.5 w-3.5 shrink-0 text-accent-success`,"aria-label":`✓`}):(0,$.jsx)(Nn,{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)(Is,{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)(xn,{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`,tN[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)(Cn,{className:`h-2.5 w-2.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Bs,{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)(Bs,{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)(eN,{spec:e.m1Specs[o],index:o,milestoneLabel:t,onClose:()=>s(null)})]})}var rN={done:vn,pending:Jo,blocked:jn,writing:Cn},iN={done:`text-accent-success`,pending:`text-muted-foreground/50`,blocked:`text-accent-warning`,writing:`text-accent-info animate-spin`};function aN({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=rN[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`,iN[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)(j_,{initial:!1,mode:`wait`,children:[d&&(0,$.jsxs)(jy.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)(Cn,{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)(jy.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)(jn,{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)(uc,{className:`mr-1.5 h-3 w-3`,"aria-hidden":!0}),c(`snapshot.rejected.retry`)]})]},`rejected`),p&&(0,$.jsxs)(jy.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)(jn,{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)(kn,{className:`mr-1.5 h-3 w-3`,"aria-hidden":!0}),c(`snapshot.halted.resume`)]})]},`halted`),t.status===`accepted`&&t.repaired&&!p&&(0,$.jsxs)(jy.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)(kn,{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)(Mn,{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)(Wo,{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:OM(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)(Mn,{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)(fc,{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 oN(){let{t:e}=K(`agent`),{t}=K(`builder`),{minimize:n,startNewConversation:r,cycleTier:i,active:a,draftPinnedProjectId:o,setPinnedProject:s,builderMode:c}=qN(),[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}=zn({enabled:!0,allowMove:!0,minWidth:400,minHeight:420,anchorFromCurrentRect:!0,persistKey:`specrails-desktop:agent-panel-geom`});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(jy.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)(xA,{active:d&&c.session.messages.length===0&&c.session.phase===`chat`,inset:-3}),(0,$.jsx)(Fo,{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)(Pj,{})]}),(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)(Dn,{className:`h-4 w-4`})}),(0,$.jsx)(Ic,{}),(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)(Ws,{className:`h-4 w-4`}):(0,$.jsx)(Us,{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)(Nn,{className:`h-4 w-4`})})]})]}),d?(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,$.jsx)(ZM,{variant:`floating`}),(0,$.jsxs)(`aside`,{className:`flex w-72 shrink-0 flex-col border-l border-border/40 lg:w-80`,children:[(0,$.jsx)(nN,{blueprint:c.session.blueprint,snapshot:c.session.snapshot}),c.session.phase===`chat`&&(0,$.jsx)(aN,{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)(Aj,{variant:`floating`})]}),!l&&(0,$.jsx)(`div`,{className:`pointer-events-none fixed inset-0 z-[61] [&>*]:pointer-events-auto`,children:(0,$.jsx)(Qn,{handles:g})})]})}var sN=`specrails-desktop:agent-bubble-pos`,cN=56,lN=12;function uN(){try{let e=localStorage.getItem(sN);if(!e)return null;let t=JSON.parse(e);if(typeof t?.left==`number`&&typeof t?.top==`number`)return t}catch{}return null}function dN(e){let t=Math.max(lN,window.innerWidth-cN-lN),n=Math.max(lN,window.innerHeight-cN-lN);return{left:Math.min(Math.max(lN,e.left),t),top:Math.min(Math.max(lN,e.top),n)}}function fN(){return{left:Math.round(window.innerWidth/2-cN/2),top:window.innerHeight-cN-20}}function pN(){let{t:e}=K(`agent`),{t}=K(`builder`),{open:n,isStreaming:r,active:i,builderMode:a}=qN(),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(()=>dN(uN()??fN())),u=ky(0),d=ky(0),f=(0,Q.useRef)(!1),p=a.active?a.session.busy:r;(0,Q.useEffect)(()=>{let e=()=>l(e=>dN(e));return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let m=(0,Q.useCallback)(e=>{try{localStorage.setItem(sN,JSON.stringify(e))}catch{}},[]);return(0,$.jsxs)(jy.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=dN({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)(xA,{active:a.active&&a.session.messages.length===0&&a.session.phase===`chat`,inset:-4}),(0,$.jsx)(Fo,{className:`h-5 w-5 text-accent-primary`}),p&&(0,$.jsx)(jy.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)(j_,{initial:!1,children:(o||p)&&(0,$.jsx)(jy.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 mN=`specrails-desktop:uiMode`;function hN(){if(!b)return`kanban`;try{return localStorage.getItem(mN)===`kanban`?`kanban`:`agent`}catch{return`agent`}}function gN(e){try{localStorage.setItem(mN,e)}catch{}}var _N=(0,Q.createContext)(null);function vN({children:e,initialMode:t,persist:n=!0}){let[r,i]=(0,Q.useState)(()=>t??hN()),a=(0,Q.useCallback)(e=>{b&&(i(e),n&&gN(e))},[n]),o=(0,Q.useCallback)(()=>{i(e=>{if(!b)return`kanban`;let t=e===`kanban`?`agent`:`kanban`;return n&&gN(t),t})},[n]),s=(0,Q.useMemo)(()=>({uiMode:r,setUiMode:a,toggleUiMode:o}),[r,a,o]);return(0,$.jsx)(_N.Provider,{value:s,children:e})}var yN={uiMode:`kanban`,setUiMode:()=>{},toggleUiMode:()=>{}};function bN(){return(0,Q.useContext)(_N)??yN}var xN={streamingText:``,isStreaming:!1,liveTools:[],turnTools:[],queued:[]},SN=`specrails-desktop:favorite-agent-conversations`;function CN(){try{let e=localStorage.getItem(SN);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 wN(e){try{localStorage.setItem(SN,JSON.stringify([...e]))}catch{}}function TN(e,t){let n=new Set(t.map(e=>e.id));return new Set([...e].filter(e=>n.has(e)))}var EN=`specrails-desktop:agent-tier-last`;function DN(){try{let e=localStorage.getItem(EN),t=e===null?0:Number.parseInt(e,10);return t===0||t===1||t===2||t===3?t:0}catch{return 0}}function ON(e){try{localStorage.setItem(EN,String(e))}catch{}}var kN=new Set([`completed`,`merged`,`discarded`,`superseded`]);function AN(e,t){return JSON.stringify(e)===JSON.stringify(t)}function jN(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 MN(e,t){if(t.supersedesDeliveryId===e.prDeliveryId)return 1;if(e.supersedesDeliveryId===t.prDeliveryId)return-1;let n=jN(e),r=jN(t);return n==null||r==null?null:r<n?-1:+(r>n)}function NN(e,t){let n=null;for(let r of e){if(r.supersedesDeliveryId!==t)continue;if(!n){n=r;continue}let e=jN(n),i=jN(r);(e==null||i==null||i>=e)&&(n=r)}return n}function PN(e,t){let n=t.restoredFromDeliveryId;if(!n)return!1;let r=NN(e,t.prDeliveryId);return!r||r.prDeliveryId===n}function FN(e,t){let n=e.filter(e=>e.role===`system`).map(e=>_o(e.content)).filter(e=>e!==null),r=[...n].reverse().find(e=>e.prDeliveryId===t.prDeliveryId),i=PN(n,t);if(r){let e=kN.has(r.decision),n=kN.has(t.decision),a=Ft(r.updatedAt,t.updatedAt);if(a===-1||a===0&&!AN(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=MN(e,t);if(n===-1||(n===0||n===null)&&!kN.has(e.decision)&&t.supersedesDeliveryId!==e.prDeliveryId)return!0}return!1}function IN(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=_o(e.content);return!t||t.prDeliveryId!==n||kN.has(t.decision)?e:(r=!0,{...e,content:JSON.stringify({...t,decision:`discarded`})})});return r?i:e}function LN(e,t){let n=e.filter(e=>e.role===`system`).map(e=>_o(e.content)).filter(e=>e!==null);if(n.some(e=>e.restoredFromDeliveryId===t.prDeliveryId&&PN(n,e)))return e;let r=!1,i=e.map(e=>{if(e.role!==`system`)return e;let n=_o(e.content);return!n||n.railIndex!==t.railIndex||n.prDeliveryId===t.prDeliveryId||kN.has(n.decision)||MN(n,t)!==1?e:(r=!0,{...e,content:JSON.stringify({...n,decision:`superseded`})})});return r?i:e}function RN(e,t,n){if(FN(e,n))return e;let r=LN(IN(e,n),n),i=JSON.stringify(n),a=r.flatMap((e,t)=>e.role===`system`&&_o(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),BN=0,VN=0,HN={sent:0,received:1,read:2};function UN(e,t){return e&&(!t||HN[e]>=HN[t])?e:t}function WN(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=UN(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 GN({children:e}){let{registerHandler:t,unregisterHandler:n,connectionStatus:r}=Ze(),{uiMode:i}=bN(),{setActiveProjectId:a,activeProjectId:o}=lt(),s=gi(),c=(0,Q.useRef)(s);c.current=s;let l=ci(),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)(CN);(0,Q.useEffect)(()=>{let e=e=>{(e.key===SN||e.key===null)&&S(CN())};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)([]),I=(0,Q.useRef)([]);I.current=N;let L=(0,Q.useRef)(!1),[ee,R]=(0,Q.useState)(null),z=(0,Q.useRef)(null);z.current=ee;let[B,V]=(0,Q.useState)(`claude`),[H,U]=(0,Q.useState)(null),[te,ne]=(0,Q.useState)(()=>DN()),[re,ie]=(0,Q.useState)(null),ae=(0,Q.useRef)({provider:`claude`,model:null,tierLevel:0,effort:null});ae.current={provider:B,model:H,tierLevel:te,effort:re};let oe=(0,Q.useRef)(null);oe.current=h?.id??null;let se=(0,Q.useRef)(T);se.current=T;let ce=(0,Q.useRef)(new Set),le=(0,Q.useRef)(new Set),ue=(0,Q.useRef)(new Map),de=(0,Q.useRef)(new Map),fe=e=>{let t=UN(e.delivery_receipt,ue.current.get(`${e.conversation_id}:m:${e.id}`));return t?{...e,delivery_receipt:t}:e},pe=(e,t)=>{let n=UN(t.deliveryReceipt,ue.current.get(`${e}:q:${t.queueId}`));return n?{...t,deliveryReceipt:n}:t},me=(0,Q.useRef)(new Set),he=(0,Q.useRef)(new Map),W=(0,Q.useRef)(new Map),ge=(0,Q.useRef)(new Map),_e=(0,Q.useRef)(null),ve=(0,Q.useRef)(0),ye=(0,Q.useRef)(0),be=(0,Q.useRef)(new Map),xe=(0,Q.useCallback)(e=>{let t=oe.current;if(!t)return`untracked`;if(FN(b.current,e))return`stale`;if(!b.current.some(t=>t.role===`system`&&_o(t.content)?.prDeliveryId===e.prDeliveryId))return`untracked`;ve.current++;let n=RN(b.current,t,e);return b.current=n,v(n=>{if(!n.some(t=>t.role===`system`&&_o(t.content)?.prDeliveryId===e.prDeliveryId))return b.current=n,n;let r=RN(n,t,e);return b.current=r,r}),`accepted`},[]),Se=(0,Q.useCallback)((e,t)=>{E(n=>{let r=t(n.get(e)??xN),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})},[]),G=(0,Q.useCallback)(e=>{let t=typeof document<`u`&&document.visibilityState===`hidden`;e===oe.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(!F||typeof document>`u`)return;let e=()=>{if(document.visibilityState!==`visible`)return;let e=oe.current;e&&Ce(e)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[Ce]);let we=(h?T.get(h.id):void 0)??xN,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 qa();m(e),S(t=>{let n=TN(CN(),e);return n.size===t.size&&[...n].every(e=>t.has(e))?t:(wN(n),n)})}catch{}},[]),Me=(0,Q.useCallback)(async()=>{try{let e=await Co();O(e.enabled)}catch{O(!1)}},[]),Ne=(0,Q.useCallback)(async()=>{try{let{any:e,installed:t}=await So();M(e),P(Array.isArray(t)?t:[])}catch{M(!0)}},[]),[Pe,Fe]=(0,Q.useState)(0);(0,Q.useEffect)(()=>F?(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;he.current.set(n,(he.current.get(n)??0)+1);let r=n===oe.current,i=e=>{ge.current.set(n,WN(ge.current.get(n)??[],e).slice(-500)),r&&(b.current=WN(b.current,e),v(t=>WN(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??de.current.get(e);if(t.queueId&&ue.current.set(e,UN(ue.current.get(e),t.receipt)),a){let e=`${n}:m:${a}`;ue.current.set(e,UN(ue.current.get(e),t.receipt));let o=(r?b.current:ge.current.get(n)??[]).find(e=>e.id===a);o&&i([fe(o)])}Se(n,e=>({...e,queued:e.queued.map(e=>e.queueId===t.queueId?{...e,deliveryReceipt:UN(e.deliveryReceipt,t.receipt)}:e)}))}else if(t.type===`agent_stream`)G(n),Se(n,e=>({...e,isStreaming:!0,streamingText:e.streamingText+(t.delta??``)}));else if(t.type===`agent_tool`)Se(n,e=>({...e,isStreaming:!0,liveTools:[...e.liveTools,{id:`t${BN++}`,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`)Se(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`){be.current.delete(n),G(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()}]}),Se(n,e=>({...xN,queued:e.queued,turnTools:e.liveTools.length?e.liveTools:e.turnTools}))}else if(t.type===`agent_error`){be.current.delete(n),G(n),Se(n,e=>({...xN,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&&ce.current.has(t.queueId))return;Se(n,e=>{let r=UN(t.deliveryReceipt??t.delivery_receipt,ue.current.get(`${n}:q:${t.queueId}`)),i={queueId:t.queueId??`srv-${VN++}`,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:UN(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(me.current.has(t.messageId)){t.queueId&&ce.current.add(t.queueId),Se(n,e=>({...e,queued:e.queued.filter(e=>e.queueId!==t.queueId)}));return}me.current.add(t.messageId),t.queueId&&ce.current.add(t.queueId),de.current.set(`${n}:q:${t.queueId}`,t.messageId);let e=UN(t.delivery_receipt??t.deliveryReceipt,ue.current.get(`${n}:q:${t.queueId}`)),r=[];t.assistantSegment&&r.push({...t.assistantSegment,conversation_id:n,role:`assistant`}),r.push(fe({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),Se(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&&ce.current.has(t.queueId))return;if(t.queueId&&ce.current.add(t.queueId),Se(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&&de.current.set(`${n}:q:${t.queueId}`,t.messageId);let e=UN(t.delivery_receipt??t.deliveryReceipt,ue.current.get(`${n}:q:${t.queueId}`));i([fe({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`)W.current.set(n,(W.current.get(n)??0)+1),t.messages?.length&&i(t.messages),Se(n,e=>({...e,queued:[]}));else if(t.type===`agent_queue_removed`){if(!t.queueId)return;ce.current.add(t.queueId),le.current.add(t.queueId),Se(n,e=>({...e,queued:e.queued.filter(e=>e.queueId!==t.queueId)}))}else if(t.type===`agent_queue_edited`)Se(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(G(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`&&(G(n),r)){let t=go(e);if(t){ve.current++;let e=RN(b.current,n,t);b.current=e,v(e=>{let r=RN(e,n,t);return b.current=r,r})}}}),()=>n(`agent-chat`)):void 0,[t,n,Se,G]);let Ie=(0,Q.useCallback)(async(e,t)=>{let n=++ye.current,r=he.current.get(e)??0;ve.current++;let{conversation:i,messages:a,pendingMessages:o,live:s}=await Za(e);if(t?.aborted)throw new DOMException(`Window transfer cancelled`,`AbortError`);if(n!==ye.current){if(t)throw new DOMException(`The mission changed during restoration`,`AbortError`);return}ve.current++;let c=WN(a,ge.current.get(e)??[]).map(fe);for(let e of c)(e.delivery_status===`delivered`||e.delivery_status===`interrupted`)&&me.current.add(e.id);g(i),b.current=c,v(c),Ce(e),r===(he.current.get(e)??0)&&(o!==void 0||s)&&Se(e,t=>({...t,...s?{isStreaming:s.isStreaming,streamingText:s.streamingText}:{},queued:o?.filter(e=>!ce.current.has(e.queueId)).map(t=>pe(e,t))??t.queued}))},[Ce,Se]),Le=(0,Q.useCallback)(async()=>{let e=oe.current;if(!e)return;let t=ve.current,n=he.current.get(e)??0,r=y.current.get(e)??0;try{let i=await Za(e);if(oe.current!==e||ve.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===(he.current.get(e)??0)){let t=WN(i.messages,ge.current.get(e)??[]).map(fe);for(let e of t)(e.delivery_status===`delivered`||e.delivery_status===`interrupted`)&&me.current.add(e.id);v(e=>WN(t,e.filter(e=>e.id.startsWith(`local-u-`)&&!t.some(t=>t.role===`user`&&t.content===e.content)))),Se(e,t=>({...t,...i.live?{isStreaming:i.live.isStreaming,streamingText:i.live.streamingText}:{},queued:i.pendingMessages?.filter(e=>!ce.current.has(e.queueId)).map(t=>pe(e,t))??t.queued}))}let a=i.messages.filter(e=>e.role===`system`).map(e=>_o(e.content)).filter(e=>e!==null);if(a.length===0)return;v(t=>{let n=a.reduce((t,n)=>RN(t,e,n),t);return b.current=n,n})}catch{}},[Se]),Re=(0,Q.useCallback)(async()=>{try{let e=new Map(he.current),t=await Ya(),n=new Set(t.turns.map(e=>e.conversationId)),r=Date.parse(t.capturedAt),i=[...se.current].flatMap(([t,i])=>{if(!i.isStreaming||n.has(t)||(e.get(t)??0)!==(he.current.get(t)??0))return[];let a=be.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)!==(he.current.get(t)??0))continue;let i=be.current.get(t);i&&Date.parse(i)>r||a.set(t,{...xN,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)!==(he.current.get(t)??0))continue;let r=a.get(t)??xN;a.set(t,{...r,isStreaming:!0,streamingText:n.streamingText??r.streamingText,queued:n.pendingMessages?.filter(e=>!ce.current.has(e.queueId)).map(e=>pe(t,e))??r.queued})}return a});for(let e of i)be.current.delete(e);let a=oe.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 qa();if(m(e),S(t=>{let n=TN(CN(),e);return n.size===t.size&&[...n].every(e=>t.has(e))?t:(wN(n),n)}),e.length>0)return await Ie(e[0].id),e[0];let t=await Xa({});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=IM(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]),Qe=(0,Q.useCallback)(async()=>{if(!u(h?.id))throw Error(`This mission is active in another window.`);if(h)return h;if(_e.current)return _e.current;let e=Xa({pinnedProjectId:z.current,provider:ae.current.provider,model:ae.current.model,tierLevel:ae.current.tierLevel,reasoningEffort:ae.current.effort}).then(e=>(oi(e.id),m(t=>[e,...t]),g(e),v([]),e)).finally(()=>{_e.current=null});return _e.current=e,e},[h]),$e=(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 Qe();he.current.set(r.id,(he.current.get(r.id)??0)+1);let i=he.current.get(r.id),a=W.current.get(r.id)??0,o=t?.queueId??`q-${Date.now()}-${VN++}`,s=new Date().toISOString();be.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=se.current.get(r.id)?.isStreaming===!0,d={queueId:o,text:n,contextRefs:t?.contextRefs,attachmentIds:t?.attachmentIds,deliveryMode:`queue`,deliveryReceipt:`sent`,timestamp:s};l?Se(r.id,e=>({...e,queued:e.queued.some(e=>e.queueId===o)?e.queued.map(e=>e.queueId===o?{...d,deliveryReceipt:UN(e.deliveryReceipt,d.deliveryReceipt),deliveryMode:e.deliveryMode??d.deliveryMode,timestamp:e.timestamp??d.timestamp}:e):[...e.queued,d]})):(v(e=>[...e,c]),Se(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 eo(r.id,n,{tierLevel:r.tier_level,attachments:f,queueId:o,contextRefs:e});if(s.removed){ce.current.add(o),le.current.add(o);let e=!l&&i===he.current.get(r.id);return oe.current===r.id&&v(e=>e.filter(e=>e.id!==c.id)),Se(r.id,t=>({...t,queued:t.queued.filter(e=>e.queueId!==o),...e?{isStreaming:!1}:{}})),e&&be.current.delete(r.id),{accepted:!0,conversationId:r.id}}if(s.message){de.current.set(`${r.id}:q:${o}`,s.message.id);let e=UN(s.message.delivery_receipt,ue.current.get(`${r.id}:q:${o}`)),t=fe({...s.message,...e?{delivery_receipt:e}:{}});return ce.current.add(o),ge.current.set(r.id,WN(ge.current.get(r.id)??[],[t]).slice(-500)),oe.current===r.id&&v(e=>WN(e.filter(e=>e.id!==c.id),[t])),Se(r.id,e=>({...e,queued:e.queued.filter(e=>e.queueId!==o)})),s.duplicate&&Re(),{accepted:!0,conversationId:r.id}}if(a!==(W.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)),ce.current.has(o)||Se(r.id,e=>e.queued.some(e=>e.queueId===o)?e:{...e,queued:[...e.queued,{...d,deliveryMode:s.deliveryMode??d.deliveryMode}]})):!u&&l&&!ce.current.has(o)&&(Se(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 ce.current.has(o)||a!==(W.current.get(r.id)??0)?{accepted:!0,conversationId:r.id}:(be.current.delete(r.id),l?Se(r.id,e=>({...e,queued:e.queued.filter(e=>e.queueId!==o)})):(Se(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,Qe,Se,Re]),et=(0,Q.useCallback)(async()=>{if(!(!h||!u(h.id)))try{await oo(h.id),W.current.set(h.id,(W.current.get(h.id)??0)+1),he.current.set(h.id,(he.current.get(h.id)??0)+1),Se(h.id,()=>null)}catch(e){J.error(e instanceof Error?e.message:`Failed to stop the agent.`)}},[h,Se]),tt=(0,Q.useCallback)(async(e,t)=>{let n=h;if(!n||!u(n.id)||se.current.get(n.id)?.queued.find(t=>t.queueId===e)?.deliveryMode===`steer`)return`conflict`;let r=await so(n.id,e,t);return r===`saved`&&Se(n.id,n=>({...n,queued:n.queued.map(n=>n.queueId===e?{...n,text:t}:n)})),r},[h,Se]),nt=(0,Q.useCallback)(async e=>{let t=h,n=t&&se.current.get(t.id)?.queued.find(t=>t.queueId===e);if(!t||!u(t.id)||!n||n.deliveryMode===`steer`)return`conflict`;let r=await co(t.id,e);return r===`saved`?(he.current.set(t.id,(he.current.get(t.id)??0)+1),Se(t.id,t=>({...t,queued:t.queued.map(t=>t.queueId===e?{...t,deliveryMode:`steer`}:t)}))):oe.current===t.id&&Le(),r},[h,Se,Le]),rt=(0,Q.useCallback)(async e=>{let t=h,n=t&&se.current.get(t.id)?.queued.find(t=>t.queueId===e);if(!t||!u(t.id)||!n||n.deliveryMode===`steer`)return`conflict`;let r=await lo(t.id,e);return r===`saved`?(ce.current.add(e),le.current.add(e),he.current.set(t.id,(he.current.get(t.id)??0)+1),Se(t.id,t=>({...t,queued:t.queued.filter(t=>t.queueId!==e)}))):oe.current===t.id&&Le(),r},[h,Se,Le]),it=(0,Q.useCallback)(e=>ce.current.has(e)&&!le.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 Qa(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]),K=(0,Q.useCallback)(async e=>{u(h?.id)&&(ON(e),h?await at({tierLevel:e}):ne(e))},[h,at]),q=(0,Q.useCallback)(async()=>{let e=((h?.tier_level??te)+1)%4;await K(e)},[h,te,K]),ot=(0,Q.useCallback)(async e=>{h?await at({provider:e}):(L.current=!0,V(e),U(null),ie(null))},[h,at]);(0,Q.useEffect)(()=>{h||L.current||N.length===0||N.includes(B)||(V(wt(N)),U(null),ie(null))},[h,N,B]);let st=(0,Q.useCallback)(async e=>{h?await at({model:e}):(U(e),ie(null))},[h,at]),ct=(0,Q.useCallback)(async e=>{h?await at({reasoningEffort:e}):ie(e)},[h,at]),ut=(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]),Y=(0,Q.useRef)(void 0);(0,Q.useEffect)(()=>{let e=Y.current;if(Y.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),L.current=!1,V(wt(I.current)),U(null),ne(DN()),ie(null))},[qe]),ft=(0,Q.useCallback)(async e=>{if(l)return;qe();let t=await Xa({pinnedProjectId:e===void 0?h?.pinned_project_id??null:e,tierLevel:DN()});m(e=>[t,...e]),g(t),v([])},[h,qe]),pt=(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]),mt=(0,Q.useCallback)(async e=>{u(e)&&(await $a(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),wN(n),n}),Se(e,()=>null),oe.current===e&&(g(null),v([])))},[Se]),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 Qa(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(CN());return t.has(e)?t.delete(e):t.add(e),wN(t),t})},[]),_t=(0,Q.useCallback)(async()=>{A(!0);try{await wo(),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:$e,abort:et,editQueuedMessage:tt,steerQueuedMessage:nt,removeQueuedMessage:rt,wasQueueConsumed:it,cycleTier:q,setTier:K,setProvider:ot,setModel:st,setPinnedProject:ut,newConversation:ft,startNewConversation:dt,materializeDraftConversation:Qe,draftPinnedProjectId:ee,draftProvider:B,draftModel:H,draftTierLevel:te,draftEffort:re,setEffort:ct,selectConversation:pt,deleteConversation:mt,renameConversation:ht,toggleFavoriteConversation:gt,refreshConversations:je,applyPrDecisionSnapshot:xe,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,$e,et,tt,nt,rt,it,q,K,ot,st,ut,ft,dt,Qe,ee,B,H,te,re,ct,pt,mt,ht,gt,je,xe]),yt=F&&i!==`agent`;return(0,$.jsxs)(zN.Provider,{value:vt,children:[e,yt&&d===`open`&&(0,$.jsx)(oN,{}),yt&&d!==`open`&&(0,$.jsx)(pN,{})]})}var KN={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 qN(){return(0,Q.useContext)(zN)??KN}var JN=new Map;function YN(){let e=qN(),t=ZD(),n=lt(),r=Ma(),{registerHandlers:i}=gi(),{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&&JN.set(r,t.captureWorkspace());let i=JN.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){Vy(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(Wy(e.conversationId))throw Error(i(`window.finishPending`));return{version:1,...e,capturedAt:Date.now(),composer:ei(e.conversationId),scroll:By(e.conversationId),workspace:{...n.captureWorkspace(),...e.projectId?{codeSelection:Ny(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&&JN.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,JN.set(t.conversationId,e.workspace),ni(t.conversationId,e.composer),t.projectId&&(e.workspace.codeSelection&&Py(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),Vy(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 XN=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 ZN(this.width*e,this.height*e)}[ft](){return{width:this.width,height:this.height}}toJSON(){return this[ft]()}},ZN=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 XN(this.width/e,this.height/e)}[ft](){return{width:this.width,height:this.height}}toJSON(){return this[ft]()}},QN=class{constructor(e){this.size=e}toLogical(e){return this.size instanceof XN?this.size:this.size.toLogical(e)}toPhysical(e){return this.size instanceof ZN?this.size:this.size.toPhysical(e)}[ft](){return{[`${this.size.type}`]:{width:this.size.width,height:this.size.height}}}toJSON(){return this[ft]()}},$N=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 eP(this.x*e,this.y*e)}[ft](){return{x:this.x,y:this.y}}toJSON(){return this[ft]()}},eP=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 $N(this.x/e,this.y/e)}[ft](){return{x:this.x,y:this.y}}toJSON(){return this[ft]()}},tP=class{constructor(e){this.position=e}toLogical(e){return this.position instanceof $N?this.position:this.position.toLogical(e)}toPhysical(e){return this.position instanceof eP?this.position:this.position.toPhysical(e)}[ft](){return{[`${this.position.type}`]:{x:this.position.x,y:this.position.y}}}toJSON(){return this[ft]()}},nP;(function(e){e[e.Critical=1]=`Critical`,e[e.Informational=2]=`Informational`})(nP||={});var rP=class{constructor(e){this._preventDefault=!1,this.event=e.event,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}},iP;(function(e){e.None=`none`,e.Normal=`normal`,e.Indeterminate=`indeterminate`,e.Paused=`paused`,e.Error=`error`})(iP||={});function aP(){return new cP(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}async function oP(){return Y(`plugin:window|get_all_windows`).then(e=>e.map(e=>new cP(e,{skip:!0})))}var sP=[`tauri://created`,`tauri://error`],cP=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 oP()).find(t=>t.label===e)??null}static getCurrent(){return aP()}static async getAll(){return oP()}static async getFocusedWindow(){for(let e of await oP())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)}:Cr(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)}:Tr(e,t,{target:{kind:`Window`,label:this.label}})}async emit(e,t){if(sP.includes(e)){for(let n of this.listeners[e]||[])n({event:e,id:-1,payload:t});return}return wr(e,t)}async emitTo(e,t,n){if(sP.includes(t)){for(let e of this.listeners[t]||[])e({event:t,id:-1,payload:n});return}return Er(e,t,n)}_handleTauriEvent(e,t){return sP.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 eP(e))}async outerPosition(){return Y(`plugin:window|outer_position`,{label:this.label}).then(e=>new eP(e))}async innerSize(){return Y(`plugin:window|inner_size`,{label:this.label}).then(e=>new ZN(e))}async outerSize(){return Y(`plugin:window|outer_size`,{label:this.label}).then(e=>new ZN(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===nP.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 QN?e:new QN(e)})}async setMinSize(e){return Y(`plugin:window|set_min_size`,{label:this.label,value:e instanceof QN?e:e?new QN(e):null})}async setMaxSize(e){return Y(`plugin:window|set_max_size`,{label:this.label,value:e instanceof QN?e:e?new QN(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 tP?e:new tP(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:ya(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 tP?e:new tP(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?ya(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(Dr.WINDOW_RESIZED,t=>{t.payload=new ZN(t.payload),e(t)})}async onMoved(e){return this.listen(Dr.WINDOW_MOVED,t=>{t.payload=new eP(t.payload),e(t)})}async onCloseRequested(e){return this.listen(Dr.WINDOW_CLOSE_REQUESTED,async t=>{let n=new rP(t);await e(n),n.isPreventDefault()||await this.destroy()})}async onDragDropEvent(e){let t=await this.listen(Dr.DRAG_ENTER,t=>{e({...t,payload:{type:`enter`,paths:t.payload.paths,position:new eP(t.payload.position)}})}),n=await this.listen(Dr.DRAG_OVER,t=>{e({...t,payload:{type:`over`,position:new eP(t.payload.position)}})}),r=await this.listen(Dr.DRAG_DROP,t=>{e({...t,payload:{type:`drop`,paths:t.payload.paths,position:new eP(t.payload.position)}})}),i=await this.listen(Dr.DRAG_LEAVE,t=>{e({...t,payload:{type:`leave`}})});return()=>{t(),r(),n(),i()}}async onFocusChanged(e){let t=await this.listen(Dr.WINDOW_FOCUS,t=>{e({...t,payload:!0})}),n=await this.listen(Dr.WINDOW_BLUR,t=>{e({...t,payload:!1})});return()=>{t(),n()}}async onScaleChanged(e){return this.listen(Dr.WINDOW_SCALE_FACTOR_CHANGED,e)}async onThemeChanged(e){return this.listen(Dr.WINDOW_THEME_CHANGED,e)}},lP;(function(e){e.Disabled=`disabled`,e.Throttle=`throttle`,e.Suspend=`suspend`})(lP||={});var uP;(function(e){e.Default=`default`,e.FluentOverlay=`fluentOverlay`})(uP||={});var dP;(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`})(dP||={});var fP;(function(e){e.FollowsWindowActiveState=`followsWindowActiveState`,e.Active=`active`,e.Inactive=`inactive`})(fP||={});var pP=12e-5,mP=36,hP=140,gP=1.5,_P=6;function vP(e,t){return{x:Math.random()*e,y:Math.random()*t,radius:.35+Math.random()*1.25,alpha:.22+Math.random()*.5,drift:gP+Math.random()*(_P-gP)}}function yP(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 bP(){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=yP(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(hP,Math.max(mP,Math.floor(o*s*pP)));a=Array.from({length:e},()=>vP(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 xP=(0,Q.lazy)(()=>c(()=>import(`./AgentModeCodePane-nHYnJUdP.js`).then(e=>({default:e.AgentModeCodePane})),__vite__mapDeps([81,1,7,10,43,51]))),SP=(0,Q.lazy)(()=>c(()=>import(`./AgentModeJobsPane-DkhcBtoZ.js`).then(e=>({default:e.AgentModeJobsPane})),__vite__mapDeps([82,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,56,51,66,67,69,70,74,78,6,9,11,44,46,47,48,49,50,52,53,54,55,57,58,59,60,61,62,63,64,65,68,71,72,73,75,76,77,83]))),CP=(0,Q.lazy)(()=>c(()=>import(`./AgentModeAnalyticsPane-WZpPaNMa.js`).then(e=>({default:e.AgentModeAnalyticsPane})),__vite__mapDeps([84,1,7,10,43,56,51,66,67])));function wP(){let{t:e}=K(`agent`),{active:t,refreshConversations:n,builderMode:r}=qN(),{codePaneOpen:i,jobsPaneOpen:a,analyticsPaneOpen:o}=ZD(),{activeProjectId:s}=lt(),c=gi(),l=Hy(t?.id??`__new-mission__`),u=!c.current&&c.transfers.some(e=>e.conversationId===t?.id&&e.state===`detached`),d=_a(),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)(K_,{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)(bP,{}),(0,$.jsxs)(`div`,{className:`relative flex h-full min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,$.jsx)(jy.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)(ZM,{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)(jy.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)(Fo,{className:`h-4 w-4 text-accent-primary`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground/80`,children:p})]}),(0,$.jsx)(bA,{autoFocus:!0})]})}):(0,$.jsx)(`div`,{className:`relative z-10 flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,$.jsx)(Aj,{variant:`inline`})})]}),h&&(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`w-[480px] border-l border-border`}),children:(0,$.jsx)(SP,{projectId:s})}),m&&(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`w-[520px] border-l border-border`}),children:(0,$.jsx)(xP,{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)(CP,{})})]})})}var TP=(e,t,n)=>Math.min(n,Math.max(t,e)),EP=e=>`specrails-desktop:sidebar-width:${e}`;function DP(e,t){let n=EP(e),[r,i]=(0,Q.useState)(()=>{try{let e=localStorage.getItem(n),r=e?Number.parseInt(e,10):NaN;if(Number.isFinite(r))return TP(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=TP(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=TP(c.current+r,t.min,t.max):e.key===o?s=TP(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 OP({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 kP=[`pinned-open`,`pinned-collapsed`,`unpinned`],AP=`specrails-desktop:sidebar-mode:left`,jP=`specrails-desktop:sidebar-mode:right`;function MP(e){return typeof e==`string`&&kP.includes(e)}function NP(e){try{let t=window.localStorage.getItem(e);if(MP(t))return t}catch{}return`unpinned`}function PP(e,t){try{window.localStorage.setItem(e,t)}catch{}}function FP(e){switch(e){case`pinned-open`:return`pinned-collapsed`;case`pinned-collapsed`:return`unpinned`;case`unpinned`:return`pinned-open`}}var IP=(0,Q.createContext)({leftMode:`unpinned`,rightMode:`unpinned`,setLeftMode:()=>{},setRightMode:()=>{},cycleLeftMode:()=>{},cycleRightMode:()=>{}});function LP({children:e}){let[t,n]=(0,Q.useState)(()=>NP(AP)),[r,i]=(0,Q.useState)(()=>NP(jP));(0,Q.useEffect)(()=>{PP(AP,t)},[t]),(0,Q.useEffect)(()=>{PP(jP,r)},[r]);let a=(0,Q.useCallback)(e=>n(e),[]),o=(0,Q.useCallback)(e=>i(e),[]),s=(0,Q.useCallback)(()=>n(e=>FP(e)),[]),c=(0,Q.useCallback)(()=>i(e=>FP(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)(IP.Provider,{value:l,children:e})}function RP(){return(0,Q.useContext)(IP)}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}=Ze(),[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=yt(o,`read-only`),P=(0,Q.useMemo)(()=>wM(v??g,{milestoneLabel:M,minSpecs:1,maxSpecs:10,requireScaffold:!1}),[g,v,M]),F=(0,Q.useMemo)(()=>EM(g,v??g,P,{minSpecs:1,maxSpecs:10}),[g,v,P]),I=(0,Q.useMemo)(()=>tn(m),[m]);(0,Q.useEffect)(()=>{if(!e||u||!N)return;let t=!1;return fetch(`${ot()}/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(`${ot()}/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=an(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(`${ot()}/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]),ee=(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]),R=(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(`${ot()}/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 z=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)(Os,{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)(Nn,{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:[Ht(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)(Qj,{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)(Cn,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(_c,{className:`h-3.5 w-3.5`})})]})]}),(0,$.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col lg:w-96`,children:[(0,$.jsx)(nN,{blueprint:g,milestoneLabel:M,snapshot:E}),(0,$.jsx)(aN,{readiness:F,snapshot:E,busy:S||w,primaryLabel:w?s(`commit.creating`):s(`milestone.commit`,{count:z,label:M}),onPrimary:R,onRepair:ee,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)(Os,{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)(Nn,{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 BP({expanded:e}){let{t}=K(`builder`),n=y(),{activeProjectId:r,projects:i}=lt(),{blueprint:a,progress:o,hasBlueprint:s,refresh:c}=Jt(r),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(()=>tM()),[_,v]=(0,Q.useState)(()=>iM()),[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 uM(r,1,h,{autoAdvance:_}),n=sM(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 mM(r,e,n);i.ok?(v(n),aM(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 fM(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 pM(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(ae?`/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&&Bt(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=yt(I,`read-only`),ee=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),nM(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)(UM,{checked:_,onChange:e=>{v(e),aM(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)(Cn,{className:`h-3 w-3 animate-spin`}):(0,$.jsx)(fc,{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)(Os,{className:`w-4 h-4 flex-shrink-0`}),e&&(0,$.jsx)(`span`,{className:`text-xs truncate`,children:t(`sidebar.title`)})]}),l&&w&&(0,Bb.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)(GM,{progress:e,actions:e.n===1?ee: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)(kn,{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 VP={"pinned-open":`sidebarPin.right.pinnedOpen`,"pinned-collapsed":`sidebarPin.right.pinnedCollapsed`,unpinned:`sidebarPin.right.unpinned`};function HP({missionOnly:e=!1}={}){let{t}=K(`agent`),{t:n}=K(`nav`),{t:r}=K(`builder`),{rightMode:i,cycleRightMode:a}=RP(),{activeProjectId:o}=lt(),s=Ma(),c=ZD(),{builderMode:l}=qN(),[u,d]=(0,Q.useState)(!1),f=l.active||i===`pinned-open`||i===`unpinned`&&u,p=DP(`right-workspace`,{side:`right`,defaultWidth:208,min:180,max:460,collapsedWidth:44,expanded:f}),m=i!==`unpinned`,h=n(VP[i]),g=!o,_=[{key:`jobs`,icon:zo,label:t(`workspace.jobs`),onClick:()=>c.toggleJobsPane(),disabled:g,disabledTitle:t(`workspace.requiresProject`)},{key:`analytics`,icon:Bo,label:t(`workspace.analytics`),onClick:()=>c.toggleAnalyticsPane(),disabled:g,disabledTitle:t(`workspace.requiresProject`)},...Me()?[{key:`browser`,icon:D,label:t(`workspace.browser`),onClick:()=>c.openBrowser(),disabled:g,disabledTitle:t(`workspace.requiresProject`)}]:[],...W?[{key:`terminal`,icon:wc,label:t(`workspace.terminal`),onClick:()=>o&&s.togglePanel(o),disabled:g,disabledTitle:t(`workspace.requiresProject`)}]:[],...se?[{key:`files`,icon:ms,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)(OP,{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)(Qs,{className:`w-4 h-4`})})]}),l.active?(0,$.jsx)(j_,{mode:`wait`,initial:!1,children:(0,$.jsxs)(jy.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)(nN,{blueprint:l.session.blueprint,snapshot:l.session.snapshot}),l.session.phase===`chat`&&(0,$.jsx)(aN,{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)(BP,{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 UP=`specrails:terminal-settings-updated`;function WP(e){typeof window>`u`||window.dispatchEvent(new CustomEvent(UP,{detail:e}))}function GP(){return new JP(aP(),window.__TAURI_INTERNALS__.metadata.currentWebview.label,{skip:!0})}async function KP(){return Y(`plugin:webview|get_all_webviews`).then(e=>e.map(e=>new JP(new cP(e.windowLabel,{skip:!0}),e.label,{skip:!0})))}var qP=[`tauri://created`,`tauri://error`],JP=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 KP()).find(t=>t.label===e)??null}static getCurrent(){return GP()}static async getAll(){return KP()}async listen(e,t){return this._handleTauriEvent(e,t)?()=>{let n=this.listeners[e];n.splice(n.indexOf(t),1)}:Cr(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)}:Tr(e,t,{target:{kind:`Webview`,label:this.label}})}async emit(e,t){if(qP.includes(e)){for(let n of this.listeners[e]||[])n({event:e,id:-1,payload:t});return}return wr(e,t)}async emitTo(e,t,n){if(qP.includes(t)){for(let e of this.listeners[t]||[])e({event:t,id:-1,payload:n});return}return Er(e,t,n)}_handleTauriEvent(e,t){return qP.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 eP(e))}async size(){return Y(`plugin:webview|webview_size`,{label:this.label}).then(e=>new ZN(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 QN?e:new QN(e)})}async setPosition(e){return Y(`plugin:webview|set_webview_position`,{label:this.label,value:e instanceof tP?e:new tP(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(Dr.DRAG_ENTER,t=>{e({...t,payload:{type:`enter`,paths:t.payload.paths,position:new eP(t.payload.position)}})}),n=await this.listen(Dr.DRAG_OVER,t=>{e({...t,payload:{type:`over`,position:new eP(t.payload.position)}})}),r=await this.listen(Dr.DRAG_DROP,t=>{e({...t,payload:{type:`drop`,paths:t.payload.paths,position:new eP(t.payload.position)}})}),i=await this.listen(Dr.DRAG_LEAVE,t=>{e({...t,payload:{type:`leave`}})});return()=>{t(),r(),n(),i()}}};function YP(e){return`'${e.replace(/'/g,`'\\''`)}'`}function XP(e){if(/[\x00-\x1f"%!]/.test(e))throw Error(`unsafe-cmd-path`);return`"`+e+`"`}function ZP(e){return`'${e.replace(/'/g,`''`)}'`}function QP(e,t,n=`powershell`){return t?n===`cmd`?XP(e):ZP(e):YP(e)}function $P(e,t,n=`powershell`){return e.map(e=>QP(e,t,n)).join(` `)}function eF(e){return/(?:^|[\\/])cmd(?:\.exe)?$/i.test(e??``)?`cmd`:`powershell`}async function tF(e){if(!ce())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&&rF(s,u.viewportEl.getBoundingClientRect(),window.devicePixelRatio||1))try{u.writeText($P(o,i,eF(u.shell)))}catch{J.error(We.t(`terminal:errors.pathPasteUnsafe`))}},o=nF((()=>{try{return GP()}catch{return null}})());o&&t.push(await o(a));let s=nF((()=>{try{return aP()}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 nF(e){let t=e?.onDragDropEvent;return typeof t==`function`?t.bind(e):null}function rF(e,t,n){let r=Number.isFinite(n)&&n>0?n:1;return iF(e.x/r,e.y/r,t)}function iF(e,t,n){return e>=n.left&&e<=n.right&&t>=n.top&&t<=n.bottom}function aF({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 oF({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:Dt(e)})},e))})}var sF=(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 cF({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,_=Dt(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)(lF,{label:y,disabled:!t,onClick:e=>o(e?{x:e.clientX,y:e.clientY}:void 0),children:(0,$.jsx)(kn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(lF,{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)(lF,{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)($o,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(lF,{label:t?h(`topBar.newTerminal`):v,disabled:!t,onClick:a,children:(0,$.jsx)(Dn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(lF,{label:h(`topBar.killActive`),disabled:!n,onClick:f,children:(0,$.jsx)(An,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(lF,{label:h(e===`maximized`?`topBar.restorePanel`:`topBar.maximizePanel`),onClick:p,children:e===`maximized`?(0,$.jsx)(Ws,{className:`h-3.5 w-3.5`}):(0,$.jsx)(Us,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(sF,{isOpen:!0,onClick:m})]})]})}function lF({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 uF({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)(dF,{session:e,active:e.id===t,onActivate:()=>n(e.id),onRename:t=>r(e.id,t),onKill:()=>i(e.id)},e.id))})})}function dF({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)(Oc,{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)(wn,{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)(Nn,{className:`h-3 w-3`})})]})})}function fF({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)(fn,{size:14})}),(0,$.jsx)(`button`,{type:`button`,title:n(`search.next`),onClick:h,className:`text-[#f8f8f2] hover:text-white p-1`,children:(0,$.jsx)(Wo,{size:14})}),(0,$.jsx)(pF,{label:`Aa`,title:n(`search.matchCase`),active:o,onToggle:()=>s(e=>!e)}),(0,$.jsx)(pF,{label:`.*`,title:n(`search.regex`),active:c,onToggle:()=>l(e=>!e)}),(0,$.jsx)(pF,{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)(Nn,{size:14})})]})}function pF({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 mF({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&&(Ca(m),a())}function _(){Sa().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)(hF,{onClick:g,disabled:!h,label:l(`common:actions.copy`),shortcut:p+`C`}),(0,$.jsx)(hF,{onClick:_,label:l(`contextMenu.paste`),shortcut:p+`V`}),(0,$.jsx)(hF,{onClick:v,label:l(`contextMenu.selectAll`),shortcut:p+`A`}),(0,$.jsx)(gF,{}),(0,$.jsx)(hF,{onClick:y,label:l(`contextMenu.clear`),shortcut:p+`K`}),(0,$.jsx)(hF,{onClick:b,label:l(`contextMenu.search`),shortcut:p+`F`}),(0,$.jsx)(hF,{onClick:x,label:l(`contextMenu.saveScrollback`)}),r&&i&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(gF,{}),(0,$.jsx)(hF,{onClick:S,label:l(`contextMenu.openPath`,{path:_F(r,40)})})]})]})}function hF({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 gF(){return(0,$.jsx)(`div`,{className:`my-1 border-t border-[#44475a]`})}function _F(e,t){return e.length<=t?e:`…`+e.slice(e.length-t+1)}async function vF(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(ce()){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 yF({sessionId:e}){let[t,n]=(0,Q.useState)(()=>Fi(e));return(0,Q.useEffect)(()=>Pi(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 bF({sessionId:e}){let{t}=K(`terminal`),[n,r]=(0,Q.useState)(Fi(e).openPreExec?.startedAt??null),[i,a]=(0,Q.useState)(Date.now());if((0,Q.useEffect)(()=>Pi(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:xF(o,t)})}function xF(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 SF({activeId:e}){let{t}=K(`terminal`),n=(0,Q.useRef)(null),r=Ma(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),c=ce();(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=>CF(e)).filter(e=>!!e);if(i.length===0)return!1;let a=typeof navigator<`u`&&/Win/i.test(navigator.platform||``);try{return m($P(i,a,eF(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=>CF(e)).filter(e=>!!e);if(i.length>0){n.preventDefault(),n.stopPropagation();let a=typeof navigator<`u`&&/Win/i.test(navigator.platform||``);try{m($P(i,a,eF(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(),Ca(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=>{wF(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),p(!0))},onDragOver:e=>{wF(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),p(!0))},onDragLeave:()=>p(!1),onDrop:e=>{wF(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),h(e.dataTransfer.files)),p(!1)},children:[e&&(0,$.jsx)(yF,{sessionId:e}),e&&(0,$.jsx)(bF,{sessionId:e}),i&&l&&(0,$.jsx)(fF,{search:l,onClose:()=>a(!1)}),o&&u&&(0,$.jsx)(mF,{x:o.x,y:o.y,term:u,cwd:d,hasReveal:c,onClose:()=>s(null),onOpenSearch:()=>a(!0),onReveal:e=>{ge(e).catch(()=>J.error(t(`errors.nativeActionFailed`)))},onSaveScrollback:()=>{u&&vF(u).catch(()=>J.error(t(`errors.nativeActionFailed`)))}})]})}function CF(e){let t=e.path;return typeof t==`string`&&t.length>0?t:null}function wF(e){return e?Array.from(e.types).includes(`Files`):!1}function TF({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 EF({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)(Oc,{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)(Dn,{className:`h-3 w-3`}),` `,t(`emptyState.newTerminal`)]})]})})}var DF=300;function OF({projectId:e,provider:t=`claude`,providers:n,state:r,viewportHeight:i,statusBarHeight:a}){let o=Ma(),{t:s}=K(`terminal`),c=y(),l=(0,Q.useRef)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(Di),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),{launchDescriptors:v}=gA(),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(UP,t),()=>window.removeEventListener(UP,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`),DF)):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 tF(()=>{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]),ee=(0,Q.useCallback)(()=>{xe(f.browserShortcutUrl)},[f.browserShortcutUrl]),R=(0,Q.useCallback)(()=>{r.activeId&&f.quickScript&&o.writeToSession(r.activeId,f.quickScript)},[f.quickScript,r.activeId,o]),z=(0,Q.useCallback)(e=>{h({...e,kind:`browser`})},[]),B=(0,Q.useCallback)(e=>{h({...e,kind:`script`})},[]),V=(0,Q.useCallback)(e=>{c(`/settings${e===`browser`?`#terminal-browser-shortcut-url`:`#terminal-quick-script`}`)},[c]),H=(0,Q.useCallback)(()=>{r.activeId&&o.kill(e,r.activeId)},[e,r.activeId,o]),U=(0,Q.useCallback)(()=>{o.setVisibility(e,r.visibility===`maximized`?`restored`:`maximized`)},[e,r.visibility,o]),te=(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)(TF,{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)(cF,{visibility:r.visibility,canCreate:N,hasActive:P,provider:t,providers:w,onCreate:F,onOpenCli:L,onOpenBrowser:ee,onPasteScript:R,pasteScriptDisabled:!P||!f.quickScript,onConfigureBrowser:z,onConfigureScript:B,onKillActive:H,onToggleMaximize:U,onCollapse:te}),m&&(0,$.jsx)(aF,{x:m.x,y:m.y,label:m.kind===`browser`?s(`shortcutMenu.configureBrowserUrl`):s(`shortcutMenu.editQuickScript`),onSelect:()=>V(m.kind),onClose:()=>h(null)}),g&&(0,$.jsx)(oF,{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)(EF,{onCreate:F}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(SF,{activeId:r.activeId}),(0,$.jsx)(uF,{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 kF(){let{t:e}=K(`agent`),{current:t,initialized:n}=gi(),{active:r}=qN(),{activeProjectId:i,projects:a}=lt(),o=Na(i),s=a.find(e=>e.id===i),[c,l]=(0,Q.useState)(window.innerHeight);return(0,Q.useEffect)(()=>{!ce()||!t||r?.id!==t.conversationId||aP().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)(wP,{})}),W&&s&&i&&(0,$.jsx)(OF,{projectId:i,provider:s.provider,providers:st(s),state:o,viewportHeight:c-36,statusBarHeight:0})]}),(0,$.jsx)(HP,{missionOnly:!0})]})}function AF(){var e=[...arguments];return(0,Q.useMemo)(()=>t=>{e.forEach(e=>e(t))},e)}var jF=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function MF(e){let t=Object.prototype.toString.call(e);return t===`[object Window]`||t===`[object global]`}function NF(e){return`nodeType`in e}function PF(e){return e?MF(e)?e:NF(e)?e.ownerDocument?.defaultView??window:window:window}function FF(e){let{Document:t}=PF(e);return e instanceof t}function IF(e){return!MF(e)&&e instanceof PF(e).HTMLElement}function LF(e){return e instanceof PF(e).SVGElement}function RF(e){return e?MF(e)?e.document:NF(e)?FF(e)?e:IF(e)||LF(e)?e.ownerDocument:document:document:document}var zF=jF?Q.useLayoutEffect:Q.useEffect;function BF(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 VF(){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 HF(e,t){t===void 0&&(t=[e]);let n=(0,Q.useRef)(e);return zF(()=>{n.current!==e&&(n.current=e)},t),n}function UF(e,t){let n=(0,Q.useRef)();return(0,Q.useMemo)(()=>{let t=e(n.current);return n.current=t,t},[...t])}function WF(e){let t=BF(e),n=(0,Q.useRef)(null);return[n,(0,Q.useCallback)(e=>{e!==n.current&&t?.(e,n.current),n.current=e},[])]}function GF(e){let t=(0,Q.useRef)();return(0,Q.useEffect)(()=>{t.current=e},[e]),t.current}var KF={};function qF(e,t){return(0,Q.useMemo)(()=>{if(t)return t;let n=KF[e]==null?0:KF[e]+1;return KF[e]=n,e+`-`+n},[e,t])}function JF(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 YF=JF(1),XF=JF(-1);function ZF(e){return`clientX`in e&&`clientY`in e}function QF(e){if(!e)return!1;let{KeyboardEvent:t}=PF(e.target);return t&&e instanceof t}function $F(e){if(!e)return!1;let{TouchEvent:t}=PF(e.target);return t&&e instanceof t}function eI(e){if($F(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 ZF(e)?{x:e.clientX,y:e.clientY}:null}var tI=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[tI.Translate.toString(e),tI.Scale.toString(e)].join(` `)}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+` `+n+`ms `+r}}}),nI=`a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]`;function rI(e){return e.matches(nI)?e:e.querySelector(nI)}var iI={display:`none`};function aI(e){let{id:t,value:n}=e;return Q.createElement(`div`,{id:t,style:iI},n)}function oI(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 sI(){let[e,t]=(0,Q.useState)(``);return{announce:(0,Q.useCallback)(e=>{e!=null&&t(e)},[]),announcement:e}}var cI=(0,Q.createContext)(null);function lI(e){let t=(0,Q.useContext)(cI);(0,Q.useEffect)(()=>{if(!t)throw Error(`useDndMonitor must be used within a children of <DndContext>`);return t(e)},[e,t])}function uI(){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 dI={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 M(){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{ce()&&await ge(e[0])}catch{}n?J.success(i(`railPr.localResultPathCopied`),{description:t}):J.info(i(`railPr.localResultPath`),{description:t})}let N=`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]`}`,P=`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]`}`,F=`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]`}`,I=`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]`}`,L=T?`w-2.5 h-2.5`:`w-3 h-3`,ee=(0,$.jsx)(Cn,{className:`${L} animate-spin`,"aria-hidden":!0}),z=c!==null||u||e.operation!=null,B=s.has(e.prDeliveryId),V=i(g===`implementation_failed`?`railPr.implementationFailedHint`:`railPr.discardTooltip`),H=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)(ln,{className:T?`w-2 h-2`:`w-2.5 h-2.5`,"aria-hidden":!0})]}):null,U=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,te=(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-discard`,disabled:z,title:V,onClick:e=>{e.stopPropagation(),D(`discard`)},className:I,children:[c===`discard`?ee:null,i(`railPr.discard`)]}),ne=!_&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-merge-local`,disabled:z,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`?ee:(0,$.jsx)(ws,{className:L,"aria-hidden":!0}),i(`railPr.mergeLocal`)]}),re=(e,t,n,r,i,a)=>!_&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":r,disabled:z,title:i,onClick:n=>{n.stopPropagation(),A(e,t)},className:P,children:[c===e?ee:a,n]}),ie=ae?(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)(ps,{className:L,"aria-hidden":!0}),i(`railPr.openReview`)]}):null,oe=Gt(e),se=r&&oe&&!_?(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-checkout`,disabled:z,title:i(`railPr.checkoutTooltip`,{branch:oe}),onClick:e=>{e.stopPropagation(),j()},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?ee:(0,$.jsx)(Sn,{className:L,"aria-hidden":!0}),i(`railPr.checkout`)]}):null,le=v.recoveryWorktreePaths.length>0?(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-inspect-local-result`,disabled:z,onClick:e=>{e.stopPropagation(),M()},className:F,title:i(`railPr.inspectLocalResultTooltip`),children:[(0,$.jsx)(bs,{className:L,"aria-hidden":!0}),i(`railPr.inspectLocalResult`)]}):null,ue=v.recoveryRecheck,de=v.manualRecovery||ue?(0,$.jsxs)(`button`,{type:`button`,"data-testid":ue?`rail-pr-recheck-recovery`:`rail-pr-recover-and-retry`,disabled:z,onClick:e=>{e.stopPropagation(),D(`recover-and-retry`)},className:ue?F:P,children:[c===`recover-and-retry`?ee:(0,$.jsx)(pc,{className:L,"aria-hidden":!0}),i(ue?`railPr.recheckRecovery`:`railPr.recoverAndRetry`)]}):null,fe=(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)(gc,{className:L,"aria-hidden":!0}),e.ticketIds[n]==null?t.slice(0,8):`#${e.ticketIds[n]}`]},t)),pe=(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:`${N} ${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}`)}),me=(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-dismiss`,disabled:z,onClick:e=>{e.stopPropagation(),D(`dismiss`)},className:I,children:[c===`dismiss`?ee:null,i(`railPr.dismiss`)]}),he=(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-discard-local`,disabled:z,onClick:e=>{e.stopPropagation(),D(`discard-local`)},className:I,children:[c===`discard`?ee:null,i(`railPr.discardLocalResult`)]}),W=!_&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-no-changes-done`,disabled:z,onClick:e=>{e.stopPropagation(),D(`no-changes-done`)},className:P,children:[c===`acknowledge-no-changes`?ee:(0,$.jsx)(qo,{className:L,"aria-hidden":!0}),i(`railPr.markDone`)]}),_e=(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rail-pr-refine`,disabled:z,onClick:e=>{e.stopPropagation(),D(`refine`)},className:I,children:[c===`discard`?ee:null,i(`railPr.refine`)]}),ve=null,ye=null;return w?(ve=(0,$.jsxs)(`span`,{className:`${N} border-accent-info/30 bg-accent-info/10 text-accent-info`,children:[(0,$.jsx)(Cn,{className:`${L} animate-spin`,"aria-hidden":!0}),i(`railPr.iteratingPr`)]}),ye=(0,$.jsxs)($.Fragment,{children:[H,U]})):v.noChanges?(ve=(0,$.jsxs)(`span`,{className:`${N} border-accent-success/30 bg-accent-success/10 text-accent-success`,children:[(0,$.jsx)(qo,{className:L,"aria-hidden":!0}),i(`railPr.noChanges`)]}),ye=(0,$.jsxs)($.Fragment,{children:[e.prUrl?H:null,v.continuation?me:(0,$.jsxs)($.Fragment,{children:[W,_e]})]})):v.partial&&!v.deliveryBlocked&&!v.retryablePush&&!v.retryablePrCreation&&!v.closed?(ve=(0,$.jsxs)(`span`,{className:`${N} border-accent-warning/30 bg-accent-warning/10 text-accent-warning`,children:[(0,$.jsx)(jn,{className:L,"aria-hidden":!0}),i(`railPr.partial`,{succeeded:v.succeededCount,total:v.totalCount})]}),ye=g===`pr_draft`&&e.prUrl?(0,$.jsxs)($.Fragment,{children:[H,se,re(`publish`,`pr_draft`,i(`railPr.publish`),`rail-pr-publish`,i(`railPr.publishTooltip`)),v.continuation?me:te]}):g===`pr_ready`?(0,$.jsxs)($.Fragment,{children:[H,se,re(`poll-merge`,`pr_ready`,i(`railPr.verifyPr`),`rail-pr-poll`,i(`railPr.verifyPrTooltip`)),v.continuation?me:te]}):g===`on_review`||g===`pr_draft`&&!e.prUrl?(0,$.jsxs)($.Fragment,{children:[se,re(`create-pr`,g,i(`railPr.createPartialPr`,{count:v.deliverableCount}),`rail-pr-create-partial`),v.continuation?me:te]}):(0,$.jsxs)($.Fragment,{children:[H,se,v.continuation?me:te]})):v.deliveryBlocked?(ve=(0,$.jsxs)(`span`,{className:`${N} border-accent-warning/30 bg-accent-warning/10 text-accent-warning`,title:e.statusDetail??void 0,children:[(0,$.jsx)(jn,{className:L,"aria-hidden":!0}),i(`railPr.deliveryBlocked`)]}),ye=(0,$.jsxs)($.Fragment,{children:[H,le,de,v.continuation?v.hasDiscardableRecoveryResult?he:me:te]})):v.retryablePush?(ve=(0,$.jsxs)(`span`,{className:`${N} border-accent-warning/30 bg-accent-warning/10 text-accent-warning`,title:e.statusDetail??void 0,children:[(0,$.jsx)(jn,{className:L,"aria-hidden":!0}),i(`railPr.updateFailed`)]}),ye=(0,$.jsxs)($.Fragment,{children:[H,se,re(`create-pr`,g,i(`railPr.retryPush`),`rail-pr-retry-push`),v.continuation?me:te]})):v.retryablePrCreation?(ve=(0,$.jsxs)(`span`,{className:`${N} border-accent-warning/30 bg-accent-warning/10 text-accent-warning`,title:e.statusDetail??void 0,children:[(0,$.jsx)(jn,{className:L,"aria-hidden":!0}),v.localOnly?i(`railPr.localOnly`):e.prState===`pushed`?i(`railPr.branchPushed`):i(`railPr.prFailed`)]}),ye=(0,$.jsxs)($.Fragment,{children:[re(`create-pr`,g,i(`railPr.retryPr`),`rail-pr-create`),se,ne,v.continuation?me:te]})):v.closed?(ve=(0,$.jsxs)(`span`,{className:`${N} border-accent-warning/30 bg-accent-warning/10 text-accent-warning`,children:[(0,$.jsx)(jn,{className:L,"aria-hidden":!0}),i(`railPr.prClosed`)]}),ye=(0,$.jsxs)($.Fragment,{children:[H,se,re(`reopen`,`pr_closed`,i(`railPr.reopen`),`rail-pr-reopen`,void 0,(0,$.jsx)(pc,{className:L,"aria-hidden":!0})),v.continuation?me:te]})):g===`on_review`?(ve=(0,$.jsxs)(`span`,{className:`${N} border-accent-warning/30 bg-accent-warning/10 text-accent-warning`,children:[(0,$.jsx)(ps,{className:L,"aria-hidden":!0}),i(`railPr.readyForReview`)]}),ye=(0,$.jsxs)($.Fragment,{children:[ie,se,re(`create-pr`,`on_review`,i(`railPr.createPr`),`rail-pr-create`,i(`railPr.createPrTooltip`,{base:e.baseBranch}),(0,$.jsx)(R,{className:L,"aria-hidden":!0})),ne,v.continuation?me:te]})):g===`pr_draft`&&e.prUrl?(ve=(0,$.jsxs)(`span`,{className:`${N} border-accent-info/30 bg-accent-info/10 text-accent-info`,children:[(0,$.jsx)(R,{className:L,"aria-hidden":!0}),i(`railPr.draftPr`)]}),ye=(0,$.jsxs)($.Fragment,{children:[H,se,re(`publish`,`pr_draft`,i(`railPr.publish`),`rail-pr-publish`,i(`railPr.publishTooltip`)),v.continuation?me:te]})):g===`pr_draft`?(ve=(0,$.jsxs)(`span`,{className:`${N} border-accent-warning/30 bg-accent-warning/10 text-accent-warning`,title:i(`railPr.branchPushedHint`),children:[(0,$.jsx)(jn,{className:L,"aria-hidden":!0}),v.localOnly?i(`railPr.localOnly`):i(`railPr.branchPushed`)]}),ye=(0,$.jsxs)($.Fragment,{children:[re(`create-pr`,`pr_draft`,i(`railPr.retryPr`),`rail-pr-create`,i(`railPr.createPrTooltip`,{base:e.baseBranch})),se,ne,v.continuation?me:te]})):g===`pr_ready`?(ve=(0,$.jsxs)(`span`,{className:`${N} border-accent-success/30 bg-accent-success/10 text-accent-success`,children:[(0,$.jsx)(ws,{className:L,"aria-hidden":!0}),i(`railPr.prReady`)]}),ye=(0,$.jsxs)($.Fragment,{children:[H,se,re(`poll-merge`,`pr_ready`,i(`railPr.verifyPr`),`rail-pr-poll`,i(`railPr.verifyPrTooltip`)),v.continuation?me:te]})):g===`pr_failed`?(ve=(0,$.jsxs)(`span`,{className:`${N} border-destructive/30 bg-destructive/10 text-destructive`,children:[(0,$.jsx)(jn,{className:L,"aria-hidden":!0}),i(`railPr.prFailed`)]}),ye=(0,$.jsxs)($.Fragment,{children:[H,se,re(`create-pr`,`pr_failed`,i(`railPr.retry`),`rail-pr-create`,i(`railPr.createPrTooltip`,{base:e.baseBranch})),!e.prUrl&&ne,v.continuation?me:te]})):g===`implementation_failed`&&v.implementationFailed&&(ve=(0,$.jsxs)(`span`,{className:`${N} border-destructive/30 bg-destructive/10 text-destructive`,title:i(`railPr.implementationFailedHint`),children:[(0,$.jsx)(jn,{className:L,"aria-hidden":!0}),i(`railPr.implementationFailed`)]}),ye=(0,$.jsx)($.Fragment,{children:v.continuation?me:te})),(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)($t,{deliveryId:e.prDeliveryId,repositories:e.repositoryDeliveries,busy:z,onAct:(t,n)=>A(t,e.decision,e.prDeliveryId,n),onCheckout:r?j:void 0}),ve,e.operation&&(0,$.jsxs)(`span`,{className:`${N} border-accent-info/30 bg-accent-info/10 text-accent-info`,"data-testid":`rail-pr-operation`,children:[(0,$.jsx)(Cn,{className:`${L} animate-spin`,"aria-hidden":!0}),i(`railPr.operation.${e.operation}`)]}),ye,e.deliverySha&&(0,$.jsxs)(`span`,{className:`${N} ${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)(qo,{className:L,"aria-hidden":!0}),i(`railPr.deliveryCommit`,{sha:e.deliverySha.slice(0,8)})]}),fe,pe,S&&(0,$.jsx)(`span`,{className:`${N} 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)(pc,{className:`${L} 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)(sr,{open:E(`merge-local`),onOpenChange:e=>{e||O()},children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`rail-pr-merge-local-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:i(`railPr.mergeLocalConfirmTitle`)}),(0,$.jsx)(Zn,{children:i(`railPr.mergeLocalConfirmBody`,{base:e.baseBranch})})]}),(0,$.jsxs)(Wn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,children:i(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:z,"data-testid":`rail-pr-merge-local-confirm-btn`,onClick:()=>k(`merge-local`,`merge-local`),children:i(`railPr.mergeLocal`)})]})]})}),(0,$.jsx)(sr,{open:E(`discard`),onOpenChange:e=>{e||O()},children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`rail-pr-discard-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:i(g===`implementation_failed`?`railPr.implementationFailedDiscardTitle`:`railPr.discardConfirmTitle`)}),(0,$.jsx)(Zn,{children:i(g===`implementation_failed`?`railPr.implementationFailedDiscardBody`:`railPr.discardConfirmBody`)}),B&&(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)(Wn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,children:i(`common:actions.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,size:`sm`,disabled:z,"data-testid":`rail-pr-discard-confirm-btn`,onClick:()=>k(`discard`,`discard`),children:i(`railPr.discard`)})]})]})}),(0,$.jsx)(sr,{open:E(`dismiss`),onOpenChange:e=>{e||O()},children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`rail-pr-dismiss-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:i(`railPr.dismissConfirmTitle`)}),(0,$.jsx)(Zn,{children:i(`railPr.dismissConfirmBody`)})]}),(0,$.jsxs)(Wn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,children:i(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:z,"data-testid":`rail-pr-dismiss-confirm-btn`,onClick:()=>k(`dismiss`,`dismiss`),children:i(`railPr.dismiss`)})]})]})}),(0,$.jsx)(sr,{open:E(`discard-local`),onOpenChange:e=>{e||O()},children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`rail-pr-discard-local-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:i(`railPr.discardLocalConfirmTitle`)}),(0,$.jsx)(Zn,{children:i(`railPr.discardLocalConfirmBody`)})]}),(0,$.jsxs)(Wn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,children:i(`common:actions.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,size:`sm`,disabled:z,"data-testid":`rail-pr-discard-local-confirm-btn`,onClick:()=>k(`discard-local`,`discard`),children:i(`railPr.discardLocalResult`)})]})]})}),(0,$.jsx)(sr,{open:E(`no-changes-done`),onOpenChange:e=>{e||O()},children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`rail-pr-no-changes-done-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:i(`railPr.markDoneConfirmTitle`)}),(0,$.jsx)(Zn,{children:i(`railPr.markDoneConfirmBody`)})]}),(0,$.jsxs)(Wn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,children:i(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:z,"data-testid":`rail-pr-no-changes-done-confirm-btn`,onClick:()=>k(`no-changes-done`,`acknowledge-no-changes`),children:i(`railPr.markDone`)})]})]})}),(0,$.jsx)(sr,{open:E(`refine`),onOpenChange:e=>{e||O()},children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`rail-pr-refine-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:i(`railPr.refineConfirmTitle`)}),(0,$.jsx)(Zn,{children:i(`railPr.refineConfirmBody`)})]}),(0,$.jsxs)(Wn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,children:i(`common:actions.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,size:`sm`,disabled:z,"data-testid":`rail-pr-refine-confirm-btn`,onClick:()=>k(`refine`,`discard`),children:i(`railPr.refine`)})]})]})}),(0,$.jsx)(sr,{open:E(`recover-and-retry`),onOpenChange:e=>{e||O()},children:(0,$.jsxs)(ar,{className:`max-w-sm`,"data-testid":`rail-pr-recover-and-retry-confirm`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:i(ue?`railPr.recheckRecoveryConfirmTitle`:`railPr.recoverAndRetryConfirmTitle`)}),(0,$.jsx)(Zn,{children:i(ue?`railPr.recheckRecoveryConfirmBody`:`railPr.recoverAndRetryConfirmBody`,{branch:e.branch??``})})]}),(0,$.jsxs)(Wn,{children:[(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:O,children:i(`common:actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:z,onClick:()=>k(`recover-and-retry`,`recover-and-retry`),children:i(ue?`railPr.recheckRecovery`:`railPr.recoverAndRetry`)})]})]})})]})}function sU({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(`${ot()}/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)(R,{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)(Nn,{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)(R,{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)(Cn,{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)(Cs,{className:`mt-0.5 h-3 w-3 shrink-0`,"aria-hidden":!0}):(0,$.jsx)(R,{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 cU(e){return`rail-${e+1}`}function lU(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 uU=800;function dU({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:ee}=K(`dashboard`),{activeProjectId:R}=lt(),z=lU(e),B=bt(s),V=(B?u?.[0]:s)??u?.[0]??`claude`,H=!B&&_t(V),U=!B&&gt(V),te=!!E&&i!==`running`&&(u?.length??0)>1,ne=!!T&&i!==`running`&&H&&r!==`loop`,re=!!D&&i!==`running`&&r===`freestyle`&&U,ie=!!O&&i!==`running`&&r===`loop`&&!B,ae=V,oe=Ix(ae),se=l&&(oe.some(e=>e.value===l)||kt(ae)&&WO(l))?l:Lx(ae),ce=!B&&St(V,se),le=B&&i!==`running`,ue=le?(0,$.jsxs)(`span`,{"data-testid":`rail-roles-chip`,title:ee(`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)(Is,{className:`w-3 h-3`}),ee(`agents:railSelectors.rolesChip`)]}):null,de=ie&&O?(0,$.jsx)(nU,{provider:ae,value:se,onChange:O,testId:`loop-model-selector`,ariaLabel:ee(`railSelectors.loopModelTitle`)}):null,fe=!!k&&i!==`running`,pe=te||re||ie||fe||le,[me,he]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!me)return;function e(e){e.target?.closest(`[role="menu"]`)||he(null)}function t(e){e.key===`Escape`&&he(null)}return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[me]);let{isOver:W,setNodeRef:ge}=DR({id:e}),{active:_e}=wR(),ve=typeof _e?.id==`number`,[ye,be]=(0,Q.useState)(0),[xe,Se]=(0,Q.useState)(!1),[G,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},uU))},[Ne,F]),Ie=(0,Q.useCallback)(e=>{let t=e.touches[0];ke.current={x:t.clientX,y:t.clientY},Se(!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&&(Se(!0),be(Math.max(n,-150)))},[Ne,Pe]),Re=(0,Q.useCallback)(()=>{Pe(),xe&&(ye<-60&&Ne?(Ce(!0),be(-80)):(be(0),Ce(!1)),Se(!1)),ke.current=null},[ye,xe,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}G&&(Ce(!1),be(0))},[G]),He=(0,Q.useCallback)(e=>{e.stopPropagation(),Ce(!1),be(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:ge,"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 ${W?`border-accent-info/60 shadow-[0_0_0_1px_hsl(var(--accent-info)/0.35),0_0_14px_hsl(var(--accent-info)/0.18)]`:ve?`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)(Ds,{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(),he({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))}),me&&L&&(0,Bb.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(me.y,window.innerHeight-60),left:Math.min(me.x,window.innerWidth-180)},onPointerDown:e=>e.stopPropagation(),children:(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:e=>{e.stopPropagation(),L(me.ticketId),he(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)(on,{className:`w-3 h-3`,"aria-hidden":!0}),ee(`railRow.moveToSpecs`)]})}),document.body),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[E&&!Me&&(0,$.jsx)(tU,{value:s??null,providers:u??[],onChange:E}),ue,T&&!Me&&H&&r!==`loop`&&(0,$.jsx)(eU,{provider:V,value:o??null,onChange:T}),D&&!Me&&r===`freestyle`&&U&&(0,$.jsx)(nU,{provider:V,value:c??null,onChange:D}),de,k&&!Me&&(0,$.jsx)(rU,{value:Wx(f,r),onChange:k,freestyleAvailable:U,loopsEnabled:d}),A&&!Me&&r===`loop`&&ce&&(0,$.jsx)(aU,{provider:V,model:se,value:p??null,onChange:A}),j&&!Me&&z!==null&&(0,$.jsx)(sU,{railIndex:z,value:m??null,onChange:j}),(0,$.jsx)(QH,{mode:r,status:i,activeJobId:a,ticketCount:n.length,freestyleAvailable:U,loopAvailable:d,onModeChange:w,onToggle:M})]}),Me&&y&&(0,$.jsx)(iU,{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:ee(`railControls.worktreesMerged`,{count:h.merged})}),h.needsReview>0&&(0,$.jsx)(`span`,{className:`text-accent-warning`,children:ee(`railControls.worktreesNeedsReview`,{count:h.needsReview})})]}),R&&z!==null&&(0,$.jsx)(ZH,{projectId:R,railIndex:z,contextual:!0}),g&&_&&(0,$.jsx)(`div`,{className:`mt-1`,children:(0,$.jsx)(oU,{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":ee(`railRow.deleteRail`,{label:t}),children:(0,$.jsx)(An,{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&&(G||ye<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)(An,{className:`w-5 h-5`}),(0,$.jsx)(`span`,{className:`text-[9px] font-medium`,children:ee(`common:actions.delete`)})]})}),(0,$.jsxs)(`div`,{className:`relative z-10 flex flex-col rounded-xl border overflow-hidden bg-card ${b&&Ne?`animate-jiggle`:``} ${W?`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:ye<0?`translateX(${ye}px)`:void 0,transition:xe?`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)(Ds,{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:[!pe&&ne&&T&&(0,$.jsx)(eU,{provider:V,value:o??null,onChange:T}),(0,$.jsx)(QH,{mode:r,status:i,activeJobId:a,ticketCount:n.length,freestyleAvailable:U,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)(An,{className:`w-3 h-3`})})]})]}),Me&&y&&(0,$.jsx)(`div`,{className:`px-3 pb-1`,children:(0,$.jsx)(iU,{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:ee(`railControls.worktreesMerged`,{count:h.merged})}),h.needsReview>0&&(0,$.jsx)(`span`,{className:`text-accent-warning`,children:ee(`railControls.worktreesNeedsReview`,{count:h.needsReview})})]}),R&&z!==null&&(0,$.jsx)(ZH,{projectId:R,railIndex:z,contextual:!0}),g&&_&&(0,$.jsx)(`div`,{className:`px-3 pb-1.5`,children:(0,$.jsx)(oU,{decision:g,density:`normal`,act:_,checkout:v},g.prDeliveryId)}),pe&&(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:[te&&E&&(0,$.jsx)(tU,{value:s??null,providers:u??[],onChange:E}),ue,pe&&ne&&T&&(0,$.jsx)(eU,{provider:V,value:o??null,onChange:T}),re&&D&&(0,$.jsx)(nU,{provider:V,value:c??null,onChange:D}),de,fe&&k&&(0,$.jsx)(rU,{value:Wx(f,r),onChange:k,freestyleAvailable:U,loopsEnabled:d}),r===`loop`&&!Me&&ce&&A&&(0,$.jsx)(aU,{provider:V,model:se,value:p??null,onChange:A}),j&&!Me&&z!==null&&(0,$.jsx)(sU,{railIndex:z,value:m??null,onChange:j})]})]}),(0,$.jsx)(`div`,{ref:ge,"data-drop-target":ve?`available`:void 0,className:`min-h-[56px] px-3 py-2 space-y-1.5 transition-colors duration-150 ${W?`bg-accent-info/[0.06]`:ve?`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 ${W?`border-accent-info/60 text-accent-info/80 bg-accent-info/[0.06]`:ve?`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:ee(W?`railRow.dropHere`:ve?`railRow.dropOnThisRail`:`railRow.dragSpecsHere`)})}):(0,$.jsx)(ZR,{items:n.map(e=>e.id),strategy:qR,children:n.map(e=>(0,$.jsx)(`div`,{onMouseDown:t=>{t.button===2&&L&&(t.preventDefault(),t.stopPropagation(),he({ticketId:e.id,x:t.clientX,y:t.clientY}))},onContextMenu:e=>{L&&(e.preventDefault(),e.stopPropagation())},children:(0,$.jsx)(gz,{ticket:e,onClick:N,dragDisabled:i===`running`})},e.id))})}),me&&L&&C===`normal`&&(0,Bb.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(me.y,window.innerHeight-60),left:Math.min(me.x,window.innerWidth-180)},onPointerDown:e=>e.stopPropagation(),children:(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:e=>{e.stopPropagation(),L(me.ticketId),he(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)(on,{className:`w-3 h-3`,"aria-hidden":!0}),ee(`railRow.moveToSpecs`)]})}),document.body)]})]})}function fU(e,t,n,r){return{...e,[t]:{...e[t]??{},[n]:r}}}function pU(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 mU=`__rail:`;function hU(e){return`${mU}${e}`}function gU(e){return typeof e==`string`&&e.startsWith(`__rail:`)}function _U(e){return e.slice(7)}function vU(e,t,n){let r=new Set(n),i=cU(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 yU({railId:e,children:t}){let{attributes:n,listeners:r,setNodeRef:i,transform:a,transition:o,isDragging:s}=az({id:hU(e)});return(0,$.jsx)(`div`,{ref:i,style:{transform:tI.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 bU({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=>hU(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)(Is,{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)(fc,{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)(Dn,{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)(ZR,{items:N,strategy:qR,children:e.map((e,y)=>{let C=lU(e.id)??y;return(0,$.jsx)(yU,{railId:e.id,children:({listeners:w,attributes:T})=>(0,$.jsx)(`div`,{"data-tour":y===0?`rail-1`:void 0,children:(0,$.jsx)(dU,{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:pU(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 xU=new Set([`editing`,`writing`,`reading`,`searching`,`running`]);function SU(e){return e.length>40?`${e.slice(0,39)}…`:e}function CU(e){return typeof e!=`string`||e.length===0?``:SU(e.replace(/\\/g,`/`).split(`/`).filter(Boolean).pop()??``)}function wU(e){return typeof e!=`string`||e.length===0?``:SU((e.trim().split(/\s+/)[0]??``).replace(/^['"`]+/,``))}var TU=/(^|\/)(ba|z|k|da|fi)?sh$/;function EU(e){if(e.length===0||!TU.test(e[0]))return e;let t=e.slice(1).filter(e=>!e.startsWith(`-`));return t.length>0?t:e}function DU(e){return Array.isArray(e)?wU(EU(e.filter(e=>typeof e==`string`)).join(` `)):typeof e!=`string`||e.length===0?``:wU(EU(e.trim().split(/\s+/)).join(` `))}function OU(e){return Array.isArray(e)?EU(e.filter(e=>typeof e==`string`)).join(` `).trim():typeof e!=`string`||e.length===0?``:EU(e.trim().split(/\s+/)).join(` `).trim()}function kU(e){if(typeof e!=`string`)return``;try{let t=JSON.parse(e)?.command;if(Array.isArray(t)||typeof t==`string`)return DU(t)}catch{}return``}function AU(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 jU(e,t){let n=t??{},r=CU(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:SU(String(n.pattern??n.query??``))};case`bash`:case`shell`:return{step:!0,actionKey:`running`,actionArg:DU(n.command)};case`task`:return{step:!0,actionKey:`delegating`,actionArg:SU(String(n.subagent_type??n.description??``).replace(/^sr-/,``))};default:return{step:!0,actionKey:`working`}}}function MU(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 NU(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{...jU(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{...jU(e.name,MU(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 jU(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 jU(AU(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:DU(e?.command)||kU(e?.arguments)||(typeof e?.name==`string`?SU(e.name):``)||(t===`local_shell_call`?`shell`:``)}:{step:!0}}return{step:!1}}function PU(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 OU(e)}return``}if(e.event_type===`agent-event`){let e=t.event;return e?.kind===`tool-start`&&typeof e.tool==`string`&&AU(e.tool)===`bash`&&typeof e.detail==`string`?OU(e.detail):``}if(e.event_type===`item.completed`){let e=t.item;if(!e)return``;if(e.command)return OU(e.command);if(typeof e.arguments==`string`)try{let t=JSON.parse(e.arguments);if(t?.command)return OU(t.command)}catch{return``}}return``}var FU=(0,Q.createContext)({});function IU(){return(0,Q.useContext)(FU)}function LU({activeProjectId:e,children:t}){let[n,r]=(0,Q.useState)(new Map),{registerHandler:i,unregisterHandler:a}=Ze(),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=NU({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)(FU.Provider,{value:c,children:t})}var RU=(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)(RU)}function BU(e,t){return nn(e,t)}var VU=new Set([`merged`,`discarded`,`completed`,`superseded`]),HU=new Set([`create-pr`,`publish`,`discard`,`poll-merge`,`merge-local`,`dismiss`,`reopen`,`acknowledge-no-changes`,`recover-and-retry`]);function UU(e,t){return JSON.stringify(e)===JSON.stringify(t)}function WU({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}=Ze(),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=VU.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=Ft(a.updatedAt,e.updatedAt);if(t===-1||t===0&&!UU(a,e))return`stale`;if(t===0&&UU(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=BU(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&&!VU.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=nn(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=nn(r.snapshot),c;return s&&u.current===o&&(c=v(s)),{...r,snapshot:s,snapshotApplication:c,busy:e.status===409&&r.error===`operation_in_progress`,operation:s?.operation??(typeof r.operation==`string`&&HU.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]),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)(RU.Provider,{value:w,children:t})}function GU(e){return e?`specrails-desktop:dashboard-split:${e}`:null}function KU(e){let t=GU(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 qU(e,t){let n=GU(e);if(n)try{localStorage.setItem(n,String(Math.round(t)))}catch{}}function JU(e,t){let n=Math.max(320,t-280);return Math.min(Math.max(e,320),n)}var YU=.7;function XU(e){return JU(Math.round(e*YU),e)}function ZU(e,t){let n=XU(t);return Math.abs(e-n)<=48?n:e}function QU(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:XU(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(XU(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??KU(e)??XU(t),a=JU(r!==null&&Number.isFinite(n)?i+n:i,t);return a!==r&&qU(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=JU(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=JU(ZU(t,n),n);return qU(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=XU(n);o(r),qU(e,r)},[e,t]);return{leftWidth:a,enabled:a!==null&&n>=900,beginDrag:p,resetToDefault:m}}function $U({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 eW({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)(sr,{open:e,onOpenChange:e=>!e&&n(),children:(0,$.jsxs)(ar,{movableResizable:!0,className:`max-w-lg glass-card`,children:[(0,$.jsx)(rr,{children:(0,$.jsx)(er,{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)(br,{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)(yn,{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)(Wn,{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)(Dn,{className:`w-3.5 h-3.5 mr-1`}),i(y?`createModal.creating`:`createModal.create`)]})]})]})})}function tW({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=Dt(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)(sr,{open:e,onOpenChange:e=>{e||o()},children:(0,$.jsxs)(ar,{movableResizable:!0,showCloseButton:!1,className:`max-w-md gap-5`,onOpenAutoFocus:e=>{e.preventDefault(),c.current?.focus()},children:[(0,$.jsx)(rr,{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)(kn,{className:`h-4.5 w-4.5`})}),(0,$.jsxs)(`div`,{className:`text-left`,children:[(0,$.jsx)(er,{className:`text-base`,children:s(`freestyleDialog.title`)}),(0,$.jsxs)(Zn,{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)(Sn,{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)(Fo,{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)(us,{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)(Wn,{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 nW(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 rW({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)(sr,{open:e,onOpenChange:e=>{e||i()},children:(0,$.jsxs)(ar,{movableResizable:!0,showCloseButton:!1,className:`max-w-md gap-5`,onOpenAutoFocus:e=>{e.preventDefault(),o.current?.focus()},children:[(0,$.jsx)(rr,{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)(fc,{className:`h-4.5 w-4.5`})}),(0,$.jsxs)(`div`,{className:`text-left`,children:[(0,$.jsx)(er,{className:`text-base`,children:a(`launchAllDialog.title`)}),(0,$.jsxs)(Zn,{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)(Sn,{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)(Is,{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)(us,{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)(Wn,{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:nW(`⌘↵`)})]})]})]})})}function iW({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)(sr,{open:e,onOpenChange:e=>{e||r()},children:(0,$.jsxs)(ar,{movableResizable:!0,showCloseButton:!1,className:`max-w-md gap-5`,onOpenAutoFocus:e=>{e.preventDefault(),a.current?.focus()},children:[(0,$.jsx)(rr,{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)(R,{className:`h-4.5 w-4.5`})}),(0,$.jsxs)(`div`,{className:`text-left`,children:[(0,$.jsx)(er,{className:`text-base`,children:i(`targetPr.confirmTitle`)}),(0,$.jsx)(Zn,{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)(R,{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)(Sn,{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)(Wn,{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:nW(`⌘↵`)})]})]})]})}):null}var aW=`postit`,oW=e=>`specrails-desktop:specs-view-tier:${e}`;function sW(e){return e===`row`||e===`postit`}function cW(e){if(!e)return aW;try{let t=localStorage.getItem(oW(e));if(sW(t))return t}catch{}return aW}function lW(e,t){if(e)try{localStorage.setItem(oW(e),t)}catch{}}function uW(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 dW(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 fW=[{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`}],pW=e=>e===`implement`||e===`batch-implement`||e===`freestyle`||e===`loop`;function mW(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 hW(e,t){for(let n of t.values())if(mW(n,[e]))return!0;return!1}function gW(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 _W(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 vW(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 yW(e,t){if(e)try{localStorage.setItem(`specrails-desktop:rails:${e}`,JSON.stringify(t))}catch{}}function bW(){let{t:e}=K(`dashboard`),{activeProjectId:t,projects:n}=lt(),r=_a().id===`galaxy`,i=(()=>{let e=n.find(e=>e.id===t);return e?st(e):[`claude`]})(),{tickets:a,isLoading:o,error:s,updateTicket:c,updateTicketStatus:l,updateTicketPriority:u,deleteTicket:d,createTicket:f,refetch:p,contractRefiningIds:m}=E(),{registerHandler:h,unregisterHandler:g,connectionStatus:_}=Ze(),{specToOpen:v,clearSpecToOpen:y}=zB(),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),[D,O]=(0,Q.useState)(null),[k,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)(()=>gW(t)),[L,ee]=(0,Q.useState)(()=>vW(t)??fW),[R,z]=(0,Q.useState)({}),B=IU(),{decisions:V,hydrated:H,act:U,checkout:te}=zU(),ne=mB(t),[re,ie]=(0,Q.useState)(ne.mode),[ae,oe]=(0,Q.useState)(ne.dir),[se,ce]=(0,Q.useState)(()=>cW(t));(0,Q.useEffect)(()=>{I(gW(t)),ee(vW(t)??fW),z({});let e=mB(t);ie(e.mode),oe(e.dir),ce(cW(t))},[t]);let le=(0,Q.useCallback)((e,n)=>{ie(e),oe(n),hB(t,e,n)},[t]),ue=(0,Q.useCallback)(e=>{ce(e),lW(t,e)},[t]);(0,Q.useEffect)(()=>{if(_!==`connected`||!t)return;let e=!1,n=vW(t)??fW,r=new Map(n.map(e=>[e.id,e]));return fetch(`${ot()}/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));ee(e=>{let n=!1,u=new Map,d=e.map((e,t)=>{let s=lU(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=pW(a)?a:l?Ux(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=cU(e.railIndex);if(f.has(t))continue;let r=a[String(e.railIndex)],s=i[String(e.railIndex)]?.mode,l=pW(s)?s:r?Ux(r.loopId):pW(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=lU(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 yW(t,g),g})}).catch(()=>{}),()=>{e=!0}},[t,_]),(0,Q.useEffect)(()=>{if(!t)return;let e=!1;return fetch(`${ot()}/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);ee(e=>{let n=!1,i=e.map((e,t)=>{let i=lU(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?(yW(t,i),i):e})}).catch(()=>{}),()=>{e=!0}},[t]),(0,Q.useEffect)(()=>{let e=new Set(a.filter(e=>e.status===`done`||H&&e.status===`on_review`&&!hW(e.id,V)).map(e=>e.id));e.size!==0&&ee(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:(yW(t,r),r)})},[a,t,L,V,H]);let de=(0,Q.useCallback)(e=>{I(n=>{let r=e(n);return _W(t,r),r})},[t]),fe=(0,Q.useCallback)(e=>{ee(n=>{let r=e(n);return yW(t,r),r})},[t]),pe=(0,Q.useMemo)(()=>{let e=new Set([`specs`,`done-specs`]);for(let t of L)e.add(t.id);return e},[L]),me=(0,Q.useCallback)(async()=>{try{let t=await fetch(`${ot()}/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=cU(n);fe(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=>lU(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`};fe(e=>[...e,r]),J.success(e(`toasts.railAdded`,{n}))},[L,fe,e]),he=(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&&de(e=>[...e??[],...n.ticketIds]),fe(e=>e.filter(e=>e.id!==t)),J.info(e(`toasts.railRemoved`,{rail:n.label}))},i=lU(t);if(i===null){r();return}try{let t=await fetch(`${ot()}/rails/${i}`,{method:`DELETE`});if(t.ok||t.status===404){r();return}J.error(e(`toasts.railDeleteFailed`))}catch{J.error(e(`toasts.railDeleteFailed`))}},[L,fe,de,e]),W=(0,Q.useCallback)((e,t)=>{fe(n=>n.map(n=>n.id===e?{...n,label:`Rail ${t}`}:n));let n=lU(e);n!==null&&fetch(`${ot()}/rails/${n}/name`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})}).catch(()=>{})},[fe]),ge=(0,Q.useRef)(t);(0,Q.useEffect)(()=>{ge.current=t},[t]);let _e=(0,Q.useCallback)(t=>{let n=t;if(n.projectId===ge.current){if(n.type===`runtime.continuation`){if(n.railIndex==null)return;let e=cU(n.railIndex);fe(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=cU(n.railIndex),t=n.jobId??n.loopRunId;fe(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=cU(e),r=n.ticketIds??[],i=n.name?`Rail ${n.name}`:`Rail ${e+1}`;fe(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:pW(n.mode)?n.mode:`implement`,status:`idle`}]);return}if(n.type===`rail.removed`){if(n.railIndex==null)return;let e=cU(n.railIndex);fe(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&&(z(e=>fU(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;fe(e=>vU(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;fe(e=>vU(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`}))}}},[fe,e]);(0,Q.useEffect)(()=>(h(`dashboard-rails`,_e),()=>g(`dashboard-rails`)),[_e,h,g]);let ve=_I(gI(SL,{activationConstraint:{distance:5}}),gI(_L)),ye=(0,Q.useCallback)(e=>{let t=typeof e.active.id==`string`&&gU(e.active.id),n=e.droppableContainers.filter(e=>{let n=e.id;return typeof n==`string`&&gU(n)?t:!t}),r={...e,droppableContainers:n};if(t)return DI(r);let i=jI(r);if(wI(i))return i;let a=kI(r);return wI(a)?a:DI(r)},[]),be=(0,Q.useMemo)(()=>new Map(a.map(e=>[e.id,e])),[a]),xe=(0,Q.useMemo)(()=>{let e=[],t=[];return L.forEach((n,r)=>{let i=lU(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=V.get(i);if(a&&!mW(a,n.ticketIds)){t.push({rail:n,reason:`pendingDecision`});return}if(n.ticketIds.some(e=>be.get(e)?.status===`on_review`&&(!H||!hW(e,V)))){t.push({rail:n,reason:`onReview`});return}e.push(n)}),{eligible:e,skipped:t}},[L,V,H,be]),Se=(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]),we=(0,Q.useMemo)(()=>{let e=new Set;for(let t of L)for(let n of t.ticketIds)e.add(n);return e},[L]),Te=(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`)&&!we.has(e.id)),[a,we]);(0,Q.useEffect)(()=>{o||re===`jira-key`&&!Te.some(e=>e.jira_key)&&le(`default`,ae)},[o,re,ae,Te,le]);let Ee=(0,Q.useMemo)(()=>{let e=Te.filter(e=>e.status!==`done`);if(re!=="default")return SB(e,re,ae);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},[Te,F,re,ae]),De=(0,Q.useMemo)(()=>Te.filter(e=>e.status===`done`),[Te]),Oe=(0,Q.useMemo)(()=>{let e=new Set;if(!H)return e;for(let t of a)t.status===`on_review`&&hW(t.id,V)&&e.add(t.id);return e},[a,V,H]),ke=(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`&&(!H||!hW(t,V))){J.info(e(`toasts.onReviewCannotMoveToRail`));return}if(r.ticketIds.includes(t)){J.info(e(`toasts.alreadyOnRail`,{rail:r.label}));return}de(e=>(e??Ee.map(e=>e.id)).filter(e=>e!==t)),fe(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,Ee,fe,de,e,V,H]),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}fe(e=>e.map(e=>e.id===n.id?{...e,ticketIds:e.ticketIds.filter(e=>e!==t)}:e)),de(e=>{let n=e??Ee.map(e=>e.id);return n.includes(t)?n:[...n,t]}),J.success(e(`toasts.removedFromRail`,{rail:n.label}))}},[L,Ee,fe,de,e]),je=(0,Q.useCallback)(e=>{if(Ee.some(t=>t.id===e))return`specs`;if(De.some(t=>t.id===e))return`done-specs`;for(let t of L)if(t.ticketIds.includes(e))return t.id;return null},[Ee,De,L]);function Me({active:e}){if(gU(e.id)){let t=_U(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(gU(n.id)){if(!gU(r.id))return;let e=_U(n.id),t=_U(r.id);if(e===t)return;fe(n=>{let r=n.findIndex(t=>t.id===e),i=n.findIndex(e=>e.id===t);return r===-1||i===-1?n:BR(n,r,i)});return}let i=n.id,o=r.id,s=je(i);if(!s)return;let l=dW(o,pe,je,gU,_U)??s;if(pe.has(l))if(s===l)if(l===`specs`){let e=Ee.map(e=>e.id),n=e.indexOf(i),r=e.indexOf(o);if(n!==-1&&r!==-1&&n!==r){let i=BR(e,n,r);de(()=>i),re!=="default"&&(ie(`default`),hB(t,`default`,ae))}}else fe(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:BR(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}de(e=>(e??Ee.map(e=>e.id)).filter(e=>e!==i)),c(i,{status:`done`})}else if(s===`done-specs`&&l===`specs`)c(i,{status:`todo`}),de(e=>uW(e??Ee.map(e=>e.id),i,o));else if(s===`specs`){if(a.find(e=>e.id===i)?.status===`on_review`&&(!H||!hW(i,V))){J.info(e(`toasts.onReviewCannotMoveToRail`));return}let t=L.find(e=>e.id===l);de(e=>(e??Ee.map(e=>e.id)).filter(e=>e!==i)),fe(e=>e.map(e=>e.id===l?{...e,ticketIds:uW(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}fe(e=>e.map(e=>e.id===s?{...e,ticketIds:e.ticketIds.filter(e=>e!==i)}:e)),de(e=>uW(e??Ee.map(e=>e.id),i,o)),t&&J.success(e(`toasts.removedFromRail`,{rail:t.label}))}else s===`done-specs`?(c(i,{status:`todo`}),fe(e=>e.map(e=>e.id===l?{...e,ticketIds:uW(e.ticketIds,i,o)}:e))):l===`done-specs`?(fe(e=>e.map(e=>e.id===s?{...e,ticketIds:e.ticketIds.filter(e=>e!==i)}:e)),c(i,{status:`done`})):fe(e=>e.map(e=>e.id===s?{...e,ticketIds:e.ticketIds.filter(e=>e!==i)}:e.id===l?{...e,ticketIds:uW(e.ticketIds,i,o)}:e))}function Pe(e,t){fe(n=>n.map(n=>n.id===e?{...n,mode:t}:n))}function Fe(e){let t=lU(e);return t===null?L.findIndex(t=>t.id===e):t}async function Ie(e,t){fe(n=>n.map(n=>n.id===e?{...n,profileName:t}:n));let n=Fe(e);if(n!==-1)try{await fetch(`${ot()}/rails/${n}/profile`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({profileName:t})})}catch{}}function Le(e,t){fe(n=>n.map(n=>n.id===e?{...n,freestyleModel:t}:n))}function Re(e,t){let n=Ux(t);fe(r=>r.map(r=>r.id===e?{...r,selectedLoopId:t,mode:n}:r))}function ze(e){let t=e?.aiEngine;return(bt(t)?void 0:t)??i[0]??`claude`}function Be(e,t){fe(n=>n.map(n=>{if(n.id!==e)return n;let r=ze(n),i=mt(r,t);return{...n,loopModel:t,reasoningEffort:n.reasoningEffort&&i.includes(n.reasoningEffort)?n.reasoningEffort:Ct(r,t)??null}}))}function Ve(e,t){fe(n=>n.map(n=>n.id===e?{...n,reasoningEffort:t}:n))}async function He(t,n){if(bt(n)){let r=L.find(e=>e.id===t);if(r&&(r.mode===`freestyle`||r.selectedLoopId===`factory:freestyle`)){J.error(e(`rail.rolesNoFreestyle`));return}fe(e=>e.map(e=>e.id===t?{...e,aiEngine:n,profileName:null}:e)),await Ue(t,n);return}fe(e=>e.map(e=>{if(e.id!==t)return e;let r=e.mode===`freestyle`||e.selectedLoopId===`factory:freestyle`,i=!gt(n)&&r,a=Ix(n),o=e=>!!(e&&(a.some(t=>t.value===e)||kt(n)&&WO(e))),s=o(e.loopModel)?e.loopModel:Lx(n),c=mt(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:Lx(n),loopModel:s,reasoningEffort:e.reasoningEffort&&c.includes(e.reasoningEffort)?e.reasoningEffort:Ct(n,s)??null}})),await Ue(t,n)}async function Ue(e,t){let n=Fe(e);if(n!==-1)try{await fetch(`${ot()}/rails/${n}/engine`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({aiEngine:t})})}catch{}}function We(e,t){fe(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(`${ot()}/rails/${r}/stop`,{method:`POST`}),fe(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){O({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`&&(!H||!hW(e,V))))return r||J.info(e(`toasts.onReviewNotLaunchable`)),`skipped`;let s=Wx(i.selectedLoopId,i.mode);if(!s)return r||J.error(e(`railControls.pickLoop`)),`failed`;let c=bt(i.aiEngine),l=ze(i),u=mt(l,i.loopModel??Lx(l)),d=i.reasoningEffort&&u.includes(i.reasoningEffort)?i.reasoningEffort:null,f=ot();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 fe(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(xe.eligible.length===0){J.info(e(`toasts.launchAllNoneEligible`));return}A(!0)}async function Je(){A(!1);let{eligible:t,skipped:n}=xe;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:be.get(j),Xe=(0,Q.useRef)(null),{leftWidth:Qe,enabled:$e,beginDrag:et,resetToDefault:tt}=QU(t,Xe),nt=typeof window<`u`?window.innerWidth:1200;return(0,$.jsx)(xz,{children:(0,$.jsxs)(yR,{sensors:ve,collisionDetection:ye,onDragStart:Me,onDragEnd:Ne,children:[(0,$.jsxs)(`div`,{ref:Xe,className:`relative z-0 flex h-full overflow-hidden`,children:[r&&(0,$.jsx)(bP,{}),(0,$.jsx)(`div`,{className:`relative z-10 min-w-0 flex flex-col overflow-hidden`,style:$e&&Qe!==null?{width:`${Qe}px`,flex:`0 0 auto`}:{flex:`1 1 0%`},children:(0,$.jsx)(qH,{tickets:Ee,allTickets:a,doneTickets:De,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:re,sortDir:ae,onSortChange:le,viewTier:se,onViewTierChange:ue,rails:L,onMoveToRail:ke,continuableReviewTicketIds:Oe})}),$e&&Qe!==null&&(0,$.jsx)($U,{leftWidth:Qe,viewport:nt,onPointerDown:et,onReset:tt}),(0,$.jsx)(`div`,{className:`relative z-10 flex-1 min-w-0 flex flex-col overflow-hidden`,children:(0,$.jsx)(bU,{rails:L,ticketMap:be,railWorktrees:R,railMetrics:B,railPrDecisions:V,onPrDecision:U,onPrCheckout:te,providers:i,onModeChange:Pe,onProfileChange:Ie,onEngineChange:He,onFreestyleModelChange:Le,onLoopModelChange:Be,loopAvailable:Ce,onLoopChange:Re,onEffortChange:Ve,onToggle:Ge,onTargetPrChange:We,onTicketClick:x,onAddRail:()=>{me()},onDeleteRail:e=>{he(e)},onRenameRail:W,onTicketMoveToSpecs:Ae,onLaunchAll:qe,launchAllCount:xe.eligible.length})})]}),(0,$.jsx)(zR,{dropAnimation:{duration:180,easing:`ease`},children:Ye?se===`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)(G,{ticket:e,allLabels:Se,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:ke,onRemoveFromRail:Ae},e.id)})(),(0,$.jsx)(eW,{open:S,allLabels:Se,onClose:()=>C(!1),onCreate:f}),(0,$.jsx)(rW,{open:k,railCount:xe.eligible.length,specCount:xe.eligible.reduce((e,t)=>e+t.ticketIds.length,0),onCancel:()=>A(!1),onConfirm:()=>{Je()}}),(()=>{let e=D?L.find(e=>e.id===D.railId):void 0;return(0,$.jsx)(iW,{open:!!D&&!!e?.targetPr,target:e?.targetPr??null,onCancel:()=>O(null),onConfirm:()=>{let e=D?.railId;O(null),e&&Ke(e)}})})(),(()=>{let e=w?L.find(e=>e.id===w.railId):void 0,t=ze(e);return(0,$.jsx)(tW,{open:!!w&&!!e,railLabel:e?.label??``,specCount:e?.ticketIds.length??0,provider:t,model:e?.freestyleModel??Lx(t),onCancel:()=>T(null),onConfirm:()=>{let e=w?.railId;T(null),e&&Ke(e)}})})()]})})}var xW=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}));xW.displayName=`Card`;var SW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:X(`flex flex-col space-y-1 p-4`,e),...t}));SW.displayName=`CardHeader`;var CW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`h3`,{ref:n,className:X(`text-sm font-semibold leading-none tracking-tight`,e),...t}));CW.displayName=`CardTitle`;var wW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`p`,{ref:n,className:X(`text-xs text-muted-foreground`,e),...t}));wW.displayName=`CardDescription`;var TW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:X(`p-4 pt-0`,e),...t}));TW.displayName=`CardContent`;var EW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:X(`flex items-center p-4 pt-0`,e),...t}));EW.displayName=`CardFooter`;var DW=[`auto`,`canvas`,`webgl`];function OW({mode:e}){let{t}=K(`settings`),{activeProjectId:n}=lt(),[r,i]=(0,Q.useState)(Di),[a,o]=(0,Q.useState)({}),[s,c]=(0,Q.useState)(Di),[l,u]=(0,Q.useState)(Di),[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),WP({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),WP({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)(xW,{children:(0,$.jsx)(TW,{children:t(`common:states.loading`)})}):(0,$.jsxs)(xW,{children:[(0,$.jsxs)(SW,{children:[(0,$.jsx)(CW,{children:t(`terminal.title`)}),(0,$.jsx)(wW,{children:t(e===`desktop`?`terminal.desktopDescription`:`terminal.projectDescription`)})]}),(0,$.jsxs)(TW,{className:`space-y-4`,children:[(0,$.jsx)(kW,{label:t(`terminal.fontFamily`),overridden:S(`fontFamily`),onClear:()=>y(`fontFamily`),mode:e,children:(0,$.jsx)(Ij,{value:l.fontFamily,onChange:e=>v(`fontFamily`,e.target.value)})}),(0,$.jsx)(kW,{label:t(`terminal.fontSize`,{min:8,max:32}),overridden:S(`fontSize`),onClear:()=>y(`fontSize`),mode:e,children:(0,$.jsx)(Ij,{type:`number`,min:8,max:32,value:l.fontSize,onChange:e=>v(`fontSize`,parseInt(e.target.value,10)||l.fontSize)})}),(0,$.jsx)(kW,{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:DW.map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))})}),(0,$.jsx)(AW,{label:t(`terminal.copyOnSelect`),checked:l.copyOnSelect,overridden:S(`copyOnSelect`),onClear:()=>y(`copyOnSelect`),onChange:e=>v(`copyOnSelect`,e),mode:e}),(0,$.jsx)(AW,{label:t(`terminal.shellIntegration`),checked:l.shellIntegrationEnabled,overridden:S(`shellIntegrationEnabled`),onClear:()=>y(`shellIntegrationEnabled`),onChange:e=>v(`shellIntegrationEnabled`,e),mode:e}),(0,$.jsx)(AW,{label:t(`terminal.notifyLongRunning`),checked:l.notifyOnCompletion,overridden:S(`notifyOnCompletion`),onClear:()=>y(`notifyOnCompletion`),onChange:e=>v(`notifyOnCompletion`,e),mode:e}),(0,$.jsx)(kW,{label:t(`terminal.longCommandThreshold`),overridden:S(`longCommandThresholdMs`),onClear:()=>y(`longCommandThresholdMs`),mode:e,children:(0,$.jsx)(Ij,{type:`number`,min:1e3,value:l.longCommandThresholdMs,onChange:e=>v(`longCommandThresholdMs`,parseInt(e.target.value,10)||l.longCommandThresholdMs)})}),(0,$.jsx)(AW,{label:t(`terminal.imageRendering`),checked:l.imageRendering,overridden:S(`imageRendering`),onClear:()=>y(`imageRendering`),onChange:e=>v(`imageRendering`,e),mode:e}),(0,$.jsx)(kW,{id:`terminal-browser-shortcut-url`,label:t(`terminal.browserShortcutUrl`),overridden:S(`browserShortcutUrl`),onClear:()=>y(`browserShortcutUrl`),mode:e,children:(0,$.jsx)(Ij,{type:`url`,value:l.browserShortcutUrl,placeholder:`https://specrails.dev`,onChange:e=>v(`browserShortcutUrl`,e.target.value)})}),(0,$.jsx)(kW,{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 kW({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 AW({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 jW(){let{activeProjectId:e,projects:t,refreshProjects:n}=lt(),r=t.find(t=>t.id===e);return r?(0,$.jsx)(MW,{project:r,refreshProjects:n},r.id):null}function MW({project:e,refreshProjects:t}){let{t:n}=K(`common`),[r,i]=(0,Q.useState)(()=>yr(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(yr(e))},[e]);let x=`${vr(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)(xW,{children:[(0,$.jsxs)(SW,{children:[(0,$.jsxs)(CW,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ys,{className:`h-4 w-4`}),n(`repositories.title`)]}),(0,$.jsx)(wW,{children:n(`repositories.sharedBacklog`)})]}),(0,$.jsxs)(TW,{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)(Ij,{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)(Ij,{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([85,0,1])),t=await e({directory:!0,multiple:!1});typeof t==`string`&&b.current&&d(t)}catch{}},children:(0,$.jsx)(bs,{className:`h-4 w-4`})})]})]}),(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`repositories.integrationBranch`),(0,$.jsx)(Ij,{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)(Dn,{className:`mr-1 h-4 w-4`}),n(`repositories.addFolder`)]})]})]})}var NW=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function PW({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:NW,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 FW({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)(PW,{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)(Ij,{value:t.escalation.model,onChange:e=>r({...t,escalation:{...t.escalation,model:e.target.value,effort:void 0}})})]}),(0,$.jsx)(PW,{value:t.escalation.effort,capability:a(`escalation`),onChange:e=>r({...t,escalation:{...t.escalation,effort:e}})})]})]})}function IW({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:NW,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)(Ij,{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 LW({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)(vc,{className:`h-3 w-3 opacity-70`,"aria-hidden":!0}):n.value?(0,$.jsx)(ss,{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 RW=[`verifier`,`decider`],zW=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function BW(e){let t=e?.roles;if(!t||typeof t!=`object`)return{};let n={};for(let e of RW){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 VW(e){let{t}=K(`agentRuntime`),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(!1),o=(0,Q.useRef)({}),s=`${vr(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=BW(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=BW(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 HW(e){return e&&(e.model||Lx(e.provider))||null}function UW({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:Ix(e).map(e=>e.value)},c=t?.provider,l=Et(c),u=c?Ix(c):[],d=c?Lx(c):``,f=t?.model&&!u.some(e=>e.value===t.model)?t.model:null,p=t?.model||d||null,m=c?mt(c,p):[],h=!!c&&St(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)(LW,{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:Dt(e),detail:e,local:Et(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)(Ij,{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 WW=[`architect`,`developer`,`verification`,`fixer`,`reviewer`,`verifier`,`decider`],GW={architect:`core`,developer:`core`,verification:`core`,fixer:`core`,reviewer:`core`,verifier:`loop`,decider:`loop`},KW=[`core`,`loop`],qW={core:WW.filter(e=>GW[e]===`core`),loop:WW.filter(e=>GW[e]===`loop`)};function JW(e){return qW[GW[e]].indexOf(e)+1}var YW={architect:ns,developer:Os,verification:xc,fixer:Mn,reviewer:ps,verifier:Xo,decider:Sn};function XW({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)(Oc,{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?vc:ss;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 ZW({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)(dc,{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 QW({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:KW.map((i,a)=>{let o=e.filter(e=>GW[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)(ZW,{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=YW[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)(XW,{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)(Go,{className:`h-3.5 w-3.5`})})]},e.id)})})]})]},i)})})}var $W=(0,Q.forwardRef)(function({phase:e,engine:t,open:n,active:r,onToggle:i,children:a},o){let{t:s}=K(`agentRuntime`),c=JW(e),l=YW[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)(XW,{engine:t}),(0,$.jsx)(Wo,{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})]})}),eG=[`claude`,`codex`,`gemini`,`kimi`],tG=[`architect`,`developer`,`reviewer`],nG=[...tG,`fixer`];function rG(e){return e.kind===`openai-compatible`&&e.label?.trim()?e.label.trim():e.id}function iG(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 aG=[`architect`,`developer`,`host`];function oG(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`&&aG.includes(e.phase))}function sG(e,t,n){let r={...e};return n?delete r[t]:r[t]=!1,Object.keys(r).length?r:void 0}var cG=[`type_correctness`,`pattern_adherence`,`test_coverage`,`security`,`architectural_alignment`],lG=[`ask`,`proceed`],uG={minScore:70,aspects:{type_correctness:60,pattern_adherence:60,test_coverage:60,security:75,architectural_alignment:60}},dG={maxTurns:100,maxAttempts:3,timeoutMs:15*6e4};function fG(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&&tG.every(e=>typeof n.agents[e]?.provider==`string`)}function pG(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 mG(e,t){let n=t,r=2;for(;e.some(({id:e})=>e===n);)n=`${t}-${r++}`;return n}function hG(e){return[e.command,...e.args].map(e=>/[\s"]/.test(e)?JSON.stringify(e):e).join(` `)}function gG(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 _G={architect:ns,developer:Os,host:Oc};function vG({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(`${vr(e)}/agent-runtime/guardrails`,{cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(`guardrails`);let n=await e.json();if(!oG(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)(xc,{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)(Wo,{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`)})}),aG.map(e=>{let i=l.filter(t=>t.phase===e);if(!i.length)return null;let a=_G[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(sG(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 yG=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function bG(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 xG(){let{activeProjectId:e,projects:t}=lt(),n=(0,Q.useRef)(new Map),r=t.find(t=>t.id===e);return e?(0,$.jsx)(TG,{projectId:e,cache:n.current,projectProviderIds:r?.providers?.length?r.providers:r?.provider?[r.provider]:[],repositories:yr(r).map(({id:e,name:t})=>({id:e,name:t}))},e):null}function SG(e){return e.map(e=>({original:e,label:e.label,repositoryId:e.repositoryId,line:hG(e)}))}function CG(e){return e.map(e=>({repositoryId:e.repositoryId,line:hG(e),reason:e.reason}))}function wG(e){return e===void 0?``:String(Math.round(e/6e4*100)/100)}function TG({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)(SG(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,ee]=(0,Q.useState)(()=>Object.fromEntries(WW.map(e=>[e,!0]))),R=(0,Q.useRef)({}),z=VW(e),B=(0,Q.useRef)(!1),V=(0,Q.useRef)(!0),H=`${vr(e)}/agent-runtime/config`,U=(0,Q.useRef)(0),te=(0,Q.useRef)(l);te.current=l;let ne=JSON.stringify([e,l?.providers,l&&tG.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 re(t){if(!te.current)return;let n=structuredClone(te.current);for(let e of[...Object.values(n.agents),...n.fixer?[n.fixer]:[]])e.escalation&&!e.escalation.model.trim()&&delete e.escalation;let r=++U.current;g(!0),v(!1);try{let i=await fetch(`${vr(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`);V.current&&!t?.aborted&&r===U.current&&m(a.roles)}catch{V.current&&!t?.aborted&&r===U.current&&(m([]),v(!0))}finally{V.current&&!t?.aborted&&r===U.current&&g(!1)}}(0,Q.useEffect)(()=>{if(U.current++,m([]),v(!1),!te.current||s?.efficiencyAvailable===!1){g(!1);return}let e=new AbortController;g(!0);let t=setTimeout(()=>{re(e.signal)},250);return()=>{clearTimeout(t),e.abort(),U.current++}},[ne,s?.efficiencyAvailable,N]);let ie=`${vr(e)}/agent-runtime/verification-suggestions`;async function ae(){try{let e=await fetch(ie,{cache:`no-store`});if(!e.ok)return null;let t=await e.json();return pG(t)?t.suggestions:null}catch{return null}}(0,Q.useEffect)(()=>{V.current=!0;let n=!1;return fetch(H,{cache:`no-store`}).then(async r=>{if(!r.ok)throw Error(i(`loadFailed`));let a=await r.json();if(!fG(a))throw Error(i(`loadFailed`));if(!n){if(t.set(e,a),c(a),!B.current&&(u(a.config),f(SG(a.config.verification)),!a.configured&&a.config.verification.length===0)){let e=await ae();if(n||B.current)return;e?.length?(f(CG(e)),w(`some`)):e&&w(`none`)}O(``)}}).catch(()=>{n||O(i(`loadFailed`))}).finally(()=>{n||E(!1)}),()=>{n=!0,V.current=!1}},[H,e,t,N,i]);function oe(e){B.current=!0,A(!1),M(!0),u(e)}function se(e){B.current=!0,A(!1),M(!0),f(e)}function ce(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 le(e){if(e.kind!==`openai-compatible`)return[];let t=a.providers[e.id]?.models,n=t&&t.length?t:Ix(e.id).map(e=>e.value);return e.defaultModel&&!n.includes(e.defaultModel)?[e.defaultModel,...n]:n}function ue(){let e=[];for(let t of d){if(!t.line.trim()&&!t.repositoryId)continue;let n=gG(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 de(){S(!0),O(``);try{let e=await ae();if(!V.current)return;if(!e){O(i(`verification.detectFailed`));return}let t=new Set(d.map(e=>`${e.repositoryId}\0${e.line}`)),n=CG(e).filter(e=>!t.has(`${e.repositoryId}\0${e.line}`));se([...d,...n]),w(e.length?`some`:`none`)}finally{V.current&&S(!1)}}async function fe(){if(!l||y)return;O(``),A(!1);let n=ue();if(n){b(!0);try{let r=await fetch(H,{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(!fG(a))throw Error(i(`saveFailed`));if(t.set(e,a),!V.current)return;B.current=!1,M(!1),c(a),u(a.config),f(SG(a.config.verification)),A(!0)}catch(e){V.current&&O(e instanceof Error?e.message:i(`saveFailed`))}finally{V.current&&b(!1)}}}let pe=l?.limits??{},me=(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),oe({...l,limits:Object.keys(r).length?r:void 0})},he=l?.review??{},W=(e,t)=>{if(!l)return;let n=t===``?void 0:Number(t),r={...he.aspects};e!==`minScore`&&(n===void 0?delete r[e]:r[e]=n);let i={},a=e===`minScore`?n:he.minScore;a!==void 0&&(i.minScore=a),Object.keys(r).length&&(i.aspects=r),oe({...l,review:Object.keys(i).length?i:void 0})},ge=e=>{l&&oe({...l,architect:e?{onLowConfidence:e}:void 0})},_e=r.length?r:(l?.providers??[]).map(e=>e.id),ve=!!l?.enabled&&s?.runtimeAvailable!==!1;function ye(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=z.roles?.[e];return t?{kind:`ai`,label:Dt(t.provider),model:HW(t),effort:t.effort??null,local:Et(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?ce(n).label:t.provider,i=n?.kind===`openai-compatible`;return{kind:`ai`,label:r,model:t.model??(n?.kind===`cli`?Lx(n.cli):n?.defaultModel)??null,effort:t.effort??null,local:i}}let be=WW.map(e=>({id:e,engine:ye(e)}));function xe(e){I(e),ee(t=>({...t,[e]:!0}));let t=R.current[e];t&&bG(t)}function Se(e){I(e),ee(t=>({...t,[e]:!t[e]}))}function G(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=>oe(e===`fixer`?{...l,fixer:t}:{...l,agents:{...l.agents,[e]:t}}),a=n?.kind===`cli`?Ix(n.cli):[],o=n?.kind===`cli`?Lx(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)(LW,{name:`runtime-${e}-provider`,value:t.provider,ariaLabel:i(`agents.provider`),tabs:l.providers.map(e=>ce(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:yG,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)(Ij,{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:le(n).map(e=>(0,$.jsx)(`option`,{value:e},e))})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`agents.maxTurns`,{turns:dG.maxTurns}),(0,$.jsx)(Ij,{type:`number`,min:`1`,step:`1`,placeholder:String(dG.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)(FW,{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,oe(e);return}let n=l.agents.developer;oe({...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)(Mn,{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&&G(`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 de(),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:yG,value:e.repositoryId,onChange:e=>se(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)(Ij,{value:e.repositoryId,onChange:e=>se(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)(Ij,{className:`font-mono`,spellCheck:!1,placeholder:`npm test`,value:e.line,onChange:e=>se(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)(Ij,{maxLength:256,value:e.label??``,onChange:e=>se(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]],se(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]],se(e)},children:`↓`}),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,onClick:()=>se(d.filter((e,n)=>n!==t)),children:i(`verification.remove`)})]})]},t)),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,onClick:()=>se([...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`)}),!ve&&(0,$.jsx)(`p`,{role:`status`,className:`rounded-md border border-accent-warning/40 p-3 text-xs text-accent-warning`,children:i(`loopRoles.disabled`)}),z.failed&&(0,$.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:i(`loadFailed`)}),z.roles===null&&!z.failed&&(0,$.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:i(`loading`)}),z.roles&&(0,$.jsx)(`fieldset`,{disabled:!ve,className:`disabled:opacity-60`,children:(0,$.jsx)(UW,{role:e,engine:z.roles[e],providers:_e,enabled:ve,onChange:t=>z.setRole(e,t)})})]})}return(0,$.jsxs)(xW,{id:`agent-runtime-settings`,children:[(0,$.jsxs)(SW,{children:[(0,$.jsx)(CW,{children:i(`title`)}),(0,$.jsx)(wW,{children:i(`description`)})]}),(0,$.jsxs)(TW,{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:dG.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)(Is,{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)(QW,{steps:be,active:F,onSelect:xe}),(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 re(),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:[KW.map(e=>(0,$.jsxs)(`div`,{className:`space-y-3`,"data-testid":`phase-cards-${e}`,children:[(0,$.jsx)(ZW,{group:e,className:e===`loop`?`border-t border-border/60 pt-3`:``}),qW[e].map(e=>(0,$.jsx)($W,{ref:t=>{R.current[e]=t},phase:e,engine:ye(e),open:L[e],active:F===e,onToggle:()=>Se(e),children:e===`verification`?we():e===`fixer`?Ce():e===`verifier`||e===`decider`?Te(e):G(e)},e))]},e)),(0,$.jsx)(vG,{projectId:e,guardrails:l.guardrails,onChange:e=>{let t={...l,guardrails:e};e||delete t.guardrails,oe(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)(IW,{config:l,onChange:oe})}),(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:dG.maxAttempts,minutes:dG.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:dG.maxAttempts}),(0,$.jsx)(Ij,{type:`number`,min:`1`,step:`1`,placeholder:String(dG.maxAttempts),value:pe.maxAttempts??``,onChange:e=>me(`maxAttempts`,e.target.value)})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`limits.timeoutMinutes`,{minutes:dG.timeoutMs/6e4}),(0,$.jsx)(Ij,{type:`number`,min:`1`,step:`1`,placeholder:String(dG.timeoutMs/6e4),value:wG(pe.timeoutMs),onChange:e=>me(`timeoutMs`,e.target.value,6e4)})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`limits.maxTokens`),(0,$.jsx)(Ij,{type:`number`,min:`1`,step:`1`,placeholder:i(`limits.unlimited`),value:pe.maxTokens??``,onChange:e=>me(`maxTokens`,e.target.value)})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`limits.maxCostUsd`),(0,$.jsx)(Ij,{type:`number`,min:`0.000001`,step:`any`,placeholder:i(`limits.unlimited`),value:pe.maxCostUsd??``,onChange:e=>me(`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=>oe({...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:uG.minScore,security:uG.aspects.security,aspect:uG.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:uG.minScore}),(0,$.jsx)(Ij,{type:`number`,min:uG.minScore,max:`100`,step:`1`,placeholder:String(uG.minScore),value:he.minScore??``,onChange:e=>W(`minScore`,e.target.value)})]}),cG.map(e=>(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`review.aspects.${e}`,{score:uG.aspects[e]}),(0,$.jsx)(Ij,{type:`number`,min:uG.aspects[e],max:`100`,step:`1`,placeholder:String(uG.aspects[e]),value:he.aspects?.[e]??``,onChange:t=>W(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:yG,value:l.architect?.onLowConfidence??``,onChange:e=>ge(e.target.value),children:[(0,$.jsx)(`option`,{value:``,children:i(`agents.defaultModel`,{model:i(`architect.ask`)})}),lG.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 fe(),children:i(y?`saving`:`save`)})]})})]})]})]})}function EG(){return(0,$.jsx)(`div`,{className:`h-32 animate-pulse rounded-lg bg-muted/30`,"data-testid":`section-skeleton`})}function DG(){let{t:e}=K(`settings`),{activeProjectId:t}=lt(),[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(`${ot()}/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)(EG,{});async function c(t){a(!0);let i=n;r(t);try{if(!(await fetch(`${ot()}/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)(xW,{children:[(0,$.jsxs)(SW,{children:[(0,$.jsx)(CW,{children:e(`telemetry.title`)}),(0,$.jsx)(wW,{children:e(`telemetry.description`)})]}),(0,$.jsx)(TW,{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)(at,{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 OG(){let{t:e}=K(`settings`),{activeProjectId:t}=lt(),[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(`${ot()}/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)(EG,{});async function d(){s(!0);try{let t=await fetch(`${ot()}/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)(xW,{children:[(0,$.jsxs)(SW,{children:[(0,$.jsx)(CW,{children:e(`integrationBranch.title`)}),(0,$.jsx)(wW,{children:e(`integrationBranch.description`)})]}),(0,$.jsxs)(TW,{className:`space-y-3`,children:[(0,$.jsx)(Ij,{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)(at,{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 kG=/^[A-Za-z_][A-Za-z0-9_]*$/,AG=[`NODE_AUTH_TOKEN`,`NPM_TOKEN`,`AWS_PROFILE`];function jG(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}function MG(){let{t:e}=K(`settings`),{activeProjectId:t}=lt(),[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(`${ot()}/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)(EG,{});function f(t){let i=jG(t);if(i.length===0)return;let o=[...n];for(let t of i){if(t.includes(`=`)){s(e(`worktreeEnv.noValues`));return}if(!kG.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(`${ot()}/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)(xW,{children:[(0,$.jsxs)(SW,{children:[(0,$.jsx)(CW,{children:e(`worktreeEnv.title`)}),(0,$.jsx)(wW,{children:e(`worktreeEnv.description`)})]}),(0,$.jsxs)(TW,{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)(Ij,{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)(Dn,{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:AG.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)(Nn,{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 NG({value:e,onChange:t,onSave:n,isSaving:r,fieldId:i,i18nRoot:a}){let{t:o}=K(`settings`);return(0,$.jsxs)(xW,{children:[(0,$.jsxs)(SW,{children:[(0,$.jsx)(CW,{children:o(`${a}.title`)}),(0,$.jsx)(wW,{children:o(`${a}.description`)})]}),(0,$.jsxs)(TW,{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 PG(){let{t:e}=K(`settings`),{activeProjectId:t}=lt(),[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(`${ot()}/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(`${ot()}/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(`${ot()}/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)(NG,{value:n,onChange:e=>{f.current.pre=!0,r(e)},onSave:p,isSaving:i,fieldId:`project-pre-prompt`,i18nRoot:`prePrompt`}),(0,$.jsx)(NG,{value:o,onChange:e=>{f.current.freestyle=!0,s(e)},onSave:m,isSaving:c,fieldId:`project-freestyle-pre-prompt`,i18nRoot:`freestylePrePrompt`})]}):(0,$.jsx)(EG,{})}function FG(){let{t:e}=K(`settings`),{activeProjectId:t}=lt(),[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(`${ot()}/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(`${ot()}/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)(xW,{children:[(0,$.jsxs)(SW,{children:[(0,$.jsx)(CW,{children:e(`budget.title`)}),(0,$.jsx)(wW,{children:e(`budget.description`)})]}),(0,$.jsx)(TW,{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)(Ij,{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)(Ij,{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)(EG,{})}function IG(){let{t:e}=K(`settings`),{activeProjectId:t}=lt(),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(`${ot()}/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)(DG,{}),(0,$.jsx)(PG,{}),(0,$.jsx)(jW,{}),(0,$.jsx)(xG,{}),(0,$.jsx)(OG,{}),(0,$.jsx)(MG,{}),(0,$.jsx)(FG,{}),(0,$.jsx)(OW,{mode:`project`})]})}function LG(){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||!tG.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`?nG:tG,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 RG(){let{t:e}=K(`settings`),t=AA();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:()=>OA({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)(kn,{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)(xA,{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=ga();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:Ui.map(t=>{let r=ia[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)(vn,{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 BG(){let{t:e}=K(`settings`);return ga()?(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 VG(e={}){let t={...e},n=Ge();return n&&(t[`X-Desktop-Token`]=n),t}var HG=(0,Q.createContext)(null);function UG(e){if(!(typeof localStorage>`u`))try{localStorage.setItem(He,e)}catch{}}function WG(){if(!(typeof localStorage>`u`))try{localStorage.removeItem(He)}catch{}}function GG({children:e,endpoint:t=`/api/language`}){let[n,r]=(0,Q.useState)(()=>Xe()),[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:VG()});if(!n.ok)return;let i=await n.json();if(e)return;Re(i.language)&&i.language!==Xe()&&(await tt(i.language),UG(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`&&Re(localStorage.getItem(`specrails-desktop:ui-language`));await tt(e),UG(e),r(e),a(!0);try{let n=await fetch(t,{method:`PATCH`,headers:VG({"Content-Type":`application/json`}),body:JSON.stringify({language:e})});if(!n.ok)throw Error(`server rejected language: ${n.status}`)}catch(e){throw await tt(i),o?UG(i):WG(),r(i),e}finally{a(!1)}},[n,t]),c=(0,Q.useMemo)(()=>({languageId:n,language:et[n],setLanguage:s,isUpdating:i}),[n,s,i]);return(0,$.jsx)(HG.Provider,{value:c,children:e})}function KG(){return(0,Q.useContext)(HG)}function qG(){let{t:e}=K(`settings`),t=KG();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:Ve.map(e=>{let t=et[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)(vn,{className:`w-3.5 h-3.5 text-accent-primary shrink-0`,"aria-hidden":`true`})]},e)})})}function JG(){let{t:e}=K(`settings`);return KG()?(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)(qG,{})]}):null}function YG(){if(!se)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 XG=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function ZG({provider:e,onChange:t,onRemove:n}){let{t:r}=K(`agentRuntime`),i=e.kind===`openai-compatible`,a=i?vc:wc;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}),rG(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)(Ij,{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:XG,value:e.cli,onChange:n=>t({...e,cli:n.target.value}),children:eG.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)(Ij,{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)(Ij,{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 QG(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 $G={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 eK({state:e,latencyMs:t,className:n}){let{t:r}=K(`agentRuntime`),i=$G[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 tK({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)(fs,{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 nK({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)(wc,{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)(eK,{state:QG(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)(tK,{label:r(`providers.overflow`),items:[{id:`remove`,label:r(`providers.remove`),icon:(0,$.jsx)(An,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),destructive:!0,onSelect:n}]})]})]})}function rK(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.reachable==`boolean`&&typeof t.authState==`string`}function iK({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||!rK(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)(Cn,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(ic,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),o(s?`providers.testing`:`providers.test`)]})}function aK(e){return(e.agentLoop??`compact`)===`compact`&&e.supportsReasoningEffort===!0&&(e.contextWindowTokens??0)>=32768}var oK=`__custom__`,sK=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`,cK=`space-y-1 text-xs text-muted-foreground`;function lK(e){return e===void 0?``:String(e)}function uK(e){if(e.trim()===``)return null;let t=Number(e);return Number.isFinite(t)&&t>=0?t:NaN}function dK({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:lK(e.rates?.inputPer1M),output:lK(e.rates?.outputPer1M)}),[_,v]=(0,Q.useState)(!1),y=t?.models??[],b=!e.defaultModel||y.includes(e.defaultModel),x=_||!b,S=uK(h.input),C=uK(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=uK(i.input),o=uK(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&&Fx(e.id,t.models)}let D=QG(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)(eK,{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)(iK,{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:cK,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)(wn,{className:`h-3 w-3`,"aria-hidden":!0}),s(`providers.rename`)]})]}),(0,$.jsx)(Ij,{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:cK,htmlFor:`${c}-label`,children:[s(`providers.label`),(0,$.jsx)(Ij,{id:`${c}-label`,value:e.label??``,placeholder:s(`providers.labelPlaceholder`),onChange:t=>r({...e,label:t.target.value||void 0})})]}),(0,$.jsxs)(`label`,{className:cK,htmlFor:`${c}-url`,children:[s(`providers.baseUrl`),(0,$.jsx)(Ij,{id:`${c}-url`,type:`url`,value:e.baseUrl,onChange:t=>r({...e,baseUrl:t.target.value})})]}),(0,$.jsxs)(`label`,{className:cK,htmlFor:`${c}-env`,children:[s(`providers.apiKeyEnv`),(0,$.jsx)(Ij,{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)(jn,{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:cK,htmlFor:`${c}-default`,children:[s(`providers.defaultModel`),(0,$.jsxs)(`select`,{id:`${c}-default`,className:sK,value:x?oK:e.defaultModel??``,onChange:t=>{if(t.target.value===oK){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:oK,children:s(`providers.customModel`)})]})]}),x&&(0,$.jsxs)(`label`,{className:cK,htmlFor:`${c}-custom`,children:[s(`providers.customModel`),(0,$.jsx)(Ij,{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:cK,htmlFor:`${c}-in`,children:[s(`providers.inputRate`),(0,$.jsx)(Ij,{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:cK,htmlFor:`${c}-out`,children:[s(`providers.outputRate`),(0,$.jsx)(Ij,{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:aK(e),title:s(`providers.presetSmallModelHint`),onClick:()=>r({...e,agentLoop:void 0,supportsReasoningEffort:!0,contextWindowTokens:e.contextWindowTokens??32768}),children:[(0,$.jsx)(kn,{className:`mr-1 h-3.5 w-3.5`,"aria-hidden":!0}),aK(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:cK,htmlFor:`${c}-ctx`,children:[s(`providers.contextWindow`),(0,$.jsx)(Ij,{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:cK,htmlFor:`${c}-out`,children:[s(`providers.maxOutput`),(0,$.jsx)(Ij,{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 fK(e){let t=e??32768;return t>=1024&&t%1024==0?`${t/1024}k`:t.toLocaleString()}function pK({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=rG(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)(vc,{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)(eK,{state:QG(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:[fK(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)(Wo,{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)(dK,{provider:e,status:t,persisted:n,onChange:i,onStatus:a,onValidity:o,onRemove:s})})]})}var mK=1;function hK(e,t){return e.map(e=>({key:mK++,provider:e,persisted:t}))}function gK({children:e}){let{t}=K(`agentRuntime`),n=!Oe(),[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||!iG(r))throw Error(r?.message??t(`loadFailed`));e||(i(hK(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:mG(r.map(e=>e.provider),`local`),kind:`openai-compatible`,baseUrl:`http://127.0.0.1:11434/v1`};i([...r,{key:mK++,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:mG(t,`cli`),kind:`cli`,cli:e??`claude`};i([...r,{key:mK++,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||!iG(n))throw Error(n?.message??t(`saveFailed`));if(!_.current)return;i(hK(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=eG.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)(Dn,{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)(ss,{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)(ZG,{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)(Dn,{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)(Dn,{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)(_K,{icon:(0,$.jsx)(wc,{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)(tK,{label:t(`providers.addCli`),align:`right`,trigger:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Dn,{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)(wc,{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)(nK,{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)(_K,{icon:(0,$.jsx)(vc,{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)(vc,{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)(pK,{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)(sn,{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)(Sc,{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)(Wo,{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 _K({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 vK(){let{t:e}=K(`settings`),{registerHandler:t,unregisterHandler:n}=Ze(),[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)(Cn,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(bn,{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)(Cn,{className:`h-3.5 w-3.5 animate-spin`}):s===`done`?(0,$.jsx)(qo,{className:`h-3.5 w-3.5 text-accent-success`}):(0,$.jsx)(uc,{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 yK=class extends dt{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){xK(t);let n=new pt;e&&(n.onmessage=e);let r=await Y(`plugin:updater|download`,{onEvent:n,rid:this.rid,...t});this.downloadedBytes=new dt(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){xK(t);let n=new pt;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 bK(e){xK(e);let t=await Y(`plugin:updater|check`,{...e});return t?new yK(t):null}function xK(e){e?.headers&&(e.headers=Array.from(new Headers(e.headers).entries()))}var SK;(function(e){e.Nsis=`nsis`,e.Msi=`msi`,e.Deb=`deb`,e.Rpm=`rpm`,e.AppImage=`appimage`,e.App=`app`})(SK||={});async function CK(){return Y(`plugin:app|version`)}async function wK(){await Y(`plugin:process|restart`)}var TK=`specrails-desktop:dismissedDesktopUpdateVersion`,EK=`specrails-desktop-desktop-update`,DK=360*60*1e3;function OK(){return typeof window<`u`&&`__TAURI_INTERNALS__`in window}function kK(){return{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1}.VITE_MOCK_DESKTOP_UPDATE===`true`}function AK(){return{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1}.VITE_MOCK_DESKTOP_UPDATE_VERSION||`99.0.0-test`}function jK(e){return new Promise(t=>setTimeout(t,e))}function MK(){return{currentVersion:`1.40.1`,version:AK(),isMock:!0,async downloadAndInstall(e){e({event:`Started`,data:{contentLength:18874368}});for(let t=0;t<12;t+=1)await jK(180),e({event:`Progress`,data:{chunkLength:1572864}});e({event:`Finished`})}}}function NK(e){return e<1024*1024?We.t(`commands:update.units.kb`,{value:Math.max(1,Math.round(e/1024))}):We.t(`commands:update.units.mb`,{value:(e/(1024*1024)).toFixed(1)})}function PK(){try{return localStorage.getItem(TK)}catch{return null}}function FK(e){try{localStorage.setItem(TK,e)}catch{}J.dismiss(EK)}function IK(e){switch(e){case`downloading`:return`var(--color-accent-info)`;case`ready`:return`var(--color-accent-success)`;default:return`var(--color-accent-primary)`}}function LK({state:e}){let t=`h-[15px] w-[15px]`;return e===`installing`?(0,$.jsx)(es,{className:`${t} u-spin`,"aria-hidden":!0}):e===`ready`?(0,$.jsx)(vn,{className:`${t} u-check`,"aria-hidden":!0}):e===`error`?(0,$.jsx)(jn,{className:t,"aria-hidden":!0}):(0,$.jsx)(Qo,{className:t,"aria-hidden":!0})}function RK({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(EK),t?.();return}Y(`restart_app`).catch(()=>{wK()})}let p=s&&s>0?Math.min(100,Math.round(a/s*100)):null,m=IK(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:NK(a)}):n(`update.desc.progress`,{percent:p,downloaded:NK(a),total:NK(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)(LK,{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)(RK,{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(EK),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:()=>{FK(e.version),t?.()},children:n(`update.actions.dismiss`)})]})})]})}function BK(e){J.custom(()=>(0,$.jsx)(zK,{update:e}),{id:EK,duration:1/0,dismissible:!1,unstyled:!0,closeButton:!1})}function VK(){(0,Q.useEffect)(()=>{let e=kK();if(!e&&!OK())return;let t=!1,n={current:!1};async function r(){if(!(t||n.current))try{let r=e?MK():await bK();if(t||!r||PK()===r.version)return;n.current=!0,J.custom(()=>(0,$.jsx)(zK,{update:r,onClose:()=>{n.current=!1}}),{id:EK,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(),DK);return()=>{t=!0,clearInterval(i)}},[])}function HK(){let{t:e}=K(`settings`),t=kK(),n=OK()||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(!OK())return;let e=!0;return CK().then(t=>{e&&i(t)}).catch(()=>{}),()=>{e=!1}},[]);let d=(0,Q.useCallback)(async()=>{o(!0),c(null);try{let n=t?MK():await bK();n?(c(`update-available`),u(n.version),BK(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)(Cn,{className:`h-3.5 w-3.5 animate-spin`}):s===`up-to-date`?(0,$.jsx)(qo,{className:`h-3.5 w-3.5 text-accent-success`}):(0,$.jsx)(uc,{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 UK=Object.defineProperty,WK=Object.getOwnPropertySymbols,GK=Object.prototype.hasOwnProperty,KK=Object.prototype.propertyIsEnumerable,qK=(e,t,n)=>t in e?UK(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,JK=(e,t)=>{for(var n in t||={})GK.call(t,n)&&qK(e,n,t[n]);if(WK)for(var n of WK(t))KK.call(t,n)&&qK(e,n,t[n]);return e},YK=(e,t)=>{var n={};for(var r in e)GK.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&WK)for(var r of WK(e))t.indexOf(r)<0&&KK.call(e,r)&&(n[r]=e[r]);return n},XK;(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})(XK||={}),(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||={})})(XK||={}),(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||={})})(XK||={});var ZK=XK,QK={L:ZK.QrCode.Ecc.LOW,M:ZK.QrCode.Ecc.MEDIUM,Q:ZK.QrCode.Ecc.QUARTILE,H:ZK.QrCode.Ecc.HIGH},$K=128,eq=`L`,tq=`#FFFFFF`,nq=`#000000`,rq=!1,iq=1,aq=4,oq=0,sq=.1;function cq(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 lq(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 uq(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*sq),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 dq(e,t){return t==null?e?aq:oq:Math.max(Math.floor(t),0)}function fq({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(...ZK.QrSegment.makeSegments(t)),e),[]);return ZK.QrCode.encodeSegments(r,QK[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=dq(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:uq(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var pq=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),mq=Q.forwardRef(function(e,t){let n=e,{value:r,size:i=$K,level:a=eq,bgColor:o=tq,fgColor:s=nq,includeMargin:c=rq,minVersion:l=iq,boostLevel:u,marginSize:d,imageSettings:f}=n,p=YK(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=YK(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}=fq({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=lq(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,pq?t.fill(new Path2D(cq(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=JK({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`,JK({style:E,height:i,width:i,ref:y,role:`img`},h)),D)});mq.displayName=`QRCodeCanvas`;var hq=Q.forwardRef(function(e,t){let n=e,{value:r,size:i=$K,level:a=eq,bgColor:o=tq,fgColor:s=nq,includeMargin:c=rq,minVersion:l=iq,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=YK(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=fq({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=lq(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=cq(y,h);return Q.createElement(`svg`,JK({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)});hq.displayName=`QRCodeSVG`;var gq=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 _q(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function vq(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 yq(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 bq(e){let t=new TextEncoder().encode(e),n=await yq(t,new CompressionStream(`deflate-raw`));return n.length<t.length?`D`+_q(n):`R`+_q(t)}async function xq(e){let t=e.trim();if(!t)throw Error(`empty signal token`);let n=vq(t.slice(1));if(t[0]===`D`)return new TextDecoder().decode(await yq(n,new DecompressionStream(`deflate-raw`)));if(t[0]===`R`)return new TextDecoder().decode(n);throw Error(`unknown signal codec tag: ${t[0]}`)}async function Sq(e){return bq(JSON.stringify({k:`offer`,v:2,hub:e.hubInstanceId,name:e.hubName,sdp:e.sdp,sec:e.secret}))}async function Cq(e){try{let t=JSON.parse(await xq(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 wq({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 Cq(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 Sq({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,gq.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)(sr,{open:e,onOpenChange:e=>{e||m()},children:(0,$.jsxs)(ar,{movableResizable:!0,className:`max-w-md`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:r(`pairWeb.title`)}),(0,$.jsx)(Zn,{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)(hq,{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 Tq=typeof navigator<`u`&&/Win/i.test(navigator.platform);function Eq(e){return!e||e.length<16?e??`—`:`${e.slice(0,8)}…${e.slice(-8)}`}function Dq(){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}=Ze();(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)(Cc,{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)(xc,{className:`h-3.5 w-3.5 text-accent-success`}),(0,$.jsx)(`span`,{title:t.certFingerprint??``,children:Eq(t.certFingerprint)}),(0,$.jsx)(`button`,{type:`button`,className:`underline`,onClick:h,disabled:a,children:e(`mobile.reset`)})]})]}),Tq&&(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)(An,{className:`h-4 w-4`})})]},t.id))]})]}),(0,$.jsx)(wq,{open:s,onClose:()=>c(!1),onPaired:u})]}):(0,$.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`})}var Oq=[`claude`,`codex`,`gemini`,`kimi`],kq=[`claude`,`gemini`,`kimi`],Aq=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;function jq(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 Mq(){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(`${Ke}/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(`${Ke}/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 kq)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!==``&&(!Aq.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)(Dn,{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)(jn,{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)(Dn,{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)(An,{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:Oq.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:jq(t),"data-testid":`external-mcp-form-provider-${e}`,children:[t&&(0,$.jsx)(vn,{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)(jn,{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:Oq.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:jq(n),children:[n&&(0,$.jsx)(vn,{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)(wn,{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)(An,{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 Nq(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 Pq(e){return JSON.stringify({mcpServers:{specrails:{command:e.bridgeCommand}}},null,2)}function Fq(){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(`${Ke}/api/mcp-admin/status`);e.ok&&n(await e.json())}catch{}},[]),u=(0,Q.useCallback)(async()=>{try{let e=await fetch(`${Ke}/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(`${Ke}/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(`${Ke}/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 Nq(Pq(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(`${Ke}/api/mcp-admin/token`);if(!t.ok)throw Error(`HTTP ${t.status}`);let{token:n}=await t.json();await Nq(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(`${Ke}/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)(ac,{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)(vn,{className:`h-3 w-3 text-accent-success`}),` `,e(`config.configCopied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(is,{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:Pq(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)(vn,{className:`h-3 w-3 text-accent-success`}),` `,e(`token.tokenCopied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(is,{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)(uc,{className:`h-3 w-3`}),` `,e(`token.regenerate`)]})]})]})]})]}),(0,$.jsx)(Mq,{})]})}var Iq=`specrails-os-notifications`,Lq={enabled:!0,filter:`all`};function Rq(){try{let e=localStorage.getItem(Iq);if(!e)return Lq;let t=JSON.parse(e);return{enabled:typeof t.enabled==`boolean`?t.enabled:Lq.enabled,filter:t.filter===`completed`||t.filter===`failed`?t.filter:Lq.filter}}catch{return Lq}}function zq(e){localStorage.setItem(Iq,JSON.stringify(e))}function Bq({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}=bN(),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),qD({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}=Ze(),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=Rq();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?We.t(`commands:notifications.providerLimitBody`,{provider:s,resetsAt:r}):We.t(`commands:notifications.providerLimitBodyNoReset`,{provider:s}),u=We.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=Rq();if(!i.enabled||i.filter===`completed`)return;let a=Math.max(1,Math.round(n/6e4)),o=t?c.current?.get(t)??``:``,l=We.t(`commands:notifications.jobStuckBody`,{count:a});if(t&&r.includes(`stop`)&&J.warning(We.t(`commands:notifications.jobStuck`),{id:`job-stuck:${e}`,description:o?`[${o}] ${l}`:l,duration:2e4,action:{label:We.t(`commands:notifications.jobStuckStop`),onClick:()=>{g(t,e)}}}),typeof Notification>`u`)return;function u(){let n=new Notification(We.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(We.t(`commands:notifications.jobStuckStopped`),{id:`job-stuck:${t}`})}catch{J.error(We.t(`commands:notifications.jobStuckStopFailed`),{id:`job-stuck:${t}`})}}function _(e,t){if(typeof Notification>`u`||typeof document<`u`&&!document.hidden)return;let n=Rq();if(!n.enabled||n.filter===`completed`&&e.status!==`completed`||n.filter===`failed`&&e.status!==`failed`)return;function r(){let n=e.status===`completed`?We.t(`commands:notifications.jobCompleted`):We.t(`commands:notifications.jobFailed`),r=t?c.current?.get(t)??``:``,i=e.command?e.command.slice(0,80):We.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 Vq=[{value:`job.completed`,labelKey:`webhooks.eventJobCompleted`},{value:`job.failed`,labelKey:`webhooks.eventJobFailed`},{value:`daily_budget_exceeded`,labelKey:`webhooks.eventDailyBudgetExceeded`}];function Hq({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 Uq=[{id:`appearance`,icon:Xs,labelKey:`desktop.nav.appearance`},{id:`effects`,icon:kn,labelKey:`desktop.nav.effects`},{id:`specrailsAgents`,icon:ss,labelKey:`desktop.nav.specrailsAgents`},{id:`code`,icon:$o,labelKey:`desktop.nav.code`},{id:`terminal`,icon:wc,labelKey:`desktop.nav.terminal`},{id:`updates`,icon:uc,labelKey:`desktop.nav.updates`},{id:`mobile`,icon:Cc,labelKey:`desktop.nav.mobile`},{id:`mcp`,icon:Fo,labelKey:`desktop.nav.mcp`},{id:`projects`,icon:bs,labelKey:`desktop.nav.projects`},{id:`advanced`,icon:Sc,labelKey:`desktop.nav.advanced`},{id:`webhooks`,icon:Pc,labelKey:`desktop.nav.webhooks`},{id:`about`,icon:Ns,labelKey:`desktop.nav.about`}];function Wq({open:e,onClose:t,onOpenOnboarding:n}){let{t:r}=K(`settings`),{projects:i,removeProject:a}=lt(),[o,s]=(0,Q.useState)(`appearance`),c=e=>X(`space-y-5`,o===e?``:`hidden`),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(!0),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)([]),[C,w]=(0,Q.useState)(``),[T,E]=(0,Q.useState)(``),[D,O]=(0,Q.useState)([`job.completed`,`job.failed`]),[k,A]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(()=>Rq().enabled),[N,P]=(0,Q.useState)(()=>Rq().filter);function F(e){M(e),zq({enabled:e,filter:N}),J.success(r(e?`notifications.enabledToast`:`notifications.disabledToast`))}function I(e){P(e),zq({enabled:j,filter:e})}let L=(0,Q.useCallback)(async()=>{try{let e=await fetch(`/api/webhooks`);if(e.ok){let t=await e.json();S(t.webhooks)}}catch{}},[]);(0,Q.useEffect)(()=>{if(!e)return;f(!0);async function t(){try{let e=await fetch(`/api/settings`);if(e.ok){let t=await e.json();u(t),m(t.costAlertThresholdUsd==null?``:String(t.costAlertThresholdUsd))}}catch{}finally{f(!1)}}t(),L()},[e,L]),(0,Q.useEffect)(()=>{e&&fetch(`/api/budget`).then(e=>e.json()).then(e=>{e.desktopDailyBudgetUsd==null?v(``):v(String(e.desktopDailyBudgetUsd))}).catch(()=>{})},[e]);async function ee(){g(!0);try{let e=p.trim()===``?null:parseFloat(p);if(e!==null&&(isNaN(e)||e<=0)){J.error(r(`budget.invalidNumber`));return}(await fetch(`/api/settings`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({costAlertThresholdUsd:e})})).ok?J.success(e==null?r(`desktop.costAlertsDisabled`):r(`budget.alertSet`,{amount:e})):J.error(r(`budget.saveThresholdFailed`))}catch{J.error(r(`budget.saveThresholdFailed`))}finally{g(!1)}}async function R(){b(!0);try{let e=_.trim()===``?null:parseFloat(_);if(e!==null&&(isNaN(e)||e<=0)){J.error(r(`budget.invalidNumber`));return}(await fetch(`/api/budget`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({desktopDailyBudgetUsd:e})})).ok?J.success(e==null?r(`desktop.dailyBudgetRemoved`):r(`desktop.dailyBudgetSet`,{amount:e})):J.error(r(`desktop.dailyBudgetSaveFailed`))}catch{J.error(r(`desktop.dailyBudgetSaveFailed`))}finally{b(!1)}}async function z(e){try{await a(e),J.success(r(`desktop.projectRemoved`))}catch(e){J.error(r(`desktop.projectRemoveFailed`),{description:e.message})}}async function B(){if(!C.trim()){J.error(r(`webhooks.urlRequired`));return}if(D.length===0){J.error(r(`webhooks.selectEvent`));return}A(!0);try{let e=await fetch(`/api/webhooks`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({url:C.trim(),secret:T.trim(),events:D})});if(e.ok)J.success(r(`webhooks.added`)),w(``),E(``),O([`job.completed`,`job.failed`]),await L();else{let t=await e.json();J.error(t.error??r(`webhooks.addFailed`))}}catch{J.error(r(`webhooks.addFailed`))}finally{A(!1)}}async function V(e,t){try{await fetch(`/api/webhooks/${e}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:t})}),await L()}catch{J.error(r(`webhooks.updateFailed`))}}async function H(e){try{(await fetch(`/api/webhooks/${e}`,{method:`DELETE`})).ok&&(J.success(r(`webhooks.removed`)),await L())}catch{J.error(r(`webhooks.removeFailed`))}}async function U(e){try{(await fetch(`/api/webhooks/${e}/test`,{method:`POST`})).ok&&J.success(r(`webhooks.testPingSent`))}catch{J.error(r(`webhooks.testPingFailed`))}}function te(e){O(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}return(0,$.jsx)(sr,{open:e,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(ar,{movableResizable:!0,className:`flex max-w-5xl w-[92vw] h-[82vh] flex-col overflow-hidden`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsxs)(er,{className:`flex items-center gap-2`,children:[(0,$.jsx)(yc,{className:`w-4 h-4`}),r(`desktop.title`)]}),(0,$.jsx)(Zn,{children:r(`desktop.description`)})]}),d?(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:Uq.map(e=>{if(e.id===`mcp`&&!fe)return null;let t=e.icon;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>s(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`,o===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:r(e.labelKey)})]},e.id)})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-y-auto pr-1`,children:[(0,$.jsxs)(`div`,{className:c(`appearance`),children:[(0,$.jsx)(BG,{}),(0,$.jsx)(JG,{})]}),(0,$.jsx)(`div`,{className:c(`effects`),children:(0,$.jsx)(RG,{})}),(0,$.jsx)(`div`,{className:c(`specrailsAgents`),children:(0,$.jsx)(gK,{children:(0,$.jsx)(LG,{})})}),(0,$.jsx)(`div`,{className:c(`code`),children:(0,$.jsx)(YG,{})}),(0,$.jsxs)(`div`,{className:c(`updates`),children:[(0,$.jsx)(HK,{}),(0,$.jsx)(vK,{})]}),(0,$.jsx)(`div`,{className:c(`mobile`),children:(0,$.jsx)(Dq,{})}),fe&&(0,$.jsx)(`div`,{className:c(`mcp`),children:(0,$.jsx)(Fq,{})}),(0,$.jsx)(`div`,{className:c(`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:r(`desktop.registeredProjects`)}),i.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:r(`desktop.noProjects`)})}):(0,$.jsx)(`div`,{className:`space-y-1.5`,children:i.map(e=>(0,$.jsx)(Hq,{project:e,onRemove:z},e.id))})]})}),(0,$.jsxs)(`div`,{className:c(`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:r(`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:r(`desktop.dailyBudgetLabel`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:r(`desktop.dailyBudgetHelper`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Ij,{type:`number`,min:`0`,step:`0.01`,value:_,onChange:e=>v(e.target.value),placeholder:r(`desktop.dailyBudgetPlaceholder`),className:`h-7 text-xs font-mono`}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs shrink-0`,disabled:y,onClick:()=>void R(),children:r(`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:r(`budget.perJobLabel`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:r(`desktop.perJobHelper`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Ij,{type:`number`,min:`0`,step:`0.01`,value:p,onChange:e=>m(e.target.value),placeholder:r(`budget.perJobPlaceholder`),className:`h-7 text-xs font-mono`}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs shrink-0`,disabled:h,onClick:ee,children:r(`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:r(`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:r(`notifications.description`)}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:j,onChange:e=>F(e.target.checked),className:`w-3.5 h-3.5`,"data-testid":`notif-toggle`}),(0,$.jsx)(No,{className:`w-3.5 h-3.5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`text-xs`,children:r(`notifications.enableLabel`)})]}),j&&(0,$.jsxs)(`div`,{className:`space-y-1.5 pl-6`,children:[(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:r(`notifications.notifyOn`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:[{value:`all`,label:r(`notifications.filterAll`)},{value:`completed`,label:r(`notifications.filterCompleted`)},{value:`failed`,label:r(`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:N===e,onChange:()=>I(e),className:`w-3 h-3`}),t]},e))})]})]})]})]}),(0,$.jsx)(`div`,{className:c(`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:r(`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)(at,{ns:`settings`,i18nKey:`webhooks.description`,components:{code:(0,$.jsx)(`code`,{className:`font-mono`})}})}),x.length>0&&(0,$.jsx)(`div`,{className:`space-y-1.5`,children:x.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 V(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?r(`webhooks.disable`):r(`webhooks.enable`),children:e.enabled?r(`webhooks.statusOn`):r(`webhooks.statusOff`)}),(0,$.jsx)(`button`,{onClick:()=>void U(e.id),className:`text-muted-foreground hover:text-foreground p-0.5`,title:r(`webhooks.sendTestPing`),children:(0,$.jsx)(Pn,{className:`w-3 h-3`})}),(0,$.jsx)(`button`,{onClick:()=>void H(e.id),className:`text-muted-foreground hover:text-destructive p-0.5`,title:r(`common:actions.remove`),children:(0,$.jsx)(An,{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:r(`webhooks.addHeading`)}),(0,$.jsx)(Ij,{value:C,onChange:e=>w(e.target.value),placeholder:`https://hooks.example.com/...`,className:`h-7 text-xs font-mono`}),(0,$.jsx)(Ij,{value:T,onChange:e=>E(e.target.value),placeholder:r(`webhooks.secretPlaceholder`),className:`h-7 text-xs font-mono`}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:Vq.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:D.includes(e),onChange:()=>te(e),className:`w-3 h-3`}),r(t)]},e))}),(0,$.jsxs)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs w-full`,disabled:k||!C.trim(),onClick:()=>void B(),children:[(0,$.jsx)(Dn,{className:`w-3 h-3 mr-1`}),r(`webhooks.addButton`)]})]})]})]})}),(0,$.jsx)(`div`,{className:c(`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:r(`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:r(`desktop.platformTour`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:r(`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)(Es,{className:`w-3 h-3 mr-1`}),r(`desktop.replayTour`)]})]})})]})}),(0,$.jsx)(`div`,{className:c(`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:r(`desktop.terminalPanelHeading`)}),(0,$.jsx)(OW,{mode:`desktop`})]})}),(0,$.jsx)(`div`,{className:c(`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:r(`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:r(`desktop.infoPort`)}),(0,$.jsx)(`span`,{className:`font-mono`,children:l?.port??4200})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:r(`desktop.infoProjects`)}),(0,$.jsx)(`span`,{className:`font-mono`,children:i.length})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:r(`desktop.infoDb`)}),(0,$.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:`~/.specrails/desktop.sqlite`})]})]})]})})]})]})]})})}var Gq=[{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`},...F?[{keys:`⌘⇧A`,descriptionKey:`shortcuts.items.toggleAgent`,category:`general`}]:[],{keys:H?`⌘1–5`:`⌘1–4`,descriptionKey:H?`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 Kq(e){let t=e.target;if(!t)return!1;let n=t.tagName;return!!(n===`INPUT`||n===`TEXTAREA`||n===`SELECT`||t.isContentEditable)}function qq(e){let t=e.target;return!t||typeof t.closest!=`function`?!1:!!t.closest(`[role="dialog"]`)}function Jq(e){let t=e.target;return!t||typeof t.closest!=`function`?!1:!!t.closest(`.specrails-xterm-container, .xterm`)}function Yq({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(qq(e))return;e.preventDefault(),b.current?.();return}if((e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&e.code===`KeyA`){if(qq(e))return;e.preventDefault(),x.current?.();return}if(Kq(e)||Jq(e)||qq(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 Xq(){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 Zq={general:`shortcuts.categories.general`,navigation:`shortcuts.categories.navigation`,actions:`shortcuts.categories.actions`},Qq=[`general`,`navigation`,`actions`];function $q({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 eJ({shortcut:e}){let{t}=K(`commands`),n=nW(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)($q,{children:e},t))})]})}function tJ({open:e,onOpenChange:t}){let{t:n}=K(`commands`),r=Qq.map(e=>({category:e,label:n(Zq[e]),shortcuts:Gq.filter(t=>t.category===e)})).filter(e=>e.shortcuts.length>0);return(0,$.jsx)(sr,{open:e,onOpenChange:t,children:(0,$.jsxs)(ar,{movableResizable:!0,className:`max-w-md`,"data-testid":`shortcuts-cheatsheet`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:n(`shortcuts.title`)}),(0,$.jsx)(Zn,{children:(0,$.jsxs)(at,{i18nKey:`shortcuts.subtitle`,ns:`commands`,children:[`Press `,(0,$.jsx)($q,{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)(eJ,{shortcut:e},e.keys))})]},e.category))})]})})}function nJ(){return typeof window<`u`&&`__TAURI_INTERNALS__`in window}function rJ(){return nJ()&&/mac/i.test(navigator.platform)}function iJ({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 aJ({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)(On,{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 oJ(){return nJ()?rJ()?(0,$.jsx)(sJ,{}):(0,$.jsx)(cJ,{}):null}function sJ(){let{projects:e,activeProjectId:t}=lt(),{uiMode:n}=bN();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)(aJ,{projectName:(e.find(e=>e.id===t)??null)?.name??null,hidden:n===`agent`})})}function cJ(){let{t:e}=K(`nav`),{projects:t,activeProjectId:n}=lt(),{uiMode:r}=bN(),i=t.find(e=>e.id===n)??null,a=(0,Q.useMemo)(()=>aP(),[]),[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)(aJ,{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)(iJ,{onClick:c,icon:(0,$.jsx)(Gs,{size:14,strokeWidth:1.8}),ariaLabel:e(`titleBar.minimizeWindow`)}),(0,$.jsx)(iJ,{onClick:l,icon:o?(0,$.jsx)(is,{size:12,strokeWidth:1.8}):(0,$.jsx)(En,{size:12,strokeWidth:1.8}),ariaLabel:e(o?`titleBar.restoreWindow`:`titleBar.maximizeWindow`)}),(0,$.jsx)(iJ,{onClick:u,icon:(0,$.jsx)(Nn,{size:15,strokeWidth:1.8}),hoverColor:`var(--color-destructive)`,hoverTextColor:`var(--color-destructive-foreground)`,ariaLabel:e(`titleBar.closeWindow`)})]})]})}var lJ=`アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン0123456789ABCDEF`,uJ=16,dJ=uJ,fJ=uJ*1.1,pJ=180,mJ=340,hJ=.07,gJ=.22,_J=18,vJ=600,yJ=48,bJ=160,xJ=360;function SJ(){return lJ[Math.floor(Math.random()*61)]??` `}function CJ(e){return{head:-Math.random()*Math.max(e,12),speed:hJ+Math.random()*(gJ-hJ),glyphs:Array.from({length:_J},()=>SJ()),nextSwapAt:0}}function wJ(){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=`${uJ}px "DM Mono", "JetBrains Mono", "Fira Code", ui-monospace, monospace`,i.textBaseline=`top`;let o=Math.ceil(t/dJ),s=Math.ceil(n/fJ);if(a.length===0)a=Array.from({length:o},()=>CJ(s));else if(a.length<o){let e=Array.from({length:o-a.length},()=>CJ(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>yJ&&s.splice(0,s.length-yJ)),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>vJ;)s.shift();let r=window.innerWidth,d=window.innerHeight;i.clearRect(0,0,r,d);let f=Math.ceil(d/fJ),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-_J>f+4&&(c.head=-Math.random()*12,c.speed=hJ+Math.random()*(gJ-hJ)),e>c.nextSwapAt&&(c.glyphs[Math.floor(Math.random()*_J)]=SJ(),c.nextSwapAt=e+bJ+Math.random()*xJ),!p)continue;let l=r*dJ+dJ/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>mJ))for(let e=0;e<_J;e++){let t=c.head-e;if(t<-1||t>f+2)continue;let a=t*fJ,u=0;if(o!==null){let e=l-o.x,t=a-o.y,n=Math.sqrt(e*e+t*t);if(n<=mJ){let e=n<pJ?1:1-(n-pJ)/(mJ-pJ);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>mJ)continue;let o=i<pJ?1:1-(i-pJ)/(mJ-pJ),s=n-e.t,c=o*(s>vJ?0:1-s/vJ);if(c>u&&(u=c),u>=.999)break}if(u<.02)continue;let d=1-e/_J,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*dJ,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 TJ=24,EJ=200,DJ=3.5,OJ=10,kJ=`hsl(210, 60%, 96%)`,AJ=`hsl(212, 100%, 62%)`;function jJ(){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>TJ&&a.splice(0,a.length-TJ)}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>EJ;)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=AJ;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/EJ);if(s<=0)continue;let c=t/a.length;i.globalAlpha=s*(.25+.75*c),i.lineWidth=Math.max(.5,DJ*c),i.shadowBlur=OJ*c,i.strokeStyle=c>.6?kJ:AJ,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 MJ={"code-rain":wJ,galaxy:jJ};function NJ(){let e=MJ[_a().id];return e?(0,$.jsx)(e,{}):null}function PJ({project:e}){let{t}=K(`nav`),n=VV(),{registerHandler:r,unregisterHandler:i}=Ze(),[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)($k,{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 FJ({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)(at,{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)(uc,{className:`w-3.5 h-3.5`}),r(`common:actions.retry`)]})]})}var IJ=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)(FJ,{projectName:this.props.projectName,errorMessage:this.state.error?.message??null,onRetry:this.handleRetry}):this.props.children}};function LJ({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)(Oc,{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)(at,{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`)}),De&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 max-w-sm`,children:t(`welcome.jiraHint`)}),fe&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 max-w-sm`,children:t(`welcome.mcpHint`)}),F&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 max-w-sm`,children:t(`welcome.agentChatHint`)}),ve&&(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)(bs,{className:`w-3.5 h-3.5`}),t(`welcome.addFirstProject`)]})]})}var RJ=`https://specrails.dev/companion-app`,zJ=`specrails-desktop:onboarding-dismissed`;function BJ(){try{return localStorage.getItem(zJ)===`true`}catch{return!1}}function VJ(){try{localStorage.setItem(zJ,`true`)}catch{}}var HJ=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform||``),UJ=HJ?`⌘`:`Ctrl`,WJ=HJ?`⌥`:`Alt`,GJ={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 KJ({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 qJ({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 JJ({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 YJ({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)(B,{className:`w-3.5 h-3.5 text-muted-foreground`})]},t.label))})}function XJ(){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)(qG,{}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:e(`onboarding.language.note`)})]})}function ZJ(){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 QJ({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)(hq,{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)(ln,{className:`w-3 h-3 shrink-0`,"aria-hidden":`true`})]})]})]})}function $J(){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)(at,{t:e,i18nKey:`onboarding.companion.intro`,components:{b:(0,$.jsx)(`span`,{className:`text-foreground font-medium`})}})}),(0,$.jsx)(JJ,{accent:GJ.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)(QJ,{icon:(0,$.jsx)(Cc,{className:`w-4 h-4 shrink-0`,"aria-hidden":`true`}),url:RJ,label:e(`onboarding.companion.open`),testId:`companion-web-link`})]}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(sc,{className:`w-4 h-4`}),label:e(`onboarding.companion.pairLabel`),accent:GJ.success,children:e(`onboarding.companion.pairBody`)})]})}function eY(e){let t={b:(0,$.jsx)(`span`,{className:`text-foreground font-medium`})};return[{navLabel:e(`onboarding.language.nav`),icon:(0,$.jsx)(Fs,{className:`w-6 h-6`}),accent:GJ.info,title:e(`onboarding.language.title`),subtitle:e(`onboarding.language.subtitle`),content:(0,$.jsx)(XJ,{})},{navLabel:e(`onboarding.theme.nav`),icon:(0,$.jsx)(Xs,{className:`w-6 h-6`}),accent:GJ.highlight,title:e(`onboarding.theme.title`),subtitle:e(`onboarding.theme.subtitle`),content:(0,$.jsx)(ZJ,{})},{navLabel:e(`onboarding.welcome.nav`),icon:(0,$.jsx)(kn,{className:`w-6 h-6`}),accent:GJ.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)(at,{t:e,i18nKey:`onboarding.welcome.intro`,components:t})}),(0,$.jsxs)(JJ,{accent:GJ.primary,label:e(`onboarding.welcome.coreLoopLabel`),children:[(0,$.jsx)(YJ,{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)(at,{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)(qJ,{icon:(0,$.jsx)(Fo,{className:`w-4 h-4`}),label:e(`onboarding.welcome.missionLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.welcome.missionBody`,components:t})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Ls,{className:`w-4 h-4`}),label:e(`onboarding.welcome.boardLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.welcome.boardBody`,components:t})})]}),(0,$.jsxs)(`div`,{className:`flex gap-3 items-start`,children:[(0,$.jsx)(xc,{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)(at,{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`)})]})},...F?[{navLabel:e(`onboarding.mission.nav`),icon:(0,$.jsx)(Fo,{className:`w-6 h-6`}),accent:GJ.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)(at,{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)(qJ,{icon:(0,$.jsx)(S,{className:`w-4 h-4`}),label:e(`onboarding.mission.missionsLabel`),accent:GJ.primary,children:e(`onboarding.mission.missionsBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(xc,{className:`w-4 h-4`}),label:e(`onboarding.mission.levelsLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.mission.levelsBody`,components:{...t,shift:(0,$.jsx)(KJ,{children:`Shift`}),tab:(0,$.jsx)(KJ,{children:`Tab`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Is,{className:`w-4 h-4`}),label:e(`onboarding.mission.cardsLabel`),accent:GJ.primary,children:e(`onboarding.mission.cardsBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Io,{className:`w-4 h-4`}),label:e(`onboarding.mission.workspaceLabel`),accent:GJ.primary,children:e(`onboarding.mission.workspaceBody`)})]}),(0,$.jsx)(JJ,{accent:GJ.primary,label:e(`onboarding.mission.mcpLabel`),children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.mission.mcpBody`,components:t})})]})}]:[],...Te?[{navLabel:e(`onboarding.builder.nav`),icon:(0,$.jsx)(Os,{className:`w-6 h-6`}),accent:GJ.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)(at,{t:e,i18nKey:`onboarding.builder.intro`,components:t})}),(0,$.jsxs)(JJ,{accent:GJ.highlight,label:e(`onboarding.builder.flowLabel`),children:[(0,$.jsx)(YJ,{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)(qJ,{icon:(0,$.jsx)(Nc,{className:`w-4 h-4`}),label:e(`onboarding.builder.cardsLabel`),accent:GJ.highlight,children:e(`onboarding.builder.cardsBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(hs,{className:`w-4 h-4`}),label:e(`onboarding.builder.specsLabel`),accent:GJ.highlight,children:e(`onboarding.builder.specsBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(fc,{className:`w-4 h-4`}),label:e(`onboarding.builder.milestonesLabel`),accent:GJ.highlight,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.builder.milestonesBody`,components:t})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Ss,{className:`w-4 h-4`}),label:e(`onboarding.builder.progressLabel`),accent:GJ.highlight,children:e(`onboarding.builder.progressBody`)})]})]})}]:[],{navLabel:e(`onboarding.authorSpecs.nav`),icon:(0,$.jsx)(S,{className:`w-6 h-6`}),accent:GJ.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)(at,{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)(qJ,{icon:(0,$.jsx)(Fo,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.agentLabel`),accent:GJ.info,children:e(`onboarding.authorSpecs.agentBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(S,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.exploreLabel`),accent:GJ.info,children:e(`onboarding.authorSpecs.exploreBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Pn,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.quickLabel`),accent:GJ.info,children:e(`onboarding.authorSpecs.quickBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(D,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.websiteLabel`),accent:GJ.info,children:e(`onboarding.authorSpecs.websiteBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(hc,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.smashLabel`),accent:GJ.info,children:e(`onboarding.authorSpecs.smashBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(sn,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.draftsLabel`),accent:GJ.info,children:e(`onboarding.authorSpecs.draftsBody`)})]}),De&&(0,$.jsx)(JJ,{accent:GJ.info,label:e(`onboarding.jira.label`),children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.jira.body`,components:t})})]})},{navLabel:e(`onboarding.rails.nav`),icon:(0,$.jsx)(Fc,{className:`w-6 h-6`}),accent:GJ.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)(at,{t:e,i18nKey:`onboarding.rails.intro`,components:{...t,play:(0,$.jsx)(`span`,{className:`text-accent-warning font-medium`})}})}),(0,$.jsxs)(JJ,{accent:GJ.success,label:e(`onboarding.rails.jobLabel`),children:[(0,$.jsx)(YJ,{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)(qJ,{icon:(0,$.jsx)(Sn,{className:`w-4 h-4`}),label:e(`onboarding.rails.reviewLabel`),accent:GJ.success,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.rails.reviewBody`,components:t})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(ps,{className:`w-4 h-4`}),label:e(`onboarding.rails.packetLabel`),accent:GJ.success,children:e(`onboarding.rails.packetBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(S,{className:`w-4 h-4`}),label:e(`onboarding.rails.steerLabel`),accent:GJ.success,children:e(`onboarding.rails.steerBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(dc,{className:`w-4 h-4`}),label:e(`onboarding.rails.loopsLabel`),accent:GJ.success,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.rails.loopsBody`,components:t})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Fo,{className:`w-4 h-4`}),label:e(`onboarding.rails.profilesLabel`),accent:GJ.success,children:e(`onboarding.rails.profilesBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(bs,{className:`w-4 h-4`}),label:e(`onboarding.rails.isolationLabel`),accent:GJ.success,children:e(`onboarding.rails.isolationBody`)})]})]})},{navLabel:e(`onboarding.providers.nav`),icon:(0,$.jsx)(Fo,{className:`w-6 h-6`}),accent:GJ.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)(at,{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)(JJ,{accent:GJ.secondary,label:e(`onboarding.providers.calloutLabel`),children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.providers.calloutBody`,components:{...t,mono:(0,$.jsx)(`span`,{className:`font-mono`})}})})]})},{navLabel:e(`onboarding.cost.nav`),icon:(0,$.jsx)(ts,{className:`w-6 h-6`}),accent:GJ.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)(at,{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)(qJ,{icon:(0,$.jsx)(Ss,{className:`w-4 h-4`}),label:e(`onboarding.cost.analyticsLabel`),accent:GJ.warning,children:e(`onboarding.cost.analyticsBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(lc,{className:`w-4 h-4`}),label:e(`onboarding.cost.perTicketLabel`),accent:GJ.warning,children:e(`onboarding.cost.perTicketBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(us,{className:`w-4 h-4`}),label:e(`onboarding.cost.honestLabel`),accent:GJ.warning,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.cost.honestBody`,components:{mono:(0,$.jsx)(`span`,{className:`font-mono`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Mc,{className:`w-4 h-4`}),label:e(`onboarding.cost.budgetsLabel`),accent:GJ.warning,children:e(`onboarding.cost.budgetsBody`)})]})]})},{navLabel:e(`onboarding.workspace.nav`),icon:(0,$.jsx)(Io,{className:`w-6 h-6`}),accent:GJ.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)(qJ,{icon:(0,$.jsx)(Oc,{className:`w-4 h-4`}),label:e(`onboarding.workspace.terminalLabel`),accent:GJ.highlight,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.workspace.terminalBody`,values:{mod:UJ},components:{mod:(0,$.jsx)(KJ,{children:UJ}),j:(0,$.jsx)(KJ,{children:`J`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(hs,{className:`w-4 h-4`}),label:e(`onboarding.workspace.codeLabel`),accent:GJ.highlight,children:e(`onboarding.workspace.codeBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(D,{className:`w-4 h-4`}),label:e(`onboarding.workspace.browserLabel`),accent:GJ.highlight,children:e(`onboarding.workspace.browserBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(ac,{className:`w-4 h-4`}),label:e(`onboarding.workspace.integrationsLabel`),accent:GJ.highlight,children:e(`onboarding.workspace.integrationsBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Xs,{className:`w-4 h-4`}),label:e(`onboarding.workspace.themesLabel`),accent:GJ.highlight,children:e(`onboarding.workspace.themesBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Is,{className:`w-4 h-4`}),label:e(`onboarding.workspace.chatsLabel`),accent:GJ.highlight,children:e(`onboarding.workspace.chatsBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Se,{className:`w-4 h-4`}),label:e(`onboarding.workspace.compareLabel`),accent:GJ.highlight,children:e(`onboarding.workspace.compareBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(fc,{className:`w-4 h-4`}),label:e(`onboarding.workspace.desktopLabel`),accent:GJ.highlight,children:e(`onboarding.workspace.desktopBody`)})]})})},{navLabel:e(`onboarding.companion.nav`),icon:(0,$.jsx)(Cc,{className:`w-6 h-6`}),accent:GJ.success,title:e(`onboarding.companion.title`),subtitle:e(`onboarding.companion.subtitle`),content:(0,$.jsx)($J,{})},{navLabel:e(`onboarding.moveFast.nav`),icon:(0,$.jsx)(rs,{className:`w-6 h-6`}),accent:GJ.primary,title:e(`onboarding.moveFast.title`),subtitle:e(`onboarding.moveFast.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(JJ,{accent:GJ.primary,label:e(`onboarding.moveFast.paletteLabel`),children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.paletteShortcut`,values:{mod:UJ},components:{f:(0,$.jsx)(`span`,{className:`text-foreground`}),m:(0,$.jsx)(`span`,{className:`text-muted-foreground`}),mod:(0,$.jsx)(KJ,{children:UJ}),k:(0,$.jsx)(KJ,{children:`K`})}})}),e(`onboarding.moveFast.paletteBody`)]}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-3`,children:[(0,$.jsx)(qJ,{icon:(0,$.jsx)(Fo,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.agentLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.agentBody`,values:{mod:UJ},components:{mod:(0,$.jsx)(KJ,{children:UJ}),shift:(0,$.jsx)(KJ,{children:`Shift`}),a:(0,$.jsx)(KJ,{children:`A`}),tab:(0,$.jsx)(KJ,{children:`Tab`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Oc,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.terminalLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.terminalBody`,values:{mod:UJ},components:{mod:(0,$.jsx)(KJ,{children:UJ}),j:(0,$.jsx)(KJ,{children:`J`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Ps,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.shortcutsLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.shortcutsBody`,components:{q:(0,$.jsx)(KJ,{children:`?`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(S,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.chatLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.chatBody`,values:{mod:UJ},components:{mod:(0,$.jsx)(KJ,{children:UJ}),bkey:(0,$.jsx)(KJ,{children:`B`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(bs,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.projectsLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.projectsBody`,values:{alt:WJ,mod:UJ},components:{alt:(0,$.jsx)(KJ,{children:WJ}),mod:(0,$.jsx)(KJ,{children:UJ}),bkey:(0,$.jsx)(KJ,{children:`B`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(rs,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.pagesLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.pagesBody`,values:{alt:WJ,mod:UJ},components:{alt:(0,$.jsx)(KJ,{children:WJ}),mod:(0,$.jsx)(KJ,{children:UJ}),n:(0,$.jsx)(KJ,{children:`1–9`})}})})]}),(0,$.jsx)(JJ,{accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.outro`,components:t})})]})}]}function tY({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)(()=>eY(n),[n]),c=s[r],l=r===0,u=r===s.length-1,d=(0,Q.useCallback)(()=>{a&&VJ(),i(0),t()},[a,t]),f=(0,Q.useCallback)(()=>{VJ(),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)(ir,{open:e,onOpenChange:e=>{e||d()},children:(0,$.jsxs)(Jn,{children:[(0,$.jsx)(qn,{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)(cr,{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)(vn,{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)(tr,{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)(on,{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)(B,{className:`w-3.5 h-3.5 ml-1`})]})]})]})]})]})]})]})})}function nY(){let[e,t]=(0,Q.useState)(new Map),n=(0,Q.useContext)($e);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(`${Ke}/api/projects/${e}/assemble-retry`,{method:`POST`})},[])}}var rY=(0,Q.lazy)(()=>c(()=>import(`./ProjectSettingsDialog-SAfCqXzC.js`).then(e=>({default:e.ProjectSettingsDialog})),__vite__mapDeps([86,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,55,65,51,66,67]))),iY=`specrails-desktop:agentTreeExpanded`;function aY(){try{let e=localStorage.getItem(iY);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 oY(e){try{localStorage.setItem(iY,JSON.stringify([...e]))}catch{}}function sY(){window.dispatchEvent(new KeyboardEvent(`keydown`,{key:`k`,metaKey:!0,ctrlKey:!0,bubbles:!0}))}var cY=`__home__`,lY=`__favorites__`;function uY({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)(S,{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:qb(e.updated_at),children:Kb(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)(ks,{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)(Nn,{className:`w-2.5 h-2.5`})})]})]})}function dY({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)(bs,{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)(Wo,{className:`w-3.5 h-3.5`}):(0,$.jsx)(Go,{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)(yc,{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)(Nn,{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)(uY,{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 fY={"pinned-open":`sidebarPin.left.pinnedOpen`,"pinned-collapsed":`sidebarPin.left.pinnedCollapsed`,unpinned:`sidebarPin.left.unpinned`};function pY({onAddProject:e,onOpenLoops:t,onOpenPlugins:n,onOpenAnalytics:r,onOpenDocs:i,onOpenSettings:a}){let{t:o}=K(`nav`),{t:s}=K(`agent`),{projects:c,activeProjectId:l,setActiveProjectId:u,removeProject:d}=lt(),f=nY(),m=y(),h=p(),g=h.pathname.startsWith(`/loops`),_=h.pathname.startsWith(`/plugins`),v=g||_||h.pathname.startsWith(`/docs`),{leftMode:x,cycleLeftMode:S}=RP(),{uiMode:C,toggleUiMode:w}=bN(),T=qN(),E=C===`agent`,D=(0,Q.useMemo)(()=>{let e=new Map,t=new Set(c.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:cY,i=e.get(r);i?i.push(n):e.set(r,[n])}return e},[T.conversations,T.favoriteConversationIds,c]),O=(0,Q.useMemo)(()=>T.conversations.filter(e=>T.favoriteConversationIds.has(e.id)),[T.conversations,T.favoriteConversationIds]),k=D.get(cY)??[],[A,j]=(0,Q.useState)(aY),M=A.has(lY),[N,P]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{!E||!l||j(e=>{if(e.has(l))return e;let t=new Set(e);return t.add(l),oY(t),t})},[E,l]);let F=e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),oY(n),n})},I=e=>{T.selectConversation(e),v&&m(`/`)},L=e=>{T.deleteConversation(e).catch(()=>{})},ee=e=>{T.toggleFavoriteConversation(e)};function R(e){if(E){u(e),F(e);return}if(e===l){v&&m(`/`);return}u(e)}let[z,B]=(0,Q.useState)(!1),V=x===`pinned-open`||x===`unpinned`&&z,H=DP(`left-arc`,{side:`left`,defaultWidth:240,min:200,max:460,collapsedWidth:44,expanded:V}),U=x!==`unpinned`,te=o(fY[x]),ne=[{label:o(`arcSidebar.docs`),icon:Po,action:i},{label:o(`arcSidebar.analytics`),icon:Vo,action:r},{label:o(`arcSidebar.settings`),icon:yc,action:a}];async function re(e){try{await d(e.id)}catch{}}return(0,$.jsxs)(`div`,{ref:H.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`&&B(!0)},onMouseLeave:()=>{x===`unpinned`&&!H.dragging&&B(!1)},children:[V&&(0,$.jsx)(OP,{side:`left`,dragging:H.dragging,width:H.width,min:200,max:460,label:o(`arcSidebar.resize`,{defaultValue:`Resize sidebar`}),onPointerDown:H.onGripPointerDown,onKeyDown:H.onGripKeyDown}),(0,$.jsxs)(`div`,{className:X(`flex items-center h-12 border-b border-border flex-shrink-0`,V?`px-3 justify-between`:`justify-center`),children:[V&&(0,$.jsx)(`span`,{className:`font-mono text-sm font-bold whitespace-nowrap overflow-hidden text-accent-primary`,children:o(`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`,U?`text-foreground bg-muted`:`text-muted-foreground/40 hover:text-muted-foreground hover:bg-muted/50`),"aria-label":te,title:o(`sidebarPin.withShortcut`,{label:te,shortcut:nW(`⌥⌘B`)}),children:(0,$.jsx)(Zs,{className:`w-4 h-4`})})]}),b&&(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(l),v&&m(`/`)},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`,V?`px-2`:`px-0 justify-center`),"aria-label":s(`newAgent`),title:V?void 0:s(`newAgent`),children:[(0,$.jsx)(Dn,{className:`w-4 h-4 flex-shrink-0`}),V&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:s(`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`,V?`px-2`:`px-0 justify-center`),"aria-label":s(E?`switchToKanban`:`switchToAgent`),title:s(E?`switchToKanban`:`switchToAgent`),children:[E?(0,$.jsx)(Ls,{className:`w-4 h-4 flex-shrink-0`}):(0,$.jsx)(Fo,{className:`w-4 h-4 flex-shrink-0 text-accent-primary`}),V&&(0,$.jsx)(`span`,{className:`min-w-0 truncate text-xs`,children:s(E?`switchToKanban`:`switchToAgent`)})]}),E&&(0,$.jsxs)(`button`,{type:`button`,onClick:sY,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`,V?`px-2`:`px-0 justify-center`),"aria-label":s(`search`),title:V?void 0:s(`search`),children:[(0,$.jsx)(On,{className:`w-4 h-4 flex-shrink-0`}),V&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:s(`search`)})]})]}),Ce&&(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`,V?`px-2`:`px-0 justify-center`,g?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),"aria-label":o(`arcSidebar.loops`),"aria-current":g?`page`:void 0,title:V?void 0:o(`arcSidebar.loops`),children:[(0,$.jsx)(Fc,{className:X(`w-4 h-4 flex-shrink-0`,g&&`text-accent-primary`)}),V&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:o(`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`,V?`px-2`:`px-0 justify-center`,_?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),"aria-label":o(`arcSidebar.plugins`),"aria-current":_?`page`:void 0,title:V?void 0:o(`arcSidebar.plugins`),children:[(0,$.jsx)(oc,{className:X(`w-4 h-4 flex-shrink-0`,_&&`text-accent-primary`)}),V&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:o(`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(lY),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`,V?`px-2`:`px-0 justify-center`),"aria-label":s(`favoriteMissions`),"aria-expanded":M,title:V?void 0:s(`favoriteMissions`),children:[V?(0,$.jsxs)(`span`,{className:`relative flex h-4 w-4 flex-shrink-0 items-center justify-center`,children:[(0,$.jsx)(ks,{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)(Wo,{className:`w-3.5 h-3.5`}):(0,$.jsx)(Go,{className:`w-3.5 h-3.5`})})]}):(0,$.jsx)(ks,{className:`w-4 h-4 flex-shrink-0 fill-current text-accent-primary`}),V&&(0,$.jsx)(`span`,{className:`text-xs truncate flex-1 text-left`,children:s(`favoriteMissions`)})]}),M&&V&&(0,$.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:O.map(e=>(0,$.jsx)(uY,{conversation:e,active:e.id===T.active?.id,streaming:T.streamingConversationIds.has(e.id),unread:T.unreadConversationIds.has(e.id),favorite:!0,expanded:V,onSelect:()=>I(e.id),onToggleFavorite:()=>ee(e.id),onDelete:()=>L(e.id)},e.id))})]}),E&&k.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>F(cY),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`,V?`px-2`:`px-0 justify-center`),"aria-label":s(`home`),"aria-expanded":A.has(cY),title:V?void 0:s(`home`),children:[V?(0,$.jsxs)(`span`,{className:`relative flex h-4 w-4 flex-shrink-0 items-center justify-center`,children:[(0,$.jsx)(js,{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(cY)?(0,$.jsx)(Wo,{className:`w-3.5 h-3.5`}):(0,$.jsx)(Go,{className:`w-3.5 h-3.5`})})]}):(0,$.jsx)(js,{className:`w-4 h-4 flex-shrink-0`}),V&&(0,$.jsx)(`span`,{className:`text-xs truncate flex-1 text-left`,children:s(`home`)})]}),A.has(cY)&&V&&(0,$.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:k.map(e=>(0,$.jsx)(uY,{conversation:e,active:e.id===T.active?.id,streaming:T.streamingConversationIds.has(e.id),unread:T.unreadConversationIds.has(e.id),expanded:V,onSelect:()=>I(e.id),onToggleFavorite:()=>ee(e.id),onDelete:()=>L(e.id)},e.id))})]}),c.map(e=>{let t=D.get(e.id)??[];return(0,$.jsx)(dY,{project:e,isActive:e.id===l&&!v,expanded:V,onSelect:()=>R(e.id),onRemove:()=>re(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:ee,onDeleteConversation:L,assembleStatus:f.statusFor(e.id),onRetryAssemble:()=>{f.retry(e.id)},onOpenProjectSettings:E?()=>{u(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`,V?`px-2`:`px-0 justify-center`),"aria-label":o(`projects.addProject`),title:V?void 0:o(`projects.addProject`),children:[(0,$.jsx)(Dn,{className:`w-4 h-4 flex-shrink-0`}),V&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:o(`projects.addProject`)})]})]}),(0,$.jsx)(`div`,{className:`border-t border-border py-2 px-1.5 space-y-0.5`,children:ne.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`,V?`px-2`:`px-0 justify-center`),"aria-label":e,title:V?void 0:e,children:[(0,$.jsx)(t,{className:`w-4 h-4 flex-shrink-0`}),V&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:e})]},e))}),N&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(rY,{open:!0,onClose:()=>P(!1)})})]})}var mY={"pinned-open":`sidebarPin.right.pinnedOpen`,"pinned-collapsed":`sidebarPin.right.pinnedCollapsed`,unpinned:`sidebarPin.right.unpinned`};function hY(){let{t:e}=K(`nav`),{rightMode:t,cycleRightMode:n}=RP(),[r,i]=(0,Q.useState)(!1),a=t===`pinned-open`||t===`unpinned`&&r,o=t!==`unpinned`,s=e(mY[t]),c=[{to:`/`,end:!0,icon:Rs,label:e(`rightSidebar.dashboard`)},{to:`/jobs`,end:!1,icon:zo,label:e(`rightSidebar.jobs`)},{to:`/analytics`,end:!1,icon:Bo,label:e(`rightSidebar.analytics`)},...se?[{to:`/code`,end:!1,icon:$o,label:e(`rightSidebar.code`)}]:[],{to:`/settings`,end:!1,icon:yc,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:nW(`⌘B`)}),children:(0,$.jsx)(Qs,{className:`w-4 h-4`})})]}),(0,$.jsxs)(`nav`,{className:`flex-1 py-2 px-1.5 space-y-0.5`,children:[(0,$.jsx)(BP,{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 gY(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 _Y({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)(qo,{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)(uc,{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)(jn,{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)(uc,{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)(yn,{className:`w-3.5 h-3.5 text-destructive flex-shrink-0`}):n||r?(0,$.jsx)(qo,{className:`w-3.5 h-3.5 text-accent-success flex-shrink-0`}):o?(0,$.jsx)(yn,{className:`w-3.5 h-3.5 text-muted-foreground/60 flex-shrink-0`}):(0,$.jsx)(yn,{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)(Ys,{className:`w-2.5 h-2.5`}),a(`prerequisites.bundledBadge`)]}),(0,$.jsxs)(`span`,{className:X(`text-muted-foreground`,t&&`text-destructive/80`),children:[`— `,gY(e,a)]})]},e.key)})})]})}function vY(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 yY=[`darwin`,`win32`,`linux`];async function bY(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 xY({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 bY(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)(vn,{className:`w-3 h-3`}),t(`common:actions.copied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(is,{className:`w-3 h-3`}),t(`common:actions.copy`)]})})}function SY({platform:e,primary:t}){let{t:n}=K(`setup`),r=vY(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)(xY,{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)(ln,{className:`w-3 h-3`})]})},e.url))}),r.note&&(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-accent-highlight`,children:r.note})]})}function CY(){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(`${Ke}/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)(vn,{className:`w-3 h-3 text-accent-success`}):(0,$.jsx)(Zo,{className:`w-3 h-3`}),e(t===`copied`?`instructions.diagnostics.copied`:t===`error`?`instructions.diagnostics.failed`:`instructions.diagnostics.copy`)]})}function wY({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=yY.filter(e=>e!==c);return n?.missingRequired?.some(e=>e.error===`corrupted-bundle`)??!1?(0,$.jsx)(sr,{open:e,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(ar,{movableResizable:!0,className:`max-w-xl`,"data-testid":`install-modal-corrupted-bundle`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:a(`instructions.corrupted.title`)}),(0,$.jsx)(Zn,{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)(sr,{open:e,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(ar,{movableResizable:!0,className:`max-w-xl`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:a(`instructions.title`)}),(0,$.jsx)(Zn,{children:a(`instructions.description`)})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(SY,{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)(SY,{platform:e,primary:!1},e))})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mt-2`,children:[(0,$.jsx)(CY,{}),(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)(uc,{className:X(`w-3 h-3`,i&&`animate-spin`)}),a(`instructions.recheck`)]})]})]})]})})}var TY=typeof window<`u`&&`__TAURI_INTERNALS__`in window;function EY({open:e,onClose:t,onOpenBuilder:n}){let r=Te&&!!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}=lt(),{status:x,isLoading:S,error:C,recheck:w}=Gj(),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)(sr,{open:e,onOpenChange:k,children:(0,$.jsxs)(ar,{className:`max-w-md`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsxs)(er,{className:`flex items-center gap-2`,children:[(0,$.jsx)(bs,{className:`w-4 h-4`}),y(`addProject.title`)]}),(0,$.jsx)(Zn,{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)(ys,{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)(kn,{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)(sr,{open:e,onOpenChange:k,children:(0,$.jsxs)(ar,{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)(rr,{children:[(0,$.jsxs)(er,{className:`flex items-center gap-2`,children:[(0,$.jsx)(bs,{className:`w-4 h-4`}),y(`addProject.title`)]}),(0,$.jsx)(Zn,{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)(_Y,{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)(Ij,{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`}),TY&&(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([85,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)(bs,{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)(Ij,{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)(Ij,{"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)(Nn,{className:`h-4 w-4`})})]},t)),(0,$.jsxs)(Z,{type:`button`,variant:`outline`,size:`sm`,onClick:async()=>{if(TY)try{let{open:e}=await c(async()=>{let{open:e}=await import(`./dist-js-CJ_2XX1Y.js`);return{open:e}},__vite__mapDeps([85,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)(Dn,{className:`mr-1 h-3.5 w-3.5`}),y(`common:repositories.addFolder`)]})]})]}),(0,$.jsxs)(Wn,{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)(wY,{open:_,onClose:()=>v(!1),status:x,onRecheck:w,isRechecking:S})]})})}var DY=1,OY=.9,kY=.8,AY=.17,jY=.1,MY=.999,NY=.9999,PY=.99,FY=/[\\\/_+.#"@\[\(\{&]/,IY=/[\\\/_+.#"@\[\(\{&]/g,LY=/[\s-]/,RY=/[\s-]/g;function zY(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?DY:PY;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*=DY:FY.test(e.charAt(l-1))?(d*=kY,p=e.slice(i,l-1).match(IY),p&&i>0&&(d*=MY**+p.length)):LY.test(e.charAt(l-1))?(d*=OY,m=e.slice(i,l-1).match(RY),m&&i>0&&(d*=MY**+m.length)):(d*=AY,i>0&&(d*=MY**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=NY)),(d<jY&&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*jY>d&&(d=f*jY)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function BY(e){return e.toLowerCase().replace(RY,` `)}function VY(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,zY(e,t,BY(e),BY(t),0,0,{})}var HY=`[cmdk-group=""]`,UY=`[cmdk-group-items=""]`,WY=`[cmdk-group-heading=""]`,GY=`[cmdk-item=""]`,KY=`${GY}:not([aria-disabled="true"])`,qY=`cmdk-item-select`,JY=`data-value`,YY=(e,t,n)=>VY(e,t,n),XY=Q.createContext(void 0),ZY=()=>Q.useContext(XY),QY=Q.createContext(void 0),$Y=()=>Q.useContext(QY),eX=Q.createContext(void 0),tX=Q.forwardRef((e,t)=>{let n=hX(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=hX(()=>new Set),i=hX(()=>new Map),a=hX(()=>new Map),o=hX(()=>new Set),s=pX(e),{label:c,children:l,value:u,onValueChange:d,filter:f,shouldFilter:p,loop:m,disablePointerSelection:h=!1,vimBindings:g=!0,..._}=e,v=Hn(),y=Hn(),b=Hn(),x=Q.useRef(null),S=vX();mX(()=>{if(u!==void 0){let e=u.trim();n.current.value=e,C.emit()}},[u]),mX(()=>{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??YY;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(UY);t?t.appendChild(e.parentElement===t?e:e.closest(`${UY} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${UY} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=x.current?.querySelector(`${HY}[${JY}="${encodeURIComponent(e[0])}"]`);t?.parentElement.appendChild(t)})}function D(){let e=j().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(JY);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(HY)?.querySelector(WY))==null||e.scrollIntoView({block:`nearest`})),t.scrollIntoView({block:`nearest`}))}function A(){return x.current?.querySelector(`${GY}[aria-selected="true"]`)}function j(){return Array.from(x.current?.querySelectorAll(KY)||[])}function M(e){let t=j()[e];t&&C.setState(`value`,t.getAttribute(JY))}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(JY))}function P(e){let t=A()?.closest(HY),n;for(;t&&!n;)t=e>0?dX(t,HY):fX(t,HY),n=t?.querySelector(KY);n?C.setState(`value`,n.getAttribute(JY)):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(In.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(qY);t.dispatchEvent(e)}}}}},Q.createElement(`label`,{"cmdk-label":``,htmlFor:w.inputId,id:w.labelId,style:xX},c),bX(e,e=>Q.createElement(QY.Provider,{value:C},Q.createElement(XY.Provider,{value:w},e))))}),nX=Q.forwardRef((e,t)=>{let n=Hn(),r=Q.useRef(null),i=Q.useContext(eX),a=ZY(),o=pX(e),s=o.current?.forceMount??i?.forceMount;mX(()=>{if(!s)return a.item(n,i?.id)},[s]);let c=_X(n,r,[e.value,e.children,r],e.keywords),l=$Y(),u=gX(e=>e.value&&e.value===c.current),d=gX(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(qY,f),()=>t.removeEventListener(qY,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(In.div,{ref:$n(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)}),rX=Q.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...a}=e,o=Hn(),s=Q.useRef(null),c=Q.useRef(null),l=Hn(),u=ZY(),d=gX(e=>i||u.filter()===!1?!0:!e.search||e.filtered.groups.has(o));mX(()=>u.group(o),[]),_X(o,s,[e.value,e.heading,c]);let f=Q.useMemo(()=>({id:o,forceMount:i}),[i]);return Q.createElement(In.div,{ref:$n(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),bX(e,e=>Q.createElement(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?l:void 0},Q.createElement(eX.Provider,{value:f},e))))}),iX=Q.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=Q.useRef(null),a=gX(e=>!e.search);return!n&&!a?null:Q.createElement(In.div,{ref:$n(i,t),...r,"cmdk-separator":``,role:`separator`})}),aX=Q.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=e.value!=null,a=$Y(),o=gX(e=>e.search),s=gX(e=>e.selectedItemId),c=ZY();return Q.useEffect(()=>{e.value!=null&&a.setState(`search`,e.value)},[e.value]),Q.createElement(In.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)}})}),oX=Q.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...i}=e,a=Q.useRef(null),o=Q.useRef(null),s=gX(e=>e.selectedItemId),c=ZY();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(In.div,{ref:$n(a,t),...i,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:c.listId},bX(e,e=>Q.createElement(`div`,{ref:$n(o,c.listInnerRef),"cmdk-list-sizer":``},e)))}),sX=Q.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return Q.createElement(ir,{open:n,onOpenChange:r},Q.createElement(Jn,{container:o},Q.createElement(qn,{"cmdk-overlay":``,className:i}),Q.createElement(cr,{"aria-label":e.label,"cmdk-dialog":``,className:a},Q.createElement(tX,{ref:t,...s}))))}),cX=Q.forwardRef((e,t)=>gX(e=>e.filtered.count===0)?Q.createElement(In.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),lX=Q.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return Q.createElement(In.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},bX(e,e=>Q.createElement(`div`,{"aria-hidden":!0},e)))}),uX=Object.assign(tX,{List:oX,Item:nX,Input:aX,Group:rX,Separator:iX,Dialog:sX,Empty:cX,Loading:lX});function dX(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function fX(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function pX(e){let t=Q.useRef(e);return mX(()=>{t.current=e}),t}var mX=typeof window>`u`?Q.useEffect:Q.useLayoutEffect;function hX(e){let t=Q.useRef();return t.current===void 0&&(t.current=e()),t}function gX(e){let t=$Y(),n=()=>e(t.snapshot());return Q.useSyncExternalStore(t.subscribe,n,n)}function _X(e,t,n,r=[]){let i=Q.useRef(),a=ZY();return mX(()=>{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(JY,s),i.current=s}),i}var vX=()=>{let[e,t]=Q.useState(),n=hX(()=>new Map);return mX(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function yX(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function bX({asChild:e,children:t},n){return e&&Q.isValidElement(t)?Q.cloneElement(yX(t),{ref:t.ref},n(t.props.children)):n(t)}var xX={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`};function SX(e){return e.normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).toLowerCase()}function CX(e,t,n=[]){let r=SX(e.trim());return!r||SX(t).includes(r)?!0:n.some(e=>e&&SX(e).includes(r))}function wX(e,t){return Wb(t.updated_at)-Wb(e.updated_at)}function TX(e,t=8){return[...e].sort(wX).slice(0,Math.max(0,t)).map(e=>({conversation:e,match:`recent`,messageId:null,snippet:null}))}function EX(e,t,n,r=20){let i=SX(t.trim());if(!i)return[];let a=SX(n);return[...e].sort(wX).filter(e=>SX(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 DX(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 OX(e){return e===`agent`?[`missions`,`projects`,`spec`,`jobs`,`navigation`]:[`projects`,`missions`,`spec`,`jobs`,`navigation`]}var kX=[];function AX(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 jX({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:kX}),{projects:h,activeProjectId:g,setActiveProjectId:_}=lt(),{leftMode:v,rightMode:b,cycleLeftMode:x,cycleRightMode:S}=RP(),{uiMode:C}=bN(),{conversations:w,liveByConversation:T,selectConversation:E,open:D}=qN(),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(`${ot()}/config`),fetch(`${ot()}/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(()=>{Ja(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?DX(EX(w,e,N),p.query===e?p.hits:kX):TX(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]),ee=(0,Q.useCallback)(async e=>{o(!1);try{let t=await fetch(`${ot()}/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]),R=(0,Q.useCallback)(e=>{o(!1),A(`/jobs/${e}`)},[A]),z=(0,Q.useCallback)(e=>{o(!1),A(e)},[A]),B=(0,Q.useCallback)(e=>{e&&(o(!1),e())},[]),V=`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`,H=h.filter(e=>CX(s,e.name,[e.slug])),U=l.filter(e=>CX(s,e.name,[e.slug,e.description??``])),te=d.filter(e=>CX(s,`${e.command} ${e.id}`,[e.status])),ne=[{key:`dashboard`,label:r(`palette.nav.dashboard`),keywords:[`home`],icon:(0,$.jsx)(Rs,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>z(`/`)},...t?[{key:`desktopAnalytics`,label:r(`palette.nav.desktopAnalytics`),keywords:[`cross-project`,`desktop`],icon:(0,$.jsx)(Ho,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>B(t)}]:[],{key:`projectAnalytics`,label:r(`palette.nav.projectAnalytics`),keywords:[`metrics`],icon:(0,$.jsx)(Bo,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>z(`/analytics`)},{key:`activityFeed`,label:r(`palette.nav.activityFeed`),keywords:[`log`],icon:(0,$.jsx)(Eo,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>z(`/activity`)},{key:`desktopSettings`,label:r(`palette.nav.desktopSettings`),keywords:[`configuration`],icon:(0,$.jsx)(yc,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>e?B(e):z(`/settings`)},{key:`docs`,label:r(`palette.nav.docs`),keywords:[`documentation`],icon:(0,$.jsx)(xn,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>n?B(n):z(`/docs`)},{key:`leftSidebar`,label:O,keywords:[`sidebar`,`panel`,`left`,`pin`,`collapse`,`unpin`,`cycle`],icon:(0,$.jsx)(Zs,{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)(Qs,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>{S(),o(!1)}}].filter(e=>CX(s,e.label,e.keywords)),re={missions:P.length>0&&(0,$.jsx)(uX.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)(uX.Item,{value:`mission:${t.id}`,onSelect:()=>L(t.id),className:X(V,`items-start`),"data-testid":`palette-mission-${t.id}`,children:[(0,$.jsx)(gn,{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:qb(t.updated_at),children:Kb(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:AX(e.snippet)})]})]})]})]},t.id)})},`missions`),projects:H.length>0&&(0,$.jsx)(uX.Group,{heading:r(`palette.groups.projects`),"data-testid":`palette-group-projects`,children:H.map(e=>(0,$.jsxs)(uX.Item,{value:e.name,keywords:[e.slug],onSelect:()=>I(e.id),className:X(V,e.id===g&&`text-accent-primary`),children:[(0,$.jsx)(bs,{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:U.length>0&&(0,$.jsx)(uX.Group,{heading:r(`palette.groups.spec`),children:U.map(e=>(0,$.jsxs)(uX.Item,{value:e.name,keywords:[e.slug,e.description??``],onSelect:()=>ee(e.slug),className:V,children:[(0,$.jsx)(Pn,{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:te.length>0&&(0,$.jsx)(uX.Group,{heading:r(`palette.groups.jobs`),children:te.map(e=>(0,$.jsxs)(uX.Item,{value:`${e.command} ${e.id}`,keywords:[e.status],onSelect:()=>R(e.id),className:V,children:[(0,$.jsx)(zo,{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:ne.length>0&&(0,$.jsx)(uX.Group,{heading:r(`palette.groups.navigation`),children:ne.map(e=>(0,$.jsxs)(uX.Item,{value:e.label,keywords:e.keywords,onSelect:e.onSelect,className:V,children:[e.icon,(0,$.jsx)(`span`,{children:e.label})]},e.key))},`navigation`)};return(0,$.jsxs)(uX.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)(On,{className:`w-4 h-4 text-muted-foreground shrink-0`}),(0,$.jsx)(uX.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)(uX.List,{className:`max-h-80 overflow-y-auto p-2`,children:[(0,$.jsx)(uX.Empty,{className:`py-8 text-center text-sm text-muted-foreground`,children:r(`palette.noResults`)}),OX(C).map(e=>re[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 MX=`
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=BU(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&&!VU.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=nn(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=nn(r.snapshot),c;return s&&u.current===o&&(c=v(s)),{...r,snapshot:s,snapshotApplication:c,busy:e.status===409&&r.error===`operation_in_progress`,operation:s?.operation??(typeof r.operation==`string`&&HU.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]),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)(RU.Provider,{value:w,children:t})}function GU(e){return e?`specrails-desktop:dashboard-split:${e}`:null}function KU(e){let t=GU(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 qU(e,t){let n=GU(e);if(n)try{localStorage.setItem(n,String(Math.round(t)))}catch{}}function JU(e,t){let n=Math.max(320,t-280);return Math.min(Math.max(e,320),n)}var YU=.7;function XU(e){return JU(Math.round(e*YU),e)}function ZU(e,t){let n=XU(t);return Math.abs(e-n)<=48?n:e}function QU(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:XU(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(XU(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??KU(e)??XU(t),a=JU(r!==null&&Number.isFinite(n)?i+n:i,t);return a!==r&&qU(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=JU(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=JU(ZU(t,n),n);return qU(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=XU(n);o(r),qU(e,r)},[e,t]);return{leftWidth:a,enabled:a!==null&&n>=900,beginDrag:p,resetToDefault:m}}function $U({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 eW({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)(sr,{open:e,onOpenChange:e=>!e&&n(),children:(0,$.jsxs)(ar,{movableResizable:!0,className:`max-w-lg glass-card`,children:[(0,$.jsx)(rr,{children:(0,$.jsx)(er,{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)(br,{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)(yn,{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)(Wn,{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)(Dn,{className:`w-3.5 h-3.5 mr-1`}),i(y?`createModal.creating`:`createModal.create`)]})]})]})})}function tW({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=Dt(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)(sr,{open:e,onOpenChange:e=>{e||o()},children:(0,$.jsxs)(ar,{movableResizable:!0,showCloseButton:!1,className:`max-w-md gap-5`,onOpenAutoFocus:e=>{e.preventDefault(),c.current?.focus()},children:[(0,$.jsx)(rr,{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)(kn,{className:`h-4.5 w-4.5`})}),(0,$.jsxs)(`div`,{className:`text-left`,children:[(0,$.jsx)(er,{className:`text-base`,children:s(`freestyleDialog.title`)}),(0,$.jsxs)(Zn,{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)(Sn,{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)(Fo,{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)(us,{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)(Wn,{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 nW(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 rW({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)(sr,{open:e,onOpenChange:e=>{e||i()},children:(0,$.jsxs)(ar,{movableResizable:!0,showCloseButton:!1,className:`max-w-md gap-5`,onOpenAutoFocus:e=>{e.preventDefault(),o.current?.focus()},children:[(0,$.jsx)(rr,{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)(fc,{className:`h-4.5 w-4.5`})}),(0,$.jsxs)(`div`,{className:`text-left`,children:[(0,$.jsx)(er,{className:`text-base`,children:a(`launchAllDialog.title`)}),(0,$.jsxs)(Zn,{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)(Sn,{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)(Is,{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)(us,{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)(Wn,{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:nW(`⌘↵`)})]})]})]})})}function iW({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)(sr,{open:e,onOpenChange:e=>{e||r()},children:(0,$.jsxs)(ar,{movableResizable:!0,showCloseButton:!1,className:`max-w-md gap-5`,onOpenAutoFocus:e=>{e.preventDefault(),a.current?.focus()},children:[(0,$.jsx)(rr,{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)(R,{className:`h-4.5 w-4.5`})}),(0,$.jsxs)(`div`,{className:`text-left`,children:[(0,$.jsx)(er,{className:`text-base`,children:i(`targetPr.confirmTitle`)}),(0,$.jsx)(Zn,{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)(R,{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)(Sn,{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)(Wn,{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:nW(`⌘↵`)})]})]})]})}):null}var aW=`postit`,oW=e=>`specrails-desktop:specs-view-tier:${e}`;function sW(e){return e===`row`||e===`postit`}function cW(e){if(!e)return aW;try{let t=localStorage.getItem(oW(e));if(sW(t))return t}catch{}return aW}function lW(e,t){if(e)try{localStorage.setItem(oW(e),t)}catch{}}function uW(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 dW(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 fW=[{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`}],pW=e=>e===`implement`||e===`batch-implement`||e===`freestyle`||e===`loop`;function mW(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 hW(e,t){for(let n of t.values())if(mW(n,[e]))return!0;return!1}function gW(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 _W(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 vW(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 yW(e,t){if(e)try{localStorage.setItem(`specrails-desktop:rails:${e}`,JSON.stringify(t))}catch{}}function bW(){let{t:e}=K(`dashboard`),{activeProjectId:t,projects:n}=lt(),r=_a().id===`galaxy`,i=(()=>{let e=n.find(e=>e.id===t);return e?st(e):[`claude`]})(),{tickets:a,isLoading:o,error:s,updateTicket:c,updateTicketStatus:l,updateTicketPriority:u,deleteTicket:d,createTicket:f,refetch:p,contractRefiningIds:m}=E(),{registerHandler:h,unregisterHandler:g,connectionStatus:_}=Ze(),{specToOpen:v,clearSpecToOpen:y}=zB(),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),[D,O]=(0,Q.useState)(null),[k,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)(()=>gW(t)),[L,ee]=(0,Q.useState)(()=>vW(t)??fW),[R,z]=(0,Q.useState)({}),B=IU(),{decisions:V,hydrated:H,act:U,checkout:te}=zU(),ne=mB(t),[re,ie]=(0,Q.useState)(ne.mode),[ae,oe]=(0,Q.useState)(ne.dir),[se,ce]=(0,Q.useState)(()=>cW(t));(0,Q.useEffect)(()=>{I(gW(t)),ee(vW(t)??fW),z({});let e=mB(t);ie(e.mode),oe(e.dir),ce(cW(t))},[t]);let le=(0,Q.useCallback)((e,n)=>{ie(e),oe(n),hB(t,e,n)},[t]),ue=(0,Q.useCallback)(e=>{ce(e),lW(t,e)},[t]);(0,Q.useEffect)(()=>{if(_!==`connected`||!t)return;let e=!1,n=vW(t)??fW,r=new Map(n.map(e=>[e.id,e]));return fetch(`${ot()}/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));ee(e=>{let n=!1,u=new Map,d=e.map((e,t)=>{let s=lU(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=pW(a)?a:l?Ux(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=cU(e.railIndex);if(f.has(t))continue;let r=a[String(e.railIndex)],s=i[String(e.railIndex)]?.mode,l=pW(s)?s:r?Ux(r.loopId):pW(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=lU(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 yW(t,g),g})}).catch(()=>{}),()=>{e=!0}},[t,_]),(0,Q.useEffect)(()=>{if(!t)return;let e=!1;return fetch(`${ot()}/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);ee(e=>{let n=!1,i=e.map((e,t)=>{let i=lU(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?(yW(t,i),i):e})}).catch(()=>{}),()=>{e=!0}},[t]),(0,Q.useEffect)(()=>{let e=new Set(a.filter(e=>e.status===`done`||H&&e.status===`on_review`&&!hW(e.id,V)).map(e=>e.id));e.size!==0&&ee(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:(yW(t,r),r)})},[a,t,L,V,H]);let de=(0,Q.useCallback)(e=>{I(n=>{let r=e(n);return _W(t,r),r})},[t]),fe=(0,Q.useCallback)(e=>{ee(n=>{let r=e(n);return yW(t,r),r})},[t]),pe=(0,Q.useMemo)(()=>{let e=new Set([`specs`,`done-specs`]);for(let t of L)e.add(t.id);return e},[L]),me=(0,Q.useCallback)(async()=>{try{let t=await fetch(`${ot()}/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=cU(n);fe(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=>lU(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`};fe(e=>[...e,r]),J.success(e(`toasts.railAdded`,{n}))},[L,fe,e]),he=(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&&de(e=>[...e??[],...n.ticketIds]),fe(e=>e.filter(e=>e.id!==t)),J.info(e(`toasts.railRemoved`,{rail:n.label}))},i=lU(t);if(i===null){r();return}try{let t=await fetch(`${ot()}/rails/${i}`,{method:`DELETE`});if(t.ok||t.status===404){r();return}J.error(e(`toasts.railDeleteFailed`))}catch{J.error(e(`toasts.railDeleteFailed`))}},[L,fe,de,e]),W=(0,Q.useCallback)((e,t)=>{fe(n=>n.map(n=>n.id===e?{...n,label:`Rail ${t}`}:n));let n=lU(e);n!==null&&fetch(`${ot()}/rails/${n}/name`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})}).catch(()=>{})},[fe]),ge=(0,Q.useRef)(t);(0,Q.useEffect)(()=>{ge.current=t},[t]);let _e=(0,Q.useCallback)(t=>{let n=t;if(n.projectId===ge.current){if(n.type===`runtime.continuation`){if(n.railIndex==null)return;let e=cU(n.railIndex);fe(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=cU(n.railIndex),t=n.jobId??n.loopRunId;fe(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=cU(e),r=n.ticketIds??[],i=n.name?`Rail ${n.name}`:`Rail ${e+1}`;fe(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:pW(n.mode)?n.mode:`implement`,status:`idle`}]);return}if(n.type===`rail.removed`){if(n.railIndex==null)return;let e=cU(n.railIndex);fe(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&&(z(e=>fU(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;fe(e=>vU(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;fe(e=>vU(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`}))}}},[fe,e]);(0,Q.useEffect)(()=>(h(`dashboard-rails`,_e),()=>g(`dashboard-rails`)),[_e,h,g]);let ve=_I(gI(SL,{activationConstraint:{distance:5}}),gI(_L)),ye=(0,Q.useCallback)(e=>{let t=typeof e.active.id==`string`&&gU(e.active.id),n=e.droppableContainers.filter(e=>{let n=e.id;return typeof n==`string`&&gU(n)?t:!t}),r={...e,droppableContainers:n};if(t)return DI(r);let i=jI(r);if(wI(i))return i;let a=kI(r);return wI(a)?a:DI(r)},[]),be=(0,Q.useMemo)(()=>new Map(a.map(e=>[e.id,e])),[a]),xe=(0,Q.useMemo)(()=>{let e=[],t=[];return L.forEach((n,r)=>{let i=lU(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=V.get(i);if(a&&!mW(a,n.ticketIds)){t.push({rail:n,reason:`pendingDecision`});return}if(n.ticketIds.some(e=>be.get(e)?.status===`on_review`&&(!H||!hW(e,V)))){t.push({rail:n,reason:`onReview`});return}e.push(n)}),{eligible:e,skipped:t}},[L,V,H,be]),Se=(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]),we=(0,Q.useMemo)(()=>{let e=new Set;for(let t of L)for(let n of t.ticketIds)e.add(n);return e},[L]),Te=(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`)&&!we.has(e.id)),[a,we]);(0,Q.useEffect)(()=>{o||re===`jira-key`&&!Te.some(e=>e.jira_key)&&le(`default`,ae)},[o,re,ae,Te,le]);let Ee=(0,Q.useMemo)(()=>{let e=Te.filter(e=>e.status!==`done`);if(re!=="default")return SB(e,re,ae);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},[Te,F,re,ae]),De=(0,Q.useMemo)(()=>Te.filter(e=>e.status===`done`),[Te]),Oe=(0,Q.useMemo)(()=>{let e=new Set;if(!H)return e;for(let t of a)t.status===`on_review`&&hW(t.id,V)&&e.add(t.id);return e},[a,V,H]),ke=(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`&&(!H||!hW(t,V))){J.info(e(`toasts.onReviewCannotMoveToRail`));return}if(r.ticketIds.includes(t)){J.info(e(`toasts.alreadyOnRail`,{rail:r.label}));return}de(e=>(e??Ee.map(e=>e.id)).filter(e=>e!==t)),fe(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,Ee,fe,de,e,V,H]),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}fe(e=>e.map(e=>e.id===n.id?{...e,ticketIds:e.ticketIds.filter(e=>e!==t)}:e)),de(e=>{let n=e??Ee.map(e=>e.id);return n.includes(t)?n:[...n,t]}),J.success(e(`toasts.removedFromRail`,{rail:n.label}))}},[L,Ee,fe,de,e]),je=(0,Q.useCallback)(e=>{if(Ee.some(t=>t.id===e))return`specs`;if(De.some(t=>t.id===e))return`done-specs`;for(let t of L)if(t.ticketIds.includes(e))return t.id;return null},[Ee,De,L]);function Me({active:e}){if(gU(e.id)){let t=_U(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(gU(n.id)){if(!gU(r.id))return;let e=_U(n.id),t=_U(r.id);if(e===t)return;fe(n=>{let r=n.findIndex(t=>t.id===e),i=n.findIndex(e=>e.id===t);return r===-1||i===-1?n:BR(n,r,i)});return}let i=n.id,o=r.id,s=je(i);if(!s)return;let l=dW(o,pe,je,gU,_U)??s;if(pe.has(l))if(s===l)if(l===`specs`){let e=Ee.map(e=>e.id),n=e.indexOf(i),r=e.indexOf(o);if(n!==-1&&r!==-1&&n!==r){let i=BR(e,n,r);de(()=>i),re!=="default"&&(ie(`default`),hB(t,`default`,ae))}}else fe(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:BR(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}de(e=>(e??Ee.map(e=>e.id)).filter(e=>e!==i)),c(i,{status:`done`})}else if(s===`done-specs`&&l===`specs`)c(i,{status:`todo`}),de(e=>uW(e??Ee.map(e=>e.id),i,o));else if(s===`specs`){if(a.find(e=>e.id===i)?.status===`on_review`&&(!H||!hW(i,V))){J.info(e(`toasts.onReviewCannotMoveToRail`));return}let t=L.find(e=>e.id===l);de(e=>(e??Ee.map(e=>e.id)).filter(e=>e!==i)),fe(e=>e.map(e=>e.id===l?{...e,ticketIds:uW(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}fe(e=>e.map(e=>e.id===s?{...e,ticketIds:e.ticketIds.filter(e=>e!==i)}:e)),de(e=>uW(e??Ee.map(e=>e.id),i,o)),t&&J.success(e(`toasts.removedFromRail`,{rail:t.label}))}else s===`done-specs`?(c(i,{status:`todo`}),fe(e=>e.map(e=>e.id===l?{...e,ticketIds:uW(e.ticketIds,i,o)}:e))):l===`done-specs`?(fe(e=>e.map(e=>e.id===s?{...e,ticketIds:e.ticketIds.filter(e=>e!==i)}:e)),c(i,{status:`done`})):fe(e=>e.map(e=>e.id===s?{...e,ticketIds:e.ticketIds.filter(e=>e!==i)}:e.id===l?{...e,ticketIds:uW(e.ticketIds,i,o)}:e))}function Pe(e,t){fe(n=>n.map(n=>n.id===e?{...n,mode:t}:n))}function Fe(e){let t=lU(e);return t===null?L.findIndex(t=>t.id===e):t}async function Ie(e,t){fe(n=>n.map(n=>n.id===e?{...n,profileName:t}:n));let n=Fe(e);if(n!==-1)try{await fetch(`${ot()}/rails/${n}/profile`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({profileName:t})})}catch{}}function Le(e,t){fe(n=>n.map(n=>n.id===e?{...n,freestyleModel:t}:n))}function Re(e,t){let n=Ux(t);fe(r=>r.map(r=>r.id===e?{...r,selectedLoopId:t,mode:n}:r))}function ze(e){let t=e?.aiEngine;return(bt(t)?void 0:t)??i[0]??`claude`}function Be(e,t){fe(n=>n.map(n=>{if(n.id!==e)return n;let r=ze(n),i=mt(r,t);return{...n,loopModel:t,reasoningEffort:n.reasoningEffort&&i.includes(n.reasoningEffort)?n.reasoningEffort:Ct(r,t)??null}}))}function Ve(e,t){fe(n=>n.map(n=>n.id===e?{...n,reasoningEffort:t}:n))}async function He(t,n){if(bt(n)){let r=L.find(e=>e.id===t);if(r&&(r.mode===`freestyle`||r.selectedLoopId===`factory:freestyle`)){J.error(e(`rail.rolesNoFreestyle`));return}fe(e=>e.map(e=>e.id===t?{...e,aiEngine:n,profileName:null}:e)),await Ue(t,n);return}fe(e=>e.map(e=>{if(e.id!==t)return e;let r=e.mode===`freestyle`||e.selectedLoopId===`factory:freestyle`,i=!gt(n)&&r,a=Ix(n),o=e=>!!(e&&(a.some(t=>t.value===e)||kt(n)&&WO(e))),s=o(e.loopModel)?e.loopModel:Lx(n),c=mt(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:Lx(n),loopModel:s,reasoningEffort:e.reasoningEffort&&c.includes(e.reasoningEffort)?e.reasoningEffort:Ct(n,s)??null}})),await Ue(t,n)}async function Ue(e,t){let n=Fe(e);if(n!==-1)try{await fetch(`${ot()}/rails/${n}/engine`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({aiEngine:t})})}catch{}}function We(e,t){fe(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(`${ot()}/rails/${r}/stop`,{method:`POST`}),fe(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){O({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`&&(!H||!hW(e,V))))return r||J.info(e(`toasts.onReviewNotLaunchable`)),`skipped`;let s=Wx(i.selectedLoopId,i.mode);if(!s)return r||J.error(e(`railControls.pickLoop`)),`failed`;let c=bt(i.aiEngine),l=ze(i),u=mt(l,i.loopModel??Lx(l)),d=i.reasoningEffort&&u.includes(i.reasoningEffort)?i.reasoningEffort:null,f=ot();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 fe(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(xe.eligible.length===0){J.info(e(`toasts.launchAllNoneEligible`));return}A(!0)}async function Je(){A(!1);let{eligible:t,skipped:n}=xe;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:be.get(j),Xe=(0,Q.useRef)(null),{leftWidth:Qe,enabled:$e,beginDrag:et,resetToDefault:tt}=QU(t,Xe),nt=typeof window<`u`?window.innerWidth:1200;return(0,$.jsx)(xz,{children:(0,$.jsxs)(yR,{sensors:ve,collisionDetection:ye,onDragStart:Me,onDragEnd:Ne,children:[(0,$.jsxs)(`div`,{ref:Xe,className:`relative z-0 flex h-full overflow-hidden`,children:[r&&(0,$.jsx)(bP,{}),(0,$.jsx)(`div`,{className:`relative z-10 min-w-0 flex flex-col overflow-hidden`,style:$e&&Qe!==null?{width:`${Qe}px`,flex:`0 0 auto`}:{flex:`1 1 0%`},children:(0,$.jsx)(qH,{tickets:Ee,allTickets:a,doneTickets:De,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:re,sortDir:ae,onSortChange:le,viewTier:se,onViewTierChange:ue,rails:L,onMoveToRail:ke,continuableReviewTicketIds:Oe})}),$e&&Qe!==null&&(0,$.jsx)($U,{leftWidth:Qe,viewport:nt,onPointerDown:et,onReset:tt}),(0,$.jsx)(`div`,{className:`relative z-10 flex-1 min-w-0 flex flex-col overflow-hidden`,children:(0,$.jsx)(bU,{rails:L,ticketMap:be,railWorktrees:R,railMetrics:B,railPrDecisions:V,onPrDecision:U,onPrCheckout:te,providers:i,onModeChange:Pe,onProfileChange:Ie,onEngineChange:He,onFreestyleModelChange:Le,onLoopModelChange:Be,loopAvailable:Ce,onLoopChange:Re,onEffortChange:Ve,onToggle:Ge,onTargetPrChange:We,onTicketClick:x,onAddRail:()=>{me()},onDeleteRail:e=>{he(e)},onRenameRail:W,onTicketMoveToSpecs:Ae,onLaunchAll:qe,launchAllCount:xe.eligible.length})})]}),(0,$.jsx)(zR,{dropAnimation:{duration:180,easing:`ease`},children:Ye?se===`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)(G,{ticket:e,allLabels:Se,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:ke,onRemoveFromRail:Ae},e.id)})(),(0,$.jsx)(eW,{open:S,allLabels:Se,onClose:()=>C(!1),onCreate:f}),(0,$.jsx)(rW,{open:k,railCount:xe.eligible.length,specCount:xe.eligible.reduce((e,t)=>e+t.ticketIds.length,0),onCancel:()=>A(!1),onConfirm:()=>{Je()}}),(()=>{let e=D?L.find(e=>e.id===D.railId):void 0;return(0,$.jsx)(iW,{open:!!D&&!!e?.targetPr,target:e?.targetPr??null,onCancel:()=>O(null),onConfirm:()=>{let e=D?.railId;O(null),e&&Ke(e)}})})(),(()=>{let e=w?L.find(e=>e.id===w.railId):void 0,t=ze(e);return(0,$.jsx)(tW,{open:!!w&&!!e,railLabel:e?.label??``,specCount:e?.ticketIds.length??0,provider:t,model:e?.freestyleModel??Lx(t),onCancel:()=>T(null),onConfirm:()=>{let e=w?.railId;T(null),e&&Ke(e)}})})()]})})}var xW=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}));xW.displayName=`Card`;var SW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:X(`flex flex-col space-y-1 p-4`,e),...t}));SW.displayName=`CardHeader`;var CW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`h3`,{ref:n,className:X(`text-sm font-semibold leading-none tracking-tight`,e),...t}));CW.displayName=`CardTitle`;var wW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`p`,{ref:n,className:X(`text-xs text-muted-foreground`,e),...t}));wW.displayName=`CardDescription`;var TW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:X(`p-4 pt-0`,e),...t}));TW.displayName=`CardContent`;var EW=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:X(`flex items-center p-4 pt-0`,e),...t}));EW.displayName=`CardFooter`;var DW=[`auto`,`canvas`,`webgl`];function OW({mode:e}){let{t}=K(`settings`),{activeProjectId:n}=lt(),[r,i]=(0,Q.useState)(Di),[a,o]=(0,Q.useState)({}),[s,c]=(0,Q.useState)(Di),[l,u]=(0,Q.useState)(Di),[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),WP({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),WP({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)(xW,{children:(0,$.jsx)(TW,{children:t(`common:states.loading`)})}):(0,$.jsxs)(xW,{children:[(0,$.jsxs)(SW,{children:[(0,$.jsx)(CW,{children:t(`terminal.title`)}),(0,$.jsx)(wW,{children:t(e===`desktop`?`terminal.desktopDescription`:`terminal.projectDescription`)})]}),(0,$.jsxs)(TW,{className:`space-y-4`,children:[(0,$.jsx)(kW,{label:t(`terminal.fontFamily`),overridden:S(`fontFamily`),onClear:()=>y(`fontFamily`),mode:e,children:(0,$.jsx)(Ij,{value:l.fontFamily,onChange:e=>v(`fontFamily`,e.target.value)})}),(0,$.jsx)(kW,{label:t(`terminal.fontSize`,{min:8,max:32}),overridden:S(`fontSize`),onClear:()=>y(`fontSize`),mode:e,children:(0,$.jsx)(Ij,{type:`number`,min:8,max:32,value:l.fontSize,onChange:e=>v(`fontSize`,parseInt(e.target.value,10)||l.fontSize)})}),(0,$.jsx)(kW,{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:DW.map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))})}),(0,$.jsx)(AW,{label:t(`terminal.copyOnSelect`),checked:l.copyOnSelect,overridden:S(`copyOnSelect`),onClear:()=>y(`copyOnSelect`),onChange:e=>v(`copyOnSelect`,e),mode:e}),(0,$.jsx)(AW,{label:t(`terminal.shellIntegration`),checked:l.shellIntegrationEnabled,overridden:S(`shellIntegrationEnabled`),onClear:()=>y(`shellIntegrationEnabled`),onChange:e=>v(`shellIntegrationEnabled`,e),mode:e}),(0,$.jsx)(AW,{label:t(`terminal.notifyLongRunning`),checked:l.notifyOnCompletion,overridden:S(`notifyOnCompletion`),onClear:()=>y(`notifyOnCompletion`),onChange:e=>v(`notifyOnCompletion`,e),mode:e}),(0,$.jsx)(kW,{label:t(`terminal.longCommandThreshold`),overridden:S(`longCommandThresholdMs`),onClear:()=>y(`longCommandThresholdMs`),mode:e,children:(0,$.jsx)(Ij,{type:`number`,min:1e3,value:l.longCommandThresholdMs,onChange:e=>v(`longCommandThresholdMs`,parseInt(e.target.value,10)||l.longCommandThresholdMs)})}),(0,$.jsx)(AW,{label:t(`terminal.imageRendering`),checked:l.imageRendering,overridden:S(`imageRendering`),onClear:()=>y(`imageRendering`),onChange:e=>v(`imageRendering`,e),mode:e}),(0,$.jsx)(kW,{id:`terminal-browser-shortcut-url`,label:t(`terminal.browserShortcutUrl`),overridden:S(`browserShortcutUrl`),onClear:()=>y(`browserShortcutUrl`),mode:e,children:(0,$.jsx)(Ij,{type:`url`,value:l.browserShortcutUrl,placeholder:`https://specrails.dev`,onChange:e=>v(`browserShortcutUrl`,e.target.value)})}),(0,$.jsx)(kW,{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 kW({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 AW({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 jW(){let{activeProjectId:e,projects:t,refreshProjects:n}=lt(),r=t.find(t=>t.id===e);return r?(0,$.jsx)(MW,{project:r,refreshProjects:n},r.id):null}function MW({project:e,refreshProjects:t}){let{t:n}=K(`common`),[r,i]=(0,Q.useState)(()=>yr(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(yr(e))},[e]);let x=`${vr(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)(xW,{children:[(0,$.jsxs)(SW,{children:[(0,$.jsxs)(CW,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ys,{className:`h-4 w-4`}),n(`repositories.title`)]}),(0,$.jsx)(wW,{children:n(`repositories.sharedBacklog`)})]}),(0,$.jsxs)(TW,{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)(Ij,{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)(Ij,{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([85,0,1])),t=await e({directory:!0,multiple:!1});typeof t==`string`&&b.current&&d(t)}catch{}},children:(0,$.jsx)(bs,{className:`h-4 w-4`})})]})]}),(0,$.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`repositories.integrationBranch`),(0,$.jsx)(Ij,{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)(Dn,{className:`mr-1 h-4 w-4`}),n(`repositories.addFolder`)]})]})]})}var NW=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function PW({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:NW,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 FW({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)(PW,{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)(Ij,{value:t.escalation.model,onChange:e=>r({...t,escalation:{...t.escalation,model:e.target.value,effort:void 0}})})]}),(0,$.jsx)(PW,{value:t.escalation.effort,capability:a(`escalation`),onChange:e=>r({...t,escalation:{...t.escalation,effort:e}})})]})]})}function IW({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:NW,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)(Ij,{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 LW({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)(vc,{className:`h-3 w-3 opacity-70`,"aria-hidden":!0}):n.value?(0,$.jsx)(ss,{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 RW=[`verifier`,`decider`],zW=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function BW(e){let t=e?.roles;if(!t||typeof t!=`object`)return{};let n={};for(let e of RW){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 VW(e){let{t}=K(`agentRuntime`),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(!1),o=(0,Q.useRef)({}),s=`${vr(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=BW(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=BW(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 HW(e){return e&&(e.model||Lx(e.provider))||null}function UW({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:Ix(e).map(e=>e.value)},c=t?.provider,l=Et(c),u=c?Ix(c):[],d=c?Lx(c):``,f=t?.model&&!u.some(e=>e.value===t.model)?t.model:null,p=t?.model||d||null,m=c?mt(c,p):[],h=!!c&&St(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)(LW,{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:Dt(e),detail:e,local:Et(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)(Ij,{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 WW=[`architect`,`developer`,`verification`,`fixer`,`reviewer`,`verifier`,`decider`],GW={architect:`core`,developer:`core`,verification:`core`,fixer:`core`,reviewer:`core`,verifier:`loop`,decider:`loop`},KW=[`core`,`loop`],qW={core:WW.filter(e=>GW[e]===`core`),loop:WW.filter(e=>GW[e]===`loop`)};function JW(e){return qW[GW[e]].indexOf(e)+1}var YW={architect:ns,developer:Os,verification:xc,fixer:Mn,reviewer:ps,verifier:Xo,decider:Sn};function XW({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)(Oc,{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?vc:ss;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 ZW({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)(dc,{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 QW({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:KW.map((i,a)=>{let o=e.filter(e=>GW[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)(ZW,{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=YW[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)(XW,{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)(Go,{className:`h-3.5 w-3.5`})})]},e.id)})})]})]},i)})})}var $W=(0,Q.forwardRef)(function({phase:e,engine:t,open:n,active:r,onToggle:i,children:a},o){let{t:s}=K(`agentRuntime`),c=JW(e),l=YW[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)(XW,{engine:t}),(0,$.jsx)(Wo,{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})]})}),eG=[`claude`,`codex`,`gemini`,`kimi`],tG=[`architect`,`developer`,`reviewer`],nG=[...tG,`fixer`];function rG(e){return e.kind===`openai-compatible`&&e.label?.trim()?e.label.trim():e.id}function iG(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 aG=[`architect`,`developer`,`host`];function oG(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`&&aG.includes(e.phase))}function sG(e,t,n){let r={...e};return n?delete r[t]:r[t]=!1,Object.keys(r).length?r:void 0}var cG=[`type_correctness`,`pattern_adherence`,`test_coverage`,`security`,`architectural_alignment`],lG=[`ask`,`proceed`],uG={minScore:70,aspects:{type_correctness:60,pattern_adherence:60,test_coverage:60,security:75,architectural_alignment:60}},dG={maxTurns:100,maxAttempts:3,timeoutMs:15*6e4};function fG(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&&tG.every(e=>typeof n.agents[e]?.provider==`string`)}function pG(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 mG(e,t){let n=t,r=2;for(;e.some(({id:e})=>e===n);)n=`${t}-${r++}`;return n}function hG(e){return[e.command,...e.args].map(e=>/[\s"]/.test(e)?JSON.stringify(e):e).join(` `)}function gG(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 _G={architect:ns,developer:Os,host:Oc};function vG({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(`${vr(e)}/agent-runtime/guardrails`,{cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(`guardrails`);let n=await e.json();if(!oG(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)(xc,{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)(Wo,{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`)})}),aG.map(e=>{let i=l.filter(t=>t.phase===e);if(!i.length)return null;let a=_G[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(sG(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 yG=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function bG(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 xG(){let{activeProjectId:e,projects:t}=lt(),n=(0,Q.useRef)(new Map),r=t.find(t=>t.id===e);return e?(0,$.jsx)(TG,{projectId:e,cache:n.current,projectProviderIds:r?.providers?.length?r.providers:r?.provider?[r.provider]:[],repositories:yr(r).map(({id:e,name:t})=>({id:e,name:t}))},e):null}function SG(e){return e.map(e=>({original:e,label:e.label,repositoryId:e.repositoryId,line:hG(e)}))}function CG(e){return e.map(e=>({repositoryId:e.repositoryId,line:hG(e),reason:e.reason}))}function wG(e){return e===void 0?``:String(Math.round(e/6e4*100)/100)}function TG({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)(SG(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,ee]=(0,Q.useState)(()=>Object.fromEntries(WW.map(e=>[e,!0]))),R=(0,Q.useRef)({}),z=VW(e),B=(0,Q.useRef)(!1),V=(0,Q.useRef)(!0),H=`${vr(e)}/agent-runtime/config`,U=(0,Q.useRef)(0),te=(0,Q.useRef)(l);te.current=l;let ne=JSON.stringify([e,l?.providers,l&&tG.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 re(t){if(!te.current)return;let n=structuredClone(te.current);for(let e of[...Object.values(n.agents),...n.fixer?[n.fixer]:[]])e.escalation&&!e.escalation.model.trim()&&delete e.escalation;let r=++U.current;g(!0),v(!1);try{let i=await fetch(`${vr(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`);V.current&&!t?.aborted&&r===U.current&&m(a.roles)}catch{V.current&&!t?.aborted&&r===U.current&&(m([]),v(!0))}finally{V.current&&!t?.aborted&&r===U.current&&g(!1)}}(0,Q.useEffect)(()=>{if(U.current++,m([]),v(!1),!te.current||s?.efficiencyAvailable===!1){g(!1);return}let e=new AbortController;g(!0);let t=setTimeout(()=>{re(e.signal)},250);return()=>{clearTimeout(t),e.abort(),U.current++}},[ne,s?.efficiencyAvailable,N]);let ie=`${vr(e)}/agent-runtime/verification-suggestions`;async function ae(){try{let e=await fetch(ie,{cache:`no-store`});if(!e.ok)return null;let t=await e.json();return pG(t)?t.suggestions:null}catch{return null}}(0,Q.useEffect)(()=>{V.current=!0;let n=!1;return fetch(H,{cache:`no-store`}).then(async r=>{if(!r.ok)throw Error(i(`loadFailed`));let a=await r.json();if(!fG(a))throw Error(i(`loadFailed`));if(!n){if(t.set(e,a),c(a),!B.current&&(u(a.config),f(SG(a.config.verification)),!a.configured&&a.config.verification.length===0)){let e=await ae();if(n||B.current)return;e?.length?(f(CG(e)),w(`some`)):e&&w(`none`)}O(``)}}).catch(()=>{n||O(i(`loadFailed`))}).finally(()=>{n||E(!1)}),()=>{n=!0,V.current=!1}},[H,e,t,N,i]);function oe(e){B.current=!0,A(!1),M(!0),u(e)}function se(e){B.current=!0,A(!1),M(!0),f(e)}function ce(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 le(e){if(e.kind!==`openai-compatible`)return[];let t=a.providers[e.id]?.models,n=t&&t.length?t:Ix(e.id).map(e=>e.value);return e.defaultModel&&!n.includes(e.defaultModel)?[e.defaultModel,...n]:n}function ue(){let e=[];for(let t of d){if(!t.line.trim()&&!t.repositoryId)continue;let n=gG(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 de(){S(!0),O(``);try{let e=await ae();if(!V.current)return;if(!e){O(i(`verification.detectFailed`));return}let t=new Set(d.map(e=>`${e.repositoryId}\0${e.line}`)),n=CG(e).filter(e=>!t.has(`${e.repositoryId}\0${e.line}`));se([...d,...n]),w(e.length?`some`:`none`)}finally{V.current&&S(!1)}}async function fe(){if(!l||y)return;O(``),A(!1);let n=ue();if(n){b(!0);try{let r=await fetch(H,{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(!fG(a))throw Error(i(`saveFailed`));if(t.set(e,a),!V.current)return;B.current=!1,M(!1),c(a),u(a.config),f(SG(a.config.verification)),A(!0)}catch(e){V.current&&O(e instanceof Error?e.message:i(`saveFailed`))}finally{V.current&&b(!1)}}}let pe=l?.limits??{},me=(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),oe({...l,limits:Object.keys(r).length?r:void 0})},he=l?.review??{},W=(e,t)=>{if(!l)return;let n=t===``?void 0:Number(t),r={...he.aspects};e!==`minScore`&&(n===void 0?delete r[e]:r[e]=n);let i={},a=e===`minScore`?n:he.minScore;a!==void 0&&(i.minScore=a),Object.keys(r).length&&(i.aspects=r),oe({...l,review:Object.keys(i).length?i:void 0})},ge=e=>{l&&oe({...l,architect:e?{onLowConfidence:e}:void 0})},_e=r.length?r:(l?.providers??[]).map(e=>e.id),ve=!!l?.enabled&&s?.runtimeAvailable!==!1;function ye(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=z.roles?.[e];return t?{kind:`ai`,label:Dt(t.provider),model:HW(t),effort:t.effort??null,local:Et(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?ce(n).label:t.provider,i=n?.kind===`openai-compatible`;return{kind:`ai`,label:r,model:t.model??(n?.kind===`cli`?Lx(n.cli):n?.defaultModel)??null,effort:t.effort??null,local:i}}let be=WW.map(e=>({id:e,engine:ye(e)}));function xe(e){I(e),ee(t=>({...t,[e]:!0}));let t=R.current[e];t&&bG(t)}function Se(e){I(e),ee(t=>({...t,[e]:!t[e]}))}function G(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=>oe(e===`fixer`?{...l,fixer:t}:{...l,agents:{...l.agents,[e]:t}}),a=n?.kind===`cli`?Ix(n.cli):[],o=n?.kind===`cli`?Lx(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)(LW,{name:`runtime-${e}-provider`,value:t.provider,ariaLabel:i(`agents.provider`),tabs:l.providers.map(e=>ce(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:yG,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)(Ij,{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:le(n).map(e=>(0,$.jsx)(`option`,{value:e},e))})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`agents.maxTurns`,{turns:dG.maxTurns}),(0,$.jsx)(Ij,{type:`number`,min:`1`,step:`1`,placeholder:String(dG.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)(FW,{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,oe(e);return}let n=l.agents.developer;oe({...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)(Mn,{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&&G(`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 de(),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:yG,value:e.repositoryId,onChange:e=>se(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)(Ij,{value:e.repositoryId,onChange:e=>se(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)(Ij,{className:`font-mono`,spellCheck:!1,placeholder:`npm test`,value:e.line,onChange:e=>se(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)(Ij,{maxLength:256,value:e.label??``,onChange:e=>se(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]],se(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]],se(e)},children:`↓`}),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,onClick:()=>se(d.filter((e,n)=>n!==t)),children:i(`verification.remove`)})]})]},t)),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,onClick:()=>se([...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`)}),!ve&&(0,$.jsx)(`p`,{role:`status`,className:`rounded-md border border-accent-warning/40 p-3 text-xs text-accent-warning`,children:i(`loopRoles.disabled`)}),z.failed&&(0,$.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:i(`loadFailed`)}),z.roles===null&&!z.failed&&(0,$.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:i(`loading`)}),z.roles&&(0,$.jsx)(`fieldset`,{disabled:!ve,className:`disabled:opacity-60`,children:(0,$.jsx)(UW,{role:e,engine:z.roles[e],providers:_e,enabled:ve,onChange:t=>z.setRole(e,t)})})]})}return(0,$.jsxs)(xW,{id:`agent-runtime-settings`,children:[(0,$.jsxs)(SW,{children:[(0,$.jsx)(CW,{children:i(`title`)}),(0,$.jsx)(wW,{children:i(`description`)})]}),(0,$.jsxs)(TW,{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:dG.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)(Is,{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)(QW,{steps:be,active:F,onSelect:xe}),(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 re(),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:[KW.map(e=>(0,$.jsxs)(`div`,{className:`space-y-3`,"data-testid":`phase-cards-${e}`,children:[(0,$.jsx)(ZW,{group:e,className:e===`loop`?`border-t border-border/60 pt-3`:``}),qW[e].map(e=>(0,$.jsx)($W,{ref:t=>{R.current[e]=t},phase:e,engine:ye(e),open:L[e],active:F===e,onToggle:()=>Se(e),children:e===`verification`?we():e===`fixer`?Ce():e===`verifier`||e===`decider`?Te(e):G(e)},e))]},e)),(0,$.jsx)(vG,{projectId:e,guardrails:l.guardrails,onChange:e=>{let t={...l,guardrails:e};e||delete t.guardrails,oe(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)(IW,{config:l,onChange:oe})}),(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:dG.maxAttempts,minutes:dG.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:dG.maxAttempts}),(0,$.jsx)(Ij,{type:`number`,min:`1`,step:`1`,placeholder:String(dG.maxAttempts),value:pe.maxAttempts??``,onChange:e=>me(`maxAttempts`,e.target.value)})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`limits.timeoutMinutes`,{minutes:dG.timeoutMs/6e4}),(0,$.jsx)(Ij,{type:`number`,min:`1`,step:`1`,placeholder:String(dG.timeoutMs/6e4),value:wG(pe.timeoutMs),onChange:e=>me(`timeoutMs`,e.target.value,6e4)})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`limits.maxTokens`),(0,$.jsx)(Ij,{type:`number`,min:`1`,step:`1`,placeholder:i(`limits.unlimited`),value:pe.maxTokens??``,onChange:e=>me(`maxTokens`,e.target.value)})]}),(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`limits.maxCostUsd`),(0,$.jsx)(Ij,{type:`number`,min:`0.000001`,step:`any`,placeholder:i(`limits.unlimited`),value:pe.maxCostUsd??``,onChange:e=>me(`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=>oe({...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:uG.minScore,security:uG.aspects.security,aspect:uG.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:uG.minScore}),(0,$.jsx)(Ij,{type:`number`,min:uG.minScore,max:`100`,step:`1`,placeholder:String(uG.minScore),value:he.minScore??``,onChange:e=>W(`minScore`,e.target.value)})]}),cG.map(e=>(0,$.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[i(`review.aspects.${e}`,{score:uG.aspects[e]}),(0,$.jsx)(Ij,{type:`number`,min:uG.aspects[e],max:`100`,step:`1`,placeholder:String(uG.aspects[e]),value:he.aspects?.[e]??``,onChange:t=>W(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:yG,value:l.architect?.onLowConfidence??``,onChange:e=>ge(e.target.value),children:[(0,$.jsx)(`option`,{value:``,children:i(`agents.defaultModel`,{model:i(`architect.ask`)})}),lG.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 fe(),children:i(y?`saving`:`save`)})]})})]})]})]})}function EG(){return(0,$.jsx)(`div`,{className:`h-32 animate-pulse rounded-lg bg-muted/30`,"data-testid":`section-skeleton`})}function DG(){let{t:e}=K(`settings`),{activeProjectId:t}=lt(),[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(`${ot()}/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)(EG,{});async function c(t){a(!0);let i=n;r(t);try{if(!(await fetch(`${ot()}/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)(xW,{children:[(0,$.jsxs)(SW,{children:[(0,$.jsx)(CW,{children:e(`telemetry.title`)}),(0,$.jsx)(wW,{children:e(`telemetry.description`)})]}),(0,$.jsx)(TW,{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)(at,{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 OG(){let{t:e}=K(`settings`),{activeProjectId:t}=lt(),[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(`${ot()}/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)(EG,{});async function d(){s(!0);try{let t=await fetch(`${ot()}/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)(xW,{children:[(0,$.jsxs)(SW,{children:[(0,$.jsx)(CW,{children:e(`integrationBranch.title`)}),(0,$.jsx)(wW,{children:e(`integrationBranch.description`)})]}),(0,$.jsxs)(TW,{className:`space-y-3`,children:[(0,$.jsx)(Ij,{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)(at,{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 kG=/^[A-Za-z_][A-Za-z0-9_]*$/,AG=[`NODE_AUTH_TOKEN`,`NPM_TOKEN`,`AWS_PROFILE`];function jG(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}function MG(){let{t:e}=K(`settings`),{activeProjectId:t}=lt(),[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(`${ot()}/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)(EG,{});function f(t){let i=jG(t);if(i.length===0)return;let o=[...n];for(let t of i){if(t.includes(`=`)){s(e(`worktreeEnv.noValues`));return}if(!kG.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(`${ot()}/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)(xW,{children:[(0,$.jsxs)(SW,{children:[(0,$.jsx)(CW,{children:e(`worktreeEnv.title`)}),(0,$.jsx)(wW,{children:e(`worktreeEnv.description`)})]}),(0,$.jsxs)(TW,{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)(Ij,{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)(Dn,{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:AG.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)(Nn,{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 NG({value:e,onChange:t,onSave:n,isSaving:r,fieldId:i,i18nRoot:a}){let{t:o}=K(`settings`);return(0,$.jsxs)(xW,{children:[(0,$.jsxs)(SW,{children:[(0,$.jsx)(CW,{children:o(`${a}.title`)}),(0,$.jsx)(wW,{children:o(`${a}.description`)})]}),(0,$.jsxs)(TW,{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 PG(){let{t:e}=K(`settings`),{activeProjectId:t}=lt(),[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(`${ot()}/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(`${ot()}/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(`${ot()}/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)(NG,{value:n,onChange:e=>{f.current.pre=!0,r(e)},onSave:p,isSaving:i,fieldId:`project-pre-prompt`,i18nRoot:`prePrompt`}),(0,$.jsx)(NG,{value:o,onChange:e=>{f.current.freestyle=!0,s(e)},onSave:m,isSaving:c,fieldId:`project-freestyle-pre-prompt`,i18nRoot:`freestylePrePrompt`})]}):(0,$.jsx)(EG,{})}function FG(){let{t:e}=K(`settings`),{activeProjectId:t}=lt(),[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(`${ot()}/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(`${ot()}/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)(xW,{children:[(0,$.jsxs)(SW,{children:[(0,$.jsx)(CW,{children:e(`budget.title`)}),(0,$.jsx)(wW,{children:e(`budget.description`)})]}),(0,$.jsx)(TW,{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)(Ij,{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)(Ij,{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)(EG,{})}function IG(){let{t:e}=K(`settings`),{activeProjectId:t}=lt(),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(`${ot()}/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)(DG,{}),(0,$.jsx)(PG,{}),(0,$.jsx)(jW,{}),(0,$.jsx)(xG,{}),(0,$.jsx)(OG,{}),(0,$.jsx)(MG,{}),(0,$.jsx)(FG,{}),(0,$.jsx)(OW,{mode:`project`})]})}function LG(){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||!tG.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`?nG:tG,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 RG(){let{t:e}=K(`settings`),t=AA();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:()=>OA({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)(kn,{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)(xA,{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=ga();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:Ui.map(t=>{let r=ia[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)(vn,{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 BG(){let{t:e}=K(`settings`);return ga()?(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 VG(e={}){let t={...e},n=Ge();return n&&(t[`X-Desktop-Token`]=n),t}var HG=(0,Q.createContext)(null);function UG(e){if(!(typeof localStorage>`u`))try{localStorage.setItem(He,e)}catch{}}function WG(){if(!(typeof localStorage>`u`))try{localStorage.removeItem(He)}catch{}}function GG({children:e,endpoint:t=`/api/language`}){let[n,r]=(0,Q.useState)(()=>Xe()),[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:VG()});if(!n.ok)return;let i=await n.json();if(e)return;Re(i.language)&&i.language!==Xe()&&(await tt(i.language),UG(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`&&Re(localStorage.getItem(`specrails-desktop:ui-language`));await tt(e),UG(e),r(e),a(!0);try{let n=await fetch(t,{method:`PATCH`,headers:VG({"Content-Type":`application/json`}),body:JSON.stringify({language:e})});if(!n.ok)throw Error(`server rejected language: ${n.status}`)}catch(e){throw await tt(i),o?UG(i):WG(),r(i),e}finally{a(!1)}},[n,t]),c=(0,Q.useMemo)(()=>({languageId:n,language:et[n],setLanguage:s,isUpdating:i}),[n,s,i]);return(0,$.jsx)(HG.Provider,{value:c,children:e})}function KG(){return(0,Q.useContext)(HG)}function qG(){let{t:e}=K(`settings`),t=KG();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:Ve.map(e=>{let t=et[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)(vn,{className:`w-3.5 h-3.5 text-accent-primary shrink-0`,"aria-hidden":`true`})]},e)})})}function JG(){let{t:e}=K(`settings`);return KG()?(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)(qG,{})]}):null}function YG(){if(!se)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 XG=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function ZG({provider:e,onChange:t,onRemove:n}){let{t:r}=K(`agentRuntime`),i=e.kind===`openai-compatible`,a=i?vc:wc;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}),rG(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)(Ij,{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:XG,value:e.cli,onChange:n=>t({...e,cli:n.target.value}),children:eG.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)(Ij,{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)(Ij,{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 QG(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 $G={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 eK({state:e,latencyMs:t,className:n}){let{t:r}=K(`agentRuntime`),i=$G[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 tK({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)(fs,{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 nK({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)(wc,{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)(eK,{state:QG(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)(tK,{label:r(`providers.overflow`),items:[{id:`remove`,label:r(`providers.remove`),icon:(0,$.jsx)(An,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),destructive:!0,onSelect:n}]})]})]})}function rK(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.reachable==`boolean`&&typeof t.authState==`string`}function iK({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||!rK(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)(Cn,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(ic,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),o(s?`providers.testing`:`providers.test`)]})}function aK(e){return(e.agentLoop??`compact`)===`compact`&&e.supportsReasoningEffort===!0&&(e.contextWindowTokens??0)>=32768}var oK=`__custom__`,sK=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`,cK=`space-y-1 text-xs text-muted-foreground`;function lK(e){return e===void 0?``:String(e)}function uK(e){if(e.trim()===``)return null;let t=Number(e);return Number.isFinite(t)&&t>=0?t:NaN}function dK({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:lK(e.rates?.inputPer1M),output:lK(e.rates?.outputPer1M)}),[_,v]=(0,Q.useState)(!1),y=t?.models??[],b=!e.defaultModel||y.includes(e.defaultModel),x=_||!b,S=uK(h.input),C=uK(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=uK(i.input),o=uK(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&&Fx(e.id,t.models)}let D=QG(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)(eK,{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)(iK,{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:cK,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)(wn,{className:`h-3 w-3`,"aria-hidden":!0}),s(`providers.rename`)]})]}),(0,$.jsx)(Ij,{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:cK,htmlFor:`${c}-label`,children:[s(`providers.label`),(0,$.jsx)(Ij,{id:`${c}-label`,value:e.label??``,placeholder:s(`providers.labelPlaceholder`),onChange:t=>r({...e,label:t.target.value||void 0})})]}),(0,$.jsxs)(`label`,{className:cK,htmlFor:`${c}-url`,children:[s(`providers.baseUrl`),(0,$.jsx)(Ij,{id:`${c}-url`,type:`url`,value:e.baseUrl,onChange:t=>r({...e,baseUrl:t.target.value})})]}),(0,$.jsxs)(`label`,{className:cK,htmlFor:`${c}-env`,children:[s(`providers.apiKeyEnv`),(0,$.jsx)(Ij,{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)(jn,{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:cK,htmlFor:`${c}-default`,children:[s(`providers.defaultModel`),(0,$.jsxs)(`select`,{id:`${c}-default`,className:sK,value:x?oK:e.defaultModel??``,onChange:t=>{if(t.target.value===oK){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:oK,children:s(`providers.customModel`)})]})]}),x&&(0,$.jsxs)(`label`,{className:cK,htmlFor:`${c}-custom`,children:[s(`providers.customModel`),(0,$.jsx)(Ij,{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:cK,htmlFor:`${c}-in`,children:[s(`providers.inputRate`),(0,$.jsx)(Ij,{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:cK,htmlFor:`${c}-out`,children:[s(`providers.outputRate`),(0,$.jsx)(Ij,{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:aK(e),title:s(`providers.presetSmallModelHint`),onClick:()=>r({...e,agentLoop:void 0,supportsReasoningEffort:!0,contextWindowTokens:e.contextWindowTokens??32768}),children:[(0,$.jsx)(kn,{className:`mr-1 h-3.5 w-3.5`,"aria-hidden":!0}),aK(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:cK,htmlFor:`${c}-ctx`,children:[s(`providers.contextWindow`),(0,$.jsx)(Ij,{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:cK,htmlFor:`${c}-out`,children:[s(`providers.maxOutput`),(0,$.jsx)(Ij,{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 fK(e){let t=e??32768;return t>=1024&&t%1024==0?`${t/1024}k`:t.toLocaleString()}function pK({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=rG(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)(vc,{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)(eK,{state:QG(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:[fK(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)(Wo,{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)(dK,{provider:e,status:t,persisted:n,onChange:i,onStatus:a,onValidity:o,onRemove:s})})]})}var mK=1;function hK(e,t){return e.map(e=>({key:mK++,provider:e,persisted:t}))}function gK({children:e}){let{t}=K(`agentRuntime`),n=!Oe(),[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||!iG(r))throw Error(r?.message??t(`loadFailed`));e||(i(hK(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:mG(r.map(e=>e.provider),`local`),kind:`openai-compatible`,baseUrl:`http://127.0.0.1:11434/v1`};i([...r,{key:mK++,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:mG(t,`cli`),kind:`cli`,cli:e??`claude`};i([...r,{key:mK++,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||!iG(n))throw Error(n?.message??t(`saveFailed`));if(!_.current)return;i(hK(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=eG.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)(Dn,{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)(ss,{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)(ZG,{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)(Dn,{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)(Dn,{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)(_K,{icon:(0,$.jsx)(wc,{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)(tK,{label:t(`providers.addCli`),align:`right`,trigger:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Dn,{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)(wc,{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)(nK,{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)(_K,{icon:(0,$.jsx)(vc,{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)(vc,{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)(pK,{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)(sn,{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)(Sc,{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)(Wo,{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 _K({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 vK(){let{t:e}=K(`settings`),{registerHandler:t,unregisterHandler:n}=Ze(),[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)(Cn,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(bn,{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)(Cn,{className:`h-3.5 w-3.5 animate-spin`}):s===`done`?(0,$.jsx)(qo,{className:`h-3.5 w-3.5 text-accent-success`}):(0,$.jsx)(uc,{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 yK=class extends dt{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){xK(t);let n=new pt;e&&(n.onmessage=e);let r=await Y(`plugin:updater|download`,{onEvent:n,rid:this.rid,...t});this.downloadedBytes=new dt(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){xK(t);let n=new pt;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 bK(e){xK(e);let t=await Y(`plugin:updater|check`,{...e});return t?new yK(t):null}function xK(e){e?.headers&&(e.headers=Array.from(new Headers(e.headers).entries()))}var SK;(function(e){e.Nsis=`nsis`,e.Msi=`msi`,e.Deb=`deb`,e.Rpm=`rpm`,e.AppImage=`appimage`,e.App=`app`})(SK||={});async function CK(){return Y(`plugin:app|version`)}async function wK(){await Y(`plugin:process|restart`)}var TK=`specrails-desktop:dismissedDesktopUpdateVersion`,EK=`specrails-desktop-desktop-update`,DK=360*60*1e3;function OK(){return typeof window<`u`&&`__TAURI_INTERNALS__`in window}function kK(){return{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1}.VITE_MOCK_DESKTOP_UPDATE===`true`}function AK(){return{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1}.VITE_MOCK_DESKTOP_UPDATE_VERSION||`99.0.0-test`}function jK(e){return new Promise(t=>setTimeout(t,e))}function MK(){return{currentVersion:`1.40.1`,version:AK(),isMock:!0,async downloadAndInstall(e){e({event:`Started`,data:{contentLength:18874368}});for(let t=0;t<12;t+=1)await jK(180),e({event:`Progress`,data:{chunkLength:1572864}});e({event:`Finished`})}}}function NK(e){return e<1024*1024?We.t(`commands:update.units.kb`,{value:Math.max(1,Math.round(e/1024))}):We.t(`commands:update.units.mb`,{value:(e/(1024*1024)).toFixed(1)})}function PK(){try{return localStorage.getItem(TK)}catch{return null}}function FK(e){try{localStorage.setItem(TK,e)}catch{}J.dismiss(EK)}function IK(e){switch(e){case`downloading`:return`var(--color-accent-info)`;case`ready`:return`var(--color-accent-success)`;default:return`var(--color-accent-primary)`}}function LK({state:e}){let t=`h-[15px] w-[15px]`;return e===`installing`?(0,$.jsx)(es,{className:`${t} u-spin`,"aria-hidden":!0}):e===`ready`?(0,$.jsx)(vn,{className:`${t} u-check`,"aria-hidden":!0}):e===`error`?(0,$.jsx)(jn,{className:t,"aria-hidden":!0}):(0,$.jsx)(Qo,{className:t,"aria-hidden":!0})}function RK({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(EK),t?.();return}Y(`restart_app`).catch(()=>{wK()})}let p=s&&s>0?Math.min(100,Math.round(a/s*100)):null,m=IK(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:NK(a)}):n(`update.desc.progress`,{percent:p,downloaded:NK(a),total:NK(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)(LK,{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)(RK,{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(EK),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:()=>{FK(e.version),t?.()},children:n(`update.actions.dismiss`)})]})})]})}function BK(e){J.custom(()=>(0,$.jsx)(zK,{update:e}),{id:EK,duration:1/0,dismissible:!1,unstyled:!0,closeButton:!1})}function VK(){(0,Q.useEffect)(()=>{let e=kK();if(!e&&!OK())return;let t=!1,n={current:!1};async function r(){if(!(t||n.current))try{let r=e?MK():await bK();if(t||!r||PK()===r.version)return;n.current=!0,J.custom(()=>(0,$.jsx)(zK,{update:r,onClose:()=>{n.current=!1}}),{id:EK,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(),DK);return()=>{t=!0,clearInterval(i)}},[])}function HK(){let{t:e}=K(`settings`),t=kK(),n=OK()||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(!OK())return;let e=!0;return CK().then(t=>{e&&i(t)}).catch(()=>{}),()=>{e=!1}},[]);let d=(0,Q.useCallback)(async()=>{o(!0),c(null);try{let n=t?MK():await bK();n?(c(`update-available`),u(n.version),BK(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)(Cn,{className:`h-3.5 w-3.5 animate-spin`}):s===`up-to-date`?(0,$.jsx)(qo,{className:`h-3.5 w-3.5 text-accent-success`}):(0,$.jsx)(uc,{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 UK=Object.defineProperty,WK=Object.getOwnPropertySymbols,GK=Object.prototype.hasOwnProperty,KK=Object.prototype.propertyIsEnumerable,qK=(e,t,n)=>t in e?UK(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,JK=(e,t)=>{for(var n in t||={})GK.call(t,n)&&qK(e,n,t[n]);if(WK)for(var n of WK(t))KK.call(t,n)&&qK(e,n,t[n]);return e},YK=(e,t)=>{var n={};for(var r in e)GK.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&WK)for(var r of WK(e))t.indexOf(r)<0&&KK.call(e,r)&&(n[r]=e[r]);return n},XK;(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})(XK||={}),(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||={})})(XK||={}),(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||={})})(XK||={});var ZK=XK,QK={L:ZK.QrCode.Ecc.LOW,M:ZK.QrCode.Ecc.MEDIUM,Q:ZK.QrCode.Ecc.QUARTILE,H:ZK.QrCode.Ecc.HIGH},$K=128,eq=`L`,tq=`#FFFFFF`,nq=`#000000`,rq=!1,iq=1,aq=4,oq=0,sq=.1;function cq(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 lq(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 uq(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*sq),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 dq(e,t){return t==null?e?aq:oq:Math.max(Math.floor(t),0)}function fq({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(...ZK.QrSegment.makeSegments(t)),e),[]);return ZK.QrCode.encodeSegments(r,QK[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=dq(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:uq(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var pq=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),mq=Q.forwardRef(function(e,t){let n=e,{value:r,size:i=$K,level:a=eq,bgColor:o=tq,fgColor:s=nq,includeMargin:c=rq,minVersion:l=iq,boostLevel:u,marginSize:d,imageSettings:f}=n,p=YK(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=YK(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}=fq({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=lq(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,pq?t.fill(new Path2D(cq(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=JK({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`,JK({style:E,height:i,width:i,ref:y,role:`img`},h)),D)});mq.displayName=`QRCodeCanvas`;var hq=Q.forwardRef(function(e,t){let n=e,{value:r,size:i=$K,level:a=eq,bgColor:o=tq,fgColor:s=nq,includeMargin:c=rq,minVersion:l=iq,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=YK(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=fq({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=lq(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=cq(y,h);return Q.createElement(`svg`,JK({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)});hq.displayName=`QRCodeSVG`;var gq=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 _q(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function vq(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 yq(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 bq(e){let t=new TextEncoder().encode(e),n=await yq(t,new CompressionStream(`deflate-raw`));return n.length<t.length?`D`+_q(n):`R`+_q(t)}async function xq(e){let t=e.trim();if(!t)throw Error(`empty signal token`);let n=vq(t.slice(1));if(t[0]===`D`)return new TextDecoder().decode(await yq(n,new DecompressionStream(`deflate-raw`)));if(t[0]===`R`)return new TextDecoder().decode(n);throw Error(`unknown signal codec tag: ${t[0]}`)}async function Sq(e){return bq(JSON.stringify({k:`offer`,v:2,hub:e.hubInstanceId,name:e.hubName,sdp:e.sdp,sec:e.secret}))}async function Cq(e){try{let t=JSON.parse(await xq(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 wq({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 Cq(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 Sq({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,gq.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)(sr,{open:e,onOpenChange:e=>{e||m()},children:(0,$.jsxs)(ar,{movableResizable:!0,className:`max-w-md`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:r(`pairWeb.title`)}),(0,$.jsx)(Zn,{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)(hq,{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 Tq=typeof navigator<`u`&&/Win/i.test(navigator.platform);function Eq(e){return!e||e.length<16?e??`—`:`${e.slice(0,8)}…${e.slice(-8)}`}function Dq(){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}=Ze();(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)(Cc,{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)(xc,{className:`h-3.5 w-3.5 text-accent-success`}),(0,$.jsx)(`span`,{title:t.certFingerprint??``,children:Eq(t.certFingerprint)}),(0,$.jsx)(`button`,{type:`button`,className:`underline`,onClick:h,disabled:a,children:e(`mobile.reset`)})]})]}),Tq&&(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)(An,{className:`h-4 w-4`})})]},t.id))]})]}),(0,$.jsx)(wq,{open:s,onClose:()=>c(!1),onPaired:u})]}):(0,$.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`})}var Oq=[`claude`,`codex`,`gemini`,`kimi`],kq=[`claude`,`gemini`,`kimi`],Aq=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;function jq(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 Mq(){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(`${Ke}/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(`${Ke}/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 kq)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!==``&&(!Aq.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)(Dn,{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)(jn,{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)(Dn,{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)(An,{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:Oq.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:jq(t),"data-testid":`external-mcp-form-provider-${e}`,children:[t&&(0,$.jsx)(vn,{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)(jn,{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:Oq.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:jq(n),children:[n&&(0,$.jsx)(vn,{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)(wn,{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)(An,{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 Nq(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 Pq(e){return JSON.stringify({mcpServers:{specrails:{command:e.bridgeCommand}}},null,2)}function Fq(){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(`${Ke}/api/mcp-admin/status`);e.ok&&n(await e.json())}catch{}},[]),u=(0,Q.useCallback)(async()=>{try{let e=await fetch(`${Ke}/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(`${Ke}/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(`${Ke}/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 Nq(Pq(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(`${Ke}/api/mcp-admin/token`);if(!t.ok)throw Error(`HTTP ${t.status}`);let{token:n}=await t.json();await Nq(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(`${Ke}/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)(ac,{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)(vn,{className:`h-3 w-3 text-accent-success`}),` `,e(`config.configCopied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(is,{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:Pq(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)(vn,{className:`h-3 w-3 text-accent-success`}),` `,e(`token.tokenCopied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(is,{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)(uc,{className:`h-3 w-3`}),` `,e(`token.regenerate`)]})]})]})]})]}),(0,$.jsx)(Mq,{})]})}var Iq=`specrails-os-notifications`,Lq={enabled:!0,filter:`all`};function Rq(){try{let e=localStorage.getItem(Iq);if(!e)return Lq;let t=JSON.parse(e);return{enabled:typeof t.enabled==`boolean`?t.enabled:Lq.enabled,filter:t.filter===`completed`||t.filter===`failed`?t.filter:Lq.filter}}catch{return Lq}}function zq(e){localStorage.setItem(Iq,JSON.stringify(e))}function Bq({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}=bN(),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),qD({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}=Ze(),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=Rq();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?We.t(`commands:notifications.providerLimitBody`,{provider:s,resetsAt:r}):We.t(`commands:notifications.providerLimitBodyNoReset`,{provider:s}),u=We.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=Rq();if(!i.enabled||i.filter===`completed`)return;let a=Math.max(1,Math.round(n/6e4)),o=t?c.current?.get(t)??``:``,l=We.t(`commands:notifications.jobStuckBody`,{count:a});if(t&&r.includes(`stop`)&&J.warning(We.t(`commands:notifications.jobStuck`),{id:`job-stuck:${e}`,description:o?`[${o}] ${l}`:l,duration:2e4,action:{label:We.t(`commands:notifications.jobStuckStop`),onClick:()=>{g(t,e)}}}),typeof Notification>`u`)return;function u(){let n=new Notification(We.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(We.t(`commands:notifications.jobStuckStopped`),{id:`job-stuck:${t}`})}catch{J.error(We.t(`commands:notifications.jobStuckStopFailed`),{id:`job-stuck:${t}`})}}function _(e,t){if(typeof Notification>`u`||typeof document<`u`&&!document.hidden)return;let n=Rq();if(!n.enabled||n.filter===`completed`&&e.status!==`completed`||n.filter===`failed`&&e.status!==`failed`)return;function r(){let n=e.status===`completed`?We.t(`commands:notifications.jobCompleted`):We.t(`commands:notifications.jobFailed`),r=t?c.current?.get(t)??``:``,i=e.command?e.command.slice(0,80):We.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 Vq=[{value:`job.completed`,labelKey:`webhooks.eventJobCompleted`},{value:`job.failed`,labelKey:`webhooks.eventJobFailed`},{value:`daily_budget_exceeded`,labelKey:`webhooks.eventDailyBudgetExceeded`}];function Hq({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 Uq=[{id:`appearance`,icon:Xs,labelKey:`desktop.nav.appearance`},{id:`effects`,icon:kn,labelKey:`desktop.nav.effects`},{id:`specrailsAgents`,icon:ss,labelKey:`desktop.nav.specrailsAgents`},{id:`code`,icon:$o,labelKey:`desktop.nav.code`},{id:`terminal`,icon:wc,labelKey:`desktop.nav.terminal`},{id:`updates`,icon:uc,labelKey:`desktop.nav.updates`},{id:`mobile`,icon:Cc,labelKey:`desktop.nav.mobile`},{id:`mcp`,icon:Fo,labelKey:`desktop.nav.mcp`},{id:`projects`,icon:bs,labelKey:`desktop.nav.projects`},{id:`advanced`,icon:Sc,labelKey:`desktop.nav.advanced`},{id:`webhooks`,icon:Pc,labelKey:`desktop.nav.webhooks`},{id:`about`,icon:Ns,labelKey:`desktop.nav.about`}];function Wq({open:e,onClose:t,onOpenOnboarding:n}){let{t:r}=K(`settings`),{projects:i,removeProject:a}=lt(),[o,s]=(0,Q.useState)(`appearance`),c=e=>X(`space-y-5`,o===e?``:`hidden`),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(!0),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)([]),[C,w]=(0,Q.useState)(``),[T,E]=(0,Q.useState)(``),[D,O]=(0,Q.useState)([`job.completed`,`job.failed`]),[k,A]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(()=>Rq().enabled),[N,P]=(0,Q.useState)(()=>Rq().filter);function F(e){M(e),zq({enabled:e,filter:N}),J.success(r(e?`notifications.enabledToast`:`notifications.disabledToast`))}function I(e){P(e),zq({enabled:j,filter:e})}let L=(0,Q.useCallback)(async()=>{try{let e=await fetch(`/api/webhooks`);if(e.ok){let t=await e.json();S(t.webhooks)}}catch{}},[]);(0,Q.useEffect)(()=>{if(!e)return;f(!0);async function t(){try{let e=await fetch(`/api/settings`);if(e.ok){let t=await e.json();u(t),m(t.costAlertThresholdUsd==null?``:String(t.costAlertThresholdUsd))}}catch{}finally{f(!1)}}t(),L()},[e,L]),(0,Q.useEffect)(()=>{e&&fetch(`/api/budget`).then(e=>e.json()).then(e=>{e.desktopDailyBudgetUsd==null?v(``):v(String(e.desktopDailyBudgetUsd))}).catch(()=>{})},[e]);async function ee(){g(!0);try{let e=p.trim()===``?null:parseFloat(p);if(e!==null&&(isNaN(e)||e<=0)){J.error(r(`budget.invalidNumber`));return}(await fetch(`/api/settings`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({costAlertThresholdUsd:e})})).ok?J.success(e==null?r(`desktop.costAlertsDisabled`):r(`budget.alertSet`,{amount:e})):J.error(r(`budget.saveThresholdFailed`))}catch{J.error(r(`budget.saveThresholdFailed`))}finally{g(!1)}}async function R(){b(!0);try{let e=_.trim()===``?null:parseFloat(_);if(e!==null&&(isNaN(e)||e<=0)){J.error(r(`budget.invalidNumber`));return}(await fetch(`/api/budget`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({desktopDailyBudgetUsd:e})})).ok?J.success(e==null?r(`desktop.dailyBudgetRemoved`):r(`desktop.dailyBudgetSet`,{amount:e})):J.error(r(`desktop.dailyBudgetSaveFailed`))}catch{J.error(r(`desktop.dailyBudgetSaveFailed`))}finally{b(!1)}}async function z(e){try{await a(e),J.success(r(`desktop.projectRemoved`))}catch(e){J.error(r(`desktop.projectRemoveFailed`),{description:e.message})}}async function B(){if(!C.trim()){J.error(r(`webhooks.urlRequired`));return}if(D.length===0){J.error(r(`webhooks.selectEvent`));return}A(!0);try{let e=await fetch(`/api/webhooks`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({url:C.trim(),secret:T.trim(),events:D})});if(e.ok)J.success(r(`webhooks.added`)),w(``),E(``),O([`job.completed`,`job.failed`]),await L();else{let t=await e.json();J.error(t.error??r(`webhooks.addFailed`))}}catch{J.error(r(`webhooks.addFailed`))}finally{A(!1)}}async function V(e,t){try{await fetch(`/api/webhooks/${e}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:t})}),await L()}catch{J.error(r(`webhooks.updateFailed`))}}async function H(e){try{(await fetch(`/api/webhooks/${e}`,{method:`DELETE`})).ok&&(J.success(r(`webhooks.removed`)),await L())}catch{J.error(r(`webhooks.removeFailed`))}}async function U(e){try{(await fetch(`/api/webhooks/${e}/test`,{method:`POST`})).ok&&J.success(r(`webhooks.testPingSent`))}catch{J.error(r(`webhooks.testPingFailed`))}}function te(e){O(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}return(0,$.jsx)(sr,{open:e,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(ar,{movableResizable:!0,className:`flex max-w-5xl w-[92vw] h-[82vh] flex-col overflow-hidden`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsxs)(er,{className:`flex items-center gap-2`,children:[(0,$.jsx)(yc,{className:`w-4 h-4`}),r(`desktop.title`)]}),(0,$.jsx)(Zn,{children:r(`desktop.description`)})]}),d?(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:Uq.map(e=>{if(e.id===`mcp`&&!fe)return null;let t=e.icon;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>s(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`,o===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:r(e.labelKey)})]},e.id)})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-y-auto pr-1`,children:[(0,$.jsxs)(`div`,{className:c(`appearance`),children:[(0,$.jsx)(BG,{}),(0,$.jsx)(JG,{})]}),(0,$.jsx)(`div`,{className:c(`effects`),children:(0,$.jsx)(RG,{})}),(0,$.jsx)(`div`,{className:c(`specrailsAgents`),children:(0,$.jsx)(gK,{children:(0,$.jsx)(LG,{})})}),(0,$.jsx)(`div`,{className:c(`code`),children:(0,$.jsx)(YG,{})}),(0,$.jsxs)(`div`,{className:c(`updates`),children:[(0,$.jsx)(HK,{}),(0,$.jsx)(vK,{})]}),(0,$.jsx)(`div`,{className:c(`mobile`),children:(0,$.jsx)(Dq,{})}),fe&&(0,$.jsx)(`div`,{className:c(`mcp`),children:(0,$.jsx)(Fq,{})}),(0,$.jsx)(`div`,{className:c(`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:r(`desktop.registeredProjects`)}),i.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:r(`desktop.noProjects`)})}):(0,$.jsx)(`div`,{className:`space-y-1.5`,children:i.map(e=>(0,$.jsx)(Hq,{project:e,onRemove:z},e.id))})]})}),(0,$.jsxs)(`div`,{className:c(`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:r(`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:r(`desktop.dailyBudgetLabel`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:r(`desktop.dailyBudgetHelper`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Ij,{type:`number`,min:`0`,step:`0.01`,value:_,onChange:e=>v(e.target.value),placeholder:r(`desktop.dailyBudgetPlaceholder`),className:`h-7 text-xs font-mono`}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs shrink-0`,disabled:y,onClick:()=>void R(),children:r(`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:r(`budget.perJobLabel`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:r(`desktop.perJobHelper`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Ij,{type:`number`,min:`0`,step:`0.01`,value:p,onChange:e=>m(e.target.value),placeholder:r(`budget.perJobPlaceholder`),className:`h-7 text-xs font-mono`}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs shrink-0`,disabled:h,onClick:ee,children:r(`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:r(`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:r(`notifications.description`)}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:j,onChange:e=>F(e.target.checked),className:`w-3.5 h-3.5`,"data-testid":`notif-toggle`}),(0,$.jsx)(No,{className:`w-3.5 h-3.5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`text-xs`,children:r(`notifications.enableLabel`)})]}),j&&(0,$.jsxs)(`div`,{className:`space-y-1.5 pl-6`,children:[(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:r(`notifications.notifyOn`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:[{value:`all`,label:r(`notifications.filterAll`)},{value:`completed`,label:r(`notifications.filterCompleted`)},{value:`failed`,label:r(`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:N===e,onChange:()=>I(e),className:`w-3 h-3`}),t]},e))})]})]})]})]}),(0,$.jsx)(`div`,{className:c(`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:r(`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)(at,{ns:`settings`,i18nKey:`webhooks.description`,components:{code:(0,$.jsx)(`code`,{className:`font-mono`})}})}),x.length>0&&(0,$.jsx)(`div`,{className:`space-y-1.5`,children:x.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 V(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?r(`webhooks.disable`):r(`webhooks.enable`),children:e.enabled?r(`webhooks.statusOn`):r(`webhooks.statusOff`)}),(0,$.jsx)(`button`,{onClick:()=>void U(e.id),className:`text-muted-foreground hover:text-foreground p-0.5`,title:r(`webhooks.sendTestPing`),children:(0,$.jsx)(Pn,{className:`w-3 h-3`})}),(0,$.jsx)(`button`,{onClick:()=>void H(e.id),className:`text-muted-foreground hover:text-destructive p-0.5`,title:r(`common:actions.remove`),children:(0,$.jsx)(An,{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:r(`webhooks.addHeading`)}),(0,$.jsx)(Ij,{value:C,onChange:e=>w(e.target.value),placeholder:`https://hooks.example.com/...`,className:`h-7 text-xs font-mono`}),(0,$.jsx)(Ij,{value:T,onChange:e=>E(e.target.value),placeholder:r(`webhooks.secretPlaceholder`),className:`h-7 text-xs font-mono`}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:Vq.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:D.includes(e),onChange:()=>te(e),className:`w-3 h-3`}),r(t)]},e))}),(0,$.jsxs)(Z,{size:`sm`,variant:`secondary`,className:`h-7 text-xs w-full`,disabled:k||!C.trim(),onClick:()=>void B(),children:[(0,$.jsx)(Dn,{className:`w-3 h-3 mr-1`}),r(`webhooks.addButton`)]})]})]})]})}),(0,$.jsx)(`div`,{className:c(`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:r(`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:r(`desktop.platformTour`)}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:r(`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)(Es,{className:`w-3 h-3 mr-1`}),r(`desktop.replayTour`)]})]})})]})}),(0,$.jsx)(`div`,{className:c(`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:r(`desktop.terminalPanelHeading`)}),(0,$.jsx)(OW,{mode:`desktop`})]})}),(0,$.jsx)(`div`,{className:c(`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:r(`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:r(`desktop.infoPort`)}),(0,$.jsx)(`span`,{className:`font-mono`,children:l?.port??4200})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:r(`desktop.infoProjects`)}),(0,$.jsx)(`span`,{className:`font-mono`,children:i.length})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:r(`desktop.infoDb`)}),(0,$.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:`~/.specrails/desktop.sqlite`})]})]})]})})]})]})]})})}var Gq=[{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`},...F?[{keys:`⌘⇧A`,descriptionKey:`shortcuts.items.toggleAgent`,category:`general`}]:[],{keys:H?`⌘1–5`:`⌘1–4`,descriptionKey:H?`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 Kq(e){let t=e.target;if(!t)return!1;let n=t.tagName;return!!(n===`INPUT`||n===`TEXTAREA`||n===`SELECT`||t.isContentEditable)}function qq(e){let t=e.target;return!t||typeof t.closest!=`function`?!1:!!t.closest(`[role="dialog"]`)}function Jq(e){let t=e.target;return!t||typeof t.closest!=`function`?!1:!!t.closest(`.specrails-xterm-container, .xterm`)}function Yq({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(qq(e))return;e.preventDefault(),b.current?.();return}if((e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&e.code===`KeyA`){if(qq(e))return;e.preventDefault(),x.current?.();return}if(Kq(e)||Jq(e)||qq(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 Xq(){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 Zq={general:`shortcuts.categories.general`,navigation:`shortcuts.categories.navigation`,actions:`shortcuts.categories.actions`},Qq=[`general`,`navigation`,`actions`];function $q({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 eJ({shortcut:e}){let{t}=K(`commands`),n=nW(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)($q,{children:e},t))})]})}function tJ({open:e,onOpenChange:t}){let{t:n}=K(`commands`),r=Qq.map(e=>({category:e,label:n(Zq[e]),shortcuts:Gq.filter(t=>t.category===e)})).filter(e=>e.shortcuts.length>0);return(0,$.jsx)(sr,{open:e,onOpenChange:t,children:(0,$.jsxs)(ar,{movableResizable:!0,className:`max-w-md`,"data-testid":`shortcuts-cheatsheet`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:n(`shortcuts.title`)}),(0,$.jsx)(Zn,{children:(0,$.jsxs)(at,{i18nKey:`shortcuts.subtitle`,ns:`commands`,children:[`Press `,(0,$.jsx)($q,{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)(eJ,{shortcut:e},e.keys))})]},e.category))})]})})}function nJ(){return typeof window<`u`&&`__TAURI_INTERNALS__`in window}function rJ(){return nJ()&&/mac/i.test(navigator.platform)}function iJ({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 aJ({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)(On,{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 oJ(){return nJ()?rJ()?(0,$.jsx)(sJ,{}):(0,$.jsx)(cJ,{}):null}function sJ(){let{projects:e,activeProjectId:t}=lt(),{uiMode:n}=bN();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)(aJ,{projectName:(e.find(e=>e.id===t)??null)?.name??null,hidden:n===`agent`})})}function cJ(){let{t:e}=K(`nav`),{projects:t,activeProjectId:n}=lt(),{uiMode:r}=bN(),i=t.find(e=>e.id===n)??null,a=(0,Q.useMemo)(()=>aP(),[]),[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)(aJ,{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)(iJ,{onClick:c,icon:(0,$.jsx)(Gs,{size:14,strokeWidth:1.8}),ariaLabel:e(`titleBar.minimizeWindow`)}),(0,$.jsx)(iJ,{onClick:l,icon:o?(0,$.jsx)(is,{size:12,strokeWidth:1.8}):(0,$.jsx)(En,{size:12,strokeWidth:1.8}),ariaLabel:e(o?`titleBar.restoreWindow`:`titleBar.maximizeWindow`)}),(0,$.jsx)(iJ,{onClick:u,icon:(0,$.jsx)(Nn,{size:15,strokeWidth:1.8}),hoverColor:`var(--color-destructive)`,hoverTextColor:`var(--color-destructive-foreground)`,ariaLabel:e(`titleBar.closeWindow`)})]})]})}var lJ=`アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン0123456789ABCDEF`,uJ=16,dJ=uJ,fJ=uJ*1.1,pJ=180,mJ=340,hJ=.07,gJ=.22,_J=18,vJ=600,yJ=48,bJ=160,xJ=360;function SJ(){return lJ[Math.floor(Math.random()*61)]??` `}function CJ(e){return{head:-Math.random()*Math.max(e,12),speed:hJ+Math.random()*(gJ-hJ),glyphs:Array.from({length:_J},()=>SJ()),nextSwapAt:0}}function wJ(){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=`${uJ}px "DM Mono", "JetBrains Mono", "Fira Code", ui-monospace, monospace`,i.textBaseline=`top`;let o=Math.ceil(t/dJ),s=Math.ceil(n/fJ);if(a.length===0)a=Array.from({length:o},()=>CJ(s));else if(a.length<o){let e=Array.from({length:o-a.length},()=>CJ(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>yJ&&s.splice(0,s.length-yJ)),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>vJ;)s.shift();let r=window.innerWidth,d=window.innerHeight;i.clearRect(0,0,r,d);let f=Math.ceil(d/fJ),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-_J>f+4&&(c.head=-Math.random()*12,c.speed=hJ+Math.random()*(gJ-hJ)),e>c.nextSwapAt&&(c.glyphs[Math.floor(Math.random()*_J)]=SJ(),c.nextSwapAt=e+bJ+Math.random()*xJ),!p)continue;let l=r*dJ+dJ/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>mJ))for(let e=0;e<_J;e++){let t=c.head-e;if(t<-1||t>f+2)continue;let a=t*fJ,u=0;if(o!==null){let e=l-o.x,t=a-o.y,n=Math.sqrt(e*e+t*t);if(n<=mJ){let e=n<pJ?1:1-(n-pJ)/(mJ-pJ);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>mJ)continue;let o=i<pJ?1:1-(i-pJ)/(mJ-pJ),s=n-e.t,c=o*(s>vJ?0:1-s/vJ);if(c>u&&(u=c),u>=.999)break}if(u<.02)continue;let d=1-e/_J,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*dJ,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 TJ=24,EJ=200,DJ=3.5,OJ=10,kJ=`hsl(210, 60%, 96%)`,AJ=`hsl(212, 100%, 62%)`;function jJ(){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>TJ&&a.splice(0,a.length-TJ)}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>EJ;)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=AJ;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/EJ);if(s<=0)continue;let c=t/a.length;i.globalAlpha=s*(.25+.75*c),i.lineWidth=Math.max(.5,DJ*c),i.shadowBlur=OJ*c,i.strokeStyle=c>.6?kJ:AJ,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 MJ={"code-rain":wJ,galaxy:jJ};function NJ(){let e=MJ[_a().id];return e?(0,$.jsx)(e,{}):null}function PJ({project:e}){let{t}=K(`nav`),n=VV(),{registerHandler:r,unregisterHandler:i}=Ze(),[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)($k,{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 FJ({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)(at,{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)(uc,{className:`w-3.5 h-3.5`}),r(`common:actions.retry`)]})]})}var IJ=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)(FJ,{projectName:this.props.projectName,errorMessage:this.state.error?.message??null,onRetry:this.handleRetry}):this.props.children}};function LJ({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)(Oc,{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)(at,{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`)}),De&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 max-w-sm`,children:t(`welcome.jiraHint`)}),fe&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 max-w-sm`,children:t(`welcome.mcpHint`)}),F&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground/80 max-w-sm`,children:t(`welcome.agentChatHint`)}),ve&&(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)(bs,{className:`w-3.5 h-3.5`}),t(`welcome.addFirstProject`)]})]})}var RJ=`https://specrails.dev/companion-app`,zJ=`specrails-desktop:onboarding-dismissed`;function BJ(){try{return localStorage.getItem(zJ)===`true`}catch{return!1}}function VJ(){try{localStorage.setItem(zJ,`true`)}catch{}}var HJ=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform||``),UJ=HJ?`⌘`:`Ctrl`,WJ=HJ?`⌥`:`Alt`,GJ={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 KJ({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 qJ({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 JJ({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 YJ({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)(B,{className:`w-3.5 h-3.5 text-muted-foreground`})]},t.label))})}function XJ(){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)(qG,{}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:e(`onboarding.language.note`)})]})}function ZJ(){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 QJ({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)(hq,{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)(ln,{className:`w-3 h-3 shrink-0`,"aria-hidden":`true`})]})]})]})}function $J(){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)(at,{t:e,i18nKey:`onboarding.companion.intro`,components:{b:(0,$.jsx)(`span`,{className:`text-foreground font-medium`})}})}),(0,$.jsx)(JJ,{accent:GJ.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)(QJ,{icon:(0,$.jsx)(Cc,{className:`w-4 h-4 shrink-0`,"aria-hidden":`true`}),url:RJ,label:e(`onboarding.companion.open`),testId:`companion-web-link`})]}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(sc,{className:`w-4 h-4`}),label:e(`onboarding.companion.pairLabel`),accent:GJ.success,children:e(`onboarding.companion.pairBody`)})]})}function eY(e){let t={b:(0,$.jsx)(`span`,{className:`text-foreground font-medium`})};return[{navLabel:e(`onboarding.language.nav`),icon:(0,$.jsx)(Fs,{className:`w-6 h-6`}),accent:GJ.info,title:e(`onboarding.language.title`),subtitle:e(`onboarding.language.subtitle`),content:(0,$.jsx)(XJ,{})},{navLabel:e(`onboarding.theme.nav`),icon:(0,$.jsx)(Xs,{className:`w-6 h-6`}),accent:GJ.highlight,title:e(`onboarding.theme.title`),subtitle:e(`onboarding.theme.subtitle`),content:(0,$.jsx)(ZJ,{})},{navLabel:e(`onboarding.welcome.nav`),icon:(0,$.jsx)(kn,{className:`w-6 h-6`}),accent:GJ.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)(at,{t:e,i18nKey:`onboarding.welcome.intro`,components:t})}),(0,$.jsxs)(JJ,{accent:GJ.primary,label:e(`onboarding.welcome.coreLoopLabel`),children:[(0,$.jsx)(YJ,{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)(at,{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)(qJ,{icon:(0,$.jsx)(Fo,{className:`w-4 h-4`}),label:e(`onboarding.welcome.missionLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.welcome.missionBody`,components:t})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Ls,{className:`w-4 h-4`}),label:e(`onboarding.welcome.boardLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.welcome.boardBody`,components:t})})]}),(0,$.jsxs)(`div`,{className:`flex gap-3 items-start`,children:[(0,$.jsx)(xc,{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)(at,{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`)})]})},...F?[{navLabel:e(`onboarding.mission.nav`),icon:(0,$.jsx)(Fo,{className:`w-6 h-6`}),accent:GJ.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)(at,{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)(qJ,{icon:(0,$.jsx)(S,{className:`w-4 h-4`}),label:e(`onboarding.mission.missionsLabel`),accent:GJ.primary,children:e(`onboarding.mission.missionsBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(xc,{className:`w-4 h-4`}),label:e(`onboarding.mission.levelsLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.mission.levelsBody`,components:{...t,shift:(0,$.jsx)(KJ,{children:`Shift`}),tab:(0,$.jsx)(KJ,{children:`Tab`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Is,{className:`w-4 h-4`}),label:e(`onboarding.mission.cardsLabel`),accent:GJ.primary,children:e(`onboarding.mission.cardsBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Io,{className:`w-4 h-4`}),label:e(`onboarding.mission.workspaceLabel`),accent:GJ.primary,children:e(`onboarding.mission.workspaceBody`)})]}),(0,$.jsx)(JJ,{accent:GJ.primary,label:e(`onboarding.mission.mcpLabel`),children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.mission.mcpBody`,components:t})})]})}]:[],...Te?[{navLabel:e(`onboarding.builder.nav`),icon:(0,$.jsx)(Os,{className:`w-6 h-6`}),accent:GJ.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)(at,{t:e,i18nKey:`onboarding.builder.intro`,components:t})}),(0,$.jsxs)(JJ,{accent:GJ.highlight,label:e(`onboarding.builder.flowLabel`),children:[(0,$.jsx)(YJ,{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)(qJ,{icon:(0,$.jsx)(Nc,{className:`w-4 h-4`}),label:e(`onboarding.builder.cardsLabel`),accent:GJ.highlight,children:e(`onboarding.builder.cardsBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(hs,{className:`w-4 h-4`}),label:e(`onboarding.builder.specsLabel`),accent:GJ.highlight,children:e(`onboarding.builder.specsBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(fc,{className:`w-4 h-4`}),label:e(`onboarding.builder.milestonesLabel`),accent:GJ.highlight,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.builder.milestonesBody`,components:t})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Ss,{className:`w-4 h-4`}),label:e(`onboarding.builder.progressLabel`),accent:GJ.highlight,children:e(`onboarding.builder.progressBody`)})]})]})}]:[],{navLabel:e(`onboarding.authorSpecs.nav`),icon:(0,$.jsx)(S,{className:`w-6 h-6`}),accent:GJ.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)(at,{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)(qJ,{icon:(0,$.jsx)(Fo,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.agentLabel`),accent:GJ.info,children:e(`onboarding.authorSpecs.agentBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(S,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.exploreLabel`),accent:GJ.info,children:e(`onboarding.authorSpecs.exploreBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Pn,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.quickLabel`),accent:GJ.info,children:e(`onboarding.authorSpecs.quickBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(D,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.websiteLabel`),accent:GJ.info,children:e(`onboarding.authorSpecs.websiteBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(hc,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.smashLabel`),accent:GJ.info,children:e(`onboarding.authorSpecs.smashBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(sn,{className:`w-4 h-4`}),label:e(`onboarding.authorSpecs.draftsLabel`),accent:GJ.info,children:e(`onboarding.authorSpecs.draftsBody`)})]}),De&&(0,$.jsx)(JJ,{accent:GJ.info,label:e(`onboarding.jira.label`),children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.jira.body`,components:t})})]})},{navLabel:e(`onboarding.rails.nav`),icon:(0,$.jsx)(Fc,{className:`w-6 h-6`}),accent:GJ.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)(at,{t:e,i18nKey:`onboarding.rails.intro`,components:{...t,play:(0,$.jsx)(`span`,{className:`text-accent-warning font-medium`})}})}),(0,$.jsxs)(JJ,{accent:GJ.success,label:e(`onboarding.rails.jobLabel`),children:[(0,$.jsx)(YJ,{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)(qJ,{icon:(0,$.jsx)(Sn,{className:`w-4 h-4`}),label:e(`onboarding.rails.reviewLabel`),accent:GJ.success,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.rails.reviewBody`,components:t})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(ps,{className:`w-4 h-4`}),label:e(`onboarding.rails.packetLabel`),accent:GJ.success,children:e(`onboarding.rails.packetBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(S,{className:`w-4 h-4`}),label:e(`onboarding.rails.steerLabel`),accent:GJ.success,children:e(`onboarding.rails.steerBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(dc,{className:`w-4 h-4`}),label:e(`onboarding.rails.loopsLabel`),accent:GJ.success,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.rails.loopsBody`,components:t})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Fo,{className:`w-4 h-4`}),label:e(`onboarding.rails.profilesLabel`),accent:GJ.success,children:e(`onboarding.rails.profilesBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(bs,{className:`w-4 h-4`}),label:e(`onboarding.rails.isolationLabel`),accent:GJ.success,children:e(`onboarding.rails.isolationBody`)})]})]})},{navLabel:e(`onboarding.providers.nav`),icon:(0,$.jsx)(Fo,{className:`w-6 h-6`}),accent:GJ.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)(at,{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)(JJ,{accent:GJ.secondary,label:e(`onboarding.providers.calloutLabel`),children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.providers.calloutBody`,components:{...t,mono:(0,$.jsx)(`span`,{className:`font-mono`})}})})]})},{navLabel:e(`onboarding.cost.nav`),icon:(0,$.jsx)(ts,{className:`w-6 h-6`}),accent:GJ.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)(at,{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)(qJ,{icon:(0,$.jsx)(Ss,{className:`w-4 h-4`}),label:e(`onboarding.cost.analyticsLabel`),accent:GJ.warning,children:e(`onboarding.cost.analyticsBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(lc,{className:`w-4 h-4`}),label:e(`onboarding.cost.perTicketLabel`),accent:GJ.warning,children:e(`onboarding.cost.perTicketBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(us,{className:`w-4 h-4`}),label:e(`onboarding.cost.honestLabel`),accent:GJ.warning,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.cost.honestBody`,components:{mono:(0,$.jsx)(`span`,{className:`font-mono`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Mc,{className:`w-4 h-4`}),label:e(`onboarding.cost.budgetsLabel`),accent:GJ.warning,children:e(`onboarding.cost.budgetsBody`)})]})]})},{navLabel:e(`onboarding.workspace.nav`),icon:(0,$.jsx)(Io,{className:`w-6 h-6`}),accent:GJ.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)(qJ,{icon:(0,$.jsx)(Oc,{className:`w-4 h-4`}),label:e(`onboarding.workspace.terminalLabel`),accent:GJ.highlight,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.workspace.terminalBody`,values:{mod:UJ},components:{mod:(0,$.jsx)(KJ,{children:UJ}),j:(0,$.jsx)(KJ,{children:`J`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(hs,{className:`w-4 h-4`}),label:e(`onboarding.workspace.codeLabel`),accent:GJ.highlight,children:e(`onboarding.workspace.codeBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(D,{className:`w-4 h-4`}),label:e(`onboarding.workspace.browserLabel`),accent:GJ.highlight,children:e(`onboarding.workspace.browserBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(ac,{className:`w-4 h-4`}),label:e(`onboarding.workspace.integrationsLabel`),accent:GJ.highlight,children:e(`onboarding.workspace.integrationsBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Xs,{className:`w-4 h-4`}),label:e(`onboarding.workspace.themesLabel`),accent:GJ.highlight,children:e(`onboarding.workspace.themesBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Is,{className:`w-4 h-4`}),label:e(`onboarding.workspace.chatsLabel`),accent:GJ.highlight,children:e(`onboarding.workspace.chatsBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Se,{className:`w-4 h-4`}),label:e(`onboarding.workspace.compareLabel`),accent:GJ.highlight,children:e(`onboarding.workspace.compareBody`)}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(fc,{className:`w-4 h-4`}),label:e(`onboarding.workspace.desktopLabel`),accent:GJ.highlight,children:e(`onboarding.workspace.desktopBody`)})]})})},{navLabel:e(`onboarding.companion.nav`),icon:(0,$.jsx)(Cc,{className:`w-6 h-6`}),accent:GJ.success,title:e(`onboarding.companion.title`),subtitle:e(`onboarding.companion.subtitle`),content:(0,$.jsx)($J,{})},{navLabel:e(`onboarding.moveFast.nav`),icon:(0,$.jsx)(rs,{className:`w-6 h-6`}),accent:GJ.primary,title:e(`onboarding.moveFast.title`),subtitle:e(`onboarding.moveFast.subtitle`),content:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(JJ,{accent:GJ.primary,label:e(`onboarding.moveFast.paletteLabel`),children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.paletteShortcut`,values:{mod:UJ},components:{f:(0,$.jsx)(`span`,{className:`text-foreground`}),m:(0,$.jsx)(`span`,{className:`text-muted-foreground`}),mod:(0,$.jsx)(KJ,{children:UJ}),k:(0,$.jsx)(KJ,{children:`K`})}})}),e(`onboarding.moveFast.paletteBody`)]}),(0,$.jsxs)(`div`,{className:`grid sm:grid-cols-2 gap-x-5 gap-y-3`,children:[(0,$.jsx)(qJ,{icon:(0,$.jsx)(Fo,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.agentLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.agentBody`,values:{mod:UJ},components:{mod:(0,$.jsx)(KJ,{children:UJ}),shift:(0,$.jsx)(KJ,{children:`Shift`}),a:(0,$.jsx)(KJ,{children:`A`}),tab:(0,$.jsx)(KJ,{children:`Tab`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Oc,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.terminalLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.terminalBody`,values:{mod:UJ},components:{mod:(0,$.jsx)(KJ,{children:UJ}),j:(0,$.jsx)(KJ,{children:`J`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(Ps,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.shortcutsLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.shortcutsBody`,components:{q:(0,$.jsx)(KJ,{children:`?`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(S,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.chatLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.chatBody`,values:{mod:UJ},components:{mod:(0,$.jsx)(KJ,{children:UJ}),bkey:(0,$.jsx)(KJ,{children:`B`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(bs,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.projectsLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.projectsBody`,values:{alt:WJ,mod:UJ},components:{alt:(0,$.jsx)(KJ,{children:WJ}),mod:(0,$.jsx)(KJ,{children:UJ}),bkey:(0,$.jsx)(KJ,{children:`B`})}})}),(0,$.jsx)(qJ,{icon:(0,$.jsx)(rs,{className:`w-4 h-4`}),label:e(`onboarding.moveFast.pagesLabel`),accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.pagesBody`,values:{alt:WJ,mod:UJ},components:{alt:(0,$.jsx)(KJ,{children:WJ}),mod:(0,$.jsx)(KJ,{children:UJ}),n:(0,$.jsx)(KJ,{children:`1–9`})}})})]}),(0,$.jsx)(JJ,{accent:GJ.primary,children:(0,$.jsx)(at,{t:e,i18nKey:`onboarding.moveFast.outro`,components:t})})]})}]}function tY({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)(()=>eY(n),[n]),c=s[r],l=r===0,u=r===s.length-1,d=(0,Q.useCallback)(()=>{a&&VJ(),i(0),t()},[a,t]),f=(0,Q.useCallback)(()=>{VJ(),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)(ir,{open:e,onOpenChange:e=>{e||d()},children:(0,$.jsxs)(Jn,{children:[(0,$.jsx)(qn,{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)(cr,{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)(vn,{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)(tr,{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)(on,{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)(B,{className:`w-3.5 h-3.5 ml-1`})]})]})]})]})]})]})]})})}function nY(){let[e,t]=(0,Q.useState)(new Map),n=(0,Q.useContext)($e);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(`${Ke}/api/projects/${e}/assemble-retry`,{method:`POST`})},[])}}var rY=(0,Q.lazy)(()=>c(()=>import(`./ProjectSettingsDialog-JQdLwCy2.js`).then(e=>({default:e.ProjectSettingsDialog})),__vite__mapDeps([86,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,55,65,51,66,67]))),iY=`specrails-desktop:agentTreeExpanded`;function aY(){try{let e=localStorage.getItem(iY);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 oY(e){try{localStorage.setItem(iY,JSON.stringify([...e]))}catch{}}function sY(){window.dispatchEvent(new KeyboardEvent(`keydown`,{key:`k`,metaKey:!0,ctrlKey:!0,bubbles:!0}))}var cY=`__home__`,lY=`__favorites__`;function uY({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)(S,{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:qb(e.updated_at),children:Kb(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)(ks,{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)(Nn,{className:`w-2.5 h-2.5`})})]})]})}function dY({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)(bs,{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)(Wo,{className:`w-3.5 h-3.5`}):(0,$.jsx)(Go,{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)(yc,{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)(Nn,{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)(uY,{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 fY={"pinned-open":`sidebarPin.left.pinnedOpen`,"pinned-collapsed":`sidebarPin.left.pinnedCollapsed`,unpinned:`sidebarPin.left.unpinned`};function pY({onAddProject:e,onOpenLoops:t,onOpenPlugins:n,onOpenAnalytics:r,onOpenDocs:i,onOpenSettings:a}){let{t:o}=K(`nav`),{t:s}=K(`agent`),{projects:c,activeProjectId:l,setActiveProjectId:u,removeProject:d}=lt(),f=nY(),m=y(),h=p(),g=h.pathname.startsWith(`/loops`),_=h.pathname.startsWith(`/plugins`),v=g||_||h.pathname.startsWith(`/docs`),{leftMode:x,cycleLeftMode:S}=RP(),{uiMode:C,toggleUiMode:w}=bN(),T=qN(),E=C===`agent`,D=(0,Q.useMemo)(()=>{let e=new Map,t=new Set(c.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:cY,i=e.get(r);i?i.push(n):e.set(r,[n])}return e},[T.conversations,T.favoriteConversationIds,c]),O=(0,Q.useMemo)(()=>T.conversations.filter(e=>T.favoriteConversationIds.has(e.id)),[T.conversations,T.favoriteConversationIds]),k=D.get(cY)??[],[A,j]=(0,Q.useState)(aY),M=A.has(lY),[N,P]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{!E||!l||j(e=>{if(e.has(l))return e;let t=new Set(e);return t.add(l),oY(t),t})},[E,l]);let F=e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),oY(n),n})},I=e=>{T.selectConversation(e),v&&m(`/`)},L=e=>{T.deleteConversation(e).catch(()=>{})},ee=e=>{T.toggleFavoriteConversation(e)};function R(e){if(E){u(e),F(e);return}if(e===l){v&&m(`/`);return}u(e)}let[z,B]=(0,Q.useState)(!1),V=x===`pinned-open`||x===`unpinned`&&z,H=DP(`left-arc`,{side:`left`,defaultWidth:240,min:200,max:460,collapsedWidth:44,expanded:V}),U=x!==`unpinned`,te=o(fY[x]),ne=[{label:o(`arcSidebar.docs`),icon:Po,action:i},{label:o(`arcSidebar.analytics`),icon:Vo,action:r},{label:o(`arcSidebar.settings`),icon:yc,action:a}];async function re(e){try{await d(e.id)}catch{}}return(0,$.jsxs)(`div`,{ref:H.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`&&B(!0)},onMouseLeave:()=>{x===`unpinned`&&!H.dragging&&B(!1)},children:[V&&(0,$.jsx)(OP,{side:`left`,dragging:H.dragging,width:H.width,min:200,max:460,label:o(`arcSidebar.resize`,{defaultValue:`Resize sidebar`}),onPointerDown:H.onGripPointerDown,onKeyDown:H.onGripKeyDown}),(0,$.jsxs)(`div`,{className:X(`flex items-center h-12 border-b border-border flex-shrink-0`,V?`px-3 justify-between`:`justify-center`),children:[V&&(0,$.jsx)(`span`,{className:`font-mono text-sm font-bold whitespace-nowrap overflow-hidden text-accent-primary`,children:o(`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`,U?`text-foreground bg-muted`:`text-muted-foreground/40 hover:text-muted-foreground hover:bg-muted/50`),"aria-label":te,title:o(`sidebarPin.withShortcut`,{label:te,shortcut:nW(`⌥⌘B`)}),children:(0,$.jsx)(Zs,{className:`w-4 h-4`})})]}),b&&(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(l),v&&m(`/`)},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`,V?`px-2`:`px-0 justify-center`),"aria-label":s(`newAgent`),title:V?void 0:s(`newAgent`),children:[(0,$.jsx)(Dn,{className:`w-4 h-4 flex-shrink-0`}),V&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:s(`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`,V?`px-2`:`px-0 justify-center`),"aria-label":s(E?`switchToKanban`:`switchToAgent`),title:s(E?`switchToKanban`:`switchToAgent`),children:[E?(0,$.jsx)(Ls,{className:`w-4 h-4 flex-shrink-0`}):(0,$.jsx)(Fo,{className:`w-4 h-4 flex-shrink-0 text-accent-primary`}),V&&(0,$.jsx)(`span`,{className:`min-w-0 truncate text-xs`,children:s(E?`switchToKanban`:`switchToAgent`)})]}),E&&(0,$.jsxs)(`button`,{type:`button`,onClick:sY,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`,V?`px-2`:`px-0 justify-center`),"aria-label":s(`search`),title:V?void 0:s(`search`),children:[(0,$.jsx)(On,{className:`w-4 h-4 flex-shrink-0`}),V&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:s(`search`)})]})]}),Ce&&(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`,V?`px-2`:`px-0 justify-center`,g?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),"aria-label":o(`arcSidebar.loops`),"aria-current":g?`page`:void 0,title:V?void 0:o(`arcSidebar.loops`),children:[(0,$.jsx)(Fc,{className:X(`w-4 h-4 flex-shrink-0`,g&&`text-accent-primary`)}),V&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:o(`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`,V?`px-2`:`px-0 justify-center`,_?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),"aria-label":o(`arcSidebar.plugins`),"aria-current":_?`page`:void 0,title:V?void 0:o(`arcSidebar.plugins`),children:[(0,$.jsx)(oc,{className:X(`w-4 h-4 flex-shrink-0`,_&&`text-accent-primary`)}),V&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:o(`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(lY),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`,V?`px-2`:`px-0 justify-center`),"aria-label":s(`favoriteMissions`),"aria-expanded":M,title:V?void 0:s(`favoriteMissions`),children:[V?(0,$.jsxs)(`span`,{className:`relative flex h-4 w-4 flex-shrink-0 items-center justify-center`,children:[(0,$.jsx)(ks,{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)(Wo,{className:`w-3.5 h-3.5`}):(0,$.jsx)(Go,{className:`w-3.5 h-3.5`})})]}):(0,$.jsx)(ks,{className:`w-4 h-4 flex-shrink-0 fill-current text-accent-primary`}),V&&(0,$.jsx)(`span`,{className:`text-xs truncate flex-1 text-left`,children:s(`favoriteMissions`)})]}),M&&V&&(0,$.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:O.map(e=>(0,$.jsx)(uY,{conversation:e,active:e.id===T.active?.id,streaming:T.streamingConversationIds.has(e.id),unread:T.unreadConversationIds.has(e.id),favorite:!0,expanded:V,onSelect:()=>I(e.id),onToggleFavorite:()=>ee(e.id),onDelete:()=>L(e.id)},e.id))})]}),E&&k.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>F(cY),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`,V?`px-2`:`px-0 justify-center`),"aria-label":s(`home`),"aria-expanded":A.has(cY),title:V?void 0:s(`home`),children:[V?(0,$.jsxs)(`span`,{className:`relative flex h-4 w-4 flex-shrink-0 items-center justify-center`,children:[(0,$.jsx)(js,{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(cY)?(0,$.jsx)(Wo,{className:`w-3.5 h-3.5`}):(0,$.jsx)(Go,{className:`w-3.5 h-3.5`})})]}):(0,$.jsx)(js,{className:`w-4 h-4 flex-shrink-0`}),V&&(0,$.jsx)(`span`,{className:`text-xs truncate flex-1 text-left`,children:s(`home`)})]}),A.has(cY)&&V&&(0,$.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:k.map(e=>(0,$.jsx)(uY,{conversation:e,active:e.id===T.active?.id,streaming:T.streamingConversationIds.has(e.id),unread:T.unreadConversationIds.has(e.id),expanded:V,onSelect:()=>I(e.id),onToggleFavorite:()=>ee(e.id),onDelete:()=>L(e.id)},e.id))})]}),c.map(e=>{let t=D.get(e.id)??[];return(0,$.jsx)(dY,{project:e,isActive:e.id===l&&!v,expanded:V,onSelect:()=>R(e.id),onRemove:()=>re(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:ee,onDeleteConversation:L,assembleStatus:f.statusFor(e.id),onRetryAssemble:()=>{f.retry(e.id)},onOpenProjectSettings:E?()=>{u(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`,V?`px-2`:`px-0 justify-center`),"aria-label":o(`projects.addProject`),title:V?void 0:o(`projects.addProject`),children:[(0,$.jsx)(Dn,{className:`w-4 h-4 flex-shrink-0`}),V&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:o(`projects.addProject`)})]})]}),(0,$.jsx)(`div`,{className:`border-t border-border py-2 px-1.5 space-y-0.5`,children:ne.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`,V?`px-2`:`px-0 justify-center`),"aria-label":e,title:V?void 0:e,children:[(0,$.jsx)(t,{className:`w-4 h-4 flex-shrink-0`}),V&&(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:e})]},e))}),N&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(rY,{open:!0,onClose:()=>P(!1)})})]})}var mY={"pinned-open":`sidebarPin.right.pinnedOpen`,"pinned-collapsed":`sidebarPin.right.pinnedCollapsed`,unpinned:`sidebarPin.right.unpinned`};function hY(){let{t:e}=K(`nav`),{rightMode:t,cycleRightMode:n}=RP(),[r,i]=(0,Q.useState)(!1),a=t===`pinned-open`||t===`unpinned`&&r,o=t!==`unpinned`,s=e(mY[t]),c=[{to:`/`,end:!0,icon:Rs,label:e(`rightSidebar.dashboard`)},{to:`/jobs`,end:!1,icon:zo,label:e(`rightSidebar.jobs`)},{to:`/analytics`,end:!1,icon:Bo,label:e(`rightSidebar.analytics`)},...se?[{to:`/code`,end:!1,icon:$o,label:e(`rightSidebar.code`)}]:[],{to:`/settings`,end:!1,icon:yc,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:nW(`⌘B`)}),children:(0,$.jsx)(Qs,{className:`w-4 h-4`})})]}),(0,$.jsxs)(`nav`,{className:`flex-1 py-2 px-1.5 space-y-0.5`,children:[(0,$.jsx)(BP,{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 gY(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 _Y({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)(qo,{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)(uc,{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)(jn,{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)(uc,{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)(yn,{className:`w-3.5 h-3.5 text-destructive flex-shrink-0`}):n||r?(0,$.jsx)(qo,{className:`w-3.5 h-3.5 text-accent-success flex-shrink-0`}):o?(0,$.jsx)(yn,{className:`w-3.5 h-3.5 text-muted-foreground/60 flex-shrink-0`}):(0,$.jsx)(yn,{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)(Ys,{className:`w-2.5 h-2.5`}),a(`prerequisites.bundledBadge`)]}),(0,$.jsxs)(`span`,{className:X(`text-muted-foreground`,t&&`text-destructive/80`),children:[`— `,gY(e,a)]})]},e.key)})})]})}function vY(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 yY=[`darwin`,`win32`,`linux`];async function bY(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 xY({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 bY(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)(vn,{className:`w-3 h-3`}),t(`common:actions.copied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(is,{className:`w-3 h-3`}),t(`common:actions.copy`)]})})}function SY({platform:e,primary:t}){let{t:n}=K(`setup`),r=vY(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)(xY,{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)(ln,{className:`w-3 h-3`})]})},e.url))}),r.note&&(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-accent-highlight`,children:r.note})]})}function CY(){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(`${Ke}/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)(vn,{className:`w-3 h-3 text-accent-success`}):(0,$.jsx)(Zo,{className:`w-3 h-3`}),e(t===`copied`?`instructions.diagnostics.copied`:t===`error`?`instructions.diagnostics.failed`:`instructions.diagnostics.copy`)]})}function wY({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=yY.filter(e=>e!==c);return n?.missingRequired?.some(e=>e.error===`corrupted-bundle`)??!1?(0,$.jsx)(sr,{open:e,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(ar,{movableResizable:!0,className:`max-w-xl`,"data-testid":`install-modal-corrupted-bundle`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:a(`instructions.corrupted.title`)}),(0,$.jsx)(Zn,{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)(sr,{open:e,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(ar,{movableResizable:!0,className:`max-w-xl`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(er,{children:a(`instructions.title`)}),(0,$.jsx)(Zn,{children:a(`instructions.description`)})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(SY,{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)(SY,{platform:e,primary:!1},e))})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mt-2`,children:[(0,$.jsx)(CY,{}),(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)(uc,{className:X(`w-3 h-3`,i&&`animate-spin`)}),a(`instructions.recheck`)]})]})]})]})})}var TY=typeof window<`u`&&`__TAURI_INTERNALS__`in window;function EY({open:e,onClose:t,onOpenBuilder:n}){let r=Te&&!!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}=lt(),{status:x,isLoading:S,error:C,recheck:w}=Gj(),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)(sr,{open:e,onOpenChange:k,children:(0,$.jsxs)(ar,{className:`max-w-md`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsxs)(er,{className:`flex items-center gap-2`,children:[(0,$.jsx)(bs,{className:`w-4 h-4`}),y(`addProject.title`)]}),(0,$.jsx)(Zn,{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)(ys,{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)(kn,{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)(sr,{open:e,onOpenChange:k,children:(0,$.jsxs)(ar,{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)(rr,{children:[(0,$.jsxs)(er,{className:`flex items-center gap-2`,children:[(0,$.jsx)(bs,{className:`w-4 h-4`}),y(`addProject.title`)]}),(0,$.jsx)(Zn,{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)(_Y,{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)(Ij,{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`}),TY&&(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([85,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)(bs,{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)(Ij,{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)(Ij,{"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)(Nn,{className:`h-4 w-4`})})]},t)),(0,$.jsxs)(Z,{type:`button`,variant:`outline`,size:`sm`,onClick:async()=>{if(TY)try{let{open:e}=await c(async()=>{let{open:e}=await import(`./dist-js-CJ_2XX1Y.js`);return{open:e}},__vite__mapDeps([85,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)(Dn,{className:`mr-1 h-3.5 w-3.5`}),y(`common:repositories.addFolder`)]})]})]}),(0,$.jsxs)(Wn,{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)(wY,{open:_,onClose:()=>v(!1),status:x,onRecheck:w,isRechecking:S})]})})}var DY=1,OY=.9,kY=.8,AY=.17,jY=.1,MY=.999,NY=.9999,PY=.99,FY=/[\\\/_+.#"@\[\(\{&]/,IY=/[\\\/_+.#"@\[\(\{&]/g,LY=/[\s-]/,RY=/[\s-]/g;function zY(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?DY:PY;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*=DY:FY.test(e.charAt(l-1))?(d*=kY,p=e.slice(i,l-1).match(IY),p&&i>0&&(d*=MY**+p.length)):LY.test(e.charAt(l-1))?(d*=OY,m=e.slice(i,l-1).match(RY),m&&i>0&&(d*=MY**+m.length)):(d*=AY,i>0&&(d*=MY**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=NY)),(d<jY&&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*jY>d&&(d=f*jY)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function BY(e){return e.toLowerCase().replace(RY,` `)}function VY(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,zY(e,t,BY(e),BY(t),0,0,{})}var HY=`[cmdk-group=""]`,UY=`[cmdk-group-items=""]`,WY=`[cmdk-group-heading=""]`,GY=`[cmdk-item=""]`,KY=`${GY}:not([aria-disabled="true"])`,qY=`cmdk-item-select`,JY=`data-value`,YY=(e,t,n)=>VY(e,t,n),XY=Q.createContext(void 0),ZY=()=>Q.useContext(XY),QY=Q.createContext(void 0),$Y=()=>Q.useContext(QY),eX=Q.createContext(void 0),tX=Q.forwardRef((e,t)=>{let n=hX(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=hX(()=>new Set),i=hX(()=>new Map),a=hX(()=>new Map),o=hX(()=>new Set),s=pX(e),{label:c,children:l,value:u,onValueChange:d,filter:f,shouldFilter:p,loop:m,disablePointerSelection:h=!1,vimBindings:g=!0,..._}=e,v=Hn(),y=Hn(),b=Hn(),x=Q.useRef(null),S=vX();mX(()=>{if(u!==void 0){let e=u.trim();n.current.value=e,C.emit()}},[u]),mX(()=>{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??YY;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(UY);t?t.appendChild(e.parentElement===t?e:e.closest(`${UY} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${UY} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=x.current?.querySelector(`${HY}[${JY}="${encodeURIComponent(e[0])}"]`);t?.parentElement.appendChild(t)})}function D(){let e=j().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(JY);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(HY)?.querySelector(WY))==null||e.scrollIntoView({block:`nearest`})),t.scrollIntoView({block:`nearest`}))}function A(){return x.current?.querySelector(`${GY}[aria-selected="true"]`)}function j(){return Array.from(x.current?.querySelectorAll(KY)||[])}function M(e){let t=j()[e];t&&C.setState(`value`,t.getAttribute(JY))}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(JY))}function P(e){let t=A()?.closest(HY),n;for(;t&&!n;)t=e>0?dX(t,HY):fX(t,HY),n=t?.querySelector(KY);n?C.setState(`value`,n.getAttribute(JY)):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(In.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(qY);t.dispatchEvent(e)}}}}},Q.createElement(`label`,{"cmdk-label":``,htmlFor:w.inputId,id:w.labelId,style:xX},c),bX(e,e=>Q.createElement(QY.Provider,{value:C},Q.createElement(XY.Provider,{value:w},e))))}),nX=Q.forwardRef((e,t)=>{let n=Hn(),r=Q.useRef(null),i=Q.useContext(eX),a=ZY(),o=pX(e),s=o.current?.forceMount??i?.forceMount;mX(()=>{if(!s)return a.item(n,i?.id)},[s]);let c=_X(n,r,[e.value,e.children,r],e.keywords),l=$Y(),u=gX(e=>e.value&&e.value===c.current),d=gX(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(qY,f),()=>t.removeEventListener(qY,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(In.div,{ref:$n(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)}),rX=Q.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...a}=e,o=Hn(),s=Q.useRef(null),c=Q.useRef(null),l=Hn(),u=ZY(),d=gX(e=>i||u.filter()===!1?!0:!e.search||e.filtered.groups.has(o));mX(()=>u.group(o),[]),_X(o,s,[e.value,e.heading,c]);let f=Q.useMemo(()=>({id:o,forceMount:i}),[i]);return Q.createElement(In.div,{ref:$n(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),bX(e,e=>Q.createElement(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?l:void 0},Q.createElement(eX.Provider,{value:f},e))))}),iX=Q.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=Q.useRef(null),a=gX(e=>!e.search);return!n&&!a?null:Q.createElement(In.div,{ref:$n(i,t),...r,"cmdk-separator":``,role:`separator`})}),aX=Q.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=e.value!=null,a=$Y(),o=gX(e=>e.search),s=gX(e=>e.selectedItemId),c=ZY();return Q.useEffect(()=>{e.value!=null&&a.setState(`search`,e.value)},[e.value]),Q.createElement(In.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)}})}),oX=Q.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...i}=e,a=Q.useRef(null),o=Q.useRef(null),s=gX(e=>e.selectedItemId),c=ZY();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(In.div,{ref:$n(a,t),...i,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:c.listId},bX(e,e=>Q.createElement(`div`,{ref:$n(o,c.listInnerRef),"cmdk-list-sizer":``},e)))}),sX=Q.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return Q.createElement(ir,{open:n,onOpenChange:r},Q.createElement(Jn,{container:o},Q.createElement(qn,{"cmdk-overlay":``,className:i}),Q.createElement(cr,{"aria-label":e.label,"cmdk-dialog":``,className:a},Q.createElement(tX,{ref:t,...s}))))}),cX=Q.forwardRef((e,t)=>gX(e=>e.filtered.count===0)?Q.createElement(In.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),lX=Q.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return Q.createElement(In.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},bX(e,e=>Q.createElement(`div`,{"aria-hidden":!0},e)))}),uX=Object.assign(tX,{List:oX,Item:nX,Input:aX,Group:rX,Separator:iX,Dialog:sX,Empty:cX,Loading:lX});function dX(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function fX(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function pX(e){let t=Q.useRef(e);return mX(()=>{t.current=e}),t}var mX=typeof window>`u`?Q.useEffect:Q.useLayoutEffect;function hX(e){let t=Q.useRef();return t.current===void 0&&(t.current=e()),t}function gX(e){let t=$Y(),n=()=>e(t.snapshot());return Q.useSyncExternalStore(t.subscribe,n,n)}function _X(e,t,n,r=[]){let i=Q.useRef(),a=ZY();return mX(()=>{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(JY,s),i.current=s}),i}var vX=()=>{let[e,t]=Q.useState(),n=hX(()=>new Map);return mX(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function yX(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function bX({asChild:e,children:t},n){return e&&Q.isValidElement(t)?Q.cloneElement(yX(t),{ref:t.ref},n(t.props.children)):n(t)}var xX={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`};function SX(e){return e.normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).toLowerCase()}function CX(e,t,n=[]){let r=SX(e.trim());return!r||SX(t).includes(r)?!0:n.some(e=>e&&SX(e).includes(r))}function wX(e,t){return Wb(t.updated_at)-Wb(e.updated_at)}function TX(e,t=8){return[...e].sort(wX).slice(0,Math.max(0,t)).map(e=>({conversation:e,match:`recent`,messageId:null,snippet:null}))}function EX(e,t,n,r=20){let i=SX(t.trim());if(!i)return[];let a=SX(n);return[...e].sort(wX).filter(e=>SX(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 DX(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 OX(e){return e===`agent`?[`missions`,`projects`,`spec`,`jobs`,`navigation`]:[`projects`,`missions`,`spec`,`jobs`,`navigation`]}var kX=[];function AX(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 jX({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:kX}),{projects:h,activeProjectId:g,setActiveProjectId:_}=lt(),{leftMode:v,rightMode:b,cycleLeftMode:x,cycleRightMode:S}=RP(),{uiMode:C}=bN(),{conversations:w,liveByConversation:T,selectConversation:E,open:D}=qN(),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(`${ot()}/config`),fetch(`${ot()}/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(()=>{Ja(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?DX(EX(w,e,N),p.query===e?p.hits:kX):TX(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]),ee=(0,Q.useCallback)(async e=>{o(!1);try{let t=await fetch(`${ot()}/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]),R=(0,Q.useCallback)(e=>{o(!1),A(`/jobs/${e}`)},[A]),z=(0,Q.useCallback)(e=>{o(!1),A(e)},[A]),B=(0,Q.useCallback)(e=>{e&&(o(!1),e())},[]),V=`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`,H=h.filter(e=>CX(s,e.name,[e.slug])),U=l.filter(e=>CX(s,e.name,[e.slug,e.description??``])),te=d.filter(e=>CX(s,`${e.command} ${e.id}`,[e.status])),ne=[{key:`dashboard`,label:r(`palette.nav.dashboard`),keywords:[`home`],icon:(0,$.jsx)(Rs,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>z(`/`)},...t?[{key:`desktopAnalytics`,label:r(`palette.nav.desktopAnalytics`),keywords:[`cross-project`,`desktop`],icon:(0,$.jsx)(Ho,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>B(t)}]:[],{key:`projectAnalytics`,label:r(`palette.nav.projectAnalytics`),keywords:[`metrics`],icon:(0,$.jsx)(Bo,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>z(`/analytics`)},{key:`activityFeed`,label:r(`palette.nav.activityFeed`),keywords:[`log`],icon:(0,$.jsx)(Eo,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>z(`/activity`)},{key:`desktopSettings`,label:r(`palette.nav.desktopSettings`),keywords:[`configuration`],icon:(0,$.jsx)(yc,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>e?B(e):z(`/settings`)},{key:`docs`,label:r(`palette.nav.docs`),keywords:[`documentation`],icon:(0,$.jsx)(xn,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>n?B(n):z(`/docs`)},{key:`leftSidebar`,label:O,keywords:[`sidebar`,`panel`,`left`,`pin`,`collapse`,`unpin`,`cycle`],icon:(0,$.jsx)(Zs,{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)(Qs,{className:`w-4 h-4 text-muted-foreground shrink-0`}),onSelect:()=>{S(),o(!1)}}].filter(e=>CX(s,e.label,e.keywords)),re={missions:P.length>0&&(0,$.jsx)(uX.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)(uX.Item,{value:`mission:${t.id}`,onSelect:()=>L(t.id),className:X(V,`items-start`),"data-testid":`palette-mission-${t.id}`,children:[(0,$.jsx)(gn,{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:qb(t.updated_at),children:Kb(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:AX(e.snippet)})]})]})]})]},t.id)})},`missions`),projects:H.length>0&&(0,$.jsx)(uX.Group,{heading:r(`palette.groups.projects`),"data-testid":`palette-group-projects`,children:H.map(e=>(0,$.jsxs)(uX.Item,{value:e.name,keywords:[e.slug],onSelect:()=>I(e.id),className:X(V,e.id===g&&`text-accent-primary`),children:[(0,$.jsx)(bs,{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:U.length>0&&(0,$.jsx)(uX.Group,{heading:r(`palette.groups.spec`),children:U.map(e=>(0,$.jsxs)(uX.Item,{value:e.name,keywords:[e.slug,e.description??``],onSelect:()=>ee(e.slug),className:V,children:[(0,$.jsx)(Pn,{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:te.length>0&&(0,$.jsx)(uX.Group,{heading:r(`palette.groups.jobs`),children:te.map(e=>(0,$.jsxs)(uX.Item,{value:`${e.command} ${e.id}`,keywords:[e.status],onSelect:()=>R(e.id),className:V,children:[(0,$.jsx)(zo,{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:ne.length>0&&(0,$.jsx)(uX.Group,{heading:r(`palette.groups.navigation`),children:ne.map(e=>(0,$.jsxs)(uX.Item,{value:e.label,keywords:e.keywords,onSelect:e.onSelect,className:V,children:[e.icon,(0,$.jsx)(`span`,{children:e.label})]},e.key))},`navigation`)};return(0,$.jsxs)(uX.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)(On,{className:`w-4 h-4 text-muted-foreground shrink-0`}),(0,$.jsx)(uX.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)(uX.List,{className:`max-h-80 overflow-y-auto p-2`,children:[(0,$.jsx)(uX.Empty,{className:`py-8 text-center text-sm text-muted-foreground`,children:r(`palette.noResults`)}),OX(C).map(e=>re[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 MX=`
75
75
 
76
76
  ---
77
77
 
78
78
  ## Contract Layer
79
79
 
80
- `;function NX(e){return`contract-refine:${e}`}async function PX(e,t){try{let n=await fetch(`${Ke}/api/projects/${e}/tickets/${t}/contract-refine`,{method:`POST`});if(n.ok)J.loading(We.t(`activity:contractRefine.refining`),{id:NX(t)});else{let e=await n.json().catch(()=>({}));J.error(e.error?We.t(`activity:contractRefine.retryRejectedWithError`,{error:e.error}):We.t(`activity:contractRefine.retryRejected`),{id:NX(t)})}}catch(e){J.error(We.t(`activity:contractRefine.retryFailed`,{message:e.message}),{id:NX(t)})}}function FX({children:e}){let{registerHandler:t,unregisterHandler:n}=Ze(),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=xt(a)?{label:We.t(`common:actions.retry`),onClick:()=>void PX(i,n)}:void 0;J.error(We.t(`activity:contractRefine.skipped`),{id:NX(n),description:We.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(MX)&&J.success(We.t(`activity:contractRefine.added`,{title:n.title||`#${n.id}`}),{id:NX(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 IX(){return typeof window<`u`&&`__TAURI_INTERNALS__`in window}function LX(){let{t:e}=K(`mcp`),t=KG()?.languageId;(0,Q.useEffect)(()=>{IX()&&Y(`set_tray_labels`,{open:e(`tray.open`),exit:e(`tray.exit`)}).catch(()=>{})},[e,t])}var RX=`input, textarea, select, [contenteditable="true"], [contenteditable=""], .monaco-editor, .xterm, [data-native-menu]`;function zX(e){return e instanceof Element&&e.closest(RX)!==null}function BX(e){zX(e.target)||e.preventDefault()}function VX(){(0,Q.useEffect)(()=>(document.addEventListener(`contextmenu`,BX),()=>document.removeEventListener(`contextmenu`,BX)),[])}var HX={jobs:[],activeJobId:null,paused:!1};function UX(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)(HX),[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(HX))}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??HX;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}=Ze();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(`${ot()}/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 WX({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(`${ot()}/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 GX=(0,Q.lazy)(()=>c(()=>import(`./AgentBrowserCapture-Dr8kZotA.js`).then(e=>({default:e.AgentBrowserCapture})),__vite__mapDeps([87,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])));function KX(){let{browserOpen:e}=ZD(),{active:t}=qN(),n=gi(),r=!n.current&&n.transfers.some(e=>e.conversationId===t?.id&&e.state===`detached`),{activeProjectId:i}=lt();return!e||!i||r?null:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(GX,{projectId:i,conversationId:t?.id??null})})}function qX(){let{state:e,openTicketDetail:t,enterSplit:n,setComparedTicket:r}=_e(),{tickets:i}=E(),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 JX(e){let{key:t,detail:n}=Qt(e);return[`chunk_failed`,`chunk_stalled`,`chunk_stopped`,`provider_limit`,`launch_rejected`,`head_missing`,`head_discarded`,`run_lost`].includes(t)?We.t(`builder:milestoneProgress.chain.reasons.${t}`,{detail:n}):e??``}function YX({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}=Ze();(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=zt(t.chain);if(!e)return;let n=i.current.get(e.id);i.current.set(e.id,e);let r=Vt(e.milestoneN);if(e.status===`running`&&e.nextChunk>1&&(!n||n.nextChunk<e.nextChunk)&&J.success(We.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(We.t(`builder:milestoneProgress.toast.checkpoint`,{milestone:r,k:e.nextChunk,n:e.totalChunks}),{id:t,duration:6e4,action:{label:We.t(`builder:milestoneProgress.toast.launchNext`),onClick:()=>{fM(o,e.id).then(e=>{e.ok?J.success(We.t(`builder:milestoneProgress.chain.nextLaunched`),{id:t}):J.error(We.t(`builder:milestoneProgress.chain.resumeFailed`),{id:t,description:e.detail??e.error})})}},cancel:{label:We.t(`builder:milestoneProgress.toast.autoContinue`),onClick:()=>{mM(o,e.id,!0).then(e=>{e.ok?J.success(We.t(`builder:milestoneProgress.chain.autoOn`),{id:t}):J.error(We.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(We.t(`builder:milestoneProgress.toast.paused`,{milestone:r,reason:JX(e.pauseReason)}),{id:`chain-paused:${e.id}`,duration:3e4,action:{label:We.t(`builder:milestoneProgress.toast.resume`),onClick:()=>{fM(o,e.id).then(t=>{t.ok?J.success(We.t(`builder:milestoneProgress.chain.resumed`),{id:`chain-paused:${e.id}`}):J.error(We.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 Kt(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=qt(e);J.success(We.t(`builder:milestoneProgress.toast.delivered`,{milestone:Vt(e.n),count:e.counts.onReview}),{id:`milestone-delivered:${t}`,duration:3e4,...i?{action:{label:We.t(`builder:milestoneProgress.toast.review`),onClick:()=>{r.current?.(o);let e=ae?`/review/${i.id}`:`/`;setTimeout(()=>{n.current(e)},50)}}}:{}})}}return}t.type===`blueprint.milestone_completed`&&typeof t.n==`number`&&J.success(We.t(`builder:milestoneProgress.toast.completed`,{milestone:Vt(t.n)}),{id:`milestone-completed:${o}:${t.milestoneId??t.n}`,duration:15e3})}),()=>s(e)},[o,s])}function XX(e){return e.startsWith(`/loops`)?`loops`:e.startsWith(`/plugins`)?`plugins`:ZX(e)?`review`:null}function ZX(e){let t=/^\/review\/([^/]+)\/?$/.exec(e);return t?decodeURIComponent(t[1]):null}function QX(e){let t=/^\/loops\/([^/]+)\/edit\/?$/.exec(e);return t?decodeURIComponent(t[1]):null}function $X({uiMode:e,pathname:t,loopsOpen:n,pluginsOpen:r,reviewOpen:i=null}){if(e===`agent`){let e=XX(t);if(!e)return null;if(e===`review`)return{kind:`modalize`,surface:e,backgroundPath:`/`,reviewDeliveryId:ZX(t)??void 0};let n=e===`loops`?QX(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 eZ=(0,Q.lazy)(()=>c(()=>import(`./JobDetailPage-CKYtQV5a.js`),__vite__mapDeps([88,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,83]))),tZ=(0,Q.lazy)(()=>c(()=>import(`./ReviewPacketPage-BoqahYNC.js`),__vite__mapDeps([89,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,90]))),nZ=(0,Q.lazy)(()=>c(()=>import(`./JobsPage-DFJm0bw0.js`),__vite__mapDeps([91,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,52,61,62,51,65,66,67,68,69,70,71,78,83,92,53]))),rZ=(0,Q.lazy)(()=>c(()=>import(`./AnalyticsPage-BbXPcz3a.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,44,45,8,46,48,67,69,70,92,53,94,95]))),iZ=(0,Q.lazy)(()=>c(()=>import(`./ActivityFeedPage-FdZBSmTU.js`),__vite__mapDeps([96,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,56,64]))),aZ=(0,Q.lazy)(()=>c(()=>import(`./AgentsPage-CTv4UVdp.js`),__vite__mapDeps([97,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,54,56,57,59,60,61,62,65,66,67,71,83]))),oZ=(0,Q.lazy)(()=>c(()=>import(`./CodePage-CIigb_O0.js`),__vite__mapDeps([98,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]))),sZ=(0,Q.lazy)(()=>c(()=>import(`./IntegrationsPage-Bhy58lnQ.js`),__vite__mapDeps([99,7,1,11,10]))),cZ=(0,Q.lazy)(()=>c(()=>import(`./PluginsPage-BR9ZTqxR.js`),__vite__mapDeps([100,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,53,56,60,61,62,63,65,51,66,67,71,72]))),lZ=(0,Q.lazy)(()=>c(()=>import(`./DesktopAnalyticsPage-DZhN5jVh.js`),__vite__mapDeps([101,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,67,66,94,8,95]))),uZ=(0,Q.lazy)(()=>c(()=>import(`./DocsPage-B1AUuk0U.js`),__vite__mapDeps([102,1,7,11,10,43,54,56,66,67,68,77,103,104]))),dZ=(0,Q.lazy)(()=>c(()=>import(`./DocsDialog-DzrqPxuj.js`),__vite__mapDeps([105,1,7,43,54,56,65,8,51,66,67,68,77,103,104]))),fZ=(0,Q.lazy)(()=>c(()=>import(`./LoopsPage-DRcT1ikP.js`),__vite__mapDeps([106,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,53,57,58,59,50,61,107,65,51,66,67,71,73,74,80,55]))),pZ=(0,Q.lazy)(()=>c(()=>import(`./LoopBuilderPage-ujkA2U0T.js`),__vite__mapDeps([108,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,55,58,59,61,62,107,65,51,66,67,71,74,95,109]))),mZ=28;function hZ({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`?Fc:e===`review`?ps:oc,{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)(Nn,{className:`h-4 w-4`})})})]})}var gZ=new Set([`/settings`,`/loops`,`/plugins`]);function _Z(e){return gZ.has(e)||e.startsWith(`/loops`)||e.startsWith(`/plugins`)||e.startsWith(`/docs`)}var vZ=`specrails-desktop:routeMemory`;try{localStorage.removeItem(vZ)}catch{}function yZ(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)(()=>{HA((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&&!_Z(t.pathname)&&r.current.set(i.current,t.pathname),e&&e!==i.current){let i=r.current.get(e),a=i&&!_Z(i)?i:`/`;t.pathname!==a&&n(a,{replace:!0})}i.current=e},[e,t.pathname,n]),(0,Q.useEffect)(()=>{e&&t.pathname!==`/`&&!_Z(t.pathname)&&r.current.set(e,t.pathname)},[e,t.pathname])}function bZ(){let{t:e}=K(`common`),{projects:t,activeProjectId:n,isLoading:r,isSwitchingProject:i,setActiveProjectId:a}=lt(),{cycleLeftMode:o,cycleRightMode:s}=RP(),c=y(),l=p(),u=Ma(),d=qN(),{startNewConversation:m}=d,{uiMode:g}=bN();qX();let[v,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(!1),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(null),[k,A]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(null),[N,P]=(0,Q.useState)(!1),I=(0,Q.useCallback)(()=>P(!1),[]),[L,ee]=(0,Q.useState)(()=>!BJ());yZ(n),LX();let{cheatsheetOpen:R,setCheatsheetOpen:z,openCheatsheet:B}=Xq(),V=[`/`,`/jobs`,`/analytics`,...H?[`/agents`]:[],...se?[`/code`]:[],`/integrations`,`/settings`];Yq({onOpenCheatsheet:B,onToggleLeftSidebar:o,onToggleRightSidebar:s,onSwitchProject:e=>{let n=t[e-1];n&&a(n.id)},onSwitchProjectPage:e=>{let t=V[e-1];t&&c(t)},onToggleTerminalPanel:W?()=>{n&&(u.togglePanel(n),u.getState(n).visibility===`hidden`?queueMicrotask(()=>u.focusActive(n)):u.focusActive(n))}:void 0,onToggleAgentChat:F&&g!==`agent`?()=>d.toggle():void 0}),Bq({setActiveProjectId:a,projectsById:(0,Q.useMemo)(()=>new Map(t.map(e=>[e.id,e.name])),[t])}),YX({setActiveProjectId:a}),(0,Q.useEffect)(()=>{oM()},[]);let U=t.find(e=>e.id===n),te=l.pathname.startsWith(`/loops`),ne=l.pathname.startsWith(`/plugins`),re=l.pathname.startsWith(`/docs`)||g!==`agent`&&(te||ne);(0,Q.useLayoutEffect)(()=>{let e=$X({uiMode:g,pathname:l.pathname,loopsOpen:T,pluginsOpen:k,reviewOpen:j});if(e){if(e.kind===`modalize`){if(e.surface===`review`){e.reviewDeliveryId&&M(e.reviewDeliveryId),l.pathname!==e.backgroundPath&&c(e.backgroundPath,{replace:!0});return}e.surface===`loops`?(A(!1),E(!0),e.loopBuilderId&&O(e.loopBuilderId)):(E(!1),A(!0)),m(n),l.pathname!==e.backgroundPath&&c(e.backgroundPath,{replace:!0});return}E(!1),A(!1),M(null),l.pathname!==e.path&&c(e.path,{replace:!0})}},[n,l.pathname,T,c,k,j,m,g]);let{connectionStatus:ie}=UX(),oe=Na(n),ce=g===`agent`?0:mZ,le=(0,Q.useRef)(null),[ue,de]=(0,Q.useState)(typeof window<`u`?window.innerHeight:820);(0,Q.useLayoutEffect)(()=>{if(!W)return;let e=le.current;if(!e)return;let t=()=>de(e.clientHeight);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[r]),(0,Q.useEffect)(()=>{!W||!n||u.ensureProject(n)},[n,u]);let fe=W&&g===`kanban`&&oe.visibility===`hidden`?(0,$.jsx)(sF,{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)(pY,{onAddProject:()=>b(!0),onOpenLoops:()=>{g===`agent`?E(!0):c(`/loops`)},onOpenPlugins:()=>{g===`agent`?A(!0):c(`/plugins`)},onOpenAnalytics:()=>w(!0),onOpenDocs:()=>P(!0),onOpenSettings:()=>S(!0)}),(0,$.jsxs)(`div`,{ref:le,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`&&!re?(0,$.jsx)(wP,{}):(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)(uZ,{})}),(0,$.jsx)(h,{path:`/docs/:category/:slug`,element:(0,$.jsx)(uZ,{})}),Ce&&(0,$.jsx)(h,{path:`/loops`,element:(0,$.jsx)(fZ,{})}),Ce&&(0,$.jsx)(h,{path:`/loops/:id/edit`,element:(0,$.jsx)(pZ,{})}),(0,$.jsx)(h,{path:`/plugins`,element:(0,$.jsx)(cZ,{})}),t.length===0?(0,$.jsx)(h,{path:`*`,element:(0,$.jsx)(LJ,{onAddProject:()=>b(!0)})}):U?(0,$.jsxs)(h,{element:(0,$.jsx)(IJ,{projectName:U.name,children:(0,$.jsx)(PJ,{project:U})},U.id),children:[(0,$.jsx)(h,{path:`/`,element:(0,$.jsx)(bW,{})}),(0,$.jsx)(h,{path:`/jobs`,element:(0,$.jsx)(nZ,{})}),(0,$.jsx)(h,{path:`/jobs/:id`,element:(0,$.jsx)(eZ,{})}),ae&&(0,$.jsx)(h,{path:`/review/:prDeliveryId`,element:(0,$.jsx)(tZ,{})}),(0,$.jsx)(h,{path:`/analytics`,element:(0,$.jsx)(rZ,{})}),(0,$.jsx)(h,{path:`/activity`,element:(0,$.jsx)(iZ,{})}),(0,$.jsx)(h,{path:`/agents`,element:(0,$.jsx)(aZ,{})}),(0,$.jsx)(h,{path:`/code`,element:se?(0,$.jsx)(oZ,{}):(0,$.jsx)(f,{to:`/`,replace:!0})}),(0,$.jsx)(h,{path:`/integrations`,element:(0,$.jsx)(sZ,{})}),(0,$.jsx)(h,{path:`/settings`,element:(0,$.jsx)(IG,{})}),(0,$.jsx)(h,{path:`*`,element:(0,$.jsx)(f,{to:`/`,replace:!0})})]}):(0,$.jsx)(h,{path:`*`,element:(0,$.jsx)(LJ,{onAddProject:()=>b(!0)})})]})})}),W&&n&&U&&(0,$.jsx)(OF,{projectId:n,provider:U.provider,providers:st(U),state:oe,viewportHeight:ue,statusBarHeight:ce}),g!==`agent`&&(0,$.jsx)(WX,{connectionStatus:ie,rightSlot:fe})]}),g===`agent`?!re&&(0,$.jsx)(HP,{}):U&&!re&&(0,$.jsx)(hY,{}),(0,$.jsx)(EY,{open:v,onClose:()=>b(!1),onOpenBuilder:()=>d.builderMode.enter()}),(0,$.jsx)(Wq,{open:x,onClose:()=>S(!1),onOpenOnboarding:()=>{S(!1),ee(!0)}}),(0,$.jsx)(sr,{open:C,onOpenChange:w,children:(0,$.jsx)(ar,{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)(lZ,{})})})})}),(0,$.jsx)(sr,{open:T,onOpenChange:e=>{E(e),e||O(null)},children:(0,$.jsxs)(ar,{showCloseButton:!1,className:`max-w-[96vw] w-[96vw] h-[92vh] max-h-[92vh] overflow-hidden p-0 flex flex-col`,children:[(0,$.jsx)(er,{className:`sr-only`,children:e(`nav:arcSidebar.loops`)}),(0,$.jsx)(Zn,{className:`sr-only`,children:e(`nav:globalSurfaceModal.loopsDescription`)}),(0,$.jsx)(hZ,{surface:`loops`,onClose:()=>{E(!1),O(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:D?(0,$.jsx)(`div`,{className:`h-full`,children:(0,$.jsx)(pZ,{loopId:D,onExit:()=>O(null)})}):(0,$.jsx)(fZ,{onOpenBuilder:O})})})]})}),ae&&(0,$.jsx)(sr,{open:j!==null,onOpenChange:e=>{e||M(null)},children:(0,$.jsxs)(ar,{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)(er,{className:`sr-only`,children:e(`nav:arcSidebar.review`)}),(0,$.jsx)(Zn,{className:`sr-only`,children:e(`nav:globalSurfaceModal.reviewDescription`)}),(0,$.jsx)(hZ,{surface:`review`,onClose:()=>M(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:j&&(0,$.jsx)(tZ,{prDeliveryId:j,onClose:()=>M(null)})})})]})}),(0,$.jsx)(sr,{open:k,onOpenChange:A,children:(0,$.jsxs)(ar,{showCloseButton:!1,className:`max-w-[96vw] w-[96vw] h-[92vh] max-h-[92vh] overflow-hidden p-0 flex flex-col`,children:[(0,$.jsx)(er,{className:`sr-only`,children:e(`nav:arcSidebar.plugins`)}),(0,$.jsx)(Zn,{className:`sr-only`,children:e(`nav:globalSurfaceModal.pluginsDescription`)}),(0,$.jsx)(hZ,{surface:`plugins`,onClose:()=>A(!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)(cZ,{})})})]})}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(dZ,{open:N,onClose:I})}),(0,$.jsx)(jX,{onOpenSettings:()=>S(!0),onOpenAnalytics:()=>w(!0),onOpenDocs:()=>P(!0)}),(0,$.jsx)(tJ,{open:R,onOpenChange:z}),(0,$.jsx)(tY,{open:L,onClose:()=>ee(!1)})]})}function xZ({children:e}){let{activeProjectId:t}=lt();return(0,$.jsx)(Aa,{activeProjectId:t,children:e})}function SZ({children:e}){let{activeProjectId:t}=lt();return(0,$.jsx)(LU,{activeProjectId:t,children:e})}function CZ({children:e}){let{activeProjectId:t}=lt();return(0,$.jsx)(WU,{activeProjectId:t,children:e})}function wZ(){return(0,$.jsx)(`span`,{"aria-hidden":!0,style:{display:`none`}})}function TZ(){let{theme:e}=ha(),t=e.previewSwatches.accents[0],n=e.status.completed,r=e.status.failed,i=e.status.canceled,a=e.status.running;return(0,Bb.createPortal)((0,$.jsx)(ct,{position:`bottom-right`,className:`specrails-toaster`,theme:e.scheme,gap:8,closeButton:!0,visibleToasts:6,icons:{loading:(0,$.jsx)(wZ,{})},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 EZ(){return VK(),null}function DZ(){let e=ci();return VX(),(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)(Je,{url:oe,children:(0,$.jsx)(ma,{children:(0,$.jsxs)(GG,{children:[(0,$.jsx)(NJ,{}),(0,$.jsx)(ut,{isolated:e,children:(0,$.jsxs)(vN,{initialMode:e?`agent`:void 0,persist:!e,children:[!e&&(0,$.jsx)(EZ,{}),(0,$.jsx)(oJ,{}),(0,$.jsx)(LB,{children:(0,$.jsx)(FX,{children:(0,$.jsx)(te,{children:(0,$.jsx)(LP,{children:(0,$.jsx)(xZ,{children:(0,$.jsx)(SZ,{children:(0,$.jsx)(CZ,{children:(0,$.jsx)(_n,{children:(0,$.jsx)(YD,{children:(0,$.jsx)(hi,{secondary:e,children:(0,$.jsx)(GN,{children:(0,$.jsx)(dO,{children:(0,$.jsx)(Ee,{children:(0,$.jsxs)(ye,{children:[(0,$.jsx)(YN,{}),(0,$.jsx)(Lc,{}),e?(0,$.jsx)(kF,{}):(0,$.jsx)(bZ,{}),(0,$.jsx)(KX,{}),(0,$.jsx)(TZ,{})]})})})})})})})})})})})})})})]})})]})})})})})}async function OZ(){await Ye(),Qe(),await Ue(),(0,Mr.createRoot)(document.getElementById(`root`)).render((0,$.jsx)(Q.StrictMode,{children:(0,$.jsx)(v,{children:(0,$.jsx)(DZ,{})})}));let e=document.getElementById(`specrails-splash`);e&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.classList.add(`is-hidden`),setTimeout(()=>e.remove(),300)})})}OZ();export{Mb as $,gI as A,bs as At,tA as B,Bo as Bt,lz as C,Hs as Ct,_L as D,As as Dt,yR as E,js as Et,BA as F,Zo as Ft,sD as G,Mo as Gt,WO as H,Lo as Ht,LA as I,qo as It,Gx as J,to as Jt,xD as K,Ao as Kt,eA as L,Ko as Lt,tI as M,gs as Mt,qN as N,ps as Nt,SL as O,Ds as Ot,Ij as P,is as Pt,Ib as Q,nA as R,Go as Rt,BR as S,Us as St,qR as T,Ns as Tt,ZD as U,Fo as Ut,GO as V,zo as Vt,oD as W,Po as Wt,Lx as X,gi as Xt,Yx as Y,_a as Yt,Ix as Z,YH as _,oc as _t,DG as a,Nc as at,pz as b,Gs as bt,jW as c,Dc as ct,zU as d,xc as dt,Uy as et,xU as f,yc as ft,XH as g,uc as gt,ZH as h,dc as ht,PG as i,Fc as it,_I as j,_s as jt,EI as k,xs as kt,OW as l,wc as lt,NU as m,pc as mt,FG as n,Py as nt,MG as o,Mc as ot,PU as p,_c as pt,Qx as q,Eo as qt,OG as r,Hy as rt,xG as s,Oc as st,UX as t,Ny as tt,nW as u,Sc as ut,zH as v,ic as vt,az as w,zs as wt,ZR as x,Ws as xt,wV as y,nc as yt,$k as z,Wo as zt};
80
+ `;function NX(e){return`contract-refine:${e}`}async function PX(e,t){try{let n=await fetch(`${Ke}/api/projects/${e}/tickets/${t}/contract-refine`,{method:`POST`});if(n.ok)J.loading(We.t(`activity:contractRefine.refining`),{id:NX(t)});else{let e=await n.json().catch(()=>({}));J.error(e.error?We.t(`activity:contractRefine.retryRejectedWithError`,{error:e.error}):We.t(`activity:contractRefine.retryRejected`),{id:NX(t)})}}catch(e){J.error(We.t(`activity:contractRefine.retryFailed`,{message:e.message}),{id:NX(t)})}}function FX({children:e}){let{registerHandler:t,unregisterHandler:n}=Ze(),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=xt(a)?{label:We.t(`common:actions.retry`),onClick:()=>void PX(i,n)}:void 0;J.error(We.t(`activity:contractRefine.skipped`),{id:NX(n),description:We.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(MX)&&J.success(We.t(`activity:contractRefine.added`,{title:n.title||`#${n.id}`}),{id:NX(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 IX(){return typeof window<`u`&&`__TAURI_INTERNALS__`in window}function LX(){let{t:e}=K(`mcp`),t=KG()?.languageId;(0,Q.useEffect)(()=>{IX()&&Y(`set_tray_labels`,{open:e(`tray.open`),exit:e(`tray.exit`)}).catch(()=>{})},[e,t])}var RX=`input, textarea, select, [contenteditable="true"], [contenteditable=""], .monaco-editor, .xterm, [data-native-menu]`;function zX(e){return e instanceof Element&&e.closest(RX)!==null}function BX(e){zX(e.target)||e.preventDefault()}function VX(){(0,Q.useEffect)(()=>(document.addEventListener(`contextmenu`,BX),()=>document.removeEventListener(`contextmenu`,BX)),[])}var HX={jobs:[],activeJobId:null,paused:!1};function UX(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)(HX),[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(HX))}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??HX;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}=Ze();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(`${ot()}/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 WX({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(`${ot()}/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 GX=(0,Q.lazy)(()=>c(()=>import(`./AgentBrowserCapture-DBGaKW4u.js`).then(e=>({default:e.AgentBrowserCapture})),__vite__mapDeps([87,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])));function KX(){let{browserOpen:e}=ZD(),{active:t}=qN(),n=gi(),r=!n.current&&n.transfers.some(e=>e.conversationId===t?.id&&e.state===`detached`),{activeProjectId:i}=lt();return!e||!i||r?null:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(GX,{projectId:i,conversationId:t?.id??null})})}function qX(){let{state:e,openTicketDetail:t,enterSplit:n,setComparedTicket:r}=_e(),{tickets:i}=E(),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 JX(e){let{key:t,detail:n}=Qt(e);return[`chunk_failed`,`chunk_stalled`,`chunk_stopped`,`provider_limit`,`launch_rejected`,`head_missing`,`head_discarded`,`run_lost`].includes(t)?We.t(`builder:milestoneProgress.chain.reasons.${t}`,{detail:n}):e??``}function YX({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}=Ze();(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=zt(t.chain);if(!e)return;let n=i.current.get(e.id);i.current.set(e.id,e);let r=Vt(e.milestoneN);if(e.status===`running`&&e.nextChunk>1&&(!n||n.nextChunk<e.nextChunk)&&J.success(We.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(We.t(`builder:milestoneProgress.toast.checkpoint`,{milestone:r,k:e.nextChunk,n:e.totalChunks}),{id:t,duration:6e4,action:{label:We.t(`builder:milestoneProgress.toast.launchNext`),onClick:()=>{fM(o,e.id).then(e=>{e.ok?J.success(We.t(`builder:milestoneProgress.chain.nextLaunched`),{id:t}):J.error(We.t(`builder:milestoneProgress.chain.resumeFailed`),{id:t,description:e.detail??e.error})})}},cancel:{label:We.t(`builder:milestoneProgress.toast.autoContinue`),onClick:()=>{mM(o,e.id,!0).then(e=>{e.ok?J.success(We.t(`builder:milestoneProgress.chain.autoOn`),{id:t}):J.error(We.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(We.t(`builder:milestoneProgress.toast.paused`,{milestone:r,reason:JX(e.pauseReason)}),{id:`chain-paused:${e.id}`,duration:3e4,action:{label:We.t(`builder:milestoneProgress.toast.resume`),onClick:()=>{fM(o,e.id).then(t=>{t.ok?J.success(We.t(`builder:milestoneProgress.chain.resumed`),{id:`chain-paused:${e.id}`}):J.error(We.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 Kt(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=qt(e);J.success(We.t(`builder:milestoneProgress.toast.delivered`,{milestone:Vt(e.n),count:e.counts.onReview}),{id:`milestone-delivered:${t}`,duration:3e4,...i?{action:{label:We.t(`builder:milestoneProgress.toast.review`),onClick:()=>{r.current?.(o);let e=ae?`/review/${i.id}`:`/`;setTimeout(()=>{n.current(e)},50)}}}:{}})}}return}t.type===`blueprint.milestone_completed`&&typeof t.n==`number`&&J.success(We.t(`builder:milestoneProgress.toast.completed`,{milestone:Vt(t.n)}),{id:`milestone-completed:${o}:${t.milestoneId??t.n}`,duration:15e3})}),()=>s(e)},[o,s])}function XX(e){return e.startsWith(`/loops`)?`loops`:e.startsWith(`/plugins`)?`plugins`:ZX(e)?`review`:null}function ZX(e){let t=/^\/review\/([^/]+)\/?$/.exec(e);return t?decodeURIComponent(t[1]):null}function QX(e){let t=/^\/loops\/([^/]+)\/edit\/?$/.exec(e);return t?decodeURIComponent(t[1]):null}function $X({uiMode:e,pathname:t,loopsOpen:n,pluginsOpen:r,reviewOpen:i=null}){if(e===`agent`){let e=XX(t);if(!e)return null;if(e===`review`)return{kind:`modalize`,surface:e,backgroundPath:`/`,reviewDeliveryId:ZX(t)??void 0};let n=e===`loops`?QX(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 eZ=(0,Q.lazy)(()=>c(()=>import(`./JobDetailPage-BnS8aHKD.js`),__vite__mapDeps([88,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,83]))),tZ=(0,Q.lazy)(()=>c(()=>import(`./ReviewPacketPage-DSSi3x16.js`),__vite__mapDeps([89,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,90]))),nZ=(0,Q.lazy)(()=>c(()=>import(`./JobsPage-BC0mq-MF.js`),__vite__mapDeps([91,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,52,61,62,51,65,66,67,68,69,70,71,78,83,92,53]))),rZ=(0,Q.lazy)(()=>c(()=>import(`./AnalyticsPage-DisrtBr7.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,44,45,8,46,48,67,69,70,92,53,94,95]))),iZ=(0,Q.lazy)(()=>c(()=>import(`./ActivityFeedPage-CyOxof-U.js`),__vite__mapDeps([96,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,56,64]))),aZ=(0,Q.lazy)(()=>c(()=>import(`./AgentsPage-CX90q-nY.js`),__vite__mapDeps([97,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,54,56,57,59,60,61,62,65,66,67,71,83]))),oZ=(0,Q.lazy)(()=>c(()=>import(`./CodePage-ixqxftCT.js`),__vite__mapDeps([98,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]))),sZ=(0,Q.lazy)(()=>c(()=>import(`./IntegrationsPage-Bhy58lnQ.js`),__vite__mapDeps([99,7,1,11,10]))),cZ=(0,Q.lazy)(()=>c(()=>import(`./PluginsPage-BhG3qPda.js`),__vite__mapDeps([100,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,53,56,60,61,62,63,65,51,66,67,71,72]))),lZ=(0,Q.lazy)(()=>c(()=>import(`./DesktopAnalyticsPage-BFB-Pn-D.js`),__vite__mapDeps([101,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,67,66,94,8,95]))),uZ=(0,Q.lazy)(()=>c(()=>import(`./DocsPage-ByS0ZCco.js`),__vite__mapDeps([102,1,7,11,10,43,54,56,66,67,68,77,103,104]))),dZ=(0,Q.lazy)(()=>c(()=>import(`./DocsDialog-BwiFrwEJ.js`),__vite__mapDeps([105,1,7,43,54,56,65,8,51,66,67,68,77,103,104]))),fZ=(0,Q.lazy)(()=>c(()=>import(`./LoopsPage-BcegqJyY.js`),__vite__mapDeps([106,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,53,57,58,59,50,61,107,65,51,66,67,71,73,74,80,55]))),pZ=(0,Q.lazy)(()=>c(()=>import(`./LoopBuilderPage-WmqNpDw2.js`),__vite__mapDeps([108,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,55,58,59,61,62,107,65,51,66,67,71,74,95,109]))),mZ=28;function hZ({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`?Fc:e===`review`?ps:oc,{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)(Nn,{className:`h-4 w-4`})})})]})}var gZ=new Set([`/settings`,`/loops`,`/plugins`]);function _Z(e){return gZ.has(e)||e.startsWith(`/loops`)||e.startsWith(`/plugins`)||e.startsWith(`/docs`)}var vZ=`specrails-desktop:routeMemory`;try{localStorage.removeItem(vZ)}catch{}function yZ(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)(()=>{HA((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&&!_Z(t.pathname)&&r.current.set(i.current,t.pathname),e&&e!==i.current){let i=r.current.get(e),a=i&&!_Z(i)?i:`/`;t.pathname!==a&&n(a,{replace:!0})}i.current=e},[e,t.pathname,n]),(0,Q.useEffect)(()=>{e&&t.pathname!==`/`&&!_Z(t.pathname)&&r.current.set(e,t.pathname)},[e,t.pathname])}function bZ(){let{t:e}=K(`common`),{projects:t,activeProjectId:n,isLoading:r,isSwitchingProject:i,setActiveProjectId:a}=lt(),{cycleLeftMode:o,cycleRightMode:s}=RP(),c=y(),l=p(),u=Ma(),d=qN(),{startNewConversation:m}=d,{uiMode:g}=bN();qX();let[v,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(!1),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(null),[k,A]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(null),[N,P]=(0,Q.useState)(!1),I=(0,Q.useCallback)(()=>P(!1),[]),[L,ee]=(0,Q.useState)(()=>!BJ());yZ(n),LX();let{cheatsheetOpen:R,setCheatsheetOpen:z,openCheatsheet:B}=Xq(),V=[`/`,`/jobs`,`/analytics`,...H?[`/agents`]:[],...se?[`/code`]:[],`/integrations`,`/settings`];Yq({onOpenCheatsheet:B,onToggleLeftSidebar:o,onToggleRightSidebar:s,onSwitchProject:e=>{let n=t[e-1];n&&a(n.id)},onSwitchProjectPage:e=>{let t=V[e-1];t&&c(t)},onToggleTerminalPanel:W?()=>{n&&(u.togglePanel(n),u.getState(n).visibility===`hidden`?queueMicrotask(()=>u.focusActive(n)):u.focusActive(n))}:void 0,onToggleAgentChat:F&&g!==`agent`?()=>d.toggle():void 0}),Bq({setActiveProjectId:a,projectsById:(0,Q.useMemo)(()=>new Map(t.map(e=>[e.id,e.name])),[t])}),YX({setActiveProjectId:a}),(0,Q.useEffect)(()=>{oM()},[]);let U=t.find(e=>e.id===n),te=l.pathname.startsWith(`/loops`),ne=l.pathname.startsWith(`/plugins`),re=l.pathname.startsWith(`/docs`)||g!==`agent`&&(te||ne);(0,Q.useLayoutEffect)(()=>{let e=$X({uiMode:g,pathname:l.pathname,loopsOpen:T,pluginsOpen:k,reviewOpen:j});if(e){if(e.kind===`modalize`){if(e.surface===`review`){e.reviewDeliveryId&&M(e.reviewDeliveryId),l.pathname!==e.backgroundPath&&c(e.backgroundPath,{replace:!0});return}e.surface===`loops`?(A(!1),E(!0),e.loopBuilderId&&O(e.loopBuilderId)):(E(!1),A(!0)),m(n),l.pathname!==e.backgroundPath&&c(e.backgroundPath,{replace:!0});return}E(!1),A(!1),M(null),l.pathname!==e.path&&c(e.path,{replace:!0})}},[n,l.pathname,T,c,k,j,m,g]);let{connectionStatus:ie}=UX(),oe=Na(n),ce=g===`agent`?0:mZ,le=(0,Q.useRef)(null),[ue,de]=(0,Q.useState)(typeof window<`u`?window.innerHeight:820);(0,Q.useLayoutEffect)(()=>{if(!W)return;let e=le.current;if(!e)return;let t=()=>de(e.clientHeight);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[r]),(0,Q.useEffect)(()=>{!W||!n||u.ensureProject(n)},[n,u]);let fe=W&&g===`kanban`&&oe.visibility===`hidden`?(0,$.jsx)(sF,{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)(pY,{onAddProject:()=>b(!0),onOpenLoops:()=>{g===`agent`?E(!0):c(`/loops`)},onOpenPlugins:()=>{g===`agent`?A(!0):c(`/plugins`)},onOpenAnalytics:()=>w(!0),onOpenDocs:()=>P(!0),onOpenSettings:()=>S(!0)}),(0,$.jsxs)(`div`,{ref:le,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`&&!re?(0,$.jsx)(wP,{}):(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)(uZ,{})}),(0,$.jsx)(h,{path:`/docs/:category/:slug`,element:(0,$.jsx)(uZ,{})}),Ce&&(0,$.jsx)(h,{path:`/loops`,element:(0,$.jsx)(fZ,{})}),Ce&&(0,$.jsx)(h,{path:`/loops/:id/edit`,element:(0,$.jsx)(pZ,{})}),(0,$.jsx)(h,{path:`/plugins`,element:(0,$.jsx)(cZ,{})}),t.length===0?(0,$.jsx)(h,{path:`*`,element:(0,$.jsx)(LJ,{onAddProject:()=>b(!0)})}):U?(0,$.jsxs)(h,{element:(0,$.jsx)(IJ,{projectName:U.name,children:(0,$.jsx)(PJ,{project:U})},U.id),children:[(0,$.jsx)(h,{path:`/`,element:(0,$.jsx)(bW,{})}),(0,$.jsx)(h,{path:`/jobs`,element:(0,$.jsx)(nZ,{})}),(0,$.jsx)(h,{path:`/jobs/:id`,element:(0,$.jsx)(eZ,{})}),ae&&(0,$.jsx)(h,{path:`/review/:prDeliveryId`,element:(0,$.jsx)(tZ,{})}),(0,$.jsx)(h,{path:`/analytics`,element:(0,$.jsx)(rZ,{})}),(0,$.jsx)(h,{path:`/activity`,element:(0,$.jsx)(iZ,{})}),(0,$.jsx)(h,{path:`/agents`,element:(0,$.jsx)(aZ,{})}),(0,$.jsx)(h,{path:`/code`,element:se?(0,$.jsx)(oZ,{}):(0,$.jsx)(f,{to:`/`,replace:!0})}),(0,$.jsx)(h,{path:`/integrations`,element:(0,$.jsx)(sZ,{})}),(0,$.jsx)(h,{path:`/settings`,element:(0,$.jsx)(IG,{})}),(0,$.jsx)(h,{path:`*`,element:(0,$.jsx)(f,{to:`/`,replace:!0})})]}):(0,$.jsx)(h,{path:`*`,element:(0,$.jsx)(LJ,{onAddProject:()=>b(!0)})})]})})}),W&&n&&U&&(0,$.jsx)(OF,{projectId:n,provider:U.provider,providers:st(U),state:oe,viewportHeight:ue,statusBarHeight:ce}),g!==`agent`&&(0,$.jsx)(WX,{connectionStatus:ie,rightSlot:fe})]}),g===`agent`?!re&&(0,$.jsx)(HP,{}):U&&!re&&(0,$.jsx)(hY,{}),(0,$.jsx)(EY,{open:v,onClose:()=>b(!1),onOpenBuilder:()=>d.builderMode.enter()}),(0,$.jsx)(Wq,{open:x,onClose:()=>S(!1),onOpenOnboarding:()=>{S(!1),ee(!0)}}),(0,$.jsx)(sr,{open:C,onOpenChange:w,children:(0,$.jsx)(ar,{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)(lZ,{})})})})}),(0,$.jsx)(sr,{open:T,onOpenChange:e=>{E(e),e||O(null)},children:(0,$.jsxs)(ar,{showCloseButton:!1,className:`max-w-[96vw] w-[96vw] h-[92vh] max-h-[92vh] overflow-hidden p-0 flex flex-col`,children:[(0,$.jsx)(er,{className:`sr-only`,children:e(`nav:arcSidebar.loops`)}),(0,$.jsx)(Zn,{className:`sr-only`,children:e(`nav:globalSurfaceModal.loopsDescription`)}),(0,$.jsx)(hZ,{surface:`loops`,onClose:()=>{E(!1),O(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:D?(0,$.jsx)(`div`,{className:`h-full`,children:(0,$.jsx)(pZ,{loopId:D,onExit:()=>O(null)})}):(0,$.jsx)(fZ,{onOpenBuilder:O})})})]})}),ae&&(0,$.jsx)(sr,{open:j!==null,onOpenChange:e=>{e||M(null)},children:(0,$.jsxs)(ar,{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)(er,{className:`sr-only`,children:e(`nav:arcSidebar.review`)}),(0,$.jsx)(Zn,{className:`sr-only`,children:e(`nav:globalSurfaceModal.reviewDescription`)}),(0,$.jsx)(hZ,{surface:`review`,onClose:()=>M(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:j&&(0,$.jsx)(tZ,{prDeliveryId:j,onClose:()=>M(null)})})})]})}),(0,$.jsx)(sr,{open:k,onOpenChange:A,children:(0,$.jsxs)(ar,{showCloseButton:!1,className:`max-w-[96vw] w-[96vw] h-[92vh] max-h-[92vh] overflow-hidden p-0 flex flex-col`,children:[(0,$.jsx)(er,{className:`sr-only`,children:e(`nav:arcSidebar.plugins`)}),(0,$.jsx)(Zn,{className:`sr-only`,children:e(`nav:globalSurfaceModal.pluginsDescription`)}),(0,$.jsx)(hZ,{surface:`plugins`,onClose:()=>A(!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)(cZ,{})})})]})}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(dZ,{open:N,onClose:I})}),(0,$.jsx)(jX,{onOpenSettings:()=>S(!0),onOpenAnalytics:()=>w(!0),onOpenDocs:()=>P(!0)}),(0,$.jsx)(tJ,{open:R,onOpenChange:z}),(0,$.jsx)(tY,{open:L,onClose:()=>ee(!1)})]})}function xZ({children:e}){let{activeProjectId:t}=lt();return(0,$.jsx)(Aa,{activeProjectId:t,children:e})}function SZ({children:e}){let{activeProjectId:t}=lt();return(0,$.jsx)(LU,{activeProjectId:t,children:e})}function CZ({children:e}){let{activeProjectId:t}=lt();return(0,$.jsx)(WU,{activeProjectId:t,children:e})}function wZ(){return(0,$.jsx)(`span`,{"aria-hidden":!0,style:{display:`none`}})}function TZ(){let{theme:e}=ha(),t=e.previewSwatches.accents[0],n=e.status.completed,r=e.status.failed,i=e.status.canceled,a=e.status.running;return(0,Bb.createPortal)((0,$.jsx)(ct,{position:`bottom-right`,className:`specrails-toaster`,theme:e.scheme,gap:8,closeButton:!0,visibleToasts:6,icons:{loading:(0,$.jsx)(wZ,{})},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 EZ(){return VK(),null}function DZ(){let e=ci();return VX(),(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)(Je,{url:oe,children:(0,$.jsx)(ma,{children:(0,$.jsxs)(GG,{children:[(0,$.jsx)(NJ,{}),(0,$.jsx)(ut,{isolated:e,children:(0,$.jsxs)(vN,{initialMode:e?`agent`:void 0,persist:!e,children:[!e&&(0,$.jsx)(EZ,{}),(0,$.jsx)(oJ,{}),(0,$.jsx)(LB,{children:(0,$.jsx)(FX,{children:(0,$.jsx)(te,{children:(0,$.jsx)(LP,{children:(0,$.jsx)(xZ,{children:(0,$.jsx)(SZ,{children:(0,$.jsx)(CZ,{children:(0,$.jsx)(_n,{children:(0,$.jsx)(YD,{children:(0,$.jsx)(hi,{secondary:e,children:(0,$.jsx)(GN,{children:(0,$.jsx)(dO,{children:(0,$.jsx)(Ee,{children:(0,$.jsxs)(ye,{children:[(0,$.jsx)(YN,{}),(0,$.jsx)(Lc,{}),e?(0,$.jsx)(kF,{}):(0,$.jsx)(bZ,{}),(0,$.jsx)(KX,{}),(0,$.jsx)(TZ,{})]})})})})})})})})})})})})})})]})})]})})})})})}async function OZ(){await Ye(),Qe(),await Ue(),(0,Mr.createRoot)(document.getElementById(`root`)).render((0,$.jsx)(Q.StrictMode,{children:(0,$.jsx)(v,{children:(0,$.jsx)(DZ,{})})}));let e=document.getElementById(`specrails-splash`);e&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.classList.add(`is-hidden`),setTimeout(()=>e.remove(),300)})})}OZ();export{Mb as $,gI as A,bs as At,tA as B,Bo as Bt,lz as C,Hs as Ct,_L as D,As as Dt,yR as E,js as Et,BA as F,Zo as Ft,sD as G,Mo as Gt,WO as H,Lo as Ht,LA as I,qo as It,Gx as J,to as Jt,xD as K,Ao as Kt,eA as L,Ko as Lt,tI as M,gs as Mt,qN as N,ps as Nt,SL as O,Ds as Ot,Ij as P,is as Pt,Ib as Q,nA as R,Go as Rt,BR as S,Us as St,qR as T,Ns as Tt,ZD as U,Fo as Ut,GO as V,zo as Vt,oD as W,Po as Wt,Lx as X,gi as Xt,Yx as Y,_a as Yt,Ix as Z,YH as _,oc as _t,DG as a,Nc as at,pz as b,Gs as bt,jW as c,Dc as ct,zU as d,xc as dt,Uy as et,xU as f,yc as ft,XH as g,uc as gt,ZH as h,dc as ht,PG as i,Fc as it,_I as j,_s as jt,EI as k,xs as kt,OW as l,wc as lt,NU as m,pc as mt,FG as n,Py as nt,MG as o,Mc as ot,PU as p,_c as pt,Qx as q,Eo as qt,OG as r,Hy as rt,xG as s,Oc as st,UX as t,Ny as tt,nW as u,Sc as ut,zH as v,ic as vt,az as w,zs as wt,ZR as x,Ws as xt,wV as y,nc as yt,$k as z,Wo as zt};