Update most recent message handler

This commit is contained in:
Nate Kelley 2025-09-17 13:54:10 -06:00
parent 743ff57720
commit ac8e2e4f2c
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
5 changed files with 7 additions and 11 deletions

View File

@ -6,7 +6,6 @@ import {
createMessage,
createMessageFileAssociation,
db,
getAssetDetailsById,
} from '@buster/database';
import type {
ChatAssetType,
@ -66,13 +65,12 @@ export async function createAssetImportMessage(
});
// Update the chat with most recent file information and title (matching Rust behavior)
const fileType = assetType === 'metric' ? 'metric' : 'dashboard';
await db
.update(chats)
.set({
title: assetDetails.name, // Set chat title to asset name
mostRecentFileId: assetId,
mostRecentFileType: fileType,
mostRecentFileType: assetType,
mostRecentVersionNumber: assetDetails.versionNumber,
updatedAt: new Date().toISOString(),
})

View File

@ -466,7 +466,6 @@ export async function handleAssetChat(
}
// Update the chat with most recent file information and title (matching Rust behavior)
const fileType = chatAssetType === 'metric' ? 'metric' : 'dashboard';
// Get the asset name from the first message
const assetName = assetMessages[0]?.title || '';
@ -476,7 +475,7 @@ export async function handleAssetChat(
.set({
title: assetName, // Set chat title to asset name
mostRecentFileId: assetId,
mostRecentFileType: fileType,
mostRecentFileType: chatAssetType,
mostRecentVersionNumber: 1, // Asset imports always start at version 1
updatedAt: new Date().toISOString(),
})
@ -617,7 +616,6 @@ export async function handleAssetChatWithPrompt(
}
// Update the chat with most recent file information and title (matching handleAssetChat)
const fileType = chatAssetType === 'metric' ? 'metric' : 'dashboard';
const assetName = assetMessages[0]?.title || '';
await db
@ -625,7 +623,7 @@ export async function handleAssetChatWithPrompt(
.set({
title: assetName, // Set chat title to asset name
mostRecentFileId: assetId,
mostRecentFileType: fileType,
mostRecentFileType: chatAssetType,
mostRecentVersionNumber: 1, // Asset imports always start at version 1
updatedAt: new Date().toISOString(),
})

View File

@ -55,7 +55,7 @@ export async function markMessageComplete(
if (input.selectedFile?.fileId && input.chatId) {
await updateChat(input.chatId, {
mostRecentFileId: input.selectedFile.fileId,
mostRecentFileType: input.selectedFile.fileType,
mostRecentFileType: input.selectedFile.fileType, //TODO: scope to actually be the enum file type
mostRecentVersionNumber: input.selectedFile.versionNumber,
});
}

View File

@ -94,7 +94,7 @@ export function createDoneToolStart(context: DoneToolContext, doneToolState: Don
try {
await updateChat(context.chatId, {
mostRecentFileId: mostRecentFile.id,
mostRecentFileType: mostRecentFile.fileType as 'metric' | 'dashboard' | 'report',
mostRecentFileType: mostRecentFile.fileType,
mostRecentVersionNumber: mostRecentFile.versionNumber || 1,
});
} catch (error) {

View File

@ -49,9 +49,9 @@ interface ToolFileInfo {
// File tracking type
interface ExtractedFile {
id: string;
fileType: 'metric' | 'dashboard' | 'report';
fileType: 'metric' | 'dashboard' | 'report'; //TODO: scope to actually be the enum file type
fileName: string;
status: 'completed' | 'failed' | 'loading';
status: 'completed' | 'failed' | 'loading'; //TODO: use an enum from server shared
operation?: 'created' | 'modified' | undefined;
versionNumber?: number | undefined;
metricIds?: string[] | undefined; // IDs of metrics that belong to this dashboard