botmancers 0.9.3 → 0.10.1

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 (204) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +5 -5
  3. package/app/.next/BUILD_ID +1 -1
  4. package/app/.next/app-path-routes-manifest.json +1 -0
  5. package/app/.next/build-manifest.json +3 -3
  6. package/app/.next/prerender-manifest.json +3 -3
  7. package/app/.next/required-server-files.json +2 -2
  8. package/app/.next/routes-manifest.json +6 -0
  9. package/app/.next/server/app/_global-error.html +1 -1
  10. package/app/.next/server/app/_global-error.rsc +1 -1
  11. package/app/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  12. package/app/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  13. package/app/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  14. package/app/.next/server/app/_not-found/page.js.nft.json +1 -1
  15. package/app/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  16. package/app/.next/server/app/_not-found.html +1 -1
  17. package/app/.next/server/app/_not-found.rsc +2 -2
  18. package/app/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  19. package/app/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
  20. package/app/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  21. package/app/.next/server/app/agents/[id]/activity/page.js.nft.json +1 -1
  22. package/app/.next/server/app/agents/[id]/activity/page_client-reference-manifest.js +1 -1
  23. package/app/.next/server/app/agents/[id]/config/page.js.nft.json +1 -1
  24. package/app/.next/server/app/agents/[id]/config/page_client-reference-manifest.js +1 -1
  25. package/app/.next/server/app/agents/[id]/conversations/[conversationId]/page.js.nft.json +1 -1
  26. package/app/.next/server/app/agents/[id]/conversations/[conversationId]/page_client-reference-manifest.js +1 -1
  27. package/app/.next/server/app/agents/[id]/conversations/page.js.nft.json +1 -1
  28. package/app/.next/server/app/agents/[id]/conversations/page_client-reference-manifest.js +1 -1
  29. package/app/.next/server/app/agents/[id]/page.js.nft.json +1 -1
  30. package/app/.next/server/app/agents/[id]/page_client-reference-manifest.js +1 -1
  31. package/app/.next/server/app/agents/[id]/sessions/page.js.nft.json +1 -1
  32. package/app/.next/server/app/agents/[id]/sessions/page_client-reference-manifest.js +1 -1
  33. package/app/.next/server/app/agents/[id]/slack/page.js.nft.json +1 -1
  34. package/app/.next/server/app/agents/[id]/slack/page_client-reference-manifest.js +1 -1
  35. package/app/.next/server/app/api/bots/[id]/activity/route.js.nft.json +1 -1
  36. package/app/.next/server/app/api/bots/[id]/config/route.js.nft.json +1 -1
  37. package/app/.next/server/app/api/bots/[id]/conversations/[conversationId]/route.js.nft.json +1 -1
  38. package/app/.next/server/app/api/bots/[id]/conversations/route.js.nft.json +1 -1
  39. package/app/.next/server/app/api/bots/[id]/overview/route.js.nft.json +1 -1
  40. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/pins/route.js.nft.json +1 -1
  41. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/route.js.nft.json +1 -1
  42. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/shares/route.js.nft.json +1 -1
  43. package/app/.next/server/app/api/bots/[id]/sessions/route.js.nft.json +1 -1
  44. package/app/.next/server/app/api/bots/[id]/sessions/sync/route.js.nft.json +1 -1
  45. package/app/.next/server/app/api/bots/[id]/share-policy/route.js.nft.json +1 -1
  46. package/app/.next/server/app/api/bots/[id]/skill/route.js.nft.json +1 -1
  47. package/app/.next/server/app/api/bots/availability/route.js.nft.json +1 -1
  48. package/app/.next/server/app/api/bots/delete-preview/route.js.nft.json +1 -1
  49. package/app/.next/server/app/api/bots/import/route.js.nft.json +1 -1
  50. package/app/.next/server/app/api/bots/manage/route.js.nft.json +1 -1
  51. package/app/.next/server/app/api/bots/name-migrations/route.js.nft.json +1 -1
  52. package/app/.next/server/app/api/bots/route.js.nft.json +1 -1
  53. package/app/.next/server/app/api/conversations/[id]/approve/route.js.nft.json +1 -1
  54. package/app/.next/server/app/api/conversations/[id]/deny/route.js.nft.json +1 -1
  55. package/app/.next/server/app/api/conversations/[id]/draft/route.js.nft.json +1 -1
  56. package/app/.next/server/app/api/conversations/[id]/messages/[messageId]/stop/route.js.nft.json +1 -1
  57. package/app/.next/server/app/api/conversations/[id]/messages/route.js.nft.json +1 -1
  58. package/app/.next/server/app/api/conversations/[id]/route.js.nft.json +1 -1
  59. package/app/.next/server/app/api/conversations/[id]/stop/route.js.nft.json +1 -1
  60. package/app/.next/server/app/api/conversations/route.js.nft.json +1 -1
  61. package/app/.next/server/app/api/exchanges/[id]/cancel/route.js.nft.json +1 -1
  62. package/app/.next/server/app/api/exchanges/[id]/route.js.nft.json +1 -1
  63. package/app/.next/server/app/api/exchanges/route.js.nft.json +1 -1
  64. package/app/.next/server/app/api/files/[name]/route.js.nft.json +1 -1
  65. package/app/.next/server/app/api/groups/route.js.nft.json +1 -1
  66. package/app/.next/server/app/api/health/route.js.nft.json +1 -1
  67. package/app/.next/server/app/api/mcp/route.js.nft.json +1 -1
  68. package/app/.next/server/app/api/messages/[id]/between/route.js.nft.json +1 -1
  69. package/app/.next/server/app/api/runtime-capacity/route/app-paths-manifest.json +3 -0
  70. package/app/.next/server/app/api/runtime-capacity/route/build-manifest.json +12 -0
  71. package/app/.next/server/app/api/runtime-capacity/route/server-reference-manifest.json +4 -0
  72. package/app/.next/server/app/api/runtime-capacity/route.js +10 -0
  73. package/app/.next/server/app/api/runtime-capacity/route.js.nft.json +1 -0
  74. package/app/.next/server/app/api/runtime-capacity/route_client-reference-manifest.js +3 -0
  75. package/app/.next/server/app/api/runtime-connections/route.js.nft.json +1 -1
  76. package/app/.next/server/app/api/service-grants/route.js.nft.json +1 -1
  77. package/app/.next/server/app/api/shares/[shareRef]/revoke/route.js.nft.json +1 -1
  78. package/app/.next/server/app/api/shares/route.js.nft.json +1 -1
  79. package/app/.next/server/app/api/v0/agents/[agentId]/conversations/[conversationId]/route.js.nft.json +1 -1
  80. package/app/.next/server/app/api/v0/agents/[agentId]/conversations/route.js.nft.json +1 -1
  81. package/app/.next/server/app/api/v0/agents/[agentId]/messages/route.js.nft.json +1 -1
  82. package/app/.next/server/app/api/v0/agents/[agentId]/pins/route.js.nft.json +1 -1
  83. package/app/.next/server/app/api/v0/agents/[agentId]/route.js.nft.json +1 -1
  84. package/app/.next/server/app/api/v0/agents/[agentId]/sessions/[ref]/route.js.nft.json +1 -1
  85. package/app/.next/server/app/api/v0/agents/[agentId]/sessions/route.js.nft.json +1 -1
  86. package/app/.next/server/app/api/v0/agents/route.js.nft.json +1 -1
  87. package/app/.next/server/app/api/v0/capabilities/route.js.nft.json +1 -1
  88. package/app/.next/server/app/api/v0/conversations/[id]/route.js.nft.json +1 -1
  89. package/app/.next/server/app/api/v0/exchanges/[id]/cancel/route.js.nft.json +1 -1
  90. package/app/.next/server/app/api/v0/exchanges/[id]/route.js.nft.json +1 -1
  91. package/app/.next/server/app/api/v0/exchanges/route.js.nft.json +1 -1
  92. package/app/.next/server/app/api/v0/mcp/route.js.nft.json +1 -1
  93. package/app/.next/server/app/api/v0/pins/[pinRef]/detach/route.js.nft.json +1 -1
  94. package/app/.next/server/app/api/v0/pins/[pinRef]/messages/route.js.nft.json +1 -1
  95. package/app/.next/server/app/api/v0/pins/[pinRef]/route.js.nft.json +1 -1
  96. package/app/.next/server/app/api/v0/requests/[id]/route.js.nft.json +1 -1
  97. package/app/.next/server/app/api/v0/sessions/[ref]/messages/route.js.nft.json +1 -1
  98. package/app/.next/server/app/api/v0/sessions/[ref]/pins/route.js.nft.json +1 -1
  99. package/app/.next/server/app/api/v0/sessions/[ref]/shares/route.js.nft.json +1 -1
  100. package/app/.next/server/app/api/v0/shares/[shareRef]/revoke/route.js.nft.json +1 -1
  101. package/app/.next/server/app/api/v0/shares/[shareRef]/route.js.nft.json +1 -1
  102. package/app/.next/server/app/api/v0/shares/current/route.js.nft.json +1 -1
  103. package/app/.next/server/app/api/v0/shares/route.js.nft.json +1 -1
  104. package/app/.next/server/app/api/wake-grants/[id]/revoke/route.js.nft.json +1 -1
  105. package/app/.next/server/app/api/wakes/[id]/decision/route.js.nft.json +1 -1
  106. package/app/.next/server/app/api/wakes/[id]/retry/route.js.nft.json +1 -1
  107. package/app/.next/server/app/bots/[id]/config/page.js.nft.json +1 -1
  108. package/app/.next/server/app/bots/[id]/config/page_client-reference-manifest.js +1 -1
  109. package/app/.next/server/app/exchanges/page.js.nft.json +1 -1
  110. package/app/.next/server/app/exchanges/page_client-reference-manifest.js +1 -1
  111. package/app/.next/server/app/exchanges.html +1 -1
  112. package/app/.next/server/app/exchanges.rsc +3 -3
  113. package/app/.next/server/app/exchanges.segments/_full.segment.rsc +3 -3
  114. package/app/.next/server/app/exchanges.segments/_tree.segment.rsc +2 -2
  115. package/app/.next/server/app/exchanges.segments/exchanges/__PAGE__.segment.rsc +3 -3
  116. package/app/.next/server/app/index.html +1 -1
  117. package/app/.next/server/app/index.rsc +3 -3
  118. package/app/.next/server/app/index.segments/__PAGE__.segment.rsc +3 -3
  119. package/app/.next/server/app/index.segments/_full.segment.rsc +3 -3
  120. package/app/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  121. package/app/.next/server/app/page.js.nft.json +1 -1
  122. package/app/.next/server/app/page_client-reference-manifest.js +1 -1
  123. package/app/.next/server/app/settings/page.js.nft.json +1 -1
  124. package/app/.next/server/app/settings/page_client-reference-manifest.js +1 -1
  125. package/app/.next/server/app/settings.html +1 -1
  126. package/app/.next/server/app/settings.rsc +3 -3
  127. package/app/.next/server/app/settings.segments/_full.segment.rsc +3 -3
  128. package/app/.next/server/app/settings.segments/_tree.segment.rsc +2 -2
  129. package/app/.next/server/app/settings.segments/settings/__PAGE__.segment.rsc +3 -3
  130. package/app/.next/server/app/threads/[id]/route.js.nft.json +1 -1
  131. package/app/.next/server/app-paths-manifest.json +1 -0
  132. package/app/.next/server/chunks/[externals]__06_ygwr._.js +3 -0
  133. package/app/.next/server/chunks/{[externals]__1eaoma8._.js → [externals]__0z3qnkl._.js} +2 -2
  134. package/app/.next/server/chunks/[root-of-the-server]__0aincj4._.js +1 -1
  135. package/app/.next/server/chunks/[root-of-the-server]__0anfwiu._.js +1 -1
  136. package/app/.next/server/chunks/[root-of-the-server]__0fku-bw._.js +1 -1
  137. package/app/.next/server/chunks/[root-of-the-server]__1280ke1._.js +1 -1
  138. package/app/.next/server/chunks/[root-of-the-server]__13wghn3._.js +4 -4
  139. package/app/.next/server/chunks/[root-of-the-server]__1jxwu9_._.js +2 -2
  140. package/app/.next/server/chunks/{[root-of-the-server]__00ntari._.js → [root-of-the-server]__1nf6z4s._.js} +10 -10
  141. package/app/.next/server/chunks/[root-of-the-server]__1qbadul._.js +5 -0
  142. package/app/.next/server/chunks/_0061c2q._.js +1 -1
  143. package/app/.next/server/chunks/_1-5mthb._.js +1 -1
  144. package/app/.next/server/chunks/_1a0er16._.js +3 -3
  145. package/app/.next/server/chunks/_1uxmsh3._.js +3 -3
  146. package/app/.next/server/chunks/_next-internal_server_app_api_runtime-capacity_route_actions_1dzvg7f.js +3 -0
  147. package/app/.next/server/chunks/lib_service-api_ts_18eok4w._.js +3 -3
  148. package/app/.next/server/chunks/ssr/_00qrupp._.js +3 -0
  149. package/app/.next/server/chunks/ssr/_01ngpwj._.js +1 -1
  150. package/app/.next/server/chunks/ssr/_0d7gv3q._.js +3 -0
  151. package/app/.next/server/chunks/ssr/_0iywd5g._.js +1 -1
  152. package/app/.next/server/chunks/ssr/_0mxifu3._.js +1 -1
  153. package/app/.next/server/chunks/ssr/_0u7urta._.js +1 -1
  154. package/app/.next/server/chunks/ssr/app_agents_[id]_0sr4fdg._.js +1 -1
  155. package/app/.next/server/chunks/ssr/app_agents_[id]_activity_AgentActivityPage_tsx_042-590._.js +1 -1
  156. package/app/.next/server/chunks/ssr/app_agents_[id]_config_page_tsx_1f_gu1l._.js +1 -1
  157. package/app/.next/server/chunks/ssr/app_agents_[id]_sessions_page_tsx_0tfup-2._.js +3 -3
  158. package/app/.next/server/chunks/ssr/app_agents_[id]_slack_AgentSlackPage_tsx_20njhs1._.js +1 -1
  159. package/app/.next/server/chunks/ssr/app_page_tsx_0pxmutw._.js +1 -1
  160. package/app/.next/server/chunks/ssr/lib_0pfn9gs._.js +1 -1
  161. package/app/.next/server/chunks/ssr/lib_agent-registration-ui_ts_1z582mm._.js +1 -1
  162. package/app/.next/server/chunks/ssr/lib_exchange-view_ts_1a4q9ju._.js +1 -1
  163. package/app/.next/server/chunks/ssr/lib_share-view_ts_08psw5o._.js +1 -1
  164. package/app/.next/server/middleware-build-manifest.js +3 -3
  165. package/app/.next/server/middleware.js +2 -2
  166. package/app/.next/server/pages/404.html +1 -1
  167. package/app/.next/server/pages/500.html +1 -1
  168. package/app/.next/server/server-reference-manifest.js +1 -1
  169. package/app/.next/server/server-reference-manifest.json +1 -1
  170. package/app/.next/static/chunks/{2dtkykrnob8wk.js → 00pca1oa16xc5.js} +1 -1
  171. package/app/.next/static/chunks/{3x56k5qa012au.js → 0apccyvpyjlo7.js} +1 -1
  172. package/app/.next/static/chunks/{04nfr73lkk7pz.js → 0l9r-x310007w.js} +1 -1
  173. package/app/.next/static/chunks/{0eqgs3167zj2j.js → 0xo3nwo_nscvf.js} +1 -1
  174. package/app/.next/static/chunks/{326jto9l-m8vj.js → 0z_bq7h1mwcf3.js} +4 -4
  175. package/app/.next/static/chunks/18btj4qlun8o7.js +1 -0
  176. package/app/.next/static/chunks/{2cc4uzbhs_v23.js → 1k8e6j67zksws.js} +1 -1
  177. package/app/.next/static/chunks/1y9hc8qm0hqds.js +1 -0
  178. package/app/.next/static/chunks/{2ebpfmg4vni8e.js → 2wbcr5n_vcynr.js} +1 -1
  179. package/app/.next/static/chunks/3_lwv2zgy_-bw.css +3 -0
  180. package/app/.next/static/chunks/3a_ffnuma49te.js +1 -0
  181. package/app/.next/static/chunks/{3whw2-l4a2sli.js → 3fm68xa8a4-es.js} +1 -1
  182. package/app/.next/static/chunks/{0cjh4u-f7mlwd.js → 3gw1ytgjq4pxu.js} +1 -1
  183. package/app/.next/static/chunks/3wlqn3gd_jv_r.js +1 -0
  184. package/app/.next/static/chunks/3xjoca0z2onuc.js +1 -0
  185. package/app/BUILD_INFO.json +2 -2
  186. package/app/package.json +1 -1
  187. package/app/public/brand/harness/claude.svg +3 -0
  188. package/app/public/brand/harness/codex.png +0 -0
  189. package/app/public/brand/harness/cursor.svg +3 -0
  190. package/app/public/brand/harness/muse.svg +33 -0
  191. package/app/server.js +1 -1
  192. package/package.json +1 -1
  193. package/schemas/botmancers.mcp.v2.tools.json +46 -46
  194. package/app/.next/server/chunks/ssr/_0g3y1u9._.js +0 -3
  195. package/app/.next/server/chunks/ssr/app_agents_[id]_conversations_page_tsx_15zl_c8._.js +0 -3
  196. package/app/.next/static/chunks/10i-rrea371m2.js +0 -1
  197. package/app/.next/static/chunks/1ob-de9xo9m2e.css +0 -3
  198. package/app/.next/static/chunks/1ypwptc0fsn4w.js +0 -1
  199. package/app/.next/static/chunks/1zryovio86f1z.js +0 -1
  200. package/app/.next/static/chunks/34v8aumua0x5n.js +0 -1
  201. package/app/.next/static/chunks/3m-2-98qud-hf.js +0 -1
  202. /package/app/.next/static/{0BJMiZPkEfFOd56nhl62e → eBmHBBldHWytVvYPu0zHc}/_buildManifest.js +0 -0
  203. /package/app/.next/static/{0BJMiZPkEfFOd56nhl62e → eBmHBBldHWytVvYPu0zHc}/_clientMiddlewareManifest.js +0 -0
  204. /package/app/.next/static/{0BJMiZPkEfFOd56nhl62e → eBmHBBldHWytVvYPu0zHc}/_ssgManifest.js +0 -0
