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