@novu/react 3.19.1-rc.68f5589d4e → 3.19.1

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/esm/index.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  TelegramConnectButton
18
18
  } from "./components/index.js";
19
19
  import {
20
- useAgentChat,
20
+ useWebChat,
21
21
  useChannelConnection,
22
22
  useChannelConnections,
23
23
  useChannelEndpoint,
@@ -53,7 +53,6 @@ export {
53
53
  SubscriptionPreferences,
54
54
  TelegramConnectButton,
55
55
  WorkflowCriticalityEnum,
56
- useAgentChat,
57
56
  useChannelConnection,
58
57
  useChannelConnections,
59
58
  useChannelEndpoint,
@@ -69,6 +68,7 @@ export {
69
68
  useSubscription,
70
69
  useSubscriptions,
71
70
  useTelegramSubscriberLink,
72
- useUpdateSubscription
71
+ useUpdateSubscription,
72
+ useWebChat
73
73
  };
74
74
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type * from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\n\nexport type {\n AllLocalization,\n AllLocalizationKey,\n ChannelConnectButtonIconKey,\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';\nexport type {\n BellProps,\n InboxContentProps,\n InboxProps,\n MsTeamsConnectButtonProps,\n MsTeamsLinkUserProps,\n NotificationProps,\n NovuProviderProps,\n SlackConnectButtonProps,\n SlackLinkUserProps,\n SubscriptionButtonProps,\n SubscriptionPreferencesProps,\n SubscriptionProps,\n TelegramConnectButtonProps,\n} from './components';\nexport {\n Bell,\n Inbox,\n InboxContent,\n MsTeamsConnectButton,\n MsTeamsLinkUser,\n Notifications,\n NovuProvider,\n Preferences,\n SlackConnectButton,\n SlackLinkUser,\n Subscription,\n SubscriptionButton,\n SubscriptionPreferences,\n TelegramConnectButton,\n} from './components';\nexport type {\n UseAgentChatProps,\n UseAgentChatResult,\n UseChannelConnectionProps,\n UseChannelConnectionResult,\n UseChannelConnectionsProps,\n UseChannelConnectionsResult,\n UseChannelEndpointProps,\n UseChannelEndpointResult,\n UseCountsProps,\n UseCountsResult,\n UseCreateChannelEndpointProps,\n UseCreateChannelEndpointResult,\n UseDeleteChannelEndpointProps,\n UseDeleteChannelEndpointResult,\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesResult,\n UseScheduleProps as UsePreferencesProps,\n UseTelegramSubscriberLinkProps,\n UseTelegramSubscriberLinkResult,\n} from './hooks';\nexport {\n useAgentChat,\n useChannelConnection,\n useChannelConnections,\n useChannelEndpoint,\n useCounts,\n useCreateChannelEndpoint,\n useCreateSubscription,\n useDeleteChannelEndpoint,\n useNotifications,\n useNovu,\n usePreferences,\n useRemoveSubscription,\n useSchedule,\n useSubscription,\n useSubscriptions,\n useTelegramSubscriberLink,\n useUpdateSubscription,\n} from './hooks';\n\nexport type {\n BaseProps,\n BellRenderer,\n BodyRenderer,\n DefaultInboxProps,\n DefaultProps,\n NoRendererProps,\n NotificationRendererProps,\n NotificationsRenderer,\n ReactAllAppearance,\n ReactInboxAppearance,\n ReactInboxTheme,\n ReactSubscriptionAppearance,\n ReactSubscriptionTheme,\n SubjectBodyRendererProps,\n SubjectRenderer,\n WithChildrenProps,\n} from './utils/types';\n"],"mappings":";AACA,SAAS,iBAAiB,mBAAmB,+BAA+B;AAiD5E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAuBP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type * from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\n\nexport type {\n AllLocalization,\n AllLocalizationKey,\n ChannelConnectButtonIconKey,\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';\nexport type {\n BellProps,\n InboxContentProps,\n InboxProps,\n MsTeamsConnectButtonProps,\n MsTeamsLinkUserProps,\n NotificationProps,\n NovuProviderProps,\n SlackConnectButtonProps,\n SlackLinkUserProps,\n SubscriptionButtonProps,\n SubscriptionPreferencesProps,\n SubscriptionProps,\n TelegramConnectButtonProps,\n} from './components';\nexport {\n Bell,\n Inbox,\n InboxContent,\n MsTeamsConnectButton,\n MsTeamsLinkUser,\n Notifications,\n NovuProvider,\n Preferences,\n SlackConnectButton,\n SlackLinkUser,\n Subscription,\n SubscriptionButton,\n SubscriptionPreferences,\n TelegramConnectButton,\n} from './components';\nexport type {\n UseWebChatProps,\n UseWebChatResult,\n UseChannelConnectionProps,\n UseChannelConnectionResult,\n UseChannelConnectionsProps,\n UseChannelConnectionsResult,\n UseChannelEndpointProps,\n UseChannelEndpointResult,\n UseCountsProps,\n UseCountsResult,\n UseCreateChannelEndpointProps,\n UseCreateChannelEndpointResult,\n UseDeleteChannelEndpointProps,\n UseDeleteChannelEndpointResult,\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesResult,\n UseScheduleProps as UsePreferencesProps,\n UseTelegramSubscriberLinkProps,\n UseTelegramSubscriberLinkResult,\n} from './hooks';\nexport {\n useWebChat,\n useChannelConnection,\n useChannelConnections,\n useChannelEndpoint,\n useCounts,\n useCreateChannelEndpoint,\n useCreateSubscription,\n useDeleteChannelEndpoint,\n useNotifications,\n useNovu,\n usePreferences,\n useRemoveSubscription,\n useSchedule,\n useSubscription,\n useSubscriptions,\n useTelegramSubscriberLink,\n useUpdateSubscription,\n} from './hooks';\n\nexport type {\n BaseProps,\n BellRenderer,\n BodyRenderer,\n DefaultInboxProps,\n DefaultProps,\n NoRendererProps,\n NotificationRendererProps,\n NotificationsRenderer,\n ReactAllAppearance,\n ReactInboxAppearance,\n ReactInboxTheme,\n ReactSubscriptionAppearance,\n ReactSubscriptionTheme,\n SubjectBodyRendererProps,\n SubjectRenderer,\n WithChildrenProps,\n} from './utils/types';\n"],"mappings":";AACA,SAAS,iBAAiB,mBAAmB,+BAA+B;AAiD5E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAuBP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
@@ -3,7 +3,7 @@ import { InboxProps } from '../components/Inbox.js';
3
3
  export * from '@novu/js';
4
4
  export { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';
5
5
  import { NovuProviderProps } from '../hooks/NovuProvider.js';
6
- import { UseAgentChatProps, UseAgentChatResult } from '../hooks/useAgentChat.js';
6
+ import { UseWebChatProps, UseWebChatResult } from '../hooks/useWebChat.js';
7
7
  import { UseCountsProps, UseCountsResult } from '../hooks/useCounts.js';
8
8
  import { UseCreateSubscriptionProps, UseCreateSubscriptionResult } from '../hooks/useCreateSubscription.js';
9
9
  import { UseNotificationsProps, UseNotificationsResult } from '../hooks/useNotifications.js';
@@ -41,7 +41,7 @@ declare function MsTeamsConnectButton(): react_jsx_runtime.JSX.Element;
41
41
  declare function MsTeamsLinkUser(): react_jsx_runtime.JSX.Element;
42
42
  declare function TelegramConnectButton(): react_jsx_runtime.JSX.Element;
43
43
  declare function useNovu(): null;
44
- declare function useAgentChat(_: UseAgentChatProps): UseAgentChatResult;
44
+ declare function useWebChat(_: UseWebChatProps): UseWebChatResult;
45
45
  declare function useCounts(_: UseCountsProps): UseCountsResult;
46
46
  declare function useNotifications(_: UseNotificationsProps): UseNotificationsResult;
47
47
  declare function usePreferences(_: UsePreferencesProps): UsePreferencesResult;
@@ -52,4 +52,4 @@ declare function useUpdateSubscription(_?: UseUpdateSubscriptionProps): UseUpdat
52
52
  declare function useRemoveSubscription(_?: UseRemoveSubscriptionProps): UseRemoveSubscriptionResult;
53
53
  declare function useSubscriptions(_: UseSubscriptionsProps): UseSubscriptionsResult;
54
54
 
55
- export { Bell, Inbox, InboxContent, InboxProps, MsTeamsConnectButton, MsTeamsLinkUser, Notifications, NovuProvider, NovuProviderProps, Preferences, SlackConnectButton, SlackLinkUser, Subscription, SubscriptionButton, SubscriptionPreferences, TelegramConnectButton, UseAgentChatProps, UseAgentChatResult, UseCountsProps, UseCountsResult, UseNotificationsProps, UseNotificationsResult, UseScheduleProps as UsePreferencesProps, UsePreferencesResult, useAgentChat, 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 };
@@ -41,21 +41,27 @@ function TelegramConnectButton() {
41
41
  function useNovu() {
42
42
  return null;
43
43
  }
44
- function useAgentChat(_) {
44
+ function useWebChat(_) {
45
45
  return {
46
46
  messages: [],
47
47
  pendingActions: [],
48
- isLoading: false,
49
- isFetching: false,
48
+ isLoading: true,
50
49
  isRunning: false,
51
50
  typing: void 0,
52
- status: "active",
53
- hasMore: false,
51
+ conversationStatus: "active",
52
+ run: { isRunning: false },
53
+ pagination: {
54
+ status: "idle",
55
+ hasMore: false,
56
+ fetchMore: () => Promise.resolve({ data: void 0, error: void 0 })
57
+ },
58
+ isRecovering: false,
59
+ catchUpError: void 0,
54
60
  refetch: () => Promise.resolve(),
55
- fetchMore: () => Promise.resolve({ data: void 0, error: void 0 }),
56
61
  sendMessage: () => Promise.resolve({ data: void 0, error: void 0 }),
57
62
  respondToAction: () => Promise.resolve({ data: void 0, error: void 0 }),
58
- sendAction: () => Promise.resolve({ data: void 0, error: void 0 })
63
+ sendAction: () => Promise.resolve({ data: void 0, error: void 0 }),
64
+ retryMessage: () => Promise.resolve({ data: void 0, error: void 0 })
59
65
  };
60
66
  }
61
67
  function useCounts(_) {
@@ -145,7 +151,6 @@ export {
145
151
  SubscriptionPreferences,
146
152
  TelegramConnectButton,
147
153
  WorkflowCriticalityEnum,
148
- useAgentChat,
149
154
  useCounts,
150
155
  useCreateSubscription,
151
156
  useNotifications,
@@ -155,6 +160,7 @@ export {
155
160
  useSchedule,
156
161
  useSubscription,
157
162
  useSubscriptions,
158
- useUpdateSubscription
163
+ useUpdateSubscription,
164
+ useWebChat
159
165
  };
160
166
  //# sourceMappingURL=index.js.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 UseAgentChatProps,\n UseAgentChatResult,\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 useAgentChat(_: UseAgentChatProps): UseAgentChatResult {\n return {\n messages: [],\n pendingActions: [],\n isLoading: false,\n isFetching: false,\n isRunning: false,\n typing: undefined,\n status: 'active',\n hasMore: false,\n refetch: () => Promise.resolve(),\n fetchMore: () => Promise.resolve({ data: undefined, error: undefined }),\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 };\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 UseAgentChatProps,\n UseAgentChatResult,\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":";AACA,SAAS,0BAA0B;AA+KnC,SAAS,iBAAiB,mBAAmB,+BAA+B;AAhJnE,SAYA,UAZA;AADF,SAAS,MAAM,OAAmB;AACvC,SAAO,oBAAC,sBAAmB;AAC7B;AAEO,SAAS,eAAe;AAAC;AAEzB,SAAS,gBAAgB;AAAC;AAE1B,SAAS,cAAc;AAAC;AAExB,SAAS,OAAO;AAAC;AAEjB,SAAS,aAAa,OAA0B;AACrD,SAAO,gCAAG,gBAAM,UAAS;AAC3B;AAEO,SAAS,eAAe;AAC7B,SAAO,oBAAC,sBAAmB;AAC7B;AAEO,SAAS,qBAAqB;AAAC;AAE/B,SAAS,0BAA0B;AAAC;AAEpC,SAAS,qBAAqB;AACnC,SAAO,oBAAC,sBAAmB;AAC7B;AAEO,SAAS,gBAAgB;AAC9B,SAAO,oBAAC,sBAAmB;AAC7B;AAEO,SAAS,uBAAuB;AACrC,SAAO,oBAAC,sBAAmB;AAC7B;AAEO,SAAS,kBAAkB;AAChC,SAAO,oBAAC,sBAAmB;AAC7B;AAEO,SAAS,wBAAwB;AACtC,SAAO,oBAAC,sBAAmB;AAC7B;AAEO,SAAS,UAAU;AACxB,SAAO;AACT;AAEO,SAAS,aAAa,GAA0C;AACrE,SAAO;AAAA,IACL,UAAU,CAAC;AAAA,IACX,gBAAgB,CAAC;AAAA,IACjB,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS,MAAM,QAAQ,QAAQ;AAAA,IAC/B,WAAW,MAAM,QAAQ,QAAQ,EAAE,MAAM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AAM,QAAQ,QAAQ;AAAA,EACjC;AACF;AAEO,SAAS,sBAAsB,IAAgC,CAAC,GAAgC;AACrG,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,OAAO;AAAA,IACP,QAAQ,MAAM,QAAQ,QAAQ,EAAE,MAAM,QAAW,OAAO,OAAU,CAAC;AAAA,EACrE;AACF;AAEO,SAAS,sBAAsB,IAAgC,CAAC,GAAgC;AACrG,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,OAAO;AAAA,IACP,QAAQ,MAAM,QAAQ,QAAQ,EAAE,MAAM,QAAW,OAAO,OAAU,CAAC;AAAA,EACrE;AACF;AAEO,SAAS,sBAAsB,IAAgC,CAAC,GAAgC;AACrG,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,OAAO;AAAA,IACP,QAAQ,MAAM,QAAQ,QAAQ,EAAE,MAAM,QAAW,OAAO,OAAU,CAAC;AAAA,EACrE;AACF;AAEO,SAAS,iBAAiB,GAAkD;AACjF,SAAO;AAAA,IACL,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,SAAS,MAAM,QAAQ,QAAQ;AAAA,EACjC;AACF;","names":[]}
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":";AACA,SAAS,0BAA0B;AAqLnC,SAAS,iBAAiB,mBAAmB,+BAA+B;AAtJnE,SAYA,UAZA;AADF,SAAS,MAAM,OAAmB;AACvC,SAAO,oBAAC,sBAAmB;AAC7B;AAEO,SAAS,eAAe;AAAC;AAEzB,SAAS,gBAAgB;AAAC;AAE1B,SAAS,cAAc;AAAC;AAExB,SAAS,OAAO;AAAC;AAEjB,SAAS,aAAa,OAA0B;AACrD,SAAO,gCAAG,gBAAM,UAAS;AAC3B;AAEO,SAAS,eAAe;AAC7B,SAAO,oBAAC,sBAAmB;AAC7B;AAEO,SAAS,qBAAqB;AAAC;AAE/B,SAAS,0BAA0B;AAAC;AAEpC,SAAS,qBAAqB;AACnC,SAAO,oBAAC,sBAAmB;AAC7B;AAEO,SAAS,gBAAgB;AAC9B,SAAO,oBAAC,sBAAmB;AAC7B;AAEO,SAAS,uBAAuB;AACrC,SAAO,oBAAC,sBAAmB;AAC7B;AAEO,SAAS,kBAAkB;AAChC,SAAO,oBAAC,sBAAmB;AAC7B;AAEO,SAAS,wBAAwB;AACtC,SAAO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CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novu/react",
3
- "version": "3.19.1-rc.68f5589d4e",
3
+ "version": "3.19.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/novuhq/novu",
@@ -121,7 +121,7 @@
121
121
  }
122
122
  },
123
123
  "dependencies": {
124
- "@novu/js": "3.19.1-rc.68f5589d4e"
124
+ "@novu/js": "3.19.1"
125
125
  },
126
126
  "nx": {
127
127
  "tags": [
@@ -130,7 +130,8 @@
130
130
  },
131
131
  "scripts": {
132
132
  "build:watch": "tsup --watch",
133
- "build": "tsup && pnpm run check-exports",
133
+ "build": "tsup && node scripts/bundle-graph.mjs && pnpm run check-exports",
134
+ "test:bundle-graph": "node ./scripts/bundle-graph.mjs",
134
135
  "check-exports": "attw --pack .",
135
136
  "check": "biome check .",
136
137
  "check:fix": "biome check --write .",
@@ -1,312 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/hooks/useAgentChat.ts
21
- var useAgentChat_exports = {};
22
- __export(useAgentChat_exports, {
23
- useAgentChat: () => useAgentChat
24
- });
25
- module.exports = __toCommonJS(useAgentChat_exports);
26
- var import_js = require("@novu/js");
27
- var import_react = require("react");
28
- var import_useDataRef = require("./internal/useDataRef.cjs");
29
- var import_NovuProvider = require("./NovuProvider.cjs");
30
- function createLocalSessionKey() {
31
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
32
- return `local_${crypto.randomUUID().replace(/-/g, "").slice(0, 12)}`;
33
- }
34
- if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
35
- const bytes = new Uint8Array(6);
36
- crypto.getRandomValues(bytes);
37
- return `local_${Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
38
- }
39
- return `local_${Date.now().toString(36)}`;
40
- }
41
- var EMPTY_CONVERSATION = {
42
- messages: [],
43
- isRunning: false,
44
- typing: void 0,
45
- status: "active",
46
- hasMore: false
47
- };
48
- function applyConversationSnapshot(snapshot, setters) {
49
- setters.setMessages(snapshot.messages);
50
- setters.setIsRunning(snapshot.isRunning);
51
- setters.setTyping(snapshot.typing);
52
- setters.setStatus(snapshot.status);
53
- setters.setHasMore(snapshot.hasMore);
54
- }
55
- var useAgentChat = (props) => {
56
- const { agentId, agentHash, conversationId: conversationIdProp } = props;
57
- const propsRef = (0, import_useDataRef.useDataRef)(props);
58
- const novu = (0, import_NovuProvider.useNovu)();
59
- const [localSessionKey, setLocalSessionKey] = (0, import_react.useState)(createLocalSessionKey);
60
- const sessionKey = conversationIdProp ?? localSessionKey;
61
- const sessionKeyRef = (0, import_useDataRef.useDataRef)(sessionKey);
62
- const prevAgentIdRef = (0, import_react.useRef)(agentId);
63
- const prevConversationIdPropRef = (0, import_react.useRef)(conversationIdProp);
64
- const [assignedConversationId, setAssignedConversationId] = (0, import_react.useState)();
65
- const conversationId = conversationIdProp ?? assignedConversationId;
66
- const conversationIdRef = (0, import_useDataRef.useDataRef)(conversationId);
67
- const [messages, setMessages] = (0, import_react.useState)([]);
68
- const [isRunning, setIsRunning] = (0, import_react.useState)(false);
69
- const [typing, setTyping] = (0, import_react.useState)();
70
- const [status, setStatus] = (0, import_react.useState)("active");
71
- const [hasMore, setHasMore] = (0, import_react.useState)(false);
72
- const [error, setError] = (0, import_react.useState)();
73
- const [isLoading, setIsLoading] = (0, import_react.useState)(Boolean(conversationIdProp));
74
- const [isFetching, setIsFetching] = (0, import_react.useState)(false);
75
- const fetchGenerationRef = (0, import_react.useRef)(0);
76
- const pendingActions = (0, import_react.useMemo)(() => (0, import_js.derivePendingActions)(messages), [messages]);
77
- const snapshotSetters = (0, import_react.useMemo)(
78
- () => ({
79
- setMessages,
80
- setIsRunning,
81
- setTyping,
82
- setStatus,
83
- setHasMore
84
- }),
85
- []
86
- );
87
- (0, import_react.useEffect)(() => {
88
- const agentChanged = prevAgentIdRef.current !== agentId;
89
- const prevConversationIdProp = prevConversationIdPropRef.current;
90
- prevAgentIdRef.current = agentId;
91
- prevConversationIdPropRef.current = conversationIdProp;
92
- if (agentChanged) {
93
- setAssignedConversationId(void 0);
94
- setLocalSessionKey(createLocalSessionKey());
95
- applyConversationSnapshot(EMPTY_CONVERSATION, snapshotSetters);
96
- setError(void 0);
97
- setIsLoading(Boolean(conversationIdProp));
98
- return;
99
- }
100
- if (conversationIdProp) {
101
- setAssignedConversationId(void 0);
102
- return;
103
- }
104
- setIsLoading(false);
105
- if (prevConversationIdProp !== void 0) {
106
- setAssignedConversationId(void 0);
107
- setLocalSessionKey(createLocalSessionKey());
108
- applyConversationSnapshot(EMPTY_CONVERSATION, snapshotSetters);
109
- }
110
- }, [agentId, conversationIdProp, snapshotSetters]);
111
- const fetchConversation = (0, import_react.useCallback)(
112
- async (targetConversationId) => {
113
- var _a, _b, _c, _d;
114
- const generation = ++fetchGenerationRef.current;
115
- setError(void 0);
116
- setIsLoading(true);
117
- setIsFetching(true);
118
- const response = await novu.agentChat.loadConversation({
119
- agentId,
120
- conversationId: targetConversationId
121
- });
122
- if (generation !== fetchGenerationRef.current) {
123
- return;
124
- }
125
- if (response.error) {
126
- setError(response.error);
127
- (_b = (_a = propsRef.current).onError) == null ? void 0 : _b.call(_a, response.error);
128
- } else if (response.data) {
129
- setMessages(response.data.messages);
130
- setHasMore(response.data.hasMore);
131
- (_d = (_c = propsRef.current).onSuccess) == null ? void 0 : _d.call(_c, response.data);
132
- }
133
- setIsLoading(false);
134
- setIsFetching(false);
135
- },
136
- [novu, agentId, propsRef]
137
- );
138
- (0, import_react.useEffect)(() => {
139
- var _a, _b;
140
- novu.agentChat.subscribe();
141
- const snapshot = novu.agentChat.getConversation({
142
- agentId,
143
- key: sessionKey,
144
- conversationId: conversationIdProp
145
- });
146
- if (snapshot) {
147
- applyConversationSnapshot(
148
- {
149
- messages: snapshot.messages,
150
- isRunning: snapshot.isRunning,
151
- typing: snapshot.typing,
152
- status: snapshot.status,
153
- hasMore: snapshot.hasMore
154
- },
155
- snapshotSetters
156
- );
157
- if (snapshot.conversationId && !conversationIdProp) {
158
- setAssignedConversationId(snapshot.conversationId);
159
- }
160
- for (const action of (0, import_js.derivePendingActions)(snapshot.messages)) {
161
- (_b = (_a = propsRef.current).onActionRequested) == null ? void 0 : _b.call(_a, action);
162
- }
163
- } else if (!conversationIdProp) {
164
- applyConversationSnapshot(EMPTY_CONVERSATION, snapshotSetters);
165
- }
166
- const cleanup = novu.on("agent_chat.messages.updated", ({ data }) => {
167
- var _a2, _b2, _c, _d, _e, _f;
168
- if (data.key !== sessionKeyRef.current) {
169
- return;
170
- }
171
- applyConversationSnapshot(
172
- {
173
- messages: data.messages,
174
- isRunning: data.isRunning,
175
- typing: data.typing,
176
- status: data.status,
177
- hasMore: data.hasMore
178
- },
179
- snapshotSetters
180
- );
181
- if (data.conversationId && !propsRef.current.conversationId) {
182
- setAssignedConversationId(data.conversationId);
183
- }
184
- const { change } = data;
185
- if (change.kind === "live") {
186
- (_b2 = (_a2 = propsRef.current).onEvent) == null ? void 0 : _b2.call(_a2, change.envelope);
187
- }
188
- if (change.kind !== "history") {
189
- for (const message of change.addedMessages) {
190
- (_d = (_c = propsRef.current).onMessage) == null ? void 0 : _d.call(_c, message);
191
- }
192
- }
193
- for (const action of change.newActions) {
194
- (_f = (_e = propsRef.current).onActionRequested) == null ? void 0 : _f.call(_e, action);
195
- }
196
- });
197
- if (conversationIdProp) {
198
- void fetchConversation(conversationIdProp);
199
- }
200
- return () => {
201
- cleanup();
202
- novu.agentChat.unsubscribe();
203
- };
204
- }, [novu, agentId, conversationIdProp, sessionKey, sessionKeyRef, propsRef, fetchConversation, snapshotSetters]);
205
- const refetch = (0, import_react.useCallback)(async () => {
206
- const id = conversationIdRef.current;
207
- if (!id) {
208
- return;
209
- }
210
- await fetchConversation(id);
211
- }, [conversationIdRef, fetchConversation]);
212
- const fetchMore = (0, import_react.useCallback)(async () => {
213
- var _a, _b;
214
- const response = await novu.agentChat.fetchMore({
215
- agentId,
216
- key: sessionKeyRef.current,
217
- conversationId: conversationIdRef.current
218
- });
219
- if (response.error) {
220
- setError(response.error);
221
- (_b = (_a = propsRef.current).onError) == null ? void 0 : _b.call(_a, response.error);
222
- } else if (response.data) {
223
- setMessages(response.data.messages);
224
- setHasMore(response.data.hasMore);
225
- }
226
- return response;
227
- }, [novu, agentId, sessionKeyRef, conversationIdRef, propsRef]);
228
- const sendMessage = (0, import_react.useCallback)(
229
- async (text) => {
230
- var _a, _b;
231
- setError(void 0);
232
- const response = await novu.agentChat.sendMessage({
233
- agentId,
234
- agentHash,
235
- text,
236
- key: sessionKeyRef.current,
237
- conversationId: conversationIdRef.current
238
- });
239
- if (response.error) {
240
- setError(response.error);
241
- (_b = (_a = propsRef.current).onError) == null ? void 0 : _b.call(_a, response.error);
242
- } else if (response.data && !propsRef.current.conversationId) {
243
- setAssignedConversationId(response.data.conversationId);
244
- }
245
- return response;
246
- },
247
- [novu, agentId, agentHash, sessionKeyRef, conversationIdRef, propsRef]
248
- );
249
- const respondToAction = (0, import_react.useCallback)(
250
- async (args) => {
251
- var _a, _b;
252
- setError(void 0);
253
- const response = await novu.agentChat.respondToAction({
254
- agentId,
255
- agentHash,
256
- key: sessionKeyRef.current,
257
- conversationId: conversationIdRef.current,
258
- actionId: args.actionId,
259
- decision: args.decision
260
- });
261
- if (response.error) {
262
- setError(response.error);
263
- (_b = (_a = propsRef.current).onError) == null ? void 0 : _b.call(_a, response.error);
264
- }
265
- return response;
266
- },
267
- [novu, agentId, agentHash, sessionKeyRef, conversationIdRef, propsRef]
268
- );
269
- const sendAction = (0, import_react.useCallback)(
270
- async (args) => {
271
- var _a, _b;
272
- setError(void 0);
273
- const response = await novu.agentChat.sendAction({
274
- agentId,
275
- agentHash,
276
- key: sessionKeyRef.current,
277
- conversationId: conversationIdRef.current,
278
- actionId: args.actionId,
279
- sourceMessageId: args.sourceMessageId,
280
- value: args.value
281
- });
282
- if (response.error) {
283
- setError(response.error);
284
- (_b = (_a = propsRef.current).onError) == null ? void 0 : _b.call(_a, response.error);
285
- }
286
- return response;
287
- },
288
- [novu, agentId, agentHash, sessionKeyRef, conversationIdRef, propsRef]
289
- );
290
- return {
291
- messages,
292
- pendingActions,
293
- sendMessage,
294
- respondToAction,
295
- sendAction,
296
- conversationId,
297
- error,
298
- isLoading,
299
- isFetching,
300
- isRunning,
301
- typing,
302
- status,
303
- hasMore,
304
- refetch,
305
- fetchMore
306
- };
307
- };
308
- // Annotate the CommonJS export names for ESM import in node:
309
- 0 && (module.exports = {
310
- useAgentChat
311
- });
312
- //# sourceMappingURL=useAgentChat.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/hooks/useAgentChat.ts"],"sourcesContent":["import type {\n AgentChatPlanLimitError,\n AgentConversationStatus,\n AgentConversationTyping,\n AgentEventEnvelope,\n AgentHashFields,\n AgentMessage,\n AgentPendingAction,\n AgentToolApprovalDecision,\n LoadConversationResult,\n NovuError,\n RespondToActionResult,\n SendActionResult,\n SendMessageResult,\n} from '@novu/js';\nimport { derivePendingActions } from '@novu/js';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { useDataRef } from './internal/useDataRef';\nimport { useNovu } from './NovuProvider';\n\nexport type UseAgentChatProps = AgentHashFields & {\n agentId: string;\n /**\n * Resume this conversation. The hook loads history on mount.\n * Omit this prop to start a new chat. The first send creates a conversation.\n * Later sends pass the returned id. Remount or clear this prop to start another chat.\n */\n conversationId?: string;\n onSuccess?: (data: LoadConversationResult) => void;\n onError?: (error: NovuError | AgentChatPlanLimitError) => void;\n /**\n * Fires once per message, when the message id first appears on the conversation.\n * History pages are silent: only new activity fires.\n * An agent message can still be empty at this point, because the first envelope of a\n * turn creates the message before any text is folded into it.\n * A send that never reaches the server does not fire: the message flips to `failed` instead.\n */\n onMessage?: (message: AgentMessage) => void;\n /**\n * Fires once per pending action, including actions still pending on mount, so a\n * resumed conversation reports what it is blocked on. Paging backwards is silent.\n */\n onActionRequested?: (action: AgentPendingAction) => void;\n /**\n * Raw envelopes for this conversation, before the derived callbacks for the same fold.\n * A duplicate envelope that the store drops does not fire. Neither does an envelope that\n * arrives before a newly created conversation claims its id.\n * The store folds the envelope before this callback runs, so `messages` here is one render old.\n */\n onEvent?: (envelope: AgentEventEnvelope) => void;\n};\n\nexport type UseAgentChatResult = {\n messages: AgentMessage[];\n pendingActions: AgentPendingAction[];\n conversationId?: string;\n error?: NovuError | AgentChatPlanLimitError;\n /** True until the first history fetch completes. False when there is no `conversationId` prop. */\n isLoading: boolean;\n isFetching: boolean;\n isRunning: boolean;\n typing?: AgentConversationTyping;\n status: AgentConversationStatus;\n /** True when older history pages are available via `fetchMore`. */\n hasMore: boolean;\n refetch: () => Promise<void>;\n fetchMore: () => Promise<{\n data?: { messages: AgentMessage[]; hasMore: boolean };\n error?: NovuError;\n }>;\n sendMessage: (text: string) => Promise<{\n data?: SendMessageResult;\n error?: NovuError | AgentChatPlanLimitError;\n }>;\n respondToAction: (args: { actionId: string; decision: AgentToolApprovalDecision }) => Promise<{\n data?: RespondToActionResult;\n error?: NovuError | AgentChatPlanLimitError;\n }>;\n sendAction: (args: { actionId: string; sourceMessageId: string; value?: string }) => Promise<{\n data?: SendActionResult;\n error?: NovuError | AgentChatPlanLimitError;\n }>;\n};\n\nfunction createLocalSessionKey(): string {\n if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n return `local_${crypto.randomUUID().replace(/-/g, '').slice(0, 12)}`;\n }\n\n if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {\n const bytes = new Uint8Array(6);\n crypto.getRandomValues(bytes);\n\n return `local_${Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('')}`;\n }\n\n return `local_${Date.now().toString(36)}`;\n}\n\ntype ConversationSnapshot = {\n messages: AgentMessage[];\n isRunning: boolean;\n typing?: AgentConversationTyping;\n status: AgentConversationStatus;\n hasMore: boolean;\n};\n\nconst EMPTY_CONVERSATION: ConversationSnapshot = {\n messages: [],\n isRunning: false,\n typing: undefined,\n status: 'active',\n hasMore: false,\n};\n\nfunction applyConversationSnapshot(\n snapshot: ConversationSnapshot,\n setters: {\n setMessages: (messages: AgentMessage[]) => void;\n setIsRunning: (isRunning: boolean) => void;\n setTyping: (typing?: AgentConversationTyping) => void;\n setStatus: (status: AgentConversationStatus) => void;\n setHasMore: (hasMore: boolean) => void;\n }\n): void {\n setters.setMessages(snapshot.messages);\n setters.setIsRunning(snapshot.isRunning);\n setters.setTyping(snapshot.typing);\n setters.setStatus(snapshot.status);\n setters.setHasMore(snapshot.hasMore);\n}\n\nexport const useAgentChat = (props: UseAgentChatProps): UseAgentChatResult => {\n const { agentId, agentHash, conversationId: conversationIdProp } = props;\n const propsRef = useDataRef(props);\n const novu = useNovu();\n\n // Resume: the prop is the key on the same render (no effect lag).\n // Create: keep a `local_*` key until remount, prop clear, or agent change.\n const [localSessionKey, setLocalSessionKey] = useState(createLocalSessionKey);\n const sessionKey = conversationIdProp ?? localSessionKey;\n const sessionKeyRef = useDataRef(sessionKey);\n const prevAgentIdRef = useRef(agentId);\n const prevConversationIdPropRef = useRef(conversationIdProp);\n\n const [assignedConversationId, setAssignedConversationId] = useState<string>();\n const conversationId = conversationIdProp ?? assignedConversationId;\n const conversationIdRef = useDataRef(conversationId);\n\n const [messages, setMessages] = useState<AgentMessage[]>([]);\n const [isRunning, setIsRunning] = useState(false);\n const [typing, setTyping] = useState<AgentConversationTyping>();\n const [status, setStatus] = useState<AgentConversationStatus>('active');\n const [hasMore, setHasMore] = useState(false);\n const [error, setError] = useState<NovuError | AgentChatPlanLimitError>();\n const [isLoading, setIsLoading] = useState(Boolean(conversationIdProp));\n const [isFetching, setIsFetching] = useState(false);\n const fetchGenerationRef = useRef(0);\n\n const pendingActions = useMemo(() => derivePendingActions(messages), [messages]);\n\n const snapshotSetters = useMemo(\n () => ({\n setMessages,\n setIsRunning,\n setTyping,\n setStatus,\n setHasMore,\n }),\n []\n );\n\n useEffect(() => {\n const agentChanged = prevAgentIdRef.current !== agentId;\n const prevConversationIdProp = prevConversationIdPropRef.current;\n prevAgentIdRef.current = agentId;\n prevConversationIdPropRef.current = conversationIdProp;\n\n if (agentChanged) {\n setAssignedConversationId(undefined);\n setLocalSessionKey(createLocalSessionKey());\n applyConversationSnapshot(EMPTY_CONVERSATION, snapshotSetters);\n setError(undefined);\n setIsLoading(Boolean(conversationIdProp));\n\n return;\n }\n\n if (conversationIdProp) {\n setAssignedConversationId(undefined);\n\n return;\n }\n\n setIsLoading(false);\n if (prevConversationIdProp !== undefined) {\n setAssignedConversationId(undefined);\n setLocalSessionKey(createLocalSessionKey());\n applyConversationSnapshot(EMPTY_CONVERSATION, snapshotSetters);\n }\n }, [agentId, conversationIdProp, snapshotSetters]);\n\n const fetchConversation = useCallback(\n async (targetConversationId: string) => {\n const generation = ++fetchGenerationRef.current;\n setError(undefined);\n setIsLoading(true);\n setIsFetching(true);\n\n const response = await novu.agentChat.loadConversation({\n agentId,\n conversationId: targetConversationId,\n });\n\n if (generation !== fetchGenerationRef.current) {\n return;\n }\n\n if (response.error) {\n setError(response.error);\n propsRef.current.onError?.(response.error);\n } else if (response.data) {\n setMessages(response.data.messages);\n setHasMore(response.data.hasMore);\n propsRef.current.onSuccess?.(response.data);\n }\n\n setIsLoading(false);\n setIsFetching(false);\n },\n [novu, agentId, propsRef]\n );\n\n useEffect(() => {\n novu.agentChat.subscribe();\n\n const snapshot = novu.agentChat.getConversation({\n agentId,\n key: sessionKey,\n conversationId: conversationIdProp,\n });\n if (snapshot) {\n applyConversationSnapshot(\n {\n messages: snapshot.messages,\n isRunning: snapshot.isRunning,\n typing: snapshot.typing,\n status: snapshot.status,\n hasMore: snapshot.hasMore,\n },\n snapshotSetters\n );\n if (snapshot.conversationId && !conversationIdProp) {\n setAssignedConversationId(snapshot.conversationId);\n }\n\n // The store reports each action once per holder, and a holder outlives a mount.\n // Replay from the snapshot so a remount still learns what the run is blocked on.\n for (const action of derivePendingActions(snapshot.messages)) {\n propsRef.current.onActionRequested?.(action);\n }\n } else if (!conversationIdProp) {\n applyConversationSnapshot(EMPTY_CONVERSATION, snapshotSetters);\n }\n\n const cleanup = novu.on('agent_chat.messages.updated', ({ data }) => {\n if (data.key !== sessionKeyRef.current) {\n return;\n }\n\n applyConversationSnapshot(\n {\n messages: data.messages,\n isRunning: data.isRunning,\n typing: data.typing,\n status: data.status,\n hasMore: data.hasMore,\n },\n snapshotSetters\n );\n if (data.conversationId && !propsRef.current.conversationId) {\n setAssignedConversationId(data.conversationId);\n }\n\n const { change } = data;\n if (change.kind === 'live') {\n propsRef.current.onEvent?.(change.envelope);\n }\n\n if (change.kind !== 'history') {\n for (const message of change.addedMessages) {\n propsRef.current.onMessage?.(message);\n }\n }\n\n for (const action of change.newActions) {\n propsRef.current.onActionRequested?.(action);\n }\n });\n\n if (conversationIdProp) {\n void fetchConversation(conversationIdProp);\n }\n\n return () => {\n cleanup();\n novu.agentChat.unsubscribe();\n };\n }, [novu, agentId, conversationIdProp, sessionKey, sessionKeyRef, propsRef, fetchConversation, snapshotSetters]);\n\n const refetch = useCallback(async () => {\n const id = conversationIdRef.current;\n if (!id) {\n return;\n }\n\n await fetchConversation(id);\n }, [conversationIdRef, fetchConversation]);\n\n const fetchMore = useCallback(async () => {\n const response = await novu.agentChat.fetchMore({\n agentId,\n key: sessionKeyRef.current,\n conversationId: conversationIdRef.current,\n });\n\n if (response.error) {\n setError(response.error);\n propsRef.current.onError?.(response.error);\n } else if (response.data) {\n setMessages(response.data.messages);\n setHasMore(response.data.hasMore);\n }\n\n return response;\n }, [novu, agentId, sessionKeyRef, conversationIdRef, propsRef]);\n\n const sendMessage = useCallback(\n async (text: string) => {\n setError(undefined);\n\n const response = await novu.agentChat.sendMessage({\n agentId,\n agentHash,\n text,\n key: sessionKeyRef.current,\n conversationId: conversationIdRef.current,\n });\n\n if (response.error) {\n setError(response.error);\n propsRef.current.onError?.(response.error);\n } else if (response.data && !propsRef.current.conversationId) {\n setAssignedConversationId(response.data.conversationId);\n }\n\n return response;\n },\n [novu, agentId, agentHash, sessionKeyRef, conversationIdRef, propsRef]\n );\n\n const respondToAction = useCallback(\n async (args: { actionId: string; decision: AgentToolApprovalDecision }) => {\n setError(undefined);\n\n const response = await novu.agentChat.respondToAction({\n agentId,\n agentHash,\n key: sessionKeyRef.current,\n conversationId: conversationIdRef.current,\n actionId: args.actionId,\n decision: args.decision,\n });\n\n if (response.error) {\n setError(response.error);\n propsRef.current.onError?.(response.error);\n }\n\n return response;\n },\n [novu, agentId, agentHash, sessionKeyRef, conversationIdRef, propsRef]\n );\n\n const sendAction = useCallback(\n async (args: { actionId: string; sourceMessageId: string; value?: string }) => {\n setError(undefined);\n\n const response = await novu.agentChat.sendAction({\n agentId,\n agentHash,\n key: sessionKeyRef.current,\n conversationId: conversationIdRef.current,\n actionId: args.actionId,\n sourceMessageId: args.sourceMessageId,\n value: args.value,\n });\n\n if (response.error) {\n setError(response.error);\n propsRef.current.onError?.(response.error);\n }\n\n return response;\n },\n [novu, agentId, agentHash, sessionKeyRef, conversationIdRef, propsRef]\n );\n\n return {\n messages,\n pendingActions,\n sendMessage,\n respondToAction,\n sendAction,\n conversationId,\n error,\n isLoading,\n isFetching,\n isRunning,\n typing,\n status,\n hasMore,\n refetch,\n fetchMore,\n };\n};\n"],"mappings":";;;;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AAI,SAAS,OAAO;AAClB,iBAAS,SAAS,KAAK;AACvB,6BAAS,SAAQ,YAAjB,4BAA2B,SAAS;AAAA,MACtC;AAEA,aAAO;AAAA,IACT;AAAA,IACA,CAAC,MAAM,SAAS,WAAW,eAAe,mBAAmB,QAAQ;AAAA,EACvE;AAEA,QAAM,iBAAa;AAAA,IACjB,OAAO,SAAwE;AAjYnF;AAkYM,eAAS,MAAS;AAElB,YAAM,WAAW,MAAM,KAAK,UAAU,WAAW;AAAA,QAC/C;AAAA,QACA;AAAA,QACA,KAAK,cAAc;AAAA,QACnB,gBAAgB,kBAAkB;AAAA,QAClC,UAAU,KAAK;AAAA,QACf,iBAAiB,KAAK;AAAA,QACtB,OAAO,KAAK;AAAA,MACd,CAAC;AAED,UAAI,SAAS,OAAO;AAClB,iBAAS,SAAS,KAAK;AACvB,6BAAS,SAAQ,YAAjB,4BAA2B,SAAS;AAAA,MACtC;AAEA,aAAO;AAAA,IACT;AAAA,IACA,CAAC,MAAM,SAAS,WAAW,eAAe,mBAAmB,QAAQ;AAAA,EACvE;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["_a","_b"]}
@@ -1,77 +0,0 @@
1
- import { AgentHashFields, LoadConversationResult, NovuError, AgentChatPlanLimitError, AgentMessage, AgentPendingAction, AgentEventEnvelope, AgentConversationTyping, AgentConversationStatus, SendMessageResult, AgentToolApprovalDecision, RespondToActionResult, SendActionResult } from '@novu/js';
2
-
3
- type UseAgentChatProps = AgentHashFields & {
4
- agentId: string;
5
- /**
6
- * Resume this conversation. The hook loads history on mount.
7
- * Omit this prop to start a new chat. The first send creates a conversation.
8
- * Later sends pass the returned id. Remount or clear this prop to start another chat.
9
- */
10
- conversationId?: string;
11
- onSuccess?: (data: LoadConversationResult) => void;
12
- onError?: (error: NovuError | AgentChatPlanLimitError) => void;
13
- /**
14
- * Fires once per message, when the message id first appears on the conversation.
15
- * History pages are silent: only new activity fires.
16
- * An agent message can still be empty at this point, because the first envelope of a
17
- * turn creates the message before any text is folded into it.
18
- * A send that never reaches the server does not fire: the message flips to `failed` instead.
19
- */
20
- onMessage?: (message: AgentMessage) => void;
21
- /**
22
- * Fires once per pending action, including actions still pending on mount, so a
23
- * resumed conversation reports what it is blocked on. Paging backwards is silent.
24
- */
25
- onActionRequested?: (action: AgentPendingAction) => void;
26
- /**
27
- * Raw envelopes for this conversation, before the derived callbacks for the same fold.
28
- * A duplicate envelope that the store drops does not fire. Neither does an envelope that
29
- * arrives before a newly created conversation claims its id.
30
- * The store folds the envelope before this callback runs, so `messages` here is one render old.
31
- */
32
- onEvent?: (envelope: AgentEventEnvelope) => void;
33
- };
34
- type UseAgentChatResult = {
35
- messages: AgentMessage[];
36
- pendingActions: AgentPendingAction[];
37
- conversationId?: string;
38
- error?: NovuError | AgentChatPlanLimitError;
39
- /** True until the first history fetch completes. False when there is no `conversationId` prop. */
40
- isLoading: boolean;
41
- isFetching: boolean;
42
- isRunning: boolean;
43
- typing?: AgentConversationTyping;
44
- status: AgentConversationStatus;
45
- /** True when older history pages are available via `fetchMore`. */
46
- hasMore: boolean;
47
- refetch: () => Promise<void>;
48
- fetchMore: () => Promise<{
49
- data?: {
50
- messages: AgentMessage[];
51
- hasMore: boolean;
52
- };
53
- error?: NovuError;
54
- }>;
55
- sendMessage: (text: string) => Promise<{
56
- data?: SendMessageResult;
57
- error?: NovuError | AgentChatPlanLimitError;
58
- }>;
59
- respondToAction: (args: {
60
- actionId: string;
61
- decision: AgentToolApprovalDecision;
62
- }) => Promise<{
63
- data?: RespondToActionResult;
64
- error?: NovuError | AgentChatPlanLimitError;
65
- }>;
66
- sendAction: (args: {
67
- actionId: string;
68
- sourceMessageId: string;
69
- value?: string;
70
- }) => Promise<{
71
- data?: SendActionResult;
72
- error?: NovuError | AgentChatPlanLimitError;
73
- }>;
74
- };
75
- declare const useAgentChat: (props: UseAgentChatProps) => UseAgentChatResult;
76
-
77
- export { type UseAgentChatProps, type UseAgentChatResult, useAgentChat };