import { ChatKit, useChatKit } from '@xpert-ai/chatkit-react';
export function MyChat() {
const chatkit = useChatKit({
frameUrl: CHATKIT_FRAME_URL || undefined,
api: {
apiUrl: XPERT_API_URL,
xpertId: XPERT_ID,
getClientSecret: async () => {
const baseUrl = API_BASE_URL || '';
const url = `${baseUrl}/api/create-session`;
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ assistantId: XPERT_ID }),
});
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
throw new Error(errorData?.error || `HTTP ${response.status}`);
}
const data = await response.json();
if (!data.client_secret) {
throw new Error('Missing client_secret in response');
}
return data.client_secret;
},
},
});
return (
<div className="h-full flex flex-col">
<ChatKit control={chatkit.control} className="flex-1" />
</div>
);
}