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