@aiden-voice/widget 0.4.0 → 0.5.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 +18 -6
- package/dist/api/client.d.ts +5 -2
- package/dist/components/App.d.ts +1 -1
- package/dist/components/Composer.d.ts +1 -1
- package/dist/components/ErrorBanner.d.ts +1 -1
- package/dist/components/Launcher.d.ts +1 -1
- package/dist/components/MessageFeedback.d.ts +1 -1
- package/dist/components/MessageList.d.ts +1 -1
- package/dist/components/Panel.d.ts +1 -1
- package/dist/components/icons.d.ts +5 -5
- package/dist/config.d.ts +1 -0
- package/dist/controller.d.ts +1 -0
- package/dist/theme.d.ts +1 -1
- package/dist/types.d.ts +7 -5
- package/dist/version.d.ts +1 -1
- package/dist/widget.iife.js +4 -4
- package/dist/widget.js +498 -466
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,6 +63,17 @@ init({
|
|
|
63
63
|
short-lived JWT to the page some other way. The widget itself never
|
|
64
64
|
holds, requests, or sees a secret key under any circumstance.
|
|
65
65
|
|
|
66
|
+
Branding (`color`, `inkColor`, `accentColor`, `name`) follows one rule in
|
|
67
|
+
both modes: **a value you pass to `init()` always wins**, anything you leave
|
|
68
|
+
out is filled in from the agent's settings in whoo-aiden, and anything still
|
|
69
|
+
missing uses the built-in default. An unusable color counts as not passed.
|
|
70
|
+
In `publishableKey` mode the widget gets those settings with the session; in
|
|
71
|
+
`sessionToken` mode it reads them with the token (`GET /widget/branding`),
|
|
72
|
+
so you don't have to copy them out of your backend's `identify-session`
|
|
73
|
+
response yourself. If you pass all four values, `sessionToken` mode makes no
|
|
74
|
+
branding request, and if the lookup fails the widget just keeps your values
|
|
75
|
+
and the defaults.
|
|
76
|
+
|
|
66
77
|
Image options accept only `https:` and `data:image/` URLs. Any other
|
|
67
78
|
value (`http:`, relative paths, `javascript:`, `data:text/html`, …) is
|
|
68
79
|
ignored with a `console.warn`, and the widget keeps its default look. Use
|
|
@@ -78,10 +89,10 @@ throws synchronously, at call time, if you pass both or neither.
|
|
|
78
89
|
| `publishableKey` | Public key used to mint a session server-side. Mutually exclusive with `sessionToken`. | none (required unless `sessionToken` is set) |
|
|
79
90
|
| `sessionToken` | A pre-minted session JWT from your own backend. Mutually exclusive with `publishableKey`. | none (required unless `publishableKey` is set) |
|
|
80
91
|
| `position` | Launcher/panel corner: `'bottom-right'` or `'bottom-left'`. | `'bottom-right'` |
|
|
81
|
-
| `color` | Primary accent color (any valid CSS color). | `'#4f46e5'` |
|
|
82
|
-
| `inkColor` | Body text color (chat title and replies). Darkened automatically if needed to stay readable.
|
|
83
|
-
| `accentColor` | Link color in replies. Darkened automatically if needed to stay readable.
|
|
84
|
-
| `name` | Agent name for the panel header and the dialog's screen-reader label ("Chat with {name}").
|
|
92
|
+
| `color` | Primary accent color (any valid CSS color). Overrides the color configured in whoo-aiden; omit it to use that one. | whoo-aiden's, else `'#4f46e5'` |
|
|
93
|
+
| `inkColor` | Body text color (chat title and replies). Darkened automatically if needed to stay readable. Overrides the color configured in whoo-aiden; omit it to use that one. | whoo-aiden's, else `'#111111'` |
|
|
94
|
+
| `accentColor` | Link color in replies. Darkened automatically if needed to stay readable. Overrides the color configured in whoo-aiden; omit it to use that one. | whoo-aiden's, else `'#0000ee'` |
|
|
95
|
+
| `name` | Agent name for the panel header and the dialog's screen-reader label ("Chat with {name}"). Overrides the name configured in whoo-aiden; omit it to use that one. | whoo-aiden's, else `'Aiden'` |
|
|
85
96
|
| `greeting` | Welcome text shown in the panel before the first message. | none |
|
|
86
97
|
| `launcherIconUrl` | Image shown on the launcher bubble instead of the default chat icon. `https:` or `data:image/` only. Until it loads, and permanently if it fails, the default icon shows. | none (default icon) |
|
|
87
98
|
| `emptyStateImageUrl` | Image (e.g. a brand lockup) shown above the greeting while the conversation is empty. `https:` or `data:image/` only. Removed if it fails to load. | none |
|
|
@@ -296,8 +307,9 @@ responsibility:
|
|
|
296
307
|
readable there regardless of how light or dark your color is.
|
|
297
308
|
Context-dependent values (`currentColor`, `inherit`, `var(...)`) aren't
|
|
298
309
|
accepted; they, like a malformed color, fall back with a console
|
|
299
|
-
warning (an unusable
|
|
300
|
-
|
|
310
|
+
warning (an unusable `color` falls back to the color configured in
|
|
311
|
+
whoo-aiden if there is one, otherwise the default theme; a whoo-aiden
|
|
312
|
+
color is only considered when yours isn't usable). Where your
|
|
301
313
|
color is used as text on the panel's white background (the header
|
|
302
314
|
controls), it's used as-is if it already reaches 4.5:1 against white;
|
|
303
315
|
otherwise the widget automatically uses a darker shade of the same hue,
|
package/dist/api/client.d.ts
CHANGED
|
@@ -2,14 +2,17 @@ export declare class WidgetApiError extends Error {
|
|
|
2
2
|
readonly status?: number;
|
|
3
3
|
constructor(message: string, status?: number);
|
|
4
4
|
}
|
|
5
|
-
export interface
|
|
6
|
-
token: string;
|
|
5
|
+
export interface Branding {
|
|
7
6
|
primaryColor: string | null;
|
|
8
7
|
name: string | null;
|
|
9
8
|
accentColor: string | null;
|
|
10
9
|
inkColor: string | null;
|
|
11
10
|
}
|
|
11
|
+
export interface MintedSession extends Branding {
|
|
12
|
+
token: string;
|
|
13
|
+
}
|
|
12
14
|
export declare function mintSession(apiBaseUrl: string, publishableKey: string): Promise<MintedSession>;
|
|
15
|
+
export declare function fetchBranding(apiBaseUrl: string, sessionToken: string): Promise<Branding>;
|
|
13
16
|
export declare function submitFeedback(apiBaseUrl: string, sessionToken: string, body: {
|
|
14
17
|
messageId: string;
|
|
15
18
|
rating: 'up' | 'down';
|
package/dist/components/App.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export declare function MessageFeedback({ state, containerRef, onThumbsUp, onThu
|
|
|
7
7
|
onThumbsDown: () => void;
|
|
8
8
|
onSubmitDetailed: (correction: string, category: '' | FeedbackCategory) => void;
|
|
9
9
|
onCancel: () => void;
|
|
10
|
-
}): import(
|
|
10
|
+
}): import('preact').JSX.Element;
|
|
@@ -14,4 +14,4 @@ export declare function MessageList({ messages, messageFeedback, lastCompletedMe
|
|
|
14
14
|
onThumbsDown: (messageId: string) => void;
|
|
15
15
|
onSubmitDetailed: (messageId: string, correction: string, category: '' | FeedbackCategory) => void;
|
|
16
16
|
onCancelFeedback: (messageId: string) => void;
|
|
17
|
-
}): import(
|
|
17
|
+
}): import('preact').JSX.Element;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export declare function ChatIcon({ size }: {
|
|
2
2
|
size?: number;
|
|
3
|
-
}): import(
|
|
3
|
+
}): import('preact').JSX.Element;
|
|
4
4
|
export declare function ChevronDownIcon({ size }: {
|
|
5
5
|
size?: number;
|
|
6
|
-
}): import(
|
|
6
|
+
}): import('preact').JSX.Element;
|
|
7
7
|
export declare function CloseIcon({ size }: {
|
|
8
8
|
size?: number;
|
|
9
|
-
}): import(
|
|
9
|
+
}): import('preact').JSX.Element;
|
|
10
10
|
export declare function ThumbUpIcon({ size }: {
|
|
11
11
|
size?: number;
|
|
12
|
-
}): import(
|
|
12
|
+
}): import('preact').JSX.Element;
|
|
13
13
|
export declare function ThumbDownIcon({ size }: {
|
|
14
14
|
size?: number;
|
|
15
|
-
}): import(
|
|
15
|
+
}): import('preact').JSX.Element;
|
package/dist/config.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ import { WidgetConfig } from './types';
|
|
|
2
2
|
export declare const DEFAULT_API_BASE_URL = "https://api.aidenvoice.com";
|
|
3
3
|
export declare const DEFAULT_Z_INDEX = 2147483000;
|
|
4
4
|
export declare function resolveZIndex(zIndex: unknown): number;
|
|
5
|
+
export declare function trimmedName(name: unknown): string;
|
|
5
6
|
export declare function validateConfig(config: WidgetConfig): void;
|
package/dist/controller.d.ts
CHANGED
package/dist/theme.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export interface ResolvedTheme {
|
|
|
31
31
|
link: boolean;
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
export declare function usableHex(color:
|
|
34
|
+
export declare function usableHex(color: unknown): string | null;
|
|
35
35
|
export declare function resolveTheme({ color, inkColor, accentColor }: ThemeInput): ResolvedTheme;
|
|
36
36
|
export declare function applyThemeColor(root: HTMLElement, color: string, fallback?: string): void;
|
|
37
37
|
export declare function applyPalette(root: HTMLElement, { inkColor, accentColor }: {
|
package/dist/types.d.ts
CHANGED
|
@@ -2,17 +2,19 @@ export interface WidgetConfig {
|
|
|
2
2
|
publishableKey?: string;
|
|
3
3
|
sessionToken?: string;
|
|
4
4
|
position?: 'bottom-right' | 'bottom-left';
|
|
5
|
+
/**
|
|
6
|
+
* Primary accent color. Overrides the color configured in whoo-aiden, in
|
|
7
|
+
* either auth mode; omit it (or pass an unusable one) to use that one.
|
|
8
|
+
*/
|
|
5
9
|
color?: string;
|
|
6
10
|
/**
|
|
7
11
|
* Body text color (header title and replies). Darkened if needed to stay
|
|
8
|
-
* readable.
|
|
9
|
-
* mint takes precedence.
|
|
12
|
+
* readable. Overrides the color configured in whoo-aiden, like `color`.
|
|
10
13
|
*/
|
|
11
14
|
inkColor?: string;
|
|
12
15
|
/**
|
|
13
|
-
* Link color in replies. Darkened if needed to stay readable.
|
|
14
|
-
*
|
|
15
|
-
* precedence.
|
|
16
|
+
* Link color in replies. Darkened if needed to stay readable. Overrides
|
|
17
|
+
* the color configured in whoo-aiden, like `color`.
|
|
16
18
|
*/
|
|
17
19
|
accentColor?: string;
|
|
18
20
|
name?: string;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const WIDGET_VERSION = "0.
|
|
1
|
+
export declare const WIDGET_VERSION = "0.5.0";
|
package/dist/widget.iife.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var whooAidenWidget=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=2147483e3,n=2147483647;function r(e){return e===void 0?t:Number.isInteger(e)&&Math.abs(e)<=n?e:(console.warn(`whoo-aiden-widget: ignoring zIndex ${String(e)} (expected an integer between -${n} and ${n}); using ${t}.`),t)}function i(e){if((typeof e.publishableKey==`string`&&e.publishableKey.length>0)==(typeof e.sessionToken==`string`&&e.sessionToken.length>0))throw Error("whoo-aiden-widget: init() requires exactly one of `publishableKey` or `sessionToken`, not both or neither.")}var a,o,s,c,l,u,d,f,p,m,h,g,_,v,y={},b=[],x=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,S=Array.isArray;function C(e,t){for(var n in t)e[n]=t[n];return e}function ee(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function w(e,t,n){var r,i,o,s={};for(o in t)o==`key`?r=t[o]:o==`ref`?i=t[o]:s[o]=t[o];if(arguments.length>2&&(s.children=arguments.length>3?a.call(arguments,2):n),typeof e==`function`&&e.defaultProps!=null)for(o in e.defaultProps)s[o]===void 0&&(s[o]=e.defaultProps[o]);return T(e,s,r,i,null)}function T(e,t,n,r,i){var a={type:e,props:t,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++s,__i:-1,__u:0};return i==null&&o.vnode!=null&&o.vnode(a),a}function E(e){return e.children}function D(e,t){this.props=e,this.context=t}function O(e,t){if(t==null)return e.__?O(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type==`function`?O(e):null}function k(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,r=[],i=[],a=C({},t);a.__v=t.__v+1,o.vnode&&o.vnode(a),oe(e.__P,a,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,r,n??O(t),!!(32&t.__u),i),a.__v=t.__v,a.__.__k[a.__i]=a,ce(r,a,i),t.__e=t.__=null,a.__e!=n&&A(a)}}function A(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),A(e)}function j(e){(!e.__d&&(e.__d=!0)&&c.push(e)&&!M.__r++||l!=o.debounceRendering)&&((l=o.debounceRendering)||u)(M)}function M(){try{for(var e,t=1;c.length;)c.length>t&&c.sort(d),e=c.shift(),t=c.length,k(e)}finally{c.length=M.__r=0}}function te(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,m,h,g,_=r&&r.__k||b,v=t.length;for(c=N(n,t,_,c,v),d=0;d<v;d++)(p=n.__k[d])!=null&&(f=p.__i!=-1&&_[p.__i]||y,p.__i=d,g=oe(e,p,f,i,a,o,s,c,l,u),m=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&de(f.ref,null,p),u.push(p.ref,p.__c||m,p)),h==null&&m!=null&&(h=m),4&p.__u?(c=ne(p,c,e),f.__e&&(f.__e=null)):typeof p.type==`function`&&g!==void 0?c=g:m&&(c=m.nextSibling),p.__u&=-7);return n.__e=h,c}function N(e,t,n,r,i){var a,o,s,c,l,u=n.length,d=u,f=0;for(e.__k=Array(i),a=0;a<i;a++)(o=t[a])!=null&&typeof o!=`boolean`&&typeof o!=`function`?(typeof o==`string`||typeof o==`number`||typeof o==`bigint`||o.constructor==String?o=e.__k[a]=T(null,o,null,null,null):S(o)?o=e.__k[a]=T(E,{children:o},null,null,null):o.constructor===void 0&&o.__b>0?o=e.__k[a]=T(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):e.__k[a]=o,c=a+f,o.__=e,o.__b=e.__b+1,s=null,(l=o.__i=re(o,n,c,d))!=-1&&(d--,(s=n[l])&&(s.__u|=2)),s==null||s.__v==null?(l==-1&&(i>u?f--:i<u&&f++),typeof o.type!=`function`&&(o.__u|=4)):l!=c&&(l==c-1?f--:l==c+1?f++:(l>c?f--:f++,o.__u|=4))):e.__k[a]=null;if(d)for(a=0;a<u;a++)(s=n[a])!=null&&!(2&s.__u)&&(s.__e==r&&(r=O(s)),fe(s,s));return r}function ne(e,t,n){var r,i;if(typeof e.type==`function`){for(r=e.__k,i=0;r&&i<r.length;i++)r[i]&&(r[i].__=e,t=ne(r[i],t,n));return t}e.__e!=t&&(t&&e.type&&!t.parentNode&&(t=O(e)),t=n.insertBefore(e.__e,t||null));do t&&=t.nextSibling;while(t!=null&&t.nodeType==8);return t}function re(e,t,n,r){var i,a,o,s=e.key,c=e.type,l=t[n],u=l!=null&&!(2&l.__u);if(l===null&&s==null||u&&s==l.key&&c==l.type)return n;if(r>+!!u){for(i=n-1,a=n+1;i>=0||a<t.length;)if((l=t[o=i>=0?i--:a++])!=null&&!(2&l.__u)&&s==l.key&&c==l.type)return o}return-1}function ie(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||x.test(t)?n:n+`px`}function P(e,t,n,r,i){var a,o;n:if(t==`style`){if(typeof n==`string`)e.style.cssText=n;else{if(typeof r==`string`&&(e.style.cssText=r=``),r)for(t in r)n&&t in n||ie(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||ie(e.style,t,n[t])}}else if(t[0]==`o`&&t[1]==`n`)a=t!=(t=t.replace(h,`$1`)),o=t.toLowerCase(),t=o in e||t==`onFocusOut`||t==`onFocusIn`?o.slice(2):t.slice(2),e.l||={},e.l[t+a]=n,n?r?n[m]=r[m]:(n[m]=g,e.addEventListener(t,a?v:_,a)):e.removeEventListener(t,a?v:_,a);else{if(i==`http://www.w3.org/2000/svg`)t=t.replace(/xlink(H|:h)/,`h`).replace(/sName$/,`s`);else if(t!=`width`&&t!=`height`&&t!=`href`&&t!=`list`&&t!=`form`&&t!=`tabIndex`&&t!=`download`&&t!=`rowSpan`&&t!=`colSpan`&&t!=`role`&&t!=`popover`&&t in e)try{e[t]=n??``;break n}catch{}typeof n==`function`||(n==null||!1===n&&t[4]!=`-`?e.removeAttribute(t):e.setAttribute(t,t==`popover`&&n==1?``:n))}}function ae(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t[p]==null)t[p]=g++;else if(t[p]<n[m])return;return n(o.event?o.event(t):t)}}}function oe(e,t,n,r,i,a,s,c,l,u){var d,f,p,m,h,g,_,v,y,x,w,T,k,A,j,M,N=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(l=!!(32&n.__u),a=[c=t.__e=n.__e]),(d=o.__b)&&d(t);n:if(typeof N==`function`){f=s.length;try{if(y=t.props,x=N.prototype&&N.prototype.render,w=(d=N.contextType)&&r[d.__c],T=d?w?w.props.value:d.__:r,n.__c?v=(p=t.__c=n.__c).__=p.__E:(x?t.__c=p=new N(y,T):(t.__c=p=new D(y,T),p.constructor=N,p.render=pe),w&&w.sub(p),p.state||(p.state={}),p.__n=r,m=p.__d=!0,p.__h=[],p._sb=[]),x&&p.__s==null&&(p.__s=p.state),x&&N.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=C({},p.__s)),C(p.__s,N.getDerivedStateFromProps(y,p.__s))),h=p.props,g=p.state,p.__v=t,m)x&&N.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),x&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(x&&N.getDerivedStateFromProps==null&&y!==h&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(y,T),t.__v==n.__v||!p.__e&&p.shouldComponentUpdate!=null&&!1===p.shouldComponentUpdate(y,p.__s,T)){t.__v!=n.__v&&(p.props=y,p.state=p.__s,p.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(e){e&&(e.__=t)}),b.push.apply(p.__h,p._sb),p._sb=[],p.__h.length&&s.push(p),c=O(n);break n}p.componentWillUpdate!=null&&p.componentWillUpdate(y,p.__s,T),x&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(h,g,_)})}if(p.context=T,p.props=y,p.__P=e,p.__e=!1,k=o.__r,A=0,x)p.state=p.__s,p.__d=!1,k&&k(t),d=p.render(p.props,p.state,p.context),b.push.apply(p.__h,p._sb),p._sb=[];else do p.__d=!1,k&&k(t),d=p.render(p.props,p.state,p.context),p.state=p.__s;while(p.__d&&++A<25);p.state=p.__s,p.getChildContext!=null&&(r=C(C({},r),p.getChildContext())),x&&!m&&p.getSnapshotBeforeUpdate!=null&&(_=p.getSnapshotBeforeUpdate(h,g)),j=d!=null&&d.type===E&&d.key==null?le(d.props.children):d,c=te(e,S(j)?j:[j],t,n,r,i,a,s,c,l,u),p.base=t.__e,t.__u&=-161,p.__h.length&&s.push(p),v&&(p.__E=p.__=null)}catch(e){if(s.length=f,t.__v=null,l||a!=null){if(e.then){for(t.__u|=l?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;a!=null&&(a[a.indexOf(c)]=null),t.__e=c}else if(a!=null)for(M=a.length;M--;)ee(a[M])}else t.__e=n.__e;t.__k??=n.__k||[],e.then||se(t),o.__e(e,t,n)}}else a==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=ue(n.__e,t,n,r,i,a,s,l,u);return(d=o.diffed)&&d(t),128&t.__u?void 0:c}function se(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(se))}function ce(e,t,n){for(var r=0;r<n.length;r++)de(n[r],n[++r],n[++r]);o.__c&&o.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){o.__e(e,t.__v)}})}function le(e){return typeof e!=`object`||!e||e.__b>0?e:S(e)?e.map(le):e.constructor===void 0?C({},e):null}function ue(e,t,n,r,i,s,c,l,u){var d,f,p,m,h,g,_,v=n.props||y,b=t.props,x=t.type;if(x==`svg`?i=`http://www.w3.org/2000/svg`:x==`math`?i=`http://www.w3.org/1998/Math/MathML`:i||=`http://www.w3.org/1999/xhtml`,s!=null){for(d=0;d<s.length;d++)if((h=s[d])&&`setAttribute`in h==!!x&&(x?h.localName==x:h.nodeType==3)){e=h,s[d]=null;break}}if(e==null){if(x==null)return document.createTextNode(b);e=document.createElementNS(i,x,b.is&&b),l&&=(o.__m&&o.__m(t,s),!1),s=null}if(x==null)v===b||l&&e.data==b||(e.data=b);else{if(s=x==`textarea`&&b.defaultValue!=null?null:s&&a.call(e.childNodes),!l&&s!=null)for(v={},d=0;d<e.attributes.length;d++)v[(h=e.attributes[d]).name]=h.value;for(d in v)h=v[d],d==`dangerouslySetInnerHTML`?p=h:d==`children`||d in b||d==`value`&&`defaultValue`in b||d==`checked`&&`defaultChecked`in b||P(e,d,null,h,i);for(d in b)h=b[d],d==`children`?m=h:d==`dangerouslySetInnerHTML`?f=h:d==`value`?g=h:d==`checked`?_=h:l&&typeof h!=`function`||v[d]===h||P(e,d,h,v[d],i);if(f)l||p&&(f.__html==p.__html||f.__html==e.innerHTML)||(e.innerHTML=f.__html),t.__k=[];else if(p&&(e.innerHTML=``),te(t.type==`template`?e.content:e,S(m)?m:[m],t,n,r,x==`foreignObject`?`http://www.w3.org/1999/xhtml`:i,s,c,s?s[0]:n.__k&&O(n,0),l,u),s!=null)for(d=s.length;d--;)ee(s[d]);l&&x!=`textarea`||(d=`value`,x==`progress`&&g==null?e.removeAttribute(`value`):g!=null&&(g!==e[d]||x==`progress`&&!g||x==`option`&&g!=v[d])&&P(e,d,g,v[d],i),d=`checked`,_!=null&&_!=e[d]&&P(e,d,_,v[d],i))}return e}function de(e,t,n){try{if(typeof e==`function`){var r=typeof e.__u==`function`;r&&e.__u(),r&&t==null||(e.__u=e(t))}else e.current=t}catch(e){o.__e(e,n)}}function fe(e,t,n){var r,i;if(o.unmount&&o.unmount(e),(r=e.ref)&&(r.current&&r.current!=e.__e||de(r,null,t)),(r=e.__c)!=null){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(e){o.__e(e,t)}r.base=r.__P=r.__n=null}if(r=e.__k)for(i=0;i<r.length;i++)r[i]&&fe(r[i],t,n||typeof e.type!=`function`);n||ee(e.__e),e.__c=e.__=e.__e=void 0}function pe(e,t,n){return this.constructor(e,n)}function me(e,t,n){var r,i,s,c;t==document&&(t=document.documentElement),o.__&&o.__(e,t),i=(r=typeof n==`function`)?null:n&&n.__k||t.__k,s=[],c=[],oe(t,e=(!r&&n||t).__k=w(E,null,[e]),i||y,y,t.namespaceURI,!r&&n?[n]:i?null:t.firstChild?a.call(t.childNodes):null,s,!r&&n?n:i?i.__e:t.firstChild,r,c),ce(s,e,c),e.props.children=null}a=b.slice,o={__e:function(e,t,n,r){for(var i,a,o;t=t.__;)if((i=t.__c)&&!i.__)try{if((a=i.constructor)&&a.getDerivedStateFromError!=null&&(i.setState(a.getDerivedStateFromError(e)),o=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,r||{}),o=i.__d),o)return i.__E=i}catch(t){e=t}throw e}},s=0,D.prototype.setState=function(e,t){var n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=C({},this.state);typeof e==`function`&&(e=e(C({},n),this.props)),e&&C(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),j(this))},D.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),j(this))},D.prototype.render=E,c=[],u=typeof Promise==`function`?Promise.prototype.then.bind(Promise.resolve()):setTimeout,d=function(e,t){return e.__v.__b-t.__v.__b},M.__r=0,f=Math.random().toString(8),p=`__d`+f,m=`__a`+f,h=/(PointerCapture)$|Capture$/i,g=0,_=ae(!1),v=ae(!0);var F,I,he,ge,L=0,_e=[],R=o,ve=R.__b,ye=R.__r,be=R.diffed,xe=R.__c,Se=R.unmount,Ce=R.__;function we(e,t){R.__h&&R.__h(I,e,L||t),L=0;var n=I.__H||(I.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function z(e){return L=1,Te(Me,e)}function Te(e,t,n){var r=we(F++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Me(void 0,t),function(e){var t=r.__N?r.__N[0]:r.__[0],n=r.t(t,e);t!==n&&(r.__N=[n,r.__[1]],r.__c.setState({}))}],r.__c=I,!I.__f)){var i=function(e,t,n){if(!r.__c.__H)return!0;var i=!1,o=r.__c.props!==e;if(r.__c.__H.__.some(function(e){if(e.__N){i=!0;var t=e.__[0];e.__=e.__N,e.__N=void 0,t!==e.__[0]&&(o=!0)}}),a){var s=a.call(this,e,t,n);return i?s||o:s}return!i||o};I.__f=!0;var a=I.shouldComponentUpdate,o=I.componentWillUpdate;I.componentWillUpdate=function(e,t,n){if(this.__e){var r=a;a=void 0,i(e,t,n),a=r}o&&o.call(this,e,t,n)},I.shouldComponentUpdate=i}return r.__N||r.__}function B(e,t){var n=we(F++,3);!R.__s&&je(n.__H,t)&&(n.__=e,n.u=t,I.__H.__h.push(n))}function V(e){return L=5,Ee(function(){return{current:e}},[])}function Ee(e,t){var n=we(F++,7);return je(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function De(){for(var e;e=_e.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(H),t.__h.some(Ae),t.__h=[]}catch(n){t.__h=[],R.__e(n,e.__v)}}}R.__b=function(e){I=null,ve&&ve(e)},R.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Ce&&Ce(e,t)},R.__r=function(e){ye&&ye(e),F=0;var t=(I=e.__c).__H;t&&(he===I?(t.__h=[],I.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(H),t.__h.some(Ae),t.__h=[],F=0)),he=I},R.diffed=function(e){be&&be(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(_e.push(t)!==1&&ge===R.requestAnimationFrame||((ge=R.requestAnimationFrame)||ke)(De)),t.__H.__.some(function(e){e.u&&=(e.__H=e.u,void 0)})),he=I=null},R.__c=function(e,t){t.some(function(e){try{e.__h.some(H),e.__h=e.__h.filter(function(e){return!e.__||Ae(e)})}catch(n){t.some(function(e){e.__h&&=[]}),t=[],R.__e(n,e.__v)}}),xe&&xe(e,t)},R.unmount=function(e){Se&&Se(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{H(e)}catch(e){t=e}}),n.__H=void 0,t&&R.__e(t,n.__v))};var Oe=typeof requestAnimationFrame==`function`;function ke(e){var t,n=function(){clearTimeout(r),Oe&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);Oe&&(t=requestAnimationFrame(n))}function H(e){var t=I,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),I=t}function Ae(e){var t=I;e.__c=e.__(),I=t}function je(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function Me(e,t){return typeof t==`function`?t(e):t}var Ne=0;Array.isArray;function U(e,t,n,r,i,a){t||={};var s,c,l=t;if(`ref`in l)for(c in l={},t)c==`ref`?s=t[c]:l[c]=t[c];var u={type:e,props:l,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Ne,__i:-1,__u:0,__source:i,__self:a};if(typeof e==`function`&&(s=e.defaultProps))for(c in s)l[c]===void 0&&(l[c]=s[c]);return o.vnode&&o.vnode(u),u}function W({name:e,size:t,children:n}){return U(`svg`,{"data-icon":e,"aria-hidden":`true`,focusable:`false`,width:t,height:t,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`,"stroke-linecap":`round`,"stroke-linejoin":`round`,children:n})}function Pe({size:e=26}){return U(W,{name:`chat`,size:e,children:[U(`path`,{d:`M4 5.5A2.5 2.5 0 0 1 6.5 3h11A2.5 2.5 0 0 1 20 5.5v8a2.5 2.5 0 0 1-2.5 2.5H10l-4.5 4v-4h0A1.5 1.5 0 0 1 4 14.5z`}),U(`path`,{d:`M8.5 9.5h.01M12 9.5h.01M15.5 9.5h.01`,"stroke-width":`2.5`})]})}function Fe({size:e=26}){return U(W,{name:`chevron-down`,size:e,children:U(`path`,{d:`M6 9l6 6 6-6`})})}function Ie({size:e=18}){return U(W,{name:`close`,size:e,children:U(`path`,{d:`M6 6l12 12M18 6L6 18`})})}var Le=`M7 11v9M7 11l3.5-7.2A1.8 1.8 0 0 1 14 4.6V9h4.6a2 2 0 0 1 2 2.3l-1.2 7A2 2 0 0 1 17.4 20H7M7 11H4.5A1.5 1.5 0 0 0 3 12.5v6A1.5 1.5 0 0 0 4.5 20H7`;function Re({size:e=16}){return U(W,{name:`thumb-up`,size:e,children:U(`path`,{d:Le})})}function ze({size:e=16}){return U(W,{name:`thumb-down`,size:e,children:U(`path`,{d:Le,transform:`matrix(1 0 0 -1 0 24)`})})}function Be({isOpen:e,onClick:t,iconUrl:n,buttonRef:r}){let[i,a]=z(`loading`),o=n!==void 0&&i!==`failed`,s=o&&!e&&i===`loaded`;return U(`button`,{type:`button`,class:`whoo-widget-launcher`,onClick:t,"aria-label":e?`Close chat`:`Open chat`,ref:r,children:[e?U(Fe,{}):s?null:U(Pe,{}),o?U(`img`,{class:`whoo-widget-launcher-icon-image`,src:n,alt:``,referrerpolicy:`no-referrer`,hidden:!s,onLoad:()=>a(`loaded`),onError:()=>a(`failed`)}):null]})}function Ve({value:e,onChange:t,onSend:n,disabled:r,inputRef:i}){return U(`div`,{class:`whoo-widget-composer`,children:[U(`label`,{class:`whoo-widget-sr-only`,for:`whoo-widget-composer-input`,children:`Message`}),U(`input`,{id:`whoo-widget-composer-input`,class:`whoo-widget-composer-input`,value:e,readOnly:r,"aria-disabled":r,ref:i,onInput:e=>t(e.target.value),onKeyDown:e=>{e.key===`Enter`&&n()}}),U(`button`,{type:`button`,class:`whoo-widget-composer-send`,onClick:n,disabled:r,children:`Send`})]})}function He({message:e}){return U(`div`,{class:`whoo-widget-error-banner`,role:`alert`,children:e})}var G=/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/y,K=/\*\*([^*\s](?:[^*]*[^*\s])?)\*\*/y,q=/(?<![A-Za-z0-9_])_([^_\s](?:[^_]*[^_\s])?)_(?![A-Za-z0-9_])/y,J=/\*([^*\s](?:[^*]*[^*\s])?)\*/y,Y=/[ \t]*[*+-][ \t]+/y,Ue=/https?:\/\/\S+/y,We=/[.,;:!?)\]}>]+$/;function Ge(e){let t=[],n=0,r=0,i=n=>{n>r&&t.push({type:`text`,value:e.slice(r,n),start:r,end:n})};for(;n<e.length;){if((n===0||e[n-1]===`
|
|
2
|
-
`)&&(
|
|
1
|
+
var whooAidenWidget=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=2147483e3,n=2147483647;function r(e){return e===void 0?t:Number.isInteger(e)&&Math.abs(e)<=n?e:(console.warn(`whoo-aiden-widget: ignoring zIndex ${String(e)} (expected an integer between -${n} and ${n}); using ${t}.`),t)}function i(e){return typeof e==`string`?e.trim():``}function a(e){if((typeof e.publishableKey==`string`&&e.publishableKey.length>0)==(typeof e.sessionToken==`string`&&e.sessionToken.length>0))throw Error("whoo-aiden-widget: init() requires exactly one of `publishableKey` or `sessionToken`, not both or neither.")}var o,s,c,l,u,d,f,p,m,h,g,_,v,y,b={},x=[],S=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,C=Array.isArray;function w(e,t){for(var n in t)e[n]=t[n];return e}function ee(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function T(e,t,n){var r,i,a,s={};for(a in t)a==`key`?r=t[a]:a==`ref`?i=t[a]:s[a]=t[a];if(arguments.length>2&&(s.children=arguments.length>3?o.call(arguments,2):n),typeof e==`function`&&e.defaultProps!=null)for(a in e.defaultProps)s[a]===void 0&&(s[a]=e.defaultProps[a]);return E(e,s,r,i,null)}function E(e,t,n,r,i){var a={type:e,props:t,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++c,__i:-1,__u:0};return i==null&&s.vnode!=null&&s.vnode(a),a}function D(e){return e.children}function O(e,t){this.props=e,this.context=t}function k(e,t){if(t==null)return e.__?k(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type==`function`?k(e):null}function te(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,r=[],i=[],a=w({},t);a.__v=t.__v+1,s.vnode&&s.vnode(a),ce(e.__P,a,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,r,n??k(t),!!(32&t.__u),i),a.__v=t.__v,a.__.__k[a.__i]=a,ue(r,a,i),t.__e=t.__=null,a.__e!=n&&A(a)}}function A(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),A(e)}function j(e){(!e.__d&&(e.__d=!0)&&l.push(e)&&!M.__r++||u!=s.debounceRendering)&&((u=s.debounceRendering)||d)(M)}function M(){try{for(var e,t=1;l.length;)l.length>t&&l.sort(f),e=l.shift(),t=l.length,te(e)}finally{l.length=M.__r=0}}function ne(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,m,h,g,_=r&&r.__k||x,v=t.length;for(c=re(n,t,_,c,v),d=0;d<v;d++)(p=n.__k[d])!=null&&(f=p.__i!=-1&&_[p.__i]||b,p.__i=d,g=ce(e,p,f,i,a,o,s,c,l,u),m=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&pe(f.ref,null,p),u.push(p.ref,p.__c||m,p)),h==null&&m!=null&&(h=m),4&p.__u?(c=ie(p,c,e),f.__e&&(f.__e=null)):typeof p.type==`function`&&g!==void 0?c=g:m&&(c=m.nextSibling),p.__u&=-7);return n.__e=h,c}function re(e,t,n,r,i){var a,o,s,c,l,u=n.length,d=u,f=0;for(e.__k=Array(i),a=0;a<i;a++)(o=t[a])!=null&&typeof o!=`boolean`&&typeof o!=`function`?(typeof o==`string`||typeof o==`number`||typeof o==`bigint`||o.constructor==String?o=e.__k[a]=E(null,o,null,null,null):C(o)?o=e.__k[a]=E(D,{children:o},null,null,null):o.constructor===void 0&&o.__b>0?o=e.__k[a]=E(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):e.__k[a]=o,c=a+f,o.__=e,o.__b=e.__b+1,s=null,(l=o.__i=ae(o,n,c,d))!=-1&&(d--,(s=n[l])&&(s.__u|=2)),s==null||s.__v==null?(l==-1&&(i>u?f--:i<u&&f++),typeof o.type!=`function`&&(o.__u|=4)):l!=c&&(l==c-1?f--:l==c+1?f++:(l>c?f--:f++,o.__u|=4))):e.__k[a]=null;if(d)for(a=0;a<u;a++)(s=n[a])!=null&&!(2&s.__u)&&(s.__e==r&&(r=k(s)),me(s,s));return r}function ie(e,t,n){var r,i;if(typeof e.type==`function`){for(r=e.__k,i=0;r&&i<r.length;i++)r[i]&&(r[i].__=e,t=ie(r[i],t,n));return t}e.__e!=t&&(t&&e.type&&!t.parentNode&&(t=k(e)),t=n.insertBefore(e.__e,t||null));do t&&=t.nextSibling;while(t!=null&&t.nodeType==8);return t}function ae(e,t,n,r){var i,a,o,s=e.key,c=e.type,l=t[n],u=l!=null&&!(2&l.__u);if(l===null&&s==null||u&&s==l.key&&c==l.type)return n;if(r>+!!u){for(i=n-1,a=n+1;i>=0||a<t.length;)if((l=t[o=i>=0?i--:a++])!=null&&!(2&l.__u)&&s==l.key&&c==l.type)return o}return-1}function oe(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||S.test(t)?n:n+`px`}function N(e,t,n,r,i){var a,o;n:if(t==`style`){if(typeof n==`string`)e.style.cssText=n;else{if(typeof r==`string`&&(e.style.cssText=r=``),r)for(t in r)n&&t in n||oe(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||oe(e.style,t,n[t])}}else if(t[0]==`o`&&t[1]==`n`)a=t!=(t=t.replace(g,`$1`)),o=t.toLowerCase(),t=o in e||t==`onFocusOut`||t==`onFocusIn`?o.slice(2):t.slice(2),e.l||={},e.l[t+a]=n,n?r?n[h]=r[h]:(n[h]=_,e.addEventListener(t,a?y:v,a)):e.removeEventListener(t,a?y:v,a);else{if(i==`http://www.w3.org/2000/svg`)t=t.replace(/xlink(H|:h)/,`h`).replace(/sName$/,`s`);else if(t!=`width`&&t!=`height`&&t!=`href`&&t!=`list`&&t!=`form`&&t!=`tabIndex`&&t!=`download`&&t!=`rowSpan`&&t!=`colSpan`&&t!=`role`&&t!=`popover`&&t in e)try{e[t]=n??``;break n}catch{}typeof n==`function`||(n==null||!1===n&&t[4]!=`-`?e.removeAttribute(t):e.setAttribute(t,t==`popover`&&n==1?``:n))}}function se(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t[m]==null)t[m]=_++;else if(t[m]<n[h])return;return n(s.event?s.event(t):t)}}}function ce(e,t,n,r,i,a,o,c,l,u){var d,f,p,m,h,g,_,v,y,b,S,T,E,te,A,j,M=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(l=!!(32&n.__u),a=[c=t.__e=n.__e]),(d=s.__b)&&d(t);n:if(typeof M==`function`){f=o.length;try{if(y=t.props,b=M.prototype&&M.prototype.render,S=(d=M.contextType)&&r[d.__c],T=d?S?S.props.value:d.__:r,n.__c?v=(p=t.__c=n.__c).__=p.__E:(b?t.__c=p=new M(y,T):(t.__c=p=new O(y,T),p.constructor=M,p.render=he),S&&S.sub(p),p.state||(p.state={}),p.__n=r,m=p.__d=!0,p.__h=[],p._sb=[]),b&&p.__s==null&&(p.__s=p.state),b&&M.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=w({},p.__s)),w(p.__s,M.getDerivedStateFromProps(y,p.__s))),h=p.props,g=p.state,p.__v=t,m)b&&M.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),b&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(b&&M.getDerivedStateFromProps==null&&y!==h&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(y,T),t.__v==n.__v||!p.__e&&p.shouldComponentUpdate!=null&&!1===p.shouldComponentUpdate(y,p.__s,T)){t.__v!=n.__v&&(p.props=y,p.state=p.__s,p.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(e){e&&(e.__=t)}),x.push.apply(p.__h,p._sb),p._sb=[],p.__h.length&&o.push(p),c=k(n);break n}p.componentWillUpdate!=null&&p.componentWillUpdate(y,p.__s,T),b&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(h,g,_)})}if(p.context=T,p.props=y,p.__P=e,p.__e=!1,E=s.__r,te=0,b)p.state=p.__s,p.__d=!1,E&&E(t),d=p.render(p.props,p.state,p.context),x.push.apply(p.__h,p._sb),p._sb=[];else do p.__d=!1,E&&E(t),d=p.render(p.props,p.state,p.context),p.state=p.__s;while(p.__d&&++te<25);p.state=p.__s,p.getChildContext!=null&&(r=w(w({},r),p.getChildContext())),b&&!m&&p.getSnapshotBeforeUpdate!=null&&(_=p.getSnapshotBeforeUpdate(h,g)),A=d!=null&&d.type===D&&d.key==null?de(d.props.children):d,c=ne(e,C(A)?A:[A],t,n,r,i,a,o,c,l,u),p.base=t.__e,t.__u&=-161,p.__h.length&&o.push(p),v&&(p.__E=p.__=null)}catch(e){if(o.length=f,t.__v=null,l||a!=null){if(e.then){for(t.__u|=l?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;a!=null&&(a[a.indexOf(c)]=null),t.__e=c}else if(a!=null)for(j=a.length;j--;)ee(a[j])}else t.__e=n.__e;t.__k??=n.__k||[],e.then||le(t),s.__e(e,t,n)}}else a==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=fe(n.__e,t,n,r,i,a,o,l,u);return(d=s.diffed)&&d(t),128&t.__u?void 0:c}function le(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(le))}function ue(e,t,n){for(var r=0;r<n.length;r++)pe(n[r],n[++r],n[++r]);s.__c&&s.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){s.__e(e,t.__v)}})}function de(e){return typeof e!=`object`||!e||e.__b>0?e:C(e)?e.map(de):e.constructor===void 0?w({},e):null}function fe(e,t,n,r,i,a,c,l,u){var d,f,p,m,h,g,_,v=n.props||b,y=t.props,x=t.type;if(x==`svg`?i=`http://www.w3.org/2000/svg`:x==`math`?i=`http://www.w3.org/1998/Math/MathML`:i||=`http://www.w3.org/1999/xhtml`,a!=null){for(d=0;d<a.length;d++)if((h=a[d])&&`setAttribute`in h==!!x&&(x?h.localName==x:h.nodeType==3)){e=h,a[d]=null;break}}if(e==null){if(x==null)return document.createTextNode(y);e=document.createElementNS(i,x,y.is&&y),l&&=(s.__m&&s.__m(t,a),!1),a=null}if(x==null)v===y||l&&e.data==y||(e.data=y);else{if(a=x==`textarea`&&y.defaultValue!=null?null:a&&o.call(e.childNodes),!l&&a!=null)for(v={},d=0;d<e.attributes.length;d++)v[(h=e.attributes[d]).name]=h.value;for(d in v)h=v[d],d==`dangerouslySetInnerHTML`?p=h:d==`children`||d in y||d==`value`&&`defaultValue`in y||d==`checked`&&`defaultChecked`in y||N(e,d,null,h,i);for(d in y)h=y[d],d==`children`?m=h:d==`dangerouslySetInnerHTML`?f=h:d==`value`?g=h:d==`checked`?_=h:l&&typeof h!=`function`||v[d]===h||N(e,d,h,v[d],i);if(f)l||p&&(f.__html==p.__html||f.__html==e.innerHTML)||(e.innerHTML=f.__html),t.__k=[];else if(p&&(e.innerHTML=``),ne(t.type==`template`?e.content:e,C(m)?m:[m],t,n,r,x==`foreignObject`?`http://www.w3.org/1999/xhtml`:i,a,c,a?a[0]:n.__k&&k(n,0),l,u),a!=null)for(d=a.length;d--;)ee(a[d]);l&&x!=`textarea`||(d=`value`,x==`progress`&&g==null?e.removeAttribute(`value`):g!=null&&(g!==e[d]||x==`progress`&&!g||x==`option`&&g!=v[d])&&N(e,d,g,v[d],i),d=`checked`,_!=null&&_!=e[d]&&N(e,d,_,v[d],i))}return e}function pe(e,t,n){try{if(typeof e==`function`){var r=typeof e.__u==`function`;r&&e.__u(),r&&t==null||(e.__u=e(t))}else e.current=t}catch(e){s.__e(e,n)}}function me(e,t,n){var r,i;if(s.unmount&&s.unmount(e),(r=e.ref)&&(r.current&&r.current!=e.__e||pe(r,null,t)),(r=e.__c)!=null){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(e){s.__e(e,t)}r.base=r.__P=r.__n=null}if(r=e.__k)for(i=0;i<r.length;i++)r[i]&&me(r[i],t,n||typeof e.type!=`function`);n||ee(e.__e),e.__c=e.__=e.__e=void 0}function he(e,t,n){return this.constructor(e,n)}function ge(e,t,n){var r,i,a,c;t==document&&(t=document.documentElement),s.__&&s.__(e,t),i=(r=typeof n==`function`)?null:n&&n.__k||t.__k,a=[],c=[],ce(t,e=(!r&&n||t).__k=T(D,null,[e]),i||b,b,t.namespaceURI,!r&&n?[n]:i?null:t.firstChild?o.call(t.childNodes):null,a,!r&&n?n:i?i.__e:t.firstChild,r,c),ue(a,e,c),e.props.children=null}o=x.slice,s={__e:function(e,t,n,r){for(var i,a,o;t=t.__;)if((i=t.__c)&&!i.__)try{if((a=i.constructor)&&a.getDerivedStateFromError!=null&&(i.setState(a.getDerivedStateFromError(e)),o=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,r||{}),o=i.__d),o)return i.__E=i}catch(t){e=t}throw e}},c=0,O.prototype.setState=function(e,t){var n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=w({},this.state);typeof e==`function`&&(e=e(w({},n),this.props)),e&&w(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),j(this))},O.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),j(this))},O.prototype.render=D,l=[],d=typeof Promise==`function`?Promise.prototype.then.bind(Promise.resolve()):setTimeout,f=function(e,t){return e.__v.__b-t.__v.__b},M.__r=0,p=Math.random().toString(8),m=`__d`+p,h=`__a`+p,g=/(PointerCapture)$|Capture$/i,_=0,v=se(!1),y=se(!0);var P,F,_e,ve,I=0,ye=[],L=s,be=L.__b,xe=L.__r,Se=L.diffed,Ce=L.__c,we=L.unmount,Te=L.__;function Ee(e,t){L.__h&&L.__h(F,e,I||t),I=0;var n=F.__H||(F.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function R(e){return I=1,De(Pe,e)}function De(e,t,n){var r=Ee(P++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Pe(void 0,t),function(e){var t=r.__N?r.__N[0]:r.__[0],n=r.t(t,e);t!==n&&(r.__N=[n,r.__[1]],r.__c.setState({}))}],r.__c=F,!F.__f)){var i=function(e,t,n){if(!r.__c.__H)return!0;var i=!1,o=r.__c.props!==e;if(r.__c.__H.__.some(function(e){if(e.__N){i=!0;var t=e.__[0];e.__=e.__N,e.__N=void 0,t!==e.__[0]&&(o=!0)}}),a){var s=a.call(this,e,t,n);return i?s||o:s}return!i||o};F.__f=!0;var a=F.shouldComponentUpdate,o=F.componentWillUpdate;F.componentWillUpdate=function(e,t,n){if(this.__e){var r=a;a=void 0,i(e,t,n),a=r}o&&o.call(this,e,t,n)},F.shouldComponentUpdate=i}return r.__N||r.__}function z(e,t){var n=Ee(P++,3);!L.__s&&Ne(n.__H,t)&&(n.__=e,n.u=t,F.__H.__h.push(n))}function B(e){return I=5,Oe(function(){return{current:e}},[])}function Oe(e,t){var n=Ee(P++,7);return Ne(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function ke(){for(var e;e=ye.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(V),t.__h.some(Me),t.__h=[]}catch(n){t.__h=[],L.__e(n,e.__v)}}}L.__b=function(e){F=null,be&&be(e)},L.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Te&&Te(e,t)},L.__r=function(e){xe&&xe(e),P=0;var t=(F=e.__c).__H;t&&(_e===F?(t.__h=[],F.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(V),t.__h.some(Me),t.__h=[],P=0)),_e=F},L.diffed=function(e){Se&&Se(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(ye.push(t)!==1&&ve===L.requestAnimationFrame||((ve=L.requestAnimationFrame)||je)(ke)),t.__H.__.some(function(e){e.u&&=(e.__H=e.u,void 0)})),_e=F=null},L.__c=function(e,t){t.some(function(e){try{e.__h.some(V),e.__h=e.__h.filter(function(e){return!e.__||Me(e)})}catch(n){t.some(function(e){e.__h&&=[]}),t=[],L.__e(n,e.__v)}}),Ce&&Ce(e,t)},L.unmount=function(e){we&&we(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{V(e)}catch(e){t=e}}),n.__H=void 0,t&&L.__e(t,n.__v))};var Ae=typeof requestAnimationFrame==`function`;function je(e){var t,n=function(){clearTimeout(r),Ae&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);Ae&&(t=requestAnimationFrame(n))}function V(e){var t=F,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),F=t}function Me(e){var t=F;e.__c=e.__(),F=t}function Ne(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function Pe(e,t){return typeof t==`function`?t(e):t}var Fe=0;Array.isArray;function H(e,t,n,r,i,a){t||={};var o,c,l=t;if(`ref`in l)for(c in l={},t)c==`ref`?o=t[c]:l[c]=t[c];var u={type:e,props:l,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Fe,__i:-1,__u:0,__source:i,__self:a};if(typeof e==`function`&&(o=e.defaultProps))for(c in o)l[c]===void 0&&(l[c]=o[c]);return s.vnode&&s.vnode(u),u}function U({name:e,size:t,children:n}){return H(`svg`,{"data-icon":e,"aria-hidden":`true`,focusable:`false`,width:t,height:t,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`,"stroke-linecap":`round`,"stroke-linejoin":`round`,children:n})}function Ie({size:e=26}){return H(U,{name:`chat`,size:e,children:[H(`path`,{d:`M4 5.5A2.5 2.5 0 0 1 6.5 3h11A2.5 2.5 0 0 1 20 5.5v8a2.5 2.5 0 0 1-2.5 2.5H10l-4.5 4v-4h0A1.5 1.5 0 0 1 4 14.5z`}),H(`path`,{d:`M8.5 9.5h.01M12 9.5h.01M15.5 9.5h.01`,"stroke-width":`2.5`})]})}function Le({size:e=26}){return H(U,{name:`chevron-down`,size:e,children:H(`path`,{d:`M6 9l6 6 6-6`})})}function Re({size:e=18}){return H(U,{name:`close`,size:e,children:H(`path`,{d:`M6 6l12 12M18 6L6 18`})})}var ze=`M7 11v9M7 11l3.5-7.2A1.8 1.8 0 0 1 14 4.6V9h4.6a2 2 0 0 1 2 2.3l-1.2 7A2 2 0 0 1 17.4 20H7M7 11H4.5A1.5 1.5 0 0 0 3 12.5v6A1.5 1.5 0 0 0 4.5 20H7`;function Be({size:e=16}){return H(U,{name:`thumb-up`,size:e,children:H(`path`,{d:ze})})}function Ve({size:e=16}){return H(U,{name:`thumb-down`,size:e,children:H(`path`,{d:ze,transform:`matrix(1 0 0 -1 0 24)`})})}function He({isOpen:e,onClick:t,iconUrl:n,buttonRef:r}){let[i,a]=R(`loading`),o=n!==void 0&&i!==`failed`,s=o&&!e&&i===`loaded`;return H(`button`,{type:`button`,class:`whoo-widget-launcher`,onClick:t,"aria-label":e?`Close chat`:`Open chat`,ref:r,children:[e?H(Le,{}):s?null:H(Ie,{}),o?H(`img`,{class:`whoo-widget-launcher-icon-image`,src:n,alt:``,referrerpolicy:`no-referrer`,hidden:!s,onLoad:()=>a(`loaded`),onError:()=>a(`failed`)}):null]})}function Ue({value:e,onChange:t,onSend:n,disabled:r,inputRef:i}){return H(`div`,{class:`whoo-widget-composer`,children:[H(`label`,{class:`whoo-widget-sr-only`,for:`whoo-widget-composer-input`,children:`Message`}),H(`input`,{id:`whoo-widget-composer-input`,class:`whoo-widget-composer-input`,value:e,readOnly:r,"aria-disabled":r,ref:i,onInput:e=>t(e.target.value),onKeyDown:e=>{e.key===`Enter`&&n()}}),H(`button`,{type:`button`,class:`whoo-widget-composer-send`,onClick:n,disabled:r,children:`Send`})]})}function We({message:e}){return H(`div`,{class:`whoo-widget-error-banner`,role:`alert`,children:e})}var W=/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/y,G=/\*\*([^*\s](?:[^*]*[^*\s])?)\*\*/y,K=/(?<![A-Za-z0-9_])_([^_\s](?:[^_]*[^_\s])?)_(?![A-Za-z0-9_])/y,q=/\*([^*\s](?:[^*]*[^*\s])?)\*/y,J=/[ \t]*[*+-][ \t]+/y,Ge=/https?:\/\/\S+/y,Ke=/[.,;:!?)\]}>]+$/;function qe(e){let t=[],n=0,r=0,i=n=>{n>r&&t.push({type:`text`,value:e.slice(r,n),start:r,end:n})};for(;n<e.length;){if((n===0||e[n-1]===`
|
|
2
|
+
`)&&(J.lastIndex=n,J.exec(e))){i(n),t.push({type:`text`,value:`• `,start:n,end:J.lastIndex}),n=J.lastIndex,r=n;continue}if(e[n]===`!`&&n+1<e.length&&e[n+1]===`[`){let t=/!\[([^\]]*)\]\(([^)]*)\)/y;t.lastIndex=n;let r=t.exec(e);if(r){n+=r[0].length;continue}}if(e[n-1]!==`!`){W.lastIndex=n;let a=W.exec(e);if(a){i(n),t.push({type:`link`,text:a[1],url:a[2],start:n,end:W.lastIndex}),n=W.lastIndex,r=n;continue}}G.lastIndex=n;let a=G.exec(e);if(a){i(n),t.push({type:`bold`,value:a[1],start:n,end:G.lastIndex}),n=G.lastIndex,r=n;continue}K.lastIndex=n;let o=K.exec(e);if(o){i(n),t.push({type:`italic`,value:o[1],start:n,end:K.lastIndex}),n=K.lastIndex,r=n;continue}q.lastIndex=n;let s=q.exec(e);if(s){i(n),t.push({type:`italic`,value:s[1],start:n,end:q.lastIndex}),n=q.lastIndex,r=n;continue}Ge.lastIndex=n;let c=Ge.exec(e);if(c){let e=c[0].match(Ke),a=e?c[0].slice(0,c[0].length-e[0].length):c[0];if(a.length>0){i(n),t.push({type:`link`,text:a,url:a,start:n,end:n+a.length}),n+=a.length,r=n;continue}}n+=1}return i(e.length),t}function Je(e){return qe(e).map((e,t)=>{switch(e.type){case`bold`:return H(`strong`,{children:Je(e.value)},t);case`italic`:return H(`em`,{children:Je(e.value)},t);case`link`:return H(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,children:[e.text,H(`span`,{class:`whoo-widget-sr-only`,children:` (opens in new tab)`})]},t);default:return e.value}})}var Ye=[{value:``,label:`Select a reason (optional)`},{value:`factual`,label:`Factual error`},{value:`incomplete`,label:`Incomplete`},{value:`tone`,label:`Off tone`},{value:`other`,label:`Other`}];function Xe({state:e,containerRef:t,onThumbsUp:n,onThumbsDown:r,onSubmitDetailed:i,onCancel:a}){let[o,s]=R(``),[c,l]=R(``),u=B(e.status);if(z(()=>{let n=u.current;if(u.current=e.status,n===e.status)return;let r=t?.current;if(!r)return;let i=r.getRootNode();r.contains(i.activeElement)||r.focus()},[e.status,t]),e.status===`submitted`)return H(`div`,{class:`whoo-widget-feedback-submitted`,role:`status`,children:`Thanks for the feedback`});if(e.status===`expanded`)return H(`div`,{class:`whoo-widget-feedback-form`,children:[H(`label`,{children:[H(`span`,{class:`whoo-widget-sr-only`,children:`Additional feedback`}),H(`textarea`,{class:`whoo-widget-feedback-textarea`,value:o,onInput:e=>s(e.target.value),placeholder:`What was wrong? (optional)`})]}),H(`select`,{class:`whoo-widget-feedback-select`,"aria-label":`Feedback category`,value:c,onChange:e=>l(e.target.value),children:Ye.map(e=>H(`option`,{value:e.value,children:e.label},e.value))}),H(`div`,{class:`whoo-widget-feedback-form-buttons`,children:[H(`button`,{type:`button`,class:`whoo-widget-feedback-submit`,onClick:()=>i(o,c),children:`Submit`}),H(`button`,{type:`button`,class:`whoo-widget-feedback-cancel`,onClick:a,children:`Cancel`})]})]});let d=e.status===`submitting`;return H(`div`,{class:`whoo-widget-feedback`,children:[H(`div`,{class:`whoo-widget-feedback-buttons`,children:[H(`button`,{type:`button`,"aria-label":`Good response`,disabled:d,onClick:n,children:H(Be,{})}),H(`button`,{type:`button`,"aria-label":`Bad response`,disabled:d,onClick:r,children:H(Ve,{})})]}),e.status===`error`?H(`div`,{class:`whoo-widget-feedback-error`,role:`status`,children:`Couldn't send feedback`}):null]})}function Ze({isSlowResponse:e}){return H(`div`,{class:`whoo-widget-pending`,role:`status`,children:[H(`span`,{class:`whoo-widget-typing`,"aria-hidden":`true`,children:[H(`span`,{}),H(`span`,{}),H(`span`,{})]}),e?H(`span`,{class:`whoo-widget-pending-text`,children:`Looking that up for you…`}):null]})}function Qe({url:e,alt:t}){let[n,r]=R(!1);return n?null:H(`img`,{class:`whoo-widget-empty-state-image`,src:e,alt:t,referrerpolicy:`no-referrer`,onError:()=>r(!0)})}function $e({message:e,feedbackState:t,showFeedback:n,pending:r,isSlowResponse:i,onThumbsUp:a,onThumbsDown:o,onSubmitDetailed:s,onCancelFeedback:c}){let l=B(null),u=e.id;return H(`div`,{ref:l,tabIndex:-1,class:`whoo-widget-message whoo-widget-message--${e.role}`,children:[r?H(Ze,{isSlowResponse:i}):Je(e.content),n&&e.role===`assistant`&&u?H(Xe,{state:t,containerRef:l,onThumbsUp:()=>a(u),onThumbsDown:()=>o(u),onSubmitDetailed:(e,t)=>s(u,e,t),onCancel:()=>c(u)}):null]})}function et({messages:e,messageFeedback:t,lastCompletedMessageText:n,emptyStateImage:r,showFeedback:i=!1,isStreaming:a=!1,isSlowResponse:o=!1,onThumbsUp:s,onThumbsDown:c,onSubmitDetailed:l,onCancelFeedback:u}){let d=B(null);return z(()=>{let e=d.current;e&&(e.scrollTop=e.scrollHeight)},[e,o]),H(D,{children:[H(`div`,{class:`whoo-widget-message-list`,ref:d,children:[r?H(Qe,{...r}):null,e.map((n,r)=>H($e,{message:n,showFeedback:i,feedbackState:n.id?t[n.id]??{status:`idle`}:{status:`idle`},pending:a&&r===e.length-1&&n.role===`assistant`&&n.content===``,isSlowResponse:o,onThumbsUp:s,onThumbsDown:c,onSubmitDetailed:l,onCancelFeedback:u},n.id??r))]}),H(`div`,{class:`whoo-widget-sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:n??``})]})}var tt=`button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])`;function nt(e){return Array.from(e.querySelectorAll(tt)).filter(e=>{let t=getComputedStyle(e);return t.display!==`none`&&t.visibility!==`hidden`})}function rt({state:e,controller:t,greeting:n}){let r=B(null),a=B(null);z(()=>{a.current?.focus()},[]);let o=e=>{if(e.key===`Escape`){t.close();return}if(e.key!==`Tab`)return;let n=r.current;if(!n)return;let i=nt(n);if(i.length===0)return;let a=i[0],o=i[i.length-1],s=n.getRootNode().activeElement;if(!n.contains(s)){e.preventDefault(),a.focus();return}e.shiftKey&&s===a?(e.preventDefault(),o.focus()):!e.shiftKey&&s===o&&(e.preventDefault(),a.focus())},s=()=>{let n=e.draft.trim();n&&!e.isStreaming&&(t.setDraft(``),t.sendMessage(n))},c=`Chat with ${i(t.config.name)||e.agentName||`Aiden`}`,l=e.messages.length===0&&n?[{role:`assistant`,content:n,id:null}]:e.messages,u=t.emptyStateImageUrl,d=e.messages.length===0&&u?{url:u,alt:t.emptyStateImageAlt}:void 0;return H(`div`,{class:`whoo-widget-panel`,role:`dialog`,"aria-modal":`true`,"aria-label":c,ref:r,onKeyDown:o,children:[H(`div`,{class:`whoo-widget-header`,children:[H(`h2`,{class:`whoo-widget-header-title`,children:c}),H(`div`,{class:`whoo-widget-header-actions`,children:[e.messages.length>0&&H(`button`,{type:`button`,class:`whoo-widget-header-reset`,onClick:()=>t.resetConversation(),children:`New conversation`}),H(`button`,{type:`button`,class:`whoo-widget-header-close`,"aria-label":`Close chat`,onClick:()=>t.close(),children:H(Re,{})})]})]}),H(et,{messages:l,messageFeedback:e.messageFeedback,lastCompletedMessageText:e.lastCompletedMessageText,emptyStateImage:d,showFeedback:t.showFeedback,isStreaming:e.isStreaming,isSlowResponse:e.isSlowResponse,onThumbsUp:e=>t.submitFeedback(e,`up`),onThumbsDown:e=>t.expandFeedback(e),onSubmitDetailed:(e,n,r)=>t.submitFeedback(e,`down`,n||void 0,r||void 0),onCancelFeedback:e=>t.cancelFeedback(e)}),e.runtimeError&&H(We,{message:e.runtimeError}),H(Ue,{value:e.draft,onChange:e=>t.setDraft(e),onSend:s,disabled:e.isStreaming,inputRef:a})]})}function it({controller:e}){let[t,n]=R(e.getState()),r=B(null),i=B(t.isOpen);return z(()=>(n(e.getState()),e.subscribe(n)),[e]),z(()=>{i.current&&!t.isOpen&&r.current?.focus(),i.current=t.isOpen},[t.isOpen]),t.initError?null:H(D,{children:[H(He,{isOpen:t.isOpen,onClick:()=>t.isOpen?e.close():e.open(),iconUrl:e.launcherIconUrl,buttonRef:r}),t.isOpen&&H(rt,{state:t,controller:e,greeting:e.config.greeting})]})}var Y=class extends Error{status;constructor(e,t){super(e),this.name=`WidgetApiError`,this.status=t}};function X(e){if(typeof e!=`string`)return null;let t=e.trim();return t===``?null:t}async function at(e,t){let n=await fetch(`${e}/api/v1/widget/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({publishable_key:t})});if(!n.ok)throw new Y(`Failed to create widget session (${n.status})`,n.status);let r=await n.json();return{token:r.token,...ot(r)}}function ot(e){return{primaryColor:X(e.primary_color),name:X(e.name),accentColor:X(e.accent_color),inkColor:X(e.ink_color)}}async function st(e,t){let n=await fetch(`${e}/api/v1/widget/branding`,{headers:{Authorization:`Bearer ${t}`}});if(!n.ok)throw new Y(`Failed to load widget branding (${n.status})`,n.status);return ot(await n.json())}async function ct(e,t,n){let r=await fetch(`${e}/api/v1/widget/feedback`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${t}`},body:JSON.stringify({message_id:n.messageId,rating:n.rating,correction:n.correction??null,category:n.category??null})});if(!r.ok)throw new Y(`Feedback submission failed (${r.status})`,r.status)}async function*lt(e,t,n,r,i){let a=await fetch(`${e}/api/v1/widget/chat`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${t}`},body:JSON.stringify({conversation_id:n,message:r}),signal:i});if(!a.ok||!a.body)throw new Y(`Chat request failed (${a.status})`,a.status);let o=a.body.getReader(),s=new TextDecoder,c=``;for(;;){let{done:e,value:t}=await o.read();if(e)break;c+=s.decode(t,{stream:!0});let n=c.indexOf(`
|
|
3
3
|
|
|
4
4
|
`);for(;n!==-1;){let e=c.slice(0,n);c=c.slice(n+2);let t=e.split(`
|
|
5
|
-
`).find(e=>e.startsWith(`data: `));t&&(yield
|
|
5
|
+
`).find(e=>e.startsWith(`data: `));t&&(yield ut(JSON.parse(t.slice(6)))),n=c.indexOf(`
|
|
6
6
|
|
|
7
|
-
`)}}}function ct(e){return typeof e.error==`string`?{type:`error`,error:e.error,conversationId:e.conversation_id}:e.done===!0?{type:`done`,conversationId:e.conversation_id,messageId:e.message_id??null}:typeof e.delta==`string`?e.verbatim===!0?{type:`delta`,delta:e.delta,verbatim:!0}:{type:`delta`,delta:e.delta}:{type:`conversation_id`,conversationId:e.conversation_id}}function lt(e,t){if(e!=null&&e!==``){if(typeof e==`string`)try{let t=new URL(e);if(t.protocol===`https:`||t.protocol===`data:`&&t.pathname.toLowerCase().startsWith(`image/`))return e}catch{}console.warn(`whoo-aiden-widget: ignoring \`${t}\` -- only https: and data:image/ URLs are allowed.`)}}var ut=40,dt=120;function ft(e){let t=[];for(let n of Ge(e))if(n.type===`text`){let e=n.value.split(/(\s+)/),r=n.start;for(let n of e)r+=n.length,n.trim().length>0&&t.push(r)}else t.push(n.end);return t}function pt(e){let t=null;return e?.addEventListener(`abort`,()=>{t?.()},{once:!0}),function(e){return new Promise(n=>{let r=setTimeout(()=>{t=null,n()},e);t=()=>{clearTimeout(r),t=null,n()}})}}async function mt(e,t,n){let r=n?.wordIntervalMs??ut,i=n?.tokenIntervalMs??dt,a=n?.signal,o=Ge(e),s=new Set(o.filter(e=>e.type!==`text`).map(e=>e.end)),c=pt(a),l=``;for(let n of ft(e))if(a?.aborted||(l=e.slice(0,n),t(l),await c(s.has(n)?i:r),a?.aborted))return;l!==e&&t(e)}function ht(e){return`whoo-aiden-widget:conversation:${e}`}function gt(e){try{return window.sessionStorage.getItem(ht(e))}catch{return null}}function _t(e,t){try{window.sessionStorage.setItem(ht(e),t)}catch{}}function vt(e){try{window.sessionStorage.removeItem(ht(e))}catch{}}var yt=8e3,bt=class{config;state;listeners=new Set;sessionToken=null;conversationId=null;storageIdentifier;activeRequestController=null;slowResponseTimer=null;prefersReducedMotion;launcherIconUrl;emptyStateImageUrl;emptyStateImageAlt;showFeedback;constructor(e){this.config=e,this.launcherIconUrl=lt(e.launcherIconUrl,`launcherIconUrl`),this.emptyStateImageUrl=lt(e.emptyStateImageUrl,`emptyStateImageUrl`),this.emptyStateImageAlt=typeof e.emptyStateImageAlt==`string`?e.emptyStateImageAlt.trim():``,this.showFeedback=e.showFeedback===!0,this.storageIdentifier=e.publishableKey??`session-token-mode`,this.prefersReducedMotion=typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,this.state={isOpen:!1,messages:[],isStreaming:!1,initError:null,runtimeError:null,messageFeedback:{},primaryColor:null,agentName:null,accentColor:null,inkColor:null,lastCompletedMessageText:null,isSlowResponse:!1,draft:``}}getState(){return this.state}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}clearSlowResponse(){this.slowResponseTimer!==null&&(clearTimeout(this.slowResponseTimer),this.slowResponseTimer=null),this.state.isSlowResponse&&this.setState({isSlowResponse:!1})}setState(e){this.state={...this.state,...e};for(let e of this.listeners)e(this.state)}async init(){let e=this.config.apiBaseUrl??`https://api.aidenvoice.com`;try{if(this.config.sessionToken)this.sessionToken=this.config.sessionToken;else if(this.config.publishableKey){let{token:t,primaryColor:n,name:r,accentColor:i,inkColor:a}=await at(e,this.config.publishableKey);this.sessionToken=t,this.setState({primaryColor:n,agentName:r,accentColor:i,inkColor:a})}else throw Error(`WidgetConfig must include exactly one of publishableKey or sessionToken`)}catch(e){console.error(`[whoo-aiden-widget] initialization failed:`,e),this.setState({initError:e instanceof Error?e.message:String(e)});return}this.conversationId=gt(this.storageIdentifier)}open(){this.setState({isOpen:!0})}resetConversation(){this.activeRequestController?.abort(),this.activeRequestController=null,this.clearSlowResponse(),this.conversationId=null,vt(this.storageIdentifier),this.setState({messages:[],messageFeedback:{},runtimeError:null,isStreaming:!1,lastCompletedMessageText:null})}setDraft(e){this.setState({draft:e})}close(){this.activeRequestController?.abort(),this.activeRequestController=null,this.clearSlowResponse(),this.setState({isOpen:!1})}async sendMessage(e){if(!this.sessionToken)return;let t=this.config.apiBaseUrl??`https://api.aidenvoice.com`,n={role:`user`,content:e,id:null},r={role:`assistant`,content:``,id:null};this.setState({messages:[...this.state.messages,n,r],isStreaming:!0,runtimeError:null});let i=e=>{let t=[...this.state.messages];t[t.length-1]={...t[t.length-1],content:e},this.setState({messages:t})};this.activeRequestController=new AbortController;let{signal:a}=this.activeRequestController;this.slowResponseTimer=setTimeout(()=>{this.slowResponseTimer=null,this.setState({isSlowResponse:!0})},yt);let o=()=>{this.setState({runtimeError:`Something went wrong, please try again.`,...this.state.draft===``?{draft:e}:{}})},s=``;try{for await(let n of st(t,this.sessionToken,this.conversationId,e,a))if(n.type===`conversation_id`)this.conversationId=n.conversationId,_t(this.storageIdentifier,n.conversationId);else if(n.type===`delta`)this.clearSlowResponse(),n.verbatim&&!this.prefersReducedMotion?(await mt(n.delta,e=>i(e),{signal:a}),s=n.delta):n.verbatim?(s=n.delta,i(s)):(s+=n.delta,i(s));else if(n.type===`done`){if(n.conversationId&&(this.conversationId=n.conversationId,_t(this.storageIdentifier,n.conversationId)),n.messageId){let e=[...this.state.messages];e[e.length-1]={...e[e.length-1],id:n.messageId},this.setState({messages:e})}this.setState({lastCompletedMessageText:s})}else if(n.type===`error`){console.error(`[whoo-aiden-widget] chat error:`,n.error),o(),this.activeRequestController?.abort();break}}catch(e){e?.name===`AbortError`||(console.error(`[whoo-aiden-widget] chat request failed:`,e),o())}finally{this.activeRequestController=null,this.clearSlowResponse(),this.setState({isStreaming:!1})}}expandFeedback(e){this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`expanded`}}})}cancelFeedback(e){this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`idle`}}})}async submitFeedback(e,t,n,r){if(!this.sessionToken)return;let i=this.config.apiBaseUrl??`https://api.aidenvoice.com`;this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`submitting`,rating:t}}});try{await ot(i,this.sessionToken,{messageId:e,rating:t,correction:n,category:r}),this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`submitted`,rating:t}}})}catch(n){console.error(`[whoo-aiden-widget] feedback submission failed:`,n),this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`error`,rating:t}}})}}},xt=`:host,.whoo-widget-root{all:initial;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif}.whoo-widget-launcher{bottom:20px;left:var(--whoo-widget-inset-left,auto);right:var(--whoo-widget-inset-right,20px);background:var(--whoo-widget-color,#4f46e5);width:56px;height:56px;color:var(--whoo-widget-text-on-color,#fff);cursor:pointer;border:none;border-radius:50%;justify-content:center;align-items:center;padding:0;font-size:24px;display:flex;position:fixed;box-shadow:0 2px 8px #0003}.whoo-widget-launcher:focus-visible{box-shadow:0 2px 8px #0003,0 0 0 4px #fff}.whoo-widget-launcher svg{display:block}.whoo-widget-launcher-icon-image{object-fit:cover;border-radius:50%;width:32px;height:32px}.whoo-widget-launcher-icon-image[hidden]{display:none}.whoo-widget-panel{bottom:88px;left:var(--whoo-widget-inset-left,auto);right:var(--whoo-widget-inset-right,20px);background:#fff;border-radius:12px;flex-direction:column;width:360px;max-width:calc(100vw - 40px);height:480px;max-height:calc(100vh - 108px);display:flex;position:fixed;overflow:hidden;box-shadow:0 4px 16px #0003}@media (width<=400px),(height<=420px){.whoo-widget-panel{width:auto;max-width:none;height:auto;max-height:none;inset:8px}}.whoo-widget-header{border-bottom:1px solid #e5e5e5;flex-shrink:0;justify-content:space-between;align-items:center;gap:8px;padding:8px 8px 8px 16px;display:flex}.whoo-widget-header-title{color:var(--whoo-widget-ink,#111);text-overflow:ellipsis;white-space:nowrap;margin:0;font-size:15px;font-weight:600;overflow:hidden}.whoo-widget-header-actions{flex-shrink:0;align-items:center;gap:4px;display:flex}.whoo-widget-header-close,.whoo-widget-header-reset{color:var(--whoo-widget-color-text,#4f46e5);cursor:pointer;background:0 0;border:none;border-radius:6px;justify-content:center;align-items:center;min-width:24px;min-height:24px;padding:4px 8px;font-size:13px;display:inline-flex}.whoo-widget-header-close{width:32px;height:32px;padding:0}.whoo-widget-header-close:hover,.whoo-widget-header-reset:hover{background:#f3f4f6}.whoo-widget-message-list{flex:1;min-height:100px;padding:12px;overflow-y:auto}.whoo-widget-empty-state-image{object-fit:contain;max-width:min(160px,100%);height:auto;max-height:160px;margin:8px auto 16px;display:block}@media (width<=400px),(height<=420px){.whoo-widget-empty-state-image{max-height:64px;margin:0 auto 8px}}.whoo-widget-message{white-space:pre-line;border-radius:8px;max-width:80%;margin-bottom:8px;padding:8px 12px}.whoo-widget-message--user{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);margin-left:auto}.whoo-widget-message--user a{color:inherit}.whoo-widget-message--assistant{color:var(--whoo-widget-ink,#111);background:#f0f0f0}.whoo-widget-message--assistant a{color:var(--whoo-widget-link-color,#00e)}.whoo-widget-pending{flex-wrap:wrap;align-items:center;gap:8px;min-height:1.2em;display:flex}.whoo-widget-typing{align-items:center;gap:4px;display:inline-flex}.whoo-widget-typing span{background:#6b7280;border-radius:50%;width:6px;height:6px;animation:1.2s ease-in-out infinite whoo-widget-typing-bounce}.whoo-widget-typing span:nth-child(2){animation-delay:.2s}.whoo-widget-typing span:nth-child(3){animation-delay:.4s}@keyframes whoo-widget-typing-bounce{0%,80%,to{transform:translateY(0)}40%{transform:translateY(-4px)}}@media (prefers-reduced-motion:reduce){.whoo-widget-typing span{animation:none}}.whoo-widget-error-banner{color:#991b1b;background:#fee2e2;padding:8px 12px;font-size:13px}.whoo-widget-composer{border-top:1px solid #e5e5e5;gap:8px;padding:12px;display:flex}.whoo-widget-composer-input{border:1px solid #6b7280;border-radius:6px;flex:1;padding:8px}.whoo-widget-composer-send{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);cursor:pointer;border:none;border-radius:6px;padding:8px 16px}.whoo-widget-composer-send:disabled,.whoo-widget-composer-input[aria-disabled=true]{opacity:.6;cursor:not-allowed}.whoo-widget-feedback{align-items:center;gap:6px;margin-top:4px;display:flex}.whoo-widget-feedback-buttons{gap:6px;display:flex}.whoo-widget-feedback-buttons button{cursor:pointer;color:#4b5563;background:0 0;border:none;border-radius:4px;justify-content:center;align-items:center;min-width:24px;min-height:24px;padding:4px;display:inline-flex}.whoo-widget-feedback-buttons button:hover:not(:disabled){color:#111;background:#0000000f}.whoo-widget-feedback-buttons button:disabled{opacity:.3;cursor:not-allowed}.whoo-widget-feedback-form{flex-direction:column;gap:6px;margin-top:6px;display:flex}.whoo-widget-feedback-textarea{box-sizing:border-box;resize:vertical;border:1px solid #6b7280;border-radius:6px;width:100%;padding:6px;font-size:12px}.whoo-widget-feedback-select{border:1px solid #6b7280;border-radius:6px;min-height:24px;padding:4px;font-size:12px}.whoo-widget-feedback-form-buttons{gap:6px;display:flex}.whoo-widget-feedback-submit{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);cursor:pointer;border:none;border-radius:6px;padding:8px 16px;font-size:13px}.whoo-widget-feedback-cancel{color:#111;cursor:pointer;background:#fff;border:1px solid #6b7280;border-radius:6px;padding:8px 16px;font-size:13px}.whoo-widget-feedback-submitted{color:#6b7280;margin-top:4px;font-size:12px}.whoo-widget-feedback-error{color:#991b1b;font-size:12px}.whoo-widget-sr-only{clip:rect(0, 0, 0, 0);white-space:nowrap;border:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}button:focus-visible,input:focus-visible,textarea:focus-visible,select:focus-visible,a:focus-visible{outline-offset:2px;outline:2px solid #111827;box-shadow:0 0 0 4px #fff}`,St=/^(inherit|initial|unset|revert|revert-layer)$|\bcurrentcolor\b|\b(var|env|attr|light-dark)\(/i;function Ct(e){if(St.test(e.trim()))return null;let t=document.createElement(`div`);if(t.style.color=e,t.style.color===``)return null;let n=document.createElement(`div`);n.attachShadow({mode:`open`}).appendChild(t),document.body.appendChild(n);let r=getComputedStyle(t).color;n.remove();let i=r.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?/);if(!i)return null;let a=i[4]===void 0?1:Number(i[4]);return{rgb:[Number(i[1]),Number(i[2]),Number(i[3])].map(e=>Math.round(e*a+255*(1-a))),translucent:a<1}}function X(e){return Ct(e)?.rgb??null}function Z([e,t,n]){let r=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return .2126*r(e)+.7152*r(t)+.0722*r(n)}function wt(e,t){let n=Math.max(e,t),r=Math.min(e,t);return(n+.05)/(r+.05)}function Tt(e){let t=X(e);if(!t)return console.warn(`[whoo-aiden-widget] Could not parse color "${e}" for contrast calculation; defaulting to white text.`),`#ffffff`;let n=Z(t);return wt(n,Z([0,0,0]))>=wt(n,Z([255,255,255]))?`#000000`:`#ffffff`}var Q=`#4f46e5`,Et=`#ffffff`,Dt=`#f0f0f0`,Ot=4.5;function kt([e,t,n]){return`#${[e,t,n].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}function At(e,t=Et){let n=X(e),r=X(t);if(!n||!r)return Q;let i=Z(r),a=e=>wt(Z(e),i)>=Ot;if(a(n))return kt(n);for(let e=.99;e>0;e-=.01){let t=n.map(t=>Math.round(t*e));if(a(t))return kt(t)}return`#000000`}var jt=`#111111`,Mt=`#0000ee`;function $(e){if(!e)return null;let t=Ct(e);return t?kt(t.rgb):null}function Nt({color:e,inkColor:t,accentColor:n}){let r=$(e),i=r??Q,a=At(i),o=$(t),s=o?At(o,Dt):jt,c=$(n),l=c?At(c,Dt):Mt;return{primary:i,textOnPrimary:Tt(i),primaryAsText:a,ink:s,link:l,adjusted:{primary:r!==null&&a!==i,ink:o!==null&&s!==o,link:c!==null&&l!==c}}}function Pt(e,t,n=Q){let r=t;$(t)===null&&(console.warn(`[whoo-aiden-widget] Could not use "${t}" as the theme color; falling back to "${n}".`),r=n);let i=Nt({color:r});e.style.setProperty(`--whoo-widget-color`,i.primary),e.style.setProperty(`--whoo-widget-text-on-color`,i.textOnPrimary),e.style.setProperty(`--whoo-widget-color-text`,i.primaryAsText)}function Ft(e,{inkColor:t,accentColor:n}){let r=Nt({inkColor:t,accentColor:n});e.style.setProperty(`--whoo-widget-ink`,r.ink),e.style.setProperty(`--whoo-widget-link-color`,r.link)}function It(e,t){e&&$(e)===null&&console.warn(`[whoo-aiden-widget] Could not use "${e}" as the ${t}; using the default.`)}function Lt(e,t){Pt(e,t.color??Q),It(t.inkColor,`ink color`),It(t.accentColor,`accent color`),Ft(e,{inkColor:t.inkColor,accentColor:t.accentColor});let n=t.position===`bottom-left`;e.style.setProperty(`--whoo-widget-inset-left`,n?`20px`:`auto`),e.style.setProperty(`--whoo-widget-inset-right`,n?`auto`:`20px`)}function Rt(e){let t=document.createElement(`div`);t.id=`whoo-aiden-widget-host`,t.style.position=`relative`,t.style.zIndex=String(r(e.zIndex));let n=t.attachShadow({mode:`open`}),i=document.createElement(`style`);i.textContent=xt,n.appendChild(i);let a=document.createElement(`div`);n.appendChild(a),Lt(a,e);let o=new bt(e),s=null,c=``;return o.subscribe(t=>{t.primaryColor&&t.primaryColor!==s&&(s=t.primaryColor,Pt(a,t.primaryColor,e.color));let n=`${t.inkColor}|${t.accentColor}`;(t.inkColor||t.accentColor)&&n!==c&&(c=n,Ft(a,{inkColor:$(t.inkColor)?t.inkColor:e.inkColor,accentColor:$(t.accentColor)?t.accentColor:e.accentColor}))}),me(U(nt,{controller:o}),a),o.init(),document.body.appendChild(t),{unmount(){me(null,a),t.remove()}}}function zt(e){return i(e),Rt(e)}return e.init=zt,e})({});
|
|
7
|
+
`)}}}function ut(e){return typeof e.error==`string`?{type:`error`,error:e.error,conversationId:e.conversation_id}:e.done===!0?{type:`done`,conversationId:e.conversation_id,messageId:e.message_id??null}:typeof e.delta==`string`?e.verbatim===!0?{type:`delta`,delta:e.delta,verbatim:!0}:{type:`delta`,delta:e.delta}:{type:`conversation_id`,conversationId:e.conversation_id}}function dt(e,t){if(e!=null&&e!==``){if(typeof e==`string`)try{let t=new URL(e);if(t.protocol===`https:`||t.protocol===`data:`&&t.pathname.toLowerCase().startsWith(`image/`))return e}catch{}console.warn(`whoo-aiden-widget: ignoring \`${t}\` -- only https: and data:image/ URLs are allowed.`)}}var ft=40,pt=120;function mt(e){let t=[];for(let n of qe(e))if(n.type===`text`){let e=n.value.split(/(\s+)/),r=n.start;for(let n of e)r+=n.length,n.trim().length>0&&t.push(r)}else t.push(n.end);return t}function ht(e){let t=null;return e?.addEventListener(`abort`,()=>{t?.()},{once:!0}),function(e){return new Promise(n=>{let r=setTimeout(()=>{t=null,n()},e);t=()=>{clearTimeout(r),t=null,n()}})}}async function gt(e,t,n){let r=n?.wordIntervalMs??ft,i=n?.tokenIntervalMs??pt,a=n?.signal,o=qe(e),s=new Set(o.filter(e=>e.type!==`text`).map(e=>e.end)),c=ht(a),l=``;for(let n of mt(e))if(a?.aborted||(l=e.slice(0,n),t(l),await c(s.has(n)?i:r),a?.aborted))return;l!==e&&t(e)}function _t(e){return`whoo-aiden-widget:conversation:${e}`}function vt(e){try{return window.sessionStorage.getItem(_t(e))}catch{return null}}function yt(e,t){try{window.sessionStorage.setItem(_t(e),t)}catch{}}function bt(e){try{window.sessionStorage.removeItem(_t(e))}catch{}}var xt=/^(inherit|initial|unset|revert|revert-layer)$|\bcurrentcolor\b|\b(var|env|attr|light-dark)\(/i;function St(e){if(xt.test(e.trim()))return null;let t=document.createElement(`div`);if(t.style.color=e,t.style.color===``)return null;let n=document.createElement(`div`);n.attachShadow({mode:`open`}).appendChild(t),document.body.appendChild(n);let r=getComputedStyle(t).color;n.remove();let i=r.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?/);if(!i)return null;let a=i[4]===void 0?1:Number(i[4]);return{rgb:[Number(i[1]),Number(i[2]),Number(i[3])].map(e=>Math.round(e*a+255*(1-a))),translucent:a<1}}function Ct(e){return St(e)?.rgb??null}function Z([e,t,n]){let r=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return .2126*r(e)+.7152*r(t)+.0722*r(n)}function wt(e,t){let n=Math.max(e,t),r=Math.min(e,t);return(n+.05)/(r+.05)}function Tt(e){let t=Ct(e);if(!t)return console.warn(`[whoo-aiden-widget] Could not parse color "${e}" for contrast calculation; defaulting to white text.`),`#ffffff`;let n=Z(t);return wt(n,Z([0,0,0]))>=wt(n,Z([255,255,255]))?`#000000`:`#ffffff`}var Q=`#4f46e5`,Et=`#ffffff`,Dt=`#f0f0f0`,Ot=4.5;function kt([e,t,n]){return`#${[e,t,n].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}function At(e,t=Et){let n=Ct(e),r=Ct(t);if(!n||!r)return Q;let i=Z(r),a=e=>wt(Z(e),i)>=Ot;if(a(n))return kt(n);for(let e=.99;e>0;e-=.01){let t=n.map(t=>Math.round(t*e));if(a(t))return kt(t)}return`#000000`}var jt=`#111111`,Mt=`#0000ee`;function $(e){if(typeof e!=`string`||!e)return null;let t=St(e);return t?kt(t.rgb):null}function Nt({color:e,inkColor:t,accentColor:n}){let r=$(e),i=r??Q,a=At(i),o=$(t),s=o?At(o,Dt):jt,c=$(n),l=c?At(c,Dt):Mt;return{primary:i,textOnPrimary:Tt(i),primaryAsText:a,ink:s,link:l,adjusted:{primary:r!==null&&a!==i,ink:o!==null&&s!==o,link:c!==null&&l!==c}}}function Pt(e){return typeof e==`string`?`"${e}"`:`a ${typeof e} value`}function Ft(e,t,n=Q){let r=t;$(t)===null&&(console.warn(`[whoo-aiden-widget] Could not use ${Pt(t)} as the theme color; falling back to ${Pt(n)}.`),r=n);let i=Nt({color:r});e.style.setProperty(`--whoo-widget-color`,i.primary),e.style.setProperty(`--whoo-widget-text-on-color`,i.textOnPrimary),e.style.setProperty(`--whoo-widget-color-text`,i.primaryAsText)}function It(e,{inkColor:t,accentColor:n}){let r=Nt({inkColor:t,accentColor:n});e.style.setProperty(`--whoo-widget-ink`,r.ink),e.style.setProperty(`--whoo-widget-link-color`,r.link)}function Lt(e,t){e&&$(e)===null&&console.warn(`[whoo-aiden-widget] Could not use ${Pt(e)} as the ${t}; using the default.`)}function Rt(e,t){Ft(e,t.color??Q),Lt(t.inkColor,`ink color`),Lt(t.accentColor,`accent color`),It(e,{inkColor:t.inkColor,accentColor:t.accentColor});let n=t.position===`bottom-left`;e.style.setProperty(`--whoo-widget-inset-left`,n?`20px`:`auto`),e.style.setProperty(`--whoo-widget-inset-right`,n?`auto`:`20px`)}var zt=8e3,Bt=class{config;state;listeners=new Set;sessionToken=null;conversationId=null;storageIdentifier;activeRequestController=null;slowResponseTimer=null;prefersReducedMotion;launcherIconUrl;emptyStateImageUrl;emptyStateImageAlt;showFeedback;constructor(e){this.config=e,this.launcherIconUrl=dt(e.launcherIconUrl,`launcherIconUrl`),this.emptyStateImageUrl=dt(e.emptyStateImageUrl,`emptyStateImageUrl`),this.emptyStateImageAlt=typeof e.emptyStateImageAlt==`string`?e.emptyStateImageAlt.trim():``,this.showFeedback=e.showFeedback===!0,this.storageIdentifier=e.publishableKey??`session-token-mode`,this.prefersReducedMotion=typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,this.state={isOpen:!1,messages:[],isStreaming:!1,initError:null,runtimeError:null,messageFeedback:{},primaryColor:null,agentName:null,accentColor:null,inkColor:null,lastCompletedMessageText:null,isSlowResponse:!1,draft:``}}getState(){return this.state}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}clearSlowResponse(){this.slowResponseTimer!==null&&(clearTimeout(this.slowResponseTimer),this.slowResponseTimer=null),this.state.isSlowResponse&&this.setState({isSlowResponse:!1})}setState(e){this.state={...this.state,...e};for(let e of this.listeners)e(this.state)}async init(){let e=this.config.apiBaseUrl??`https://api.aidenvoice.com`;try{if(this.config.sessionToken)this.sessionToken=this.config.sessionToken;else if(this.config.publishableKey){let{token:t,primaryColor:n,name:r,accentColor:i,inkColor:a}=await at(e,this.config.publishableKey);this.sessionToken=t,this.setState({primaryColor:n,agentName:r,accentColor:i,inkColor:a})}else throw Error(`WidgetConfig must include exactly one of publishableKey or sessionToken`)}catch(e){console.error(`[whoo-aiden-widget] initialization failed:`,e),this.setState({initError:e instanceof Error?e.message:String(e)});return}this.conversationId=vt(this.storageIdentifier),this.config.sessionToken&&await this.loadBranding(e,this.config.sessionToken)}async loadBranding(e,t){try{let n=this.config;if($(n.color)&&$(n.inkColor)&&$(n.accentColor)&&i(n.name))return;let{primaryColor:r,name:a,accentColor:o,inkColor:s}=await st(e,t);this.setState({primaryColor:r,agentName:a,accentColor:o,inkColor:s})}catch{}}open(){this.setState({isOpen:!0})}resetConversation(){this.activeRequestController?.abort(),this.activeRequestController=null,this.clearSlowResponse(),this.conversationId=null,bt(this.storageIdentifier),this.setState({messages:[],messageFeedback:{},runtimeError:null,isStreaming:!1,lastCompletedMessageText:null})}setDraft(e){this.setState({draft:e})}close(){this.activeRequestController?.abort(),this.activeRequestController=null,this.clearSlowResponse(),this.setState({isOpen:!1})}async sendMessage(e){if(!this.sessionToken)return;let t=this.config.apiBaseUrl??`https://api.aidenvoice.com`,n={role:`user`,content:e,id:null},r={role:`assistant`,content:``,id:null};this.setState({messages:[...this.state.messages,n,r],isStreaming:!0,runtimeError:null});let i=e=>{let t=[...this.state.messages];t[t.length-1]={...t[t.length-1],content:e},this.setState({messages:t})};this.activeRequestController=new AbortController;let{signal:a}=this.activeRequestController;this.slowResponseTimer=setTimeout(()=>{this.slowResponseTimer=null,this.setState({isSlowResponse:!0})},zt);let o=()=>{this.setState({runtimeError:`Something went wrong, please try again.`,...this.state.draft===``?{draft:e}:{}})},s=``;try{for await(let n of lt(t,this.sessionToken,this.conversationId,e,a))if(n.type===`conversation_id`)this.conversationId=n.conversationId,yt(this.storageIdentifier,n.conversationId);else if(n.type===`delta`)this.clearSlowResponse(),n.verbatim&&!this.prefersReducedMotion?(await gt(n.delta,e=>i(e),{signal:a}),s=n.delta):n.verbatim?(s=n.delta,i(s)):(s+=n.delta,i(s));else if(n.type===`done`){if(n.conversationId&&(this.conversationId=n.conversationId,yt(this.storageIdentifier,n.conversationId)),n.messageId){let e=[...this.state.messages];e[e.length-1]={...e[e.length-1],id:n.messageId},this.setState({messages:e})}this.setState({lastCompletedMessageText:s})}else if(n.type===`error`){console.error(`[whoo-aiden-widget] chat error:`,n.error),o(),this.activeRequestController?.abort();break}}catch(e){e?.name===`AbortError`||(console.error(`[whoo-aiden-widget] chat request failed:`,e),o())}finally{this.activeRequestController=null,this.clearSlowResponse(),this.setState({isStreaming:!1})}}expandFeedback(e){this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`expanded`}}})}cancelFeedback(e){this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`idle`}}})}async submitFeedback(e,t,n,r){if(!this.sessionToken)return;let i=this.config.apiBaseUrl??`https://api.aidenvoice.com`;this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`submitting`,rating:t}}});try{await ct(i,this.sessionToken,{messageId:e,rating:t,correction:n,category:r}),this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`submitted`,rating:t}}})}catch(n){console.error(`[whoo-aiden-widget] feedback submission failed:`,n),this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`error`,rating:t}}})}}},Vt=`:host,.whoo-widget-root{all:initial;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif}.whoo-widget-launcher{bottom:20px;left:var(--whoo-widget-inset-left,auto);right:var(--whoo-widget-inset-right,20px);background:var(--whoo-widget-color,#4f46e5);width:56px;height:56px;color:var(--whoo-widget-text-on-color,#fff);cursor:pointer;border:none;border-radius:50%;justify-content:center;align-items:center;padding:0;font-size:24px;display:flex;position:fixed;box-shadow:0 2px 8px #0003}.whoo-widget-launcher:focus-visible{box-shadow:0 2px 8px #0003,0 0 0 4px #fff}.whoo-widget-launcher svg{display:block}.whoo-widget-launcher-icon-image{object-fit:cover;border-radius:50%;width:32px;height:32px}.whoo-widget-launcher-icon-image[hidden]{display:none}.whoo-widget-panel{bottom:88px;left:var(--whoo-widget-inset-left,auto);right:var(--whoo-widget-inset-right,20px);background:#fff;border-radius:12px;flex-direction:column;width:360px;max-width:calc(100vw - 40px);height:480px;max-height:calc(100vh - 108px);display:flex;position:fixed;overflow:hidden;box-shadow:0 4px 16px #0003}@media (width<=400px),(height<=420px){.whoo-widget-panel{width:auto;max-width:none;height:auto;max-height:none;inset:8px}}.whoo-widget-header{border-bottom:1px solid #e5e5e5;flex-shrink:0;justify-content:space-between;align-items:center;gap:8px;padding:8px 8px 8px 16px;display:flex}.whoo-widget-header-title{color:var(--whoo-widget-ink,#111);text-overflow:ellipsis;white-space:nowrap;margin:0;font-size:15px;font-weight:600;overflow:hidden}.whoo-widget-header-actions{flex-shrink:0;align-items:center;gap:4px;display:flex}.whoo-widget-header-close,.whoo-widget-header-reset{color:var(--whoo-widget-color-text,#4f46e5);cursor:pointer;background:0 0;border:none;border-radius:6px;justify-content:center;align-items:center;min-width:24px;min-height:24px;padding:4px 8px;font-size:13px;display:inline-flex}.whoo-widget-header-close{width:32px;height:32px;padding:0}.whoo-widget-header-close:hover,.whoo-widget-header-reset:hover{background:#f3f4f6}.whoo-widget-message-list{flex:1;min-height:100px;padding:12px;overflow-y:auto}.whoo-widget-empty-state-image{object-fit:contain;max-width:min(160px,100%);height:auto;max-height:160px;margin:8px auto 16px;display:block}@media (width<=400px),(height<=420px){.whoo-widget-empty-state-image{max-height:64px;margin:0 auto 8px}}.whoo-widget-message{white-space:pre-line;border-radius:8px;max-width:80%;margin-bottom:8px;padding:8px 12px}.whoo-widget-message--user{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);margin-left:auto}.whoo-widget-message--user a{color:inherit}.whoo-widget-message--assistant{color:var(--whoo-widget-ink,#111);background:#f0f0f0}.whoo-widget-message--assistant a{color:var(--whoo-widget-link-color,#00e)}.whoo-widget-pending{flex-wrap:wrap;align-items:center;gap:8px;min-height:1.2em;display:flex}.whoo-widget-typing{align-items:center;gap:4px;display:inline-flex}.whoo-widget-typing span{background:#6b7280;border-radius:50%;width:6px;height:6px;animation:1.2s ease-in-out infinite whoo-widget-typing-bounce}.whoo-widget-typing span:nth-child(2){animation-delay:.2s}.whoo-widget-typing span:nth-child(3){animation-delay:.4s}@keyframes whoo-widget-typing-bounce{0%,80%,to{transform:translateY(0)}40%{transform:translateY(-4px)}}@media (prefers-reduced-motion:reduce){.whoo-widget-typing span{animation:none}}.whoo-widget-error-banner{color:#991b1b;background:#fee2e2;padding:8px 12px;font-size:13px}.whoo-widget-composer{border-top:1px solid #e5e5e5;gap:8px;padding:12px;display:flex}.whoo-widget-composer-input{border:1px solid #6b7280;border-radius:6px;flex:1;padding:8px}.whoo-widget-composer-send{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);cursor:pointer;border:none;border-radius:6px;padding:8px 16px}.whoo-widget-composer-send:disabled,.whoo-widget-composer-input[aria-disabled=true]{opacity:.6;cursor:not-allowed}.whoo-widget-feedback{align-items:center;gap:6px;margin-top:4px;display:flex}.whoo-widget-feedback-buttons{gap:6px;display:flex}.whoo-widget-feedback-buttons button{cursor:pointer;color:#4b5563;background:0 0;border:none;border-radius:4px;justify-content:center;align-items:center;min-width:24px;min-height:24px;padding:4px;display:inline-flex}.whoo-widget-feedback-buttons button:hover:not(:disabled){color:#111;background:#0000000f}.whoo-widget-feedback-buttons button:disabled{opacity:.3;cursor:not-allowed}.whoo-widget-feedback-form{flex-direction:column;gap:6px;margin-top:6px;display:flex}.whoo-widget-feedback-textarea{box-sizing:border-box;resize:vertical;border:1px solid #6b7280;border-radius:6px;width:100%;padding:6px;font-size:12px}.whoo-widget-feedback-select{border:1px solid #6b7280;border-radius:6px;min-height:24px;padding:4px;font-size:12px}.whoo-widget-feedback-form-buttons{gap:6px;display:flex}.whoo-widget-feedback-submit{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);cursor:pointer;border:none;border-radius:6px;padding:8px 16px;font-size:13px}.whoo-widget-feedback-cancel{color:#111;cursor:pointer;background:#fff;border:1px solid #6b7280;border-radius:6px;padding:8px 16px;font-size:13px}.whoo-widget-feedback-submitted{color:#6b7280;margin-top:4px;font-size:12px}.whoo-widget-feedback-error{color:#991b1b;font-size:12px}.whoo-widget-sr-only{clip:rect(0, 0, 0, 0);white-space:nowrap;border:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}button:focus-visible,input:focus-visible,textarea:focus-visible,select:focus-visible,a:focus-visible{outline-offset:2px;outline:2px solid #111827;box-shadow:0 0 0 4px #fff}`;function Ht(e){let t=document.createElement(`div`);t.id=`whoo-aiden-widget-host`,t.style.position=`relative`,t.style.zIndex=String(r(e.zIndex));let n=t.attachShadow({mode:`open`}),i=document.createElement(`style`);i.textContent=Vt,n.appendChild(i);let a=document.createElement(`div`);n.appendChild(a),Rt(a,e);let o=new Bt(e),s=$(e.color)!==null,c=null,l=``;return o.subscribe(t=>{!s&&t.primaryColor&&t.primaryColor!==c&&(c=t.primaryColor,Ft(a,t.primaryColor,e.color));let n=`${t.inkColor}|${t.accentColor}`;(t.inkColor||t.accentColor)&&n!==l&&(l=n,It(a,{inkColor:$(e.inkColor)?e.inkColor:t.inkColor,accentColor:$(e.accentColor)?e.accentColor:t.accentColor}))}),ge(H(it,{controller:o}),a),o.init(),document.body.appendChild(t),{unmount(){ge(null,a),t.remove()}}}function Ut(e){return a(e),Ht(e)}return e.init=Ut,e})({});
|