@opencx/widget 3.0.90 → 3.0.91
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 +6 -6
- package/dist/designs.cjs.map +1 -1
- package/dist/designs.js +170 -171
- package/dist/designs.js.map +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +2 -2
- package/dist/src/designs/react/index.d.ts +2 -3
- package/dist/src/headless/core/index.d.ts +1 -1
- package/dist/src/headless/core/types/widget-config.d.ts +20 -0
- package/dist/src/headless/react/WidgetProvider.d.ts +1 -4
- package/dist/src/headless/react/hooks/useModes.d.ts +2 -2
- package/dist/src/headless/react/index.d.ts +0 -1
- package/dist/useModes-CAashveE.cjs +2 -0
- package/dist/useModes-CAashveE.cjs.map +1 -0
- package/dist/{useModes-B3IdrBWZ.js → useModes-COzOEDch.js} +47 -49
- package/dist/useModes-COzOEDch.js.map +1 -0
- package/dist-embed/script.js +18 -18
- package/dist-embed/script.js.map +1 -1
- package/package.json +1 -1
- package/dist/src/headless/react/types/modes.components.d.ts +0 -11
- package/dist/useModes-B3IdrBWZ.js.map +0 -1
- package/dist/useModes-ZmjqOTMd.cjs +0 -2
- package/dist/useModes-ZmjqOTMd.cjs.map +0 -1
package/dist/react.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useModes-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useModes-CAashveE.cjs"),o=require("react-use/lib/useAsyncFn");function g(s,t,i){const{widgetCtx:{api:u}}=e.useWidget();return o(async r=>u.vote({action:r==="up"?"upvote":"downvote",messagePublicId:s,sessionId:t}).then(i),[u,s,t,i])}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.useModes=e.useModes;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 o } from "./useModes-
|
|
2
|
-
import { W as m, k as c, a as f, b as l, c as v, d as W, l as P, e as w, f as x, g as y, i as C, h as b, j as h } from "./useModes-
|
|
1
|
+
import { u as o } from "./useModes-COzOEDch.js";
|
|
2
|
+
import { W as m, k as c, a as f, b as l, c as v, d as W, l as P, e as w, f as x, g as y, i as C, h as b, j as h } from "./useModes-COzOEDch.js";
|
|
3
3
|
import r from "react-use/lib/useAsyncFn";
|
|
4
4
|
function n(e, s, t) {
|
|
5
5
|
const {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { WidgetConfig } from '../../headless/core';
|
|
3
|
-
import { WidgetComponentType
|
|
4
|
-
declare function WidgetWrapper({ options, components,
|
|
3
|
+
import { WidgetComponentType } from '../../headless/react';
|
|
4
|
+
declare function WidgetWrapper({ options, components, loadingComponent, }: {
|
|
5
5
|
options: WidgetConfig;
|
|
6
6
|
components?: WidgetComponentType[];
|
|
7
|
-
modesComponents?: WidgetModeComponentType[];
|
|
8
7
|
loadingComponent?: React.ReactNode;
|
|
9
8
|
}): React.JSX.Element;
|
|
10
9
|
export { WidgetWrapper as Widget };
|
|
@@ -2,7 +2,7 @@ export type { AgentOrBotType } from './types/agent-or-bot';
|
|
|
2
2
|
export type { SafeExtract, StringOrLiteral } from './types/helpers';
|
|
3
3
|
export type { LiteralWidgetComponentKey, WidgetComponentKey, UserMessageType, AgentMessageType, BotMessageType, MessageType, } from './types/messages';
|
|
4
4
|
export type { MessageAttachmentType, MessageDto, PreludeDto, SendMessageDto, SendMessageOutputDto, ResolveSessionDto, SessionDto, VoteInputDto, VoteOutputDto, ActionCallDto, ModeDto, } from './types/dtos';
|
|
5
|
-
export type { WidgetConfig, HeaderButtonU } from './types/widget-config';
|
|
5
|
+
export type { WidgetConfig, HeaderButtonU, ModeComponent, ModeComponentProps, } from './types/widget-config';
|
|
6
6
|
export type { ExternalStorage } from './types/external-storage';
|
|
7
7
|
export type { OpenCxComponentNameU } from './types/component-name';
|
|
8
8
|
export type { IconNameU } from './types/icons';
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
1
2
|
import { AgentOrBotType } from './agent-or-bot';
|
|
2
3
|
import { IconNameU } from './icons';
|
|
3
4
|
import { JsonValue } from './json-value';
|
|
5
|
+
import { ModeDto } from './dtos';
|
|
6
|
+
import { SessionCtx } from '../context/session.ctx';
|
|
7
|
+
import { MessageCtx } from '../context/message.ctx';
|
|
4
8
|
type UserBaseConfig = {
|
|
5
9
|
token: string;
|
|
6
10
|
data?: never;
|
|
@@ -118,6 +122,18 @@ export type HeaderButtonU = (HeaderButtonBase & {
|
|
|
118
122
|
cancelButtonText?: string;
|
|
119
123
|
};
|
|
120
124
|
});
|
|
125
|
+
export type ModeComponentProps = {
|
|
126
|
+
react: typeof React;
|
|
127
|
+
mode: ModeDto;
|
|
128
|
+
createStateCheckpoint: SessionCtx['createStateCheckpoint'];
|
|
129
|
+
sendMessage: MessageCtx['sendMessage'];
|
|
130
|
+
isSendingMessage: boolean;
|
|
131
|
+
};
|
|
132
|
+
export type ModeComponent = {
|
|
133
|
+
/** The mode's ID, name or slug */
|
|
134
|
+
key: string;
|
|
135
|
+
component: (props: ModeComponentProps) => ReturnType<typeof React.createElement>;
|
|
136
|
+
};
|
|
121
137
|
export interface WidgetConfig {
|
|
122
138
|
/**
|
|
123
139
|
* Your organization's widget token.
|
|
@@ -248,6 +264,10 @@ export interface WidgetConfig {
|
|
|
248
264
|
sessionsScreen?: Array<HeaderButtonU>;
|
|
249
265
|
chatScreen?: Array<HeaderButtonU>;
|
|
250
266
|
};
|
|
267
|
+
/**
|
|
268
|
+
* Custom components to be mounted in the canvas if there is an active mode.
|
|
269
|
+
*/
|
|
270
|
+
modesComponents?: Array<ModeComponent>;
|
|
251
271
|
/**
|
|
252
272
|
* Customize the router behavior.
|
|
253
273
|
*/
|
|
@@ -2,21 +2,18 @@ import { default as React } from 'react';
|
|
|
2
2
|
import { ExternalStorage, WidgetConfig, WidgetCtx } from '../core';
|
|
3
3
|
import { ComponentRegistry } from './ComponentRegistry';
|
|
4
4
|
import { WidgetComponentType } from './types/components';
|
|
5
|
-
import { WidgetModeComponentType } from './types/modes.components';
|
|
6
5
|
interface WidgetProviderValue {
|
|
7
6
|
widgetCtx: WidgetCtx;
|
|
8
7
|
config: WidgetConfig;
|
|
9
8
|
components?: WidgetComponentType[];
|
|
10
|
-
modesComponents?: WidgetModeComponentType[];
|
|
11
9
|
componentStore: ComponentRegistry;
|
|
12
10
|
version: string;
|
|
13
11
|
contentIframeRef?: React.MutableRefObject<HTMLIFrameElement | null>;
|
|
14
12
|
}
|
|
15
|
-
export declare function WidgetProvider({ options: config, children, components,
|
|
13
|
+
export declare function WidgetProvider({ options: config, children, components, storage, loadingComponent, }: {
|
|
16
14
|
options: WidgetConfig;
|
|
17
15
|
children: React.ReactNode;
|
|
18
16
|
components?: WidgetComponentType[];
|
|
19
|
-
modesComponents?: WidgetModeComponentType[];
|
|
20
17
|
storage?: ExternalStorage;
|
|
21
18
|
/**
|
|
22
19
|
* Custom loading component while the widget is initializing
|
|
@@ -4,12 +4,12 @@ export declare function useModes(): {
|
|
|
4
4
|
name: string;
|
|
5
5
|
slug?: string | null;
|
|
6
6
|
}[];
|
|
7
|
-
modesComponents: import('
|
|
7
|
+
modesComponents: import('../../core').ModeComponent[] | undefined;
|
|
8
8
|
activeModeId: string | null | undefined;
|
|
9
9
|
activeMode: {
|
|
10
10
|
id: string;
|
|
11
11
|
name: string;
|
|
12
12
|
slug?: string | null;
|
|
13
13
|
} | undefined;
|
|
14
|
-
Component: import('
|
|
14
|
+
Component: ((props: import('../../core').ModeComponentProps) => ReturnType<typeof React.createElement>) | undefined;
|
|
15
15
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export type { WidgetComponentType, WidgetComponentProps, } from './types/components';
|
|
2
|
-
export type { WidgetModeComponentType } from './types/modes.components';
|
|
3
2
|
export { WidgetProvider, useWidget } from './WidgetProvider';
|
|
4
3
|
export { useConfig } from './hooks/useConfig';
|
|
5
4
|
export { useContact } from './hooks/useContact';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const U=require("swr"),u=require("react"),F=require("uuid"),y=require("react/jsx-runtime"),P=require("./widget.ctx-6xcbtF7q.cjs"),R="3.0.91";class b{constructor(t){this.components=[];const{components:n}=t;if(n&&n.forEach(o=>this.register(o)),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(o=>o.key===t.key);return n!==-1?this.components[n]=t:this.components.push(t),this}get(t){const n=this.components.find(o=>o.key.toUpperCase()===t.toUpperCase());return n||null}getComponent(t){var n;return(n=this.get(t))==null?void 0:n.component}}const W=u.createContext(null);function A({options:e,children:t,components:n,storage:o,loadingComponent:i}){const c=u.useRef(null),d=u.useRef(!1),[l,C]=u.useState(null),p=u.useMemo(()=>new b({components:n}),[n]);return u.useEffect(()=>{d.current||(d.current=!0,P.WidgetCtx.initialize({config:e,storage:o}).then(C))},[]),l?y.jsx(W.Provider,{value:{widgetCtx:l,config:e,components:n,componentStore:p,version:R,contentIframeRef:c},children:t}):i||null}function g(){const e=u.useContext(W);if(!e)throw new Error("useWidget must be used within a WidgetProvider");return e}function x(){const{config:e}=g();return e}function m(e){return u.useSyncExternalStore(e.subscribe,e.get,e.get)}function M(){const{widgetCtx:e}=g();return{contactState:m(e.contactCtx.state),createUnverifiedContact:e.contactCtx.createUnverifiedContact}}function v(){const{widgetCtx:e}=g();return{messagesState:m(e.messageCtx.state),sendMessage:e.messageCtx.sendMessage}}function w(){const{widgetCtx:e}=g(),{oneOpenSessionAllowed:t}=x(),n=m(e.sessionCtx.sessionState),o=m(e.sessionCtx.sessionsState),{openSessions:i,closedSessions:c}=u.useMemo(()=>({openSessions:o.data.filter(l=>l.isOpened===!0),closedSessions:o.data.filter(l=>l.isOpened===!1)}),[o.data]),d=u.useMemo(()=>t?i.length===0:!0,[t,i.length]);return{sessionState:n,sessionsState:o,loadMoreSessions:e.sessionCtx.loadMoreSessions,resolveSession:e.sessionCtx.resolveSession,createStateCheckpoint:e.sessionCtx.createStateCheckpoint,openSessions:i,closedSessions:c,canCreateNewSession:d}}function k(){var d;const{sessionState:e}=w(),{messagesState:t}=v(),n=((d=e.session)==null?void 0:d.assignee.kind)==="ai",o=t.messages.length>0?t.messages[t.messages.length-1]:null,i=(o==null?void 0:o.type)==="FROM_USER";return{isAwaitingBotReply:(n||e.isCreatingSession)&&(t.isSendingMessage||i)}}function O(){const{widgetCtx:e}=g();return U([e.config.token],e.api.widgetPrelude,{revalidateOnFocus:!1})}function T(){const{widgetCtx:e}=g();return{routerState:m(e.routerCtx.state),toSessionsScreen:e.routerCtx.toSessionsScreen,toChatScreen:e.routerCtx.toChatScreen}}const f=new Map;function N(){const[e,t]=u.useState([]),{widgetCtx:{api:n}}=g();function o(s){const r=s.map(a=>({file:a,id:F.v4(),status:"pending",progress:0}));t(a=>[...a,...r]),r.forEach(d)}function i(s,r){t(a=>a.map(S=>S.id===s?{...S,...r}:S))}function c(s){t(r=>r.filter(a=>a.id!==s))}const d=async s=>{const r=new AbortController;f.set(s.id,r);try{t(S=>S.map(h=>h.id===s.id?{...h,status:"uploading",progress:0}:h));const a=await n.uploadFile({file:s.file,abortSignal:r.signal,onProgress:S=>{i(s.id,{progress:S})}});i(s.id,{status:"success",fileUrl:a.fileUrl,progress:100})}catch(a){r.signal.aborted||i(s.id,{status:"error",error:a instanceof Error?a.message:"Upload failed",progress:0})}finally{f.delete(s.id)}},l=s=>{const r=f.get(s);r&&(r.abort(),f.delete(s)),c(s)},C=u.useMemo(()=>e.filter(s=>s.status==="success"&&s.fileUrl),[e]);function p(){f.forEach(s=>s.abort()),f.clear(),t([])}return u.useEffect(()=>()=>{f.forEach(s=>s.abort()),f.clear()},[]),{allFiles:e,appendFiles:o,handleCancelUpload:l,successFiles:C,emptyTheFiles:p,getFileById:s=>e.find(r=>r.id===s),getUploadProgress:s=>{var r;return((r=e.find(a=>a.id===s))==null?void 0:r.progress)??0},getUploadStatus:s=>{var r;return(r=e.find(a=>a.id===s))==null?void 0:r.status},hasErrors:e.some(s=>s.status==="error"),isUploading:e.some(s=>s.status==="uploading")}}const E=u.createContext(null);function B({children:e}){const t=x(),[n,o]=u.useState(t.isOpen??!1);return u.useEffect(()=>{o(i=>t.isOpen??i)},[t.isOpen]),u.useEffect(()=>{const i=t.openAfterNSeconds;if(typeof i!="number"||isNaN(i))return;const c=setTimeout(()=>o(!0),i*1e3);return()=>clearTimeout(c)},[t.openAfterNSeconds]),y.jsx(E.Provider,{value:{isOpen:n,setIsOpen:o},children:e})}function q(){const e=u.useContext(E);if(!e)throw new Error("useWidgetTrigger must be used within a WidgetTriggerProvider");return e}function I(){var l,C;const{widgetCtx:e}=g(),{modesComponents:t}=x(),{sessionState:n}=w(),o=e.modes,i=(l=n.session)==null?void 0:l.modeId,c=o.find(p=>p.id===i),d=(C=t==null?void 0:t.find(p=>{var s,r;return[(c==null?void 0:c.id)||"",((s=c==null?void 0:c.name)==null?void 0:s.toLowerCase())||"",((r=c==null?void 0:c.slug)==null?void 0:r.toLowerCase())||""].includes(p.key.toLowerCase())}))==null?void 0:C.component;return{modes:o,modesComponents:t,activeModeId:i,activeMode:c,Component:d}}exports.WidgetProvider=A;exports.WidgetTriggerProvider=B;exports.useConfig=x;exports.useContact=M;exports.useIsAwaitingBotReply=k;exports.useMessages=v;exports.useModes=I;exports.usePreludeData=O;exports.usePrimitiveState=m;exports.useSessions=w;exports.useUploadFiles=N;exports.useWidget=g;exports.useWidgetRouter=T;exports.useWidgetTrigger=q;
|
|
2
|
+
//# sourceMappingURL=useModes-CAashveE.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useModes-CAashveE.cjs","sources":["../src/headless/react/ComponentRegistry.ts","../src/headless/react/WidgetProvider.tsx","../src/headless/react/hooks/useConfig.ts","../src/headless/react/hooks/usePrimitiveState.ts","../src/headless/react/hooks/useContact.ts","../src/headless/react/hooks/useMessages.ts","../src/headless/react/hooks/useSessions.ts","../src/headless/react/hooks/useIsAwaitingBotReply.ts","../src/headless/react/hooks/usePreludeData.ts","../src/headless/react/hooks/useWidgetRouter.ts","../src/headless/react/hooks/useUploadFiles.ts","../src/headless/react/hooks/useWidgetTrigger.tsx","../src/headless/react/hooks/useModes.ts"],"sourcesContent":["import type { WidgetComponentKey } from '../core';\nimport type { WidgetComponentType } from './types/components';\n\nexport class ComponentRegistry {\n components: WidgetComponentType[] = [];\n\n constructor(opts: { components?: WidgetComponentType[] }) {\n const { components } = opts;\n\n if (components) {\n components.forEach((c) => this.register(c));\n }\n\n if (this.components.length === 0) {\n throw new Error('No components registered');\n }\n if (!this.get('fallback')) {\n throw new Error('No fallback component registered');\n }\n }\n\n // TODO test that this registers or replaces the component\n register(component: WidgetComponentType) {\n // Replace the key if it already exists\n const index = this.components.findIndex((c) => c.key === component.key);\n if (index !== -1) {\n this.components[index] = component;\n } else {\n this.components.push(component);\n }\n return this;\n }\n\n private get(key: WidgetComponentKey) {\n const c = this.components.find(\n (c) => c.key.toUpperCase() === key.toUpperCase(),\n );\n if (c) return c;\n return null;\n }\n\n public getComponent(key: string) {\n return this.get(key)?.component;\n }\n}\n","import React, {\n createContext,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { version } from '../../../package.json';\nimport { type ExternalStorage, type WidgetConfig, WidgetCtx } from '../core';\nimport { ComponentRegistry } from './ComponentRegistry';\nimport type { WidgetComponentType } from './types/components';\n\ninterface WidgetProviderValue {\n widgetCtx: WidgetCtx;\n config: WidgetConfig;\n components?: WidgetComponentType[];\n componentStore: ComponentRegistry;\n version: string;\n contentIframeRef?: React.MutableRefObject<HTMLIFrameElement | null>;\n}\n\nconst context = createContext<WidgetProviderValue | null>(null);\n\nexport function WidgetProvider({\n options: config,\n children,\n components,\n storage,\n loadingComponent,\n}: {\n options: WidgetConfig;\n children: React.ReactNode;\n components?: WidgetComponentType[];\n storage?: ExternalStorage;\n /**\n * Custom loading component while the widget is initializing\n * Not to be confused with the `loading` custom component which renders when the bot's reply is pending\n */\n loadingComponent?: React.ReactNode;\n}) {\n const contentIframeRef = useRef<HTMLIFrameElement | null>(null);\n\n const didInitialize = useRef(false);\n const [widgetCtx, setWidgetCtx] = useState<WidgetCtx | null>(null);\n\n const componentStore = useMemo(\n () =>\n new ComponentRegistry({\n components: components,\n }),\n [components],\n );\n\n useEffect(() => {\n if (didInitialize.current) return;\n didInitialize.current = true;\n\n WidgetCtx.initialize({ config, storage }).then(setWidgetCtx);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n if (!widgetCtx) {\n return loadingComponent || null;\n }\n\n return (\n <context.Provider\n value={{\n widgetCtx,\n config,\n components,\n componentStore,\n version,\n contentIframeRef,\n }}\n >\n {children}\n </context.Provider>\n );\n}\n\nexport function useWidget() {\n const ctx = useContext(context);\n if (!ctx) {\n throw new Error('useWidget must be used within a WidgetProvider');\n }\n return ctx;\n}\n","import { useWidget } from '../WidgetProvider';\n\nexport function useConfig() {\n const { config } = useWidget();\n\n return config;\n}\n","import { useSyncExternalStore } from 'react';\nimport type { PrimitiveState } from '../../core';\n\nexport function usePrimitiveState<T>(p: PrimitiveState<T>) {\n return useSyncExternalStore(p.subscribe, p.get, p.get);\n}\n","import { useWidget } from '../WidgetProvider';\nimport { usePrimitiveState } from './usePrimitiveState';\n\nexport function useContact() {\n const { widgetCtx } = useWidget();\n const contactState = usePrimitiveState(widgetCtx.contactCtx.state);\n\n return {\n contactState,\n createUnverifiedContact: widgetCtx.contactCtx.createUnverifiedContact,\n };\n}\n","import { usePrimitiveState } from './usePrimitiveState';\nimport { useWidget } from '../WidgetProvider';\n\nexport function useMessages() {\n const { widgetCtx } = useWidget();\n const messagesState = usePrimitiveState(widgetCtx.messageCtx.state);\n\n return { messagesState, sendMessage: widgetCtx.messageCtx.sendMessage };\n}\n","import { useMemo } from 'react';\nimport { useWidget } from '../WidgetProvider';\nimport { usePrimitiveState } from './usePrimitiveState';\nimport { useConfig } from './useConfig';\n\nexport function useSessions() {\n const { widgetCtx } = useWidget();\n const { oneOpenSessionAllowed } = useConfig();\n const sessionState = usePrimitiveState(widgetCtx.sessionCtx.sessionState);\n const sessionsState = usePrimitiveState(widgetCtx.sessionCtx.sessionsState);\n\n const { openSessions, closedSessions } = useMemo(() => {\n return {\n openSessions: sessionsState.data.filter((s) => s.isOpened === true),\n closedSessions: sessionsState.data.filter((s) => s.isOpened === false),\n };\n }, [sessionsState.data]);\n\n const canCreateNewSession = useMemo(() => {\n if (oneOpenSessionAllowed) {\n return openSessions.length === 0;\n }\n return true;\n }, [oneOpenSessionAllowed, openSessions.length]);\n\n return {\n sessionState,\n sessionsState,\n loadMoreSessions: widgetCtx.sessionCtx.loadMoreSessions,\n resolveSession: widgetCtx.sessionCtx.resolveSession,\n createStateCheckpoint: widgetCtx.sessionCtx.createStateCheckpoint,\n openSessions,\n closedSessions,\n canCreateNewSession,\n };\n}\n","import { useMessages } from './useMessages';\nimport { useSessions } from './useSessions';\n\nexport function useIsAwaitingBotReply() {\n const { sessionState } = useSessions();\n const { messagesState } = useMessages();\n\n const isSessionAssignedToAI = sessionState.session?.assignee.kind === 'ai';\n // This check is useful in cases where the user might navigate in and out of a chat, and `isSendingMessage` is reset back to its default value\n const lastMessage =\n messagesState.messages.length > 0\n ? messagesState.messages[messagesState.messages.length - 1]\n : null;\n const isLastMessageAUserMessage = lastMessage?.type === 'FROM_USER';\n\n const isAwaitingBotReply =\n (isSessionAssignedToAI || sessionState.isCreatingSession) &&\n (messagesState.isSendingMessage || isLastMessageAUserMessage);\n\n return { isAwaitingBotReply };\n}\n","import useSWR from 'swr';\nimport { useWidget } from '../WidgetProvider';\n\nfunction usePreludeData() {\n const { widgetCtx } = useWidget();\n\n // TODO remove swr dependency\n return useSWR([widgetCtx.config.token], widgetCtx.api.widgetPrelude, {\n revalidateOnFocus: false,\n });\n}\n\nexport { usePreludeData };\n","import { useWidget } from '../WidgetProvider';\nimport { usePrimitiveState } from './usePrimitiveState';\n\nexport function useWidgetRouter() {\n const { widgetCtx } = useWidget();\n\n const routerState = usePrimitiveState(widgetCtx.routerCtx.state);\n\n return {\n routerState,\n toSessionsScreen: widgetCtx.routerCtx.toSessionsScreen,\n toChatScreen: widgetCtx.routerCtx.toChatScreen,\n };\n}\n","import { useEffect, useMemo, useState } from 'react';\nimport { useWidget } from '../WidgetProvider';\nimport { v4 } from 'uuid';\n\nconst uploadAbortControllers: Map<string, AbortController> = new Map();\n\ninterface FileWithProgress {\n status: 'pending' | 'uploading' | 'success' | 'error';\n id: string;\n file: File;\n fileUrl?: string;\n progress: number;\n error?: string;\n}\n\nfunction useUploadFiles() {\n const [files, setFiles] = useState<FileWithProgress[]>([]);\n const {\n widgetCtx: { api },\n } = useWidget();\n function appendFiles(files: File[]) {\n const newFiles = files.map((file) => ({\n file,\n id: v4(),\n status: 'pending' as const,\n progress: 0,\n }));\n\n setFiles((prev) => [...prev, ...newFiles]);\n newFiles.forEach(uploadFile);\n }\n\n function updateFileById(id: string, update: Partial<FileWithProgress>) {\n setFiles((prev) =>\n prev.map((f) => (f.id === id ? { ...f, ...update } : f)),\n );\n }\n\n function removeFileById(id: string) {\n setFiles((prev) => prev.filter((f) => f.id !== id));\n }\n\n const uploadFile = async (fileItem: FileWithProgress) => {\n const controller = new AbortController();\n uploadAbortControllers.set(fileItem.id, controller);\n\n try {\n setFiles((prev) =>\n prev.map((f) =>\n f.id === fileItem.id ? { ...f, status: 'uploading', progress: 0 } : f,\n ),\n );\n\n const response = await api.uploadFile({\n file: fileItem.file,\n abortSignal: controller.signal,\n onProgress: (percentage) => {\n updateFileById(fileItem.id, { progress: percentage });\n },\n });\n\n updateFileById(fileItem.id, {\n status: 'success',\n fileUrl: response.fileUrl,\n progress: 100,\n });\n } catch (error) {\n if (!controller.signal.aborted) {\n updateFileById(fileItem.id, {\n status: 'error',\n error: error instanceof Error ? error.message : 'Upload failed',\n progress: 0,\n });\n }\n } finally {\n uploadAbortControllers.delete(fileItem.id);\n }\n };\n\n const handleCancelUpload = (fileId: string) => {\n const controller = uploadAbortControllers.get(fileId);\n if (controller) {\n controller.abort();\n uploadAbortControllers.delete(fileId);\n }\n removeFileById(fileId);\n };\n\n const successFiles = useMemo(() => {\n return files.filter((f) => f.status === 'success' && f.fileUrl);\n }, [files]);\n\n function emptyTheFiles() {\n uploadAbortControllers.forEach((controller) => controller.abort());\n uploadAbortControllers.clear();\n setFiles([]);\n }\n\n useEffect(() => {\n return () => {\n uploadAbortControllers.forEach((controller) => controller.abort());\n uploadAbortControllers.clear();\n };\n }, []);\n\n return {\n allFiles: files,\n appendFiles,\n handleCancelUpload,\n successFiles,\n emptyTheFiles,\n getFileById: (id: string) => files.find((f) => f.id === id),\n getUploadProgress: (id: string) =>\n files.find((f) => f.id === id)?.progress ?? 0,\n getUploadStatus: (id: string) => files.find((f) => f.id === id)?.status,\n hasErrors: files.some((f) => f.status === 'error'),\n isUploading: files.some((f) => f.status === 'uploading'),\n };\n}\n\nexport { useUploadFiles, type FileWithProgress };\n","import React, {\n createContext,\n useContext,\n useEffect,\n useState,\n type Dispatch,\n type ReactNode,\n type SetStateAction,\n} from 'react';\nimport { useConfig } from './useConfig';\n\ntype WidgetTriggerCtx = {\n isOpen: boolean;\n setIsOpen: Dispatch<SetStateAction<boolean>>;\n};\n\nconst context = createContext<WidgetTriggerCtx | null>(null);\n\nexport function WidgetTriggerProvider({ children }: { children: ReactNode }) {\n const config = useConfig();\n const [isOpen, setIsOpen] = useState(config.isOpen ?? false);\n\n useEffect(() => {\n setIsOpen((prev) => config.isOpen ?? prev);\n }, [config.isOpen]);\n\n useEffect(() => {\n const openAfterNSeconds = config.openAfterNSeconds;\n if (typeof openAfterNSeconds !== 'number' || isNaN(openAfterNSeconds))\n return;\n\n const timeout = setTimeout(() => setIsOpen(true), openAfterNSeconds * 1000);\n\n return () => clearTimeout(timeout);\n }, [config.openAfterNSeconds]);\n\n return (\n <context.Provider value={{ isOpen, setIsOpen }}>\n {children}\n </context.Provider>\n );\n}\n\nexport function useWidgetTrigger() {\n const ctx = useContext(context);\n if (!ctx) {\n throw new Error(\n 'useWidgetTrigger must be used within a WidgetTriggerProvider',\n );\n }\n return ctx;\n}\n","import { useWidget } from '../WidgetProvider';\nimport { useConfig } from './useConfig';\nimport { useSessions } from './useSessions';\n\nexport function useModes() {\n const { widgetCtx } = useWidget();\n const { modesComponents } = useConfig();\n const { sessionState } = useSessions();\n\n const modes = widgetCtx.modes;\n const activeModeId = sessionState.session?.modeId;\n const activeMode = modes.find((mode) => mode.id === activeModeId);\n\n const Component = modesComponents?.find((modeComponent) =>\n [\n activeMode?.id || '',\n activeMode?.name?.toLowerCase() || '',\n activeMode?.slug?.toLowerCase() || '',\n ].includes(modeComponent.key.toLowerCase()),\n )?.component;\n\n return {\n modes,\n modesComponents,\n activeModeId,\n activeMode,\n Component,\n };\n}\n"],"names":["ComponentRegistry","opts","components","c","component","index","key","_a","context","createContext","WidgetProvider","config","children","storage","loadingComponent","contentIframeRef","useRef","didInitialize","widgetCtx","setWidgetCtx","useState","componentStore","useMemo","useEffect","WidgetCtx","jsx","version","useWidget","ctx","useContext","useConfig","usePrimitiveState","p","useSyncExternalStore","useContact","useMessages","useSessions","oneOpenSessionAllowed","sessionState","sessionsState","openSessions","closedSessions","s","canCreateNewSession","useIsAwaitingBotReply","messagesState","isSessionAssignedToAI","lastMessage","isLastMessageAUserMessage","usePreludeData","useSWR","useWidgetRouter","uploadAbortControllers","useUploadFiles","files","setFiles","api","appendFiles","newFiles","file","v4","prev","uploadFile","updateFileById","id","update","f","removeFileById","fileItem","controller","response","percentage","error","handleCancelUpload","fileId","successFiles","emptyTheFiles","WidgetTriggerProvider","isOpen","setIsOpen","openAfterNSeconds","timeout","useWidgetTrigger","useModes","modesComponents","modes","activeModeId","activeMode","mode","Component","_b","modeComponent"],"mappings":"0JAGO,MAAMA,CAAkB,CAG7B,YAAYC,EAA8C,CAF1D,KAAA,WAAoC,GAG5B,KAAA,CAAE,WAAAC,CAAe,EAAAD,EAMnB,GAJAC,GACFA,EAAW,QAASC,GAAM,KAAK,SAASA,CAAC,CAAC,EAGxC,KAAK,WAAW,SAAW,EACvB,MAAA,IAAI,MAAM,0BAA0B,EAE5C,GAAI,CAAC,KAAK,IAAI,UAAU,EAChB,MAAA,IAAI,MAAM,kCAAkC,CAEtD,CAGA,SAASC,EAAgC,CAEjC,MAAAC,EAAQ,KAAK,WAAW,UAAWF,GAAMA,EAAE,MAAQC,EAAU,GAAG,EACtE,OAAIC,IAAU,GACP,KAAA,WAAWA,CAAK,EAAID,EAEpB,KAAA,WAAW,KAAKA,CAAS,EAEzB,IACT,CAEQ,IAAIE,EAAyB,CAC7B,MAAAH,EAAI,KAAK,WAAW,KACvBA,GAAMA,EAAE,IAAI,YAAY,IAAMG,EAAI,YAAY,CAAA,EAEjD,OAAIH,GACG,IACT,CAEO,aAAaG,EAAa,OACxB,OAAAC,EAAA,KAAK,IAAID,CAAG,IAAZ,YAAAC,EAAe,SACxB,CACF,CCtBA,MAAMC,EAAUC,EAAAA,cAA0C,IAAI,EAEvD,SAASC,EAAe,CAC7B,QAASC,EACT,SAAAC,EACA,WAAAV,EACA,QAAAW,EACA,iBAAAC,CACF,EAUG,CACK,MAAAC,EAAmBC,SAAiC,IAAI,EAExDC,EAAgBD,SAAO,EAAK,EAC5B,CAACE,EAAWC,CAAY,EAAIC,WAA2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|
+
import { createContext as U, useRef as b, useState as w, useMemo as m, useEffect as h, useContext as F, useSyncExternalStore as P } from "react";
|
|
3
3
|
import { v4 as O } from "uuid";
|
|
4
|
-
import { jsx as
|
|
4
|
+
import { jsx as W } from "react/jsx-runtime";
|
|
5
5
|
import { W as R } from "./widget.ctx-uAWzif3-.js";
|
|
6
|
-
const N = "3.0.
|
|
6
|
+
const N = "3.0.91";
|
|
7
7
|
class T {
|
|
8
8
|
constructor(t) {
|
|
9
9
|
this.components = [];
|
|
@@ -29,46 +29,44 @@ class T {
|
|
|
29
29
|
return (n = this.get(t)) == null ? void 0 : n.component;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
const
|
|
32
|
+
const v = U(null);
|
|
33
33
|
function D({
|
|
34
34
|
options: e,
|
|
35
35
|
children: t,
|
|
36
36
|
components: n,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
loadingComponent: a
|
|
37
|
+
storage: o,
|
|
38
|
+
loadingComponent: i
|
|
40
39
|
}) {
|
|
41
|
-
const
|
|
40
|
+
const a = b(null), u = b(!1), [d, S] = w(null), p = m(
|
|
42
41
|
() => new T({
|
|
43
42
|
components: n
|
|
44
43
|
}),
|
|
45
44
|
[n]
|
|
46
45
|
);
|
|
47
46
|
return h(() => {
|
|
48
|
-
u.current || (u.current = !0, R.initialize({ config: e, storage:
|
|
49
|
-
}, []),
|
|
50
|
-
|
|
47
|
+
u.current || (u.current = !0, R.initialize({ config: e, storage: o }).then(S));
|
|
48
|
+
}, []), d ? /* @__PURE__ */ W(
|
|
49
|
+
v.Provider,
|
|
51
50
|
{
|
|
52
51
|
value: {
|
|
53
|
-
widgetCtx:
|
|
52
|
+
widgetCtx: d,
|
|
54
53
|
config: e,
|
|
55
54
|
components: n,
|
|
56
|
-
componentStore:
|
|
57
|
-
modesComponents: o,
|
|
55
|
+
componentStore: p,
|
|
58
56
|
version: N,
|
|
59
|
-
contentIframeRef:
|
|
57
|
+
contentIframeRef: a
|
|
60
58
|
},
|
|
61
59
|
children: t
|
|
62
60
|
}
|
|
63
|
-
) :
|
|
61
|
+
) : i || null;
|
|
64
62
|
}
|
|
65
63
|
function g() {
|
|
66
|
-
const e =
|
|
64
|
+
const e = F(v);
|
|
67
65
|
if (!e)
|
|
68
66
|
throw new Error("useWidget must be used within a WidgetProvider");
|
|
69
67
|
return e;
|
|
70
68
|
}
|
|
71
|
-
function
|
|
69
|
+
function y() {
|
|
72
70
|
const { config: e } = g();
|
|
73
71
|
return e;
|
|
74
72
|
}
|
|
@@ -87,10 +85,10 @@ function M() {
|
|
|
87
85
|
return { messagesState: C(e.messageCtx.state), sendMessage: e.messageCtx.sendMessage };
|
|
88
86
|
}
|
|
89
87
|
function E() {
|
|
90
|
-
const { widgetCtx: e } = g(), { oneOpenSessionAllowed: t } =
|
|
91
|
-
openSessions: o.data.filter((
|
|
92
|
-
closedSessions: o.data.filter((
|
|
93
|
-
}), [o.data]),
|
|
88
|
+
const { widgetCtx: e } = g(), { oneOpenSessionAllowed: t } = y(), n = C(e.sessionCtx.sessionState), o = C(e.sessionCtx.sessionsState), { openSessions: i, closedSessions: a } = m(() => ({
|
|
89
|
+
openSessions: o.data.filter((d) => d.isOpened === !0),
|
|
90
|
+
closedSessions: o.data.filter((d) => d.isOpened === !1)
|
|
91
|
+
}), [o.data]), u = m(() => t ? i.length === 0 : !0, [t, i.length]);
|
|
94
92
|
return {
|
|
95
93
|
sessionState: n,
|
|
96
94
|
sessionsState: o,
|
|
@@ -99,12 +97,12 @@ function E() {
|
|
|
99
97
|
createStateCheckpoint: e.sessionCtx.createStateCheckpoint,
|
|
100
98
|
openSessions: i,
|
|
101
99
|
closedSessions: a,
|
|
102
|
-
canCreateNewSession:
|
|
100
|
+
canCreateNewSession: u
|
|
103
101
|
};
|
|
104
102
|
}
|
|
105
103
|
function $() {
|
|
106
|
-
var
|
|
107
|
-
const { sessionState: e } = E(), { messagesState: t } = M(), n = ((
|
|
104
|
+
var u;
|
|
105
|
+
const { sessionState: e } = E(), { messagesState: t } = M(), n = ((u = e.session) == null ? void 0 : u.assignee.kind) === "ai", o = t.messages.length > 0 ? t.messages[t.messages.length - 1] : null, i = (o == null ? void 0 : o.type) === "FROM_USER";
|
|
108
106
|
return { isAwaitingBotReply: (n || e.isCreatingSession) && (t.isSendingMessage || i) };
|
|
109
107
|
}
|
|
110
108
|
function q() {
|
|
@@ -133,30 +131,30 @@ function H() {
|
|
|
133
131
|
status: "pending",
|
|
134
132
|
progress: 0
|
|
135
133
|
}));
|
|
136
|
-
t((c) => [...c, ...r]), r.forEach(
|
|
134
|
+
t((c) => [...c, ...r]), r.forEach(u);
|
|
137
135
|
}
|
|
138
136
|
function i(s, r) {
|
|
139
137
|
t(
|
|
140
|
-
(c) => c.map((
|
|
138
|
+
(c) => c.map((f) => f.id === s ? { ...f, ...r } : f)
|
|
141
139
|
);
|
|
142
140
|
}
|
|
143
141
|
function a(s) {
|
|
144
142
|
t((r) => r.filter((c) => c.id !== s));
|
|
145
143
|
}
|
|
146
|
-
const
|
|
144
|
+
const u = async (s) => {
|
|
147
145
|
const r = new AbortController();
|
|
148
146
|
l.set(s.id, r);
|
|
149
147
|
try {
|
|
150
148
|
t(
|
|
151
|
-
(
|
|
149
|
+
(f) => f.map(
|
|
152
150
|
(x) => x.id === s.id ? { ...x, status: "uploading", progress: 0 } : x
|
|
153
151
|
)
|
|
154
152
|
);
|
|
155
153
|
const c = await n.uploadFile({
|
|
156
154
|
file: s.file,
|
|
157
155
|
abortSignal: r.signal,
|
|
158
|
-
onProgress: (
|
|
159
|
-
i(s.id, { progress:
|
|
156
|
+
onProgress: (f) => {
|
|
157
|
+
i(s.id, { progress: f });
|
|
160
158
|
}
|
|
161
159
|
});
|
|
162
160
|
i(s.id, {
|
|
@@ -173,11 +171,11 @@ function H() {
|
|
|
173
171
|
} finally {
|
|
174
172
|
l.delete(s.id);
|
|
175
173
|
}
|
|
176
|
-
},
|
|
174
|
+
}, d = (s) => {
|
|
177
175
|
const r = l.get(s);
|
|
178
176
|
r && (r.abort(), l.delete(s)), a(s);
|
|
179
|
-
},
|
|
180
|
-
function
|
|
177
|
+
}, S = m(() => e.filter((s) => s.status === "success" && s.fileUrl), [e]);
|
|
178
|
+
function p() {
|
|
181
179
|
l.forEach((s) => s.abort()), l.clear(), t([]);
|
|
182
180
|
}
|
|
183
181
|
return h(() => () => {
|
|
@@ -185,9 +183,9 @@ function H() {
|
|
|
185
183
|
}, []), {
|
|
186
184
|
allFiles: e,
|
|
187
185
|
appendFiles: o,
|
|
188
|
-
handleCancelUpload:
|
|
189
|
-
successFiles:
|
|
190
|
-
emptyTheFiles:
|
|
186
|
+
handleCancelUpload: d,
|
|
187
|
+
successFiles: S,
|
|
188
|
+
emptyTheFiles: p,
|
|
191
189
|
getFileById: (s) => e.find((r) => r.id === s),
|
|
192
190
|
getUploadProgress: (s) => {
|
|
193
191
|
var r;
|
|
@@ -201,9 +199,9 @@ function H() {
|
|
|
201
199
|
isUploading: e.some((s) => s.status === "uploading")
|
|
202
200
|
};
|
|
203
201
|
}
|
|
204
|
-
const A =
|
|
202
|
+
const A = U(null);
|
|
205
203
|
function J({ children: e }) {
|
|
206
|
-
const t =
|
|
204
|
+
const t = y(), [n, o] = w(t.isOpen ?? !1);
|
|
207
205
|
return h(() => {
|
|
208
206
|
o((i) => t.isOpen ?? i);
|
|
209
207
|
}, [t.isOpen]), h(() => {
|
|
@@ -212,10 +210,10 @@ function J({ children: e }) {
|
|
|
212
210
|
return;
|
|
213
211
|
const a = setTimeout(() => o(!0), i * 1e3);
|
|
214
212
|
return () => clearTimeout(a);
|
|
215
|
-
}, [t.openAfterNSeconds]), /* @__PURE__ */
|
|
213
|
+
}, [t.openAfterNSeconds]), /* @__PURE__ */ W(A.Provider, { value: { isOpen: n, setIsOpen: o }, children: e });
|
|
216
214
|
}
|
|
217
215
|
function K() {
|
|
218
|
-
const e =
|
|
216
|
+
const e = F(A);
|
|
219
217
|
if (!e)
|
|
220
218
|
throw new Error(
|
|
221
219
|
"useWidgetTrigger must be used within a WidgetTriggerProvider"
|
|
@@ -223,28 +221,28 @@ function K() {
|
|
|
223
221
|
return e;
|
|
224
222
|
}
|
|
225
223
|
function Q() {
|
|
226
|
-
var
|
|
227
|
-
const { widgetCtx: e, modesComponents: t } =
|
|
228
|
-
(
|
|
224
|
+
var d, S;
|
|
225
|
+
const { widgetCtx: e } = g(), { modesComponents: t } = y(), { sessionState: n } = E(), o = e.modes, i = (d = n.session) == null ? void 0 : d.modeId, a = o.find((p) => p.id === i), u = (S = t == null ? void 0 : t.find(
|
|
226
|
+
(p) => {
|
|
229
227
|
var s, r;
|
|
230
228
|
return [
|
|
231
229
|
(a == null ? void 0 : a.id) || "",
|
|
232
230
|
((s = a == null ? void 0 : a.name) == null ? void 0 : s.toLowerCase()) || "",
|
|
233
231
|
((r = a == null ? void 0 : a.slug) == null ? void 0 : r.toLowerCase()) || ""
|
|
234
|
-
].includes(
|
|
232
|
+
].includes(p.key.toLowerCase());
|
|
235
233
|
}
|
|
236
|
-
)) == null ? void 0 :
|
|
234
|
+
)) == null ? void 0 : S.component;
|
|
237
235
|
return {
|
|
238
236
|
modes: o,
|
|
239
237
|
modesComponents: t,
|
|
240
238
|
activeModeId: i,
|
|
241
239
|
activeMode: a,
|
|
242
|
-
Component:
|
|
240
|
+
Component: u
|
|
243
241
|
};
|
|
244
242
|
}
|
|
245
243
|
export {
|
|
246
244
|
D as W,
|
|
247
|
-
|
|
245
|
+
y as a,
|
|
248
246
|
_ as b,
|
|
249
247
|
$ as c,
|
|
250
248
|
M as d,
|
|
@@ -258,4 +256,4 @@ export {
|
|
|
258
256
|
Q as l,
|
|
259
257
|
g as u
|
|
260
258
|
};
|
|
261
|
-
//# sourceMappingURL=useModes-
|
|
259
|
+
//# sourceMappingURL=useModes-COzOEDch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useModes-COzOEDch.js","sources":["../src/headless/react/ComponentRegistry.ts","../src/headless/react/WidgetProvider.tsx","../src/headless/react/hooks/useConfig.ts","../src/headless/react/hooks/usePrimitiveState.ts","../src/headless/react/hooks/useContact.ts","../src/headless/react/hooks/useMessages.ts","../src/headless/react/hooks/useSessions.ts","../src/headless/react/hooks/useIsAwaitingBotReply.ts","../src/headless/react/hooks/usePreludeData.ts","../src/headless/react/hooks/useWidgetRouter.ts","../src/headless/react/hooks/useUploadFiles.ts","../src/headless/react/hooks/useWidgetTrigger.tsx","../src/headless/react/hooks/useModes.ts"],"sourcesContent":["import type { WidgetComponentKey } from '../core';\nimport type { WidgetComponentType } from './types/components';\n\nexport class ComponentRegistry {\n components: WidgetComponentType[] = [];\n\n constructor(opts: { components?: WidgetComponentType[] }) {\n const { components } = opts;\n\n if (components) {\n components.forEach((c) => this.register(c));\n }\n\n if (this.components.length === 0) {\n throw new Error('No components registered');\n }\n if (!this.get('fallback')) {\n throw new Error('No fallback component registered');\n }\n }\n\n // TODO test that this registers or replaces the component\n register(component: WidgetComponentType) {\n // Replace the key if it already exists\n const index = this.components.findIndex((c) => c.key === component.key);\n if (index !== -1) {\n this.components[index] = component;\n } else {\n this.components.push(component);\n }\n return this;\n }\n\n private get(key: WidgetComponentKey) {\n const c = this.components.find(\n (c) => c.key.toUpperCase() === key.toUpperCase(),\n );\n if (c) return c;\n return null;\n }\n\n public getComponent(key: string) {\n return this.get(key)?.component;\n }\n}\n","import React, {\n createContext,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { version } from '../../../package.json';\nimport { type ExternalStorage, type WidgetConfig, WidgetCtx } from '../core';\nimport { ComponentRegistry } from './ComponentRegistry';\nimport type { WidgetComponentType } from './types/components';\n\ninterface WidgetProviderValue {\n widgetCtx: WidgetCtx;\n config: WidgetConfig;\n components?: WidgetComponentType[];\n componentStore: ComponentRegistry;\n version: string;\n contentIframeRef?: React.MutableRefObject<HTMLIFrameElement | null>;\n}\n\nconst context = createContext<WidgetProviderValue | null>(null);\n\nexport function WidgetProvider({\n options: config,\n children,\n components,\n storage,\n loadingComponent,\n}: {\n options: WidgetConfig;\n children: React.ReactNode;\n components?: WidgetComponentType[];\n storage?: ExternalStorage;\n /**\n * Custom loading component while the widget is initializing\n * Not to be confused with the `loading` custom component which renders when the bot's reply is pending\n */\n loadingComponent?: React.ReactNode;\n}) {\n const contentIframeRef = useRef<HTMLIFrameElement | null>(null);\n\n const didInitialize = useRef(false);\n const [widgetCtx, setWidgetCtx] = useState<WidgetCtx | null>(null);\n\n const componentStore = useMemo(\n () =>\n new ComponentRegistry({\n components: components,\n }),\n [components],\n );\n\n useEffect(() => {\n if (didInitialize.current) return;\n didInitialize.current = true;\n\n WidgetCtx.initialize({ config, storage }).then(setWidgetCtx);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n if (!widgetCtx) {\n return loadingComponent || null;\n }\n\n return (\n <context.Provider\n value={{\n widgetCtx,\n config,\n components,\n componentStore,\n version,\n contentIframeRef,\n }}\n >\n {children}\n </context.Provider>\n );\n}\n\nexport function useWidget() {\n const ctx = useContext(context);\n if (!ctx) {\n throw new Error('useWidget must be used within a WidgetProvider');\n }\n return ctx;\n}\n","import { useWidget } from '../WidgetProvider';\n\nexport function useConfig() {\n const { config } = useWidget();\n\n return config;\n}\n","import { useSyncExternalStore } from 'react';\nimport type { PrimitiveState } from '../../core';\n\nexport function usePrimitiveState<T>(p: PrimitiveState<T>) {\n return useSyncExternalStore(p.subscribe, p.get, p.get);\n}\n","import { useWidget } from '../WidgetProvider';\nimport { usePrimitiveState } from './usePrimitiveState';\n\nexport function useContact() {\n const { widgetCtx } = useWidget();\n const contactState = usePrimitiveState(widgetCtx.contactCtx.state);\n\n return {\n contactState,\n createUnverifiedContact: widgetCtx.contactCtx.createUnverifiedContact,\n };\n}\n","import { usePrimitiveState } from './usePrimitiveState';\nimport { useWidget } from '../WidgetProvider';\n\nexport function useMessages() {\n const { widgetCtx } = useWidget();\n const messagesState = usePrimitiveState(widgetCtx.messageCtx.state);\n\n return { messagesState, sendMessage: widgetCtx.messageCtx.sendMessage };\n}\n","import { useMemo } from 'react';\nimport { useWidget } from '../WidgetProvider';\nimport { usePrimitiveState } from './usePrimitiveState';\nimport { useConfig } from './useConfig';\n\nexport function useSessions() {\n const { widgetCtx } = useWidget();\n const { oneOpenSessionAllowed } = useConfig();\n const sessionState = usePrimitiveState(widgetCtx.sessionCtx.sessionState);\n const sessionsState = usePrimitiveState(widgetCtx.sessionCtx.sessionsState);\n\n const { openSessions, closedSessions } = useMemo(() => {\n return {\n openSessions: sessionsState.data.filter((s) => s.isOpened === true),\n closedSessions: sessionsState.data.filter((s) => s.isOpened === false),\n };\n }, [sessionsState.data]);\n\n const canCreateNewSession = useMemo(() => {\n if (oneOpenSessionAllowed) {\n return openSessions.length === 0;\n }\n return true;\n }, [oneOpenSessionAllowed, openSessions.length]);\n\n return {\n sessionState,\n sessionsState,\n loadMoreSessions: widgetCtx.sessionCtx.loadMoreSessions,\n resolveSession: widgetCtx.sessionCtx.resolveSession,\n createStateCheckpoint: widgetCtx.sessionCtx.createStateCheckpoint,\n openSessions,\n closedSessions,\n canCreateNewSession,\n };\n}\n","import { useMessages } from './useMessages';\nimport { useSessions } from './useSessions';\n\nexport function useIsAwaitingBotReply() {\n const { sessionState } = useSessions();\n const { messagesState } = useMessages();\n\n const isSessionAssignedToAI = sessionState.session?.assignee.kind === 'ai';\n // This check is useful in cases where the user might navigate in and out of a chat, and `isSendingMessage` is reset back to its default value\n const lastMessage =\n messagesState.messages.length > 0\n ? messagesState.messages[messagesState.messages.length - 1]\n : null;\n const isLastMessageAUserMessage = lastMessage?.type === 'FROM_USER';\n\n const isAwaitingBotReply =\n (isSessionAssignedToAI || sessionState.isCreatingSession) &&\n (messagesState.isSendingMessage || isLastMessageAUserMessage);\n\n return { isAwaitingBotReply };\n}\n","import useSWR from 'swr';\nimport { useWidget } from '../WidgetProvider';\n\nfunction usePreludeData() {\n const { widgetCtx } = useWidget();\n\n // TODO remove swr dependency\n return useSWR([widgetCtx.config.token], widgetCtx.api.widgetPrelude, {\n revalidateOnFocus: false,\n });\n}\n\nexport { usePreludeData };\n","import { useWidget } from '../WidgetProvider';\nimport { usePrimitiveState } from './usePrimitiveState';\n\nexport function useWidgetRouter() {\n const { widgetCtx } = useWidget();\n\n const routerState = usePrimitiveState(widgetCtx.routerCtx.state);\n\n return {\n routerState,\n toSessionsScreen: widgetCtx.routerCtx.toSessionsScreen,\n toChatScreen: widgetCtx.routerCtx.toChatScreen,\n };\n}\n","import { useEffect, useMemo, useState } from 'react';\nimport { useWidget } from '../WidgetProvider';\nimport { v4 } from 'uuid';\n\nconst uploadAbortControllers: Map<string, AbortController> = new Map();\n\ninterface FileWithProgress {\n status: 'pending' | 'uploading' | 'success' | 'error';\n id: string;\n file: File;\n fileUrl?: string;\n progress: number;\n error?: string;\n}\n\nfunction useUploadFiles() {\n const [files, setFiles] = useState<FileWithProgress[]>([]);\n const {\n widgetCtx: { api },\n } = useWidget();\n function appendFiles(files: File[]) {\n const newFiles = files.map((file) => ({\n file,\n id: v4(),\n status: 'pending' as const,\n progress: 0,\n }));\n\n setFiles((prev) => [...prev, ...newFiles]);\n newFiles.forEach(uploadFile);\n }\n\n function updateFileById(id: string, update: Partial<FileWithProgress>) {\n setFiles((prev) =>\n prev.map((f) => (f.id === id ? { ...f, ...update } : f)),\n );\n }\n\n function removeFileById(id: string) {\n setFiles((prev) => prev.filter((f) => f.id !== id));\n }\n\n const uploadFile = async (fileItem: FileWithProgress) => {\n const controller = new AbortController();\n uploadAbortControllers.set(fileItem.id, controller);\n\n try {\n setFiles((prev) =>\n prev.map((f) =>\n f.id === fileItem.id ? { ...f, status: 'uploading', progress: 0 } : f,\n ),\n );\n\n const response = await api.uploadFile({\n file: fileItem.file,\n abortSignal: controller.signal,\n onProgress: (percentage) => {\n updateFileById(fileItem.id, { progress: percentage });\n },\n });\n\n updateFileById(fileItem.id, {\n status: 'success',\n fileUrl: response.fileUrl,\n progress: 100,\n });\n } catch (error) {\n if (!controller.signal.aborted) {\n updateFileById(fileItem.id, {\n status: 'error',\n error: error instanceof Error ? error.message : 'Upload failed',\n progress: 0,\n });\n }\n } finally {\n uploadAbortControllers.delete(fileItem.id);\n }\n };\n\n const handleCancelUpload = (fileId: string) => {\n const controller = uploadAbortControllers.get(fileId);\n if (controller) {\n controller.abort();\n uploadAbortControllers.delete(fileId);\n }\n removeFileById(fileId);\n };\n\n const successFiles = useMemo(() => {\n return files.filter((f) => f.status === 'success' && f.fileUrl);\n }, [files]);\n\n function emptyTheFiles() {\n uploadAbortControllers.forEach((controller) => controller.abort());\n uploadAbortControllers.clear();\n setFiles([]);\n }\n\n useEffect(() => {\n return () => {\n uploadAbortControllers.forEach((controller) => controller.abort());\n uploadAbortControllers.clear();\n };\n }, []);\n\n return {\n allFiles: files,\n appendFiles,\n handleCancelUpload,\n successFiles,\n emptyTheFiles,\n getFileById: (id: string) => files.find((f) => f.id === id),\n getUploadProgress: (id: string) =>\n files.find((f) => f.id === id)?.progress ?? 0,\n getUploadStatus: (id: string) => files.find((f) => f.id === id)?.status,\n hasErrors: files.some((f) => f.status === 'error'),\n isUploading: files.some((f) => f.status === 'uploading'),\n };\n}\n\nexport { useUploadFiles, type FileWithProgress };\n","import React, {\n createContext,\n useContext,\n useEffect,\n useState,\n type Dispatch,\n type ReactNode,\n type SetStateAction,\n} from 'react';\nimport { useConfig } from './useConfig';\n\ntype WidgetTriggerCtx = {\n isOpen: boolean;\n setIsOpen: Dispatch<SetStateAction<boolean>>;\n};\n\nconst context = createContext<WidgetTriggerCtx | null>(null);\n\nexport function WidgetTriggerProvider({ children }: { children: ReactNode }) {\n const config = useConfig();\n const [isOpen, setIsOpen] = useState(config.isOpen ?? false);\n\n useEffect(() => {\n setIsOpen((prev) => config.isOpen ?? prev);\n }, [config.isOpen]);\n\n useEffect(() => {\n const openAfterNSeconds = config.openAfterNSeconds;\n if (typeof openAfterNSeconds !== 'number' || isNaN(openAfterNSeconds))\n return;\n\n const timeout = setTimeout(() => setIsOpen(true), openAfterNSeconds * 1000);\n\n return () => clearTimeout(timeout);\n }, [config.openAfterNSeconds]);\n\n return (\n <context.Provider value={{ isOpen, setIsOpen }}>\n {children}\n </context.Provider>\n );\n}\n\nexport function useWidgetTrigger() {\n const ctx = useContext(context);\n if (!ctx) {\n throw new Error(\n 'useWidgetTrigger must be used within a WidgetTriggerProvider',\n );\n }\n return ctx;\n}\n","import { useWidget } from '../WidgetProvider';\nimport { useConfig } from './useConfig';\nimport { useSessions } from './useSessions';\n\nexport function useModes() {\n const { widgetCtx } = useWidget();\n const { modesComponents } = useConfig();\n const { sessionState } = useSessions();\n\n const modes = widgetCtx.modes;\n const activeModeId = sessionState.session?.modeId;\n const activeMode = modes.find((mode) => mode.id === activeModeId);\n\n const Component = modesComponents?.find((modeComponent) =>\n [\n activeMode?.id || '',\n activeMode?.name?.toLowerCase() || '',\n activeMode?.slug?.toLowerCase() || '',\n ].includes(modeComponent.key.toLowerCase()),\n )?.component;\n\n return {\n modes,\n modesComponents,\n activeModeId,\n activeMode,\n Component,\n };\n}\n"],"names":["ComponentRegistry","opts","components","c","component","index","key","_a","context","createContext","WidgetProvider","config","children","storage","loadingComponent","contentIframeRef","useRef","didInitialize","widgetCtx","setWidgetCtx","useState","componentStore","useMemo","useEffect","WidgetCtx","jsx","version","useWidget","ctx","useContext","useConfig","usePrimitiveState","p","useSyncExternalStore","useContact","useMessages","useSessions","oneOpenSessionAllowed","sessionState","sessionsState","openSessions","closedSessions","s","canCreateNewSession","useIsAwaitingBotReply","messagesState","isSessionAssignedToAI","lastMessage","isLastMessageAUserMessage","usePreludeData","useSWR","useWidgetRouter","uploadAbortControllers","useUploadFiles","files","setFiles","api","appendFiles","newFiles","file","v4","prev","uploadFile","updateFileById","id","update","removeFileById","f","fileItem","controller","response","percentage","error","handleCancelUpload","fileId","successFiles","emptyTheFiles","WidgetTriggerProvider","isOpen","setIsOpen","openAfterNSeconds","timeout","useWidgetTrigger","useModes","modesComponents","modes","activeModeId","activeMode","mode","Component","_b","modeCom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