refactor: remove didusersendmessage tracking event (#23777)

This commit is contained in:
Jamie Howard 2025-06-20 12:20:33 +01:00 committed by GitHub
parent 2b12c3705c
commit fab5596272
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 2 additions and 53 deletions

View File

@ -378,14 +378,6 @@ interface DidUsePresetPromptEvent {
}; };
} }
interface DidUserSendMessageEvent {
name: 'didUserSendMessage';
properties: {
'attachment-type': 'code' | 'figma' | 'image' | 'none';
'number-of-input-tokens': number;
};
}
interface DidAnswerMessageEvent { interface DidAnswerMessageEvent {
name: 'didAnswerMessage'; name: 'didAnswerMessage';
properties: { properties: {
@ -431,7 +423,6 @@ type EventsWithProperties =
| DidSortMediaLibraryElementsEvent | DidSortMediaLibraryElementsEvent
| DidSubmitWithErrorsFirstAdminEvent | DidSubmitWithErrorsFirstAdminEvent
| DidUsePresetPromptEvent | DidUsePresetPromptEvent
| DidUserSendMessageEvent
| DidAnswerMessageEvent | DidAnswerMessageEvent
| DidVoteAnswerEvent | DidVoteAnswerEvent
| LogoEvent | LogoEvent

View File

@ -376,8 +376,7 @@ export const UploadCodeModal = () => {
}); });
const { isCodeUploadOpen, closeCodeUpload, submitOnFinish } = useUploadProjectToChat(); const { isCodeUploadOpen, closeCodeUpload, submitOnFinish } = useUploadProjectToChat();
const { setMessages, reload, openChat, input, setInput, setCurrentAttachmentType } = const { setMessages, reload, openChat, input, setInput } = useStrapiChat();
useStrapiChat();
const handleCancel = () => { const handleCancel = () => {
setProjectName(null); setProjectName(null);
@ -386,8 +385,6 @@ export const UploadCodeModal = () => {
}; };
const handleComplete = async () => { const handleComplete = async () => {
setCurrentAttachmentType('code');
// Ensure chat is opened // Ensure chat is opened
openChat(); openChat();

View File

@ -274,8 +274,6 @@ export const UploadFigmaModal = () => {
const [selectedImages, setSelectedImages] = useState<string[]>([]); const [selectedImages, setSelectedImages] = useState<string[]>([]);
const { t } = useTranslations(); const { t } = useTranslations();
const { setCurrentAttachmentType } = useStrapiChat();
const { addAttachments } = useAttachments(); const { addAttachments } = useAttachments();
const { isFigmaUploadOpen, closeFigmaUpload, submitOnFinish } = useUploadFigmaToChat(); const { isFigmaUploadOpen, closeFigmaUpload, submitOnFinish } = useUploadFigmaToChat();
const { input, setInput, setMessages, reload, openChat } = useStrapiChat(); const { input, setInput, setMessages, reload, openChat } = useStrapiChat();
@ -320,8 +318,6 @@ export const UploadFigmaModal = () => {
return; return;
} }
setCurrentAttachmentType('figma');
// Ensure chat is opened // Ensure chat is opened
openChat(); openChat();

View File

@ -11,7 +11,7 @@ import { useFetchUploadMedia } from './useAIFetch';
import type { Attachment } from '../lib/types/attachments'; import type { Attachment } from '../lib/types/attachments';
export function useAttachments() { export function useAttachments() {
const { setAttachments, attachments, id: chatId, setCurrentAttachmentType } = useStrapiChat(); const { setAttachments, attachments, id: chatId } = useStrapiChat();
const { toggleNotification } = useNotification(); const { toggleNotification } = useNotification();
const { fetch: fetchUploadMedia } = useFetchUploadMedia(); const { fetch: fetchUploadMedia } = useFetchUploadMedia();
@ -85,10 +85,6 @@ export function useAttachments() {
} }
} }
if (limitedFiles.length > 0) {
setCurrentAttachmentType('image');
}
// Upload // Upload
for (const file of limitedFiles) { for (const file of limitedFiles) {
const pendingAttachment: Attachment = { const pendingAttachment: Attachment = {
@ -149,7 +145,6 @@ export function useAttachments() {
fetchUploadMedia, fetchUploadMedia,
removeAttachment, removeAttachment,
updateAttachment, updateAttachment,
setCurrentAttachmentType,
] ]
); );

View File

@ -20,8 +20,6 @@ import { UploadFigmaToChatProvider } from '../UploadFigmaModal';
import { SchemaChatProvider } from './SchemaProvider'; import { SchemaChatProvider } from './SchemaProvider';
type AttachmentType = 'code' | 'figma' | 'image' | 'none';
interface ChatContextType extends Omit<ReturnType<typeof useChat>, 'messages'> { interface ChatContextType extends Omit<ReturnType<typeof useChat>, 'messages'> {
isChatEnabled: boolean; isChatEnabled: boolean;
title?: string; title?: string;
@ -37,9 +35,6 @@ interface ChatContextType extends Omit<ReturnType<typeof useChat>, 'messages'> {
// Attachments // Attachments
attachments: Attachment[]; attachments: Attachment[];
setAttachments: React.Dispatch<React.SetStateAction<Attachment[]>>; setAttachments: React.Dispatch<React.SetStateAction<Attachment[]>>;
// Attachment type tracking
currentAttachmentType: AttachmentType;
setCurrentAttachmentType: (type: AttachmentType) => void;
} }
const ChatContext = createContext<ChatContextType | undefined>(undefined); const ChatContext = createContext<ChatContextType | undefined>(undefined);
@ -62,9 +57,6 @@ export const BaseChatProvider = ({
// Files // Files
const [attachments, setAttachments] = useState<Attachment[]>([]); const [attachments, setAttachments] = useState<Attachment[]>([]);
// Attachment type tracking - set by providers
const [currentAttachmentType, setCurrentAttachmentType] = useState<AttachmentType>('none');
const { trackUsage } = useTracking(); const { trackUsage } = useTracking();
// DataManager // DataManager
@ -111,26 +103,7 @@ export const BaseChatProvider = ({
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [chat.messages]); }, [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 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, { chat.handleSubmit(event, {
experimental_attachments: attachments experimental_attachments: attachments
// Transform to ai/sdk format and remove any attachments that are not yet ready // Transform to ai/sdk format and remove any attachments that are not yet ready
@ -209,9 +182,6 @@ export const BaseChatProvider = ({
// Attachments // Attachments
attachments, attachments,
setAttachments, setAttachments,
// Attachment type tracking
currentAttachmentType,
setCurrentAttachmentType,
}} }}
> >
{children} {children}