agent-relay-server 0.32.1 → 0.32.2

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 (64) hide show
  1. package/docs/openapi.json +57 -127
  2. package/package.json +1 -1
  3. package/public/assets/{activity-C6nbfryG.js → activity-DT1JGHnp.js} +2 -2
  4. package/public/assets/{activity-C6nbfryG.js.map → activity-DT1JGHnp.js.map} +1 -1
  5. package/public/assets/{agent-profiles-FEITAgHs.js → agent-profiles-CrMemMkZ.js} +2 -2
  6. package/public/assets/{agent-profiles-FEITAgHs.js.map → agent-profiles-CrMemMkZ.js.map} +1 -1
  7. package/public/assets/{agents-D4S0yIbe.js → agents-Bl-rrgOy.js} +2 -2
  8. package/public/assets/{agents-D4S0yIbe.js.map → agents-Bl-rrgOy.js.map} +1 -1
  9. package/public/assets/{analytics-DM2g62T_.js → analytics-a663ak56.js} +2 -2
  10. package/public/assets/{analytics-DM2g62T_.js.map → analytics-a663ak56.js.map} +1 -1
  11. package/public/assets/{automation-3D2pQa1C.js → automation-CiaLThdO.js} +2 -2
  12. package/public/assets/{automation-3D2pQa1C.js.map → automation-CiaLThdO.js.map} +1 -1
  13. package/public/assets/{branch-state-badge-Bi4IbkOZ.js → branch-state-badge-D4ur3m3_.js} +2 -2
  14. package/public/assets/{branch-state-badge-Bi4IbkOZ.js.map → branch-state-badge-D4ur3m3_.js.map} +1 -1
  15. package/public/assets/{channels-QNp7zmA_.js → channels-o9KLTHoK.js} +2 -2
  16. package/public/assets/{channels-QNp7zmA_.js.map → channels-o9KLTHoK.js.map} +1 -1
  17. package/public/assets/{chat-jeXt_SFs.js → chat-5hvHZcAe.js} +2 -2
  18. package/public/assets/{chat-jeXt_SFs.js.map → chat-5hvHZcAe.js.map} +1 -1
  19. package/public/assets/{connectors-BGJARDui.js → connectors-CdC806mA.js} +2 -2
  20. package/public/assets/{connectors-BGJARDui.js.map → connectors-CdC806mA.js.map} +1 -1
  21. package/public/assets/{formatted-body-impl-B7FgqkYL.js → formatted-body-impl-Ca74OAEH.js} +2 -2
  22. package/public/assets/{formatted-body-impl-B7FgqkYL.js.map → formatted-body-impl-Ca74OAEH.js.map} +1 -1
  23. package/public/assets/{index-2m9mT8kV.js → index-C_33ymaw.js} +6 -6
  24. package/public/assets/{index-2m9mT8kV.js.map → index-C_33ymaw.js.map} +1 -1
  25. package/public/assets/{integrations-CJm8-FcG.js → integrations-1nxMizDY.js} +2 -2
  26. package/public/assets/{integrations-CJm8-FcG.js.map → integrations-1nxMizDY.js.map} +1 -1
  27. package/public/assets/{maintenance-CBvZrVAG.js → maintenance-DiFNzNPN.js} +2 -2
  28. package/public/assets/{maintenance-CBvZrVAG.js.map → maintenance-DiFNzNPN.js.map} +1 -1
  29. package/public/assets/{managed-agents-Dcmm8YKt.js → managed-agents-Do3dKvfj.js} +2 -2
  30. package/public/assets/{managed-agents-Dcmm8YKt.js.map → managed-agents-Do3dKvfj.js.map} +1 -1
  31. package/public/assets/{markdown-preview-impl-7xjqdiEu.js → markdown-preview-impl-CLA0J255.js} +2 -2
  32. package/public/assets/{markdown-preview-impl-7xjqdiEu.js.map → markdown-preview-impl-CLA0J255.js.map} +1 -1
  33. package/public/assets/{memory-BmGNW61h.js → memory-IjwqFzBd.js} +2 -2
  34. package/public/assets/{memory-BmGNW61h.js.map → memory-IjwqFzBd.js.map} +1 -1
  35. package/public/assets/{messages-BvMMhoy-.js → messages-DjvWqHyn.js} +2 -2
  36. package/public/assets/{messages-BvMMhoy-.js.map → messages-DjvWqHyn.js.map} +1 -1
  37. package/public/assets/{orchestrators-DsstaupT.js → orchestrators-D2IqDxDT.js} +2 -2
  38. package/public/assets/{orchestrators-DsstaupT.js.map → orchestrators-D2IqDxDT.js.map} +1 -1
  39. package/public/assets/{overview-kK6PTce3.js → overview-DKC3TbAh.js} +2 -2
  40. package/public/assets/{overview-kK6PTce3.js.map → overview-DKC3TbAh.js.map} +1 -1
  41. package/public/assets/{pairs-BEFvTW6X.js → pairs-WpKCPE1n.js} +2 -2
  42. package/public/assets/{pairs-BEFvTW6X.js.map → pairs-WpKCPE1n.js.map} +1 -1
  43. package/public/assets/{security-Dc5wZwv0.js → security-BF7ZtPQe.js} +2 -2
  44. package/public/assets/{security-Dc5wZwv0.js.map → security-BF7ZtPQe.js.map} +1 -1
  45. package/public/assets/{settings-CEtJrORa.js → settings-CQnjrTa-.js} +2 -2
  46. package/public/assets/{settings-CEtJrORa.js.map → settings-CQnjrTa-.js.map} +1 -1
  47. package/public/assets/{store-DkmReBlH.js → store-C9VcSo05.js} +2 -2
  48. package/public/assets/{store-DkmReBlH.js.map → store-C9VcSo05.js.map} +1 -1
  49. package/public/assets/{tasks-pQKtxqeV.js → tasks-CbN_GSSb.js} +2 -2
  50. package/public/assets/{tasks-pQKtxqeV.js.map → tasks-CbN_GSSb.js.map} +1 -1
  51. package/public/assets/{terminal-viewer-impl-Cc769mYy.js → terminal-viewer-impl-BJRohThT.js} +2 -2
  52. package/public/assets/{terminal-viewer-impl-Cc769mYy.js.map → terminal-viewer-impl-BJRohThT.js.map} +1 -1
  53. package/public/assets/{work-queue-DjAanr02.js → work-queue-C5xLBLmm.js} +2 -2
  54. package/public/assets/{work-queue-DjAanr02.js.map → work-queue-C5xLBLmm.js.map} +1 -1
  55. package/public/assets/{workspaces-DLBNyR4k.js → workspaces-D91H3wDX.js} +2 -2
  56. package/public/assets/{workspaces-DLBNyR4k.js.map → workspaces-D91H3wDX.js.map} +1 -1
  57. package/public/index.html +2 -2
  58. package/scripts/orchestrator-spawn-smoke.ts +2 -1
  59. package/src/automations.ts +2 -4
  60. package/src/managed-policy.ts +2 -4
  61. package/src/mcp.ts +3 -3
  62. package/src/routes.ts +69 -139
  63. package/src/runtime-tokens.ts +17 -8
  64. package/src/security.ts +0 -2
