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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,13 +142,52 @@ 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
 
147
151
  Parameterised routes substitute the `:invocationId` placeholder. See the
148
152
  [AI service SDK](#ai-service-sdk) section for the underlying client.
149
153
 
154
+ ### Standalone `NewAgentModal`
155
+
156
+ `NewAgentModal` normally renders as a child of `AgentMonitorKanban` (the board
157
+ supplies `agentDefinitions` and an `onStart` handler). It can also be mounted on
158
+ its own — e.g. as a server-rendered `new-agent-modal` widget — by passing
159
+ endpoint URLs instead. In this mode the modal loads its own definitions, creates
160
+ the agent, and navigates the page on close/success.
161
+
162
+ ```tsx
163
+ import { NewAgentModal } from 'agent-view-frontend';
164
+
165
+ const api = 'https://ai-agent-service.qa.arbor.engineering/api/v1';
166
+
167
+ <NewAgentModal
168
+ open
169
+ authToken={jwt}
170
+ headers={{ 'X-Arbor-Application': 'agent-view' }}
171
+ agentDefinitionsUrl={`${api}/agent-definitions`}
172
+ agentsUrl={`${api}/agents`}
173
+ closeUrl="/dashboard"
174
+ successUrl="/agents"
175
+ />;
176
+ ```
177
+
178
+ | Prop | Attribute | Required | Purpose |
179
+ |---|---|---|---|
180
+ | `agentDefinitionsUrl` | `agent-definitions-url` | yes | Full URL to GET the agent definitions list. |
181
+ | `agentsUrl` | `agents-url` | yes | Full URL to POST a new agent. |
182
+ | `authToken` | `auth-token` | no | Bearer token attached to every request. |
183
+ | `headers` | `headers` | no | Extra headers merged into every request. |
184
+ | `open` | `open` | no | Whether the modal is open. |
185
+ | `closeUrl` | `close-url` | no | Page navigated to when the modal is closed. |
186
+ | `successUrl` | `success-url` | no | Page navigated to after a successful start. |
187
+
188
+ Navigation uses `window.location.assign`. `closeUrl`/`successUrl` are optional —
189
+ omit them (and pass `onClose`/`onStart`) to keep the modal fully controlled.
190
+
150
191
  ---
151
192
 
152
193
  ## NPM usage
@@ -173,7 +214,9 @@ function Page() {
173
214
  agentUrl={`${api}/agents/:invocationId`}
174
215
  agentChecklistUrl={`${api}/agents/:invocationId/checklist`}
175
216
  agentResourcesUrl={`${api}/agents/:invocationId/resources`}
217
+ agentTimelineUrl={`${api}/agents/:invocationId/agent-timeline`}
176
218
  agentChatUrl={`${api}/agents/:invocationId/chat`}
219
+ agentConversationUrl={`${api}/conversations/:invocationId`}
177
220
  />
178
221
  );
179
222
  }
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",De="msg-opening",Ae="Unable to load agent tasks. Please try again.",nt="Unable to load the resources for this agent",st="Something went wrong. Please try again.",$e="Unable to load agents. Please try again.",ee="Loading tasks…",Ie="Loading agents…",at="Task",rt="What recent actions have you taken?",ot={[N.briefing]:"Briefing",[N.running]:"Working",[N.stopped]:"Stopped",[N.complete]:"Complete"},it=[v["generating-a-response"],v.hitl,v.complete,v.failed],ct={[v["generating-a-response"]]:"Agents currently working on tasks for you.",[v.hitl]:"Agents that need your input before they can continue.",[v.complete]:"Agents that have finished their work.",[v.failed]:"Agents that failed or were stopped."},lt=()=>n.jsxs("svg",{className:"agent-view__empty-illustration",viewBox:"0 0 360 240",xmlns:"http://www.w3.org/2000/svg",role:"img","aria-label":"Preview of the agents board layout",children:[n.jsx("rect",{x:"0",y:"0",width:"360",height:"240",rx:"12",fill:"var(--color-grey-100)"}),n.jsx("rect",{x:"16",y:"16",width:"100",height:"208",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"130",y:"16",width:"100",height:"208",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"244",y:"16",width:"100",height:"100",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"244",y:"124",width:"100",height:"100",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"28",y:"52",width:"76",height:"36",rx:"6",fill:"var(--color-grey-050)"}),n.jsx("rect",{x:"28",y:"96",width:"76",height:"36",rx:"6",fill:"var(--color-grey-050)"}),n.jsx("rect",{x:"142",y:"52",width:"76",height:"36",rx:"6",fill:"var(--color-semantic-warning-050)"}),n.jsx("circle",{cx:"40",cy:"70",r:"4",fill:"var(--color-brand-600)"}),n.jsx("circle",{cx:"40",cy:"114",r:"4",fill:"var(--color-brand-600)"}),n.jsx("circle",{cx:"154",cy:"70",r:"4",fill:"var(--color-semantic-warning-600)"}),n.jsx("circle",{cx:"256",cy:"52",r:"4",fill:"var(--color-grey-400)"}),n.jsx("circle",{cx:"256",cy:"160",r:"4",fill:"var(--color-semantic-destructive-500)"})]}),dt=({status:e})=>{const t=pe[e];return t.statusIcon?n.jsx(u.Icon,{name:t.statusIcon.name,size:16,color:t.statusIcon.color,screenReaderText:t.title}):n.jsx(u.Dot,{colour:t.dotColour,label:t.title})},gt=()=>n.jsxs("section",{className:"agent-view__empty","aria-label":"About the agents board",children:[n.jsxs("div",{className:"agent-view__empty-content",children:[n.jsx(u.Heading,{level:4,children:"Your agents board"}),n.jsx("p",{className:"agent-view__empty-lead",children:"When you start an agent, it appears here so you can track progress at a glance. Agents move between columns as their status changes."}),n.jsx("ul",{className:"agent-view__empty-columns",children:it.map(e=>{const t=pe[e];return n.jsxs("li",{className:"agent-view__empty-column",children:[n.jsx("span",{className:"agent-view__empty-column-indicator",children:n.jsx(dt,{status:e})}),n.jsxs("span",{className:"agent-view__empty-column-text",children:[n.jsx("span",{className:"agent-view__empty-column-title",children:t.title}),n.jsx("span",{className:"agent-view__empty-column-description",children:ct[e]})]})]},e)})}),n.jsxs("p",{className:"agent-view__empty-hint",children:["Use ",n.jsx("strong",{children:"Start an agent"})," above to begin."]})]}),n.jsx("div",{className:"agent-view__empty-visual",children:n.jsx(lt,{})})]}),ut=(e,t)=>({...e,...t.length>0?{children:t}:{}}),He=e=>{const t=[],s=[];for(const a of e){const r=a.children?He(a.children):{needsInput:[],tasks:[]};if(t.push(...r.needsInput),a.status===S.hitl){t.push({...a,children:void 0});continue}s.push(ut(a,r.tasks))}return{needsInput:t,tasks:s}},pt=e=>e.map((t,s)=>({item:t,index:s})).sort((t,s)=>{const a=t.item.status===S.hitl,r=s.item.status===S.hitl;return a!==r?a?-1:1:t.index-s.index}).map(({item:t})=>t),ht=({checklist:e})=>e.length===0?n.jsx("p",{className:"agent-view__progress-empty",children:"No tasks to display."}):n.jsx("ul",{className:"agent-view__progress-list","aria-label":"Agent tasks",children:pt(e).map(t=>{const s=U[t.status];return n.jsxs("li",{className:L("agent-view__progress-item",`agent-view__progress-item--${t.status.replace(/_/g,"-")}`),children:[n.jsx(u.Icon,{name:s.icon,size:16,color:s.color,screenReaderText:`${s.label}:`,className:L({"agent-view__progress-icon--spinning":t.status===S["generating-a-response"]})}),n.jsxs("div",{className:"agent-view__progress-item-content",children:[n.jsx("span",{className:"agent-view__progress-label",children:t.task}),t.status!==S.complete&&n.jsx("span",{className:"agent-view__progress-description",children:t.description})]})]},t.task)})}),mt=({prompts:e,classNamePrefix:t="agent-workspace",onSelect:s})=>e.length===0?null:n.jsx("div",{className:`${t}__chips`,children:e.map(a=>n.jsx("button",{type:"button",className:`${t}__chip`,onClick:()=>s(a),children:a},a))});class _t{constructor(t,s){this.connector=t,this.canSend=s.canSend,this.onTurn=s.onTurn,this.onAwaitingChange=s.onAwaitingChange}get canRate(){return!1}get canLoadHistory(){return!1}get canListInteractions(){return!1}get canSendNotification(){return!1}get ratingPopupUrls(){return{}}async sendMessage(t){var s,a;if(!this.canSend())return null;(s=this.onAwaitingChange)==null||s.call(this,!0);try{const r=await this.connector.sendMessage(t.userMessage,t.uploadFiles);return this.onTurn(r),{id:r.message.id,text:r.message.text,type:se.CHAT_RESPONSE_TYPE_AGENT,...r.message.followUpPrompts?{followUpPrompts:r.message.followUpPrompts}:{}}}catch{return{id:`error-${Date.now()}`,text:st,type:se.CHAT_RESPONSE_TYPE_ERROR}}finally{(a=this.onAwaitingChange)==null||a.call(this,!1)}}async loadHistory(t){return null}async listInteractions(){return null}async rateMessage(t){}async sendNotification(t){return!1}}const ft=({connector:e,phase:t,chatHistory:s,chatSessionKey:a,startQuery:r,clarificationMessage:c,enableUpload:l=!1,onTurn:d,onAwaitingChange:w,onClarificationPrompt:f,onDismissClarification:p})=>{const _=i.useMemo(()=>new _t(e,{canSend:()=>t===N.running,onTurn:d,onAwaitingChange:w}),[e,t,d,w]),h=t!==N.running,j=t===N.running;return n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--chat","aria-label":"Chat",children:[c&&n.jsxs("div",{className:"agent-workspace__clarification",role:"region","aria-label":"Agent question",children:[n.jsx("p",{className:"agent-workspace__clarification-text",children:c.text}),c.followUpPrompts&&n.jsx(mt,{prompts:c.followUpPrompts,onSelect:f}),n.jsx("button",{type:"button",className:"agent-workspace__clarification-dismiss",onClick:p,children:"Dismiss"})]}),n.jsx("div",{className:"agent-workspace__ask-arbor",children:n.jsx(se.ChatPanel,{connector:_,chatHistory:s,startQuery:r,lockConversation:h,enableUpload:l,speechEnabled:j,speechLanguage:"en-GB",speechSubmissionDelay:1e3,slashMenuItems:[],menuContent:[],introHeading:"Message your agent",introBody:"Ask questions, share trip details, or paste a link. The agent will update the checklist as it works.",placeholder:j?"Message the agent, paste a link, or attach a file…":"The agent is not accepting messages."},a)}),t===N.stopped&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(u.Icon,{name:"circle-alert",size:16,color:"var(--color-semantic-warning-600)"}),n.jsx("span",{children:"You stopped the agent. Its progress is saved in the checklist on the left."})]}),t===N.complete&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(u.Icon,{name:"party-popper",size:16,color:"var(--color-semantic-success-600)"}),n.jsx("span",{children:"The agent has finished."})]})]})},Fe=({item:e,depth:t,canRequestInput:s,onAttentionItemClick:a})=>{const r=U[e.status],c=e.status.replace(/_/g,"-"),l=e.status===S.hitl&&s&&a,d=n.jsxs("div",{className:"agent-workspace__task-row",children:[n.jsx(u.Icon,{name:r.icon,size:16,color:r.color,screenReaderText:`${r.label}:`,className:L({"agent-workspace__task-icon--spinning":e.status===S["generating-a-response"]})}),n.jsxs("div",{className:"agent-workspace__task-content",children:[n.jsx("span",{className:"agent-workspace__task-label",children:e.task}),e.status!==S.complete&&e.description&&n.jsx("span",{className:"agent-workspace__task-description",children:e.description})]})]});return n.jsxs("li",{className:L("agent-workspace__task",`agent-workspace__task--${c}`,{"agent-workspace__task--child":t>0}),children:[l?n.jsx("button",{type:"button",className:"agent-workspace__task-button","aria-label":`Provide input for ${e.task}`,onClick:()=>a(e),children:d}):d,e.children&&e.children.length>0&&n.jsx("ul",{className:"agent-workspace__task-children",children:e.children.map(w=>n.jsx(Fe,{item:w,depth:t+1,canRequestInput:s,onAttentionItemClick:a},w.task))})]})},Re=({items:e,ariaLabel:t,canRequestInput:s,onAttentionItemClick:a})=>n.jsx("ul",{className:"agent-workspace__task-list","aria-label":t,children:e.map(r=>n.jsx(Fe,{item:r,depth:0,canRequestInput:s,onAttentionItemClick:a},r.task))}),vt=({checklist:e,isLoading:t,error:s,phase:a,canRequestInput:r,onStop:c,onAttentionItemClick:l})=>{const d=i.useMemo(()=>e?He(e):null,[e]);return n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--checklist","aria-label":"Checklist",children:[n.jsxs("div",{className:"agent-workspace__panel-header",children:[n.jsx(u.Heading,{level:4,children:"Checklist"}),a===N.running&&n.jsx(u.Button,{variant:"secondary-destructive",size:"S",iconLeftName:"circle-x",iconLeftScreenReaderText:"Stop",onClick:c,children:"Stop agent"})]}),n.jsxs("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:[t&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:ee}),n.jsx("span",{children:ee})]}),!t&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!t&&!s&&d&&n.jsxs(n.Fragment,{children:[d.needsInput.length>0&&n.jsxs("div",{className:"agent-workspace__task-group",children:[n.jsx("p",{className:"agent-workspace__task-group-label",children:"Needs your input"}),n.jsx(Re,{items:d.needsInput,ariaLabel:"Tasks needing your input",canRequestInput:r,onAttentionItemClick:l})]}),d.tasks.length>0&&n.jsxs("div",{className:L("agent-workspace__task-group",{"agent-workspace__task-group--following":d.needsInput.length>0}),children:[d.needsInput.length>0&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"Other tasks"}),n.jsx(Re,{items:d.tasks,ariaLabel:"Agent tasks",canRequestInput:r,onAttentionItemClick:l})]})]}),!t&&!s&&(!d||d.needsInput.length===0&&d.tasks.length===0)&&n.jsx("p",{className:"agent-workspace__empty",children:a===N.briefing?"Tasks will appear here once the agent starts.":"No tasks to display."})]})]})},wt={[Z.MIS_RECORD]:{icon:"table",label:"Arbor MIS",color:"var(--color-brand-600)"},[Z.FILE]:{icon:"file",label:"File",color:"var(--color-semantic-caution-800)"},[Z.WORKFLOW]:{icon:"list-tree",label:"Workflow",color:"var(--color-semantic-warning-700)"},[Z.LINK]:{icon:"link",label:"Link",color:"var(--color-semantic-info-700)"}},xt=({resources:e,isLoading:t=!1,error:s=null})=>n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--documents","aria-label":"Resources",children:[n.jsxs("div",{className:"agent-workspace__panel-header",children:[n.jsx(u.Heading,{level:4,children:"Resources"}),n.jsx("span",{className:"agent-workspace__panel-count",children:e.length})]}),n.jsxs("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:[t&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:"Loading resources"}),n.jsx("span",{children:"Loading resources…"})]}),!t&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!t&&!s&&e.length>0&&n.jsx("ul",{className:"agent-workspace__resource-list","aria-label":"Agent resources",children:e.map(a=>{const r=wt[a.type];return n.jsx("li",{className:"agent-workspace__resource",children:n.jsxs("a",{className:"agent-workspace__resource-card",href:a.uri,target:"_blank",rel:"noreferrer",children:[n.jsx("span",{className:`agent-workspace__resource-icon agent-workspace__resource-icon--${a.type.toLowerCase()}`,children:n.jsx(u.Icon,{name:r.icon,size:16,color:r.color,screenReaderText:`${r.label}:`})}),n.jsxs("span",{className:"agent-workspace__resource-content",children:[n.jsxs("span",{className:"agent-workspace__resource-top",children:[n.jsx("span",{className:"agent-workspace__resource-name",children:a.name}),n.jsx("span",{className:`agent-workspace__resource-badge agent-workspace__resource-badge--${a.type.toLowerCase()}`,children:r.label})]}),a.description&&n.jsx("span",{className:"agent-workspace__resource-description",children:a.description})]}),n.jsx(u.Icon,{name:"external-link",size:12,color:"var(--color-grey-500)",screenReaderText:"Opens in a new tab",className:"agent-workspace__resource-open"})]})},`${a.type}-${a.uri}`)})}),!t&&!s&&e.length===0&&n.jsx("p",{className:"agent-workspace__empty",children:"No resources yet."})]})]}),kt=["I'll get the details and come back to you","Skip this for now"],At=e=>{var s;const t=(s=e.prompt)!=null&&s.trim()?e.prompt.trim():`I need a bit more from you on "${e.task}". ${e.description} What can you tell me?`;return{id:`clarification-${Date.now()}`,author:B.agent,text:t,followUpPrompts:e.clarificationPrompts??kt}},ce=e=>({id:e.id,text:e.text,type:e.author===B.user?se.CHAT_RESPONSE_TYPE_USER:e.author===B.system?se.CHAT_RESPONSE_TYPE_INFO:se.CHAT_RESPONSE_TYPE_AGENT,...e.followUpPrompts?{followUpPrompts:e.followUpPrompts}:{}});class te extends Error{constructor(t,s,a){super(a??`Agent service request failed (${t})`),this.name="AgentServiceError",this.status=t,this.detail=s}}const yt="/api/v1",E={agentDefinitions:"/agent-definitions",agents:"/agents",tripOptions:"/trip-options",demoDataset:"/demo/dataset"},T={GET:"GET",POST:"POST"},St={error:"error"},Nt={user:"user"},ne={acceptJson:"application/json",acceptEventStream:"text/event-stream",contentTypeJson:"application/json",arborApplicationUrl:"X-Arbor-Application-Url"},jt=/:invocationId\b/g,Ct=e=>e.trim().replace(/^Bearer\s+/i,""),bt=e=>e.endsWith("/")?e.slice(0,-1):e;class Ne{constructor(t){var a;this.baseUrl=bt(t.baseUrl??"");const s=(a=t.token)==null?void 0:a.trim();this.token=s?Ct(s):void 0,this.customHeaders=t.headers,this.urls=t.urls??{},this.fetchImpl=t.fetch??globalThis.fetch.bind(globalThis)}setHeaders(t){this.customHeaders=t}async listAgentDefinitions(){return(await this.request(T.GET,this.resolveUrl("agentDefinitions",E.agentDefinitions))).agent_definitions??[]}getAgentDefinition(t){return this.request(T.GET,this.apiUrl(`${E.agentDefinitions}/${encodeURIComponent(t)}`))}listTripOptions(){return this.request(T.GET,this.apiUrl(E.tripOptions))}getDataset(){return this.request(T.GET,this.apiUrl(E.demoDataset))}setDataset(t){return this.request(T.POST,this.apiUrl(E.demoDataset),{dataset:t})}listAgents(t={}){const s=new URLSearchParams;t.status&&s.set("status",t.status),t.agentDefinitionRef&&s.set("agent_definition_ref",t.agentDefinitionRef);const a=s.toString()?`?${s.toString()}`:"";return this.request(T.GET,`${this.resolveUrl("agents",E.agents)}${a}`)}createAgent(t,s={}){var l,d;const a={agent_definition_ref:t},r=(l=s.invocationName)==null?void 0:l.trim(),c=(d=s.agentIntent)==null?void 0:d.trim();return r&&(a.invocation_name=r),c&&(a.agent_intent=c),this.request(T.POST,this.resolveUrl("agents",E.agents),a)}getAgent(t){return this.request(T.GET,this.resolveUrl("agent",`${E.agents}/${encodeURIComponent(t)}`,t))}getAgentChecklist(t){return this.request(T.GET,this.resolveUrl("agentChecklist",`${E.agents}/${encodeURIComponent(t)}/checklist`,t))}getAgentResources(t){return this.request(T.GET,this.resolveUrl("agentResources",`${E.agents}/${encodeURIComponent(t)}/resources`,t))}getAgentContext(t){return this.request(T.GET,this.apiUrl(`${E.agents}/${encodeURIComponent(t)}/context`))}cancelAgent(t){return this.request(T.POST,this.apiUrl(`${E.agents}/${encodeURIComponent(t)}/cancel`))}archiveAgent(t){return this.request(T.POST,this.apiUrl(`${E.agents}/${encodeURIComponent(t)}/archive`))}async chat(t,s,a={}){const r=!!(a.uploadFiles&&a.uploadFiles.length>0),c=await this.fetchImpl(this.resolveUrl("agentChat",`${E.agents}/${encodeURIComponent(t)}/chat`,t),{method:T.POST,headers:{...this.customHeaders,...this.authHeaders(),Accept:ne.acceptEventStream,...r?{}:{"Content-Type":ne.contentTypeJson}},body:r?Tt(s,a.uploadFiles??[]):JSON.stringify(s),signal:a.signal});if(!c.ok)throw await this.toError(c);if(!c.body)throw new te(c.status,null,"Chat response contained no stream body");return this.consumeSse(c.body,a.onEvent)}authHeaders(){return this.token?{Authorization:`Bearer ${this.token}`}:{}}apiUrl(t){return`${this.baseUrl}${yt}${t}`}resolveUrl(t,s,a){const r=this.urls[t];return r?a?r.replace(jt,encodeURIComponent(a)):r:this.apiUrl(s)}async request(t,s,a){const r=await this.fetchImpl(s,{method:t,headers:{...this.customHeaders,...this.authHeaders(),Accept:ne.acceptJson,...a===void 0?{}:{"Content-Type":ne.contentTypeJson}},...a===void 0?{}:{body:JSON.stringify(a)}});if(!r.ok)throw await this.toError(r);if(r.status!==204)return await r.json()}async toError(t){let s=null;try{s=await t.json()}catch{}return new te(t.status,s,`Agent service request failed (${t.status} ${t.statusText})`)}async consumeSse(t,s){const a=t.getReader(),r=new TextDecoder;let c="",l;const d=w=>{const{event:f,data:p}=Et(w);if(p===null)return;if(f===St.error){const h=Oe(p);throw new te(502,h,(h==null?void 0:h.message)??"Chat stream error")}const _=Oe(p);_&&(l=_,s==null||s(_))};for(;;){const{done:w,value:f}=await a.read();if(w)break;c+=r.decode(f,{stream:!0});const p=c.split(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),r=require("react"),G=require("classnames"),g=require("@arbor-education/design-system.components"),oe=require("@arbor-education/ask-arbor-chat-panel"),j={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},O={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},E={briefing:"briefing",running:"running",stopped:"stopped",complete:"complete"},X={agent:"agent",user:"user",system:"system"},se={MIS_RECORD:"MIS_RECORD",FILE:"FILE",WORKFLOW:"WORKFLOW",LINK:"LINK"},Je={cancelled:"cancelled",archived:"archived"},De={in_progress:"in_progress",requires_attention:"requires_attention",available:"available"},W={[O.complete]:{label:"Complete",icon:"circle-check",color:"var(--color-semantic-success-600)"},[O.failed]:{label:"Failed",icon:"circle-x",color:"var(--color-semantic-destructive-600)"},[O.hitl]:{label:"Requires attention",icon:"triangle-alert",color:"var(--color-semantic-warning-600)"},[O["generating-a-response"]]:{label:"Generating a response",icon:"sparkles",color:"var(--color-brand-600)"}},Ee={[j["generating-a-response"]]:{status:j["generating-a-response"],title:"Active",dotColour:"green",statusIcon:{name:W["generating-a-response"].icon,color:W["generating-a-response"].color}},[j.hitl]:{status:j.hitl,title:"Requires attention",dotColour:"orange",statusIcon:{name:W.hitl.icon,color:W.hitl.color}},[j.complete]:{status:j.complete,title:"Complete",dotColour:"green",dotModifier:"grey-dark",statusIcon:{name:W.complete.icon,color:W.complete.color}},[j.failed]:{status:j.failed,title:"Failed",dotColour:"salmon",statusIcon:{name:W.failed.icon,color:W.failed.color}}},Ct=[j["generating-a-response"],j.hitl],bt=[j.complete,j.failed],Tt="m4",Et="1",st="msg-opening",Te="Unable to load agent tasks. Please try again.",It="Unable to load the resources for this agent",at="Unable to load the timeline for this agent",Rt="Something went wrong. Please try again.",it="Unable to load agents. Please try again.",ae="Loading tasks…",Ve="Loading agents…",Ot="Task",Pt={[E.briefing]:"Briefing",[E.running]:"Working",[E.stopped]:"Stopped",[E.complete]:"Complete"},Mt=[j["generating-a-response"],j.hitl,j.complete,j.failed],Lt={[j["generating-a-response"]]:"Agents currently working on tasks for you.",[j.hitl]:"Agents that need your input before they can continue.",[j.complete]:"Agents that have finished their work.",[j.failed]:"Agents that failed or were stopped."},Dt=()=>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)"})]}),$t=({status:e})=>{const t=Ee[e];return t.statusIcon?n.jsx(g.Icon,{name:t.statusIcon.name,size:16,color:t.statusIcon.color,screenReaderText:t.title}):n.jsx(g.Dot,{colour:t.dotColour,label:t.title})},Ut=()=>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:Mt.map(e=>{const t=Ee[e];return n.jsxs("li",{className:"agent-view__empty-column",children:[n.jsx("span",{className:"agent-view__empty-column-indicator",children:n.jsx($t,{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:Lt[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(Dt,{})})]}),Bt=(e,t)=>({...e,...t.length>0?{children:t}:{}}),rt=e=>{const t=[],s=[];for(const a of e){const i=a.children?rt(a.children):{needsInput:[],tasks:[]};if(t.push(...i.needsInput),a.status===O.hitl){t.push({...a,children:void 0});continue}s.push(Bt(a,i.tasks))}return{needsInput:t,tasks:s}},Ht=e=>e.map((t,s)=>({item:t,index:s})).sort((t,s)=>{const a=t.item.status===O.hitl,i=s.item.status===O.hitl;return a!==i?a?-1:1:t.index-s.index}).map(({item:t})=>t),Ft=({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:Ht(e).map(t=>{const s=W[t.status];return n.jsxs("li",{className:G("agent-view__progress-item",`agent-view__progress-item--${t.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:t.task}),t.status!==O.complete&&n.jsx("span",{className:"agent-view__progress-description",children:t.description})]})]},t.task)})}),zt=({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 Gt{constructor(t,s){this.connector=t,this.canSend=s.canSend,this.onTurn=s.onTurn,this.onAwaitingChange=s.onAwaitingChange}get canRate(){return!1}get canLoadHistory(){return!1}get canListInteractions(){return!1}get canSendNotification(){return!1}get ratingPopupUrls(){return{}}async sendMessage(t){var s,a;if(!this.canSend())return null;(s=this.onAwaitingChange)==null||s.call(this,!0);try{const i=await this.connector.sendMessage(t.userMessage,t.uploadFiles);return this.onTurn(i),{id:i.message.id,text:i.message.text,type:oe.CHAT_RESPONSE_TYPE_AGENT,...i.message.followUpPrompts?{followUpPrompts:i.message.followUpPrompts}:{}}}catch{return{id:`error-${Date.now()}`,text:Rt,type:oe.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 qt=({connector:e,phase:t,chatHistory:s,chatSessionKey:a,startQuery:i,clarificationMessage:l,enableUpload:o=!1,onTurn:c,onAwaitingChange:d,onClarificationPrompt:f,onDismissClarification:h})=>{const u=r.useMemo(()=>new Gt(e,{canSend:()=>t===E.running,onTurn:c,onAwaitingChange:d}),[e,t,c,d]),w=t!==E.running,m=t===E.running;return n.jsxs("section",{className:"agent-workspace__chat-body","aria-label":"Chat",children:[l&&n.jsxs("div",{className:"agent-workspace__clarification",role:"region","aria-label":"Agent question",children:[n.jsx("p",{className:"agent-workspace__clarification-text",children:l.text}),l.followUpPrompts&&n.jsx(zt,{prompts:l.followUpPrompts,onSelect:f}),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:u,chatHistory:s,startQuery:i,lockConversation:w,enableUpload:o,speechEnabled:m,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:m?"Message the agent, paste a link, or attach a file…":"The agent is not accepting messages."},a)}),t===E.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."})]}),t===E.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."})]})]})},ot=({item:e,depth:t,canRequestInput:s,onAttentionItemClick:a})=>{const i=W[e.status],l=e.status.replace(/_/g,"-"),o=e.status===O.hitl&&s&&a,c=n.jsxs("div",{className:"agent-workspace__task-row",children:[n.jsx(g.Icon,{name:i.icon,size:16,color:i.color,screenReaderText:`${i.label}:`}),n.jsxs("div",{className:"agent-workspace__task-content",children:[n.jsx("span",{className:"agent-workspace__task-label",children:e.task}),e.status!==O.complete&&e.description&&n.jsx("span",{className:"agent-workspace__task-description",children:e.description})]})]});return n.jsxs("li",{className:G("agent-workspace__task",`agent-workspace__task--${l}`,{"agent-workspace__task--child":t>0}),children:[o?n.jsx("button",{type:"button",className:"agent-workspace__task-button","aria-label":`Provide input for ${e.task}`,onClick:()=>a(e),children:c}):c,e.children&&e.children.length>0&&n.jsx("ul",{className:"agent-workspace__task-children",children:e.children.map(d=>n.jsx(ot,{item:d,depth:t+1,canRequestInput:s,onAttentionItemClick:a},d.task))})]})},Ye=({items:e,ariaLabel:t,canRequestInput:s,onAttentionItemClick:a})=>n.jsx("ul",{className:"agent-workspace__task-list","aria-label":t,children:e.map(i=>n.jsx(ot,{item:i,depth:0,canRequestInput:s,onAttentionItemClick:a},i.task))}),Kt=({checklist:e,isLoading:t,error:s,phase:a,canRequestInput:i,onStop:l,onAttentionItemClick:o})=>{const c=r.useMemo(()=>e?rt(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(g.Heading,{level:4,children:"Checklist"}),a===E.running&&n.jsx(g.Button,{variant:"secondary-destructive",size:"S",iconLeftName:"circle-x",iconLeftScreenReaderText:"Stop",onClick:l,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(g.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:ae}),n.jsx("span",{children:ae})]}),!t&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!t&&!s&&c&&n.jsxs(n.Fragment,{children:[c.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(Ye,{items:c.needsInput,ariaLabel:"Tasks needing your input",canRequestInput:i,onAttentionItemClick:o})]}),c.tasks.length>0&&n.jsxs("div",{className:G("agent-workspace__task-group",{"agent-workspace__task-group--following":c.needsInput.length>0}),children:[c.needsInput.length>0&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"Other tasks"}),n.jsx(Ye,{items:c.tasks,ariaLabel:"Agent tasks",canRequestInput:i,onAttentionItemClick:o})]})]}),!t&&!s&&(!c||c.needsInput.length===0&&c.tasks.length===0)&&n.jsx("p",{className:"agent-workspace__empty",children:a===E.briefing?"Tasks will appear here once the agent starts.":"No tasks to display."})]})]})},Wt={[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)"}},Jt=({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(g.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(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…"})]}),!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 i=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(g.Icon,{name:i.icon,size:16,color:i.color,screenReaderText:`${i.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:i.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}`)})}),!t&&!s&&e.length===0&&n.jsx("p",{className:"agent-workspace__empty",children:"No resources yet."})]})]}),Ie=e=>{const t=Date.parse(e);return Number.isFinite(t)?t:0},Vt=new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"2-digit"}),$e=e=>{const t=new Date(e);return Number.isFinite(t.getTime())?Vt.format(t):e},Ce=e=>e.replace(/[A-Za-z0-9]+(?:[_-][A-Za-z0-9]+)+/g,t=>t.split(/[_-]/).map(s=>s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()).join(" ")),he=(e,t)=>t<=1?0:e/(t-1)*100,ct=e=>Math.max(e,0)+2,Yt=e=>e+1,Xt=(e,t)=>{if(t.length===0)return 50;const s=ct(t.length),a=he(1,s),i=he(t.length,s),l=t.map(h=>Ie(h.timestamp)),o=Math.min(...l),c=Math.max(...l);if(c<=o)return a;const d=(Ie(e.timestamp)-o)/(c-o),f=Math.min(1,Math.max(0,d));return a+f*(i-a)},Qt=8,Zt=20,en=(e,t=Qt,s=Zt)=>{const a=new Map;if(e.length===0)return a;const i=[...e].sort((o,c)=>o.leftPercent-c.leftPercent||o.timestampMs-c.timestampMs||o.id.localeCompare(c.id)),l=[];for(const o of i){const c=l[l.length-1];c&&o.leftPercent-c[c.length-1].leftPercent<t?c.push(o):l.push([o])}for(const o of l){const c=[...o].sort((f,h)=>f.timestampMs-h.timestampMs||f.id.localeCompare(h.id)),d=(c.length-1)/2;c.forEach((f,h)=>{a.set(f.id,(h-d)*s)})}return a},be=(e,t=0)=>({left:`calc(${e/100} * (100% - var(--agent-timeline-node-size)) + (var(--agent-timeline-node-size) / 2) + ${t}px)`,transform:"translateX(-50%)"}),tn=e=>e.type!=="message-sent",nn=({timeline:e,isLoading:t,error:s,onOpenChatSession:a})=>{const i=((e==null?void 0:e.actionLog)??[]).filter(tn),l=(e==null?void 0:e.chatSessions)??[],o=!t&&!s&&i.length===0&&l.length===0,c=ct(i.length),d=i.map((u,w)=>({id:`action-${u.timestamp}-${w}`,leftPercent:he(Yt(w),c),timestampMs:Ie(u.timestamp)})),f=l.map(u=>({id:u.sessionId,leftPercent:Xt(u,i),timestampMs:Ie(u.timestamp)})),h=en([...d,...f]);return n.jsxs("section",{className:"agent-workspace__timeline","aria-label":"Agent timeline",children:[t&&n.jsx("p",{className:"agent-workspace__timeline-status",role:"status",children:"Loading timeline…"}),s&&n.jsx("p",{className:"agent-workspace__timeline-status",role:"alert",children:s||at}),o&&n.jsx("p",{className:"agent-workspace__timeline-status",role:"status",children:"No timeline activity yet."}),!t&&!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,c)),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"})]}),i.map((u,w)=>{const m=`action-${u.timestamp}-${w}`,S=d[w].leftPercent,y=u.type==="checklist-updated",T=u.type==="status-transition",D=y?"checklist":T?"status":"note";return n.jsxs("div",{className:`agent-timeline__station agent-timeline__station--${D}`,style:be(S,h.get(m)??0),children:[n.jsxs("button",{type:"button",className:`agent-timeline__station-node agent-timeline__station-node--${D}`,"aria-label":`${Ce(u.type)}: ${Ce(u.entry)}`,children:[y&&n.jsx(g.Icon,{name:"check-solid",size:16,color:"currentColor"}),T&&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(u.type)}),n.jsx("span",{className:"agent-timeline__pill-entry",children:Ce(u.entry)}),n.jsx("span",{className:"agent-timeline__pill-entry",children:$e(u.timestamp)})]})]},m)}),n.jsxs("div",{className:"agent-timeline__station agent-timeline__station--terminus",style:be(he(c-1,c)),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"})]}),l.map((u,w)=>{const m=f[w].leftPercent;return n.jsxs("div",{className:"agent-timeline__chat-station",style:be(m,h.get(u.sessionId)??0),children:[n.jsx("button",{type:"button",className:"agent-timeline__chat-node","aria-label":`Open chat session from ${$e(u.timestamp)}`,onClick:()=>a(u.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:$e(u.timestamp)})]})]},u.sessionId)})]})]})},sn=["I'll get the details and come back to you","Skip this for now"],an=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:X.agent,text:t,followUpPrompts:e.clarificationPrompts??sn}},pe=e=>({id:e.id,text:e.text,type:e.author===X.user?oe.CHAT_RESPONSE_TYPE_USER:e.author===X.system?oe.CHAT_RESPONSE_TYPE_INFO:oe.CHAT_RESPONSE_TYPE_AGENT,...e.followUpPrompts?{followUpPrompts:e.followUpPrompts}:{}});class ie extends Error{constructor(t,s,a){super(a??`Agent service request failed (${t})`),this.name="AgentServiceError",this.status=t,this.detail=s}}const rn="/api/v1",U={agentDefinitions:"/agent-definitions",agents:"/agents",conversations:"/conversations",tripOptions:"/trip-options",demoDataset:"/demo/dataset"},B={GET:"GET",POST:"POST"},on={error:"error"},cn={user:"user"},re={acceptJson:"application/json",acceptEventStream:"text/event-stream",contentTypeJson:"application/json",arborApplicationUrl:"X-Arbor-Application-Url"},ln=/:invocationId\b/g,dn=e=>e.trim().replace(/^Bearer\s+/i,""),gn=e=>e.endsWith("/")?e.slice(0,-1):e;class Re{constructor(t){var a;this.baseUrl=gn(t.baseUrl??"");const s=(a=t.token)==null?void 0:a.trim();this.token=s?dn(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(B.GET,this.resolveUrl("agentDefinitions",U.agentDefinitions))).agent_definitions??[]}getAgentDefinition(t){return this.request(B.GET,this.apiUrl(`${U.agentDefinitions}/${encodeURIComponent(t)}`))}listTripOptions(){return this.request(B.GET,this.apiUrl(U.tripOptions))}getDataset(){return this.request(B.GET,this.apiUrl(U.demoDataset))}setDataset(t){return this.request(B.POST,this.apiUrl(U.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(B.GET,`${this.resolveUrl("agents",U.agents)}${a}`)}createAgent(t,s={}){var o,c;const a={agent_definition_ref:t},i=(o=s.invocationName)==null?void 0:o.trim(),l=(c=s.agentIntent)==null?void 0:c.trim();return i&&(a.invocation_name=i),l&&(a.agent_intent=l),this.request(B.POST,this.resolveUrl("agents",U.agents),a)}getAgent(t){return this.request(B.GET,this.resolveUrl("agent",`${U.agents}/${encodeURIComponent(t)}`,t))}getAgentChecklist(t){return this.request(B.GET,this.resolveUrl("agentChecklist",`${U.agents}/${encodeURIComponent(t)}/checklist`,t))}getAgentResources(t){return this.request(B.GET,this.resolveUrl("agentResources",`${U.agents}/${encodeURIComponent(t)}/resources`,t))}getAgentTimeline(t){return this.request(B.GET,this.resolveUrl("agentTimeline",`${U.agents}/${encodeURIComponent(t)}/agent-timeline`,t))}getAgentContext(t){return this.request(B.GET,this.apiUrl(`${U.agents}/${encodeURIComponent(t)}/context`))}cancelAgent(t){return this.request(B.POST,this.apiUrl(`${U.agents}/${encodeURIComponent(t)}/cancel`))}archiveAgent(t){return this.request(B.POST,this.apiUrl(`${U.agents}/${encodeURIComponent(t)}/archive`))}getConversation(t){return this.request(B.GET,this.resolveUrl("agentConversation",`${U.conversations}/${encodeURIComponent(t)}`,t))}async chat(t,s,a={}){const i=!!(a.uploadFiles&&a.uploadFiles.length>0),l=await this.fetchImpl(this.resolveUrl("agentChat",`${U.agents}/${encodeURIComponent(t)}/chat`,t),{method:B.POST,headers:{...this.customHeaders,...this.authHeaders(),Accept:re.acceptEventStream,...i?{}:{"Content-Type":re.contentTypeJson}},body:i?pn(s,a.uploadFiles??[]):JSON.stringify(s),signal:a.signal});if(!l.ok)throw await this.toError(l);if(!l.body)throw new ie(l.status,null,"Chat response contained no stream body");return this.consumeSse(l.body,a.onEvent)}authHeaders(){return this.token?{Authorization:`Bearer ${this.token}`}:{}}apiUrl(t){return`${this.baseUrl}${rn}${t}`}resolveUrl(t,s,a){const i=this.urls[t];return i?a?i.replace(ln,encodeURIComponent(a)):i:this.apiUrl(s)}async request(t,s,a){const i=await this.fetchImpl(s,{method:t,headers:{...this.customHeaders,...this.authHeaders(),Accept:re.acceptJson,...a===void 0?{}:{"Content-Type":re.contentTypeJson}},...a===void 0?{}:{body:JSON.stringify(a)}});if(!i.ok)throw await this.toError(i);if(i.status!==204)return await i.json()}async toError(t){let s=null;try{s=await t.json()}catch{}return new ie(t.status,s,`Agent service request failed (${t.status} ${t.statusText})`)}async consumeSse(t,s){const a=t.getReader(),i=new TextDecoder;let l="",o;const c=d=>{const{event:f,data:h}=un(d);if(h===null)return;if(f===on.error){const w=Xe(h);throw new ie(502,w,(w==null?void 0:w.message)??"Chat stream error")}const u=Xe(h);u&&(o=u,s==null||s(u))};for(;;){const{done:d,value:f}=await a.read();if(d)break;l+=i.decode(f,{stream:!0});const h=l.split(`
2
2
 
