@arbor-education/agent-view-frontend 0.5.1 → 0.5.3

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