@novu/react 3.18.2 → 3.19.1-rc.56a8a168f8
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/cjs/components/telegram-connect-button/DefaultTelegramConnectButton.cjs +3 -0
- package/dist/cjs/components/telegram-connect-button/DefaultTelegramConnectButton.cjs.map +1 -1
- package/dist/cjs/components/telegram-connect-button/DefaultTelegramConnectButton.d.cts +1 -1
- package/dist/cjs/hooks/index.cjs +2 -0
- package/dist/cjs/hooks/index.cjs.map +1 -1
- package/dist/cjs/hooks/index.d.cts +1 -0
- package/dist/cjs/hooks/useWebChat.cjs +326 -0
- package/dist/cjs/hooks/useWebChat.cjs.map +1 -0
- package/dist/cjs/hooks/useWebChat.d.cts +117 -0
- package/dist/cjs/index.cjs +4 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -0
- package/dist/cjs/server/index.cjs +27 -2
- package/dist/cjs/server/index.cjs.map +1 -1
- package/dist/cjs/server/index.d.cts +3 -1
- package/dist/esm/components/telegram-connect-button/DefaultTelegramConnectButton.d.ts +1 -1
- package/dist/esm/components/telegram-connect-button/DefaultTelegramConnectButton.js +3 -0
- package/dist/esm/components/telegram-connect-button/DefaultTelegramConnectButton.js.map +1 -1
- package/dist/esm/hooks/index.d.ts +1 -0
- package/dist/esm/hooks/index.js +1 -0
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/hooks/useWebChat.d.ts +117 -0
- package/dist/esm/hooks/useWebChat.js +294 -0
- package/dist/esm/hooks/useWebChat.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/server/index.d.ts +3 -1
- package/dist/esm/server/index.js +25 -1
- package/dist/esm/server/index.js.map +1 -1
- package/package.json +4 -3
|
@@ -46,7 +46,8 @@ __export(server_exports, {
|
|
|
46
46
|
useSchedule: () => useSchedule,
|
|
47
47
|
useSubscription: () => useSubscription,
|
|
48
48
|
useSubscriptions: () => useSubscriptions,
|
|
49
|
-
useUpdateSubscription: () => useUpdateSubscription
|
|
49
|
+
useUpdateSubscription: () => useUpdateSubscription,
|
|
50
|
+
useWebChat: () => useWebChat
|
|
50
51
|
});
|
|
51
52
|
module.exports = __toCommonJS(server_exports);
|
|
52
53
|
var import_ShadowRootDetector = require("../components/ShadowRootDetector.cjs");
|
|
@@ -91,6 +92,29 @@ function TelegramConnectButton() {
|
|
|
91
92
|
function useNovu() {
|
|
92
93
|
return null;
|
|
93
94
|
}
|
|
95
|
+
function useWebChat(_) {
|
|
96
|
+
return {
|
|
97
|
+
messages: [],
|
|
98
|
+
pendingActions: [],
|
|
99
|
+
isLoading: true,
|
|
100
|
+
isRunning: false,
|
|
101
|
+
typing: void 0,
|
|
102
|
+
conversationStatus: "active",
|
|
103
|
+
run: { isRunning: false },
|
|
104
|
+
pagination: {
|
|
105
|
+
status: "idle",
|
|
106
|
+
hasMore: false,
|
|
107
|
+
fetchMore: () => Promise.resolve({ data: void 0, error: void 0 })
|
|
108
|
+
},
|
|
109
|
+
isRecovering: false,
|
|
110
|
+
catchUpError: void 0,
|
|
111
|
+
refetch: () => Promise.resolve(),
|
|
112
|
+
sendMessage: () => Promise.resolve({ data: void 0, error: void 0 }),
|
|
113
|
+
respondToAction: () => Promise.resolve({ data: void 0, error: void 0 }),
|
|
114
|
+
sendAction: () => Promise.resolve({ data: void 0, error: void 0 }),
|
|
115
|
+
retryMessage: () => Promise.resolve({ data: void 0, error: void 0 })
|
|
116
|
+
};
|
|
117
|
+
}
|
|
94
118
|
function useCounts(_) {
|
|
95
119
|
return {
|
|
96
120
|
isLoading: false,
|
|
@@ -188,6 +212,7 @@ function useSubscriptions(_) {
|
|
|
188
212
|
useSchedule,
|
|
189
213
|
useSubscription,
|
|
190
214
|
useSubscriptions,
|
|
191
|
-
useUpdateSubscription
|
|
215
|
+
useUpdateSubscription,
|
|
216
|
+
useWebChat
|
|
192
217
|
});
|
|
193
218
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/index.tsx"],"sourcesContent":["import type { InboxProps } from '../components/Inbox';\nimport { ShadowRootDetector } from '../components/ShadowRootDetector';\nimport type {\n UseCreateSubscriptionProps,\n UseCreateSubscriptionResult,\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesProps,\n UsePreferencesResult,\n UseRemoveSubscriptionProps,\n UseRemoveSubscriptionResult,\n UseScheduleProps,\n UseScheduleResult,\n UseSubscriptionProps,\n UseSubscriptionResult,\n UseSubscriptionsProps,\n UseSubscriptionsResult,\n UseUpdateSubscriptionProps,\n UseUpdateSubscriptionResult,\n} from '../hooks';\nimport type { NovuProviderProps } from '../hooks/NovuProvider';\nimport type { UseCountsProps, UseCountsResult } from '../hooks/useCounts';\n\n/**\n * Exporting all components from the components folder\n * as empty functions to fix build errors in SSR\n * This will be replaced with actual components\n * when we implement the SSR components in @novu/js/ui\n */\nexport function Inbox(props: InboxProps) {\n return <ShadowRootDetector />;\n}\n\nexport function InboxContent() {}\n\nexport function Notifications() {}\n\nexport function Preferences() {}\n\nexport function Bell() {}\n\nexport function NovuProvider(props: NovuProviderProps) {\n return <>{props.children}</>;\n}\n\nexport function Subscription() {\n return <ShadowRootDetector />;\n}\n\nexport function SubscriptionButton() {}\n\nexport function SubscriptionPreferences() {}\n\nexport function SlackConnectButton() {\n return <ShadowRootDetector />;\n}\n\nexport function SlackLinkUser() {\n return <ShadowRootDetector />;\n}\n\nexport function MsTeamsConnectButton() {\n return <ShadowRootDetector />;\n}\n\nexport function MsTeamsLinkUser() {\n return <ShadowRootDetector />;\n}\n\nexport function TelegramConnectButton() {\n return <ShadowRootDetector />;\n}\n\nexport function useNovu() {\n return null;\n}\n\nexport function useCounts(_: UseCountsProps): UseCountsResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useNotifications(_: UseNotificationsProps): UseNotificationsResult {\n return {\n isLoading: false,\n isFetching: false,\n hasMore: false,\n readAll: () => Promise.resolve({ data: undefined, error: undefined }),\n seenAll: () => Promise.resolve({ data: undefined, error: undefined }),\n archiveAll: () => Promise.resolve({ data: undefined, error: undefined }),\n archiveAllRead: () => Promise.resolve({ data: undefined, error: undefined }),\n refetch: () => Promise.resolve(),\n fetchMore: () => Promise.resolve(),\n };\n}\n\nexport function usePreferences(_: UsePreferencesProps): UsePreferencesResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useSchedule(_: UseScheduleProps): UseScheduleResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useSubscription(_: UseSubscriptionProps): UseSubscriptionResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useCreateSubscription(_: UseCreateSubscriptionProps = {}): UseCreateSubscriptionResult {\n return {\n isCreating: false,\n error: undefined,\n create: () => Promise.resolve({ data: undefined, error: undefined }),\n };\n}\n\nexport function useUpdateSubscription(_: UseUpdateSubscriptionProps = {}): UseUpdateSubscriptionResult {\n return {\n isUpdating: false,\n error: undefined,\n update: () => Promise.resolve({ data: undefined, error: undefined }),\n };\n}\n\nexport function useRemoveSubscription(_: UseRemoveSubscriptionProps = {}): UseRemoveSubscriptionResult {\n return {\n isRemoving: false,\n error: undefined,\n remove: () => Promise.resolve({ data: undefined, error: undefined }),\n };\n}\n\nexport function useSubscriptions(_: UseSubscriptionsProps): UseSubscriptionsResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport type * from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\n\nexport type {\n AllLocalization,\n AllLocalizationKey,\n ElementStyles,\n InboxAppearance,\n InboxAppearanceCallback,\n InboxAppearanceCallbackFunction,\n InboxAppearanceCallbackKeys,\n InboxAppearanceKey,\n InboxElements,\n InboxLocalization,\n InboxLocalizationKey,\n InboxTheme,\n NotificationActionClickHandler,\n NotificationClickHandler,\n NotificationRenderer,\n PreferenceGroups,\n PreferencesFilter,\n RouterPush,\n SubscriptionAppearance,\n SubscriptionAppearanceCallback,\n SubscriptionAppearanceCallbackFunction,\n SubscriptionAppearanceCallbackKeys,\n SubscriptionAppearanceKey,\n SubscriptionElements,\n SubscriptionLocalization,\n SubscriptionLocalizationKey,\n SubscriptionTheme,\n Tab,\n Variables,\n} from '@novu/js/ui';\n\nexport type { BellProps, InboxContentProps, InboxProps, NotificationProps, NovuProviderProps } from '../components';\n\nexport type {\n UseCountsProps,\n UseCountsResult,\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesResult,\n UseScheduleProps as UsePreferencesProps,\n} from '../hooks';\n\nexport type {\n BaseProps,\n BellRenderer,\n BodyRenderer,\n DefaultInboxProps,\n DefaultProps,\n NoRendererProps,\n NotificationRendererProps,\n NotificationsRenderer,\n SubjectBodyRendererProps,\n SubjectRenderer,\n WithChildrenProps,\n} from '../utils/types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gCAAmC;
|
|
1
|
+
{"version":3,"sources":["../../../src/server/index.tsx"],"sourcesContent":["import type { InboxProps } from '../components/Inbox';\nimport { ShadowRootDetector } from '../components/ShadowRootDetector';\nimport type {\n UseWebChatProps,\n UseWebChatResult,\n UseCreateSubscriptionProps,\n UseCreateSubscriptionResult,\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesProps,\n UsePreferencesResult,\n UseRemoveSubscriptionProps,\n UseRemoveSubscriptionResult,\n UseScheduleProps,\n UseScheduleResult,\n UseSubscriptionProps,\n UseSubscriptionResult,\n UseSubscriptionsProps,\n UseSubscriptionsResult,\n UseUpdateSubscriptionProps,\n UseUpdateSubscriptionResult,\n} from '../hooks';\nimport type { NovuProviderProps } from '../hooks/NovuProvider';\nimport type { UseCountsProps, UseCountsResult } from '../hooks/useCounts';\n\n/**\n * Exporting all components from the components folder\n * as empty functions to fix build errors in SSR\n * This will be replaced with actual components\n * when we implement the SSR components in @novu/js/ui\n */\nexport function Inbox(props: InboxProps) {\n return <ShadowRootDetector />;\n}\n\nexport function InboxContent() {}\n\nexport function Notifications() {}\n\nexport function Preferences() {}\n\nexport function Bell() {}\n\nexport function NovuProvider(props: NovuProviderProps) {\n return <>{props.children}</>;\n}\n\nexport function Subscription() {\n return <ShadowRootDetector />;\n}\n\nexport function SubscriptionButton() {}\n\nexport function SubscriptionPreferences() {}\n\nexport function SlackConnectButton() {\n return <ShadowRootDetector />;\n}\n\nexport function SlackLinkUser() {\n return <ShadowRootDetector />;\n}\n\nexport function MsTeamsConnectButton() {\n return <ShadowRootDetector />;\n}\n\nexport function MsTeamsLinkUser() {\n return <ShadowRootDetector />;\n}\n\nexport function TelegramConnectButton() {\n return <ShadowRootDetector />;\n}\n\nexport function useNovu() {\n return null;\n}\n\nexport function useWebChat(_: UseWebChatProps): UseWebChatResult {\n return {\n messages: [],\n pendingActions: [],\n isLoading: true,\n isRunning: false,\n typing: undefined,\n conversationStatus: 'active',\n run: { isRunning: false },\n pagination: {\n status: 'idle',\n hasMore: false,\n fetchMore: () => Promise.resolve({ data: undefined, error: undefined }),\n },\n isRecovering: false,\n catchUpError: undefined,\n refetch: () => Promise.resolve(),\n sendMessage: () => Promise.resolve({ data: undefined, error: undefined }),\n respondToAction: () => Promise.resolve({ data: undefined, error: undefined }),\n sendAction: () => Promise.resolve({ data: undefined, error: undefined }),\n retryMessage: () => Promise.resolve({ data: undefined, error: undefined }),\n };\n}\n\nexport function useCounts(_: UseCountsProps): UseCountsResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useNotifications(_: UseNotificationsProps): UseNotificationsResult {\n return {\n isLoading: false,\n isFetching: false,\n hasMore: false,\n readAll: () => Promise.resolve({ data: undefined, error: undefined }),\n seenAll: () => Promise.resolve({ data: undefined, error: undefined }),\n archiveAll: () => Promise.resolve({ data: undefined, error: undefined }),\n archiveAllRead: () => Promise.resolve({ data: undefined, error: undefined }),\n refetch: () => Promise.resolve(),\n fetchMore: () => Promise.resolve(),\n };\n}\n\nexport function usePreferences(_: UsePreferencesProps): UsePreferencesResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useSchedule(_: UseScheduleProps): UseScheduleResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useSubscription(_: UseSubscriptionProps): UseSubscriptionResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useCreateSubscription(_: UseCreateSubscriptionProps = {}): UseCreateSubscriptionResult {\n return {\n isCreating: false,\n error: undefined,\n create: () => Promise.resolve({ data: undefined, error: undefined }),\n };\n}\n\nexport function useUpdateSubscription(_: UseUpdateSubscriptionProps = {}): UseUpdateSubscriptionResult {\n return {\n isUpdating: false,\n error: undefined,\n update: () => Promise.resolve({ data: undefined, error: undefined }),\n };\n}\n\nexport function useRemoveSubscription(_: UseRemoveSubscriptionProps = {}): UseRemoveSubscriptionResult {\n return {\n isRemoving: false,\n error: undefined,\n remove: () => Promise.resolve({ data: undefined, error: undefined }),\n };\n}\n\nexport function useSubscriptions(_: UseSubscriptionsProps): UseSubscriptionsResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport type * from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\n\nexport type {\n AllLocalization,\n AllLocalizationKey,\n ElementStyles,\n InboxAppearance,\n InboxAppearanceCallback,\n InboxAppearanceCallbackFunction,\n InboxAppearanceCallbackKeys,\n InboxAppearanceKey,\n InboxElements,\n InboxLocalization,\n InboxLocalizationKey,\n InboxTheme,\n NotificationActionClickHandler,\n NotificationClickHandler,\n NotificationRenderer,\n PreferenceGroups,\n PreferencesFilter,\n RouterPush,\n SubscriptionAppearance,\n SubscriptionAppearanceCallback,\n SubscriptionAppearanceCallbackFunction,\n SubscriptionAppearanceCallbackKeys,\n SubscriptionAppearanceKey,\n SubscriptionElements,\n SubscriptionLocalization,\n SubscriptionLocalizationKey,\n SubscriptionTheme,\n Tab,\n Variables,\n} from '@novu/js/ui';\n\nexport type { BellProps, InboxContentProps, InboxProps, NotificationProps, NovuProviderProps } from '../components';\n\nexport type {\n UseWebChatProps,\n UseWebChatResult,\n UseCountsProps,\n UseCountsResult,\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesResult,\n UseScheduleProps as UsePreferencesProps,\n} from '../hooks';\n\nexport type {\n BaseProps,\n BellRenderer,\n BodyRenderer,\n DefaultInboxProps,\n DefaultProps,\n NoRendererProps,\n NotificationRendererProps,\n NotificationsRenderer,\n SubjectBodyRendererProps,\n SubjectRenderer,\n WithChildrenProps,\n} from '../utils/types';\n"],"mappings":"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","names":[]}
|
|
@@ -3,6 +3,7 @@ import { InboxProps } from '../components/Inbox.cjs';
|
|
|
3
3
|
export * from '@novu/js';
|
|
4
4
|
export { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';
|
|
5
5
|
import { NovuProviderProps } from '../hooks/NovuProvider.cjs';
|
|
6
|
+
import { UseWebChatProps, UseWebChatResult } from '../hooks/useWebChat.cjs';
|
|
6
7
|
import { UseCountsProps, UseCountsResult } from '../hooks/useCounts.cjs';
|
|
7
8
|
import { UseCreateSubscriptionProps, UseCreateSubscriptionResult } from '../hooks/useCreateSubscription.cjs';
|
|
8
9
|
import { UseNotificationsProps, UseNotificationsResult } from '../hooks/useNotifications.cjs';
|
|
@@ -40,6 +41,7 @@ declare function MsTeamsConnectButton(): react_jsx_runtime.JSX.Element;
|
|
|
40
41
|
declare function MsTeamsLinkUser(): react_jsx_runtime.JSX.Element;
|
|
41
42
|
declare function TelegramConnectButton(): react_jsx_runtime.JSX.Element;
|
|
42
43
|
declare function useNovu(): null;
|
|
44
|
+
declare function useWebChat(_: UseWebChatProps): UseWebChatResult;
|
|
43
45
|
declare function useCounts(_: UseCountsProps): UseCountsResult;
|
|
44
46
|
declare function useNotifications(_: UseNotificationsProps): UseNotificationsResult;
|
|
45
47
|
declare function usePreferences(_: UsePreferencesProps): UsePreferencesResult;
|
|
@@ -50,4 +52,4 @@ declare function useUpdateSubscription(_?: UseUpdateSubscriptionProps): UseUpdat
|
|
|
50
52
|
declare function useRemoveSubscription(_?: UseRemoveSubscriptionProps): UseRemoveSubscriptionResult;
|
|
51
53
|
declare function useSubscriptions(_: UseSubscriptionsProps): UseSubscriptionsResult;
|
|
52
54
|
|
|
53
|
-
export { Bell, Inbox, InboxContent, InboxProps, MsTeamsConnectButton, MsTeamsLinkUser, Notifications, NovuProvider, NovuProviderProps, Preferences, SlackConnectButton, SlackLinkUser, Subscription, SubscriptionButton, SubscriptionPreferences, TelegramConnectButton, UseCountsProps, UseCountsResult, UseNotificationsProps, UseNotificationsResult, UseScheduleProps as UsePreferencesProps, UsePreferencesResult, useCounts, useCreateSubscription, useNotifications, useNovu, usePreferences, useRemoveSubscription, useSchedule, useSubscription, useSubscriptions, useUpdateSubscription };
|
|
55
|
+
export { Bell, Inbox, InboxContent, InboxProps, MsTeamsConnectButton, MsTeamsLinkUser, Notifications, NovuProvider, NovuProviderProps, Preferences, SlackConnectButton, SlackLinkUser, Subscription, SubscriptionButton, SubscriptionPreferences, TelegramConnectButton, UseCountsProps, UseCountsResult, UseNotificationsProps, UseNotificationsResult, UseScheduleProps as UsePreferencesProps, UsePreferencesResult, UseWebChatProps, UseWebChatResult, useCounts, useCreateSubscription, useNotifications, useNovu, usePreferences, useRemoveSubscription, useSchedule, useSubscription, useSubscriptions, useUpdateSubscription, useWebChat };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { TelegramConnectButtonProps } from '@novu/js/ui';
|
|
3
3
|
|
|
4
|
-
type DefaultTelegramConnectButtonProps = Pick<TelegramConnectButtonProps, 'integrationIdentifier' | 'subscriberId' | 'context' | 'onConnectSuccess' | 'onConnectError' | 'onDisconnectSuccess' | 'onDisconnectError' | 'connectLabel' | 'connectedLabel'>;
|
|
4
|
+
type DefaultTelegramConnectButtonProps = Pick<TelegramConnectButtonProps, 'integrationIdentifier' | 'subscriberId' | 'context' | 'contextHash' | 'onConnectSuccess' | 'onConnectError' | 'onDisconnectSuccess' | 'onDisconnectError' | 'connectLabel' | 'connectedLabel'>;
|
|
5
5
|
declare const DefaultTelegramConnectButton: (props: DefaultTelegramConnectButtonProps) => react_jsx_runtime.JSX.Element;
|
|
6
6
|
|
|
7
7
|
export { DefaultTelegramConnectButton, type DefaultTelegramConnectButtonProps };
|
|
@@ -8,6 +8,7 @@ var DefaultTelegramConnectButton = (props) => {
|
|
|
8
8
|
integrationIdentifier,
|
|
9
9
|
subscriberId,
|
|
10
10
|
context,
|
|
11
|
+
contextHash,
|
|
11
12
|
onConnectSuccess,
|
|
12
13
|
onConnectError,
|
|
13
14
|
onDisconnectSuccess,
|
|
@@ -24,6 +25,7 @@ var DefaultTelegramConnectButton = (props) => {
|
|
|
24
25
|
integrationIdentifier,
|
|
25
26
|
subscriberId,
|
|
26
27
|
context,
|
|
28
|
+
contextHash,
|
|
27
29
|
onConnectSuccess,
|
|
28
30
|
onConnectError,
|
|
29
31
|
onDisconnectSuccess,
|
|
@@ -39,6 +41,7 @@ var DefaultTelegramConnectButton = (props) => {
|
|
|
39
41
|
integrationIdentifier,
|
|
40
42
|
subscriberId,
|
|
41
43
|
context,
|
|
44
|
+
contextHash,
|
|
42
45
|
onConnectSuccess,
|
|
43
46
|
onConnectError,
|
|
44
47
|
onDisconnectSuccess,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/telegram-connect-button/DefaultTelegramConnectButton.tsx"],"sourcesContent":["import { TelegramConnectButtonProps } from '@novu/js/ui';\nimport { useCallback } from 'react';\nimport { useNovuUI } from '../../context/NovuUIContext';\nimport { Mounter } from '../Mounter';\n\nexport type DefaultTelegramConnectButtonProps = Pick<\n TelegramConnectButtonProps,\n | 'integrationIdentifier'\n | 'subscriberId'\n | 'context'\n | 'onConnectSuccess'\n | 'onConnectError'\n | 'onDisconnectSuccess'\n | 'onDisconnectError'\n | 'connectLabel'\n | 'connectedLabel'\n>;\n\nexport const DefaultTelegramConnectButton = (props: DefaultTelegramConnectButtonProps) => {\n const {\n integrationIdentifier,\n subscriberId,\n context,\n onConnectSuccess,\n onConnectError,\n onDisconnectSuccess,\n onDisconnectError,\n connectLabel,\n connectedLabel,\n } = props;\n const { novuUI } = useNovuUI();\n\n const mount = useCallback(\n (element: HTMLElement) => {\n return novuUI.mountComponent({\n name: 'TelegramConnectButton',\n props: {\n integrationIdentifier,\n subscriberId,\n context,\n onConnectSuccess,\n onConnectError,\n onDisconnectSuccess,\n onDisconnectError,\n connectLabel,\n connectedLabel,\n },\n element,\n });\n },\n [\n novuUI,\n integrationIdentifier,\n subscriberId,\n context,\n onConnectSuccess,\n onConnectError,\n onDisconnectSuccess,\n onDisconnectError,\n connectLabel,\n connectedLabel,\n ]\n );\n\n return <Mounter mount={mount} />;\n};\n"],"mappings":";AACA,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAC1B,SAAS,eAAe;
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/telegram-connect-button/DefaultTelegramConnectButton.tsx"],"sourcesContent":["import { TelegramConnectButtonProps } from '@novu/js/ui';\nimport { useCallback } from 'react';\nimport { useNovuUI } from '../../context/NovuUIContext';\nimport { Mounter } from '../Mounter';\n\nexport type DefaultTelegramConnectButtonProps = Pick<\n TelegramConnectButtonProps,\n | 'integrationIdentifier'\n | 'subscriberId'\n | 'context'\n | 'contextHash'\n | 'onConnectSuccess'\n | 'onConnectError'\n | 'onDisconnectSuccess'\n | 'onDisconnectError'\n | 'connectLabel'\n | 'connectedLabel'\n>;\n\nexport const DefaultTelegramConnectButton = (props: DefaultTelegramConnectButtonProps) => {\n const {\n integrationIdentifier,\n subscriberId,\n context,\n contextHash,\n onConnectSuccess,\n onConnectError,\n onDisconnectSuccess,\n onDisconnectError,\n connectLabel,\n connectedLabel,\n } = props;\n const { novuUI } = useNovuUI();\n\n const mount = useCallback(\n (element: HTMLElement) => {\n return novuUI.mountComponent({\n name: 'TelegramConnectButton',\n props: {\n integrationIdentifier,\n subscriberId,\n context,\n contextHash,\n onConnectSuccess,\n onConnectError,\n onDisconnectSuccess,\n onDisconnectError,\n connectLabel,\n connectedLabel,\n },\n element,\n });\n },\n [\n novuUI,\n integrationIdentifier,\n subscriberId,\n context,\n contextHash,\n onConnectSuccess,\n onConnectError,\n onDisconnectSuccess,\n onDisconnectError,\n connectLabel,\n connectedLabel,\n ]\n );\n\n return <Mounter mount={mount} />;\n};\n"],"mappings":";AACA,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AAiEf;AAjDF,IAAM,+BAA+B,CAAC,UAA6C;AACxF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,EAAE,OAAO,IAAI,UAAU;AAE7B,QAAM,QAAQ;AAAA,IACZ,CAAC,YAAyB;AACxB,aAAO,OAAO,eAAe;AAAA,QAC3B,MAAM;AAAA,QACN,OAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO,oBAAC,WAAQ,OAAc;AAChC;","names":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from '@novu/js';
|
|
2
2
|
export { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';
|
|
3
3
|
export { NovuProvider, useNovu } from './NovuProvider.js';
|
|
4
|
+
export { UseWebChatProps, UseWebChatResult, useWebChat } from './useWebChat.js';
|
|
4
5
|
export { UseChannelConnectionProps, UseChannelConnectionResult, useChannelConnection } from './useChannelConnection.js';
|
|
5
6
|
export { UseChannelConnectionsProps, UseChannelConnectionsResult, useChannelConnections } from './useChannelConnections.js';
|
|
6
7
|
export { UseChannelEndpointProps, UseChannelEndpointResult, useChannelEndpoint } from './useChannelEndpoint.js';
|
package/dist/esm/hooks/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/hooks/index.ts
|
|
2
2
|
import { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from "@novu/js";
|
|
3
3
|
import { NovuProvider, useNovu } from "./NovuProvider.js";
|
|
4
|
+
export * from "./useWebChat.js";
|
|
4
5
|
export * from "./useChannelConnection.js";
|
|
5
6
|
export * from "./useChannelConnections.js";
|
|
6
7
|
export * from "./useChannelEndpoint.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/index.ts"],"sourcesContent":["export type * from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\nexport { NovuProvider, useNovu } from './NovuProvider';\nexport * from './useChannelConnection';\nexport * from './useChannelConnections';\nexport * from './useChannelEndpoint';\nexport * from './useChannelEndpoints';\nexport * from './useCounts';\nexport * from './useCreateChannelEndpoint';\nexport * from './useCreateSubscription';\nexport * from './useDeleteChannelConnection';\nexport * from './useDeleteChannelEndpoint';\nexport * from './useNotifications';\nexport * from './usePreferences';\nexport * from './useRemoveSubscription';\nexport * from './useSchedule';\nexport * from './useSubscription';\nexport * from './useSubscriptions';\nexport * from './useTelegramSubscriberLink';\nexport * from './useUpdateSubscription';\n"],"mappings":";AACA,SAAS,iBAAiB,mBAAmB,+BAA+B;AAC5E,SAAS,cAAc,eAAe;AACtC,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/index.ts"],"sourcesContent":["export type * from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\nexport { NovuProvider, useNovu } from './NovuProvider';\nexport * from './useWebChat';\nexport * from './useChannelConnection';\nexport * from './useChannelConnections';\nexport * from './useChannelEndpoint';\nexport * from './useChannelEndpoints';\nexport * from './useCounts';\nexport * from './useCreateChannelEndpoint';\nexport * from './useCreateSubscription';\nexport * from './useDeleteChannelConnection';\nexport * from './useDeleteChannelEndpoint';\nexport * from './useNotifications';\nexport * from './usePreferences';\nexport * from './useRemoveSubscription';\nexport * from './useSchedule';\nexport * from './useSubscription';\nexport * from './useSubscriptions';\nexport * from './useTelegramSubscriberLink';\nexport * from './useUpdateSubscription';\n"],"mappings":";AACA,SAAS,iBAAiB,mBAAmB,+BAA+B;AAC5E,SAAS,cAAc,eAAe;AACtC,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { LoadConversationResult, NovuError, WebChatPlanLimitError, AgentMessage, AgentPendingAction, AgentEventEnvelope, AgentHashFields, AgentConversationRuntime, AgentConversationRunSnapshot, AgentConversationStatus, WebChatPagination, SendMessageInput, SendMessageResult, AgentToolApprovalDecision, RespondToActionResult, SendActionResult } from '@novu/js';
|
|
2
|
+
|
|
3
|
+
type UseWebChatCallbacks = {
|
|
4
|
+
onSuccess?: (data: LoadConversationResult) => void;
|
|
5
|
+
onError?: (error: NovuError | WebChatPlanLimitError) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Fires once when a message id first appears. History pages do not fire.
|
|
8
|
+
* The first event of a turn can create an empty assistant message before text arrives.
|
|
9
|
+
* A send that never reaches the server does not fire. The message status becomes `failed` instead.
|
|
10
|
+
*/
|
|
11
|
+
onMessage?: (message: AgentMessage) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Fires once per pending action, including actions still pending on mount.
|
|
14
|
+
* Paging backwards does not fire.
|
|
15
|
+
*/
|
|
16
|
+
onActionRequested?: (action: AgentPendingAction) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Live event envelopes for this conversation.
|
|
19
|
+
* Duplicates that the client drops do not fire.
|
|
20
|
+
* Envelopes that arrive before the conversation id exists do not fire.
|
|
21
|
+
* The message list in this render does not include this envelope yet.
|
|
22
|
+
*/
|
|
23
|
+
onEvent?: (envelope: AgentEventEnvelope) => void;
|
|
24
|
+
};
|
|
25
|
+
/** Arguments for {@link useWebChat}. Pass `agentId`, or pass `conversation`. Do not mix the two. */
|
|
26
|
+
type UseWebChatProps = UseWebChatCallbacks & AgentHashFields & ({
|
|
27
|
+
agentId: string;
|
|
28
|
+
/**
|
|
29
|
+
* Resume this conversation. The hook loads history on mount.
|
|
30
|
+
* Omit this prop to start a new chat. The first send creates a conversation.
|
|
31
|
+
*/
|
|
32
|
+
conversationId?: string;
|
|
33
|
+
conversation?: never;
|
|
34
|
+
} | {
|
|
35
|
+
/** Share an existing conversation runtime across multiple hook instances. */
|
|
36
|
+
conversation: AgentConversationRuntime;
|
|
37
|
+
agentId?: never;
|
|
38
|
+
conversationId?: never;
|
|
39
|
+
agentHash?: never;
|
|
40
|
+
});
|
|
41
|
+
/** State and actions returned by {@link useWebChat}. */
|
|
42
|
+
type UseWebChatResult = {
|
|
43
|
+
/** Conversation timeline. */
|
|
44
|
+
messages: AgentMessage[];
|
|
45
|
+
/** Tool approvals and MCP connect items that are still pending. */
|
|
46
|
+
pendingActions: AgentPendingAction[];
|
|
47
|
+
/** Server conversation id after create or resume. */
|
|
48
|
+
conversationId?: string;
|
|
49
|
+
/** Last error from load, send, retry, or action. */
|
|
50
|
+
error?: NovuError | WebChatPlanLimitError;
|
|
51
|
+
/** True while Web Chat loads and, for an existing conversation, until the first history fetch completes. */
|
|
52
|
+
isLoading: boolean;
|
|
53
|
+
/** True while the agent turn is in progress. Same as `run.isRunning`. */
|
|
54
|
+
isRunning: boolean;
|
|
55
|
+
/** Typing indicator. Same as `run.typing`. Absent when the agent is not typing. */
|
|
56
|
+
typing?: AgentConversationRunSnapshot['typing'];
|
|
57
|
+
/** `'active'` or `'resolved'`. The agent sets `resolved` with `ctx.resolve()`. Not a loading flag. */
|
|
58
|
+
conversationStatus: AgentConversationStatus;
|
|
59
|
+
/** Current agent-run snapshot. */
|
|
60
|
+
run: AgentConversationRunSnapshot;
|
|
61
|
+
/** Older-history control. Not a top-level `hasMore` or `fetchMore`. */
|
|
62
|
+
pagination: WebChatPagination & {
|
|
63
|
+
fetchMore: () => Promise<{
|
|
64
|
+
data?: {
|
|
65
|
+
messages: AgentMessage[];
|
|
66
|
+
hasMore: boolean;
|
|
67
|
+
};
|
|
68
|
+
error?: NovuError;
|
|
69
|
+
}>;
|
|
70
|
+
};
|
|
71
|
+
/** True while reconnect recovery is in progress. */
|
|
72
|
+
isRecovering: boolean;
|
|
73
|
+
/** Set when reconnect recovery fails. Separate from send and fetch `error`. */
|
|
74
|
+
catchUpError?: NovuError;
|
|
75
|
+
/** Reload the newest history page. No-op when there is no conversation id. */
|
|
76
|
+
refetch: () => Promise<void>;
|
|
77
|
+
/** Send a user message. `input` is a string, or `{ text, metadata }`. Creates a conversation when `conversationId` is omitted. */
|
|
78
|
+
sendMessage: (input: SendMessageInput) => Promise<{
|
|
79
|
+
data?: SendMessageResult;
|
|
80
|
+
error?: NovuError | WebChatPlanLimitError;
|
|
81
|
+
}>;
|
|
82
|
+
/** Resolve a pending `tool-approval`. Pass `action.id` from `pendingActions`. */
|
|
83
|
+
respondToAction: (args: {
|
|
84
|
+
actionId: string;
|
|
85
|
+
decision: AgentToolApprovalDecision;
|
|
86
|
+
}) => Promise<{
|
|
87
|
+
data?: RespondToActionResult;
|
|
88
|
+
error?: NovuError | WebChatPlanLimitError;
|
|
89
|
+
}>;
|
|
90
|
+
/** Click a Card button. Do not use this for tool approval. */
|
|
91
|
+
sendAction: (args: {
|
|
92
|
+
actionId: string;
|
|
93
|
+
sourceMessageId: string;
|
|
94
|
+
value?: string;
|
|
95
|
+
}) => Promise<{
|
|
96
|
+
data?: SendActionResult;
|
|
97
|
+
error?: NovuError | WebChatPlanLimitError;
|
|
98
|
+
}>;
|
|
99
|
+
/** Resend a message whose `status` is `failed`. Reuses the original idempotency key. */
|
|
100
|
+
retryMessage: (messageId: string) => Promise<{
|
|
101
|
+
data?: SendMessageResult;
|
|
102
|
+
error?: NovuError | WebChatPlanLimitError;
|
|
103
|
+
}>;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Headless Web Chat client. Use it inside `NovuProvider`.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```tsx
|
|
110
|
+
* const { messages, sendMessage, isRunning, isLoading, error } = useWebChat({
|
|
111
|
+
* agentId: 'YOUR_AGENT_IDENTIFIER',
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
declare const useWebChat: (props: UseWebChatProps) => UseWebChatResult;
|
|
116
|
+
|
|
117
|
+
export { type UseWebChatProps, type UseWebChatResult, useWebChat };
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// src/hooks/useWebChat.ts
|
|
2
|
+
import { NovuError } from "@novu/js";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { useDataRef } from "./internal/useDataRef.js";
|
|
5
|
+
import { useNovu } from "./NovuProvider.js";
|
|
6
|
+
var EMPTY_SERVER_SNAPSHOT = {
|
|
7
|
+
key: "ssr",
|
|
8
|
+
status: "loading",
|
|
9
|
+
run: { isRunning: false },
|
|
10
|
+
conversationStatus: "active",
|
|
11
|
+
pagination: { hasMore: false, status: "idle" },
|
|
12
|
+
messages: [],
|
|
13
|
+
pendingActions: [],
|
|
14
|
+
isRecovering: false
|
|
15
|
+
};
|
|
16
|
+
function handlePublicationCallbacks(args) {
|
|
17
|
+
const {
|
|
18
|
+
snapshot,
|
|
19
|
+
meta,
|
|
20
|
+
conversationIdProp,
|
|
21
|
+
propsRef,
|
|
22
|
+
loadNotifiedRef,
|
|
23
|
+
notifiedCatchUpErrorRef,
|
|
24
|
+
lastReportedErrorKeyRef
|
|
25
|
+
} = args;
|
|
26
|
+
if ((meta?.historyLoaded || meta?.change?.kind === "history") && !loadNotifiedRef.current && conversationIdProp) {
|
|
27
|
+
if (snapshot.conversationId) {
|
|
28
|
+
loadNotifiedRef.current = true;
|
|
29
|
+
propsRef.current.onSuccess?.({
|
|
30
|
+
conversationId: snapshot.conversationId,
|
|
31
|
+
messages: [...snapshot.messages],
|
|
32
|
+
hasMore: snapshot.pagination.hasMore
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (snapshot.catchUpError && snapshot.catchUpError !== notifiedCatchUpErrorRef.current) {
|
|
37
|
+
notifiedCatchUpErrorRef.current = snapshot.catchUpError;
|
|
38
|
+
propsRef.current.onError?.(snapshot.catchUpError);
|
|
39
|
+
} else if (!snapshot.catchUpError) {
|
|
40
|
+
notifiedCatchUpErrorRef.current = void 0;
|
|
41
|
+
}
|
|
42
|
+
if (snapshot.error) {
|
|
43
|
+
const originalMessage = "originalError" in snapshot.error ? snapshot.error.originalError?.message ?? "" : "";
|
|
44
|
+
const errorKey = `${snapshot.error.message}:${originalMessage}`;
|
|
45
|
+
if (lastReportedErrorKeyRef.current !== errorKey) {
|
|
46
|
+
lastReportedErrorKeyRef.current = errorKey;
|
|
47
|
+
propsRef.current.onError?.(snapshot.error);
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
lastReportedErrorKeyRef.current = void 0;
|
|
51
|
+
}
|
|
52
|
+
const change = meta?.change;
|
|
53
|
+
if (change?.kind === "live") {
|
|
54
|
+
propsRef.current.onEvent?.(change.envelope);
|
|
55
|
+
}
|
|
56
|
+
if (change && change.kind !== "history") {
|
|
57
|
+
for (const message of change.addedMessages) {
|
|
58
|
+
propsRef.current.onMessage?.(message);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (change) {
|
|
62
|
+
for (const action of change.newActions) {
|
|
63
|
+
propsRef.current.onActionRequested?.(action);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function getCreateFlowKey(agentId, agentHash) {
|
|
68
|
+
return `${agentId}\0${agentHash ?? ""}`;
|
|
69
|
+
}
|
|
70
|
+
function resolveOwnedRuntime(args) {
|
|
71
|
+
const key = getCreateFlowKey(args.agentId, args.agentHash);
|
|
72
|
+
const current = args.ownedRuntimeRef.current;
|
|
73
|
+
if (current?.novu === args.novu && current.key === key) {
|
|
74
|
+
return current.runtime;
|
|
75
|
+
}
|
|
76
|
+
current?.runtime.dispose();
|
|
77
|
+
const runtime = args.novu.webChat.conversation({ agentId: args.agentId, agentHash: args.agentHash });
|
|
78
|
+
args.ownedRuntimeRef.current = { key, novu: args.novu, runtime };
|
|
79
|
+
return runtime;
|
|
80
|
+
}
|
|
81
|
+
function toNovuError(error) {
|
|
82
|
+
if (error instanceof NovuError) {
|
|
83
|
+
return error;
|
|
84
|
+
}
|
|
85
|
+
if (error instanceof Error) {
|
|
86
|
+
return new NovuError("Failed to load Web Chat", error);
|
|
87
|
+
}
|
|
88
|
+
return new NovuError("Failed to load Web Chat", new Error(String(error)));
|
|
89
|
+
}
|
|
90
|
+
var useWebChat = (props) => {
|
|
91
|
+
const novu = useNovu();
|
|
92
|
+
const propsRef = useDataRef(props);
|
|
93
|
+
const [loadState, setLoadState] = useState(() => ({
|
|
94
|
+
novu,
|
|
95
|
+
status: "loading"
|
|
96
|
+
}));
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
let cancelled = false;
|
|
99
|
+
if (!novu.isWebChatLoaded) {
|
|
100
|
+
setLoadState({ novu, status: "loading" });
|
|
101
|
+
}
|
|
102
|
+
void novu.loadWebChat().then(() => {
|
|
103
|
+
if (!cancelled) {
|
|
104
|
+
setLoadState({ novu, status: "ready" });
|
|
105
|
+
}
|
|
106
|
+
}).catch((error) => {
|
|
107
|
+
if (cancelled) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const novuError = toNovuError(error);
|
|
111
|
+
propsRef.current.onError?.(novuError);
|
|
112
|
+
setLoadState({ novu, status: "error", error: novuError });
|
|
113
|
+
});
|
|
114
|
+
return () => {
|
|
115
|
+
cancelled = true;
|
|
116
|
+
};
|
|
117
|
+
}, [novu, propsRef]);
|
|
118
|
+
const webChatReady = loadState.novu === novu && loadState.status === "ready";
|
|
119
|
+
const webChatLoadError = loadState.novu === novu && loadState.status === "error" ? loadState.error : void 0;
|
|
120
|
+
const isWebChatLoading = loadState.novu !== novu || loadState.status === "loading";
|
|
121
|
+
const sharedRuntime = "conversation" in props ? props.conversation : void 0;
|
|
122
|
+
const agentId = sharedRuntime?.agentId ?? props.agentId;
|
|
123
|
+
const conversationIdProp = sharedRuntime ? void 0 : props.conversationId;
|
|
124
|
+
const agentHash = sharedRuntime ? void 0 : props.agentHash;
|
|
125
|
+
const ownedRuntimeRef = useRef(null);
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
const current = ownedRuntimeRef.current;
|
|
128
|
+
if (current && current.novu !== novu) {
|
|
129
|
+
current.runtime.dispose();
|
|
130
|
+
ownedRuntimeRef.current = null;
|
|
131
|
+
}
|
|
132
|
+
}, [novu]);
|
|
133
|
+
const cachedRuntime = useMemo(() => {
|
|
134
|
+
if (!webChatReady) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
if (sharedRuntime) {
|
|
138
|
+
return sharedRuntime;
|
|
139
|
+
}
|
|
140
|
+
if (!conversationIdProp) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
return novu.webChat.conversation({
|
|
144
|
+
agentId,
|
|
145
|
+
conversationId: conversationIdProp,
|
|
146
|
+
agentHash
|
|
147
|
+
});
|
|
148
|
+
}, [webChatReady, sharedRuntime, novu, agentId, conversationIdProp, agentHash]);
|
|
149
|
+
if (sharedRuntime || conversationIdProp) {
|
|
150
|
+
ownedRuntimeRef.current?.runtime.dispose();
|
|
151
|
+
ownedRuntimeRef.current = null;
|
|
152
|
+
}
|
|
153
|
+
const ownedRuntime = !webChatReady || sharedRuntime || conversationIdProp ? null : resolveOwnedRuntime({ novu, agentId, agentHash, ownedRuntimeRef });
|
|
154
|
+
const runtime = sharedRuntime ?? cachedRuntime ?? ownedRuntime;
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
return () => {
|
|
157
|
+
ownedRuntimeRef.current?.runtime.dispose();
|
|
158
|
+
ownedRuntimeRef.current = null;
|
|
159
|
+
};
|
|
160
|
+
}, []);
|
|
161
|
+
const loadNotifiedRef = useRef(false);
|
|
162
|
+
const replayedActionsRef = useRef(false);
|
|
163
|
+
const notifiedCatchUpErrorRef = useRef();
|
|
164
|
+
const lastReportedErrorKeyRef = useRef();
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
loadNotifiedRef.current = false;
|
|
167
|
+
replayedActionsRef.current = false;
|
|
168
|
+
notifiedCatchUpErrorRef.current = void 0;
|
|
169
|
+
lastReportedErrorKeyRef.current = void 0;
|
|
170
|
+
}, [runtime]);
|
|
171
|
+
const subscribe = useCallback(
|
|
172
|
+
(onStoreChange) => {
|
|
173
|
+
if (!runtime) {
|
|
174
|
+
return () => {
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (!replayedActionsRef.current) {
|
|
178
|
+
replayedActionsRef.current = true;
|
|
179
|
+
for (const action of runtime.getSnapshot().pendingActions) {
|
|
180
|
+
propsRef.current.onActionRequested?.(action);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return runtime.subscribe((snapshot2, meta) => {
|
|
184
|
+
onStoreChange();
|
|
185
|
+
handlePublicationCallbacks({
|
|
186
|
+
snapshot: snapshot2,
|
|
187
|
+
meta,
|
|
188
|
+
conversationIdProp,
|
|
189
|
+
propsRef,
|
|
190
|
+
loadNotifiedRef,
|
|
191
|
+
notifiedCatchUpErrorRef,
|
|
192
|
+
lastReportedErrorKeyRef
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
},
|
|
196
|
+
[runtime, conversationIdProp, propsRef]
|
|
197
|
+
);
|
|
198
|
+
const getSnapshot = useCallback(() => {
|
|
199
|
+
return runtime?.getSnapshot() ?? EMPTY_SERVER_SNAPSHOT;
|
|
200
|
+
}, [runtime]);
|
|
201
|
+
const getServerSnapshot = useCallback(() => {
|
|
202
|
+
return runtime?.getServerSnapshot() ?? EMPTY_SERVER_SNAPSHOT;
|
|
203
|
+
}, [runtime]);
|
|
204
|
+
const snapshot = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
205
|
+
const callRuntime = useCallback(
|
|
206
|
+
async (action) => {
|
|
207
|
+
if (!runtime) {
|
|
208
|
+
const error = webChatLoadError ?? new NovuError(
|
|
209
|
+
isWebChatLoading ? "Web Chat is still loading" : "Web Chat runtime is unavailable",
|
|
210
|
+
new Error("Web Chat runtime is not ready")
|
|
211
|
+
);
|
|
212
|
+
propsRef.current.onError?.(error);
|
|
213
|
+
return { error };
|
|
214
|
+
}
|
|
215
|
+
const response = await action(runtime);
|
|
216
|
+
if (response.error) {
|
|
217
|
+
propsRef.current.onError?.(response.error);
|
|
218
|
+
}
|
|
219
|
+
return response;
|
|
220
|
+
},
|
|
221
|
+
[runtime, webChatLoadError, isWebChatLoading, propsRef]
|
|
222
|
+
);
|
|
223
|
+
const refetch = useCallback(async () => {
|
|
224
|
+
if (!runtime) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const response = await runtime.load();
|
|
228
|
+
if (response.data) {
|
|
229
|
+
propsRef.current.onSuccess?.({
|
|
230
|
+
conversationId: response.data.conversationId,
|
|
231
|
+
messages: [...response.data.messages],
|
|
232
|
+
hasMore: response.data.hasMore
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}, [runtime, propsRef]);
|
|
236
|
+
const fetchMore = useCallback(async () => {
|
|
237
|
+
const response = await callRuntime((target) => target.fetchMore());
|
|
238
|
+
return {
|
|
239
|
+
...response,
|
|
240
|
+
error: response.error,
|
|
241
|
+
data: response.data ? {
|
|
242
|
+
messages: [...response.data.messages],
|
|
243
|
+
hasMore: response.data.hasMore
|
|
244
|
+
} : void 0
|
|
245
|
+
};
|
|
246
|
+
}, [callRuntime]);
|
|
247
|
+
const paginationWithFetch = useMemo(
|
|
248
|
+
() => ({
|
|
249
|
+
status: snapshot.pagination.status,
|
|
250
|
+
hasMore: snapshot.pagination.hasMore,
|
|
251
|
+
fetchMore
|
|
252
|
+
}),
|
|
253
|
+
[snapshot.pagination.status, snapshot.pagination.hasMore, fetchMore]
|
|
254
|
+
);
|
|
255
|
+
const sendMessage = useCallback(
|
|
256
|
+
(input) => callRuntime((target) => target.sendMessage(input)),
|
|
257
|
+
[callRuntime]
|
|
258
|
+
);
|
|
259
|
+
const respondToAction = useCallback(
|
|
260
|
+
(args) => callRuntime((target) => target.respondToAction(args)),
|
|
261
|
+
[callRuntime]
|
|
262
|
+
);
|
|
263
|
+
const sendAction = useCallback(
|
|
264
|
+
(args) => callRuntime((target) => target.sendAction(args)),
|
|
265
|
+
[callRuntime]
|
|
266
|
+
);
|
|
267
|
+
const retryMessage = useCallback(
|
|
268
|
+
(messageId) => callRuntime((target) => target.retryMessage(messageId)),
|
|
269
|
+
[callRuntime]
|
|
270
|
+
);
|
|
271
|
+
return {
|
|
272
|
+
messages: [...snapshot.messages],
|
|
273
|
+
pendingActions: [...snapshot.pendingActions],
|
|
274
|
+
conversationId: snapshot.conversationId,
|
|
275
|
+
error: webChatLoadError ?? snapshot.error,
|
|
276
|
+
isLoading: !webChatLoadError && (isWebChatLoading || snapshot.status === "loading"),
|
|
277
|
+
isRunning: snapshot.run.isRunning,
|
|
278
|
+
typing: snapshot.run.typing,
|
|
279
|
+
conversationStatus: snapshot.conversationStatus,
|
|
280
|
+
run: snapshot.run,
|
|
281
|
+
pagination: paginationWithFetch,
|
|
282
|
+
isRecovering: snapshot.isRecovering,
|
|
283
|
+
catchUpError: snapshot.catchUpError,
|
|
284
|
+
refetch,
|
|
285
|
+
sendMessage,
|
|
286
|
+
respondToAction,
|
|
287
|
+
sendAction,
|
|
288
|
+
retryMessage
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
export {
|
|
292
|
+
useWebChat
|
|
293
|
+
};
|
|
294
|
+
//# sourceMappingURL=useWebChat.js.map
|