@bigduu/lotus 2026.7.9 → 2026.7.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/assets/ChildApprovalDialog-BGB7jXaL.js +1 -0
  2. package/dist/assets/CommandPalette-B-wksgcV.js +1 -0
  3. package/dist/assets/CommandSelector-BGErcJ56.js +1 -0
  4. package/dist/assets/ContextBar-BJiA6A7b.js +1 -0
  5. package/dist/assets/FilePreview-Xwi8sy95.js +1 -0
  6. package/dist/assets/FileReferenceSelector-DNssZZdw.js +1 -0
  7. package/dist/assets/HomeDashboard-D0Voco33.js +1 -0
  8. package/dist/assets/MetricsService-CPTVCb46.css +1 -0
  9. package/dist/assets/MetricsService-Df1w4gpU.js +261 -0
  10. package/dist/assets/{index-EeCSowUv.js → QuestionDialog-_XMu820Q.js} +2 -2
  11. package/dist/assets/SessionSummaryCard-DREhRVce.js +1 -0
  12. package/dist/assets/{SubAgentsPanel-DfcoRpzb.js → SubAgentsPanel-NKJ-dRmb.js} +2 -2
  13. package/dist/assets/SystemPromptSelector-Du-DUNZL.js +1 -0
  14. package/dist/assets/SystemSettingsPage-DIiaAU90.js +22 -0
  15. package/dist/assets/TodoList-YXzvjE_q.js +1 -0
  16. package/dist/assets/WorkspacePathModal-CUPh00c9.js +1 -0
  17. package/dist/assets/{architectureDiagram-3BPJPVTR-zn4WxqxE.js → architectureDiagram-3BPJPVTR-9KiHua3S.js} +1 -1
  18. package/dist/assets/{blockDiagram-GPEHLZMM-Ch0Ziv1n.js → blockDiagram-GPEHLZMM-CDqNjvTO.js} +2 -2
  19. package/dist/assets/{c4Diagram-AAUBKEIU-E8sZoNMD.js → c4Diagram-AAUBKEIU-O3QJ6yC8.js} +2 -2
  20. package/dist/assets/{chunk-4BX2VUAB-CqoBM7mt.js → chunk-4BX2VUAB-ChEPx3no.js} +1 -1
  21. package/dist/assets/{chunk-QZHKN3VN--PEq4c1n.js → chunk-QZHKN3VN-D7IvMKA1.js} +1 -1
  22. package/dist/assets/{chunk-727SXJPM-BBevu2P-.js → classDiagram-v2-Q7XG4LA2-LK77IBQl.js} +52 -52
  23. package/dist/assets/{cose-bilkent-S5V4N54A-lHdLyyBT.js → cose-bilkent-S5V4N54A-Blt8eoRn.js} +1 -1
  24. package/dist/assets/dagre-BM42HDAG-CLb8Kvaa.js +4 -0
  25. package/dist/assets/{diagram-2AECGRRQ-BF9kNVCU.js → diagram-2AECGRRQ-D4fGy6Ej.js} +1 -1
  26. package/dist/assets/diagram-5GNKFQAL-Bgx-l53x.js +10 -0
  27. package/dist/assets/{diagram-KO2AKTUF-Ca5AJNBH.js → diagram-KO2AKTUF-BM2owdHD.js} +3 -3
  28. package/dist/assets/{diagram-LMA3HP47-amJkFRYA.js → diagram-LMA3HP47-BKx6RUYq.js} +1 -1
  29. package/dist/assets/diagram-OG6HWLK6-D5LmpUCq.js +24 -0
  30. package/dist/assets/dist-js-BgoG8Mq6.js +1 -0
  31. package/dist/assets/{erDiagram-TEJ5UH35-BxoOik0u.js → erDiagram-TEJ5UH35-DVlyLc1E.js} +3 -3
  32. package/dist/assets/{flowDiagram-I6XJVG4X-dkeiO2hH.js → flowDiagram-I6XJVG4X-BuGmviEX.js} +3 -3
  33. package/dist/assets/{ganttDiagram-6RSMTGT7-CswVWiU9.js → ganttDiagram-6RSMTGT7-DauTBCuZ.js} +3 -3
  34. package/dist/assets/{gitGraphDiagram-PVQCEYII-Dd6AExxZ.js → gitGraphDiagram-PVQCEYII-B3crSu9f.js} +3 -3
  35. package/dist/assets/{graph-BlwPajkw.js → graph-D-orRPRH.js} +1 -1
  36. package/dist/assets/index-CmG-lq98.js +1 -0
  37. package/dist/assets/{index.es-C0d2kHgW.js → index.es-DWpZqL6k.js} +1 -1
  38. package/dist/assets/{ishikawaDiagram-YF4QCWOH-DlSHp01F.js → ishikawaDiagram-YF4QCWOH-9Zn2N4xm.js} +5 -5
  39. package/dist/assets/{journeyDiagram-JHISSGLW-q9U7Sgre.js → journeyDiagram-JHISSGLW-wiPB2QJI.js} +4 -4
  40. package/dist/assets/{kanban-definition-UN3LZRKU-BnNVlM7m.js → kanban-definition-UN3LZRKU-DIb_jb5t.js} +7 -7
  41. package/dist/assets/main-BUi2UcLi.js +12 -0
  42. package/dist/assets/{mindmap-definition-RKZ34NQL-PSaSLfIp.js → mindmap-definition-RKZ34NQL-C48DWZww.js} +5 -5
  43. package/dist/assets/{pieDiagram-4H26LBE5-CnXe4K_Q.js → pieDiagram-4H26LBE5-CQtqwmqz.js} +3 -3
  44. package/dist/assets/{quadrantDiagram-W4KKPZXB-CPY889f9.js → quadrantDiagram-W4KKPZXB-7MXbGiBF.js} +2 -2
  45. package/dist/assets/{requirementDiagram-4Y6WPE33-2korUSK9.js → requirementDiagram-4Y6WPE33-Ly5ueOWG.js} +3 -3
  46. package/dist/assets/{sankeyDiagram-5OEKKPKP-VqQwHzkn.js → sankeyDiagram-5OEKKPKP-D8unLaCs.js} +1 -1
  47. package/dist/assets/{sequenceDiagram-3UESZ5HK-B-UbRHxC.js → sequenceDiagram-3UESZ5HK-BIHn_8QS.js} +4 -4
  48. package/dist/assets/stateDiagram-AJRCARHV-CZ2zexSi.js +1 -0
  49. package/dist/assets/{chunk-AQP2D5EJ-BoimMEmP.js → stateDiagram-v2-BHNVJYJU-CgP87CwS.js} +4 -4
  50. package/dist/assets/{timeline-definition-PNZ67QCA-CBk63lxT.js → timeline-definition-PNZ67QCA-CIkPqyVN.js} +3 -3
  51. package/dist/assets/{vendor-antd-C-pjKgeW.js → vendor-antd-IzIw5qDM.js} +1 -1
  52. package/dist/assets/{vendor-charts-Bd0YvT0v.js → vendor-charts-DCh8kdbi.js} +1 -1
  53. package/dist/assets/{vendor-markdown-CARODNj-.js → vendor-markdown-Bz_2-zkk.js} +1 -1
  54. package/dist/assets/{vendor-mermaid-RKNJ-cQ7.js → vendor-mermaid-Dham3vip.js} +5 -5
  55. package/dist/assets/{vendor-pdf-t6zJ6Yt2.js → vendor-pdf-CPLQd8Bw.js} +4 -4
  56. package/dist/assets/{vennDiagram-CIIHVFJN-CfuV7x76.js → vennDiagram-CIIHVFJN-CymSp_gg.js} +4 -4
  57. package/dist/assets/{wardley-L42UT6IY-BNWzkDHh.js → wardley-L42UT6IY-BAwEDvKY.js} +53 -52
  58. package/dist/assets/{wardleyDiagram-YWT4CUSO-CZKpXhFc.js → wardleyDiagram-YWT4CUSO-Iw4_ra5v.js} +4 -4
  59. package/dist/assets/{xychartDiagram-2RQKCTM6-D97S91oO.js → xychartDiagram-2RQKCTM6-BGmkgtHh.js} +3 -3
  60. package/dist/index.html +16 -5
  61. package/package.json +1 -1
  62. package/dist/assets/App-BbO6pZGu.js +0 -247
  63. package/dist/assets/App-xovo7L2Z.css +0 -1
  64. package/dist/assets/FeatureGuide-C6ZU-khJ.js +0 -1
  65. package/dist/assets/MachineTag-B76KAFbJ.js +0 -1
  66. package/dist/assets/MetricsService-C90ALhMS.js +0 -1
  67. package/dist/assets/chunk-2J33WTMH-Bb08FhRS.js +0 -1
  68. package/dist/assets/chunk-55IACEB6-CuagtSth.js +0 -1
  69. package/dist/assets/chunk-FMBD7UC4-Ds8zFWzV.js +0 -15
  70. package/dist/assets/chunk-ND2GUHAM-CWCqbI2E.js +0 -1
  71. package/dist/assets/classDiagram-4FO5ZUOK-Cb6_vGRW.js +0 -1
  72. package/dist/assets/classDiagram-v2-Q7XG4LA2-Cb6_vGRW.js +0 -1
  73. package/dist/assets/core-Cfh-QHsP.js +0 -1
  74. package/dist/assets/dagre-BM42HDAG-DzbtYvED.js +0 -4
  75. package/dist/assets/diagram-5GNKFQAL-BXcYsUYI.js +0 -10
  76. package/dist/assets/diagram-OG6HWLK6-CaFeFER9.js +0 -24
  77. package/dist/assets/en-US-BrF2u6up.js +0 -3
  78. package/dist/assets/index-B8CHauZa.js +0 -1
  79. package/dist/assets/index-BQ68M6ks.js +0 -1
  80. package/dist/assets/index-BQloTnmU.js +0 -1
  81. package/dist/assets/index-BR_Vstvx.js +0 -22
  82. package/dist/assets/index-BmjFP0ha.js +0 -1
  83. package/dist/assets/index-CA2bZRdR.js +0 -1
  84. package/dist/assets/index-CIy8jvyx.js +0 -1
  85. package/dist/assets/index-D9j5B6hj.js +0 -1
  86. package/dist/assets/index-DCSLre-B.js +0 -1
  87. package/dist/assets/index-Dh4pBGzl.js +0 -1
  88. package/dist/assets/index-Duf3d-S6.js +0 -1
  89. package/dist/assets/index-EgRLn-Uk.js +0 -1
  90. package/dist/assets/index-LBYJ_hLj.js +0 -1
  91. package/dist/assets/index-TahpVE7K.js +0 -1
  92. package/dist/assets/index-_XI0Qq6F.js +0 -1
  93. package/dist/assets/infoDiagram-5YYISTIA-D0lt97Qw.js +0 -2
  94. package/dist/assets/layout-Boy8vhSP.js +0 -1
  95. package/dist/assets/main-Bra_iqhj.js +0 -8
  96. package/dist/assets/onboardingStorage-BVcEpmTy.js +0 -1
  97. package/dist/assets/stateDiagram-AJRCARHV-DFaTkWDQ.js +0 -1
  98. package/dist/assets/stateDiagram-v2-BHNVJYJU-CnbekWW3.js +0 -1
  99. package/dist/assets/zh-CN-CVlaaAdZ.js +0 -3
