@arbor-education/agent-view-frontend 0.9.2-alpha.0 → 0.9.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.
package/dist/index.cjs CHANGED
@@ -1,8 +1,9 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),a=require("react"),J=require("classnames"),c=require("@arbor-education/design-system.components"),Ge=require("@arbor-education/ask-arbor-chat-panel"),Zs=require("pusher-js"),y={"generating-a-response":"generating-a-response",hitl:"hitl",paused:"paused",complete:"complete"},M={"generating-a-response":"generating-a-response",to_do:"to_do",hitl:"hitl",complete:"complete",failed:"failed"},F={briefing:"briefing",running:"running",paused:"paused",complete:"complete"},ue={agent:"agent",user:"user",system:"system"},ke={document_html:"document_html",mis_record:"mis_record",workflow:"workflow",file:"file",user_file:"user_file",link:"link"},ts={user_file:"user_file"},_n={active:"active",complete:"complete",paused:"paused"},yt={in_progress:"in_progress",to_do:"to_do",requires_attention:"requires_attention",waiting_on_human:"waiting_on_human",available:"available"},ye={[M.complete]:{label:"Complete",icon:"circle-check",color:"var(--color-semantic-success-600)"},[M.failed]:{label:"Failed",icon:"circle-x",color:"var(--color-semantic-destructive-600)"},[M.hitl]:{label:"Requires attention",icon:"triangle-alert",color:"var(--color-semantic-warning-600)"},[M["generating-a-response"]]:{label:"In progress",icon:"loader",color:"var(--color-brand-600)",spin:!0},[M.to_do]:{label:"To do",color:"var(--color-brand-600)"}},ns="var(--color-grey-600)",it={[y["generating-a-response"]]:{status:y["generating-a-response"],title:"Active",dotColour:"green",statusIcon:{name:"sparkles",color:ye["generating-a-response"].color}},[y.hitl]:{status:y.hitl,title:"Requires attention",dotColour:"orange",statusIcon:{name:ye.hitl.icon,color:ye.hitl.color}},[y.paused]:{status:y.paused,title:"Paused",dotColour:"green",statusIcon:{name:"circle-x",color:ns}},[y.complete]:{status:y.complete,title:"Complete",dotColour:"green",dotModifier:"grey-dark",statusIcon:{name:ye.complete.icon,color:ye.complete.color}}},Qs={name:"archive",color:ns},Hn=[y["generating-a-response"],y.hitl,y.complete],ea="m4",ta="1",ss="msg-opening",Qt="Unable to load agent tasks. Please try again.",na="Unable to load context.",sa="Unable to load the resources for this agent",aa="Unable to load this document. Please try again.",as="Unable to load the timeline for this agent",ra="Unable to pause the agent. Please try again.",Nn="Unable to archive the agent. Please try again.",ia="Archive this agent?",la="Archiving files this agent away and stops its work. You can restore it later as paused; it will not run until you resume it. Chat is not available while it is archived. You can still open it from Archived to view the timeline and resources.",oa="This agent is still in progress.",kn="Unable to unarchive the agent. Please try again.",ca="Restore this agent?",ua="Restoring returns this agent to the board as paused. It will not run chats or scheduled work until you resume it.",da="Unable to delete the agent. Please try again.",ha="You do not have permission to delete this agent.",ga="This agent must be paused or archived before it can be deleted.",ma="This agent could not be found. It may have already been deleted.",pa="Delete this agent?",_a="Deleting cannot be undone. This permanently removes the agent and its related data. It will not appear in Archived and cannot be restored.",fa="Unable to resume the agent. Please try again.",va="The agent was resumed but could not be woken. Send a message to continue.",$n="You have been resumed after being paused. Reassess your current progress and continue your work from where you left off.",xa="Unable to rename the agent. Please try again.",wa="Something went wrong. Please try again.",rs="Unable to load agents. Please try again.",Aa="Agent not found",Na="Agent not found",rt="Loading tasks…",ka="Task",ya={[F.briefing]:"Briefing",[F.running]:"Working",[F.paused]:"Paused",[F.complete]:"Complete"},is="all",ba=[y["generating-a-response"],y.hitl,y.complete],Ca={[y["generating-a-response"]]:"Agents currently working on tasks for you.",[y.hitl]:"Agents that need your input before they can continue.",[y.paused]:"Agents that are paused until you resume them.",[y.complete]:"Agents that have finished their work."},Ea=()=>n.jsxs("svg",{className:"agent-view__empty-illustration",viewBox:"0 0 360 240",xmlns:"http://www.w3.org/2000/svg",role:"img","aria-label":"Preview of the agents board layout",children:[n.jsx("rect",{x:"0",y:"0",width:"360",height:"240",rx:"12",fill:"var(--color-grey-100)"}),n.jsx("rect",{x:"16",y:"16",width:"100",height:"208",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"130",y:"16",width:"100",height:"208",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"244",y:"16",width:"100",height:"208",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"28",y:"52",width:"76",height:"36",rx:"6",fill:"var(--color-grey-050)"}),n.jsx("rect",{x:"28",y:"96",width:"76",height:"36",rx:"6",fill:"var(--color-grey-050)"}),n.jsx("rect",{x:"142",y:"52",width:"76",height:"36",rx:"6",fill:"var(--color-semantic-warning-050)"}),n.jsx("rect",{x:"256",y:"52",width:"76",height:"36",rx:"6",fill:"var(--color-grey-050)"}),n.jsx("circle",{cx:"40",cy:"70",r:"4",fill:"var(--color-brand-600)"}),n.jsx("circle",{cx:"40",cy:"114",r:"4",fill:"var(--color-brand-600)"}),n.jsx("circle",{cx:"154",cy:"70",r:"4",fill:"var(--color-semantic-warning-600)"}),n.jsx("circle",{cx:"256",cy:"70",r:"4",fill:"var(--color-grey-400)"})]}),Sa=({status:e})=>{const t=it[e];return t.statusIcon?n.jsx(c.Icon,{name:t.statusIcon.name,size:16,color:t.statusIcon.color,screenReaderText:t.title}):n.jsx(c.Dot,{colour:t.dotColour,label:t.title})},ja=()=>n.jsxs("section",{className:"agent-view__empty","aria-label":"About the agents board",children:[n.jsxs("div",{className:"agent-view__empty-content",children:[n.jsx(c.Heading,{level:4,children:"Your agents board"}),n.jsx("p",{className:"agent-view__empty-lead",children:"When you start an agent, it appears here so you can track progress at a glance. Agents move between columns as their status changes."}),n.jsx("ul",{className:"agent-view__empty-columns",children:ba.map(e=>{const t=it[e];return n.jsxs("li",{className:"agent-view__empty-column",children:[n.jsx("span",{className:"agent-view__empty-column-indicator",children:n.jsx(Sa,{status:e})}),n.jsxs("span",{className:"agent-view__empty-column-text",children:[n.jsx("span",{className:"agent-view__empty-column-title",children:t.title}),n.jsx("span",{className:"agent-view__empty-column-description",children:Ca[e]})]})]},e)})}),n.jsxs("p",{className:"agent-view__empty-hint",children:["Use ",n.jsx("strong",{children:"Start an agent"})," above to begin."]})]}),n.jsx("div",{className:"agent-view__empty-visual",children:n.jsx(Ea,{})})]}),Ra=()=>({inProgress:[],needsInput:[],complete:[],failed:[],tasks:[]}),Ta=(e,t)=>({...e,children:t.length>0?t:void 0}),ls=e=>{const t=[],s=[],r=[],i=[],h=[];for(const l of e){const m=l.children?ls(l.children):Ra();if(t.push(...m.inProgress),s.push(...m.needsInput),r.push(...m.complete),i.push(...m.failed),l.status===M.hitl){s.push({...l,children:void 0});continue}if(l.status===M.complete){r.push({...l,children:void 0});continue}if(l.status===M.failed){i.push({...l,children:void 0});continue}if(l.status===M["generating-a-response"]){t.push({...l,children:void 0}),h.push(...m.tasks);continue}h.push(Ta(l,m.tasks))}return{inProgress:t,needsInput:s,complete:r,failed:i,tasks:h}},Bn=e=>e===M.hitl?0:e===M.complete?1:e===M.failed?2:3,Ia=e=>e.map((t,s)=>({item:t,index:s})).sort((t,s)=>{const r=Bn(t.item.status)-Bn(s.item.status);return r!==0?r:t.index-s.index}).map(({item:t})=>t),os=({status:e,className:t})=>{const s=ye[e];return e===M.to_do||!s.icon?n.jsxs(n.Fragment,{children:[n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:s.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:J("ds-icon","ds-icon-circle",t),role:"img","aria-hidden":!0,children:n.jsx("circle",{cx:12,cy:12,r:10})}),n.jsx("span",{className:"sr-only",children:`${s.label}:`})]}):n.jsx(c.Icon,{name:s.icon,size:16,color:s.color,className:t,screenReaderText:`${s.label}:`})},fn=2,Oa=e=>{if(!e)return{canScrollUp:!1,canScrollDown:!1};const t=e.scrollHeight-e.clientHeight;return t<=fn?{canScrollUp:!1,canScrollDown:!1}:{canScrollUp:e.scrollTop>fn,canScrollDown:e.scrollTop<t-fn}},La=(e,t)=>{if(!e||!t)return null;const s=e.getBoundingClientRect(),r=t.getBoundingClientRect();return{top:r.top-s.top,left:r.left-s.left,width:r.width,height:r.height}},nn=({children:e,className:t,contentClassName:s,scrollSelector:r,style:i,"aria-label":h})=>{const l=a.useRef(null),m=a.useRef(null),[u,w]=a.useState(!1),[_,N]=a.useState(!1),[o,x]=a.useState(null),S=()=>{var R;return r?((R=l.current)==null?void 0:R.querySelector(r))??null:m.current},E=()=>{const R=S(),A=Oa(R);if(w(p=>p===A.canScrollUp?p:A.canScrollUp),N(p=>p===A.canScrollDown?p:A.canScrollDown),r){const p=La(l.current,R);x(f=>(f==null?void 0:f.top)===(p==null?void 0:p.top)&&(f==null?void 0:f.left)===(p==null?void 0:p.left)&&(f==null?void 0:f.width)===(p==null?void 0:p.width)&&(f==null?void 0:f.height)===(p==null?void 0:p.height)?f:p)}else x(p=>p===null?p:null)};a.useLayoutEffect(()=>{E()}),a.useEffect(()=>{const R=l.current;if(!R)return;let A=null,p=null;const f=()=>{A==null||A.removeEventListener("scroll",E),p==null||p.disconnect(),p=null,A=null},T=W=>{if(W===A){E();return}if(f(),A=W,!A){E();return}A.addEventListener("scroll",E,{passive:!0}),p=new ResizeObserver(()=>E()),p.observe(A),A.firstElementChild instanceof HTMLElement&&p.observe(A.firstElementChild),E()};T(S());const H=new MutationObserver(()=>{T(S())});return H.observe(R,{childList:!0,subtree:!0,characterData:!0}),window.addEventListener("resize",E),()=>{window.removeEventListener("resize",E),H.disconnect(),f()}},[r]);const O=R=>{const A=S();if(!A)return;const p=Math.max(A.clientHeight*.75,120);A.scrollBy({top:R==="up"?-p:p,behavior:"smooth"})},L=n.jsxs(n.Fragment,{children:[u&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"scrollable-region__fade scrollable-region__fade--top","aria-hidden":"true"}),n.jsx("button",{type:"button",className:"scrollable-region__edge scrollable-region__edge--top","aria-label":"Scroll up",onClick:()=>O("up"),children:n.jsx(c.Icon,{name:"chevron-up",size:16,color:"currentColor"})})]}),_&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"scrollable-region__fade scrollable-region__fade--bottom","aria-hidden":"true"}),n.jsx("button",{type:"button",className:"scrollable-region__edge scrollable-region__edge--bottom","aria-label":"Scroll down",onClick:()=>O("down"),children:n.jsx(c.Icon,{name:"chevron-down",size:16,color:"currentColor"})})]})]});return n.jsx("div",{ref:l,className:J("scrollable-region",t),style:i,"aria-label":h,children:r?n.jsxs(n.Fragment,{children:[e,o&&(u||_)&&n.jsx("div",{className:"scrollable-region__overlay",style:{top:o.top,left:o.left,width:o.width,height:o.height},children:L})]}):n.jsxs(n.Fragment,{children:[L,n.jsx("div",{ref:m,className:J("scrollable-region__viewport",s),children:e})]})})},Pa=48,Ma=({checklist:e})=>{const t=a.useRef(null),s=a.useRef(!1);return a.useLayoutEffect(()=>{const r=t.current;if(!r)return;const i=r.scrollHeight-r.scrollTop-r.clientHeight;(!s.current||i<=Pa)&&(r.scrollTop=r.scrollHeight,s.current=!0)},[e]),e.length===0?n.jsx("p",{className:"agent-view__progress-empty",children:"No tasks to display."}):n.jsx(nn,{className:"agent-view__progress-scroll",scrollSelector:".agent-view__progress-list",children:n.jsx("ul",{ref:t,className:"agent-view__progress-list","aria-label":"Agent tasks",children:Ia(e).map(r=>{const i=ye[r.status];return n.jsxs("li",{className:J("agent-view__progress-item",`agent-view__progress-item--${r.status.replace(/_/g,"-")}`),children:[n.jsx(os,{status:r.status,className:i.spin?"agent-view__progress-icon--spinning":void 0}),n.jsxs("div",{className:"agent-view__progress-item-content",children:[n.jsx("span",{className:"agent-view__progress-label",children:r.task}),r.status!==M.complete&&n.jsx("span",{className:"agent-view__progress-description",children:r.description})]})]},r.task)})})})},cs=({open:e,isInProgress:t,isArchiving:s,error:r,onCancel:i,onConfirm:h})=>{const l=a.useId(),m=a.useId();return n.jsxs(c.Modal,{open:e,closeHandler:i,className:"archive-agent-confirm",children:[n.jsx(c.Modal.Header,{className:"archive-agent-confirm__header",children:n.jsx(c.Modal.Title,{id:l,children:ia})}),n.jsxs(c.Modal.Body,{className:"archive-agent-confirm__body",children:[n.jsxs("div",{role:"alertdialog","aria-labelledby":l,"aria-describedby":m,children:[n.jsx("p",{id:m,className:"archive-agent-confirm__lead",children:la}),t?n.jsx("p",{className:"archive-agent-confirm__progress",children:oa}):null,r?n.jsx("p",{className:"archive-agent-confirm__error",role:"alert",children:r}):null]}),n.jsxs("div",{className:"archive-agent-confirm__actions",children:[n.jsx(c.Button,{variant:"secondary",size:"S",disabled:s,onClick:i,children:"Cancel"}),n.jsx(c.Button,{variant:"secondary-destructive",size:"S",disabled:s,onClick:h,children:s?"Archiving…":"Archive"})]})]})]})},us=({open:e,isDeleting:t,error:s,onCancel:r,onConfirm:i})=>{const h=a.useId(),l=a.useId();return n.jsxs(c.Modal,{open:e,closeHandler:r,className:"archive-agent-confirm",children:[n.jsx(c.Modal.Header,{className:"archive-agent-confirm__header",children:n.jsx(c.Modal.Title,{id:h,children:pa})}),n.jsxs(c.Modal.Body,{className:"archive-agent-confirm__body",children:[n.jsxs("div",{role:"alertdialog","aria-labelledby":h,"aria-describedby":l,children:[n.jsx("p",{id:l,className:"archive-agent-confirm__lead",children:_a}),s?n.jsx("p",{className:"archive-agent-confirm__error",role:"alert",children:s}):null]}),n.jsxs("div",{className:"archive-agent-confirm__actions",children:[n.jsx(c.Button,{variant:"secondary",size:"S",disabled:t,onClick:r,children:"Cancel"}),n.jsx(c.Button,{variant:"secondary-destructive",size:"S",disabled:t,onClick:i,children:t?"Deleting…":"Delete"})]})]})]})},ds=({open:e,isUnarchiving:t,error:s,onCancel:r,onConfirm:i})=>{const h=a.useId(),l=a.useId();return n.jsxs(c.Modal,{open:e,closeHandler:r,className:"archive-agent-confirm",children:[n.jsx(c.Modal.Header,{className:"archive-agent-confirm__header",children:n.jsx(c.Modal.Title,{id:h,children:ca})}),n.jsxs(c.Modal.Body,{className:"archive-agent-confirm__body",children:[n.jsxs("div",{role:"alertdialog","aria-labelledby":h,"aria-describedby":l,children:[n.jsx("p",{id:l,className:"archive-agent-confirm__lead",children:ua}),s?n.jsx("p",{className:"archive-agent-confirm__error",role:"alert",children:s}):null]}),n.jsxs("div",{className:"archive-agent-confirm__actions",children:[n.jsx(c.Button,{variant:"secondary",size:"S",disabled:t,onClick:r,children:"Cancel"}),n.jsx(c.Button,{variant:"secondary",size:"S",disabled:t,onClick:i,children:t?"Restoring…":"Restore"})]})]})]})},Ua=e=>e!==void 0&&e.some(t=>t.status===M.hitl),hs=e=>e!==void 0&&e.length>0&&e.every(t=>t.status===M.complete),vn=(e,t)=>e.status===y.paused?hs(t)?y.complete:y["generating-a-response"]:Ua(t)?y.hitl:e.status===y.complete?y.complete:e.status===y.hitl?y.hitl:y["generating-a-response"];class Da{constructor(t,s){this.connector=t,this.canSend=s.canSend,this.onTurn=s.onTurn,this.onAwaitingChange=s.onAwaitingChange}get canRate(){return!1}get canLoadHistory(){return!1}get canListInteractions(){return!1}get canSendNotification(){return!1}get ratingPopupUrls(){return{}}async sendMessage(t){var s,r;if(!this.canSend())return null;(s=this.onAwaitingChange)==null||s.call(this,!0);try{const i=await this.connector.sendMessage(t.userMessage,t.uploadFiles,...t.onThinking?[{onThinking:t.onThinking}]:[]);return this.onTurn(i),{id:i.message.id,text:i.message.text,type:Ge.CHAT_RESPONSE_TYPE_AGENT,...i.message.followUpPrompts?{followUpPrompts:i.message.followUpPrompts}:{}}}catch{return{id:`error-${Date.now()}`,text:wa,type:Ge.CHAT_RESPONSE_TYPE_ERROR}}finally{(r=this.onAwaitingChange)==null||r.call(this,!1)}}async loadHistory(t){return null}async listInteractions(){return null}async rateMessage(t){}async sendNotification(t){return!1}}const Ha=({connector:e,phase:t,chatHistory:s,chatSessionKey:r,readOnly:i=!1,enableUpload:h=!1,onTurn:l,onAwaitingChange:m})=>{const u=a.useMemo(()=>new Da(e,{canSend:()=>!i&&t===F.running,onTurn:l,onAwaitingChange:m}),[e,t,i,l,m]),w=i||t!==F.running,_=!i&&t===F.running;let N="The agent is not accepting messages.";return _&&(N="Message the agent, paste a link, or attach a file…"),i&&(N="You can view this conversation but cannot send messages."),n.jsxs("section",{className:"agent-workspace__chat-body","aria-label":"Chat",children:[n.jsx("div",{className:"agent-workspace__ask-arbor",children:n.jsx(nn,{scrollSelector:".chat-panel-message-list",children:n.jsx(Ge.ChatPanel,{connector:u,chatHistory:s,lockConversation:w,enableUpload:h,speechEnabled:_,speechLanguage:"en-GB",speechSubmissionDelay:1e3,slashMenuItems:[],menuContent:[],introHeading:"Message your agent",introBody:"Ask questions, share trip details, or paste a link. The agent will update the checklist as it works.",placeholder:N},r)})}),i&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(c.Icon,{name:"eye",size:16,color:"var(--color-grey-700)"}),n.jsx("span",{children:"View only — you cannot interact with this agent."})]}),t===F.paused&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(c.Icon,{name:"circle-alert",size:16,color:"var(--color-semantic-warning-600)"}),n.jsx("span",{children:"The agent is paused. Its progress is saved in the checklist."})]}),t===F.complete&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(c.Icon,{name:"party-popper",size:16,color:"var(--color-semantic-success-600)"}),n.jsx("span",{children:"The agent has finished."})]})]})},gs=({item:e,depth:t})=>{const s=ye[e.status],r=e.status.replace(/_/g,"-");return n.jsxs("li",{className:J("agent-workspace__task",`agent-workspace__task--${r}`,{"agent-workspace__task--child":t>0}),children:[n.jsxs("div",{className:"agent-workspace__task-row",children:[n.jsx(os,{status:e.status,className:s.spin?"agent-workspace__task-icon--spinning":void 0}),n.jsxs("div",{className:"agent-workspace__task-content",children:[n.jsx("span",{className:"agent-workspace__task-label",children:e.task}),e.status!==M.complete&&e.description&&n.jsx("span",{className:"agent-workspace__task-description",children:e.description})]})]}),e.children&&e.children.length>0&&n.jsx("ul",{className:"agent-workspace__task-children",children:e.children.map(i=>n.jsx(gs,{item:i,depth:t+1},i.task))})]})},bt=({items:e,ariaLabel:t})=>n.jsx("ul",{className:"agent-workspace__task-list","aria-label":t,children:e.map(s=>n.jsx(gs,{item:s,depth:0},s.task))}),$a=({checklist:e,isLoading:t,error:s,phase:r,adminMode:i=!1,context:h,contextLoaded:l=!1,contextLoading:m=!1,contextError:u=null,onContextSelect:w})=>{const[_,N]=a.useState("checklist"),o=a.useMemo(()=>e?ls(e):null,[e]),x=()=>{N("context"),w==null||w()};return n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--checklist","aria-label":"Checklist",children:[n.jsx("div",{className:"agent-workspace__panel-header",children:i?n.jsxs(c.Tabs,{className:"agent-workspace__checklist-tabs","aria-label":"Checklist panel",children:[n.jsx(c.Tabs.Item,{active:_==="checklist",tabElementProps:{id:"agent-checklist-tab-checklist",onClick:()=>N("checklist")},children:"Checklist"}),n.jsx(c.Tabs.Item,{active:_==="context",tabElementProps:{id:"agent-checklist-tab-context",onClick:x},children:"Context"})]}):n.jsx(c.Heading,{level:4,children:"Checklist"})}),n.jsx("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:n.jsx(nn,{children:_==="context"?n.jsxs(n.Fragment,{children:[m&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(c.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:"Loading context"}),n.jsx("span",{children:"Loading context…"})]}),!m&&u&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:u}),!m&&!u&&l&&h==null&&n.jsx("p",{className:"agent-workspace__empty",children:"No context available."}),!m&&!u&&l&&h!==null&&h!==void 0&&n.jsx("pre",{className:"agent-workspace__context-json",children:JSON.stringify(h,null,2)})]}):n.jsxs(n.Fragment,{children:[t&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(c.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:rt}),n.jsx("span",{children:rt})]}),!t&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!t&&!s&&o&&n.jsxs(n.Fragment,{children:[o.inProgress.length>0&&n.jsxs("div",{className:"agent-workspace__task-group",children:[(o.needsInput.length>0||o.tasks.length>0||o.failed.length>0||o.complete.length>0)&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"In progress"}),n.jsx(bt,{items:o.inProgress,ariaLabel:"In progress"})]}),o.needsInput.length>0&&n.jsxs("div",{className:J("agent-workspace__task-group",{"agent-workspace__task-group--following":o.inProgress.length>0}),children:[n.jsx("p",{className:"agent-workspace__task-group-label",children:"Needs your input"}),n.jsx(bt,{items:o.needsInput,ariaLabel:"Tasks needing your input"})]}),o.failed.length>0&&n.jsxs("div",{className:J("agent-workspace__task-group",{"agent-workspace__task-group--following":o.inProgress.length>0||o.needsInput.length>0}),children:[(o.inProgress.length>0||o.needsInput.length>0||o.tasks.length>0||o.complete.length>0)&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"Failed"}),n.jsx(bt,{items:o.failed,ariaLabel:"Failed tasks"})]}),o.tasks.length>0&&n.jsxs("div",{className:J("agent-workspace__task-group",{"agent-workspace__task-group--following":o.inProgress.length>0||o.needsInput.length>0||o.failed.length>0}),children:[(o.inProgress.length>0||o.needsInput.length>0||o.failed.length>0||o.complete.length>0)&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"To Do"}),n.jsx(bt,{items:o.tasks,ariaLabel:"Upcoming tasks"})]}),o.complete.length>0&&n.jsxs("div",{className:J("agent-workspace__task-group",{"agent-workspace__task-group--following":o.inProgress.length>0||o.needsInput.length>0||o.tasks.length>0||o.failed.length>0}),children:[(o.inProgress.length>0||o.needsInput.length>0||o.tasks.length>0||o.failed.length>0)&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"Completed"}),n.jsx(bt,{items:o.complete,ariaLabel:"Completed tasks"})]})]}),!t&&!s&&(!o||o.inProgress.length===0&&o.needsInput.length===0&&o.complete.length===0&&o.failed.length===0&&o.tasks.length===0)&&n.jsx("p",{className:"agent-workspace__empty",children:r===F.briefing?"Tasks will appear here once the agent starts.":"No tasks to display."})]})})})]})},Ba=({resource:e,html:t,isLoading:s,error:r,onClose:i})=>{a.useEffect(()=>{if(!e)return;const l=c.SlideoverUtils.removeSlideover;return c.SlideoverUtils.removeSlideover=()=>{l(),i()},()=>{c.SlideoverUtils.removeSlideover=l}},[e,i]),a.useEffect(()=>{if(!e)return;const l=m=>{m.key==="Escape"&&c.SlideoverUtils.removeSlideover()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e]);const h=a.useMemo(()=>e?[{centerHeaderText:!1,children:n.jsxs("div",{className:"resource-preview-slideover__body",children:[s&&n.jsxs("div",{className:"resource-preview-slideover__status",children:[n.jsx(c.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:"Loading document"}),n.jsx("span",{children:"Loading document…"})]}),!s&&r&&n.jsx("p",{className:"resource-preview-slideover__error",role:"alert",children:r}),!s&&!r&&t!==null&&n.jsx("iframe",{className:"resource-preview-slideover__frame",title:e.title,sandbox:"",srcDoc:t})]})}]:[],[e,t,s,r]);return n.jsx("div",{className:"resource-preview-slideover",children:n.jsx(c.SlideoverManager,{slideovers:h})})},Fa={[ke.mis_record]:{icon:"table",label:"Arbor MIS",color:"var(--color-brand-600)"},[ke.document_html]:{icon:"file",label:"Document",color:"var(--color-semantic-caution-800)"},[ke.file]:{icon:"file",label:"File",color:"var(--color-semantic-caution-800)"},[ke.user_file]:{icon:"upload",label:"File upload",color:"var(--color-semantic-caution-800)"},[ke.workflow]:{icon:"list-tree",label:"Workflow",color:"var(--color-semantic-warning-700)"},[ke.link]:{icon:"link",label:"Link",color:"var(--color-semantic-info-700)"}},Ga=({resources:e,isLoading:t=!1,error:s=null,onOpenResource:r})=>n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--documents","aria-label":"Resources",children:[n.jsxs("div",{className:"agent-workspace__panel-header",children:[n.jsx(c.Heading,{level:4,children:"Resources"}),n.jsx("span",{className:"agent-workspace__panel-count",children:e.length})]}),n.jsx("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:n.jsxs(nn,{children:[t&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(c.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:"Loading resources"}),n.jsx("span",{children:"Loading resources…"})]}),!t&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!t&&!s&&e.length>0&&n.jsx("ul",{className:"agent-workspace__resource-list","aria-label":"Agent resources",children:e.map(i=>{const h=Fa[i.type],l=i.misRecordUrl;return n.jsx("li",{className:"agent-workspace__resource",children:l?n.jsx("a",{className:"agent-workspace__resource-card",href:l,target:"_blank",rel:"noreferrer",onClick:m=>{m.preventDefault(),r(i)},children:n.jsx(Fn,{resource:i,config:h,external:!0})}):n.jsx("button",{type:"button",className:"agent-workspace__resource-card",onClick:()=>r(i),children:n.jsx(Fn,{resource:i,config:h})})},i.id)})}),!t&&!s&&e.length===0&&n.jsx("p",{className:"agent-workspace__empty",children:"No resources yet."})]})})]}),Fn=({resource:e,config:t,external:s=!1})=>n.jsxs(n.Fragment,{children:[n.jsx("span",{className:`agent-workspace__resource-icon agent-workspace__resource-icon--${e.type}`,children:n.jsx(c.Icon,{name:t.icon,size:16,color:t.color,screenReaderText:`${t.label}:`})}),n.jsx("span",{className:"agent-workspace__resource-content",children:n.jsxs("span",{className:"agent-workspace__resource-top",children:[n.jsx("span",{className:"agent-workspace__resource-name",children:e.title}),n.jsx("span",{className:`agent-workspace__resource-badge agent-workspace__resource-badge--${e.type}`,children:t.label})]})}),s&&n.jsx(c.Icon,{name:"external-link",size:12,color:"var(--color-grey-500)",screenReaderText:"Opens in a new tab",className:"agent-workspace__resource-open"})]}),xn=e=>{const t=Date.parse(e);return Number.isFinite(t)?t:0},za=new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"2-digit"}),wn=e=>{const t=new Date(e);return Number.isFinite(t.getTime())?za.format(t):e},Gn=e=>e.replace(/[A-Za-z0-9]+(?:[_-][A-Za-z0-9]+)+/g,t=>t.split(/[_-]/).map(s=>s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()).join(" ")),zn=e=>{const s=e.replace(/[A-Za-z0-9]+(?:[_-][A-Za-z0-9]+)+/g,r=>r.split(/[_-]/).map(i=>i.toLowerCase()).join(" ")).toLowerCase();return s&&s.charAt(0).toUpperCase()+s.slice(1)},qa=60*60*1e3,ms=60*60*1e3,Ct=24*ms,yn=7*Ct,Va=e=>e.type!=="message-sent",Ka=e=>{if(e==null||e<=0)return null;if(e%86400===0){const s=e/86400;return s===1?"every day":`every ${s} days`}if(e%3600===0){const s=e/3600;return s===1?"every hour":`every ${s} hours`}if(e%60===0){const s=e/60;return s===1?"every minute":`every ${s} minutes`}const t=Math.max(1,Math.round(e/60));return t===1?"every minute":`every ${t} minutes`},Ya=e=>{if(e.recurrence==="one_off")return"Scheduled to run once";const t=Ka(e.repeatIntervalSeconds);return t?`Repeating ${t}`:"Repeating run scheduled"},Ja=e=>e.recurrence==="one_off"?"scheduled-one-off":"scheduled-repeating",Wa=(e,t,s=[])=>{const r=e.filter(Va).map((l,m)=>({kind:"action",id:`action-${l.timestamp}-${m}`,timestampMs:xn(l.timestamp),item:l})),i=t.map(l=>({kind:"chat",id:l.sessionId,timestampMs:xn(l.timestamp),session:l})),h=s.map(l=>({kind:"scheduled",id:`scheduled-${l.scheduleId}`,timestampMs:xn(l.dueAt),run:l}));return[...r,...i,...h].sort((l,m)=>l.timestampMs-m.timestampMs||l.id.localeCompare(m.id))},Xa=e=>e>=yn?"weeks":e>=Ct?"days":"hours",Za=e=>{if(e<Ct){const r=Math.max(1,Math.round(e/ms));return r===1?"1 hour later":`${r} hours later`}if(e<yn){const r=Math.max(1,Math.round(e/Ct));return r===1?"1 day later":`${r} days later`}const t=Math.max(1,Math.round(e/yn));if(t<5)return t===1?"1 week later":`${t} weeks later`;const s=Math.max(1,Math.round(e/(30*Ct)));return s===1?"1 month later":`${s} months later`},Qa=(e,t=qa)=>{if(e.length===0)return[];const s=[e[0]];for(let r=1;r<e.length;r+=1){const i=e[r-1],h=e[r],l=h.timestampMs-i.timestampMs;l>=t&&s.push({kind:"gap",id:`gap-${i.id}-${h.id}`,durationMs:l,label:Za(l),size:Xa(l)}),s.push(h)}return s},er=e=>e.type==="checklist-updated"?"checklist":e.type==="status-transition"?"status":"note",tr=({timeline:e,isLoading:t,error:s,onOpenChatSession:r})=>{const i=(e==null?void 0:e.actionLog)??[],h=(e==null?void 0:e.chatSessions)??[],l=(e==null?void 0:e.scheduledRuns)??[],m=Wa(i,h,l),u=Qa(m),w=!t&&!s&&m.length===0;return n.jsxs("section",{className:"agent-workspace__timeline","aria-label":"Agent timeline",children:[t&&n.jsx("p",{className:"agent-workspace__timeline-status",role:"status",children:"Loading timeline…"}),s&&n.jsx("p",{className:"agent-workspace__timeline-status",role:"alert",children:s||as}),w&&n.jsx("p",{className:"agent-workspace__timeline-status",role:"status",children:"No timeline activity yet."}),!t&&!s&&!w&&n.jsxs("div",{className:"agent-timeline",children:[n.jsx("div",{className:"agent-timeline__track","aria-hidden":"true"}),n.jsxs("div",{className:"agent-timeline__station agent-timeline__station--terminus",children:[n.jsx("span",{className:"agent-timeline__station-rail",children:n.jsx("span",{className:"agent-timeline__station-node agent-timeline__station-node--terminus","aria-hidden":"true",children:n.jsx(c.Icon,{name:"arrow-right-from-line",size:16,color:"currentColor"})})}),n.jsx("div",{className:"agent-timeline__label",children:n.jsx("strong",{className:"agent-timeline__label-type",children:"Start"})})]}),u.map(_=>{if(_.kind==="gap")return n.jsxs("div",{className:`agent-timeline__gap agent-timeline__gap--${_.size}`,role:"separator","aria-label":_.label,children:[n.jsx("span",{className:"agent-timeline__gap-rail","aria-hidden":"true",children:n.jsx("span",{className:"agent-timeline__gap-dot"})}),n.jsx("span",{className:"agent-timeline__gap-label",children:_.label})]},_.id);if(_.kind==="chat"){const E=wn(_.session.timestamp),O=n.jsx(c.Icon,{name:"sparkles",size:16,color:"currentColor"});return n.jsxs("div",{className:"agent-timeline__chat-station",children:[r?n.jsx("button",{type:"button",className:"agent-timeline__chat-node","aria-label":`Open chat session from ${E}`,onClick:()=>r(_.session.sessionId),children:O}):n.jsx("span",{className:"agent-timeline__chat-node agent-timeline__chat-node--static","aria-hidden":"true",children:O}),n.jsxs("div",{className:"agent-timeline__label",children:[n.jsx("strong",{className:"agent-timeline__label-type",children:"Chat session"}),n.jsx("span",{className:"agent-timeline__label-time",children:E})]})]},_.id)}if(_.kind==="scheduled"){const E=Ja(_.run),O=_.run.recurrence==="one_off"?"One-off run":"Repeating run";return n.jsxs("div",{className:`agent-timeline__station agent-timeline__station--${E}`,children:[n.jsx("span",{className:"agent-timeline__station-rail",children:n.jsx("span",{className:`agent-timeline__station-node agent-timeline__station-node--${E}`,"aria-hidden":"true",children:n.jsx(c.Icon,{name:"date",size:16,color:"currentColor"})})}),n.jsxs("div",{className:"agent-timeline__label",children:[n.jsx("strong",{className:"agent-timeline__label-type",children:O}),n.jsx("span",{className:"agent-timeline__label-entry",children:Ya(_.run)}),n.jsx("span",{className:"agent-timeline__label-time",children:wn(_.run.dueAt)})]})]},_.id)}const{item:N}=_,o=er(N),x=o==="checklist",S=o==="status";return n.jsxs("div",{className:`agent-timeline__station agent-timeline__station--${o}`,children:[n.jsx("span",{className:"agent-timeline__station-rail",children:n.jsxs("button",{type:"button",className:`agent-timeline__station-node agent-timeline__station-node--${o}`,"aria-label":`${Gn(N.type)}: ${zn(N.entry)}`,children:[x&&n.jsx(c.Icon,{name:"check-solid",size:16,color:"currentColor"}),S&&n.jsx(c.Icon,{name:"iteration-ccw",size:16,color:"currentColor"})]})}),n.jsxs("div",{className:"agent-timeline__label",children:[n.jsx("strong",{className:"agent-timeline__label-type",children:Gn(N.type)}),n.jsx("span",{className:"agent-timeline__label-entry",children:zn(N.entry)}),n.jsx("span",{className:"agent-timeline__label-time",children:wn(N.timestamp)})]})]},_.id)}),n.jsxs("div",{className:"agent-timeline__station agent-timeline__station--terminus",children:[n.jsx("span",{className:"agent-timeline__station-rail",children:n.jsx("span",{className:"agent-timeline__station-node agent-timeline__station-node--terminus","aria-hidden":"true",children:n.jsx(c.Icon,{name:"flag",size:16,color:"currentColor"})})}),n.jsx("div",{className:"agent-timeline__label",children:n.jsx("strong",{className:"agent-timeline__label-type",children:"Finish"})})]})]})]})},nr=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),sr=e=>e.kind===ts.user_file?`<strong>${nr(e.text)}</strong>`:e.text,Ne=e=>({id:e.id,text:sr(e),type:e.author===ue.user?Ge.CHAT_RESPONSE_TYPE_USER:e.author===ue.system?Ge.CHAT_RESPONSE_TYPE_INFO:Ge.CHAT_RESPONSE_TYPE_AGENT,...e.followUpPrompts?{followUpPrompts:e.followUpPrompts}:{}}),bn="MESSAGE_TYPE_REPOLL",ps="agentUi:update",Sn="arbor-agent-",be={all:"ALL",checklist:"CHECKLIST",resources:"RESOURCES",chat:"CHAT",timeline:"TIMELINE"},ar=new Set(Object.values(be)),_s=(e,t)=>`${e.endsWith("-")?e:`${e}-`}${t}`,rr=e=>typeof e=="string"&&ar.has(e)?e:be.all,ir=e=>{if(!e||typeof e!="object")return null;const t=e;return t.type!==bn?null:{type:bn,target:rr(t.target)}},fs=e=>{const t=Array.isArray(e)?e:[e],s=[];for(const r of t){const i=ir(r);i&&s.push(i)}return s},lr=({enabled:e,channelPrefix:t,agentId:s,subscribeToPusher:r,onRepoll:i})=>{const h=a.useRef(i),l=t==null?void 0:t.trim(),m=!!(e&&r&&l&&(s!=null&&s.trim()));return a.useEffect(()=>{h.current=i},[i]),a.useEffect(()=>{if(!m||!r||!l)return;const u=r(_s(l,s),ps,w=>{for(const _ of fs(w))h.current(_.target)});return()=>{u()}},[m,l,s,r]),m};let ce=null,Cn="",En="",tn=0;const or=()=>{window.setTimeout(()=>{tn>0||!ce||(ce.disconnect(),ce=null,Cn="",En="")},0)},cr=(e,t)=>(ce&&(Cn!==e||En!==t)&&(ce.disconnect(),ce=null),ce||(ce=new Zs(e,{cluster:t}),Cn=e,En=t),tn+=1,ce),ur=()=>{tn=Math.max(0,tn-1),or()},vs=({enabled:e,key:t,cluster:s,isAdmin:r=!1})=>{const i=a.useRef(null),h=t.trim(),l=s.trim(),m=e&&!!h&&!!l;return a.useEffect(()=>{if(!m){i.current=null;return}const u=cr(h,l);return i.current=u,()=>{i.current=null,ur()}},[m,h,l]),a.useMemo(()=>{if(m)return(u,w,_)=>{const N=i.current??ce;if(!N)return r&&console.log(`[pusher] subscribe skipped — client not ready for "${u}"`),()=>{};const o=N.subscribe(u);return o.bind(w,_),()=>{o.unbind(w,_),N.unsubscribe(u)}}},[m,r])};class Fe extends Error{constructor(t,s,r){super(r??`Agent service request failed (${t})`),this.name="AgentServiceError",this.status=t,this.detail=s}}const dr="/api/v1",B={agentDefinitions:"/agent-definitions",agents:"/agents",conversations:"/conversations",tripOptions:"/trip-options",demoDataset:"/demo/dataset"},q={GET:"GET",POST:"POST",PATCH:"PATCH",DELETE:"DELETE"},hr={error:"error"},gr={user:"user"},Be={acceptJson:"application/json",acceptHtml:"text/html",acceptEventStream:"text/event-stream",contentTypeJson:"application/json",arborApplicationUrl:"X-Arbor-Application-Url"},mr=100,xs=e=>{switch(e){case _n.paused:return y.paused;case _n.complete:return y.complete;case y.hitl:return y.hitl;case _n.active:case y["generating-a-response"]:return y["generating-a-response"];default:return y["generating-a-response"]}},ws=e=>{switch(e){case yt.requires_attention:case yt.waiting_on_human:case M.hitl:return M.hitl;case yt.in_progress:case M["generating-a-response"]:return M["generating-a-response"];case yt.to_do:case yt.available:case M.to_do:return M.to_do;case M.failed:case M.complete:return e;default:return M.to_do}},jn=e=>({ref:e.name,display_name:e.display_name,agent_intent:e.agent_intent??"",description:e.description}),pr=e=>({id:e.id,name:e.name,...e.has_run_before?{hasRunBefore:e.has_run_before}:{}}),_r=new Set(Object.values(ke)),fr=e=>_r.has(e)?e:ke.document_html,As=e=>({id:e.id,type:fr(e.type),title:e.title,createdDatetime:e.created_datetime,lastUpdatedDatetime:e.last_updated_datetime,misRecordUrl:e.mis_record_url}),Ns=e=>({resources:e.resources.map(As),pageNumber:e.page_number,pageSize:e.page_size,totalRecords:e.total_records}),ks=e=>({actionLog:(e.action_log??[]).map(t=>({timestamp:t.timestamp,type:t.type,entry:t.entry,origin:t.origin})),chatSessions:(e.chat_sessions??[]).map(t=>({sessionId:t.session_id,timestamp:t.timestamp})),scheduledRuns:(e.scheduled_runs??[]).map(t=>({scheduleId:t.schedule_id,dueAt:t.due_at,recurrence:t.recurrence,repeatIntervalSeconds:t.repeat_interval_seconds,wakePrompt:t.wake_prompt}))}),Ce=e=>{var s;const t=e.invocation_id??e.id;return{id:e.id,invocation_id:t,agent_definition_ref:e.agent_definition_ref,...e.agent_intent?{agent_intent:e.agent_intent}:{},invocation_name:((s=e.invocation_name)==null?void 0:s.trim())||e.agent_definition_ref,application_id:e.application_id,...e.application_name?{application_name:e.application_name}:{},created_by:e.created_by,usable:e.usable??!1,status:xs(e.status),archivedAt:e.archived_at??null,context_ref:e.context_ref??null,checklist_ref:e.checklist_ref??null}},Rn=e=>({task:e.item??e.task??e.name??e.label??ka,status:ws(e.status),description:e.description??""}),vr=e=>Array.isArray(e)?e:e.checklist_items??e.checklist??e.items??[],sn=(e,t,s)=>{var h;const r=!Array.isArray(t)&&(t.opening_message||(h=t.opening_follow_up_prompts)!=null&&h.length)?t:s,i=r?Et(r):void 0;return{invocation_id:e,checklist:vr(t).map(Rn),...i?{openingMessage:i}:{}}},xr=(e,t)=>{const s=Et(t);return{invocation_id:t.invocation_id??e,checklist:(t.checklist_items??[]).map(Rn),...s?{openingMessage:s}:{}}},Et=e=>{var s,r;const t=(s=e.opening_message)==null?void 0:s.trim();if(t)return{id:ss,author:ue.agent,text:t,...(r=e.opening_follow_up_prompts)!=null&&r.length?{followUpPrompts:e.opening_follow_up_prompts}:{}}},wr=e=>{try{const t=JSON.parse(e);if(Array.isArray(t)){const s=t.filter(r=>!!r&&typeof r=="object"&&typeof r.text=="string").map(r=>r.text);if(s.length>0)return s.join(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),a=require("react"),K=require("classnames"),c=require("@arbor-education/design-system.components"),Ce=require("@arbor-education/ask-arbor-chat-panel"),Zs=require("pusher-js"),k={"generating-a-response":"generating-a-response",hitl:"hitl",paused:"paused",complete:"complete"},U={"generating-a-response":"generating-a-response",to_do:"to_do",hitl:"hitl",complete:"complete",failed:"failed"},B={briefing:"briefing",running:"running",paused:"paused",complete:"complete"},ge={agent:"agent",user:"user",system:"system"},Ne={document_html:"document_html",mis_record:"mis_record",workflow:"workflow",file:"file",user_file:"user_file",link:"link"},ts={user_file:"user_file"},_n={active:"active",complete:"complete",paused:"paused"},Rt={in_progress:"in_progress",to_do:"to_do",requires_attention:"requires_attention",waiting_on_human:"waiting_on_human",available:"available"},ye={[U.complete]:{label:"Complete",icon:"circle-check",color:"var(--color-semantic-success-600)"},[U.failed]:{label:"Failed",icon:"circle-x",color:"var(--color-semantic-destructive-600)"},[U.hitl]:{label:"Requires attention",icon:"triangle-alert",color:"var(--color-semantic-warning-600)"},[U["generating-a-response"]]:{label:"In progress",icon:"loader",color:"var(--color-brand-600)",spin:!0},[U.to_do]:{label:"To do",color:"var(--color-brand-600)"}},ns="var(--color-grey-600)",it={[k["generating-a-response"]]:{status:k["generating-a-response"],title:"Active",dotColour:"green",statusIcon:{name:"sparkles",color:ye["generating-a-response"].color}},[k.hitl]:{status:k.hitl,title:"Requires attention",dotColour:"orange",statusIcon:{name:ye.hitl.icon,color:ye.hitl.color}},[k.paused]:{status:k.paused,title:"Paused",dotColour:"green",statusIcon:{name:"circle-x",color:ns}},[k.complete]:{status:k.complete,title:"Complete",dotColour:"green",dotModifier:"grey-dark",statusIcon:{name:ye.complete.icon,color:ye.complete.color}}},Qs={name:"archive",color:ns},Hn=[k["generating-a-response"],k.hitl,k.complete],ea="m4",ta="1",ss="msg-opening",Xt="Unable to load agent tasks. Please try again.",na="Unable to load context.",sa="Unable to load the resources for this agent",aa="Unable to load this document. Please try again.",as="Unable to load the timeline for this agent",ra="Unable to pause the agent. Please try again.",Nn="Unable to archive the agent. Please try again.",ia="Archive this agent?",la="Archiving files this agent away and stops its work. You can restore it later as paused; it will not run until you resume it. Chat is not available while it is archived. You can still open it from Archived to view the timeline and resources.",oa="This agent is still in progress.",yn="Unable to unarchive the agent. Please try again.",ca="Restore this agent?",da="Restoring returns this agent to the board as paused. It will not run chats or scheduled work until you resume it.",ua="Unable to delete the agent. Please try again.",ha="You do not have permission to delete this agent.",ga="This agent must be paused or archived before it can be deleted.",ma="This agent could not be found. It may have already been deleted.",pa="Delete this agent?",_a="Deleting cannot be undone. This permanently removes the agent and its related data. It will not appear in Archived and cannot be restored.",fa="Unable to resume the agent. Please try again.",va="The agent was resumed but could not be woken. Send a message to continue.",$n="You have been resumed after being paused. Reassess your current progress and continue your work from where you left off.",xa="Unable to rename the agent. Please try again.",wa="Something went wrong. Please try again.",Aa="Unable to send the message. Please try again.",rs="Unable to load agents. Please try again.",Na="Agent not found",ya="Agent not found",rt="Loading tasks…",ka="Task",ba={[B.briefing]:"Briefing",[B.running]:"Working",[B.paused]:"Paused",[B.complete]:"Complete"},is="all",Ca=[k["generating-a-response"],k.hitl,k.complete],Ea={[k["generating-a-response"]]:"Agents currently working on tasks for you.",[k.hitl]:"Agents that need your input before they can continue.",[k.paused]:"Agents that are paused until you resume them.",[k.complete]:"Agents that have finished their work."},Sa=()=>n.jsxs("svg",{className:"agent-view__empty-illustration",viewBox:"0 0 360 240",xmlns:"http://www.w3.org/2000/svg",role:"img","aria-label":"Preview of the agents board layout",children:[n.jsx("rect",{x:"0",y:"0",width:"360",height:"240",rx:"12",fill:"var(--color-grey-100)"}),n.jsx("rect",{x:"16",y:"16",width:"100",height:"208",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"130",y:"16",width:"100",height:"208",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"244",y:"16",width:"100",height:"208",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"28",y:"52",width:"76",height:"36",rx:"6",fill:"var(--color-grey-050)"}),n.jsx("rect",{x:"28",y:"96",width:"76",height:"36",rx:"6",fill:"var(--color-grey-050)"}),n.jsx("rect",{x:"142",y:"52",width:"76",height:"36",rx:"6",fill:"var(--color-semantic-warning-050)"}),n.jsx("rect",{x:"256",y:"52",width:"76",height:"36",rx:"6",fill:"var(--color-grey-050)"}),n.jsx("circle",{cx:"40",cy:"70",r:"4",fill:"var(--color-brand-600)"}),n.jsx("circle",{cx:"40",cy:"114",r:"4",fill:"var(--color-brand-600)"}),n.jsx("circle",{cx:"154",cy:"70",r:"4",fill:"var(--color-semantic-warning-600)"}),n.jsx("circle",{cx:"256",cy:"70",r:"4",fill:"var(--color-grey-400)"})]}),ja=({status:e})=>{const t=it[e];return t.statusIcon?n.jsx(c.Icon,{name:t.statusIcon.name,size:16,color:t.statusIcon.color,screenReaderText:t.title}):n.jsx(c.Dot,{colour:t.dotColour,label:t.title})},Ra=()=>n.jsxs("section",{className:"agent-view__empty","aria-label":"About the agents board",children:[n.jsxs("div",{className:"agent-view__empty-content",children:[n.jsx(c.Heading,{level:4,children:"Your agents board"}),n.jsx("p",{className:"agent-view__empty-lead",children:"When you start an agent, it appears here so you can track progress at a glance. Agents move between columns as their status changes."}),n.jsx("ul",{className:"agent-view__empty-columns",children:Ca.map(e=>{const t=it[e];return n.jsxs("li",{className:"agent-view__empty-column",children:[n.jsx("span",{className:"agent-view__empty-column-indicator",children:n.jsx(ja,{status:e})}),n.jsxs("span",{className:"agent-view__empty-column-text",children:[n.jsx("span",{className:"agent-view__empty-column-title",children:t.title}),n.jsx("span",{className:"agent-view__empty-column-description",children:Ea[e]})]})]},e)})}),n.jsxs("p",{className:"agent-view__empty-hint",children:["Use ",n.jsx("strong",{children:"Start an agent"})," above to begin."]})]}),n.jsx("div",{className:"agent-view__empty-visual",children:n.jsx(Sa,{})})]}),Ta=()=>({inProgress:[],needsInput:[],complete:[],failed:[],tasks:[]}),Ia=(e,t)=>({...e,children:t.length>0?t:void 0}),ls=e=>{const t=[],s=[],r=[],i=[],h=[];for(const l of e){const m=l.children?ls(l.children):Ta();if(t.push(...m.inProgress),s.push(...m.needsInput),r.push(...m.complete),i.push(...m.failed),l.status===U.hitl){s.push({...l,children:void 0});continue}if(l.status===U.complete){r.push({...l,children:void 0});continue}if(l.status===U.failed){i.push({...l,children:void 0});continue}if(l.status===U["generating-a-response"]){t.push({...l,children:void 0}),h.push(...m.tasks);continue}h.push(Ia(l,m.tasks))}return{inProgress:t,needsInput:s,complete:r,failed:i,tasks:h}},Bn=e=>e===U.hitl?0:e===U.complete?1:e===U.failed?2:3,Oa=e=>e.map((t,s)=>({item:t,index:s})).sort((t,s)=>{const r=Bn(t.item.status)-Bn(s.item.status);return r!==0?r:t.index-s.index}).map(({item:t})=>t),os=({status:e,className:t})=>{const s=ye[e];return e===U.to_do||!s.icon?n.jsxs(n.Fragment,{children:[n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:s.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:K("ds-icon","ds-icon-circle",t),role:"img","aria-hidden":!0,children:n.jsx("circle",{cx:12,cy:12,r:10})}),n.jsx("span",{className:"sr-only",children:`${s.label}:`})]}):n.jsx(c.Icon,{name:s.icon,size:16,color:s.color,className:t,screenReaderText:`${s.label}:`})},fn=2,La=e=>{if(!e)return{canScrollUp:!1,canScrollDown:!1};const t=e.scrollHeight-e.clientHeight;return t<=fn?{canScrollUp:!1,canScrollDown:!1}:{canScrollUp:e.scrollTop>fn,canScrollDown:e.scrollTop<t-fn}},Pa=(e,t)=>{if(!e||!t)return null;const s=e.getBoundingClientRect(),r=t.getBoundingClientRect();return{top:r.top-s.top,left:r.left-s.left,width:r.width,height:r.height}},en=({children:e,className:t,contentClassName:s,scrollSelector:r,style:i,"aria-label":h})=>{const l=a.useRef(null),m=a.useRef(null),[d,w]=a.useState(!1),[_,N]=a.useState(!1),[o,x]=a.useState(null),S=()=>{var R;return r?((R=l.current)==null?void 0:R.querySelector(r))??null:m.current},E=()=>{const R=S(),A=La(R);if(w(p=>p===A.canScrollUp?p:A.canScrollUp),N(p=>p===A.canScrollDown?p:A.canScrollDown),r){const p=Pa(l.current,R);x(f=>(f==null?void 0:f.top)===(p==null?void 0:p.top)&&(f==null?void 0:f.left)===(p==null?void 0:p.left)&&(f==null?void 0:f.width)===(p==null?void 0:p.width)&&(f==null?void 0:f.height)===(p==null?void 0:p.height)?f:p)}else x(p=>p===null?p:null)};a.useLayoutEffect(()=>{E()}),a.useEffect(()=>{const R=l.current;if(!R)return;let A=null,p=null;const f=()=>{A==null||A.removeEventListener("scroll",E),p==null||p.disconnect(),p=null,A=null},T=X=>{if(X===A){E();return}if(f(),A=X,!A){E();return}A.addEventListener("scroll",E,{passive:!0}),p=new ResizeObserver(()=>E()),p.observe(A),A.firstElementChild instanceof HTMLElement&&p.observe(A.firstElementChild),E()};T(S());const D=new MutationObserver(()=>{T(S())});return D.observe(R,{childList:!0,subtree:!0,characterData:!0}),window.addEventListener("resize",E),()=>{window.removeEventListener("resize",E),D.disconnect(),f()}},[r]);const O=R=>{const A=S();if(!A)return;const p=Math.max(A.clientHeight*.75,120);A.scrollBy({top:R==="up"?-p:p,behavior:"smooth"})},L=n.jsxs(n.Fragment,{children:[d&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"scrollable-region__fade scrollable-region__fade--top","aria-hidden":"true"}),n.jsx("button",{type:"button",className:"scrollable-region__edge scrollable-region__edge--top","aria-label":"Scroll up",onClick:()=>O("up"),children:n.jsx(c.Icon,{name:"chevron-up",size:16,color:"currentColor"})})]}),_&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"scrollable-region__fade scrollable-region__fade--bottom","aria-hidden":"true"}),n.jsx("button",{type:"button",className:"scrollable-region__edge scrollable-region__edge--bottom","aria-label":"Scroll down",onClick:()=>O("down"),children:n.jsx(c.Icon,{name:"chevron-down",size:16,color:"currentColor"})})]})]});return n.jsx("div",{ref:l,className:K("scrollable-region",t),style:i,"aria-label":h,children:r?n.jsxs(n.Fragment,{children:[e,o&&(d||_)&&n.jsx("div",{className:"scrollable-region__overlay",style:{top:o.top,left:o.left,width:o.width,height:o.height},children:L})]}):n.jsxs(n.Fragment,{children:[L,n.jsx("div",{ref:m,className:K("scrollable-region__viewport",s),children:e})]})})},Ma=48,Ua=({checklist:e})=>{const t=a.useRef(null),s=a.useRef(!1);return a.useLayoutEffect(()=>{const r=t.current;if(!r)return;const i=r.scrollHeight-r.scrollTop-r.clientHeight;(!s.current||i<=Ma)&&(r.scrollTop=r.scrollHeight,s.current=!0)},[e]),e.length===0?n.jsx("p",{className:"agent-view__progress-empty",children:"No tasks to display."}):n.jsx(en,{className:"agent-view__progress-scroll",scrollSelector:".agent-view__progress-list",children:n.jsx("ul",{ref:t,className:"agent-view__progress-list","aria-label":"Agent tasks",children:Oa(e).map(r=>{const i=ye[r.status];return n.jsxs("li",{className:K("agent-view__progress-item",`agent-view__progress-item--${r.status.replace(/_/g,"-")}`),children:[n.jsx(os,{status:r.status,className:i.spin?"agent-view__progress-icon--spinning":void 0}),n.jsxs("div",{className:"agent-view__progress-item-content",children:[n.jsx("span",{className:"agent-view__progress-label",children:r.task}),r.status!==U.complete&&n.jsx("span",{className:"agent-view__progress-description",children:r.description})]})]},r.task)})})})},cs=({open:e,isInProgress:t,isArchiving:s,error:r,onCancel:i,onConfirm:h})=>{const l=a.useId(),m=a.useId();return n.jsxs(c.Modal,{open:e,closeHandler:i,className:"archive-agent-confirm",children:[n.jsx(c.Modal.Header,{className:"archive-agent-confirm__header",children:n.jsx(c.Modal.Title,{id:l,children:ia})}),n.jsxs(c.Modal.Body,{className:"archive-agent-confirm__body",children:[n.jsxs("div",{role:"alertdialog","aria-labelledby":l,"aria-describedby":m,children:[n.jsx("p",{id:m,className:"archive-agent-confirm__lead",children:la}),t?n.jsx("p",{className:"archive-agent-confirm__progress",children:oa}):null,r?n.jsx("p",{className:"archive-agent-confirm__error",role:"alert",children:r}):null]}),n.jsxs("div",{className:"archive-agent-confirm__actions",children:[n.jsx(c.Button,{variant:"secondary",size:"S",disabled:s,onClick:i,children:"Cancel"}),n.jsx(c.Button,{variant:"secondary-destructive",size:"S",disabled:s,onClick:h,children:s?"Archiving…":"Archive"})]})]})]})},ds=({open:e,isDeleting:t,error:s,onCancel:r,onConfirm:i})=>{const h=a.useId(),l=a.useId();return n.jsxs(c.Modal,{open:e,closeHandler:r,className:"archive-agent-confirm",children:[n.jsx(c.Modal.Header,{className:"archive-agent-confirm__header",children:n.jsx(c.Modal.Title,{id:h,children:pa})}),n.jsxs(c.Modal.Body,{className:"archive-agent-confirm__body",children:[n.jsxs("div",{role:"alertdialog","aria-labelledby":h,"aria-describedby":l,children:[n.jsx("p",{id:l,className:"archive-agent-confirm__lead",children:_a}),s?n.jsx("p",{className:"archive-agent-confirm__error",role:"alert",children:s}):null]}),n.jsxs("div",{className:"archive-agent-confirm__actions",children:[n.jsx(c.Button,{variant:"secondary",size:"S",disabled:t,onClick:r,children:"Cancel"}),n.jsx(c.Button,{variant:"secondary-destructive",size:"S",disabled:t,onClick:i,children:t?"Deleting…":"Delete"})]})]})]})},us=({open:e,isUnarchiving:t,error:s,onCancel:r,onConfirm:i})=>{const h=a.useId(),l=a.useId();return n.jsxs(c.Modal,{open:e,closeHandler:r,className:"archive-agent-confirm",children:[n.jsx(c.Modal.Header,{className:"archive-agent-confirm__header",children:n.jsx(c.Modal.Title,{id:h,children:ca})}),n.jsxs(c.Modal.Body,{className:"archive-agent-confirm__body",children:[n.jsxs("div",{role:"alertdialog","aria-labelledby":h,"aria-describedby":l,children:[n.jsx("p",{id:l,className:"archive-agent-confirm__lead",children:da}),s?n.jsx("p",{className:"archive-agent-confirm__error",role:"alert",children:s}):null]}),n.jsxs("div",{className:"archive-agent-confirm__actions",children:[n.jsx(c.Button,{variant:"secondary",size:"S",disabled:t,onClick:r,children:"Cancel"}),n.jsx(c.Button,{variant:"secondary",size:"S",disabled:t,onClick:i,children:t?"Restoring…":"Restore"})]})]})]})},Da=e=>e!==void 0&&e.some(t=>t.status===U.hitl),hs=e=>e!==void 0&&e.length>0&&e.every(t=>t.status===U.complete),vn=(e,t)=>e.status===k.paused?hs(t)?k.complete:k["generating-a-response"]:Da(t)?k.hitl:e.status===k.complete?k.complete:e.status===k.hitl?k.hitl:k["generating-a-response"];class Ha{constructor(t,s){this.connector=t,this.canSend=s.canSend,this.onTurn=s.onTurn,this.onAwaitingChange=s.onAwaitingChange}get canRate(){return!1}get canLoadHistory(){return!1}get canListInteractions(){return!1}get canSendNotification(){return!1}get ratingPopupUrls(){return{}}async sendMessage(t){var s,r;if(!this.canSend())return{id:`error-${Date.now()}`,text:Aa,type:Ce.CHAT_RESPONSE_TYPE_ERROR};(s=this.onAwaitingChange)==null||s.call(this,!0);try{const i=await this.connector.sendMessage(t.userMessage,t.uploadFiles,...t.onThinking?[{onThinking:t.onThinking}]:[]);return this.onTurn(i),{id:i.message.id,text:i.message.text,type:Ce.CHAT_RESPONSE_TYPE_AGENT,...i.message.followUpPrompts?{followUpPrompts:i.message.followUpPrompts}:{}}}catch{return{id:`error-${Date.now()}`,text:wa,type:Ce.CHAT_RESPONSE_TYPE_ERROR}}finally{(r=this.onAwaitingChange)==null||r.call(this,!1)}}async loadHistory(t){return null}async listInteractions(){return null}async rateMessage(t){}async sendNotification(t){return!1}}const $a=({connector:e,phase:t,chatHistory:s,chatSessionKey:r,readOnly:i=!1,enableUpload:h=!1,onTurn:l,onAwaitingChange:m})=>{const d=a.useMemo(()=>new Ha(e,{canSend:()=>!i&&t===B.running,onTurn:l,onAwaitingChange:m}),[e,t,i,l,m]),w=i||t!==B.running,_=!i&&t===B.running;let N="The agent is not accepting messages.";return _&&(N="Message the agent, paste a link, or attach a file…"),i&&(N="You can view this conversation but cannot send messages."),n.jsxs("section",{className:"agent-workspace__chat-body","aria-label":"Chat",children:[n.jsx("div",{className:"agent-workspace__ask-arbor",children:n.jsx(en,{scrollSelector:".chat-panel-message-list",children:n.jsx(Ce.ChatPanel,{connector:d,chatHistory:s,lockConversation:w,enableUpload:h,speechEnabled:_,speechLanguage:"en-GB",speechSubmissionDelay:1e3,slashMenuItems:[],menuContent:[],introHeading:"Message your agent",introBody:"Ask questions, share trip details, or paste a link. The agent will update the checklist as it works.",placeholder:N},r)})}),i&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(c.Icon,{name:"eye",size:16,color:"var(--color-grey-700)"}),n.jsx("span",{children:"View only — you cannot interact with this agent."})]}),t===B.paused&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(c.Icon,{name:"circle-alert",size:16,color:"var(--color-semantic-warning-600)"}),n.jsx("span",{children:"The agent is paused. Its progress is saved in the checklist."})]}),t===B.complete&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(c.Icon,{name:"party-popper",size:16,color:"var(--color-semantic-success-600)"}),n.jsx("span",{children:"The agent has finished."})]})]})},gs=({item:e,depth:t})=>{const s=ye[e.status],r=e.status.replace(/_/g,"-");return n.jsxs("li",{className:K("agent-workspace__task",`agent-workspace__task--${r}`,{"agent-workspace__task--child":t>0}),children:[n.jsxs("div",{className:"agent-workspace__task-row",children:[n.jsx(os,{status:e.status,className:s.spin?"agent-workspace__task-icon--spinning":void 0}),n.jsxs("div",{className:"agent-workspace__task-content",children:[n.jsx("span",{className:"agent-workspace__task-label",children:e.task}),e.status!==U.complete&&e.description&&n.jsx("span",{className:"agent-workspace__task-description",children:e.description})]})]}),e.children&&e.children.length>0&&n.jsx("ul",{className:"agent-workspace__task-children",children:e.children.map(i=>n.jsx(gs,{item:i,depth:t+1},i.task))})]})},Tt=({items:e,ariaLabel:t})=>n.jsx("ul",{className:"agent-workspace__task-list","aria-label":t,children:e.map(s=>n.jsx(gs,{item:s,depth:0},s.task))}),Ba=({checklist:e,isLoading:t,error:s,phase:r,adminMode:i=!1,context:h,contextLoaded:l=!1,contextLoading:m=!1,contextError:d=null,onContextSelect:w})=>{const[_,N]=a.useState("checklist"),o=a.useMemo(()=>e?ls(e):null,[e]),x=()=>{N("context"),w==null||w()};return n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--checklist","aria-label":"Checklist",children:[n.jsx("div",{className:"agent-workspace__panel-header",children:i?n.jsxs(c.Tabs,{className:"agent-workspace__checklist-tabs","aria-label":"Checklist panel",children:[n.jsx(c.Tabs.Item,{active:_==="checklist",tabElementProps:{id:"agent-checklist-tab-checklist",onClick:()=>N("checklist")},children:"Checklist"}),n.jsx(c.Tabs.Item,{active:_==="context",tabElementProps:{id:"agent-checklist-tab-context",onClick:x},children:"Context"})]}):n.jsx(c.Heading,{level:4,children:"Checklist"})}),n.jsx("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:n.jsx(en,{children:_==="context"?n.jsxs(n.Fragment,{children:[m&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(c.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:"Loading context"}),n.jsx("span",{children:"Loading context…"})]}),!m&&d&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:d}),!m&&!d&&l&&h==null&&n.jsx("p",{className:"agent-workspace__empty",children:"No context available."}),!m&&!d&&l&&h!==null&&h!==void 0&&n.jsx("pre",{className:"agent-workspace__context-json",children:JSON.stringify(h,null,2)})]}):n.jsxs(n.Fragment,{children:[t&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(c.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:rt}),n.jsx("span",{children:rt})]}),!t&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!t&&!s&&o&&n.jsxs(n.Fragment,{children:[o.inProgress.length>0&&n.jsxs("div",{className:"agent-workspace__task-group",children:[(o.needsInput.length>0||o.tasks.length>0||o.failed.length>0||o.complete.length>0)&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"In progress"}),n.jsx(Tt,{items:o.inProgress,ariaLabel:"In progress"})]}),o.needsInput.length>0&&n.jsxs("div",{className:K("agent-workspace__task-group",{"agent-workspace__task-group--following":o.inProgress.length>0}),children:[n.jsx("p",{className:"agent-workspace__task-group-label",children:"Needs your input"}),n.jsx(Tt,{items:o.needsInput,ariaLabel:"Tasks needing your input"})]}),o.failed.length>0&&n.jsxs("div",{className:K("agent-workspace__task-group",{"agent-workspace__task-group--following":o.inProgress.length>0||o.needsInput.length>0}),children:[(o.inProgress.length>0||o.needsInput.length>0||o.tasks.length>0||o.complete.length>0)&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"Failed"}),n.jsx(Tt,{items:o.failed,ariaLabel:"Failed tasks"})]}),o.tasks.length>0&&n.jsxs("div",{className:K("agent-workspace__task-group",{"agent-workspace__task-group--following":o.inProgress.length>0||o.needsInput.length>0||o.failed.length>0}),children:[(o.inProgress.length>0||o.needsInput.length>0||o.failed.length>0||o.complete.length>0)&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"To Do"}),n.jsx(Tt,{items:o.tasks,ariaLabel:"Upcoming tasks"})]}),o.complete.length>0&&n.jsxs("div",{className:K("agent-workspace__task-group",{"agent-workspace__task-group--following":o.inProgress.length>0||o.needsInput.length>0||o.tasks.length>0||o.failed.length>0}),children:[(o.inProgress.length>0||o.needsInput.length>0||o.tasks.length>0||o.failed.length>0)&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"Completed"}),n.jsx(Tt,{items:o.complete,ariaLabel:"Completed tasks"})]})]}),!t&&!s&&(!o||o.inProgress.length===0&&o.needsInput.length===0&&o.complete.length===0&&o.failed.length===0&&o.tasks.length===0)&&n.jsx("p",{className:"agent-workspace__empty",children:r===B.briefing?"Tasks will appear here once the agent starts.":"No tasks to display."})]})})})]})},Fa=({resource:e,html:t,isLoading:s,error:r,onClose:i})=>{a.useEffect(()=>{if(!e)return;const l=c.SlideoverUtils.removeSlideover;return c.SlideoverUtils.removeSlideover=()=>{l(),i()},()=>{c.SlideoverUtils.removeSlideover=l}},[e,i]),a.useEffect(()=>{if(!e)return;const l=m=>{m.key==="Escape"&&c.SlideoverUtils.removeSlideover()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e]);const h=a.useMemo(()=>e?[{centerHeaderText:!1,children:n.jsxs("div",{className:"resource-preview-slideover__body",children:[s&&n.jsxs("div",{className:"resource-preview-slideover__status",children:[n.jsx(c.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:"Loading document"}),n.jsx("span",{children:"Loading document…"})]}),!s&&r&&n.jsx("p",{className:"resource-preview-slideover__error",role:"alert",children:r}),!s&&!r&&t!==null&&n.jsx("iframe",{className:"resource-preview-slideover__frame",title:e.title,sandbox:"",srcDoc:t})]})}]:[],[e,t,s,r]);return n.jsx("div",{className:"resource-preview-slideover",children:n.jsx(c.SlideoverManager,{slideovers:h})})},Ga={[Ne.mis_record]:{icon:"table",label:"Arbor MIS",color:"var(--color-brand-600)"},[Ne.document_html]:{icon:"file",label:"Document",color:"var(--color-semantic-caution-800)"},[Ne.file]:{icon:"file",label:"File",color:"var(--color-semantic-caution-800)"},[Ne.user_file]:{icon:"upload",label:"File upload",color:"var(--color-semantic-caution-800)"},[Ne.workflow]:{icon:"list-tree",label:"Workflow",color:"var(--color-semantic-warning-700)"},[Ne.link]:{icon:"link",label:"Link",color:"var(--color-semantic-info-700)"}},za=({resources:e,isLoading:t=!1,error:s=null,onOpenResource:r})=>n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--documents","aria-label":"Resources",children:[n.jsxs("div",{className:"agent-workspace__panel-header",children:[n.jsx(c.Heading,{level:4,children:"Resources"}),n.jsx("span",{className:"agent-workspace__panel-count",children:e.length})]}),n.jsx("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:n.jsxs(en,{children:[t&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(c.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:"Loading resources"}),n.jsx("span",{children:"Loading resources…"})]}),!t&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!t&&!s&&e.length>0&&n.jsx("ul",{className:"agent-workspace__resource-list","aria-label":"Agent resources",children:e.map(i=>{const h=Ga[i.type],l=i.misRecordUrl;return n.jsx("li",{className:"agent-workspace__resource",children:l?n.jsx("a",{className:"agent-workspace__resource-card",href:l,target:"_blank",rel:"noreferrer",onClick:m=>{m.preventDefault(),r(i)},children:n.jsx(Fn,{resource:i,config:h,external:!0})}):n.jsx("button",{type:"button",className:"agent-workspace__resource-card",onClick:()=>r(i),children:n.jsx(Fn,{resource:i,config:h})})},i.id)})}),!t&&!s&&e.length===0&&n.jsx("p",{className:"agent-workspace__empty",children:"No resources yet."})]})})]}),Fn=({resource:e,config:t,external:s=!1})=>n.jsxs(n.Fragment,{children:[n.jsx("span",{className:`agent-workspace__resource-icon agent-workspace__resource-icon--${e.type}`,children:n.jsx(c.Icon,{name:t.icon,size:16,color:t.color,screenReaderText:`${t.label}:`})}),n.jsx("span",{className:"agent-workspace__resource-content",children:n.jsxs("span",{className:"agent-workspace__resource-top",children:[n.jsx("span",{className:"agent-workspace__resource-name",children:e.title}),n.jsx("span",{className:`agent-workspace__resource-badge agent-workspace__resource-badge--${e.type}`,children:t.label})]})}),s&&n.jsx(c.Icon,{name:"external-link",size:12,color:"var(--color-grey-500)",screenReaderText:"Opens in a new tab",className:"agent-workspace__resource-open"})]}),xn=e=>{const t=Date.parse(e);return Number.isFinite(t)?t:0},qa=new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"2-digit"}),wn=e=>{const t=new Date(e);return Number.isFinite(t.getTime())?qa.format(t):e},Gn=e=>e.replace(/[A-Za-z0-9]+(?:[_-][A-Za-z0-9]+)+/g,t=>t.split(/[_-]/).map(s=>s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()).join(" ")),zn=e=>{const s=e.replace(/[A-Za-z0-9]+(?:[_-][A-Za-z0-9]+)+/g,r=>r.split(/[_-]/).map(i=>i.toLowerCase()).join(" ")).toLowerCase();return s&&s.charAt(0).toUpperCase()+s.slice(1)},Va=60*60*1e3,ms=60*60*1e3,It=24*ms,kn=7*It,Ka=e=>e.type!=="message-sent",Ya=e=>{if(e==null||e<=0)return null;if(e%86400===0){const s=e/86400;return s===1?"every day":`every ${s} days`}if(e%3600===0){const s=e/3600;return s===1?"every hour":`every ${s} hours`}if(e%60===0){const s=e/60;return s===1?"every minute":`every ${s} minutes`}const t=Math.max(1,Math.round(e/60));return t===1?"every minute":`every ${t} minutes`},Ja=e=>{if(e.recurrence==="one_off")return"Scheduled to run once";const t=Ya(e.repeatIntervalSeconds);return t?`Repeating ${t}`:"Repeating run scheduled"},Wa=e=>e.recurrence==="one_off"?"scheduled-one-off":"scheduled-repeating",Xa=(e,t,s=[])=>{const r=e.filter(Ka).map((l,m)=>({kind:"action",id:`action-${l.timestamp}-${m}`,timestampMs:xn(l.timestamp),item:l})),i=t.map(l=>({kind:"chat",id:l.sessionId,timestampMs:xn(l.timestamp),session:l})),h=s.map(l=>({kind:"scheduled",id:`scheduled-${l.scheduleId}`,timestampMs:xn(l.dueAt),run:l}));return[...r,...i,...h].sort((l,m)=>l.timestampMs-m.timestampMs||l.id.localeCompare(m.id))},Za=e=>e>=kn?"weeks":e>=It?"days":"hours",Qa=e=>{if(e<It){const r=Math.max(1,Math.round(e/ms));return r===1?"1 hour later":`${r} hours later`}if(e<kn){const r=Math.max(1,Math.round(e/It));return r===1?"1 day later":`${r} days later`}const t=Math.max(1,Math.round(e/kn));if(t<5)return t===1?"1 week later":`${t} weeks later`;const s=Math.max(1,Math.round(e/(30*It)));return s===1?"1 month later":`${s} months later`},er=(e,t=Va)=>{if(e.length===0)return[];const s=[e[0]];for(let r=1;r<e.length;r+=1){const i=e[r-1],h=e[r],l=h.timestampMs-i.timestampMs;l>=t&&s.push({kind:"gap",id:`gap-${i.id}-${h.id}`,durationMs:l,label:Qa(l),size:Za(l)}),s.push(h)}return s},tr=e=>e.type==="checklist-updated"?"checklist":e.type==="status-transition"?"status":"note",nr=({timeline:e,isLoading:t,error:s,onOpenChatSession:r})=>{const i=(e==null?void 0:e.actionLog)??[],h=(e==null?void 0:e.chatSessions)??[],l=(e==null?void 0:e.scheduledRuns)??[],m=Xa(i,h,l),d=er(m),w=!t&&!s&&m.length===0;return n.jsxs("section",{className:"agent-workspace__timeline","aria-label":"Agent timeline",children:[t&&n.jsx("p",{className:"agent-workspace__timeline-status",role:"status",children:"Loading timeline…"}),s&&n.jsx("p",{className:"agent-workspace__timeline-status",role:"alert",children:s||as}),w&&n.jsx("p",{className:"agent-workspace__timeline-status",role:"status",children:"No timeline activity yet."}),!t&&!s&&!w&&n.jsxs("div",{className:"agent-timeline",children:[n.jsx("div",{className:"agent-timeline__track","aria-hidden":"true"}),n.jsxs("div",{className:"agent-timeline__station agent-timeline__station--terminus",children:[n.jsx("span",{className:"agent-timeline__station-rail",children:n.jsx("span",{className:"agent-timeline__station-node agent-timeline__station-node--terminus","aria-hidden":"true",children:n.jsx(c.Icon,{name:"arrow-right-from-line",size:16,color:"currentColor"})})}),n.jsx("div",{className:"agent-timeline__label",children:n.jsx("strong",{className:"agent-timeline__label-type",children:"Start"})})]}),d.map(_=>{if(_.kind==="gap")return n.jsxs("div",{className:`agent-timeline__gap agent-timeline__gap--${_.size}`,role:"separator","aria-label":_.label,children:[n.jsx("span",{className:"agent-timeline__gap-rail","aria-hidden":"true",children:n.jsx("span",{className:"agent-timeline__gap-dot"})}),n.jsx("span",{className:"agent-timeline__gap-label",children:_.label})]},_.id);if(_.kind==="chat"){const E=wn(_.session.timestamp),O=n.jsx(c.Icon,{name:"sparkles",size:16,color:"currentColor"});return n.jsxs("div",{className:"agent-timeline__chat-station",children:[r?n.jsx("button",{type:"button",className:"agent-timeline__chat-node","aria-label":`Open chat session from ${E}`,onClick:()=>r(_.session.sessionId),children:O}):n.jsx("span",{className:"agent-timeline__chat-node agent-timeline__chat-node--static","aria-hidden":"true",children:O}),n.jsxs("div",{className:"agent-timeline__label",children:[n.jsx("strong",{className:"agent-timeline__label-type",children:"Chat session"}),n.jsx("span",{className:"agent-timeline__label-time",children:E})]})]},_.id)}if(_.kind==="scheduled"){const E=Wa(_.run),O=_.run.recurrence==="one_off"?"One-off run":"Repeating run";return n.jsxs("div",{className:`agent-timeline__station agent-timeline__station--${E}`,children:[n.jsx("span",{className:"agent-timeline__station-rail",children:n.jsx("span",{className:`agent-timeline__station-node agent-timeline__station-node--${E}`,"aria-hidden":"true",children:n.jsx(c.Icon,{name:"date",size:16,color:"currentColor"})})}),n.jsxs("div",{className:"agent-timeline__label",children:[n.jsx("strong",{className:"agent-timeline__label-type",children:O}),n.jsx("span",{className:"agent-timeline__label-entry",children:Ja(_.run)}),n.jsx("span",{className:"agent-timeline__label-time",children:wn(_.run.dueAt)})]})]},_.id)}const{item:N}=_,o=tr(N),x=o==="checklist",S=o==="status";return n.jsxs("div",{className:`agent-timeline__station agent-timeline__station--${o}`,children:[n.jsx("span",{className:"agent-timeline__station-rail",children:n.jsxs("button",{type:"button",className:`agent-timeline__station-node agent-timeline__station-node--${o}`,"aria-label":`${Gn(N.type)}: ${zn(N.entry)}`,children:[x&&n.jsx(c.Icon,{name:"check-solid",size:16,color:"currentColor"}),S&&n.jsx(c.Icon,{name:"iteration-ccw",size:16,color:"currentColor"})]})}),n.jsxs("div",{className:"agent-timeline__label",children:[n.jsx("strong",{className:"agent-timeline__label-type",children:Gn(N.type)}),n.jsx("span",{className:"agent-timeline__label-entry",children:zn(N.entry)}),n.jsx("span",{className:"agent-timeline__label-time",children:wn(N.timestamp)})]})]},_.id)}),n.jsxs("div",{className:"agent-timeline__station agent-timeline__station--terminus",children:[n.jsx("span",{className:"agent-timeline__station-rail",children:n.jsx("span",{className:"agent-timeline__station-node agent-timeline__station-node--terminus","aria-hidden":"true",children:n.jsx(c.Icon,{name:"flag",size:16,color:"currentColor"})})}),n.jsx("div",{className:"agent-timeline__label",children:n.jsx("strong",{className:"agent-timeline__label-type",children:"Finish"})})]})]})]})},sr=(e,t)=>({id:t,contentType:"WIDGET",editedOrCreatedByUser:!0,visible:!0,content:{type:"FILE",header:e}}),Ae=e=>{const t=e.kind===ts.user_file;return{id:e.id,text:t?"":e.text,type:e.author===ge.user?Ce.CHAT_RESPONSE_TYPE_USER:e.author===ge.system?Ce.CHAT_RESPONSE_TYPE_INFO:Ce.CHAT_RESPONSE_TYPE_AGENT,...t?{element:sr(e.text,`${e.id}-file`)}:{},...e.followUpPrompts?{followUpPrompts:e.followUpPrompts}:{}}},bn="MESSAGE_TYPE_REPOLL",ps="agentUi:update",Sn="arbor-agent-",ke={all:"ALL",checklist:"CHECKLIST",resources:"RESOURCES",chat:"CHAT",timeline:"TIMELINE"},ar=new Set(Object.values(ke)),_s=(e,t)=>`${e.endsWith("-")?e:`${e}-`}${t}`,rr=e=>typeof e=="string"&&ar.has(e)?e:ke.all,ir=e=>{if(!e||typeof e!="object")return null;const t=e;return t.type!==bn?null:{type:bn,target:rr(t.target)}},fs=e=>{const t=Array.isArray(e)?e:[e],s=[];for(const r of t){const i=ir(r);i&&s.push(i)}return s},lr=({enabled:e,channelPrefix:t,agentId:s,subscribeToPusher:r,onRepoll:i})=>{const h=a.useRef(i),l=t==null?void 0:t.trim(),m=!!(e&&r&&l&&(s!=null&&s.trim()));return a.useEffect(()=>{h.current=i},[i]),a.useEffect(()=>{if(!m||!r||!l)return;const d=r(_s(l,s),ps,w=>{for(const _ of fs(w))h.current(_.target)});return()=>{d()}},[m,l,s,r]),m};let he=null,Cn="",En="",Qt=0;const or=()=>{window.setTimeout(()=>{Qt>0||!he||(he.disconnect(),he=null,Cn="",En="")},0)},cr=(e,t)=>(he&&(Cn!==e||En!==t)&&(he.disconnect(),he=null),he||(he=new Zs(e,{cluster:t}),Cn=e,En=t),Qt+=1,he),dr=()=>{Qt=Math.max(0,Qt-1),or()},vs=({enabled:e,key:t,cluster:s,isAdmin:r=!1})=>{const i=a.useRef(null),h=t.trim(),l=s.trim(),m=e&&!!h&&!!l;return a.useEffect(()=>{if(!m){i.current=null;return}const d=cr(h,l);return i.current=d,()=>{i.current=null,dr()}},[m,h,l]),a.useMemo(()=>{if(m)return(d,w,_)=>{const N=i.current??he;if(!N)return r&&console.log(`[pusher] subscribe skipped — client not ready for "${d}"`),()=>{};const o=N.subscribe(d);return o.bind(w,_),()=>{o.unbind(w,_),N.unsubscribe(d)}}},[m,r])};class Be extends Error{constructor(t,s,r){super(r??`Agent service request failed (${t})`),this.name="AgentServiceError",this.status=t,this.detail=s}}const ur="/api/v1",$={agentDefinitions:"/agent-definitions",agents:"/agents",conversations:"/conversations",tripOptions:"/trip-options",demoDataset:"/demo/dataset"},z={GET:"GET",POST:"POST",PATCH:"PATCH",DELETE:"DELETE"},hr={error:"error"},gr={user:"user"},$e={acceptJson:"application/json",acceptHtml:"text/html",acceptEventStream:"text/event-stream",contentTypeJson:"application/json",arborApplicationUrl:"X-Arbor-Application-Url"},mr=100,xs=e=>{switch(e){case _n.paused:return k.paused;case _n.complete:return k.complete;case k.hitl:return k.hitl;case _n.active:case k["generating-a-response"]:return k["generating-a-response"];default:return k["generating-a-response"]}},ws=e=>{switch(e){case Rt.requires_attention:case Rt.waiting_on_human:case U.hitl:return U.hitl;case Rt.in_progress:case U["generating-a-response"]:return U["generating-a-response"];case Rt.to_do:case Rt.available:case U.to_do:return U.to_do;case U.failed:case U.complete:return e;default:return U.to_do}},jn=e=>({ref:e.name,display_name:e.display_name,agent_intent:e.agent_intent??"",description:e.description}),pr=e=>({id:e.id,name:e.name,...e.has_run_before?{hasRunBefore:e.has_run_before}:{}}),_r=new Set(Object.values(Ne)),fr=e=>_r.has(e)?e:Ne.document_html,As=e=>({id:e.id,type:fr(e.type),title:e.title,createdDatetime:e.created_datetime,lastUpdatedDatetime:e.last_updated_datetime,misRecordUrl:e.mis_record_url}),Ns=e=>({resources:e.resources.map(As),pageNumber:e.page_number,pageSize:e.page_size,totalRecords:e.total_records}),ys=e=>({actionLog:(e.action_log??[]).map(t=>({timestamp:t.timestamp,type:t.type,entry:t.entry,origin:t.origin})),chatSessions:(e.chat_sessions??[]).map(t=>({sessionId:t.session_id,timestamp:t.timestamp})),scheduledRuns:(e.scheduled_runs??[]).map(t=>({scheduleId:t.schedule_id,dueAt:t.due_at,recurrence:t.recurrence,repeatIntervalSeconds:t.repeat_interval_seconds,wakePrompt:t.wake_prompt}))}),be=e=>{var s;const t=e.invocation_id??e.id;return{id:e.id,invocation_id:t,agent_definition_ref:e.agent_definition_ref,...e.agent_intent?{agent_intent:e.agent_intent}:{},invocation_name:((s=e.invocation_name)==null?void 0:s.trim())||e.agent_definition_ref,application_id:e.application_id,...e.application_name?{application_name:e.application_name}:{},created_by:e.created_by,usable:e.usable??!1,status:xs(e.status),archivedAt:e.archived_at??null,context_ref:e.context_ref??null,checklist_ref:e.checklist_ref??null}},Rn=e=>({task:e.item??e.task??e.name??e.label??ka,status:ws(e.status),description:e.description??""}),vr=e=>Array.isArray(e)?e:e.checklist_items??e.checklist??e.items??[],tn=(e,t,s)=>{var h;const r=!Array.isArray(t)&&(t.opening_message||(h=t.opening_follow_up_prompts)!=null&&h.length)?t:s,i=r?Ot(r):void 0;return{invocation_id:e,checklist:vr(t).map(Rn),...i?{openingMessage:i}:{}}},xr=(e,t)=>{const s=Ot(t);return{invocation_id:t.invocation_id??e,checklist:(t.checklist_items??[]).map(Rn),...s?{openingMessage:s}:{}}},Ot=e=>{var s,r;const t=(s=e.opening_message)==null?void 0:s.trim();if(t)return{id:ss,author:ge.agent,text:t,...(r=e.opening_follow_up_prompts)!=null&&r.length?{followUpPrompts:e.opening_follow_up_prompts}:{}}},wr=e=>{try{const t=JSON.parse(e);if(Array.isArray(t)){const s=t.filter(r=>!!r&&typeof r=="object"&&typeof r.text=="string").map(r=>r.text);if(s.length>0)return s.join(`
2
2
  `)}}catch{}return e},Ar=e=>{const t=e.trim();return t.length>0?`File upload
3
3
 
4
- ${t}`:"File upload"},qn=e=>{var s;const t=(s=e.filename)==null?void 0:s.trim();return t||null},ys=e=>e.filter(t=>qn(t)&&t.role==="user"?!0:(t.role==="user"||t.role==="assistant")&&typeof t.content=="string"&&t.content.length>0&&t.message_type!=="tool_request").map(t=>{const s=qn(t);return s&&t.role==="user"?{id:t.message_id,author:ue.user,kind:ts.user_file,text:s}:{id:t.message_id,author:t.role==="user"?ue.user:ue.agent,text:t.content}}),Nr=/:invocationId\b/g,kr=/:resourceId\b/g,yr=e=>e.trim().replace(/^Bearer\s+/i,""),Vn=e=>e.endsWith("/")?e.slice(0,-1):e;class an{constructor(t){var r;this.baseUrl=Vn(t.baseUrl??"");const s=(r=t.token)==null?void 0:r.trim();this.token=s?yr(s):void 0,this.customHeaders=t.headers,this.urls=t.urls??{},this.fetchImpl=t.fetch??globalThis.fetch.bind(globalThis)}setHeaders(t){this.customHeaders=t}async listAgentDefinitions(){return(await this.request(q.GET,this.resolveUrl("agentDefinitions",B.agentDefinitions))).agent_definitions??[]}getAgentDefinition(t){return this.request(q.GET,this.apiUrl(`${B.agentDefinitions}/${encodeURIComponent(t)}`))}listTripOptions(){return this.request(q.GET,this.apiUrl(B.tripOptions))}getDataset(){return this.request(q.GET,this.apiUrl(B.demoDataset))}setDataset(t){return this.request(q.POST,this.apiUrl(B.demoDataset),{dataset:t})}listAgents(t={}){const s=new URLSearchParams;t.status&&s.set("status",t.status),t.agentDefinitionRef&&s.set("agent_definition_ref",t.agentDefinitionRef),t.scope&&s.set("scope",t.scope);const r=s.toString()?`?${s.toString()}`:"";return this.request(q.GET,`${this.resolveUrl("agents",B.agents)}${r}`)}createAgent(t,s={}){var l,m;const r={agent_definition_ref:t},i=(l=s.invocationName)==null?void 0:l.trim(),h=(m=s.agentIntent)==null?void 0:m.trim();return i&&(r.invocation_name=i),h&&(r.agent_intent=h),this.request(q.POST,this.resolveUrl("agents",B.agents),r)}getAgent(t){return this.request(q.GET,this.resolveUrl("agent",`${B.agents}/${encodeURIComponent(t)}`,t))}updateAgent(t,s){const i={invocation_name:s.invocationName.trim()};return this.request(q.PATCH,this.resolveUrl("agent",`${B.agents}/${encodeURIComponent(t)}`,t),i)}getAgentChecklist(t){return this.request(q.GET,this.resolveUrl("agentChecklist",`${B.agents}/${encodeURIComponent(t)}/checklist`,t))}getAgentResources(t,s={}){const r=new URLSearchParams;s.pageNumber!==void 0&&r.set("page_number",String(s.pageNumber)),s.pageSize!==void 0&&r.set("page_size",String(s.pageSize)),s.type&&r.set("type",s.type);const i=r.toString(),h=this.resolveUrl("agentResources",`${B.agents}/${encodeURIComponent(t)}/resources`,t);return this.request(q.GET,i?`${h}?${i}`:h)}async listAllAgentResources(t){const s=mr;let r=1;const i=[];let h=Number.POSITIVE_INFINITY;for(;i.length<h;){const l=Ns(await this.getAgentResources(t,{pageNumber:r,pageSize:s}));if(h=l.totalRecords,l.resources.length===0||(i.push(...l.resources),i.length>=h))break;r+=1}return i}getAgentResourceHtml(t,s){return this.requestText(q.GET,this.resolveResourceHtmlUrl(t,s))}getAgentTimeline(t){return this.request(q.GET,this.resolveUrl("agentTimeline",`${B.agents}/${encodeURIComponent(t)}/agent-timeline`,t))}getAgentContext(t){const s=this.resolveUrl("agent",`${B.agents}/${encodeURIComponent(t)}`,t);return this.request(q.GET,`${Vn(s)}/context`)}pauseAgent(t){return this.request(q.POST,this.resolveUrl("pauseAgent",`${B.agents}/${encodeURIComponent(t)}/pause`,t))}resumeAgent(t){return this.request(q.POST,this.resolveUrl("resumeAgent",`${B.agents}/${encodeURIComponent(t)}/resume`,t))}archiveAgent(t){return this.request(q.POST,this.resolveUrl("archiveAgent",`${B.agents}/${encodeURIComponent(t)}/archive`,t))}unarchiveAgent(t){return this.request(q.POST,this.resolveUrl("unarchiveAgent",`${B.agents}/${encodeURIComponent(t)}/unarchive`,t))}deleteAgent(t){return this.request(q.DELETE,this.resolveUrl("agent",`${B.agents}/${encodeURIComponent(t)}`,t))}getConversation(t){return this.request(q.GET,this.resolveUrl("agentConversation",`${B.conversations}/${encodeURIComponent(t)}`,t))}async chat(t,s,r={}){const i=!!(r.uploadFiles&&r.uploadFiles.length>0),h=await this.fetchImpl(this.resolveUrl("agentChat",`${B.agents}/${encodeURIComponent(t)}/chat`,t),{method:q.POST,headers:{...this.customHeaders,...this.authHeaders(),Accept:Be.acceptEventStream,...i?{}:{"Content-Type":Be.contentTypeJson}},body:i?Cr(s,r.uploadFiles??[]):JSON.stringify(s),signal:r.signal});if(!h.ok)throw await this.toError(h);if(!h.body)throw new Fe(h.status,null,"Chat response contained no stream body");return this.consumeSse(h.body,r.onEvent)}authHeaders(){return this.token?{Authorization:`Bearer ${this.token}`}:{}}apiUrl(t){return`${this.baseUrl}${dr}${t}`}resolveUrl(t,s,r,i){const h=this.urls[t];if(!h)return this.apiUrl(s);let l=h;return r&&(l=l.replace(Nr,encodeURIComponent(r))),i&&(l=l.replace(kr,encodeURIComponent(i))),l}resolveResourceHtmlUrl(t,s){return this.urls.agentResourceHtml?this.resolveUrl("agentResourceHtml",`${B.agents}/${encodeURIComponent(t)}/resources/${encodeURIComponent(s)}`,t,s):this.urls.agentResources?`${this.resolveUrl("agentResources",`${B.agents}/${encodeURIComponent(t)}/resources`,t).replace(/\/$/,"")}/${encodeURIComponent(s)}`:this.apiUrl(`${B.agents}/${encodeURIComponent(t)}/resources/${encodeURIComponent(s)}`)}async request(t,s,r){const i=await this.fetchImpl(s,{method:t,headers:{...this.customHeaders,...this.authHeaders(),Accept:Be.acceptJson,...r===void 0?{}:{"Content-Type":Be.contentTypeJson}},...r===void 0?{}:{body:JSON.stringify(r)}});if(!i.ok)throw await this.toError(i);if(i.status!==204)return await i.json()}async requestText(t,s){const r=await this.fetchImpl(s,{method:t,headers:{...this.customHeaders,...this.authHeaders(),Accept:Be.acceptHtml}});if(!r.ok)throw await this.toError(r);return r.text()}async toError(t){let s=null;try{s=await t.json()}catch{}return new Fe(t.status,s,`Agent service request failed (${t.status} ${t.statusText})`)}async consumeSse(t,s){const r=t.getReader(),i=new TextDecoder;let h="",l,m;const u=_=>{const{event:N,data:o}=br(_);if(o===null)return;if(N===hr.error){const S=Kn(o);throw new Fe(502,S,(S==null?void 0:S.message)??"Chat stream error")}const x=Kn(o);x&&(l=x,s==null||s(x),x.is_final&&(m=x))};try{for(;;){const{done:_,value:N}=await r.read();if(_)break;h+=i.decode(N,{stream:!0});const o=h.split(`
4
+ ${t}`:"File upload"},Nr=e=>!e.includes(`
5
+ `)&&e.length>0&&e.length<=240&&/\.[A-Za-z0-9]{2,5}$/.test(e),qn=e=>{var s,r;const t=(s=e.filename)==null?void 0:s.trim();if(t)return t;if(e.message_type==="user_file"&&e.role==="user"){const i=(r=e.content)==null?void 0:r.trim();return i&&Nr(i)?i:i?"File upload":null}return null},ks=e=>e.filter(t=>qn(t)&&t.role==="user"?!0:(t.role==="user"||t.role==="assistant")&&typeof t.content=="string"&&t.content.length>0&&t.message_type!=="tool_request"&&t.message_type!=="user_file").map(t=>{const s=qn(t);return s&&t.role==="user"?{id:t.message_id,author:ge.user,kind:ts.user_file,text:s}:{id:t.message_id,author:t.role==="user"?ge.user:ge.agent,text:t.content}}),yr=/:invocationId\b/g,kr=/:resourceId\b/g,br=e=>e.trim().replace(/^Bearer\s+/i,""),Vn=e=>e.endsWith("/")?e.slice(0,-1):e;class nn{constructor(t){var r;this.baseUrl=Vn(t.baseUrl??"");const s=(r=t.token)==null?void 0:r.trim();this.token=s?br(s):void 0,this.customHeaders=t.headers,this.urls=t.urls??{},this.fetchImpl=t.fetch??globalThis.fetch.bind(globalThis)}setHeaders(t){this.customHeaders=t}async listAgentDefinitions(){return(await this.request(z.GET,this.resolveUrl("agentDefinitions",$.agentDefinitions))).agent_definitions??[]}getAgentDefinition(t){return this.request(z.GET,this.apiUrl(`${$.agentDefinitions}/${encodeURIComponent(t)}`))}listTripOptions(){return this.request(z.GET,this.apiUrl($.tripOptions))}getDataset(){return this.request(z.GET,this.apiUrl($.demoDataset))}setDataset(t){return this.request(z.POST,this.apiUrl($.demoDataset),{dataset:t})}listAgents(t={}){const s=new URLSearchParams;t.status&&s.set("status",t.status),t.agentDefinitionRef&&s.set("agent_definition_ref",t.agentDefinitionRef),t.scope&&s.set("scope",t.scope);const r=s.toString()?`?${s.toString()}`:"";return this.request(z.GET,`${this.resolveUrl("agents",$.agents)}${r}`)}createAgent(t,s={}){var l,m;const r={agent_definition_ref:t},i=(l=s.invocationName)==null?void 0:l.trim(),h=(m=s.agentIntent)==null?void 0:m.trim();return i&&(r.invocation_name=i),h&&(r.agent_intent=h),this.request(z.POST,this.resolveUrl("agents",$.agents),r)}getAgent(t){return this.request(z.GET,this.resolveUrl("agent",`${$.agents}/${encodeURIComponent(t)}`,t))}updateAgent(t,s){const i={invocation_name:s.invocationName.trim()};return this.request(z.PATCH,this.resolveUrl("agent",`${$.agents}/${encodeURIComponent(t)}`,t),i)}getAgentChecklist(t){return this.request(z.GET,this.resolveUrl("agentChecklist",`${$.agents}/${encodeURIComponent(t)}/checklist`,t))}getAgentResources(t,s={}){const r=new URLSearchParams;s.pageNumber!==void 0&&r.set("page_number",String(s.pageNumber)),s.pageSize!==void 0&&r.set("page_size",String(s.pageSize)),s.type&&r.set("type",s.type);const i=r.toString(),h=this.resolveUrl("agentResources",`${$.agents}/${encodeURIComponent(t)}/resources`,t);return this.request(z.GET,i?`${h}?${i}`:h)}async listAllAgentResources(t){const s=mr;let r=1;const i=[];let h=Number.POSITIVE_INFINITY;for(;i.length<h;){const l=Ns(await this.getAgentResources(t,{pageNumber:r,pageSize:s}));if(h=l.totalRecords,l.resources.length===0||(i.push(...l.resources),i.length>=h))break;r+=1}return i}getAgentResourceHtml(t,s){return this.requestText(z.GET,this.resolveResourceHtmlUrl(t,s))}getAgentTimeline(t){return this.request(z.GET,this.resolveUrl("agentTimeline",`${$.agents}/${encodeURIComponent(t)}/agent-timeline`,t))}getAgentContext(t){const s=this.resolveUrl("agent",`${$.agents}/${encodeURIComponent(t)}`,t);return this.request(z.GET,`${Vn(s)}/context`)}pauseAgent(t){return this.request(z.POST,this.resolveUrl("pauseAgent",`${$.agents}/${encodeURIComponent(t)}/pause`,t))}resumeAgent(t){return this.request(z.POST,this.resolveUrl("resumeAgent",`${$.agents}/${encodeURIComponent(t)}/resume`,t))}archiveAgent(t){return this.request(z.POST,this.resolveUrl("archiveAgent",`${$.agents}/${encodeURIComponent(t)}/archive`,t))}unarchiveAgent(t){return this.request(z.POST,this.resolveUrl("unarchiveAgent",`${$.agents}/${encodeURIComponent(t)}/unarchive`,t))}deleteAgent(t){return this.request(z.DELETE,this.resolveUrl("agent",`${$.agents}/${encodeURIComponent(t)}`,t))}getConversation(t){return this.request(z.GET,this.resolveUrl("agentConversation",`${$.conversations}/${encodeURIComponent(t)}`,t))}async chat(t,s,r={}){const i=!!(r.uploadFiles&&r.uploadFiles.length>0),h=await this.fetchImpl(this.resolveUrl("agentChat",`${$.agents}/${encodeURIComponent(t)}/chat`,t),{method:z.POST,headers:{...this.customHeaders,...this.authHeaders(),Accept:$e.acceptEventStream,...i?{}:{"Content-Type":$e.contentTypeJson}},body:i?Er(s,r.uploadFiles??[]):JSON.stringify(s),signal:r.signal});if(!h.ok)throw await this.toError(h);if(!h.body)throw new Be(h.status,null,"Chat response contained no stream body");return this.consumeSse(h.body,r.onEvent)}authHeaders(){return this.token?{Authorization:`Bearer ${this.token}`}:{}}apiUrl(t){return`${this.baseUrl}${ur}${t}`}resolveUrl(t,s,r,i){const h=this.urls[t];if(!h)return this.apiUrl(s);let l=h;return r&&(l=l.replace(yr,encodeURIComponent(r))),i&&(l=l.replace(kr,encodeURIComponent(i))),l}resolveResourceHtmlUrl(t,s){return this.urls.agentResourceHtml?this.resolveUrl("agentResourceHtml",`${$.agents}/${encodeURIComponent(t)}/resources/${encodeURIComponent(s)}`,t,s):this.urls.agentResources?`${this.resolveUrl("agentResources",`${$.agents}/${encodeURIComponent(t)}/resources`,t).replace(/\/$/,"")}/${encodeURIComponent(s)}`:this.apiUrl(`${$.agents}/${encodeURIComponent(t)}/resources/${encodeURIComponent(s)}`)}async request(t,s,r){const i=await this.fetchImpl(s,{method:t,headers:{...this.customHeaders,...this.authHeaders(),Accept:$e.acceptJson,...r===void 0?{}:{"Content-Type":$e.contentTypeJson}},...r===void 0?{}:{body:JSON.stringify(r)}});if(!i.ok)throw await this.toError(i);if(i.status!==204)return await i.json()}async requestText(t,s){const r=await this.fetchImpl(s,{method:t,headers:{...this.customHeaders,...this.authHeaders(),Accept:$e.acceptHtml}});if(!r.ok)throw await this.toError(r);return r.text()}async toError(t){let s=null;try{s=await t.json()}catch{}return new Be(t.status,s,`Agent service request failed (${t.status} ${t.statusText})`)}async consumeSse(t,s){const r=t.getReader(),i=new TextDecoder;let h="",l,m;const d=_=>{const{event:N,data:o}=Cr(_);if(o===null)return;if(N===hr.error){const S=Kn(o);throw new Be(502,S,(S==null?void 0:S.message)??"Chat stream error")}const x=Kn(o);x&&(l=x,s==null||s(x),x.is_final&&(m=x))};try{for(;;){const{done:_,value:N}=await r.read();if(_)break;h+=i.decode(N,{stream:!0});const o=h.split(`
5
6
 
6
- `);h=o.pop()??"";for(const x of o)u(x);if(m){await r.cancel().catch(()=>{});break}}!m&&h.trim()&&u(h)}finally{try{r.releaseLock()}catch{}}const w=m??l;if(!w)throw new Fe(502,null,"Chat stream ended without any events");return w}}const br=e=>{let t=null;const s=[];for(const r of e.split(`
7
+ `);h=o.pop()??"";for(const x of o)d(x);if(m){await r.cancel().catch(()=>{});break}}!m&&h.trim()&&d(h)}finally{try{r.releaseLock()}catch{}}const w=m??l;if(!w)throw new Be(502,null,"Chat stream ended without any events");return w}}const Cr=e=>{let t=null;const s=[];for(const r of e.split(`
7
8
  `)){const i=r.trimEnd();i.startsWith("event:")?t=i.slice(6).trim():i.startsWith("data:")&&s.push(i.slice(5).trim())}return{event:t,data:s.length>0?s.join(`
8
- `):null}},Kn=e=>{try{return JSON.parse(e)}catch{return}};function Cr(e,t){const s=new FormData;s.append("body",JSON.stringify(e));for(const r of t)s.append("files",r,r.name);return s}const Er={id:ss,author:ue.agent,text:"Type a question or upload a file. You can ask it how it's progressing, or send an instruction and it'll act on it."};let Yn=0;const Sr=e=>(Yn+=1,`${e}-${Date.now()}-${Yn}`),jr=e=>{const t=e.destination?` to ${e.destination}`:"";return`Let's get started on ${e.tripName.trim()||e.destination.trim()||"this task"}${t}. What will you do first?`};class bs{constructor(t,s,r={}){this.seededChecklist=[],this.client=t,this.agentId=s,this.chatId=r.chatId??s,this.opening=r.openingMessage??Er,this.model=r.model}openingMessage(){return this.opening}async bootstrapConversation(){const t=await this.client.getConversation(this.chatId),s=ys(t.messages);return s.length===0?[this.opening]:s}async start(t){return{...await this.exchange(jr(t)),phase:F.running}}sendMessage(t,s,r){return this.exchange(t,s,r)}async pause(){await this.client.pauseAgent(this.agentId)}async resume(){await this.client.resumeAgent(this.agentId)}seedChecklist(t){this.seededChecklist=t}async exchange(t,s,r){var N;const i=[{role:gr.user,content:t}];let h="",l=null,m;const u=await this.client.chat(this.agentId,{messages:i,chat_id:this.chatId,...this.model?{model:this.model}:{},moderation_enabled:!0,meta:{feature_id:"agent_view",source:"agent_view_frontend"}},{...s&&s.length>0?{uploadFiles:s}:{},onEvent:o=>{var E;const x=o.message;if((x==null?void 0:x.role)==="assistant"&&x.tool_calls&&x.tool_calls.length>0){const O=Ge.thinkingPhrasesFromToolCalls(x.tool_calls);for(const L of O)L.phrase!==l&&(l=L.phrase,(E=r==null?void 0:r.onThinking)==null||E.call(r,L))}const S=x==null?void 0:x.content;S&&(h=o.is_final?S:h+S),o.is_final&&(m=o)}}),w=m??u,_={id:w.event_id||Sr("msg-agent"),author:ue.agent,text:h||w.message.content||"",...(N=w.follow_up_prompts)!=null&&N.length?{followUpPrompts:w.follow_up_prompts}:{}};try{const o=await this.client.getAgentChecklist(this.agentId),{checklist:x}=sn(this.agentId,o);return x.length===0?{message:_}:(this.seededChecklist=x,{message:_,checklist:x})}catch{return{message:_,...this.seededChecklist.length?{checklist:this.seededChecklist}:{}}}}}const Tn=(e,t)=>s=>{var r,i;return new bs(e,s.invocation_id,{model:t==null?void 0:t.model,chatId:((r=t==null?void 0:t.resolveChatId)==null?void 0:r.call(t,s))??(t==null?void 0:t.chatId)??s.invocation_id,openingMessage:((i=t==null?void 0:t.resolveOpeningMessage)==null?void 0:i.call(t,s))??(t==null?void 0:t.openingMessage)})},Cs=e=>e instanceof Fe?e.message:e instanceof TypeError?"Network error while contacting the agent service.":e instanceof Error&&e.message?e.message:rs,Es=e=>{if(e instanceof Fe){if(e.status===403)return ha;if(e.status===409)return ga;if(e.status===404)return ma}return da},Rr=e=>{const t={};for(const s of e){const r=Et(s);if(!r)continue;const i=s.invocation_id??s.id;t[i]=r,t[s.id]=r}return t},Tr=e=>JSON.stringify(e),Zt=(e,t)=>JSON.stringify(e)===JSON.stringify(t),Ss=e=>{const{jwt:t,headers:s,urls:r,scope:i=is}=e,h=JSON.stringify(s??{}),l=Tr(r),m=a.useMemo(()=>({scope:i}),[i]),u=a.useMemo(()=>new an({token:t,headers:s,urls:r}),[t,l]);a.useLayoutEffect(()=>{u.setHeaders(s)},[u,h]);const[w,_]=a.useState([]),[N,o]=a.useState([]),[x,S]=a.useState({}),[E,O]=a.useState("loading"),[L,R]=a.useState(null),[A,p]=a.useState(0),f=a.useRef(0),T=a.useCallback((k,U)=>{const j=k.map(Ce),D=U.map(jn),$=Rr(k);_(V=>Zt(V,j)?V:j),o(V=>Zt(V,D)?V:D),S(V=>Zt(V,$)?V:$),O("idle"),R(null)},[]);a.useEffect(()=>{const k=++f.current;O("loading"),R(null),(async()=>{try{const[U,j]=await Promise.all([u.listAgents(m),u.listAgentDefinitions()]);if(k!==f.current)return;T(U,j)}catch(U){if(k!==f.current)return;_([]),o([]),S({}),O("error"),R(Cs(U))}})()},[T,u,m,A]);const H=a.useCallback(()=>{p(k=>k+1)},[]),W=a.useCallback(async()=>{const k=++f.current;try{const[U,j]=await Promise.all([u.listAgents(m),u.listAgentDefinitions()]);if(k!==f.current)return;T(U,j)}catch{}},[T,u,m]),lt=a.useCallback(async k=>{const[U,j]=await Promise.all([u.getAgentChecklist(k),u.getAgent(k).catch(()=>null)]);return sn(k,U,j??void 0)},[u]),ze=a.useCallback(async k=>u.listAllAgentResources(k),[u]),Y=a.useCallback(async({definition:k,invocationName:U})=>{const j=await u.createAgent(k.ref,{invocationName:U}),D=await u.getAgent(j.id),$=Ce(D),V=Et(D);return _(ge=>[$,...ge]),V&&S(ge=>({...ge,[$.invocation_id]:V,[$.id]:V})),$},[u]),te=a.useCallback(async k=>{const U=await u.archiveAgent(k),j=Ce(U);return _(D=>D.map($=>$.id===j.id||$.id===k||$.invocation_id===k?j:$)),j},[u]),re=a.useCallback(async k=>{const U=await u.unarchiveAgent(k),j=Ce(U);return _(D=>D.map($=>$.id===j.id||$.id===k||$.invocation_id===k?j:$)),j},[u]),de=a.useCallback(k=>{_(U=>U.filter(j=>j.id!==k&&j.invocation_id!==k))},[]),P=a.useCallback(k=>{_(U=>{const j=U.map(D=>D.id===k.id||D.invocation_id===k.invocation_id?{...D,...k}:D);return Zt(U,j)?U:j})},[]),he=a.useCallback(async k=>{await u.deleteAgent(k),de(k)},[u,de]),Q=a.useMemo(()=>Tn(u,{resolveOpeningMessage:k=>x[k.invocation_id]??x[k.id]}),[u,x]);return{agents:w,agentDefinitions:N,loadState:E,loadError:L,reload:H,refresh:W,fetchAgentChecklist:lt,fetchAgentResources:ze,createAgent:Y,archiveAgent:te,unarchiveAgent:re,deleteAgent:he,removeAgent:de,replaceAgent:P,chatConnector:Q}},Ir=e=>JSON.stringify(e),js=e=>{const{agent:t,jwt:s,headers:r,urls:i,chatId:h}=e,l=JSON.stringify(r??{}),m=Ir(i),u=a.useMemo(()=>new an({token:s,headers:r,urls:{agent:i.agentUrl,agentChecklist:i.agentChecklistUrl,...i.agentResourcesUrl?{agentResources:i.agentResourcesUrl}:{},...i.agentTimelineUrl?{agentTimeline:i.agentTimelineUrl}:{},agentChat:i.agentChatUrl,agentConversation:i.agentConversationUrl,...i.pauseAgentUrl?{pauseAgent:i.pauseAgentUrl}:{},...i.resumeAgentUrl?{resumeAgent:i.resumeAgentUrl}:{},...i.archiveAgentUrl?{archiveAgent:i.archiveAgentUrl}:{},...i.unarchiveAgentUrl?{unarchiveAgent:i.unarchiveAgentUrl}:{}}}),[s,m]);a.useLayoutEffect(()=>{u.setHeaders(r)},[u,l]);const w=a.useCallback(async p=>Ce(await u.getAgent(p)),[u]),_=a.useCallback(async p=>{const[f,T]=await Promise.all([u.getAgentChecklist(p),u.getAgent(p).catch(()=>null)]);return sn(p,f,T??void 0)},[u]),N=a.useCallback(async p=>u.listAllAgentResources(p),[u]),o=a.useCallback(async p=>u.getAgentContext(p),[u]),x=a.useCallback(async(p,f)=>u.getAgentResourceHtml(p,f),[u]),S=a.useCallback(async p=>{const f=await u.getAgentTimeline(p);return ks(f)},[u]),E=a.useCallback(async(p,f)=>{await u.updateAgent(p,{invocationName:f})},[u]),O=a.useCallback(async p=>Ce(await u.archiveAgent(p)),[u]),L=a.useCallback(async p=>Ce(await u.unarchiveAgent(p)),[u]),R=a.useCallback(async p=>{await u.deleteAgent(p)},[u]);return{connector:a.useMemo(()=>Tn(u,{chatId:h??t.invocation_id})(t),[u,t.invocation_id,h]),fetchAgent:w,fetchAgentChecklist:_,fetchAgentContext:o,fetchAgentResources:N,fetchAgentResourceHtml:x,fetchAgentTimeline:S,updateAgentInvocationName:E,archiveAgent:O,unarchiveAgent:L,deleteAgent:R}},Or=3e4,Lr=(e,t)=>{const s=e.hasRunBefore?t||"This trip":e.tripName.trim()||"A new trip",r=e.destination?` to ${e.destination}`:"",i=e.hasRunBefore?" It has run before.":"";return`${s}${r}.${i}`.trim()},Jn=e=>{switch(e){case y.paused:return F.paused;case y.complete:return F.complete;default:return F.running}},An=e=>e===y.paused,Wn=(e,t)=>{t([Ne(e)])},Pr=(e,t)=>e.length===t.length&&e.every((s,r)=>{const i=t[r];return i!==void 0&&s.id===i.id&&s.text===i.text}),Rs=({agent:e,invocationId:t,open:s,onClose:r,jwt:i,headers:h,agentUrl:l,agentChecklistUrl:m,agentResourcesUrl:u,agentTimelineUrl:w,agentChatUrl:_,agentConversationUrl:N,pauseAgentUrl:o,resumeAgentUrl:x,archiveAgentUrl:S,unarchiveAgentUrl:E,chatId:O,enableUpload:L,adminMode:R=!1,initialBrief:A,initialPhase:p,initialChecklist:f,usePusherToRepoll:T=!1,pusherChannelPrefix:H=Sn,pusherKey:W="",pusherCluster:lt="",subscribeToPusher:ze,onArchived:Y,onUnarchived:te,onDeleted:re,onAgentUpdated:de})=>{const[P,he]=a.useState(O??t),[Q,k]=a.useState("chat"),[U,j]=a.useState(!1),{connector:D,fetchAgent:$,fetchAgentChecklist:V,fetchAgentContext:ge,fetchAgentResources:Ee,fetchAgentResourceHtml:St,fetchAgentTimeline:qe,updateAgentInvocationName:jt,archiveAgent:Ve,unarchiveAgent:Se,deleteAgent:je}=js({agent:{...e,invocation_id:t},jwt:i,headers:h,chatId:P,urls:{agentUrl:l,agentChecklistUrl:m,agentResourcesUrl:u,agentTimelineUrl:w,agentChatUrl:_,agentConversationUrl:N,pauseAgentUrl:o,resumeAgentUrl:x,archiveAgentUrl:S,unarchiveAgentUrl:E}}),K=a.useRef(D),[Re,ne]=a.useState(e.invocation_name),[Rt,Te]=a.useState(0),[Ie,fe]=a.useState(null),[ie,se]=a.useState(p??(A?F.running:Jn(e.status))),[rn,z]=a.useState([]),[ot,Oe]=a.useState(0),[Tt,It]=a.useState([]),[Ke,Ot]=a.useState(!1),[ct,ve]=a.useState(null),[ut,Ye]=a.useState(null),[Lt,dt]=a.useState(null),[Je,me]=a.useState(!1),[ht,Le]=a.useState(null),[xe,Pt]=a.useState(null),[We,Mt]=a.useState(!1),[Ut,Xe]=a.useState(null),[Pe,le]=a.useState(f??null),[Dt,Me]=a.useState(!1),[Ht,Ze]=a.useState(null),[ln,gt]=a.useState(void 0),[Qe,et]=a.useState(!1),[we,mt]=a.useState(!1),[on,pt]=a.useState(null),[$t,_t]=a.useState(!1),[Bt,Ft]=a.useState(!1),[Gt,zt]=a.useState(!1),[cn,ft]=a.useState(!1),[un,tt]=a.useState(null),[qt,Vt]=a.useState(!1),[dn,vt]=a.useState(!1),[Kt,Ue]=a.useState(null),[d,b]=a.useState(!1),[C,ee]=a.useState(!1),[De,pe]=a.useState(null),[Ae,X]=a.useState(null),[Ls,xt]=a.useState(()=>An(e.status)),[Ps,In]=a.useState(e.archivedAt??null),G=!!Ps,wt=!e.usable,[hn,At]=a.useState(!1),[Yt,Ms]=a.useState(!1),[Jt,Us]=a.useState(!1),On=a.useRef(hn),Ln=a.useRef(e.invocation_name),nt=a.useRef(e),oe=a.useRef(de),Pn=a.useRef(0),Mn=a.useRef(0),st=a.useRef(0),Nt=a.useRef(0);oe.current=de,a.useEffect(()=>{In(e.archivedAt??null)},[e.archivedAt]),a.useEffect(()=>{K.current=D},[D]),a.useEffect(()=>{Ln.current=e.invocation_name},[e.invocation_name]),a.useEffect(()=>{nt.current=e},[e]),a.useEffect(()=>{On.current=hn},[hn]),a.useEffect(()=>{he(O??t),k("chat"),j(!1),z([]),Oe(g=>g+1),fe(null)},[t,O]),a.useEffect(()=>(st.current+=1,gt(void 0),et(!1),mt(!1),pt(null),()=>{st.current+=1}),[t]),a.useEffect(()=>{xt(An(e.status))},[e.status,t]),a.useEffect(()=>{if(!s||A||G)return;const g=++Nt.current;return(async()=>{var v;try{const I=await $(t);if(g!==Nt.current)return;se(Jn(I.status)),xt(An(I.status)),nt.current=I,(v=oe.current)==null||v.call(oe,I)}catch{}})(),()=>{Nt.current+=1}},[s,t,A,G,$]),a.useEffect(()=>{ne(e.invocation_name),Te(g=>g+1)},[e.invocation_name]),a.useEffect(()=>{G&&k("timeline")},[G]),a.useEffect(()=>{if(!s||A||G)return;const g=K.current.bootstrapConversation;if(!g){Wn(K.current.openingMessage(),z);return}let v=!1;return At(!0),(async()=>{try{const I=await g.call(K.current);if(v)return;z(I.map(Ne))}catch{v||Wn(K.current.openingMessage(),z)}finally{v||At(!1)}})(),()=>{v=!0}},[s,A,G,t,P]);const He=a.useCallback(()=>{const g=++Pn.current;(async()=>{var v,I;try{const Z=await V(t);if(g!==Pn.current)return;le(ae=>Z.checklist.length===0&&Array.isArray(ae)&&ae.length>0||JSON.stringify(ae)===JSON.stringify(Z.checklist)?ae:Z.checklist),Ze(null),(I=(v=K.current).seedChecklist)==null||I.call(v,Z.checklist)}catch{}})()},[V,t]),$e=a.useCallback(()=>{u&&(async()=>{try{const g=await Ee(t);It(g),ve(null)}catch{}})()},[u,Ee,t]),_e=a.useCallback(()=>{if(!w)return;const g=++Mn.current;(async()=>{try{const v=await qe(t);if(g!==Mn.current)return;Pt(I=>JSON.stringify(I)===JSON.stringify(v)?I:v),Xe(null)}catch{}})()},[w,qe,t]),kt=a.useCallback(g=>{const v=K.current.bootstrapConversation;v&&(async()=>{try{const I=await v.call(K.current);if(On.current)return;const Z=I.map(Ne);let ae=!1;z(at=>Pr(at,Z)?at:(ae=!0,Z)),ae&&(g!=null&&g.refreshSidePanelsOnChange)&&(He(),_e())}catch{}})()},[He,_e]),Ds=a.useCallback(g=>{switch(g){case be.checklist:He();return;case be.resources:$e();return;case be.chat:kt();return;case be.timeline:_e();return;case be.all:default:He(),$e(),kt(),_e()}},[He,kt,$e,_e]),Hs=vs({enabled:!!(s&&T&&!ze),key:W,cluster:lt,isAdmin:R}),$s=ze??Hs,Un=lr({enabled:s&&T,channelPrefix:H,agentId:e.id||t,subscribeToPusher:$s,onRepoll:Ds});a.useEffect(()=>{if(!s||A||G||Un)return;const g=window.setInterval(()=>{kt({refreshSidePanelsOnChange:!0})},Or);return()=>{window.clearInterval(g)}},[s,A,G,Un,t,P,kt]);const Wt=a.useCallback(g=>{var v,I;if(g&&g.length>0){le(g),(I=(v=K.current).seedChecklist)==null||I.call(v,g);return}He()},[He]),gn=a.useCallback(g=>{Wt(g.checklist),g.phase&&se(g.phase),$e(),_e()},[Wt,$e,_e]);a.useEffect(()=>{var g,v;!s||A||f&&f.length>0&&((v=(g=K.current).seedChecklist)==null||v.call(g,f))},[s,A,f]),a.useEffect(()=>{if(!s||A)return;let g=!1;return Me(v=>f!=null&&f.length?!1:v||Pe===null||Pe.length===0),Ze(null),(async()=>{var v,I;try{const Z=await V(t);if(g)return;f!=null&&f.length||(le(Z.checklist),(I=(v=K.current).seedChecklist)==null||I.call(v,Z.checklist))}catch{!g&&!(f!=null&&f.length)&&Ze(Qt)}finally{g||Me(!1)}})(),()=>{g=!0}},[s,t,A,f,V]),a.useEffect(()=>{if(!s||!u)return;let g=!1;return Ot(!0),ve(null),(async()=>{try{const v=await Ee(t);g||It(v)}catch{g||ve(sa)}finally{g||Ot(!1)}})(),()=>{g=!0}},[s,t,u,Ee]);const Bs=a.useCallback(()=>{Ye(null),dt(null),Le(null),me(!1)},[]),Fs=a.useCallback(g=>{if(g.misRecordUrl){window.open(g.misRecordUrl,"_blank","noopener,noreferrer");return}Ye(g),dt(null),Le(null),me(!0),(async()=>{try{const v=await St(t,g.id);dt(v)}catch{Le(aa)}finally{me(!1)}})()},[St,t]);a.useEffect(()=>{if(!s||!w)return;let g=!1;return Mt(v=>v||xe===null),Xe(null),(async()=>{try{const v=await qe(t);g||Pt(v)}catch{g||Xe(as)}finally{g||Mt(!1)}})(),()=>{g=!0}},[s,t,w,qe]),a.useEffect(()=>{if(!s||!A)return;let g=!1;const v={id:`user-brief-${Date.now()}`,author:ue.user,text:Lr(A,Ln.current)};return(async()=>{const I=await K.current.start(A);g||(z([Ne(K.current.openingMessage()),Ne(v),Ne(I.message)]),Wt(I.checklist),se(I.phase??F.running),$e(),_e())})(),()=>{g=!0}},[s,A,t,Wt,$e,_e]);const mn=O??t,Xt=xe==null?void 0:xe.chatSessions,Dn=Xt!=null&&Xt.length?Xt.reduce((g,v)=>Date.parse(v.timestamp)<Date.parse(g.timestamp)?v:g).sessionId:void 0,pn=a.useCallback(()=>{k("chat"),j(!1),P!==mn&&(he(mn),z([]),Oe(g=>g+1))},[P,mn]),Gs=a.useCallback(g=>{if(g===Dn){pn();return}he(g),j(!0),k("chat"),z([]),Oe(v=>v+1)},[Dn,pn]),zs=a.useCallback(async()=>{var g;X(null),_t(!0);try{await K.current.pause(),Nt.current+=1,se(F.paused),xt(!0);const v={...nt.current,status:y.paused};nt.current=v,(g=oe.current)==null||g.call(oe,v)}catch{X(ra)}finally{_t(!1)}},[]),qs=a.useCallback(async()=>{var v;X(null),Ft(!0);let g=!1;try{await K.current.resume(),g=!0,Nt.current+=1,se(F.running),xt(!1);const I={...nt.current,status:y["generating-a-response"]};nt.current=I,(v=oe.current)==null||v.call(oe,I),At(!0);const Z={id:`wake-${Date.now()}`,author:ue.user,text:$n};z(at=>[...at,Ne(Z)]);const ae=await K.current.sendMessage($n);z(at=>[...at,Ne(ae.message)]),gn(ae)}catch{X(g?va:fa)}finally{Ft(!1),At(!1)}},[gn]),Vs=a.useCallback(async()=>{X(null),tt(null),zt(!0);try{await Ve(t),ft(!1),Y==null||Y(),r()}catch{tt(Nn),X(Nn)}finally{zt(!1)}},[t,Ve,Y,r]),Ks=a.useCallback(async()=>{X(null),Ue(null),Vt(!0);try{await Se(t),In(null),se(F.paused),xt(!0),k("chat"),vt(!1),te==null||te()}catch{Ue(kn),X(kn)}finally{Vt(!1)}},[t,Se,te]),Ys=a.useCallback(async()=>{X(null),pe(null),b(!0);try{await je(t),ee(!1),re==null||re(),r()}catch(g){pe(Es(g))}finally{b(!1)}},[t,je,re,r]),Js=a.useCallback(g=>{const v=g.trim(),I=Re;if(fe(null),!v){Te(Z=>Z+1);return}v!==I&&(ne(v),(async()=>{try{await jt(t,v)}catch{ne(I),Te(Z=>Z+1),fe(xa)}})())},[Re,t,jt]),Ws=a.useCallback(()=>{if(!R||Qe||we)return;const g=++st.current;mt(!0),pt(null),(async()=>{try{const v=await ge(t);if(st.current!==g)return;gt(v),et(!0)}catch{st.current===g&&pt(na)}finally{st.current===g&&mt(!1)}})()},[R,Qe,we,ge,t]),Xs=Pe;return n.jsxs(n.Fragment,{children:[n.jsxs(c.Modal,{open:s,closeHandler:r,hideCloseButton:!0,className:"agent-workspace",children:[n.jsxs(c.Modal.Header,{className:"agent-workspace__header",children:[n.jsxs("div",{className:"agent-workspace__header-title",children:[n.jsx("span",{className:"agent-workspace__header-avatar","aria-hidden":"true",children:n.jsx(c.Icon,{name:"ask-arbor",size:24})}),n.jsx(c.Modal.Title,{children:G?n.jsx("span",{className:"agent-workspace__header-name",children:Re}):n.jsx(c.EditableText,{className:"agent-workspace__header-name",text:Re,onEditSave:Js},Rt)}),n.jsx("span",{className:J("agent-workspace__phase",`agent-workspace__phase--${ie}`),children:ya[ie]}),G?n.jsx("span",{className:"agent-workspace__phase agent-workspace__phase--archived",children:"Archived"}):null,Ie&&n.jsx("p",{className:"agent-workspace__error agent-workspace__name-error",role:"alert",children:Ie})]}),n.jsxs("div",{className:"agent-workspace__header-actions",children:[n.jsx(c.Button,{variant:Yt?"secondary":"primary",size:"S",iconLeftName:"clipboard-list",iconLeftScreenReaderText:"Toggle checklist","aria-pressed":!Yt,onClick:()=>Ms(g=>!g),children:"Checklist"}),n.jsx(c.Button,{variant:Jt?"secondary":"primary",size:"S",iconLeftName:"files",iconLeftScreenReaderText:"Toggle resources","aria-pressed":!Jt,onClick:()=>Us(g=>!g),children:"Resources"}),n.jsx(c.Button,{variant:"secondary",size:"S",iconLeftName:"x",iconLeftScreenReaderText:"Close",onClick:r,children:"Close"})]})]}),n.jsxs(c.Modal.Body,{className:J("agent-workspace__body",{"agent-workspace__body--no-checklist":Yt,"agent-workspace__body--no-resources":Jt}),children:[n.jsxs("section",{className:J("agent-workspace__panel","agent-workspace__panel--chat",{"agent-workspace__panel--timeline":!!w&&(G||Q==="timeline")}),"aria-label":"Agent",children:[n.jsxs("div",{className:"agent-workspace__panel-header",children:[n.jsx(c.Heading,{level:4,children:"Agent"}),o&&!wt&&!G&&ie===F.running&&n.jsx(c.Button,{className:"agent-workspace__panel-header-action",variant:"secondary-destructive",size:"S",iconLeftName:"circle-x",iconLeftScreenReaderText:"Pause",disabled:$t,onClick:()=>void zs(),children:$t?"Pausing…":"Pause agent"}),x&&!wt&&!G&&ie===F.paused&&Ls&&n.jsx(c.Button,{className:"agent-workspace__panel-header-action",variant:"secondary",size:"S",iconLeftName:"iteration-ccw",iconLeftScreenReaderText:"Resume",disabled:Bt,onClick:()=>void qs(),children:Bt?"Resuming…":"Resume agent"}),S&&!wt&&!G&&n.jsx(c.Button,{className:"agent-workspace__panel-header-action",variant:"secondary",size:"S",iconLeftName:"archive",iconLeftScreenReaderText:"Archive",onClick:()=>{tt(null),X(null),ft(!0)},children:"Archive agent"}),E&&!wt&&G&&n.jsx(c.Button,{className:"agent-workspace__panel-header-action",variant:"secondary",size:"S",onClick:()=>{Ue(null),X(null),vt(!0)},children:"Unarchive agent"}),R&&G&&n.jsx(c.Button,{className:"agent-workspace__panel-header-action",variant:"secondary-destructive",size:"S",onClick:()=>{pe(null),X(null),ee(!0)},children:"Delete agent"})]}),Ae&&n.jsx("p",{className:"agent-workspace__error agent-workspace__lifecycle-error",role:"alert",children:Ae}),w&&!G&&n.jsxs(c.Tabs,{className:"agent-workspace__center-tabs","aria-label":"Center panel",children:[n.jsx(c.Tabs.Item,{active:Q==="chat",tabElementProps:{id:"agent-center-tab-chat",onClick:()=>k("chat")},children:"Chat"}),n.jsx(c.Tabs.Item,{active:Q==="timeline",tabElementProps:{id:"agent-center-tab-timeline",onClick:()=>k("timeline")},children:"Timeline"})]}),w&&!G&&Q==="chat"&&U&&n.jsx("div",{className:"agent-workspace__center-back",children:n.jsx(c.Button,{variant:"tertiary",size:"S",iconLeftName:"arrow-left",iconLeftScreenReaderText:"Back to main chat",onClick:pn,children:"Back to main chat"})}),w&&(G||Q==="timeline")&&n.jsx(tr,{timeline:xe,isLoading:We,error:Ut,onOpenChatSession:G?void 0:Gs}),!G&&n.jsx("div",{className:"agent-workspace__chat-keep-alive",hidden:!!w&&Q!=="chat",children:n.jsx(Ha,{connector:D,phase:ie,chatHistory:rn,chatSessionKey:ot,readOnly:wt,enableUpload:L,onTurn:gn,onAwaitingChange:At})}),G&&!w&&n.jsx("p",{className:"agent-workspace__timeline-status",role:"status",children:"Chat is not available for archived agents."})]}),!Yt&&n.jsx($a,{checklist:Xs,isLoading:Dt,error:Ht,phase:ie,adminMode:R,context:ln,contextLoaded:Qe,contextLoading:we,contextError:on,onContextSelect:Ws},t),!Jt&&n.jsx(Ga,{resources:Tt,isLoading:Ke,error:ct,onOpenResource:Fs}),n.jsx(Ba,{resource:ut,html:Lt,isLoading:Je,error:ht,onClose:Bs})]})]}),n.jsx(cs,{open:cn,isInProgress:ie===F.running||ie===F.paused&&!hs(Pe??void 0),isArchiving:Gt,error:un,onCancel:()=>{Gt||(tt(null),ft(!1))},onConfirm:()=>{Vs()}}),n.jsx(ds,{open:dn,isUnarchiving:qt,error:Kt,onCancel:()=>{qt||(Ue(null),vt(!1))},onConfirm:()=>{Ks()}}),n.jsx(us,{open:C,isDeleting:d,error:De,onCancel:()=>{d||(pe(null),ee(!1))},onConfirm:()=>{Ys()}})]})},Mr="Unable to load agent definitions. Please try again.",Ur="Unable to start the agent.",Xn="Loading agents…",Dr="Which agent?",Hr="Select an agent",$r="Name for this run",Br="e.g. Year 6 Science Museum trip",Fr="Shown on the board and in the workspace",Zn="new-agent-invocation-name-hint",Ts=({open:e,onClose:t,onStart:s,agentDefinitions:r,definitionsState:i="idle",definitionsError:h=null,onRetryDefinitions:l,embedded:m=!1})=>{const[u,w]=a.useState(void 0),[_,N]=a.useState(""),[o,x]=a.useState(!1),[S,E]=a.useState(null),O=[...r].sort((T,H)=>T.display_name.localeCompare(H.display_name)).map(T=>({value:T.ref,label:T.display_name}));a.useEffect(()=>{e&&(w(void 0),N(""),x(!1),E(null))},[e]);const L=u!==void 0&&_.trim().length>0,R=a.useCallback(T=>{const H=r.find(W=>W.ref===T[0]);H&&w(H)},[r]),A=a.useCallback(async()=>{if(!(!u||!L||o)){x(!0),E(null);try{await s({definition:u,invocationName:_.trim()})}catch(T){E(T instanceof Error?T.message:Ur)}finally{x(!1)}}},[L,u,_,o,s]);if(i==="idle"&&r.length===0||!e)return null;const p=n.jsxs("div",{className:"new-agent__header-title",children:[n.jsx("span",{className:"new-agent__header-avatar","aria-hidden":"true",children:n.jsx(c.Icon,{name:"ask-arbor",size:24})}),m?n.jsx("h2",{className:"new-agent__title",children:"Start an agent"}):n.jsx(c.Modal.Title,{children:"Start an agent"})]});let f;return i==="loading"?f=n.jsxs("div",{className:"new-agent__state","aria-live":"polite",children:[n.jsx(c.Icon,{name:"loader",size:24,color:"var(--color-brand-600)",className:"new-agent__spinner",screenReaderText:Xn}),n.jsx("p",{className:"new-agent__state-message",children:Xn})]}):i==="error"?f=n.jsxs("div",{className:"new-agent__state new-agent__state--error",role:"alert",children:[n.jsx(c.Icon,{name:"triangle-alert",size:24,color:"var(--color-semantic-destructive-600)"}),n.jsx("p",{className:"new-agent__state-message",children:h??Mr}),l?n.jsx(c.Button,{variant:"secondary",size:"S",onClick:l,children:"Try again"}):null]}):f=n.jsxs("form",{className:"new-agent__form","aria-label":"Start an agent",onSubmit:T=>{T.preventDefault(),L&&!o&&A()},children:[n.jsxs("div",{className:"new-agent__type-field",children:[n.jsx("label",{className:"new-agent__type-label",htmlFor:"new-agent-type",children:Dr}),n.jsx(c.SelectDropdown,{id:"new-agent-type",placeholder:Hr,options:O,selectedValues:u?[u.ref]:[],onSelectionChange:R})]}),n.jsxs("div",{className:"new-agent__type-field",children:[n.jsx("label",{className:"new-agent__type-label",htmlFor:"new-agent-invocation-name",children:$r}),n.jsx(c.TextInput,{id:"new-agent-invocation-name",value:_,placeholder:Br,"aria-describedby":Zn,onChange:T=>N(T.target.value)}),n.jsx("p",{className:"new-agent__field-hint",id:Zn,children:Fr})]}),S?n.jsx("p",{className:"new-agent__error",role:"alert",children:S}):null,n.jsx("div",{className:"new-agent__actions",children:n.jsx(c.Button,{type:"submit",variant:"primary",className:J("new-agent__start-button",{"new-agent__start-button--starting":o}),disabled:!L||o,iconLeftName:o?"loader":"sparkles",iconLeftScreenReaderText:o?"Starting":void 0,children:o?"Starting…":"Start"})})]}),m?n.jsxs("div",{className:J("new-agent","new-agent--embedded"),children:[n.jsx("div",{className:"new-agent__header",children:p}),n.jsx("div",{className:"new-agent__body",children:f})]}):n.jsxs(c.Modal,{open:e,closeHandler:t,className:"new-agent",children:[n.jsx(c.Modal.Header,{className:"new-agent__header",children:p}),n.jsx(c.Modal.Body,{className:"new-agent__body",children:f})]})},Qn=e=>{window.location.assign(e)},Gr=({open:e,authToken:t,headers:s,agentDefinitionsUrl:r,agentsUrl:i,closeUrl:h,successUrl:l,onClose:m,onStart:u,embedded:w=!1})=>{const _=JSON.stringify(s??{}),N=a.useMemo(()=>new an({token:t,headers:s,urls:{agentDefinitions:r,agents:i}}),[t,r,i,_]),[o,x]=a.useState([]),[S,E]=a.useState("loading"),[O,L]=a.useState(null),[R,A]=a.useState(0);a.useEffect(()=>{if(!e)return;let H=!1;return E("loading"),L(null),(async()=>{try{const W=await N.listAgentDefinitions();if(H)return;x(W.map(jn)),E("idle")}catch(W){if(H)return;x([]),L(Cs(W)),E("error")}})(),()=>{H=!0}},[N,e,R]);const p=a.useCallback(()=>{m==null||m(),h&&Qn(h)},[h,m]),f=a.useCallback(async H=>{await N.createAgent(H.definition.ref,{invocationName:H.invocationName}),u==null||u(H),l&&Qn(l)},[N,u,l]),T=a.useCallback(()=>{A(H=>H+1)},[]);return n.jsx(Ts,{open:e,onClose:p,onStart:f,agentDefinitions:o,definitionsState:S,definitionsError:O,onRetryDefinitions:T,embedded:w})},zr=e=>"agentDefinitionsUrl"in e,Is=e=>zr(e)?n.jsx(Gr,{...e}):n.jsx(Ts,{...e}),qr=({open:e,onClose:t})=>{const s=a.useId(),r=a.useId();return n.jsxs(c.Modal,{open:e,closeHandler:t,className:"archive-agent-confirm",children:[n.jsx(c.Modal.Header,{className:"archive-agent-confirm__header",children:n.jsx(c.Modal.Title,{id:s,children:Aa})}),n.jsxs(c.Modal.Body,{className:"archive-agent-confirm__body",children:[n.jsx("div",{role:"alertdialog","aria-labelledby":s,"aria-describedby":r,children:n.jsx("p",{id:r,className:"archive-agent-confirm__lead",children:Na})}),n.jsx("div",{className:"archive-agent-confirm__actions",children:n.jsx(c.Button,{variant:"secondary",size:"S",onClick:t,children:"Close"})})]})]})},Vr=3,Kr=56,Yr=e=>e.archivedAt?"archived":e.status===y.paused?"paused":null,Jr=e=>{if(e==="archived")return Qs;if(e==="paused")return it[y.paused].statusIcon},Wr=({column:e,overlayIcon:t,label:s})=>{const r=t??e.statusIcon;return r?n.jsx("span",{className:"agent-view__status-indicator",children:n.jsx(c.Icon,{name:r.name,size:16,color:r.color,className:J({"agent-view__progress-icon--spinning":r.spin}),screenReaderText:s})}):n.jsx("span",{className:J("agent-view__dot",{[`agent-view__dot--${e.dotModifier}`]:e.dotModifier}),children:n.jsx(c.Dot,{colour:e.dotColour,label:s})})},Os=({agent:e,agentName:t,column:s,isExpanded:r,isLoading:i,checklist:h,error:l,canArchive:m,canUnarchive:u=!1,canDelete:w=!1,onToggle:_,onViewAgent:N,onArchive:o,onUnarchive:x,onDelete:S})=>{const{id:E,invocation_name:O}=e,L=`agent-card-${E}-header`,R=`agent-card-${E}-progress`,A=Yr(e),p=Jr(A);return n.jsx("li",{className:J("agent-view__card",{"agent-view__card--expanded":r,"agent-view__card--paused":A==="paused","agent-view__card--archived":A==="archived","agent-view__card--view-only":!e.usable}),children:n.jsxs(c.Card,{spacing:"dense",children:[n.jsx("button",{type:"button",className:"agent-view__card-toggle","aria-expanded":r,"aria-controls":R,"aria-label":O,id:L,onClick:()=>_(E),children:n.jsxs("div",{className:"agent-view__card-content",children:[n.jsx(Wr,{column:s,overlayIcon:p}),n.jsx("span",{className:"agent-view__card-invocation-name",children:O}),n.jsx("span",{className:"agent-view__card-agent-name",children:t}),A==="paused"?n.jsx("span",{className:"agent-view__card-state-pill",children:"Paused"}):null,A==="archived"?n.jsx("span",{className:"agent-view__card-state-pill",children:"Archived"}):null,e.usable?null:n.jsx("span",{className:"agent-view__card-state-pill",children:"View only"}),n.jsx(c.Icon,{name:r?"chevron-up":"chevron-down",size:16,className:"agent-view__card-chevron"})]})}),r&&n.jsxs("div",{id:R,"aria-labelledby":L,className:"agent-view__card-progress",children:[i&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(c.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:rt}),n.jsx("span",{children:rt})]}),!i&&l&&n.jsx("p",{className:"agent-view__progress-error",role:"alert",children:l}),!i&&!l&&h!==null&&n.jsx(Ma,{checklist:h}),!i&&!l&&h===null&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(c.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:rt}),n.jsx("span",{children:rt})]}),n.jsxs("div",{className:"agent-view__card-actions",children:[m?n.jsx(c.Button,{variant:"secondary",size:"S",iconLeftName:"archive",iconLeftScreenReaderText:"Archive",onClick:()=>o==null?void 0:o(e),children:"Archive"}):u?n.jsx(c.Button,{variant:"secondary",size:"S",onClick:()=>x==null?void 0:x(e),children:"Unarchive"}):w?n.jsx(c.Button,{variant:"secondary-destructive",size:"S",onClick:()=>S==null?void 0:S(e),children:"Delete"}):n.jsx("span",{}),u&&w?n.jsx(c.Button,{variant:"secondary-destructive",size:"S",onClick:()=>S==null?void 0:S(e),children:"Delete"}):null,n.jsx(c.Button,{variant:"secondary",size:"S",onClick:()=>N==null?void 0:N(e),children:"View agent"})]})]})]})})},Xr=()=>n.jsx("ul",{className:"agent-view__card-list","aria-hidden":"true",children:Array.from({length:Vr},(e,t)=>n.jsx("li",{className:"agent-view__card agent-view__card--skeleton",children:n.jsx(c.Skeleton,{className:"agent-view__card-skeleton",width:"100%",height:Kr})},t))}),es=({column:e,agents:t,expandedAgentId:s,loadingAgentId:r,checklistByInvocationId:i,errorByAgentId:h,definitionNameByRef:l,onToggleAgent:m,onViewAgent:u,onArchiveAgent:w,canArchive:_,isLoading:N=!1})=>n.jsxs("section",{className:"agent-view__column","aria-label":e.title,children:[n.jsxs("div",{className:"agent-view__column-header",children:[n.jsx(c.Heading,{level:4,children:e.title}),n.jsx("span",{className:"agent-view__column-count",children:N?0:t.length})]}),N?n.jsx(Xr,{}):n.jsx("ul",{className:"agent-view__card-list",children:t.map(o=>n.jsx(Os,{agent:o,agentName:en(o,l),column:e,isExpanded:s===o.id,isLoading:r===o.id,checklist:i[o.invocation_id]??null,error:h[o.id]??null,canArchive:_&&!o.archivedAt&&o.usable,onToggle:m,onViewAgent:u,onArchive:w},o.id))})]}),en=(e,t)=>t.get(e.agent_definition_ref)??e.agent_definition_ref.replace(/_/g," "),Zr=({jwt:e,headers:t,agentDefinitionsUrl:s,agentsUrl:r,agentUrl:i,agentChecklistUrl:h,agentResourcesUrl:l,agentTimelineUrl:m,agentChatUrl:u,agentConversationUrl:w,pauseAgentUrl:_,resumeAgentUrl:N,archiveAgentUrl:o,unarchiveAgentUrl:x,enableUpload:S,adminMode:E=!1,showHeader:O=!1,institutions:L,usePusherToRepoll:R=!1,pusherChannelPrefix:A=Sn,pusherKey:p,pusherCluster:f,subscribeToPusher:T,selectedAgent:H=null,agentIdToOpenOnMount:W,scope:lt=is})=>{var Ue;const ze=a.useMemo(()=>({agentDefinitions:s,agents:r,agent:i,agentChecklist:h,...l?{agentResources:l}:{},...m?{agentTimeline:m}:{},agentChat:u,agentConversation:w,...o?{archiveAgent:o}:{},...x?{unarchiveAgent:x}:{}}),[s,r,i,h,l,m,u,w,o,x]),[Y,te]=a.useState(H),re=Y?(Ue=L==null?void 0:L.find(d=>d.applicationId===Y.application_id))==null?void 0:Ue.applicationUrl:void 0,de=a.useMemo(()=>{const d={...t??{}};return re?d[Be.arborApplicationUrl]=re:delete d[Be.arborApplicationUrl],d},[t,re]),{agents:P,agentDefinitions:he,loadState:Q,loadError:k,reload:U,refresh:j,fetchAgentChecklist:D,createAgent:$,archiveAgent:V,unarchiveAgent:ge,deleteAgent:Ee,removeAgent:St,replaceAgent:qe}=Ss({jwt:e,headers:de,urls:ze,scope:lt}),[jt,Ve]=a.useState(!1),[Se,je]=a.useState(null),[K,Re]=a.useState(null),[ne,Rt]=a.useState({}),[Te,Ie]=a.useState({}),[fe,ie]=a.useState([]),[se,rn]=a.useState([]),[z,ot]=a.useState(null),[Oe,Tt]=a.useState(!1),[It,Ke]=a.useState(null),[Ot,ct]=a.useState(!1),[ve,ut]=a.useState(null),[Ye,Lt]=a.useState(!1),[dt,Je]=a.useState(null),[me,ht]=a.useState(null),[Le,xe]=a.useState(!1),[Pt,We]=a.useState(null),[Mt,Ut]=a.useState(!1),Xe=a.useRef(!1);a.useEffect(()=>{te(d=>{if(!d)return null;const b=P.find(C=>C.id===d.id||C.invocation_id===d.invocation_id||C.invocation_id===d.id);return b||(Q==="loading"?d:null)})},[P,Q]),a.useEffect(()=>{if(!W||Xe.current||Q==="loading")return;Xe.current=!0;const d=P.find(({id:b})=>b===W);if(d){te(d);return}Ut(!0)},[W,P,Q]);const Pe=a.useMemo(()=>{const d=new Set(P.map(C=>C.application_id)),b=new Map((L??[]).map(C=>[C.applicationId,C.name]));return[...d].sort((C,ee)=>(b.get(C)??C).localeCompare(b.get(ee)??ee)).map(C=>({value:C,label:b.get(C)??C}))},[P,L]),le=a.useMemo(()=>new Map(he.map(d=>[d.ref,d.display_name])),[he]),Dt=a.useMemo(()=>[...new Set(P.map(b=>en(b,le)))].sort((b,C)=>b.localeCompare(C)).map(b=>({value:b,label:b})),[P,le]),Me=a.useMemo(()=>P.filter(d=>!(fe.length>0&&!fe.includes(d.application_id)||se.length>0&&!se.includes(en(d,le)))),[P,le,se,fe]),Ht=Pe.length>1,Ze=Dt.length>1,ln=Ht||Ze;a.useEffect(()=>{const d=window.setInterval(()=>{j()},6e4);return()=>{window.clearInterval(d)}},[j]),a.useEffect(()=>{if(P.length===0)return;let d=!1;return(async()=>{const b=await Promise.allSettled(P.map(async C=>{const ee=await D(C.invocation_id);return{agentId:C.id,invocationId:C.invocation_id,checklist:ee.checklist}}));d||(Rt(C=>{const ee={...C};let De=!1;for(const pe of b){if(pe.status!=="fulfilled")continue;const{invocationId:Ae,checklist:X}=pe.value;JSON.stringify(C[Ae])!==JSON.stringify(X)&&(ee[Ae]=X,De=!0)}return De?ee:C}),Ie(C=>{const ee={...C};let De=!1;return b.forEach((pe,Ae)=>{pe.status==="rejected"&&ee[P[Ae].id]!==Qt&&(ee[P[Ae].id]=Qt,De=!0)}),De?ee:C}))})(),()=>{d=!0}},[P,D]);const gt=a.useCallback(async d=>{if(!ne[d.invocation_id]){Re(d.id),Ie(b=>{const C={...b};return delete C[d.id],C});try{const b=await D(d.invocation_id);Rt(C=>({...C,[d.invocation_id]:b.checklist}))}catch{Ie(b=>({...b,[d.id]:Qt}))}finally{Re(b=>b===d.id?null:b)}}},[D,ne]),Qe=a.useCallback(d=>{if(Se===d){je(null);return}const b=P.find(({id:C})=>C===d);b&&(je(d),gt(b))},[P,Se,gt]),et=a.useMemo(()=>Me.filter(d=>!!d.archivedAt),[Me]),we=a.useMemo(()=>Me.filter(d=>!d.archivedAt),[Me]),mt=a.useMemo(()=>{const d={};for(const b of we){const C=vn(b,ne[b.invocation_id]);(d[C]??(d[C]=[])).push(b)}return d},[we,ne]),on=Q==="loading"&&P.length===0,pt=we.length>0&&we.some(d=>ne[d.invocation_id]===void 0&&Te[d.id]===void 0),$t=on||pt,_t=a.useCallback(d=>{te(d)},[]),Bt=a.useCallback(d=>{Ke(null),ot(d)},[]),Ft=a.useCallback(()=>{Oe||(Ke(null),ot(null))},[Oe]),Gt=a.useCallback(async()=>{if(z){Tt(!0),Ke(null),Ie(d=>{const b={...d};return delete b[z.id],b});try{await V(z.invocation_id),te(d=>(d==null?void 0:d.id)===z.id?null:d),je(z.id),ct(!0),ot(null)}catch{Ke(Nn)}finally{Tt(!1)}}},[z,V]),zt=a.useCallback(d=>{Je(null),ut(d)},[]),cn=a.useCallback(()=>{Ye||(Je(null),ut(null))},[Ye]),ft=a.useCallback(async()=>{if(ve){Lt(!0),Je(null);try{await ge(ve.invocation_id),ut(null)}catch{Je(kn)}finally{Lt(!1)}}},[ve,ge]),un=z?vn(z,ne[z.invocation_id])!==y.complete:!1,tt=a.useCallback(async d=>{const b=await $(d);te(b),Ve(!1)},[$]),qt=a.useCallback(d=>{We(null),ht(d)},[]),Vt=a.useCallback(()=>{Le||(We(null),ht(null))},[Le]),dn=a.useCallback(async()=>{if(me){xe(!0),We(null);try{await Ee(me.invocation_id),te(d=>(d==null?void 0:d.id)===me.id?null:d),ht(null)}catch(d){We(Es(d))}finally{xe(!1)}}},[me,Ee]),vt=a.useCallback(()=>{te(null)},[]),Kt={expandedAgentId:Se,loadingAgentId:K,checklistByInvocationId:ne,errorByAgentId:Te,definitionNameByRef:le,onToggleAgent:Qe,onViewAgent:_t,onArchiveAgent:Bt,canArchive:!!o};return n.jsxs("div",{className:"agent-view-frontend agent-view",children:[O&&n.jsxs("div",{className:"agent-view__header",children:[n.jsx(c.Heading,{level:1,children:"Agents"}),n.jsx(c.Button,{variant:"primary",size:"S",iconLeftName:"sparkles",iconLeftScreenReaderText:"Start an agent",onClick:()=>Ve(!0),children:"Start an agent"})]}),P.length>0&&ln&&n.jsxs("div",{className:"agent-view__filters",children:[Ht&&n.jsxs("div",{className:"agent-view__filter",children:[n.jsx("label",{className:"agent-view__filter-label",htmlFor:"agent-view-institution-filter",children:"Institution"}),n.jsx(c.Combobox,{id:"agent-view-institution-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All institutions",options:Pe,value:fe,onValueChange:ie,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear institutions"})]}),Ze&&n.jsxs("div",{className:"agent-view__filter",children:[n.jsx("label",{className:"agent-view__filter-label",htmlFor:"agent-view-agent-filter",children:"Agent"}),n.jsx(c.Combobox,{id:"agent-view-agent-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All agents",options:Dt,value:se,onValueChange:rn,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear agents"})]})]}),Q==="error"?n.jsxs("div",{className:"agent-view__state agent-view__state--error",role:"alert",children:[n.jsx(c.Icon,{name:"triangle-alert",size:24,color:"var(--color-semantic-destructive-600)"}),n.jsx("p",{className:"agent-view__state-message",children:k??rs}),n.jsx(c.Button,{variant:"secondary",size:"S",onClick:U,children:"Try again"})]}):$t?n.jsx("div",{className:"agent-view__board","aria-busy":"true","aria-live":"polite",children:Hn.map(d=>n.jsx(es,{column:it[d],agents:[],isLoading:!0,...Kt},d))}):P.length===0?n.jsx(ja,{}):n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"agent-view__board",children:Hn.map(d=>n.jsx(es,{column:it[d],agents:mt[d]??[],...Kt},d))}),et.length>0?n.jsxs("details",{className:"agent-view__archived",open:Ot,onToggle:d=>{ct(d.currentTarget.open)},children:[n.jsxs("summary",{className:"agent-view__archived-summary",children:[n.jsx(c.Heading,{level:4,children:"Archived"}),n.jsx("span",{className:"agent-view__column-count",children:et.length})]}),n.jsx("ul",{className:"agent-view__card-list agent-view__archived-list",children:et.map(d=>n.jsx(Os,{agent:d,agentName:en(d,le),column:it[vn(d,ne[d.invocation_id])],isExpanded:Se===d.id,isLoading:K===d.id,checklist:ne[d.invocation_id]??null,error:Te[d.id]??null,canArchive:!1,canUnarchive:!!x&&d.usable,canDelete:E&&d.usable,onToggle:Qe,onViewAgent:_t,onUnarchive:zt,onDelete:qt},d.id))})]}):null]}),Y&&n.jsx(Rs,{agent:Y,invocationId:Y.invocation_id,open:!0,jwt:e,headers:de,agentUrl:i,agentChecklistUrl:h,agentResourcesUrl:l,agentTimelineUrl:m,agentChatUrl:u,agentConversationUrl:w,pauseAgentUrl:_,resumeAgentUrl:N,archiveAgentUrl:o,unarchiveAgentUrl:x,enableUpload:S,adminMode:E,initialChecklist:ne[Y.invocation_id]??null,usePusherToRepoll:R,pusherChannelPrefix:A,pusherKey:p,pusherCluster:f,subscribeToPusher:T,onClose:vt,onAgentUpdated:qe,onArchived:()=>{je(Y.id),ct(!0),j()},onUnarchived:()=>{j()},onDeleted:()=>{St(Y.invocation_id)}},Y.id||Y.invocation_id),n.jsx(cs,{open:!!z,isInProgress:un,isArchiving:Oe,error:It,onCancel:Ft,onConfirm:()=>{Gt()}}),n.jsx(ds,{open:!!ve,isUnarchiving:Ye,error:dt,onCancel:cn,onConfirm:()=>{ft()}}),n.jsx(us,{open:!!me,isDeleting:Le,error:Pt,onCancel:Vt,onConfirm:()=>{dn()}}),n.jsx(qr,{open:Mt,onClose:()=>Ut(!1)}),n.jsx(Is,{open:jt,onClose:()=>Ve(!1),onStart:tt,agentDefinitions:he})]})},Qr=(e,t)=>{const s=Date.now(),r=t.trim()||e.agent_intent;return{id:`agent-${s}`,invocation_id:`inv-${s}`,agent_definition_ref:e.ref,agent_intent:e.agent_intent,invocation_name:r,application_id:ea,created_by:ta,usable:!0,status:y["generating-a-response"],archivedAt:null,context_ref:null,checklist_ref:null}};exports.AgentMonitorKanban=Zr;exports.AgentServiceClient=an;exports.AgentServiceError=Fe;exports.AgentView=Rs;exports.DEFAULT_PUSHER_CHANNEL_PREFIX=Sn;exports.HttpChatConnector=bs;exports.MESSAGE_TYPE_REPOLL=bn;exports.NewAgentModal=Is;exports.PUSHER_AGENT_MESSAGE_EVENT=ps;exports.REPOLL_TARGET=be;exports.buildAgentFromDefinition=Qr;exports.buildAgentPusherChannel=_s;exports.createHttpChatConnectorFactory=Tn;exports.formatUserFileChatCardText=Ar;exports.mapApiAgent=Ce;exports.mapApiAgentDefinition=jn;exports.mapApiAgentStatus=xs;exports.mapApiAgentTimelineResponse=ks;exports.mapApiChecklistEndpointResponse=sn;exports.mapApiChecklistItem=Rn;exports.mapApiChecklistResponse=xr;exports.mapApiChecklistStatus=ws;exports.mapApiConversationMessages=ys;exports.mapApiOpeningMessage=Et;exports.mapApiResource=As;exports.mapApiResourcesEndpointResponse=Ns;exports.mapApiTripOption=pr;exports.parseConversationContentCaption=wr;exports.parseRepollMessages=fs;exports.useAgentService=Ss;exports.useAgentWorkspace=js;exports.useSubscribeToPusher=vs;
9
+ `):null}},Kn=e=>{try{return JSON.parse(e)}catch{return}};function Er(e,t){const s=new FormData;s.append("body",JSON.stringify(e));for(const r of t)s.append("files",r,r.name);return s}const Sr={id:ss,author:ge.agent,text:"Type a question or upload a file. You can ask it how it's progressing, or send an instruction and it'll act on it."};let Yn=0;const jr=e=>(Yn+=1,`${e}-${Date.now()}-${Yn}`),Rr=e=>{const t=e.destination?` to ${e.destination}`:"";return`Let's get started on ${e.tripName.trim()||e.destination.trim()||"this task"}${t}. What will you do first?`};class bs{constructor(t,s,r={}){this.seededChecklist=[],this.client=t,this.agentId=s,this.chatId=r.chatId??s,this.opening=r.openingMessage??Sr,this.model=r.model}openingMessage(){return this.opening}async bootstrapConversation(){const t=await this.client.getConversation(this.chatId),s=ks(t.messages);return s.length===0?[this.opening]:s}async start(t){return{...await this.exchange(Rr(t)),phase:B.running}}sendMessage(t,s,r){return this.exchange(t,s,r)}async pause(){await this.client.pauseAgent(this.agentId)}async resume(){await this.client.resumeAgent(this.agentId)}seedChecklist(t){this.seededChecklist=t}async exchange(t,s,r){var N;const i=[{role:gr.user,content:t}];let h="",l=null,m;const d=await this.client.chat(this.agentId,{messages:i,chat_id:this.chatId,...this.model?{model:this.model}:{},moderation_enabled:!0,meta:{feature_id:"agent_view",source:"agent_view_frontend"}},{...s&&s.length>0?{uploadFiles:s}:{},onEvent:o=>{var E;const x=o.message;if((x==null?void 0:x.role)==="assistant"&&x.tool_calls&&x.tool_calls.length>0){const O=Ce.thinkingPhrasesFromToolCalls(x.tool_calls);for(const L of O)L.phrase!==l&&(l=L.phrase,(E=r==null?void 0:r.onThinking)==null||E.call(r,L))}const S=x==null?void 0:x.content;S&&(h=o.is_final?S:h+S),o.is_final&&(m=o)}}),w=m??d,_={id:w.event_id||jr("msg-agent"),author:ge.agent,text:h||w.message.content||"",...(N=w.follow_up_prompts)!=null&&N.length?{followUpPrompts:w.follow_up_prompts}:{}};try{const o=await this.client.getAgentChecklist(this.agentId),{checklist:x}=tn(this.agentId,o);return x.length===0?{message:_}:(this.seededChecklist=x,{message:_,checklist:x})}catch{return{message:_,...this.seededChecklist.length?{checklist:this.seededChecklist}:{}}}}}const Tn=(e,t)=>s=>{var r,i;return new bs(e,s.invocation_id,{model:t==null?void 0:t.model,chatId:((r=t==null?void 0:t.resolveChatId)==null?void 0:r.call(t,s))??(t==null?void 0:t.chatId)??s.invocation_id,openingMessage:((i=t==null?void 0:t.resolveOpeningMessage)==null?void 0:i.call(t,s))??(t==null?void 0:t.openingMessage)})},Cs=e=>e instanceof Be?e.message:e instanceof TypeError?"Network error while contacting the agent service.":e instanceof Error&&e.message?e.message:rs,Es=e=>{if(e instanceof Be){if(e.status===403)return ha;if(e.status===409)return ga;if(e.status===404)return ma}return ua},Tr=e=>{const t={};for(const s of e){const r=Ot(s);if(!r)continue;const i=s.invocation_id??s.id;t[i]=r,t[s.id]=r}return t},Ir=e=>JSON.stringify(e),Wt=(e,t)=>JSON.stringify(e)===JSON.stringify(t),Ss=e=>{const{jwt:t,headers:s,urls:r,scope:i=is}=e,h=JSON.stringify(s??{}),l=Ir(r),m=a.useMemo(()=>({scope:i}),[i]),d=a.useMemo(()=>new nn({token:t,headers:s,urls:r}),[t,l]);a.useLayoutEffect(()=>{d.setHeaders(s)},[d,h]);const[w,_]=a.useState([]),[N,o]=a.useState([]),[x,S]=a.useState({}),[E,O]=a.useState("loading"),[L,R]=a.useState(null),[A,p]=a.useState(0),f=a.useRef(0),T=a.useCallback((y,P)=>{const j=y.map(be),F=P.map(jn),H=Tr(y);_(q=>Wt(q,j)?q:j),o(q=>Wt(q,F)?q:F),S(q=>Wt(q,H)?q:H),O("idle"),R(null)},[]);a.useEffect(()=>{const y=++f.current;O("loading"),R(null),(async()=>{try{const[P,j]=await Promise.all([d.listAgents(m),d.listAgentDefinitions()]);if(y!==f.current)return;T(P,j)}catch(P){if(y!==f.current)return;_([]),o([]),S({}),O("error"),R(Cs(P))}})()},[T,d,m,A]);const D=a.useCallback(()=>{p(y=>y+1)},[]),X=a.useCallback(async()=>{const y=++f.current;try{const[P,j]=await Promise.all([d.listAgents(m),d.listAgentDefinitions()]);if(y!==f.current)return;T(P,j)}catch{}},[T,d,m]),lt=a.useCallback(async y=>{const[P,j]=await Promise.all([d.getAgentChecklist(y),d.getAgent(y).catch(()=>null)]);return tn(y,P,j??void 0)},[d]),J=a.useCallback(async y=>d.listAllAgentResources(y),[d]),Z=a.useCallback(async({definition:y,invocationName:P})=>{const j=await d.createAgent(y.ref,{invocationName:P}),F=await d.getAgent(j.id),H=be(F),q=Ot(F);return _(pe=>[H,...pe]),q&&S(pe=>({...pe,[H.invocation_id]:q,[H.id]:q})),H},[d]),oe=a.useCallback(async y=>{const P=await d.archiveAgent(y),j=be(P);return _(F=>F.map(H=>H.id===j.id||H.id===y||H.invocation_id===y?j:H)),j},[d]),me=a.useCallback(async y=>{const P=await d.unarchiveAgent(y),j=be(P);return _(F=>F.map(H=>H.id===j.id||H.id===y||H.invocation_id===y?j:H)),j},[d]),M=a.useCallback(y=>{_(P=>P.filter(j=>j.id!==y&&j.invocation_id!==y))},[]),re=a.useCallback(y=>{_(P=>{const j=P.map(F=>F.id===y.id||F.invocation_id===y.invocation_id?{...F,...y}:F);return Wt(P,j)?P:j})},[]),se=a.useCallback(async y=>{await d.deleteAgent(y),M(y)},[d,M]),ce=a.useMemo(()=>Tn(d,{resolveOpeningMessage:y=>x[y.invocation_id]??x[y.id]}),[d,x]);return{agents:w,agentDefinitions:N,loadState:E,loadError:L,reload:D,refresh:X,fetchAgentChecklist:lt,fetchAgentResources:J,createAgent:Z,archiveAgent:oe,unarchiveAgent:me,deleteAgent:se,removeAgent:M,replaceAgent:re,chatConnector:ce}},Or=e=>JSON.stringify(e),js=e=>{const{agent:t,jwt:s,headers:r,urls:i,chatId:h}=e,l=JSON.stringify(r??{}),m=Or(i),d=a.useMemo(()=>new nn({token:s,headers:r,urls:{agent:i.agentUrl,agentChecklist:i.agentChecklistUrl,...i.agentResourcesUrl?{agentResources:i.agentResourcesUrl}:{},...i.agentTimelineUrl?{agentTimeline:i.agentTimelineUrl}:{},agentChat:i.agentChatUrl,agentConversation:i.agentConversationUrl,...i.pauseAgentUrl?{pauseAgent:i.pauseAgentUrl}:{},...i.resumeAgentUrl?{resumeAgent:i.resumeAgentUrl}:{},...i.archiveAgentUrl?{archiveAgent:i.archiveAgentUrl}:{},...i.unarchiveAgentUrl?{unarchiveAgent:i.unarchiveAgentUrl}:{}}}),[s,m]);a.useLayoutEffect(()=>{d.setHeaders(r)},[d,l]);const w=a.useCallback(async p=>be(await d.getAgent(p)),[d]),_=a.useCallback(async p=>{const[f,T]=await Promise.all([d.getAgentChecklist(p),d.getAgent(p).catch(()=>null)]);return tn(p,f,T??void 0)},[d]),N=a.useCallback(async p=>d.listAllAgentResources(p),[d]),o=a.useCallback(async p=>d.getAgentContext(p),[d]),x=a.useCallback(async(p,f)=>d.getAgentResourceHtml(p,f),[d]),S=a.useCallback(async p=>{const f=await d.getAgentTimeline(p);return ys(f)},[d]),E=a.useCallback(async(p,f)=>{await d.updateAgent(p,{invocationName:f})},[d]),O=a.useCallback(async p=>be(await d.archiveAgent(p)),[d]),L=a.useCallback(async p=>be(await d.unarchiveAgent(p)),[d]),R=a.useCallback(async p=>{await d.deleteAgent(p)},[d]);return{connector:a.useMemo(()=>Tn(d,{chatId:h??t.invocation_id})(t),[d,t.invocation_id,h]),fetchAgent:w,fetchAgentChecklist:_,fetchAgentContext:o,fetchAgentResources:N,fetchAgentResourceHtml:x,fetchAgentTimeline:S,updateAgentInvocationName:E,archiveAgent:O,unarchiveAgent:L,deleteAgent:R}},Lr=3e4,Pr=(e,t)=>{const s=e.hasRunBefore?t||"This trip":e.tripName.trim()||"A new trip",r=e.destination?` to ${e.destination}`:"",i=e.hasRunBefore?" It has run before.":"";return`${s}${r}.${i}`.trim()},Jn=e=>{switch(e){case k.paused:return B.paused;case k.complete:return B.complete;default:return B.running}},An=e=>e===k.paused,Wn=(e,t)=>{t([Ae(e)])},Mr=(e,t)=>e.length===t.length&&e.every((s,r)=>{const i=t[r];return i!==void 0&&s.id===i.id&&s.text===i.text}),Rs=({agent:e,invocationId:t,open:s,onClose:r,jwt:i,headers:h,agentUrl:l,agentChecklistUrl:m,agentResourcesUrl:d,agentTimelineUrl:w,agentChatUrl:_,agentConversationUrl:N,pauseAgentUrl:o,resumeAgentUrl:x,archiveAgentUrl:S,unarchiveAgentUrl:E,chatId:O,enableUpload:L,adminMode:R=!1,initialBrief:A,initialPhase:p,initialChecklist:f,usePusherToRepoll:T=!1,pusherChannelPrefix:D=Sn,pusherKey:X="",pusherCluster:lt="",subscribeToPusher:J,onArchived:Z,onUnarchived:oe,onDeleted:me,onAgentUpdated:M})=>{const[re,se]=a.useState(O??t),[ce,y]=a.useState("chat"),[P,j]=a.useState(!1),{connector:F,fetchAgent:H,fetchAgentChecklist:q,fetchAgentContext:pe,fetchAgentResources:Fe,fetchAgentResourceHtml:Lt,fetchAgentTimeline:Ge,updateAgentInvocationName:ze,archiveAgent:Ee,unarchiveAgent:Se,deleteAgent:ot}=js({agent:{...e,invocation_id:t},jwt:i,headers:h,chatId:re,urls:{agentUrl:l,agentChecklistUrl:m,agentResourcesUrl:d,agentTimelineUrl:w,agentChatUrl:_,agentConversationUrl:N,pauseAgentUrl:o,resumeAgentUrl:x,archiveAgentUrl:S,unarchiveAgentUrl:E}}),V=a.useRef(F),[W,qe]=a.useState(e.invocation_name),[ct,ve]=a.useState(0),[je,dt]=a.useState(null),[ee,xe]=a.useState(p??(A?B.running:Jn(e.status))),[ae,Q]=a.useState([]),[ut,Ve]=a.useState(0),[sn,Re]=a.useState([]),[an,Ke]=a.useState(!1),[Ye,Te]=a.useState(null),[ht,gt]=a.useState(null),[rn,we]=a.useState(null),[Ie,Oe]=a.useState(!1),[mt,Je]=a.useState(null),[Le,Pe]=a.useState(null),[ln,pt]=a.useState(!1),[Pt,We]=a.useState(null),[ie,Xe]=a.useState(f??null),[Ze,_t]=a.useState(!1),[Mt,ft]=a.useState(null),[Ut,vt]=a.useState(void 0),[Me,Ue]=a.useState(!1),[xt,wt]=a.useState(!1),[on,At]=a.useState(null),[Nt,Dt]=a.useState(!1),[Ht,$t]=a.useState(!1),[Bt,Ft]=a.useState(!1),[cn,yt]=a.useState(!1),[dn,Qe]=a.useState(null),[Gt,zt]=a.useState(!1),[un,et]=a.useState(!1),[qt,u]=a.useState(null),[b,C]=a.useState(!1),[te,_e]=a.useState(!1),[tt,de]=a.useState(null),[kt,ne]=a.useState(null),[Ls,bt]=a.useState(()=>An(e.status)),[Ps,In]=a.useState(e.archivedAt??null),G=!!Ps,Ct=!e.usable,[hn,Et]=a.useState(!1),[Vt,Ms]=a.useState(!1),[Kt,Us]=a.useState(!1),On=a.useRef(hn),Ln=a.useRef(e.invocation_name),nt=a.useRef(e),ue=a.useRef(M),Pn=a.useRef(0),Mn=a.useRef(0),st=a.useRef(0),St=a.useRef(0);ue.current=M,a.useEffect(()=>{In(e.archivedAt??null)},[e.archivedAt]),a.useEffect(()=>{V.current=F},[F]),a.useEffect(()=>{Ln.current=e.invocation_name},[e.invocation_name]),a.useEffect(()=>{nt.current=e},[e]),a.useEffect(()=>{On.current=hn},[hn]),a.useEffect(()=>{se(O??t),y("chat"),j(!1),Q([]),Ve(g=>g+1),dt(null)},[t,O]),a.useEffect(()=>(st.current+=1,vt(void 0),Ue(!1),wt(!1),At(null),()=>{st.current+=1}),[t]),a.useEffect(()=>{bt(An(e.status))},[e.status,t]),a.useEffect(()=>{if(!s||A||G)return;const g=++St.current;return(async()=>{var v;try{const I=await H(t);if(g!==St.current)return;xe(Jn(I.status)),bt(An(I.status)),nt.current=I,(v=ue.current)==null||v.call(ue,I)}catch{}})(),()=>{St.current+=1}},[s,t,A,G,H]),a.useEffect(()=>{qe(e.invocation_name),ve(g=>g+1)},[e.invocation_name]),a.useEffect(()=>{G&&y("timeline")},[G]),a.useEffect(()=>{if(!s||A||G)return;const g=V.current.bootstrapConversation;if(!g){Wn(V.current.openingMessage(),Q);return}let v=!1;return Et(!0),(async()=>{try{const I=await g.call(V.current);if(v)return;Q(I.map(Ae))}catch{v||Wn(V.current.openingMessage(),Q)}finally{v||Et(!1)}})(),()=>{v=!0}},[s,A,G,t,re]);const De=a.useCallback(()=>{const g=++Pn.current;(async()=>{var v,I;try{const Y=await q(t);if(g!==Pn.current)return;Xe(le=>Y.checklist.length===0&&Array.isArray(le)&&le.length>0||JSON.stringify(le)===JSON.stringify(Y.checklist)?le:Y.checklist),ft(null),(I=(v=V.current).seedChecklist)==null||I.call(v,Y.checklist)}catch{}})()},[q,t]),He=a.useCallback(()=>{d&&(async()=>{try{const g=await Fe(t);Re(g),Te(null)}catch{}})()},[d,Fe,t]),fe=a.useCallback(()=>{if(!w)return;const g=++Mn.current;(async()=>{try{const v=await Ge(t);if(g!==Mn.current)return;Pe(I=>JSON.stringify(I)===JSON.stringify(v)?I:v),We(null)}catch{}})()},[w,Ge,t]),jt=a.useCallback(g=>{const v=V.current.bootstrapConversation;v&&(async()=>{try{const I=await v.call(V.current);if(On.current)return;const Y=I.map(Ae);let le=!1;Q(at=>Mr(at,Y)?at:(le=!0,Y)),le&&(g!=null&&g.refreshSidePanelsOnChange)&&(De(),fe())}catch{}})()},[De,fe]),Ds=a.useCallback(g=>{switch(g){case ke.checklist:De();return;case ke.resources:He();return;case ke.chat:jt();return;case ke.timeline:fe();return;case ke.all:default:De(),He(),jt(),fe()}},[De,jt,He,fe]),Hs=vs({enabled:!!(s&&T&&!J),key:X,cluster:lt,isAdmin:R}),$s=J??Hs,Un=lr({enabled:s&&T,channelPrefix:D,agentId:e.id||t,subscribeToPusher:$s,onRepoll:Ds});a.useEffect(()=>{if(!s||A||G||Un)return;const g=window.setInterval(()=>{jt({refreshSidePanelsOnChange:!0})},Lr);return()=>{window.clearInterval(g)}},[s,A,G,Un,t,re,jt]);const Yt=a.useCallback(g=>{var v,I;if(g&&g.length>0){Xe(g),(I=(v=V.current).seedChecklist)==null||I.call(v,g);return}De()},[De]),gn=a.useCallback(g=>{Yt(g.checklist),g.phase&&xe(g.phase),He(),fe()},[Yt,He,fe]);a.useEffect(()=>{var g,v;!s||A||f&&f.length>0&&((v=(g=V.current).seedChecklist)==null||v.call(g,f))},[s,A,f]),a.useEffect(()=>{if(!s||A)return;let g=!1;return _t(v=>f!=null&&f.length?!1:v||ie===null||ie.length===0),ft(null),(async()=>{var v,I;try{const Y=await q(t);if(g)return;f!=null&&f.length||(Xe(Y.checklist),(I=(v=V.current).seedChecklist)==null||I.call(v,Y.checklist))}catch{!g&&!(f!=null&&f.length)&&ft(Xt)}finally{g||_t(!1)}})(),()=>{g=!0}},[s,t,A,f,q]),a.useEffect(()=>{if(!s||!d)return;let g=!1;return Ke(!0),Te(null),(async()=>{try{const v=await Fe(t);g||Re(v)}catch{g||Te(sa)}finally{g||Ke(!1)}})(),()=>{g=!0}},[s,t,d,Fe]);const Bs=a.useCallback(()=>{gt(null),we(null),Je(null),Oe(!1)},[]),Fs=a.useCallback(g=>{if(g.misRecordUrl){window.open(g.misRecordUrl,"_blank","noopener,noreferrer");return}gt(g),we(null),Je(null),Oe(!0),(async()=>{try{const v=await Lt(t,g.id);we(v)}catch{Je(aa)}finally{Oe(!1)}})()},[Lt,t]);a.useEffect(()=>{if(!s||!w)return;let g=!1;return pt(v=>v||Le===null),We(null),(async()=>{try{const v=await Ge(t);g||Pe(v)}catch{g||We(as)}finally{g||pt(!1)}})(),()=>{g=!0}},[s,t,w,Ge]),a.useEffect(()=>{if(!s||!A)return;let g=!1;const v={id:`user-brief-${Date.now()}`,author:ge.user,text:Pr(A,Ln.current)};return(async()=>{const I=await V.current.start(A);g||(Q([Ae(V.current.openingMessage()),Ae(v),Ae(I.message)]),Yt(I.checklist),xe(I.phase??B.running),He(),fe())})(),()=>{g=!0}},[s,A,t,Yt,He,fe]);const mn=O??t,Jt=Le==null?void 0:Le.chatSessions,Dn=Jt!=null&&Jt.length?Jt.reduce((g,v)=>Date.parse(v.timestamp)<Date.parse(g.timestamp)?v:g).sessionId:void 0,pn=a.useCallback(()=>{y("chat"),j(!1),re!==mn&&(se(mn),Q([]),Ve(g=>g+1))},[re,mn]),Gs=a.useCallback(g=>{if(g===Dn){pn();return}se(g),j(!0),y("chat"),Q([]),Ve(v=>v+1)},[Dn,pn]),zs=a.useCallback(async()=>{var g;ne(null),Dt(!0);try{await V.current.pause(),St.current+=1,xe(B.paused),bt(!0);const v={...nt.current,status:k.paused};nt.current=v,(g=ue.current)==null||g.call(ue,v)}catch{ne(ra)}finally{Dt(!1)}},[]),qs=a.useCallback(async()=>{var v;ne(null),$t(!0);let g=!1;try{await V.current.resume(),g=!0,St.current+=1,xe(B.running),bt(!1);const I={...nt.current,status:k["generating-a-response"]};nt.current=I,(v=ue.current)==null||v.call(ue,I),Et(!0);const Y={id:`wake-${Date.now()}`,author:ge.user,text:$n};Q(at=>[...at,Ae(Y)]);const le=await V.current.sendMessage($n);Q(at=>[...at,Ae(le.message)]),gn(le)}catch{ne(g?va:fa)}finally{$t(!1),Et(!1)}},[gn]),Vs=a.useCallback(async()=>{ne(null),Qe(null),Ft(!0);try{await Ee(t),yt(!1),Z==null||Z(),r()}catch{Qe(Nn),ne(Nn)}finally{Ft(!1)}},[t,Ee,Z,r]),Ks=a.useCallback(async()=>{ne(null),u(null),zt(!0);try{await Se(t),In(null),xe(B.paused),bt(!0),y("chat"),et(!1),oe==null||oe()}catch{u(yn),ne(yn)}finally{zt(!1)}},[t,Se,oe]),Ys=a.useCallback(async()=>{ne(null),de(null),C(!0);try{await ot(t),_e(!1),me==null||me(),r()}catch(g){de(Es(g))}finally{C(!1)}},[t,ot,me,r]),Js=a.useCallback(g=>{const v=g.trim(),I=W;if(dt(null),!v){ve(Y=>Y+1);return}v!==I&&(qe(v),(async()=>{try{await ze(t,v)}catch{qe(I),ve(Y=>Y+1),dt(xa)}})())},[W,t,ze]),Ws=a.useCallback(()=>{if(!R||Me||xt)return;const g=++st.current;wt(!0),At(null),(async()=>{try{const v=await pe(t);if(st.current!==g)return;vt(v),Ue(!0)}catch{st.current===g&&At(na)}finally{st.current===g&&wt(!1)}})()},[R,Me,xt,pe,t]),Xs=ie;return n.jsxs(n.Fragment,{children:[n.jsxs(c.Modal,{open:s,closeHandler:r,hideCloseButton:!0,className:"agent-workspace",children:[n.jsxs(c.Modal.Header,{className:"agent-workspace__header",children:[n.jsxs("div",{className:"agent-workspace__header-title",children:[n.jsx("span",{className:"agent-workspace__header-avatar","aria-hidden":"true",children:n.jsx(c.Icon,{name:"ask-arbor",size:24})}),n.jsx(c.Modal.Title,{children:G?n.jsx("span",{className:"agent-workspace__header-name",children:W}):n.jsx(c.EditableText,{className:"agent-workspace__header-name",text:W,onEditSave:Js},ct)}),n.jsx("span",{className:K("agent-workspace__phase",`agent-workspace__phase--${ee}`),children:ba[ee]}),G?n.jsx("span",{className:"agent-workspace__phase agent-workspace__phase--archived",children:"Archived"}):null,je&&n.jsx("p",{className:"agent-workspace__error agent-workspace__name-error",role:"alert",children:je})]}),n.jsxs("div",{className:"agent-workspace__header-actions",children:[n.jsx(c.Button,{variant:Vt?"secondary":"primary",size:"S",iconLeftName:"clipboard-list",iconLeftScreenReaderText:"Toggle checklist","aria-pressed":!Vt,onClick:()=>Ms(g=>!g),children:"Checklist"}),n.jsx(c.Button,{variant:Kt?"secondary":"primary",size:"S",iconLeftName:"files",iconLeftScreenReaderText:"Toggle resources","aria-pressed":!Kt,onClick:()=>Us(g=>!g),children:"Resources"}),n.jsx(c.Button,{variant:"secondary",size:"S",iconLeftName:"x",iconLeftScreenReaderText:"Close",onClick:r,children:"Close"})]})]}),n.jsxs(c.Modal.Body,{className:K("agent-workspace__body",{"agent-workspace__body--no-checklist":Vt,"agent-workspace__body--no-resources":Kt}),children:[n.jsxs("section",{className:K("agent-workspace__panel","agent-workspace__panel--chat",{"agent-workspace__panel--timeline":!!w&&(G||ce==="timeline")}),"aria-label":"Agent",children:[n.jsxs("div",{className:"agent-workspace__panel-header",children:[n.jsx(c.Heading,{level:4,children:"Agent"}),o&&!Ct&&!G&&ee===B.running&&n.jsx(c.Button,{className:"agent-workspace__panel-header-action",variant:"secondary-destructive",size:"S",iconLeftName:"circle-x",iconLeftScreenReaderText:"Pause",disabled:Nt,onClick:()=>void zs(),children:Nt?"Pausing…":"Pause agent"}),x&&!Ct&&!G&&ee===B.paused&&Ls&&n.jsx(c.Button,{className:"agent-workspace__panel-header-action",variant:"secondary",size:"S",iconLeftName:"iteration-ccw",iconLeftScreenReaderText:"Resume",disabled:Ht,onClick:()=>void qs(),children:Ht?"Resuming…":"Resume agent"}),S&&!Ct&&!G&&n.jsx(c.Button,{className:"agent-workspace__panel-header-action",variant:"secondary",size:"S",iconLeftName:"archive",iconLeftScreenReaderText:"Archive",onClick:()=>{Qe(null),ne(null),yt(!0)},children:"Archive agent"}),E&&!Ct&&G&&n.jsx(c.Button,{className:"agent-workspace__panel-header-action",variant:"secondary",size:"S",onClick:()=>{u(null),ne(null),et(!0)},children:"Unarchive agent"}),R&&G&&n.jsx(c.Button,{className:"agent-workspace__panel-header-action",variant:"secondary-destructive",size:"S",onClick:()=>{de(null),ne(null),_e(!0)},children:"Delete agent"})]}),kt&&n.jsx("p",{className:"agent-workspace__error agent-workspace__lifecycle-error",role:"alert",children:kt}),w&&!G&&n.jsxs(c.Tabs,{className:"agent-workspace__center-tabs","aria-label":"Center panel",children:[n.jsx(c.Tabs.Item,{active:ce==="chat",tabElementProps:{id:"agent-center-tab-chat",onClick:()=>y("chat")},children:"Chat"}),n.jsx(c.Tabs.Item,{active:ce==="timeline",tabElementProps:{id:"agent-center-tab-timeline",onClick:()=>y("timeline")},children:"Timeline"})]}),w&&!G&&ce==="chat"&&P&&n.jsx("div",{className:"agent-workspace__center-back",children:n.jsx(c.Button,{variant:"tertiary",size:"S",iconLeftName:"arrow-left",iconLeftScreenReaderText:"Back to main chat",onClick:pn,children:"Back to main chat"})}),w&&(G||ce==="timeline")&&n.jsx(nr,{timeline:Le,isLoading:ln,error:Pt,onOpenChatSession:G?void 0:Gs}),!G&&n.jsx("div",{className:"agent-workspace__chat-keep-alive",hidden:!!w&&ce!=="chat",children:n.jsx($a,{connector:F,phase:ee,chatHistory:ae,chatSessionKey:ut,readOnly:Ct,enableUpload:L,onTurn:gn,onAwaitingChange:Et})}),G&&!w&&n.jsx("p",{className:"agent-workspace__timeline-status",role:"status",children:"Chat is not available for archived agents."})]}),!Vt&&n.jsx(Ba,{checklist:Xs,isLoading:Ze,error:Mt,phase:ee,adminMode:R,context:Ut,contextLoaded:Me,contextLoading:xt,contextError:on,onContextSelect:Ws},t),!Kt&&n.jsx(za,{resources:sn,isLoading:an,error:Ye,onOpenResource:Fs}),n.jsx(Fa,{resource:ht,html:rn,isLoading:Ie,error:mt,onClose:Bs})]})]}),n.jsx(cs,{open:cn,isInProgress:ee===B.running||ee===B.paused&&!hs(ie??void 0),isArchiving:Bt,error:dn,onCancel:()=>{Bt||(Qe(null),yt(!1))},onConfirm:()=>{Vs()}}),n.jsx(us,{open:un,isUnarchiving:Gt,error:qt,onCancel:()=>{Gt||(u(null),et(!1))},onConfirm:()=>{Ks()}}),n.jsx(ds,{open:te,isDeleting:b,error:tt,onCancel:()=>{b||(de(null),_e(!1))},onConfirm:()=>{Ys()}})]})},Ur="Unable to load agent definitions. Please try again.",Dr="Unable to start the agent.",Xn="Loading agents…",Hr="Which agent?",$r="Select an agent",Br="Name for this run",Fr="e.g. Year 6 Science Museum trip",Gr="Shown on the board and in the workspace",Zn="new-agent-invocation-name-hint",Ts=({open:e,onClose:t,onStart:s,agentDefinitions:r,definitionsState:i="idle",definitionsError:h=null,onRetryDefinitions:l,embedded:m=!1})=>{const[d,w]=a.useState(void 0),[_,N]=a.useState(""),[o,x]=a.useState(!1),[S,E]=a.useState(null),O=[...r].sort((T,D)=>T.display_name.localeCompare(D.display_name)).map(T=>({value:T.ref,label:T.display_name}));a.useEffect(()=>{e&&(w(void 0),N(""),x(!1),E(null))},[e]);const L=d!==void 0&&_.trim().length>0,R=a.useCallback(T=>{const D=r.find(X=>X.ref===T[0]);D&&w(D)},[r]),A=a.useCallback(async()=>{if(!(!d||!L||o)){x(!0),E(null);try{await s({definition:d,invocationName:_.trim()})}catch(T){E(T instanceof Error?T.message:Dr)}finally{x(!1)}}},[L,d,_,o,s]);if(i==="idle"&&r.length===0||!e)return null;const p=n.jsxs("div",{className:"new-agent__header-title",children:[n.jsx("span",{className:"new-agent__header-avatar","aria-hidden":"true",children:n.jsx(c.Icon,{name:"ask-arbor",size:24})}),m?n.jsx("h2",{className:"new-agent__title",children:"Start an agent"}):n.jsx(c.Modal.Title,{children:"Start an agent"})]});let f;return i==="loading"?f=n.jsxs("div",{className:"new-agent__state","aria-live":"polite",children:[n.jsx(c.Icon,{name:"loader",size:24,color:"var(--color-brand-600)",className:"new-agent__spinner",screenReaderText:Xn}),n.jsx("p",{className:"new-agent__state-message",children:Xn})]}):i==="error"?f=n.jsxs("div",{className:"new-agent__state new-agent__state--error",role:"alert",children:[n.jsx(c.Icon,{name:"triangle-alert",size:24,color:"var(--color-semantic-destructive-600)"}),n.jsx("p",{className:"new-agent__state-message",children:h??Ur}),l?n.jsx(c.Button,{variant:"secondary",size:"S",onClick:l,children:"Try again"}):null]}):f=n.jsxs("form",{className:"new-agent__form","aria-label":"Start an agent",onSubmit:T=>{T.preventDefault(),L&&!o&&A()},children:[n.jsxs("div",{className:"new-agent__type-field",children:[n.jsx("label",{className:"new-agent__type-label",htmlFor:"new-agent-type",children:Hr}),n.jsx(c.SelectDropdown,{id:"new-agent-type",placeholder:$r,options:O,selectedValues:d?[d.ref]:[],onSelectionChange:R})]}),n.jsxs("div",{className:"new-agent__type-field",children:[n.jsx("label",{className:"new-agent__type-label",htmlFor:"new-agent-invocation-name",children:Br}),n.jsx(c.TextInput,{id:"new-agent-invocation-name",value:_,placeholder:Fr,"aria-describedby":Zn,onChange:T=>N(T.target.value)}),n.jsx("p",{className:"new-agent__field-hint",id:Zn,children:Gr})]}),S?n.jsx("p",{className:"new-agent__error",role:"alert",children:S}):null,n.jsx("div",{className:"new-agent__actions",children:n.jsx(c.Button,{type:"submit",variant:"primary",className:K("new-agent__start-button",{"new-agent__start-button--starting":o}),disabled:!L||o,iconLeftName:o?"loader":"sparkles",iconLeftScreenReaderText:o?"Starting":void 0,children:o?"Starting…":"Start"})})]}),m?n.jsxs("div",{className:K("new-agent","new-agent--embedded"),children:[n.jsx("div",{className:"new-agent__header",children:p}),n.jsx("div",{className:"new-agent__body",children:f})]}):n.jsxs(c.Modal,{open:e,closeHandler:t,className:"new-agent",children:[n.jsx(c.Modal.Header,{className:"new-agent__header",children:p}),n.jsx(c.Modal.Body,{className:"new-agent__body",children:f})]})},Qn=e=>{window.location.assign(e)},zr=({open:e,authToken:t,headers:s,agentDefinitionsUrl:r,agentsUrl:i,closeUrl:h,successUrl:l,onClose:m,onStart:d,embedded:w=!1})=>{const _=JSON.stringify(s??{}),N=a.useMemo(()=>new nn({token:t,headers:s,urls:{agentDefinitions:r,agents:i}}),[t,r,i,_]),[o,x]=a.useState([]),[S,E]=a.useState("loading"),[O,L]=a.useState(null),[R,A]=a.useState(0);a.useEffect(()=>{if(!e)return;let D=!1;return E("loading"),L(null),(async()=>{try{const X=await N.listAgentDefinitions();if(D)return;x(X.map(jn)),E("idle")}catch(X){if(D)return;x([]),L(Cs(X)),E("error")}})(),()=>{D=!0}},[N,e,R]);const p=a.useCallback(()=>{m==null||m(),h&&Qn(h)},[h,m]),f=a.useCallback(async D=>{await N.createAgent(D.definition.ref,{invocationName:D.invocationName}),d==null||d(D),l&&Qn(l)},[N,d,l]),T=a.useCallback(()=>{A(D=>D+1)},[]);return n.jsx(Ts,{open:e,onClose:p,onStart:f,agentDefinitions:o,definitionsState:S,definitionsError:O,onRetryDefinitions:T,embedded:w})},qr=e=>"agentDefinitionsUrl"in e,Is=e=>qr(e)?n.jsx(zr,{...e}):n.jsx(Ts,{...e}),Vr=({open:e,onClose:t})=>{const s=a.useId(),r=a.useId();return n.jsxs(c.Modal,{open:e,closeHandler:t,className:"archive-agent-confirm",children:[n.jsx(c.Modal.Header,{className:"archive-agent-confirm__header",children:n.jsx(c.Modal.Title,{id:s,children:Na})}),n.jsxs(c.Modal.Body,{className:"archive-agent-confirm__body",children:[n.jsx("div",{role:"alertdialog","aria-labelledby":s,"aria-describedby":r,children:n.jsx("p",{id:r,className:"archive-agent-confirm__lead",children:ya})}),n.jsx("div",{className:"archive-agent-confirm__actions",children:n.jsx(c.Button,{variant:"secondary",size:"S",onClick:t,children:"Close"})})]})]})},Kr=3,Yr=56,Jr=e=>e.archivedAt?"archived":e.status===k.paused?"paused":null,Wr=e=>{if(e==="archived")return Qs;if(e==="paused")return it[k.paused].statusIcon},Xr=({column:e,overlayIcon:t,label:s})=>{const r=t??e.statusIcon;return r?n.jsx("span",{className:"agent-view__status-indicator",children:n.jsx(c.Icon,{name:r.name,size:16,color:r.color,className:K({"agent-view__progress-icon--spinning":r.spin}),screenReaderText:s})}):n.jsx("span",{className:K("agent-view__dot",{[`agent-view__dot--${e.dotModifier}`]:e.dotModifier}),children:n.jsx(c.Dot,{colour:e.dotColour,label:s})})},Os=({agent:e,agentName:t,column:s,isExpanded:r,isLoading:i,checklist:h,error:l,canArchive:m,canUnarchive:d=!1,canDelete:w=!1,onToggle:_,onViewAgent:N,onArchive:o,onUnarchive:x,onDelete:S})=>{const{id:E,invocation_name:O}=e,L=`agent-card-${E}-header`,R=`agent-card-${E}-progress`,A=Jr(e),p=Wr(A);return n.jsx("li",{className:K("agent-view__card",{"agent-view__card--expanded":r,"agent-view__card--paused":A==="paused","agent-view__card--archived":A==="archived","agent-view__card--view-only":!e.usable}),children:n.jsxs(c.Card,{spacing:"dense",children:[n.jsx("button",{type:"button",className:"agent-view__card-toggle","aria-expanded":r,"aria-controls":R,"aria-label":O,id:L,onClick:()=>_(E),children:n.jsxs("div",{className:"agent-view__card-content",children:[n.jsx(Xr,{column:s,overlayIcon:p}),n.jsx("span",{className:"agent-view__card-invocation-name",children:O}),n.jsx("span",{className:"agent-view__card-agent-name",children:t}),A==="paused"?n.jsx("span",{className:"agent-view__card-state-pill",children:"Paused"}):null,A==="archived"?n.jsx("span",{className:"agent-view__card-state-pill",children:"Archived"}):null,e.usable?null:n.jsx("span",{className:"agent-view__card-state-pill",children:"View only"}),n.jsx(c.Icon,{name:r?"chevron-up":"chevron-down",size:16,className:"agent-view__card-chevron"})]})}),r&&n.jsxs("div",{id:R,"aria-labelledby":L,className:"agent-view__card-progress",children:[i&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(c.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:rt}),n.jsx("span",{children:rt})]}),!i&&l&&n.jsx("p",{className:"agent-view__progress-error",role:"alert",children:l}),!i&&!l&&h!==null&&n.jsx(Ua,{checklist:h}),!i&&!l&&h===null&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(c.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:rt}),n.jsx("span",{children:rt})]}),n.jsxs("div",{className:"agent-view__card-actions",children:[m?n.jsx(c.Button,{variant:"secondary",size:"S",iconLeftName:"archive",iconLeftScreenReaderText:"Archive",onClick:()=>o==null?void 0:o(e),children:"Archive"}):d?n.jsx(c.Button,{variant:"secondary",size:"S",onClick:()=>x==null?void 0:x(e),children:"Unarchive"}):w?n.jsx(c.Button,{variant:"secondary-destructive",size:"S",onClick:()=>S==null?void 0:S(e),children:"Delete"}):n.jsx("span",{}),d&&w?n.jsx(c.Button,{variant:"secondary-destructive",size:"S",onClick:()=>S==null?void 0:S(e),children:"Delete"}):null,n.jsx(c.Button,{variant:"secondary",size:"S",onClick:()=>N==null?void 0:N(e),children:"View agent"})]})]})]})})},Zr=()=>n.jsx("ul",{className:"agent-view__card-list","aria-hidden":"true",children:Array.from({length:Kr},(e,t)=>n.jsx("li",{className:"agent-view__card agent-view__card--skeleton",children:n.jsx(c.Skeleton,{className:"agent-view__card-skeleton",width:"100%",height:Yr})},t))}),es=({column:e,agents:t,expandedAgentId:s,loadingAgentId:r,checklistByInvocationId:i,errorByAgentId:h,definitionNameByRef:l,onToggleAgent:m,onViewAgent:d,onArchiveAgent:w,canArchive:_,isLoading:N=!1})=>n.jsxs("section",{className:"agent-view__column","aria-label":e.title,children:[n.jsxs("div",{className:"agent-view__column-header",children:[n.jsx(c.Heading,{level:4,children:e.title}),n.jsx("span",{className:"agent-view__column-count",children:N?0:t.length})]}),N?n.jsx(Zr,{}):n.jsx("ul",{className:"agent-view__card-list",children:t.map(o=>n.jsx(Os,{agent:o,agentName:Zt(o,l),column:e,isExpanded:s===o.id,isLoading:r===o.id,checklist:i[o.invocation_id]??null,error:h[o.id]??null,canArchive:_&&!o.archivedAt&&o.usable,onToggle:m,onViewAgent:d,onArchive:w},o.id))})]}),Zt=(e,t)=>t.get(e.agent_definition_ref)??e.agent_definition_ref.replace(/_/g," "),Qr=({jwt:e,headers:t,agentDefinitionsUrl:s,agentsUrl:r,agentUrl:i,agentChecklistUrl:h,agentResourcesUrl:l,agentTimelineUrl:m,agentChatUrl:d,agentConversationUrl:w,pauseAgentUrl:_,resumeAgentUrl:N,archiveAgentUrl:o,unarchiveAgentUrl:x,enableUpload:S,adminMode:E=!1,showHeader:O=!1,institutions:L,usePusherToRepoll:R=!1,pusherChannelPrefix:A=Sn,pusherKey:p,pusherCluster:f,subscribeToPusher:T,selectedAgent:D,scope:X=is})=>{var qt;const lt=a.useMemo(()=>({agentDefinitions:s,agents:r,agent:i,agentChecklist:h,...l?{agentResources:l}:{},...m?{agentTimeline:m}:{},agentChat:d,agentConversation:w,...o?{archiveAgent:o}:{},...x?{unarchiveAgent:x}:{}}),[s,r,i,h,l,m,d,w,o,x]),[J,Z]=a.useState(null),oe=J?(qt=L==null?void 0:L.find(u=>u.applicationId===J.application_id))==null?void 0:qt.applicationUrl:void 0,me=a.useMemo(()=>{const u={...t??{}};return oe?u[$e.arborApplicationUrl]=oe:delete u[$e.arborApplicationUrl],u},[t,oe]),{agents:M,agentDefinitions:re,loadState:se,loadError:ce,reload:y,refresh:P,fetchAgentChecklist:j,createAgent:F,archiveAgent:H,unarchiveAgent:q,deleteAgent:pe,removeAgent:Fe,replaceAgent:Lt}=Ss({jwt:e,headers:me,urls:lt,scope:X}),[Ge,ze]=a.useState(!1),[Ee,Se]=a.useState(null),[ot,V]=a.useState(null),[W,qe]=a.useState({}),[ct,ve]=a.useState({}),[je,dt]=a.useState([]),[ee,xe]=a.useState([]),[ae,Q]=a.useState(null),[ut,Ve]=a.useState(!1),[sn,Re]=a.useState(null),[an,Ke]=a.useState(!1),[Ye,Te]=a.useState(null),[ht,gt]=a.useState(!1),[rn,we]=a.useState(null),[Ie,Oe]=a.useState(null),[mt,Je]=a.useState(!1),[Le,Pe]=a.useState(null),[ln,pt]=a.useState(!1),Pt=a.useRef(!1);a.useEffect(()=>{Z(u=>{if(!u)return null;const b=M.find(C=>C.id===u.id||C.invocation_id===u.invocation_id||C.invocation_id===u.id);return b||(se==="loading"?u:null)})},[M,se]),a.useEffect(()=>{if(!D||Pt.current||se==="loading")return;Pt.current=!0;const u=M.find(({id:b})=>b===D);if(u){Z(u);return}pt(!0)},[D,M,se]);const We=a.useMemo(()=>{const u=new Set(M.map(C=>C.application_id)),b=new Map((L??[]).map(C=>[C.applicationId,C.name]));return[...u].sort((C,te)=>(b.get(C)??C).localeCompare(b.get(te)??te)).map(C=>({value:C,label:b.get(C)??C}))},[M,L]),ie=a.useMemo(()=>new Map(re.map(u=>[u.ref,u.display_name])),[re]),Xe=a.useMemo(()=>[...new Set(M.map(b=>Zt(b,ie)))].sort((b,C)=>b.localeCompare(C)).map(b=>({value:b,label:b})),[M,ie]),Ze=a.useMemo(()=>M.filter(u=>!(je.length>0&&!je.includes(u.application_id)||ee.length>0&&!ee.includes(Zt(u,ie)))),[M,ie,ee,je]),_t=We.length>1,Mt=Xe.length>1,ft=_t||Mt;a.useEffect(()=>{const u=window.setInterval(()=>{P()},6e4);return()=>{window.clearInterval(u)}},[P]),a.useEffect(()=>{if(M.length===0)return;let u=!1;return(async()=>{const b=await Promise.allSettled(M.map(async C=>{const te=await j(C.invocation_id);return{agentId:C.id,invocationId:C.invocation_id,checklist:te.checklist}}));u||(qe(C=>{const te={...C};let _e=!1;for(const tt of b){if(tt.status!=="fulfilled")continue;const{invocationId:de,checklist:kt}=tt.value;JSON.stringify(C[de])!==JSON.stringify(kt)&&(te[de]=kt,_e=!0)}return _e?te:C}),ve(C=>{const te={...C};let _e=!1;return b.forEach((tt,de)=>{tt.status==="rejected"&&te[M[de].id]!==Xt&&(te[M[de].id]=Xt,_e=!0)}),_e?te:C}))})(),()=>{u=!0}},[M,j]);const Ut=a.useCallback(async u=>{if(!W[u.invocation_id]){V(u.id),ve(b=>{const C={...b};return delete C[u.id],C});try{const b=await j(u.invocation_id);qe(C=>({...C,[u.invocation_id]:b.checklist}))}catch{ve(b=>({...b,[u.id]:Xt}))}finally{V(b=>b===u.id?null:b)}}},[j,W]),vt=a.useCallback(u=>{if(Ee===u){Se(null);return}const b=M.find(({id:C})=>C===u);b&&(Se(u),Ut(b))},[M,Ee,Ut]),Me=a.useMemo(()=>Ze.filter(u=>!!u.archivedAt),[Ze]),Ue=a.useMemo(()=>Ze.filter(u=>!u.archivedAt),[Ze]),xt=a.useMemo(()=>{const u={};for(const b of Ue){const C=vn(b,W[b.invocation_id]);(u[C]??(u[C]=[])).push(b)}return u},[Ue,W]),wt=se==="loading"&&M.length===0,on=Ue.length>0&&Ue.some(u=>W[u.invocation_id]===void 0&&ct[u.id]===void 0),At=wt||on,Nt=a.useCallback(u=>{Z(u)},[]),Dt=a.useCallback(u=>{Re(null),Q(u)},[]),Ht=a.useCallback(()=>{ut||(Re(null),Q(null))},[ut]),$t=a.useCallback(async()=>{if(ae){Ve(!0),Re(null),ve(u=>{const b={...u};return delete b[ae.id],b});try{await H(ae.invocation_id),Z(u=>(u==null?void 0:u.id)===ae.id?null:u),Se(ae.id),Ke(!0),Q(null)}catch{Re(Nn)}finally{Ve(!1)}}},[ae,H]),Bt=a.useCallback(u=>{we(null),Te(u)},[]),Ft=a.useCallback(()=>{ht||(we(null),Te(null))},[ht]),cn=a.useCallback(async()=>{if(Ye){gt(!0),we(null);try{await q(Ye.invocation_id),Te(null)}catch{we(yn)}finally{gt(!1)}}},[Ye,q]),yt=ae?vn(ae,W[ae.invocation_id])!==k.complete:!1,dn=a.useCallback(async u=>{const b=await F(u);Z(b),ze(!1)},[F]),Qe=a.useCallback(u=>{Pe(null),Oe(u)},[]),Gt=a.useCallback(()=>{mt||(Pe(null),Oe(null))},[mt]),zt=a.useCallback(async()=>{if(Ie){Je(!0),Pe(null);try{await pe(Ie.invocation_id),Z(u=>(u==null?void 0:u.id)===Ie.id?null:u),Oe(null)}catch(u){Pe(Es(u))}finally{Je(!1)}}},[Ie,pe]),un=a.useCallback(()=>{Z(null)},[]),et={expandedAgentId:Ee,loadingAgentId:ot,checklistByInvocationId:W,errorByAgentId:ct,definitionNameByRef:ie,onToggleAgent:vt,onViewAgent:Nt,onArchiveAgent:Dt,canArchive:!!o};return n.jsxs("div",{className:"agent-view-frontend agent-view",children:[O&&n.jsxs("div",{className:"agent-view__header",children:[n.jsx(c.Heading,{level:1,children:"Agents"}),n.jsx(c.Button,{variant:"primary",size:"S",iconLeftName:"sparkles",iconLeftScreenReaderText:"Start an agent",onClick:()=>ze(!0),children:"Start an agent"})]}),M.length>0&&ft&&n.jsxs("div",{className:"agent-view__filters",children:[_t&&n.jsxs("div",{className:"agent-view__filter",children:[n.jsx("label",{className:"agent-view__filter-label",htmlFor:"agent-view-institution-filter",children:"Institution"}),n.jsx(c.Combobox,{id:"agent-view-institution-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All institutions",options:We,value:je,onValueChange:dt,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear institutions"})]}),Mt&&n.jsxs("div",{className:"agent-view__filter",children:[n.jsx("label",{className:"agent-view__filter-label",htmlFor:"agent-view-agent-filter",children:"Agent"}),n.jsx(c.Combobox,{id:"agent-view-agent-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All agents",options:Xe,value:ee,onValueChange:xe,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear agents"})]})]}),se==="error"?n.jsxs("div",{className:"agent-view__state agent-view__state--error",role:"alert",children:[n.jsx(c.Icon,{name:"triangle-alert",size:24,color:"var(--color-semantic-destructive-600)"}),n.jsx("p",{className:"agent-view__state-message",children:ce??rs}),n.jsx(c.Button,{variant:"secondary",size:"S",onClick:y,children:"Try again"})]}):At?n.jsx("div",{className:"agent-view__board","aria-busy":"true","aria-live":"polite",children:Hn.map(u=>n.jsx(es,{column:it[u],agents:[],isLoading:!0,...et},u))}):M.length===0?n.jsx(Ra,{}):n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"agent-view__board",children:Hn.map(u=>n.jsx(es,{column:it[u],agents:xt[u]??[],...et},u))}),Me.length>0?n.jsxs("details",{className:"agent-view__archived",open:an,onToggle:u=>{Ke(u.currentTarget.open)},children:[n.jsxs("summary",{className:"agent-view__archived-summary",children:[n.jsx(c.Heading,{level:4,children:"Archived"}),n.jsx("span",{className:"agent-view__column-count",children:Me.length})]}),n.jsx("ul",{className:"agent-view__card-list agent-view__archived-list",children:Me.map(u=>n.jsx(Os,{agent:u,agentName:Zt(u,ie),column:it[vn(u,W[u.invocation_id])],isExpanded:Ee===u.id,isLoading:ot===u.id,checklist:W[u.invocation_id]??null,error:ct[u.id]??null,canArchive:!1,canUnarchive:!!x&&u.usable,canDelete:E&&u.usable,onToggle:vt,onViewAgent:Nt,onUnarchive:Bt,onDelete:Qe},u.id))})]}):null]}),J&&n.jsx(Rs,{agent:J,invocationId:J.invocation_id,open:!0,jwt:e,headers:me,agentUrl:i,agentChecklistUrl:h,agentResourcesUrl:l,agentTimelineUrl:m,agentChatUrl:d,agentConversationUrl:w,pauseAgentUrl:_,resumeAgentUrl:N,archiveAgentUrl:o,unarchiveAgentUrl:x,enableUpload:S,adminMode:E,initialChecklist:W[J.invocation_id]??null,usePusherToRepoll:R,pusherChannelPrefix:A,pusherKey:p,pusherCluster:f,subscribeToPusher:T,onClose:un,onAgentUpdated:Lt,onArchived:()=>{Se(J.id),Ke(!0),P()},onUnarchived:()=>{P()},onDeleted:()=>{Fe(J.invocation_id)}},J.id||J.invocation_id),n.jsx(cs,{open:!!ae,isInProgress:yt,isArchiving:ut,error:sn,onCancel:Ht,onConfirm:()=>{$t()}}),n.jsx(us,{open:!!Ye,isUnarchiving:ht,error:rn,onCancel:Ft,onConfirm:()=>{cn()}}),n.jsx(ds,{open:!!Ie,isDeleting:mt,error:Le,onCancel:Gt,onConfirm:()=>{zt()}}),n.jsx(Vr,{open:ln,onClose:()=>pt(!1)}),n.jsx(Is,{open:Ge,onClose:()=>ze(!1),onStart:dn,agentDefinitions:re})]})},ei=(e,t)=>{const s=Date.now(),r=t.trim()||e.agent_intent;return{id:`agent-${s}`,invocation_id:`inv-${s}`,agent_definition_ref:e.ref,agent_intent:e.agent_intent,invocation_name:r,application_id:ea,created_by:ta,usable:!0,status:k["generating-a-response"],archivedAt:null,context_ref:null,checklist_ref:null}};exports.AgentMonitorKanban=Qr;exports.AgentServiceClient=nn;exports.AgentServiceError=Be;exports.AgentView=Rs;exports.DEFAULT_PUSHER_CHANNEL_PREFIX=Sn;exports.HttpChatConnector=bs;exports.MESSAGE_TYPE_REPOLL=bn;exports.NewAgentModal=Is;exports.PUSHER_AGENT_MESSAGE_EVENT=ps;exports.REPOLL_TARGET=ke;exports.buildAgentFromDefinition=ei;exports.buildAgentPusherChannel=_s;exports.createHttpChatConnectorFactory=Tn;exports.formatUserFileChatCardText=Ar;exports.mapApiAgent=be;exports.mapApiAgentDefinition=jn;exports.mapApiAgentStatus=xs;exports.mapApiAgentTimelineResponse=ys;exports.mapApiChecklistEndpointResponse=tn;exports.mapApiChecklistItem=Rn;exports.mapApiChecklistResponse=xr;exports.mapApiChecklistStatus=ws;exports.mapApiConversationMessages=ks;exports.mapApiOpeningMessage=Ot;exports.mapApiResource=As;exports.mapApiResourcesEndpointResponse=Ns;exports.mapApiTripOption=pr;exports.parseConversationContentCaption=wr;exports.parseRepollMessages=fs;exports.useAgentService=Ss;exports.useAgentWorkspace=js;exports.useSubscribeToPusher=vs;
package/dist/index.d.ts CHANGED
@@ -64,7 +64,7 @@ export declare type AgentDefinition = {
64
64
  description: string;
65
65
  };
