@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.
@@ -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 };
@@ -1,280 +0,0 @@
1
- // src/hooks/useAgentChat.ts
2
- import { derivePendingActions } from "@novu/js";
3
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
- import { useDataRef } from "./internal/useDataRef.js";
5
- import { useNovu } from "./NovuProvider.js";
6
- function createLocalSessionKey() {
7
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
8
- return `local_${crypto.randomUUID().replace(/-/g, "").slice(0, 12)}`;
9
- }
10
- if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
11
- const bytes = new Uint8Array(6);
12
- crypto.getRandomValues(bytes);
13
- return `local_${Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
14
- }
15
- return `local_${Date.now().toString(36)}`;
16
- }
17
- var EMPTY_CONVERSATION = {
18
- messages: [],
19
- isRunning: false,
20
- typing: void 0,
21
- status: "active",
22
- hasMore: false
23
- };
24
- function applyConversationSnapshot(snapshot, setters) {
25
- setters.setMessages(snapshot.messages);
26
- setters.setIsRunning(snapshot.isRunning);
27
- setters.setTyping(snapshot.typing);
28
- setters.setStatus(snapshot.status);
29
- setters.setHasMore(snapshot.hasMore);
30
- }
31
- var useAgentChat = (props) => {
32
- const { agentId, agentHash, conversationId: conversationIdProp } = props;
33
- const propsRef = useDataRef(props);
34
- const novu = useNovu();
35
- const [localSessionKey, setLocalSessionKey] = useState(createLocalSessionKey);
36
- const sessionKey = conversationIdProp ?? localSessionKey;
37
- const sessionKeyRef = useDataRef(sessionKey);
38
- const prevAgentIdRef = useRef(agentId);
39
- const prevConversationIdPropRef = useRef(conversationIdProp);
40
- const [assignedConversationId, setAssignedConversationId] = useState();
41
- const conversationId = conversationIdProp ?? assignedConversationId;
42
- const conversationIdRef = useDataRef(conversationId);
43
- const [messages, setMessages] = useState([]);
44
- const [isRunning, setIsRunning] = useState(false);
45
- const [typing, setTyping] = useState();
46
- const [status, setStatus] = useState("active");
47
- const [hasMore, setHasMore] = useState(false);
48
- const [error, setError] = useState();
49
- const [isLoading, setIsLoading] = useState(Boolean(conversationIdProp));
50
- const [isFetching, setIsFetching] = useState(false);
51
- const fetchGenerationRef = useRef(0);
52
- const pendingActions = useMemo(() => derivePendingActions(messages), [messages]);
53
- const snapshotSetters = useMemo(
54
- () => ({
55
- setMessages,
56
- setIsRunning,
57
- setTyping,
58
- setStatus,
59
- setHasMore
60
- }),
61
- []
62
- );
63
- useEffect(() => {
64
- const agentChanged = prevAgentIdRef.current !== agentId;
65
- const prevConversationIdProp = prevConversationIdPropRef.current;
66
- prevAgentIdRef.current = agentId;
67
- prevConversationIdPropRef.current = conversationIdProp;
68
- if (agentChanged) {
69
- setAssignedConversationId(void 0);
70
- setLocalSessionKey(createLocalSessionKey());
71
- applyConversationSnapshot(EMPTY_CONVERSATION, snapshotSetters);
72
- setError(void 0);
73
- setIsLoading(Boolean(conversationIdProp));
74
- return;
75
- }
76
- if (conversationIdProp) {
77
- setAssignedConversationId(void 0);
78
- return;
79
- }
80
- setIsLoading(false);
81
- if (prevConversationIdProp !== void 0) {
82
- setAssignedConversationId(void 0);
83
- setLocalSessionKey(createLocalSessionKey());
84
- applyConversationSnapshot(EMPTY_CONVERSATION, snapshotSetters);
85
- }
86
- }, [agentId, conversationIdProp, snapshotSetters]);
87
- const fetchConversation = useCallback(
88
- async (targetConversationId) => {
89
- const generation = ++fetchGenerationRef.current;
90
- setError(void 0);
91
- setIsLoading(true);
92
- setIsFetching(true);
93
- const response = await novu.agentChat.loadConversation({
94
- agentId,
95
- conversationId: targetConversationId
96
- });
97
- if (generation !== fetchGenerationRef.current) {
98
- return;
99
- }
100
- if (response.error) {
101
- setError(response.error);
102
- propsRef.current.onError?.(response.error);
103
- } else if (response.data) {
104
- setMessages(response.data.messages);
105
- setHasMore(response.data.hasMore);
106
- propsRef.current.onSuccess?.(response.data);
107
- }
108
- setIsLoading(false);
109
- setIsFetching(false);
110
- },
111
- [novu, agentId, propsRef]
112
- );
113
- useEffect(() => {
114
- novu.agentChat.subscribe();
115
- const snapshot = novu.agentChat.getConversation({
116
- agentId,
117
- key: sessionKey,
118
- conversationId: conversationIdProp
119
- });
120
- if (snapshot) {
121
- applyConversationSnapshot(
122
- {
123
- messages: snapshot.messages,
124
- isRunning: snapshot.isRunning,
125
- typing: snapshot.typing,
126
- status: snapshot.status,
127
- hasMore: snapshot.hasMore
128
- },
129
- snapshotSetters
130
- );
131
- if (snapshot.conversationId && !conversationIdProp) {
132
- setAssignedConversationId(snapshot.conversationId);
133
- }
134
- for (const action of derivePendingActions(snapshot.messages)) {
135
- propsRef.current.onActionRequested?.(action);
136
- }
137
- } else if (!conversationIdProp) {
138
- applyConversationSnapshot(EMPTY_CONVERSATION, snapshotSetters);
139
- }
140
- const cleanup = novu.on("agent_chat.messages.updated", ({ data }) => {
141
- if (data.key !== sessionKeyRef.current) {
142
- return;
143
- }
144
- applyConversationSnapshot(
145
- {
146
- messages: data.messages,
147
- isRunning: data.isRunning,
148
- typing: data.typing,
149
- status: data.status,
150
- hasMore: data.hasMore
151
- },
152
- snapshotSetters
153
- );
154
- if (data.conversationId && !propsRef.current.conversationId) {
155
- setAssignedConversationId(data.conversationId);
156
- }
157
- const { change } = data;
158
- if (change.kind === "live") {
159
- propsRef.current.onEvent?.(change.envelope);
160
- }
161
- if (change.kind !== "history") {
162
- for (const message of change.addedMessages) {
163
- propsRef.current.onMessage?.(message);
164
- }
165
- }
166
- for (const action of change.newActions) {
167
- propsRef.current.onActionRequested?.(action);
168
- }
169
- });
170
- if (conversationIdProp) {
171
- void fetchConversation(conversationIdProp);
172
- }
173
- return () => {
174
- cleanup();
175
- novu.agentChat.unsubscribe();
176
- };
177
- }, [novu, agentId, conversationIdProp, sessionKey, sessionKeyRef, propsRef, fetchConversation, snapshotSetters]);
178
- const refetch = useCallback(async () => {
179
- const id = conversationIdRef.current;
180
- if (!id) {
181
- return;
182
- }
183
- await fetchConversation(id);
184
- }, [conversationIdRef, fetchConversation]);
185
- const fetchMore = useCallback(async () => {
186
- const response = await novu.agentChat.fetchMore({
187
- agentId,
188
- key: sessionKeyRef.current,
189
- conversationId: conversationIdRef.current
190
- });
191
- if (response.error) {
192
- setError(response.error);
193
- propsRef.current.onError?.(response.error);
194
- } else if (response.data) {
195
- setMessages(response.data.messages);
196
- setHasMore(response.data.hasMore);
197
- }
198
- return response;
199
- }, [novu, agentId, sessionKeyRef, conversationIdRef, propsRef]);
200
- const sendMessage = useCallback(
201
- async (text) => {
202
- setError(void 0);
203
- const response = await novu.agentChat.sendMessage({
204
- agentId,
205
- agentHash,
206
- text,
207
- key: sessionKeyRef.current,
208
- conversationId: conversationIdRef.current
209
- });
210
- if (response.error) {
211
- setError(response.error);
212
- propsRef.current.onError?.(response.error);
213
- } else if (response.data && !propsRef.current.conversationId) {
214
- setAssignedConversationId(response.data.conversationId);
215
- }
216
- return response;
217
- },
218
- [novu, agentId, agentHash, sessionKeyRef, conversationIdRef, propsRef]
219
- );
220
- const respondToAction = useCallback(
221
- async (args) => {
222
- setError(void 0);
223
- const response = await novu.agentChat.respondToAction({
224
- agentId,
225
- agentHash,
226
- key: sessionKeyRef.current,
227
- conversationId: conversationIdRef.current,
228
- actionId: args.actionId,
229
- decision: args.decision
230
- });
231
- if (response.error) {
232
- setError(response.error);
233
- propsRef.current.onError?.(response.error);
234
- }
235
- return response;
236
- },
237
- [novu, agentId, agentHash, sessionKeyRef, conversationIdRef, propsRef]
238
- );
239
- const sendAction = useCallback(
240
- async (args) => {
241
- setError(void 0);
242
- const response = await novu.agentChat.sendAction({
243
- agentId,
244
- agentHash,
245
- key: sessionKeyRef.current,
246
- conversationId: conversationIdRef.current,
247
- actionId: args.actionId,
248
- sourceMessageId: args.sourceMessageId,
249
- value: args.value
250
- });
251
- if (response.error) {
252
- setError(response.error);
253
- propsRef.current.onError?.(response.error);
254
- }
255
- return response;
256
- },
257
- [novu, agentId, agentHash, sessionKeyRef, conversationIdRef, propsRef]
258
- );
259
- return {
260
- messages,
261
- pendingActions,
262
- sendMessage,
263
- respondToAction,
264
- sendAction,
265
- conversationId,
266
- error,
267
- isLoading,
268
- isFetching,
269
- isRunning,
270
- typing,
271
- status,
272
- hasMore,
273
- refetch,
274
- fetchMore
275
- };
276
- };
277
- export {
278
- useAgentChat
279
- };
280
- //# sourceMappingURL=useAgentChat.js.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":";AAeA,S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