mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 15:51:00 +00:00
feat(assistant): an attached file can be kept in Files, on its own or with a booking or an expense
The chips offered to keep an attached file in Files, but nothing could do it: the assistant's upload_trip_file stays denied, and the file never reached Files. A new server write, keep_attached_file, is offered to the model where the thread holds an attachment and held as a change card naming the file and the booking, expense or place it goes with. Applied, it runs the checks of a Files upload with the user's rights (the demo block, the trip, file_upload and file_edit for a link, the instance's file types, every linked id on the same trip), copies the bytes to a trip file of their own, and writes the trip file, its expense link and the attachment's pointer to it in one transaction; the members' planners get file:created after it. A second keep of the same attachment answers the file kept the first time. FilesService gains storeBytes and discardBytes so the storage write stays out of that transaction. The receipt opens the Files tab; the card's verb, its "Attached to" row and the receipt's open label are new keys in all 27 locales. Undo is not offered: no tool takes a trip file back yet.
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import { assistantAttachmentIdSchema, assistantReadAttachedFileArgsSchema } from './assistant-attachments.schema';
|
||||
import {
|
||||
assistantAttachmentIdSchema,
|
||||
assistantKeepFileArgsSchema,
|
||||
assistantReadAttachedFileArgsSchema,
|
||||
} from './assistant-attachments.schema';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
@@ -18,4 +22,13 @@ describe('assistant attachments contract', () => {
|
||||
});
|
||||
expect(assistantReadAttachedFileArgsSchema.safeParse({}).success).toBe(false);
|
||||
});
|
||||
|
||||
it('keeps a file with plain ids of the trip, never a string or a negative id, and a short description', () => {
|
||||
const kept = { attachmentId: ID, reservation_id: 5, budget_item_id: 7, place_id: 9, description: 'Airbnb' };
|
||||
expect(assistantKeepFileArgsSchema.parse({ ...kept, name: 'x.pdf' })).toEqual(kept);
|
||||
expect(assistantKeepFileArgsSchema.parse({ attachmentId: ID })).toEqual({ attachmentId: ID });
|
||||
for (const bad of [{ reservation_id: '5' }, { budget_item_id: -1 }, { description: 'x'.repeat(1001) }]) {
|
||||
expect(assistantKeepFileArgsSchema.safeParse({ attachmentId: ID, ...bad }).success).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import { idSchema } from '../common/primitives.schema';
|
||||
import { fileUpdateRequestSchema } from '../file/file.schema';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
@@ -20,3 +23,18 @@ export const assistantReadAttachedFileArgsSchema = z.object({
|
||||
attachmentId: assistantAttachmentIdSchema,
|
||||
});
|
||||
export type AssistantReadAttachedFileArgs = z.infer<typeof assistantReadAttachedFileArgsSchema>;
|
||||
|
||||
/**
|
||||
* What the model calls `keep_attached_file` with: the attachment, and what
|
||||
* of the trip the kept file is attached to, the fields a trip file's update
|
||||
* takes (`fileUpdateRequestSchema`) as plain ids. Every id must name a row of
|
||||
* the same trip; the server checks that when the user applies the change.
|
||||
*/
|
||||
export const assistantKeepFileArgsSchema = z.object({
|
||||
attachmentId: assistantAttachmentIdSchema,
|
||||
reservation_id: idSchema.optional(),
|
||||
budget_item_id: idSchema.optional(),
|
||||
place_id: idSchema.optional(),
|
||||
description: fileUpdateRequestSchema.shape.description.unwrap().max(1000).optional(),
|
||||
});
|
||||
export type AssistantKeepFileArgs = z.infer<typeof assistantKeepFileArgsSchema>;
|
||||
|
||||
@@ -105,6 +105,8 @@ export const CORE_VERB_KEYS = [
|
||||
'rememberNote',
|
||||
// The text of a file attached in the chat, sent to the AI provider once the user agrees.
|
||||
'readAttachment',
|
||||
// A file attached in the chat, kept in the trip's Files, on its own or with a booking, an expense or a place.
|
||||
'keepFile',
|
||||
// A tour: a hike or a city walk created, a hike changed, tours taken in from a GPX file.
|
||||
'addTour',
|
||||
'updateTour',
|
||||
@@ -183,6 +185,8 @@ export const ASSISTANT_CHANGE_LABEL_KEYS = [
|
||||
'field',
|
||||
// Where the text of an attached file goes once the user agrees: the model and its host.
|
||||
'sentTo',
|
||||
// The booking, expense or place a kept file is attached to.
|
||||
'attachedTo',
|
||||
] as const;
|
||||
export const assistantChangeLabelKeySchema = z.enum(ASSISTANT_CHANGE_LABEL_KEYS);
|
||||
export type AssistantChangeLabelKey = z.infer<typeof assistantChangeLabelKeySchema>;
|
||||
@@ -419,6 +423,8 @@ export const CORE_APPLIED_ENTITIES = [
|
||||
'reservation',
|
||||
'memory',
|
||||
'tour',
|
||||
// A file kept in the trip's Files.
|
||||
'file',
|
||||
'other',
|
||||
] as const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user