@arbor-education/agent-view-frontend 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),i=require("react"),L=require("classnames"),u=require("@arbor-education/design-system.components"),se=require("@arbor-education/ask-arbor-chat-panel"),v={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},S={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},N={briefing:"briefing",running:"running",stopped:"stopped",complete:"complete"},B={agent:"agent",user:"user",system:"system"},Z={MIS_RECORD:"MIS_RECORD",FILE:"FILE",WORKFLOW:"WORKFLOW",LINK:"LINK"},Te={cancelled:"cancelled",archived:"archived"},ke={in_progress:"in_progress",requires_attention:"requires_attention",available:"available"},U={[S.complete]:{label:"Complete",icon:"circle-check",color:"var(--color-semantic-success-600)"},[S.failed]:{label:"Failed",icon:"circle-x",color:"var(--color-semantic-destructive-600)"},[S.hitl]:{label:"Requires attention",icon:"triangle-alert",color:"var(--color-semantic-warning-600)"},[S["generating-a-response"]]:{label:"Generating a response",icon:"loader",color:"var(--color-brand-600)"}},pe={[v["generating-a-response"]]:{status:v["generating-a-response"],title:"Active",dotColour:"green",statusIcon:{name:U["generating-a-response"].icon,color:U["generating-a-response"].color,spin:!0}},[v.hitl]:{status:v.hitl,title:"Requires attention",dotColour:"orange",statusIcon:{name:U.hitl.icon,color:U.hitl.color}},[v.complete]:{status:v.complete,title:"Complete",dotColour:"green",dotModifier:"grey-dark",statusIcon:{name:U.complete.icon,color:U.complete.color}},[v.failed]:{status:v.failed,title:"Failed",dotColour:"salmon",statusIcon:{name:U.failed.icon,color:U.failed.color}}},Xe=[v["generating-a-response"],v.hitl],Ze=[v.complete,v.failed],et="m4",tt="1",$e="msg-opening",Ae="Unable to load agent tasks. Please try again.",nt="Unable to load the resources for this agent",st="Something went wrong. Please try again.",De="Unable to load agents. Please try again.",ee="Loading tasks…",Ie="Loading agents…",at="Task",rt="What recent actions have you taken?",ot={[N.briefing]:"Briefing",[N.running]:"Working",[N.stopped]:"Stopped",[N.complete]:"Complete"},it=[v["generating-a-response"],v.hitl,v.complete,v.failed],ct={[v["generating-a-response"]]:"Agents currently working on tasks for you.",[v.hitl]:"Agents that need your input before they can continue.",[v.complete]:"Agents that have finished their work.",[v.failed]:"Agents that failed or were stopped."},lt=()=>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)"})]}),dt=({status:e})=>{const t=pe[e];return t.statusIcon?n.jsx(u.Icon,{name:t.statusIcon.name,size:16,color:t.statusIcon.color,screenReaderText:t.title}):n.jsx(u.Dot,{colour:t.dotColour,label:t.title})},gt=()=>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(u.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:it.map(e=>{const t=pe[e];return n.jsxs("li",{className:"agent-view__empty-column",children:[n.jsx("span",{className:"agent-view__empty-column-indicator",children:n.jsx(dt,{status:e})}),n.jsxs("span",{className:"agent-view__empty-column-text",children:[n.jsx("span",{className:"agent-view__empty-column-title",children:t.title}),n.jsx("span",{className:"agent-view__empty-column-description",children:ct[e]})]})]},e)})}),n.jsxs("p",{className:"agent-view__empty-hint",children:["Use ",n.jsx("strong",{children:"Start an agent"})," above to begin."]})]}),n.jsx("div",{className:"agent-view__empty-visual",children:n.jsx(lt,{})})]}),ut=(e,t)=>({...e,...t.length>0?{children:t}:{}}),He=e=>{const t=[],s=[];for(const a of e){const r=a.children?He(a.children):{needsInput:[],tasks:[]};if(t.push(...r.needsInput),a.status===S.hitl){t.push({...a,children:void 0});continue}s.push(ut(a,r.tasks))}return{needsInput:t,tasks:s}},pt=e=>e.map((t,s)=>({item:t,index:s})).sort((t,s)=>{const a=t.item.status===S.hitl,r=s.item.status===S.hitl;return a!==r?a?-1:1:t.index-s.index}).map(({item:t})=>t),ht=({checklist:e})=>e.length===0?n.jsx("p",{className:"agent-view__progress-empty",children:"No tasks to display."}):n.jsx("ul",{className:"agent-view__progress-list","aria-label":"Agent tasks",children:pt(e).map(t=>{const s=U[t.status];return n.jsxs("li",{className:L("agent-view__progress-item",`agent-view__progress-item--${t.status.replace(/_/g,"-")}`),children:[n.jsx(u.Icon,{name:s.icon,size:16,color:s.color,screenReaderText:`${s.label}:`,className:L({"agent-view__progress-icon--spinning":t.status===S["generating-a-response"]})}),n.jsxs("div",{className:"agent-view__progress-item-content",children:[n.jsx("span",{className:"agent-view__progress-label",children:t.task}),t.status!==S.complete&&n.jsx("span",{className:"agent-view__progress-description",children:t.description})]})]},t.task)})}),mt=({prompts:e,classNamePrefix:t="agent-workspace",onSelect:s})=>e.length===0?null:n.jsx("div",{className:`${t}__chips`,children:e.map(a=>n.jsx("button",{type:"button",className:`${t}__chip`,onClick:()=>s(a),children:a},a))});class _t{constructor(t,s){this.connector=t,this.canSend=s.canSend,this.onTurn=s.onTurn,this.onAwaitingChange=s.onAwaitingChange}get canRate(){return!1}get canLoadHistory(){return!1}get canListInteractions(){return!1}get canSendNotification(){return!1}get ratingPopupUrls(){return{}}async sendMessage(t){var s,a;if(!this.canSend())return null;(s=this.onAwaitingChange)==null||s.call(this,!0);try{const r=await this.connector.sendMessage(t.userMessage);return this.onTurn(r),{id:r.message.id,text:r.message.text,type:se.CHAT_RESPONSE_TYPE_AGENT,...r.message.followUpPrompts?{followUpPrompts:r.message.followUpPrompts}:{}}}catch{return{id:`error-${Date.now()}`,text:st,type:se.CHAT_RESPONSE_TYPE_ERROR}}finally{(a=this.onAwaitingChange)==null||a.call(this,!1)}}async loadHistory(t){return null}async listInteractions(){return null}async rateMessage(t){}async sendNotification(t){return!1}}const ft=({connector:e,phase:t,chatHistory:s,chatSessionKey:a,startQuery:r,clarificationMessage:d,enableUpload:g=!1,onTurn:l,onAwaitingChange:w,onClarificationPrompt:f,onDismissClarification:p})=>{const _=i.useMemo(()=>new _t(e,{canSend:()=>t===N.running,onTurn:l,onAwaitingChange:w}),[e,t,l,w]),h=t!==N.running,j=t===N.running;return n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--chat","aria-label":"Chat",children:[d&&n.jsxs("div",{className:"agent-workspace__clarification",role:"region","aria-label":"Agent question",children:[n.jsx("p",{className:"agent-workspace__clarification-text",children:d.text}),d.followUpPrompts&&n.jsx(mt,{prompts:d.followUpPrompts,onSelect:f}),n.jsx("button",{type:"button",className:"agent-workspace__clarification-dismiss",onClick:p,children:"Dismiss"})]}),n.jsx("div",{className:"agent-workspace__ask-arbor",children:n.jsx(se.ChatPanel,{connector:_,chatHistory:s,startQuery:r,lockConversation:h,enableUpload:g,speechEnabled:j,speechLanguage:"en-GB",speechSubmissionDelay:1e3,slashMenuItems:[],menuContent:[],introHeading:"Message your agent",introBody:"Ask questions, share trip details, or paste a link. The agent will update the checklist as it works.",placeholder:j?"Message the agent, paste a link, or attach a file…":"The agent is not accepting messages."},a)}),t===N.stopped&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(u.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."})]}),t===N.complete&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(u.Icon,{name:"party-popper",size:16,color:"var(--color-semantic-success-600)"}),n.jsx("span",{children:"The agent has finished."})]})]})},Fe=({item:e,depth:t,canRequestInput:s,onAttentionItemClick:a})=>{const r=U[e.status],d=e.status.replace(/_/g,"-"),g=e.status===S.hitl&&s&&a,l=n.jsxs("div",{className:"agent-workspace__task-row",children:[n.jsx(u.Icon,{name:r.icon,size:16,color:r.color,screenReaderText:`${r.label}:`,className:L({"agent-workspace__task-icon--spinning":e.status===S["generating-a-response"]})}),n.jsxs("div",{className:"agent-workspace__task-content",children:[n.jsx("span",{className:"agent-workspace__task-label",children:e.task}),e.status!==S.complete&&e.description&&n.jsx("span",{className:"agent-workspace__task-description",children:e.description})]})]});return n.jsxs("li",{className:L("agent-workspace__task",`agent-workspace__task--${d}`,{"agent-workspace__task--child":t>0}),children:[g?n.jsx("button",{type:"button",className:"agent-workspace__task-button","aria-label":`Provide input for ${e.task}`,onClick:()=>a(e),children:l}):l,e.children&&e.children.length>0&&n.jsx("ul",{className:"agent-workspace__task-children",children:e.children.map(w=>n.jsx(Fe,{item:w,depth:t+1,canRequestInput:s,onAttentionItemClick:a},w.task))})]})},Re=({items:e,ariaLabel:t,canRequestInput:s,onAttentionItemClick:a})=>n.jsx("ul",{className:"agent-workspace__task-list","aria-label":t,children:e.map(r=>n.jsx(Fe,{item:r,depth:0,canRequestInput:s,onAttentionItemClick:a},r.task))}),vt=({checklist:e,isLoading:t,error:s,phase:a,canRequestInput:r,onStop:d,onAttentionItemClick:g})=>{const l=i.useMemo(()=>e?He(e):null,[e]);return n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--checklist","aria-label":"Checklist",children:[n.jsxs("div",{className:"agent-workspace__panel-header",children:[n.jsx(u.Heading,{level:4,children:"Checklist"}),a===N.running&&n.jsx(u.Button,{variant:"secondary-destructive",size:"S",iconLeftName:"circle-x",iconLeftScreenReaderText:"Stop",onClick:d,children:"Stop agent"})]}),n.jsxs("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:[t&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:ee}),n.jsx("span",{children:ee})]}),!t&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!t&&!s&&l&&n.jsxs(n.Fragment,{children:[l.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(Re,{items:l.needsInput,ariaLabel:"Tasks needing your input",canRequestInput:r,onAttentionItemClick:g})]}),l.tasks.length>0&&n.jsxs("div",{className:L("agent-workspace__task-group",{"agent-workspace__task-group--following":l.needsInput.length>0}),children:[l.needsInput.length>0&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"Other tasks"}),n.jsx(Re,{items:l.tasks,ariaLabel:"Agent tasks",canRequestInput:r,onAttentionItemClick:g})]})]}),!t&&!s&&(!l||l.needsInput.length===0&&l.tasks.length===0)&&n.jsx("p",{className:"agent-workspace__empty",children:a===N.briefing?"Tasks will appear here once the agent starts.":"No tasks to display."})]})]})},wt={[Z.MIS_RECORD]:{icon:"table",label:"Arbor MIS",color:"var(--color-brand-600)"},[Z.FILE]:{icon:"file",label:"File",color:"var(--color-semantic-caution-800)"},[Z.WORKFLOW]:{icon:"list-tree",label:"Workflow",color:"var(--color-semantic-warning-700)"},[Z.LINK]:{icon:"link",label:"Link",color:"var(--color-semantic-info-700)"}},xt=({resources:e,isLoading:t=!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(u.Heading,{level:4,children:"Resources"}),n.jsx("span",{className:"agent-workspace__panel-count",children:e.length})]}),n.jsxs("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:[t&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:"Loading resources"}),n.jsx("span",{children:"Loading resources…"})]}),!t&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!t&&!s&&e.length>0&&n.jsx("ul",{className:"agent-workspace__resource-list","aria-label":"Agent resources",children:e.map(a=>{const r=wt[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(u.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(u.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}`)})}),!t&&!s&&e.length===0&&n.jsx("p",{className:"agent-workspace__empty",children:"No resources yet."})]})]}),kt=["I'll get the details and come back to you","Skip this for now"],At=e=>{var s;const t=(s=e.prompt)!=null&&s.trim()?e.prompt.trim():`I need a bit more from you on "${e.task}". ${e.description} What can you tell me?`;return{id:`clarification-${Date.now()}`,author:B.agent,text:t,followUpPrompts:e.clarificationPrompts??kt}},ce=e=>({id:e.id,text:e.text,type:e.author===B.user?se.CHAT_RESPONSE_TYPE_USER:e.author===B.system?se.CHAT_RESPONSE_TYPE_INFO:se.CHAT_RESPONSE_TYPE_AGENT,...e.followUpPrompts?{followUpPrompts:e.followUpPrompts}:{}});class te extends Error{constructor(t,s,a){super(a??`Agent service request failed (${t})`),this.name="AgentServiceError",this.status=t,this.detail=s}}const yt="/api/v1",E={agentDefinitions:"/agent-definitions",agents:"/agents",tripOptions:"/trip-options",demoDataset:"/demo/dataset"},T={GET:"GET",POST:"POST"},St={error:"error"},Nt={user:"user"},ne={acceptJson:"application/json",acceptEventStream:"text/event-stream",contentTypeJson:"application/json",arborApplicationUrl:"X-Arbor-Application-Url"},jt=/:invocationId\b/g,Ct=e=>e.trim().replace(/^Bearer\s+/i,""),bt=e=>e.endsWith("/")?e.slice(0,-1):e;class Ne{constructor(t){var a;this.baseUrl=bt(t.baseUrl??"");const s=(a=t.token)==null?void 0:a.trim();this.token=s?Ct(s):void 0,this.customHeaders=t.headers,this.urls=t.urls??{},this.fetchImpl=t.fetch??globalThis.fetch.bind(globalThis)}setHeaders(t){this.customHeaders=t}async listAgentDefinitions(){return(await this.request(T.GET,this.resolveUrl("agentDefinitions",E.agentDefinitions))).agent_definitions??[]}getAgentDefinition(t){return this.request(T.GET,this.apiUrl(`${E.agentDefinitions}/${encodeURIComponent(t)}`))}listTripOptions(){return this.request(T.GET,this.apiUrl(E.tripOptions))}getDataset(){return this.request(T.GET,this.apiUrl(E.demoDataset))}setDataset(t){return this.request(T.POST,this.apiUrl(E.demoDataset),{dataset:t})}listAgents(t={}){const s=new URLSearchParams;t.status&&s.set("status",t.status),t.agentDefinitionRef&&s.set("agent_definition_ref",t.agentDefinitionRef);const a=s.toString()?`?${s.toString()}`:"";return this.request(T.GET,`${this.resolveUrl("agents",E.agents)}${a}`)}createAgent(t,s={}){var g,l;const a={agent_definition_ref:t},r=(g=s.invocationName)==null?void 0:g.trim(),d=(l=s.agentIntent)==null?void 0:l.trim();return r&&(a.invocation_name=r),d&&(a.agent_intent=d),this.request(T.POST,this.resolveUrl("agents",E.agents),a)}getAgent(t){return this.request(T.GET,this.resolveUrl("agent",`${E.agents}/${encodeURIComponent(t)}`,t))}getAgentChecklist(t){return this.request(T.GET,this.resolveUrl("agentChecklist",`${E.agents}/${encodeURIComponent(t)}/checklist`,t))}getAgentResources(t){return this.request(T.GET,this.resolveUrl("agentResources",`${E.agents}/${encodeURIComponent(t)}/resources`,t))}getAgentContext(t){return this.request(T.GET,this.apiUrl(`${E.agents}/${encodeURIComponent(t)}/context`))}cancelAgent(t){return this.request(T.POST,this.apiUrl(`${E.agents}/${encodeURIComponent(t)}/cancel`))}archiveAgent(t){return this.request(T.POST,this.apiUrl(`${E.agents}/${encodeURIComponent(t)}/archive`))}async chat(t,s,a={}){const r=await this.fetchImpl(this.resolveUrl("agentChat",`${E.agents}/${encodeURIComponent(t)}/chat`,t),{method:T.POST,headers:{...this.customHeaders,...this.authHeaders(),Accept:ne.acceptEventStream,"Content-Type":ne.contentTypeJson},body:JSON.stringify(s),signal:a.signal});if(!r.ok)throw await this.toError(r);if(!r.body)throw new te(r.status,null,"Chat response contained no stream body");return this.consumeSse(r.body,a.onEvent)}authHeaders(){return this.token?{Authorization:`Bearer ${this.token}`}:{}}apiUrl(t){return`${this.baseUrl}${yt}${t}`}resolveUrl(t,s,a){const r=this.urls[t];return r?a?r.replace(jt,encodeURIComponent(a)):r:this.apiUrl(s)}async request(t,s,a){const r=await this.fetchImpl(s,{method:t,headers:{...this.customHeaders,...this.authHeaders(),Accept:ne.acceptJson,...a===void 0?{}:{"Content-Type":ne.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(t){let s=null;try{s=await t.json()}catch{}return new te(t.status,s,`Agent service request failed (${t.status} ${t.statusText})`)}async consumeSse(t,s){const a=t.getReader(),r=new TextDecoder;let d="",g;const l=w=>{const{event:f,data:p}=Et(w);if(p===null)return;if(f===St.error){const h=Oe(p);throw new te(502,h,(h==null?void 0:h.message)??"Chat stream error")}const _=Oe(p);_&&(g=_,s==null||s(_))};for(;;){const{done:w,value:f}=await a.read();if(w)break;d+=r.decode(f,{stream:!0});const p=d.split(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),i=require("react"),L=require("classnames"),u=require("@arbor-education/design-system.components"),se=require("@arbor-education/ask-arbor-chat-panel"),v={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},S={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},N={briefing:"briefing",running:"running",stopped:"stopped",complete:"complete"},B={agent:"agent",user:"user",system:"system"},Z={MIS_RECORD:"MIS_RECORD",FILE:"FILE",WORKFLOW:"WORKFLOW",LINK:"LINK"},Te={cancelled:"cancelled",archived:"archived"},ke={in_progress:"in_progress",requires_attention:"requires_attention",available:"available"},U={[S.complete]:{label:"Complete",icon:"circle-check",color:"var(--color-semantic-success-600)"},[S.failed]:{label:"Failed",icon:"circle-x",color:"var(--color-semantic-destructive-600)"},[S.hitl]:{label:"Requires attention",icon:"triangle-alert",color:"var(--color-semantic-warning-600)"},[S["generating-a-response"]]:{label:"Generating a response",icon:"loader",color:"var(--color-brand-600)"}},pe={[v["generating-a-response"]]:{status:v["generating-a-response"],title:"Active",dotColour:"green",statusIcon:{name:U["generating-a-response"].icon,color:U["generating-a-response"].color,spin:!0}},[v.hitl]:{status:v.hitl,title:"Requires attention",dotColour:"orange",statusIcon:{name:U.hitl.icon,color:U.hitl.color}},[v.complete]:{status:v.complete,title:"Complete",dotColour:"green",dotModifier:"grey-dark",statusIcon:{name:U.complete.icon,color:U.complete.color}},[v.failed]:{status:v.failed,title:"Failed",dotColour:"salmon",statusIcon:{name:U.failed.icon,color:U.failed.color}}},Xe=[v["generating-a-response"],v.hitl],Ze=[v.complete,v.failed],et="m4",tt="1",De="msg-opening",Ae="Unable to load agent tasks. Please try again.",nt="Unable to load the resources for this agent",st="Something went wrong. Please try again.",$e="Unable to load agents. Please try again.",ee="Loading tasks…",Ie="Loading agents…",at="Task",rt="What recent actions have you taken?",ot={[N.briefing]:"Briefing",[N.running]:"Working",[N.stopped]:"Stopped",[N.complete]:"Complete"},it=[v["generating-a-response"],v.hitl,v.complete,v.failed],ct={[v["generating-a-response"]]:"Agents currently working on tasks for you.",[v.hitl]:"Agents that need your input before they can continue.",[v.complete]:"Agents that have finished their work.",[v.failed]:"Agents that failed or were stopped."},lt=()=>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)"})]}),dt=({status:e})=>{const t=pe[e];return t.statusIcon?n.jsx(u.Icon,{name:t.statusIcon.name,size:16,color:t.statusIcon.color,screenReaderText:t.title}):n.jsx(u.Dot,{colour:t.dotColour,label:t.title})},gt=()=>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(u.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:it.map(e=>{const t=pe[e];return n.jsxs("li",{className:"agent-view__empty-column",children:[n.jsx("span",{className:"agent-view__empty-column-indicator",children:n.jsx(dt,{status:e})}),n.jsxs("span",{className:"agent-view__empty-column-text",children:[n.jsx("span",{className:"agent-view__empty-column-title",children:t.title}),n.jsx("span",{className:"agent-view__empty-column-description",children:ct[e]})]})]},e)})}),n.jsxs("p",{className:"agent-view__empty-hint",children:["Use ",n.jsx("strong",{children:"Start an agent"})," above to begin."]})]}),n.jsx("div",{className:"agent-view__empty-visual",children:n.jsx(lt,{})})]}),ut=(e,t)=>({...e,...t.length>0?{children:t}:{}}),He=e=>{const t=[],s=[];for(const a of e){const r=a.children?He(a.children):{needsInput:[],tasks:[]};if(t.push(...r.needsInput),a.status===S.hitl){t.push({...a,children:void 0});continue}s.push(ut(a,r.tasks))}return{needsInput:t,tasks:s}},pt=e=>e.map((t,s)=>({item:t,index:s})).sort((t,s)=>{const a=t.item.status===S.hitl,r=s.item.status===S.hitl;return a!==r?a?-1:1:t.index-s.index}).map(({item:t})=>t),ht=({checklist:e})=>e.length===0?n.jsx("p",{className:"agent-view__progress-empty",children:"No tasks to display."}):n.jsx("ul",{className:"agent-view__progress-list","aria-label":"Agent tasks",children:pt(e).map(t=>{const s=U[t.status];return n.jsxs("li",{className:L("agent-view__progress-item",`agent-view__progress-item--${t.status.replace(/_/g,"-")}`),children:[n.jsx(u.Icon,{name:s.icon,size:16,color:s.color,screenReaderText:`${s.label}:`,className:L({"agent-view__progress-icon--spinning":t.status===S["generating-a-response"]})}),n.jsxs("div",{className:"agent-view__progress-item-content",children:[n.jsx("span",{className:"agent-view__progress-label",children:t.task}),t.status!==S.complete&&n.jsx("span",{className:"agent-view__progress-description",children:t.description})]})]},t.task)})}),mt=({prompts:e,classNamePrefix:t="agent-workspace",onSelect:s})=>e.length===0?null:n.jsx("div",{className:`${t}__chips`,children:e.map(a=>n.jsx("button",{type:"button",className:`${t}__chip`,onClick:()=>s(a),children:a},a))});class _t{constructor(t,s){this.connector=t,this.canSend=s.canSend,this.onTurn=s.onTurn,this.onAwaitingChange=s.onAwaitingChange}get canRate(){return!1}get canLoadHistory(){return!1}get canListInteractions(){return!1}get canSendNotification(){return!1}get ratingPopupUrls(){return{}}async sendMessage(t){var s,a;if(!this.canSend())return null;(s=this.onAwaitingChange)==null||s.call(this,!0);try{const r=await this.connector.sendMessage(t.userMessage,t.uploadFiles);return this.onTurn(r),{id:r.message.id,text:r.message.text,type:se.CHAT_RESPONSE_TYPE_AGENT,...r.message.followUpPrompts?{followUpPrompts:r.message.followUpPrompts}:{}}}catch{return{id:`error-${Date.now()}`,text:st,type:se.CHAT_RESPONSE_TYPE_ERROR}}finally{(a=this.onAwaitingChange)==null||a.call(this,!1)}}async loadHistory(t){return null}async listInteractions(){return null}async rateMessage(t){}async sendNotification(t){return!1}}const ft=({connector:e,phase:t,chatHistory:s,chatSessionKey:a,startQuery:r,clarificationMessage:c,enableUpload:l=!1,onTurn:d,onAwaitingChange:w,onClarificationPrompt:f,onDismissClarification:p})=>{const _=i.useMemo(()=>new _t(e,{canSend:()=>t===N.running,onTurn:d,onAwaitingChange:w}),[e,t,d,w]),h=t!==N.running,j=t===N.running;return n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--chat","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(mt,{prompts:c.followUpPrompts,onSelect:f}),n.jsx("button",{type:"button",className:"agent-workspace__clarification-dismiss",onClick:p,children:"Dismiss"})]}),n.jsx("div",{className:"agent-workspace__ask-arbor",children:n.jsx(se.ChatPanel,{connector:_,chatHistory:s,startQuery:r,lockConversation:h,enableUpload:l,speechEnabled:j,speechLanguage:"en-GB",speechSubmissionDelay:1e3,slashMenuItems:[],menuContent:[],introHeading:"Message your agent",introBody:"Ask questions, share trip details, or paste a link. The agent will update the checklist as it works.",placeholder:j?"Message the agent, paste a link, or attach a file…":"The agent is not accepting messages."},a)}),t===N.stopped&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(u.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."})]}),t===N.complete&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(u.Icon,{name:"party-popper",size:16,color:"var(--color-semantic-success-600)"}),n.jsx("span",{children:"The agent has finished."})]})]})},Fe=({item:e,depth:t,canRequestInput:s,onAttentionItemClick:a})=>{const r=U[e.status],c=e.status.replace(/_/g,"-"),l=e.status===S.hitl&&s&&a,d=n.jsxs("div",{className:"agent-workspace__task-row",children:[n.jsx(u.Icon,{name:r.icon,size:16,color:r.color,screenReaderText:`${r.label}:`,className:L({"agent-workspace__task-icon--spinning":e.status===S["generating-a-response"]})}),n.jsxs("div",{className:"agent-workspace__task-content",children:[n.jsx("span",{className:"agent-workspace__task-label",children:e.task}),e.status!==S.complete&&e.description&&n.jsx("span",{className:"agent-workspace__task-description",children:e.description})]})]});return n.jsxs("li",{className:L("agent-workspace__task",`agent-workspace__task--${c}`,{"agent-workspace__task--child":t>0}),children:[l?n.jsx("button",{type:"button",className:"agent-workspace__task-button","aria-label":`Provide input for ${e.task}`,onClick:()=>a(e),children:d}):d,e.children&&e.children.length>0&&n.jsx("ul",{className:"agent-workspace__task-children",children:e.children.map(w=>n.jsx(Fe,{item:w,depth:t+1,canRequestInput:s,onAttentionItemClick:a},w.task))})]})},Re=({items:e,ariaLabel:t,canRequestInput:s,onAttentionItemClick:a})=>n.jsx("ul",{className:"agent-workspace__task-list","aria-label":t,children:e.map(r=>n.jsx(Fe,{item:r,depth:0,canRequestInput:s,onAttentionItemClick:a},r.task))}),vt=({checklist:e,isLoading:t,error:s,phase:a,canRequestInput:r,onStop:c,onAttentionItemClick:l})=>{const d=i.useMemo(()=>e?He(e):null,[e]);return n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--checklist","aria-label":"Checklist",children:[n.jsxs("div",{className:"agent-workspace__panel-header",children:[n.jsx(u.Heading,{level:4,children:"Checklist"}),a===N.running&&n.jsx(u.Button,{variant:"secondary-destructive",size:"S",iconLeftName:"circle-x",iconLeftScreenReaderText:"Stop",onClick:c,children:"Stop agent"})]}),n.jsxs("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:[t&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:ee}),n.jsx("span",{children:ee})]}),!t&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!t&&!s&&d&&n.jsxs(n.Fragment,{children:[d.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(Re,{items:d.needsInput,ariaLabel:"Tasks needing your input",canRequestInput:r,onAttentionItemClick:l})]}),d.tasks.length>0&&n.jsxs("div",{className:L("agent-workspace__task-group",{"agent-workspace__task-group--following":d.needsInput.length>0}),children:[d.needsInput.length>0&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"Other tasks"}),n.jsx(Re,{items:d.tasks,ariaLabel:"Agent tasks",canRequestInput:r,onAttentionItemClick:l})]})]}),!t&&!s&&(!d||d.needsInput.length===0&&d.tasks.length===0)&&n.jsx("p",{className:"agent-workspace__empty",children:a===N.briefing?"Tasks will appear here once the agent starts.":"No tasks to display."})]})]})},wt={[Z.MIS_RECORD]:{icon:"table",label:"Arbor MIS",color:"var(--color-brand-600)"},[Z.FILE]:{icon:"file",label:"File",color:"var(--color-semantic-caution-800)"},[Z.WORKFLOW]:{icon:"list-tree",label:"Workflow",color:"var(--color-semantic-warning-700)"},[Z.LINK]:{icon:"link",label:"Link",color:"var(--color-semantic-info-700)"}},xt=({resources:e,isLoading:t=!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(u.Heading,{level:4,children:"Resources"}),n.jsx("span",{className:"agent-workspace__panel-count",children:e.length})]}),n.jsxs("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:[t&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:"Loading resources"}),n.jsx("span",{children:"Loading resources…"})]}),!t&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!t&&!s&&e.length>0&&n.jsx("ul",{className:"agent-workspace__resource-list","aria-label":"Agent resources",children:e.map(a=>{const r=wt[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(u.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(u.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}`)})}),!t&&!s&&e.length===0&&n.jsx("p",{className:"agent-workspace__empty",children:"No resources yet."})]})]}),kt=["I'll get the details and come back to you","Skip this for now"],At=e=>{var s;const t=(s=e.prompt)!=null&&s.trim()?e.prompt.trim():`I need a bit more from you on "${e.task}". ${e.description} What can you tell me?`;return{id:`clarification-${Date.now()}`,author:B.agent,text:t,followUpPrompts:e.clarificationPrompts??kt}},ce=e=>({id:e.id,text:e.text,type:e.author===B.user?se.CHAT_RESPONSE_TYPE_USER:e.author===B.system?se.CHAT_RESPONSE_TYPE_INFO:se.CHAT_RESPONSE_TYPE_AGENT,...e.followUpPrompts?{followUpPrompts:e.followUpPrompts}:{}});class te extends Error{constructor(t,s,a){super(a??`Agent service request failed (${t})`),this.name="AgentServiceError",this.status=t,this.detail=s}}const yt="/api/v1",E={agentDefinitions:"/agent-definitions",agents:"/agents",tripOptions:"/trip-options",demoDataset:"/demo/dataset"},T={GET:"GET",POST:"POST"},St={error:"error"},Nt={user:"user"},ne={acceptJson:"application/json",acceptEventStream:"text/event-stream",contentTypeJson:"application/json",arborApplicationUrl:"X-Arbor-Application-Url"},jt=/:invocationId\b/g,Ct=e=>e.trim().replace(/^Bearer\s+/i,""),bt=e=>e.endsWith("/")?e.slice(0,-1):e;class Ne{constructor(t){var a;this.baseUrl=bt(t.baseUrl??"");const s=(a=t.token)==null?void 0:a.trim();this.token=s?Ct(s):void 0,this.customHeaders=t.headers,this.urls=t.urls??{},this.fetchImpl=t.fetch??globalThis.fetch.bind(globalThis)}setHeaders(t){this.customHeaders=t}async listAgentDefinitions(){return(await this.request(T.GET,this.resolveUrl("agentDefinitions",E.agentDefinitions))).agent_definitions??[]}getAgentDefinition(t){return this.request(T.GET,this.apiUrl(`${E.agentDefinitions}/${encodeURIComponent(t)}`))}listTripOptions(){return this.request(T.GET,this.apiUrl(E.tripOptions))}getDataset(){return this.request(T.GET,this.apiUrl(E.demoDataset))}setDataset(t){return this.request(T.POST,this.apiUrl(E.demoDataset),{dataset:t})}listAgents(t={}){const s=new URLSearchParams;t.status&&s.set("status",t.status),t.agentDefinitionRef&&s.set("agent_definition_ref",t.agentDefinitionRef);const a=s.toString()?`?${s.toString()}`:"";return this.request(T.GET,`${this.resolveUrl("agents",E.agents)}${a}`)}createAgent(t,s={}){var l,d;const a={agent_definition_ref:t},r=(l=s.invocationName)==null?void 0:l.trim(),c=(d=s.agentIntent)==null?void 0:d.trim();return r&&(a.invocation_name=r),c&&(a.agent_intent=c),this.request(T.POST,this.resolveUrl("agents",E.agents),a)}getAgent(t){return this.request(T.GET,this.resolveUrl("agent",`${E.agents}/${encodeURIComponent(t)}`,t))}getAgentChecklist(t){return this.request(T.GET,this.resolveUrl("agentChecklist",`${E.agents}/${encodeURIComponent(t)}/checklist`,t))}getAgentResources(t){return this.request(T.GET,this.resolveUrl("agentResources",`${E.agents}/${encodeURIComponent(t)}/resources`,t))}getAgentContext(t){return this.request(T.GET,this.apiUrl(`${E.agents}/${encodeURIComponent(t)}/context`))}cancelAgent(t){return this.request(T.POST,this.apiUrl(`${E.agents}/${encodeURIComponent(t)}/cancel`))}archiveAgent(t){return this.request(T.POST,this.apiUrl(`${E.agents}/${encodeURIComponent(t)}/archive`))}async chat(t,s,a={}){const r=!!(a.uploadFiles&&a.uploadFiles.length>0),c=await this.fetchImpl(this.resolveUrl("agentChat",`${E.agents}/${encodeURIComponent(t)}/chat`,t),{method:T.POST,headers:{...this.customHeaders,...this.authHeaders(),Accept:ne.acceptEventStream,...r?{}:{"Content-Type":ne.contentTypeJson}},body:r?Tt(s,a.uploadFiles??[]):JSON.stringify(s),signal:a.signal});if(!c.ok)throw await this.toError(c);if(!c.body)throw new te(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(t){return`${this.baseUrl}${yt}${t}`}resolveUrl(t,s,a){const r=this.urls[t];return r?a?r.replace(jt,encodeURIComponent(a)):r:this.apiUrl(s)}async request(t,s,a){const r=await this.fetchImpl(s,{method:t,headers:{...this.customHeaders,...this.authHeaders(),Accept:ne.acceptJson,...a===void 0?{}:{"Content-Type":ne.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(t){let s=null;try{s=await t.json()}catch{}return new te(t.status,s,`Agent service request failed (${t.status} ${t.statusText})`)}async consumeSse(t,s){const a=t.getReader(),r=new TextDecoder;let c="",l;const d=w=>{const{event:f,data:p}=Et(w);if(p===null)return;if(f===St.error){const h=Oe(p);throw new te(502,h,(h==null?void 0:h.message)??"Chat stream error")}const _=Oe(p);_&&(l=_,s==null||s(_))};for(;;){const{done:w,value:f}=await a.read();if(w)break;c+=r.decode(f,{stream:!0});const p=c.split(`
2
2
 
3
- `);d=p.pop()??"";for(const _ of p)l(_)}if(d.trim()&&l(d),!g)throw new te(502,null,"Chat stream ended without any events");return g}}const Et=e=>{let t=null;const s=[];for(const a of e.split(`
3
+ `);c=p.pop()??"";for(const _ of p)d(_)}if(c.trim()&&d(c),!l)throw new te(502,null,"Chat stream ended without any events");return l}}const Et=e=>{let t=null;const s=[];for(const a of e.split(`
4
4
  `)){const r=a.trimEnd();r.startsWith("event:")?t=r.slice(6).trim():r.startsWith("data:")&&s.push(r.slice(5).trim())}return{event:t,data:s.length>0?s.join(`
5
- `):null}},Oe=e=>{try{return JSON.parse(e)}catch{return}},Tt={id:$e,author:B.agent,text:"I'm connected to this agent. Ask me how it's progressing, or send an instruction and I’ll act on it."};let Pe=0;const Me=e=>(Pe+=1,`${e}-${Date.now()}-${Pe}`),It=e=>{const t=e.destination?` to ${e.destination}`:"";return`Let's get started on ${e.tripName.trim()||e.destination.trim()||"this task"}${t}. What will you do first?`};class Be{constructor(t,s,a={}){this.seededChecklist=[],this.client=t,this.agentId=s,this.opening=a.openingMessage??Tt,this.model=a.model,this.bootstrapPrompt=a.bootstrapPrompt??rt}openingMessage(){return this.opening}async bootstrapConversation(t=this.bootstrapPrompt){const s=t.trim();if(!s)return[this.opening];const a={id:Me("msg-user"),author:B.user,text:s},r=await this.exchange(s);return[a,r.message]}async start(t){return{...await this.exchange(It(t)),phase:N.running}}sendMessage(t){return this.exchange(t)}async stop(){}seedChecklist(t){this.seededChecklist=t}async exchange(t){var d;const s=[{role:Nt.user,content:t}],a=await this.client.chat(this.agentId,{messages:s,...this.chatId?{chat_id:this.chatId}:{},...this.model?{model:this.model}:{},moderation_enabled:!0,meta:{feature_id:"agent_view",source:"agent_view_frontend"}});return this.chatId=a.chat_id,{message:{id:a.event_id||Me("msg-agent"),author:B.agent,text:a.message.content,...(d=a.follow_up_prompts)!=null&&d.length?{followUpPrompts:a.follow_up_prompts}:{}}}}}const je=(e,t)=>s=>{var a;return new Be(e,s.invocation_id,{model:t==null?void 0:t.model,bootstrapPrompt:t==null?void 0:t.bootstrapPrompt,openingMessage:((a=t==null?void 0:t.resolveOpeningMessage)==null?void 0:a.call(t,s))??(t==null?void 0:t.openingMessage)})},Ge=e=>{switch(e){case Te.cancelled:return v.failed;case Te.archived:return v.complete;case v.hitl:case v.complete:case v.failed:case v["generating-a-response"]:return e;default:return v["generating-a-response"]}},qe=e=>{switch(e){case ke.requires_attention:return S.hitl;case ke.in_progress:case ke.available:return S["generating-a-response"];case S.failed:case S.complete:case S.hitl:case S["generating-a-response"]:return e;default:return S["generating-a-response"]}},Ke=e=>({ref:e.name,display_name:e.display_name,agent_intent:e.agent_intent??e.display_name,description:e.description}),Rt=e=>({id:e.id,name:e.name,...e.has_run_before?{hasRunBefore:e.has_run_before}:{}}),Ot=new Set(Object.values(Z)),Pt=e=>e&&Ot.has(e)?e:Z.LINK,ze=e=>({uri:e.uri??"",type:Pt(e.type),name:e.name??"",description:e.description??""}),Ce=e=>(Array.isArray(e)?e:e.resources??[]).map(ze),ye=e=>{var s;const t=e.invocation_id??e.id;return{id:e.id,invocation_id:t,agent_definition_ref:e.agent_definition_ref,...e.agent_intent?{agent_intent:e.agent_intent}:{},invocation_name:((s=e.invocation_name)==null?void 0:s.trim())||e.agent_definition_ref,application_id:e.application_id,...e.application_name?{application_name:e.application_name}:{},created_by:e.created_by,status:Ge(e.status),context_ref:e.context_ref??null,checklist_ref:e.checklist_ref??null}},be=e=>{var t;return{task:e.task??e.name??e.label??at,status:qe(e.status),description:e.description??"",...e.prompt?{prompt:e.prompt}:{},...(t=e.follow_up_prompts)!=null&&t.length?{clarificationPrompts:e.follow_up_prompts}:{}}},Mt=e=>Array.isArray(e)?e:e.checklist_items??e.checklist??e.items??[],Ee=(e,t,s)=>{var d;const a=!Array.isArray(t)&&(t.opening_message||(d=t.opening_follow_up_prompts)!=null&&d.length)?t:s,r=a?le(a):void 0;return{invocation_id:e,checklist:Mt(t).map(be),...r?{openingMessage:r}:{}}},Lt=(e,t)=>{const s=le(t);return{invocation_id:t.invocation_id??e,checklist:(t.checklist_items??[]).map(be),...s?{openingMessage:s}:{}}},le=e=>{var s,a;const t=(s=e.opening_message)==null?void 0:s.trim();if(t)return{id:$e,author:B.agent,text:t,...(a=e.opening_follow_up_prompts)!=null&&a.length?{followUpPrompts:e.opening_follow_up_prompts}:{}}},Ut=e=>e instanceof te?e.message:e instanceof TypeError?"Network error while contacting the agent service.":e instanceof Error&&e.message?e.message:De,$t=e=>{const t={};for(const s of e){const a=le(s);if(!a)continue;const r=s.invocation_id??s.id;t[r]=a,t[s.id]=a}return t},Dt=e=>JSON.stringify(e),We=e=>{const{jwt:t,headers:s,urls:a}=e,r=JSON.stringify(s??{}),d=Dt(a),g=i.useMemo(()=>new Ne({token:t,headers:s,urls:a}),[t,d]);i.useLayoutEffect(()=>{g.setHeaders(s)},[g,r]);const[l,w]=i.useState([]),[f,p]=i.useState([]),[_,h]=i.useState({}),[j,b]=i.useState("loading"),[k,y]=i.useState(null),[x,O]=i.useState(0);i.useEffect(()=>{let A=!1;return b("loading"),y(null),(async()=>{try{const[C,M]=await Promise.all([g.listAgents(),g.listAgentDefinitions()]);if(A)return;w(C.map(ye)),p(M.map(Ke)),h($t(C)),b("idle")}catch(C){if(A)return;w([]),p([]),h({}),b("error"),y(Ut(C))}})(),()=>{A=!0}},[g,x]);const G=i.useCallback(()=>{O(A=>A+1)},[]),P=i.useCallback(async A=>{const[C,M]=await Promise.all([g.getAgentChecklist(A),g.getAgent(A).catch(()=>null)]);return Ee(A,C,M??void 0)},[g]),J=i.useCallback(async A=>{const C=await g.getAgentResources(A);return Ce(C)},[g]),V=i.useCallback(async({definition:A,invocationName:C})=>{const M=await g.createAgent(A.ref,{invocationName:C}),K=await g.getAgent(M.id),I=ye(K),$=le(K);return w(D=>[I,...D]),$&&h(D=>({...D,[I.invocation_id]:$,[I.id]:$})),I},[g]),q=i.useMemo(()=>je(g,{resolveOpeningMessage:A=>_[A.invocation_id]??_[A.id]}),[g,_]);return{agents:l,agentDefinitions:f,loadState:j,loadError:k,reload:G,fetchAgentChecklist:P,fetchAgentResources:J,createAgent:V,chatConnector:q}},Ht=e=>JSON.stringify(e),Je=e=>{const{agent:t,jwt:s,headers:a,urls:r}=e,d=JSON.stringify(a??{}),g=Ht(r),l=i.useMemo(()=>new Ne({token:s,headers:a,urls:{agent:r.agentUrl,agentChecklist:r.agentChecklistUrl,agentResources:r.agentResourcesUrl,agentChat:r.agentChatUrl}}),[s,g]);i.useLayoutEffect(()=>{l.setHeaders(a)},[l,d]);const w=i.useCallback(async _=>{const[h,j]=await Promise.all([l.getAgentChecklist(_),l.getAgent(_).catch(()=>null)]);return Ee(_,h,j??void 0)},[l]),f=i.useCallback(async _=>{const h=await l.getAgentResources(_);return Ce(h)},[l]);return{connector:i.useMemo(()=>je(l)(t),[l,t]),fetchAgentChecklist:w,fetchAgentResources:f}},Ft=(e,t)=>{const s=e.hasRunBefore?t||"This trip":e.tripName.trim()||"A new trip",a=e.destination?` to ${e.destination}`:"",r=e.hasRunBefore?" It has run before.":"";return`${s}${a}.${r}`.trim()},Bt=e=>{switch(e){case v.failed:return N.stopped;case v.complete:return N.complete;default:return N.running}},Le=(e,t)=>{t([ce(e)])},Ve=({agent:e,open:t,onClose:s,jwt:a,headers:r,agentUrl:d,agentChecklistUrl:g,agentResourcesUrl:l,agentChatUrl:w,enableUpload:f,initialBrief:p,initialPhase:_,initialChecklist:h})=>{const{connector:j,fetchAgentChecklist:b,fetchAgentResources:k}=Je({agent:e,jwt:a,headers:r,urls:{agentUrl:d,agentChecklistUrl:g,agentResourcesUrl:l,agentChatUrl:w}}),y=i.useRef(j),[x,O]=i.useState(_??(p?N.running:Bt(e.status))),[G,P]=i.useState([]),[J,V]=i.useState(0),[q,A]=i.useState(),[C,M]=i.useState(null),[K,I]=i.useState([]),[$,D]=i.useState(!1),[ae,z]=i.useState(null),[he,H]=i.useState(h??null),[me,re]=i.useState(!1),[W,oe]=i.useState(null),[de,Y]=i.useState(!1),[Q,_e]=i.useState(!1),[X,fe]=i.useState(!1),F=i.useRef(!1);i.useEffect(()=>{y.current=j},[j]),i.useEffect(()=>{F.current=!1,P([]),V(o=>o+1)},[e.invocation_id]),i.useEffect(()=>{if(!t||p||F.current)return;const o=y.current.bootstrapConversation;if(!o){Le(y.current.openingMessage(),P);return}F.current=!0;let c=!1;return Y(!0),(async()=>{try{const m=await o.call(y.current);if(c)return;P(m.map(ce))}catch{c||Le(y.current.openingMessage(),P)}finally{c||Y(!1)}})(),()=>{c=!0}},[t,p,e.invocation_id,j]);const ve=i.useCallback(o=>{o.checklist&&H(o.checklist),o.phase&&O(o.phase)},[]);i.useEffect(()=>{var o,c;!t||p||h&&h.length>0&&((c=(o=y.current).seedChecklist)==null||c.call(o,h))},[t,p,h]),i.useEffect(()=>{if(!t||p)return;let o=!1;return re(!(h!=null&&h.length)),oe(null),(async()=>{var c,m;try{const R=await b(e.invocation_id);if(o)return;h!=null&&h.length||(H(R.checklist),(m=(c=y.current).seedChecklist)==null||m.call(c,R.checklist))}catch{!o&&!(h!=null&&h.length)&&oe(Ae)}finally{o||re(!1)}})(),()=>{o=!0}},[t,e.invocation_id,p,h,b]),i.useEffect(()=>{if(!t)return;let o=!1;return D(!0),z(null),(async()=>{try{const c=await k(e.invocation_id);o||I(c)}catch{o||z(nt)}finally{o||D(!1)}})(),()=>{o=!0}},[t,e.invocation_id,k]),i.useEffect(()=>{if(!t||!p||F.current)return;F.current=!0;const o={id:`user-brief-${Date.now()}`,author:B.user,text:Ft(p,e.invocation_name)};(async()=>{const c=await y.current.start(p);P([ce(y.current.openingMessage()),ce(o),ce(c.message)]),c.checklist&&H(c.checklist),O(c.phase??N.running)})()},[t,p,e.invocation_name]);const we=i.useCallback(o=>{M(At(o))},[]),xe=i.useCallback(o=>{M(null),A(o),V(c=>c+1)},[]),ge=i.useCallback(async()=>{await y.current.stop(),O(N.stopped)},[]),ue=he;return n.jsxs(u.Modal,{open:t,closeHandler:s,hideCloseButton:!0,className:"agent-workspace",children:[n.jsxs(u.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(u.Icon,{name:"ask-arbor",size:24})}),n.jsx(u.Modal.Title,{children:e.invocation_name}),n.jsx("span",{className:L("agent-workspace__phase",`agent-workspace__phase--${x}`),children:ot[x]})]}),n.jsxs("div",{className:"agent-workspace__header-actions",children:[n.jsx(u.Button,{variant:"tertiary",size:"S",iconLeftName:"clipboard-list",iconLeftScreenReaderText:"Toggle checklist","aria-pressed":!X,onClick:()=>fe(o=>!o),children:"Checklist"}),n.jsx(u.Button,{variant:"tertiary",size:"S",iconLeftName:"files",iconLeftScreenReaderText:"Toggle resources","aria-pressed":!Q,onClick:()=>_e(o=>!o),children:"Resources"}),n.jsx(u.Button,{variant:"secondary",size:"S",iconLeftName:"x",iconLeftScreenReaderText:"Close",onClick:s,children:"Close"})]})]}),n.jsxs(u.Modal.Body,{className:L("agent-workspace__body",{"agent-workspace__body--no-left":X,"agent-workspace__body--no-right":Q}),children:[!X&&n.jsx(vt,{checklist:ue,isLoading:me,error:W,phase:x,canRequestInput:x===N.running&&!de,onStop:()=>void ge(),onAttentionItemClick:we}),n.jsx(ft,{connector:y.current,phase:x,chatHistory:G,chatSessionKey:J,startQuery:q,clarificationMessage:C,enableUpload:f,onTurn:ve,onAwaitingChange:Y,onClarificationPrompt:xe,onDismissClarification:()=>M(null)}),!Q&&n.jsx(xt,{resources:K,isLoading:$,error:ae})]})]})},Ye=({open:e,onClose:t,onStart:s,agentDefinitions:a})=>{const r=a[0],[d,g]=i.useState(r),[l,w]=i.useState(""),[f,p]=i.useState(!1),[_,h]=i.useState(null),j=[...a].sort((x,O)=>x.agent_intent.localeCompare(O.agent_intent)).map(x=>({value:x.ref,label:x.agent_intent}));i.useEffect(()=>{e&&(g(r),w(""),p(!1),h(null))},[e,r]);const b=d!==void 0&&l.trim().length>0,k=i.useCallback(x=>{const O=a.find(G=>G.ref===x[0]);O&&g(O)},[a]),y=i.useCallback(async()=>{if(!(!d||!b||f)){p(!0),h(null);try{await s({definition:d,invocationName:l.trim()})}catch(x){h(x instanceof Error?x.message:"Unable to start the agent.")}finally{p(!1)}}},[b,d,l,f,s]);return!d||a.length===0?null:n.jsxs(u.Modal,{open:e,closeHandler:t,className:"new-agent",children:[n.jsx(u.Modal.Header,{className:"new-agent__header",children:n.jsxs("div",{className:"new-agent__header-title",children:[n.jsx("span",{className:"new-agent__header-avatar","aria-hidden":"true",children:n.jsx(u.Icon,{name:"ask-arbor",size:24})}),n.jsx(u.Modal.Title,{children:"Start an agent"})]})}),n.jsx(u.Modal.Body,{className:"new-agent__body",children:n.jsxs("form",{className:"new-agent__form","aria-label":"Start an agent",onSubmit:x=>{x.preventDefault(),b&&!f&&y()},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(u.SelectDropdown,{id:"new-agent-type",placeholder:"Choose an intent",options:j,selectedValues:[d.ref],onSelectionChange:k}),n.jsx("p",{className:"new-agent__type-description",children:d.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(u.TextInput,{id:"new-agent-invocation-name",value:l,placeholder:"e.g. Test with memory3",onChange:x=>w(x.target.value)})]}),_?n.jsx("p",{className:"new-agent__error",role:"alert",children:_}):null,n.jsx("div",{className:"new-agent__actions",children:n.jsx(u.Button,{type:"submit",variant:"primary",disabled:!b||f,iconLeftName:f?"loader":"sparkles",iconLeftScreenReaderText:f?"Starting":void 0,children:f?"Starting…":"Start"})})]})})]})},Gt=e=>e!==void 0&&e.some(t=>t.status===S.hitl),qt=(e,t)=>Gt(t)?v.hitl:e.status,Kt=({column:e,label:t})=>e.statusIcon?n.jsx("span",{className:"agent-view__status-indicator",children:n.jsx(u.Icon,{name:e.statusIcon.name,size:16,color:e.statusIcon.color,className:L({"agent-view__progress-icon--spinning":e.statusIcon.spin}),screenReaderText:t})}):n.jsx("span",{className:L("agent-view__dot",{[`agent-view__dot--${e.dotModifier}`]:e.dotModifier}),children:n.jsx(u.Dot,{colour:e.dotColour,label:t})}),zt=({agent:e,agentName:t,column:s,isExpanded:a,isLoading:r,checklist:d,error:g,onToggle:l,onViewAgent:w})=>{const{id:f,invocation_name:p}=e,_=`agent-card-${f}-header`,h=`agent-card-${f}-progress`;return n.jsx("li",{className:L("agent-view__card",{"agent-view__card--expanded":a}),children:n.jsxs(u.Card,{spacing:"dense",children:[n.jsx("button",{type:"button",className:"agent-view__card-toggle","aria-expanded":a,"aria-controls":h,"aria-label":p,id:_,onClick:()=>l(f),children:n.jsxs("div",{className:"agent-view__card-content",children:[n.jsx(Kt,{column:s}),n.jsx("span",{className:"agent-view__card-invocation-name",children:p}),n.jsx("span",{className:"agent-view__card-agent-name",children:t}),n.jsx(u.Icon,{name:a?"chevron-up":"chevron-down",size:16,className:"agent-view__card-chevron"})]})}),a&&n.jsxs("div",{id:h,"aria-labelledby":_,className:"agent-view__card-progress",children:[r&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:ee}),n.jsx("span",{children:ee})]}),!r&&g&&n.jsx("p",{className:"agent-view__progress-error",role:"alert",children:g}),!r&&!g&&d!==null&&n.jsx(ht,{checklist:d}),!r&&!g&&d===null&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:ee}),n.jsx("span",{children:ee})]}),n.jsx("div",{className:"agent-view__card-actions",children:n.jsx(u.Button,{variant:"secondary",size:"S",onClick:()=>w==null?void 0:w(e),children:"View agent"})})]})]})})},Ue=({column:e,agents:t,expandedAgentId:s,loadingAgentId:a,checklistByInvocationId:r,errorByAgentId:d,definitionNameByRef:g,onToggleAgent:l,onViewAgent:w,isSplit:f=!1})=>n.jsxs("section",{className:L("agent-view__column",{"agent-view__column--split":f}),"aria-label":e.title,children:[n.jsxs("div",{className:"agent-view__column-header",children:[n.jsx(u.Heading,{level:4,children:e.title}),n.jsx("span",{className:"agent-view__column-count",children:t.length})]}),n.jsx("ul",{className:"agent-view__card-list",children:t.map(p=>n.jsx(zt,{agent:p,agentName:Se(p,g),column:e,isExpanded:s===p.id,isLoading:a===p.id,checklist:r[p.invocation_id]??null,error:d[p.id]??null,onToggle:l,onViewAgent:w},p.id))})]}),Se=(e,t)=>t.get(e.agent_definition_ref)??e.agent_definition_ref.replace(/_/g," "),Wt=({jwt:e,headers:t,agentDefinitionsUrl:s,agentsUrl:a,agentUrl:r,agentChecklistUrl:d,agentResourcesUrl:g,agentChatUrl:l,enableUpload:w,institutions:f})=>{var ue;const p=i.useMemo(()=>({agentDefinitions:s,agents:a,agent:r,agentChecklist:d,agentResources:g,agentChat:l}),[s,a,r,d,g,l]),[_,h]=i.useState(null),j=_?(ue=f==null?void 0:f.find(o=>o.applicationId===_.application_id))==null?void 0:ue.applicationUrl:void 0,b=i.useMemo(()=>{const o={...t??{}};return j?o[ne.arborApplicationUrl]=j:delete o[ne.arborApplicationUrl],o},[t,j]),{agents:k,agentDefinitions:y,loadState:x,loadError:O,reload:G,fetchAgentChecklist:P,createAgent:J}=We({jwt:e,headers:b,urls:p}),[V,q]=i.useState(!1),[A,C]=i.useState(null),[M,K]=i.useState(null),[I,$]=i.useState({}),[D,ae]=i.useState({}),[z,he]=i.useState([]),[H,me]=i.useState([]),re=i.useMemo(()=>{const o=new Set(k.map(m=>m.application_id)),c=new Map((f??[]).map(m=>[m.applicationId,m.name]));return[...o].sort((m,R)=>(c.get(m)??m).localeCompare(c.get(R)??R)).map(m=>({value:m,label:c.get(m)??m}))},[k,f]),W=i.useMemo(()=>new Map(y.map(o=>[o.ref,o.display_name])),[y]),oe=i.useMemo(()=>[...new Set(k.map(c=>Se(c,W)))].sort((c,m)=>c.localeCompare(m)).map(c=>({value:c,label:c})),[k,W]),de=i.useMemo(()=>k.filter(o=>!(z.length>0&&!z.includes(o.application_id)||H.length>0&&!H.includes(Se(o,W)))),[k,W,H,z]),Y=re.length>1,Q=oe.length>1,_e=Y||Q;i.useEffect(()=>{if(k.length===0)return;let o=!1;return(async()=>{const c=await Promise.allSettled(k.map(async m=>{const R=await P(m.invocation_id);return{agentId:m.id,invocationId:m.invocation_id,checklist:R.checklist}}));o||($(m=>{const R={...m};for(const ie of c)ie.status==="fulfilled"&&(R[ie.value.invocationId]=ie.value.checklist);return R}),ae(m=>{const R={...m};return c.forEach((ie,Qe)=>{ie.status==="rejected"&&(R[k[Qe].id]=Ae)}),R}))})(),()=>{o=!0}},[k,P]);const X=i.useCallback(async o=>{if(!I[o.invocation_id]){K(o.id),ae(c=>{const m={...c};return delete m[o.id],m});try{const c=await P(o.invocation_id);$(m=>({...m,[o.invocation_id]:c.checklist}))}catch{ae(c=>({...c,[o.id]:Ae}))}finally{K(c=>c===o.id?null:c)}}},[P,I]),fe=i.useCallback(o=>{if(A===o){C(null);return}const c=k.find(({id:m})=>m===o);c&&(C(o),X(c))},[k,A,X]),F=i.useMemo(()=>{const o={};for(const c of de){const m=qt(c,I[c.invocation_id]);(o[m]??(o[m]=[])).push(c)}return o},[de,I]),ve=i.useCallback(o=>{h(o)},[]),we=i.useCallback(async o=>{const c=await J(o);h(c),q(!1)},[J]),xe=i.useCallback(()=>{h(null)},[]),ge={expandedAgentId:A,loadingAgentId:M,checklistByInvocationId:I,errorByAgentId:D,definitionNameByRef:W,onToggleAgent:fe,onViewAgent:ve};return n.jsxs("div",{className:"agent-view-frontend agent-view",children:[n.jsxs("div",{className:"agent-view__header",children:[n.jsx(u.Heading,{level:1,children:"Agents"}),n.jsx(u.Button,{variant:"primary",size:"S",iconLeftName:"sparkles",iconLeftScreenReaderText:"Start an agent",onClick:()=>q(!0),children:"Start an agent"})]}),k.length>0&&_e&&n.jsxs("div",{className:"agent-view__filters",children:[Y&&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(u.Combobox,{id:"agent-view-institution-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All institutions",options:re,value:z,onValueChange:he,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear institutions"})]}),Q&&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(u.Combobox,{id:"agent-view-agent-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All agents",options:oe,value:H,onValueChange:me,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear agents"})]})]}),x==="error"?n.jsxs("div",{className:"agent-view__state agent-view__state--error",role:"alert",children:[n.jsx(u.Icon,{name:"triangle-alert",size:24,color:"var(--color-semantic-destructive-600)"}),n.jsx("p",{className:"agent-view__state-message",children:O??De}),n.jsx(u.Button,{variant:"secondary",size:"S",onClick:G,children:"Try again"})]}):x==="loading"&&k.length===0?n.jsxs("div",{className:"agent-view__state","aria-live":"polite",children:[n.jsx(u.Icon,{name:"loader",size:24,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:Ie}),n.jsx("p",{className:"agent-view__state-message",children:Ie})]}):k.length===0?n.jsx(gt,{}):n.jsxs("div",{className:"agent-view__board",children:[Xe.map(o=>n.jsx(Ue,{column:pe[o],agents:F[o]??[],...ge},o)),n.jsx("div",{className:"agent-view__split-column",children:Ze.map(o=>n.jsx(Ue,{column:pe[o],agents:F[o]??[],isSplit:!0,...ge},o))})]}),_&&n.jsx(Ve,{agent:_,open:!0,jwt:e,headers:b,agentUrl:r,agentChecklistUrl:d,agentResourcesUrl:g,agentChatUrl:l,enableUpload:w,initialChecklist:I[_.invocation_id]??null,onClose:xe},_.id),n.jsx(Ye,{open:V,onClose:()=>q(!1),onStart:we,agentDefinitions:y})]})},Jt=(e,t)=>{const s=Date.now(),a=t.trim()||e.agent_intent;return{id:`agent-${s}`,invocation_id:`inv-${s}`,agent_definition_ref:e.ref,agent_intent:e.agent_intent,invocation_name:a,application_id:et,created_by:tt,status:v["generating-a-response"],context_ref:null,checklist_ref:null}};exports.AgentMonitorKanban=Wt;exports.AgentServiceClient=Ne;exports.AgentServiceError=te;exports.AgentView=Ve;exports.HttpChatConnector=Be;exports.NewAgentModal=Ye;exports.buildAgentFromDefinition=Jt;exports.createHttpChatConnectorFactory=je;exports.mapApiAgent=ye;exports.mapApiAgentDefinition=Ke;exports.mapApiAgentStatus=Ge;exports.mapApiChecklistEndpointResponse=Ee;exports.mapApiChecklistItem=be;exports.mapApiChecklistResponse=Lt;exports.mapApiChecklistStatus=qe;exports.mapApiOpeningMessage=le;exports.mapApiResource=ze;exports.mapApiResourcesEndpointResponse=Ce;exports.mapApiTripOption=Rt;exports.useAgentService=We;exports.useAgentWorkspace=Je;
5
+ `):null}},Oe=e=>{try{return JSON.parse(e)}catch{return}};function Tt(e,t){const s=new FormData;s.append("body",JSON.stringify(e));for(const a of t)s.append("files",a,a.name);return s}const It={id:De,author:B.agent,text:"I'm connected to this agent. Ask me how it's progressing, or send an instruction and I’ll act on it."};let Pe=0;const Me=e=>(Pe+=1,`${e}-${Date.now()}-${Pe}`),Rt=e=>{const t=e.destination?` to ${e.destination}`:"";return`Let's get started on ${e.tripName.trim()||e.destination.trim()||"this task"}${t}. What will you do first?`};class Be{constructor(t,s,a={}){this.seededChecklist=[],this.client=t,this.agentId=s,this.opening=a.openingMessage??It,this.model=a.model,this.bootstrapPrompt=a.bootstrapPrompt??rt}openingMessage(){return this.opening}async bootstrapConversation(t=this.bootstrapPrompt){const s=t.trim();if(!s)return[this.opening];const a={id:Me("msg-user"),author:B.user,text:s},r=await this.exchange(s);return[a,r.message]}async start(t){return{...await this.exchange(Rt(t)),phase:N.running}}sendMessage(t,s){return this.exchange(t,s)}async stop(){}seedChecklist(t){this.seededChecklist=t}async exchange(t,s){var l;const a=[{role:Nt.user,content:t}],r=await this.client.chat(this.agentId,{messages:a,...this.chatId?{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}]:[]);return this.chatId=r.chat_id,{message:{id:r.event_id||Me("msg-agent"),author:B.agent,text:r.message.content,...(l=r.follow_up_prompts)!=null&&l.length?{followUpPrompts:r.follow_up_prompts}:{}}}}}const je=(e,t)=>s=>{var a;return new Be(e,s.invocation_id,{model:t==null?void 0:t.model,bootstrapPrompt:t==null?void 0:t.bootstrapPrompt,openingMessage:((a=t==null?void 0:t.resolveOpeningMessage)==null?void 0:a.call(t,s))??(t==null?void 0:t.openingMessage)})},Ge=e=>{switch(e){case Te.cancelled:return v.failed;case Te.archived:return v.complete;case v.hitl:case v.complete:case v.failed:case v["generating-a-response"]:return e;default:return v["generating-a-response"]}},qe=e=>{switch(e){case ke.requires_attention:return S.hitl;case ke.in_progress:case ke.available:return S["generating-a-response"];case S.failed:case S.complete:case S.hitl:case S["generating-a-response"]:return e;default:return S["generating-a-response"]}},Ke=e=>({ref:e.name,display_name:e.display_name,agent_intent:e.agent_intent??e.display_name,description:e.description}),Ot=e=>({id:e.id,name:e.name,...e.has_run_before?{hasRunBefore:e.has_run_before}:{}}),Pt=new Set(Object.values(Z)),Mt=e=>e&&Pt.has(e)?e:Z.LINK,ze=e=>({uri:e.uri??"",type:Mt(e.type),name:e.name??"",description:e.description??""}),Ce=e=>(Array.isArray(e)?e:e.resources??[]).map(ze),ye=e=>{var s;const t=e.invocation_id??e.id;return{id:e.id,invocation_id:t,agent_definition_ref:e.agent_definition_ref,...e.agent_intent?{agent_intent:e.agent_intent}:{},invocation_name:((s=e.invocation_name)==null?void 0:s.trim())||e.agent_definition_ref,application_id:e.application_id,...e.application_name?{application_name:e.application_name}:{},created_by:e.created_by,status:Ge(e.status),context_ref:e.context_ref??null,checklist_ref:e.checklist_ref??null}},be=e=>{var t;return{task:e.task??e.name??e.label??at,status:qe(e.status),description:e.description??"",...e.prompt?{prompt:e.prompt}:{},...(t=e.follow_up_prompts)!=null&&t.length?{clarificationPrompts:e.follow_up_prompts}:{}}},Lt=e=>Array.isArray(e)?e:e.checklist_items??e.checklist??e.items??[],Ee=(e,t,s)=>{var c;const a=!Array.isArray(t)&&(t.opening_message||(c=t.opening_follow_up_prompts)!=null&&c.length)?t:s,r=a?le(a):void 0;return{invocation_id:e,checklist:Lt(t).map(be),...r?{openingMessage:r}:{}}},Ut=(e,t)=>{const s=le(t);return{invocation_id:t.invocation_id??e,checklist:(t.checklist_items??[]).map(be),...s?{openingMessage:s}:{}}},le=e=>{var s,a;const t=(s=e.opening_message)==null?void 0:s.trim();if(t)return{id:De,author:B.agent,text:t,...(a=e.opening_follow_up_prompts)!=null&&a.length?{followUpPrompts:e.opening_follow_up_prompts}:{}}},Dt=e=>e instanceof te?e.message:e instanceof TypeError?"Network error while contacting the agent service.":e instanceof Error&&e.message?e.message:$e,$t=e=>{const t={};for(const s of e){const a=le(s);if(!a)continue;const r=s.invocation_id??s.id;t[r]=a,t[s.id]=a}return t},Ht=e=>JSON.stringify(e),We=e=>{const{jwt:t,headers:s,urls:a}=e,r=JSON.stringify(s??{}),c=Ht(a),l=i.useMemo(()=>new Ne({token:t,headers:s,urls:a}),[t,c]);i.useLayoutEffect(()=>{l.setHeaders(s)},[l,r]);const[d,w]=i.useState([]),[f,p]=i.useState([]),[_,h]=i.useState({}),[j,b]=i.useState("loading"),[k,y]=i.useState(null),[x,O]=i.useState(0);i.useEffect(()=>{let A=!1;return b("loading"),y(null),(async()=>{try{const[C,M]=await Promise.all([l.listAgents(),l.listAgentDefinitions()]);if(A)return;w(C.map(ye)),p(M.map(Ke)),h($t(C)),b("idle")}catch(C){if(A)return;w([]),p([]),h({}),b("error"),y(Dt(C))}})(),()=>{A=!0}},[l,x]);const G=i.useCallback(()=>{O(A=>A+1)},[]),P=i.useCallback(async A=>{const[C,M]=await Promise.all([l.getAgentChecklist(A),l.getAgent(A).catch(()=>null)]);return Ee(A,C,M??void 0)},[l]),J=i.useCallback(async A=>{const C=await l.getAgentResources(A);return Ce(C)},[l]),V=i.useCallback(async({definition:A,invocationName:C})=>{const M=await l.createAgent(A.ref,{invocationName:C}),K=await l.getAgent(M.id),I=ye(K),D=le(K);return w($=>[I,...$]),D&&h($=>({...$,[I.invocation_id]:D,[I.id]:D})),I},[l]),q=i.useMemo(()=>je(l,{resolveOpeningMessage:A=>_[A.invocation_id]??_[A.id]}),[l,_]);return{agents:d,agentDefinitions:f,loadState:j,loadError:k,reload:G,fetchAgentChecklist:P,fetchAgentResources:J,createAgent:V,chatConnector:q}},Ft=e=>JSON.stringify(e),Je=e=>{const{agent:t,jwt:s,headers:a,urls:r}=e,c=JSON.stringify(a??{}),l=Ft(r),d=i.useMemo(()=>new Ne({token:s,headers:a,urls:{agent:r.agentUrl,agentChecklist:r.agentChecklistUrl,...r.agentResourcesUrl?{agentResources:r.agentResourcesUrl}:{},agentChat:r.agentChatUrl}}),[s,l]);i.useLayoutEffect(()=>{d.setHeaders(a)},[d,c]);const w=i.useCallback(async _=>{const[h,j]=await Promise.all([d.getAgentChecklist(_),d.getAgent(_).catch(()=>null)]);return Ee(_,h,j??void 0)},[d]),f=i.useCallback(async _=>{const h=await d.getAgentResources(_);return Ce(h)},[d]);return{connector:i.useMemo(()=>je(d)(t),[d,t]),fetchAgentChecklist:w,fetchAgentResources:f}},Bt=(e,t)=>{const s=e.hasRunBefore?t||"This trip":e.tripName.trim()||"A new trip",a=e.destination?` to ${e.destination}`:"",r=e.hasRunBefore?" It has run before.":"";return`${s}${a}.${r}`.trim()},Gt=e=>{switch(e){case v.failed:return N.stopped;case v.complete:return N.complete;default:return N.running}},Le=(e,t)=>{t([ce(e)])},Ve=({agent:e,open:t,onClose:s,jwt:a,headers:r,agentUrl:c,agentChecklistUrl:l,agentResourcesUrl:d,agentChatUrl:w,enableUpload:f,initialBrief:p,initialPhase:_,initialChecklist:h})=>{const{connector:j,fetchAgentChecklist:b,fetchAgentResources:k}=Je({agent:e,jwt:a,headers:r,urls:{agentUrl:c,agentChecklistUrl:l,agentResourcesUrl:d,agentChatUrl:w}}),y=i.useRef(j),[x,O]=i.useState(_??(p?N.running:Gt(e.status))),[G,P]=i.useState([]),[J,V]=i.useState(0),[q,A]=i.useState(),[C,M]=i.useState(null),[K,I]=i.useState([]),[D,$]=i.useState(!1),[ae,z]=i.useState(null),[he,H]=i.useState(h??null),[me,re]=i.useState(!1),[W,oe]=i.useState(null),[de,Y]=i.useState(!1),[Q,_e]=i.useState(!1),[X,fe]=i.useState(!1),F=i.useRef(!1);i.useEffect(()=>{y.current=j},[j]),i.useEffect(()=>{F.current=!1,P([]),V(o=>o+1)},[e.invocation_id]),i.useEffect(()=>{if(!t||p||F.current)return;const o=y.current.bootstrapConversation;if(!o){Le(y.current.openingMessage(),P);return}F.current=!0;let g=!1;return Y(!0),(async()=>{try{const m=await o.call(y.current);if(g)return;P(m.map(ce))}catch{g||Le(y.current.openingMessage(),P)}finally{g||Y(!1)}})(),()=>{g=!0}},[t,p,e.invocation_id,j]);const ve=i.useCallback(o=>{o.checklist&&H(o.checklist),o.phase&&O(o.phase)},[]);i.useEffect(()=>{var o,g;!t||p||h&&h.length>0&&((g=(o=y.current).seedChecklist)==null||g.call(o,h))},[t,p,h]),i.useEffect(()=>{if(!t||p)return;let o=!1;return re(!(h!=null&&h.length)),oe(null),(async()=>{var g,m;try{const R=await b(e.invocation_id);if(o)return;h!=null&&h.length||(H(R.checklist),(m=(g=y.current).seedChecklist)==null||m.call(g,R.checklist))}catch{!o&&!(h!=null&&h.length)&&oe(Ae)}finally{o||re(!1)}})(),()=>{o=!0}},[t,e.invocation_id,p,h,b]),i.useEffect(()=>{if(!t||!d)return;let o=!1;return $(!0),z(null),(async()=>{try{const g=await k(e.invocation_id);o||I(g)}catch{o||z(nt)}finally{o||$(!1)}})(),()=>{o=!0}},[t,e.invocation_id,d,k]),i.useEffect(()=>{if(!t||!p||F.current)return;F.current=!0;const o={id:`user-brief-${Date.now()}`,author:B.user,text:Bt(p,e.invocation_name)};(async()=>{const g=await y.current.start(p);P([ce(y.current.openingMessage()),ce(o),ce(g.message)]),g.checklist&&H(g.checklist),O(g.phase??N.running)})()},[t,p,e.invocation_name]);const we=i.useCallback(o=>{M(At(o))},[]),xe=i.useCallback(o=>{M(null),A(o),V(g=>g+1)},[]),ge=i.useCallback(async()=>{await y.current.stop(),O(N.stopped)},[]),ue=he;return n.jsxs(u.Modal,{open:t,closeHandler:s,hideCloseButton:!0,className:"agent-workspace",children:[n.jsxs(u.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(u.Icon,{name:"ask-arbor",size:24})}),n.jsx(u.Modal.Title,{children:e.invocation_name}),n.jsx("span",{className:L("agent-workspace__phase",`agent-workspace__phase--${x}`),children:ot[x]})]}),n.jsxs("div",{className:"agent-workspace__header-actions",children:[n.jsx(u.Button,{variant:"tertiary",size:"S",iconLeftName:"clipboard-list",iconLeftScreenReaderText:"Toggle checklist","aria-pressed":!X,onClick:()=>fe(o=>!o),children:"Checklist"}),n.jsx(u.Button,{variant:"tertiary",size:"S",iconLeftName:"files",iconLeftScreenReaderText:"Toggle resources","aria-pressed":!Q,onClick:()=>_e(o=>!o),children:"Resources"}),n.jsx(u.Button,{variant:"secondary",size:"S",iconLeftName:"x",iconLeftScreenReaderText:"Close",onClick:s,children:"Close"})]})]}),n.jsxs(u.Modal.Body,{className:L("agent-workspace__body",{"agent-workspace__body--no-left":X,"agent-workspace__body--no-right":Q}),children:[!X&&n.jsx(vt,{checklist:ue,isLoading:me,error:W,phase:x,canRequestInput:x===N.running&&!de,onStop:()=>void ge(),onAttentionItemClick:we}),n.jsx(ft,{connector:y.current,phase:x,chatHistory:G,chatSessionKey:J,startQuery:q,clarificationMessage:C,enableUpload:f,onTurn:ve,onAwaitingChange:Y,onClarificationPrompt:xe,onDismissClarification:()=>M(null)}),!Q&&n.jsx(xt,{resources:K,isLoading:D,error:ae})]})]})},Ye=({open:e,onClose:t,onStart:s,agentDefinitions:a})=>{const r=a[0],[c,l]=i.useState(r),[d,w]=i.useState(""),[f,p]=i.useState(!1),[_,h]=i.useState(null),j=[...a].sort((x,O)=>x.agent_intent.localeCompare(O.agent_intent)).map(x=>({value:x.ref,label:x.agent_intent}));i.useEffect(()=>{e&&(l(r),w(""),p(!1),h(null))},[e,r]);const b=c!==void 0&&d.trim().length>0,k=i.useCallback(x=>{const O=a.find(G=>G.ref===x[0]);O&&l(O)},[a]),y=i.useCallback(async()=>{if(!(!c||!b||f)){p(!0),h(null);try{await s({definition:c,invocationName:d.trim()})}catch(x){h(x instanceof Error?x.message:"Unable to start the agent.")}finally{p(!1)}}},[b,c,d,f,s]);return!c||a.length===0?null:n.jsxs(u.Modal,{open:e,closeHandler:t,className:"new-agent",children:[n.jsx(u.Modal.Header,{className:"new-agent__header",children:n.jsxs("div",{className:"new-agent__header-title",children:[n.jsx("span",{className:"new-agent__header-avatar","aria-hidden":"true",children:n.jsx(u.Icon,{name:"ask-arbor",size:24})}),n.jsx(u.Modal.Title,{children:"Start an agent"})]})}),n.jsx(u.Modal.Body,{className:"new-agent__body",children:n.jsxs("form",{className:"new-agent__form","aria-label":"Start an agent",onSubmit:x=>{x.preventDefault(),b&&!f&&y()},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(u.SelectDropdown,{id:"new-agent-type",placeholder:"Choose an intent",options:j,selectedValues:[c.ref],onSelectionChange:k}),n.jsx("p",{className:"new-agent__type-description",children:c.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(u.TextInput,{id:"new-agent-invocation-name",value:d,placeholder:"e.g. Test with memory3",onChange:x=>w(x.target.value)})]}),_?n.jsx("p",{className:"new-agent__error",role:"alert",children:_}):null,n.jsx("div",{className:"new-agent__actions",children:n.jsx(u.Button,{type:"submit",variant:"primary",disabled:!b||f,iconLeftName:f?"loader":"sparkles",iconLeftScreenReaderText:f?"Starting":void 0,children:f?"Starting…":"Start"})})]})})]})},qt=e=>e!==void 0&&e.some(t=>t.status===S.hitl),Kt=(e,t)=>qt(t)?v.hitl:e.status,zt=({column:e,label:t})=>e.statusIcon?n.jsx("span",{className:"agent-view__status-indicator",children:n.jsx(u.Icon,{name:e.statusIcon.name,size:16,color:e.statusIcon.color,className:L({"agent-view__progress-icon--spinning":e.statusIcon.spin}),screenReaderText:t})}):n.jsx("span",{className:L("agent-view__dot",{[`agent-view__dot--${e.dotModifier}`]:e.dotModifier}),children:n.jsx(u.Dot,{colour:e.dotColour,label:t})}),Wt=({agent:e,agentName:t,column:s,isExpanded:a,isLoading:r,checklist:c,error:l,onToggle:d,onViewAgent:w})=>{const{id:f,invocation_name:p}=e,_=`agent-card-${f}-header`,h=`agent-card-${f}-progress`;return n.jsx("li",{className:L("agent-view__card",{"agent-view__card--expanded":a}),children:n.jsxs(u.Card,{spacing:"dense",children:[n.jsx("button",{type:"button",className:"agent-view__card-toggle","aria-expanded":a,"aria-controls":h,"aria-label":p,id:_,onClick:()=>d(f),children:n.jsxs("div",{className:"agent-view__card-content",children:[n.jsx(zt,{column:s}),n.jsx("span",{className:"agent-view__card-invocation-name",children:p}),n.jsx("span",{className:"agent-view__card-agent-name",children:t}),n.jsx(u.Icon,{name:a?"chevron-up":"chevron-down",size:16,className:"agent-view__card-chevron"})]})}),a&&n.jsxs("div",{id:h,"aria-labelledby":_,className:"agent-view__card-progress",children:[r&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:ee}),n.jsx("span",{children:ee})]}),!r&&l&&n.jsx("p",{className:"agent-view__progress-error",role:"alert",children:l}),!r&&!l&&c!==null&&n.jsx(ht,{checklist:c}),!r&&!l&&c===null&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:ee}),n.jsx("span",{children:ee})]}),n.jsx("div",{className:"agent-view__card-actions",children:n.jsx(u.Button,{variant:"secondary",size:"S",onClick:()=>w==null?void 0:w(e),children:"View agent"})})]})]})})},Ue=({column:e,agents:t,expandedAgentId:s,loadingAgentId:a,checklistByInvocationId:r,errorByAgentId:c,definitionNameByRef:l,onToggleAgent:d,onViewAgent:w,isSplit:f=!1})=>n.jsxs("section",{className:L("agent-view__column",{"agent-view__column--split":f}),"aria-label":e.title,children:[n.jsxs("div",{className:"agent-view__column-header",children:[n.jsx(u.Heading,{level:4,children:e.title}),n.jsx("span",{className:"agent-view__column-count",children:t.length})]}),n.jsx("ul",{className:"agent-view__card-list",children:t.map(p=>n.jsx(Wt,{agent:p,agentName:Se(p,l),column:e,isExpanded:s===p.id,isLoading:a===p.id,checklist:r[p.invocation_id]??null,error:c[p.id]??null,onToggle:d,onViewAgent:w},p.id))})]}),Se=(e,t)=>t.get(e.agent_definition_ref)??e.agent_definition_ref.replace(/_/g," "),Jt=({jwt:e,headers:t,agentDefinitionsUrl:s,agentsUrl:a,agentUrl:r,agentChecklistUrl:c,agentResourcesUrl:l,agentChatUrl:d,enableUpload:w,institutions:f})=>{var ue;const p=i.useMemo(()=>({agentDefinitions:s,agents:a,agent:r,agentChecklist:c,...l?{agentResources:l}:{},agentChat:d}),[s,a,r,c,l,d]),[_,h]=i.useState(null),j=_?(ue=f==null?void 0:f.find(o=>o.applicationId===_.application_id))==null?void 0:ue.applicationUrl:void 0,b=i.useMemo(()=>{const o={...t??{}};return j?o[ne.arborApplicationUrl]=j:delete o[ne.arborApplicationUrl],o},[t,j]),{agents:k,agentDefinitions:y,loadState:x,loadError:O,reload:G,fetchAgentChecklist:P,createAgent:J}=We({jwt:e,headers:b,urls:p}),[V,q]=i.useState(!1),[A,C]=i.useState(null),[M,K]=i.useState(null),[I,D]=i.useState({}),[$,ae]=i.useState({}),[z,he]=i.useState([]),[H,me]=i.useState([]),re=i.useMemo(()=>{const o=new Set(k.map(m=>m.application_id)),g=new Map((f??[]).map(m=>[m.applicationId,m.name]));return[...o].sort((m,R)=>(g.get(m)??m).localeCompare(g.get(R)??R)).map(m=>({value:m,label:g.get(m)??m}))},[k,f]),W=i.useMemo(()=>new Map(y.map(o=>[o.ref,o.display_name])),[y]),oe=i.useMemo(()=>[...new Set(k.map(g=>Se(g,W)))].sort((g,m)=>g.localeCompare(m)).map(g=>({value:g,label:g})),[k,W]),de=i.useMemo(()=>k.filter(o=>!(z.length>0&&!z.includes(o.application_id)||H.length>0&&!H.includes(Se(o,W)))),[k,W,H,z]),Y=re.length>1,Q=oe.length>1,_e=Y||Q;i.useEffect(()=>{if(k.length===0)return;let o=!1;return(async()=>{const g=await Promise.allSettled(k.map(async m=>{const R=await P(m.invocation_id);return{agentId:m.id,invocationId:m.invocation_id,checklist:R.checklist}}));o||(D(m=>{const R={...m};for(const ie of g)ie.status==="fulfilled"&&(R[ie.value.invocationId]=ie.value.checklist);return R}),ae(m=>{const R={...m};return g.forEach((ie,Qe)=>{ie.status==="rejected"&&(R[k[Qe].id]=Ae)}),R}))})(),()=>{o=!0}},[k,P]);const X=i.useCallback(async o=>{if(!I[o.invocation_id]){K(o.id),ae(g=>{const m={...g};return delete m[o.id],m});try{const g=await P(o.invocation_id);D(m=>({...m,[o.invocation_id]:g.checklist}))}catch{ae(g=>({...g,[o.id]:Ae}))}finally{K(g=>g===o.id?null:g)}}},[P,I]),fe=i.useCallback(o=>{if(A===o){C(null);return}const g=k.find(({id:m})=>m===o);g&&(C(o),X(g))},[k,A,X]),F=i.useMemo(()=>{const o={};for(const g of de){const m=Kt(g,I[g.invocation_id]);(o[m]??(o[m]=[])).push(g)}return o},[de,I]),ve=i.useCallback(o=>{h(o)},[]),we=i.useCallback(async o=>{const g=await J(o);h(g),q(!1)},[J]),xe=i.useCallback(()=>{h(null)},[]),ge={expandedAgentId:A,loadingAgentId:M,checklistByInvocationId:I,errorByAgentId:$,definitionNameByRef:W,onToggleAgent:fe,onViewAgent:ve};return n.jsxs("div",{className:"agent-view-frontend agent-view",children:[n.jsxs("div",{className:"agent-view__header",children:[n.jsx(u.Heading,{level:1,children:"Agents"}),n.jsx(u.Button,{variant:"primary",size:"S",iconLeftName:"sparkles",iconLeftScreenReaderText:"Start an agent",onClick:()=>q(!0),children:"Start an agent"})]}),k.length>0&&_e&&n.jsxs("div",{className:"agent-view__filters",children:[Y&&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(u.Combobox,{id:"agent-view-institution-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All institutions",options:re,value:z,onValueChange:he,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear institutions"})]}),Q&&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(u.Combobox,{id:"agent-view-agent-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All agents",options:oe,value:H,onValueChange:me,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear agents"})]})]}),x==="error"?n.jsxs("div",{className:"agent-view__state agent-view__state--error",role:"alert",children:[n.jsx(u.Icon,{name:"triangle-alert",size:24,color:"var(--color-semantic-destructive-600)"}),n.jsx("p",{className:"agent-view__state-message",children:O??$e}),n.jsx(u.Button,{variant:"secondary",size:"S",onClick:G,children:"Try again"})]}):x==="loading"&&k.length===0?n.jsxs("div",{className:"agent-view__state","aria-live":"polite",children:[n.jsx(u.Icon,{name:"loader",size:24,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:Ie}),n.jsx("p",{className:"agent-view__state-message",children:Ie})]}):k.length===0?n.jsx(gt,{}):n.jsxs("div",{className:"agent-view__board",children:[Xe.map(o=>n.jsx(Ue,{column:pe[o],agents:F[o]??[],...ge},o)),n.jsx("div",{className:"agent-view__split-column",children:Ze.map(o=>n.jsx(Ue,{column:pe[o],agents:F[o]??[],isSplit:!0,...ge},o))})]}),_&&n.jsx(Ve,{agent:_,open:!0,jwt:e,headers:b,agentUrl:r,agentChecklistUrl:c,agentResourcesUrl:l,agentChatUrl:d,enableUpload:w,initialChecklist:I[_.invocation_id]??null,onClose:xe},_.id),n.jsx(Ye,{open:V,onClose:()=>q(!1),onStart:we,agentDefinitions:y})]})},Vt=(e,t)=>{const s=Date.now(),a=t.trim()||e.agent_intent;return{id:`agent-${s}`,invocation_id:`inv-${s}`,agent_definition_ref:e.ref,agent_intent:e.agent_intent,invocation_name:a,application_id:et,created_by:tt,status:v["generating-a-response"],context_ref:null,checklist_ref:null}};exports.AgentMonitorKanban=Jt;exports.AgentServiceClient=Ne;exports.AgentServiceError=te;exports.AgentView=Ve;exports.HttpChatConnector=Be;exports.NewAgentModal=Ye;exports.buildAgentFromDefinition=Vt;exports.createHttpChatConnectorFactory=je;exports.mapApiAgent=ye;exports.mapApiAgentDefinition=Ke;exports.mapApiAgentStatus=Ge;exports.mapApiChecklistEndpointResponse=Ee;exports.mapApiChecklistItem=be;exports.mapApiChecklistResponse=Ut;exports.mapApiChecklistStatus=qe;exports.mapApiOpeningMessage=le;exports.mapApiResource=ze;exports.mapApiResourcesEndpointResponse=Ce;exports.mapApiTripOption=Ot;exports.useAgentService=We;exports.useAgentWorkspace=Je;
package/dist/index.d.ts CHANGED
@@ -69,7 +69,8 @@ export declare type AgentMonitorKanbanProps = {
69
69
  agentsUrl: string;
70
70
  agentUrl: string;
71
71
  agentChecklistUrl: string;
72
- agentResourcesUrl: string;
72
+ /** Optional — omit when the backend has no /resources route. */
73
+ agentResourcesUrl?: string;
73
74
  agentChatUrl: string;
74
75
  enableUpload?: boolean;
75
76
  institutions?: InstitutionConfig[];
@@ -166,7 +167,8 @@ export declare type AgentViewProps = {
166
167
  headers?: Record<string, string>;
167
168
  agentUrl: string;
168
169
  agentChecklistUrl: string;
169
- agentResourcesUrl: string;
170
+ /** Optional — omit when the backend has no /resources route. */
171
+ agentResourcesUrl?: string;
170
172
  agentChatUrl: string;
171
173
  /** When true, enables chat file uploads (posted to agentChatUrl). */
172
174
  enableUpload?: boolean;
@@ -178,7 +180,7 @@ export declare type AgentViewProps = {
178
180
  export declare type AgentWorkspaceUrls = {
179
181
  agentUrl: string;
180
182
  agentChecklistUrl: string;
181
- agentResourcesUrl: string;
183
+ agentResourcesUrl?: string;
182
184
  agentChatUrl: string;
183
185
  };
184
186
 
@@ -313,7 +315,7 @@ export declare const buildAgentFromDefinition: (definition: AgentDefinition, inv
313
315
  export declare interface ChatConnector {
314
316
  openingMessage(): ChatMessage;
315
317
  start(brief: AgentBrief): Promise<ChatTurn>;
316
- sendMessage(text: string): Promise<ChatTurn>;
318
+ sendMessage(text: string, uploadFiles?: File[]): Promise<ChatTurn>;
317
319
  stop(): Promise<void>;
318
320
  seedChecklist?(checklist: AgentChecklistItem[]): void;
319
321
  bootstrapConversation?(prompt?: string): Promise<ChatMessage[]>;
@@ -332,6 +334,8 @@ export declare type ChatMessageAuthor = 'agent' | 'user' | 'system';
332
334
  export declare type ChatOptions = {
333
335
  onEvent?: (event: ApiChatStreamEvent) => void;
334
336
  signal?: AbortSignal;
337
+ /** When set, the chat turn is posted as multipart/form-data with these files. */
338
+ uploadFiles?: File[];
335
339
  };
336
340
 
337
341
  export declare type ChatTurn = {
@@ -364,7 +368,7 @@ export declare class HttpChatConnector implements ChatConnector {
364
368
  openingMessage(): ChatMessage;
365
369
  bootstrapConversation(prompt?: string): Promise<ChatMessage[]>;
366
370
  start(brief: AgentBrief): Promise<ChatTurn>;
367
- sendMessage(text: string): Promise<ChatTurn>;
371
+ sendMessage(text: string, uploadFiles?: File[]): Promise<ChatTurn>;
368
372
  stop(): Promise<void>;
369
373
  seedChecklist(checklist: AgentChecklistItem[]): void;
370
374
  private exchange;