mirror of
https://github.com/strapi/strapi.git
synced 2025-06-27 00:41:25 +00:00
refactor: remove didusersendmessage tracking event (#23777)
This commit is contained in:
parent
2b12c3705c
commit
fab5596272
@ -378,14 +378,6 @@ interface DidUsePresetPromptEvent {
|
||||
};
|
||||
}
|
||||
|
||||
interface DidUserSendMessageEvent {
|
||||
name: 'didUserSendMessage';
|
||||
properties: {
|
||||
'attachment-type': 'code' | 'figma' | 'image' | 'none';
|
||||
'number-of-input-tokens': number;
|
||||
};
|
||||
}
|
||||
|
||||
interface DidAnswerMessageEvent {
|
||||
name: 'didAnswerMessage';
|
||||
properties: {
|
||||
@ -431,7 +423,6 @@ type EventsWithProperties =
|
||||
| DidSortMediaLibraryElementsEvent
|
||||
| DidSubmitWithErrorsFirstAdminEvent
|
||||
| DidUsePresetPromptEvent
|
||||
| DidUserSendMessageEvent
|
||||
| DidAnswerMessageEvent
|
||||
| DidVoteAnswerEvent
|
||||
| LogoEvent
|
||||
|
@ -376,8 +376,7 @@ export const UploadCodeModal = () => {
|
||||
});
|
||||
|
||||
const { isCodeUploadOpen, closeCodeUpload, submitOnFinish } = useUploadProjectToChat();
|
||||
const { setMessages, reload, openChat, input, setInput, setCurrentAttachmentType } =
|
||||
useStrapiChat();
|
||||
const { setMessages, reload, openChat, input, setInput } = useStrapiChat();
|
||||
|
||||
const handleCancel = () => {
|
||||
setProjectName(null);
|
||||
@ -386,8 +385,6 @@ export const UploadCodeModal = () => {
|
||||
};
|
||||
|
||||
const handleComplete = async () => {
|
||||
setCurrentAttachmentType('code');
|
||||
|
||||
// Ensure chat is opened
|
||||
openChat();
|
||||
|
||||
|
@ -274,8 +274,6 @@ export const UploadFigmaModal = () => {
|
||||
const [selectedImages, setSelectedImages] = useState<string[]>([]);
|
||||
const { t } = useTranslations();
|
||||
|
||||
const { setCurrentAttachmentType } = useStrapiChat();
|
||||
|
||||
const { addAttachments } = useAttachments();
|
||||
const { isFigmaUploadOpen, closeFigmaUpload, submitOnFinish } = useUploadFigmaToChat();
|
||||
const { input, setInput, setMessages, reload, openChat } = useStrapiChat();
|
||||
@ -320,8 +318,6 @@ export const UploadFigmaModal = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
setCurrentAttachmentType('figma');
|
||||
|
||||
// Ensure chat is opened
|
||||
openChat();
|
||||
|
||||
|
@ -11,7 +11,7 @@ import { useFetchUploadMedia } from './useAIFetch';
|
||||
import type { Attachment } from '../lib/types/attachments';
|
||||
|
||||
export function useAttachments() {
|
||||
const { setAttachments, attachments, id: chatId, setCurrentAttachmentType } = useStrapiChat();
|
||||
const { setAttachments, attachments, id: chatId } = useStrapiChat();
|
||||
const { toggleNotification } = useNotification();
|
||||
|
||||
const { fetch: fetchUploadMedia } = useFetchUploadMedia();
|
||||
@ -85,10 +85,6 @@ export function useAttachments() {
|
||||
}
|
||||
}
|
||||
|
||||
if (limitedFiles.length > 0) {
|
||||
setCurrentAttachmentType('image');
|
||||
}
|
||||
|
||||
// Upload
|
||||
for (const file of limitedFiles) {
|
||||
const pendingAttachment: Attachment = {
|
||||
@ -149,7 +145,6 @@ export function useAttachments() {
|
||||
fetchUploadMedia,
|
||||
removeAttachment,
|
||||
updateAttachment,
|
||||
setCurrentAttachmentType,
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -20,8 +20,6 @@ import { UploadFigmaToChatProvider } from '../UploadFigmaModal';
|
||||
|
||||
import { SchemaChatProvider } from './SchemaProvider';
|
||||
|
||||
type AttachmentType = 'code' | 'figma' | 'image' | 'none';
|
||||
|
||||
interface ChatContextType extends Omit<ReturnType<typeof useChat>, 'messages'> {
|
||||
isChatEnabled: boolean;
|
||||
title?: string;
|
||||
@ -37,9 +35,6 @@ interface ChatContextType extends Omit<ReturnType<typeof useChat>, 'messages'> {
|
||||
// Attachments
|
||||
attachments: Attachment[];
|
||||
setAttachments: React.Dispatch<React.SetStateAction<Attachment[]>>;
|
||||
// Attachment type tracking
|
||||
currentAttachmentType: AttachmentType;
|
||||
setCurrentAttachmentType: (type: AttachmentType) => void;
|
||||
}
|
||||
|
||||
const ChatContext = createContext<ChatContextType | undefined>(undefined);
|
||||
@ -62,9 +57,6 @@ export const BaseChatProvider = ({
|
||||
// Files
|
||||
const [attachments, setAttachments] = useState<Attachment[]>([]);
|
||||
|
||||
// Attachment type tracking - set by providers
|
||||
const [currentAttachmentType, setCurrentAttachmentType] = useState<AttachmentType>('none');
|
||||
|
||||
const { trackUsage } = useTracking();
|
||||
|
||||
// DataManager
|
||||
@ -111,26 +103,7 @@ export const BaseChatProvider = ({
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [chat.messages]);
|
||||
|
||||
// Reset attachment type when attachments change
|
||||
useEffect(() => {
|
||||
if (attachments.length === 0) {
|
||||
setCurrentAttachmentType('none');
|
||||
}
|
||||
}, [attachments]);
|
||||
|
||||
const getTokenCount = (text: string): number => {
|
||||
// TODO: Implement token counting
|
||||
return text.length;
|
||||
};
|
||||
|
||||
const handleSubmit = async (event: Parameters<typeof chat.handleSubmit>[0]) => {
|
||||
const tokenCount = getTokenCount(chat.input || '');
|
||||
|
||||
trackUsage('didUserSendMessage', {
|
||||
'attachment-type': currentAttachmentType,
|
||||
'number-of-input-tokens': tokenCount,
|
||||
});
|
||||
|
||||
chat.handleSubmit(event, {
|
||||
experimental_attachments: attachments
|
||||
// Transform to ai/sdk format and remove any attachments that are not yet ready
|
||||
@ -209,9 +182,6 @@ export const BaseChatProvider = ({
|
||||
// Attachments
|
||||
attachments,
|
||||
setAttachments,
|
||||
// Attachment type tracking
|
||||
currentAttachmentType,
|
||||
setCurrentAttachmentType,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
Loading…
x
Reference in New Issue
Block a user