@runfusion/fusion 0.58.0 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/dist/bin.js +16894 -14563
- package/dist/client/.vite/manifest.json +247 -244
- package/dist/client/assets/AgentDetailView-UmilJU0C.js +18 -0
- package/dist/client/assets/{AgentPermissionPolicyEditor-3x5cc2cp.js → AgentPermissionPolicyEditor-DqYOX1kN.js} +1 -1
- package/dist/client/assets/{AgentsView-B77vHi_7.js → AgentsView-Dt0nKyx7.js} +4 -4
- package/dist/client/assets/ChatView-C7trV16u.js +6 -0
- package/dist/client/assets/CommandCenter-DSrIaOro.css +1 -0
- package/dist/client/assets/CommandCenter-Dsg16_mK.js +99 -0
- package/dist/client/assets/{DevServerView-BXmkO05R.js → DevServerView-DnpnAU_g.js} +1 -1
- package/dist/client/assets/{DirectoryPicker-CZ3EXSE5.js → DirectoryPicker-BzpWdpTC.js} +1 -1
- package/dist/client/assets/{DocumentsView-BSWFgTsC.css → DocumentsView-BSC7wh2B.css} +1 -1
- package/dist/client/assets/{DocumentsView-GlAyW64J.js → DocumentsView-C2jRDIo6.js} +2 -2
- package/dist/client/assets/{EvalsView-BLmcsNNf.js → EvalsView-M1nIXx-S.js} +1 -1
- package/dist/client/assets/ExperimentalAgentOnboardingModal-5Kg2iQtB.js +1 -0
- package/dist/client/assets/{GoalsView-BRfZ4qGe.js → GoalsView-7bFpy-lr.js} +1 -1
- package/dist/client/assets/InsightsView-D0HPy3RP.js +11 -0
- package/dist/client/assets/{MemoryView-ChkuBpUf.js → MemoryView-CNzJcoPi.js} +2 -2
- package/dist/client/assets/{PiExtensionsManager-DXwQdB7b.js → PiExtensionsManager-D0a8Q47c.js} +1 -1
- package/dist/client/assets/{PluginManager-B8zAjhqf.js → PluginManager-N2Ne57i_.js} +1 -1
- package/dist/client/assets/{PullRequestView-DL1E1ixh.js → PullRequestView-Be4GM2H5.js} +2 -2
- package/dist/client/assets/{ResearchView-BCYCHiyQ.js → ResearchView-DYW9ViMl.js} +1 -1
- package/dist/client/assets/SecretsView-B3jEFeGp.js +1 -0
- package/dist/client/assets/{SessionTerminal-BvK8A98c.css → SessionTerminal-CDTiqrd7.css} +1 -1
- package/dist/client/assets/SessionTerminal-DGFADOH4.js +2 -0
- package/dist/client/assets/SettingsModal-CtOCCZEj.js +21 -0
- package/dist/client/assets/{SettingsModal-U7ma-5OU.js → SettingsModal-Lw0RmeRd.js} +1 -1
- package/dist/client/assets/{SetupWizardModal-BCDoA33s.js → SetupWizardModal-BifMmJIa.js} +2 -2
- package/dist/client/assets/{ShadcnColorPicker-EVU2cXpo.js → ShadcnColorPicker-B1UClHqm.js} +2 -2
- package/dist/client/assets/{SkillsView-V48VsthB.js → SkillsView--U-5lH1V.js} +1 -1
- package/dist/client/assets/TodoView-BwxNdIXm.js +6 -0
- package/dist/client/assets/TodoView-CUD4xw3T.css +1 -0
- package/dist/client/assets/WorkflowNodeEditor-BmTZR0i8.js +8 -0
- package/dist/client/assets/{agentSkills-B-QDeW2q.js → agentSkills-PqEK0Uf_.js} +1 -1
- package/dist/client/assets/{app-SucmTDhV.js → app-BlgX3hw4.js} +3 -3
- package/dist/client/assets/{app-RIK4I745.js → app-C7eDKtXM.js} +3 -3
- package/dist/client/assets/{app-SHNioZxk.js → app-CL1Ik1qS.js} +3 -3
- package/dist/client/assets/{app-De_pkbYi.js → app-Ckb9wA3K.js} +3 -3
- package/dist/client/assets/{app-cZgmPvs6.js → app-Den3D7oy.js} +3 -3
- package/dist/client/assets/{app--U62_ZWS.js → app-nAsTBQMW.js} +3 -3
- package/dist/client/assets/{architectureDiagram-3BPJPVTR-DvR35aCH.js → architectureDiagram-3BPJPVTR-DxAKryer.js} +1 -1
- package/dist/client/assets/{blockDiagram-GPEHLZMM-ciQdpSqc.js → blockDiagram-GPEHLZMM-BfPC7WG4.js} +1 -1
- package/dist/client/assets/{c4Diagram-AAUBKEIU-CV0Z6UEL.js → c4Diagram-AAUBKEIU-DnVJBAB1.js} +1 -1
- package/dist/client/assets/channel-D23u9xEh.js +1 -0
- package/dist/client/assets/{chunk-2J33WTMH-CkAQRX3g.js → chunk-2J33WTMH-2LaGYtnx.js} +1 -1
- package/dist/client/assets/{chunk-4BX2VUAB-CJXvYVcN.js → chunk-4BX2VUAB-C7xxOb1T.js} +1 -1
- package/dist/client/assets/{chunk-55IACEB6-DOv0lN1u.js → chunk-55IACEB6-CAxHAFXx.js} +1 -1
- package/dist/client/assets/{chunk-727SXJPM-tRsHXz7i.js → chunk-727SXJPM-CnZuaU-I.js} +1 -1
- package/dist/client/assets/{chunk-AQP2D5EJ-CfzOMXn9.js → chunk-AQP2D5EJ-DutKSMk1.js} +1 -1
- package/dist/client/assets/{chunk-FMBD7UC4-BKvUZ2cn.js → chunk-FMBD7UC4-C7PQ58jc.js} +1 -1
- package/dist/client/assets/{chunk-ND2GUHAM-FqiVnW7u.js → chunk-ND2GUHAM-BQ0UHfJw.js} +1 -1
- package/dist/client/assets/{chunk-QZHKN3VN-BAJDyCpZ.js → chunk-QZHKN3VN-BadmXu1v.js} +1 -1
- package/dist/client/assets/classDiagram-4FO5ZUOK-BMIDIijD.js +1 -0
- package/dist/client/assets/classDiagram-v2-Q7XG4LA2-BMIDIijD.js +1 -0
- package/dist/client/assets/{cose-bilkent-S5V4N54A-DYizdcNp.js → cose-bilkent-S5V4N54A-37z9Hx7d.js} +1 -1
- package/dist/client/assets/{dagre-BM42HDAG-BDWwvXJx.js → dagre-BM42HDAG-B70rt1ZW.js} +1 -1
- package/dist/client/assets/{dashboard-view-BYn_jRw9.js → dashboard-view-DdAL0vfN.js} +1 -1
- package/dist/client/assets/{dashboard-view-DmfIFCV-.js → dashboard-view-GT7dDNd7.js} +1 -1
- package/dist/client/assets/{diagram-2AECGRRQ-C8ic2E9q.js → diagram-2AECGRRQ-se4pabEk.js} +1 -1
- package/dist/client/assets/{diagram-5GNKFQAL-H5IDcv9E.js → diagram-5GNKFQAL-ijyxpVgX.js} +1 -1
- package/dist/client/assets/{diagram-KO2AKTUF-DkczJXd6.js → diagram-KO2AKTUF-DUGQ8jXI.js} +1 -1
- package/dist/client/assets/{diagram-LMA3HP47-P1vh7RIU.js → diagram-LMA3HP47-BYydC37K.js} +1 -1
- package/dist/client/assets/{diagram-OG6HWLK6-CgeybA5t.js → diagram-OG6HWLK6-DlUn5jkD.js} +1 -1
- package/dist/client/assets/{erDiagram-TEJ5UH35-DSJa4zRQ.js → erDiagram-TEJ5UH35-ChYKGDIc.js} +1 -1
- package/dist/client/assets/{flowDiagram-I6XJVG4X-DG91ZWS9.js → flowDiagram-I6XJVG4X-CoQKr6ba.js} +1 -1
- package/dist/client/assets/{folder-open-iGyAYoN-.js → folder-open-YuIEuDwd.js} +1 -1
- package/dist/client/assets/{ganttDiagram-6RSMTGT7-dkOQjOK8.js → ganttDiagram-6RSMTGT7-Cff6URun.js} +1 -1
- package/dist/client/assets/{gitGraphDiagram-PVQCEYII-GqrJtmDT.js → gitGraphDiagram-PVQCEYII-CnlZVE6T.js} +1 -1
- package/dist/client/assets/index-C2HFa2A-.css +1 -0
- package/dist/client/assets/index-aBQwNV_I.js +2540 -0
- package/dist/client/assets/{infoDiagram-5YYISTIA-BfFhhqbU.js → infoDiagram-5YYISTIA-DYLBAKrj.js} +1 -1
- package/dist/client/assets/{ishikawaDiagram-YF4QCWOH-DBBV-PIS.js → ishikawaDiagram-YF4QCWOH-7xSxQNhn.js} +1 -1
- package/dist/client/assets/{journeyDiagram-JHISSGLW-xZisXOgZ.js → journeyDiagram-JHISSGLW-DREqJGeQ.js} +1 -1
- package/dist/client/assets/{kanban-definition-UN3LZRKU-CbOJloOw.js → kanban-definition-UN3LZRKU-_lzeYhpL.js} +1 -1
- package/dist/client/assets/{mermaid.core-DKBiVV3q.js → mermaid.core-DNTJMy0V.js} +4 -4
- package/dist/client/assets/{mindmap-definition-RKZ34NQL-Bf9V63ac.js → mindmap-definition-RKZ34NQL-DR9UulDp.js} +1 -1
- package/dist/client/assets/{pieDiagram-4H26LBE5-0ukMaTVl.js → pieDiagram-4H26LBE5-DD1LCdSp.js} +1 -1
- package/dist/client/assets/{puzzle-BvEf9PLH.js → puzzle-DaVSYDOd.js} +1 -1
- package/dist/client/assets/{quadrantDiagram-W4KKPZXB-CwXZAtYI.js → quadrantDiagram-W4KKPZXB-iLEGylFT.js} +1 -1
- package/dist/client/assets/{requirementDiagram-4Y6WPE33-DVsu9t-w.js → requirementDiagram-4Y6WPE33-D7IX9UbY.js} +1 -1
- package/dist/client/assets/{sankeyDiagram-5OEKKPKP-DOJUnv7J.js → sankeyDiagram-5OEKKPKP-DC30taEV.js} +1 -1
- package/dist/client/assets/{sequenceDiagram-3UESZ5HK-B67g0g9m.js → sequenceDiagram-3UESZ5HK-DjMKbjmL.js} +1 -1
- package/dist/client/assets/{shield-alert-4FPCIFZ2.js → shield-alert-BcyPZs5t.js} +1 -1
- package/dist/client/assets/{stateDiagram-AJRCARHV-CPPa0bHh.js → stateDiagram-AJRCARHV-DJSnSkUL.js} +1 -1
- package/dist/client/assets/{stateDiagram-v2-BHNVJYJU-Dyj14elw.js → stateDiagram-v2-BHNVJYJU-KC2rSU3J.js} +1 -1
- package/dist/client/assets/{timeline-definition-PNZ67QCA-UVWf2E8M.js → timeline-definition-PNZ67QCA-5DyrH8WZ.js} +1 -1
- package/dist/client/assets/{upload-BkgVjwwc.js → upload-C_8IHSzk.js} +1 -1
- package/dist/client/assets/{users-9nCT4liw.js → users-DfGiwmqG.js} +1 -1
- package/dist/client/assets/{vennDiagram-CIIHVFJN-CqGrv1wQ.js → vennDiagram-CIIHVFJN-Bh5X-uVf.js} +1 -1
- package/dist/client/assets/{wardley-L42UT6IY-aA0pos_F.js → wardley-L42UT6IY-ZIwV-wIZ.js} +1 -1
- package/dist/client/assets/{wardleyDiagram-YWT4CUSO-C-O5tD1L.js → wardleyDiagram-YWT4CUSO-DI92L1jA.js} +1 -1
- package/dist/client/assets/{xychartDiagram-2RQKCTM6-qoIF674C.js → xychartDiagram-2RQKCTM6-B6RjJCM8.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/client/version.json +1 -1
- package/dist/droid-cli/package.json +1 -1
- package/dist/extension.js +12961 -11668
- package/dist/pi-claude-cli/package.json +1 -1
- package/dist/plugin-sdk/index.d.ts +20 -1
- package/dist/plugins/fusion-plugin-acp-runtime/bundled.js +4 -1
- package/dist/plugins/fusion-plugin-acp-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-cli-printing-press/package.json +1 -1
- package/dist/plugins/fusion-plugin-compound-engineering/package.json +1 -1
- package/dist/plugins/fusion-plugin-cursor-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-dependency-graph/package.json +1 -1
- package/dist/plugins/fusion-plugin-droid-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-grok-runtime/bundled.js +4 -1
- package/dist/plugins/fusion-plugin-grok-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-hermes-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-linear-import/package.json +1 -1
- package/dist/plugins/fusion-plugin-openclaw-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-paperclip-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-reports/package.json +1 -1
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/ShareBlocksPanel.tsx +4 -1
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/__tests__/ShareBlocksPanel.test.tsx +41 -2
- package/dist/plugins/fusion-plugin-roadmap/package.json +1 -1
- package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +1 -1
- package/package.json +1 -1
- package/skill/fusion/SKILL.md +1 -1
- package/skill/fusion/references/engine-tools.md +1 -0
- package/skill/fusion/references/extension-tools.md +10 -0
- package/skill/fusion/references/fusion-capabilities.md +1 -0
- package/dist/client/assets/AgentDetailView-whCXABbu.js +0 -18
- package/dist/client/assets/ChatView-CninsTIm.js +0 -6
- package/dist/client/assets/CommandCenter-B9q-zM9p.css +0 -1
- package/dist/client/assets/CommandCenter-C6LmdUin.js +0 -71
- package/dist/client/assets/ExperimentalAgentOnboardingModal-DvDix9pH.js +0 -1
- package/dist/client/assets/InsightsView-X4RlcgrU.js +0 -11
- package/dist/client/assets/SecretsView-B48BIZKw.js +0 -1
- package/dist/client/assets/SessionTerminal-CUyYlq16.js +0 -2
- package/dist/client/assets/SettingsModal-DbjBoUYD.js +0 -21
- package/dist/client/assets/TodoView-DmpJmxu7.css +0 -1
- package/dist/client/assets/TodoView-MZ9Pfl65.js +0 -6
- package/dist/client/assets/WorkflowNodeEditor-B95Dvf-O.js +0 -8
- package/dist/client/assets/channel-Y_Uhrtqx.js +0 -1
- package/dist/client/assets/classDiagram-4FO5ZUOK-DhicwSPE.js +0 -1
- package/dist/client/assets/classDiagram-v2-Q7XG4LA2-DhicwSPE.js +0 -1
- package/dist/client/assets/index-Bg8SMXUs.css +0 -1
- package/dist/client/assets/index-DO9Ch72Y.js +0 -2544
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{r,j as e}from"./vendor-react-SZ_qB27O.js";import{u as
|
|
1
|
+
import{r,j as e}from"./vendor-react-SZ_qB27O.js";import{u as Ie}from"./SettingsModal-Lw0RmeRd.js";import{aK as fe,aL as Se,aM as Re,aN as qe,aO as Te,aP as Pe,aQ as je,aR as ve,aS as He,aT as _e,aU as Oe,aV as Ue,aJ as Qe,V as $e,aW as We,L as D,aX as Ne}from"./index-aBQwNV_I.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 O=".fusion/memory/MEMORY.md",Ve=5e4,Ye="0 3 * * *",Ge="0 4 * * *";function de(i){return{memoryEnabled:i.memoryEnabled!==!1,memoryAutoSummarizeEnabled:i.memoryAutoSummarizeEnabled??!1,memoryAutoSummarizeThresholdChars:i.memoryAutoSummarizeThresholdChars??Ve,memoryAutoSummarizeSchedule:i.memoryAutoSummarizeSchedule??Ye,memoryDreamsEnabled:i.memoryDreamsEnabled??!1,memoryDreamsSchedule:i.memoryDreamsSchedule??Ge}}function Ce(i,t){return i.some(h=>h.path===t)?t:i.find(h=>h.path===O)?.path??i[0]?.path??O}function Ke(i={}){const{projectId:t}=i,[h,s]=r.useState(null),[d,v]=r.useState(!0),[I,z]=r.useState(!1),[L,S]=r.useState(()=>de({})),[x,j]=r.useState(!0),[n,k]=r.useState(!1),[U,Q]=r.useState([]),[Z,R]=r.useState(!0),[y,M]=r.useState(O),[N,w]=r.useState(""),[ye,$]=r.useState(!1),[l,u]=r.useState(!1),[J,W]=r.useState(!1),[g,B]=r.useState(!1),[ee,q]=r.useState(!1),[c,P]=r.useState(null),[he,V]=r.useState(!0),[se,Y]=r.useState(!1),[te,G]=r.useState(!1),{status:K,loading:ue,refresh:A}=Ie({projectId:t}),X=r.useCallback(m=>{w(m),u(!0)},[]),H=r.useCallback(async m=>{$(!0);try{const{content:o}=await fe(m,t);M(m),w(o),u(!1)}finally{$(!1)}},[t]),C=r.useCallback(async()=>{R(!0);try{const{files:m}=await Se(t);if(Q(m),m.length===0){M(O),w(""),u(!1);return}const o=Ce(m,y);o!==y&&await H(o)}finally{R(!1)}},[t,y,H]);r.useEffect(()=>{let m=!1;async function o(){try{const p=await ve(t);m||(s(p.content),z(p.exists),v(!1))}catch{m||(s(null),z(!1),v(!1))}}return o(),()=>{m=!0}},[t]),r.useEffect(()=>{let m=!1;async function o(){j(!0);try{const p=await Qe(t);m||S(de(p))}catch{m||S(de({}))}finally{m||j(!1)}}return o(),()=>{m=!0}},[t]);const ae=r.useRef(y);r.useEffect(()=>{ae.current=y},[y]),r.useEffect(()=>{let m=!1;async function o(){R(!0);try{const{files:p}=await Se(t);if(m)return;if(Q(p),p.length===0){M(O),w(""),u(!1);return}const oe=Ce(p,ae.current),{content:xe}=await fe(oe,t);if(m)return;M(oe),w(xe),u(!1)}catch{m||(Q([]),M(O),w(""),u(!1))}finally{m||R(!1)}}return o(),()=>{m=!0}},[t]),r.useEffect(()=>{let m=!1;async function o(){try{const p=await je(t);m||(P(p),V(!1))}catch{m||(P(null),V(!1))}}return o(),()=>{m=!0}},[t]);const re=r.useCallback(async m=>{k(!0);try{const o=await Re(m,t);S(de(o))}finally{k(!1)}},[t]),me=r.useCallback(async m=>{await H(m)},[H]),ne=r.useCallback(async()=>{if(l){W(!0);try{await qe(y,N,t),u(!1),await C()}finally{W(!1)}}},[N,l,y,t,C]),ie=r.useCallback(async()=>{G(!0);try{const m=await Te(t);return await A(),m}finally{G(!1)}},[t,A]),le=r.useCallback(async m=>Pe(m,t),[t]),_=r.useCallback(async()=>{try{const m=await je(t);P(m)}catch{P(null)}},[t]),F=r.useCallback(async()=>{try{const m=await ve(t);s(m.content),z(m.exists)}catch{s(null),z(!1)}},[t]),f=r.useCallback(async m=>{await He(m,t),await F()},[t,F]),ge=r.useCallback(async()=>{B(!0);try{const m=await _e(t);return await Promise.all([F(),_()]),{success:m.success,summary:m.summary}}finally{B(!1)}},[t,F,_]),T=r.useCallback(async()=>{q(!0);try{return await Oe(t)}finally{q(!1)}},[t]),be=r.useCallback(async m=>{Y(!0);try{const o=await Ue(m,t),p=o.path??m;M(p),w(o.content),u(!1),await C()}finally{Y(!1)}},[t,C]);return{insightsContent:h,insightsLoading:d,insightsExists:I,refreshInsights:F,saveInsights:f,memorySettings:L,settingsLoading:x,savingMemorySettings:n,saveMemorySettings:re,memoryFiles:U,memoryFilesLoading:Z,selectedFilePath:y,selectedFileContent:N,selectedFileLoading:ye,selectedFileDirty:l,setSelectedFileContent:X,selectFile:me,saveSelectedFile:ne,savingSelectedFile:J,reloadMemoryFiles:C,backendStatus:K,backendLoading:ue,extractInsights:ge,extracting:g,triggerDreamNow:T,dreamRunning:ee,auditReport:c,auditLoading:he,refreshAudit:_,compactMemory:be,compacting:se,installQmdAction:ie,installingQmd:te,testRetrieval:le}}const Xe={Patterns:"pattern",Principles:"principle",Conventions:"convention",Pitfalls:"pitfall",Context:"context"},Ze=72;function Je(i,t){if(i.length<=t)return i;const h=Math.max(1,t-1),s=Math.ceil(h/2),d=Math.floor(h/2);return`${i.slice(0,s)}…${i.slice(i.length-d)}`}function es(i){const t=`${i.label} — ${i.path}`;return Je(t,Ze)}function ss(i){if(!i)return[];const t=[],h=i.split(/(?=^## )/m);for(const s of h){const d=s.trim();if(!d)continue;const v=d.match(/^##\s+(.+?)(\n|$)/);if(v){const I=v[1].trim(),z=Xe[I]??I.toLowerCase(),L=d.slice(v[0].length).replace(/<!--[\s\S]*?-->/g,"").trim(),S=L.split(`
|
|
2
2
|
`).reduce((x,j)=>{const n=j.trim();return/^[-*]\s+/.test(j)?x.push(n.replace(/^[-*]\s+/,"")):n.length>0&&x.length>0&&(x[x.length-1]=`${x[x.length-1]}
|
|
3
|
-
${j.trimEnd()}`),x},[]);(S.length>0||I.length>0)&&t.push({name:L,key:z,items:S.length>0?S:I.length>0?[I]:[],expanded:!0})}}return t}function ts(i){if(!i)return null;const t=i.match(/##\s+Last\s+Updated:\s*(\d{4}-\d{2}-\d{2})/i);return t?t[1]:null}function as(i){return i.reduce((t,h)=>t+h.items.length,0)}function ds({projectId:i,addToast:t,onSendSelectionToTask:h}){const{t:s}=We("app"),[d,v]=r.useState("working"),[L,z]=r.useState(new Set),[I,S]=r.useState(!1),[x,j]=r.useState(null),[n,k]=r.useState({memoryEnabled:!0,memoryAutoSummarizeEnabled:!1,memoryAutoSummarizeThresholdChars:5e4,memoryAutoSummarizeSchedule:"0 3 * * *",memoryDreamsEnabled:!1,memoryDreamsSchedule:"0 4 * * *"}),[U,Q]=r.useState(""),[J,R]=r.useState(!1),[y,M]=r.useState(null),{insightsContent:N,insightsLoading:w,insightsExists:ye,saveInsights:$,memorySettings:l,settingsLoading:u,saveMemorySettings:X,savingMemorySettings:B,backendStatus:g,backendLoading:W,extractInsights:ee,extracting:q,auditReport:c,auditLoading:P,refreshAudit:he,compactMemory:V,compacting:se,installQmdAction:Y,installingQmd:te,testRetrieval:G,memoryFiles:K,memoryFilesLoading:ue,selectedFilePath:A,selectedFileContent:Z,selectedFileLoading:H,selectedFileDirty:C,setSelectedFileContent:ae,selectFile:re,saveSelectedFile:me,savingSelectedFile:ne,reloadMemoryFiles:ie,triggerDreamNow:le,dreamRunning:_}=Ke({projectId:i});r.useEffect(()=>{k(l)},[l]);const F=r.useMemo(()=>n.memoryEnabled!==l.memoryEnabled||n.memoryAutoSummarizeEnabled!==l.memoryAutoSummarizeEnabled||n.memoryAutoSummarizeThresholdChars!==l.memoryAutoSummarizeThresholdChars||n.memoryAutoSummarizeSchedule!==l.memoryAutoSummarizeSchedule||n.memoryDreamsEnabled!==l.memoryDreamsEnabled||n.memoryDreamsSchedule!==l.memoryDreamsSchedule,[n,l]),f=r.useMemo(()=>K.find(a=>a.path===A),[K,A]),ge=f?f.layer==="long-term"?s("memory.layerDescLongTerm","Curated durable decisions, conventions, constraints, and pitfalls promoted from dreams."):f.layer==="daily"?s("memory.layerDescDaily","Raw daily observations, open loops, and running context for dream processing."):s("memory.layerDescDreams","Synthesized patterns and open loops promoted from daily memory."):s("memory.editorDefaultDescription","Edits the selected memory file."),T=r.useMemo(()=>ss(N),[N]),be=r.useMemo(()=>as(T),[T]),m=r.useMemo(()=>ts(N),[N]),o=r.useCallback(a=>{z(b=>{const E=new Set(b);return E.has(a)?E.delete(a):E.add(a),E})},[]),p=r.useCallback(async a=>{try{await re(a)}catch{t(s("memory.loadFileFailed","Failed to load memory file"),"error")}},[re,t]),oe=r.useCallback(async()=>{try{await me(),t(s("memory.memorySaved","Memory saved"),"success")}catch{t(s("memory.saveMemoryFailed","Failed to save memory"),"error")}},[me,t]),xe=r.useCallback(async()=>{if(!F)return;const a={};n.memoryEnabled!==l.memoryEnabled&&(a.memoryEnabled=n.memoryEnabled),n.memoryAutoSummarizeEnabled!==l.memoryAutoSummarizeEnabled&&(a.memoryAutoSummarizeEnabled=n.memoryAutoSummarizeEnabled),n.memoryAutoSummarizeThresholdChars!==l.memoryAutoSummarizeThresholdChars&&(a.memoryAutoSummarizeThresholdChars=n.memoryAutoSummarizeThresholdChars),n.memoryAutoSummarizeSchedule!==l.memoryAutoSummarizeSchedule&&(a.memoryAutoSummarizeSchedule=n.memoryAutoSummarizeSchedule),n.memoryDreamsEnabled!==l.memoryDreamsEnabled&&(a.memoryDreamsEnabled=n.memoryDreamsEnabled),n.memoryDreamsSchedule!==l.memoryDreamsSchedule&&(a.memoryDreamsSchedule=n.memoryDreamsSchedule);try{await X(a),t(s("memory.settingsSaved","Memory settings saved"),"success")}catch{t(s("memory.saveSettingsFailed","Failed to save memory settings"),"error")}},[F,n,l,X,t]),Ee=r.useCallback(async()=>{try{const a=await Y();t(a.qmdAvailable?s("memory.qmdInstallSuccess","qmd installed successfully"):s("memory.qmdInstallUnavailable","qmd install finished, but qmd is still unavailable"),a.qmdAvailable?"success":"info")}catch{t(s("memory.installQmdFailed","Failed to install qmd"),"error")}},[Y,t]),ke=r.useCallback(async()=>{R(!0),M(null);try{const a=await G(U);M(a),t(a.qmdAvailable?s("memory.retrievalTestComplete","Memory retrieval test complete"):s("memory.retrievalTestFallback","qmd is not installed; local fallback was used"),a.qmdAvailable?"success":"info")}catch{t(s("memory.retrievalTestFailed","Failed to test memory retrieval"),"error")}finally{R(!1)}},[U,G,t]),Me=r.useCallback(async()=>{try{await le(),t(s("memory.dreamProcessingComplete","Dream processing completed"),"success"),await ie()}catch(a){t(a instanceof Error?a.message:s("memory.dreamProcessingFailed","Failed to run dream processing"),"error")}},[le,ie,t]),we=r.useCallback(async()=>{try{await V(A),t(s("memory.fileCompacted","Memory file compacted"),"success")}catch{t(s("memory.compactFailed","Failed to compact memory"),"error")}},[V,A,t]),pe=r.useCallback(async()=>{try{const a=await ee();t(a.summary,"success")}catch(a){t(a instanceof Error?a.message:s("memory.extractInsightsFailed","Failed to extract insights"),"error")}},[ee,t]),Ae=r.useCallback(async()=>{if(x!==null)try{await $(x),S(!1),j(null),t(s("memory.insightsSaved","Insights saved"),"success")}catch{t(s("memory.saveInsightsFailed","Failed to save insights"),"error")}},[x,$,t]),Fe=r.useCallback(()=>{j(N??""),S(!0)},[N]),De=r.useCallback(()=>{S(!1),j(null)},[]),ze=!W&&g!==null,ce=g?.capabilities?.writable??!1;return e.jsxs("div",{className:"memory-view",children:[e.jsx($e,{icon:Be,title:s("memory.title","Memory")}),e.jsxs("div",{className:"memory-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":d==="working",className:`memory-view-tab${d==="working"?" memory-view-tab--active":""}`,onClick:()=>v("working"),"data-testid":"memory-tab-working",children:s("memory.tabWorking","Working Memory")}),e.jsx("button",{type:"button",role:"tab","aria-selected":d==="insights",className:`memory-view-tab${d==="insights"?" memory-view-tab--active":""}`,onClick:()=>v("insights"),"data-testid":"memory-tab-insights",children:s("memory.tabInsights","Insights")}),e.jsx("button",{type:"button",role:"tab","aria-selected":d==="engines",className:`memory-view-tab${d==="engines"?" memory-view-tab--active":""}`,onClick:()=>v("engines"),"data-testid":"memory-tab-engines",children:s("memory.tabEngines","Engines")})]}),e.jsxs("div",{className:"memory-view-content",children:[d==="working"&&e.jsxs("div",{className:"memory-working-tab",children:[ze&&!ce&&e.jsx("div",{className:"memory-readonly-banner",children:s("memory.readOnlyBanner","This memory backend is read-only. Changes cannot be saved.")}),ue||H?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(D,{size:20,className:"animate-spin"}),e.jsx("span",{children:s("memory.loadingFile","Loading memory file…")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-editor-section",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryViewFilePath",children:s("memory.fileLabel","Memory File")}),e.jsx("select",{id:"memoryViewFilePath",className:"select",value:A,onChange:a=>{p(a.target.value)},disabled:C,children:K.map(a=>e.jsx("option",{value:a.path,title:`${a.label} — ${a.path}`,children:es(a)},a.path))}),e.jsx("small",{children:C?s("memory.fileSwitchDirtyHint","Save or discard the current edits before switching files."):s("memory.fileSwitchHint","Choose any project memory file to view or edit.")})]}),f&&e.jsxs("div",{className:"memory-file-summary",children:[e.jsx("span",{children:f.layer==="long-term"?s("memory.layerLongTerm","Long-term"):f.layer==="daily"?s("memory.layerDaily","Daily"):s("memory.layerDreams","Dreams")}),e.jsx("strong",{children:f.path}),e.jsx("small",{children:s("memory.fileSummary","{{size}} bytes · updated {{updatedAt}}",{size:f.size.toLocaleString(),updatedAt:new Date(f.updatedAt).toLocaleString()})})]}),e.jsxs("div",{className:"form-group memory-editor-form-group",children:[e.jsx("label",{children:f?.label||s("memory.editorLabel","Memory Editor")}),e.jsx("small",{children:ge}),e.jsx("div",{className:"memory-editor-container",children:e.jsx(Ne,{content:Z,onChange:ae,readOnly:!ce,filePath:A,forceToolbarActionsVisible:!0,onSendSelectionToTask:h})})]})]}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsx("span",{className:"memory-char-count",children:s("memory.charCount","{{count}} characters",{count:Z.length})}),e.jsx("div",{className:"memory-flex-spacer"}),ce&&Z.length>0&&e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:we,disabled:se||C,children:se?e.jsxs(e.Fragment,{children:[e.jsx(D,{size:14,className:"animate-spin"}),s("memory.compacting","Compacting…")]}):s("memory.compactSelectedFile","Compact Selected File")}),C&&ce&&e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:oe,disabled:ne,children:ne?e.jsxs(e.Fragment,{children:[e.jsx(D,{size:14,className:"animate-spin"}),s("memory.saving","Saving…")]}):s("memory.save","Save")})]}),e.jsxs("div",{className:"memory-config-section",children:[e.jsxs("div",{className:"memory-settings-group",children:[e.jsxs("div",{className:"form-group memory-toggle-row",children:[e.jsxs("label",{htmlFor:"memoryDreamsEnabled",className:"checkbox-label",title:s("memory.dreamsEnabledTooltip","Daily notes are distilled into DREAMS.md and reusable lessons are promoted into MEMORY.md."),children:[e.jsx("input",{id:"memoryDreamsEnabled",type:"checkbox",checked:n.memoryDreamsEnabled,onChange:a=>{k(b=>({...b,memoryDreamsEnabled:a.target.checked}))},disabled:!n.memoryEnabled||u}),s("memory.dreamsEnabledLabel","Process dreams from daily memory")]}),e.jsx("small",{children:s("memory.dreamsEnabledHint","Turns daily notes into DREAMS.md and promotes reusable lessons into MEMORY.md.")})]}),n.memoryEnabled&&n.memoryDreamsEnabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryDreamsSchedule",children:s("memory.dreamsScheduleLabel","Dream Schedule")}),e.jsx("input",{id:"memoryDreamsSchedule",type:"text",className:"input",value:n.memoryDreamsSchedule,onChange:a=>{k(b=>({...b,memoryDreamsSchedule:a.target.value}))},placeholder:"0 4 * * *",disabled:u}),e.jsx("small",{children:s("memory.dreamsScheduleHint","Cron expression for dream processing.")})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:Me,disabled:_||!n.memoryDreamsEnabled,children:_?e.jsxs(e.Fragment,{children:[e.jsx(D,{size:14,className:"animate-spin"}),s("memory.dreaming","Dreaming…")]}):s("memory.dreamNow","Dream Now")}),e.jsx("small",{children:s("memory.dreamNowHint","Manually trigger dream processing now.")})]})]})]}),e.jsxs("div",{className:"memory-settings-group",children:[e.jsxs("div",{className:"form-group memory-toggle-row",children:[e.jsxs("label",{htmlFor:"memoryAutoSummarizeEnabled",className:"checkbox-label",children:[e.jsx("input",{id:"memoryAutoSummarizeEnabled",type:"checkbox",checked:n.memoryAutoSummarizeEnabled,onChange:a=>{k(b=>({...b,memoryAutoSummarizeEnabled:a.target.checked}))},disabled:!n.memoryEnabled||u}),s("memory.autoSummarizeLabel","Auto-summarize memory")]}),e.jsx("small",{children:s("memory.autoSummarizeHint","Automatically compacts memory when it exceeds the threshold on a schedule.")})]}),n.memoryEnabled&&n.memoryAutoSummarizeEnabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryAutoSummarizeThresholdChars",children:s("memory.compactionThresholdLabel","Compaction Threshold (chars)")}),e.jsx("input",{id:"memoryAutoSummarizeThresholdChars",type:"number",className:"input",value:n.memoryAutoSummarizeThresholdChars,onChange:a=>{k(b=>({...b,memoryAutoSummarizeThresholdChars:parseInt(a.target.value,10)||5e4}))},min:1e3,disabled:u}),e.jsx("small",{children:s("memory.compactionThresholdHint","Memory will be compacted when it exceeds this character count")})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryAutoSummarizeSchedule",children:s("memory.autoSummarizeScheduleLabel","Schedule (cron)")}),e.jsx("input",{id:"memoryAutoSummarizeSchedule",type:"text",className:"input",value:n.memoryAutoSummarizeSchedule,onChange:a=>{k(b=>({...b,memoryAutoSummarizeSchedule:a.target.value}))},placeholder:"0 3 * * *",disabled:u}),e.jsx("small",{children:s("memory.autoSummarizeScheduleHint","Cron expression for auto-summarize schedule (default: daily at 3 AM)")})]})]})]}),!n.memoryEnabled&&e.jsx("div",{className:"settings-empty-state memory-status-message",children:s("memory.disabledMessage","Memory is currently disabled. Enable memory tools in Settings to edit these automations.")}),F&&e.jsx("div",{className:"memory-action-bar",children:e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:xe,disabled:B||u,children:B?e.jsxs(e.Fragment,{children:[e.jsx(D,{size:14,className:"animate-spin"}),s("memory.saving","Saving…")]}):s("memory.saveSettings","Save Settings")})})]})]})]}),d==="insights"&&e.jsx("div",{className:"memory-insights-tab",children:w?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(D,{size:20,className:"animate-spin"}),e.jsx("span",{children:s("memory.loadingInsights","Loading insights…")})]}):I?e.jsxs("div",{className:"memory-insights-editor-layout",children:[e.jsx("div",{className:"memory-editor-container",children:e.jsx(Ne,{content:x??"",onChange:j,readOnly:!1,filePath:".fusion/memory/memory-insights.md",forceToolbarActionsVisible:!0,onSendSelectionToTask:h})}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:De,children:s("memory.cancel","Cancel")}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:Ae,children:s("memory.saveInsights","Save Insights")})]})]}):!ye||T.length===0?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx("p",{children:s("memory.noInsights","No insights extracted yet.")}),e.jsx("p",{children:s("memory.noInsightsHint",'Insights are automatically extracted from working memory. Click "Extract Now" to trigger extraction manually.')}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm memory-empty-extract-button",onClick:pe,disabled:q,children:q?e.jsxs(e.Fragment,{children:[e.jsx(D,{size:14,className:"animate-spin"}),s("memory.extracting","Extracting…")]}):s("memory.extractNow","Extract Now")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-stats-row",children:[e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value",children:be}),e.jsx("div",{className:"memory-stat-label",children:s("memory.totalInsights","Total Insights")})]}),e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value",children:T.length}),e.jsx("div",{className:"memory-stat-label",children:s("memory.categories","Categories")})]}),m&&e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value memory-stat-value--updated",children:m}),e.jsx("div",{className:"memory-stat-label",children:s("memory.lastUpdated","Last Updated")})]})]}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:pe,disabled:q,children:q?e.jsxs(e.Fragment,{children:[e.jsx(D,{size:14,className:"animate-spin"}),s("memory.extracting","Extracting…")]}):s("memory.extractNow","Extract Now")}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Fe,children:s("memory.editRaw","Edit Raw")})]}),e.jsx("div",{className:"memory-categories-list",children:T.map(a=>{const b=!L.has(a.key);return e.jsxs("div",{className:"memory-category-section",children:[e.jsxs("div",{className:"memory-category-header",onClick:()=>o(a.key),role:"button",tabIndex:0,onKeyDown:E=>{(E.key==="Enter"||E.key===" ")&&(E.preventDefault(),o(a.key))},children:[e.jsx("h4",{children:a.name}),e.jsx("span",{className:"memory-category-count",children:a.items.length})]}),b&&e.jsx("div",{className:"memory-category-items",children:a.items.map((E,Ie)=>e.jsx("div",{className:"memory-insight-item",children:E.replace(/^-\s+/,"").replace(/^\*\s+/,"")},Ie))})]},a.key)})})]})}),d==="engines"&&e.jsx("div",{className:"memory-engines-tab",children:W||P?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(D,{size:20,className:"animate-spin"}),e.jsx("span",{children:s("memory.loadingEngineStatus","Loading engine status…")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-engine-card memory-qmd-card",children:[e.jsx("h3",{children:s("memory.qmdIntegrationTitle","QMD Integration")}),g?.qmdAvailable===!0?e.jsxs("div",{className:"memory-engine-status",children:[e.jsx("span",{className:"memory-health-badge memory-health-badge--healthy",children:s("memory.qmdInstalled","Installed")}),e.jsx("span",{className:"memory-char-count",children:s("memory.qmdAvailableOnPath","qmd is available on PATH.")})]}):g?.qmdAvailable===!1?e.jsxs("div",{className:"settings-empty-state memory-status-message",children:[e.jsxs("span",{children:[s("memory.qmdNotInstalled","qmd is not installed. Search will use local files. Install indexed retrieval:")," ",e.jsx("code",{children:g.qmdInstallCommand||"bun install -g @tobilu/qmd"})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Ee,disabled:te,children:te?s("memory.installing","Installing…"):s("memory.installQmd","Install qmd")})]}):e.jsxs("div",{className:"memory-engine-status",children:[e.jsx("span",{className:"memory-health-badge",children:s("memory.qmdChecking","Checking")}),e.jsx("span",{className:"memory-char-count",children:s("memory.qmdCheckingAvailability","Checking qmd availability…")})]})]}),e.jsxs("div",{className:"memory-engine-card memory-retrieval-card",children:[e.jsx("h3",{children:s("memory.testMemorySearchTitle","Test Memory Search")}),e.jsxs("div",{className:"memory-retrieval-input-row",children:[e.jsx("input",{type:"text",className:"input",value:U,onChange:a=>Q(a.target.value),placeholder:s("memory.searchPlaceholder","Search memory with qmd")}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:ke,disabled:J,children:J?s("memory.testing","Testing…"):s("memory.testRetrieval","Test Retrieval")})]}),e.jsx("small",{className:"settings-muted",children:s("memory.testSearchHint","Runs the same qmd-backed memory_search path agents use.")}),y&&e.jsxs("div",{className:"memory-test-result",children:[e.jsx("strong",{children:s("memory.testResultCount",'{{count}} result for "{{query}}"',{count:y.results.length,query:y.query,defaultValue_one:'{{count}} result for "{{query}}"',defaultValue_other:'{{count}} results for "{{query}}"'})}),e.jsx("small",{children:s("memory.testResultStatus","qmd {{qmdStatus}} · {{fallbackStatus}}",{qmdStatus:y.qmdAvailable?s("memory.qmdStatusAvailable","available"):s("memory.qmdStatusMissing","missing"),fallbackStatus:y.usedFallback?s("memory.localFallbackUsed","local fallback used"):s("memory.qmdPathUsed","qmd path used")})}),y.results.length>0?e.jsx("ul",{children:y.results.map((a,b)=>e.jsxs("li",{children:[e.jsxs("span",{children:[a.path,":",a.lineStart]}),e.jsx("p",{children:a.snippet})]},`${a.path}-${a.lineStart}-${b}`))}):e.jsx("small",{children:s("memory.noMatchingMemory","No matching memory found.")})]})]}),e.jsxs("div",{className:"memory-engine-card",children:[e.jsx("h3",{children:s("memory.currentBackendTitle","Current Backend")}),e.jsx("div",{className:"memory-engine-status",children:e.jsx("span",{className:"memory-emphasis-text",children:g?.currentBackend==="file"?s("memory.backendFile","File (.fusion/memory/, agent/<agent-name>/memory/)"):g?.currentBackend==="readonly"?s("memory.backendReadonly","Read-Only"):g?.currentBackend==="qmd"?s("memory.backendQmd","QMD (Quantized Memory Distillation)"):g?.currentBackend??"unknown"})}),e.jsxs("div",{className:"memory-capability-row",children:[g?.capabilities?.readable&&e.jsx("span",{className:"memory-capability-badge",children:s("memory.capReadable","Readable")}),g?.capabilities?.writable&&e.jsx("span",{className:"memory-capability-badge",children:s("memory.capWritable","Writable")}),g?.capabilities?.supportsAtomicWrite&&e.jsx("span",{className:"memory-capability-badge",children:s("memory.capAtomicWrites","Atomic Writes")}),g?.capabilities?.persistent&&e.jsx("span",{className:"memory-capability-badge",children:s("memory.capPersistent","Persistent")})]})]}),c&&e.jsxs("div",{className:"memory-engine-card",children:[e.jsxs("div",{className:"memory-health-header",children:[e.jsx("h3",{children:s("memory.healthStatusTitle","Health Status")}),e.jsx("span",{className:`memory-health-badge memory-health-badge--${c.health}`,children:c.health==="healthy"?s("memory.healthHealthy","Healthy"):c.health==="warning"?s("memory.healthWarning","Warning"):s("memory.healthIssues","Issues Found")})]}),e.jsxs("div",{className:"memory-health-grid",children:[e.jsxs("div",{children:[e.jsx("div",{className:"memory-health-label",children:s("memory.workingMemoryLabel","Working Memory")}),e.jsx("div",{className:"memory-emphasis-text",children:s("memory.sizeChars","{{size}} chars",{size:c.workingMemory.size})}),e.jsx("div",{className:"memory-health-detail",children:s("memory.sectionCount","{{count}} sections",{count:c.workingMemory.sectionCount})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"memory-health-label",children:s("memory.insightsMemoryLabel","Insights Memory")}),e.jsx("div",{className:"memory-emphasis-text",children:s("memory.sizeChars","{{size}} chars",{size:c.insightsMemory.size})}),e.jsx("div",{className:"memory-health-detail",children:s("memory.insightCount","{{count}} insights",{count:c.insightsMemory.insightCount})})]})]}),e.jsxs("div",{className:"memory-health-section",children:[e.jsx("div",{className:"memory-health-label",children:s("memory.lastExtractionLabel","Last Extraction")}),e.jsx("div",{className:"memory-emphasis-text",children:c.extraction.success?e.jsx("span",{className:"memory-status-text memory-status-text--success",children:s("memory.extractionSuccess","Success")}):e.jsx("span",{className:"memory-status-text memory-status-text--error",children:s("memory.extractionFailed","Failed")})}),e.jsx("div",{className:"memory-health-detail",children:c.extraction.summary||s("memory.insightsExtracted","{{count}} insights extracted",{count:c.extraction.insightCount})})]}),e.jsxs("div",{className:"memory-health-section",children:[e.jsx("div",{className:"memory-health-label",children:s("memory.pruningLabel","Pruning")}),e.jsx("div",{className:"memory-emphasis-text",children:c.pruning.applied?e.jsx("span",{className:"memory-status-text memory-status-text--warning",children:s("memory.pruningApplied","Applied")}):e.jsx("span",{className:"memory-status-text memory-status-text--muted",children:s("memory.pruningNotNeeded","Not needed")})}),c.pruning.applied&&e.jsx("div",{className:"memory-health-detail",children:c.pruning.reason})]})]}),c&&c.checks.length>0&&e.jsxs("div",{className:"memory-engine-card",children:[e.jsx("h3",{children:s("memory.auditChecksTitle","Audit Checks")}),e.jsx("div",{children:c.checks.map(a=>e.jsxs("div",{className:"memory-audit-check",children:[e.jsx("span",{className:a.passed?"memory-audit-check-passed":"memory-audit-check-failed",children:a.passed?"✓":"✗"}),e.jsxs("div",{className:"memory-audit-check-content",children:[e.jsx("div",{className:"memory-emphasis-text",children:a.name}),e.jsx("div",{className:"memory-health-detail",children:a.details})]})]},a.id))})]}),e.jsx("div",{className:"memory-action-bar",children:e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>he(),children:s("memory.runAudit","Run Audit")})}),e.jsxs("div",{className:"memory-settings-note",children:[e.jsx("span",{children:s("memory.settingsNote","Note: Change backend type in")}),e.jsx("button",{type:"button",className:"memory-settings-note-button",onClick:()=>{t(s("memory.settingsNoteToast","Open Settings → Memory to change backend type"),"info")},children:s("memory.settingsNoteLink","Settings → Memory")})]})]})})]})]})}export{ds as MemoryView};
|
|
3
|
+
${j.trimEnd()}`),x},[]);(S.length>0||L.length>0)&&t.push({name:I,key:z,items:S.length>0?S:L.length>0?[L]:[],expanded:!0})}}return t}function ts(i){if(!i)return null;const t=i.match(/##\s+Last\s+Updated:\s*(\d{4}-\d{2}-\d{2})/i);return t?t[1]:null}function as(i){return i.reduce((t,h)=>t+h.items.length,0)}function ds({projectId:i,addToast:t,onSendSelectionToTask:h}){const{t:s}=Be("app"),[d,v]=r.useState("working"),[I,z]=r.useState(new Set),[L,S]=r.useState(!1),[x,j]=r.useState(null),[n,k]=r.useState({memoryEnabled:!0,memoryAutoSummarizeEnabled:!1,memoryAutoSummarizeThresholdChars:5e4,memoryAutoSummarizeSchedule:"0 3 * * *",memoryDreamsEnabled:!1,memoryDreamsSchedule:"0 4 * * *"}),[U,Q]=r.useState(""),[Z,R]=r.useState(!1),[y,M]=r.useState(null),{insightsContent:N,insightsLoading:w,insightsExists:ye,saveInsights:$,memorySettings:l,settingsLoading:u,saveMemorySettings:J,savingMemorySettings:W,backendStatus:g,backendLoading:B,extractInsights:ee,extracting:q,auditReport:c,auditLoading:P,refreshAudit:he,compactMemory:V,compacting:se,installQmdAction:Y,installingQmd:te,testRetrieval:G,memoryFiles:K,memoryFilesLoading:ue,selectedFilePath:A,selectedFileContent:X,selectedFileLoading:H,selectedFileDirty:C,setSelectedFileContent:ae,selectFile:re,saveSelectedFile:me,savingSelectedFile:ne,reloadMemoryFiles:ie,triggerDreamNow:le,dreamRunning:_}=Ke({projectId:i});r.useEffect(()=>{k(l)},[l]);const F=r.useMemo(()=>n.memoryEnabled!==l.memoryEnabled||n.memoryAutoSummarizeEnabled!==l.memoryAutoSummarizeEnabled||n.memoryAutoSummarizeThresholdChars!==l.memoryAutoSummarizeThresholdChars||n.memoryAutoSummarizeSchedule!==l.memoryAutoSummarizeSchedule||n.memoryDreamsEnabled!==l.memoryDreamsEnabled||n.memoryDreamsSchedule!==l.memoryDreamsSchedule,[n,l]),f=r.useMemo(()=>K.find(a=>a.path===A),[K,A]),ge=f?f.layer==="long-term"?s("memory.layerDescLongTerm","Curated durable decisions, conventions, constraints, and pitfalls promoted from dreams."):f.layer==="daily"?s("memory.layerDescDaily","Raw daily observations, open loops, and running context for dream processing."):s("memory.layerDescDreams","Synthesized patterns and open loops promoted from daily memory."):s("memory.editorDefaultDescription","Edits the selected memory file."),T=r.useMemo(()=>ss(N),[N]),be=r.useMemo(()=>as(T),[T]),m=r.useMemo(()=>ts(N),[N]),o=r.useCallback(a=>{z(b=>{const E=new Set(b);return E.has(a)?E.delete(a):E.add(a),E})},[]),p=r.useCallback(async a=>{try{await re(a)}catch{t(s("memory.loadFileFailed","Failed to load memory file"),"error")}},[re,t]),oe=r.useCallback(async()=>{try{await me(),t(s("memory.memorySaved","Memory saved"),"success")}catch{t(s("memory.saveMemoryFailed","Failed to save memory"),"error")}},[me,t]),xe=r.useCallback(async()=>{if(!F)return;const a={};n.memoryEnabled!==l.memoryEnabled&&(a.memoryEnabled=n.memoryEnabled),n.memoryAutoSummarizeEnabled!==l.memoryAutoSummarizeEnabled&&(a.memoryAutoSummarizeEnabled=n.memoryAutoSummarizeEnabled),n.memoryAutoSummarizeThresholdChars!==l.memoryAutoSummarizeThresholdChars&&(a.memoryAutoSummarizeThresholdChars=n.memoryAutoSummarizeThresholdChars),n.memoryAutoSummarizeSchedule!==l.memoryAutoSummarizeSchedule&&(a.memoryAutoSummarizeSchedule=n.memoryAutoSummarizeSchedule),n.memoryDreamsEnabled!==l.memoryDreamsEnabled&&(a.memoryDreamsEnabled=n.memoryDreamsEnabled),n.memoryDreamsSchedule!==l.memoryDreamsSchedule&&(a.memoryDreamsSchedule=n.memoryDreamsSchedule);try{await J(a),t(s("memory.settingsSaved","Memory settings saved"),"success")}catch{t(s("memory.saveSettingsFailed","Failed to save memory settings"),"error")}},[F,n,l,J,t]),Ee=r.useCallback(async()=>{try{const a=await Y();t(a.qmdAvailable?s("memory.qmdInstallSuccess","qmd installed successfully"):s("memory.qmdInstallUnavailable","qmd install finished, but qmd is still unavailable"),a.qmdAvailable?"success":"info")}catch{t(s("memory.installQmdFailed","Failed to install qmd"),"error")}},[Y,t]),ke=r.useCallback(async()=>{R(!0),M(null);try{const a=await G(U);M(a),t(a.qmdAvailable?s("memory.retrievalTestComplete","Memory retrieval test complete"):s("memory.retrievalTestFallback","qmd is not installed; local fallback was used"),a.qmdAvailable?"success":"info")}catch{t(s("memory.retrievalTestFailed","Failed to test memory retrieval"),"error")}finally{R(!1)}},[U,G,t]),Me=r.useCallback(async()=>{try{await le(),t(s("memory.dreamProcessingComplete","Dream processing completed"),"success"),await ie()}catch(a){t(a instanceof Error?a.message:s("memory.dreamProcessingFailed","Failed to run dream processing"),"error")}},[le,ie,t]),we=r.useCallback(async()=>{try{await V(A),t(s("memory.fileCompacted","Memory file compacted"),"success")}catch{t(s("memory.compactFailed","Failed to compact memory"),"error")}},[V,A,t]),pe=r.useCallback(async()=>{try{const a=await ee();t(a.summary,"success")}catch(a){t(a instanceof Error?a.message:s("memory.extractInsightsFailed","Failed to extract insights"),"error")}},[ee,t]),Ae=r.useCallback(async()=>{if(x!==null)try{await $(x),S(!1),j(null),t(s("memory.insightsSaved","Insights saved"),"success")}catch{t(s("memory.saveInsightsFailed","Failed to save insights"),"error")}},[x,$,t]),Fe=r.useCallback(()=>{j(N??""),S(!0)},[N]),De=r.useCallback(()=>{S(!1),j(null)},[]),ze=!B&&g!==null,ce=g?.capabilities?.writable??!1;return e.jsxs("div",{className:"memory-view",children:[e.jsx($e,{icon:We,title:s("memory.title","Memory")}),e.jsxs("div",{className:"memory-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":d==="working",className:`memory-view-tab${d==="working"?" memory-view-tab--active":""}`,onClick:()=>v("working"),"data-testid":"memory-tab-working",children:s("memory.tabWorking","Working Memory")}),e.jsx("button",{type:"button",role:"tab","aria-selected":d==="insights",className:`memory-view-tab${d==="insights"?" memory-view-tab--active":""}`,onClick:()=>v("insights"),"data-testid":"memory-tab-insights",children:s("memory.tabInsights","Insights")}),e.jsx("button",{type:"button",role:"tab","aria-selected":d==="engines",className:`memory-view-tab${d==="engines"?" memory-view-tab--active":""}`,onClick:()=>v("engines"),"data-testid":"memory-tab-engines",children:s("memory.tabEngines","Engines")})]}),e.jsxs("div",{className:"memory-view-content",children:[d==="working"&&e.jsxs("div",{className:"memory-working-tab",children:[ze&&!ce&&e.jsx("div",{className:"memory-readonly-banner",children:s("memory.readOnlyBanner","This memory backend is read-only. Changes cannot be saved.")}),ue||H?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(D,{size:20,className:"animate-spin"}),e.jsx("span",{children:s("memory.loadingFile","Loading memory file…")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-editor-section",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryViewFilePath",children:s("memory.fileLabel","Memory File")}),e.jsx("select",{id:"memoryViewFilePath",className:"select",value:A,onChange:a=>{p(a.target.value)},disabled:C,children:K.map(a=>e.jsx("option",{value:a.path,title:`${a.label} — ${a.path}`,children:es(a)},a.path))}),e.jsx("small",{children:C?s("memory.fileSwitchDirtyHint","Save or discard the current edits before switching files."):s("memory.fileSwitchHint","Choose any project memory file to view or edit.")})]}),f&&e.jsxs("div",{className:"memory-file-summary",children:[e.jsx("span",{children:f.layer==="long-term"?s("memory.layerLongTerm","Long-term"):f.layer==="daily"?s("memory.layerDaily","Daily"):s("memory.layerDreams","Dreams")}),e.jsx("strong",{children:f.path}),e.jsx("small",{children:s("memory.fileSummary","{{size}} bytes · updated {{updatedAt}}",{size:f.size.toLocaleString(),updatedAt:new Date(f.updatedAt).toLocaleString()})})]}),e.jsxs("div",{className:"form-group memory-editor-form-group",children:[e.jsx("label",{children:f?.label||s("memory.editorLabel","Memory Editor")}),e.jsx("small",{children:ge}),e.jsx("div",{className:"memory-editor-container",children:e.jsx(Ne,{content:X,onChange:ae,readOnly:!ce,filePath:A,forceToolbarActionsVisible:!0,onSendSelectionToTask:h})})]})]}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsx("span",{className:"memory-char-count",children:s("memory.charCount","{{count}} characters",{count:X.length})}),e.jsx("div",{className:"memory-flex-spacer"}),ce&&X.length>0&&e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:we,disabled:se||C,children:se?e.jsxs(e.Fragment,{children:[e.jsx(D,{size:14,className:"animate-spin"}),s("memory.compacting","Compacting…")]}):s("memory.compactSelectedFile","Compact Selected File")}),C&&ce&&e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:oe,disabled:ne,children:ne?e.jsxs(e.Fragment,{children:[e.jsx(D,{size:14,className:"animate-spin"}),s("memory.saving","Saving…")]}):s("memory.save","Save")})]}),e.jsxs("div",{className:"memory-config-section",children:[e.jsxs("div",{className:"memory-settings-group",children:[e.jsxs("div",{className:"form-group memory-toggle-row",children:[e.jsxs("label",{htmlFor:"memoryDreamsEnabled",className:"checkbox-label",title:s("memory.dreamsEnabledTooltip","Daily notes are distilled into DREAMS.md and reusable lessons are promoted into MEMORY.md."),children:[e.jsx("input",{id:"memoryDreamsEnabled",type:"checkbox",checked:n.memoryDreamsEnabled,onChange:a=>{k(b=>({...b,memoryDreamsEnabled:a.target.checked}))},disabled:!n.memoryEnabled||u}),s("memory.dreamsEnabledLabel","Process dreams from daily memory")]}),e.jsx("small",{children:s("memory.dreamsEnabledHint","Turns daily notes into DREAMS.md and promotes reusable lessons into MEMORY.md.")})]}),n.memoryEnabled&&n.memoryDreamsEnabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryDreamsSchedule",children:s("memory.dreamsScheduleLabel","Dream Schedule")}),e.jsx("input",{id:"memoryDreamsSchedule",type:"text",className:"input",value:n.memoryDreamsSchedule,onChange:a=>{k(b=>({...b,memoryDreamsSchedule:a.target.value}))},placeholder:"0 4 * * *",disabled:u}),e.jsx("small",{children:s("memory.dreamsScheduleHint","Cron expression for dream processing.")})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:Me,disabled:_||!n.memoryDreamsEnabled,children:_?e.jsxs(e.Fragment,{children:[e.jsx(D,{size:14,className:"animate-spin"}),s("memory.dreaming","Dreaming…")]}):s("memory.dreamNow","Dream Now")}),e.jsx("small",{children:s("memory.dreamNowHint","Manually trigger dream processing now.")})]})]})]}),e.jsxs("div",{className:"memory-settings-group",children:[e.jsxs("div",{className:"form-group memory-toggle-row",children:[e.jsxs("label",{htmlFor:"memoryAutoSummarizeEnabled",className:"checkbox-label",children:[e.jsx("input",{id:"memoryAutoSummarizeEnabled",type:"checkbox",checked:n.memoryAutoSummarizeEnabled,onChange:a=>{k(b=>({...b,memoryAutoSummarizeEnabled:a.target.checked}))},disabled:!n.memoryEnabled||u}),s("memory.autoSummarizeLabel","Auto-summarize memory")]}),e.jsx("small",{children:s("memory.autoSummarizeHint","Automatically compacts memory when it exceeds the threshold on a schedule.")})]}),n.memoryEnabled&&n.memoryAutoSummarizeEnabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryAutoSummarizeThresholdChars",children:s("memory.compactionThresholdLabel","Compaction Threshold (chars)")}),e.jsx("input",{id:"memoryAutoSummarizeThresholdChars",type:"number",className:"input",value:n.memoryAutoSummarizeThresholdChars,onChange:a=>{k(b=>({...b,memoryAutoSummarizeThresholdChars:parseInt(a.target.value,10)||5e4}))},min:1e3,disabled:u}),e.jsx("small",{children:s("memory.compactionThresholdHint","Memory will be compacted when it exceeds this character count")})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryAutoSummarizeSchedule",children:s("memory.autoSummarizeScheduleLabel","Schedule (cron)")}),e.jsx("input",{id:"memoryAutoSummarizeSchedule",type:"text",className:"input",value:n.memoryAutoSummarizeSchedule,onChange:a=>{k(b=>({...b,memoryAutoSummarizeSchedule:a.target.value}))},placeholder:"0 3 * * *",disabled:u}),e.jsx("small",{children:s("memory.autoSummarizeScheduleHint","Cron expression for auto-summarize schedule (default: daily at 3 AM)")})]})]})]}),!n.memoryEnabled&&e.jsx("div",{className:"settings-empty-state memory-status-message",children:s("memory.disabledMessage","Memory is currently disabled. Enable memory tools in Settings to edit these automations.")}),F&&e.jsx("div",{className:"memory-action-bar",children:e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:xe,disabled:W||u,children:W?e.jsxs(e.Fragment,{children:[e.jsx(D,{size:14,className:"animate-spin"}),s("memory.saving","Saving…")]}):s("memory.saveSettings","Save Settings")})})]})]})]}),d==="insights"&&e.jsx("div",{className:"memory-insights-tab",children:w?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(D,{size:20,className:"animate-spin"}),e.jsx("span",{children:s("memory.loadingInsights","Loading insights…")})]}):L?e.jsxs("div",{className:"memory-insights-editor-layout",children:[e.jsx("div",{className:"memory-editor-container",children:e.jsx(Ne,{content:x??"",onChange:j,readOnly:!1,filePath:".fusion/memory/memory-insights.md",forceToolbarActionsVisible:!0,onSendSelectionToTask:h})}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:De,children:s("memory.cancel","Cancel")}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:Ae,children:s("memory.saveInsights","Save Insights")})]})]}):!ye||T.length===0?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx("p",{children:s("memory.noInsights","No insights extracted yet.")}),e.jsx("p",{children:s("memory.noInsightsHint",'Insights are automatically extracted from working memory. Click "Extract Now" to trigger extraction manually.')}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm memory-empty-extract-button",onClick:pe,disabled:q,children:q?e.jsxs(e.Fragment,{children:[e.jsx(D,{size:14,className:"animate-spin"}),s("memory.extracting","Extracting…")]}):s("memory.extractNow","Extract Now")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-stats-row",children:[e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value",children:be}),e.jsx("div",{className:"memory-stat-label",children:s("memory.totalInsights","Total Insights")})]}),e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value",children:T.length}),e.jsx("div",{className:"memory-stat-label",children:s("memory.categories","Categories")})]}),m&&e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value memory-stat-value--updated",children:m}),e.jsx("div",{className:"memory-stat-label",children:s("memory.lastUpdated","Last Updated")})]})]}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:pe,disabled:q,children:q?e.jsxs(e.Fragment,{children:[e.jsx(D,{size:14,className:"animate-spin"}),s("memory.extracting","Extracting…")]}):s("memory.extractNow","Extract Now")}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Fe,children:s("memory.editRaw","Edit Raw")})]}),e.jsx("div",{className:"memory-categories-list",children:T.map(a=>{const b=!I.has(a.key);return e.jsxs("div",{className:"memory-category-section",children:[e.jsxs("div",{className:"memory-category-header",onClick:()=>o(a.key),role:"button",tabIndex:0,onKeyDown:E=>{(E.key==="Enter"||E.key===" ")&&(E.preventDefault(),o(a.key))},children:[e.jsx("h4",{children:a.name}),e.jsx("span",{className:"memory-category-count",children:a.items.length})]}),b&&e.jsx("div",{className:"memory-category-items",children:a.items.map((E,Le)=>e.jsx("div",{className:"memory-insight-item",children:E.replace(/^-\s+/,"").replace(/^\*\s+/,"")},Le))})]},a.key)})})]})}),d==="engines"&&e.jsx("div",{className:"memory-engines-tab",children:B||P?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(D,{size:20,className:"animate-spin"}),e.jsx("span",{children:s("memory.loadingEngineStatus","Loading engine status…")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-engine-card memory-qmd-card",children:[e.jsx("h3",{children:s("memory.qmdIntegrationTitle","QMD Integration")}),g?.qmdAvailable===!0?e.jsxs("div",{className:"memory-engine-status",children:[e.jsx("span",{className:"memory-health-badge memory-health-badge--healthy",children:s("memory.qmdInstalled","Installed")}),e.jsx("span",{className:"memory-char-count",children:s("memory.qmdAvailableOnPath","qmd is available on PATH.")})]}):g?.qmdAvailable===!1?e.jsxs("div",{className:"settings-empty-state memory-status-message",children:[e.jsxs("span",{children:[s("memory.qmdNotInstalled","qmd is not installed. Search will use local files. Install indexed retrieval:")," ",e.jsx("code",{children:g.qmdInstallCommand||"bun install -g @tobilu/qmd"})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Ee,disabled:te,children:te?s("memory.installing","Installing…"):s("memory.installQmd","Install qmd")})]}):e.jsxs("div",{className:"memory-engine-status",children:[e.jsx("span",{className:"memory-health-badge",children:s("memory.qmdChecking","Checking")}),e.jsx("span",{className:"memory-char-count",children:s("memory.qmdCheckingAvailability","Checking qmd availability…")})]})]}),e.jsxs("div",{className:"memory-engine-card memory-retrieval-card",children:[e.jsx("h3",{children:s("memory.testMemorySearchTitle","Test Memory Search")}),e.jsxs("div",{className:"memory-retrieval-input-row",children:[e.jsx("input",{type:"text",className:"input",value:U,onChange:a=>Q(a.target.value),placeholder:s("memory.searchPlaceholder","Search memory with qmd")}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:ke,disabled:Z,children:Z?s("memory.testing","Testing…"):s("memory.testRetrieval","Test Retrieval")})]}),e.jsx("small",{className:"settings-muted",children:s("memory.testSearchHint","Runs the same qmd-backed memory_search path agents use.")}),y&&e.jsxs("div",{className:"memory-test-result",children:[e.jsx("strong",{children:s("memory.testResultCount",'{{count}} result for "{{query}}"',{count:y.results.length,query:y.query,defaultValue_one:'{{count}} result for "{{query}}"',defaultValue_other:'{{count}} results for "{{query}}"'})}),e.jsx("small",{children:s("memory.testResultStatus","qmd {{qmdStatus}} · {{fallbackStatus}}",{qmdStatus:y.qmdAvailable?s("memory.qmdStatusAvailable","available"):s("memory.qmdStatusMissing","missing"),fallbackStatus:y.usedFallback?s("memory.localFallbackUsed","local fallback used"):s("memory.qmdPathUsed","qmd path used")})}),y.results.length>0?e.jsx("ul",{children:y.results.map((a,b)=>e.jsxs("li",{children:[e.jsxs("span",{children:[a.path,":",a.lineStart]}),e.jsx("p",{children:a.snippet})]},`${a.path}-${a.lineStart}-${b}`))}):e.jsx("small",{children:s("memory.noMatchingMemory","No matching memory found.")})]})]}),e.jsxs("div",{className:"memory-engine-card",children:[e.jsx("h3",{children:s("memory.currentBackendTitle","Current Backend")}),e.jsx("div",{className:"memory-engine-status",children:e.jsx("span",{className:"memory-emphasis-text",children:g?.currentBackend==="file"?s("memory.backendFile","File (.fusion/memory/, agent/<agent-name>/memory/)"):g?.currentBackend==="readonly"?s("memory.backendReadonly","Read-Only"):g?.currentBackend==="qmd"?s("memory.backendQmd","QMD (Quantized Memory Distillation)"):g?.currentBackend??"unknown"})}),e.jsxs("div",{className:"memory-capability-row",children:[g?.capabilities?.readable&&e.jsx("span",{className:"memory-capability-badge",children:s("memory.capReadable","Readable")}),g?.capabilities?.writable&&e.jsx("span",{className:"memory-capability-badge",children:s("memory.capWritable","Writable")}),g?.capabilities?.supportsAtomicWrite&&e.jsx("span",{className:"memory-capability-badge",children:s("memory.capAtomicWrites","Atomic Writes")}),g?.capabilities?.persistent&&e.jsx("span",{className:"memory-capability-badge",children:s("memory.capPersistent","Persistent")})]})]}),c&&e.jsxs("div",{className:"memory-engine-card",children:[e.jsxs("div",{className:"memory-health-header",children:[e.jsx("h3",{children:s("memory.healthStatusTitle","Health Status")}),e.jsx("span",{className:`memory-health-badge memory-health-badge--${c.health}`,children:c.health==="healthy"?s("memory.healthHealthy","Healthy"):c.health==="warning"?s("memory.healthWarning","Warning"):s("memory.healthIssues","Issues Found")})]}),e.jsxs("div",{className:"memory-health-grid",children:[e.jsxs("div",{children:[e.jsx("div",{className:"memory-health-label",children:s("memory.workingMemoryLabel","Working Memory")}),e.jsx("div",{className:"memory-emphasis-text",children:s("memory.sizeChars","{{size}} chars",{size:c.workingMemory.size})}),e.jsx("div",{className:"memory-health-detail",children:s("memory.sectionCount","{{count}} sections",{count:c.workingMemory.sectionCount})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"memory-health-label",children:s("memory.insightsMemoryLabel","Insights Memory")}),e.jsx("div",{className:"memory-emphasis-text",children:s("memory.sizeChars","{{size}} chars",{size:c.insightsMemory.size})}),e.jsx("div",{className:"memory-health-detail",children:s("memory.insightCount","{{count}} insights",{count:c.insightsMemory.insightCount})})]})]}),e.jsxs("div",{className:"memory-health-section",children:[e.jsx("div",{className:"memory-health-label",children:s("memory.lastExtractionLabel","Last Extraction")}),e.jsx("div",{className:"memory-emphasis-text",children:c.extraction.success?e.jsx("span",{className:"memory-status-text memory-status-text--success",children:s("memory.extractionSuccess","Success")}):e.jsx("span",{className:"memory-status-text memory-status-text--error",children:s("memory.extractionFailed","Failed")})}),e.jsx("div",{className:"memory-health-detail",children:c.extraction.summary||s("memory.insightsExtracted","{{count}} insights extracted",{count:c.extraction.insightCount})})]}),e.jsxs("div",{className:"memory-health-section",children:[e.jsx("div",{className:"memory-health-label",children:s("memory.pruningLabel","Pruning")}),e.jsx("div",{className:"memory-emphasis-text",children:c.pruning.applied?e.jsx("span",{className:"memory-status-text memory-status-text--warning",children:s("memory.pruningApplied","Applied")}):e.jsx("span",{className:"memory-status-text memory-status-text--muted",children:s("memory.pruningNotNeeded","Not needed")})}),c.pruning.applied&&e.jsx("div",{className:"memory-health-detail",children:c.pruning.reason})]})]}),c&&c.checks.length>0&&e.jsxs("div",{className:"memory-engine-card",children:[e.jsx("h3",{children:s("memory.auditChecksTitle","Audit Checks")}),e.jsx("div",{children:c.checks.map(a=>e.jsxs("div",{className:"memory-audit-check",children:[e.jsx("span",{className:a.passed?"memory-audit-check-passed":"memory-audit-check-failed",children:a.passed?"✓":"✗"}),e.jsxs("div",{className:"memory-audit-check-content",children:[e.jsx("div",{className:"memory-emphasis-text",children:a.name}),e.jsx("div",{className:"memory-health-detail",children:a.details})]})]},a.id))})]}),e.jsx("div",{className:"memory-action-bar",children:e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>he(),children:s("memory.runAudit","Run Audit")})}),e.jsxs("div",{className:"memory-settings-note",children:[e.jsx("span",{children:s("memory.settingsNote","Note: Change backend type in")}),e.jsx("button",{type:"button",className:"memory-settings-note-button",onClick:()=>{t(s("memory.settingsNoteToast","Open Settings → Memory to change backend type"),"info")},children:s("memory.settingsNoteLink","Settings → Memory")})]})]})})]})]})}export{ds as MemoryView};
|
package/dist/client/assets/{PiExtensionsManager-DXwQdB7b.js → PiExtensionsManager-D0a8Q47c.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as l,j as e}from"./vendor-react-SZ_qB27O.js";import{c as V,
|
|
1
|
+
import{r as l,j as e}from"./vendor-react-SZ_qB27O.js";import{c as V,b5 as Y,b6 as Z,b7 as T,R as L,a9 as D,ab as P,P as ee,C as se,e as ae,u as ie,b8 as B,b9 as ne,ba as te,bb as $,X as re}from"./index-aBQwNV_I.js";import{u as le}from"./vendor-i18n-GF3RlKbq.js";import{P as A}from"./puzzle-DaVSYDOd.js";import{B as G}from"./AgentPermissionPolicyEditor-DqYOX1kN.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.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as d,j as e}from"./vendor-react-SZ_qB27O.js";import{ag as Ve,ah as Te,ai as We,aj as ge,ak as Ke,X as de,al as Qe,am as Ye,an as pe,P as me,ao as he,u as be,R as ye,ap as Je,N as Xe,aq as Ze,ar as es,as as ss,at as ns,au as xe,av as is,aw as ts,ax as L,ay as as,az as ls}from"./index-DO9Ch72Y.js";import{D as rs}from"./DirectoryPicker-CZ3EXSE5.js";import{u as os}from"./vendor-i18n-GF3RlKbq.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.js";import"./folder-open-iGyAYoN-.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-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}],A={started:"var(--color-success)",loaded:"var(--color-warning)",error:"var(--color-error)",stopped:"var(--color-muted)",installed:"var(--color-info)"};function us(r){const u=r.settingsSchema,n=u&&Object.keys(u).length>0;return r.id!==we?n?u:void 0:n?{...fe,...u}:fe}function cs(r){const u=new Map,n=[];for(const[N,y]of Object.entries(r))if(y.group){const R=u.get(y.group)??[];R.push([N,y]),u.set(y.group,R)}else n.push([N,y]);return{grouped:u,ungrouped:n}}function ve(r,u="plugin-error-text"){return r.state!=="error"||!r.error?null:e.jsx("p",{className:u,title:r.error,children:r.error})}function js({addToast:r,projectId:u}){const{t:n}=os("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),[K,Q]=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({}),[Le,se]=d.useState(null),[k,ne]=d.useState(null),[Ae,ie]=d.useState(null),{confirm:De}=Ve(),h=d.useCallback(async()=>{try{M(!0);const s=await Te(u);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)}},[u,r]),S=d.useCallback(async(s=b,i=f)=>{try{J(!0),Z(null);const l=await We(s,i||void 0,u);Pe(l)}catch(l){const o=l instanceof Error?l.message:String(l);Z(o)}finally{J(!1)}},[u,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(o=>o.id===l.id));if(s.length===0)return;let i=!1;return Promise.all(s.map(async l=>{try{const o=await ge(l.id,u);if(i)return;z(g=>({...g,[l.id]:o}))}catch{if(i)return;z(o=>({...o,[l.id]:{hasSetup:!0,setupCheckDeferred:!0,deferredReason:"plugin-not-started",pluginState:"installed"}}))}})),()=>{i=!0}},[N,u]);const Ge=d.useRef([]);Ge.current=N,d.useEffect(()=>{const s=u?`?projectId=${encodeURIComponent(u)}`:"",i=l=>{try{const o=JSON.parse(l.data);if(o.scope==="project"&&(o.projectId??u)!==u)return;switch(o.transition){case"installing":case"enabled":case"disabled":case"settings-updated":S(b,f),y(g=>{const a=g.findIndex(t=>t.id===o.pluginId);if(a>=0){const t=[...g];return t[a]={...t[a],enabled:o.enabled,state:o.state,settings:o.settings,error:o.error},t}else return h(),g});break;case"state-changed":y(g=>{const a=g.findIndex(t=>t.id===o.pluginId);if(a>=0){const t=[...g];return t[a]={...t[a],state:o.state,error:o.error},t}return g});break;case"uninstalled":y(g=>g.filter(a=>a.id!==o.pluginId)),S(b,f);break;case"error":y(g=>{const a=g.findIndex(t=>t.id===o.pluginId);if(a>=0){const t=[...g];return t[a]={...t[a],state:o.state,error:o.error},t}return g});break}}catch{}};return Ke(`/api/events${s}`,{events:{"plugin:lifecycle":i},onReconnect:()=>{h(),S(b,f)}})},[u,h,S,f,b]);const te=async()=>{if(!B.trim()){r(n("plugins.installPathRequired","Please enter a plugin path"),"error");return}try{$(!0),await L({path:B,...q?{aiScanOnLoad:!0}:{}},u),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{Q(s.id),await L({path:s.path},u),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{Q(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 L({path:s.path},u),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,u);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,u);z(o=>({...o,[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,u);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,u),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 L({path:s.path},u);await xe(l.id,u),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,u),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,u),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},u),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,u),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,u);x(i)}catch{x({})}finally{W(!1)}},Ue=async()=>{if(c)try{await ss(c.id,m,u),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:A[c.state]||A.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(Qe,{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=us(c);return s&&Object.keys(s).length>0?e.jsxs("div",{className:"plugin-settings-form",children:[(()=>{const{grouped:i,ungrouped:l}=cs(s),o=[];l.length>0&&o.push({title:null,entries:l});for(const[g,a]of i.entries())o.push({title:g,entries:a});return o.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 oe=new Map(N.map(s=>[s.id,s])),ue=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=oe.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=oe.get(s.id),l=!!i,o=Fe[s.id],g=!!(o&&"setupCheckDeferred"in o&&o.setupCheckDeferred),a=o&&"status"in o?o.status:void 0,t=l&&s.hasSetup&&o?.hasSetup&&!g&&i?.state==="started"&&(a==="not-installed"||a==="error"),v=l&&o?.hasSetup&&a==="installed",E=Le===s.id,p=!s.path,j=s.category==="runtime",C=i?i.enabled:!0,w=Ae===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:K===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"):K===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:[ue.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:ue.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:A[s.state]||A.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,A as STATE_COLORS};
|
|
1
|
+
import{r as d,j as e}from"./vendor-react-SZ_qB27O.js";import{a2 as qe,a3 as Te,a4 as We,a5 as ge,a6 as Ke,X as de,a7 as Qe,a8 as Ye,a9 as pe,P as me,aa as he,u as be,R as ye,ab as Je,O as Xe,ac as Ze,ad as es,ae as ss,af as ns,ag as xe,ah as is,ai as ts,aj as L,ak as as,al as ls}from"./index-aBQwNV_I.js";import{D as rs}from"./DirectoryPicker-BzpWdpTC.js";import{u as os}from"./vendor-i18n-GF3RlKbq.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.js";import"./folder-open-YuIEuDwd.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-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}],A={started:"var(--color-success)",loaded:"var(--color-warning)",error:"var(--color-error)",stopped:"var(--color-muted)",installed:"var(--color-info)"};function us(r){const u=r.settingsSchema,n=u&&Object.keys(u).length>0;return r.id!==we?n?u:void 0:n?{...fe,...u}:fe}function cs(r){const u=new Map,n=[];for(const[N,y]of Object.entries(r))if(y.group){const R=u.get(y.group)??[];R.push([N,y]),u.set(y.group,R)}else n.push([N,y]);return{grouped:u,ungrouped:n}}function ve(r,u="plugin-error-text"){return r.state!=="error"||!r.error?null:e.jsx("p",{className:u,title:r.error,children:r.error})}function js({addToast:r,projectId:u}){const{t:n}=os("app"),[N,y]=d.useState([]),[R,M]=d.useState(!0),[Ce,D]=d.useState(!1),[B,G]=d.useState(""),[U,$]=d.useState(!1),[V,q]=d.useState(!1),[P,T]=d.useState(null),[c,O]=d.useState(null),[m,x]=d.useState({}),[Re,W]=d.useState(!1),[K,Q]=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({}),[Le,se]=d.useState(null),[k,ne]=d.useState(null),[Ae,ie]=d.useState(null),{confirm:De}=qe(),h=d.useCallback(async()=>{try{M(!0);const s=await Te(u);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)}},[u,r]),S=d.useCallback(async(s=b,i=f)=>{try{J(!0),Z(null);const l=await We(s,i||void 0,u);Pe(l)}catch(l){const o=l instanceof Error?l.message:String(l);Z(o)}finally{J(!1)}},[u,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(o=>o.id===l.id));if(s.length===0)return;let i=!1;return Promise.all(s.map(async l=>{try{const o=await ge(l.id,u);if(i)return;z(g=>({...g,[l.id]:o}))}catch{if(i)return;z(o=>({...o,[l.id]:{hasSetup:!0,setupCheckDeferred:!0,deferredReason:"plugin-not-started",pluginState:"installed"}}))}})),()=>{i=!0}},[N,u]);const Ge=d.useRef([]);Ge.current=N,d.useEffect(()=>{const s=u?`?projectId=${encodeURIComponent(u)}`:"",i=l=>{try{const o=JSON.parse(l.data);if(o.scope==="project"&&(o.projectId??u)!==u)return;switch(o.transition){case"installing":case"enabled":case"disabled":case"settings-updated":S(b,f),y(g=>{const a=g.findIndex(t=>t.id===o.pluginId);if(a>=0){const t=[...g];return t[a]={...t[a],enabled:o.enabled,state:o.state,settings:o.settings,error:o.error},t}else return h(),g});break;case"state-changed":y(g=>{const a=g.findIndex(t=>t.id===o.pluginId);if(a>=0){const t=[...g];return t[a]={...t[a],state:o.state,error:o.error},t}return g});break;case"uninstalled":y(g=>g.filter(a=>a.id!==o.pluginId)),S(b,f);break;case"error":y(g=>{const a=g.findIndex(t=>t.id===o.pluginId);if(a>=0){const t=[...g];return t[a]={...t[a],state:o.state,error:o.error},t}return g});break}}catch{}};return Ke(`/api/events${s}`,{events:{"plugin:lifecycle":i},onReconnect:()=>{h(),S(b,f)}})},[u,h,S,f,b]);const te=async()=>{if(!B.trim()){r(n("plugins.installPathRequired","Please enter a plugin path"),"error");return}try{$(!0),await L({path:B,...V?{aiScanOnLoad:!0}:{}},u),r(n("plugins.installedGlobally","Plugin installed globally"),"success"),D(!1),G(""),q(!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{Q(s.id),await L({path:s.path},u),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{Q(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 L({path:s.path},u),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,u);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,u);z(o=>({...o,[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,u);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,u),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 L({path:s.path},u);await xe(l.id,u),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,u),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,u),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},u),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,u),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,u);x(i)}catch{x({})}finally{W(!1)}},Ue=async()=>{if(c)try{await ss(c.id,m,u),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:A[c.state]||A.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(Qe,{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=us(c);return s&&Object.keys(s).length>0?e.jsxs("div",{className:"plugin-settings-form",children:[(()=>{const{grouped:i,ungrouped:l}=cs(s),o=[];l.length>0&&o.push({title:null,entries:l});for(const[g,a]of i.entries())o.push({title:g,entries:a});return o.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 oe=new Map(N.map(s=>[s.id,s])),ue=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=oe.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)})})]}),Ve=()=>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=oe.get(s.id),l=!!i,o=Fe[s.id],g=!!(o&&"setupCheckDeferred"in o&&o.setupCheckDeferred),a=o&&"status"in o?o.status:void 0,t=l&&s.hasSetup&&o?.hasSetup&&!g&&i?.state==="started"&&(a==="not-installed"||a==="error"),v=l&&o?.hasSetup&&a==="installed",E=Le===s.id,p=!s.path,j=s.category==="runtime",C=i?i.enabled:!0,w=Ae===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:K===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"):K===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:V,onChange:s=>q(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:[ue.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:ue.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:A[s.state]||A.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))}),Ve(),$e()]})]})}export{fe as AGENT_BROWSER_SETTINGS_SCHEMA,we as BUILTIN_AGENT_BROWSER_PLUGIN_ID,Se as BUILTIN_PLUGINS,js as PluginManager,A 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,
|
|
1
|
+
import{r as a,j as e}from"./vendor-react-SZ_qB27O.js";import{c as te,V as ie,aY as k,aZ as N,a_ as C,aa as F,a$ as M,b0 as ae,b1 as J,a7 as X,aA as Y,_ as E}from"./index-aBQwNV_I.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(J,{size:14,className:"pr-icon-success"}):t==="failure"?e.jsx(X,{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 W(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:$,loadPullRequests:q}=t,h=n!==void 0,[L,S]=a.useState(null),[i,x]=a.useState(n??null),[v,p]=a.useState(null),[T,I]=a.useState([]),[A,U]=a.useState(null),[u,_]=a.useState(null),[Y,B]=a.useState(!1),[K,j]=a.useState(!1),[Q,G]=a.useState(!1),H=a.useMemo(()=>$??ce(l),[$,l]),O=a.useMemo(()=>q??oe(l),[q,l]),D=a.useMemo(()=>R??pe(l),[R,l]),z=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(!z){try{p(null),U(null),G(!0),x(null),I(await W(O(),"Timed out loading pull requests"))}catch(r){I([]),U(r instanceof Error?r.message:s("pr.view.listError","Failed to load pull requests"))}finally{G(!1)}return}try{p(null),j(!0),x(await W(H(z),"Timed out loading pull request"))}catch(r){p(r instanceof Error?r.message:"Failed to load PR")}finally{j(!1)}},[z,n,h,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{_(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{_(null),B(!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]})]}):Q?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…")})]}):T.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:T.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),S(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:()=>S(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")]}),Y?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:()=>B(!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(X,{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(Z,{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(J,{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(Z,{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(J,{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 Z(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:$,loadPullRequests:q}=t,h=n!==void 0,[L,S]=a.useState(null),[i,x]=a.useState(n??null),[v,p]=a.useState(null),[T,A]=a.useState([]),[I,_]=a.useState(null),[u,U]=a.useState(null),[K,B]=a.useState(!1),[Q,j]=a.useState(!1),[W,G]=a.useState(!1),H=a.useMemo(()=>$??ce(l),[$,l]),O=a.useMemo(()=>q??oe(l),[q,l]),D=a.useMemo(()=>R??pe(l),[R,l]),z=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(!z){try{p(null),_(null),G(!0),x(null),A(await Z(O(),"Timed out loading pull requests"))}catch(r){A([]),_(r instanceof Error?r.message:s("pr.view.listError","Failed to load pull requests"))}finally{G(!1)}return}try{p(null),j(!0),x(await Z(H(z),"Timed out loading pull request"))}catch(r){p(r instanceof Error?r.message:"Failed to load PR")}finally{j(!1)}},[z,n,h,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 b=await D(r,i.id,re);x(b)}catch(b){p(b instanceof Error?b.message:`Action ${r} failed`)}finally{U(null),B(!1)}},[i,D]),d=e.jsx(ie,{icon:k,title:s("pr.view.title","Pull Requests")});if(ee)return I?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(N,{size:16})," ",I]})]}):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…")})]}):T.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:T.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),S(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(N,{size:16})," ",v]});if(!i)return Q?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:()=>S(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(N,{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")]}),K?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:()=>B(!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(J,{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(N,{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{aA as W,aB as de,aC as ue,bp as he,bG as xe,aF as ae,bH as ye,ak as ge,bI as X,bJ as Re,bK as _e,bL as Se,bM as je,bN as we,bO as Ne,bt as ke,bP as Ee,bQ as Ce,aH as Ae,bR as Te,V as Le,bS as me,L as Pe,an as Fe}from"./index-DO9Ch72Y.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",z={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??z.pageFetch,github:i?.enabledSources?.github??a?.enabledSources?.github??z.github,localDocs:i?.enabledSources?.localDocs??a?.enabledSources?.localDocs??z.localDocs,llmSynthesis:i?.enabledSources?.llmSynthesis??a?.enabledSources?.llmSynthesis??z.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 Oe(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),[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,O]=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),O(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");O(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}`,U=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,U(),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 Ue({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,O]=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=>O(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:O,attachRunToTask:V,statusCounts:S,refresh:w,uiError:k,runActionState:x}=Oe({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,U]=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]),Q=async(t,u,f)=>{U(t);try{await u(),a?.(f,"success"),await w()}catch(m){a?.(m instanceof Error?m.message:s("research.actionFailed","Action failed"),"error")}finally{U(null)}},te=async t=>{if(r){U(`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{U(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 Q("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 Q("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(Ue,{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 Q("create-task",()=>O(r.id,m,L.findingId,C,le,oe),s("research.taskCreatedFromResearch","Task created from research")):f&&await Q("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{aC as Q,aD as de,aE as ue,bt as he,bK as xe,aH as ae,bL as ye,a6 as ge,bM as X,bN as Re,bO as _e,bP as Se,bQ as je,bR as we,bS as Ne,bx as ke,bT as Ee,bU as Ce,aJ as Ae,bV as Te,V as Le,bW as me,L as Pe,a9 as Fe}from"./index-aBQwNV_I.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",z={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??z.pageFetch,github:i?.enabledSources?.github??a?.enabledSources?.github??z.github,localDocs:i?.enabledSources?.localDocs??a?.enabledSources?.localDocs??z.localDocs,llmSynthesis:i?.enabledSources?.llmSynthesis??a?.enabledSources?.llmSynthesis??z.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}`,_=Q(v,{maxAgeMs:de}),g=Q(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)),[V,U]=c.useState(null),[G,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=Q(v,{maxAgeMs:de}),o=Q(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:V,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:G,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(""),[V,U]=c.useState([]),[G,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:G?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:V.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 Ve=["web-search","page-fetch","github","local-docs","llm-synthesis"],Ge={"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:V,createTaskFromRun:U,attachRunToTask:G,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??Ve,J=b.searchProvider,Z=t=>t==="web-search"?!0:b.enabledSources[Ge[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 V(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",()=>G(r.id,f,L.findingId,oe),s("research.taskEnrichedFromResearch","Task enriched from research")),K(null)}}):null})()]})}export{Je as ResearchView};
|