@opencx/widget 2.6.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/basic.cjs +89 -89
- package/dist/basic.cjs.map +1 -1
- package/dist/basic.d.ts +1 -1
- package/dist/basic.js +34083 -34125
- package/dist/basic.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -22
- package/dist/react.cjs +1 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +20 -10
- package/dist/react.js.map +1 -1
- package/dist/src/designs/react/basic/index.d.ts +10 -0
- package/dist/src/designs/{basic → react/basic}/utils/group-messages-by-type.d.ts +1 -1
- package/dist/src/{@components → designs/react/components}/BotOrAgentMessage.d.ts +1 -1
- package/dist/src/{@components → designs/react/components}/BotOrAgentMessageGroup.d.ts +2 -2
- package/dist/src/designs/react/components/BotOrAgentMessageWrapper.d.ts +7 -0
- package/dist/src/{@components → designs/react/components}/Fallback.component.d.ts +2 -2
- package/dist/src/{components → designs/react/components}/RenderFile.d.ts +2 -2
- package/dist/src/{@components → designs/react/components}/Text.component.d.ts +1 -1
- package/dist/src/{components → designs/react/components}/UserMessageGroup.d.ts +1 -1
- package/dist/src/{components → designs/react/components}/VoteButtons.d.ts +1 -1
- package/dist/src/designs/{constants.d.ts → react/constants.d.ts} +2 -4
- package/dist/src/designs/react/hooks/useLocale.d.ts +6 -0
- package/dist/src/{index.d.ts → designs/react/index.d.ts} +2 -2
- package/dist/src/designs/translation/ar.locale.d.ts +2 -0
- package/dist/src/designs/translation/de.locale.d.ts +2 -0
- package/dist/src/designs/translation/en.locale.d.ts +2 -0
- package/dist/src/designs/translation/fr.locale.d.ts +2 -0
- package/dist/src/designs/translation/index.d.ts +14 -0
- package/dist/src/designs/translation/nl.locale.d.ts +2 -0
- package/dist/src/designs/translation/pt.locale.d.ts +2 -0
- package/dist/src/designs/translation/translation.types.d.ts +4 -0
- package/dist/{core/client → src/headless/core}/api.d.ts +49 -103
- package/dist/src/headless/core/context/contact.d.ts +25 -0
- package/dist/src/headless/core/context/message.d.ts +40 -0
- package/dist/src/headless/core/context/session.d.ts +74 -0
- package/dist/src/headless/core/context/widget.d.ts +16 -0
- package/dist/src/headless/core/index.d.ts +7 -0
- package/dist/src/headless/core/types/WidgetConfig.d.ts +34 -0
- package/dist/src/headless/core/types/agent-or-bot.d.ts +6 -0
- package/dist/src/headless/core/types/helpers.d.ts +4 -0
- package/dist/{core → src/headless/core}/types/messages.d.ts +11 -31
- package/dist/src/headless/core/types/schemas.d.ts +9 -0
- package/dist/src/headless/core/utils/Poller.d.ts +12 -0
- package/dist/{core/types/pub-sub.d.ts → src/headless/core/utils/PubSub.d.ts} +6 -9
- package/dist/{react-web/core-integration/components.d.ts → src/headless/react/ComponentRegistry.d.ts} +1 -1
- package/dist/src/headless/react/WidgetProvider.d.ts +17 -0
- package/dist/src/headless/react/hooks/useConfig.d.ts +1 -0
- package/dist/src/headless/react/hooks/useContact.d.ts +10 -0
- package/dist/src/headless/react/hooks/useIsAwaitingBotReply.d.ts +3 -0
- package/dist/src/headless/react/hooks/useMessages.d.ts +8 -0
- package/dist/{react-web/core-integration → src/headless/react}/hooks/usePreludeData.d.ts +2 -2
- package/dist/{react-web/core-integration → src/headless/react}/hooks/usePubsub.d.ts +1 -1
- package/dist/src/headless/react/hooks/useSession.d.ts +6 -0
- package/dist/{react-web/core-integration → src/headless/react}/hooks/useVote.d.ts +2 -2
- package/dist/src/headless/react/index.d.ts +11 -0
- package/dist/src/headless/react/types/components.d.ts +15 -0
- package/dist/style.css +1 -1
- package/dist/useUploadFiles-BZa0DENN.cjs +18 -0
- package/dist/useUploadFiles-BZa0DENN.cjs.map +1 -0
- package/dist/useUploadFiles-BaCcqTwX.js +1336 -0
- package/dist/useUploadFiles-BaCcqTwX.js.map +1 -0
- package/dist/widget-BlvH6dre.cjs +2 -0
- package/dist/widget-BlvH6dre.cjs.map +1 -0
- package/dist/widget-DbgWez1r.js +514 -0
- package/dist/widget-DbgWez1r.js.map +1 -0
- package/dist-embed/script.js +120 -140
- package/dist-embed/script.js.map +1 -1
- package/package.json +9 -4
- package/dist/api-CAm3rFZk.js +0 -1070
- package/dist/api-CAm3rFZk.js.map +0 -1
- package/dist/api-oIDR-KZx.cjs +0 -2
- package/dist/api-oIDR-KZx.cjs.map +0 -1
- package/dist/core/client/chat.d.ts +0 -101
- package/dist/core/client/config.d.ts +0 -43
- package/dist/core/client/contact.d.ts +0 -29
- package/dist/core/client/index.d.ts +0 -4
- package/dist/core/errors/index.d.ts +0 -27
- package/dist/core/index.d.ts +0 -9
- package/dist/core/platform/audio.d.ts +0 -38
- package/dist/core/platform/index.d.ts +0 -15
- package/dist/core/platform/logger.d.ts +0 -14
- package/dist/core/platform/storage.d.ts +0 -52
- package/dist/core/tests/platform/logger.test.d.ts +0 -1
- package/dist/core/tests/platform/storage.test.d.ts +0 -1
- package/dist/core/tests/test-utils.d.ts +0 -2
- package/dist/core/tests/types/pub-sub.test.d.ts +0 -1
- package/dist/core/types/contact.d.ts +0 -2
- package/dist/core/types/helpers.d.ts +0 -20
- package/dist/core/types/index.d.ts +0 -52
- package/dist/core/types/prelude.d.ts +0 -14
- package/dist/core/types/schemas-v2.d.ts +0 -10
- package/dist/index-CSptf_Dw.cjs +0 -18
- package/dist/index-CSptf_Dw.cjs.map +0 -1
- package/dist/index-cUkS-tdv.js +0 -1232
- package/dist/index-cUkS-tdv.js.map +0 -1
- package/dist/react-web/core-integration/ChatProvider.d.ts +0 -107
- package/dist/react-web/core-integration/hooks/useChatMessages.d.ts +0 -70
- package/dist/react-web/core-integration/hooks/useChatSession.d.ts +0 -83
- package/dist/react-web/core-integration/hooks/useConfig.d.ts +0 -1
- package/dist/react-web/core-integration/hooks/useContact.d.ts +0 -17
- package/dist/react-web/core-integration/hooks/useLocale.d.ts +0 -4
- package/dist/react-web/core-integration/hooks.d.ts +0 -9
- package/dist/react-web/core-integration/index.d.ts +0 -2
- package/dist/react-web/core-integration/locales/ar.locale.d.ts +0 -2
- package/dist/react-web/core-integration/locales/de.locale.d.ts +0 -2
- package/dist/react-web/core-integration/locales/en.locale.d.ts +0 -55
- package/dist/react-web/core-integration/locales/fr.locale.d.ts +0 -2
- package/dist/react-web/core-integration/locales/helper.d.ts +0 -65
- package/dist/react-web/core-integration/locales/index.d.ts +0 -3
- package/dist/react-web/core-integration/locales/nl.locale.d.ts +0 -2
- package/dist/react-web/core-integration/locales/pt.locale.d.ts +0 -2
- package/dist/react-web/hooks/useScrollTo.d.ts +0 -2
- package/dist/react-web/index.d.ts +0 -4
- package/dist/react-web/types/components.d.ts +0 -13
- package/dist/react-web/types/index.d.ts +0 -8
- package/dist/react-web/types/options.d.ts +0 -17
- package/dist/src/@components/BotOrAgentMessageWrapper.d.ts +0 -9
- package/dist/src/@components/ChatEvent.component.d.ts +0 -9
- package/dist/src/@components/index.d.ts +0 -6
- package/dist/src/designs/basic/index.d.ts +0 -8
- /package/dist/src/designs/{basic → react/basic}/WidgetPopoverTrigger.d.ts +0 -0
- /package/dist/src/designs/{basic → react/basic}/screens/chat-screen/ChatFooter.d.ts +0 -0
- /package/dist/src/designs/{basic → react/basic}/screens/chat-screen/ChatHeader.d.ts +0 -0
- /package/dist/src/designs/{basic → react/basic}/screens/chat-screen/ChatMain.d.ts +0 -0
- /package/dist/src/designs/{basic → react/basic}/screens/chat-screen/ChatScreen.d.ts +0 -0
- /package/dist/src/designs/{basic → react/basic}/screens/root-screen.d.ts +0 -0
- /package/dist/src/designs/{basic → react/basic}/screens/welcome-screen/WelcomeScreen.d.ts +0 -0
- /package/dist/{core/tests/client/integration-perisitance.test.d.ts → src/designs/react/basic/widget-interaction-tests/widget.test.d.ts} +0 -0
- /package/dist/src/{@components → designs/react/components}/Loading.component.d.ts +0 -0
- /package/dist/src/{@components → designs/react/components}/OpenLogoSvg.d.ts +0 -0
- /package/dist/src/{components → designs/react/components}/keyboard.d.ts +0 -0
- /package/dist/src/{components → designs/react/components/lib}/MotionDiv.d.ts +0 -0
- /package/dist/src/{components → designs/react/components/lib}/avatar.d.ts +0 -0
- /package/dist/src/{components → designs/react/components/lib}/button.d.ts +0 -0
- /package/dist/src/{components → designs/react/components/lib}/dialog.d.ts +0 -0
- /package/dist/src/{components → designs/react/components/lib}/dropdown-menu.d.ts +0 -0
- /package/dist/src/{components → designs/react/components/lib}/input.d.ts +0 -0
- /package/dist/src/{components → designs/react/components/lib}/popover.d.ts +0 -0
- /package/dist/src/{components → designs/react/components/lib}/skeleton.d.ts +0 -0
- /package/dist/src/{components → designs/react/components/lib}/switch.d.ts +0 -0
- /package/dist/src/{components → designs/react/components/lib}/tooltip.d.ts +0 -0
- /package/dist/src/{utils.d.ts → designs/react/components/lib/utils/cn.d.ts} +0 -0
- /package/dist/src/{components → designs/react/components/lib}/wobble.d.ts +0 -0
- /package/dist/src/{@components → designs/react/components}/markdown.d.ts +0 -0
- /package/dist/{react-web → src/designs/react}/hooks/useWidgetContentHeight.d.ts +0 -0
- /package/dist/src/{render.d.ts → designs/react/render.d.ts} +0 -0
- /package/dist/{core → src/headless/core}/sdk/index.d.ts +0 -0
- /package/dist/{core/tests/client/integration.test.d.ts → src/headless/core/utils/PubSub.test.d.ts} +0 -0
- /package/dist/{core/utils/genUuid.d.ts → src/headless/core/utils/uuid.d.ts} +0 -0
- /package/dist/{react-web/core-integration → src/headless/react}/hooks/useUploadFiles.d.ts +0 -0
- /package/dist/{react-web → src/headless/react}/utils/create-safe-context.d.ts +0 -0
- /package/dist/{core/tests/platform/audio.test.d.ts → vitest/setup.d.ts} +0 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { MessageAttachmentType, SendMessageOutputDto, MessageDto, SomeOptional, SafeOmit, SendMessageDto, WidgetConfig } from 'src/headless/core';
|
|
2
|
+
import { BotMessageType, MessageType, UserMessageType } from 'src/headless/core/types/messages';
|
|
3
|
+
import { ApiCaller } from '../api';
|
|
4
|
+
import { SessionCtx } from './session';
|
|
5
|
+
import { PubSub } from 'src/headless/core/utils/PubSub';
|
|
6
|
+
export declare class MessageCtx {
|
|
7
|
+
private config;
|
|
8
|
+
private api;
|
|
9
|
+
private sessionCtx;
|
|
10
|
+
private poller;
|
|
11
|
+
state: PubSub<{
|
|
12
|
+
messages: MessageType[];
|
|
13
|
+
isSendingMessage: boolean;
|
|
14
|
+
suggestedReplies: string[] | null;
|
|
15
|
+
}>;
|
|
16
|
+
private sendMessageAbortController;
|
|
17
|
+
constructor({ config, api, sessionCtx, }: {
|
|
18
|
+
config: WidgetConfig;
|
|
19
|
+
api: ApiCaller;
|
|
20
|
+
sessionCtx: SessionCtx;
|
|
21
|
+
});
|
|
22
|
+
reset: () => void;
|
|
23
|
+
registerPolling: () => void;
|
|
24
|
+
sendMessage: (input: SomeOptional<SafeOmit<SendMessageDto, "bot_token" | "uuid">, "session_id" | "user">) => Promise<void>;
|
|
25
|
+
fetchAndSetHistory: (sessionId: string, abortSignal: AbortSignal) => Promise<void>;
|
|
26
|
+
/** Not the best name but whatever */
|
|
27
|
+
static mapHistoryToMessage(history: MessageDto): MessageType;
|
|
28
|
+
static toUserMessage(content: string, attachments?: MessageAttachmentType[]): UserMessageType;
|
|
29
|
+
static toBotMessage(response: SendMessageOutputDto): BotMessageType | null;
|
|
30
|
+
static toErrorMessage(message: string): {
|
|
31
|
+
type: "FROM_BOT";
|
|
32
|
+
id: string;
|
|
33
|
+
timestamp: string;
|
|
34
|
+
component: string;
|
|
35
|
+
data: {
|
|
36
|
+
message: string;
|
|
37
|
+
variant: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ApiCaller } from 'src/headless/core/api';
|
|
2
|
+
import { SessionDto } from 'src/headless/core';
|
|
3
|
+
import { PubSub } from 'src/headless/core/utils/PubSub';
|
|
4
|
+
export declare class SessionCtx {
|
|
5
|
+
private api;
|
|
6
|
+
private poller;
|
|
7
|
+
state: PubSub<{
|
|
8
|
+
session: SessionDto | null;
|
|
9
|
+
isCreatingSession: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
constructor(api: ApiCaller);
|
|
12
|
+
/** Clears the session and stops polling */
|
|
13
|
+
reset: () => Promise<void>;
|
|
14
|
+
registerPolling: () => void;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new session
|
|
17
|
+
* @returns The session
|
|
18
|
+
*/
|
|
19
|
+
createSession: () => Promise<{
|
|
20
|
+
id: string;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
updatedAt: string;
|
|
23
|
+
isHandedOff: boolean;
|
|
24
|
+
isOpened: boolean;
|
|
25
|
+
assignee: {
|
|
26
|
+
kind: "human" | "ai" | "none" | "unknown";
|
|
27
|
+
name: string | null;
|
|
28
|
+
avatarUrl: string | null;
|
|
29
|
+
};
|
|
30
|
+
channel: string;
|
|
31
|
+
isVerified: boolean;
|
|
32
|
+
} | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Fetches the session from the API
|
|
35
|
+
* @param id - The ID of the session to fetch
|
|
36
|
+
* @returns The session
|
|
37
|
+
*/
|
|
38
|
+
fetch: (sessionId: string, abortSignal: AbortSignal) => Promise<import('openapi-fetch').FetchResponse<{
|
|
39
|
+
parameters: {
|
|
40
|
+
query?: never;
|
|
41
|
+
header?: never;
|
|
42
|
+
path: {
|
|
43
|
+
sessionId: string;
|
|
44
|
+
};
|
|
45
|
+
cookie?: never;
|
|
46
|
+
};
|
|
47
|
+
requestBody?: never;
|
|
48
|
+
responses: {
|
|
49
|
+
200: {
|
|
50
|
+
headers: {
|
|
51
|
+
[name: string]: unknown;
|
|
52
|
+
};
|
|
53
|
+
content: {
|
|
54
|
+
"application/json": import('../sdk/schema').components["schemas"]["WidgetSessionDto"];
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
500: {
|
|
58
|
+
headers: {
|
|
59
|
+
[name: string]: unknown;
|
|
60
|
+
};
|
|
61
|
+
content: {
|
|
62
|
+
"application/json": import('../sdk/schema').components["schemas"]["ErrorDto"];
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}, {
|
|
67
|
+
params: {
|
|
68
|
+
path: {
|
|
69
|
+
sessionId: string;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
signal: AbortSignal;
|
|
73
|
+
}, `${string}/${string}`>>;
|
|
74
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WidgetConfig } from 'src/headless/core/types/WidgetConfig';
|
|
2
|
+
import { ApiCaller } from '../api';
|
|
3
|
+
import { ContactCtx } from './contact';
|
|
4
|
+
import { MessageCtx } from './message';
|
|
5
|
+
import { SessionCtx } from './session';
|
|
6
|
+
export declare class WidgetCtx {
|
|
7
|
+
config: WidgetConfig;
|
|
8
|
+
api: ApiCaller;
|
|
9
|
+
contactCtx: ContactCtx;
|
|
10
|
+
sessionCtx: SessionCtx;
|
|
11
|
+
messageCtx: MessageCtx;
|
|
12
|
+
constructor({ config }: {
|
|
13
|
+
config: WidgetConfig;
|
|
14
|
+
});
|
|
15
|
+
resetChat: () => void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './types/agent-or-bot';
|
|
2
|
+
export * from './types/helpers';
|
|
3
|
+
export * from './types/messages';
|
|
4
|
+
export * from './types/schemas';
|
|
5
|
+
export * from './types/WidgetConfig';
|
|
6
|
+
export { WidgetCtx } from './context/widget';
|
|
7
|
+
export { PubSub } from './utils/PubSub';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AgentOrBotType } from './agent-or-bot';
|
|
2
|
+
export interface WidgetConfig {
|
|
3
|
+
token: string;
|
|
4
|
+
apiUrl?: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
queryParams?: Record<string, string>;
|
|
7
|
+
collectUserData?: boolean;
|
|
8
|
+
debug?: boolean;
|
|
9
|
+
initialMessages?: string[];
|
|
10
|
+
language?: string;
|
|
11
|
+
user?: {
|
|
12
|
+
external_id?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
email?: string;
|
|
15
|
+
phone?: string;
|
|
16
|
+
customData?: Record<string, string>;
|
|
17
|
+
avatarUrl?: string;
|
|
18
|
+
};
|
|
19
|
+
contactToken?: string;
|
|
20
|
+
bot?: AgentOrBotType;
|
|
21
|
+
soundEffectsUrls?: {
|
|
22
|
+
messageArrived?: string;
|
|
23
|
+
};
|
|
24
|
+
theme?: {
|
|
25
|
+
primaryColor?: string;
|
|
26
|
+
};
|
|
27
|
+
settings?: {
|
|
28
|
+
persistSession?: boolean;
|
|
29
|
+
playSoundEffects?: boolean;
|
|
30
|
+
};
|
|
31
|
+
assets?: {
|
|
32
|
+
organizationLogo?: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ChatAttachmentType, WidgetHistoryDto } from './schemas-v2';
|
|
1
|
+
import { MessageAttachmentType, MessageDto } from './schemas';
|
|
3
2
|
import { SafeExtract, StringOrLiteral } from './helpers';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
id: string | null;
|
|
7
|
-
name: string;
|
|
8
|
-
avatar: string | null;
|
|
9
|
-
};
|
|
3
|
+
import { AgentOrBotType } from './agent-or-bot';
|
|
4
|
+
import { DefaultTextComponentBaseProps, WidgetLiteralComponentKey } from 'src/headless/react/types/components';
|
|
10
5
|
export type UserMessageType = {
|
|
11
6
|
id: string;
|
|
12
7
|
type: "FROM_USER";
|
|
13
8
|
content: string;
|
|
14
9
|
deliveredAt: string | null;
|
|
15
|
-
attachments?:
|
|
10
|
+
attachments?: MessageAttachmentType[] | null;
|
|
16
11
|
timestamp: string;
|
|
17
12
|
user?: {
|
|
18
13
|
name?: string;
|
|
@@ -31,9 +26,9 @@ export type BotMessageType<TData = DefaultTextComponentBaseProps | unknown> = {
|
|
|
31
26
|
component: StringOrLiteral<SafeExtract<WidgetLiteralComponentKey, "bot_message">>;
|
|
32
27
|
data: TData;
|
|
33
28
|
timestamp: string;
|
|
34
|
-
original?:
|
|
35
|
-
agent?:
|
|
36
|
-
attachments?:
|
|
29
|
+
original?: MessageDto;
|
|
30
|
+
agent?: AgentOrBotType;
|
|
31
|
+
attachments?: MessageAttachmentType[];
|
|
37
32
|
};
|
|
38
33
|
export type AgentMessageType = {
|
|
39
34
|
id: string;
|
|
@@ -41,24 +36,9 @@ export type AgentMessageType = {
|
|
|
41
36
|
component: SafeExtract<WidgetLiteralComponentKey, "agent_message">;
|
|
42
37
|
data: DefaultTextComponentBaseProps;
|
|
43
38
|
timestamp?: string;
|
|
44
|
-
original?:
|
|
45
|
-
agent?:
|
|
46
|
-
attachments?:
|
|
39
|
+
original?: MessageDto;
|
|
40
|
+
agent?: AgentOrBotType;
|
|
41
|
+
attachments?: MessageAttachmentType[];
|
|
47
42
|
};
|
|
43
|
+
/** Find a better name for this thing */
|
|
48
44
|
export type MessageType = UserMessageType | BotMessageType | AgentMessageType;
|
|
49
|
-
export interface SendMessageInput {
|
|
50
|
-
content: {
|
|
51
|
-
text: string;
|
|
52
|
-
};
|
|
53
|
-
attachments?: ChatAttachmentType[];
|
|
54
|
-
id?: string;
|
|
55
|
-
language?: string;
|
|
56
|
-
user?: {
|
|
57
|
-
external_id?: string;
|
|
58
|
-
name?: string;
|
|
59
|
-
email?: string;
|
|
60
|
-
phone?: string;
|
|
61
|
-
customData?: Record<string, string>;
|
|
62
|
-
avatarUrl?: string;
|
|
63
|
-
};
|
|
64
|
-
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Dto } from 'src/headless/core/sdk';
|
|
2
|
+
export type VoteInputDto = Dto["WidgetVoteDto"];
|
|
3
|
+
export type VoteOutputDto = Dto["WidgetVoteResponseDto"];
|
|
4
|
+
export type SendMessageDto = Dto["HttpChatInputDto"];
|
|
5
|
+
export type SendMessageOutputDto = Dto["HandleContactMessageOutputDto"];
|
|
6
|
+
export type SessionDto = Dto["WidgetSessionDto"];
|
|
7
|
+
export type MessageDto = Dto["WidgetHistoryDto"];
|
|
8
|
+
export type PreludeDto = Dto["WidgetPreludeDto"];
|
|
9
|
+
export type MessageAttachmentType = NonNullable<Dto["WidgetHistoryDto"]["attachments"]>[number];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PubSub } from 'src/headless/core/utils/PubSub';
|
|
2
|
+
export type PollingState = {
|
|
3
|
+
isPolling: boolean;
|
|
4
|
+
isError: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare class Poller {
|
|
7
|
+
state: PubSub<PollingState>;
|
|
8
|
+
private abortController;
|
|
9
|
+
reset: () => void;
|
|
10
|
+
stopPolling: (() => void) | null;
|
|
11
|
+
startPolling: (cb: (abortSignal: AbortSignal) => Promise<void>, interval: number) => void;
|
|
12
|
+
}
|
|
@@ -25,18 +25,16 @@ export declare class PubSub<S> {
|
|
|
25
25
|
* @param callback Function to call when state changes
|
|
26
26
|
* @returns Unsubscribe function
|
|
27
27
|
*/
|
|
28
|
-
subscribe: (callback: Subscriber<S>) => () => void;
|
|
29
|
-
onLifecycle: (event: LifecycleEvent, listener: LifecycleListener) => () => void;
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
*/
|
|
33
|
-
getState: () => S;
|
|
28
|
+
subscribe: (callback: Subscriber<S>) => (() => void);
|
|
29
|
+
onLifecycle: (event: LifecycleEvent, listener: LifecycleListener) => (() => void);
|
|
30
|
+
/** Get the current state */
|
|
31
|
+
get: () => S;
|
|
34
32
|
/**
|
|
35
33
|
* Set the state and notify subscribers if the state changes
|
|
36
34
|
* @param newState The new state to set
|
|
37
35
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
set: (newState: S) => void;
|
|
37
|
+
setPartial: (_s: Partial<S>) => void;
|
|
40
38
|
/**
|
|
41
39
|
* Clear all subscriptions
|
|
42
40
|
*/
|
|
@@ -44,5 +42,4 @@ export declare class PubSub<S> {
|
|
|
44
42
|
reset: () => void;
|
|
45
43
|
lastUpdated: () => number | null;
|
|
46
44
|
}
|
|
47
|
-
export declare function createPubSub<S>(state: S): PubSub<S>;
|
|
48
45
|
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { WidgetConfig, WidgetCtx } from 'src/headless/core';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
import { ComponentRegistry } from './ComponentRegistry';
|
|
4
|
+
import { WidgetComponentType } from './types/components';
|
|
5
|
+
interface WidgetProviderValue {
|
|
6
|
+
widgetCtx: WidgetCtx;
|
|
7
|
+
components?: WidgetComponentType[];
|
|
8
|
+
componentStore: ComponentRegistry;
|
|
9
|
+
version: string;
|
|
10
|
+
}
|
|
11
|
+
declare const useWidget: () => WidgetProviderValue;
|
|
12
|
+
declare function WidgetProvider({ options, children, components, }: {
|
|
13
|
+
options: WidgetConfig;
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
components?: WidgetComponentType[];
|
|
16
|
+
}): React.JSX.Element;
|
|
17
|
+
export { useWidget, WidgetProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useConfig(): import('..').WidgetConfig;
|
|
@@ -14,7 +14,7 @@ declare function usePreludeData(): import('swr').SWRResponse<import('openapi-fet
|
|
|
14
14
|
[name: string]: unknown;
|
|
15
15
|
};
|
|
16
16
|
content: {
|
|
17
|
-
"application/json": import('
|
|
17
|
+
"application/json": import('../../core/sdk/schema').components["schemas"]["WidgetPreludeDto"];
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
500: {
|
|
@@ -22,7 +22,7 @@ declare function usePreludeData(): import('swr').SWRResponse<import('openapi-fet
|
|
|
22
22
|
[name: string]: unknown;
|
|
23
23
|
};
|
|
24
24
|
content: {
|
|
25
|
-
"application/json": import('
|
|
25
|
+
"application/json": import('../../core/sdk/schema').components["schemas"]["ErrorDto"];
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PubSub } from '
|
|
1
|
+
import { PubSub } from 'src/headless/core';
|
|
2
2
|
export declare function usePubsub<T>(p: PubSub<T>): T;
|
|
@@ -8,11 +8,11 @@ export declare function useVote(id: string, sessionId: string, onSuccess?: () =>
|
|
|
8
8
|
* @param id
|
|
9
9
|
* @param onSuccess
|
|
10
10
|
* @deprecated use useVote instead
|
|
11
|
-
*/
|
|
11
|
+
*/
|
|
12
12
|
export declare function useUpvote(id: string, sessionId: string, onSuccess?: () => void): import('react-use/lib/useAsyncFn').AsyncFnReturn<() => Promise<void>>;
|
|
13
13
|
/**
|
|
14
14
|
* @param id
|
|
15
15
|
* @param onSuccess
|
|
16
16
|
* @deprecated use useVote instead
|
|
17
|
-
*/
|
|
17
|
+
*/
|
|
18
18
|
export declare function useDownvote(id: string, sessionId: string, onSuccess?: () => void): import('react-use/lib/useAsyncFn').AsyncFnReturn<() => Promise<void>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { WidgetProvider, useWidget, } from './WidgetProvider';
|
|
2
|
+
export { useConfig } from './hooks/useConfig';
|
|
3
|
+
export { useContact } from './hooks/useContact';
|
|
4
|
+
export { useIsAwaitingBotReply } from './hooks/useIsAwaitingBotReply';
|
|
5
|
+
export { useMessages } from './hooks/useMessages';
|
|
6
|
+
export { usePreludeData } from './hooks/usePreludeData';
|
|
7
|
+
export { usePubsub } from './hooks/usePubsub';
|
|
8
|
+
export { useSession } from './hooks/useSession';
|
|
9
|
+
export { useVote } from './hooks/useVote';
|
|
10
|
+
export { type FileWithProgress, useUploadFiles } from './hooks/useUploadFiles';
|
|
11
|
+
export type { WidgetConfig } from 'src/headless/core';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { BotMessageType } from 'src/headless/core/types/messages';
|
|
3
|
+
import { StringOrLiteral } from 'src/headless/core';
|
|
4
|
+
export type WidgetComponentProps<TData> = BotMessageType<TData>;
|
|
5
|
+
export type WidgetLiteralComponentKey = "bot_message" | "agent_message" | "loading" | "fallback";
|
|
6
|
+
export type WidgetComponentKey = StringOrLiteral<WidgetLiteralComponentKey>;
|
|
7
|
+
export type WidgetComponentType = {
|
|
8
|
+
key: WidgetComponentKey;
|
|
9
|
+
component: React.ElementType;
|
|
10
|
+
};
|
|
11
|
+
export type DefaultTextComponentBaseProps = {
|
|
12
|
+
message: string;
|
|
13
|
+
variant?: "default" | "error";
|
|
14
|
+
};
|
|
15
|
+
export type DefaultTextComponentProps = WidgetComponentProps<DefaultTextComponentBaseProps>;
|