@@ -1,2 +1,2 @@
1
- import{r as e}from"./chunk-CilyBKbf.js";import{$t as t,An as n,D as r,Dn as i,Dt as a,E as o,Et as s,Ft as c,G as l,H as u,I as d,It as f,J as p,Jt as m,K as h,Lt as g,P as _,Pn as v,Vn as y,Wt as b,Z as x,an as S,at as C,b as w,c as T,dn as ee,en as E,et as te,g as ne,i as D,in as O,it as k,jn as re,kn as ie,kt as ae,mn as A,nn as oe,qt as se,r as ce,rn as le,s as ue,tn as de,tt as fe,wn as j,x as pe,xn as me,yn as he,yt as ge}from"./lucide-react-CD8Xl2U3.js";import{t as _e}from"./react-dom-CX8inunm.js";import{d as ve,i as ye,l as be,s as xe,t as M,u as Se}from"./store-DkmReBlH.js";import{$ as Ce,D as N,E as we,H as Te,I as Ee,M as De,N as Oe,O as ke,R as P,S as Ae,V as je,a as Me,g as Ne,i as Pe,m as F,q as I,u as L,w as Fe,z as R}from"./display-JI19Vc7L.js";import{t as Ie}from"./badge-t8zAwHW9.js";import{t as z}from"./button-DDA5P2YQ.js";import{t as B}from"./input-BW9UD3FM.js";import{t as Le}from"./copy-button-CE8e2c-F.js";import{C as Re,E as ze,I as Be,S as Ve,T as He,_ as Ue,a as We,d as Ge,g as Ke,h as qe,i as Je,k as V,l as Ye,m as H,o as Xe,p as Ze,r as Qe,t as U,v as $e,w as W,y as et}from"./index-2m9mT8kV.js";import{t as tt}from"./use-keyboard-viewport-DxY_xJV5.js";import{n as nt,t as rt}from"./branch-state-badge-Bi4IbkOZ.js";var G=e(y(),1),K=e(_e(),1),it=[{name:`/reply`,source:`skill`,description:`Reply to a relay message by id`,argumentHint:`<messageId> <body>`},{name:`/message`,source:`skill`,description:`Send a relay message to an agent, label, tag, or broadcast`,argumentHint:`<target> <body>`},{name:`/pair`,source:`skill`,description:`Start or manage a two-agent pair session`},{name:`/react`,source:`skill`,description:`Add a reaction to a relay message`,argumentHint:`<messageId> <emoji>`},{name:`/read-message`,source:`skill`,description:`Fetch a full relay message by id`,argumentHint:`<messageId>`},{name:`/send-claimable`,source:`skill`,description:`Enqueue a claimable work item for one agent to claim`},{name:`/status`,source:`skill`,description:`Show this agent's relay status`},{name:`/tags`,source:`skill`,description:`List or update this agent's relay tags`},{name:`/label`,source:`skill`,description:`Read, set, or clear this agent's relay label`},{name:`/disconnect`,source:`skill`,description:`End the current relay pair session`}],at=[{name:`/clear`,source:`builtin`,description:`Clear conversation history and free up context`},{name:`/compact`,source:`builtin`,description:`Compact the conversation to reclaim context`,argumentHint:`[instructions]`},{name:`/model`,source:`builtin`,description:`Switch the active model`,argumentHint:`[model]`},{name:`/help`,source:`builtin`,description:`Show help`}],ot=[{name:`/compact`,source:`builtin`,description:`Compact the conversation to reclaim context`},{name:`/new`,source:`builtin`,description:`Start a new thread`}];function st(e){return[...e===`claude`?at:e===`codex`?ot:[],...it]}var q=ie();function ct(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function lt(e,t){if(t.startsWith(`/`))return t;let n=`${e.replace(/\/+$/,``)}/${t}`.split(`/`),r=[];for(let e of n)!e||e===`.`||(e===`..`?r.pop():r.push(e));return`/`+r.join(`/`)}function ut(e){let t=e.replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n>0?t.slice(0,n):`/`}function dt(e,t){return e.filter(e=>e.status===`online`&&De(t,e.baseDir)).sort((e,t)=>N(t.baseDir).length-N(e.baseDir).length)[0]||e.find(e=>e.status===`online`)}function ft(){return typeof window<`u`&&window.matchMedia(`(min-width: 1280px)`).matches}function pt(){return typeof window<`u`&&!!window.getSelection()?.toString()}function mt(e){let t=e.payload?.attachments;return Array.isArray(t)?t.filter(e=>!!(e&&typeof e==`object`&&typeof e.artifactId==`string`)):[]}var J=[`👍`,`❤️`,`✅`,`👀`];function ht(e){let t=new Map;for(let n of e.reactions||[]){let e=ke(n.emoji),r=t.get(e)??{emoji:e,count:0,mine:!1,actors:[]};r.count+=1,r.mine=r.mine||n.actorId===`user`,r.actors.push(n.actorId),t.set(e,r)}return[...t.values()].sort((e,t)=>t.count-e.count||e.emoji.localeCompare(t.emoji))}function Y(e){return Ae(e)}function gt(e,n){let r=e.readBy||[],i=e.resolvedToAgent||n||e.to,a=i?r.includes(i):!1,o=r.some(e=>e!==Ce);if(a||o){let e=a?i:r.find(e=>e!==Ce);return{label:`read`,title:e?`Read by ${e}`:`Read by agent`,tone:`ok`,icon:S}}if(e.deliveryStatus===`delivered`)return{label:`delivered`,title:`Delivered to agent inbox`,tone:`ok`,icon:S};if(e.deliveryStatus===`queued`)return{label:`queued`,title:`Queued until the target agent is available`,tone:`warn`,icon:b};if(e.deliveryStatus===`failed`||e.deliveryStatus===`dead`){let n=e.deliveryPoisonReason||e.deliveryLastError||e.deliveryStatus;return{label:e.deliveryStatus,title:n,tone:`danger`,icon:t}}return{label:`sent`,title:`Accepted by Relay`,tone:`muted`,icon:O}}function X(e){let t=R(e.createdAt);return(e.reactions||[]).reduce((e,t)=>Math.max(e,R(t.updatedAt||t.createdAt)),t)}function _t(e){return e?e.messages.reduce((e,t)=>Math.max(e,X(t)),0):0}function vt(){let e=M(e=>e.agents),t=M(e=>e.showBuiltIns),n=M(e=>e.showOffline),r=M(e=>e.chatAgentSearch),i=M(e=>e.chatAgentProviderFilter),a=M(e=>e.chatAgentStatusFilter),o=M(e=>e.chatAgentTagFilter),s=M(e=>e.chatAgentCapFilter),c=M(e=>e.chatAgentHostFilter),l=M(e=>e.chatAgentSort),u=M(e=>e.chatAgentSortDir),d=M(e=>e.managedPolicies);return(0,G.useMemo)(()=>{let f=Te(e,t,d);if(n||(f=f.filter(e=>e.status!==`offline`)),r){let e=r.toLowerCase();f=f.filter(t=>t.id.toLowerCase().includes(e)||(t.name||``).toLowerCase().includes(e)||(t.label||``).toLowerCase().includes(e)||(t.tags||[]).some(t=>t.toLowerCase().includes(e))||(t.capabilities||[]).some(t=>t.toLowerCase().includes(e)))}i&&(f=f.filter(e=>Me(e)===i)),a&&(f=f.filter(e=>e.status===a)),o&&(f=f.filter(e=>(e.tags||[]).includes(o))),s&&(f=f.filter(e=>(e.capabilities||[]).includes(s))),c&&(f=f.filter(e=>(e.machine||``)===c));let p=u===`desc`?-1:1;return[...f].sort((e,t)=>l===`name`?L(e).localeCompare(L(t))*p:l===`lastSeen`?(R(t.lastSeen)-R(e.lastSeen))*p||L(e).localeCompare(L(t)):((I[e.status]??9)-(I[t.status]??9))*p||L(e).localeCompare(L(t)))},[e,t,n,d,r,i,a,o,s,c,l,u])}var yt=[],bt=[];function xt(e){return M(t=>t.chatStatusEvents[e]??yt)}function St(e,t){let n=(0,G.useRef)(!1);(0,G.useEffect)(()=>{if(!e)return;n.current||=(window.history.pushState({chatGuard:!0},``),!0);function r(e){(e.state?.chatGuard!==void 0||!n.current)&&(window.history.pushState({chatGuard:!0},``),t())}function i(e){e.preventDefault()}return window.addEventListener(`popstate`,r),window.addEventListener(`beforeunload`,i),()=>{window.removeEventListener(`popstate`,r),window.removeEventListener(`beforeunload`,i)}},[e,t]),(0,G.useEffect)(()=>{!e&&n.current&&(n.current=!1)},[e])}function Ct(){let e=M(e=>e.inboxDrafts),t=M(e=>e.agentsById),n=M(e=>e.set);(0,G.useEffect)(()=>{let r=Object.keys(e);if(r.length===0)return;let i=r.filter(e=>!t[e]&&e!==`user`);if(i.length===0)return;let a=setTimeout(()=>{let e=M.getState().agentsById,t={...M.getState().inboxDrafts},r=!1;for(let n of i)e[n]||(delete t[n],r=!0);r&&n({inboxDrafts:t})},3e4);return()=>clearTimeout(a)},[])}function wt({value:e,onChange:t,onKeyDown:n,onPaste:r,placeholder:a,className:o}){let s=(0,G.useRef)(null);return(0,G.useEffect)(()=>{let e=s.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[e]),(0,G.useEffect)(()=>{let e=window.visualViewport;if(!e)return;function t(){let e=s.current;!e||document.activeElement!==e||requestAnimationFrame(()=>{e.scrollIntoView({block:`nearest`,behavior:`smooth`})})}return e.addEventListener(`resize`,t),()=>e.removeEventListener(`resize`,t)},[]),(0,q.jsx)(`textarea`,{ref:s,value:e,onChange:t,onKeyDown:n,onPaste:r,placeholder:a,rows:1,className:i(`w-full resize-none rounded-xl border border-border bg-background px-3.5 py-2.5 text-sm`,`placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`min-h-[42px] max-h-[200px] overflow-y-auto`,o)})}function Tt({threads:e,onSelectAgent:t}){let n=M(e=>e.set),a=M(e=>e.openInboxThread),o=M(e=>e.openAgentSpawn),s=M(e=>e.selectedInboxThread),c=M(e=>e.chatAgentSearch),l=M(e=>e.chatAgentSort),u=M(e=>e.chatAgentSortDir),f=M(e=>e.chatAgentProviderFilter),p=M(e=>e.chatAgentStatusFilter),m=M(e=>e.chatAgentTagFilter),h=M(e=>e.chatAgentCapFilter),g=M(e=>e.chatAgentHostFilter),_=M(e=>e.chatAgentGroupBy),v=M(e=>e.chatAgentFiltersCollapsed),y=ye(),b=vt(),x=(0,G.useMemo)(()=>{let t=new Map;for(let n of e)t.set(n.peer,n);return t},[e]),S=(0,G.useMemo)(()=>{if(l!==`lastMessage`)return b;let e=u===`desc`?-1:1;return[...b].sort((t,n)=>{let r=_t(x.get(t.id));return(_t(x.get(n.id))-r)*e||L(t).localeCompare(L(n))})},[b,l,u,x]),C=(0,G.useMemo)(()=>[...new Set(b.flatMap(e=>e.tags||[]))],[b]),w=(0,G.useMemo)(()=>[...new Set(b.flatMap(e=>je(e.capabilities||[])))],[b]),T=Be(),ee=(0,G.useMemo)(()=>{if(_!==`project`)return null;let e=new Map;for(let t of S){let n=H(t)||`No project`,r=e.get(n);r?r.push(t):e.set(n,[t])}return[...e.entries()].sort((e,t)=>e[0].localeCompare(t[0]))},[S,_]),te=[f,p,m,h,g].filter(Boolean).length;function ne(e){a(e,x.get(e)?.messages),t?.(e)}function D(e){let t=x.get(e.id),n=t?.attention.unread||0,r=t?.previewMessage,a=_t(t),o=s===e.id,c=qe(e),l=H(e),u=c.Icon;return(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{className:i(`w-full text-left px-3 py-2.5 flex items-start gap-2.5 hover:bg-muted/50 transition-colors border-b border-border/50`,o&&`bg-muted/60`),onClick:()=>ne(e.id),children:[(0,q.jsxs)(`div`,{className:`relative shrink-0 mt-0.5`,children:[(0,q.jsx)(Ke,{agent:e}),(0,q.jsx)(Ue,{agent:e,now:y,className:`absolute -bottom-0.5 -right-0.5 w-2 h-2`})]}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-1 mb-0.5`,children:[(0,q.jsx)(`span`,{className:`text-xs font-medium truncate`,children:L(e)}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[a>0&&(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,title:F(a),children:P(y,a)}),n>0&&(0,q.jsx)(Ie,{className:`bg-red-500 text-white text-xs min-w-[18px] h-[18px] flex items-center justify-center shrink-0 px-1`,children:n})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-0.5 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(`span`,{title:c.title,className:`inline-flex shrink-0`,children:(0,q.jsx)(u,{className:i(`h-3 w-3`,c.iconColor)})}),(0,q.jsx)(`span`,{className:`truncate`,children:l||c.label}),e.context&&(0,q.jsx)(`span`,{className:`ml-auto shrink-0`,children:(0,q.jsx)(Ze,{utilization:e.context.utilization,size:18})})]}),r&&(0,q.jsxs)(`p`,{className:`text-xs text-muted-foreground truncate leading-tight`,children:[r.from===`user`?`You: `:``,we(r)]}),e.status!==`offline`&&(0,q.jsx)(`div`,{className:`mt-1`,children:(0,q.jsx)(`span`,{className:i(`text-xs`,e.status===`busy`?`text-yellow-400`:`text-emerald-400`),children:e.status})})]})]})},e.id)}return(0,q.jsxs)(`div`,{className:`flex flex-col h-full border-r border-border min-w-0`,children:[(0,q.jsxs)(`div`,{className:`p-3 border-b border-border space-y-2`,children:[(0,q.jsxs)(`div`,{className:`relative`,children:[(0,q.jsx)(r,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground pointer-events-none`}),(0,q.jsx)(B,{placeholder:`Search agents...`,value:c,onChange:e=>n({chatAgentSearch:e.target.value}),className:`pl-8 h-7 text-xs`})]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>n({chatAgentFiltersCollapsed:!v}),className:`sm:hidden flex w-full items-center justify-between h-6 px-1.5 text-xs rounded-md border border-border bg-background text-muted-foreground`,children:[(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,q.jsx)(pe,{className:`w-3.5 h-3.5`}),`Filters & sort`,te>0&&(0,q.jsx)(Ie,{className:`bg-primary/20 text-primary text-[10px] h-4 min-w-4 px-1 flex items-center justify-center`,children:te})]}),v?(0,q.jsx)(le,{className:`w-3.5 h-3.5`}):(0,q.jsx)(E,{className:`w-3.5 h-3.5`})]}),(0,q.jsxs)(`div`,{className:i(`space-y-2`,v?`hidden`:`block`,`sm:block`),children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsxs)(`select`,{value:l,onChange:e=>n({chatAgentSort:e.target.value}),className:`flex-1 h-6 text-xs rounded-md border border-border bg-background px-1.5 text-foreground`,children:[(0,q.jsx)(`option`,{value:`status`,children:`By status`}),(0,q.jsx)(`option`,{value:`name`,children:`By name`}),(0,q.jsx)(`option`,{value:`lastSeen`,children:`By last seen`}),(0,q.jsx)(`option`,{value:`lastMessage`,children:`By last activity`})]}),(0,q.jsx)(z,{variant:`ghost`,size:`icon-xs`,onClick:()=>n({chatAgentSortDir:u===`asc`?`desc`:`asc`}),children:u===`asc`?(0,q.jsx)(he,{className:`w-3.5 h-3.5`}):(0,q.jsx)(j,{className:`w-3.5 h-3.5`})})]}),(0,q.jsxs)(`select`,{value:_,onChange:e=>n({chatAgentGroupBy:e.target.value}),className:`w-full h-6 text-xs rounded-md border border-border bg-background px-1.5 text-foreground`,children:[(0,q.jsx)(`option`,{value:``,children:`No grouping`}),(0,q.jsx)(`option`,{value:`project`,children:`Group by project`})]}),(0,q.jsxs)(`div`,{className:`flex gap-1`,children:[(0,q.jsxs)(`select`,{value:f,onChange:e=>n({chatAgentProviderFilter:e.target.value}),className:`flex-1 h-6 text-xs rounded-md border border-border bg-background px-1.5 text-foreground`,children:[(0,q.jsx)(`option`,{value:``,children:`All types`}),(0,q.jsx)(`option`,{value:`claude`,children:`Claude`}),(0,q.jsx)(`option`,{value:`codex`,children:`Codex`}),(0,q.jsx)(`option`,{value:`agent`,children:`Agent`}),(0,q.jsx)(`option`,{value:`user`,children:`User`})]}),(0,q.jsxs)(`select`,{value:p,onChange:e=>n({chatAgentStatusFilter:e.target.value}),className:`flex-1 h-6 text-xs rounded-md border border-border bg-background px-1.5 text-foreground`,children:[(0,q.jsx)(`option`,{value:``,children:`All status`}),(0,q.jsx)(`option`,{value:`online`,children:`Online`}),(0,q.jsx)(`option`,{value:`idle`,children:`Idle`}),(0,q.jsx)(`option`,{value:`busy`,children:`Busy`}),(0,q.jsx)(`option`,{value:`offline`,children:`Offline`})]}),T.length>1&&(0,q.jsxs)(`select`,{value:g,onChange:e=>n({chatAgentHostFilter:e.target.value}),className:`flex-1 h-6 text-xs rounded-md border border-border bg-background px-1.5 text-foreground`,children:[(0,q.jsx)(`option`,{value:``,children:`All hosts`}),T.map(e=>(0,q.jsx)(`option`,{value:e,children:e},e))]})]}),(C.length>0||w.length>0)&&(0,q.jsxs)(`div`,{className:`flex gap-1`,children:[C.length>0&&(0,q.jsxs)(`select`,{value:m,onChange:e=>n({chatAgentTagFilter:e.target.value}),className:`flex-1 h-6 text-xs rounded-md border border-border bg-background px-1.5 text-foreground`,children:[(0,q.jsx)(`option`,{value:``,children:`All tags`}),C.map(e=>(0,q.jsxs)(`option`,{value:e,children:[`#`,e]},e))]}),w.length>0&&(0,q.jsxs)(`select`,{value:h,onChange:e=>n({chatAgentCapFilter:e.target.value}),className:`flex-1 h-6 text-xs rounded-md border border-border bg-background px-1.5 text-foreground`,children:[(0,q.jsx)(`option`,{value:``,children:`All caps`}),w.map(e=>(0,q.jsx)(`option`,{value:e,children:e},e))]})]})]})]}),(0,q.jsxs)(`button`,{type:`button`,className:`flex w-full shrink-0 items-center gap-2.5 border-b border-border px-3 py-2 text-left transition-colors hover:bg-muted/50`,onClick:o,children:[(0,q.jsx)(`div`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-full border border-dashed border-primary/50 bg-primary/10 text-primary`,children:(0,q.jsx)(d,{className:`h-3.5 w-3.5`})}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`text-xs font-medium`,children:`New Agent`}),(0,q.jsx)(`div`,{className:`truncate text-[10px] text-muted-foreground`,children:`Spawn a fresh chat agent`})]})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:S.length===0?(0,q.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-10 text-center px-4`,children:[(0,q.jsx)(A,{className:`w-8 h-8 text-zinc-600 mb-2`}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No agents match filters`})]}):ee?ee.map(([e,t])=>(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-1.5 border-b border-border/50 bg-background/95 px-3 py-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground backdrop-blur`,children:[(0,q.jsx)(`span`,{className:`truncate`,children:e}),(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:t.length})]}),(0,q.jsx)(`ul`,{children:t.map(D)})]},e)):(0,q.jsx)(`ul`,{children:S.map(D)})})]})}function Et(e){return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function Dt(e){return new Date(e.occurredAt??e.createdAt).getTime()}function Ot(e){let t=new Date,[n,r,i]=e.split(`-`).map(Number),a=new Date(n,r-1,i);if(e===en(t.getTime()))return`Today`;let o=new Date(t);return o.setDate(o.getDate()-1),e===en(o.getTime())?`Yesterday`:a.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`,year:a.getFullYear()===t.getFullYear()?void 0:`numeric`})}var kt={online:`text-emerald-400`,offline:`text-zinc-400`,shutdown:`text-zinc-400`,restarted:`text-blue-400`,"compaction-requested":`text-zinc-400`,compacting:`text-amber-400`,compacted:`text-amber-400`,"compaction-stalled":`text-red-400`,"clear-requested":`text-zinc-400`,"clearing-context":`text-amber-400`,"context-cleared":`text-amber-400`,"clear-stalled":`text-red-400`,"shutting-down":`text-zinc-400`},At={online:`came online`,offline:`went offline`,shutdown:`shut down`,restarted:`restarted`,"compaction-requested":`compaction requested`,compacting:`compaction started`,compacted:`context compacted`,"compaction-stalled":`compaction stalled — may need manual intervention`,"clear-requested":`clear requested`,"clearing-context":`clear started`,"context-cleared":`context cleared`,"clear-stalled":`context clear stalled — may need manual intervention`,"shutting-down":`shutting down`},jt=new Set(Object.keys(At)),Mt=3e3,Nt=96;function Pt({event:e}){return(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-2 my-1`,children:[(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,q.jsx)(se,{className:i(`w-2 h-2 fill-current`,kt[e.status]||`text-zinc-400`)}),(0,q.jsx)(`span`,{children:At[e.status]||e.status}),(0,q.jsx)(`span`,{className:`text-muted-foreground/60`,children:Et(e.timestamp)})]}),(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`})]})}function Ft({blockedLabel:e,onInterrupt:n}){return e?(0,q.jsx)(`div`,{className:`flex justify-start mb-3`,children:(0,q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-2xl rounded-bl-sm bg-card ring-1 ring-red-500/30 px-4 py-2.5`,children:[(0,q.jsx)(t,{className:`w-3.5 h-3.5 text-red-400`}),(0,q.jsxs)(`span`,{className:`text-xs text-red-300`,children:[`blocked: `,e]})]})}):(0,q.jsx)(`div`,{className:`flex justify-start mb-3`,children:(0,q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-2xl rounded-bl-sm bg-card ring-1 ring-foreground/10 px-4 py-2.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-yellow-400 animate-[pulse_1.4s_ease-in-out_infinite]`}),(0,q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-yellow-400 animate-[pulse_1.4s_ease-in-out_0.2s_infinite]`}),(0,q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-yellow-400 animate-[pulse_1.4s_ease-in-out_0.4s_infinite]`})]}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`working`}),n&&(0,q.jsxs)(`button`,{onClick:n,title:`Interrupt`,className:`ml-1 flex items-center gap-1 rounded-full px-1.5 py-0.5 text-xs text-muted-foreground hover:text-red-300 hover:bg-red-500/10 transition-colors`,children:[(0,q.jsx)(m,{className:`w-3.5 h-3.5`}),`Stop`]})]})})}var It=`agent-relay:chat-hide-tools`,Lt=(()=>{let e=new Set,t=(()=>{try{return window.localStorage.getItem(It)===`on`}catch{return!1}})(),n=()=>e.forEach(e=>e());return typeof window<`u`&&window.addEventListener(`storage`,e=>{e.key===It&&(t=e.newValue===`on`,n())}),{subscribe(t){return e.add(t),()=>e.delete(t)},get:()=>t,toggle(){t=!t;try{window.localStorage.setItem(It,t?`on`:`off`)}catch{}n()}}})();function Rt(){return[(0,G.useSyncExternalStore)(Lt.subscribe,Lt.get,()=>!1),Lt.toggle]}function zt({steps:e,showReasoning:t}){let[n,r]=Rt(),a=t?e:e.filter(e=>e.kind!==`reasoning`);if(!a.length)return null;let o=a.filter(e=>e.kind===`tool`).length;return(0,q.jsx)(`div`,{className:`flex justify-start mb-2`,children:(0,q.jsxs)(`div`,{className:`max-w-[85%] md:max-w-[75%] min-w-0 space-y-1.5`,children:[a.map(e=>e.kind===`narration`?(0,q.jsx)(`div`,{className:`text-sm leading-relaxed whitespace-pre-wrap break-words text-foreground/90 min-w-0`,children:e.text},e.id):e.kind===`reasoning`?(0,q.jsxs)(`div`,{className:`flex items-start gap-1.5 text-xs leading-relaxed text-muted-foreground/80`,children:[(0,q.jsx)(ee,{className:`w-3.5 h-3.5 mt-0.5 shrink-0 opacity-70`}),(0,q.jsx)(`span`,{className:`italic whitespace-pre-wrap break-words min-w-0`,children:e.text})]},e.id):n?null:(0,q.jsxs)(`div`,{className:`flex items-start gap-1.5 text-xs leading-relaxed text-muted-foreground`,children:[(0,q.jsx)(ne,{className:`w-3 h-3 mt-0.5 shrink-0 opacity-70`}),(0,q.jsxs)(`span`,{className:`min-w-0 break-words`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:e.label||`tool`}),e.text?(0,q.jsxs)(`span`,{className:`opacity-70`,children:[` — `,e.text]}):null]})]},e.id)),o>0&&(0,q.jsxs)(`button`,{onClick:r,className:`flex items-center gap-1 text-[11px] text-muted-foreground/50 hover:text-muted-foreground transition-colors text-left`,children:[(0,q.jsx)(de,{className:i(`w-3 h-3 shrink-0 transition-transform`,!n&&`rotate-90`)}),(0,q.jsx)(`span`,{children:n?`show ${o} tool step${o===1?``:`s`}`:`hide tool steps`})]})]})})}function Bt({agentId:e,approval:n}){let r=M(e=>e.sendPermissionDecision),[i,a]=(0,G.useState)(null);if(!n)return null;if(n.questions&&n.questions.length)return(0,q.jsx)(Ut,{agentId:e,approval:n,questions:n.questions});let o=n,s=n.choices.length?n.choices:[{id:`approve`,label:`Approve`},{id:`deny`,label:`Deny`}];async function c(t){if(!i){a(t.id);try{await r(e,o.id,t.id)}finally{a(null)}}}let l=n.kind===`plan`;return(0,q.jsx)(`div`,{className:`flex justify-start mb-3`,children:(0,q.jsx)(`div`,{className:`max-w-[92%] md:max-w-[78%] rounded-2xl rounded-bl-sm bg-card ring-1 ring-amber-500/35 px-3.5 py-3 text-sm`,children:(0,q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[l?(0,q.jsx)(C,{className:`mt-0.5 h-4 w-4 shrink-0 text-amber-400`}):(0,q.jsx)(t,{className:`mt-0.5 h-4 w-4 shrink-0 text-amber-400`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`text-sm font-medium text-amber-100`,children:n.title}),n.body&&(l?(0,q.jsx)(`div`,{className:`mt-2 max-h-72 overflow-auto rounded-md bg-background/60 p-2.5 text-xs leading-relaxed`,children:(0,q.jsx)(U,{text:n.body,rawBody:n.body,className:`leading-relaxed`})}):(0,q.jsx)(`pre`,{className:`mt-2 max-h-44 overflow-auto whitespace-pre-wrap break-words rounded-md bg-background/80 p-2 font-mono text-xs leading-relaxed text-muted-foreground`,children:n.body})),(0,q.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:s.map(e=>(0,q.jsxs)(z,{size:`sm`,variant:e.id===`deny`||e.id===`abort`?`outline`:`default`,disabled:!!i,onClick:()=>void c(e),className:`h-7 px-2 text-xs`,children:[i===e.id&&(0,q.jsx)(k,{className:`mr-1.5 h-3 w-3 animate-spin`}),e.label]},e.id))})]})]})})})}function Vt(e){return e?e.otherActive&&e.other.trim()?!0:e.labels.length>0:!1}function Ht(e){let t=[...e.labels];return e.otherActive&&e.other.trim()&&t.push(e.other.trim()),t.join(`, `)}function Ut({agentId:e,approval:t,questions:n}){let r=M(e=>e.sendPermissionDecision),[a,o]=(0,G.useState)(0),[s,c]=(0,G.useState)({}),[l,u]=(0,G.useState)(null),d=n[Math.min(a,n.length-1)],f=s[a];if(!d)return null;let p=!!d.multiSelect,m=n.length,h=a===m-1,g=Vt(f),_=n.every((e,t)=>Vt(s[t])),v=!!l;function y(e){c(t=>{let n=t[a]??{labels:[],other:``,otherActive:!1};return{...t,[a]:{...n,...e}}})}function b(e){if(p){let t=f?.labels.includes(e);y({labels:t?(f?.labels??[]).filter(t=>t!==e):[...f?.labels??[],e]})}else y({labels:[e],otherActive:!1})}function S(){y(p?{otherActive:!f?.otherActive}:{labels:[],otherActive:!0})}async function C(){if(!(!_||v)){u(`answer`);try{let i={};n.forEach((e,t)=>{let n=s[t];n&&(i[e.question]=Ht(n))}),await r(e,t.id,`answer`,i)}finally{u(null)}}}async function w(){if(!v){u(`dismiss`);try{await r(e,t.id,`deny`)}finally{u(null)}}}let T=!!f?.otherActive;return(0,q.jsx)(`div`,{className:`flex justify-start mb-3`,children:(0,q.jsxs)(`div`,{className:`w-full max-w-[92%] md:max-w-[78%] rounded-2xl rounded-bl-sm bg-card ring-1 ring-amber-500/35 px-3.5 py-3 text-sm`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(x,{className:`h-4 w-4 shrink-0 text-amber-400`}),(0,q.jsx)(`div`,{className:`text-sm font-medium text-amber-100`,children:t.title}),m>1&&(0,q.jsxs)(Ie,{variant:`outline`,className:`ml-auto h-5 px-1.5 text-[10px] text-muted-foreground`,children:[a+1,` / `,m]})]}),(0,q.jsxs)(`div`,{className:`mt-3`,children:[d.header&&(0,q.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-amber-300/80`,children:d.header}),(0,q.jsx)(`div`,{className:`mt-0.5 text-sm text-foreground whitespace-pre-wrap break-words`,children:d.question}),p&&(0,q.jsx)(`div`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:`Select all that apply`}),(0,q.jsxs)(`div`,{className:`mt-2 flex flex-col gap-1.5`,children:[d.options.map(e=>{let t=!!f?.labels.includes(e.label);return(0,q.jsxs)(`button`,{type:`button`,disabled:v,onClick:()=>b(e.label),className:i(`flex items-start gap-2 rounded-lg border px-2.5 py-2 text-left transition-colors`,t?`border-amber-500/60 bg-amber-500/10`:`border-border bg-background/60 hover:bg-background`,v&&`opacity-60`),children:[(0,q.jsx)(`span`,{className:i(`mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center border text-amber-300`,p?`rounded`:`rounded-full`,t?`border-amber-400 bg-amber-400/20`:`border-muted-foreground/40`),children:t&&(0,q.jsx)(O,{className:`h-3 w-3`})}),(0,q.jsxs)(`span`,{className:`min-w-0`,children:[(0,q.jsx)(`span`,{className:`text-sm text-foreground`,children:e.label}),e.description&&(0,q.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.description})]})]},e.label)}),(0,q.jsxs)(`button`,{type:`button`,disabled:v,onClick:S,className:i(`flex items-start gap-2 rounded-lg border px-2.5 py-2 text-left transition-colors`,T?`border-amber-500/60 bg-amber-500/10`:`border-border bg-background/60 hover:bg-background`,v&&`opacity-60`),children:[(0,q.jsx)(`span`,{className:i(`mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center border text-amber-300`,p?`rounded`:`rounded-full`,T?`border-amber-400 bg-amber-400/20`:`border-muted-foreground/40`),children:T&&(0,q.jsx)(O,{className:`h-3 w-3`})}),(0,q.jsx)(`span`,{className:`text-sm text-foreground`,children:`Other…`})]}),T&&(0,q.jsx)(Qe,{autoFocus:!0,rows:2,disabled:v,value:f?.other??``,onChange:e=>y({other:e.target.value,otherActive:!0}),placeholder:`Type your answer`,className:`mt-1 text-sm`})]})]}),(0,q.jsxs)(`div`,{className:`mt-3 flex items-center gap-1.5`,children:[a>0&&(0,q.jsxs)(z,{size:`sm`,variant:`outline`,disabled:v,onClick:()=>o(e=>e-1),className:`h-7 px-2 text-xs`,children:[(0,q.jsx)(oe,{className:`mr-1 h-3 w-3`}),`Back`]}),h?(0,q.jsxs)(z,{size:`sm`,disabled:v||!_,onClick:()=>void C(),className:`h-7 px-2 text-xs`,children:[l===`answer`&&(0,q.jsx)(k,{className:`mr-1.5 h-3 w-3 animate-spin`}),`Send answer`,m>1?`s`:``]}):(0,q.jsxs)(z,{size:`sm`,disabled:v||!g,onClick:()=>o(e=>e+1),className:`h-7 px-2 text-xs`,children:[`Next`,(0,q.jsx)(de,{className:`ml-1 h-3 w-3`})]}),(0,q.jsxs)(z,{size:`sm`,variant:`ghost`,disabled:v,onClick:()=>void w(),className:`ml-auto h-7 px-2 text-xs text-muted-foreground`,children:[l===`dismiss`&&(0,q.jsx)(k,{className:`mr-1.5 h-3 w-3 animate-spin`}),`Dismiss`]})]})]})})}function Wt({date:e}){return(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-3 py-3 my-1`,children:[(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`}),(0,q.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:Ot(e)}),(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`})]})}function Gt({timestamp:e}){let t=new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,year:`numeric`,hour:`2-digit`,minute:`2-digit`});return(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-2 my-1`,children:[(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`}),(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground/60`,children:[`created `,t]}),(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`})]})}function Kt({history:e}){let t=e.sourceAgentLabel||e.sourcePeerId,n=e.entries.length;return(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-2 my-1`,children:[(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-full border border-dashed border-border bg-muted/30 px-2 py-1 text-[11px] text-muted-foreground`,children:[(0,q.jsx)(ge,{className:`h-3 w-3`}),(0,q.jsxs)(`span`,{children:[`forked history from `,t]}),(0,q.jsxs)(`span`,{className:`text-muted-foreground/60`,children:[n,` `,n===1?`entry`:`entries`]})]}),(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`})]})}function qt({entry:e,sourceLabel:t}){let n=e.message,r=Fe(n),a=e.originalFrom===Ce;return(0,q.jsx)(`div`,{className:i(`flex mb-3 opacity-80`,a?`justify-end`:`justify-start`),children:(0,q.jsx)(`div`,{className:`max-w-[85%] md:max-w-[75%]`,children:(0,q.jsxs)(`div`,{className:i(`rounded-2xl border border-dashed px-3.5 py-2 text-sm select-text`,a?`border-primary/25 bg-primary/10 text-foreground rounded-br-sm`:`border-border bg-card/70 rounded-bl-sm`),children:[(0,q.jsxs)(`div`,{className:i(`mb-1 text-[10px] uppercase tracking-normal`,a?`text-primary/70`:`text-muted-foreground`),children:[`forked history · `,a?`you`:t||e.originalFrom]}),(0,q.jsx)(U,{text:r,rawBody:n.body,className:`leading-relaxed`}),(0,q.jsxs)(`p`,{className:i(`mt-1 flex items-center justify-end gap-1.5 text-xs`,a?`text-primary/60`:`text-muted-foreground`),children:[(0,q.jsxs)(`span`,{className:`opacity-40`,children:[`#`,e.originalMessageId]}),(0,q.jsx)(`span`,{children:Et(e.originalCreatedAt)})]})]})})})}function Jt({attachment:e,outbound:n}){let r=e.kind===`image`,a=e.title||e.artifactId,[o,s]=(0,G.useState)(null),[c,l]=(0,G.useState)(null),[u,d]=(0,G.useState)(!1),[f,p]=(0,G.useState)(!1);(0,G.useEffect)(()=>{let t=!1,n=null;async function r(){d(!0),l(null),s(null);try{let r=await re(`/artifacts/${encodeURIComponent(e.artifactId)}/content`);if(t)return;n=URL.createObjectURL(r),s(n)}catch(e){t||l(e.message)}finally{t||d(!1)}}return r(),()=>{t=!0,n&&URL.revokeObjectURL(n)}},[e.artifactId]);function m(){if(!o)return;let e=document.createElement(`a`);e.href=o,e.download=a,document.body.appendChild(e),e.click(),e.remove()}return r?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>o&&p(!0),disabled:!o,className:`group/img mt-2 block overflow-hidden rounded-md border border-foreground/10 bg-black/10 text-left disabled:cursor-default relative`,children:o?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`img`,{src:o,alt:a,loading:`lazy`,className:`block max-h-72 max-w-full object-contain`}),(0,q.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center bg-black/0 group-hover/img:bg-black/30 transition-colors`,children:(0,q.jsx)(ce,{className:`w-6 h-6 text-white opacity-0 group-hover/img:opacity-100 transition-opacity drop-shadow-md`})})]}):(0,q.jsxs)(`span`,{className:i(`flex min-h-20 items-center gap-2 px-3 py-2 text-xs`,c?`text-red-400`:`text-muted-foreground`),children:[u?(0,q.jsx)(k,{className:`h-4 w-4 animate-spin`}):(0,q.jsx)(t,{className:`h-4 w-4`}),c||`Loading image`]})}),o&&(0,q.jsx)(Je,{open:f,onOpenChange:p,children:(0,q.jsxs)(We,{className:`max-w-[95vw] max-h-[95vh] w-auto p-0 bg-black/95 border-zinc-800 gap-0 overflow-hidden`,showCloseButton:!1,children:[(0,q.jsx)(Xe,{className:`sr-only`,children:a}),(0,q.jsxs)(`div`,{className:`relative flex items-center justify-center min-h-[200px]`,children:[(0,q.jsx)(`img`,{src:o,alt:a,className:`max-w-[93vw] max-h-[90vh] object-contain`}),(0,q.jsxs)(`div`,{className:`absolute top-2 right-2 flex gap-1`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:m,className:`rounded-md bg-black/60 hover:bg-black/80 p-2 text-white transition-colors`,title:`Download`,children:(0,q.jsx)(g,{className:`w-4 h-4`})}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>p(!1),className:`rounded-md bg-black/60 hover:bg-black/80 p-2 text-white transition-colors`,title:`Close`,children:(0,q.jsx)(D,{className:`w-4 h-4`})})]})]})]})})]}):(0,q.jsxs)(`button`,{type:`button`,onClick:m,disabled:!o,className:i(`mt-2 flex w-full items-center gap-2 rounded-md border px-2.5 py-2 text-left text-xs transition-colors disabled:cursor-default disabled:opacity-70`,n?`border-primary-foreground/20 bg-primary-foreground/10 hover:bg-primary-foreground/15`:`border-border bg-background hover:bg-muted`),children:[u?(0,q.jsx)(k,{className:`h-4 w-4 shrink-0 animate-spin`}):c?(0,q.jsx)(t,{className:`h-4 w-4 shrink-0 text-red-400`}):(0,q.jsx)(ae,{className:`h-4 w-4 shrink-0`}),(0,q.jsx)(`span`,{className:i(`min-w-0 flex-1 truncate`,c&&`text-red-400`),children:c||a}),(0,q.jsx)(g,{className:`h-3.5 w-3.5 shrink-0`})]})}function Yt({item:e,onRemove:n}){let[r,a]=(0,G.useState)(!1),o=!!(e.previewUrl&&!e.error);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 rounded-md border border-border bg-card px-2.5 py-2 text-xs`,children:[(0,q.jsx)(`button`,{type:`button`,disabled:!o,onClick:()=>a(!0),className:`group/pending relative flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded bg-muted disabled:cursor-default`,title:o?`Preview image`:e.fileName,children:e.previewUrl?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`img`,{src:e.previewUrl,alt:e.fileName,className:`h-full w-full object-cover`}),(0,q.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center bg-black/0 group-hover/pending:bg-black/30 transition-colors`,children:(0,q.jsx)(ce,{className:`h-3.5 w-3.5 text-white opacity-0 group-hover/pending:opacity-100 transition-opacity drop-shadow-md`})})]}):e.error?(0,q.jsx)(t,{className:`h-4 w-4 text-red-400`}):e.uploading?(0,q.jsx)(k,{className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,q.jsx)(ae,{className:`h-4 w-4 text-muted-foreground`})}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`p`,{className:`truncate font-medium`,children:e.fileName}),(0,q.jsx)(`p`,{className:i(`truncate text-muted-foreground`,e.error&&`text-red-400`),children:e.error||(e.uploading?`Uploading`:ct(e.size))})]}),(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,title:`Remove attachment`,onClick:n,children:(0,q.jsx)(D,{className:`h-3.5 w-3.5`})})]}),e.previewUrl&&(0,q.jsx)(Je,{open:r,onOpenChange:a,children:(0,q.jsxs)(We,{className:`max-w-[95vw] max-h-[95vh] w-auto p-0 bg-black/95 border-zinc-800 gap-0 overflow-hidden`,showCloseButton:!1,children:[(0,q.jsx)(Xe,{className:`sr-only`,children:e.fileName}),(0,q.jsxs)(`div`,{className:`relative flex items-center justify-center min-h-[200px]`,children:[(0,q.jsx)(`img`,{src:e.previewUrl,alt:e.fileName,className:`max-w-[93vw] max-h-[90vh] object-contain`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`absolute top-2 right-2 rounded-md bg-black/60 hover:bg-black/80 p-2 text-white transition-colors`,title:`Close`,children:(0,q.jsx)(D,{className:`w-4 h-4`})})]})]})})]})}function Xt({preview:e,error:t,onReadError:n,onMouseEnter:r,onMouseLeave:i}){let{anchor:a}=e,o=Math.min(560,window.innerWidth-24),s=Math.min(380,window.innerHeight-24),c=Math.max(12,Math.min(a.left,window.innerWidth-o-12));return(0,K.createPortal)((0,q.jsxs)(`div`,{className:`fixed z-50 flex flex-col overflow-hidden rounded-lg border border-border bg-background shadow-xl`,style:{top:window.innerHeight-a.bottom>=s+8?a.bottom+8:a.top-8-s>=12?a.top-8-s:Math.max(12,window.innerHeight-s-12),left:c,width:o,height:s},onMouseEnter:r,onMouseLeave:i,children:[(0,q.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center gap-2 border-b border-border px-2.5`,children:[(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] font-medium text-muted-foreground`,children:e.path}),t&&(0,q.jsx)(`span`,{className:`max-w-[12rem] truncate text-[11px] text-red-400`,children:t}),(0,q.jsx)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground/70`,children:`click to pin`})]}),(0,q.jsx)(`div`,{className:`min-h-0 flex-1`,children:e.type===`directory`?(0,q.jsx)($e,{orchestratorId:e.orchestratorId,selectedPath:e.path,onReadError:n}):(0,q.jsx)(et,{orchestratorId:e.orchestratorId,selectedPath:e.path,line:e.line,onReadError:n})})]}),document.body)}function Z({open:e,onToggle:t,onReact:n}){return(0,q.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,q.jsx)(`button`,{type:`button`,title:`Add reaction`,onClick:t,className:i(`inline-flex h-5 w-6 items-center justify-center rounded-full border border-border bg-popover text-muted-foreground shadow-sm transition hover:bg-muted hover:text-foreground`,e?`opacity-100`:`opacity-0 pointer-events-none md:group-hover/msg:opacity-100 md:group-hover/msg:pointer-events-auto`),children:(0,q.jsx)(w,{className:`h-3 w-3`})}),e&&(0,q.jsx)(`div`,{className:`absolute bottom-full left-0 z-30 mb-1 flex gap-0.5 rounded-full border border-border bg-popover p-0.5 shadow-md`,children:J.map(e=>(0,q.jsx)(`button`,{type:`button`,title:`React ${e}`,onClick:()=>n(e),className:`inline-flex h-6 w-7 items-center justify-center rounded-full text-xs transition-colors hover:bg-muted`,children:e},e))})]})}function Zt(){return(0,G.useSyncExternalStore)(e=>ve.subscribe(e),()=>ve.getPlayingKey(),()=>null)}var Qt=(0,G.memo)(function({msg:e,peer:t,onOpenReferencedPath:n,onPreviewReferencedPath:r,onPreviewReferencedPathEnd:a}){let o=e.from===Ce,s=M(e=>e.reactToMessage),c=M(e=>e.voiceTtsEnabled),l=Zt(),u=M(e=>{let n=e.agentsById[t]?.meta?.cwd;return typeof n==`string`?n:``}),[d,f]=(0,G.useState)(!1),p=(0,G.useRef)(null),h=(0,G.useRef)(null),g=(0,G.useRef)(!1),_=Fe(e),v=Et(e.occurredAt??e.createdAt),y=mt(e),b=ht(e),x=o?gt(e,t):null,S=x?.icon,C=l===String(e.id),w=c&&!o&&!Y(e)&&_.trim().length>0;function ee(t){t.stopPropagation(),C?ve.bargeIn():ve.speak(e.body,String(e.id))}(0,G.useEffect)(()=>{if(!d)return;function e(e){pt()||p.current&&!p.current.contains(e.target)&&f(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e)}},[d]);function E(e){return lt(u||`/`,e)}function te(e,t){let r=E(e);n?.(r,t)}function ne(e,t,n){let i=E(e);r?.(i,t,n)}function D(t){s(e,t),f(!1)}function O(e){e.button===0&&(h.current={x:e.clientX,y:e.clientY},g.current=!1)}function k(e){let t=h.current;t&&(Math.abs(e.clientX-t.x)>3||Math.abs(e.clientY-t.y)>3)&&(g.current=!0)}function re(t){if(!(Y(e)||o)&&!t.target.closest(`a,button,input,textarea,select,[role="button"]`)){if(g.current||pt()){g.current=!1;return}f(e=>!e)}}return(0,q.jsx)(`div`,{"data-msg-id":e.id,className:i(`group/msg flex mb-3`,o?`justify-end`:`justify-start`),children:(0,q.jsxs)(`div`,{ref:p,className:`relative max-w-[85%] md:max-w-[75%]`,children:[w&&(0,q.jsx)(`button`,{type:`button`,title:C?`Stop playback`:`Play aloud`,onClick:ee,className:i(`absolute -top-2 -right-2 z-20 inline-flex h-6 w-6 items-center justify-center rounded-full border bg-popover shadow-sm transition`,C?`border-primary/50 text-primary opacity-100`:`border-border text-muted-foreground opacity-70 hover:bg-muted hover:text-foreground hover:opacity-100 [@media(hover:hover)]:md:opacity-0 [@media(hover:hover)]:md:group-hover/msg:opacity-100`),children:C?(0,q.jsx)(m,{className:`h-3.5 w-3.5 animate-pulse`}):(0,q.jsx)(T,{className:`h-3.5 w-3.5`})}),(0,q.jsxs)(`div`,{className:i(`rounded-2xl px-3.5 py-2 text-sm select-text`,!o&&!Y(e)&&`cursor-pointer`,o?`bg-primary text-primary-foreground rounded-br-sm`:`bg-card ring-1 ring-foreground/10 rounded-bl-sm`),onPointerDown:O,onPointerMove:k,onClick:re,children:[e.subject&&(0,q.jsx)(`p`,{className:i(`text-xs font-semibold mb-1`,o?`text-primary-foreground/70`:`text-muted-foreground`),children:e.subject}),(0,q.jsx)(U,{text:_,rawBody:e.body,className:`leading-relaxed`,onOpenPath:te,onPreviewPath:ne,onPreviewPathEnd:a,resolvePathTitle:(e,t)=>`${E(e)}${t?`:${t}`:``}`}),y.map(t=>(0,q.jsx)(Jt,{attachment:t,outbound:o},`${e.id}-${t.artifactId}-${t.role||``}`)),(0,q.jsxs)(`p`,{className:i(`text-xs mt-1 flex items-center gap-1.5`,o?`justify-end text-primary-foreground/60`:`justify-end text-muted-foreground`),children:[(0,q.jsxs)(`span`,{className:`opacity-40`,children:[`#`,e.id]}),(0,q.jsx)(`span`,{children:v}),x&&S&&(0,q.jsxs)(`span`,{className:i(`inline-flex items-center gap-1`,x.tone===`ok`&&`text-emerald-300`,x.tone===`warn`&&`text-amber-200`,x.tone===`danger`&&`text-red-200`),title:x.title,children:[(0,q.jsx)(S,{className:`h-3 w-3`}),x.label]})]})]}),!Y(e)&&b.length>0&&(0,q.jsxs)(`div`,{className:i(`flex flex-wrap items-center gap-0.5 -mt-1 relative z-10`,o?`justify-end pr-2`:`justify-start pl-2`),children:[!o&&(0,q.jsx)(Z,{open:d,onToggle:()=>f(e=>!e),onReact:D}),b.map(e=>(0,q.jsxs)(`button`,{type:`button`,title:e.actors.join(`, `),onClick:()=>D(e.emoji),className:i(`inline-flex h-5 items-center gap-0.5 rounded-full border px-1.5 text-[11px] shadow-sm transition-colors`,e.mine?`border-primary/40 bg-primary/10 text-primary`:`border-border bg-background hover:bg-muted text-foreground`),children:[(0,q.jsx)(`span`,{children:e.emoji}),e.count>1&&(0,q.jsx)(`span`,{children:e.count})]},e.emoji))]}),!Y(e)&&!o&&b.length===0&&(0,q.jsx)(`div`,{className:`absolute -bottom-2.5 left-1 z-20`,children:(0,q.jsx)(Z,{open:d,onToggle:()=>f(e=>!e),onReact:D})})]})})});function $t(e){if(e.kind!==`session`)return null;let t=e.payload?.session;return!t||t.type!==`narration`&&t.type!==`reasoning`&&t.type!==`tool`?null:{id:e.id,kind:t.type,label:typeof t.label==`string`?t.label:void 0,text:e.body,ts:Dt(e),turnId:typeof t.turnId==`string`?t.turnId:void 0}}function en(e){let t=new Date(e);return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}function tn(e){let t=e.filter(e=>jt.has(e.status)).slice().sort((e,t)=>e.timestamp-t.timestamp),n=[];for(let e of t)n.some(t=>t.id===e.id)||n.some(t=>t.status===e.status&&Math.abs(t.timestamp-e.timestamp)<=Mt)||n.push(e);return n}function Q(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=Nt}function nn(e,t){let n=(0,G.useRef)(null),r=(0,G.useRef)(!0),i=(0,G.useRef)(null),a=(0,G.useCallback)(()=>{let e=n.current;e&&(r.current=Q(e))},[]);return(0,G.useLayoutEffect)(()=>{let t=n.current;t&&(i.current!==e&&(i.current=e,r.current=!0),r.current&&(t.scrollTop=t.scrollHeight))},[e,...t]),{ref:n,onScroll:a}}function rn(e){for(let t of e)t.previewUrl&&URL.revokeObjectURL(t.previewUrl)}function an(e,t,n,r=[]){let i=[];for(let e of r){let t=e.entries.reduce((e,t)=>Math.min(e,R(t.originalCreatedAt)),1/0),n=Number.isFinite(t)?t-1:e.importedAt;i.push({ts:n,entry:{type:`import-boundary`,history:e,timestamp:n}});for(let t of e.entries)i.push({ts:R(t.originalCreatedAt),entry:{type:`imported-message`,history:e,entry:t}})}if(n){let e=new Date(n).getTime();Number.isFinite(e)&&i.push({ts:e,entry:{type:`created`,timestamp:e}})}let a=new Set;for(let t of e){if(t.kind!==`session`)continue;let e=t.payload?.session;e?.type===`response`&&typeof e.turnId==`string`&&a.add(`${e.turnId} ${t.body.trim()}`)}for(let t of e){if(Y(t))continue;let e=$t(t);if(e){if(e.kind===`narration`&&e.turnId&&a.has(`${e.turnId} ${e.text.trim()}`))continue;i.push({ts:e.ts,entry:{type:`activity`,steps:[e],timestamp:e.ts}});continue}i.push({ts:Dt(t),entry:{type:`message`,msg:t}})}for(let e of tn(t))i.push({ts:e.timestamp,entry:{type:`status`,event:e}});let o={created:0,date:1,"import-boundary":2,"imported-message":3,message:4,activity:4,status:5};i.sort((e,t)=>{let n=e.ts-t.ts;return Math.abs(n)<3e3&&o[e.entry.type]-o[t.entry.type]||n});let s=[],c=``;for(let{ts:e,entry:t}of i){if(t.type===`created`){s.push(t);continue}let n=en(e);if(n!==c&&(s.push({type:`date`,date:n,timestamp:e}),c=n),t.type===`activity`){let e=s[s.length-1];if(e&&e.type===`activity`&&on(e,t)){e.steps.push(...t.steps);continue}}s.push(t)}return s}function on(e,t){let n=e.steps[e.steps.length-1]?.turnId,r=t.steps[0]?.turnId;return n&&r?n===r:!n&&!r}function sn({scrollRef:e,timeline:t}){let[n,r]=(0,G.useState)(!0),[a,o]=(0,G.useState)(!1),[s,c]=(0,G.useState)(!1),[l,u]=(0,G.useState)(!0),d=(0,G.useMemo)(()=>{for(let e=t.length-1;e>=0;e--){let n=t[e];if(!(!n||n.type!==`message`)&&n.msg.from===`user`)return{id:n.msg.id,body:Fe(n.msg)}}return null},[t]);if((0,G.useEffect)(()=>{let t=e.current;if(!d||!t){r(!0);return}let n=t.querySelector(`[data-msg-id="${d.id}"]`);if(!n){r(!0);return}let i=new IntersectionObserver(([e])=>{if(e&&(r(e.isIntersecting),!e.isIntersecting)){let n=e.rootBounds?.top??t.getBoundingClientRect().top;u(e.boundingClientRect.top<n)}},{root:t,threshold:0});i.observe(n);let a=()=>{let e=n.getBoundingClientRect(),r=t.getBoundingClientRect();u(e.top<r.top)};return t.addEventListener(`scroll`,a,{passive:!0}),()=>{i.disconnect(),t.removeEventListener(`scroll`,a)}},[d?.id,e]),(0,G.useEffect)(()=>{o(!1),c(!1)},[d?.id]),n||!d||!d.body.trim())return null;function f(){let t=e.current;!t||!d||t.querySelector(`[data-msg-id="${d.id}"]`)?.scrollIntoView({behavior:`smooth`,block:`center`})}let p=l?`↑`:`↓`;return s?(0,q.jsx)(`div`,{className:`sticky top-0 z-10 -mx-3 md:-mx-4 -mt-3 md:-mt-4 bg-background`,children:(0,q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center justify-center gap-1.5 py-1 text-[11px] text-primary/60 hover:text-primary border-b border-primary/10 transition-colors`,onClick:()=>c(!1),children:[(0,q.jsx)(`span`,{children:`Your prompt`}),(0,q.jsx)(le,{className:`w-3 h-3`})]})}):(0,q.jsxs)(`div`,{className:`sticky top-0 z-10 -mx-3 md:-mx-4 -mt-3 md:-mt-4 px-2 md:px-3 pt-2 pb-1.5 bg-background border-b border-primary/10`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-muted-foreground mb-0.5`,children:[(0,q.jsx)(`span`,{className:`font-medium text-primary/70`,children:`Your prompt`}),(0,q.jsxs)(`button`,{type:`button`,className:`ml-auto hover:text-foreground transition-colors`,onClick:f,children:[p,` scroll to original`]}),(0,q.jsx)(`button`,{type:`button`,className:`hover:text-foreground transition-colors`,onClick:()=>c(!0),title:`Minimize`,children:(0,q.jsx)(E,{className:`w-3 h-3`})})]}),(0,q.jsx)(`p`,{className:i(`text-sm text-foreground leading-snug cursor-pointer`,!a&&`line-clamp-2`),onClick:()=>o(e=>!e),children:d.body})]})}function $({threads:e,onBack:t,showBackButton:r}){let d=M(e=>e.selectedInboxThread),y=M(e=>e.agentsById),b=M(e=>e.inboxDrafts),x=ye(),S=M(e=>e.sendChatMessage),C=M(e=>e.openFilesAt),w=M(e=>e.openFilesForAgent),ee=M(e=>e.openAgentDetail),E=M(e=>e.chatSending),O=M(e=>e.markInboxThreadRead),re=M(e=>e.markInboxThreadUnread),ie=M(e=>e.setReplyDraft),ae=M(e=>e.exportThread),A=M(e=>e.doAgentAction),oe=M(e=>e.workspaceAction),se=M(e=>e.openWorkspaceFocus),ce=M(e=>e.forkFromAgent),le=M(e=>e.chatHistoryImports),de=M(e=>e.threadHistory[e.selectedInboxThread]??bt),j=M(e=>e.openConfirm),pe=M(e=>e.showError),he=M(e=>e.orchestrators),_e=M(e=>e.fetchOrchestrators),Ce=M(e=>e.showReasoning),N=M(e=>e.voiceTtsEnabled),we=M(e=>e.setVoiceTtsEnabled),Te=M(e=>e.voiceInputMode),De=(0,G.useRef)(null),ke=(0,G.useRef)(null),[P,je]=(0,G.useState)(`idle`),Me=(0,G.useRef)([]),[F,I]=(0,G.useState)([]),[Fe,R]=(0,G.useState)(!1),[B,Be]=(0,G.useState)(null),[We,qe]=(0,G.useState)(null),[Je,V]=(0,G.useState)(``),H=(0,G.useRef)(null),Xe=(0,G.useRef)(0),Qe=xt(d),U=(0,G.useMemo)(()=>e.find(e=>e.peer===d)||null,[e,d]),tt=(0,G.useMemo)(()=>{let e=U?.messages??[];if(de.length===0)return e;let t=new Map;for(let e of de)Ne(e)===d&&!Ae(e)&&t.set(e.id,e);for(let n of e)t.set(n.id,n);return[...t.values()].sort((e,t)=>e.id-t.id)},[U?.messages,de,d]),K=y[d]||null,it=typeof K?.meta?.lifecycleAction==`string`&&K.meta.lifecycleAction.startsWith(`finalizing-`),{terminalOpen:at,terminalTarget:ot,terminalOpening:ct,openTerminal:lt,closeTerminal:pt}=nt(K?.id),mt=typeof K?.meta?.spawnRequestId==`string`?K.meta.spawnRequestId:``,J=(0,G.useMemo)(()=>le.filter(e=>e.targetAgentId===d||!!(mt&&e.targetSpawnRequestId===mt)),[mt,le,d]),ht=Oe(K),Y=ht?.pendingApproval,gt=U||(J.length>0?{peer:d,messages:[],importedHistory:J}:null),X=b[d]||``,_t=J.reduce((e,t)=>e+t.entries.length,0),vt=nn(d,[tt.length,Qe.length,_t,Y?.id,K?.status]),yt=typeof K?.meta?.tmuxSession==`string`&&K.meta.tmuxSession.trim()?K.meta.tmuxSession:null,Ct=yt?he.find(e=>e.managedAgents?.some(e=>e.agentId===K.id||e.tmuxSession===yt))??null:null,Tt=!!(yt&&Ct?.status===`online`&&K?.providerCapabilities?.terminal?.live?.read),Et=K?.providerCapabilities?.model?.provider??(typeof K?.meta?.provider==`string`?K.meta.provider:void 0),Dt=!!(Tt&&(K?.providerCapabilities?.terminal?.live?.write||Et===`claude`)),Ot=K?.providerCapabilities?.terminal?.attach?.create===!0,kt=Tt||Ot,At=Pe(K,`compact`),jt=Pe(K,`clearContext`),Mt=Pe(K,`shutdown`),Nt=Pe(K,`interrupt`),It=()=>{K&&A(K,`interrupt`)},[Lt,Rt]=(0,G.useState)(0),[Vt,Ht]=(0,G.useState)(!1),Ut=K?.providerCapabilities?.liveSession?.slashCommands===!0,Jt=K?.providerCapabilities?.model?.provider??(typeof K?.meta?.provider==`string`?K.meta.provider:void 0),Z=Ut&&!Vt&&/^\/\S*$/.test(X)?st(Jt).filter(e=>e.name.toLowerCase().startsWith(X.toLowerCase())):[],Zt=Z.length?Math.min(Lt,Z.length-1):0;function $t(e){ie(d,`${e.name} `),Rt(0)}function en(e){ie(d,e),Vt&&Ht(!1),Rt(0)}let tn=F.some(e=>e.uploading),Q=F.filter(e=>e.artifact);St(X.trim().length>0||F.length>0,(0,G.useCallback)(()=>{},[])),Me.current=F,(0,G.useEffect)(()=>()=>{rn(Me.current)},[]),(0,G.useEffect)(()=>{K?.meta?.tmuxSession&&he.length===0&&_e()},[K?.id,K?.meta?.tmuxSession,he.length]),(0,G.useEffect)(()=>()=>{H.current!==null&&window.clearTimeout(H.current)},[]);let on=(0,G.useMemo)(()=>an(tt,Qe,K?.createdAt,J),[tt,Qe,K?.createdAt,J]),$=(0,G.useCallback)(()=>{H.current!==null&&(window.clearTimeout(H.current),H.current=null)},[]),cn=(0,G.useCallback)(async e=>{let t=dt(he,e);if(!t)return null;try{let r=await n(`GET`,`/orchestrators/${encodeURIComponent(t.id)}/files/stat?path=${encodeURIComponent(e)}`);return{orchestratorId:t.id,path:r.path,type:r.type}}catch{return null}},[he]),ln=(0,G.useCallback)((e,t,n)=>{if(!ft()||!n)return;let r=++Xe.current;cn(e).then(e=>{Xe.current===r&&e&&($(),qe({...e,line:t||0,anchor:n}),V(``))})},[$,cn]),un=(0,G.useCallback)(()=>{Xe.current+=1,$(),H.current=window.setTimeout(()=>{qe(null)},250)},[$]),dn=(0,G.useCallback)((e,t)=>{cn(e).then(n=>{if(!n){pe(`File Not Found`,e);return}if(ft()){Xe.current+=1,$(),qe(null),Be({...n,line:t||0}),V(``);return}n.type===`directory`?C({orchestratorId:n.orchestratorId,path:n.path,overlay:!0}):C({orchestratorId:n.orchestratorId,path:ut(n.path),selectedPath:n.path,line:t,overlay:!0})})},[$,C,cn,pe]);function fn(){Be(null),V(``)}async function pn(e){let t=Array.from(e).filter(e=>e.size>0);if(!t.length)return;let n=t.map(e=>({id:`${Date.now()}-${e.name}-${Math.random().toString(16).slice(2)}`,fileName:e.name,size:e.size,previewUrl:e.type.startsWith(`image/`)?URL.createObjectURL(e):void 0,uploading:!0}));I(e=>[...e,...n]);for(let e=0;e<t.length;e+=1){let r=t[e],i=n[e];try{let e=await v(`/artifacts`,r,{filename:r.name,sensitivity:`normal`});I(t=>t.map(t=>t.id===i.id?{...t,artifact:e,uploading:!1}:t))}catch(e){I(t=>t.map(t=>t.id===i.id?{...t,error:e.message,uploading:!1}:t))}}}function mn(e){I(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})}function hn(){rn(F),I([])}function gn(){if(!X.trim()&&Q.length===0||!d||E||tn||it)return;let e=Q.map(e=>({artifactId:e.artifact.id,kind:e.artifact.kind,role:`media`,title:e.artifact.filename||e.fileName}));S(X,{peer:d,lastMessage:U?.lastMessage||null},e),hn()}function _n(e){if(Z.length){if(e.key===`ArrowDown`){e.preventDefault(),Rt(e=>Math.min(e+1,Z.length-1));return}if(e.key===`ArrowUp`){e.preventDefault(),Rt(e=>Math.max(e-1,0));return}if(e.key===`Escape`){e.preventDefault(),Ht(!0);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let t=Z[Zt];t&&$t(t);return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),gn())}function vn(e){let t=Array.from(e.clipboardData.files).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),pn(t))}async function yn(){if(!be||P!==`idle`||!d)return;ve.bargeIn();let e=new xe;try{await e.start(),ke.current=e,je(`recording`)}catch(e){ke.current=null,je(`idle`),pe(`Microphone unavailable`,e?.message||`Could not access the microphone.`)}}async function bn(){let e=ke.current;if(!(!e||P!==`recording`)){ke.current=null,je(`transcribing`);try{let t=await e.stop();if(!t)return;let n=await Se(t);if(!n)return;let r=X?`${X} ${n}`:n;if(Te===`autosend`&&!E&&!tn){let e=Q.map(e=>({artifactId:e.artifact.id,kind:e.artifact.kind,role:`media`,title:e.artifact.filename||e.fileName}));S(r,{peer:d,lastMessage:U?.lastMessage||null},e),hn()}else ie(d,r)}catch(e){pe(`Transcription failed`,e?.message||`Could not transcribe audio.`)}finally{je(`idle`)}}}return d?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`flex h-full min-w-0`,children:[(0,q.jsxs)(`div`,{className:`@container/chat flex h-full min-w-0 flex-1 flex-col`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between px-3 md:px-4 py-2.5 md:py-3 border-b border-border shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 md:gap-2.5 min-w-0`,children:[r&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,onClick:t,className:`shrink-0 -ml-1`,children:(0,q.jsx)(me,{className:`w-4 h-4`})}),(0,q.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 md:gap-2.5 min-w-0 hover:opacity-80 transition-opacity`,onClick:()=>K&&ee(K),disabled:!K,children:[(0,q.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,q.jsx)(Ke,{agent:K}),(0,q.jsx)(Ue,{agent:K,now:x,className:`absolute -bottom-0.5 -right-0.5 w-2 h-2`})]}),(0,q.jsxs)(`div`,{className:`min-w-0 text-left`,children:[(0,q.jsx)(`p`,{className:`text-sm font-medium truncate`,children:K?L(K):d}),K&&(0,q.jsxs)(`p`,{className:`text-xs text-muted-foreground truncate`,children:[ht?`blocked: ${ht.label}`:K.status,K.machine&&` · ${K.machine}`,typeof K.meta?.cwd==`string`&&K.meta.cwd&&` · ${Ee(K.meta.cwd,1)}`]})]})]}),K&&(0,q.jsx)(Ge,{agent:K,compact:!0,className:`hidden @4xl/chat:flex shrink-0`}),K?.context&&(0,q.jsx)(Ze,{utilization:K.context.utilization}),K?.branchState&&K.branchWorkspaceId&&(0,q.jsx)(rt,{state:K.branchState,className:`shrink-0`,onClick:()=>void se(K.branchWorkspaceId)}),U?.attention.unread?(0,q.jsxs)(Ie,{className:`bg-red-500/20 text-red-400 text-xs shrink-0 hidden @2xl/chat:flex`,children:[U.attention.unread,` unread`]}):null]}),(0,q.jsx)(`div`,{className:`flex items-center gap-0.5 md:gap-1 shrink-0`,children:K&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Le,{value:K.id,label:`Copy agent ID`,size:`icon-sm`}),ve.available&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,title:N?`Speaking agent responses aloud — click to mute (engine & voice in Settings)`:`Speak agent responses aloud (active chat) — engine & voice in Settings`,className:N?`text-primary`:``,onClick:()=>we(!N),children:N?(0,q.jsx)(T,{className:`w-3.5 h-3.5`}):(0,q.jsx)(ue,{className:`w-3.5 h-3.5`})}),kt&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,disabled:ct,title:`Terminal`,onClick:()=>void lt(),children:(0,q.jsx)(ne,{className:`w-3.5 h-3.5`})}),Nt&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`text-red-400 hover:text-red-300`,title:`Interrupt`,onClick:It,children:(0,q.jsx)(m,{className:`w-3.5 h-3.5`})}),(K.branchState===`changes`||K.branchState===`idle`)&&K.branchWorkspaceId&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex text-amber-400 hover:text-amber-300`,title:`Mark workspace ready — hand off to the auto-merge`,onClick:()=>j(`Mark Workspace Ready`,`Mark ${L(K)}'s branch ready to land? The relay auto-merge will rebase and land it.`,()=>oe(K.branchWorkspaceId,`ready`)),children:(0,q.jsx)(a,{className:`w-3.5 h-3.5`})}),At&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Compact`,onClick:()=>j(`Compact Agent`,`Compact context for ${L(K)}?`,()=>A(K,`compact`)),children:(0,q.jsx)(l,{className:`w-3.5 h-3.5`})}),jt&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Clear context`,onClick:()=>j(`Clear Context`,`Clear context for ${L(K)}?`,()=>A(K,`clearContext`)),children:(0,q.jsx)(c,{className:`w-3.5 h-3.5`})}),Mt&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Shutdown`,onClick:()=>j(`Shutdown Agent`,`Shutdown ${L(K)}?`,()=>A(K,`shutdown`)),children:(0,q.jsx)(_,{className:`w-3.5 h-3.5`})}),K&&typeof K.meta?.cwd==`string`&&K.meta.cwd&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Open ${K.meta.cwd} in Files`,onClick:()=>void w(K),children:(0,q.jsx)(s,{className:`w-3.5 h-3.5`})}),K&&U&&U.messages.length>0&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Fork — spawn new agent with this chat history`,onClick:()=>ce(K.id,U.messages),children:(0,q.jsx)(ge,{className:`w-3.5 h-3.5`})}),U&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Mark unread`,onClick:()=>re(d),children:(0,q.jsx)(te,{className:`w-3.5 h-3.5`})}),U&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Mark read`,onClick:()=>O(U.peer,U.messages),children:(0,q.jsx)(fe,{className:`w-3.5 h-3.5`})}),gt&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Export thread`,onClick:()=>ae({...gt,importedHistory:J},`json`),children:(0,q.jsx)(g,{className:`w-3.5 h-3.5`})}),(0,q.jsxs)(Ve,{children:[(0,q.jsx)(ze,{asChild:!0,children:(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`@4xl/chat:hidden`,children:(0,q.jsx)(f,{className:`w-3.5 h-3.5`})})}),(0,q.jsxs)(Re,{align:`end`,children:[kt&&(0,q.jsxs)(W,{disabled:ct,onClick:()=>void lt(),children:[(0,q.jsx)(ne,{className:`w-3.5 h-3.5`}),`Terminal`]}),Nt&&(0,q.jsxs)(W,{onClick:It,children:[(0,q.jsx)(m,{className:`w-3.5 h-3.5`}),`Interrupt`]}),(K.branchState===`changes`||K.branchState===`idle`)&&K.branchWorkspaceId&&(0,q.jsxs)(W,{onClick:()=>j(`Mark Workspace Ready`,`Mark ${L(K)}'s branch ready to land? The relay auto-merge will rebase and land it.`,()=>oe(K.branchWorkspaceId,`ready`)),children:[(0,q.jsx)(a,{className:`w-3.5 h-3.5`}),`Mark Ready`]}),At&&(0,q.jsxs)(W,{onClick:()=>j(`Compact Agent`,`Compact context for ${L(K)}?`,()=>A(K,`compact`)),children:[(0,q.jsx)(l,{className:`w-3.5 h-3.5`}),`Compact`]}),jt&&(0,q.jsxs)(W,{onClick:()=>j(`Clear Context`,`Clear context for ${L(K)}?`,()=>A(K,`clearContext`)),children:[(0,q.jsx)(c,{className:`w-3.5 h-3.5`}),`Clear Context`]}),Mt&&(0,q.jsxs)(W,{onClick:()=>j(`Shutdown Agent`,`Shutdown ${L(K)}?`,()=>A(K,`shutdown`)),children:[(0,q.jsx)(_,{className:`w-3.5 h-3.5`}),`Shutdown`]}),K&&typeof K.meta?.cwd==`string`&&K.meta.cwd&&(0,q.jsxs)(W,{onClick:()=>void w(K),children:[(0,q.jsx)(s,{className:`w-3.5 h-3.5`}),`Open Files`]}),K&&U&&U.messages.length>0&&(0,q.jsxs)(W,{onClick:()=>ce(K.id,U.messages),children:[(0,q.jsx)(ge,{className:`w-3.5 h-3.5`}),`Fork`]}),(kt||At||jt||Mt)&&(0,q.jsx)(He,{}),U&&(0,q.jsxs)(W,{onClick:()=>re(d),children:[(0,q.jsx)(te,{className:`w-3.5 h-3.5`}),`Mark Unread`]}),U&&(0,q.jsxs)(W,{onClick:()=>O(U.peer,U.messages),children:[(0,q.jsx)(fe,{className:`w-3.5 h-3.5`}),`Mark Read`]}),gt&&(0,q.jsxs)(W,{onClick:()=>ae({...gt,importedHistory:J},`json`),children:[(0,q.jsx)(g,{className:`w-3.5 h-3.5`}),`Download`]})]})]})]})})]}),(0,q.jsx)(`div`,{ref:vt.ref,onScroll:vt.onScroll,className:`flex-1 overflow-y-auto px-3 md:px-4 py-3 md:py-4`,style:{minHeight:0},children:on.length===0?(0,q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-center`,children:[(0,q.jsx)(p,{className:`w-8 h-8 text-zinc-600 mb-2`}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No messages yet`})]}):(0,q.jsxs)(`div`,{children:[(0,q.jsx)(sn,{scrollRef:vt.ref,timeline:on}),on.map(e=>e.type===`message`?(0,q.jsx)(Qt,{msg:e.msg,peer:d,onOpenReferencedPath:dn,onPreviewReferencedPath:ln,onPreviewReferencedPathEnd:un},e.msg.id):e.type===`activity`?(0,q.jsx)(zt,{steps:e.steps,showReasoning:Ce},`act-${e.steps[0]?.id??e.timestamp}`):e.type===`import-boundary`?(0,q.jsx)(Kt,{history:e.history},`import-${e.history.id}`):e.type===`imported-message`?(0,q.jsx)(qt,{entry:e.entry,sourceLabel:e.history.sourceAgentLabel||e.history.sourcePeerId},`import-${e.history.id}-${e.entry.originalMessageId}-${e.entry.position}`):e.type===`status`?(0,q.jsx)(Pt,{event:e.event},e.event.id):e.type===`date`?(0,q.jsx)(Wt,{date:e.date},`d-${e.date}`):e.type===`created`?(0,q.jsx)(Gt,{timestamp:e.timestamp},`created`):null),Y&&K&&(0,q.jsx)(Bt,{agentId:K.id,approval:Y}),K?.status===`busy`&&!Y&&(0,q.jsx)(Ft,{blockedLabel:ht?.label,onInterrupt:Nt?It:void 0})]})}),(0,q.jsxs)(`div`,{className:i(`relative shrink-0 border-t border-border px-3 md:px-4 py-2.5 md:py-3 safe-area-bottom`,Fe&&`bg-primary/5 ring-1 ring-primary/40`),onDragOver:e=>{e.preventDefault(),R(!0)},onDragLeave:()=>R(!1),onDrop:e=>{e.preventDefault(),R(!1),pn(e.dataTransfer.files)},children:[F.length>0&&(0,q.jsx)(`div`,{className:`mb-2 grid gap-2 sm:grid-cols-2`,children:F.map(e=>(0,q.jsx)(Yt,{item:e,onRemove:()=>mn(e.id)},e.id))}),(0,q.jsx)(`input`,{ref:De,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{e.target.files&&pn(e.target.files),e.currentTarget.value=``}}),Z.length>0&&(0,q.jsx)(`div`,{className:`absolute bottom-full left-3 right-3 md:left-4 md:right-4 mb-2 z-20 max-h-64 overflow-auto rounded-xl border border-border bg-popover shadow-lg`,children:Z.map((e,t)=>(0,q.jsxs)(`button`,{onMouseDown:t=>{t.preventDefault(),$t(e)},onMouseEnter:()=>Rt(t),className:i(`flex w-full items-baseline gap-2 px-3 py-1.5 text-left text-sm`,t===Zt?`bg-accent`:`hover:bg-accent/50`),children:[(0,q.jsx)(`span`,{className:`font-medium shrink-0`,children:e.name}),e.argumentHint&&(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:e.argumentHint}),e.description&&(0,q.jsx)(`span`,{className:`ml-auto truncate text-xs text-muted-foreground/70`,children:e.description})]},e.name))}),(0,q.jsxs)(`div`,{className:`hidden md:flex items-end gap-2`,children:[(0,q.jsx)(z,{variant:`ghost`,size:`icon`,title:`Attach files`,disabled:E,onClick:()=>De.current?.click(),className:`shrink-0 mb-0.5 rounded-xl h-[42px] w-[42px]`,children:(0,q.jsx)(u,{className:`w-4 h-4`})}),(0,q.jsx)(wt,{value:X,onChange:e=>en(e.target.value),onKeyDown:_n,onPaste:vn,placeholder:`Message ${K?L(K):d}…`,className:`flex-1`}),be&&(0,q.jsx)(z,{variant:`ghost`,size:`icon`,title:P===`recording`?`Release to transcribe`:`Hold to talk`,disabled:E||P===`transcribing`,onPointerDown:e=>{e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId),yn()},onPointerUp:e=>{e.preventDefault();try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}bn()},className:`shrink-0 mb-0.5 rounded-xl h-[42px] w-[42px] ${P===`recording`?`text-red-400 animate-pulse`:``}`,children:P===`transcribing`?(0,q.jsx)(k,{className:`w-4 h-4 animate-spin`}):(0,q.jsx)(h,{className:`w-4 h-4`})}),(0,q.jsx)(z,{size:`icon`,disabled:!X.trim()&&Q.length===0||tn||E||it,onClick:gn,className:`shrink-0 mb-0.5 rounded-xl h-[42px] w-[42px]`,children:(0,q.jsx)(o,{className:`w-4 h-4`})})]}),(0,q.jsxs)(`div`,{className:`md:hidden space-y-2`,children:[(0,q.jsx)(wt,{value:X,onChange:e=>en(e.target.value),onKeyDown:_n,onPaste:vn,placeholder:`Message ${K?L(K):d}…`,className:`w-full`}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(z,{variant:`ghost`,size:`icon`,title:`Attach files`,disabled:E,onClick:()=>De.current?.click(),className:`rounded-xl h-9 w-9`,children:(0,q.jsx)(u,{className:`w-4 h-4`})}),be&&(0,q.jsx)(z,{variant:`ghost`,size:`icon`,title:P===`recording`?`Release to transcribe`:`Hold to talk`,disabled:E||P===`transcribing`,onPointerDown:e=>{e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId),yn()},onPointerUp:e=>{e.preventDefault();try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}bn()},className:`rounded-xl h-9 w-9 ${P===`recording`?`text-red-400 animate-pulse`:``}`,children:P===`transcribing`?(0,q.jsx)(k,{className:`w-4 h-4 animate-spin`}):(0,q.jsx)(h,{className:`w-4 h-4`})})]}),(0,q.jsx)(z,{size:`icon`,disabled:!X.trim()&&Q.length===0||tn||E||it,onClick:gn,className:`rounded-xl h-9 w-9`,children:(0,q.jsx)(o,{className:`w-4 h-4`})})]})]}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1.5 hidden md:block`,children:it?`${K?L(K):`Agent`} is wrapping up (${(K?.meta?.lifecycleAction).slice(11)}) — messaging paused`:`Enter to send · Shift+Enter for newline`})]})]}),B&&(0,q.jsxs)(`aside`,{className:`hidden h-full w-[min(44vw,720px)] min-w-[360px] shrink-0 flex-col border-l border-border bg-background xl:flex`,children:[(0,q.jsxs)(`div`,{className:`flex h-10 shrink-0 items-center gap-2 border-b border-border px-3`,children:[(0,q.jsx)(`span`,{className:`min-w-0 flex-1 text-xs font-medium text-muted-foreground`,children:`File preview`}),Je&&(0,q.jsx)(`span`,{className:`max-w-[18rem] truncate text-xs text-red-400`,children:Je}),(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,title:`Close preview`,onClick:fn,children:(0,q.jsx)(D,{className:`h-3.5 w-3.5`})})]}),(0,q.jsx)(`div`,{className:`min-h-0 flex-1`,children:B.type===`directory`?(0,q.jsx)($e,{orchestratorId:B.orchestratorId,selectedPath:B.path,onReadError:V}):(0,q.jsx)(et,{orchestratorId:B.orchestratorId,selectedPath:B.path,line:B.line,onReadError:V})})]})]}),We&&(0,q.jsx)(Xt,{preview:We,error:Je,onReadError:V,onMouseEnter:$,onMouseLeave:un}),ot&&(0,q.jsx)(Ye,{open:at,onOpenChange:pt,orchestratorId:ot.orchestratorId,session:ot.session,interactive:ot.interactive||Dt})]}):(0,q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-center px-4`,children:[(0,q.jsx)(p,{className:`w-12 h-12 text-zinc-600 mb-3`}),(0,q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Select an agent to start chatting`})]})}function cn(){let e=V(),t=M(e=>e.selectedInboxThread),n=M(e=>e.set),r=vt(),i=!!t;Ct(),(0,G.useEffect)(()=>{t&&(r.some(e=>e.id===t)||n({selectedInboxThread:``}))},[t,r,n]);function a(){n({selectedInboxThread:``})}return(0,q.jsxs)(`div`,{className:`flex -m-4 md:-m-6`,style:{height:`calc(100dvh - var(--header-h) - var(--sat))`},children:[(0,q.jsxs)(`div`,{className:`hidden md:flex w-full`,children:[(0,q.jsx)(`div`,{className:`w-1/3 min-w-[240px] max-w-xs flex flex-col overflow-hidden`,children:(0,q.jsx)(Tt,{threads:e})}),(0,q.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:(0,q.jsx)($,{threads:e},t||`empty`)})]}),(0,q.jsx)(`div`,{className:`md:hidden flex w-full overflow-hidden`,children:i?(0,q.jsx)(ln,{children:(0,q.jsx)($,{threads:e,onBack:a,showBackButton:!0},t||`empty`)}):(0,q.jsx)(`div`,{className:`w-full flex flex-col overflow-hidden`,children:(0,q.jsx)(Tt,{threads:e})})})]})}function ln({children:e}){let t=tt();return(0,q.jsx)(`div`,{className:`fixed inset-x-0 top-0 z-40 flex flex-col bg-background pt-[var(--sat)]`,style:{height:t?`${t}px`:`100dvh`},children:e})}export{cn as ChatView};
2
- //# sourceMappingURL=chat-jeXt_SFs.js.map
1
+ import{r as e}from"./chunk-CilyBKbf.js";import{$t as t,An as n,D as r,Dn as i,Dt as a,E as o,Et as s,Ft as c,G as l,H as u,I as d,It as f,J as p,Jt as m,K as h,Lt as g,P as _,Pn as v,Vn as y,Wt as b,Z as x,an as S,at as C,b as w,c as T,dn as ee,en as E,et as te,g as ne,i as D,in as O,it as k,jn as re,kn as ie,kt as ae,mn as A,nn as oe,qt as se,r as ce,rn as le,s as ue,tn as de,tt as fe,wn as j,x as pe,xn as me,yn as he,yt as ge}from"./lucide-react-CD8Xl2U3.js";import{t as _e}from"./react-dom-CX8inunm.js";import{d as ve,i as ye,l as be,s as xe,t as M,u as Se}from"./store-C9VcSo05.js";import{$ as Ce,D as N,E as we,H as Te,I as Ee,M as De,N as Oe,O as ke,R as P,S as Ae,V as je,a as Me,g as Ne,i as Pe,m as F,q as I,u as L,w as Fe,z as R}from"./display-JI19Vc7L.js";import{t as Ie}from"./badge-t8zAwHW9.js";import{t as z}from"./button-DDA5P2YQ.js";import{t as B}from"./input-BW9UD3FM.js";import{t as Le}from"./copy-button-CE8e2c-F.js";import{C as Re,E as ze,I as Be,S as Ve,T as He,_ as Ue,a as We,d as Ge,g as Ke,h as qe,i as Je,k as V,l as Ye,m as H,o as Xe,p as Ze,r as Qe,t as U,v as $e,w as W,y as et}from"./index-C_33ymaw.js";import{t as tt}from"./use-keyboard-viewport-DxY_xJV5.js";import{n as nt,t as rt}from"./branch-state-badge-D4ur3m3_.js";var G=e(y(),1),K=e(_e(),1),it=[{name:`/reply`,source:`skill`,description:`Reply to a relay message by id`,argumentHint:`<messageId> <body>`},{name:`/message`,source:`skill`,description:`Send a relay message to an agent, label, tag, or broadcast`,argumentHint:`<target> <body>`},{name:`/pair`,source:`skill`,description:`Start or manage a two-agent pair session`},{name:`/react`,source:`skill`,description:`Add a reaction to a relay message`,argumentHint:`<messageId> <emoji>`},{name:`/read-message`,source:`skill`,description:`Fetch a full relay message by id`,argumentHint:`<messageId>`},{name:`/send-claimable`,source:`skill`,description:`Enqueue a claimable work item for one agent to claim`},{name:`/status`,source:`skill`,description:`Show this agent's relay status`},{name:`/tags`,source:`skill`,description:`List or update this agent's relay tags`},{name:`/label`,source:`skill`,description:`Read, set, or clear this agent's relay label`},{name:`/disconnect`,source:`skill`,description:`End the current relay pair session`}],at=[{name:`/clear`,source:`builtin`,description:`Clear conversation history and free up context`},{name:`/compact`,source:`builtin`,description:`Compact the conversation to reclaim context`,argumentHint:`[instructions]`},{name:`/model`,source:`builtin`,description:`Switch the active model`,argumentHint:`[model]`},{name:`/help`,source:`builtin`,description:`Show help`}],ot=[{name:`/compact`,source:`builtin`,description:`Compact the conversation to reclaim context`},{name:`/new`,source:`builtin`,description:`Start a new thread`}];function st(e){return[...e===`claude`?at:e===`codex`?ot:[],...it]}var q=ie();function ct(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function lt(e,t){if(t.startsWith(`/`))return t;let n=`${e.replace(/\/+$/,``)}/${t}`.split(`/`),r=[];for(let e of n)!e||e===`.`||(e===`..`?r.pop():r.push(e));return`/`+r.join(`/`)}function ut(e){let t=e.replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n>0?t.slice(0,n):`/`}function dt(e,t){return e.filter(e=>e.status===`online`&&De(t,e.baseDir)).sort((e,t)=>N(t.baseDir).length-N(e.baseDir).length)[0]||e.find(e=>e.status===`online`)}function ft(){return typeof window<`u`&&window.matchMedia(`(min-width: 1280px)`).matches}function pt(){return typeof window<`u`&&!!window.getSelection()?.toString()}function mt(e){let t=e.payload?.attachments;return Array.isArray(t)?t.filter(e=>!!(e&&typeof e==`object`&&typeof e.artifactId==`string`)):[]}var J=[`👍`,`❤️`,`✅`,`👀`];function ht(e){let t=new Map;for(let n of e.reactions||[]){let e=ke(n.emoji),r=t.get(e)??{emoji:e,count:0,mine:!1,actors:[]};r.count+=1,r.mine=r.mine||n.actorId===`user`,r.actors.push(n.actorId),t.set(e,r)}return[...t.values()].sort((e,t)=>t.count-e.count||e.emoji.localeCompare(t.emoji))}function Y(e){return Ae(e)}function gt(e,n){let r=e.readBy||[],i=e.resolvedToAgent||n||e.to,a=i?r.includes(i):!1,o=r.some(e=>e!==Ce);if(a||o){let e=a?i:r.find(e=>e!==Ce);return{label:`read`,title:e?`Read by ${e}`:`Read by agent`,tone:`ok`,icon:S}}if(e.deliveryStatus===`delivered`)return{label:`delivered`,title:`Delivered to agent inbox`,tone:`ok`,icon:S};if(e.deliveryStatus===`queued`)return{label:`queued`,title:`Queued until the target agent is available`,tone:`warn`,icon:b};if(e.deliveryStatus===`failed`||e.deliveryStatus===`dead`){let n=e.deliveryPoisonReason||e.deliveryLastError||e.deliveryStatus;return{label:e.deliveryStatus,title:n,tone:`danger`,icon:t}}return{label:`sent`,title:`Accepted by Relay`,tone:`muted`,icon:O}}function X(e){let t=R(e.createdAt);return(e.reactions||[]).reduce((e,t)=>Math.max(e,R(t.updatedAt||t.createdAt)),t)}function _t(e){return e?e.messages.reduce((e,t)=>Math.max(e,X(t)),0):0}function vt(){let e=M(e=>e.agents),t=M(e=>e.showBuiltIns),n=M(e=>e.showOffline),r=M(e=>e.chatAgentSearch),i=M(e=>e.chatAgentProviderFilter),a=M(e=>e.chatAgentStatusFilter),o=M(e=>e.chatAgentTagFilter),s=M(e=>e.chatAgentCapFilter),c=M(e=>e.chatAgentHostFilter),l=M(e=>e.chatAgentSort),u=M(e=>e.chatAgentSortDir),d=M(e=>e.managedPolicies);return(0,G.useMemo)(()=>{let f=Te(e,t,d);if(n||(f=f.filter(e=>e.status!==`offline`)),r){let e=r.toLowerCase();f=f.filter(t=>t.id.toLowerCase().includes(e)||(t.name||``).toLowerCase().includes(e)||(t.label||``).toLowerCase().includes(e)||(t.tags||[]).some(t=>t.toLowerCase().includes(e))||(t.capabilities||[]).some(t=>t.toLowerCase().includes(e)))}i&&(f=f.filter(e=>Me(e)===i)),a&&(f=f.filter(e=>e.status===a)),o&&(f=f.filter(e=>(e.tags||[]).includes(o))),s&&(f=f.filter(e=>(e.capabilities||[]).includes(s))),c&&(f=f.filter(e=>(e.machine||``)===c));let p=u===`desc`?-1:1;return[...f].sort((e,t)=>l===`name`?L(e).localeCompare(L(t))*p:l===`lastSeen`?(R(t.lastSeen)-R(e.lastSeen))*p||L(e).localeCompare(L(t)):((I[e.status]??9)-(I[t.status]??9))*p||L(e).localeCompare(L(t)))},[e,t,n,d,r,i,a,o,s,c,l,u])}var yt=[],bt=[];function xt(e){return M(t=>t.chatStatusEvents[e]??yt)}function St(e,t){let n=(0,G.useRef)(!1);(0,G.useEffect)(()=>{if(!e)return;n.current||=(window.history.pushState({chatGuard:!0},``),!0);function r(e){(e.state?.chatGuard!==void 0||!n.current)&&(window.history.pushState({chatGuard:!0},``),t())}function i(e){e.preventDefault()}return window.addEventListener(`popstate`,r),window.addEventListener(`beforeunload`,i),()=>{window.removeEventListener(`popstate`,r),window.removeEventListener(`beforeunload`,i)}},[e,t]),(0,G.useEffect)(()=>{!e&&n.current&&(n.current=!1)},[e])}function Ct(){let e=M(e=>e.inboxDrafts),t=M(e=>e.agentsById),n=M(e=>e.set);(0,G.useEffect)(()=>{let r=Object.keys(e);if(r.length===0)return;let i=r.filter(e=>!t[e]&&e!==`user`);if(i.length===0)return;let a=setTimeout(()=>{let e=M.getState().agentsById,t={...M.getState().inboxDrafts},r=!1;for(let n of i)e[n]||(delete t[n],r=!0);r&&n({inboxDrafts:t})},3e4);return()=>clearTimeout(a)},[])}function wt({value:e,onChange:t,onKeyDown:n,onPaste:r,placeholder:a,className:o}){let s=(0,G.useRef)(null);return(0,G.useEffect)(()=>{let e=s.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[e]),(0,G.useEffect)(()=>{let e=window.visualViewport;if(!e)return;function t(){let e=s.current;!e||document.activeElement!==e||requestAnimationFrame(()=>{e.scrollIntoView({block:`nearest`,behavior:`smooth`})})}return e.addEventListener(`resize`,t),()=>e.removeEventListener(`resize`,t)},[]),(0,q.jsx)(`textarea`,{ref:s,value:e,onChange:t,onKeyDown:n,onPaste:r,placeholder:a,rows:1,className:i(`w-full resize-none rounded-xl border border-border bg-background px-3.5 py-2.5 text-sm`,`placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`min-h-[42px] max-h-[200px] overflow-y-auto`,o)})}function Tt({threads:e,onSelectAgent:t}){let n=M(e=>e.set),a=M(e=>e.openInboxThread),o=M(e=>e.openAgentSpawn),s=M(e=>e.selectedInboxThread),c=M(e=>e.chatAgentSearch),l=M(e=>e.chatAgentSort),u=M(e=>e.chatAgentSortDir),f=M(e=>e.chatAgentProviderFilter),p=M(e=>e.chatAgentStatusFilter),m=M(e=>e.chatAgentTagFilter),h=M(e=>e.chatAgentCapFilter),g=M(e=>e.chatAgentHostFilter),_=M(e=>e.chatAgentGroupBy),v=M(e=>e.chatAgentFiltersCollapsed),y=ye(),b=vt(),x=(0,G.useMemo)(()=>{let t=new Map;for(let n of e)t.set(n.peer,n);return t},[e]),S=(0,G.useMemo)(()=>{if(l!==`lastMessage`)return b;let e=u===`desc`?-1:1;return[...b].sort((t,n)=>{let r=_t(x.get(t.id));return(_t(x.get(n.id))-r)*e||L(t).localeCompare(L(n))})},[b,l,u,x]),C=(0,G.useMemo)(()=>[...new Set(b.flatMap(e=>e.tags||[]))],[b]),w=(0,G.useMemo)(()=>[...new Set(b.flatMap(e=>je(e.capabilities||[])))],[b]),T=Be(),ee=(0,G.useMemo)(()=>{if(_!==`project`)return null;let e=new Map;for(let t of S){let n=H(t)||`No project`,r=e.get(n);r?r.push(t):e.set(n,[t])}return[...e.entries()].sort((e,t)=>e[0].localeCompare(t[0]))},[S,_]),te=[f,p,m,h,g].filter(Boolean).length;function ne(e){a(e,x.get(e)?.messages),t?.(e)}function D(e){let t=x.get(e.id),n=t?.attention.unread||0,r=t?.previewMessage,a=_t(t),o=s===e.id,c=qe(e),l=H(e),u=c.Icon;return(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{className:i(`w-full text-left px-3 py-2.5 flex items-start gap-2.5 hover:bg-muted/50 transition-colors border-b border-border/50`,o&&`bg-muted/60`),onClick:()=>ne(e.id),children:[(0,q.jsxs)(`div`,{className:`relative shrink-0 mt-0.5`,children:[(0,q.jsx)(Ke,{agent:e}),(0,q.jsx)(Ue,{agent:e,now:y,className:`absolute -bottom-0.5 -right-0.5 w-2 h-2`})]}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-1 mb-0.5`,children:[(0,q.jsx)(`span`,{className:`text-xs font-medium truncate`,children:L(e)}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[a>0&&(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,title:F(a),children:P(y,a)}),n>0&&(0,q.jsx)(Ie,{className:`bg-red-500 text-white text-xs min-w-[18px] h-[18px] flex items-center justify-center shrink-0 px-1`,children:n})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-0.5 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(`span`,{title:c.title,className:`inline-flex shrink-0`,children:(0,q.jsx)(u,{className:i(`h-3 w-3`,c.iconColor)})}),(0,q.jsx)(`span`,{className:`truncate`,children:l||c.label}),e.context&&(0,q.jsx)(`span`,{className:`ml-auto shrink-0`,children:(0,q.jsx)(Ze,{utilization:e.context.utilization,size:18})})]}),r&&(0,q.jsxs)(`p`,{className:`text-xs text-muted-foreground truncate leading-tight`,children:[r.from===`user`?`You: `:``,we(r)]}),e.status!==`offline`&&(0,q.jsx)(`div`,{className:`mt-1`,children:(0,q.jsx)(`span`,{className:i(`text-xs`,e.status===`busy`?`text-yellow-400`:`text-emerald-400`),children:e.status})})]})]})},e.id)}return(0,q.jsxs)(`div`,{className:`flex flex-col h-full border-r border-border min-w-0`,children:[(0,q.jsxs)(`div`,{className:`p-3 border-b border-border space-y-2`,children:[(0,q.jsxs)(`div`,{className:`relative`,children:[(0,q.jsx)(r,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground pointer-events-none`}),(0,q.jsx)(B,{placeholder:`Search agents...`,value:c,onChange:e=>n({chatAgentSearch:e.target.value}),className:`pl-8 h-7 text-xs`})]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>n({chatAgentFiltersCollapsed:!v}),className:`sm:hidden flex w-full items-center justify-between h-6 px-1.5 text-xs rounded-md border border-border bg-background text-muted-foreground`,children:[(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,q.jsx)(pe,{className:`w-3.5 h-3.5`}),`Filters & sort`,te>0&&(0,q.jsx)(Ie,{className:`bg-primary/20 text-primary text-[10px] h-4 min-w-4 px-1 flex items-center justify-center`,children:te})]}),v?(0,q.jsx)(le,{className:`w-3.5 h-3.5`}):(0,q.jsx)(E,{className:`w-3.5 h-3.5`})]}),(0,q.jsxs)(`div`,{className:i(`space-y-2`,v?`hidden`:`block`,`sm:block`),children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsxs)(`select`,{value:l,onChange:e=>n({chatAgentSort:e.target.value}),className:`flex-1 h-6 text-xs rounded-md border border-border bg-background px-1.5 text-foreground`,children:[(0,q.jsx)(`option`,{value:`status`,children:`By status`}),(0,q.jsx)(`option`,{value:`name`,children:`By name`}),(0,q.jsx)(`option`,{value:`lastSeen`,children:`By last seen`}),(0,q.jsx)(`option`,{value:`lastMessage`,children:`By last activity`})]}),(0,q.jsx)(z,{variant:`ghost`,size:`icon-xs`,onClick:()=>n({chatAgentSortDir:u===`asc`?`desc`:`asc`}),children:u===`asc`?(0,q.jsx)(he,{className:`w-3.5 h-3.5`}):(0,q.jsx)(j,{className:`w-3.5 h-3.5`})})]}),(0,q.jsxs)(`select`,{value:_,onChange:e=>n({chatAgentGroupBy:e.target.value}),className:`w-full h-6 text-xs rounded-md border border-border bg-background px-1.5 text-foreground`,children:[(0,q.jsx)(`option`,{value:``,children:`No grouping`}),(0,q.jsx)(`option`,{value:`project`,children:`Group by project`})]}),(0,q.jsxs)(`div`,{className:`flex gap-1`,children:[(0,q.jsxs)(`select`,{value:f,onChange:e=>n({chatAgentProviderFilter:e.target.value}),className:`flex-1 h-6 text-xs rounded-md border border-border bg-background px-1.5 text-foreground`,children:[(0,q.jsx)(`option`,{value:``,children:`All types`}),(0,q.jsx)(`option`,{value:`claude`,children:`Claude`}),(0,q.jsx)(`option`,{value:`codex`,children:`Codex`}),(0,q.jsx)(`option`,{value:`agent`,children:`Agent`}),(0,q.jsx)(`option`,{value:`user`,children:`User`})]}),(0,q.jsxs)(`select`,{value:p,onChange:e=>n({chatAgentStatusFilter:e.target.value}),className:`flex-1 h-6 text-xs rounded-md border border-border bg-background px-1.5 text-foreground`,children:[(0,q.jsx)(`option`,{value:``,children:`All status`}),(0,q.jsx)(`option`,{value:`online`,children:`Online`}),(0,q.jsx)(`option`,{value:`idle`,children:`Idle`}),(0,q.jsx)(`option`,{value:`busy`,children:`Busy`}),(0,q.jsx)(`option`,{value:`offline`,children:`Offline`})]}),T.length>1&&(0,q.jsxs)(`select`,{value:g,onChange:e=>n({chatAgentHostFilter:e.target.value}),className:`flex-1 h-6 text-xs rounded-md border border-border bg-background px-1.5 text-foreground`,children:[(0,q.jsx)(`option`,{value:``,children:`All hosts`}),T.map(e=>(0,q.jsx)(`option`,{value:e,children:e},e))]})]}),(C.length>0||w.length>0)&&(0,q.jsxs)(`div`,{className:`flex gap-1`,children:[C.length>0&&(0,q.jsxs)(`select`,{value:m,onChange:e=>n({chatAgentTagFilter:e.target.value}),className:`flex-1 h-6 text-xs rounded-md border border-border bg-background px-1.5 text-foreground`,children:[(0,q.jsx)(`option`,{value:``,children:`All tags`}),C.map(e=>(0,q.jsxs)(`option`,{value:e,children:[`#`,e]},e))]}),w.length>0&&(0,q.jsxs)(`select`,{value:h,onChange:e=>n({chatAgentCapFilter:e.target.value}),className:`flex-1 h-6 text-xs rounded-md border border-border bg-background px-1.5 text-foreground`,children:[(0,q.jsx)(`option`,{value:``,children:`All caps`}),w.map(e=>(0,q.jsx)(`option`,{value:e,children:e},e))]})]})]})]}),(0,q.jsxs)(`button`,{type:`button`,className:`flex w-full shrink-0 items-center gap-2.5 border-b border-border px-3 py-2 text-left transition-colors hover:bg-muted/50`,onClick:o,children:[(0,q.jsx)(`div`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-full border border-dashed border-primary/50 bg-primary/10 text-primary`,children:(0,q.jsx)(d,{className:`h-3.5 w-3.5`})}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`text-xs font-medium`,children:`New Agent`}),(0,q.jsx)(`div`,{className:`truncate text-[10px] text-muted-foreground`,children:`Spawn a fresh chat agent`})]})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:S.length===0?(0,q.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-10 text-center px-4`,children:[(0,q.jsx)(A,{className:`w-8 h-8 text-zinc-600 mb-2`}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No agents match filters`})]}):ee?ee.map(([e,t])=>(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-1.5 border-b border-border/50 bg-background/95 px-3 py-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground backdrop-blur`,children:[(0,q.jsx)(`span`,{className:`truncate`,children:e}),(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:t.length})]}),(0,q.jsx)(`ul`,{children:t.map(D)})]},e)):(0,q.jsx)(`ul`,{children:S.map(D)})})]})}function Et(e){return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function Dt(e){return new Date(e.occurredAt??e.createdAt).getTime()}function Ot(e){let t=new Date,[n,r,i]=e.split(`-`).map(Number),a=new Date(n,r-1,i);if(e===en(t.getTime()))return`Today`;let o=new Date(t);return o.setDate(o.getDate()-1),e===en(o.getTime())?`Yesterday`:a.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`,year:a.getFullYear()===t.getFullYear()?void 0:`numeric`})}var kt={online:`text-emerald-400`,offline:`text-zinc-400`,shutdown:`text-zinc-400`,restarted:`text-blue-400`,"compaction-requested":`text-zinc-400`,compacting:`text-amber-400`,compacted:`text-amber-400`,"compaction-stalled":`text-red-400`,"clear-requested":`text-zinc-400`,"clearing-context":`text-amber-400`,"context-cleared":`text-amber-400`,"clear-stalled":`text-red-400`,"shutting-down":`text-zinc-400`},At={online:`came online`,offline:`went offline`,shutdown:`shut down`,restarted:`restarted`,"compaction-requested":`compaction requested`,compacting:`compaction started`,compacted:`context compacted`,"compaction-stalled":`compaction stalled — may need manual intervention`,"clear-requested":`clear requested`,"clearing-context":`clear started`,"context-cleared":`context cleared`,"clear-stalled":`context clear stalled — may need manual intervention`,"shutting-down":`shutting down`},jt=new Set(Object.keys(At)),Mt=3e3,Nt=96;function Pt({event:e}){return(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-2 my-1`,children:[(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,q.jsx)(se,{className:i(`w-2 h-2 fill-current`,kt[e.status]||`text-zinc-400`)}),(0,q.jsx)(`span`,{children:At[e.status]||e.status}),(0,q.jsx)(`span`,{className:`text-muted-foreground/60`,children:Et(e.timestamp)})]}),(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`})]})}function Ft({blockedLabel:e,onInterrupt:n}){return e?(0,q.jsx)(`div`,{className:`flex justify-start mb-3`,children:(0,q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-2xl rounded-bl-sm bg-card ring-1 ring-red-500/30 px-4 py-2.5`,children:[(0,q.jsx)(t,{className:`w-3.5 h-3.5 text-red-400`}),(0,q.jsxs)(`span`,{className:`text-xs text-red-300`,children:[`blocked: `,e]})]})}):(0,q.jsx)(`div`,{className:`flex justify-start mb-3`,children:(0,q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-2xl rounded-bl-sm bg-card ring-1 ring-foreground/10 px-4 py-2.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-yellow-400 animate-[pulse_1.4s_ease-in-out_infinite]`}),(0,q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-yellow-400 animate-[pulse_1.4s_ease-in-out_0.2s_infinite]`}),(0,q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-yellow-400 animate-[pulse_1.4s_ease-in-out_0.4s_infinite]`})]}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`working`}),n&&(0,q.jsxs)(`button`,{onClick:n,title:`Interrupt`,className:`ml-1 flex items-center gap-1 rounded-full px-1.5 py-0.5 text-xs text-muted-foreground hover:text-red-300 hover:bg-red-500/10 transition-colors`,children:[(0,q.jsx)(m,{className:`w-3.5 h-3.5`}),`Stop`]})]})})}var It=`agent-relay:chat-hide-tools`,Lt=(()=>{let e=new Set,t=(()=>{try{return window.localStorage.getItem(It)===`on`}catch{return!1}})(),n=()=>e.forEach(e=>e());return typeof window<`u`&&window.addEventListener(`storage`,e=>{e.key===It&&(t=e.newValue===`on`,n())}),{subscribe(t){return e.add(t),()=>e.delete(t)},get:()=>t,toggle(){t=!t;try{window.localStorage.setItem(It,t?`on`:`off`)}catch{}n()}}})();function Rt(){return[(0,G.useSyncExternalStore)(Lt.subscribe,Lt.get,()=>!1),Lt.toggle]}function zt({steps:e,showReasoning:t}){let[n,r]=Rt(),a=t?e:e.filter(e=>e.kind!==`reasoning`);if(!a.length)return null;let o=a.filter(e=>e.kind===`tool`).length;return(0,q.jsx)(`div`,{className:`flex justify-start mb-2`,children:(0,q.jsxs)(`div`,{className:`max-w-[85%] md:max-w-[75%] min-w-0 space-y-1.5`,children:[a.map(e=>e.kind===`narration`?(0,q.jsx)(`div`,{className:`text-sm leading-relaxed whitespace-pre-wrap break-words text-foreground/90 min-w-0`,children:e.text},e.id):e.kind===`reasoning`?(0,q.jsxs)(`div`,{className:`flex items-start gap-1.5 text-xs leading-relaxed text-muted-foreground/80`,children:[(0,q.jsx)(ee,{className:`w-3.5 h-3.5 mt-0.5 shrink-0 opacity-70`}),(0,q.jsx)(`span`,{className:`italic whitespace-pre-wrap break-words min-w-0`,children:e.text})]},e.id):n?null:(0,q.jsxs)(`div`,{className:`flex items-start gap-1.5 text-xs leading-relaxed text-muted-foreground`,children:[(0,q.jsx)(ne,{className:`w-3 h-3 mt-0.5 shrink-0 opacity-70`}),(0,q.jsxs)(`span`,{className:`min-w-0 break-words`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:e.label||`tool`}),e.text?(0,q.jsxs)(`span`,{className:`opacity-70`,children:[` — `,e.text]}):null]})]},e.id)),o>0&&(0,q.jsxs)(`button`,{onClick:r,className:`flex items-center gap-1 text-[11px] text-muted-foreground/50 hover:text-muted-foreground transition-colors text-left`,children:[(0,q.jsx)(de,{className:i(`w-3 h-3 shrink-0 transition-transform`,!n&&`rotate-90`)}),(0,q.jsx)(`span`,{children:n?`show ${o} tool step${o===1?``:`s`}`:`hide tool steps`})]})]})})}function Bt({agentId:e,approval:n}){let r=M(e=>e.sendPermissionDecision),[i,a]=(0,G.useState)(null);if(!n)return null;if(n.questions&&n.questions.length)return(0,q.jsx)(Ut,{agentId:e,approval:n,questions:n.questions});let o=n,s=n.choices.length?n.choices:[{id:`approve`,label:`Approve`},{id:`deny`,label:`Deny`}];async function c(t){if(!i){a(t.id);try{await r(e,o.id,t.id)}finally{a(null)}}}let l=n.kind===`plan`;return(0,q.jsx)(`div`,{className:`flex justify-start mb-3`,children:(0,q.jsx)(`div`,{className:`max-w-[92%] md:max-w-[78%] rounded-2xl rounded-bl-sm bg-card ring-1 ring-amber-500/35 px-3.5 py-3 text-sm`,children:(0,q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[l?(0,q.jsx)(C,{className:`mt-0.5 h-4 w-4 shrink-0 text-amber-400`}):(0,q.jsx)(t,{className:`mt-0.5 h-4 w-4 shrink-0 text-amber-400`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`text-sm font-medium text-amber-100`,children:n.title}),n.body&&(l?(0,q.jsx)(`div`,{className:`mt-2 max-h-72 overflow-auto rounded-md bg-background/60 p-2.5 text-xs leading-relaxed`,children:(0,q.jsx)(U,{text:n.body,rawBody:n.body,className:`leading-relaxed`})}):(0,q.jsx)(`pre`,{className:`mt-2 max-h-44 overflow-auto whitespace-pre-wrap break-words rounded-md bg-background/80 p-2 font-mono text-xs leading-relaxed text-muted-foreground`,children:n.body})),(0,q.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:s.map(e=>(0,q.jsxs)(z,{size:`sm`,variant:e.id===`deny`||e.id===`abort`?`outline`:`default`,disabled:!!i,onClick:()=>void c(e),className:`h-7 px-2 text-xs`,children:[i===e.id&&(0,q.jsx)(k,{className:`mr-1.5 h-3 w-3 animate-spin`}),e.label]},e.id))})]})]})})})}function Vt(e){return e?e.otherActive&&e.other.trim()?!0:e.labels.length>0:!1}function Ht(e){let t=[...e.labels];return e.otherActive&&e.other.trim()&&t.push(e.other.trim()),t.join(`, `)}function Ut({agentId:e,approval:t,questions:n}){let r=M(e=>e.sendPermissionDecision),[a,o]=(0,G.useState)(0),[s,c]=(0,G.useState)({}),[l,u]=(0,G.useState)(null),d=n[Math.min(a,n.length-1)],f=s[a];if(!d)return null;let p=!!d.multiSelect,m=n.length,h=a===m-1,g=Vt(f),_=n.every((e,t)=>Vt(s[t])),v=!!l;function y(e){c(t=>{let n=t[a]??{labels:[],other:``,otherActive:!1};return{...t,[a]:{...n,...e}}})}function b(e){if(p){let t=f?.labels.includes(e);y({labels:t?(f?.labels??[]).filter(t=>t!==e):[...f?.labels??[],e]})}else y({labels:[e],otherActive:!1})}function S(){y(p?{otherActive:!f?.otherActive}:{labels:[],otherActive:!0})}async function C(){if(!(!_||v)){u(`answer`);try{let i={};n.forEach((e,t)=>{let n=s[t];n&&(i[e.question]=Ht(n))}),await r(e,t.id,`answer`,i)}finally{u(null)}}}async function w(){if(!v){u(`dismiss`);try{await r(e,t.id,`deny`)}finally{u(null)}}}let T=!!f?.otherActive;return(0,q.jsx)(`div`,{className:`flex justify-start mb-3`,children:(0,q.jsxs)(`div`,{className:`w-full max-w-[92%] md:max-w-[78%] rounded-2xl rounded-bl-sm bg-card ring-1 ring-amber-500/35 px-3.5 py-3 text-sm`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(x,{className:`h-4 w-4 shrink-0 text-amber-400`}),(0,q.jsx)(`div`,{className:`text-sm font-medium text-amber-100`,children:t.title}),m>1&&(0,q.jsxs)(Ie,{variant:`outline`,className:`ml-auto h-5 px-1.5 text-[10px] text-muted-foreground`,children:[a+1,` / `,m]})]}),(0,q.jsxs)(`div`,{className:`mt-3`,children:[d.header&&(0,q.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-amber-300/80`,children:d.header}),(0,q.jsx)(`div`,{className:`mt-0.5 text-sm text-foreground whitespace-pre-wrap break-words`,children:d.question}),p&&(0,q.jsx)(`div`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:`Select all that apply`}),(0,q.jsxs)(`div`,{className:`mt-2 flex flex-col gap-1.5`,children:[d.options.map(e=>{let t=!!f?.labels.includes(e.label);return(0,q.jsxs)(`button`,{type:`button`,disabled:v,onClick:()=>b(e.label),className:i(`flex items-start gap-2 rounded-lg border px-2.5 py-2 text-left transition-colors`,t?`border-amber-500/60 bg-amber-500/10`:`border-border bg-background/60 hover:bg-background`,v&&`opacity-60`),children:[(0,q.jsx)(`span`,{className:i(`mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center border text-amber-300`,p?`rounded`:`rounded-full`,t?`border-amber-400 bg-amber-400/20`:`border-muted-foreground/40`),children:t&&(0,q.jsx)(O,{className:`h-3 w-3`})}),(0,q.jsxs)(`span`,{className:`min-w-0`,children:[(0,q.jsx)(`span`,{className:`text-sm text-foreground`,children:e.label}),e.description&&(0,q.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.description})]})]},e.label)}),(0,q.jsxs)(`button`,{type:`button`,disabled:v,onClick:S,className:i(`flex items-start gap-2 rounded-lg border px-2.5 py-2 text-left transition-colors`,T?`border-amber-500/60 bg-amber-500/10`:`border-border bg-background/60 hover:bg-background`,v&&`opacity-60`),children:[(0,q.jsx)(`span`,{className:i(`mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center border text-amber-300`,p?`rounded`:`rounded-full`,T?`border-amber-400 bg-amber-400/20`:`border-muted-foreground/40`),children:T&&(0,q.jsx)(O,{className:`h-3 w-3`})}),(0,q.jsx)(`span`,{className:`text-sm text-foreground`,children:`Other…`})]}),T&&(0,q.jsx)(Qe,{autoFocus:!0,rows:2,disabled:v,value:f?.other??``,onChange:e=>y({other:e.target.value,otherActive:!0}),placeholder:`Type your answer`,className:`mt-1 text-sm`})]})]}),(0,q.jsxs)(`div`,{className:`mt-3 flex items-center gap-1.5`,children:[a>0&&(0,q.jsxs)(z,{size:`sm`,variant:`outline`,disabled:v,onClick:()=>o(e=>e-1),className:`h-7 px-2 text-xs`,children:[(0,q.jsx)(oe,{className:`mr-1 h-3 w-3`}),`Back`]}),h?(0,q.jsxs)(z,{size:`sm`,disabled:v||!_,onClick:()=>void C(),className:`h-7 px-2 text-xs`,children:[l===`answer`&&(0,q.jsx)(k,{className:`mr-1.5 h-3 w-3 animate-spin`}),`Send answer`,m>1?`s`:``]}):(0,q.jsxs)(z,{size:`sm`,disabled:v||!g,onClick:()=>o(e=>e+1),className:`h-7 px-2 text-xs`,children:[`Next`,(0,q.jsx)(de,{className:`ml-1 h-3 w-3`})]}),(0,q.jsxs)(z,{size:`sm`,variant:`ghost`,disabled:v,onClick:()=>void w(),className:`ml-auto h-7 px-2 text-xs text-muted-foreground`,children:[l===`dismiss`&&(0,q.jsx)(k,{className:`mr-1.5 h-3 w-3 animate-spin`}),`Dismiss`]})]})]})})}function Wt({date:e}){return(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-3 py-3 my-1`,children:[(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`}),(0,q.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:Ot(e)}),(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`})]})}function Gt({timestamp:e}){let t=new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,year:`numeric`,hour:`2-digit`,minute:`2-digit`});return(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-2 my-1`,children:[(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`}),(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground/60`,children:[`created `,t]}),(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`})]})}function Kt({history:e}){let t=e.sourceAgentLabel||e.sourcePeerId,n=e.entries.length;return(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-2 my-1`,children:[(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-full border border-dashed border-border bg-muted/30 px-2 py-1 text-[11px] text-muted-foreground`,children:[(0,q.jsx)(ge,{className:`h-3 w-3`}),(0,q.jsxs)(`span`,{children:[`forked history from `,t]}),(0,q.jsxs)(`span`,{className:`text-muted-foreground/60`,children:[n,` `,n===1?`entry`:`entries`]})]}),(0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`})]})}function qt({entry:e,sourceLabel:t}){let n=e.message,r=Fe(n),a=e.originalFrom===Ce;return(0,q.jsx)(`div`,{className:i(`flex mb-3 opacity-80`,a?`justify-end`:`justify-start`),children:(0,q.jsx)(`div`,{className:`max-w-[85%] md:max-w-[75%]`,children:(0,q.jsxs)(`div`,{className:i(`rounded-2xl border border-dashed px-3.5 py-2 text-sm select-text`,a?`border-primary/25 bg-primary/10 text-foreground rounded-br-sm`:`border-border bg-card/70 rounded-bl-sm`),children:[(0,q.jsxs)(`div`,{className:i(`mb-1 text-[10px] uppercase tracking-normal`,a?`text-primary/70`:`text-muted-foreground`),children:[`forked history · `,a?`you`:t||e.originalFrom]}),(0,q.jsx)(U,{text:r,rawBody:n.body,className:`leading-relaxed`}),(0,q.jsxs)(`p`,{className:i(`mt-1 flex items-center justify-end gap-1.5 text-xs`,a?`text-primary/60`:`text-muted-foreground`),children:[(0,q.jsxs)(`span`,{className:`opacity-40`,children:[`#`,e.originalMessageId]}),(0,q.jsx)(`span`,{children:Et(e.originalCreatedAt)})]})]})})})}function Jt({attachment:e,outbound:n}){let r=e.kind===`image`,a=e.title||e.artifactId,[o,s]=(0,G.useState)(null),[c,l]=(0,G.useState)(null),[u,d]=(0,G.useState)(!1),[f,p]=(0,G.useState)(!1);(0,G.useEffect)(()=>{let t=!1,n=null;async function r(){d(!0),l(null),s(null);try{let r=await re(`/artifacts/${encodeURIComponent(e.artifactId)}/content`);if(t)return;n=URL.createObjectURL(r),s(n)}catch(e){t||l(e.message)}finally{t||d(!1)}}return r(),()=>{t=!0,n&&URL.revokeObjectURL(n)}},[e.artifactId]);function m(){if(!o)return;let e=document.createElement(`a`);e.href=o,e.download=a,document.body.appendChild(e),e.click(),e.remove()}return r?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>o&&p(!0),disabled:!o,className:`group/img mt-2 block overflow-hidden rounded-md border border-foreground/10 bg-black/10 text-left disabled:cursor-default relative`,children:o?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`img`,{src:o,alt:a,loading:`lazy`,className:`block max-h-72 max-w-full object-contain`}),(0,q.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center bg-black/0 group-hover/img:bg-black/30 transition-colors`,children:(0,q.jsx)(ce,{className:`w-6 h-6 text-white opacity-0 group-hover/img:opacity-100 transition-opacity drop-shadow-md`})})]}):(0,q.jsxs)(`span`,{className:i(`flex min-h-20 items-center gap-2 px-3 py-2 text-xs`,c?`text-red-400`:`text-muted-foreground`),children:[u?(0,q.jsx)(k,{className:`h-4 w-4 animate-spin`}):(0,q.jsx)(t,{className:`h-4 w-4`}),c||`Loading image`]})}),o&&(0,q.jsx)(Je,{open:f,onOpenChange:p,children:(0,q.jsxs)(We,{className:`max-w-[95vw] max-h-[95vh] w-auto p-0 bg-black/95 border-zinc-800 gap-0 overflow-hidden`,showCloseButton:!1,children:[(0,q.jsx)(Xe,{className:`sr-only`,children:a}),(0,q.jsxs)(`div`,{className:`relative flex items-center justify-center min-h-[200px]`,children:[(0,q.jsx)(`img`,{src:o,alt:a,className:`max-w-[93vw] max-h-[90vh] object-contain`}),(0,q.jsxs)(`div`,{className:`absolute top-2 right-2 flex gap-1`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:m,className:`rounded-md bg-black/60 hover:bg-black/80 p-2 text-white transition-colors`,title:`Download`,children:(0,q.jsx)(g,{className:`w-4 h-4`})}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>p(!1),className:`rounded-md bg-black/60 hover:bg-black/80 p-2 text-white transition-colors`,title:`Close`,children:(0,q.jsx)(D,{className:`w-4 h-4`})})]})]})]})})]}):(0,q.jsxs)(`button`,{type:`button`,onClick:m,disabled:!o,className:i(`mt-2 flex w-full items-center gap-2 rounded-md border px-2.5 py-2 text-left text-xs transition-colors disabled:cursor-default disabled:opacity-70`,n?`border-primary-foreground/20 bg-primary-foreground/10 hover:bg-primary-foreground/15`:`border-border bg-background hover:bg-muted`),children:[u?(0,q.jsx)(k,{className:`h-4 w-4 shrink-0 animate-spin`}):c?(0,q.jsx)(t,{className:`h-4 w-4 shrink-0 text-red-400`}):(0,q.jsx)(ae,{className:`h-4 w-4 shrink-0`}),(0,q.jsx)(`span`,{className:i(`min-w-0 flex-1 truncate`,c&&`text-red-400`),children:c||a}),(0,q.jsx)(g,{className:`h-3.5 w-3.5 shrink-0`})]})}function Yt({item:e,onRemove:n}){let[r,a]=(0,G.useState)(!1),o=!!(e.previewUrl&&!e.error);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 rounded-md border border-border bg-card px-2.5 py-2 text-xs`,children:[(0,q.jsx)(`button`,{type:`button`,disabled:!o,onClick:()=>a(!0),className:`group/pending relative flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded bg-muted disabled:cursor-default`,title:o?`Preview image`:e.fileName,children:e.previewUrl?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`img`,{src:e.previewUrl,alt:e.fileName,className:`h-full w-full object-cover`}),(0,q.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center bg-black/0 group-hover/pending:bg-black/30 transition-colors`,children:(0,q.jsx)(ce,{className:`h-3.5 w-3.5 text-white opacity-0 group-hover/pending:opacity-100 transition-opacity drop-shadow-md`})})]}):e.error?(0,q.jsx)(t,{className:`h-4 w-4 text-red-400`}):e.uploading?(0,q.jsx)(k,{className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,q.jsx)(ae,{className:`h-4 w-4 text-muted-foreground`})}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`p`,{className:`truncate font-medium`,children:e.fileName}),(0,q.jsx)(`p`,{className:i(`truncate text-muted-foreground`,e.error&&`text-red-400`),children:e.error||(e.uploading?`Uploading`:ct(e.size))})]}),(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,title:`Remove attachment`,onClick:n,children:(0,q.jsx)(D,{className:`h-3.5 w-3.5`})})]}),e.previewUrl&&(0,q.jsx)(Je,{open:r,onOpenChange:a,children:(0,q.jsxs)(We,{className:`max-w-[95vw] max-h-[95vh] w-auto p-0 bg-black/95 border-zinc-800 gap-0 overflow-hidden`,showCloseButton:!1,children:[(0,q.jsx)(Xe,{className:`sr-only`,children:e.fileName}),(0,q.jsxs)(`div`,{className:`relative flex items-center justify-center min-h-[200px]`,children:[(0,q.jsx)(`img`,{src:e.previewUrl,alt:e.fileName,className:`max-w-[93vw] max-h-[90vh] object-contain`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`absolute top-2 right-2 rounded-md bg-black/60 hover:bg-black/80 p-2 text-white transition-colors`,title:`Close`,children:(0,q.jsx)(D,{className:`w-4 h-4`})})]})]})})]})}function Xt({preview:e,error:t,onReadError:n,onMouseEnter:r,onMouseLeave:i}){let{anchor:a}=e,o=Math.min(560,window.innerWidth-24),s=Math.min(380,window.innerHeight-24),c=Math.max(12,Math.min(a.left,window.innerWidth-o-12));return(0,K.createPortal)((0,q.jsxs)(`div`,{className:`fixed z-50 flex flex-col overflow-hidden rounded-lg border border-border bg-background shadow-xl`,style:{top:window.innerHeight-a.bottom>=s+8?a.bottom+8:a.top-8-s>=12?a.top-8-s:Math.max(12,window.innerHeight-s-12),left:c,width:o,height:s},onMouseEnter:r,onMouseLeave:i,children:[(0,q.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center gap-2 border-b border-border px-2.5`,children:[(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] font-medium text-muted-foreground`,children:e.path}),t&&(0,q.jsx)(`span`,{className:`max-w-[12rem] truncate text-[11px] text-red-400`,children:t}),(0,q.jsx)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground/70`,children:`click to pin`})]}),(0,q.jsx)(`div`,{className:`min-h-0 flex-1`,children:e.type===`directory`?(0,q.jsx)($e,{orchestratorId:e.orchestratorId,selectedPath:e.path,onReadError:n}):(0,q.jsx)(et,{orchestratorId:e.orchestratorId,selectedPath:e.path,line:e.line,onReadError:n})})]}),document.body)}function Z({open:e,onToggle:t,onReact:n}){return(0,q.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,q.jsx)(`button`,{type:`button`,title:`Add reaction`,onClick:t,className:i(`inline-flex h-5 w-6 items-center justify-center rounded-full border border-border bg-popover text-muted-foreground shadow-sm transition hover:bg-muted hover:text-foreground`,e?`opacity-100`:`opacity-0 pointer-events-none md:group-hover/msg:opacity-100 md:group-hover/msg:pointer-events-auto`),children:(0,q.jsx)(w,{className:`h-3 w-3`})}),e&&(0,q.jsx)(`div`,{className:`absolute bottom-full left-0 z-30 mb-1 flex gap-0.5 rounded-full border border-border bg-popover p-0.5 shadow-md`,children:J.map(e=>(0,q.jsx)(`button`,{type:`button`,title:`React ${e}`,onClick:()=>n(e),className:`inline-flex h-6 w-7 items-center justify-center rounded-full text-xs transition-colors hover:bg-muted`,children:e},e))})]})}function Zt(){return(0,G.useSyncExternalStore)(e=>ve.subscribe(e),()=>ve.getPlayingKey(),()=>null)}var Qt=(0,G.memo)(function({msg:e,peer:t,onOpenReferencedPath:n,onPreviewReferencedPath:r,onPreviewReferencedPathEnd:a}){let o=e.from===Ce,s=M(e=>e.reactToMessage),c=M(e=>e.voiceTtsEnabled),l=Zt(),u=M(e=>{let n=e.agentsById[t]?.meta?.cwd;return typeof n==`string`?n:``}),[d,f]=(0,G.useState)(!1),p=(0,G.useRef)(null),h=(0,G.useRef)(null),g=(0,G.useRef)(!1),_=Fe(e),v=Et(e.occurredAt??e.createdAt),y=mt(e),b=ht(e),x=o?gt(e,t):null,S=x?.icon,C=l===String(e.id),w=c&&!o&&!Y(e)&&_.trim().length>0;function ee(t){t.stopPropagation(),C?ve.bargeIn():ve.speak(e.body,String(e.id))}(0,G.useEffect)(()=>{if(!d)return;function e(e){pt()||p.current&&!p.current.contains(e.target)&&f(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e)}},[d]);function E(e){return lt(u||`/`,e)}function te(e,t){let r=E(e);n?.(r,t)}function ne(e,t,n){let i=E(e);r?.(i,t,n)}function D(t){s(e,t),f(!1)}function O(e){e.button===0&&(h.current={x:e.clientX,y:e.clientY},g.current=!1)}function k(e){let t=h.current;t&&(Math.abs(e.clientX-t.x)>3||Math.abs(e.clientY-t.y)>3)&&(g.current=!0)}function re(t){if(!(Y(e)||o)&&!t.target.closest(`a,button,input,textarea,select,[role="button"]`)){if(g.current||pt()){g.current=!1;return}f(e=>!e)}}return(0,q.jsx)(`div`,{"data-msg-id":e.id,className:i(`group/msg flex mb-3`,o?`justify-end`:`justify-start`),children:(0,q.jsxs)(`div`,{ref:p,className:`relative max-w-[85%] md:max-w-[75%]`,children:[w&&(0,q.jsx)(`button`,{type:`button`,title:C?`Stop playback`:`Play aloud`,onClick:ee,className:i(`absolute -top-2 -right-2 z-20 inline-flex h-6 w-6 items-center justify-center rounded-full border bg-popover shadow-sm transition`,C?`border-primary/50 text-primary opacity-100`:`border-border text-muted-foreground opacity-70 hover:bg-muted hover:text-foreground hover:opacity-100 [@media(hover:hover)]:md:opacity-0 [@media(hover:hover)]:md:group-hover/msg:opacity-100`),children:C?(0,q.jsx)(m,{className:`h-3.5 w-3.5 animate-pulse`}):(0,q.jsx)(T,{className:`h-3.5 w-3.5`})}),(0,q.jsxs)(`div`,{className:i(`rounded-2xl px-3.5 py-2 text-sm select-text`,!o&&!Y(e)&&`cursor-pointer`,o?`bg-primary text-primary-foreground rounded-br-sm`:`bg-card ring-1 ring-foreground/10 rounded-bl-sm`),onPointerDown:O,onPointerMove:k,onClick:re,children:[e.subject&&(0,q.jsx)(`p`,{className:i(`text-xs font-semibold mb-1`,o?`text-primary-foreground/70`:`text-muted-foreground`),children:e.subject}),(0,q.jsx)(U,{text:_,rawBody:e.body,className:`leading-relaxed`,onOpenPath:te,onPreviewPath:ne,onPreviewPathEnd:a,resolvePathTitle:(e,t)=>`${E(e)}${t?`:${t}`:``}`}),y.map(t=>(0,q.jsx)(Jt,{attachment:t,outbound:o},`${e.id}-${t.artifactId}-${t.role||``}`)),(0,q.jsxs)(`p`,{className:i(`text-xs mt-1 flex items-center gap-1.5`,o?`justify-end text-primary-foreground/60`:`justify-end text-muted-foreground`),children:[(0,q.jsxs)(`span`,{className:`opacity-40`,children:[`#`,e.id]}),(0,q.jsx)(`span`,{children:v}),x&&S&&(0,q.jsxs)(`span`,{className:i(`inline-flex items-center gap-1`,x.tone===`ok`&&`text-emerald-300`,x.tone===`warn`&&`text-amber-200`,x.tone===`danger`&&`text-red-200`),title:x.title,children:[(0,q.jsx)(S,{className:`h-3 w-3`}),x.label]})]})]}),!Y(e)&&b.length>0&&(0,q.jsxs)(`div`,{className:i(`flex flex-wrap items-center gap-0.5 -mt-1 relative z-10`,o?`justify-end pr-2`:`justify-start pl-2`),children:[!o&&(0,q.jsx)(Z,{open:d,onToggle:()=>f(e=>!e),onReact:D}),b.map(e=>(0,q.jsxs)(`button`,{type:`button`,title:e.actors.join(`, `),onClick:()=>D(e.emoji),className:i(`inline-flex h-5 items-center gap-0.5 rounded-full border px-1.5 text-[11px] shadow-sm transition-colors`,e.mine?`border-primary/40 bg-primary/10 text-primary`:`border-border bg-background hover:bg-muted text-foreground`),children:[(0,q.jsx)(`span`,{children:e.emoji}),e.count>1&&(0,q.jsx)(`span`,{children:e.count})]},e.emoji))]}),!Y(e)&&!o&&b.length===0&&(0,q.jsx)(`div`,{className:`absolute -bottom-2.5 left-1 z-20`,children:(0,q.jsx)(Z,{open:d,onToggle:()=>f(e=>!e),onReact:D})})]})})});function $t(e){if(e.kind!==`session`)return null;let t=e.payload?.session;return!t||t.type!==`narration`&&t.type!==`reasoning`&&t.type!==`tool`?null:{id:e.id,kind:t.type,label:typeof t.label==`string`?t.label:void 0,text:e.body,ts:Dt(e),turnId:typeof t.turnId==`string`?t.turnId:void 0}}function en(e){let t=new Date(e);return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}function tn(e){let t=e.filter(e=>jt.has(e.status)).slice().sort((e,t)=>e.timestamp-t.timestamp),n=[];for(let e of t)n.some(t=>t.id===e.id)||n.some(t=>t.status===e.status&&Math.abs(t.timestamp-e.timestamp)<=Mt)||n.push(e);return n}function Q(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=Nt}function nn(e,t){let n=(0,G.useRef)(null),r=(0,G.useRef)(!0),i=(0,G.useRef)(null),a=(0,G.useCallback)(()=>{let e=n.current;e&&(r.current=Q(e))},[]);return(0,G.useLayoutEffect)(()=>{let t=n.current;t&&(i.current!==e&&(i.current=e,r.current=!0),r.current&&(t.scrollTop=t.scrollHeight))},[e,...t]),{ref:n,onScroll:a}}function rn(e){for(let t of e)t.previewUrl&&URL.revokeObjectURL(t.previewUrl)}function an(e,t,n,r=[]){let i=[];for(let e of r){let t=e.entries.reduce((e,t)=>Math.min(e,R(t.originalCreatedAt)),1/0),n=Number.isFinite(t)?t-1:e.importedAt;i.push({ts:n,entry:{type:`import-boundary`,history:e,timestamp:n}});for(let t of e.entries)i.push({ts:R(t.originalCreatedAt),entry:{type:`imported-message`,history:e,entry:t}})}if(n){let e=new Date(n).getTime();Number.isFinite(e)&&i.push({ts:e,entry:{type:`created`,timestamp:e}})}let a=new Set;for(let t of e){if(t.kind!==`session`)continue;let e=t.payload?.session;e?.type===`response`&&typeof e.turnId==`string`&&a.add(`${e.turnId} ${t.body.trim()}`)}for(let t of e){if(Y(t))continue;let e=$t(t);if(e){if(e.kind===`narration`&&e.turnId&&a.has(`${e.turnId} ${e.text.trim()}`))continue;i.push({ts:e.ts,entry:{type:`activity`,steps:[e],timestamp:e.ts}});continue}i.push({ts:Dt(t),entry:{type:`message`,msg:t}})}for(let e of tn(t))i.push({ts:e.timestamp,entry:{type:`status`,event:e}});let o={created:0,date:1,"import-boundary":2,"imported-message":3,message:4,activity:4,status:5};i.sort((e,t)=>{let n=e.ts-t.ts;return Math.abs(n)<3e3&&o[e.entry.type]-o[t.entry.type]||n});let s=[],c=``;for(let{ts:e,entry:t}of i){if(t.type===`created`){s.push(t);continue}let n=en(e);if(n!==c&&(s.push({type:`date`,date:n,timestamp:e}),c=n),t.type===`activity`){let e=s[s.length-1];if(e&&e.type===`activity`&&on(e,t)){e.steps.push(...t.steps);continue}}s.push(t)}return s}function on(e,t){let n=e.steps[e.steps.length-1]?.turnId,r=t.steps[0]?.turnId;return n&&r?n===r:!n&&!r}function sn({scrollRef:e,timeline:t}){let[n,r]=(0,G.useState)(!0),[a,o]=(0,G.useState)(!1),[s,c]=(0,G.useState)(!1),[l,u]=(0,G.useState)(!0),d=(0,G.useMemo)(()=>{for(let e=t.length-1;e>=0;e--){let n=t[e];if(!(!n||n.type!==`message`)&&n.msg.from===`user`)return{id:n.msg.id,body:Fe(n.msg)}}return null},[t]);if((0,G.useEffect)(()=>{let t=e.current;if(!d||!t){r(!0);return}let n=t.querySelector(`[data-msg-id="${d.id}"]`);if(!n){r(!0);return}let i=new IntersectionObserver(([e])=>{if(e&&(r(e.isIntersecting),!e.isIntersecting)){let n=e.rootBounds?.top??t.getBoundingClientRect().top;u(e.boundingClientRect.top<n)}},{root:t,threshold:0});i.observe(n);let a=()=>{let e=n.getBoundingClientRect(),r=t.getBoundingClientRect();u(e.top<r.top)};return t.addEventListener(`scroll`,a,{passive:!0}),()=>{i.disconnect(),t.removeEventListener(`scroll`,a)}},[d?.id,e]),(0,G.useEffect)(()=>{o(!1),c(!1)},[d?.id]),n||!d||!d.body.trim())return null;function f(){let t=e.current;!t||!d||t.querySelector(`[data-msg-id="${d.id}"]`)?.scrollIntoView({behavior:`smooth`,block:`center`})}let p=l?`↑`:`↓`;return s?(0,q.jsx)(`div`,{className:`sticky top-0 z-10 -mx-3 md:-mx-4 -mt-3 md:-mt-4 bg-background`,children:(0,q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center justify-center gap-1.5 py-1 text-[11px] text-primary/60 hover:text-primary border-b border-primary/10 transition-colors`,onClick:()=>c(!1),children:[(0,q.jsx)(`span`,{children:`Your prompt`}),(0,q.jsx)(le,{className:`w-3 h-3`})]})}):(0,q.jsxs)(`div`,{className:`sticky top-0 z-10 -mx-3 md:-mx-4 -mt-3 md:-mt-4 px-2 md:px-3 pt-2 pb-1.5 bg-background border-b border-primary/10`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-muted-foreground mb-0.5`,children:[(0,q.jsx)(`span`,{className:`font-medium text-primary/70`,children:`Your prompt`}),(0,q.jsxs)(`button`,{type:`button`,className:`ml-auto hover:text-foreground transition-colors`,onClick:f,children:[p,` scroll to original`]}),(0,q.jsx)(`button`,{type:`button`,className:`hover:text-foreground transition-colors`,onClick:()=>c(!0),title:`Minimize`,children:(0,q.jsx)(E,{className:`w-3 h-3`})})]}),(0,q.jsx)(`p`,{className:i(`text-sm text-foreground leading-snug cursor-pointer`,!a&&`line-clamp-2`),onClick:()=>o(e=>!e),children:d.body})]})}function $({threads:e,onBack:t,showBackButton:r}){let d=M(e=>e.selectedInboxThread),y=M(e=>e.agentsById),b=M(e=>e.inboxDrafts),x=ye(),S=M(e=>e.sendChatMessage),C=M(e=>e.openFilesAt),w=M(e=>e.openFilesForAgent),ee=M(e=>e.openAgentDetail),E=M(e=>e.chatSending),O=M(e=>e.markInboxThreadRead),re=M(e=>e.markInboxThreadUnread),ie=M(e=>e.setReplyDraft),ae=M(e=>e.exportThread),A=M(e=>e.doAgentAction),oe=M(e=>e.workspaceAction),se=M(e=>e.openWorkspaceFocus),ce=M(e=>e.forkFromAgent),le=M(e=>e.chatHistoryImports),de=M(e=>e.threadHistory[e.selectedInboxThread]??bt),j=M(e=>e.openConfirm),pe=M(e=>e.showError),he=M(e=>e.orchestrators),_e=M(e=>e.fetchOrchestrators),Ce=M(e=>e.showReasoning),N=M(e=>e.voiceTtsEnabled),we=M(e=>e.setVoiceTtsEnabled),Te=M(e=>e.voiceInputMode),De=(0,G.useRef)(null),ke=(0,G.useRef)(null),[P,je]=(0,G.useState)(`idle`),Me=(0,G.useRef)([]),[F,I]=(0,G.useState)([]),[Fe,R]=(0,G.useState)(!1),[B,Be]=(0,G.useState)(null),[We,qe]=(0,G.useState)(null),[Je,V]=(0,G.useState)(``),H=(0,G.useRef)(null),Xe=(0,G.useRef)(0),Qe=xt(d),U=(0,G.useMemo)(()=>e.find(e=>e.peer===d)||null,[e,d]),tt=(0,G.useMemo)(()=>{let e=U?.messages??[];if(de.length===0)return e;let t=new Map;for(let e of de)Ne(e)===d&&!Ae(e)&&t.set(e.id,e);for(let n of e)t.set(n.id,n);return[...t.values()].sort((e,t)=>e.id-t.id)},[U?.messages,de,d]),K=y[d]||null,it=typeof K?.meta?.lifecycleAction==`string`&&K.meta.lifecycleAction.startsWith(`finalizing-`),{terminalOpen:at,terminalTarget:ot,terminalOpening:ct,openTerminal:lt,closeTerminal:pt}=nt(K?.id),mt=typeof K?.meta?.spawnRequestId==`string`?K.meta.spawnRequestId:``,J=(0,G.useMemo)(()=>le.filter(e=>e.targetAgentId===d||!!(mt&&e.targetSpawnRequestId===mt)),[mt,le,d]),ht=Oe(K),Y=ht?.pendingApproval,gt=U||(J.length>0?{peer:d,messages:[],importedHistory:J}:null),X=b[d]||``,_t=J.reduce((e,t)=>e+t.entries.length,0),vt=nn(d,[tt.length,Qe.length,_t,Y?.id,K?.status]),yt=typeof K?.meta?.tmuxSession==`string`&&K.meta.tmuxSession.trim()?K.meta.tmuxSession:null,Ct=yt?he.find(e=>e.managedAgents?.some(e=>e.agentId===K.id||e.tmuxSession===yt))??null:null,Tt=!!(yt&&Ct?.status===`online`&&K?.providerCapabilities?.terminal?.live?.read),Et=K?.providerCapabilities?.model?.provider??(typeof K?.meta?.provider==`string`?K.meta.provider:void 0),Dt=!!(Tt&&(K?.providerCapabilities?.terminal?.live?.write||Et===`claude`)),Ot=K?.providerCapabilities?.terminal?.attach?.create===!0,kt=Tt||Ot,At=Pe(K,`compact`),jt=Pe(K,`clearContext`),Mt=Pe(K,`shutdown`),Nt=Pe(K,`interrupt`),It=()=>{K&&A(K,`interrupt`)},[Lt,Rt]=(0,G.useState)(0),[Vt,Ht]=(0,G.useState)(!1),Ut=K?.providerCapabilities?.liveSession?.slashCommands===!0,Jt=K?.providerCapabilities?.model?.provider??(typeof K?.meta?.provider==`string`?K.meta.provider:void 0),Z=Ut&&!Vt&&/^\/\S*$/.test(X)?st(Jt).filter(e=>e.name.toLowerCase().startsWith(X.toLowerCase())):[],Zt=Z.length?Math.min(Lt,Z.length-1):0;function $t(e){ie(d,`${e.name} `),Rt(0)}function en(e){ie(d,e),Vt&&Ht(!1),Rt(0)}let tn=F.some(e=>e.uploading),Q=F.filter(e=>e.artifact);St(X.trim().length>0||F.length>0,(0,G.useCallback)(()=>{},[])),Me.current=F,(0,G.useEffect)(()=>()=>{rn(Me.current)},[]),(0,G.useEffect)(()=>{K?.meta?.tmuxSession&&he.length===0&&_e()},[K?.id,K?.meta?.tmuxSession,he.length]),(0,G.useEffect)(()=>()=>{H.current!==null&&window.clearTimeout(H.current)},[]);let on=(0,G.useMemo)(()=>an(tt,Qe,K?.createdAt,J),[tt,Qe,K?.createdAt,J]),$=(0,G.useCallback)(()=>{H.current!==null&&(window.clearTimeout(H.current),H.current=null)},[]),cn=(0,G.useCallback)(async e=>{let t=dt(he,e);if(!t)return null;try{let r=await n(`GET`,`/orchestrators/${encodeURIComponent(t.id)}/files/stat?path=${encodeURIComponent(e)}`);return{orchestratorId:t.id,path:r.path,type:r.type}}catch{return null}},[he]),ln=(0,G.useCallback)((e,t,n)=>{if(!ft()||!n)return;let r=++Xe.current;cn(e).then(e=>{Xe.current===r&&e&&($(),qe({...e,line:t||0,anchor:n}),V(``))})},[$,cn]),un=(0,G.useCallback)(()=>{Xe.current+=1,$(),H.current=window.setTimeout(()=>{qe(null)},250)},[$]),dn=(0,G.useCallback)((e,t)=>{cn(e).then(n=>{if(!n){pe(`File Not Found`,e);return}if(ft()){Xe.current+=1,$(),qe(null),Be({...n,line:t||0}),V(``);return}n.type===`directory`?C({orchestratorId:n.orchestratorId,path:n.path,overlay:!0}):C({orchestratorId:n.orchestratorId,path:ut(n.path),selectedPath:n.path,line:t,overlay:!0})})},[$,C,cn,pe]);function fn(){Be(null),V(``)}async function pn(e){let t=Array.from(e).filter(e=>e.size>0);if(!t.length)return;let n=t.map(e=>({id:`${Date.now()}-${e.name}-${Math.random().toString(16).slice(2)}`,fileName:e.name,size:e.size,previewUrl:e.type.startsWith(`image/`)?URL.createObjectURL(e):void 0,uploading:!0}));I(e=>[...e,...n]);for(let e=0;e<t.length;e+=1){let r=t[e],i=n[e];try{let e=await v(`/artifacts`,r,{filename:r.name,sensitivity:`normal`});I(t=>t.map(t=>t.id===i.id?{...t,artifact:e,uploading:!1}:t))}catch(e){I(t=>t.map(t=>t.id===i.id?{...t,error:e.message,uploading:!1}:t))}}}function mn(e){I(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})}function hn(){rn(F),I([])}function gn(){if(!X.trim()&&Q.length===0||!d||E||tn||it)return;let e=Q.map(e=>({artifactId:e.artifact.id,kind:e.artifact.kind,role:`media`,title:e.artifact.filename||e.fileName}));S(X,{peer:d,lastMessage:U?.lastMessage||null},e),hn()}function _n(e){if(Z.length){if(e.key===`ArrowDown`){e.preventDefault(),Rt(e=>Math.min(e+1,Z.length-1));return}if(e.key===`ArrowUp`){e.preventDefault(),Rt(e=>Math.max(e-1,0));return}if(e.key===`Escape`){e.preventDefault(),Ht(!0);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let t=Z[Zt];t&&$t(t);return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),gn())}function vn(e){let t=Array.from(e.clipboardData.files).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),pn(t))}async function yn(){if(!be||P!==`idle`||!d)return;ve.bargeIn();let e=new xe;try{await e.start(),ke.current=e,je(`recording`)}catch(e){ke.current=null,je(`idle`),pe(`Microphone unavailable`,e?.message||`Could not access the microphone.`)}}async function bn(){let e=ke.current;if(!(!e||P!==`recording`)){ke.current=null,je(`transcribing`);try{let t=await e.stop();if(!t)return;let n=await Se(t);if(!n)return;let r=X?`${X} ${n}`:n;if(Te===`autosend`&&!E&&!tn){let e=Q.map(e=>({artifactId:e.artifact.id,kind:e.artifact.kind,role:`media`,title:e.artifact.filename||e.fileName}));S(r,{peer:d,lastMessage:U?.lastMessage||null},e),hn()}else ie(d,r)}catch(e){pe(`Transcription failed`,e?.message||`Could not transcribe audio.`)}finally{je(`idle`)}}}return d?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`flex h-full min-w-0`,children:[(0,q.jsxs)(`div`,{className:`@container/chat flex h-full min-w-0 flex-1 flex-col`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between px-3 md:px-4 py-2.5 md:py-3 border-b border-border shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 md:gap-2.5 min-w-0`,children:[r&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,onClick:t,className:`shrink-0 -ml-1`,children:(0,q.jsx)(me,{className:`w-4 h-4`})}),(0,q.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 md:gap-2.5 min-w-0 hover:opacity-80 transition-opacity`,onClick:()=>K&&ee(K),disabled:!K,children:[(0,q.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,q.jsx)(Ke,{agent:K}),(0,q.jsx)(Ue,{agent:K,now:x,className:`absolute -bottom-0.5 -right-0.5 w-2 h-2`})]}),(0,q.jsxs)(`div`,{className:`min-w-0 text-left`,children:[(0,q.jsx)(`p`,{className:`text-sm font-medium truncate`,children:K?L(K):d}),K&&(0,q.jsxs)(`p`,{className:`text-xs text-muted-foreground truncate`,children:[ht?`blocked: ${ht.label}`:K.status,K.machine&&` · ${K.machine}`,typeof K.meta?.cwd==`string`&&K.meta.cwd&&` · ${Ee(K.meta.cwd,1)}`]})]})]}),K&&(0,q.jsx)(Ge,{agent:K,compact:!0,className:`hidden @4xl/chat:flex shrink-0`}),K?.context&&(0,q.jsx)(Ze,{utilization:K.context.utilization}),K?.branchState&&K.branchWorkspaceId&&(0,q.jsx)(rt,{state:K.branchState,className:`shrink-0`,onClick:()=>void se(K.branchWorkspaceId)}),U?.attention.unread?(0,q.jsxs)(Ie,{className:`bg-red-500/20 text-red-400 text-xs shrink-0 hidden @2xl/chat:flex`,children:[U.attention.unread,` unread`]}):null]}),(0,q.jsx)(`div`,{className:`flex items-center gap-0.5 md:gap-1 shrink-0`,children:K&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Le,{value:K.id,label:`Copy agent ID`,size:`icon-sm`}),ve.available&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,title:N?`Speaking agent responses aloud — click to mute (engine & voice in Settings)`:`Speak agent responses aloud (active chat) — engine & voice in Settings`,className:N?`text-primary`:``,onClick:()=>we(!N),children:N?(0,q.jsx)(T,{className:`w-3.5 h-3.5`}):(0,q.jsx)(ue,{className:`w-3.5 h-3.5`})}),kt&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,disabled:ct,title:`Terminal`,onClick:()=>void lt(),children:(0,q.jsx)(ne,{className:`w-3.5 h-3.5`})}),Nt&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`text-red-400 hover:text-red-300`,title:`Interrupt`,onClick:It,children:(0,q.jsx)(m,{className:`w-3.5 h-3.5`})}),(K.branchState===`changes`||K.branchState===`idle`)&&K.branchWorkspaceId&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex text-amber-400 hover:text-amber-300`,title:`Mark workspace ready — hand off to the auto-merge`,onClick:()=>j(`Mark Workspace Ready`,`Mark ${L(K)}'s branch ready to land? The relay auto-merge will rebase and land it.`,()=>oe(K.branchWorkspaceId,`ready`)),children:(0,q.jsx)(a,{className:`w-3.5 h-3.5`})}),At&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Compact`,onClick:()=>j(`Compact Agent`,`Compact context for ${L(K)}?`,()=>A(K,`compact`)),children:(0,q.jsx)(l,{className:`w-3.5 h-3.5`})}),jt&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Clear context`,onClick:()=>j(`Clear Context`,`Clear context for ${L(K)}?`,()=>A(K,`clearContext`)),children:(0,q.jsx)(c,{className:`w-3.5 h-3.5`})}),Mt&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Shutdown`,onClick:()=>j(`Shutdown Agent`,`Shutdown ${L(K)}?`,()=>A(K,`shutdown`)),children:(0,q.jsx)(_,{className:`w-3.5 h-3.5`})}),K&&typeof K.meta?.cwd==`string`&&K.meta.cwd&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Open ${K.meta.cwd} in Files`,onClick:()=>void w(K),children:(0,q.jsx)(s,{className:`w-3.5 h-3.5`})}),K&&U&&U.messages.length>0&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Fork — spawn new agent with this chat history`,onClick:()=>ce(K.id,U.messages),children:(0,q.jsx)(ge,{className:`w-3.5 h-3.5`})}),U&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Mark unread`,onClick:()=>re(d),children:(0,q.jsx)(te,{className:`w-3.5 h-3.5`})}),U&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Mark read`,onClick:()=>O(U.peer,U.messages),children:(0,q.jsx)(fe,{className:`w-3.5 h-3.5`})}),gt&&(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`hidden @4xl/chat:inline-flex`,title:`Export thread`,onClick:()=>ae({...gt,importedHistory:J},`json`),children:(0,q.jsx)(g,{className:`w-3.5 h-3.5`})}),(0,q.jsxs)(Ve,{children:[(0,q.jsx)(ze,{asChild:!0,children:(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,className:`@4xl/chat:hidden`,children:(0,q.jsx)(f,{className:`w-3.5 h-3.5`})})}),(0,q.jsxs)(Re,{align:`end`,children:[kt&&(0,q.jsxs)(W,{disabled:ct,onClick:()=>void lt(),children:[(0,q.jsx)(ne,{className:`w-3.5 h-3.5`}),`Terminal`]}),Nt&&(0,q.jsxs)(W,{onClick:It,children:[(0,q.jsx)(m,{className:`w-3.5 h-3.5`}),`Interrupt`]}),(K.branchState===`changes`||K.branchState===`idle`)&&K.branchWorkspaceId&&(0,q.jsxs)(W,{onClick:()=>j(`Mark Workspace Ready`,`Mark ${L(K)}'s branch ready to land? The relay auto-merge will rebase and land it.`,()=>oe(K.branchWorkspaceId,`ready`)),children:[(0,q.jsx)(a,{className:`w-3.5 h-3.5`}),`Mark Ready`]}),At&&(0,q.jsxs)(W,{onClick:()=>j(`Compact Agent`,`Compact context for ${L(K)}?`,()=>A(K,`compact`)),children:[(0,q.jsx)(l,{className:`w-3.5 h-3.5`}),`Compact`]}),jt&&(0,q.jsxs)(W,{onClick:()=>j(`Clear Context`,`Clear context for ${L(K)}?`,()=>A(K,`clearContext`)),children:[(0,q.jsx)(c,{className:`w-3.5 h-3.5`}),`Clear Context`]}),Mt&&(0,q.jsxs)(W,{onClick:()=>j(`Shutdown Agent`,`Shutdown ${L(K)}?`,()=>A(K,`shutdown`)),children:[(0,q.jsx)(_,{className:`w-3.5 h-3.5`}),`Shutdown`]}),K&&typeof K.meta?.cwd==`string`&&K.meta.cwd&&(0,q.jsxs)(W,{onClick:()=>void w(K),children:[(0,q.jsx)(s,{className:`w-3.5 h-3.5`}),`Open Files`]}),K&&U&&U.messages.length>0&&(0,q.jsxs)(W,{onClick:()=>ce(K.id,U.messages),children:[(0,q.jsx)(ge,{className:`w-3.5 h-3.5`}),`Fork`]}),(kt||At||jt||Mt)&&(0,q.jsx)(He,{}),U&&(0,q.jsxs)(W,{onClick:()=>re(d),children:[(0,q.jsx)(te,{className:`w-3.5 h-3.5`}),`Mark Unread`]}),U&&(0,q.jsxs)(W,{onClick:()=>O(U.peer,U.messages),children:[(0,q.jsx)(fe,{className:`w-3.5 h-3.5`}),`Mark Read`]}),gt&&(0,q.jsxs)(W,{onClick:()=>ae({...gt,importedHistory:J},`json`),children:[(0,q.jsx)(g,{className:`w-3.5 h-3.5`}),`Download`]})]})]})]})})]}),(0,q.jsx)(`div`,{ref:vt.ref,onScroll:vt.onScroll,className:`flex-1 overflow-y-auto px-3 md:px-4 py-3 md:py-4`,style:{minHeight:0},children:on.length===0?(0,q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-center`,children:[(0,q.jsx)(p,{className:`w-8 h-8 text-zinc-600 mb-2`}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No messages yet`})]}):(0,q.jsxs)(`div`,{children:[(0,q.jsx)(sn,{scrollRef:vt.ref,timeline:on}),on.map(e=>e.type===`message`?(0,q.jsx)(Qt,{msg:e.msg,peer:d,onOpenReferencedPath:dn,onPreviewReferencedPath:ln,onPreviewReferencedPathEnd:un},e.msg.id):e.type===`activity`?(0,q.jsx)(zt,{steps:e.steps,showReasoning:Ce},`act-${e.steps[0]?.id??e.timestamp}`):e.type===`import-boundary`?(0,q.jsx)(Kt,{history:e.history},`import-${e.history.id}`):e.type===`imported-message`?(0,q.jsx)(qt,{entry:e.entry,sourceLabel:e.history.sourceAgentLabel||e.history.sourcePeerId},`import-${e.history.id}-${e.entry.originalMessageId}-${e.entry.position}`):e.type===`status`?(0,q.jsx)(Pt,{event:e.event},e.event.id):e.type===`date`?(0,q.jsx)(Wt,{date:e.date},`d-${e.date}`):e.type===`created`?(0,q.jsx)(Gt,{timestamp:e.timestamp},`created`):null),Y&&K&&(0,q.jsx)(Bt,{agentId:K.id,approval:Y}),K?.status===`busy`&&!Y&&(0,q.jsx)(Ft,{blockedLabel:ht?.label,onInterrupt:Nt?It:void 0})]})}),(0,q.jsxs)(`div`,{className:i(`relative shrink-0 border-t border-border px-3 md:px-4 py-2.5 md:py-3 safe-area-bottom`,Fe&&`bg-primary/5 ring-1 ring-primary/40`),onDragOver:e=>{e.preventDefault(),R(!0)},onDragLeave:()=>R(!1),onDrop:e=>{e.preventDefault(),R(!1),pn(e.dataTransfer.files)},children:[F.length>0&&(0,q.jsx)(`div`,{className:`mb-2 grid gap-2 sm:grid-cols-2`,children:F.map(e=>(0,q.jsx)(Yt,{item:e,onRemove:()=>mn(e.id)},e.id))}),(0,q.jsx)(`input`,{ref:De,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{e.target.files&&pn(e.target.files),e.currentTarget.value=``}}),Z.length>0&&(0,q.jsx)(`div`,{className:`absolute bottom-full left-3 right-3 md:left-4 md:right-4 mb-2 z-20 max-h-64 overflow-auto rounded-xl border border-border bg-popover shadow-lg`,children:Z.map((e,t)=>(0,q.jsxs)(`button`,{onMouseDown:t=>{t.preventDefault(),$t(e)},onMouseEnter:()=>Rt(t),className:i(`flex w-full items-baseline gap-2 px-3 py-1.5 text-left text-sm`,t===Zt?`bg-accent`:`hover:bg-accent/50`),children:[(0,q.jsx)(`span`,{className:`font-medium shrink-0`,children:e.name}),e.argumentHint&&(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:e.argumentHint}),e.description&&(0,q.jsx)(`span`,{className:`ml-auto truncate text-xs text-muted-foreground/70`,children:e.description})]},e.name))}),(0,q.jsxs)(`div`,{className:`hidden md:flex items-end gap-2`,children:[(0,q.jsx)(z,{variant:`ghost`,size:`icon`,title:`Attach files`,disabled:E,onClick:()=>De.current?.click(),className:`shrink-0 mb-0.5 rounded-xl h-[42px] w-[42px]`,children:(0,q.jsx)(u,{className:`w-4 h-4`})}),(0,q.jsx)(wt,{value:X,onChange:e=>en(e.target.value),onKeyDown:_n,onPaste:vn,placeholder:`Message ${K?L(K):d}…`,className:`flex-1`}),be&&(0,q.jsx)(z,{variant:`ghost`,size:`icon`,title:P===`recording`?`Release to transcribe`:`Hold to talk`,disabled:E||P===`transcribing`,onPointerDown:e=>{e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId),yn()},onPointerUp:e=>{e.preventDefault();try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}bn()},className:`shrink-0 mb-0.5 rounded-xl h-[42px] w-[42px] ${P===`recording`?`text-red-400 animate-pulse`:``}`,children:P===`transcribing`?(0,q.jsx)(k,{className:`w-4 h-4 animate-spin`}):(0,q.jsx)(h,{className:`w-4 h-4`})}),(0,q.jsx)(z,{size:`icon`,disabled:!X.trim()&&Q.length===0||tn||E||it,onClick:gn,className:`shrink-0 mb-0.5 rounded-xl h-[42px] w-[42px]`,children:(0,q.jsx)(o,{className:`w-4 h-4`})})]}),(0,q.jsxs)(`div`,{className:`md:hidden space-y-2`,children:[(0,q.jsx)(wt,{value:X,onChange:e=>en(e.target.value),onKeyDown:_n,onPaste:vn,placeholder:`Message ${K?L(K):d}…`,className:`w-full`}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(z,{variant:`ghost`,size:`icon`,title:`Attach files`,disabled:E,onClick:()=>De.current?.click(),className:`rounded-xl h-9 w-9`,children:(0,q.jsx)(u,{className:`w-4 h-4`})}),be&&(0,q.jsx)(z,{variant:`ghost`,size:`icon`,title:P===`recording`?`Release to transcribe`:`Hold to talk`,disabled:E||P===`transcribing`,onPointerDown:e=>{e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId),yn()},onPointerUp:e=>{e.preventDefault();try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}bn()},className:`rounded-xl h-9 w-9 ${P===`recording`?`text-red-400 animate-pulse`:``}`,children:P===`transcribing`?(0,q.jsx)(k,{className:`w-4 h-4 animate-spin`}):(0,q.jsx)(h,{className:`w-4 h-4`})})]}),(0,q.jsx)(z,{size:`icon`,disabled:!X.trim()&&Q.length===0||tn||E||it,onClick:gn,className:`rounded-xl h-9 w-9`,children:(0,q.jsx)(o,{className:`w-4 h-4`})})]})]}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1.5 hidden md:block`,children:it?`${K?L(K):`Agent`} is wrapping up (${(K?.meta?.lifecycleAction).slice(11)}) — messaging paused`:`Enter to send · Shift+Enter for newline`})]})]}),B&&(0,q.jsxs)(`aside`,{className:`hidden h-full w-[min(44vw,720px)] min-w-[360px] shrink-0 flex-col border-l border-border bg-background xl:flex`,children:[(0,q.jsxs)(`div`,{className:`flex h-10 shrink-0 items-center gap-2 border-b border-border px-3`,children:[(0,q.jsx)(`span`,{className:`min-w-0 flex-1 text-xs font-medium text-muted-foreground`,children:`File preview`}),Je&&(0,q.jsx)(`span`,{className:`max-w-[18rem] truncate text-xs text-red-400`,children:Je}),(0,q.jsx)(z,{variant:`ghost`,size:`icon-sm`,title:`Close preview`,onClick:fn,children:(0,q.jsx)(D,{className:`h-3.5 w-3.5`})})]}),(0,q.jsx)(`div`,{className:`min-h-0 flex-1`,children:B.type===`directory`?(0,q.jsx)($e,{orchestratorId:B.orchestratorId,selectedPath:B.path,onReadError:V}):(0,q.jsx)(et,{orchestratorId:B.orchestratorId,selectedPath:B.path,line:B.line,onReadError:V})})]})]}),We&&(0,q.jsx)(Xt,{preview:We,error:Je,onReadError:V,onMouseEnter:$,onMouseLeave:un}),ot&&(0,q.jsx)(Ye,{open:at,onOpenChange:pt,orchestratorId:ot.orchestratorId,session:ot.session,interactive:ot.interactive||Dt})]}):(0,q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-center px-4`,children:[(0,q.jsx)(p,{className:`w-12 h-12 text-zinc-600 mb-3`}),(0,q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Select an agent to start chatting`})]})}function cn(){let e=V(),t=M(e=>e.selectedInboxThread),n=M(e=>e.set),r=vt(),i=!!t;Ct(),(0,G.useEffect)(()=>{t&&(r.some(e=>e.id===t)||n({selectedInboxThread:``}))},[t,r,n]);function a(){n({selectedInboxThread:``})}return(0,q.jsxs)(`div`,{className:`flex -m-4 md:-m-6`,style:{height:`calc(100dvh - var(--header-h) - var(--sat))`},children:[(0,q.jsxs)(`div`,{className:`hidden md:flex w-full`,children:[(0,q.jsx)(`div`,{className:`w-1/3 min-w-[240px] max-w-xs flex flex-col overflow-hidden`,children:(0,q.jsx)(Tt,{threads:e})}),(0,q.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:(0,q.jsx)($,{threads:e},t||`empty`)})]}),(0,q.jsx)(`div`,{className:`md:hidden flex w-full overflow-hidden`,children:i?(0,q.jsx)(ln,{children:(0,q.jsx)($,{threads:e,onBack:a,showBackButton:!0},t||`empty`)}):(0,q.jsx)(`div`,{className:`w-full flex flex-col overflow-hidden`,children:(0,q.jsx)(Tt,{threads:e})})})]})}function ln({children:e}){let t=tt();return(0,q.jsx)(`div`,{className:`fixed inset-x-0 top-0 z-40 flex flex-col bg-background pt-[var(--sat)]`,style:{height:t?`${t}px`:`100dvh`},children:e})}export{cn as ChatView};
2
+ //# sourceMappingURL=chat-5hvHZcAe.js.map