@runfusion/fusion 0.70.2 → 0.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/bin.js +2425 -2183
  2. package/dist/child-process-worker.js +1575 -1491
  3. package/dist/client/.vite/manifest.json +250 -250
  4. package/dist/client/assets/{AgentDetailView-UMM9DyW-.js → AgentDetailView-Bq6qfKGR.js} +5 -5
  5. package/dist/client/assets/{AgentPermissionPolicyEditor-BfNZUiDb.js → AgentPermissionPolicyEditor-Dah1P8IX.js} +2 -2
  6. package/dist/client/assets/{AgentsView-DtC-DVyX.js → AgentsView-Bu8h0vGY.js} +4 -4
  7. package/dist/client/assets/{ChatView-sDJXcOwT.js → ChatView-BTE8fIib.js} +1 -1
  8. package/dist/client/assets/{CommandCenter-B7BECRSV.js → CommandCenter-l4no66mI.js} +1 -1
  9. package/dist/client/assets/{DevServerView-CyW7l6rY.js → DevServerView-Cuxhgjdv.js} +1 -1
  10. package/dist/client/assets/DirectoryPicker-tm1SS2jF.js +1 -0
  11. package/dist/client/assets/{DocumentsView-Dbn8T4ZT.js → DocumentsView-Dg8lFF7X.js} +2 -2
  12. package/dist/client/assets/{EvalsView-DGOBPt3P.js → EvalsView-TccfkTNy.js} +1 -1
  13. package/dist/client/assets/{ExperimentalAgentOnboardingModal-Beno0EK8.js → ExperimentalAgentOnboardingModal-2qAtocIG.js} +1 -1
  14. package/dist/client/assets/{GoalsView-BLxtocMB.js → GoalsView-Du_jIEn2.js} +1 -1
  15. package/dist/client/assets/{InsightsView-DjTpiw1S.js → InsightsView-BxJ327Tj.js} +2 -2
  16. package/dist/client/assets/{MemoryView-BvAhPVCo.js → MemoryView-Blv0YUWC.js} +2 -2
  17. package/dist/client/assets/{PiExtensionsManager-Di3Q9J6V.js → PiExtensionsManager-BUS_ZKwO.js} +2 -2
  18. package/dist/client/assets/{PluginManager-reQpowmU.js → PluginManager-DM5-rNen.js} +1 -1
  19. package/dist/client/assets/{PullRequestView-DLDz9RXL.js → PullRequestView-D7ozwDrc.js} +2 -2
  20. package/dist/client/assets/{ResearchView-BpdpPwyr.js → ResearchView-CRGaOkBH.js} +1 -1
  21. package/dist/client/assets/{SecretsView-BHu1JHnH.js → SecretsView-Nwc-7xGn.js} +1 -1
  22. package/dist/client/assets/{SessionTerminal-rtlAx2uQ.js → SessionTerminal-gC7X57E6.js} +1 -1
  23. package/dist/client/assets/{SettingsModal-Dxz7-SNa.js → SettingsModal-CuEXiFb_.js} +4 -4
  24. package/dist/client/assets/{SettingsModal-B7m-bZlG.js → SettingsModal-q_D1o7T-.js} +1 -1
  25. package/dist/client/assets/{SettingsTextareaRow-5Vb6XYSC.js → SettingsTextareaRow-DnsWtbkh.js} +1 -1
  26. package/dist/client/assets/SetupWizardModal-3-mXX0VJ.js +2 -0
  27. package/dist/client/assets/{SkillsView-CNQaKfLx.js → SkillsView-Dw8m0G-9.js} +1 -1
  28. package/dist/client/assets/{ThemeDropdown-Bhz3TH1Z.js → ThemeDropdown-C7qybW7w.js} +1 -1
  29. package/dist/client/assets/{TodoView-Ccr5rxPw.js → TodoView-r_qHhO28.js} +2 -2
  30. package/dist/client/assets/{WorkflowNodeEditor-BeY_3iQR.js → WorkflowNodeEditor-B0TGhu5B.js} +1 -1
  31. package/dist/client/assets/{app-bX7Aarj6.js → app-0sCAWTFb.js} +1 -1
  32. package/dist/client/assets/{app-BFkCDjfl.js → app-Cndq8AGV.js} +1 -1
  33. package/dist/client/assets/{app-Bx4Tg9WL.js → app-CqpqmC8O.js} +1 -1
  34. package/dist/client/assets/{app-BwKqEIVs.js → app-DjxXVWX9.js} +1 -1
  35. package/dist/client/assets/{app-gasJpw6T.js → app-DrnsOtt9.js} +1 -1
  36. package/dist/client/assets/{app-BLTqCjPk.js → app-Kb21Gl_h.js} +1 -1
  37. package/dist/client/assets/{architectureDiagram-3BPJPVTR-DbmZMyHk.js → architectureDiagram-3BPJPVTR-9REjGWnr.js} +1 -1
  38. package/dist/client/assets/{blockDiagram-GPEHLZMM-BkspaqvN.js → blockDiagram-GPEHLZMM-OATfTc06.js} +1 -1
  39. package/dist/client/assets/{c4Diagram-AAUBKEIU-BfOk6DAf.js → c4Diagram-AAUBKEIU-B-nq1avj.js} +1 -1
  40. package/dist/client/assets/channel-BW-0I-xJ.js +1 -0
  41. package/dist/client/assets/{chunk-2J33WTMH-DbL54v_S.js → chunk-2J33WTMH-Dds2A4Un.js} +1 -1
  42. package/dist/client/assets/{chunk-4BX2VUAB-VAUWnfVr.js → chunk-4BX2VUAB-Dc-jRxxZ.js} +1 -1
  43. package/dist/client/assets/{chunk-55IACEB6-C5h7MxPM.js → chunk-55IACEB6-CKtwSOvQ.js} +1 -1
  44. package/dist/client/assets/{chunk-727SXJPM-CCc56jyj.js → chunk-727SXJPM-DbRZhQCr.js} +1 -1
  45. package/dist/client/assets/{chunk-AQP2D5EJ-CUK6s79q.js → chunk-AQP2D5EJ-Dq_cSIeh.js} +1 -1
  46. package/dist/client/assets/{chunk-FMBD7UC4-COFczZ8r.js → chunk-FMBD7UC4-BmnvYNOo.js} +1 -1
  47. package/dist/client/assets/{chunk-ND2GUHAM-BXTcFeIM.js → chunk-ND2GUHAM-D6nyZn0C.js} +1 -1
  48. package/dist/client/assets/{chunk-QZHKN3VN-BEYAo7eA.js → chunk-QZHKN3VN-FFojVCmd.js} +1 -1
  49. package/dist/client/assets/classDiagram-4FO5ZUOK-DfBIljo4.js +1 -0
  50. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-DfBIljo4.js +1 -0
  51. package/dist/client/assets/{cose-bilkent-S5V4N54A-DqQ74MrB.js → cose-bilkent-S5V4N54A-DysS3-yZ.js} +1 -1
  52. package/dist/client/assets/{dagre-BM42HDAG-D1DsLIdG.js → dagre-BM42HDAG-DgL7uNq4.js} +1 -1
  53. package/dist/client/assets/{dashboard-view-D5F_ho0i.js → dashboard-view-Bu_nB-cd.js} +1 -1
  54. package/dist/client/assets/{dashboard-view-DFy7Ta-E.js → dashboard-view-DlxD_dta.js} +1 -1
  55. package/dist/client/assets/{dashboard-view-CgBE7XiJ.js → dashboard-view-ln6_a3ZY.js} +1 -1
  56. package/dist/client/assets/{diagram-2AECGRRQ-p-547bXh.js → diagram-2AECGRRQ-DTACb17z.js} +1 -1
  57. package/dist/client/assets/{diagram-5GNKFQAL-BE9UnZuh.js → diagram-5GNKFQAL-DqdKDR_d.js} +1 -1
  58. package/dist/client/assets/{diagram-KO2AKTUF-BHTLL-vQ.js → diagram-KO2AKTUF-CCKa3iUW.js} +1 -1
  59. package/dist/client/assets/{diagram-LMA3HP47-CWLbQcuj.js → diagram-LMA3HP47-C2SLmXdM.js} +1 -1
  60. package/dist/client/assets/{diagram-OG6HWLK6-CXUiMHIE.js → diagram-OG6HWLK6-Dz9wXgRN.js} +1 -1
  61. package/dist/client/assets/{erDiagram-TEJ5UH35-Dre62Vsd.js → erDiagram-TEJ5UH35-GGHapzlB.js} +1 -1
  62. package/dist/client/assets/{flowDiagram-I6XJVG4X-BFeMnep3.js → flowDiagram-I6XJVG4X-B3SLxAlP.js} +1 -1
  63. package/dist/client/assets/{folder-open-s7aQO2Ib.js → folder-open-BWBZSyO2.js} +1 -1
  64. package/dist/client/assets/{ganttDiagram-6RSMTGT7-CfrUWiHI.js → ganttDiagram-6RSMTGT7-DYveq-32.js} +1 -1
  65. package/dist/client/assets/{gitGraphDiagram-PVQCEYII-KjKsgpva.js → gitGraphDiagram-PVQCEYII-Bxh-7IFt.js} +1 -1
  66. package/dist/client/assets/index-CiqkhNwQ.css +1 -0
  67. package/dist/client/assets/{index-DF2cd-e3.js → index-D8sgsB8q.js} +268 -268
  68. package/dist/client/assets/{infoDiagram-5YYISTIA-Cb_8B_3K.js → infoDiagram-5YYISTIA-B3_g2TQW.js} +1 -1
  69. package/dist/client/assets/{ishikawaDiagram-YF4QCWOH-8jtlcCaf.js → ishikawaDiagram-YF4QCWOH-CExRn4qZ.js} +1 -1
  70. package/dist/client/assets/{journeyDiagram-JHISSGLW-O6X0tJvH.js → journeyDiagram-JHISSGLW-Dgck68vd.js} +1 -1
  71. package/dist/client/assets/{kanban-definition-UN3LZRKU-BetEnps7.js → kanban-definition-UN3LZRKU-B258_39Z.js} +1 -1
  72. package/dist/client/assets/{mermaid.core-CZbT2qhF.js → mermaid.core-uCT9za93.js} +4 -4
  73. package/dist/client/assets/{mindmap-definition-RKZ34NQL-BRjDmxQK.js → mindmap-definition-RKZ34NQL-DHevd0he.js} +1 -1
  74. package/dist/client/assets/{pieDiagram-4H26LBE5-CJHx1ZvR.js → pieDiagram-4H26LBE5-rTbXqg0x.js} +1 -1
  75. package/dist/client/assets/{puzzle-BJEQBgfR.js → puzzle-D7NHfczg.js} +1 -1
  76. package/dist/client/assets/{quadrantDiagram-W4KKPZXB-D49nAI3y.js → quadrantDiagram-W4KKPZXB-C-N3JbLv.js} +1 -1
  77. package/dist/client/assets/{requirementDiagram-4Y6WPE33-BM4Uv6Jr.js → requirementDiagram-4Y6WPE33-DNINb6LP.js} +1 -1
  78. package/dist/client/assets/{sankeyDiagram-5OEKKPKP-RSKSlyjr.js → sankeyDiagram-5OEKKPKP-UI7SyvRN.js} +1 -1
  79. package/dist/client/assets/{sequenceDiagram-3UESZ5HK-BXpcHAnr.js → sequenceDiagram-3UESZ5HK-pc1RDjwM.js} +1 -1
  80. package/dist/client/assets/{shield-alert-DcsqJWMG.js → shield-alert-c_--H0ce.js} +1 -1
  81. package/dist/client/assets/{standing-instructions-template-CUYzx5D8.js → standing-instructions-template-aTeHy5lT.js} +1 -1
  82. package/dist/client/assets/{stateDiagram-AJRCARHV-CavU8Ef4.js → stateDiagram-AJRCARHV-CEiZfKWc.js} +1 -1
  83. package/dist/client/assets/{stateDiagram-v2-BHNVJYJU-Cq-9bJPI.js → stateDiagram-v2-BHNVJYJU-B7aNz5OD.js} +1 -1
  84. package/dist/client/assets/{timeline-definition-PNZ67QCA-7fHh3hS9.js → timeline-definition-PNZ67QCA-DyE71jn0.js} +1 -1
  85. package/dist/client/assets/{upload-DNwFaPfV.js → upload-YGrA50-5.js} +1 -1
  86. package/dist/client/assets/{users-D-kPhpXu.js → users-fxiLvP6C.js} +1 -1
  87. package/dist/client/assets/{vennDiagram-CIIHVFJN-mCh9G6D5.js → vennDiagram-CIIHVFJN-DX-6Y82D.js} +1 -1
  88. package/dist/client/assets/{wardley-L42UT6IY-DEu4AYE9.js → wardley-L42UT6IY-ew7KQxeH.js} +1 -1
  89. package/dist/client/assets/{wardleyDiagram-YWT4CUSO-DRL0ZyeQ.js → wardleyDiagram-YWT4CUSO-DqSCrJdO.js} +1 -1
  90. package/dist/client/assets/{xychartDiagram-2RQKCTM6-DUpC-GBX.js → xychartDiagram-2RQKCTM6-CEtZEj45.js} +1 -1
  91. package/dist/client/index.html +2 -2
  92. package/dist/client/version.json +1 -1
  93. package/dist/extension.js +1797 -1713
  94. package/dist/plugins/fusion-plugin-dependency-graph/.bundled.reload-1.js +8084 -0
  95. package/dist/plugins/fusion-plugin-grok-runtime/.bundled.reload-2.js +26479 -0
  96. package/package.json +1 -1
  97. package/dist/client/assets/DirectoryPicker-BT3OeDJ3.js +0 -1
  98. package/dist/client/assets/SetupWizardModal-BixsaVgv.js +0 -2
  99. package/dist/client/assets/channel-CABKCAbA.js +0 -1
  100. package/dist/client/assets/classDiagram-4FO5ZUOK-DgshwmmF.js +0 -1
  101. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-DgshwmmF.js +0 -1
  102. package/dist/client/assets/index-Co20nJU4.css +0 -1
