@djangocfg/layouts 2.0.4 → 2.0.6
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/README.md +138 -20
- package/package.json +20 -5
- package/src/components/RedirectPage/RedirectPage.tsx +70 -0
- package/src/components/RedirectPage/index.ts +7 -0
- package/src/components/core/index.ts +10 -0
- package/src/components/errors/ErrorLayout.tsx +228 -0
- package/src/components/errors/errorConfig.ts +118 -0
- package/src/components/errors/index.ts +10 -0
- package/src/components/index.ts +13 -5
- package/src/contexts/LeadsContext.tsx +156 -0
- package/src/contexts/NewsletterContext.tsx +263 -0
- package/src/contexts/SupportContext.tsx +256 -0
- package/src/contexts/index.ts +59 -0
- package/src/contexts/knowbase/ChatContext.tsx +174 -0
- package/src/contexts/knowbase/DocumentsContext.tsx +304 -0
- package/src/contexts/knowbase/SessionsContext.tsx +174 -0
- package/src/contexts/knowbase/index.ts +61 -0
- package/src/contexts/payments/BalancesContext.tsx +65 -0
- package/src/contexts/payments/CurrenciesContext.tsx +66 -0
- package/src/contexts/payments/OverviewContext.tsx +174 -0
- package/src/contexts/payments/PaymentsContext.tsx +132 -0
- package/src/contexts/payments/README.md +201 -0
- package/src/contexts/payments/RootPaymentsContext.tsx +68 -0
- package/src/contexts/payments/index.ts +50 -0
- package/src/index.ts +8 -0
- package/src/layouts/AppLayout/AppLayout.tsx +24 -14
- package/src/layouts/PaymentsLayout/PaymentsLayout.tsx +1 -1
- package/src/layouts/PaymentsLayout/components/CreatePaymentDialog.tsx +1 -1
- package/src/layouts/PaymentsLayout/views/overview/components/BalanceCard.tsx +1 -1
- package/src/layouts/PaymentsLayout/views/overview/components/RecentPayments.tsx +1 -1
- package/src/layouts/PaymentsLayout/views/transactions/components/TransactionsList.tsx +1 -1
- package/src/layouts/ProfileLayout/components/ProfileForm.tsx +1 -1
- package/src/layouts/SupportLayout/SupportLayout.tsx +1 -1
- package/src/layouts/SupportLayout/components/TicketCard.tsx +1 -1
- package/src/layouts/SupportLayout/context/SupportLayoutContext.tsx +1 -1
- package/src/layouts/SupportLayout/index.ts +2 -0
- package/src/layouts/SupportLayout/types.ts +2 -4
- package/src/pages/index.ts +6 -0
- package/src/pages/legal/LegalPage.tsx +85 -0
- package/src/pages/legal/configs.ts +131 -0
- package/src/pages/legal/index.ts +24 -0
- package/src/pages/legal/pages.tsx +58 -0
- package/src/pages/legal/types.ts +15 -0
- package/src/snippets/Chat/ChatWidget.tsx +1 -1
- package/src/snippets/Chat/components/SessionList.tsx +1 -1
- package/src/snippets/Chat/index.tsx +1 -1
- package/src/snippets/Chat/types.ts +7 -5
- package/src/snippets/ContactForm/ContactForm.tsx +20 -8
- package/src/utils/index.ts +1 -0
- package/src/utils/og-image.ts +169 -0
- /package/src/components/{JsonLd.tsx → core/JsonLd.tsx} +0 -0
- /package/src/components/{LucideIcon.tsx → core/LucideIcon.tsx} +0 -0
- /package/src/components/{PageProgress.tsx → core/PageProgress.tsx} +0 -0
- /package/src/components/{Suspense.tsx → core/Suspense.tsx} +0 -0
- /package/src/components/{ErrorBoundary.tsx → errors/ErrorBoundary.tsx} +0 -0
- /package/src/components/{ErrorsTracker → errors/ErrorsTracker}/README.md +0 -0
- /package/src/components/{ErrorsTracker → errors/ErrorsTracker}/components/ErrorButtons.tsx +0 -0
- /package/src/components/{ErrorsTracker → errors/ErrorsTracker}/components/ErrorToast.tsx +0 -0
- /package/src/components/{ErrorsTracker → errors/ErrorsTracker}/hooks.ts +0 -0
- /package/src/components/{ErrorsTracker → errors/ErrorsTracker}/index.ts +0 -0
- /package/src/components/{ErrorsTracker → errors/ErrorsTracker}/providers/ErrorTrackingProvider.tsx +0 -0
- /package/src/components/{ErrorsTracker → errors/ErrorsTracker}/types.ts +0 -0
- /package/src/components/{ErrorsTracker → errors/ErrorsTracker}/utils/curl-generator.ts +0 -0
- /package/src/components/{ErrorsTracker → errors/ErrorsTracker}/utils/formatters.ts +0 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { createContext, useContext, type ReactNode } from 'react';
|
|
4
|
+
import { api } from '@djangocfg/api';
|
|
5
|
+
import {
|
|
6
|
+
useSupportTicketsList,
|
|
7
|
+
useSupportTicketsRetrieve,
|
|
8
|
+
useCreateSupportTicketsCreate,
|
|
9
|
+
useUpdateSupportTicketsUpdate,
|
|
10
|
+
usePartialUpdateSupportTicketsPartialUpdate,
|
|
11
|
+
useDeleteSupportTicketsDestroy,
|
|
12
|
+
useSupportTicketsMessagesList,
|
|
13
|
+
useSupportTicketsMessagesRetrieve,
|
|
14
|
+
useCreateSupportTicketsMessagesCreate,
|
|
15
|
+
useUpdateSupportTicketsMessagesUpdate,
|
|
16
|
+
usePartialUpdateSupportTicketsMessagesPartialUpdate,
|
|
17
|
+
useDeleteSupportTicketsMessagesDestroy,
|
|
18
|
+
} from '@djangocfg/api';
|
|
19
|
+
import type { API } from '@djangocfg/api';
|
|
20
|
+
import type {
|
|
21
|
+
Ticket,
|
|
22
|
+
TicketRequest,
|
|
23
|
+
PatchedTicketRequest,
|
|
24
|
+
Message,
|
|
25
|
+
MessageRequest,
|
|
26
|
+
MessageCreateRequest,
|
|
27
|
+
PatchedMessageRequest,
|
|
28
|
+
} from '@djangocfg/api';
|
|
29
|
+
|
|
30
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
31
|
+
// Context Type
|
|
32
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
33
|
+
|
|
34
|
+
export interface SupportContextValue {
|
|
35
|
+
// Tickets
|
|
36
|
+
tickets: Ticket[] | undefined;
|
|
37
|
+
isLoadingTickets: boolean;
|
|
38
|
+
ticketsError: Error | undefined;
|
|
39
|
+
refreshTickets: () => Promise<void>;
|
|
40
|
+
|
|
41
|
+
// Ticket operations
|
|
42
|
+
getTicket: (uuid: string) => Promise<Ticket | undefined>;
|
|
43
|
+
createTicket: (data: TicketRequest) => Promise<Ticket>;
|
|
44
|
+
updateTicket: (uuid: string, data: TicketRequest) => Promise<Ticket>;
|
|
45
|
+
partialUpdateTicket: (uuid: string, data: PatchedTicketRequest) => Promise<Ticket>;
|
|
46
|
+
deleteTicket: (uuid: string) => Promise<void>;
|
|
47
|
+
|
|
48
|
+
// Messages
|
|
49
|
+
getMessages: (ticketUuid: string) => Promise<Message[] | undefined>;
|
|
50
|
+
getMessage: (ticketUuid: string, messageUuid: string) => Promise<Message | undefined>;
|
|
51
|
+
createMessage: (ticketUuid: string, data: MessageCreateRequest) => Promise<Message>;
|
|
52
|
+
updateMessage: (ticketUuid: string, messageUuid: string, data: MessageRequest) => Promise<Message>;
|
|
53
|
+
partialUpdateMessage: (
|
|
54
|
+
ticketUuid: string,
|
|
55
|
+
messageUuid: string,
|
|
56
|
+
data: PatchedMessageRequest
|
|
57
|
+
) => Promise<Message>;
|
|
58
|
+
deleteMessage: (ticketUuid: string, messageUuid: string) => Promise<void>;
|
|
59
|
+
refreshMessages: (ticketUuid: string) => Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
63
|
+
// Context
|
|
64
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
65
|
+
|
|
66
|
+
const SupportContext = createContext<SupportContextValue | undefined>(undefined);
|
|
67
|
+
|
|
68
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
69
|
+
// Provider
|
|
70
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
export function SupportProvider({ children }: { children: ReactNode }) {
|
|
73
|
+
// List tickets (first page only for count)
|
|
74
|
+
const {
|
|
75
|
+
data: ticketsData,
|
|
76
|
+
error: ticketsError,
|
|
77
|
+
isLoading: isLoadingTickets,
|
|
78
|
+
mutate: mutateTickets,
|
|
79
|
+
} = useSupportTicketsList({ page: 1, page_size: 1 }, api as unknown as API);
|
|
80
|
+
|
|
81
|
+
const refreshTickets = async () => {
|
|
82
|
+
await mutateTickets();
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// Ticket mutations
|
|
86
|
+
const createTicketMutation = useCreateSupportTicketsCreate();
|
|
87
|
+
const updateTicketMutation = useUpdateSupportTicketsUpdate();
|
|
88
|
+
const partialUpdateTicketMutation = usePartialUpdateSupportTicketsPartialUpdate();
|
|
89
|
+
const deleteTicketMutation = useDeleteSupportTicketsDestroy();
|
|
90
|
+
|
|
91
|
+
// Message mutations
|
|
92
|
+
const createMessageMutation = useCreateSupportTicketsMessagesCreate();
|
|
93
|
+
const updateMessageMutation = useUpdateSupportTicketsMessagesUpdate();
|
|
94
|
+
const partialUpdateMessageMutation = usePartialUpdateSupportTicketsMessagesPartialUpdate();
|
|
95
|
+
const deleteMessageMutation = useDeleteSupportTicketsMessagesDestroy();
|
|
96
|
+
|
|
97
|
+
// Get single ticket
|
|
98
|
+
const getTicket = async (uuid: string): Promise<Ticket | undefined> => {
|
|
99
|
+
const { data } = useSupportTicketsRetrieve(uuid, api as unknown as API);
|
|
100
|
+
return data;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Create ticket
|
|
104
|
+
const createTicket = async (data: TicketRequest): Promise<Ticket> => {
|
|
105
|
+
const result = await createTicketMutation(data, api as unknown as API);
|
|
106
|
+
await refreshTickets();
|
|
107
|
+
return result as Ticket;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// Update ticket
|
|
111
|
+
const updateTicket = async (uuid: string, data: TicketRequest): Promise<Ticket> => {
|
|
112
|
+
const result = await updateTicketMutation(uuid, data, api as unknown as API);
|
|
113
|
+
await refreshTickets();
|
|
114
|
+
return result as Ticket;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// Partial update ticket (currently not supported by generated API)
|
|
118
|
+
const partialUpdateTicket = async (
|
|
119
|
+
uuid: string,
|
|
120
|
+
data: PatchedTicketRequest
|
|
121
|
+
): Promise<Ticket> => {
|
|
122
|
+
// TODO: Fix generator to include data parameter for PATCH requests
|
|
123
|
+
// const result = await partialUpdateTicketMutation(uuid, data, api as unknown as API);
|
|
124
|
+
// For now, fallback to full update
|
|
125
|
+
const result = await updateTicketMutation(uuid, data as unknown as TicketRequest, api as unknown as API);
|
|
126
|
+
await refreshTickets();
|
|
127
|
+
return result as Ticket;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Delete ticket
|
|
131
|
+
const deleteTicket = async (uuid: string): Promise<void> => {
|
|
132
|
+
await deleteTicketMutation(uuid, api as unknown as API);
|
|
133
|
+
await refreshTickets();
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// Get messages for ticket
|
|
137
|
+
const getMessages = async (ticketUuid: string): Promise<Message[] | undefined> => {
|
|
138
|
+
const { data } = useSupportTicketsMessagesList(ticketUuid, { page: 1, page_size: 100 }, api as unknown as API);
|
|
139
|
+
return data?.results;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// Get single message
|
|
143
|
+
const getMessage = async (
|
|
144
|
+
ticketUuid: string,
|
|
145
|
+
messageUuid: string
|
|
146
|
+
): Promise<Message | undefined> => {
|
|
147
|
+
const { data } = useSupportTicketsMessagesRetrieve(
|
|
148
|
+
ticketUuid,
|
|
149
|
+
messageUuid,
|
|
150
|
+
api as unknown as API
|
|
151
|
+
);
|
|
152
|
+
return data;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// Create message
|
|
156
|
+
const createMessage = async (
|
|
157
|
+
ticketUuid: string,
|
|
158
|
+
data: MessageCreateRequest
|
|
159
|
+
): Promise<Message> => {
|
|
160
|
+
const result = await createMessageMutation(ticketUuid, data, api as unknown as API);
|
|
161
|
+
return result as Message;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// Update message
|
|
165
|
+
const updateMessage = async (
|
|
166
|
+
ticketUuid: string,
|
|
167
|
+
messageUuid: string,
|
|
168
|
+
data: MessageRequest
|
|
169
|
+
): Promise<Message> => {
|
|
170
|
+
const result = await updateMessageMutation(
|
|
171
|
+
ticketUuid,
|
|
172
|
+
messageUuid,
|
|
173
|
+
data,
|
|
174
|
+
api as unknown as API
|
|
175
|
+
);
|
|
176
|
+
return result as Message;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// Partial update message (currently not supported by generated API)
|
|
180
|
+
const partialUpdateMessage = async (
|
|
181
|
+
ticketUuid: string,
|
|
182
|
+
messageUuid: string,
|
|
183
|
+
data: PatchedMessageRequest
|
|
184
|
+
): Promise<Message> => {
|
|
185
|
+
// TODO: Fix generator to include data parameter for PATCH requests
|
|
186
|
+
// const result = await partialUpdateMessageMutation(ticketUuid, messageUuid, data, api as unknown as API);
|
|
187
|
+
// For now, fallback to full update
|
|
188
|
+
const result = await updateMessageMutation(
|
|
189
|
+
ticketUuid,
|
|
190
|
+
messageUuid,
|
|
191
|
+
data as MessageRequest,
|
|
192
|
+
api as unknown as API
|
|
193
|
+
);
|
|
194
|
+
return result as Message;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// Delete message
|
|
198
|
+
const deleteMessage = async (ticketUuid: string, messageUuid: string): Promise<void> => {
|
|
199
|
+
await deleteMessageMutation(ticketUuid, messageUuid, api as unknown as API);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// Refresh messages for specific ticket
|
|
203
|
+
const refreshMessages = async (ticketUuid: string): Promise<void> => {
|
|
204
|
+
// We'll use mutate from the hook, but we need to get it dynamically
|
|
205
|
+
// For now, we can just refresh tickets which will update everything
|
|
206
|
+
await refreshTickets();
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const value: SupportContextValue = {
|
|
210
|
+
tickets: ticketsData?.results,
|
|
211
|
+
isLoadingTickets,
|
|
212
|
+
ticketsError,
|
|
213
|
+
refreshTickets,
|
|
214
|
+
getTicket,
|
|
215
|
+
createTicket,
|
|
216
|
+
updateTicket,
|
|
217
|
+
partialUpdateTicket,
|
|
218
|
+
deleteTicket,
|
|
219
|
+
getMessages,
|
|
220
|
+
getMessage,
|
|
221
|
+
createMessage,
|
|
222
|
+
updateMessage,
|
|
223
|
+
partialUpdateMessage,
|
|
224
|
+
deleteMessage,
|
|
225
|
+
refreshMessages,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
return <SupportContext.Provider value={value}>{children}</SupportContext.Provider>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
232
|
+
// Hook
|
|
233
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
234
|
+
|
|
235
|
+
export function useSupportContext(): SupportContextValue {
|
|
236
|
+
const context = useContext(SupportContext);
|
|
237
|
+
if (!context) {
|
|
238
|
+
throw new Error('useSupportContext must be used within SupportProvider');
|
|
239
|
+
}
|
|
240
|
+
return context;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
244
|
+
// Re-export types for external use
|
|
245
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
246
|
+
|
|
247
|
+
export type {
|
|
248
|
+
Ticket,
|
|
249
|
+
TicketRequest,
|
|
250
|
+
PatchedTicketRequest,
|
|
251
|
+
Message,
|
|
252
|
+
MessageRequest,
|
|
253
|
+
MessageCreateRequest,
|
|
254
|
+
PatchedMessageRequest,
|
|
255
|
+
};
|
|
256
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CFG API Contexts
|
|
3
|
+
*
|
|
4
|
+
* Centralized React contexts for all CFG API modules
|
|
5
|
+
* Uses generated SWR hooks for optimal data fetching and caching
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use client';
|
|
9
|
+
|
|
10
|
+
// Newsletter (Campaigns & Subscriptions)
|
|
11
|
+
export { NewsletterProvider, useNewsletterContext } from './NewsletterContext';
|
|
12
|
+
export type {
|
|
13
|
+
NewsletterContextValue,
|
|
14
|
+
NewsletterCampaign,
|
|
15
|
+
NewsletterCampaignRequest,
|
|
16
|
+
PatchedNewsletterCampaignRequest,
|
|
17
|
+
NewsletterSubscription,
|
|
18
|
+
PaginatedNewsletterCampaignList,
|
|
19
|
+
PaginatedNewsletterSubscriptionList,
|
|
20
|
+
SubscribeRequest,
|
|
21
|
+
SubscribeResponse,
|
|
22
|
+
UnsubscribeRequest,
|
|
23
|
+
SuccessResponse,
|
|
24
|
+
SendCampaignRequest,
|
|
25
|
+
SendCampaignResponse,
|
|
26
|
+
} from './NewsletterContext';
|
|
27
|
+
|
|
28
|
+
// Leads (Lead Submissions)
|
|
29
|
+
export { LeadsProvider, useLeadsContext } from './LeadsContext';
|
|
30
|
+
export type {
|
|
31
|
+
LeadsContextValue,
|
|
32
|
+
LeadSubmission,
|
|
33
|
+
LeadSubmissionRequest,
|
|
34
|
+
PatchedLeadSubmissionRequest,
|
|
35
|
+
PaginatedLeadSubmissionList,
|
|
36
|
+
} from './LeadsContext';
|
|
37
|
+
|
|
38
|
+
// Support (Tickets & Messages)
|
|
39
|
+
export {
|
|
40
|
+
SupportProvider,
|
|
41
|
+
useSupportContext
|
|
42
|
+
} from './SupportContext';
|
|
43
|
+
export type {
|
|
44
|
+
SupportContextValue,
|
|
45
|
+
Ticket,
|
|
46
|
+
TicketRequest,
|
|
47
|
+
PatchedTicketRequest,
|
|
48
|
+
Message,
|
|
49
|
+
MessageRequest,
|
|
50
|
+
MessageCreateRequest,
|
|
51
|
+
PatchedMessageRequest,
|
|
52
|
+
} from './SupportContext';
|
|
53
|
+
|
|
54
|
+
// Payments (Payments, Balances, Currencies, API Keys, Overview)
|
|
55
|
+
export * from './payments';
|
|
56
|
+
|
|
57
|
+
// Knowbase (Chat, Documents, Sessions)
|
|
58
|
+
export * from './knowbase';
|
|
59
|
+
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowbase Chat Context
|
|
3
|
+
* Context for RAG-powered chat functionality
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use client';
|
|
7
|
+
|
|
8
|
+
import React, { createContext, useContext, type ReactNode } from 'react';
|
|
9
|
+
import { api } from '@djangocfg/api';
|
|
10
|
+
import {
|
|
11
|
+
useKnowbaseAdminChatList,
|
|
12
|
+
useKnowbaseAdminChatRetrieve,
|
|
13
|
+
useCreateKnowbaseAdminChatCreate,
|
|
14
|
+
useUpdateKnowbaseAdminChatUpdate,
|
|
15
|
+
usePartialUpdateKnowbaseAdminChatPartialUpdate,
|
|
16
|
+
useDeleteKnowbaseAdminChatDestroy,
|
|
17
|
+
useKnowbaseAdminChatHistoryRetrieve,
|
|
18
|
+
useCreateKnowbaseAdminChatQueryCreate,
|
|
19
|
+
} from '@djangocfg/api';
|
|
20
|
+
import type { API } from '@djangocfg/api';
|
|
21
|
+
import type {
|
|
22
|
+
PaginatedChatResponseList,
|
|
23
|
+
ChatResponse,
|
|
24
|
+
ChatResponseRequest,
|
|
25
|
+
PatchedChatResponseRequest,
|
|
26
|
+
ChatHistory,
|
|
27
|
+
ChatQueryRequest,
|
|
28
|
+
} from '@djangocfg/api';
|
|
29
|
+
|
|
30
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
31
|
+
// Context Type
|
|
32
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
33
|
+
|
|
34
|
+
export interface KnowbaseChatContextValue {
|
|
35
|
+
// Chat list
|
|
36
|
+
chats: PaginatedChatResponseList | undefined;
|
|
37
|
+
isLoadingChats: boolean;
|
|
38
|
+
chatsError: Error | undefined;
|
|
39
|
+
refreshChats: () => Promise<void>;
|
|
40
|
+
|
|
41
|
+
// Chat operations
|
|
42
|
+
getChat: (id: string) => Promise<ChatResponse | undefined>;
|
|
43
|
+
getChatHistory: (id: string) => Promise<ChatHistory | undefined>;
|
|
44
|
+
createChat: (data: ChatResponseRequest) => Promise<ChatResponse>;
|
|
45
|
+
updateChat: (id: string, data: ChatResponseRequest) => Promise<ChatResponse>;
|
|
46
|
+
partialUpdateChat: (id: string, data: PatchedChatResponseRequest) => Promise<ChatResponse>;
|
|
47
|
+
deleteChat: (id: string) => Promise<void>;
|
|
48
|
+
|
|
49
|
+
// RAG Query
|
|
50
|
+
sendQuery: (data: ChatQueryRequest) => Promise<ChatResponse>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
54
|
+
// Context
|
|
55
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
const KnowbaseChatContext = createContext<KnowbaseChatContextValue | undefined>(undefined);
|
|
58
|
+
|
|
59
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
60
|
+
// Provider
|
|
61
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
62
|
+
|
|
63
|
+
export function KnowbaseChatProvider({ children }: { children: ReactNode }) {
|
|
64
|
+
// List chats
|
|
65
|
+
const {
|
|
66
|
+
data: chats,
|
|
67
|
+
error: chatsError,
|
|
68
|
+
isLoading: isLoadingChats,
|
|
69
|
+
mutate: mutateChats,
|
|
70
|
+
} = useKnowbaseAdminChatList({}, api as unknown as API);
|
|
71
|
+
|
|
72
|
+
const refreshChats = async () => {
|
|
73
|
+
await mutateChats();
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// Mutations
|
|
77
|
+
const createChatMutation = useCreateKnowbaseAdminChatCreate();
|
|
78
|
+
const updateChatMutation = useUpdateKnowbaseAdminChatUpdate();
|
|
79
|
+
const partialUpdateChatMutation = usePartialUpdateKnowbaseAdminChatPartialUpdate();
|
|
80
|
+
const deleteChatMutation = useDeleteKnowbaseAdminChatDestroy();
|
|
81
|
+
const sendQueryMutation = useCreateKnowbaseAdminChatQueryCreate();
|
|
82
|
+
|
|
83
|
+
// Get single chat
|
|
84
|
+
const getChat = async (id: string): Promise<ChatResponse | undefined> => {
|
|
85
|
+
const { data } = useKnowbaseAdminChatRetrieve(id, api as unknown as API);
|
|
86
|
+
return data;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// Get chat history
|
|
90
|
+
const getChatHistory = async (id: string): Promise<ChatHistory | undefined> => {
|
|
91
|
+
const { data } = useKnowbaseAdminChatHistoryRetrieve(id, api as unknown as API);
|
|
92
|
+
return data;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Create chat
|
|
96
|
+
const createChat = async (data: ChatResponseRequest): Promise<ChatResponse> => {
|
|
97
|
+
const result = await createChatMutation(data, api as unknown as API);
|
|
98
|
+
await refreshChats();
|
|
99
|
+
return result as ChatResponse;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// Update chat
|
|
103
|
+
const updateChat = async (id: string, data: ChatResponseRequest): Promise<ChatResponse> => {
|
|
104
|
+
const result = await updateChatMutation(id, data, api as unknown as API);
|
|
105
|
+
await refreshChats();
|
|
106
|
+
return result as ChatResponse;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// Partial update chat
|
|
110
|
+
const partialUpdateChat = async (
|
|
111
|
+
id: string,
|
|
112
|
+
data: PatchedChatResponseRequest
|
|
113
|
+
): Promise<ChatResponse> => {
|
|
114
|
+
const result = await partialUpdateChatMutation(id, data, api as unknown as API);
|
|
115
|
+
await refreshChats();
|
|
116
|
+
return result as ChatResponse;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// Delete chat
|
|
120
|
+
const deleteChat = async (id: string): Promise<void> => {
|
|
121
|
+
await deleteChatMutation(id, api as unknown as API);
|
|
122
|
+
await refreshChats();
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Send RAG query
|
|
126
|
+
const sendQuery = async (data: ChatQueryRequest): Promise<ChatResponse> => {
|
|
127
|
+
const result = await sendQueryMutation(data, api as unknown as API);
|
|
128
|
+
await refreshChats();
|
|
129
|
+
return result as ChatResponse;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const value: KnowbaseChatContextValue = {
|
|
133
|
+
chats,
|
|
134
|
+
isLoadingChats,
|
|
135
|
+
chatsError,
|
|
136
|
+
refreshChats,
|
|
137
|
+
getChat,
|
|
138
|
+
getChatHistory,
|
|
139
|
+
createChat,
|
|
140
|
+
updateChat,
|
|
141
|
+
partialUpdateChat,
|
|
142
|
+
deleteChat,
|
|
143
|
+
sendQuery,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
return <KnowbaseChatContext.Provider value={value}>{children}</KnowbaseChatContext.Provider>;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
150
|
+
// Hook
|
|
151
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
152
|
+
|
|
153
|
+
export function useKnowbaseChatContext(): KnowbaseChatContextValue {
|
|
154
|
+
const context = useContext(KnowbaseChatContext);
|
|
155
|
+
if (!context) {
|
|
156
|
+
throw new Error('useKnowbaseChatContext must be used within KnowbaseChatProvider');
|
|
157
|
+
}
|
|
158
|
+
return context;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
162
|
+
// Re-export types for external use
|
|
163
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
164
|
+
|
|
165
|
+
export type {
|
|
166
|
+
ChatResponse,
|
|
167
|
+
ChatResponseRequest,
|
|
168
|
+
PatchedChatResponseRequest,
|
|
169
|
+
ChatHistory,
|
|
170
|
+
ChatQueryRequest,
|
|
171
|
+
ChatMessage,
|
|
172
|
+
ChatSource,
|
|
173
|
+
} from '@djangocfg/api';
|
|
174
|
+
|