@@ -1,10 +1,10 @@
1
- module.exports=[26847,a=>{"use strict";var b=a.i(87924),c=a.i(38246),d=a.i(72131),e=a.i(50944),f=a.i(65221),g=a.i(22151),h=a.i(10209),i=a.i(35099);function j({mode:a,session:c,agents:e,origin:g,onClose:k,onStarted:l}){let m=(0,d.useId)(),n=(0,d.useId)(),o=(0,d.useId)(),p=(0,d.useId)(),[q,r]=(0,d.useState)(""),[s,t]=(0,d.useState)(""),[u,v]=(0,d.useState)(!1),[w,x]=(0,d.useState)({}),[y,z]=(0,d.useState)(""),[A,B]=(0,d.useState)(!1),C=(0,d.useRef)(!1),D=(0,d.useRef)(null),E=(0,d.useRef)(null),F=(0,d.useRef)(null),G=(0,d.useRef)(null),H=(0,d.useRef)(null),I=(0,i.sessionDialogUsesPin)(a,c.route),J=e.filter(a=>a.id!==c.agent.id);(0,d.useEffect)(()=>{("continue"===a?G.current:F.current)?.focus()},[a]),(0,d.useEffect)(()=>{let a=a=>{"Escape"===a.key&&(a.stopPropagation(),k())};return document.addEventListener("keydown",a,!0),()=>document.removeEventListener("keydown",a,!0)},[k]);let K=async b=>{if(b.preventDefault(),C.current)return;let d={mode:"resume"===a?"ask":a,instruction:q,originConversationId:g.conversationId,destinationAgentId:s},e="resume"===a?(0,i.validateResumeDraft)(q,u):(0,i.validateDraft)(d);if(x(e),Object.keys(e).length>0)return void(e.destination?G.current?.focus():e.instruction?F.current?.focus():H.current?.focus());let f="resume"===a?"resume":"ask",h=a=>I?(0,i.pinRequestBody)(f,q,g.conversationId,u,a):(0,i.exchangeRequestBody)(d,{agentId:c.agent.id,sessionRef:c.ref},a),j=JSON.stringify(h(""));D.current&&D.current.payload===j||(D.current={payload:j,key:crypto.randomUUID()}),C.current=!0,B(!0),z("");try{let a=I?`/api/bots/${encodeURIComponent(c.agent.id)}/sessions/${encodeURIComponent(c.ref)}/pins`:"/api/exchanges",b=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h(D.current.key))}),d=await b.json().catch(()=>null);if(!b.ok){let a="string"==typeof d?.error?.code?d.error.code:null;"idempotency_conflict"===a&&(D.current=null),z((0,i.submitErrorMessage)(a,"string"==typeof d?.error?.message?d.error.message:null));return}let e=I?d?.turn?.exchange_id:d?.exchange?.id;l("string"==typeof e?e:null)}catch{z((0,i.submitErrorMessage)(null,"Botmancers could not be reached. Your draft is kept; try again."))}finally{C.current=!1,B(!1)}},L=J.find(a=>a.id===s)?.name,M="ask"===a,N="resume"===a;return(0,b.jsx)("div",{className:"modal-scrim exchange-scrim",onMouseDown:a=>{a.target===a.currentTarget&&k()},onKeyDown:a=>{if("Tab"!==a.key||!E.current)return;let b=Array.from(E.current.querySelectorAll(h.DIALOG_FOCUSABLE)),c=(0,h.wrapFocusTarget)(b,document.activeElement,a.shiftKey);c&&(a.preventDefault(),c.focus())},children:(0,b.jsxs)("div",{ref:E,className:"form-card exchange-dialog",role:"dialog","aria-modal":"true","aria-labelledby":m,"data-exchange-mode":a,children:[(0,b.jsx)("h2",{id:m,className:"delete-title",children:(0,i.sessionDialogTitle)(a)}),(0,b.jsxs)("section",{className:"exchange-source","aria-label":"Source session",children:[(0,b.jsx)("p",{className:"exchange-source-agent",children:c.agent.name}),(0,b.jsx)("p",{className:"exchange-source-title",children:c.title}),(0,b.jsxs)("p",{className:"exchange-source-meta",children:["Last activity ",(0,f.formatSessionDate)(c.last_activity_at),c.origin.conversation?` \xb7 from ${c.origin.conversation.label}`:""]})]}),(0,b.jsxs)("form",{onSubmit:K,noValidate:!0,className:"exchange-form",children:[M||N?null:(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("label",{htmlFor:o,children:"Hand off to"}),(0,b.jsxs)("select",{ref:G,id:o,className:"exchange-select",value:s,"aria-invalid":!!w.destination||void 0,"aria-describedby":w.destination?`${o}-error`:void 0,disabled:A,onChange:a=>{t(a.target.value),x(a=>({...a,destination:void 0}))},children:[(0,b.jsx)("option",{value:"",children:"Choose an Agent"}),J.map(a=>(0,b.jsx)("option",{value:a.id,children:a.name},a.id))]}),w.destination?(0,b.jsx)("p",{id:`${o}-error`,className:"exchange-field-error",children:w.destination}):null]}),(0,b.jsx)("label",{htmlFor:n,children:M?"Question":N?"Instruction":"Objective"}),(0,b.jsx)("textarea",{ref:F,id:n,rows:4,maxLength:i.INSTRUCTION_LIMIT,value:q,readOnly:A,"aria-invalid":!!w.instruction||void 0,"aria-describedby":`${n}-hint${w.instruction?` ${n}-error`:""}`,onChange:a=>{r(a.target.value),x(a=>({...a,instruction:void 0}))}}),w.instruction?(0,b.jsx)("p",{id:`${n}-error`,className:"exchange-field-error",children:w.instruction}):null,(0,b.jsx)("p",{id:`${n}-hint`,className:"exchange-hint",children:M?`${c.agent.name} answers from this exact session, read-only. The answer arrives in ${g.label}.`:N?`${c.agent.name} resumes work in this exact session and may edit its workspace. The turn never moves to another session. Progress shows in ${g.label}.`:`${L??"The Agent you choose"} receives an extracted handoff (objective, decisions, constraints, references, open questions) and starts a new session of its own. ${c.agent.name}’s session is not shared and is not changed. Progress shows in ${g.label}.`}),N?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("label",{className:"exchange-approval",htmlFor:p,children:[(0,b.jsx)("input",{ref:H,id:p,type:"checkbox",checked:u,disabled:A,"aria-invalid":!!w.approval||void 0,"aria-describedby":w.approval?`${p}-error`:void 0,onChange:a=>{v(a.target.checked),x(a=>({...a,approval:void 0}))}})," ","I approve edits by ",c.agent.name," in this session"]}),w.approval?(0,b.jsx)("p",{id:`${p}-error`,className:"exchange-field-error",children:w.approval}):null]}):null,y?(0,b.jsx)("p",{className:"exchange-server-error",role:"alert",children:y}):null,(0,b.jsx)("p",{className:"exchange-sending",role:"status",children:A?"Sending…":""}),(0,b.jsxs)("div",{className:"form-actions",children:[(0,b.jsx)("button",{type:"button",className:"cancel-btn",onClick:k,children:"Cancel"}),(0,b.jsx)("button",{type:"submit",className:"create-btn",disabled:A,"aria-disabled":A,children:y?"Try again":"Send"})]})]})]})})}var k=a.i(23464);function l(){return"u">typeof crypto&&"function"==typeof crypto.randomUUID?`owner-share-${crypto.randomUUID()}`:`owner-share-${Date.now()}-${Math.random().toString(36).slice(2)}`}function m({row:a,shares:e,policy:f,onChanged:g}){let h=(0,d.useId)(),[i,j]=(0,d.useState)(!1),[l,p]=(0,d.useState)(!1),q=e?(0,k.sessionShares)(e,a.ref):[],r=q.filter(k.shareIsLive),s=q.filter(a=>!(0,k.shareIsLive)(a)),t="loading"===f,u="loading"===f?null:f,v=t?null:(0,k.shareCreateAvailability)(a,u),w=l?s:s.slice(0,3*!r.length);return(0,b.jsxs)("section",{className:"session-shares","aria-labelledby":h,"data-session-shares":a.ref,children:[(0,b.jsxs)("div",{className:"session-shares-head",children:[(0,b.jsx)("h3",{id:h,className:"session-shares-title",children:"Slack share"}),v?.available&&!i?(0,b.jsx)("button",{type:"button",className:"session-action","data-share-action":"create",onClick:()=>j(!0),children:"Share to Slack"}):null]}),t?(0,b.jsx)("p",{className:"session-share-note session-share-loading",role:"status",children:"Checking the share policy…"}):null,v&&!v.available?(0,b.jsxs)("p",{className:"session-share-unavailable",children:[v.reason," ",v.configHref?(0,b.jsx)(c.default,{className:"session-link",href:v.configHref,children:"Open Config"}):null]}):null,i&&u?(0,b.jsx)(o,{row:a,policy:u,onCancel:()=>j(!1),onCreated:()=>{j(!1),g()}}):null,null===e?(0,b.jsx)("p",{className:"session-share-note",role:"status",children:"Loading shares…"}):null,null===e||0!==q.length||i?null:(0,b.jsx)("p",{className:"session-share-note",children:"Not shared."}),r.length+w.length>0?(0,b.jsx)("ul",{className:"session-share-list","aria-label":`Slack shares of ${a.title}`,children:[...r,...w].map(a=>(0,b.jsx)(n,{share:a,onChanged:g},a.share_ref))}):null,s.length>w.length?(0,b.jsxs)("button",{type:"button",className:"pin-word",onClick:()=>p(!0),children:["Show ",s.length-w.length," ended share",s.length-w.length==1?"":"s"]}):null]})}function n({share:a,onChanged:c}){let[e,f]=(0,d.useState)(!1),[g,h]=(0,d.useState)(!1),[i,j]=(0,d.useState)(""),[l,m]=(0,d.useState)(!1),o=(0,k.shareIsLive)(a),p=async()=>{try{await navigator.clipboard.writeText(a.share_ref),m(!0)}catch{j("Copy failed. Select the reference instead.")}},q=async()=>{h(!0),j("");try{let b=await fetch(`/api/shares/${encodeURIComponent(a.share_ref)}/revoke`,{method:"POST"}),d=await b.json().catch(()=>null);b.ok?(f(!1),c()):j("string"==typeof d?.error?.message?d.error.message:"The share could not be revoked.")}catch{j("The share could not be revoked.")}finally{h(!1)}};return(0,b.jsxs)("li",{className:`session-share is-${a.status}`,"data-share-ref":a.share_ref,"data-share-status":a.status,children:[(0,b.jsxs)("div",{className:"session-share-head",children:[(0,b.jsx)("span",{className:`manage-tag session-share-status is-${a.status}`,children:k.SHARE_STATUS_LABELS[a.status]}),(0,b.jsx)("span",{className:"session-share-audience",children:(0,k.audienceLabel)(a.audience)})]}),(0,b.jsxs)("dl",{className:"manage-meta session-share-meta",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Expiry"}),(0,b.jsx)("dd",{children:(0,k.expiryLabel)(a)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Questions"}),(0,b.jsx)("dd",{children:(0,k.turnsLabel)(a)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Thread"}),(0,b.jsx)("dd",{children:(0,k.threadLabel)(a)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Reference"}),(0,b.jsx)("dd",{children:(0,b.jsx)("code",{className:"session-share-ref",children:a.share_ref})})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Origin"}),(0,b.jsxs)("dd",{children:[(0,k.createdByLabel)(a)," · read-only Ask"]})]})]}),(0,b.jsx)("p",{className:"session-share-note",children:(0,k.shareStatusNote)(a)}),(0,b.jsxs)("div",{className:"session-actions",role:"group","aria-label":"Share actions",children:[(0,b.jsx)("button",{type:"button",className:"pin-word","data-share-action":"copy",onClick:()=>{p()},children:l?"Copied":"Copy reference"}),o&&!e?(0,b.jsx)("button",{type:"button",className:"session-action session-share-revoke","data-share-action":"revoke",onClick:()=>f(!0),children:"Revoke"}):null]}),e?(0,b.jsxs)("div",{className:"session-share-confirm",role:"group","aria-label":"Confirm revoke",children:[(0,b.jsx)("p",{children:"Revoke this share? The next Slack question in its thread gets the revoked notice. This can’t be undone."}),(0,b.jsxs)("div",{className:"session-actions",children:[(0,b.jsx)("button",{type:"button",className:"session-action session-share-revoke","data-share-action":"confirm-revoke",disabled:g,onClick:()=>{q()},children:g?"Revoking…":"Revoke share"}),(0,b.jsx)("button",{type:"button",className:"pin-word",disabled:g,onClick:()=>f(!1),children:"Keep it"})]})]}):null,i?(0,b.jsx)("p",{className:"delete-error",role:"alert",children:i}):null]})}function o({row:a,policy:c,onCancel:e,onCreated:f}){let g={channel:(0,d.useId)(),duration:(0,d.useId)(),turns:(0,d.useId)()},[h,i]=(0,d.useState)(0),[j,m]=(0,d.useState)(c.limits.ttl_seconds.default),[n,p]=(0,d.useState)(String(c.limits.max_turns.default)),[q]=(0,d.useState)(l),[r,s]=(0,d.useState)(!1),[t,u]=(0,d.useState)(""),v=Number(n),w=Number.isInteger(v)&&v>=c.limits.max_turns.min&&v<=c.limits.max_turns.max,x=async b=>{if(b.preventDefault(),w){s(!0),u("");try{let b=await fetch(`/api/bots/${encodeURIComponent(a.agent.id)}/sessions/${encodeURIComponent(a.ref)}/shares`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify((0,k.shareCreateBody)(c.audiences[h],j,v,q))}),d=await b.json().catch(()=>null);b.ok?f():u("string"==typeof d?.error?.message?d.error.message:"The share could not be created.")}catch{u("The share could not be created.")}finally{s(!1)}}};return(0,b.jsxs)("form",{className:"session-share-form",onSubmit:a=>{x(a)},"aria-label":`Share ${a.title} to Slack`,children:[(0,b.jsxs)("p",{className:"session-share-note",children:["Shares ",(0,b.jsx)("strong",{children:a.title})," (",a.agent.name,") as a read-only Ask: Slack replies in the share’s thread ask exactly this session."]}),(0,b.jsx)("label",{htmlFor:g.channel,children:"Slack channel"}),(0,b.jsx)("select",{id:g.channel,value:h,onChange:a=>i(Number(a.target.value)),disabled:r,children:c.audiences.map((a,c)=>(0,b.jsx)("option",{value:c,children:(0,k.audienceLabel)(a)},`${a.team_id}:${a.channel_id}`))}),(0,b.jsx)("label",{htmlFor:g.duration,children:"Expires after"}),(0,b.jsx)("select",{id:g.duration,value:j,onChange:a=>m(Number(a.target.value)),disabled:r,children:k.SHARE_DURATIONS.map(a=>(0,b.jsx)("option",{value:a.seconds,children:a.label},a.seconds))}),(0,b.jsx)("label",{htmlFor:g.turns,children:"Questions allowed"}),(0,b.jsx)("input",{id:g.turns,type:"number",inputMode:"numeric",min:c.limits.max_turns.min,max:c.limits.max_turns.max,value:n,onChange:a=>p(a.target.value),disabled:r,"aria-invalid":!w}),w?null:(0,b.jsxs)("p",{className:"delete-error",children:["Questions allowed must be a whole number from ",c.limits.max_turns.min," to ",c.limits.max_turns.max,"."]}),t?(0,b.jsx)("p",{className:"delete-error",role:"alert",children:t}):null,(0,b.jsxs)("div",{className:"session-actions",children:[(0,b.jsx)("button",{type:"submit",className:"session-action","data-share-action":"submit",disabled:r||!w,children:r?"Sharing…":"Create share"}),(0,b.jsx)("button",{type:"button",className:"pin-word",onClick:e,disabled:r,children:"Cancel"})]})]})}function p(a,b,c,d,e){let f=new URLSearchParams({status:b}),g=c.trim();return g&&f.set("q",g),d&&f.set("workspace",d),e&&f.set("cursor",e),`/api/bots/${encodeURIComponent(a)}/sessions?${f.toString()}`}function q({agentId:a,agentName:h,agentProvider:k,agents:l,origin:m,onExchangeStarted:n}){let o=(0,e.useRouter)(),t=(0,e.useSearchParams)().get("session"),[u,v]=(0,d.useState)("all"),[w,x]=(0,d.useState)(null),[y,z]=(0,d.useState)(null),[A,B]=(0,d.useState)(!1),[C,D]=(0,d.useState)(""),[E,F]=(0,d.useState)(""),[G,H]=(0,d.useState)(0),[I,J]=(0,d.useState)(""),[K,L]=(0,d.useState)(""),[M,N]=(0,d.useState)([]),[O,P]=(0,d.useState)(null),[Q,R]=(0,d.useState)(!1),[S,T]=(0,d.useState)(""),[U,V]=(0,d.useState)(null),[W,X]=(0,d.useState)(null),[Y,Z]=(0,d.useState)(null),[$,_]=(0,d.useState)(null),[aa,ab]=(0,d.useState)("loading"),[ac,ad]=(0,d.useState)(0),ae=(0,d.useRef)(0),af=(0,d.useRef)(""),ag=(0,d.useRef)(""),ah=(0,d.useRef)(null),ai=(0,d.useRef)(null),aj=(0,d.useRef)(null),ak=(0,d.useRef)(!1),al=(0,d.useRef)(null),am=k&&(0,g.agentLabel)(k)||void 0;(0,d.useEffect)(()=>{ae.current+=1;let b=ae.current,c=`${a}
1
+ module.exports=[26847,a=>{"use strict";var b=a.i(87924),c=a.i(38246),d=a.i(72131),e=a.i(50944),f=a.i(65221),g=a.i(22151),h=a.i(10209),i=a.i(35099);function j({mode:a,session:c,agents:e,origin:g,onClose:k,onStarted:l}){let m=(0,d.useId)(),n=(0,d.useId)(),o=(0,d.useId)(),p=(0,d.useId)(),[q,r]=(0,d.useState)(""),[s,t]=(0,d.useState)(""),[u,v]=(0,d.useState)(!1),[w,x]=(0,d.useState)({}),[y,z]=(0,d.useState)(""),[A,B]=(0,d.useState)(!1),C=(0,d.useRef)(!1),D=(0,d.useRef)(null),E=(0,d.useRef)(null),F=(0,d.useRef)(null),G=(0,d.useRef)(null),H=(0,d.useRef)(null),I=(0,i.sessionDialogUsesPin)(a,c.route),J=e.filter(a=>a.id!==c.agent.id);(0,d.useEffect)(()=>{("continue"===a?G.current:F.current)?.focus()},[a]),(0,d.useEffect)(()=>{let a=a=>{"Escape"===a.key&&(a.stopPropagation(),k())};return document.addEventListener("keydown",a,!0),()=>document.removeEventListener("keydown",a,!0)},[k]);let K=async b=>{if(b.preventDefault(),C.current)return;let d={mode:"resume"===a?"ask":a,instruction:q,originConversationId:g.conversationId,destinationAgentId:s},e="resume"===a?(0,i.validateResumeDraft)(q,u):(0,i.validateDraft)(d);if(x(e),Object.keys(e).length>0)return void(e.destination?G.current?.focus():e.instruction?F.current?.focus():H.current?.focus());let f="resume"===a?"resume":"ask",h=a=>I?(0,i.pinRequestBody)(f,q,g.conversationId,u,a):(0,i.exchangeRequestBody)(d,{agentId:c.agent.id,sessionRef:c.ref},a),j=JSON.stringify(h(""));D.current&&D.current.payload===j||(D.current={payload:j,key:crypto.randomUUID()}),C.current=!0,B(!0),z("");try{let a=I?`/api/bots/${encodeURIComponent(c.agent.id)}/sessions/${encodeURIComponent(c.ref)}/pins`:"/api/exchanges",b=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h(D.current.key))}),d=await b.json().catch(()=>null);if(!b.ok){let a="string"==typeof d?.error?.code?d.error.code:null;"idempotency_conflict"===a&&(D.current=null),z((0,i.submitErrorMessage)(a,"string"==typeof d?.error?.message?d.error.message:null));return}let e=I?d?.turn?.exchange_id:d?.exchange?.id;l("string"==typeof e?e:null)}catch{z((0,i.submitErrorMessage)(null,"Botmancers could not be reached. Your draft is kept; try again."))}finally{C.current=!1,B(!1)}},L=J.find(a=>a.id===s)?.name,M="ask"===a,N="resume"===a;return(0,b.jsx)("div",{className:"modal-scrim exchange-scrim",onMouseDown:a=>{a.target===a.currentTarget&&k()},onKeyDown:a=>{if("Tab"!==a.key||!E.current)return;let b=Array.from(E.current.querySelectorAll(h.DIALOG_FOCUSABLE)),c=(0,h.wrapFocusTarget)(b,document.activeElement,a.shiftKey);c&&(a.preventDefault(),c.focus())},children:(0,b.jsxs)("div",{ref:E,className:"form-card exchange-dialog",role:"dialog","aria-modal":"true","aria-labelledby":m,"data-exchange-mode":a,children:[(0,b.jsx)("h2",{id:m,className:"delete-title",children:(0,i.sessionDialogTitle)(a)}),(0,b.jsxs)("section",{className:"exchange-source","aria-label":"Source session",children:[(0,b.jsx)("p",{className:"exchange-source-agent",children:c.agent.name}),(0,b.jsx)("p",{className:"exchange-source-title",children:c.title}),(0,b.jsxs)("p",{className:"exchange-source-meta",children:["Last activity ",(0,f.formatSessionDate)(c.last_activity_at),c.origin.conversation?` \xb7 from ${c.origin.conversation.label}`:""]})]}),(0,b.jsxs)("form",{onSubmit:K,noValidate:!0,className:"exchange-form",children:[M||N?null:(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("label",{htmlFor:o,children:"Hand off to"}),(0,b.jsxs)("select",{ref:G,id:o,className:"exchange-select",value:s,"aria-invalid":!!w.destination||void 0,"aria-describedby":w.destination?`${o}-error`:void 0,disabled:A,onChange:a=>{t(a.target.value),x(a=>({...a,destination:void 0}))},children:[(0,b.jsx)("option",{value:"",children:"Choose an agent"}),J.map(a=>(0,b.jsx)("option",{value:a.id,children:a.name},a.id))]}),w.destination?(0,b.jsx)("p",{id:`${o}-error`,className:"exchange-field-error",children:w.destination}):null]}),(0,b.jsx)("label",{htmlFor:n,children:M?"Question":N?"Instruction":"Objective"}),(0,b.jsx)("textarea",{ref:F,id:n,rows:4,maxLength:i.INSTRUCTION_LIMIT,value:q,readOnly:A,"aria-invalid":!!w.instruction||void 0,"aria-describedby":`${n}-hint${w.instruction?` ${n}-error`:""}`,onChange:a=>{r(a.target.value),x(a=>({...a,instruction:void 0}))}}),w.instruction?(0,b.jsx)("p",{id:`${n}-error`,className:"exchange-field-error",children:w.instruction}):null,(0,b.jsx)("p",{id:`${n}-hint`,className:"exchange-hint",children:M?`${c.agent.name} answers from this exact session, read-only. The answer arrives in ${g.label}.`:N?`${c.agent.name} resumes work in this exact session and may edit its workspace. The turn never moves to another session. Progress shows in ${g.label}.`:`${L??"The agent you choose"} receives an extracted handoff (objective, decisions, constraints, references, open questions) and starts a new session of its own. ${c.agent.name}’s session is not shared and is not changed. Progress shows in ${g.label}.`}),N?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("label",{className:"exchange-approval",htmlFor:p,children:[(0,b.jsx)("input",{ref:H,id:p,type:"checkbox",checked:u,disabled:A,"aria-invalid":!!w.approval||void 0,"aria-describedby":w.approval?`${p}-error`:void 0,onChange:a=>{v(a.target.checked),x(a=>({...a,approval:void 0}))}})," ","I approve edits by ",c.agent.name," in this session"]}),w.approval?(0,b.jsx)("p",{id:`${p}-error`,className:"exchange-field-error",children:w.approval}):null]}):null,y?(0,b.jsx)("p",{className:"exchange-server-error",role:"alert",children:y}):null,(0,b.jsx)("p",{className:"exchange-sending",role:"status",children:A?"Sending…":""}),(0,b.jsxs)("div",{className:"form-actions",children:[(0,b.jsx)("button",{type:"button",className:"cancel-btn",onClick:k,children:"Cancel"}),(0,b.jsx)("button",{type:"submit",className:"create-btn",disabled:A,"aria-disabled":A,children:y?"Try again":"Send"})]})]})]})})}var k=a.i(23464);function l(){return"u">typeof crypto&&"function"==typeof crypto.randomUUID?`owner-share-${crypto.randomUUID()}`:`owner-share-${Date.now()}-${Math.random().toString(36).slice(2)}`}function m({row:a,shares:e,policy:f,onChanged:g}){let h=(0,d.useId)(),[i,j]=(0,d.useState)(!1),[l,p]=(0,d.useState)(!1),q=e?(0,k.sessionShares)(e,a.ref):[],r=q.filter(k.shareIsLive),s=q.filter(a=>!(0,k.shareIsLive)(a)),t="loading"===f,u="loading"===f?null:f,v=t?null:(0,k.shareCreateAvailability)(a,u),w=l?s:s.slice(0,3*!r.length);return(0,b.jsxs)("section",{className:"session-shares","aria-labelledby":h,"data-session-shares":a.ref,children:[(0,b.jsxs)("div",{className:"session-shares-head",children:[(0,b.jsx)("h3",{id:h,className:"session-shares-title",children:"Slack share"}),v?.available&&!i?(0,b.jsx)("button",{type:"button",className:"session-action","data-share-action":"create",onClick:()=>j(!0),children:"Share to Slack"}):null]}),t?(0,b.jsx)("p",{className:"session-share-note session-share-loading",role:"status",children:"Checking the share policy…"}):null,v&&!v.available?(0,b.jsxs)("p",{className:"session-share-unavailable",children:[v.reason," ",v.configHref?(0,b.jsx)(c.default,{className:"session-link",href:v.configHref,children:"Open Config"}):null]}):null,i&&u?(0,b.jsx)(o,{row:a,policy:u,onCancel:()=>j(!1),onCreated:()=>{j(!1),g()}}):null,null===e?(0,b.jsx)("p",{className:"session-share-note",role:"status",children:"Loading shares…"}):null,null===e||0!==q.length||i?null:(0,b.jsx)("p",{className:"session-share-note",children:"Not shared."}),r.length+w.length>0?(0,b.jsx)("ul",{className:"session-share-list","aria-label":`Slack shares of ${a.title}`,children:[...r,...w].map(a=>(0,b.jsx)(n,{share:a,onChanged:g},a.share_ref))}):null,s.length>w.length?(0,b.jsxs)("button",{type:"button",className:"pin-word",onClick:()=>p(!0),children:["Show ",s.length-w.length," ended share",s.length-w.length==1?"":"s"]}):null]})}function n({share:a,onChanged:c}){let[e,f]=(0,d.useState)(!1),[g,h]=(0,d.useState)(!1),[i,j]=(0,d.useState)(""),[l,m]=(0,d.useState)(!1),o=(0,k.shareIsLive)(a),p=async()=>{try{await navigator.clipboard.writeText(a.share_ref),m(!0)}catch{j("Copy failed. Select the reference instead.")}},q=async()=>{h(!0),j("");try{let b=await fetch(`/api/shares/${encodeURIComponent(a.share_ref)}/revoke`,{method:"POST"}),d=await b.json().catch(()=>null);b.ok?(f(!1),c()):j("string"==typeof d?.error?.message?d.error.message:"The share could not be revoked.")}catch{j("The share could not be revoked.")}finally{h(!1)}};return(0,b.jsxs)("li",{className:`session-share is-${a.status}`,"data-share-ref":a.share_ref,"data-share-status":a.status,children:[(0,b.jsxs)("div",{className:"session-share-head",children:[(0,b.jsx)("span",{className:`manage-tag session-share-status is-${a.status}`,children:k.SHARE_STATUS_LABELS[a.status]}),(0,b.jsx)("span",{className:"session-share-audience",children:(0,k.audienceLabel)(a.audience)})]}),(0,b.jsxs)("dl",{className:"manage-meta session-share-meta",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Expiry"}),(0,b.jsx)("dd",{children:(0,k.expiryLabel)(a)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Questions"}),(0,b.jsx)("dd",{children:(0,k.turnsLabel)(a)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Thread"}),(0,b.jsx)("dd",{children:(0,k.threadLabel)(a)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Reference"}),(0,b.jsx)("dd",{children:(0,b.jsx)("code",{className:"session-share-ref",children:a.share_ref})})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Origin"}),(0,b.jsxs)("dd",{children:[(0,k.createdByLabel)(a)," · read-only Ask"]})]})]}),(0,b.jsx)("p",{className:"session-share-note",children:(0,k.shareStatusNote)(a)}),(0,b.jsxs)("div",{className:"session-actions",role:"group","aria-label":"Share actions",children:[(0,b.jsx)("button",{type:"button",className:"pin-word","data-share-action":"copy",onClick:()=>{p()},children:l?"Copied":"Copy reference"}),o&&!e?(0,b.jsx)("button",{type:"button",className:"session-action session-share-revoke","data-share-action":"revoke",onClick:()=>f(!0),children:"Revoke"}):null]}),e?(0,b.jsxs)("div",{className:"session-share-confirm",role:"group","aria-label":"Confirm revoke",children:[(0,b.jsx)("p",{children:"Revoke this share? The next Slack question in its thread gets the revoked notice. This can’t be undone."}),(0,b.jsxs)("div",{className:"session-actions",children:[(0,b.jsx)("button",{type:"button",className:"session-action session-share-revoke","data-share-action":"confirm-revoke",disabled:g,onClick:()=>{q()},children:g?"Revoking…":"Revoke share"}),(0,b.jsx)("button",{type:"button",className:"pin-word",disabled:g,onClick:()=>f(!1),children:"Keep it"})]})]}):null,i?(0,b.jsx)("p",{className:"delete-error",role:"alert",children:i}):null]})}function o({row:a,policy:c,onCancel:e,onCreated:f}){let g={channel:(0,d.useId)(),duration:(0,d.useId)(),turns:(0,d.useId)()},[h,i]=(0,d.useState)(0),[j,m]=(0,d.useState)(c.limits.ttl_seconds.default),[n,p]=(0,d.useState)(String(c.limits.max_turns.default)),[q]=(0,d.useState)(l),[r,s]=(0,d.useState)(!1),[t,u]=(0,d.useState)(""),v=Number(n),w=Number.isInteger(v)&&v>=c.limits.max_turns.min&&v<=c.limits.max_turns.max,x=async b=>{if(b.preventDefault(),w){s(!0),u("");try{let b=await fetch(`/api/bots/${encodeURIComponent(a.agent.id)}/sessions/${encodeURIComponent(a.ref)}/shares`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify((0,k.shareCreateBody)(c.audiences[h],j,v,q))}),d=await b.json().catch(()=>null);b.ok?f():u("string"==typeof d?.error?.message?d.error.message:"The share could not be created.")}catch{u("The share could not be created.")}finally{s(!1)}}};return(0,b.jsxs)("form",{className:"session-share-form",onSubmit:a=>{x(a)},"aria-label":`Share ${a.title} to Slack`,children:[(0,b.jsxs)("p",{className:"session-share-note",children:["Shares ",(0,b.jsx)("strong",{children:a.title})," (",a.agent.name,") as a read-only Ask: Slack replies in the share’s thread ask exactly this session."]}),(0,b.jsx)("label",{htmlFor:g.channel,children:"Slack channel"}),(0,b.jsx)("select",{id:g.channel,value:h,onChange:a=>i(Number(a.target.value)),disabled:r,children:c.audiences.map((a,c)=>(0,b.jsx)("option",{value:c,children:(0,k.audienceLabel)(a)},`${a.team_id}:${a.channel_id}`))}),(0,b.jsx)("label",{htmlFor:g.duration,children:"Expires after"}),(0,b.jsx)("select",{id:g.duration,value:j,onChange:a=>m(Number(a.target.value)),disabled:r,children:k.SHARE_DURATIONS.map(a=>(0,b.jsx)("option",{value:a.seconds,children:a.label},a.seconds))}),(0,b.jsx)("label",{htmlFor:g.turns,children:"Questions allowed"}),(0,b.jsx)("input",{id:g.turns,type:"number",inputMode:"numeric",min:c.limits.max_turns.min,max:c.limits.max_turns.max,value:n,onChange:a=>p(a.target.value),disabled:r,"aria-invalid":!w}),w?null:(0,b.jsxs)("p",{className:"delete-error",children:["Questions allowed must be a whole number from ",c.limits.max_turns.min," to ",c.limits.max_turns.max,"."]}),t?(0,b.jsx)("p",{className:"delete-error",role:"alert",children:t}):null,(0,b.jsxs)("div",{className:"session-actions",children:[(0,b.jsx)("button",{type:"submit",className:"session-action","data-share-action":"submit",disabled:r||!w,children:r?"Sharing…":"Create share"}),(0,b.jsx)("button",{type:"button",className:"pin-word",onClick:e,disabled:r,children:"Cancel"})]})]})}function p(a,b,c,d,e){let f=new URLSearchParams({status:b}),g=c.trim();return g&&f.set("q",g),d&&f.set("workspace",d),e&&f.set("cursor",e),`/api/bots/${encodeURIComponent(a)}/sessions?${f.toString()}`}function q({agentId:a,agentName:h,agentProvider:k,agents:l,origin:m,onExchangeStarted:n}){let o=(0,e.useRouter)(),t=(0,e.useSearchParams)().get("session"),[u,v]=(0,d.useState)("all"),[w,x]=(0,d.useState)(null),[y,z]=(0,d.useState)(null),[A,B]=(0,d.useState)(!1),[C,D]=(0,d.useState)(""),[E,F]=(0,d.useState)(""),[G,H]=(0,d.useState)(0),[I,J]=(0,d.useState)(""),[K,L]=(0,d.useState)(""),[M,N]=(0,d.useState)([]),[O,P]=(0,d.useState)(null),[Q,R]=(0,d.useState)(!1),[S,T]=(0,d.useState)(""),[U,V]=(0,d.useState)(null),[W,X]=(0,d.useState)(null),[Y,Z]=(0,d.useState)(null),[$,_]=(0,d.useState)(null),[aa,ab]=(0,d.useState)("loading"),[ac,ad]=(0,d.useState)(0),ae=(0,d.useRef)(0),af=(0,d.useRef)(""),ag=(0,d.useRef)(""),ah=(0,d.useRef)(null),ai=(0,d.useRef)(null),aj=(0,d.useRef)(null),ak=(0,d.useRef)(!1),al=(0,d.useRef)(null),am=k&&(0,g.agentLabel)(k)||void 0;(0,d.useEffect)(()=>{ae.current+=1;let b=ae.current,c=`${a}
2
2
  ${u}`,d=ag.current!==c;ag.current=c;let e=250*(I!==af.current);af.current=I;let f=!1,g=setTimeout(()=>{fetch(p(a,u,I,K,null),{cache:"no-store"}).then(async c=>{let e=await c.json().catch(()=>null);if(f||ae.current!==b)return;if(!c.ok||!Array.isArray(e?.sessions))return void F("string"==typeof e?.error?e.error:"Could not load sessions.");let g=e.sessions;x(g),z(e?.sync&&"object"==typeof e.sync?e.sync:null),P("string"==typeof e?.next_cursor?e.next_cursor:null),T(`${a}
3
3
  ${u}
4
4
  ${I.trim()}
5
- ${K}`),F("");let h=g.map(a=>a.context.workspace).filter(a=>!!a);N(a=>[...new Set([...d?[]:a,...h])])}).catch(()=>{f||ae.current!==b||F("Could not load sessions.")})},e);return()=>{f=!0,clearTimeout(g)}},[a,u,I,K,G]),(0,d.useEffect)(()=>{if(!t||null===w)return;if(w.some(a=>a.ref===t)){al.current!==t&&(al.current=t,requestAnimationFrame(()=>requestAnimationFrame(()=>{document.querySelector(`[data-session-ref="${CSS.escape(t)}"]`)?.scrollIntoView({block:"nearest"})})));return}if("all"!==u||I.trim()||K)return;let b=!1;return fetch(`/api/bots/${encodeURIComponent(a)}/sessions/${encodeURIComponent(t)}`,{cache:"no-store"}).then(async a=>{let c=await a.json().catch(()=>null);if(b||!a.ok||!c?.session)return;let d=c.session;x(a=>!a||a.some(a=>a.ref===d.ref)?a:[d,...a])}).catch(()=>{}),()=>{b=!0}},[t,w,a,u,I,K]),(0,d.useEffect)(()=>{w&&(t&&w.some(a=>a.ref===t)?V(t):V(null))},[t,w]),(0,d.useEffect)(()=>{!w||!t||w.some(a=>a.ref===t)||("all"!==u||I.trim()||K)&&o.replace(`/agents/${encodeURIComponent(a)}/sessions`,{scroll:!1})},[w,t,u,I,K,a,o]),(0,d.useEffect)(()=>{if(!U){let a=ai.current;if(!a||ak.current)return;ai.current=null,a.isConnected&&a.focus();return}ak.current&&(ak.current=!1,aj.current?.focus())},[U]);let an=`${a}
5
+ ${K}`),F("");let h=g.map(a=>a.context.workspace).filter(a=>!!a);N(a=>[...new Set([...d?[]:a,...h])])}).catch(()=>{f||ae.current!==b||F("Could not load sessions.")})},e);return()=>{f=!0,clearTimeout(g)}},[a,u,I,K,G]),(0,d.useEffect)(()=>{if(!t||null===w)return;if(w.some(a=>a.ref===t)){al.current!==t&&(al.current=t,requestAnimationFrame(()=>requestAnimationFrame(()=>{document.querySelector(`[data-session-ref="${CSS.escape(t)}"]`)?.scrollIntoView({block:"nearest"})})));return}if("all"!==u||I.trim()||K)return;let b=!1;return fetch(`/api/bots/${encodeURIComponent(a)}/sessions/${encodeURIComponent(t)}`,{cache:"no-store"}).then(async a=>{let c=await a.json().catch(()=>null);if(b||!a.ok||!c?.session)return;let d=c.session;x(a=>!a||a.some(a=>a.ref===d.ref)?a:[d,...a])}).catch(()=>{}),()=>{b=!0}},[t,w,a,u,I,K]);let an=w?t&&w.some(a=>a.ref===t)?t:null:U;an!==U&&V(an),(0,d.useEffect)(()=>{!w||!t||w.some(a=>a.ref===t)||("all"!==u||I.trim()||K)&&o.replace(`/agents/${encodeURIComponent(a)}/sessions`,{scroll:!1})},[w,t,u,I,K,a,o]),(0,d.useEffect)(()=>{if(!U){let a=ai.current;if(!a||ak.current)return;ai.current=null,a.isConnected&&a.focus();return}ak.current&&(ak.current=!1,aj.current?.focus())},[U]);let ao=`${a}
6
6
  ${u}
7
7
  ${I.trim()}
8
- ${K}`,ao=null!==O&&S===an,ap=(0,d.useCallback)(async()=>{if(Q||!w||!O||S!==an)return;R(!0);let b=ae.current;try{let c=await fetch(p(a,u,I,K,O),{cache:"no-store"}),d=await c.json().catch(()=>null);if(ae.current!==b)return;if(!c.ok||!Array.isArray(d?.sessions))return void F("Could not load more sessions.");let e=d.sessions,f=new Set(w.map(a=>a.ref));x([...w,...e.filter(a=>!f.has(a.ref))]),P("string"==typeof d?.next_cursor?d.next_cursor:null),F("");let g=e.map(a=>a.context.workspace).filter(a=>!!a);g.length&&N(a=>[...new Set([...a,...g])])}catch{ae.current===b&&F("Could not load more sessions.")}finally{R(!1)}},[a,u,I,K,Q,w,O,an,S]),aq=(0,d.useCallback)(async()=>{if(!A){B(!0),D("");try{let b=await fetch(`/api/bots/${encodeURIComponent(a)}/sessions/sync`,{method:"POST"}),c=await b.json().catch(()=>null);if(409===b.status)D("A sync is already running.");else if(b.ok){let a=Array.isArray(c?.imported)?c.imported.length:0,b=Array.isArray(c?.updated)?c.updated.length:0;D(`Synced: ${a} imported, ${b} updated.`)}else D("Could not sync sessions.")}catch{D("Could not sync sessions.")}finally{B(!1),H(a=>a+1)}}},[a,A]);(0,d.useEffect)(()=>{let b=!1,c=encodeURIComponent(a);return fetch(`/api/bots/${c}/share-policy`,{cache:"no-store"}).then(a=>a.ok?a.json():null).then(a=>{b||ab(a?.policy??null)}).catch(()=>{b||ab(null)}),fetch(`/api/shares?agent_id=${c}&limit=100`,{cache:"no-store"}).then(a=>a.ok?a.json():null).then(a=>{b||_(Array.isArray(a?.shares)?a.shares:[])}).catch(()=>{b||_([])}),()=>{b=!0}},[a,ac]),(0,d.useEffect)(()=>{let a=setInterval(()=>ad(a=>a+1),15e3);return()=>clearInterval(a)},[]),(0,d.useEffect)(()=>{if(W||!ah.current)return;let a=ah.current;ah.current=null,a.isConnected&&a.focus()},[W]);let ar=(a=u)=>{x(null),F(""),v(a),H(a=>a+1)},as=""!==I.trim()||""!==K,at=w?.find(a=>a.ref===U)??null,au=(b,c)=>{ai.current=c,ak.current=!0,o.replace(`/agents/${encodeURIComponent(a)}/sessions?session=${encodeURIComponent(b.ref)}`,{scroll:!1})},av=()=>{ah.current=W?.returnTo??null,X(null)};return(0,b.jsxs)("div",{className:"agent-sessions-page","data-agent-sessions-page":!0,children:[(0,b.jsxs)("header",{className:"agent-sessions-head",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{className:"agent-eyebrow",children:"Sessions"}),(0,b.jsxs)("h2",{children:["Review ",h,"’s work"]}),(0,b.jsx)("p",{children:"Scan runtime sessions, then open one for actions and operational detail."})]}),(0,b.jsxs)("div",{className:"agent-sessions-sync",children:[(0,b.jsxs)("span",{children:["Last synced ",(0,f.formatSyncRelativeTime)(y?.synced_at??null)]}),(0,b.jsx)("button",{type:"button",className:"sessions-filter-btn",onClick:()=>{aq()},disabled:A,children:A?"Refreshing…":"Refresh"})]})]}),(0,b.jsxs)("div",{className:"sessions-filter",role:"group","aria-label":"Filter sessions",children:[(0,b.jsx)("div",{className:"sessions-status-filter",role:"group","aria-label":"Show sessions",children:f.SESSION_FILTER_OPTIONS.map(a=>(0,b.jsx)("button",{type:"button",className:"sessions-filter-btn","aria-pressed":u===a.value,onClick:()=>{u!==a.value&&ar(a.value)},children:a.label},a.value))}),(0,b.jsx)("input",{type:"search",className:"sessions-search","aria-label":"Search sessions by title",placeholder:"Search by title",value:I,onChange:a=>J(a.target.value)}),(0,b.jsxs)("select",{className:"sessions-workspace","aria-label":"Filter sessions by workspace",value:K,onChange:a=>L(a.target.value),children:[(0,b.jsx)("option",{value:"",children:"All workspaces"}),(0,f.workspaceOptions)(M).map(a=>(0,b.jsx)("option",{value:a.value,title:a.value,children:a.label},a.value))]}),(0,b.jsx)("span",{className:"manage-count","aria-live":"polite",children:w?`${w.length} shown`:""})]}),(0,b.jsx)("div",{className:"exchange-started",role:"status",children:C}),(0,b.jsx)("div",{className:"exchange-started",role:"status",children:Y?(0,b.jsxs)(b.Fragment,{children:[Y.text," ",Y.id?(0,b.jsx)(c.default,{className:"session-link",href:(0,i.detailsHref)(Y.id),children:"View in Exchanges"}):null]}):null}),(0,b.jsxs)("div",{className:`sessions-review${at?" has-detail":""}`,inert:!!W,children:[(0,b.jsxs)("section",{className:"sessions-list-pane","aria-labelledby":"sessions-list-title",children:[(0,b.jsx)("h3",{id:"sessions-list-title",className:"session-sr",children:"Session list"}),E?(0,b.jsxs)("div",{className:"sessions-state",role:"alert",children:[(0,b.jsx)("p",{className:"delete-error",children:E}),(0,b.jsx)("button",{type:"button",className:"pin-word",onClick:()=>ar(),children:"Retry"})]}):null,w||E?null:(0,b.jsx)("p",{className:"delete-copy sessions-state",role:"status",children:"Loading sessions…"}),w?(0,b.jsxs)("ul",{className:"sessions-list","aria-label":`Sessions for ${h}`,children:[0===w.length?(0,b.jsx)("li",{className:"delete-copy sessions-state",children:as?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("p",{children:(0,f.noMatchingSessionsCopy)(I,K||null)}),(0,b.jsx)("button",{type:"button",className:"pin-word",onClick:()=>{J(""),L("")},children:"Clear search"})]}):(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("p",{children:(0,f.emptySessionsCopy)(u,h,y,am)}),"all"===u&&y?.last_error_code?(0,b.jsx)("button",{type:"button",className:"pin-word",onClick:()=>{aq()},disabled:A,children:A?"Retrying…":"Retry"}):null,"all"===u&&!y?.last_error_code&&(y?.out_of_scope_count??0)>0?(0,b.jsx)(c.default,{className:"session-link",href:`/agents/${encodeURIComponent(a)}/config`,children:"Widen the scope in Config"}):null]})}):null,w.map(a=>(0,b.jsx)(r,{row:a,selected:U===a.ref,onSelect:au},a.ref))]}):null,w&&w.length>0&&ao?(0,b.jsx)("div",{className:"sessions-more",children:(0,b.jsx)("button",{type:"button",className:"sessions-filter-btn",onClick:()=>{ap()},disabled:Q,children:Q?"Loading…":"Load more"})}):null]}),(0,b.jsx)("section",{className:"sessions-detail-pane","aria-label":"Session detail",children:at?(0,b.jsx)(s,{row:at,agentId:a,headingRef:aj,origin:m,agents:l,shares:$,sharePolicy:aa,onClose:()=>{ak.current=!1,o.replace(`/agents/${encodeURIComponent(a)}/sessions`,{scroll:!1})},onAction:(a,b)=>{Z(null),X({mode:a,row:at,returnTo:b})},onSharesChanged:()=>ad(a=>a+1)},at.ref):(0,b.jsxs)("div",{className:"sessions-detail-empty",children:[(0,b.jsx)("p",{className:"agent-eyebrow",children:"Session detail"}),(0,b.jsx)("h3",{children:"Select a session"}),(0,b.jsx)("p",{children:"Actions, usage, origin, shares, and debug detail appear here."})]})})]}),W&&m?(0,b.jsx)(j,{mode:W.mode,session:W.row,agents:l,origin:m,onClose:av,onStarted:a=>{Z({id:a,text:"ask"===W.mode?`Asked ${W.row.agent.name}’s session. The answer arrives in ${m.label}.`:"resume"===W.mode?`Resumed work in ${W.row.agent.name}’s session. Progress shows in ${m.label}.`:`Handoff started from ${W.row.agent.name}’s session. Progress shows in ${m.label}.`}),av(),n?.(a)}}):null]})}function r({row:a,selected:c,onSelect:d}){let e=(0,i.sessionRowActions)(a).filter(a=>a.availability.available).length,g=(0,f.workspaceFolderName)(a.context.workspace),h=(0,f.sessionOriginChips)(a),j=(0,f.sessionStateTags)(a);return(0,b.jsx)("li",{className:`session-scan-row is-${a.status}${c?" is-selected":""}`,"data-session-ref":a.ref,children:(0,b.jsxs)("button",{type:"button",className:"session-scan-button","aria-current":c?"true":void 0,onClick:b=>d(a,b.currentTarget),children:[(0,b.jsxs)("span",{className:"session-scan-title-line",children:[(0,b.jsx)("strong",{className:"session-title",children:a.title}),(0,b.jsx)("span",{className:`manage-tag session-status is-${a.status}`,children:(0,f.statusLabel)(a)})]}),(0,b.jsxs)("span",{className:"session-scan-context",children:[(0,b.jsx)("span",{className:"session-activity",children:(0,f.formatSessionDate)(a.last_activity_at)}),g?(0,b.jsx)("span",{className:"session-workspace",title:a.context.workspace??void 0,children:g}):null]}),h.length||j.length?(0,b.jsxs)("span",{className:"session-scan-chips",children:[h.map(a=>(0,b.jsx)("span",{className:"session-origin-chip",children:a},a)),j.map(a=>(0,b.jsx)("span",{className:`manage-tag session-state-tag is-${a.toLowerCase()}`,children:a},a))]}):null,(0,b.jsx)("span",{className:`session-attention${e?" is-actionable":""}`,children:e?`${e} action${1===e?"":"s"} available`:"Review details"})]})})}function s({row:a,agentId:e,headingRef:g,origin:h,agents:j,shares:k,sharePolicy:l,onClose:n,onAction:o,onSharesChanged:p}){let q,[r,t]=(0,d.useState)(null),[v,w]=(0,d.useState)(null),[x,y]=(0,d.useState)(""),[z,A]=(0,d.useState)(null),[B,C]=(0,d.useState)(""),[D,E]=(0,d.useState)(!1),F=`/api/bots/${encodeURIComponent(e)}/sessions/${encodeURIComponent(a.ref)}`,G=(0,i.sessionRowActions)(a),H=G.filter(a=>a.availability.available),I=G.filter(a=>!a.availability.available),J=a.origin.conversation,K=(q=a.origin.conversation)?q.thread_agent_id?`/agents/${encodeURIComponent(q.thread_agent_id)}/conversations`:"group"===q.kind?`/threads/${encodeURIComponent(q.id)}`:null:null,L=(0,f.workRequestLabel)(a),M=(0,f.sessionUsageLine)(a.usage);(0,d.useEffect)(()=>{let a=!1;return fetch(F,{cache:"no-store"}).then(async b=>{let c=await b.json().catch(()=>null);a||(b.ok&&Array.isArray(c?.session?.attempts)?(t(c.session.attempts),w({totals:c.session.usage,samples:Array.isArray(c.session.usage_samples)?c.session.usage_samples:[]})):y("Could not load session details."))}).catch(()=>{a||y("Could not load session details.")}),()=>{a=!0}},[F]);let N=(0,d.useCallback)(async()=>{if(null===z)try{let a=await fetch(`${F}?debug=external_session_id`,{cache:"no-store"}),b=await a.json().catch(()=>null),c=b?.debug?.external_session_id;a.ok&&"string"==typeof c?A(c):C("Not available.")}catch{C("Not available.")}},[F,z]),O=async()=>{if(z)try{await navigator.clipboard.writeText(z),E(!0)}catch{E(!1)}};return(0,b.jsxs)("article",{className:"session-detail","data-session-detail":a.ref,children:[(0,b.jsxs)("div",{className:"session-detail-head",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{className:"agent-eyebrow",children:"Session detail"}),(0,b.jsx)("h3",{ref:g,tabIndex:-1,children:a.title})]}),(0,b.jsx)("button",{type:"button",className:"pin-word session-detail-close",onClick:n,children:"Back to session list"})]}),(0,b.jsxs)("div",{className:"session-detail-tags",children:[(0,b.jsx)("span",{className:`manage-tag session-status is-${a.status}`,children:(0,f.statusLabel)(a)}),(0,f.sessionStateTags)(a).map(a=>(0,b.jsx)("span",{className:`manage-tag session-state-tag is-${a.toLowerCase()}`,children:a},a))]}),(0,b.jsxs)("dl",{className:"session-detail-meta",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Last activity"}),(0,b.jsx)("dd",{children:(0,f.formatSessionDate)(a.last_activity_at)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Started"}),(0,b.jsx)("dd",{children:(0,f.formatSessionDate)(a.created_at)})]}),null!==a.ended_at?(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Ended"}),(0,b.jsx)("dd",{children:(0,f.formatSessionDate)(a.ended_at)})]}):null,(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Runtime"}),(0,b.jsx)("dd",{children:(0,f.runtimeLabel)(a)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Reported usage"}),(0,b.jsxs)("dd",{children:[(0,b.jsx)("span",{className:`session-usage is-${M.quality}`,"aria-hidden":"true",children:M.text}),(0,b.jsx)("span",{className:"session-sr",children:M.label}),M.partial?(0,b.jsx)("span",{className:"manage-tag session-usage-tag",children:"Partial"}):null]})]}),a.context.workspace?(0,b.jsxs)("div",{className:"is-wide",children:[(0,b.jsx)("dt",{children:"Workspace"}),(0,b.jsx)("dd",{children:a.context.workspace})]}):null,(0,b.jsxs)("div",{className:"is-wide",children:[(0,b.jsx)("dt",{children:"Origin"}),(0,b.jsx)("dd",{children:K&&J?(0,b.jsx)(c.default,{className:"session-link",href:K,children:J.label}):J?.label??"Not recorded"})]}),L?(0,b.jsxs)("div",{className:"is-wide",children:[(0,b.jsx)("dt",{children:"Work request"}),(0,b.jsx)("dd",{children:L})]}):null]}),(0,b.jsxs)("section",{className:"session-detail-section","aria-labelledby":`actions-${a.ref}`,children:[(0,b.jsx)("h4",{id:`actions-${a.ref}`,children:"Actions"}),h&&H.length?(0,b.jsx)("div",{className:"session-actions",role:"group","aria-label":`Actions for ${a.title}`,children:H.map(a=>(0,b.jsx)("button",{type:"button",className:"session-action","data-session-action":a.action,"aria-haspopup":"dialog",onClick:b=>o((0,i.sessionDialogMode)(a.action),b.currentTarget),children:a.label},a.action))}):null,!h&&H.length?(0,b.jsx)("p",{className:"session-unavailable",children:"Open this Agent’s Conversation before starting an action."}):null,I.length?(0,b.jsx)("ul",{className:"session-unavailable","aria-label":`Unavailable actions for ${a.title}`,children:I.map(a=>(0,b.jsxs)("li",{children:[(0,b.jsxs)("strong",{children:[a.label,":"]})," ",a.availability.available?"":a.availability.reason]},a.action))}):null]}),(0,b.jsx)("section",{className:"session-detail-section",children:(0,b.jsx)(m,{row:a,shares:k,policy:l,onChanged:p})}),(0,b.jsxs)("section",{className:"session-detail-section","aria-labelledby":`runs-${a.ref}`,children:[(0,b.jsx)("h4",{id:`runs-${a.ref}`,children:"Runs and usage"}),x?(0,b.jsx)("p",{className:"delete-error",role:"alert",children:x}):null,r||x?null:(0,b.jsx)("p",{className:"delete-copy",role:"status",children:"Loading details…"}),r?(0,b.jsxs)("ol",{className:"session-attempts","aria-label":"Runs in this session",children:[0===r.length?(0,b.jsx)("li",{children:"No recorded runs."}):null,r.map(a=>(0,b.jsxs)("li",{children:[(0,f.formatSessionDate)(a.started_at)," · ",(0,f.attemptLabel)(a)]},`${a.request_id}-${a.attempt_number}`))]}):null,v?(0,b.jsx)(u,{totals:v.totals,samples:v.samples}):null]}),(0,b.jsxs)("details",{className:"session-debug session-detail-section",onToggle:a=>{a.currentTarget.open&&N()},children:[(0,b.jsx)("summary",{children:"Local debug: provider session ID"}),(0,b.jsx)("p",{className:"session-debug-note",children:"For local troubleshooting only. Botmancers resumes sessions for you; you never need to copy this."}),B?(0,b.jsx)("p",{className:"delete-error",children:B}):null,z?(0,b.jsxs)("div",{className:"session-debug-value",children:[(0,b.jsx)("code",{children:z}),(0,b.jsx)("button",{type:"button",className:"pin-word",onClick:()=>{O()},children:D?"Copied":"Copy"})]}):null]})]})}let t=["input_tokens","output_tokens","cost_usd"];function u({totals:a,samples:c}){let e=(0,d.useId)();return(0,b.jsxs)("section",{className:"session-usage-detail","aria-labelledby":e,children:[(0,b.jsx)("h5",{id:e,className:"session-usage-head",children:"Reported usage"}),(0,b.jsx)("dl",{className:"session-usage-totals",children:t.map(c=>{let d=(0,f.usageMetricView)(c,a?.[c],!0);return(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:d.name}),(0,b.jsxs)("dd",{children:[(0,b.jsx)("span",{className:`session-usage is-${d.quality}`,"aria-hidden":"true",children:d.text}),(0,b.jsxs)("span",{className:"session-sr",children:[d.label,"."]}),(0,b.jsx)("span",{className:`session-usage-coverage is-${d.quality}`,children:d.coverage})]})]},c)})}),0===c.length?(0,b.jsx)("p",{className:"session-usage-none",children:"No run in this session reported usage."}):(0,b.jsx)("ol",{className:"session-usage-runs","aria-label":"Reported usage by run",children:c.map((a,c)=>{let d=(0,f.usageSampleValues)(a);return(0,b.jsxs)("li",{children:[(0,b.jsxs)("span",{className:"session-usage-run",children:[(0,f.formatSessionDate)(a.observed_at)," · ",(0,f.usageSampleLabel)(a,c)]}),(0,b.jsxs)("span",{className:"session-usage-values",children:[(0,b.jsxs)("span",{className:null===a.input_tokens?"is-unavailable":void 0,children:["In ",d.input]}),(0,b.jsxs)("span",{className:null===a.output_tokens?"is-unavailable":void 0,children:["Out ",d.output]}),(0,b.jsxs)("span",{className:null===a.cost_usd?"is-unavailable":void 0,children:["Cost ",d.cost]})]})]},`${a.observed_at}-${c}`)})})]})}var v=a.i(15722);a.s(["default",0,function(){let{id:a,agents:d,overview:e,loading:f,error:g,notFound:h}=(0,v.useAgentOverview)();return f?(0,b.jsx)("div",{className:"agent-state",role:"status",children:"Loading sessions…"}):h?(0,b.jsxs)("div",{className:"agent-state",children:[(0,b.jsx)("h2",{children:"Agent not found"}),(0,b.jsx)(c.default,{href:"/",children:"Choose an Agent"})]}):g||!e?(0,b.jsxs)("div",{className:"agent-state",role:"alert",children:[(0,b.jsx)("h2",{children:"Sessions unavailable"}),(0,b.jsx)("p",{children:"Botmancers could not load this Agent. Refresh to try again."})]}):(0,b.jsx)(q,{agentId:a,agentName:e.agent.name,agentProvider:e.runtime.agent,agents:d.map(a=>({id:a.id,name:a.name})),origin:e.conversation?{conversationId:e.conversation.id,label:`${e.agent.name} conversation`}:null})}],26847)}];
8
+ ${K}`,ap=null!==O&&S===ao,aq=(0,d.useCallback)(async()=>{if(Q||!w||!O||S!==ao)return;R(!0);let b=ae.current;try{let c=await fetch(p(a,u,I,K,O),{cache:"no-store"}),d=await c.json().catch(()=>null);if(ae.current!==b)return;if(!c.ok||!Array.isArray(d?.sessions))return void F("Could not load more sessions.");let e=d.sessions,f=new Set(w.map(a=>a.ref));x([...w,...e.filter(a=>!f.has(a.ref))]),P("string"==typeof d?.next_cursor?d.next_cursor:null),F("");let g=e.map(a=>a.context.workspace).filter(a=>!!a);g.length&&N(a=>[...new Set([...a,...g])])}catch{ae.current===b&&F("Could not load more sessions.")}finally{R(!1)}},[a,u,I,K,Q,w,O,ao,S]),ar=(0,d.useCallback)(async()=>{if(!A){B(!0),D("");try{let b=await fetch(`/api/bots/${encodeURIComponent(a)}/sessions/sync`,{method:"POST"}),c=await b.json().catch(()=>null);if(409===b.status)D("A sync is already running.");else if(b.ok){let a=Array.isArray(c?.imported)?c.imported.length:0,b=Array.isArray(c?.updated)?c.updated.length:0;D(`Synced: ${a} imported, ${b} updated.`)}else D("Could not sync sessions.")}catch{D("Could not sync sessions.")}finally{B(!1),H(a=>a+1)}}},[a,A]);(0,d.useEffect)(()=>{let b=!1,c=encodeURIComponent(a);return fetch(`/api/bots/${c}/share-policy`,{cache:"no-store"}).then(a=>a.ok?a.json():null).then(a=>{b||ab(a?.policy??null)}).catch(()=>{b||ab(null)}),fetch(`/api/shares?agent_id=${c}&limit=100`,{cache:"no-store"}).then(a=>a.ok?a.json():null).then(a=>{b||_(Array.isArray(a?.shares)?a.shares:[])}).catch(()=>{b||_([])}),()=>{b=!0}},[a,ac]),(0,d.useEffect)(()=>{let a=setInterval(()=>ad(a=>a+1),15e3);return()=>clearInterval(a)},[]),(0,d.useEffect)(()=>{if(W||!ah.current)return;let a=ah.current;ah.current=null,a.isConnected&&a.focus()},[W]);let as=(a=u)=>{x(null),F(""),v(a),H(a=>a+1)},at=""!==I.trim()||""!==K,au=w?.find(a=>a.ref===U)??null,av=(b,c)=>{ai.current=c,ak.current=!0,o.replace(`/agents/${encodeURIComponent(a)}/sessions?session=${encodeURIComponent(b.ref)}`,{scroll:!1})},aw=()=>{ah.current=W?.returnTo??null,X(null)};return(0,b.jsxs)("div",{className:"agent-sessions-page","data-agent-sessions-page":!0,children:[(0,b.jsxs)("header",{className:"agent-sessions-head",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{className:"agent-eyebrow",children:"Sessions"}),(0,b.jsxs)("h2",{children:["Review ",h,"’s work"]}),(0,b.jsx)("p",{children:"Scan runtime sessions, then open one for actions and operational detail."})]}),(0,b.jsxs)("div",{className:"agent-sessions-sync",children:[(0,b.jsxs)("span",{children:["Last synced ",(0,f.formatSyncRelativeTime)(y?.synced_at??null)]}),(0,b.jsx)("button",{type:"button",className:"sessions-filter-btn",onClick:()=>{ar()},disabled:A,children:A?"Refreshing…":"Refresh"})]})]}),(0,b.jsxs)("div",{className:"sessions-filter",role:"group","aria-label":"Filter sessions",children:[(0,b.jsx)("div",{className:"sessions-status-filter",role:"group","aria-label":"Show sessions",children:f.SESSION_FILTER_OPTIONS.map(a=>(0,b.jsx)("button",{type:"button",className:"sessions-filter-btn","aria-pressed":u===a.value,onClick:()=>{u!==a.value&&as(a.value)},children:a.label},a.value))}),(0,b.jsx)("input",{type:"search",className:"sessions-search","aria-label":"Search sessions by title",placeholder:"Search by title",value:I,onChange:a=>J(a.target.value)}),(0,b.jsxs)("select",{className:"sessions-workspace","aria-label":"Filter sessions by workspace",value:K,onChange:a=>L(a.target.value),children:[(0,b.jsx)("option",{value:"",children:"All workspaces"}),(0,f.workspaceOptions)(M).map(a=>(0,b.jsx)("option",{value:a.value,title:a.value,children:a.label},a.value))]}),(0,b.jsx)("span",{className:"manage-count","aria-live":"polite",children:w?`${w.length} shown`:""})]}),(0,b.jsx)("div",{className:"exchange-started",role:"status",children:C}),(0,b.jsx)("div",{className:"exchange-started",role:"status",children:Y?(0,b.jsxs)(b.Fragment,{children:[Y.text," ",Y.id?(0,b.jsx)(c.default,{className:"session-link",href:(0,i.detailsHref)(Y.id),children:"View in Exchanges"}):null]}):null}),(0,b.jsxs)("div",{className:`sessions-review${au?" has-detail":""}`,inert:!!W,children:[(0,b.jsxs)("section",{className:"sessions-list-pane","aria-labelledby":"sessions-list-title",children:[(0,b.jsx)("h3",{id:"sessions-list-title",className:"session-sr",children:"Session list"}),E?(0,b.jsxs)("div",{className:"sessions-state",role:"alert",children:[(0,b.jsx)("p",{className:"delete-error",children:E}),(0,b.jsx)("button",{type:"button",className:"pin-word",onClick:()=>as(),children:"Retry"})]}):null,w||E?null:(0,b.jsx)("p",{className:"delete-copy sessions-state",role:"status",children:"Loading sessions…"}),w?(0,b.jsxs)("ul",{className:"sessions-list","aria-label":`Sessions for ${h}`,children:[0===w.length?(0,b.jsx)("li",{className:"delete-copy sessions-state",children:at?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("p",{children:(0,f.noMatchingSessionsCopy)(I,K||null)}),(0,b.jsx)("button",{type:"button",className:"pin-word",onClick:()=>{J(""),L("")},children:"Clear search"})]}):(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("p",{children:(0,f.emptySessionsCopy)(u,h,y,am)}),"all"===u&&y?.last_error_code?(0,b.jsx)("button",{type:"button",className:"pin-word",onClick:()=>{ar()},disabled:A,children:A?"Retrying…":"Retry"}):null,"all"===u&&!y?.last_error_code&&(y?.out_of_scope_count??0)>0?(0,b.jsx)(c.default,{className:"session-link",href:`/agents/${encodeURIComponent(a)}/config`,children:"Widen the scope in Config"}):null]})}):null,w.map(a=>(0,b.jsx)(r,{row:a,selected:U===a.ref,onSelect:av},a.ref))]}):null,w&&w.length>0&&ap?(0,b.jsx)("div",{className:"sessions-more",children:(0,b.jsx)("button",{type:"button",className:"sessions-filter-btn",onClick:()=>{aq()},disabled:Q,children:Q?"Loading…":"Load more"})}):null]}),(0,b.jsx)("section",{className:"sessions-detail-pane","aria-label":"Session detail",children:au?(0,b.jsx)(s,{row:au,agentId:a,headingRef:aj,origin:m,agents:l,shares:$,sharePolicy:aa,onClose:()=>{ak.current=!1,o.replace(`/agents/${encodeURIComponent(a)}/sessions`,{scroll:!1})},onAction:(a,b)=>{Z(null),X({mode:a,row:au,returnTo:b})},onSharesChanged:()=>ad(a=>a+1)},au.ref):(0,b.jsxs)("div",{className:"sessions-detail-empty",children:[(0,b.jsx)("p",{className:"agent-eyebrow",children:"Session detail"}),(0,b.jsx)("h3",{children:"Select a session"}),(0,b.jsx)("p",{children:"Actions, usage, origin, shares, and debug detail appear here."})]})})]}),W&&m?(0,b.jsx)(j,{mode:W.mode,session:W.row,agents:l,origin:m,onClose:aw,onStarted:a=>{Z({id:a,text:"ask"===W.mode?`Asked ${W.row.agent.name}’s session. The answer arrives in ${m.label}.`:"resume"===W.mode?`Resumed work in ${W.row.agent.name}’s session. Progress shows in ${m.label}.`:`Handoff started from ${W.row.agent.name}’s session. Progress shows in ${m.label}.`}),aw(),n?.(a)}}):null]})}function r({row:a,selected:c,onSelect:d}){let e=(0,i.sessionRowActions)(a).filter(a=>a.availability.available).length,g=(0,f.workspaceFolderName)(a.context.workspace),h=(0,f.sessionOriginChips)(a),j=(0,f.sessionStateTags)(a);return(0,b.jsx)("li",{className:`session-scan-row is-${a.status}${c?" is-selected":""}`,"data-session-ref":a.ref,children:(0,b.jsxs)("button",{type:"button",className:"session-scan-button","aria-current":c?"true":void 0,onClick:b=>d(a,b.currentTarget),children:[(0,b.jsxs)("span",{className:"session-scan-title-line",children:[(0,b.jsx)("strong",{className:"session-title",children:a.title}),(0,b.jsx)("span",{className:`manage-tag session-status is-${a.status}`,children:(0,f.statusLabel)(a)})]}),(0,b.jsxs)("span",{className:"session-scan-context",children:[(0,b.jsx)("span",{className:"session-activity",children:(0,f.formatSessionDate)(a.last_activity_at)}),g?(0,b.jsx)("span",{className:"session-workspace",title:a.context.workspace??void 0,children:g}):null]}),h.length||j.length?(0,b.jsxs)("span",{className:"session-scan-chips",children:[h.map(a=>(0,b.jsx)("span",{className:"session-origin-chip",children:a},a)),j.map(a=>(0,b.jsx)("span",{className:`manage-tag session-state-tag is-${a.toLowerCase()}`,children:a},a))]}):null,(0,b.jsx)("span",{className:`session-attention${e?" is-actionable":""}`,children:e?`${e} action${1===e?"":"s"} available`:"Review details"})]})})}function s({row:a,agentId:e,headingRef:g,origin:h,agents:j,shares:k,sharePolicy:l,onClose:n,onAction:o,onSharesChanged:p}){let q,[r,t]=(0,d.useState)(null),[v,w]=(0,d.useState)(null),[x,y]=(0,d.useState)(""),[z,A]=(0,d.useState)(null),[B,C]=(0,d.useState)(""),[D,E]=(0,d.useState)(!1),F=`/api/bots/${encodeURIComponent(e)}/sessions/${encodeURIComponent(a.ref)}`,G=(0,i.sessionRowActions)(a),H=G.filter(a=>a.availability.available),I=G.filter(a=>!a.availability.available),J=a.origin.conversation,K=(q=a.origin.conversation)?(0,f.sessionConversationHref)(q):null,L=(0,f.workRequestLabel)(a),M=(0,f.sessionUsageLine)(a.usage);(0,d.useEffect)(()=>{let a=!1;return fetch(F,{cache:"no-store"}).then(async b=>{let c=await b.json().catch(()=>null);a||(b.ok&&Array.isArray(c?.session?.attempts)?(t(c.session.attempts),w({totals:c.session.usage,samples:Array.isArray(c.session.usage_samples)?c.session.usage_samples:[]})):y("Could not load session details."))}).catch(()=>{a||y("Could not load session details.")}),()=>{a=!0}},[F]);let N=(0,d.useCallback)(async()=>{if(null===z)try{let a=await fetch(`${F}?debug=external_session_id`,{cache:"no-store"}),b=await a.json().catch(()=>null),c=b?.debug?.external_session_id;a.ok&&"string"==typeof c?A(c):C("Not available.")}catch{C("Not available.")}},[F,z]),O=async()=>{if(z)try{await navigator.clipboard.writeText(z),E(!0)}catch{E(!1)}};return(0,b.jsxs)("article",{className:"session-detail","data-session-detail":a.ref,children:[(0,b.jsxs)("div",{className:"session-detail-head",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{className:"agent-eyebrow",children:"Session detail"}),(0,b.jsx)("h3",{ref:g,tabIndex:-1,children:a.title})]}),(0,b.jsx)("button",{type:"button",className:"pin-word session-detail-close",onClick:n,children:"Back to session list"})]}),(0,b.jsxs)("div",{className:"session-detail-tags",children:[(0,b.jsx)("span",{className:`manage-tag session-status is-${a.status}`,children:(0,f.statusLabel)(a)}),(0,f.sessionStateTags)(a).map(a=>(0,b.jsx)("span",{className:`manage-tag session-state-tag is-${a.toLowerCase()}`,children:a},a))]}),(0,b.jsxs)("dl",{className:"session-detail-meta",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Last activity"}),(0,b.jsx)("dd",{children:(0,f.formatSessionDate)(a.last_activity_at)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Started"}),(0,b.jsx)("dd",{children:(0,f.formatSessionDate)(a.created_at)})]}),null!==a.ended_at?(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Ended"}),(0,b.jsx)("dd",{children:(0,f.formatSessionDate)(a.ended_at)})]}):null,(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Runtime"}),(0,b.jsx)("dd",{children:(0,f.runtimeLabel)(a)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Reported usage"}),(0,b.jsxs)("dd",{children:[(0,b.jsx)("span",{className:`session-usage is-${M.quality}`,"aria-hidden":"true",children:M.text}),(0,b.jsx)("span",{className:"session-sr",children:M.label}),M.partial?(0,b.jsx)("span",{className:"manage-tag session-usage-tag",children:"Partial"}):null]})]}),a.context.workspace?(0,b.jsxs)("div",{className:"is-wide",children:[(0,b.jsx)("dt",{children:"Workspace"}),(0,b.jsx)("dd",{children:a.context.workspace})]}):null,(0,b.jsxs)("div",{className:"is-wide",children:[(0,b.jsx)("dt",{children:"Origin"}),(0,b.jsx)("dd",{children:K&&J?(0,b.jsx)(c.default,{className:"session-link",href:K,children:J.label}):J?.label??"Not recorded"})]}),L?(0,b.jsxs)("div",{className:"is-wide",children:[(0,b.jsx)("dt",{children:"Work request"}),(0,b.jsx)("dd",{children:L})]}):null]}),(0,b.jsxs)("section",{className:"session-detail-section","aria-labelledby":`actions-${a.ref}`,children:[(0,b.jsx)("h4",{id:`actions-${a.ref}`,children:"Actions"}),h&&H.length?(0,b.jsx)("div",{className:"session-actions",role:"group","aria-label":`Actions for ${a.title}`,children:H.map(a=>(0,b.jsx)("button",{type:"button",className:"session-action","data-session-action":a.action,"aria-haspopup":"dialog",onClick:b=>o((0,i.sessionDialogMode)(a.action),b.currentTarget),children:a.label},a.action))}):null,!h&&H.length?(0,b.jsx)("p",{className:"session-unavailable",children:"Open this agent’s Conversation before starting an action."}):null,I.length?(0,b.jsx)("ul",{className:"session-unavailable","aria-label":`Unavailable actions for ${a.title}`,children:I.map(a=>(0,b.jsxs)("li",{children:[(0,b.jsxs)("strong",{children:[a.label,":"]})," ",a.availability.available?"":a.availability.reason]},a.action))}):null]}),(0,b.jsx)("section",{className:"session-detail-section",children:(0,b.jsx)(m,{row:a,shares:k,policy:l,onChanged:p})}),(0,b.jsxs)("section",{className:"session-detail-section","aria-labelledby":`runs-${a.ref}`,children:[(0,b.jsx)("h4",{id:`runs-${a.ref}`,children:"Runs and usage"}),x?(0,b.jsx)("p",{className:"delete-error",role:"alert",children:x}):null,r||x?null:(0,b.jsx)("p",{className:"delete-copy",role:"status",children:"Loading details…"}),r?(0,b.jsxs)("ol",{className:"session-attempts","aria-label":"Runs in this session",children:[0===r.length?(0,b.jsx)("li",{children:"No recorded runs."}):null,r.map(a=>(0,b.jsxs)("li",{children:[(0,f.formatSessionDate)(a.started_at)," · ",(0,f.attemptLabel)(a)]},`${a.request_id}-${a.attempt_number}`))]}):null,v?(0,b.jsx)(u,{totals:v.totals,samples:v.samples}):null]}),(0,b.jsxs)("details",{className:"session-debug session-detail-section",onToggle:a=>{a.currentTarget.open&&N()},children:[(0,b.jsx)("summary",{children:"Local debug: provider session ID"}),(0,b.jsx)("p",{className:"session-debug-note",children:"For local troubleshooting only. Botmancers resumes sessions for you; you never need to copy this."}),B?(0,b.jsx)("p",{className:"delete-error",children:B}):null,z?(0,b.jsxs)("div",{className:"session-debug-value",children:[(0,b.jsx)("code",{children:z}),(0,b.jsx)("button",{type:"button",className:"pin-word",onClick:()=>{O()},children:D?"Copied":"Copy"})]}):null]})]})}let t=["input_tokens","output_tokens","cost_usd"];function u({totals:a,samples:c}){let e=(0,d.useId)();return(0,b.jsxs)("section",{className:"session-usage-detail","aria-labelledby":e,children:[(0,b.jsx)("h5",{id:e,className:"session-usage-head",children:"Reported usage"}),(0,b.jsx)("dl",{className:"session-usage-totals",children:t.map(c=>{let d=(0,f.usageMetricView)(c,a?.[c],!0);return(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:d.name}),(0,b.jsxs)("dd",{children:[(0,b.jsx)("span",{className:`session-usage is-${d.quality}`,"aria-hidden":"true",children:d.text}),(0,b.jsxs)("span",{className:"session-sr",children:[d.label,"."]}),(0,b.jsx)("span",{className:`session-usage-coverage is-${d.quality}`,children:d.coverage})]})]},c)})}),0===c.length?(0,b.jsx)("p",{className:"session-usage-none",children:"No run in this session reported usage."}):(0,b.jsx)("ol",{className:"session-usage-runs","aria-label":"Reported usage by run",children:c.map((a,c)=>{let d=(0,f.usageSampleValues)(a);return(0,b.jsxs)("li",{children:[(0,b.jsxs)("span",{className:"session-usage-run",children:[(0,f.formatSessionDate)(a.observed_at)," · ",(0,f.usageSampleLabel)(a,c)]}),(0,b.jsxs)("span",{className:"session-usage-values",children:[(0,b.jsxs)("span",{className:null===a.input_tokens?"is-unavailable":void 0,children:["In ",d.input]}),(0,b.jsxs)("span",{className:null===a.output_tokens?"is-unavailable":void 0,children:["Out ",d.output]}),(0,b.jsxs)("span",{className:null===a.cost_usd?"is-unavailable":void 0,children:["Cost ",d.cost]})]})]},`${a.observed_at}-${c}`)})})]})}var v=a.i(15722);a.s(["default",0,function(){let{id:a,agents:d,overview:e,loading:f,error:g,notFound:h}=(0,v.useAgentOverview)();return f?(0,b.jsx)("div",{className:"agent-state",role:"status",children:"Loading sessions…"}):h?(0,b.jsxs)("div",{className:"agent-state",children:[(0,b.jsx)("h2",{children:"Agent not found"}),(0,b.jsx)(c.default,{href:"/",children:"Choose an agent"})]}):g||!e?(0,b.jsxs)("div",{className:"agent-state",role:"alert",children:[(0,b.jsx)("h2",{children:"Sessions unavailable"}),(0,b.jsx)("p",{children:"Botmancers could not load this agent. Refresh to try again."})]}):(0,b.jsx)(q,{agentId:a,agentName:e.agent.name,agentProvider:e.runtime.agent,agents:d.map(a=>({id:a.id,name:a.name})),origin:e.conversation?{conversationId:e.conversation.id,label:`${e.agent.name} conversation`}:null})}],26847)}];
9
9
 
10
10
  //# sourceMappingURL=app_agents_%5Bid%5D_sessions_page_tsx_0tfup-2._.js.map
@@ -1,3 +1,3 @@
1
- module.exports=[632,a=>{"use strict";var b=a.i(87924),c=a.i(38246),d=a.i(72131),e=a.i(15722);let f=["disabled","misconfigured","connecting","connected","reconnecting","failed","stopped"],g=["slack_tokens_absent","app_token_missing","bot_token_missing","app_token_invalid","bot_token_invalid","share_config_absent","share_config_invalid","share_config_no_audience","workspace_not_allowlisted","slack_auth_failed","slack_connect_failed"],h={app_token_missing:"Add the Socket Mode app token to the Botmancers core environment, then restart Botmancers.",bot_token_missing:"Add the bot token to the Botmancers core environment, then restart Botmancers.",app_token_invalid:"Replace the Socket Mode app token with a valid value, then restart Botmancers.",bot_token_invalid:"Replace the bot token with a valid value, then restart Botmancers.",share_config_absent:"Add an allowlisted Slack channel in Agent Config, then restart Botmancers.",share_config_invalid:"Repair the session sharing policy in Agent Config, then restart Botmancers.",share_config_no_audience:"Add an allowlisted Slack channel in Agent Config, then restart Botmancers.",workspace_not_allowlisted:"Allowlist a channel from the workspace connected to the Botmancers Slack app, then restart Botmancers."};function i(a){switch(a.state){case"disabled":return{label:"Disabled",summary:"The optional Botmancers Slack relay is off.",guidance:"To use Slack sharing, configure both Slack relay credentials and at least one allowlisted channel, then restart Botmancers.",tone:"quiet"};case"misconfigured":return{label:"Needs configuration",summary:"The Botmancers Slack relay cannot start with its current configuration.",guidance:h[a.reason??"share_config_invalid"]??"Review the Slack relay credentials and sharing allowlist, then restart Botmancers.",tone:"warning"};case"connecting":return{label:"Connecting",summary:"The Botmancers Slack relay is opening its Socket Mode connection.",guidance:"Wait a moment, then refresh. Existing shares remain bounded to their exact sessions.",tone:"working"};case"connected":return{label:"Connected",summary:"The single Botmancers Slack relay is connected.",guidance:"It can post and answer eligible shared-session threads for all Agents on this Botmancers instance.",tone:"good"};case"reconnecting":return{label:"Reconnecting",summary:"The Botmancers Slack relay lost its connection and is reconnecting.",guidance:"Wait and refresh. Pending work is recovered after the connection returns; do not recreate shares just for a reconnect.",tone:"working"};case"failed":return{label:"Failed",summary:"The Botmancers Slack relay could not authenticate or connect.",guidance:"slack_auth_failed"===a.reason?"Check the configured Slack app and bot credentials, then restart Botmancers.":"Check Slack connectivity and the Socket Mode app configuration, then restart Botmancers.",tone:"warning"};case"stopped":return{label:"Stopped",summary:"The Botmancers Slack relay is not running.",guidance:"Start or restart Botmancers. Existing share records remain available for review.",tone:"quiet"}}}let j=[{value:"all",label:"All states"},{value:"active",label:"Live"},{value:"expired",label:"Expired"},{value:"revoked",label:"Revoked"}];var k=a.i(23464);function l({agentId:a,agentName:d,relay:e,policy:f,shares:g,filter:h,nextCursor:i,refreshing:k,loadingMore:q,onFilter:r,onRefresh:s,onLoadMore:t,onSharesChanged:u}){let v=`/agents/${encodeURIComponent(a)}/sessions`,w=`/agents/${encodeURIComponent(a)}/config#session-sharing`;return(0,b.jsxs)("div",{className:"agent-slack","data-agent-slack-page":!0,children:[(0,b.jsxs)("header",{className:"agent-slack-intro",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{className:"agent-eyebrow",children:"Slack"}),(0,b.jsx)("h2",{children:"Relay health and shared sessions"}),(0,b.jsxs)("p",{children:["Botmancers runs one optional Slack relay. ",d," does not have a separate Slack app; below are only the session threads shared for this Agent."]})]}),(0,b.jsx)("button",{type:"button",className:"agent-slack-refresh",onClick:s,disabled:k,children:k?"Refreshing…":"Refresh"})]}),(0,b.jsxs)("section",{className:"agent-slack-relay","aria-labelledby":"relay-heading",children:[(0,b.jsxs)("div",{className:"agent-slack-section-head",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{className:"agent-eyebrow",children:"Botmancers-wide connection"}),(0,b.jsx)("h3",{id:"relay-heading",children:"Slack relay"})]}),"ready"===e.state?(0,b.jsx)(m,{health:e.value}):null]}),"loading"===e.state?(0,b.jsx)("p",{role:"status",children:"Checking the relay…"}):null,"error"===e.state?(0,b.jsxs)("div",{className:"agent-slack-error",role:"alert",children:[(0,b.jsx)("strong",{children:"Relay health unavailable"}),(0,b.jsx)("p",{children:"Botmancers could not read the redacted health status. Refresh to try again."})]}):null,"ready"===e.state?(0,b.jsx)(n,{health:e.value}):null]}),(0,b.jsxs)("section",{className:"agent-slack-policy","aria-labelledby":"policy-heading",children:[(0,b.jsxs)("div",{className:"agent-slack-section-head",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{className:"agent-eyebrow",children:"This Agent"}),(0,b.jsx)("h3",{id:"policy-heading",children:"Sharing readiness"})]}),(0,b.jsx)(c.default,{href:w,children:"Edit in Config"})]}),"loading"===f.state?(0,b.jsx)("p",{role:"status",children:"Checking sharing policy…"}):null,"error"===f.state?(0,b.jsxs)("div",{className:"agent-slack-error",role:"alert",children:[(0,b.jsx)("strong",{children:"Sharing policy unavailable"}),(0,b.jsx)("p",{children:"Refresh, or open Config to review this Agent’s stored policy."})]}):null,"ready"===f.state?(0,b.jsx)(o,{policy:f.value}):null]}),(0,b.jsxs)("section",{className:"agent-slack-shares","aria-labelledby":"shares-heading",children:[(0,b.jsxs)("div",{className:"agent-slack-section-head agent-slack-shares-head",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{className:"agent-eyebrow",children:"This Agent"}),(0,b.jsx)("h3",{id:"shares-heading",children:"Shared session threads"}),(0,b.jsx)("p",{children:"Each share is ask-only and can reach exactly one owning session."})]}),(0,b.jsx)(c.default,{className:"agent-primary-action",href:v,children:"Share a session"})]}),(0,b.jsx)("div",{className:"agent-slack-filters",role:"group","aria-label":"Filter shares by state",children:j.map(a=>(0,b.jsx)("button",{type:"button","aria-pressed":h===a.value,onClick:()=>r(a.value),children:a.label},a.value))}),"loading"===g.state?(0,b.jsx)("p",{className:"agent-slack-empty",role:"status",children:"Loading shared sessions…"}):null,"error"===g.state?(0,b.jsxs)("div",{className:"agent-slack-error",role:"alert",children:[(0,b.jsx)("strong",{children:"Shared sessions unavailable"}),(0,b.jsx)("p",{children:"No partial or stale list is shown. Refresh to try again."})]}):null,"ready"===g.state&&0===g.value.length?(0,b.jsx)("p",{className:"agent-slack-empty",children:"all"===h?`No sessions from ${d} have been shared to Slack yet.`:`No ${j.find(a=>a.value===h)?.label.toLowerCase()} shares for ${d}.`}):null,"ready"===g.state&&g.value.length>0?(0,b.jsx)("ul",{className:"agent-slack-share-list","aria-label":`Slack shares for ${d}`,children:g.value.map(c=>(0,b.jsx)(p,{share:c,agentId:a,onChanged:u},c.share_ref))}):null,"ready"===g.state&&i?(0,b.jsx)("button",{type:"button",className:"agent-slack-more",onClick:t,disabled:q,children:q?"Loading…":"Load more shares"}):null]})]})}function m({health:a}){let c=i(a);return(0,b.jsx)("span",{className:`agent-slack-status is-${c.tone}`,"data-relay-state":a.state,children:c.label})}function n({health:a}){let c=i(a);return(0,b.jsxs)("div",{className:"agent-slack-relay-copy",children:[(0,b.jsx)("p",{children:(0,b.jsx)("strong",{children:c.summary})}),(0,b.jsx)("p",{children:c.guidance}),"connected"===a.state&&a.connections>0?(0,b.jsxs)("p",{className:"agent-muted",children:["Connections opened this run: ",a.connections]}):null]})}function o({policy:a}){let c="loaded"===a.state&&a.audiences.length>0;return(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{children:(0,b.jsx)("strong",{children:c?"Ready to create session shares.":"invalid"===a.state?"The sharing policy needs repair.":"No Slack audience is allowlisted yet."})}),(0,b.jsxs)("p",{className:"agent-muted",children:["Share from a running Agent turn: ",a.agent.share_from_turn?"On":"Off",". Session owners can still share eligible sessions from Sessions."]}),a.audiences.length?(0,b.jsx)("ul",{className:"agent-slack-audiences","aria-label":"Allowed Slack audiences",children:a.audiences.map(a=>(0,b.jsx)("li",{children:(0,k.audienceLabel)(a)},`${a.team_id}:${a.channel_id}`))}):(0,b.jsx)("p",{className:"agent-slack-empty",children:"No allowlisted Slack channels."})]})}function p({share:a,agentId:e,onChanged:f}){let[g,h]=(0,d.useState)(!1),[i,j]=(0,d.useState)(!1),[l,m]=(0,d.useState)(""),n=(0,d.useRef)(null),o=(0,k.shareIsLive)(a),q=`/agents/${encodeURIComponent(e)}/sessions?session=${encodeURIComponent(a.session_ref)}`,r=async()=>{j(!0),m("");try{let b=await fetch(`/api/shares/${encodeURIComponent(a.share_ref)}/revoke`,{method:"POST"}),c=await b.json().catch(()=>null);if(!b.ok)throw Error("string"==typeof c?.error?.message?c.error.message:"The share could not be revoked.");h(!1),f()}catch(a){m(a instanceof Error?a.message:"The share could not be revoked.")}finally{j(!1)}};return(0,b.jsxs)("li",{className:`agent-slack-share is-${a.status}`,"data-share-ref":a.share_ref,"data-share-status":a.status,children:[(0,b.jsxs)("div",{className:"agent-slack-share-summary",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("span",{className:`agent-slack-status is-share-${a.status}`,children:k.SHARE_STATUS_LABELS[a.status]}),(0,b.jsx)("strong",{children:(0,k.audienceLabel)(a.audience)}),(0,b.jsxs)("small",{children:[(0,k.turnsLabel)(a)," · ",(0,k.expiryLabel)(a)]})]}),(0,b.jsx)("span",{className:"agent-slack-detail-hint",children:"Open for details"})]}),(0,b.jsx)("p",{className:"agent-slack-state-note",children:(0,k.shareStatusNote)(a)}),(0,b.jsxs)("details",{className:"agent-slack-details",children:[(0,b.jsx)("summary",{children:"Details"}),(0,b.jsxs)("dl",{className:"agent-slack-share-details",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Owning session"}),(0,b.jsx)("dd",{children:(0,b.jsx)(c.default,{href:q,children:a.session_ref})})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Posted thread"}),(0,b.jsx)("dd",{children:(0,k.threadLabel)(a)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Creation path"}),(0,b.jsx)("dd",{children:"current_session"===a.created_via?"Running Agent turn":"owner"===a.created_by?"Agent Sessions":"Session share API"})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Created by"}),(0,b.jsx)("dd",{children:(0,k.createdByLabel)(a)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Authority"}),(0,b.jsx)("dd",{children:"Ask only · exact session"})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Share reference"}),(0,b.jsx)("dd",{children:(0,b.jsx)("code",{children:a.share_ref})})]})]})]}),(0,b.jsxs)("div",{className:"agent-slack-share-actions",children:[(0,b.jsx)(c.default,{href:q,children:"Open owning session"}),o&&!g?(0,b.jsx)("button",{ref:n,type:"button",className:"agent-slack-revoke","data-share-action":"revoke",onClick:()=>h(!0),children:"Revoke"}):null]}),g?(0,b.jsxs)("div",{className:"agent-slack-confirm",role:"group","aria-label":"Confirm revoke",children:[(0,b.jsx)("p",{children:"Revoke this share? The next Slack question in its thread gets the revoked notice. This can’t be undone."}),(0,b.jsxs)("div",{children:[(0,b.jsx)("button",{type:"button",className:"agent-slack-revoke","data-share-action":"confirm-revoke",disabled:i,onClick:()=>{r()},children:i?"Revoking…":"Revoke share"}),(0,b.jsx)("button",{type:"button",disabled:i,onClick:()=>{h(!1),requestAnimationFrame(()=>n.current?.focus())},children:"Keep it"})]})]}):null,l?(0,b.jsx)("p",{className:"delete-error",role:"alert",children:l}):null]})}a.s(["AgentSlackView",0,l,"default",0,function(){let{id:a,overview:h,loading:i,error:j,notFound:k}=(0,e.useAgentOverview)(),[m,n]=(0,d.useState)({state:"loading"}),[o,p]=(0,d.useState)({state:"loading"}),[q,r]=(0,d.useState)({state:"loading"}),[s,t]=(0,d.useState)("all"),[u,v]=(0,d.useState)(null),[w,x]=(0,d.useState)(!1),[y,z]=(0,d.useState)(!1),[A,B]=(0,d.useState)(0),[C,D]=(0,d.useState)(""),E=(0,d.useRef)(0),F=(0,d.useCallback)((b=null)=>{let c=new URLSearchParams({agent_id:a,limit:String(12)});return"all"!==s&&c.set("state",s),b&&c.set("cursor",b),`/api/shares?${c.toString()}`},[s,a]);(0,d.useEffect)(()=>{let b=!1,c=++E.current;return Promise.allSettled([fetch("/api/health",{cache:"no-store"}).then(async a=>(function(a){if(!a||"object"!=typeof a||!f.includes(a.state))return null;let b=null===a.reason?null:g.includes(a.reason)?a.reason:null;return{state:a.state,reason:b,since:Number.isFinite(a.since)?Number(a.since):0,connections:Number.isInteger(a.connections)&&Number(a.connections)>=0?Number(a.connections):0}})((await a.json().catch(()=>null))?.slack)),fetch(`/api/bots/${encodeURIComponent(a)}/share-policy`,{cache:"no-store"}).then(async a=>{let b=await a.json().catch(()=>null);if(!a.ok||!b?.policy)throw Error("policy");return b.policy}),fetch(F(),{cache:"no-store"}).then(async b=>{let c=await b.json().catch(()=>null);if(!b.ok||!Array.isArray(c?.shares))throw Error("shares");return{shares:c.shares.filter(b=>b.agent.id===a),cursor:"string"==typeof c.next_cursor?c.next_cursor:null}})]).then(([d,e,f])=>{b||c!==E.current||(n("fulfilled"===d.status&&d.value?{state:"ready",value:d.value}:{state:"error"}),p("fulfilled"===e.status?{state:"ready",value:e.value}:{state:"error"}),"fulfilled"===f.status?(r({state:"ready",value:f.value.shares}),v(f.value.cursor)):r({state:"error"}),D(a))}).finally(()=>{b||c!==E.current||z(!1)}),()=>{b=!0}},[a,A,F]);let G=()=>{z(!0),n({state:"loading"}),p({state:"loading"}),r({state:"loading"}),v(null),B(a=>a+1)},H=async()=>{if(u&&!w&&"ready"===q.state){x(!0);try{let b=await fetch(F(u),{cache:"no-store"}),c=await b.json().catch(()=>null);if(!b.ok||!Array.isArray(c?.shares))throw Error("shares");let d=c.shares.filter(b=>b.agent.id===a);r({state:"ready",value:[...q.value,...d]}),v("string"==typeof c.next_cursor?c.next_cursor:null)}catch{r({state:"error"})}finally{x(!1)}}};if(i)return(0,b.jsx)("div",{className:"agent-state",role:"status",children:"Loading Slack operations…"});if(k)return(0,b.jsxs)("div",{className:"agent-state",children:[(0,b.jsx)("h2",{children:"Agent not found"}),(0,b.jsx)(c.default,{href:"/",children:"Choose an Agent"})]});if(j||!h)return(0,b.jsxs)("div",{className:"agent-state",role:"alert",children:[(0,b.jsx)("h2",{children:"Slack page unavailable"}),(0,b.jsx)("p",{children:"Botmancers could not load this Agent."})]});let I=C!==a;return(0,b.jsx)(l,{agentId:a,agentName:h.agent.name,relay:I?{state:"loading"}:m,policy:I?{state:"loading"}:o,shares:I?{state:"loading"}:q,filter:s,nextCursor:u,refreshing:y,loadingMore:w,onFilter:a=>{a!==s&&(r({state:"loading"}),v(null),t(a))},onRefresh:G,onLoadMore:()=>{H()},onSharesChanged:G})}],632)}];
1
+ module.exports=[632,a=>{"use strict";var b=a.i(87924),c=a.i(38246),d=a.i(72131),e=a.i(15722);let f=["disabled","misconfigured","connecting","connected","reconnecting","failed","stopped"],g=["slack_tokens_absent","app_token_missing","bot_token_missing","app_token_invalid","bot_token_invalid","share_config_absent","share_config_invalid","share_config_no_audience","workspace_not_allowlisted","slack_auth_failed","slack_connect_failed"],h={app_token_missing:"Add the Socket Mode app token to the Botmancers core environment, then restart Botmancers.",bot_token_missing:"Add the bot token to the Botmancers core environment, then restart Botmancers.",app_token_invalid:"Replace the Socket Mode app token with a valid value, then restart Botmancers.",bot_token_invalid:"Replace the bot token with a valid value, then restart Botmancers.",share_config_absent:"Add an allowlisted Slack channel in Agent Config, then restart Botmancers.",share_config_invalid:"Repair the session sharing policy in Agent Config, then restart Botmancers.",share_config_no_audience:"Add an allowlisted Slack channel in Agent Config, then restart Botmancers.",workspace_not_allowlisted:"Allowlist a channel from the workspace connected to the Botmancers Slack app, then restart Botmancers."};function i(a){switch(a.state){case"disabled":return{label:"Disabled",summary:"The optional Botmancers Slack relay is off.",guidance:"To use Slack sharing, configure both Slack relay credentials and at least one allowlisted channel, then restart Botmancers.",tone:"quiet"};case"misconfigured":return{label:"Needs configuration",summary:"The Botmancers Slack relay cannot start with its current configuration.",guidance:h[a.reason??"share_config_invalid"]??"Review the Slack relay credentials and sharing allowlist, then restart Botmancers.",tone:"warning"};case"connecting":return{label:"Connecting",summary:"The Botmancers Slack relay is opening its Socket Mode connection.",guidance:"Wait a moment, then refresh. Existing shares remain bounded to their exact sessions.",tone:"working"};case"connected":return{label:"Connected",summary:"The single Botmancers Slack relay is connected.",guidance:"It can post and answer eligible shared-session threads for all agents on this Botmancers instance.",tone:"good"};case"reconnecting":return{label:"Reconnecting",summary:"The Botmancers Slack relay lost its connection and is reconnecting.",guidance:"Wait and refresh. Pending work is recovered after the connection returns; do not recreate shares just for a reconnect.",tone:"working"};case"failed":return{label:"Failed",summary:"The Botmancers Slack relay could not authenticate or connect.",guidance:"slack_auth_failed"===a.reason?"Check the configured Slack app and bot credentials, then restart Botmancers.":"Check Slack connectivity and the Socket Mode app configuration, then restart Botmancers.",tone:"warning"};case"stopped":return{label:"Stopped",summary:"The Botmancers Slack relay is not running.",guidance:"Start or restart Botmancers. Existing share records remain available for review.",tone:"quiet"}}}let j=[{value:"all",label:"All states"},{value:"active",label:"Live"},{value:"expired",label:"Expired"},{value:"revoked",label:"Revoked"}];var k=a.i(23464);function l({agentId:a,agentName:d,relay:e,policy:f,shares:g,filter:h,nextCursor:i,refreshing:k,loadingMore:q,onFilter:r,onRefresh:s,onLoadMore:t,onSharesChanged:u}){let v=`/agents/${encodeURIComponent(a)}/sessions`,w=`/agents/${encodeURIComponent(a)}/config#session-sharing`;return(0,b.jsxs)("div",{className:"agent-slack","data-agent-slack-page":!0,children:[(0,b.jsxs)("header",{className:"agent-slack-intro",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{className:"agent-eyebrow",children:"Slack"}),(0,b.jsx)("h2",{children:"Relay health and shared sessions"}),(0,b.jsxs)("p",{children:["Botmancers runs one optional Slack relay. ",d," does not have a separate Slack app; below are only the session threads shared for this agent."]})]}),(0,b.jsx)("button",{type:"button",className:"agent-slack-refresh",onClick:s,disabled:k,children:k?"Refreshing…":"Refresh"})]}),(0,b.jsxs)("section",{className:"agent-slack-relay","aria-labelledby":"relay-heading",children:[(0,b.jsxs)("div",{className:"agent-slack-section-head",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{className:"agent-eyebrow",children:"Botmancers-wide connection"}),(0,b.jsx)("h3",{id:"relay-heading",children:"Slack relay"})]}),"ready"===e.state?(0,b.jsx)(m,{health:e.value}):null]}),"loading"===e.state?(0,b.jsx)("p",{role:"status",children:"Checking the relay…"}):null,"error"===e.state?(0,b.jsxs)("div",{className:"agent-slack-error",role:"alert",children:[(0,b.jsx)("strong",{children:"Relay health unavailable"}),(0,b.jsx)("p",{children:"Botmancers could not read the redacted health status. Refresh to try again."})]}):null,"ready"===e.state?(0,b.jsx)(n,{health:e.value}):null]}),(0,b.jsxs)("section",{className:"agent-slack-policy","aria-labelledby":"policy-heading",children:[(0,b.jsxs)("div",{className:"agent-slack-section-head",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{className:"agent-eyebrow",children:"This agent"}),(0,b.jsx)("h3",{id:"policy-heading",children:"Sharing readiness"})]}),(0,b.jsx)(c.default,{href:w,children:"Edit in Config"})]}),"loading"===f.state?(0,b.jsx)("p",{role:"status",children:"Checking sharing policy…"}):null,"error"===f.state?(0,b.jsxs)("div",{className:"agent-slack-error",role:"alert",children:[(0,b.jsx)("strong",{children:"Sharing policy unavailable"}),(0,b.jsx)("p",{children:"Refresh, or open Config to review this agent’s stored policy."})]}):null,"ready"===f.state?(0,b.jsx)(o,{policy:f.value}):null]}),(0,b.jsxs)("section",{className:"agent-slack-shares","aria-labelledby":"shares-heading",children:[(0,b.jsxs)("div",{className:"agent-slack-section-head agent-slack-shares-head",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{className:"agent-eyebrow",children:"This agent"}),(0,b.jsx)("h3",{id:"shares-heading",children:"Shared session threads"}),(0,b.jsx)("p",{children:"Each share is ask-only and can reach exactly one owning session."})]}),(0,b.jsx)(c.default,{className:"agent-primary-action",href:v,children:"Share a session"})]}),(0,b.jsx)("div",{className:"agent-slack-filters",role:"group","aria-label":"Filter shares by state",children:j.map(a=>(0,b.jsx)("button",{type:"button","aria-pressed":h===a.value,onClick:()=>r(a.value),children:a.label},a.value))}),"loading"===g.state?(0,b.jsx)("p",{className:"agent-slack-empty",role:"status",children:"Loading shared sessions…"}):null,"error"===g.state?(0,b.jsxs)("div",{className:"agent-slack-error",role:"alert",children:[(0,b.jsx)("strong",{children:"Shared sessions unavailable"}),(0,b.jsx)("p",{children:"No partial or stale list is shown. Refresh to try again."})]}):null,"ready"===g.state&&0===g.value.length?(0,b.jsx)("p",{className:"agent-slack-empty",children:"all"===h?`No sessions from ${d} have been shared to Slack yet.`:`No ${j.find(a=>a.value===h)?.label.toLowerCase()} shares for ${d}.`}):null,"ready"===g.state&&g.value.length>0?(0,b.jsx)("ul",{className:"agent-slack-share-list","aria-label":`Slack shares for ${d}`,children:g.value.map(c=>(0,b.jsx)(p,{share:c,agentId:a,onChanged:u},c.share_ref))}):null,"ready"===g.state&&i?(0,b.jsx)("button",{type:"button",className:"agent-slack-more",onClick:t,disabled:q,children:q?"Loading…":"Load more shares"}):null]})]})}function m({health:a}){let c=i(a);return(0,b.jsx)("span",{className:`agent-slack-status is-${c.tone}`,"data-relay-state":a.state,children:c.label})}function n({health:a}){let c=i(a);return(0,b.jsxs)("div",{className:"agent-slack-relay-copy",children:[(0,b.jsx)("p",{children:(0,b.jsx)("strong",{children:c.summary})}),(0,b.jsx)("p",{children:c.guidance}),"connected"===a.state&&a.connections>0?(0,b.jsxs)("p",{className:"agent-muted",children:["Connections opened this run: ",a.connections]}):null]})}function o({policy:a}){let c="loaded"===a.state&&a.audiences.length>0;return(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{children:(0,b.jsx)("strong",{children:c?"Ready to create session shares.":"invalid"===a.state?"The sharing policy needs repair.":"No Slack audience is allowlisted yet."})}),(0,b.jsxs)("p",{className:"agent-muted",children:["Share from a running agent turn: ",a.agent.share_from_turn?"On":"Off",". Session owners can still share eligible sessions from Sessions."]}),a.audiences.length?(0,b.jsx)("ul",{className:"agent-slack-audiences","aria-label":"Allowed Slack audiences",children:a.audiences.map(a=>(0,b.jsx)("li",{children:(0,k.audienceLabel)(a)},`${a.team_id}:${a.channel_id}`))}):(0,b.jsx)("p",{className:"agent-slack-empty",children:"No allowlisted Slack channels."})]})}function p({share:a,agentId:e,onChanged:f}){let[g,h]=(0,d.useState)(!1),[i,j]=(0,d.useState)(!1),[l,m]=(0,d.useState)(""),n=(0,d.useRef)(null),o=(0,k.shareIsLive)(a),q=`/agents/${encodeURIComponent(e)}/sessions?session=${encodeURIComponent(a.session_ref)}`,r=async()=>{j(!0),m("");try{let b=await fetch(`/api/shares/${encodeURIComponent(a.share_ref)}/revoke`,{method:"POST"}),c=await b.json().catch(()=>null);if(!b.ok)throw Error("string"==typeof c?.error?.message?c.error.message:"The share could not be revoked.");h(!1),f()}catch(a){m(a instanceof Error?a.message:"The share could not be revoked.")}finally{j(!1)}};return(0,b.jsxs)("li",{className:`agent-slack-share is-${a.status}`,"data-share-ref":a.share_ref,"data-share-status":a.status,children:[(0,b.jsxs)("div",{className:"agent-slack-share-summary",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("span",{className:`agent-slack-status is-share-${a.status}`,children:k.SHARE_STATUS_LABELS[a.status]}),(0,b.jsx)("strong",{children:(0,k.audienceLabel)(a.audience)}),(0,b.jsxs)("small",{children:[(0,k.turnsLabel)(a)," · ",(0,k.expiryLabel)(a)]})]}),(0,b.jsx)("span",{className:"agent-slack-detail-hint",children:"Open for details"})]}),(0,b.jsx)("p",{className:"agent-slack-state-note",children:(0,k.shareStatusNote)(a)}),(0,b.jsxs)("details",{className:"agent-slack-details",children:[(0,b.jsx)("summary",{children:"Details"}),(0,b.jsxs)("dl",{className:"agent-slack-share-details",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Owning session"}),(0,b.jsx)("dd",{children:(0,b.jsx)(c.default,{href:q,children:a.session_ref})})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Posted thread"}),(0,b.jsx)("dd",{children:(0,k.threadLabel)(a)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Creation path"}),(0,b.jsx)("dd",{children:"current_session"===a.created_via?"Running agent turn":"owner"===a.created_by?"Sessions":"Session share API"})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Created by"}),(0,b.jsx)("dd",{children:(0,k.createdByLabel)(a)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Authority"}),(0,b.jsx)("dd",{children:"Ask only · exact session"})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Share reference"}),(0,b.jsx)("dd",{children:(0,b.jsx)("code",{children:a.share_ref})})]})]})]}),(0,b.jsxs)("div",{className:"agent-slack-share-actions",children:[(0,b.jsx)(c.default,{href:q,children:"Open owning session"}),o&&!g?(0,b.jsx)("button",{ref:n,type:"button",className:"agent-slack-revoke","data-share-action":"revoke",onClick:()=>h(!0),children:"Revoke"}):null]}),g?(0,b.jsxs)("div",{className:"agent-slack-confirm",role:"group","aria-label":"Confirm revoke",children:[(0,b.jsx)("p",{children:"Revoke this share? The next Slack question in its thread gets the revoked notice. This can’t be undone."}),(0,b.jsxs)("div",{children:[(0,b.jsx)("button",{type:"button",className:"agent-slack-revoke","data-share-action":"confirm-revoke",disabled:i,onClick:()=>{r()},children:i?"Revoking…":"Revoke share"}),(0,b.jsx)("button",{type:"button",disabled:i,onClick:()=>{h(!1),requestAnimationFrame(()=>n.current?.focus())},children:"Keep it"})]})]}):null,l?(0,b.jsx)("p",{className:"delete-error",role:"alert",children:l}):null]})}a.s(["AgentSlackView",0,l,"default",0,function(){let{id:a,overview:h,loading:i,error:j,notFound:k}=(0,e.useAgentOverview)(),[m,n]=(0,d.useState)({state:"loading"}),[o,p]=(0,d.useState)({state:"loading"}),[q,r]=(0,d.useState)({state:"loading"}),[s,t]=(0,d.useState)("all"),[u,v]=(0,d.useState)(null),[w,x]=(0,d.useState)(!1),[y,z]=(0,d.useState)(!1),[A,B]=(0,d.useState)(0),[C,D]=(0,d.useState)(""),E=(0,d.useRef)(0),F=(0,d.useCallback)((b=null)=>{let c=new URLSearchParams({agent_id:a,limit:String(12)});return"all"!==s&&c.set("state",s),b&&c.set("cursor",b),`/api/shares?${c.toString()}`},[s,a]);(0,d.useEffect)(()=>{let b=!1,c=++E.current;return Promise.allSettled([fetch("/api/health",{cache:"no-store"}).then(async a=>(function(a){if(!a||"object"!=typeof a||!f.includes(a.state))return null;let b=null===a.reason?null:g.includes(a.reason)?a.reason:null;return{state:a.state,reason:b,since:Number.isFinite(a.since)?Number(a.since):0,connections:Number.isInteger(a.connections)&&Number(a.connections)>=0?Number(a.connections):0}})((await a.json().catch(()=>null))?.slack)),fetch(`/api/bots/${encodeURIComponent(a)}/share-policy`,{cache:"no-store"}).then(async a=>{let b=await a.json().catch(()=>null);if(!a.ok||!b?.policy)throw Error("policy");return b.policy}),fetch(F(),{cache:"no-store"}).then(async b=>{let c=await b.json().catch(()=>null);if(!b.ok||!Array.isArray(c?.shares))throw Error("shares");return{shares:c.shares.filter(b=>b.agent.id===a),cursor:"string"==typeof c.next_cursor?c.next_cursor:null}})]).then(([d,e,f])=>{b||c!==E.current||(n("fulfilled"===d.status&&d.value?{state:"ready",value:d.value}:{state:"error"}),p("fulfilled"===e.status?{state:"ready",value:e.value}:{state:"error"}),"fulfilled"===f.status?(r({state:"ready",value:f.value.shares}),v(f.value.cursor)):r({state:"error"}),D(a))}).finally(()=>{b||c!==E.current||z(!1)}),()=>{b=!0}},[a,A,F]);let G=()=>{z(!0),n({state:"loading"}),p({state:"loading"}),r({state:"loading"}),v(null),B(a=>a+1)},H=async()=>{if(u&&!w&&"ready"===q.state){x(!0);try{let b=await fetch(F(u),{cache:"no-store"}),c=await b.json().catch(()=>null);if(!b.ok||!Array.isArray(c?.shares))throw Error("shares");let d=c.shares.filter(b=>b.agent.id===a);r({state:"ready",value:[...q.value,...d]}),v("string"==typeof c.next_cursor?c.next_cursor:null)}catch{r({state:"error"})}finally{x(!1)}}};if(i)return(0,b.jsx)("div",{className:"agent-state",role:"status",children:"Loading Slack operations…"});if(k)return(0,b.jsxs)("div",{className:"agent-state",children:[(0,b.jsx)("h2",{children:"Agent not found"}),(0,b.jsx)(c.default,{href:"/",children:"Choose an agent"})]});if(j||!h)return(0,b.jsxs)("div",{className:"agent-state",role:"alert",children:[(0,b.jsx)("h2",{children:"Slack page unavailable"}),(0,b.jsx)("p",{children:"Botmancers could not load this agent."})]});let I=C!==a;return(0,b.jsx)(l,{agentId:a,agentName:h.agent.name,relay:I?{state:"loading"}:m,policy:I?{state:"loading"}:o,shares:I?{state:"loading"}:q,filter:s,nextCursor:u,refreshing:y,loadingMore:w,onFilter:a=>{a!==s&&(r({state:"loading"}),v(null),t(a))},onRefresh:G,onLoadMore:()=>{H()},onSharesChanged:G})}],632)}];
2
2
 