@@ -1 +1 @@
1
- import{r as d,j as e}from"./vendor-react-SZ_qB27O.js";import{a1 as Ve,a2 as Te,a3 as We,a4 as ge,a5 as Qe,X as de,a6 as Ke,a7 as Ye,a8 as pe,P as me,a9 as he,s as be,R as ye,aa as Je,N as Xe,ab as Ze,ac as es,ad as ss,ae as ns,af as xe,ag as is,ah as ts,ai as A,aj as as,ak as ls}from"./index-DF2cd-e3.js";import{D as rs}from"./DirectoryPicker-BT3OeDJ3.js";import{u as us}from"./vendor-i18n-GF3RlKbq.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.js";import"./folder-open-s7aQO2Ib.js";const we="fusion-plugin-agent-browser",fe={enabled:{type:"boolean",label:"Enable Agent Browser",group:"General"},installChannel:{type:"enum",label:"Install Channel",enumValues:["stable","beta","nightly"],defaultValue:"stable",group:"General"},commandTimeoutMs:{type:"number",label:"Command Timeout (ms)",defaultValue:12e4,group:"General"},headlessMode:{type:"boolean",label:"Headless Mode",defaultValue:!0,group:"Browser"},allowedDomains:{type:"array",label:"Allowed Domains",itemType:"string",group:"Browser"},promptExecutorSystem:{type:"string",label:"Executor System Prompt",multiline:!0,group:"Prompt Contributions"},promptExecutorTask:{type:"string",label:"Executor Task Prompt",multiline:!0,group:"Prompt Contributions"},promptTriage:{type:"string",label:"Triage Prompt",multiline:!0,group:"Prompt Contributions"},promptReviewer:{type:"string",label:"Reviewer Prompt",multiline:!0,group:"Prompt Contributions"},promptHeartbeat:{type:"string",label:"Heartbeat Prompt",multiline:!0,group:"Prompt Contributions"},skillExposure:{type:"enum",label:"Skill Exposure",enumValues:["none","selected","all"],defaultValue:"selected",group:"Skills"}},je={General:"plugins.agentBrowser.groupGeneral",Browser:"plugins.agentBrowser.groupBrowser","Prompt Contributions":"plugins.agentBrowser.groupPromptContributions",Skills:"plugins.agentBrowser.groupSkills"},Ne={"Enable Agent Browser":"plugins.agentBrowser.labelEnabled","Install Channel":"plugins.agentBrowser.labelInstallChannel","Command Timeout (ms)":"plugins.agentBrowser.labelCommandTimeoutMs","Headless Mode":"plugins.agentBrowser.labelHeadlessMode","Allowed Domains":"plugins.agentBrowser.labelAllowedDomains","Executor System Prompt":"plugins.agentBrowser.labelPromptExecutorSystem","Executor Task Prompt":"plugins.agentBrowser.labelPromptExecutorTask","Triage Prompt":"plugins.agentBrowser.labelPromptTriage","Reviewer Prompt":"plugins.agentBrowser.labelPromptReviewer","Heartbeat Prompt":"plugins.agentBrowser.labelPromptHeartbeat","Skill Exposure":"plugins.agentBrowser.labelSkillExposure"},Se=[{id:"fusion-plugin-hermes-runtime",name:"Hermes Runtime",description:"Runtime provider for Hermes CLI-backed execution.",category:"runtime",path:"./plugins/fusion-plugin-hermes-runtime",experimental:!0},{id:"fusion-plugin-paperclip-runtime",name:"Paperclip Runtime",description:"Runtime provider for Paperclip agent connections.",category:"runtime",path:"./plugins/fusion-plugin-paperclip-runtime"},{id:"fusion-plugin-openclaw-runtime",name:"OpenClaw Runtime",description:"Runtime provider for OpenClaw execution.",category:"runtime",path:"./plugins/fusion-plugin-openclaw-runtime",experimental:!0},{id:"fusion-plugin-droid-runtime",name:"Droid Runtime",description:"Runtime provider for Droid CLI execution.",category:"runtime",path:"./plugins/fusion-plugin-droid-runtime",experimental:!0},{id:"fusion-plugin-dependency-graph",name:"Dependency Graph",description:"Dashboard plugin for task dependency graph visualization.",category:"integration",path:"./plugins/fusion-plugin-dependency-graph"},{id:"fusion-plugin-reports",name:"Reports",description:"View report history, compare runs side-by-side, and export standalone HTML summaries.",category:"integration",path:"./plugins/fusion-plugin-reports"},{id:"fusion-plugin-whatsapp-chat",name:"WhatsApp Chat",description:"Pairs to WhatsApp Web (multi-device) with QR or pairing code, then bridges direct chats to a Fusion agent.",category:"integration",path:"./plugins/fusion-plugin-whatsapp-chat"},{id:"fusion-plugin-cli-printing-press",name:"CLI Printing Press",description:"Guided wizard for drafting external service CLI definitions.",category:"integration",path:"./plugins/fusion-plugin-cli-printing-press"},{id:"fusion-plugin-compound-engineering",name:"Compound Engineering",description:"A dedicated dashboard surface for compound-engineering artifacts and interactive ce-* sessions.",category:"integration",path:"./plugins/fusion-plugin-compound-engineering"},{id:"fusion-plugin-quality",name:"Quality",description:"Task QA tab and Quality hub: preview servers, test runs, reports, screenshots, and suggested cases.",category:"integration",path:"./plugins/fusion-plugin-quality"},{id:"fusion-plugin-linear-import",name:"Linear Import",description:"Browse Linear issues and import selected issues as Fusion triage tasks through plugin-owned settings.",category:"integration",path:"./plugins/fusion-plugin-linear-import"},{id:we,name:"Agent Browser",description:"Built-in integration metadata. Package install support lands in FN-3101.",category:"integration",hasSetup:!0}],L={started:"var(--color-success)",loaded:"var(--color-warning)",error:"var(--color-error)",stopped:"var(--color-muted)",installed:"var(--color-info)"};function os(r){const o=r.settingsSchema,n=o&&Object.keys(o).length>0;return r.id!==we?n?o:void 0:n?{...fe,...o}:fe}function cs(r){const o=new Map,n=[];for(const[N,y]of Object.entries(r))if(y.group){const R=o.get(y.group)??[];R.push([N,y]),o.set(y.group,R)}else n.push([N,y]);return{grouped:o,ungrouped:n}}function ve(r,o="plugin-error-text"){return r.state!=="error"||!r.error?null:e.jsx("p",{className:o,title:r.error,children:r.error})}function js({addToast:r,projectId:o}){const{t:n}=us("app"),[N,y]=d.useState([]),[R,M]=d.useState(!0),[Ce,D]=d.useState(!1),[B,G]=d.useState(""),[U,$]=d.useState(!1),[q,V]=d.useState(!1),[P,T]=d.useState(null),[c,O]=d.useState(null),[m,x]=d.useState({}),[Re,W]=d.useState(!1),[Q,K]=d.useState(null),[Y,Pe]=d.useState([]),[Ie,J]=d.useState(!0),[X,Z]=d.useState(null),[b,Ee]=d.useState(""),[f,Be]=d.useState(""),[ke,ee]=d.useState(null),I=d.useRef(null),[Fe,z]=d.useState({}),[Ae,se]=d.useState(null),[k,ne]=d.useState(null),[Le,ie]=d.useState(null),{confirm:De}=Ve(),h=d.useCallback(async()=>{try{M(!0);const s=await Te(o);y(s)}catch(s){r(n("plugins.loadFailed","Failed to load plugins: {{error}}",{error:s instanceof Error?s.message:String(s)}),"error")}finally{M(!1)}},[o,r]),S=d.useCallback(async(s=b,i=f)=>{try{J(!0),Z(null);const l=await We(s,i||void 0,o);Pe(l)}catch(l){const u=l instanceof Error?l.message:String(l);Z(u)}finally{J(!1)}},[o,f,b]);d.useEffect(()=>{h()},[h]),d.useEffect(()=>(I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{S(b,f)},300),()=>{I.current&&clearTimeout(I.current)}),[S,f,b]),d.useEffect(()=>{const s=Se.filter(l=>l.hasSetup&&N.some(u=>u.id===l.id));if(s.length===0)return;let i=!1;return Promise.all(s.map(async l=>{try{const u=await ge(l.id,o);if(i)return;z(g=>({...g,[l.id]:u}))}catch{if(i)return;z(u=>({...u,[l.id]:{hasSetup:!0,setupCheckDeferred:!0,deferredReason:"plugin-not-started",pluginState:"installed"}}))}})),()=>{i=!0}},[N,o]);const Ge=d.useRef([]);Ge.current=N,d.useEffect(()=>{const s=o?`?projectId=${encodeURIComponent(o)}`:"",i=l=>{try{const u=JSON.parse(l.data);if(u.scope==="project"&&(u.projectId??o)!==o)return;switch(u.transition){case"installing":case"enabled":case"disabled":case"settings-updated":S(b,f),y(g=>{const a=g.findIndex(t=>t.id===u.pluginId);if(a>=0){const t=[...g];return t[a]={...t[a],enabled:u.enabled,state:u.state,settings:u.settings,error:u.error},t}else return h(),g});break;case"state-changed":y(g=>{const a=g.findIndex(t=>t.id===u.pluginId);if(a>=0){const t=[...g];return t[a]={...t[a],state:u.state,error:u.error},t}return g});break;case"uninstalled":y(g=>g.filter(a=>a.id!==u.pluginId)),S(b,f);break;case"error":y(g=>{const a=g.findIndex(t=>t.id===u.pluginId);if(a>=0){const t=[...g];return t[a]={...t[a],state:u.state,error:u.error},t}return g});break}}catch{}};return Qe(`/api/events${s}`,{events:{"plugin:lifecycle":i},onReconnect:()=>{h(),S(b,f)}})},[o,h,S,f,b]);const te=async()=>{if(!B.trim()){r(n("plugins.installPathRequired","Please enter a plugin path"),"error");return}try{$(!0),await A({path:B,...q?{aiScanOnLoad:!0}:{}},o),r(n("plugins.installedGlobally","Plugin installed globally"),"success"),D(!1),G(""),V(!1),await h()}catch(s){r(n("plugins.installFailed","Failed to install plugin: {{error}}",{error:s instanceof Error?s.message:String(s)}),"error")}finally{$(!1)}},Oe=async s=>{if(!s.path){r(n("plugins.builtinNoPackage","{{name}} is built in and does not have an installable package yet",{name:s.name}),"warning");return}try{K(s.id),await A({path:s.path},o),r(n("plugins.builtinInstalledGlobally","{{name}} installed globally",{name:s.name}),"success"),await h()}catch(i){r(n("plugins.builtinInstallFailed","Failed to install {{name}}: {{error}}",{name:s.name,error:i instanceof Error?i.message:String(i)}),"error")}finally{K(null)}},ze=async s=>{if(!s.path){r(n("plugins.registryNotInstallable","{{name}} is not available for one-click install yet",{name:s.name}),"warning");return}try{ee(s.id),await A({path:s.path},o),r(n("plugins.registryInstalled","{{name}} installed and enabled",{name:s.name}),"success"),await h(),await S(b,f)}catch(i){r(n("plugins.registryInstallFailed","Failed to install {{name}}: {{error}}",{name:s.name,error:i instanceof Error?i.message:String(i)}),"error")}finally{ee(null)}},ae=async s=>{try{ne(s.id);const i=await ls(s.id,o);if(!i.success){r(n("plugins.setupInstallFailed","Failed to install {{name}} setup: {{error}}",{name:s.name,error:i.error??n("plugins.unknownError","unknown error")}),"error");return}r(n("plugins.setupInstalled","{{name}} setup installed",{name:s.name}),"success"),se(s.id);const l=await ge(s.id,o);z(u=>({...u,[s.id]:l}))}catch(i){r(n("plugins.setupInstallFailed","Failed to install {{name}} setup: {{error}}",{name:s.name,error:i instanceof Error?i.message:String(i)}),"error")}finally{ne(null),se(null)}},_=async s=>{try{const i=await is(s.id,o);if(i.state==="error"){r(n("plugins.enableFailed","Failed to enable {{name}}: {{error}}",{name:s.name,error:i.error??n("plugins.unknownError","unknown error")}),"error"),await h();return}r(n("plugins.enabledForProject","{{name}} enabled for this project",{name:s.name}),"success"),await h()}catch(i){r(n("plugins.enablePluginFailed","Failed to enable plugin: {{error}}",{error:i instanceof Error?i.message:String(i)}),"error")}},H=async s=>{try{await xe(s.id,o),r(n("plugins.disabledForProject","{{name}} disabled for this project",{name:s.name}),"success"),await h()}catch(i){r(n("plugins.disablePluginFailed","Failed to disable plugin: {{error}}",{error:i instanceof Error?i.message:String(i)}),"error")}},_e=async(s,i)=>{if(i){i.enabled?await H(i):await _(i);return}if(!s.path){r(n("plugins.builtinNoPackage","{{name}} is built in and does not have an installable package yet",{name:s.name}),"warning");return}try{ie(s.id);const l=await A({path:s.path},o);await xe(l.id,o),r(n("plugins.disabledForProject","{{name}} disabled for this project",{name:s.name}),"success"),await h()}catch(l){r(n("plugins.disablePluginFailed","Failed to disable plugin: {{error}}",{error:l instanceof Error?l.message:String(l)}),"error")}finally{ie(null)}},le=async s=>{try{T(s.id),await ns(s.id,o),r(n("plugins.reloaded","{{name}} reloaded",{name:s.name}),"success"),await h()}catch(i){r(n("plugins.reloadFailed","Failed to reload plugin: {{error}}",{error:i instanceof Error?i.message:String(i)}),"error")}finally{T(null)}},re=async s=>{if(await De({title:n("plugins.uninstallTitle","Uninstall Plugin Globally"),message:n("plugins.uninstallConfirm",'Are you sure you want to uninstall "{{name}}" globally (all projects)?',{name:s.name}),danger:!0}))try{await ts(s.id,o),r(n("plugins.uninstalledGlobally","{{name}} uninstalled globally",{name:s.name}),"success"),await h(),O(null)}catch(l){r(n("plugins.uninstallFailed","Failed to uninstall plugin: {{error}}",{error:l instanceof Error?l.message:String(l)}),"error")}},He=async(s,i)=>{try{await Ze(s.id,{aiScanOnLoad:i},o),r(i?n("plugins.aiScanEnabled","AI scan on load enabled"):n("plugins.aiScanDisabled","AI scan on load disabled"),"success"),await h()}catch(l){r(n("plugins.updateFailed","Failed to update plugin: {{error}}",{error:l instanceof Error?l.message:String(l)}),"error")}},Me=async s=>{try{await es(s.id,o),r(n("plugins.rescanned","{{name}} rescanned",{name:s.name}),"success"),await h()}catch(i){r(n("plugins.rescanFailed","Failed to rescan plugin: {{error}}",{error:i instanceof Error?i.message:String(i)}),"error")}},F=async s=>{O(s);try{W(!0);const i=await as(s.id,o);x(i)}catch{x({})}finally{W(!1)}},Ue=async()=>{if(c)try{await ss(c.id,m,o),r(n("plugins.settingsSaved","Settings saved"),"success")}catch(s){r(n("plugins.saveSettingsFailed","Failed to save settings: {{error}}",{error:s instanceof Error?s.message:String(s)}),"error")}};if(c)return e.jsxs("div",{className:"plugin-manager-detail","data-testid":"plugin-manager-detail",children:[e.jsxs("div",{className:"plugin-manager-detail-header",children:[e.jsx("button",{className:"btn-icon",onClick:()=>O(null),"aria-label":n("plugins.backToList","Back to plugin list"),children:e.jsx(de,{size:16})}),e.jsxs("div",{className:"plugin-detail-title",children:[e.jsxs("div",{className:"plugin-detail-title-copy",children:[e.jsx("h4",{className:"plugin-detail-name",children:c.name}),ve(c,"plugin-error-text plugin-error-text--detail")]}),e.jsx("span",{className:"plugin-state-badge",style:{color:L[c.state]||L.installed},children:c.state})]})]}),e.jsxs("div",{className:"plugin-detail-content",children:[e.jsxs("div",{className:"plugin-detail-card",children:[c.description&&e.jsx("p",{className:"plugin-description",children:c.description}),c.author&&e.jsxs("p",{className:"plugin-detail-meta-row",children:[e.jsx("span",{className:"text-muted",children:n("plugins.author","Author:")}),c.author]}),c.homepage&&e.jsxs("p",{className:"plugin-detail-meta-row plugin-homepage",children:[e.jsx("span",{className:"text-muted",children:n("plugins.homepage","Homepage:")}),e.jsxs("a",{href:c.homepage,target:"_blank",rel:"noopener noreferrer",children:[c.homepage,e.jsx(Ke,{size:12})]})]}),e.jsxs("p",{className:"plugin-detail-meta-row",children:[e.jsx("span",{className:"text-muted",children:n("plugins.version","Version:")}),c.version]})]}),e.jsxs("div",{className:"plugin-detail-card",children:[e.jsx("h5",{className:"plugin-detail-section-heading",children:n("plugins.securityScan","Security Scan")}),e.jsxs("div",{className:"plugin-security-row",children:[e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:!!c.aiScanOnLoad,onChange:s=>void He(c,s.target.checked)}),n("plugins.enableAiScanBeforeLoad","Enable AI scan before load/reload")]}),e.jsxs("button",{className:"btn btn-secondary btn-sm",onClick:()=>void Me(c),children:[e.jsx(Ye,{size:14})," ",n("plugins.rescanAndReload","Rescan and Reload")]})]}),e.jsx("p",{className:"text-muted",children:n("plugins.aiScanHint","Turning this on only updates configuration. Use Rescan and Reload to run it now.")}),c.lastSecurityScan?e.jsxs("div",{className:"plugin-security-results",children:[e.jsxs("div",{className:"plugin-security-header",children:[e.jsx("span",{className:`plugin-state-badge plugin-security-badge plugin-security-badge--${c.lastSecurityScan.verdict}`,children:c.lastSecurityScan.verdict}),e.jsx("span",{className:"text-muted",children:c.lastSecurityScan.scannedAt})]}),e.jsx("p",{className:"plugin-security-summary",children:c.lastSecurityScan.summary}),e.jsxs("details",{children:[e.jsx("summary",{children:n("plugins.findings","Findings ({{count}})",{count:c.lastSecurityScan.findings.length})}),e.jsx("ul",{className:"plugin-security-findings",children:c.lastSecurityScan.findings.map((s,i)=>e.jsxs("li",{children:[e.jsx("strong",{children:s.severity})," ",s.category," — ",s.file,": ",s.reason]},`${s.file}-${i}`))})]})]}):e.jsx("p",{className:"text-muted",children:n("plugins.noSecurityScan","No security scan has been run yet.")})]}),e.jsxs("div",{className:"plugin-detail-card",children:[e.jsx("h5",{className:"plugin-detail-section-heading",children:n("plugins.settings","Settings")}),Re?e.jsx("p",{className:"text-muted",children:e.jsx(pe,{label:n("plugins.loading","Loading...")})}):(()=>{const s=os(c);return s&&Object.keys(s).length>0?e.jsxs("div",{className:"plugin-settings-form",children:[(()=>{const{grouped:i,ungrouped:l}=cs(s),u=[];l.length>0&&u.push({title:null,entries:l});for(const[g,a]of i.entries())u.push({title:g,entries:a});return u.map(g=>e.jsxs("div",{className:g.title?"plugin-settings-group":void 0,children:[g.title&&e.jsx("h6",{className:"plugin-settings-group-heading",children:je[g.title]?n(je[g.title],g.title):g.title}),g.entries.map(([a,t])=>{const v=`setting-${a}-help`,E=t.label?Ne[t.label]?n(Ne[t.label],t.label):t.label:a;return e.jsxs("div",{className:"form-group",children:[e.jsxs("label",{htmlFor:`setting-${a}`,children:[E,t.required&&" *"]}),t.type==="string"&&!t.multiline&&e.jsx("input",{className:"input",type:"text",id:`setting-${a}`,value:m[a]??"",onChange:p=>x({...m,[a]:p.target.value}),placeholder:t.description,"aria-describedby":t.description&&!t.required?v:void 0}),t.type==="string"&&t.multiline&&e.jsx("textarea",{className:"input",id:`setting-${a}`,rows:4,value:m[a]??"",onChange:p=>x({...m,[a]:p.target.value}),placeholder:t.description,"aria-describedby":t.description&&!t.required?v:void 0}),t.type==="password"&&e.jsx("input",{className:"input",type:"password",id:`setting-${a}`,value:m[a]??"",onChange:p=>x({...m,[a]:p.target.value}),placeholder:t.description,"aria-describedby":t.description&&!t.required?v:void 0}),t.type==="number"&&e.jsx("input",{className:"input",type:"number",id:`setting-${a}`,value:m[a]??"",onChange:p=>x({...m,[a]:Number(p.target.value)}),"aria-describedby":t.description&&!t.required?v:void 0}),t.type==="boolean"&&e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:m[a]??!1,onChange:p=>x({...m,[a]:p.target.checked})}),t.description]}),t.type==="enum"&&e.jsxs("select",{className:"select",id:`setting-${a}`,value:m[a]??"",onChange:p=>x({...m,[a]:p.target.value}),"aria-describedby":t.description&&!t.required?v:void 0,children:[e.jsx("option",{value:"",children:n("plugins.selectOption","Select...")}),t.enumValues?.map(p=>e.jsx("option",{value:p,children:p},p))]}),t.type==="array"&&e.jsxs("div",{className:"plugin-settings-array",children:[m[a]?.map((p,j)=>e.jsxs("div",{className:"plugin-settings-array-item",children:[e.jsx("input",{className:"input",type:t.itemType==="number"?"number":"text",value:p??"",onChange:C=>{const w=C.target.value,ce=[...m[a]||[]];ce[j]=t.itemType==="number"?Number(w):w,x({...m,[a]:ce})}}),e.jsx("button",{className:"btn-icon",onClick:()=>{const w=[...m[a]||[]];w.splice(j,1),x({...m,[a]:w})},"aria-label":n("plugins.removeItem","Remove item"),children:e.jsx(de,{size:14})})]},j)),e.jsxs("button",{className:"btn btn-secondary",onClick:()=>{const p=m[a]||[],j=t.itemType==="number"?0:"";x({...m,[a]:[...p,j]})},children:[e.jsx(me,{size:14})," ",n("plugins.addItem","Add Item")]})]}),t.description&&!t.required&&!t.multiline&&e.jsx("span",{id:v,className:"form-help",children:t.description})]},a)})]},g.title??"ungrouped"))})(),e.jsx("button",{className:"btn btn-primary",onClick:Ue,children:n("plugins.saveSettings","Save Settings")})]}):e.jsx("p",{className:"text-muted",children:n("plugins.noConfigurableSettings","No configurable settings.")})})()]}),e.jsxs("div",{className:"plugin-detail-actions",children:[c.state==="started"&&e.jsxs("button",{className:"btn btn-secondary",onClick:()=>le(c),disabled:P===c.id,children:[e.jsx(he,{size:14,className:P===c.id?"spin":""}),P===c.id?n("plugins.reloading","Reloading..."):n("plugins.reload","Reload")]}),c.enabled?e.jsx("button",{className:"btn btn-secondary",onClick:()=>H(c),children:n("plugins.disableInProject","Disable in Project")}):e.jsx("button",{className:"btn btn-primary",onClick:()=>_(c),children:n("plugins.enableInProject","Enable in Project")}),e.jsxs("button",{className:"btn btn-danger",onClick:()=>re(c),children:[e.jsx(be,{size:14})," ",n("plugins.uninstallGlobally","Uninstall Globally")]})]})]})]});const ue=new Map(N.map(s=>[s.id,s])),oe=N,$e=()=>e.jsxs("section",{className:"plugin-registry-section","aria-label":n("plugins.browseRegistry","Browse Registry"),children:[e.jsxs("div",{className:"plugin-registry-header",children:[e.jsxs("div",{className:"plugin-registry-heading-copy",children:[e.jsx("h4",{className:"plugin-registry-heading",children:n("plugins.browseRegistry","Browse Registry")}),e.jsx("p",{className:"plugin-registry-description",children:n("plugins.registryDescription","Discover curated runtimes and integrations that can be added to this Fusion workspace.")})]}),e.jsxs("div",{className:"plugin-registry-controls",children:[e.jsxs("label",{className:"plugin-registry-category-label",children:[e.jsx("span",{className:"sr-only",children:n("plugins.registryCategory","Registry category")}),e.jsxs("select",{className:"select plugin-registry-category-select",value:f,onChange:s=>Be(s.target.value),"aria-label":n("plugins.registryCategory","Registry category"),children:[e.jsx("option",{value:"",children:n("plugins.registryCategoryAll","All Categories")}),e.jsx("option",{value:"runtime",children:n("plugins.registryCategoryRuntime","Runtime")}),e.jsx("option",{value:"integration",children:n("plugins.registryCategoryIntegration","Integration")})]})]}),e.jsxs("label",{className:"plugin-registry-search-label",children:[e.jsx("span",{className:"sr-only",children:n("plugins.searchRegistry","Search registry")}),e.jsx("input",{className:"input plugin-registry-search-input",type:"search",value:b,onChange:s=>Ee(s.target.value),placeholder:n("plugins.searchRegistryPlaceholder","Search registry plugins")})]})]})]}),Ie?e.jsxs("div",{className:"plugin-registry-state",role:"status",children:[e.jsx(ye,{size:14,className:"spin"}),n("plugins.registryLoading","Loading registry...")]}):X?e.jsxs("div",{className:"plugin-registry-state plugin-registry-state--error",role:"alert",children:[e.jsx("span",{children:n("plugins.registryLoadFailed","Failed to load registry: {{error}}",{error:X})}),e.jsx("button",{className:"btn btn-secondary btn-sm plugin-registry-retry",onClick:()=>void S(b,f),children:n("plugins.retry","Retry")})]}):Y.length===0?e.jsx("div",{className:"plugin-registry-state",children:b.trim()?n("plugins.registryEmptySearch","No registry plugins match your search."):n("plugins.registryEmpty","No registry plugins are available.")}):e.jsx("div",{className:"plugin-registry-list","aria-label":n("plugins.registryPluginResults","Registry plugin results"),children:Y.map(s=>{const i=ue.get(s.id),l=ke===s.id;return e.jsxs("div",{className:"plugin-registry-item",children:[e.jsxs("div",{className:"plugin-registry-meta",children:[e.jsxs("div",{className:"plugin-registry-title-row",children:[e.jsx("span",{className:"plugin-registry-name",children:s.name}),e.jsxs("span",{className:"plugin-registry-version",children:["v",s.version]}),e.jsx("span",{className:"plugin-registry-badge",children:s.category}),s.installed&&e.jsxs("span",{className:"plugin-registry-status plugin-registry-status--installed",children:[n("plugins.statusInstalled","Installed"),s.installedVersion&&s.installedVersion!==s.version?` · v${s.installedVersion}`:""]})]}),e.jsx("span",{className:"plugin-registry-description-text",children:s.description}),e.jsx("span",{className:"plugin-registry-author",children:n("plugins.registryByAuthor","By {{author}}",{author:s.author})})]}),e.jsx("div",{className:"plugin-registry-actions",children:s.installed?e.jsx("button",{className:"btn btn-secondary btn-sm plugin-registry-action",onClick:()=>{i?F(i):h()},children:n("plugins.manage","Manage")}):s.canInstall?e.jsx("button",{className:"btn btn-primary btn-sm plugin-registry-action",onClick:()=>void ze(s),disabled:l,children:l?n("plugins.installing","Installing..."):n("plugins.installFromRegistry","Install")}):e.jsx("span",{className:"plugin-registry-coming-soon",children:n("plugins.registryComingSoon","Coming Soon")})})]},s.id)})})]}),qe=()=>e.jsxs("section",{className:"plugin-builtins-section","aria-label":n("plugins.builtinPlugins","Built-in Plugins"),children:[e.jsxs("div",{className:"plugin-builtins-header",children:[e.jsx("h4",{className:"plugin-builtins-heading",children:n("plugins.builtinPlugins","Built-in Plugins")}),e.jsx("p",{className:"plugin-builtins-description",children:n("plugins.builtinPluginsCatalog","Built-in plugin catalog for runtimes and integrations.")})]}),e.jsx("div",{className:"plugin-builtins-list","aria-label":n("plugins.builtinPluginRecommendations","Built-in plugin recommendations"),children:Se.map(s=>{const i=ue.get(s.id),l=!!i,u=Fe[s.id],g=!!(u&&"setupCheckDeferred"in u&&u.setupCheckDeferred),a=u&&"status"in u?u.status:void 0,t=l&&s.hasSetup&&u?.hasSetup&&!g&&i?.state==="started"&&(a==="not-installed"||a==="error"),v=l&&u?.hasSetup&&a==="installed",E=Ae===s.id,p=!s.path,j=s.category==="runtime",C=i?i.enabled:!0,w=Le===s.id;return e.jsxs("div",{className:"plugin-builtins-item",children:[e.jsxs("div",{className:"plugin-builtins-meta",children:[e.jsx("span",{className:"plugin-builtins-name",children:s.name}),s.experimental&&e.jsx("span",{className:"plugin-builtins-runtime-badge",children:n("plugins.experimental","Experimental")}),e.jsx("span",{className:"plugin-builtins-runtime-badge",children:s.category}),e.jsx("span",{className:`plugin-builtins-status ${l?"plugin-builtins-status--installed":"plugin-builtins-status--available"}`,children:l?n("plugins.statusInstalled","Installed"):p?n("plugins.statusBuiltIn","Built in"):n("plugins.statusNotInstalled","Not installed")}),j&&!C&&e.jsx("span",{className:"plugin-builtins-setup-status plugin-builtins-setup-status--warning",children:n("plugins.builtinDisabled","Disabled")}),t&&e.jsx("span",{className:"plugin-builtins-setup-status plugin-builtins-setup-status--warning",children:n("plugins.setupRequired","Setup required")}),v&&e.jsx("span",{className:"plugin-builtins-setup-status plugin-builtins-setup-status--ready",children:n("plugins.setupReady","Setup ready")}),E&&e.jsx("span",{className:"plugin-builtins-setup-status plugin-builtins-setup-status--pending",children:n("plugins.checkingSetup","Checking setup...")}),g&&e.jsx("span",{className:"plugin-builtins-setup-status plugin-builtins-setup-status--deferred",children:n("plugins.startPluginToCheckSetup","Start plugin to check setup")}),e.jsx("span",{className:"plugin-builtins-description-text",children:s.description})]}),e.jsxs("div",{className:"plugin-builtins-actions",children:[j&&e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",checked:C,onChange:()=>void _e(s,i),disabled:w,"aria-label":C?n("plugins.disablePlugin","Disable {{name}}",{name:s.name}):n("plugins.enablePlugin","Enable {{name}}",{name:s.name})}),e.jsx("span",{className:"toggle-slider"})]}),p?l&&t?e.jsx("button",{className:"btn btn-primary btn-sm",onClick:()=>void ae(s),disabled:k===s.id||E,children:k===s.id?n("plugins.settingUp","Setting up..."):n("plugins.installSetup","Install Setup")}):l&&i?e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>void F(i),children:n("plugins.manage","Manage")}):j?null:e.jsx("span",{className:"plugin-builtins-metadata-only",children:n("plugins.builtinMetadataOnly","Built-in metadata only")}):e.jsx("button",{className:`btn ${l&&!t?"btn-secondary":"btn-primary"} btn-sm`,onClick:()=>{if(!l){Oe(s);return}if(t){ae(s);return}i&&F(i)},disabled:Q===s.id||k===s.id||E,children:l?t?k===s.id?n("plugins.settingUp","Setting up..."):n("plugins.installSetup","Install Setup"):n("plugins.manage","Manage"):Q===s.id?n("plugins.installing","Installing..."):n("plugins.installNamed","Install {{name}}",{name:s.name})})]})]},s.id)})})]});return e.jsxs("div",{className:"plugin-manager","data-testid":"plugin-manager",children:[e.jsxs("div",{className:"plugin-manager-header",children:[e.jsx("span",{className:"plugin-manager-header-title",children:n("plugins.installedPlugins","Installed Plugins")}),e.jsxs("div",{className:"plugin-manager-actions",children:[e.jsxs("button",{className:"btn btn-sm",onClick:h,title:n("plugins.refresh","Refresh"),"aria-label":n("plugins.refreshPluginList","Refresh plugin list"),children:[e.jsx(ye,{size:14,className:R?"spin":""}),n("plugins.refresh","Refresh")]}),e.jsxs("button",{className:"btn btn-primary btn-sm",onClick:()=>D(!0),children:[e.jsx(me,{size:14})," ",n("plugins.install","Install")]})]})]}),Ce&&e.jsxs("div",{className:"plugin-install-form",children:[e.jsx("p",{className:"plugin-install-hint",children:n("plugins.installHint","Browse to a plugin package root (contains manifest.json) or a built dist directory.")}),e.jsx(rs,{value:B,onChange:G,placeholder:n("plugins.installPathPlaceholder","Absolute path to plugin directory or dist folder"),onInputKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),te())}}),e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:q,onChange:s=>V(s.target.checked)}),n("plugins.enableAiSecurityScan","Enable AI security scan on load")]}),e.jsxs("div",{className:"plugin-install-actions",children:[e.jsx("button",{className:"btn btn-primary",onClick:te,disabled:U||!B.trim(),children:U?n("plugins.installing","Installing..."):n("plugins.installPluginGlobally","Install Plugin Globally")}),e.jsx("button",{className:"btn btn-secondary",onClick:()=>{D(!1),G("")},children:n("plugins.cancel","Cancel")})]})]}),R?e.jsx("div",{className:"settings-empty-state",children:e.jsx(pe,{label:n("plugins.loadingPlugins","Loading plugins...")})}):e.jsxs(e.Fragment,{children:[oe.length===0?e.jsxs("div",{className:"settings-empty-state",children:[e.jsx(Je,{size:32,className:"text-muted"}),e.jsx("p",{children:n("plugins.noPluginsInstalled","No plugins installed.")}),e.jsx("p",{className:"text-muted",children:n("plugins.noPluginsHint","Install a plugin to get started, or use the built-in catalog below.")})]}):e.jsx("div",{className:"plugin-list",children:oe.map(s=>e.jsxs("div",{className:"plugin-item",children:[e.jsx("div",{className:"plugin-info",children:e.jsxs("div",{className:"plugin-copy",children:[e.jsxs("div",{className:"plugin-copy-header",children:[e.jsx("span",{className:"plugin-name",children:s.name}),e.jsxs("span",{className:"plugin-version text-muted",children:["v",s.version]}),e.jsx("span",{className:"plugin-state-badge",style:{color:L[s.state]||L.installed},children:s.state})]}),ve(s)]})}),e.jsxs("div",{className:"plugin-actions",children:[s.state==="started"&&e.jsx("button",{className:"btn-icon",onClick:()=>le(s),disabled:P===s.id,title:n("plugins.reload","Reload"),children:e.jsx(he,{size:14,className:P===s.id?"spin":""})}),e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",checked:s.enabled,onChange:()=>s.enabled?H(s):_(s),"aria-label":s.enabled?n("plugins.disablePlugin","Disable {{name}}",{name:s.name}):n("plugins.enablePlugin","Enable {{name}}",{name:s.name})}),e.jsx("span",{className:"toggle-slider"})]}),e.jsx("button",{className:"btn-icon",onClick:()=>F(s),title:n("plugins.settings","Settings"),children:e.jsx(Xe,{size:14})}),e.jsx("button",{className:"btn-icon",onClick:()=>re(s),title:n("plugins.uninstallGloballyTitle","Uninstall globally"),children:e.jsx(be,{size:14})})]})]},s.id))}),qe(),$e()]})]})}export{fe as AGENT_BROWSER_SETTINGS_SCHEMA,we as BUILTIN_AGENT_BROWSER_PLUGIN_ID,Se as BUILTIN_PLUGINS,js as PluginManager,L as STATE_COLORS};
1
+ import{r as d,j as e}from"./vendor-react-SZ_qB27O.js";import{a1 as Ve,a2 as Te,a3 as We,a4 as ge,a5 as Qe,X as de,a6 as Ke,a7 as Ye,a8 as pe,P as me,a9 as he,s as be,R as ye,aa as Je,N as Xe,ab as Ze,ac as es,ad as ss,ae as ns,af as xe,ag as is,ah as ts,ai as A,aj as as,ak as ls}from"./index-D8sgsB8q.js";import{D as rs}from"./DirectoryPicker-tm1SS2jF.js";import{u as us}from"./vendor-i18n-GF3RlKbq.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.js";import"./folder-open-BWBZSyO2.js";const we="fusion-plugin-agent-browser",fe={enabled:{type:"boolean",label:"Enable Agent Browser",group:"General"},installChannel:{type:"enum",label:"Install Channel",enumValues:["stable","beta","nightly"],defaultValue:"stable",group:"General"},commandTimeoutMs:{type:"number",label:"Command Timeout (ms)",defaultValue:12e4,group:"General"},headlessMode:{type:"boolean",label:"Headless Mode",defaultValue:!0,group:"Browser"},allowedDomains:{type:"array",label:"Allowed Domains",itemType:"string",group:"Browser"},promptExecutorSystem:{type:"string",label:"Executor System Prompt",multiline:!0,group:"Prompt Contributions"},promptExecutorTask:{type:"string",label:"Executor Task Prompt",multiline:!0,group:"Prompt Contributions"},promptTriage:{type:"string",label:"Triage Prompt",multiline:!0,group:"Prompt Contributions"},promptReviewer:{type:"string",label:"Reviewer Prompt",multiline:!0,group:"Prompt Contributions"},promptHeartbeat:{type:"string",label:"Heartbeat Prompt",multiline:!0,group:"Prompt Contributions"},skillExposure:{type:"enum",label:"Skill Exposure",enumValues:["none","selected","all"],defaultValue:"selected",group:"Skills"}},je={General:"plugins.agentBrowser.groupGeneral",Browser:"plugins.agentBrowser.groupBrowser","Prompt Contributions":"plugins.agentBrowser.groupPromptContributions",Skills:"plugins.agentBrowser.groupSkills"},Ne={"Enable Agent Browser":"plugins.agentBrowser.labelEnabled","Install Channel":"plugins.agentBrowser.labelInstallChannel","Command Timeout (ms)":"plugins.agentBrowser.labelCommandTimeoutMs","Headless Mode":"plugins.agentBrowser.labelHeadlessMode","Allowed Domains":"plugins.agentBrowser.labelAllowedDomains","Executor System Prompt":"plugins.agentBrowser.labelPromptExecutorSystem","Executor Task Prompt":"plugins.agentBrowser.labelPromptExecutorTask","Triage Prompt":"plugins.agentBrowser.labelPromptTriage","Reviewer Prompt":"plugins.agentBrowser.labelPromptReviewer","Heartbeat Prompt":"plugins.agentBrowser.labelPromptHeartbeat","Skill Exposure":"plugins.agentBrowser.labelSkillExposure"},Se=[{id:"fusion-plugin-hermes-runtime",name:"Hermes Runtime",description:"Runtime provider for Hermes CLI-backed execution.",category:"runtime",path:"./plugins/fusion-plugin-hermes-runtime",experimental:!0},{id:"fusion-plugin-paperclip-runtime",name:"Paperclip Runtime",description:"Runtime provider for Paperclip agent connections.",category:"runtime",path:"./plugins/fusion-plugin-paperclip-runtime"},{id:"fusion-plugin-openclaw-runtime",name:"OpenClaw Runtime",description:"Runtime provider for OpenClaw execution.",category:"runtime",path:"./plugins/fusion-plugin-openclaw-runtime",experimental:!0},{id:"fusion-plugin-droid-runtime",name:"Droid Runtime",description:"Runtime provider for Droid CLI execution.",category:"runtime",path:"./plugins/fusion-plugin-droid-runtime",experimental:!0},{id:"fusion-plugin-dependency-graph",name:"Dependency Graph",description:"Dashboard plugin for task dependency graph visualization.",category:"integration",path:"./plugins/fusion-plugin-dependency-graph"},{id:"fusion-plugin-reports",name:"Reports",description:"View report history, compare runs side-by-side, and export standalone HTML summaries.",category:"integration",path:"./plugins/fusion-plugin-reports"},{id:"fusion-plugin-whatsapp-chat",name:"WhatsApp Chat",description:"Pairs to WhatsApp Web (multi-device) with QR or pairing code, then bridges direct chats to a Fusion agent.",category:"integration",path:"./plugins/fusion-plugin-whatsapp-chat"},{id:"fusion-plugin-cli-printing-press",name:"CLI Printing Press",description:"Guided wizard for drafting external service CLI definitions.",category:"integration",path:"./plugins/fusion-plugin-cli-printing-press"},{id:"fusion-plugin-compound-engineering",name:"Compound Engineering",description:"A dedicated dashboard surface for compound-engineering artifacts and interactive ce-* sessions.",category:"integration",path:"./plugins/fusion-plugin-compound-engineering"},{id:"fusion-plugin-quality",name:"Quality",description:"Task QA tab and Quality hub: preview servers, test runs, reports, screenshots, and suggested cases.",category:"integration",path:"./plugins/fusion-plugin-quality"},{id:"fusion-plugin-linear-import",name:"Linear Import",description:"Browse Linear issues and import selected issues as Fusion triage tasks through plugin-owned settings.",category:"integration",path:"./plugins/fusion-plugin-linear-import"},{id:we,name:"Agent Browser",description:"Built-in integration metadata. Package install support lands in FN-3101.",category:"integration",hasSetup:!0}],L={started:"var(--color-success)",loaded:"var(--color-warning)",error:"var(--color-error)",stopped:"var(--color-muted)",installed:"var(--color-info)"};function os(r){const o=r.settingsSchema,n=o&&Object.keys(o).length>0;return r.id!==we?n?o:void 0:n?{...fe,...o}:fe}function cs(r){const o=new Map,n=[];for(const[N,y]of Object.entries(r))if(y.group){const R=o.get(y.group)??[];R.push([N,y]),o.set(y.group,R)}else n.push([N,y]);return{grouped:o,ungrouped:n}}function ve(r,o="plugin-error-text"){return r.state!=="error"||!r.error?null:e.jsx("p",{className:o,title:r.error,children:r.error})}function js({addToast:r,projectId:o}){const{t:n}=us("app"),[N,y]=d.useState([]),[R,M]=d.useState(!0),[Ce,D]=d.useState(!1),[B,G]=d.useState(""),[U,$]=d.useState(!1),[q,V]=d.useState(!1),[P,T]=d.useState(null),[c,O]=d.useState(null),[m,x]=d.useState({}),[Re,W]=d.useState(!1),[Q,K]=d.useState(null),[Y,Pe]=d.useState([]),[Ie,J]=d.useState(!0),[X,Z]=d.useState(null),[b,Ee]=d.useState(""),[f,Be]=d.useState(""),[ke,ee]=d.useState(null),I=d.useRef(null),[Fe,z]=d.useState({}),[Ae,se]=d.useState(null),[k,ne]=d.useState(null),[Le,ie]=d.useState(null),{confirm:De}=Ve(),h=d.useCallback(async()=>{try{M(!0);const s=await Te(o);y(s)}catch(s){r(n("plugins.loadFailed","Failed to load plugins: {{error}}",{error:s instanceof Error?s.message:String(s)}),"error")}finally{M(!1)}},[o,r]),S=d.useCallback(async(s=b,i=f)=>{try{J(!0),Z(null);const l=await We(s,i||void 0,o);Pe(l)}catch(l){const u=l instanceof Error?l.message:String(l);Z(u)}finally{J(!1)}},[o,f,b]);d.useEffect(()=>{h()},[h]),d.useEffect(()=>(I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{S(b,f)},300),()=>{I.current&&clearTimeout(I.current)}),[S,f,b]),d.useEffect(()=>{const s=Se.filter(l=>l.hasSetup&&N.some(u=>u.id===l.id));if(s.length===0)return;let i=!1;return Promise.all(s.map(async l=>{try{const u=await ge(l.id,o);if(i)return;z(g=>({...g,[l.id]:u}))}catch{if(i)return;z(u=>({...u,[l.id]:{hasSetup:!0,setupCheckDeferred:!0,deferredReason:"plugin-not-started",pluginState:"installed"}}))}})),()=>{i=!0}},[N,o]);const Ge=d.useRef([]);Ge.current=N,d.useEffect(()=>{const s=o?`?projectId=${encodeURIComponent(o)}`:"",i=l=>{try{const u=JSON.parse(l.data);if(u.scope==="project"&&(u.projectId??o)!==o)return;switch(u.transition){case"installing":case"enabled":case"disabled":case"settings-updated":S(b,f),y(g=>{const a=g.findIndex(t=>t.id===u.pluginId);if(a>=0){const t=[...g];return t[a]={...t[a],enabled:u.enabled,state:u.state,settings:u.settings,error:u.error},t}else return h(),g});break;case"state-changed":y(g=>{const a=g.findIndex(t=>t.id===u.pluginId);if(a>=0){const t=[...g];return t[a]={...t[a],state:u.state,error:u.error},t}return g});break;case"uninstalled":y(g=>g.filter(a=>a.id!==u.pluginId)),S(b,f);break;case"error":y(g=>{const a=g.findIndex(t=>t.id===u.pluginId);if(a>=0){const t=[...g];return t[a]={...t[a],state:u.state,error:u.error},t}return g});break}}catch{}};return Qe(`/api/events${s}`,{events:{"plugin:lifecycle":i},onReconnect:()=>{h(),S(b,f)}})},[o,h,S,f,b]);const te=async()=>{if(!B.trim()){r(n("plugins.installPathRequired","Please enter a plugin path"),"error");return}try{$(!0),await A({path:B,...q?{aiScanOnLoad:!0}:{}},o),r(n("plugins.installedGlobally","Plugin installed globally"),"success"),D(!1),G(""),V(!1),await h()}catch(s){r(n("plugins.installFailed","Failed to install plugin: {{error}}",{error:s instanceof Error?s.message:String(s)}),"error")}finally{$(!1)}},Oe=async s=>{if(!s.path){r(n("plugins.builtinNoPackage","{{name}} is built in and does not have an installable package yet",{name:s.name}),"warning");return}try{K(s.id),await A({path:s.path},o),r(n("plugins.builtinInstalledGlobally","{{name}} installed globally",{name:s.name}),"success"),await h()}catch(i){r(n("plugins.builtinInstallFailed","Failed to install {{name}}: {{error}}",{name:s.name,error:i instanceof Error?i.message:String(i)}),"error")}finally{K(null)}},ze=async s=>{if(!s.path){r(n("plugins.registryNotInstallable","{{name}} is not available for one-click install yet",{name:s.name}),"warning");return}try{ee(s.id),await A({path:s.path},o),r(n("plugins.registryInstalled","{{name}} installed and enabled",{name:s.name}),"success"),await h(),await S(b,f)}catch(i){r(n("plugins.registryInstallFailed","Failed to install {{name}}: {{error}}",{name:s.name,error:i instanceof Error?i.message:String(i)}),"error")}finally{ee(null)}},ae=async s=>{try{ne(s.id);const i=await ls(s.id,o);if(!i.success){r(n("plugins.setupInstallFailed","Failed to install {{name}} setup: {{error}}",{name:s.name,error:i.error??n("plugins.unknownError","unknown error")}),"error");return}r(n("plugins.setupInstalled","{{name}} setup installed",{name:s.name}),"success"),se(s.id);const l=await ge(s.id,o);z(u=>({...u,[s.id]:l}))}catch(i){r(n("plugins.setupInstallFailed","Failed to install {{name}} setup: {{error}}",{name:s.name,error:i instanceof Error?i.message:String(i)}),"error")}finally{ne(null),se(null)}},_=async s=>{try{const i=await is(s.id,o);if(i.state==="error"){r(n("plugins.enableFailed","Failed to enable {{name}}: {{error}}",{name:s.name,error:i.error??n("plugins.unknownError","unknown error")}),"error"),await h();return}r(n("plugins.enabledForProject","{{name}} enabled for this project",{name:s.name}),"success"),await h()}catch(i){r(n("plugins.enablePluginFailed","Failed to enable plugin: {{error}}",{error:i instanceof Error?i.message:String(i)}),"error")}},H=async s=>{try{await xe(s.id,o),r(n("plugins.disabledForProject","{{name}} disabled for this project",{name:s.name}),"success"),await h()}catch(i){r(n("plugins.disablePluginFailed","Failed to disable plugin: {{error}}",{error:i instanceof Error?i.message:String(i)}),"error")}},_e=async(s,i)=>{if(i){i.enabled?await H(i):await _(i);return}if(!s.path){r(n("plugins.builtinNoPackage","{{name}} is built in and does not have an installable package yet",{name:s.name}),"warning");return}try{ie(s.id);const l=await A({path:s.path},o);await xe(l.id,o),r(n("plugins.disabledForProject","{{name}} disabled for this project",{name:s.name}),"success"),await h()}catch(l){r(n("plugins.disablePluginFailed","Failed to disable plugin: {{error}}",{error:l instanceof Error?l.message:String(l)}),"error")}finally{ie(null)}},le=async s=>{try{T(s.id),await ns(s.id,o),r(n("plugins.reloaded","{{name}} reloaded",{name:s.name}),"success"),await h()}catch(i){r(n("plugins.reloadFailed","Failed to reload plugin: {{error}}",{error:i instanceof Error?i.message:String(i)}),"error")}finally{T(null)}},re=async s=>{if(await De({title:n("plugins.uninstallTitle","Uninstall Plugin Globally"),message:n("plugins.uninstallConfirm",'Are you sure you want to uninstall "{{name}}" globally (all projects)?',{name:s.name}),danger:!0}))try{await ts(s.id,o),r(n("plugins.uninstalledGlobally","{{name}} uninstalled globally",{name:s.name}),"success"),await h(),O(null)}catch(l){r(n("plugins.uninstallFailed","Failed to uninstall plugin: {{error}}",{error:l instanceof Error?l.message:String(l)}),"error")}},He=async(s,i)=>{try{await Ze(s.id,{aiScanOnLoad:i},o),r(i?n("plugins.aiScanEnabled","AI scan on load enabled"):n("plugins.aiScanDisabled","AI scan on load disabled"),"success"),await h()}catch(l){r(n("plugins.updateFailed","Failed to update plugin: {{error}}",{error:l instanceof Error?l.message:String(l)}),"error")}},Me=async s=>{try{await es(s.id,o),r(n("plugins.rescanned","{{name}} rescanned",{name:s.name}),"success"),await h()}catch(i){r(n("plugins.rescanFailed","Failed to rescan plugin: {{error}}",{error:i instanceof Error?i.message:String(i)}),"error")}},F=async s=>{O(s);try{W(!0);const i=await as(s.id,o);x(i)}catch{x({})}finally{W(!1)}},Ue=async()=>{if(c)try{await ss(c.id,m,o),r(n("plugins.settingsSaved","Settings saved"),"success")}catch(s){r(n("plugins.saveSettingsFailed","Failed to save settings: {{error}}",{error:s instanceof Error?s.message:String(s)}),"error")}};if(c)return e.jsxs("div",{className:"plugin-manager-detail","data-testid":"plugin-manager-detail",children:[e.jsxs("div",{className:"plugin-manager-detail-header",children:[e.jsx("button",{className:"btn-icon",onClick:()=>O(null),"aria-label":n("plugins.backToList","Back to plugin list"),children:e.jsx(de,{size:16})}),e.jsxs("div",{className:"plugin-detail-title",children:[e.jsxs("div",{className:"plugin-detail-title-copy",children:[e.jsx("h4",{className:"plugin-detail-name",children:c.name}),ve(c,"plugin-error-text plugin-error-text--detail")]}),e.jsx("span",{className:"plugin-state-badge",style:{color:L[c.state]||L.installed},children:c.state})]})]}),e.jsxs("div",{className:"plugin-detail-content",children:[e.jsxs("div",{className:"plugin-detail-card",children:[c.description&&e.jsx("p",{className:"plugin-description",children:c.description}),c.author&&e.jsxs("p",{className:"plugin-detail-meta-row",children:[e.jsx("span",{className:"text-muted",children:n("plugins.author","Author:")}),c.author]}),c.homepage&&e.jsxs("p",{className:"plugin-detail-meta-row plugin-homepage",children:[e.jsx("span",{className:"text-muted",children:n("plugins.homepage","Homepage:")}),e.jsxs("a",{href:c.homepage,target:"_blank",rel:"noopener noreferrer",children:[c.homepage,e.jsx(Ke,{size:12})]})]}),e.jsxs("p",{className:"plugin-detail-meta-row",children:[e.jsx("span",{className:"text-muted",children:n("plugins.version","Version:")}),c.version]})]}),e.jsxs("div",{className:"plugin-detail-card",children:[e.jsx("h5",{className:"plugin-detail-section-heading",children:n("plugins.securityScan","Security Scan")}),e.jsxs("div",{className:"plugin-security-row",children:[e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:!!c.aiScanOnLoad,onChange:s=>void He(c,s.target.checked)}),n("plugins.enableAiScanBeforeLoad","Enable AI scan before load/reload")]}),e.jsxs("button",{className:"btn btn-secondary btn-sm",onClick:()=>void Me(c),children:[e.jsx(Ye,{size:14})," ",n("plugins.rescanAndReload","Rescan and Reload")]})]}),e.jsx("p",{className:"text-muted",children:n("plugins.aiScanHint","Turning this on only updates configuration. Use Rescan and Reload to run it now.")}),c.lastSecurityScan?e.jsxs("div",{className:"plugin-security-results",children:[e.jsxs("div",{className:"plugin-security-header",children:[e.jsx("span",{className:`plugin-state-badge plugin-security-badge plugin-security-badge--${c.lastSecurityScan.verdict}`,children:c.lastSecurityScan.verdict}),e.jsx("span",{className:"text-muted",children:c.lastSecurityScan.scannedAt})]}),e.jsx("p",{className:"plugin-security-summary",children:c.lastSecurityScan.summary}),e.jsxs("details",{children:[e.jsx("summary",{children:n("plugins.findings","Findings ({{count}})",{count:c.lastSecurityScan.findings.length})}),e.jsx("ul",{className:"plugin-security-findings",children:c.lastSecurityScan.findings.map((s,i)=>e.jsxs("li",{children:[e.jsx("strong",{children:s.severity})," ",s.category," — ",s.file,": ",s.reason]},`${s.file}-${i}`))})]})]}):e.jsx("p",{className:"text-muted",children:n("plugins.noSecurityScan","No security scan has been run yet.")})]}),e.jsxs("div",{className:"plugin-detail-card",children:[e.jsx("h5",{className:"plugin-detail-section-heading",children:n("plugins.settings","Settings")}),Re?e.jsx("p",{className:"text-muted",children:e.jsx(pe,{label:n("plugins.loading","Loading...")})}):(()=>{const s=os(c);return s&&Object.keys(s).length>0?e.jsxs("div",{className:"plugin-settings-form",children:[(()=>{const{grouped:i,ungrouped:l}=cs(s),u=[];l.length>0&&u.push({title:null,entries:l});for(const[g,a]of i.entries())u.push({title:g,entries:a});return u.map(g=>e.jsxs("div",{className:g.title?"plugin-settings-group":void 0,children:[g.title&&e.jsx("h6",{className:"plugin-settings-group-heading",children:je[g.title]?n(je[g.title],g.title):g.title}),g.entries.map(([a,t])=>{const v=`setting-${a}-help`,E=t.label?Ne[t.label]?n(Ne[t.label],t.label):t.label:a;return e.jsxs("div",{className:"form-group",children:[e.jsxs("label",{htmlFor:`setting-${a}`,children:[E,t.required&&" *"]}),t.type==="string"&&!t.multiline&&e.jsx("input",{className:"input",type:"text",id:`setting-${a}`,value:m[a]??"",onChange:p=>x({...m,[a]:p.target.value}),placeholder:t.description,"aria-describedby":t.description&&!t.required?v:void 0}),t.type==="string"&&t.multiline&&e.jsx("textarea",{className:"input",id:`setting-${a}`,rows:4,value:m[a]??"",onChange:p=>x({...m,[a]:p.target.value}),placeholder:t.description,"aria-describedby":t.description&&!t.required?v:void 0}),t.type==="password"&&e.jsx("input",{className:"input",type:"password",id:`setting-${a}`,value:m[a]??"",onChange:p=>x({...m,[a]:p.target.value}),placeholder:t.description,"aria-describedby":t.description&&!t.required?v:void 0}),t.type==="number"&&e.jsx("input",{className:"input",type:"number",id:`setting-${a}`,value:m[a]??"",onChange:p=>x({...m,[a]:Number(p.target.value)}),"aria-describedby":t.description&&!t.required?v:void 0}),t.type==="boolean"&&e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:m[a]??!1,onChange:p=>x({...m,[a]:p.target.checked})}),t.description]}),t.type==="enum"&&e.jsxs("select",{className:"select",id:`setting-${a}`,value:m[a]??"",onChange:p=>x({...m,[a]:p.target.value}),"aria-describedby":t.description&&!t.required?v:void 0,children:[e.jsx("option",{value:"",children:n("plugins.selectOption","Select...")}),t.enumValues?.map(p=>e.jsx("option",{value:p,children:p},p))]}),t.type==="array"&&e.jsxs("div",{className:"plugin-settings-array",children:[m[a]?.map((p,j)=>e.jsxs("div",{className:"plugin-settings-array-item",children:[e.jsx("input",{className:"input",type:t.itemType==="number"?"number":"text",value:p??"",onChange:C=>{const w=C.target.value,ce=[...m[a]||[]];ce[j]=t.itemType==="number"?Number(w):w,x({...m,[a]:ce})}}),e.jsx("button",{className:"btn-icon",onClick:()=>{const w=[...m[a]||[]];w.splice(j,1),x({...m,[a]:w})},"aria-label":n("plugins.removeItem","Remove item"),children:e.jsx(de,{size:14})})]},j)),e.jsxs("button",{className:"btn btn-secondary",onClick:()=>{const p=m[a]||[],j=t.itemType==="number"?0:"";x({...m,[a]:[...p,j]})},children:[e.jsx(me,{size:14})," ",n("plugins.addItem","Add Item")]})]}),t.description&&!t.required&&!t.multiline&&e.jsx("span",{id:v,className:"form-help",children:t.description})]},a)})]},g.title??"ungrouped"))})(),e.jsx("button",{className:"btn btn-primary",onClick:Ue,children:n("plugins.saveSettings","Save Settings")})]}):e.jsx("p",{className:"text-muted",children:n("plugins.noConfigurableSettings","No configurable settings.")})})()]}),e.jsxs("div",{className:"plugin-detail-actions",children:[c.state==="started"&&e.jsxs("button",{className:"btn btn-secondary",onClick:()=>le(c),disabled:P===c.id,children:[e.jsx(he,{size:14,className:P===c.id?"spin":""}),P===c.id?n("plugins.reloading","Reloading..."):n("plugins.reload","Reload")]}),c.enabled?e.jsx("button",{className:"btn btn-secondary",onClick:()=>H(c),children:n("plugins.disableInProject","Disable in Project")}):e.jsx("button",{className:"btn btn-primary",onClick:()=>_(c),children:n("plugins.enableInProject","Enable in Project")}),e.jsxs("button",{className:"btn btn-danger",onClick:()=>re(c),children:[e.jsx(be,{size:14})," ",n("plugins.uninstallGlobally","Uninstall Globally")]})]})]})]});const ue=new Map(N.map(s=>[s.id,s])),oe=N,$e=()=>e.jsxs("section",{className:"plugin-registry-section","aria-label":n("plugins.browseRegistry","Browse Registry"),children:[e.jsxs("div",{className:"plugin-registry-header",children:[e.jsxs("div",{className:"plugin-registry-heading-copy",children:[e.jsx("h4",{className:"plugin-registry-heading",children:n("plugins.browseRegistry","Browse Registry")}),e.jsx("p",{className:"plugin-registry-description",children:n("plugins.registryDescription","Discover curated runtimes and integrations that can be added to this Fusion workspace.")})]}),e.jsxs("div",{className:"plugin-registry-controls",children:[e.jsxs("label",{className:"plugin-registry-category-label",children:[e.jsx("span",{className:"sr-only",children:n("plugins.registryCategory","Registry category")}),e.jsxs("select",{className:"select plugin-registry-category-select",value:f,onChange:s=>Be(s.target.value),"aria-label":n("plugins.registryCategory","Registry category"),children:[e.jsx("option",{value:"",children:n("plugins.registryCategoryAll","All Categories")}),e.jsx("option",{value:"runtime",children:n("plugins.registryCategoryRuntime","Runtime")}),e.jsx("option",{value:"integration",children:n("plugins.registryCategoryIntegration","Integration")})]})]}),e.jsxs("label",{className:"plugin-registry-search-label",children:[e.jsx("span",{className:"sr-only",children:n("plugins.searchRegistry","Search registry")}),e.jsx("input",{className:"input plugin-registry-search-input",type:"search",value:b,onChange:s=>Ee(s.target.value),placeholder:n("plugins.searchRegistryPlaceholder","Search registry plugins")})]})]})]}),Ie?e.jsxs("div",{className:"plugin-registry-state",role:"status",children:[e.jsx(ye,{size:14,className:"spin"}),n("plugins.registryLoading","Loading registry...")]}):X?e.jsxs("div",{className:"plugin-registry-state plugin-registry-state--error",role:"alert",children:[e.jsx("span",{children:n("plugins.registryLoadFailed","Failed to load registry: {{error}}",{error:X})}),e.jsx("button",{className:"btn btn-secondary btn-sm plugin-registry-retry",onClick:()=>void S(b,f),children:n("plugins.retry","Retry")})]}):Y.length===0?e.jsx("div",{className:"plugin-registry-state",children:b.trim()?n("plugins.registryEmptySearch","No registry plugins match your search."):n("plugins.registryEmpty","No registry plugins are available.")}):e.jsx("div",{className:"plugin-registry-list","aria-label":n("plugins.registryPluginResults","Registry plugin results"),children:Y.map(s=>{const i=ue.get(s.id),l=ke===s.id;return e.jsxs("div",{className:"plugin-registry-item",children:[e.jsxs("div",{className:"plugin-registry-meta",children:[e.jsxs("div",{className:"plugin-registry-title-row",children:[e.jsx("span",{className:"plugin-registry-name",children:s.name}),e.jsxs("span",{className:"plugin-registry-version",children:["v",s.version]}),e.jsx("span",{className:"plugin-registry-badge",children:s.category}),s.installed&&e.jsxs("span",{className:"plugin-registry-status plugin-registry-status--installed",children:[n("plugins.statusInstalled","Installed"),s.installedVersion&&s.installedVersion!==s.version?` · v${s.installedVersion}`:""]})]}),e.jsx("span",{className:"plugin-registry-description-text",children:s.description}),e.jsx("span",{className:"plugin-registry-author",children:n("plugins.registryByAuthor","By {{author}}",{author:s.author})})]}),e.jsx("div",{className:"plugin-registry-actions",children:s.installed?e.jsx("button",{className:"btn btn-secondary btn-sm plugin-registry-action",onClick:()=>{i?F(i):h()},children:n("plugins.manage","Manage")}):s.canInstall?e.jsx("button",{className:"btn btn-primary btn-sm plugin-registry-action",onClick:()=>void ze(s),disabled:l,children:l?n("plugins.installing","Installing..."):n("plugins.installFromRegistry","Install")}):e.jsx("span",{className:"plugin-registry-coming-soon",children:n("plugins.registryComingSoon","Coming Soon")})})]},s.id)})})]}),qe=()=>e.jsxs("section",{className:"plugin-builtins-section","aria-label":n("plugins.builtinPlugins","Built-in Plugins"),children:[e.jsxs("div",{className:"plugin-builtins-header",children:[e.jsx("h4",{className:"plugin-builtins-heading",children:n("plugins.builtinPlugins","Built-in Plugins")}),e.jsx("p",{className:"plugin-builtins-description",children:n("plugins.builtinPluginsCatalog","Built-in plugin catalog for runtimes and integrations.")})]}),e.jsx("div",{className:"plugin-builtins-list","aria-label":n("plugins.builtinPluginRecommendations","Built-in plugin recommendations"),children:Se.map(s=>{const i=ue.get(s.id),l=!!i,u=Fe[s.id],g=!!(u&&"setupCheckDeferred"in u&&u.setupCheckDeferred),a=u&&"status"in u?u.status:void 0,t=l&&s.hasSetup&&u?.hasSetup&&!g&&i?.state==="started"&&(a==="not-installed"||a==="error"),v=l&&u?.hasSetup&&a==="installed",E=Ae===s.id,p=!s.path,j=s.category==="runtime",C=i?i.enabled:!0,w=Le===s.id;return e.jsxs("div",{className:"plugin-builtins-item",children:[e.jsxs("div",{className:"plugin-builtins-meta",children:[e.jsx("span",{className:"plugin-builtins-name",children:s.name}),s.experimental&&e.jsx("span",{className:"plugin-builtins-runtime-badge",children:n("plugins.experimental","Experimental")}),e.jsx("span",{className:"plugin-builtins-runtime-badge",children:s.category}),e.jsx("span",{className:`plugin-builtins-status ${l?"plugin-builtins-status--installed":"plugin-builtins-status--available"}`,children:l?n("plugins.statusInstalled","Installed"):p?n("plugins.statusBuiltIn","Built in"):n("plugins.statusNotInstalled","Not installed")}),j&&!C&&e.jsx("span",{className:"plugin-builtins-setup-status plugin-builtins-setup-status--warning",children:n("plugins.builtinDisabled","Disabled")}),t&&e.jsx("span",{className:"plugin-builtins-setup-status plugin-builtins-setup-status--warning",children:n("plugins.setupRequired","Setup required")}),v&&e.jsx("span",{className:"plugin-builtins-setup-status plugin-builtins-setup-status--ready",children:n("plugins.setupReady","Setup ready")}),E&&e.jsx("span",{className:"plugin-builtins-setup-status plugin-builtins-setup-status--pending",children:n("plugins.checkingSetup","Checking setup...")}),g&&e.jsx("span",{className:"plugin-builtins-setup-status plugin-builtins-setup-status--deferred",children:n("plugins.startPluginToCheckSetup","Start plugin to check setup")}),e.jsx("span",{className:"plugin-builtins-description-text",children:s.description})]}),e.jsxs("div",{className:"plugin-builtins-actions",children:[j&&e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",checked:C,onChange:()=>void _e(s,i),disabled:w,"aria-label":C?n("plugins.disablePlugin","Disable {{name}}",{name:s.name}):n("plugins.enablePlugin","Enable {{name}}",{name:s.name})}),e.jsx("span",{className:"toggle-slider"})]}),p?l&&t?e.jsx("button",{className:"btn btn-primary btn-sm",onClick:()=>void ae(s),disabled:k===s.id||E,children:k===s.id?n("plugins.settingUp","Setting up..."):n("plugins.installSetup","Install Setup")}):l&&i?e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>void F(i),children:n("plugins.manage","Manage")}):j?null:e.jsx("span",{className:"plugin-builtins-metadata-only",children:n("plugins.builtinMetadataOnly","Built-in metadata only")}):e.jsx("button",{className:`btn ${l&&!t?"btn-secondary":"btn-primary"} btn-sm`,onClick:()=>{if(!l){Oe(s);return}if(t){ae(s);return}i&&F(i)},disabled:Q===s.id||k===s.id||E,children:l?t?k===s.id?n("plugins.settingUp","Setting up..."):n("plugins.installSetup","Install Setup"):n("plugins.manage","Manage"):Q===s.id?n("plugins.installing","Installing..."):n("plugins.installNamed","Install {{name}}",{name:s.name})})]})]},s.id)})})]});return e.jsxs("div",{className:"plugin-manager","data-testid":"plugin-manager",children:[e.jsxs("div",{className:"plugin-manager-header",children:[e.jsx("span",{className:"plugin-manager-header-title",children:n("plugins.installedPlugins","Installed Plugins")}),e.jsxs("div",{className:"plugin-manager-actions",children:[e.jsxs("button",{className:"btn btn-sm",onClick:h,title:n("plugins.refresh","Refresh"),"aria-label":n("plugins.refreshPluginList","Refresh plugin list"),children:[e.jsx(ye,{size:14,className:R?"spin":""}),n("plugins.refresh","Refresh")]}),e.jsxs("button",{className:"btn btn-primary btn-sm",onClick:()=>D(!0),children:[e.jsx(me,{size:14})," ",n("plugins.install","Install")]})]})]}),Ce&&e.jsxs("div",{className:"plugin-install-form",children:[e.jsx("p",{className:"plugin-install-hint",children:n("plugins.installHint","Browse to a plugin package root (contains manifest.json) or a built dist directory.")}),e.jsx(rs,{value:B,onChange:G,placeholder:n("plugins.installPathPlaceholder","Absolute path to plugin directory or dist folder"),onInputKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),te())}}),e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:q,onChange:s=>V(s.target.checked)}),n("plugins.enableAiSecurityScan","Enable AI security scan on load")]}),e.jsxs("div",{className:"plugin-install-actions",children:[e.jsx("button",{className:"btn btn-primary",onClick:te,disabled:U||!B.trim(),children:U?n("plugins.installing","Installing..."):n("plugins.installPluginGlobally","Install Plugin Globally")}),e.jsx("button",{className:"btn btn-secondary",onClick:()=>{D(!1),G("")},children:n("plugins.cancel","Cancel")})]})]}),R?e.jsx("div",{className:"settings-empty-state",children:e.jsx(pe,{label:n("plugins.loadingPlugins","Loading plugins...")})}):e.jsxs(e.Fragment,{children:[oe.length===0?e.jsxs("div",{className:"settings-empty-state",children:[e.jsx(Je,{size:32,className:"text-muted"}),e.jsx("p",{children:n("plugins.noPluginsInstalled","No plugins installed.")}),e.jsx("p",{className:"text-muted",children:n("plugins.noPluginsHint","Install a plugin to get started, or use the built-in catalog below.")})]}):e.jsx("div",{className:"plugin-list",children:oe.map(s=>e.jsxs("div",{className:"plugin-item",children:[e.jsx("div",{className:"plugin-info",children:e.jsxs("div",{className:"plugin-copy",children:[e.jsxs("div",{className:"plugin-copy-header",children:[e.jsx("span",{className:"plugin-name",children:s.name}),e.jsxs("span",{className:"plugin-version text-muted",children:["v",s.version]}),e.jsx("span",{className:"plugin-state-badge",style:{color:L[s.state]||L.installed},children:s.state})]}),ve(s)]})}),e.jsxs("div",{className:"plugin-actions",children:[s.state==="started"&&e.jsx("button",{className:"btn-icon",onClick:()=>le(s),disabled:P===s.id,title:n("plugins.reload","Reload"),children:e.jsx(he,{size:14,className:P===s.id?"spin":""})}),e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",checked:s.enabled,onChange:()=>s.enabled?H(s):_(s),"aria-label":s.enabled?n("plugins.disablePlugin","Disable {{name}}",{name:s.name}):n("plugins.enablePlugin","Enable {{name}}",{name:s.name})}),e.jsx("span",{className:"toggle-slider"})]}),e.jsx("button",{className:"btn-icon",onClick:()=>F(s),title:n("plugins.settings","Settings"),children:e.jsx(Xe,{size:14})}),e.jsx("button",{className:"btn-icon",onClick:()=>re(s),title:n("plugins.uninstallGloballyTitle","Uninstall globally"),children:e.jsx(be,{size:14})})]})]},s.id))}),qe(),$e()]})]})}export{fe as AGENT_BROWSER_SETTINGS_SCHEMA,we as BUILTIN_AGENT_BROWSER_PLUGIN_ID,Se as BUILTIN_PLUGINS,js as PluginManager,L as STATE_COLORS};
@@ -1,6 +1,6 @@
1
- import{r as a,j as e}from"./vendor-react-SZ_qB27O.js";import{c as te,V as ie,aM as k,aN as b,aO as C,a9 as F,aP as M,aQ as ae,aR as Q,a6 as X,az as Y,Y as E}from"./index-DF2cd-e3.js";import{u as ne}from"./vendor-i18n-GF3RlKbq.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.js";/**
1
+ import{r as a,j as e}from"./vendor-react-SZ_qB27O.js";import{c as te,V as ie,aO as k,aP as b,aQ as C,a9 as F,aR as M,aS as ae,aT as Q,a6 as X,aB as Y,Y as E}from"./index-D8sgsB8q.js";import{u as ne}from"./vendor-i18n-GF3RlKbq.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.js";/**
2
2
  * @license lucide-react v1.7.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const le=[["path",{d:"M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z",key:"emmmcr"}],["path",{d:"M7 10v12",key:"1qc93n"}]],de=te("thumbs-up",le);function ce(t){return async s=>{const n=t?`?projectId=${encodeURIComponent(t)}`:"";return(await E(`/pull-requests/${s}${n}`)).pullRequest}}function oe(t){return async()=>{const s=t?`?projectId=${encodeURIComponent(t)}`:"";return(await E(`/pull-requests${s}`)).pullRequests}}function pe(t){return async(s,n,o)=>(await E(`/pull-requests/${n}/${s==="automerge"?"automerge":s}`,{method:"POST",body:JSON.stringify({...o??{},...t?{projectId:t}:{}}),headers:{"content-type":"application/json"}})).pullRequest}function V({rollup:t}){return t==="success"?e.jsx(Y,{size:14,className:"pr-icon-success"}):t==="failure"?e.jsx(Q,{size:14,className:"pr-icon-failure"}):t==="pending"?e.jsx(C,{size:14,className:"pr-icon-pending"}):e.jsx("span",{className:"pr-icon-none",children:"—"})}const ue=15e3;async function J(t,s){const n=new Promise((o,l)=>setTimeout(()=>l(new Error(s)),ue));return Promise.race([t,n])}function fe(t){const{t:s}=ne("app"),{detail:n,pullRequestId:o,projectId:l,onAction:R,loadPullRequest:q,loadPullRequests:S}=t,h=n!==void 0,[z,T]=a.useState(null),[i,x]=a.useState(n??null),[v,p]=a.useState(null),[$,I]=a.useState([]),[A,U]=a.useState(null),[u,B]=a.useState(null),[Z,G]=a.useState(!1),[K,j]=a.useState(!1),[W,H]=a.useState(!1),O=a.useMemo(()=>q??ce(l),[q,l]),_=a.useMemo(()=>S??oe(l),[S,l]),D=a.useMemo(()=>R??pe(l),[R,l]),L=o??z??void 0,ee=!h&&!o&&!z,se=!h&&!o&&!!z,f=a.useCallback(async()=>{if(h){x(n??null),p(null),j(!1);return}if(!L){try{p(null),U(null),H(!0),x(null),I(await J(_(),"Timed out loading pull requests"))}catch(r){I([]),U(r instanceof Error?r.message:s("pr.view.listError","Failed to load pull requests"))}finally{H(!1)}return}try{p(null),j(!0),x(await J(O(L),"Timed out loading pull request"))}catch(r){p(r instanceof Error?r.message:"Failed to load PR")}finally{j(!1)}},[L,n,h,O,_,s]);a.useEffect(()=>{f()},[f]),a.useEffect(()=>{if(h)return;const r=()=>void f();return window.addEventListener("fusion:store-changed",r),()=>window.removeEventListener("fusion:store-changed",r)},[h,f]);const g=a.useCallback(async(r,re)=>{if(i)try{B(r),p(null);const N=await D(r,i.id,re);x(N)}catch(N){p(N instanceof Error?N.message:`Action ${r} failed`)}finally{B(null),G(!1)}},[i,D]),d=e.jsx(ie,{icon:k,title:s("pr.view.title","Pull Requests")});if(ee)return A?e.jsxs("div",{className:"pr-view pr-view--error","data-testid":"pr-list-error",children:[d,e.jsxs("div",{className:"pr-list-state pr-list-state--error",children:[e.jsx(b,{size:16})," ",A]})]}):W?e.jsxs("div",{className:"pr-view pr-view--loading","data-testid":"pr-list-loading",children:[d,e.jsx("div",{className:"pr-list-state",children:s("pr.view.listLoading","Loading pull requests…")})]}):$.length===0?e.jsxs("div",{className:"pr-view pr-view--empty","data-testid":"pr-list-empty",children:[d,e.jsxs("div",{className:"pr-list-state",children:[e.jsx(k,{size:16})," ",s("pr.view.listEmpty","No active pull requests to show.")]})]}):e.jsxs("div",{className:"pr-view","data-testid":"pr-list",children:[d,e.jsx("div",{className:"pr-list-title",children:s("pr.view.listTitle","Active pull requests")}),e.jsx("div",{className:"pr-list-items",children:$.map(r=>e.jsxs("button",{type:"button",className:"pr-list-item","data-testid":"pr-list-item","aria-label":s("pr.view.listItemLabel","Open pull request {{repo}} {{number}}",{repo:r.repo,number:r.prNumber!=null?`#${r.prNumber}`:r.headBranch}),onClick:()=>{p(null),j(!0),T(r.id)},children:[e.jsxs("span",{className:"pr-list-item-main",children:[e.jsx("span",{className:"pr-list-item-repo",children:r.repo}),r.prNumber!=null&&e.jsxs("span",{className:"pr-list-item-number",children:["#",r.prNumber]}),e.jsx("span",{className:"pr-list-item-branch",children:r.headBranch})]}),e.jsxs("span",{className:"pr-list-item-meta",children:[e.jsx("span",{className:`pr-identity-state pr-identity-state--${r.state}`,children:r.state}),e.jsxs("span",{className:"pr-list-item-checks",children:[e.jsx(V,{rollup:r.summary.checksRollup})," ",r.summary.checksRollup]})]})]},r.id))})]});if(v&&!i)return e.jsxs("div",{className:"pr-view pr-view--error","data-testid":"pr-view-error",children:[e.jsx(b,{size:16})," ",v]});if(!i)return K?e.jsx("div",{className:"pr-view pr-view--loading","data-testid":"pr-view-loading",children:s("pr.view.loading","Loading PR…")}):e.jsxs("div",{className:"pr-view pr-view--empty","data-testid":"pr-view-empty",children:[e.jsx(k,{size:16})," ",s("pr.view.empty","No pull request to show.")]});const{state:c,summary:m}=i,w=se?e.jsx("button",{type:"button",className:"pr-back-to-list btn","data-testid":"pr-back-to-list",onClick:()=>T(null),children:s("pr.view.backToList","Back to list")}):null;if(c==="creating")return e.jsxs("div",{className:"pr-view","data-testid":"pr-view","data-state":"creating",children:[d,w,e.jsx(y,{detail:i}),e.jsxs("div",{className:"pr-placeholder","data-testid":"pr-creating",children:[e.jsx(C,{size:16})," ",s("pr.view.creating","Creating PR…")]})]});if(c==="failed")return e.jsxs("div",{className:"pr-view","data-testid":"pr-view","data-state":"failed",children:[d,w,e.jsx(y,{detail:i}),e.jsxs("div",{className:"pr-error-reason","data-testid":"pr-failed",children:[e.jsx(b,{size:16,className:"pr-icon-failure"}),e.jsx("span",{children:i.failureReason??s("pr.view.creationFailed","PR creation failed")})]}),e.jsx("div",{className:"pr-action-bar",children:e.jsxs("button",{type:"button",className:"pr-action pr-action--retry","data-testid":"pr-retry-create",disabled:u==="retry-create",onClick:()=>void g("retry-create"),children:[e.jsx(F,{size:14})," ",s("pr.view.retryCreation","Retry PR creation")]})}),v&&e.jsx("div",{className:"pr-inline-error",children:v})]});if(i.unverified)return e.jsxs("div",{className:"pr-view","data-testid":"pr-view","data-state":"unverified",children:[d,w,e.jsx(y,{detail:i}),e.jsxs("div",{className:"pr-notice pr-notice--unverified","data-testid":"pr-unverified",children:[e.jsx(C,{size:16})," ",s("pr.view.verifyingGithub","Verifying with GitHub…")]}),e.jsx("div",{className:"pr-action-bar",children:e.jsxs("button",{type:"button",className:"pr-action","data-testid":"pr-merge",disabled:!0,title:s("pr.view.mergeDisabledUntilVerified","Merge is disabled until GitHub verifies this PR"),children:[e.jsx(M,{size:14})," ",s("pr.view.merge","Merge")]})})]});const P=m.conflicting;return e.jsxs("div",{className:"pr-view","data-testid":"pr-view","data-state":c,children:[d,w,e.jsx(y,{detail:i}),c==="responding"&&e.jsxs("div",{className:"pr-banner pr-banner--responding","data-testid":"pr-responding",children:[e.jsx(ae,{size:16})," ",s("pr.view.responsePending","Response run in progress — {{count}} threads pending",{count:m.pendingThreads})]}),e.jsxs("div",{className:"pr-action-bar","data-testid":"pr-action-bar",children:[e.jsxs("button",{type:"button",className:"pr-action pr-action--approve","data-testid":"pr-approve",disabled:c==="responding"||u==="approve",onClick:()=>void g("approve"),children:[e.jsx(de,{size:14})," ",s("pr.view.approve","Approve")]}),e.jsxs("button",{type:"button",className:"pr-action pr-action--retry","data-testid":"pr-retry",disabled:c==="responding"||u==="retry",title:c==="responding"?s("pr.view.responseAlreadyInProgress","A response run is already in progress"):void 0,onClick:()=>void g("retry"),children:[e.jsx(F,{size:14})," ",s("pr.view.requestRetry","Request retry")]}),Z?e.jsxs("button",{type:"button",className:"pr-action pr-action--merge-confirm","data-testid":"pr-merge-confirm",disabled:u==="merge",onClick:()=>void g("merge"),children:[e.jsx(M,{size:14})," ",s("pr.view.confirmMerge","Confirm merge")]}):e.jsxs("button",{type:"button",className:"pr-action pr-action--merge","data-testid":"pr-merge",disabled:P||c==="responding"||u==="merge",title:P?s("pr.view.resolveConflictsBeforeMerge","Resolve conflicts on GitHub before merging"):void 0,onClick:()=>G(!0),children:[e.jsx(M,{size:14})," ",s("pr.view.merge","Merge")]}),e.jsxs("button",{type:"button",className:"pr-action pr-action--close","data-testid":"pr-close",disabled:u==="close",onClick:()=>void g("close"),children:[e.jsx(Q,{size:14})," ",s("pr.view.close","Close")]}),e.jsxs("label",{className:"pr-automerge-toggle","data-testid":"pr-automerge",children:[e.jsx("input",{type:"checkbox",checked:i.autoMerge,disabled:u==="automerge",onChange:r=>void g("automerge",{enabled:r.target.checked})}),e.jsx("span",{children:s("pr.view.autoMerge","Auto-merge")}),e.jsx("span",{className:"pr-automerge-gate","data-testid":"pr-automerge-gate",children:m.autoMergeReason})]})]}),P&&i.prUrl&&e.jsxs("a",{className:"pr-conflict-link","data-testid":"pr-conflict-link",href:i.prUrl,target:"_blank",rel:"noopener noreferrer",children:[s("pr.view.resolveConflictsOnGithub","Resolve conflicts on GitHub")," ",e.jsx(X,{size:12})]}),e.jsxs("div",{className:"pr-summary","data-testid":"pr-summary",children:[e.jsxs("span",{className:"pr-summary-item","data-testid":"pr-summary-mergeable",children:[s("pr.view.mergeableLabel","Mergeable:")," ",m.mergeable]}),e.jsxs("span",{className:"pr-summary-item","data-testid":"pr-summary-review",children:[s("pr.view.reviewLabel","Review:")," ",m.reviewDecision??s("pr.view.none","none")]}),e.jsxs("span",{className:"pr-summary-item","data-testid":"pr-summary-checks",children:[e.jsx(V,{rollup:m.checksRollup})," ",m.checksRollup]})]}),e.jsx("div",{className:"pr-threads","data-testid":"pr-threads",children:i.threads.length===0?e.jsx("div",{className:"pr-threads-empty",children:s("pr.view.noReviewThreads","No review threads.")}):i.threads.map(r=>e.jsxs("div",{className:`pr-thread pr-thread--${r.outcome} ${r.outcome==="disagreed"?"pr-thread--agent-disagreement":""}`,"data-testid":`pr-thread-${r.outcome}`,"data-agent-disagreement":r.outcome==="disagreed"?"true":"false",children:[e.jsxs("div",{className:"pr-thread-head",children:[r.outcome==="pending"&&e.jsxs("span",{className:"pr-thread-pending",children:[e.jsx(C,{size:12})," ",s("pr.view.threadPending","pending")]}),r.outcome==="disagreed"&&e.jsxs("span",{className:"pr-thread-disagreed",children:[e.jsx(b,{size:12})," ",s("pr.view.agentDisagreed","agent disagreed")]}),r.outcome==="fixed"&&e.jsxs("span",{className:"pr-thread-fixed",children:[e.jsx(Y,{size:12})," ",s("pr.view.threadFixed","fixed")]}),e.jsx("span",{className:"pr-thread-id",children:r.threadId})]}),r.fixCommitSha&&e.jsx("div",{className:"pr-thread-reply","data-testid":"pr-thread-reply",children:s("pr.view.agentReplyFix","Agent reply — fix {{sha}}",{sha:r.fixCommitSha.slice(0,8)})})]},`${r.threadId}:${r.headOid}`))}),v&&e.jsx("div",{className:"pr-inline-error",children:v})]})}function y({detail:t}){return e.jsxs("div",{className:"pr-identity","data-testid":"pr-identity",children:[e.jsx(k,{size:16}),e.jsx("span",{className:"pr-identity-repo",children:t.repo}),t.prNumber!=null?t.prUrl?e.jsxs("a",{className:"pr-identity-number",href:t.prUrl,target:"_blank",rel:"noopener noreferrer",children:["#",t.prNumber," ",e.jsx(X,{size:12})]}):e.jsxs("span",{className:"pr-identity-number",children:["#",t.prNumber]}):null,e.jsx("span",{className:"pr-identity-branch",children:t.headBranch}),e.jsx("span",{className:`pr-identity-state pr-identity-state--${t.state}`,children:t.state})]})}export{fe as PullRequestView};
6
+ */const le=[["path",{d:"M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z",key:"emmmcr"}],["path",{d:"M7 10v12",key:"1qc93n"}]],de=te("thumbs-up",le);function ce(t){return async s=>{const n=t?`?projectId=${encodeURIComponent(t)}`:"";return(await E(`/pull-requests/${s}${n}`)).pullRequest}}function oe(t){return async()=>{const s=t?`?projectId=${encodeURIComponent(t)}`:"";return(await E(`/pull-requests${s}`)).pullRequests}}function pe(t){return async(s,n,o)=>(await E(`/pull-requests/${n}/${s==="automerge"?"automerge":s}`,{method:"POST",body:JSON.stringify({...o??{},...t?{projectId:t}:{}}),headers:{"content-type":"application/json"}})).pullRequest}function V({rollup:t}){return t==="success"?e.jsx(Y,{size:14,className:"pr-icon-success"}):t==="failure"?e.jsx(Q,{size:14,className:"pr-icon-failure"}):t==="pending"?e.jsx(C,{size:14,className:"pr-icon-pending"}):e.jsx("span",{className:"pr-icon-none",children:"—"})}const ue=15e3;async function J(t,s){const n=new Promise((o,l)=>setTimeout(()=>l(new Error(s)),ue));return Promise.race([t,n])}function fe(t){const{t:s}=ne("app"),{detail:n,pullRequestId:o,projectId:l,onAction:R,loadPullRequest:S,loadPullRequests:T}=t,h=n!==void 0,[L,q]=a.useState(null),[i,x]=a.useState(n??null),[v,p]=a.useState(null),[$,I]=a.useState([]),[A,B]=a.useState(null),[u,U]=a.useState(null),[Z,G]=a.useState(!1),[K,j]=a.useState(!1),[W,H]=a.useState(!1),O=a.useMemo(()=>S??ce(l),[S,l]),_=a.useMemo(()=>T??oe(l),[T,l]),D=a.useMemo(()=>R??pe(l),[R,l]),P=o??L??void 0,ee=!h&&!o&&!L,se=!h&&!o&&!!L,f=a.useCallback(async()=>{if(h){x(n??null),p(null),j(!1);return}if(!P){try{p(null),B(null),H(!0),x(null),I(await J(_(),"Timed out loading pull requests"))}catch(r){I([]),B(r instanceof Error?r.message:s("pr.view.listError","Failed to load pull requests"))}finally{H(!1)}return}try{p(null),j(!0),x(await J(O(P),"Timed out loading pull request"))}catch(r){p(r instanceof Error?r.message:"Failed to load PR")}finally{j(!1)}},[P,n,h,O,_,s]);a.useEffect(()=>{f()},[f]),a.useEffect(()=>{if(h)return;const r=()=>void f();return window.addEventListener("fusion:store-changed",r),()=>window.removeEventListener("fusion:store-changed",r)},[h,f]);const g=a.useCallback(async(r,re)=>{if(i)try{U(r),p(null);const N=await D(r,i.id,re);x(N)}catch(N){p(N instanceof Error?N.message:`Action ${r} failed`)}finally{U(null),G(!1)}},[i,D]),d=e.jsx(ie,{icon:k,title:s("pr.view.title","Pull Requests")});if(ee)return A?e.jsxs("div",{className:"pr-view pr-view--error","data-testid":"pr-list-error",children:[d,e.jsxs("div",{className:"pr-list-state pr-list-state--error",children:[e.jsx(b,{size:16})," ",A]})]}):W?e.jsxs("div",{className:"pr-view pr-view--loading","data-testid":"pr-list-loading",children:[d,e.jsx("div",{className:"pr-list-state",children:s("pr.view.listLoading","Loading pull requests…")})]}):$.length===0?e.jsxs("div",{className:"pr-view pr-view--empty","data-testid":"pr-list-empty",children:[d,e.jsxs("div",{className:"pr-list-state",children:[e.jsx(k,{size:16})," ",s("pr.view.listEmpty","No active pull requests to show.")]})]}):e.jsxs("div",{className:"pr-view","data-testid":"pr-list",children:[d,e.jsx("div",{className:"pr-list-title",children:s("pr.view.listTitle","Active pull requests")}),e.jsx("div",{className:"pr-list-items",children:$.map(r=>e.jsxs("button",{type:"button",className:"pr-list-item","data-testid":"pr-list-item","aria-label":s("pr.view.listItemLabel","Open pull request {{repo}} {{number}}",{repo:r.repo,number:r.prNumber!=null?`#${r.prNumber}`:r.headBranch}),onClick:()=>{p(null),j(!0),q(r.id)},children:[e.jsxs("span",{className:"pr-list-item-main",children:[e.jsx("span",{className:"pr-list-item-repo",children:r.repo}),r.prNumber!=null&&e.jsxs("span",{className:"pr-list-item-number",children:["#",r.prNumber]}),e.jsx("span",{className:"pr-list-item-branch",children:r.headBranch})]}),e.jsxs("span",{className:"pr-list-item-meta",children:[e.jsx("span",{className:`pr-identity-state pr-identity-state--${r.state}`,children:r.state}),e.jsxs("span",{className:"pr-list-item-checks",children:[e.jsx(V,{rollup:r.summary.checksRollup})," ",r.summary.checksRollup]})]})]},r.id))})]});if(v&&!i)return e.jsxs("div",{className:"pr-view pr-view--error","data-testid":"pr-view-error",children:[e.jsx(b,{size:16})," ",v]});if(!i)return K?e.jsx("div",{className:"pr-view pr-view--loading","data-testid":"pr-view-loading",children:s("pr.view.loading","Loading PR…")}):e.jsxs("div",{className:"pr-view pr-view--empty","data-testid":"pr-view-empty",children:[e.jsx(k,{size:16})," ",s("pr.view.empty","No pull request to show.")]});const{state:c,summary:m}=i,w=se?e.jsx("button",{type:"button",className:"pr-back-to-list btn","data-testid":"pr-back-to-list",onClick:()=>q(null),children:s("pr.view.backToList","Back to list")}):null;if(c==="creating")return e.jsxs("div",{className:"pr-view","data-testid":"pr-view","data-state":"creating",children:[d,w,e.jsx(y,{detail:i}),e.jsxs("div",{className:"pr-placeholder","data-testid":"pr-creating",children:[e.jsx(C,{size:16})," ",s("pr.view.creating","Creating PR…")]})]});if(c==="failed")return e.jsxs("div",{className:"pr-view","data-testid":"pr-view","data-state":"failed",children:[d,w,e.jsx(y,{detail:i}),e.jsxs("div",{className:"pr-error-reason","data-testid":"pr-failed",children:[e.jsx(b,{size:16,className:"pr-icon-failure"}),e.jsx("span",{children:i.failureReason??s("pr.view.creationFailed","PR creation failed")})]}),e.jsx("div",{className:"pr-action-bar",children:e.jsxs("button",{type:"button",className:"pr-action pr-action--retry","data-testid":"pr-retry-create",disabled:u==="retry-create",onClick:()=>void g("retry-create"),children:[e.jsx(F,{size:14})," ",s("pr.view.retryCreation","Retry PR creation")]})}),v&&e.jsx("div",{className:"pr-inline-error",children:v})]});if(i.unverified)return e.jsxs("div",{className:"pr-view","data-testid":"pr-view","data-state":"unverified",children:[d,w,e.jsx(y,{detail:i}),e.jsxs("div",{className:"pr-notice pr-notice--unverified","data-testid":"pr-unverified",children:[e.jsx(C,{size:16})," ",s("pr.view.verifyingGithub","Verifying with GitHub…")]}),e.jsx("div",{className:"pr-action-bar",children:e.jsxs("button",{type:"button",className:"pr-action","data-testid":"pr-merge",disabled:!0,title:s("pr.view.mergeDisabledUntilVerified","Merge is disabled until GitHub verifies this PR"),children:[e.jsx(M,{size:14})," ",s("pr.view.merge","Merge")]})})]});const z=m.conflicting;return e.jsxs("div",{className:"pr-view","data-testid":"pr-view","data-state":c,children:[d,w,e.jsx(y,{detail:i}),c==="responding"&&e.jsxs("div",{className:"pr-banner pr-banner--responding","data-testid":"pr-responding",children:[e.jsx(ae,{size:16})," ",s("pr.view.responsePending","Response run in progress — {{count}} threads pending",{count:m.pendingThreads})]}),e.jsxs("div",{className:"pr-action-bar","data-testid":"pr-action-bar",children:[e.jsxs("button",{type:"button",className:"pr-action pr-action--approve","data-testid":"pr-approve",disabled:c==="responding"||u==="approve",onClick:()=>void g("approve"),children:[e.jsx(de,{size:14})," ",s("pr.view.approve","Approve")]}),e.jsxs("button",{type:"button",className:"pr-action pr-action--retry","data-testid":"pr-retry",disabled:c==="responding"||u==="retry",title:c==="responding"?s("pr.view.responseAlreadyInProgress","A response run is already in progress"):void 0,onClick:()=>void g("retry"),children:[e.jsx(F,{size:14})," ",s("pr.view.requestRetry","Request retry")]}),Z?e.jsxs("button",{type:"button",className:"pr-action pr-action--merge-confirm","data-testid":"pr-merge-confirm",disabled:u==="merge",onClick:()=>void g("merge"),children:[e.jsx(M,{size:14})," ",s("pr.view.confirmMerge","Confirm merge")]}):e.jsxs("button",{type:"button",className:"pr-action pr-action--merge","data-testid":"pr-merge",disabled:z||c==="responding"||u==="merge",title:z?s("pr.view.resolveConflictsBeforeMerge","Resolve conflicts on GitHub before merging"):void 0,onClick:()=>G(!0),children:[e.jsx(M,{size:14})," ",s("pr.view.merge","Merge")]}),e.jsxs("button",{type:"button",className:"pr-action pr-action--close","data-testid":"pr-close",disabled:u==="close",onClick:()=>void g("close"),children:[e.jsx(Q,{size:14})," ",s("pr.view.close","Close")]}),e.jsxs("label",{className:"pr-automerge-toggle","data-testid":"pr-automerge",children:[e.jsx("input",{type:"checkbox",checked:i.autoMerge,disabled:u==="automerge",onChange:r=>void g("automerge",{enabled:r.target.checked})}),e.jsx("span",{children:s("pr.view.autoMerge","Auto-merge")}),e.jsx("span",{className:"pr-automerge-gate","data-testid":"pr-automerge-gate",children:m.autoMergeReason})]})]}),z&&i.prUrl&&e.jsxs("a",{className:"pr-conflict-link","data-testid":"pr-conflict-link",href:i.prUrl,target:"_blank",rel:"noopener noreferrer",children:[s("pr.view.resolveConflictsOnGithub","Resolve conflicts on GitHub")," ",e.jsx(X,{size:12})]}),e.jsxs("div",{className:"pr-summary","data-testid":"pr-summary",children:[e.jsxs("span",{className:"pr-summary-item","data-testid":"pr-summary-mergeable",children:[s("pr.view.mergeableLabel","Mergeable:")," ",m.mergeable]}),e.jsxs("span",{className:"pr-summary-item","data-testid":"pr-summary-review",children:[s("pr.view.reviewLabel","Review:")," ",m.reviewDecision??s("pr.view.none","none")]}),e.jsxs("span",{className:"pr-summary-item","data-testid":"pr-summary-checks",children:[e.jsx(V,{rollup:m.checksRollup})," ",m.checksRollup]})]}),e.jsx("div",{className:"pr-threads","data-testid":"pr-threads",children:i.threads.length===0?e.jsx("div",{className:"pr-threads-empty",children:s("pr.view.noReviewThreads","No review threads.")}):i.threads.map(r=>e.jsxs("div",{className:`pr-thread pr-thread--${r.outcome} ${r.outcome==="disagreed"?"pr-thread--agent-disagreement":""}`,"data-testid":`pr-thread-${r.outcome}`,"data-agent-disagreement":r.outcome==="disagreed"?"true":"false",children:[e.jsxs("div",{className:"pr-thread-head",children:[r.outcome==="pending"&&e.jsxs("span",{className:"pr-thread-pending",children:[e.jsx(C,{size:12})," ",s("pr.view.threadPending","pending")]}),r.outcome==="disagreed"&&e.jsxs("span",{className:"pr-thread-disagreed",children:[e.jsx(b,{size:12})," ",s("pr.view.agentDisagreed","agent disagreed")]}),r.outcome==="fixed"&&e.jsxs("span",{className:"pr-thread-fixed",children:[e.jsx(Y,{size:12})," ",s("pr.view.threadFixed","fixed")]}),e.jsx("span",{className:"pr-thread-id",children:r.threadId})]}),r.fixCommitSha&&e.jsx("div",{className:"pr-thread-reply","data-testid":"pr-thread-reply",children:s("pr.view.agentReplyFix","Agent reply — fix {{sha}}",{sha:r.fixCommitSha.slice(0,8)})})]},`${r.threadId}:${r.headOid}`))}),v&&e.jsx("div",{className:"pr-inline-error",children:v})]})}function y({detail:t}){return e.jsxs("div",{className:"pr-identity","data-testid":"pr-identity",children:[e.jsx(k,{size:16}),e.jsx("span",{className:"pr-identity-repo",children:t.repo}),t.prNumber!=null?t.prUrl?e.jsxs("a",{className:"pr-identity-number",href:t.prUrl,target:"_blank",rel:"noopener noreferrer",children:["#",t.prNumber," ",e.jsx(X,{size:12})]}):e.jsxs("span",{className:"pr-identity-number",children:["#",t.prNumber]}):null,e.jsx("span",{className:"pr-identity-branch",children:t.headBranch}),e.jsx("span",{className:`pr-identity-state pr-identity-state--${t.state}`,children:t.state})]})}export{fe as PullRequestView};
@@ -1 +1 @@
1
- import{r as c,j as e}from"./vendor-react-SZ_qB27O.js";import{aB as W,aC as de,aD as ue,bi as he,bz as xe,aG as ae,bA as ye,a5 as ge,bB as X,bC as Re,bD as _e,bE as Se,bF as je,bG as we,bH as Ne,bm as ke,bI as Ee,bJ as Ce,aI as Ae,bK as Te,V as Le,bL as me,L as Pe,a8 as Ie}from"./index-DF2cd-e3.js";import{u as be}from"./vendor-i18n-GF3RlKbq.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.js";const Fe="builtin",Q={pageFetch:!0,github:!1,localDocs:!0,llmSynthesis:!0};function ne(n){const a=n?.researchGlobalDefaults,i=n?.researchSettings;return{enabled:i?.enabled??n?.researchEnabled??n?.researchGlobalEnabled??!0,searchProvider:i?.searchProvider??a?.searchProvider??n?.researchGlobalWebSearchProvider??Fe,synthesisProvider:i?.synthesisProvider??a?.synthesisProvider,synthesisModelId:i?.synthesisModelId??a?.synthesisModelId,enabledSources:{webSearch:!0,pageFetch:i?.enabledSources?.pageFetch??a?.enabledSources?.pageFetch??Q.pageFetch,github:i?.enabledSources?.github??a?.enabledSources?.github??Q.github,localDocs:i?.enabledSources?.localDocs??a?.enabledSources?.localDocs??Q.localDocs,llmSynthesis:i?.enabledSources?.llmSynthesis??a?.enabledSources?.llmSynthesis??Q.llmSynthesis},limits:{maxConcurrentRuns:i?.limits?.maxConcurrentRuns??n?.researchMaxConcurrentRuns??n?.researchGlobalMaxConcurrentRuns??3,maxSourcesPerRun:i?.limits?.maxSourcesPerRun??a?.maxSourcesPerRun??n?.researchMaxSourcesPerRun??n?.researchGlobalMaxSourcesPerRun??20,maxDurationMs:i?.limits?.maxDurationMs??n?.researchDefaultTimeout??n?.researchGlobalDefaultTimeout??3e5,requestTimeoutMs:i?.limits?.requestTimeoutMs??n?.researchGlobalFetchTimeoutMs??3e4},defaultExportFormat:a?.defaultExportFormat??"markdown"}}const Me=300,De=4e3,He=["queued","running","cancelling","retry_waiting"];function ce(n,a){if(n instanceof ke){const i=n;return{message:n.message,status:n.status,code:i.researchCode??"INTERNAL_ERROR",setupHint:i.setupHint,retryable:i.retryable}}return n instanceof Error?{message:n.message,code:"INTERNAL_ERROR"}:{message:a,code:"INTERNAL_ERROR"}}function qe(n){if(!n)return{cancelable:!1,retryable:!1,isTransitioning:!1,blockingReason:"No run selected"};const a=He.includes(n.status),i=n.status==="queued"||n.status==="running",v=n.lifecycle?.retryable,s=n.status==="failed"||n.status==="timed_out",_=!!(s&&v);let g;return!i&&a?g="Run is already transitioning":!i&&n.status==="completed"?g="Completed runs cannot be cancelled":!i&&n.status==="cancelled"?g="Run is already cancelled":!i&&n.status==="retry_exhausted"?g="Retry attempts exhausted":!i&&n.status==="failed"?g="Failed runs cannot be cancelled":!i&&n.status==="timed_out"&&(g="Timed out runs cannot be cancelled"),!_&&s&&v===!1&&(g=n.lifecycle?.errorCode==="RETRY_EXHAUSTED"?"Retry attempts exhausted":"Run is not retryable"),{cancelable:i,retryable:_,isTransitioning:a,blockingReason:g}}function Ue(n){const a=n?.projectId,i=a??"",v=`${ue.RESEARCH_RUNS_PREFIX}${i}`,s=`${ue.RESEARCH_SELECTED_ID_PREFIX}${i}`,_=W(v,{maxAgeMs:de}),g=W(s,{maxAgeMs:he}),r=c.useRef(Array.isArray(_)&&_.length>0),[I,P]=c.useState(()=>Array.isArray(_)?_:[]),[h,E]=c.useState(g??null),[A,N]=c.useState(null),[q,F]=c.useState({available:!0}),[M,T]=c.useState(!(Array.isArray(_)&&_.length>0)),[G,U]=c.useState(null),[V,S]=c.useState(null),[w,k]=c.useState(""),x=c.useRef(0),d=c.useRef(0),D=c.useRef(a);c.useEffect(()=>{D.current!==a&&(D.current=a,d.current++);const l=W(v,{maxAgeMs:de}),o=W(s,{maxAgeMs:he}),p=Array.isArray(l)&&l.length>0;P(Array.isArray(l)?l:[]),E(o??null),N(null),T(!p),r.current=p},[a,v,s]);const b=c.useCallback(async(l=w)=>{const o=++x.current,p=a;r.current||T(!0),U(null),S(null);try{const R=await xe({q:l||void 0,limit:100},p);if(o!==x.current||p!==a)return;P(R.runs),ae(v,R.runs,{maxBytes:5e5}),r.current=!0,F(R.availability),h&&!R.runs.some(y=>y.id===h)&&(E(null),ae(s,null,{maxBytes:5e5}),N(null))}catch(R){if(o!==x.current||p!==a)return;const y=ce(R,"Failed to load research runs");U(y.message),S(y)}finally{o===x.current&&T(!1)}},[a,v,w,s,h]),H=c.useCallback(async l=>{const o=await ye(l,a);return N(o.run),F(o.availability),o.run},[a]);c.useEffect(()=>{r.current||T(!0);const l=window.setTimeout(()=>{b(w)},Me);return()=>window.clearTimeout(l)},[b,w]),c.useEffect(()=>{if(!h){N(null);return}H(h)},[H,h]),c.useEffect(()=>{const l=d.current,o=()=>d.current!==l,p=a?`?projectId=${encodeURIComponent(a)}`:"";let R=!0;const y=()=>{!R||o()||(b(),h&&H(h))},j=`/api/events${p}`,O=ge(j,{events:{"research:run:created":y,"research:run:updated":y,"research:run:completed":y,"research:run:failed":y,"research:run:cancelled":y},onReconnect:()=>{X({view:"useResearch",trigger:"sse-reconnect",projectId:a,replayAttempted:!1,sseChannel:j}),y()}});X({view:"useResearch",trigger:"sse-open",projectId:a,replayAttempted:!1,sseChannel:j});const L=window.setInterval(y,De);return()=>{R=!1,O(),window.clearInterval(L)}},[a,b,h,H]);const B=c.useCallback(l=>{E(l),ae(s,l,{maxBytes:5e5})},[s]);return{runs:I,selectedRun:A,selectedRunId:h,setSelectedRunId:B,availability:q,loading:M,error:G,searchQuery:w,setSearchQuery:k,refresh:b,createRun:l=>Ne(l,a),cancelRun:async l=>{try{S(null);const o=await we(l,a);return h===l&&N(o.run),await b(),o}catch(o){const p=ce(o,"Failed to cancel run");throw S(p),p}},retryRun:async l=>{try{S(null);const o=await je(l,a);return h===l&&N(o.run),await b(),o}catch(o){const p=ce(o,"Failed to retry run");throw S(p),p}},exportRun:(l,o)=>Se(l,o,a),createTaskFromRun:(l,o,p,R,y,j)=>_e(l,{title:o,findingId:p,description:R,priority:y,attachExport:j},a),attachRunToTask:(l,o,p,R)=>Re(l,{taskId:o,findingId:p,attachExport:R},a),uiError:V,runActionState:qe(A),statusCounts:I.reduce((l,o)=>(l[o.status]+=1,l),{queued:0,running:0,cancelling:0,retry_waiting:0,completed:0,failed:0,cancelled:0,timed_out:0,retry_exhausted:0})}}function Oe({open:n,mode:a,run:i,finding:v,projectId:s,onClose:_,onConfirm:g}){const{t:r}=be("app");Ee(n);const[I,P]=c.useState(!1),[h,E]=c.useState(""),[A,N]=c.useState(""),[q,F]=c.useState("normal"),[M,T]=c.useState(""),[G,U]=c.useState([]),[V,S]=c.useState(!1),[w,k]=c.useState(!1),x=c.useMemo(()=>{const d=(v.content??"").split(/(?<=[.!?])\s+/)[0]??"";return`${v.heading||r("research.defaultFindingHeading","Research finding")} — ${d}`.trim()},[v.content,v.heading,r]);return c.useEffect(()=>{n&&(P(!1),E(`Research: ${v.heading||i.title}`),N(x),F("normal"),T(""),a==="enrich"&&(S(!0),Ce(50,0,s).then(d=>U(d.filter(D=>D.column!=="archived"))).finally(()=>S(!1))))},[n,a,s,v.heading,x,i.title]),n?e.jsx("div",{className:"modal-overlay open",role:"presentation",onClick:_,children:e.jsxs("div",{className:"modal modal-lg research-task-action-modal",role:"dialog","aria-modal":"true",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:a==="create"?r("research.createTaskTitle","Create task from finding"):r("research.enrichTaskTitle","Enrich existing task")}),e.jsx("button",{className:"modal-close",type:"button","aria-label":r("actions.close","Close"),onClick:_,children:"×"})]}),e.jsxs("div",{className:"research-task-action-modal__body",children:[e.jsxs("div",{className:"card research-task-action-modal__preview",children:[e.jsxs("p",{children:[e.jsxs("strong",{children:[r("research.runLabel","Run:")," "]})," ",i.id]}),e.jsxs("p",{children:[e.jsxs("strong",{children:[r("research.findingLabel","Finding:")," "]})," ",v.id,v.heading?` — ${v.heading}`:""]}),e.jsx("p",{children:x||r("research.noPreview","No preview available.")})]}),a==="create"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"research-task-action-modal__field",children:[r("research.titleLabel","Title"),e.jsx("input",{className:"input",value:h,onChange:d=>E(d.target.value)})]}),e.jsxs("label",{className:"research-task-action-modal__field",children:[r("research.descriptionLabel","Description"),e.jsx("textarea",{className:"input research-task-action-modal__textarea",value:A,onChange:d=>N(d.target.value)})]}),e.jsxs("label",{className:"research-task-action-modal__field",children:[r("research.priorityLabel","Priority"),e.jsxs("select",{className:"select",value:q,onChange:d=>F(d.target.value),children:[e.jsx("option",{value:"low",children:r("research.priorityLow","Low")}),e.jsx("option",{value:"normal",children:r("research.priorityNormal","Normal")}),e.jsx("option",{value:"high",children:r("research.priorityHigh","High")}),e.jsx("option",{value:"urgent",children:r("research.priorityUrgent","Urgent")})]})]})]}):e.jsxs("label",{className:"research-task-action-modal__field",children:[r("research.targetTaskLabel","Target task"),e.jsx("input",{className:"input",list:"research-task-action-task-list",value:M,placeholder:V?r("research.loadingTasks","Loading tasks…"):r("research.enterTaskId","Enter task ID"),onChange:d=>T(d.target.value)}),e.jsx("datalist",{id:"research-task-action-task-list",children:G.map(d=>e.jsx("option",{value:d.id,children:d.title},d.id))})]}),e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:I,onChange:d=>P(d.target.checked)}),e.jsx("span",{children:r("research.attachExport","Attach markdown export artifact")})]})]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",type:"button",onClick:_,children:r("actions.cancel","Cancel")}),e.jsx("button",{className:"btn btn-primary",type:"button",disabled:w||a==="enrich"&&!M,onClick:()=>{k(!0),g({taskId:a==="enrich"?M:void 0,title:a==="create"?h.trim():void 0,description:a==="create"?A.trim():void 0,priority:a==="create"?q:void 0,attachExport:I}).finally(()=>k(!1))},children:a==="create"?r("research.createTaskButton","Create Task"):r("research.enrichTaskButton","Enrich Task")})]})]})}):null}const Ge=["web-search","page-fetch","github","local-docs","llm-synthesis"],Ve={"web-search":"webSearch","page-fetch":"pageFetch",github:"github","local-docs":"localDocs","llm-synthesis":"llmSynthesis"};function $e(n){return{"web-search":n("research.providerWebSearch","Web Search"),"page-fetch":n("research.providerPageFetch","Page Fetch"),github:n("research.providerGitHub","GitHub"),"local-docs":n("research.providerLocalDocs","Local Docs"),"llm-synthesis":n("research.providerLlmSynthesis","LLM Synthesis")}}let ie=!1;function Je({projectId:n,addToast:a,onOpenSettings:i,readinessVersion:v=0}){const{t:s}=be("app"),_=$e(s);c.useEffect(()=>(X({view:"ResearchView",trigger:ie?"route-active":"remount",projectId:n,replayAttempted:!1}),ie=!1,()=>{ie=!0,X({view:"ResearchView",trigger:"route-inactive",projectId:n,replayAttempted:!1})}),[n]);const{runs:g,selectedRun:r,selectedRunId:I,setSelectedRunId:P,availability:h,loading:E,error:A,searchQuery:N,setSearchQuery:q,createRun:F,cancelRun:M,retryRun:T,exportRun:G,createTaskFromRun:U,attachRunToTask:V,statusCounts:S,refresh:w,uiError:k,runActionState:x}=Ue({projectId:n}),[d,D]=c.useState(""),[b,H]=c.useState(()=>ne(void 0)),[B,l]=c.useState([]),[o,p]=c.useState(!1),[R,y]=c.useState([]),[j,O]=c.useState(null),[L,K]=c.useState(null),Y=h.supportedProviders??Ge,J=b.searchProvider,Z=t=>t==="web-search"?!0:b.enabledSources[Ve[t]];c.useEffect(()=>{const t=Y.filter(u=>Z(u));y(u=>{const f=u.filter(m=>t.includes(m));return f.length>0?f:t})},[b.enabledSources,Y]),c.useEffect(()=>{let t=!1;return Promise.all([Ae(n),Te().catch(()=>({providers:[]}))]).then(([u,f])=>{t||(H(ne(u)),l(f.providers.filter(m=>m.type==="api_key").map(m=>({id:m.id,authenticated:m.authenticated}))))}).catch(()=>{t||H(ne(void 0))}),()=>{t=!0}},[n,v]);const pe=c.useMemo(()=>r?r.status:s("research.noRunSelected","No run selected"),[r,s]),fe=c.useMemo(()=>r?r.status==="queued"||r.status==="retry_waiting"?"status-dot status-dot--pending":r.status==="running"?"status-dot status-dot--connecting":r.status==="completed"?"status-dot status-dot--online":r.status==="failed"||r.status==="cancelled"?"status-dot status-dot--error":"status-dot":"status-dot",[r]),ee=h.supportedExportFormats??["markdown","json","html"],se=c.useMemo(()=>new Map(B.map(t=>[t.id,t.authenticated])),[B]),re=c.useMemo(()=>{const t=new Set;return b.enabledSources.webSearch&&J&&t.add(J),b.enabledSources.llmSynthesis&&b.synthesisProvider&&t.add(b.synthesisProvider),[...t].filter(u=>se.has(u))},[b.enabledSources.llmSynthesis,b.enabledSources.webSearch,b.synthesisProvider,J,se]).find(t=>se.get(t)!==!0),$=c.useMemo(()=>h.available?b.enabled?re?{reason:s("research.missingApiKey","Missing API key for {{provider}}.",{provider:re}),details:s("research.addCredentialsHint","Add provider credentials in Authentication settings."),settingsSection:"authentication"}:null:{reason:s("research.disabled","Research is disabled for this project."),details:s("research.enableResearchHint","Enable project research settings to create runs."),settingsSection:"research-project"}:{reason:h.reason??s("research.unavailable","Research is unavailable for this project."),details:h.setupInstructions,settingsSection:"research-project"},[h.available,h.reason,h.setupInstructions,b.enabled,re,s]),z=async(t,u,f)=>{O(t);try{await u(),a?.(f,"success"),await w()}catch(m){a?.(m instanceof Error?m.message:s("research.actionFailed","Action failed"),"error")}finally{O(null)}},te=async t=>{if(r){O(`export-${t}`);try{const u=await G(r.id,t),f=new Blob([u.content],{type:"text/plain;charset=utf-8"}),m=URL.createObjectURL(f),C=document.createElement("a");C.href=m,C.download=u.filename,document.body.appendChild(C),C.click(),C.remove(),URL.revokeObjectURL(m),a?.(s("research.exportedFile","Exported {{filename}}",{filename:u.filename}),"success")}catch(u){a?.(u instanceof Error?u.message:s("research.exportFailed","Export failed"),"error")}finally{O(null)}}},ve=async()=>{if(d.trim()){p(!0);try{const t=R.filter(f=>Z(f));if(t.length===0){p(!1),a?.(s("research.noSourcesAvailable","No enabled research sources are available for this project."),"error");return}const u=await F({query:d.trim(),providers:t});P(u.run.id),D(""),a?.(s("research.runCreated","Research run created"),"success"),await w()}catch(t){a?.(t instanceof Error?t.message:s("research.createRunFailed","Failed to create run"),"error")}finally{p(!1)}}};return e.jsxs("section",{className:"research-view","aria-label":s("research.viewLabel","Research view"),children:[e.jsx(Le,{icon:me,title:s("research.title","Research"),actions:e.jsx("button",{className:"btn",type:"button",onClick:()=>void w(),children:s("actions.refresh","Refresh")})}),e.jsx("p",{className:"research-view__subtitle",children:s("research.subtitle","Cited search and synthesis runs: gather sources, fetch content, and synthesize findings.")}),$?e.jsxs("div",{className:"research-view__state research-view__state--error card","data-testid":"research-state-unavailable",children:[e.jsx("p",{children:$.reason}),$.details&&e.jsx("p",{children:$.details}),e.jsx("p",{children:s("research.currentDefaults","Current defaults: provider {{provider}}, max sources {{maxSources}}",{provider:b.searchProvider??s("research.notSet","(not set)"),maxSources:b.limits.maxSourcesPerRun})}),e.jsxs("div",{className:"research-view__actions",children:[e.jsx("button",{className:"btn",type:"button",onClick:()=>void w(),children:s("actions.refresh","Refresh")}),e.jsx("button",{className:"btn btn-primary",type:"button",onClick:()=>i?.($.settingsSection),children:s("actions.openSettings","Open Settings")})]})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"research-view__layout",children:[e.jsx("aside",{className:"research-view__sidebar card",children:e.jsxs("div",{className:"research-view__sidebar-content",children:[e.jsxs("div",{className:"research-view__form",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"research-query",children:s("research.queryLabel","Query")}),e.jsx("textarea",{id:"research-query",className:"input research-view__textarea",value:d,onChange:t=>D(t.target.value)})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:s("research.providersLabel","Providers")}),e.jsx("div",{className:"research-view__providers",children:Y.map(t=>{const u=Z(t),f=t==="web-search";return e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:f||R.includes(t),disabled:f||!u,onChange:()=>{f||!u||y(m=>m.includes(t)?m.filter(C=>C!==t):[...m,t])}}),e.jsxs("span",{children:[_[t]??t,f?e.jsx("span",{className:"research-view__provider-lock",children:s("research.alwaysOn","Always on")}):null]})]},t)})})]}),e.jsxs("button",{className:"btn btn-primary",type:"button",disabled:!d.trim()||o,onClick:()=>void ve(),children:[o?e.jsx(Pe,{className:"animate-spin",size:14}):null,s("research.createRun","Create Run")]})]}),e.jsxs("div",{className:"research-view__history-header form-group",children:[e.jsx("label",{htmlFor:"research-run-search",children:s("actions.search","Search")}),e.jsxs("div",{className:"research-view__history-search-row",children:[e.jsx(me,{size:14}),e.jsx("input",{id:"research-run-search",className:"input",placeholder:s("research.searchRunsPlaceholder","Search runs"),value:N,onChange:t=>q(t.target.value)})]})]}),e.jsx("div",{className:"research-view__history","data-testid":"research-state-running",children:g.map(t=>e.jsxs("button",{type:"button",className:`research-view__history-item card${I===t.id?" research-view__history-item--active":""}`,onClick:()=>P(t.id),children:[e.jsx("span",{className:"card-id",children:t.id}),e.jsx("span",{children:t.title})]},t.id))})]})}),e.jsxs("div",{className:"research-view__reader card",children:[E&&e.jsx("p",{"data-testid":"research-state-loading",children:e.jsx(Ie,{label:s("research.loadingRuns","Loading research runs…")})}),!E&&A&&e.jsx("p",{"data-testid":"research-state-error",children:A}),!E&&!A&&g.length===0&&e.jsx("p",{"data-testid":"research-state-empty",children:s("research.noRunsYet","No research runs yet")}),e.jsxs("div",{className:"research-view__reader-content",children:[r&&e.jsxs("div",{className:"research-view__run-detail",children:[e.jsxs("div",{className:"research-view__status-row",children:[e.jsx("span",{className:fe}),e.jsx("strong",{children:pe})]}),e.jsx("h3",{className:"research-view__run-title",children:r.title}),e.jsx("p",{className:"research-view__run-query",children:r.query}),e.jsx("p",{className:"research-view__run-summary","data-testid":"research-state-results",children:r.results?.summary??s("research.noSummaryYet","No summary yet.")}),e.jsxs("div",{className:"research-view__actions",children:[e.jsx("button",{className:"btn",type:"button",title:x.cancelable?void 0:x.blockingReason,disabled:j==="cancel"||j==="retry"||!x.cancelable,onClick:()=>void z("cancel",()=>M(r.id),s("research.runCancelled","Run cancelled")),children:s("actions.cancel","Cancel")}),e.jsx("button",{className:"btn",type:"button",title:x.retryable?void 0:x.blockingReason,disabled:j==="cancel"||j==="retry"||!x.retryable,onClick:()=>void z("retry",()=>T(r.id),s("research.runRetried","Run retried")),children:s("actions.retry","Retry")}),ee.includes("markdown")&&e.jsx("button",{className:"btn",type:"button",disabled:j==="export-markdown",onClick:()=>void te("markdown"),children:s("research.exportMd","Export MD")}),ee.includes("json")&&e.jsx("button",{className:"btn",type:"button",disabled:j==="export-json",onClick:()=>void te("json"),children:s("research.exportJson","Export JSON")}),ee.includes("html")&&e.jsx("button",{className:"btn",type:"button",disabled:j==="export-html",onClick:()=>void te("html"),children:s("research.exportHtml","Export HTML")})]}),r.error&&e.jsx("p",{className:"research-view__error",children:r.error}),k&&e.jsxs("div",{className:"form-error",role:"alert",children:[e.jsx("p",{children:k.message}),k.setupHint&&e.jsx("p",{children:k.setupHint}),k.code==="MISSING_CREDENTIALS"&&e.jsx("button",{className:"btn btn-sm",type:"button",onClick:()=>i?.("authentication"),children:s("research.openAuthSettings","Open Authentication Settings")}),k.code==="FEATURE_DISABLED"&&e.jsx("button",{className:"btn btn-sm",type:"button",onClick:()=>i?.("research-project"),children:s("research.openResearchSettings","Open Research Settings")})]}),x.blockingReason&&e.jsx("p",{className:"research-view__run-query",children:x.blockingReason}),Array.isArray(r.results?.findings)&&r.results.findings.length>0&&e.jsx("div",{className:"research-view__findings",children:r.results.findings.map((t,u)=>{const m=t.id?.trim()||`finding-${u+1}`;return e.jsxs("article",{className:"research-view__finding card",children:[e.jsx("h4",{children:t.heading}),e.jsx("p",{children:t.content}),e.jsxs("div",{className:"research-view__actions research-view__finding-actions",children:[e.jsx("button",{className:"btn btn-primary btn-sm",type:"button",onClick:()=>K({mode:"create",findingId:m}),children:s("research.createTask","Create Task")}),e.jsx("button",{className:"btn btn-sm",type:"button",onClick:()=>K({mode:"enrich",findingId:m}),children:s("research.enrichTask","Enrich Task")})]})]},m)})}),Array.isArray(r.results?.citations)&&r.results.citations.length>0&&e.jsx("ul",{className:"research-view__citations",children:r.results.citations.map(t=>e.jsx("li",{children:e.jsx("a",{href:t,target:"_blank",rel:"noreferrer",children:t})},t))}),r.events.length>0&&e.jsxs("details",{children:[e.jsx("summary",{children:s("research.runHistory","Run history")}),e.jsx("ul",{className:"research-view__events",children:r.events.map(t=>e.jsx("li",{children:t.message},t.id))})]})]}),!r&&g.length>0&&e.jsx("p",{children:s("research.selectRunToViewDetails","Select a run to view details.")}),e.jsxs("div",{className:"research-view__stats",children:[e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:s("research.statRunning","Running")}),e.jsx("div",{className:"research-view__stat-value",children:S.running})]}),e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:s("research.statCompleted","Completed")}),e.jsx("div",{className:"research-view__stat-value",children:S.completed})]}),e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:s("research.statFailed","Failed")}),e.jsx("div",{className:"research-view__stat-value",children:S.failed})]})]})]})]})]})}),r&&L&&(()=>{const t=r.results?.findings?.findIndex((f,m)=>(f.id?.trim()||`finding-${m+1}`)===L.findingId)??-1,u=t>=0?r.results.findings[t]:null;return u?e.jsx(Oe,{open:!0,mode:L.mode,run:r,finding:{id:L.findingId,heading:u.heading,content:u.content},projectId:n,onClose:()=>K(null),onConfirm:async({taskId:f,title:m,description:C,priority:le,attachExport:oe})=>{L.mode==="create"?await z("create-task",()=>U(r.id,m,L.findingId,C,le,oe),s("research.taskCreatedFromResearch","Task created from research")):f&&await z("attach-task",()=>V(r.id,f,L.findingId,oe),s("research.taskEnrichedFromResearch","Task enriched from research")),K(null)}}):null})()]})}export{Je as ResearchView};
1
+ import{r as c,j as e}from"./vendor-react-SZ_qB27O.js";import{aD as z,aE as de,aF as ue,bk as he,bB as xe,aI as ae,bC as ye,a5 as ge,bD as X,bE as Re,bF as _e,bG as Se,bH as je,bI as we,bJ as Ne,bo as ke,bK as Ee,bL as Ce,aK as Ae,au as Te,V as Le,bM as me,L as Pe,a8 as Fe}from"./index-D8sgsB8q.js";import{u as be}from"./vendor-i18n-GF3RlKbq.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.js";const Ie="builtin",Q={pageFetch:!0,github:!1,localDocs:!0,llmSynthesis:!0};function ne(n){const a=n?.researchGlobalDefaults,i=n?.researchSettings;return{enabled:i?.enabled??n?.researchEnabled??n?.researchGlobalEnabled??!0,searchProvider:i?.searchProvider??a?.searchProvider??n?.researchGlobalWebSearchProvider??Ie,synthesisProvider:i?.synthesisProvider??a?.synthesisProvider,synthesisModelId:i?.synthesisModelId??a?.synthesisModelId,enabledSources:{webSearch:!0,pageFetch:i?.enabledSources?.pageFetch??a?.enabledSources?.pageFetch??Q.pageFetch,github:i?.enabledSources?.github??a?.enabledSources?.github??Q.github,localDocs:i?.enabledSources?.localDocs??a?.enabledSources?.localDocs??Q.localDocs,llmSynthesis:i?.enabledSources?.llmSynthesis??a?.enabledSources?.llmSynthesis??Q.llmSynthesis},limits:{maxConcurrentRuns:i?.limits?.maxConcurrentRuns??n?.researchMaxConcurrentRuns??n?.researchGlobalMaxConcurrentRuns??3,maxSourcesPerRun:i?.limits?.maxSourcesPerRun??a?.maxSourcesPerRun??n?.researchMaxSourcesPerRun??n?.researchGlobalMaxSourcesPerRun??20,maxDurationMs:i?.limits?.maxDurationMs??n?.researchDefaultTimeout??n?.researchGlobalDefaultTimeout??3e5,requestTimeoutMs:i?.limits?.requestTimeoutMs??n?.researchGlobalFetchTimeoutMs??3e4},defaultExportFormat:a?.defaultExportFormat??"markdown"}}const Me=300,De=4e3,He=["queued","running","cancelling","retry_waiting"];function ce(n,a){if(n instanceof ke){const i=n;return{message:n.message,status:n.status,code:i.researchCode??"INTERNAL_ERROR",setupHint:i.setupHint,retryable:i.retryable}}return n instanceof Error?{message:n.message,code:"INTERNAL_ERROR"}:{message:a,code:"INTERNAL_ERROR"}}function qe(n){if(!n)return{cancelable:!1,retryable:!1,isTransitioning:!1,blockingReason:"No run selected"};const a=He.includes(n.status),i=n.status==="queued"||n.status==="running",v=n.lifecycle?.retryable,s=n.status==="failed"||n.status==="timed_out",_=!!(s&&v);let g;return!i&&a?g="Run is already transitioning":!i&&n.status==="completed"?g="Completed runs cannot be cancelled":!i&&n.status==="cancelled"?g="Run is already cancelled":!i&&n.status==="retry_exhausted"?g="Retry attempts exhausted":!i&&n.status==="failed"?g="Failed runs cannot be cancelled":!i&&n.status==="timed_out"&&(g="Timed out runs cannot be cancelled"),!_&&s&&v===!1&&(g=n.lifecycle?.errorCode==="RETRY_EXHAUSTED"?"Retry attempts exhausted":"Run is not retryable"),{cancelable:i,retryable:_,isTransitioning:a,blockingReason:g}}function Ue(n){const a=n?.projectId,i=a??"",v=`${ue.RESEARCH_RUNS_PREFIX}${i}`,s=`${ue.RESEARCH_SELECTED_ID_PREFIX}${i}`,_=z(v,{maxAgeMs:de}),g=z(s,{maxAgeMs:he}),r=c.useRef(Array.isArray(_)&&_.length>0),[F,P]=c.useState(()=>Array.isArray(_)?_:[]),[h,E]=c.useState(g??null),[A,N]=c.useState(null),[q,I]=c.useState({available:!0}),[M,T]=c.useState(!(Array.isArray(_)&&_.length>0)),[G,U]=c.useState(null),[V,S]=c.useState(null),[w,k]=c.useState(""),x=c.useRef(0),d=c.useRef(0),D=c.useRef(a);c.useEffect(()=>{D.current!==a&&(D.current=a,d.current++);const l=z(v,{maxAgeMs:de}),o=z(s,{maxAgeMs:he}),p=Array.isArray(l)&&l.length>0;P(Array.isArray(l)?l:[]),E(o??null),N(null),T(!p),r.current=p},[a,v,s]);const b=c.useCallback(async(l=w)=>{const o=++x.current,p=a;r.current||T(!0),U(null),S(null);try{const R=await xe({q:l||void 0,limit:100},p);if(o!==x.current||p!==a)return;P(R.runs),ae(v,R.runs,{maxBytes:5e5}),r.current=!0,I(R.availability),h&&!R.runs.some(y=>y.id===h)&&(E(null),ae(s,null,{maxBytes:5e5}),N(null))}catch(R){if(o!==x.current||p!==a)return;const y=ce(R,"Failed to load research runs");U(y.message),S(y)}finally{o===x.current&&T(!1)}},[a,v,w,s,h]),H=c.useCallback(async l=>{const o=await ye(l,a);return N(o.run),I(o.availability),o.run},[a]);c.useEffect(()=>{r.current||T(!0);const l=window.setTimeout(()=>{b(w)},Me);return()=>window.clearTimeout(l)},[b,w]),c.useEffect(()=>{if(!h){N(null);return}H(h)},[H,h]),c.useEffect(()=>{const l=d.current,o=()=>d.current!==l,p=a?`?projectId=${encodeURIComponent(a)}`:"";let R=!0;const y=()=>{!R||o()||(b(),h&&H(h))},j=`/api/events${p}`,O=ge(j,{events:{"research:run:created":y,"research:run:updated":y,"research:run:completed":y,"research:run:failed":y,"research:run:cancelled":y},onReconnect:()=>{X({view:"useResearch",trigger:"sse-reconnect",projectId:a,replayAttempted:!1,sseChannel:j}),y()}});X({view:"useResearch",trigger:"sse-open",projectId:a,replayAttempted:!1,sseChannel:j});const L=window.setInterval(y,De);return()=>{R=!1,O(),window.clearInterval(L)}},[a,b,h,H]);const B=c.useCallback(l=>{E(l),ae(s,l,{maxBytes:5e5})},[s]);return{runs:F,selectedRun:A,selectedRunId:h,setSelectedRunId:B,availability:q,loading:M,error:G,searchQuery:w,setSearchQuery:k,refresh:b,createRun:l=>Ne(l,a),cancelRun:async l=>{try{S(null);const o=await we(l,a);return h===l&&N(o.run),await b(),o}catch(o){const p=ce(o,"Failed to cancel run");throw S(p),p}},retryRun:async l=>{try{S(null);const o=await je(l,a);return h===l&&N(o.run),await b(),o}catch(o){const p=ce(o,"Failed to retry run");throw S(p),p}},exportRun:(l,o)=>Se(l,o,a),createTaskFromRun:(l,o,p,R,y,j)=>_e(l,{title:o,findingId:p,description:R,priority:y,attachExport:j},a),attachRunToTask:(l,o,p,R)=>Re(l,{taskId:o,findingId:p,attachExport:R},a),uiError:V,runActionState:qe(A),statusCounts:F.reduce((l,o)=>(l[o.status]+=1,l),{queued:0,running:0,cancelling:0,retry_waiting:0,completed:0,failed:0,cancelled:0,timed_out:0,retry_exhausted:0})}}function Oe({open:n,mode:a,run:i,finding:v,projectId:s,onClose:_,onConfirm:g}){const{t:r}=be("app");Ee(n);const[F,P]=c.useState(!1),[h,E]=c.useState(""),[A,N]=c.useState(""),[q,I]=c.useState("normal"),[M,T]=c.useState(""),[G,U]=c.useState([]),[V,S]=c.useState(!1),[w,k]=c.useState(!1),x=c.useMemo(()=>{const d=(v.content??"").split(/(?<=[.!?])\s+/)[0]??"";return`${v.heading||r("research.defaultFindingHeading","Research finding")} — ${d}`.trim()},[v.content,v.heading,r]);return c.useEffect(()=>{n&&(P(!1),E(`Research: ${v.heading||i.title}`),N(x),I("normal"),T(""),a==="enrich"&&(S(!0),Ce(50,0,s).then(d=>U(d.filter(D=>D.column!=="archived"))).finally(()=>S(!1))))},[n,a,s,v.heading,x,i.title]),n?e.jsx("div",{className:"modal-overlay open",role:"presentation",onClick:_,children:e.jsxs("div",{className:"modal modal-lg research-task-action-modal",role:"dialog","aria-modal":"true",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:a==="create"?r("research.createTaskTitle","Create task from finding"):r("research.enrichTaskTitle","Enrich existing task")}),e.jsx("button",{className:"modal-close",type:"button","aria-label":r("actions.close","Close"),onClick:_,children:"×"})]}),e.jsxs("div",{className:"research-task-action-modal__body",children:[e.jsxs("div",{className:"card research-task-action-modal__preview",children:[e.jsxs("p",{children:[e.jsxs("strong",{children:[r("research.runLabel","Run:")," "]})," ",i.id]}),e.jsxs("p",{children:[e.jsxs("strong",{children:[r("research.findingLabel","Finding:")," "]})," ",v.id,v.heading?` — ${v.heading}`:""]}),e.jsx("p",{children:x||r("research.noPreview","No preview available.")})]}),a==="create"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"research-task-action-modal__field",children:[r("research.titleLabel","Title"),e.jsx("input",{className:"input",value:h,onChange:d=>E(d.target.value)})]}),e.jsxs("label",{className:"research-task-action-modal__field",children:[r("research.descriptionLabel","Description"),e.jsx("textarea",{className:"input research-task-action-modal__textarea",value:A,onChange:d=>N(d.target.value)})]}),e.jsxs("label",{className:"research-task-action-modal__field",children:[r("research.priorityLabel","Priority"),e.jsxs("select",{className:"select",value:q,onChange:d=>I(d.target.value),children:[e.jsx("option",{value:"low",children:r("research.priorityLow","Low")}),e.jsx("option",{value:"normal",children:r("research.priorityNormal","Normal")}),e.jsx("option",{value:"high",children:r("research.priorityHigh","High")}),e.jsx("option",{value:"urgent",children:r("research.priorityUrgent","Urgent")})]})]})]}):e.jsxs("label",{className:"research-task-action-modal__field",children:[r("research.targetTaskLabel","Target task"),e.jsx("input",{className:"input",list:"research-task-action-task-list",value:M,placeholder:V?r("research.loadingTasks","Loading tasks…"):r("research.enterTaskId","Enter task ID"),onChange:d=>T(d.target.value)}),e.jsx("datalist",{id:"research-task-action-task-list",children:G.map(d=>e.jsx("option",{value:d.id,children:d.title},d.id))})]}),e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:F,onChange:d=>P(d.target.checked)}),e.jsx("span",{children:r("research.attachExport","Attach markdown export artifact")})]})]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",type:"button",onClick:_,children:r("actions.cancel","Cancel")}),e.jsx("button",{className:"btn btn-primary",type:"button",disabled:w||a==="enrich"&&!M,onClick:()=>{k(!0),g({taskId:a==="enrich"?M:void 0,title:a==="create"?h.trim():void 0,description:a==="create"?A.trim():void 0,priority:a==="create"?q:void 0,attachExport:F}).finally(()=>k(!1))},children:a==="create"?r("research.createTaskButton","Create Task"):r("research.enrichTaskButton","Enrich Task")})]})]})}):null}const Ge=["web-search","page-fetch","github","local-docs","llm-synthesis"],Ve={"web-search":"webSearch","page-fetch":"pageFetch",github:"github","local-docs":"localDocs","llm-synthesis":"llmSynthesis"};function $e(n){return{"web-search":n("research.providerWebSearch","Web Search"),"page-fetch":n("research.providerPageFetch","Page Fetch"),github:n("research.providerGitHub","GitHub"),"local-docs":n("research.providerLocalDocs","Local Docs"),"llm-synthesis":n("research.providerLlmSynthesis","LLM Synthesis")}}let ie=!1;function Je({projectId:n,addToast:a,onOpenSettings:i,readinessVersion:v=0}){const{t:s}=be("app"),_=$e(s);c.useEffect(()=>(X({view:"ResearchView",trigger:ie?"route-active":"remount",projectId:n,replayAttempted:!1}),ie=!1,()=>{ie=!0,X({view:"ResearchView",trigger:"route-inactive",projectId:n,replayAttempted:!1})}),[n]);const{runs:g,selectedRun:r,selectedRunId:F,setSelectedRunId:P,availability:h,loading:E,error:A,searchQuery:N,setSearchQuery:q,createRun:I,cancelRun:M,retryRun:T,exportRun:G,createTaskFromRun:U,attachRunToTask:V,statusCounts:S,refresh:w,uiError:k,runActionState:x}=Ue({projectId:n}),[d,D]=c.useState(""),[b,H]=c.useState(()=>ne(void 0)),[B,l]=c.useState([]),[o,p]=c.useState(!1),[R,y]=c.useState([]),[j,O]=c.useState(null),[L,K]=c.useState(null),Y=h.supportedProviders??Ge,J=b.searchProvider,Z=t=>t==="web-search"?!0:b.enabledSources[Ve[t]];c.useEffect(()=>{const t=Y.filter(u=>Z(u));y(u=>{const f=u.filter(m=>t.includes(m));return f.length>0?f:t})},[b.enabledSources,Y]),c.useEffect(()=>{let t=!1;return Promise.all([Ae(n),Te().catch(()=>({providers:[]}))]).then(([u,f])=>{t||(H(ne(u)),l(f.providers.filter(m=>m.type==="api_key").map(m=>({id:m.id,authenticated:m.authenticated}))))}).catch(()=>{t||H(ne(void 0))}),()=>{t=!0}},[n,v]);const pe=c.useMemo(()=>r?r.status:s("research.noRunSelected","No run selected"),[r,s]),fe=c.useMemo(()=>r?r.status==="queued"||r.status==="retry_waiting"?"status-dot status-dot--pending":r.status==="running"?"status-dot status-dot--connecting":r.status==="completed"?"status-dot status-dot--online":r.status==="failed"||r.status==="cancelled"?"status-dot status-dot--error":"status-dot":"status-dot",[r]),ee=h.supportedExportFormats??["markdown","json","html"],se=c.useMemo(()=>new Map(B.map(t=>[t.id,t.authenticated])),[B]),re=c.useMemo(()=>{const t=new Set;return b.enabledSources.webSearch&&J&&t.add(J),b.enabledSources.llmSynthesis&&b.synthesisProvider&&t.add(b.synthesisProvider),[...t].filter(u=>se.has(u))},[b.enabledSources.llmSynthesis,b.enabledSources.webSearch,b.synthesisProvider,J,se]).find(t=>se.get(t)!==!0),$=c.useMemo(()=>h.available?b.enabled?re?{reason:s("research.missingApiKey","Missing API key for {{provider}}.",{provider:re}),details:s("research.addCredentialsHint","Add provider credentials in Authentication settings."),settingsSection:"authentication"}:null:{reason:s("research.disabled","Research is disabled for this project."),details:s("research.enableResearchHint","Enable project research settings to create runs."),settingsSection:"research-project"}:{reason:h.reason??s("research.unavailable","Research is unavailable for this project."),details:h.setupInstructions,settingsSection:"research-project"},[h.available,h.reason,h.setupInstructions,b.enabled,re,s]),W=async(t,u,f)=>{O(t);try{await u(),a?.(f,"success"),await w()}catch(m){a?.(m instanceof Error?m.message:s("research.actionFailed","Action failed"),"error")}finally{O(null)}},te=async t=>{if(r){O(`export-${t}`);try{const u=await G(r.id,t),f=new Blob([u.content],{type:"text/plain;charset=utf-8"}),m=URL.createObjectURL(f),C=document.createElement("a");C.href=m,C.download=u.filename,document.body.appendChild(C),C.click(),C.remove(),URL.revokeObjectURL(m),a?.(s("research.exportedFile","Exported {{filename}}",{filename:u.filename}),"success")}catch(u){a?.(u instanceof Error?u.message:s("research.exportFailed","Export failed"),"error")}finally{O(null)}}},ve=async()=>{if(d.trim()){p(!0);try{const t=R.filter(f=>Z(f));if(t.length===0){p(!1),a?.(s("research.noSourcesAvailable","No enabled research sources are available for this project."),"error");return}const u=await I({query:d.trim(),providers:t});P(u.run.id),D(""),a?.(s("research.runCreated","Research run created"),"success"),await w()}catch(t){a?.(t instanceof Error?t.message:s("research.createRunFailed","Failed to create run"),"error")}finally{p(!1)}}};return e.jsxs("section",{className:"research-view","aria-label":s("research.viewLabel","Research view"),children:[e.jsx(Le,{icon:me,title:s("research.title","Research"),actions:e.jsx("button",{className:"btn",type:"button",onClick:()=>void w(),children:s("actions.refresh","Refresh")})}),e.jsx("p",{className:"research-view__subtitle",children:s("research.subtitle","Cited search and synthesis runs: gather sources, fetch content, and synthesize findings.")}),$?e.jsxs("div",{className:"research-view__state research-view__state--error card","data-testid":"research-state-unavailable",children:[e.jsx("p",{children:$.reason}),$.details&&e.jsx("p",{children:$.details}),e.jsx("p",{children:s("research.currentDefaults","Current defaults: provider {{provider}}, max sources {{maxSources}}",{provider:b.searchProvider??s("research.notSet","(not set)"),maxSources:b.limits.maxSourcesPerRun})}),e.jsxs("div",{className:"research-view__actions",children:[e.jsx("button",{className:"btn",type:"button",onClick:()=>void w(),children:s("actions.refresh","Refresh")}),e.jsx("button",{className:"btn btn-primary",type:"button",onClick:()=>i?.($.settingsSection),children:s("actions.openSettings","Open Settings")})]})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"research-view__layout",children:[e.jsx("aside",{className:"research-view__sidebar card",children:e.jsxs("div",{className:"research-view__sidebar-content",children:[e.jsxs("div",{className:"research-view__form",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"research-query",children:s("research.queryLabel","Query")}),e.jsx("textarea",{id:"research-query",className:"input research-view__textarea",value:d,onChange:t=>D(t.target.value)})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:s("research.providersLabel","Providers")}),e.jsx("div",{className:"research-view__providers",children:Y.map(t=>{const u=Z(t),f=t==="web-search";return e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:f||R.includes(t),disabled:f||!u,onChange:()=>{f||!u||y(m=>m.includes(t)?m.filter(C=>C!==t):[...m,t])}}),e.jsxs("span",{children:[_[t]??t,f?e.jsx("span",{className:"research-view__provider-lock",children:s("research.alwaysOn","Always on")}):null]})]},t)})})]}),e.jsxs("button",{className:"btn btn-primary",type:"button",disabled:!d.trim()||o,onClick:()=>void ve(),children:[o?e.jsx(Pe,{className:"animate-spin",size:14}):null,s("research.createRun","Create Run")]})]}),e.jsxs("div",{className:"research-view__history-header form-group",children:[e.jsx("label",{htmlFor:"research-run-search",children:s("actions.search","Search")}),e.jsxs("div",{className:"research-view__history-search-row",children:[e.jsx(me,{size:14}),e.jsx("input",{id:"research-run-search",className:"input",placeholder:s("research.searchRunsPlaceholder","Search runs"),value:N,onChange:t=>q(t.target.value)})]})]}),e.jsx("div",{className:"research-view__history","data-testid":"research-state-running",children:g.map(t=>e.jsxs("button",{type:"button",className:`research-view__history-item card${F===t.id?" research-view__history-item--active":""}`,onClick:()=>P(t.id),children:[e.jsx("span",{className:"card-id",children:t.id}),e.jsx("span",{children:t.title})]},t.id))})]})}),e.jsxs("div",{className:"research-view__reader card",children:[E&&e.jsx("p",{"data-testid":"research-state-loading",children:e.jsx(Fe,{label:s("research.loadingRuns","Loading research runs…")})}),!E&&A&&e.jsx("p",{"data-testid":"research-state-error",children:A}),!E&&!A&&g.length===0&&e.jsx("p",{"data-testid":"research-state-empty",children:s("research.noRunsYet","No research runs yet")}),e.jsxs("div",{className:"research-view__reader-content",children:[r&&e.jsxs("div",{className:"research-view__run-detail",children:[e.jsxs("div",{className:"research-view__status-row",children:[e.jsx("span",{className:fe}),e.jsx("strong",{children:pe})]}),e.jsx("h3",{className:"research-view__run-title",children:r.title}),e.jsx("p",{className:"research-view__run-query",children:r.query}),e.jsx("p",{className:"research-view__run-summary","data-testid":"research-state-results",children:r.results?.summary??s("research.noSummaryYet","No summary yet.")}),e.jsxs("div",{className:"research-view__actions",children:[e.jsx("button",{className:"btn",type:"button",title:x.cancelable?void 0:x.blockingReason,disabled:j==="cancel"||j==="retry"||!x.cancelable,onClick:()=>void W("cancel",()=>M(r.id),s("research.runCancelled","Run cancelled")),children:s("actions.cancel","Cancel")}),e.jsx("button",{className:"btn",type:"button",title:x.retryable?void 0:x.blockingReason,disabled:j==="cancel"||j==="retry"||!x.retryable,onClick:()=>void W("retry",()=>T(r.id),s("research.runRetried","Run retried")),children:s("actions.retry","Retry")}),ee.includes("markdown")&&e.jsx("button",{className:"btn",type:"button",disabled:j==="export-markdown",onClick:()=>void te("markdown"),children:s("research.exportMd","Export MD")}),ee.includes("json")&&e.jsx("button",{className:"btn",type:"button",disabled:j==="export-json",onClick:()=>void te("json"),children:s("research.exportJson","Export JSON")}),ee.includes("html")&&e.jsx("button",{className:"btn",type:"button",disabled:j==="export-html",onClick:()=>void te("html"),children:s("research.exportHtml","Export HTML")})]}),r.error&&e.jsx("p",{className:"research-view__error",children:r.error}),k&&e.jsxs("div",{className:"form-error",role:"alert",children:[e.jsx("p",{children:k.message}),k.setupHint&&e.jsx("p",{children:k.setupHint}),k.code==="MISSING_CREDENTIALS"&&e.jsx("button",{className:"btn btn-sm",type:"button",onClick:()=>i?.("authentication"),children:s("research.openAuthSettings","Open Authentication Settings")}),k.code==="FEATURE_DISABLED"&&e.jsx("button",{className:"btn btn-sm",type:"button",onClick:()=>i?.("research-project"),children:s("research.openResearchSettings","Open Research Settings")})]}),x.blockingReason&&e.jsx("p",{className:"research-view__run-query",children:x.blockingReason}),Array.isArray(r.results?.findings)&&r.results.findings.length>0&&e.jsx("div",{className:"research-view__findings",children:r.results.findings.map((t,u)=>{const m=t.id?.trim()||`finding-${u+1}`;return e.jsxs("article",{className:"research-view__finding card",children:[e.jsx("h4",{children:t.heading}),e.jsx("p",{children:t.content}),e.jsxs("div",{className:"research-view__actions research-view__finding-actions",children:[e.jsx("button",{className:"btn btn-primary btn-sm",type:"button",onClick:()=>K({mode:"create",findingId:m}),children:s("research.createTask","Create Task")}),e.jsx("button",{className:"btn btn-sm",type:"button",onClick:()=>K({mode:"enrich",findingId:m}),children:s("research.enrichTask","Enrich Task")})]})]},m)})}),Array.isArray(r.results?.citations)&&r.results.citations.length>0&&e.jsx("ul",{className:"research-view__citations",children:r.results.citations.map(t=>e.jsx("li",{children:e.jsx("a",{href:t,target:"_blank",rel:"noreferrer",children:t})},t))}),r.events.length>0&&e.jsxs("details",{children:[e.jsx("summary",{children:s("research.runHistory","Run history")}),e.jsx("ul",{className:"research-view__events",children:r.events.map(t=>e.jsx("li",{children:t.message},t.id))})]})]}),!r&&g.length>0&&e.jsx("p",{children:s("research.selectRunToViewDetails","Select a run to view details.")}),e.jsxs("div",{className:"research-view__stats",children:[e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:s("research.statRunning","Running")}),e.jsx("div",{className:"research-view__stat-value",children:S.running})]}),e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:s("research.statCompleted","Completed")}),e.jsx("div",{className:"research-view__stat-value",children:S.completed})]}),e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:s("research.statFailed","Failed")}),e.jsx("div",{className:"research-view__stat-value",children:S.failed})]})]})]})]})]})}),r&&L&&(()=>{const t=r.results?.findings?.findIndex((f,m)=>(f.id?.trim()||`finding-${m+1}`)===L.findingId)??-1,u=t>=0?r.results.findings[t]:null;return u?e.jsx(Oe,{open:!0,mode:L.mode,run:r,finding:{id:L.findingId,heading:u.heading,content:u.content},projectId:n,onClose:()=>K(null),onConfirm:async({taskId:f,title:m,description:C,priority:le,attachExport:oe})=>{L.mode==="create"?await W("create-task",()=>U(r.id,m,L.findingId,C,le,oe),s("research.taskCreatedFromResearch","Task created from research")):f&&await W("attach-task",()=>V(r.id,f,L.findingId,oe),s("research.taskEnrichedFromResearch","Task enriched from research")),K(null)}}):null})()]})}export{Je as ResearchView};
@@ -1 +1 @@
1
- import{r as c,j as e}from"./vendor-react-SZ_qB27O.js";import{V as he,m as me,R as J,P as ye,E as Y,n as z,o as xe,p as ve,q as be,s as je,C as fe,e as Se,u as ge}from"./index-DF2cd-e3.js";import{u as Ne}from"./vendor-i18n-GF3RlKbq.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.js";const Ce="__sync_passphrase__",L={key:"",value:"",description:"",scope:"project",accessPolicy:"prompt",envExportable:!1,envExportKey:""},n={className:"secrets-action-icon","aria-hidden":!0,style:{width:"1em",height:"1em"}},Pe={...n,className:"secrets-action-icon spin"},Me=({addToast:i})=>{const{t:a}=Ne("app"),[R,G]=c.useState([]),[T,M]=c.useState(!0),[A,D]=c.useState(null),[K,b]=c.useState(null),[p,O]=c.useState(null),[U,x]=c.useState(!1),[Q,g]=c.useState(null),[t,l]=c.useState(L),[N,C]=c.useState(!1),[V,j]=c.useState({}),[W,F]=c.useState(null),[u,X]=c.useState(!1),[Z,_]=c.useState(!1),[f,B]=c.useState(""),[P,$]=c.useState(""),[ee,H]=c.useState(!1),[E,se]=c.useState(!1),h=c.useRef(new Map),w=c.useRef(new Map),o=c.useCallback(async(s,r)=>{const d=await fetch(s,{...r,headers:{"Content-Type":"application/json",...r?.headers??{}}});if(!d.ok){const m=await d.json().catch(()=>({error:"Request failed"}));throw new Error(String(m?.error??"Request failed"))}if(d.status!==204)return d.json()},[]),v=c.useCallback(async()=>{M(!0),D(null);try{const s=await o("/api/secrets");G(s.secrets)}catch(s){D(s instanceof Error?s.message:String(s))}finally{M(!1)}},[o]),S=c.useCallback(async()=>{try{const s=await o("/api/secrets/sync-passphrase");X(!!s.configured)}catch(s){i?.(a("secrets.errorLoadSyncStatus","Failed to load sync passphrase status: {{error}}",{error:s instanceof Error?s.message:String(s)}),"error")}},[i,o]);c.useEffect(()=>(v(),S(),()=>{h.current.forEach(s=>clearTimeout(s)),w.current.forEach(s=>clearTimeout(s))}),[v,S]);const k=()=>{_(!1),B(""),$("")},ae=async s=>{await o("/api/secrets/sync-passphrase",{method:"PUT",body:JSON.stringify({passphrase:s})})},re=async()=>{H(!0);try{await ae(f),i?.(u?a("secrets.syncPassphraseRotated","Sync passphrase rotated"):a("secrets.syncPassphraseSet","Sync passphrase set"),"success"),k(),await S()}catch(s){i?.(a("secrets.errorSaveSyncPassphrase","Failed to save sync passphrase: {{error}}",{error:s instanceof Error?s.message:String(s)}),"error")}finally{H(!1)}},te=async()=>{if(window.confirm(a("secrets.confirmClearSyncPassphrase","Clear the cross-node sync passphrase? Existing sync pairs will stop working until you set a new passphrase.")))try{await o("/api/secrets/sync-passphrase",{method:"DELETE"}),i?.(a("secrets.syncPassphraseCleared","Sync passphrase cleared"),"success"),await S()}catch(r){i?.(a("secrets.errorClearSyncPassphrase","Failed to clear sync passphrase: {{error}}",{error:r instanceof Error?r.message:String(r)}),"error")}},ce=()=>{O(null),l(L),x(!0),C(!1),b(null)},le=s=>{O(s),l({key:s.key,value:"",description:s.description??"",scope:s.scope,accessPolicy:s.accessPolicy,envExportable:s.envExportable,envExportKey:s.envExportKey??""}),x(!0),C(!1),b(null)},ne=async()=>{b(null);try{if(p){const s={key:t.key,description:t.description||null,accessPolicy:t.accessPolicy,envExportable:t.envExportable,envExportKey:t.envExportable&&t.envExportKey||null};t.value&&(s.value=t.value),await o(`/api/secrets/${p.scope}/${p.id}`,{method:"PATCH",body:JSON.stringify(s)})}else await o("/api/secrets",{method:"POST",body:JSON.stringify({scope:t.scope,key:t.key,value:t.value,description:t.description||null,accessPolicy:t.accessPolicy,envExportable:t.envExportable,envExportKey:t.envExportable&&t.envExportKey||null})});x(!1),l(L),await v()}catch(s){b(s instanceof Error?s.message:String(s))}},oe=s=>{const r=h.current.get(s.id);r&&(clearTimeout(r),h.current.delete(s.id)),j(d=>({...d,[s.id]:null}))},ie=async s=>{const r=await o(`/api/secrets/${s.scope}/${s.id}/reveal`,{method:"POST"});j(y=>({...y,[s.id]:r.value})),i?.(a("secrets.revealed","Revealed"),"success");const d=setTimeout(()=>{j(y=>({...y,[s.id]:null})),h.current.delete(s.id)},3e4),m=h.current.get(s.id);m&&clearTimeout(m),h.current.set(s.id,d)},de=async s=>{const r=V[s.id];if(!r)return;if(!await ge(r)){i?.(a("secrets.copyFailed","Failed to copy secret"),"error");return}F(s.id),i?.(a("secrets.copied","Copied"),"success");const m=setTimeout(()=>{F(null),j(ue=>({...ue,[s.id]:null}))},1500),y=w.current.get(s.id);y&&clearTimeout(y),w.current.set(s.id,m)},pe=async s=>{await o(`/api/secrets/${s.scope}/${s.id}`,{method:"DELETE"}),g(null),await v()},I=c.useMemo(()=>[...R].filter(s=>!(s.scope==="global"&&s.key===Ce)).sort((s,r)=>s.key.localeCompare(r.key)),[R]),q=f.length>0&&f===P;return e.jsxs("section",{className:"secrets-view",children:[e.jsx(he,{icon:me,title:a("secrets.title","Secrets"),actions:e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm",onClick:()=>void v(),children:[e.jsx(J,{...n})," ",a("secrets.refresh","Refresh")]}),e.jsxs("button",{className:"btn btn-primary btn-sm",onClick:ce,children:[e.jsx(ye,{...n})," ",a("secrets.addSecret","Add Secret")]})]})}),A?e.jsx("div",{className:"form-error",children:A}):null,T?e.jsxs("div",{className:"secrets-loading",children:[e.jsx(J,{...Pe})," ",a("secrets.loading","Loading…")]}):null,!T&&I.length===0?e.jsx("div",{className:"secrets-empty",children:a("secrets.empty","No secrets found.")}):null,e.jsx("div",{className:"secrets-list",children:I.map(s=>{const r=V[s.id];return e.jsxs("article",{className:"card secrets-row",children:[e.jsxs("div",{className:"secrets-row-main",children:[e.jsx("div",{className:"secrets-row-key",children:s.key}),e.jsxs("div",{className:"secrets-row-meta",children:[e.jsx("span",{className:"secrets-chip",children:s.scope}),e.jsx("span",{className:"secrets-chip",children:s.accessPolicy}),s.envExportable?e.jsx("span",{className:"secrets-chip",children:a("secrets.envExportableChip","env exportable")}):null]}),r?e.jsx("pre",{className:"secrets-revealed",children:r}):null]}),e.jsxs("div",{className:"secrets-row-side",children:[e.jsx("span",{className:"secrets-row-read",children:s.lastReadAt?new Date(s.lastReadAt).toLocaleString():a("secrets.neverRead","Never read")}),e.jsxs("div",{className:"secrets-row-actions",children:[e.jsx("button",{type:"button",className:"btn btn-icon secrets-visibility-toggle",onClick:()=>{if(r){oe(s);return}ie(s)},"aria-label":r?a("secrets.hideAriaLabel","Hide"):a("secrets.revealAriaLabel","Reveal"),children:r?e.jsx(Y,{...n}):e.jsx(z,{...n})}),e.jsx("button",{className:"btn btn-icon",onClick:()=>void de(s),"aria-label":a("secrets.copyAriaLabel","Copy"),disabled:!r,children:W===s.id?e.jsx(xe,{...n}):e.jsx(ve,{...n})}),e.jsx("button",{className:"btn btn-icon",onClick:()=>le(s),"aria-label":a("secrets.editAriaLabel","Edit"),children:e.jsx(be,{...n})}),e.jsx("button",{className:"btn btn-icon btn-danger",onClick:()=>g(s.id),"aria-label":a("secrets.deleteAriaLabel","Delete"),children:e.jsx(je,{...n})})]}),Q===s.id?e.jsxs("div",{className:"secrets-confirm",children:[e.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void pe(s),children:a("secrets.confirmDelete","Confirm")}),e.jsx("button",{className:"btn btn-sm",onClick:()=>g(null),children:a("secrets.cancelDelete","Cancel")})]}):null]})]},s.id)})}),e.jsxs("article",{className:"card secrets-sync-card secrets-sync-disclosure",children:[e.jsxs("button",{type:"button",className:"secrets-sync-disclosure-toggle","data-testid":"secrets-passphrase-disclosure","aria-expanded":E,"aria-controls":"secrets-sync-disclosure-panel",onClick:()=>se(s=>!s),children:[E?e.jsx(fe,{size:16,"aria-hidden":"true"}):e.jsx(Se,{size:16,"aria-hidden":"true"}),e.jsx("span",{children:a("secrets.syncPassphraseTitle","Cross-Node Sync Passphrase")})]}),E?e.jsxs("div",{id:"secrets-sync-disclosure-panel",className:"secrets-sync-disclosure-panel",children:[e.jsxs("div",{className:"secrets-sync-header",children:[e.jsxs("p",{className:"secrets-sync-status",children:[e.jsx("span",{className:`status-dot ${u?"status-dot--online":"status-dot--pending"}`,"aria-hidden":"true"})," ",u?a("secrets.syncConfigured","Configured"):a("secrets.syncNotConfigured","Not configured")]}),e.jsxs("div",{className:"secrets-sync-actions",children:[e.jsx("button",{className:"btn",onClick:()=>_(!0),children:u?a("secrets.rotateSyncPassphrase","Rotate"):a("secrets.setPassphrase","Set passphrase")}),u?e.jsx("button",{className:"btn btn-danger",onClick:()=>void te(),children:a("secrets.clearSyncPassphrase","Clear")}):null]})]}),e.jsx("p",{className:"secrets-sync-copy",children:a("secrets.syncPassphraseDescription","Shared passphrase used to wrap cross-node secret bundles. Both nodes in a sync pair must share the same value. Stored locally only; never transmitted.")})]}):null]}),Z?e.jsx("div",{className:"modal-overlay open",role:"presentation",children:e.jsxs("div",{className:"modal",role:"dialog","aria-modal":"true","aria-label":u?a("secrets.rotateSyncPassphraseModalTitle","Rotate sync passphrase"):a("secrets.setSyncPassphraseModalTitle","Set sync passphrase"),children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:u?a("secrets.rotateSyncPassphraseModalTitle","Rotate sync passphrase"):a("secrets.setSyncPassphraseModalTitle","Set sync passphrase")}),e.jsx("button",{className:"modal-close",onClick:k,"aria-label":a("secrets.closeAriaLabel","Close"),children:"×"})]}),e.jsxs("div",{className:"secrets-modal-body",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.passphraseLabel","Passphrase")}),e.jsx("input",{"aria-label":a("secrets.passphraseLabel","Passphrase"),className:"input",type:"password",autoComplete:"new-password",value:f,onChange:s=>B(s.target.value)})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.confirmPassphraseLabel","Confirm passphrase")}),e.jsx("input",{"aria-label":a("secrets.confirmPassphraseLabel","Confirm passphrase"),className:"input",type:"password",autoComplete:"new-password",value:P,onChange:s=>$(s.target.value)})]}),!q&&P.length>0?e.jsx("div",{className:"form-error",children:a("secrets.passphraseMustMatch","Passphrases must match.")}):null]}),e.jsx("div",{className:"modal-actions",children:e.jsxs("div",{className:"modal-actions-right",children:[e.jsx("button",{className:"btn",onClick:k,children:a("secrets.cancelBtn","Cancel")}),e.jsx("button",{className:"btn btn-primary",onClick:()=>void re(),disabled:!q||ee,children:u?a("secrets.rotateSyncPassphrase","Rotate"):a("secrets.setPassphrase","Set passphrase")})]})})]})}):null,U?e.jsx("div",{className:"modal-overlay open",role:"presentation",children:e.jsxs("div",{className:"modal",role:"dialog","aria-modal":"true","aria-label":p?a("secrets.editSecretModalTitle","Edit secret"):a("secrets.addSecretModalTitle","Add secret"),children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:p?a("secrets.editSecretModalTitle","Edit secret"):a("secrets.addSecretModalTitle","Add secret")}),e.jsx("button",{className:"modal-close",onClick:()=>x(!1),"aria-label":a("secrets.closeAriaLabel","Close"),children:"×"})]}),e.jsxs("div",{className:"secrets-modal-body",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.keyLabel","Key")}),e.jsx("input",{className:"input",value:t.key,onChange:s=>l(r=>({...r,key:s.target.value}))})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.valueLabel","Value")}),e.jsxs("div",{className:"secrets-value-row",children:[e.jsx("input",{className:"input",type:N?"text":"password",autoComplete:"off",spellCheck:!1,value:t.value,onChange:s=>l(r=>({...r,value:s.target.value}))}),e.jsx("button",{type:"button",className:"btn btn-icon secrets-visibility-toggle",onClick:()=>C(s=>!s),"aria-label":N?a("secrets.hideValueAriaLabel","Hide value"):a("secrets.showValueAriaLabel","Show value"),children:N?e.jsx(Y,{...n}):e.jsx(z,{...n})})]})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.descriptionLabel","Description")}),e.jsx("textarea",{className:"input",value:t.description,onChange:s=>l(r=>({...r,description:s.target.value}))})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.scopeLabel","Scope")}),e.jsxs("div",{className:"secrets-radio-row",children:[e.jsxs("label",{children:[e.jsx("input",{type:"radio",checked:t.scope==="project",onChange:()=>l(s=>({...s,scope:"project"})),disabled:!!p})," ",a("secrets.scopeProject","Project")]}),e.jsxs("label",{children:[e.jsx("input",{type:"radio",checked:t.scope==="global",onChange:()=>l(s=>({...s,scope:"global"})),disabled:!!p})," ",a("secrets.scopeGlobal","Global")]})]})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.accessPolicyLabel","Access policy")}),e.jsxs("select",{className:"select",value:t.accessPolicy,onChange:s=>l(r=>({...r,accessPolicy:s.target.value})),children:[e.jsx("option",{value:"auto",children:a("secrets.accessPolicyAuto","auto")}),e.jsx("option",{value:"prompt",children:a("secrets.accessPolicyPrompt","prompt")}),e.jsx("option",{value:"deny",children:a("secrets.accessPolicyDeny","deny")})]})]}),e.jsx("div",{className:"form-group",children:e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:t.envExportable,onChange:s=>l(r=>({...r,envExportable:s.target.checked}))})," ",a("secrets.exportToEnvLabel","Export to env")]})}),t.envExportable?e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.envKeyLabel","Env key")}),e.jsx("input",{className:"input",value:t.envExportKey,onChange:s=>l(r=>({...r,envExportKey:s.target.value}))})]}):null,K?e.jsx("div",{className:"form-error",children:K}):null]}),e.jsx("div",{className:"modal-actions",children:e.jsxs("div",{className:"modal-actions-right",children:[e.jsx("button",{className:"btn",onClick:()=>x(!1),children:a("secrets.cancelBtn","Cancel")}),e.jsx("button",{className:"btn btn-primary",onClick:()=>void ne(),children:p?a("secrets.saveBtn","Save"):a("secrets.createBtn","Create")})]})})]})}):null]})};export{Me as SecretsView};
1
+ import{r as c,j as e}from"./vendor-react-SZ_qB27O.js";import{V as he,m as me,R as J,P as ye,E as Y,n as z,o as xe,p as ve,q as be,s as je,C as fe,e as Se,u as ge}from"./index-D8sgsB8q.js";import{u as Ne}from"./vendor-i18n-GF3RlKbq.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.js";const Ce="__sync_passphrase__",L={key:"",value:"",description:"",scope:"project",accessPolicy:"prompt",envExportable:!1,envExportKey:""},n={className:"secrets-action-icon","aria-hidden":!0,style:{width:"1em",height:"1em"}},Pe={...n,className:"secrets-action-icon spin"},Me=({addToast:i})=>{const{t:a}=Ne("app"),[R,G]=c.useState([]),[T,M]=c.useState(!0),[A,D]=c.useState(null),[K,b]=c.useState(null),[p,O]=c.useState(null),[U,x]=c.useState(!1),[Q,g]=c.useState(null),[t,l]=c.useState(L),[N,C]=c.useState(!1),[V,j]=c.useState({}),[W,F]=c.useState(null),[u,X]=c.useState(!1),[Z,_]=c.useState(!1),[f,B]=c.useState(""),[P,$]=c.useState(""),[ee,H]=c.useState(!1),[E,se]=c.useState(!1),h=c.useRef(new Map),w=c.useRef(new Map),o=c.useCallback(async(s,r)=>{const d=await fetch(s,{...r,headers:{"Content-Type":"application/json",...r?.headers??{}}});if(!d.ok){const m=await d.json().catch(()=>({error:"Request failed"}));throw new Error(String(m?.error??"Request failed"))}if(d.status!==204)return d.json()},[]),v=c.useCallback(async()=>{M(!0),D(null);try{const s=await o("/api/secrets");G(s.secrets)}catch(s){D(s instanceof Error?s.message:String(s))}finally{M(!1)}},[o]),S=c.useCallback(async()=>{try{const s=await o("/api/secrets/sync-passphrase");X(!!s.configured)}catch(s){i?.(a("secrets.errorLoadSyncStatus","Failed to load sync passphrase status: {{error}}",{error:s instanceof Error?s.message:String(s)}),"error")}},[i,o]);c.useEffect(()=>(v(),S(),()=>{h.current.forEach(s=>clearTimeout(s)),w.current.forEach(s=>clearTimeout(s))}),[v,S]);const k=()=>{_(!1),B(""),$("")},ae=async s=>{await o("/api/secrets/sync-passphrase",{method:"PUT",body:JSON.stringify({passphrase:s})})},re=async()=>{H(!0);try{await ae(f),i?.(u?a("secrets.syncPassphraseRotated","Sync passphrase rotated"):a("secrets.syncPassphraseSet","Sync passphrase set"),"success"),k(),await S()}catch(s){i?.(a("secrets.errorSaveSyncPassphrase","Failed to save sync passphrase: {{error}}",{error:s instanceof Error?s.message:String(s)}),"error")}finally{H(!1)}},te=async()=>{if(window.confirm(a("secrets.confirmClearSyncPassphrase","Clear the cross-node sync passphrase? Existing sync pairs will stop working until you set a new passphrase.")))try{await o("/api/secrets/sync-passphrase",{method:"DELETE"}),i?.(a("secrets.syncPassphraseCleared","Sync passphrase cleared"),"success"),await S()}catch(r){i?.(a("secrets.errorClearSyncPassphrase","Failed to clear sync passphrase: {{error}}",{error:r instanceof Error?r.message:String(r)}),"error")}},ce=()=>{O(null),l(L),x(!0),C(!1),b(null)},le=s=>{O(s),l({key:s.key,value:"",description:s.description??"",scope:s.scope,accessPolicy:s.accessPolicy,envExportable:s.envExportable,envExportKey:s.envExportKey??""}),x(!0),C(!1),b(null)},ne=async()=>{b(null);try{if(p){const s={key:t.key,description:t.description||null,accessPolicy:t.accessPolicy,envExportable:t.envExportable,envExportKey:t.envExportable&&t.envExportKey||null};t.value&&(s.value=t.value),await o(`/api/secrets/${p.scope}/${p.id}`,{method:"PATCH",body:JSON.stringify(s)})}else await o("/api/secrets",{method:"POST",body:JSON.stringify({scope:t.scope,key:t.key,value:t.value,description:t.description||null,accessPolicy:t.accessPolicy,envExportable:t.envExportable,envExportKey:t.envExportable&&t.envExportKey||null})});x(!1),l(L),await v()}catch(s){b(s instanceof Error?s.message:String(s))}},oe=s=>{const r=h.current.get(s.id);r&&(clearTimeout(r),h.current.delete(s.id)),j(d=>({...d,[s.id]:null}))},ie=async s=>{const r=await o(`/api/secrets/${s.scope}/${s.id}/reveal`,{method:"POST"});j(y=>({...y,[s.id]:r.value})),i?.(a("secrets.revealed","Revealed"),"success");const d=setTimeout(()=>{j(y=>({...y,[s.id]:null})),h.current.delete(s.id)},3e4),m=h.current.get(s.id);m&&clearTimeout(m),h.current.set(s.id,d)},de=async s=>{const r=V[s.id];if(!r)return;if(!await ge(r)){i?.(a("secrets.copyFailed","Failed to copy secret"),"error");return}F(s.id),i?.(a("secrets.copied","Copied"),"success");const m=setTimeout(()=>{F(null),j(ue=>({...ue,[s.id]:null}))},1500),y=w.current.get(s.id);y&&clearTimeout(y),w.current.set(s.id,m)},pe=async s=>{await o(`/api/secrets/${s.scope}/${s.id}`,{method:"DELETE"}),g(null),await v()},I=c.useMemo(()=>[...R].filter(s=>!(s.scope==="global"&&s.key===Ce)).sort((s,r)=>s.key.localeCompare(r.key)),[R]),q=f.length>0&&f===P;return e.jsxs("section",{className:"secrets-view",children:[e.jsx(he,{icon:me,title:a("secrets.title","Secrets"),actions:e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm",onClick:()=>void v(),children:[e.jsx(J,{...n})," ",a("secrets.refresh","Refresh")]}),e.jsxs("button",{className:"btn btn-primary btn-sm",onClick:ce,children:[e.jsx(ye,{...n})," ",a("secrets.addSecret","Add Secret")]})]})}),A?e.jsx("div",{className:"form-error",children:A}):null,T?e.jsxs("div",{className:"secrets-loading",children:[e.jsx(J,{...Pe})," ",a("secrets.loading","Loading…")]}):null,!T&&I.length===0?e.jsx("div",{className:"secrets-empty",children:a("secrets.empty","No secrets found.")}):null,e.jsx("div",{className:"secrets-list",children:I.map(s=>{const r=V[s.id];return e.jsxs("article",{className:"card secrets-row",children:[e.jsxs("div",{className:"secrets-row-main",children:[e.jsx("div",{className:"secrets-row-key",children:s.key}),e.jsxs("div",{className:"secrets-row-meta",children:[e.jsx("span",{className:"secrets-chip",children:s.scope}),e.jsx("span",{className:"secrets-chip",children:s.accessPolicy}),s.envExportable?e.jsx("span",{className:"secrets-chip",children:a("secrets.envExportableChip","env exportable")}):null]}),r?e.jsx("pre",{className:"secrets-revealed",children:r}):null]}),e.jsxs("div",{className:"secrets-row-side",children:[e.jsx("span",{className:"secrets-row-read",children:s.lastReadAt?new Date(s.lastReadAt).toLocaleString():a("secrets.neverRead","Never read")}),e.jsxs("div",{className:"secrets-row-actions",children:[e.jsx("button",{type:"button",className:"btn btn-icon secrets-visibility-toggle",onClick:()=>{if(r){oe(s);return}ie(s)},"aria-label":r?a("secrets.hideAriaLabel","Hide"):a("secrets.revealAriaLabel","Reveal"),children:r?e.jsx(Y,{...n}):e.jsx(z,{...n})}),e.jsx("button",{className:"btn btn-icon",onClick:()=>void de(s),"aria-label":a("secrets.copyAriaLabel","Copy"),disabled:!r,children:W===s.id?e.jsx(xe,{...n}):e.jsx(ve,{...n})}),e.jsx("button",{className:"btn btn-icon",onClick:()=>le(s),"aria-label":a("secrets.editAriaLabel","Edit"),children:e.jsx(be,{...n})}),e.jsx("button",{className:"btn btn-icon btn-danger",onClick:()=>g(s.id),"aria-label":a("secrets.deleteAriaLabel","Delete"),children:e.jsx(je,{...n})})]}),Q===s.id?e.jsxs("div",{className:"secrets-confirm",children:[e.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void pe(s),children:a("secrets.confirmDelete","Confirm")}),e.jsx("button",{className:"btn btn-sm",onClick:()=>g(null),children:a("secrets.cancelDelete","Cancel")})]}):null]})]},s.id)})}),e.jsxs("article",{className:"card secrets-sync-card secrets-sync-disclosure",children:[e.jsxs("button",{type:"button",className:"secrets-sync-disclosure-toggle","data-testid":"secrets-passphrase-disclosure","aria-expanded":E,"aria-controls":"secrets-sync-disclosure-panel",onClick:()=>se(s=>!s),children:[E?e.jsx(fe,{size:16,"aria-hidden":"true"}):e.jsx(Se,{size:16,"aria-hidden":"true"}),e.jsx("span",{children:a("secrets.syncPassphraseTitle","Cross-Node Sync Passphrase")})]}),E?e.jsxs("div",{id:"secrets-sync-disclosure-panel",className:"secrets-sync-disclosure-panel",children:[e.jsxs("div",{className:"secrets-sync-header",children:[e.jsxs("p",{className:"secrets-sync-status",children:[e.jsx("span",{className:`status-dot ${u?"status-dot--online":"status-dot--pending"}`,"aria-hidden":"true"})," ",u?a("secrets.syncConfigured","Configured"):a("secrets.syncNotConfigured","Not configured")]}),e.jsxs("div",{className:"secrets-sync-actions",children:[e.jsx("button",{className:"btn",onClick:()=>_(!0),children:u?a("secrets.rotateSyncPassphrase","Rotate"):a("secrets.setPassphrase","Set passphrase")}),u?e.jsx("button",{className:"btn btn-danger",onClick:()=>void te(),children:a("secrets.clearSyncPassphrase","Clear")}):null]})]}),e.jsx("p",{className:"secrets-sync-copy",children:a("secrets.syncPassphraseDescription","Shared passphrase used to wrap cross-node secret bundles. Both nodes in a sync pair must share the same value. Stored locally only; never transmitted.")})]}):null]}),Z?e.jsx("div",{className:"modal-overlay open",role:"presentation",children:e.jsxs("div",{className:"modal",role:"dialog","aria-modal":"true","aria-label":u?a("secrets.rotateSyncPassphraseModalTitle","Rotate sync passphrase"):a("secrets.setSyncPassphraseModalTitle","Set sync passphrase"),children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:u?a("secrets.rotateSyncPassphraseModalTitle","Rotate sync passphrase"):a("secrets.setSyncPassphraseModalTitle","Set sync passphrase")}),e.jsx("button",{className:"modal-close",onClick:k,"aria-label":a("secrets.closeAriaLabel","Close"),children:"×"})]}),e.jsxs("div",{className:"secrets-modal-body",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.passphraseLabel","Passphrase")}),e.jsx("input",{"aria-label":a("secrets.passphraseLabel","Passphrase"),className:"input",type:"password",autoComplete:"new-password",value:f,onChange:s=>B(s.target.value)})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.confirmPassphraseLabel","Confirm passphrase")}),e.jsx("input",{"aria-label":a("secrets.confirmPassphraseLabel","Confirm passphrase"),className:"input",type:"password",autoComplete:"new-password",value:P,onChange:s=>$(s.target.value)})]}),!q&&P.length>0?e.jsx("div",{className:"form-error",children:a("secrets.passphraseMustMatch","Passphrases must match.")}):null]}),e.jsx("div",{className:"modal-actions",children:e.jsxs("div",{className:"modal-actions-right",children:[e.jsx("button",{className:"btn",onClick:k,children:a("secrets.cancelBtn","Cancel")}),e.jsx("button",{className:"btn btn-primary",onClick:()=>void re(),disabled:!q||ee,children:u?a("secrets.rotateSyncPassphrase","Rotate"):a("secrets.setPassphrase","Set passphrase")})]})})]})}):null,U?e.jsx("div",{className:"modal-overlay open",role:"presentation",children:e.jsxs("div",{className:"modal",role:"dialog","aria-modal":"true","aria-label":p?a("secrets.editSecretModalTitle","Edit secret"):a("secrets.addSecretModalTitle","Add secret"),children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:p?a("secrets.editSecretModalTitle","Edit secret"):a("secrets.addSecretModalTitle","Add secret")}),e.jsx("button",{className:"modal-close",onClick:()=>x(!1),"aria-label":a("secrets.closeAriaLabel","Close"),children:"×"})]}),e.jsxs("div",{className:"secrets-modal-body",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.keyLabel","Key")}),e.jsx("input",{className:"input",value:t.key,onChange:s=>l(r=>({...r,key:s.target.value}))})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.valueLabel","Value")}),e.jsxs("div",{className:"secrets-value-row",children:[e.jsx("input",{className:"input",type:N?"text":"password",autoComplete:"off",spellCheck:!1,value:t.value,onChange:s=>l(r=>({...r,value:s.target.value}))}),e.jsx("button",{type:"button",className:"btn btn-icon secrets-visibility-toggle",onClick:()=>C(s=>!s),"aria-label":N?a("secrets.hideValueAriaLabel","Hide value"):a("secrets.showValueAriaLabel","Show value"),children:N?e.jsx(Y,{...n}):e.jsx(z,{...n})})]})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.descriptionLabel","Description")}),e.jsx("textarea",{className:"input",value:t.description,onChange:s=>l(r=>({...r,description:s.target.value}))})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.scopeLabel","Scope")}),e.jsxs("div",{className:"secrets-radio-row",children:[e.jsxs("label",{children:[e.jsx("input",{type:"radio",checked:t.scope==="project",onChange:()=>l(s=>({...s,scope:"project"})),disabled:!!p})," ",a("secrets.scopeProject","Project")]}),e.jsxs("label",{children:[e.jsx("input",{type:"radio",checked:t.scope==="global",onChange:()=>l(s=>({...s,scope:"global"})),disabled:!!p})," ",a("secrets.scopeGlobal","Global")]})]})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.accessPolicyLabel","Access policy")}),e.jsxs("select",{className:"select",value:t.accessPolicy,onChange:s=>l(r=>({...r,accessPolicy:s.target.value})),children:[e.jsx("option",{value:"auto",children:a("secrets.accessPolicyAuto","auto")}),e.jsx("option",{value:"prompt",children:a("secrets.accessPolicyPrompt","prompt")}),e.jsx("option",{value:"deny",children:a("secrets.accessPolicyDeny","deny")})]})]}),e.jsx("div",{className:"form-group",children:e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:t.envExportable,onChange:s=>l(r=>({...r,envExportable:s.target.checked}))})," ",a("secrets.exportToEnvLabel","Export to env")]})}),t.envExportable?e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:a("secrets.envKeyLabel","Env key")}),e.jsx("input",{className:"input",value:t.envExportKey,onChange:s=>l(r=>({...r,envExportKey:s.target.value}))})]}):null,K?e.jsx("div",{className:"form-error",children:K}):null]}),e.jsx("div",{className:"modal-actions",children:e.jsxs("div",{className:"modal-actions-right",children:[e.jsx("button",{className:"btn",onClick:()=>x(!1),children:a("secrets.cancelBtn","Cancel")}),e.jsx("button",{className:"btn btn-primary",onClick:()=>void ne(),children:p?a("secrets.saveBtn","Save"):a("secrets.createBtn","Create")})]})})]})}):null]})};export{Me as SecretsView};
@@ -1,2 +1,2 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-xterm-BNq00GSj.js","assets/vendor-react-SZ_qB27O.js","assets/vendor-xterm-LZoznX6r.css","assets/addon-fit-C1WQXRvu.js","assets/addon-unicode11-BVmNDUBM.js","assets/addon-webgl-uLc0RKcC.js"])))=>i.map(i=>d[i]);
2
- import{D as ge,F as A,G as le,H as V,I as ce,J as B,K as xe,N as Ne,n as Re,O as Pe,Q as J,U as je,W as De,Y as Me,_ as I,$ as Le,a0 as Oe}from"./index-DF2cd-e3.js";import{r as i,j as t}from"./vendor-react-SZ_qB27O.js";import"./vendor-xterm-BNq00GSj.js";import{u as Ae}from"./vendor-i18n-GF3RlKbq.js";import{S as ze}from"./shield-alert-DcsqJWMG.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";const Fe=32*1024,Be=100,Ie="\x1B",Ke=" ",We="",$e="\x1B[A",Ue="\x1B[B",Qe="\x1B[C",Ve="\x1B[D",K={ctrl:"Ctrl",escape:"Esc",tab:"Tab",ctrlC:"^C"};function de(u){if(u.length!==1)return null;const o=u.toUpperCase().charCodeAt(0);return o>=64&&o<=95?String.fromCharCode(o&31):null}function Je(){const[u,f]=i.useState(()=>J());return i.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const o=window.matchMedia(je),a=window.visualViewport,y=()=>f(J());return y(),typeof a?.addEventListener=="function"&&a.addEventListener("resize",y),typeof o.addEventListener=="function"?(o.addEventListener("change",y),()=>{o.removeEventListener("change",y),typeof a?.removeEventListener=="function"&&a.removeEventListener("resize",y)}):(o.addListener(y),()=>{o.removeListener(y),typeof a?.removeEventListener=="function"&&a.removeEventListener("resize",y)})},[]),u}function Ye(u,f){if(typeof window>"u")return"";const a=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/cli-sessions/ws?sessionId=${encodeURIComponent(u)}&ticket=${encodeURIComponent(f)}`;return Oe(a)}function He(){return/Mac|iPhone|iPad|iPod/i.test(navigator.platform)}function Ge(u){if(typeof window<"u"&&typeof window.atob=="function"){const f=window.atob(u),o=new Uint8Array(f.length);for(let a=0;a<f.length;a++)o[a]=f.charCodeAt(a);return new TextDecoder("utf-8").decode(o)}return Buffer.from(u,"base64").toString("utf8")}function at({sessionId:u,readOnly:f=!1,posture:o,mode:a="live",projectId:y,onConfirmAdvance:E,showConfirmAdvance:W=!1,onOpenAdapterSettings:Y}){const{t:r}=Ae("app"),C=i.useRef(null),T=i.useRef(null),j=i.useRef(null),S=i.useRef(null),[H,G]=i.useState(!1),[ue,$]=i.useState(!1),[q,Z]=i.useState(!1),g=Je(),{keyboardOpen:z,keyboardOverlap:me}=ge({enabled:g}),fe=i.useRef(null),[_,X]=i.useState(""),[x,D]=i.useState(!1),[pe,ye]=i.useState(()=>A().customShortcuts),[ee,te]=i.useState(null),ne=f||ee===!0,M=!f&&ee===!1&&a==="live",b=i.useCallback(e=>{if(!e||!M)return;const n=S.current;n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({type:"input",data:e}))},[M]),N=i.useCallback(e=>{if(x){const n=de(e);if(D(!1),n){b(n);return}}b(e)},[x,b]),l=i.useCallback(e=>{e.preventDefault()},[]),be=i.useCallback(e=>{e?.preventDefault?.(),_&&b(_),b("\r"),X("")},[_,b]),he=i.useCallback(e=>{if(x&&e.length>_.length){const n=e.slice(_.length,_.length+1),d=de(n);if(D(!1),d){b(d);return}}X(e)},[x,_,b]);i.useEffect(()=>{W&&$(!1)},[W,u]);const L=i.useCallback((e,n)=>{const d=S.current;d?.readyState===WebSocket.OPEN&&d.send(JSON.stringify({type:"resize",cols:e,rows:n}))},[]),ie=i.useCallback(()=>{const e=T.current;if(!e)return;const n=A(),d=le(n.fontFamily);e.options.fontFamily=d,C.current?.style.setProperty("--terminal-glyph-font-family",V(n.fontFamily)),e.options.fontSize=n.fontSize,e.options.cursorStyle=n.cursorStyle,e.options.cursorBlink=n.cursorBlink&&M;try{j.current?.fit?.(),L(e.cols,e.rows)}catch{}ce(n.fontSize,d).then(R=>{if(!(!R||T.current!==e||e.options.fontSize!==n.fontSize||e.options.fontFamily!==d)){B(e,d),e.options.fontSize=n.fontSize;try{j.current?.fit?.(),L(e.cols,e.rows),B(e,d),e.refresh(0,Math.max(0,e.rows-1))}catch{}}},()=>{})},[M,L]);i.useEffect(()=>{if(typeof window>"u")return;const e=n=>{n.key===De&&(ie(),ye(A().customShortcuts))};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[ie]),i.useEffect(()=>{if(!u||typeof window>"u")return;let e=!1,n=null,d=null,R=0;te(null);const U=L,ke=p=>{if(R+=p,R<Fe)return;const h=S.current;h?.readyState===WebSocket.OPEN&&h.send(JSON.stringify({type:"ack",bytes:R})),R=0};return(async()=>{let p;try{p=await Me(`/cli-sessions/${encodeURIComponent(u)}/attach-ticket`,{method:"POST",body:JSON.stringify(y?{projectId:y}:{})})}catch{return}if(e)return;te(p.readOnly);const h=!f&&!p.readOnly&&a==="live",[{Terminal:ve},{FitAddon:Ee},{Unicode11Addon:Ce}]=await Promise.all([I(()=>import("./vendor-xterm-BNq00GSj.js").then(c=>c.x),__vite__mapDeps([0,1,2])),I(()=>import("./addon-fit-C1WQXRvu.js").then(c=>c.a),__vite__mapDeps([3,1])),I(()=>import("./addon-unicode11-BVmNDUBM.js").then(c=>c.a),__vite__mapDeps([4,1]))]);if(e||!C.current)return;const w=A(),O=le(w.fontFamily);C.current.style.setProperty("--terminal-glyph-font-family",V(w.fontFamily));const s=new ve({convertEol:!1,cursorBlink:w.cursorBlink&&h,cursorStyle:w.cursorStyle,disableStdin:!h,scrollback:1e4,fontFamily:O,fontSize:w.fontSize}),P=new Ee;s.loadAddon(P);const Te=new Ce;if(s.loadAddon(Te),s.unicode.activeVersion="11",Le(()=>{s.open(C.current)}),T.current=s,j.current=P,w.renderer==="auto"&&!J())try{const{WebglAddon:c}=await I(async()=>{const{WebglAddon:m}=await import("./addon-webgl-uLc0RKcC.js").then(k=>k.a);return{WebglAddon:m}},__vite__mapDeps([5,1]));if(!e){const m=new c;m.onContextLoss(()=>{try{m.dispose()}catch{}}),s.loadAddon(m)}}catch{}try{P.fit()}catch{}(async()=>{if(!(!await ce(w.fontSize,O)||e||T.current!==s||j.current!==P||s.options.fontSize!==w.fontSize||s.options.fontFamily!==O))try{B(s,O),s.options.fontSize=w.fontSize,P.fit(),U(s.cols,s.rows),B(s,O),s.refresh(0,Math.max(0,s.rows-1))}catch{}})(),h&&(s.onData(c=>{const m=S.current;m?.readyState===WebSocket.OPEN&&m.send(JSON.stringify({type:"input",data:c}))}),s.attachCustomKeyEventHandler(c=>{if(c.type!=="keydown"||!(He()?c.metaKey:c.ctrlKey)||c.altKey||c.shiftKey)return!0;const k=c.key.toLowerCase();if(k==="c"){const v=s.hasSelection()?s.getSelection():"";return v?(navigator.clipboard?.writeText(v).catch(()=>{}),!1):!0}if(k==="v"){const v=navigator.clipboard?.readText;return v&&v.call(navigator.clipboard).then(ae=>{if(!ae)return;const re=S.current;re?.readyState===WebSocket.OPEN&&re.send(JSON.stringify({type:"input",data:ae}))}).catch(()=>{}),!1}return!0})),n=new ResizeObserver(()=>{d&&clearTimeout(d),d=setTimeout(()=>{try{P.fit(),U(s.cols,s.rows)}catch{}},Be)}),n.observe(C.current);const Q=new WebSocket(Ye(u,p.ticket));S.current=Q,Q.onopen=()=>{U(s.cols,s.rows)},Q.onmessage=c=>{let m;try{m=JSON.parse(typeof c.data=="string"?c.data:"")}catch{return}switch(m.type){case"scrollback":case"data":{if(typeof m.data!="string")return;const k=Ge(m.data),v=k.length;s.write(k,()=>ke(v));break}}}})(),()=>{e=!0,d&&clearTimeout(d),n&&n.disconnect();const p=S.current;if(p){p.onopen=null,p.onmessage=null,p.onclose=null,p.onerror=null;try{p.close()}catch{}S.current=null}const h=T.current;if(h){try{h.dispose()}catch{}T.current=null}j.current=null}},[u,f,a,y,L]);const se=i.useMemo(()=>a==="idle"?r("cliTerminal.replayIdle","Session idle"):a==="ended"?r("cliTerminal.replayEnded","Session ended"):null,[a,r]),we=i.useCallback(async()=>{if(E){Z(!0);try{await E("advance"),$(!0)}finally{Z(!1)}}},[E]),Se=i.useCallback(async()=>{E&&await E("not-yet"),$(!0)},[E]),F=!!o?.elevated,oe=o?.elevatedFlags?.join(", "),_e={"--terminal-glyph-font-family":V(A().fontFamily)};return t.jsxs("div",{className:`cli-session-terminal${g?" cli-session-terminal--mobile":""}${g&&z?" cli-session-terminal--keyboard-open":""}`,"data-mode":a,"data-read-only":ne,"data-mobile":g,"data-keyboard-open":g&&z,children:[t.jsxs("header",{className:"cli-session-terminal__header",children:[o&&t.jsxs("div",{className:"cli-session-terminal__posture-wrap",children:[t.jsxs("button",{type:"button",className:`cli-posture-chip${F?" cli-posture-chip--elevated":""}`,"data-elevated":F,"aria-expanded":H,onClick:()=>G(e=>!e),children:[F?t.jsx(ze,{size:13,"aria-hidden":"true"}):t.jsx(xe,{size:13,"aria-hidden":"true"}),t.jsx("span",{className:"cli-posture-chip__name",children:o.adapterName}),o.mode&&t.jsx("span",{className:"cli-posture-chip__mode",children:o.mode}),F&&oe&&t.jsx("span",{className:"cli-posture-chip__flag",children:oe})]}),H&&t.jsxs("div",{className:"cli-posture-tooltip",role:"tooltip",children:[t.jsx("p",{className:"cli-posture-tooltip__title",children:r("cliTerminal.postureResolved","Resolved posture")}),t.jsxs("ul",{className:"cli-posture-tooltip__list",children:[(o.resolved??[]).map((e,n)=>t.jsx("li",{children:e},n)),(o.resolved??[]).length===0&&t.jsx("li",{children:o.mode??r("cliTerminal.postureBaseline","Baseline")})]}),Y&&t.jsxs("button",{type:"button",className:"cli-posture-tooltip__settings",onClick:()=>{G(!1),Y()},children:[t.jsx(Ne,{size:12,"aria-hidden":"true"}),r("cliTerminal.adapterSettings","Adapter settings")]})]})]}),ne&&t.jsxs("span",{className:"cli-session-terminal__readonly-badge",children:[t.jsx(Re,{size:12,"aria-hidden":"true"}),r("cliTerminal.readOnly","Read-only")]}),se&&t.jsx("span",{className:"cli-session-terminal__replay-badge","data-replay-mode":a,children:se})]}),t.jsx("div",{className:"cli-session-terminal__viewport",ref:C,"data-testid":"cli-terminal-viewport",style:_e}),W&&!ue&&t.jsxs("div",{className:"cli-session-terminal__advance-strip",role:"region",children:[t.jsx("span",{className:"cli-session-terminal__advance-copy",children:r("cliTerminal.advancePrompt","This session looks idle — advance to review?")}),t.jsxs("div",{className:"cli-session-terminal__advance-actions",children:[t.jsx("button",{type:"button",className:"cli-session-terminal__advance-btn",disabled:q,onClick:we,children:r("cliTerminal.advance","Advance")}),t.jsx("button",{type:"button",className:"cli-session-terminal__advance-btn cli-session-terminal__advance-btn--secondary",disabled:q,onClick:Se,children:r("cliTerminal.notYet","Not yet")})]})]}),g&&M&&t.jsxs("div",{className:`cli-session-terminal__mobile-bar${z?" cli-session-terminal__mobile-bar--keyboard-open":""}`,"data-testid":"cli-terminal-mobile-bar",style:z?{bottom:`${me}px`}:void 0,children:[t.jsxs("div",{className:"cli-session-terminal__key-row","data-testid":"cli-terminal-key-bar",children:[t.jsx("button",{type:"button",className:`cli-terminal-key cli-terminal-key--ctrl${x?" cli-terminal-key--active":""}`,"data-testid":"cli-key-ctrl","aria-label":r("cliTerminal.mobileKeyCtrl","Sticky Ctrl modifier"),"aria-pressed":x,onPointerDown:l,onMouseDown:l,onClick:()=>D(e=>!e),children:K.ctrl}),t.jsx("button",{type:"button",className:"cli-terminal-key","data-testid":"cli-key-esc","aria-label":r("cliTerminal.mobileKeyEsc","Send Escape"),onPointerDown:l,onMouseDown:l,onClick:()=>N(Ie),children:K.escape}),t.jsx("button",{type:"button",className:"cli-terminal-key","data-testid":"cli-key-tab","aria-label":r("cliTerminal.mobileKeyTab","Send Tab"),onPointerDown:l,onMouseDown:l,onClick:()=>N(Ke),children:K.tab}),t.jsx("button",{type:"button",className:"cli-terminal-key cli-terminal-key--ctrlc","data-testid":"cli-key-ctrl-c","aria-label":r("cliTerminal.mobileKeyCtrlC","Send Ctrl-C"),onPointerDown:l,onMouseDown:l,onClick:()=>{D(!1),b(We)},children:K.ctrlC}),t.jsx("button",{type:"button",className:"cli-terminal-key","data-testid":"cli-key-arrow-up","aria-label":r("cliTerminal.mobileKeyArrowUp","Cursor up"),onPointerDown:l,onMouseDown:l,onClick:()=>N($e),children:"↑"}),t.jsx("button",{type:"button",className:"cli-terminal-key","data-testid":"cli-key-arrow-down","aria-label":r("cliTerminal.mobileKeyArrowDown","Cursor down"),onPointerDown:l,onMouseDown:l,onClick:()=>N(Ue),children:"↓"}),t.jsx("button",{type:"button",className:"cli-terminal-key","data-testid":"cli-key-arrow-left","aria-label":r("cliTerminal.mobileKeyArrowLeft","Cursor left"),onPointerDown:l,onMouseDown:l,onClick:()=>N(Ve),children:"←"}),t.jsx("button",{type:"button",className:"cli-terminal-key","data-testid":"cli-key-arrow-right","aria-label":r("cliTerminal.mobileKeyArrowRight","Cursor right"),onPointerDown:l,onMouseDown:l,onClick:()=>N(Qe),children:"→"}),pe.map(e=>t.jsx("button",{type:"button",className:"cli-terminal-key cli-terminal-key--custom","data-testid":`cli-terminal-custom-shortcut-${e.id}`,title:e.label,"aria-label":e.label,onPointerDown:l,onMouseDown:l,onClick:()=>{D(!1),b(Pe(e.value))},children:e.label},e.id))]}),t.jsxs("form",{className:"cli-session-terminal__input-row",onSubmit:be,children:[t.jsx("input",{ref:fe,type:"text",className:"cli-session-terminal__mobile-input","data-testid":"cli-terminal-mobile-input",value:_,placeholder:r("cliTerminal.mobileInputPlaceholder","Type to send to the session…"),autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",spellCheck:!1,onChange:e=>he(e.target.value)}),t.jsx("button",{type:"submit",className:"cli-session-terminal__mobile-send","data-testid":"cli-terminal-mobile-send","aria-label":r("cliTerminal.mobileSend","Send"),onPointerDown:l,onMouseDown:l,children:r("cliTerminal.mobileSend","Send")})]})]})]})}export{at as SessionTerminal};
2
+ import{D as ge,F as A,G as le,H as V,I as ce,J as B,K as xe,N as Ne,n as Re,O as Pe,Q as J,U as je,W as De,Y as Me,_ as I,$ as Le,a0 as Oe}from"./index-D8sgsB8q.js";import{r as i,j as t}from"./vendor-react-SZ_qB27O.js";import"./vendor-xterm-BNq00GSj.js";import{u as Ae}from"./vendor-i18n-GF3RlKbq.js";import{S as ze}from"./shield-alert-c_--H0ce.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";const Fe=32*1024,Be=100,Ie="\x1B",Ke=" ",We="",$e="\x1B[A",Ue="\x1B[B",Qe="\x1B[C",Ve="\x1B[D",K={ctrl:"Ctrl",escape:"Esc",tab:"Tab",ctrlC:"^C"};function de(u){if(u.length!==1)return null;const o=u.toUpperCase().charCodeAt(0);return o>=64&&o<=95?String.fromCharCode(o&31):null}function Je(){const[u,f]=i.useState(()=>J());return i.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const o=window.matchMedia(je),a=window.visualViewport,y=()=>f(J());return y(),typeof a?.addEventListener=="function"&&a.addEventListener("resize",y),typeof o.addEventListener=="function"?(o.addEventListener("change",y),()=>{o.removeEventListener("change",y),typeof a?.removeEventListener=="function"&&a.removeEventListener("resize",y)}):(o.addListener(y),()=>{o.removeListener(y),typeof a?.removeEventListener=="function"&&a.removeEventListener("resize",y)})},[]),u}function Ye(u,f){if(typeof window>"u")return"";const a=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/cli-sessions/ws?sessionId=${encodeURIComponent(u)}&ticket=${encodeURIComponent(f)}`;return Oe(a)}function He(){return/Mac|iPhone|iPad|iPod/i.test(navigator.platform)}function Ge(u){if(typeof window<"u"&&typeof window.atob=="function"){const f=window.atob(u),o=new Uint8Array(f.length);for(let a=0;a<f.length;a++)o[a]=f.charCodeAt(a);return new TextDecoder("utf-8").decode(o)}return Buffer.from(u,"base64").toString("utf8")}function at({sessionId:u,readOnly:f=!1,posture:o,mode:a="live",projectId:y,onConfirmAdvance:E,showConfirmAdvance:W=!1,onOpenAdapterSettings:Y}){const{t:r}=Ae("app"),C=i.useRef(null),T=i.useRef(null),j=i.useRef(null),S=i.useRef(null),[H,G]=i.useState(!1),[ue,$]=i.useState(!1),[q,Z]=i.useState(!1),g=Je(),{keyboardOpen:z,keyboardOverlap:me}=ge({enabled:g}),fe=i.useRef(null),[_,X]=i.useState(""),[x,D]=i.useState(!1),[pe,ye]=i.useState(()=>A().customShortcuts),[ee,te]=i.useState(null),ne=f||ee===!0,M=!f&&ee===!1&&a==="live",b=i.useCallback(e=>{if(!e||!M)return;const n=S.current;n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({type:"input",data:e}))},[M]),N=i.useCallback(e=>{if(x){const n=de(e);if(D(!1),n){b(n);return}}b(e)},[x,b]),l=i.useCallback(e=>{e.preventDefault()},[]),be=i.useCallback(e=>{e?.preventDefault?.(),_&&b(_),b("\r"),X("")},[_,b]),he=i.useCallback(e=>{if(x&&e.length>_.length){const n=e.slice(_.length,_.length+1),d=de(n);if(D(!1),d){b(d);return}}X(e)},[x,_,b]);i.useEffect(()=>{W&&$(!1)},[W,u]);const L=i.useCallback((e,n)=>{const d=S.current;d?.readyState===WebSocket.OPEN&&d.send(JSON.stringify({type:"resize",cols:e,rows:n}))},[]),ie=i.useCallback(()=>{const e=T.current;if(!e)return;const n=A(),d=le(n.fontFamily);e.options.fontFamily=d,C.current?.style.setProperty("--terminal-glyph-font-family",V(n.fontFamily)),e.options.fontSize=n.fontSize,e.options.cursorStyle=n.cursorStyle,e.options.cursorBlink=n.cursorBlink&&M;try{j.current?.fit?.(),L(e.cols,e.rows)}catch{}ce(n.fontSize,d).then(R=>{if(!(!R||T.current!==e||e.options.fontSize!==n.fontSize||e.options.fontFamily!==d)){B(e,d),e.options.fontSize=n.fontSize;try{j.current?.fit?.(),L(e.cols,e.rows),B(e,d),e.refresh(0,Math.max(0,e.rows-1))}catch{}}},()=>{})},[M,L]);i.useEffect(()=>{if(typeof window>"u")return;const e=n=>{n.key===De&&(ie(),ye(A().customShortcuts))};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[ie]),i.useEffect(()=>{if(!u||typeof window>"u")return;let e=!1,n=null,d=null,R=0;te(null);const U=L,ke=p=>{if(R+=p,R<Fe)return;const h=S.current;h?.readyState===WebSocket.OPEN&&h.send(JSON.stringify({type:"ack",bytes:R})),R=0};return(async()=>{let p;try{p=await Me(`/cli-sessions/${encodeURIComponent(u)}/attach-ticket`,{method:"POST",body:JSON.stringify(y?{projectId:y}:{})})}catch{return}if(e)return;te(p.readOnly);const h=!f&&!p.readOnly&&a==="live",[{Terminal:ve},{FitAddon:Ee},{Unicode11Addon:Ce}]=await Promise.all([I(()=>import("./vendor-xterm-BNq00GSj.js").then(c=>c.x),__vite__mapDeps([0,1,2])),I(()=>import("./addon-fit-C1WQXRvu.js").then(c=>c.a),__vite__mapDeps([3,1])),I(()=>import("./addon-unicode11-BVmNDUBM.js").then(c=>c.a),__vite__mapDeps([4,1]))]);if(e||!C.current)return;const w=A(),O=le(w.fontFamily);C.current.style.setProperty("--terminal-glyph-font-family",V(w.fontFamily));const s=new ve({convertEol:!1,cursorBlink:w.cursorBlink&&h,cursorStyle:w.cursorStyle,disableStdin:!h,scrollback:1e4,fontFamily:O,fontSize:w.fontSize}),P=new Ee;s.loadAddon(P);const Te=new Ce;if(s.loadAddon(Te),s.unicode.activeVersion="11",Le(()=>{s.open(C.current)}),T.current=s,j.current=P,w.renderer==="auto"&&!J())try{const{WebglAddon:c}=await I(async()=>{const{WebglAddon:m}=await import("./addon-webgl-uLc0RKcC.js").then(k=>k.a);return{WebglAddon:m}},__vite__mapDeps([5,1]));if(!e){const m=new c;m.onContextLoss(()=>{try{m.dispose()}catch{}}),s.loadAddon(m)}}catch{}try{P.fit()}catch{}(async()=>{if(!(!await ce(w.fontSize,O)||e||T.current!==s||j.current!==P||s.options.fontSize!==w.fontSize||s.options.fontFamily!==O))try{B(s,O),s.options.fontSize=w.fontSize,P.fit(),U(s.cols,s.rows),B(s,O),s.refresh(0,Math.max(0,s.rows-1))}catch{}})(),h&&(s.onData(c=>{const m=S.current;m?.readyState===WebSocket.OPEN&&m.send(JSON.stringify({type:"input",data:c}))}),s.attachCustomKeyEventHandler(c=>{if(c.type!=="keydown"||!(He()?c.metaKey:c.ctrlKey)||c.altKey||c.shiftKey)return!0;const k=c.key.toLowerCase();if(k==="c"){const v=s.hasSelection()?s.getSelection():"";return v?(navigator.clipboard?.writeText(v).catch(()=>{}),!1):!0}if(k==="v"){const v=navigator.clipboard?.readText;return v&&v.call(navigator.clipboard).then(ae=>{if(!ae)return;const re=S.current;re?.readyState===WebSocket.OPEN&&re.send(JSON.stringify({type:"input",data:ae}))}).catch(()=>{}),!1}return!0})),n=new ResizeObserver(()=>{d&&clearTimeout(d),d=setTimeout(()=>{try{P.fit(),U(s.cols,s.rows)}catch{}},Be)}),n.observe(C.current);const Q=new WebSocket(Ye(u,p.ticket));S.current=Q,Q.onopen=()=>{U(s.cols,s.rows)},Q.onmessage=c=>{let m;try{m=JSON.parse(typeof c.data=="string"?c.data:"")}catch{return}switch(m.type){case"scrollback":case"data":{if(typeof m.data!="string")return;const k=Ge(m.data),v=k.length;s.write(k,()=>ke(v));break}}}})(),()=>{e=!0,d&&clearTimeout(d),n&&n.disconnect();const p=S.current;if(p){p.onopen=null,p.onmessage=null,p.onclose=null,p.onerror=null;try{p.close()}catch{}S.current=null}const h=T.current;if(h){try{h.dispose()}catch{}T.current=null}j.current=null}},[u,f,a,y,L]);const se=i.useMemo(()=>a==="idle"?r("cliTerminal.replayIdle","Session idle"):a==="ended"?r("cliTerminal.replayEnded","Session ended"):null,[a,r]),we=i.useCallback(async()=>{if(E){Z(!0);try{await E("advance"),$(!0)}finally{Z(!1)}}},[E]),Se=i.useCallback(async()=>{E&&await E("not-yet"),$(!0)},[E]),F=!!o?.elevated,oe=o?.elevatedFlags?.join(", "),_e={"--terminal-glyph-font-family":V(A().fontFamily)};return t.jsxs("div",{className:`cli-session-terminal${g?" cli-session-terminal--mobile":""}${g&&z?" cli-session-terminal--keyboard-open":""}`,"data-mode":a,"data-read-only":ne,"data-mobile":g,"data-keyboard-open":g&&z,children:[t.jsxs("header",{className:"cli-session-terminal__header",children:[o&&t.jsxs("div",{className:"cli-session-terminal__posture-wrap",children:[t.jsxs("button",{type:"button",className:`cli-posture-chip${F?" cli-posture-chip--elevated":""}`,"data-elevated":F,"aria-expanded":H,onClick:()=>G(e=>!e),children:[F?t.jsx(ze,{size:13,"aria-hidden":"true"}):t.jsx(xe,{size:13,"aria-hidden":"true"}),t.jsx("span",{className:"cli-posture-chip__name",children:o.adapterName}),o.mode&&t.jsx("span",{className:"cli-posture-chip__mode",children:o.mode}),F&&oe&&t.jsx("span",{className:"cli-posture-chip__flag",children:oe})]}),H&&t.jsxs("div",{className:"cli-posture-tooltip",role:"tooltip",children:[t.jsx("p",{className:"cli-posture-tooltip__title",children:r("cliTerminal.postureResolved","Resolved posture")}),t.jsxs("ul",{className:"cli-posture-tooltip__list",children:[(o.resolved??[]).map((e,n)=>t.jsx("li",{children:e},n)),(o.resolved??[]).length===0&&t.jsx("li",{children:o.mode??r("cliTerminal.postureBaseline","Baseline")})]}),Y&&t.jsxs("button",{type:"button",className:"cli-posture-tooltip__settings",onClick:()=>{G(!1),Y()},children:[t.jsx(Ne,{size:12,"aria-hidden":"true"}),r("cliTerminal.adapterSettings","Adapter settings")]})]})]}),ne&&t.jsxs("span",{className:"cli-session-terminal__readonly-badge",children:[t.jsx(Re,{size:12,"aria-hidden":"true"}),r("cliTerminal.readOnly","Read-only")]}),se&&t.jsx("span",{className:"cli-session-terminal__replay-badge","data-replay-mode":a,children:se})]}),t.jsx("div",{className:"cli-session-terminal__viewport",ref:C,"data-testid":"cli-terminal-viewport",style:_e}),W&&!ue&&t.jsxs("div",{className:"cli-session-terminal__advance-strip",role:"region",children:[t.jsx("span",{className:"cli-session-terminal__advance-copy",children:r("cliTerminal.advancePrompt","This session looks idle — advance to review?")}),t.jsxs("div",{className:"cli-session-terminal__advance-actions",children:[t.jsx("button",{type:"button",className:"cli-session-terminal__advance-btn",disabled:q,onClick:we,children:r("cliTerminal.advance","Advance")}),t.jsx("button",{type:"button",className:"cli-session-terminal__advance-btn cli-session-terminal__advance-btn--secondary",disabled:q,onClick:Se,children:r("cliTerminal.notYet","Not yet")})]})]}),g&&M&&t.jsxs("div",{className:`cli-session-terminal__mobile-bar${z?" cli-session-terminal__mobile-bar--keyboard-open":""}`,"data-testid":"cli-terminal-mobile-bar",style:z?{bottom:`${me}px`}:void 0,children:[t.jsxs("div",{className:"cli-session-terminal__key-row","data-testid":"cli-terminal-key-bar",children:[t.jsx("button",{type:"button",className:`cli-terminal-key cli-terminal-key--ctrl${x?" cli-terminal-key--active":""}`,"data-testid":"cli-key-ctrl","aria-label":r("cliTerminal.mobileKeyCtrl","Sticky Ctrl modifier"),"aria-pressed":x,onPointerDown:l,onMouseDown:l,onClick:()=>D(e=>!e),children:K.ctrl}),t.jsx("button",{type:"button",className:"cli-terminal-key","data-testid":"cli-key-esc","aria-label":r("cliTerminal.mobileKeyEsc","Send Escape"),onPointerDown:l,onMouseDown:l,onClick:()=>N(Ie),children:K.escape}),t.jsx("button",{type:"button",className:"cli-terminal-key","data-testid":"cli-key-tab","aria-label":r("cliTerminal.mobileKeyTab","Send Tab"),onPointerDown:l,onMouseDown:l,onClick:()=>N(Ke),children:K.tab}),t.jsx("button",{type:"button",className:"cli-terminal-key cli-terminal-key--ctrlc","data-testid":"cli-key-ctrl-c","aria-label":r("cliTerminal.mobileKeyCtrlC","Send Ctrl-C"),onPointerDown:l,onMouseDown:l,onClick:()=>{D(!1),b(We)},children:K.ctrlC}),t.jsx("button",{type:"button",className:"cli-terminal-key","data-testid":"cli-key-arrow-up","aria-label":r("cliTerminal.mobileKeyArrowUp","Cursor up"),onPointerDown:l,onMouseDown:l,onClick:()=>N($e),children:"↑"}),t.jsx("button",{type:"button",className:"cli-terminal-key","data-testid":"cli-key-arrow-down","aria-label":r("cliTerminal.mobileKeyArrowDown","Cursor down"),onPointerDown:l,onMouseDown:l,onClick:()=>N(Ue),children:"↓"}),t.jsx("button",{type:"button",className:"cli-terminal-key","data-testid":"cli-key-arrow-left","aria-label":r("cliTerminal.mobileKeyArrowLeft","Cursor left"),onPointerDown:l,onMouseDown:l,onClick:()=>N(Ve),children:"←"}),t.jsx("button",{type:"button",className:"cli-terminal-key","data-testid":"cli-key-arrow-right","aria-label":r("cliTerminal.mobileKeyArrowRight","Cursor right"),onPointerDown:l,onMouseDown:l,onClick:()=>N(Qe),children:"→"}),pe.map(e=>t.jsx("button",{type:"button",className:"cli-terminal-key cli-terminal-key--custom","data-testid":`cli-terminal-custom-shortcut-${e.id}`,title:e.label,"aria-label":e.label,onPointerDown:l,onMouseDown:l,onClick:()=>{D(!1),b(Pe(e.value))},children:e.label},e.id))]}),t.jsxs("form",{className:"cli-session-terminal__input-row",onSubmit:be,children:[t.jsx("input",{ref:fe,type:"text",className:"cli-session-terminal__mobile-input","data-testid":"cli-terminal-mobile-input",value:_,placeholder:r("cliTerminal.mobileInputPlaceholder","Type to send to the session…"),autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",spellCheck:!1,onChange:e=>he(e.target.value)}),t.jsx("button",{type:"submit",className:"cli-session-terminal__mobile-send","data-testid":"cli-terminal-mobile-send","aria-label":r("cliTerminal.mobileSend","Send"),onPointerDown:l,onMouseDown:l,children:r("cliTerminal.mobileSend","Send")})]})]})]})}export{at as SessionTerminal};