@arbor-education/agent-view-frontend 0.3.1 → 0.4.0
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 +49 -26
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +54 -16
- package/dist/index.js +1073 -1017
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
React components to support the development of the Agentic MATs initiative.
|
|
4
4
|
|
|
5
5
|
The UI is designed to work against the **AI agent service** — not only the local mock
|
|
6
|
-
server.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
SDK** (`AgentServiceClient`)
|
|
6
|
+
server. Hosts compose full endpoint URLs from their service origin (see the demo).
|
|
7
|
+
`AgentMonitorKanban` lists/creates agents from those URLs; `AgentView` can be mounted
|
|
8
|
+
on its own and fetches checklist, resources, and chat for a single agent. Both talk to
|
|
9
|
+
the bundled **AI service SDK** (`AgentServiceClient`). The demo ships with presets for
|
|
10
10
|
mock, local (`localhost:8001`), and staging backends; see
|
|
11
11
|
[Wiring the UI to the AI service](#wiring-the-ui-to-the-ai-service).
|
|
12
12
|
|
|
@@ -49,8 +49,8 @@ Use **Debug options** in the toolbar to switch backends:
|
|
|
49
49
|
| **Local AI service** | `http://localhost:8001` | Real AI agent service on your machine. Bearer token required. |
|
|
50
50
|
| **Staging AI service** | `https://ai-agent-service.qa.arbor.engineering` | QA environment. Bearer token required. |
|
|
51
51
|
|
|
52
|
-
You can also paste any service origin into the **Service URL** field (the
|
|
53
|
-
`/api/v1
|
|
52
|
+
You can also paste any service origin into the **Service URL** field (the demo
|
|
53
|
+
appends `/api/v1/…` when building endpoint URL props).
|
|
54
54
|
|
|
55
55
|
You can also configure the demo without opening the debug panel:
|
|
56
56
|
|
|
@@ -101,38 +101,51 @@ VITE_AGENT_SERVICE_PROXY_TARGET=https://ai-agent-service.qa.arbor.engineering ma
|
|
|
101
101
|
|
|
102
102
|
## Wiring the UI to the AI service
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
loading checklists and resources, creating agents, and streaming chat.
|
|
104
|
+
Library components take **full endpoint URLs** (no `baseUrl` prop). The host — e.g.
|
|
105
|
+
the demo — resolves a service origin and builds each URL.
|
|
107
106
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
Service URL field into `baseUrl`; see [`demo/App.tsx`](demo/App.tsx) (and the URL
|
|
111
|
-
helpers in [`demo/backendApi.ts`](demo/backendApi.ts)).
|
|
107
|
+
- **`AgentMonitorKanban`** — lists agents/definitions, card checklists, creates agents.
|
|
108
|
+
- **`AgentView`** — standalone workspace; fetches checklist, resources, and chat itself.
|
|
112
109
|
|
|
113
|
-
**In
|
|
110
|
+
**In the demo** — open **Debug options**, pick a backend, paste a bearer token, and
|
|
111
|
+
click **Reload board**. See [`demo/App.tsx`](demo/App.tsx) for how `baseUrl` +
|
|
112
|
+
`/api/v1` become the URL props.
|
|
113
|
+
|
|
114
|
+
**In your app:**
|
|
114
115
|
|
|
115
116
|
```tsx
|
|
116
|
-
import { AgentMonitorKanban } from 'agent-view-frontend';
|
|
117
|
+
import { AgentMonitorKanban, AgentView } from 'agent-view-frontend';
|
|
117
118
|
import 'agent-view-frontend/style.css';
|
|
118
119
|
import '@arbor-education/design-system.components/dist/index.css';
|
|
119
120
|
|
|
121
|
+
const api = 'https://ai-agent-service.qa.arbor.engineering/api/v1';
|
|
122
|
+
|
|
120
123
|
<AgentMonitorKanban
|
|
121
124
|
jwt={jwt}
|
|
122
125
|
headers={{ 'X-Arbor-Application': 'agent-view' }}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
agentDefinitionsUrl={`${api}/agent-definitions`}
|
|
127
|
+
agentsUrl={`${api}/agents`}
|
|
128
|
+
agentUrl={`${api}/agents/:invocationId`}
|
|
129
|
+
agentChecklistUrl={`${api}/agents/:invocationId/checklist`}
|
|
130
|
+
agentResourcesUrl={`${api}/agents/:invocationId/resources`}
|
|
131
|
+
agentChatUrl={`${api}/agents/:invocationId/chat`}
|
|
132
|
+
/>;
|
|
133
|
+
|
|
134
|
+
// Or mount the workspace alone:
|
|
135
|
+
<AgentView
|
|
136
|
+
agent={agent}
|
|
137
|
+
open
|
|
138
|
+
onClose={onClose}
|
|
139
|
+
jwt={jwt}
|
|
140
|
+
agentUrl={`${api}/agents/:invocationId`}
|
|
141
|
+
agentChecklistUrl={`${api}/agents/:invocationId/checklist`}
|
|
142
|
+
agentResourcesUrl={`${api}/agents/:invocationId/resources`}
|
|
143
|
+
agentChatUrl={`${api}/agents/:invocationId/chat`}
|
|
128
144
|
/>;
|
|
129
145
|
```
|
|
130
146
|
|
|
131
|
-
|
|
132
|
-
(
|
|
133
|
-
`agentResourcesUrl`, `agentChatUrl`) each fall back to `baseUrl` +
|
|
134
|
-
`/api/v1` + the route when omitted. See the [AI service SDK](#ai-service-sdk) section
|
|
135
|
-
for the underlying client, which you can also use directly.
|
|
147
|
+
Parameterised routes substitute the `:invocationId` placeholder. See the
|
|
148
|
+
[AI service SDK](#ai-service-sdk) section for the underlying client.
|
|
136
149
|
|
|
137
150
|
---
|
|
138
151
|
|
|
@@ -152,7 +165,17 @@ import 'agent-view-frontend/style.css';
|
|
|
152
165
|
import '@arbor-education/design-system.components/dist/index.css';
|
|
153
166
|
|
|
154
167
|
function Page() {
|
|
155
|
-
|
|
168
|
+
const api = '/api/ai-agent-service/api/v1';
|
|
169
|
+
return (
|
|
170
|
+
<AgentMonitorKanban
|
|
171
|
+
agentsUrl={`${api}/agents`}
|
|
172
|
+
agentDefinitionsUrl={`${api}/agent-definitions`}
|
|
173
|
+
agentUrl={`${api}/agents/:invocationId`}
|
|
174
|
+
agentChecklistUrl={`${api}/agents/:invocationId/checklist`}
|
|
175
|
+
agentResourcesUrl={`${api}/agents/:invocationId/resources`}
|
|
176
|
+
agentChatUrl={`${api}/agents/:invocationId/chat`}
|
|
177
|
+
/>
|
|
178
|
+
);
|
|
156
179
|
}
|
|
157
180
|
```
|
|
158
181
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),o=require("react"),P=require("classnames"),d=require("@arbor-education/design-system.components"),se=require("@arbor-education/ask-arbor-chat-panel"),v={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},N={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},b={briefing:"briefing",running:"running",stopped:"stopped",complete:"complete"},W={agent:"agent",user:"user",system:"system"},Z={MIS_RECORD:"MIS_RECORD",FILE:"FILE",WORKFLOW:"WORKFLOW",LINK:"LINK"},je={cancelled:"cancelled",archived:"archived"},ve={in_progress:"in_progress",requires_attention:"requires_attention",available:"available"},$={[N.complete]:{label:"Complete",icon:"circle-check",color:"var(--color-semantic-success-600)"},[N.failed]:{label:"Failed",icon:"circle-x",color:"var(--color-semantic-destructive-600)"},[N.hitl]:{label:"Requires attention",icon:"triangle-alert",color:"var(--color-semantic-warning-600)"},[N["generating-a-response"]]:{label:"Generating a response",icon:"loader",color:"var(--color-brand-600)"}},he={[v["generating-a-response"]]:{status:v["generating-a-response"],title:"Active",dotColour:"green",statusIcon:{name:$["generating-a-response"].icon,color:$["generating-a-response"].color,spin:!0}},[v.hitl]:{status:v.hitl,title:"Requires attention",dotColour:"orange",statusIcon:{name:$.hitl.icon,color:$.hitl.color}},[v.complete]:{status:v.complete,title:"Complete",dotColour:"green",dotModifier:"grey-dark",statusIcon:{name:$.complete.icon,color:$.complete.color}},[v.failed]:{status:v.failed,title:"Failed",dotColour:"salmon",statusIcon:{name:$.failed.icon,color:$.failed.color}}},et=[v["generating-a-response"],v.hitl],tt=[v.complete,v.failed],nt="m4",st="1",Pe="msg-opening",we="Unable to load agent tasks. Please try again.",at="Unable to load the resources for this agent",rt="Something went wrong. Please try again.",Me="Unable to load agents. Please try again.",ee="Loading tasks…",be="Loading agents…",ot="Task",it="What recent actions have you taken?",ct={[b.briefing]:"Briefing",[b.running]:"Working",[b.stopped]:"Stopped",[b.complete]:"Complete"},lt=[v["generating-a-response"],v.hitl,v.complete,v.failed],dt={[v["generating-a-response"]]:"Agents currently working on tasks for you.",[v.hitl]:"Agents that need your input before they can continue.",[v.complete]:"Agents that have finished their work.",[v.failed]:"Agents that failed or were stopped."},gt=()=>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)"})]}),ut=({status:e})=>{const t=he[e];return t.statusIcon?n.jsx(d.Icon,{name:t.statusIcon.name,size:16,color:t.statusIcon.color,screenReaderText:t.title}):n.jsx(d.Dot,{colour:t.dotColour,label:t.title})},pt=()=>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:lt.map(e=>{const t=he[e];return n.jsxs("li",{className:"agent-view__empty-column",children:[n.jsx("span",{className:"agent-view__empty-column-indicator",children:n.jsx(ut,{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:dt[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(gt,{})})]}),ht=(e,t)=>({...e,...t.length>0?{children:t}:{}}),Le=e=>{const t=[],a=[];for(const s of e){const r=s.children?Le(s.children):{needsInput:[],tasks:[]};if(t.push(...r.needsInput),s.status===N.hitl){t.push({...s,children:void 0});continue}a.push(ht(s,r.tasks))}return{needsInput:t,tasks:a}},_t=e=>e.map((t,a)=>({item:t,index:a})).sort((t,a)=>{const s=t.item.status===N.hitl,r=a.item.status===N.hitl;return s!==r?s?-1:1:t.index-a.index}).map(({item:t})=>t),mt=({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:_t(e).map(t=>{const a=$[t.status];return n.jsxs("li",{className:P("agent-view__progress-item",`agent-view__progress-item--${t.status.replace(/_/g,"-")}`),children:[n.jsx(d.Icon,{name:a.icon,size:16,color:a.color,screenReaderText:`${a.label}:`,className:P({"agent-view__progress-icon--spinning":t.status===N["generating-a-response"]})}),n.jsxs("div",{className:"agent-view__progress-item-content",children:[n.jsx("span",{className:"agent-view__progress-label",children:t.task}),t.status!==N.complete&&n.jsx("span",{className:"agent-view__progress-description",children:t.description})]})]},t.task)})}),ft=({prompts:e,classNamePrefix:t="agent-workspace",onSelect:a})=>e.length===0?null:n.jsx("div",{className:`${t}__chips`,children:e.map(s=>n.jsx("button",{type:"button",className:`${t}__chip`,onClick:()=>a(s),children:s},s))});class vt{constructor(t,a){this.connector=t,this.canSend=a.canSend,this.onTurn=a.onTurn,this.onAwaitingChange=a.onAwaitingChange}get canRate(){return!1}get canLoadHistory(){return!1}get canListInteractions(){return!1}get canSendNotification(){return!1}get ratingPopupUrls(){return{}}async sendMessage(t){var a,s;if(!this.canSend())return null;(a=this.onAwaitingChange)==null||a.call(this,!0);try{const r=await this.connector.sendMessage(t.userMessage);return this.onTurn(r),{id:r.message.id,text:r.message.text,type:se.CHAT_RESPONSE_TYPE_AGENT,...r.message.followUpPrompts?{followUpPrompts:r.message.followUpPrompts}:{}}}catch{return{id:`error-${Date.now()}`,text:rt,type:se.CHAT_RESPONSE_TYPE_ERROR}}finally{(s=this.onAwaitingChange)==null||s.call(this,!1)}}async loadHistory(t){return null}async listInteractions(){return null}async rateMessage(t){}async sendNotification(t){return!1}}const wt=({connector:e,phase:t,chatHistory:a,chatSessionKey:s,startQuery:r,clarificationMessage:i,onTurn:c,onAwaitingChange:g,onClarificationPrompt:w,onDismissClarification:u})=>{const p=o.useMemo(()=>new vt(e,{canSend:()=>t===b.running,onTurn:c,onAwaitingChange:g}),[e,t,c,g]),m=t!==b.running,x=t===b.running;return n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--chat","aria-label":"Chat",children:[i&&n.jsxs("div",{className:"agent-workspace__clarification",role:"region","aria-label":"Agent question",children:[n.jsx("p",{className:"agent-workspace__clarification-text",children:i.text}),i.followUpPrompts&&n.jsx(ft,{prompts:i.followUpPrompts,onSelect:w}),n.jsx("button",{type:"button",className:"agent-workspace__clarification-dismiss",onClick:u,children:"Dismiss"})]}),n.jsx("div",{className:"agent-workspace__ask-arbor",children:n.jsx(se.ChatPanel,{connector:p,chatHistory:a,startQuery:r,lockConversation:m,enableUpload:!0,speechEnabled:x,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:x?"Message the agent, paste a link, or attach a file…":"The agent is not accepting messages."},s)}),t===b.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."})]}),t===b.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."})]})]})},Ue=({item:e,depth:t,canRequestInput:a,onAttentionItemClick:s})=>{const r=$[e.status],i=e.status.replace(/_/g,"-"),c=e.status===N.hitl&&a&&s,g=n.jsxs("div",{className:"agent-workspace__task-row",children:[n.jsx(d.Icon,{name:r.icon,size:16,color:r.color,screenReaderText:`${r.label}:`,className:P({"agent-workspace__task-icon--spinning":e.status===N["generating-a-response"]})}),n.jsxs("div",{className:"agent-workspace__task-content",children:[n.jsx("span",{className:"agent-workspace__task-label",children:e.task}),e.status!==N.complete&&e.description&&n.jsx("span",{className:"agent-workspace__task-description",children:e.description})]})]});return n.jsxs("li",{className:P("agent-workspace__task",`agent-workspace__task--${i}`,{"agent-workspace__task--child":t>0}),children:[c?n.jsx("button",{type:"button",className:"agent-workspace__task-button","aria-label":`Provide input for ${e.task}`,onClick:()=>s(e),children:g}):g,e.children&&e.children.length>0&&n.jsx("ul",{className:"agent-workspace__task-children",children:e.children.map(w=>n.jsx(Ue,{item:w,depth:t+1,canRequestInput:a,onAttentionItemClick:s},w.task))})]})},Ce=({items:e,ariaLabel:t,canRequestInput:a,onAttentionItemClick:s})=>n.jsx("ul",{className:"agent-workspace__task-list","aria-label":t,children:e.map(r=>n.jsx(Ue,{item:r,depth:0,canRequestInput:a,onAttentionItemClick:s},r.task))}),xt=({checklist:e,isLoading:t,error:a,phase:s,canRequestInput:r,onStop:i,onAttentionItemClick:c})=>{const g=o.useMemo(()=>e?Le(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(d.Heading,{level:4,children:"Checklist"}),s===b.running&&n.jsx(d.Button,{variant:"secondary-destructive",size:"S",iconLeftName:"circle-x",iconLeftScreenReaderText:"Stop",onClick:i,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(d.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:ee}),n.jsx("span",{children:ee})]}),!t&&a&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:a}),!t&&!a&&g&&n.jsxs(n.Fragment,{children:[g.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(Ce,{items:g.needsInput,ariaLabel:"Tasks needing your input",canRequestInput:r,onAttentionItemClick:c})]}),g.tasks.length>0&&n.jsxs("div",{className:P("agent-workspace__task-group",{"agent-workspace__task-group--following":g.needsInput.length>0}),children:[g.needsInput.length>0&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"Other tasks"}),n.jsx(Ce,{items:g.tasks,ariaLabel:"Agent tasks",canRequestInput:r,onAttentionItemClick:c})]})]}),!t&&!a&&(!g||g.needsInput.length===0&&g.tasks.length===0)&&n.jsx("p",{className:"agent-workspace__empty",children:s===b.briefing?"Tasks will appear here once the agent starts.":"No tasks to display."})]})]})},kt={[Z.MIS_RECORD]:{icon:"table",label:"Arbor MIS",color:"var(--color-brand-600)"},[Z.FILE]:{icon:"file",label:"File",color:"var(--color-semantic-caution-800)"},[Z.WORKFLOW]:{icon:"list-tree",label:"Workflow",color:"var(--color-semantic-warning-700)"},[Z.LINK]:{icon:"link",label:"Link",color:"var(--color-semantic-info-700)"}},At=({resources:e,isLoading:t=!1,error:a=null})=>n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--documents","aria-label":"Resources",children:[n.jsxs("div",{className:"agent-workspace__panel-header",children:[n.jsx(d.Heading,{level:4,children:"Resources"}),n.jsx("span",{className:"agent-workspace__panel-count",children: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(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…"})]}),!t&&a&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:a}),!t&&!a&&e.length>0&&n.jsx("ul",{className:"agent-workspace__resource-list","aria-label":"Agent resources",children:e.map(s=>{const r=kt[s.type];return n.jsx("li",{className:"agent-workspace__resource",children:n.jsxs("a",{className:"agent-workspace__resource-card",href:s.uri,target:"_blank",rel:"noreferrer",children:[n.jsx("span",{className:`agent-workspace__resource-icon agent-workspace__resource-icon--${s.type.toLowerCase()}`,children:n.jsx(d.Icon,{name:r.icon,size:16,color:r.color,screenReaderText:`${r.label}:`})}),n.jsxs("span",{className:"agent-workspace__resource-content",children:[n.jsxs("span",{className:"agent-workspace__resource-top",children:[n.jsx("span",{className:"agent-workspace__resource-name",children:s.name}),n.jsx("span",{className:`agent-workspace__resource-badge agent-workspace__resource-badge--${s.type.toLowerCase()}`,children:r.label})]}),s.description&&n.jsx("span",{className:"agent-workspace__resource-description",children:s.description})]}),n.jsx(d.Icon,{name:"external-link",size:12,color:"var(--color-grey-500)",screenReaderText:"Opens in a new tab",className:"agent-workspace__resource-open"})]})},`${s.type}-${s.uri}`)})}),!t&&!a&&e.length===0&&n.jsx("p",{className:"agent-workspace__empty",children:"No resources yet."})]})]}),St=["I'll get the details and come back to you","Skip this for now"],yt=e=>{var a;const t=(a=e.prompt)!=null&&a.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:W.agent,text:t,followUpPrompts:e.clarificationPrompts??St}},ce=e=>({id:e.id,text:e.text,type:e.author===W.user?se.CHAT_RESPONSE_TYPE_USER:e.author===W.system?se.CHAT_RESPONSE_TYPE_INFO:se.CHAT_RESPONSE_TYPE_AGENT,...e.followUpPrompts?{followUpPrompts:e.followUpPrompts}:{}}),Nt=(e,t)=>{const a=e.hasRunBefore?t||"This trip":e.tripName.trim()||"A new trip",s=e.destination?` to ${e.destination}`:"",r=e.hasRunBefore?" It has run before.":"";return`${a}${s}.${r}`.trim()},jt=e=>{switch(e){case v.failed:return b.stopped;case v.complete:return b.complete;default:return b.running}},Ee=(e,t)=>{t([ce(e)])},$e=({agent:e,open:t,onClose:a,initialBrief:s,initialPhase:r,initialChecklist:i,fetchAgentChecklist:c,fetchAgentResources:g,connector:w})=>{const u=o.useRef(w),[p,m]=o.useState(r??(s?b.running:jt(e.status))),[x,T]=o.useState([]),[I,k]=o.useState(0),[M,y]=o.useState(),[L,D]=o.useState(null),[H,ae]=o.useState([]),[Q,J]=o.useState(!1),[A,j]=o.useState(null),[O,F]=o.useState(i??null),[G,B]=o.useState(!1),[R,re]=o.useState(null),[_e,V]=o.useState(!1),[q,me]=o.useState(!1),[z,fe]=o.useState(!1),K=o.useRef(!1);o.useEffect(()=>{u.current=w},[w]),o.useEffect(()=>{K.current=!1,T([]),k(h=>h+1)},[e.invocation_id]),o.useEffect(()=>{if(!t||s||K.current)return;const h=u.current.bootstrapConversation;if(!h){Ee(u.current.openingMessage(),T);return}K.current=!0;let S=!1;return V(!0),(async()=>{try{const X=await h.call(u.current);if(S)return;T(X.map(ce))}catch{S||Ee(u.current.openingMessage(),T)}finally{S||V(!1)}})(),()=>{S=!0}},[t,s,e.invocation_id,w]);const Y=o.useCallback(h=>{h.checklist&&F(h.checklist),h.phase&&m(h.phase)},[]);o.useEffect(()=>{var h,S;!t||s||i&&i.length>0&&((S=(h=u.current).seedChecklist)==null||S.call(h,i))},[t,s,i]),o.useEffect(()=>{if(!t||s||!c)return;let h=!1;return B(!(i!=null&&i.length)),re(null),(async()=>{var S,X;try{const oe=await c(e.invocation_id);if(h)return;i!=null&&i.length||(F(oe.checklist),(X=(S=u.current).seedChecklist)==null||X.call(S,oe.checklist))}catch{!h&&!(i!=null&&i.length)&&re(we)}finally{h||B(!1)}})(),()=>{h=!0}},[t,e.invocation_id,s,i,c]),o.useEffect(()=>{if(!t||!g)return;let h=!1;return J(!0),j(null),(async()=>{try{const S=await g(e.invocation_id);h||ae(S)}catch{h||j(at)}finally{h||J(!1)}})(),()=>{h=!0}},[t,e.invocation_id,g]),o.useEffect(()=>{if(!t||!s||K.current)return;K.current=!0;const h={id:`user-brief-${Date.now()}`,author:W.user,text:Nt(s,e.invocation_name)};(async()=>{const S=await u.current.start(s);T([ce(u.current.openingMessage()),ce(h),ce(S.message)]),S.checklist&&F(S.checklist),m(S.phase??b.running)})()},[t,s,e.invocation_name]);const de=o.useCallback(h=>{D(yt(h))},[]),ge=o.useCallback(h=>{D(null),y(h),k(S=>S+1)},[]),ue=o.useCallback(async()=>{await u.current.stop(),m(b.stopped)},[]),pe=O;return n.jsxs(d.Modal,{open:t,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:e.invocation_name}),n.jsx("span",{className:P("agent-workspace__phase",`agent-workspace__phase--${p}`),children:ct[p]})]}),n.jsxs("div",{className:"agent-workspace__header-actions",children:[n.jsx(d.Button,{variant:"tertiary",size:"S",iconLeftName:"clipboard-list",iconLeftScreenReaderText:"Toggle checklist","aria-pressed":!z,onClick:()=>fe(h=>!h),children:"Checklist"}),n.jsx(d.Button,{variant:"tertiary",size:"S",iconLeftName:"files",iconLeftScreenReaderText:"Toggle resources","aria-pressed":!q,onClick:()=>me(h=>!h),children:"Resources"}),n.jsx(d.Button,{variant:"secondary",size:"S",iconLeftName:"x",iconLeftScreenReaderText:"Close",onClick:a,children:"Close"})]})]}),n.jsxs(d.Modal.Body,{className:P("agent-workspace__body",{"agent-workspace__body--no-left":z,"agent-workspace__body--no-right":q}),children:[!z&&n.jsx(xt,{checklist:pe,isLoading:G,error:R,phase:p,canRequestInput:p===b.running&&!_e,onStop:()=>void ue(),onAttentionItemClick:de}),n.jsx(wt,{connector:u.current,phase:p,chatHistory:x,chatSessionKey:I,startQuery:M,clarificationMessage:L,onTurn:Y,onAwaitingChange:V,onClarificationPrompt:ge,onDismissClarification:()=>D(null)}),!q&&n.jsx(At,{resources:H,isLoading:Q,error:A})]})]})},De=({open:e,onClose:t,onStart:a,agentDefinitions:s})=>{const r=s[0],[i,c]=o.useState(r),[g,w]=o.useState(""),[u,p]=o.useState(!1),[m,x]=o.useState(null),T=[...s].sort((y,L)=>y.agent_intent.localeCompare(L.agent_intent)).map(y=>({value:y.ref,label:y.agent_intent}));o.useEffect(()=>{e&&(c(r),w(""),p(!1),x(null))},[e,r]);const I=i!==void 0&&g.trim().length>0,k=o.useCallback(y=>{const L=s.find(D=>D.ref===y[0]);L&&c(L)},[s]),M=o.useCallback(async()=>{if(!(!i||!I||u)){p(!0),x(null);try{await a({definition:i,invocationName:g.trim()})}catch(y){x(y instanceof Error?y.message:"Unable to start the agent.")}finally{p(!1)}}},[I,i,g,u,a]);return!i||s.length===0?null:n.jsxs(d.Modal,{open:e,closeHandler:t,className:"new-agent",children:[n.jsx(d.Modal.Header,{className:"new-agent__header",children:n.jsxs("div",{className:"new-agent__header-title",children:[n.jsx("span",{className:"new-agent__header-avatar","aria-hidden":"true",children:n.jsx(d.Icon,{name:"ask-arbor",size:24})}),n.jsx(d.Modal.Title,{children:"Start an agent"})]})}),n.jsx(d.Modal.Body,{className:"new-agent__body",children:n.jsxs("form",{className:"new-agent__form","aria-label":"Start an agent",onSubmit:y=>{y.preventDefault(),I&&!u&&M()},children:[n.jsxs("div",{className:"new-agent__type-field",children:[n.jsx("label",{className:"new-agent__type-label",htmlFor:"new-agent-type",children:"What would you like your agent to do?"}),n.jsx(d.SelectDropdown,{id:"new-agent-type",placeholder:"Choose an intent",options:T,selectedValues:[i.ref],onSelectionChange:k}),n.jsx("p",{className:"new-agent__type-description",children:i.description})]}),n.jsxs("div",{className:"new-agent__type-field",children:[n.jsx("label",{className:"new-agent__type-label",htmlFor:"new-agent-invocation-name",children:"Name"}),n.jsx(d.TextInput,{id:"new-agent-invocation-name",value:g,placeholder:"e.g. Test with memory3",onChange:y=>w(y.target.value)})]}),m?n.jsx("p",{className:"new-agent__error",role:"alert",children:m}):null,n.jsx("div",{className:"new-agent__actions",children:n.jsx(d.Button,{type:"submit",variant:"primary",disabled:!I||u,iconLeftName:u?"loader":"sparkles",iconLeftScreenReaderText:u?"Starting":void 0,children:u?"Starting…":"Start"})})]})})]})};class te extends Error{constructor(t,a,s){super(s??`Agent service request failed (${t})`),this.name="AgentServiceError",this.status=t,this.detail=a}}const bt="/api/v1",C={agentDefinitions:"/agent-definitions",agents:"/agents",tripOptions:"/trip-options",demoDataset:"/demo/dataset"},E={GET:"GET",POST:"POST"},Ct={error:"error"},Et={user:"user"},ne={acceptJson:"application/json",acceptEventStream:"text/event-stream",contentTypeJson:"application/json",arborApplicationUrl:"X-Arbor-Application-Url"},Tt=/:invocationId\b/g,It=e=>e.trim().replace(/^Bearer\s+/i,""),Rt=e=>e.endsWith("/")?e.slice(0,-1):e;class He{constructor(t){var s;this.baseUrl=Rt(t.baseUrl);const a=(s=t.token)==null?void 0:s.trim();this.token=a?It(a):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(E.GET,this.resolveUrl("agentDefinitions",C.agentDefinitions))).agent_definitions??[]}getAgentDefinition(t){return this.request(E.GET,this.apiUrl(`${C.agentDefinitions}/${encodeURIComponent(t)}`))}listTripOptions(){return this.request(E.GET,this.apiUrl(C.tripOptions))}getDataset(){return this.request(E.GET,this.apiUrl(C.demoDataset))}setDataset(t){return this.request(E.POST,this.apiUrl(C.demoDataset),{dataset:t})}listAgents(t={}){const a=new URLSearchParams;t.status&&a.set("status",t.status),t.agentDefinitionRef&&a.set("agent_definition_ref",t.agentDefinitionRef);const s=a.toString()?`?${a.toString()}`:"";return this.request(E.GET,`${this.resolveUrl("agents",C.agents)}${s}`)}createAgent(t,a={}){var c,g;const s={agent_definition_ref:t},r=(c=a.invocationName)==null?void 0:c.trim(),i=(g=a.agentIntent)==null?void 0:g.trim();return r&&(s.invocation_name=r),i&&(s.agent_intent=i),this.request(E.POST,this.resolveUrl("agents",C.agents),s)}getAgent(t){return this.request(E.GET,this.resolveUrl("agent",`${C.agents}/${encodeURIComponent(t)}`,t))}getAgentChecklist(t){return this.request(E.GET,this.resolveUrl("agentChecklist",`${C.agents}/${encodeURIComponent(t)}/checklist`,t))}getAgentResources(t){return this.request(E.GET,this.resolveUrl("agentResources",`${C.agents}/${encodeURIComponent(t)}/resources`,t))}getAgentContext(t){return this.request(E.GET,this.apiUrl(`${C.agents}/${encodeURIComponent(t)}/context`))}cancelAgent(t){return this.request(E.POST,this.apiUrl(`${C.agents}/${encodeURIComponent(t)}/cancel`))}archiveAgent(t){return this.request(E.POST,this.apiUrl(`${C.agents}/${encodeURIComponent(t)}/archive`))}async chat(t,a,s={}){const r=await this.fetchImpl(this.resolveUrl("agentChat",`${C.agents}/${encodeURIComponent(t)}/chat`,t),{method:E.POST,headers:{...this.customHeaders,...this.authHeaders(),Accept:ne.acceptEventStream,"Content-Type":ne.contentTypeJson},body:JSON.stringify(a),signal:s.signal});if(!r.ok)throw await this.toError(r);if(!r.body)throw new te(r.status,null,"Chat response contained no stream body");return this.consumeSse(r.body,s.onEvent)}authHeaders(){return this.token?{Authorization:`Bearer ${this.token}`}:{}}apiUrl(t){return`${this.baseUrl}${bt}${t}`}resolveUrl(t,a,s){const r=this.urls[t];return r?s?r.replace(Tt,encodeURIComponent(s)):r:this.apiUrl(a)}async request(t,a,s){const r=await this.fetchImpl(a,{method:t,headers:{...this.customHeaders,...this.authHeaders(),Accept:ne.acceptJson,...s===void 0?{}:{"Content-Type":ne.contentTypeJson}},...s===void 0?{}:{body:JSON.stringify(s)}});if(!r.ok)throw await this.toError(r);if(r.status!==204)return await r.json()}async toError(t){let a=null;try{a=await t.json()}catch{}return new te(t.status,a,`Agent service request failed (${t.status} ${t.statusText})`)}async consumeSse(t,a){const s=t.getReader(),r=new TextDecoder;let i="",c;const g=w=>{const{event:u,data:p}=Ot(w);if(p===null)return;if(u===Ct.error){const x=Te(p);throw new te(502,x,(x==null?void 0:x.message)??"Chat stream error")}const m=Te(p);m&&(c=m,a==null||a(m))};for(;;){const{done:w,value:u}=await s.read();if(w)break;i+=r.decode(u,{stream:!0});const p=i.split(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),i=require("react"),L=require("classnames"),u=require("@arbor-education/design-system.components"),se=require("@arbor-education/ask-arbor-chat-panel"),v={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},S={"generating-a-response":"generating-a-response",hitl:"hitl",complete:"complete",failed:"failed"},N={briefing:"briefing",running:"running",stopped:"stopped",complete:"complete"},B={agent:"agent",user:"user",system:"system"},Z={MIS_RECORD:"MIS_RECORD",FILE:"FILE",WORKFLOW:"WORKFLOW",LINK:"LINK"},Te={cancelled:"cancelled",archived:"archived"},ke={in_progress:"in_progress",requires_attention:"requires_attention",available:"available"},U={[S.complete]:{label:"Complete",icon:"circle-check",color:"var(--color-semantic-success-600)"},[S.failed]:{label:"Failed",icon:"circle-x",color:"var(--color-semantic-destructive-600)"},[S.hitl]:{label:"Requires attention",icon:"triangle-alert",color:"var(--color-semantic-warning-600)"},[S["generating-a-response"]]:{label:"Generating a response",icon:"loader",color:"var(--color-brand-600)"}},pe={[v["generating-a-response"]]:{status:v["generating-a-response"],title:"Active",dotColour:"green",statusIcon:{name:U["generating-a-response"].icon,color:U["generating-a-response"].color,spin:!0}},[v.hitl]:{status:v.hitl,title:"Requires attention",dotColour:"orange",statusIcon:{name:U.hitl.icon,color:U.hitl.color}},[v.complete]:{status:v.complete,title:"Complete",dotColour:"green",dotModifier:"grey-dark",statusIcon:{name:U.complete.icon,color:U.complete.color}},[v.failed]:{status:v.failed,title:"Failed",dotColour:"salmon",statusIcon:{name:U.failed.icon,color:U.failed.color}}},Xe=[v["generating-a-response"],v.hitl],Ze=[v.complete,v.failed],et="m4",tt="1",$e="msg-opening",Ae="Unable to load agent tasks. Please try again.",nt="Unable to load the resources for this agent",st="Something went wrong. Please try again.",De="Unable to load agents. Please try again.",ee="Loading tasks…",Ie="Loading agents…",at="Task",rt="What recent actions have you taken?",ot={[N.briefing]:"Briefing",[N.running]:"Working",[N.stopped]:"Stopped",[N.complete]:"Complete"},it=[v["generating-a-response"],v.hitl,v.complete,v.failed],ct={[v["generating-a-response"]]:"Agents currently working on tasks for you.",[v.hitl]:"Agents that need your input before they can continue.",[v.complete]:"Agents that have finished their work.",[v.failed]:"Agents that failed or were stopped."},lt=()=>n.jsxs("svg",{className:"agent-view__empty-illustration",viewBox:"0 0 360 240",xmlns:"http://www.w3.org/2000/svg",role:"img","aria-label":"Preview of the agents board layout",children:[n.jsx("rect",{x:"0",y:"0",width:"360",height:"240",rx:"12",fill:"var(--color-grey-100)"}),n.jsx("rect",{x:"16",y:"16",width:"100",height:"208",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"130",y:"16",width:"100",height:"208",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"244",y:"16",width:"100",height:"100",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"244",y:"124",width:"100",height:"100",rx:"8",fill:"var(--card-default-color-background)",stroke:"var(--card-default-color-border)"}),n.jsx("rect",{x:"28",y:"52",width:"76",height:"36",rx:"6",fill:"var(--color-grey-050)"}),n.jsx("rect",{x:"28",y:"96",width:"76",height:"36",rx:"6",fill:"var(--color-grey-050)"}),n.jsx("rect",{x:"142",y:"52",width:"76",height:"36",rx:"6",fill:"var(--color-semantic-warning-050)"}),n.jsx("circle",{cx:"40",cy:"70",r:"4",fill:"var(--color-brand-600)"}),n.jsx("circle",{cx:"40",cy:"114",r:"4",fill:"var(--color-brand-600)"}),n.jsx("circle",{cx:"154",cy:"70",r:"4",fill:"var(--color-semantic-warning-600)"}),n.jsx("circle",{cx:"256",cy:"52",r:"4",fill:"var(--color-grey-400)"}),n.jsx("circle",{cx:"256",cy:"160",r:"4",fill:"var(--color-semantic-destructive-500)"})]}),dt=({status:e})=>{const t=pe[e];return t.statusIcon?n.jsx(u.Icon,{name:t.statusIcon.name,size:16,color:t.statusIcon.color,screenReaderText:t.title}):n.jsx(u.Dot,{colour:t.dotColour,label:t.title})},gt=()=>n.jsxs("section",{className:"agent-view__empty","aria-label":"About the agents board",children:[n.jsxs("div",{className:"agent-view__empty-content",children:[n.jsx(u.Heading,{level:4,children:"Your agents board"}),n.jsx("p",{className:"agent-view__empty-lead",children:"When you start an agent, it appears here so you can track progress at a glance. Agents move between columns as their status changes."}),n.jsx("ul",{className:"agent-view__empty-columns",children:it.map(e=>{const t=pe[e];return n.jsxs("li",{className:"agent-view__empty-column",children:[n.jsx("span",{className:"agent-view__empty-column-indicator",children:n.jsx(dt,{status:e})}),n.jsxs("span",{className:"agent-view__empty-column-text",children:[n.jsx("span",{className:"agent-view__empty-column-title",children:t.title}),n.jsx("span",{className:"agent-view__empty-column-description",children:ct[e]})]})]},e)})}),n.jsxs("p",{className:"agent-view__empty-hint",children:["Use ",n.jsx("strong",{children:"Start an agent"})," above to begin."]})]}),n.jsx("div",{className:"agent-view__empty-visual",children:n.jsx(lt,{})})]}),ut=(e,t)=>({...e,...t.length>0?{children:t}:{}}),He=e=>{const t=[],s=[];for(const a of e){const r=a.children?He(a.children):{needsInput:[],tasks:[]};if(t.push(...r.needsInput),a.status===S.hitl){t.push({...a,children:void 0});continue}s.push(ut(a,r.tasks))}return{needsInput:t,tasks:s}},pt=e=>e.map((t,s)=>({item:t,index:s})).sort((t,s)=>{const a=t.item.status===S.hitl,r=s.item.status===S.hitl;return a!==r?a?-1:1:t.index-s.index}).map(({item:t})=>t),ht=({checklist:e})=>e.length===0?n.jsx("p",{className:"agent-view__progress-empty",children:"No tasks to display."}):n.jsx("ul",{className:"agent-view__progress-list","aria-label":"Agent tasks",children:pt(e).map(t=>{const s=U[t.status];return n.jsxs("li",{className:L("agent-view__progress-item",`agent-view__progress-item--${t.status.replace(/_/g,"-")}`),children:[n.jsx(u.Icon,{name:s.icon,size:16,color:s.color,screenReaderText:`${s.label}:`,className:L({"agent-view__progress-icon--spinning":t.status===S["generating-a-response"]})}),n.jsxs("div",{className:"agent-view__progress-item-content",children:[n.jsx("span",{className:"agent-view__progress-label",children:t.task}),t.status!==S.complete&&n.jsx("span",{className:"agent-view__progress-description",children:t.description})]})]},t.task)})}),mt=({prompts:e,classNamePrefix:t="agent-workspace",onSelect:s})=>e.length===0?null:n.jsx("div",{className:`${t}__chips`,children:e.map(a=>n.jsx("button",{type:"button",className:`${t}__chip`,onClick:()=>s(a),children:a},a))});class _t{constructor(t,s){this.connector=t,this.canSend=s.canSend,this.onTurn=s.onTurn,this.onAwaitingChange=s.onAwaitingChange}get canRate(){return!1}get canLoadHistory(){return!1}get canListInteractions(){return!1}get canSendNotification(){return!1}get ratingPopupUrls(){return{}}async sendMessage(t){var s,a;if(!this.canSend())return null;(s=this.onAwaitingChange)==null||s.call(this,!0);try{const r=await this.connector.sendMessage(t.userMessage);return this.onTurn(r),{id:r.message.id,text:r.message.text,type:se.CHAT_RESPONSE_TYPE_AGENT,...r.message.followUpPrompts?{followUpPrompts:r.message.followUpPrompts}:{}}}catch{return{id:`error-${Date.now()}`,text:st,type:se.CHAT_RESPONSE_TYPE_ERROR}}finally{(a=this.onAwaitingChange)==null||a.call(this,!1)}}async loadHistory(t){return null}async listInteractions(){return null}async rateMessage(t){}async sendNotification(t){return!1}}const ft=({connector:e,phase:t,chatHistory:s,chatSessionKey:a,startQuery:r,clarificationMessage:d,enableUpload:g=!1,onTurn:l,onAwaitingChange:w,onClarificationPrompt:f,onDismissClarification:p})=>{const _=i.useMemo(()=>new _t(e,{canSend:()=>t===N.running,onTurn:l,onAwaitingChange:w}),[e,t,l,w]),h=t!==N.running,j=t===N.running;return n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--chat","aria-label":"Chat",children:[d&&n.jsxs("div",{className:"agent-workspace__clarification",role:"region","aria-label":"Agent question",children:[n.jsx("p",{className:"agent-workspace__clarification-text",children:d.text}),d.followUpPrompts&&n.jsx(mt,{prompts:d.followUpPrompts,onSelect:f}),n.jsx("button",{type:"button",className:"agent-workspace__clarification-dismiss",onClick:p,children:"Dismiss"})]}),n.jsx("div",{className:"agent-workspace__ask-arbor",children:n.jsx(se.ChatPanel,{connector:_,chatHistory:s,startQuery:r,lockConversation:h,enableUpload:g,speechEnabled:j,speechLanguage:"en-GB",speechSubmissionDelay:1e3,slashMenuItems:[],menuContent:[],introHeading:"Message your agent",introBody:"Ask questions, share trip details, or paste a link. The agent will update the checklist as it works.",placeholder:j?"Message the agent, paste a link, or attach a file…":"The agent is not accepting messages."},a)}),t===N.stopped&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(u.Icon,{name:"circle-alert",size:16,color:"var(--color-semantic-warning-600)"}),n.jsx("span",{children:"You stopped the agent. Its progress is saved in the checklist on the left."})]}),t===N.complete&&n.jsxs("div",{className:"agent-workspace__notice",role:"status",children:[n.jsx(u.Icon,{name:"party-popper",size:16,color:"var(--color-semantic-success-600)"}),n.jsx("span",{children:"The agent has finished."})]})]})},Fe=({item:e,depth:t,canRequestInput:s,onAttentionItemClick:a})=>{const r=U[e.status],d=e.status.replace(/_/g,"-"),g=e.status===S.hitl&&s&&a,l=n.jsxs("div",{className:"agent-workspace__task-row",children:[n.jsx(u.Icon,{name:r.icon,size:16,color:r.color,screenReaderText:`${r.label}:`,className:L({"agent-workspace__task-icon--spinning":e.status===S["generating-a-response"]})}),n.jsxs("div",{className:"agent-workspace__task-content",children:[n.jsx("span",{className:"agent-workspace__task-label",children:e.task}),e.status!==S.complete&&e.description&&n.jsx("span",{className:"agent-workspace__task-description",children:e.description})]})]});return n.jsxs("li",{className:L("agent-workspace__task",`agent-workspace__task--${d}`,{"agent-workspace__task--child":t>0}),children:[g?n.jsx("button",{type:"button",className:"agent-workspace__task-button","aria-label":`Provide input for ${e.task}`,onClick:()=>a(e),children:l}):l,e.children&&e.children.length>0&&n.jsx("ul",{className:"agent-workspace__task-children",children:e.children.map(w=>n.jsx(Fe,{item:w,depth:t+1,canRequestInput:s,onAttentionItemClick:a},w.task))})]})},Re=({items:e,ariaLabel:t,canRequestInput:s,onAttentionItemClick:a})=>n.jsx("ul",{className:"agent-workspace__task-list","aria-label":t,children:e.map(r=>n.jsx(Fe,{item:r,depth:0,canRequestInput:s,onAttentionItemClick:a},r.task))}),vt=({checklist:e,isLoading:t,error:s,phase:a,canRequestInput:r,onStop:d,onAttentionItemClick:g})=>{const l=i.useMemo(()=>e?He(e):null,[e]);return n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--checklist","aria-label":"Checklist",children:[n.jsxs("div",{className:"agent-workspace__panel-header",children:[n.jsx(u.Heading,{level:4,children:"Checklist"}),a===N.running&&n.jsx(u.Button,{variant:"secondary-destructive",size:"S",iconLeftName:"circle-x",iconLeftScreenReaderText:"Stop",onClick:d,children:"Stop agent"})]}),n.jsxs("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:[t&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:ee}),n.jsx("span",{children:ee})]}),!t&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!t&&!s&&l&&n.jsxs(n.Fragment,{children:[l.needsInput.length>0&&n.jsxs("div",{className:"agent-workspace__task-group",children:[n.jsx("p",{className:"agent-workspace__task-group-label",children:"Needs your input"}),n.jsx(Re,{items:l.needsInput,ariaLabel:"Tasks needing your input",canRequestInput:r,onAttentionItemClick:g})]}),l.tasks.length>0&&n.jsxs("div",{className:L("agent-workspace__task-group",{"agent-workspace__task-group--following":l.needsInput.length>0}),children:[l.needsInput.length>0&&n.jsx("p",{className:"agent-workspace__task-group-label",children:"Other tasks"}),n.jsx(Re,{items:l.tasks,ariaLabel:"Agent tasks",canRequestInput:r,onAttentionItemClick:g})]})]}),!t&&!s&&(!l||l.needsInput.length===0&&l.tasks.length===0)&&n.jsx("p",{className:"agent-workspace__empty",children:a===N.briefing?"Tasks will appear here once the agent starts.":"No tasks to display."})]})]})},wt={[Z.MIS_RECORD]:{icon:"table",label:"Arbor MIS",color:"var(--color-brand-600)"},[Z.FILE]:{icon:"file",label:"File",color:"var(--color-semantic-caution-800)"},[Z.WORKFLOW]:{icon:"list-tree",label:"Workflow",color:"var(--color-semantic-warning-700)"},[Z.LINK]:{icon:"link",label:"Link",color:"var(--color-semantic-info-700)"}},xt=({resources:e,isLoading:t=!1,error:s=null})=>n.jsxs("section",{className:"agent-workspace__panel agent-workspace__panel--documents","aria-label":"Resources",children:[n.jsxs("div",{className:"agent-workspace__panel-header",children:[n.jsx(u.Heading,{level:4,children:"Resources"}),n.jsx("span",{className:"agent-workspace__panel-count",children:e.length})]}),n.jsxs("div",{className:"agent-workspace__panel-body","aria-live":"polite",children:[t&&n.jsxs("div",{className:"agent-workspace__loading",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-workspace__task-icon--spinning",screenReaderText:"Loading resources"}),n.jsx("span",{children:"Loading resources…"})]}),!t&&s&&n.jsx("p",{className:"agent-workspace__error",role:"alert",children:s}),!t&&!s&&e.length>0&&n.jsx("ul",{className:"agent-workspace__resource-list","aria-label":"Agent resources",children:e.map(a=>{const r=wt[a.type];return n.jsx("li",{className:"agent-workspace__resource",children:n.jsxs("a",{className:"agent-workspace__resource-card",href:a.uri,target:"_blank",rel:"noreferrer",children:[n.jsx("span",{className:`agent-workspace__resource-icon agent-workspace__resource-icon--${a.type.toLowerCase()}`,children:n.jsx(u.Icon,{name:r.icon,size:16,color:r.color,screenReaderText:`${r.label}:`})}),n.jsxs("span",{className:"agent-workspace__resource-content",children:[n.jsxs("span",{className:"agent-workspace__resource-top",children:[n.jsx("span",{className:"agent-workspace__resource-name",children:a.name}),n.jsx("span",{className:`agent-workspace__resource-badge agent-workspace__resource-badge--${a.type.toLowerCase()}`,children:r.label})]}),a.description&&n.jsx("span",{className:"agent-workspace__resource-description",children:a.description})]}),n.jsx(u.Icon,{name:"external-link",size:12,color:"var(--color-grey-500)",screenReaderText:"Opens in a new tab",className:"agent-workspace__resource-open"})]})},`${a.type}-${a.uri}`)})}),!t&&!s&&e.length===0&&n.jsx("p",{className:"agent-workspace__empty",children:"No resources yet."})]})]}),kt=["I'll get the details and come back to you","Skip this for now"],At=e=>{var s;const t=(s=e.prompt)!=null&&s.trim()?e.prompt.trim():`I need a bit more from you on "${e.task}". ${e.description} What can you tell me?`;return{id:`clarification-${Date.now()}`,author:B.agent,text:t,followUpPrompts:e.clarificationPrompts??kt}},ce=e=>({id:e.id,text:e.text,type:e.author===B.user?se.CHAT_RESPONSE_TYPE_USER:e.author===B.system?se.CHAT_RESPONSE_TYPE_INFO:se.CHAT_RESPONSE_TYPE_AGENT,...e.followUpPrompts?{followUpPrompts:e.followUpPrompts}:{}});class te extends Error{constructor(t,s,a){super(a??`Agent service request failed (${t})`),this.name="AgentServiceError",this.status=t,this.detail=s}}const yt="/api/v1",E={agentDefinitions:"/agent-definitions",agents:"/agents",tripOptions:"/trip-options",demoDataset:"/demo/dataset"},T={GET:"GET",POST:"POST"},St={error:"error"},Nt={user:"user"},ne={acceptJson:"application/json",acceptEventStream:"text/event-stream",contentTypeJson:"application/json",arborApplicationUrl:"X-Arbor-Application-Url"},jt=/:invocationId\b/g,Ct=e=>e.trim().replace(/^Bearer\s+/i,""),bt=e=>e.endsWith("/")?e.slice(0,-1):e;class Ne{constructor(t){var a;this.baseUrl=bt(t.baseUrl??"");const s=(a=t.token)==null?void 0:a.trim();this.token=s?Ct(s):void 0,this.customHeaders=t.headers,this.urls=t.urls??{},this.fetchImpl=t.fetch??globalThis.fetch.bind(globalThis)}setHeaders(t){this.customHeaders=t}async listAgentDefinitions(){return(await this.request(T.GET,this.resolveUrl("agentDefinitions",E.agentDefinitions))).agent_definitions??[]}getAgentDefinition(t){return this.request(T.GET,this.apiUrl(`${E.agentDefinitions}/${encodeURIComponent(t)}`))}listTripOptions(){return this.request(T.GET,this.apiUrl(E.tripOptions))}getDataset(){return this.request(T.GET,this.apiUrl(E.demoDataset))}setDataset(t){return this.request(T.POST,this.apiUrl(E.demoDataset),{dataset:t})}listAgents(t={}){const s=new URLSearchParams;t.status&&s.set("status",t.status),t.agentDefinitionRef&&s.set("agent_definition_ref",t.agentDefinitionRef);const a=s.toString()?`?${s.toString()}`:"";return this.request(T.GET,`${this.resolveUrl("agents",E.agents)}${a}`)}createAgent(t,s={}){var g,l;const a={agent_definition_ref:t},r=(g=s.invocationName)==null?void 0:g.trim(),d=(l=s.agentIntent)==null?void 0:l.trim();return r&&(a.invocation_name=r),d&&(a.agent_intent=d),this.request(T.POST,this.resolveUrl("agents",E.agents),a)}getAgent(t){return this.request(T.GET,this.resolveUrl("agent",`${E.agents}/${encodeURIComponent(t)}`,t))}getAgentChecklist(t){return this.request(T.GET,this.resolveUrl("agentChecklist",`${E.agents}/${encodeURIComponent(t)}/checklist`,t))}getAgentResources(t){return this.request(T.GET,this.resolveUrl("agentResources",`${E.agents}/${encodeURIComponent(t)}/resources`,t))}getAgentContext(t){return this.request(T.GET,this.apiUrl(`${E.agents}/${encodeURIComponent(t)}/context`))}cancelAgent(t){return this.request(T.POST,this.apiUrl(`${E.agents}/${encodeURIComponent(t)}/cancel`))}archiveAgent(t){return this.request(T.POST,this.apiUrl(`${E.agents}/${encodeURIComponent(t)}/archive`))}async chat(t,s,a={}){const r=await this.fetchImpl(this.resolveUrl("agentChat",`${E.agents}/${encodeURIComponent(t)}/chat`,t),{method:T.POST,headers:{...this.customHeaders,...this.authHeaders(),Accept:ne.acceptEventStream,"Content-Type":ne.contentTypeJson},body:JSON.stringify(s),signal:a.signal});if(!r.ok)throw await this.toError(r);if(!r.body)throw new te(r.status,null,"Chat response contained no stream body");return this.consumeSse(r.body,a.onEvent)}authHeaders(){return this.token?{Authorization:`Bearer ${this.token}`}:{}}apiUrl(t){return`${this.baseUrl}${yt}${t}`}resolveUrl(t,s,a){const r=this.urls[t];return r?a?r.replace(jt,encodeURIComponent(a)):r:this.apiUrl(s)}async request(t,s,a){const r=await this.fetchImpl(s,{method:t,headers:{...this.customHeaders,...this.authHeaders(),Accept:ne.acceptJson,...a===void 0?{}:{"Content-Type":ne.contentTypeJson}},...a===void 0?{}:{body:JSON.stringify(a)}});if(!r.ok)throw await this.toError(r);if(r.status!==204)return await r.json()}async toError(t){let s=null;try{s=await t.json()}catch{}return new te(t.status,s,`Agent service request failed (${t.status} ${t.statusText})`)}async consumeSse(t,s){const a=t.getReader(),r=new TextDecoder;let d="",g;const l=w=>{const{event:f,data:p}=Et(w);if(p===null)return;if(f===St.error){const h=Oe(p);throw new te(502,h,(h==null?void 0:h.message)??"Chat stream error")}const _=Oe(p);_&&(g=_,s==null||s(_))};for(;;){const{done:w,value:f}=await a.read();if(w)break;d+=r.decode(f,{stream:!0});const p=d.split(`
|
|
2
2
|
|
|
3
|
-
`);
|
|
4
|
-
`)){const r=
|
|
5
|
-
`):null}},Te=e=>{try{return JSON.parse(e)}catch{return}},Pt={id:Pe,author:W.agent,text:"I'm connected to this agent. Ask me how it's progressing, or send an instruction and I’ll act on it."};let Ie=0;const Re=e=>(Ie+=1,`${e}-${Date.now()}-${Ie}`),Mt=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 Fe{constructor(t,a,s={}){this.seededChecklist=[],this.client=t,this.agentId=a,this.opening=s.openingMessage??Pt,this.model=s.model,this.bootstrapPrompt=s.bootstrapPrompt??it}openingMessage(){return this.opening}async bootstrapConversation(t=this.bootstrapPrompt){const a=t.trim();if(!a)return[this.opening];const s={id:Re("msg-user"),author:W.user,text:a},r=await this.exchange(a);return[s,r.message]}async start(t){return{...await this.exchange(Mt(t)),phase:b.running}}sendMessage(t){return this.exchange(t)}async stop(){}seedChecklist(t){this.seededChecklist=t}async exchange(t){var i;const a=[{role:Et.user,content:t}],s=await this.client.chat(this.agentId,{messages:a,...this.chatId?{chat_id:this.chatId}:{},...this.model?{model:this.model}:{},moderation_enabled:!0,meta:{feature_id:"agent_view",source:"agent_view_frontend"}});return this.chatId=s.chat_id,{message:{id:s.event_id||Re("msg-agent"),author:W.agent,text:s.message.content,...(i=s.follow_up_prompts)!=null&&i.length?{followUpPrompts:s.follow_up_prompts}:{}}}}}const Be=(e,t)=>a=>{var s;return new Fe(e,a.invocation_id,{model:t==null?void 0:t.model,bootstrapPrompt:t==null?void 0:t.bootstrapPrompt,openingMessage:((s=t==null?void 0:t.resolveOpeningMessage)==null?void 0:s.call(t,a))??(t==null?void 0:t.openingMessage)})},Ge=e=>{switch(e){case je.cancelled:return v.failed;case je.archived:return v.complete;case v.hitl:case v.complete:case v.failed:case v["generating-a-response"]:return e;default:return v["generating-a-response"]}},qe=e=>{switch(e){case ve.requires_attention:return N.hitl;case ve.in_progress:case ve.available:return N["generating-a-response"];case N.failed:case N.complete:case N.hitl:case N["generating-a-response"]:return e;default:return N["generating-a-response"]}},ze=e=>({ref:e.name,display_name:e.display_name,agent_intent:e.agent_intent??e.display_name,description:e.description}),Lt=e=>({id:e.id,name:e.name,...e.has_run_before?{hasRunBefore:e.has_run_before}:{}}),Ut=new Set(Object.values(Z)),$t=e=>e&&Ut.has(e)?e:Z.LINK,Ke=e=>({uri:e.uri??"",type:$t(e.type),name:e.name??"",description:e.description??""}),We=e=>(Array.isArray(e)?e:e.resources??[]).map(Ke),xe=e=>{var a;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:((a=e.invocation_name)==null?void 0:a.trim())||e.agent_definition_ref,application_id:e.application_id,...e.application_name?{application_name:e.application_name}:{},created_by:e.created_by,status:Ge(e.status),context_ref:e.context_ref??null,checklist_ref:e.checklist_ref??null}},Ae=e=>{var t;return{task:e.task??e.name??e.label??ot,status:qe(e.status),description:e.description??"",...e.prompt?{prompt:e.prompt}:{},...(t=e.follow_up_prompts)!=null&&t.length?{clarificationPrompts:e.follow_up_prompts}:{}}},Dt=e=>Array.isArray(e)?e:e.checklist_items??e.checklist??e.items??[],Je=(e,t,a)=>{var i;const s=!Array.isArray(t)&&(t.opening_message||(i=t.opening_follow_up_prompts)!=null&&i.length)?t:a,r=s?le(s):void 0;return{invocation_id:e,checklist:Dt(t).map(Ae),...r?{openingMessage:r}:{}}},Ht=(e,t)=>{const a=le(t);return{invocation_id:t.invocation_id??e,checklist:(t.checklist_items??[]).map(Ae),...a?{openingMessage:a}:{}}},le=e=>{var a,s;const t=(a=e.opening_message)==null?void 0:a.trim();if(t)return{id:Pe,author:W.agent,text:t,...(s=e.opening_follow_up_prompts)!=null&&s.length?{followUpPrompts:e.opening_follow_up_prompts}:{}}},Ft=e=>e instanceof te?e.message:e instanceof TypeError?"Network error while contacting the agent service.":e instanceof Error&&e.message?e.message:Me,Bt=e=>{const t={};for(const a of e){const s=le(a);if(!s)continue;const r=a.invocation_id??a.id;t[r]=s,t[a.id]=s}return t},Gt=e=>JSON.stringify(e),Ve=e=>{const{jwt:t,headers:a,urls:s}=e,r=JSON.stringify(a??{}),i=Gt(s),c=o.useMemo(()=>{const{baseUrl:A,...j}=s;return new He({baseUrl:A,token:t,headers:a,urls:j})},[t,i]);o.useLayoutEffect(()=>{c.setHeaders(a)},[c,r]);const[g,w]=o.useState([]),[u,p]=o.useState([]),[m,x]=o.useState({}),[T,I]=o.useState("loading"),[k,M]=o.useState(null),[y,L]=o.useState(0);o.useEffect(()=>{let A=!1;return I("loading"),M(null),(async()=>{try{const[j,O]=await Promise.all([c.listAgents(),c.listAgentDefinitions()]);if(A)return;w(j.map(xe)),p(O.map(ze)),x(Bt(j)),I("idle")}catch(j){if(A)return;w([]),p([]),x({}),I("error"),M(Ft(j))}})(),()=>{A=!0}},[c,y]);const D=o.useCallback(()=>{L(A=>A+1)},[]),H=o.useCallback(async A=>{const[j,O]=await Promise.all([c.getAgentChecklist(A),c.getAgent(A).catch(()=>null)]);return Je(A,j,O??void 0)},[c]),ae=o.useCallback(async A=>{const j=await c.getAgentResources(A);return We(j)},[c]),Q=o.useCallback(async({definition:A,invocationName:j})=>{const O=await c.createAgent(A.ref,{invocationName:j}),F=await c.getAgent(O.id),G=xe(F),B=le(F);return w(R=>[G,...R]),B&&x(R=>({...R,[G.invocation_id]:B,[G.id]:B})),G},[c]),J=o.useMemo(()=>Be(c,{resolveOpeningMessage:A=>m[A.invocation_id]??m[A.id]}),[c,m]);return{agents:g,agentDefinitions:u,loadState:T,loadError:k,reload:D,fetchAgentChecklist:H,fetchAgentResources:ae,createAgent:Q,chatConnector:J}},qt=e=>e!==void 0&&e.some(t=>t.status===N.hitl),zt=(e,t)=>qt(t)?v.hitl:e.status,Kt=({column:e,label:t})=>e.statusIcon?n.jsx("span",{className:"agent-view__status-indicator",children:n.jsx(d.Icon,{name:e.statusIcon.name,size:16,color:e.statusIcon.color,className:P({"agent-view__progress-icon--spinning":e.statusIcon.spin}),screenReaderText:t})}):n.jsx("span",{className:P("agent-view__dot",{[`agent-view__dot--${e.dotModifier}`]:e.dotModifier}),children:n.jsx(d.Dot,{colour:e.dotColour,label:t})}),Wt=({agent:e,agentName:t,column:a,isExpanded:s,isLoading:r,checklist:i,error:c,onToggle:g,onViewAgent:w})=>{const{id:u,invocation_name:p}=e,m=`agent-card-${u}-header`,x=`agent-card-${u}-progress`;return n.jsx("li",{className:P("agent-view__card",{"agent-view__card--expanded":s}),children:n.jsxs(d.Card,{spacing:"dense",children:[n.jsx("button",{type:"button",className:"agent-view__card-toggle","aria-expanded":s,"aria-controls":x,"aria-label":p,id:m,onClick:()=>g(u),children:n.jsxs("div",{className:"agent-view__card-content",children:[n.jsx(Kt,{column:a}),n.jsx("span",{className:"agent-view__card-invocation-name",children:p}),n.jsx("span",{className:"agent-view__card-agent-name",children:t}),n.jsx(d.Icon,{name:s?"chevron-up":"chevron-down",size:16,className:"agent-view__card-chevron"})]})}),s&&n.jsxs("div",{id:x,"aria-labelledby":m,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:ee}),n.jsx("span",{children:ee})]}),!r&&c&&n.jsx("p",{className:"agent-view__progress-error",role:"alert",children:c}),!r&&!c&&i!==null&&n.jsx(mt,{checklist:i}),!r&&!c&&i===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:ee}),n.jsx("span",{children:ee})]}),n.jsx("div",{className:"agent-view__card-actions",children:n.jsx(d.Button,{variant:"secondary",size:"S",onClick:()=>w==null?void 0:w(e),children:"View agent"})})]})]})})},Oe=({column:e,agents:t,expandedAgentId:a,loadingAgentId:s,checklistByInvocationId:r,errorByAgentId:i,definitionNameByRef:c,onToggleAgent:g,onViewAgent:w,isSplit:u=!1})=>n.jsxs("section",{className:P("agent-view__column",{"agent-view__column--split":u}),"aria-label":e.title,children:[n.jsxs("div",{className:"agent-view__column-header",children:[n.jsx(d.Heading,{level:4,children:e.title}),n.jsx("span",{className:"agent-view__column-count",children:t.length})]}),n.jsx("ul",{className:"agent-view__card-list",children:t.map(p=>n.jsx(Wt,{agent:p,agentName:ke(p,c),column:e,isExpanded:a===p.id,isLoading:s===p.id,checklist:r[p.invocation_id]??null,error:i[p.id]??null,onToggle:g,onViewAgent:w},p.id))})]}),ke=(e,t)=>t.get(e.agent_definition_ref)??e.agent_definition_ref.replace(/_/g," "),Jt=({jwt:e,headers:t,baseUrl:a,agentDefinitionsUrl:s,agentsUrl:r,agentUrl:i,agentChecklistUrl:c,agentResourcesUrl:g,agentChatUrl:w,institutions:u})=>{var Ne;const p=o.useMemo(()=>({baseUrl:a,...s?{agentDefinitions:s}:{},...r?{agents:r}:{},...i?{agent:i}:{},...c?{agentChecklist:c}:{},...g?{agentResources:g}:{},...w?{agentChat:w}:{}}),[a,s,r,i,c,g,w]),[m,x]=o.useState(null),T=m?(Ne=u==null?void 0:u.find(l=>l.applicationId===m.application_id))==null?void 0:Ne.applicationUrl:void 0,I=o.useMemo(()=>{const l={...t??{}};return T?l[ne.arborApplicationUrl]=T:delete l[ne.arborApplicationUrl],l},[t,T]),{agents:k,agentDefinitions:M,loadState:y,loadError:L,reload:D,fetchAgentChecklist:H,fetchAgentResources:ae,createAgent:Q,chatConnector:J}=Ve({jwt:e,headers:I,urls:p}),[A,j]=o.useState(!1),[O,F]=o.useState(null),[G,B]=o.useState(null),[R,re]=o.useState({}),[_e,V]=o.useState({}),[q,me]=o.useState([]),[z,fe]=o.useState([]),K=o.useMemo(()=>{const l=new Set(k.map(_=>_.application_id)),f=new Map((u??[]).map(_=>[_.applicationId,_.name]));return[...l].sort((_,U)=>(f.get(_)??_).localeCompare(f.get(U)??U)).map(_=>({value:_,label:f.get(_)??_}))},[k,u]),Y=o.useMemo(()=>new Map(M.map(l=>[l.ref,l.display_name])),[M]),de=o.useMemo(()=>[...new Set(k.map(f=>ke(f,Y)))].sort((f,_)=>f.localeCompare(_)).map(f=>({value:f,label:f})),[k,Y]),ge=o.useMemo(()=>k.filter(l=>!(q.length>0&&!q.includes(l.application_id)||z.length>0&&!z.includes(ke(l,Y)))),[k,Y,z,q]),ue=K.length>1,pe=de.length>1,h=ue||pe;o.useEffect(()=>{if(k.length===0)return;let l=!1;return(async()=>{const f=await Promise.allSettled(k.map(async _=>{const U=await H(_.invocation_id);return{agentId:_.id,invocationId:_.invocation_id,checklist:U.checklist}}));l||(re(_=>{const U={..._};for(const ie of f)ie.status==="fulfilled"&&(U[ie.value.invocationId]=ie.value.checklist);return U}),V(_=>{const U={..._};return f.forEach((ie,Ze)=>{ie.status==="rejected"&&(U[k[Ze].id]=we)}),U}))})(),()=>{l=!0}},[k,H]);const S=o.useCallback(async l=>{if(!R[l.invocation_id]){B(l.id),V(f=>{const _={...f};return delete _[l.id],_});try{const f=await H(l.invocation_id);re(_=>({..._,[l.invocation_id]:f.checklist}))}catch{V(f=>({...f,[l.id]:we}))}finally{B(f=>f===l.id?null:f)}}},[H,R]),X=o.useCallback(l=>{if(O===l){F(null);return}const f=k.find(({id:_})=>_===l);f&&(F(l),S(f))},[k,O,S]),oe=o.useMemo(()=>{const l={};for(const f of ge){const _=zt(f,R[f.invocation_id]);(l[_]??(l[_]=[])).push(f)}return l},[ge,R]),Ye=o.useCallback(l=>{x(l)},[]),Qe=o.useCallback(async l=>{const f=await Q(l);x(f),j(!1)},[Q]),Xe=o.useCallback(()=>{x(null)},[]),Se=o.useMemo(()=>m?J(m):void 0,[J,m]),ye={expandedAgentId:O,loadingAgentId:G,checklistByInvocationId:R,errorByAgentId:_e,definitionNameByRef:Y,onToggleAgent:X,onViewAgent:Ye};return n.jsxs("div",{className:"agent-view-frontend agent-view",children:[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:()=>j(!0),children:"Start an agent"})]}),k.length>0&&h&&n.jsxs("div",{className:"agent-view__filters",children:[ue&&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:K,value:q,onValueChange:me,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear institutions"})]}),pe&&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:de,value:z,onValueChange:fe,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear agents"})]})]}),y==="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:L??Me}),n.jsx(d.Button,{variant:"secondary",size:"S",onClick:D,children:"Try again"})]}):y==="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:be}),n.jsx("p",{className:"agent-view__state-message",children:be})]}):k.length===0?n.jsx(pt,{}):n.jsxs("div",{className:"agent-view__board",children:[et.map(l=>n.jsx(Oe,{column:he[l],agents:oe[l]??[],...ye},l)),n.jsx("div",{className:"agent-view__split-column",children:tt.map(l=>n.jsx(Oe,{column:he[l],agents:oe[l]??[],isSplit:!0,...ye},l))})]}),m&&Se&&n.jsx($e,{agent:m,open:!0,initialChecklist:R[m.invocation_id]??null,fetchAgentChecklist:H,fetchAgentResources:ae,onClose:Xe,connector:Se},m.id),n.jsx(De,{open:A,onClose:()=>j(!1),onStart:Qe,agentDefinitions:M})]})},Vt=(e,t)=>{const a=Date.now(),s=t.trim()||e.agent_intent;return{id:`agent-${a}`,invocation_id:`inv-${a}`,agent_definition_ref:e.ref,agent_intent:e.agent_intent,invocation_name:s,application_id:nt,created_by:st,status:v["generating-a-response"],context_ref:null,checklist_ref:null}};exports.AgentMonitorKanban=Jt;exports.AgentServiceClient=He;exports.AgentServiceError=te;exports.AgentView=$e;exports.HttpChatConnector=Fe;exports.NewAgentModal=De;exports.buildAgentFromDefinition=Vt;exports.createHttpChatConnectorFactory=Be;exports.mapApiAgent=xe;exports.mapApiAgentDefinition=ze;exports.mapApiAgentStatus=Ge;exports.mapApiChecklistEndpointResponse=Je;exports.mapApiChecklistItem=Ae;exports.mapApiChecklistResponse=Ht;exports.mapApiChecklistStatus=qe;exports.mapApiOpeningMessage=le;exports.mapApiResource=Ke;exports.mapApiResourcesEndpointResponse=We;exports.mapApiTripOption=Lt;exports.useAgentService=Ve;
|
|
3
|
+
`);d=p.pop()??"";for(const _ of p)l(_)}if(d.trim()&&l(d),!g)throw new te(502,null,"Chat stream ended without any events");return g}}const Et=e=>{let t=null;const s=[];for(const a of e.split(`
|
|
4
|
+
`)){const r=a.trimEnd();r.startsWith("event:")?t=r.slice(6).trim():r.startsWith("data:")&&s.push(r.slice(5).trim())}return{event:t,data:s.length>0?s.join(`
|
|
5
|
+
`):null}},Oe=e=>{try{return JSON.parse(e)}catch{return}},Tt={id:$e,author:B.agent,text:"I'm connected to this agent. Ask me how it's progressing, or send an instruction and I’ll act on it."};let Pe=0;const Me=e=>(Pe+=1,`${e}-${Date.now()}-${Pe}`),It=e=>{const t=e.destination?` to ${e.destination}`:"";return`Let's get started on ${e.tripName.trim()||e.destination.trim()||"this task"}${t}. What will you do first?`};class Be{constructor(t,s,a={}){this.seededChecklist=[],this.client=t,this.agentId=s,this.opening=a.openingMessage??Tt,this.model=a.model,this.bootstrapPrompt=a.bootstrapPrompt??rt}openingMessage(){return this.opening}async bootstrapConversation(t=this.bootstrapPrompt){const s=t.trim();if(!s)return[this.opening];const a={id:Me("msg-user"),author:B.user,text:s},r=await this.exchange(s);return[a,r.message]}async start(t){return{...await this.exchange(It(t)),phase:N.running}}sendMessage(t){return this.exchange(t)}async stop(){}seedChecklist(t){this.seededChecklist=t}async exchange(t){var d;const s=[{role:Nt.user,content:t}],a=await this.client.chat(this.agentId,{messages:s,...this.chatId?{chat_id:this.chatId}:{},...this.model?{model:this.model}:{},moderation_enabled:!0,meta:{feature_id:"agent_view",source:"agent_view_frontend"}});return this.chatId=a.chat_id,{message:{id:a.event_id||Me("msg-agent"),author:B.agent,text:a.message.content,...(d=a.follow_up_prompts)!=null&&d.length?{followUpPrompts:a.follow_up_prompts}:{}}}}}const je=(e,t)=>s=>{var a;return new Be(e,s.invocation_id,{model:t==null?void 0:t.model,bootstrapPrompt:t==null?void 0:t.bootstrapPrompt,openingMessage:((a=t==null?void 0:t.resolveOpeningMessage)==null?void 0:a.call(t,s))??(t==null?void 0:t.openingMessage)})},Ge=e=>{switch(e){case Te.cancelled:return v.failed;case Te.archived:return v.complete;case v.hitl:case v.complete:case v.failed:case v["generating-a-response"]:return e;default:return v["generating-a-response"]}},qe=e=>{switch(e){case ke.requires_attention:return S.hitl;case ke.in_progress:case ke.available:return S["generating-a-response"];case S.failed:case S.complete:case S.hitl:case S["generating-a-response"]:return e;default:return S["generating-a-response"]}},Ke=e=>({ref:e.name,display_name:e.display_name,agent_intent:e.agent_intent??e.display_name,description:e.description}),Rt=e=>({id:e.id,name:e.name,...e.has_run_before?{hasRunBefore:e.has_run_before}:{}}),Ot=new Set(Object.values(Z)),Pt=e=>e&&Ot.has(e)?e:Z.LINK,ze=e=>({uri:e.uri??"",type:Pt(e.type),name:e.name??"",description:e.description??""}),Ce=e=>(Array.isArray(e)?e:e.resources??[]).map(ze),ye=e=>{var s;const t=e.invocation_id??e.id;return{id:e.id,invocation_id:t,agent_definition_ref:e.agent_definition_ref,...e.agent_intent?{agent_intent:e.agent_intent}:{},invocation_name:((s=e.invocation_name)==null?void 0:s.trim())||e.agent_definition_ref,application_id:e.application_id,...e.application_name?{application_name:e.application_name}:{},created_by:e.created_by,status:Ge(e.status),context_ref:e.context_ref??null,checklist_ref:e.checklist_ref??null}},be=e=>{var t;return{task:e.task??e.name??e.label??at,status:qe(e.status),description:e.description??"",...e.prompt?{prompt:e.prompt}:{},...(t=e.follow_up_prompts)!=null&&t.length?{clarificationPrompts:e.follow_up_prompts}:{}}},Mt=e=>Array.isArray(e)?e:e.checklist_items??e.checklist??e.items??[],Ee=(e,t,s)=>{var d;const a=!Array.isArray(t)&&(t.opening_message||(d=t.opening_follow_up_prompts)!=null&&d.length)?t:s,r=a?le(a):void 0;return{invocation_id:e,checklist:Mt(t).map(be),...r?{openingMessage:r}:{}}},Lt=(e,t)=>{const s=le(t);return{invocation_id:t.invocation_id??e,checklist:(t.checklist_items??[]).map(be),...s?{openingMessage:s}:{}}},le=e=>{var s,a;const t=(s=e.opening_message)==null?void 0:s.trim();if(t)return{id:$e,author:B.agent,text:t,...(a=e.opening_follow_up_prompts)!=null&&a.length?{followUpPrompts:e.opening_follow_up_prompts}:{}}},Ut=e=>e instanceof te?e.message:e instanceof TypeError?"Network error while contacting the agent service.":e instanceof Error&&e.message?e.message:De,$t=e=>{const t={};for(const s of e){const a=le(s);if(!a)continue;const r=s.invocation_id??s.id;t[r]=a,t[s.id]=a}return t},Dt=e=>JSON.stringify(e),We=e=>{const{jwt:t,headers:s,urls:a}=e,r=JSON.stringify(s??{}),d=Dt(a),g=i.useMemo(()=>new Ne({token:t,headers:s,urls:a}),[t,d]);i.useLayoutEffect(()=>{g.setHeaders(s)},[g,r]);const[l,w]=i.useState([]),[f,p]=i.useState([]),[_,h]=i.useState({}),[j,b]=i.useState("loading"),[k,y]=i.useState(null),[x,O]=i.useState(0);i.useEffect(()=>{let A=!1;return b("loading"),y(null),(async()=>{try{const[C,M]=await Promise.all([g.listAgents(),g.listAgentDefinitions()]);if(A)return;w(C.map(ye)),p(M.map(Ke)),h($t(C)),b("idle")}catch(C){if(A)return;w([]),p([]),h({}),b("error"),y(Ut(C))}})(),()=>{A=!0}},[g,x]);const G=i.useCallback(()=>{O(A=>A+1)},[]),P=i.useCallback(async A=>{const[C,M]=await Promise.all([g.getAgentChecklist(A),g.getAgent(A).catch(()=>null)]);return Ee(A,C,M??void 0)},[g]),J=i.useCallback(async A=>{const C=await g.getAgentResources(A);return Ce(C)},[g]),V=i.useCallback(async({definition:A,invocationName:C})=>{const M=await g.createAgent(A.ref,{invocationName:C}),K=await g.getAgent(M.id),I=ye(K),$=le(K);return w(D=>[I,...D]),$&&h(D=>({...D,[I.invocation_id]:$,[I.id]:$})),I},[g]),q=i.useMemo(()=>je(g,{resolveOpeningMessage:A=>_[A.invocation_id]??_[A.id]}),[g,_]);return{agents:l,agentDefinitions:f,loadState:j,loadError:k,reload:G,fetchAgentChecklist:P,fetchAgentResources:J,createAgent:V,chatConnector:q}},Ht=e=>JSON.stringify(e),Je=e=>{const{agent:t,jwt:s,headers:a,urls:r}=e,d=JSON.stringify(a??{}),g=Ht(r),l=i.useMemo(()=>new Ne({token:s,headers:a,urls:{agent:r.agentUrl,agentChecklist:r.agentChecklistUrl,agentResources:r.agentResourcesUrl,agentChat:r.agentChatUrl}}),[s,g]);i.useLayoutEffect(()=>{l.setHeaders(a)},[l,d]);const w=i.useCallback(async _=>{const[h,j]=await Promise.all([l.getAgentChecklist(_),l.getAgent(_).catch(()=>null)]);return Ee(_,h,j??void 0)},[l]),f=i.useCallback(async _=>{const h=await l.getAgentResources(_);return Ce(h)},[l]);return{connector:i.useMemo(()=>je(l)(t),[l,t]),fetchAgentChecklist:w,fetchAgentResources:f}},Ft=(e,t)=>{const s=e.hasRunBefore?t||"This trip":e.tripName.trim()||"A new trip",a=e.destination?` to ${e.destination}`:"",r=e.hasRunBefore?" It has run before.":"";return`${s}${a}.${r}`.trim()},Bt=e=>{switch(e){case v.failed:return N.stopped;case v.complete:return N.complete;default:return N.running}},Le=(e,t)=>{t([ce(e)])},Ve=({agent:e,open:t,onClose:s,jwt:a,headers:r,agentUrl:d,agentChecklistUrl:g,agentResourcesUrl:l,agentChatUrl:w,enableUpload:f,initialBrief:p,initialPhase:_,initialChecklist:h})=>{const{connector:j,fetchAgentChecklist:b,fetchAgentResources:k}=Je({agent:e,jwt:a,headers:r,urls:{agentUrl:d,agentChecklistUrl:g,agentResourcesUrl:l,agentChatUrl:w}}),y=i.useRef(j),[x,O]=i.useState(_??(p?N.running:Bt(e.status))),[G,P]=i.useState([]),[J,V]=i.useState(0),[q,A]=i.useState(),[C,M]=i.useState(null),[K,I]=i.useState([]),[$,D]=i.useState(!1),[ae,z]=i.useState(null),[he,H]=i.useState(h??null),[me,re]=i.useState(!1),[W,oe]=i.useState(null),[de,Y]=i.useState(!1),[Q,_e]=i.useState(!1),[X,fe]=i.useState(!1),F=i.useRef(!1);i.useEffect(()=>{y.current=j},[j]),i.useEffect(()=>{F.current=!1,P([]),V(o=>o+1)},[e.invocation_id]),i.useEffect(()=>{if(!t||p||F.current)return;const o=y.current.bootstrapConversation;if(!o){Le(y.current.openingMessage(),P);return}F.current=!0;let c=!1;return Y(!0),(async()=>{try{const m=await o.call(y.current);if(c)return;P(m.map(ce))}catch{c||Le(y.current.openingMessage(),P)}finally{c||Y(!1)}})(),()=>{c=!0}},[t,p,e.invocation_id,j]);const ve=i.useCallback(o=>{o.checklist&&H(o.checklist),o.phase&&O(o.phase)},[]);i.useEffect(()=>{var o,c;!t||p||h&&h.length>0&&((c=(o=y.current).seedChecklist)==null||c.call(o,h))},[t,p,h]),i.useEffect(()=>{if(!t||p)return;let o=!1;return re(!(h!=null&&h.length)),oe(null),(async()=>{var c,m;try{const R=await b(e.invocation_id);if(o)return;h!=null&&h.length||(H(R.checklist),(m=(c=y.current).seedChecklist)==null||m.call(c,R.checklist))}catch{!o&&!(h!=null&&h.length)&&oe(Ae)}finally{o||re(!1)}})(),()=>{o=!0}},[t,e.invocation_id,p,h,b]),i.useEffect(()=>{if(!t)return;let o=!1;return D(!0),z(null),(async()=>{try{const c=await k(e.invocation_id);o||I(c)}catch{o||z(nt)}finally{o||D(!1)}})(),()=>{o=!0}},[t,e.invocation_id,k]),i.useEffect(()=>{if(!t||!p||F.current)return;F.current=!0;const o={id:`user-brief-${Date.now()}`,author:B.user,text:Ft(p,e.invocation_name)};(async()=>{const c=await y.current.start(p);P([ce(y.current.openingMessage()),ce(o),ce(c.message)]),c.checklist&&H(c.checklist),O(c.phase??N.running)})()},[t,p,e.invocation_name]);const we=i.useCallback(o=>{M(At(o))},[]),xe=i.useCallback(o=>{M(null),A(o),V(c=>c+1)},[]),ge=i.useCallback(async()=>{await y.current.stop(),O(N.stopped)},[]),ue=he;return n.jsxs(u.Modal,{open:t,closeHandler:s,hideCloseButton:!0,className:"agent-workspace",children:[n.jsxs(u.Modal.Header,{className:"agent-workspace__header",children:[n.jsxs("div",{className:"agent-workspace__header-title",children:[n.jsx("span",{className:"agent-workspace__header-avatar","aria-hidden":"true",children:n.jsx(u.Icon,{name:"ask-arbor",size:24})}),n.jsx(u.Modal.Title,{children:e.invocation_name}),n.jsx("span",{className:L("agent-workspace__phase",`agent-workspace__phase--${x}`),children:ot[x]})]}),n.jsxs("div",{className:"agent-workspace__header-actions",children:[n.jsx(u.Button,{variant:"tertiary",size:"S",iconLeftName:"clipboard-list",iconLeftScreenReaderText:"Toggle checklist","aria-pressed":!X,onClick:()=>fe(o=>!o),children:"Checklist"}),n.jsx(u.Button,{variant:"tertiary",size:"S",iconLeftName:"files",iconLeftScreenReaderText:"Toggle resources","aria-pressed":!Q,onClick:()=>_e(o=>!o),children:"Resources"}),n.jsx(u.Button,{variant:"secondary",size:"S",iconLeftName:"x",iconLeftScreenReaderText:"Close",onClick:s,children:"Close"})]})]}),n.jsxs(u.Modal.Body,{className:L("agent-workspace__body",{"agent-workspace__body--no-left":X,"agent-workspace__body--no-right":Q}),children:[!X&&n.jsx(vt,{checklist:ue,isLoading:me,error:W,phase:x,canRequestInput:x===N.running&&!de,onStop:()=>void ge(),onAttentionItemClick:we}),n.jsx(ft,{connector:y.current,phase:x,chatHistory:G,chatSessionKey:J,startQuery:q,clarificationMessage:C,enableUpload:f,onTurn:ve,onAwaitingChange:Y,onClarificationPrompt:xe,onDismissClarification:()=>M(null)}),!Q&&n.jsx(xt,{resources:K,isLoading:$,error:ae})]})]})},Ye=({open:e,onClose:t,onStart:s,agentDefinitions:a})=>{const r=a[0],[d,g]=i.useState(r),[l,w]=i.useState(""),[f,p]=i.useState(!1),[_,h]=i.useState(null),j=[...a].sort((x,O)=>x.agent_intent.localeCompare(O.agent_intent)).map(x=>({value:x.ref,label:x.agent_intent}));i.useEffect(()=>{e&&(g(r),w(""),p(!1),h(null))},[e,r]);const b=d!==void 0&&l.trim().length>0,k=i.useCallback(x=>{const O=a.find(G=>G.ref===x[0]);O&&g(O)},[a]),y=i.useCallback(async()=>{if(!(!d||!b||f)){p(!0),h(null);try{await s({definition:d,invocationName:l.trim()})}catch(x){h(x instanceof Error?x.message:"Unable to start the agent.")}finally{p(!1)}}},[b,d,l,f,s]);return!d||a.length===0?null:n.jsxs(u.Modal,{open:e,closeHandler:t,className:"new-agent",children:[n.jsx(u.Modal.Header,{className:"new-agent__header",children:n.jsxs("div",{className:"new-agent__header-title",children:[n.jsx("span",{className:"new-agent__header-avatar","aria-hidden":"true",children:n.jsx(u.Icon,{name:"ask-arbor",size:24})}),n.jsx(u.Modal.Title,{children:"Start an agent"})]})}),n.jsx(u.Modal.Body,{className:"new-agent__body",children:n.jsxs("form",{className:"new-agent__form","aria-label":"Start an agent",onSubmit:x=>{x.preventDefault(),b&&!f&&y()},children:[n.jsxs("div",{className:"new-agent__type-field",children:[n.jsx("label",{className:"new-agent__type-label",htmlFor:"new-agent-type",children:"What would you like your agent to do?"}),n.jsx(u.SelectDropdown,{id:"new-agent-type",placeholder:"Choose an intent",options:j,selectedValues:[d.ref],onSelectionChange:k}),n.jsx("p",{className:"new-agent__type-description",children:d.description})]}),n.jsxs("div",{className:"new-agent__type-field",children:[n.jsx("label",{className:"new-agent__type-label",htmlFor:"new-agent-invocation-name",children:"Name"}),n.jsx(u.TextInput,{id:"new-agent-invocation-name",value:l,placeholder:"e.g. Test with memory3",onChange:x=>w(x.target.value)})]}),_?n.jsx("p",{className:"new-agent__error",role:"alert",children:_}):null,n.jsx("div",{className:"new-agent__actions",children:n.jsx(u.Button,{type:"submit",variant:"primary",disabled:!b||f,iconLeftName:f?"loader":"sparkles",iconLeftScreenReaderText:f?"Starting":void 0,children:f?"Starting…":"Start"})})]})})]})},Gt=e=>e!==void 0&&e.some(t=>t.status===S.hitl),qt=(e,t)=>Gt(t)?v.hitl:e.status,Kt=({column:e,label:t})=>e.statusIcon?n.jsx("span",{className:"agent-view__status-indicator",children:n.jsx(u.Icon,{name:e.statusIcon.name,size:16,color:e.statusIcon.color,className:L({"agent-view__progress-icon--spinning":e.statusIcon.spin}),screenReaderText:t})}):n.jsx("span",{className:L("agent-view__dot",{[`agent-view__dot--${e.dotModifier}`]:e.dotModifier}),children:n.jsx(u.Dot,{colour:e.dotColour,label:t})}),zt=({agent:e,agentName:t,column:s,isExpanded:a,isLoading:r,checklist:d,error:g,onToggle:l,onViewAgent:w})=>{const{id:f,invocation_name:p}=e,_=`agent-card-${f}-header`,h=`agent-card-${f}-progress`;return n.jsx("li",{className:L("agent-view__card",{"agent-view__card--expanded":a}),children:n.jsxs(u.Card,{spacing:"dense",children:[n.jsx("button",{type:"button",className:"agent-view__card-toggle","aria-expanded":a,"aria-controls":h,"aria-label":p,id:_,onClick:()=>l(f),children:n.jsxs("div",{className:"agent-view__card-content",children:[n.jsx(Kt,{column:s}),n.jsx("span",{className:"agent-view__card-invocation-name",children:p}),n.jsx("span",{className:"agent-view__card-agent-name",children:t}),n.jsx(u.Icon,{name:a?"chevron-up":"chevron-down",size:16,className:"agent-view__card-chevron"})]})}),a&&n.jsxs("div",{id:h,"aria-labelledby":_,className:"agent-view__card-progress",children:[r&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:ee}),n.jsx("span",{children:ee})]}),!r&&g&&n.jsx("p",{className:"agent-view__progress-error",role:"alert",children:g}),!r&&!g&&d!==null&&n.jsx(ht,{checklist:d}),!r&&!g&&d===null&&n.jsxs("div",{className:"agent-view__progress-loading","aria-live":"polite",children:[n.jsx(u.Icon,{name:"loader",size:16,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:ee}),n.jsx("span",{children:ee})]}),n.jsx("div",{className:"agent-view__card-actions",children:n.jsx(u.Button,{variant:"secondary",size:"S",onClick:()=>w==null?void 0:w(e),children:"View agent"})})]})]})})},Ue=({column:e,agents:t,expandedAgentId:s,loadingAgentId:a,checklistByInvocationId:r,errorByAgentId:d,definitionNameByRef:g,onToggleAgent:l,onViewAgent:w,isSplit:f=!1})=>n.jsxs("section",{className:L("agent-view__column",{"agent-view__column--split":f}),"aria-label":e.title,children:[n.jsxs("div",{className:"agent-view__column-header",children:[n.jsx(u.Heading,{level:4,children:e.title}),n.jsx("span",{className:"agent-view__column-count",children:t.length})]}),n.jsx("ul",{className:"agent-view__card-list",children:t.map(p=>n.jsx(zt,{agent:p,agentName:Se(p,g),column:e,isExpanded:s===p.id,isLoading:a===p.id,checklist:r[p.invocation_id]??null,error:d[p.id]??null,onToggle:l,onViewAgent:w},p.id))})]}),Se=(e,t)=>t.get(e.agent_definition_ref)??e.agent_definition_ref.replace(/_/g," "),Wt=({jwt:e,headers:t,agentDefinitionsUrl:s,agentsUrl:a,agentUrl:r,agentChecklistUrl:d,agentResourcesUrl:g,agentChatUrl:l,enableUpload:w,institutions:f})=>{var ue;const p=i.useMemo(()=>({agentDefinitions:s,agents:a,agent:r,agentChecklist:d,agentResources:g,agentChat:l}),[s,a,r,d,g,l]),[_,h]=i.useState(null),j=_?(ue=f==null?void 0:f.find(o=>o.applicationId===_.application_id))==null?void 0:ue.applicationUrl:void 0,b=i.useMemo(()=>{const o={...t??{}};return j?o[ne.arborApplicationUrl]=j:delete o[ne.arborApplicationUrl],o},[t,j]),{agents:k,agentDefinitions:y,loadState:x,loadError:O,reload:G,fetchAgentChecklist:P,createAgent:J}=We({jwt:e,headers:b,urls:p}),[V,q]=i.useState(!1),[A,C]=i.useState(null),[M,K]=i.useState(null),[I,$]=i.useState({}),[D,ae]=i.useState({}),[z,he]=i.useState([]),[H,me]=i.useState([]),re=i.useMemo(()=>{const o=new Set(k.map(m=>m.application_id)),c=new Map((f??[]).map(m=>[m.applicationId,m.name]));return[...o].sort((m,R)=>(c.get(m)??m).localeCompare(c.get(R)??R)).map(m=>({value:m,label:c.get(m)??m}))},[k,f]),W=i.useMemo(()=>new Map(y.map(o=>[o.ref,o.display_name])),[y]),oe=i.useMemo(()=>[...new Set(k.map(c=>Se(c,W)))].sort((c,m)=>c.localeCompare(m)).map(c=>({value:c,label:c})),[k,W]),de=i.useMemo(()=>k.filter(o=>!(z.length>0&&!z.includes(o.application_id)||H.length>0&&!H.includes(Se(o,W)))),[k,W,H,z]),Y=re.length>1,Q=oe.length>1,_e=Y||Q;i.useEffect(()=>{if(k.length===0)return;let o=!1;return(async()=>{const c=await Promise.allSettled(k.map(async m=>{const R=await P(m.invocation_id);return{agentId:m.id,invocationId:m.invocation_id,checklist:R.checklist}}));o||($(m=>{const R={...m};for(const ie of c)ie.status==="fulfilled"&&(R[ie.value.invocationId]=ie.value.checklist);return R}),ae(m=>{const R={...m};return c.forEach((ie,Qe)=>{ie.status==="rejected"&&(R[k[Qe].id]=Ae)}),R}))})(),()=>{o=!0}},[k,P]);const X=i.useCallback(async o=>{if(!I[o.invocation_id]){K(o.id),ae(c=>{const m={...c};return delete m[o.id],m});try{const c=await P(o.invocation_id);$(m=>({...m,[o.invocation_id]:c.checklist}))}catch{ae(c=>({...c,[o.id]:Ae}))}finally{K(c=>c===o.id?null:c)}}},[P,I]),fe=i.useCallback(o=>{if(A===o){C(null);return}const c=k.find(({id:m})=>m===o);c&&(C(o),X(c))},[k,A,X]),F=i.useMemo(()=>{const o={};for(const c of de){const m=qt(c,I[c.invocation_id]);(o[m]??(o[m]=[])).push(c)}return o},[de,I]),ve=i.useCallback(o=>{h(o)},[]),we=i.useCallback(async o=>{const c=await J(o);h(c),q(!1)},[J]),xe=i.useCallback(()=>{h(null)},[]),ge={expandedAgentId:A,loadingAgentId:M,checklistByInvocationId:I,errorByAgentId:D,definitionNameByRef:W,onToggleAgent:fe,onViewAgent:ve};return n.jsxs("div",{className:"agent-view-frontend agent-view",children:[n.jsxs("div",{className:"agent-view__header",children:[n.jsx(u.Heading,{level:1,children:"Agents"}),n.jsx(u.Button,{variant:"primary",size:"S",iconLeftName:"sparkles",iconLeftScreenReaderText:"Start an agent",onClick:()=>q(!0),children:"Start an agent"})]}),k.length>0&&_e&&n.jsxs("div",{className:"agent-view__filters",children:[Y&&n.jsxs("div",{className:"agent-view__filter",children:[n.jsx("label",{className:"agent-view__filter-label",htmlFor:"agent-view-institution-filter",children:"Institution"}),n.jsx(u.Combobox,{id:"agent-view-institution-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All institutions",options:re,value:z,onValueChange:he,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear institutions"})]}),Q&&n.jsxs("div",{className:"agent-view__filter",children:[n.jsx("label",{className:"agent-view__filter-label",htmlFor:"agent-view-agent-filter",children:"Agent"}),n.jsx(u.Combobox,{id:"agent-view-agent-filter",triggerVariant:"button",multiple:!0,searchType:"substring",placeholder:"All agents",options:oe,value:H,onValueChange:me,showSelectionCountBadge:!0,showClearAll:!0,clearAllLabel:"Clear agents"})]})]}),x==="error"?n.jsxs("div",{className:"agent-view__state agent-view__state--error",role:"alert",children:[n.jsx(u.Icon,{name:"triangle-alert",size:24,color:"var(--color-semantic-destructive-600)"}),n.jsx("p",{className:"agent-view__state-message",children:O??De}),n.jsx(u.Button,{variant:"secondary",size:"S",onClick:G,children:"Try again"})]}):x==="loading"&&k.length===0?n.jsxs("div",{className:"agent-view__state","aria-live":"polite",children:[n.jsx(u.Icon,{name:"loader",size:24,color:"var(--color-brand-600)",className:"agent-view__progress-icon--spinning",screenReaderText:Ie}),n.jsx("p",{className:"agent-view__state-message",children:Ie})]}):k.length===0?n.jsx(gt,{}):n.jsxs("div",{className:"agent-view__board",children:[Xe.map(o=>n.jsx(Ue,{column:pe[o],agents:F[o]??[],...ge},o)),n.jsx("div",{className:"agent-view__split-column",children:Ze.map(o=>n.jsx(Ue,{column:pe[o],agents:F[o]??[],isSplit:!0,...ge},o))})]}),_&&n.jsx(Ve,{agent:_,open:!0,jwt:e,headers:b,agentUrl:r,agentChecklistUrl:d,agentResourcesUrl:g,agentChatUrl:l,enableUpload:w,initialChecklist:I[_.invocation_id]??null,onClose:xe},_.id),n.jsx(Ye,{open:V,onClose:()=>q(!1),onStart:we,agentDefinitions:y})]})},Jt=(e,t)=>{const s=Date.now(),a=t.trim()||e.agent_intent;return{id:`agent-${s}`,invocation_id:`inv-${s}`,agent_definition_ref:e.ref,agent_intent:e.agent_intent,invocation_name:a,application_id:et,created_by:tt,status:v["generating-a-response"],context_ref:null,checklist_ref:null}};exports.AgentMonitorKanban=Wt;exports.AgentServiceClient=Ne;exports.AgentServiceError=te;exports.AgentView=Ve;exports.HttpChatConnector=Be;exports.NewAgentModal=Ye;exports.buildAgentFromDefinition=Jt;exports.createHttpChatConnectorFactory=je;exports.mapApiAgent=ye;exports.mapApiAgentDefinition=Ke;exports.mapApiAgentStatus=Ge;exports.mapApiChecklistEndpointResponse=Ee;exports.mapApiChecklistItem=be;exports.mapApiChecklistResponse=Lt;exports.mapApiChecklistStatus=qe;exports.mapApiOpeningMessage=le;exports.mapApiResource=ze;exports.mapApiResourcesEndpointResponse=Ce;exports.mapApiTripOption=Rt;exports.useAgentService=We;exports.useAgentWorkspace=Je;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,19 @@ export declare type Agent = {
|
|
|
14
14
|
checklist_ref: string | null;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
export declare type AgentBackendConfig = {
|
|
18
|
+
jwt?: string;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
agentDefinitionsUrl?: string;
|
|
21
|
+
agentsUrl?: string;
|
|
22
|
+
agentUrl?: string;
|
|
23
|
+
agentChecklistUrl?: string;
|
|
24
|
+
agentResourcesUrl?: string;
|
|
25
|
+
agentChatUrl?: string;
|
|
26
|
+
/** When true, enables chat file uploads (posted to agentChatUrl). */
|
|
27
|
+
enableUpload?: boolean;
|
|
28
|
+
};
|
|
29
|
+
|
|
17
30
|
export declare type AgentBrief = {
|
|
18
31
|
tripId: string | null;
|
|
19
32
|
isNewTrip: boolean;
|
|
@@ -47,18 +60,18 @@ export declare type AgentDefinition = {
|
|
|
47
60
|
description: string;
|
|
48
61
|
};
|
|
49
62
|
|
|
50
|
-
export declare const AgentMonitorKanban: ({ jwt, headers,
|
|
63
|
+
export declare const AgentMonitorKanban: ({ jwt, headers, agentDefinitionsUrl, agentsUrl, agentUrl, agentChecklistUrl, agentResourcesUrl, agentChatUrl, enableUpload, institutions, }: AgentMonitorKanbanProps) => JSX_2.Element;
|
|
51
64
|
|
|
52
65
|
export declare type AgentMonitorKanbanProps = {
|
|
53
66
|
jwt?: string;
|
|
54
67
|
headers?: Record<string, string>;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
agentDefinitionsUrl: string;
|
|
69
|
+
agentsUrl: string;
|
|
70
|
+
agentUrl: string;
|
|
71
|
+
agentChecklistUrl: string;
|
|
72
|
+
agentResourcesUrl: string;
|
|
73
|
+
agentChatUrl: string;
|
|
74
|
+
enableUpload?: boolean;
|
|
62
75
|
institutions?: InstitutionConfig[];
|
|
63
76
|
};
|
|
64
77
|
|
|
@@ -109,7 +122,7 @@ export declare class AgentServiceClient {
|
|
|
109
122
|
}
|
|
110
123
|
|
|
111
124
|
export declare type AgentServiceClientOptions = {
|
|
112
|
-
baseUrl
|
|
125
|
+
baseUrl?: string;
|
|
113
126
|
token?: string;
|
|
114
127
|
headers?: Record<string, string>;
|
|
115
128
|
urls?: AgentServiceUrlOverrides;
|
|
@@ -139,24 +152,34 @@ export declare type AgentServiceUrlOverrides = {
|
|
|
139
152
|
agentChat?: string;
|
|
140
153
|
};
|
|
141
154
|
|
|
142
|
-
export declare type AgentServiceUrls = AgentServiceUrlOverrides
|
|
143
|
-
baseUrl: string;
|
|
144
|
-
};
|
|
155
|
+
export declare type AgentServiceUrls = AgentServiceUrlOverrides;
|
|
145
156
|
|
|
146
157
|
export declare type AgentStatus = 'generating-a-response' | 'hitl' | 'complete' | 'failed';
|
|
147
158
|
|
|
148
|
-
export declare const AgentView: ({ agent, open, onClose,
|
|
159
|
+
export declare const AgentView: ({ agent, open, onClose, jwt, headers, agentUrl, agentChecklistUrl, agentResourcesUrl, agentChatUrl, enableUpload, initialBrief, initialPhase, initialChecklist, }: AgentViewProps) => JSX_2.Element;
|
|
149
160
|
|
|
150
161
|
export declare type AgentViewProps = {
|
|
151
162
|
agent: Agent;
|
|
152
163
|
open: boolean;
|
|
153
164
|
onClose: () => void;
|
|
165
|
+
jwt?: string;
|
|
166
|
+
headers?: Record<string, string>;
|
|
167
|
+
agentUrl: string;
|
|
168
|
+
agentChecklistUrl: string;
|
|
169
|
+
agentResourcesUrl: string;
|
|
170
|
+
agentChatUrl: string;
|
|
171
|
+
/** When true, enables chat file uploads (posted to agentChatUrl). */
|
|
172
|
+
enableUpload?: boolean;
|
|
154
173
|
initialBrief?: AgentBrief;
|
|
155
174
|
initialPhase?: WorkspacePhase;
|
|
156
175
|
initialChecklist?: AgentChecklistItem[] | null;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export declare type AgentWorkspaceUrls = {
|
|
179
|
+
agentUrl: string;
|
|
180
|
+
agentChecklistUrl: string;
|
|
181
|
+
agentResourcesUrl: string;
|
|
182
|
+
agentChatUrl: string;
|
|
160
183
|
};
|
|
161
184
|
|
|
162
185
|
export declare type ApiAgentDefinition = {
|
|
@@ -424,6 +447,21 @@ export declare type UseAgentServiceResult = {
|
|
|
424
447
|
chatConnector: (agent: Agent) => ChatConnector;
|
|
425
448
|
};
|
|
426
449
|
|
|
450
|
+
export declare const useAgentWorkspace: (config: UseAgentWorkspaceConfig) => UseAgentWorkspaceResult;
|
|
451
|
+
|
|
452
|
+
export declare type UseAgentWorkspaceConfig = {
|
|
453
|
+
agent: Agent;
|
|
454
|
+
jwt?: string;
|
|
455
|
+
headers?: Record<string, string>;
|
|
456
|
+
urls: AgentWorkspaceUrls;
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
export declare type UseAgentWorkspaceResult = {
|
|
460
|
+
connector: ChatConnector;
|
|
461
|
+
fetchAgentChecklist: (invocationId: string) => Promise<AgentChecklistResponse>;
|
|
462
|
+
fetchAgentResources: (invocationId: string) => Promise<AgentResource[]>;
|
|
463
|
+
};
|
|
464
|
+
|
|
427
465
|
export declare type WorkspacePhase = 'briefing' | 'running' | 'stopped' | 'complete';
|
|
428
466
|
|
|
429
467
|
export { }
|