mirror of https://github.com/buster-so/buster.git
fix: correct version on file response messages
This commit is contained in:
parent
aa52cfdc81
commit
7fc4d44779
|
@ -1,6 +1,5 @@
|
||||||
import {
|
import {
|
||||||
type UpdateMessageEntriesParams,
|
type UpdateMessageEntriesParams,
|
||||||
getAssetLatestVersion,
|
|
||||||
updateChat,
|
updateChat,
|
||||||
updateMessage,
|
updateMessage,
|
||||||
updateMessageEntries,
|
updateMessageEntries,
|
||||||
|
@ -52,6 +51,7 @@ export function createDoneToolDelta(context: DoneToolContext, doneToolState: Don
|
||||||
assetId: string;
|
assetId: string;
|
||||||
assetName: string;
|
assetName: string;
|
||||||
assetType: ResponseMessageFileType;
|
assetType: ResponseMessageFileType;
|
||||||
|
versionNumber: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
function isAssetToReturn(value: unknown): value is AssetToReturn {
|
function isAssetToReturn(value: unknown): value is AssetToReturn {
|
||||||
|
@ -63,7 +63,8 @@ export function createDoneToolDelta(context: DoneToolContext, doneToolState: Don
|
||||||
const typeOk =
|
const typeOk =
|
||||||
typeof typeVal === 'string' &&
|
typeof typeVal === 'string' &&
|
||||||
ResponseMessageFileTypeSchema.options.includes(typeVal as ResponseMessageFileType);
|
ResponseMessageFileTypeSchema.options.includes(typeVal as ResponseMessageFileType);
|
||||||
return idOk && nameOk && typeOk;
|
const versionOk = typeof obj.versionNumber === 'number' && obj.versionNumber > 0;
|
||||||
|
return idOk && nameOk && typeOk && versionOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
let assetsToInsert: AssetToReturn[] = [];
|
let assetsToInsert: AssetToReturn[] = [];
|
||||||
|
@ -95,7 +96,7 @@ export function createDoneToolDelta(context: DoneToolContext, doneToolState: Don
|
||||||
type: 'file' as const,
|
type: 'file' as const,
|
||||||
file_type: a.assetType,
|
file_type: a.assetType,
|
||||||
file_name: a.assetName,
|
file_name: a.assetName,
|
||||||
version_number: 1,
|
version_number: a.versionNumber,
|
||||||
filter_version_id: null,
|
filter_version_id: null,
|
||||||
metadata: [
|
metadata: [
|
||||||
{
|
{
|
||||||
|
@ -128,7 +129,7 @@ export function createDoneToolDelta(context: DoneToolContext, doneToolState: Don
|
||||||
if (newAssets.length > 0) {
|
if (newAssets.length > 0) {
|
||||||
doneToolState.addedAssets = [
|
doneToolState.addedAssets = [
|
||||||
...(doneToolState.addedAssets || []),
|
...(doneToolState.addedAssets || []),
|
||||||
...newAssets.map((a) => ({ assetId: a.assetId, assetType: a.assetType })),
|
...newAssets.map((a) => ({ assetId: a.assetId, assetType: a.assetType, versionNumber: a.versionNumber })),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,16 +160,10 @@ export function createDoneToolDelta(context: DoneToolContext, doneToolState: Don
|
||||||
const firstAsset = doneToolState.addedAssets[0];
|
const firstAsset = doneToolState.addedAssets[0];
|
||||||
|
|
||||||
if (firstAsset) {
|
if (firstAsset) {
|
||||||
// Get the actual version number from the database
|
|
||||||
const versionNumber = await getAssetLatestVersion({
|
|
||||||
assetId: firstAsset.assetId,
|
|
||||||
assetType: firstAsset.assetType,
|
|
||||||
});
|
|
||||||
|
|
||||||
await updateChat(context.chatId, {
|
await updateChat(context.chatId, {
|
||||||
mostRecentFileId: firstAsset.assetId,
|
mostRecentFileId: firstAsset.assetId,
|
||||||
mostRecentFileType: firstAsset.assetType,
|
mostRecentFileType: firstAsset.assetType,
|
||||||
mostRecentVersionNumber: versionNumber,
|
mostRecentVersionNumber: firstAsset.versionNumber,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ export const DoneToolInputSchema = z.object({
|
||||||
assetId: z.string().uuid(),
|
assetId: z.string().uuid(),
|
||||||
assetName: z.string(),
|
assetName: z.string(),
|
||||||
assetType: AssetTypeSchema,
|
assetType: AssetTypeSchema,
|
||||||
|
versionNumber: z.number().int().positive().describe('The version number of the asset to return'),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.describe(
|
.describe(
|
||||||
|
@ -60,17 +61,12 @@ const DoneToolStateSchema = z.object({
|
||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
assetId: z.string(),
|
assetId: z.string(),
|
||||||
assetType: z.enum([
|
assetType: AssetTypeSchema,
|
||||||
'metric_file',
|
versionNumber: z.number(),
|
||||||
'dashboard_file',
|
|
||||||
'report_file',
|
|
||||||
'analyst_chat',
|
|
||||||
'collection',
|
|
||||||
]),
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.optional()
|
.optional()
|
||||||
.describe('Assets that have been added with their types for chat update'),
|
.describe('Assets that have been added with their types and version numbers for chat update'),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type DoneToolInput = z.infer<typeof DoneToolInputSchema>;
|
export type DoneToolInput = z.infer<typeof DoneToolInputSchema>;
|
||||||
|
|
Loading…
Reference in New Issue