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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -128,7 +128,9 @@ const api = 'https://ai-agent-service.qa.arbor.engineering/api/v1';
128
128
  agentUrl={`${api}/agents/:invocationId`}
129
129
  agentChecklistUrl={`${api}/agents/:invocationId/checklist`}
130
130
  agentResourcesUrl={`${api}/agents/:invocationId/resources`}
131
+ agentTimelineUrl={`${api}/agents/:invocationId/agent-timeline`}
131
132
  agentChatUrl={`${api}/agents/:invocationId/chat`}
133
+ agentConversationUrl={`${api}/conversations/:invocationId`}
132
134
  />;
133
135
 
134
136
  // Or mount the workspace alone:
@@ -140,7 +142,9 @@ const api = 'https://ai-agent-service.qa.arbor.engineering/api/v1';
140
142
  agentUrl={`${api}/agents/:invocationId`}
141
143
  agentChecklistUrl={`${api}/agents/:invocationId/checklist`}
142
144
  agentResourcesUrl={`${api}/agents/:invocationId/resources`}
145
+ agentTimelineUrl={`${api}/agents/:invocationId/agent-timeline`}
143
146
  agentChatUrl={`${api}/agents/:invocationId/chat`}
147
+ agentConversationUrl={`${api}/conversations/:invocationId`}
144
148
  />;
