@opencx/widget 3.0.83 → 3.0.85
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/dist/designs.cjs +21 -21
- package/dist/designs.cjs.map +1 -1
- package/dist/designs.js +3051 -3118
- package/dist/designs.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +2 -2
- package/dist/src/designs/react/components/lib/MotionDiv.d.ts +1 -0
- package/dist/src/designs/translation/translation.types.d.ts +1 -1
- package/dist/src/headless/core/context/router.ctx.d.ts +6 -5
- package/dist/src/headless/core/index.d.ts +1 -1
- package/dist/src/headless/core/types/widget-config.d.ts +18 -1
- package/dist/src/headless/react/hooks/useSessions.d.ts +31 -0
- package/dist/src/headless/react/hooks/useWidgetRouter.d.ts +1 -1
- package/dist/{useWidgetTrigger-ClIdKwZT.cjs → useWidgetTrigger-Be2RN31V.cjs} +4 -4
- package/dist/useWidgetTrigger-Be2RN31V.cjs.map +1 -0
- package/dist/{useWidgetTrigger-CiXxBOLI.js → useWidgetTrigger-D94qDfz7.js} +354 -348
- package/dist/useWidgetTrigger-D94qDfz7.js.map +1 -0
- package/dist/{widget.ctx-r2Nzp00O.js → widget.ctx-0z1bMkkT.js} +246 -236
- package/dist/{widget.ctx-r2Nzp00O.js.map → widget.ctx-0z1bMkkT.js.map} +1 -1
- package/dist/widget.ctx-BOpwwK5L.cjs +5 -0
- package/dist/{widget.ctx-CoJrM0OY.cjs.map → widget.ctx-BOpwwK5L.cjs.map} +1 -1
- package/dist-embed/script.js +82 -102
- package/dist-embed/script.js.map +1 -1
- package/package.json +1 -1
- package/dist/useWidgetTrigger-CiXxBOLI.js.map +0 -1
- package/dist/useWidgetTrigger-ClIdKwZT.cjs.map +0 -1
- package/dist/widget.ctx-CoJrM0OY.cjs +0 -5
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./widget.ctx-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./widget.ctx-BOpwwK5L.cjs");exports.PrimitiveState=t.PrimitiveState;exports.WidgetCtx=t.WidgetCtx;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
package/dist/react.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useWidgetTrigger-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useWidgetTrigger-Be2RN31V.cjs");function g(t,i,s){const{widgetCtx:{api:u}}=e.useWidget();return e._default(async r=>u.vote({action:r==="up"?"upvote":"downvote",messagePublicId:t,sessionId:i}).then(s),[u,t,i,s])}exports.WidgetProvider=e.WidgetProvider;exports.WidgetTriggerProvider=e.WidgetTriggerProvider;exports.useConfig=e.useConfig;exports.useContact=e.useContact;exports.useIsAwaitingBotReply=e.useIsAwaitingBotReply;exports.useMessages=e.useMessages;exports.usePreludeData=e.usePreludeData;exports.usePrimitiveState=e.usePrimitiveState;exports.useSessions=e.useSessions;exports.useUploadFiles=e.useUploadFiles;exports.useWidget=e.useWidget;exports.useWidgetRouter=e.useWidgetRouter;exports.useWidgetTrigger=e.useWidgetTrigger;exports.useVote=g;
|
|
2
2
|
//# sourceMappingURL=react.cjs.map
|
package/dist/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { u, _ as r } from "./useWidgetTrigger-
|
|
2
|
-
import { W as p, k as f, a as l, b as v, c as W, d as c, e as m, f as P, g as w, i as x, h as C, j as b } from "./useWidgetTrigger-
|
|
1
|
+
import { u, _ as r } from "./useWidgetTrigger-D94qDfz7.js";
|
|
2
|
+
import { W as p, k as f, a as l, b as v, c as W, d as c, e as m, f as P, g as w, i as x, h as C, j as b } from "./useWidgetTrigger-D94qDfz7.js";
|
|
3
3
|
function g(e, s, t) {
|
|
4
4
|
const {
|
|
5
5
|
widgetCtx: { api: a }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type TranslationKeysU = 'ok' | 'yes' | 'no' | 'agree' | 'cancel' | 'yes-exit' | 'yes-reset' | 'no-cancel' | 'are-you-sure' | 'recording' | 'thank-you' | 'sorry-try-again' | 'error-occurred' | 'please-try-again' | 'write-a-message' | 'send-message' | 'connected' | 'connecting' | 'reconnecting' | 'reconnected' | 'disconnecting' | 'disconnected' | 'error' | 'persist-session' | 'settings' | 'close' | 'help' | 'chat' | 'send' | 'copy' | 'copied' | 'sound-effects' | 'language' | 'select' | 'agent' | 'user' | 'bot' | 'close-widget' | 'got-any-questions' | 'typical-response-time' | 'session-closed-lead' | 'create-new-ticket' | 'exit' | 'reset-conversation' | 'new-conversation' | 'welcome-title' | 'welcome-description' | 'your-name' | 'your-email' | 'start-chat' | 'starting-chat' | 'hello-greeting' | 'i-need-more-help' | 'this-was-helpful' | 'optional' | 'no-conversations-yet';
|
|
1
|
+
export type TranslationKeysU = 'ok' | 'yes' | 'no' | 'agree' | 'cancel' | 'yes-exit' | 'yes-reset' | 'no-cancel' | 'are-you-sure' | 'recording' | 'thank-you' | 'sorry-try-again' | 'error-occurred' | 'please-try-again' | 'write-a-message' | 'send-message' | 'connected' | 'connecting' | 'reconnecting' | 'reconnected' | 'disconnecting' | 'disconnected' | 'error' | 'persist-session' | 'settings' | 'close' | 'help' | 'chat' | 'send' | 'copy' | 'copied' | 'sound-effects' | 'language' | 'select' | 'agent' | 'user' | 'bot' | 'close-widget' | 'got-any-questions' | 'typical-response-time' | 'session-closed-lead' | 'create-new-ticket' | 'exit' | 'reset-conversation' | 'new-conversation' | 'welcome-title' | 'welcome-description' | 'your-name' | 'your-email' | 'start-chat' | 'starting-chat' | 'hello-greeting' | 'i-need-more-help' | 'this-was-helpful' | 'optional' | 'no-conversations-yet' | 'back-to-conversations' | 'closed-conversations';
|
|
2
2
|
export type TranslationInterface = {
|
|
3
3
|
[K in TranslationKeysU]: string;
|
|
4
4
|
};
|
|
@@ -3,12 +3,13 @@ import { PrimitiveState } from '../utils/PrimitiveState';
|
|
|
3
3
|
import { ContactCtx } from './contact.ctx';
|
|
4
4
|
import { SessionCtx } from './session.ctx';
|
|
5
5
|
import { WidgetCtx } from './widget.ctx';
|
|
6
|
+
export type ScreenU = /** A welcome screen to collect user data. Useful in public non-logged-in environments */ 'welcome'
|
|
7
|
+
/** Show a list of the user's previous sessions */
|
|
8
|
+
| 'sessions'
|
|
9
|
+
/** Self-explanatory */
|
|
10
|
+
| 'chat';
|
|
6
11
|
type RouterState = {
|
|
7
|
-
screen:
|
|
8
|
-
/** Show a list of the user's previous sessions */
|
|
9
|
-
| 'sessions'
|
|
10
|
-
/** Self-explanatory */
|
|
11
|
-
| 'chat';
|
|
12
|
+
screen: ScreenU;
|
|
12
13
|
};
|
|
13
14
|
export declare class RouterCtx {
|
|
14
15
|
state: PrimitiveState<RouterState>;
|
|
@@ -9,5 +9,5 @@ export { WidgetCtx } from './context/widget.ctx';
|
|
|
9
9
|
export type { ContactCtx } from './context/contact.ctx';
|
|
10
10
|
export type { SessionCtx } from './context/session.ctx';
|
|
11
11
|
export type { MessageCtx } from './context/message.ctx';
|
|
12
|
-
export type { RouterCtx } from './context/router.ctx';
|
|
12
|
+
export type { RouterCtx, ScreenU } from './context/router.ctx';
|
|
13
13
|
export { PrimitiveState } from './utils/PrimitiveState';
|
|
@@ -21,7 +21,7 @@ export type UserConfig = UserBaseConfig & {
|
|
|
21
21
|
};
|
|
22
22
|
type ThemeOptions = {
|
|
23
23
|
/**
|
|
24
|
-
* @default '
|
|
24
|
+
* @default 'stone'
|
|
25
25
|
*/
|
|
26
26
|
palette?: 'neutral' | 'stone' | 'zinc' | 'slate';
|
|
27
27
|
primaryColor?: string;
|
|
@@ -214,7 +214,24 @@ export interface WidgetConfig {
|
|
|
214
214
|
* @default true
|
|
215
215
|
*/
|
|
216
216
|
goToChatIfNoSessions?: boolean;
|
|
217
|
+
/**
|
|
218
|
+
* If true, only the `welcome` and `chat` screens are visible.
|
|
219
|
+
* The most recent `open` session will be selected.
|
|
220
|
+
* If none found, a new empty conversation will be opened, and a session will be created if the user sends a message.
|
|
221
|
+
* The `back to sessions screen` button in the header will be hidden.
|
|
222
|
+
*
|
|
223
|
+
* @default false
|
|
224
|
+
*/
|
|
225
|
+
chatScreenOnly?: boolean;
|
|
217
226
|
};
|
|
227
|
+
/**
|
|
228
|
+
* By default, the user can have multiple open sessions.
|
|
229
|
+
*
|
|
230
|
+
* Setting this option to `true` will hide the `new conversation` button if there is an open session.
|
|
231
|
+
*
|
|
232
|
+
* @default false
|
|
233
|
+
*/
|
|
234
|
+
oneOpenSessionAllowed?: boolean;
|
|
218
235
|
/**
|
|
219
236
|
* The target attribute for all links in the AI or human agents responses.
|
|
220
237
|
*
|
|
@@ -11,4 +11,35 @@ export declare function useSessions(): {
|
|
|
11
11
|
isInitialFetchLoading: boolean;
|
|
12
12
|
};
|
|
13
13
|
loadMoreSessions: () => Promise<void>;
|
|
14
|
+
openSessions: {
|
|
15
|
+
id: string;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
isHandedOff: boolean;
|
|
19
|
+
isOpened: boolean;
|
|
20
|
+
assignee: {
|
|
21
|
+
kind: "human" | "ai" | "none" | "unknown";
|
|
22
|
+
name: string | null;
|
|
23
|
+
avatarUrl: string | null;
|
|
24
|
+
};
|
|
25
|
+
channel: string;
|
|
26
|
+
isVerified: boolean;
|
|
27
|
+
lastMessage: string | null;
|
|
28
|
+
}[];
|
|
29
|
+
closedSessions: {
|
|
30
|
+
id: string;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
updatedAt: string;
|
|
33
|
+
isHandedOff: boolean;
|
|
34
|
+
isOpened: boolean;
|
|
35
|
+
assignee: {
|
|
36
|
+
kind: "human" | "ai" | "none" | "unknown";
|
|
37
|
+
name: string | null;
|
|
38
|
+
avatarUrl: string | null;
|
|
39
|
+
};
|
|
40
|
+
channel: string;
|
|
41
|
+
isVerified: boolean;
|
|
42
|
+
lastMessage: string | null;
|
|
43
|
+
}[];
|
|
44
|
+
canCreateNewSession: boolean;
|
|
14
45
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const g=require("react"),Ht=require("uuid"),et=require("react/jsx-runtime"),Kt=require("./widget.ctx-BOpwwK5L.cjs"),zt="3.0.85";class kt{constructor(t){this.components=[];const{components:n}=t;if(n&&n.forEach(r=>this.register(r)),this.components.length===0)throw new Error("No components registered");if(!this.get("fallback"))throw new Error("No fallback component registered")}register(t){const n=this.components.findIndex(r=>r.key===t.key);return n!==-1?this.components[n]=t:this.components.push(t),this}get(t){const n=this.components.find(r=>r.key.toUpperCase()===t.toUpperCase());return n||null}getComponent(t){var n;return(n=this.get(t))==null?void 0:n.component}}const tt=g.createContext(null);function Yt({options:e,children:t,components:n,storage:r,loadingComponent:o}){const s=g.useRef(null),i=g.useRef(!1),[f,h]=g.useState(null),c=g.useMemo(()=>new kt({components:n}),[n]);return g.useEffect(()=>{i.current||(i.current=!0,Kt.WidgetCtx.initialize({config:e,storage:r}).then(h))},[]),f?et.jsx(tt.Provider,{value:{widgetCtx:f,config:e,components:n,componentStore:c,version:zt,contentIframeRef:s},children:t}):o||null}function K(){const e=g.useContext(tt);if(!e)throw new Error("useWidget must be used within a WidgetProvider");return e}function Le(){const{config:e}=K();return e}function ee(e){return g.useSyncExternalStore(e.subscribe,e.get,e.get)}function Jt(){const{widgetCtx:e}=K();return{contactState:ee(e.contactCtx.state),createUnverifiedContact:e.contactCtx.createUnverifiedContact}}function nt(){const{widgetCtx:e}=K();return{messagesState:ee(e.messageCtx.state),sendMessage:e.messageCtx.sendMessage}}function rt(){const{widgetCtx:e}=K(),{oneOpenSessionAllowed:t}=Le(),n=ee(e.sessionCtx.sessionState),r=ee(e.sessionCtx.sessionsState),{openSessions:o,closedSessions:s}=g.useMemo(()=>({openSessions:r.data.filter(f=>f.isOpened===!0),closedSessions:r.data.filter(f=>f.isOpened===!1)}),[r.data]),i=g.useMemo(()=>t?o.length===0:!0,[t,o.length]);return{sessionState:n,sessionsState:r,loadMoreSessions:e.sessionCtx.loadMoreSessions,openSessions:o,closedSessions:s,canCreateNewSession:i}}function Xt(){var i;const{sessionState:e}=rt(),{messagesState:t}=nt(),n=((i=e.session)==null?void 0:i.assignee.kind)==="ai",r=t.messages.length>0?t.messages[t.messages.length-1]:null,o=(r==null?void 0:r.type)==="FROM_USER";return{isAwaitingBotReply:(n||e.isCreatingSession)&&(t.isSendingMessage||o)}}var Qt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Zt(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function en(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var n=function r(){return this instanceof r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}),n}var Re={exports:{}},_e={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* use-sync-external-store-shim.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var ze;function tn(){if(ze)return _e;ze=1;var e=g;function t(u,d){return u===d&&(u!==0||1/u===1/d)||u!==u&&d!==d}var n=typeof Object.is=="function"?Object.is:t,r=e.useState,o=e.useEffect,s=e.useLayoutEffect,i=e.useDebugValue;function f(u,d){var l=d(),_=r({inst:{value:l,getSnapshot:d}}),y=_[0].inst,C=_[1];return s(function(){y.value=l,y.getSnapshot=d,h(y)&&C({inst:y})},[u,l,d]),o(function(){return h(y)&&C({inst:y}),u(function(){h(y)&&C({inst:y})})},[u]),i(l),l}function h(u){var d=u.getSnapshot;u=u.value;try{var l=d();return!n(u,l)}catch{return!0}}function c(u,d){return d()}var a=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?c:f;return _e.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:a,_e}var Ee={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* use-sync-external-store-shim.development.js
|
|
12
12
|
*
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var ze;function nn(){return ze||(ze=1,process.env.NODE_ENV!=="production"&&function(){typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=y,t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function n(R){{for(var v=arguments.length,w=new Array(v>1?v-1:0),S=1;S<v;S++)w[S-1]=arguments[S];r("error",R,w)}}function r(R,v,w){{var S=t.ReactDebugCurrentFrame,I=S.getStackAddendum();I!==""&&(v+="%s",w=w.concat([I]));var m=w.map(function(D){return String(D)});m.unshift("Warning: "+v),Function.prototype.apply.call(console[R],console,m)}}function o(R,v){return R===v&&(R!==0||1/R===1/v)||R!==R&&v!==v}var s=typeof Object.is=="function"?Object.is:o,i=e.useState,d=e.useEffect,h=e.useLayoutEffect,c=e.useDebugValue,a=!1,u=!1;function l(R,v,w){a||e.startTransition!==void 0&&(a=!0,n("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var S=v();if(!u){var I=v();s(S,I)||(n("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}var m=i({inst:{value:S,getSnapshot:v}}),D=m[0].inst,j=m[1];return h(function(){D.value=S,D.getSnapshot=v,f(D)&&j({inst:D})},[R,S,v]),d(function(){f(D)&&j({inst:D});var B=function(){f(D)&&j({inst:D})};return R(B)},[R]),c(S),S}function f(R){var v=R.getSnapshot,w=R.value;try{var S=v();return!s(w,S)}catch{return!0}}function _(R,v,w){return v()}var g=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",C=!g,p=C?_:l,k=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:p;Ee.useSyncExternalStore=k,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),Ee}process.env.NODE_ENV==="production"?Re.exports=tn():Re.exports=nn();var rn=Re.exports;const G=()=>{},L=G(),ve=Object,E=e=>e===L,F=e=>typeof e=="function",H=(e,t)=>({...e,...t}),on=e=>F(e.then),ue=new WeakMap;let sn=0;const oe=e=>{const t=typeof e,n=e&&e.constructor,r=n==Date;let o,s;if(ve(e)===e&&!r&&n!=RegExp){if(o=ue.get(e),o)return o;if(o=++sn+"~",ue.set(e,o),n==Array){for(o="@",s=0;s<e.length;s++)o+=oe(e[s])+",";ue.set(e,o)}if(n==ve){o="#";const i=ve.keys(e).sort();for(;!E(s=i.pop());)E(e[s])||(o+=s+":"+oe(e[s])+",");ue.set(e,o)}}else o=r?e.toJSON():t=="symbol"?e.toString():t=="string"?JSON.stringify(e):""+e;return o},q=new WeakMap,Se={},ce={},Le="undefined",pe=typeof window!=Le,Te=typeof document!=Le,an=()=>pe&&typeof window.requestAnimationFrame!=Le,ot=(e,t)=>{const n=q.get(e);return[()=>!E(t)&&e.get(t)||Se,r=>{if(!E(t)){const o=e.get(t);t in ce||(ce[t]=o),n[5](t,H(o,r),o||Se)}},n[6],()=>!E(t)&&t in ce?ce[t]:!E(t)&&e.get(t)||Se]};let Ce=!0;const un=()=>Ce,[De,Ae]=pe&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[G,G],cn=()=>{const e=Te&&document.visibilityState;return E(e)||e!=="hidden"},fn=e=>(Te&&document.addEventListener("visibilitychange",e),De("focus",e),()=>{Te&&document.removeEventListener("visibilitychange",e),Ae("focus",e)}),ln=e=>{const t=()=>{Ce=!0,e()},n=()=>{Ce=!1};return De("online",t),De("offline",n),()=>{Ae("online",t),Ae("offline",n)}},dn={isOnline:un,isVisible:cn},pn={initFocus:fn,initReconnect:ln},ke=!y.useId,se=!pe||"Deno"in window,hn=e=>an()?window.requestAnimationFrame(e):setTimeout(e,1),we=se?y.useEffect:y.useLayoutEffect,me=typeof navigator<"u"&&navigator.connection,Ye=!se&&me&&(["slow-2g","2g"].includes(me.effectiveType)||me.saveData),Ie=e=>{if(F(e))try{e=e()}catch{e=""}const t=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?oe(e):"",[e,t]};let gn=0;const xe=()=>++gn,st=0,it=1,at=2,yn=3;var re={__proto__:null,ERROR_REVALIDATE_EVENT:yn,FOCUS_EVENT:st,MUTATE_EVENT:at,RECONNECT_EVENT:it};async function ut(...e){const[t,n,r,o]=e,s=H({populateCache:!0,throwOnError:!0},typeof o=="boolean"?{revalidate:o}:o||{});let i=s.populateCache;const d=s.rollbackOnError;let h=s.optimisticData;const c=l=>typeof d=="function"?d(l):d!==!1,a=s.throwOnError;if(F(n)){const l=n,f=[],_=t.keys();for(const g of _)!/^\$(inf|sub)\$/.test(g)&&l(t.get(g)._k)&&f.push(g);return Promise.all(f.map(u))}return u(n);async function u(l){const[f]=Ie(l);if(!f)return;const[_,g]=ot(t,f),[C,p,k,R]=q.get(t),v=()=>{const M=C[f];return(F(s.revalidate)?s.revalidate(_().data,l):s.revalidate!==!1)&&(delete k[f],delete R[f],M&&M[0])?M[0](at).then(()=>_().data):_().data};if(e.length<3)return v();let w=r,S;const I=xe();p[f]=[I,0];const m=!E(h),D=_(),j=D.data,B=D._c,z=E(B)?j:B;if(m&&(h=F(h)?h(z,j):h,g({data:h,_c:z})),F(w))try{w=w(z)}catch(M){S=M}if(w&&on(w))if(w=await w.catch(M=>{S=M}),I!==p[f][0]){if(S)throw S;return w}else S&&m&&c(S)&&(i=!0,g({data:z,_c:L}));if(i&&!S)if(F(i)){const M=i(w,z);g({data:M,error:L,_c:L})}else g({data:w,error:L,_c:L});if(p[f][1]=xe(),Promise.resolve(v()).then(()=>{g({_c:L})}),S){if(a)throw S;return}return w}}const Je=(e,t)=>{for(const n in e)e[n][0]&&e[n][0](t)},_n=(e,t)=>{if(!q.has(e)){const n=H(pn,t),r={},o=ut.bind(L,e);let s=G;const i={},d=(a,u)=>{const l=i[a]||[];return i[a]=l,l.push(u),()=>l.splice(l.indexOf(u),1)},h=(a,u,l)=>{e.set(a,u);const f=i[a];if(f)for(const _ of f)_(u,l)},c=()=>{if(!q.has(e)&&(q.set(e,[r,{},{},{},o,h,d]),!se)){const a=n.initFocus(setTimeout.bind(L,Je.bind(L,r,st))),u=n.initReconnect(setTimeout.bind(L,Je.bind(L,r,it)));s=()=>{a&&a(),u&&u(),q.delete(e)}}};return c(),[e,o,c,s]}return[e,q.get(e)[4]]},En=(e,t,n,r,o)=>{const s=n.errorRetryCount,i=o.retryCount,d=~~((Math.random()+.5)*(1<<(i<8?i:8)))*n.errorRetryInterval;!E(s)&&i>s||setTimeout(r,d,o)},vn=(e,t)=>oe(e)==oe(t),[ct,Sn]=_n(new Map),wn=H({onLoadingSlow:G,onSuccess:G,onError:G,onErrorRetry:En,onDiscarded:G,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:Ye?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:Ye?5e3:3e3,compare:vn,isPaused:()=>!1,cache:ct,mutate:Sn,fallback:{}},dn),mn=(e,t)=>{const n=H(e,t);if(t){const{use:r,fallback:o}=e,{use:s,fallback:i}=t;r&&s&&(n.use=r.concat(s)),o&&i&&(n.fallback=H(o,i))}return n},bn=y.createContext({}),On="$inf$",ft=pe&&window.__SWR_DEVTOOLS_USE__,Rn=ft?window.__SWR_DEVTOOLS_USE__:[],Tn=()=>{ft&&(window.__SWR_DEVTOOLS_REACT__=y)},Cn=e=>F(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],Dn=()=>H(wn,y.useContext(bn)),An=e=>(t,n,r)=>e(t,n&&((...s)=>{const[i]=Ie(t),[,,,d]=q.get(ct);if(i.startsWith(On))return n(...s);const h=d[i];return E(h)?n(...s):(delete d[i],h)}),r),xn=Rn.concat(An),Pn=e=>function(...n){const r=Dn(),[o,s,i]=Cn(n),d=mn(r,i);let h=e;const{use:c}=d,a=(c||[]).concat(xn);for(let u=a.length;u--;)h=a[u](h);return h(o,s||d.fetcher||null,d)},jn=(e,t,n)=>{const r=t[e]||(t[e]=[]);return r.push(n),()=>{const o=r.indexOf(n);o>=0&&(r[o]=r[r.length-1],r.pop())}};Tn();const Xe=y.use||(e=>{if(e.status==="pending")throw e;if(e.status==="fulfilled")return e.value;throw e.status==="rejected"?e.reason:(e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e)}),be={dedupe:!0},Ln=(e,t,n)=>{const{cache:r,compare:o,suspense:s,fallbackData:i,revalidateOnMount:d,revalidateIfStale:h,refreshInterval:c,refreshWhenHidden:a,refreshWhenOffline:u,keepPreviousData:l}=n,[f,_,g,C]=q.get(r),[p,k]=Ie(e),R=y.useRef(!1),v=y.useRef(!1),w=y.useRef(p),S=y.useRef(t),I=y.useRef(n),m=()=>I.current,D=()=>m().isVisible()&&m().isOnline(),[j,B,z,M]=ot(r,p),Y=y.useRef({}).current,Wt=E(i)?n.fallback[p]:i,Me=(b,O)=>{for(const x in Y){const T=x;if(T==="data"){if(!o(b[T],O[T])&&(!E(b[T])||!o(ae,O[T])))return!1}else if(O[T]!==b[T])return!1}return!0},Ne=y.useMemo(()=>{const b=!p||!t?!1:E(d)?m().isPaused()||s?!1:E(h)?!0:h:d,O=P=>{const U=H(P);return delete U._k,b?{isValidating:!0,isLoading:!0,...U}:U},x=j(),T=M(),N=O(x),Z=x===T?N:O(T);let A=N;return[()=>{const P=O(j());return Me(P,A)?(A.data=P.data,A.isLoading=P.isLoading,A.isValidating=P.isValidating,A.error=P.error,A):(A=P,P)},()=>Z]},[r,p]),J=rn.useSyncExternalStore(y.useCallback(b=>z(p,(O,x)=>{Me(x,O)||b()}),[r,p]),Ne[0],Ne[1]),Fe=!R.current,qt=f[p]&&f[p].length>0,X=J.data,Q=E(X)?Wt:X,ie=J.error,Ue=y.useRef(Q),ae=l?E(X)?Ue.current:X:Q,We=qt&&!E(ie)?!1:Fe&&!E(d)?d:m().isPaused()?!1:s?E(Q)?!1:h:E(Q)||h,qe=!!(p&&t&&Fe&&We),Bt=E(J.isValidating)?qe:J.isValidating,$t=E(J.isLoading)?qe:J.isLoading,ne=y.useCallback(async b=>{const O=S.current;if(!p||!O||v.current||m().isPaused())return!1;let x,T,N=!0;const Z=b||{},A=!g[p]||!Z.dedupe,P=()=>ke?!v.current&&p===w.current&&R.current:p===w.current,U={isValidating:!1,isLoading:!1},$e=()=>{B(U)},Ge=()=>{const V=g[p];V&&V[1]===T&&delete g[p]},He={isValidating:!0};E(j().data)&&(He.isLoading=!0);try{if(A&&(B(He),n.loadingTimeout&&E(j().data)&&setTimeout(()=>{N&&P()&&m().onLoadingSlow(p,n)},n.loadingTimeout),g[p]=[O(k),xe()]),[x,T]=g[p],x=await x,A&&setTimeout(Ge,n.dedupingInterval),!g[p]||g[p][1]!==T)return A&&P()&&m().onDiscarded(p),!1;U.error=L;const V=_[p];if(!E(V)&&(T<=V[0]||T<=V[1]||V[1]===0))return $e(),A&&P()&&m().onDiscarded(p),!1;const W=j().data;U.data=o(W,x)?W:x,A&&P()&&m().onSuccess(x,p,n)}catch(V){Ge();const W=m(),{shouldRetryOnError:ge}=W;W.isPaused()||(U.error=V,A&&P()&&(W.onError(V,p,W),(ge===!0||F(ge)&&ge(V))&&(!m().revalidateOnFocus||!m().revalidateOnReconnect||D())&&W.onErrorRetry(V,p,W,Gt=>{const ye=f[p];ye&&ye[0]&&ye[0](re.ERROR_REVALIDATE_EVENT,Gt)},{retryCount:(Z.retryCount||0)+1,dedupe:!0})))}return N=!1,$e(),!0},[p,r]),Be=y.useCallback((...b)=>ut(r,w.current,...b),[]);if(we(()=>{S.current=t,I.current=n,E(X)||(Ue.current=X)}),we(()=>{if(!p)return;const b=ne.bind(L,be);let O=0;const T=jn(p,f,(N,Z={})=>{if(N==re.FOCUS_EVENT){const A=Date.now();m().revalidateOnFocus&&A>O&&D()&&(O=A+m().focusThrottleInterval,b())}else if(N==re.RECONNECT_EVENT)m().revalidateOnReconnect&&D()&&b();else{if(N==re.MUTATE_EVENT)return ne();if(N==re.ERROR_REVALIDATE_EVENT)return ne(Z)}});return v.current=!1,w.current=p,R.current=!0,B({_k:k}),We&&(E(Q)||se?b():hn(b)),()=>{v.current=!0,T()}},[p]),we(()=>{let b;function O(){const T=F(c)?c(j().data):c;T&&b!==-1&&(b=setTimeout(x,T))}function x(){!j().error&&(a||m().isVisible())&&(u||m().isOnline())?ne(be).then(O):O()}return O(),()=>{b&&(clearTimeout(b),b=-1)}},[c,a,u,p]),y.useDebugValue(ae),s&&E(Q)&&p){if(!ke&&se)throw new Error("Fallback data is required when using suspense in SSR.");S.current=t,I.current=n,v.current=!1;const b=C[p];if(!E(b)){const O=Be(b);Xe(O)}if(E(ie)){const O=ne(be);E(ae)||(O.status="fulfilled",O.value=!0),Xe(O)}else throw ie}return{mutate:Be,get data(){return Y.data=!0,ae},get error(){return Y.error=!0,ie},get isValidating(){return Y.isValidating=!0,Bt},get isLoading(){return Y.isLoading=!0,$t}}},In=Pn(Ln);function Vn(){const{widgetCtx:e}=K();return In([e.config.token],e.api.widgetPrelude,{revalidateOnFocus:!1})}function Mn(){const{widgetCtx:e}=K();return{routerState:ee(e.routerCtx.state),toSessionsScreen:e.routerCtx.toSessionsScreen,toChatScreen:e.routerCtx.toChatScreen}}var lt={},Pe=function(e,t){return Pe=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[o]=r[o])},Pe(e,t)};function dt(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Pe(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}var le=function(){return le=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},le.apply(this,arguments)};function pt(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function ht(e,t,n,r){var o=arguments.length,s=o<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(e,t,n,r);else for(var d=e.length-1;d>=0;d--)(i=e[d])&&(s=(o<3?i(s):o>3?i(t,n,s):i(t,n))||s);return o>3&&s&&Object.defineProperty(t,n,s),s}function gt(e,t){return function(n,r){t(n,r,e)}}function yt(e,t,n,r,o,s){function i(p){if(p!==void 0&&typeof p!="function")throw new TypeError("Function expected");return p}for(var d=r.kind,h=d==="getter"?"get":d==="setter"?"set":"value",c=!t&&e?r.static?e:e.prototype:null,a=t||(c?Object.getOwnPropertyDescriptor(c,r.name):{}),u,l=!1,f=n.length-1;f>=0;f--){var _={};for(var g in r)_[g]=g==="access"?{}:r[g];for(var g in r.access)_.access[g]=r.access[g];_.addInitializer=function(p){if(l)throw new TypeError("Cannot add initializers after decoration has completed");s.push(i(p||null))};var C=(0,n[f])(d==="accessor"?{get:a.get,set:a.set}:a[h],_);if(d==="accessor"){if(C===void 0)continue;if(C===null||typeof C!="object")throw new TypeError("Object expected");(u=i(C.get))&&(a.get=u),(u=i(C.set))&&(a.set=u),(u=i(C.init))&&o.unshift(u)}else(u=i(C))&&(d==="field"?o.unshift(u):a[h]=u)}c&&Object.defineProperty(c,r.name,a),l=!0}function _t(e,t,n){for(var r=arguments.length>2,o=0;o<t.length;o++)n=r?t[o].call(e,n):t[o].call(e);return r?n:void 0}function Et(e){return typeof e=="symbol"?e:"".concat(e)}function vt(e,t,n){return typeof t=="symbol"&&(t=t.description?"[".concat(t.description,"]"):""),Object.defineProperty(e,"name",{configurable:!0,value:n?"".concat(n," ",t):t})}function St(e,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(e,t)}function wt(e,t,n,r){function o(s){return s instanceof n?s:new n(function(i){i(s)})}return new(n||(n=Promise))(function(s,i){function d(a){try{c(r.next(a))}catch(u){i(u)}}function h(a){try{c(r.throw(a))}catch(u){i(u)}}function c(a){a.done?s(a.value):o(a.value).then(d,h)}c((r=r.apply(e,t||[])).next())})}function mt(e,t){var n={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,o,s,i=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return i.next=d(0),i.throw=d(1),i.return=d(2),typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function d(c){return function(a){return h([c,a])}}function h(c){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(n=0)),n;)try{if(r=1,o&&(s=c[0]&2?o.return:c[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,c[1])).done)return s;switch(o=0,s&&(c=[c[0]&2,s.value]),c[0]){case 0:case 1:s=c;break;case 4:return n.label++,{value:c[1],done:!1};case 5:n.label++,o=c[1],c=[0];continue;case 7:c=n.ops.pop(),n.trys.pop();continue;default:if(s=n.trys,!(s=s.length>0&&s[s.length-1])&&(c[0]===6||c[0]===2)){n=0;continue}if(c[0]===3&&(!s||c[1]>s[0]&&c[1]<s[3])){n.label=c[1];break}if(c[0]===6&&n.label<s[1]){n.label=s[1],s=c;break}if(s&&n.label<s[2]){n.label=s[2],n.ops.push(c);break}s[2]&&n.ops.pop(),n.trys.pop();continue}c=t.call(e,n)}catch(a){c=[6,a],o=0}finally{r=s=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}var he=Object.create?function(e,t,n,r){r===void 0&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]};function bt(e,t){for(var n in e)n!=="default"&&!Object.prototype.hasOwnProperty.call(t,n)&&he(t,e,n)}function de(e){var t=typeof Symbol=="function"&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ve(e,t){var n=typeof Symbol=="function"&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),o,s=[],i;try{for(;(t===void 0||t-- >0)&&!(o=r.next()).done;)s.push(o.value)}catch(d){i={error:d}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return s}function Ot(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(Ve(arguments[t]));return e}function Rt(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var r=Array(e),o=0,t=0;t<n;t++)for(var s=arguments[t],i=0,d=s.length;i<d;i++,o++)r[o]=s[i];return r}function Tt(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}function te(e){return this instanceof te?(this.v=e,this):new te(e)}function Ct(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),o,s=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),d("next"),d("throw"),d("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(f){return function(_){return Promise.resolve(_).then(f,u)}}function d(f,_){r[f]&&(o[f]=function(g){return new Promise(function(C,p){s.push([f,g,C,p])>1||h(f,g)})},_&&(o[f]=_(o[f])))}function h(f,_){try{c(r[f](_))}catch(g){l(s[0][3],g)}}function c(f){f.value instanceof te?Promise.resolve(f.value.v).then(a,u):l(s[0][2],f)}function a(f){h("next",f)}function u(f){h("throw",f)}function l(f,_){f(_),s.shift(),s.length&&h(s[0][0],s[0][1])}}function Dt(e){var t,n;return t={},r("next"),r("throw",function(o){throw o}),r("return"),t[Symbol.iterator]=function(){return this},t;function r(o,s){t[o]=e[o]?function(i){return(n=!n)?{value:te(e[o](i)),done:!1}:s?s(i):i}:s}}function At(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof de=="function"?de(e):e[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(s){n[s]=e[s]&&function(i){return new Promise(function(d,h){i=e[s](i),o(d,h,i.done,i.value)})}}function o(s,i,d,h){Promise.resolve(h).then(function(c){s({value:c,done:d})},i)}}function xt(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}var Nn=Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t};function Pt(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n in e)n!=="default"&&Object.prototype.hasOwnProperty.call(e,n)&&he(t,e,n);return Nn(t,e),t}function jt(e){return e&&e.__esModule?e:{default:e}}function Lt(e,t,n,r){if(n==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return n==="m"?r:n==="a"?r.call(e):r?r.value:t.get(e)}function It(e,t,n,r,o){if(r==="m")throw new TypeError("Private method is not writable");if(r==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r==="a"?o.call(e,n):o?o.value=n:t.set(e,n),n}function Vt(e,t){if(t===null||typeof t!="object"&&typeof t!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof e=="function"?t===e:e.has(t)}function Mt(e,t,n){if(t!=null){if(typeof t!="object"&&typeof t!="function")throw new TypeError("Object expected.");var r,o;if(n){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");r=t[Symbol.asyncDispose]}if(r===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");r=t[Symbol.dispose],n&&(o=r)}if(typeof r!="function")throw new TypeError("Object not disposable.");o&&(r=function(){try{o.call(this)}catch(s){return Promise.reject(s)}}),e.stack.push({value:t,dispose:r,async:n})}else n&&e.stack.push({async:!0});return t}var Fn=typeof SuppressedError=="function"?SuppressedError:function(e,t,n){var r=new Error(n);return r.name="SuppressedError",r.error=e,r.suppressed=t,r};function Nt(e){function t(s){e.error=e.hasError?new Fn(s,e.error,"An error was suppressed during disposal."):s,e.hasError=!0}var n,r=0;function o(){for(;n=e.stack.pop();)try{if(!n.async&&r===1)return r=0,e.stack.push(n),Promise.resolve().then(o);if(n.dispose){var s=n.dispose.call(n.value);if(n.async)return r|=2,Promise.resolve(s).then(o,function(i){return t(i),o()})}else r|=1}catch(i){t(i)}if(r===1)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}return o()}function Ft(e,t){return typeof e=="string"&&/^\.\.?\//.test(e)?e.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(n,r,o,s,i){return r?t?".jsx":".js":o&&(!s||!i)?n:o+s+"."+i.toLowerCase()+"js"}):e}const Un={__extends:dt,__assign:le,__rest:pt,__decorate:ht,__param:gt,__esDecorate:yt,__runInitializers:_t,__propKey:Et,__setFunctionName:vt,__metadata:St,__awaiter:wt,__generator:mt,__createBinding:he,__exportStar:bt,__values:de,__read:Ve,__spread:Ot,__spreadArrays:Rt,__spreadArray:Tt,__await:te,__asyncGenerator:Ct,__asyncDelegator:Dt,__asyncValues:At,__makeTemplateObject:xt,__importStar:Pt,__importDefault:jt,__classPrivateFieldGet:Lt,__classPrivateFieldSet:It,__classPrivateFieldIn:Vt,__addDisposableResource:Mt,__disposeResources:Nt,__rewriteRelativeImportExtension:Ft},Wn=Object.freeze(Object.defineProperty({__proto__:null,__addDisposableResource:Mt,get __assign(){return le},__asyncDelegator:Dt,__asyncGenerator:Ct,__asyncValues:At,__await:te,__awaiter:wt,__classPrivateFieldGet:Lt,__classPrivateFieldIn:Vt,__classPrivateFieldSet:It,__createBinding:he,__decorate:ht,__disposeResources:Nt,__esDecorate:yt,__exportStar:bt,__extends:dt,__generator:mt,__importDefault:jt,__importStar:Pt,__makeTemplateObject:xt,__metadata:St,__param:gt,__propKey:Et,__read:Ve,__rest:pt,__rewriteRelativeImportExtension:Ft,__runInitializers:_t,__setFunctionName:vt,__spread:Ot,__spreadArray:Tt,__spreadArrays:Rt,__values:de,default:Un},Symbol.toStringTag,{value:"Module"})),qn=en(Wn);var fe={},Qe;function Bn(){if(Qe)return fe;Qe=1,Object.defineProperty(fe,"__esModule",{value:!0});var e=y;function t(){var n=e.useRef(!1),r=e.useCallback(function(){return n.current},[]);return e.useEffect(function(){return n.current=!0,function(){n.current=!1}},[]),r}return fe.default=t,fe}Object.defineProperty(lt,"__esModule",{value:!0});var je=qn,Oe=y,$n=je.__importDefault(Bn());function Gn(e,t,n){t===void 0&&(t=[]),n===void 0&&(n={loading:!1});var r=Oe.useRef(0),o=$n.default(),s=Oe.useState(n),i=s[0],d=s[1],h=Oe.useCallback(function(){for(var c=[],a=0;a<arguments.length;a++)c[a]=arguments[a];var u=++r.current;return i.loading||d(function(l){return je.__assign(je.__assign({},l),{loading:!0})}),e.apply(void 0,c).then(function(l){return o()&&u===r.current&&d({value:l,loading:!1}),l},function(l){return o()&&u===r.current&&d({error:l,loading:!1}),l})},t);return[i,h]}var Hn=lt.default=Gn;const $=new Map;function Kn(){const[e,t]=y.useState([]),{widgetCtx:{api:n}}=K();function r(a){const u=a.map(l=>({file:l,id:Ht.v4(),status:"pending",progress:0}));t(l=>[...l,...u]),u.forEach(i)}function o(a,u){t(l=>l.map(f=>f.id===a?{...f,...u}:f))}function s(a){t(u=>u.filter(l=>l.id!==a))}const i=async a=>{const u=new AbortController;$.set(a.id,u);try{t(f=>f.map(_=>_.id===a.id?{..._,status:"uploading",progress:0}:_));const l=await n.uploadFile({file:a.file,abortSignal:u.signal,onProgress:f=>{o(a.id,{progress:f})}});o(a.id,{status:"success",fileUrl:l.fileUrl,progress:100})}catch(l){u.signal.aborted||o(a.id,{status:"error",error:l instanceof Error?l.message:"Upload failed",progress:0})}finally{$.delete(a.id)}},d=a=>{const u=$.get(a);u&&(u.abort(),$.delete(a)),s(a)},h=y.useMemo(()=>e.filter(a=>a.status==="success"&&a.fileUrl),[e]);function c(){$.forEach(a=>a.abort()),$.clear(),t([])}return y.useEffect(()=>()=>{$.forEach(a=>a.abort()),$.clear()},[]),{allFiles:e,appendFiles:r,handleCancelUpload:d,successFiles:h,emptyTheFiles:c,getFileById:a=>e.find(u=>u.id===a),getUploadProgress:a=>{var u;return((u=e.find(l=>l.id===a))==null?void 0:u.progress)??0},getUploadStatus:a=>{var u;return(u=e.find(l=>l.id===a))==null?void 0:u.status},hasErrors:e.some(a=>a.status==="error"),isUploading:e.some(a=>a.status==="uploading")}}const Ut=y.createContext(null);function zn({children:e}){const t=tt(),[n,r]=y.useState(t.isOpen??!1);return y.useEffect(()=>{r(o=>t.isOpen??o)},[t.isOpen]),y.useEffect(()=>{const o=t.openAfterNSeconds;if(typeof o!="number"||isNaN(o))return;const s=setTimeout(()=>r(!0),o*1e3);return()=>clearTimeout(s)},[t.openAfterNSeconds]),Ze.jsx(Ut.Provider,{value:{isOpen:n,setIsOpen:r},children:e})}function kn(){const e=y.useContext(Ut);if(!e)throw new Error("useWidgetTrigger must be used within a WidgetTriggerProvider");return e}exports.WidgetProvider=Yt;exports.WidgetTriggerProvider=zn;exports._default=Hn;exports.commonjsGlobal=Qt;exports.getDefaultExportFromCjs=Zt;exports.useConfig=tt;exports.useContact=Jt;exports.useIsAwaitingBotReply=Xt;exports.useMessages=nt;exports.usePreludeData=Vn;exports.usePrimitiveState=ee;exports.useSessions=rt;exports.useUploadFiles=Kn;exports.useWidget=K;exports.useWidgetRouter=Mn;exports.useWidgetTrigger=kn;
|
|
18
|
-
//# sourceMappingURL=useWidgetTrigger-
|
|
17
|
+
*/var ke;function nn(){return ke||(ke=1,process.env.NODE_ENV!=="production"&&function(){typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=g,t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function n(R){{for(var S=arguments.length,w=new Array(S>1?S-1:0),v=1;v<S;v++)w[v-1]=arguments[v];r("error",R,w)}}function r(R,S,w){{var v=t.ReactDebugCurrentFrame,I=v.getStackAddendum();I!==""&&(S+="%s",w=w.concat([I]));var m=w.map(function(D){return String(D)});m.unshift("Warning: "+S),Function.prototype.apply.call(console[R],console,m)}}function o(R,S){return R===S&&(R!==0||1/R===1/S)||R!==R&&S!==S}var s=typeof Object.is=="function"?Object.is:o,i=e.useState,f=e.useEffect,h=e.useLayoutEffect,c=e.useDebugValue,a=!1,u=!1;function d(R,S,w){a||e.startTransition!==void 0&&(a=!0,n("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var v=S();if(!u){var I=S();s(v,I)||(n("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}var m=i({inst:{value:v,getSnapshot:S}}),D=m[0].inst,j=m[1];return h(function(){D.value=v,D.getSnapshot=S,l(D)&&j({inst:D})},[R,v,S]),f(function(){l(D)&&j({inst:D});var B=function(){l(D)&&j({inst:D})};return R(B)},[R]),c(v),v}function l(R){var S=R.getSnapshot,w=R.value;try{var v=S();return!s(w,v)}catch{return!0}}function _(R,S,w){return S()}var y=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",C=!y,p=C?_:d,k=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:p;Ee.useSyncExternalStore=k,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),Ee}process.env.NODE_ENV==="production"?Re.exports=tn():Re.exports=nn();var rn=Re.exports;const G=()=>{},L=G(),Se=Object,E=e=>e===L,F=e=>typeof e=="function",H=(e,t)=>({...e,...t}),on=e=>F(e.then),ue=new WeakMap;let sn=0;const oe=e=>{const t=typeof e,n=e&&e.constructor,r=n==Date;let o,s;if(Se(e)===e&&!r&&n!=RegExp){if(o=ue.get(e),o)return o;if(o=++sn+"~",ue.set(e,o),n==Array){for(o="@",s=0;s<e.length;s++)o+=oe(e[s])+",";ue.set(e,o)}if(n==Se){o="#";const i=Se.keys(e).sort();for(;!E(s=i.pop());)E(e[s])||(o+=s+":"+oe(e[s])+",");ue.set(e,o)}}else o=r?e.toJSON():t=="symbol"?e.toString():t=="string"?JSON.stringify(e):""+e;return o},q=new WeakMap,ve={},ce={},Ie="undefined",pe=typeof window!=Ie,Te=typeof document!=Ie,an=()=>pe&&typeof window.requestAnimationFrame!=Ie,ot=(e,t)=>{const n=q.get(e);return[()=>!E(t)&&e.get(t)||ve,r=>{if(!E(t)){const o=e.get(t);t in ce||(ce[t]=o),n[5](t,H(o,r),o||ve)}},n[6],()=>!E(t)&&t in ce?ce[t]:!E(t)&&e.get(t)||ve]};let Ce=!0;const un=()=>Ce,[De,Ae]=pe&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[G,G],cn=()=>{const e=Te&&document.visibilityState;return E(e)||e!=="hidden"},fn=e=>(Te&&document.addEventListener("visibilitychange",e),De("focus",e),()=>{Te&&document.removeEventListener("visibilitychange",e),Ae("focus",e)}),ln=e=>{const t=()=>{Ce=!0,e()},n=()=>{Ce=!1};return De("online",t),De("offline",n),()=>{Ae("online",t),Ae("offline",n)}},dn={isOnline:un,isVisible:cn},pn={initFocus:fn,initReconnect:ln},Ye=!g.useId,se=!pe||"Deno"in window,hn=e=>an()?window.requestAnimationFrame(e):setTimeout(e,1),we=se?g.useEffect:g.useLayoutEffect,me=typeof navigator<"u"&&navigator.connection,Je=!se&&me&&(["slow-2g","2g"].includes(me.effectiveType)||me.saveData),Ve=e=>{if(F(e))try{e=e()}catch{e=""}const t=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?oe(e):"",[e,t]};let gn=0;const xe=()=>++gn,st=0,it=1,at=2,yn=3;var re={__proto__:null,ERROR_REVALIDATE_EVENT:yn,FOCUS_EVENT:st,MUTATE_EVENT:at,RECONNECT_EVENT:it};async function ut(...e){const[t,n,r,o]=e,s=H({populateCache:!0,throwOnError:!0},typeof o=="boolean"?{revalidate:o}:o||{});let i=s.populateCache;const f=s.rollbackOnError;let h=s.optimisticData;const c=d=>typeof f=="function"?f(d):f!==!1,a=s.throwOnError;if(F(n)){const d=n,l=[],_=t.keys();for(const y of _)!/^\$(inf|sub)\$/.test(y)&&d(t.get(y)._k)&&l.push(y);return Promise.all(l.map(u))}return u(n);async function u(d){const[l]=Ve(d);if(!l)return;const[_,y]=ot(t,l),[C,p,k,R]=q.get(t),S=()=>{const M=C[l];return(F(s.revalidate)?s.revalidate(_().data,d):s.revalidate!==!1)&&(delete k[l],delete R[l],M&&M[0])?M[0](at).then(()=>_().data):_().data};if(e.length<3)return S();let w=r,v;const I=xe();p[l]=[I,0];const m=!E(h),D=_(),j=D.data,B=D._c,z=E(B)?j:B;if(m&&(h=F(h)?h(z,j):h,y({data:h,_c:z})),F(w))try{w=w(z)}catch(M){v=M}if(w&&on(w))if(w=await w.catch(M=>{v=M}),I!==p[l][0]){if(v)throw v;return w}else v&&m&&c(v)&&(i=!0,y({data:z,_c:L}));if(i&&!v)if(F(i)){const M=i(w,z);y({data:M,error:L,_c:L})}else y({data:w,error:L,_c:L});if(p[l][1]=xe(),Promise.resolve(S()).then(()=>{y({_c:L})}),v){if(a)throw v;return}return w}}const Xe=(e,t)=>{for(const n in e)e[n][0]&&e[n][0](t)},_n=(e,t)=>{if(!q.has(e)){const n=H(pn,t),r={},o=ut.bind(L,e);let s=G;const i={},f=(a,u)=>{const d=i[a]||[];return i[a]=d,d.push(u),()=>d.splice(d.indexOf(u),1)},h=(a,u,d)=>{e.set(a,u);const l=i[a];if(l)for(const _ of l)_(u,d)},c=()=>{if(!q.has(e)&&(q.set(e,[r,{},{},{},o,h,f]),!se)){const a=n.initFocus(setTimeout.bind(L,Xe.bind(L,r,st))),u=n.initReconnect(setTimeout.bind(L,Xe.bind(L,r,it)));s=()=>{a&&a(),u&&u(),q.delete(e)}}};return c(),[e,o,c,s]}return[e,q.get(e)[4]]},En=(e,t,n,r,o)=>{const s=n.errorRetryCount,i=o.retryCount,f=~~((Math.random()+.5)*(1<<(i<8?i:8)))*n.errorRetryInterval;!E(s)&&i>s||setTimeout(r,f,o)},Sn=(e,t)=>oe(e)==oe(t),[ct,vn]=_n(new Map),wn=H({onLoadingSlow:G,onSuccess:G,onError:G,onErrorRetry:En,onDiscarded:G,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:Je?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:Je?5e3:3e3,compare:Sn,isPaused:()=>!1,cache:ct,mutate:vn,fallback:{}},dn),mn=(e,t)=>{const n=H(e,t);if(t){const{use:r,fallback:o}=e,{use:s,fallback:i}=t;r&&s&&(n.use=r.concat(s)),o&&i&&(n.fallback=H(o,i))}return n},bn=g.createContext({}),On="$inf$",ft=pe&&window.__SWR_DEVTOOLS_USE__,Rn=ft?window.__SWR_DEVTOOLS_USE__:[],Tn=()=>{ft&&(window.__SWR_DEVTOOLS_REACT__=g)},Cn=e=>F(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],Dn=()=>H(wn,g.useContext(bn)),An=e=>(t,n,r)=>e(t,n&&((...s)=>{const[i]=Ve(t),[,,,f]=q.get(ct);if(i.startsWith(On))return n(...s);const h=f[i];return E(h)?n(...s):(delete f[i],h)}),r),xn=Rn.concat(An),Pn=e=>function(...n){const r=Dn(),[o,s,i]=Cn(n),f=mn(r,i);let h=e;const{use:c}=f,a=(c||[]).concat(xn);for(let u=a.length;u--;)h=a[u](h);return h(o,s||f.fetcher||null,f)},jn=(e,t,n)=>{const r=t[e]||(t[e]=[]);return r.push(n),()=>{const o=r.indexOf(n);o>=0&&(r[o]=r[r.length-1],r.pop())}};Tn();const Qe=g.use||(e=>{if(e.status==="pending")throw e;if(e.status==="fulfilled")return e.value;throw e.status==="rejected"?e.reason:(e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e)}),be={dedupe:!0},Ln=(e,t,n)=>{const{cache:r,compare:o,suspense:s,fallbackData:i,revalidateOnMount:f,revalidateIfStale:h,refreshInterval:c,refreshWhenHidden:a,refreshWhenOffline:u,keepPreviousData:d}=n,[l,_,y,C]=q.get(r),[p,k]=Ve(e),R=g.useRef(!1),S=g.useRef(!1),w=g.useRef(p),v=g.useRef(t),I=g.useRef(n),m=()=>I.current,D=()=>m().isVisible()&&m().isOnline(),[j,B,z,M]=ot(r,p),Y=g.useRef({}).current,Wt=E(i)?n.fallback[p]:i,Ne=(b,O)=>{for(const x in Y){const T=x;if(T==="data"){if(!o(b[T],O[T])&&(!E(b[T])||!o(ae,O[T])))return!1}else if(O[T]!==b[T])return!1}return!0},Fe=g.useMemo(()=>{const b=!p||!t?!1:E(f)?m().isPaused()||s?!1:E(h)?!0:h:f,O=P=>{const U=H(P);return delete U._k,b?{isValidating:!0,isLoading:!0,...U}:U},x=j(),T=M(),N=O(x),Z=x===T?N:O(T);let A=N;return[()=>{const P=O(j());return Ne(P,A)?(A.data=P.data,A.isLoading=P.isLoading,A.isValidating=P.isValidating,A.error=P.error,A):(A=P,P)},()=>Z]},[r,p]),J=rn.useSyncExternalStore(g.useCallback(b=>z(p,(O,x)=>{Ne(x,O)||b()}),[r,p]),Fe[0],Fe[1]),Ue=!R.current,qt=l[p]&&l[p].length>0,X=J.data,Q=E(X)?Wt:X,ie=J.error,We=g.useRef(Q),ae=d?E(X)?We.current:X:Q,qe=qt&&!E(ie)?!1:Ue&&!E(f)?f:m().isPaused()?!1:s?E(Q)?!1:h:E(Q)||h,Be=!!(p&&t&&Ue&&qe),Bt=E(J.isValidating)?Be:J.isValidating,$t=E(J.isLoading)?Be:J.isLoading,ne=g.useCallback(async b=>{const O=v.current;if(!p||!O||S.current||m().isPaused())return!1;let x,T,N=!0;const Z=b||{},A=!y[p]||!Z.dedupe,P=()=>Ye?!S.current&&p===w.current&&R.current:p===w.current,U={isValidating:!1,isLoading:!1},Ge=()=>{B(U)},He=()=>{const V=y[p];V&&V[1]===T&&delete y[p]},Ke={isValidating:!0};E(j().data)&&(Ke.isLoading=!0);try{if(A&&(B(Ke),n.loadingTimeout&&E(j().data)&&setTimeout(()=>{N&&P()&&m().onLoadingSlow(p,n)},n.loadingTimeout),y[p]=[O(k),xe()]),[x,T]=y[p],x=await x,A&&setTimeout(He,n.dedupingInterval),!y[p]||y[p][1]!==T)return A&&P()&&m().onDiscarded(p),!1;U.error=L;const V=_[p];if(!E(V)&&(T<=V[0]||T<=V[1]||V[1]===0))return Ge(),A&&P()&&m().onDiscarded(p),!1;const W=j().data;U.data=o(W,x)?W:x,A&&P()&&m().onSuccess(x,p,n)}catch(V){He();const W=m(),{shouldRetryOnError:ge}=W;W.isPaused()||(U.error=V,A&&P()&&(W.onError(V,p,W),(ge===!0||F(ge)&&ge(V))&&(!m().revalidateOnFocus||!m().revalidateOnReconnect||D())&&W.onErrorRetry(V,p,W,Gt=>{const ye=l[p];ye&&ye[0]&&ye[0](re.ERROR_REVALIDATE_EVENT,Gt)},{retryCount:(Z.retryCount||0)+1,dedupe:!0})))}return N=!1,Ge(),!0},[p,r]),$e=g.useCallback((...b)=>ut(r,w.current,...b),[]);if(we(()=>{v.current=t,I.current=n,E(X)||(We.current=X)}),we(()=>{if(!p)return;const b=ne.bind(L,be);let O=0;const T=jn(p,l,(N,Z={})=>{if(N==re.FOCUS_EVENT){const A=Date.now();m().revalidateOnFocus&&A>O&&D()&&(O=A+m().focusThrottleInterval,b())}else if(N==re.RECONNECT_EVENT)m().revalidateOnReconnect&&D()&&b();else{if(N==re.MUTATE_EVENT)return ne();if(N==re.ERROR_REVALIDATE_EVENT)return ne(Z)}});return S.current=!1,w.current=p,R.current=!0,B({_k:k}),qe&&(E(Q)||se?b():hn(b)),()=>{S.current=!0,T()}},[p]),we(()=>{let b;function O(){const T=F(c)?c(j().data):c;T&&b!==-1&&(b=setTimeout(x,T))}function x(){!j().error&&(a||m().isVisible())&&(u||m().isOnline())?ne(be).then(O):O()}return O(),()=>{b&&(clearTimeout(b),b=-1)}},[c,a,u,p]),g.useDebugValue(ae),s&&E(Q)&&p){if(!Ye&&se)throw new Error("Fallback data is required when using suspense in SSR.");v.current=t,I.current=n,S.current=!1;const b=C[p];if(!E(b)){const O=$e(b);Qe(O)}if(E(ie)){const O=ne(be);E(ae)||(O.status="fulfilled",O.value=!0),Qe(O)}else throw ie}return{mutate:$e,get data(){return Y.data=!0,ae},get error(){return Y.error=!0,ie},get isValidating(){return Y.isValidating=!0,Bt},get isLoading(){return Y.isLoading=!0,$t}}},In=Pn(Ln);function Vn(){const{widgetCtx:e}=K();return In([e.config.token],e.api.widgetPrelude,{revalidateOnFocus:!1})}function Mn(){const{widgetCtx:e}=K();return{routerState:ee(e.routerCtx.state),toSessionsScreen:e.routerCtx.toSessionsScreen,toChatScreen:e.routerCtx.toChatScreen}}var lt={},Pe=function(e,t){return Pe=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[o]=r[o])},Pe(e,t)};function dt(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Pe(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}var le=function(){return le=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},le.apply(this,arguments)};function pt(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function ht(e,t,n,r){var o=arguments.length,s=o<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(e,t,n,r);else for(var f=e.length-1;f>=0;f--)(i=e[f])&&(s=(o<3?i(s):o>3?i(t,n,s):i(t,n))||s);return o>3&&s&&Object.defineProperty(t,n,s),s}function gt(e,t){return function(n,r){t(n,r,e)}}function yt(e,t,n,r,o,s){function i(p){if(p!==void 0&&typeof p!="function")throw new TypeError("Function expected");return p}for(var f=r.kind,h=f==="getter"?"get":f==="setter"?"set":"value",c=!t&&e?r.static?e:e.prototype:null,a=t||(c?Object.getOwnPropertyDescriptor(c,r.name):{}),u,d=!1,l=n.length-1;l>=0;l--){var _={};for(var y in r)_[y]=y==="access"?{}:r[y];for(var y in r.access)_.access[y]=r.access[y];_.addInitializer=function(p){if(d)throw new TypeError("Cannot add initializers after decoration has completed");s.push(i(p||null))};var C=(0,n[l])(f==="accessor"?{get:a.get,set:a.set}:a[h],_);if(f==="accessor"){if(C===void 0)continue;if(C===null||typeof C!="object")throw new TypeError("Object expected");(u=i(C.get))&&(a.get=u),(u=i(C.set))&&(a.set=u),(u=i(C.init))&&o.unshift(u)}else(u=i(C))&&(f==="field"?o.unshift(u):a[h]=u)}c&&Object.defineProperty(c,r.name,a),d=!0}function _t(e,t,n){for(var r=arguments.length>2,o=0;o<t.length;o++)n=r?t[o].call(e,n):t[o].call(e);return r?n:void 0}function Et(e){return typeof e=="symbol"?e:"".concat(e)}function St(e,t,n){return typeof t=="symbol"&&(t=t.description?"[".concat(t.description,"]"):""),Object.defineProperty(e,"name",{configurable:!0,value:n?"".concat(n," ",t):t})}function vt(e,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(e,t)}function wt(e,t,n,r){function o(s){return s instanceof n?s:new n(function(i){i(s)})}return new(n||(n=Promise))(function(s,i){function f(a){try{c(r.next(a))}catch(u){i(u)}}function h(a){try{c(r.throw(a))}catch(u){i(u)}}function c(a){a.done?s(a.value):o(a.value).then(f,h)}c((r=r.apply(e,t||[])).next())})}function mt(e,t){var n={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,o,s,i=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return i.next=f(0),i.throw=f(1),i.return=f(2),typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function f(c){return function(a){return h([c,a])}}function h(c){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(n=0)),n;)try{if(r=1,o&&(s=c[0]&2?o.return:c[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,c[1])).done)return s;switch(o=0,s&&(c=[c[0]&2,s.value]),c[0]){case 0:case 1:s=c;break;case 4:return n.label++,{value:c[1],done:!1};case 5:n.label++,o=c[1],c=[0];continue;case 7:c=n.ops.pop(),n.trys.pop();continue;default:if(s=n.trys,!(s=s.length>0&&s[s.length-1])&&(c[0]===6||c[0]===2)){n=0;continue}if(c[0]===3&&(!s||c[1]>s[0]&&c[1]<s[3])){n.label=c[1];break}if(c[0]===6&&n.label<s[1]){n.label=s[1],s=c;break}if(s&&n.label<s[2]){n.label=s[2],n.ops.push(c);break}s[2]&&n.ops.pop(),n.trys.pop();continue}c=t.call(e,n)}catch(a){c=[6,a],o=0}finally{r=s=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}var he=Object.create?function(e,t,n,r){r===void 0&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]};function bt(e,t){for(var n in e)n!=="default"&&!Object.prototype.hasOwnProperty.call(t,n)&&he(t,e,n)}function de(e){var t=typeof Symbol=="function"&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Me(e,t){var n=typeof Symbol=="function"&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),o,s=[],i;try{for(;(t===void 0||t-- >0)&&!(o=r.next()).done;)s.push(o.value)}catch(f){i={error:f}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return s}function Ot(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(Me(arguments[t]));return e}function Rt(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var r=Array(e),o=0,t=0;t<n;t++)for(var s=arguments[t],i=0,f=s.length;i<f;i++,o++)r[o]=s[i];return r}function Tt(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}function te(e){return this instanceof te?(this.v=e,this):new te(e)}function Ct(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),o,s=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),f("next"),f("throw"),f("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(l){return function(_){return Promise.resolve(_).then(l,u)}}function f(l,_){r[l]&&(o[l]=function(y){return new Promise(function(C,p){s.push([l,y,C,p])>1||h(l,y)})},_&&(o[l]=_(o[l])))}function h(l,_){try{c(r[l](_))}catch(y){d(s[0][3],y)}}function c(l){l.value instanceof te?Promise.resolve(l.value.v).then(a,u):d(s[0][2],l)}function a(l){h("next",l)}function u(l){h("throw",l)}function d(l,_){l(_),s.shift(),s.length&&h(s[0][0],s[0][1])}}function Dt(e){var t,n;return t={},r("next"),r("throw",function(o){throw o}),r("return"),t[Symbol.iterator]=function(){return this},t;function r(o,s){t[o]=e[o]?function(i){return(n=!n)?{value:te(e[o](i)),done:!1}:s?s(i):i}:s}}function At(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof de=="function"?de(e):e[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(s){n[s]=e[s]&&function(i){return new Promise(function(f,h){i=e[s](i),o(f,h,i.done,i.value)})}}function o(s,i,f,h){Promise.resolve(h).then(function(c){s({value:c,done:f})},i)}}function xt(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}var Nn=Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t};function Pt(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n in e)n!=="default"&&Object.prototype.hasOwnProperty.call(e,n)&&he(t,e,n);return Nn(t,e),t}function jt(e){return e&&e.__esModule?e:{default:e}}function Lt(e,t,n,r){if(n==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return n==="m"?r:n==="a"?r.call(e):r?r.value:t.get(e)}function It(e,t,n,r,o){if(r==="m")throw new TypeError("Private method is not writable");if(r==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r==="a"?o.call(e,n):o?o.value=n:t.set(e,n),n}function Vt(e,t){if(t===null||typeof t!="object"&&typeof t!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof e=="function"?t===e:e.has(t)}function Mt(e,t,n){if(t!=null){if(typeof t!="object"&&typeof t!="function")throw new TypeError("Object expected.");var r,o;if(n){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");r=t[Symbol.asyncDispose]}if(r===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");r=t[Symbol.dispose],n&&(o=r)}if(typeof r!="function")throw new TypeError("Object not disposable.");o&&(r=function(){try{o.call(this)}catch(s){return Promise.reject(s)}}),e.stack.push({value:t,dispose:r,async:n})}else n&&e.stack.push({async:!0});return t}var Fn=typeof SuppressedError=="function"?SuppressedError:function(e,t,n){var r=new Error(n);return r.name="SuppressedError",r.error=e,r.suppressed=t,r};function Nt(e){function t(s){e.error=e.hasError?new Fn(s,e.error,"An error was suppressed during disposal."):s,e.hasError=!0}var n,r=0;function o(){for(;n=e.stack.pop();)try{if(!n.async&&r===1)return r=0,e.stack.push(n),Promise.resolve().then(o);if(n.dispose){var s=n.dispose.call(n.value);if(n.async)return r|=2,Promise.resolve(s).then(o,function(i){return t(i),o()})}else r|=1}catch(i){t(i)}if(r===1)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}return o()}function Ft(e,t){return typeof e=="string"&&/^\.\.?\//.test(e)?e.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(n,r,o,s,i){return r?t?".jsx":".js":o&&(!s||!i)?n:o+s+"."+i.toLowerCase()+"js"}):e}const Un={__extends:dt,__assign:le,__rest:pt,__decorate:ht,__param:gt,__esDecorate:yt,__runInitializers:_t,__propKey:Et,__setFunctionName:St,__metadata:vt,__awaiter:wt,__generator:mt,__createBinding:he,__exportStar:bt,__values:de,__read:Me,__spread:Ot,__spreadArrays:Rt,__spreadArray:Tt,__await:te,__asyncGenerator:Ct,__asyncDelegator:Dt,__asyncValues:At,__makeTemplateObject:xt,__importStar:Pt,__importDefault:jt,__classPrivateFieldGet:Lt,__classPrivateFieldSet:It,__classPrivateFieldIn:Vt,__addDisposableResource:Mt,__disposeResources:Nt,__rewriteRelativeImportExtension:Ft},Wn=Object.freeze(Object.defineProperty({__proto__:null,__addDisposableResource:Mt,get __assign(){return le},__asyncDelegator:Dt,__asyncGenerator:Ct,__asyncValues:At,__await:te,__awaiter:wt,__classPrivateFieldGet:Lt,__classPrivateFieldIn:Vt,__classPrivateFieldSet:It,__createBinding:he,__decorate:ht,__disposeResources:Nt,__esDecorate:yt,__exportStar:bt,__extends:dt,__generator:mt,__importDefault:jt,__importStar:Pt,__makeTemplateObject:xt,__metadata:vt,__param:gt,__propKey:Et,__read:Me,__rest:pt,__rewriteRelativeImportExtension:Ft,__runInitializers:_t,__setFunctionName:St,__spread:Ot,__spreadArray:Tt,__spreadArrays:Rt,__values:de,default:Un},Symbol.toStringTag,{value:"Module"})),qn=en(Wn);var fe={},Ze;function Bn(){if(Ze)return fe;Ze=1,Object.defineProperty(fe,"__esModule",{value:!0});var e=g;function t(){var n=e.useRef(!1),r=e.useCallback(function(){return n.current},[]);return e.useEffect(function(){return n.current=!0,function(){n.current=!1}},[]),r}return fe.default=t,fe}Object.defineProperty(lt,"__esModule",{value:!0});var je=qn,Oe=g,$n=je.__importDefault(Bn());function Gn(e,t,n){t===void 0&&(t=[]),n===void 0&&(n={loading:!1});var r=Oe.useRef(0),o=$n.default(),s=Oe.useState(n),i=s[0],f=s[1],h=Oe.useCallback(function(){for(var c=[],a=0;a<arguments.length;a++)c[a]=arguments[a];var u=++r.current;return i.loading||f(function(d){return je.__assign(je.__assign({},d),{loading:!0})}),e.apply(void 0,c).then(function(d){return o()&&u===r.current&&f({value:d,loading:!1}),d},function(d){return o()&&u===r.current&&f({error:d,loading:!1}),d})},t);return[i,h]}var Hn=lt.default=Gn;const $=new Map;function Kn(){const[e,t]=g.useState([]),{widgetCtx:{api:n}}=K();function r(a){const u=a.map(d=>({file:d,id:Ht.v4(),status:"pending",progress:0}));t(d=>[...d,...u]),u.forEach(i)}function o(a,u){t(d=>d.map(l=>l.id===a?{...l,...u}:l))}function s(a){t(u=>u.filter(d=>d.id!==a))}const i=async a=>{const u=new AbortController;$.set(a.id,u);try{t(l=>l.map(_=>_.id===a.id?{..._,status:"uploading",progress:0}:_));const d=await n.uploadFile({file:a.file,abortSignal:u.signal,onProgress:l=>{o(a.id,{progress:l})}});o(a.id,{status:"success",fileUrl:d.fileUrl,progress:100})}catch(d){u.signal.aborted||o(a.id,{status:"error",error:d instanceof Error?d.message:"Upload failed",progress:0})}finally{$.delete(a.id)}},f=a=>{const u=$.get(a);u&&(u.abort(),$.delete(a)),s(a)},h=g.useMemo(()=>e.filter(a=>a.status==="success"&&a.fileUrl),[e]);function c(){$.forEach(a=>a.abort()),$.clear(),t([])}return g.useEffect(()=>()=>{$.forEach(a=>a.abort()),$.clear()},[]),{allFiles:e,appendFiles:r,handleCancelUpload:f,successFiles:h,emptyTheFiles:c,getFileById:a=>e.find(u=>u.id===a),getUploadProgress:a=>{var u;return((u=e.find(d=>d.id===a))==null?void 0:u.progress)??0},getUploadStatus:a=>{var u;return(u=e.find(d=>d.id===a))==null?void 0:u.status},hasErrors:e.some(a=>a.status==="error"),isUploading:e.some(a=>a.status==="uploading")}}const Ut=g.createContext(null);function zn({children:e}){const t=Le(),[n,r]=g.useState(t.isOpen??!1);return g.useEffect(()=>{r(o=>t.isOpen??o)},[t.isOpen]),g.useEffect(()=>{const o=t.openAfterNSeconds;if(typeof o!="number"||isNaN(o))return;const s=setTimeout(()=>r(!0),o*1e3);return()=>clearTimeout(s)},[t.openAfterNSeconds]),et.jsx(Ut.Provider,{value:{isOpen:n,setIsOpen:r},children:e})}function kn(){const e=g.useContext(Ut);if(!e)throw new Error("useWidgetTrigger must be used within a WidgetTriggerProvider");return e}exports.WidgetProvider=Yt;exports.WidgetTriggerProvider=zn;exports._default=Hn;exports.commonjsGlobal=Qt;exports.getDefaultExportFromCjs=Zt;exports.useConfig=Le;exports.useContact=Jt;exports.useIsAwaitingBotReply=Xt;exports.useMessages=nt;exports.usePreludeData=Vn;exports.usePrimitiveState=ee;exports.useSessions=rt;exports.useUploadFiles=Kn;exports.useWidget=K;exports.useWidgetRouter=Mn;exports.useWidgetTrigger=kn;
|
|
18
|
+
//# sourceMappingURL=useWidgetTrigger-Be2RN31V.cjs.map
|