@arbor-education/agent-view-frontend 0.4.7 → 0.4.8

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,5 +1,5 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),o=require("react"),q=require("classnames"),d=require("@arbor-education/design-system.components"),ue=require("@arbor-education/ask-arbor-chat-panel"),b={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},H={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},U={briefing:"briefing",running:"running",stopped:"stopped",complete:"complete"},Y={agent:"agent",user:"user",system:"system"},se={document_html:"document_html",mis_record:"mis_record",workflow:"workflow",file:"file",link:"link"},it={cancelled:"cancelled",archived:"archived"},Je={in_progress:"in_progress",requires_attention:"requires_attention",available:"available"},W={[H.complete]:{label:"Complete",icon:"circle-check",color:"var(--color-semantic-success-600)"},[H.failed]:{label:"Failed",icon:"circle-x",color:"var(--color-semantic-destructive-600)"},[H.hitl]:{label:"Requires attention",icon:"triangle-alert",color:"var(--color-semantic-warning-600)"},[H["generating-a-response"]]:{label:"Generating a response",icon:"sparkles",color:"var(--color-brand-600)"}},Ue={[b["generating-a-response"]]:{status:b["generating-a-response"],title:"Active",dotColour:"green",statusIcon:{name:W["generating-a-response"].icon,color:W["generating-a-response"].color}},[b.hitl]:{status:b.hitl,title:"Requires attention",dotColour:"orange",statusIcon:{name:W.hitl.icon,color:W.hitl.color}},[b.complete]:{status:b.complete,title:"Complete",dotColour:"green",dotModifier:"grey-dark",statusIcon:{name:W.complete.icon,color:W.complete.color}},[b.failed]:{status:b.failed,title:"Failed",dotColour:"salmon",statusIcon:{name:W.failed.icon,color:W.failed.color}}},Wt=[b["generating-a-response"],b.hitl],Vt=[b.complete,b.failed],Yt="m4",Xt="1",ft="msg-opening",Me="Unable to load agent tasks. Please try again.",Qt="Unable to load the resources for this agent",Zt="Unable to load this document. Please try again.",vt="Unable to load the timeline for this agent",en="Something went wrong. Please try again.",wt="Unable to load agents. Please try again.",ce="Loading tasks…",lt="Loading agents…",tn="Task",nn={[U.briefing]:"Briefing",[U.running]:"Working",[U.stopped]:"Stopped",[U.complete]:"Complete"},sn=[b["generating-a-response"],b.hitl,b.complete,b.failed],an={[b["generating-a-response"]]:"Agents currently working on tasks for you.",[b.hitl]:"Agents that need your input before they can continue.",[b.complete]:"Agents that have finished their work.",[b.failed]:"Agents that failed or were stopped."},rn=()=>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:"100",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"244",y:"124",width:"100",height:"100",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("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:"52",r:"4",fill:"var(--color-grey-400)"}),n.jsx("circle",{cx:"256",cy:"160",r:"4",fill:"var(--color-semantic-destructive-500)"})]}),on=({status:t})=>{const e=Ue[t];return e.statusIcon?n.jsx(d.Icon,{name:e.statusIcon.name,size:16,color:e.statusIcon.color,screenReaderText:e.title}):n.jsx(d.Dot,{colour:e.dotColour,label:e.title})},ln=()=>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(d.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:sn.map(t=>{const e=Ue[t];return n.jsxs("li",{className:"agent-view__empty-column",children:[n.jsx("span",{className:"agent-view__empty-column-indicator",children:n.jsx(on,{status:t})}),n.jsxs("span",{className:"agent-view__empty-column-text",children:[n.jsx("span",{className:"agent-view__empty-column-title",children:e.title}),n.jsx("span",{className:"agent-view__empty-column-description",children:an[t]})]})]},t)})}),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(rn,{})})]}),cn=(t,e)=>({...t,...e.length>0?{children:e}:{}}),xt=t=>{const e=[],s=[];for(const a of t){const r=a.children?xt(a.children):{needsInput:[],tasks:[]};if(e.push(...r.needsInput),a.status===H.hitl){e.push({...a,children:void 0});continue}s.push(cn(a,r.tasks))}return{needsInput:e,tasks:s}},dn=t=>t.map((e,s)=>({item:e,index:s})).sort((e,s)=>{const a=e.item.status===H.hitl,r=s.item.status===H.hitl;return a!==r?a?-1:1:e.index-s.index}).map(({item:e})=>e),We=2,un=t=>{if(!t)return{canScrollUp:!1,canScrollDown:!1};const e=t.scrollHeight-t.clientHeight;return e<=We?{canScrollUp:!1,canScrollDown:!1}:{canScrollUp:t.scrollTop>We,canScrollDown:t.scrollTop<e-We}},gn=(t,e)=>{if(!t||!e)return null;const s=t.getBoundingClientRect(),a=e.getBoundingClientRect();return{top:a.top-s.top,left:a.left-s.left,width:a.width,height:a.height}},$e=({children:t,className:e,contentClassName:s,scrollSelector:a,style:r,"aria-label":l})=>{const i=o.useRef(null),u=o.useRef(null),[c,w]=o.useState(!1),[f,h]=o.useState(!1),[p,O]=o.useState(null),v=()=>{var k;return a?((k=i.current)==null?void 0:k.querySelector(a))??null:u.current},N=()=>{const k=v(),x=un(k);if(w(_=>_===x.canScrollUp?_:x.canScrollUp),h(_=>_===x.canScrollDown?_:x.canScrollDown),a){const _=gn(i.current,k);O(A=>(A==null?void 0:A.top)===(_==null?void 0:_.top)&&(A==null?void 0:A.left)===(_==null?void 0:_.left)&&(A==null?void 0:A.width)===(_==null?void 0:_.width)&&(A==null?void 0:A.height)===(_==null?void 0:_.height)?A:_)}else O(_=>_===null?_:null)};o.useLayoutEffect(()=>{N()}),o.useEffect(()=>{const k=i.current;if(!k)return;let x=null,_=null;const A=()=>{x==null||x.removeEventListener("scroll",N),_==null||_.disconnect(),_=null,x=null},T=D=>{if(D===x){N();return}if(A(),x=D,!x){N();return}x.addEventListener("scroll",N,{passive:!0}),_=new ResizeObserver(()=>N()),_.observe(x),x.firstElementChild instanceof HTMLElement&&_.observe(x.firstElementChild),N()};T(v());const E=new MutationObserver(()=>{T(v())});return E.observe(k,{childList:!0,subtree:!0,characterData:!0}),window.addEventListener("resize",N),()=>{window.removeEventListener("resize",N),E.disconnect(),A()}},[a]);const S=k=>{const x=v();if(!x)return;const _=Math.max(x.clientHeight*.75,120);x.scrollBy({top:k==="up"?-_:_,behavior:"smooth"})},P=n.jsxs(n.Fragment,{children:[c&&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:()=>S("up"),children:n.jsx(d.Icon,{name:"chevron-up",size:16,color:"currentColor"})})]}),f&&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:()=>S("down"),children:n.jsx(d.Icon,{name:"chevron-down",size:16,color:"currentColor"})})]})]});return n.jsx("div",{ref:i,className:q("scrollable-region",e),style:r,"aria-label":l,children:a?n.jsxs(n.Fragment,{children:[t,p&&(c||f)&&n.jsx("div",{className:"scrollable-region__overlay",style:{top:p.top,left:p.left,width:p.width,height:p.height},children:P})]}):n.jsxs(n.Fragment,{children:[P,n.jsx("div",{ref:u,className:q("scrollable-region__viewport",s),children:t})]})})},hn=48,pn=({checklist:t})=>{const e=o.useRef(null),s=o.useRef(!1);return o.useLayoutEffect(()=>{const a=e.current;if(!a)return;const r=a.scrollHeight-a.scrollTop-a.clientHeight;(!s.current||r<=hn)&&(a.scrollTop=a.scrollHeight,s.current=!0)},[t]),t.length===0?n.jsx("p",{className:"agent-view__progress-empty",children:"No tasks to display."}):n.jsx($e,{className:"agent-view__progress-scroll",scrollSelector:".agent-view__progress-list",children:n.jsx("ul",{ref:e,className:"agent-view__progress-list","aria-label":"Agent tasks",children:dn(t).map(a=>{const r=W[a.status];return n.jsxs("li",{className:q("agent-view__progress-item",`agent-view__progress-item--${a.status.replace(/_/g,"-")}`),children:[n.jsx(d.Icon,{name:r.icon,size:16,color:r.color,screenReaderText:`${r.label}:`}),n.jsxs("div",{className:"agent-view__progress-item-content",children:[n.jsx("span",{className:"agent-view__progress-label",children:a.task}),a.status!==H.complete&&n.jsx("span",{className:"agent-view__progress-description",children:a.description})]})]},a.task)})})})},mn=({prompts:t,classNamePrefix:e="agent-workspace",onSelect:s})=>t.length===0?null:n.jsx("div",{className:`${e}__chips`,children:t.map(a=>n.jsx("button",{type:"button",className:`${e}__chip`,onClick:()=>s(a),children:a},a))});class _n{constructor(e,s){this.connector=e,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(e){var s,a;if(!this.canSend())return null;(s=this.onAwaitingChange)==null||s.call(this,!0);try{const r=await this.connector.sendMessage(e.userMessage,e.uploadFiles);return this.onTurn(r),{id:r.message.id,text:r.message.text,type:ue.CHAT_RESPONSE_TYPE_AGENT,...r.message.followUpPrompts?{followUpPrompts:r.message.followUpPrompts}:{}}}catch{return{id:`error-${Date.now()}`,text:en,type:ue.CHAT_RESPONSE_TYPE_ERROR}}finally{(a=this.onAwaitingChange)==null||a.call(this,!1)}}async loadHistory(e){return null}async listInteractions(){return null}async rateMessage(e){}async sendNotification(e){return!1}}const fn=({connector:t,phase:e,chatHistory:s,chatSessionKey:a,startQuery:r,clarificationMessage:l,enableUpload:i=!1,onTurn:u,onAwaitingChange:c,onClarificationPrompt:w,onDismissClarification:f})=>{const h=o.useMemo(()=>new _n(t,{canSend:()=>e===U.running,onTurn:u,onAwaitingChange:c}),[t,e,u,c]),p=e!==U.running,O=e===U.running;return n.jsxs("section",{className:"agent-workspace__chat-body","aria-label":"Chat",children:[l&&n.jsxs("div",{className:"agent-workspace__clarification",role:"region","aria-label":"Agent question",children:[n.jsx("p",{className:"agent-workspace__clarification-text",children:l.text}),l.followUpPrompts&&n.jsx(mn,{prompts:l.followUpPrompts,onSelect:w}),n.jsx("button",{type:"button",className:"agent-workspace__clarification-dismiss",onClick:f,children:"Dismiss"})]}),n.jsx("div",{className:"agent-workspace__ask-arbor",children:n.jsx($e,{scrollSelector:".chat-panel-message-list",children:n.jsx(ue.ChatPanel,{connector:h,chatHistory:s,startQuery:r,lockConversation:p,enableUpload:i,speechEnabled:O,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:O?"Message the agent, paste a link, or attach a file…":"The agent is not accepting messages."},a)})}),e===U.stopped&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(d.Icon,{name:"circle-alert",size:16,color:"var(--color-semantic-warning-600)"}),n.jsx("span",{children:"You stopped the agent. Its progress is saved in the checklist on the left."})]}),e===U.complete&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(d.Icon,{name:"party-popper",size:16,color:"var(--color-semantic-success-600)"}),n.jsx("span",{children:"The agent has finished."})]})]})},kt=({item:t,depth:e,canRequestInput:s,onAttentionItemClick:a})=>{const r=W[t.status],l=t.status.replace(/_/g,"-"),i=t.status===H.hitl&&s&&a,u=n.jsxs("div",{className:"agent-workspace__task-row",children:[n.jsx(d.Icon,{name:r.icon,size:16,color:r.color,screenReaderText:`${r.label}:`}),n.jsxs("div",{className:"agent-workspace__task-content",children:[n.jsx("span",{className:"agent-workspace__task-label",children:t.task}),t.status!==H.complete&&t.description&&n.jsx("span",{className:"agent-workspace__task-description",children:t.description})]})]});return n.jsxs("li",{className:q("agent-workspace__task",`agent-workspace__task--${l}`,{"agent-workspace__task--child":e>0}),children:[i?n.jsx("button",{type:"button",className:"agent-workspace__task-button","aria-label":`Provide input for ${t.task}`,onClick:()=>a(t),children:u}):u,t.children&&t.children.length>0&&n.jsx("ul",{className:"agent-workspace__task-children",children:t.children.map(c=>n.jsx(kt,{item:c,depth:e+1,canRequestInput:s,onAttentionItemClick:a},c.task))})]})},ct=({items:t,ariaLabel:e,canRequestInput:s,onAttentionItemClick:a})=>n.jsx("ul",{className:"agent-workspace__task-list","aria-label":e,children:t.map(r=>n.jsx(kt,{item:r,depth:0,canRequestInput:s,onAttentionItemClick:a},r.task))}),vn=({checklist:t,isLoading:e,error:s,phase:a,canRequestInput:r,onAttentionItemClick:l})=>{const i=o.useMemo(()=>t?xt(t):null,[t]);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:n.jsx(d.Heading,{level:4,children:"Checklist"})}),n.jsx("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:n.jsxs($e,{children:[e&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(d.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:ce}),n.jsx("span",{children:ce})]}),!e&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!e&&!s&&i&&n.jsxs(n.Fragment,{children:[i.needsInput.length>0&&n.jsxs("div",{className:"agent-workspace__task-group",children:[n.jsx("p",{className:"agent-workspace__task-group-label",children:"Needs your input"}),n.jsx(ct,{items:i.needsInput,ariaLabel:"Tasks needing your input",canRequestInput:r,onAttentionItemClick:l})]}),i.tasks.length>0&&n.jsxs("div",{className:q("agent-workspace__task-group",{"agent-workspace__task-group--following":i.needsInput.length>0}),children:[i.needsInput.length>0&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"Other tasks"}),n.jsx(ct,{items:i.tasks,ariaLabel:"Agent tasks",canRequestInput:r,onAttentionItemClick:l})]})]}),!e&&!s&&(!i||i.needsInput.length===0&&i.tasks.length===0)&&n.jsx("p",{className:"agent-workspace__empty",children:a===U.briefing?"Tasks will appear here once the agent starts.":"No tasks to display."})]})})]})},wn=({resource:t,html:e,isLoading:s,error:a,onClose:r})=>{o.useEffect(()=>{if(!t)return;const i=d.SlideoverUtils.removeSlideover;return d.SlideoverUtils.removeSlideover=()=>{i(),r()},()=>{d.SlideoverUtils.removeSlideover=i}},[t,r]),o.useEffect(()=>{if(!t)return;const i=u=>{u.key==="Escape"&&d.SlideoverUtils.removeSlideover()};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[t]);const l=o.useMemo(()=>t?[{centerHeaderText:!1,children:n.jsxs("div",{className:"resource-preview-slideover__body",children:[s&&n.jsxs("div",{className:"resource-preview-slideover__status",children:[n.jsx(d.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&&a&&n.jsx("p",{className:"resource-preview-slideover__error",role:"alert",children:a}),!s&&!a&&e!==null&&n.jsx("iframe",{className:"resource-preview-slideover__frame",title:t.title,sandbox:"",srcDoc:e})]})}]:[],[t,e,s,a]);return n.jsx("div",{className:"resource-preview-slideover",children:n.jsx(d.SlideoverManager,{slideovers:l})})},xn={[se.mis_record]:{icon:"table",label:"Arbor MIS",color:"var(--color-brand-600)"},[se.document_html]:{icon:"file",label:"Document",color:"var(--color-semantic-caution-800)"},[se.file]:{icon:"file",label:"File",color:"var(--color-semantic-caution-800)"},[se.workflow]:{icon:"list-tree",label:"Workflow",color:"var(--color-semantic-warning-700)"},[se.link]:{icon:"link",label:"Link",color:"var(--color-semantic-info-700)"}},kn=({resources:t,isLoading:e=!1,error:s=null,onOpenResource:a})=>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(d.Heading,{level:4,children:"Resources"}),n.jsx("span",{className:"agent-workspace__panel-count",children:t.length})]}),n.jsx("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:n.jsxs($e,{children:[e&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(d.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…"})]}),!e&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!e&&!s&&t.length>0&&n.jsx("ul",{className:"agent-workspace__resource-list","aria-label":"Agent resources",children:t.map(r=>{const l=xn[r.type],i=r.misRecordUrl;return n.jsx("li",{className:"agent-workspace__resource",children:i?n.jsx("a",{className:"agent-workspace__resource-card",href:i,target:"_blank",rel:"noreferrer",onClick:u=>{u.preventDefault(),a(r)},children:n.jsx(dt,{resource:r,config:l,external:!0})}):n.jsx("button",{type:"button",className:"agent-workspace__resource-card",onClick:()=>a(r),children:n.jsx(dt,{resource:r,config:l})})},r.id)})}),!e&&!s&&t.length===0&&n.jsx("p",{className:"agent-workspace__empty",children:"No resources yet."})]})})]}),dt=({resource:t,config:e,external:s=!1})=>n.jsxs(n.Fragment,{children:[n.jsx("span",{className:`agent-workspace__resource-icon agent-workspace__resource-icon--${t.type}`,children:n.jsx(d.Icon,{name:e.icon,size:16,color:e.color,screenReaderText:`${e.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:t.title}),n.jsx("span",{className:`agent-workspace__resource-badge agent-workspace__resource-badge--${t.type}`,children:e.label})]})}),s&&n.jsx(d.Icon,{name:"external-link",size:12,color:"var(--color-grey-500)",screenReaderText:"Opens in a new tab",className:"agent-workspace__resource-open"})]}),De=t=>{const e=Date.parse(t);return Number.isFinite(e)?e:0},yn=new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"2-digit"}),Ve=t=>{const e=new Date(t);return Number.isFinite(e.getTime())?yn.format(e):t},Pe=t=>t.replace(/[A-Za-z0-9]+(?:[_-][A-Za-z0-9]+)+/g,e=>e.split(/[_-]/).map(s=>s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()).join(" ")),xe=(t,e)=>e<=1?0:t/(e-1)*100,yt=t=>Math.max(t,0)+2,Sn=t=>t+1,Nn=(t,e)=>{if(e.length===0)return 50;const s=yt(e.length),a=xe(1,s),r=xe(e.length,s),l=e.map(f=>De(f.timestamp)),i=Math.min(...l),u=Math.max(...l);if(u<=i)return a;const c=(De(t.timestamp)-i)/(u-i),w=Math.min(1,Math.max(0,c));return a+w*(r-a)},jn=8,bn=20,An=(t,e=jn,s=bn)=>{const a=new Map;if(t.length===0)return a;const r=[...t].sort((i,u)=>i.leftPercent-u.leftPercent||i.timestampMs-u.timestampMs||i.id.localeCompare(u.id)),l=[];for(const i of r){const u=l[l.length-1];u&&i.leftPercent-u[u.length-1].leftPercent<e?u.push(i):l.push([i])}for(const i of l){const u=[...i].sort((w,f)=>w.timestampMs-f.timestampMs||w.id.localeCompare(f.id)),c=(u.length-1)/2;u.forEach((w,f)=>{a.set(w.id,(f-c)*s)})}return a},Le=(t,e=0)=>({left:`calc(${t/100} * (100% - var(--agent-timeline-node-size)) + (var(--agent-timeline-node-size) / 2) + ${e}px)`,transform:"translateX(-50%)"}),Cn=t=>t.type!=="message-sent",En=({timeline:t,isLoading:e,error:s,onOpenChatSession:a})=>{const r=((t==null?void 0:t.actionLog)??[]).filter(Cn),l=(t==null?void 0:t.chatSessions)??[],i=!e&&!s&&r.length===0&&l.length===0,u=yt(r.length),c=r.map((h,p)=>({id:`action-${h.timestamp}-${p}`,leftPercent:xe(Sn(p),u),timestampMs:De(h.timestamp)})),w=l.map(h=>({id:h.sessionId,leftPercent:Nn(h,r),timestampMs:De(h.timestamp)})),f=An([...c,...w]);return n.jsxs("section",{className:"agent-workspace__timeline","aria-label":"Agent timeline",children:[e&&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||vt}),i&&n.jsx("p",{className:"agent-workspace__timeline-status",role:"status",children:"No timeline activity yet."}),!e&&!s&&!i&&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",style:Le(xe(0,u)),children:[n.jsx("span",{className:"agent-timeline__station-node agent-timeline__station-node--terminus","aria-hidden":"true",children:n.jsx(d.Icon,{name:"arrow-right-from-line",size:16,color:"currentColor"})}),n.jsx("span",{className:"agent-timeline__terminus-label",children:"Start"})]}),r.map((h,p)=>{const O=`action-${h.timestamp}-${p}`,v=c[p].leftPercent,N=h.type==="checklist-updated",S=h.type==="status-transition",P=N?"checklist":S?"status":"note";return n.jsxs("div",{className:`agent-timeline__station agent-timeline__station--${P}`,style:Le(v,f.get(O)??0),children:[n.jsxs("button",{type:"button",className:`agent-timeline__station-node agent-timeline__station-node--${P}`,"aria-label":`${Pe(h.type)}: ${Pe(h.entry)}`,children:[N&&n.jsx(d.Icon,{name:"check-solid",size:16,color:"currentColor"}),S&&n.jsx(d.Icon,{name:"iteration-ccw",size:16,color:"currentColor"})]}),n.jsxs("div",{className:"agent-timeline__pill",role:"tooltip",children:[n.jsx("strong",{className:"agent-timeline__pill-type",children:Pe(h.type)}),n.jsx("span",{className:"agent-timeline__pill-entry",children:Pe(h.entry)}),n.jsx("span",{className:"agent-timeline__pill-entry",children:Ve(h.timestamp)})]})]},O)}),n.jsxs("div",{className:"agent-timeline__station agent-timeline__station--terminus",style:Le(xe(u-1,u)),children:[n.jsx("span",{className:"agent-timeline__station-node agent-timeline__station-node--terminus","aria-hidden":"true",children:n.jsx(d.Icon,{name:"flag",size:16,color:"currentColor"})}),n.jsx("span",{className:"agent-timeline__terminus-label",children:"Finish"})]}),l.map((h,p)=>{const O=w[p].leftPercent;return n.jsxs("div",{className:"agent-timeline__chat-station",style:Le(O,f.get(h.sessionId)??0),children:[n.jsx("button",{type:"button",className:"agent-timeline__chat-node","aria-label":`Open chat session from ${Ve(h.timestamp)}`,onClick:()=>a(h.sessionId),children:n.jsx(d.Icon,{name:"sparkles",size:16,color:"currentColor"})}),n.jsxs("div",{className:"agent-timeline__pill",role:"tooltip",children:[n.jsx("strong",{className:"agent-timeline__pill-type",children:"Chat session"}),n.jsx("span",{className:"agent-timeline__pill-entry",children:Ve(h.timestamp)})]})]},h.sessionId)})]})]})},Tn=["I'll get the details and come back to you","Skip this for now"],Rn=t=>{var s;const e=(s=t.prompt)!=null&&s.trim()?t.prompt.trim():`I need a bit more from you on "${t.task}". ${t.description} What can you tell me?`;return{id:`clarification-${Date.now()}`,author:Y.agent,text:e,followUpPrompts:t.clarificationPrompts??Tn}},le=t=>({id:t.id,text:t.text,type:t.author===Y.user?ue.CHAT_RESPONSE_TYPE_USER:t.author===Y.system?ue.CHAT_RESPONSE_TYPE_INFO:ue.CHAT_RESPONSE_TYPE_AGENT,...t.followUpPrompts?{followUpPrompts:t.followUpPrompts}:{}});class de extends Error{constructor(e,s,a){super(a??`Agent service request failed (${e})`),this.name="AgentServiceError",this.status=e,this.detail=s}}const In="/api/v1",M={agentDefinitions:"/agent-definitions",agents:"/agents",conversations:"/conversations",tripOptions:"/trip-options",demoDataset:"/demo/dataset"},z={GET:"GET",POST:"POST"},On={error:"error"},Pn={user:"user"},ae={acceptJson:"application/json",acceptHtml:"text/html",acceptEventStream:"text/event-stream",contentTypeJson:"application/json",arborApplicationUrl:"X-Arbor-Application-Url"},Ln=100,St=t=>{switch(t){case it.cancelled:return b.failed;case it.archived:return b.complete;case b.hitl:case b.complete:case b.failed:case b["generating-a-response"]:return t;default:return b["generating-a-response"]}},Nt=t=>{switch(t){case Je.requires_attention:return H.hitl;case Je.in_progress:case Je.available:return H["generating-a-response"];case H.failed:case H.complete:case H.hitl:case H["generating-a-response"]:return t;default:return H["generating-a-response"]}},Ze=t=>({ref:t.name,display_name:t.display_name,agent_intent:t.agent_intent??"",description:t.description}),Mn=t=>({id:t.id,name:t.name,...t.has_run_before?{hasRunBefore:t.has_run_before}:{}}),Un=new Set(Object.values(se)),Dn=t=>Un.has(t)?t:se.document_html,jt=t=>({id:t.id,type:Dn(t.type),title:t.title,createdDatetime:t.created_datetime,lastUpdatedDatetime:t.last_updated_datetime,misRecordUrl:t.mis_record_url}),bt=t=>({resources:t.resources.map(jt),pageNumber:t.page_number,pageSize:t.page_size,totalRecords:t.total_records}),At=t=>({actionLog:(t.action_log??[]).map(e=>({timestamp:e.timestamp,type:e.type,entry:e.entry,origin:e.origin})),chatSessions:(t.chat_sessions??[]).map(e=>({sessionId:e.session_id,timestamp:e.timestamp}))}),Xe=t=>{var s;const e=t.invocation_id??t.id;return{id:t.id,invocation_id:e,agent_definition_ref:t.agent_definition_ref,...t.agent_intent?{agent_intent:t.agent_intent}:{},invocation_name:((s=t.invocation_name)==null?void 0:s.trim())||t.agent_definition_ref,application_id:t.application_id,...t.application_name?{application_name:t.application_name}:{},created_by:t.created_by,status:St(t.status),context_ref:t.context_ref??null,checklist_ref:t.checklist_ref??null}},et=t=>{var e;return{task:t.task??t.name??t.label??tn,status:Nt(t.status),description:t.description??"",...t.prompt?{prompt:t.prompt}:{},...(e=t.follow_up_prompts)!=null&&e.length?{clarificationPrompts:t.follow_up_prompts}:{}}},$n=t=>Array.isArray(t)?t:t.checklist_items??t.checklist??t.items??[],tt=(t,e,s)=>{var l;const a=!Array.isArray(e)&&(e.opening_message||(l=e.opening_follow_up_prompts)!=null&&l.length)?e:s,r=a?ke(a):void 0;return{invocation_id:t,checklist:$n(e).map(et),...r?{openingMessage:r}:{}}},Ct=(t,e)=>{const s=ke(e);return{invocation_id:e.invocation_id??t,checklist:(e.checklist_items??[]).map(et),...s?{openingMessage:s}:{}}},ke=t=>{var s,a;const e=(s=t.opening_message)==null?void 0:s.trim();if(e)return{id:ft,author:Y.agent,text:e,...(a=t.opening_follow_up_prompts)!=null&&a.length?{followUpPrompts:t.opening_follow_up_prompts}:{}}},Et=t=>t.filter(e=>(e.role==="user"||e.role==="assistant")&&typeof e.content=="string"&&e.content.length>0&&e.message_type!=="tool_request").map(e=>({id:e.message_id,author:e.role==="user"?Y.user:Y.agent,text:e.content})),Hn=/:invocationId\b/g,Bn=/:resourceId\b/g,zn=t=>t.trim().replace(/^Bearer\s+/i,""),Fn=t=>t.endsWith("/")?t.slice(0,-1):t;class He{constructor(e){var a;this.baseUrl=Fn(e.baseUrl??"");const s=(a=e.token)==null?void 0:a.trim();this.token=s?zn(s):void 0,this.customHeaders=e.headers,this.urls=e.urls??{},this.fetchImpl=e.fetch??globalThis.fetch.bind(globalThis)}setHeaders(e){this.customHeaders=e}async listAgentDefinitions(){return(await this.request(z.GET,this.resolveUrl("agentDefinitions",M.agentDefinitions))).agent_definitions??[]}getAgentDefinition(e){return this.request(z.GET,this.apiUrl(`${M.agentDefinitions}/${encodeURIComponent(e)}`))}listTripOptions(){return this.request(z.GET,this.apiUrl(M.tripOptions))}getDataset(){return this.request(z.GET,this.apiUrl(M.demoDataset))}setDataset(e){return this.request(z.POST,this.apiUrl(M.demoDataset),{dataset:e})}listAgents(e={}){const s=new URLSearchParams;e.status&&s.set("status",e.status),e.agentDefinitionRef&&s.set("agent_definition_ref",e.agentDefinitionRef);const a=s.toString()?`?${s.toString()}`:"";return this.request(z.GET,`${this.resolveUrl("agents",M.agents)}${a}`)}createAgent(e,s={}){var i,u;const a={agent_definition_ref:e},r=(i=s.invocationName)==null?void 0:i.trim(),l=(u=s.agentIntent)==null?void 0:u.trim();return r&&(a.invocation_name=r),l&&(a.agent_intent=l),this.request(z.POST,this.resolveUrl("agents",M.agents),a)}getAgent(e){return this.request(z.GET,this.resolveUrl("agent",`${M.agents}/${encodeURIComponent(e)}`,e))}getAgentChecklist(e){return this.request(z.GET,this.resolveUrl("agentChecklist",`${M.agents}/${encodeURIComponent(e)}/checklist`,e))}getAgentResources(e,s={}){const a=new URLSearchParams;s.pageNumber!==void 0&&a.set("page_number",String(s.pageNumber)),s.pageSize!==void 0&&a.set("page_size",String(s.pageSize)),s.type&&a.set("type",s.type);const r=a.toString(),l=this.resolveUrl("agentResources",`${M.agents}/${encodeURIComponent(e)}/resources`,e);return this.request(z.GET,r?`${l}?${r}`:l)}async listAllAgentResources(e){const s=Ln;let a=1;const r=[];let l=Number.POSITIVE_INFINITY;for(;r.length<l;){const i=bt(await this.getAgentResources(e,{pageNumber:a,pageSize:s}));if(l=i.totalRecords,i.resources.length===0||(r.push(...i.resources),r.length>=l))break;a+=1}return r}getAgentResourceHtml(e,s){return this.requestText(z.GET,this.resolveResourceHtmlUrl(e,s))}getAgentTimeline(e){return this.request(z.GET,this.resolveUrl("agentTimeline",`${M.agents}/${encodeURIComponent(e)}/agent-timeline`,e))}getAgentContext(e){return this.request(z.GET,this.apiUrl(`${M.agents}/${encodeURIComponent(e)}/context`))}cancelAgent(e){return this.request(z.POST,this.apiUrl(`${M.agents}/${encodeURIComponent(e)}/cancel`))}archiveAgent(e){return this.request(z.POST,this.apiUrl(`${M.agents}/${encodeURIComponent(e)}/archive`))}getConversation(e){return this.request(z.GET,this.resolveUrl("agentConversation",`${M.conversations}/${encodeURIComponent(e)}`,e))}async chat(e,s,a={}){const r=!!(a.uploadFiles&&a.uploadFiles.length>0),l=await this.fetchImpl(this.resolveUrl("agentChat",`${M.agents}/${encodeURIComponent(e)}/chat`,e),{method:z.POST,headers:{...this.customHeaders,...this.authHeaders(),Accept:ae.acceptEventStream,...r?{}:{"Content-Type":ae.contentTypeJson}},body:r?qn(s,a.uploadFiles??[]):JSON.stringify(s),signal:a.signal});if(!l.ok)throw await this.toError(l);if(!l.body)throw new de(l.status,null,"Chat response contained no stream body");return this.consumeSse(l.body,a.onEvent)}authHeaders(){return this.token?{Authorization:`Bearer ${this.token}`}:{}}apiUrl(e){return`${this.baseUrl}${In}${e}`}resolveUrl(e,s,a,r){const l=this.urls[e];if(!l)return this.apiUrl(s);let i=l;return a&&(i=i.replace(Hn,encodeURIComponent(a))),r&&(i=i.replace(Bn,encodeURIComponent(r))),i}resolveResourceHtmlUrl(e,s){return this.urls.agentResourceHtml?this.resolveUrl("agentResourceHtml",`${M.agents}/${encodeURIComponent(e)}/resources/${encodeURIComponent(s)}`,e,s):this.urls.agentResources?`${this.resolveUrl("agentResources",`${M.agents}/${encodeURIComponent(e)}/resources`,e).replace(/\/$/,"")}/${encodeURIComponent(s)}`:this.apiUrl(`${M.agents}/${encodeURIComponent(e)}/resources/${encodeURIComponent(s)}`)}async request(e,s,a){const r=await this.fetchImpl(s,{method:e,headers:{...this.customHeaders,...this.authHeaders(),Accept:ae.acceptJson,...a===void 0?{}:{"Content-Type":ae.contentTypeJson}},...a===void 0?{}:{body:JSON.stringify(a)}});if(!r.ok)throw await this.toError(r);if(r.status!==204)return await r.json()}async requestText(e,s){const a=await this.fetchImpl(s,{method:e,headers:{...this.customHeaders,...this.authHeaders(),Accept:ae.acceptHtml}});if(!a.ok)throw await this.toError(a);return a.text()}async toError(e){let s=null;try{s=await e.json()}catch{}return new de(e.status,s,`Agent service request failed (${e.status} ${e.statusText})`)}async consumeSse(e,s){const a=e.getReader(),r=new TextDecoder;let l="",i;const u=c=>{const{event:w,data:f}=Gn(c);if(f===null)return;if(w===On.error){const p=ut(f);throw new de(502,p,(p==null?void 0:p.message)??"Chat stream error")}const h=ut(f);h&&(i=h,s==null||s(h))};for(;;){const{done:c,value:w}=await a.read();if(c)break;l+=r.decode(w,{stream:!0});const f=l.split(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),o=require("react"),J=require("classnames"),d=require("@arbor-education/design-system.components"),me=require("@arbor-education/ask-arbor-chat-panel"),A={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},B={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},H={briefing:"briefing",running:"running",stopped:"stopped",complete:"complete"},Z={agent:"agent",user:"user",system:"system"},re={document_html:"document_html",mis_record:"mis_record",workflow:"workflow",file:"file",link:"link"},gt={cancelled:"cancelled",archived:"archived"},Xe={in_progress:"in_progress",requires_attention:"requires_attention",available:"available"},V={[B.complete]:{label:"Complete",icon:"circle-check",color:"var(--color-semantic-success-600)"},[B.failed]:{label:"Failed",icon:"circle-x",color:"var(--color-semantic-destructive-600)"},[B.hitl]:{label:"Requires attention",icon:"triangle-alert",color:"var(--color-semantic-warning-600)"},[B["generating-a-response"]]:{label:"Generating a response",icon:"sparkles",color:"var(--color-brand-600)"}},He={[A["generating-a-response"]]:{status:A["generating-a-response"],title:"Active",dotColour:"green",statusIcon:{name:V["generating-a-response"].icon,color:V["generating-a-response"].color}},[A.hitl]:{status:A.hitl,title:"Requires attention",dotColour:"orange",statusIcon:{name:V.hitl.icon,color:V.hitl.color}},[A.complete]:{status:A.complete,title:"Complete",dotColour:"green",dotModifier:"grey-dark",statusIcon:{name:V.complete.icon,color:V.complete.color}},[A.failed]:{status:A.failed,title:"Failed",dotColour:"salmon",statusIcon:{name:V.failed.icon,color:V.failed.color}}},Zt=[A["generating-a-response"],A.hitl],es=[A.complete,A.failed],ts="m4",ss="1",yt="msg-opening",$e="Unable to load agent tasks. Please try again.",ns="Unable to load the resources for this agent",as="Unable to load this document. Please try again.",St="Unable to load the timeline for this agent",rs="Something went wrong. Please try again.",Nt="Unable to load agents. Please try again.",he="Loading tasks…",ht="Loading agents…",os="Task",is={[H.briefing]:"Briefing",[H.running]:"Working",[H.stopped]:"Stopped",[H.complete]:"Complete"},ls=[A["generating-a-response"],A.hitl,A.complete,A.failed],cs={[A["generating-a-response"]]:"Agents currently working on tasks for you.",[A.hitl]:"Agents that need your input before they can continue.",[A.complete]:"Agents that have finished their work.",[A.failed]:"Agents that failed or were stopped."},ds=()=>s.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:[s.jsx("rect",{x:"0",y:"0",width:"360",height:"240",rx:"12",fill:"var(--color-grey-100)"}),s.jsx("rect",{x:"16",y:"16",width:"100",height:"208",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),s.jsx("rect",{x:"130",y:"16",width:"100",height:"208",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),s.jsx("rect",{x:"244",y:"16",width:"100",height:"100",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),s.jsx("rect",{x:"244",y:"124",width:"100",height:"100",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),s.jsx("rect",{x:"28",y:"52",width:"76",height:"36",rx:"6",fill:"var(--color-grey-050)"}),s.jsx("rect",{x:"28",y:"96",width:"76",height:"36",rx:"6",fill:"var(--color-grey-050)"}),s.jsx("rect",{x:"142",y:"52",width:"76",height:"36",rx:"6",fill:"var(--color-semantic-warning-050)"}),s.jsx("circle",{cx:"40",cy:"70",r:"4",fill:"var(--color-brand-600)"}),s.jsx("circle",{cx:"40",cy:"114",r:"4",fill:"var(--color-brand-600)"}),s.jsx("circle",{cx:"154",cy:"70",r:"4",fill:"var(--color-semantic-warning-600)"}),s.jsx("circle",{cx:"256",cy:"52",r:"4",fill:"var(--color-grey-400)"}),s.jsx("circle",{cx:"256",cy:"160",r:"4",fill:"var(--color-semantic-destructive-500)"})]}),us=({status:t})=>{const e=He[t];return e.statusIcon?s.jsx(d.Icon,{name:e.statusIcon.name,size:16,color:e.statusIcon.color,screenReaderText:e.title}):s.jsx(d.Dot,{colour:e.dotColour,label:e.title})},gs=()=>s.jsxs("section",{className:"agent-view__empty","aria-label":"About the agents board",children:[s.jsxs("div",{className:"agent-view__empty-content",children:[s.jsx(d.Heading,{level:4,children:"Your agents board"}),s.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."}),s.jsx("ul",{className:"agent-view__empty-columns",children:ls.map(t=>{const e=He[t];return s.jsxs("li",{className:"agent-view__empty-column",children:[s.jsx("span",{className:"agent-view__empty-column-indicator",children:s.jsx(us,{status:t})}),s.jsxs("span",{className:"agent-view__empty-column-text",children:[s.jsx("span",{className:"agent-view__empty-column-title",children:e.title}),s.jsx("span",{className:"agent-view__empty-column-description",children:cs[t]})]})]},t)})}),s.jsxs("p",{className:"agent-view__empty-hint",children:["Use ",s.jsx("strong",{children:"Start an agent"})," above to begin."]})]}),s.jsx("div",{className:"agent-view__empty-visual",children:s.jsx(ds,{})})]}),hs=(t,e)=>({...t,...e.length>0?{children:e}:{}}),jt=t=>{const e=[],n=[];for(const a of t){const r=a.children?jt(a.children):{needsInput:[],tasks:[]};if(e.push(...r.needsInput),a.status===B.hitl){e.push({...a,children:void 0});continue}n.push(hs(a,r.tasks))}return{needsInput:e,tasks:n}},ps=t=>t.map((e,n)=>({item:e,index:n})).sort((e,n)=>{const a=e.item.status===B.hitl,r=n.item.status===B.hitl;return a!==r?a?-1:1:e.index-n.index}).map(({item:e})=>e),Qe=2,ms=t=>{if(!t)return{canScrollUp:!1,canScrollDown:!1};const e=t.scrollHeight-t.clientHeight;return e<=Qe?{canScrollUp:!1,canScrollDown:!1}:{canScrollUp:t.scrollTop>Qe,canScrollDown:t.scrollTop<e-Qe}},_s=(t,e)=>{if(!t||!e)return null;const n=t.getBoundingClientRect(),a=e.getBoundingClientRect();return{top:a.top-n.top,left:a.left-n.left,width:a.width,height:a.height}},ze=({children:t,className:e,contentClassName:n,scrollSelector:a,style:r,"aria-label":l})=>{const i=o.useRef(null),u=o.useRef(null),[c,v]=o.useState(!1),[f,h]=o.useState(!1),[p,O]=o.useState(null),w=()=>{var y;return a?((y=i.current)==null?void 0:y.querySelector(a))??null:u.current},j=()=>{const y=w(),k=ms(y);if(v(_=>_===k.canScrollUp?_:k.canScrollUp),h(_=>_===k.canScrollDown?_:k.canScrollDown),a){const _=_s(i.current,y);O(C=>(C==null?void 0:C.top)===(_==null?void 0:_.top)&&(C==null?void 0:C.left)===(_==null?void 0:_.left)&&(C==null?void 0:C.width)===(_==null?void 0:_.width)&&(C==null?void 0:C.height)===(_==null?void 0:_.height)?C:_)}else O(_=>_===null?_:null)};o.useLayoutEffect(()=>{j()}),o.useEffect(()=>{const y=i.current;if(!y)return;let k=null,_=null;const C=()=>{k==null||k.removeEventListener("scroll",j),_==null||_.disconnect(),_=null,k=null},R=M=>{if(M===k){j();return}if(C(),k=M,!k){j();return}k.addEventListener("scroll",j,{passive:!0}),_=new ResizeObserver(()=>j()),_.observe(k),k.firstElementChild instanceof HTMLElement&&_.observe(k.firstElementChild),j()};R(w());const T=new MutationObserver(()=>{R(w())});return T.observe(y,{childList:!0,subtree:!0,characterData:!0}),window.addEventListener("resize",j),()=>{window.removeEventListener("resize",j),T.disconnect(),C()}},[a]);const N=y=>{const k=w();if(!k)return;const _=Math.max(k.clientHeight*.75,120);k.scrollBy({top:y==="up"?-_:_,behavior:"smooth"})},P=s.jsxs(s.Fragment,{children:[c&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"scrollable-region__fade scrollable-region__fade--top","aria-hidden":"true"}),s.jsx("button",{type:"button",className:"scrollable-region__edge scrollable-region__edge--top","aria-label":"Scroll up",onClick:()=>N("up"),children:s.jsx(d.Icon,{name:"chevron-up",size:16,color:"currentColor"})})]}),f&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"scrollable-region__fade scrollable-region__fade--bottom","aria-hidden":"true"}),s.jsx("button",{type:"button",className:"scrollable-region__edge scrollable-region__edge--bottom","aria-label":"Scroll down",onClick:()=>N("down"),children:s.jsx(d.Icon,{name:"chevron-down",size:16,color:"currentColor"})})]})]});return s.jsx("div",{ref:i,className:J("scrollable-region",e),style:r,"aria-label":l,children:a?s.jsxs(s.Fragment,{children:[t,p&&(c||f)&&s.jsx("div",{className:"scrollable-region__overlay",style:{top:p.top,left:p.left,width:p.width,height:p.height},children:P})]}):s.jsxs(s.Fragment,{children:[P,s.jsx("div",{ref:u,className:J("scrollable-region__viewport",n),children:t})]})})},fs=48,vs=({checklist:t})=>{const e=o.useRef(null),n=o.useRef(!1);return o.useLayoutEffect(()=>{const a=e.current;if(!a)return;const r=a.scrollHeight-a.scrollTop-a.clientHeight;(!n.current||r<=fs)&&(a.scrollTop=a.scrollHeight,n.current=!0)},[t]),t.length===0?s.jsx("p",{className:"agent-view__progress-empty",children:"No tasks to display."}):s.jsx(ze,{className:"agent-view__progress-scroll",scrollSelector:".agent-view__progress-list",children:s.jsx("ul",{ref:e,className:"agent-view__progress-list","aria-label":"Agent tasks",children:ps(t).map(a=>{const r=V[a.status];return s.jsxs("li",{className:J("agent-view__progress-item",`agent-view__progress-item--${a.status.replace(/_/g,"-")}`),children:[s.jsx(d.Icon,{name:r.icon,size:16,color:r.color,screenReaderText:`${r.label}:`}),s.jsxs("div",{className:"agent-view__progress-item-content",children:[s.jsx("span",{className:"agent-view__progress-label",children:a.task}),a.status!==B.complete&&s.jsx("span",{className:"agent-view__progress-description",children:a.description})]})]},a.task)})})})},ws=({prompts:t,classNamePrefix:e="agent-workspace",onSelect:n})=>t.length===0?null:s.jsx("div",{className:`${e}__chips`,children:t.map(a=>s.jsx("button",{type:"button",className:`${e}__chip`,onClick:()=>n(a),children:a},a))});class xs{constructor(e,n){this.connector=e,this.canSend=n.canSend,this.onTurn=n.onTurn,this.onAwaitingChange=n.onAwaitingChange}get canRate(){return!1}get canLoadHistory(){return!1}get canListInteractions(){return!1}get canSendNotification(){return!1}get ratingPopupUrls(){return{}}async sendMessage(e){var n,a;if(!this.canSend())return null;(n=this.onAwaitingChange)==null||n.call(this,!0);try{const r=await this.connector.sendMessage(e.userMessage,e.uploadFiles);return this.onTurn(r),{id:r.message.id,text:r.message.text,type:me.CHAT_RESPONSE_TYPE_AGENT,...r.message.followUpPrompts?{followUpPrompts:r.message.followUpPrompts}:{}}}catch{return{id:`error-${Date.now()}`,text:rs,type:me.CHAT_RESPONSE_TYPE_ERROR}}finally{(a=this.onAwaitingChange)==null||a.call(this,!1)}}async loadHistory(e){return null}async listInteractions(){return null}async rateMessage(e){}async sendNotification(e){return!1}}const ks=({connector:t,phase:e,chatHistory:n,chatSessionKey:a,startQuery:r,clarificationMessage:l,enableUpload:i=!1,onTurn:u,onAwaitingChange:c,onClarificationPrompt:v,onDismissClarification:f})=>{const h=o.useMemo(()=>new xs(t,{canSend:()=>e===H.running,onTurn:u,onAwaitingChange:c}),[t,e,u,c]),p=e!==H.running,O=e===H.running;return s.jsxs("section",{className:"agent-workspace__chat-body","aria-label":"Chat",children:[l&&s.jsxs("div",{className:"agent-workspace__clarification",role:"region","aria-label":"Agent question",children:[s.jsx("p",{className:"agent-workspace__clarification-text",children:l.text}),l.followUpPrompts&&s.jsx(ws,{prompts:l.followUpPrompts,onSelect:v}),s.jsx("button",{type:"button",className:"agent-workspace__clarification-dismiss",onClick:f,children:"Dismiss"})]}),s.jsx("div",{className:"agent-workspace__ask-arbor",children:s.jsx(ze,{scrollSelector:".chat-panel-message-list",children:s.jsx(me.ChatPanel,{connector:h,chatHistory:n,startQuery:r,lockConversation:p,enableUpload:i,speechEnabled:O,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:O?"Message the agent, paste a link, or attach a file…":"The agent is not accepting messages."},a)})}),e===H.stopped&&s.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[s.jsx(d.Icon,{name:"circle-alert",size:16,color:"var(--color-semantic-warning-600)"}),s.jsx("span",{children:"You stopped the agent. Its progress is saved in the checklist on the left."})]}),e===H.complete&&s.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[s.jsx(d.Icon,{name:"party-popper",size:16,color:"var(--color-semantic-success-600)"}),s.jsx("span",{children:"The agent has finished."})]})]})},bt=({item:t,depth:e,canRequestInput:n,onAttentionItemClick:a})=>{const r=V[t.status],l=t.status.replace(/_/g,"-"),i=t.status===B.hitl&&n&&a,u=s.jsxs("div",{className:"agent-workspace__task-row",children:[s.jsx(d.Icon,{name:r.icon,size:16,color:r.color,screenReaderText:`${r.label}:`}),s.jsxs("div",{className:"agent-workspace__task-content",children:[s.jsx("span",{className:"agent-workspace__task-label",children:t.task}),t.status!==B.complete&&t.description&&s.jsx("span",{className:"agent-workspace__task-description",children:t.description})]})]});return s.jsxs("li",{className:J("agent-workspace__task",`agent-workspace__task--${l}`,{"agent-workspace__task--child":e>0}),children:[i?s.jsx("button",{type:"button",className:"agent-workspace__task-button","aria-label":`Provide input for ${t.task}`,onClick:()=>a(t),children:u}):u,t.children&&t.children.length>0&&s.jsx("ul",{className:"agent-workspace__task-children",children:t.children.map(c=>s.jsx(bt,{item:c,depth:e+1,canRequestInput:n,onAttentionItemClick:a},c.task))})]})},pt=({items:t,ariaLabel:e,canRequestInput:n,onAttentionItemClick:a})=>s.jsx("ul",{className:"agent-workspace__task-list","aria-label":e,children:t.map(r=>s.jsx(bt,{item:r,depth:0,canRequestInput:n,onAttentionItemClick:a},r.task))}),ys=({checklist:t,isLoading:e,error:n,phase:a,canRequestInput:r,onAttentionItemClick:l})=>{const i=o.useMemo(()=>t?jt(t):null,[t]);return s.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--checklist","aria-label":"Checklist",children:[s.jsx("div",{className:"agent-workspace__panel-header",children:s.jsx(d.Heading,{level:4,children:"Checklist"})}),s.jsx("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:s.jsxs(ze,{children:[e&&s.jsxs("div",{className:"agent-workspace__loading",children:[s.jsx(d.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:he}),s.jsx("span",{children:he})]}),!e&&n&&s.jsx("p",{className:"agent-workspace__error",role:"alert",children:n}),!e&&!n&&i&&s.jsxs(s.Fragment,{children:[i.needsInput.length>0&&s.jsxs("div",{className:"agent-workspace__task-group",children:[s.jsx("p",{className:"agent-workspace__task-group-label",children:"Needs your input"}),s.jsx(pt,{items:i.needsInput,ariaLabel:"Tasks needing your input",canRequestInput:r,onAttentionItemClick:l})]}),i.tasks.length>0&&s.jsxs("div",{className:J("agent-workspace__task-group",{"agent-workspace__task-group--following":i.needsInput.length>0}),children:[i.needsInput.length>0&&s.jsx("p",{className:"agent-workspace__task-group-label",children:"Other tasks"}),s.jsx(pt,{items:i.tasks,ariaLabel:"Agent tasks",canRequestInput:r,onAttentionItemClick:l})]})]}),!e&&!n&&(!i||i.needsInput.length===0&&i.tasks.length===0)&&s.jsx("p",{className:"agent-workspace__empty",children:a===H.briefing?"Tasks will appear here once the agent starts.":"No tasks to display."})]})})]})},Ss=({resource:t,html:e,isLoading:n,error:a,onClose:r})=>{o.useEffect(()=>{if(!t)return;const i=d.SlideoverUtils.removeSlideover;return d.SlideoverUtils.removeSlideover=()=>{i(),r()},()=>{d.SlideoverUtils.removeSlideover=i}},[t,r]),o.useEffect(()=>{if(!t)return;const i=u=>{u.key==="Escape"&&d.SlideoverUtils.removeSlideover()};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[t]);const l=o.useMemo(()=>t?[{centerHeaderText:!1,children:s.jsxs("div",{className:"resource-preview-slideover__body",children:[n&&s.jsxs("div",{className:"resource-preview-slideover__status",children:[s.jsx(d.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:"Loading document"}),s.jsx("span",{children:"Loading document…"})]}),!n&&a&&s.jsx("p",{className:"resource-preview-slideover__error",role:"alert",children:a}),!n&&!a&&e!==null&&s.jsx("iframe",{className:"resource-preview-slideover__frame",title:t.title,sandbox:"",srcDoc:e})]})}]:[],[t,e,n,a]);return s.jsx("div",{className:"resource-preview-slideover",children:s.jsx(d.SlideoverManager,{slideovers:l})})},Ns={[re.mis_record]:{icon:"table",label:"Arbor MIS",color:"var(--color-brand-600)"},[re.document_html]:{icon:"file",label:"Document",color:"var(--color-semantic-caution-800)"},[re.file]:{icon:"file",label:"File",color:"var(--color-semantic-caution-800)"},[re.workflow]:{icon:"list-tree",label:"Workflow",color:"var(--color-semantic-warning-700)"},[re.link]:{icon:"link",label:"Link",color:"var(--color-semantic-info-700)"}},js=({resources:t,isLoading:e=!1,error:n=null,onOpenResource:a})=>s.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--documents","aria-label":"Resources",children:[s.jsxs("div",{className:"agent-workspace__panel-header",children:[s.jsx(d.Heading,{level:4,children:"Resources"}),s.jsx("span",{className:"agent-workspace__panel-count",children:t.length})]}),s.jsx("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:s.jsxs(ze,{children:[e&&s.jsxs("div",{className:"agent-workspace__loading",children:[s.jsx(d.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:"Loading resources"}),s.jsx("span",{children:"Loading resources…"})]}),!e&&n&&s.jsx("p",{className:"agent-workspace__error",role:"alert",children:n}),!e&&!n&&t.length>0&&s.jsx("ul",{className:"agent-workspace__resource-list","aria-label":"Agent resources",children:t.map(r=>{const l=Ns[r.type],i=r.misRecordUrl;return s.jsx("li",{className:"agent-workspace__resource",children:i?s.jsx("a",{className:"agent-workspace__resource-card",href:i,target:"_blank",rel:"noreferrer",onClick:u=>{u.preventDefault(),a(r)},children:s.jsx(mt,{resource:r,config:l,external:!0})}):s.jsx("button",{type:"button",className:"agent-workspace__resource-card",onClick:()=>a(r),children:s.jsx(mt,{resource:r,config:l})})},r.id)})}),!e&&!n&&t.length===0&&s.jsx("p",{className:"agent-workspace__empty",children:"No resources yet."})]})})]}),mt=({resource:t,config:e,external:n=!1})=>s.jsxs(s.Fragment,{children:[s.jsx("span",{className:`agent-workspace__resource-icon agent-workspace__resource-icon--${t.type}`,children:s.jsx(d.Icon,{name:e.icon,size:16,color:e.color,screenReaderText:`${e.label}:`})}),s.jsx("span",{className:"agent-workspace__resource-content",children:s.jsxs("span",{className:"agent-workspace__resource-top",children:[s.jsx("span",{className:"agent-workspace__resource-name",children:t.title}),s.jsx("span",{className:`agent-workspace__resource-badge agent-workspace__resource-badge--${t.type}`,children:e.label})]})}),n&&s.jsx(d.Icon,{name:"external-link",size:12,color:"var(--color-grey-500)",screenReaderText:"Opens in a new tab",className:"agent-workspace__resource-open"})]}),Be=t=>{const e=Date.parse(t);return Number.isFinite(e)?e:0},bs=new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"2-digit"}),Ze=t=>{const e=new Date(t);return Number.isFinite(e.getTime())?bs.format(e):t},Ue=t=>t.replace(/[A-Za-z0-9]+(?:[_-][A-Za-z0-9]+)+/g,e=>e.split(/[_-]/).map(n=>n.charAt(0).toUpperCase()+n.slice(1).toLowerCase()).join(" ")),Ne=(t,e)=>e<=1?0:t/(e-1)*100,At=t=>Math.max(t,0)+2,As=t=>t+1,Cs=(t,e)=>{if(e.length===0)return 50;const n=At(e.length),a=Ne(1,n),r=Ne(e.length,n),l=e.map(f=>Be(f.timestamp)),i=Math.min(...l),u=Math.max(...l);if(u<=i)return a;const c=(Be(t.timestamp)-i)/(u-i),v=Math.min(1,Math.max(0,c));return a+v*(r-a)},Es=8,Ts=20,Rs=(t,e=Es,n=Ts)=>{const a=new Map;if(t.length===0)return a;const r=[...t].sort((i,u)=>i.leftPercent-u.leftPercent||i.timestampMs-u.timestampMs||i.id.localeCompare(u.id)),l=[];for(const i of r){const u=l[l.length-1];u&&i.leftPercent-u[u.length-1].leftPercent<e?u.push(i):l.push([i])}for(const i of l){const u=[...i].sort((v,f)=>v.timestampMs-f.timestampMs||v.id.localeCompare(f.id)),c=(u.length-1)/2;u.forEach((v,f)=>{a.set(v.id,(f-c)*n)})}return a},De=(t,e=0)=>({left:`calc(${t/100} * (100% - var(--agent-timeline-node-size)) + (var(--agent-timeline-node-size) / 2) + ${e}px)`,transform:"translateX(-50%)"}),Is=t=>t.type!=="message-sent",Os=({timeline:t,isLoading:e,error:n,onOpenChatSession:a})=>{const r=((t==null?void 0:t.actionLog)??[]).filter(Is),l=(t==null?void 0:t.chatSessions)??[],i=!e&&!n&&r.length===0&&l.length===0,u=At(r.length),c=r.map((h,p)=>({id:`action-${h.timestamp}-${p}`,leftPercent:Ne(As(p),u),timestampMs:Be(h.timestamp)})),v=l.map(h=>({id:h.sessionId,leftPercent:Cs(h,r),timestampMs:Be(h.timestamp)})),f=Rs([...c,...v]);return s.jsxs("section",{className:"agent-workspace__timeline","aria-label":"Agent timeline",children:[e&&s.jsx("p",{className:"agent-workspace__timeline-status",role:"status",children:"Loading timeline…"}),n&&s.jsx("p",{className:"agent-workspace__timeline-status",role:"alert",children:n||St}),i&&s.jsx("p",{className:"agent-workspace__timeline-status",role:"status",children:"No timeline activity yet."}),!e&&!n&&!i&&s.jsxs("div",{className:"agent-timeline",children:[s.jsx("div",{className:"agent-timeline__track","aria-hidden":"true"}),s.jsxs("div",{className:"agent-timeline__station agent-timeline__station--terminus",style:De(Ne(0,u)),children:[s.jsx("span",{className:"agent-timeline__station-node agent-timeline__station-node--terminus","aria-hidden":"true",children:s.jsx(d.Icon,{name:"arrow-right-from-line",size:16,color:"currentColor"})}),s.jsx("span",{className:"agent-timeline__terminus-label",children:"Start"})]}),r.map((h,p)=>{const O=`action-${h.timestamp}-${p}`,w=c[p].leftPercent,j=h.type==="checklist-updated",N=h.type==="status-transition",P=j?"checklist":N?"status":"note";return s.jsxs("div",{className:`agent-timeline__station agent-timeline__station--${P}`,style:De(w,f.get(O)??0),children:[s.jsxs("button",{type:"button",className:`agent-timeline__station-node agent-timeline__station-node--${P}`,"aria-label":`${Ue(h.type)}: ${Ue(h.entry)}`,children:[j&&s.jsx(d.Icon,{name:"check-solid",size:16,color:"currentColor"}),N&&s.jsx(d.Icon,{name:"iteration-ccw",size:16,color:"currentColor"})]}),s.jsxs("div",{className:"agent-timeline__pill",role:"tooltip",children:[s.jsx("strong",{className:"agent-timeline__pill-type",children:Ue(h.type)}),s.jsx("span",{className:"agent-timeline__pill-entry",children:Ue(h.entry)}),s.jsx("span",{className:"agent-timeline__pill-entry",children:Ze(h.timestamp)})]})]},O)}),s.jsxs("div",{className:"agent-timeline__station agent-timeline__station--terminus",style:De(Ne(u-1,u)),children:[s.jsx("span",{className:"agent-timeline__station-node agent-timeline__station-node--terminus","aria-hidden":"true",children:s.jsx(d.Icon,{name:"flag",size:16,color:"currentColor"})}),s.jsx("span",{className:"agent-timeline__terminus-label",children:"Finish"})]}),l.map((h,p)=>{const O=v[p].leftPercent;return s.jsxs("div",{className:"agent-timeline__chat-station",style:De(O,f.get(h.sessionId)??0),children:[s.jsx("button",{type:"button",className:"agent-timeline__chat-node","aria-label":`Open chat session from ${Ze(h.timestamp)}`,onClick:()=>a(h.sessionId),children:s.jsx(d.Icon,{name:"sparkles",size:16,color:"currentColor"})}),s.jsxs("div",{className:"agent-timeline__pill",role:"tooltip",children:[s.jsx("strong",{className:"agent-timeline__pill-type",children:"Chat session"}),s.jsx("span",{className:"agent-timeline__pill-entry",children:Ze(h.timestamp)})]})]},h.sessionId)})]})]})},Ps=["I'll get the details and come back to you","Skip this for now"],Ls=t=>{var n;const e=(n=t.prompt)!=null&&n.trim()?t.prompt.trim():`I need a bit more from you on "${t.task}". ${t.description} What can you tell me?`;return{id:`clarification-${Date.now()}`,author:Z.agent,text:e,followUpPrompts:t.clarificationPrompts??Ps}},ge=t=>({id:t.id,text:t.text,type:t.author===Z.user?me.CHAT_RESPONSE_TYPE_USER:t.author===Z.system?me.CHAT_RESPONSE_TYPE_INFO:me.CHAT_RESPONSE_TYPE_AGENT,...t.followUpPrompts?{followUpPrompts:t.followUpPrompts}:{}});class pe extends Error{constructor(e,n,a){super(a??`Agent service request failed (${e})`),this.name="AgentServiceError",this.status=e,this.detail=n}}const Ms="/api/v1",$={agentDefinitions:"/agent-definitions",agents:"/agents",conversations:"/conversations",tripOptions:"/trip-options",demoDataset:"/demo/dataset"},F={GET:"GET",POST:"POST"},Us={error:"error"},Ds={user:"user"},oe={acceptJson:"application/json",acceptHtml:"text/html",acceptEventStream:"text/event-stream",contentTypeJson:"application/json",arborApplicationUrl:"X-Arbor-Application-Url"},$s=100,Ct=t=>{switch(t){case gt.cancelled:return A.failed;case gt.archived:return A.complete;case A.hitl:case A.complete:case A.failed:case A["generating-a-response"]:return t;default:return A["generating-a-response"]}},Et=t=>{switch(t){case Xe.requires_attention:return B.hitl;case Xe.in_progress:case Xe.available:return B["generating-a-response"];case B.failed:case B.complete:case B.hitl:case B["generating-a-response"]:return t;default:return B["generating-a-response"]}},nt=t=>({ref:t.name,display_name:t.display_name,agent_intent:t.agent_intent??"",description:t.description}),Hs=t=>({id:t.id,name:t.name,...t.has_run_before?{hasRunBefore:t.has_run_before}:{}}),Bs=new Set(Object.values(re)),zs=t=>Bs.has(t)?t:re.document_html,Tt=t=>({id:t.id,type:zs(t.type),title:t.title,createdDatetime:t.created_datetime,lastUpdatedDatetime:t.last_updated_datetime,misRecordUrl:t.mis_record_url}),Rt=t=>({resources:t.resources.map(Tt),pageNumber:t.page_number,pageSize:t.page_size,totalRecords:t.total_records}),It=t=>({actionLog:(t.action_log??[]).map(e=>({timestamp:e.timestamp,type:e.type,entry:e.entry,origin:e.origin})),chatSessions:(t.chat_sessions??[]).map(e=>({sessionId:e.session_id,timestamp:e.timestamp}))}),tt=t=>{var n;const e=t.invocation_id??t.id;return{id:t.id,invocation_id:e,agent_definition_ref:t.agent_definition_ref,...t.agent_intent?{agent_intent:t.agent_intent}:{},invocation_name:((n=t.invocation_name)==null?void 0:n.trim())||t.agent_definition_ref,application_id:t.application_id,...t.application_name?{application_name:t.application_name}:{},created_by:t.created_by,status:Ct(t.status),context_ref:t.context_ref??null,checklist_ref:t.checklist_ref??null}},at=t=>{var e;return{task:t.task??t.name??t.label??os,status:Et(t.status),description:t.description??"",...t.prompt?{prompt:t.prompt}:{},...(e=t.follow_up_prompts)!=null&&e.length?{clarificationPrompts:t.follow_up_prompts}:{}}},Fs=t=>Array.isArray(t)?t:t.checklist_items??t.checklist??t.items??[],rt=(t,e,n)=>{var l;const a=!Array.isArray(e)&&(e.opening_message||(l=e.opening_follow_up_prompts)!=null&&l.length)?e:n,r=a?je(a):void 0;return{invocation_id:t,checklist:Fs(e).map(at),...r?{openingMessage:r}:{}}},Ot=(t,e)=>{const n=je(e);return{invocation_id:e.invocation_id??t,checklist:(e.checklist_items??[]).map(at),...n?{openingMessage:n}:{}}},je=t=>{var n,a;const e=(n=t.opening_message)==null?void 0:n.trim();if(e)return{id:yt,author:Z.agent,text:e,...(a=t.opening_follow_up_prompts)!=null&&a.length?{followUpPrompts:t.opening_follow_up_prompts}:{}}},Pt=t=>t.filter(e=>(e.role==="user"||e.role==="assistant")&&typeof e.content=="string"&&e.content.length>0&&e.message_type!=="tool_request").map(e=>({id:e.message_id,author:e.role==="user"?Z.user:Z.agent,text:e.content})),qs=/:invocationId\b/g,Gs=/:resourceId\b/g,Js=t=>t.trim().replace(/^Bearer\s+/i,""),Ks=t=>t.endsWith("/")?t.slice(0,-1):t;class Fe{constructor(e){var a;this.baseUrl=Ks(e.baseUrl??"");const n=(a=e.token)==null?void 0:a.trim();this.token=n?Js(n):void 0,this.customHeaders=e.headers,this.urls=e.urls??{},this.fetchImpl=e.fetch??globalThis.fetch.bind(globalThis)}setHeaders(e){this.customHeaders=e}async listAgentDefinitions(){return(await this.request(F.GET,this.resolveUrl("agentDefinitions",$.agentDefinitions))).agent_definitions??[]}getAgentDefinition(e){return this.request(F.GET,this.apiUrl(`${$.agentDefinitions}/${encodeURIComponent(e)}`))}listTripOptions(){return this.request(F.GET,this.apiUrl($.tripOptions))}getDataset(){return this.request(F.GET,this.apiUrl($.demoDataset))}setDataset(e){return this.request(F.POST,this.apiUrl($.demoDataset),{dataset:e})}listAgents(e={}){const n=new URLSearchParams;e.status&&n.set("status",e.status),e.agentDefinitionRef&&n.set("agent_definition_ref",e.agentDefinitionRef);const a=n.toString()?`?${n.toString()}`:"";return this.request(F.GET,`${this.resolveUrl("agents",$.agents)}${a}`)}createAgent(e,n={}){var i,u;const a={agent_definition_ref:e},r=(i=n.invocationName)==null?void 0:i.trim(),l=(u=n.agentIntent)==null?void 0:u.trim();return r&&(a.invocation_name=r),l&&(a.agent_intent=l),this.request(F.POST,this.resolveUrl("agents",$.agents),a)}getAgent(e){return this.request(F.GET,this.resolveUrl("agent",`${$.agents}/${encodeURIComponent(e)}`,e))}getAgentChecklist(e){return this.request(F.GET,this.resolveUrl("agentChecklist",`${$.agents}/${encodeURIComponent(e)}/checklist`,e))}getAgentResources(e,n={}){const a=new URLSearchParams;n.pageNumber!==void 0&&a.set("page_number",String(n.pageNumber)),n.pageSize!==void 0&&a.set("page_size",String(n.pageSize)),n.type&&a.set("type",n.type);const r=a.toString(),l=this.resolveUrl("agentResources",`${$.agents}/${encodeURIComponent(e)}/resources`,e);return this.request(F.GET,r?`${l}?${r}`:l)}async listAllAgentResources(e){const n=$s;let a=1;const r=[];let l=Number.POSITIVE_INFINITY;for(;r.length<l;){const i=Rt(await this.getAgentResources(e,{pageNumber:a,pageSize:n}));if(l=i.totalRecords,i.resources.length===0||(r.push(...i.resources),r.length>=l))break;a+=1}return r}getAgentResourceHtml(e,n){return this.requestText(F.GET,this.resolveResourceHtmlUrl(e,n))}getAgentTimeline(e){return this.request(F.GET,this.resolveUrl("agentTimeline",`${$.agents}/${encodeURIComponent(e)}/agent-timeline`,e))}getAgentContext(e){return this.request(F.GET,this.apiUrl(`${$.agents}/${encodeURIComponent(e)}/context`))}cancelAgent(e){return this.request(F.POST,this.apiUrl(`${$.agents}/${encodeURIComponent(e)}/cancel`))}archiveAgent(e){return this.request(F.POST,this.apiUrl(`${$.agents}/${encodeURIComponent(e)}/archive`))}getConversation(e){return this.request(F.GET,this.resolveUrl("agentConversation",`${$.conversations}/${encodeURIComponent(e)}`,e))}async chat(e,n,a={}){const r=!!(a.uploadFiles&&a.uploadFiles.length>0),l=await this.fetchImpl(this.resolveUrl("agentChat",`${$.agents}/${encodeURIComponent(e)}/chat`,e),{method:F.POST,headers:{...this.customHeaders,...this.authHeaders(),Accept:oe.acceptEventStream,...r?{}:{"Content-Type":oe.contentTypeJson}},body:r?Vs(n,a.uploadFiles??[]):JSON.stringify(n),signal:a.signal});if(!l.ok)throw await this.toError(l);if(!l.body)throw new pe(l.status,null,"Chat response contained no stream body");return this.consumeSse(l.body,a.onEvent)}authHeaders(){return this.token?{Authorization:`Bearer ${this.token}`}:{}}apiUrl(e){return`${this.baseUrl}${Ms}${e}`}resolveUrl(e,n,a,r){const l=this.urls[e];if(!l)return this.apiUrl(n);let i=l;return a&&(i=i.replace(qs,encodeURIComponent(a))),r&&(i=i.replace(Gs,encodeURIComponent(r))),i}resolveResourceHtmlUrl(e,n){return this.urls.agentResourceHtml?this.resolveUrl("agentResourceHtml",`${$.agents}/${encodeURIComponent(e)}/resources/${encodeURIComponent(n)}`,e,n):this.urls.agentResources?`${this.resolveUrl("agentResources",`${$.agents}/${encodeURIComponent(e)}/resources`,e).replace(/\/$/,"")}/${encodeURIComponent(n)}`:this.apiUrl(`${$.agents}/${encodeURIComponent(e)}/resources/${encodeURIComponent(n)}`)}async request(e,n,a){const r=await this.fetchImpl(n,{method:e,headers:{...this.customHeaders,...this.authHeaders(),Accept:oe.acceptJson,...a===void 0?{}:{"Content-Type":oe.contentTypeJson}},...a===void 0?{}:{body:JSON.stringify(a)}});if(!r.ok)throw await this.toError(r);if(r.status!==204)return await r.json()}async requestText(e,n){const a=await this.fetchImpl(n,{method:e,headers:{...this.customHeaders,...this.authHeaders(),Accept:oe.acceptHtml}});if(!a.ok)throw await this.toError(a);return a.text()}async toError(e){let n=null;try{n=await e.json()}catch{}return new pe(e.status,n,`Agent service request failed (${e.status} ${e.statusText})`)}async consumeSse(e,n){const a=e.getReader(),r=new TextDecoder;let l="",i;const u=c=>{const{event:v,data:f}=Ws(c);if(f===null)return;if(v===Us.error){const p=_t(f);throw new pe(502,p,(p==null?void 0:p.message)??"Chat stream error")}const h=_t(f);h&&(i=h,n==null||n(h))};for(;;){const{done:c,value:v}=await a.read();if(c)break;l+=r.decode(v,{stream:!0});const f=l.split(`
2
2
 
3
- `);l=f.pop()??"";for(const h of f)u(h)}if(l.trim()&&u(l),!i)throw new de(502,null,"Chat stream ended without any events");return i}}const Gn=t=>{let e=null;const s=[];for(const a of t.split(`
4
- `)){const r=a.trimEnd();r.startsWith("event:")?e=r.slice(6).trim():r.startsWith("data:")&&s.push(r.slice(5).trim())}return{event:e,data:s.length>0?s.join(`
5
- `):null}},ut=t=>{try{return JSON.parse(t)}catch{return}};function qn(t,e){const s=new FormData;s.append("body",JSON.stringify(t));for(const a of e)s.append("files",a,a.name);return s}const Kn={id:ft,author:Y.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 gt=0;const Jn=t=>(gt+=1,`${t}-${Date.now()}-${gt}`),Wn=t=>{const e=t.destination?` to ${t.destination}`:"";return`Let's get started on ${t.tripName.trim()||t.destination.trim()||"this task"}${e}. What will you do first?`};class Tt{constructor(e,s,a={}){this.seededChecklist=[],this.client=e,this.agentId=s,this.chatId=a.chatId??s,this.opening=a.openingMessage??Kn,this.model=a.model}openingMessage(){return this.opening}async bootstrapConversation(){const e=await this.client.getConversation(this.chatId),s=Et(e.messages);return s.length===0?[this.opening]:s}async start(e){return{...await this.exchange(Wn(e)),phase:U.running}}sendMessage(e,s){return this.exchange(e,s)}async stop(){}seedChecklist(e){this.seededChecklist=e}async exchange(e,s){var i;const a=[{role:Pn.user,content:e}],r=await this.client.chat(this.agentId,{messages:a,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}]:[]),l={id:r.event_id||Jn("msg-agent"),author:Y.agent,text:r.message.content,...(i=r.follow_up_prompts)!=null&&i.length?{followUpPrompts:r.follow_up_prompts}:{}};try{const u=await this.client.getAgent(this.agentId),{checklist:c}=Ct(this.agentId,u);return this.seededChecklist=c,{message:l,checklist:c}}catch{return{message:l,...this.seededChecklist.length?{checklist:this.seededChecklist}:{}}}}}const nt=(t,e)=>s=>{var a,r;return new Tt(t,s.invocation_id,{model:e==null?void 0:e.model,chatId:((a=e==null?void 0:e.resolveChatId)==null?void 0:a.call(e,s))??(e==null?void 0:e.chatId)??s.invocation_id,openingMessage:((r=e==null?void 0:e.resolveOpeningMessage)==null?void 0:r.call(e,s))??(e==null?void 0:e.openingMessage)})},Rt=t=>t instanceof de?t.message:t instanceof TypeError?"Network error while contacting the agent service.":t instanceof Error&&t.message?t.message:wt,Vn=t=>{const e={};for(const s of t){const a=ke(s);if(!a)continue;const r=s.invocation_id??s.id;e[r]=a,e[s.id]=a}return e},Yn=t=>JSON.stringify(t),Ye=(t,e)=>JSON.stringify(t)===JSON.stringify(e),It=t=>{const{jwt:e,headers:s,urls:a}=t,r=JSON.stringify(s??{}),l=Yn(a),i=o.useMemo(()=>new He({token:e,headers:s,urls:a}),[e,l]);o.useLayoutEffect(()=>{i.setHeaders(s)},[i,r]);const[u,c]=o.useState([]),[w,f]=o.useState([]),[h,p]=o.useState({}),[O,v]=o.useState("loading"),[N,S]=o.useState(null),[P,k]=o.useState(0),x=o.useCallback((R,$)=>{const I=R.map(Xe),F=$.map(Ze),K=Vn(R);c(B=>Ye(B,I)?B:I),f(B=>Ye(B,F)?B:F),p(B=>Ye(B,K)?B:K),v("idle"),S(null)},[]);o.useEffect(()=>{let R=!1;return v("loading"),S(null),(async()=>{try{const[$,I]=await Promise.all([i.listAgents(),i.listAgentDefinitions()]);if(R)return;x($,I)}catch($){if(R)return;c([]),f([]),p({}),v("error"),S(Rt($))}})(),()=>{R=!0}},[x,i,P]);const _=o.useCallback(()=>{k(R=>R+1)},[]),A=o.useCallback(async()=>{try{const[R,$]=await Promise.all([i.listAgents(),i.listAgentDefinitions()]);x(R,$)}catch{}},[x,i]),T=o.useCallback(async R=>{const[$,I]=await Promise.all([i.getAgentChecklist(R),i.getAgent(R).catch(()=>null)]);return tt(R,$,I??void 0)},[i]),E=o.useCallback(async R=>i.listAllAgentResources(R),[i]),D=o.useCallback(async({definition:R,invocationName:$})=>{const I=await i.createAgent(R.ref,{invocationName:$}),F=await i.getAgent(I.id),K=Xe(F),B=ke(F);return c(L=>[K,...L]),B&&p(L=>({...L,[K.invocation_id]:B,[K.id]:B})),K},[i]),V=o.useMemo(()=>nt(i,{resolveOpeningMessage:R=>h[R.invocation_id]??h[R.id]}),[i,h]);return{agents:u,agentDefinitions:w,loadState:O,loadError:N,reload:_,refresh:A,fetchAgentChecklist:T,fetchAgentResources:E,createAgent:D,chatConnector:V}},Xn=t=>JSON.stringify(t),Ot=t=>{const{agent:e,jwt:s,headers:a,urls:r,chatId:l}=t,i=JSON.stringify(a??{}),u=Xn(r),c=o.useMemo(()=>new He({token:s,headers:a,urls:{agent:r.agentUrl,agentChecklist:r.agentChecklistUrl,...r.agentResourcesUrl?{agentResources:r.agentResourcesUrl}:{},...r.agentTimelineUrl?{agentTimeline:r.agentTimelineUrl}:{},agentChat:r.agentChatUrl,agentConversation:r.agentConversationUrl}}),[s,u]);o.useLayoutEffect(()=>{c.setHeaders(a)},[c,i]);const w=o.useCallback(async v=>{const[N,S]=await Promise.all([c.getAgentChecklist(v),c.getAgent(v).catch(()=>null)]);return tt(v,N,S??void 0)},[c]),f=o.useCallback(async v=>c.listAllAgentResources(v),[c]),h=o.useCallback(async(v,N)=>c.getAgentResourceHtml(v,N),[c]),p=o.useCallback(async v=>{const N=await c.getAgentTimeline(v);return At(N)},[c]);return{connector:o.useMemo(()=>nt(c,{chatId:l??e.invocation_id})(e),[c,e.invocation_id,l]),fetchAgentChecklist:w,fetchAgentResources:f,fetchAgentResourceHtml:h,fetchAgentTimeline:p}},Qn=3e4,Zn=(t,e)=>{const s=t.hasRunBefore?e||"This trip":t.tripName.trim()||"A new trip",a=t.destination?` to ${t.destination}`:"",r=t.hasRunBefore?" It has run before.":"";return`${s}${a}.${r}`.trim()},es=t=>{switch(t){case b.failed:return U.stopped;case b.complete:return U.complete;default:return U.running}},ht=(t,e)=>{e([le(t)])},ts=(t,e)=>t.length===e.length&&t.every((s,a)=>{const r=e[a];return r!==void 0&&s.id===r.id&&s.text===r.text}),Pt=({agent:t,invocationId:e,open:s,onClose:a,jwt:r,headers:l,agentUrl:i,agentChecklistUrl:u,agentResourcesUrl:c,agentTimelineUrl:w,agentChatUrl:f,agentConversationUrl:h,chatId:p,enableUpload:O,initialBrief:v,initialPhase:N,initialChecklist:S})=>{const[P,k]=o.useState(p??e),[x,_]=o.useState("chat"),[A,T]=o.useState(!1),{connector:E,fetchAgentChecklist:D,fetchAgentResources:V,fetchAgentResourceHtml:R,fetchAgentTimeline:$}=Ot({agent:{...t,invocation_id:e},jwt:r,headers:l,chatId:P,urls:{agentUrl:i,agentChecklistUrl:u,agentResourcesUrl:c,agentTimelineUrl:w,agentChatUrl:f,agentConversationUrl:h}}),I=o.useRef(E),[F,K]=o.useState(N??(v?U.running:es(t.status))),[B,L]=o.useState([]),[ye,re]=o.useState(0),[ge,oe]=o.useState(),[Be,X]=o.useState(null),[ze,he]=o.useState([]),[Z,pe]=o.useState(!1),[Se,ie]=o.useState(null),[Ne,je]=o.useState(null),[be,me]=o.useState(null),[Ae,_e]=o.useState(!1),[Fe,fe]=o.useState(null),[ee,Ce]=o.useState(null),[m,j]=o.useState(!1),[y,G]=o.useState(null),[te,Q]=o.useState(S??null),[ne,ve]=o.useState(!1),[Ut,st]=o.useState(null),[Ee,Ge]=o.useState(!1),[Te,Dt]=o.useState(!1),[Re,$t]=o.useState(!1),at=o.useRef(Ee);o.useEffect(()=>{I.current=E},[E]),o.useEffect(()=>{at.current=Ee},[Ee]),o.useEffect(()=>{k(p??e),_("chat"),T(!1),L([]),re(g=>g+1)},[e,p]),o.useEffect(()=>{if(!s||v)return;const g=I.current.bootstrapConversation;if(!g){ht(I.current.openingMessage(),L);return}let C=!1;return Ge(!0),(async()=>{try{const J=await g.call(I.current);if(C)return;L(J.map(le))}catch{C||ht(I.current.openingMessage(),L)}finally{C||Ge(!1)}})(),()=>{C=!0}},[s,v,e,P]),o.useEffect(()=>{if(!s||v)return;const g=window.setInterval(()=>{const C=I.current.bootstrapConversation;C&&(async()=>{try{const J=await C.call(I.current);if(at.current)return;const we=J.map(le);L(ot=>ts(ot,we)?ot:we)}catch{}})()},Qn);return()=>{window.clearInterval(g)}},[s,v,e,P]);const Ie=o.useCallback(()=>{c&&(async()=>{try{const g=await V(e);he(g),ie(null)}catch{}})()},[c,V,e]),Ht=o.useCallback(g=>{g.checklist&&Q(g.checklist),g.phase&&K(g.phase),Ie()},[Ie]);o.useEffect(()=>{var g,C;!s||v||S&&S.length>0&&((C=(g=I.current).seedChecklist)==null||C.call(g,S))},[s,v,S]),o.useEffect(()=>{if(!s||v)return;let g=!1;return ve(!(S!=null&&S.length)),st(null),(async()=>{var C,J;try{const we=await D(e);if(g)return;S!=null&&S.length||(Q(we.checklist),(J=(C=I.current).seedChecklist)==null||J.call(C,we.checklist))}catch{!g&&!(S!=null&&S.length)&&st(Me)}finally{g||ve(!1)}})(),()=>{g=!0}},[s,e,v,S,D]),o.useEffect(()=>{if(!s||!c)return;let g=!1;return pe(!0),ie(null),(async()=>{try{const C=await V(e);g||he(C)}catch{g||ie(Qt)}finally{g||pe(!1)}})(),()=>{g=!0}},[s,e,c,V]);const Bt=o.useCallback(()=>{je(null),me(null),fe(null),_e(!1)},[]),zt=o.useCallback(g=>{if(g.misRecordUrl){window.open(g.misRecordUrl,"_blank","noopener,noreferrer");return}je(g),me(null),fe(null),_e(!0),(async()=>{try{const C=await R(e,g.id);me(C)}catch{fe(Zt)}finally{_e(!1)}})()},[R,e]);o.useEffect(()=>{if(!s||!w)return;let g=!1;return j(!0),G(null),(async()=>{try{const C=await $(e);g||Ce(C)}catch{g||G(vt)}finally{g||j(!1)}})(),()=>{g=!0}},[s,e,w,$]),o.useEffect(()=>{if(!s||!v)return;let g=!1;const C={id:`user-brief-${Date.now()}`,author:Y.user,text:Zn(v,t.invocation_name)};return(async()=>{const J=await I.current.start(v);g||(L([le(I.current.openingMessage()),le(C),le(J.message)]),J.checklist&&Q(J.checklist),K(J.phase??U.running),Ie())})(),()=>{g=!0}},[s,v,t.invocation_name,e,Ie]);const Ft=o.useCallback(g=>{X(Rn(g))},[]),qe=p??e,Oe=ee==null?void 0:ee.chatSessions,rt=Oe!=null&&Oe.length?Oe.reduce((g,C)=>Date.parse(C.timestamp)<Date.parse(g.timestamp)?C:g).sessionId:void 0,Ke=o.useCallback(()=>{_("chat"),T(!1),P!==qe&&(k(qe),L([]),re(g=>g+1))},[P,qe]),Gt=o.useCallback(g=>{if(g===rt){Ke();return}k(g),T(!0),_("chat"),L([]),re(C=>C+1)},[rt,Ke]),qt=o.useCallback(g=>{X(null),oe(g),re(C=>C+1)},[]),Kt=o.useCallback(async()=>{await I.current.stop(),K(U.stopped)},[]),Jt=te;return n.jsxs(d.Modal,{open:s,closeHandler:a,hideCloseButton:!0,className:"agent-workspace",children:[n.jsxs(d.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(d.Icon,{name:"ask-arbor",size:24})}),n.jsx(d.Modal.Title,{children:t.invocation_name}),n.jsx("span",{className:q("agent-workspace__phase",`agent-workspace__phase--${F}`),children:nn[F]})]}),n.jsxs("div",{className:"agent-workspace__header-actions",children:[n.jsx(d.Button,{variant:Te?"secondary":"primary",size:"S",iconLeftName:"clipboard-list",iconLeftScreenReaderText:"Toggle checklist","aria-pressed":!Te,onClick:()=>Dt(g=>!g),children:"Checklist"}),n.jsx(d.Button,{variant:Re?"secondary":"primary",size:"S",iconLeftName:"files",iconLeftScreenReaderText:"Toggle resources","aria-pressed":!Re,onClick:()=>$t(g=>!g),children:"Resources"}),n.jsx(d.Button,{variant:"secondary",size:"S",iconLeftName:"x",iconLeftScreenReaderText:"Close",onClick:a,children:"Close"})]})]}),n.jsxs(d.Modal.Body,{className:q("agent-workspace__body",{"agent-workspace__body--no-checklist":Te,"agent-workspace__body--no-resources":Re}),children:[" ",n.jsxs("section",{className:q("agent-workspace__panel","agent-workspace__panel--chat",{"agent-workspace__panel--timeline":!!w&&x==="timeline"}),"aria-label":"Agent",children:[n.jsxs("div",{className:"agent-workspace__panel-header",children:[n.jsx(d.Heading,{level:4,children:"Agent"}),F===U.running&&n.jsx(d.Button,{className:"agent-workspace__panel-header-action",variant:"secondary-destructive",size:"S",iconLeftName:"circle-x",iconLeftScreenReaderText:"Stop",onClick:()=>void Kt(),children:"Stop agent"})]}),w&&n.jsxs(d.Tabs,{className:"agent-workspace__center-tabs","aria-label":"Center panel",children:[n.jsx(d.Tabs.Item,{active:x==="chat",tabElementProps:{id:"agent-center-tab-chat",onClick:()=>_("chat")},children:"Chat"}),n.jsx(d.Tabs.Item,{active:x==="timeline",tabElementProps:{id:"agent-center-tab-timeline",onClick:()=>_("timeline")},children:"Timeline"})]}),w&&x==="chat"&&A&&n.jsx("div",{className:"agent-workspace__center-back",children:n.jsx(d.Button,{variant:"tertiary",size:"S",iconLeftName:"arrow-left",iconLeftScreenReaderText:"Back to main chat",onClick:Ke,children:"Back to main chat"})}),w&&x==="timeline"&&n.jsx(En,{timeline:ee,isLoading:m,error:y,onOpenChatSession:Gt}),n.jsx("div",{className:"agent-workspace__chat-keep-alive",hidden:!!w&&x!=="chat",children:n.jsx(fn,{connector:E,phase:F,chatHistory:B,chatSessionKey:ye,startQuery:ge,clarificationMessage:Be,enableUpload:O,onTurn:Ht,onAwaitingChange:Ge,onClarificationPrompt:qt,onDismissClarification:()=>X(null)})})]}),!Te&&n.jsx(vn,{checklist:Jt,isLoading:ne,error:Ut,phase:F,canRequestInput:F===U.running&&!Ee,onAttentionItemClick:Ft}),!Re&&n.jsx(kn,{resources:ze,isLoading:Z,error:Se,onOpenResource:zt}),n.jsx(wn,{resource:Ne,html:be,isLoading:Ae,error:Fe,onClose:Bt})]})]})},ns="Unable to load agent definitions. Please try again.",ss="Unable to start the agent.",pt="Loading agents…",Lt=({open:t,onClose:e,onStart:s,agentDefinitions:a,definitionsState:r="idle",definitionsError:l=null,onRetryDefinitions:i,embedded:u=!1})=>{const[c,w]=o.useState(void 0),[f,h]=o.useState(""),[p,O]=o.useState(!1),[v,N]=o.useState(null),S=[...a].sort((T,E)=>T.display_name.localeCompare(E.display_name)).map(T=>({value:T.ref,label:T.display_name}));o.useEffect(()=>{t&&(w(void 0),h(""),O(!1),N(null))},[t]);const P=c!==void 0&&f.trim().length>0,k=o.useCallback(T=>{const E=a.find(D=>D.ref===T[0]);E&&w(E)},[a]),x=o.useCallback(async()=>{if(!(!c||!P||p)){O(!0),N(null);try{await s({definition:c,invocationName:f.trim()})}catch(T){N(T instanceof Error?T.message:ss)}finally{O(!1)}}},[P,c,f,p,s]);if(r==="idle"&&a.length===0||!t)return null;const _=n.jsxs("div",{className:"new-agent__header-title",children:[n.jsx("span",{className:"new-agent__header-avatar","aria-hidden":"true",children:n.jsx(d.Icon,{name:"ask-arbor",size:24})}),u?n.jsx("h2",{className:"new-agent__title",children:"Start an agent"}):n.jsx(d.Modal.Title,{children:"Start an agent"})]});let A;return r==="loading"?A=n.jsxs("div",{className:"new-agent__state","aria-live":"polite",children:[n.jsx(d.Icon,{name:"loader",size:24,color:"var(--color-brand-600)",className:"new-agent__spinner",screenReaderText:pt}),n.jsx("p",{className:"new-agent__state-message",children:pt})]}):r==="error"?A=n.jsxs("div",{className:"new-agent__state new-agent__state--error",role:"alert",children:[n.jsx(d.Icon,{name:"triangle-alert",size:24,color:"var(--color-semantic-destructive-600)"}),n.jsx("p",{className:"new-agent__state-message",children:l??ns}),i?n.jsx(d.Button,{variant:"secondary",size:"S",onClick:i,children:"Try again"}):null]}):A=n.jsxs("form",{className:"new-agent__form","aria-label":"Start an agent",onSubmit:T=>{T.preventDefault(),P&&!p&&x()},children:[n.jsxs("div",{className:"new-agent__type-field",children:[n.jsx("label",{className:"new-agent__type-label",htmlFor:"new-agent-type",children:"What would you like your agent to do?"}),n.jsx(d.SelectDropdown,{id:"new-agent-type",placeholder:"Which agent would you like to start?",options:S,selectedValues:c?[c.ref]:[],onSelectionChange:k})]}),n.jsxs("div",{className:"new-agent__type-field",children:[n.jsx("label",{className:"new-agent__type-label",htmlFor:"new-agent-invocation-name",children:"Name"}),n.jsx(d.TextInput,{id:"new-agent-invocation-name",value:f,placeholder:"What would you like to call your agent?",onChange:T=>h(T.target.value)})]}),v?n.jsx("p",{className:"new-agent__error",role:"alert",children:v}):null,n.jsx("div",{className:"new-agent__actions",children:n.jsx(d.Button,{type:"submit",variant:"primary",className:q("new-agent__start-button",{"new-agent__start-button--starting":p}),disabled:!P||p,iconLeftName:p?"loader":"sparkles",iconLeftScreenReaderText:p?"Starting":void 0,children:p?"Starting…":"Start"})})]}),u?n.jsxs("div",{className:q("new-agent","new-agent--embedded"),children:[n.jsx("div",{className:"new-agent__header",children:_}),n.jsx("div",{className:"new-agent__body",children:A})]}):n.jsxs(d.Modal,{open:t,closeHandler:e,className:"new-agent",children:[n.jsx(d.Modal.Header,{className:"new-agent__header",children:_}),n.jsx(d.Modal.Body,{className:"new-agent__body",children:A})]})},mt=t=>{window.location.assign(t)},as=({open:t,authToken:e,headers:s,agentDefinitionsUrl:a,agentsUrl:r,closeUrl:l,successUrl:i,onClose:u,onStart:c,embedded:w=!1})=>{const f=JSON.stringify(s??{}),h=o.useMemo(()=>new He({token:e,headers:s,urls:{agentDefinitions:a,agents:r}}),[e,a,r,f]),[p,O]=o.useState([]),[v,N]=o.useState("loading"),[S,P]=o.useState(null),[k,x]=o.useState(0);o.useEffect(()=>{if(!t)return;let E=!1;return N("loading"),P(null),(async()=>{try{const D=await h.listAgentDefinitions();if(E)return;O(D.map(Ze)),N("idle")}catch(D){if(E)return;O([]),P(Rt(D)),N("error")}})(),()=>{E=!0}},[h,t,k]);const _=o.useCallback(()=>{u==null||u(),l&&mt(l)},[l,u]),A=o.useCallback(async E=>{await h.createAgent(E.definition.ref,{invocationName:E.invocationName}),c==null||c(E),i&&mt(i)},[h,c,i]),T=o.useCallback(()=>{x(E=>E+1)},[]);return n.jsx(Lt,{open:t,onClose:_,onStart:A,agentDefinitions:p,definitionsState:v,definitionsError:S,onRetryDefinitions:T,embedded:w})},rs=t=>"agentDefinitionsUrl"in t,Mt=t=>rs(t)?n.jsx(as,{...t}):n.jsx(Lt,{...t}),os=t=>t!==void 0&&t.some(e=>e.status===H.hitl),is=(t,e)=>os(e)?b.hitl:t.status,ls=({column:t,label:e})=>t.statusIcon?n.jsx("span",{className:"agent-view__status-indicator",children:n.jsx(d.Icon,{name:t.statusIcon.name,size:16,color:t.statusIcon.color,className:q({"agent-view__progress-icon--spinning":t.statusIcon.spin}),screenReaderText:e})}):n.jsx("span",{className:q("agent-view__dot",{[`agent-view__dot--${t.dotModifier}`]:t.dotModifier}),children:n.jsx(d.Dot,{colour:t.dotColour,label:e})}),cs=({agent:t,agentName:e,column:s,isExpanded:a,isLoading:r,checklist:l,error:i,onToggle:u,onViewAgent:c})=>{const{id:w,invocation_name:f}=t,h=`agent-card-${w}-header`,p=`agent-card-${w}-progress`;return n.jsx("li",{className:q("agent-view__card",{"agent-view__card--expanded":a}),children:n.jsxs(d.Card,{spacing:"dense",children:[n.jsx("button",{type:"button",className:"agent-view__card-toggle","aria-expanded":a,"aria-controls":p,"aria-label":f,id:h,onClick:()=>u(w),children:n.jsxs("div",{className:"agent-view__card-content",children:[n.jsx(ls,{column:s}),n.jsx("span",{className:"agent-view__card-invocation-name",children:f}),n.jsx("span",{className:"agent-view__card-agent-name",children:e}),n.jsx(d.Icon,{name:a?"chevron-up":"chevron-down",size:16,className:"agent-view__card-chevron"})]})}),a&&n.jsxs("div",{id:p,"aria-labelledby":h,className:"agent-view__card-progress",children:[r&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(d.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:ce}),n.jsx("span",{children:ce})]}),!r&&i&&n.jsx("p",{className:"agent-view__progress-error",role:"alert",children:i}),!r&&!i&&l!==null&&n.jsx(pn,{checklist:l}),!r&&!i&&l===null&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(d.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:ce}),n.jsx("span",{children:ce})]}),n.jsx("div",{className:"agent-view__card-actions",children:n.jsx(d.Button,{variant:"secondary",size:"S",onClick:()=>c==null?void 0:c(t),children:"View agent"})})]})]})})},_t=({column:t,agents:e,expandedAgentId:s,loadingAgentId:a,checklistByInvocationId:r,errorByAgentId:l,definitionNameByRef:i,onToggleAgent:u,onViewAgent:c,isSplit:w=!1})=>n.jsxs("section",{className:q("agent-view__column",{"agent-view__column--split":w}),"aria-label":t.title,children:[n.jsxs("div",{className:"agent-view__column-header",children:[n.jsx(d.Heading,{level:4,children:t.title}),n.jsx("span",{className:"agent-view__column-count",children:e.length})]}),n.jsx("ul",{className:"agent-view__card-list",children:e.map(f=>n.jsx(cs,{agent:f,agentName:Qe(f,i),column:t,isExpanded:s===f.id,isLoading:a===f.id,checklist:r[f.invocation_id]??null,error:l[f.id]??null,onToggle:u,onViewAgent:c},f.id))})]}),Qe=(t,e)=>e.get(t.agent_definition_ref)??t.agent_definition_ref.replace(/_/g," "),ds=({jwt:t,headers:e,agentDefinitionsUrl:s,agentsUrl:a,agentUrl:r,agentChecklistUrl:l,agentResourcesUrl:i,agentTimelineUrl:u,agentChatUrl:c,agentConversationUrl:w,enableUpload:f,showHeader:h=!1,institutions:p})=>{var Ce;const O=o.useMemo(()=>({agentDefinitions:s,agents:a,agent:r,agentChecklist:l,...i?{agentResources:i}:{},...u?{agentTimeline:u}:{},agentChat:c,agentConversation:w}),[s,a,r,l,i,u,c,w]),[v,N]=o.useState(null),S=v?(Ce=p==null?void 0:p.find(m=>m.applicationId===v.application_id))==null?void 0:Ce.applicationUrl:void 0,P=o.useMemo(()=>{const m={...e??{}};return S?m[ae.arborApplicationUrl]=S:delete m[ae.arborApplicationUrl],m},[e,S]),{agents:k,agentDefinitions:x,loadState:_,loadError:A,reload:T,refresh:E,fetchAgentChecklist:D,createAgent:V}=It({jwt:t,headers:P,urls:O}),[R,$]=o.useState(!1),[I,F]=o.useState(null),[K,B]=o.useState(null),[L,ye]=o.useState({}),[re,ge]=o.useState({}),[oe,Be]=o.useState([]),[X,ze]=o.useState([]),he=o.useMemo(()=>{const m=new Set(k.map(y=>y.application_id)),j=new Map((p??[]).map(y=>[y.applicationId,y.name]));return[...m].sort((y,G)=>(j.get(y)??y).localeCompare(j.get(G)??G)).map(y=>({value:y,label:j.get(y)??y}))},[k,p]),Z=o.useMemo(()=>new Map(x.map(m=>[m.ref,m.display_name])),[x]),pe=o.useMemo(()=>[...new Set(k.map(j=>Qe(j,Z)))].sort((j,y)=>j.localeCompare(y)).map(j=>({value:j,label:j})),[k,Z]),Se=o.useMemo(()=>k.filter(m=>!(oe.length>0&&!oe.includes(m.application_id)||X.length>0&&!X.includes(Qe(m,Z)))),[k,Z,X,oe]),ie=he.length>1,Ne=pe.length>1,je=ie||Ne;o.useEffect(()=>{const m=window.setInterval(()=>{E()},6e4);return()=>{window.clearInterval(m)}},[E]),o.useEffect(()=>{if(k.length===0)return;let m=!1;return(async()=>{const j=await Promise.allSettled(k.map(async y=>{const G=await D(y.invocation_id);return{agentId:y.id,invocationId:y.invocation_id,checklist:G.checklist}}));m||(ye(y=>{const G={...y};let te=!1;for(const Q of j){if(Q.status!=="fulfilled")continue;const{invocationId:ne,checklist:ve}=Q.value;JSON.stringify(y[ne])!==JSON.stringify(ve)&&(G[ne]=ve,te=!0)}return te?G:y}),ge(y=>{const G={...y};let te=!1;return j.forEach((Q,ne)=>{Q.status==="rejected"&&G[k[ne].id]!==Me&&(G[k[ne].id]=Me,te=!0)}),te?G:y}))})(),()=>{m=!0}},[k,D]);const be=o.useCallback(async m=>{if(!L[m.invocation_id]){B(m.id),ge(j=>{const y={...j};return delete y[m.id],y});try{const j=await D(m.invocation_id);ye(y=>({...y,[m.invocation_id]:j.checklist}))}catch{ge(j=>({...j,[m.id]:Me}))}finally{B(j=>j===m.id?null:j)}}},[D,L]),me=o.useCallback(m=>{if(I===m){F(null);return}const j=k.find(({id:y})=>y===m);j&&(F(m),be(j))},[k,I,be]),Ae=o.useMemo(()=>{const m={};for(const j of Se){const y=is(j,L[j.invocation_id]);(m[y]??(m[y]=[])).push(j)}return m},[Se,L]),_e=o.useCallback(m=>{N(m)},[]),Fe=o.useCallback(async m=>{const j=await V(m);N(j),$(!1)},[V]),fe=o.useCallback(()=>{N(null)},[]),ee={expandedAgentId:I,loadingAgentId:K,checklistByInvocationId:L,errorByAgentId:re,definitionNameByRef:Z,onToggleAgent:me,onViewAgent:_e};return n.jsxs("div",{className:"agent-view-frontend agent-view",children:[h&&n.jsxs("div",{className:"agent-view__header",children:[n.jsx(d.Heading,{level:1,children:"Agents"}),n.jsx(d.Button,{variant:"primary",size:"S",iconLeftName:"sparkles",iconLeftScreenReaderText:"Start an agent",onClick:()=>$(!0),children:"Start an agent"})]}),k.length>0&&je&&n.jsxs("div",{className:"agent-view__filters",children:[ie&&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(d.Combobox,{id:"agent-view-institution-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All institutions",options:he,value:oe,onValueChange:Be,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear institutions"})]}),Ne&&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(d.Combobox,{id:"agent-view-agent-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All agents",options:pe,value:X,onValueChange:ze,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear agents"})]})]}),_==="error"?n.jsxs("div",{className:"agent-view__state agent-view__state--error",role:"alert",children:[n.jsx(d.Icon,{name:"triangle-alert",size:24,color:"var(--color-semantic-destructive-600)"}),n.jsx("p",{className:"agent-view__state-message",children:A??wt}),n.jsx(d.Button,{variant:"secondary",size:"S",onClick:T,children:"Try again"})]}):_==="loading"&&k.length===0?n.jsxs("div",{className:"agent-view__state","aria-live":"polite",children:[n.jsx(d.Icon,{name:"loader",size:24,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:lt}),n.jsx("p",{className:"agent-view__state-message",children:lt})]}):k.length===0?n.jsx(ln,{}):n.jsxs("div",{className:"agent-view__board",children:[Wt.map(m=>n.jsx(_t,{column:Ue[m],agents:Ae[m]??[],...ee},m)),n.jsx("div",{className:"agent-view__split-column",children:Vt.map(m=>n.jsx(_t,{column:Ue[m],agents:Ae[m]??[],isSplit:!0,...ee},m))})]}),v&&n.jsx(Pt,{agent:v,invocationId:v.invocation_id,open:!0,jwt:t,headers:P,agentUrl:r,agentChecklistUrl:l,agentResourcesUrl:i,agentTimelineUrl:u,agentChatUrl:c,agentConversationUrl:w,enableUpload:f,initialChecklist:L[v.invocation_id]??null,onClose:fe},v.id),n.jsx(Mt,{open:R,onClose:()=>$(!1),onStart:Fe,agentDefinitions:x})]})},us=(t,e)=>{const s=Date.now(),a=e.trim()||t.agent_intent;return{id:`agent-${s}`,invocation_id:`inv-${s}`,agent_definition_ref:t.ref,agent_intent:t.agent_intent,invocation_name:a,application_id:Yt,created_by:Xt,status:b["generating-a-response"],context_ref:null,checklist_ref:null}};exports.AgentMonitorKanban=ds;exports.AgentServiceClient=He;exports.AgentServiceError=de;exports.AgentView=Pt;exports.HttpChatConnector=Tt;exports.NewAgentModal=Mt;exports.buildAgentFromDefinition=us;exports.createHttpChatConnectorFactory=nt;exports.mapApiAgent=Xe;exports.mapApiAgentDefinition=Ze;exports.mapApiAgentStatus=St;exports.mapApiAgentTimelineResponse=At;exports.mapApiChecklistEndpointResponse=tt;exports.mapApiChecklistItem=et;exports.mapApiChecklistResponse=Ct;exports.mapApiChecklistStatus=Nt;exports.mapApiConversationMessages=Et;exports.mapApiOpeningMessage=ke;exports.mapApiResource=jt;exports.mapApiResourcesEndpointResponse=bt;exports.mapApiTripOption=Mn;exports.useAgentService=It;exports.useAgentWorkspace=Ot;
3
+ `);l=f.pop()??"";for(const h of f)u(h)}if(l.trim()&&u(l),!i)throw new pe(502,null,"Chat stream ended without any events");return i}}const Ws=t=>{let e=null;const n=[];for(const a of t.split(`
4
+ `)){const r=a.trimEnd();r.startsWith("event:")?e=r.slice(6).trim():r.startsWith("data:")&&n.push(r.slice(5).trim())}return{event:e,data:n.length>0?n.join(`
5
+ `):null}},_t=t=>{try{return JSON.parse(t)}catch{return}};function Vs(t,e){const n=new FormData;n.append("body",JSON.stringify(t));for(const a of e)n.append("files",a,a.name);return n}const Ys={id:yt,author:Z.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 ft=0;const Xs=t=>(ft+=1,`${t}-${Date.now()}-${ft}`),Qs=t=>{const e=t.destination?` to ${t.destination}`:"";return`Let's get started on ${t.tripName.trim()||t.destination.trim()||"this task"}${e}. What will you do first?`};class Lt{constructor(e,n,a={}){this.seededChecklist=[],this.client=e,this.agentId=n,this.chatId=a.chatId??n,this.opening=a.openingMessage??Ys,this.model=a.model}openingMessage(){return this.opening}async bootstrapConversation(){const e=await this.client.getConversation(this.chatId),n=Pt(e.messages);return n.length===0?[this.opening]:n}async start(e){return{...await this.exchange(Qs(e)),phase:H.running}}sendMessage(e,n){return this.exchange(e,n)}async stop(){}seedChecklist(e){this.seededChecklist=e}async exchange(e,n){var i;const a=[{role:Ds.user,content:e}],r=await this.client.chat(this.agentId,{messages:a,chat_id:this.chatId,...this.model?{model:this.model}:{},moderation_enabled:!0,meta:{feature_id:"agent_view",source:"agent_view_frontend"}},...n&&n.length>0?[{uploadFiles:n}]:[]),l={id:r.event_id||Xs("msg-agent"),author:Z.agent,text:r.message.content,...(i=r.follow_up_prompts)!=null&&i.length?{followUpPrompts:r.follow_up_prompts}:{}};try{const u=await this.client.getAgent(this.agentId),{checklist:c}=Ot(this.agentId,u);return this.seededChecklist=c,{message:l,checklist:c}}catch{return{message:l,...this.seededChecklist.length?{checklist:this.seededChecklist}:{}}}}}const ot=(t,e)=>n=>{var a,r;return new Lt(t,n.invocation_id,{model:e==null?void 0:e.model,chatId:((a=e==null?void 0:e.resolveChatId)==null?void 0:a.call(e,n))??(e==null?void 0:e.chatId)??n.invocation_id,openingMessage:((r=e==null?void 0:e.resolveOpeningMessage)==null?void 0:r.call(e,n))??(e==null?void 0:e.openingMessage)})},Mt=t=>t instanceof pe?t.message:t instanceof TypeError?"Network error while contacting the agent service.":t instanceof Error&&t.message?t.message:Nt,Zs=t=>{const e={};for(const n of t){const a=je(n);if(!a)continue;const r=n.invocation_id??n.id;e[r]=a,e[n.id]=a}return e},en=t=>JSON.stringify(t),et=(t,e)=>JSON.stringify(t)===JSON.stringify(e),Ut=t=>{const{jwt:e,headers:n,urls:a}=t,r=JSON.stringify(n??{}),l=en(a),i=o.useMemo(()=>new Fe({token:e,headers:n,urls:a}),[e,l]);o.useLayoutEffect(()=>{i.setHeaders(n)},[i,r]);const[u,c]=o.useState([]),[v,f]=o.useState([]),[h,p]=o.useState({}),[O,w]=o.useState("loading"),[j,N]=o.useState(null),[P,y]=o.useState(0),k=o.useCallback((I,U)=>{const E=I.map(tt),q=U.map(nt),K=Zs(I);c(z=>et(z,E)?z:E),f(z=>et(z,q)?z:q),p(z=>et(z,K)?z:K),w("idle"),N(null)},[]);o.useEffect(()=>{let I=!1;return w("loading"),N(null),(async()=>{try{const[U,E]=await Promise.all([i.listAgents(),i.listAgentDefinitions()]);if(I)return;k(U,E)}catch(U){if(I)return;c([]),f([]),p({}),w("error"),N(Mt(U))}})(),()=>{I=!0}},[k,i,P]);const _=o.useCallback(()=>{y(I=>I+1)},[]),C=o.useCallback(async()=>{try{const[I,U]=await Promise.all([i.listAgents(),i.listAgentDefinitions()]);k(I,U)}catch{}},[k,i]),R=o.useCallback(async I=>{const[U,E]=await Promise.all([i.getAgentChecklist(I),i.getAgent(I).catch(()=>null)]);return rt(I,U,E??void 0)},[i]),T=o.useCallback(async I=>i.listAllAgentResources(I),[i]),M=o.useCallback(async({definition:I,invocationName:U})=>{const E=await i.createAgent(I.ref,{invocationName:U}),q=await i.getAgent(E.id),K=tt(q),z=je(q);return c(D=>[K,...D]),z&&p(D=>({...D,[K.invocation_id]:z,[K.id]:z})),K},[i]),Y=o.useMemo(()=>ot(i,{resolveOpeningMessage:I=>h[I.invocation_id]??h[I.id]}),[i,h]);return{agents:u,agentDefinitions:v,loadState:O,loadError:j,reload:_,refresh:C,fetchAgentChecklist:R,fetchAgentResources:T,createAgent:M,chatConnector:Y}},tn=t=>JSON.stringify(t),Dt=t=>{const{agent:e,jwt:n,headers:a,urls:r,chatId:l}=t,i=JSON.stringify(a??{}),u=tn(r),c=o.useMemo(()=>new Fe({token:n,headers:a,urls:{agent:r.agentUrl,agentChecklist:r.agentChecklistUrl,...r.agentResourcesUrl?{agentResources:r.agentResourcesUrl}:{},...r.agentTimelineUrl?{agentTimeline:r.agentTimelineUrl}:{},agentChat:r.agentChatUrl,agentConversation:r.agentConversationUrl}}),[n,u]);o.useLayoutEffect(()=>{c.setHeaders(a)},[c,i]);const v=o.useCallback(async w=>{const[j,N]=await Promise.all([c.getAgentChecklist(w),c.getAgent(w).catch(()=>null)]);return rt(w,j,N??void 0)},[c]),f=o.useCallback(async w=>c.listAllAgentResources(w),[c]),h=o.useCallback(async(w,j)=>c.getAgentResourceHtml(w,j),[c]),p=o.useCallback(async w=>{const j=await c.getAgentTimeline(w);return It(j)},[c]);return{connector:o.useMemo(()=>ot(c,{chatId:l??e.invocation_id})(e),[c,e.invocation_id,l]),fetchAgentChecklist:v,fetchAgentResources:f,fetchAgentResourceHtml:h,fetchAgentTimeline:p}},sn=3e4,nn=(t,e)=>{const n=t.hasRunBefore?e||"This trip":t.tripName.trim()||"A new trip",a=t.destination?` to ${t.destination}`:"",r=t.hasRunBefore?" It has run before.":"";return`${n}${a}.${r}`.trim()},an=t=>{switch(t){case A.failed:return H.stopped;case A.complete:return H.complete;default:return H.running}},vt=(t,e)=>{e([ge(t)])},rn=(t,e)=>t.length===e.length&&t.every((n,a)=>{const r=e[a];return r!==void 0&&n.id===r.id&&n.text===r.text}),$t=({agent:t,invocationId:e,open:n,onClose:a,jwt:r,headers:l,agentUrl:i,agentChecklistUrl:u,agentResourcesUrl:c,agentTimelineUrl:v,agentChatUrl:f,agentConversationUrl:h,chatId:p,enableUpload:O,initialBrief:w,initialPhase:j,initialChecklist:N})=>{const[P,y]=o.useState(p??e),[k,_]=o.useState("chat"),[C,R]=o.useState(!1),{connector:T,fetchAgentChecklist:M,fetchAgentResources:Y,fetchAgentResourceHtml:I,fetchAgentTimeline:U}=Dt({agent:{...t,invocation_id:e},jwt:r,headers:l,chatId:P,urls:{agentUrl:i,agentChecklistUrl:u,agentResourcesUrl:c,agentTimelineUrl:v,agentChatUrl:f,agentConversationUrl:h}}),E=o.useRef(T),[q,K]=o.useState(j??(w?H.running:an(t.status))),[z,D]=o.useState([]),[be,ie]=o.useState(0),[_e,le]=o.useState(),[qe,ee]=o.useState(null),[Ge,fe]=o.useState([]),[ne,ve]=o.useState(!1),[Ae,ce]=o.useState(null),[Ce,Ee]=o.useState(null),[Te,we]=o.useState(null),[Re,xe]=o.useState(!1),[Je,ke]=o.useState(null),[te,ye]=o.useState(null),[m,b]=o.useState(!1),[S,G]=o.useState(null),[X,Q]=o.useState(N??null),[ae,Se]=o.useState(!1),[zt,Ke]=o.useState(null),[Ie,We]=o.useState(!1),[Oe,Ft]=o.useState(!1),[Pe,qt]=o.useState(!1),it=o.useRef(Ie),lt=o.useRef(0),ct=o.useRef(0);o.useEffect(()=>{E.current=T},[T]),o.useEffect(()=>{it.current=Ie},[Ie]),o.useEffect(()=>{y(p??e),_("chat"),R(!1),D([]),ie(g=>g+1)},[e,p]),o.useEffect(()=>{if(!n||w)return;const g=E.current.bootstrapConversation;if(!g){vt(E.current.openingMessage(),D);return}let x=!1;return We(!0),(async()=>{try{const L=await g.call(E.current);if(x)return;D(L.map(ge))}catch{x||vt(E.current.openingMessage(),D)}finally{x||We(!1)}})(),()=>{x=!0}},[n,w,e,P]);const de=o.useCallback(()=>{const g=++lt.current;(async()=>{var x,L;try{const W=await M(e);if(g!==lt.current)return;Q(se=>JSON.stringify(se)===JSON.stringify(W.checklist)?se:W.checklist),Ke(null),(L=(x=E.current).seedChecklist)==null||L.call(x,W.checklist)}catch{}})()},[M,e]),Le=o.useCallback(()=>{c&&(async()=>{try{const g=await Y(e);fe(g),ce(null)}catch{}})()},[c,Y,e]),ue=o.useCallback(()=>{if(!v)return;const g=++ct.current;(async()=>{try{const x=await U(e);if(g!==ct.current)return;ye(L=>JSON.stringify(L)===JSON.stringify(x)?L:x),G(null)}catch{}})()},[v,U,e]);o.useEffect(()=>{if(!n||w)return;const g=window.setInterval(()=>{const x=E.current.bootstrapConversation;x&&(async()=>{try{const L=await x.call(E.current);if(it.current)return;const W=L.map(ge);let se=!1;D(ut=>rn(ut,W)?ut:(se=!0,W)),se&&(de(),ue())}catch{}})()},sn);return()=>{window.clearInterval(g)}},[n,w,e,P,de,ue]);const Gt=o.useCallback(g=>{var x,L;g.checklist?(Q(g.checklist),(L=(x=E.current).seedChecklist)==null||L.call(x,g.checklist)):de(),g.phase&&K(g.phase),Le(),ue()},[de,Le,ue]);o.useEffect(()=>{var g,x;!n||w||N&&N.length>0&&((x=(g=E.current).seedChecklist)==null||x.call(g,N))},[n,w,N]),o.useEffect(()=>{if(!n||w)return;let g=!1;return Se(x=>N!=null&&N.length?!1:x||X===null||X.length===0),Ke(null),(async()=>{var x,L;try{const W=await M(e);if(g)return;N!=null&&N.length||(Q(W.checklist),(L=(x=E.current).seedChecklist)==null||L.call(x,W.checklist))}catch{!g&&!(N!=null&&N.length)&&Ke($e)}finally{g||Se(!1)}})(),()=>{g=!0}},[n,e,w,N,M]),o.useEffect(()=>{if(!n||!c)return;let g=!1;return ve(!0),ce(null),(async()=>{try{const x=await Y(e);g||fe(x)}catch{g||ce(ns)}finally{g||ve(!1)}})(),()=>{g=!0}},[n,e,c,Y]);const Jt=o.useCallback(()=>{Ee(null),we(null),ke(null),xe(!1)},[]),Kt=o.useCallback(g=>{if(g.misRecordUrl){window.open(g.misRecordUrl,"_blank","noopener,noreferrer");return}Ee(g),we(null),ke(null),xe(!0),(async()=>{try{const x=await I(e,g.id);we(x)}catch{ke(as)}finally{xe(!1)}})()},[I,e]);o.useEffect(()=>{if(!n||!v)return;let g=!1;return b(x=>x||te===null),G(null),(async()=>{try{const x=await U(e);g||ye(x)}catch{g||G(St)}finally{g||b(!1)}})(),()=>{g=!0}},[n,e,v,U]),o.useEffect(()=>{if(!n||!w)return;let g=!1;const x={id:`user-brief-${Date.now()}`,author:Z.user,text:nn(w,t.invocation_name)};return(async()=>{var W,se;const L=await E.current.start(w);g||(D([ge(E.current.openingMessage()),ge(x),ge(L.message)]),L.checklist?(Q(L.checklist),(se=(W=E.current).seedChecklist)==null||se.call(W,L.checklist)):de(),K(L.phase??H.running),Le(),ue())})(),()=>{g=!0}},[n,w,t.invocation_name,e,de,Le,ue]);const Wt=o.useCallback(g=>{ee(Ls(g))},[]),Ve=p??e,Me=te==null?void 0:te.chatSessions,dt=Me!=null&&Me.length?Me.reduce((g,x)=>Date.parse(x.timestamp)<Date.parse(g.timestamp)?x:g).sessionId:void 0,Ye=o.useCallback(()=>{_("chat"),R(!1),P!==Ve&&(y(Ve),D([]),ie(g=>g+1))},[P,Ve]),Vt=o.useCallback(g=>{if(g===dt){Ye();return}y(g),R(!0),_("chat"),D([]),ie(x=>x+1)},[dt,Ye]),Yt=o.useCallback(g=>{ee(null),le(g),ie(x=>x+1)},[]),Xt=o.useCallback(async()=>{await E.current.stop(),K(H.stopped)},[]),Qt=X;return s.jsxs(d.Modal,{open:n,closeHandler:a,hideCloseButton:!0,className:"agent-workspace",children:[s.jsxs(d.Modal.Header,{className:"agent-workspace__header",children:[s.jsxs("div",{className:"agent-workspace__header-title",children:[s.jsx("span",{className:"agent-workspace__header-avatar","aria-hidden":"true",children:s.jsx(d.Icon,{name:"ask-arbor",size:24})}),s.jsx(d.Modal.Title,{children:t.invocation_name}),s.jsx("span",{className:J("agent-workspace__phase",`agent-workspace__phase--${q}`),children:is[q]})]}),s.jsxs("div",{className:"agent-workspace__header-actions",children:[s.jsx(d.Button,{variant:Oe?"secondary":"primary",size:"S",iconLeftName:"clipboard-list",iconLeftScreenReaderText:"Toggle checklist","aria-pressed":!Oe,onClick:()=>Ft(g=>!g),children:"Checklist"}),s.jsx(d.Button,{variant:Pe?"secondary":"primary",size:"S",iconLeftName:"files",iconLeftScreenReaderText:"Toggle resources","aria-pressed":!Pe,onClick:()=>qt(g=>!g),children:"Resources"}),s.jsx(d.Button,{variant:"secondary",size:"S",iconLeftName:"x",iconLeftScreenReaderText:"Close",onClick:a,children:"Close"})]})]}),s.jsxs(d.Modal.Body,{className:J("agent-workspace__body",{"agent-workspace__body--no-checklist":Oe,"agent-workspace__body--no-resources":Pe}),children:[" ",s.jsxs("section",{className:J("agent-workspace__panel","agent-workspace__panel--chat",{"agent-workspace__panel--timeline":!!v&&k==="timeline"}),"aria-label":"Agent",children:[s.jsxs("div",{className:"agent-workspace__panel-header",children:[s.jsx(d.Heading,{level:4,children:"Agent"}),q===H.running&&s.jsx(d.Button,{className:"agent-workspace__panel-header-action",variant:"secondary-destructive",size:"S",iconLeftName:"circle-x",iconLeftScreenReaderText:"Stop",onClick:()=>void Xt(),children:"Stop agent"})]}),v&&s.jsxs(d.Tabs,{className:"agent-workspace__center-tabs","aria-label":"Center panel",children:[s.jsx(d.Tabs.Item,{active:k==="chat",tabElementProps:{id:"agent-center-tab-chat",onClick:()=>_("chat")},children:"Chat"}),s.jsx(d.Tabs.Item,{active:k==="timeline",tabElementProps:{id:"agent-center-tab-timeline",onClick:()=>_("timeline")},children:"Timeline"})]}),v&&k==="chat"&&C&&s.jsx("div",{className:"agent-workspace__center-back",children:s.jsx(d.Button,{variant:"tertiary",size:"S",iconLeftName:"arrow-left",iconLeftScreenReaderText:"Back to main chat",onClick:Ye,children:"Back to main chat"})}),v&&k==="timeline"&&s.jsx(Os,{timeline:te,isLoading:m,error:S,onOpenChatSession:Vt}),s.jsx("div",{className:"agent-workspace__chat-keep-alive",hidden:!!v&&k!=="chat",children:s.jsx(ks,{connector:T,phase:q,chatHistory:z,chatSessionKey:be,startQuery:_e,clarificationMessage:qe,enableUpload:O,onTurn:Gt,onAwaitingChange:We,onClarificationPrompt:Yt,onDismissClarification:()=>ee(null)})})]}),!Oe&&s.jsx(ys,{checklist:Qt,isLoading:ae,error:zt,phase:q,canRequestInput:q===H.running&&!Ie,onAttentionItemClick:Wt}),!Pe&&s.jsx(js,{resources:Ge,isLoading:ne,error:Ae,onOpenResource:Kt}),s.jsx(Ss,{resource:Ce,html:Te,isLoading:Re,error:Je,onClose:Jt})]})]})},on="Unable to load agent definitions. Please try again.",ln="Unable to start the agent.",wt="Loading agents…",Ht=({open:t,onClose:e,onStart:n,agentDefinitions:a,definitionsState:r="idle",definitionsError:l=null,onRetryDefinitions:i,embedded:u=!1})=>{const[c,v]=o.useState(void 0),[f,h]=o.useState(""),[p,O]=o.useState(!1),[w,j]=o.useState(null),N=[...a].sort((R,T)=>R.display_name.localeCompare(T.display_name)).map(R=>({value:R.ref,label:R.display_name}));o.useEffect(()=>{t&&(v(void 0),h(""),O(!1),j(null))},[t]);const P=c!==void 0&&f.trim().length>0,y=o.useCallback(R=>{const T=a.find(M=>M.ref===R[0]);T&&v(T)},[a]),k=o.useCallback(async()=>{if(!(!c||!P||p)){O(!0),j(null);try{await n({definition:c,invocationName:f.trim()})}catch(R){j(R instanceof Error?R.message:ln)}finally{O(!1)}}},[P,c,f,p,n]);if(r==="idle"&&a.length===0||!t)return null;const _=s.jsxs("div",{className:"new-agent__header-title",children:[s.jsx("span",{className:"new-agent__header-avatar","aria-hidden":"true",children:s.jsx(d.Icon,{name:"ask-arbor",size:24})}),u?s.jsx("h2",{className:"new-agent__title",children:"Start an agent"}):s.jsx(d.Modal.Title,{children:"Start an agent"})]});let C;return r==="loading"?C=s.jsxs("div",{className:"new-agent__state","aria-live":"polite",children:[s.jsx(d.Icon,{name:"loader",size:24,color:"var(--color-brand-600)",className:"new-agent__spinner",screenReaderText:wt}),s.jsx("p",{className:"new-agent__state-message",children:wt})]}):r==="error"?C=s.jsxs("div",{className:"new-agent__state new-agent__state--error",role:"alert",children:[s.jsx(d.Icon,{name:"triangle-alert",size:24,color:"var(--color-semantic-destructive-600)"}),s.jsx("p",{className:"new-agent__state-message",children:l??on}),i?s.jsx(d.Button,{variant:"secondary",size:"S",onClick:i,children:"Try again"}):null]}):C=s.jsxs("form",{className:"new-agent__form","aria-label":"Start an agent",onSubmit:R=>{R.preventDefault(),P&&!p&&k()},children:[s.jsxs("div",{className:"new-agent__type-field",children:[s.jsx("label",{className:"new-agent__type-label",htmlFor:"new-agent-type",children:"What would you like your agent to do?"}),s.jsx(d.SelectDropdown,{id:"new-agent-type",placeholder:"Which agent would you like to start?",options:N,selectedValues:c?[c.ref]:[],onSelectionChange:y})]}),s.jsxs("div",{className:"new-agent__type-field",children:[s.jsx("label",{className:"new-agent__type-label",htmlFor:"new-agent-invocation-name",children:"Name"}),s.jsx(d.TextInput,{id:"new-agent-invocation-name",value:f,placeholder:"What would you like to call your agent?",onChange:R=>h(R.target.value)})]}),w?s.jsx("p",{className:"new-agent__error",role:"alert",children:w}):null,s.jsx("div",{className:"new-agent__actions",children:s.jsx(d.Button,{type:"submit",variant:"primary",className:J("new-agent__start-button",{"new-agent__start-button--starting":p}),disabled:!P||p,iconLeftName:p?"loader":"sparkles",iconLeftScreenReaderText:p?"Starting":void 0,children:p?"Starting…":"Start"})})]}),u?s.jsxs("div",{className:J("new-agent","new-agent--embedded"),children:[s.jsx("div",{className:"new-agent__header",children:_}),s.jsx("div",{className:"new-agent__body",children:C})]}):s.jsxs(d.Modal,{open:t,closeHandler:e,className:"new-agent",children:[s.jsx(d.Modal.Header,{className:"new-agent__header",children:_}),s.jsx(d.Modal.Body,{className:"new-agent__body",children:C})]})},xt=t=>{window.location.assign(t)},cn=({open:t,authToken:e,headers:n,agentDefinitionsUrl:a,agentsUrl:r,closeUrl:l,successUrl:i,onClose:u,onStart:c,embedded:v=!1})=>{const f=JSON.stringify(n??{}),h=o.useMemo(()=>new Fe({token:e,headers:n,urls:{agentDefinitions:a,agents:r}}),[e,a,r,f]),[p,O]=o.useState([]),[w,j]=o.useState("loading"),[N,P]=o.useState(null),[y,k]=o.useState(0);o.useEffect(()=>{if(!t)return;let T=!1;return j("loading"),P(null),(async()=>{try{const M=await h.listAgentDefinitions();if(T)return;O(M.map(nt)),j("idle")}catch(M){if(T)return;O([]),P(Mt(M)),j("error")}})(),()=>{T=!0}},[h,t,y]);const _=o.useCallback(()=>{u==null||u(),l&&xt(l)},[l,u]),C=o.useCallback(async T=>{await h.createAgent(T.definition.ref,{invocationName:T.invocationName}),c==null||c(T),i&&xt(i)},[h,c,i]),R=o.useCallback(()=>{k(T=>T+1)},[]);return s.jsx(Ht,{open:t,onClose:_,onStart:C,agentDefinitions:p,definitionsState:w,definitionsError:N,onRetryDefinitions:R,embedded:v})},dn=t=>"agentDefinitionsUrl"in t,Bt=t=>dn(t)?s.jsx(cn,{...t}):s.jsx(Ht,{...t}),un=t=>t!==void 0&&t.some(e=>e.status===B.hitl),gn=(t,e)=>un(e)?A.hitl:t.status,hn=({column:t,label:e})=>t.statusIcon?s.jsx("span",{className:"agent-view__status-indicator",children:s.jsx(d.Icon,{name:t.statusIcon.name,size:16,color:t.statusIcon.color,className:J({"agent-view__progress-icon--spinning":t.statusIcon.spin}),screenReaderText:e})}):s.jsx("span",{className:J("agent-view__dot",{[`agent-view__dot--${t.dotModifier}`]:t.dotModifier}),children:s.jsx(d.Dot,{colour:t.dotColour,label:e})}),pn=({agent:t,agentName:e,column:n,isExpanded:a,isLoading:r,checklist:l,error:i,onToggle:u,onViewAgent:c})=>{const{id:v,invocation_name:f}=t,h=`agent-card-${v}-header`,p=`agent-card-${v}-progress`;return s.jsx("li",{className:J("agent-view__card",{"agent-view__card--expanded":a}),children:s.jsxs(d.Card,{spacing:"dense",children:[s.jsx("button",{type:"button",className:"agent-view__card-toggle","aria-expanded":a,"aria-controls":p,"aria-label":f,id:h,onClick:()=>u(v),children:s.jsxs("div",{className:"agent-view__card-content",children:[s.jsx(hn,{column:n}),s.jsx("span",{className:"agent-view__card-invocation-name",children:f}),s.jsx("span",{className:"agent-view__card-agent-name",children:e}),s.jsx(d.Icon,{name:a?"chevron-up":"chevron-down",size:16,className:"agent-view__card-chevron"})]})}),a&&s.jsxs("div",{id:p,"aria-labelledby":h,className:"agent-view__card-progress",children:[r&&s.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[s.jsx(d.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:he}),s.jsx("span",{children:he})]}),!r&&i&&s.jsx("p",{className:"agent-view__progress-error",role:"alert",children:i}),!r&&!i&&l!==null&&s.jsx(vs,{checklist:l}),!r&&!i&&l===null&&s.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[s.jsx(d.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:he}),s.jsx("span",{children:he})]}),s.jsx("div",{className:"agent-view__card-actions",children:s.jsx(d.Button,{variant:"secondary",size:"S",onClick:()=>c==null?void 0:c(t),children:"View agent"})})]})]})})},kt=({column:t,agents:e,expandedAgentId:n,loadingAgentId:a,checklistByInvocationId:r,errorByAgentId:l,definitionNameByRef:i,onToggleAgent:u,onViewAgent:c,isSplit:v=!1})=>s.jsxs("section",{className:J("agent-view__column",{"agent-view__column--split":v}),"aria-label":t.title,children:[s.jsxs("div",{className:"agent-view__column-header",children:[s.jsx(d.Heading,{level:4,children:t.title}),s.jsx("span",{className:"agent-view__column-count",children:e.length})]}),s.jsx("ul",{className:"agent-view__card-list",children:e.map(f=>s.jsx(pn,{agent:f,agentName:st(f,i),column:t,isExpanded:n===f.id,isLoading:a===f.id,checklist:r[f.invocation_id]??null,error:l[f.id]??null,onToggle:u,onViewAgent:c},f.id))})]}),st=(t,e)=>e.get(t.agent_definition_ref)??t.agent_definition_ref.replace(/_/g," "),mn=({jwt:t,headers:e,agentDefinitionsUrl:n,agentsUrl:a,agentUrl:r,agentChecklistUrl:l,agentResourcesUrl:i,agentTimelineUrl:u,agentChatUrl:c,agentConversationUrl:v,enableUpload:f,showHeader:h=!1,institutions:p})=>{var ye;const O=o.useMemo(()=>({agentDefinitions:n,agents:a,agent:r,agentChecklist:l,...i?{agentResources:i}:{},...u?{agentTimeline:u}:{},agentChat:c,agentConversation:v}),[n,a,r,l,i,u,c,v]),[w,j]=o.useState(null),N=w?(ye=p==null?void 0:p.find(m=>m.applicationId===w.application_id))==null?void 0:ye.applicationUrl:void 0,P=o.useMemo(()=>{const m={...e??{}};return N?m[oe.arborApplicationUrl]=N:delete m[oe.arborApplicationUrl],m},[e,N]),{agents:y,agentDefinitions:k,loadState:_,loadError:C,reload:R,refresh:T,fetchAgentChecklist:M,createAgent:Y}=Ut({jwt:t,headers:P,urls:O}),[I,U]=o.useState(!1),[E,q]=o.useState(null),[K,z]=o.useState(null),[D,be]=o.useState({}),[ie,_e]=o.useState({}),[le,qe]=o.useState([]),[ee,Ge]=o.useState([]),fe=o.useMemo(()=>{const m=new Set(y.map(S=>S.application_id)),b=new Map((p??[]).map(S=>[S.applicationId,S.name]));return[...m].sort((S,G)=>(b.get(S)??S).localeCompare(b.get(G)??G)).map(S=>({value:S,label:b.get(S)??S}))},[y,p]),ne=o.useMemo(()=>new Map(k.map(m=>[m.ref,m.display_name])),[k]),ve=o.useMemo(()=>[...new Set(y.map(b=>st(b,ne)))].sort((b,S)=>b.localeCompare(S)).map(b=>({value:b,label:b})),[y,ne]),Ae=o.useMemo(()=>y.filter(m=>!(le.length>0&&!le.includes(m.application_id)||ee.length>0&&!ee.includes(st(m,ne)))),[y,ne,ee,le]),ce=fe.length>1,Ce=ve.length>1,Ee=ce||Ce;o.useEffect(()=>{const m=window.setInterval(()=>{T()},6e4);return()=>{window.clearInterval(m)}},[T]),o.useEffect(()=>{if(y.length===0)return;let m=!1;return(async()=>{const b=await Promise.allSettled(y.map(async S=>{const G=await M(S.invocation_id);return{agentId:S.id,invocationId:S.invocation_id,checklist:G.checklist}}));m||(be(S=>{const G={...S};let X=!1;for(const Q of b){if(Q.status!=="fulfilled")continue;const{invocationId:ae,checklist:Se}=Q.value;JSON.stringify(S[ae])!==JSON.stringify(Se)&&(G[ae]=Se,X=!0)}return X?G:S}),_e(S=>{const G={...S};let X=!1;return b.forEach((Q,ae)=>{Q.status==="rejected"&&G[y[ae].id]!==$e&&(G[y[ae].id]=$e,X=!0)}),X?G:S}))})(),()=>{m=!0}},[y,M]);const Te=o.useCallback(async m=>{if(!D[m.invocation_id]){z(m.id),_e(b=>{const S={...b};return delete S[m.id],S});try{const b=await M(m.invocation_id);be(S=>({...S,[m.invocation_id]:b.checklist}))}catch{_e(b=>({...b,[m.id]:$e}))}finally{z(b=>b===m.id?null:b)}}},[M,D]),we=o.useCallback(m=>{if(E===m){q(null);return}const b=y.find(({id:S})=>S===m);b&&(q(m),Te(b))},[y,E,Te]),Re=o.useMemo(()=>{const m={};for(const b of Ae){const S=gn(b,D[b.invocation_id]);(m[S]??(m[S]=[])).push(b)}return m},[Ae,D]),xe=o.useCallback(m=>{j(m)},[]),Je=o.useCallback(async m=>{const b=await Y(m);j(b),U(!1)},[Y]),ke=o.useCallback(()=>{j(null)},[]),te={expandedAgentId:E,loadingAgentId:K,checklistByInvocationId:D,errorByAgentId:ie,definitionNameByRef:ne,onToggleAgent:we,onViewAgent:xe};return s.jsxs("div",{className:"agent-view-frontend agent-view",children:[h&&s.jsxs("div",{className:"agent-view__header",children:[s.jsx(d.Heading,{level:1,children:"Agents"}),s.jsx(d.Button,{variant:"primary",size:"S",iconLeftName:"sparkles",iconLeftScreenReaderText:"Start an agent",onClick:()=>U(!0),children:"Start an agent"})]}),y.length>0&&Ee&&s.jsxs("div",{className:"agent-view__filters",children:[ce&&s.jsxs("div",{className:"agent-view__filter",children:[s.jsx("label",{className:"agent-view__filter-label",htmlFor:"agent-view-institution-filter",children:"Institution"}),s.jsx(d.Combobox,{id:"agent-view-institution-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All institutions",options:fe,value:le,onValueChange:qe,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear institutions"})]}),Ce&&s.jsxs("div",{className:"agent-view__filter",children:[s.jsx("label",{className:"agent-view__filter-label",htmlFor:"agent-view-agent-filter",children:"Agent"}),s.jsx(d.Combobox,{id:"agent-view-agent-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All agents",options:ve,value:ee,onValueChange:Ge,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear agents"})]})]}),_==="error"?s.jsxs("div",{className:"agent-view__state agent-view__state--error",role:"alert",children:[s.jsx(d.Icon,{name:"triangle-alert",size:24,color:"var(--color-semantic-destructive-600)"}),s.jsx("p",{className:"agent-view__state-message",children:C??Nt}),s.jsx(d.Button,{variant:"secondary",size:"S",onClick:R,children:"Try again"})]}):_==="loading"&&y.length===0?s.jsxs("div",{className:"agent-view__state","aria-live":"polite",children:[s.jsx(d.Icon,{name:"loader",size:24,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:ht}),s.jsx("p",{className:"agent-view__state-message",children:ht})]}):y.length===0?s.jsx(gs,{}):s.jsxs("div",{className:"agent-view__board",children:[Zt.map(m=>s.jsx(kt,{column:He[m],agents:Re[m]??[],...te},m)),s.jsx("div",{className:"agent-view__split-column",children:es.map(m=>s.jsx(kt,{column:He[m],agents:Re[m]??[],isSplit:!0,...te},m))})]}),w&&s.jsx($t,{agent:w,invocationId:w.invocation_id,open:!0,jwt:t,headers:P,agentUrl:r,agentChecklistUrl:l,agentResourcesUrl:i,agentTimelineUrl:u,agentChatUrl:c,agentConversationUrl:v,enableUpload:f,initialChecklist:D[w.invocation_id]??null,onClose:ke},w.id),s.jsx(Bt,{open:I,onClose:()=>U(!1),onStart:Je,agentDefinitions:k})]})},_n=(t,e)=>{const n=Date.now(),a=e.trim()||t.agent_intent;return{id:`agent-${n}`,invocation_id:`inv-${n}`,agent_definition_ref:t.ref,agent_intent:t.agent_intent,invocation_name:a,application_id:ts,created_by:ss,status:A["generating-a-response"],context_ref:null,checklist_ref:null}};exports.AgentMonitorKanban=mn;exports.AgentServiceClient=Fe;exports.AgentServiceError=pe;exports.AgentView=$t;exports.HttpChatConnector=Lt;exports.NewAgentModal=Bt;exports.buildAgentFromDefinition=_n;exports.createHttpChatConnectorFactory=ot;exports.mapApiAgent=tt;exports.mapApiAgentDefinition=nt;exports.mapApiAgentStatus=Ct;exports.mapApiAgentTimelineResponse=It;exports.mapApiChecklistEndpointResponse=rt;exports.mapApiChecklistItem=at;exports.mapApiChecklistResponse=Ot;exports.mapApiChecklistStatus=Et;exports.mapApiConversationMessages=Pt;exports.mapApiOpeningMessage=je;exports.mapApiResource=Tt;exports.mapApiResourcesEndpointResponse=Rt;exports.mapApiTripOption=Hs;exports.useAgentService=Ut;exports.useAgentWorkspace=Dt;