3
- `);c=p.pop()??"";for(const _ of p)d(_)}if(c.trim()&&d(c),!l)throw new te(502,null,"Chat stream ended without any events");return l}}const Et=e=>{let t=null;const s=[];for(const a of e.split(`
4
- `)){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}};function Tt(e,t){const s=new FormData;s.append("body",JSON.stringify(e));for(const a of t)s.append("files",a,a.name);return s}const It={id:De,author:B.agent,text:"I'm connected to this agent. Ask me how it's progressing, or send an instruction and I’ll act on it."};let Pe=0;const Me=e=>(Pe+=1,`${e}-${Date.now()}-${Pe}`),Rt=e=>{const t=e.destination?` to ${e.destination}`:"";return`Let's get started on ${e.tripName.trim()||e.destination.trim()||"this task"}${t}. What will you do first?`};class Be{constructor(t,s,a={}){this.seededChecklist=[],this.client=t,this.agentId=s,this.opening=a.openingMessage??It,this.model=a.model,this.bootstrapPrompt=a.bootstrapPrompt??rt}openingMessage(){return this.opening}async bootstrapConversation(t=this.bootstrapPrompt){const s=t.trim();if(!s)return[this.opening];const a={id:Me("msg-user"),author:B.user,text:s},r=await this.exchange(s);return[a,r.message]}async start(t){return{...await this.exchange(Rt(t)),phase:N.running}}sendMessage(t,s){return this.exchange(t,s)}async stop(){}seedChecklist(t){this.seededChecklist=t}async exchange(t,s){var l;const a=[{role:Nt.user,content:t}],r=await this.client.chat(this.agentId,{messages:a,...this.chatId?{chat_id:this.chatId}:{},...this.model?{model:this.model}:{},moderation_enabled:!0,meta:{feature_id:"agent_view",source:"agent_view_frontend"}},...s&&s.length>0?[{uploadFiles:s}]:[]);return this.chatId=r.chat_id,{message:{id:r.event_id||Me("msg-agent"),author:B.agent,text:r.message.content,...(l=r.follow_up_prompts)!=null&&l.length?{followUpPrompts:r.follow_up_prompts}:{}}}}}const je=(e,t)=>s=>{var a;return new Be(e,s.invocation_id,{model:t==null?void 0:t.model,bootstrapPrompt:t==null?void 0:t.bootstrapPrompt,openingMessage:((a=t==null?void 0:t.resolveOpeningMessage)==null?void 0:a.call(t,s))??(t==null?void 0:t.openingMessage)})},Ge=e=>{switch(e){case Te.cancelled:return v.failed;case Te.archived:return v.complete;case v.hitl:case v.complete:case v.failed:case v["generating-a-response"]:return e;default:return v["generating-a-response"]}},qe=e=>{switch(e){case ke.requires_attention:return S.hitl;case ke.in_progress:case ke.available:return S["generating-a-response"];case S.failed:case S.complete:case S.hitl:case S["generating-a-response"]:return e;default:return S["generating-a-response"]}},Ke=e=>({ref:e.name,display_name:e.display_name,agent_intent:e.agent_intent??e.display_name,description:e.description}),Ot=e=>({id:e.id,name:e.name,...e.has_run_before?{hasRunBefore:e.has_run_before}:{}}),Pt=new Set(Object.values(Z)),Mt=e=>e&&Pt.has(e)?e:Z.LINK,ze=e=>({uri:e.uri??"",type:Mt(e.type),name:e.name??"",description:e.description??""}),Ce=e=>(Array.isArray(e)?e:e.resources??[]).map(ze),ye=e=>{var s;const t=e.invocation_id??e.id;return{id:e.id,invocation_id:t,agent_definition_ref:e.agent_definition_ref,...e.agent_intent?{agent_intent:e.agent_intent}:{},invocation_name:((s=e.invocation_name)==null?void 0:s.trim())||e.agent_definition_ref,application_id:e.application_id,...e.application_name?{application_name:e.application_name}:{},created_by:e.created_by,status:Ge(e.status),context_ref:e.context_ref??null,checklist_ref:e.checklist_ref??null}},be=e=>{var t;return{task:e.task??e.name??e.label??at,status:qe(e.status),description:e.description??"",...e.prompt?{prompt:e.prompt}:{},...(t=e.follow_up_prompts)!=null&&t.length?{clarificationPrompts:e.follow_up_prompts}:{}}},Lt=e=>Array.isArray(e)?e:e.checklist_items??e.checklist??e.items??[],Ee=(e,t,s)=>{var c;const a=!Array.isArray(t)&&(t.opening_message||(c=t.opening_follow_up_prompts)!=null&&c.length)?t:s,r=a?le(a):void 0;return{invocation_id:e,checklist:Lt(t).map(be),...r?{openingMessage:r}:{}}},Ut=(e,t)=>{const s=le(t);return{invocation_id:t.invocation_id??e,checklist:(t.checklist_items??[]).map(be),...s?{openingMessage:s}:{}}},le=e=>{var s,a;const t=(s=e.opening_message)==null?void 0:s.trim();if(t)return{id:De,author:B.agent,text:t,...(a=e.opening_follow_up_prompts)!=null&&a.length?{followUpPrompts:e.opening_follow_up_prompts}:{}}},Dt=e=>e instanceof te?e.message:e instanceof TypeError?"Network error while contacting the agent service.":e instanceof Error&&e.message?e.message:$e,$t=e=>{const t={};for(const s of e){const a=le(s);if(!a)continue;const r=s.invocation_id??s.id;t[r]=a,t[s.id]=a}return t},Ht=e=>JSON.stringify(e),We=e=>{const{jwt:t,headers:s,urls:a}=e,r=JSON.stringify(s??{}),c=Ht(a),l=i.useMemo(()=>new Ne({token:t,headers:s,urls:a}),[t,c]);i.useLayoutEffect(()=>{l.setHeaders(s)},[l,r]);const[d,w]=i.useState([]),[f,p]=i.useState([]),[_,h]=i.useState({}),[j,b]=i.useState("loading"),[k,y]=i.useState(null),[x,O]=i.useState(0);i.useEffect(()=>{let A=!1;return b("loading"),y(null),(async()=>{try{const[C,M]=await Promise.all([l.listAgents(),l.listAgentDefinitions()]);if(A)return;w(C.map(ye)),p(M.map(Ke)),h($t(C)),b("idle")}catch(C){if(A)return;w([]),p([]),h({}),b("error"),y(Dt(C))}})(),()=>{A=!0}},[l,x]);const G=i.useCallback(()=>{O(A=>A+1)},[]),P=i.useCallback(async A=>{const[C,M]=await Promise.all([l.getAgentChecklist(A),l.getAgent(A).catch(()=>null)]);return Ee(A,C,M??void 0)},[l]),J=i.useCallback(async A=>{const C=await l.getAgentResources(A);return Ce(C)},[l]),V=i.useCallback(async({definition:A,invocationName:C})=>{const M=await l.createAgent(A.ref,{invocationName:C}),K=await l.getAgent(M.id),I=ye(K),D=le(K);return w($=>[I,...$]),D&&h($=>({...$,[I.invocation_id]:D,[I.id]:D})),I},[l]),q=i.useMemo(()=>je(l,{resolveOpeningMessage:A=>_[A.invocation_id]??_[A.id]}),[l,_]);return{agents:d,agentDefinitions:f,loadState:j,loadError:k,reload:G,fetchAgentChecklist:P,fetchAgentResources:J,createAgent:V,chatConnector:q}},Ft=e=>JSON.stringify(e),Je=e=>{const{agent:t,jwt:s,headers:a,urls:r}=e,c=JSON.stringify(a??{}),l=Ft(r),d=i.useMemo(()=>new Ne({token:s,headers:a,urls:{agent:r.agentUrl,agentChecklist:r.agentChecklistUrl,...r.agentResourcesUrl?{agentResources:r.agentResourcesUrl}:{},agentChat:r.agentChatUrl}}),[s,l]);i.useLayoutEffect(()=>{d.setHeaders(a)},[d,c]);const w=i.useCallback(async _=>{const[h,j]=await Promise.all([d.getAgentChecklist(_),d.getAgent(_).catch(()=>null)]);return Ee(_,h,j??void 0)},[d]),f=i.useCallback(async _=>{const h=await d.getAgentResources(_);return Ce(h)},[d]);return{connector:i.useMemo(()=>je(d)(t),[d,t]),fetchAgentChecklist:w,fetchAgentResources:f}},Bt=(e,t)=>{const s=e.hasRunBefore?t||"This trip":e.tripName.trim()||"A new trip",a=e.destination?` to ${e.destination}`:"",r=e.hasRunBefore?" It has run before.":"";return`${s}${a}.${r}`.trim()},Gt=e=>{switch(e){case v.failed:return N.stopped;case v.complete:return N.complete;default:return N.running}},Le=(e,t)=>{t([ce(e)])},Ve=({agent:e,open:t,onClose:s,jwt:a,headers:r,agentUrl:c,agentChecklistUrl:l,agentResourcesUrl:d,agentChatUrl:w,enableUpload:f,initialBrief:p,initialPhase:_,initialChecklist:h})=>{const{connector:j,fetchAgentChecklist:b,fetchAgentResources:k}=Je({agent:e,jwt:a,headers:r,urls:{agentUrl:c,agentChecklistUrl:l,agentResourcesUrl:d,agentChatUrl:w}}),y=i.useRef(j),[x,O]=i.useState(_??(p?N.running:Gt(e.status))),[G,P]=i.useState([]),[J,V]=i.useState(0),[q,A]=i.useState(),[C,M]=i.useState(null),[K,I]=i.useState([]),[D,$]=i.useState(!1),[ae,z]=i.useState(null),[he,H]=i.useState(h??null),[me,re]=i.useState(!1),[W,oe]=i.useState(null),[de,Y]=i.useState(!1),[Q,_e]=i.useState(!1),[X,fe]=i.useState(!1),F=i.useRef(!1);i.useEffect(()=>{y.current=j},[j]),i.useEffect(()=>{F.current=!1,P([]),V(o=>o+1)},[e.invocation_id]),i.useEffect(()=>{if(!t||p||F.current)return;const o=y.current.bootstrapConversation;if(!o){Le(y.current.openingMessage(),P);return}F.current=!0;let g=!1;return Y(!0),(async()=>{try{const m=await o.call(y.current);if(g)return;P(m.map(ce))}catch{g||Le(y.current.openingMessage(),P)}finally{g||Y(!1)}})(),()=>{g=!0}},[t,p,e.invocation_id,j]);const ve=i.useCallback(o=>{o.checklist&&H(o.checklist),o.phase&&O(o.phase)},[]);i.useEffect(()=>{var o,g;!t||p||h&&h.length>0&&((g=(o=y.current).seedChecklist)==null||g.call(o,h))},[t,p,h]),i.useEffect(()=>{if(!t||p)return;let o=!1;return re(!(h!=null&&h.length)),oe(null),(async()=>{var g,m;try{const R=await b(e.invocation_id);if(o)return;h!=null&&h.length||(H(R.checklist),(m=(g=y.current).seedChecklist)==null||m.call(g,R.checklist))}catch{!o&&!(h!=null&&h.length)&&oe(Ae)}finally{o||re(!1)}})(),()=>{o=!0}},[t,e.invocation_id,p,h,b]),i.useEffect(()=>{if(!t||!d)return;let o=!1;return $(!0),z(null),(async()=>{try{const g=await k(e.invocation_id);o||I(g)}catch{o||z(nt)}finally{o||$(!1)}})(),()=>{o=!0}},[t,e.invocation_id,d,k]),i.useEffect(()=>{if(!t||!p||F.current)return;F.current=!0;const o={id:`user-brief-${Date.now()}`,author:B.user,text:Bt(p,e.invocation_name)};(async()=>{const g=await y.current.start(p);P([ce(y.current.openingMessage()),ce(o),ce(g.message)]),g.checklist&&H(g.checklist),O(g.phase??N.running)})()},[t,p,e.invocation_name]);const we=i.useCallback(o=>{M(At(o))},[]),xe=i.useCallback(o=>{M(null),A(o),V(g=>g+1)},[]),ge=i.useCallback(async()=>{await y.current.stop(),O(N.stopped)},[]),ue=he;return n.jsxs(u.Modal,{open:t,closeHandler:s,hideCloseButton:!0,className:"agent-workspace",children:[n.jsxs(u.Modal.Header,{className:"agent-workspace__header",children:[n.jsxs("div",{className:"agent-workspace__header-title",children:[n.jsx("span",{className:"agent-workspace__header-avatar","aria-hidden":"true",children:n.jsx(u.Icon,{name:"ask-arbor",size:24})}),n.jsx(u.Modal.Title,{children:e.invocation_name}),n.jsx("span",{className:L("agent-workspace__phase",`agent-workspace__phase--${x}`),children:ot[x]})]}),n.jsxs("div",{className:"agent-workspace__header-actions",children:[n.jsx(u.Button,{variant:"tertiary",size:"S",iconLeftName:"clipboard-list",iconLeftScreenReaderText:"Toggle checklist","aria-pressed":!X,onClick:()=>fe(o=>!o),children:"Checklist"}),n.jsx(u.Button,{variant:"tertiary",size:"S",iconLeftName:"files",iconLeftScreenReaderText:"Toggle resources","aria-pressed":!Q,onClick:()=>_e(o=>!o),children:"Resources"}),n.jsx(u.Button,{variant:"secondary",size:"S",iconLeftName:"x",iconLeftScreenReaderText:"Close",onClick:s,children:"Close"})]})]}),n.jsxs(u.Modal.Body,{className:L("agent-workspace__body",{"agent-workspace__body--no-left":X,"agent-workspace__body--no-right":Q}),children:[!X&&n.jsx(vt,{checklist:ue,isLoading:me,error:W,phase:x,canRequestInput:x===N.running&&!de,onStop:()=>void ge(),onAttentionItemClick:we}),n.jsx(ft,{connector:y.current,phase:x,chatHistory:G,chatSessionKey:J,startQuery:q,clarificationMessage:C,enableUpload:f,onTurn:ve,onAwaitingChange:Y,onClarificationPrompt:xe,onDismissClarification:()=>M(null)}),!Q&&n.jsx(xt,{resources:K,isLoading:D,error:ae})]})]})},Ye=({open:e,onClose:t,onStart:s,agentDefinitions:a})=>{const r=a[0],[c,l]=i.useState(r),[d,w]=i.useState(""),[f,p]=i.useState(!1),[_,h]=i.useState(null),j=[...a].sort((x,O)=>x.agent_intent.localeCompare(O.agent_intent)).map(x=>({value:x.ref,label:x.agent_intent}));i.useEffect(()=>{e&&(l(r),w(""),p(!1),h(null))},[e,r]);const b=c!==void 0&&d.trim().length>0,k=i.useCallback(x=>{const O=a.find(G=>G.ref===x[0]);O&&l(O)},[a]),y=i.useCallback(async()=>{if(!(!c||!b||f)){p(!0),h(null);try{await s({definition:c,invocationName:d.trim()})}catch(x){h(x instanceof Error?x.message:"Unable to start the agent.")}finally{p(!1)}}},[b,c,d,f,s]);return!c||a.length===0?null:n.jsxs(u.Modal,{open:e,closeHandler:t,className:"new-agent",children:[n.jsx(u.Modal.Header,{className:"new-agent__header",children:n.jsxs("div",{className:"new-agent__header-title",children:[n.jsx("span",{className:"new-agent__header-avatar","aria-hidden":"true",children:n.jsx(u.Icon,{name:"ask-arbor",size:24})}),n.jsx(u.Modal.Title,{children:"Start an agent"})]})}),n.jsx(u.Modal.Body,{className:"new-agent__body",children:n.jsxs("form",{className:"new-agent__form","aria-label":"Start an agent",onSubmit:x=>{x.preventDefault(),b&&!f&&y()},children:[n.jsxs("div",{className:"new-agent__type-field",children:[n.jsx("label",{className:"new-agent__type-label",htmlFor:"new-agent-type",children:"What would you like your agent to do?"}),n.jsx(u.SelectDropdown,{id:"new-agent-type",placeholder:"Choose an intent",options:j,selectedValues:[c.ref],onSelectionChange:k}),n.jsx("p",{className:"new-agent__type-description",children:c.description})]}),n.jsxs("div",{className:"new-agent__type-field",children:[n.jsx("label",{className:"new-agent__type-label",htmlFor:"new-agent-invocation-name",children:"Name"}),n.jsx(u.TextInput,{id:"new-agent-invocation-name",value:d,placeholder:"e.g. Test with memory3",onChange:x=>w(x.target.value)})]}),_?n.jsx("p",{className:"new-agent__error",role:"alert",children:_}):null,n.jsx("div",{className:"new-agent__actions",children:n.jsx(u.Button,{type:"submit",variant:"primary",disabled:!b||f,iconLeftName:f?"loader":"sparkles",iconLeftScreenReaderText:f?"Starting":void 0,children:f?"Starting…":"Start"})})]})})]})},qt=e=>e!==void 0&&e.some(t=>t.status===S.hitl),Kt=(e,t)=>qt(t)?v.hitl:e.status,zt=({column:e,label:t})=>e.statusIcon?n.jsx("span",{className:"agent-view__status-indicator",children:n.jsx(u.Icon,{name:e.statusIcon.name,size:16,color:e.statusIcon.color,className:L({"agent-view__progress-icon--spinning":e.statusIcon.spin}),screenReaderText:t})}):n.jsx("span",{className:L("agent-view__dot",{[`agent-view__dot--${e.dotModifier}`]:e.dotModifier}),children:n.jsx(u.Dot,{colour:e.dotColour,label:t})}),Wt=({agent:e,agentName:t,column:s,isExpanded:a,isLoading:r,checklist:c,error:l,onToggle:d,onViewAgent:w})=>{const{id:f,invocation_name:p}=e,_=`agent-card-${f}-header`,h=`agent-card-${f}-progress`;return n.jsx("li",{className:L("agent-view__card",{"agent-view__card--expanded":a}),children:n.jsxs(u.Card,{spacing:"dense",children:[n.jsx("button",{type:"button",className:"agent-view__card-toggle","aria-expanded":a,"aria-controls":h,"aria-label":p,id:_,onClick:()=>d(f),children:n.jsxs("div",{className:"agent-view__card-content",children:[n.jsx(zt,{column:s}),n.jsx("span",{className:"agent-view__card-invocation-name",children:p}),n.jsx("span",{className:"agent-view__card-agent-name",children:t}),n.jsx(u.Icon,{name:a?"chevron-up":"chevron-down",size:16,className:"agent-view__card-chevron"})]})}),a&&n.jsxs("div",{id:h,"aria-labelledby":_,className:"agent-view__card-progress",children:[r&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:ee}),n.jsx("span",{children:ee})]}),!r&&l&&n.jsx("p",{className:"agent-view__progress-error",role:"alert",children:l}),!r&&!l&&c!==null&&n.jsx(ht,{checklist:c}),!r&&!l&&c===null&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:ee}),n.jsx("span",{children:ee})]}),n.jsx("div",{className:"agent-view__card-actions",children:n.jsx(u.Button,{variant:"secondary",size:"S",onClick:()=>w==null?void 0:w(e),children:"View agent"})})]})]})})},Ue=({column:e,agents:t,expandedAgentId:s,loadingAgentId:a,checklistByInvocationId:r,errorByAgentId:c,definitionNameByRef:l,onToggleAgent:d,onViewAgent:w,isSplit:f=!1})=>n.jsxs("section",{className:L("agent-view__column",{"agent-view__column--split":f}),"aria-label":e.title,children:[n.jsxs("div",{className:"agent-view__column-header",children:[n.jsx(u.Heading,{level:4,children:e.title}),n.jsx("span",{className:"agent-view__column-count",children:t.length})]}),n.jsx("ul",{className:"agent-view__card-list",children:t.map(p=>n.jsx(Wt,{agent:p,agentName:Se(p,l),column:e,isExpanded:s===p.id,isLoading:a===p.id,checklist:r[p.invocation_id]??null,error:c[p.id]??null,onToggle:d,onViewAgent:w},p.id))})]}),Se=(e,t)=>t.get(e.agent_definition_ref)??e.agent_definition_ref.replace(/_/g," "),Jt=({jwt:e,headers:t,agentDefinitionsUrl:s,agentsUrl:a,agentUrl:r,agentChecklistUrl:c,agentResourcesUrl:l,agentChatUrl:d,enableUpload:w,institutions:f})=>{var ue;const p=i.useMemo(()=>({agentDefinitions:s,agents:a,agent:r,agentChecklist:c,...l?{agentResources:l}:{},agentChat:d}),[s,a,r,c,l,d]),[_,h]=i.useState(null),j=_?(ue=f==null?void 0:f.find(o=>o.applicationId===_.application_id))==null?void 0:ue.applicationUrl:void 0,b=i.useMemo(()=>{const o={...t??{}};return j?o[ne.arborApplicationUrl]=j:delete o[ne.arborApplicationUrl],o},[t,j]),{agents:k,agentDefinitions:y,loadState:x,loadError:O,reload:G,fetchAgentChecklist:P,createAgent:J}=We({jwt:e,headers:b,urls:p}),[V,q]=i.useState(!1),[A,C]=i.useState(null),[M,K]=i.useState(null),[I,D]=i.useState({}),[$,ae]=i.useState({}),[z,he]=i.useState([]),[H,me]=i.useState([]),re=i.useMemo(()=>{const o=new Set(k.map(m=>m.application_id)),g=new Map((f??[]).map(m=>[m.applicationId,m.name]));return[...o].sort((m,R)=>(g.get(m)??m).localeCompare(g.get(R)??R)).map(m=>({value:m,label:g.get(m)??m}))},[k,f]),W=i.useMemo(()=>new Map(y.map(o=>[o.ref,o.display_name])),[y]),oe=i.useMemo(()=>[...new Set(k.map(g=>Se(g,W)))].sort((g,m)=>g.localeCompare(m)).map(g=>({value:g,label:g})),[k,W]),de=i.useMemo(()=>k.filter(o=>!(z.length>0&&!z.includes(o.application_id)||H.length>0&&!H.includes(Se(o,W)))),[k,W,H,z]),Y=re.length>1,Q=oe.length>1,_e=Y||Q;i.useEffect(()=>{if(k.length===0)return;let o=!1;return(async()=>{const g=await Promise.allSettled(k.map(async m=>{const R=await P(m.invocation_id);return{agentId:m.id,invocationId:m.invocation_id,checklist:R.checklist}}));o||(D(m=>{const R={...m};for(const ie of g)ie.status==="fulfilled"&&(R[ie.value.invocationId]=ie.value.checklist);return R}),ae(m=>{const R={...m};return g.forEach((ie,Qe)=>{ie.status==="rejected"&&(R[k[Qe].id]=Ae)}),R}))})(),()=>{o=!0}},[k,P]);const X=i.useCallback(async o=>{if(!I[o.invocation_id]){K(o.id),ae(g=>{const m={...g};return delete m[o.id],m});try{const g=await P(o.invocation_id);D(m=>({...m,[o.invocation_id]:g.checklist}))}catch{ae(g=>({...g,[o.id]:Ae}))}finally{K(g=>g===o.id?null:g)}}},[P,I]),fe=i.useCallback(o=>{if(A===o){C(null);return}const g=k.find(({id:m})=>m===o);g&&(C(o),X(g))},[k,A,X]),F=i.useMemo(()=>{const o={};for(const g of de){const m=Kt(g,I[g.invocation_id]);(o[m]??(o[m]=[])).push(g)}return o},[de,I]),ve=i.useCallback(o=>{h(o)},[]),we=i.useCallback(async o=>{const g=await J(o);h(g),q(!1)},[J]),xe=i.useCallback(()=>{h(null)},[]),ge={expandedAgentId:A,loadingAgentId:M,checklistByInvocationId:I,errorByAgentId:$,definitionNameByRef:W,onToggleAgent:fe,onViewAgent:ve};return n.jsxs("div",{className:"agent-view-frontend agent-view",children:[n.jsxs("div",{className:"agent-view__header",children:[n.jsx(u.Heading,{level:1,children:"Agents"}),n.jsx(u.Button,{variant:"primary",size:"S",iconLeftName:"sparkles",iconLeftScreenReaderText:"Start an agent",onClick:()=>q(!0),children:"Start an agent"})]}),k.length>0&&_e&&n.jsxs("div",{className:"agent-view__filters",children:[Y&&n.jsxs("div",{className:"agent-view__filter",children:[n.jsx("label",{className:"agent-view__filter-label",htmlFor:"agent-view-institution-filter",children:"Institution"}),n.jsx(u.Combobox,{id:"agent-view-institution-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All institutions",options:re,value:z,onValueChange:he,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear institutions"})]}),Q&&n.jsxs("div",{className:"agent-view__filter",children:[n.jsx("label",{className:"agent-view__filter-label",htmlFor:"agent-view-agent-filter",children:"Agent"}),n.jsx(u.Combobox,{id:"agent-view-agent-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All agents",options:oe,value:H,onValueChange:me,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear agents"})]})]}),x==="error"?n.jsxs("div",{className:"agent-view__state agent-view__state--error",role:"alert",children:[n.jsx(u.Icon,{name:"triangle-alert",size:24,color:"var(--color-semantic-destructive-600)"}),n.jsx("p",{className:"agent-view__state-message",children:O??$e}),n.jsx(u.Button,{variant:"secondary",size:"S",onClick:G,children:"Try again"})]}):x==="loading"&&k.length===0?n.jsxs("div",{className:"agent-view__state","aria-live":"polite",children:[n.jsx(u.Icon,{name:"loader",size:24,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:Ie}),n.jsx("p",{className:"agent-view__state-message",children:Ie})]}):k.length===0?n.jsx(gt,{}):n.jsxs("div",{className:"agent-view__board",children:[Xe.map(o=>n.jsx(Ue,{column:pe[o],agents:F[o]??[],...ge},o)),n.jsx("div",{className:"agent-view__split-column",children:Ze.map(o=>n.jsx(Ue,{column:pe[o],agents:F[o]??[],isSplit:!0,...ge},o))})]}),_&&n.jsx(Ve,{agent:_,open:!0,jwt:e,headers:b,agentUrl:r,agentChecklistUrl:c,agentResourcesUrl:l,agentChatUrl:d,enableUpload:w,initialChecklist:I[_.invocation_id]??null,onClose:xe},_.id),n.jsx(Ye,{open:V,onClose:()=>q(!1),onStart:we,agentDefinitions:y})]})},Vt=(e,t)=>{const s=Date.now(),a=t.trim()||e.agent_intent;return{id:`agent-${s}`,invocation_id:`inv-${s}`,agent_definition_ref:e.ref,agent_intent:e.agent_intent,invocation_name:a,application_id:et,created_by:tt,status:v["generating-a-response"],context_ref:null,checklist_ref:null}};exports.AgentMonitorKanban=Jt;exports.AgentServiceClient=Ne;exports.AgentServiceError=te;exports.AgentView=Ve;exports.HttpChatConnector=Be;exports.NewAgentModal=Ye;exports.buildAgentFromDefinition=Vt;exports.createHttpChatConnectorFactory=je;exports.mapApiAgent=ye;exports.mapApiAgentDefinition=Ke;exports.mapApiAgentStatus=Ge;exports.mapApiChecklistEndpointResponse=Ee;exports.mapApiChecklistItem=be;exports.mapApiChecklistResponse=Ut;exports.mapApiChecklistStatus=qe;exports.mapApiOpeningMessage=le;exports.mapApiResource=ze;exports.mapApiResourcesEndpointResponse=Ce;exports.mapApiTripOption=Ot;exports.useAgentService=We;exports.useAgentWorkspace=Je;
3
+ `);l=h.pop()??"";for(const u of h)c(u)}if(l.trim()&&c(l),!o)throw new ie(502,null,"Chat stream ended without any events");return o}}const un=e=>{let t=null;const s=[];for(const a of e.split(`
4
+ `)){const i=a.trimEnd();i.startsWith("event:")?t=i.slice(6).trim():i.startsWith("data:")&&s.push(i.slice(5).trim())}return{event:t,data:s.length>0?s.join(`
5
+ `):null}},Xe=e=>{try{return JSON.parse(e)}catch{return}};function pn(e,t){const s=new FormData;s.append("body",JSON.stringify(e));for(const a of t)s.append("files",a,a.name);return s}const lt=e=>{switch(e){case Je.cancelled:return j.failed;case Je.archived:return j.complete;case j.hitl:case j.complete:case j.failed:case j["generating-a-response"]:return e;default:return j["generating-a-response"]}},dt=e=>{switch(e){case De.requires_attention:return O.hitl;case De.in_progress:case De.available:return O["generating-a-response"];case O.failed:case O.complete:case O.hitl:case O["generating-a-response"]:return e;default:return O["generating-a-response"]}},Fe=e=>({ref:e.name,display_name:e.display_name,agent_intent:e.agent_intent??e.display_name,description:e.description}),hn=e=>({id:e.id,name:e.name,...e.has_run_before?{hasRunBefore:e.has_run_before}:{}}),mn=new Set(Object.values(se)),_n=e=>e&&mn.has(e)?e:se.LINK,gt=e=>({uri:e.uri??"",type:_n(e.type),name:e.name??"",description:e.description??""}),ze=e=>(Array.isArray(e)?e:e.resources??[]).map(gt),ut=e=>({actionLog:(e.action_log??[]).map(t=>({timestamp:t.timestamp,type:t.type,entry:t.entry,origin:t.origin})),chatSessions:(e.chat_sessions??[]).map(t=>({sessionId:t.session_id,timestamp:t.timestamp}))}),Be=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:lt(e.status),context_ref:e.context_ref??null,checklist_ref:e.checklist_ref??null}},Ge=e=>{var t;return{task:e.task??e.name??e.label??Ot,status:dt(e.status),description:e.description??"",...e.prompt?{prompt:e.prompt}:{},...(t=e.follow_up_prompts)!=null&&t.length?{clarificationPrompts:e.follow_up_prompts}:{}}},fn=e=>Array.isArray(e)?e:e.checklist_items??e.checklist??e.items??[],qe=(e,t,s)=>{var l;const a=!Array.isArray(t)&&(t.opening_message||(l=t.opening_follow_up_prompts)!=null&&l.length)?t:s,i=a?me(a):void 0;return{invocation_id:e,checklist:fn(t).map(Ge),...i?{openingMessage:i}:{}}},pt=(e,t)=>{const s=me(t);return{invocation_id:t.invocation_id??e,checklist:(t.checklist_items??[]).map(Ge),...s?{openingMessage:s}:{}}},me=e=>{var s,a;const t=(s=e.opening_message)==null?void 0:s.trim();if(t)return{id:st,author:X.agent,text:t,...(a=e.opening_follow_up_prompts)!=null&&a.length?{followUpPrompts:e.opening_follow_up_prompts}:{}}},ht=e=>e.filter(t=>(t.role==="user"||t.role==="assistant")&&typeof t.content=="string"&&t.content.length>0&&t.message_type!=="tool_request").map(t=>({id:t.message_id,author:t.role==="user"?X.user:X.agent,text:t.content})),vn={id:st,author:X.agent,text:"Type a question or upload a file. You can ask it how it's progressing, or send an instruction and it'll act on it."};let Qe=0;const wn=e=>(Qe+=1,`${e}-${Date.now()}-${Qe}`),xn=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 mt{constructor(t,s,a={}){this.seededChecklist=[],this.client=t,this.agentId=s,this.chatId=a.chatId??s,this.opening=a.openingMessage??vn,this.model=a.model}openingMessage(){return this.opening}async bootstrapConversation(){const t=await this.client.getConversation(this.chatId),s=ht(t.messages);return s.length===0?[this.opening]:s}async start(t){return{...await this.exchange(xn(t)),phase:E.running}}sendMessage(t,s){return this.exchange(t,s)}async stop(){}seedChecklist(t){this.seededChecklist=t}async exchange(t,s){var o;const a=[{role:cn.user,content:t}],i=await this.client.chat(this.agentId,{messages:a,chat_id:this.chatId,...this.model?{model:this.model}:{},moderation_enabled:!0,meta:{feature_id:"agent_view",source:"agent_view_frontend"}},...s&&s.length>0?[{uploadFiles:s}]:[]),l={id:i.event_id||wn("msg-agent"),author:X.agent,text:i.message.content,...(o=i.follow_up_prompts)!=null&&o.length?{followUpPrompts:i.follow_up_prompts}:{}};try{const c=await this.client.getAgent(this.agentId),{checklist:d}=pt(this.agentId,c);return this.seededChecklist=d,{message:l,checklist:d}}catch{return{message:l,...this.seededChecklist.length?{checklist:this.seededChecklist}:{}}}}}const Ke=(e,t)=>s=>{var a,i;return new mt(e,s.invocation_id,{model:t==null?void 0:t.model,chatId:((a=t==null?void 0:t.resolveChatId)==null?void 0:a.call(t,s))??(t==null?void 0:t.chatId)??s.invocation_id,openingMessage:((i=t==null?void 0:t.resolveOpeningMessage)==null?void 0:i.call(t,s))??(t==null?void 0:t.openingMessage)})},_t=e=>e instanceof ie?e.message:e instanceof TypeError?"Network error while contacting the agent service.":e instanceof Error&&e.message?e.message:it,kn=e=>{const t={};for(const s of e){const a=me(s);if(!a)continue;const i=s.invocation_id??s.id;t[i]=a,t[s.id]=a}return t},yn=e=>JSON.stringify(e),Ue=(e,t)=>JSON.stringify(e)===JSON.stringify(t),ft=e=>{const{jwt:t,headers:s,urls:a}=e,i=JSON.stringify(s??{}),l=yn(a),o=r.useMemo(()=>new Re({token:t,headers:s,urls:a}),[t,l]);r.useLayoutEffect(()=>{o.setHeaders(s)},[o,i]);const[c,d]=r.useState([]),[f,h]=r.useState([]),[u,w]=r.useState({}),[m,S]=r.useState("loading"),[y,T]=r.useState(null),[D,N]=r.useState(0),I=r.useCallback((k,C)=>{const $=k.map(Be),K=C.map(Fe),M=kn(k);d(L=>Ue(L,$)?L:$),h(L=>Ue(L,K)?L:K),w(L=>Ue(L,M)?L:M),S("idle"),T(null)},[]);r.useEffect(()=>{let k=!1;return S("loading"),T(null),(async()=>{try{const[C,$]=await Promise.all([o.listAgents(),o.listAgentDefinitions()]);if(k)return;I(C,$)}catch(C){if(k)return;d([]),h([]),w({}),S("error"),T(_t(C))}})(),()=>{k=!0}},[I,o,D]);const q=r.useCallback(()=>{N(k=>k+1)},[]),z=r.useCallback(async()=>{try{const[k,C]=await Promise.all([o.listAgents(),o.listAgentDefinitions()]);I(k,C)}catch{}},[I,o]),P=r.useCallback(async k=>{const[C,$]=await Promise.all([o.getAgentChecklist(k),o.getAgent(k).catch(()=>null)]);return qe(k,C,$??void 0)},[o]),A=r.useCallback(async k=>{const C=await o.getAgentResources(k);return ze(C)},[o]),R=r.useCallback(async({definition:k,invocationName:C})=>{const $=await o.createAgent(k.ref,{invocationName:C}),K=await o.getAgent($.id),M=Be(K),L=me(K);return d(H=>[M,...H]),L&&w(H=>({...H,[M.invocation_id]:L,[M.id]:L})),M},[o]),J=r.useMemo(()=>Ke(o,{resolveOpeningMessage:k=>u[k.invocation_id]??u[k.id]}),[o,u]);return{agents:c,agentDefinitions:f,loadState:m,loadError:y,reload:q,refresh:z,fetchAgentChecklist:P,fetchAgentResources:A,createAgent:R,chatConnector:J}},Nn=e=>JSON.stringify(e),vt=e=>{const{agent:t,jwt:s,headers:a,urls:i,chatId:l}=e,o=JSON.stringify(a??{}),c=Nn(i),d=r.useMemo(()=>new Re({token:s,headers:a,urls:{agent:i.agentUrl,agentChecklist:i.agentChecklistUrl,...i.agentResourcesUrl?{agentResources:i.agentResourcesUrl}:{},...i.agentTimelineUrl?{agentTimeline:i.agentTimelineUrl}:{},agentChat:i.agentChatUrl,agentConversation:i.agentConversationUrl}}),[s,c]);r.useLayoutEffect(()=>{d.setHeaders(a)},[d,o]);const f=r.useCallback(async m=>{const[S,y]=await Promise.all([d.getAgentChecklist(m),d.getAgent(m).catch(()=>null)]);return qe(m,S,y??void 0)},[d]),h=r.useCallback(async m=>{const S=await d.getAgentResources(m);return ze(S)},[d]),u=r.useCallback(async m=>{const S=await d.getAgentTimeline(m);return ut(S)},[d]);return{connector:r.useMemo(()=>Ke(d,{chatId:l??t.invocation_id})(t),[d,t.invocation_id,l]),fetchAgentChecklist:f,fetchAgentResources:h,fetchAgentTimeline:u}},An=(e,t)=>{const s=e.hasRunBefore?t||"This trip":e.tripName.trim()||"A new trip",a=e.destination?` to ${e.destination}`:"",i=e.hasRunBefore?" It has run before.":"";return`${s}${a}.${i}`.trim()},jn=e=>{switch(e){case j.failed:return E.stopped;case j.complete:return E.complete;default:return E.running}},Ze=(e,t)=>{t([pe(e)])},wt=({agent:e,open:t,onClose:s,jwt:a,headers:i,agentUrl:l,agentChecklistUrl:o,agentResourcesUrl:c,agentTimelineUrl:d,agentChatUrl:f,agentConversationUrl:h,chatId:u,enableUpload:w,initialBrief:m,initialPhase:S,initialChecklist:y})=>{const[T,D]=r.useState(u??e.invocation_id),[N,I]=r.useState("chat"),[q,z]=r.useState(!1),{connector:P,fetchAgentChecklist:A,fetchAgentResources:R,fetchAgentTimeline:J}=vt({agent:e,jwt:a,headers:i,chatId:T,urls:{agentUrl:l,agentChecklistUrl:o,agentResourcesUrl:c,agentTimelineUrl:d,agentChatUrl:f,agentConversationUrl:h}}),k=r.useRef(P),[C,$]=r.useState(S??(m?E.running:jn(e.status))),[K,M]=r.useState([]),[L,H]=r.useState(0),[_e,Oe]=r.useState(),[ce,Q]=r.useState(null),[Pe,te]=r.useState([]),[Me,le]=r.useState(!1),[Z,de]=r.useState(null),[fe,ve]=r.useState(null),[we,xe]=r.useState(!1),[ke,ye]=r.useState(null),[Ne,ge]=r.useState(y??null),[Le,Ae]=r.useState(!1),[je,ue]=r.useState(null),[p,x]=r.useState(!1),[v,F]=r.useState(!1),[V,ne]=r.useState(!1);r.useEffect(()=>{k.current=P},[P]),r.useEffect(()=>{D(u??e.invocation_id),I("chat"),z(!1),M([]),H(_=>_+1)},[e.invocation_id,u]),r.useEffect(()=>{if(!t||m)return;const _=k.current.bootstrapConversation;if(!_){Ze(k.current.openingMessage(),M);return}let b=!1;return x(!0),(async()=>{try{const Y=await _.call(k.current);if(b)return;M(Y.map(pe))}catch{b||Ze(k.current.openingMessage(),M)}finally{b||x(!1)}})(),()=>{b=!0}},[t,m,e.invocation_id,T]);const ee=r.useCallback(_=>{_.checklist&&ge(_.checklist),_.phase&&$(_.phase)},[]);r.useEffect(()=>{var _,b;!t||m||y&&y.length>0&&((b=(_=k.current).seedChecklist)==null||b.call(_,y))},[t,m,y]),r.useEffect(()=>{if(!t||m)return;let _=!1;return Ae(!(y!=null&&y.length)),ue(null),(async()=>{var b,Y;try{const We=await A(e.invocation_id);if(_)return;y!=null&&y.length||(ge(We.checklist),(Y=(b=k.current).seedChecklist)==null||Y.call(b,We.checklist))}catch{!_&&!(y!=null&&y.length)&&ue(Te)}finally{_||Ae(!1)}})(),()=>{_=!0}},[t,e.invocation_id,m,y,A]),r.useEffect(()=>{if(!t||!c)return;let _=!1;return le(!0),de(null),(async()=>{try{const b=await R(e.invocation_id);_||te(b)}catch{_||de(It)}finally{_||le(!1)}})(),()=>{_=!0}},[t,e.invocation_id,c,R]),r.useEffect(()=>{if(!t||!d)return;let _=!1;return xe(!0),ye(null),(async()=>{try{const b=await J(e.invocation_id);_||ve(b)}catch{_||ye(at)}finally{_||xe(!1)}})(),()=>{_=!0}},[t,e.invocation_id,d,J]),r.useEffect(()=>{if(!t||!m)return;let _=!1;const b={id:`user-brief-${Date.now()}`,author:X.user,text:An(m,e.invocation_name)};return(async()=>{const Y=await k.current.start(m);_||(M([pe(k.current.openingMessage()),pe(b),pe(Y.message)]),Y.checklist&&ge(Y.checklist),$(Y.phase??E.running))})(),()=>{_=!0}},[t,m,e.invocation_name,e.invocation_id]);const Se=r.useCallback(_=>{Q(an(_))},[]),yt=r.useCallback(_=>{D(_),z(!0),I("chat"),M([]),H(b=>b+1)},[]),Nt=r.useCallback(()=>{I("timeline"),z(!1),D(u??e.invocation_id),M([]),H(_=>_+1)},[e.invocation_id,u]),At=r.useCallback(_=>{Q(null),Oe(_),H(b=>b+1)},[]),jt=r.useCallback(async()=>{await k.current.stop(),$(E.stopped)},[]),St=Ne;return n.jsxs(g.Modal,{open:t,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:e.invocation_name}),n.jsx("span",{className:G("agent-workspace__phase",`agent-workspace__phase--${C}`),children:Pt[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":!V,onClick:()=>ne(_=>!_),children:"Checklist"}),n.jsx(g.Button,{variant:"tertiary",size:"S",iconLeftName:"files",iconLeftScreenReaderText:"Toggle resources","aria-pressed":!v,onClick:()=>F(_=>!_),children:"Resources"}),n.jsx(g.Button,{variant:"secondary",size:"S",iconLeftName:"x",iconLeftScreenReaderText:"Close",onClick:s,children:"Close"})]})]}),n.jsxs(g.Modal.Body,{className:G("agent-workspace__body",{"agent-workspace__body--no-left":V,"agent-workspace__body--no-right":v}),children:[!V&&n.jsx(Kt,{checklist:St,isLoading:Le,error:je,phase:C,canRequestInput:C===E.running&&!p,onStop:()=>void jt(),onAttentionItemClick:Se}),n.jsxs("section",{className:G("agent-workspace__panel","agent-workspace__panel--chat",{"agent-workspace__panel--timeline":!!d&&N==="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:N==="chat",tabElementProps:{id:"agent-center-tab-chat",onClick:()=>I("chat")},children:"Chat"}),n.jsx(g.Tabs.Item,{active:N==="timeline",tabElementProps:{id:"agent-center-tab-timeline",onClick:()=>I("timeline")},children:"Timeline"})]}),d&&N==="chat"&&q&&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:Nt,children:"Back to timeline"})}),!d||N==="chat"?n.jsx(qt,{connector:P,phase:C,chatHistory:K,chatSessionKey:L,startQuery:_e,clarificationMessage:ce,enableUpload:w,onTurn:ee,onAwaitingChange:x,onClarificationPrompt:At,onDismissClarification:()=>Q(null)}):n.jsx(nn,{timeline:fe,isLoading:we,error:ke,onOpenChatSession:yt})]}),!v&&n.jsx(Jt,{resources:Pe,isLoading:Me,error:Z})]})]})},Sn="Unable to load agent definitions. Please try again.",Cn="Unable to start the agent.",et="Loading agents…",xt=({open:e,onClose:t,onStart:s,agentDefinitions:a,definitionsState:i="idle",definitionsError:l=null,onRetryDefinitions:o,embedded:c=!1})=>{const d=a[0],[f,h]=r.useState(d),[u,w]=r.useState(""),[m,S]=r.useState(!1),[y,T]=r.useState(null),D=[...a].sort((A,R)=>A.agent_intent.localeCompare(R.agent_intent)).map(A=>({value:A.ref,label:A.agent_intent}));r.useEffect(()=>{e&&(h(d),w(""),S(!1),T(null))},[e,d]);const N=f!==void 0&&u.trim().length>0,I=r.useCallback(A=>{const R=a.find(J=>J.ref===A[0]);R&&h(R)},[a]),q=r.useCallback(async()=>{if(!(!f||!N||m)){S(!0),T(null);try{await s({definition:f,invocationName:u.trim()})}catch(A){T(A instanceof Error?A.message:Cn)}finally{S(!1)}}},[N,f,u,m,s]);if(i==="idle"&&a.length===0||!e)return null;const z=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})}),c?n.jsx("h2",{className:"new-agent__title",children:"Start an agent"}):n.jsx(g.Modal.Title,{children:"Start an agent"})]});let P;return i==="loading"?P=n.jsxs("div",{className:"new-agent__state","aria-live":"polite",children:[n.jsx(g.Icon,{name:"loader",size:24,color:"var(--color-brand-600)",className:"new-agent__spinner",screenReaderText:et}),n.jsx("p",{className:"new-agent__state-message",children:et})]}):i==="error"?P=n.jsxs("div",{className:"new-agent__state new-agent__state--error",role:"alert",children:[n.jsx(g.Icon,{name:"triangle-alert",size:24,color:"var(--color-semantic-destructive-600)"}),n.jsx("p",{className:"new-agent__state-message",children:l??Sn}),o?n.jsx(g.Button,{variant:"secondary",size:"S",onClick:o,children:"Try again"}):null]}):f?P=n.jsxs("form",{className:"new-agent__form","aria-label":"Start an agent",onSubmit:A=>{A.preventDefault(),N&&!m&&q()},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:D,selectedValues:[f.ref],onSelectionChange:I}),n.jsx("p",{className:"new-agent__type-description",children:f.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:u,placeholder:"e.g. Test with memory3",onChange:A=>w(A.target.value)})]}),y?n.jsx("p",{className:"new-agent__error",role:"alert",children:y}):null,n.jsx("div",{className:"new-agent__actions",children:n.jsx(g.Button,{type:"submit",variant:"primary",disabled:!N||m,iconLeftName:m?"loader":"sparkles",iconLeftScreenReaderText:m?"Starting":void 0,children:m?"Starting…":"Start"})})]}):P=null,c?n.jsxs("div",{className:G("new-agent","new-agent--embedded"),children:[n.jsx("div",{className:"new-agent__header",children:z}),n.jsx("div",{className:"new-agent__body",children:P})]}):n.jsxs(g.Modal,{open:e,closeHandler:t,className:"new-agent",children:[n.jsx(g.Modal.Header,{className:"new-agent__header",children:z}),n.jsx(g.Modal.Body,{className:"new-agent__body",children:P})]})},tt=e=>{window.location.assign(e)},bn=({open:e,authToken:t,headers:s,agentDefinitionsUrl:a,agentsUrl:i,closeUrl:l,successUrl:o,onClose:c,onStart:d,embedded:f=!1})=>{const h=JSON.stringify(s??{}),u=r.useMemo(()=>new Re({token:t,headers:s,urls:{agentDefinitions:a,agents:i}}),[t,a,i,h]),[w,m]=r.useState([]),[S,y]=r.useState("loading"),[T,D]=r.useState(null),[N,I]=r.useState(0);r.useEffect(()=>{if(!e)return;let A=!1;return y("loading"),D(null),(async()=>{try{const R=await u.listAgentDefinitions();if(A)return;m(R.map(Fe)),y("idle")}catch(R){if(A)return;m([]),D(_t(R)),y("error")}})(),()=>{A=!0}},[u,e,N]);const q=r.useCallback(()=>{c==null||c(),l&&tt(l)},[l,c]),z=r.useCallback(async A=>{await u.createAgent(A.definition.ref,{invocationName:A.invocationName}),d==null||d(A),o&&tt(o)},[u,d,o]),P=r.useCallback(()=>{I(A=>A+1)},[]);return n.jsx(xt,{open:e,onClose:q,onStart:z,agentDefinitions:w,definitionsState:S,definitionsError:T,onRetryDefinitions:P,embedded:f})},Tn=e=>"agentDefinitionsUrl"in e,kt=e=>Tn(e)?n.jsx(bn,{...e}):n.jsx(xt,{...e}),En=e=>e!==void 0&&e.some(t=>t.status===O.hitl),In=(e,t)=>En(t)?j.hitl:e.status,Rn=({column:e,label:t})=>e.statusIcon?n.jsx("span",{className:"agent-view__status-indicator",children:n.jsx(g.Icon,{name:e.statusIcon.name,size:16,color:e.statusIcon.color,className:G({"agent-view__progress-icon--spinning":e.statusIcon.spin}),screenReaderText:t})}):n.jsx("span",{className:G("agent-view__dot",{[`agent-view__dot--${e.dotModifier}`]:e.dotModifier}),children:n.jsx(g.Dot,{colour:e.dotColour,label:t})}),On=({agent:e,agentName:t,column:s,isExpanded:a,isLoading:i,checklist:l,error:o,onToggle:c,onViewAgent:d})=>{const{id:f,invocation_name:h}=e,u=`agent-card-${f}-header`,w=`agent-card-${f}-progress`;return n.jsx("li",{className:G("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":w,"aria-label":h,id:u,onClick:()=>c(f),children:n.jsxs("div",{className:"agent-view__card-content",children:[n.jsx(Rn,{column:s}),n.jsx("span",{className:"agent-view__card-invocation-name",children:h}),n.jsx("span",{className:"agent-view__card-agent-name",children:t}),n.jsx(g.Icon,{name:a?"chevron-up":"chevron-down",size:16,className:"agent-view__card-chevron"})]})}),a&&n.jsxs("div",{id:w,"aria-labelledby":u,className:"agent-view__card-progress",children:[i&&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})]}),!i&&o&&n.jsx("p",{className:"agent-view__progress-error",role:"alert",children:o}),!i&&!o&&l!==null&&n.jsx(Ft,{checklist:l}),!i&&!o&&l===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(e),children:"View agent"})})]})]})})},nt=({column:e,agents:t,expandedAgentId:s,loadingAgentId:a,checklistByInvocationId:i,errorByAgentId:l,definitionNameByRef:o,onToggleAgent:c,onViewAgent:d,isSplit:f=!1})=>n.jsxs("section",{className:G("agent-view__column",{"agent-view__column--split":f}),"aria-label":e.title,children:[n.jsxs("div",{className:"agent-view__column-header",children:[n.jsx(g.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(h=>n.jsx(On,{agent:h,agentName:He(h,o),column:e,isExpanded:s===h.id,isLoading:a===h.id,checklist:i[h.invocation_id]??null,error:l[h.id]??null,onToggle:c,onViewAgent:d},h.id))})]}),He=(e,t)=>t.get(e.agent_definition_ref)??e.agent_definition_ref.replace(/_/g," "),Pn=({jwt:e,headers:t,agentDefinitionsUrl:s,agentsUrl:a,agentUrl:i,agentChecklistUrl:l,agentResourcesUrl:o,agentTimelineUrl:c,agentChatUrl:d,agentConversationUrl:f,enableUpload:h,showHeader:u=!1,institutions:w})=>{var ue;const m=r.useMemo(()=>({agentDefinitions:s,agents:a,agent:i,agentChecklist:l,...o?{agentResources:o}:{},...c?{agentTimeline:c}:{},agentChat:d,agentConversation:f}),[s,a,i,l,o,c,d,f]),[S,y]=r.useState(null),T=S?(ue=w==null?void 0:w.find(p=>p.applicationId===S.application_id))==null?void 0:ue.applicationUrl:void 0,D=r.useMemo(()=>{const p={...t??{}};return T?p[re.arborApplicationUrl]=T:delete p[re.arborApplicationUrl],p},[t,T]),{agents:N,agentDefinitions:I,loadState:q,loadError:z,reload:P,refresh:A,fetchAgentChecklist:R,createAgent:J}=ft({jwt:e,headers:D,urls:m}),[k,C]=r.useState(!1),[$,K]=r.useState(null),[M,L]=r.useState(null),[H,_e]=r.useState({}),[Oe,ce]=r.useState({}),[Q,Pe]=r.useState([]),[te,Me]=r.useState([]),le=r.useMemo(()=>{const p=new Set(N.map(v=>v.application_id)),x=new Map((w??[]).map(v=>[v.applicationId,v.name]));return[...p].sort((v,F)=>(x.get(v)??v).localeCompare(x.get(F)??F)).map(v=>({value:v,label:x.get(v)??v}))},[N,w]),Z=r.useMemo(()=>new Map(I.map(p=>[p.ref,p.display_name])),[I]),de=r.useMemo(()=>[...new Set(N.map(x=>He(x,Z)))].sort((x,v)=>x.localeCompare(v)).map(x=>({value:x,label:x})),[N,Z]),fe=r.useMemo(()=>N.filter(p=>!(Q.length>0&&!Q.includes(p.application_id)||te.length>0&&!te.includes(He(p,Z)))),[N,Z,te,Q]),ve=le.length>1,we=de.length>1,xe=ve||we;r.useEffect(()=>{const p=window.setInterval(()=>{A()},6e4);return()=>{window.clearInterval(p)}},[A]),r.useEffect(()=>{if(N.length===0)return;let p=!1;return(async()=>{const x=await Promise.allSettled(N.map(async v=>{const F=await R(v.invocation_id);return{agentId:v.id,invocationId:v.invocation_id,checklist:F.checklist}}));p||(_e(v=>{const F={...v};let V=!1;for(const ne of x){if(ne.status!=="fulfilled")continue;const{invocationId:ee,checklist:Se}=ne.value;JSON.stringify(v[ee])!==JSON.stringify(Se)&&(F[ee]=Se,V=!0)}return V?F:v}),ce(v=>{const F={...v};let V=!1;return x.forEach((ne,ee)=>{ne.status==="rejected"&&F[N[ee].id]!==Te&&(F[N[ee].id]=Te,V=!0)}),V?F:v}))})(),()=>{p=!0}},[N,R]);const ke=r.useCallback(async p=>{if(!H[p.invocation_id]){L(p.id),ce(x=>{const v={...x};return delete v[p.id],v});try{const x=await R(p.invocation_id);_e(v=>({...v,[p.invocation_id]:x.checklist}))}catch{ce(x=>({...x,[p.id]:Te}))}finally{L(x=>x===p.id?null:x)}}},[R,H]),ye=r.useCallback(p=>{if($===p){K(null);return}const x=N.find(({id:v})=>v===p);x&&(K(p),ke(x))},[N,$,ke]),Ne=r.useMemo(()=>{const p={};for(const x of fe){const v=In(x,H[x.invocation_id]);(p[v]??(p[v]=[])).push(x)}return p},[fe,H]),ge=r.useCallback(p=>{y(p)},[]),Le=r.useCallback(async p=>{const x=await J(p);y(x),C(!1)},[J]),Ae=r.useCallback(()=>{y(null)},[]),je={expandedAgentId:$,loadingAgentId:M,checklistByInvocationId:H,errorByAgentId:Oe,definitionNameByRef:Z,onToggleAgent:ye,onViewAgent:ge};return n.jsxs("div",{className:"agent-view-frontend agent-view",children:[u&&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"})]}),N.length>0&&xe&&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:Q,onValueChange:Pe,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear institutions"})]}),we&&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:Me,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear agents"})]})]}),q==="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:z??it}),n.jsx(g.Button,{variant:"secondary",size:"S",onClick:P,children:"Try again"})]}):q==="loading"&&N.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:Ve}),n.jsx("p",{className:"agent-view__state-message",children:Ve})]}):N.length===0?n.jsx(Ut,{}):n.jsxs("div",{className:"agent-view__board",children:[Ct.map(p=>n.jsx(nt,{column:Ee[p],agents:Ne[p]??[],...je},p)),n.jsx("div",{className:"agent-view__split-column",children:bt.map(p=>n.jsx(nt,{column:Ee[p],agents:Ne[p]??[],isSplit:!0,...je},p))})]}),S&&n.jsx(wt,{agent:S,open:!0,jwt:e,headers:D,agentUrl:i,agentChecklistUrl:l,agentResourcesUrl:o,agentTimelineUrl:c,agentChatUrl:d,agentConversationUrl:f,enableUpload:h,initialChecklist:H[S.invocation_id]??null,onClose:Ae},S.id),n.jsx(kt,{open:k,onClose:()=>C(!1),onStart:Le,agentDefinitions:I})]})},Mn=(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:Tt,created_by:Et,status:j["generating-a-response"],context_ref:null,checklist_ref:null}};exports.AgentMonitorKanban=Pn;exports.AgentServiceClient=Re;exports.AgentServiceError=ie;exports.AgentView=wt;exports.HttpChatConnector=mt;exports.NewAgentModal=kt;exports.buildAgentFromDefinition=Mn;exports.createHttpChatConnectorFactory=Ke;exports.mapApiAgent=Be;exports.mapApiAgentDefinition=Fe;exports.mapApiAgentStatus=lt;exports.mapApiAgentTimelineResponse=ut;exports.mapApiChecklistEndpointResponse=qe;exports.mapApiChecklistItem=Ge;exports.mapApiChecklistResponse=pt;exports.mapApiChecklistStatus=dt;exports.mapApiConversationMessages=ht;exports.mapApiOpeningMessage=me;exports.mapApiResource=gt;exports.mapApiResourcesEndpointResponse=ze;exports.mapApiTripOption=hn;exports.useAgentService=ft;exports.useAgentWorkspace=vt;
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;
@@ -71,8 +73,13 @@ export declare type AgentMonitorKanbanProps = {
71
73
  agentChecklistUrl: string;
72
74
  /** Optional — omit when the backend has no /resources route. */
73
75
  agentResourcesUrl?: string;
76
+ /** Optional — omit when the backend has no /agent-timeline route. */
77
+ agentTimelineUrl?: string;
74
78
  agentChatUrl: string;
79
+ agentConversationUrl: string;
75
80
  enableUpload?: boolean;
81
+ /** When true, renders the Agents heading and Start an agent button. Defaults to false. */
82
+ showHeader?: boolean;
76
83
  institutions?: InstitutionConfig[];
77
84
  };
78
85
 
@@ -110,9 +117,11 @@ export declare class AgentServiceClient {
110
117
  getAgent(agentId: string): Promise<ApiAgentInvocationDetail>;
111
118
  getAgentChecklist(agentId: string): Promise<ApiChecklistEndpointResponse>;
112
119
  getAgentResources(agentId: string): Promise<ApiResourcesEndpointResponse>;
120
+ getAgentTimeline(agentId: string): Promise<ApiAgentTimelineResponse>;
113
121
  getAgentContext(agentId: string): Promise<unknown>;
114
122
  cancelAgent(agentId: string): Promise<ApiAgentInvocation>;
115
123
  archiveAgent(agentId: string): Promise<ApiAgentInvocation>;
124
+ getConversation(agentId: string): Promise<ApiConversationResponse>;
116
125
  chat(agentId: string, request: ApiChatRequest, options?: ChatOptions): Promise<ApiChatStreamEvent>;
117
126
  private authHeaders;
118
127
  private apiUrl;
@@ -150,14 +159,33 @@ export declare type AgentServiceUrlOverrides = {
150
159
  agent?: string;
151
160
  agentChecklist?: string;
152
161
  agentResources?: string;
162
+ agentTimeline?: string;
153
163
  agentChat?: string;
164
+ agentConversation?: string;
154
165
  };
155
166
 
156
167
  export declare type AgentServiceUrls = AgentServiceUrlOverrides;
157
168
 
158
169
  export declare type AgentStatus = 'generating-a-response' | 'hitl' | 'complete' | 'failed';
159
170
 
160
- 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;
161
189
 
162
190
  export declare type AgentViewProps = {
163
191
  agent: Agent;
@@ -169,7 +197,12 @@ export declare type AgentViewProps = {
169
197
  agentChecklistUrl: string;
170
198
  /** Optional — omit when the backend has no /resources route. */
171
199
  agentResourcesUrl?: string;
200
+ /** Optional — omit when the backend has no /agent-timeline route. */
201
+ agentTimelineUrl?: string;
172
202
  agentChatUrl: string;
203
+ agentConversationUrl: string;
204
+ /** Timeline/conversation session id for chat turns. Defaults to agent.invocation_id. */
205
+ chatId?: string;
173
206
  /** When true, enables chat file uploads (posted to agentChatUrl). */
174
207
  enableUpload?: boolean;
175
208
  initialBrief?: AgentBrief;
@@ -181,7 +214,9 @@ export declare type AgentWorkspaceUrls = {
181
214
  agentUrl: string;
182
215
  agentChecklistUrl: string;
183
216
  agentResourcesUrl?: string;
217
+ agentTimelineUrl?: string;
184
218
  agentChatUrl: string;
219
+ agentConversationUrl: string;
185
220
  };
186
221
 
187
222
  export declare type ApiAgentDefinition = {
@@ -233,6 +268,23 @@ export declare type ApiAgentResource = {
233
268
  description?: string;
234
269
  };
235
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
+
236
288
  export declare type ApiChatMessage = {
237
289
  role: ApiChatRole;
238
290
  content: string;
@@ -292,6 +344,36 @@ export declare type ApiChecklistItem = {
292
344
 
293
345
  export declare type ApiChecklistItemStatus = 'in_progress' | 'requires_attention' | 'failed' | 'complete' | 'available' | 'generating-a-response' | 'hitl';
294
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
+
295
377
  export declare type ApiCreateAgentResponse = {
296
378
  id: string;
297
379
  status: ApiAgentInvocationStatus;
@@ -349,6 +431,10 @@ export declare const createHttpChatConnectorFactory: (client: AgentServiceClient
349
431
  id: string;
350
432
  invocation_id: string;
351
433
  }) => ChatMessage | undefined;
434
+ resolveChatId?: (agent: {
435
+ id: string;
436
+ invocation_id: string;
437
+ }) => string | undefined;
352
438
  }) => (agent: {
353
439
  id: string;
354
440
  invocation_id: string;
@@ -359,14 +445,13 @@ declare type FetchLike = typeof fetch;
359
445
  export declare class HttpChatConnector implements ChatConnector {
360
446
  private readonly client;
361
447
  private readonly agentId;
448
+ private readonly chatId;
362
449
  private readonly opening;
363
450
  private readonly model?;
364
- private readonly bootstrapPrompt;
365
- private chatId?;
366
451
  private seededChecklist;
367
452
  constructor(client: AgentServiceClient, agentId: string, options?: HttpChatConnectorOptions);
368
453
  openingMessage(): ChatMessage;
369
- bootstrapConversation(prompt?: string): Promise<ChatMessage[]>;
454
+ bootstrapConversation(): Promise<ChatMessage[]>;
370
455
  start(brief: AgentBrief): Promise<ChatTurn>;
371
456
  sendMessage(text: string, uploadFiles?: File[]): Promise<ChatTurn>;
372
457
  stop(): Promise<void>;
@@ -377,7 +462,7 @@ export declare class HttpChatConnector implements ChatConnector {
377
462
  export declare type HttpChatConnectorOptions = {
378
463
  openingMessage?: ChatMessage;
379
464
  model?: string;
380
- bootstrapPrompt?: string;
465
+ chatId?: string;
381
466
  };
382
467
 
383
468
  export declare type InstitutionConfig = {
@@ -397,6 +482,8 @@ export declare const mapApiAgentDefinition: (record: ApiAgentDefinition) => Agen
397
482
 
398
483
  export declare const mapApiAgentStatus: (status: string) => AgentStatus;
399
484
 
485
+ export declare const mapApiAgentTimelineResponse: (payload: ApiAgentTimelineResponse) => AgentTimeline;
486
+
400
487
  export declare const mapApiChecklistEndpointResponse: (invocationId: string, payload: ApiChecklistEndpointResponse, agent?: Pick<ApiAgentInvocation, "opening_message" | "opening_follow_up_prompts">) => AgentChecklistResponse;
401
488
 
402
489
  export declare const mapApiChecklistItem: (item: ApiChecklistItem) => AgentChecklistItem;
@@ -405,6 +492,8 @@ export declare const mapApiChecklistResponse: (invocationId: string, detail: Api
405
492
 
406
493
  export declare const mapApiChecklistStatus: (status: ApiChecklistItemStatus | string | undefined) => AgentChecklistItemStatus;
407
494
 
495
+ export declare const mapApiConversationMessages: (messages: ApiConversationMessage[]) => ChatMessage[];
496
+
408
497
  export declare const mapApiOpeningMessage: (record: Pick<ApiAgentInvocation, "opening_message" | "opening_follow_up_prompts">) => ChatMessage | undefined;
409
498
 
410
499
  export declare const mapApiResource: (record: ApiAgentResource) => AgentResource;
@@ -417,13 +506,39 @@ export declare const mapApiTripOption: (record: ApiTripOption) => {
417
506
  name: string;
418
507
  };
419
508
 
420
- export declare const NewAgentModal: ({ open, onClose, onStart, agentDefinitions, }: NewAgentModalProps) => JSX_2.Element | null;
509
+ export declare const NewAgentModal: (props: NewAgentModalProps) => JSX_2.Element;
421
510
 
422
- export declare type NewAgentModalProps = {
511
+ export declare type NewAgentModalControlledProps = {
423
512
  open: boolean;
424
513
  onClose: () => void;
425
514
  onStart: (payload: NewAgentStartPayload) => void | Promise<void>;
426
515
  agentDefinitions: AgentDefinition[];
516
+ /** When true, render inline (no design-system Modal portal). */
517
+ embedded?: boolean;
518
+ };
519
+
520
+ export declare type NewAgentModalProps = NewAgentModalControlledProps | NewAgentModalStandaloneProps;
521
+
522
+ export declare type NewAgentModalStandaloneProps = {
523
+ open: boolean;
524
+ /** Bearer token attached to every AI Service SDK request. */
525
+ authToken?: string;
526
+ /** Extra headers merged into every AI Service SDK request. */
527
+ headers?: Record<string, string>;
528
+ /** Full URL to GET the list of agent definitions. */
529
+ agentDefinitionsUrl: string;
530
+ /** Full URL to POST a new agent (the agents collection). */
531
+ agentsUrl: string;
532
+ /** Navigated to when the modal is closed without starting. */
533
+ closeUrl?: string;
534
+ /** Navigated to after a successful start. */
535
+ successUrl?: string;
536
+ /** Called when the modal is closed, before navigating to `closeUrl`. */
537
+ onClose?: () => void;
538
+ /** Called after a successful start, before navigating to `successUrl`. */
539
+ onStart?: (payload: NewAgentStartPayload) => void;
540
+ /** When true, render inline (no design-system Modal portal). For hosts like MIS `ui:window`. */
541
+ embedded?: boolean;
427
542
  };
428
543
 
429
544
  export declare type NewAgentStartPayload = {
@@ -445,6 +560,8 @@ export declare type UseAgentServiceResult = {
445
560
  loadState: AgentServiceLoadState;
446
561
  loadError: string | null;
447
562
  reload: () => void;
563
+ /** Re-fetch agents without a loading flash; no-ops state when unchanged. */
564
+ refresh: () => Promise<void>;
448
565
  fetchAgentChecklist: (invocationId: string) => Promise<AgentChecklistResponse>;
449
566
  fetchAgentResources: (invocationId: string) => Promise<AgentResource[]>;
450
567
  createAgent: (payload: NewAgentStartPayload) => Promise<Agent>;
@@ -458,12 +575,14 @@ export declare type UseAgentWorkspaceConfig = {
458
575
  jwt?: string;
459
576
  headers?: Record<string, string>;
460
577
  urls: AgentWorkspaceUrls;
578
+ chatId?: string;
461
579
  };
462
580
 
463
581
  export declare type UseAgentWorkspaceResult = {
464
582
  connector: ChatConnector;
465
583
  fetchAgentChecklist: (invocationId: string) => Promise<AgentChecklistResponse>;
466
584
  fetchAgentResources: (invocationId: string) => Promise<AgentResource[]>;
585
+ fetchAgentTimeline: (invocationId: string) => Promise<AgentTimeline>;
467
586
  };
468
587
 
469
588
  export declare type WorkspacePhase = 'briefing' | 'running' | 'stopped' | 'complete';