@aiden-voice/widget 0.5.1 → 0.5.2
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 +48 -14
- package/dist/controller.d.ts +3 -0
- package/dist/sessionToken.d.ts +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/widget.iife.js +6 -6
- package/dist/widget.js +98 -62
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,6 +5,15 @@ install the npm package) and get a working, ready-to-use chat bubble in
|
|
|
5
5
|
the corner of your site, backed entirely by whoo-aiden's public widget API
|
|
6
6
|
— no UI code of your own required.
|
|
7
7
|
|
|
8
|
+
This README is for developers working on the widget. If you are embedding
|
|
9
|
+
the widget on a site, read the public documentation instead, starting with
|
|
10
|
+
[Install the widget](https://docs.aidenvoice.com/widget/install/):
|
|
11
|
+
|
|
12
|
+
- [Configuration reference](https://docs.aidenvoice.com/widget/configuration/)
|
|
13
|
+
- [Connection keys and allowed addresses](https://docs.aidenvoice.com/widget/keys-and-origins/)
|
|
14
|
+
- [Troubleshooting](https://docs.aidenvoice.com/widget/troubleshooting/)
|
|
15
|
+
- [Versions](https://docs.aidenvoice.com/widget/versions/)
|
|
16
|
+
|
|
8
17
|
## Installation
|
|
9
18
|
|
|
10
19
|
### Option 1: CDN `<script>` tag
|
|
@@ -13,7 +22,7 @@ the corner of your site, backed entirely by whoo-aiden's public widget API
|
|
|
13
22
|
<script src="https://widget.aidenvoice.com/v0/widget.iife.js"></script>
|
|
14
23
|
<script>
|
|
15
24
|
window.whooAidenWidget.init({
|
|
16
|
-
publishableKey: '
|
|
25
|
+
publishableKey: 'pk_...',
|
|
17
26
|
})
|
|
18
27
|
</script>
|
|
19
28
|
```
|
|
@@ -28,7 +37,7 @@ pnpm add @aiden-voice/widget
|
|
|
28
37
|
import { init } from '@aiden-voice/widget'
|
|
29
38
|
|
|
30
39
|
init({
|
|
31
|
-
publishableKey: '
|
|
40
|
+
publishableKey: 'pk_...',
|
|
32
41
|
})
|
|
33
42
|
```
|
|
34
43
|
|
|
@@ -41,7 +50,7 @@ two — whether you load the widget via the CDN script tag
|
|
|
41
50
|
|
|
42
51
|
```ts
|
|
43
52
|
init({
|
|
44
|
-
publishableKey: '
|
|
53
|
+
publishableKey: 'pk_...', // OR sessionToken -- exactly one, never both
|
|
45
54
|
// sessionToken: '<jwt from your own backend's identify-session call>',
|
|
46
55
|
position: 'bottom-right', // optional theming, all have defaults
|
|
47
56
|
color: '#4f46e5',
|
|
@@ -345,22 +354,47 @@ checklist run before each release.
|
|
|
345
354
|
|
|
346
355
|
The widget distinguishes two deliberately different error tiers:
|
|
347
356
|
|
|
348
|
-
- **Init/auth failures** (an invalid `publishableKey`, an
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
at all. The failure is logged via
|
|
352
|
-
diagnose it, but nothing partial or
|
|
353
|
-
page.
|
|
357
|
+
- **Init/auth failures** (an invalid `publishableKey`, an Origin not on the
|
|
358
|
+
allowlist, a session-minting quota that is used up, or an expired or refused
|
|
359
|
+
`sessionToken`) are entirely silent to the visitor — no launcher bubble
|
|
360
|
+
renders at all. The failure is logged via
|
|
361
|
+
`console.error` with enough detail to diagnose it, but nothing partial or
|
|
362
|
+
broken-looking ever appears on the page.
|
|
354
363
|
- **Failures once the widget is already visible and in an active chat**
|
|
355
|
-
(a network error, an SSE connection dropping mid-stream,
|
|
356
|
-
|
|
357
|
-
the chat panel itself (e.g.
|
|
358
|
-
|
|
364
|
+
(a network error, an SSE connection dropping mid-stream, an error
|
|
365
|
+
response from the server, a session that runs out while the page is open)
|
|
366
|
+
show a short, non-technical inline message in the chat panel itself (e.g.
|
|
367
|
+
"Something went wrong, please try again"), leaving any partial response
|
|
368
|
+
already rendered in place above it.
|
|
369
|
+
|
|
370
|
+
How a bad `sessionToken` is caught at start-up, without the widget ever
|
|
371
|
+
holding a key to check its signature:
|
|
372
|
+
|
|
373
|
+
- If the token is a JWT whose `exp` has already passed, `init()` treats it as
|
|
374
|
+
an init failure straight away, with no network request. A token the widget
|
|
375
|
+
can't read (not a JWT, no `exp`) is never rejected locally.
|
|
376
|
+
- Otherwise, when the widget looks up the agent's branding with the token
|
|
377
|
+
(see above), a `401` or `403` answer is an init failure too. That lookup is
|
|
378
|
+
skipped when you pass every branding value yourself, so in that case only the
|
|
379
|
+
expiry check applies and a token the server would refuse for another reason
|
|
380
|
+
fails on the visitor's first message instead.
|
|
381
|
+
- Any other branding failure (an older backend without the endpoint, a network
|
|
382
|
+
blip, a `5xx`) stays silent: branding is cosmetic, so the widget keeps your
|
|
383
|
+
values and the defaults.
|
|
384
|
+
|
|
385
|
+
The launcher is not drawn until start-up has finished (the session minted in
|
|
386
|
+
`publishableKey` mode, or the checks above in `sessionToken` mode), so it never
|
|
387
|
+
appears for a session that is about to be refused. The branding lookup is
|
|
388
|
+
waited for at most 3 seconds; if it is slower than that the launcher appears
|
|
389
|
+
anyway, and a `401`/`403` that arrives later still removes it.
|
|
390
|
+
|
|
391
|
+
A malformed `init()` call (both or neither of `publishableKey` and
|
|
392
|
+
`sessionToken`) throws synchronously from `init()` itself.
|
|
359
393
|
|
|
360
394
|
## License
|
|
361
395
|
|
|
362
396
|
Proprietary. This package is licensed only for embedding the Aiden service under
|
|
363
|
-
the applicable Aiden terms of service
|
|
397
|
+
the applicable Aiden terms of service. See `LICENSE.md` in the package.
|
|
364
398
|
|
|
365
399
|
## Local development
|
|
366
400
|
|
package/dist/controller.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { WidgetConfig } from './types';
|
|
2
2
|
export declare const SLOW_RESPONSE_DELAY_MS = 8000;
|
|
3
|
+
export declare const BRANDING_LOOKUP_WAIT_MS = 3000;
|
|
3
4
|
export interface Message {
|
|
4
5
|
role: 'user' | 'assistant';
|
|
5
6
|
content: string;
|
|
@@ -17,6 +18,7 @@ export interface WidgetState {
|
|
|
17
18
|
messages: Message[];
|
|
18
19
|
isStreaming: boolean;
|
|
19
20
|
initError: string | null;
|
|
21
|
+
isInitializing: boolean;
|
|
20
22
|
runtimeError: string | null;
|
|
21
23
|
messageFeedback: Record<string, MessageFeedbackState>;
|
|
22
24
|
primaryColor: string | null;
|
|
@@ -48,6 +50,7 @@ export declare class WidgetController {
|
|
|
48
50
|
private clearSlowResponse;
|
|
49
51
|
private setState;
|
|
50
52
|
init(): Promise<void>;
|
|
53
|
+
private start;
|
|
51
54
|
private loadBranding;
|
|
52
55
|
open(): void;
|
|
53
56
|
resetConversation(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isExpiredSessionToken(token: string, nowMs?: number): boolean;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const WIDGET_VERSION = "0.5.
|
|
1
|
+
export declare const WIDGET_VERSION = "0.5.2";
|
package/dist/widget.iife.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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)}var i=`Aiden`;function a(e){return typeof e==`string`?e.trim():``}function o(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 s,c,l,u,d,f,p,m,h,g,_,v,y,b,x={},S=[],C=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,ee=Array.isArray;function w(e,t){for(var n in t)e[n]=t[n];return e}function te(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function T(e,t,n){var r,i,a,o={};for(a in t)a==`key`?r=t[a]:a==`ref`?i=t[a]:o[a]=t[a];if(arguments.length>2&&(o.children=arguments.length>3?s.call(arguments,2):n),typeof e==`function`&&e.defaultProps!=null)for(a in e.defaultProps)o[a]===void 0&&(o[a]=e.defaultProps[a]);return E(e,o,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??++l,__i:-1,__u:0};return i==null&&c.vnode!=null&&c.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 A(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,r=[],i=[],a=w({},t);a.__v=t.__v+1,c.vnode&&c.vnode(a),le(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,de(r,a,i),t.__e=t.__=null,a.__e!=n&&j(a)}}function j(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}),j(e)}function M(e){(!e.__d&&(e.__d=!0)&&u.push(e)&&!ne.__r++||d!=c.debounceRendering)&&((d=c.debounceRendering)||f)(ne)}function ne(){try{for(var e,t=1;u.length;)u.length>t&&u.sort(p),e=u.shift(),t=u.length,A(e)}finally{u.length=ne.__r=0}}function re(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,m,h,g,_=r&&r.__k||S,v=t.length;for(c=ie(n,t,_,c,v),d=0;d<v;d++)(p=n.__k[d])!=null&&(f=p.__i!=-1&&_[p.__i]||x,p.__i=d,g=le(e,p,f,i,a,o,s,c,l,u),m=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&me(f.ref,null,p),u.push(p.ref,p.__c||m,p)),h==null&&m!=null&&(h=m),4&p.__u?(c=ae(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 ie(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):ee(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=oe(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)),he(s,s));return r}function ae(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=ae(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 oe(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 se(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||C.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||se(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||se(e.style,t,n[t])}}else if(t[0]==`o`&&t[1]==`n`)a=t!=(t=t.replace(_,`$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[g]=r[g]:(n[g]=v,e.addEventListener(t,a?b:y,a)):e.removeEventListener(t,a?b:y,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 ce(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t[h]==null)t[h]=v++;else if(t[h]<n[g])return;return n(c.event?c.event(t):t)}}}function le(e,t,n,r,i,a,o,s,l,u){var d,f,p,m,h,g,_,v,y,b,x,C,T,E,A,j,M=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(l=!!(32&n.__u),a=[s=t.__e=n.__e]),(d=c.__b)&&d(t);n:if(typeof M==`function`){f=o.length;try{if(y=t.props,b=M.prototype&&M.prototype.render,x=(d=M.contextType)&&r[d.__c],C=d?x?x.props.value:d.__:r,n.__c?v=(p=t.__c=n.__c).__=p.__E:(b?t.__c=p=new M(y,C):(t.__c=p=new O(y,C),p.constructor=M,p.render=ge),x&&x.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,C),t.__v==n.__v||!p.__e&&p.shouldComponentUpdate!=null&&!1===p.shouldComponentUpdate(y,p.__s,C)){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)}),S.push.apply(p.__h,p._sb),p._sb=[],p.__h.length&&o.push(p),s=k(n);break n}p.componentWillUpdate!=null&&p.componentWillUpdate(y,p.__s,C),b&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(h,g,_)})}if(p.context=C,p.props=y,p.__P=e,p.__e=!1,T=c.__r,E=0,b)p.state=p.__s,p.__d=!1,T&&T(t),d=p.render(p.props,p.state,p.context),S.push.apply(p.__h,p._sb),p._sb=[];else do p.__d=!1,T&&T(t),d=p.render(p.props,p.state,p.context),p.state=p.__s;while(p.__d&&++E<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?fe(d.props.children):d,s=re(e,ee(A)?A:[A],t,n,r,i,a,o,s,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;s&&s.nodeType==8&&s.nextSibling;)s=s.nextSibling;a!=null&&(a[a.indexOf(s)]=null),t.__e=s}else if(a!=null)for(j=a.length;j--;)te(a[j])}else t.__e=n.__e;t.__k??=n.__k||[],e.then||ue(t),c.__e(e,t,n)}}else a==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):s=t.__e=pe(n.__e,t,n,r,i,a,o,l,u);return(d=c.diffed)&&d(t),128&t.__u?void 0:s}function ue(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(ue))}function de(e,t,n){for(var r=0;r<n.length;r++)me(n[r],n[++r],n[++r]);c.__c&&c.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){c.__e(e,t.__v)}})}function fe(e){return typeof e!=`object`||!e||e.__b>0?e:ee(e)?e.map(fe):e.constructor===void 0?w({},e):null}function pe(e,t,n,r,i,a,o,l,u){var d,f,p,m,h,g,_,v=n.props||x,y=t.props,b=t.type;if(b==`svg`?i=`http://www.w3.org/2000/svg`:b==`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==!!b&&(b?h.localName==b:h.nodeType==3)){e=h,a[d]=null;break}}if(e==null){if(b==null)return document.createTextNode(y);e=document.createElementNS(i,b,y.is&&y),l&&=(c.__m&&c.__m(t,a),!1),a=null}if(b==null)v===y||l&&e.data==y||(e.data=y);else{if(a=b==`textarea`&&y.defaultValue!=null?null:a&&s.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=``),re(t.type==`template`?e.content:e,ee(m)?m:[m],t,n,r,b==`foreignObject`?`http://www.w3.org/1999/xhtml`:i,a,o,a?a[0]:n.__k&&k(n,0),l,u),a!=null)for(d=a.length;d--;)te(a[d]);l&&b!=`textarea`||(d=`value`,b==`progress`&&g==null?e.removeAttribute(`value`):g!=null&&(g!==e[d]||b==`progress`&&!g||b==`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 me(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){c.__e(e,n)}}function he(e,t,n){var r,i;if(c.unmount&&c.unmount(e),(r=e.ref)&&(r.current&&r.current!=e.__e||me(r,null,t)),(r=e.__c)!=null){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(e){c.__e(e,t)}r.base=r.__P=r.__n=null}if(r=e.__k)for(i=0;i<r.length;i++)r[i]&&he(r[i],t,n||typeof e.type!=`function`);n||te(e.__e),e.__c=e.__=e.__e=void 0}function ge(e,t,n){return this.constructor(e,n)}function _e(e,t,n){var r,i,a,o;t==document&&(t=document.documentElement),c.__&&c.__(e,t),i=(r=typeof n==`function`)?null:n&&n.__k||t.__k,a=[],o=[],le(t,e=(!r&&n||t).__k=T(D,null,[e]),i||x,x,t.namespaceURI,!r&&n?[n]:i?null:t.firstChild?s.call(t.childNodes):null,a,!r&&n?n:i?i.__e:t.firstChild,r,o),de(a,e,o),e.props.children=null}s=S.slice,c={__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}},l=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),M(this))},O.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),M(this))},O.prototype.render=D,u=[],f=typeof Promise==`function`?Promise.prototype.then.bind(Promise.resolve()):setTimeout,p=function(e,t){return e.__v.__b-t.__v.__b},ne.__r=0,m=Math.random().toString(8),h=`__d`+m,g=`__a`+m,_=/(PointerCapture)$|Capture$/i,v=0,y=ce(!1),b=ce(!0);var P,F,ve,ye,I=0,be=[],L=c,xe=L.__b,Se=L.__r,Ce=L.diffed,we=L.__c,Te=L.unmount,Ee=L.__;function De(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 Oe(e){return I=1,ke(Ie,e)}function ke(e,t,n){var r=De(P++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Ie(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 R(e,t){var n=De(P++,3);!L.__s&&Fe(n.__H,t)&&(n.__=e,n.u=t,F.__H.__h.push(n))}function z(e){return I=5,Ae(function(){return{current:e}},[])}function Ae(e,t){var n=De(P++,7);return Fe(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function je(){for(var e;e=be.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(B),t.__h.some(Pe),t.__h=[]}catch(n){t.__h=[],L.__e(n,e.__v)}}}L.__b=function(e){F=null,xe&&xe(e)},L.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Ee&&Ee(e,t)},L.__r=function(e){Se&&Se(e),P=0;var t=(F=e.__c).__H;t&&(ve===F?(t.__h=[],F.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(B),t.__h.some(Pe),t.__h=[],P=0)),ve=F},L.diffed=function(e){Ce&&Ce(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(be.push(t)!==1&&ye===L.requestAnimationFrame||((ye=L.requestAnimationFrame)||Ne)(je)),t.__H.__.some(function(e){e.u&&=(e.__H=e.u,void 0)})),ve=F=null},L.__c=function(e,t){t.some(function(e){try{e.__h.some(B),e.__h=e.__h.filter(function(e){return!e.__||Pe(e)})}catch(n){t.some(function(e){e.__h&&=[]}),t=[],L.__e(n,e.__v)}}),we&&we(e,t)},L.unmount=function(e){Te&&Te(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{B(e)}catch(e){t=e}}),n.__H=void 0,t&&L.__e(t,n.__v))};var Me=typeof requestAnimationFrame==`function`;function Ne(e){var t,n=function(){clearTimeout(r),Me&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);Me&&(t=requestAnimationFrame(n))}function B(e){var t=F,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),F=t}function Pe(e){var t=F;e.__c=e.__(),F=t}function Fe(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function Ie(e,t){return typeof t==`function`?t(e):t}var Le=0;Array.isArray;function V(e,t,n,r,i,a){t||={};var o,s,l=t;if(`ref`in l)for(s in l={},t)s==`ref`?o=t[s]:l[s]=t[s];var u={type:e,props:l,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Le,__i:-1,__u:0,__source:i,__self:a};if(typeof e==`function`&&(o=e.defaultProps))for(s in o)l[s]===void 0&&(l[s]=o[s]);return c.vnode&&c.vnode(u),u}function H({name:e,size:t,children:n}){return V(`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 Re({size:e=26}){return V(H,{name:`chat`,size:e,children:[V(`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`}),V(`path`,{d:`M8.5 9.5h.01M12 9.5h.01M15.5 9.5h.01`,"stroke-width":`2.5`})]})}function ze({size:e=26}){return V(H,{name:`chevron-down`,size:e,children:V(`path`,{d:`M6 9l6 6 6-6`})})}function Be({size:e=18}){return V(H,{name:`close`,size:e,children:V(`path`,{d:`M6 6l12 12M18 6L6 18`})})}var Ve=`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 He({size:e=16}){return V(H,{name:`thumb-up`,size:e,children:V(`path`,{d:Ve})})}function Ue({size:e=16}){return V(H,{name:`thumb-down`,size:e,children:V(`path`,{d:Ve,transform:`matrix(1 0 0 -1 0 24)`})})}function We({isOpen:e,onClick:t,iconUrl:n,buttonRef:r}){let[i,a]=Oe(`loading`),o=n!==void 0&&i!==`failed`,s=o&&!e&&i===`loaded`;return V(`button`,{type:`button`,class:`whoo-widget-launcher`,onClick:t,"aria-label":e?`Close chat`:`Open chat`,ref:r,children:[e?V(ze,{}):s?null:V(Re,{}),o?V(`img`,{class:`whoo-widget-launcher-icon-image`,src:n,alt:``,referrerpolicy:`no-referrer`,hidden:!s,onLoad:()=>a(`loaded`),onError:()=>a(`failed`)}):null]})}function Ge({value:e,onChange:t,onSend:n,disabled:r,inputRef:i}){return V(`div`,{class:`whoo-widget-composer`,children:[V(`label`,{class:`whoo-widget-sr-only`,for:`whoo-widget-composer-input`,children:`Message`}),V(`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()}}),V(`button`,{type:`button`,class:`whoo-widget-composer-send`,"aria-disabled":r,onClick:()=>{r||n()},children:`Send`})]})}function Ke({message:e}){return V(`div`,{class:`whoo-widget-error-banner`,role:`alert`,children:e})}var U=/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/y,W=/\*\*([^*\s](?:[^*]*[^*\s])?)\*\*/y,G=/(?<![A-Za-z0-9_])_([^_\s](?:[^_]*[^_\s])?)_(?![A-Za-z0-9_])/y,K=/\*([^*\s](?:[^*]*[^*\s])?)\*/y,q=/[ \t]*[*+-][ \t]+/y,qe=/https?:\/\/\S+/y,Je=/[.,;:!?)\]}>]+$/;function J(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)}var i=`Aiden`;function a(e){return typeof e==`string`?e.trim():``}function o(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 s,c,l,u,d,f,p,m,h,g,_,v,y,b,x={},S=[],C=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,w=Array.isArray;function T(e,t){for(var n in t)e[n]=t[n];return e}function ee(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function E(e,t,n){var r,i,a,o={};for(a in t)a==`key`?r=t[a]:a==`ref`?i=t[a]:o[a]=t[a];if(arguments.length>2&&(o.children=arguments.length>3?s.call(arguments,2):n),typeof e==`function`&&e.defaultProps!=null)for(a in e.defaultProps)o[a]===void 0&&(o[a]=e.defaultProps[a]);return D(e,o,r,i,null)}function D(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??++l,__i:-1,__u:0};return i==null&&c.vnode!=null&&c.vnode(a),a}function O(e){return e.children}function k(e,t){this.props=e,this.context=t}function A(e,t){if(t==null)return e.__?A(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`?A(e):null}function j(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,r=[],i=[],a=T({},t);a.__v=t.__v+1,c.vnode&&c.vnode(a),ce(e.__P,a,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,r,n??A(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&&M(a)}}function M(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}),M(e)}function N(e){(!e.__d&&(e.__d=!0)&&u.push(e)&&!P.__r++||d!=c.debounceRendering)&&((d=c.debounceRendering)||f)(P)}function P(){try{for(var e,t=1;u.length;)u.length>t&&u.sort(p),e=u.shift(),t=u.length,j(e)}finally{u.length=P.__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||S,v=t.length;for(c=ne(n,t,_,c,v),d=0;d<v;d++)(p=n.__k[d])!=null&&(f=p.__i!=-1&&_[p.__i]||x,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=re(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 ne(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]=D(null,o,null,null,null):w(o)?o=e.__k[a]=D(O,{children:o},null,null,null):o.constructor===void 0&&o.__b>0?o=e.__k[a]=D(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=ie(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=A(s)),me(s,s));return r}function re(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=re(r[i],t,n));return t}e.__e!=t&&(t&&e.type&&!t.parentNode&&(t=A(e)),t=n.insertBefore(e.__e,t||null));do t&&=t.nextSibling;while(t!=null&&t.nodeType==8);return t}function ie(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 ae(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||C.test(t)?n:n+`px`}function oe(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||ae(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||ae(e.style,t,n[t])}}else if(t[0]==`o`&&t[1]==`n`)a=t!=(t=t.replace(_,`$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[g]=r[g]:(n[g]=v,e.addEventListener(t,a?b:y,a)):e.removeEventListener(t,a?b:y,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[h]==null)t[h]=v++;else if(t[h]<n[g])return;return n(c.event?c.event(t):t)}}}function ce(e,t,n,r,i,a,o,s,l,u){var d,f,p,m,h,g,_,v,y,b,x,C,E,D,j,M,N=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(l=!!(32&n.__u),a=[s=t.__e=n.__e]),(d=c.__b)&&d(t);n:if(typeof N==`function`){f=o.length;try{if(y=t.props,b=N.prototype&&N.prototype.render,x=(d=N.contextType)&&r[d.__c],C=d?x?x.props.value:d.__:r,n.__c?v=(p=t.__c=n.__c).__=p.__E:(b?t.__c=p=new N(y,C):(t.__c=p=new k(y,C),p.constructor=N,p.render=he),x&&x.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&&N.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=T({},p.__s)),T(p.__s,N.getDerivedStateFromProps(y,p.__s))),h=p.props,g=p.state,p.__v=t,m)b&&N.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),b&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(b&&N.getDerivedStateFromProps==null&&y!==h&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(y,C),t.__v==n.__v||!p.__e&&p.shouldComponentUpdate!=null&&!1===p.shouldComponentUpdate(y,p.__s,C)){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)}),S.push.apply(p.__h,p._sb),p._sb=[],p.__h.length&&o.push(p),s=A(n);break n}p.componentWillUpdate!=null&&p.componentWillUpdate(y,p.__s,C),b&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(h,g,_)})}if(p.context=C,p.props=y,p.__P=e,p.__e=!1,E=c.__r,D=0,b)p.state=p.__s,p.__d=!1,E&&E(t),d=p.render(p.props,p.state,p.context),S.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&&++D<25);p.state=p.__s,p.getChildContext!=null&&(r=T(T({},r),p.getChildContext())),b&&!m&&p.getSnapshotBeforeUpdate!=null&&(_=p.getSnapshotBeforeUpdate(h,g)),j=d!=null&&d.type===O&&d.key==null?de(d.props.children):d,s=te(e,w(j)?j:[j],t,n,r,i,a,o,s,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;s&&s.nodeType==8&&s.nextSibling;)s=s.nextSibling;a!=null&&(a[a.indexOf(s)]=null),t.__e=s}else if(a!=null)for(M=a.length;M--;)ee(a[M])}else t.__e=n.__e;t.__k??=n.__k||[],e.then||le(t),c.__e(e,t,n)}}else a==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):s=t.__e=fe(n.__e,t,n,r,i,a,o,l,u);return(d=c.diffed)&&d(t),128&t.__u?void 0:s}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]);c.__c&&c.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){c.__e(e,t.__v)}})}function de(e){return typeof e!=`object`||!e||e.__b>0?e:w(e)?e.map(de):e.constructor===void 0?T({},e):null}function fe(e,t,n,r,i,a,o,l,u){var d,f,p,m,h,g,_,v=n.props||x,y=t.props,b=t.type;if(b==`svg`?i=`http://www.w3.org/2000/svg`:b==`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==!!b&&(b?h.localName==b:h.nodeType==3)){e=h,a[d]=null;break}}if(e==null){if(b==null)return document.createTextNode(y);e=document.createElementNS(i,b,y.is&&y),l&&=(c.__m&&c.__m(t,a),!1),a=null}if(b==null)v===y||l&&e.data==y||(e.data=y);else{if(a=b==`textarea`&&y.defaultValue!=null?null:a&&s.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||oe(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||oe(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,w(m)?m:[m],t,n,r,b==`foreignObject`?`http://www.w3.org/1999/xhtml`:i,a,o,a?a[0]:n.__k&&A(n,0),l,u),a!=null)for(d=a.length;d--;)ee(a[d]);l&&b!=`textarea`||(d=`value`,b==`progress`&&g==null?e.removeAttribute(`value`):g!=null&&(g!==e[d]||b==`progress`&&!g||b==`option`&&g!=v[d])&&oe(e,d,g,v[d],i),d=`checked`,_!=null&&_!=e[d]&&oe(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){c.__e(e,n)}}function me(e,t,n){var r,i;if(c.unmount&&c.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){c.__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,o;t==document&&(t=document.documentElement),c.__&&c.__(e,t),i=(r=typeof n==`function`)?null:n&&n.__k||t.__k,a=[],o=[],ce(t,e=(!r&&n||t).__k=E(O,null,[e]),i||x,x,t.namespaceURI,!r&&n?[n]:i?null:t.firstChild?s.call(t.childNodes):null,a,!r&&n?n:i?i.__e:t.firstChild,r,o),ue(a,e,o),e.props.children=null}s=S.slice,c={__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}},l=0,k.prototype.setState=function(e,t){var n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=T({},this.state);typeof e==`function`&&(e=e(T({},n),this.props)),e&&T(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),N(this))},k.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),N(this))},k.prototype.render=O,u=[],f=typeof Promise==`function`?Promise.prototype.then.bind(Promise.resolve()):setTimeout,p=function(e,t){return e.__v.__b-t.__v.__b},P.__r=0,m=Math.random().toString(8),h=`__d`+m,g=`__a`+m,_=/(PointerCapture)$|Capture$/i,v=0,y=se(!1),b=se(!0);var F,I,_e,ve,L=0,ye=[],R=c,be=R.__b,xe=R.__r,Se=R.diffed,Ce=R.__c,we=R.unmount,Te=R.__;function Ee(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 De(e){return L=1,Oe(Fe,e)}function Oe(e,t,n){var r=Ee(F++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Fe(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 z(e,t){var n=Ee(F++,3);!R.__s&&Pe(n.__H,t)&&(n.__=e,n.u=t,I.__H.__h.push(n))}function B(e){return L=5,ke(function(){return{current:e}},[])}function ke(e,t){var n=Ee(F++,7);return Pe(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function Ae(){for(var e;e=ye.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(V),t.__h.some(Ne),t.__h=[]}catch(n){t.__h=[],R.__e(n,e.__v)}}}R.__b=function(e){I=null,be&&be(e)},R.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Te&&Te(e,t)},R.__r=function(e){xe&&xe(e),F=0;var t=(I=e.__c).__H;t&&(_e===I?(t.__h=[],I.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(V),t.__h.some(Ne),t.__h=[],F=0)),_e=I},R.diffed=function(e){Se&&Se(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(ye.push(t)!==1&&ve===R.requestAnimationFrame||((ve=R.requestAnimationFrame)||Me)(Ae)),t.__H.__.some(function(e){e.u&&=(e.__H=e.u,void 0)})),_e=I=null},R.__c=function(e,t){t.some(function(e){try{e.__h.some(V),e.__h=e.__h.filter(function(e){return!e.__||Ne(e)})}catch(n){t.some(function(e){e.__h&&=[]}),t=[],R.__e(n,e.__v)}}),Ce&&Ce(e,t)},R.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&&R.__e(t,n.__v))};var je=typeof requestAnimationFrame==`function`;function Me(e){var t,n=function(){clearTimeout(r),je&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);je&&(t=requestAnimationFrame(n))}function V(e){var t=I,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),I=t}function Ne(e){var t=I;e.__c=e.__(),I=t}function Pe(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function Fe(e,t){return typeof t==`function`?t(e):t}var Ie=0;Array.isArray;function H(e,t,n,r,i,a){t||={};var o,s,l=t;if(`ref`in l)for(s in l={},t)s==`ref`?o=t[s]:l[s]=t[s];var u={type:e,props:l,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Ie,__i:-1,__u:0,__source:i,__self:a};if(typeof e==`function`&&(o=e.defaultProps))for(s in o)l[s]===void 0&&(l[s]=o[s]);return c.vnode&&c.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 Le({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 Re({size:e=26}){return H(U,{name:`chevron-down`,size:e,children:H(`path`,{d:`M6 9l6 6 6-6`})})}function ze({size:e=18}){return H(U,{name:`close`,size:e,children:H(`path`,{d:`M6 6l12 12M18 6L6 18`})})}var Be=`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 Ve({size:e=16}){return H(U,{name:`thumb-up`,size:e,children:H(`path`,{d:Be})})}function He({size:e=16}){return H(U,{name:`thumb-down`,size:e,children:H(`path`,{d:Be,transform:`matrix(1 0 0 -1 0 24)`})})}function Ue({isOpen:e,onClick:t,iconUrl:n,buttonRef:r}){let[i,a]=De(`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(Re,{}):s?null:H(Le,{}),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 We({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`,"aria-disabled":r,onClick:()=>{r||n()},children:`Send`})]})}function Ge({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,Ke=/https?:\/\/\S+/y,qe=/[.,;:!?)\]}>]+$/;function Y(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}Ke.lastIndex=n;let c=Ke.exec(e);if(c){let e=c[0].match(qe),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}var Je=/^[ \t]*[*+-][ \t]+(.*)$/;function Ye(e){let t=[],n=[],r=[],i=()=>{n.length>0&&t.push({type:`text`,text:n.join(`
|
|
3
3
|
`)}),n=[]},a=()=>{r.length>0&&t.push({type:`list`,items:r}),r=[]};for(let t of e.split(`
|
|
4
|
-
`)){let e=t.match(
|
|
5
|
-
`),n=
|
|
4
|
+
`)){let e=t.match(Je);e?(i(),r.push(e[1])):(a(),n.push(t))}return i(),a(),t.some(e=>e.type===`list`)?t.flatMap((e,n)=>{if(e.type===`list`)return[e];let{text:r}=e;return t[n-1]?.type===`list`&&(r=r.replace(/^(?:[ \t]*\n)+/,``)),t[n+1]?.type===`list`&&(r=r.replace(/(?:\n[ \t]*)+$/,``)),r.trim()===``?[]:[{type:`text`,text:r}]}):null}function X(e){return Y(e).map((e,t)=>{switch(e.type){case`bold`:return H(`strong`,{children:X(e.value)},t);case`italic`:return H(`em`,{children:X(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}})}function Xe(e){let t=e.replace(/\r\n?/g,`
|
|
5
|
+
`),n=Ye(t);return n?n.map((e,t)=>e.type===`list`?H(`ul`,{class:`whoo-widget-list`,children:e.items.map((e,t)=>H(`li`,{children:X(e)},t))},t):H(`span`,{children:X(e.text)},t)):X(t)}var Ze=[{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 Qe({state:e,containerRef:t,onThumbsUp:n,onThumbsDown:r,onDraftChange:i,onSubmitDetailed:a,onCancel:o}){let s=e.correction??``,c=e.category??``,l=B(e.status);if(z(()=>{let n=l.current;if(l.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===`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:s,onInput:e=>i(e.target.value,c),placeholder:`What was wrong? (optional)`})]}),H(`select`,{class:`whoo-widget-feedback-select`,"aria-label":`Feedback category`,value:c,onChange:e=>i(s,e.target.value),children:Ze.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:()=>a(s,c),children:`Submit`}),H(`button`,{type:`button`,class:`whoo-widget-feedback-cancel`,onClick:o,children:`Cancel`})]})]});let u=e.status===`submitting`,d=e.status===`submitted`;return H(`div`,{class:`whoo-widget-feedback`,children:[d?null:H(`div`,{class:`whoo-widget-feedback-buttons`,children:[H(`button`,{type:`button`,"aria-label":`Good response`,disabled:u,onClick:n,children:H(Ve,{})}),H(`button`,{type:`button`,"aria-label":`Bad response`,disabled:u,onClick:r,children:H(He,{})})]}),H(`div`,{role:`status`,class:d?`whoo-widget-feedback-submitted`:e.status===`error`?`whoo-widget-feedback-error`:void 0,children:d?`Thanks for the feedback`:e.status===`error`?`Couldn't send feedback`:null})]})}function $e({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 et({url:e,alt:t}){let[n,r]=De(!1);return n?null:H(`img`,{class:`whoo-widget-empty-state-image`,src:e,alt:t,referrerpolicy:`no-referrer`,onError:()=>r(!0)})}function tt({message:e,speaker:t,feedbackState:n,showFeedback:r,pending:i,isSlowResponse:a,onThumbsUp:o,onThumbsDown:s,onDraftChange:c,onSubmitDetailed:l,onCancelFeedback:u}){let d=B(null),f=e.id;return H(`div`,{ref:d,tabIndex:-1,class:`whoo-widget-message whoo-widget-message--${e.role}`,children:[H(`span`,{class:`whoo-widget-sr-only`,children:[t,`: `]}),i?H($e,{isSlowResponse:a}):Xe(e.content),r&&e.role===`assistant`&&f?H(Qe,{state:n,containerRef:d,onThumbsUp:()=>o(f),onThumbsDown:()=>s(f),onDraftChange:(e,t)=>c(f,e,t),onSubmitDetailed:(e,t)=>l(f,e,t),onCancel:()=>u(f)}):null]})}function nt({messages:e,messageFeedback:t,announcement:n,emptyStateImage:r,agentName:a=i,showFeedback:o=!1,isStreaming:s=!1,isSlowResponse:c=!1,onThumbsUp:l,onThumbsDown:u,onDraftChange:d=()=>{},onSubmitDetailed:f,onCancelFeedback:p}){let m=B(null);return z(()=>{let e=m.current;e&&(e.scrollTop=e.scrollHeight)},[e,c]),H(O,{children:[H(`section`,{class:`whoo-widget-message-list`,ref:m,"aria-label":`Conversation`,tabIndex:0,children:[r?H(et,{...r}):null,e.map((n,r)=>H(tt,{message:n,speaker:n.role===`user`?`You`:a,showFeedback:o,feedbackState:n.id?t[n.id]??{status:`idle`}:{status:`idle`},pending:s&&r===e.length-1&&n.role===`assistant`&&n.content===``,isSlowResponse:c,onThumbsUp:l,onThumbsDown:u,onDraftChange:d,onSubmitDetailed:f,onCancelFeedback:p},n.id??r))]}),H(`div`,{class:`whoo-widget-sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:n??``})]})}var rt=`button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])`;function it(e){return Array.from(e.querySelectorAll(rt)).filter(e=>{let t=getComputedStyle(e);return t.display!==`none`&&t.visibility!==`hidden`})}function at({state:e,controller:t,greeting:n}){let r=B(null),i=B(null);z(()=>{i.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=it(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=a(t.config.name)||e.agentName||`Aiden`,l=`Chat with ${c}`,u=e.messages.length===0&&n?[{role:`assistant`,content:n,id:null}]:e.messages,d=t.emptyStateImageUrl,f=e.messages.length===0&&d?{url:d,alt:t.emptyStateImageAlt}:void 0;return H(`div`,{class:`whoo-widget-panel`,role:`dialog`,"aria-modal":`true`,"aria-label":l,ref:r,onKeyDown:o,children:[H(`div`,{class:`whoo-widget-header`,children:[H(`h2`,{class:`whoo-widget-header-title`,children:l}),H(`div`,{class:`whoo-widget-header-actions`,children:[e.messages.length>0&&H(`button`,{type:`button`,class:`whoo-widget-header-reset`,onClick:()=>{t.resetConversation(),i.current?.focus()},children:`New conversation`}),H(`button`,{type:`button`,class:`whoo-widget-header-close`,"aria-label":`Close chat`,onClick:()=>t.close(),children:H(ze,{})})]})]}),H(nt,{messages:u,messageFeedback:e.messageFeedback,announcement:e.announcement,emptyStateImage:f,agentName:c,showFeedback:t.showFeedback,isStreaming:e.isStreaming,isSlowResponse:e.isSlowResponse,onThumbsUp:e=>t.submitFeedback(e,`up`),onThumbsDown:e=>t.expandFeedback(e),onDraftChange:(e,n,r)=>t.setFeedbackDraft(e,n,r),onSubmitDetailed:(e,n,r)=>t.submitFeedback(e,`down`,n||void 0,r||void 0),onCancelFeedback:e=>t.cancelFeedback(e)}),e.runtimeError&&H(Ge,{message:e.runtimeError}),H(We,{value:e.draft,onChange:e=>t.setDraft(e),onSend:s,disabled:e.isStreaming,inputRef:i})]})}function ot({controller:e}){let[t,n]=De(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||t.isInitializing?null:H(O,{children:[H(Ue,{isOpen:t.isOpen,onClick:()=>t.isOpen?e.close():e.open(),iconUrl:e.launcherIconUrl,buttonRef:r}),t.isOpen&&H(at,{state:t,controller:e,greeting:e.config.greeting})]})}var Z=class extends Error{status;constructor(e,t){super(e),this.name=`WidgetApiError`,this.status=t}};function st(e){if(typeof e!=`string`)return null;let t=e.trim();return t===``?null:t}async function ct(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 Z(`Failed to create widget session (${n.status})`,n.status);let r=await n.json();return{token:r.token,...lt(r)}}function lt(e){return{primaryColor:st(e.primary_color),name:st(e.name),accentColor:st(e.accent_color),inkColor:st(e.ink_color)}}async function ut(e,t){let n=await fetch(`${e}/api/v1/widget/branding`,{headers:{Authorization:`Bearer ${t}`}});if(!n.ok)throw new Z(`Failed to load widget branding (${n.status})`,n.status);return lt(await n.json())}async function dt(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 Z(`Feedback submission failed (${r.status})`,r.status)}async function*ft(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 Z(`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(`
|
|
6
6
|
|
|
7
7
|
`);for(;n!==-1;){let e=c.slice(0,n);c=c.slice(n+2);let t=e.split(`
|
|
8
8
|
`).find(e=>e.startsWith(`data: `));t&&(yield pt(JSON.parse(t.slice(6)))),n=c.indexOf(`
|
|
9
9
|
|
|
10
|
-
`)}}}function pt(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 mt(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.`)}}function ht(e){return
|
|
11
|
-
`)).map(e=>{switch(e.type){case`bold`:case`italic`:return ht(e.value);case`link`:return e.text;default:return e.value}}).join(``)}var gt=40,_t=120;function vt(e){let t=[];for(let n of J(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 yt(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 bt(e,t,n){let r=n?.wordIntervalMs??gt,i=n?.tokenIntervalMs??_t,a=n?.signal,o=J(e),s=new Set(o.filter(e=>e.type!==`text`).map(e=>e.end)),c=yt(a),l=``;for(let n of vt(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 xt(e){return`whoo-aiden-widget:conversation:${e}`}function St(e){try{return window.sessionStorage.getItem(xt(e))}catch{return null}}function Ct(e,t){try{window.sessionStorage.setItem(xt(e),t)}catch{}}function wt(e){try{window.sessionStorage.removeItem(xt(e))}catch{}}var Tt=/^(inherit|initial|unset|revert|revert-layer)$|\bcurrentcolor\b|\b(var|env|attr|light-dark)\(/i;function Et(e){if(Tt.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 Dt(e){return Et(e)?.rgb??null}function Q([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 Ot(e,t){let n=Math.max(e,t),r=Math.min(e,t);return(n+.05)/(r+.05)}function kt(e){let t=Dt(e);if(!t)return console.warn(`[whoo-aiden-widget] Could not parse color "${e}" for contrast calculation; defaulting to white text.`),`#ffffff`;let n=Q(t);return Ot(n,Q([0,0,0]))>=Ot(n,Q([255,255,255]))?`#000000`:`#ffffff`}var At=`#4f46e5`,jt=`#ffffff`,Mt=`#f0f0f0`,Nt=`#f3f4f6`,Pt=4.5;function Ft([e,t,n]){return`#${[e,t,n].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}function It(e,t=jt){let n=Dt(e),r=Dt(t);if(!n||!r)return At;let i=Q(r),a=e=>Ot(Q(e),i)>=Pt;if(a(n))return Ft(n);for(let e=.99;e>0;e-=.01){let t=n.map(t=>Math.round(t*e));if(a(t))return Ft(t)}return`#000000`}var Lt=`#111111`,Rt=`#0000ee`;function $(e){if(typeof e!=`string`||!e)return null;let t=Et(e);return t?Ft(t.rgb):null}function zt({color:e,inkColor:t,accentColor:n}){let r=$(e),i=r??At,a=It(i,Nt),o=$(t),s=o?It(o,Mt):Lt,c=$(n),l=c?It(c,Mt):Rt;return{primary:i,textOnPrimary:kt(i),primaryAsText:a,ink:s,link:l,adjusted:{primary:r!==null&&a!==i,ink:o!==null&&s!==o,link:c!==null&&l!==c}}}function Bt(e){return typeof e==`string`?`"${e}"`:`a ${typeof e} value`}function Vt(e,t,n=At){let r=t;$(t)===null&&(console.warn(`[whoo-aiden-widget] Could not use ${Bt(t)} as the theme color; falling back to ${Bt(n)}.`),r=n);let i=zt({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 Ht(e,{inkColor:t,accentColor:n}){let r=zt({inkColor:t,accentColor:n});e.style.setProperty(`--whoo-widget-ink`,r.ink),e.style.setProperty(`--whoo-widget-link-color`,r.link)}function Ut(e,t){e&&$(e)===null&&console.warn(`[whoo-aiden-widget] Could not use ${Bt(e)} as the ${t}; using the default.`)}function Wt(e,t){Vt(e,t.color??At),Ut(t.inkColor,`ink color`),Ut(t.accentColor,`accent color`),Ht(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 Gt=8e3,Kt=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=mt(e.launcherIconUrl,`launcherIconUrl`),this.emptyStateImageUrl=mt(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,announcement: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 ct(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=St(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)&&a(n.name))return;let{primaryColor:r,name:i,accentColor:o,inkColor:s}=await ut(e,t);this.setState({primaryColor:r,agentName:i,accentColor:o,inkColor:s})}catch{}}open(){this.setState({isOpen:!0})}resetConversation(){this.activeRequestController?.abort(),this.activeRequestController=null,this.clearSlowResponse(),this.conversationId=null,wt(this.storageIdentifier),this.setState({messages:[],messageFeedback:{},runtimeError:null,isStreaming:!1,announcement:`Conversation cleared`})}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,announcement: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})},Gt);let o=()=>{this.setState({runtimeError:`Something went wrong, please try again.`,...this.state.draft===``?{draft:e}:{}})},s=``;try{for await(let n of ft(t,this.sessionToken,this.conversationId,e,a))if(n.type===`conversation_id`)this.conversationId=n.conversationId,Ct(this.storageIdentifier,n.conversationId);else if(n.type===`delta`)this.clearSlowResponse(),n.verbatim&&!this.prefersReducedMotion?(await bt(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,Ct(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({announcement:ht(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){let{correction:t,category:n}=this.state.messageFeedback[e]??{};this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`expanded`,correction:t,category:n}}})}setFeedbackDraft(e,t,n){this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{...this.state.messageFeedback[e],correction:t,category:n}}})}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 dt(i,this.sessionToken,{messageId:e,rating:t,correction:n,category:r}),this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`submitted`,rating:t}}})}catch(i){console.error(`[whoo-aiden-widget] feedback submission failed:`,i),this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`error`,rating:t,correction:n,category:r}}})}}},qt=`: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-wrap:wrap;flex-shrink:0;justify-content:space-between;align-items:center;gap:8px;max-height:50%;padding:8px 8px 8px 16px;display:flex;overflow-y:auto}.whoo-widget-header-title{color:var(--whoo-widget-ink,#111);overflow-wrap:anywhere;flex:auto;min-width:0;margin:0;font-size:15px;font-weight:600}.whoo-widget-header-actions{background:#fff;flex-shrink:0;align-items:center;gap:4px;margin-left:auto;display:flex;position:sticky;bottom:0}.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:0;padding:12px;overflow-y:auto}.whoo-widget-message-list:focus-visible{outline-offset:-2px;outline:2px solid #111827;box-shadow:inset 0 0 0 4px #fff}.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{overflow-wrap:anywhere;white-space:pre-line;border-radius:8px;max-width:80%;margin-bottom:8px;padding:8px 12px}.whoo-widget-list{margin:4px 0;padding-left:20px}.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[aria-disabled=true],.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:#4b5563;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}@media (forced-colors:active){.whoo-widget-launcher,.whoo-widget-header-close,.whoo-widget-header-reset,.whoo-widget-composer-send,.whoo-widget-feedback-submit,.whoo-widget-feedback-buttons button{border:1px solid buttontext}.whoo-widget-panel{box-sizing:border-box;border:1px solid canvastext}}`;function Jt(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=qt,n.appendChild(i);let a=document.createElement(`div`);n.appendChild(a),Wt(a,e);let o=new Kt(e),s=$(e.color)!==null,c=null,l=``;return o.subscribe(t=>{!s&&t.primaryColor&&t.primaryColor!==c&&(c=t.primaryColor,Vt(a,t.primaryColor,e.color));let n=`${t.inkColor}|${t.accentColor}`;(t.inkColor||t.accentColor)&&n!==l&&(l=n,Ht(a,{inkColor:$(e.inkColor)?e.inkColor:t.inkColor,accentColor:$(e.accentColor)?e.accentColor:t.accentColor}))}),_e(V(st,{controller:o}),a),o.init(),document.body.appendChild(t),{unmount(){_e(null,a),t.remove()}}}function Yt(e){return o(e),Jt(e)}return e.init=Yt,e})({});
|
|
10
|
+
`)}}}function pt(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 mt(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.`)}}function ht(e){return Y(e.replace(/\r\n?/g,`
|
|
11
|
+
`)).map(e=>{switch(e.type){case`bold`:case`italic`:return ht(e.value);case`link`:return e.text;default:return e.value}}).join(``)}var gt=40,_t=120;function vt(e){let t=[];for(let n of Y(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 yt(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 bt(e,t,n){let r=n?.wordIntervalMs??gt,i=n?.tokenIntervalMs??_t,a=n?.signal,o=Y(e),s=new Set(o.filter(e=>e.type!==`text`).map(e=>e.end)),c=yt(a),l=``;for(let n of vt(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 xt(e,t=Date.now()){let n=e.split(`.`);if(n.length!==3||n.some(e=>e===``))return!1;let r=n[1];try{let e=r.replace(/-/g,`+`).replace(/_/g,`/`),n=JSON.parse(atob(e.padEnd(Math.ceil(e.length/4)*4,`=`)))?.exp;return typeof n==`number`&&Number.isFinite(n)&&n*1e3<=t}catch{return!1}}function St(e){return`whoo-aiden-widget:conversation:${e}`}function Ct(e){try{return window.sessionStorage.getItem(St(e))}catch{return null}}function wt(e,t){try{window.sessionStorage.setItem(St(e),t)}catch{}}function Tt(e){try{window.sessionStorage.removeItem(St(e))}catch{}}var Et=/^(inherit|initial|unset|revert|revert-layer)$|\bcurrentcolor\b|\b(var|env|attr|light-dark)\(/i;function Dt(e){if(Et.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 Ot(e){return Dt(e)?.rgb??null}function Q([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 kt(e,t){let n=Math.max(e,t),r=Math.min(e,t);return(n+.05)/(r+.05)}function At(e){let t=Ot(e);if(!t)return console.warn(`[whoo-aiden-widget] Could not parse color "${e}" for contrast calculation; defaulting to white text.`),`#ffffff`;let n=Q(t);return kt(n,Q([0,0,0]))>=kt(n,Q([255,255,255]))?`#000000`:`#ffffff`}var jt=`#4f46e5`,Mt=`#ffffff`,Nt=`#f0f0f0`,Pt=`#f3f4f6`,Ft=4.5;function It([e,t,n]){return`#${[e,t,n].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}function Lt(e,t=Mt){let n=Ot(e),r=Ot(t);if(!n||!r)return jt;let i=Q(r),a=e=>kt(Q(e),i)>=Ft;if(a(n))return It(n);for(let e=.99;e>0;e-=.01){let t=n.map(t=>Math.round(t*e));if(a(t))return It(t)}return`#000000`}var Rt=`#111111`,zt=`#0000ee`;function $(e){if(typeof e!=`string`||!e)return null;let t=Dt(e);return t?It(t.rgb):null}function Bt({color:e,inkColor:t,accentColor:n}){let r=$(e),i=r??jt,a=Lt(i,Pt),o=$(t),s=o?Lt(o,Nt):Rt,c=$(n),l=c?Lt(c,Nt):zt;return{primary:i,textOnPrimary:At(i),primaryAsText:a,ink:s,link:l,adjusted:{primary:r!==null&&a!==i,ink:o!==null&&s!==o,link:c!==null&&l!==c}}}function Vt(e){return typeof e==`string`?`"${e}"`:`a ${typeof e} value`}function Ht(e,t,n=jt){let r=t;$(t)===null&&(console.warn(`[whoo-aiden-widget] Could not use ${Vt(t)} as the theme color; falling back to ${Vt(n)}.`),r=n);let i=Bt({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 Ut(e,{inkColor:t,accentColor:n}){let r=Bt({inkColor:t,accentColor:n});e.style.setProperty(`--whoo-widget-ink`,r.ink),e.style.setProperty(`--whoo-widget-link-color`,r.link)}function Wt(e,t){e&&$(e)===null&&console.warn(`[whoo-aiden-widget] Could not use ${Vt(e)} as the ${t}; using the default.`)}function Gt(e,t){Ht(e,t.color??jt),Wt(t.inkColor,`ink color`),Wt(t.accentColor,`accent color`),Ut(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 Kt=8e3,qt=3e3;function Jt(e,t){return new Promise(n=>{let r=setTimeout(n,t);e.then(()=>{clearTimeout(r),n()})})}var Yt=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=mt(e.launcherIconUrl,`launcherIconUrl`),this.emptyStateImageUrl=mt(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,isInitializing:!1,runtimeError:null,messageFeedback:{},primaryColor:null,agentName:null,accentColor:null,inkColor:null,announcement: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(){this.setState({isInitializing:!0});try{await this.start()}finally{this.setState({isInitializing:!1})}}async start(){let e=this.config.apiBaseUrl??`https://api.aidenvoice.com`;try{if(this.config.sessionToken){if(xt(this.config.sessionToken))throw Error(`The sessionToken has expired.`);this.sessionToken=this.config.sessionToken}else if(this.config.publishableKey){let{token:t,primaryColor:n,name:r,accentColor:i,inkColor:a}=await ct(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=Ct(this.storageIdentifier),this.config.sessionToken&&await Jt(this.loadBranding(e,this.config.sessionToken),qt)}async loadBranding(e,t){try{let n=this.config;if($(n.color)&&$(n.inkColor)&&$(n.accentColor)&&a(n.name))return;let{primaryColor:r,name:i,accentColor:o,inkColor:s}=await ut(e,t);this.setState({primaryColor:r,agentName:i,accentColor:o,inkColor:s})}catch(e){let t=e?.status;(t===401||t===403)&&(console.error(`[whoo-aiden-widget] initialization failed:`,e),this.setState({initError:e instanceof Error?e.message:String(e)}))}}open(){this.setState({isOpen:!0})}resetConversation(){this.activeRequestController?.abort(),this.activeRequestController=null,this.clearSlowResponse(),this.conversationId=null,Tt(this.storageIdentifier),this.setState({messages:[],messageFeedback:{},runtimeError:null,isStreaming:!1,announcement:`Conversation cleared`})}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,announcement: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})},Kt);let o=()=>{this.setState({runtimeError:`Something went wrong, please try again.`,...this.state.draft===``?{draft:e}:{}})},s=``;try{for await(let n of ft(t,this.sessionToken,this.conversationId,e,a))if(n.type===`conversation_id`)this.conversationId=n.conversationId,wt(this.storageIdentifier,n.conversationId);else if(n.type===`delta`)this.clearSlowResponse(),n.verbatim&&!this.prefersReducedMotion?(await bt(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,wt(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({announcement:ht(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){let{correction:t,category:n}=this.state.messageFeedback[e]??{};this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`expanded`,correction:t,category:n}}})}setFeedbackDraft(e,t,n){this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{...this.state.messageFeedback[e],correction:t,category:n}}})}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 dt(i,this.sessionToken,{messageId:e,rating:t,correction:n,category:r}),this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`submitted`,rating:t}}})}catch(i){console.error(`[whoo-aiden-widget] feedback submission failed:`,i),this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`error`,rating:t,correction:n,category:r}}})}}},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-wrap:wrap;flex-shrink:0;justify-content:space-between;align-items:center;gap:8px;max-height:50%;padding:8px 8px 8px 16px;display:flex;overflow-y:auto}.whoo-widget-header-title{color:var(--whoo-widget-ink,#111);overflow-wrap:anywhere;flex:auto;min-width:0;margin:0;font-size:15px;font-weight:600}.whoo-widget-header-actions{background:#fff;flex-shrink:0;align-items:center;gap:4px;margin-left:auto;display:flex;position:sticky;bottom:0}.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:0;padding:12px;overflow-y:auto}.whoo-widget-message-list:focus-visible{outline-offset:-2px;outline:2px solid #111827;box-shadow:inset 0 0 0 4px #fff}.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{overflow-wrap:anywhere;white-space:pre-line;border-radius:8px;max-width:80%;margin-bottom:8px;padding:8px 12px}.whoo-widget-list{margin:4px 0;padding-left:20px}.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[aria-disabled=true],.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:#4b5563;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}@media (forced-colors:active){.whoo-widget-launcher,.whoo-widget-header-close,.whoo-widget-header-reset,.whoo-widget-composer-send,.whoo-widget-feedback-submit,.whoo-widget-feedback-buttons button{border:1px solid buttontext}.whoo-widget-panel{box-sizing:border-box;border:1px solid canvastext}}`;function Zt(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),Gt(a,e);let o=new Yt(e),s=$(e.color)!==null,c=null,l=``;return o.subscribe(t=>{!s&&t.primaryColor&&t.primaryColor!==c&&(c=t.primaryColor,Ht(a,t.primaryColor,e.color));let n=`${t.inkColor}|${t.accentColor}`;(t.inkColor||t.accentColor)&&n!==l&&(l=n,Ut(a,{inkColor:$(e.inkColor)?e.inkColor:t.inkColor,accentColor:$(e.accentColor)?e.accentColor:t.accentColor}))}),o.init(),ge(H(ot,{controller:o}),a),document.body.appendChild(t),{unmount(){ge(null,a),t.remove()}}}function Qt(e){return o(e),Zt(e)}return e.init=Qt,e})({});
|
package/dist/widget.js
CHANGED
|
@@ -977,7 +977,7 @@ function at({ controller: e }) {
|
|
|
977
977
|
let [t, n] = Ee(e.getState()), r = z(null), i = z(t.isOpen);
|
|
978
978
|
return R(() => (n(e.getState()), e.subscribe(n)), [e]), R(() => {
|
|
979
979
|
i.current && !t.isOpen && r.current?.focus(), i.current = t.isOpen;
|
|
980
|
-
}, [t.isOpen]), t.initError ? null : /* @__PURE__ */ V(E, { children: [/* @__PURE__ */ V(He, {
|
|
980
|
+
}, [t.isOpen]), t.initError || t.isInitializing ? null : /* @__PURE__ */ V(E, { children: [/* @__PURE__ */ V(He, {
|
|
981
981
|
isOpen: t.isOpen,
|
|
982
982
|
onClick: () => t.isOpen ? e.close() : e.open(),
|
|
983
983
|
iconUrl: e.launcherIconUrl,
|
|
@@ -1149,32 +1149,45 @@ async function vt(e, t, n) {
|
|
|
1149
1149
|
l !== e && t(e);
|
|
1150
1150
|
}
|
|
1151
1151
|
//#endregion
|
|
1152
|
+
//#region src/sessionToken.ts
|
|
1153
|
+
function yt(e, t = Date.now()) {
|
|
1154
|
+
let n = e.split(".");
|
|
1155
|
+
if (n.length !== 3 || n.some((e) => e === "")) return !1;
|
|
1156
|
+
let r = n[1];
|
|
1157
|
+
try {
|
|
1158
|
+
let e = r.replace(/-/g, "+").replace(/_/g, "/"), n = JSON.parse(atob(e.padEnd(Math.ceil(e.length / 4) * 4, "=")))?.exp;
|
|
1159
|
+
return typeof n == "number" && Number.isFinite(n) && n * 1e3 <= t;
|
|
1160
|
+
} catch {
|
|
1161
|
+
return !1;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
//#endregion
|
|
1152
1165
|
//#region src/storage.ts
|
|
1153
|
-
function
|
|
1166
|
+
function bt(e) {
|
|
1154
1167
|
return `whoo-aiden-widget:conversation:${e}`;
|
|
1155
1168
|
}
|
|
1156
|
-
function
|
|
1169
|
+
function xt(e) {
|
|
1157
1170
|
try {
|
|
1158
|
-
return window.sessionStorage.getItem(
|
|
1171
|
+
return window.sessionStorage.getItem(bt(e));
|
|
1159
1172
|
} catch {
|
|
1160
1173
|
return null;
|
|
1161
1174
|
}
|
|
1162
1175
|
}
|
|
1163
|
-
function
|
|
1176
|
+
function St(e, t) {
|
|
1164
1177
|
try {
|
|
1165
|
-
window.sessionStorage.setItem(
|
|
1178
|
+
window.sessionStorage.setItem(bt(e), t);
|
|
1166
1179
|
} catch {}
|
|
1167
1180
|
}
|
|
1168
|
-
function
|
|
1181
|
+
function Ct(e) {
|
|
1169
1182
|
try {
|
|
1170
|
-
window.sessionStorage.removeItem(
|
|
1183
|
+
window.sessionStorage.removeItem(bt(e));
|
|
1171
1184
|
} catch {}
|
|
1172
1185
|
}
|
|
1173
1186
|
//#endregion
|
|
1174
1187
|
//#region src/theme.ts
|
|
1175
|
-
var
|
|
1176
|
-
function
|
|
1177
|
-
if (
|
|
1188
|
+
var wt = /^(inherit|initial|unset|revert|revert-layer)$|\bcurrentcolor\b|\b(var|env|attr|light-dark)\(/i;
|
|
1189
|
+
function Tt(e) {
|
|
1190
|
+
if (wt.test(e.trim())) return null;
|
|
1178
1191
|
let t = document.createElement("div");
|
|
1179
1192
|
if (t.style.color = e, t.style.color === "") return null;
|
|
1180
1193
|
let n = document.createElement("div");
|
|
@@ -1193,8 +1206,8 @@ function wt(e) {
|
|
|
1193
1206
|
translucent: a < 1
|
|
1194
1207
|
};
|
|
1195
1208
|
}
|
|
1196
|
-
function
|
|
1197
|
-
return
|
|
1209
|
+
function Et(e) {
|
|
1210
|
+
return Tt(e)?.rgb ?? null;
|
|
1198
1211
|
}
|
|
1199
1212
|
function Q([e, t, n]) {
|
|
1200
1213
|
let r = (e) => {
|
|
@@ -1203,54 +1216,54 @@ function Q([e, t, n]) {
|
|
|
1203
1216
|
};
|
|
1204
1217
|
return .2126 * r(e) + .7152 * r(t) + .0722 * r(n);
|
|
1205
1218
|
}
|
|
1206
|
-
function
|
|
1219
|
+
function Dt(e, t) {
|
|
1207
1220
|
let n = Math.max(e, t), r = Math.min(e, t);
|
|
1208
1221
|
return (n + .05) / (r + .05);
|
|
1209
1222
|
}
|
|
1210
|
-
function
|
|
1211
|
-
let t =
|
|
1223
|
+
function Ot(e) {
|
|
1224
|
+
let t = Et(e);
|
|
1212
1225
|
if (!t) return console.warn(`[whoo-aiden-widget] Could not parse color "${e}" for contrast calculation; defaulting to white text.`), "#ffffff";
|
|
1213
1226
|
let n = Q(t);
|
|
1214
|
-
return
|
|
1227
|
+
return Dt(n, Q([
|
|
1215
1228
|
0,
|
|
1216
1229
|
0,
|
|
1217
1230
|
0
|
|
1218
|
-
])) >=
|
|
1231
|
+
])) >= Dt(n, Q([
|
|
1219
1232
|
255,
|
|
1220
1233
|
255,
|
|
1221
1234
|
255
|
|
1222
1235
|
])) ? "#000000" : "#ffffff";
|
|
1223
1236
|
}
|
|
1224
|
-
var
|
|
1225
|
-
function
|
|
1237
|
+
var kt = "#4f46e5", At = "#ffffff", jt = "#f0f0f0", Mt = "#f3f4f6", Nt = 4.5;
|
|
1238
|
+
function Pt([e, t, n]) {
|
|
1226
1239
|
return `#${[
|
|
1227
1240
|
e,
|
|
1228
1241
|
t,
|
|
1229
1242
|
n
|
|
1230
1243
|
].map((e) => e.toString(16).padStart(2, "0")).join("")}`;
|
|
1231
1244
|
}
|
|
1232
|
-
function
|
|
1233
|
-
let n =
|
|
1234
|
-
if (!n || !r) return
|
|
1235
|
-
let i = Q(r), a = (e) =>
|
|
1236
|
-
if (a(n)) return
|
|
1245
|
+
function Ft(e, t = At) {
|
|
1246
|
+
let n = Et(e), r = Et(t);
|
|
1247
|
+
if (!n || !r) return kt;
|
|
1248
|
+
let i = Q(r), a = (e) => Dt(Q(e), i) >= Nt;
|
|
1249
|
+
if (a(n)) return Pt(n);
|
|
1237
1250
|
for (let e = .99; e > 0; e -= .01) {
|
|
1238
1251
|
let t = n.map((t) => Math.round(t * e));
|
|
1239
|
-
if (a(t)) return
|
|
1252
|
+
if (a(t)) return Pt(t);
|
|
1240
1253
|
}
|
|
1241
1254
|
return "#000000";
|
|
1242
1255
|
}
|
|
1243
|
-
var
|
|
1256
|
+
var It = "#111111", Lt = "#0000ee";
|
|
1244
1257
|
function $(e) {
|
|
1245
1258
|
if (typeof e != "string" || !e) return null;
|
|
1246
|
-
let t =
|
|
1247
|
-
return t ?
|
|
1259
|
+
let t = Tt(e);
|
|
1260
|
+
return t ? Pt(t.rgb) : null;
|
|
1248
1261
|
}
|
|
1249
|
-
function
|
|
1250
|
-
let r = $(e), i = r ??
|
|
1262
|
+
function Rt({ color: e, inkColor: t, accentColor: n }) {
|
|
1263
|
+
let r = $(e), i = r ?? kt, a = Ft(i, Mt), o = $(t), s = o ? Ft(o, jt) : It, c = $(n), l = c ? Ft(c, jt) : Lt;
|
|
1251
1264
|
return {
|
|
1252
1265
|
primary: i,
|
|
1253
|
-
textOnPrimary:
|
|
1266
|
+
textOnPrimary: Ot(i),
|
|
1254
1267
|
primaryAsText: a,
|
|
1255
1268
|
ink: s,
|
|
1256
1269
|
link: l,
|
|
@@ -1261,27 +1274,27 @@ function Lt({ color: e, inkColor: t, accentColor: n }) {
|
|
|
1261
1274
|
}
|
|
1262
1275
|
};
|
|
1263
1276
|
}
|
|
1264
|
-
function
|
|
1277
|
+
function zt(e) {
|
|
1265
1278
|
return typeof e == "string" ? `"${e}"` : `a ${typeof e} value`;
|
|
1266
1279
|
}
|
|
1267
|
-
function
|
|
1280
|
+
function Bt(e, t, n = kt) {
|
|
1268
1281
|
let r = t;
|
|
1269
|
-
$(t) === null && (console.warn(`[whoo-aiden-widget] Could not use ${
|
|
1270
|
-
let i =
|
|
1282
|
+
$(t) === null && (console.warn(`[whoo-aiden-widget] Could not use ${zt(t)} as the theme color; falling back to ${zt(n)}.`), r = n);
|
|
1283
|
+
let i = Rt({ color: r });
|
|
1271
1284
|
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);
|
|
1272
1285
|
}
|
|
1273
|
-
function
|
|
1274
|
-
let r =
|
|
1286
|
+
function Vt(e, { inkColor: t, accentColor: n }) {
|
|
1287
|
+
let r = Rt({
|
|
1275
1288
|
inkColor: t,
|
|
1276
1289
|
accentColor: n
|
|
1277
1290
|
});
|
|
1278
1291
|
e.style.setProperty("--whoo-widget-ink", r.ink), e.style.setProperty("--whoo-widget-link-color", r.link);
|
|
1279
1292
|
}
|
|
1280
|
-
function Vt(e, t) {
|
|
1281
|
-
e && $(e) === null && console.warn(`[whoo-aiden-widget] Could not use ${Rt(e)} as the ${t}; using the default.`);
|
|
1282
|
-
}
|
|
1283
1293
|
function Ht(e, t) {
|
|
1284
|
-
|
|
1294
|
+
e && $(e) === null && console.warn(`[whoo-aiden-widget] Could not use ${zt(e)} as the ${t}; using the default.`);
|
|
1295
|
+
}
|
|
1296
|
+
function Ut(e, t) {
|
|
1297
|
+
Bt(e, t.color ?? kt), Ht(t.inkColor, "ink color"), Ht(t.accentColor, "accent color"), Vt(e, {
|
|
1285
1298
|
inkColor: t.inkColor,
|
|
1286
1299
|
accentColor: t.accentColor
|
|
1287
1300
|
});
|
|
@@ -1290,7 +1303,16 @@ function Ht(e, t) {
|
|
|
1290
1303
|
}
|
|
1291
1304
|
//#endregion
|
|
1292
1305
|
//#region src/controller.ts
|
|
1293
|
-
var
|
|
1306
|
+
var Wt = 8e3, Gt = 3e3;
|
|
1307
|
+
function Kt(e, t) {
|
|
1308
|
+
return new Promise((n) => {
|
|
1309
|
+
let r = setTimeout(n, t);
|
|
1310
|
+
e.then(() => {
|
|
1311
|
+
clearTimeout(r), n();
|
|
1312
|
+
});
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
var qt = class {
|
|
1294
1316
|
config;
|
|
1295
1317
|
state;
|
|
1296
1318
|
listeners = /* @__PURE__ */ new Set();
|
|
@@ -1310,6 +1332,7 @@ var Ut = 8e3, Wt = class {
|
|
|
1310
1332
|
messages: [],
|
|
1311
1333
|
isStreaming: !1,
|
|
1312
1334
|
initError: null,
|
|
1335
|
+
isInitializing: !1,
|
|
1313
1336
|
runtimeError: null,
|
|
1314
1337
|
messageFeedback: {},
|
|
1315
1338
|
primaryColor: null,
|
|
@@ -1338,10 +1361,20 @@ var Ut = 8e3, Wt = class {
|
|
|
1338
1361
|
for (let e of this.listeners) e(this.state);
|
|
1339
1362
|
}
|
|
1340
1363
|
async init() {
|
|
1364
|
+
this.setState({ isInitializing: !0 });
|
|
1365
|
+
try {
|
|
1366
|
+
await this.start();
|
|
1367
|
+
} finally {
|
|
1368
|
+
this.setState({ isInitializing: !1 });
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
async start() {
|
|
1341
1372
|
let e = this.config.apiBaseUrl ?? "https://api.aidenvoice.com";
|
|
1342
1373
|
try {
|
|
1343
|
-
if (this.config.sessionToken)
|
|
1344
|
-
|
|
1374
|
+
if (this.config.sessionToken) {
|
|
1375
|
+
if (yt(this.config.sessionToken)) throw Error("The sessionToken has expired.");
|
|
1376
|
+
this.sessionToken = this.config.sessionToken;
|
|
1377
|
+
} else if (this.config.publishableKey) {
|
|
1345
1378
|
let { token: t, primaryColor: n, name: r, accentColor: i, inkColor: a } = await ot(e, this.config.publishableKey);
|
|
1346
1379
|
this.sessionToken = t, this.setState({
|
|
1347
1380
|
primaryColor: n,
|
|
@@ -1354,7 +1387,7 @@ var Ut = 8e3, Wt = class {
|
|
|
1354
1387
|
console.error("[whoo-aiden-widget] initialization failed:", e), this.setState({ initError: e instanceof Error ? e.message : String(e) });
|
|
1355
1388
|
return;
|
|
1356
1389
|
}
|
|
1357
|
-
this.conversationId =
|
|
1390
|
+
this.conversationId = xt(this.storageIdentifier), this.config.sessionToken && await Kt(this.loadBranding(e, this.config.sessionToken), Gt);
|
|
1358
1391
|
}
|
|
1359
1392
|
async loadBranding(e, t) {
|
|
1360
1393
|
try {
|
|
@@ -1367,13 +1400,16 @@ var Ut = 8e3, Wt = class {
|
|
|
1367
1400
|
accentColor: o,
|
|
1368
1401
|
inkColor: s
|
|
1369
1402
|
});
|
|
1370
|
-
} catch {
|
|
1403
|
+
} catch (e) {
|
|
1404
|
+
let t = e?.status;
|
|
1405
|
+
(t === 401 || t === 403) && (console.error("[whoo-aiden-widget] initialization failed:", e), this.setState({ initError: e instanceof Error ? e.message : String(e) }));
|
|
1406
|
+
}
|
|
1371
1407
|
}
|
|
1372
1408
|
open() {
|
|
1373
1409
|
this.setState({ isOpen: !0 });
|
|
1374
1410
|
}
|
|
1375
1411
|
resetConversation() {
|
|
1376
|
-
this.activeRequestController?.abort(), this.activeRequestController = null, this.clearSlowResponse(), this.conversationId = null,
|
|
1412
|
+
this.activeRequestController?.abort(), this.activeRequestController = null, this.clearSlowResponse(), this.conversationId = null, Ct(this.storageIdentifier), this.setState({
|
|
1377
1413
|
messages: [],
|
|
1378
1414
|
messageFeedback: {},
|
|
1379
1415
|
runtimeError: null,
|
|
@@ -1419,7 +1455,7 @@ var Ut = 8e3, Wt = class {
|
|
|
1419
1455
|
let { signal: a } = this.activeRequestController;
|
|
1420
1456
|
this.slowResponseTimer = setTimeout(() => {
|
|
1421
1457
|
this.slowResponseTimer = null, this.setState({ isSlowResponse: !0 });
|
|
1422
|
-
},
|
|
1458
|
+
}, Wt);
|
|
1423
1459
|
let o = () => {
|
|
1424
1460
|
this.setState({
|
|
1425
1461
|
runtimeError: "Something went wrong, please try again.",
|
|
@@ -1427,10 +1463,10 @@ var Ut = 8e3, Wt = class {
|
|
|
1427
1463
|
});
|
|
1428
1464
|
}, s = "";
|
|
1429
1465
|
try {
|
|
1430
|
-
for await (let n of ut(t, this.sessionToken, this.conversationId, e, a)) if (n.type === "conversation_id") this.conversationId = n.conversationId,
|
|
1466
|
+
for await (let n of ut(t, this.sessionToken, this.conversationId, e, a)) if (n.type === "conversation_id") this.conversationId = n.conversationId, St(this.storageIdentifier, n.conversationId);
|
|
1431
1467
|
else if (n.type === "delta") this.clearSlowResponse(), n.verbatim && !this.prefersReducedMotion ? (await vt(n.delta, (e) => i(e), { signal: a }), s = n.delta) : n.verbatim ? (s = n.delta, i(s)) : (s += n.delta, i(s));
|
|
1432
1468
|
else if (n.type === "done") {
|
|
1433
|
-
if (n.conversationId && (this.conversationId = n.conversationId,
|
|
1469
|
+
if (n.conversationId && (this.conversationId = n.conversationId, St(this.storageIdentifier, n.conversationId)), n.messageId) {
|
|
1434
1470
|
let e = [...this.state.messages];
|
|
1435
1471
|
e[e.length - 1] = {
|
|
1436
1472
|
...e[e.length - 1],
|
|
@@ -1510,32 +1546,32 @@ var Ut = 8e3, Wt = class {
|
|
|
1510
1546
|
} });
|
|
1511
1547
|
}
|
|
1512
1548
|
}
|
|
1513
|
-
},
|
|
1549
|
+
}, Jt = ":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-wrap:wrap;flex-shrink:0;justify-content:space-between;align-items:center;gap:8px;max-height:50%;padding:8px 8px 8px 16px;display:flex;overflow-y:auto}.whoo-widget-header-title{color:var(--whoo-widget-ink,#111);overflow-wrap:anywhere;flex:auto;min-width:0;margin:0;font-size:15px;font-weight:600}.whoo-widget-header-actions{background:#fff;flex-shrink:0;align-items:center;gap:4px;margin-left:auto;display:flex;position:sticky;bottom:0}.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:0;padding:12px;overflow-y:auto}.whoo-widget-message-list:focus-visible{outline-offset:-2px;outline:2px solid #111827;box-shadow:inset 0 0 0 4px #fff}.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{overflow-wrap:anywhere;white-space:pre-line;border-radius:8px;max-width:80%;margin-bottom:8px;padding:8px 12px}.whoo-widget-list{margin:4px 0;padding-left:20px}.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[aria-disabled=true],.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:#4b5563;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}@media (forced-colors:active){.whoo-widget-launcher,.whoo-widget-header-close,.whoo-widget-header-reset,.whoo-widget-composer-send,.whoo-widget-feedback-submit,.whoo-widget-feedback-buttons button{border:1px solid buttontext}.whoo-widget-panel{box-sizing:border-box;border:1px solid canvastext}}";
|
|
1514
1550
|
//#endregion
|
|
1515
1551
|
//#region src/mount.tsx
|
|
1516
|
-
function
|
|
1552
|
+
function Yt(e) {
|
|
1517
1553
|
let t = document.createElement("div");
|
|
1518
1554
|
t.id = "whoo-aiden-widget-host", t.style.position = "relative", t.style.zIndex = String(n(e.zIndex));
|
|
1519
1555
|
let r = t.attachShadow({ mode: "open" }), i = document.createElement("style");
|
|
1520
|
-
i.textContent =
|
|
1556
|
+
i.textContent = Jt, r.appendChild(i);
|
|
1521
1557
|
let a = document.createElement("div");
|
|
1522
|
-
r.appendChild(a),
|
|
1523
|
-
let o = new
|
|
1558
|
+
r.appendChild(a), Ut(a, e);
|
|
1559
|
+
let o = new qt(e), s = $(e.color) !== null, c = null, l = "";
|
|
1524
1560
|
return o.subscribe((t) => {
|
|
1525
|
-
!s && t.primaryColor && t.primaryColor !== c && (c = t.primaryColor,
|
|
1561
|
+
!s && t.primaryColor && t.primaryColor !== c && (c = t.primaryColor, Bt(a, t.primaryColor, e.color));
|
|
1526
1562
|
let n = `${t.inkColor}|${t.accentColor}`;
|
|
1527
|
-
(t.inkColor || t.accentColor) && n !== l && (l = n,
|
|
1563
|
+
(t.inkColor || t.accentColor) && n !== l && (l = n, Vt(a, {
|
|
1528
1564
|
inkColor: $(e.inkColor) ? e.inkColor : t.inkColor,
|
|
1529
1565
|
accentColor: $(e.accentColor) ? e.accentColor : t.accentColor
|
|
1530
1566
|
}));
|
|
1531
|
-
}), he(/* @__PURE__ */ V(at, { controller: o }), a),
|
|
1567
|
+
}), o.init(), he(/* @__PURE__ */ V(at, { controller: o }), a), document.body.appendChild(t), { unmount() {
|
|
1532
1568
|
he(null, a), t.remove();
|
|
1533
1569
|
} };
|
|
1534
1570
|
}
|
|
1535
1571
|
//#endregion
|
|
1536
1572
|
//#region src/index.ts
|
|
1537
|
-
function
|
|
1538
|
-
return i(e),
|
|
1573
|
+
function Xt(e) {
|
|
1574
|
+
return i(e), Yt(e);
|
|
1539
1575
|
}
|
|
1540
1576
|
//#endregion
|
|
1541
|
-
export {
|
|
1577
|
+
export { Xt as init, Rt as resolveTheme };
|