@arbor-education/ask-arbor-chat-panel 1.0.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 +150 -0
- package/dist/index.cjs +93 -0
- package/dist/index.d.ts +243 -0
- package/dist/index.js +3216 -0
- package/dist/style.css +1 -0
- package/package.json +90 -0
package/README.md
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Ask Arbor Standalone Component
|
|
2
|
+
|
|
3
|
+
Self-contained AI chat widget and React component library. No arbor-fe ecosystem dependencies.
|
|
4
|
+
|
|
5
|
+
Published as two artefacts:
|
|
6
|
+
- **NPM package** — `ChatPanel` React component for host apps that already use React
|
|
7
|
+
- **IIFE widget** — `ask-arbor-widget.js` drop-in script for any HTML page (Zendesk-style floating button)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Quick start (widget dev)
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
yarn install
|
|
15
|
+
make dev
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Opens `http://localhost:5173/playground/widget-demo.html` with hot reload. Mock API endpoints are included — no backend or build step needed.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Scripts
|
|
23
|
+
|
|
24
|
+
| Command | What it does |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `yarn dev` / `make dev` | Hot-reload widget demo (`playground/widget-demo.html`) |
|
|
27
|
+
| `yarn build:widget` | Production IIFE bundle → `dist-widget/ask-arbor-widget.js` |
|
|
28
|
+
| `yarn build` | NPM package build → `dist/` |
|
|
29
|
+
| `yarn build:all` | Both builds in sequence |
|
|
30
|
+
| `yarn test` | Run Vitest test suite (87 tests) |
|
|
31
|
+
| `yarn test:watch` | Vitest in watch mode |
|
|
32
|
+
| `yarn check-types` | TypeScript type-check with no emit |
|
|
33
|
+
| `yarn eslint` | ESLint check |
|
|
34
|
+
| `yarn style-lint` | Stylelint check for SCSS |
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Widget integration (production)
|
|
39
|
+
|
|
40
|
+
Drop one `<script>` into any HTML page — no React, no CSS imports required:
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<script src="ask-arbor-widget.js"></script>
|
|
44
|
+
<script>
|
|
45
|
+
AskArbor.init({
|
|
46
|
+
chatUrl: 'https://your-api.example.com/chat',
|
|
47
|
+
openOnStart: false, // true → opens immediately
|
|
48
|
+
position: 'bottom-right', // 'bottom-right' | 'bottom-left'
|
|
49
|
+
authorizationToken: 'eyJ...', // optional JWT — sent as Authorization: Bearer
|
|
50
|
+
});
|
|
51
|
+
</script>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Auto-init
|
|
55
|
+
|
|
56
|
+
Set `window.AskArborConfig` before loading the script and init runs automatically:
|
|
57
|
+
|
|
58
|
+
```html
|
|
59
|
+
<script>
|
|
60
|
+
window.AskArborConfig = {
|
|
61
|
+
chatUrl: 'https://your-api.example.com/chat',
|
|
62
|
+
platform: 'SAM_PEOPLE',
|
|
63
|
+
openOnStart: true,
|
|
64
|
+
};
|
|
65
|
+
</script>
|
|
66
|
+
<script src="ask-arbor-widget.js"></script>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Global API
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
AskArbor.init(config) // mount the widget
|
|
73
|
+
AskArbor.destroy() // unmount and clean up
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## React component (NPM package)
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
import {ChatPanel} from 'ask-arbor-chat-panel';
|
|
82
|
+
import 'ask-arbor-chat-panel/style.css';
|
|
83
|
+
|
|
84
|
+
<ChatPanel
|
|
85
|
+
chatUrl="https://your-api.example.com/chat"
|
|
86
|
+
authorizationToken={jwt}
|
|
87
|
+
onClose={() => setOpen(false)}
|
|
88
|
+
/>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Peer dependencies: `react ≥18`, `react-dom ≥18`, `@arbor-education/design-system.components ≥0.21`.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## API shape
|
|
96
|
+
|
|
97
|
+
### POST `chatUrl`
|
|
98
|
+
|
|
99
|
+
Request:
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"chatId": "string | undefined",
|
|
103
|
+
"userMessage": "string",
|
|
104
|
+
"canvasMode": false
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Response:
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"items": [{
|
|
112
|
+
"id": "string",
|
|
113
|
+
"text": "string",
|
|
114
|
+
"type": "AGENT",
|
|
115
|
+
"chatId": "string (optional)"
|
|
116
|
+
}]
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Authorization
|
|
121
|
+
|
|
122
|
+
Pass `authorizationToken` to the widget/component. Every request will include:
|
|
123
|
+
```
|
|
124
|
+
Authorization: Bearer <token>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Project structure
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
src/
|
|
133
|
+
widget.tsx # IIFE entry — AskArborWidget + init/destroy
|
|
134
|
+
ChatPanel.tsx # Core React component (also the NPM export)
|
|
135
|
+
platformConfig.ts # Platform → colour/logo mapping
|
|
136
|
+
utils/
|
|
137
|
+
http.ts # fetch wrapper with Authorization header support
|
|
138
|
+
getNewAgentMessage.ts
|
|
139
|
+
getHistoricMessages.ts
|
|
140
|
+
sendNotification.ts
|
|
141
|
+
sendMessageRating.ts
|
|
142
|
+
playground/
|
|
143
|
+
widget-demo.html # Widget demo (served by dev:widget)
|
|
144
|
+
index.html # React component playground (served by dev)
|
|
145
|
+
widget-dev-shim.ts # Dev-only: exposes window.AskArbor from source
|
|
146
|
+
dist-widget/
|
|
147
|
+
ask-arbor-widget.js # Production IIFE bundle (run build:widget)
|
|
148
|
+
tests/
|
|
149
|
+
ChatPanel.test.tsx # 87 Vitest tests
|
|
150
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),Re=require("@arbor-education/design-system.components"),l=require("react"),dr=require("react-dom");function fr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var $n={exports:{}};/*!
|
|
2
|
+
Copyright (c) 2018 Jed Watson.
|
|
3
|
+
Licensed under the MIT License (MIT), see
|
|
4
|
+
http://jedwatson.github.io/classnames
|
|
5
|
+
*/(function(e){(function(){var n={}.hasOwnProperty;function r(){for(var i="",d=0;d<arguments.length;d++){var h=arguments[d];h&&(i=u(i,a(h)))}return i}function a(i){if(typeof i=="string"||typeof i=="number")return i;if(typeof i!="object")return"";if(Array.isArray(i))return r.apply(null,i);if(i.toString!==Object.prototype.toString&&!i.toString.toString().includes("[native code]"))return i.toString();var d="";for(var h in i)n.call(i,h)&&i[h]&&(d=u(d,h));return d}function u(i,d){return d?i?i+" "+d:i+d:i}e.exports?(r.default=r,e.exports=r):window.classNames=r})()})($n);var pr=$n.exports;const pe=fr(pr);function mr(e,n,r,a){var u=this,i=l.useRef(null),d=l.useRef(0),h=l.useRef(0),_=l.useRef(null),m=l.useRef([]),E=l.useRef(),S=l.useRef(),g=l.useRef(e),A=l.useRef(!0),x=l.useRef(),O=l.useRef();g.current=e;var N=typeof window<"u",w=!n&&n!==0&&N;if(typeof e!="function")throw new TypeError("Expected a function");n=+n||0;var j=!!(r=r||{}).leading,ue=!("trailing"in r)||!!r.trailing,U=!!r.flushOnExit&&ue,$="maxWait"in r,M="debounceOnServer"in r&&!!r.debounceOnServer,Y=$?Math.max(+r.maxWait||0,n):null,de=l.useMemo(function(){var V=function(L){var z=m.current,fe=E.current;return m.current=E.current=null,d.current=L,h.current=h.current||L,S.current=g.current.apply(fe,z)},F=function(L,z){w&&cancelAnimationFrame(_.current),_.current=w?requestAnimationFrame(L):setTimeout(L,z)},ce=function(L){if(!A.current)return!1;var z=L-i.current;return!i.current||z>=n||z<0||$&&L-d.current>=Y},T=function(L){return _.current=null,ue&&m.current?V(L):(m.current=E.current=null,S.current)},v=function L(){var z=Date.now();if(j&&h.current===d.current&&H(),ce(z))return T(z);if(A.current){var fe=n-(z-i.current),Ce=$?Math.min(fe,Y-(z-d.current)):fe;F(L,Ce)}},H=function(){},ee=function(){if(N||M){var L,z=Date.now(),fe=ce(z);if(m.current=[].slice.call(arguments),E.current=u,i.current=z,U&&!x.current&&(x.current=function(){var Ce;((Ce=globalThis.document)==null?void 0:Ce.visibilityState)==="hidden"&&O.current.flush()},(L=globalThis.document)==null||L.addEventListener==null||L.addEventListener("visibilitychange",x.current)),fe){if(!_.current&&A.current)return d.current=i.current,F(v,n),j?V(i.current):S.current;if($)return F(v,n),V(i.current)}return _.current||F(v,n),S.current}};return ee.cancel=function(){var L=_.current;L&&(w?cancelAnimationFrame(_.current):clearTimeout(_.current)),d.current=0,m.current=i.current=E.current=_.current=null},ee.isPending=function(){return!!_.current},ee.flush=function(){return _.current?T(Date.now()):S.current},ee},[j,$,n,Y,ue,U,w,N,M,a]);return O.current=de,l.useEffect(function(){return A.current=!0,function(){var V;U&&O.current.flush(),x.current&&((V=globalThis.document)==null||V.removeEventListener==null||V.removeEventListener("visibilitychange",x.current),x.current=null),A.current=!1}},[U]),de}const hr=()=>s.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[s.jsx("path",{d:"M9.76794 5.1605L10.9845 5.50809C11.1003 5.54083 11.1784 5.64662 11.1784 5.765C11.1784 5.88338 11.1003 5.98917 10.9845 6.02191L9.76794 6.3695L9.42036 7.58606C9.38761 7.70192 9.28183 7.78 9.16344 7.78C9.04506 7.78 8.93928 7.70192 8.90653 7.58606L8.55894 6.3695L7.34239 6.02191C7.22653 5.98917 7.14844 5.88338 7.14844 5.765C7.14844 5.64662 7.22653 5.54083 7.34239 5.50809L8.55894 5.1605L8.90653 3.94394C8.93928 3.82808 9.04506 3.75 9.16344 3.75C9.28183 3.75 9.38761 3.82808 9.42036 3.94394L9.76794 5.1605Z",fill:"#F7941D"}),s.jsx("path",{d:"M6.67581 3.31451L7.42144 3.52755C7.49245 3.54762 7.54031 3.61246 7.54031 3.68501C7.54031 3.75757 7.49245 3.82241 7.42144 3.84247L6.67581 4.05551L6.46277 4.80114C6.4427 4.87216 6.37786 4.92001 6.30531 4.92001C6.23275 4.92001 6.16791 4.87216 6.14784 4.80114L5.93481 4.05551L5.18918 3.84247C5.11816 3.82241 5.07031 3.75757 5.07031 3.68501C5.07031 3.61246 5.11816 3.54762 5.18918 3.52755L5.93481 3.31451L6.14784 2.56888C6.16791 2.49787 6.23275 2.45001 6.30531 2.45001C6.37786 2.45001 6.4427 2.49787 6.46277 2.56888L6.67581 3.31451Z",fill:"#CFDD27"}),s.jsx("path",{d:"M6.49287 7.78652L8.18036 8.26865C8.34107 8.31407 8.44938 8.46081 8.44938 8.62502C8.44938 8.78922 8.34107 8.93596 8.18036 8.98138L6.49287 9.46352L6.01074 11.151C5.96532 11.3117 5.81857 11.42 5.65437 11.42C5.49016 11.42 5.34342 11.3117 5.298 11.151L4.81587 9.46352L3.1284 8.98138C2.96768 8.93596 2.85938 8.78922 2.85938 8.62502C2.85938 8.46081 2.96768 8.31407 3.1284 8.26865L4.81587 7.78652L5.298 6.09904C5.34342 5.93832 5.49016 5.83002 5.65437 5.83002C5.81857 5.83002 5.96532 5.93832 6.01074 6.09904L6.49287 7.78652Z",fill:"#7BB93C"})]}),_r="Enter",gr=" ",Nn=({category:e,isExpanded:n,onHeaderClick:r})=>{const a=`ask-arbor-prompt-library__body-${e.id}`,u=i=>{(i.key===_r||i.key===gr)&&(i.preventDefault(),r(e.id))};return s.jsx("div",{className:pe("ask-arbor-prompt-library__category",`ask-arbor-prompt-library__category--${e.theme}`,{"ask-arbor-prompt-library__category--expanded":n}),children:s.jsxs("div",{className:"ask-arbor-prompt-library__header",onClick:()=>r(e.id),onKeyDown:u,role:"button",tabIndex:0,"aria-expanded":n,"aria-controls":a,"aria-label":`${e.title}, ${n?"collapse":"expand"} to ${n?"hide":"show"} prompts`,children:[s.jsx("div",{className:"ask-arbor-prompt-library__icon-circle",children:s.jsx(Re.Icon,{name:e.icon,size:12,screenReaderText:e.title})}),s.jsx("div",{className:"ask-arbor-prompt-library__header-text",children:s.jsx("h4",{className:"ask-arbor-prompt-library__title",children:e.title})}),s.jsx(Re.Icon,{name:n?"chevron-up":"chevron-down",size:16,screenReaderText:n?"Collapse section":"Expand section",className:"ask-arbor-prompt-library__chevron"}),s.jsx("p",{className:"ask-arbor-prompt-library__description",children:e.description})]})})},br=({onSelectPrompt:e,onPromptHover:n,categories:r})=>{const[a,u]=l.useState(null),i=g=>{u(A=>A===g?null:g)},d=(g,A)=>{g.stopPropagation(),e(A)},h=a!=null?r.findIndex(g=>g.id===a):-1,_=h>=0?r[h]:null,m=g=>s.jsx("div",{className:"ask-arbor-prompt-library__grid-item ask-arbor-prompt-library__grid-item--full-width",children:s.jsxs("div",{className:"ask-arbor-prompt-library__expanded-block",children:[s.jsx(Nn,{category:g,isExpanded:!0,onHeaderClick:i}),s.jsx("div",{id:`ask-arbor-prompt-library__body-${g.id}`,className:"ask-arbor-prompt-library__drawer",role:"region","aria-label":`${g.title} prompts`,children:g.promptGroups.map(A=>s.jsxs("div",{className:"ask-arbor-prompt-library__prompt-group",children:[s.jsx(Re.Tag,{color:g.theme,children:A.tag}),s.jsx("div",{className:"ask-arbor-prompt-library__prompts",children:A.prompts.map((x,O)=>s.jsxs("button",{type:"button",className:"ask-arbor-prompt-library__prompt-row",onClick:N=>d(N,x),onMouseEnter:()=>n==null?void 0:n(x),onMouseLeave:()=>n==null?void 0:n(null),children:[s.jsx("span",{className:"ask-arbor-prompt-library__prompt-text",children:x}),s.jsx(Re.Icon,{name:"chevron-right",size:12,screenReaderText:"Submit prompt"})]},`${A.tag}-${O}`))})]},A.tag))})]})},g.id),E=g=>s.jsx("div",{className:"ask-arbor-prompt-library__grid-item",children:s.jsx(Nn,{category:g,isExpanded:!1,onHeaderClick:i})},g.id),S=h>=0?[...r.slice(0,h).map(E),m(_),...r.slice(h+1).map(E)]:r.map(E);return s.jsx("div",{className:"ask-arbor-prompt-library","data-testid":"ask-arbor-prompt-library",children:s.jsx("div",{className:"ask-arbor-prompt-library__grid",children:S})})};/**
|
|
6
|
+
* @license lucide-react v1.21.0 - ISC
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the ISC license.
|
|
9
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
10
|
+
*/const Yn=(...e)=>e.filter((n,r,a)=>!!n&&n.trim()!==""&&a.indexOf(n)===r).join(" ").trim();/**
|
|
11
|
+
* @license lucide-react v1.21.0 - ISC
|
|
12
|
+
*
|
|
13
|
+
* This source code is licensed under the ISC license.
|
|
14
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
15
|
+
*/const Tr=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();/**
|
|
16
|
+
* @license lucide-react v1.21.0 - ISC
|
|
17
|
+
*
|
|
18
|
+
* This source code is licensed under the ISC license.
|
|
19
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
20
|
+
*/const yr=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(n,r,a)=>a?a.toUpperCase():r.toLowerCase());/**
|
|
21
|
+
* @license lucide-react v1.21.0 - ISC
|
|
22
|
+
*
|
|
23
|
+
* This source code is licensed under the ISC license.
|
|
24
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
25
|
+
*/const wn=e=>{const n=yr(e);return n.charAt(0).toUpperCase()+n.slice(1)};/**
|
|
26
|
+
* @license lucide-react v1.21.0 - ISC
|
|
27
|
+
*
|
|
28
|
+
* This source code is licensed under the ISC license.
|
|
29
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
30
|
+
*/var Jt={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
|
|
31
|
+
* @license lucide-react v1.21.0 - ISC
|
|
32
|
+
*
|
|
33
|
+
* This source code is licensed under the ISC license.
|
|
34
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
35
|
+
*/const Er=e=>{for(const n in e)if(n.startsWith("aria-")||n==="role"||n==="title")return!0;return!1},Ar=l.createContext({}),Sr=()=>l.useContext(Ar),Nr=l.forwardRef(({color:e,size:n,strokeWidth:r,absoluteStrokeWidth:a,className:u="",children:i,iconNode:d,...h},_)=>{const{size:m=24,strokeWidth:E=2,absoluteStrokeWidth:S=!1,color:g="currentColor",className:A=""}=Sr()??{},x=a??S?Number(r??E)*24/Number(n??m):r??E;return l.createElement("svg",{ref:_,...Jt,width:n??m??Jt.width,height:n??m??Jt.height,stroke:e??g,strokeWidth:x,className:Yn("lucide",A,u),...!i&&!Er(h)&&{"aria-hidden":"true"},...h},[...d.map(([O,N])=>l.createElement(O,N)),...Array.isArray(i)?i:[i]])});/**
|
|
36
|
+
* @license lucide-react v1.21.0 - ISC
|
|
37
|
+
*
|
|
38
|
+
* This source code is licensed under the ISC license.
|
|
39
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
40
|
+
*/const ke=(e,n)=>{const r=l.forwardRef(({className:a,...u},i)=>l.createElement(Nr,{ref:i,iconNode:n,className:Yn(`lucide-${Tr(wn(e))}`,`lucide-${e}`,a),...u}));return r.displayName=wn(e),r};/**
|
|
41
|
+
* @license lucide-react v1.21.0 - ISC
|
|
42
|
+
*
|
|
43
|
+
* This source code is licensed under the ISC license.
|
|
44
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
45
|
+
*/const wr=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],xr=ke("arrow-right",wr);/**
|
|
46
|
+
* @license lucide-react v1.21.0 - ISC
|
|
47
|
+
*
|
|
48
|
+
* This source code is licensed under the ISC license.
|
|
49
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
50
|
+
*/const Rr=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]],kr=ke("circle-alert",Rr);/**
|
|
51
|
+
* @license lucide-react v1.21.0 - ISC
|
|
52
|
+
*
|
|
53
|
+
* This source code is licensed under the ISC license.
|
|
54
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
55
|
+
*/const Cr=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M16 16s-1.5-2-4-2-4 2-4 2",key:"epbg0q"}],["line",{x1:"9",x2:"9.01",y1:"9",y2:"9",key:"yxxnd0"}],["line",{x1:"15",x2:"15.01",y1:"9",y2:"9",key:"1p4y9e"}]],Ir=ke("frown",Cr);/**
|
|
56
|
+
* @license lucide-react v1.21.0 - ISC
|
|
57
|
+
*
|
|
58
|
+
* This source code is licensed under the ISC license.
|
|
59
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
60
|
+
*/const Or=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],vr=ke("info",Or);/**
|
|
61
|
+
* @license lucide-react v1.21.0 - ISC
|
|
62
|
+
*
|
|
63
|
+
* This source code is licensed under the ISC license.
|
|
64
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
65
|
+
*/const Lr=[["path",{d:"M12 19v3",key:"npa21l"}],["path",{d:"M15 9.34V5a3 3 0 0 0-5.68-1.33",key:"1gzdoj"}],["path",{d:"M16.95 16.95A7 7 0 0 1 5 12v-2",key:"cqa7eg"}],["path",{d:"M18.89 13.23A7 7 0 0 0 19 12v-2",key:"16hl24"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v3a3 3 0 0 0 5.12 2.12",key:"r2i35w"}]],Dr=ke("mic-off",Lr);/**
|
|
66
|
+
* @license lucide-react v1.21.0 - ISC
|
|
67
|
+
*
|
|
68
|
+
* This source code is licensed under the ISC license.
|
|
69
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
70
|
+
*/const Mr=[["path",{d:"M12 19v3",key:"npa21l"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["rect",{x:"9",y:"2",width:"6",height:"13",rx:"3",key:"s6n7sd"}]],Pr=ke("mic",Mr);/**
|
|
71
|
+
* @license lucide-react v1.21.0 - ISC
|
|
72
|
+
*
|
|
73
|
+
* This source code is licensed under the ISC license.
|
|
74
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
75
|
+
*/const jr=[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],Ur=ke("settings",jr);/**
|
|
76
|
+
* @license lucide-react v1.21.0 - ISC
|
|
77
|
+
*
|
|
78
|
+
* This source code is licensed under the ISC license.
|
|
79
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
80
|
+
*/const Fr=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 14s1.5 2 4 2 4-2 4-2",key:"1y1vjs"}],["line",{x1:"9",x2:"9.01",y1:"9",y2:"9",key:"yxxnd0"}],["line",{x1:"15",x2:"15.01",y1:"9",y2:"9",key:"1p4y9e"}]],Hr=ke("smile",Fr);/**
|
|
81
|
+
* @license lucide-react v1.21.0 - ISC
|
|
82
|
+
*
|
|
83
|
+
* This source code is licensed under the ISC license.
|
|
84
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
85
|
+
*/const zr=[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],Gr=ke("triangle-alert",zr);/**
|
|
86
|
+
* @license lucide-react v1.21.0 - ISC
|
|
87
|
+
*
|
|
88
|
+
* This source code is licensed under the ISC license.
|
|
89
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
90
|
+
*/const Br=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Wr=ke("x",Br);function $r(e,n){if(n){n(e);return}/^https?:\/\//.test(e)?window.open(e,"_blank","noopener,noreferrer"):window.location.href=e}const Kn=({isOpen:e,onClose:n,anchorRef:r,items:a,onNavigate:u,className:i})=>{const d=l.useRef(null);return l.useEffect(()=>{if(!e)return;const h=m=>{d.current&&!d.current.contains(m.target)&&r.current&&!r.current.contains(m.target)&&n()},_=m=>{m.key==="Escape"&&n()};return document.addEventListener("mousedown",h),document.addEventListener("keydown",_),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("keydown",_)}},[e,n,r]),e?s.jsx("div",{ref:d,className:pe("ask-arbor-settings",i),role:"menu","aria-label":"Settings menu",children:a.map((h,_)=>s.jsxs("a",{href:h.url,className:"ask-arbor-settings__item",role:"menuitem",onClick:m=>{m.preventDefault(),n(),$r(h.url,u)},children:[h.icon,s.jsx("span",{className:"ask-arbor-settings__label",children:h.label})]},`${h.label}-${_}`))}):null};Kn.displayName="AskArborSettings";function Yr(e){const n=Math.floor(e/60),r=e%60;return`${n}:${r.toString().padStart(2,"0")}`}const qn=l.forwardRef(({value:e,onChange:n,onKeyDown:r,placeholder:a="Explain what you need in your own words...",onSubmit:u,onSettingsClick:i,onMicClick:d,onStopClick:h,menuContent:_,onNavigate:m,isProcessing:E=!1,speechEngaged:S=!1,showMicButton:g=!0,ariaLabel:A="Chat panel input",disclaimerText:x="Ask Arbor can occasionally be wrong. Please check any important information.",showDisclaimer:O=!1},N)=>{const w=l.useRef(null),j=l.useRef(null),[ue,U]=l.useState(0),[$,M]=l.useState(!1);l.useEffect(()=>{if(!S){U(0);return}U(0);const F=setInterval(()=>{U(ce=>ce+1)},1e3);return()=>clearInterval(F)},[S]),l.useImperativeHandle(N,()=>w.current);const Y=!E&&!S&&e.trim().length>0,de=S,V=l.useMemo(()=>(_??[]).map(F=>({label:F.label,icon:s.jsx(Re.Icon,{name:F.icon,size:12}),url:F.url})),[_]);return s.jsxs("div",{className:"ask-arbor-input",children:[s.jsxs("div",{className:"ask-arbor-input__frame",children:[s.jsx("div",{className:"ask-arbor-input__input-row",children:s.jsx("textarea",{ref:w,className:"ask-arbor-input__textarea",value:e,onChange:F=>n(F.target.value),onKeyDown:r,placeholder:S?"":a,"aria-label":A,disabled:E||S,rows:1,tabIndex:S?-1:void 0,readOnly:S})}),s.jsx("div",{className:"ask-arbor-input__bottom-actions",children:s.jsxs("div",{className:"ask-arbor-input__actions-right",children:[S&&s.jsx("span",{className:"ask-arbor-input__timer",children:Yr(ue)}),V.length>0&&s.jsxs("div",{className:"ask-arbor-input__settings-wrap",children:[s.jsx("button",{ref:j,type:"button",className:pe("ask-arbor-input__btn","ask-arbor-input__btn--settings",{"ask-arbor-input__btn--settings-open":$}),onClick:()=>{M(F=>!F),i==null||i()},"aria-label":"Settings","aria-expanded":$,"aria-haspopup":"menu",children:s.jsx(Ur,{size:12,stroke:"#000000"})}),s.jsx(Kn,{isOpen:$,onClose:()=>M(!1),anchorRef:j,items:V,onNavigate:m})]}),g&&d&&!de&&s.jsx("button",{type:"button",className:pe("ask-arbor-input__btn","ask-arbor-input__btn--mic"),onClick:d,"aria-label":"speak with agent",disabled:S||E,children:s.jsx(Pr,{size:12,stroke:"#3C3735"})}),de&&h?s.jsxs("button",{type:"button",className:"ask-arbor-input__btn ask-arbor-input__btn--stop",onClick:h,"aria-label":"Stop",children:[s.jsx(Dr,{size:12,stroke:"#FFFFFF"}),"Stop"]}):s.jsx("button",{type:"button",className:"ask-arbor-input__btn ask-arbor-input__btn--submit",onClick:u,disabled:!Y,"aria-label":"submit message",children:s.jsx(xr,{size:12,stroke:"#FFFFFF",strokeWidth:2.5})})]})})]}),O&&s.jsx("p",{className:"ask-arbor-input__disclaimer",children:x})]})});qn.displayName="AskArborInput";const Rt="AGENT",Ze="USER",Bt="INFO",kt="WARNING",Ee="ERROR",Qt="up",xn="down",Rn=10,Kr=({message:e,onRate:n,upRatingPopupUrl:r,downRatingPopupUrl:a,onRatingPopupOpen:u})=>{const[i,d]=l.useState(null),h=m=>{const E=m===Qt?r:a;E!=null&&E.trim()&&(u?u(E.trim()):window.open(E.trim(),"_blank","noopener,noreferrer"))},_=m=>{d(m),n(m),h(m)};return s.jsxs("div",{className:"chat-message__feedback",children:[s.jsx("span",{className:"chat-message__feedback-question",children:"How did Ask Arbor do?"}),s.jsxs("div",{className:"chat-message__feedback-buttons",children:[s.jsxs("button",{type:"button","aria-label":"Rate message as good response",title:"Good response",className:pe("chat-message__feedback-button","chat-message__feedback-button--up",{"chat-message__feedback-button--selected":i===Qt}),onClick:()=>_(Qt),children:[s.jsx(Hr,{size:Rn,strokeWidth:1.5,className:"chat-message__feedback-button-icon","aria-hidden":!0}),s.jsx("span",{className:"chat-message__feedback-button-text",children:"Nailed it"})]}),s.jsxs("button",{type:"button","aria-label":"Rate message as bad response",title:"Bad response",className:pe("chat-message__feedback-button","chat-message__feedback-button--down",{"chat-message__feedback-button--selected":i===xn}),onClick:()=>_(xn),children:[s.jsx(Ir,{size:Rn,strokeWidth:1.5,className:"chat-message__feedback-button-icon","aria-hidden":!0}),s.jsx("span",{className:"chat-message__feedback-button-text",children:"Missed the mark"})]})]})]})},qr=({id:e,text:n,type:r,onRate:a,ratingPopupUrls:u={},chatId:i,showRating:d=!1,followUpPrompts:h,onFollowUpPromptClick:_,processCanvasReferences:m,isFallbackMessage:E,onRatingPopupOpen:S,children:g})=>{const A=r===Rt,x=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:pe("chat-message",{"chat-message--user":r===Ze,"chat-message--agent":r===Rt,"chat-message--info":r===Bt,"chat-message--error":r===Ee,"chat-message--warning":r===kt}),children:[r===Bt&&s.jsx(vr,{className:"chat-message__icon","aria-label":"Information",size:20}),r===kt&&s.jsx(Gr,{className:"chat-message__icon","aria-label":"Warning",size:20}),r===Ee&&s.jsx(kr,{className:"chat-message__icon","aria-label":"Error",size:20}),g??s.jsx("span",{dangerouslySetInnerHTML:{__html:m(n)}})]}),A&&s.jsxs("div",{className:"chat-message__footer-actions",children:[s.jsx("div",{className:"chat-message__footer-icons",children:d&&a&&i&&s.jsx(Kr,{upRatingPopupUrl:u.up,downRatingPopupUrl:u.down,message:{id:e,type:r,text:n},onRate:O=>a(O,e),onRatingPopupOpen:S})}),s.jsx("div",{className:"chat-message__follow-up-prompts",children:h&&h.length>0&&!E&&s.jsx("ul",{className:"chat-message__follow-up-prompts-list",children:h.map((O,N)=>s.jsx("li",{children:s.jsx("button",{type:"button",className:"chat-message__follow-up-prompt",onClick:()=>_==null?void 0:_(O),children:O})},`follow-up-prompt-${N}`))})})]})]});return s.jsx("li",{className:pe("chat-message-container",{"chat-message-container--user":r===Ze,"chat-message-container--agent":A}),children:A?s.jsx("div",{className:"chat-message-container__content",children:x}):x})},Vr="Not authorised. Your session could have expired or is invalid. Please refresh the page and try again.",Xr="You do not have permission to use this feature. Please contact your administrator if you need access.",Zr="The chat service could not be found. Please check your configuration and try again.",Jr="It looks like this request took too long to complete. Please try again.",Qr="Whoops! Too many requests. Please wait a moment and try again.",es="The chat service is temporarily unavailable. Please try again later.",ts="Unable to reach the chat service. Please check your connection and try again.",Vn="Something went wrong. Please try again later.",ns="Something went wrong while trying to get a new agent message. Please try again later.",kn="keyboard-shortcut-menu-portal";function rs(){let e=document.getElementById(kn);return e||(e=document.createElement("div"),e.id=kn,e.style.cssText="position:fixed;left:0;top:0;z-index:19950;pointer-events:none;",document.body.appendChild(e)),e}const Wt=200;function ss(e){const n=window.innerHeight,r=e.top+e.height>n-Wt,a=e.top<Wt;return r?"above":a?"below":"above"}function os(e){const n=ss(e),r=8;return n==="below"?{left:e.left,width:e.width,top:e.bottom+r,placement:"below"}:{left:e.left,width:e.width,bottom:window.innerHeight-e.top+r,placement:"above"}}function Cn(e,n){if(n){n(e);return}/^https?:\/\//.test(e)?window.open(e,"_blank","noopener,noreferrer"):window.location.href=e}const as=({anchorRef:e,...n})=>{const[r,a]=l.useState(null);if(l.useLayoutEffect(()=>{const i=()=>{const m=e.current;if(!m)return;const E=m.getBoundingClientRect();a(os(E))};i();const d=requestAnimationFrame(()=>i()),h=()=>i(),_=()=>i();return document.addEventListener("scroll",h,!0),window.addEventListener("resize",_),()=>{cancelAnimationFrame(d),document.removeEventListener("scroll",h,!0),window.removeEventListener("resize",_)}},[e]),!r)return null;const u={position:"fixed",left:r.left,width:r.width,pointerEvents:"auto"};return r.placement==="below"?u.top=r.top:u.bottom=r.bottom,dr.createPortal(s.jsx(Xn,{...n,portalStyle:u}),rs())},Xn=e=>{const{menuItems:n=[],onSelectItem:r,onClose:a,hideReferenceFromList:u=!1,anchorRef:i,portalStyle:d,onNavigate:h}=e,[_,m]=l.useState(0),[E,S]=l.useState(""),[g,A]=l.useState(n),x=l.useRef(null),O=l.useRef(null),N=l.useRef(null),[w,j]=l.useState(!1),[ue,U]=l.useState(!1),$=d?d.top!=null:w,M=d?!0:ue;l.useEffect(()=>{m(0),S("")},[]),l.useEffect(()=>{d&&setTimeout(()=>{var T;return(T=N.current)==null?void 0:T.focus()},0)},[d]),l.useEffect(()=>{if(d||i||!x.current)return;const T=x.current.getBoundingClientRect(),v=window.innerHeight,H=T.top,ee=H+T.height>v-Wt,L=H<Wt;j(ee?!1:!!L),U(!0),setTimeout(()=>{var z;return(z=N.current)==null?void 0:z.focus()},0)},[i]),l.useEffect(()=>{if(O.current){const T=O.current.querySelector(".keyboard-shortcut-menu__items"),v=T==null?void 0:T.querySelector(".keyboard-shortcut-menu__item--selected");v&&v.scrollIntoView({behavior:"smooth",block:"nearest"})}},[_]),l.useEffect(()=>{A(E?n.filter(T=>T.reference.toLowerCase().includes(E.toLowerCase())||T.description.toLowerCase().includes(E.toLowerCase())):n)},[E,n]);const Y=T=>{var v;r&&g[T]&&!g[T].link&&r(g[T]),a&&!((v=g[T])!=null&&v.link)&&a()};l.useEffect(()=>{const T=H=>{H.key==="Escape"&&a&&(H.preventDefault(),a())},v=H=>{x.current&&!x.current.contains(H.target)&&a&&a()};return document.addEventListener("keydown",T),document.addEventListener("mousedown",v),()=>{document.removeEventListener("keydown",T),document.removeEventListener("mousedown",v)}},[a]);const de=T=>{switch(T.key){case"ArrowDown":T.preventDefault(),m(v=>v<g.length-1?v+1:v);break;case"ArrowUp":T.preventDefault(),m(v=>v>0?v-1:0);break;case"Enter":T.preventDefault(),g[_]&&(g[_].link?Cn(g[_].link.replace(/\/\?/g,""),h):Y(_));break;case"Escape":T.preventDefault(),a&&a();break}},V=T=>{S(T),m(0)},F=(T,v)=>{const H=v===_,ee=T.icon?s.jsxs(s.Fragment,{children:[s.jsx(Re.Icon,{name:T.icon,size:12}),s.jsx("span",{className:"keyboard-shortcut-menu__item-description keyboard-shortcut-menu__item-main",children:T.description})]}):s.jsx(s.Fragment,{children:u?s.jsx("span",{"data-testid":"keyboard-shortcut-menu-item",className:"keyboard-shortcut-menu__item-description keyboard-shortcut-menu__item-main",children:T.description}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"keyboard-shortcut-menu__item-reference keyboard-shortcut-menu__item-main",children:T.reference}),s.jsx("span",{className:"keyboard-shortcut-menu__item-description keyboard-shortcut-menu__item-secondary",children:T.description})]})});if(T.link){const L=T.link.replace(/\/\?/g,"");return s.jsx("li",{role:"menuitem",children:s.jsx("a",{href:L,className:pe("keyboard-shortcut-menu__item-main keyboard-shortcut-menu__item",{"keyboard-shortcut-menu__item--selected":H,"keyboard-shortcut-menu__item--with-icon":!!T.icon}),onClick:z=>{z.preventDefault(),Cn(L,h),a==null||a()},children:ee})},T.reference)}return s.jsx("li",{role:"menuitem",className:pe("keyboard-shortcut-menu__item",{"keyboard-shortcut-menu__item--selected":H,"keyboard-shortcut-menu__item--with-icon":!!T.icon}),onClick:()=>{r&&r(T),a&&a()},"aria-selected":H,children:ee},T.reference)},ce=s.jsx("div",{className:pe("keyboard-shortcut-menu",{"keyboard-shortcut-menu-below":$,"keyboard-shortcut-menu-hidden":!M}),onKeyDown:de,tabIndex:0,"aria-label":"Keyboard shortcut menu","data-testid":"keyboard-shortcut-menu",ref:x,children:s.jsxs("div",{className:"keyboard-shortcut-menu__content",ref:O,children:[s.jsxs("div",{className:"keyboard-shortcut-menu__header",children:[s.jsx("div",{className:"keyboard-shortcut-menu__search",children:s.jsx("input",{type:"text",value:E,onChange:T=>V(T.target.value),placeholder:"Search...",autoFocus:!0,ref:N})}),a&&s.jsx("button",{type:"button",className:"keyboard-shortcut-menu__close",onClick:a,"aria-label":"Close menu",children:s.jsx(Wr,{size:12,className:"keyboard-shortcut-menu__close-icon"})})]}),s.jsx("ul",{className:"keyboard-shortcut-menu__items",role:"menu","aria-label":"Menu options",children:g.length===0?s.jsx("li",{className:"keyboard-shortcut-menu__no-results",role:"menuitem",children:"No results found"}):g.map((T,v)=>F(T,v))})]})});return i&&!d?s.jsx(as,{anchorRef:i,menuItems:n,onSelectItem:r,onClose:a,hideReferenceFromList:e.hideReferenceFromList,title:e.title,onNavigate:h}):d?s.jsx("div",{style:d,children:ce}):ce},In=({className:e})=>s.jsx("div",{className:pe("loading-spinner",e),"aria-label":"Loading",role:"img",children:s.jsxs("div",{className:"loading-spinner__inner",role:"presentation",children:[s.jsx("div",{className:"loading-spinner__circle loading-spinner__circle-left",role:"presentation"}),s.jsx("div",{className:"loading-spinner__circle loading-spinner__circle-top",role:"presentation"}),s.jsx("div",{className:"loading-spinner__circle loading-spinner__circle-right",role:"presentation"}),s.jsx("div",{className:"loading-spinner__circle loading-spinner__circle-bottom",role:"presentation"})]})}),is=4e3,cs=500,ls=8e3,en=["I'm working on it…","Generating insights…","Piecing things together…","Processing your request…","Refining the details…","Just a moment…","Organising the information…","Bringing it all together…","Gathering facts…","Crafting a response…","Thinking things through…","Preparing results…","Double-checking my output…","Reviewing the options…","Gathering data…","Looking at data…","Digging deeper…","Reaching a conclusion…","Checking the data…","Thinking…","Putting ideas together…","Cross-checking information…","Filling in the gaps…","Finding the answers…","Organising my thoughts…","On it…","Working on my response…","Building your response…","Exploring the possibilities…","Completing the task…","Shaping the outcome…","Fine-tuning the details…","Crunching the data…","Looking up insights…","Composing an answer…","Pulling it all together…","Preparing a solution…","Making connections…","Polishing the results…","Steady progress…","Testing assumptions…","Checking possibilities…","Sifting through some ideas…","Organising concepts…","Analysing your query…","Analysing results…","Working through the details…"],us=({loadingPhrase:e,showSpinnerAsIcon:n=!0,showNotifyLaterButton:r=!1,onNotifyLater:a,onNotificationRegisteredGotIt:u})=>{const i=()=>Math.floor(Math.random()*en.length),d=l.useRef(null),[h,_]=l.useState(e||en[i()]),[m,E]=l.useState("fade-in"),[S,g]=l.useState(!1),[A,x]=l.useState(!1);l.useEffect(()=>{r||x(!1)},[r]),l.useEffect(()=>{if(!r||!a)return;const w=setTimeout(()=>{g(!0)},ls);return()=>{clearTimeout(w)}},[r,a]);const O=async()=>{if(!a)return;await a()&&x(!0)},N=()=>{x(!1),u==null||u()};return l.useEffect(()=>{let w=null;return e?(_(e),E("fade-in")):w=setInterval(()=>{E("fade-out"),setTimeout(()=>{let j;do j=i();while(j===d.current);d.current=j,_(en[j]),E("fade-in")},cs)},is),()=>{w&&clearInterval(w)}},[e]),s.jsxs("li",{"aria-label":"Loading response",className:"chat-panel__loading-container","data-testid":"loading-widget",children:[s.jsxs("div",{className:"chat-panel__loading-content",children:[n?s.jsx(In,{className:"chat-panel__loading-spinner"}):s.jsx("span",{className:"chat-panel__loading-spinner-container",children:s.jsx(In,{className:"chat-panel__loading-spinner"})}),s.jsx("span",{className:`chat-panel__loading-phrase ${m}`,children:h})]}),r&&a&&S&&s.jsx("div",{className:"chat-panel__notify-later",children:A?s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"chat-panel__notify-later-message",children:"We'll notify you in the notifications panel on the left of your MIS."}),s.jsx("button",{type:"button",className:"chat-panel__notify-later-btn",onClick:N,"aria-label":"Got it",children:"Got it"})]}):s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"chat-panel__notify-later-message",children:"This one's taking a bit longer than usual"}),s.jsx("button",{type:"button",className:"chat-panel__notify-later-btn",onClick:O,"aria-label":"Let me know when it's done",children:"Let me know when it's done"})]})})]})};function ds(e){l.useEffect(e,[])}function fs(){const e=l.useRef(!1);return l.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),e}function ps(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():Math.random().toString(36).substring(2)+Date.now().toString(36)}function ms(e,n=0){if(typeof e=="number"&&e>0)return e;if(typeof e=="string"){const r=parseInt(e,10);if(!isNaN(r)&&r>0)return r}return n}const hs=/\*\*(.+?)\*\*/g;function _s(e){return e.replace(hs,"<strong>$1</strong>")}/*! @license DOMPurify 3.4.11 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.11/LICENSE */function On(e,n){(n==null||n>e.length)&&(n=e.length);for(var r=0,a=Array(n);r<n;r++)a[r]=e[r];return a}function gs(e){if(Array.isArray(e))return e}function bs(e,n){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var a,u,i,d,h=[],_=!0,m=!1;try{if(i=(r=r.call(e)).next,n!==0)for(;!(_=(a=i.call(r)).done)&&(h.push(a.value),h.length!==n);_=!0);}catch(E){m=!0,u=E}finally{try{if(!_&&r.return!=null&&(d=r.return(),Object(d)!==d))return}finally{if(m)throw u}}return h}}function Ts(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
91
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ys(e,n){return gs(e)||bs(e,n)||Es(e,n)||Ts()}function Es(e,n){if(e){if(typeof e=="string")return On(e,n);var r={}.toString.call(e).slice(8,-1);return r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set"?Array.from(e):r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?On(e,n):void 0}}const Zn=Object.entries,vn=Object.setPrototypeOf,As=Object.isFrozen,Ss=Object.getPrototypeOf,Ns=Object.getOwnPropertyDescriptor;let re=Object.freeze,se=Object.seal,ft=Object.create,Jn=typeof Reflect<"u"&&Reflect,cn=Jn.apply,ln=Jn.construct;re||(re=function(n){return n});se||(se=function(n){return n});cn||(cn=function(n,r){for(var a=arguments.length,u=new Array(a>2?a-2:0),i=2;i<a;i++)u[i-2]=arguments[i];return n.apply(r,u)});ln||(ln=function(n){for(var r=arguments.length,a=new Array(r>1?r-1:0),u=1;u<r;u++)a[u-1]=arguments[u];return new n(...a)});const At=q(Array.prototype.forEach),ws=q(Array.prototype.lastIndexOf),Ln=q(Array.prototype.pop),dt=q(Array.prototype.push),xs=q(Array.prototype.splice),Fe=Array.isArray,xt=q(String.prototype.toLowerCase),tn=q(String.prototype.toString),Dn=q(String.prototype.match),St=q(String.prototype.replace),Mn=q(String.prototype.indexOf),Rs=q(String.prototype.trim),ks=q(Number.prototype.toString),Cs=q(Boolean.prototype.toString),Pn=typeof BigInt>"u"?null:q(BigInt.prototype.toString),jn=typeof Symbol>"u"?null:q(Symbol.prototype.toString),Q=q(Object.prototype.hasOwnProperty),Nt=q(Object.prototype.toString),ne=q(RegExp.prototype.test),Xe=Is(TypeError);function q(e){return function(n){n instanceof RegExp&&(n.lastIndex=0);for(var r=arguments.length,a=new Array(r>1?r-1:0),u=1;u<r;u++)a[u-1]=arguments[u];return cn(e,n,a)}}function Is(e){return function(){for(var n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];return ln(e,r)}}function C(e,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:xt;if(vn&&vn(e,null),!Fe(n))return e;let a=n.length;for(;a--;){let u=n[a];if(typeof u=="string"){const i=r(u);i!==u&&(As(n)||(n[a]=i),u=i)}e[u]=!0}return e}function Os(e){for(let n=0;n<e.length;n++)Q(e,n)||(e[n]=null);return e}function ie(e){const n=ft(null);for(const a of Zn(e)){var r=ys(a,2);const u=r[0],i=r[1];Q(e,u)&&(Fe(i)?n[u]=Os(i):i&&typeof i=="object"&&i.constructor===Object?n[u]=ie(i):n[u]=i)}return n}function vs(e){switch(typeof e){case"string":return e;case"number":return ks(e);case"boolean":return Cs(e);case"bigint":return Pn?Pn(e):"0";case"symbol":return jn?jn(e):"Symbol()";case"undefined":return Nt(e);case"function":case"object":{if(e===null)return Nt(e);const n=e,r=xe(n,"toString");if(typeof r=="function"){const a=r(n);return typeof a=="string"?a:Nt(a)}return Nt(e)}default:return Nt(e)}}function xe(e,n){for(;e!==null;){const a=Ns(e,n);if(a){if(a.get)return q(a.get);if(typeof a.value=="function")return q(a.value)}e=Ss(e)}function r(){return null}return r}function Ls(e){try{return ne(e,""),!0}catch{return!1}}const Un=re(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),nn=re(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),rn=re(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),Ds=re(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),sn=re(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),Ms=re(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),Fn=re(["#text"]),Hn=re(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","command","commandfor","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns"]),on=re(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),zn=re(["accent","accentunder","align","bevelled","close","columnalign","columnlines","columnspacing","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lquote","lspace","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),zt=re(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),Ps=se(/{{[\w\W]*|^[\w\W]*}}/g),js=se(/<%[\w\W]*|^[\w\W]*%>/g),Us=se(/\${[\w\W]*/g),Fs=se(/^data-[\-\w.\u00B7-\uFFFF]+$/),Hs=se(/^aria-[\-\w]+$/),Gn=se(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),zs=se(/^(?:\w+script|data):/i),Gs=se(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Bs=se(/^html$/i),Ws=se(/^[a-z][.\w]*(-[.\w]+)+$/i),Bn=se(/<[/\w!]/g),$s=se(/<[/\w]/g),Ys=se(/<\/no(script|embed|frames)/i),Ks=se(/\/>/i),we={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},qs=function(){return typeof window>"u"?null:window},Vs=function(n,r){if(typeof n!="object"||typeof n.createPolicy!="function")return null;let a=null;const u="data-tt-policy-suffix";r&&r.hasAttribute(u)&&(a=r.getAttribute(u));const i="dompurify"+(a?"#"+a:"");try{return n.createPolicy(i,{createHTML(d){return d},createScriptURL(d){return d}})}catch{return console.warn("TrustedTypes policy "+i+" could not be created."),null}},Wn=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Ue=function(n,r,a,u){return Q(n,r)&&Fe(n[r])?C(u.base?ie(u.base):{},n[r],u.transform):a};function Qn(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:qs();const n=p=>Qn(p);if(n.version="3.4.11",n.removed=[],!e||!e.document||e.document.nodeType!==we.document||!e.Element)return n.isSupported=!1,n;let r=e.document;const a=r,u=a.currentScript;e.DocumentFragment;const i=e.HTMLTemplateElement,d=e.Node,h=e.Element,_=e.NodeFilter,m=e.NamedNodeMap;m===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;const E=e.DOMParser,S=e.trustedTypes,g=h.prototype,A=xe(g,"cloneNode"),x=xe(g,"remove"),O=xe(g,"nextSibling"),N=xe(g,"childNodes"),w=xe(g,"parentNode"),j=xe(g,"shadowRoot"),ue=xe(g,"attributes"),U=d&&d.prototype?xe(d.prototype,"nodeType"):null,$=d&&d.prototype?xe(d.prototype,"nodeName"):null;if(typeof i=="function"){const p=r.createElement("template");p.content&&p.content.ownerDocument&&(r=p.content.ownerDocument)}let M,Y="",de,V=!1,F=0;const ce=function(){if(F>0)throw Xe('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},T=function(t){ce(),F++;try{return M.createHTML(t)}finally{F--}},v=function(t){ce(),F++;try{return M.createScriptURL(t)}finally{F--}},H=function(){return V||(de=Vs(S,u),V=!0),de},ee=r,L=ee.implementation,z=ee.createNodeIterator,fe=ee.createDocumentFragment,Ce=ee.getElementsByTagName,ve=a.importNode;let P=Wn();n.isSupported=typeof Zn=="function"&&typeof w=="function"&&L&&L.createHTMLDocument!==void 0;const te=Ps,pt=js,X=Us,mt=Fs,$t=Hs,Ct=zs,Je=Gs,He=Ws;let Le=Gn,D=null;const Qe=C({},[...Un,...nn,...rn,...sn,...Fn]);let B=null;const et=C({},[...Hn,...on,...zn,...zt]);let G=Object.seal(ft(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),Ae=null,ht=null;const be=Object.seal(ft(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let It=!0,ze=!0,tt=!1,De=!0,Te=!1,Ge=!0,Se=!1,nt=!1,Be=null,Me=null,rt=!1,Ie=!1,We=!1,st=!1,_t=!0,$e=!1;const ot="user-content-";let gt=!0,at=!1,Pe={},me=null;const Ye=C({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]);let Ot=null;const Ke=C({},["audio","video","img","source","image","track"]);let bt=null;const vt=C({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Ne="http://www.w3.org/1998/Math/MathML",it="http://www.w3.org/2000/svg",Z="http://www.w3.org/1999/xhtml";let he=Z,ct=!1,lt=null;const Yt=C({},[Ne,it,Z],tn),Lt=re(["mi","mo","mn","ms","mtext"]);let Tt=C({},Lt);const Dt=re(["annotation-xml"]);let yt=C({},Dt);const Kt=C({},["title","style","font","a","script"]);let qe=null;const qt=["application/xhtml+xml","text/html"],Mt="text/html";let W=null,c=null;const y=r.createElement("form"),k=function(t){return t instanceof RegExp||t instanceof Function},oe=function(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(c&&c===t)return;(!t||typeof t!="object")&&(t={}),t=ie(t),qe=qt.indexOf(t.PARSER_MEDIA_TYPE)===-1?Mt:t.PARSER_MEDIA_TYPE,W=qe==="application/xhtml+xml"?tn:xt,D=Ue(t,"ALLOWED_TAGS",Qe,{transform:W}),B=Ue(t,"ALLOWED_ATTR",et,{transform:W}),lt=Ue(t,"ALLOWED_NAMESPACES",Yt,{transform:tn}),bt=Ue(t,"ADD_URI_SAFE_ATTR",vt,{transform:W,base:vt}),Ot=Ue(t,"ADD_DATA_URI_TAGS",Ke,{transform:W,base:Ke}),me=Ue(t,"FORBID_CONTENTS",Ye,{transform:W}),Ae=Ue(t,"FORBID_TAGS",ie({}),{transform:W}),ht=Ue(t,"FORBID_ATTR",ie({}),{transform:W}),Pe=Q(t,"USE_PROFILES")?t.USE_PROFILES&&typeof t.USE_PROFILES=="object"?ie(t.USE_PROFILES):t.USE_PROFILES:!1,It=t.ALLOW_ARIA_ATTR!==!1,ze=t.ALLOW_DATA_ATTR!==!1,tt=t.ALLOW_UNKNOWN_PROTOCOLS||!1,De=t.ALLOW_SELF_CLOSE_IN_ATTR!==!1,Te=t.SAFE_FOR_TEMPLATES||!1,Ge=t.SAFE_FOR_XML!==!1,Se=t.WHOLE_DOCUMENT||!1,Ie=t.RETURN_DOM||!1,We=t.RETURN_DOM_FRAGMENT||!1,st=t.RETURN_TRUSTED_TYPE||!1,rt=t.FORCE_BODY||!1,_t=t.SANITIZE_DOM!==!1,$e=t.SANITIZE_NAMED_PROPS||!1,gt=t.KEEP_CONTENT!==!1,at=t.IN_PLACE||!1,Le=Ls(t.ALLOWED_URI_REGEXP)?t.ALLOWED_URI_REGEXP:Gn,he=typeof t.NAMESPACE=="string"?t.NAMESPACE:Z,Tt=Q(t,"MATHML_TEXT_INTEGRATION_POINTS")&&t.MATHML_TEXT_INTEGRATION_POINTS&&typeof t.MATHML_TEXT_INTEGRATION_POINTS=="object"?ie(t.MATHML_TEXT_INTEGRATION_POINTS):C({},Lt),yt=Q(t,"HTML_INTEGRATION_POINTS")&&t.HTML_INTEGRATION_POINTS&&typeof t.HTML_INTEGRATION_POINTS=="object"?ie(t.HTML_INTEGRATION_POINTS):C({},Dt);const o=Q(t,"CUSTOM_ELEMENT_HANDLING")&&t.CUSTOM_ELEMENT_HANDLING&&typeof t.CUSTOM_ELEMENT_HANDLING=="object"?ie(t.CUSTOM_ELEMENT_HANDLING):ft(null);if(G=ft(null),Q(o,"tagNameCheck")&&k(o.tagNameCheck)&&(G.tagNameCheck=o.tagNameCheck),Q(o,"attributeNameCheck")&&k(o.attributeNameCheck)&&(G.attributeNameCheck=o.attributeNameCheck),Q(o,"allowCustomizedBuiltInElements")&&typeof o.allowCustomizedBuiltInElements=="boolean"&&(G.allowCustomizedBuiltInElements=o.allowCustomizedBuiltInElements),se(G),Te&&(ze=!1),We&&(Ie=!0),Pe&&(D=C({},Fn),B=ft(null),Pe.html===!0&&(C(D,Un),C(B,Hn)),Pe.svg===!0&&(C(D,nn),C(B,on),C(B,zt)),Pe.svgFilters===!0&&(C(D,rn),C(B,on),C(B,zt)),Pe.mathMl===!0&&(C(D,sn),C(B,zn),C(B,zt))),be.tagCheck=null,be.attributeCheck=null,Q(t,"ADD_TAGS")&&(typeof t.ADD_TAGS=="function"?be.tagCheck=t.ADD_TAGS:Fe(t.ADD_TAGS)&&(D===Qe&&(D=ie(D)),C(D,t.ADD_TAGS,W))),Q(t,"ADD_ATTR")&&(typeof t.ADD_ATTR=="function"?be.attributeCheck=t.ADD_ATTR:Fe(t.ADD_ATTR)&&(B===et&&(B=ie(B)),C(B,t.ADD_ATTR,W))),Q(t,"ADD_URI_SAFE_ATTR")&&Fe(t.ADD_URI_SAFE_ATTR)&&C(bt,t.ADD_URI_SAFE_ATTR,W),Q(t,"FORBID_CONTENTS")&&Fe(t.FORBID_CONTENTS)&&(me===Ye&&(me=ie(me)),C(me,t.FORBID_CONTENTS,W)),Q(t,"ADD_FORBID_CONTENTS")&&Fe(t.ADD_FORBID_CONTENTS)&&(me===Ye&&(me=ie(me)),C(me,t.ADD_FORBID_CONTENTS,W)),gt&&(D["#text"]=!0),Se&&C(D,["html","head","body"]),D.table&&(C(D,["tbody"]),delete Ae.tbody),t.TRUSTED_TYPES_POLICY){if(typeof t.TRUSTED_TYPES_POLICY.createHTML!="function")throw Xe('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof t.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Xe('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');const f=M;M=t.TRUSTED_TYPES_POLICY;try{Y=T("")}catch(b){throw M=f,b}}else t.TRUSTED_TYPES_POLICY===null?(M=void 0,Y=""):(M===void 0&&(M=H()),M&&typeof Y=="string"&&(Y=T("")));re&&re(t),c=t},_e=C({},[...nn,...rn,...Ds]),le=C({},[...sn,...Ms]),Pt=function(t,o,f){return o.namespaceURI===Z?t==="svg":o.namespaceURI===Ne?t==="svg"&&(f==="annotation-xml"||Tt[f]):!!_e[t]},hn=function(t,o,f){return o.namespaceURI===Z?t==="math":o.namespaceURI===it?t==="math"&&yt[f]:!!le[t]},_n=function(t,o,f){return o.namespaceURI===it&&!yt[f]||o.namespaceURI===Ne&&!Tt[f]?!1:!le[t]&&(Kt[t]||!_e[t])},jt=function(t){let o=w(t);(!o||!o.tagName)&&(o={namespaceURI:he,tagName:"template"});const f=xt(t.tagName),b=xt(o.tagName);return lt[t.namespaceURI]?t.namespaceURI===it?Pt(f,o,b):t.namespaceURI===Ne?hn(f,o,b):t.namespaceURI===Z?_n(f,o,b):!!(qe==="application/xhtml+xml"&<[t.namespaceURI]):!1},je=function(t){dt(n.removed,{element:t});try{w(t).removeChild(t)}catch{if(x(t),!w(t))throw Xe("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},gn=function(t){const o=N(t);if(o){const b=[];At(o,R=>{dt(b,R)}),At(b,R=>{try{x(R)}catch{}})}const f=ue(t);if(f)for(let b=f.length-1;b>=0;--b){const R=f[b],I=R&&R.name;if(typeof I=="string")try{t.removeAttribute(I)}catch{}}},Ve=function(t,o){try{dt(n.removed,{attribute:o.getAttributeNode(t),from:o})}catch{dt(n.removed,{attribute:null,from:o})}if(o.removeAttribute(t),t==="is")if(Ie||We)try{je(o)}catch{}else try{o.setAttribute(t,"")}catch{}},sr=function(t){const o=ue(t);if(o)for(let f=o.length-1;f>=0;--f){const b=o[f],R=b&&b.name;if(!(typeof R!="string"||B[W(R)]))try{t.removeAttribute(R)}catch{}}},or=function(t){const o=[t];for(;o.length>0;){const f=o.pop();(U?U(f):f.nodeType)===we.element&&sr(f);const R=N(f);if(R)for(let I=R.length-1;I>=0;--I)o.push(R[I])}},bn=function(t){let o=null,f=null;if(rt)t="<remove></remove>"+t;else{const I=Dn(t,/^[\r\n\t ]+/);f=I&&I[0]}qe==="application/xhtml+xml"&&he===Z&&(t='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+t+"</body></html>");const b=M?T(t):t;if(he===Z)try{o=new E().parseFromString(b,qe)}catch{}if(!o||!o.documentElement){o=L.createDocument(he,"template",null);try{o.documentElement.innerHTML=ct?Y:b}catch{}}const R=o.body||o.documentElement;return t&&f&&R.insertBefore(r.createTextNode(f),R.childNodes[0]||null),he===Z?Ce.call(o,Se?"html":"body")[0]:Se?o.documentElement:R},Tn=function(t){return z.call(t.ownerDocument||t,t,_.SHOW_ELEMENT|_.SHOW_COMMENT|_.SHOW_TEXT|_.SHOW_PROCESSING_INSTRUCTION|_.SHOW_CDATA_SECTION,null)},Ut=function(t){return t=St(t,te," "),t=St(t,pt," "),t=St(t,X," "),t},Vt=function(t){var o;t.normalize();const f=z.call(t.ownerDocument||t,t,_.SHOW_TEXT|_.SHOW_COMMENT|_.SHOW_CDATA_SECTION|_.SHOW_PROCESSING_INSTRUCTION,null);let b=f.nextNode();for(;b;)b.data=Ut(b.data),b=f.nextNode();const R=(o=t.querySelectorAll)===null||o===void 0?void 0:o.call(t,"template");R&&At(R,I=>{ut(I.content)&&Vt(I.content)})},Ft=function(t){const o=$?$(t):null;return typeof o!="string"||W(o)!=="form"?!1:typeof t.nodeName!="string"||typeof t.textContent!="string"||typeof t.removeChild!="function"||t.attributes!==ue(t)||typeof t.removeAttribute!="function"||typeof t.setAttribute!="function"||typeof t.namespaceURI!="string"||typeof t.insertBefore!="function"||typeof t.hasChildNodes!="function"||t.nodeType!==U(t)||t.childNodes!==N(t)},ut=function(t){if(!U||typeof t!="object"||t===null)return!1;try{return U(t)===we.documentFragment}catch{return!1}},Et=function(t){if(!U||typeof t!="object"||t===null)return!1;try{return typeof U(t)=="number"}catch{return!1}};function Oe(p,t,o){p.length!==0&&At(p,f=>{f.call(n,t,o,c)})}const ar=function(t,o){return!!(Ge&&t.hasChildNodes()&&!Et(t.firstElementChild)&&ne(Bn,t.textContent)&&ne(Bn,t.innerHTML)||Ge&&t.namespaceURI===Z&&o==="style"&&Et(t.firstElementChild)||t.nodeType===we.processingInstruction||Ge&&t.nodeType===we.comment&&ne($s,t.data))},ir=function(t,o){if(!Ae[o]&&An(o)&&(G.tagNameCheck instanceof RegExp&&ne(G.tagNameCheck,o)||G.tagNameCheck instanceof Function&&G.tagNameCheck(o)))return!1;if(gt&&!me[o]){const f=w(t),b=N(t);if(b&&f){const R=b.length;for(let I=R-1;I>=0;--I){const J=at?b[I]:A(b[I],!0);f.insertBefore(J,O(t))}}}return je(t),!0},yn=function(t){if(Oe(P.beforeSanitizeElements,t,null),Ft(t))return je(t),!0;const o=W($?$(t):t.nodeName);if(Oe(P.uponSanitizeElement,t,{tagName:o,allowedTags:D}),ar(t,o))return je(t),!0;if(Ae[o]||!(be.tagCheck instanceof Function&&be.tagCheck(o))&&!D[o])return ir(t,o);if((U?U(t):t.nodeType)===we.element&&!jt(t)||(o==="noscript"||o==="noembed"||o==="noframes")&&ne(Ys,t.innerHTML))return je(t),!0;if(Te&&t.nodeType===we.text){const b=Ut(t.textContent);t.textContent!==b&&(dt(n.removed,{element:t.cloneNode()}),t.textContent=b)}return Oe(P.afterSanitizeElements,t,null),!1},En=function(t,o,f){if(ht[o]||_t&&(o==="id"||o==="name")&&(f in r||f in y))return!1;const b=B[o]||be.attributeCheck instanceof Function&&be.attributeCheck(o,t);if(!(ze&&ne(mt,o))){if(!(It&&ne($t,o))){if(b){if(!bt[o]){if(!ne(Le,St(f,Je,""))){if(!((o==="src"||o==="xlink:href"||o==="href")&&t!=="script"&&Mn(f,"data:")===0&&Ot[t])){if(!(tt&&!ne(Ct,St(f,Je,"")))){if(f)return!1}}}}}else if(!(An(t)&&(G.tagNameCheck instanceof RegExp&&ne(G.tagNameCheck,t)||G.tagNameCheck instanceof Function&&G.tagNameCheck(t))&&(G.attributeNameCheck instanceof RegExp&&ne(G.attributeNameCheck,o)||G.attributeNameCheck instanceof Function&&G.attributeNameCheck(o,t))||o==="is"&&G.allowCustomizedBuiltInElements&&(G.tagNameCheck instanceof RegExp&&ne(G.tagNameCheck,f)||G.tagNameCheck instanceof Function&&G.tagNameCheck(f))))return!1}}return!0},cr=C({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),An=function(t){return!cr[xt(t)]&&ne(He,t)},lr=function(t,o,f,b){if(M&&typeof S=="object"&&typeof S.getAttributeType=="function"&&!f)switch(S.getAttributeType(t,o)){case"TrustedHTML":return T(b);case"TrustedScriptURL":return v(b)}return b},ur=function(t,o,f,b){try{f?t.setAttributeNS(f,o,b):t.setAttribute(o,b),Ft(t)?je(t):Ln(n.removed)}catch{Ve(o,t)}},Sn=function(t){Oe(P.beforeSanitizeAttributes,t,null);const o=t.attributes;if(!o||Ft(t))return;const f={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:B,forceKeepAttr:void 0};let b=o.length;const R=W(t.nodeName);for(;b--;){const I=o[b],J=I.name,K=I.namespaceURI,ge=I.value,ye=W(J),Zt=ge;let ae=J==="value"?Zt:Rs(Zt);if(f.attrName=ye,f.attrValue=ae,f.keepAttr=!0,f.forceKeepAttr=void 0,Oe(P.uponSanitizeAttribute,t,f),ae=f.attrValue,$e&&(ye==="id"||ye==="name")&&Mn(ae,ot)!==0&&(Ve(J,t),ae=ot+ae),Ge&&ne(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,ae)){Ve(J,t);continue}if(ye==="attributename"&&Dn(ae,"href")){Ve(J,t);continue}if(!f.forceKeepAttr){if(!f.keepAttr){Ve(J,t);continue}if(!De&&ne(Ks,ae)){Ve(J,t);continue}if(Te&&(ae=Ut(ae)),!En(R,ye,ae)){Ve(J,t);continue}ae=lr(R,ye,K,ae),ae!==Zt&&ur(t,J,K,ae)}}Oe(P.afterSanitizeAttributes,t,null)},Ht=function(t){let o=null;const f=Tn(t);for(Oe(P.beforeSanitizeShadowDOM,t,null);o=f.nextNode();)if(Oe(P.uponSanitizeShadowNode,o,null),yn(o),Sn(o),ut(o.content)&&Ht(o.content),(U?U(o):o.nodeType)===we.element){const R=j(o);ut(R)&&(Xt(R),Ht(R))}Oe(P.afterSanitizeShadowDOM,t,null)},Xt=function(t){const o=[{node:t,shadow:null}];for(;o.length>0;){const f=o.pop();if(f.shadow){Ht(f.shadow);continue}const b=f.node,I=(U?U(b):b.nodeType)===we.element,J=N(b);if(J)for(let K=J.length-1;K>=0;--K)o.push({node:J[K],shadow:null});if(I){const K=$?$(b):null;if(typeof K=="string"&&W(K)==="template"){const ge=b.content;ut(ge)&&o.push({node:ge,shadow:null})}}if(I){const K=j(b);ut(K)&&o.push({node:null,shadow:K},{node:K,shadow:null})}}};return n.sanitize=function(p){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=null,f=null,b=null,R=null;if(ct=!p,ct&&(p="<!-->"),typeof p!="string"&&!Et(p)&&(p=vs(p),typeof p!="string"))throw Xe("dirty is not a string, aborting");if(!n.isSupported)return p;nt?(D=Be,B=Me):oe(t),(P.uponSanitizeElement.length>0||P.uponSanitizeAttribute.length>0)&&(D=ie(D)),P.uponSanitizeAttribute.length>0&&(B=ie(B)),n.removed=[];const I=at&&typeof p!="string"&&Et(p);if(I){const ge=$?$(p):p.nodeName;if(typeof ge=="string"){const ye=W(ge);if(!D[ye]||Ae[ye])throw Xe("root node is forbidden and cannot be sanitized in-place")}if(Ft(p))throw Xe("root node is clobbered and cannot be sanitized in-place");try{Xt(p)}catch(ye){throw gn(p),ye}}else if(Et(p))o=bn("<!---->"),f=o.ownerDocument.importNode(p,!0),f.nodeType===we.element&&f.nodeName==="BODY"||f.nodeName==="HTML"?o=f:o.appendChild(f),Xt(f);else{if(!Ie&&!Te&&!Se&&p.indexOf("<")===-1)return M&&st?T(p):p;if(o=bn(p),!o)return Ie?null:st?Y:""}o&&rt&&je(o.firstChild);const J=Tn(I?p:o);try{for(;b=J.nextNode();)yn(b),Sn(b),ut(b.content)&&Ht(b.content)}catch(ge){throw I&&gn(p),ge}if(I)return At(n.removed,ge=>{ge.element&&or(ge.element)}),Te&&Vt(p),p;if(Ie){if(Te&&Vt(o),We)for(R=fe.call(o.ownerDocument);o.firstChild;)R.appendChild(o.firstChild);else R=o;return(B.shadowroot||B.shadowrootmode)&&(R=ve.call(a,R,!0)),R}let K=Se?o.outerHTML:o.innerHTML;return Se&&D["!doctype"]&&o.ownerDocument&&o.ownerDocument.doctype&&o.ownerDocument.doctype.name&&ne(Bs,o.ownerDocument.doctype.name)&&(K="<!DOCTYPE "+o.ownerDocument.doctype.name+`>
|
|
92
|
+
`+K),Te&&(K=Ut(K)),M&&st?T(K):K},n.setConfig=function(){let p=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};oe(p),nt=!0,Be=D,Me=B},n.clearConfig=function(){c=null,nt=!1,Be=null,Me=null,M=de,Y=""},n.isValidAttribute=function(p,t,o){c||oe({});const f=W(p),b=W(t);return En(f,b,o)},n.addHook=function(p,t){typeof t=="function"&&Q(P,p)&&dt(P[p],t)},n.removeHook=function(p,t){if(Q(P,p)){if(t!==void 0){const o=ws(P[p],t);return o===-1?void 0:xs(P[p],o,1)[0]}return Ln(P[p])}},n.removeHooks=function(p){Q(P,p)&&(P[p]=[])},n.removeAllHooks=function(){P=Wn()},n}var Gt=Qn();const Xs=["a","b","br","div","em","i","li","ol","p","s","span","strong","u","ul"];function Zs(e){e.hasAttribute("href")&&(e.setAttribute("target","_blank"),e.setAttribute("rel","noopener noreferrer"))}function Js(e){Gt.addHook("afterSanitizeAttributes",Zs);const n=Gt.sanitize(e,{ALLOWED_TAGS:[...Xs]});return Gt.removeHook("afterSanitizeAttributes"),n}function Qs(e){return Gt.sanitize(e,{ALLOWED_TAGS:[]})}class pn extends Error{constructor(n,r){super(`HTTP ${n}: ${r}`),this.name="HttpError",this.status=n,this.statusText=r}}async function er(e,n,r,a={}){const{authorizationToken:u,headers:i,...d}=a,h=await fetch(n,{method:e,headers:{"Content-Type":"application/json",...u&&{Authorization:`Bearer ${u}`},...i},body:r!==void 0?JSON.stringify(r):void 0,...d});if(!h.ok)throw new pn(h.status,h.statusText);return h.json()}const tr=(e,n,r,a)=>er("GET",e,void 0,{signal:r,authorizationToken:a}),mn=(e,n,r={})=>er("POST",e,n,r);function un(e){if(e==="")return"";try{const n=JSON.parse(e);return typeof n=="string"?n:String(n??"")}catch{return e}}function eo(e){return e.includes("/chat/agent-completions")}function nr(e){return/\/conversations(?:\/|$)/.test(e.replace(/\?.*$/,""))}const wt={model:"gpt-4o-mini",agentName:"Group_Ask_Arbor_Agent",systemPrompt:"You are a helpful AI assistant for Arbor Education group MIS users.",modelKwargs:{temperature:1,top_p:1},mcps:[{server:"statsapi",tools:["*"]},{server:"arbormis",tools:["create_pdf","academic_date_range_finder"]}]},dn="user",to="assistant",no="system";function ro({chatId:e,userMessage:n,chatHistory:r=[],config:a={}}){const u=a.model??wt.model,i=a.agentName??wt.agentName,d=a.systemPrompt??wt.systemPrompt,h=a.modelKwargs??wt.modelKwargs,_=a.mcps??[...wt.mcps],m=!e&&r.length===0,S={messages:m?[{role:no,content:d},{role:dn,content:n}]:[{role:dn,content:n}],model:u,model_kwargs:h,mcps:_,meta:{feature_id:i,source:"ask-arbor-standalone"},moderation_enabled:!0};return e&&(S.chat_id=e),m&&(S.auto_title=!1),S}function so(e){const n=e.trim();if(!n.startsWith("data:"))return null;const r=n.slice(5).trim();if(!r)return null;try{return JSON.parse(r)}catch{return null}}async function oo(e){var m,E,S;if((e.headers.get("content-type")??"").includes("application/json")){const A=(m=(await e.json()).items)==null?void 0:m[0];return A?{text:A.text??A.content??"",chatId:A.chatId,messageId:A.id}:null}const r=(E=e.body)==null?void 0:E.getReader();if(!r)return null;const a=new TextDecoder;let u="",i="",d,h=`agent-${Date.now()}`,_=!1;for(;;){const{done:g,value:A}=await r.read();if(g)break;u+=a.decode(A,{stream:!0});const x=u.split(`
|
|
93
|
+
`);u=x.pop()??"";for(const O of x){const N=O.trim();if(N==="event: error"){_=!0;continue}const w=so(N);if(!w)continue;if(w.error||_)throw new Error(w.message_text??(typeof w.message=="string"?w.message:"Agent completion stream failed"));_=!1,w.chat_id&&(d=w.chat_id),w.event_id&&(h=w.event_id),w.client_message_id&&(h=w.client_message_id);const j=(S=w.message)==null?void 0:S.content;j&&(i=w.is_final?j:i+j)}}return i?{text:i,chatId:d,messageId:h}:null}async function ao({chatUrl:e,chatId:n,userMessage:r,chatHistory:a,authorizationToken:u,config:i}){const d=ro({chatId:n,userMessage:r,chatHistory:a,config:i}),h=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...u&&{Authorization:`Bearer ${u}`},"X-Trace-Id":crypto.randomUUID()},body:JSON.stringify(d)});if(!h.ok)throw new pn(h.status,h.statusText);return oo(h)}function io(e){switch(e){case 401:return{text:Vr,type:Ee};case 403:return{text:Xr,type:Ee};case 404:return{text:Zr,type:Ee};case 408:case 504:return{text:Jr,type:kt};case 429:return{text:Qr,type:kt};default:return e>=500?{text:es,type:Ee}:{text:Vn,type:Ee}}}function co(e){return e instanceof pn?io(e.status):e instanceof TypeError?{text:ts,type:Ee}:{text:Vn,type:Ee}}const lo=55e3,fn="fallback",uo=async({chatId:e=void 0,chatUrl:n,userMessage:r,userInputDeviceLastUsed:a,chatHistory:u,canvasHistory:i,authorizationToken:d,agentCompletionsConfig:h})=>{let _;try{if(eo(n)){const N=await ao({chatUrl:n,chatId:e,userMessage:r,chatHistory:u,authorizationToken:d,config:h});return N?{text:N.text,id:N.messageId,...N.chatId!=null&&{chatId:N.chatId},type:Rt}:null}const g={chatId:e,userMessage:r,userInputDeviceLastUsed:a,chatHistory:u,canvasHistory:i},A=new AbortController,x=mn(n,g,{authorizationToken:d,signal:A.signal}),O=new Promise(N=>setTimeout(()=>{A.abort(),N({items:[{id:fn,hardStopped:!0,type:Bt}]})},lo));_=await Promise.race([x,O])}catch(g){console.error("Error in getNewAgentMessage",g);const{text:A,type:x}=co(g);return{text:A,type:x,id:crypto.randomUUID()}}const m=_.items[0];if(!m)return null;const E=m.text!=null&&m.text!==""?m.text:un(typeof m.content=="string"?m.content:"");return{text:typeof E=="string"?E:"",id:m.id,...m.chatId!=null&&{chatId:m.chatId},...m.timedOut!=null&&{timedOut:m.timedOut},...m.deferred!=null&&{deferred:m.deferred},...m.hardStopped!=null&&{hardStopped:m.hardStopped},type:m.type,...m.element!=null&&{element:m.element}}},fo=e=>new Date(e).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"}),po=[{field:"title",headerName:"Conversation",flex:1},{field:"updatedAt",headerName:"Last Conversation",width:140,valueFormatter:({value:e})=>fo(e)}],mo={sortable:!1,filter:!1,resizable:!1,editable:!1,suppressHeaderMenuButton:!0},an="NONE",ho="KEYBOARD",_o="VOICE",go="MIXED",bo=2e4,To=15,yo=(e,n)=>new Promise(r=>{if(n!=null&&n.aborted){r(!1);return}const a=setTimeout(()=>{n==null||n.removeEventListener("abort",u),r(!0)},e),u=()=>{clearTimeout(a),r(!1)};n==null||n.addEventListener("abort",u)}),Eo=({title:e,connector:n,newChatUrl:r,lockConversation:a=!1,messageLimit:u,chatId:i,speechEnabled:d=!0,speechLanguage:h="en-GB",speechSubmissionDelay:_=1e3,chatHistory:m,canvasHistory:E,refreshAgentMessages:S,startQuery:g,slashMenuItems:A,menuContent:x,samplePrompts:O,dailyPrompt:N,prompts:w,promptLibrary:j,placeholder:ue="Explain what you need in your own words...",introHeading:U="Get instant answers from your MIS",introBody:$="Type a question about your students, staff or school and get the answer in seconds. No reports to run, no clicking around - just ask!",onClose:M,onNavigate:Y,onRatingPopupOpen:de,focusDelay:V})=>{const F=(()=>{if(j&&j.length>0)return j;if(!w||w.trim()==="")return[];try{const c=JSON.parse(w);return Array.isArray(c)&&c.length>0?c:[]}catch{return[]}})(),ce=l.useRef(!1),T=c=>{ce.current=c},v=fs(),H=l.useRef(null),ee=l.useRef(null),L=l.useRef(null),z=l.useRef(null),fe=l.useRef(null),Ce=l.useRef(null),[ve,P]=l.useState(()=>i?"":g??""),[te,pt]=l.useState(i),[X,mt]=l.useState([]),[$t,Ct]=l.useState([]),Je=c=>{(!ce.current||c.id==="DEEP_THINKING_MESSAGE")&&mt(y=>[...y,c])},[He,Le]=l.useState(!1),[D,Qe]=l.useState(!1),[B,et]=l.useState(!1),G=l.useRef(!1),Ae=l.useRef(null),ht=l.useRef(!1),[be,It]=l.useState(!1),[ze,tt]=l.useState(an),[De,Te]=l.useState(!1),[Ge,Se]=l.useState(!0),[nt,Be]=l.useState(!1),[Me,rt]=l.useState("getting-started"),[Ie,We]=l.useState([]),[st,_t]=l.useState(!1),$e=ms(u,0),ot=$e>0&&X.length>=$e,gt=He||D;ds(()=>{if(!!(g!=null&&g.trim())&&!i||V==null&&!g)return;const y=setTimeout(()=>{var k;(k=H.current)==null||k.focus()},V??0);return()=>clearTimeout(y)});const[at,Pe]=l.useState(!1),me=!window.webkitSpeechRecognition&&!window.SpeechRecognition,Ye=typeof navigator<"u"&&navigator.userAgent.toLowerCase().includes("firefox"),Ot=async()=>{let c=!1;if(navigator.permissions)try{c=(await navigator.permissions.query({name:"microphone"})).state==="denied"}catch(y){console.warn("Could not check microphone permission:",y)}return!d||me||Ye||c};l.useEffect(()=>{(async()=>{const y=await Ot();Pe(y)})()},[d,De]),l.useEffect(()=>{m&&m.length>0&&mt(m)},[m]);const Ke=async(c=te)=>{if(!n.canLoadHistory||!c)return;Qe(!0);const y=await n.loadHistory(c);if(v.current){if(JSON.stringify(y)===JSON.stringify(X)||!y){Qe(!1);return}return y.chatItems.length>0&&mt(y.chatItems),Ct(y.followUpPrompts),Qe(!1),It(!0),y}};l.useEffect(()=>{S&&!ce.current&&Ke()},[S]),l.useEffect(()=>{v.current&&n.canLoadHistory&&i&&(be||Ke(i))},[i,n.canLoadHistory,be]),l.useLayoutEffect(()=>{L.current&&L.current.scrollTo({top:L.current.scrollHeight,behavior:"smooth"})},[X]);const bt=c=>{const y=_s(c),k=/\['Canvas_Element_ID'\s*:\s*'([^']+)',\s*'Title'\s*:\s*'([^']+)'\]/g;return y.replace(k,(oe,_e,le)=>`<span class="chat-panel__message-tag">@${le}</span>`)},vt=async({maxAttempts:c=6,chatIdToFetch:y,signal:k}={})=>{const oe=new Set(X.map(({id:Pt})=>Pt));let _e=0,le;for(;_e<c;){if(k!=null&&k.aborted||!await yo(bo,k)||(le=await Ke(y),k!=null&&k.aborted))return;if(((le==null?void 0:le.chatItems)||[]).some(jt=>jt.type!==Ze&&!oe.has(jt.id)))break;_e++}if(Number.isFinite(c)&&_e>=c){Je({text:ns,id:fn,type:Ee});return}return le},Ne=()=>{setTimeout(()=>{var c;(c=H.current)==null||c.focus()},0)},it=async c=>{Ct(null),Le(!0);const y=await n.sendMessage({chatId:te,userMessage:c,userInputDeviceLastUsed:ze,chatHistory:X,canvasHistory:E});if(!y){Le(!1),Ne();return}if(y.deferred===!0){y.chatId&&pt(y.chatId);const k=y.chatId||te;Ae.current=new AbortController;try{await vt({maxAttempts:To,chatIdToFetch:k,signal:Ae.current.signal})}finally{Ae.current=null}v.current&&(Le(!1),Ne());return}if(y.hardStopped===!0){!G.current&&n.canSendNotification&&te&&await n.sendNotification({chatId:te})&&(G.current=!0),v.current&&(et(!0),Le(!1),Ne());return}Je({text:Js(y.text),type:y.type,id:y.id,...y.element!=null&&{element:y.element}}),y.chatId&&pt(y.chatId),Le(!1),Ne()},Z=async({prompt:c=null,allowDoubleMessage:y=!1}={})=>{var _e;let k=null;if(c!=null&&c.trim()!==""&&(k=c.trim()),k===null&&(k=Qs(ve).trim()),!k||He||D)return;const oe=X.slice().reverse().find(le=>le.type===Ze);if(!y&&oe&&oe.text===k){console.warn("Duplicate message detected, not adding:",k);return}(_e=Ce.current)==null||_e.cancel(),he(),et(!1),G.current=!1,Je({type:Ze,text:k,id:ps()}),P(""),Ne(),T(!1),await it(k),tt(an)};l.useEffect(()=>{if(ht.current||!(g!=null&&g.trim())||i)return;ht.current=!0;const c=setTimeout(()=>{Z({prompt:g})},V??0);return()=>clearTimeout(c)},[]);const he=()=>{fe.current&&(fe.current.stop(),fe.current=null),Te(!1),z.current&&(clearTimeout(z.current),z.current=null)},ct=mr(c=>{he(),c.trim().length>0&&Ge&&Z()},_);Ce.current=ct;const lt=c=>{if(ze===an){tt(c);return}if(ze!==c){tt(go);return}},Yt=()=>{if(He||D)return;lt(_o),Se(!0);const c=new window.webkitSpeechRecognition;fe.current=c,c.continuous=!0,c.interimResults=!0,c.lang=h,c.start(),c.onstart=()=>{Te(!0)},c.onresult=y=>{const k=Array.from(y.results).map(oe=>oe[0]).map(oe=>oe.transcript).join("");k!==ve&&P(k),ct(k)},c.onerror=()=>{he()}},Lt=()=>{De?he():Yt()},Tt=!D&&!He&&ve.trim().length>0;l.useEffect(()=>()=>{var c;(c=Ae.current)==null||c.abort()},[]),l.useEffect(()=>{if(!n.canListInteractions)return;let c=!1;return _t(!0),n.listInteractions().then(y=>{c||We(y??[])}).catch(()=>{c||We([])}).finally(()=>{c||_t(!1)}),()=>{c=!0}},[n]);const Dt=()=>A!=null&&A.length?A.map(c=>{let y=c.url;return te&&y.includes("/chat-id/")&&(y.match(/\/chat-id\/[^/]+$/)||(y=`${y}${te}`)),{reference:c.label,description:c.label,link:y,icon:c.icon}}):[],yt=c=>{c.key!=="Enter"&&(lt(ho),De&&Se(!1),c.key==="/"&&ve.length===0&&(A!=null&&A.length)&&(Be(!0),c.preventDefault())),c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),Tt&&Z({allowDoubleMessage:!0})),c.key==="Escape"&&nt&&Be(!1)},Kt=()=>{Be(!1),setTimeout(()=>{var c;(c=H.current)==null||c.focus()},0)},qe=l.useCallback(c=>{P(c),setTimeout(()=>{H.current&&(H.current.focus(),H.current.selectionStart=H.current.value.length,H.current.selectionEnd=H.current.value.length)},0)},[]),qt=l.useCallback(async()=>!n.canSendNotification||!te?!1:n.sendNotification({chatId:te}),[te,n]),Mt=l.useCallback(()=>{et(!1),M==null||M()},[M]),W=l.useCallback((c,y)=>{te&&n.rateMessage({rating:c,messageId:y,chatId:te})},[te,n]);return s.jsxs("section",{"aria-label":e?`Chat Panel: ${e}`:"Chat Panel",className:"chat-panel",children:[r&&X.length>0&&s.jsx("section",{className:"chat-panel__active-chat-header",children:s.jsx("a",{href:r,className:"chat-panel__new-chat-button",onClick:c=>{Y&&(c.preventDefault(),Y(r))},children:"New"})}),(X.length>0||!a&&!ot)&&s.jsxs("div",{className:pe("chat-panel__body",{"chat-panel__body--no-messages":X.length===0}),children:[X.length>0&&s.jsxs("div",{className:"chat-panel__message-list-wrapper",children:[s.jsxs("ul",{className:"chat-panel-message-list",ref:L,children:[X.map((c,y)=>{const k=y===X.length-1,oe=k?$t:void 0,_e=c.id===fn,le=k;return s.jsx(qr,{id:c.id,type:c.type,text:c.text,chatId:te,onRate:n.canRate?W:void 0,ratingPopupUrls:n.ratingPopupUrls,showRating:le,followUpPrompts:oe,onFollowUpPromptClick:qe,processCanvasReferences:bt,isFallbackMessage:_e,onRatingPopupOpen:de},`${c.id}_${y}`)}),gt&&s.jsx(us,{showNotifyLaterButton:n.canSendNotification&&!!te,onNotifyLater:qt,onNotificationRegisteredGotIt:Mt}),B&&s.jsx("li",{className:"chat-panel__hard-stop-banner","data-testid":"hard-stop-banner",children:s.jsxs("div",{className:"chat-panel__notify-later",children:[s.jsx("p",{className:"chat-panel__notify-later-message",children:"This one's taking longer than usual. We'll notify you in the notifications panel on the left of your MIS when it's done."}),s.jsx("button",{type:"button",className:"chat-panel__notify-later-btn",onClick:Mt,"aria-label":"Got it",children:"Got it"})]})})]}),$e>0&&X.length>0&&s.jsxs("div",{className:"chat-panel__message-limit",children:[X.length," ","/",$e]})]}),!a&&!ot&&s.jsxs(s.Fragment,{children:[X.length===0&&!D&&s.jsxs("div",{className:"chat-panel__chat-intro",children:[s.jsxs("div",{className:"chat-panel__chat-intro-frame",children:[s.jsx("span",{className:"chat-panel__chat-intro-icon",children:s.jsx(hr,{})}),s.jsx("h3",{className:"chat-panel__chat-intro-heading",children:U})]}),s.jsx("p",{className:"chat-panel__chat-intro-body",children:$})]}),s.jsx("div",{className:"chat-panel__input-container",children:s.jsxs("div",{className:"chat-panel__input-wrapper",ref:ee,children:[nt&&s.jsx(Xn,{anchorRef:ee,menuItems:Dt(),onClose:Kt,onNavigate:Y}),s.jsx(qn,{ref:H,value:ve,onChange:P,onKeyDown:yt,placeholder:ue,onSubmit:()=>{ve.trim()&&Z({allowDoubleMessage:!0})},onMicClick:Lt,onStopClick:()=>{De&&he()},isProcessing:He,speechEngaged:De,showMicButton:!at&&d&&!Ye,ariaLabel:"Chat panel input",menuContent:x,onNavigate:Y,showDisclaimer:X.length>0})]})})]})]}),X.length===0&&s.jsxs(s.Fragment,{children:[at&&s.jsx("div",{className:"chat-panel__speech-disabled-wrapper",children:Ye?s.jsxs(s.Fragment,{children:[" ","Speech isn't supported in Firefox. To enable speech, please use Google Chrome."]}):s.jsx(s.Fragment,{children:" To use speech, please allow Arbor to use your microphone."})}),s.jsxs(Re.Tabs,{className:"chat-panel__tabs",children:[s.jsx(Re.Tabs.Item,{active:Me==="getting-started",tabElementProps:{onClick:()=>rt("getting-started")},children:"Getting started"}),s.jsx(Re.Tabs.Item,{active:Me==="recent",tabElementProps:{onClick:()=>rt("recent")},children:"Recent"})]}),s.jsxs("div",{className:"chat-panel__tab-content",children:[Me==="getting-started"&&s.jsxs(s.Fragment,{children:[F.length>0&&s.jsx("div",{className:"chat-panel__sample-prompt-container",children:s.jsx(br,{onSelectPrompt:c=>{Z({prompt:c,allowDoubleMessage:!0})},onPromptHover:c=>{c!=null&&P(c)},categories:F})}),(O&&O.length>0&&F.length===0||!!(N!=null&&N.trim()))&&s.jsxs("div",{className:"chat-panel__sample-prompt-container",children:[O==null?void 0:O.map((c,y)=>s.jsx("button",{type:"button",className:"chat-panel__sample-prompt",onClick:()=>Z({prompt:c,allowDoubleMessage:!0}),children:c},`sample-${y}`)),N&&s.jsx("button",{type:"button",className:"chat-panel__daily-prompt",onClick:()=>Z({prompt:N,allowDoubleMessage:!0}),children:s.jsxs("span",{children:["✨"," ",s.jsx("strong",{children:"Daily Prompt:"}),s.jsx("br",{}),N]})},"daily-prompt")]})]}),Me==="recent"&&s.jsx("div",{className:"chat-panel__tab-panel--recent",children:st?s.jsx("div",{className:"chat-panel__ai-interactions-loading",children:"Loading..."}):Ie.length===0?s.jsx("div",{className:"chat-panel__ai-interactions-empty",children:"No previous chats found."}):s.jsx(Re.Table,{wrapperClassName:"chat-panel__ai-interactions-table",hasSearch:!1,tableTheme:"tidy",domLayout:"autoHeight",rowData:Ie,columnDefs:po,defaultColDef:mo,getRowId:({data:c})=>c.id,onRowClicked:({data:c})=>{!c||!n.canLoadHistory||(pt(c.chatId),Ke(c.chatId))}})})]})]}),ot&&s.jsx("div",{className:"chat-panel-footer",children:"You've reached the maximum number of messages for this conversation"})]})};function Ao(e){switch(e.toLowerCase()){case dn:return Ze;case to:return Rt;default:return null}}function So(e){const n=[];for(const r of e.messages??[]){const a=Ao(r.role);!a||!r.content||n.push({id:r.message_id,type:a,text:r.content})}return{chatItems:n,followUpPrompts:[]}}const No=async(e,n)=>{try{const r=await tr(e,void 0,void 0,n);if(nr(e)&&Array.isArray(r==null?void 0:r.messages))return So(r);if(!(r!=null&&r.items))return console.error("Invalid response in getHistoricMessages",e,r),{chatItems:[],followUpPrompts:[]};let a=[],u=[];return r.items.forEach(i=>{if("chatItems"in i)a=i.chatItems.map(({id:d,type:h,text:_,content:m,...E})=>{const S=_!=null&&_!==""?_:un(typeof m=="string"?m:"");return{id:d,type:h.toUpperCase(),text:S,...E.element!=null&&{element:E.element}}});else if("id"in i&&"type"in i){const d=i.text!=null&&i.text!==""?i.text:un(typeof i.content=="string"?i.content:"");a.push({id:i.id,type:i.type.toUpperCase(),text:d,...i.element!=null&&{element:i.element}})}"followUpPrompts"in i&&(u=i.followUpPrompts||[])}),{chatItems:a,followUpPrompts:u}}catch(r){return console.error("Error in getHistoricMessages",r,e),{chatItems:[],followUpPrompts:[]}}},wo=async({rating:e,messageId:n,chatId:r,ratingUrl:a,authorizationToken:u})=>{try{await mn(a,{messageId:n,rating:e,chatId:r},{authorizationToken:u})}catch(i){console.error("Error rating message",i)}},xo=async({chatId:e,notificationCallbackUrl:n,authorizationToken:r})=>{try{return await mn(n,{chatId:e},{authorizationToken:r}),!0}catch(a){return console.error("Error sending notification",a),!1}};function Ro(e){return(e.conversations??[]).map(n=>{var r,a;return{id:n.session_id,chatId:n.session_id,title:((r=n.title)==null?void 0:r.trim())||((a=n.preview)==null?void 0:a.trim())||"Untitled conversation",updatedAt:n.updated_at??n.created_at??""}})}class rr{constructor(n){this.config=n}get canRate(){return!!this.config.ratingUrl}get canLoadHistory(){return!!this.config.historicChatUrl}get canListInteractions(){return!!this.config.aiInteractionsUrl}get canSendNotification(){return!!this.config.notificationCallbackUrl}get ratingPopupUrls(){return{up:this.config.upRatingPopupUrl,down:this.config.downRatingPopupUrl}}async sendMessage(n){return uo({chatUrl:this.config.chatUrl,authorizationToken:this.config.authorizationToken,agentCompletionsConfig:this.config.agentCompletionsConfig,...n})}async loadHistory(n){return this.config.historicChatUrl?No(`${this.config.historicChatUrl}/${n}`,this.config.authorizationToken):null}async listInteractions(){if(!this.config.aiInteractionsUrl)return null;try{const n=await tr(this.config.aiInteractionsUrl,void 0,void 0,this.config.authorizationToken);return nr(this.config.aiInteractionsUrl)&&Array.isArray(n.conversations)?Ro(n):Array.isArray(n)?n:Array.isArray(n.items)?n.items:[]}catch{return null}}async rateMessage(n){this.config.ratingUrl&&await wo({ratingUrl:this.config.ratingUrl,authorizationToken:this.config.authorizationToken,...n})}async sendNotification(n){return this.config.notificationCallbackUrl?xo({notificationCallbackUrl:this.config.notificationCallbackUrl,authorizationToken:this.config.authorizationToken,...n}):!1}}const ko={create(e){const n=e.model||e.agentName||e.systemPrompt||e.mcps?{...e.model&&{model:e.model},...e.agentName&&{agentName:e.agentName},...e.systemPrompt&&{systemPrompt:e.systemPrompt},...e.mcps&&{mcps:e.mcps}}:void 0;return new rr({chatUrl:e.chatUrl,authorizationToken:e.authorizationToken??void 0,historicChatUrl:e.historicChatUrl??void 0,aiInteractionsUrl:e.aiInteractionsUrl??void 0,ratingUrl:e.ratingUrl??void 0,upRatingPopupUrl:e.upRatingPopupUrl??void 0,downRatingPopupUrl:e.downRatingPopupUrl??void 0,notificationCallbackUrl:e.notificationCallbackUrl??void 0,agentCompletionsConfig:n})}};exports.AIServiceConnectorFactory=ko;exports.CHAT_RESPONSE_TYPE_AGENT=Rt;exports.CHAT_RESPONSE_TYPE_ERROR=Ee;exports.CHAT_RESPONSE_TYPE_INFO=Bt;exports.CHAT_RESPONSE_TYPE_USER=Ze;exports.CHAT_RESPONSE_TYPE_WARNING=kt;exports.ChatPanel=Eo;exports.HttpAIServiceConnector=rr;
|