3
3
  //# sourceMappingURL=app_agents_%5Bid%5D_slack_AgentSlackPage_tsx_20njhs1._.js.map
@@ -1,3 +1,3 @@
1
- module.exports=[60350,a=>{"use strict";var b=a.i(87924),c=a.i(72131),d=a.i(38246),e=a.i(71987),f=a.i(50944),g=a.i(15752),h=a.i(36391),i=a.i(10014),j=a.i(45559),k=a.i(20851),l=a.i(1160),m=a.i(22855),n=a.i(79202),o=a.i(80219),p=a.i(60193),q=a.i(35832);function r(a){return String(a).padStart(2,"0")}function s(a){let b=new Date(a);return`${b.getFullYear()}-${r(b.getMonth()+1)}-${r(b.getDate())} ${r(b.getHours())}:${r(b.getMinutes())}`}function t({onClose:a,onDeleted:d}){let e=(0,c.useId)(),[f,g]=(0,c.useState)(null),[h,i]=(0,c.useState)(""),[j,l]=(0,c.useState)(""),[m,n]=(0,c.useState)([]),[o,r]=(0,c.useState)(!1),u=(0,c.useRef)(null),v=(0,c.useRef)(null),w=(0,c.useRef)(null);(0,c.useEffect)(()=>{let a=!1;return fetch("/api/bots/manage",{cache:"no-store"}).then(async b=>{let c=await b.json().catch(()=>null);if(!a){if(!b.ok||!Array.isArray(c))return void i("string"==typeof c?.error?c.error:"Could not load agents.");g(c)}}).catch(()=>{a||i("Could not load agents.")}),u.current?.focus(),()=>{a=!0}},[]);let x=j.trim().toLowerCase(),y=(f??[]).filter(a=>a.name.toLowerCase().includes(x)),z=y.filter(a=>!a.blocked);return(0,c.useEffect)(()=>{if(o)return;let b=b=>{"Escape"===b.key&&a()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[o,a]),(0,b.jsxs)("div",{className:"modal-scrim manage-scrim",children:[(0,b.jsxs)("div",{ref:w,className:"manage-card",role:"dialog","aria-modal":"true","aria-labelledby":e,onKeyDown:a=>{if("Tab"!==a.key||!w.current)return;let b=Array.from(w.current.querySelectorAll("button:not(:disabled), input:not(:disabled)"));if(0===b.length)return;let c=b[0],d=b[b.length-1];a.shiftKey&&document.activeElement===c?(a.preventDefault(),d.focus()):a.shiftKey||document.activeElement!==d||(a.preventDefault(),c.focus())},children:[(0,b.jsxs)("div",{className:"manage-head",children:[(0,b.jsx)("h2",{id:e,className:"delete-title",children:"Manage agents"}),(0,b.jsx)("button",{type:"button",className:"cancel-btn",onClick:a,children:"Close"})]}),(0,b.jsx)("label",{className:"manage-search-label",htmlFor:`${e}-search`,children:"Filter by name"}),(0,b.jsx)("input",{id:`${e}-search`,ref:u,className:"manage-search",type:"search",value:j,onChange:a=>l(a.target.value),placeholder:"Name contains…"}),(0,b.jsxs)("div",{className:"manage-tools",children:[(0,b.jsx)("button",{type:"button",className:"pin-word",onClick:()=>{n(a=>Array.from(new Set([...a,...z.map(a=>a.id)])))},disabled:0===z.length,children:"Select all shown"}),(0,b.jsx)("button",{type:"button",className:"pin-word",onClick:()=>{n([]),u.current?.focus()},disabled:0===m.length,children:"Clear selection"}),(0,b.jsxs)("span",{className:"manage-count","aria-live":"polite",children:[m.length," selected · ",y.length," shown of ",f?.length??0]})]}),h?(0,b.jsx)("p",{className:"delete-error",role:"alert",children:h}):null,f||h?null:(0,b.jsx)("p",{className:"delete-copy",children:"Loading agents…"}),f?(0,b.jsxs)("ul",{className:"manage-list","aria-label":"Agents",children:[0===y.length?(0,b.jsx)("li",{className:"delete-copy",children:"No agents match."}):null,y.map(a=>{let c=`${e}-row-${a.id}`,d=(0,k.botConnectionLabel)(a)??"Not set";return(0,b.jsxs)("li",{className:a.blocked?"manage-row is-blocked":"manage-row","data-agent-id":a.id,children:[(0,b.jsx)("input",{id:c,type:"checkbox",checked:m.includes(a.id),disabled:!!a.blocked,onChange:()=>{var b;return b=a.id,void n(a=>a.includes(b)?a.filter(a=>a!==b):[...a,b])},"aria-describedby":a.blocked?`${c}-reason`:void 0}),(0,b.jsxs)("div",{className:"manage-copy",children:[(0,b.jsxs)("label",{htmlFor:c,className:"manage-name",children:[a.name,a.hidden?(0,b.jsx)("span",{className:"manage-tag",children:"Hidden"}):null]}),(0,b.jsxs)("dl",{className:"manage-meta",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Agent"}),(0,b.jsx)("dd",{children:(0,k.botAgentLabel)(a)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Connection"}),(0,b.jsx)("dd",{children:d})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Source"}),(0,b.jsx)("dd",{children:a.source_provider||"Created here"})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Created"}),(0,b.jsx)("dd",{children:s(a.created_at)})]}),a.last_activity?(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Last activity"}),(0,b.jsx)("dd",{children:s(a.last_activity)})]}):null]}),a.blocked?(0,b.jsx)("p",{id:`${c}-reason`,className:"manage-reason",children:(0,q.blockedReasonCopy)(a.blocked)}):null]})]},a.id)})]}):null,(0,b.jsxs)("div",{className:"form-actions manage-actions",children:[(0,b.jsx)("button",{type:"button",className:"cancel-btn",onClick:a,children:"Cancel"}),(0,b.jsxs)("button",{ref:v,type:"button",className:"delete-btn",disabled:0===m.length,onClick:()=>r(!0),children:["Delete selected",m.length>0?` (${m.length})`:""]})]})]}),o?(0,b.jsx)(p.default,{ids:m,onCancel:()=>{r(!1),requestAnimationFrame(()=>v.current?.focus())},onDeleted:d}):null]})}var u=a.i(10209);function v({view:a,agentName:c}){if("loading"===a)return(0,b.jsx)("p",{className:"thread-note",role:"status",children:"Loading messages…"});if("error"===a)return(0,b.jsx)("p",{className:"thread-note thread-note-error",role:"alert",children:"Couldn’t load messages. Trying again…"});if("empty"===a){let a={title:`No messages with ${c} yet.`,hint:"Say something below to start the conversation."};return(0,b.jsxs)("div",{className:"thread-empty","data-thread-empty":"",children:[(0,b.jsx)("p",{className:"thread-empty-title",children:a.title}),(0,b.jsx)("p",{className:"thread-empty-hint",children:a.hint})]})}return null}var w=a.i(25073),x=a.i(59807),y=a.i(4921),z=a.i(11030),A=a.i(27828),B=a.i(65221),C=a.i(22151);function D(a,b,c){let d=b?`/agents/${encodeURIComponent(a)}/conversations/${encodeURIComponent(b)}`:`/agents/${encodeURIComponent(a)}/conversations`;return c?`${d}?exchange=${encodeURIComponent(c)}`:d}function E(a){return!!a&&"chief-of-staff"===a.name.toLowerCase()}function F(a){return E(a)?0:a.pinned?1:2}function G(a){let b=a;for(let a=0;a<2;a++){let a=b.replace(/^\s*\[Message from [^\]]+\]\s*(?:\r?\n)?/,"");if(a===b)break;b=a}return b.replace(/^\s+/,"")}function H(a){let b=a;for(let a=0;a<4;a++){let a=b.replace(/^\s*\[(?:Message from|From) [^\]]+\]\s*(?:\r?\n)?/,"");if(a===b)break;b=a}return b}function I({message:a,conversationId:d,status:e,onDone:f}){let g=(0,j.parseDraft)(H(a.content)),[h,i]=(0,c.useState)(g?.recipient??""),[k,l]=(0,c.useState)(g?.body??""),[m,n]=(0,c.useState)(!1),[o,p]=(0,c.useState)("open"!==e),q=(0,c.useRef)("open"!==e);if(!g)return null;let r="open"!==e||o,s=r?g.recipient:h,t=r?g.body:k,u=async b=>{if(!r&&!q.current&&!m&&("send"!==b||""!==h.trim())){q.current=!0,p(!0),n(!0);try{(await fetch(`/api/conversations/${d}/draft`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messageId:a.id,action:b,recipient:h,body:k})})).ok||(q.current=!1,p(!1))}finally{n(!1),f()}}};return(0,b.jsxs)("div",{className:"draft-card",children:[(0,b.jsx)("div",{className:"draft-title",children:(0,j.draftTitle)(g.channel)}),(0,b.jsx)("input",{type:"text","aria-label":"Recipient",value:s,readOnly:r,disabled:m,onChange:a=>{r||i(a.target.value)}}),(0,b.jsx)("textarea",{rows:3,"aria-label":"Draft body",value:t,readOnly:r,disabled:m,onChange:a=>{r||l(a.target.value)}}),"sent"===e?(0,b.jsx)("span",{className:"draft-mark",children:"Sent"}):null,"discarded"===e?(0,b.jsx)("span",{className:"draft-mark",children:"Discarded"}):null,"discarded"!==e?(0,b.jsx)("button",{type:"button",className:"approve-control",disabled:m,onClick:()=>{u("send")},children:"Send"}):null,"open"===e?(0,b.jsx)("button",{type:"button",className:"approve-control",style:{marginLeft:8},disabled:m,onClick:()=>{u("discard")},children:"Discard"}):null]})}function J({message:a,conversationId:d,status:e,onDone:f}){let g=(0,j.parseApprovalCode)(a.content),[h,i]=(0,c.useState)(!1),k=(0,c.useRef)("pending"!==e);if(!g)return null;let l=async b=>{if(!k.current&&!h){k.current=!0,i(!0);try{(await fetch(`/api/conversations/${d}/${b}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:g,messageId:a.id})})).ok||(k.current=!1)}finally{i(!1),f()}}};return"pending"!==e?(0,b.jsx)("span",{className:"draft-mark",children:"approved"===e?"Approved":"Denied"}):(0,b.jsxs)("span",{className:"draft-mark",children:[(0,b.jsx)("button",{type:"button",className:"approve-control",disabled:h,onClick:()=>{l("approve")},children:"Approve"}),(0,b.jsx)("button",{type:"button",className:"approve-control",style:{marginLeft:8},disabled:h,onClick:()=>{l("deny")},children:"Deny"})]})}function K({names:a}){return 0===a.length?null:(0,b.jsx)(b.Fragment,{children:a.map(a=>(0,b.jsxs)("span",{children:[(0,b.jsx)("br",{}),(0,b.jsxs)("a",{className:"file-control",href:`/api/files/${encodeURIComponent(a)}`,download:a,children:["Download ",a]})]},a))})}function L({anchorRef:a,onClose:d,onCreated:e}){let[f,g]=(0,c.useState)(""),[h,i]=(0,c.useState)(l.DEFAULT_REGISTRATION_FORM),[j,o]=(0,c.useState)(""),[p,q]=(0,c.useState)(!1),[r,s]=(0,c.useState)(!1),[t,v]=(0,c.useState)(null),w=(0,n.useRuntimeConnections)(),[x,y]=(0,c.useState)(null),z=(0,c.useRef)(null),A=(0,c.useRef)(null),D=(0,c.useRef)(null);(0,c.useLayoutEffect)(()=>{let b=()=>{let b=a.current?.getBoundingClientRect();y((0,u.newAgentDialogPlacement)(b?{left:b.left,bottom:b.bottom}:null,{width:window.innerWidth,height:window.innerHeight}))};return b(),window.addEventListener("resize",b),()=>window.removeEventListener("resize",b)},[a]),(0,c.useEffect)(()=>{A.current?.focus()},[]),(0,c.useEffect)(()=>{t&&D.current?.focus()},[t]),(0,c.useEffect)(()=>{let a=a=>{"Escape"===a.key&&(a.stopPropagation(),d())};return document.addEventListener("keydown",a,!0),()=>document.removeEventListener("keydown",a,!0)},[d]);let E=(0,l.registrationFormView)(h,w.state),F=async a=>{let b;if(a.preventDefault(),E.submitDisabled||r)return;if((0,l.hasRegistrationErrors)(E)){q(!0),o("Fix the highlighted fields.");return}o(""),s(!0);try{b=await fetch("/api/bots",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify((0,l.registrationCreateBody)(f,h))})}finally{s(!1)}let c=await b.json().catch(()=>null);if(!b.ok)return void o("string"==typeof c?.error&&c.error?c.error:"Failed to create agent");let d=c?.session_sync;if(!d||"string"!=typeof d.outcome)return void e();let g="string"==typeof c?.agent?(0,C.agentLabel)(c.agent):"Sessions";v({line:(0,B.registrationSessionSyncCopy)(d,g),agentName:"string"==typeof c?.name?c.name:f})};return(0,b.jsx)("div",{className:"modal-scrim new-agent-scrim",onKeyDown:a=>{if("Tab"!==a.key||!z.current)return;let b=Array.from(z.current.querySelectorAll(u.DIALOG_FOCUSABLE)),c=(0,u.wrapFocusTarget)(b,document.activeElement,a.shiftKey);c&&(a.preventDefault(),c.focus())},children:(0,b.jsxs)("div",{ref:z,className:"form-card new-agent-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"new-agent-title",style:x??void 0,children:[(0,b.jsx)("div",{className:"kind-row",children:(0,b.jsx)("h2",{id:"new-agent-title",className:"kind-word new-agent-title",children:"New Agent"})}),t?(0,b.jsxs)("div",{className:"bot-form",children:[(0,b.jsx)("div",{className:"new-agent-body",children:(0,b.jsxs)("p",{role:"status",children:[t.agentName," created. ",t.line]})}),(0,b.jsx)("div",{className:"form-actions",children:(0,b.jsx)("button",{ref:D,type:"button",className:"create-btn",onClick:e,children:"Done"})})]}):(0,b.jsxs)("form",{onSubmit:F,className:"bot-form",children:[(0,b.jsxs)("div",{className:"new-agent-body",children:[(0,b.jsx)("label",{htmlFor:"bot-name",children:"Name"}),(0,b.jsx)("input",{ref:A,id:"bot-name",type:"text",value:f,onChange:a=>g(a.target.value),required:!0}),(0,b.jsx)(m.RegistrationFields,{idPrefix:"bot",variant:"modal",form:h,onChange:a=>{o(""),i(b=>({...b,...a}))},view:E,showErrors:p,connections:w.state,onRetryConnections:w.retry,onAddConnection:w.add,workspacePlaceholder:k.WORKSPACE_TEMPLATE,workspaceHint:k.NEW_AGENT_WORKSPACE_HINT}),j?(0,b.jsx)("p",{className:"form-error",role:"alert",children:j}):null]}),(0,b.jsxs)("div",{className:"form-actions",children:[(0,b.jsx)("button",{type:"button",className:"cancel-btn",onClick:d,children:"Cancel"}),(0,b.jsx)("button",{type:"submit",className:"create-btn",disabled:E.submitDisabled||r,children:r?"Creating…":"Create"})]})]})]})})}a.s(["default",0,function(){var a,l,m,n;let p=(0,f.useRouter)(),[r,s]=(0,c.useState)([]),[u,B]=(0,c.useState)(!1),[C,M]=(0,c.useState)(null),N=(0,c.useRef)(!1),O=(0,c.useRef)(0),[P,Q]=(0,c.useState)([]),[R,S]=(0,c.useState)([]),[T,U]=(0,c.useState)([]),V=(0,c.useRef)(null),[W,X]=(0,c.useState)(null),Y=(0,c.useRef)(null),[Z,$]=(0,c.useState)(""),[_,aa]=(0,c.useState)(""),[ab,ac]=(0,c.useState)(!1),[ad,ae]=(0,c.useState)([]),[af,ag]=(0,c.useState)(""),ah=(0,c.useRef)(null),ai=(0,c.useRef)(null),[aj,ak]=(0,c.useState)(!1),al=(0,c.useRef)(null),[am,an]=(0,c.useState)(!1),[ao,ap]=(0,c.useState)(!1),[aq,ar]=(0,c.useState)({}),as=(0,c.useRef)({}),[at,au]=(0,c.useState)(!1),av=(0,c.useRef)(null),[aw,ax]=(0,c.useState)(""),ay=(0,c.useRef)(null),az=(0,c.useRef)(null),aA=(0,c.useRef)(null),aB=(0,c.useRef)(null),aC=(0,c.useRef)(null),aD=(0,c.useRef)(null),aE=(0,c.useRef)(null),[aF,aG]=(0,c.useState)([]),[aH,aI]=(0,c.useState)({serverNow:0,fetchedAt:0}),[aJ,aK]=(0,c.useState)(()=>Date.now()),aL=(0,c.useRef)({}),aM=(0,c.useRef)(!1),[aN,aO]=(0,c.useState)(!1);(0,c.useEffect)(()=>{aM.current||0===r.length||(aM.current=!0,aO(!0))},[r.length]),(0,c.useEffect)(()=>{let a=(0,o.importedBotId)(window.location.search);if(a)return void window.location.replace((0,o.importedConfigPath)(a));let b=new URLSearchParams(window.location.search);"1"===b.get("new")?(N.current=!0,window.setTimeout(()=>ak(!0),0),window.history.replaceState(null,"","/")):"1"===b.get("manage")&&(N.current=!0,window.setTimeout(()=>au(!0),0),window.history.replaceState(null,"","/"));let c=Number(b.get("deleted"));c>0&&(O.current=c,window.history.replaceState(null,"","/"));let d=b.get("agent");if(d){if(N.current=!0,"1"===b.get("sessions")){let a=b.get("session"),c=a?`/agents/${encodeURIComponent(d)}/sessions?session=${encodeURIComponent(a)}`:`/agents/${encodeURIComponent(d)}/sessions`;window.location.replace(c);return}let a=b.get("exchange");fetch(`/api/conversations?botId=${encodeURIComponent(d)}`,{cache:"no-store"}).then(async a=>a.ok?a.json():null).then(b=>{window.location.replace(D(d,b?.id??null,a))}).catch(()=>window.location.replace(D(d,null,a)))}aS().then(()=>{c>0&&ax((0,q.deletedStatusLine)(c))});let e=setInterval(aS,2e3),f=setInterval(()=>aK(Date.now()),1e3);return()=>{clearInterval(e),clearInterval(f)}},[]),(0,c.useEffect)(()=>{if(N.current||0===r.length||C)return;let a=[...r].filter(a=>!a.hidden).sort((a,b)=>F(a)-F(b))[0]||r[0];N.current=!0;let b=O.current;p.replace(`/agents/${encodeURIComponent(a.id)}${b>0?`?deleted=${b}`:""}`)},[r,C]),(0,c.useEffect)(()=>{if(Y.current=C?.id??null,C)return aT(),aE.current&&clearInterval(aE.current),aE.current=setInterval(aT,2e3),()=>{aE.current&&clearInterval(aE.current)}},[C]);let aP=C?r.find(a=>a.id===C.details.id)??C.details:void 0,aQ=!!C&&E(aP),aR=aQ?function(a){for(let b=a.length-1;b>=0;b--){let c=(0,g.parseRun)(a[b].content);if(c){if("stopped"===c.state)return null;return c.page||c.html||null}}return null}(P):null;async function aS(){let a=await fetch("/api/bots",{cache:"no-store"}),b=await a.json(),c=Date.parse(a.headers.get("date")||"");aI({serverNow:Number.isNaN(c)?Date.now():c,fetchedAt:Date.now()}),Array.isArray(b)&&(s(b),B(!0))}async function aT(){if(!C)return;let a=C.id,b=null,c=!1,d=fetch(`/api/conversations/${a}`).then(async a=>{let b=await a.json();return a.ok&&Array.isArray(b?.events)?b.events:null}).catch(()=>null),e=fetch(`/api/exchanges?conversation=${encodeURIComponent(a)}`,{cache:"no-store"}).then(async a=>{let b=await a.json();return a.ok&&Array.isArray(b?.exchanges)?b.exchanges:null}).catch(()=>null);try{let d=await fetch(`/api/conversations/${a}/messages`);b=await d.json(),c=d.ok&&Array.isArray(b)}catch{c=!1}let f=await d,g=await e;Y.current===a&&(c&&Q(b),f&&S((0,z.wakeNotices)(f)),g&&U(g),X({conversationId:a,status:c?"ready":"error"}))}(0,c.useLayoutEffect)(()=>{let a=aA.current?.parentElement;if(!a)return;let b=aB.current,c=aC.current,d=aD.current;if(aQ&&b&&c&&d){let e=e=>{let f=Math.ceil(b.getBoundingClientRect().height);c.style.height=f+16+e+"px";let g=c.getBoundingClientRect().top-a.getBoundingClientRect().top;d.style.height=Math.max(0,a.clientHeight-g)+"px";let h=b.getBoundingClientRect().top-a.getBoundingClientRect().top+a.scrollTop;a.scrollTop=Math.max(0,h-g)};e(0);let f=c.nextElementSibling,g=b.getBoundingClientRect().bottom,h=f?f.getBoundingClientRect().top:c.getBoundingClientRect().bottom;g>=h&&e(Math.max(16,Math.ceil(g-h)));return}d&&(d.style.height="0px"),c&&(c.style.height=""),a.scrollTop=a.scrollHeight},[P,aQ]),(0,c.useEffect)(()=>{let a=V.current;if(!a)return;let b=document.getElementById(`exchange-${a}`);b&&(V.current=null,b.scrollIntoView({block:"center"}),b.focus({preventScroll:!0}))},[T]),(0,c.useLayoutEffect)(()=>{aG(a=>{if(0===a.length)return a;let b=a.filter(a=>{let b=aL.current[a]??0;return P.some(c=>"bot"===c.sender_type&&c.sender_id===a&&c.created_at>b&&!/^\[(mcp|tool call|tool result)\]/i.test(c.content.trim()))});if(0===b.length)return a;for(let a of b)delete aL.current[a];return a.filter(a=>!b.includes(a))})},[P]);let aU=async a=>{C&&(await fetch(`/api/conversations/${C.id}/messages/${a}/stop`,{method:"POST"}),await aT())},aV=async()=>{C&&(await fetch(`/api/conversations/${C.id}/stop`,{method:"POST"}),await aT())},aW=async(a,b)=>{if(aq[a.id])return void ar(b=>{let c={...b};return delete c[a.id],c});if(as.current[a.id])return;let c=P.findIndex(b=>b.id===a.id),d=r.find(a=>a.name===b),e=P.slice(c+1).find(a=>"bot"===a.sender_type&&(d?a.sender_id===d.id:a.sender_name===b));if(e){as.current[a.id]=!0;try{let b=await fetch(`/api/messages/${a.id}/between?other=${encodeURIComponent(e.id)}`),c=await b.json().catch(()=>null);b.ok&&Array.isArray(c)&&c.length>0&&ar(b=>({...b,[a.id]:c}))}finally{delete as.current[a.id]}}},aX=async()=>{if(!C)return;let a=ay.current?.files?.[0];if(!a)return;let b=await new Promise((b,c)=>{let d=new FileReader;d.onload=()=>b(String(d.result||"")),d.onerror=()=>c(d.error),d.readAsDataURL(a)});if(!b.startsWith("data:image/"))return;let c=await fetch("/api/bots",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:C.details.id,avatar:b})});if(!c.ok)return;let d=await c.json();s(a=>a.map(a=>a.id===d.id?{...a,avatar:d.avatar}:a)),M({...C,details:{...C.details,avatar:d.avatar}})},aY=async a=>{if(!a||!C)return;let b=await new Promise((b,c)=>{let d=new FileReader;d.onload=()=>b(String(d.result||"")),d.onerror=()=>c(d.error),d.readAsDataURL(a)});if(!b.startsWith("data:image/"))return;let c=await fetch("/api/bots",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:C.details.id,avatar:b})});if(!c.ok)return;let d=await c.json();s(a=>a.map(a=>a.id===d.id?{...a,avatar:d.avatar}:a)),M({...C,details:{...C.details,avatar:d.avatar}})},aZ=async()=>{if(!C)return;let a=await fetch("/api/bots",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:C.details.id,avatar:null})});if(!a.ok)return;let b=await a.json();s(a=>a.map(a=>a.id===b.id?{...a,avatar:b.avatar||""}:a)),M({...C,details:{...C.details,avatar:b.avatar||""}})},a$=u&&0===r.length,a_=async a=>{let b=a.map(a=>a.id);au(!1),ax((0,q.deletedStatusLine)(b.length)),requestAnimationFrame(()=>av.current?.focus()),s(a=>a.filter(a=>!b.includes(a.id))),C&&b.includes(C.details.id)&&(M(null),Q([]),S([])),await aS()},a0=ab?r.filter(a=>a.name.toLowerCase().includes(_.toLowerCase())):[],a1=a=>{let b=ah.current,c=b?b.selectionStart:Z.length,d=Z.slice(0,c).lastIndexOf("@");if(d<0)return;$(Z.slice(0,d)+"@"+a+" "+Z.slice(c)),ac(!1);let e=d+a.length+2;requestAnimationFrame(()=>{b?.focus(),b?.setSelectionRange(e,e)})},a2=a=>{if(0===a.length)return;let b=6-ad.length;a.length>b?ag("Up to six attachments."):ag("");let c=a.slice(0,Math.max(b,0));0!==c.length&&ae(a=>[...a,...c.map((b,c)=>({id:b.name+"-"+a.length+"-"+c+"-"+b.size,name:b.name}))])},a3=async()=>{let a=ad.map(a=>a.name),b=Z.trim();if(!b&&0===a.length||!C)return;let c=[b,...a].filter(a=>a.length>0).join("\n"),d=[C.details.id],e=P.reduce((a,b)=>Math.max(a,b.created_at||0),0);for(let a of d)aL.current[a]=e;aG(a=>Array.from(new Set([...a,...d])));let f=[...r].sort((a,b)=>b.name.length-a.name.length).find(a=>(function(a,b){let c="@"+b,d=0;for(;d<a.length;){let b=a.indexOf(c,d);if(b<0)break;let e=a[b+c.length];if(!e||/[\s.,!?:;]/.test(e))return!0;d=b+c.length}return!1})(c,a.name));if(!(await fetch(`/api/conversations/${C.id}/messages`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:c,mentionedBotId:f?.id,idempotencyKey:crypto.randomUUID()})})).ok){for(let a of d)delete aL.current[a];aG(a=>a.filter(a=>!d.includes(a)))}$(""),ae([]),ag(""),ac(!1),aT()},a4=C?(a=C.id,P.length>0?"messages":W&&W.conversationId===a&&"loading"!==W.status?"error"===W.status?"error":"empty":"loading"):"loading",a5=C?(0,b.jsx)(v,{view:a4,agentName:C.details.name}):null,a6=(C?.details.title||"").trim(),a7=C?.details.color,a8=new Set,a9=a=>(0,b.jsx)("div",{className:"msg-status",children:(0,b.jsx)(y.default,{notice:a,onDone:()=>{aT()}})},a.eventId),ba=new Set,bb=a=>(0,b.jsx)("div",{className:"msg-status",children:(0,b.jsx)(A.default,{summary:a,onChanged:()=>{aT()}})},`exchange-${a.id}`),bc=a=>{let b=T.filter(b=>!ba.has(b.id)&&b.created_at<a).sort((a,b)=>a.created_at-b.created_at||(a.id<b.id?-1:1));return b.forEach(a=>ba.add(a.id)),b.map(bb)},bd=()=>{ak(!1),requestAnimationFrame(()=>al.current?.focus())};return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("div",{className:"field",inert:aj,children:[(0,b.jsx)(i.default,{agents:r,activeAgentId:C?.details.id,workingIds:aF,beatClock:aH,now:aJ,status:aw,logoDrop:aN,onAgentsChange:a=>s(a),onNew:()=>ak(!0),onManage:()=>{ax(""),au(!0)},onDeleted:a=>{a_(a)},newButtonRef:al,manageButtonRef:av}),(0,b.jsx)("section",{className:"pane",children:C?(0,b.jsxs)("div",{className:"thread",children:[(0,b.jsxs)("div",{className:"thread-bar",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("button",{type:"button",className:"thread-name",style:a7?{color:a7}:void 0,onClick:()=>{an(!0),ap(!1)},children:C.details.name}),a6?(0,b.jsx)("div",{className:"thread-role",children:a6}):null,(0,b.jsx)("div",{className:"thread-role",children:aF.includes(C.details.id)?"Working":"Not working"}),(0,b.jsx)("div",{className:"thread-role",children:(l=(aP??C.details).last_seen,m=aH.serverNow,n=aH.fetchedAt,l&&m?aJ-n+(m-l)>15e3?"Stopped":"Heartbeat "+new Intl.DateTimeFormat("en-US",{timeZone:"America/Los_Angeles",hour:"numeric",minute:"2-digit",second:"2-digit"}).format(new Date(l)):"Stopped")}),am?(0,b.jsx)("button",{type:"button",className:"avatar-pic",onClick:()=>ap(!0),"aria-label":"Picture",children:C.details.avatar?(0,b.jsx)("img",{src:C.details.avatar,alt:""}):(0,b.jsx)(h.default,{bot:C.details,size:46})}):null]}),(0,b.jsxs)("div",{style:{marginLeft:"auto",display:"flex",gap:16,alignItems:"flex-start"},children:[(0,b.jsx)(d.default,{href:`/agents/${C.details.id}/config`,className:"attach-word",style:{textDecoration:"none"},children:"Config"}),(0,b.jsx)(d.default,{href:`/agents/${encodeURIComponent(C.details.id)}/sessions`,className:"attach-word",style:{textDecoration:"none"},children:"Sessions"}),(0,b.jsx)("button",{type:"button",className:"attach-word",title:"Stop delegated turns in this thread",onClick:()=>{aV()},children:"Stop"})]})]}),ao?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("div",{className:"avatar-step avatar-desk",children:[(0,b.jsx)("span",{className:"kind-word",children:"Agent"}),(0,b.jsx)("button",{type:"button",className:"kind-word",children:"Generate"}),(0,b.jsxs)("label",{className:"kind-word",children:["Upload",(0,b.jsx)("input",{ref:ay,type:"file",accept:"image/*,.svg"})]}),(0,b.jsx)("button",{type:"button",className:"create-btn",onClick:aX,children:"Set avatar"})]}),(0,b.jsxs)("div",{className:"avatar-step avatar-phone",children:[(0,b.jsx)("button",{type:"button",className:"kind-word",onClick:()=>az.current?.click(),children:"Gallery"}),(0,b.jsx)("button",{type:"button",className:"kind-word",children:"Generate"}),(0,b.jsx)("button",{type:"button",className:"kind-word",onClick:aZ,children:"Remove Photo"}),(0,b.jsx)("input",{ref:az,type:"file",accept:"image/*,.svg",onChange:a=>{let b=a.target.files?.[0];a.target.value="",aY(b)}})]})]}):null,(0,b.jsxs)("div",{className:"messages-wrap",children:[(0,b.jsxs)("div",{className:"messages",children:[aQ?null:a5,P.map(a=>{var d;let e,f=R.filter(b=>!a8.has(b.eventId)&&b.createdAt<a.created_at);f.forEach(a=>a8.add(a.eventId));let h=bc(a.created_at),i="user"===a.sender_type,l=i?null:(0,x.classifyRuntimeFailure)(H(a.content));if(l)return(0,b.jsxs)(c.Fragment,{children:[f.map(a9),h,(0,b.jsx)("div",{className:"msg-status",children:(0,b.jsx)(w.default,{failure:l})})]},a.id);let m=(d=H(a.content),e=[],{text:G(d.replace(/data:image\/[a-zA-Z0-9.+-]+;base64,[A-Za-z0-9+/=\s]+/g,a=>(e.push(a.replace(/\s/g,"")),""))),images:e}),n=m.images.map(a=>(0,b.jsx)("img",{src:a,alt:"",style:{display:"block",width:64,height:64}},a.slice(0,48))),o=i?void 0:C.details.color,p=i?null:(0,g.parseRun)(a.content),q=i||p?null:(0,j.parseDraft)(H(a.content)),r=i||p?null:(0,j.parseApprovalCode)(a.content),s=i||p?[]:(0,j.parseFileNames)(a.content),t=i||p?null:(0,j.parseHandoff)(m.text),u=a.draftStatus??(q?"open":null),v=a.approvalStatus??(r?"pending":null);return(0,b.jsxs)(c.Fragment,{children:[f.map(a9),h,(0,b.jsxs)("div",{className:i?"msg-you":"msg-bot",ref:p&&"running"===p.state?aB:void 0,children:[(0,b.jsx)("div",{className:i?"msg-name msg-name-you":"msg-name",style:o?{color:o}:void 0,children:i?"You":a.sender_name||C.details.name}),p?(0,b.jsxs)("div",{className:"msg-body",children:[(0,g.runLine)(p),"running"===p.state?(0,b.jsxs)(b.Fragment,{children:[" ",(0,b.jsx)("button",{type:"button",className:"attach-word",style:{font:"inherit"},onClick:b=>{b.preventDefault(),b.stopPropagation(),aU(a.id)},children:"Stop"})]}):null]}):q&&u?(0,b.jsx)("div",{className:"msg-body",children:(0,b.jsx)(I,{message:a,conversationId:C.id,status:u,onDone:()=>{aT()}},a.id+u)}):(0,b.jsxs)("div",{className:"msg-body",onClick:t?()=>{aW(a,t)}:void 0,title:t?"Show the replies between this handoff and the reply":void 0,style:t?{cursor:"pointer"}:void 0,children:[function(a,c){let d=String(a??"").split("\n");if(!d.some(a=>null!==(0,k.agentEventDisplay)(a)))return a;let e=[];return d.forEach((a,d)=>{d>0&&e.push((0,b.jsx)("br",{},c+"-br-"+d));let f=(0,k.agentEventDisplay)(a);f?e.push((0,b.jsxs)("span",{className:"agent-event",children:[(0,b.jsx)("span",{className:"agent-event-label",children:f.label}),f.detail?" "+f.detail:""]},c+"-"+d)):e.push((0,b.jsx)("span",{children:a},c+"-"+d))}),e}(m.text,a.id),n,r&&v?(0,b.jsx)(J,{message:a,conversationId:C.id,status:v,onDone:()=>{aT()}},a.id+v):null,(0,b.jsx)(K,{names:s})]}),aq[a.id]?(0,b.jsx)("div",{className:"msg-body",children:aq[a.id].map(a=>(0,b.jsx)("div",{children:(a.sender_name||"Agent")+": "+G(a.content)},a.id))}):null]})]},a.id)}),R.filter(a=>!a8.has(a.eventId)).map(a9),bc(1/0),(0,b.jsx)("div",{ref:aD}),(0,b.jsx)("div",{ref:aA})]}),aQ?(0,b.jsxs)("div",{className:"computer-float",children:[(0,b.jsxs)("div",{className:"computer-top",children:[(0,b.jsxs)("span",{className:"computer-lights","aria-hidden":"true",children:[(0,b.jsx)("span",{className:"computer-light computer-light-red"}),(0,b.jsx)("span",{className:"computer-light computer-light-yellow"}),(0,b.jsx)("span",{className:"computer-light computer-light-green"})]}),(0,b.jsxs)("span",{className:"computer-teach",children:[(0,b.jsxs)("span",{className:"computer-teach-pill",children:[(0,b.jsx)("span",{className:"computer-teach-mark","aria-hidden":"true"}),"Teach a task"]}),(0,b.jsx)("span",{className:"computer-expand","aria-hidden":"true",children:(0,b.jsx)("svg",{viewBox:"0 0 16 16",width:"14",height:"14",children:(0,b.jsx)("path",{d:"M9.2 2.6H13.4V6.8M6.8 13.4H2.6V9.2M13.1 2.9L9.4 6.6M2.9 13.1L6.6 9.4",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]}),(0,b.jsx)("div",{className:"messages"===a4?"computer-band":"computer-band computer-band-note",ref:aC,children:a5}),(0,b.jsxs)("div",{className:"computer-desk",children:[aR?(0,b.jsx)("iframe",{className:"computer-page",sandbox:"",srcDoc:aR,tabIndex:-1}):null,(0,b.jsxs)("div",{className:"computer-dock",children:[(0,b.jsx)("img",{src:"/computer/dock-chrome.png",alt:""}),(0,b.jsx)("img",{src:"/computer/dock-gray.png",alt:""}),(0,b.jsx)("img",{src:"/computer/dock-terminal.png",alt:""})]})]})]}):null]}),(0,b.jsxs)("div",{className:"composer",onPaste:a=>{let b=[],c=a.clipboardData.files;if(c&&c.length>0)b.push(...Array.from(c));else for(let c of Array.from(a.clipboardData.items)){if("file"!==c.kind)continue;let a=c.getAsFile();a&&b.push(a)}0!==b.length&&(a.preventDefault(),a2(b))},children:[ab&&a0.length>0?(0,b.jsx)("div",{className:"mention-list",children:a0.map(a=>(0,b.jsxs)("button",{type:"button",onMouseDown:b=>{b.preventDefault(),a1(a.name)},children:["@",a.name]},a.id))}):null,(0,b.jsxs)("div",{className:"composer-box",children:[af?(0,b.jsx)("p",{className:"attach-error",children:af}):null,ad.length>0?(0,b.jsx)("div",{className:"attach-names",children:ad.map(a=>(0,b.jsx)("span",{children:a.name},a.id))}):null,(0,b.jsx)("textarea",{ref:ah,rows:2,value:Z,onChange:a=>{var b,c;let d,e;$(a.target.value),b=a.target.value,c=a.target.selectionStart,(e=(d=b.slice(0,c)).lastIndexOf("@"))<0||/\s/.test(d.slice(e+1))?ac(!1):(aa(d.slice(e+1)),ac(!0))},onKeyDown:a=>{if("Enter"===a.key&&!a.shiftKey){if(a.preventDefault(),ab&&a0.length>0)return void a1(a0[0].name);a3()}},placeholder:"Say something"})]}),(0,b.jsx)("input",{ref:ai,className:"attach-input",type:"file",multiple:!0,onChange:a=>{a2(Array.from(a.target.files||[])),a.target.value=""}}),(0,b.jsx)("button",{type:"button",className:"attach-word",onClick:()=>ai.current?.click(),children:"Attach"}),(0,b.jsx)("button",{type:"button",className:"send-btn",onClick:a3,children:"Send"})]})]}):a$?(0,b.jsxs)("div",{className:"welcome",children:[(0,b.jsx)(e.default,{className:"welcome-mark",src:"/brand/botmancers-logo-outline-256.png",alt:"Botmancers",width:144,height:144,priority:!0}),(0,b.jsx)("p",{className:"empty-line",children:"Pick someone to talk to."})]}):(0,b.jsx)("p",{className:"empty-line",children:"Pick someone to talk to."})}),at?(0,b.jsx)(t,{onClose:()=>{au(!1),requestAnimationFrame(()=>av.current?.focus())},onDeleted:a=>{a_(a)}}):null]}),aj&&(0,b.jsx)(L,{anchorRef:al,onClose:bd,onCreated:()=>{aS(),bd()}})]})}],60350)}];
1
+ module.exports=[60350,a=>{"use strict";var b=a.i(87924),c=a.i(72131),d=a.i(38246),e=a.i(71987),f=a.i(50944),g=a.i(15752),h=a.i(36391),i=a.i(10014),j=a.i(45559),k=a.i(20851),l=a.i(1160),m=a.i(22855),n=a.i(79202),o=a.i(80219),p=a.i(60193),q=a.i(35832);function r(a){return String(a).padStart(2,"0")}function s(a){let b=new Date(a);return`${b.getFullYear()}-${r(b.getMonth()+1)}-${r(b.getDate())} ${r(b.getHours())}:${r(b.getMinutes())}`}function t({onClose:a,onDeleted:d}){let e=(0,c.useId)(),[f,g]=(0,c.useState)(null),[h,i]=(0,c.useState)(""),[j,l]=(0,c.useState)(""),[m,n]=(0,c.useState)([]),[o,r]=(0,c.useState)(!1),u=(0,c.useRef)(null),v=(0,c.useRef)(null),w=(0,c.useRef)(null);(0,c.useEffect)(()=>{let a=!1;return fetch("/api/bots/manage",{cache:"no-store"}).then(async b=>{let c=await b.json().catch(()=>null);if(!a){if(!b.ok||!Array.isArray(c))return void i("string"==typeof c?.error?c.error:"Could not load agents.");g(c)}}).catch(()=>{a||i("Could not load agents.")}),u.current?.focus(),()=>{a=!0}},[]);let x=j.trim().toLowerCase(),y=(f??[]).filter(a=>a.name.toLowerCase().includes(x)),z=y.filter(a=>!a.blocked);return(0,c.useEffect)(()=>{if(o)return;let b=b=>{"Escape"===b.key&&a()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[o,a]),(0,b.jsxs)("div",{className:"modal-scrim manage-scrim",children:[(0,b.jsxs)("div",{ref:w,className:"manage-card",role:"dialog","aria-modal":"true","aria-labelledby":e,onKeyDown:a=>{if("Tab"!==a.key||!w.current)return;let b=Array.from(w.current.querySelectorAll("button:not(:disabled), input:not(:disabled)"));if(0===b.length)return;let c=b[0],d=b[b.length-1];a.shiftKey&&document.activeElement===c?(a.preventDefault(),d.focus()):a.shiftKey||document.activeElement!==d||(a.preventDefault(),c.focus())},children:[(0,b.jsxs)("div",{className:"manage-head",children:[(0,b.jsx)("h2",{id:e,className:"delete-title",children:"Manage agents"}),(0,b.jsx)("button",{type:"button",className:"cancel-btn",onClick:a,children:"Close"})]}),(0,b.jsx)("label",{className:"manage-search-label",htmlFor:`${e}-search`,children:"Filter by name"}),(0,b.jsx)("input",{id:`${e}-search`,ref:u,className:"manage-search",type:"search",value:j,onChange:a=>l(a.target.value),placeholder:"Name contains…"}),(0,b.jsxs)("div",{className:"manage-tools",children:[(0,b.jsx)("button",{type:"button",className:"pin-word",onClick:()=>{n(a=>Array.from(new Set([...a,...z.map(a=>a.id)])))},disabled:0===z.length,children:"Select all shown"}),(0,b.jsx)("button",{type:"button",className:"pin-word",onClick:()=>{n([]),u.current?.focus()},disabled:0===m.length,children:"Clear selection"}),(0,b.jsxs)("span",{className:"manage-count","aria-live":"polite",children:[m.length," selected · ",y.length," shown of ",f?.length??0]})]}),h?(0,b.jsx)("p",{className:"delete-error",role:"alert",children:h}):null,f||h?null:(0,b.jsx)("p",{className:"delete-copy",children:"Loading agents…"}),f?(0,b.jsxs)("ul",{className:"manage-list","aria-label":"Agents",children:[0===y.length?(0,b.jsx)("li",{className:"delete-copy",children:"No agents match."}):null,y.map(a=>{let c=`${e}-row-${a.id}`,d=(0,k.botConnectionLabel)(a)??"Not set";return(0,b.jsxs)("li",{className:a.blocked?"manage-row is-blocked":"manage-row","data-agent-id":a.id,children:[(0,b.jsx)("input",{id:c,type:"checkbox",checked:m.includes(a.id),disabled:!!a.blocked,onChange:()=>{var b;return b=a.id,void n(a=>a.includes(b)?a.filter(a=>a!==b):[...a,b])},"aria-describedby":a.blocked?`${c}-reason`:void 0}),(0,b.jsxs)("div",{className:"manage-copy",children:[(0,b.jsxs)("label",{htmlFor:c,className:"manage-name",children:[a.name,a.hidden?(0,b.jsx)("span",{className:"manage-tag",children:"Hidden"}):null]}),(0,b.jsxs)("dl",{className:"manage-meta",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Agent"}),(0,b.jsx)("dd",{children:(0,k.botAgentLabel)(a)})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Connection"}),(0,b.jsx)("dd",{children:d})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Source"}),(0,b.jsx)("dd",{children:a.source_provider||"Created here"})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Created"}),(0,b.jsx)("dd",{children:s(a.created_at)})]}),a.last_activity?(0,b.jsxs)("div",{children:[(0,b.jsx)("dt",{children:"Last activity"}),(0,b.jsx)("dd",{children:s(a.last_activity)})]}):null]}),a.blocked?(0,b.jsx)("p",{id:`${c}-reason`,className:"manage-reason",children:(0,q.blockedReasonCopy)(a.blocked)}):null]})]},a.id)})]}):null,(0,b.jsxs)("div",{className:"form-actions manage-actions",children:[(0,b.jsx)("button",{type:"button",className:"cancel-btn",onClick:a,children:"Cancel"}),(0,b.jsxs)("button",{ref:v,type:"button",className:"delete-btn",disabled:0===m.length,onClick:()=>r(!0),children:["Delete selected",m.length>0?` (${m.length})`:""]})]})]}),o?(0,b.jsx)(p.default,{ids:m,onCancel:()=>{r(!1),requestAnimationFrame(()=>v.current?.focus())},onDeleted:d}):null]})}var u=a.i(10209);function v({view:a,agentName:c}){if("loading"===a)return(0,b.jsx)("p",{className:"thread-note",role:"status",children:"Loading messages…"});if("error"===a)return(0,b.jsx)("p",{className:"thread-note thread-note-error",role:"alert",children:"Couldn’t load messages. Trying again…"});if("empty"===a){let a={title:`No messages with ${c} yet.`,hint:"Say something below to start the conversation."};return(0,b.jsxs)("div",{className:"thread-empty","data-thread-empty":"",children:[(0,b.jsx)("p",{className:"thread-empty-title",children:a.title}),(0,b.jsx)("p",{className:"thread-empty-hint",children:a.hint})]})}return null}var w=a.i(25073),x=a.i(59807),y=a.i(4921),z=a.i(11030),A=a.i(27828),B=a.i(65221),C=a.i(22151);function D(a,b,c){let d=b?`/agents/${encodeURIComponent(a)}/conversations/${encodeURIComponent(b)}`:`/agents/${encodeURIComponent(a)}/conversations`;return c?`${d}?exchange=${encodeURIComponent(c)}`:d}function E(a){return!!a&&"chief-of-staff"===a.name.toLowerCase()}function F(a){return E(a)?0:a.pinned?1:2}function G(a){let b=a;for(let a=0;a<2;a++){let a=b.replace(/^\s*\[Message from [^\]]+\]\s*(?:\r?\n)?/,"");if(a===b)break;b=a}return b.replace(/^\s+/,"")}function H(a){let b=a;for(let a=0;a<4;a++){let a=b.replace(/^\s*\[(?:Message from|From) [^\]]+\]\s*(?:\r?\n)?/,"");if(a===b)break;b=a}return b}function I({message:a,conversationId:d,status:e,onDone:f}){let g=(0,j.parseDraft)(H(a.content)),[h,i]=(0,c.useState)(g?.recipient??""),[k,l]=(0,c.useState)(g?.body??""),[m,n]=(0,c.useState)(!1),[o,p]=(0,c.useState)("open"!==e),q=(0,c.useRef)("open"!==e);if(!g)return null;let r="open"!==e||o,s=r?g.recipient:h,t=r?g.body:k,u=async b=>{if(!r&&!q.current&&!m&&("send"!==b||""!==h.trim())){q.current=!0,p(!0),n(!0);try{(await fetch(`/api/conversations/${d}/draft`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messageId:a.id,action:b,recipient:h,body:k})})).ok||(q.current=!1,p(!1))}finally{n(!1),f()}}};return(0,b.jsxs)("div",{className:"draft-card",children:[(0,b.jsx)("div",{className:"draft-title",children:(0,j.draftTitle)(g.channel)}),(0,b.jsx)("input",{type:"text","aria-label":"Recipient",value:s,readOnly:r,disabled:m,onChange:a=>{r||i(a.target.value)}}),(0,b.jsx)("textarea",{rows:3,"aria-label":"Draft body",value:t,readOnly:r,disabled:m,onChange:a=>{r||l(a.target.value)}}),"sent"===e?(0,b.jsx)("span",{className:"draft-mark",children:"Sent"}):null,"discarded"===e?(0,b.jsx)("span",{className:"draft-mark",children:"Discarded"}):null,"discarded"!==e?(0,b.jsx)("button",{type:"button",className:"approve-control",disabled:m,onClick:()=>{u("send")},children:"Send"}):null,"open"===e?(0,b.jsx)("button",{type:"button",className:"approve-control",style:{marginLeft:8},disabled:m,onClick:()=>{u("discard")},children:"Discard"}):null]})}function J({message:a,conversationId:d,status:e,onDone:f}){let g=(0,j.parseApprovalCode)(a.content),[h,i]=(0,c.useState)(!1),k=(0,c.useRef)("pending"!==e);if(!g)return null;let l=async b=>{if(!k.current&&!h){k.current=!0,i(!0);try{(await fetch(`/api/conversations/${d}/${b}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:g,messageId:a.id})})).ok||(k.current=!1)}finally{i(!1),f()}}};return"pending"!==e?(0,b.jsx)("span",{className:"draft-mark",children:"approved"===e?"Approved":"Denied"}):(0,b.jsxs)("span",{className:"draft-mark",children:[(0,b.jsx)("button",{type:"button",className:"approve-control",disabled:h,onClick:()=>{l("approve")},children:"Approve"}),(0,b.jsx)("button",{type:"button",className:"approve-control",style:{marginLeft:8},disabled:h,onClick:()=>{l("deny")},children:"Deny"})]})}function K({names:a}){return 0===a.length?null:(0,b.jsx)(b.Fragment,{children:a.map(a=>(0,b.jsxs)("span",{children:[(0,b.jsx)("br",{}),(0,b.jsxs)("a",{className:"file-control",href:`/api/files/${encodeURIComponent(a)}`,download:a,children:["Download ",a]})]},a))})}function L({anchorRef:a,onClose:d,onCreated:e}){let[f,g]=(0,c.useState)(""),[h,i]=(0,c.useState)(l.DEFAULT_REGISTRATION_FORM),[j,o]=(0,c.useState)(""),[p,q]=(0,c.useState)(!1),[r,s]=(0,c.useState)(!1),[t,v]=(0,c.useState)(null),w=(0,n.useRuntimeConnections)(),[x,y]=(0,c.useState)(null),z=(0,c.useRef)(null),A=(0,c.useRef)(null),D=(0,c.useRef)(null);(0,c.useLayoutEffect)(()=>{let b=()=>{let b=a.current?.getBoundingClientRect();y((0,u.newAgentDialogPlacement)(b?{left:b.left,bottom:b.bottom}:null,{width:window.innerWidth,height:window.innerHeight}))};return b(),window.addEventListener("resize",b),()=>window.removeEventListener("resize",b)},[a]),(0,c.useEffect)(()=>{A.current?.focus()},[]),(0,c.useEffect)(()=>{t&&D.current?.focus()},[t]),(0,c.useEffect)(()=>{let a=a=>{"Escape"===a.key&&(a.stopPropagation(),d())};return document.addEventListener("keydown",a,!0),()=>document.removeEventListener("keydown",a,!0)},[d]);let E=(0,l.registrationFormView)(h,w.state),F=async a=>{let b;if(a.preventDefault(),E.submitDisabled||r)return;if((0,l.hasRegistrationErrors)(E)){q(!0),o("Fix the highlighted fields.");return}o(""),s(!0);try{b=await fetch("/api/bots",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify((0,l.registrationCreateBody)(f,h))})}finally{s(!1)}let c=await b.json().catch(()=>null);if(!b.ok)return void o("string"==typeof c?.error&&c.error?c.error:"Failed to create agent");let d=c?.session_sync;if(!d||"string"!=typeof d.outcome)return void e();let g="string"==typeof c?.agent?(0,C.agentLabel)(c.agent):"Sessions";v({line:(0,B.registrationSessionSyncCopy)(d,g),agentName:"string"==typeof c?.name?c.name:f})};return(0,b.jsx)("div",{className:"modal-scrim new-agent-scrim",onKeyDown:a=>{if("Tab"!==a.key||!z.current)return;let b=Array.from(z.current.querySelectorAll(u.DIALOG_FOCUSABLE)),c=(0,u.wrapFocusTarget)(b,document.activeElement,a.shiftKey);c&&(a.preventDefault(),c.focus())},children:(0,b.jsxs)("div",{ref:z,className:"form-card new-agent-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"new-agent-title",style:x??void 0,children:[(0,b.jsx)("div",{className:"kind-row",children:(0,b.jsx)("h2",{id:"new-agent-title",className:"kind-word new-agent-title",children:"New agent"})}),t?(0,b.jsxs)("div",{className:"bot-form",children:[(0,b.jsx)("div",{className:"new-agent-body",children:(0,b.jsxs)("p",{role:"status",children:[t.agentName," created. ",t.line]})}),(0,b.jsx)("div",{className:"form-actions",children:(0,b.jsx)("button",{ref:D,type:"button",className:"create-btn",onClick:e,children:"Done"})})]}):(0,b.jsxs)("form",{onSubmit:F,className:"bot-form",children:[(0,b.jsxs)("div",{className:"new-agent-body",children:[(0,b.jsx)("label",{htmlFor:"bot-name",children:"Name"}),(0,b.jsx)("input",{ref:A,id:"bot-name",type:"text",value:f,onChange:a=>g(a.target.value),required:!0}),(0,b.jsx)(m.RegistrationFields,{idPrefix:"bot",variant:"modal",form:h,onChange:a=>{o(""),i(b=>({...b,...a}))},view:E,showErrors:p,connections:w.state,onRetryConnections:w.retry,onAddConnection:w.add,workspacePlaceholder:k.WORKSPACE_TEMPLATE,workspaceHint:k.NEW_AGENT_WORKSPACE_HINT}),j?(0,b.jsx)("p",{className:"form-error",role:"alert",children:j}):null]}),(0,b.jsxs)("div",{className:"form-actions",children:[(0,b.jsx)("button",{type:"button",className:"cancel-btn",onClick:d,children:"Cancel"}),(0,b.jsx)("button",{type:"submit",className:"create-btn",disabled:E.submitDisabled||r,children:r?"Creating…":"Create"})]})]})]})})}a.s(["default",0,function(){var a,l,m,n;let p=(0,f.useRouter)(),[r,s]=(0,c.useState)([]),[u,B]=(0,c.useState)(!1),[C,M]=(0,c.useState)(null),N=(0,c.useRef)(!1),O=(0,c.useRef)(0),[P,Q]=(0,c.useState)([]),[R,S]=(0,c.useState)([]),[T,U]=(0,c.useState)([]),V=(0,c.useRef)(null),[W,X]=(0,c.useState)(null),Y=(0,c.useRef)(null),[Z,$]=(0,c.useState)(""),[_,aa]=(0,c.useState)(""),[ab,ac]=(0,c.useState)(!1),[ad,ae]=(0,c.useState)([]),[af,ag]=(0,c.useState)(""),ah=(0,c.useRef)(null),ai=(0,c.useRef)(null),[aj,ak]=(0,c.useState)(!1),al=(0,c.useRef)(null),[am,an]=(0,c.useState)(!1),[ao,ap]=(0,c.useState)(!1),[aq,ar]=(0,c.useState)({}),as=(0,c.useRef)({}),[at,au]=(0,c.useState)(!1),av=(0,c.useRef)(null),[aw,ax]=(0,c.useState)(""),ay=(0,c.useRef)(null),az=(0,c.useRef)(null),aA=(0,c.useRef)(null),aB=(0,c.useRef)(null),aC=(0,c.useRef)(null),aD=(0,c.useRef)(null),aE=(0,c.useRef)(null),[aF,aG]=(0,c.useState)([]),[aH,aI]=(0,c.useState)({serverNow:0,fetchedAt:0}),[aJ,aK]=(0,c.useState)(()=>Date.now()),aL=(0,c.useRef)({}),aM=(0,c.useRef)(!1),[aN,aO]=(0,c.useState)(!1);(0,c.useEffect)(()=>{aM.current||0===r.length||(aM.current=!0,aO(!0))},[r.length]),(0,c.useEffect)(()=>{let a=(0,o.importedBotId)(window.location.search);if(a)return void window.location.replace((0,o.importedConfigPath)(a));let b=new URLSearchParams(window.location.search);"1"===b.get("new")?(N.current=!0,window.setTimeout(()=>ak(!0),0),window.history.replaceState(null,"","/")):"1"===b.get("manage")&&(N.current=!0,window.setTimeout(()=>au(!0),0),window.history.replaceState(null,"","/"));let c=Number(b.get("deleted"));c>0&&(O.current=c,window.history.replaceState(null,"","/"));let d=b.get("agent");if(d){if(N.current=!0,"1"===b.get("sessions")){let a=b.get("session"),c=a?`/agents/${encodeURIComponent(d)}/sessions?session=${encodeURIComponent(a)}`:`/agents/${encodeURIComponent(d)}/sessions`;window.location.replace(c);return}let a=b.get("exchange");fetch(`/api/conversations?botId=${encodeURIComponent(d)}`,{cache:"no-store"}).then(async a=>a.ok?a.json():null).then(b=>{window.location.replace(D(d,b?.id??null,a))}).catch(()=>window.location.replace(D(d,null,a)))}aS().then(()=>{c>0&&ax((0,q.deletedStatusLine)(c))});let e=setInterval(aS,2e3),f=setInterval(()=>aK(Date.now()),1e3);return()=>{clearInterval(e),clearInterval(f)}},[]),(0,c.useEffect)(()=>{if(N.current||0===r.length||C)return;let a=[...r].filter(a=>!a.hidden).sort((a,b)=>F(a)-F(b))[0]||r[0];N.current=!0;let b=O.current;p.replace(`/agents/${encodeURIComponent(a.id)}${b>0?`?deleted=${b}`:""}`)},[r,C]),(0,c.useEffect)(()=>{if(Y.current=C?.id??null,C)return aT(),aE.current&&clearInterval(aE.current),aE.current=setInterval(aT,2e3),()=>{aE.current&&clearInterval(aE.current)}},[C]);let aP=C?r.find(a=>a.id===C.details.id)??C.details:void 0,aQ=!!C&&E(aP),aR=aQ?function(a){for(let b=a.length-1;b>=0;b--){let c=(0,g.parseRun)(a[b].content);if(c){if("stopped"===c.state)return null;return c.page||c.html||null}}return null}(P):null;async function aS(){let a=await fetch("/api/bots",{cache:"no-store"}),b=await a.json(),c=Date.parse(a.headers.get("date")||"");aI({serverNow:Number.isNaN(c)?Date.now():c,fetchedAt:Date.now()}),Array.isArray(b)&&(s(b),B(!0))}async function aT(){if(!C)return;let a=C.id,b=null,c=!1,d=fetch(`/api/conversations/${a}`).then(async a=>{let b=await a.json();return a.ok&&Array.isArray(b?.events)?b.events:null}).catch(()=>null),e=fetch(`/api/exchanges?conversation=${encodeURIComponent(a)}`,{cache:"no-store"}).then(async a=>{let b=await a.json();return a.ok&&Array.isArray(b?.exchanges)?b.exchanges:null}).catch(()=>null);try{let d=await fetch(`/api/conversations/${a}/messages`);b=await d.json(),c=d.ok&&Array.isArray(b)}catch{c=!1}let f=await d,g=await e;Y.current===a&&(c&&Q(b),f&&S((0,z.wakeNotices)(f)),g&&U(g),X({conversationId:a,status:c?"ready":"error"}))}(0,c.useLayoutEffect)(()=>{let a=aA.current?.parentElement;if(!a)return;let b=aB.current,c=aC.current,d=aD.current;if(aQ&&b&&c&&d){let e=e=>{let f=Math.ceil(b.getBoundingClientRect().height);c.style.height=f+16+e+"px";let g=c.getBoundingClientRect().top-a.getBoundingClientRect().top;d.style.height=Math.max(0,a.clientHeight-g)+"px";let h=b.getBoundingClientRect().top-a.getBoundingClientRect().top+a.scrollTop;a.scrollTop=Math.max(0,h-g)};e(0);let f=c.nextElementSibling,g=b.getBoundingClientRect().bottom,h=f?f.getBoundingClientRect().top:c.getBoundingClientRect().bottom;g>=h&&e(Math.max(16,Math.ceil(g-h)));return}d&&(d.style.height="0px"),c&&(c.style.height=""),a.scrollTop=a.scrollHeight},[P,aQ]),(0,c.useEffect)(()=>{let a=V.current;if(!a)return;let b=document.getElementById(`exchange-${a}`);b&&(V.current=null,b.scrollIntoView({block:"center"}),b.focus({preventScroll:!0}))},[T]),(0,c.useLayoutEffect)(()=>{aG(a=>{if(0===a.length)return a;let b=a.filter(a=>{let b=aL.current[a]??0;return P.some(c=>"bot"===c.sender_type&&c.sender_id===a&&c.created_at>b&&!/^\[(mcp|tool call|tool result)\]/i.test(c.content.trim()))});if(0===b.length)return a;for(let a of b)delete aL.current[a];return a.filter(a=>!b.includes(a))})},[P]);let aU=async a=>{C&&(await fetch(`/api/conversations/${C.id}/messages/${a}/stop`,{method:"POST"}),await aT())},aV=async()=>{C&&(await fetch(`/api/conversations/${C.id}/stop`,{method:"POST"}),await aT())},aW=async(a,b)=>{if(aq[a.id])return void ar(b=>{let c={...b};return delete c[a.id],c});if(as.current[a.id])return;let c=P.findIndex(b=>b.id===a.id),d=r.find(a=>a.name===b),e=P.slice(c+1).find(a=>"bot"===a.sender_type&&(d?a.sender_id===d.id:a.sender_name===b));if(e){as.current[a.id]=!0;try{let b=await fetch(`/api/messages/${a.id}/between?other=${encodeURIComponent(e.id)}`),c=await b.json().catch(()=>null);b.ok&&Array.isArray(c)&&c.length>0&&ar(b=>({...b,[a.id]:c}))}finally{delete as.current[a.id]}}},aX=async()=>{if(!C)return;let a=ay.current?.files?.[0];if(!a)return;let b=await new Promise((b,c)=>{let d=new FileReader;d.onload=()=>b(String(d.result||"")),d.onerror=()=>c(d.error),d.readAsDataURL(a)});if(!b.startsWith("data:image/"))return;let c=await fetch("/api/bots",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:C.details.id,avatar:b})});if(!c.ok)return;let d=await c.json();s(a=>a.map(a=>a.id===d.id?{...a,avatar:d.avatar}:a)),M({...C,details:{...C.details,avatar:d.avatar}})},aY=async a=>{if(!a||!C)return;let b=await new Promise((b,c)=>{let d=new FileReader;d.onload=()=>b(String(d.result||"")),d.onerror=()=>c(d.error),d.readAsDataURL(a)});if(!b.startsWith("data:image/"))return;let c=await fetch("/api/bots",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:C.details.id,avatar:b})});if(!c.ok)return;let d=await c.json();s(a=>a.map(a=>a.id===d.id?{...a,avatar:d.avatar}:a)),M({...C,details:{...C.details,avatar:d.avatar}})},aZ=async()=>{if(!C)return;let a=await fetch("/api/bots",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:C.details.id,avatar:null})});if(!a.ok)return;let b=await a.json();s(a=>a.map(a=>a.id===b.id?{...a,avatar:b.avatar||""}:a)),M({...C,details:{...C.details,avatar:b.avatar||""}})},a$=u&&0===r.length,a_=async a=>{let b=a.map(a=>a.id);au(!1),ax((0,q.deletedStatusLine)(b.length)),requestAnimationFrame(()=>av.current?.focus()),s(a=>a.filter(a=>!b.includes(a.id))),C&&b.includes(C.details.id)&&(M(null),Q([]),S([])),await aS()},a0=ab?r.filter(a=>a.name.toLowerCase().includes(_.toLowerCase())):[],a1=a=>{let b=ah.current,c=b?b.selectionStart:Z.length,d=Z.slice(0,c).lastIndexOf("@");if(d<0)return;$(Z.slice(0,d)+"@"+a+" "+Z.slice(c)),ac(!1);let e=d+a.length+2;requestAnimationFrame(()=>{b?.focus(),b?.setSelectionRange(e,e)})},a2=a=>{if(0===a.length)return;let b=6-ad.length;a.length>b?ag("Up to six attachments."):ag("");let c=a.slice(0,Math.max(b,0));0!==c.length&&ae(a=>[...a,...c.map((b,c)=>({id:b.name+"-"+a.length+"-"+c+"-"+b.size,name:b.name}))])},a3=async()=>{let a=ad.map(a=>a.name),b=Z.trim();if(!b&&0===a.length||!C)return;let c=[b,...a].filter(a=>a.length>0).join("\n"),d=[C.details.id],e=P.reduce((a,b)=>Math.max(a,b.created_at||0),0);for(let a of d)aL.current[a]=e;aG(a=>Array.from(new Set([...a,...d])));let f=[...r].sort((a,b)=>b.name.length-a.name.length).find(a=>(function(a,b){let c="@"+b,d=0;for(;d<a.length;){let b=a.indexOf(c,d);if(b<0)break;let e=a[b+c.length];if(!e||/[\s.,!?:;]/.test(e))return!0;d=b+c.length}return!1})(c,a.name));if(!(await fetch(`/api/conversations/${C.id}/messages`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:c,mentionedBotId:f?.id,idempotencyKey:crypto.randomUUID()})})).ok){for(let a of d)delete aL.current[a];aG(a=>a.filter(a=>!d.includes(a)))}$(""),ae([]),ag(""),ac(!1),aT()},a4=C?(a=C.id,P.length>0?"messages":W&&W.conversationId===a&&"loading"!==W.status?"error"===W.status?"error":"empty":"loading"):"loading",a5=C?(0,b.jsx)(v,{view:a4,agentName:C.details.name}):null,a6=(C?.details.title||"").trim(),a7=C?.details.color,a8=new Set,a9=a=>(0,b.jsx)("div",{className:"msg-status",children:(0,b.jsx)(y.default,{notice:a,onDone:()=>{aT()}})},a.eventId),ba=new Set,bb=a=>(0,b.jsx)("div",{className:"msg-status",children:(0,b.jsx)(A.default,{summary:a,onChanged:()=>{aT()}})},`exchange-${a.id}`),bc=a=>{let b=T.filter(b=>!ba.has(b.id)&&b.created_at<a).sort((a,b)=>a.created_at-b.created_at||(a.id<b.id?-1:1));return b.forEach(a=>ba.add(a.id)),b.map(bb)},bd=()=>{ak(!1),requestAnimationFrame(()=>al.current?.focus())};return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("div",{className:"field",inert:aj,children:[(0,b.jsx)(i.default,{agents:r,activeAgentId:C?.details.id,workingIds:aF,beatClock:aH,now:aJ,status:aw,logoDrop:aN,onAgentsChange:a=>s(a),onNew:()=>ak(!0),onManage:()=>{ax(""),au(!0)},onDeleted:a=>{a_(a)},newButtonRef:al,manageButtonRef:av}),(0,b.jsx)("section",{className:"pane",children:C?(0,b.jsxs)("div",{className:"thread",children:[(0,b.jsxs)("div",{className:"thread-bar",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("button",{type:"button",className:"thread-name",style:a7?{color:a7}:void 0,onClick:()=>{an(!0),ap(!1)},children:C.details.name}),a6?(0,b.jsx)("div",{className:"thread-role",children:a6}):null,(0,b.jsx)("div",{className:"thread-role",children:aF.includes(C.details.id)?"Working":"Not working"}),(0,b.jsx)("div",{className:"thread-role",children:(l=(aP??C.details).last_seen,m=aH.serverNow,n=aH.fetchedAt,l&&m?aJ-n+(m-l)>15e3?"Stopped":"Heartbeat "+new Intl.DateTimeFormat("en-US",{timeZone:"America/Los_Angeles",hour:"numeric",minute:"2-digit",second:"2-digit"}).format(new Date(l)):"Stopped")}),am?(0,b.jsx)("button",{type:"button",className:"avatar-pic",onClick:()=>ap(!0),"aria-label":"Picture",children:C.details.avatar?(0,b.jsx)("img",{src:C.details.avatar,alt:""}):(0,b.jsx)(h.default,{bot:C.details,size:46})}):null]}),(0,b.jsxs)("div",{style:{marginLeft:"auto",display:"flex",gap:16,alignItems:"flex-start"},children:[(0,b.jsx)(d.default,{href:`/agents/${C.details.id}/config`,className:"attach-word",style:{textDecoration:"none"},children:"Config"}),(0,b.jsx)(d.default,{href:`/agents/${encodeURIComponent(C.details.id)}/sessions`,className:"attach-word",style:{textDecoration:"none"},children:"Sessions"}),(0,b.jsx)("button",{type:"button",className:"attach-word",title:"Stop delegated turns in this thread",onClick:()=>{aV()},children:"Stop"})]})]}),ao?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("div",{className:"avatar-step avatar-desk",children:[(0,b.jsx)("span",{className:"kind-word",children:"Agent"}),(0,b.jsx)("button",{type:"button",className:"kind-word",children:"Generate"}),(0,b.jsxs)("label",{className:"kind-word",children:["Upload",(0,b.jsx)("input",{ref:ay,type:"file",accept:"image/*,.svg"})]}),(0,b.jsx)("button",{type:"button",className:"create-btn",onClick:aX,children:"Set avatar"})]}),(0,b.jsxs)("div",{className:"avatar-step avatar-phone",children:[(0,b.jsx)("button",{type:"button",className:"kind-word",onClick:()=>az.current?.click(),children:"Gallery"}),(0,b.jsx)("button",{type:"button",className:"kind-word",children:"Generate"}),(0,b.jsx)("button",{type:"button",className:"kind-word",onClick:aZ,children:"Remove Photo"}),(0,b.jsx)("input",{ref:az,type:"file",accept:"image/*,.svg",onChange:a=>{let b=a.target.files?.[0];a.target.value="",aY(b)}})]})]}):null,(0,b.jsxs)("div",{className:"messages-wrap",children:[(0,b.jsxs)("div",{className:"messages",children:[aQ?null:a5,P.map(a=>{var d;let e,f=R.filter(b=>!a8.has(b.eventId)&&b.createdAt<a.created_at);f.forEach(a=>a8.add(a.eventId));let h=bc(a.created_at),i="user"===a.sender_type,l=i?null:(0,x.classifyRuntimeFailure)(H(a.content));if(l)return(0,b.jsxs)(c.Fragment,{children:[f.map(a9),h,(0,b.jsx)("div",{className:"msg-status",children:(0,b.jsx)(w.default,{failure:l})})]},a.id);let m=(d=H(a.content),e=[],{text:G(d.replace(/data:image\/[a-zA-Z0-9.+-]+;base64,[A-Za-z0-9+/=\s]+/g,a=>(e.push(a.replace(/\s/g,"")),""))),images:e}),n=m.images.map(a=>(0,b.jsx)("img",{src:a,alt:"",style:{display:"block",width:64,height:64}},a.slice(0,48))),o=i?void 0:C.details.color,p=i?null:(0,g.parseRun)(a.content),q=i||p?null:(0,j.parseDraft)(H(a.content)),r=i||p?null:(0,j.parseApprovalCode)(a.content),s=i||p?[]:(0,j.parseFileNames)(a.content),t=i||p?null:(0,j.parseHandoff)(m.text),u=a.draftStatus??(q?"open":null),v=a.approvalStatus??(r?"pending":null);return(0,b.jsxs)(c.Fragment,{children:[f.map(a9),h,(0,b.jsxs)("div",{className:i?"msg-you":"msg-bot",ref:p&&"running"===p.state?aB:void 0,children:[(0,b.jsx)("div",{className:i?"msg-name msg-name-you":"msg-name",style:o?{color:o}:void 0,children:i?"You":a.sender_name||C.details.name}),p?(0,b.jsxs)("div",{className:"msg-body",children:[(0,g.runLine)(p),"running"===p.state?(0,b.jsxs)(b.Fragment,{children:[" ",(0,b.jsx)("button",{type:"button",className:"attach-word",style:{font:"inherit"},onClick:b=>{b.preventDefault(),b.stopPropagation(),aU(a.id)},children:"Stop"})]}):null]}):q&&u?(0,b.jsx)("div",{className:"msg-body",children:(0,b.jsx)(I,{message:a,conversationId:C.id,status:u,onDone:()=>{aT()}},a.id+u)}):(0,b.jsxs)("div",{className:"msg-body",onClick:t?()=>{aW(a,t)}:void 0,title:t?"Show the replies between this handoff and the reply":void 0,style:t?{cursor:"pointer"}:void 0,children:[function(a,c){let d=String(a??"").split("\n");if(!d.some(a=>null!==(0,k.agentEventDisplay)(a)))return a;let e=[];return d.forEach((a,d)=>{d>0&&e.push((0,b.jsx)("br",{},c+"-br-"+d));let f=(0,k.agentEventDisplay)(a);f?e.push((0,b.jsxs)("span",{className:"agent-event",children:[(0,b.jsx)("span",{className:"agent-event-label",children:f.label}),f.detail?" "+f.detail:""]},c+"-"+d)):e.push((0,b.jsx)("span",{children:a},c+"-"+d))}),e}(m.text,a.id),n,r&&v?(0,b.jsx)(J,{message:a,conversationId:C.id,status:v,onDone:()=>{aT()}},a.id+v):null,(0,b.jsx)(K,{names:s})]}),aq[a.id]?(0,b.jsx)("div",{className:"msg-body",children:aq[a.id].map(a=>(0,b.jsx)("div",{children:(a.sender_name||"Agent")+": "+G(a.content)},a.id))}):null]})]},a.id)}),R.filter(a=>!a8.has(a.eventId)).map(a9),bc(1/0),(0,b.jsx)("div",{ref:aD}),(0,b.jsx)("div",{ref:aA})]}),aQ?(0,b.jsxs)("div",{className:"computer-float",children:[(0,b.jsxs)("div",{className:"computer-top",children:[(0,b.jsxs)("span",{className:"computer-lights","aria-hidden":"true",children:[(0,b.jsx)("span",{className:"computer-light computer-light-red"}),(0,b.jsx)("span",{className:"computer-light computer-light-yellow"}),(0,b.jsx)("span",{className:"computer-light computer-light-green"})]}),(0,b.jsxs)("span",{className:"computer-teach",children:[(0,b.jsxs)("span",{className:"computer-teach-pill",children:[(0,b.jsx)("span",{className:"computer-teach-mark","aria-hidden":"true"}),"Teach a task"]}),(0,b.jsx)("span",{className:"computer-expand","aria-hidden":"true",children:(0,b.jsx)("svg",{viewBox:"0 0 16 16",width:"14",height:"14",children:(0,b.jsx)("path",{d:"M9.2 2.6H13.4V6.8M6.8 13.4H2.6V9.2M13.1 2.9L9.4 6.6M2.9 13.1L6.6 9.4",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]}),(0,b.jsx)("div",{className:"messages"===a4?"computer-band":"computer-band computer-band-note",ref:aC,children:a5}),(0,b.jsxs)("div",{className:"computer-desk",children:[aR?(0,b.jsx)("iframe",{className:"computer-page",sandbox:"",srcDoc:aR,tabIndex:-1}):null,(0,b.jsxs)("div",{className:"computer-dock",children:[(0,b.jsx)("img",{src:"/computer/dock-chrome.png",alt:""}),(0,b.jsx)("img",{src:"/computer/dock-gray.png",alt:""}),(0,b.jsx)("img",{src:"/computer/dock-terminal.png",alt:""})]})]})]}):null]}),(0,b.jsxs)("div",{className:"composer",onPaste:a=>{let b=[],c=a.clipboardData.files;if(c&&c.length>0)b.push(...Array.from(c));else for(let c of Array.from(a.clipboardData.items)){if("file"!==c.kind)continue;let a=c.getAsFile();a&&b.push(a)}0!==b.length&&(a.preventDefault(),a2(b))},children:[ab&&a0.length>0?(0,b.jsx)("div",{className:"mention-list",children:a0.map(a=>(0,b.jsxs)("button",{type:"button",onMouseDown:b=>{b.preventDefault(),a1(a.name)},children:["@",a.name]},a.id))}):null,(0,b.jsxs)("div",{className:"composer-box",children:[af?(0,b.jsx)("p",{className:"attach-error",children:af}):null,ad.length>0?(0,b.jsx)("div",{className:"attach-names",children:ad.map(a=>(0,b.jsx)("span",{children:a.name},a.id))}):null,(0,b.jsx)("textarea",{ref:ah,rows:2,value:Z,onChange:a=>{var b,c;let d,e;$(a.target.value),b=a.target.value,c=a.target.selectionStart,(e=(d=b.slice(0,c)).lastIndexOf("@"))<0||/\s/.test(d.slice(e+1))?ac(!1):(aa(d.slice(e+1)),ac(!0))},onKeyDown:a=>{if("Enter"===a.key&&!a.shiftKey){if(a.preventDefault(),ab&&a0.length>0)return void a1(a0[0].name);a3()}},placeholder:"Say something"})]}),(0,b.jsx)("input",{ref:ai,className:"attach-input",type:"file",multiple:!0,onChange:a=>{a2(Array.from(a.target.files||[])),a.target.value=""}}),(0,b.jsx)("button",{type:"button",className:"attach-word",onClick:()=>ai.current?.click(),children:"Attach"}),(0,b.jsx)("button",{type:"button",className:"send-btn",onClick:a3,children:"Send"})]})]}):a$?(0,b.jsxs)("div",{className:"welcome",children:[(0,b.jsx)(e.default,{className:"welcome-mark",src:"/brand/botmancers-logo-outline-256.png",alt:"Botmancers",width:144,height:144,priority:!0}),(0,b.jsx)("p",{className:"empty-line",children:"Pick someone to talk to."})]}):(0,b.jsx)("p",{className:"empty-line",children:"Pick someone to talk to."})}),at?(0,b.jsx)(t,{onClose:()=>{au(!1),requestAnimationFrame(()=>av.current?.focus())},onDeleted:a=>{a_(a)}}):null]}),aj&&(0,b.jsx)(L,{anchorRef:al,onClose:bd,onCreated:()=>{aS(),bd()}})]})}],60350)}];
2
2
 
3
3
  //# sourceMappingURL=app_page_tsx_0pxmutw._.js.map
@@ -1,3 +1,3 @@
1
- module.exports=[10209,a=>{"use strict";a.s(["DIALOG_FOCUSABLE",0,'a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])',"newAgentDialogPlacement",0,function(a,b){let c=Math.min(358,b.width-32),d=Math.max(16,b.width-16-c),e=16,f=16;if(a){f=Math.min(Math.max(a.left,16),d);let c=a.bottom+8;b.height-c-16>=360&&(e=c)}return{top:e,left:f,maxHeight:Math.max(0,b.height-e-16)}},"wrapFocusTarget",0,function(a,b,c){if(0===a.length)return null;let d=a[0],e=a[a.length-1],f=null!==b&&a.includes(b);return c?f&&b!==d?null:e:f&&b!==e?null:d}])},23464,a=>{"use strict";var b=a.i(65221),c=a.i(35099);function d(a){return"active"===a.state}let e=/^T[A-Z0-9]{2,20}$/,f=/^[CG][A-Z0-9]{2,20}$/;a.s(["SHARE_DURATIONS",0,[{label:"5 minutes",seconds:300},{label:"1 hour",seconds:3600},{label:"8 hours",seconds:28800},{label:"24 hours",seconds:86400}],"SHARE_STATUS_LABELS",0,{active:"Active",exhausted:"Questions used",answering:"Answering",recovering:"Recovering",expired:"Expired",revoked:"Revoked"},"audienceInputError",0,function(a,b,c){let d=a.trim(),g=b.trim();return e.test(d)?f.test(g)?c.some(a=>a.team_id===d&&a.channel_id===g)?"That channel is already on the allowlist.":null:"Channel ID must look like C0123ABCD (a public or private channel ID; no wildcards).":"Workspace ID must look like T0123ABCD (a Slack team ID; no wildcards)."},"audienceLabel",0,function(a){return`Slack channel ${a.channel_id} \xb7 workspace ${a.team_id}`},"createdByLabel",0,function(a){return"owner"===a.created_by?"Shared by you":"current_session"===a.created_by?"Shared from a turn of this session":"Shared by a service"},"expiryLabel",0,function(a,c=Date.now()){return"revoked"===a.state?`Revoked ${(0,b.formatSessionDate)(a.revoked_at??a.expires_at)}`:"expired"===a.state||a.expires_at<=c?`Expired ${(0,b.formatSessionDate)(a.expires_at)}`:`Expires ${(0,b.formatSessionDate)(a.expires_at)} (in ${function(a){let b=Math.max(1,Math.round(a/6e4));if(b<60)return`${b} min`;let c=Math.floor(b/60),d=b%60;return d?`${c} h ${d} min`:`${c} h`}(a.expires_at-c)})`},"sessionShares",0,function(a,b){let c=a.filter(a=>a.session_ref===b);return[...c.filter(d).sort((a,b)=>b.created_at-a.created_at),...c.filter(a=>!d(a)).sort((a,b)=>(b.revoked_at??b.expires_at)-(a.revoked_at??a.expires_at))]},"shareCreateAvailability",0,function(a,b){let d=`/agents/${encodeURIComponent(a.agent.id)}/config#session-sharing`;if(!b)return{available:!1,reason:"Share to Slack is unavailable: the share policy could not be loaded.",configHref:null};let e=(0,c.sessionRowActions)(a).find(a=>"ask"===a.action);return e&&!e.availability.available?{available:!1,reason:e.availability.reason.replace(/^Ask from this context is unavailable:/,"Share to Slack is unavailable:"),configHref:null}:"invalid"===b.state?{available:!1,reason:"Share to Slack is unavailable: the share policy file is invalid. Fix it in Config.",configHref:d}:0===b.audiences.length?{available:!1,reason:"Share to Slack needs a Slack channel on the share allowlist. Add one in Config.",configHref:d}:{available:!0}},"shareCreateBody",0,function(a,b,c,d){return{audience:{team_id:a.team_id,channel_id:a.channel_id},ttl_seconds:b,max_turns:c,idempotency_key:d}},"shareFromTurnNote",0,function(a){return a.agent.share_current.supported?a.agent.share_from_turn?"On: a turn Botmancers launches for this Agent can share its own session to an allowlisted channel. Turning it off revokes every live turn context at once.":"Off: no turn of this Agent can share its own session. Sessions can still be shared from the Agent Sessions page.":a.agent.share_current.reason??"This runtime cannot share its own session from a turn."},"shareIsLive",0,d,"shareStatusNote",0,function(a){switch(a.status){case"active":return"Slack replies in its thread ask this session (read-only).";case"answering":return"A Slack question is being answered now. The next one waits until it finishes.";case"recovering":return"A question was interrupted by a Botmancers restart. The next Slack question clears it.";case"exhausted":return`All ${a.max_turns} questions are used. Slack questions get the limit notice; create a new share to keep going.`;case"expired":return"Expired: Slack questions get the expired notice. Its history stays here.";case"revoked":return"Revoked: Slack questions get the revoked notice. Its history stays here."}},"threadLabel",0,function(a){return a.thread.posted?`Slack thread posted ${(0,b.formatSessionDate)(a.thread.posted_at??0)}`:"active"===a.state?"Waiting for the Slack relay to post the thread":"No Slack thread was posted"},"turnsLabel",0,function(a){return`${a.turns_used} of ${a.max_turns} question${1===a.max_turns?"":"s"} used`}])}];
1
+ module.exports=[10209,a=>{"use strict";a.s(["DIALOG_FOCUSABLE",0,'a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])',"newAgentDialogPlacement",0,function(a,b){let c=Math.min(358,b.width-32),d=Math.max(16,b.width-16-c),e=16,f=16;if(a){f=Math.min(Math.max(a.left,16),d);let c=a.bottom+8;b.height-c-16>=360&&(e=c)}return{top:e,left:f,maxHeight:Math.max(0,b.height-e-16)}},"wrapFocusTarget",0,function(a,b,c){if(0===a.length)return null;let d=a[0],e=a[a.length-1],f=null!==b&&a.includes(b);return c?f&&b!==d?null:e:f&&b!==e?null:d}])},23464,a=>{"use strict";var b=a.i(65221),c=a.i(35099);function d(a){return"active"===a.state}let e=/^T[A-Z0-9]{2,20}$/,f=/^[CG][A-Z0-9]{2,20}$/;a.s(["SHARE_DURATIONS",0,[{label:"5 minutes",seconds:300},{label:"1 hour",seconds:3600},{label:"8 hours",seconds:28800},{label:"24 hours",seconds:86400}],"SHARE_STATUS_LABELS",0,{active:"Active",exhausted:"Questions used",answering:"Answering",recovering:"Recovering",expired:"Expired",revoked:"Revoked"},"audienceInputError",0,function(a,b,c){let d=a.trim(),g=b.trim();return e.test(d)?f.test(g)?c.some(a=>a.team_id===d&&a.channel_id===g)?"That channel is already on the allowlist.":null:"Channel ID must look like C0123ABCD (a public or private channel ID; no wildcards).":"Workspace ID must look like T0123ABCD (a Slack team ID; no wildcards)."},"audienceLabel",0,function(a){return`Slack channel ${a.channel_id} \xb7 workspace ${a.team_id}`},"createdByLabel",0,function(a){return"owner"===a.created_by?"Shared by you":"current_session"===a.created_by?"Shared from a turn of this session":"Shared by a service"},"expiryLabel",0,function(a,c=Date.now()){return"revoked"===a.state?`Revoked ${(0,b.formatSessionDate)(a.revoked_at??a.expires_at)}`:"expired"===a.state||a.expires_at<=c?`Expired ${(0,b.formatSessionDate)(a.expires_at)}`:`Expires ${(0,b.formatSessionDate)(a.expires_at)} (in ${function(a){let b=Math.max(1,Math.round(a/6e4));if(b<60)return`${b} min`;let c=Math.floor(b/60),d=b%60;return d?`${c} h ${d} min`:`${c} h`}(a.expires_at-c)})`},"sessionShares",0,function(a,b){let c=a.filter(a=>a.session_ref===b);return[...c.filter(d).sort((a,b)=>b.created_at-a.created_at),...c.filter(a=>!d(a)).sort((a,b)=>(b.revoked_at??b.expires_at)-(a.revoked_at??a.expires_at))]},"shareCreateAvailability",0,function(a,b){let d=`/agents/${encodeURIComponent(a.agent.id)}/config#session-sharing`;if(!b)return{available:!1,reason:"Share to Slack is unavailable: the share policy could not be loaded.",configHref:null};let e=(0,c.sessionRowActions)(a).find(a=>"ask"===a.action);return e&&!e.availability.available?{available:!1,reason:e.availability.reason.replace(/^Ask from this context is unavailable:/,"Share to Slack is unavailable:"),configHref:null}:"invalid"===b.state?{available:!1,reason:"Share to Slack is unavailable: the share policy file is invalid. Fix it in Config.",configHref:d}:0===b.audiences.length?{available:!1,reason:"Share to Slack needs a Slack channel on the share allowlist. Add one in Config.",configHref:d}:{available:!0}},"shareCreateBody",0,function(a,b,c,d){return{audience:{team_id:a.team_id,channel_id:a.channel_id},ttl_seconds:b,max_turns:c,idempotency_key:d}},"shareFromTurnNote",0,function(a){return a.agent.share_current.supported?a.agent.share_from_turn?"On: a turn Botmancers launches for this agent can share its own session to an allowlisted channel. Turning it off revokes every live turn context at once.":"Off: no turn of this agent can share its own session. Sessions can still be shared from the Sessions page.":a.agent.share_current.reason??"This runtime cannot share its own session from a turn."},"shareIsLive",0,d,"shareStatusNote",0,function(a){switch(a.status){case"active":return"Slack replies in its thread ask this session (read-only).";case"answering":return"A Slack question is being answered now. The next one waits until it finishes.";case"recovering":return"A question was interrupted by a Botmancers restart. The next Slack question clears it.";case"exhausted":return`All ${a.max_turns} questions are used. Slack questions get the limit notice; create a new share to keep going.`;case"expired":return"Expired: Slack questions get the expired notice. Its history stays here.";case"revoked":return"Revoked: Slack questions get the revoked notice. Its history stays here."}},"threadLabel",0,function(a){return a.thread.posted?`Slack thread posted ${(0,b.formatSessionDate)(a.thread.posted_at??0)}`:"active"===a.state?"Waiting for the Slack relay to post the thread":"No Slack thread was posted"},"turnsLabel",0,function(a){return`${a.turns_used} of ${a.max_turns} question${1===a.max_turns?"":"s"} used`}])}];
2
2
 
3
3
  //# sourceMappingURL=lib_0pfn9gs._.js.map