145
149
  ```
146
150
 
@@ -173,7 +177,9 @@ function Page() {
173
177
  agentUrl={`${api}/agents/:invocationId`}
174
178
  agentChecklistUrl={`${api}/agents/:invocationId/checklist`}
175
179
  agentResourcesUrl={`${api}/agents/:invocationId/resources`}
180
+ agentTimelineUrl={`${api}/agents/:invocationId/agent-timeline`}
176
181
  agentChatUrl={`${api}/agents/:invocationId/chat`}
182
+ agentConversationUrl={`${api}/conversations/:invocationId`}
177
183
  />
178
184
  );
179
185
  }
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"),F=require("classnames"),g=require("@arbor-education/design-system.components"),oe=require("@arbor-education/ask-arbor-chat-panel"),y={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},E={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},T={briefing:"briefing",running:"running",stopped:"stopped",complete:"complete"},K={agent:"agent",user:"user",system:"system"},se={MIS_RECORD:"MIS_RECORD",FILE:"FILE",WORKFLOW:"WORKFLOW",LINK:"LINK"},We={cancelled:"cancelled",archived:"archived"},Le={in_progress:"in_progress",requires_attention:"requires_attention",available:"available"},B={[E.complete]:{label:"Complete",icon:"circle-check",color:"var(--color-semantic-success-600)"},[E.failed]:{label:"Failed",icon:"circle-x",color:"var(--color-semantic-destructive-600)"},[E.hitl]:{label:"Requires attention",icon:"triangle-alert",color:"var(--color-semantic-warning-600)"},[E["generating-a-response"]]:{label:"Generating a response",icon:"sparkles",color:"var(--color-brand-600)"}},Ee={[y["generating-a-response"]]:{status:y["generating-a-response"],title:"Active",dotColour:"green",statusIcon:{name:B["generating-a-response"].icon,color:B["generating-a-response"].color}},[y.hitl]:{status:y.hitl,title:"Requires attention",dotColour:"orange",statusIcon:{name:B.hitl.icon,color:B.hitl.color}},[y.complete]:{status:y.complete,title:"Complete",dotColour:"green",dotModifier:"grey-dark",statusIcon:{name:B.complete.icon,color:B.complete.color}},[y.failed]:{status:y.failed,title:"Failed",dotColour:"salmon",statusIcon:{name:B.failed.icon,color:B.failed.color}}},At=[y["generating-a-response"],y.hitl],Nt=[y.complete,y.failed],jt="m4",St="1",et="msg-opening",Te="Unable to load agent tasks. Please try again.",Ct="Unable to load the resources for this agent",tt="Unable to load the timeline for this agent",bt="Something went wrong. Please try again.",nt="Unable to load agents. Please try again.",ae="Loading tasks…",Je="Loading agents…",Tt="Task",Et={[T.briefing]:"Briefing",[T.running]:"Working",[T.stopped]:"Stopped",[T.complete]:"Complete"},It=[y["generating-a-response"],y.hitl,y.complete,y.failed],Rt={[y["generating-a-response"]]:"Agents currently working on tasks for you.",[y.hitl]:"Agents that need your input before they can continue.",[y.complete]:"Agents that have finished their work.",[y.failed]:"Agents that failed or were stopped."},Ot=()=>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)"})]}),Pt=({status:t})=>{const e=Ee[t];return e.statusIcon?n.jsx(g.Icon,{name:e.statusIcon.name,size:16,color:e.statusIcon.color,screenReaderText:e.title}):n.jsx(g.Dot,{colour:e.dotColour,label:e.title})},Mt=()=>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(g.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(t=>{const e=Ee[t];return n.jsxs("li",{className:"agent-view__empty-column",children:[n.jsx("span",{className:"agent-view__empty-column-indicator",children:n.jsx(Pt,{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:Rt[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(Ot,{})})]}),Lt=(t,e)=>({...t,...e.length>0?{children:e}:{}}),st=t=>{const e=[],s=[];for(const a of t){const r=a.children?st(a.children):{needsInput:[],tasks:[]};if(e.push(...r.needsInput),a.status===E.hitl){e.push({...a,children:void 0});continue}s.push(Lt(a,r.tasks))}return{needsInput:e,tasks:s}},Ut=t=>t.map((e,s)=>({item:e,index:s})).sort((e,s)=>{const a=e.item.status===E.hitl,r=s.item.status===E.hitl;return a!==r?a?-1:1:e.index-s.index}).map(({item:e})=>e),$t=({checklist:t})=>t.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:Ut(t).map(e=>{const s=B[e.status];return n.jsxs("li",{className:F("agent-view__progress-item",`agent-view__progress-item--${e.status.replace(/_/g,"-")}`),children:[n.jsx(g.Icon,{name:s.icon,size:16,color:s.color,screenReaderText:`${s.label}:`}),n.jsxs("div",{className:"agent-view__progress-item-content",children:[n.jsx("span",{className:"agent-view__progress-label",children:e.task}),e.status!==E.complete&&n.jsx("span",{className:"agent-view__progress-description",children:e.description})]})]},e.task)})}),Dt=({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 Ht{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:oe.CHAT_RESPONSE_TYPE_AGENT,...r.message.followUpPrompts?{followUpPrompts:r.message.followUpPrompts}:{}}}catch{return{id:`error-${Date.now()}`,text:bt,type:oe.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 Bt=({connector:t,phase:e,chatHistory:s,chatSessionKey:a,startQuery:r,clarificationMessage:c,enableUpload:o=!1,onTurn:l,onAwaitingChange:d,onClarificationPrompt:_,onDismissClarification:h})=>{const p=i.useMemo(()=>new Ht(t,{canSend:()=>e===T.running,onTurn:l,onAwaitingChange:d}),[t,e,l,d]),x=e!==T.running,k=e===T.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(Dt,{prompts:c.followUpPrompts,onSelect:_}),n.jsx("button",{type:"button",className:"agent-workspace__clarification-dismiss",onClick:h,children:"Dismiss"})]}),n.jsx("div",{className:"agent-workspace__ask-arbor",children:n.jsx(oe.ChatPanel,{connector:p,chatHistory:s,startQuery:r,lockConversation:x,enableUpload:o,speechEnabled:k,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:k?"Message the agent, paste a link, or attach a file…":"The agent is not accepting messages."},a)}),e===T.stopped&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(g.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===T.complete&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(g.Icon,{name:"party-popper",size:16,color:"var(--color-semantic-success-600)"}),n.jsx("span",{children:"The agent has finished."})]})]})},at=({item:t,depth:e,canRequestInput:s,onAttentionItemClick:a})=>{const r=B[t.status],c=t.status.replace(/_/g,"-"),o=t.status===E.hitl&&s&&a,l=n.jsxs("div",{className:"agent-workspace__task-row",children:[n.jsx(g.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!==E.complete&&t.description&&n.jsx("span",{className:"agent-workspace__task-description",children:t.description})]})]});return n.jsxs("li",{className:F("agent-workspace__task",`agent-workspace__task--${c}`,{"agent-workspace__task--child":e>0}),children:[o?n.jsx("button",{type:"button",className:"agent-workspace__task-button","aria-label":`Provide input for ${t.task}`,onClick:()=>a(t),children:l}):l,t.children&&t.children.length>0&&n.jsx("ul",{className:"agent-workspace__task-children",children:t.children.map(d=>n.jsx(at,{item:d,depth:e+1,canRequestInput:s,onAttentionItemClick:a},d.task))})]})},Ve=({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(at,{item:r,depth:0,canRequestInput:s,onAttentionItemClick:a},r.task))}),Ft=({checklist:t,isLoading:e,error:s,phase:a,canRequestInput:r,onStop:c,onAttentionItemClick:o})=>{const l=i.useMemo(()=>t?st(t):null,[t]);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(g.Heading,{level:4,children:"Checklist"}),a===T.running&&n.jsx(g.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:[e&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(g.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:ae}),n.jsx("span",{children:ae})]}),!e&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!e&&!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(Ve,{items:l.needsInput,ariaLabel:"Tasks needing your input",canRequestInput:r,onAttentionItemClick:o})]}),l.tasks.length>0&&n.jsxs("div",{className:F("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(Ve,{items:l.tasks,ariaLabel:"Agent tasks",canRequestInput:r,onAttentionItemClick:o})]})]}),!e&&!s&&(!l||l.needsInput.length===0&&l.tasks.length===0)&&n.jsx("p",{className:"agent-workspace__empty",children:a===T.briefing?"Tasks will appear here once the agent starts.":"No tasks to display."})]})]})},Gt={[se.MIS_RECORD]:{icon:"table",label:"Arbor MIS",color:"var(--color-brand-600)"},[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)"}},zt=({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(g.Heading,{level:4,children:"Resources"}),n.jsx("span",{className:"agent-workspace__panel-count",children:t.length})]}),n.jsxs("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:[e&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(g.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=Gt[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(g.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(g.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},qt=new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"2-digit"}),Ue=t=>{const e=new Date(t);return Number.isFinite(e.getTime())?qt.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(" ")),he=(t,e)=>e<=1?0:t/(e-1)*100,rt=t=>Math.max(t,0)+2,Kt=t=>t+1,Wt=(t,e)=>{if(e.length===0)return 50;const s=rt(e.length),a=he(1,s),r=he(e.length,s),c=e.map(h=>Ie(h.timestamp)),o=Math.min(...c),l=Math.max(...c);if(l<=o)return a;const d=(Ie(t.timestamp)-o)/(l-o),_=Math.min(1,Math.max(0,d));return a+_*(r-a)},Jt=8,Vt=20,Yt=(t,e=Jt,s=Vt)=>{const a=new Map;if(t.length===0)return a;const r=[...t].sort((o,l)=>o.leftPercent-l.leftPercent||o.timestampMs-l.timestampMs||o.id.localeCompare(l.id)),c=[];for(const o of r){const l=c[c.length-1];l&&o.leftPercent-l[l.length-1].leftPercent<e?l.push(o):c.push([o])}for(const o of c){const l=[...o].sort((_,h)=>_.timestampMs-h.timestampMs||_.id.localeCompare(h.id)),d=(l.length-1)/2;l.forEach((_,h)=>{a.set(_.id,(h-d)*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%)"}),Xt=t=>t.type!=="message-sent",Qt=({timeline:t,isLoading:e,error:s,onOpenChatSession:a})=>{const r=((t==null?void 0:t.actionLog)??[]).filter(Xt),c=(t==null?void 0:t.chatSessions)??[],o=!e&&!s&&r.length===0&&c.length===0,l=rt(r.length),d=r.map((p,x)=>({id:`action-${p.timestamp}-${x}`,leftPercent:he(Kt(x),l),timestampMs:Ie(p.timestamp)})),_=c.map(p=>({id:p.sessionId,leftPercent:Wt(p,r),timestampMs:Ie(p.timestamp)})),h=Yt([...d,..._]);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||tt}),o&&n.jsx("p",{className:"agent-workspace__timeline-status",role:"status",children:"No timeline activity yet."}),!e&&!s&&!o&&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(he(0,l)),children:[n.jsx("span",{className:"agent-timeline__station-node agent-timeline__station-node--terminus","aria-hidden":"true",children:n.jsx(g.Icon,{name:"arrow-right-from-line",size:16,color:"currentColor"})}),n.jsx("span",{className:"agent-timeline__terminus-label",children:"Start"})]}),r.map((p,x)=>{const k=`action-${p.timestamp}-${x}`,j=d[x].leftPercent,N=p.type==="checklist-updated",U=p.type==="status-transition",S=N?"checklist":U?"status":"note";return n.jsxs("div",{className:`agent-timeline__station agent-timeline__station--${S}`,style:be(j,h.get(k)??0),children:[n.jsxs("button",{type:"button",className:`agent-timeline__station-node agent-timeline__station-node--${S}`,"aria-label":`${Ce(p.type)}: ${Ce(p.entry)}`,children:[N&&n.jsx(g.Icon,{name:"check-solid",size:16,color:"currentColor"}),U&&n.jsx(g.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(p.type)}),n.jsx("span",{className:"agent-timeline__pill-entry",children:Ce(p.entry)}),n.jsx("span",{className:"agent-timeline__pill-entry",children:Ue(p.timestamp)})]})]},k)}),n.jsxs("div",{className:"agent-timeline__station agent-timeline__station--terminus",style:be(he(l-1,l)),children:[n.jsx("span",{className:"agent-timeline__station-node agent-timeline__station-node--terminus","aria-hidden":"true",children:n.jsx(g.Icon,{name:"flag",size:16,color:"currentColor"})}),n.jsx("span",{className:"agent-timeline__terminus-label",children:"Finish"})]}),c.map((p,x)=>{const k=_[x].leftPercent;return n.jsxs("div",{className:"agent-timeline__chat-station",style:be(k,h.get(p.sessionId)??0),children:[n.jsx("button",{type:"button",className:"agent-timeline__chat-node","aria-label":`Open chat session from ${Ue(p.timestamp)}`,onClick:()=>a(p.sessionId),children:n.jsx(g.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:Ue(p.timestamp)})]})]},p.sessionId)})]})]})},Zt=["I'll get the details and come back to you","Skip this for now"],en=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:K.agent,text:e,followUpPrompts:t.clarificationPrompts??Zt}},pe=t=>({id:t.id,text:t.text,type:t.author===K.user?oe.CHAT_RESPONSE_TYPE_USER:t.author===K.system?oe.CHAT_RESPONSE_TYPE_INFO:oe.CHAT_RESPONSE_TYPE_AGENT,...t.followUpPrompts?{followUpPrompts:t.followUpPrompts}:{}});class re extends Error{constructor(e,s,a){super(a??`Agent service request failed (${e})`),this.name="AgentServiceError",this.status=e,this.detail=s}}const tn="/api/v1",M={agentDefinitions:"/agent-definitions",agents:"/agents",conversations:"/conversations",tripOptions:"/trip-options",demoDataset:"/demo/dataset"},L={GET:"GET",POST:"POST"},nn={error:"error"},sn={user:"user"},ie={acceptJson:"application/json",acceptEventStream:"text/event-stream",contentTypeJson:"application/json",arborApplicationUrl:"X-Arbor-Application-Url"},an=/:invocationId\b/g,rn=t=>t.trim().replace(/^Bearer\s+/i,""),on=t=>t.endsWith("/")?t.slice(0,-1):t;class Be{constructor(e){var a;this.baseUrl=on(e.baseUrl??"");const s=(a=e.token)==null?void 0:a.trim();this.token=s?rn(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(L.GET,this.resolveUrl("agentDefinitions",M.agentDefinitions))).agent_definitions??[]}getAgentDefinition(e){return this.request(L.GET,this.apiUrl(`${M.agentDefinitions}/${encodeURIComponent(e)}`))}listTripOptions(){return this.request(L.GET,this.apiUrl(M.tripOptions))}getDataset(){return this.request(L.GET,this.apiUrl(M.demoDataset))}setDataset(e){return this.request(L.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(L.GET,`${this.resolveUrl("agents",M.agents)}${a}`)}createAgent(e,s={}){var o,l;const a={agent_definition_ref:e},r=(o=s.invocationName)==null?void 0:o.trim(),c=(l=s.agentIntent)==null?void 0:l.trim();return r&&(a.invocation_name=r),c&&(a.agent_intent=c),this.request(L.POST,this.resolveUrl("agents",M.agents),a)}getAgent(e){return this.request(L.GET,this.resolveUrl("agent",`${M.agents}/${encodeURIComponent(e)}`,e))}getAgentChecklist(e){return this.request(L.GET,this.resolveUrl("agentChecklist",`${M.agents}/${encodeURIComponent(e)}/checklist`,e))}getAgentResources(e){return this.request(L.GET,this.resolveUrl("agentResources",`${M.agents}/${encodeURIComponent(e)}/resources`,e))}getAgentTimeline(e){return this.request(L.GET,this.resolveUrl("agentTimeline",`${M.agents}/${encodeURIComponent(e)}/agent-timeline`,e))}getAgentContext(e){return this.request(L.GET,this.apiUrl(`${M.agents}/${encodeURIComponent(e)}/context`))}cancelAgent(e){return this.request(L.POST,this.apiUrl(`${M.agents}/${encodeURIComponent(e)}/cancel`))}archiveAgent(e){return this.request(L.POST,this.apiUrl(`${M.agents}/${encodeURIComponent(e)}/archive`))}getConversation(e){return this.request(L.GET,this.resolveUrl("agentConversation",`${M.conversations}/${encodeURIComponent(e)}`,e))}async chat(e,s,a={}){const r=!!(a.uploadFiles&&a.uploadFiles.length>0),c=await this.fetchImpl(this.resolveUrl("agentChat",`${M.agents}/${encodeURIComponent(e)}/chat`,e),{method:L.POST,headers:{...this.customHeaders,...this.authHeaders(),Accept:ie.acceptEventStream,...r?{}:{"Content-Type":ie.contentTypeJson}},body:r?ln(s,a.uploadFiles??[]):JSON.stringify(s),signal:a.signal});if(!c.ok)throw await this.toError(c);if(!c.body)throw new re(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}${tn}${e}`}resolveUrl(e,s,a){const r=this.urls[e];return r?a?r.replace(an,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:ie.acceptJson,...a===void 0?{}:{"Content-Type":ie.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 re(e.status,s,`Agent service request failed (${e.status} ${e.statusText})`)}async consumeSse(e,s){const a=e.getReader(),r=new TextDecoder;let c="",o;const l=d=>{const{event:_,data:h}=cn(d);if(h===null)return;if(_===nn.error){const x=Ye(h);throw new re(502,x,(x==null?void 0:x.message)??"Chat stream error")}const p=Ye(h);p&&(o=p,s==null||s(p))};for(;;){const{done:d,value:_}=await a.read();if(d)break;c+=r.decode(_,{stream:!0});const h=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(`
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;
3
+ `);c=h.pop()??"";for(const p of h)l(p)}if(c.trim()&&l(c),!o)throw new re(502,null,"Chat stream ended without any events");return o}}const cn=t=>{let e=null;const s=[];for(const a of t.split(`
4
+ `)){const r=a.trimEnd();r.startsWith("event:")?e=r.slice(6).trim():r.startsWith("data:")&&s.push(r.slice(5).trim())}return{event:e,data:s.length>0?s.join(`
5
+ `):null}},Ye=t=>{try{return JSON.parse(t)}catch{return}};function ln(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 it=t=>{switch(t){case We.cancelled:return y.failed;case We.archived:return y.complete;case y.hitl:case y.complete:case y.failed:case y["generating-a-response"]:return t;default:return y["generating-a-response"]}},ot=t=>{switch(t){case Le.requires_attention:return E.hitl;case Le.in_progress:case Le.available:return E["generating-a-response"];case E.failed:case E.complete:case E.hitl:case E["generating-a-response"]:return t;default:return E["generating-a-response"]}},ct=t=>({ref:t.name,display_name:t.display_name,agent_intent:t.agent_intent??t.display_name,description:t.description}),dn=t=>({id:t.id,name:t.name,...t.has_run_before?{hasRunBefore:t.has_run_before}:{}}),gn=new Set(Object.values(se)),un=t=>t&&gn.has(t)?t:se.LINK,lt=t=>({uri:t.uri??"",type:un(t.type),name:t.name??"",description:t.description??""}),Fe=t=>(Array.isArray(t)?t:t.resources??[]).map(lt),dt=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}))}),De=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:it(t.status),context_ref:t.context_ref??null,checklist_ref:t.checklist_ref??null}},Ge=t=>{var e;return{task:t.task??t.name??t.label??Tt,status:ot(t.status),description:t.description??"",...t.prompt?{prompt:t.prompt}:{},...(e=t.follow_up_prompts)!=null&&e.length?{clarificationPrompts:t.follow_up_prompts}:{}}},pn=t=>Array.isArray(t)?t:t.checklist_items??t.checklist??t.items??[],ze=(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?me(a):void 0;return{invocation_id:t,checklist:pn(e).map(Ge),...r?{openingMessage:r}:{}}},gt=(t,e)=>{const s=me(e);return{invocation_id:e.invocation_id??t,checklist:(e.checklist_items??[]).map(Ge),...s?{openingMessage:s}:{}}},me=t=>{var s,a;const e=(s=t.opening_message)==null?void 0:s.trim();if(e)return{id:et,author:K.agent,text:e,...(a=t.opening_follow_up_prompts)!=null&&a.length?{followUpPrompts:t.opening_follow_up_prompts}:{}}},ut=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"?K.user:K.agent,text:e.content})),hn={id:et,author:K.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 Xe=0;const mn=t=>(Xe+=1,`${t}-${Date.now()}-${Xe}`),_n=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 pt{constructor(e,s,a={}){this.seededChecklist=[],this.client=e,this.agentId=s,this.chatId=a.chatId??s,this.opening=a.openingMessage??hn,this.model=a.model}openingMessage(){return this.opening}async bootstrapConversation(){const e=await this.client.getConversation(this.chatId),s=ut(e.messages);return s.length===0?[this.opening]:s}async start(e){return{...await this.exchange(_n(e)),phase:T.running}}sendMessage(e,s){return this.exchange(e,s)}async stop(){}seedChecklist(e){this.seededChecklist=e}async exchange(e,s){var o;const a=[{role:sn.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||mn("msg-agent"),author:K.agent,text:r.message.content,...(o=r.follow_up_prompts)!=null&&o.length?{followUpPrompts:r.follow_up_prompts}:{}};try{const l=await this.client.getAgent(this.agentId),{checklist:d}=gt(this.agentId,l);return this.seededChecklist=d,{message:c,checklist:d}}catch{return{message:c,...this.seededChecklist.length?{checklist:this.seededChecklist}:{}}}}}const qe=(t,e)=>s=>{var a,r;return new pt(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)})},fn=t=>t instanceof re?t.message:t instanceof TypeError?"Network error while contacting the agent service.":t instanceof Error&&t.message?t.message:nt,vn=t=>{const e={};for(const s of t){const a=me(s);if(!a)continue;const r=s.invocation_id??s.id;e[r]=a,e[s.id]=a}return e},xn=t=>JSON.stringify(t),$e=(t,e)=>JSON.stringify(t)===JSON.stringify(e),ht=t=>{const{jwt:e,headers:s,urls:a}=t,r=JSON.stringify(s??{}),c=xn(a),o=i.useMemo(()=>new Be({token:e,headers:s,urls:a}),[e,c]);i.useLayoutEffect(()=>{o.setHeaders(s)},[o,r]);const[l,d]=i.useState([]),[_,h]=i.useState([]),[p,x]=i.useState({}),[k,j]=i.useState("loading"),[N,U]=i.useState(null),[S,A]=i.useState(0),O=i.useCallback((w,C)=>{const P=w.map(De),H=C.map(ct),I=vn(w);d(R=>$e(R,P)?R:P),h(R=>$e(R,H)?R:H),x(R=>$e(R,I)?R:I),j("idle"),U(null)},[]);i.useEffect(()=>{let w=!1;return j("loading"),U(null),(async()=>{try{const[C,P]=await Promise.all([o.listAgents(),o.listAgentDefinitions()]);if(w)return;O(C,P)}catch(C){if(w)return;d([]),h([]),x({}),j("error"),U(fn(C))}})(),()=>{w=!0}},[O,o,S]);const ee=i.useCallback(()=>{A(w=>w+1)},[]),V=i.useCallback(async()=>{try{const[w,C]=await Promise.all([o.listAgents(),o.listAgentDefinitions()]);O(w,C)}catch{}},[O,o]),W=i.useCallback(async w=>{const[C,P]=await Promise.all([o.getAgentChecklist(w),o.getAgent(w).catch(()=>null)]);return ze(w,C,P??void 0)},[o]),Y=i.useCallback(async w=>{const C=await o.getAgentResources(w);return Fe(C)},[o]),G=i.useCallback(async({definition:w,invocationName:C})=>{const P=await o.createAgent(w.ref,{invocationName:C}),H=await o.getAgent(P.id),I=De(H),R=me(H);return d($=>[I,...$]),R&&x($=>({...$,[I.invocation_id]:R,[I.id]:R})),I},[o]),X=i.useMemo(()=>qe(o,{resolveOpeningMessage:w=>p[w.invocation_id]??p[w.id]}),[o,p]);return{agents:l,agentDefinitions:_,loadState:k,loadError:N,reload:ee,refresh:V,fetchAgentChecklist:W,fetchAgentResources:Y,createAgent:G,chatConnector:X}},wn=t=>JSON.stringify(t),mt=t=>{const{agent:e,jwt:s,headers:a,urls:r,chatId:c}=t,o=JSON.stringify(a??{}),l=wn(r),d=i.useMemo(()=>new Be({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,l]);i.useLayoutEffect(()=>{d.setHeaders(a)},[d,o]);const _=i.useCallback(async k=>{const[j,N]=await Promise.all([d.getAgentChecklist(k),d.getAgent(k).catch(()=>null)]);return ze(k,j,N??void 0)},[d]),h=i.useCallback(async k=>{const j=await d.getAgentResources(k);return Fe(j)},[d]),p=i.useCallback(async k=>{const j=await d.getAgentTimeline(k);return dt(j)},[d]);return{connector:i.useMemo(()=>qe(d,{chatId:c??e.invocation_id})(e),[d,e.invocation_id,c]),fetchAgentChecklist:_,fetchAgentResources:h,fetchAgentTimeline:p}},kn=(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()},yn=t=>{switch(t){case y.failed:return T.stopped;case y.complete:return T.complete;default:return T.running}},Qe=(t,e)=>{e([pe(t)])},_t=({agent:t,open:e,onClose:s,jwt:a,headers:r,agentUrl:c,agentChecklistUrl:o,agentResourcesUrl:l,agentTimelineUrl:d,agentChatUrl:_,agentConversationUrl:h,chatId:p,enableUpload:x,initialBrief:k,initialPhase:j,initialChecklist:N})=>{const[U,S]=i.useState(p??t.invocation_id),[A,O]=i.useState("chat"),[ee,V]=i.useState(!1),{connector:W,fetchAgentChecklist:Y,fetchAgentResources:G,fetchAgentTimeline:X}=mt({agent:t,jwt:a,headers:r,chatId:U,urls:{agentUrl:c,agentChecklistUrl:o,agentResourcesUrl:l,agentTimelineUrl:d,agentChatUrl:_,agentConversationUrl:h}}),w=i.useRef(W),[C,P]=i.useState(j??(k?T.running:yn(t.status))),[H,I]=i.useState([]),[R,$]=i.useState(0),[_e,Re]=i.useState(),[ce,J]=i.useState(null),[Oe,te]=i.useState([]),[Pe,le]=i.useState(!1),[Q,de]=i.useState(null),[fe,ve]=i.useState(null),[xe,we]=i.useState(!1),[ke,ye]=i.useState(null),[Ae,ge]=i.useState(N??null),[Me,Ne]=i.useState(!1),[je,ue]=i.useState(null),[u,v]=i.useState(!1),[f,D]=i.useState(!1),[z,ne]=i.useState(!1);i.useEffect(()=>{w.current=W},[W]),i.useEffect(()=>{S(p??t.invocation_id),O("chat"),V(!1),I([]),$(m=>m+1)},[t.invocation_id,p]),i.useEffect(()=>{if(!e||k)return;const m=w.current.bootstrapConversation;if(!m){Qe(w.current.openingMessage(),I);return}let b=!1;return v(!0),(async()=>{try{const q=await m.call(w.current);if(b)return;I(q.map(pe))}catch{b||Qe(w.current.openingMessage(),I)}finally{b||v(!1)}})(),()=>{b=!0}},[e,k,t.invocation_id,U]);const Z=i.useCallback(m=>{m.checklist&&ge(m.checklist),m.phase&&P(m.phase)},[]);i.useEffect(()=>{var m,b;!e||k||N&&N.length>0&&((b=(m=w.current).seedChecklist)==null||b.call(m,N))},[e,k,N]),i.useEffect(()=>{if(!e||k)return;let m=!1;return Ne(!(N!=null&&N.length)),ue(null),(async()=>{var b,q;try{const Ke=await Y(t.invocation_id);if(m)return;N!=null&&N.length||(ge(Ke.checklist),(q=(b=w.current).seedChecklist)==null||q.call(b,Ke.checklist))}catch{!m&&!(N!=null&&N.length)&&ue(Te)}finally{m||Ne(!1)}})(),()=>{m=!0}},[e,t.invocation_id,k,N,Y]),i.useEffect(()=>{if(!e||!l)return;let m=!1;return le(!0),de(null),(async()=>{try{const b=await G(t.invocation_id);m||te(b)}catch{m||de(Ct)}finally{m||le(!1)}})(),()=>{m=!0}},[e,t.invocation_id,l,G]),i.useEffect(()=>{if(!e||!d)return;let m=!1;return we(!0),ye(null),(async()=>{try{const b=await X(t.invocation_id);m||ve(b)}catch{m||ye(tt)}finally{m||we(!1)}})(),()=>{m=!0}},[e,t.invocation_id,d,X]),i.useEffect(()=>{if(!e||!k)return;let m=!1;const b={id:`user-brief-${Date.now()}`,author:K.user,text:kn(k,t.invocation_name)};return(async()=>{const q=await w.current.start(k);m||(I([pe(w.current.openingMessage()),pe(b),pe(q.message)]),q.checklist&&ge(q.checklist),P(q.phase??T.running))})(),()=>{m=!0}},[e,k,t.invocation_name,t.invocation_id]);const Se=i.useCallback(m=>{J(en(m))},[]),vt=i.useCallback(m=>{S(m),V(!0),O("chat"),I([]),$(b=>b+1)},[]),xt=i.useCallback(()=>{O("timeline"),V(!1),S(p??t.invocation_id),I([]),$(m=>m+1)},[t.invocation_id,p]),wt=i.useCallback(m=>{J(null),Re(m),$(b=>b+1)},[]),kt=i.useCallback(async()=>{await w.current.stop(),P(T.stopped)},[]),yt=Ae;return n.jsxs(g.Modal,{open:e,closeHandler:s,hideCloseButton:!0,className:"agent-workspace",children:[n.jsxs(g.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(g.Icon,{name:"ask-arbor",size:24})}),n.jsx(g.Modal.Title,{children:t.invocation_name}),n.jsx("span",{className:F("agent-workspace__phase",`agent-workspace__phase--${C}`),children:Et[C]})]}),n.jsxs("div",{className:"agent-workspace__header-actions",children:[n.jsx(g.Button,{variant:"tertiary",size:"S",iconLeftName:"clipboard-list",iconLeftScreenReaderText:"Toggle checklist","aria-pressed":!z,onClick:()=>ne(m=>!m),children:"Checklist"}),n.jsx(g.Button,{variant:"tertiary",size:"S",iconLeftName:"files",iconLeftScreenReaderText:"Toggle resources","aria-pressed":!f,onClick:()=>D(m=>!m),children:"Resources"}),n.jsx(g.Button,{variant:"secondary",size:"S",iconLeftName:"x",iconLeftScreenReaderText:"Close",onClick:s,children:"Close"})]})]}),n.jsxs(g.Modal.Body,{className:F("agent-workspace__body",{"agent-workspace__body--no-left":z,"agent-workspace__body--no-right":f}),children:[!z&&n.jsx(Ft,{checklist:yt,isLoading:Me,error:je,phase:C,canRequestInput:C===T.running&&!u,onStop:()=>void kt(),onAttentionItemClick:Se}),n.jsxs("section",{className:F("agent-workspace__panel","agent-workspace__panel--chat",{"agent-workspace__panel--timeline":!!d&&A==="timeline"}),"aria-label":"Agent conversation",children:[d&&n.jsxs(g.Tabs,{className:"agent-workspace__center-tabs","aria-label":"Center panel",children:[n.jsx(g.Tabs.Item,{active:A==="chat",tabElementProps:{id:"agent-center-tab-chat",onClick:()=>O("chat")},children:"Chat"}),n.jsx(g.Tabs.Item,{active:A==="timeline",tabElementProps:{id:"agent-center-tab-timeline",onClick:()=>O("timeline")},children:"Timeline"})]}),d&&A==="chat"&&ee&&n.jsx("div",{className:"agent-workspace__center-back",children:n.jsx(g.Button,{variant:"tertiary",size:"S",iconLeftName:"arrow-left",iconLeftScreenReaderText:"Back to timeline",onClick:xt,children:"Back to timeline"})}),!d||A==="chat"?n.jsx(Bt,{connector:W,phase:C,chatHistory:H,chatSessionKey:R,startQuery:_e,clarificationMessage:ce,enableUpload:x,onTurn:Z,onAwaitingChange:v,onClarificationPrompt:wt,onDismissClarification:()=>J(null)}):n.jsx(Qt,{timeline:fe,isLoading:xe,error:ke,onOpenChatSession:vt})]}),!f&&n.jsx(zt,{resources:Oe,isLoading:Pe,error:Q})]})]})},ft=({open:t,onClose:e,onStart:s,agentDefinitions:a})=>{const r=a[0],[c,o]=i.useState(r),[l,d]=i.useState(""),[_,h]=i.useState(!1),[p,x]=i.useState(null),k=[...a].sort((S,A)=>S.agent_intent.localeCompare(A.agent_intent)).map(S=>({value:S.ref,label:S.agent_intent}));i.useEffect(()=>{t&&(o(r),d(""),h(!1),x(null))},[t,r]);const j=c!==void 0&&l.trim().length>0,N=i.useCallback(S=>{const A=a.find(O=>O.ref===S[0]);A&&o(A)},[a]),U=i.useCallback(async()=>{if(!(!c||!j||_)){h(!0),x(null);try{await s({definition:c,invocationName:l.trim()})}catch(S){x(S instanceof Error?S.message:"Unable to start the agent.")}finally{h(!1)}}},[j,c,l,_,s]);return!c||a.length===0?null:n.jsxs(g.Modal,{open:t,closeHandler:e,className:"new-agent",children:[n.jsx(g.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(g.Icon,{name:"ask-arbor",size:24})}),n.jsx(g.Modal.Title,{children:"Start an agent"})]})}),n.jsx(g.Modal.Body,{className:"new-agent__body",children:n.jsxs("form",{className:"new-agent__form","aria-label":"Start an agent",onSubmit:S=>{S.preventDefault(),j&&!_&&U()},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(g.SelectDropdown,{id:"new-agent-type",placeholder:"Choose an intent",options:k,selectedValues:[c.ref],onSelectionChange:N}),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(g.TextInput,{id:"new-agent-invocation-name",value:l,placeholder:"e.g. Test with memory3",onChange:S=>d(S.target.value)})]}),p?n.jsx("p",{className:"new-agent__error",role:"alert",children:p}):null,n.jsx("div",{className:"new-agent__actions",children:n.jsx(g.Button,{type:"submit",variant:"primary",disabled:!j||_,iconLeftName:_?"loader":"sparkles",iconLeftScreenReaderText:_?"Starting":void 0,children:_?"Starting…":"Start"})})]})})]})},An=t=>t!==void 0&&t.some(e=>e.status===E.hitl),Nn=(t,e)=>An(e)?y.hitl:t.status,jn=({column:t,label:e})=>t.statusIcon?n.jsx("span",{className:"agent-view__status-indicator",children:n.jsx(g.Icon,{name:t.statusIcon.name,size:16,color:t.statusIcon.color,className:F({"agent-view__progress-icon--spinning":t.statusIcon.spin}),screenReaderText:e})}):n.jsx("span",{className:F("agent-view__dot",{[`agent-view__dot--${t.dotModifier}`]:t.dotModifier}),children:n.jsx(g.Dot,{colour:t.dotColour,label:e})}),Sn=({agent:t,agentName:e,column:s,isExpanded:a,isLoading:r,checklist:c,error:o,onToggle:l,onViewAgent:d})=>{const{id:_,invocation_name:h}=t,p=`agent-card-${_}-header`,x=`agent-card-${_}-progress`;return n.jsx("li",{className:F("agent-view__card",{"agent-view__card--expanded":a}),children:n.jsxs(g.Card,{spacing:"dense",children:[n.jsx("button",{type:"button",className:"agent-view__card-toggle","aria-expanded":a,"aria-controls":x,"aria-label":h,id:p,onClick:()=>l(_),children:n.jsxs("div",{className:"agent-view__card-content",children:[n.jsx(jn,{column:s}),n.jsx("span",{className:"agent-view__card-invocation-name",children:h}),n.jsx("span",{className:"agent-view__card-agent-name",children:e}),n.jsx(g.Icon,{name:a?"chevron-up":"chevron-down",size:16,className:"agent-view__card-chevron"})]})}),a&&n.jsxs("div",{id:x,"aria-labelledby":p,className:"agent-view__card-progress",children:[r&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(g.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:ae}),n.jsx("span",{children:ae})]}),!r&&o&&n.jsx("p",{className:"agent-view__progress-error",role:"alert",children:o}),!r&&!o&&c!==null&&n.jsx($t,{checklist:c}),!r&&!o&&c===null&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(g.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:ae}),n.jsx("span",{children:ae})]}),n.jsx("div",{className:"agent-view__card-actions",children:n.jsx(g.Button,{variant:"secondary",size:"S",onClick:()=>d==null?void 0:d(t),children:"View agent"})})]})]})})},Ze=({column:t,agents:e,expandedAgentId:s,loadingAgentId:a,checklistByInvocationId:r,errorByAgentId:c,definitionNameByRef:o,onToggleAgent:l,onViewAgent:d,isSplit:_=!1})=>n.jsxs("section",{className:F("agent-view__column",{"agent-view__column--split":_}),"aria-label":t.title,children:[n.jsxs("div",{className:"agent-view__column-header",children:[n.jsx(g.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(h=>n.jsx(Sn,{agent:h,agentName:He(h,o),column:t,isExpanded:s===h.id,isLoading:a===h.id,checklist:r[h.invocation_id]??null,error:c[h.id]??null,onToggle:l,onViewAgent:d},h.id))})]}),He=(t,e)=>e.get(t.agent_definition_ref)??t.agent_definition_ref.replace(/_/g," "),Cn=({jwt:t,headers:e,agentDefinitionsUrl:s,agentsUrl:a,agentUrl:r,agentChecklistUrl:c,agentResourcesUrl:o,agentTimelineUrl:l,agentChatUrl:d,agentConversationUrl:_,enableUpload:h,showHeader:p=!1,institutions:x})=>{var ue;const k=i.useMemo(()=>({agentDefinitions:s,agents:a,agent:r,agentChecklist:c,...o?{agentResources:o}:{},...l?{agentTimeline:l}:{},agentChat:d,agentConversation:_}),[s,a,r,c,o,l,d,_]),[j,N]=i.useState(null),U=j?(ue=x==null?void 0:x.find(u=>u.applicationId===j.application_id))==null?void 0:ue.applicationUrl:void 0,S=i.useMemo(()=>{const u={...e??{}};return U?u[ie.arborApplicationUrl]=U:delete u[ie.arborApplicationUrl],u},[e,U]),{agents:A,agentDefinitions:O,loadState:ee,loadError:V,reload:W,refresh:Y,fetchAgentChecklist:G,createAgent:X}=ht({jwt:t,headers:S,urls:k}),[w,C]=i.useState(!1),[P,H]=i.useState(null),[I,R]=i.useState(null),[$,_e]=i.useState({}),[Re,ce]=i.useState({}),[J,Oe]=i.useState([]),[te,Pe]=i.useState([]),le=i.useMemo(()=>{const u=new Set(A.map(f=>f.application_id)),v=new Map((x??[]).map(f=>[f.applicationId,f.name]));return[...u].sort((f,D)=>(v.get(f)??f).localeCompare(v.get(D)??D)).map(f=>({value:f,label:v.get(f)??f}))},[A,x]),Q=i.useMemo(()=>new Map(O.map(u=>[u.ref,u.display_name])),[O]),de=i.useMemo(()=>[...new Set(A.map(v=>He(v,Q)))].sort((v,f)=>v.localeCompare(f)).map(v=>({value:v,label:v})),[A,Q]),fe=i.useMemo(()=>A.filter(u=>!(J.length>0&&!J.includes(u.application_id)||te.length>0&&!te.includes(He(u,Q)))),[A,Q,te,J]),ve=le.length>1,xe=de.length>1,we=ve||xe;i.useEffect(()=>{const u=window.setInterval(()=>{Y()},6e4);return()=>{window.clearInterval(u)}},[Y]),i.useEffect(()=>{if(A.length===0)return;let u=!1;return(async()=>{const v=await Promise.allSettled(A.map(async f=>{const D=await G(f.invocation_id);return{agentId:f.id,invocationId:f.invocation_id,checklist:D.checklist}}));u||(_e(f=>{const D={...f};let z=!1;for(const ne of v){if(ne.status!=="fulfilled")continue;const{invocationId:Z,checklist:Se}=ne.value;JSON.stringify(f[Z])!==JSON.stringify(Se)&&(D[Z]=Se,z=!0)}return z?D:f}),ce(f=>{const D={...f};let z=!1;return v.forEach((ne,Z)=>{ne.status==="rejected"&&D[A[Z].id]!==Te&&(D[A[Z].id]=Te,z=!0)}),z?D:f}))})(),()=>{u=!0}},[A,G]);const ke=i.useCallback(async u=>{if(!$[u.invocation_id]){R(u.id),ce(v=>{const f={...v};return delete f[u.id],f});try{const v=await G(u.invocation_id);_e(f=>({...f,[u.invocation_id]:v.checklist}))}catch{ce(v=>({...v,[u.id]:Te}))}finally{R(v=>v===u.id?null:v)}}},[G,$]),ye=i.useCallback(u=>{if(P===u){H(null);return}const v=A.find(({id:f})=>f===u);v&&(H(u),ke(v))},[A,P,ke]),Ae=i.useMemo(()=>{const u={};for(const v of fe){const f=Nn(v,$[v.invocation_id]);(u[f]??(u[f]=[])).push(v)}return u},[fe,$]),ge=i.useCallback(u=>{N(u)},[]),Me=i.useCallback(async u=>{const v=await X(u);N(v),C(!1)},[X]),Ne=i.useCallback(()=>{N(null)},[]),je={expandedAgentId:P,loadingAgentId:I,checklistByInvocationId:$,errorByAgentId:Re,definitionNameByRef:Q,onToggleAgent:ye,onViewAgent:ge};return n.jsxs("div",{className:"agent-view-frontend agent-view",children:[p&&n.jsxs("div",{className:"agent-view__header",children:[n.jsx(g.Heading,{level:1,children:"Agents"}),n.jsx(g.Button,{variant:"primary",size:"S",iconLeftName:"sparkles",iconLeftScreenReaderText:"Start an agent",onClick:()=>C(!0),children:"Start an agent"})]}),A.length>0&&we&&n.jsxs("div",{className:"agent-view__filters",children:[ve&&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(g.Combobox,{id:"agent-view-institution-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All institutions",options:le,value:J,onValueChange:Oe,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear institutions"})]}),xe&&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(g.Combobox,{id:"agent-view-agent-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All agents",options:de,value:te,onValueChange:Pe,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear agents"})]})]}),ee==="error"?n.jsxs("div",{className:"agent-view__state agent-view__state--error",role:"alert",children:[n.jsx(g.Icon,{name:"triangle-alert",size:24,color:"var(--color-semantic-destructive-600)"}),n.jsx("p",{className:"agent-view__state-message",children:V??nt}),n.jsx(g.Button,{variant:"secondary",size:"S",onClick:W,children:"Try again"})]}):ee==="loading"&&A.length===0?n.jsxs("div",{className:"agent-view__state","aria-live":"polite",children:[n.jsx(g.Icon,{name:"loader",size:24,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:Je}),n.jsx("p",{className:"agent-view__state-message",children:Je})]}):A.length===0?n.jsx(Mt,{}):n.jsxs("div",{className:"agent-view__board",children:[At.map(u=>n.jsx(Ze,{column:Ee[u],agents:Ae[u]??[],...je},u)),n.jsx("div",{className:"agent-view__split-column",children:Nt.map(u=>n.jsx(Ze,{column:Ee[u],agents:Ae[u]??[],isSplit:!0,...je},u))})]}),j&&n.jsx(_t,{agent:j,open:!0,jwt:t,headers:S,agentUrl:r,agentChecklistUrl:c,agentResourcesUrl:o,agentTimelineUrl:l,agentChatUrl:d,agentConversationUrl:_,enableUpload:h,initialChecklist:$[j.invocation_id]??null,onClose:Ne},j.id),n.jsx(ft,{open:w,onClose:()=>C(!1),onStart:Me,agentDefinitions:O})]})},bn=(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:jt,created_by:St,status:y["generating-a-response"],context_ref:null,checklist_ref:null}};exports.AgentMonitorKanban=Cn;exports.AgentServiceClient=Be;exports.AgentServiceError=re;exports.AgentView=_t;exports.HttpChatConnector=pt;exports.NewAgentModal=ft;exports.buildAgentFromDefinition=bn;exports.createHttpChatConnectorFactory=qe;exports.mapApiAgent=De;exports.mapApiAgentDefinition=ct;exports.mapApiAgentStatus=it;exports.mapApiAgentTimelineResponse=dt;exports.mapApiChecklistEndpointResponse=ze;exports.mapApiChecklistItem=Ge;exports.mapApiChecklistResponse=gt;exports.mapApiChecklistStatus=ot;exports.mapApiConversationMessages=ut;exports.mapApiOpeningMessage=me;exports.mapApiResource=lt;exports.mapApiResourcesEndpointResponse=Fe;exports.mapApiTripOption=dn;exports.useAgentService=ht;exports.useAgentWorkspace=mt;
package/dist/index.d.ts CHANGED
@@ -22,7 +22,9 @@ export declare type AgentBackendConfig = {
22
22
  agentUrl?: string;
23
23
  agentChecklistUrl?: string;
24
24
  agentResourcesUrl?: string;
25
+ agentTimelineUrl?: string;
25
26
  agentChatUrl?: string;
27
+ agentConversationUrl?: string;
26
28
  /** When true, enables chat file uploads (posted to agentChatUrl). */
27
29
  enableUpload?: boolean;
28
30
  };
@@ -60,7 +62,7 @@ export declare type AgentDefinition = {
60
62
  description: string;
61
63
  };
62
64
 
63
- export declare const AgentMonitorKanban: ({ jwt, headers, agentDefinitionsUrl, agentsUrl, agentUrl, agentChecklistUrl, agentResourcesUrl, agentChatUrl, enableUpload, institutions, }: AgentMonitorKanbanProps) => JSX_2.Element;
65
+ export declare const AgentMonitorKanban: ({ jwt, headers, agentDefinitionsUrl, agentsUrl, agentUrl, agentChecklistUrl, agentResourcesUrl, agentTimelineUrl, agentChatUrl, agentConversationUrl, enableUpload, showHeader, institutions, }: AgentMonitorKanbanProps) => JSX_2.Element;
64
66
 
65
67
  export declare type AgentMonitorKanbanProps = {
66
68
  jwt?: string;
@@ -69,9 +71,15 @@ export declare type AgentMonitorKanbanProps = {
69
71
  agentsUrl: string;
70
72
  agentUrl: string;
71
73
  agentChecklistUrl: string;
72
- agentResourcesUrl: string;
74
+ /** Optional — omit when the backend has no /resources route. */
75
+ agentResourcesUrl?: string;
76
+ /** Optional — omit when the backend has no /agent-timeline route. */
77
+ agentTimelineUrl?: string;
73
78
  agentChatUrl: string;
79
+ agentConversationUrl: string;
74
80
  enableUpload?: boolean;
81
+ /** When true, renders the Agents heading and Start an agent button. Defaults to false. */
82
+ showHeader?: boolean;
75
83
  institutions?: InstitutionConfig[];
76
84
  };
77
85
 
@@ -109,9 +117,11 @@ export declare class AgentServiceClient {
109
117
  getAgent(agentId: string): Promise<ApiAgentInvocationDetail>;
110
118
  getAgentChecklist(agentId: string): Promise<ApiChecklistEndpointResponse>;
111
119
  getAgentResources(agentId: string): Promise<ApiResourcesEndpointResponse>;
120
+ getAgentTimeline(agentId: string): Promise<ApiAgentTimelineResponse>;
112
121
  getAgentContext(agentId: string): Promise<unknown>;
113
122
  cancelAgent(agentId: string): Promise<ApiAgentInvocation>;
114
123
  archiveAgent(agentId: string): Promise<ApiAgentInvocation>;
124
+ getConversation(agentId: string): Promise<ApiConversationResponse>;
115
125
  chat(agentId: string, request: ApiChatRequest, options?: ChatOptions): Promise<ApiChatStreamEvent>;
116
126
  private authHeaders;
117
127
  private apiUrl;
@@ -149,14 +159,33 @@ export declare type AgentServiceUrlOverrides = {
149
159
  agent?: string;
150
160
  agentChecklist?: string;
151
161
  agentResources?: string;
162
+ agentTimeline?: string;
152
163
  agentChat?: string;
164
+ agentConversation?: string;
153
165
  };
154
166
 
155
167
  export declare type AgentServiceUrls = AgentServiceUrlOverrides;
156
168
 
157
169
  export declare type AgentStatus = 'generating-a-response' | 'hitl' | 'complete' | 'failed';
158
170
 
159
- export declare const AgentView: ({ agent, open, onClose, jwt, headers, agentUrl, agentChecklistUrl, agentResourcesUrl, agentChatUrl, enableUpload, initialBrief, initialPhase, initialChecklist, }: AgentViewProps) => JSX_2.Element;
171
+ declare type AgentTimeline = {
172
+ actionLog: AgentTimelineActionLogEntry[];
173
+ chatSessions: AgentTimelineChatSession[];
174
+ };
175
+
176
+ declare type AgentTimelineActionLogEntry = {
177
+ timestamp: string;
178
+ type: string;
179
+ entry: string;
180
+ origin: string;
181
+ };
182
+
183
+ declare type AgentTimelineChatSession = {
184
+ sessionId: string;
185
+ timestamp: string;
186
+ };
187
+
188
+ export declare const AgentView: ({ agent, open, onClose, jwt, headers, agentUrl, agentChecklistUrl, agentResourcesUrl, agentTimelineUrl, agentChatUrl, agentConversationUrl, chatId, enableUpload, initialBrief, initialPhase, initialChecklist, }: AgentViewProps) => JSX_2.Element;
160
189
 
161
190
  export declare type AgentViewProps = {
162
191
  agent: Agent;
@@ -166,8 +195,14 @@ export declare type AgentViewProps = {
166
195
  headers?: Record<string, string>;
167
196
  agentUrl: string;
168
197
  agentChecklistUrl: string;
169
- agentResourcesUrl: string;
198
+ /** Optional — omit when the backend has no /resources route. */
199
+ agentResourcesUrl?: string;
200
+ /** Optional — omit when the backend has no /agent-timeline route. */
201
+ agentTimelineUrl?: string;
170
202
  agentChatUrl: string;
203
+ agentConversationUrl: string;
204
+ /** Timeline/conversation session id for chat turns. Defaults to agent.invocation_id. */
205
+ chatId?: string;
171
206
  /** When true, enables chat file uploads (posted to agentChatUrl). */
172
207
  enableUpload?: boolean;
173
208
  initialBrief?: AgentBrief;
@@ -178,8 +213,10 @@ export declare type AgentViewProps = {
178
213
  export declare type AgentWorkspaceUrls = {
179
214
  agentUrl: string;
180
215
  agentChecklistUrl: string;
181
- agentResourcesUrl: string;
216
+ agentResourcesUrl?: string;
217
+ agentTimelineUrl?: string;
182
218
  agentChatUrl: string;
219
+ agentConversationUrl: string;
183
220
  };
184
221
 
185
222
  export declare type ApiAgentDefinition = {
@@ -231,6 +268,23 @@ export declare type ApiAgentResource = {
231
268
  description?: string;
232
269
  };
233
270
 
271
+ export declare type ApiAgentTimelineActionLogEntry = {
272
+ timestamp: string;
273
+ type: string;
274
+ entry: string;
275
+ origin: string;
276
+ };
277
+
278
+ export declare type ApiAgentTimelineChatSession = {
279
+ session_id: string;
280
+ timestamp: string;
281
+ };
282
+
283
+ export declare type ApiAgentTimelineResponse = {
284
+ action_log: ApiAgentTimelineActionLogEntry[];
285
+ chat_sessions: ApiAgentTimelineChatSession[];
286
+ };
287
+
234
288
  export declare type ApiChatMessage = {
235
289
  role: ApiChatRole;
236
290
  content: string;
@@ -290,6 +344,36 @@ export declare type ApiChecklistItem = {
290
344
 
291
345
  export declare type ApiChecklistItemStatus = 'in_progress' | 'requires_attention' | 'failed' | 'complete' | 'available' | 'generating-a-response' | 'hitl';
292
346
 
347
+ export declare type ApiConversationMessage = {
348
+ message_id: string;
349
+ seq_in_session: number;
350
+ message_type: ApiConversationMessageType;
351
+ role: ApiConversationMessageRole;
352
+ content: string | null;
353
+ created_at: string;
354
+ tool_call_id: string | null;
355
+ tool_calls: ApiConversationToolCall[] | null;
356
+ moderation_status: string | null;
357
+ };
358
+
359
+ export declare type ApiConversationMessageRole = 'system' | 'user' | 'assistant' | 'tool';
360
+
361
+ export declare type ApiConversationMessageType = 'system' | 'user' | 'assistant' | 'tool_request' | 'tool_response';
362
+
363
+ export declare type ApiConversationResponse = {
364
+ session_id: string;
365
+ messages: ApiConversationMessage[];
366
+ };
367
+
368
+ export declare type ApiConversationToolCall = {
369
+ id: string;
370
+ type: string;
371
+ function: {
372
+ name: string;
373
+ arguments: string;
374
+ };
375
+ };
376
+
293
377
  export declare type ApiCreateAgentResponse = {
294
378
  id: string;
295
379
  status: ApiAgentInvocationStatus;
@@ -313,7 +397,7 @@ export declare const buildAgentFromDefinition: (definition: AgentDefinition, inv
313
397
  export declare interface ChatConnector {
314
398
  openingMessage(): ChatMessage;
315
399
  start(brief: AgentBrief): Promise<ChatTurn>;
316
- sendMessage(text: string): Promise<ChatTurn>;
400
+ sendMessage(text: string, uploadFiles?: File[]): Promise<ChatTurn>;
317
401
  stop(): Promise<void>;
318
402
  seedChecklist?(checklist: AgentChecklistItem[]): void;
319
403
  bootstrapConversation?(prompt?: string): Promise<ChatMessage[]>;
@@ -332,6 +416,8 @@ export declare type ChatMessageAuthor = 'agent' | 'user' | 'system';
332
416
  export declare type ChatOptions = {
333
417
  onEvent?: (event: ApiChatStreamEvent) => void;
334
418
  signal?: AbortSignal;
419
+ /** When set, the chat turn is posted as multipart/form-data with these files. */
420
+ uploadFiles?: File[];
335
421
  };
336
422
 
337
423
  export declare type ChatTurn = {
@@ -345,6 +431,10 @@ export declare const createHttpChatConnectorFactory: (client: AgentServiceClient
345
431
  id: string;
346
432
  invocation_id: string;
347
433
  }) => ChatMessage | undefined;
434
+ resolveChatId?: (agent: {
435
+ id: string;
436
+ invocation_id: string;
437
+ }) => string | undefined;
348
438
  }) => (agent: {
349
439
  id: string;
350
440
  invocation_id: string;
@@ -355,16 +445,15 @@ declare type FetchLike = typeof fetch;
355
445
  export declare class HttpChatConnector implements ChatConnector {
356
446
  private readonly client;
357
447
  private readonly agentId;
448
+ private readonly chatId;
358
449
  private readonly opening;
359
450
  private readonly model?;
360
- private readonly bootstrapPrompt;
361
- private chatId?;
362
451
  private seededChecklist;
363
452
  constructor(client: AgentServiceClient, agentId: string, options?: HttpChatConnectorOptions);
364
453
  openingMessage(): ChatMessage;
365
- bootstrapConversation(prompt?: string): Promise<ChatMessage[]>;
454
+ bootstrapConversation(): Promise<ChatMessage[]>;
366
455
  start(brief: AgentBrief): Promise<ChatTurn>;
367
- sendMessage(text: string): Promise<ChatTurn>;
456
+ sendMessage(text: string, uploadFiles?: File[]): Promise<ChatTurn>;
368
457
  stop(): Promise<void>;
369
458
  seedChecklist(checklist: AgentChecklistItem[]): void;
370
459
  private exchange;
@@ -373,7 +462,7 @@ export declare class HttpChatConnector implements ChatConnector {
373
462
  export declare type HttpChatConnectorOptions = {
374
463
  openingMessage?: ChatMessage;
375
464
  model?: string;
376
- bootstrapPrompt?: string;
465
+ chatId?: string;
377
466
  };
378
467
 
379
468
  export declare type InstitutionConfig = {
@@ -393,6 +482,8 @@ export declare const mapApiAgentDefinition: (record: ApiAgentDefinition) => Agen
393
482
 
394
483
  export declare const mapApiAgentStatus: (status: string) => AgentStatus;
395
484
 
485
+ export declare const mapApiAgentTimelineResponse: (payload: ApiAgentTimelineResponse) => AgentTimeline;
486
+
396
487
  export declare const mapApiChecklistEndpointResponse: (invocationId: string, payload: ApiChecklistEndpointResponse, agent?: Pick<ApiAgentInvocation, "opening_message" | "opening_follow_up_prompts">) => AgentChecklistResponse;
397
488
 
398
489
  export declare const mapApiChecklistItem: (item: ApiChecklistItem) => AgentChecklistItem;
@@ -401,6 +492,8 @@ export declare const mapApiChecklistResponse: (invocationId: string, detail: Api
401
492
 
402
493
  export declare const mapApiChecklistStatus: (status: ApiChecklistItemStatus | string | undefined) => AgentChecklistItemStatus;
403
494
 
495
+ export declare const mapApiConversationMessages: (messages: ApiConversationMessage[]) => ChatMessage[];
496
+
404
497
  export declare const mapApiOpeningMessage: (record: Pick<ApiAgentInvocation, "opening_message" | "opening_follow_up_prompts">) => ChatMessage | undefined;
405
498
 
406
499
  export declare const mapApiResource: (record: ApiAgentResource) => AgentResource;
@@ -441,6 +534,8 @@ export declare type UseAgentServiceResult = {
441
534
  loadState: AgentServiceLoadState;
442
535
  loadError: string | null;
443
536
  reload: () => void;
537
+ /** Re-fetch agents without a loading flash; no-ops state when unchanged. */
538
+ refresh: () => Promise<void>;
444
539
  fetchAgentChecklist: (invocationId: string) => Promise<AgentChecklistResponse>;
445
540
  fetchAgentResources: (invocationId: string) => Promise<AgentResource[]>;
446
541
  createAgent: (payload: NewAgentStartPayload) => Promise<Agent>;
@@ -454,12 +549,14 @@ export declare type UseAgentWorkspaceConfig = {
454
549
  jwt?: string;
455
550
  headers?: Record<string, string>;
456
551
  urls: AgentWorkspaceUrls;
552
+ chatId?: string;
457
553
  };
458
554
 
459
555
  export declare type UseAgentWorkspaceResult = {
460
556
  connector: ChatConnector;
461
557
  fetchAgentChecklist: (invocationId: string) => Promise<AgentChecklistResponse>;
462
558
  fetchAgentResources: (invocationId: string) => Promise<AgentResource[]>;
559
+ fetchAgentTimeline: (invocationId: string) => Promise<AgentTimeline>;
463
560
  };
464
561
 
465
562
  export declare type WorkspacePhase = 'briefing' | 'running' | 'stopped' | 'complete';