@tickernelz/wardmote-ui 2026.1114.2 → 2026.1114.3

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 (140) hide show
  1. package/dist/assets/{ActiveAgentsPanel-Budj8e9v.js → ActiveAgentsPanel-CF0fwsze.js} +1 -1
  2. package/dist/assets/{AdapterManager-DhiW44Eo.js → AdapterManager-DUXWwNxv.js} +1 -1
  3. package/dist/assets/{AdvancedToolsRoute-CICI1XRd.js → AdvancedToolsRoute-BamlkE3p.js} +1 -1
  4. package/dist/assets/{AgentActionButtons-DIhpv51Y.js → AgentActionButtons-CPIhsP04.js} +1 -1
  5. package/dist/assets/{AgentBubbleActionRow-DIr3TdR9.js → AgentBubbleActionRow-BUAUmJKa.js} +1 -1
  6. package/dist/assets/{AgentChat-CeuGtMXr.js → AgentChat-BAn_ghsu.js} +1 -1
  7. package/dist/assets/{AgentChats-CmDtTrMa.js → AgentChats-f73hodzr.js} +1 -1
  8. package/dist/assets/{AgentDefaults-DpYaMGkf.js → AgentDefaults-BL1XYvEo.js} +1 -1
  9. package/dist/assets/{AgentDetail-DFTeFc4-.js → AgentDetail-DthxFfuB.js} +1 -1
  10. package/dist/assets/{AgentTodoCard-DRXZ7hmU.js → AgentTodoCard-BvgkWD0T.js} +1 -1
  11. package/dist/assets/{Agents-CClUUMUq.js → Agents-D5qI6yZZ.js} +3 -3
  12. package/dist/assets/{AppDetail-DfHLFOtj.js → AppDetail-B6PtMl8J.js} +1 -1
  13. package/dist/assets/{AppNotConnected-CcmXbFtD.js → AppNotConnected-C_tGn786.js} +1 -1
  14. package/dist/assets/{ApprovalCard-uT_9D_uH.js → ApprovalCard-DrfZAdGQ.js} +1 -1
  15. package/dist/assets/{ApprovalDetail-CE41WFbd.js → ApprovalDetail-sfPpfdXc.js} +1 -1
  16. package/dist/assets/{ApprovalPayload-_zU9bukt.js → ApprovalPayload-C4F3ItGH.js} +1 -1
  17. package/dist/assets/{Approvals-BXrjqpKc.js → Approvals-DZoMl7_m.js} +1 -1
  18. package/dist/assets/{AppsConnect-DH7aSjtS.js → AppsConnect-D8Gu187f.js} +1 -1
  19. package/dist/assets/{AppsReview-C0Y3SxmZ.js → AppsReview-DokFETm0.js} +1 -1
  20. package/dist/assets/{ArtifactCard-DKUUBZ0K.js → ArtifactCard-BTf2-JIV.js} +1 -1
  21. package/dist/assets/{Artifacts-Bsv5m0aU.js → Artifacts-CK8FaygC.js} +1 -1
  22. package/dist/assets/{AssistantConnection-Dm2PaSeU.js → AssistantConnection-BlKC7jk0.js} +1 -1
  23. package/dist/assets/{AttentionInteractionResolver-CBjNuhYo.js → AttentionInteractionResolver-C2iz6oqT.js} +1 -1
  24. package/dist/assets/{AuditHub-DbUni0O_.js → AuditHub-DMhunMn8.js} +1 -1
  25. package/dist/assets/{BoardChat-CgzCuFIL.js → BoardChat-C4W8JLKB.js} +1 -1
  26. package/dist/assets/{BootstrapSetupUxLab-D-niQCV5.js → BootstrapSetupUxLab-D58OwniR.js} +1 -1
  27. package/dist/assets/{Browse-0bmB5mqw.js → Browse-BDjohBak.js} +1 -1
  28. package/dist/assets/{BudgetPolicyCard-CqFUHqOj.js → BudgetPolicyCard-DfAAgk9Z.js} +1 -1
  29. package/dist/assets/{CaseDetail-DakrB2jI.js → CaseDetail-CL0FC5sG.js} +1 -1
  30. package/dist/assets/{Cases-DXbr4HJt.js → Cases-C-7dXrEt.js} +1 -1
  31. package/dist/assets/{ChatEndpointDetail-BdDKo-Gq.js → ChatEndpointDetail-C-IYAYG8.js} +1 -1
  32. package/dist/assets/{ChatEndpointSetup-BX3iDH7N.js → ChatEndpointSetup-CM3QixMj.js} +1 -1
  33. package/dist/assets/{ChoiceControls-Bu-fd6qI.js → ChoiceControls-3Qpci4yE.js} +1 -1
  34. package/dist/assets/{Companies-FcUNLIkt.js → Companies-97toQ8Cw.js} +1 -1
  35. package/dist/assets/{CompanyAccess-BUcTNg7_.js → CompanyAccess-CKhS1BaS.js} +1 -1
  36. package/dist/assets/{CompanyActivity-ScpRBz1G.js → CompanyActivity-DzNrAyAb.js} +1 -1
  37. package/dist/assets/{CompanyConnections-DMEwbZv7.js → CompanyConnections-ORCH4i3U.js} +1 -1
  38. package/dist/assets/{CompanyEnvironments-EqXhVruZ.js → CompanyEnvironments-DphURbtb.js} +1 -1
  39. package/dist/assets/{CompanyExport-DQ9ffuua.js → CompanyExport-XeVCUcK3.js} +1 -1
  40. package/dist/assets/{CompanyImport-BhuZu4oc.js → CompanyImport-DPKpUaRa.js} +1 -1
  41. package/dist/assets/{CompanySettings-BSkg4ahA.js → CompanySettings-4JQpzuS1.js} +1 -1
  42. package/dist/assets/{CompanySettingsPluginPage-BzZkZqh-.js → CompanySettingsPluginPage-cVvXh0_G.js} +1 -1
  43. package/dist/assets/{CompanySkills-BbA4RKIw.js → CompanySkills-BA_9Ztwj.js} +1 -1
  44. package/dist/assets/{ComposerAddMenu-D9z2INup.js → ComposerAddMenu-DNp4ecG8.js} +1 -1
  45. package/dist/assets/{ConfigureBuiltInAgentModal-BUJPbmWc.js → ConfigureBuiltInAgentModal-CQCHDkl4.js} +1 -1
  46. package/dist/assets/{ConnectionSetupFlow-DKjP5RBZ.js → ConnectionSetupFlow-BaarToKu.js} +1 -1
  47. package/dist/assets/{CopyableGatewayUrl-BZyE_jT9.js → CopyableGatewayUrl-DxQsV7Hr.js} +1 -1
  48. package/dist/assets/{Dashboard--lTwxjV-.js → Dashboard--iaPJqJp.js} +1 -1
  49. package/dist/assets/{DashboardLive-BYyTgF5d.js → DashboardLive-4rGeotay.js} +1 -1
  50. package/dist/assets/{DecisionDateChips-vXwAFdua.js → DecisionDateChips-CJOLtNrJ.js} +1 -1
  51. package/dist/assets/{DecisionModelSettings-NrNERkaW.js → DecisionModelSettings-D-OxKIGP.js} +1 -1
  52. package/dist/assets/{DecisionQueuePage-BaaKuZBi.js → DecisionQueuePage-D-kNFav_.js} +1 -1
  53. package/dist/assets/{DesignGuide-DS6MuXWY.js → DesignGuide-D7486q4b.js} +1 -1
  54. package/dist/assets/{DocumentFrameHeader-DTSqcw4Q.js → DocumentFrameHeader-B61HhahB.js} +1 -1
  55. package/dist/assets/{EmailEndpointSetup-CJFYu2G0.js → EmailEndpointSetup-6OHb9B4q.js} +1 -1
  56. package/dist/assets/{ExecutionWorkspaceDetail-CuD5xWOB.js → ExecutionWorkspaceDetail-BGV-9D5Y.js} +1 -1
  57. package/dist/assets/{FolderControls-B7TWghGc.js → FolderControls-L2RzbfdQ.js} +1 -1
  58. package/dist/assets/{GatewayDetail-xNVOxSIs.js → GatewayDetail-CdXNQ9gD.js} +1 -1
  59. package/dist/assets/{GatewaysList-DsSKLm1h.js → GatewaysList-B0Jq1IRC.js} +1 -1
  60. package/dist/assets/{GoalDetail-oN5pyUUY.js → GoalDetail-D2VhPtvw.js} +1 -1
  61. package/dist/assets/{GoalTree-DaFizciF.js → GoalTree-kFpgH4dA.js} +1 -1
  62. package/dist/assets/{Goals-xgGKfQZi.js → Goals-B-_gq_Qu.js} +1 -1
  63. package/dist/assets/{ImageGalleryModal-CjHED0Lb.js → ImageGalleryModal-DzKBMOnu.js} +1 -1
  64. package/dist/assets/{Inbox-wHhHozfr.js → Inbox-zllmqRcB.js} +1 -1
  65. package/dist/assets/{InstanceAdvanced-Bdf2a4c_.js → InstanceAdvanced-B7tDfjwG.js} +1 -1
  66. package/dist/assets/{InviteLanding-McBYpNeW.js → InviteLanding-brwa_8NC.js} +1 -1
  67. package/dist/assets/{IssueChatLongThreadPerf-DD3RLbBo.js → IssueChatLongThreadPerf-D0HJe6IV.js} +1 -1
  68. package/dist/assets/{IssueChatThread-BN-_8hT8.js → IssueChatThread-CMXzuvrF.js} +1 -1
  69. package/dist/assets/{IssueDetail-CsaD311l.js → IssueDetail-DGdg-mB8.js} +1 -1
  70. package/dist/assets/{IssueDocumentAnnotations-BVdH4RTa.js → IssueDocumentAnnotations-BK-LgExc.js} +1 -1
  71. package/dist/assets/{IssueOutputSection-CDIMRaF0.js → IssueOutputSection-aSyiE1pg.js} +1 -1
  72. package/dist/assets/{IssueRecoveryActionCard-C9qJAHes.js → IssueRecoveryActionCard-vAuL_OEC.js} +1 -1
  73. package/dist/assets/{IssueThreadInteractionCard-BbigJB2U.js → IssueThreadInteractionCard-wFidFTIh.js} +1 -1
  74. package/dist/assets/{Issues-BWoc80Y9.js → Issues-CsmM33z_.js} +1 -1
  75. package/dist/assets/{LiveNowTodoLine-B9oTH2L0.js → LiveNowTodoLine-CP32NNp_.js} +1 -1
  76. package/dist/assets/{ManagedAiConnectionDetails-B0aWUPkf.js → ManagedAiConnectionDetails-Ba0awZ-O.js} +1 -1
  77. package/dist/assets/{McpConnect-Dzf7W2K6.js → McpConnect-CYLP1yLX.js} +1 -1
  78. package/dist/assets/{MembershipAction-oiLtxQm3.js → MembershipAction-CKs7Ua9x.js} +1 -1
  79. package/dist/assets/{ModelsAndProviders-BEb4Z38S.js → ModelsAndProviders-gaR7HDQm.js} +1 -1
  80. package/dist/assets/{NewAgent-C3MxIRJj.js → NewAgent-DBQzvxIr.js} +1 -1
  81. package/dist/assets/{OmpAllSettings-DBtL1qDL.js → OmpAllSettings-B_Knr51Z.js} +1 -1
  82. package/dist/assets/{PipelineSettings-BcAtsehE.js → PipelineSettings-Dl-94FB5.js} +1 -1
  83. package/dist/assets/{Pipelines-CkiYUQS-.js → Pipelines-CY9hGe0h.js} +1 -1
  84. package/dist/assets/{PixelsOffice-BSlctoug.js → PixelsOffice-BgyGZsiV.js} +1 -1
  85. package/dist/assets/{PluginPage-C6Qnf9ka.js → PluginPage-CMA4Ei50.js} +1 -1
  86. package/dist/assets/{PluginSettings-Do37r6Zu.js → PluginSettings-Cm4H1JRT.js} +1 -1
  87. package/dist/assets/{ProfileDetailRoute-DRFQNId6.js → ProfileDetailRoute-BEBctbC6.js} +1 -1
  88. package/dist/assets/{ProfileSettings-BMwLBQDB.js → ProfileSettings-Djo7BLIj.js} +1 -1
  89. package/dist/assets/{ProfileWizardRoute-XnnvzH9S.js → ProfileWizardRoute-DxLujEtD.js} +1 -1
  90. package/dist/assets/{ProjectDetail-BW6Lr4Iq.js → ProjectDetail-CmmdvUHn.js} +1 -1
  91. package/dist/assets/{ProjectWorkspaceDetail-DR4JCa1b.js → ProjectWorkspaceDetail-BsA0hJ-k.js} +1 -1
  92. package/dist/assets/{ProjectWorkspacesContent-CadPZn0k.js → ProjectWorkspacesContent-BNNI_WAk.js} +1 -1
  93. package/dist/assets/{Projects-DLBFbxcj.js → Projects-BTAauZr0.js} +1 -1
  94. package/dist/assets/{PublicIssueSharePage-C9yRZOdP.js → PublicIssueSharePage-DdPjfmD9.js} +1 -1
  95. package/dist/assets/{ReviewQueueCard-CIkiY-Lm.js → ReviewQueueCard-BC6VY8Bc.js} +1 -1
  96. package/dist/assets/{RichWorkProductCard-JGHGU_RI.js → RichWorkProductCard-ClpMt_Bh.js} +1 -1
  97. package/dist/assets/{RoutineDetail-izWzADvA.js → RoutineDetail-BT6_GKnC.js} +1 -1
  98. package/dist/assets/{RoutineRunVariablesDialog-DiT_o5Dm.js → RoutineRunVariablesDialog-D_Mls1sV.js} +1 -1
  99. package/dist/assets/{Routines-CHtabiYj.js → Routines-4LevOfvV.js} +1 -1
  100. package/dist/assets/{ScrollToBottom-pyHLjOjY.js → ScrollToBottom-jItsgDR8.js} +1 -1
  101. package/dist/assets/{Search-yNNB6kys.js → Search-bmcm0_m_.js} +1 -1
  102. package/dist/assets/{Secrets-BOyOk5BF.js → Secrets-DfR1fBAZ.js} +1 -1
  103. package/dist/assets/{SkillSourceTree-M58QwBFF.js → SkillSourceTree--FWKWyF3.js} +1 -1
  104. package/dist/assets/{SkillSources-Cw4PU-Bz.js → SkillSources-jUDjqy5i.js} +1 -1
  105. package/dist/assets/{SkillStudio-Cj_M3ZJa.js → SkillStudio-BsqtUnzF.js} +1 -1
  106. package/dist/assets/{SourceTrustBadge-BZBQe5No.js → SourceTrustBadge-CfBrvKL3.js} +1 -1
  107. package/dist/assets/{StatusCards-DaJdQUN5.js → StatusCards-Dt3zorUZ.js} +1 -1
  108. package/dist/assets/{SummarySlotCard-DlSmN6PL.js → SummarySlotCard-D1C0qH2L.js} +1 -1
  109. package/dist/assets/{TaskChatLab-CU5eA7nX.js → TaskChatLab-B0coUvdp.js} +1 -1
  110. package/dist/assets/{TaskChatMarker-wBVUFL3u.js → TaskChatMarker-C40twVjh.js} +1 -1
  111. package/dist/assets/{TaskChatProtocolCard-D-Dwy2EL.js → TaskChatProtocolCard--bi_tc6i.js} +1 -1
  112. package/dist/assets/{TaskChatThreadView-Crlf9I05.js → TaskChatThreadView-DkzFDrLW.js} +1 -1
  113. package/dist/assets/{TaskDetailRelationsPanel-CkktN1EC.js → TaskDetailRelationsPanel-DZGkinoJ.js} +1 -1
  114. package/dist/assets/{TaskTreeControls-B_ulMOi1.js → TaskTreeControls-DznugVpi.js} +1 -1
  115. package/dist/assets/Terminal-NjEb5-2b.js +1 -0
  116. package/dist/assets/TerminalView-DZxK2Ei5.js +58 -0
  117. package/dist/assets/{TrustPresetSection-DTc1Rj4q.js → TrustPresetSection-CjNwNBo3.js} +1 -1
  118. package/dist/assets/{UserProfile-C6q55R0Q.js → UserProfile-Dujv3qdz.js} +1 -1
  119. package/dist/assets/{WhatNeedsMe-1igJA4gL.js → WhatNeedsMe-C9P2EsqQ.js} +1 -1
  120. package/dist/assets/{Workspaces-rtQKliW0.js → Workspaces-BTgSx9nA.js} +1 -1
  121. package/dist/assets/{connection-owner-CZwxTEuM.js → connection-owner-DL4yKhSt.js} +1 -1
  122. package/dist/assets/dist-ypeTPGg_.js +1 -0
  123. package/dist/assets/dropdown-menu-DEO3mF_E.js +1 -0
  124. package/dist/assets/{environment-variables-editor-CCxeFKKk.js → environment-variables-editor-0qgSPgNN.js} +1 -1
  125. package/dist/assets/{index-DDoARkPG.js → index-3AxqhPET.js} +4 -4
  126. package/dist/assets/index-B5bd7Tk6.css +2 -0
  127. package/dist/assets/{issue-properties-lmRBaUTG.js → issue-properties-B1cYnBDU.js} +1 -1
  128. package/dist/assets/{issue-workspace-selection-4JI2Uh9p.js → issue-workspace-selection-S8UgGgK1.js} +1 -1
  129. package/dist/assets/{pipeline-stage-presentation-BSuBql6K.js → pipeline-stage-presentation-5UBw7nsb.js} +1 -1
  130. package/dist/assets/{shared-DDwmHbeD.js → shared-4LF6wQ38.js} +1 -1
  131. package/dist/assets/{tool-taxonomy-DR7Q8sVs.js → tool-taxonomy-B5zpbkHA.js} +1 -1
  132. package/dist/assets/{transcript-adapter-wiFIjKfq.js → transcript-adapter-C29ZJiU2.js} +1 -1
  133. package/dist/assets/{useSummaryDraftStream-CWOQt25o.js → useSummaryDraftStream-R2Y2bAUU.js} +1 -1
  134. package/dist/index.html +7 -6
  135. package/dist/sw.js +1 -1
  136. package/package.json +1 -1
  137. package/dist/assets/Terminal-Bo-WuezO.js +0 -1
  138. package/dist/assets/TerminalView-AkFY5bLC.js +0 -58
  139. package/dist/assets/dropdown-menu-CqRAF7Oj.js +0 -1
  140. package/dist/assets/index-KZ2bEg2H.css +0 -2
