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