@aiden-voice/widget 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -10
- package/dist/api/client.d.ts +6 -2
- package/dist/components/Launcher.d.ts +2 -2
- package/dist/components/MessageList.d.ts +7 -1
- package/dist/controller.d.ts +10 -0
- package/dist/imageUrl.d.ts +1 -0
- package/dist/theme.d.ts +6 -2
- package/dist/types.d.ts +7 -1
- package/dist/version.d.ts +1 -1
- package/dist/widget.iife.js +3 -3
- package/dist/widget.js +402 -309
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -46,7 +46,9 @@ init({
|
|
|
46
46
|
position: 'bottom-right', // optional theming, all have defaults
|
|
47
47
|
color: '#4f46e5',
|
|
48
48
|
greeting: 'Hi! How can we help?',
|
|
49
|
-
|
|
49
|
+
launcherIconUrl: 'https://example.com/icon.png',
|
|
50
|
+
emptyStateImageUrl: 'https://example.com/lockup.png',
|
|
51
|
+
emptyStateImageAlt: 'Example Co.',
|
|
50
52
|
})
|
|
51
53
|
```
|
|
52
54
|
|
|
@@ -61,6 +63,11 @@ init({
|
|
|
61
63
|
short-lived JWT to the page some other way. The widget itself never
|
|
62
64
|
holds, requests, or sees a secret key under any circumstance.
|
|
63
65
|
|
|
66
|
+
Image options accept only `https:` and `data:image/` URLs. Any other
|
|
67
|
+
value (`http:`, relative paths, `javascript:`, `data:text/html`, …) is
|
|
68
|
+
ignored with a `console.warn`, and the widget keeps its default look. Use
|
|
69
|
+
static images: see `docs/accessibility-report.md` §4.
|
|
70
|
+
|
|
64
71
|
`publishableKey` and `sessionToken` are mutually exclusive — `init()`
|
|
65
72
|
throws synchronously, at call time, if you pass both or neither.
|
|
66
73
|
|
|
@@ -72,8 +79,11 @@ throws synchronously, at call time, if you pass both or neither.
|
|
|
72
79
|
| `sessionToken` | A pre-minted session JWT from your own backend. Mutually exclusive with `publishableKey`. | none (required unless `publishableKey` is set) |
|
|
73
80
|
| `position` | Launcher/panel corner: `'bottom-right'` or `'bottom-left'`. | `'bottom-right'` |
|
|
74
81
|
| `color` | Primary accent color (any valid CSS color). | `'#4f46e5'` |
|
|
82
|
+
| `name` | Agent name for the panel header and the dialog's screen-reader label ("Chat with {name}"). In `publishableKey` mode the name configured in whoo-aiden takes precedence; in `sessionToken` mode this is the only source. | `'Aiden'` |
|
|
75
83
|
| `greeting` | Welcome text shown in the panel before the first message. | none |
|
|
76
|
-
| `
|
|
84
|
+
| `launcherIconUrl` | Image shown on the launcher bubble instead of the default chat icon. `https:` or `data:image/` only. Until it loads, and permanently if it fails, the default icon shows. | none (default icon) |
|
|
85
|
+
| `emptyStateImageUrl` | Image (e.g. a brand lockup) shown above the greeting while the conversation is empty. `https:` or `data:image/` only. Removed if it fails to load. | none |
|
|
86
|
+
| `emptyStateImageAlt` | Alt text for `emptyStateImageUrl`. Set it when the image carries meaning (e.g. your brand name); omit it for a purely decorative image. | none (decorative) |
|
|
77
87
|
| `apiBaseUrl` | Override the whoo-aiden API host the widget talks to. | `'https://api.aidenvoice.com'` |
|
|
78
88
|
|
|
79
89
|
## Versions
|
|
@@ -148,9 +158,12 @@ Pushing a `v*` tag runs the workflow. The `cdn` job:
|
|
|
148
158
|
`staticwebapp.config.json` adding one cache route per alias folder
|
|
149
159
|
found in the archive.
|
|
150
160
|
|
|
151
|
-
Once `cdn` succeeds, the `publish` job
|
|
152
|
-
|
|
153
|
-
|
|
161
|
+
Once `cdn` succeeds, the `publish` job downloads the `dist` artifact `cdn`
|
|
162
|
+
built and tested (it installs no project dependencies and does no second
|
|
163
|
+
build) and publishes it to npm as `@aiden-voice/widget` under the dist-tag
|
|
164
|
+
the plan computed: `latest` for the newest stable, `next` for the newest
|
|
165
|
+
prerelease, and `maintenance` for an out-of-order release of either kind
|
|
166
|
+
(see [Versions](#versions)).
|
|
154
167
|
|
|
155
168
|
Publishing uses npm **trusted publishing** (OIDC) — no npm token exists
|
|
156
169
|
for this package at all. The package's Trusted Publisher, configured on
|
|
@@ -158,7 +171,8 @@ npmjs.com, is org `whoo-ai`, repository `whoo-aiden-widget`, workflow
|
|
|
158
171
|
`release.yml`, environment `release` (all four fields are case-sensitive
|
|
159
172
|
and must match exactly). Because trusted publishing needs npm ≥ 11.5.1
|
|
160
173
|
and Node 22 bundles npm 10, the `publish` job upgrades npm
|
|
161
|
-
(`npm install -g npm@
|
|
174
|
+
to a pinned, reviewed 11.x (`npm install -g npm@11.20.0`) immediately
|
|
175
|
+
before publishing. Provenance
|
|
162
176
|
attestations are **not** generated, because the source repository is
|
|
163
177
|
private (provenance requires either a public repo or npm-side allowlisting
|
|
164
178
|
that isn't set up here).
|
|
@@ -249,18 +263,26 @@ screen-reader announcements for streaming replies and errors, and labeled
|
|
|
249
263
|
form controls out of the box. A few things stay the embedding site's
|
|
250
264
|
responsibility:
|
|
251
265
|
|
|
252
|
-
- **Theme color contrast:** for any
|
|
253
|
-
`
|
|
266
|
+
- **Theme color contrast:** for any hex, named (`'yellow'`), `rgb()` or
|
|
267
|
+
`hsl()` color (`oklch()`, `lab()`, `color()` and `color-mix()` aren't
|
|
268
|
+
supported yet and fall back with a warning), the widget automatically picks black
|
|
254
269
|
or white text against whatever `color` (or server-provided
|
|
255
270
|
`primaryColor`) is in effect on button/bubble surfaces, so text stays
|
|
256
|
-
readable there regardless of how light or dark your color is.
|
|
271
|
+
readable there regardless of how light or dark your color is.
|
|
272
|
+
Context-dependent values (`currentColor`, `inherit`, `var(...)`) aren't
|
|
273
|
+
accepted; they, like a malformed color, fall back with a console
|
|
274
|
+
warning (an unusable server color keeps your configured `color`; an
|
|
275
|
+
unusable `color` uses the default theme). Where your
|
|
257
276
|
color is used as text on the panel's white background (the header
|
|
258
277
|
controls), it's used as-is if it already reaches 4.5:1 against white;
|
|
259
278
|
otherwise the widget automatically uses a darker shade of the same hue,
|
|
260
279
|
so a pale brand color will look noticeably darker there. A translucent
|
|
261
280
|
color (`rgba(…, 0.5)`, `#rrggbbaa`) is flattened to how it looks over
|
|
262
281
|
white, since the launcher floats over page content the widget can't
|
|
263
|
-
know.
|
|
282
|
+
know. The other brand colors whoo-aiden detects (ink for body text,
|
|
283
|
+
accent for links in replies) get the same treatment: each is darkened
|
|
284
|
+
just enough to stay readable on the reply bubble. See
|
|
285
|
+
`docs/accessibility-report.md` for details.
|
|
264
286
|
- **Page language:** the widget renders inside your page's DOM and
|
|
265
287
|
inherits language from your document's `<html lang>` attribute; there is
|
|
266
288
|
no separate widget-level locale override.
|
package/dist/api/client.d.ts
CHANGED
|
@@ -2,10 +2,14 @@ export declare class WidgetApiError extends Error {
|
|
|
2
2
|
readonly status?: number;
|
|
3
3
|
constructor(message: string, status?: number);
|
|
4
4
|
}
|
|
5
|
-
export
|
|
5
|
+
export interface MintedSession {
|
|
6
6
|
token: string;
|
|
7
7
|
primaryColor: string | null;
|
|
8
|
-
|
|
8
|
+
name: string | null;
|
|
9
|
+
accentColor: string | null;
|
|
10
|
+
inkColor: string | null;
|
|
11
|
+
}
|
|
12
|
+
export declare function mintSession(apiBaseUrl: string, publishableKey: string): Promise<MintedSession>;
|
|
9
13
|
export declare function submitFeedback(apiBaseUrl: string, sessionToken: string, body: {
|
|
10
14
|
messageId: string;
|
|
11
15
|
rating: 'up' | 'down';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RefObject } from 'preact';
|
|
2
|
-
export declare function Launcher({ isOpen, onClick,
|
|
2
|
+
export declare function Launcher({ isOpen, onClick, iconUrl, buttonRef, }: {
|
|
3
3
|
isOpen: boolean;
|
|
4
4
|
onClick: () => void;
|
|
5
|
-
|
|
5
|
+
iconUrl?: string;
|
|
6
6
|
buttonRef?: RefObject<HTMLButtonElement>;
|
|
7
7
|
}): import("preact").JSX.Element;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { FeedbackCategory, Message, MessageFeedbackState } from '../controller';
|
|
2
|
-
export declare function MessageList({ messages, messageFeedback, lastCompletedMessageText, onThumbsUp, onThumbsDown, onSubmitDetailed, onCancelFeedback, }: {
|
|
2
|
+
export declare function MessageList({ messages, messageFeedback, lastCompletedMessageText, emptyStateImage, isStreaming, isSlowResponse, onThumbsUp, onThumbsDown, onSubmitDetailed, onCancelFeedback, }: {
|
|
3
3
|
messages: Message[];
|
|
4
4
|
messageFeedback: Record<string, MessageFeedbackState>;
|
|
5
5
|
lastCompletedMessageText: string | null;
|
|
6
|
+
emptyStateImage?: {
|
|
7
|
+
url: string;
|
|
8
|
+
alt: string;
|
|
9
|
+
};
|
|
10
|
+
isStreaming?: boolean;
|
|
11
|
+
isSlowResponse?: boolean;
|
|
6
12
|
onThumbsUp: (messageId: string) => void;
|
|
7
13
|
onThumbsDown: (messageId: string) => void;
|
|
8
14
|
onSubmitDetailed: (messageId: string, correction: string, category: '' | FeedbackCategory) => void;
|
package/dist/controller.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WidgetConfig } from './types';
|
|
2
|
+
export declare const SLOW_RESPONSE_DELAY_MS = 8000;
|
|
2
3
|
export interface Message {
|
|
3
4
|
role: 'user' | 'assistant';
|
|
4
5
|
content: string;
|
|
@@ -17,7 +18,11 @@ export interface WidgetState {
|
|
|
17
18
|
runtimeError: string | null;
|
|
18
19
|
messageFeedback: Record<string, MessageFeedbackState>;
|
|
19
20
|
primaryColor: string | null;
|
|
21
|
+
agentName: string | null;
|
|
22
|
+
accentColor: string | null;
|
|
23
|
+
inkColor: string | null;
|
|
20
24
|
lastCompletedMessageText: string | null;
|
|
25
|
+
isSlowResponse: boolean;
|
|
21
26
|
draft: string;
|
|
22
27
|
}
|
|
23
28
|
type Listener = (state: WidgetState) => void;
|
|
@@ -29,10 +34,15 @@ export declare class WidgetController {
|
|
|
29
34
|
private conversationId;
|
|
30
35
|
private readonly storageIdentifier;
|
|
31
36
|
private activeRequestController;
|
|
37
|
+
private slowResponseTimer;
|
|
32
38
|
private readonly prefersReducedMotion;
|
|
39
|
+
readonly launcherIconUrl: string | undefined;
|
|
40
|
+
readonly emptyStateImageUrl: string | undefined;
|
|
41
|
+
readonly emptyStateImageAlt: string;
|
|
33
42
|
constructor(config: WidgetConfig);
|
|
34
43
|
getState(): WidgetState;
|
|
35
44
|
subscribe(listener: Listener): () => void;
|
|
45
|
+
private clearSlowResponse;
|
|
36
46
|
private setState;
|
|
37
47
|
init(): Promise<void>;
|
|
38
48
|
open(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function safeImageUrl(value: unknown, optionName: string): string | undefined;
|
package/dist/theme.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { WidgetConfig } from './types';
|
|
2
2
|
export declare function pickTextColor(cssColor: string): '#000000' | '#ffffff';
|
|
3
3
|
export declare function contrastRatio(cssColorA: string, cssColorB: string): number;
|
|
4
|
-
export declare function textSafeColor(cssColor: string): string;
|
|
5
|
-
export declare function applyThemeColor(root: HTMLElement, color: string): void;
|
|
4
|
+
export declare function textSafeColor(cssColor: string, background?: string): string;
|
|
5
|
+
export declare function applyThemeColor(root: HTMLElement, color: string, fallback?: string): void;
|
|
6
|
+
export declare function applyPalette(root: HTMLElement, { inkColor, accentColor }: {
|
|
7
|
+
inkColor: string | null;
|
|
8
|
+
accentColor: string | null;
|
|
9
|
+
}): void;
|
|
6
10
|
export declare function applyTheme(root: HTMLElement, config: WidgetConfig): void;
|
package/dist/types.d.ts
CHANGED
|
@@ -3,8 +3,14 @@ export interface WidgetConfig {
|
|
|
3
3
|
sessionToken?: string;
|
|
4
4
|
position?: 'bottom-right' | 'bottom-left';
|
|
5
5
|
color?: string;
|
|
6
|
+
name?: string;
|
|
6
7
|
greeting?: string;
|
|
7
|
-
|
|
8
|
+
/** Image shown on the launcher bubble instead of the default chat icon. */
|
|
9
|
+
launcherIconUrl?: string;
|
|
10
|
+
/** Image shown above the greeting while the conversation is empty. */
|
|
11
|
+
emptyStateImageUrl?: string;
|
|
12
|
+
/** Alt text for `emptyStateImageUrl`; omit to treat the image as decorative. */
|
|
13
|
+
emptyStateImageAlt?: string;
|
|
8
14
|
apiBaseUrl?: string;
|
|
9
15
|
}
|
|
10
16
|
export interface WidgetHandle {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const WIDGET_VERSION = "0.
|
|
1
|
+
export declare const WIDGET_VERSION = "0.2.0";
|
package/dist/widget.iife.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var whooAidenWidget=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(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 n,r,i,a,o,s,c,l,u,d,f,p,m,h,g={},_=[],v=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,y=Array.isArray;function b(e,t){for(var n in t)e[n]=t[n];return e}function x(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function S(e,t,r){var i,a,o,s={};for(o in t)o==`key`?i=t[o]:o==`ref`?a=t[o]:s[o]=t[o];if(arguments.length>2&&(s.children=arguments.length>3?n.call(arguments,2):r),typeof e==`function`&&e.defaultProps!=null)for(o in e.defaultProps)s[o]===void 0&&(s[o]=e.defaultProps[o]);return C(e,s,i,a,null)}function C(e,t,n,a,o){var s={type:e,props:t,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:o??++i,__i:-1,__u:0};return o==null&&r.vnode!=null&&r.vnode(s),s}function w(e){return e.children}function T(e,t){this.props=e,this.context=t}function E(e,t){if(t==null)return e.__?E(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`?E(e):null}function D(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,i=[],a=[],o=b({},t);o.__v=t.__v+1,r.vnode&&r.vnode(o),F(e.__P,o,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,i,n??E(t),!!(32&t.__u),a),o.__v=t.__v,o.__.__k[o.__i]=o,ie(i,o,a),t.__e=t.__=null,o.__e!=n&&O(o)}}function O(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}),O(e)}function k(e){(!e.__d&&(e.__d=!0)&&a.push(e)&&!A.__r++||o!=r.debounceRendering)&&((o=r.debounceRendering)||s)(A)}function A(){try{for(var e,t=1;a.length;)a.length>t&&a.sort(c),e=a.shift(),t=a.length,D(e)}finally{a.length=A.__r=0}}function ee(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,m,h,v,y=r&&r.__k||_,b=t.length;for(c=te(n,t,y,c,b),d=0;d<b;d++)(p=n.__k[d])!=null&&(f=p.__i!=-1&&y[p.__i]||g,p.__i=d,v=F(e,p,f,i,a,o,s,c,l,u),m=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&I(f.ref,null,p),u.push(p.ref,p.__c||m,p)),h==null&&m!=null&&(h=m),4&p.__u?(c=j(p,c,e),f.__e&&(f.__e=null)):typeof p.type==`function`&&v!==void 0?c=v:m&&(c=m.nextSibling),p.__u&=-7);return n.__e=h,c}function te(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]=C(null,o,null,null,null):y(o)?o=e.__k[a]=C(w,{children:o},null,null,null):o.constructor===void 0&&o.__b>0?o=e.__k[a]=C(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=M(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=E(s)),se(s,s));return r}function j(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=j(r[i],t,n));return t}e.__e!=t&&(t&&e.type&&!t.parentNode&&(t=E(e)),t=n.insertBefore(e.__e,t||null));do t&&=t.nextSibling;while(t!=null&&t.nodeType==8);return t}function M(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 N(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||v.test(t)?n:n+`px`}function P(e,t,n,r,i){var a,o;n:if(t==`style`){if(typeof n==`string`)e.style.cssText=n;else{if(typeof r==`string`&&(e.style.cssText=r=``),r)for(t in r)n&&t in n||N(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||N(e.style,t,n[t])}}else if(t[0]==`o`&&t[1]==`n`)a=t!=(t=t.replace(f,`$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[d]=r[d]:(n[d]=p,e.addEventListener(t,a?h:m,a)):e.removeEventListener(t,a?h:m,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 ne(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t[u]==null)t[u]=p++;else if(t[u]<n[d])return;return n(r.event?r.event(t):t)}}}function F(e,t,n,i,a,o,s,c,l,u){var d,f,p,m,h,g,v,S,C,D,O,k,A,te,j,M,N=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(l=!!(32&n.__u),o=[c=t.__e=n.__e]),(d=r.__b)&&d(t);n:if(typeof N==`function`){f=s.length;try{if(C=t.props,D=N.prototype&&N.prototype.render,O=(d=N.contextType)&&i[d.__c],k=d?O?O.props.value:d.__:i,n.__c?S=(p=t.__c=n.__c).__=p.__E:(D?t.__c=p=new N(C,k):(t.__c=p=new T(C,k),p.constructor=N,p.render=ce),O&&O.sub(p),p.state||(p.state={}),p.__n=i,m=p.__d=!0,p.__h=[],p._sb=[]),D&&p.__s==null&&(p.__s=p.state),D&&N.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=b({},p.__s)),b(p.__s,N.getDerivedStateFromProps(C,p.__s))),h=p.props,g=p.state,p.__v=t,m)D&&N.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),D&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(D&&N.getDerivedStateFromProps==null&&C!==h&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(C,k),t.__v==n.__v||!p.__e&&p.shouldComponentUpdate!=null&&!1===p.shouldComponentUpdate(C,p.__s,k)){t.__v!=n.__v&&(p.props=C,p.state=p.__s,p.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(e){e&&(e.__=t)}),_.push.apply(p.__h,p._sb),p._sb=[],p.__h.length&&s.push(p),c=E(n);break n}p.componentWillUpdate!=null&&p.componentWillUpdate(C,p.__s,k),D&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(h,g,v)})}if(p.context=k,p.props=C,p.__P=e,p.__e=!1,A=r.__r,te=0,D)p.state=p.__s,p.__d=!1,A&&A(t),d=p.render(p.props,p.state,p.context),_.push.apply(p.__h,p._sb),p._sb=[];else do p.__d=!1,A&&A(t),d=p.render(p.props,p.state,p.context),p.state=p.__s;while(p.__d&&++te<25);p.state=p.__s,p.getChildContext!=null&&(i=b(b({},i),p.getChildContext())),D&&!m&&p.getSnapshotBeforeUpdate!=null&&(v=p.getSnapshotBeforeUpdate(h,g)),j=d!=null&&d.type===w&&d.key==null?ae(d.props.children):d,c=ee(e,y(j)?j:[j],t,n,i,a,o,s,c,l,u),p.base=t.__e,t.__u&=-161,p.__h.length&&s.push(p),S&&(p.__E=p.__=null)}catch(e){if(s.length=f,t.__v=null,l||o!=null){if(e.then){for(t.__u|=l?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;o!=null&&(o[o.indexOf(c)]=null),t.__e=c}else if(o!=null)for(M=o.length;M--;)x(o[M])}else t.__e=n.__e;t.__k??=n.__k||[],e.then||re(t),r.__e(e,t,n)}}else o==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=oe(n.__e,t,n,i,a,o,s,l,u);return(d=r.diffed)&&d(t),128&t.__u?void 0:c}function re(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(re))}function ie(e,t,n){for(var i=0;i<n.length;i++)I(n[i],n[++i],n[++i]);r.__c&&r.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){r.__e(e,t.__v)}})}function ae(e){return typeof e!=`object`||!e||e.__b>0?e:y(e)?e.map(ae):e.constructor===void 0?b({},e):null}function oe(e,t,i,a,o,s,c,l,u){var d,f,p,m,h,_,v,b=i.props||g,S=t.props,C=t.type;if(C==`svg`?o=`http://www.w3.org/2000/svg`:C==`math`?o=`http://www.w3.org/1998/Math/MathML`:o||=`http://www.w3.org/1999/xhtml`,s!=null){for(d=0;d<s.length;d++)if((h=s[d])&&`setAttribute`in h==!!C&&(C?h.localName==C:h.nodeType==3)){e=h,s[d]=null;break}}if(e==null){if(C==null)return document.createTextNode(S);e=document.createElementNS(o,C,S.is&&S),l&&=(r.__m&&r.__m(t,s),!1),s=null}if(C==null)b===S||l&&e.data==S||(e.data=S);else{if(s=C==`textarea`&&S.defaultValue!=null?null:s&&n.call(e.childNodes),!l&&s!=null)for(b={},d=0;d<e.attributes.length;d++)b[(h=e.attributes[d]).name]=h.value;for(d in b)h=b[d],d==`dangerouslySetInnerHTML`?p=h:d==`children`||d in S||d==`value`&&`defaultValue`in S||d==`checked`&&`defaultChecked`in S||P(e,d,null,h,o);for(d in S)h=S[d],d==`children`?m=h:d==`dangerouslySetInnerHTML`?f=h:d==`value`?_=h:d==`checked`?v=h:l&&typeof h!=`function`||b[d]===h||P(e,d,h,b[d],o);if(f)l||p&&(f.__html==p.__html||f.__html==e.innerHTML)||(e.innerHTML=f.__html),t.__k=[];else if(p&&(e.innerHTML=``),ee(t.type==`template`?e.content:e,y(m)?m:[m],t,i,a,C==`foreignObject`?`http://www.w3.org/1999/xhtml`:o,s,c,s?s[0]:i.__k&&E(i,0),l,u),s!=null)for(d=s.length;d--;)x(s[d]);l&&C!=`textarea`||(d=`value`,C==`progress`&&_==null?e.removeAttribute(`value`):_!=null&&(_!==e[d]||C==`progress`&&!_||C==`option`&&_!=b[d])&&P(e,d,_,b[d],o),d=`checked`,v!=null&&v!=e[d]&&P(e,d,v,b[d],o))}return e}function I(e,t,n){try{if(typeof e==`function`){var i=typeof e.__u==`function`;i&&e.__u(),i&&t==null||(e.__u=e(t))}else e.current=t}catch(e){r.__e(e,n)}}function se(e,t,n){var i,a;if(r.unmount&&r.unmount(e),(i=e.ref)&&(i.current&&i.current!=e.__e||I(i,null,t)),(i=e.__c)!=null){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(e){r.__e(e,t)}i.base=i.__P=i.__n=null}if(i=e.__k)for(a=0;a<i.length;a++)i[a]&&se(i[a],t,n||typeof e.type!=`function`);n||x(e.__e),e.__c=e.__=e.__e=void 0}function ce(e,t,n){return this.constructor(e,n)}function le(e,t,i){var a,o,s,c;t==document&&(t=document.documentElement),r.__&&r.__(e,t),o=(a=typeof i==`function`)?null:i&&i.__k||t.__k,s=[],c=[],F(t,e=(!a&&i||t).__k=S(w,null,[e]),o||g,g,t.namespaceURI,!a&&i?[i]:o?null:t.firstChild?n.call(t.childNodes):null,s,!a&&i?i:o?o.__e:t.firstChild,a,c),ie(s,e,c),e.props.children=null}n=_.slice,r={__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}},i=0,T.prototype.setState=function(e,t){var n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=b({},this.state);typeof e==`function`&&(e=e(b({},n),this.props)),e&&b(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),k(this))},T.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),k(this))},T.prototype.render=w,a=[],s=typeof Promise==`function`?Promise.prototype.then.bind(Promise.resolve()):setTimeout,c=function(e,t){return e.__v.__b-t.__v.__b},A.__r=0,l=Math.random().toString(8),u=`__d`+l,d=`__a`+l,f=/(PointerCapture)$|Capture$/i,p=0,m=ne(!1),h=ne(!0);var L,R,ue,de,z=0,fe=[],B=r,pe=B.__b,me=B.__r,he=B.diffed,ge=B.__c,_e=B.unmount,ve=B.__;function V(e,t){B.__h&&B.__h(R,e,z||t),z=0;var n=R.__H||(R.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function H(e){return z=1,ye(Te,e)}function ye(e,t,n){var r=V(L++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Te(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=R,!R.__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};R.__f=!0;var a=R.shouldComponentUpdate,o=R.componentWillUpdate;R.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)},R.shouldComponentUpdate=i}return r.__N||r.__}function U(e,t){var n=V(L++,3);!B.__s&&we(n.__H,t)&&(n.__=e,n.u=t,R.__H.__h.push(n))}function W(e){return z=5,be(function(){return{current:e}},[])}function be(e,t){var n=V(L++,7);return we(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function xe(){for(var e;e=fe.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(G),t.__h.some(K),t.__h=[]}catch(n){t.__h=[],B.__e(n,e.__v)}}}B.__b=function(e){R=null,pe&&pe(e)},B.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ve&&ve(e,t)},B.__r=function(e){me&&me(e),L=0;var t=(R=e.__c).__H;t&&(ue===R?(t.__h=[],R.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(G),t.__h.some(K),t.__h=[],L=0)),ue=R},B.diffed=function(e){he&&he(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(fe.push(t)!==1&&de===B.requestAnimationFrame||((de=B.requestAnimationFrame)||Ce)(xe)),t.__H.__.some(function(e){e.u&&=(e.__H=e.u,void 0)})),ue=R=null},B.__c=function(e,t){t.some(function(e){try{e.__h.some(G),e.__h=e.__h.filter(function(e){return!e.__||K(e)})}catch(n){t.some(function(e){e.__h&&=[]}),t=[],B.__e(n,e.__v)}}),ge&&ge(e,t)},B.unmount=function(e){_e&&_e(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{G(e)}catch(e){t=e}}),n.__H=void 0,t&&B.__e(t,n.__v))};var Se=typeof requestAnimationFrame==`function`;function Ce(e){var t,n=function(){clearTimeout(r),Se&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);Se&&(t=requestAnimationFrame(n))}function G(e){var t=R,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),R=t}function K(e){var t=R;e.__c=e.__(),R=t}function we(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function Te(e,t){return typeof t==`function`?t(e):t}var Ee=0;Array.isArray;function q(e,t,n,i,a,o){t||={};var s,c,l=t;if(`ref`in l)for(c in l={},t)c==`ref`?s=t[c]:l[c]=t[c];var u={type:e,props:l,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Ee,__i:-1,__u:0,__source:a,__self:o};if(typeof e==`function`&&(s=e.defaultProps))for(c in s)l[c]===void 0&&(l[c]=s[c]);return r.vnode&&r.vnode(u),u}function J({name:e,size:t,children:n}){return q(`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 De({size:e=26}){return q(J,{name:`chat`,size:e,children:[q(`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`}),q(`path`,{d:`M8.5 9.5h.01M12 9.5h.01M15.5 9.5h.01`,"stroke-width":`2.5`})]})}function Oe({size:e=26}){return q(J,{name:`chevron-down`,size:e,children:q(`path`,{d:`M6 9l6 6 6-6`})})}function ke({size:e=18}){return q(J,{name:`close`,size:e,children:q(`path`,{d:`M6 6l12 12M18 6L6 18`})})}var Ae=`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 je({size:e=16}){return q(J,{name:`thumb-up`,size:e,children:q(`path`,{d:Ae})})}function Me({size:e=16}){return q(J,{name:`thumb-down`,size:e,children:q(`path`,{d:Ae,transform:`matrix(1 0 0 -1 0 24)`})})}function Ne({isOpen:e,onClick:t,logoUrl:n,buttonRef:r}){return q(`button`,{type:`button`,class:`whoo-widget-launcher`,onClick:t,"aria-label":e?`Close chat`:`Open chat`,ref:r,children:e?q(Oe,{}):n?q(`img`,{class:`whoo-widget-launcher-logo`,src:n,alt:``}):q(De,{})})}function Pe({value:e,onChange:t,onSend:n,disabled:r,inputRef:i}){return q(`div`,{class:`whoo-widget-composer`,children:[q(`label`,{class:`whoo-widget-sr-only`,for:`whoo-widget-composer-input`,children:`Message`}),q(`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()}}),q(`button`,{type:`button`,class:`whoo-widget-composer-send`,onClick:n,disabled:r,children:`Send`})]})}function Fe({message:e}){return q(`div`,{class:`whoo-widget-error-banner`,role:`alert`,children:e})}var Y=/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/y,X=/\*\*([^*]+)\*\*/y,Z=/(?<![A-Za-z0-9_])_([^_\s](?:[^_]*[^_\s])?)_(?![A-Za-z0-9_])/y,Q=/\*([^*]+)\*/y,Ie=/https?:\/\/\S+/y,Le=/[.,;:!?)\]}>]+$/;function Re(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(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]!==`!`){Y.lastIndex=n;let a=Y.exec(e);if(a){i(n),t.push({type:`link`,text:a[1],url:a[2],start:n,end:Y.lastIndex}),n=Y.lastIndex,r=n;continue}}X.lastIndex=n;let a=X.exec(e);if(a){i(n),t.push({type:`bold`,value:a[1],start:n,end:X.lastIndex}),n=X.lastIndex,r=n;continue}Z.lastIndex=n;let o=Z.exec(e);if(o){i(n),t.push({type:`italic`,value:o[1],start:n,end:Z.lastIndex}),n=Z.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}Ie.lastIndex=n;let c=Ie.exec(e);if(c){let e=c[0].match(Le),a=e?c[0].slice(0,c[0].length-e[0].length):c[0];if(a.length>0){i(n),t.push({type:`link`,text:a,url:a,start:n,end:n+a.length}),n+=a.length,r=n;continue}}n+=1}return i(e.length),t}function ze(e){return Re(e).map((e,t)=>{switch(e.type){case`bold`:return q(`strong`,{children:e.value},t);case`italic`:return q(`em`,{children:e.value},t);case`link`:return q(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,children:[e.text,q(`span`,{class:`whoo-widget-sr-only`,children:` (opens in new tab)`})]},t);default:return e.value}})}var Be=[{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 Ve({state:e,containerRef:t,onThumbsUp:n,onThumbsDown:r,onSubmitDetailed:i,onCancel:a}){let[o,s]=H(``),[c,l]=H(``),u=W(e.status);if(U(()=>{let n=u.current;if(u.current=e.status,n===e.status)return;let r=t?.current;if(!r)return;let i=r.getRootNode();r.contains(i.activeElement)||r.focus()},[e.status,t]),e.status===`submitted`)return q(`div`,{class:`whoo-widget-feedback-submitted`,role:`status`,children:`Thanks for the feedback`});if(e.status===`expanded`)return q(`div`,{class:`whoo-widget-feedback-form`,children:[q(`label`,{children:[q(`span`,{class:`whoo-widget-sr-only`,children:`Additional feedback`}),q(`textarea`,{class:`whoo-widget-feedback-textarea`,value:o,onInput:e=>s(e.target.value),placeholder:`What was wrong? (optional)`})]}),q(`select`,{class:`whoo-widget-feedback-select`,"aria-label":`Feedback category`,value:c,onChange:e=>l(e.target.value),children:Be.map(e=>q(`option`,{value:e.value,children:e.label},e.value))}),q(`div`,{class:`whoo-widget-feedback-form-buttons`,children:[q(`button`,{type:`button`,class:`whoo-widget-feedback-submit`,onClick:()=>i(o,c),children:`Submit`}),q(`button`,{type:`button`,class:`whoo-widget-feedback-cancel`,onClick:a,children:`Cancel`})]})]});let d=e.status===`submitting`;return q(`div`,{class:`whoo-widget-feedback`,children:[q(`div`,{class:`whoo-widget-feedback-buttons`,children:[q(`button`,{type:`button`,"aria-label":`Good response`,disabled:d,onClick:n,children:q(je,{})}),q(`button`,{type:`button`,"aria-label":`Bad response`,disabled:d,onClick:r,children:q(Me,{})})]}),e.status===`error`?q(`div`,{class:`whoo-widget-feedback-error`,role:`status`,children:`Couldn't send feedback`}):null]})}function He({message:e,feedbackState:t,onThumbsUp:n,onThumbsDown:r,onSubmitDetailed:i,onCancelFeedback:a}){let o=W(null),s=e.id;return q(`div`,{ref:o,tabIndex:-1,class:`whoo-widget-message whoo-widget-message--${e.role}`,children:[ze(e.content),e.role===`assistant`&&s?q(Ve,{state:t,containerRef:o,onThumbsUp:()=>n(s),onThumbsDown:()=>r(s),onSubmitDetailed:(e,t)=>i(s,e,t),onCancel:()=>a(s)}):null]})}function Ue({messages:e,messageFeedback:t,lastCompletedMessageText:n,onThumbsUp:r,onThumbsDown:i,onSubmitDetailed:a,onCancelFeedback:o}){let s=W(null);return U(()=>{let e=s.current;e&&(e.scrollTop=e.scrollHeight)},[e]),q(w,{children:[q(`div`,{class:`whoo-widget-message-list`,ref:s,children:e.map((e,n)=>q(He,{message:e,feedbackState:e.id?t[e.id]??{status:`idle`}:{status:`idle`},onThumbsUp:r,onThumbsDown:i,onSubmitDetailed:a,onCancelFeedback:o},e.id??n))}),q(`div`,{class:`whoo-widget-sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:n??``})]})}var We=`button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])`;function Ge(e){return Array.from(e.querySelectorAll(We)).filter(e=>{let t=getComputedStyle(e);return t.display!==`none`&&t.visibility!==`hidden`})}function Ke({state:e,controller:t,greeting:n}){let r=W(null),i=W(null);U(()=>{i.current?.focus()},[]);let a=e=>{if(e.key===`Escape`){t.close();return}if(e.key!==`Tab`)return;let n=r.current;if(!n)return;let i=Ge(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())},o=()=>{let n=e.draft.trim();!n||e.isStreaming||(t.setDraft(``),t.sendMessage(n))},s=e.messages.length===0&&n?[{role:`assistant`,content:n,id:null}]:e.messages;return q(`div`,{class:`whoo-widget-panel`,role:`dialog`,"aria-modal":`true`,"aria-label":`Chat with Aiden`,ref:r,onKeyDown:a,children:[q(`div`,{class:`whoo-widget-header`,children:[q(`h2`,{class:`whoo-widget-header-title`,children:`Chat with Aiden`}),q(`div`,{class:`whoo-widget-header-actions`,children:[e.messages.length>0&&q(`button`,{type:`button`,class:`whoo-widget-header-reset`,onClick:()=>t.resetConversation(),children:`New conversation`}),q(`button`,{type:`button`,class:`whoo-widget-header-close`,"aria-label":`Close chat`,onClick:()=>t.close(),children:q(ke,{})})]})]}),q(Ue,{messages:s,messageFeedback:e.messageFeedback,lastCompletedMessageText:e.lastCompletedMessageText,onThumbsUp:e=>t.submitFeedback(e,`up`),onThumbsDown:e=>t.expandFeedback(e),onSubmitDetailed:(e,n,r)=>t.submitFeedback(e,`down`,n||void 0,r||void 0),onCancelFeedback:e=>t.cancelFeedback(e)}),e.runtimeError&&q(Fe,{message:e.runtimeError}),q(Pe,{value:e.draft,onChange:e=>t.setDraft(e),onSend:o,disabled:e.isStreaming,inputRef:i})]})}function qe({controller:e}){let[t,n]=H(e.getState()),r=W(null),i=W(t.isOpen);return U(()=>(n(e.getState()),e.subscribe(n)),[e]),U(()=>{i.current&&!t.isOpen&&r.current?.focus(),i.current=t.isOpen},[t.isOpen]),t.initError?null:q(w,{children:[q(Ne,{isOpen:t.isOpen,onClick:()=>t.isOpen?e.close():e.open(),logoUrl:e.config.logoUrl,buttonRef:r}),t.isOpen&&q(Ke,{state:t,controller:e,greeting:e.config.greeting})]})}var Je=class extends Error{status;constructor(e,t){super(e),this.name=`WidgetApiError`,this.status=t}};async function Ye(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 Je(`Failed to create widget session (${n.status})`,n.status);let r=await n.json();return{token:r.token,primaryColor:r.primary_color??null}}async function Xe(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 Je(`Feedback submission failed (${r.status})`,r.status)}async function*Ze(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 Je(`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(`
|
|
1
|
+
var whooAidenWidget=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(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 n,r,i,a,o,s,c,l,u,d,f,p,m,h,g={},_=[],v=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,y=Array.isArray;function b(e,t){for(var n in t)e[n]=t[n];return e}function ee(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function x(e,t,r){var i,a,o,s={};for(o in t)o==`key`?i=t[o]:o==`ref`?a=t[o]:s[o]=t[o];if(arguments.length>2&&(s.children=arguments.length>3?n.call(arguments,2):r),typeof e==`function`&&e.defaultProps!=null)for(o in e.defaultProps)s[o]===void 0&&(s[o]=e.defaultProps[o]);return S(e,s,i,a,null)}function S(e,t,n,a,o){var s={type:e,props:t,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:o??++i,__i:-1,__u:0};return o==null&&r.vnode!=null&&r.vnode(s),s}function C(e){return e.children}function w(e,t){this.props=e,this.context=t}function T(e,t){if(t==null)return e.__?T(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`?T(e):null}function E(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,i=[],a=[],o=b({},t);o.__v=t.__v+1,r.vnode&&r.vnode(o),ie(e.__P,o,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,i,n??T(t),!!(32&t.__u),a),o.__v=t.__v,o.__.__k[o.__i]=o,oe(i,o,a),t.__e=t.__=null,o.__e!=n&&D(o)}}function D(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}),D(e)}function O(e){(!e.__d&&(e.__d=!0)&&a.push(e)&&!k.__r++||o!=r.debounceRendering)&&((o=r.debounceRendering)||s)(k)}function k(){try{for(var e,t=1;a.length;)a.length>t&&a.sort(c),e=a.shift(),t=a.length,E(e)}finally{a.length=k.__r=0}}function te(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,m,h,v,y=r&&r.__k||_,b=t.length;for(c=ne(n,t,y,c,b),d=0;d<b;d++)(p=n.__k[d])!=null&&(f=p.__i!=-1&&y[p.__i]||g,p.__i=d,v=ie(e,p,f,i,a,o,s,c,l,u),m=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&P(f.ref,null,p),u.push(p.ref,p.__c||m,p)),h==null&&m!=null&&(h=m),4&p.__u?(c=A(p,c,e),f.__e&&(f.__e=null)):typeof p.type==`function`&&v!==void 0?c=v: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]=S(null,o,null,null,null):y(o)?o=e.__k[a]=S(C,{children:o},null,null,null):o.constructor===void 0&&o.__b>0?o=e.__k[a]=S(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=j(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=T(s)),le(s,s));return r}function A(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=A(r[i],t,n));return t}e.__e!=t&&(t&&e.type&&!t.parentNode&&(t=T(e)),t=n.insertBefore(e.__e,t||null));do t&&=t.nextSibling;while(t!=null&&t.nodeType==8);return t}function j(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 M(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||v.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||M(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||M(e.style,t,n[t])}}else if(t[0]==`o`&&t[1]==`n`)a=t!=(t=t.replace(f,`$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[d]=r[d]:(n[d]=p,e.addEventListener(t,a?h:m,a)):e.removeEventListener(t,a?h:m,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 re(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t[u]==null)t[u]=p++;else if(t[u]<n[d])return;return n(r.event?r.event(t):t)}}}function ie(e,t,n,i,a,o,s,c,l,u){var d,f,p,m,h,g,v,x,S,E,D,O,k,ne,A,j,M=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(l=!!(32&n.__u),o=[c=t.__e=n.__e]),(d=r.__b)&&d(t);n:if(typeof M==`function`){f=s.length;try{if(S=t.props,E=M.prototype&&M.prototype.render,D=(d=M.contextType)&&i[d.__c],O=d?D?D.props.value:d.__:i,n.__c?x=(p=t.__c=n.__c).__=p.__E:(E?t.__c=p=new M(S,O):(t.__c=p=new w(S,O),p.constructor=M,p.render=ue),D&&D.sub(p),p.state||(p.state={}),p.__n=i,m=p.__d=!0,p.__h=[],p._sb=[]),E&&p.__s==null&&(p.__s=p.state),E&&M.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=b({},p.__s)),b(p.__s,M.getDerivedStateFromProps(S,p.__s))),h=p.props,g=p.state,p.__v=t,m)E&&M.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),E&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(E&&M.getDerivedStateFromProps==null&&S!==h&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(S,O),t.__v==n.__v||!p.__e&&p.shouldComponentUpdate!=null&&!1===p.shouldComponentUpdate(S,p.__s,O)){t.__v!=n.__v&&(p.props=S,p.state=p.__s,p.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(e){e&&(e.__=t)}),_.push.apply(p.__h,p._sb),p._sb=[],p.__h.length&&s.push(p),c=T(n);break n}p.componentWillUpdate!=null&&p.componentWillUpdate(S,p.__s,O),E&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(h,g,v)})}if(p.context=O,p.props=S,p.__P=e,p.__e=!1,k=r.__r,ne=0,E)p.state=p.__s,p.__d=!1,k&&k(t),d=p.render(p.props,p.state,p.context),_.push.apply(p.__h,p._sb),p._sb=[];else do p.__d=!1,k&&k(t),d=p.render(p.props,p.state,p.context),p.state=p.__s;while(p.__d&&++ne<25);p.state=p.__s,p.getChildContext!=null&&(i=b(b({},i),p.getChildContext())),E&&!m&&p.getSnapshotBeforeUpdate!=null&&(v=p.getSnapshotBeforeUpdate(h,g)),A=d!=null&&d.type===C&&d.key==null?se(d.props.children):d,c=te(e,y(A)?A:[A],t,n,i,a,o,s,c,l,u),p.base=t.__e,t.__u&=-161,p.__h.length&&s.push(p),x&&(p.__E=p.__=null)}catch(e){if(s.length=f,t.__v=null,l||o!=null){if(e.then){for(t.__u|=l?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;o!=null&&(o[o.indexOf(c)]=null),t.__e=c}else if(o!=null)for(j=o.length;j--;)ee(o[j])}else t.__e=n.__e;t.__k??=n.__k||[],e.then||ae(t),r.__e(e,t,n)}}else o==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=ce(n.__e,t,n,i,a,o,s,l,u);return(d=r.diffed)&&d(t),128&t.__u?void 0:c}function ae(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(ae))}function oe(e,t,n){for(var i=0;i<n.length;i++)P(n[i],n[++i],n[++i]);r.__c&&r.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){r.__e(e,t.__v)}})}function se(e){return typeof e!=`object`||!e||e.__b>0?e:y(e)?e.map(se):e.constructor===void 0?b({},e):null}function ce(e,t,i,a,o,s,c,l,u){var d,f,p,m,h,_,v,b=i.props||g,x=t.props,S=t.type;if(S==`svg`?o=`http://www.w3.org/2000/svg`:S==`math`?o=`http://www.w3.org/1998/Math/MathML`:o||=`http://www.w3.org/1999/xhtml`,s!=null){for(d=0;d<s.length;d++)if((h=s[d])&&`setAttribute`in h==!!S&&(S?h.localName==S:h.nodeType==3)){e=h,s[d]=null;break}}if(e==null){if(S==null)return document.createTextNode(x);e=document.createElementNS(o,S,x.is&&x),l&&=(r.__m&&r.__m(t,s),!1),s=null}if(S==null)b===x||l&&e.data==x||(e.data=x);else{if(s=S==`textarea`&&x.defaultValue!=null?null:s&&n.call(e.childNodes),!l&&s!=null)for(b={},d=0;d<e.attributes.length;d++)b[(h=e.attributes[d]).name]=h.value;for(d in b)h=b[d],d==`dangerouslySetInnerHTML`?p=h:d==`children`||d in x||d==`value`&&`defaultValue`in x||d==`checked`&&`defaultChecked`in x||N(e,d,null,h,o);for(d in x)h=x[d],d==`children`?m=h:d==`dangerouslySetInnerHTML`?f=h:d==`value`?_=h:d==`checked`?v=h:l&&typeof h!=`function`||b[d]===h||N(e,d,h,b[d],o);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,y(m)?m:[m],t,i,a,S==`foreignObject`?`http://www.w3.org/1999/xhtml`:o,s,c,s?s[0]:i.__k&&T(i,0),l,u),s!=null)for(d=s.length;d--;)ee(s[d]);l&&S!=`textarea`||(d=`value`,S==`progress`&&_==null?e.removeAttribute(`value`):_!=null&&(_!==e[d]||S==`progress`&&!_||S==`option`&&_!=b[d])&&N(e,d,_,b[d],o),d=`checked`,v!=null&&v!=e[d]&&N(e,d,v,b[d],o))}return e}function P(e,t,n){try{if(typeof e==`function`){var i=typeof e.__u==`function`;i&&e.__u(),i&&t==null||(e.__u=e(t))}else e.current=t}catch(e){r.__e(e,n)}}function le(e,t,n){var i,a;if(r.unmount&&r.unmount(e),(i=e.ref)&&(i.current&&i.current!=e.__e||P(i,null,t)),(i=e.__c)!=null){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(e){r.__e(e,t)}i.base=i.__P=i.__n=null}if(i=e.__k)for(a=0;a<i.length;a++)i[a]&&le(i[a],t,n||typeof e.type!=`function`);n||ee(e.__e),e.__c=e.__=e.__e=void 0}function ue(e,t,n){return this.constructor(e,n)}function de(e,t,i){var a,o,s,c;t==document&&(t=document.documentElement),r.__&&r.__(e,t),o=(a=typeof i==`function`)?null:i&&i.__k||t.__k,s=[],c=[],ie(t,e=(!a&&i||t).__k=x(C,null,[e]),o||g,g,t.namespaceURI,!a&&i?[i]:o?null:t.firstChild?n.call(t.childNodes):null,s,!a&&i?i:o?o.__e:t.firstChild,a,c),oe(s,e,c),e.props.children=null}n=_.slice,r={__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}},i=0,w.prototype.setState=function(e,t){var n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=b({},this.state);typeof e==`function`&&(e=e(b({},n),this.props)),e&&b(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),O(this))},w.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),O(this))},w.prototype.render=C,a=[],s=typeof Promise==`function`?Promise.prototype.then.bind(Promise.resolve()):setTimeout,c=function(e,t){return e.__v.__b-t.__v.__b},k.__r=0,l=Math.random().toString(8),u=`__d`+l,d=`__a`+l,f=/(PointerCapture)$|Capture$/i,p=0,m=re(!1),h=re(!0);var F,I,fe,pe,L=0,me=[],R=r,he=R.__b,ge=R.__r,_e=R.diffed,ve=R.__c,ye=R.unmount,be=R.__;function xe(e,t){R.__h&&R.__h(I,e,L||t),L=0;var n=I.__H||(I.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function z(e){return L=1,Se(ke,e)}function Se(e,t,n){var r=xe(F++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):ke(void 0,t),function(e){var t=r.__N?r.__N[0]:r.__[0],n=r.t(t,e);t!==n&&(r.__N=[n,r.__[1]],r.__c.setState({}))}],r.__c=I,!I.__f)){var i=function(e,t,n){if(!r.__c.__H)return!0;var i=!1,o=r.__c.props!==e;if(r.__c.__H.__.some(function(e){if(e.__N){i=!0;var t=e.__[0];e.__=e.__N,e.__N=void 0,t!==e.__[0]&&(o=!0)}}),a){var s=a.call(this,e,t,n);return i?s||o:s}return!i||o};I.__f=!0;var a=I.shouldComponentUpdate,o=I.componentWillUpdate;I.componentWillUpdate=function(e,t,n){if(this.__e){var r=a;a=void 0,i(e,t,n),a=r}o&&o.call(this,e,t,n)},I.shouldComponentUpdate=i}return r.__N||r.__}function B(e,t){var n=xe(F++,3);!R.__s&&Oe(n.__H,t)&&(n.__=e,n.u=t,I.__H.__h.push(n))}function V(e){return L=5,Ce(function(){return{current:e}},[])}function Ce(e,t){var n=xe(F++,7);return Oe(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function we(){for(var e;e=me.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(H),t.__h.some(De),t.__h=[]}catch(n){t.__h=[],R.__e(n,e.__v)}}}R.__b=function(e){I=null,he&&he(e)},R.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),be&&be(e,t)},R.__r=function(e){ge&&ge(e),F=0;var t=(I=e.__c).__H;t&&(fe===I?(t.__h=[],I.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(H),t.__h.some(De),t.__h=[],F=0)),fe=I},R.diffed=function(e){_e&&_e(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(me.push(t)!==1&&pe===R.requestAnimationFrame||((pe=R.requestAnimationFrame)||Ee)(we)),t.__H.__.some(function(e){e.u&&=(e.__H=e.u,void 0)})),fe=I=null},R.__c=function(e,t){t.some(function(e){try{e.__h.some(H),e.__h=e.__h.filter(function(e){return!e.__||De(e)})}catch(n){t.some(function(e){e.__h&&=[]}),t=[],R.__e(n,e.__v)}}),ve&&ve(e,t)},R.unmount=function(e){ye&&ye(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{H(e)}catch(e){t=e}}),n.__H=void 0,t&&R.__e(t,n.__v))};var Te=typeof requestAnimationFrame==`function`;function Ee(e){var t,n=function(){clearTimeout(r),Te&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);Te&&(t=requestAnimationFrame(n))}function H(e){var t=I,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),I=t}function De(e){var t=I;e.__c=e.__(),I=t}function Oe(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function ke(e,t){return typeof t==`function`?t(e):t}var Ae=0;Array.isArray;function U(e,t,n,i,a,o){t||={};var s,c,l=t;if(`ref`in l)for(c in l={},t)c==`ref`?s=t[c]:l[c]=t[c];var u={type:e,props:l,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Ae,__i:-1,__u:0,__source:a,__self:o};if(typeof e==`function`&&(s=e.defaultProps))for(c in s)l[c]===void 0&&(l[c]=s[c]);return r.vnode&&r.vnode(u),u}function W({name:e,size:t,children:n}){return U(`svg`,{"data-icon":e,"aria-hidden":`true`,focusable:`false`,width:t,height:t,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`,"stroke-linecap":`round`,"stroke-linejoin":`round`,children:n})}function je({size:e=26}){return U(W,{name:`chat`,size:e,children:[U(`path`,{d:`M4 5.5A2.5 2.5 0 0 1 6.5 3h11A2.5 2.5 0 0 1 20 5.5v8a2.5 2.5 0 0 1-2.5 2.5H10l-4.5 4v-4h0A1.5 1.5 0 0 1 4 14.5z`}),U(`path`,{d:`M8.5 9.5h.01M12 9.5h.01M15.5 9.5h.01`,"stroke-width":`2.5`})]})}function Me({size:e=26}){return U(W,{name:`chevron-down`,size:e,children:U(`path`,{d:`M6 9l6 6 6-6`})})}function Ne({size:e=18}){return U(W,{name:`close`,size:e,children:U(`path`,{d:`M6 6l12 12M18 6L6 18`})})}var Pe=`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 Fe({size:e=16}){return U(W,{name:`thumb-up`,size:e,children:U(`path`,{d:Pe})})}function Ie({size:e=16}){return U(W,{name:`thumb-down`,size:e,children:U(`path`,{d:Pe,transform:`matrix(1 0 0 -1 0 24)`})})}function Le({isOpen:e,onClick:t,iconUrl:n,buttonRef:r}){let[i,a]=z(`loading`),o=n!==void 0&&i!==`failed`,s=o&&!e&&i===`loaded`;return U(`button`,{type:`button`,class:`whoo-widget-launcher`,onClick:t,"aria-label":e?`Close chat`:`Open chat`,ref:r,children:[e?U(Me,{}):s?null:U(je,{}),o?U(`img`,{class:`whoo-widget-launcher-icon-image`,src:n,alt:``,referrerpolicy:`no-referrer`,hidden:!s,onLoad:()=>a(`loaded`),onError:()=>a(`failed`)}):null]})}function Re({value:e,onChange:t,onSend:n,disabled:r,inputRef:i}){return U(`div`,{class:`whoo-widget-composer`,children:[U(`label`,{class:`whoo-widget-sr-only`,for:`whoo-widget-composer-input`,children:`Message`}),U(`input`,{id:`whoo-widget-composer-input`,class:`whoo-widget-composer-input`,value:e,readOnly:r,"aria-disabled":r,ref:i,onInput:e=>t(e.target.value),onKeyDown:e=>{e.key===`Enter`&&n()}}),U(`button`,{type:`button`,class:`whoo-widget-composer-send`,onClick:n,disabled:r,children:`Send`})]})}function ze({message:e}){return U(`div`,{class:`whoo-widget-error-banner`,role:`alert`,children:e})}var G=/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/y,K=/\*\*([^*]+)\*\*/y,q=/(?<![A-Za-z0-9_])_([^_\s](?:[^_]*[^_\s])?)_(?![A-Za-z0-9_])/y,J=/\*([^*]+)\*/y,Be=/https?:\/\/\S+/y,Ve=/[.,;:!?)\]}>]+$/;function He(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(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]!==`!`){G.lastIndex=n;let a=G.exec(e);if(a){i(n),t.push({type:`link`,text:a[1],url:a[2],start:n,end:G.lastIndex}),n=G.lastIndex,r=n;continue}}K.lastIndex=n;let a=K.exec(e);if(a){i(n),t.push({type:`bold`,value:a[1],start:n,end:K.lastIndex}),n=K.lastIndex,r=n;continue}q.lastIndex=n;let o=q.exec(e);if(o){i(n),t.push({type:`italic`,value:o[1],start:n,end:q.lastIndex}),n=q.lastIndex,r=n;continue}J.lastIndex=n;let s=J.exec(e);if(s){i(n),t.push({type:`italic`,value:s[1],start:n,end:J.lastIndex}),n=J.lastIndex,r=n;continue}Be.lastIndex=n;let c=Be.exec(e);if(c){let e=c[0].match(Ve),a=e?c[0].slice(0,c[0].length-e[0].length):c[0];if(a.length>0){i(n),t.push({type:`link`,text:a,url:a,start:n,end:n+a.length}),n+=a.length,r=n;continue}}n+=1}return i(e.length),t}function Ue(e){return He(e).map((e,t)=>{switch(e.type){case`bold`:return U(`strong`,{children:e.value},t);case`italic`:return U(`em`,{children:e.value},t);case`link`:return U(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,children:[e.text,U(`span`,{class:`whoo-widget-sr-only`,children:` (opens in new tab)`})]},t);default:return e.value}})}var We=[{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 Ge({state:e,containerRef:t,onThumbsUp:n,onThumbsDown:r,onSubmitDetailed:i,onCancel:a}){let[o,s]=z(``),[c,l]=z(``),u=V(e.status);if(B(()=>{let n=u.current;if(u.current=e.status,n===e.status)return;let r=t?.current;if(!r)return;let i=r.getRootNode();r.contains(i.activeElement)||r.focus()},[e.status,t]),e.status===`submitted`)return U(`div`,{class:`whoo-widget-feedback-submitted`,role:`status`,children:`Thanks for the feedback`});if(e.status===`expanded`)return U(`div`,{class:`whoo-widget-feedback-form`,children:[U(`label`,{children:[U(`span`,{class:`whoo-widget-sr-only`,children:`Additional feedback`}),U(`textarea`,{class:`whoo-widget-feedback-textarea`,value:o,onInput:e=>s(e.target.value),placeholder:`What was wrong? (optional)`})]}),U(`select`,{class:`whoo-widget-feedback-select`,"aria-label":`Feedback category`,value:c,onChange:e=>l(e.target.value),children:We.map(e=>U(`option`,{value:e.value,children:e.label},e.value))}),U(`div`,{class:`whoo-widget-feedback-form-buttons`,children:[U(`button`,{type:`button`,class:`whoo-widget-feedback-submit`,onClick:()=>i(o,c),children:`Submit`}),U(`button`,{type:`button`,class:`whoo-widget-feedback-cancel`,onClick:a,children:`Cancel`})]})]});let d=e.status===`submitting`;return U(`div`,{class:`whoo-widget-feedback`,children:[U(`div`,{class:`whoo-widget-feedback-buttons`,children:[U(`button`,{type:`button`,"aria-label":`Good response`,disabled:d,onClick:n,children:U(Fe,{})}),U(`button`,{type:`button`,"aria-label":`Bad response`,disabled:d,onClick:r,children:U(Ie,{})})]}),e.status===`error`?U(`div`,{class:`whoo-widget-feedback-error`,role:`status`,children:`Couldn't send feedback`}):null]})}function Ke({isSlowResponse:e}){return U(`div`,{class:`whoo-widget-pending`,role:`status`,children:[U(`span`,{class:`whoo-widget-typing`,"aria-hidden":`true`,children:[U(`span`,{}),U(`span`,{}),U(`span`,{})]}),e?U(`span`,{class:`whoo-widget-pending-text`,children:`Looking that up for you…`}):null]})}function qe({url:e,alt:t}){let[n,r]=z(!1);return n?null:U(`img`,{class:`whoo-widget-empty-state-image`,src:e,alt:t,referrerpolicy:`no-referrer`,onError:()=>r(!0)})}function Je({message:e,feedbackState:t,pending:n,isSlowResponse:r,onThumbsUp:i,onThumbsDown:a,onSubmitDetailed:o,onCancelFeedback:s}){let c=V(null),l=e.id;return U(`div`,{ref:c,tabIndex:-1,class:`whoo-widget-message whoo-widget-message--${e.role}`,children:[n?U(Ke,{isSlowResponse:r}):Ue(e.content),e.role===`assistant`&&l?U(Ge,{state:t,containerRef:c,onThumbsUp:()=>i(l),onThumbsDown:()=>a(l),onSubmitDetailed:(e,t)=>o(l,e,t),onCancel:()=>s(l)}):null]})}function Ye({messages:e,messageFeedback:t,lastCompletedMessageText:n,emptyStateImage:r,isStreaming:i=!1,isSlowResponse:a=!1,onThumbsUp:o,onThumbsDown:s,onSubmitDetailed:c,onCancelFeedback:l}){let u=V(null);return B(()=>{let e=u.current;e&&(e.scrollTop=e.scrollHeight)},[e,a]),U(C,{children:[U(`div`,{class:`whoo-widget-message-list`,ref:u,children:[r?U(qe,{...r}):null,e.map((n,r)=>U(Je,{message:n,feedbackState:n.id?t[n.id]??{status:`idle`}:{status:`idle`},pending:i&&r===e.length-1&&n.role===`assistant`&&n.content===``,isSlowResponse:a,onThumbsUp:o,onThumbsDown:s,onSubmitDetailed:c,onCancelFeedback:l},n.id??r))]}),U(`div`,{class:`whoo-widget-sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:n??``})]})}var Xe=`button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])`;function Ze(e){return Array.from(e.querySelectorAll(Xe)).filter(e=>{let t=getComputedStyle(e);return t.display!==`none`&&t.visibility!==`hidden`})}function Qe({state:e,controller:t,greeting:n}){let r=V(null),i=V(null);B(()=>{i.current?.focus()},[]);let a=e=>{if(e.key===`Escape`){t.close();return}if(e.key!==`Tab`)return;let n=r.current;if(!n)return;let i=Ze(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())},o=()=>{let n=e.draft.trim();n&&!e.isStreaming&&(t.setDraft(``),t.sendMessage(n))},s=`Chat with ${e.agentName??(t.config.name?.trim()||`Aiden`)}`,c=e.messages.length===0&&n?[{role:`assistant`,content:n,id:null}]:e.messages,l=t.emptyStateImageUrl,u=e.messages.length===0&&l?{url:l,alt:t.emptyStateImageAlt}:void 0;return U(`div`,{class:`whoo-widget-panel`,role:`dialog`,"aria-modal":`true`,"aria-label":s,ref:r,onKeyDown:a,children:[U(`div`,{class:`whoo-widget-header`,children:[U(`h2`,{class:`whoo-widget-header-title`,children:s}),U(`div`,{class:`whoo-widget-header-actions`,children:[e.messages.length>0&&U(`button`,{type:`button`,class:`whoo-widget-header-reset`,onClick:()=>t.resetConversation(),children:`New conversation`}),U(`button`,{type:`button`,class:`whoo-widget-header-close`,"aria-label":`Close chat`,onClick:()=>t.close(),children:U(Ne,{})})]})]}),U(Ye,{messages:c,messageFeedback:e.messageFeedback,lastCompletedMessageText:e.lastCompletedMessageText,emptyStateImage:u,isStreaming:e.isStreaming,isSlowResponse:e.isSlowResponse,onThumbsUp:e=>t.submitFeedback(e,`up`),onThumbsDown:e=>t.expandFeedback(e),onSubmitDetailed:(e,n,r)=>t.submitFeedback(e,`down`,n||void 0,r||void 0),onCancelFeedback:e=>t.cancelFeedback(e)}),e.runtimeError&&U(ze,{message:e.runtimeError}),U(Re,{value:e.draft,onChange:e=>t.setDraft(e),onSend:o,disabled:e.isStreaming,inputRef:i})]})}function $e({controller:e}){let[t,n]=z(e.getState()),r=V(null),i=V(t.isOpen);return B(()=>(n(e.getState()),e.subscribe(n)),[e]),B(()=>{i.current&&!t.isOpen&&r.current?.focus(),i.current=t.isOpen},[t.isOpen]),t.initError?null:U(C,{children:[U(Le,{isOpen:t.isOpen,onClick:()=>t.isOpen?e.close():e.open(),iconUrl:e.launcherIconUrl,buttonRef:r}),t.isOpen&&U(Qe,{state:t,controller:e,greeting:e.config.greeting})]})}var et=class extends Error{status;constructor(e,t){super(e),this.name=`WidgetApiError`,this.status=t}};function tt(e){if(typeof e!=`string`)return null;let t=e.trim();return t===``?null:t}async function nt(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 et(`Failed to create widget session (${n.status})`,n.status);let r=await n.json();return{token:r.token,primaryColor:r.primary_color??null,name:tt(r.name),accentColor:tt(r.accent_color),inkColor:tt(r.ink_color)}}async function rt(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 et(`Feedback submission failed (${r.status})`,r.status)}async function*it(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 et(`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(`
|
|
2
2
|
|
|
3
3
|
`);for(;n!==-1;){let e=c.slice(0,n);c=c.slice(n+2);let t=e.split(`
|
|
4
|
-
`).find(e=>e.startsWith(`data: `));t&&(yield
|
|
4
|
+
`).find(e=>e.startsWith(`data: `));t&&(yield at(JSON.parse(t.slice(6)))),n=c.indexOf(`
|
|
5
5
|
|
|
6
|
-
`)}}}function Qe(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}}var $e=40,et=120;function tt(e){let t=[];for(let n of Re(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 nt(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 rt(e,t,n){let r=n?.wordIntervalMs??$e,i=n?.tokenIntervalMs??et,a=n?.signal,o=Re(e),s=new Set(o.filter(e=>e.type!==`text`).map(e=>e.end)),c=nt(a),l=``;for(let n of tt(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 it(e){return`whoo-aiden-widget:conversation:${e}`}function at(e){try{return window.sessionStorage.getItem(it(e))}catch{return null}}function ot(e,t){try{window.sessionStorage.setItem(it(e),t)}catch{}}function st(e){try{window.sessionStorage.removeItem(it(e))}catch{}}var ct=class{config;state;listeners=new Set;sessionToken=null;conversationId=null;storageIdentifier;activeRequestController=null;prefersReducedMotion;constructor(e){this.config=e,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,lastCompletedMessageText:null,draft:``}}getState(){return this.state}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}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}=await Ye(e,this.config.publishableKey);this.sessionToken=t,this.setState({primaryColor:n})}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=at(this.storageIdentifier)}open(){this.setState({isOpen:!0})}resetConversation(){this.activeRequestController?.abort(),this.activeRequestController=null,this.conversationId=null,st(this.storageIdentifier),this.setState({messages:[],messageFeedback:{},runtimeError:null,isStreaming:!1,lastCompletedMessageText:null})}setDraft(e){this.setState({draft:e})}close(){this.activeRequestController?.abort(),this.activeRequestController=null,this.setState({isOpen:!1})}async sendMessage(e){if(!this.sessionToken)return;let t=this.config.apiBaseUrl??`https://api.aidenvoice.com`,n={role:`user`,content:e,id:null},r={role:`assistant`,content:``,id:null};this.setState({messages:[...this.state.messages,n,r],isStreaming:!0,runtimeError:null});let i=e=>{let t=[...this.state.messages];t[t.length-1]={...t[t.length-1],content:e},this.setState({messages:t})};this.activeRequestController=new AbortController;let{signal:a}=this.activeRequestController,o=()=>{this.setState({runtimeError:`Something went wrong, please try again.`,...this.state.draft===``?{draft:e}:{}})},s=``;try{for await(let n of Ze(t,this.sessionToken,this.conversationId,e,a))if(n.type===`conversation_id`)this.conversationId=n.conversationId,ot(this.storageIdentifier,n.conversationId);else if(n.type===`delta`)n.verbatim&&!this.prefersReducedMotion?(await rt(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,ot(this.storageIdentifier,n.conversationId)),n.messageId){let e=[...this.state.messages];e[e.length-1]={...e[e.length-1],id:n.messageId},this.setState({messages:e})}this.setState({lastCompletedMessageText:s})}else n.type===`error`&&(console.error(`[whoo-aiden-widget] chat error:`,n.error),o())}catch(e){e?.name===`AbortError`||(console.error(`[whoo-aiden-widget] chat request failed:`,e),o())}finally{this.activeRequestController=null,this.setState({isStreaming:!1})}}expandFeedback(e){this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`expanded`}}})}cancelFeedback(e){this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`idle`}}})}async submitFeedback(e,t,n,r){if(!this.sessionToken)return;let i=this.config.apiBaseUrl??`https://api.aidenvoice.com`;this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`submitting`,rating:t}}});try{await Xe(i,this.sessionToken,{messageId:e,rating:t,correction:n,category:r}),this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`submitted`,rating:t}}})}catch(n){console.error(`[whoo-aiden-widget] feedback submission failed:`,n),this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`error`,rating:t}}})}}},lt=`: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-logo{object-fit:cover;border-radius:50%;width:32px;height:32px}.whoo-widget-panel{bottom:88px;left:var(--whoo-widget-inset-left,auto);right:var(--whoo-widget-inset-right,20px);background:#fff;border-radius:12px;flex-direction:column;width:360px;max-width:calc(100vw - 40px);height:480px;max-height:calc(100vh - 108px);display:flex;position:fixed;overflow:hidden;box-shadow:0 4px 16px #0003}@media (width<=400px),(height<=420px){.whoo-widget-panel{width:auto;max-width:none;height:auto;max-height:none;inset:8px}}.whoo-widget-header{border-bottom:1px solid #e5e5e5;flex-shrink:0;justify-content:space-between;align-items:center;gap:8px;padding:8px 8px 8px 16px;display:flex}.whoo-widget-header-title{color:#111;text-overflow:ellipsis;white-space:nowrap;margin:0;font-size:15px;font-weight:600;overflow:hidden}.whoo-widget-header-actions{flex-shrink:0;align-items:center;gap:4px;display:flex}.whoo-widget-header-close,.whoo-widget-header-reset{color:var(--whoo-widget-color-text,#4f46e5);cursor:pointer;background:0 0;border:none;border-radius:6px;justify-content:center;align-items:center;min-width:24px;min-height:24px;padding:4px 8px;font-size:13px;display:inline-flex}.whoo-widget-header-close{width:32px;height:32px;padding:0}.whoo-widget-header-close:hover,.whoo-widget-header-reset:hover{background:#f3f4f6}.whoo-widget-message-list{flex:1;min-height:100px;padding:12px;overflow-y:auto}.whoo-widget-message{border-radius:8px;max-width:80%;margin-bottom:8px;padding:8px 12px}.whoo-widget-message--user{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);margin-left:auto}.whoo-widget-message--assistant{color:#111;background:#f0f0f0}.whoo-widget-error-banner{color:#991b1b;background:#fee2e2;padding:8px 12px;font-size:13px}.whoo-widget-composer{border-top:1px solid #e5e5e5;gap:8px;padding:12px;display:flex}.whoo-widget-composer-input{border:1px solid #6b7280;border-radius:6px;flex:1;padding:8px}.whoo-widget-composer-send{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);cursor:pointer;border:none;border-radius:6px;padding:8px 16px}.whoo-widget-composer-send:disabled,.whoo-widget-composer-input[aria-disabled=true]{opacity:.6;cursor:not-allowed}.whoo-widget-feedback{align-items:center;gap:6px;margin-top:4px;display:flex}.whoo-widget-feedback-buttons{gap:6px;display:flex}.whoo-widget-feedback-buttons button{cursor:pointer;color:#4b5563;background:0 0;border:none;border-radius:4px;justify-content:center;align-items:center;min-width:24px;min-height:24px;padding:4px;display:inline-flex}.whoo-widget-feedback-buttons button:hover:not(:disabled){color:#111;background:#0000000f}.whoo-widget-feedback-buttons button:disabled{opacity:.3;cursor:not-allowed}.whoo-widget-feedback-form{flex-direction:column;gap:6px;margin-top:6px;display:flex}.whoo-widget-feedback-textarea{box-sizing:border-box;resize:vertical;border:1px solid #6b7280;border-radius:6px;width:100%;padding:6px;font-size:12px}.whoo-widget-feedback-select{border:1px solid #6b7280;border-radius:6px;min-height:24px;padding:4px;font-size:12px}.whoo-widget-feedback-form-buttons{gap:6px;display:flex}.whoo-widget-feedback-submit{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);cursor:pointer;border:none;border-radius:6px;padding:8px 16px;font-size:13px}.whoo-widget-feedback-cancel{color:#111;cursor:pointer;background:#fff;border:1px solid #6b7280;border-radius:6px;padding:8px 16px;font-size:13px}.whoo-widget-feedback-submitted{color:#6b7280;margin-top:4px;font-size:12px}.whoo-widget-feedback-error{color:#991b1b;font-size:12px}.whoo-widget-sr-only{clip:rect(0, 0, 0, 0);white-space:nowrap;border:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}button:focus-visible,input:focus-visible,textarea:focus-visible,select:focus-visible,a:focus-visible{outline-offset:2px;outline:2px solid #111827;box-shadow:0 0 0 4px #fff}`;function ut(e){let t=document.createElement(`div`);if(t.style.color=e,t.style.color===``)return null;document.body.appendChild(t);let n=getComputedStyle(t).color;document.body.removeChild(t);let r=n.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?/);if(!r)return null;let i=r[4]===void 0?1:Number(r[4]);return{rgb:[Number(r[1]),Number(r[2]),Number(r[3])].map(e=>Math.round(e*i+255*(1-i))),translucent:i<1}}function dt(e){return ut(e)?.rgb??null}function $([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 ft(e,t){let n=Math.max(e,t),r=Math.min(e,t);return(n+.05)/(r+.05)}function pt(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=$(t);return ft(n,$([0,0,0]))>=ft(n,$([255,255,255]))?`#000000`:`#ffffff`}var mt=`#4f46e5`,ht=[255,255,255],gt=4.5;function _t([e,t,n]){return`#${[e,t,n].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}function vt(e){let t=dt(e);if(!t)return mt;let n=$(ht),r=e=>ft($(e),n)>=gt;if(r(t))return e;for(let e=.99;e>0;e-=.01){let n=t.map(t=>Math.round(t*e));if(r(n))return _t(n)}return`#000000`}function yt(e,t){let n=ut(t),r=n?.translucent?_t(n.rgb):t;e.style.setProperty(`--whoo-widget-color`,r),e.style.setProperty(`--whoo-widget-text-on-color`,pt(r)),e.style.setProperty(`--whoo-widget-color-text`,vt(r))}function bt(e,t){yt(e,t.color??mt);let n=t.position===`bottom-left`;e.style.setProperty(`--whoo-widget-inset-left`,n?`20px`:`auto`),e.style.setProperty(`--whoo-widget-inset-right`,n?`auto`:`20px`)}function xt(e){let t=document.createElement(`div`);t.id=`whoo-aiden-widget-host`;let n=t.attachShadow({mode:`open`}),r=document.createElement(`style`);r.textContent=lt,n.appendChild(r);let i=document.createElement(`div`);n.appendChild(i),bt(i,e);let a=new ct(e);return a.subscribe(e=>{e.primaryColor&&yt(i,e.primaryColor)}),le(q(qe,{controller:a}),i),a.init(),document.body.appendChild(t),{unmount(){le(null,i),t.remove()}}}function St(e){return t(e),xt(e)}return e.init=St,e})({});
|
|
6
|
+
`)}}}function at(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 ot(e,t){if(e!=null&&e!==``){if(typeof e==`string`)try{let t=new URL(e);if(t.protocol===`https:`||t.protocol===`data:`&&t.pathname.toLowerCase().startsWith(`image/`))return e}catch{}console.warn(`whoo-aiden-widget: ignoring \`${t}\` -- only https: and data:image/ URLs are allowed.`)}}var st=40,ct=120;function lt(e){let t=[];for(let n of He(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 ut(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 dt(e,t,n){let r=n?.wordIntervalMs??st,i=n?.tokenIntervalMs??ct,a=n?.signal,o=He(e),s=new Set(o.filter(e=>e.type!==`text`).map(e=>e.end)),c=ut(a),l=``;for(let n of lt(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 ft(e){return`whoo-aiden-widget:conversation:${e}`}function pt(e){try{return window.sessionStorage.getItem(ft(e))}catch{return null}}function mt(e,t){try{window.sessionStorage.setItem(ft(e),t)}catch{}}function ht(e){try{window.sessionStorage.removeItem(ft(e))}catch{}}var gt=8e3,_t=class{config;state;listeners=new Set;sessionToken=null;conversationId=null;storageIdentifier;activeRequestController=null;slowResponseTimer=null;prefersReducedMotion;launcherIconUrl;emptyStateImageUrl;emptyStateImageAlt;constructor(e){this.config=e,this.launcherIconUrl=ot(e.launcherIconUrl,`launcherIconUrl`),this.emptyStateImageUrl=ot(e.emptyStateImageUrl,`emptyStateImageUrl`),this.emptyStateImageAlt=typeof e.emptyStateImageAlt==`string`?e.emptyStateImageAlt.trim():``,this.storageIdentifier=e.publishableKey??`session-token-mode`,this.prefersReducedMotion=typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,this.state={isOpen:!1,messages:[],isStreaming:!1,initError:null,runtimeError:null,messageFeedback:{},primaryColor:null,agentName:null,accentColor:null,inkColor:null,lastCompletedMessageText:null,isSlowResponse:!1,draft:``}}getState(){return this.state}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}clearSlowResponse(){this.slowResponseTimer!==null&&(clearTimeout(this.slowResponseTimer),this.slowResponseTimer=null),this.state.isSlowResponse&&this.setState({isSlowResponse:!1})}setState(e){this.state={...this.state,...e};for(let e of this.listeners)e(this.state)}async init(){let e=this.config.apiBaseUrl??`https://api.aidenvoice.com`;try{if(this.config.sessionToken)this.sessionToken=this.config.sessionToken;else if(this.config.publishableKey){let{token:t,primaryColor:n,name:r,accentColor:i,inkColor:a}=await nt(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=pt(this.storageIdentifier)}open(){this.setState({isOpen:!0})}resetConversation(){this.activeRequestController?.abort(),this.activeRequestController=null,this.clearSlowResponse(),this.conversationId=null,ht(this.storageIdentifier),this.setState({messages:[],messageFeedback:{},runtimeError:null,isStreaming:!1,lastCompletedMessageText:null})}setDraft(e){this.setState({draft:e})}close(){this.activeRequestController?.abort(),this.activeRequestController=null,this.clearSlowResponse(),this.setState({isOpen:!1})}async sendMessage(e){if(!this.sessionToken)return;let t=this.config.apiBaseUrl??`https://api.aidenvoice.com`,n={role:`user`,content:e,id:null},r={role:`assistant`,content:``,id:null};this.setState({messages:[...this.state.messages,n,r],isStreaming:!0,runtimeError:null});let i=e=>{let t=[...this.state.messages];t[t.length-1]={...t[t.length-1],content:e},this.setState({messages:t})};this.activeRequestController=new AbortController;let{signal:a}=this.activeRequestController;this.slowResponseTimer=setTimeout(()=>{this.slowResponseTimer=null,this.setState({isSlowResponse:!0})},gt);let o=()=>{this.setState({runtimeError:`Something went wrong, please try again.`,...this.state.draft===``?{draft:e}:{}})},s=``;try{for await(let n of it(t,this.sessionToken,this.conversationId,e,a))if(n.type===`conversation_id`)this.conversationId=n.conversationId,mt(this.storageIdentifier,n.conversationId);else if(n.type===`delta`)this.clearSlowResponse(),n.verbatim&&!this.prefersReducedMotion?(await dt(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,mt(this.storageIdentifier,n.conversationId)),n.messageId){let e=[...this.state.messages];e[e.length-1]={...e[e.length-1],id:n.messageId},this.setState({messages:e})}this.setState({lastCompletedMessageText:s})}else if(n.type===`error`){console.error(`[whoo-aiden-widget] chat error:`,n.error),o(),this.activeRequestController?.abort();break}}catch(e){e?.name===`AbortError`||(console.error(`[whoo-aiden-widget] chat request failed:`,e),o())}finally{this.activeRequestController=null,this.clearSlowResponse(),this.setState({isStreaming:!1})}}expandFeedback(e){this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`expanded`}}})}cancelFeedback(e){this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`idle`}}})}async submitFeedback(e,t,n,r){if(!this.sessionToken)return;let i=this.config.apiBaseUrl??`https://api.aidenvoice.com`;this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`submitting`,rating:t}}});try{await rt(i,this.sessionToken,{messageId:e,rating:t,correction:n,category:r}),this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`submitted`,rating:t}}})}catch(n){console.error(`[whoo-aiden-widget] feedback submission failed:`,n),this.setState({messageFeedback:{...this.state.messageFeedback,[e]:{status:`error`,rating:t}}})}}},vt=`:host,.whoo-widget-root{all:initial;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif}.whoo-widget-launcher{bottom:20px;left:var(--whoo-widget-inset-left,auto);right:var(--whoo-widget-inset-right,20px);background:var(--whoo-widget-color,#4f46e5);width:56px;height:56px;color:var(--whoo-widget-text-on-color,#fff);cursor:pointer;border:none;border-radius:50%;justify-content:center;align-items:center;padding:0;font-size:24px;display:flex;position:fixed;box-shadow:0 2px 8px #0003}.whoo-widget-launcher:focus-visible{box-shadow:0 2px 8px #0003,0 0 0 4px #fff}.whoo-widget-launcher svg{display:block}.whoo-widget-launcher-icon-image{object-fit:cover;border-radius:50%;width:32px;height:32px}.whoo-widget-launcher-icon-image[hidden]{display:none}.whoo-widget-panel{bottom:88px;left:var(--whoo-widget-inset-left,auto);right:var(--whoo-widget-inset-right,20px);background:#fff;border-radius:12px;flex-direction:column;width:360px;max-width:calc(100vw - 40px);height:480px;max-height:calc(100vh - 108px);display:flex;position:fixed;overflow:hidden;box-shadow:0 4px 16px #0003}@media (width<=400px),(height<=420px){.whoo-widget-panel{width:auto;max-width:none;height:auto;max-height:none;inset:8px}}.whoo-widget-header{border-bottom:1px solid #e5e5e5;flex-shrink:0;justify-content:space-between;align-items:center;gap:8px;padding:8px 8px 8px 16px;display:flex}.whoo-widget-header-title{color:var(--whoo-widget-ink,#111);text-overflow:ellipsis;white-space:nowrap;margin:0;font-size:15px;font-weight:600;overflow:hidden}.whoo-widget-header-actions{flex-shrink:0;align-items:center;gap:4px;display:flex}.whoo-widget-header-close,.whoo-widget-header-reset{color:var(--whoo-widget-color-text,#4f46e5);cursor:pointer;background:0 0;border:none;border-radius:6px;justify-content:center;align-items:center;min-width:24px;min-height:24px;padding:4px 8px;font-size:13px;display:inline-flex}.whoo-widget-header-close{width:32px;height:32px;padding:0}.whoo-widget-header-close:hover,.whoo-widget-header-reset:hover{background:#f3f4f6}.whoo-widget-message-list{flex:1;min-height:100px;padding:12px;overflow-y:auto}.whoo-widget-empty-state-image{object-fit:contain;max-width:min(160px,100%);height:auto;max-height:160px;margin:8px auto 16px;display:block}@media (width<=400px),(height<=420px){.whoo-widget-empty-state-image{max-height:64px;margin:0 auto 8px}}.whoo-widget-message{border-radius:8px;max-width:80%;margin-bottom:8px;padding:8px 12px}.whoo-widget-message--user{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);margin-left:auto}.whoo-widget-message--user a{color:inherit}.whoo-widget-message--assistant{color:var(--whoo-widget-ink,#111);background:#f0f0f0}.whoo-widget-message--assistant a{color:var(--whoo-widget-link-color,LinkText)}.whoo-widget-pending{flex-wrap:wrap;align-items:center;gap:8px;min-height:1.2em;display:flex}.whoo-widget-typing{align-items:center;gap:4px;display:inline-flex}.whoo-widget-typing span{background:#6b7280;border-radius:50%;width:6px;height:6px;animation:1.2s ease-in-out infinite whoo-widget-typing-bounce}.whoo-widget-typing span:nth-child(2){animation-delay:.2s}.whoo-widget-typing span:nth-child(3){animation-delay:.4s}@keyframes whoo-widget-typing-bounce{0%,80%,to{transform:translateY(0)}40%{transform:translateY(-4px)}}@media (prefers-reduced-motion:reduce){.whoo-widget-typing span{animation:none}}.whoo-widget-error-banner{color:#991b1b;background:#fee2e2;padding:8px 12px;font-size:13px}.whoo-widget-composer{border-top:1px solid #e5e5e5;gap:8px;padding:12px;display:flex}.whoo-widget-composer-input{border:1px solid #6b7280;border-radius:6px;flex:1;padding:8px}.whoo-widget-composer-send{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);cursor:pointer;border:none;border-radius:6px;padding:8px 16px}.whoo-widget-composer-send:disabled,.whoo-widget-composer-input[aria-disabled=true]{opacity:.6;cursor:not-allowed}.whoo-widget-feedback{align-items:center;gap:6px;margin-top:4px;display:flex}.whoo-widget-feedback-buttons{gap:6px;display:flex}.whoo-widget-feedback-buttons button{cursor:pointer;color:#4b5563;background:0 0;border:none;border-radius:4px;justify-content:center;align-items:center;min-width:24px;min-height:24px;padding:4px;display:inline-flex}.whoo-widget-feedback-buttons button:hover:not(:disabled){color:#111;background:#0000000f}.whoo-widget-feedback-buttons button:disabled{opacity:.3;cursor:not-allowed}.whoo-widget-feedback-form{flex-direction:column;gap:6px;margin-top:6px;display:flex}.whoo-widget-feedback-textarea{box-sizing:border-box;resize:vertical;border:1px solid #6b7280;border-radius:6px;width:100%;padding:6px;font-size:12px}.whoo-widget-feedback-select{border:1px solid #6b7280;border-radius:6px;min-height:24px;padding:4px;font-size:12px}.whoo-widget-feedback-form-buttons{gap:6px;display:flex}.whoo-widget-feedback-submit{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);cursor:pointer;border:none;border-radius:6px;padding:8px 16px;font-size:13px}.whoo-widget-feedback-cancel{color:#111;cursor:pointer;background:#fff;border:1px solid #6b7280;border-radius:6px;padding:8px 16px;font-size:13px}.whoo-widget-feedback-submitted{color:#6b7280;margin-top:4px;font-size:12px}.whoo-widget-feedback-error{color:#991b1b;font-size:12px}.whoo-widget-sr-only{clip:rect(0, 0, 0, 0);white-space:nowrap;border:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}button:focus-visible,input:focus-visible,textarea:focus-visible,select:focus-visible,a:focus-visible{outline-offset:2px;outline:2px solid #111827;box-shadow:0 0 0 4px #fff}`,yt=/^(inherit|initial|unset|revert|revert-layer)$|\bcurrentcolor\b|\b(var|env|attr|light-dark)\(/i;function Y(e){if(yt.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 bt(e){return Y(e)?.rgb??null}function X([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 Z(e,t){let n=Math.max(e,t),r=Math.min(e,t);return(n+.05)/(r+.05)}function xt(e){let t=bt(e);if(!t)return console.warn(`[whoo-aiden-widget] Could not parse color "${e}" for contrast calculation; defaulting to white text.`),`#ffffff`;let n=X(t);return Z(n,X([0,0,0]))>=Z(n,X([255,255,255]))?`#000000`:`#ffffff`}var Q=`#4f46e5`,St=`#ffffff`,Ct=`#f0f0f0`,wt=4.5;function $([e,t,n]){return`#${[e,t,n].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}function Tt(e,t=St){let n=bt(e),r=bt(t);if(!n||!r)return Q;let i=X(r),a=e=>Z(X(e),i)>=wt;if(a(n))return $(n);for(let e=.99;e>0;e-=.01){let t=n.map(t=>Math.round(t*e));if(a(t))return $(t)}return`#000000`}function Et(e,t,n=Q){let r=Y(t);r||=(console.warn(`[whoo-aiden-widget] Could not use "${t}" as the theme color; falling back to "${n}".`),Y(n));let i=r?$(r.rgb):Q;e.style.setProperty(`--whoo-widget-color`,i),e.style.setProperty(`--whoo-widget-text-on-color`,xt(i)),e.style.setProperty(`--whoo-widget-color-text`,Tt(i))}function Dt(e,{inkColor:t,accentColor:n}){let r=e=>{let t=e===null?null:Y(e);return t?Tt($(t.rgb),Ct):null},i=r(t),a=r(n);i&&e.style.setProperty(`--whoo-widget-ink`,i),a&&e.style.setProperty(`--whoo-widget-link-color`,a)}function Ot(e,t){Et(e,t.color??Q);let n=t.position===`bottom-left`;e.style.setProperty(`--whoo-widget-inset-left`,n?`20px`:`auto`),e.style.setProperty(`--whoo-widget-inset-right`,n?`auto`:`20px`)}function kt(e){let t=document.createElement(`div`);t.id=`whoo-aiden-widget-host`;let n=t.attachShadow({mode:`open`}),r=document.createElement(`style`);r.textContent=vt,n.appendChild(r);let i=document.createElement(`div`);n.appendChild(i),Ot(i,e);let a=new _t(e),o=null,s=``;return a.subscribe(t=>{t.primaryColor&&t.primaryColor!==o&&(o=t.primaryColor,Et(i,t.primaryColor,e.color));let n=`${t.inkColor}|${t.accentColor}`;(t.inkColor||t.accentColor)&&n!==s&&(s=n,Dt(i,{inkColor:t.inkColor,accentColor:t.accentColor}))}),de(U($e,{controller:a}),i),a.init(),document.body.appendChild(t),{unmount(){de(null,i),t.remove()}}}function At(e){return t(e),kt(e)}return e.init=At,e})({});
|