66
66
 
67
- export declare const AgentMonitorKanban: ({ jwt, headers, agentDefinitionsUrl, agentsUrl, agentUrl, agentChecklistUrl, agentResourcesUrl, agentTimelineUrl, agentChatUrl, agentConversationUrl, pauseAgentUrl, resumeAgentUrl, archiveAgentUrl, unarchiveAgentUrl, enableUpload, adminMode, showHeader, institutions, usePusherToRepoll, pusherChannelPrefix, pusherKey, pusherCluster, subscribeToPusher, selectedAgent: selectedAgentProp, agentIdToOpenOnMount, scope, }: AgentMonitorKanbanProps) => JSX_2.Element;
67
+ export declare const AgentMonitorKanban: ({ jwt, headers, agentDefinitionsUrl, agentsUrl, agentUrl, agentChecklistUrl, agentResourcesUrl, agentTimelineUrl, agentChatUrl, agentConversationUrl, pauseAgentUrl, resumeAgentUrl, archiveAgentUrl, unarchiveAgentUrl, enableUpload, adminMode, showHeader, institutions, usePusherToRepoll, pusherChannelPrefix, pusherKey, pusherCluster, subscribeToPusher, selectedAgent: selectedAgentId, scope, }: AgentMonitorKanbanProps) => JSX_2.Element;
68
68
 
69
69
  export declare type AgentMonitorKanbanProps = {
70
70
  jwt?: string;
@@ -90,8 +90,7 @@ export declare type AgentMonitorKanbanProps = {
90
90
  pusherKey?: string;
91
91
  pusherCluster?: string;
92
92
  subscribeToPusher?: SubscribeToPusher;
93
- selectedAgent?: Agent | null;
94
- agentIdToOpenOnMount?: string;
93
+ selectedAgent?: string;
95
94
  scope?: AgentScope;
96
95
  };
97
96