@@ -1 +1 @@
1
- var Ye=Object.defineProperty;var t=(a,r)=>Ye(a,"name",{value:r,configurable:!0});import{i as Ge}from"./rolldown-runtime-ZpX3ckPj.js";import{Bn as Fe,In as Je,Ji as Xe,Xi as Ze,Yi as Ke,na as et,ta as tt}from"./createLucideIcon-DJi9suAC.js";import{a as Re,y as Ue}from"./star-BZgQbzhV.js";import{X as We,_ as ye,t as ge,v as ce}from"./queryKeys-DYV5MhM_.js";import{o as st}from"./companies-query-D9PxIiMT.js";import{n as He}from"./CompanyContext-CSrVsSze.js";import{it as at,o as Le,t as Oe}from"./router-2UfGeejU.js";import{t as nt}from"./checkbox-BHQhs41k.js";import{t as Ce}from"./label-BPz3pg9_.js";import{t as it}from"./circle-question-mark-B1jR2is9.js";import{t as qe}from"./copy-_wvZOjTe.js";import{t as Q}from"./external-link-nl1b263c.js";import{t as rt}from"./eye-off-CVVA-EWh.js";import{t as ot}from"./eye-DRS7RbEp.js";import{r as Y,t as p}from"./button-CMwV3L1P.js";import{t as ze}from"./triangle-alert-CBVKiaXB.js";import{n as ct,t as Ae}from"./SetupWizard-C8qzkJn1.js";import{i as lt,n as dt,t as pt}from"./tooltip-B5WQ3lq5.js";import{t as ut}from"./AgentAvatar-DgGEobSY.js";import{i as Be}from"./ToastContext-DMdt9oTd.js";import{t as Pe}from"./agents-DmlgUVso.js";import{t as ht}from"./instanceSettings-D8g_QlS-.js";import{t as mt}from"./projects-mixWrT5q.js";import{a as xt,c as gt,i as ft,n as bt,r as kt,s as yt,t as jt}from"./dialog-CKUblzlR.js";import{t as ie}from"./input-DobnTAyB.js";import{t as vt}from"./health-DF7yrggW.js";import{t as W}from"./chatEndpoints-BKsIHowE.js";import{n as De}from"./BreadcrumbContext-BVZDZoC0.js";import{t as Te}from"./textarea-BRPEfJ-g.js";import{n as $e}from"./AgentMultiSelect-DsJfZtR2.js";import{t as Ie}from"./clipboard-CTLKYvRL.js";import{t as wt}from"./AgentCharacter-BTEn5MBu.js";import{t as Ct}from"./use-copy-action-D5dEzo6L.js";import{Cn as Nt,Gr as ve,Wr as Ve,yn as St}from"./index-DDoARkPG.js";import{r as At}from"./EmailEndpointSetup-CJFYu2G0.js";import{a as It,i as Tt,m as Me,o as Se,p as Et,r as Pt}from"./OpenwaGatewayManager-DH3bF7fa.js";var Rt=new Set(["terminated","pending_approval","paused"]),Ut=new Set(["active","idle","running","error"]);function Wt(a){return Ut.has(a)&&!Rt.has(a)}t(Wt,"isAgentStatusInvokable");var c=Ge(et(),1),e=Ge(tt(),1);function Lt({endpoint:a,stage:r,disabled:u,saveDetails:d,onSaved:U,onBusy:A,onManual:b,onContinue:i,onSaveExit:g}){const[y,h]=(0,c.useState)(""),[l,q]=(0,c.useState)(!1),[C,S]=(0,c.useState)(null),[G,te]=(0,c.useState)(!1),T=(0,c.useRef)(crypto.randomUUID()),z=(0,c.useRef)(!1),j=(0,c.useRef)(null),k=(0,c.useRef)(!0);(0,c.useEffect)(()=>(k.current=!0,()=>{k.current=!1,j.current?.close(),j.current=null}),[]);const P=a.setup?.slackRegistration,_=P?.status==="uncertain",M=P?.status==="creating",K=!!P?.appId,O=P?.errorCode==="slack_manifest_update_pending";async function s(f){if(!z.current){z.current=!0,q(!0),A(!0),S(null);try{await f()}catch(X){S(Se(X,{configurationToken:y}))}finally{h(""),q(!1),A(!1),z.current=!1}}}t(s,"run");async function N(){const f=window.open("about:blank","_blank");f&&(f.opener=null,f.document.title="Preparing Slack installation",f.document.body.textContent="Preparing your Slack installation…",j.current=f);let X=y.trim();h("");try{let L;try{K||await d(),(P?.status==="failed"||G)&&(T.current=crypto.randomUUID()),L=await W.createSlackApp(a.id,{requestId:T.current,credentials:{configurationToken:X},...G?{confirmedNoAppCreated:!0}:{}})}catch(re){const B=await W.get(a.id).catch(()=>null);if(B&&k.current&&U(B),!B?.setup?.slackRegistration?.appId)throw new Error(Se(re,{configurationToken:X}));L=B}if(X="",!k.current)return;te(!1),U(L);const Z=L.setup?.slackRegistration;if(!Z?.appId||(i(),Z.status!=="install"||Z.errorCode))return;if(!f||f.closed){S("Select Install in Slack to open the installation page.");return}const v=await W.installSlackApp(a.id);if(!k.current)return;if(f.closed){S("Select Install in Slack to reopen the installation page.");return}f.location.replace(v.authorizationUrl),j.current=null}finally{X="",j.current?.close(),j.current=null}}t(N,"create");async function J(){const f=await W.installSlackApp(a.id);window.location.assign(f.authorizationUrl)}return t(J,"authorize"),(0,e.jsxs)("div",{className:"space-y-5",children:[C||P?.errorCode?(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:C??Ze(P.errorCode)}):null,(r==="app"&&!K&&!M||O)&&(0,e.jsxs)(e.Fragment,{children:[_&&(0,e.jsxs)("div",{className:"space-y-3 text-sm",children:[(0,e.jsxs)("a",{href:P?.managementUrl??"https://api.slack.com/apps",target:"_blank",rel:"noopener noreferrer",className:"underline underline-offset-4",children:["Open Slack app settings ",(0,e.jsx)(Q,{className:"inline size-3"})]}),(0,e.jsxs)("label",{className:"flex items-center gap-2",children:[(0,e.jsx)(nt,{checked:G,disabled:l,onCheckedChange:t(f=>te(f===!0),"onCheckedChange")}),"I checked Slack and no app was created. Create a new app."]})]}),(!_||G)&&(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)(p,{asChild:!0,size:"lg",className:"mb-4 h-auto w-full whitespace-normal py-4",children:(0,e.jsxs)("a",{href:"https://api.slack.com/apps",target:"_blank",rel:"noopener noreferrer",children:["Get your App configuration access token ",(0,e.jsx)(Q,{className:"size-4"})]})}),(0,e.jsxs)("div",{id:"slack-configuration-token-help",className:"space-y-3 pb-3 text-sm",children:[(0,e.jsxs)("ol",{className:"list-decimal space-y-2 pl-5",children:[(0,e.jsxs)("li",{children:["In Slack app settings, find ",(0,e.jsx)("strong",{children:"Your App Configuration Tokens"})," and choose ",(0,e.jsx)("strong",{children:"Generate Token"}),"."]}),(0,e.jsx)("li",{children:"Select the workspace where you want to install your bot."}),(0,e.jsxs)("li",{children:["Copy the ",(0,e.jsx)("strong",{children:"Access Token"})," and paste it below."]})]}),(0,e.jsx)("p",{className:"text-ink-3",children:"Wardmote uses this token to create your app"})]}),(0,e.jsx)("label",{htmlFor:"slack-configuration-token",className:"text-sm font-medium",children:"App configuration access token"}),(0,e.jsx)(ie,{id:"slack-configuration-token",type:"password",autoComplete:"off",spellCheck:!1,value:y,disabled:l,onChange:t(f=>h(f.target.value),"onChange"),"aria-describedby":"slack-configuration-token-help"})]})]}),M&&(0,e.jsxs)("p",{role:"status",className:"flex items-center gap-2 text-sm text-ink-3",children:[(0,e.jsx)(Y,{className:"size-4 animate-spin"})," Creating your Slack app. You can return to this saved setup."]}),K&&(0,e.jsxs)("p",{className:"text-sm",children:[(0,e.jsx)("strong",{children:a.setup?.slackApp?.appName??"Your Slack app"})," is created.",r==="credentials"&&" Approve installation with your Slack account. Wardmote will link it to your signed-in Wardmote account and send you a welcome DM."]}),r==="credentials"&&P?.status==="credentials_saved"&&(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Your installation credentials are saved. Retry connecting to finish setup. If Slack access has changed, authorize the same app again."}),(0,e.jsx)(p,{variant:"link",className:"h-auto p-0",disabled:l||u,onClick:t(()=>{s(J)},"onClick"),children:"Authorize in Slack again"})]}),r==="app"&&(0,e.jsx)(Me,{children:(0,e.jsxs)("div",{className:"flex flex-wrap gap-4 text-sm",children:[(0,e.jsx)(p,{variant:"link",className:"h-auto p-0",disabled:l||M,onClick:t(()=>{s(()=>b(!1))},"onClick"),children:"Create manually"}),(0,e.jsx)(p,{variant:"link",className:"h-auto p-0",disabled:l||M,onClick:t(()=>{s(()=>b(!0))},"onClick"),children:"Use an existing app"})]})}),(0,e.jsx)(Ae,{onSaveExit:g,disabled:l,children:O?(0,e.jsxs)(p,{disabled:l||u||!y.trim(),onClick:t(()=>{s(N)},"onClick"),children:[l&&(0,e.jsx)(Y,{className:"size-4 animate-spin"}),"Retry app configuration"]}):r==="app"?(0,e.jsxs)(p,{disabled:l||u||M||!K&&(!y.trim()||_&&!G),onClick:t(()=>K?i():void s(N),"onClick"),children:[l&&(0,e.jsx)(Y,{className:"size-4 animate-spin"}),K?"Continue to installation":"Create Slack app"]}):P?.status==="credentials_saved"?(0,e.jsxs)(p,{disabled:l,onClick:t(()=>{s(async()=>U(await W.resumeSlackInstallation(a.id)))},"onClick"),children:[l&&(0,e.jsx)(Y,{className:"size-4 animate-spin"}),"Retry connecting"]}):(0,e.jsxs)(p,{disabled:l||!K||u,onClick:t(()=>{s(J)},"onClick"),children:[l?(0,e.jsx)(Y,{className:"size-4 animate-spin"}):(0,e.jsx)(Q,{className:"size-4"}),"Install in Slack"]})})]})}t(Lt,"SlackAutomaticSetup");var zt="https://github.com/tickernelz/wardmote/blob/main/doc/LOW-TRUST-PRESETS.md";function Qe({agent:a,onChangeToLowTrust:r,disabled:u}){return!a||Nt(a.permissions)==="low_trust_review"?null:(0,e.jsxs)("div",{role:"alert",className:"space-y-2 rounded-lg border border-(--status-task-todo)/30 bg-(--status-task-todo)/10 p-4 text-sm",children:[(0,e.jsxs)("p",{className:"flex items-center gap-2 font-medium",children:[(0,e.jsx)(ze,{className:"size-4 shrink-0"}),a.name," is not configured for low-trust review"]}),(0,e.jsx)("p",{children:"GitHub comments and pull requests can contain malicious instructions. We recommend a low-trust agent with a scoped work boundary and an isolated sandbox runtime."}),(0,e.jsx)("p",{className:"text-xs text-ink-3",children:"Continuing keeps this agent’s current permissions. A restricted guest profile does not replace the agent’s trust and runtime settings."}),r&&(0,e.jsxs)(p,{variant:"secondary",className:"h-auto whitespace-normal",disabled:u,onClick:r,children:["Change ",a.name," to a low trust agent"]}),(0,e.jsxs)("a",{className:"inline-flex items-center gap-1 underline underline-offset-4",href:zt,target:"_blank",rel:"noreferrer",children:["Learn about low-trust agents",(0,e.jsx)(Q,{className:"size-3.5"})]})]})}t(Qe,"GitHubAgentTrustWarning");function Dt(a){const r=new URL(a.registrationUrl);if(r.origin!=="https://github.com"||r.username||r.password||r.hash||!/^\/(settings|organizations\/[A-Za-z0-9-]+\/settings)\/apps\/new$/.test(r.pathname))throw new Error("GitHub returned an invalid registration address");return r.toString()}t(Dt,"gitHubAppManifestAction");function Mt({registration:a,onSaveExit:r,disabled:u,autoSubmit:d,onSubmit:U}){const A=(0,c.useRef)(null),b=(0,c.useRef)(!1);return(0,c.useEffect)(()=>{d||(b.current=!1),d&&!u&&!b.current&&A.current&&(b.current=!0,A.current.requestSubmit())},[d,u]),(0,e.jsxs)("form",{ref:A,method:"post",action:Dt(a),onSubmit:U,children:[(0,e.jsx)("input",{type:"hidden",name:"manifest",value:JSON.stringify(a.manifest)}),(0,e.jsx)(Ae,{onSaveExit:r,disabled:u,children:(0,e.jsx)(p,{type:"submit",disabled:u,children:"Continue to GitHub"})})]})}t(Mt,"GitHubAppManifestForm");function Ot(){const[a,r]=Ue(),u=Le(),{selectedCompanyId:d}=He(),{setBreadcrumbs:U}=De(),A=We(),b=a.get("resume"),i=a.get("stage")==="identity",g=a.get("reconnect")==="1",[y,h]=(0,c.useState)(a.get("agentId")??""),[l,q]=(0,c.useState)("personal"),[C,S]=(0,c.useState)(""),[G,te]=(0,c.useState)(!1),[T,z]=(0,c.useState)(""),[j,k]=(0,c.useState)(!1),[P,_]=(0,c.useState)(!1),[M,K]=(0,c.useState)(""),[O,s]=(0,c.useState)(a.get("reconnect")==="1"),[N,J]=(0,c.useState)({appId:"",privateKey:"",webhookSecret:""}),[f,X]=(0,c.useState)(""),[L,Z]=(0,c.useState)(!1),[v,re]=(0,c.useState)(null),B=ce({queryKey:["github-setup-agents",d],queryFn:t(()=>Pe.list(d),"queryFn"),enabled:!!d&&!i}),F=ce({queryKey:["github-setup",b],queryFn:t(()=>W.get(b),"queryFn"),enabled:!!b,refetchInterval:3e3}),x=F.data,oe=ce({queryKey:["github-wizard",b],queryFn:t(()=>ve.advance(b),"queryFn"),enabled:!!x&&!O&&!i,refetchInterval:t(o=>["connected","create","identity","recovery"].includes(o.state.data?.state??"")?!1:5e3,"refetchInterval"),retry:!1}),$=ce({queryKey:["github-personal-connections",b],queryFn:t(()=>ve.personalConnections(b),"queryFn"),enabled:!!x&&(i||oe.data?.state==="identity")}),D=B.data?.find(o=>o.id===(x?.assignedAgentId??y)),w=i?void 0:oe.data,fe=!!x&&!i&&!O&&w?.state==="create",m=ce({queryKey:["project-repositories",d],queryFn:t(()=>mt.repositoryOptions(d),"queryFn"),enabled:!!d&&fe,staleTime:3e4}),H=ce({queryKey:ge.chatEndpoints.list(d),queryFn:t(()=>W.list(d),"queryFn"),enabled:!!d&&fe,staleTime:3e4}),le=new Map;for(const o of m.data?.repositories??[]){if(o.ownerType!=="organization")continue;const R=o.fullName.split("/")[0];le.set(R.toLowerCase(),R)}for(const o of H.data??[]){const R=o.setup?.github;o.provider==="github"&&["active","paused"].includes(o.status)&&R?.ownerType==="organization"&&R.ownerLogin&&le.set(R.ownerLogin.toLowerCase(),R.ownerLogin)}const he=[...le.values()].sort((o,R)=>o.localeCompare(R)),pe=le.get(C.toLowerCase()),E=l==="personal"?"personal":!G&&pe?`organization:${pe}`:"organization",me=w?.state==="verify"&&!!x?.setup?.webhookVerifiedAt&&w.verification?.checks.some(o=>!o.ok&&["webhook","delivery"].includes(o.key)),xe=i||w?.identityMethod==="existing_connection",be=w?.state==="connected"&&!O;(0,c.useEffect)(()=>{!be||!x||(A.setQueryData(ge.chatEndpoints.detail(x.id),x),D&&A.setQueryData(ge.agents.detail(D.id),D),u(`/apps/chat/${x.id}/settings`,{replace:!0,state:{githubConnectionComplete:{endpointId:x.id,runtimeChecks:w.runtimeChecks}}}))},[be,x,D,w,A,u]),(0,c.useEffect)(()=>(U([{label:"Connectors",href:"/apps"},{label:"GitHub Code Review Bot"}]),()=>U([])),[U]),(0,c.useEffect)(()=>{x&&(h(x.assignedAgentId),x.setup?.github?.ownerType&&q(x.setup.github.ownerType),S(x.setup?.github?.ownerLogin??""),te(!1),x.setup?.github?.appName&&z(x.setup.github.appName))},[x?.id,x?.setup?.github?.ownerType,x?.setup?.github?.ownerLogin,x?.setup?.github?.appName]);async function V(o){k(!0),K("");try{await o()}catch(R){K(R instanceof Error?R.message:"Could not connect GitHub. Try again.")}finally{k(!1)}}t(V,"run");async function ee(){await F.refetch(),i||await oe.refetch()}t(ee,"refresh");const je=t(()=>({name:(T||D?.name||x?.assignedAgentName||"GitHub Reviewer").slice(0,34),ownerType:l,...l==="organization"?{ownerLogin:C.trim()}:{}}),"appInput"),ue=t(()=>{V(async()=>{!i&&x&&!x.botExternalId&&!w?.registration&&w?.state!=="recovery"&&(await ve.saveDraft(x.id,je()),await F.refetch()),u("/apps")})},"exit"),se=t((o,R,we=!1)=>(0,e.jsx)(Ae,{onSaveExit:ue,disabled:j,children:o&&R&&(0,e.jsxs)(p,{disabled:j||we,onClick:t(()=>{V(R)},"onClick"),children:[j&&(0,e.jsx)(Y,{className:"mr-2 size-4 animate-spin"}),o]})}),"footer");return b&&!x?(0,e.jsxs)("div",{className:"mx-auto w-full max-w-3xl space-y-6 px-4 py-6 sm:px-6",children:[(0,e.jsx)("h1",{className:"text-2xl font-semibold",children:"Resume GitHub setup"}),F.error?(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Could not load this connection. Try again to resume your draft."}):(0,e.jsx)("p",{role:"status",className:"text-sm text-ink-3",children:"Loading your draft…"}),se(F.error?"Try again":void 0,async()=>{await F.refetch()})]}):be?null:(0,e.jsxs)("div",{className:"mx-auto w-full max-w-3xl space-y-6 px-4 py-6 sm:px-6",children:[!i&&(0,e.jsx)(ct,{labels:["Choose agent","Connect GitHub"],step:x?1:0,availableStep:x?1:0,onSelect:t(()=>{},"onSelect"),disabled:!0,takeover:!0}),(0,e.jsx)("h1",{className:"text-2xl font-semibold",children:x?i||w?.state==="identity"?"Connect your account":"Connect GitHub":"Choose agent"}),(M||!i&&oe.error||$.error)&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:M||($.error instanceof Error?$.error.message:void 0)||(oe.error instanceof Error?oe.error.message:"Could not check GitHub setup. Try again.")}),x?!i&&!O&&oe.isPending?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{role:"status",className:"text-sm text-ink-3",children:"Checking your GitHub connection…"}),se()]}):O?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{className:"text-sm text-ink-3",children:g?"Leave these blank to reuse this App’s stored credentials, or enter both fields to repair them.":"Use the credentials from this App’s GitHub settings."}),(0,e.jsx)(Ce,{htmlFor:"github-app-id",children:"App ID"}),(0,e.jsx)(ie,{id:"github-app-id",value:N.appId,onChange:t(o=>J({...N,appId:o.target.value}),"onChange")}),(0,e.jsx)(Ce,{htmlFor:"github-private-key",children:"Private key"}),(0,e.jsx)(Te,{id:"github-private-key",value:N.privateKey,onChange:t(o=>J({...N,privateKey:o.target.value}),"onChange")}),!g&&!["active","paused","revoked"].includes(x.status)&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Ce,{htmlFor:"github-webhook-secret",children:"Webhook secret"}),(0,e.jsx)(ie,{id:"github-webhook-secret",type:"password",value:N.webhookSecret,onChange:t(o=>J({...N,webhookSecret:o.target.value}),"onChange")})]}),se(g?"Reconnect App":"Connect existing App",async()=>{g||["active","paused","revoked"].includes(x.status)?await W.setup(x.id,{action:"reconnect",...N.appId.trim()||N.privateKey.trim()?{credentials:{appId:N.appId,privateKey:N.privateKey}}:{}}):await ve.connectApp(x.id,N),J({appId:"",privateKey:"",webhookSecret:""}),s(!1),await ee()},g?!!(N.appId.trim()||N.privateKey.trim())&&(!N.appId.trim()||!N.privateKey.trim()):!N.appId.trim()||!N.privateKey.trim()||!["active","paused","revoked"].includes(x.status)&&!N.webhookSecret.trim())]}):w?.state==="identity"||i?(0,e.jsx)(e.Fragment,{children:i&&L?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("p",{role:"status",className:"text-sm",children:["GitHub account ",(0,e.jsx)("strong",{children:v?.login})," ","connected. You can now mention this bot on GitHub."]}),se()]}):w?.identity?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("p",{className:"text-sm",children:["Connect GitHub account ",(0,e.jsx)("strong",{children:w.identity.login})," ","to your Wardmote account."]}),se("Confirm my account",async()=>{await ve.confirmIdentity(x.id,w.identity.githubUserId),await ee()})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Link your GitHub account so your mentions use your Wardmote permissions."}),($.data?.length??0)>0&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Ce,{htmlFor:"github-personal-account",children:"Existing GitHub connection"}),(0,e.jsxs)("select",{id:"github-personal-account",className:"w-full rounded-md border border-line-strong bg-bg px-3 py-2 text-sm",value:f,onChange:t(o=>{X(o.target.value),re(null),Z(!1)},"onChange"),children:[(0,e.jsx)("option",{value:"",children:"Choose an account"}),$.data?.filter(o=>o.status==="active"&&o.enabled).map(o=>(0,e.jsx)("option",{value:o.connectionId,children:o.login??o.name},o.connectionId))]}),v&&(0,e.jsxs)("p",{className:"text-sm",children:["GitHub account: ",(0,e.jsx)("strong",{children:v.login})]})]}),xe&&!f&&(0,e.jsx)(Oe,{className:"text-sm underline",to:"/apps/connect?source=github",children:"Add a personal GitHub connection, then return to this draft"}),se(f?v?"Confirm my account":"Check my account":"Connect my GitHub account",async()=>{if(f){const o=await ve.identity(x.id,f,v?.githubUserId);re(o),v&&(Z(!0),await ee())}else{const o=await ve.startIdentity(x.id);window.location.assign(o.authorizationUrl)}},xe&&!f)]})}):w?.state==="install"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{role:"status",className:"text-sm text-ink-3",children:"Waiting for GitHub installation or administrator approval…"}),w.installationUrl&&(0,e.jsxs)("a",{className:"inline-flex items-center gap-1 text-sm underline",href:w.installationUrl,children:["Continue installation on GitHub",(0,e.jsx)(Q,{className:"size-3"})]}),se()]}):w?.state==="recovery"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{role:"status",className:"text-sm",children:w.message}),(0,e.jsx)(p,{variant:"ghost",onClick:t(()=>s(!0),"onClick"),children:"Use existing App credentials"}),se("Try again",ee)]}):w?.state==="verify"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{role:"status",className:"text-sm text-ink-3",children:me?"GitHub delivery verified. Checking App and repository access…":w.message??"Checking GitHub access…"}),w.verification?.checks.filter(o=>!o.ok&&!(me&&["webhook","delivery"].includes(o.key))).map(o=>(0,e.jsx)("p",{className:"text-sm",children:o.detail},o.key)),(0,e.jsx)(Oe,{className:"text-sm underline",to:`/apps/chat/${x.id}/settings`,children:"Connection settings"}),se("Try again",ee)]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)(Ce,{htmlFor:"github-owner-type",children:"GitHub account"}),(0,e.jsxs)("select",{id:"github-owner-type",className:"w-full rounded-md border border-line-strong bg-bg px-3 py-2 text-sm",value:E,disabled:j||!!w?.registration,onChange:t(o=>{const R=o.target.value;q(R==="personal"?"personal":"organization"),te(R==="organization"),R.startsWith("organization:")?S(R.slice(13)):R==="organization"&&S("")},"onChange"),children:[(0,e.jsx)("option",{value:"personal",children:"My account"}),he.map(o=>(0,e.jsx)("option",{value:`organization:${o}`,children:o},o.toLowerCase())),(0,e.jsx)("option",{value:"organization",children:"Another organization"})]}),(m.isError||H.isError)&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Could not load some connected GitHub accounts. Choose Another organization to enter a name."})]}),E==="organization"&&(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)(Ce,{htmlFor:"github-owner-login",children:"Organization"}),(0,e.jsx)(ie,{id:"github-owner-login",disabled:j||!!w?.registration,value:C,onChange:t(o=>S(o.target.value),"onChange"),placeholder:"GitHub organization name"})]}),(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)(Ce,{htmlFor:"github-app-name",children:"App name"}),(0,e.jsx)(ie,{id:"github-app-name",disabled:j||!!w?.registration,maxLength:34,value:T||D?.name?.slice(0,34)||x.assignedAgentName?.slice(0,34)||"GitHub Reviewer",onChange:t(o=>z(o.target.value),"onChange")})]}),(0,e.jsx)("button",{className:"text-sm text-ink-3 underline",onClick:t(()=>s(!0),"onClick"),children:"I already have an App"}),w?.registration?(0,e.jsx)(Mt,{registration:w.registration,onSaveExit:ue,disabled:j,autoSubmit:P,onSubmit:t(()=>_(!1),"onSubmit")}):se("Continue to GitHub",async()=>{const o=await ve.registration(x.id,je());A.setQueryData(["github-wizard",x.id],o),o.registration&&_(!0)},oe.isPending||l==="organization"&&!C.trim())]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)($e,{agents:B.data??[],value:y,onChange:h}),D&&(0,e.jsx)(Qe,{agent:D,disabled:j,onChangeToLowTrust:t(()=>{V(async()=>{const o=St(D.permissions,"low_trust_review");await Pe.updatePermissions(D.id,{...o,canCreateAgents:!1,canCreateSkills:!1,canAssignTasks:typeof D.permissions.canAssignTasks=="boolean"?D.permissions.canAssignTasks:!0},d),await A.invalidateQueries({queryKey:["github-setup-agents",d]})})},"onChangeToLowTrust")}),se("Continue",async()=>{const o=await W.create(d,{provider:"github",assignedAgentId:y});z((D?.name??"GitHub Reviewer").slice(0,34));const R=new URLSearchParams(a);R.set("resume",o.id),r(R,{replace:!0}),A.setQueryData(["github-setup",o.id],o)},!y||!d)]})]})}t(Ot,"GitHubChatSetup");function _t({endpointId:a,command:r,testStartedAt:u,onConnected:d,onSaveExit:U}){const A=We(),[b,i]=(0,c.useState)(!1),[g,y]=(0,c.useState)(!1),h=ce({queryKey:ge.auth.session,queryFn:st.getSession,retry:!1}),l=ce({queryKey:ge.health,queryFn:vt.get}),q=ce({queryKey:ge.chatEndpoints.principals(a),queryFn:t(()=>W.listPrincipals(a),"queryFn"),refetchInterval:1500}),C=l.data?.deploymentMode==="local_trusted",S=C?"local-board":h.data?.user.id,G=C?"Local Board":h.data?.user.name||h.data?.user.email,te=(q.data??[]).filter(k=>k.lastConnectAt&&(!u||Date.parse(k.lastConnectAt)>=Date.parse(u))),T=te.some(k=>k.status==="linked"&&k.wardmoteUserId===S),z=`${r} connect`,j=ye({mutationFn:t(async k=>{const{confirmationUrl:P}=await W.createLinkIntent(a,k),_=new URL(P,window.location.origin).searchParams.get("token");if(!_)throw new Error("Could not create the account confirmation. Try again.");await W.confirmIdentityLink(_)},"mutationFn"),onSuccess:t(()=>A.invalidateQueries({queryKey:ge.chatEndpoints.principals(a)}),"onSuccess")});return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:"Connect your Slack account"}),(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:"Send this command in Slack so we can identify your account. It won't start agent work."})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border border-line p-3",children:[(0,e.jsx)("code",{className:"text-sm",children:z}),(0,e.jsxs)(p,{variant:"ghost",size:"sm",onClick:t(()=>{Ie(z).then(()=>{i(!0),y(!1)},()=>y(!0))},"onClick"),children:[(0,e.jsx)(qe,{className:"size-4"}),b?"Copied":"Copy command"]})]}),g&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Couldn't copy the command. Select and copy it above."}),(0,e.jsxs)("p",{className:"text-sm",children:[(0,e.jsxs)("a",{href:"https://app.slack.com/",target:"_blank",rel:"noopener noreferrer",className:"underline underline-offset-4",children:["Open Slack ",(0,e.jsx)(Q,{className:"inline size-3"})]}),", send the command in your workspace, then return here."]}),q.isError?(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Couldn't check for your Slack account. We'll keep trying."}):te.length===0?(0,e.jsxs)("p",{role:"status",className:"flex items-center gap-2 text-sm text-ink-3",children:[(0,e.jsx)(Y,{className:"size-4 animate-spin"}),"Waiting for your connect command…"]}):(0,e.jsxs)("div",{className:`space-y-3 rounded-lg border p-4 ${T?"border-(--status-task-done)/30 bg-(--status-task-done)/10":"border-(--status-task-todo)/30 bg-(--status-task-todo)/10"}`,children:[(0,e.jsxs)("p",{className:"text-sm",children:["Choose your Slack account below to link it to ",(0,e.jsx)("strong",{children:G??"your Wardmote account"}),". Only confirm an account that belongs to you. Future messages will use your Wardmote permissions."]}),te.map(k=>{const P=k.status==="linked"&&k.wardmoteUserId===S;return(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border border-line p-3",children:[(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsx)("p",{className:"text-sm font-medium",children:k.externalLabel}),(0,e.jsx)("p",{className:"text-xs text-ink-3",children:k.externalDetail})]}),P?(0,e.jsxs)("p",{role:"status",className:"flex items-center gap-2 text-sm",children:[(0,e.jsx)(Re,{className:"size-4 text-(--status-task-done)"}),"Linked to you"]}):k.status==="linked"?(0,e.jsxs)("p",{className:"text-sm text-ink-3",children:["Linked to ",k.wardmoteUserLabel??"another Wardmote account"]}):(0,e.jsxs)(p,{variant:"secondary",disabled:!S||j.isPending,onClick:t(()=>j.mutate(k.principalId),"onClick"),"aria-label":`Link ${k.externalLabel} to my Wardmote account`,children:[j.isPending&&j.variables===k.principalId&&(0,e.jsx)(Y,{className:"size-4 animate-spin"}),"This is my Slack account"]})]},k.principalId)})]}),!S&&!h.isPending&&!l.isPending&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Sign in to Wardmote to link your Slack account. Refresh this page after signing in."}),j.isError&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Couldn't link your account. Check that you are a member of this company and try again."}),(0,e.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,e.jsx)(p,{variant:"ghost",onClick:U,children:"Save & exit"}),T&&(0,e.jsx)(p,{onClick:d,children:"Continue to message test"})]})]})}t(_t,"SlackIdentityStep");function Gt({endpoint:a,agentName:r,repairing:u,pending:d,onAction:U}){const[A,b]=(0,c.useState)(a.providerAccountId??""),[i,g]=(0,c.useState)(""),[y,h]=(0,c.useState)(""),l=ye({mutationFn:t(()=>W.inspectPhoton(a.id,{projectId:A.trim(),projectSecret:i}),"mutationFn"),onSuccess:t(C=>{const S=C.lines.filter(G=>G.eligible);h(S.length===1?S[0].lineId:"")},"onSuccess")}),q=t(()=>{l.reset(),h("")},"resetInspection");return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:"Connect iMessage Photon"}),(0,e.jsxs)("p",{className:"text-sm text-ink-3",children:["Connect ",r," to Photon Cloud. Pro supports direct messages through a shared line. Dedicated numbers also support individually enabled groups."]}),(0,e.jsxs)("p",{className:"text-sm",children:[(0,e.jsx)("a",{className:"underline",href:"https://app.photon.codes/",target:"_blank",rel:"noreferrer",children:"Photon dashboard"})," · ",(0,e.jsx)("a",{className:"underline",href:"https://photon.codes/docs/spectrum-ts/providers/imessage/connection-and-routing",target:"_blank",rel:"noreferrer",children:"Photon line setup"})]})]}),u&&(0,e.jsxs)("p",{className:"text-sm text-ink-3",children:["Reconnect keeps this project and"," ",a.photonAllocation==="shared"?"shared DM allocation":a.botExternalId??"dedicated number",". Leave the secret blank to reuse the saved connection."]}),(0,e.jsxs)("label",{className:"grid gap-2 text-sm font-medium",children:["Project ID",(0,e.jsx)(ie,{value:A,autoComplete:"off",disabled:d||l.isPending||!!a.botExternalId,onChange:t(C=>{b(C.target.value),q()},"onChange")})]}),(0,e.jsxs)("label",{className:"grid gap-2 text-sm font-medium",children:["Project secret",(0,e.jsx)(ie,{type:"password",value:i,autoComplete:"new-password",disabled:d||l.isPending,onChange:t(C=>{g(C.target.value),q()},"onChange")})]}),(0,e.jsx)(p,{variant:"secondary",disabled:d||l.isPending||!A.trim()||!i,onClick:t(()=>l.mutate(),"onClick"),children:l.isPending?"Inspecting Photon…":"Inspect Photon project"}),l.isError&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:Se(l.error,{projectSecret:i})}),l.data&&(0,e.jsxs)("fieldset",{className:"space-y-3",children:[(0,e.jsxs)("legend",{className:"text-sm font-medium",children:[l.data.allocation==="shared"?"Shared DMs":"Dedicated numbers"," in ",l.data.projectName]}),!l.data.eligible&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:l.data.allocation==="shared"?"This shared project already belongs to another channel. Use a separate Photon project for each agent.":"No eligible dedicated number is available. Check the line allocation in Photon and existing Wardmote channels."}),l.data.allocation==="shared"&&l.data.eligible&&(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Direct messages only. Enroll each test sender in your Photon project's Users page, then use the number Photon assigns to that sender. Wardmote identity linking is still required. Groups cannot be enabled on this channel."}),l.data.lines.map(C=>(0,e.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,e.jsx)("input",{type:"radio",name:"photon-line",value:C.lineId,checked:y===C.lineId,disabled:!C.eligible||d||!!a.botExternalId&&a.botExternalId!==C.phoneNumber,onChange:t(()=>h(C.lineId),"onChange")}),(0,e.jsxs)("span",{children:[C.phoneNumber,C.unavailableReason?` — ${C.unavailableReason}`:""]})]},C.lineId))]}),(0,e.jsx)("div",{children:(0,e.jsx)(p,{disabled:d||l.isPending||!(l.data?.eligible&&(l.data.allocation==="shared"||y))&&!(u&&!i),onClick:t(()=>U(u?"reconnect":"configure",l.data?.eligible&&l.data.allocation==="shared"?{projectId:A.trim(),projectSecret:i,allocation:"shared"}:y?{projectId:A.trim(),projectSecret:i,lineId:y,allocation:"dedicated"}:void 0),"onClick"),children:d?"Connecting…":u?"Reconnect Photon":l.data?.allocation==="shared"?"Connect shared DMs":"Connect selected number"})})]})}t(Gt,"PhotonConnectStep");var Ft="https://github.com/rmyndharis/OpenWA";function _e(a){const r=a.providerAccountId??"",u=r.lastIndexOf("#");return u>0?r.slice(0,u):""}t(_e,"storedBaseUrl");function Kt(a){const r=a.providerAccountId??"",u=r.lastIndexOf("#");return u>0?r.slice(u+1):""}t(Kt,"storedSessionId");function Ee({htmlFor:a,label:r,help:u}){return(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,e.jsx)("label",{htmlFor:a,children:r}),(0,e.jsxs)(pt,{children:[(0,e.jsx)(lt,{asChild:!0,children:(0,e.jsx)("button",{type:"button","aria-label":`Help with ${r.toLowerCase()}`,className:"rounded-sm text-ink-3 hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus",children:(0,e.jsx)(it,{className:"size-3.5","aria-hidden":"true"})})}),(0,e.jsx)(dt,{className:"max-w-xs",children:u})]})]})}t(Ee,"FieldLabel");function Ht({endpoint:a,agentName:r,repairing:u,pending:d,onAction:U,onSaveExit:A}){const b=Kt(a),[i,g]=(0,c.useState)(_e(a)),[y,h]=(0,c.useState)(""),[l,q]=(0,c.useState)(""),[C,S]=(0,c.useState)(""),[G,te]=(0,c.useState)(""),[T,z]=(0,c.useState)(null),[j,k]=(0,c.useState)(!1),[P,_]=(0,c.useState)(""),[M,K]=(0,c.useState)(),[O,s]=(0,c.useState)(a.policy?.numberMode??"agent_number"),[N,J]=(0,c.useState)(a.policy?.attestations.pacing??!1),[f,X]=(0,c.useState)(a.policy?.attestations.soleClient??!1),L=ye({mutationFn:t(()=>W.inspectOpenwa(a.id,{baseUrl:i.trim(),...y.trim()?{apiKey:y.trim()}:{},...l.trim()?{adminApiKey:l.trim()}:{}}),"mutationFn"),onSuccess:t(m=>{const H=m.sessions.filter(he=>he.eligible),le=H.find(he=>he.sessionId===(b||G));S(le?.sessionId??(H.length===1?H[0].sessionId:""))},"onSuccess")}),Z=t(()=>{L.reset(),S(""),z(null),k(!1)},"resetInspection"),v=L.data,re=l.trim()||y.trim(),B=t(m=>W.runOpenwaGatewayAdmin(a.id,{...m,connection:{baseUrl:v.baseUrl,adminApiKey:re}}),"run"),F=ye({mutationFn:t(()=>Tt(B,P),"mutationFn"),onSuccess:t(m=>{k(!1),_(""),z(m)},"onSuccess")}),x=(0,c.useCallback)(()=>{T&&(te(T.id),z(null),L.mutate())},[T,L]),oe=t(()=>{const m=It(P);K(m),m||F.mutate()},"submitSessionName"),$={apiKey:y,adminApiKey:l},D=u&&!y.trim(),w=N&&f&&(D||!!v?.eligible&&!!C),fe=t(()=>U(u?"reconnect":"configure",D?{baseUrl:_e(a),sessionId:b,...l.trim()?{adminApiKey:l.trim()}:{},numberMode:O,pacing:String(N),soleClient:String(f)}:{baseUrl:v.baseUrl,...y.trim()?{apiKey:y.trim()}:{},...l.trim()?{adminApiKey:l.trim()}:{},sessionId:C,numberMode:O,pacing:String(N),soleClient:String(f)}),"connect");return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:"Connect OpenWA"}),(0,e.jsxs)("p",{className:"text-sm text-ink-3",children:["Connect ",r," to one WhatsApp session on your self-hosted OpenWA gateway. You can create the session and scan its QR code here; nothing is sent until an owner messages the number."]}),(0,e.jsx)("p",{className:"text-sm",children:(0,e.jsx)("a",{className:"underline",href:Ft,target:"_blank",rel:"noreferrer",children:"OpenWA documentation"})})]}),u&&(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Reconnect keeps this gateway session. Leave the keys blank to reuse the saved ones, or enter only the admin key to add or replace it."}),(0,e.jsxs)("div",{className:"grid gap-2 text-sm font-medium",children:[(0,e.jsx)(Ee,{htmlFor:"openwa-base-url",label:"Gateway URL",help:"The address of your OpenWA gateway, such as http://localhost:2785. Use only the origin, without /api."}),(0,e.jsx)(ie,{id:"openwa-base-url",value:i,placeholder:"http://localhost:2785",autoComplete:"off",inputMode:"url",disabled:d||L.isPending||!!a.providerAccountId,onChange:t(m=>{g(m.target.value),Z()},"onChange")})]}),(0,e.jsxs)("div",{className:"grid gap-2 text-sm font-medium",children:[(0,e.jsx)(Ee,{htmlFor:"openwa-admin-api-key",label:"Admin API key",help:"OpenWA prints this key in its log the first time the gateway starts. It is stored encrypted and only used from this page and Settings."}),(0,e.jsx)(ie,{id:"openwa-admin-api-key",type:"password",value:l,autoComplete:"new-password",disabled:d||L.isPending,onChange:t(m=>{q(m.target.value),Z()},"onChange")}),(0,e.jsxs)("p",{className:"text-xs font-normal text-ink-3",children:["The admin key lets Wardmote create the session and show its QR here, then give ",r," its own operator key limited to that one session, while an operator key you paste below can only connect a session that is already linked."]})]}),(0,e.jsxs)("details",{className:"text-sm",children:[(0,e.jsx)("summary",{className:"cursor-pointer font-medium",children:"I only have an operator key"}),(0,e.jsxs)("div",{className:"mt-3 grid gap-2 font-medium",children:[(0,e.jsx)(Ee,{htmlFor:"openwa-api-key",label:"Operator API key",help:"An operator key whose allowed sessions contain only this agent's session. Leave allowed chats empty: a chat-restricted key cannot receive live events."}),(0,e.jsx)(ie,{id:"openwa-api-key",type:"password",value:y,autoComplete:"new-password",disabled:d||L.isPending,onChange:t(m=>{h(m.target.value),Z()},"onChange")})]})]}),(0,e.jsx)(p,{variant:"secondary",disabled:d||L.isPending||!i.trim()||!y.trim()&&!l.trim(),onClick:t(()=>L.mutate(),"onClick"),children:L.isPending?"Inspecting gateway…":"Inspect gateway"}),L.isError&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:Se(L.error,$)}),v&&(0,e.jsxs)("div",{className:"space-y-4",children:[(0,e.jsxs)("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-sm",children:[(0,e.jsx)("dt",{className:"text-ink-3",children:"Gateway version"}),(0,e.jsx)("dd",{children:v.gatewayVersion??`Unknown (assuming ${v.pinnedVersion})`}),(0,e.jsx)("dt",{className:"text-ink-3",children:"Engine"}),(0,e.jsx)("dd",{children:v.engine??"Unknown"}),(0,e.jsx)("dt",{className:"text-ink-3",children:"Agent key"}),(0,e.jsx)("dd",{children:v.agentKeyMinted?"New operator key for the chosen session":v.keyRole})]}),v.warnings.length>0&&(0,e.jsx)("div",{role:"status",className:"space-y-1 rounded-lg border border-line bg-bg-3/30 p-4 text-sm",children:v.warnings.map(m=>(0,e.jsxs)("p",{className:"flex gap-2",children:[(0,e.jsx)(ze,{className:"mt-0.5 size-4 shrink-0","aria-hidden":"true"}),(0,e.jsx)("span",{children:m})]},m))}),(0,e.jsxs)("fieldset",{className:"space-y-2",children:[(0,e.jsx)("legend",{className:"text-sm font-medium",children:"WhatsApp session"}),v.sessions.length===0?(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"This gateway has no WhatsApp session yet. Create one below."}):v.eligible||T?null:v.canManageSessions?(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"No session is ready yet. Link WhatsApp to a session, or create a new one."}):(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"No session can be connected. Connect WhatsApp in the OpenWA dashboard or free the session from its other channel."}),v.sessions.map(m=>(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[(0,e.jsxs)("label",{className:"flex min-w-0 flex-1 items-center gap-2 text-sm",children:[(0,e.jsx)("input",{type:"radio",name:"openwa-session",value:m.sessionId,checked:C===m.sessionId,disabled:!m.eligible||d||!!b&&b!==m.sessionId,onChange:t(()=>S(m.sessionId),"onChange")}),(0,e.jsxs)("span",{className:"min-w-0 break-words",children:[m.name,m.maskedNumber?` · ${m.maskedNumber}`:"",m.pushName?` · ${m.pushName}`:"",m.unavailableReason?` — ${m.unavailableReason}`:""]})]}),v.canManageSessions&&m.status!=="ready"&&T?.id!==m.sessionId&&!b?(0,e.jsx)(p,{size:"sm",variant:"secondary",disabled:d,onClick:t(()=>{k(!1),z({id:m.sessionId,name:m.name,status:m.status})},"onClick"),children:"Link WhatsApp"}):null]},m.sessionId))]}),v.canManageSessions&&!b&&!T&&(j?(0,e.jsxs)("div",{className:"space-y-2 rounded-lg border border-line p-4",children:[(0,e.jsx)("label",{htmlFor:"openwa-new-session-name",className:"block text-sm font-medium",children:"New session name"}),(0,e.jsx)(ie,{id:"openwa-new-session-name",value:P,placeholder:"pmo",autoComplete:"off",disabled:F.isPending,"aria-invalid":M?!0:void 0,onChange:t(m=>_(m.target.value),"onChange")}),(0,e.jsx)("p",{className:"text-xs text-ink-3",children:"Letters, digits, dots, dashes or underscores. OpenWA cannot rename a session later."}),(M||F.isError)&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:M??Se(F.error,$)}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,e.jsx)(p,{size:"sm",disabled:F.isPending,onClick:oe,children:F.isPending?"Creating session…":"Create and show QR"}),(0,e.jsx)(p,{size:"sm",variant:"ghost",disabled:F.isPending,onClick:t(()=>k(!1),"onClick"),children:"Cancel"})]})]}):(0,e.jsx)(p,{variant:"secondary",disabled:d,onClick:t(()=>k(!0),"onClick"),children:"Create new WhatsApp session"})),T&&(0,e.jsxs)("section",{"aria-label":"Link "+T.name,className:"space-y-3 rounded-lg border border-line p-4",children:[(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsxs)("h2",{className:"text-base font-semibold",children:["Link WhatsApp to ",T.name]}),(0,e.jsx)("p",{className:"text-sm text-ink-3",children:'On the phone, open WhatsApp, go to Linked devices, then scan the QR code, or choose "Link with phone number" and enter the pairing code. The session is selected as soon as it is ready.'})]}),(0,e.jsx)(Pt,{endpointId:a.id,run:B,session:T,onReady:x}),(0,e.jsx)(p,{size:"sm",variant:"ghost",onClick:t(()=>z(null),"onClick"),children:"Cancel"})]})]}),(v?.eligible||D)&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("fieldset",{className:"space-y-2",children:[(0,e.jsx)("legend",{className:"text-sm font-medium",children:"Whose number is this?"}),(0,e.jsxs)("label",{className:"flex items-start gap-2 text-sm",children:[(0,e.jsx)("input",{type:"radio",name:"openwa-number-mode",className:"mt-1",checked:O==="agent_number",disabled:d||D,onChange:t(()=>s("agent_number"),"onChange")}),(0,e.jsxs)("span",{children:[(0,e.jsxs)("span",{className:"font-medium",children:["A number dedicated to ",r]}),(0,e.jsx)("span",{className:"block text-ink-3",children:"People message this number to reach the agent. Direct messages, mentions, and replies start work."})]})]}),(0,e.jsxs)("label",{className:"flex items-start gap-2 text-sm",children:[(0,e.jsx)("input",{type:"radio",name:"openwa-number-mode",className:"mt-1",checked:O==="owner_number",disabled:d||D,onChange:t(()=>s("owner_number"),"onChange")}),(0,e.jsxs)("span",{children:[(0,e.jsx)("span",{className:"font-medium",children:"An owner's personal number"}),(0,e.jsx)("span",{className:"block text-ink-3",children:"The agent replies as you. Only chats you enable in Settings can trigger it, and its messages carry a visible prefix so contacts know an assistant wrote them. Wardmote can read every chat this session can see."})]})]})]}),(0,e.jsxs)("fieldset",{className:"space-y-2",children:[(0,e.jsx)("legend",{className:"text-sm font-medium",children:"Before connecting, confirm"}),(0,e.jsxs)("label",{className:"flex items-start gap-2 text-sm",children:[(0,e.jsx)("input",{type:"checkbox",className:"mt-1",checked:N,disabled:d,onChange:t(m=>J(m.target.checked),"onChange")}),(0,e.jsx)("span",{children:"Send pacing is turned on in the gateway (SEND_PACING_ENABLED). It spaces out outgoing messages to lower the risk of WhatsApp restricting the number."})]}),(0,e.jsxs)("label",{className:"flex items-start gap-2 text-sm",children:[(0,e.jsx)("input",{type:"checkbox",className:"mt-1",checked:f,disabled:d,onChange:t(m=>X(m.target.checked),"onChange")}),(0,e.jsx)("span",{children:"Wardmote is the only app sending as this session. Other bots, webhooks, or scripts on the same session could make the agent mistake their messages for yours."})]})]})]}),(0,e.jsx)(Ae,{onSaveExit:A,disabled:d,children:(0,e.jsx)(p,{disabled:d||L.isPending||!w,onClick:fe,children:d?"Connecting…":u?"Reconnect OpenWA":"Connect session"})})]})}t(Ht,"OpenwaConnectStep");function qt(){let a=0;return{start(){return a+=1,a},invalidate(){a+=1},isCurrent(r){return r===a}}}t(qt,"createGitHubPrivateKeyReadGuard");async function Bt(a){if(a.size===0)throw new Error("That file is empty. Choose the private key downloaded from your GitHub App.");if(a.size>65536)throw new Error("That file is too large. Choose a GitHub App private key smaller than 64 KB.");let r;try{r=await a.text()}catch{throw new Error("Wardmote couldn't read that file. Choose the .pem file again or paste the private key.")}if(!r.trim())throw new Error("That file is empty. Choose the private key downloaded from your GitHub App.");return r}t(Bt,"readGitHubPrivateKeyFile");var Ne={speko:"Speko",agentmail:"AgentMail",slack:"Slack",github:"GitHub",discord:"Discord","microsoft-teams":"Microsoft Teams",telegram:"Telegram","imessage-photon":"iMessage Photon",openwa:"OpenWA"},$t=new Set(Object.keys(Ne));function Vt(a,r){return r?{action:a,...r.apiKey||r.adminApiKey?{credentials:{...r.apiKey?{apiKey:r.apiKey}:{},...r.adminApiKey?{adminApiKey:r.adminApiKey}:{}}}:{},openwa:{baseUrl:r.baseUrl,sessionId:r.sessionId,numberMode:r.numberMode==="owner_number"?"owner_number":"agent_number",attestations:{pacing:r.pacing==="true",soleClient:r.soleClient==="true"}}}:{action:a}}t(Vt,"openwaSetupInput");function Qt(a){return a!==null&&$t.has(a)}t(Qt,"isProvider");function Yt(a){if(!a)return null;try{return new URL(a).origin}catch{return null}}t(Yt,"publicOrigin");function Jt(a,r,u){if(!r||!a)return!1;const d=a.status==="attention"||a.status==="revoked";return a.provider==="github"&&d&&!a.providerAccountId&&!a.botExternalId?!1:d||u&&(a.status==="active"||a.status==="paused")}t(Jt,"isChatEndpointRepairing");function Xt({provider:a,onChat:r,onTools:u}){const{setBreadcrumbs:d}=De();return(0,c.useEffect)(()=>(d([{label:"Connectors",href:"/apps"},{label:"Choose connection"}]),()=>d([])),[d]),(0,e.jsxs)("div",{className:"max-w-2xl space-y-6",children:[(0,e.jsx)(Ve,{labels:a==="slack"?["Choose agent","App configuration access token","Install Slack app","Send a message"]:void 0,step:0,availableStep:0,onSelect:r}),(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:"Choose how to connect"}),(0,e.jsxs)("p",{className:"mt-1 text-sm text-ink-3",children:["What should this ",Ne[a]," connection do?"]})]}),(0,e.jsxs)("div",{className:"grid gap-3",children:[(0,e.jsxs)("button",{type:"button",className:"flex items-center gap-4 rounded-xl border border-line p-4 text-left hover:bg-bg-3/40",onClick:r,children:[(0,e.jsx)(ut,{size:48}),(0,e.jsxs)("span",{children:[(0,e.jsx)("span",{className:"block text-sm font-semibold",children:"Chat with an agent"}),(0,e.jsxs)("span",{className:"mt-1 block text-sm text-ink-3",children:["People in ",Ne[a]," can start and continue Wardmote tasks."]})]})]}),(0,e.jsxs)("button",{type:"button",className:"flex items-center gap-4 rounded-xl border border-line p-4 text-left hover:bg-bg-3/40",onClick:u,children:[(0,e.jsx)("span",{className:"flex size-12 shrink-0 items-center justify-center text-ink-3","aria-hidden":"true",children:(0,e.jsx)(at,{className:"size-8"})}),(0,e.jsxs)("span",{children:[(0,e.jsx)("span",{className:"block text-sm font-semibold",children:"Use this connection as an agent tool"}),(0,e.jsxs)("span",{className:"mt-1 block text-sm text-ink-3",children:["Let agents use ",Ne[a]," actions and data while they work."]})]})]})]})]})}t(Xt,"ChatConnectionPurpose");function Os(){const[a]=Ue();return a.get("provider")==="github"?(0,e.jsx)(Ot,{}):a.get("provider")==="agentmail"?(0,e.jsx)(At,{}):(0,e.jsx)(Zt,{})}t(Os,"ChatEndpointSetup");function Zt(){const[a,r]=Ue(),u=Le(),d=We(),{selectedCompanyId:U}=He(),{setBreadcrumbs:A}=De(),{pushToast:b}=Be(),i=Qt(a.get("provider"))?a.get("provider"):null,g=a.get("toolHref")||"/apps",y=a.get("agentId")??"",h=a.get("resume")??"",l=a.get("reconnect")==="1",[q,C]=(0,c.useState)(a.get("purpose")==="chat"?"chat":"choice"),[S,G]=(0,c.useState)(y),[te,T]=(0,c.useState)(a.get("stage")==="credentials"),[z,j]=(0,c.useState)(null),[k,P]=(0,c.useState)(!1),[_,M]=(0,c.useState)(!1),[K,O]=(0,c.useState)(null),[s,N]=(0,c.useState)(null),[J,f]=(0,c.useState)({}),[X,L]=(0,c.useState)(""),[Z,v]=(0,c.useState)(null);(0,c.useEffect)(()=>(A([{label:"Connectors",href:"/apps"},{label:"Connect chat"}]),()=>A([])),[A]);const re=ce({queryKey:["chat-endpoint-setup-agents",U],queryFn:t(()=>Pe.list(U),"queryFn"),enabled:!!U}),B=ce({queryKey:["chat-endpoint-setup-resume",h],queryFn:t(()=>W.get(h),"queryFn"),enabled:!!h,refetchInterval:t(n=>["creating","install","credentials_saved"].includes(n.state.data?.setup?.slackRegistration?.status??"")?1500:!1,"refetchInterval")});(0,c.useEffect)(()=>{B.data&&(N(n=>(n?.setup?.slackSetupMethod==="automatic"&&!n.providerAccountId&&B.data.providerAccountId&&j(null),B.data)),G(B.data.assignedAgentId),C("chat"))},[B.data]);const F=ce({queryKey:["chat-endpoint-github-webhook-verification",s?.id],queryFn:t(()=>W.get(s.id),"queryFn"),enabled:!!(i==="github"&&s?.id&&s.setup?.step==="provider_setup"&&s.setup?.webhookSecretConfigured&&!s.setup.webhookVerifiedAt),refetchInterval:1500});(0,c.useEffect)(()=>{!F.data||i!=="github"||!s||s.id!==F.data.id||s.setup?.step!=="provider_setup"||!s.setup?.webhookSecretConfigured||s.setup.webhookVerifiedAt||N(F.data)},[s,F.data,i]);const x=ce({queryKey:ge.instance.experimentalSettings,queryFn:t(()=>ht.getExperimental(),"queryFn"),enabled:s?.setup?.step==="test"}),oe=(0,c.useMemo)(()=>(re.data??[]).filter(n=>Wt(n.status)),[re.data]),$=re.data?.find(n=>n.id===S),D=K?.agentId===S?K.app:s?.setup?.slackApp??Ke($?.name??s?.assignedAgentName??""),w=Fe.safeParse(D),fe=!_&&(!s||s.status==="draft"&&!s.botExternalId&&(!s.setup?.slackRegistration||s.setup.slackRegistration.status==="failed")),m=t((n,I=!1)=>{n.setup?.slackSetupMethod==="automatic"&&n.setup.slackRegistration?.status==="configured"&&s?.setup?.slackRegistration?.status!=="configured"&&j(null),N(ae=>I&&ae?.id!==n.id?ae:n),d.setQueryData(["chat-endpoint-setup-resume",n.id],n),d.setQueryData(ge.chatEndpoints.detail(n.id),n),n.provider==="github"&&d.setQueryData(["chat-endpoint-github-webhook-verification",n.id],n)},"syncEndpointSnapshot"),H=ye({mutationFn:t(()=>W.create(U,{provider:i,assignedAgentId:S,...i==="slack"?{slackApp:w.success?w.data:D}:{}}),"mutationFn"),onSuccess:t(n=>{if(j(null),m(n),n.provider==="imessage-photon"||n.provider==="slack"||n.provider==="openwa"){const I=new URLSearchParams(a);I.set("resume",n.id),r(I,{replace:!0})}},"onSuccess"),onError:t(n=>b({title:"Couldn't start setup",body:n instanceof Error?n.message:"Try again.",tone:"error"}),"onError")}),le=ye({scope:{id:`slack-app-details:${s?.id}`},mutationFn:t(n=>W.update(s.id,{slackApp:n}),"mutationFn"),onSuccess:t(n=>m(n),"onSuccess")}),he=t(async()=>{s&&fe&&w.success&&JSON.stringify(w.data)!==JSON.stringify(s.setup?.slackApp)&&await le.mutateAsync(w.data)},"persistSlackDetails"),pe=t(async n=>{if(n&&i!=="slack"){u("/apps");return}if(!s){if(!S){n&&u("/apps");return}H.mutate(void 0,{onSuccess:t(()=>{n&&u("/apps")},"onSuccess")});return}try{i==="slack"&&await he()}catch{return}n?u("/apps"):j(1)},"continueFromAgent"),E=ye({mutationFn:t(async({action:n,values:I})=>{const ae=s.id;try{return i==="openwa"?await W.setup(ae,Vt(n,I)):await W.setup(ae,i==="imessage-photon"?{action:n,...I?.projectSecret?{credentials:{projectSecret:I.projectSecret}}:{},...I?.projectId&&I.allocation==="shared"?{photon:{allocation:"shared",projectId:I.projectId}}:I?.projectId&&I?.lineId?{photon:{allocation:"dedicated",projectId:I.projectId,lineId:I.lineId}}:{}}:{action:n,credentials:I})}catch(de){if(n==="verify"){const ke=await W.get(ae).catch(()=>null);if(ke?.setup?.step==="test"||ke?.setup?.step==="complete")return ke}throw de}},"mutationFn"),onMutate:t(()=>v(null),"onMutate"),onSuccess:t(n=>{v(null),j(null),m(n),f({}),n.setup?.step!=="test"&&n.setup?.step!=="complete"&&P(!1)},"onSuccess"),onError:t((n,I)=>v(Se(n,i==="openwa"?{apiKey:I.values?.apiKey??"",adminApiKey:I.values?.adminApiKey??""}:I.values)),"onError")}),me=ye({mutationFn:t(()=>W.generateSetupSecret(s.id),"mutationFn"),onMutate:t(async()=>{const n=s.id;return await Promise.all([d.cancelQueries({queryKey:["chat-endpoint-github-webhook-verification",n],exact:!0}),d.cancelQueries({queryKey:["chat-endpoint-setup-resume",n],exact:!0}),d.cancelQueries({queryKey:ge.chatEndpoints.detail(n),exact:!0})]),{endpointId:n}},"onMutate"),onSuccess:t(async({webhookSecret:n},I,ae)=>{const de=ae.endpointId,ke=t(ne=>({...ne,setup:{...ne.setup,step:"provider_setup",webhookSecretConfigured:!0,webhookVerifiedAt:null}}),"markRotated");d.removeQueries({queryKey:["chat-endpoint-github-webhook-verification",de],exact:!0}),L(n),N(ne=>ne&&ne.id===de?ke(ne):ne),d.setQueryData(["chat-endpoint-setup-resume",de],ne=>ne&&ke(ne)),d.setQueryData(ge.chatEndpoints.detail(de),ne=>ne&&ke(ne));try{const ne=await W.get(de);m(ne,!0)}catch{}},"onSuccess"),onError:t(n=>b({title:"Couldn't generate webhook secret",body:n instanceof Error?n.message:"Try again.",tone:"error"}),"onError")}),xe=ye({mutationFn:t(()=>i==="slack"?W.finishSlackSetup(s.id):W.test(s.id),"mutationFn"),onSuccess:t(n=>{m(n),n.status==="active"&&u(`/apps/chat/${n.id}/settings`)},"onSuccess"),onError:t(n=>b({title:i==="slack"?"Couldn't finish setup":"Test not complete",body:n instanceof Error?n.message:i==="slack"?"Try finishing setup again.":"Send the provider message, then try again.",tone:"error"}),"onError")}),be=Jt(s,h,l),V=i==="slack",ee=V&&(!s||s.setup?.slackSetupMethod==="automatic"),je=ee&&(s?.setup?.step==="test"||s?.setup?.step==="complete"),ue=V?ee?3:5:2,se=s?ee&&s.setup?.slackRegistration?.status==="configured"&&s.setup.slackAccount?.status!=="linked"&&s.setup.step!=="complete"?2:!be&&(s.setup?.step==="test"||s.setup?.step==="complete")?V&&s.setup?.step!=="complete"&&!ee&&!k?4:ue:ee&&s.setup?.slackRegistration?.status==="credentials_saved"?2:V&&s.providerAccountId&&!be?3:V&&(te||be||s.setup?.slackSetupMethod==="existing"||ee&&s.setup?.slackRegistration?.appId)?2:1:0,o=Math.min(z??se,se),R=ce({queryKey:["chat-endpoint-slack-webhook-verification",s?.id],queryFn:t(()=>W.get(s.id),"queryFn"),enabled:!!(V&&o===3&&s?.setup?.step==="provider_setup"&&!s.setup.webhookVerifiedAt&&!E.isPending),refetchInterval:1500});(0,c.useEffect)(()=>{const n=R.data;!n||!s||n.id!==s.id||E.isPending||s.setup?.step!=="provider_setup"||s.setup.webhookVerifiedAt||!n.setup?.webhookVerifiedAt||N(n)},[R.data,s,E.isPending]);const we=(0,c.useRef)(null);return(0,c.useEffect)(()=>{if(!V||o!==3||s?.setup?.step!=="provider_setup"||!s.setup.webhookVerifiedAt||E.isPending)return;const n=`${s.id}:${s.setup.webhookVerifiedAt}`;we.current!==n&&(we.current=n,E.mutate({action:"verify"}))},[V,o,s,E]),i?U?q==="choice"?(0,e.jsx)(Xt,{provider:i,onChat:t(()=>C("chat"),"onChat"),onTools:t(()=>u(g),"onTools")}):(0,e.jsxs)("div",{className:je&&o===ue?"mx-auto w-full max-w-2xl space-y-6":"max-w-2xl space-y-6",children:[(0,e.jsx)(Ve,{labels:V?ee?["Choose agent","App configuration access token","Install Slack app","Send a message"]:["Choose agent","Create Slack app","Add credentials","Verify Slack connection","Connect your Slack account","Try it"]:void 0,step:o,availableStep:se,disabled:_||H.isPending||le.isPending||E.isPending||me.isPending||xe.isPending,onSelect:j}),(0,e.jsxs)("div",{className:"min-w-0 space-y-6",children:[o===0?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:"Which agent do you want to chat with?"}),(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:"This agent is permanent for the connection. Connect another channel to represent a different agent."})]}),s?(0,e.jsx)(ie,{"aria-label":"Assigned agent",value:s.assignedAgentName??$?.name??S,readOnly:!0}):(0,e.jsx)($e,{agents:oe,value:S,onChange:G,placeholder:"Choose an active agent",emptyMessage:"No active agents are available."}),V&&($||s)&&(0,e.jsxs)(Me,{children:[(0,e.jsx)(Et,{value:D,readOnly:!fe||H.isPending,onChange:t(n=>O({agentId:S,app:n}),"onChange"),onBlur:t(()=>{he().catch(()=>{})},"onBlur")}),le.isError&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Couldn't save the Slack app details. Try again before continuing."})]}),i==="github"&&(0,e.jsx)(Qe,{agent:$}),(0,e.jsx)(Ae,{disabled:H.isPending||le.isPending,onSaveExit:t(()=>{pe(!0)},"onSaveExit"),children:(0,e.jsxs)(p,{disabled:!S||H.isPending||le.isPending||V&&!w.success,onClick:t(()=>{pe(!1)},"onClick"),children:[H.isPending&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),"Continue"]})})]}):null,s&&!(je&&o===ue)&&(0,e.jsxs)("div",{hidden:o!==1&&!(V&&(o===2||o===3)),className:"space-y-6",children:[Z?(0,e.jsxs)("div",{role:"alert",className:"rounded-lg border border-bad/30 bg-bad/10 p-4 text-sm text-bad",children:[(0,e.jsx)("p",{className:"font-medium",children:"Connection failed"}),(0,e.jsx)("p",{className:"mt-1",children:Z})]}):null,(0,e.jsx)(es,{provider:i,slackStage:o===1?"app":o===3?"finish":"credentials",onSlackCredentialsContinue:t(()=>j(3),"onSlackCredentialsContinue"),onSlackVerificationContinue:t(()=>j(4),"onSlackVerificationContinue"),slackVerificationError:R.isError,onSlackAppCreated:t(()=>{T(!0),j(2);const n=new URLSearchParams(a);n.set("resume",s.id),n.set("stage","credentials"),r(n,{replace:!0})},"onSlackAppCreated"),agentName:$?.name??s.assignedAgentName,endpoint:s,onEndpointSaved:m,credentials:J,setCredentials:f,repairing:be,pending:E.isPending,onAutomaticBusy:M,generatedWebhookSecret:X,generatingSetupSecret:me.isPending,onGenerateSetupSecret:t(()=>me.mutate(),"onGenerateSetupSecret"),onAction:t((n,I)=>E.mutate({action:n,values:I}),"onAction")},`${i}:${s.id}`)]}),s&&V&&!ee&&o===4&&(0,e.jsx)(_t,{endpointId:s.id,command:s.setup?.slackApp?.command??s.setup?.command??"/wardmote",testStartedAt:s.setup?.testStartedAt,onSaveExit:t(()=>u("/apps"),"onSaveExit"),onConnected:t(()=>{P(!0),j(5)},"onConnected")}),s&&o===ue&&(!ee||je)&&(ee?(0,e.jsxs)("div",{className:"flex flex-col items-center gap-6 py-8 text-center",children:[(0,e.jsx)(wt,{agent:$??{id:s.assignedAgentId,name:s.assignedAgentName},size:256,state:"success",trackingScope:"page",label:`${$?.name??s.assignedAgentName} avatar`}),(0,e.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[(0,e.jsxs)("h1",{className:"flex items-center gap-2 text-2xl font-bold",children:[(0,e.jsx)(Re,{"aria-hidden":"true",className:"size-6 text-(--status-task-done)"}),"Success"]}),(0,e.jsxs)("p",{className:"flex flex-wrap items-center justify-center gap-2 text-base text-ink-3",children:[(0,e.jsxs)("span",{children:["You can now talk to ",$?.name??s.assignedAgentName," in Slack"]}),(0,e.jsx)("img",{src:"/brands/apps/slack.svg",alt:"","aria-hidden":"true",className:"size-6"})]})]}),(0,e.jsxs)(p,{disabled:xe.isPending,onClick:t(()=>xe.mutate(),"onClick"),children:[xe.isPending&&(0,e.jsx)(Y,{className:"size-4 animate-spin"}),"Done"]})]}):(0,e.jsx)(ts,{endpointId:s.id,provider:i,agentName:$?.name??s.assignedAgentName,botLabel:s.botLabel,botUsername:s.botUsername,botExternalId:s.botExternalId,slackAccount:s.setup?.slackAccount,photonAllocation:s.photonAllocation,providerUrl:s.setup?.slackAccount?.dmChannelId&&s.providerAccountId?`https://app.slack.com/client/${encodeURIComponent(s.providerAccountId)}/${encodeURIComponent(s.setup.slackAccount.dmChannelId)}`:s.setup?.providerUrl,guestIsolationState:x.isPending?"loading":x.isError?"unknown":x.data?.enableIsolatedWorkspaces===!0?"enabled":"disabled",pending:xe.isPending,onOpenAccess:t(()=>u(`/apps/chat/${s.id}/access`),"onOpenAccess"),onTest:t(()=>xe.mutate(),"onTest"),onSaveExit:t(()=>u("/apps"),"onSaveExit")})),o!==0&&!V&&!(i==="openwa"&&o===1)&&(0,e.jsx)("div",{className:"flex justify-start",children:(0,e.jsx)(p,{variant:"ghost",onClick:t(()=>u("/apps"),"onClick"),children:"Save & exit"})})]})]}):(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Select an organization to connect chat."}):(0,e.jsx)("p",{className:"text-sm text-bad",children:"This chat provider is not supported."})}t(Zt,"ChatSdkEndpointSetup");function es({provider:a,slackStage:r,onSlackCredentialsContinue:u,onSlackVerificationContinue:d,slackVerificationError:U,onSlackAppCreated:A,agentName:b,endpoint:i,credentials:g,setCredentials:y,repairing:h,pending:l,onAutomaticBusy:q,onEndpointSaved:C,generatedWebhookSecret:S,generatingSetupSecret:G,onGenerateSetupSecret:te,onAction:T}){const{pushToast:z}=Be(),j=Le(),k=(g.botToken??"").trim(),P=a==="slack"&&k.length>0&&!k.startsWith("xoxb-"),_=a==="slack"&&/^x[a-z0-9]*-/i.test((g.signingSecret??"").trim()),M=a==="slack"&&!!i.providerAccountId,K=M&&!h&&!k&&!g.signingSecret?.trim(),O=t(()=>z({title:"Couldn't copy to clipboard",body:"Select and copy the value manually.",tone:"error"}),"reportCopyFailure"),s=t((n,I,ae="password")=>(0,e.jsxs)("label",{className:"grid gap-2 text-sm font-medium",children:[I,(0,e.jsx)(ie,{type:ae,value:g[n]??"",onChange:t(de=>y({...g,[n]:de.target.value}),"onChange")})]}),"field"),N=t(n=>window.open(i.setup?.authorizationUrl??i.setup?.providerUrl??n,"_blank","noopener,noreferrer"),"openProviderSetup"),J=t((n,I)=>(0,e.jsxs)("div",{className:"grid gap-2",children:[(0,e.jsx)("p",{className:"text-sm font-medium",children:n}),(0,e.jsx)("div",{className:"rounded-lg border border-line bg-bg-3 p-3 font-mono text-xs break-all",children:I??"This endpoint is unavailable. Check the server's public URL."})]}),"endpointValue"),[f,X]=(0,c.useState)(!1),L=Ct(),[Z,v]=(0,c.useState)(!1),re=(0,c.useRef)(null);(0,c.useEffect)(()=>(v(!1),()=>{re.current!==null&&(clearTimeout(re.current),re.current=null)}),[r]);const[B,F]=(0,c.useState)(!1),[x,oe]=(0,c.useState)(null),[$,D]=(0,c.useState)(!1),[w,fe]=(0,c.useState)(!1),m=(0,c.useRef)(null),H=(0,c.useRef)(qt()).current;(0,c.useEffect)(()=>()=>{H.invalidate()},[H]);const le=t(async n=>{const I=n.currentTarget.files?.[0];if(n.currentTarget.value="",!I)return;const ae=H.start();oe(null),D(!1),fe(!0);try{const de=await Bt(I);if(!H.isCurrent(ae))return;y(ke=>({...ke,privateKey:de})),F(!1),D(!0)}catch(de){if(!H.isCurrent(ae))return;oe(de instanceof Error?de.message:"Wardmote couldn't read that file. Choose the .pem file again or paste the private key.")}finally{H.isCurrent(ae)&&fe(!1)}},"loadPrivateKeyFile"),he=t(n=>{H.invalidate(),oe(null),D(!1),fe(!1),y(I=>({...I,privateKey:n}))},"replacePrivateKey"),pe=i.setup?.slackApp??{...Ke(b),...i.setup?.command?{command:i.setup.command}:{}},E=i.setup?.slackSetupMethod==="automatic",me=Fe.safeParse(pe),xe=t(()=>j("/apps"),"saveSlackAndExit"),be=pe.appName.trim(),V=pe.botName.trim(),ee=pe.command.trim(),je=i.setup?.webhookUrl??"<wardmote-webhook-url>",ue=JSON.stringify(Xe({app:{appName:be,botName:V,command:ee},agentName:b,webhookUrl:je,...E&&i.setup?.slackOAuthCallbackUri?{redirectUri:i.setup.slackOAuthCallbackUri}:{}}),null,2),se=`https://api.slack.com/apps?new_app=1&manifest_json=${encodeURIComponent(ue)}`;(0,c.useEffect)(()=>X(!1),[ue]);const o=g.clientId?.trim()||"<application-client-id>",R=JSON.stringify({bots:[{botId:o,scopes:["personal","team","groupChat"],supportsFiles:!0,isNotificationOnly:!1,commandLists:[{scopes:["personal","groupChat"],commands:[{title:"/status",description:"Show the active Wardmote task status"},{title:"/new",description:"Start a new Wardmote task in this chat"},{title:"/close",description:"Close the active chat conversation"}]}]}],webApplicationInfo:{id:o,resource:"https://paperclip.ing"},authorization:{permissions:{resourceSpecific:[{name:"ChannelMessage.Read.Group",type:"Application"},{name:"ChatMessage.Read.Chat",type:"Application"}]}}},null,2);if(a==="imessage-photon")return(0,e.jsx)(Gt,{endpoint:i,agentName:b,repairing:h,pending:l,onAction:T});if(a==="openwa")return(0,e.jsx)(Ht,{endpoint:i,agentName:b,repairing:h,pending:l,onAction:T,onSaveExit:t(()=>j("/apps"),"onSaveExit")});if(a==="discord"){const n=g.applicationId?.trim()??"",I=g.guildId?.trim()??"",ae=n?`https://discord.com/oauth2/authorize?client_id=${encodeURIComponent(n)}&permissions=309237763136&scope=bot${I?`&guild_id=${encodeURIComponent(I)}&disable_guild_select=true`:""}`:null;return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("h1",{className:"text-xl font-bold",children:["Connect ",b," to Discord"]}),(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:h?"Reconnect verifies this same Discord application and server installation. It does not add or remove the bot from the server. Leave fields blank to reuse saved credentials.":"Create one dedicated Discord application and bot for this Wardmote agent."})]}),(0,e.jsxs)("ol",{className:"list-decimal space-y-2 pl-5 text-sm",children:[(0,e.jsx)("li",{children:"In Discord Developer Portal, create an application. Copy its Application ID from General Information."}),(0,e.jsx)("li",{children:"Open Bot, create the bot, enable Message Content Intent, then reset and copy its token."}),(0,e.jsx)("li",{children:"Enable Developer Mode in Discord, right-click the target server, and copy its Server ID."}),(0,e.jsx)("li",{children:"Enter those values below, then use the generated install link to add the bot to that server."})]}),(0,e.jsxs)(p,{variant:"secondary",onClick:t(()=>N("https://discord.com/developers/applications"),"onClick"),children:["Open Discord Developer Portal ",(0,e.jsx)(Q,{})]}),s("applicationId","Application ID","text"),s("guildId","Server ID","text"),s("botToken","Bot token"),ae&&(0,e.jsx)(p,{asChild:!0,variant:"secondary",children:(0,e.jsxs)("a",{href:ae,target:"_blank",rel:"noreferrer",children:["Install bot in this server ",(0,e.jsx)(Q,{})]})}),(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"The install link grants only View Channels, Send Messages, Create Public Threads, Send Messages in Threads, Read Message History, Add Reactions, Embed Links, and Attach Files. Wardmote still requires each discovered channel to be enabled in Access."}),(0,e.jsxs)(p,{disabled:!h&&(!g.applicationId||!g.guildId||!g.botToken)||l,onClick:t(()=>T(h?"reconnect":"configure",g),"onClick"),children:[l&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),h?"Reconnect Discord bot":"Connect Discord bot"]})]})}if(a==="telegram")return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("h1",{className:"text-xl font-bold",children:["Create ",b," in Telegram"]}),(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:h?"Reconnect verifies this same BotFather bot and automatically refreshes its Wardmote webhook and command menu. It does not recreate the bot or change its chat memberships. Leave the token blank to reuse the saved credential.":"Create a bot with BotFather, then paste the token it gives you."})]}),(0,e.jsxs)("ol",{className:"list-decimal space-y-2 pl-5 text-sm",children:[(0,e.jsxs)("li",{children:["Open BotFather and send ",(0,e.jsx)("code",{children:"/newbot"}),"."]}),(0,e.jsx)("li",{children:"Enter the bot display name."}),(0,e.jsxs)("li",{children:["Choose an available username ending in ",(0,e.jsx)("code",{children:"bot"}),"."]})]}),(0,e.jsxs)("p",{className:"rounded-md border border-line bg-bg-3/40 p-3 text-sm text-ink-3",children:["Wardmote works with Telegram's default bot privacy mode and registers its command menu automatically. In a group, ordinary mentions are not delivered to bots: start or continue work with"," ",(0,e.jsx)("code",{children:"/task@bot_username <request>"}),", or reply directly to a message from the bot."]}),(0,e.jsxs)(p,{variant:"secondary",onClick:t(()=>N("https://t.me/BotFather"),"onClick"),children:["Open BotFather ",(0,e.jsx)(Q,{})]}),s("botToken","Bot token"),(!i.setup?.webhookUrl||E&&!i.setup?.slackOAuthCallbackUri?.startsWith("https://"))&&(0,e.jsx)("p",{className:"text-sm text-bad",children:"Configure a public HTTPS URL for this Wardmote instance before connecting Telegram."}),(0,e.jsxs)(p,{disabled:!h&&!g.botToken||!i.setup?.webhookUrl||l,onClick:t(()=>T(h?"reconnect":"configure",g),"onClick"),children:[l&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),h?"Reconnect bot":"Connect bot"]})]});if(a==="microsoft-teams")return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("h1",{className:"text-xl font-bold",children:["Connect ",b," to Microsoft Teams"]}),(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:h?"Reconnect verifies this same Microsoft app, tenant, and bot identity. It does not upload or reinstall the Teams app. Leave fields blank to reuse saved credentials.":"Use your own Microsoft app credentials for this bot."})]}),(0,e.jsx)("p",{className:"rounded-md border border-line bg-bg-3/40 p-3 text-sm text-ink-3",children:"This setup requires a Microsoft 365 work or school organization where you can register an Entra app, create an Azure Bot, and upload or install a Teams app. Personal or free Teams accounts at teams.live.com cannot complete this setup. This release supports Microsoft 365 commercial cloud tenants only; GCC, GCC High, DoD, and Microsoft 365 operated by 21Vianet are not supported yet."}),(0,e.jsxs)("ol",{className:"list-decimal space-y-2 pl-5 text-sm",children:[(0,e.jsx)("li",{children:"In Microsoft Entra, create a single-tenant app registration. Copy its Application (client) ID and Directory (tenant) ID, then create a client secret and copy its value."}),(0,e.jsx)("li",{children:"In Azure, create an Azure Bot. Choose Single Tenant, use that Application ID, set its messaging endpoint to the Wardmote URL below, and add the Microsoft Teams channel."}),(0,e.jsx)("li",{children:"In Teams Developer Portal, create an app, add a bot with the same Application ID, then apply the manifest settings shown below. The block binds the Teams resource-specific consent permissions to that Entra app; these are not Microsoft Graph permissions in Entra. These permissions let the installed app receive every message in a team or group chat without an @mention, so describe that access to installers. Download the package and install it in the target team or group chat."})]}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,e.jsx)(p,{asChild:!0,variant:"secondary",children:(0,e.jsxs)("a",{href:"https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade",target:"_blank",rel:"noreferrer",children:["Open Microsoft Entra ",(0,e.jsx)(Q,{})]})}),(0,e.jsx)(p,{asChild:!0,variant:"secondary",children:(0,e.jsxs)("a",{href:"https://portal.azure.com/#create/Microsoft.AzureBot",target:"_blank",rel:"noreferrer",children:["Create Azure Bot ",(0,e.jsx)(Q,{})]})}),(0,e.jsx)(p,{asChild:!0,variant:"secondary",children:(0,e.jsxs)("a",{href:"https://dev.teams.microsoft.com/apps",target:"_blank",rel:"noreferrer",children:["Open Teams Developer Portal ",(0,e.jsx)(Q,{})]})})]}),J("Wardmote messaging endpoint",i.setup?.messagingEndpoint),s("clientId","Application / Client ID","text"),s("tenantId","Directory / Tenant ID","text"),s("clientSecret","Client secret value"),(0,e.jsxs)("section",{className:"space-y-3 rounded-lg border border-line p-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"text-sm font-semibold",children:"Microsoft portal field map"}),(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:"Use these exact portal sections and reuse the same Application ID in all three places."})]}),(0,e.jsxs)("ol",{className:"list-decimal space-y-3 pl-5 text-sm",children:[(0,e.jsxs)("li",{children:[(0,e.jsx)("strong",{children:"Microsoft Entra admin center · App registrations"}),": select ",(0,e.jsx)("strong",{children:"New registration"}),", choose"," ",(0,e.jsx)("strong",{children:"Accounts in this organizational directory only (Single tenant)"}),", then select ",(0,e.jsx)("strong",{children:"Register"}),". Copy"," ",(0,e.jsx)("strong",{children:"Application (client) ID"})," and"," ",(0,e.jsx)("strong",{children:"Directory (tenant) ID"}),". Under"," ",(0,e.jsx)("strong",{children:"Certificates & secrets · Client secrets"}),", select ",(0,e.jsx)("strong",{children:"New client secret"})," and copy its"," ",(0,e.jsx)("strong",{children:"Value"}),", not its Secret ID."]}),(0,e.jsxs)("li",{children:[(0,e.jsx)("strong",{children:"Azure · Create Azure Bot"}),": set"," ",(0,e.jsx)("strong",{children:"Microsoft App ID"})," to"," ",(0,e.jsx)("strong",{children:"Single Tenant"}),", set ",(0,e.jsx)("strong",{children:"Creation type"})," ","to ",(0,e.jsx)("strong",{children:"Use existing app registration"}),", and enter the Application ID and Tenant ID above. After creation, open"," ",(0,e.jsx)("strong",{children:"Settings · Configuration"})," and paste the Wardmote"," ",(0,e.jsx)("strong",{children:"Messaging endpoint"}),"; then open"," ",(0,e.jsx)("strong",{children:"Settings · Channels"})," and enable"," ",(0,e.jsx)("strong",{children:"Microsoft Teams"}),"."]}),(0,e.jsxs)("li",{children:[(0,e.jsx)("strong",{children:"Teams Developer Portal · Apps"}),": select"," ",(0,e.jsx)("strong",{children:"New app"}),". Under"," ",(0,e.jsx)("strong",{children:"Configure · App features · Bot"}),", add an existing bot using the same Application ID; enable"," ",(0,e.jsx)("strong",{children:"Personal"}),", ",(0,e.jsx)("strong",{children:"Team"}),", and"," ",(0,e.jsx)("strong",{children:"Group chat"})," scopes plus file support. Under"," ",(0,e.jsx)("strong",{children:"Configure · Permissions"}),", add the two RSC"," ",(0,e.jsx)("strong",{children:"Application"})," permissions shown below. Complete the required app details and icons, explain that the app can receive every message in an installed team or group chat, then download the app package."]}),(0,e.jsxs)("li",{children:[(0,e.jsx)("strong",{children:"Microsoft Teams · Apps · Manage your apps"}),": select"," ",(0,e.jsx)("strong",{children:"Upload an app · Upload a custom app"}),", choose the downloaded package, and install it in each intended personal chat, group chat, or team. One team install covers its standard channels. Private and shared channels require a separate app installation and are not supported by this release. If upload is unavailable, a Teams administrator must enable or approve custom apps."]})]})]}),(0,e.jsxs)("label",{className:"grid gap-2 text-sm font-medium",children:["Required Teams app manifest block",(0,e.jsx)(Te,{className:"min-h-80 font-mono text-xs",readOnly:!0,value:R})]}),(0,e.jsx)("div",{className:"flex flex-wrap gap-2",children:(0,e.jsx)(p,{variant:"secondary",disabled:!g.clientId?.trim(),onClick:t(()=>{Ie(R).then(()=>X(!0),O)},"onClick"),children:f?"Manifest settings copied":"Copy manifest settings"})}),(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Enter the Application / Client ID above before copying so the block contains the real bot identity. This block contains the Wardmote-specific fields to verify in Developer Portal or merge into a complete Teams app manifest. It is not a complete app package; Developer Portal supplies the remaining required metadata and packages the manifest with your app icons."}),(0,e.jsxs)("p",{className:"text-sm text-ink-3",children:["Wardmote does not use Teams single sign-on in this release. The copied ",(0,e.jsx)("code",{children:"webApplicationInfo"})," entry only associates the RSC permissions with the same Entra Application ID. Its nonempty resource is an RSC placeholder; you do not need to register an Entra Application ID URI or add delegated Microsoft Graph permissions."]}),(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"The two application RSC permissions let the bot receive every message, without an @mention, in each team or group chat where it is installed. Wardmote retains and acts only on messages admitted by your Wardmote reach and access rules. Make this provider access clear in the app description shown to installers."}),(0,e.jsxs)("p",{className:"text-sm text-ink-3",children:["This release supports personal chats, group chats, and standard team channels—not private channels. ",(0,e.jsx)("code",{children:"supportsFiles: true"})," ","enables native file receipt and consent-based sending in personal chats; channel and group-chat files need a separate Microsoft Graph connection and are not ingested here."]}),!i.setup?.messagingEndpoint&&(0,e.jsx)("p",{className:"text-sm text-bad",children:"Configure a public HTTPS URL for this Wardmote instance before connecting Microsoft Teams."}),(0,e.jsxs)(p,{disabled:!h&&(!g.clientId||!g.tenantId||!g.clientSecret)||!i.setup?.messagingEndpoint||l,onClick:t(()=>T(h?"reconnect":"configure",g),"onClick"),children:[l&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),h?"Reconnect Microsoft app":"Verify Microsoft credentials"]})]});if(a==="github")return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:h?"Reconnect GitHub App":"Create or connect a GitHub App"}),(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:h?"Reconnect verifies this same App and installation, then updates its webhook URL, secret, and secure delivery settings. It does not reinstall the App or change repository access. Leave App ID and private key blank to reuse saved credentials. Keep Webhooks · Active enabled in GitHub; send a test conversation after reconnecting.":"Configure its webhook and permissions, then verify the App with Wardmote."})]}),!h&&(0,e.jsxs)("ol",{className:"list-decimal space-y-2 pl-5 text-sm",children:[(0,e.jsx)("li",{children:"Under the target user or organization, create a new GitHub App. Give it a globally unique name (34 characters or fewer), use the Wardmote homepage URL below, and leave user authorization off."}),(0,e.jsxs)("li",{children:["Keep ",(0,e.jsx)("strong",{children:"Webhooks · Active"})," on. Enter the Wardmote webhook URL and the Wardmote-generated webhook secret below, and keep ",(0,e.jsx)("strong",{children:"Enable SSL verification"})," selected."]}),(0,e.jsxs)("li",{children:["Under Repository permissions, set ",(0,e.jsx)("strong",{children:"Issues"})," and"," ",(0,e.jsx)("strong",{children:"Pull requests"})," to"," ",(0,e.jsx)("strong",{children:"Read & write"}),". Leave every other permission at its default; Metadata remains read-only."]}),(0,e.jsxs)("li",{children:["Subscribe to ",(0,e.jsx)("strong",{children:"Issue comment"})," (",(0,e.jsx)("code",{children:"issue_comment"}),"),"," ",(0,e.jsx)("strong",{children:"Pull request review comment"})," (",(0,e.jsx)("code",{children:"pull_request_review_comment"}),"). GitHub sends"," ",(0,e.jsx)("code",{children:"installation"})," and"," ",(0,e.jsx)("code",{children:"installation_repositories"})," to every GitHub App automatically; they are not selectable here."]}),(0,e.jsxs)("li",{children:["Choose ",(0,e.jsx)("strong",{children:"Only on this account"}),", create the App, copy its App ID, generate one private key, then install it on the selected repositories."]})]}),J("Wardmote homepage URL",Yt(i.setup?.webhookUrl)),J("Wardmote webhook URL",i.setup?.webhookUrl),(0,e.jsxs)(p,{variant:"secondary",onClick:t(()=>window.open(h?"https://github.com/settings/apps":i.setup?.authorizationUrl??"https://github.com/settings/apps/new","_blank","noopener,noreferrer"),"onClick"),children:[h?"Open GitHub App settings":"Open new GitHub App form"," ",(0,e.jsx)(Q,{})]}),s("appId","GitHub App ID","text"),(0,e.jsxs)("div",{className:"grid gap-2 text-sm font-medium",children:[(0,e.jsx)("label",{htmlFor:"github-private-key",children:"Private key (PEM)"}),(0,e.jsxs)("div",{className:"relative",children:[B?(0,e.jsx)(Te,{id:"github-private-key",className:"min-h-24 pr-11 font-mono text-xs",value:g.privateKey??"",onChange:t(n=>he(n.target.value),"onChange")}):(0,e.jsx)(ie,{id:"github-private-key",type:"password",className:"pr-11 font-mono text-xs",value:g.privateKey??"",onChange:t(n=>he(n.target.value),"onChange"),onPaste:t(n=>{n.preventDefault(),he(n.clipboardData.getData("text"))},"onPaste")}),(0,e.jsx)(p,{type:"button",variant:"ghost",size:"icon",className:"absolute right-1 top-1","aria-label":B?"Hide private key":"Show private key",onClick:t(()=>F(n=>!n),"onClick"),children:B?(0,e.jsx)(rt,{}):(0,e.jsx)(ot,{})})]}),(0,e.jsx)("input",{ref:m,type:"file",accept:".pem,.key,application/x-pem-file,application/pkcs8,text/plain",className:"hidden","aria-label":"Choose GitHub App private key file",onChange:le}),(0,e.jsx)("div",{children:(0,e.jsx)(p,{type:"button",variant:"secondary",onClick:t(()=>m.current?.click(),"onClick"),children:"Choose .pem file"})}),x?(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:x}):null,w?(0,e.jsx)("p",{role:"status","aria-live":"polite",className:"text-sm text-ink-3",children:"Reading private key file…"}):$?(0,e.jsx)("p",{role:"status","aria-live":"polite",className:"text-sm text-ink-3",children:"Private key loaded. It stays in this form until you connect."}):null]}),(0,e.jsxs)("div",{className:"grid gap-2",children:[(0,e.jsx)("p",{className:"text-sm font-medium",children:"Webhook secret"}),S?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(ie,{"aria-label":"Generated webhook secret",className:"font-mono text-xs",readOnly:!0,value:S}),(0,e.jsx)("div",{className:"flex flex-wrap gap-2",children:(0,e.jsx)(p,{type:"button",variant:"secondary",onClick:t(()=>{L.copy(S).then(n=>{n==="failed"&&O()})},"onClick"),children:L.copied?"Webhook secret copied":L.failed?"Couldn’t copy — select it manually":"Copy webhook secret"})}),(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Copy this value now. Wardmote will not show it again."})]}):(0,e.jsx)("p",{className:"text-sm text-ink-3",children:i.setup?.webhookSecretConfigured?"A webhook secret is configured and cannot be shown again.":"Generate the secret in Wardmote, then paste it into the GitHub App."}),(0,e.jsx)("div",{children:(0,e.jsxs)(p,{type:"button",variant:"secondary",disabled:G,onClick:te,children:[G&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),i.setup?.webhookSecretConfigured?"Regenerate webhook secret":"Generate webhook secret"]})}),i.setup?.webhookSecretConfigured&&(0,e.jsx)("p",{className:"text-sm text-ink-3",children:i.providerAccountId||i.botExternalId?"Regenerating immediately invalidates GitHub webhook signatures until you replace the secret in the GitHub App settings.":"Generating another secret replaces the previous value. Paste the newest value into GitHub before continuing."}),i.setup?.webhookSecretConfigured&&(0,e.jsx)("p",{className:`text-sm ${i.setup.webhookVerifiedAt?"text-ink":"text-ink-3"}`,children:i.setup.webhookVerifiedAt?"GitHub has verified this webhook.":"Waiting for GitHub to deliver its signed webhook ping…"})]}),(!i.setup?.webhookUrl||E&&!i.setup?.slackOAuthCallbackUri?.startsWith("https://"))&&(0,e.jsx)("p",{className:"text-sm text-bad",children:"Configure a public HTTPS URL for this Wardmote instance before connecting GitHub."}),(0,e.jsxs)(p,{disabled:!h&&(!g.appId||!g.privateKey)||!i.setup?.webhookSecretConfigured||!i.setup?.webhookVerifiedAt||!i.setup?.webhookUrl||w||G||l,onClick:t(()=>T(h?"reconnect":"configure",g),"onClick"),children:[l&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),h?"Reconnect and verify":"Connect and verify"]})]});const we=(0,e.jsxs)("ol",{className:"list-decimal space-y-2 pl-5 text-sm",children:[(0,e.jsxs)("li",{children:[(0,e.jsxs)("a",{className:"underline underline-offset-4",href:i.setup?.slackRegistration?.appId?`https://api.slack.com/apps/${encodeURIComponent(i.setup.slackRegistration.appId)}/event-subscriptions`:"https://api.slack.com/apps",target:"_blank",rel:"noopener noreferrer",children:["Open Slack app Settings ",(0,e.jsx)(Q,{className:"inline size-3"})]})," and choose ",(0,e.jsx)("strong",{children:pe.appName}),"."]}),(0,e.jsxs)("li",{children:["Choose ",(0,e.jsx)("strong",{children:"Event Subscriptions"}),"."]}),(0,e.jsxs)("li",{children:["Beside the prefilled ",(0,e.jsx)("strong",{children:"Request URL"}),", click ",(0,e.jsx)("strong",{children:"Retry"})," if it isn't verified. Save changes if Slack asks."]})]});return r==="finish"?(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:E?"Send a message to your agent":"Verify Slack connection"}),!E&&(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:"Slack needs to confirm that it can reach your Wardmote instance."})]}),E?(0,e.jsx)(p,{asChild:!0,variant:"secondary",children:(0,e.jsxs)("a",{href:i.setup?.slackAccount?.dmChannelId&&i.providerAccountId?`https://app.slack.com/client/${encodeURIComponent(i.providerAccountId)}/${encodeURIComponent(i.setup.slackAccount.dmChannelId)}`:i.setup?.providerUrl??"https://app.slack.com",target:"_blank",rel:"noopener noreferrer",children:["Open Slack ",(0,e.jsx)(Q,{className:"size-4"})]})}):we,i.setup?.webhookVerifiedAt?(0,e.jsxs)("p",{role:"status",className:"flex items-center gap-2 text-sm",children:[(0,e.jsx)(Re,{className:"size-4 text-(--status-task-done)"}),"Your Slack connection is working.",l?E?" Finishing setup…":" Opening the message test…":""]}):U?(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Couldn't check verification. We'll keep trying; check your connection if this continues."}):(0,e.jsxs)("p",{role:"status",className:"flex items-center gap-2 text-sm text-ink-3",children:[(0,e.jsx)(Y,{className:"size-4 animate-spin"})," ",E?"Waiting for your message…":"Waiting for Slack. We’ll continue automatically."]}),(0,e.jsxs)(Me,{label:E?"Didn’t work?":"Troubleshooting",children:[E&&we,(0,e.jsx)("p",{className:"text-ink-3",children:"If the Request URL is missing or different, paste this URL into Event Subscriptions. If verification fails, check that your public HTTPS server is reachable and your Signing Secret is correct."}),J("Wardmote webhook URL",i.setup?.webhookUrl)]}),(0,e.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,e.jsx)(p,{variant:"ghost",onClick:t(()=>j("/apps"),"onClick"),children:"Save & exit"}),(!E||i.setup?.webhookVerifiedAt)&&(0,e.jsxs)(p,{disabled:l||!i.setup?.webhookVerifiedAt,onClick:t(()=>i.setup?.step==="provider_setup"?T("verify"):d(),"onClick"),children:[l&&(0,e.jsx)(Y,{className:"size-4 animate-spin"}),"Continue"]})]})]}):(0,e.jsxs)("div",{className:"space-y-5",children:[(!i.setup?.webhookUrl||E&&!i.setup?.slackOAuthCallbackUri?.startsWith("https://"))&&(0,e.jsxs)("div",{role:"alert",className:"flex items-start gap-3 rounded-lg border border-bad/30 bg-bad/10 p-4",children:[(0,e.jsx)(ze,{className:"size-5 shrink-0 text-bad"}),(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsx)("p",{className:"text-sm font-semibold",children:"Public HTTPS URL required"}),(0,e.jsx)("p",{className:"text-sm",children:"Slack needs a public HTTPS URL to send messages to Wardmote. Configure one for this instance before creating or connecting your Slack app."}),(0,e.jsx)("a",{href:"https://github.com/tickernelz/wardmote/blob/main/docs/deploy/deployment-modes.md",target:"_blank",rel:"noopener noreferrer",className:"text-sm underline underline-offset-4",children:"Learn how to set up HTTPS"})]})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:r==="app"?E?"App configuration access token":"Create a Slack app":E?"Install Slack app":"Add Slack credentials"}),h&&!E&&(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:"Reconnect verifies or replaces credentials for this same Slack app. It does not reinstall the app or change its workspace or channel membership. Leave credentials blank to reuse the saved values."})]}),(0,e.jsxs)("div",{hidden:r!=="app"||E,className:"space-y-5",children:[(0,e.jsx)("div",{className:"space-y-3 text-sm",children:(0,e.jsx)("div",{className:"flex justify-end",children:(0,e.jsxs)(jt,{children:[(0,e.jsx)(gt,{asChild:!0,children:(0,e.jsx)(p,{variant:"link",className:"h-auto p-0 text-xs underline underline-offset-4",children:"View Slack App Manifest"})}),(0,e.jsxs)(bt,{className:"sm:max-w-2xl",children:[(0,e.jsxs)(xt,{children:[(0,e.jsx)(yt,{children:"Slack app manifest"}),(0,e.jsx)(kt,{children:"Generated from your app name, bot name, and slash command. Edit those fields to update the manifest."})]}),(0,e.jsx)(Te,{"aria-label":"Slack app manifest",className:"h-80 font-mono text-xs",readOnly:!0,value:ue}),(0,e.jsx)(ft,{children:(0,e.jsx)(p,{variant:"secondary",disabled:!me.success,onClick:t(()=>{Ie(ue).then(()=>X(!0),O)},"onClick"),children:f?"Manifest copied":"Copy manifest"})})]})]})})}),!E&&(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 pt-3",children:[(0,e.jsx)(p,{variant:"ghost",onClick:t(()=>{xe()},"onClick"),children:"Save & exit"}),(0,e.jsxs)("div",{className:"ml-auto flex flex-wrap items-center justify-end gap-2",children:[(0,e.jsx)(p,{variant:"secondary",disabled:Z||!i.setup?.webhookUrl||!me.success,onClick:A,children:"I already created the app"}),!h&&(0,e.jsxs)(p,{disabled:Z||!i.setup?.webhookUrl||!me.success,onClick:t(()=>{window.open(se,"_blank","noopener,noreferrer"),v(!0),re.current=setTimeout(()=>{re.current=null,v(!1),A()},1e3)},"onClick"),children:["Create Slack app ",(0,e.jsx)(Q,{})]})]})]})]}),E&&(0,e.jsx)(Lt,{endpoint:i,stage:r,disabled:!i.setup?.webhookUrl||!i.setup?.slackOAuthCallbackUri?.startsWith("https://")||!me.success,saveDetails:t(async()=>{},"saveDetails"),onBusy:q,onSaved:C,onContinue:A,onManual:t(async n=>{C(await W.update(i.id,{slackSetupMethod:n?"existing":"manual"})),n&&A()},"onManual"),onSaveExit:t(()=>{xe()},"onSaveExit")},i.id),!E&&(0,e.jsxs)("div",{hidden:r!=="credentials",className:"space-y-5",children:[(0,e.jsx)("p",{className:"text-sm",children:"Now you need to find two secrets. They are in two different screens on Slack."}),M&&!h&&(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Your credentials are saved. Leave the fields blank to keep them, or enter replacements."}),(0,e.jsxs)("section",{className:"space-y-3",children:[(0,e.jsx)("h2",{className:"text-sm font-semibold",children:(0,e.jsx)("label",{htmlFor:"slack-bot-token",children:"Bot User OAuth Token"})}),(0,e.jsxs)("ul",{id:"slack-bot-token-help",className:"list-disc space-y-1 pl-5 text-sm",children:[(0,e.jsxs)("li",{children:[(0,e.jsxs)("a",{href:"https://api.slack.com/apps",target:"_blank",rel:"noopener noreferrer",className:"underline underline-offset-4",children:["Open Slack app Settings ",(0,e.jsx)(Q,{className:"inline size-3"})]})," and choose ",(0,e.jsx)("strong",{children:pe.appName}),"."]}),(0,e.jsxs)("li",{children:["Choose ",(0,e.jsx)("strong",{children:"OAuth & Permissions"})]}),(0,e.jsxs)("li",{children:["Copy and paste your ",(0,e.jsx)("strong",{children:"Bot OAuth Token"})]})]}),(0,e.jsx)(ie,{id:"slack-bot-token",type:"password",placeholder:M?"Saved — leave blank to keep":void 0,value:g.botToken??"","aria-invalid":P||void 0,"aria-describedby":`slack-bot-token-help${P?" slack-bot-token-warning":""}`,onChange:t(n=>y({...g,botToken:n.target.value}),"onChange")}),P&&(0,e.jsxs)("p",{id:"slack-bot-token-warning",role:"alert",className:"text-sm text-bad",children:["Your Bot User OAuth Token must start with ",(0,e.jsx)("code",{children:"xoxb-"}),". Copy it from ",(0,e.jsx)("strong",{children:"OAuth & Permissions"}),"."]})]}),(0,e.jsxs)("section",{className:"space-y-3",children:[(0,e.jsx)("h2",{className:"text-sm font-semibold",children:(0,e.jsx)("label",{htmlFor:"slack-signing-secret",children:"Signing Secret"})}),(0,e.jsxs)("ul",{id:"slack-signing-secret-help",className:"list-disc space-y-1 pl-5 text-sm",children:[(0,e.jsxs)("li",{children:[(0,e.jsxs)("a",{href:"https://api.slack.com/apps",target:"_blank",rel:"noopener noreferrer",className:"underline underline-offset-4",children:["Open Slack app Settings ",(0,e.jsx)(Q,{className:"inline size-3"})]})," and choose ",(0,e.jsx)("strong",{children:pe.appName}),"."]}),(0,e.jsxs)("li",{children:["Choose ",(0,e.jsx)("strong",{children:"Basic Information"})]}),(0,e.jsxs)("li",{children:["Copy and paste your ",(0,e.jsx)("strong",{children:"Signing Secret"})]})]}),(0,e.jsx)(ie,{id:"slack-signing-secret",type:"password",placeholder:M?"Saved — leave blank to keep":void 0,value:g.signingSecret??"","aria-invalid":_||void 0,"aria-describedby":`slack-signing-secret-help${_?" slack-signing-secret-warning":""}`,onChange:t(n=>y({...g,signingSecret:n.target.value}),"onChange")}),_&&(0,e.jsxs)("p",{id:"slack-signing-secret-warning",role:"alert",className:"text-sm text-bad",children:["Use the ",(0,e.jsx)("strong",{children:"Signing Secret"}),", NOT an app or bot token. The Signing Secret has no token prefix."]})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,e.jsx)(p,{variant:"ghost",onClick:t(()=>j("/apps"),"onClick"),children:"Save & exit"}),(0,e.jsxs)(p,{className:"ml-auto",disabled:!h&&!M&&(!k||!g.signingSecret?.trim())||!i.setup?.webhookUrl||!me.success||l||_||P,onClick:t(()=>K?u():T(h||M?"reconnect":"configure",g),"onClick"),children:[l&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),K?"Continue":h||M?"Reconnect Slack app":"Connect Slack app"]})]})]})]})}t(es,"ProviderConnectStep");function ts({endpointId:a,provider:r,agentName:u,botLabel:d,botUsername:U,botExternalId:A,slackAccount:b,photonAllocation:i,providerUrl:g,guestIsolationState:y,pending:h,onOpenAccess:l,onTest:q,onSaveExit:C}){const[S,G]=(0,c.useState)(!1),[te,T]=(0,c.useState)(!1),z=ce({queryKey:ge.chatEndpoints.principals(a),queryFn:t(()=>W.listPrincipals(a),"queryFn"),enabled:r!=="slack",refetchInterval:1500}),[j,k]=(0,c.useState)(!1),[P,_]=(0,c.useState)(null),M=z.data??[],K=M.filter(v=>v.status!=="linked"),O=r==="imessage-photon"?"send a fresh message to your Photon number":r==="openwa"?"send a fresh WhatsApp message to the connected number":r==="telegram"?"start a fresh conversation with /new and send the test message again":r==="github"?"start a new issue or pull request conversation and mention the agent again":r==="microsoft-teams"?"start a new channel post and mention the agent again":"send a new root mention to the agent",s=r==="slack"||r==="openwa"?null:r==="imessage-photon"&&z.isSuccess&&(M.length===0||K.length>0)?{tone:"info",title:"Link your Messages identity",body:"Send one message to discover your phone number or Apple account address, then link that exact identity in Access. Send a fresh request after linking; earlier messages do not start work."}:z.isError?{tone:"warning",title:"Identity readiness could not be checked",body:`Review Access before expecting an agent reply. After linking the account you are testing, ${O}.`}:!z.isSuccess||y==="loading"?null:M.length===0?y==="disabled"?{tone:"warning",title:"Link the account you’re testing",body:r==="telegram"?"Tap Start in Telegram to discover your account; the welcome does not start an agent run. Link the account privately in Access, then return and send the test message.":`Your first ${Ne[r]} message discovers the external account, but isolated guest work is off, so it cannot safely start ${u}. Send it once, link that account privately in Access, then ${O}.`}:{tone:"info",title:"Your first message identifies your account",body:r==="telegram"?"Tap Start in Telegram to discover your account. Until linked, it is a restricted guest and still needs a sandbox-backed isolated run; test that path intentionally, or link it in Access and then send the test message.":`Until linked, the account is a restricted guest and still needs a sandbox-backed isolated run. Test that guest path intentionally, or link the account in Access and then ${O}.`}:K.length>0?y==="disabled"?{tone:"warning",title:"Link the account you’re testing",body:`An observed external account is unlinked, and isolated guest work is off, so it cannot safely start ${u}. Link the account in Access, then ${O}; Wardmote does not replay the refused request.`}:{tone:"info",title:"Unlinked identity detected",body:`An unlinked account is a restricted guest and still needs a sandbox-backed isolated run. Test guest access intentionally, or link the account in Access and then ${O}.`}:null,N=U?.replace(/^@/,""),J=r==="github"?N?.replace(/\[bot\]$/i,""):N,f=J?`@${J}`:d??u,X=b?.status==="linked"?"you there?":`${f.startsWith("@")?f:`@${f}`} you there?`,L=A?Je(A):"the connected number",Z=r==="openwa"?["Owners are linked in Settings. Only an owner's message completes this test.",`Send a WhatsApp message from an owner's phone to ${L}.`,"Wait for the agent’s actual reply. Setup completes after that reply is delivered."]:r==="imessage-photon"?[i==="shared"?"In your Photon project, enroll your sender in Users and find its assigned number in Get started. Send a fresh message to that number from Apple Messages.":`Open Apple Messages and send a fresh message to ${U??d??"the dedicated number"}.`,"Link the discovered sender to a Wardmote person in Access, then send a fresh request.","Wait for the agent’s actual reply. Setup completes after that reply is delivered.",...i==="shared"?["This Pro-compatible channel supports DMs only. Group messages cannot start work."]:["For a group: add the number in Messages, send a message, enable the discovered group in Settings, then send a fresh request."]]:r==="discord"?["Open a text channel where the bot is installed.",`Mention ${f} in a new root message.`,`Reply once inside ${u}'s new Discord thread.`]:r==="telegram"?["Open the bot's private chat.","Tap Start.","Send “Help me test this”."]:r==="github"?["Open an installed issue or pull request.",`Mention ${f} in a comment.`,"Add another comment to continue the same task."]:r==="microsoft-teams"?["Open an installed channel and start a new post.",`Mention ${f} in the post.`,"Reply once beneath the post."]:[`Open a channel and invite ${f} if needed.`,`Mention ${f} in a new channel message.`,`Reply once in ${u}'s thread.`];return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("h1",{className:"text-xl font-bold",children:["Try ",u," in ",Ne[r]]}),r!=="slack"&&(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:"Complete this real conversation to finish setup."})]}),r!=="slack"&&(!z.isSuccess||y==="loading")&&!z.isError?(0,e.jsx)("p",{role:"status",className:"text-sm text-ink-3",children:"Checking identity and guest readiness…"}):null,s?(0,e.jsxs)("div",{role:s.tone==="warning"?"alert":"status",className:s.tone==="warning"?"rounded-lg border border-bad/30 bg-bad/10 p-4 text-sm":"rounded-lg border border-line bg-bg-3/30 p-4 text-sm",children:[(0,e.jsx)("h2",{className:"font-medium",children:s.title}),(0,e.jsx)("p",{className:"mt-1 text-ink-3",children:s.body}),(0,e.jsx)(p,{className:"mt-3",size:"sm",variant:"secondary",onClick:l,children:"Review identity access"})]}):null,r==="imessage-photon"&&U&&(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)(p,{variant:"secondary",onClick:t(()=>{Ie(U).then(()=>{k(!0),_(null)},()=>_("Could not copy the number. Select it in the instructions below."))},"onClick"),children:j?"Number copied":`Copy ${U}`}),P&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:P})]}),r==="slack"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("ol",{className:"list-decimal space-y-4 pl-5 text-sm",children:[(0,e.jsx)("li",{children:b?.status==="linked"?(0,e.jsx)(p,{asChild:!0,variant:"secondary",children:(0,e.jsxs)("a",{href:g??"https://app.slack.com",target:"_blank",rel:"noopener noreferrer",children:[b.dmChannelId?"Open your Slack DM":"Open Slack",(0,e.jsx)(Q,{})]})}):(0,e.jsxs)(e.Fragment,{children:["Open a channel and invite ",f," if needed."]})}),(0,e.jsxs)("li",{children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border border-line p-3",children:[(0,e.jsx)("code",{children:X}),(0,e.jsxs)(p,{size:"sm",variant:"ghost",onClick:t(()=>{Ie(X).then(()=>{G(!0),T(!1)},()=>T(!0))},"onClick"),children:[(0,e.jsx)(qe,{className:"size-4"}),S?"Copied":"Copy message"]})]}),b?.status!=="linked"&&(0,e.jsx)("p",{className:"mt-2 text-ink-3",children:"Select the bot from Slack’s @mention suggestions."})]}),(0,e.jsx)("li",{children:"Continue the conversation in the thread."})]}),te&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Couldn't copy. Select and copy the command above."}),(0,e.jsx)(Ae,{onSaveExit:C,disabled:h,children:(0,e.jsxs)(p,{disabled:h,onClick:q,children:[h&&(0,e.jsx)(Y,{className:"size-4 animate-spin"}),"Done"]})})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("ol",{className:"list-decimal space-y-2 pl-5 text-sm",children:Z.map(v=>(0,e.jsx)("li",{children:v},v))}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[g&&(0,e.jsx)(p,{asChild:!0,variant:"secondary",children:(0,e.jsxs)("a",{href:g,target:"_blank",rel:"noopener noreferrer",children:["Open ",Ne[r]," ",(0,e.jsx)(Q,{})]})}),(0,e.jsxs)(p,{disabled:h,onClick:q,children:[h&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),"I've sent the test message"]})]})]})]})}t(ts,"TryStep");export{Os as ChatEndpointSetup};
1
+ var Ye=Object.defineProperty;var t=(a,r)=>Ye(a,"name",{value:r,configurable:!0});import{i as Ge}from"./rolldown-runtime-ZpX3ckPj.js";import{Bn as Fe,In as Je,Ji as Xe,Xi as Ze,Yi as Ke,na as et,ta as tt}from"./createLucideIcon-DJi9suAC.js";import{a as Re,y as Ue}from"./star-BZgQbzhV.js";import{X as We,_ as ye,t as ge,v as ce}from"./queryKeys-DYV5MhM_.js";import{o as st}from"./companies-query-D9PxIiMT.js";import{n as He}from"./CompanyContext-CSrVsSze.js";import{it as at,o as Le,t as Oe}from"./router-2UfGeejU.js";import{t as nt}from"./checkbox-BHQhs41k.js";import{t as Ce}from"./label-BPz3pg9_.js";import{t as it}from"./circle-question-mark-B1jR2is9.js";import{t as qe}from"./copy-_wvZOjTe.js";import{t as Q}from"./external-link-nl1b263c.js";import{t as rt}from"./eye-off-CVVA-EWh.js";import{t as ot}from"./eye-DRS7RbEp.js";import{r as Y,t as p}from"./button-CMwV3L1P.js";import{t as ze}from"./triangle-alert-CBVKiaXB.js";import{n as ct,t as Ae}from"./SetupWizard-C8qzkJn1.js";import{i as lt,n as dt,t as pt}from"./tooltip-B5WQ3lq5.js";import{t as ut}from"./AgentAvatar-DgGEobSY.js";import{i as Be}from"./ToastContext-DMdt9oTd.js";import{t as Pe}from"./agents-DmlgUVso.js";import{t as ht}from"./instanceSettings-D8g_QlS-.js";import{t as mt}from"./projects-mixWrT5q.js";import{a as xt,c as gt,i as ft,n as bt,r as kt,s as yt,t as jt}from"./dialog-CKUblzlR.js";import{t as ie}from"./input-DobnTAyB.js";import{t as vt}from"./health-DF7yrggW.js";import{t as W}from"./chatEndpoints-BKsIHowE.js";import{n as De}from"./BreadcrumbContext-BVZDZoC0.js";import{t as Te}from"./textarea-BRPEfJ-g.js";import{n as $e}from"./AgentMultiSelect-DsJfZtR2.js";import{t as Ie}from"./clipboard-CTLKYvRL.js";import{t as wt}from"./AgentCharacter-BTEn5MBu.js";import{t as Ct}from"./use-copy-action-D5dEzo6L.js";import{Cn as Nt,Gr as ve,Wr as Ve,yn as St}from"./index-3AxqhPET.js";import{r as At}from"./EmailEndpointSetup-6OHb9B4q.js";import{a as It,i as Tt,m as Me,o as Se,p as Et,r as Pt}from"./OpenwaGatewayManager-DH3bF7fa.js";var Rt=new Set(["terminated","pending_approval","paused"]),Ut=new Set(["active","idle","running","error"]);function Wt(a){return Ut.has(a)&&!Rt.has(a)}t(Wt,"isAgentStatusInvokable");var c=Ge(et(),1),e=Ge(tt(),1);function Lt({endpoint:a,stage:r,disabled:u,saveDetails:d,onSaved:U,onBusy:A,onManual:b,onContinue:i,onSaveExit:g}){const[y,h]=(0,c.useState)(""),[l,q]=(0,c.useState)(!1),[C,S]=(0,c.useState)(null),[G,te]=(0,c.useState)(!1),T=(0,c.useRef)(crypto.randomUUID()),z=(0,c.useRef)(!1),j=(0,c.useRef)(null),k=(0,c.useRef)(!0);(0,c.useEffect)(()=>(k.current=!0,()=>{k.current=!1,j.current?.close(),j.current=null}),[]);const P=a.setup?.slackRegistration,_=P?.status==="uncertain",M=P?.status==="creating",K=!!P?.appId,O=P?.errorCode==="slack_manifest_update_pending";async function s(f){if(!z.current){z.current=!0,q(!0),A(!0),S(null);try{await f()}catch(X){S(Se(X,{configurationToken:y}))}finally{h(""),q(!1),A(!1),z.current=!1}}}t(s,"run");async function N(){const f=window.open("about:blank","_blank");f&&(f.opener=null,f.document.title="Preparing Slack installation",f.document.body.textContent="Preparing your Slack installation…",j.current=f);let X=y.trim();h("");try{let L;try{K||await d(),(P?.status==="failed"||G)&&(T.current=crypto.randomUUID()),L=await W.createSlackApp(a.id,{requestId:T.current,credentials:{configurationToken:X},...G?{confirmedNoAppCreated:!0}:{}})}catch(re){const B=await W.get(a.id).catch(()=>null);if(B&&k.current&&U(B),!B?.setup?.slackRegistration?.appId)throw new Error(Se(re,{configurationToken:X}));L=B}if(X="",!k.current)return;te(!1),U(L);const Z=L.setup?.slackRegistration;if(!Z?.appId||(i(),Z.status!=="install"||Z.errorCode))return;if(!f||f.closed){S("Select Install in Slack to open the installation page.");return}const v=await W.installSlackApp(a.id);if(!k.current)return;if(f.closed){S("Select Install in Slack to reopen the installation page.");return}f.location.replace(v.authorizationUrl),j.current=null}finally{X="",j.current?.close(),j.current=null}}t(N,"create");async function J(){const f=await W.installSlackApp(a.id);window.location.assign(f.authorizationUrl)}return t(J,"authorize"),(0,e.jsxs)("div",{className:"space-y-5",children:[C||P?.errorCode?(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:C??Ze(P.errorCode)}):null,(r==="app"&&!K&&!M||O)&&(0,e.jsxs)(e.Fragment,{children:[_&&(0,e.jsxs)("div",{className:"space-y-3 text-sm",children:[(0,e.jsxs)("a",{href:P?.managementUrl??"https://api.slack.com/apps",target:"_blank",rel:"noopener noreferrer",className:"underline underline-offset-4",children:["Open Slack app settings ",(0,e.jsx)(Q,{className:"inline size-3"})]}),(0,e.jsxs)("label",{className:"flex items-center gap-2",children:[(0,e.jsx)(nt,{checked:G,disabled:l,onCheckedChange:t(f=>te(f===!0),"onCheckedChange")}),"I checked Slack and no app was created. Create a new app."]})]}),(!_||G)&&(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)(p,{asChild:!0,size:"lg",className:"mb-4 h-auto w-full whitespace-normal py-4",children:(0,e.jsxs)("a",{href:"https://api.slack.com/apps",target:"_blank",rel:"noopener noreferrer",children:["Get your App configuration access token ",(0,e.jsx)(Q,{className:"size-4"})]})}),(0,e.jsxs)("div",{id:"slack-configuration-token-help",className:"space-y-3 pb-3 text-sm",children:[(0,e.jsxs)("ol",{className:"list-decimal space-y-2 pl-5",children:[(0,e.jsxs)("li",{children:["In Slack app settings, find ",(0,e.jsx)("strong",{children:"Your App Configuration Tokens"})," and choose ",(0,e.jsx)("strong",{children:"Generate Token"}),"."]}),(0,e.jsx)("li",{children:"Select the workspace where you want to install your bot."}),(0,e.jsxs)("li",{children:["Copy the ",(0,e.jsx)("strong",{children:"Access Token"})," and paste it below."]})]}),(0,e.jsx)("p",{className:"text-ink-3",children:"Wardmote uses this token to create your app"})]}),(0,e.jsx)("label",{htmlFor:"slack-configuration-token",className:"text-sm font-medium",children:"App configuration access token"}),(0,e.jsx)(ie,{id:"slack-configuration-token",type:"password",autoComplete:"off",spellCheck:!1,value:y,disabled:l,onChange:t(f=>h(f.target.value),"onChange"),"aria-describedby":"slack-configuration-token-help"})]})]}),M&&(0,e.jsxs)("p",{role:"status",className:"flex items-center gap-2 text-sm text-ink-3",children:[(0,e.jsx)(Y,{className:"size-4 animate-spin"})," Creating your Slack app. You can return to this saved setup."]}),K&&(0,e.jsxs)("p",{className:"text-sm",children:[(0,e.jsx)("strong",{children:a.setup?.slackApp?.appName??"Your Slack app"})," is created.",r==="credentials"&&" Approve installation with your Slack account. Wardmote will link it to your signed-in Wardmote account and send you a welcome DM."]}),r==="credentials"&&P?.status==="credentials_saved"&&(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Your installation credentials are saved. Retry connecting to finish setup. If Slack access has changed, authorize the same app again."}),(0,e.jsx)(p,{variant:"link",className:"h-auto p-0",disabled:l||u,onClick:t(()=>{s(J)},"onClick"),children:"Authorize in Slack again"})]}),r==="app"&&(0,e.jsx)(Me,{children:(0,e.jsxs)("div",{className:"flex flex-wrap gap-4 text-sm",children:[(0,e.jsx)(p,{variant:"link",className:"h-auto p-0",disabled:l||M,onClick:t(()=>{s(()=>b(!1))},"onClick"),children:"Create manually"}),(0,e.jsx)(p,{variant:"link",className:"h-auto p-0",disabled:l||M,onClick:t(()=>{s(()=>b(!0))},"onClick"),children:"Use an existing app"})]})}),(0,e.jsx)(Ae,{onSaveExit:g,disabled:l,children:O?(0,e.jsxs)(p,{disabled:l||u||!y.trim(),onClick:t(()=>{s(N)},"onClick"),children:[l&&(0,e.jsx)(Y,{className:"size-4 animate-spin"}),"Retry app configuration"]}):r==="app"?(0,e.jsxs)(p,{disabled:l||u||M||!K&&(!y.trim()||_&&!G),onClick:t(()=>K?i():void s(N),"onClick"),children:[l&&(0,e.jsx)(Y,{className:"size-4 animate-spin"}),K?"Continue to installation":"Create Slack app"]}):P?.status==="credentials_saved"?(0,e.jsxs)(p,{disabled:l,onClick:t(()=>{s(async()=>U(await W.resumeSlackInstallation(a.id)))},"onClick"),children:[l&&(0,e.jsx)(Y,{className:"size-4 animate-spin"}),"Retry connecting"]}):(0,e.jsxs)(p,{disabled:l||!K||u,onClick:t(()=>{s(J)},"onClick"),children:[l?(0,e.jsx)(Y,{className:"size-4 animate-spin"}):(0,e.jsx)(Q,{className:"size-4"}),"Install in Slack"]})})]})}t(Lt,"SlackAutomaticSetup");var zt="https://github.com/tickernelz/wardmote/blob/main/doc/LOW-TRUST-PRESETS.md";function Qe({agent:a,onChangeToLowTrust:r,disabled:u}){return!a||Nt(a.permissions)==="low_trust_review"?null:(0,e.jsxs)("div",{role:"alert",className:"space-y-2 rounded-lg border border-(--status-task-todo)/30 bg-(--status-task-todo)/10 p-4 text-sm",children:[(0,e.jsxs)("p",{className:"flex items-center gap-2 font-medium",children:[(0,e.jsx)(ze,{className:"size-4 shrink-0"}),a.name," is not configured for low-trust review"]}),(0,e.jsx)("p",{children:"GitHub comments and pull requests can contain malicious instructions. We recommend a low-trust agent with a scoped work boundary and an isolated sandbox runtime."}),(0,e.jsx)("p",{className:"text-xs text-ink-3",children:"Continuing keeps this agent’s current permissions. A restricted guest profile does not replace the agent’s trust and runtime settings."}),r&&(0,e.jsxs)(p,{variant:"secondary",className:"h-auto whitespace-normal",disabled:u,onClick:r,children:["Change ",a.name," to a low trust agent"]}),(0,e.jsxs)("a",{className:"inline-flex items-center gap-1 underline underline-offset-4",href:zt,target:"_blank",rel:"noreferrer",children:["Learn about low-trust agents",(0,e.jsx)(Q,{className:"size-3.5"})]})]})}t(Qe,"GitHubAgentTrustWarning");function Dt(a){const r=new URL(a.registrationUrl);if(r.origin!=="https://github.com"||r.username||r.password||r.hash||!/^\/(settings|organizations\/[A-Za-z0-9-]+\/settings)\/apps\/new$/.test(r.pathname))throw new Error("GitHub returned an invalid registration address");return r.toString()}t(Dt,"gitHubAppManifestAction");function Mt({registration:a,onSaveExit:r,disabled:u,autoSubmit:d,onSubmit:U}){const A=(0,c.useRef)(null),b=(0,c.useRef)(!1);return(0,c.useEffect)(()=>{d||(b.current=!1),d&&!u&&!b.current&&A.current&&(b.current=!0,A.current.requestSubmit())},[d,u]),(0,e.jsxs)("form",{ref:A,method:"post",action:Dt(a),onSubmit:U,children:[(0,e.jsx)("input",{type:"hidden",name:"manifest",value:JSON.stringify(a.manifest)}),(0,e.jsx)(Ae,{onSaveExit:r,disabled:u,children:(0,e.jsx)(p,{type:"submit",disabled:u,children:"Continue to GitHub"})})]})}t(Mt,"GitHubAppManifestForm");function Ot(){const[a,r]=Ue(),u=Le(),{selectedCompanyId:d}=He(),{setBreadcrumbs:U}=De(),A=We(),b=a.get("resume"),i=a.get("stage")==="identity",g=a.get("reconnect")==="1",[y,h]=(0,c.useState)(a.get("agentId")??""),[l,q]=(0,c.useState)("personal"),[C,S]=(0,c.useState)(""),[G,te]=(0,c.useState)(!1),[T,z]=(0,c.useState)(""),[j,k]=(0,c.useState)(!1),[P,_]=(0,c.useState)(!1),[M,K]=(0,c.useState)(""),[O,s]=(0,c.useState)(a.get("reconnect")==="1"),[N,J]=(0,c.useState)({appId:"",privateKey:"",webhookSecret:""}),[f,X]=(0,c.useState)(""),[L,Z]=(0,c.useState)(!1),[v,re]=(0,c.useState)(null),B=ce({queryKey:["github-setup-agents",d],queryFn:t(()=>Pe.list(d),"queryFn"),enabled:!!d&&!i}),F=ce({queryKey:["github-setup",b],queryFn:t(()=>W.get(b),"queryFn"),enabled:!!b,refetchInterval:3e3}),x=F.data,oe=ce({queryKey:["github-wizard",b],queryFn:t(()=>ve.advance(b),"queryFn"),enabled:!!x&&!O&&!i,refetchInterval:t(o=>["connected","create","identity","recovery"].includes(o.state.data?.state??"")?!1:5e3,"refetchInterval"),retry:!1}),$=ce({queryKey:["github-personal-connections",b],queryFn:t(()=>ve.personalConnections(b),"queryFn"),enabled:!!x&&(i||oe.data?.state==="identity")}),D=B.data?.find(o=>o.id===(x?.assignedAgentId??y)),w=i?void 0:oe.data,fe=!!x&&!i&&!O&&w?.state==="create",m=ce({queryKey:["project-repositories",d],queryFn:t(()=>mt.repositoryOptions(d),"queryFn"),enabled:!!d&&fe,staleTime:3e4}),H=ce({queryKey:ge.chatEndpoints.list(d),queryFn:t(()=>W.list(d),"queryFn"),enabled:!!d&&fe,staleTime:3e4}),le=new Map;for(const o of m.data?.repositories??[]){if(o.ownerType!=="organization")continue;const R=o.fullName.split("/")[0];le.set(R.toLowerCase(),R)}for(const o of H.data??[]){const R=o.setup?.github;o.provider==="github"&&["active","paused"].includes(o.status)&&R?.ownerType==="organization"&&R.ownerLogin&&le.set(R.ownerLogin.toLowerCase(),R.ownerLogin)}const he=[...le.values()].sort((o,R)=>o.localeCompare(R)),pe=le.get(C.toLowerCase()),E=l==="personal"?"personal":!G&&pe?`organization:${pe}`:"organization",me=w?.state==="verify"&&!!x?.setup?.webhookVerifiedAt&&w.verification?.checks.some(o=>!o.ok&&["webhook","delivery"].includes(o.key)),xe=i||w?.identityMethod==="existing_connection",be=w?.state==="connected"&&!O;(0,c.useEffect)(()=>{!be||!x||(A.setQueryData(ge.chatEndpoints.detail(x.id),x),D&&A.setQueryData(ge.agents.detail(D.id),D),u(`/apps/chat/${x.id}/settings`,{replace:!0,state:{githubConnectionComplete:{endpointId:x.id,runtimeChecks:w.runtimeChecks}}}))},[be,x,D,w,A,u]),(0,c.useEffect)(()=>(U([{label:"Connectors",href:"/apps"},{label:"GitHub Code Review Bot"}]),()=>U([])),[U]),(0,c.useEffect)(()=>{x&&(h(x.assignedAgentId),x.setup?.github?.ownerType&&q(x.setup.github.ownerType),S(x.setup?.github?.ownerLogin??""),te(!1),x.setup?.github?.appName&&z(x.setup.github.appName))},[x?.id,x?.setup?.github?.ownerType,x?.setup?.github?.ownerLogin,x?.setup?.github?.appName]);async function V(o){k(!0),K("");try{await o()}catch(R){K(R instanceof Error?R.message:"Could not connect GitHub. Try again.")}finally{k(!1)}}t(V,"run");async function ee(){await F.refetch(),i||await oe.refetch()}t(ee,"refresh");const je=t(()=>({name:(T||D?.name||x?.assignedAgentName||"GitHub Reviewer").slice(0,34),ownerType:l,...l==="organization"?{ownerLogin:C.trim()}:{}}),"appInput"),ue=t(()=>{V(async()=>{!i&&x&&!x.botExternalId&&!w?.registration&&w?.state!=="recovery"&&(await ve.saveDraft(x.id,je()),await F.refetch()),u("/apps")})},"exit"),se=t((o,R,we=!1)=>(0,e.jsx)(Ae,{onSaveExit:ue,disabled:j,children:o&&R&&(0,e.jsxs)(p,{disabled:j||we,onClick:t(()=>{V(R)},"onClick"),children:[j&&(0,e.jsx)(Y,{className:"mr-2 size-4 animate-spin"}),o]})}),"footer");return b&&!x?(0,e.jsxs)("div",{className:"mx-auto w-full max-w-3xl space-y-6 px-4 py-6 sm:px-6",children:[(0,e.jsx)("h1",{className:"text-2xl font-semibold",children:"Resume GitHub setup"}),F.error?(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Could not load this connection. Try again to resume your draft."}):(0,e.jsx)("p",{role:"status",className:"text-sm text-ink-3",children:"Loading your draft…"}),se(F.error?"Try again":void 0,async()=>{await F.refetch()})]}):be?null:(0,e.jsxs)("div",{className:"mx-auto w-full max-w-3xl space-y-6 px-4 py-6 sm:px-6",children:[!i&&(0,e.jsx)(ct,{labels:["Choose agent","Connect GitHub"],step:x?1:0,availableStep:x?1:0,onSelect:t(()=>{},"onSelect"),disabled:!0,takeover:!0}),(0,e.jsx)("h1",{className:"text-2xl font-semibold",children:x?i||w?.state==="identity"?"Connect your account":"Connect GitHub":"Choose agent"}),(M||!i&&oe.error||$.error)&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:M||($.error instanceof Error?$.error.message:void 0)||(oe.error instanceof Error?oe.error.message:"Could not check GitHub setup. Try again.")}),x?!i&&!O&&oe.isPending?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{role:"status",className:"text-sm text-ink-3",children:"Checking your GitHub connection…"}),se()]}):O?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{className:"text-sm text-ink-3",children:g?"Leave these blank to reuse this App’s stored credentials, or enter both fields to repair them.":"Use the credentials from this App’s GitHub settings."}),(0,e.jsx)(Ce,{htmlFor:"github-app-id",children:"App ID"}),(0,e.jsx)(ie,{id:"github-app-id",value:N.appId,onChange:t(o=>J({...N,appId:o.target.value}),"onChange")}),(0,e.jsx)(Ce,{htmlFor:"github-private-key",children:"Private key"}),(0,e.jsx)(Te,{id:"github-private-key",value:N.privateKey,onChange:t(o=>J({...N,privateKey:o.target.value}),"onChange")}),!g&&!["active","paused","revoked"].includes(x.status)&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Ce,{htmlFor:"github-webhook-secret",children:"Webhook secret"}),(0,e.jsx)(ie,{id:"github-webhook-secret",type:"password",value:N.webhookSecret,onChange:t(o=>J({...N,webhookSecret:o.target.value}),"onChange")})]}),se(g?"Reconnect App":"Connect existing App",async()=>{g||["active","paused","revoked"].includes(x.status)?await W.setup(x.id,{action:"reconnect",...N.appId.trim()||N.privateKey.trim()?{credentials:{appId:N.appId,privateKey:N.privateKey}}:{}}):await ve.connectApp(x.id,N),J({appId:"",privateKey:"",webhookSecret:""}),s(!1),await ee()},g?!!(N.appId.trim()||N.privateKey.trim())&&(!N.appId.trim()||!N.privateKey.trim()):!N.appId.trim()||!N.privateKey.trim()||!["active","paused","revoked"].includes(x.status)&&!N.webhookSecret.trim())]}):w?.state==="identity"||i?(0,e.jsx)(e.Fragment,{children:i&&L?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("p",{role:"status",className:"text-sm",children:["GitHub account ",(0,e.jsx)("strong",{children:v?.login})," ","connected. You can now mention this bot on GitHub."]}),se()]}):w?.identity?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("p",{className:"text-sm",children:["Connect GitHub account ",(0,e.jsx)("strong",{children:w.identity.login})," ","to your Wardmote account."]}),se("Confirm my account",async()=>{await ve.confirmIdentity(x.id,w.identity.githubUserId),await ee()})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Link your GitHub account so your mentions use your Wardmote permissions."}),($.data?.length??0)>0&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Ce,{htmlFor:"github-personal-account",children:"Existing GitHub connection"}),(0,e.jsxs)("select",{id:"github-personal-account",className:"w-full rounded-md border border-line-strong bg-bg px-3 py-2 text-sm",value:f,onChange:t(o=>{X(o.target.value),re(null),Z(!1)},"onChange"),children:[(0,e.jsx)("option",{value:"",children:"Choose an account"}),$.data?.filter(o=>o.status==="active"&&o.enabled).map(o=>(0,e.jsx)("option",{value:o.connectionId,children:o.login??o.name},o.connectionId))]}),v&&(0,e.jsxs)("p",{className:"text-sm",children:["GitHub account: ",(0,e.jsx)("strong",{children:v.login})]})]}),xe&&!f&&(0,e.jsx)(Oe,{className:"text-sm underline",to:"/apps/connect?source=github",children:"Add a personal GitHub connection, then return to this draft"}),se(f?v?"Confirm my account":"Check my account":"Connect my GitHub account",async()=>{if(f){const o=await ve.identity(x.id,f,v?.githubUserId);re(o),v&&(Z(!0),await ee())}else{const o=await ve.startIdentity(x.id);window.location.assign(o.authorizationUrl)}},xe&&!f)]})}):w?.state==="install"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{role:"status",className:"text-sm text-ink-3",children:"Waiting for GitHub installation or administrator approval…"}),w.installationUrl&&(0,e.jsxs)("a",{className:"inline-flex items-center gap-1 text-sm underline",href:w.installationUrl,children:["Continue installation on GitHub",(0,e.jsx)(Q,{className:"size-3"})]}),se()]}):w?.state==="recovery"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{role:"status",className:"text-sm",children:w.message}),(0,e.jsx)(p,{variant:"ghost",onClick:t(()=>s(!0),"onClick"),children:"Use existing App credentials"}),se("Try again",ee)]}):w?.state==="verify"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{role:"status",className:"text-sm text-ink-3",children:me?"GitHub delivery verified. Checking App and repository access…":w.message??"Checking GitHub access…"}),w.verification?.checks.filter(o=>!o.ok&&!(me&&["webhook","delivery"].includes(o.key))).map(o=>(0,e.jsx)("p",{className:"text-sm",children:o.detail},o.key)),(0,e.jsx)(Oe,{className:"text-sm underline",to:`/apps/chat/${x.id}/settings`,children:"Connection settings"}),se("Try again",ee)]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)(Ce,{htmlFor:"github-owner-type",children:"GitHub account"}),(0,e.jsxs)("select",{id:"github-owner-type",className:"w-full rounded-md border border-line-strong bg-bg px-3 py-2 text-sm",value:E,disabled:j||!!w?.registration,onChange:t(o=>{const R=o.target.value;q(R==="personal"?"personal":"organization"),te(R==="organization"),R.startsWith("organization:")?S(R.slice(13)):R==="organization"&&S("")},"onChange"),children:[(0,e.jsx)("option",{value:"personal",children:"My account"}),he.map(o=>(0,e.jsx)("option",{value:`organization:${o}`,children:o},o.toLowerCase())),(0,e.jsx)("option",{value:"organization",children:"Another organization"})]}),(m.isError||H.isError)&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Could not load some connected GitHub accounts. Choose Another organization to enter a name."})]}),E==="organization"&&(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)(Ce,{htmlFor:"github-owner-login",children:"Organization"}),(0,e.jsx)(ie,{id:"github-owner-login",disabled:j||!!w?.registration,value:C,onChange:t(o=>S(o.target.value),"onChange"),placeholder:"GitHub organization name"})]}),(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)(Ce,{htmlFor:"github-app-name",children:"App name"}),(0,e.jsx)(ie,{id:"github-app-name",disabled:j||!!w?.registration,maxLength:34,value:T||D?.name?.slice(0,34)||x.assignedAgentName?.slice(0,34)||"GitHub Reviewer",onChange:t(o=>z(o.target.value),"onChange")})]}),(0,e.jsx)("button",{className:"text-sm text-ink-3 underline",onClick:t(()=>s(!0),"onClick"),children:"I already have an App"}),w?.registration?(0,e.jsx)(Mt,{registration:w.registration,onSaveExit:ue,disabled:j,autoSubmit:P,onSubmit:t(()=>_(!1),"onSubmit")}):se("Continue to GitHub",async()=>{const o=await ve.registration(x.id,je());A.setQueryData(["github-wizard",x.id],o),o.registration&&_(!0)},oe.isPending||l==="organization"&&!C.trim())]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)($e,{agents:B.data??[],value:y,onChange:h}),D&&(0,e.jsx)(Qe,{agent:D,disabled:j,onChangeToLowTrust:t(()=>{V(async()=>{const o=St(D.permissions,"low_trust_review");await Pe.updatePermissions(D.id,{...o,canCreateAgents:!1,canCreateSkills:!1,canAssignTasks:typeof D.permissions.canAssignTasks=="boolean"?D.permissions.canAssignTasks:!0},d),await A.invalidateQueries({queryKey:["github-setup-agents",d]})})},"onChangeToLowTrust")}),se("Continue",async()=>{const o=await W.create(d,{provider:"github",assignedAgentId:y});z((D?.name??"GitHub Reviewer").slice(0,34));const R=new URLSearchParams(a);R.set("resume",o.id),r(R,{replace:!0}),A.setQueryData(["github-setup",o.id],o)},!y||!d)]})]})}t(Ot,"GitHubChatSetup");function _t({endpointId:a,command:r,testStartedAt:u,onConnected:d,onSaveExit:U}){const A=We(),[b,i]=(0,c.useState)(!1),[g,y]=(0,c.useState)(!1),h=ce({queryKey:ge.auth.session,queryFn:st.getSession,retry:!1}),l=ce({queryKey:ge.health,queryFn:vt.get}),q=ce({queryKey:ge.chatEndpoints.principals(a),queryFn:t(()=>W.listPrincipals(a),"queryFn"),refetchInterval:1500}),C=l.data?.deploymentMode==="local_trusted",S=C?"local-board":h.data?.user.id,G=C?"Local Board":h.data?.user.name||h.data?.user.email,te=(q.data??[]).filter(k=>k.lastConnectAt&&(!u||Date.parse(k.lastConnectAt)>=Date.parse(u))),T=te.some(k=>k.status==="linked"&&k.wardmoteUserId===S),z=`${r} connect`,j=ye({mutationFn:t(async k=>{const{confirmationUrl:P}=await W.createLinkIntent(a,k),_=new URL(P,window.location.origin).searchParams.get("token");if(!_)throw new Error("Could not create the account confirmation. Try again.");await W.confirmIdentityLink(_)},"mutationFn"),onSuccess:t(()=>A.invalidateQueries({queryKey:ge.chatEndpoints.principals(a)}),"onSuccess")});return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:"Connect your Slack account"}),(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:"Send this command in Slack so we can identify your account. It won't start agent work."})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border border-line p-3",children:[(0,e.jsx)("code",{className:"text-sm",children:z}),(0,e.jsxs)(p,{variant:"ghost",size:"sm",onClick:t(()=>{Ie(z).then(()=>{i(!0),y(!1)},()=>y(!0))},"onClick"),children:[(0,e.jsx)(qe,{className:"size-4"}),b?"Copied":"Copy command"]})]}),g&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Couldn't copy the command. Select and copy it above."}),(0,e.jsxs)("p",{className:"text-sm",children:[(0,e.jsxs)("a",{href:"https://app.slack.com/",target:"_blank",rel:"noopener noreferrer",className:"underline underline-offset-4",children:["Open Slack ",(0,e.jsx)(Q,{className:"inline size-3"})]}),", send the command in your workspace, then return here."]}),q.isError?(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Couldn't check for your Slack account. We'll keep trying."}):te.length===0?(0,e.jsxs)("p",{role:"status",className:"flex items-center gap-2 text-sm text-ink-3",children:[(0,e.jsx)(Y,{className:"size-4 animate-spin"}),"Waiting for your connect command…"]}):(0,e.jsxs)("div",{className:`space-y-3 rounded-lg border p-4 ${T?"border-(--status-task-done)/30 bg-(--status-task-done)/10":"border-(--status-task-todo)/30 bg-(--status-task-todo)/10"}`,children:[(0,e.jsxs)("p",{className:"text-sm",children:["Choose your Slack account below to link it to ",(0,e.jsx)("strong",{children:G??"your Wardmote account"}),". Only confirm an account that belongs to you. Future messages will use your Wardmote permissions."]}),te.map(k=>{const P=k.status==="linked"&&k.wardmoteUserId===S;return(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border border-line p-3",children:[(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsx)("p",{className:"text-sm font-medium",children:k.externalLabel}),(0,e.jsx)("p",{className:"text-xs text-ink-3",children:k.externalDetail})]}),P?(0,e.jsxs)("p",{role:"status",className:"flex items-center gap-2 text-sm",children:[(0,e.jsx)(Re,{className:"size-4 text-(--status-task-done)"}),"Linked to you"]}):k.status==="linked"?(0,e.jsxs)("p",{className:"text-sm text-ink-3",children:["Linked to ",k.wardmoteUserLabel??"another Wardmote account"]}):(0,e.jsxs)(p,{variant:"secondary",disabled:!S||j.isPending,onClick:t(()=>j.mutate(k.principalId),"onClick"),"aria-label":`Link ${k.externalLabel} to my Wardmote account`,children:[j.isPending&&j.variables===k.principalId&&(0,e.jsx)(Y,{className:"size-4 animate-spin"}),"This is my Slack account"]})]},k.principalId)})]}),!S&&!h.isPending&&!l.isPending&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Sign in to Wardmote to link your Slack account. Refresh this page after signing in."}),j.isError&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Couldn't link your account. Check that you are a member of this company and try again."}),(0,e.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,e.jsx)(p,{variant:"ghost",onClick:U,children:"Save & exit"}),T&&(0,e.jsx)(p,{onClick:d,children:"Continue to message test"})]})]})}t(_t,"SlackIdentityStep");function Gt({endpoint:a,agentName:r,repairing:u,pending:d,onAction:U}){const[A,b]=(0,c.useState)(a.providerAccountId??""),[i,g]=(0,c.useState)(""),[y,h]=(0,c.useState)(""),l=ye({mutationFn:t(()=>W.inspectPhoton(a.id,{projectId:A.trim(),projectSecret:i}),"mutationFn"),onSuccess:t(C=>{const S=C.lines.filter(G=>G.eligible);h(S.length===1?S[0].lineId:"")},"onSuccess")}),q=t(()=>{l.reset(),h("")},"resetInspection");return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:"Connect iMessage Photon"}),(0,e.jsxs)("p",{className:"text-sm text-ink-3",children:["Connect ",r," to Photon Cloud. Pro supports direct messages through a shared line. Dedicated numbers also support individually enabled groups."]}),(0,e.jsxs)("p",{className:"text-sm",children:[(0,e.jsx)("a",{className:"underline",href:"https://app.photon.codes/",target:"_blank",rel:"noreferrer",children:"Photon dashboard"})," · ",(0,e.jsx)("a",{className:"underline",href:"https://photon.codes/docs/spectrum-ts/providers/imessage/connection-and-routing",target:"_blank",rel:"noreferrer",children:"Photon line setup"})]})]}),u&&(0,e.jsxs)("p",{className:"text-sm text-ink-3",children:["Reconnect keeps this project and"," ",a.photonAllocation==="shared"?"shared DM allocation":a.botExternalId??"dedicated number",". Leave the secret blank to reuse the saved connection."]}),(0,e.jsxs)("label",{className:"grid gap-2 text-sm font-medium",children:["Project ID",(0,e.jsx)(ie,{value:A,autoComplete:"off",disabled:d||l.isPending||!!a.botExternalId,onChange:t(C=>{b(C.target.value),q()},"onChange")})]}),(0,e.jsxs)("label",{className:"grid gap-2 text-sm font-medium",children:["Project secret",(0,e.jsx)(ie,{type:"password",value:i,autoComplete:"new-password",disabled:d||l.isPending,onChange:t(C=>{g(C.target.value),q()},"onChange")})]}),(0,e.jsx)(p,{variant:"secondary",disabled:d||l.isPending||!A.trim()||!i,onClick:t(()=>l.mutate(),"onClick"),children:l.isPending?"Inspecting Photon…":"Inspect Photon project"}),l.isError&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:Se(l.error,{projectSecret:i})}),l.data&&(0,e.jsxs)("fieldset",{className:"space-y-3",children:[(0,e.jsxs)("legend",{className:"text-sm font-medium",children:[l.data.allocation==="shared"?"Shared DMs":"Dedicated numbers"," in ",l.data.projectName]}),!l.data.eligible&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:l.data.allocation==="shared"?"This shared project already belongs to another channel. Use a separate Photon project for each agent.":"No eligible dedicated number is available. Check the line allocation in Photon and existing Wardmote channels."}),l.data.allocation==="shared"&&l.data.eligible&&(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Direct messages only. Enroll each test sender in your Photon project's Users page, then use the number Photon assigns to that sender. Wardmote identity linking is still required. Groups cannot be enabled on this channel."}),l.data.lines.map(C=>(0,e.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,e.jsx)("input",{type:"radio",name:"photon-line",value:C.lineId,checked:y===C.lineId,disabled:!C.eligible||d||!!a.botExternalId&&a.botExternalId!==C.phoneNumber,onChange:t(()=>h(C.lineId),"onChange")}),(0,e.jsxs)("span",{children:[C.phoneNumber,C.unavailableReason?` — ${C.unavailableReason}`:""]})]},C.lineId))]}),(0,e.jsx)("div",{children:(0,e.jsx)(p,{disabled:d||l.isPending||!(l.data?.eligible&&(l.data.allocation==="shared"||y))&&!(u&&!i),onClick:t(()=>U(u?"reconnect":"configure",l.data?.eligible&&l.data.allocation==="shared"?{projectId:A.trim(),projectSecret:i,allocation:"shared"}:y?{projectId:A.trim(),projectSecret:i,lineId:y,allocation:"dedicated"}:void 0),"onClick"),children:d?"Connecting…":u?"Reconnect Photon":l.data?.allocation==="shared"?"Connect shared DMs":"Connect selected number"})})]})}t(Gt,"PhotonConnectStep");var Ft="https://github.com/rmyndharis/OpenWA";function _e(a){const r=a.providerAccountId??"",u=r.lastIndexOf("#");return u>0?r.slice(0,u):""}t(_e,"storedBaseUrl");function Kt(a){const r=a.providerAccountId??"",u=r.lastIndexOf("#");return u>0?r.slice(u+1):""}t(Kt,"storedSessionId");function Ee({htmlFor:a,label:r,help:u}){return(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,e.jsx)("label",{htmlFor:a,children:r}),(0,e.jsxs)(pt,{children:[(0,e.jsx)(lt,{asChild:!0,children:(0,e.jsx)("button",{type:"button","aria-label":`Help with ${r.toLowerCase()}`,className:"rounded-sm text-ink-3 hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus",children:(0,e.jsx)(it,{className:"size-3.5","aria-hidden":"true"})})}),(0,e.jsx)(dt,{className:"max-w-xs",children:u})]})]})}t(Ee,"FieldLabel");function Ht({endpoint:a,agentName:r,repairing:u,pending:d,onAction:U,onSaveExit:A}){const b=Kt(a),[i,g]=(0,c.useState)(_e(a)),[y,h]=(0,c.useState)(""),[l,q]=(0,c.useState)(""),[C,S]=(0,c.useState)(""),[G,te]=(0,c.useState)(""),[T,z]=(0,c.useState)(null),[j,k]=(0,c.useState)(!1),[P,_]=(0,c.useState)(""),[M,K]=(0,c.useState)(),[O,s]=(0,c.useState)(a.policy?.numberMode??"agent_number"),[N,J]=(0,c.useState)(a.policy?.attestations.pacing??!1),[f,X]=(0,c.useState)(a.policy?.attestations.soleClient??!1),L=ye({mutationFn:t(()=>W.inspectOpenwa(a.id,{baseUrl:i.trim(),...y.trim()?{apiKey:y.trim()}:{},...l.trim()?{adminApiKey:l.trim()}:{}}),"mutationFn"),onSuccess:t(m=>{const H=m.sessions.filter(he=>he.eligible),le=H.find(he=>he.sessionId===(b||G));S(le?.sessionId??(H.length===1?H[0].sessionId:""))},"onSuccess")}),Z=t(()=>{L.reset(),S(""),z(null),k(!1)},"resetInspection"),v=L.data,re=l.trim()||y.trim(),B=t(m=>W.runOpenwaGatewayAdmin(a.id,{...m,connection:{baseUrl:v.baseUrl,adminApiKey:re}}),"run"),F=ye({mutationFn:t(()=>Tt(B,P),"mutationFn"),onSuccess:t(m=>{k(!1),_(""),z(m)},"onSuccess")}),x=(0,c.useCallback)(()=>{T&&(te(T.id),z(null),L.mutate())},[T,L]),oe=t(()=>{const m=It(P);K(m),m||F.mutate()},"submitSessionName"),$={apiKey:y,adminApiKey:l},D=u&&!y.trim(),w=N&&f&&(D||!!v?.eligible&&!!C),fe=t(()=>U(u?"reconnect":"configure",D?{baseUrl:_e(a),sessionId:b,...l.trim()?{adminApiKey:l.trim()}:{},numberMode:O,pacing:String(N),soleClient:String(f)}:{baseUrl:v.baseUrl,...y.trim()?{apiKey:y.trim()}:{},...l.trim()?{adminApiKey:l.trim()}:{},sessionId:C,numberMode:O,pacing:String(N),soleClient:String(f)}),"connect");return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:"Connect OpenWA"}),(0,e.jsxs)("p",{className:"text-sm text-ink-3",children:["Connect ",r," to one WhatsApp session on your self-hosted OpenWA gateway. You can create the session and scan its QR code here; nothing is sent until an owner messages the number."]}),(0,e.jsx)("p",{className:"text-sm",children:(0,e.jsx)("a",{className:"underline",href:Ft,target:"_blank",rel:"noreferrer",children:"OpenWA documentation"})})]}),u&&(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Reconnect keeps this gateway session. Leave the keys blank to reuse the saved ones, or enter only the admin key to add or replace it."}),(0,e.jsxs)("div",{className:"grid gap-2 text-sm font-medium",children:[(0,e.jsx)(Ee,{htmlFor:"openwa-base-url",label:"Gateway URL",help:"The address of your OpenWA gateway, such as http://localhost:2785. Use only the origin, without /api."}),(0,e.jsx)(ie,{id:"openwa-base-url",value:i,placeholder:"http://localhost:2785",autoComplete:"off",inputMode:"url",disabled:d||L.isPending||!!a.providerAccountId,onChange:t(m=>{g(m.target.value),Z()},"onChange")})]}),(0,e.jsxs)("div",{className:"grid gap-2 text-sm font-medium",children:[(0,e.jsx)(Ee,{htmlFor:"openwa-admin-api-key",label:"Admin API key",help:"OpenWA prints this key in its log the first time the gateway starts. It is stored encrypted and only used from this page and Settings."}),(0,e.jsx)(ie,{id:"openwa-admin-api-key",type:"password",value:l,autoComplete:"new-password",disabled:d||L.isPending,onChange:t(m=>{q(m.target.value),Z()},"onChange")}),(0,e.jsxs)("p",{className:"text-xs font-normal text-ink-3",children:["The admin key lets Wardmote create the session and show its QR here, then give ",r," its own operator key limited to that one session, while an operator key you paste below can only connect a session that is already linked."]})]}),(0,e.jsxs)("details",{className:"text-sm",children:[(0,e.jsx)("summary",{className:"cursor-pointer font-medium",children:"I only have an operator key"}),(0,e.jsxs)("div",{className:"mt-3 grid gap-2 font-medium",children:[(0,e.jsx)(Ee,{htmlFor:"openwa-api-key",label:"Operator API key",help:"An operator key whose allowed sessions contain only this agent's session. Leave allowed chats empty: a chat-restricted key cannot receive live events."}),(0,e.jsx)(ie,{id:"openwa-api-key",type:"password",value:y,autoComplete:"new-password",disabled:d||L.isPending,onChange:t(m=>{h(m.target.value),Z()},"onChange")})]})]}),(0,e.jsx)(p,{variant:"secondary",disabled:d||L.isPending||!i.trim()||!y.trim()&&!l.trim(),onClick:t(()=>L.mutate(),"onClick"),children:L.isPending?"Inspecting gateway…":"Inspect gateway"}),L.isError&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:Se(L.error,$)}),v&&(0,e.jsxs)("div",{className:"space-y-4",children:[(0,e.jsxs)("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-sm",children:[(0,e.jsx)("dt",{className:"text-ink-3",children:"Gateway version"}),(0,e.jsx)("dd",{children:v.gatewayVersion??`Unknown (assuming ${v.pinnedVersion})`}),(0,e.jsx)("dt",{className:"text-ink-3",children:"Engine"}),(0,e.jsx)("dd",{children:v.engine??"Unknown"}),(0,e.jsx)("dt",{className:"text-ink-3",children:"Agent key"}),(0,e.jsx)("dd",{children:v.agentKeyMinted?"New operator key for the chosen session":v.keyRole})]}),v.warnings.length>0&&(0,e.jsx)("div",{role:"status",className:"space-y-1 rounded-lg border border-line bg-bg-3/30 p-4 text-sm",children:v.warnings.map(m=>(0,e.jsxs)("p",{className:"flex gap-2",children:[(0,e.jsx)(ze,{className:"mt-0.5 size-4 shrink-0","aria-hidden":"true"}),(0,e.jsx)("span",{children:m})]},m))}),(0,e.jsxs)("fieldset",{className:"space-y-2",children:[(0,e.jsx)("legend",{className:"text-sm font-medium",children:"WhatsApp session"}),v.sessions.length===0?(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"This gateway has no WhatsApp session yet. Create one below."}):v.eligible||T?null:v.canManageSessions?(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"No session is ready yet. Link WhatsApp to a session, or create a new one."}):(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"No session can be connected. Connect WhatsApp in the OpenWA dashboard or free the session from its other channel."}),v.sessions.map(m=>(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[(0,e.jsxs)("label",{className:"flex min-w-0 flex-1 items-center gap-2 text-sm",children:[(0,e.jsx)("input",{type:"radio",name:"openwa-session",value:m.sessionId,checked:C===m.sessionId,disabled:!m.eligible||d||!!b&&b!==m.sessionId,onChange:t(()=>S(m.sessionId),"onChange")}),(0,e.jsxs)("span",{className:"min-w-0 break-words",children:[m.name,m.maskedNumber?` · ${m.maskedNumber}`:"",m.pushName?` · ${m.pushName}`:"",m.unavailableReason?` — ${m.unavailableReason}`:""]})]}),v.canManageSessions&&m.status!=="ready"&&T?.id!==m.sessionId&&!b?(0,e.jsx)(p,{size:"sm",variant:"secondary",disabled:d,onClick:t(()=>{k(!1),z({id:m.sessionId,name:m.name,status:m.status})},"onClick"),children:"Link WhatsApp"}):null]},m.sessionId))]}),v.canManageSessions&&!b&&!T&&(j?(0,e.jsxs)("div",{className:"space-y-2 rounded-lg border border-line p-4",children:[(0,e.jsx)("label",{htmlFor:"openwa-new-session-name",className:"block text-sm font-medium",children:"New session name"}),(0,e.jsx)(ie,{id:"openwa-new-session-name",value:P,placeholder:"pmo",autoComplete:"off",disabled:F.isPending,"aria-invalid":M?!0:void 0,onChange:t(m=>_(m.target.value),"onChange")}),(0,e.jsx)("p",{className:"text-xs text-ink-3",children:"Letters, digits, dots, dashes or underscores. OpenWA cannot rename a session later."}),(M||F.isError)&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:M??Se(F.error,$)}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,e.jsx)(p,{size:"sm",disabled:F.isPending,onClick:oe,children:F.isPending?"Creating session…":"Create and show QR"}),(0,e.jsx)(p,{size:"sm",variant:"ghost",disabled:F.isPending,onClick:t(()=>k(!1),"onClick"),children:"Cancel"})]})]}):(0,e.jsx)(p,{variant:"secondary",disabled:d,onClick:t(()=>k(!0),"onClick"),children:"Create new WhatsApp session"})),T&&(0,e.jsxs)("section",{"aria-label":"Link "+T.name,className:"space-y-3 rounded-lg border border-line p-4",children:[(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsxs)("h2",{className:"text-base font-semibold",children:["Link WhatsApp to ",T.name]}),(0,e.jsx)("p",{className:"text-sm text-ink-3",children:'On the phone, open WhatsApp, go to Linked devices, then scan the QR code, or choose "Link with phone number" and enter the pairing code. The session is selected as soon as it is ready.'})]}),(0,e.jsx)(Pt,{endpointId:a.id,run:B,session:T,onReady:x}),(0,e.jsx)(p,{size:"sm",variant:"ghost",onClick:t(()=>z(null),"onClick"),children:"Cancel"})]})]}),(v?.eligible||D)&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("fieldset",{className:"space-y-2",children:[(0,e.jsx)("legend",{className:"text-sm font-medium",children:"Whose number is this?"}),(0,e.jsxs)("label",{className:"flex items-start gap-2 text-sm",children:[(0,e.jsx)("input",{type:"radio",name:"openwa-number-mode",className:"mt-1",checked:O==="agent_number",disabled:d||D,onChange:t(()=>s("agent_number"),"onChange")}),(0,e.jsxs)("span",{children:[(0,e.jsxs)("span",{className:"font-medium",children:["A number dedicated to ",r]}),(0,e.jsx)("span",{className:"block text-ink-3",children:"People message this number to reach the agent. Direct messages, mentions, and replies start work."})]})]}),(0,e.jsxs)("label",{className:"flex items-start gap-2 text-sm",children:[(0,e.jsx)("input",{type:"radio",name:"openwa-number-mode",className:"mt-1",checked:O==="owner_number",disabled:d||D,onChange:t(()=>s("owner_number"),"onChange")}),(0,e.jsxs)("span",{children:[(0,e.jsx)("span",{className:"font-medium",children:"An owner's personal number"}),(0,e.jsx)("span",{className:"block text-ink-3",children:"The agent replies as you. Only chats you enable in Settings can trigger it, and its messages carry a visible prefix so contacts know an assistant wrote them. Wardmote can read every chat this session can see."})]})]})]}),(0,e.jsxs)("fieldset",{className:"space-y-2",children:[(0,e.jsx)("legend",{className:"text-sm font-medium",children:"Before connecting, confirm"}),(0,e.jsxs)("label",{className:"flex items-start gap-2 text-sm",children:[(0,e.jsx)("input",{type:"checkbox",className:"mt-1",checked:N,disabled:d,onChange:t(m=>J(m.target.checked),"onChange")}),(0,e.jsx)("span",{children:"Send pacing is turned on in the gateway (SEND_PACING_ENABLED). It spaces out outgoing messages to lower the risk of WhatsApp restricting the number."})]}),(0,e.jsxs)("label",{className:"flex items-start gap-2 text-sm",children:[(0,e.jsx)("input",{type:"checkbox",className:"mt-1",checked:f,disabled:d,onChange:t(m=>X(m.target.checked),"onChange")}),(0,e.jsx)("span",{children:"Wardmote is the only app sending as this session. Other bots, webhooks, or scripts on the same session could make the agent mistake their messages for yours."})]})]})]}),(0,e.jsx)(Ae,{onSaveExit:A,disabled:d,children:(0,e.jsx)(p,{disabled:d||L.isPending||!w,onClick:fe,children:d?"Connecting…":u?"Reconnect OpenWA":"Connect session"})})]})}t(Ht,"OpenwaConnectStep");function qt(){let a=0;return{start(){return a+=1,a},invalidate(){a+=1},isCurrent(r){return r===a}}}t(qt,"createGitHubPrivateKeyReadGuard");async function Bt(a){if(a.size===0)throw new Error("That file is empty. Choose the private key downloaded from your GitHub App.");if(a.size>65536)throw new Error("That file is too large. Choose a GitHub App private key smaller than 64 KB.");let r;try{r=await a.text()}catch{throw new Error("Wardmote couldn't read that file. Choose the .pem file again or paste the private key.")}if(!r.trim())throw new Error("That file is empty. Choose the private key downloaded from your GitHub App.");return r}t(Bt,"readGitHubPrivateKeyFile");var Ne={speko:"Speko",agentmail:"AgentMail",slack:"Slack",github:"GitHub",discord:"Discord","microsoft-teams":"Microsoft Teams",telegram:"Telegram","imessage-photon":"iMessage Photon",openwa:"OpenWA"},$t=new Set(Object.keys(Ne));function Vt(a,r){return r?{action:a,...r.apiKey||r.adminApiKey?{credentials:{...r.apiKey?{apiKey:r.apiKey}:{},...r.adminApiKey?{adminApiKey:r.adminApiKey}:{}}}:{},openwa:{baseUrl:r.baseUrl,sessionId:r.sessionId,numberMode:r.numberMode==="owner_number"?"owner_number":"agent_number",attestations:{pacing:r.pacing==="true",soleClient:r.soleClient==="true"}}}:{action:a}}t(Vt,"openwaSetupInput");function Qt(a){return a!==null&&$t.has(a)}t(Qt,"isProvider");function Yt(a){if(!a)return null;try{return new URL(a).origin}catch{return null}}t(Yt,"publicOrigin");function Jt(a,r,u){if(!r||!a)return!1;const d=a.status==="attention"||a.status==="revoked";return a.provider==="github"&&d&&!a.providerAccountId&&!a.botExternalId?!1:d||u&&(a.status==="active"||a.status==="paused")}t(Jt,"isChatEndpointRepairing");function Xt({provider:a,onChat:r,onTools:u}){const{setBreadcrumbs:d}=De();return(0,c.useEffect)(()=>(d([{label:"Connectors",href:"/apps"},{label:"Choose connection"}]),()=>d([])),[d]),(0,e.jsxs)("div",{className:"max-w-2xl space-y-6",children:[(0,e.jsx)(Ve,{labels:a==="slack"?["Choose agent","App configuration access token","Install Slack app","Send a message"]:void 0,step:0,availableStep:0,onSelect:r}),(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:"Choose how to connect"}),(0,e.jsxs)("p",{className:"mt-1 text-sm text-ink-3",children:["What should this ",Ne[a]," connection do?"]})]}),(0,e.jsxs)("div",{className:"grid gap-3",children:[(0,e.jsxs)("button",{type:"button",className:"flex items-center gap-4 rounded-xl border border-line p-4 text-left hover:bg-bg-3/40",onClick:r,children:[(0,e.jsx)(ut,{size:48}),(0,e.jsxs)("span",{children:[(0,e.jsx)("span",{className:"block text-sm font-semibold",children:"Chat with an agent"}),(0,e.jsxs)("span",{className:"mt-1 block text-sm text-ink-3",children:["People in ",Ne[a]," can start and continue Wardmote tasks."]})]})]}),(0,e.jsxs)("button",{type:"button",className:"flex items-center gap-4 rounded-xl border border-line p-4 text-left hover:bg-bg-3/40",onClick:u,children:[(0,e.jsx)("span",{className:"flex size-12 shrink-0 items-center justify-center text-ink-3","aria-hidden":"true",children:(0,e.jsx)(at,{className:"size-8"})}),(0,e.jsxs)("span",{children:[(0,e.jsx)("span",{className:"block text-sm font-semibold",children:"Use this connection as an agent tool"}),(0,e.jsxs)("span",{className:"mt-1 block text-sm text-ink-3",children:["Let agents use ",Ne[a]," actions and data while they work."]})]})]})]})]})}t(Xt,"ChatConnectionPurpose");function Os(){const[a]=Ue();return a.get("provider")==="github"?(0,e.jsx)(Ot,{}):a.get("provider")==="agentmail"?(0,e.jsx)(At,{}):(0,e.jsx)(Zt,{})}t(Os,"ChatEndpointSetup");function Zt(){const[a,r]=Ue(),u=Le(),d=We(),{selectedCompanyId:U}=He(),{setBreadcrumbs:A}=De(),{pushToast:b}=Be(),i=Qt(a.get("provider"))?a.get("provider"):null,g=a.get("toolHref")||"/apps",y=a.get("agentId")??"",h=a.get("resume")??"",l=a.get("reconnect")==="1",[q,C]=(0,c.useState)(a.get("purpose")==="chat"?"chat":"choice"),[S,G]=(0,c.useState)(y),[te,T]=(0,c.useState)(a.get("stage")==="credentials"),[z,j]=(0,c.useState)(null),[k,P]=(0,c.useState)(!1),[_,M]=(0,c.useState)(!1),[K,O]=(0,c.useState)(null),[s,N]=(0,c.useState)(null),[J,f]=(0,c.useState)({}),[X,L]=(0,c.useState)(""),[Z,v]=(0,c.useState)(null);(0,c.useEffect)(()=>(A([{label:"Connectors",href:"/apps"},{label:"Connect chat"}]),()=>A([])),[A]);const re=ce({queryKey:["chat-endpoint-setup-agents",U],queryFn:t(()=>Pe.list(U),"queryFn"),enabled:!!U}),B=ce({queryKey:["chat-endpoint-setup-resume",h],queryFn:t(()=>W.get(h),"queryFn"),enabled:!!h,refetchInterval:t(n=>["creating","install","credentials_saved"].includes(n.state.data?.setup?.slackRegistration?.status??"")?1500:!1,"refetchInterval")});(0,c.useEffect)(()=>{B.data&&(N(n=>(n?.setup?.slackSetupMethod==="automatic"&&!n.providerAccountId&&B.data.providerAccountId&&j(null),B.data)),G(B.data.assignedAgentId),C("chat"))},[B.data]);const F=ce({queryKey:["chat-endpoint-github-webhook-verification",s?.id],queryFn:t(()=>W.get(s.id),"queryFn"),enabled:!!(i==="github"&&s?.id&&s.setup?.step==="provider_setup"&&s.setup?.webhookSecretConfigured&&!s.setup.webhookVerifiedAt),refetchInterval:1500});(0,c.useEffect)(()=>{!F.data||i!=="github"||!s||s.id!==F.data.id||s.setup?.step!=="provider_setup"||!s.setup?.webhookSecretConfigured||s.setup.webhookVerifiedAt||N(F.data)},[s,F.data,i]);const x=ce({queryKey:ge.instance.experimentalSettings,queryFn:t(()=>ht.getExperimental(),"queryFn"),enabled:s?.setup?.step==="test"}),oe=(0,c.useMemo)(()=>(re.data??[]).filter(n=>Wt(n.status)),[re.data]),$=re.data?.find(n=>n.id===S),D=K?.agentId===S?K.app:s?.setup?.slackApp??Ke($?.name??s?.assignedAgentName??""),w=Fe.safeParse(D),fe=!_&&(!s||s.status==="draft"&&!s.botExternalId&&(!s.setup?.slackRegistration||s.setup.slackRegistration.status==="failed")),m=t((n,I=!1)=>{n.setup?.slackSetupMethod==="automatic"&&n.setup.slackRegistration?.status==="configured"&&s?.setup?.slackRegistration?.status!=="configured"&&j(null),N(ae=>I&&ae?.id!==n.id?ae:n),d.setQueryData(["chat-endpoint-setup-resume",n.id],n),d.setQueryData(ge.chatEndpoints.detail(n.id),n),n.provider==="github"&&d.setQueryData(["chat-endpoint-github-webhook-verification",n.id],n)},"syncEndpointSnapshot"),H=ye({mutationFn:t(()=>W.create(U,{provider:i,assignedAgentId:S,...i==="slack"?{slackApp:w.success?w.data:D}:{}}),"mutationFn"),onSuccess:t(n=>{if(j(null),m(n),n.provider==="imessage-photon"||n.provider==="slack"||n.provider==="openwa"){const I=new URLSearchParams(a);I.set("resume",n.id),r(I,{replace:!0})}},"onSuccess"),onError:t(n=>b({title:"Couldn't start setup",body:n instanceof Error?n.message:"Try again.",tone:"error"}),"onError")}),le=ye({scope:{id:`slack-app-details:${s?.id}`},mutationFn:t(n=>W.update(s.id,{slackApp:n}),"mutationFn"),onSuccess:t(n=>m(n),"onSuccess")}),he=t(async()=>{s&&fe&&w.success&&JSON.stringify(w.data)!==JSON.stringify(s.setup?.slackApp)&&await le.mutateAsync(w.data)},"persistSlackDetails"),pe=t(async n=>{if(n&&i!=="slack"){u("/apps");return}if(!s){if(!S){n&&u("/apps");return}H.mutate(void 0,{onSuccess:t(()=>{n&&u("/apps")},"onSuccess")});return}try{i==="slack"&&await he()}catch{return}n?u("/apps"):j(1)},"continueFromAgent"),E=ye({mutationFn:t(async({action:n,values:I})=>{const ae=s.id;try{return i==="openwa"?await W.setup(ae,Vt(n,I)):await W.setup(ae,i==="imessage-photon"?{action:n,...I?.projectSecret?{credentials:{projectSecret:I.projectSecret}}:{},...I?.projectId&&I.allocation==="shared"?{photon:{allocation:"shared",projectId:I.projectId}}:I?.projectId&&I?.lineId?{photon:{allocation:"dedicated",projectId:I.projectId,lineId:I.lineId}}:{}}:{action:n,credentials:I})}catch(de){if(n==="verify"){const ke=await W.get(ae).catch(()=>null);if(ke?.setup?.step==="test"||ke?.setup?.step==="complete")return ke}throw de}},"mutationFn"),onMutate:t(()=>v(null),"onMutate"),onSuccess:t(n=>{v(null),j(null),m(n),f({}),n.setup?.step!=="test"&&n.setup?.step!=="complete"&&P(!1)},"onSuccess"),onError:t((n,I)=>v(Se(n,i==="openwa"?{apiKey:I.values?.apiKey??"",adminApiKey:I.values?.adminApiKey??""}:I.values)),"onError")}),me=ye({mutationFn:t(()=>W.generateSetupSecret(s.id),"mutationFn"),onMutate:t(async()=>{const n=s.id;return await Promise.all([d.cancelQueries({queryKey:["chat-endpoint-github-webhook-verification",n],exact:!0}),d.cancelQueries({queryKey:["chat-endpoint-setup-resume",n],exact:!0}),d.cancelQueries({queryKey:ge.chatEndpoints.detail(n),exact:!0})]),{endpointId:n}},"onMutate"),onSuccess:t(async({webhookSecret:n},I,ae)=>{const de=ae.endpointId,ke=t(ne=>({...ne,setup:{...ne.setup,step:"provider_setup",webhookSecretConfigured:!0,webhookVerifiedAt:null}}),"markRotated");d.removeQueries({queryKey:["chat-endpoint-github-webhook-verification",de],exact:!0}),L(n),N(ne=>ne&&ne.id===de?ke(ne):ne),d.setQueryData(["chat-endpoint-setup-resume",de],ne=>ne&&ke(ne)),d.setQueryData(ge.chatEndpoints.detail(de),ne=>ne&&ke(ne));try{const ne=await W.get(de);m(ne,!0)}catch{}},"onSuccess"),onError:t(n=>b({title:"Couldn't generate webhook secret",body:n instanceof Error?n.message:"Try again.",tone:"error"}),"onError")}),xe=ye({mutationFn:t(()=>i==="slack"?W.finishSlackSetup(s.id):W.test(s.id),"mutationFn"),onSuccess:t(n=>{m(n),n.status==="active"&&u(`/apps/chat/${n.id}/settings`)},"onSuccess"),onError:t(n=>b({title:i==="slack"?"Couldn't finish setup":"Test not complete",body:n instanceof Error?n.message:i==="slack"?"Try finishing setup again.":"Send the provider message, then try again.",tone:"error"}),"onError")}),be=Jt(s,h,l),V=i==="slack",ee=V&&(!s||s.setup?.slackSetupMethod==="automatic"),je=ee&&(s?.setup?.step==="test"||s?.setup?.step==="complete"),ue=V?ee?3:5:2,se=s?ee&&s.setup?.slackRegistration?.status==="configured"&&s.setup.slackAccount?.status!=="linked"&&s.setup.step!=="complete"?2:!be&&(s.setup?.step==="test"||s.setup?.step==="complete")?V&&s.setup?.step!=="complete"&&!ee&&!k?4:ue:ee&&s.setup?.slackRegistration?.status==="credentials_saved"?2:V&&s.providerAccountId&&!be?3:V&&(te||be||s.setup?.slackSetupMethod==="existing"||ee&&s.setup?.slackRegistration?.appId)?2:1:0,o=Math.min(z??se,se),R=ce({queryKey:["chat-endpoint-slack-webhook-verification",s?.id],queryFn:t(()=>W.get(s.id),"queryFn"),enabled:!!(V&&o===3&&s?.setup?.step==="provider_setup"&&!s.setup.webhookVerifiedAt&&!E.isPending),refetchInterval:1500});(0,c.useEffect)(()=>{const n=R.data;!n||!s||n.id!==s.id||E.isPending||s.setup?.step!=="provider_setup"||s.setup.webhookVerifiedAt||!n.setup?.webhookVerifiedAt||N(n)},[R.data,s,E.isPending]);const we=(0,c.useRef)(null);return(0,c.useEffect)(()=>{if(!V||o!==3||s?.setup?.step!=="provider_setup"||!s.setup.webhookVerifiedAt||E.isPending)return;const n=`${s.id}:${s.setup.webhookVerifiedAt}`;we.current!==n&&(we.current=n,E.mutate({action:"verify"}))},[V,o,s,E]),i?U?q==="choice"?(0,e.jsx)(Xt,{provider:i,onChat:t(()=>C("chat"),"onChat"),onTools:t(()=>u(g),"onTools")}):(0,e.jsxs)("div",{className:je&&o===ue?"mx-auto w-full max-w-2xl space-y-6":"max-w-2xl space-y-6",children:[(0,e.jsx)(Ve,{labels:V?ee?["Choose agent","App configuration access token","Install Slack app","Send a message"]:["Choose agent","Create Slack app","Add credentials","Verify Slack connection","Connect your Slack account","Try it"]:void 0,step:o,availableStep:se,disabled:_||H.isPending||le.isPending||E.isPending||me.isPending||xe.isPending,onSelect:j}),(0,e.jsxs)("div",{className:"min-w-0 space-y-6",children:[o===0?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:"Which agent do you want to chat with?"}),(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:"This agent is permanent for the connection. Connect another channel to represent a different agent."})]}),s?(0,e.jsx)(ie,{"aria-label":"Assigned agent",value:s.assignedAgentName??$?.name??S,readOnly:!0}):(0,e.jsx)($e,{agents:oe,value:S,onChange:G,placeholder:"Choose an active agent",emptyMessage:"No active agents are available."}),V&&($||s)&&(0,e.jsxs)(Me,{children:[(0,e.jsx)(Et,{value:D,readOnly:!fe||H.isPending,onChange:t(n=>O({agentId:S,app:n}),"onChange"),onBlur:t(()=>{he().catch(()=>{})},"onBlur")}),le.isError&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Couldn't save the Slack app details. Try again before continuing."})]}),i==="github"&&(0,e.jsx)(Qe,{agent:$}),(0,e.jsx)(Ae,{disabled:H.isPending||le.isPending,onSaveExit:t(()=>{pe(!0)},"onSaveExit"),children:(0,e.jsxs)(p,{disabled:!S||H.isPending||le.isPending||V&&!w.success,onClick:t(()=>{pe(!1)},"onClick"),children:[H.isPending&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),"Continue"]})})]}):null,s&&!(je&&o===ue)&&(0,e.jsxs)("div",{hidden:o!==1&&!(V&&(o===2||o===3)),className:"space-y-6",children:[Z?(0,e.jsxs)("div",{role:"alert",className:"rounded-lg border border-bad/30 bg-bad/10 p-4 text-sm text-bad",children:[(0,e.jsx)("p",{className:"font-medium",children:"Connection failed"}),(0,e.jsx)("p",{className:"mt-1",children:Z})]}):null,(0,e.jsx)(es,{provider:i,slackStage:o===1?"app":o===3?"finish":"credentials",onSlackCredentialsContinue:t(()=>j(3),"onSlackCredentialsContinue"),onSlackVerificationContinue:t(()=>j(4),"onSlackVerificationContinue"),slackVerificationError:R.isError,onSlackAppCreated:t(()=>{T(!0),j(2);const n=new URLSearchParams(a);n.set("resume",s.id),n.set("stage","credentials"),r(n,{replace:!0})},"onSlackAppCreated"),agentName:$?.name??s.assignedAgentName,endpoint:s,onEndpointSaved:m,credentials:J,setCredentials:f,repairing:be,pending:E.isPending,onAutomaticBusy:M,generatedWebhookSecret:X,generatingSetupSecret:me.isPending,onGenerateSetupSecret:t(()=>me.mutate(),"onGenerateSetupSecret"),onAction:t((n,I)=>E.mutate({action:n,values:I}),"onAction")},`${i}:${s.id}`)]}),s&&V&&!ee&&o===4&&(0,e.jsx)(_t,{endpointId:s.id,command:s.setup?.slackApp?.command??s.setup?.command??"/wardmote",testStartedAt:s.setup?.testStartedAt,onSaveExit:t(()=>u("/apps"),"onSaveExit"),onConnected:t(()=>{P(!0),j(5)},"onConnected")}),s&&o===ue&&(!ee||je)&&(ee?(0,e.jsxs)("div",{className:"flex flex-col items-center gap-6 py-8 text-center",children:[(0,e.jsx)(wt,{agent:$??{id:s.assignedAgentId,name:s.assignedAgentName},size:256,state:"success",trackingScope:"page",label:`${$?.name??s.assignedAgentName} avatar`}),(0,e.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[(0,e.jsxs)("h1",{className:"flex items-center gap-2 text-2xl font-bold",children:[(0,e.jsx)(Re,{"aria-hidden":"true",className:"size-6 text-(--status-task-done)"}),"Success"]}),(0,e.jsxs)("p",{className:"flex flex-wrap items-center justify-center gap-2 text-base text-ink-3",children:[(0,e.jsxs)("span",{children:["You can now talk to ",$?.name??s.assignedAgentName," in Slack"]}),(0,e.jsx)("img",{src:"/brands/apps/slack.svg",alt:"","aria-hidden":"true",className:"size-6"})]})]}),(0,e.jsxs)(p,{disabled:xe.isPending,onClick:t(()=>xe.mutate(),"onClick"),children:[xe.isPending&&(0,e.jsx)(Y,{className:"size-4 animate-spin"}),"Done"]})]}):(0,e.jsx)(ts,{endpointId:s.id,provider:i,agentName:$?.name??s.assignedAgentName,botLabel:s.botLabel,botUsername:s.botUsername,botExternalId:s.botExternalId,slackAccount:s.setup?.slackAccount,photonAllocation:s.photonAllocation,providerUrl:s.setup?.slackAccount?.dmChannelId&&s.providerAccountId?`https://app.slack.com/client/${encodeURIComponent(s.providerAccountId)}/${encodeURIComponent(s.setup.slackAccount.dmChannelId)}`:s.setup?.providerUrl,guestIsolationState:x.isPending?"loading":x.isError?"unknown":x.data?.enableIsolatedWorkspaces===!0?"enabled":"disabled",pending:xe.isPending,onOpenAccess:t(()=>u(`/apps/chat/${s.id}/access`),"onOpenAccess"),onTest:t(()=>xe.mutate(),"onTest"),onSaveExit:t(()=>u("/apps"),"onSaveExit")})),o!==0&&!V&&!(i==="openwa"&&o===1)&&(0,e.jsx)("div",{className:"flex justify-start",children:(0,e.jsx)(p,{variant:"ghost",onClick:t(()=>u("/apps"),"onClick"),children:"Save & exit"})})]})]}):(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Select an organization to connect chat."}):(0,e.jsx)("p",{className:"text-sm text-bad",children:"This chat provider is not supported."})}t(Zt,"ChatSdkEndpointSetup");function es({provider:a,slackStage:r,onSlackCredentialsContinue:u,onSlackVerificationContinue:d,slackVerificationError:U,onSlackAppCreated:A,agentName:b,endpoint:i,credentials:g,setCredentials:y,repairing:h,pending:l,onAutomaticBusy:q,onEndpointSaved:C,generatedWebhookSecret:S,generatingSetupSecret:G,onGenerateSetupSecret:te,onAction:T}){const{pushToast:z}=Be(),j=Le(),k=(g.botToken??"").trim(),P=a==="slack"&&k.length>0&&!k.startsWith("xoxb-"),_=a==="slack"&&/^x[a-z0-9]*-/i.test((g.signingSecret??"").trim()),M=a==="slack"&&!!i.providerAccountId,K=M&&!h&&!k&&!g.signingSecret?.trim(),O=t(()=>z({title:"Couldn't copy to clipboard",body:"Select and copy the value manually.",tone:"error"}),"reportCopyFailure"),s=t((n,I,ae="password")=>(0,e.jsxs)("label",{className:"grid gap-2 text-sm font-medium",children:[I,(0,e.jsx)(ie,{type:ae,value:g[n]??"",onChange:t(de=>y({...g,[n]:de.target.value}),"onChange")})]}),"field"),N=t(n=>window.open(i.setup?.authorizationUrl??i.setup?.providerUrl??n,"_blank","noopener,noreferrer"),"openProviderSetup"),J=t((n,I)=>(0,e.jsxs)("div",{className:"grid gap-2",children:[(0,e.jsx)("p",{className:"text-sm font-medium",children:n}),(0,e.jsx)("div",{className:"rounded-lg border border-line bg-bg-3 p-3 font-mono text-xs break-all",children:I??"This endpoint is unavailable. Check the server's public URL."})]}),"endpointValue"),[f,X]=(0,c.useState)(!1),L=Ct(),[Z,v]=(0,c.useState)(!1),re=(0,c.useRef)(null);(0,c.useEffect)(()=>(v(!1),()=>{re.current!==null&&(clearTimeout(re.current),re.current=null)}),[r]);const[B,F]=(0,c.useState)(!1),[x,oe]=(0,c.useState)(null),[$,D]=(0,c.useState)(!1),[w,fe]=(0,c.useState)(!1),m=(0,c.useRef)(null),H=(0,c.useRef)(qt()).current;(0,c.useEffect)(()=>()=>{H.invalidate()},[H]);const le=t(async n=>{const I=n.currentTarget.files?.[0];if(n.currentTarget.value="",!I)return;const ae=H.start();oe(null),D(!1),fe(!0);try{const de=await Bt(I);if(!H.isCurrent(ae))return;y(ke=>({...ke,privateKey:de})),F(!1),D(!0)}catch(de){if(!H.isCurrent(ae))return;oe(de instanceof Error?de.message:"Wardmote couldn't read that file. Choose the .pem file again or paste the private key.")}finally{H.isCurrent(ae)&&fe(!1)}},"loadPrivateKeyFile"),he=t(n=>{H.invalidate(),oe(null),D(!1),fe(!1),y(I=>({...I,privateKey:n}))},"replacePrivateKey"),pe=i.setup?.slackApp??{...Ke(b),...i.setup?.command?{command:i.setup.command}:{}},E=i.setup?.slackSetupMethod==="automatic",me=Fe.safeParse(pe),xe=t(()=>j("/apps"),"saveSlackAndExit"),be=pe.appName.trim(),V=pe.botName.trim(),ee=pe.command.trim(),je=i.setup?.webhookUrl??"<wardmote-webhook-url>",ue=JSON.stringify(Xe({app:{appName:be,botName:V,command:ee},agentName:b,webhookUrl:je,...E&&i.setup?.slackOAuthCallbackUri?{redirectUri:i.setup.slackOAuthCallbackUri}:{}}),null,2),se=`https://api.slack.com/apps?new_app=1&manifest_json=${encodeURIComponent(ue)}`;(0,c.useEffect)(()=>X(!1),[ue]);const o=g.clientId?.trim()||"<application-client-id>",R=JSON.stringify({bots:[{botId:o,scopes:["personal","team","groupChat"],supportsFiles:!0,isNotificationOnly:!1,commandLists:[{scopes:["personal","groupChat"],commands:[{title:"/status",description:"Show the active Wardmote task status"},{title:"/new",description:"Start a new Wardmote task in this chat"},{title:"/close",description:"Close the active chat conversation"}]}]}],webApplicationInfo:{id:o,resource:"https://paperclip.ing"},authorization:{permissions:{resourceSpecific:[{name:"ChannelMessage.Read.Group",type:"Application"},{name:"ChatMessage.Read.Chat",type:"Application"}]}}},null,2);if(a==="imessage-photon")return(0,e.jsx)(Gt,{endpoint:i,agentName:b,repairing:h,pending:l,onAction:T});if(a==="openwa")return(0,e.jsx)(Ht,{endpoint:i,agentName:b,repairing:h,pending:l,onAction:T,onSaveExit:t(()=>j("/apps"),"onSaveExit")});if(a==="discord"){const n=g.applicationId?.trim()??"",I=g.guildId?.trim()??"",ae=n?`https://discord.com/oauth2/authorize?client_id=${encodeURIComponent(n)}&permissions=309237763136&scope=bot${I?`&guild_id=${encodeURIComponent(I)}&disable_guild_select=true`:""}`:null;return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("h1",{className:"text-xl font-bold",children:["Connect ",b," to Discord"]}),(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:h?"Reconnect verifies this same Discord application and server installation. It does not add or remove the bot from the server. Leave fields blank to reuse saved credentials.":"Create one dedicated Discord application and bot for this Wardmote agent."})]}),(0,e.jsxs)("ol",{className:"list-decimal space-y-2 pl-5 text-sm",children:[(0,e.jsx)("li",{children:"In Discord Developer Portal, create an application. Copy its Application ID from General Information."}),(0,e.jsx)("li",{children:"Open Bot, create the bot, enable Message Content Intent, then reset and copy its token."}),(0,e.jsx)("li",{children:"Enable Developer Mode in Discord, right-click the target server, and copy its Server ID."}),(0,e.jsx)("li",{children:"Enter those values below, then use the generated install link to add the bot to that server."})]}),(0,e.jsxs)(p,{variant:"secondary",onClick:t(()=>N("https://discord.com/developers/applications"),"onClick"),children:["Open Discord Developer Portal ",(0,e.jsx)(Q,{})]}),s("applicationId","Application ID","text"),s("guildId","Server ID","text"),s("botToken","Bot token"),ae&&(0,e.jsx)(p,{asChild:!0,variant:"secondary",children:(0,e.jsxs)("a",{href:ae,target:"_blank",rel:"noreferrer",children:["Install bot in this server ",(0,e.jsx)(Q,{})]})}),(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"The install link grants only View Channels, Send Messages, Create Public Threads, Send Messages in Threads, Read Message History, Add Reactions, Embed Links, and Attach Files. Wardmote still requires each discovered channel to be enabled in Access."}),(0,e.jsxs)(p,{disabled:!h&&(!g.applicationId||!g.guildId||!g.botToken)||l,onClick:t(()=>T(h?"reconnect":"configure",g),"onClick"),children:[l&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),h?"Reconnect Discord bot":"Connect Discord bot"]})]})}if(a==="telegram")return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("h1",{className:"text-xl font-bold",children:["Create ",b," in Telegram"]}),(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:h?"Reconnect verifies this same BotFather bot and automatically refreshes its Wardmote webhook and command menu. It does not recreate the bot or change its chat memberships. Leave the token blank to reuse the saved credential.":"Create a bot with BotFather, then paste the token it gives you."})]}),(0,e.jsxs)("ol",{className:"list-decimal space-y-2 pl-5 text-sm",children:[(0,e.jsxs)("li",{children:["Open BotFather and send ",(0,e.jsx)("code",{children:"/newbot"}),"."]}),(0,e.jsx)("li",{children:"Enter the bot display name."}),(0,e.jsxs)("li",{children:["Choose an available username ending in ",(0,e.jsx)("code",{children:"bot"}),"."]})]}),(0,e.jsxs)("p",{className:"rounded-md border border-line bg-bg-3/40 p-3 text-sm text-ink-3",children:["Wardmote works with Telegram's default bot privacy mode and registers its command menu automatically. In a group, ordinary mentions are not delivered to bots: start or continue work with"," ",(0,e.jsx)("code",{children:"/task@bot_username <request>"}),", or reply directly to a message from the bot."]}),(0,e.jsxs)(p,{variant:"secondary",onClick:t(()=>N("https://t.me/BotFather"),"onClick"),children:["Open BotFather ",(0,e.jsx)(Q,{})]}),s("botToken","Bot token"),(!i.setup?.webhookUrl||E&&!i.setup?.slackOAuthCallbackUri?.startsWith("https://"))&&(0,e.jsx)("p",{className:"text-sm text-bad",children:"Configure a public HTTPS URL for this Wardmote instance before connecting Telegram."}),(0,e.jsxs)(p,{disabled:!h&&!g.botToken||!i.setup?.webhookUrl||l,onClick:t(()=>T(h?"reconnect":"configure",g),"onClick"),children:[l&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),h?"Reconnect bot":"Connect bot"]})]});if(a==="microsoft-teams")return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("h1",{className:"text-xl font-bold",children:["Connect ",b," to Microsoft Teams"]}),(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:h?"Reconnect verifies this same Microsoft app, tenant, and bot identity. It does not upload or reinstall the Teams app. Leave fields blank to reuse saved credentials.":"Use your own Microsoft app credentials for this bot."})]}),(0,e.jsx)("p",{className:"rounded-md border border-line bg-bg-3/40 p-3 text-sm text-ink-3",children:"This setup requires a Microsoft 365 work or school organization where you can register an Entra app, create an Azure Bot, and upload or install a Teams app. Personal or free Teams accounts at teams.live.com cannot complete this setup. This release supports Microsoft 365 commercial cloud tenants only; GCC, GCC High, DoD, and Microsoft 365 operated by 21Vianet are not supported yet."}),(0,e.jsxs)("ol",{className:"list-decimal space-y-2 pl-5 text-sm",children:[(0,e.jsx)("li",{children:"In Microsoft Entra, create a single-tenant app registration. Copy its Application (client) ID and Directory (tenant) ID, then create a client secret and copy its value."}),(0,e.jsx)("li",{children:"In Azure, create an Azure Bot. Choose Single Tenant, use that Application ID, set its messaging endpoint to the Wardmote URL below, and add the Microsoft Teams channel."}),(0,e.jsx)("li",{children:"In Teams Developer Portal, create an app, add a bot with the same Application ID, then apply the manifest settings shown below. The block binds the Teams resource-specific consent permissions to that Entra app; these are not Microsoft Graph permissions in Entra. These permissions let the installed app receive every message in a team or group chat without an @mention, so describe that access to installers. Download the package and install it in the target team or group chat."})]}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,e.jsx)(p,{asChild:!0,variant:"secondary",children:(0,e.jsxs)("a",{href:"https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade",target:"_blank",rel:"noreferrer",children:["Open Microsoft Entra ",(0,e.jsx)(Q,{})]})}),(0,e.jsx)(p,{asChild:!0,variant:"secondary",children:(0,e.jsxs)("a",{href:"https://portal.azure.com/#create/Microsoft.AzureBot",target:"_blank",rel:"noreferrer",children:["Create Azure Bot ",(0,e.jsx)(Q,{})]})}),(0,e.jsx)(p,{asChild:!0,variant:"secondary",children:(0,e.jsxs)("a",{href:"https://dev.teams.microsoft.com/apps",target:"_blank",rel:"noreferrer",children:["Open Teams Developer Portal ",(0,e.jsx)(Q,{})]})})]}),J("Wardmote messaging endpoint",i.setup?.messagingEndpoint),s("clientId","Application / Client ID","text"),s("tenantId","Directory / Tenant ID","text"),s("clientSecret","Client secret value"),(0,e.jsxs)("section",{className:"space-y-3 rounded-lg border border-line p-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"text-sm font-semibold",children:"Microsoft portal field map"}),(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:"Use these exact portal sections and reuse the same Application ID in all three places."})]}),(0,e.jsxs)("ol",{className:"list-decimal space-y-3 pl-5 text-sm",children:[(0,e.jsxs)("li",{children:[(0,e.jsx)("strong",{children:"Microsoft Entra admin center · App registrations"}),": select ",(0,e.jsx)("strong",{children:"New registration"}),", choose"," ",(0,e.jsx)("strong",{children:"Accounts in this organizational directory only (Single tenant)"}),", then select ",(0,e.jsx)("strong",{children:"Register"}),". Copy"," ",(0,e.jsx)("strong",{children:"Application (client) ID"})," and"," ",(0,e.jsx)("strong",{children:"Directory (tenant) ID"}),". Under"," ",(0,e.jsx)("strong",{children:"Certificates & secrets · Client secrets"}),", select ",(0,e.jsx)("strong",{children:"New client secret"})," and copy its"," ",(0,e.jsx)("strong",{children:"Value"}),", not its Secret ID."]}),(0,e.jsxs)("li",{children:[(0,e.jsx)("strong",{children:"Azure · Create Azure Bot"}),": set"," ",(0,e.jsx)("strong",{children:"Microsoft App ID"})," to"," ",(0,e.jsx)("strong",{children:"Single Tenant"}),", set ",(0,e.jsx)("strong",{children:"Creation type"})," ","to ",(0,e.jsx)("strong",{children:"Use existing app registration"}),", and enter the Application ID and Tenant ID above. After creation, open"," ",(0,e.jsx)("strong",{children:"Settings · Configuration"})," and paste the Wardmote"," ",(0,e.jsx)("strong",{children:"Messaging endpoint"}),"; then open"," ",(0,e.jsx)("strong",{children:"Settings · Channels"})," and enable"," ",(0,e.jsx)("strong",{children:"Microsoft Teams"}),"."]}),(0,e.jsxs)("li",{children:[(0,e.jsx)("strong",{children:"Teams Developer Portal · Apps"}),": select"," ",(0,e.jsx)("strong",{children:"New app"}),". Under"," ",(0,e.jsx)("strong",{children:"Configure · App features · Bot"}),", add an existing bot using the same Application ID; enable"," ",(0,e.jsx)("strong",{children:"Personal"}),", ",(0,e.jsx)("strong",{children:"Team"}),", and"," ",(0,e.jsx)("strong",{children:"Group chat"})," scopes plus file support. Under"," ",(0,e.jsx)("strong",{children:"Configure · Permissions"}),", add the two RSC"," ",(0,e.jsx)("strong",{children:"Application"})," permissions shown below. Complete the required app details and icons, explain that the app can receive every message in an installed team or group chat, then download the app package."]}),(0,e.jsxs)("li",{children:[(0,e.jsx)("strong",{children:"Microsoft Teams · Apps · Manage your apps"}),": select"," ",(0,e.jsx)("strong",{children:"Upload an app · Upload a custom app"}),", choose the downloaded package, and install it in each intended personal chat, group chat, or team. One team install covers its standard channels. Private and shared channels require a separate app installation and are not supported by this release. If upload is unavailable, a Teams administrator must enable or approve custom apps."]})]})]}),(0,e.jsxs)("label",{className:"grid gap-2 text-sm font-medium",children:["Required Teams app manifest block",(0,e.jsx)(Te,{className:"min-h-80 font-mono text-xs",readOnly:!0,value:R})]}),(0,e.jsx)("div",{className:"flex flex-wrap gap-2",children:(0,e.jsx)(p,{variant:"secondary",disabled:!g.clientId?.trim(),onClick:t(()=>{Ie(R).then(()=>X(!0),O)},"onClick"),children:f?"Manifest settings copied":"Copy manifest settings"})}),(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Enter the Application / Client ID above before copying so the block contains the real bot identity. This block contains the Wardmote-specific fields to verify in Developer Portal or merge into a complete Teams app manifest. It is not a complete app package; Developer Portal supplies the remaining required metadata and packages the manifest with your app icons."}),(0,e.jsxs)("p",{className:"text-sm text-ink-3",children:["Wardmote does not use Teams single sign-on in this release. The copied ",(0,e.jsx)("code",{children:"webApplicationInfo"})," entry only associates the RSC permissions with the same Entra Application ID. Its nonempty resource is an RSC placeholder; you do not need to register an Entra Application ID URI or add delegated Microsoft Graph permissions."]}),(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"The two application RSC permissions let the bot receive every message, without an @mention, in each team or group chat where it is installed. Wardmote retains and acts only on messages admitted by your Wardmote reach and access rules. Make this provider access clear in the app description shown to installers."}),(0,e.jsxs)("p",{className:"text-sm text-ink-3",children:["This release supports personal chats, group chats, and standard team channels—not private channels. ",(0,e.jsx)("code",{children:"supportsFiles: true"})," ","enables native file receipt and consent-based sending in personal chats; channel and group-chat files need a separate Microsoft Graph connection and are not ingested here."]}),!i.setup?.messagingEndpoint&&(0,e.jsx)("p",{className:"text-sm text-bad",children:"Configure a public HTTPS URL for this Wardmote instance before connecting Microsoft Teams."}),(0,e.jsxs)(p,{disabled:!h&&(!g.clientId||!g.tenantId||!g.clientSecret)||!i.setup?.messagingEndpoint||l,onClick:t(()=>T(h?"reconnect":"configure",g),"onClick"),children:[l&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),h?"Reconnect Microsoft app":"Verify Microsoft credentials"]})]});if(a==="github")return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:h?"Reconnect GitHub App":"Create or connect a GitHub App"}),(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:h?"Reconnect verifies this same App and installation, then updates its webhook URL, secret, and secure delivery settings. It does not reinstall the App or change repository access. Leave App ID and private key blank to reuse saved credentials. Keep Webhooks · Active enabled in GitHub; send a test conversation after reconnecting.":"Configure its webhook and permissions, then verify the App with Wardmote."})]}),!h&&(0,e.jsxs)("ol",{className:"list-decimal space-y-2 pl-5 text-sm",children:[(0,e.jsx)("li",{children:"Under the target user or organization, create a new GitHub App. Give it a globally unique name (34 characters or fewer), use the Wardmote homepage URL below, and leave user authorization off."}),(0,e.jsxs)("li",{children:["Keep ",(0,e.jsx)("strong",{children:"Webhooks · Active"})," on. Enter the Wardmote webhook URL and the Wardmote-generated webhook secret below, and keep ",(0,e.jsx)("strong",{children:"Enable SSL verification"})," selected."]}),(0,e.jsxs)("li",{children:["Under Repository permissions, set ",(0,e.jsx)("strong",{children:"Issues"})," and"," ",(0,e.jsx)("strong",{children:"Pull requests"})," to"," ",(0,e.jsx)("strong",{children:"Read & write"}),". Leave every other permission at its default; Metadata remains read-only."]}),(0,e.jsxs)("li",{children:["Subscribe to ",(0,e.jsx)("strong",{children:"Issue comment"})," (",(0,e.jsx)("code",{children:"issue_comment"}),"),"," ",(0,e.jsx)("strong",{children:"Pull request review comment"})," (",(0,e.jsx)("code",{children:"pull_request_review_comment"}),"). GitHub sends"," ",(0,e.jsx)("code",{children:"installation"})," and"," ",(0,e.jsx)("code",{children:"installation_repositories"})," to every GitHub App automatically; they are not selectable here."]}),(0,e.jsxs)("li",{children:["Choose ",(0,e.jsx)("strong",{children:"Only on this account"}),", create the App, copy its App ID, generate one private key, then install it on the selected repositories."]})]}),J("Wardmote homepage URL",Yt(i.setup?.webhookUrl)),J("Wardmote webhook URL",i.setup?.webhookUrl),(0,e.jsxs)(p,{variant:"secondary",onClick:t(()=>window.open(h?"https://github.com/settings/apps":i.setup?.authorizationUrl??"https://github.com/settings/apps/new","_blank","noopener,noreferrer"),"onClick"),children:[h?"Open GitHub App settings":"Open new GitHub App form"," ",(0,e.jsx)(Q,{})]}),s("appId","GitHub App ID","text"),(0,e.jsxs)("div",{className:"grid gap-2 text-sm font-medium",children:[(0,e.jsx)("label",{htmlFor:"github-private-key",children:"Private key (PEM)"}),(0,e.jsxs)("div",{className:"relative",children:[B?(0,e.jsx)(Te,{id:"github-private-key",className:"min-h-24 pr-11 font-mono text-xs",value:g.privateKey??"",onChange:t(n=>he(n.target.value),"onChange")}):(0,e.jsx)(ie,{id:"github-private-key",type:"password",className:"pr-11 font-mono text-xs",value:g.privateKey??"",onChange:t(n=>he(n.target.value),"onChange"),onPaste:t(n=>{n.preventDefault(),he(n.clipboardData.getData("text"))},"onPaste")}),(0,e.jsx)(p,{type:"button",variant:"ghost",size:"icon",className:"absolute right-1 top-1","aria-label":B?"Hide private key":"Show private key",onClick:t(()=>F(n=>!n),"onClick"),children:B?(0,e.jsx)(rt,{}):(0,e.jsx)(ot,{})})]}),(0,e.jsx)("input",{ref:m,type:"file",accept:".pem,.key,application/x-pem-file,application/pkcs8,text/plain",className:"hidden","aria-label":"Choose GitHub App private key file",onChange:le}),(0,e.jsx)("div",{children:(0,e.jsx)(p,{type:"button",variant:"secondary",onClick:t(()=>m.current?.click(),"onClick"),children:"Choose .pem file"})}),x?(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:x}):null,w?(0,e.jsx)("p",{role:"status","aria-live":"polite",className:"text-sm text-ink-3",children:"Reading private key file…"}):$?(0,e.jsx)("p",{role:"status","aria-live":"polite",className:"text-sm text-ink-3",children:"Private key loaded. It stays in this form until you connect."}):null]}),(0,e.jsxs)("div",{className:"grid gap-2",children:[(0,e.jsx)("p",{className:"text-sm font-medium",children:"Webhook secret"}),S?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(ie,{"aria-label":"Generated webhook secret",className:"font-mono text-xs",readOnly:!0,value:S}),(0,e.jsx)("div",{className:"flex flex-wrap gap-2",children:(0,e.jsx)(p,{type:"button",variant:"secondary",onClick:t(()=>{L.copy(S).then(n=>{n==="failed"&&O()})},"onClick"),children:L.copied?"Webhook secret copied":L.failed?"Couldn’t copy — select it manually":"Copy webhook secret"})}),(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Copy this value now. Wardmote will not show it again."})]}):(0,e.jsx)("p",{className:"text-sm text-ink-3",children:i.setup?.webhookSecretConfigured?"A webhook secret is configured and cannot be shown again.":"Generate the secret in Wardmote, then paste it into the GitHub App."}),(0,e.jsx)("div",{children:(0,e.jsxs)(p,{type:"button",variant:"secondary",disabled:G,onClick:te,children:[G&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),i.setup?.webhookSecretConfigured?"Regenerate webhook secret":"Generate webhook secret"]})}),i.setup?.webhookSecretConfigured&&(0,e.jsx)("p",{className:"text-sm text-ink-3",children:i.providerAccountId||i.botExternalId?"Regenerating immediately invalidates GitHub webhook signatures until you replace the secret in the GitHub App settings.":"Generating another secret replaces the previous value. Paste the newest value into GitHub before continuing."}),i.setup?.webhookSecretConfigured&&(0,e.jsx)("p",{className:`text-sm ${i.setup.webhookVerifiedAt?"text-ink":"text-ink-3"}`,children:i.setup.webhookVerifiedAt?"GitHub has verified this webhook.":"Waiting for GitHub to deliver its signed webhook ping…"})]}),(!i.setup?.webhookUrl||E&&!i.setup?.slackOAuthCallbackUri?.startsWith("https://"))&&(0,e.jsx)("p",{className:"text-sm text-bad",children:"Configure a public HTTPS URL for this Wardmote instance before connecting GitHub."}),(0,e.jsxs)(p,{disabled:!h&&(!g.appId||!g.privateKey)||!i.setup?.webhookSecretConfigured||!i.setup?.webhookVerifiedAt||!i.setup?.webhookUrl||w||G||l,onClick:t(()=>T(h?"reconnect":"configure",g),"onClick"),children:[l&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),h?"Reconnect and verify":"Connect and verify"]})]});const we=(0,e.jsxs)("ol",{className:"list-decimal space-y-2 pl-5 text-sm",children:[(0,e.jsxs)("li",{children:[(0,e.jsxs)("a",{className:"underline underline-offset-4",href:i.setup?.slackRegistration?.appId?`https://api.slack.com/apps/${encodeURIComponent(i.setup.slackRegistration.appId)}/event-subscriptions`:"https://api.slack.com/apps",target:"_blank",rel:"noopener noreferrer",children:["Open Slack app Settings ",(0,e.jsx)(Q,{className:"inline size-3"})]})," and choose ",(0,e.jsx)("strong",{children:pe.appName}),"."]}),(0,e.jsxs)("li",{children:["Choose ",(0,e.jsx)("strong",{children:"Event Subscriptions"}),"."]}),(0,e.jsxs)("li",{children:["Beside the prefilled ",(0,e.jsx)("strong",{children:"Request URL"}),", click ",(0,e.jsx)("strong",{children:"Retry"})," if it isn't verified. Save changes if Slack asks."]})]});return r==="finish"?(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:E?"Send a message to your agent":"Verify Slack connection"}),!E&&(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:"Slack needs to confirm that it can reach your Wardmote instance."})]}),E?(0,e.jsx)(p,{asChild:!0,variant:"secondary",children:(0,e.jsxs)("a",{href:i.setup?.slackAccount?.dmChannelId&&i.providerAccountId?`https://app.slack.com/client/${encodeURIComponent(i.providerAccountId)}/${encodeURIComponent(i.setup.slackAccount.dmChannelId)}`:i.setup?.providerUrl??"https://app.slack.com",target:"_blank",rel:"noopener noreferrer",children:["Open Slack ",(0,e.jsx)(Q,{className:"size-4"})]})}):we,i.setup?.webhookVerifiedAt?(0,e.jsxs)("p",{role:"status",className:"flex items-center gap-2 text-sm",children:[(0,e.jsx)(Re,{className:"size-4 text-(--status-task-done)"}),"Your Slack connection is working.",l?E?" Finishing setup…":" Opening the message test…":""]}):U?(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Couldn't check verification. We'll keep trying; check your connection if this continues."}):(0,e.jsxs)("p",{role:"status",className:"flex items-center gap-2 text-sm text-ink-3",children:[(0,e.jsx)(Y,{className:"size-4 animate-spin"})," ",E?"Waiting for your message…":"Waiting for Slack. We’ll continue automatically."]}),(0,e.jsxs)(Me,{label:E?"Didn’t work?":"Troubleshooting",children:[E&&we,(0,e.jsx)("p",{className:"text-ink-3",children:"If the Request URL is missing or different, paste this URL into Event Subscriptions. If verification fails, check that your public HTTPS server is reachable and your Signing Secret is correct."}),J("Wardmote webhook URL",i.setup?.webhookUrl)]}),(0,e.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,e.jsx)(p,{variant:"ghost",onClick:t(()=>j("/apps"),"onClick"),children:"Save & exit"}),(!E||i.setup?.webhookVerifiedAt)&&(0,e.jsxs)(p,{disabled:l||!i.setup?.webhookVerifiedAt,onClick:t(()=>i.setup?.step==="provider_setup"?T("verify"):d(),"onClick"),children:[l&&(0,e.jsx)(Y,{className:"size-4 animate-spin"}),"Continue"]})]})]}):(0,e.jsxs)("div",{className:"space-y-5",children:[(!i.setup?.webhookUrl||E&&!i.setup?.slackOAuthCallbackUri?.startsWith("https://"))&&(0,e.jsxs)("div",{role:"alert",className:"flex items-start gap-3 rounded-lg border border-bad/30 bg-bad/10 p-4",children:[(0,e.jsx)(ze,{className:"size-5 shrink-0 text-bad"}),(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsx)("p",{className:"text-sm font-semibold",children:"Public HTTPS URL required"}),(0,e.jsx)("p",{className:"text-sm",children:"Slack needs a public HTTPS URL to send messages to Wardmote. Configure one for this instance before creating or connecting your Slack app."}),(0,e.jsx)("a",{href:"https://github.com/tickernelz/wardmote/blob/main/docs/deploy/deployment-modes.md",target:"_blank",rel:"noopener noreferrer",className:"text-sm underline underline-offset-4",children:"Learn how to set up HTTPS"})]})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-xl font-bold",children:r==="app"?E?"App configuration access token":"Create a Slack app":E?"Install Slack app":"Add Slack credentials"}),h&&!E&&(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:"Reconnect verifies or replaces credentials for this same Slack app. It does not reinstall the app or change its workspace or channel membership. Leave credentials blank to reuse the saved values."})]}),(0,e.jsxs)("div",{hidden:r!=="app"||E,className:"space-y-5",children:[(0,e.jsx)("div",{className:"space-y-3 text-sm",children:(0,e.jsx)("div",{className:"flex justify-end",children:(0,e.jsxs)(jt,{children:[(0,e.jsx)(gt,{asChild:!0,children:(0,e.jsx)(p,{variant:"link",className:"h-auto p-0 text-xs underline underline-offset-4",children:"View Slack App Manifest"})}),(0,e.jsxs)(bt,{className:"sm:max-w-2xl",children:[(0,e.jsxs)(xt,{children:[(0,e.jsx)(yt,{children:"Slack app manifest"}),(0,e.jsx)(kt,{children:"Generated from your app name, bot name, and slash command. Edit those fields to update the manifest."})]}),(0,e.jsx)(Te,{"aria-label":"Slack app manifest",className:"h-80 font-mono text-xs",readOnly:!0,value:ue}),(0,e.jsx)(ft,{children:(0,e.jsx)(p,{variant:"secondary",disabled:!me.success,onClick:t(()=>{Ie(ue).then(()=>X(!0),O)},"onClick"),children:f?"Manifest copied":"Copy manifest"})})]})]})})}),!E&&(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 pt-3",children:[(0,e.jsx)(p,{variant:"ghost",onClick:t(()=>{xe()},"onClick"),children:"Save & exit"}),(0,e.jsxs)("div",{className:"ml-auto flex flex-wrap items-center justify-end gap-2",children:[(0,e.jsx)(p,{variant:"secondary",disabled:Z||!i.setup?.webhookUrl||!me.success,onClick:A,children:"I already created the app"}),!h&&(0,e.jsxs)(p,{disabled:Z||!i.setup?.webhookUrl||!me.success,onClick:t(()=>{window.open(se,"_blank","noopener,noreferrer"),v(!0),re.current=setTimeout(()=>{re.current=null,v(!1),A()},1e3)},"onClick"),children:["Create Slack app ",(0,e.jsx)(Q,{})]})]})]})]}),E&&(0,e.jsx)(Lt,{endpoint:i,stage:r,disabled:!i.setup?.webhookUrl||!i.setup?.slackOAuthCallbackUri?.startsWith("https://")||!me.success,saveDetails:t(async()=>{},"saveDetails"),onBusy:q,onSaved:C,onContinue:A,onManual:t(async n=>{C(await W.update(i.id,{slackSetupMethod:n?"existing":"manual"})),n&&A()},"onManual"),onSaveExit:t(()=>{xe()},"onSaveExit")},i.id),!E&&(0,e.jsxs)("div",{hidden:r!=="credentials",className:"space-y-5",children:[(0,e.jsx)("p",{className:"text-sm",children:"Now you need to find two secrets. They are in two different screens on Slack."}),M&&!h&&(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Your credentials are saved. Leave the fields blank to keep them, or enter replacements."}),(0,e.jsxs)("section",{className:"space-y-3",children:[(0,e.jsx)("h2",{className:"text-sm font-semibold",children:(0,e.jsx)("label",{htmlFor:"slack-bot-token",children:"Bot User OAuth Token"})}),(0,e.jsxs)("ul",{id:"slack-bot-token-help",className:"list-disc space-y-1 pl-5 text-sm",children:[(0,e.jsxs)("li",{children:[(0,e.jsxs)("a",{href:"https://api.slack.com/apps",target:"_blank",rel:"noopener noreferrer",className:"underline underline-offset-4",children:["Open Slack app Settings ",(0,e.jsx)(Q,{className:"inline size-3"})]})," and choose ",(0,e.jsx)("strong",{children:pe.appName}),"."]}),(0,e.jsxs)("li",{children:["Choose ",(0,e.jsx)("strong",{children:"OAuth & Permissions"})]}),(0,e.jsxs)("li",{children:["Copy and paste your ",(0,e.jsx)("strong",{children:"Bot OAuth Token"})]})]}),(0,e.jsx)(ie,{id:"slack-bot-token",type:"password",placeholder:M?"Saved — leave blank to keep":void 0,value:g.botToken??"","aria-invalid":P||void 0,"aria-describedby":`slack-bot-token-help${P?" slack-bot-token-warning":""}`,onChange:t(n=>y({...g,botToken:n.target.value}),"onChange")}),P&&(0,e.jsxs)("p",{id:"slack-bot-token-warning",role:"alert",className:"text-sm text-bad",children:["Your Bot User OAuth Token must start with ",(0,e.jsx)("code",{children:"xoxb-"}),". Copy it from ",(0,e.jsx)("strong",{children:"OAuth & Permissions"}),"."]})]}),(0,e.jsxs)("section",{className:"space-y-3",children:[(0,e.jsx)("h2",{className:"text-sm font-semibold",children:(0,e.jsx)("label",{htmlFor:"slack-signing-secret",children:"Signing Secret"})}),(0,e.jsxs)("ul",{id:"slack-signing-secret-help",className:"list-disc space-y-1 pl-5 text-sm",children:[(0,e.jsxs)("li",{children:[(0,e.jsxs)("a",{href:"https://api.slack.com/apps",target:"_blank",rel:"noopener noreferrer",className:"underline underline-offset-4",children:["Open Slack app Settings ",(0,e.jsx)(Q,{className:"inline size-3"})]})," and choose ",(0,e.jsx)("strong",{children:pe.appName}),"."]}),(0,e.jsxs)("li",{children:["Choose ",(0,e.jsx)("strong",{children:"Basic Information"})]}),(0,e.jsxs)("li",{children:["Copy and paste your ",(0,e.jsx)("strong",{children:"Signing Secret"})]})]}),(0,e.jsx)(ie,{id:"slack-signing-secret",type:"password",placeholder:M?"Saved — leave blank to keep":void 0,value:g.signingSecret??"","aria-invalid":_||void 0,"aria-describedby":`slack-signing-secret-help${_?" slack-signing-secret-warning":""}`,onChange:t(n=>y({...g,signingSecret:n.target.value}),"onChange")}),_&&(0,e.jsxs)("p",{id:"slack-signing-secret-warning",role:"alert",className:"text-sm text-bad",children:["Use the ",(0,e.jsx)("strong",{children:"Signing Secret"}),", NOT an app or bot token. The Signing Secret has no token prefix."]})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,e.jsx)(p,{variant:"ghost",onClick:t(()=>j("/apps"),"onClick"),children:"Save & exit"}),(0,e.jsxs)(p,{className:"ml-auto",disabled:!h&&!M&&(!k||!g.signingSecret?.trim())||!i.setup?.webhookUrl||!me.success||l||_||P,onClick:t(()=>K?u():T(h||M?"reconnect":"configure",g),"onClick"),children:[l&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),K?"Continue":h||M?"Reconnect Slack app":"Connect Slack app"]})]})]})]})}t(es,"ProviderConnectStep");function ts({endpointId:a,provider:r,agentName:u,botLabel:d,botUsername:U,botExternalId:A,slackAccount:b,photonAllocation:i,providerUrl:g,guestIsolationState:y,pending:h,onOpenAccess:l,onTest:q,onSaveExit:C}){const[S,G]=(0,c.useState)(!1),[te,T]=(0,c.useState)(!1),z=ce({queryKey:ge.chatEndpoints.principals(a),queryFn:t(()=>W.listPrincipals(a),"queryFn"),enabled:r!=="slack",refetchInterval:1500}),[j,k]=(0,c.useState)(!1),[P,_]=(0,c.useState)(null),M=z.data??[],K=M.filter(v=>v.status!=="linked"),O=r==="imessage-photon"?"send a fresh message to your Photon number":r==="openwa"?"send a fresh WhatsApp message to the connected number":r==="telegram"?"start a fresh conversation with /new and send the test message again":r==="github"?"start a new issue or pull request conversation and mention the agent again":r==="microsoft-teams"?"start a new channel post and mention the agent again":"send a new root mention to the agent",s=r==="slack"||r==="openwa"?null:r==="imessage-photon"&&z.isSuccess&&(M.length===0||K.length>0)?{tone:"info",title:"Link your Messages identity",body:"Send one message to discover your phone number or Apple account address, then link that exact identity in Access. Send a fresh request after linking; earlier messages do not start work."}:z.isError?{tone:"warning",title:"Identity readiness could not be checked",body:`Review Access before expecting an agent reply. After linking the account you are testing, ${O}.`}:!z.isSuccess||y==="loading"?null:M.length===0?y==="disabled"?{tone:"warning",title:"Link the account you’re testing",body:r==="telegram"?"Tap Start in Telegram to discover your account; the welcome does not start an agent run. Link the account privately in Access, then return and send the test message.":`Your first ${Ne[r]} message discovers the external account, but isolated guest work is off, so it cannot safely start ${u}. Send it once, link that account privately in Access, then ${O}.`}:{tone:"info",title:"Your first message identifies your account",body:r==="telegram"?"Tap Start in Telegram to discover your account. Until linked, it is a restricted guest and still needs a sandbox-backed isolated run; test that path intentionally, or link it in Access and then send the test message.":`Until linked, the account is a restricted guest and still needs a sandbox-backed isolated run. Test that guest path intentionally, or link the account in Access and then ${O}.`}:K.length>0?y==="disabled"?{tone:"warning",title:"Link the account you’re testing",body:`An observed external account is unlinked, and isolated guest work is off, so it cannot safely start ${u}. Link the account in Access, then ${O}; Wardmote does not replay the refused request.`}:{tone:"info",title:"Unlinked identity detected",body:`An unlinked account is a restricted guest and still needs a sandbox-backed isolated run. Test guest access intentionally, or link the account in Access and then ${O}.`}:null,N=U?.replace(/^@/,""),J=r==="github"?N?.replace(/\[bot\]$/i,""):N,f=J?`@${J}`:d??u,X=b?.status==="linked"?"you there?":`${f.startsWith("@")?f:`@${f}`} you there?`,L=A?Je(A):"the connected number",Z=r==="openwa"?["Owners are linked in Settings. Only an owner's message completes this test.",`Send a WhatsApp message from an owner's phone to ${L}.`,"Wait for the agent’s actual reply. Setup completes after that reply is delivered."]:r==="imessage-photon"?[i==="shared"?"In your Photon project, enroll your sender in Users and find its assigned number in Get started. Send a fresh message to that number from Apple Messages.":`Open Apple Messages and send a fresh message to ${U??d??"the dedicated number"}.`,"Link the discovered sender to a Wardmote person in Access, then send a fresh request.","Wait for the agent’s actual reply. Setup completes after that reply is delivered.",...i==="shared"?["This Pro-compatible channel supports DMs only. Group messages cannot start work."]:["For a group: add the number in Messages, send a message, enable the discovered group in Settings, then send a fresh request."]]:r==="discord"?["Open a text channel where the bot is installed.",`Mention ${f} in a new root message.`,`Reply once inside ${u}'s new Discord thread.`]:r==="telegram"?["Open the bot's private chat.","Tap Start.","Send “Help me test this”."]:r==="github"?["Open an installed issue or pull request.",`Mention ${f} in a comment.`,"Add another comment to continue the same task."]:r==="microsoft-teams"?["Open an installed channel and start a new post.",`Mention ${f} in the post.`,"Reply once beneath the post."]:[`Open a channel and invite ${f} if needed.`,`Mention ${f} in a new channel message.`,`Reply once in ${u}'s thread.`];return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("h1",{className:"text-xl font-bold",children:["Try ",u," in ",Ne[r]]}),r!=="slack"&&(0,e.jsx)("p",{className:"mt-1 text-sm text-ink-3",children:"Complete this real conversation to finish setup."})]}),r!=="slack"&&(!z.isSuccess||y==="loading")&&!z.isError?(0,e.jsx)("p",{role:"status",className:"text-sm text-ink-3",children:"Checking identity and guest readiness…"}):null,s?(0,e.jsxs)("div",{role:s.tone==="warning"?"alert":"status",className:s.tone==="warning"?"rounded-lg border border-bad/30 bg-bad/10 p-4 text-sm":"rounded-lg border border-line bg-bg-3/30 p-4 text-sm",children:[(0,e.jsx)("h2",{className:"font-medium",children:s.title}),(0,e.jsx)("p",{className:"mt-1 text-ink-3",children:s.body}),(0,e.jsx)(p,{className:"mt-3",size:"sm",variant:"secondary",onClick:l,children:"Review identity access"})]}):null,r==="imessage-photon"&&U&&(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)(p,{variant:"secondary",onClick:t(()=>{Ie(U).then(()=>{k(!0),_(null)},()=>_("Could not copy the number. Select it in the instructions below."))},"onClick"),children:j?"Number copied":`Copy ${U}`}),P&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:P})]}),r==="slack"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("ol",{className:"list-decimal space-y-4 pl-5 text-sm",children:[(0,e.jsx)("li",{children:b?.status==="linked"?(0,e.jsx)(p,{asChild:!0,variant:"secondary",children:(0,e.jsxs)("a",{href:g??"https://app.slack.com",target:"_blank",rel:"noopener noreferrer",children:[b.dmChannelId?"Open your Slack DM":"Open Slack",(0,e.jsx)(Q,{})]})}):(0,e.jsxs)(e.Fragment,{children:["Open a channel and invite ",f," if needed."]})}),(0,e.jsxs)("li",{children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border border-line p-3",children:[(0,e.jsx)("code",{children:X}),(0,e.jsxs)(p,{size:"sm",variant:"ghost",onClick:t(()=>{Ie(X).then(()=>{G(!0),T(!1)},()=>T(!0))},"onClick"),children:[(0,e.jsx)(qe,{className:"size-4"}),S?"Copied":"Copy message"]})]}),b?.status!=="linked"&&(0,e.jsx)("p",{className:"mt-2 text-ink-3",children:"Select the bot from Slack’s @mention suggestions."})]}),(0,e.jsx)("li",{children:"Continue the conversation in the thread."})]}),te&&(0,e.jsx)("p",{role:"alert",className:"text-sm text-bad",children:"Couldn't copy. Select and copy the command above."}),(0,e.jsx)(Ae,{onSaveExit:C,disabled:h,children:(0,e.jsxs)(p,{disabled:h,onClick:q,children:[h&&(0,e.jsx)(Y,{className:"size-4 animate-spin"}),"Done"]})})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("ol",{className:"list-decimal space-y-2 pl-5 text-sm",children:Z.map(v=>(0,e.jsx)("li",{children:v},v))}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[g&&(0,e.jsx)(p,{asChild:!0,variant:"secondary",children:(0,e.jsxs)("a",{href:g,target:"_blank",rel:"noopener noreferrer",children:["Open ",Ne[r]," ",(0,e.jsx)(Q,{})]})}),(0,e.jsxs)(p,{disabled:h,onClick:q,children:[h&&(0,e.jsx)(Y,{className:"h-4 w-4 animate-spin"}),"I've sent the test message"]})]})]})]})}t(ts,"TryStep");export{Os as ChatEndpointSetup};