@aiden-voice/widget 0.1.1 → 0.1.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 CHANGED
@@ -180,12 +180,21 @@ to a stable release (e.g. there's no prerelease queued), move it by hand:
180
180
  npm dist-tag add @aiden-voice/widget@<stable-version> next
181
181
  ```
182
182
 
183
- If `publish` fails (a transient npm outage, a misconfigured Trusted
184
- Publisher) after `cdn` has already succeeded, re-run just that job from
185
- the GitHub Actions UI
186
- (Actions the failed run **Re-run failed jobs**) it rebuilds and
187
- publishes from the same tag without re-touching the archive or
188
- redeploying the Static Web App. The tag itself is never re-pushed.
183
+ If `publish` fails after `cdn` has succeeded, first re-run just that job from
184
+ the failed run (Actions the run → **Re-run failed jobs**): it downloads the
185
+ `dist` artifact `cdn` uploaded (kept 30 days) and publishes it, without
186
+ touching the archive or the Static Web App. If the run is gone or `publish` never ran for a version the CDN already
187
+ has, use the publish-only path instead: Actions **Release** → **Run
188
+ workflow** `version` (e.g. `0.1.1`, no leading `v`). That run skips `cdn`;
189
+ a `build_tag` job without publish rights checks out `v<version>`, refuses if
190
+ `package.json` disagrees or if
191
+ `https://widget.aidenvoice.com/v<version>/widget.iife.js` is not there, and
192
+ rebuilds `dist` from the tag; `publish` then downloads it, refuses if npm
193
+ already has the version, computes the dist-tag from npm's published versions
194
+ (`scripts/release-plan.mjs tag-for`, taken from the dispatching branch so tags
195
+ cut before that command existed still work) and publishes. Neither
196
+ recovery path modifies the archive; clearing archived folders (below) is only
197
+ for a failed `cdn` job.
189
198
 
190
199
  ### Recovering a failed release
191
200
 
@@ -234,7 +243,7 @@ npm view @aiden-voice/widget dist-tags
234
243
 
235
244
  ## Accessibility
236
245
 
237
- The widget targets WCAG 2.1 AA and ships with dialog focus management,
246
+ The widget targets WCAG 2.2 AA and ships with dialog focus management,
238
247
  keyboard support (Tab-trapping while the panel is open, Escape to close),
239
248
  screen-reader announcements for streaming replies and errors, and labeled
240
249
  form controls out of the box. A few things stay the embedding site's
@@ -244,13 +253,14 @@ responsibility:
244
253
  `'yellow'`, `rgb()`, `hsl()`, etc.), the widget automatically picks black
245
254
  or white text against whatever `color` (or server-provided
246
255
  `primaryColor`) is in effect on button/bubble surfaces, so text stays
247
- readable there regardless of how light or dark your color is. One
248
- exception: the panel's "New conversation" and "Close chat" text buttons
249
- render your `color` directly as text on the panel's white background,
250
- which is **not** auto-corrected pick a color with reasonable contrast
251
- against white if you care about that spot (the default `#4f46e5` works
252
- well; very light/pastel colors will not). See
253
- `docs/accessibility-report.md` for details.
256
+ readable there regardless of how light or dark your color is. Where your
257
+ color is used as text on the panel's white background (the header
258
+ controls), it's used as-is if it already reaches 4.5:1 against white;
259
+ otherwise the widget automatically uses a darker shade of the same hue,
260
+ so a pale brand color will look noticeably darker there. A translucent
261
+ color (`rgba(…, 0.5)`, `#rrggbbaa`) is flattened to how it looks over
262
+ white, since the launcher floats over page content the widget can't
263
+ know. See `docs/accessibility-report.md` for details.
254
264
  - **Page language:** the widget renders inside your page's DOM and
255
265
  inherits language from your document's `<html lang>` attribute; there is
256
266
  no separate widget-level locale override.
@@ -0,0 +1,15 @@
1
+ export declare function ChatIcon({ size }: {
2
+ size?: number;
3
+ }): import("preact").JSX.Element;
4
+ export declare function ChevronDownIcon({ size }: {
5
+ size?: number;
6
+ }): import("preact").JSX.Element;
7
+ export declare function CloseIcon({ size }: {
8
+ size?: number;
9
+ }): import("preact").JSX.Element;
10
+ export declare function ThumbUpIcon({ size }: {
11
+ size?: number;
12
+ }): import("preact").JSX.Element;
13
+ export declare function ThumbDownIcon({ size }: {
14
+ size?: number;
15
+ }): import("preact").JSX.Element;
@@ -18,6 +18,7 @@ export interface WidgetState {
18
18
  messageFeedback: Record<string, MessageFeedbackState>;
19
19
  primaryColor: string | null;
20
20
  lastCompletedMessageText: string | null;
21
+ draft: string;
21
22
  }
22
23
  type Listener = (state: WidgetState) => void;
