@novu/react 3.19.1-rc.68f5589d4e → 3.19.1-rc.852194fa77
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/hooks/useAgentChat.cjs +213 -250
- package/dist/cjs/hooks/useAgentChat.cjs.map +1 -1
- package/dist/cjs/hooks/useAgentChat.d.cts +41 -20
- package/dist/cjs/server/index.cjs +11 -4
- package/dist/cjs/server/index.cjs.map +1 -1
- package/dist/esm/hooks/useAgentChat.d.ts +41 -20
- package/dist/esm/hooks/useAgentChat.js +207 -243
- package/dist/esm/hooks/useAgentChat.js.map +1 -1
- package/dist/esm/server/index.js +11 -4
- package/dist/esm/server/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LoadConversationResult, NovuError, AgentChatPlanLimitError, AgentMessage, AgentPendingAction, AgentEventEnvelope, AgentHashFields, AgentConversationRuntime, AgentConversationRunSnapshot, AgentConversationStatus, AgentChatPagination, SendMessageResult, AgentToolApprovalDecision, RespondToActionResult, SendActionResult } from '@novu/js';
|
|
2
2
|
|
|
3
|
-
type
|
|
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;
|
|
3
|
+
type UseAgentChatCallbacks = {
|
|
11
4
|
onSuccess?: (data: LoadConversationResult) => void;
|
|
12
5
|
onError?: (error: NovuError | AgentChatPlanLimitError) => void;
|
|
13
6
|
/**
|
|
@@ -31,6 +24,22 @@ type UseAgentChatProps = AgentHashFields & {
|
|
|
31
24
|
*/
|
|
32
25
|
onEvent?: (envelope: AgentEventEnvelope) => void;
|
|
33
26
|
};
|
|
27
|
+
type UseAgentChatProps = UseAgentChatCallbacks & AgentHashFields & ({
|
|
28
|
+
agentId: string;
|
|
29
|
+
/**
|
|
30
|
+
* Resume this conversation. The hook loads history on mount.
|
|
31
|
+
* Omit this prop to start a new chat. The first send creates a conversation.
|
|
32
|
+
* Later sends pass the returned id. Remount or clear this prop to start another chat.
|
|
33
|
+
*/
|
|
34
|
+
conversationId?: string;
|
|
35
|
+
conversation?: never;
|
|
36
|
+
} | {
|
|
37
|
+
/** Share an existing conversation runtime across multiple hook instances. */
|
|
38
|
+
conversation: AgentConversationRuntime;
|
|
39
|
+
agentId?: never;
|
|
40
|
+
conversationId?: never;
|
|
41
|
+
agentHash?: never;
|
|
42
|
+
});
|
|
34
43
|
type UseAgentChatResult = {
|
|
35
44
|
messages: AgentMessage[];
|
|
36
45
|
pendingActions: AgentPendingAction[];
|
|
@@ -38,20 +47,28 @@ type UseAgentChatResult = {
|
|
|
38
47
|
error?: NovuError | AgentChatPlanLimitError;
|
|
39
48
|
/** True until the first history fetch completes. False when there is no `conversationId` prop. */
|
|
40
49
|
isLoading: boolean;
|
|
41
|
-
isFetching: boolean;
|
|
42
50
|
isRunning: boolean;
|
|
43
|
-
typing?:
|
|
51
|
+
typing?: AgentConversationRunSnapshot['typing'];
|
|
52
|
+
/** Conversation lifecycle status (`active`, etc.). */
|
|
44
53
|
status: AgentConversationStatus;
|
|
45
|
-
/**
|
|
46
|
-
|
|
54
|
+
/** Explicit alias for `status`. */
|
|
55
|
+
conversationStatus: AgentConversationStatus;
|
|
56
|
+
/** Current agent run snapshot. */
|
|
57
|
+
run: AgentConversationRunSnapshot;
|
|
58
|
+
pagination: AgentChatPagination & {
|
|
59
|
+
fetchMore: () => Promise<{
|
|
60
|
+
data?: {
|
|
61
|
+
messages: AgentMessage[];
|
|
62
|
+
hasMore: boolean;
|
|
63
|
+
};
|
|
64
|
+
error?: NovuError;
|
|
65
|
+
}>;
|
|
66
|
+
};
|
|
67
|
+
/** True while reconnect catch-up is in flight for this conversation. */
|
|
68
|
+
isRecovering: boolean;
|
|
69
|
+
/** Set when reconnect catch-up fails. Separate from send/fetch `error`. */
|
|
70
|
+
catchUpError?: NovuError;
|
|
47
71
|
refetch: () => Promise<void>;
|
|
48
|
-
fetchMore: () => Promise<{
|
|
49
|
-
data?: {
|
|
50
|
-
messages: AgentMessage[];
|
|
51
|
-
hasMore: boolean;
|
|
52
|
-
};
|
|
53
|
-
error?: NovuError;
|
|
54
|
-
}>;
|
|
55
72
|
sendMessage: (text: string) => Promise<{
|
|
56
73
|
data?: SendMessageResult;
|
|
57
74
|
error?: NovuError | AgentChatPlanLimitError;
|
|
@@ -71,6 +88,10 @@ type UseAgentChatResult = {
|
|
|
71
88
|
data?: SendActionResult;
|
|
72
89
|
error?: NovuError | AgentChatPlanLimitError;
|
|
73
90
|
}>;
|
|
91
|
+
retryMessage: (messageId: string) => Promise<{
|
|
92
|
+
data?: SendMessageResult;
|
|
93
|
+
error?: NovuError | AgentChatPlanLimitError;
|
|
94
|
+
}>;
|
|
74
95
|
};
|
|
75
96
|
declare const useAgentChat: (props: UseAgentChatProps) => UseAgentChatResult;
|
|
76
97
|
|
|
@@ -97,16 +97,23 @@ function useAgentChat(_) {
|
|
|
97
97
|
messages: [],
|
|
98
98
|
pendingActions: [],
|
|
99
99
|
isLoading: false,
|
|
100
|
-
isFetching: false,
|
|
101
100
|
isRunning: false,
|
|
102
101
|
typing: void 0,
|
|
103
102
|
status: "active",
|
|
104
|
-
|
|
103
|
+
conversationStatus: "active",
|
|
104
|
+
run: { isRunning: false },
|
|
105
|
+
pagination: {
|
|
106
|
+
status: "idle",
|
|
107
|
+
hasMore: false,
|
|
108
|
+
fetchMore: () => Promise.resolve({ data: void 0, error: void 0 })
|
|
109
|
+
},
|
|
110
|
+
isRecovering: false,
|
|
111
|
+
catchUpError: void 0,
|
|
105
112
|
refetch: () => Promise.resolve(),
|
|
106
|
-
fetchMore: () => Promise.resolve({ data: void 0, error: void 0 }),
|
|
107
113
|
sendMessage: () => Promise.resolve({ data: void 0, error: void 0 }),
|
|
108
114
|
respondToAction: () => Promise.resolve({ data: void 0, error: void 0 }),
|
|
109
|
-
sendAction: () => Promise.resolve({ data: void 0, error: void 0 })
|
|
115
|
+
sendAction: () => Promise.resolve({ data: void 0, error: void 0 }),
|
|
116
|
+
retryMessage: () => Promise.resolve({ data: void 0, error: void 0 })
|
|
110
117
|
};
|
|
111
118
|
}
|
|
112
119
|
function useCounts(_) {
|
|
@@ -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
|
|
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 isRunning: false,\n typing: undefined,\n status: 'active',\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 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,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C;AACF;AAEO,SAAS,YAAY,GAAwC;AAClE,SAAO;AAAA,IACL,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,SAAS,MAAM,QAAQ,QAAQ;AAAA,EACjC;AACF;AAEO,SAAS,gBAAgB,GAAgD;AAC9E,SAAO;AAAA,IACL,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,SAAS,MAAM,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,13 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LoadConversationResult, NovuError, AgentChatPlanLimitError, AgentMessage, AgentPendingAction, AgentEventEnvelope, AgentHashFields, AgentConversationRuntime, AgentConversationRunSnapshot, AgentConversationStatus, AgentChatPagination, SendMessageResult, AgentToolApprovalDecision, RespondToActionResult, SendActionResult } from '@novu/js';
|
|
2
2
|
|
|
3
|
-
type
|
|
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;
|
|
3
|
+
type UseAgentChatCallbacks = {
|
|
11
4
|
onSuccess?: (data: LoadConversationResult) => void;
|
|
12
5
|
onError?: (error: NovuError | AgentChatPlanLimitError) => void;
|
|
13
6
|
/**
|
|
@@ -31,6 +24,22 @@ type UseAgentChatProps = AgentHashFields & {
|
|
|
31
24
|
*/
|
|
32
25
|
onEvent?: (envelope: AgentEventEnvelope) => void;
|
|
33
26
|
};
|
|
27
|
+
type UseAgentChatProps = UseAgentChatCallbacks & AgentHashFields & ({
|
|
28
|
+
agentId: string;
|
|
29
|
+
/**
|
|
30
|
+
* Resume this conversation. The hook loads history on mount.
|
|
31
|
+
* Omit this prop to start a new chat. The first send creates a conversation.
|
|
32
|
+
* Later sends pass the returned id. Remount or clear this prop to start another chat.
|
|
33
|
+
*/
|
|
34
|
+
conversationId?: string;
|
|
35
|
+
conversation?: never;
|
|
36
|
+
} | {
|
|
37
|
+
/** Share an existing conversation runtime across multiple hook instances. */
|
|
38
|
+
conversation: AgentConversationRuntime;
|
|
39
|
+
agentId?: never;
|
|
40
|
+
conversationId?: never;
|
|
41
|
+
agentHash?: never;
|
|
42
|
+
});
|
|
34
43
|
type UseAgentChatResult = {
|
|
35
44
|
messages: AgentMessage[];
|
|
36
45
|
pendingActions: AgentPendingAction[];
|
|
@@ -38,20 +47,28 @@ type UseAgentChatResult = {
|
|
|
38
47
|
error?: NovuError | AgentChatPlanLimitError;
|
|
39
48
|
/** True until the first history fetch completes. False when there is no `conversationId` prop. */
|
|
40
49
|
isLoading: boolean;
|
|
41
|
-
isFetching: boolean;
|
|
42
50
|
isRunning: boolean;
|
|
43
|
-
typing?:
|
|
51
|
+
typing?: AgentConversationRunSnapshot['typing'];
|
|
52
|
+
/** Conversation lifecycle status (`active`, etc.). */
|
|
44
53
|
status: AgentConversationStatus;
|
|
45
|
-
/**
|
|
46
|
-
|
|
54
|
+
/** Explicit alias for `status`. */
|
|
55
|
+
conversationStatus: AgentConversationStatus;
|
|
56
|
+
/** Current agent run snapshot. */
|
|
57
|
+
run: AgentConversationRunSnapshot;
|
|
58
|
+
pagination: AgentChatPagination & {
|
|
59
|
+
fetchMore: () => Promise<{
|
|
60
|
+
data?: {
|
|
61
|
+
messages: AgentMessage[];
|
|
62
|
+
hasMore: boolean;
|
|
63
|
+
};
|
|
64
|
+
error?: NovuError;
|
|
65
|
+
}>;
|
|
66
|
+
};
|
|
67
|
+
/** True while reconnect catch-up is in flight for this conversation. */
|
|
68
|
+
isRecovering: boolean;
|
|
69
|
+
/** Set when reconnect catch-up fails. Separate from send/fetch `error`. */
|
|
70
|
+
catchUpError?: NovuError;
|
|
47
71
|
refetch: () => Promise<void>;
|
|
48
|
-
fetchMore: () => Promise<{
|
|
49
|
-
data?: {
|
|
50
|
-
messages: AgentMessage[];
|
|
51
|
-
hasMore: boolean;
|
|
52
|
-
};
|
|
53
|
-
error?: NovuError;
|
|
54
|
-
}>;
|
|
55
72
|
sendMessage: (text: string) => Promise<{
|
|
56
73
|
data?: SendMessageResult;
|
|
57
74
|
error?: NovuError | AgentChatPlanLimitError;
|
|
@@ -71,6 +88,10 @@ type UseAgentChatResult = {
|
|
|
71
88
|
data?: SendActionResult;
|
|
72
89
|
error?: NovuError | AgentChatPlanLimitError;
|
|
73
90
|
}>;
|
|
91
|
+
retryMessage: (messageId: string) => Promise<{
|
|
92
|
+
data?: SendMessageResult;
|
|
93
|
+
error?: NovuError | AgentChatPlanLimitError;
|
|
94
|
+
}>;
|
|
74
95
|
};
|
|
75
96
|
declare const useAgentChat: (props: UseAgentChatProps) => UseAgentChatResult;
|
|
76
97
|
|