@@ -1,8 +1,8 @@
1
- import{j as i}from"./vendor-markdown-CARODNj-.js";import{R as ye,u as ve,a as r}from"./vendor-i18n-Dm-c3D_C.js";import{u as T,b as xe,s as Ee,c as he,d as j,r as qe,e as Ce,f as Se,g as Re,a as Y,h as A,C as L}from"./App-BbO6pZGu.js";/* empty css */import{A as we,j as ke,B as Z,k as be,l as Te,n as F,o as ee,p as je,t as De}from"./vendor-antd-C-pjKgeW.js";import"./vendor-mermaid-RKNJ-cQ7.js";import"./main-Bra_iqhj.js";const a={questionCard:"qd-questionCard",questionHeader:"qd-questionHeader",headerLeft:"qd-headerLeft",questionIcon:"qd-questionIcon",questionText:"qd-questionText",collapseBtn:"qd-collapseBtn",questionBody:"qd-questionBody",optionsGroup:"qd-optionsGroup",optionItem:"qd-optionItem",customHint:"qd-customHint",questionFooter:"qd-questionFooter"},{Text:D}=ke,{useToken:Ne}=De,Be=n=>{const f=(n||"").replace(/\\r\\n/g,`
1
+ import{j as i}from"./vendor-markdown-Bz_2-zkk.js";import{R as ye,u as ve,a as r}from"./vendor-i18n-Dm-c3D_C.js";import{u as T,h as xe,j as qe,k as Ee,l as j,r as he,n as Ce,q as Se,d as Re,t as Y,v as A,w as L}from"./MetricsService-Df1w4gpU.js";/* empty css */import{A as we,T as ke,B as Z,$ as be,ae as Te,a5 as F,j as ee,af as je,t as De}from"./vendor-antd-IzIw5qDM.js";import"./vendor-mermaid-Dham3vip.js";import"./main-BUi2UcLi.js";const a={questionCard:"qd-questionCard",questionHeader:"qd-questionHeader",headerLeft:"qd-headerLeft",questionIcon:"qd-questionIcon",questionText:"qd-questionText",collapseBtn:"qd-collapseBtn",questionBody:"qd-questionBody",optionsGroup:"qd-optionsGroup",optionItem:"qd-optionItem",customHint:"qd-customHint",questionFooter:"qd-questionFooter"},{Text:D}=ke,{useToken:Ne}=De,Be=n=>{const f=(n||"").replace(/\\r\\n/g,`
2
2
  `).replace(/\\n/g,`
3
3
  `).replace(/\r\n?/g,`
4
4
  `).trim();return f?f.includes(`
5
5
  `)?f:f.replace(/\s+(?=\d+[).]\s)/g,`
6
6
  `).replace(/\s+(?=[一二三四五六七八九十]+[、.]\s)/g,`
7
7
  `).replace(/\s+(?=[-*•]\s)/g,`
8
- `):""};const te=({sessionId:n,onResponseSubmitted:f,onQuestionAppeared:H})=>{const{t:x}=ve(),{token:E}=Ne(),{message:N}=we.useApp(),[g,q]=r.useState(null),[B,z]=r.useState(!1),[ne,_]=r.useState(!0),[w,k]=r.useState(!1),u=r.useRef(0),p=r.useRef(0),m=r.useRef(null),c=r.useRef(null),h=r.useRef(0),b=r.useRef(H);b.current=H;const C=r.useCallback(()=>{h.current+=1,h.current},[n]),[P,oe]=r.useState(()=>typeof document>"u"?!0:!document.hidden),{markRespondStart:re,markSettleTimeout:G,applyExecutionStarted:le,setPendingQuestion:M,clearPendingQuestion:S,sessionModelRef:y,sessionReasoningEffort:ie,inputReasoningEffort:se,isCurrentSession:I}=T(xe(e=>{var l,s,d,X;const t=n?e.chats.find(ge=>ge.id===n)??null:null;return{markRespondStart:e.markRespondStart,markSettleTimeout:e.markSettleTimeout,applyExecutionStarted:e.applyExecutionStarted,setPendingQuestion:e.setPendingQuestion,clearPendingQuestion:e.clearPendingQuestion,sessionModelRef:((l=t==null?void 0:t.config)==null?void 0:l.model_ref)??null,sessionReasoningEffort:((s=t==null?void 0:t.config)==null?void 0:s.reasoningEffort)??null,inputReasoningEffort:n?((X=(d=e.inputStates)==null?void 0:d[n])==null?void 0:X.reasoningEffort)??null:null,isCurrentSession:e.currentSessionId===n}})),o=T(Ee(n)),R=he(y),O=j(e=>e.currentProvider),V=j(e=>e.providerConfig),$=j(e=>e.providerInstances),ue=r.useMemo(()=>qe(V,R,(y==null?void 0:y.provider)??O,$),[R,y==null?void 0:y.provider,V,O,$]),ae=r.useMemo(()=>n?Ce(n):void 0,[n]),ce=Se({sessionEffort:ie,inputEffort:se,persistedEffort:ae,providerDefault:ue}),v=r.useCallback(()=>{var t,l;const e=(t=T.getState().executionBySession)==null?void 0:t[n];return e?{phase:e.phase,generation:e.generation,backendRunId:e.backendRunId??null,backendIsRunning:e.backend.isRunning,hasPendingQuestion:e.interaction.pendingQuestion!=null,pendingQuestionToolCallId:((l=e.interaction.pendingQuestion)==null?void 0:l.toolCallId)??null,tokenCount:e.stream.tokenCount,hasTokens:e.stream.hasTokens,activeReasons:e.activeReasons}:null},[n]),K=T(Re(n)),U=r.useCallback(async()=>{const e=h.current;try{const t=await Y.get(`respond/${n}/pending`);if(e!==h.current)return;if(t.has_pending_question){const l={question:t.question??"",options:t.options??[],allowCustom:t.allow_custom??!0,toolCallId:t.tool_call_id??null},s=A({sessionId:n,...l});if(c.current===s){u.current=0,p.current=0;return}c.current=null,M(n,l),u.current=0,p.current=0}else c.current=null,S(n),m.current=null,u.current+=1,u.current>=6?p.current=2:u.current>=2&&(p.current=1)}catch(t){if(e!==h.current)return;if(t instanceof Error&&t.message.includes("404")){c.current=null,S(n),m.current=null,u.current+=1;return}c.current=null,S(n),m.current=null,u.current+=1,u.current>=6?p.current=2:u.current>=2&&(p.current=1),console.error("Failed to fetch pending question:",t)}finally{if(e!==h.current)return;_(!1)}},[n,M,S]);r.useEffect(()=>{C(),u.current=0,p.current=0,m.current=null,c.current=null,_(!0),q(null),k(!1)},[n,C]),r.useEffect(()=>{if(typeof document>"u")return;const e=()=>{oe(!document.hidden)};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[]),r.useEffect(()=>{var e;if(o){const t=A({sessionId:n,question:o.question,options:o.options,allowCustom:o.allowCustom,toolCallId:o.toolCallId});m.current===t||(q(null),k(!1),(e=b.current)==null||e.call(b)),m.current=t,c.current!==null&&c.current!==t&&(c.current=null)}else m.current=null},[n,o,o==null?void 0:o.allowCustom,o==null?void 0:o.options,o==null?void 0:o.question,o==null?void 0:o.toolCallId]);const W=r.useCallback(()=>{if(o)return null;if(K)return I?P?5e3:15e3:null;if(!I||!P)return null;const e=p.current;return e===0?3e4:e===1?6e4:12e4},[o,K,I,P]);r.useEffect(()=>{if(o){_(!1);return}let e=!1,t=null;const l=async()=>{if(e||B||(await U(),e))return;const s=W();s!==null&&(t=setTimeout(l,s))};return l(),()=>{e=!0,t&&clearTimeout(t)}},[o,U,W,B]),r.useEffect(()=>{if(typeof window>"u")return;const e=t=>{var d;const s=((d=t.detail)==null?void 0:d.sessionId)??null;!s||s!==n||(v(),C(),q(null),m.current=null,u.current=0)};return window.addEventListener(L,e),()=>{window.removeEventListener(L,e)}},[n,C,v]);const de=r.useCallback(e=>{q(e)},[]),fe=async()=>{if(!g||g==="custom"){N.warning(x("components.questionDialog.selectOptionWarning"));return}z(!0),o==null||o.toolCallId,v(),C();const e=re(n,(o==null?void 0:o.toolCallId)??null);v(),await new Promise(t=>setTimeout(t,0));try{const t={};j.getState().isProviderModelRefEnabled()&&R&&(t.model_ref=R,t.provider=R.provider);const l=await Y.post(`respond/${n}`,{response:g,reasoning_effort:ce,...t});v(),N.success(x("components.questionDialog.responseSubmitted")),c.current=o?A({sessionId:n,question:o.question,options:o.options,allowCustom:o.allowCustom,toolCallId:o.toolCallId}):null,q(null),u.current=0,S(n),typeof window<"u"&&window.dispatchEvent(new CustomEvent(L,{detail:{sessionId:n}}));const s=l==null?void 0:l.auto_resume_status,d=l==null?void 0:l.run_id;v(),s==="started"||s==="already_running"?(le(n,d??"",e),v(),void 0):(s==="error"||!s)&&(console.error("[QuestionDialog] Failed to auto-resume agent execution"),G(n)),f==null||f()}catch(t){console.error("Failed to submit response:",t),N.error(t instanceof Error?t.message:x("components.questionDialog.submitFailed")),G(n)}finally{z(!1)}};if(ne||!o)return null;const{question:pe,options:Q,allowCustom:me}=o,J=Be(pe);return i.jsxs("div",{className:a.questionCard,style:{background:E.colorBgContainer,borderColor:E.colorBorderSecondary,border:`1px solid ${E.colorBorderSecondary}`},children:[i.jsxs("div",{className:a.questionHeader,"data-collapsed":w?"true":"false",onClick:()=>k(e=>!e),role:"button",tabIndex:0,onKeyDown:e=>{(e.key==="Enter"||e.key===" ")&&k(t=>!t)},children:[i.jsxs("span",{className:a.headerLeft,children:[i.jsx("span",{className:a.questionIcon,children:"🤔"}),i.jsx(D,{strong:!0,className:a.questionText,style:{color:E.colorPrimary,whiteSpace:"pre-wrap"},title:w?J:void 0,children:J})]}),i.jsx(Z,{type:"text",size:"small",icon:w?i.jsx(be,{}):i.jsx(Te,{}),className:a.collapseBtn,tabIndex:-1})]}),!w&&i.jsxs("div",{className:a.questionBody,children:[i.jsx(F.Group,{className:a.optionsGroup,value:g,onChange:e=>de(e.target.value),children:i.jsxs(ee,{direction:"vertical",size:4,style:{width:"100%"},children:[Q==null?void 0:Q.map(e=>i.jsx(F,{value:e,className:a.optionItem,children:i.jsx(D,{style:{color:E.colorText},children:e})},e)),me&&i.jsx(F,{value:"custom",className:a.optionItem,children:i.jsxs(ee,{size:4,children:[i.jsx(je,{}),i.jsx(D,{style:{color:E.colorText},children:x("components.questionDialog.otherTypeBelow")})]})})]})}),g==="custom"&&i.jsx("div",{className:a.customHint,children:i.jsx(D,{type:"secondary",style:{fontSize:12},children:x("components.questionDialog.customAnswerTip")})}),g&&g!=="custom"&&i.jsx("div",{className:a.questionFooter,children:i.jsx(Z,{type:"primary",size:"small",onClick:fe,loading:B,children:x("components.questionDialog.confirm")})})]})]})};te.displayName="QuestionDialog";const _e=ye.memo(te);_e.displayName="QuestionDialog";export{_e as QuestionDialog,_e as default};
8
+ `):""};const te=({sessionId:n,onResponseSubmitted:f,onQuestionAppeared:H})=>{const{t:x}=ve(),{token:q}=Ne(),{message:N}=we.useApp(),[g,h]=r.useState(null),[B,z]=r.useState(!1),[ne,_]=r.useState(!0),[w,k]=r.useState(!1),u=r.useRef(0),p=r.useRef(0),m=r.useRef(null),c=r.useRef(null),E=r.useRef(0),b=r.useRef(H);b.current=H;const C=r.useCallback(()=>{E.current+=1,E.current},[n]),[P,oe]=r.useState(()=>typeof document>"u"?!0:!document.hidden),{markRespondStart:re,markSettleTimeout:G,applyExecutionStarted:le,setPendingQuestion:M,clearPendingQuestion:S,sessionModelRef:y,sessionReasoningEffort:ie,inputReasoningEffort:se,isCurrentSession:I}=T(xe(e=>{var l,s,d,X;const t=n?e.chats.find(ge=>ge.id===n)??null:null;return{markRespondStart:e.markRespondStart,markSettleTimeout:e.markSettleTimeout,applyExecutionStarted:e.applyExecutionStarted,setPendingQuestion:e.setPendingQuestion,clearPendingQuestion:e.clearPendingQuestion,sessionModelRef:((l=t==null?void 0:t.config)==null?void 0:l.model_ref)??null,sessionReasoningEffort:((s=t==null?void 0:t.config)==null?void 0:s.reasoningEffort)??null,inputReasoningEffort:n?((X=(d=e.inputStates)==null?void 0:d[n])==null?void 0:X.reasoningEffort)??null:null,isCurrentSession:e.currentSessionId===n}})),o=T(qe(n)),R=Ee(y),O=j(e=>e.currentProvider),$=j(e=>e.providerConfig),V=j(e=>e.providerInstances),ue=r.useMemo(()=>he($,R,(y==null?void 0:y.provider)??O,V),[R,y==null?void 0:y.provider,$,O,V]),ae=r.useMemo(()=>n?Ce(n):void 0,[n]),ce=Se({sessionEffort:ie,inputEffort:se,persistedEffort:ae,providerDefault:ue}),v=r.useCallback(()=>{var t,l;const e=(t=T.getState().executionBySession)==null?void 0:t[n];return e?{phase:e.phase,generation:e.generation,backendRunId:e.backendRunId??null,backendIsRunning:e.backend.isRunning,hasPendingQuestion:e.interaction.pendingQuestion!=null,pendingQuestionToolCallId:((l=e.interaction.pendingQuestion)==null?void 0:l.toolCallId)??null,tokenCount:e.stream.tokenCount,hasTokens:e.stream.hasTokens,activeReasons:e.activeReasons}:null},[n]),K=T(Re(n)),U=r.useCallback(async()=>{const e=E.current;try{const t=await Y.get(`respond/${n}/pending`);if(e!==E.current)return;if(t.has_pending_question){const l={question:t.question??"",options:t.options??[],allowCustom:t.allow_custom??!0,toolCallId:t.tool_call_id??null},s=A({sessionId:n,...l});if(c.current===s){u.current=0,p.current=0;return}c.current=null,M(n,l),u.current=0,p.current=0}else c.current=null,S(n),m.current=null,u.current+=1,u.current>=6?p.current=2:u.current>=2&&(p.current=1)}catch(t){if(e!==E.current)return;if(t instanceof Error&&t.message.includes("404")){c.current=null,S(n),m.current=null,u.current+=1;return}c.current=null,S(n),m.current=null,u.current+=1,u.current>=6?p.current=2:u.current>=2&&(p.current=1),console.error("Failed to fetch pending question:",t)}finally{if(e!==E.current)return;_(!1)}},[n,M,S]);r.useEffect(()=>{C(),u.current=0,p.current=0,m.current=null,c.current=null,_(!0),h(null),k(!1)},[n,C]),r.useEffect(()=>{if(typeof document>"u")return;const e=()=>{oe(!document.hidden)};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[]),r.useEffect(()=>{var e;if(o){const t=A({sessionId:n,question:o.question,options:o.options,allowCustom:o.allowCustom,toolCallId:o.toolCallId});m.current===t||(h(null),k(!1),(e=b.current)==null||e.call(b)),m.current=t,c.current!==null&&c.current!==t&&(c.current=null)}else m.current=null},[n,o,o==null?void 0:o.allowCustom,o==null?void 0:o.options,o==null?void 0:o.question,o==null?void 0:o.toolCallId]);const W=r.useCallback(()=>{if(o)return null;if(K)return I?P?5e3:15e3:null;if(!I||!P)return null;const e=p.current;return e===0?3e4:e===1?6e4:12e4},[o,K,I,P]);r.useEffect(()=>{if(o){_(!1);return}let e=!1,t=null;const l=async()=>{if(e||B||(await U(),e))return;const s=W();s!==null&&(t=setTimeout(l,s))};return l(),()=>{e=!0,t&&clearTimeout(t)}},[o,U,W,B]),r.useEffect(()=>{if(typeof window>"u")return;const e=t=>{var d;const s=((d=t.detail)==null?void 0:d.sessionId)??null;!s||s!==n||(v(),C(),h(null),m.current=null,u.current=0)};return window.addEventListener(L,e),()=>{window.removeEventListener(L,e)}},[n,C,v]);const de=r.useCallback(e=>{h(e)},[]),fe=async()=>{if(!g||g==="custom"){N.warning(x("components.questionDialog.selectOptionWarning"));return}z(!0),o==null||o.toolCallId,v(),C();const e=re(n,(o==null?void 0:o.toolCallId)??null);v(),await new Promise(t=>setTimeout(t,0));try{const t={};j.getState().isProviderModelRefEnabled()&&R&&(t.model_ref=R,t.provider=R.provider);const l=await Y.post(`respond/${n}`,{response:g,reasoning_effort:ce,...t});v(),N.success(x("components.questionDialog.responseSubmitted")),c.current=o?A({sessionId:n,question:o.question,options:o.options,allowCustom:o.allowCustom,toolCallId:o.toolCallId}):null,h(null),u.current=0,S(n),typeof window<"u"&&window.dispatchEvent(new CustomEvent(L,{detail:{sessionId:n}}));const s=l==null?void 0:l.auto_resume_status,d=l==null?void 0:l.run_id;v(),s==="started"||s==="already_running"?(le(n,d??"",e),v(),void 0):(s==="error"||!s)&&(console.error("[QuestionDialog] Failed to auto-resume agent execution"),G(n)),f==null||f()}catch(t){console.error("Failed to submit response:",t),N.error(t instanceof Error?t.message:x("components.questionDialog.submitFailed")),G(n)}finally{z(!1)}};if(ne||!o)return null;const{question:pe,options:Q,allowCustom:me}=o,J=Be(pe);return i.jsxs("div",{className:a.questionCard,style:{background:q.colorBgContainer,borderColor:q.colorBorderSecondary,border:`1px solid ${q.colorBorderSecondary}`},children:[i.jsxs("div",{className:a.questionHeader,"data-collapsed":w?"true":"false",onClick:()=>k(e=>!e),role:"button",tabIndex:0,onKeyDown:e=>{(e.key==="Enter"||e.key===" ")&&k(t=>!t)},children:[i.jsxs("span",{className:a.headerLeft,children:[i.jsx("span",{className:a.questionIcon,children:"🤔"}),i.jsx(D,{strong:!0,className:a.questionText,style:{color:q.colorPrimary,whiteSpace:"pre-wrap"},title:w?J:void 0,children:J})]}),i.jsx(Z,{type:"text",size:"small",icon:w?i.jsx(be,{}):i.jsx(Te,{}),className:a.collapseBtn,tabIndex:-1})]}),!w&&i.jsxs("div",{className:a.questionBody,children:[i.jsx(F.Group,{className:a.optionsGroup,value:g,onChange:e=>de(e.target.value),children:i.jsxs(ee,{direction:"vertical",size:4,style:{width:"100%"},children:[Q==null?void 0:Q.map(e=>i.jsx(F,{value:e,className:a.optionItem,children:i.jsx(D,{style:{color:q.colorText},children:e})},e)),me&&i.jsx(F,{value:"custom",className:a.optionItem,children:i.jsxs(ee,{size:4,children:[i.jsx(je,{}),i.jsx(D,{style:{color:q.colorText},children:x("components.questionDialog.otherTypeBelow")})]})})]})}),g==="custom"&&i.jsx("div",{className:a.customHint,children:i.jsx(D,{type:"secondary",style:{fontSize:12},children:x("components.questionDialog.customAnswerTip")})}),g&&g!=="custom"&&i.jsx("div",{className:a.questionFooter,children:i.jsx(Z,{type:"primary",size:"small",onClick:fe,loading:B,children:x("components.questionDialog.confirm")})})]})]})};te.displayName="QuestionDialog";const _e=ye.memo(te);_e.displayName="QuestionDialog";export{_e as QuestionDialog,_e as default};
@@ -0,0 +1 @@
1
+ import{j as s}from"./vendor-markdown-Bz_2-zkk.js";import{u as M,a as N}from"./vendor-i18n-Dm-c3D_C.js";import{u as b,b as I,m as w,c as A,f as T,I as B}from"./MetricsService-Df1w4gpU.js";import{t as W,ab as D,O as $,ac as R,k as _,l as v,D as k,$ as F,ad as L,N as O,n as z}from"./vendor-antd-IzIw5qDM.js";import"./vendor-mermaid-Dham3vip.js";import"./main-BUi2UcLi.js";const S=new Map,P=new Set(["Write","Edit","apply_patch","NotebookEdit"]),H=l=>{const n=l.match(/(?:file_path|Wrote file|Edited file)[:\s]*["']?([^\s"',]+)/i);if(n){const o=n[1];return o.split("/").pop()||o}return null},K=(l,n)=>{const o=n-l;if(o<0)return"";const e=Math.floor(o/1e3);if(e<60)return`${e}s`;const i=Math.floor(e/60);return i<60?`${i}m ${e%60}s`:`${Math.floor(i/60)}h ${i%60}m`},U=l=>{var p,j;let n=0,o=0,e=0,i=0,y=!1,x=0,d="";const h=new Set;let u=0,t=0;for(const a of l){const c=a.createdAt?new Date(a.createdAt).getTime():0;if(c>0&&(u===0||c<u)&&(u=c),c>t&&(t=c),a.isCompressed){y=!0,x++;continue}if(a.role==="user"&&!("type"in a&&a.type==="file_reference")&&n++,a.role==="assistant"){if("type"in a&&a.type==="tool_call"&&(e+=((p=a.toolCalls)==null?void 0:p.length)??0),"type"in a&&a.type==="tool_result"){const m=a;if(m.isError&&i++,P.has(m.toolName)){const f=H(((j=m.result)==null?void 0:j.result)??"");f&&h.add(f)}}if("type"in a&&a.type==="text"){o++;const m=a.content||"";m.length>0&&m.length>30&&(d=m.slice(0,300))}}}return{messageCount:l.length,userMessageCount:n,assistantMessageCount:o,toolCallCount:e,toolErrorCount:i,fileChanges:Array.from(h).slice(0,10),lastAssistantExcerpt:d,hasCompression:y,compressionCount:x,duration:u>0&&t>u?K(u,t):""}},Y=({sessionId:l,compact:n=!1})=>{const{t:o}=M(),{token:e}=W.useToken(),[i,y]=N.useState(!1),[x,d]=N.useState(()=>S.get(l)),h=b(I(l)),u=h==null?void 0:h.messages,t=N.useMemo(()=>!u||u.length===0?null:U(u),[u]);if(N.useEffect(()=>{let r=!1;const g=S.get(l);return g!==void 0?(d(g),()=>{r=!0}):(d(void 0),w.getSessionDetail(l).then(C=>{if(r)return;const E=(C==null?void 0:C.session)??null;S.set(l,E),d(E)},()=>{r||(S.set(l,null),d(null))}),()=>{r=!0})},[l]),!t||t.messageCount<3)return null;const p=t.fileChanges.length>0,j=t.lastAssistantExcerpt.length>0,a=n&&p?t.fileChanges:[],c=x==null?void 0:x.total_token_usage,m=c?A(c.total_tokens):null,f=c?s.jsxs("div",{style:{minWidth:180},children:[s.jsx("div",{style:{fontWeight:600,marginBottom:4},children:o("sessionSummary.totalTokens","Total tokens")}),s.jsxs("div",{children:[o("sessionSummary.promptTokens","Prompt"),":"," ",T(c.prompt_tokens)]}),s.jsxs("div",{children:[o("sessionSummary.completionTokens","Completion"),":"," ",T(c.completion_tokens)]}),s.jsxs("div",{children:[o("sessionSummary.totalTokens","Total tokens"),":"," ",T(c.total_tokens)]})]}):null;return s.jsxs("div",{className:`lotus-session-summary ${n?"lotus-session-summary--compact":""}`,style:{borderColor:e.colorBorderSecondary,background:`${e.colorBgElevated}`},children:[s.jsxs("div",{className:"lotus-session-summary-header",onClick:()=>y(r=>!r),role:"button",tabIndex:0,onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),y(g=>!g))},"aria-expanded":i,children:[s.jsx("span",{className:"lotus-session-summary-header-icon",style:{color:e.colorPrimary},children:s.jsx(D,{})}),s.jsx("span",{className:"lotus-session-summary-header-title",style:{color:e.colorText},children:o("sessionSummary.title","Session Summary")}),!i&&s.jsxs("span",{className:"lotus-session-summary-stats",children:[s.jsxs("span",{className:"lotus-session-summary-stat",style:{color:e.colorTextSecondary},children:[s.jsx($,{className:"lotus-session-summary-stat-icon"}),s.jsx("span",{className:"lotus-session-summary-stat-value",children:t.messageCount})]}),t.toolCallCount>0&&s.jsxs("span",{className:"lotus-session-summary-stat",style:{color:e.colorTextSecondary},children:[s.jsx(R,{className:"lotus-session-summary-stat-icon"}),s.jsx("span",{className:"lotus-session-summary-stat-value",children:t.toolCallCount})]}),p&&s.jsxs("span",{className:"lotus-session-summary-stat",style:{color:e.colorTextSecondary},children:[s.jsx(_,{className:"lotus-session-summary-stat-icon"}),s.jsx("span",{className:"lotus-session-summary-stat-value",children:t.fileChanges.length})]}),m&&s.jsx(v,{title:f,children:s.jsxs("span",{className:"lotus-session-summary-stat",style:{color:e.colorTextSecondary},children:[s.jsx(k,{className:"lotus-session-summary-stat-icon"}),s.jsx("span",{className:"lotus-session-summary-stat-value",children:m})]})})]}),s.jsx("span",{className:`lotus-session-summary-toggle ${i?"is-expanded":""}`,style:{color:e.colorTextTertiary},children:s.jsx(F,{})})]}),i&&s.jsxs("div",{className:"lotus-session-summary-body",children:[s.jsxs("div",{className:"lotus-session-summary-stats",children:[s.jsxs("span",{className:"lotus-session-summary-stat",style:{color:e.colorTextSecondary},children:[s.jsx($,{className:"lotus-session-summary-stat-icon"}),s.jsxs("span",{children:[s.jsx("span",{className:"lotus-session-summary-stat-value",children:t.messageCount})," ",o("sessionSummary.messages","messages")]})]}),s.jsxs("span",{className:"lotus-session-summary-stat",style:{color:e.colorTextSecondary},children:[s.jsx("span",{className:"lotus-session-summary-stat-icon",children:"👤"}),s.jsxs("span",{children:[s.jsx("span",{className:"lotus-session-summary-stat-value",children:t.userMessageCount})," ",o("sessionSummary.userTurns","user")]})]}),s.jsxs("span",{className:"lotus-session-summary-stat",style:{color:e.colorTextSecondary},children:[s.jsx("span",{className:"lotus-session-summary-stat-icon",children:"🤖"}),s.jsxs("span",{children:[s.jsx("span",{className:"lotus-session-summary-stat-value",children:t.assistantMessageCount})," ",o("sessionSummary.assistantTurns","assistant")]})]}),t.toolCallCount>0&&s.jsxs("span",{className:"lotus-session-summary-stat",style:{color:e.colorTextSecondary},children:[s.jsx(R,{className:"lotus-session-summary-stat-icon"}),s.jsxs("span",{children:[s.jsx("span",{className:"lotus-session-summary-stat-value",children:t.toolCallCount})," ",o("sessionSummary.toolCalls","tool calls")]})]}),t.toolErrorCount>0&&s.jsxs("span",{className:"lotus-session-summary-stat",style:{color:"#ff4d4f"},children:[s.jsx(L,{className:"lotus-session-summary-stat-icon"}),s.jsxs("span",{children:[s.jsx("span",{className:"lotus-session-summary-stat-value",children:t.toolErrorCount})," ",o("sessionSummary.errors","errors")]})]}),t.duration&&s.jsxs("span",{className:"lotus-session-summary-stat",style:{color:e.colorTextSecondary},children:[s.jsx(O,{className:"lotus-session-summary-stat-icon"}),s.jsx("span",{children:t.duration})]}),t.hasCompression&&s.jsxs("span",{className:"lotus-session-summary-stat",style:{color:e.colorTextSecondary},children:[s.jsx(k,{className:"lotus-session-summary-stat-icon"}),s.jsxs("span",{children:[s.jsx("span",{className:"lotus-session-summary-stat-value",children:t.compressionCount})," ",o("sessionSummary.compressions","compressions")]})]}),m&&s.jsx(v,{title:f,children:s.jsxs("span",{className:"lotus-session-summary-stat",style:{color:e.colorTextSecondary},children:[s.jsx(k,{className:"lotus-session-summary-stat-icon"}),s.jsxs("span",{children:[s.jsx("span",{className:"lotus-session-summary-stat-value",children:m})," ",o("sessionSummary.totalTokens","total tokens")]})]})})]}),p&&s.jsxs("div",{children:[s.jsx("div",{style:{fontSize:n?10:11,fontWeight:600,color:e.colorTextSecondary,marginBottom:n?2:4,textTransform:"uppercase",letterSpacing:.3},children:o("sessionSummary.filesChanged","Files Changed")}),n?s.jsx(B,{items:a,style:{lineHeight:1.4,wordBreak:"break-word",whiteSpace:"normal"}}):s.jsx("div",{className:"lotus-session-summary-files",children:t.fileChanges.map(r=>s.jsx(v,{title:r,children:s.jsxs(z,{bordered:!1,className:"lotus-session-summary-file-tag",children:[s.jsx(_,{style:{marginRight:4}}),r]})},r))})]}),j&&s.jsxs("div",{children:[s.jsx("div",{style:{fontSize:n?10:11,fontWeight:600,color:e.colorTextSecondary,marginBottom:n?2:4,textTransform:"uppercase",letterSpacing:.3},children:o("sessionSummary.lastResponse","Latest Response")}),s.jsx("div",{className:"lotus-session-summary-conclusion",style:{color:e.colorTextSecondary},children:t.lastAssistantExcerpt})]})]})]})};export{Y as SessionSummaryCard,Y as default};
@@ -1,3 +1,3 @@
1
- var Fe=Object.defineProperty;var Be=(t,e,l)=>e in t?Fe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:l}):t[e]=l;var pe=(t,e,l)=>Be(t,typeof e!="symbol"?e+"":e,l);import{j as r}from"./vendor-markdown-CARODNj-.js";import{a as u,u as Y}from"./vendor-i18n-Dm-c3D_C.js";import{B,H as Te,J as Xe,K as ze,L as De,M as We,N as Le,O as Ne,P as Ue,j as fe,Q as me,I as Q,u as R,R as Ge,q as Ke}from"./App-BbO6pZGu.js";import{x as L,Q as I,B as _,az as qe,a8 as Ye,j as ee,t as te,aA as Je,A as Ve,k as ye,l as Se,U as Qe}from"./vendor-antd-C-pjKgeW.js";import{M as Ce}from"./MachineTag-B76KAFbJ.js";import"./vendor-mermaid-RKNJ-cQ7.js";import"./main-Bra_iqhj.js";const O=class O{static getInstance(){return O.instance||(O.instance=new O),O.instance}parseUserCommand(e){B("[ToolService]",`[ToolService] parseUserCommand: Parsing content: "${e}"`);const l=e.trim();if(!l.startsWith("/"))return B("[ToolService]",'[ToolService] parseUserCommand: Content does not start with "/", not a tool command.'),null;const n=l.indexOf(" ");let o,a;if(n===-1?(o=l.substring(1),a=""):(o=l.substring(1,n),a=l.substring(n+1).trim()),o){const g={tool_name:o,user_description:a};return B("[ToolService]","[ToolService] parseUserCommand: Successfully parsed command:",g),g}return B("[ToolService]","[ToolService] parseUserCommand: Failed to parse tool name from content."),null}parseAIResponseToToolCall(e){return this.parseUserCommand(e)}async executeTool(e){B("[ToolService]","[ToolService] executeTool: Attempting to execute tool via HTTP with request:",e);try{const l=await Te.post("tools/execute",e),n=JSON.parse(l.result);if(!n||typeof n!="object"||typeof n.success!="boolean"||typeof n.result!="string")throw new Error("Tool execution returned a malformed result");const o=n;return B("[ToolService]","[ToolService] executeTool: Parsed structured result:",o),o}catch(l){throw console.error("[ToolService] executeTool: HTTP tool execution failed:",l),l instanceof Xe?new Error(`Workflow execution failed: ${l.message}`):l}}};pe(O,"instance");let Z=O;const J=new Z;class Ze{async listProfiles(){return Te.get("subagent_profiles")}}const et=new Ze,tt=[];function nt(t={}){const{enabled:e=!0,refreshKey:l}=t,[n,o]=u.useState(null),[a,g]=u.useState(!1),[p,y]=u.useState(null),C=u.useCallback(async()=>{g(!0);try{const f=await et.listProfiles();o(f),y(null)}catch(f){y(f instanceof Error?f:new Error(String(f)))}finally{g(!1)}},[]);u.useEffect(()=>{e&&C()},[e,C,l]);const x=u.useMemo(()=>{const f=new Map;if(n!=null&&n.profiles)for(const v of n.profiles)f.set(v.id,v);return f},[n]);return{profiles:(n==null?void 0:n.profiles)??tt,fallbackId:(n==null?void 0:n.fallback_id)??null,loading:a,error:p,refresh:C,byId:x}}const je=(t,e)=>{const l=ze(t,e);return De({key:l,atomFamily:We,store:Le,emptyState:Ne})},st=(t,e)=>t.outputPreview||e||"",be=(t,e,l)=>{var C,x,f,v,m;const n=t==null?void 0:t.trim();if(!n)return null;const o=e.get(n),a=((C=o==null?void 0:o.display_name)==null?void 0:C.trim())||n,g=(f=(x=o==null?void 0:o.ui)==null?void 0:x.icon)==null?void 0:f.trim(),p=((m=(v=o==null?void 0:o.ui)==null?void 0:v.color)==null?void 0:m.trim())||void 0;return(l==null?void 0:l.compact)??!1?r.jsx("span",{"data-testid":`sub-agent-role-tag-${n}`,style:{color:p||"inherit",lineHeight:"inherit",whiteSpace:"nowrap"},children:g?`${g} ${a}`:a}):r.jsx(L,{color:p,style:{marginInlineEnd:0,flex:"0 0 auto"},"data-testid":`sub-agent-role-tag-${n}`,children:g?`${g} ${a}`:a})},rt={preview:"",connecting:!1};function lt(t,e,l){const[n,o]=u.useState(""),[a,g]=u.useState(!1),p=u.useRef(""),y=u.useRef(null);return u.useEffect(()=>{if(!l||!e)return;let C=!1;const x=new AbortController,f=Ue(t,e).outputPreview??"";p.current=f,o(f),g(!0);const v=()=>{y.current=null,C||o(p.current)},m=()=>{y.current==null&&(y.current=setTimeout(v,80))},h=j=>{p.current=(p.current+j).slice(-me),m()};return f||(async()=>{try{const j=await fe.getHistory(e);if(C||p.current)return;const P=j.messages.filter(A=>A.role==="assistant"&&A.content).map(A=>A.content).join(`
1
+ var Fe=Object.defineProperty;var Be=(t,e,l)=>e in t?Fe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:l}):t[e]=l;var pe=(t,e,l)=>Be(t,typeof e!="symbol"?e+"":e,l);import{j as r}from"./vendor-markdown-Bz_2-zkk.js";import{a as u,u as Y}from"./vendor-i18n-Dm-c3D_C.js";import{e as B,J as Te,M as Xe,N as ze,O as De,P as We,Q as Le,R as Ne,S as Ue,a as fe,T as me,I as Q,u as R,U as Ge,F as qe}from"./MetricsService-Df1w4gpU.js";import{n as L,F as I,B as _,aw as Ke,aa as Ye,T as ee,t as te,ax as Je,A as Ve,$ as ye,ae as Se,q as Qe}from"./vendor-antd-IzIw5qDM.js";import{M as Ce}from"./main-BUi2UcLi.js";import"./vendor-mermaid-Dham3vip.js";const O=class O{static getInstance(){return O.instance||(O.instance=new O),O.instance}parseUserCommand(e){B("[ToolService]",`[ToolService] parseUserCommand: Parsing content: "${e}"`);const l=e.trim();if(!l.startsWith("/"))return B("[ToolService]",'[ToolService] parseUserCommand: Content does not start with "/", not a tool command.'),null;const n=l.indexOf(" ");let o,a;if(n===-1?(o=l.substring(1),a=""):(o=l.substring(1,n),a=l.substring(n+1).trim()),o){const g={tool_name:o,user_description:a};return B("[ToolService]","[ToolService] parseUserCommand: Successfully parsed command:",g),g}return B("[ToolService]","[ToolService] parseUserCommand: Failed to parse tool name from content."),null}parseAIResponseToToolCall(e){return this.parseUserCommand(e)}async executeTool(e){B("[ToolService]","[ToolService] executeTool: Attempting to execute tool via HTTP with request:",e);try{const l=await Te.post("tools/execute",e),n=JSON.parse(l.result);if(!n||typeof n!="object"||typeof n.success!="boolean"||typeof n.result!="string")throw new Error("Tool execution returned a malformed result");const o=n;return B("[ToolService]","[ToolService] executeTool: Parsed structured result:",o),o}catch(l){throw console.error("[ToolService] executeTool: HTTP tool execution failed:",l),l instanceof Xe?new Error(`Workflow execution failed: ${l.message}`):l}}};pe(O,"instance");let Z=O;const J=new Z;class Ze{async listProfiles(){return Te.get("subagent_profiles")}}const et=new Ze,tt=[];function nt(t={}){const{enabled:e=!0,refreshKey:l}=t,[n,o]=u.useState(null),[a,g]=u.useState(!1),[p,y]=u.useState(null),C=u.useCallback(async()=>{g(!0);try{const f=await et.listProfiles();o(f),y(null)}catch(f){y(f instanceof Error?f:new Error(String(f)))}finally{g(!1)}},[]);u.useEffect(()=>{e&&C()},[e,C,l]);const x=u.useMemo(()=>{const f=new Map;if(n!=null&&n.profiles)for(const v of n.profiles)f.set(v.id,v);return f},[n]);return{profiles:(n==null?void 0:n.profiles)??tt,fallbackId:(n==null?void 0:n.fallback_id)??null,loading:a,error:p,refresh:C,byId:x}}const je=(t,e)=>{const l=ze(t,e);return De({key:l,atomFamily:We,store:Le,emptyState:Ne})},st=(t,e)=>t.outputPreview||e||"",be=(t,e,l)=>{var C,x,f,v,m;const n=t==null?void 0:t.trim();if(!n)return null;const o=e.get(n),a=((C=o==null?void 0:o.display_name)==null?void 0:C.trim())||n,g=(f=(x=o==null?void 0:o.ui)==null?void 0:x.icon)==null?void 0:f.trim(),p=((m=(v=o==null?void 0:o.ui)==null?void 0:v.color)==null?void 0:m.trim())||void 0;return(l==null?void 0:l.compact)??!1?r.jsx("span",{"data-testid":`sub-agent-role-tag-${n}`,style:{color:p||"inherit",lineHeight:"inherit",whiteSpace:"nowrap"},children:g?`${g} ${a}`:a}):r.jsx(L,{color:p,style:{marginInlineEnd:0,flex:"0 0 auto"},"data-testid":`sub-agent-role-tag-${n}`,children:g?`${g} ${a}`:a})},rt={preview:"",connecting:!1};function lt(t,e,l){const[n,o]=u.useState(""),[a,g]=u.useState(!1),p=u.useRef(""),y=u.useRef(null);return u.useEffect(()=>{if(!l||!e)return;let C=!1;const x=new AbortController,f=Ue(t,e).outputPreview??"";p.current=f,o(f),g(!0);const v=()=>{y.current=null,C||o(p.current)},m=()=>{y.current==null&&(y.current=setTimeout(v,80))},h=j=>{p.current=(p.current+j).slice(-me),m()};return f||(async()=>{try{const j=await fe.getHistory(e);if(C||p.current)return;const P=j.messages.filter(A=>A.role==="assistant"&&A.content).map(A=>A.content).join(`
2
2
 
3
- `).slice(-me);P&&(p.current=P,o(P))}catch{}})(),fe.subscribeToEvents(e,{onToken:j=>h(j)},x).catch(()=>{}).finally(()=>{C||g(!1)}),()=>{C=!0,x.abort(),y.current!=null&&(clearTimeout(y.current),y.current=null)}},[l,t,e]),l?{preview:n,connecting:a}:rt}const{Text:ot}=ee,{useToken:Ee}=te,we=u.memo(function({preview:e,maxHeight:l}){const n=u.useRef(null),{token:o}=Ee();return u.useEffect(()=>{const a=n.current;a&&(a.scrollTop=a.scrollHeight)},[e]),r.jsx("div",{ref:n,style:{maxHeight:l,overflowY:"auto",overflowX:"hidden",fontFamily:"monospace",fontSize:o.fontSizeSM,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",color:o.colorTextSecondary},children:e})}),xe=({parentSessionId:t,childSessionId:e,childTitle:l,status:n,onOpenChild:o,children:a})=>{const{t:g}=Y(),{token:p}=Ee(),[y,C]=u.useState(!1),[x,f]=u.useState(!1),v=je(t,e),h=lt(t,e,y||x).preview||v.outputPreview,j=n==="running"?"processing":n==="completed"?"success":n==="error"||n==="failed"?"error":n==="cancelled"?"warning":"default",P=n==="running"?g("chat.subAgents.statusRunning"):n==="completed"?g("chat.subAgents.statusCompleted"):n==="pending"?g("chat.subAgents.statusPending"):n==="cancelled"?g("chat.subAgents.statusCancelled"):n==="error"||n==="failed"?g("chat.subAgents.statusFailed"):n??"",A=()=>{C(!1),f(!0)},T=()=>{f(!1),o(e)},w=r.jsxs("div",{children:[r.jsx(I,{justify:"flex-end",style:{marginBottom:p.marginXS},children:r.jsx(_,{size:"small",type:"link",onClick:A,children:g("chat.subAgents.previewExpand")})}),r.jsx(we,{preview:h,maxHeight:320})]});return r.jsxs(r.Fragment,{children:[r.jsx(qe,{trigger:"hover",mouseEnterDelay:.3,open:y&&!x,onOpenChange:C,content:w,overlayInnerStyle:{width:420},children:a}),r.jsx(Ye,{open:x,mask:!1,width:640,onCancel:()=>f(!1),title:r.jsxs(I,{align:"center",gap:p.marginXS,children:[r.jsx(ot,{strong:!0,ellipsis:!0,style:{minWidth:0},children:l||g("chat.subAgents.fallbackTitle")}),n?r.jsx(L,{color:j,style:{flex:"0 0 auto"},children:P}):null]}),footer:r.jsxs(I,{justify:"flex-end",gap:p.marginSM,children:[r.jsx(_,{onClick:()=>f(!1),children:g("chat.subAgents.previewClose")}),r.jsx(_,{type:"primary",onClick:T,children:g("chat.subAgents.previewOpenSession")})]}),children:r.jsx(we,{preview:h,maxHeight:"60vh"})})]})},{Text:D}=ee,{useToken:it}=te,at=t=>{const e=(t||"").trim().toLowerCase();return e?e==="started"||e==="already_running"?"running":e==="success"||e==="done"?"completed":e==="canceled"?"cancelled":e==="queued"||e==="created"?"pending":e:"pending"},ct=u.memo(({parentSessionId:t,item:e,index:l,compact:n,isRetrying:o,isContinuing:a,isDeleting:g,subagentProfilesById:p,onOpenChild:y,onContinueChild:C,onRetryChild:x,onTogglePin:f,onDeleteChild:v})=>{const{token:m}=it(),{t:h}=Y(),j=je(t,e.childSessionId),P=st(j,e.outputPreview),A=n?{marginInlineEnd:0,flex:"0 0 auto",fontSize:10,lineHeight:"16px",paddingInline:6}:{marginInlineEnd:0,flex:"0 0 auto"},T=n?{paddingInline:0,height:22}:void 0,w=at(e.status),X=w==="running",H=o||a||g,N=["running","completed","cancelled","error","failed"].includes(w),z=b=>b==="running"?h("chat.subAgents.statusRunning"):b==="completed"?h("chat.subAgents.statusCompleted"):b==="pending"?h("chat.subAgents.statusPending"):b==="cancelled"?h("chat.subAgents.statusCancelled"):b==="error"||b==="failed"?h("chat.subAgents.statusFailed"):b,k=b=>b==="running"?m.colorPrimary:b==="completed"?m.colorSuccess:b==="error"||b==="failed"?m.colorError:b==="cancelled"?m.colorWarning:m.colorTextSecondary;return r.jsxs(I,{vertical:!0,gap:n?6:m.marginSM,className:n?void 0:"lotus-settings-list-item",style:{width:"100%",minWidth:0,padding:n?"6px 0":m.paddingSM,borderRadius:n?0:m.borderRadiusSM,borderTop:n&&l>0?`1px solid ${m.colorBorderSecondary}`:void 0,background:n?"transparent":void 0},children:[r.jsxs(I,{vertical:!0,style:{width:"100%",minWidth:0},children:[r.jsxs(I,{align:"center",gap:m.marginXS,wrap:!0,style:{width:"100%",minWidth:0},children:[r.jsx(D,{strong:!0,ellipsis:!0,style:{minWidth:0,flex:"1 1 180px",fontSize:n?13:void 0},children:(e.lifecycle==="resident"?e.residentName:null)||e.title||h("chat.subAgents.fallbackTitle")}),n?r.jsx(Q,{nowrap:!0,items:[r.jsx("span",{style:{color:k(w)},children:z(w)}),e.pinned?h("chat.subAgents.pinned"):null,e.lifecycle==="resident"?h("chat.subAgents.residentBadge"):null,be(e.subagentType,p,{compact:!0}),e.placement?r.jsx(Ce,{placement:e.placement,compact:!0}):null]}):r.jsxs(r.Fragment,{children:[r.jsx(L,{color:w==="running"?"processing":w==="completed"?"success":w==="error"||w==="failed"?"error":w==="cancelled"?"warning":"default",style:A,children:z(w)}),e.pinned?r.jsx(L,{color:"warning",style:A,children:h("chat.subAgents.pinned")}):null,e.lifecycle==="resident"?r.jsx(L,{color:"purple",style:A,children:h("chat.subAgents.residentBadge")}):null,be(e.subagentType,p),e.placement?r.jsx(Ce,{placement:e.placement,compact:!0}):null]})]}),n?r.jsx(Q,{block:!0,items:[e.childSessionId.slice(0,8),e.updatedAt,e.lastHeartbeatAt?`${h("chat.subAgents.heartbeat")}: ${e.lastHeartbeatAt}`:null,typeof e.roundCount=="number"?`${h("chat.subAgents.round")} ${e.roundCount+1}`:null]}):r.jsxs(D,{type:"secondary",style:{display:"block",minWidth:0,fontSize:12,marginTop:2},children:[e.childSessionId.slice(0,8),e.updatedAt?` • ${e.updatedAt}`:"",e.lastHeartbeatAt?` • ${h("chat.subAgents.heartbeat")}: ${e.lastHeartbeatAt}`:"",typeof e.roundCount=="number"?` • ${h("chat.subAgents.round")} ${e.roundCount+1}`:""]}),P?r.jsx(xe,{parentSessionId:t,childSessionId:e.childSessionId,childTitle:e.title,status:w,onOpenChild:y,children:r.jsx(D,{type:"secondary",style:{display:"block",minWidth:0,marginTop:n?4:m.marginXS,fontSize:n?11:13,lineHeight:n?1.35:void 0},ellipsis:!0,children:P})}):N?r.jsx(xe,{parentSessionId:t,childSessionId:e.childSessionId,childTitle:e.title,status:w,onOpenChild:y,children:r.jsx(D,{type:"secondary",italic:!0,style:{display:"block",minWidth:0,marginTop:n?4:m.marginXS,fontSize:n?11:12,lineHeight:n?1.35:void 0,opacity:.65,cursor:"pointer"},children:h("chat.subAgents.previewHint")})}):null,e.error?r.jsx(D,{type:"danger",style:{display:"block",minWidth:0,marginTop:n?4:m.marginXS,fontSize:n?11:void 0,lineHeight:n?1.35:void 0},children:e.error}):null]}),r.jsxs(I,{gap:n?4:8,wrap:!0,style:{width:"100%",minWidth:0,paddingTop:n?2:0},children:[r.jsx(_,{size:"small",type:n?"text":"default",style:T,disabled:H,onClick:()=>y(e.childSessionId),children:h("chat.subAgents.open")}),r.jsx(_,{size:"small",type:n?"text":"default",style:T,loading:a,disabled:g||o,"data-testid":`sub-agent-continue-${e.childSessionId}`,onClick:()=>C(e.childSessionId),children:h("chat.subAgents.continue")}),r.jsx(Je,{trigger:["click"],menu:{items:[{key:"regenerate",label:h("chat.actions.regenerate")},{key:"error_retry",label:h("chat.actions.retryFailed")}],onClick:({key:b})=>{x(e.childSessionId,b)}},disabled:g||X||a,children:r.jsx(_,{size:"small",type:n?"text":"default",style:T,loading:o,disabled:g||X||a,"data-testid":`sub-agent-retry-${e.childSessionId}`,children:h("chat.subAgents.retry")})}),typeof e.pinned=="boolean"?r.jsx(_,{size:"small",type:n?"text":"default",style:T,disabled:H,onClick:()=>f(e.childSessionId,e.pinned),children:e.pinned?h("chat.actions.unpin"):h("chat.actions.pin")}):null,r.jsx(_,{danger:!0,type:n?"text":"default",style:T,size:"small",loading:g,disabled:o,"data-testid":`sub-agent-delete-${e.childSessionId}`,onClick:()=>v(e.childSessionId),children:h("common.delete")})]})]})},(t,e)=>t.parentSessionId===e.parentSessionId&&t.item===e.item&&t.index===e.index&&t.compact===e.compact&&t.isRetrying===e.isRetrying&&t.isContinuing===e.isContinuing&&t.isDeleting===e.isDeleting&&t.subagentProfilesById===e.subagentProfilesById&&t.onOpenChild===e.onOpenChild&&t.onContinueChild===e.onContinueChild&&t.onRetryChild===e.onRetryChild&&t.onTogglePin===e.onTogglePin&&t.onDeleteChild===e.onDeleteChild),{Text:W}=ee,{useToken:Pe}=te,ut="chat-session-sub-agents-collapsed:",dt=3,gt=600,q=t=>{const e=(t||"").trim().toLowerCase();return e?e==="started"||e==="already_running"?"running":e==="success"||e==="done"?"completed":e==="canceled"?"cancelled":e==="queued"||e==="created"?"pending":e:"pending"},ht=(t,e)=>{if(e&&e.trim())return e;if(t.isRunning)return"running";if(t.lastRunStatus&&t.lastRunStatus.trim())return t.lastRunStatus;const l=t.messageCount??0;return l>2?"completed":(l>0,"pending")},pt=new Set(["running","pending"]),ft=t=>pt.has(q(t)),V=(t,e)=>{const l=(e.createdAt??0)-(t.createdAt??0);return l!==0?l:t.childSessionId.localeCompare(e.childSessionId)},ke=t=>`${ut}${t}`,Ae=t=>{if(typeof window>"u")return!1;try{const e=window.localStorage.getItem(ke(t));return e==="1"?!0:e==="0"?!1:null}catch{return null}},mt=(t,e)=>{if(!(typeof window>"u"))try{window.localStorage.setItem(ke(t),e?"1":"0")}catch{}},ve=(t,e)=>{var l,n,o,a;return t.childSessionId===e.childSessionId&&t.title===e.title&&t.status===e.status&&t.error===e.error&&t.lastHeartbeatAt===e.lastHeartbeatAt&&t.lastEventAt===e.lastEventAt&&t.outputPreview===e.outputPreview&&t.pinned===e.pinned&&t.updatedAt===e.updatedAt&&t.createdAt===e.createdAt&&t.isRunning===e.isRunning&&t.messageCount===e.messageCount&&t.lastRunStatus===e.lastRunStatus&&t.lastRunError===e.lastRunError&&t.subagentType===e.subagentType&&t.roundCount===e.roundCount&&t.lifecycle===e.lifecycle&&t.residentName===e.residentName&&((l=t.placement)==null?void 0:l.kind)===((n=e.placement)==null?void 0:n.kind)&&((o=t.placement)==null?void 0:o.host)===((a=e.placement)==null?void 0:a.host)},jt=({parentSessionId:t,compact:e=!1})=>{const{t:l}=Y(),{token:n}=Pe(),{message:o}=Ve.useApp(),[a,g]=u.useState(()=>Ae(t)??!1),[p,y]=u.useState(null),[C,x]=u.useState(null),[f,v]=u.useState(null),[m,h]=u.useState(!1),j=R(s=>Ge(t)(s)),P=R(s=>s.chats),A=R(s=>s.loadChatHistory),T=R(s=>s.refreshChats),w=R(s=>s.markOptimisticStart),X=R(s=>s.markRetryStart),H=R(s=>s.markSettleTimeout),N=R(s=>s.pinSession),z=R(s=>s.unpinSession),k=R(s=>s.applyChildProgress),b=R(s=>s.clearChildProgress),{byId:Re}=nt(),ne=u.useRef(new Map),se=u.useMemo(()=>Object.entries(j).map(([s,c])=>({childSessionId:s,...c})),[j]),re=u.useMemo(()=>P.filter(s=>s.kind==="child"&&s.parentSessionId===t).sort((s,c)=>(c.createdAt??0)-(s.createdAt??0)),[P,t]),$=u.useMemo(()=>{const s=new Map(se.map(i=>[i.childSessionId,i])),c=ne.current,S=[];for(const i of re){const d=s.get(i.id),E={childSessionId:i.id,title:i.title||(d==null?void 0:d.title),status:q(ht(i,d==null?void 0:d.status)),error:(d==null?void 0:d.error)||i.lastRunError,lastHeartbeatAt:d==null?void 0:d.lastHeartbeatAt,lastEventAt:d==null?void 0:d.lastEventAt,outputPreview:d==null?void 0:d.outputPreview,roundCount:d==null?void 0:d.roundCount,pinned:i.pinned,updatedAt:i.updatedAt,createdAt:i.createdAt,isRunning:i.isRunning,messageCount:i.messageCount,lastRunStatus:i.lastRunStatus,lastRunError:i.lastRunError,subagentType:i.subagentType??null,lifecycle:i.lifecycle??null,residentName:i.residentName??null,placement:i.placement??null},M=c.get(i.id);S.push(M&&ve(M,E)?M:E),s.delete(i.id)}for(const i of s.values()){const d={childSessionId:i.childSessionId,title:i.title,status:q(i.status),error:i.error,lastHeartbeatAt:i.lastHeartbeatAt,lastEventAt:i.lastEventAt,outputPreview:i.outputPreview,roundCount:i.roundCount,createdAt:Date.now()},E=c.get(i.childSessionId);S.push(E&&ve(E,d)?E:d)}return ne.current=new Map(S.map(i=>[i.childSessionId,i])),S},[re,se]),{residentItems:U,activeItems:G,completedItems:F}=u.useMemo(()=>{const s=[],c=[],S=[];for(const i of $)i.lifecycle==="resident"?s.push(i):ft(i.status)?c.push(i):S.push(i);return s.sort(V),c.sort(V),S.sort(V),{residentItems:s,activeItems:c,completedItems:S}},[$]);u.useEffect(()=>{g(Ae(t)??!1)},[t]);const _e=u.useCallback(()=>{g(s=>{const c=!s;return mt(t,c),c})},[t]),le=u.useCallback(s=>s instanceof Error&&s.message.trim()?s.message:l("chat.subAgents.runChildFailed"),[l]),oe=u.useCallback(async(s,c="regenerate")=>{y(s),k(t,s,{status:"running",error:void 0,lastEventAt:new Date().toISOString()}),X(s);try{const S=await J.executeTool({tool_name:"SubAgent",session_id:t,parameters:[{name:"action",value:"run"},{name:"child_session_id",value:s},{name:"reset_to_last_user",value:c==="error_retry"?"false":"true"}]});if(!S.success)throw new Error(S.result||"Failed to run sub-agent");k(t,s,{status:"running",error:void 0,lastEventAt:new Date().toISOString()}),await A(s,{mode:"replace"}),await T()}catch(S){H(s),k(t,s,{status:"error",error:le(S),lastEventAt:new Date().toISOString()})}finally{y(S=>S===s?null:S)}},[A,t,T,X,H,le,k]),ie=u.useCallback(async s=>{const c=typeof window<"u"?window.prompt.bind(window):null;if(!c)return;const S=c("Send a follow-up message to this sub-agent:","Continue from where you left off.");if(S===null)return;const i=S.trim();if(!i){k(t,s,{status:"error",error:"Follow-up message cannot be empty.",lastEventAt:new Date().toISOString()});return}x(s),k(t,s,{status:"running",error:void 0,lastEventAt:new Date().toISOString()}),w(s);try{const d=await J.executeTool({tool_name:"SubAgent",session_id:t,parameters:[{name:"action",value:"send_message"},{name:"child_session_id",value:s},{name:"message",value:i},{name:"auto_run",value:"true"}]});if(!d.success)throw new Error(d.result||"Follow-up failed");let E="running";try{const M=JSON.parse(d.result);M.status==="message_delivered_live"?(E="running",o.success(l("chat.subAgents.steeredLive"))):M.status==="message_queued"?(E="pending",o.info(l("chat.subAgents.queuedNextTurn"))):M.status==="pending"&&(E="pending")}catch{E="running"}k(t,s,{status:E,error:void 0,lastEventAt:new Date().toISOString()}),await T()}catch(d){H(s),k(t,s,{status:"error",error:d instanceof Error&&d.message.trim()?d.message:l("chat.subAgents.continueChildFailed"),lastEventAt:new Date().toISOString()})}finally{x(d=>d===s?null:d)}},[t,T,w,H,k,l,o]),ae=u.useCallback(async s=>{v(s);try{const c=await J.executeTool({tool_name:"SubAgent",session_id:t,parameters:[{name:"action",value:"delete"},{name:"child_session_id",value:s}]});if(!c.success)throw new Error(c.result||"Failed to delete sub-agent");b(t,s),await T()}finally{v(c=>c===s?null:c)}},[b,t,T]),Ie=u.useCallback(s=>{Ke(s),A(s)},[A]),$e=u.useCallback(s=>{ie(s)},[ie]),He=u.useCallback((s,c)=>{oe(s,c)},[oe]),Me=u.useCallback((s,c)=>{c?z(s):N(s)},[N,z]),Oe=u.useCallback(s=>{ae(s)},[ae]);if($.length===0)return null;const ce=r.jsxs(W,{strong:!0,children:[l("chat.subAgents.title")," ",r.jsx(W,{type:"secondary",children:G.length>0?l("chat.subAgents.headerCount",{active:G.length,total:$.length}):`(${$.length})`})]}),ue=r.jsx(_,{type:"text",size:"small",icon:a?r.jsx(ye,{}):r.jsx(Se,{}),onClick:_e,"data-testid":"sub-agents-toggle",style:e?{paddingInline:4}:void 0,children:l(a?"chat.subAgents.expand":"chat.subAgents.collapse")}),K=(s,c)=>r.jsx(ct,{parentSessionId:t,item:s,index:c,compact:e,isRetrying:p===s.childSessionId,isContinuing:C===s.childSessionId,isDeleting:f===s.childSessionId,subagentProfilesById:Re,onOpenChild:Ie,onContinueChild:$e,onRetryChild:He,onTogglePin:Me,onDeleteChild:Oe},s.childSessionId),de=F.length<=dt,ge=a?r.jsx(W,{type:"secondary","data-testid":"sub-agents-collapsed-hint",children:l("chat.subAgents.hiddenHint",{count:$.length})}):r.jsxs(I,{vertical:!0,gap:e?n.marginXS:n.marginSM,"data-testid":"sub-agents-list",style:{width:"100%",minWidth:0,maxHeight:`${gt}px`,overflowY:"auto",overflowX:"hidden",paddingRight:e?0:n.paddingXS},children:[U.length>0?r.jsxs(r.Fragment,{children:[r.jsx(W,{type:"secondary","data-testid":"sub-agents-resident-label",style:{fontSize:12,opacity:.75},children:l("chat.subAgents.residentGroup",{count:U.length})}),U.map((s,c)=>K(s,c))]}):null,G.length>0?G.map((s,c)=>K(s,c)):U.length===0&&F.length>0&&!de?r.jsx(W,{type:"secondary","data-testid":"sub-agents-no-active",children:l("chat.subAgents.noActive")}):null,F.length>0?de?F.map((s,c)=>K(s,c)):r.jsxs(r.Fragment,{children:[r.jsx(_,{type:"text",size:"small","data-testid":"sub-agents-completed-toggle",icon:m?r.jsx(Se,{}):r.jsx(ye,{}),onClick:()=>h(s=>!s),style:{alignSelf:"flex-start",paddingInline:4,color:n.colorTextSecondary},children:l("chat.subAgents.completedGroup",{count:F.length})}),m?F.map((s,c)=>K(s,c)):null]}):null]}),he=!a&&$.length>1?r.jsx(yt,{items:$}):null;return e?r.jsxs("section",{"data-testid":"sub-agents-panel",style:{width:"100%",minWidth:0,marginBottom:n.marginXS,overflow:"hidden"},children:[r.jsxs(I,{align:"center",justify:"space-between",gap:n.marginXS,style:{padding:`${n.paddingXXS??2}px 0 ${n.paddingXS}px`,borderBottom:`1px solid ${n.colorBorderSecondary}`},children:[r.jsx("div",{style:{flex:1,minWidth:0},children:ce}),r.jsx("div",{style:{flex:"0 0 auto"},children:ue})]}),r.jsxs("div",{style:{padding:`${n.paddingXS}px 0 0`},children:[ge,he]})]}):r.jsxs(Qe,{size:"small",className:"lotus-settings-card",style:{marginBottom:n.marginMD},"data-testid":"sub-agents-panel",title:ce,extra:ue,children:[ge,he]})},yt=({items:t})=>{const{token:e}=Pe(),{t:l}=Y(),n=t.reduce((a,g)=>{const p=q(g.status);return p==="completed"?a.completed++:p==="running"?a.running++:p==="error"||p==="failed"?a.error++:p==="cancelled"?a.cancelled++:a.pending++,a},{completed:0,running:0,error:0,pending:0,cancelled:0}),o=[];return n.completed>0&&o.push(l("chat.subAgents.summaryCompleted",{count:n.completed})),n.running>0&&o.push(l("chat.subAgents.summaryRunning",{count:n.running})),n.pending>0&&o.push(l("chat.subAgents.summaryPending",{count:n.pending})),n.cancelled>0&&o.push(`${n.cancelled} ${l("chat.subAgents.statusCancelled")}`),n.error>0&&o.push(l("chat.subAgents.summaryFailed",{count:n.error})),o.length===0?null:r.jsx(Q,{block:!0,items:o,style:{marginTop:e.marginXS}})};export{jt as SubAgentsPanel};
3
+ `).slice(-me);P&&(p.current=P,o(P))}catch{}})(),fe.subscribeToEvents(e,{onToken:j=>h(j)},x).catch(()=>{}).finally(()=>{C||g(!1)}),()=>{C=!0,x.abort(),y.current!=null&&(clearTimeout(y.current),y.current=null)}},[l,t,e]),l?{preview:n,connecting:a}:rt}const{Text:ot}=ee,{useToken:Ee}=te,we=u.memo(function({preview:e,maxHeight:l}){const n=u.useRef(null),{token:o}=Ee();return u.useEffect(()=>{const a=n.current;a&&(a.scrollTop=a.scrollHeight)},[e]),r.jsx("div",{ref:n,style:{maxHeight:l,overflowY:"auto",overflowX:"hidden",fontFamily:"monospace",fontSize:o.fontSizeSM,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",color:o.colorTextSecondary},children:e})}),xe=({parentSessionId:t,childSessionId:e,childTitle:l,status:n,onOpenChild:o,children:a})=>{const{t:g}=Y(),{token:p}=Ee(),[y,C]=u.useState(!1),[x,f]=u.useState(!1),v=je(t,e),h=lt(t,e,y||x).preview||v.outputPreview,j=n==="running"?"processing":n==="completed"?"success":n==="error"||n==="failed"?"error":n==="cancelled"?"warning":"default",P=n==="running"?g("chat.subAgents.statusRunning"):n==="completed"?g("chat.subAgents.statusCompleted"):n==="pending"?g("chat.subAgents.statusPending"):n==="cancelled"?g("chat.subAgents.statusCancelled"):n==="error"||n==="failed"?g("chat.subAgents.statusFailed"):n??"",A=()=>{C(!1),f(!0)},T=()=>{f(!1),o(e)},w=r.jsxs("div",{children:[r.jsx(I,{justify:"flex-end",style:{marginBottom:p.marginXS},children:r.jsx(_,{size:"small",type:"link",onClick:A,children:g("chat.subAgents.previewExpand")})}),r.jsx(we,{preview:h,maxHeight:320})]});return r.jsxs(r.Fragment,{children:[r.jsx(Ke,{trigger:"hover",mouseEnterDelay:.3,open:y&&!x,onOpenChange:C,content:w,overlayInnerStyle:{width:420},children:a}),r.jsx(Ye,{open:x,mask:!1,width:640,onCancel:()=>f(!1),title:r.jsxs(I,{align:"center",gap:p.marginXS,children:[r.jsx(ot,{strong:!0,ellipsis:!0,style:{minWidth:0},children:l||g("chat.subAgents.fallbackTitle")}),n?r.jsx(L,{color:j,style:{flex:"0 0 auto"},children:P}):null]}),footer:r.jsxs(I,{justify:"flex-end",gap:p.marginSM,children:[r.jsx(_,{onClick:()=>f(!1),children:g("chat.subAgents.previewClose")}),r.jsx(_,{type:"primary",onClick:T,children:g("chat.subAgents.previewOpenSession")})]}),children:r.jsx(we,{preview:h,maxHeight:"60vh"})})]})},{Text:D}=ee,{useToken:it}=te,at=t=>{const e=(t||"").trim().toLowerCase();return e?e==="started"||e==="already_running"?"running":e==="success"||e==="done"?"completed":e==="canceled"?"cancelled":e==="queued"||e==="created"?"pending":e:"pending"},ct=u.memo(({parentSessionId:t,item:e,index:l,compact:n,isRetrying:o,isContinuing:a,isDeleting:g,subagentProfilesById:p,onOpenChild:y,onContinueChild:C,onRetryChild:x,onTogglePin:f,onDeleteChild:v})=>{const{token:m}=it(),{t:h}=Y(),j=je(t,e.childSessionId),P=st(j,e.outputPreview),A=n?{marginInlineEnd:0,flex:"0 0 auto",fontSize:10,lineHeight:"16px",paddingInline:6}:{marginInlineEnd:0,flex:"0 0 auto"},T=n?{paddingInline:0,height:22}:void 0,w=at(e.status),X=w==="running",M=o||a||g,N=["running","completed","cancelled","error","failed"].includes(w),z=b=>b==="running"?h("chat.subAgents.statusRunning"):b==="completed"?h("chat.subAgents.statusCompleted"):b==="pending"?h("chat.subAgents.statusPending"):b==="cancelled"?h("chat.subAgents.statusCancelled"):b==="error"||b==="failed"?h("chat.subAgents.statusFailed"):b,k=b=>b==="running"?m.colorPrimary:b==="completed"?m.colorSuccess:b==="error"||b==="failed"?m.colorError:b==="cancelled"?m.colorWarning:m.colorTextSecondary;return r.jsxs(I,{vertical:!0,gap:n?6:m.marginSM,className:n?void 0:"lotus-settings-list-item",style:{width:"100%",minWidth:0,padding:n?"6px 0":m.paddingSM,borderRadius:n?0:m.borderRadiusSM,borderTop:n&&l>0?`1px solid ${m.colorBorderSecondary}`:void 0,background:n?"transparent":void 0},children:[r.jsxs(I,{vertical:!0,style:{width:"100%",minWidth:0},children:[r.jsxs(I,{align:"center",gap:m.marginXS,wrap:!0,style:{width:"100%",minWidth:0},children:[r.jsx(D,{strong:!0,ellipsis:!0,style:{minWidth:0,flex:"1 1 180px",fontSize:n?13:void 0},children:(e.lifecycle==="resident"?e.residentName:null)||e.title||h("chat.subAgents.fallbackTitle")}),n?r.jsx(Q,{nowrap:!0,items:[r.jsx("span",{style:{color:k(w)},children:z(w)}),e.pinned?h("chat.subAgents.pinned"):null,e.lifecycle==="resident"?h("chat.subAgents.residentBadge"):null,be(e.subagentType,p,{compact:!0}),e.placement?r.jsx(Ce,{placement:e.placement,compact:!0}):null]}):r.jsxs(r.Fragment,{children:[r.jsx(L,{color:w==="running"?"processing":w==="completed"?"success":w==="error"||w==="failed"?"error":w==="cancelled"?"warning":"default",style:A,children:z(w)}),e.pinned?r.jsx(L,{color:"warning",style:A,children:h("chat.subAgents.pinned")}):null,e.lifecycle==="resident"?r.jsx(L,{color:"purple",style:A,children:h("chat.subAgents.residentBadge")}):null,be(e.subagentType,p),e.placement?r.jsx(Ce,{placement:e.placement,compact:!0}):null]})]}),n?r.jsx(Q,{block:!0,items:[e.childSessionId.slice(0,8),e.updatedAt,e.lastHeartbeatAt?`${h("chat.subAgents.heartbeat")}: ${e.lastHeartbeatAt}`:null,typeof e.roundCount=="number"?`${h("chat.subAgents.round")} ${e.roundCount+1}`:null]}):r.jsxs(D,{type:"secondary",style:{display:"block",minWidth:0,fontSize:12,marginTop:2},children:[e.childSessionId.slice(0,8),e.updatedAt?` • ${e.updatedAt}`:"",e.lastHeartbeatAt?` • ${h("chat.subAgents.heartbeat")}: ${e.lastHeartbeatAt}`:"",typeof e.roundCount=="number"?` • ${h("chat.subAgents.round")} ${e.roundCount+1}`:""]}),P?r.jsx(xe,{parentSessionId:t,childSessionId:e.childSessionId,childTitle:e.title,status:w,onOpenChild:y,children:r.jsx(D,{type:"secondary",style:{display:"block",minWidth:0,marginTop:n?4:m.marginXS,fontSize:n?11:13,lineHeight:n?1.35:void 0},ellipsis:!0,children:P})}):N?r.jsx(xe,{parentSessionId:t,childSessionId:e.childSessionId,childTitle:e.title,status:w,onOpenChild:y,children:r.jsx(D,{type:"secondary",italic:!0,style:{display:"block",minWidth:0,marginTop:n?4:m.marginXS,fontSize:n?11:12,lineHeight:n?1.35:void 0,opacity:.65,cursor:"pointer"},children:h("chat.subAgents.previewHint")})}):null,e.error?r.jsx(D,{type:"danger",style:{display:"block",minWidth:0,marginTop:n?4:m.marginXS,fontSize:n?11:void 0,lineHeight:n?1.35:void 0},children:e.error}):null]}),r.jsxs(I,{gap:n?4:8,wrap:!0,style:{width:"100%",minWidth:0,paddingTop:n?2:0},children:[r.jsx(_,{size:"small",type:n?"text":"default",style:T,disabled:M,onClick:()=>y(e.childSessionId),children:h("chat.subAgents.open")}),r.jsx(_,{size:"small",type:n?"text":"default",style:T,loading:a,disabled:g||o,"data-testid":`sub-agent-continue-${e.childSessionId}`,onClick:()=>C(e.childSessionId),children:h("chat.subAgents.continue")}),r.jsx(Je,{trigger:["click"],menu:{items:[{key:"regenerate",label:h("chat.actions.regenerate")},{key:"error_retry",label:h("chat.actions.retryFailed")}],onClick:({key:b})=>{x(e.childSessionId,b)}},disabled:g||X||a,children:r.jsx(_,{size:"small",type:n?"text":"default",style:T,loading:o,disabled:g||X||a,"data-testid":`sub-agent-retry-${e.childSessionId}`,children:h("chat.subAgents.retry")})}),typeof e.pinned=="boolean"?r.jsx(_,{size:"small",type:n?"text":"default",style:T,disabled:M,onClick:()=>f(e.childSessionId,e.pinned),children:e.pinned?h("chat.actions.unpin"):h("chat.actions.pin")}):null,r.jsx(_,{danger:!0,type:n?"text":"default",style:T,size:"small",loading:g,disabled:o,"data-testid":`sub-agent-delete-${e.childSessionId}`,onClick:()=>v(e.childSessionId),children:h("common.delete")})]})]})},(t,e)=>t.parentSessionId===e.parentSessionId&&t.item===e.item&&t.index===e.index&&t.compact===e.compact&&t.isRetrying===e.isRetrying&&t.isContinuing===e.isContinuing&&t.isDeleting===e.isDeleting&&t.subagentProfilesById===e.subagentProfilesById&&t.onOpenChild===e.onOpenChild&&t.onContinueChild===e.onContinueChild&&t.onRetryChild===e.onRetryChild&&t.onTogglePin===e.onTogglePin&&t.onDeleteChild===e.onDeleteChild),{Text:W}=ee,{useToken:Pe}=te,ut="chat-session-sub-agents-collapsed:",dt=3,gt=600,K=t=>{const e=(t||"").trim().toLowerCase();return e?e==="started"||e==="already_running"?"running":e==="success"||e==="done"?"completed":e==="canceled"?"cancelled":e==="queued"||e==="created"?"pending":e:"pending"},ht=(t,e)=>{if(e&&e.trim())return e;if(t.isRunning)return"running";if(t.lastRunStatus&&t.lastRunStatus.trim())return t.lastRunStatus;const l=t.messageCount??0;return l>2?"completed":(l>0,"pending")},pt=new Set(["running","pending"]),ft=t=>pt.has(K(t)),V=(t,e)=>{const l=(e.createdAt??0)-(t.createdAt??0);return l!==0?l:t.childSessionId.localeCompare(e.childSessionId)},ke=t=>`${ut}${t}`,Ae=t=>{if(typeof window>"u")return!1;try{const e=window.localStorage.getItem(ke(t));return e==="1"?!0:e==="0"?!1:null}catch{return null}},mt=(t,e)=>{if(!(typeof window>"u"))try{window.localStorage.setItem(ke(t),e?"1":"0")}catch{}},ve=(t,e)=>{var l,n,o,a;return t.childSessionId===e.childSessionId&&t.title===e.title&&t.status===e.status&&t.error===e.error&&t.lastHeartbeatAt===e.lastHeartbeatAt&&t.lastEventAt===e.lastEventAt&&t.outputPreview===e.outputPreview&&t.pinned===e.pinned&&t.updatedAt===e.updatedAt&&t.createdAt===e.createdAt&&t.isRunning===e.isRunning&&t.messageCount===e.messageCount&&t.lastRunStatus===e.lastRunStatus&&t.lastRunError===e.lastRunError&&t.subagentType===e.subagentType&&t.roundCount===e.roundCount&&t.lifecycle===e.lifecycle&&t.residentName===e.residentName&&((l=t.placement)==null?void 0:l.kind)===((n=e.placement)==null?void 0:n.kind)&&((o=t.placement)==null?void 0:o.host)===((a=e.placement)==null?void 0:a.host)},Tt=({parentSessionId:t,compact:e=!1})=>{const{t:l}=Y(),{token:n}=Pe(),{message:o}=Ve.useApp(),[a,g]=u.useState(()=>Ae(t)??!1),[p,y]=u.useState(null),[C,x]=u.useState(null),[f,v]=u.useState(null),[m,h]=u.useState(!1),j=R(s=>Ge(t)(s)),P=R(s=>s.chats),A=R(s=>s.loadChatHistory),T=R(s=>s.refreshChats),w=R(s=>s.markOptimisticStart),X=R(s=>s.markRetryStart),M=R(s=>s.markSettleTimeout),N=R(s=>s.pinSession),z=R(s=>s.unpinSession),k=R(s=>s.applyChildProgress),b=R(s=>s.clearChildProgress),{byId:Re}=nt(),ne=u.useRef(new Map),se=u.useMemo(()=>Object.entries(j).map(([s,c])=>({childSessionId:s,...c})),[j]),re=u.useMemo(()=>P.filter(s=>s.kind==="child"&&s.parentSessionId===t).sort((s,c)=>(c.createdAt??0)-(s.createdAt??0)),[P,t]),$=u.useMemo(()=>{const s=new Map(se.map(i=>[i.childSessionId,i])),c=ne.current,S=[];for(const i of re){const d=s.get(i.id),E={childSessionId:i.id,title:i.title||(d==null?void 0:d.title),status:K(ht(i,d==null?void 0:d.status)),error:(d==null?void 0:d.error)||i.lastRunError,lastHeartbeatAt:d==null?void 0:d.lastHeartbeatAt,lastEventAt:d==null?void 0:d.lastEventAt,outputPreview:d==null?void 0:d.outputPreview,roundCount:d==null?void 0:d.roundCount,pinned:i.pinned,updatedAt:i.updatedAt,createdAt:i.createdAt,isRunning:i.isRunning,messageCount:i.messageCount,lastRunStatus:i.lastRunStatus,lastRunError:i.lastRunError,subagentType:i.subagentType??null,lifecycle:i.lifecycle??null,residentName:i.residentName??null,placement:i.placement??null},H=c.get(i.id);S.push(H&&ve(H,E)?H:E),s.delete(i.id)}for(const i of s.values()){const d={childSessionId:i.childSessionId,title:i.title,status:K(i.status),error:i.error,lastHeartbeatAt:i.lastHeartbeatAt,lastEventAt:i.lastEventAt,outputPreview:i.outputPreview,roundCount:i.roundCount,createdAt:Date.now()},E=c.get(i.childSessionId);S.push(E&&ve(E,d)?E:d)}return ne.current=new Map(S.map(i=>[i.childSessionId,i])),S},[re,se]),{residentItems:U,activeItems:G,completedItems:F}=u.useMemo(()=>{const s=[],c=[],S=[];for(const i of $)i.lifecycle==="resident"?s.push(i):ft(i.status)?c.push(i):S.push(i);return s.sort(V),c.sort(V),S.sort(V),{residentItems:s,activeItems:c,completedItems:S}},[$]);u.useEffect(()=>{g(Ae(t)??!1)},[t]);const _e=u.useCallback(()=>{g(s=>{const c=!s;return mt(t,c),c})},[t]),le=u.useCallback(s=>s instanceof Error&&s.message.trim()?s.message:l("chat.subAgents.runChildFailed"),[l]),oe=u.useCallback(async(s,c="regenerate")=>{y(s),k(t,s,{status:"running",error:void 0,lastEventAt:new Date().toISOString()}),X(s);try{const S=await J.executeTool({tool_name:"SubAgent",session_id:t,parameters:[{name:"action",value:"run"},{name:"child_session_id",value:s},{name:"reset_to_last_user",value:c==="error_retry"?"false":"true"}]});if(!S.success)throw new Error(S.result||"Failed to run sub-agent");k(t,s,{status:"running",error:void 0,lastEventAt:new Date().toISOString()}),await A(s,{mode:"replace"}),await T()}catch(S){M(s),k(t,s,{status:"error",error:le(S),lastEventAt:new Date().toISOString()})}finally{y(S=>S===s?null:S)}},[A,t,T,X,M,le,k]),ie=u.useCallback(async s=>{const c=typeof window<"u"?window.prompt.bind(window):null;if(!c)return;const S=c("Send a follow-up message to this sub-agent:","Continue from where you left off.");if(S===null)return;const i=S.trim();if(!i){k(t,s,{status:"error",error:"Follow-up message cannot be empty.",lastEventAt:new Date().toISOString()});return}x(s),k(t,s,{status:"running",error:void 0,lastEventAt:new Date().toISOString()}),w(s);try{const d=await J.executeTool({tool_name:"SubAgent",session_id:t,parameters:[{name:"action",value:"send_message"},{name:"child_session_id",value:s},{name:"message",value:i},{name:"auto_run",value:"true"}]});if(!d.success)throw new Error(d.result||"Follow-up failed");let E="running";try{const H=JSON.parse(d.result);H.status==="message_delivered_live"?(E="running",o.success(l("chat.subAgents.steeredLive"))):H.status==="message_queued"?(E="pending",o.info(l("chat.subAgents.queuedNextTurn"))):H.status==="pending"&&(E="pending")}catch{E="running"}k(t,s,{status:E,error:void 0,lastEventAt:new Date().toISOString()}),await T()}catch(d){M(s),k(t,s,{status:"error",error:d instanceof Error&&d.message.trim()?d.message:l("chat.subAgents.continueChildFailed"),lastEventAt:new Date().toISOString()})}finally{x(d=>d===s?null:d)}},[t,T,w,M,k,l,o]),ae=u.useCallback(async s=>{v(s);try{const c=await J.executeTool({tool_name:"SubAgent",session_id:t,parameters:[{name:"action",value:"delete"},{name:"child_session_id",value:s}]});if(!c.success)throw new Error(c.result||"Failed to delete sub-agent");b(t,s),await T()}finally{v(c=>c===s?null:c)}},[b,t,T]),Ie=u.useCallback(s=>{qe(s),A(s)},[A]),$e=u.useCallback(s=>{ie(s)},[ie]),Me=u.useCallback((s,c)=>{oe(s,c)},[oe]),He=u.useCallback((s,c)=>{c?z(s):N(s)},[N,z]),Oe=u.useCallback(s=>{ae(s)},[ae]);if($.length===0)return null;const ce=r.jsxs(W,{strong:!0,children:[l("chat.subAgents.title")," ",r.jsx(W,{type:"secondary",children:G.length>0?l("chat.subAgents.headerCount",{active:G.length,total:$.length}):`(${$.length})`})]}),ue=r.jsx(_,{type:"text",size:"small",icon:a?r.jsx(ye,{}):r.jsx(Se,{}),onClick:_e,"data-testid":"sub-agents-toggle",style:e?{paddingInline:4}:void 0,children:l(a?"chat.subAgents.expand":"chat.subAgents.collapse")}),q=(s,c)=>r.jsx(ct,{parentSessionId:t,item:s,index:c,compact:e,isRetrying:p===s.childSessionId,isContinuing:C===s.childSessionId,isDeleting:f===s.childSessionId,subagentProfilesById:Re,onOpenChild:Ie,onContinueChild:$e,onRetryChild:Me,onTogglePin:He,onDeleteChild:Oe},s.childSessionId),de=F.length<=dt,ge=a?r.jsx(W,{type:"secondary","data-testid":"sub-agents-collapsed-hint",children:l("chat.subAgents.hiddenHint",{count:$.length})}):r.jsxs(I,{vertical:!0,gap:e?n.marginXS:n.marginSM,"data-testid":"sub-agents-list",style:{width:"100%",minWidth:0,maxHeight:`${gt}px`,overflowY:"auto",overflowX:"hidden",paddingRight:e?0:n.paddingXS},children:[U.length>0?r.jsxs(r.Fragment,{children:[r.jsx(W,{type:"secondary","data-testid":"sub-agents-resident-label",style:{fontSize:12,opacity:.75},children:l("chat.subAgents.residentGroup",{count:U.length})}),U.map((s,c)=>q(s,c))]}):null,G.length>0?G.map((s,c)=>q(s,c)):U.length===0&&F.length>0&&!de?r.jsx(W,{type:"secondary","data-testid":"sub-agents-no-active",children:l("chat.subAgents.noActive")}):null,F.length>0?de?F.map((s,c)=>q(s,c)):r.jsxs(r.Fragment,{children:[r.jsx(_,{type:"text",size:"small","data-testid":"sub-agents-completed-toggle",icon:m?r.jsx(Se,{}):r.jsx(ye,{}),onClick:()=>h(s=>!s),style:{alignSelf:"flex-start",paddingInline:4,color:n.colorTextSecondary},children:l("chat.subAgents.completedGroup",{count:F.length})}),m?F.map((s,c)=>q(s,c)):null]}):null]}),he=!a&&$.length>1?r.jsx(yt,{items:$}):null;return e?r.jsxs("section",{"data-testid":"sub-agents-panel",style:{width:"100%",minWidth:0,marginBottom:n.marginXS,overflow:"hidden"},children:[r.jsxs(I,{align:"center",justify:"space-between",gap:n.marginXS,style:{padding:`${n.paddingXXS??2}px 0 ${n.paddingXS}px`,borderBottom:`1px solid ${n.colorBorderSecondary}`},children:[r.jsx("div",{style:{flex:1,minWidth:0},children:ce}),r.jsx("div",{style:{flex:"0 0 auto"},children:ue})]}),r.jsxs("div",{style:{padding:`${n.paddingXS}px 0 0`},children:[ge,he]})]}):r.jsxs(Qe,{size:"small",className:"lotus-settings-card",style:{marginBottom:n.marginMD},"data-testid":"sub-agents-panel",title:ce,extra:ue,children:[ge,he]})},yt=({items:t})=>{const{token:e}=Pe(),{t:l}=Y(),n=t.reduce((a,g)=>{const p=K(g.status);return p==="completed"?a.completed++:p==="running"?a.running++:p==="error"||p==="failed"?a.error++:p==="cancelled"?a.cancelled++:a.pending++,a},{completed:0,running:0,error:0,pending:0,cancelled:0}),o=[];return n.completed>0&&o.push(l("chat.subAgents.summaryCompleted",{count:n.completed})),n.running>0&&o.push(l("chat.subAgents.summaryRunning",{count:n.running})),n.pending>0&&o.push(l("chat.subAgents.summaryPending",{count:n.pending})),n.cancelled>0&&o.push(`${n.cancelled} ${l("chat.subAgents.statusCancelled")}`),n.error>0&&o.push(l("chat.subAgents.summaryFailed",{count:n.error})),o.length===0?null:r.jsx(Q,{block:!0,items:o,style:{marginTop:e.marginXS}})};export{Tt as SubAgentsPanel};
@@ -0,0 +1 @@
1
+ import{j as t,M as E,r as F,h as H}from"./vendor-markdown-Bz_2-zkk.js";import{i as I,u as R,a as p}from"./vendor-i18n-Dm-c3D_C.js";import{j as y,B as L,q as X,T,v as A,a5 as Y,n as f,a6 as q,a7 as O,a8 as J,a9 as K,aa as N,E as Q,a2 as U,t as V}from"./vendor-antd-IzIw5qDM.js";import{o as W,u as z,g as Z}from"./MetricsService-Df1w4gpU.js";import"./vendor-mermaid-Dham3vip.js";import"./main-BUi2UcLi.js";const _=({buttons:r,className:e,style:g,size:l="middle",align:a="right"})=>{const h={className:e,style:{width:"100%",justifyContent:a==="left"?"flex-start":a==="center"?"center":"flex-end",...g}};return t.jsx(y,{...h,children:r.map(n=>t.jsx(L,{type:n.type||"default",disabled:n.disabled,loading:n.loading,danger:n.danger,onClick:n.onClick,size:l,icon:n.icon,children:n.text},n.key))})},k=(r,e)=>({key:"cancel",text:e||I.t("common.cancel"),type:"default",onClick:r}),ee=(r,e)=>({key:"ok",text:(e==null?void 0:e.text)||I.t("common.ok"),type:"primary",disabled:e==null?void 0:e.disabled,loading:e==null?void 0:e.loading,onClick:r}),{Text:b,Paragraph:te}=T,re=({content:r,token:e,showGradient:g,onClick:l})=>t.jsx(X,{size:"small",style:{marginLeft:e.marginLG,marginTop:e.marginXS,backgroundColor:e.colorBgLayout,borderColor:e.colorBorderSecondary},styles:{body:{padding:e.paddingMD}},onClick:l,children:t.jsxs("div",{style:{maxHeight:"60vh",overflowY:"auto",position:"relative",paddingRight:e.paddingXS},children:[t.jsx(E,{remarkPlugins:[F],components:{p:({children:a})=>t.jsx(te,{style:{marginBottom:e.marginSM},children:a}),ol:({children:a})=>t.jsx("ol",{style:{marginBottom:e.marginSM,paddingLeft:e.paddingLG},children:a}),ul:({children:a})=>t.jsx("ul",{style:{marginBottom:e.marginSM,paddingLeft:e.paddingLG},children:a}),li:({children:a})=>t.jsx("li",{style:{marginBottom:e.marginXS},children:a}),h1:({children:a})=>t.jsx(b,{strong:!0,style:{fontSize:e.fontSizeHeading3,marginBottom:e.marginSM,display:"block"},children:a}),h2:({children:a})=>t.jsx(b,{strong:!0,style:{fontSize:e.fontSizeHeading4,marginBottom:e.marginSM,display:"block"},children:a}),code:({inline:a,className:h,children:n,...i})=>{const o=/language-(\w+)/.exec(h||"");return a?t.jsx("code",{className:h,style:{backgroundColor:e.colorFillTertiary,padding:"0 4px",borderRadius:e.borderRadiusSM,fontSize:e.fontSizeSM},...i,children:n}):t.jsx(H,{style:W,language:(o==null?void 0:o[1])||"text",PreTag:"div",wrapLongLines:!0,children:String(n).replace(/\n$/,"")})}},children:r||"No content available."}),g?t.jsx("div",{style:{position:"sticky",bottom:0,height:48,background:`linear-gradient(180deg, transparent, ${e.colorBgLayout})`,pointerEvents:"none",marginTop:-48}}):null]})}),{Text:v,Paragraph:se}=T,ae=({prompt:r,token:e,isSelected:g,isExpanded:l,onSelect:a,onToggleExpand:h,onCopy:n})=>{const{t:i}=R(),o=r.content||"",{nonEmptyLineCount:j,wordCount:u,characterCount:P,showGradient:x}=p.useMemo(()=>{const S=(o?o.split(/\r?\n/):[]).filter(w=>w.trim().length>0).length,C=o.trim()?o.trim().split(/\s+/).filter(Boolean).length:0,m=o.length;return{nonEmptyLineCount:S,wordCount:C,characterCount:m,showGradient:!l&&m>600}},[o,l]);return t.jsx(A.Item,{style:{cursor:"pointer",padding:e.paddingMD,borderRadius:e.borderRadius,border:g?`2px solid ${e.colorPrimary}`:`1px solid ${e.colorBorderSecondary}`,marginBottom:e.marginXS,backgroundColor:g?e.colorPrimaryBg:e.colorBgContainer,transition:"all 0.2s ease"},onClick:()=>a(r.id),children:t.jsxs(y,{direction:"vertical",style:{width:"100%"},size:e.marginSM,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",width:"100%",gap:e.marginSM},children:[t.jsxs(y,{align:"start",children:[t.jsx(Y,{checked:g,onChange:()=>a(r.id),onClick:c=>c.stopPropagation()}),t.jsxs("div",{children:[t.jsx(v,{strong:!0,children:r.name||r.id}),t.jsx("div",{children:t.jsx(v,{code:!0,style:{fontSize:e.fontSizeSM,color:e.colorTextSecondary},children:r.id})})]}),r.isDefault?t.jsx(f,{color:"warning",children:i("chat.systemPromptSelector.defaultTag")}):null]}),t.jsxs(y,{size:"small",children:[t.jsx(L,{type:"text",size:"small",icon:l?t.jsx(q,{}):t.jsx(O,{}),onClick:c=>{c.stopPropagation(),h(r.id)},children:i(l?"chat.systemPromptSelector.hide":"chat.systemPromptSelector.preview")}),t.jsx(L,{type:"text",size:"small",icon:t.jsx(J,{}),onClick:c=>n(c,r),children:i("chat.systemPromptSelector.copy")})]})]}),r.description?t.jsx(v,{type:"secondary",style:{marginLeft:e.marginLG,fontSize:e.fontSizeSM},children:r.description}):null,t.jsxs(y,{size:"small",wrap:!0,style:{marginLeft:e.marginLG},children:[t.jsx(f,{color:"processing",children:i("chat.systemPromptSelector.lines",{count:j})}),t.jsx(f,{color:"purple",children:i("chat.systemPromptSelector.words",{count:u})}),t.jsx(f,{color:"success",children:i("chat.systemPromptSelector.chars",{count:P})})]}),l?t.jsx(re,{content:o,token:e,showGradient:x,onClick:c=>c.stopPropagation()}):t.jsx(se,{type:"secondary",ellipsis:{rows:3},style:{marginLeft:e.marginLG,marginBottom:0,color:e.colorTextSecondary},children:o||i("chat.systemPromptSelector.noContent")})]})},r.id)},{Text:ne}=T,{useToken:ie}=V,he=({open:r,onClose:e,onSelect:g,prompts:l,title:a,showCancelButton:h=!0})=>{const{t:n}=R(),{token:i}=ie(),[o,j]=K.useMessage(),u=z(s=>s.lastSelectedPromptId),P=z(s=>s.setLastSelectedPromptId),[x,c]=p.useState(null),[S,C]=p.useState(null),m=p.useMemo(()=>l.filter(s=>s.id&&s.id.trim()!==""),[l]),w=async(s,d)=>{s.stopPropagation();const M=d.content??"";try{await Z(M),o.success(n("success.promptCopied",{name:d.name}))}catch(D){console.error("[SystemPromptSelector] Failed to copy prompt:",D),o.error(n("error.copyPromptFailed"))}},G=a??n("chat.prompt.selectorTitle");p.useEffect(()=>{if(r){const s=m.find(M=>M.isDefault),d=u||(s==null?void 0:s.id)||(m.length>0?m[0].id:null);c(d)}},[r,u,m.length]);const $=s=>{c(s.id),P(s.id),g(s),e()},B=()=>{e()};return t.jsxs(t.Fragment,{children:[j,t.jsxs(N,{title:t.jsxs(y,{children:[t.jsx(U,{}),G]}),open:r,onCancel:B,width:700,footer:t.jsx(_,{buttons:[...h?[k(B)]:[],ee(()=>{const s=m.find(d=>d.id===x);s&&$(s)},{text:n("chat.prompt.createButton"),disabled:!x})]}),styles:{body:{maxHeight:"70vh",overflowY:"auto",padding:i.paddingMD}},children:[t.jsx("div",{style:{marginBottom:i.marginMD},children:t.jsx(ne,{type:"secondary",style:{fontSize:i.fontSizeSM},children:n("chat.prompt.helperText")})}),m.length===0?t.jsx(Q,{description:n("chat.prompt.emptyDescription"),style:{margin:i.marginLG}}):t.jsx("div",{children:m.map(s=>t.jsx(ae,{prompt:s,token:i,isSelected:x===s.id,isExpanded:S===s.id,onSelect:d=>c(d),onToggleExpand:d=>C(S===d?null:d),onCopy:w},s.id))})]})]})};export{he as default};