23
24
  export declare class WidgetController {
@@ -36,6 +37,7 @@ export declare class WidgetController {
36
37
  init(): Promise<void>;
37
38
  open(): void;
38
39
  resetConversation(): void;
40
+ setDraft(draft: string): void;
39
41
  close(): void;
40
42
  sendMessage(text: string): Promise<void>;
41
43
  expandFeedback(messageId: string): void;
package/dist/theme.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  import { WidgetConfig } from './types';
2
2
  export declare function pickTextColor(cssColor: string): '#000000' | '#ffffff';
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;
3
6
  export declare function applyTheme(root: HTMLElement, config: WidgetConfig): void;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const WIDGET_VERSION = "0.1.1";
1
+ export declare const WIDGET_VERSION = "0.1.2";
@@ -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),I(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,re(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=j(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=I(e,p,f,i,a,o,s,c,l,u),m=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&L(f.ref,null,p),u.push(p.ref,p.__c||m,p)),h==null&&m!=null&&(h=m),4&p.__u?(c=M(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 j(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=N(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)),oe(s,s));return r}function M(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=M(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 N(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 P(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||v.test(t)?n:n+`px`}function F(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||P(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||P(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 te(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 I(e,t,n,i,a,o,s,c,l,u){var d,f,p,m,h,g,v,S,C,D,O,k,A,j,M,N,P=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 P==`function`){f=s.length;try{if(C=t.props,D=P.prototype&&P.prototype.render,O=(d=P.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 P(C,k):(t.__c=p=new T(C,k),p.constructor=P,p.render=se),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&&P.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=b({},p.__s)),b(p.__s,P.getDerivedStateFromProps(C,p.__s))),h=p.props,g=p.state,p.__v=t,m)D&&P.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),D&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(D&&P.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,j=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&&++j<25);p.state=p.__s,p.getChildContext!=null&&(i=b(b({},i),p.getChildContext())),D&&!m&&p.getSnapshotBeforeUpdate!=null&&(v=p.getSnapshotBeforeUpdate(h,g)),M=d!=null&&d.type===w&&d.key==null?ie(d.props.children):d,c=ee(e,y(M)?M:[M],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(N=o.length;N--;)x(o[N])}else t.__e=n.__e;t.__k??=n.__k||[],e.then||ne(t),r.__e(e,t,n)}}else o==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=ae(n.__e,t,n,i,a,o,s,l,u);return(d=r.diffed)&&d(t),128&t.__u?void 0:c}function ne(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(ne))}function re(e,t,n){for(var i=0;i<n.length;i++)L(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 ie(e){return typeof e!=`object`||!e||e.__b>0?e:y(e)?e.map(ie):e.constructor===void 0?b({},e):null}function ae(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||F(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||F(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])&&F(e,d,_,b[d],o),d=`checked`,v!=null&&v!=e[d]&&F(e,d,v,b[d],o))}return e}function L(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 oe(e,t,n){var i,a;if(r.unmount&&r.unmount(e),(i=e.ref)&&(i.current&&i.current!=e.__e||L(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]&&oe(i[a],t,n||typeof e.type!=`function`);n||x(e.__e),e.__c=e.__=e.__e=void 0}function se(e,t,n){return this.constructor(e,n)}function ce(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=[],I(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),re(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=te(!1),h=te(!0);var R,z,B,le,V=0,ue=[],H=r,de=H.__b,fe=H.__r,pe=H.diffed,me=H.__c,he=H.unmount,ge=H.__;function U(e,t){H.__h&&H.__h(z,e,V||t),V=0;var n=z.__H||(z.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function W(e){return V=1,_e(Ce,e)}function _e(e,t,n){var r=U(R++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Ce(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=z,!z.__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};z.__f=!0;var a=z.shouldComponentUpdate,o=z.componentWillUpdate;z.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)},z.shouldComponentUpdate=i}return r.__N||r.__}function G(e,t){var n=U(R++,3);!H.__s&&Se(n.__H,t)&&(n.__=e,n.u=t,z.__H.__h.push(n))}function K(e){return V=5,ve(function(){return{current:e}},[])}function ve(e,t){var n=U(R++,7);return Se(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function ye(){for(var e;e=ue.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(q),t.__h.some(J),t.__h=[]}catch(n){t.__h=[],H.__e(n,e.__v)}}}H.__b=function(e){z=null,de&&de(e)},H.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ge&&ge(e,t)},H.__r=function(e){fe&&fe(e),R=0;var t=(z=e.__c).__H;t&&(B===z?(t.__h=[],z.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(q),t.__h.some(J),t.__h=[],R=0)),B=z},H.diffed=function(e){pe&&pe(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(ue.push(t)!==1&&le===H.requestAnimationFrame||((le=H.requestAnimationFrame)||xe)(ye)),t.__H.__.some(function(e){e.u&&=(e.__H=e.u,void 0)})),B=z=null},H.__c=function(e,t){t.some(function(e){try{e.__h.some(q),e.__h=e.__h.filter(function(e){return!e.__||J(e)})}catch(n){t.some(function(e){e.__h&&=[]}),t=[],H.__e(n,e.__v)}}),me&&me(e,t)},H.unmount=function(e){he&&he(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{q(e)}catch(e){t=e}}),n.__H=void 0,t&&H.__e(t,n.__v))};var be=typeof requestAnimationFrame==`function`;function xe(e){var t,n=function(){clearTimeout(r),be&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);be&&(t=requestAnimationFrame(n))}function q(e){var t=z,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),z=t}function J(e){var t=z;e.__c=e.__(),z=t}function Se(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function Ce(e,t){return typeof t==`function`?t(e):t}var we=0;Array.isArray;function Y(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:--we,__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 Te({isOpen:e,onClick:t,logoUrl:n,buttonRef:r}){return Y(`button`,{type:`button`,class:`whoo-widget-launcher`,onClick:t,"aria-label":e?`Close chat`:`Open chat`,ref:r,children:e?Y(`span`,{"aria-hidden":`true`,children:`✕`}):n?Y(`img`,{class:`whoo-widget-launcher-logo`,src:n,alt:``}):Y(`span`,{"aria-hidden":`true`,children:`💬`})})}function Ee({value:e,onChange:t,onSend:n,disabled:r,inputRef:i}){return Y(`div`,{class:`whoo-widget-composer`,children:[Y(`label`,{class:`whoo-widget-sr-only`,for:`whoo-widget-composer-input`,children:`Message`}),Y(`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()}}),Y(`button`,{type:`button`,class:`whoo-widget-composer-send`,onClick:n,disabled:r,children:`Send`})]})}function De({message:e}){return Y(`div`,{class:`whoo-widget-error-banner`,role:`alert`,children:e})}var X=/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/y,Z=/\*\*([^*]+)\*\*/y,Q=/(?<![A-Za-z0-9_])_([^_\s](?:[^_]*[^_\s])?)_(?![A-Za-z0-9_])/y,$=/\*([^*]+)\*/y,Oe=/https?:\/\/\S+/y,ke=/[.,;:!?)\]}>]+$/;function Ae(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]!==`!`){X.lastIndex=n;let a=X.exec(e);if(a){i(n),t.push({type:`link`,text:a[1],url:a[2],start:n,end:X.lastIndex}),n=X.lastIndex,r=n;continue}}Z.lastIndex=n;let a=Z.exec(e);if(a){i(n),t.push({type:`bold`,value:a[1],start:n,end:Z.lastIndex}),n=Z.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}$.lastIndex=n;let s=$.exec(e);if(s){i(n),t.push({type:`italic`,value:s[1],start:n,end:$.lastIndex}),n=$.lastIndex,r=n;continue}Oe.lastIndex=n;let c=Oe.exec(e);if(c){let e=c[0].match(ke),a=e?c[0].slice(0,c[0].length-e[0].length):c[0];if(a.length>0){i(n),t.push({type:`link`,text:a,url:a,start:n,end:n+a.length}),n+=a.length,r=n;continue}}n+=1}return i(e.length),t}function je(e){return Ae(e).map((e,t)=>{switch(e.type){case`bold`:return Y(`strong`,{children:e.value},t);case`italic`:return Y(`em`,{children:e.value},t);case`link`:return Y(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,children:[e.text,Y(`span`,{class:`whoo-widget-sr-only`,children:` (opens in new tab)`})]},t);default:return e.value}})}var Me=[{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 Ne({state:e,containerRef:t,onThumbsUp:n,onThumbsDown:r,onSubmitDetailed:i,onCancel:a}){let[o,s]=W(``),[c,l]=W(``),u=K(e.status);if(G(()=>{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 Y(`div`,{class:`whoo-widget-feedback-submitted`,role:`status`,children:`Thanks for the feedback`});if(e.status===`expanded`)return Y(`div`,{class:`whoo-widget-feedback-form`,children:[Y(`label`,{children:[Y(`span`,{class:`whoo-widget-sr-only`,children:`Additional feedback`}),Y(`textarea`,{class:`whoo-widget-feedback-textarea`,value:o,onInput:e=>s(e.target.value),placeholder:`What was wrong? (optional)`})]}),Y(`select`,{class:`whoo-widget-feedback-select`,"aria-label":`Feedback category`,value:c,onChange:e=>l(e.target.value),children:Me.map(e=>Y(`option`,{value:e.value,children:e.label},e.value))}),Y(`div`,{class:`whoo-widget-feedback-form-buttons`,children:[Y(`button`,{type:`button`,class:`whoo-widget-feedback-submit`,onClick:()=>i(o,c),children:`Submit`}),Y(`button`,{type:`button`,class:`whoo-widget-feedback-cancel`,onClick:a,children:`Cancel`})]})]});let d=e.status===`submitting`;return Y(`div`,{class:`whoo-widget-feedback`,children:[Y(`div`,{class:`whoo-widget-feedback-buttons`,children:[Y(`button`,{type:`button`,"aria-label":`Good response`,disabled:d,onClick:n,children:`👍`}),Y(`button`,{type:`button`,"aria-label":`Bad response`,disabled:d,onClick:r,children:`👎`})]}),e.status===`error`?Y(`div`,{class:`whoo-widget-feedback-error`,role:`status`,children:`Couldn't send feedback`}):null]})}function Pe({message:e,feedbackState:t,onThumbsUp:n,onThumbsDown:r,onSubmitDetailed:i,onCancelFeedback:a}){let o=K(null),s=e.id;return Y(`div`,{ref:o,tabIndex:-1,class:`whoo-widget-message whoo-widget-message--${e.role}`,children:[je(e.content),e.role===`assistant`&&s?Y(Ne,{state:t,containerRef:o,onThumbsUp:()=>n(s),onThumbsDown:()=>r(s),onSubmitDetailed:(e,t)=>i(s,e,t),onCancel:()=>a(s)}):null]})}function Fe({messages:e,messageFeedback:t,lastCompletedMessageText:n,onThumbsUp:r,onThumbsDown:i,onSubmitDetailed:a,onCancelFeedback:o}){let s=K(null);return G(()=>{let e=s.current;e&&(e.scrollTop=e.scrollHeight)},[e]),Y(w,{children:[Y(`div`,{class:`whoo-widget-message-list`,ref:s,children:e.map((e,n)=>Y(Pe,{message:e,feedbackState:e.id?t[e.id]??{status:`idle`}:{status:`idle`},onThumbsUp:r,onThumbsDown:i,onSubmitDetailed:a,onCancelFeedback:o},e.id??n))}),Y(`div`,{class:`whoo-widget-sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:n??``})]})}var Ie=`button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])`;function Le(e){return Array.from(e.querySelectorAll(Ie)).filter(e=>{let t=getComputedStyle(e);return t.display!==`none`&&t.visibility!==`hidden`})}function Re({state:e,controller:t,greeting:n}){let[r,i]=W(``),a=K(null),o=K(null);G(()=>{o.current?.focus()},[]);let s=e=>{if(e.key===`Escape`){t.close();return}if(e.key!==`Tab`)return;let n=a.current;if(!n)return;let r=Le(n);if(r.length===0)return;let i=r[0],o=r[r.length-1],s=n.getRootNode().activeElement;if(!n.contains(s)){e.preventDefault(),i.focus();return}e.shiftKey&&s===i?(e.preventDefault(),o.focus()):!e.shiftKey&&s===o&&(e.preventDefault(),i.focus())},c=()=>{let n=r.trim();!n||e.isStreaming||(i(``),t.sendMessage(n))},l=e.messages.length===0&&n?[{role:`assistant`,content:n,id:null}]:e.messages;return Y(`div`,{class:`whoo-widget-panel`,role:`dialog`,"aria-modal":`true`,"aria-label":`Chat with Aiden`,ref:a,onKeyDown:s,children:[Y(`div`,{class:`whoo-widget-header`,children:[Y(`button`,{type:`button`,class:`whoo-widget-header-close`,onClick:()=>t.close(),children:`Close chat`}),e.messages.length>0&&Y(`button`,{type:`button`,class:`whoo-widget-header-reset`,onClick:()=>t.resetConversation(),children:`New conversation`})]}),Y(Fe,{messages:l,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&&Y(De,{message:e.runtimeError}),Y(Ee,{value:r,onChange:i,onSend:c,disabled:e.isStreaming,inputRef:o})]})}function ze({controller:e}){let[t,n]=W(e.getState()),r=K(null),i=K(t.isOpen);return G(()=>(n(e.getState()),e.subscribe(n)),[e]),G(()=>{i.current&&!t.isOpen&&r.current?.focus(),i.current=t.isOpen},[t.isOpen]),t.initError?null:Y(w,{children:[Y(Te,{isOpen:t.isOpen,onClick:()=>t.isOpen?e.close():e.open(),logoUrl:e.config.logoUrl,buttonRef:r}),t.isOpen&&Y(Re,{state:t,controller:e,greeting:e.config.greeting})]})}var Be=class extends Error{status;constructor(e,t){super(e),this.name=`WidgetApiError`,this.status=t}};async function Ve(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 Be(`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 He(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 Be(`Feedback submission failed (${r.status})`,r.status)}async function*Ue(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 Be(`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 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(`
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 We(JSON.parse(t.slice(6)))),n=c.indexOf(`
4
+ `).find(e=>e.startsWith(`data: `));t&&(yield Qe(JSON.parse(t.slice(6)))),n=c.indexOf(`
5
5
 
6
- `)}}}function We(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 Ge=40,Ke=120;function qe(e){let t=[];for(let n of Ae(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 Je(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 Ye(e,t,n){let r=n?.wordIntervalMs??Ge,i=n?.tokenIntervalMs??Ke,a=n?.signal,o=Ae(e),s=new Set(o.filter(e=>e.type!==`text`).map(e=>e.end)),c=Je(a),l=``;for(let n of qe(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 Xe(e){return`whoo-aiden-widget:conversation:${e}`}function Ze(e){try{return window.sessionStorage.getItem(Xe(e))}catch{return null}}function Qe(e,t){try{window.sessionStorage.setItem(Xe(e),t)}catch{}}function $e(e){try{window.sessionStorage.removeItem(Xe(e))}catch{}}var et=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}}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 Ve(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=Ze(this.storageIdentifier)}open(){this.setState({isOpen:!0})}resetConversation(){this.activeRequestController?.abort(),this.activeRequestController=null,this.conversationId=null,$e(this.storageIdentifier),this.setState({messages:[],messageFeedback:{},runtimeError:null,isStreaming:!1,lastCompletedMessageText:null})}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=``;try{for await(let n of Ue(t,this.sessionToken,this.conversationId,e,a))if(n.type===`conversation_id`)this.conversationId=n.conversationId,Qe(this.storageIdentifier,n.conversationId);else if(n.type===`delta`)n.verbatim&&!this.prefersReducedMotion?(await Ye(n.delta,e=>i(e),{signal:a}),o=n.delta):n.verbatim?(o=n.delta,i(o)):(o+=n.delta,i(o));else if(n.type===`done`){if(n.conversationId&&(this.conversationId=n.conversationId,Qe(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:o})}else n.type===`error`&&(console.error(`[whoo-aiden-widget] chat error:`,n.error),this.setState({runtimeError:`Something went wrong, please try again.`}))}catch(e){e?.name===`AbortError`||(console.error(`[whoo-aiden-widget] chat request failed:`,e),this.setState({runtimeError:`Something went wrong, please try again.`}))}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 He(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}}})}}},tt=`: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-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;height:480px;max-height:90vh;display:flex;position:fixed;overflow:hidden;box-shadow:0 4px 16px #0003}.whoo-widget-header{flex-shrink:0;justify-content:space-between;align-items:center;padding:8px 12px 0;display:flex}.whoo-widget-header-close,.whoo-widget-header-reset{color:var(--whoo-widget-color,#4f46e5);cursor:pointer;background:0 0;border:none;padding:4px 6px;font-size:12px}.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;opacity:.6;background:0 0;border:none;padding:2px 4px;font-size:14px}.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;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 nt(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+)/);return r?[Number(r[1]),Number(r[2]),Number(r[3])]:null}function rt([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 it(e,t){let n=Math.max(e,t),r=Math.min(e,t);return(n+.05)/(r+.05)}function at(e){let t=nt(e);if(!t)return console.warn(`[whoo-aiden-widget] Could not parse color "${e}" for contrast calculation; defaulting to white text.`),`#ffffff`;let n=rt(t);return it(n,rt([0,0,0]))>=it(n,rt([255,255,255]))?`#000000`:`#ffffff`}function ot(e,t){let n=t.color??`#4f46e5`;e.style.setProperty(`--whoo-widget-color`,n),e.style.setProperty(`--whoo-widget-text-on-color`,at(n));let r=t.position===`bottom-left`;e.style.setProperty(`--whoo-widget-inset-left`,r?`20px`:`auto`),e.style.setProperty(`--whoo-widget-inset-right`,r?`auto`:`20px`)}function st(e){let t=document.createElement(`div`);t.id=`whoo-aiden-widget-host`;let n=t.attachShadow({mode:`open`}),r=document.createElement(`style`);r.textContent=tt,n.appendChild(r);let i=document.createElement(`div`);n.appendChild(i),ot(i,e);let a=new et(e);return a.subscribe(e=>{e.primaryColor&&(i.style.setProperty(`--whoo-widget-color`,e.primaryColor),i.style.setProperty(`--whoo-widget-text-on-color`,at(e.primaryColor)))}),ce(Y(ze,{controller:a}),i),a.init(),document.body.appendChild(t),{unmount(){ce(null,i),t.remove()}}}function ct(e){return t(e),st(e)}return e.init=ct,e})({});
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})({});
package/dist/widget.js CHANGED
@@ -253,20 +253,20 @@ t = g.slice, n = { __e: function(e, t, n, r) {
253
253
  }, k.__r = 0, c = Math.random().toString(8), l = "__d" + c, u = "__a" + c, d = /(PointerCapture)$|Capture$/i, f = 0, p = te(!1), m = te(!0);
254
254
  //#endregion
255
255
  //#region node_modules/.pnpm/preact@10.29.8/node_modules/preact/hooks/dist/hooks.module.js
256
- var L, R, le, ue, z = 0, de = [], B = n, fe = B.__b, pe = B.__r, me = B.diffed, he = B.__c, ge = B.unmount, _e = B.__;
257
- function V(e, t) {
258
- B.__h && B.__h(R, e, z || t), z = 0;
256
+ var L, R, z, le, B = 0, ue = [], V = n, de = V.__b, fe = V.__r, pe = V.diffed, me = V.__c, he = V.unmount, ge = V.__;
257
+ function H(e, t) {
258
+ V.__h && V.__h(R, e, B || t), B = 0;
259
259
  var n = R.__H || (R.__H = {
260
260
  __: [],
261
261
  __h: []
262
262
  });
263
263
  return e >= n.__.length && n.__.push({}), n.__[e];
264
264
  }
265
- function H(e) {
266
- return z = 1, ve(we, e);
265
+ function U(e) {
266
+ return B = 1, _e(we, e);
267
267
  }
268
- function ve(e, t, n) {
269
- var r = V(L++, 2);
268
+ function _e(e, t, n) {
269
+ var r = H(L++, 2);
270
270
  if (r.t = e, !r.__c && (r.__ = [n ? n(t) : we(void 0, t), function(e) {
271
271
  var t = r.__N ? r.__N[0] : r.__[0], n = r.t(t, e);
272
272
  t !== n && (r.__N = [n, r.__[1]], r.__c.setState({}));
@@ -298,80 +298,80 @@ function ve(e, t, n) {
298
298
  }
299
299
  return r.__N || r.__;
300
300
  }
301
- function U(e, t) {
302
- var n = V(L++, 3);
303
- !B.__s && Ce(n.__H, t) && (n.__ = e, n.u = t, R.__H.__h.push(n));
301
+ function W(e, t) {
302
+ var n = H(L++, 3);
303
+ !V.__s && Ce(n.__H, t) && (n.__ = e, n.u = t, R.__H.__h.push(n));
304
304
  }
305
- function W(e) {
306
- return z = 5, ye(function() {
305
+ function G(e) {
306
+ return B = 5, ve(function() {
307
307
  return { current: e };
308
308
  }, []);
309
309
  }
310
- function ye(e, t) {
311
- var n = V(L++, 7);
310
+ function ve(e, t) {
311
+ var n = H(L++, 7);
312
312
  return Ce(n.__H, t) && (n.__ = e(), n.__H = t, n.__h = e), n.__;
313
313
  }
314
- function be() {
315
- for (var e; e = de.shift();) {
314
+ function ye() {
315
+ for (var e; e = ue.shift();) {
316
316
  var t = e.__H;
317
317
  if (e.__P && t) try {
318
- t.__h.some(G), t.__h.some(K), t.__h = [];
318
+ t.__h.some(K), t.__h.some(Se), t.__h = [];
319
319
  } catch (n) {
320
- t.__h = [], B.__e(n, e.__v);
320
+ t.__h = [], V.__e(n, e.__v);
321
321
  }
322
322
  }
323
323
  }
324
- B.__b = function(e) {
325
- R = null, fe && fe(e);
326
- }, B.__ = function(e, t) {
327
- e && t.__k && t.__k.__m && (e.__m = t.__k.__m), _e && _e(e, t);
328
- }, B.__r = function(e) {
329
- pe && pe(e), L = 0;
324
+ V.__b = function(e) {
325
+ R = null, de && de(e);
326
+ }, V.__ = function(e, t) {
327
+ e && t.__k && t.__k.__m && (e.__m = t.__k.__m), ge && ge(e, t);
328
+ }, V.__r = function(e) {
329
+ fe && fe(e), L = 0;
330
330
  var t = (R = e.__c).__H;
331
- t && (le === R ? (t.__h = [], R.__h = [], t.__.some(function(e) {
331
+ t && (z === R ? (t.__h = [], R.__h = [], t.__.some(function(e) {
332
332
  e.__N && (e.__ = e.__N), e.u = e.__N = void 0;
333
- })) : (t.__h.some(G), t.__h.some(K), t.__h = [], L = 0)), le = R;
334
- }, B.diffed = function(e) {
335
- me && me(e);
333
+ })) : (t.__h.some(K), t.__h.some(Se), t.__h = [], L = 0)), z = R;
334
+ }, V.diffed = function(e) {
335
+ pe && pe(e);
336
336
  var t = e.__c;
337
- t && t.__H && (t.__H.__h.length && (de.push(t) !== 1 && ue === B.requestAnimationFrame || ((ue = B.requestAnimationFrame) || Se)(be)), t.__H.__.some(function(e) {
337
+ t && t.__H && (t.__H.__h.length && (ue.push(t) !== 1 && le === V.requestAnimationFrame || ((le = V.requestAnimationFrame) || xe)(ye)), t.__H.__.some(function(e) {
338
338
  e.u &&= (e.__H = e.u, void 0);
339
- })), le = R = null;
340
- }, B.__c = function(e, t) {
339
+ })), z = R = null;
340
+ }, V.__c = function(e, t) {
341
341
  t.some(function(e) {
342
342
  try {
343
- e.__h.some(G), e.__h = e.__h.filter(function(e) {
344
- return !e.__ || K(e);
343
+ e.__h.some(K), e.__h = e.__h.filter(function(e) {
344
+ return !e.__ || Se(e);
345
345
  });
346
346
  } catch (n) {
347
347
  t.some(function(e) {
348
348
  e.__h &&= [];
349
- }), t = [], B.__e(n, e.__v);
349
+ }), t = [], V.__e(n, e.__v);
350
350
  }
351
- }), he && he(e, t);
352
- }, B.unmount = function(e) {
353
- ge && ge(e);
351
+ }), me && me(e, t);
352
+ }, V.unmount = function(e) {
353
+ he && he(e);
354
354
  var t, n = e.__c;
355
355
  n && n.__H && (n.__H.__.some(function(e) {
356
356
  try {
357
- G(e);
357
+ K(e);
358
358
  } catch (e) {
359
359
  t = e;
360
360
  }
361
- }), n.__H = void 0, t && B.__e(t, n.__v));
361
+ }), n.__H = void 0, t && V.__e(t, n.__v));
362
362
  };
363
- var xe = typeof requestAnimationFrame == "function";
364
- function Se(e) {
363
+ var be = typeof requestAnimationFrame == "function";
364
+ function xe(e) {
365
365
  var t, n = function() {
366
- clearTimeout(r), xe && cancelAnimationFrame(t), setTimeout(e);
366
+ clearTimeout(r), be && cancelAnimationFrame(t), setTimeout(e);
367
367
  }, r = setTimeout(n, 35);
368
- xe && (t = requestAnimationFrame(n));
368
+ be && (t = requestAnimationFrame(n));
369
369
  }
370
- function G(e) {
370
+ function K(e) {
371
371
  var t = R, n = e.__c;
372
372
  typeof n == "function" && (e.__c = void 0, n()), R = t;
373
373
  }
374
- function K(e) {
374
+ function Se(e) {
375
375
  var t = R;
376
376
  e.__c = e.__(), R = t;
377
377
  }
@@ -412,30 +412,84 @@ function q(e, t, r, i, a, o) {
412
412
  return n.vnode && n.vnode(u), u;
413
413
  }
414
414
  //#endregion
415
+ //#region src/components/icons.tsx
416
+ function J({ name: e, size: t, children: n }) {
417
+ return /* @__PURE__ */ q("svg", {
418
+ "data-icon": e,
419
+ "aria-hidden": "true",
420
+ focusable: "false",
421
+ width: t,
422
+ height: t,
423
+ viewBox: "0 0 24 24",
424
+ fill: "none",
425
+ stroke: "currentColor",
426
+ "stroke-width": "2",
427
+ "stroke-linecap": "round",
428
+ "stroke-linejoin": "round",
429
+ children: n
430
+ });
431
+ }
432
+ function Ee({ size: e = 26 }) {
433
+ return /* @__PURE__ */ q(J, {
434
+ name: "chat",
435
+ size: e,
436
+ children: [/* @__PURE__ */ 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" }), /* @__PURE__ */ q("path", {
437
+ d: "M8.5 9.5h.01M12 9.5h.01M15.5 9.5h.01",
438
+ "stroke-width": "2.5"
439
+ })]
440
+ });
441
+ }
442
+ function De({ size: e = 26 }) {
443
+ return /* @__PURE__ */ q(J, {
444
+ name: "chevron-down",
445
+ size: e,
446
+ children: /* @__PURE__ */ q("path", { d: "M6 9l6 6 6-6" })
447
+ });
448
+ }
449
+ function Oe({ size: e = 18 }) {
450
+ return /* @__PURE__ */ q(J, {
451
+ name: "close",
452
+ size: e,
453
+ children: /* @__PURE__ */ q("path", { d: "M6 6l12 12M18 6L6 18" })
454
+ });
455
+ }
456
+ var ke = "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";
457
+ function Ae({ size: e = 16 }) {
458
+ return /* @__PURE__ */ q(J, {
459
+ name: "thumb-up",
460
+ size: e,
461
+ children: /* @__PURE__ */ q("path", { d: ke })
462
+ });
463
+ }
464
+ function je({ size: e = 16 }) {
465
+ return /* @__PURE__ */ q(J, {
466
+ name: "thumb-down",
467
+ size: e,
468
+ children: /* @__PURE__ */ q("path", {
469
+ d: ke,
470
+ transform: "matrix(1 0 0 -1 0 24)"
471
+ })
472
+ });
473
+ }
474
+ //#endregion
415
475
  //#region src/components/Launcher.tsx
416
- function Ee({ isOpen: e, onClick: t, logoUrl: n, buttonRef: r }) {
476
+ function Me({ isOpen: e, onClick: t, logoUrl: n, buttonRef: r }) {
417
477
  return /* @__PURE__ */ q("button", {
418
478
  type: "button",
419
479
  class: "whoo-widget-launcher",
420
480
  onClick: t,
421
481
  "aria-label": e ? "Close chat" : "Open chat",
422
482
  ref: r,
423
- children: e ? /* @__PURE__ */ q("span", {
424
- "aria-hidden": "true",
425
- children: "✕"
426
- }) : n ? /* @__PURE__ */ q("img", {
483
+ children: e ? /* @__PURE__ */ q(De, {}) : n ? /* @__PURE__ */ q("img", {
427
484
  class: "whoo-widget-launcher-logo",
428
485
  src: n,
429
486
  alt: ""
430
- }) : /* @__PURE__ */ q("span", {
431
- "aria-hidden": "true",
432
- children: "💬"
433
- })
487
+ }) : /* @__PURE__ */ q(Ee, {})
434
488
  });
435
489
  }
436
490
  //#endregion
437
491
  //#region src/components/Composer.tsx
438
- function De({ value: e, onChange: t, onSend: n, disabled: r, inputRef: i }) {
492
+ function Ne({ value: e, onChange: t, onSend: n, disabled: r, inputRef: i }) {
439
493
  return /* @__PURE__ */ q("div", {
440
494
  class: "whoo-widget-composer",
441
495
  children: [
@@ -468,7 +522,7 @@ function De({ value: e, onChange: t, onSend: n, disabled: r, inputRef: i }) {
468
522
  }
469
523
  //#endregion
470
524
  //#region src/components/ErrorBanner.tsx
471
- function Oe({ message: e }) {
525
+ function Pe({ message: e }) {
472
526
  return /* @__PURE__ */ q("div", {
473
527
  class: "whoo-widget-error-banner",
474
528
  role: "alert",
@@ -477,8 +531,8 @@ function Oe({ message: e }) {
477
531
  }
478
532
  //#endregion
479
533
  //#region src/markdown/tokenizer.ts
480
- var J = /\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/y, Y = /\*\*([^*]+)\*\*/y, X = /(?<![A-Za-z0-9_])_([^_\s](?:[^_]*[^_\s])?)_(?![A-Za-z0-9_])/y, Z = /\*([^*]+)\*/y, ke = /https?:\/\/\S+/y, Ae = /[.,;:!?)\]}>]+$/;
481
- function Q(e) {
534
+ var Y = /\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/y, X = /\*\*([^*]+)\*\*/y, Z = /(?<![A-Za-z0-9_])_([^_\s](?:[^_]*[^_\s])?)_(?![A-Za-z0-9_])/y, Q = /\*([^*]+)\*/y, Fe = /https?:\/\/\S+/y, Ie = /[.,;:!?)\]}>]+$/;
535
+ function Le(e) {
482
536
  let t = [], n = 0, r = 0, i = (n) => {
483
537
  n > r && t.push({
484
538
  type: "text",
@@ -498,56 +552,56 @@ function Q(e) {
498
552
  }
499
553
  }
500
554
  if (e[n - 1] !== "!") {
501
- J.lastIndex = n;
502
- let a = J.exec(e);
555
+ Y.lastIndex = n;
556
+ let a = Y.exec(e);
503
557
  if (a) {
504
558
  i(n), t.push({
505
559
  type: "link",
506
560
  text: a[1],
507
561
  url: a[2],
508
562
  start: n,
509
- end: J.lastIndex
510
- }), n = J.lastIndex, r = n;
563
+ end: Y.lastIndex
564
+ }), n = Y.lastIndex, r = n;
511
565
  continue;
512
566
  }
513
567
  }
514
- Y.lastIndex = n;
515
- let a = Y.exec(e);
568
+ X.lastIndex = n;
569
+ let a = X.exec(e);
516
570
  if (a) {
517
571
  i(n), t.push({
518
572
  type: "bold",
519
573
  value: a[1],
520
574
  start: n,
521
- end: Y.lastIndex
522
- }), n = Y.lastIndex, r = n;
575
+ end: X.lastIndex
576
+ }), n = X.lastIndex, r = n;
523
577
  continue;
524
578
  }
525
- X.lastIndex = n;
526
- let o = X.exec(e);
579
+ Z.lastIndex = n;
580
+ let o = Z.exec(e);
527
581
  if (o) {
528
582
  i(n), t.push({
529
583
  type: "italic",
530
584
  value: o[1],
531
585
  start: n,
532
- end: X.lastIndex
533
- }), n = X.lastIndex, r = n;
586
+ end: Z.lastIndex
587
+ }), n = Z.lastIndex, r = n;
534
588
  continue;
535
589
  }
536
- Z.lastIndex = n;
537
- let s = Z.exec(e);
590
+ Q.lastIndex = n;
591
+ let s = Q.exec(e);
538
592
  if (s) {
539
593
  i(n), t.push({
540
594
  type: "italic",
541
595
  value: s[1],
542
596
  start: n,
543
- end: Z.lastIndex
544
- }), n = Z.lastIndex, r = n;
597
+ end: Q.lastIndex
598
+ }), n = Q.lastIndex, r = n;
545
599
  continue;
546
600
  }
547
- ke.lastIndex = n;
548
- let c = ke.exec(e);
601
+ Fe.lastIndex = n;
602
+ let c = Fe.exec(e);
549
603
  if (c) {
550
- let e = c[0].match(Ae), a = e ? c[0].slice(0, c[0].length - e[0].length) : c[0];
604
+ let e = c[0].match(Ie), a = e ? c[0].slice(0, c[0].length - e[0].length) : c[0];
551
605
  if (a.length > 0) {
552
606
  i(n), t.push({
553
607
  type: "link",
@@ -565,8 +619,8 @@ function Q(e) {
565
619
  }
566
620
  //#endregion
567
621
  //#region src/markdown/render.tsx
568
- function je(e) {
569
- return Q(e).map((e, t) => {
622
+ function Re(e) {
623
+ return Le(e).map((e, t) => {
570
624
  switch (e.type) {
571
625
  case "bold": return /* @__PURE__ */ q("strong", { children: e.value }, t);
572
626
  case "italic": return /* @__PURE__ */ q("em", { children: e.value }, t);
@@ -585,7 +639,7 @@ function je(e) {
585
639
  }
586
640
  //#endregion
587
641
  //#region src/components/MessageFeedback.tsx
588
- var Me = [
642
+ var ze = [
589
643
  {
590
644
  value: "",
591
645
  label: "Select a reason (optional)"
@@ -607,9 +661,9 @@ var Me = [
607
661
  label: "Other"
608
662
  }
609
663
  ];
610
- function Ne({ state: e, containerRef: t, onThumbsUp: n, onThumbsDown: r, onSubmitDetailed: i, onCancel: a }) {
611
- let [o, s] = H(""), [c, l] = H(""), u = W(e.status);
612
- if (U(() => {
664
+ function Be({ state: e, containerRef: t, onThumbsUp: n, onThumbsDown: r, onSubmitDetailed: i, onCancel: a }) {
665
+ let [o, s] = U(""), [c, l] = U(""), u = G(e.status);
666
+ if (W(() => {
613
667
  let n = u.current;
614
668
  if (u.current = e.status, n === e.status) return;
615
669
  let r = t?.current;
@@ -638,7 +692,7 @@ function Ne({ state: e, containerRef: t, onThumbsUp: n, onThumbsDown: r, onSubmi
638
692
  "aria-label": "Feedback category",
639
693
  value: c,
640
694
  onChange: (e) => l(e.target.value),
641
- children: Me.map((e) => /* @__PURE__ */ q("option", {
695
+ children: ze.map((e) => /* @__PURE__ */ q("option", {
642
696
  value: e.value,
643
697
  children: e.label
644
698
  }, e.value))
@@ -669,13 +723,13 @@ function Ne({ state: e, containerRef: t, onThumbsUp: n, onThumbsDown: r, onSubmi
669
723
  "aria-label": "Good response",
670
724
  disabled: d,
671
725
  onClick: n,
672
- children: "👍"
726
+ children: /* @__PURE__ */ q(Ae, {})
673
727
  }), /* @__PURE__ */ q("button", {
674
728
  type: "button",
675
729
  "aria-label": "Bad response",
676
730
  disabled: d,
677
731
  onClick: r,
678
- children: "👎"
732
+ children: /* @__PURE__ */ q(je, {})
679
733
  })]
680
734
  }), e.status === "error" ? /* @__PURE__ */ q("div", {
681
735
  class: "whoo-widget-feedback-error",
@@ -686,13 +740,13 @@ function Ne({ state: e, containerRef: t, onThumbsUp: n, onThumbsDown: r, onSubmi
686
740
  }
687
741
  //#endregion
688
742
  //#region src/components/MessageList.tsx
689
- function Pe({ message: e, feedbackState: t, onThumbsUp: n, onThumbsDown: r, onSubmitDetailed: i, onCancelFeedback: a }) {
690
- let o = W(null), s = e.id;
743
+ function Ve({ message: e, feedbackState: t, onThumbsUp: n, onThumbsDown: r, onSubmitDetailed: i, onCancelFeedback: a }) {
744
+ let o = G(null), s = e.id;
691
745
  return /* @__PURE__ */ q("div", {
692
746
  ref: o,
693
747
  tabIndex: -1,
694
748
  class: `whoo-widget-message whoo-widget-message--${e.role}`,
695
- children: [je(e.content), e.role === "assistant" && s ? /* @__PURE__ */ q(Ne, {
749
+ children: [Re(e.content), e.role === "assistant" && s ? /* @__PURE__ */ q(Be, {
696
750
  state: t,
697
751
  containerRef: o,
698
752
  onThumbsUp: () => n(s),
@@ -702,15 +756,15 @@ function Pe({ message: e, feedbackState: t, onThumbsUp: n, onThumbsDown: r, onSu
702
756
  }) : null]
703
757
  });
704
758
  }
705
- function Fe({ messages: e, messageFeedback: t, lastCompletedMessageText: n, onThumbsUp: r, onThumbsDown: i, onSubmitDetailed: a, onCancelFeedback: o }) {
706
- let s = W(null);
707
- return U(() => {
759
+ function He({ messages: e, messageFeedback: t, lastCompletedMessageText: n, onThumbsUp: r, onThumbsDown: i, onSubmitDetailed: a, onCancelFeedback: o }) {
760
+ let s = G(null);
761
+ return W(() => {
708
762
  let e = s.current;
709
763
  e && (e.scrollTop = e.scrollHeight);
710
764
  }, [e]), /* @__PURE__ */ q(C, { children: [/* @__PURE__ */ q("div", {
711
765
  class: "whoo-widget-message-list",
712
766
  ref: s,
713
- children: e.map((e, n) => /* @__PURE__ */ q(Pe, {
767
+ children: e.map((e, n) => /* @__PURE__ */ q(Ve, {
714
768
  message: e,
715
769
  feedbackState: e.id ? t[e.id] ?? { status: "idle" } : { status: "idle" },
716
770
  onThumbsUp: r,
@@ -727,38 +781,38 @@ function Fe({ messages: e, messageFeedback: t, lastCompletedMessageText: n, onTh
727
781
  }
728
782
  //#endregion
729
783
  //#region src/components/Panel.tsx
730
- var Ie = "button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex=\"-1\"])";
731
- function Le(e) {
732
- return Array.from(e.querySelectorAll(Ie)).filter((e) => {
784
+ var Ue = "button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex=\"-1\"])";
785
+ function We(e) {
786
+ return Array.from(e.querySelectorAll(Ue)).filter((e) => {
733
787
  let t = getComputedStyle(e);
734
788
  return t.display !== "none" && t.visibility !== "hidden";
735
789
  });
736
790
  }
737
- function Re({ state: e, controller: t, greeting: n }) {
738
- let [r, i] = H(""), a = W(null), o = W(null);
739
- U(() => {
740
- o.current?.focus();
791
+ function Ge({ state: e, controller: t, greeting: n }) {
792
+ let r = G(null), i = G(null);
793
+ W(() => {
794
+ i.current?.focus();
741
795
  }, []);
742
- let s = (e) => {
796
+ let a = (e) => {
743
797
  if (e.key === "Escape") {
744
798
  t.close();
745
799
  return;
746
800
  }
747
801
  if (e.key !== "Tab") return;
748
- let n = a.current;
802
+ let n = r.current;
749
803
  if (!n) return;
750
- let r = Le(n);
751
- if (r.length === 0) return;
752
- let i = r[0], o = r[r.length - 1], s = n.getRootNode().activeElement;
804
+ let i = We(n);
805
+ if (i.length === 0) return;
806
+ let a = i[0], o = i[i.length - 1], s = n.getRootNode().activeElement;
753
807
  if (!n.contains(s)) {
754
- e.preventDefault(), i.focus();
808
+ e.preventDefault(), a.focus();
755
809
  return;
756
810
  }
757
- e.shiftKey && s === i ? (e.preventDefault(), o.focus()) : !e.shiftKey && s === o && (e.preventDefault(), i.focus());
758
- }, c = () => {
759
- let n = r.trim();
760
- !n || e.isStreaming || (i(""), t.sendMessage(n));
761
- }, l = e.messages.length === 0 && n ? [{
811
+ e.shiftKey && s === a ? (e.preventDefault(), o.focus()) : !e.shiftKey && s === o && (e.preventDefault(), a.focus());
812
+ }, o = () => {
813
+ let n = e.draft.trim();
814
+ !n || e.isStreaming || (t.setDraft(""), t.sendMessage(n));
815
+ }, s = e.messages.length === 0 && n ? [{
762
816
  role: "assistant",
763
817
  content: n,
764
818
  id: null
@@ -768,25 +822,32 @@ function Re({ state: e, controller: t, greeting: n }) {
768
822
  role: "dialog",
769
823
  "aria-modal": "true",
770
824
  "aria-label": "Chat with Aiden",
771
- ref: a,
772
- onKeyDown: s,
825
+ ref: r,
826
+ onKeyDown: a,
773
827
  children: [
774
828
  /* @__PURE__ */ q("div", {
775
829
  class: "whoo-widget-header",
776
- children: [/* @__PURE__ */ q("button", {
777
- type: "button",
778
- class: "whoo-widget-header-close",
779
- onClick: () => t.close(),
780
- children: "Close chat"
781
- }), e.messages.length > 0 && /* @__PURE__ */ q("button", {
782
- type: "button",
783
- class: "whoo-widget-header-reset",
784
- onClick: () => t.resetConversation(),
785
- children: "New conversation"
830
+ children: [/* @__PURE__ */ q("h2", {
831
+ class: "whoo-widget-header-title",
832
+ children: "Chat with Aiden"
833
+ }), /* @__PURE__ */ q("div", {
834
+ class: "whoo-widget-header-actions",
835
+ children: [e.messages.length > 0 && /* @__PURE__ */ q("button", {
836
+ type: "button",
837
+ class: "whoo-widget-header-reset",
838
+ onClick: () => t.resetConversation(),
839
+ children: "New conversation"
840
+ }), /* @__PURE__ */ q("button", {
841
+ type: "button",
842
+ class: "whoo-widget-header-close",
843
+ "aria-label": "Close chat",
844
+ onClick: () => t.close(),
845
+ children: /* @__PURE__ */ q(Oe, {})
846
+ })]
786
847
  })]
787
848
  }),
788
- /* @__PURE__ */ q(Fe, {
789
- messages: l,
849
+ /* @__PURE__ */ q(He, {
850
+ messages: s,
790
851
  messageFeedback: e.messageFeedback,
791
852
  lastCompletedMessageText: e.lastCompletedMessageText,
792
853
  onThumbsUp: (e) => t.submitFeedback(e, "up"),
@@ -794,29 +855,29 @@ function Re({ state: e, controller: t, greeting: n }) {
794
855
  onSubmitDetailed: (e, n, r) => t.submitFeedback(e, "down", n || void 0, r || void 0),
795
856
  onCancelFeedback: (e) => t.cancelFeedback(e)
796
857
  }),
797
- e.runtimeError && /* @__PURE__ */ q(Oe, { message: e.runtimeError }),
798
- /* @__PURE__ */ q(De, {
799
- value: r,
800
- onChange: i,
801
- onSend: c,
858
+ e.runtimeError && /* @__PURE__ */ q(Pe, { message: e.runtimeError }),
859
+ /* @__PURE__ */ q(Ne, {
860
+ value: e.draft,
861
+ onChange: (e) => t.setDraft(e),
862
+ onSend: o,
802
863
  disabled: e.isStreaming,
803
- inputRef: o
864
+ inputRef: i
804
865
  })
805
866
  ]
806
867
  });
807
868
  }
808
869
  //#endregion
809
870
  //#region src/components/App.tsx
810
- function ze({ controller: e }) {
811
- let [t, n] = H(e.getState()), r = W(null), i = W(t.isOpen);
812
- return U(() => (n(e.getState()), e.subscribe(n)), [e]), U(() => {
871
+ function Ke({ controller: e }) {
872
+ let [t, n] = U(e.getState()), r = G(null), i = G(t.isOpen);
873
+ return W(() => (n(e.getState()), e.subscribe(n)), [e]), W(() => {
813
874
  i.current && !t.isOpen && r.current?.focus(), i.current = t.isOpen;
814
- }, [t.isOpen]), t.initError ? null : /* @__PURE__ */ q(C, { children: [/* @__PURE__ */ q(Ee, {
875
+ }, [t.isOpen]), t.initError ? null : /* @__PURE__ */ q(C, { children: [/* @__PURE__ */ q(Me, {
815
876
  isOpen: t.isOpen,
816
877
  onClick: () => t.isOpen ? e.close() : e.open(),
817
878
  logoUrl: e.config.logoUrl,
818
879
  buttonRef: r
819
- }), t.isOpen && /* @__PURE__ */ q(Re, {
880
+ }), t.isOpen && /* @__PURE__ */ q(Ge, {
820
881
  state: t,
821
882
  controller: e,
822
883
  greeting: e.config.greeting
@@ -824,26 +885,26 @@ function ze({ controller: e }) {
824
885
  }
825
886
  //#endregion
826
887
  //#region src/api/client.ts
827
- var Be = class extends Error {
888
+ var qe = class extends Error {
828
889
  status;
829
890
  constructor(e, t) {
830
891
  super(e), this.name = "WidgetApiError", this.status = t;
831
892
  }
832
893
  };
833
- async function Ve(e, t) {
894
+ async function Je(e, t) {
834
895
  let n = await fetch(`${e}/api/v1/widget/session`, {
835
896
  method: "POST",
836
897
  headers: { "Content-Type": "application/json" },
837
898
  body: JSON.stringify({ publishable_key: t })
838
899
  });
839
- if (!n.ok) throw new Be(`Failed to create widget session (${n.status})`, n.status);
900
+ if (!n.ok) throw new qe(`Failed to create widget session (${n.status})`, n.status);
840
901
  let r = await n.json();
841
902
  return {
842
903
  token: r.token,
843
904
  primaryColor: r.primary_color ?? null
844
905
  };
845
906
  }
846
- async function He(e, t, n) {
907
+ async function Ye(e, t, n) {
847
908
  let r = await fetch(`${e}/api/v1/widget/feedback`, {
848
909
  method: "POST",
849
910
  headers: {
@@ -857,11 +918,11 @@ async function He(e, t, n) {
857
918
  category: n.category ?? null
858
919
  })
859
920
  });
860
- if (!r.ok) throw new Be(`Feedback submission failed (${r.status})`, r.status);
921
+ if (!r.ok) throw new qe(`Feedback submission failed (${r.status})`, r.status);
861
922
  }
862
923
  //#endregion
863
924
  //#region src/api/sse.ts
864
- async function* Ue(e, t, n, r, i) {
925
+ async function* Xe(e, t, n, r, i) {
865
926
  let a = await fetch(`${e}/api/v1/widget/chat`, {
866
927
  method: "POST",
867
928
  headers: {
@@ -874,7 +935,7 @@ async function* Ue(e, t, n, r, i) {
874
935
  }),
875
936
  signal: i
876
937
  });
877
- if (!a.ok || !a.body) throw new Be(`Chat request failed (${a.status})`, a.status);
938
+ if (!a.ok || !a.body) throw new qe(`Chat request failed (${a.status})`, a.status);
878
939
  let o = a.body.getReader(), s = new TextDecoder(), c = "";
879
940
  for (;;) {
880
941
  let { done: e, value: t } = await o.read();
@@ -885,11 +946,11 @@ async function* Ue(e, t, n, r, i) {
885
946
  let e = c.slice(0, n);
886
947
  c = c.slice(n + 2);
887
948
  let t = e.split("\n").find((e) => e.startsWith("data: "));
888
- t && (yield We(JSON.parse(t.slice(6)))), n = c.indexOf("\n\n");
949
+ t && (yield Ze(JSON.parse(t.slice(6)))), n = c.indexOf("\n\n");
889
950
  }
890
951
  }
891
952
  }
892
- function We(e) {
953
+ function Ze(e) {
893
954
  return typeof e.error == "string" ? {
894
955
  type: "error",
895
956
  error: e.error,
@@ -912,16 +973,16 @@ function We(e) {
912
973
  }
913
974
  //#endregion
914
975
  //#region src/markdown/reveal.ts
915
- var Ge = 40, Ke = 120;
916
- function qe(e) {
976
+ var Qe = 40, $e = 120;
977
+ function et(e) {
917
978
  let t = [];
918
- for (let n of Q(e)) if (n.type === "text") {
979
+ for (let n of Le(e)) if (n.type === "text") {
919
980
  let e = n.value.split(/(\s+)/), r = n.start;
920
981
  for (let n of e) r += n.length, n.trim().length > 0 && t.push(r);
921
982
  } else t.push(n.end);
922
983
  return t;
923
984
  }
924
- function Je(e) {
985
+ function tt(e) {
925
986
  let t = null;
926
987
  return e?.addEventListener("abort", () => {
927
988
  t?.();
@@ -936,36 +997,36 @@ function Je(e) {
936
997
  });
937
998
  };
938
999
  }
939
- async function Ye(e, t, n) {
940
- let r = n?.wordIntervalMs ?? Ge, i = n?.tokenIntervalMs ?? Ke, a = n?.signal, o = Q(e), s = new Set(o.filter((e) => e.type !== "text").map((e) => e.end)), c = Je(a), l = "";
941
- for (let n of qe(e)) if (a?.aborted || (l = e.slice(0, n), t(l), await c(s.has(n) ? i : r), a?.aborted)) return;
1000
+ async function nt(e, t, n) {
1001
+ let r = n?.wordIntervalMs ?? Qe, i = n?.tokenIntervalMs ?? $e, a = n?.signal, o = Le(e), s = new Set(o.filter((e) => e.type !== "text").map((e) => e.end)), c = tt(a), l = "";
1002
+ for (let n of et(e)) if (a?.aborted || (l = e.slice(0, n), t(l), await c(s.has(n) ? i : r), a?.aborted)) return;
942
1003
  l !== e && t(e);
943
1004
  }
944
1005
  //#endregion
945
1006
  //#region src/storage.ts
946
- function Xe(e) {
1007
+ function rt(e) {
947
1008
  return `whoo-aiden-widget:conversation:${e}`;
948
1009
  }
949
- function Ze(e) {
1010
+ function it(e) {
950
1011
  try {
951
- return window.sessionStorage.getItem(Xe(e));
1012
+ return window.sessionStorage.getItem(rt(e));
952
1013
  } catch {
953
1014
  return null;
954
1015
  }
955
1016
  }
956
- function Qe(e, t) {
1017
+ function at(e, t) {
957
1018
  try {
958
- window.sessionStorage.setItem(Xe(e), t);
1019
+ window.sessionStorage.setItem(rt(e), t);
959
1020
  } catch {}
960
1021
  }
961
- function $e(e) {
1022
+ function ot(e) {
962
1023
  try {
963
- window.sessionStorage.removeItem(Xe(e));
1024
+ window.sessionStorage.removeItem(rt(e));
964
1025
  } catch {}
965
1026
  }
966
1027
  //#endregion
967
1028
  //#region src/controller.ts
968
- var et = class {
1029
+ var st = class {
969
1030
  config;
970
1031
  state;
971
1032
  listeners = /* @__PURE__ */ new Set();
@@ -983,7 +1044,8 @@ var et = class {
983
1044
  runtimeError: null,
984
1045
  messageFeedback: {},
985
1046
  primaryColor: null,
986
- lastCompletedMessageText: null
1047
+ lastCompletedMessageText: null,
1048
+ draft: ""
987
1049
  };
988
1050
  }
989
1051
  getState() {
@@ -1004,20 +1066,20 @@ var et = class {
1004
1066
  try {
1005
1067
  if (this.config.sessionToken) this.sessionToken = this.config.sessionToken;
1006
1068
  else if (this.config.publishableKey) {
1007
- let { token: t, primaryColor: n } = await Ve(e, this.config.publishableKey);
1069
+ let { token: t, primaryColor: n } = await Je(e, this.config.publishableKey);
1008
1070
  this.sessionToken = t, this.setState({ primaryColor: n });
1009
1071
  } else throw Error("WidgetConfig must include exactly one of publishableKey or sessionToken");
1010
1072
  } catch (e) {
1011
1073
  console.error("[whoo-aiden-widget] initialization failed:", e), this.setState({ initError: e instanceof Error ? e.message : String(e) });
1012
1074
  return;
1013
1075
  }
1014
- this.conversationId = Ze(this.storageIdentifier);
1076
+ this.conversationId = it(this.storageIdentifier);
1015
1077
  }
1016
1078
  open() {
1017
1079
  this.setState({ isOpen: !0 });
1018
1080
  }
1019
1081
  resetConversation() {
1020
- this.activeRequestController?.abort(), this.activeRequestController = null, this.conversationId = null, $e(this.storageIdentifier), this.setState({
1082
+ this.activeRequestController?.abort(), this.activeRequestController = null, this.conversationId = null, ot(this.storageIdentifier), this.setState({
1021
1083
  messages: [],
1022
1084
  messageFeedback: {},
1023
1085
  runtimeError: null,
@@ -1025,6 +1087,9 @@ var et = class {
1025
1087
  lastCompletedMessageText: null
1026
1088
  });
1027
1089
  }
1090
+ setDraft(e) {
1091
+ this.setState({ draft: e });
1092
+ }
1028
1093
  close() {
1029
1094
  this.activeRequestController?.abort(), this.activeRequestController = null, this.setState({ isOpen: !1 });
1030
1095
  }
@@ -1056,22 +1121,27 @@ var et = class {
1056
1121
  }, this.setState({ messages: t });
1057
1122
  };
1058
1123
  this.activeRequestController = new AbortController();
1059
- let { signal: a } = this.activeRequestController, o = "";
1124
+ let { signal: a } = this.activeRequestController, o = () => {
1125
+ this.setState({
1126
+ runtimeError: "Something went wrong, please try again.",
1127
+ ...this.state.draft === "" ? { draft: e } : {}
1128
+ });
1129
+ }, s = "";
1060
1130
  try {
1061
- for await (let n of Ue(t, this.sessionToken, this.conversationId, e, a)) if (n.type === "conversation_id") this.conversationId = n.conversationId, Qe(this.storageIdentifier, n.conversationId);
1062
- else if (n.type === "delta") n.verbatim && !this.prefersReducedMotion ? (await Ye(n.delta, (e) => i(e), { signal: a }), o = n.delta) : n.verbatim ? (o = n.delta, i(o)) : (o += n.delta, i(o));
1131
+ for await (let n of Xe(t, this.sessionToken, this.conversationId, e, a)) if (n.type === "conversation_id") this.conversationId = n.conversationId, at(this.storageIdentifier, n.conversationId);
1132
+ else if (n.type === "delta") n.verbatim && !this.prefersReducedMotion ? (await nt(n.delta, (e) => i(e), { signal: a }), s = n.delta) : n.verbatim ? (s = n.delta, i(s)) : (s += n.delta, i(s));
1063
1133
  else if (n.type === "done") {
1064
- if (n.conversationId && (this.conversationId = n.conversationId, Qe(this.storageIdentifier, n.conversationId)), n.messageId) {
1134
+ if (n.conversationId && (this.conversationId = n.conversationId, at(this.storageIdentifier, n.conversationId)), n.messageId) {
1065
1135
  let e = [...this.state.messages];
1066
1136
  e[e.length - 1] = {
1067
1137
  ...e[e.length - 1],
1068
1138
  id: n.messageId
1069
1139
  }, this.setState({ messages: e });
1070
1140
  }
1071
- this.setState({ lastCompletedMessageText: o });
1072
- } else n.type === "error" && (console.error("[whoo-aiden-widget] chat error:", n.error), this.setState({ runtimeError: "Something went wrong, please try again." }));
1141
+ this.setState({ lastCompletedMessageText: s });
1142
+ } else n.type === "error" && (console.error("[whoo-aiden-widget] chat error:", n.error), o());
1073
1143
  } catch (e) {
1074
- e?.name === "AbortError" || (console.error("[whoo-aiden-widget] chat request failed:", e), this.setState({ runtimeError: "Something went wrong, please try again." }));
1144
+ e?.name === "AbortError" || (console.error("[whoo-aiden-widget] chat request failed:", e), o());
1075
1145
  } finally {
1076
1146
  this.activeRequestController = null, this.setState({ isStreaming: !1 });
1077
1147
  }
@@ -1099,7 +1169,7 @@ var et = class {
1099
1169
  }
1100
1170
  } });
1101
1171
  try {
1102
- await He(i, this.sessionToken, {
1172
+ await Ye(i, this.sessionToken, {
1103
1173
  messageId: e,
1104
1174
  rating: t,
1105
1175
  correction: n,
@@ -1121,21 +1191,29 @@ var et = class {
1121
1191
  } });
1122
1192
  }
1123
1193
  }
1124
- }, tt = ":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-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;height:480px;max-height:90vh;display:flex;position:fixed;overflow:hidden;box-shadow:0 4px 16px #0003}.whoo-widget-header{flex-shrink:0;justify-content:space-between;align-items:center;padding:8px 12px 0;display:flex}.whoo-widget-header-close,.whoo-widget-header-reset{color:var(--whoo-widget-color,#4f46e5);cursor:pointer;background:0 0;border:none;padding:4px 6px;font-size:12px}.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;opacity:.6;background:0 0;border:none;padding:2px 4px;font-size:14px}.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;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}";
1194
+ }, ct = ":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}";
1125
1195
  //#endregion
1126
1196
  //#region src/theme.ts
1127
- function nt(e) {
1197
+ function lt(e) {
1128
1198
  let t = document.createElement("div");
1129
1199
  if (t.style.color = e, t.style.color === "") return null;
1130
1200
  document.body.appendChild(t);
1131
1201
  let n = getComputedStyle(t).color;
1132
1202
  document.body.removeChild(t);
1133
- let r = n.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
1134
- return r ? [
1135
- Number(r[1]),
1136
- Number(r[2]),
1137
- Number(r[3])
1138
- ] : null;
1203
+ let r = n.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?/);
1204
+ if (!r) return null;
1205
+ let i = r[4] === void 0 ? 1 : Number(r[4]);
1206
+ return {
1207
+ rgb: [
1208
+ Number(r[1]),
1209
+ Number(r[2]),
1210
+ Number(r[3])
1211
+ ].map((e) => Math.round(e * i + 255 * (1 - i))),
1212
+ translucent: i < 1
1213
+ };
1214
+ }
1215
+ function ut(e) {
1216
+ return lt(e)?.rgb ?? null;
1139
1217
  }
1140
1218
  function $([e, t, n]) {
1141
1219
  let r = (e) => {
@@ -1144,50 +1222,76 @@ function $([e, t, n]) {
1144
1222
  };
1145
1223
  return .2126 * r(e) + .7152 * r(t) + .0722 * r(n);
1146
1224
  }
1147
- function rt(e, t) {
1225
+ function dt(e, t) {
1148
1226
  let n = Math.max(e, t), r = Math.min(e, t);
1149
1227
  return (n + .05) / (r + .05);
1150
1228
  }
1151
- function it(e) {
1152
- let t = nt(e);
1229
+ function ft(e) {
1230
+ let t = ut(e);
1153
1231
  if (!t) return console.warn(`[whoo-aiden-widget] Could not parse color "${e}" for contrast calculation; defaulting to white text.`), "#ffffff";
1154
1232
  let n = $(t);
1155
- return rt(n, $([
1233
+ return dt(n, $([
1156
1234
  0,
1157
1235
  0,
1158
1236
  0
1159
- ])) >= rt(n, $([
1237
+ ])) >= dt(n, $([
1160
1238
  255,
1161
1239
  255,
1162
1240
  255
1163
1241
  ])) ? "#000000" : "#ffffff";
1164
1242
  }
1165
- function at(e, t) {
1166
- let n = t.color ?? "#4f46e5";
1167
- e.style.setProperty("--whoo-widget-color", n), e.style.setProperty("--whoo-widget-text-on-color", it(n));
1168
- let r = t.position === "bottom-left";
1169
- e.style.setProperty("--whoo-widget-inset-left", r ? "20px" : "auto"), e.style.setProperty("--whoo-widget-inset-right", r ? "auto" : "20px");
1243
+ var pt = "#4f46e5", mt = [
1244
+ 255,
1245
+ 255,
1246
+ 255
1247
+ ], ht = 4.5;
1248
+ function gt([e, t, n]) {
1249
+ return `#${[
1250
+ e,
1251
+ t,
1252
+ n
1253
+ ].map((e) => e.toString(16).padStart(2, "0")).join("")}`;
1254
+ }
1255
+ function _t(e) {
1256
+ let t = ut(e);
1257
+ if (!t) return pt;
1258
+ let n = $(mt), r = (e) => dt($(e), n) >= ht;
1259
+ if (r(t)) return e;
1260
+ for (let e = .99; e > 0; e -= .01) {
1261
+ let n = t.map((t) => Math.round(t * e));
1262
+ if (r(n)) return gt(n);
1263
+ }
1264
+ return "#000000";
1265
+ }
1266
+ function vt(e, t) {
1267
+ let n = lt(t), r = n?.translucent ? gt(n.rgb) : t;
1268
+ e.style.setProperty("--whoo-widget-color", r), e.style.setProperty("--whoo-widget-text-on-color", ft(r)), e.style.setProperty("--whoo-widget-color-text", _t(r));
1269
+ }
1270
+ function yt(e, t) {
1271
+ vt(e, t.color ?? pt);
1272
+ let n = t.position === "bottom-left";
1273
+ e.style.setProperty("--whoo-widget-inset-left", n ? "20px" : "auto"), e.style.setProperty("--whoo-widget-inset-right", n ? "auto" : "20px");
1170
1274
  }
1171
1275
  //#endregion
1172
1276
  //#region src/mount.tsx
1173
- function ot(e) {
1277
+ function bt(e) {
1174
1278
  let t = document.createElement("div");
1175
1279
  t.id = "whoo-aiden-widget-host";
1176
1280
  let n = t.attachShadow({ mode: "open" }), r = document.createElement("style");
1177
- r.textContent = tt, n.appendChild(r);
1281
+ r.textContent = ct, n.appendChild(r);
1178
1282
  let i = document.createElement("div");
1179
- n.appendChild(i), at(i, e);
1180
- let a = new et(e);
1283
+ n.appendChild(i), yt(i, e);
1284
+ let a = new st(e);
1181
1285
  return a.subscribe((e) => {
1182
- e.primaryColor && (i.style.setProperty("--whoo-widget-color", e.primaryColor), i.style.setProperty("--whoo-widget-text-on-color", it(e.primaryColor)));
1183
- }), ce(/* @__PURE__ */ q(ze, { controller: a }), i), a.init(), document.body.appendChild(t), { unmount() {
1286
+ e.primaryColor && vt(i, e.primaryColor);
1287
+ }), ce(/* @__PURE__ */ q(Ke, { controller: a }), i), a.init(), document.body.appendChild(t), { unmount() {
1184
1288
  ce(null, i), t.remove();
1185
1289
  } };
1186
1290
  }
1187
1291
  //#endregion
1188
1292
  //#region src/index.ts
1189
- function st(t) {
1190
- return e(t), ot(t);
1293
+ function xt(t) {
1294
+ return e(t), bt(t);
1191
1295
  }
1192
1296
  //#endregion
1193
- export { st as init };
1297
+ export { xt as init };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiden-voice/widget",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "packageManager": "pnpm@11.9.0",
5
5
  "description": "Embeddable chat widget for whoo-aiden",
6
6
  "repository": {