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:
Maurice
2026-10-24 21:41:16 +02:00
parent aeda658f18
commit 89c33ac3f4
49 changed files with 907 additions and 27 deletions
@@ -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>;
+6
View File
@@ -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;
+3
View File
@@ -574,5 +574,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'اسمح للمساعد بقراءة الملف',
'assistant.change.label.sentTo': 'يُرسل إلى',
'assistant.step.readingAttachment': 'جارٍ قراءة الملف',
'assistant.change.verb.keepFile': 'احفظ الملف في الملفات',
'assistant.change.label.attachedTo': 'مرفق بـ',
'assistant.card.file.open': 'افتح في الملفات',
};
export default assistant;
+3
View File
@@ -492,5 +492,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Köməkçiyə faylı oxumağa icazə ver',
'assistant.change.label.sentTo': 'Göndərilir',
'assistant.step.readingAttachment': 'Fayl oxunur',
'assistant.change.verb.keepFile': 'Faylı Fayllarda saxla',
'assistant.change.label.attachedTo': 'Əlavə olunduğu yer',
'assistant.card.file.open': 'Fayllarda aç',
};
export default assistant;
+3
View File
@@ -493,5 +493,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Deixar o assistente ler o arquivo',
'assistant.change.label.sentTo': 'Enviado para',
'assistant.step.readingAttachment': 'Lendo o arquivo',
'assistant.change.verb.keepFile': 'Guardar o arquivo em Arquivos',
'assistant.change.label.attachedTo': 'Anexado a',
'assistant.card.file.open': 'Abrir em Arquivos',
};
export default assistant;
+3
View File
@@ -495,5 +495,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Deixa que l’assistent llegeixi el fitxer',
'assistant.change.label.sentTo': 'S’envia a',
'assistant.step.readingAttachment': 'S’està llegint el fitxer',
'assistant.change.verb.keepFile': 'Desa el fitxer a Fitxers',
'assistant.change.label.attachedTo': 'Adjunt a',
'assistant.card.file.open': 'Obre a Fitxers',
};
export default assistant;
+3
View File
@@ -512,5 +512,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Nechat asistenta přečíst soubor',
'assistant.change.label.sentTo': 'Odesílá se do',
'assistant.step.readingAttachment': 'Čtu soubor',
'assistant.change.verb.keepFile': 'Uložit soubor do Souborů',
'assistant.change.label.attachedTo': 'Připojeno k',
'assistant.card.file.open': 'Otevřít v Souborech',
};
export default assistant;
+3
View File
@@ -493,5 +493,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Den Assistenten die Datei lesen lassen',
'assistant.change.label.sentTo': 'Geht an',
'assistant.step.readingAttachment': 'Lese die Datei',
'assistant.change.verb.keepFile': 'Datei in Dateien ablegen',
'assistant.change.label.attachedTo': 'Angehängt an',
'assistant.card.file.open': 'In Dateien öffnen',
};
export default assistant;
+3
View File
@@ -487,5 +487,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Let the assistant read the file',
'assistant.change.label.sentTo': 'Sent to',
'assistant.step.readingAttachment': 'Reading the file',
'assistant.change.verb.keepFile': 'Keep the file in Files',
'assistant.change.label.attachedTo': 'Attached to',
'assistant.card.file.open': 'Open in Files',
};
export default assistant;
+3
View File
@@ -491,5 +491,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Dejar que el asistente lea el archivo',
'assistant.change.label.sentTo': 'Se envía a',
'assistant.step.readingAttachment': 'Leyendo el archivo',
'assistant.change.verb.keepFile': 'Guardar el archivo en Archivos',
'assistant.change.label.attachedTo': 'Adjunto a',
'assistant.card.file.open': 'Abrir en Archivos',
};
export default assistant;
+3
View File
@@ -492,5 +492,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Luba assistendil fail läbi lugeda',
'assistant.change.label.sentTo': 'Saadetakse',
'assistant.step.readingAttachment': 'Loen faili',
'assistant.change.verb.keepFile': 'Salvesta fail failidesse',
'assistant.change.label.attachedTo': 'Lisatud juurde',
'assistant.card.file.open': 'Ava failides',
};
export default assistant;
+3
View File
@@ -498,5 +498,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Laisser l’assistant lire le fichier',
'assistant.change.label.sentTo': 'Envoyé à',
'assistant.step.readingAttachment': 'Lecture du fichier',
'assistant.change.verb.keepFile': 'Garder le fichier dans Fichiers',
'assistant.change.label.attachedTo': 'Joint à',
'assistant.card.file.open': 'Ouvrir dans Fichiers',
};
export default assistant;
+3
View File
@@ -496,5 +496,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Άφησε τον βοηθό να διαβάσει το αρχείο',
'assistant.change.label.sentTo': 'Αποστέλλεται σε',
'assistant.step.readingAttachment': 'Ανάγνωση του αρχείου',
'assistant.change.verb.keepFile': 'Αποθήκευση του αρχείου στα Αρχεία',
'assistant.change.label.attachedTo': 'Επισυνάπτεται σε',
'assistant.card.file.open': 'Άνοιγμα στα Αρχεία',
};
export default assistant;
+3
View File
@@ -496,5 +496,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Engedd, hogy az asszisztens elolvassa a fájlt',
'assistant.change.label.sentTo': 'Címzett',
'assistant.step.readingAttachment': 'A fájl olvasása',
'assistant.change.verb.keepFile': 'A fájl mentése a Fájlok közé',
'assistant.change.label.attachedTo': 'Csatolva ehhez',
'assistant.card.file.open': 'Megnyitás a Fájlokban',
};
export default assistant;
+3
View File
@@ -471,5 +471,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Izinkan asisten membaca berkas',
'assistant.change.label.sentTo': 'Dikirim ke',
'assistant.step.readingAttachment': 'Membaca berkas',
'assistant.change.verb.keepFile': 'Simpan berkas di Berkas',
'assistant.change.label.attachedTo': 'Dilampirkan ke',
'assistant.card.file.open': 'Buka di Berkas',
};
export default assistant;
+3
View File
@@ -499,5 +499,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Lascia che l’assistente legga il file',
'assistant.change.label.sentTo': 'Inviato a',
'assistant.step.readingAttachment': 'Lettura del file',
'assistant.change.verb.keepFile': 'Salva il file in File',
'assistant.change.label.attachedTo': 'Allegato a',
'assistant.card.file.open': 'Apri in File',
};
export default assistant;
+3
View File
@@ -465,5 +465,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'アシスタントにファイルを読ませる',
'assistant.change.label.sentTo': '送信先',
'assistant.step.readingAttachment': 'ファイルを読んでいます',
'assistant.change.verb.keepFile': 'ファイルに保存',
'assistant.change.label.attachedTo': '添付先',
'assistant.card.file.open': 'ファイルで開く',
};
export default assistant;
+3
View File
@@ -462,5 +462,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': '어시스턴트가 파일을 읽도록 허용',
'assistant.change.label.sentTo': '전송 대상',
'assistant.step.readingAttachment': '파일을 읽는 중',
'assistant.change.verb.keepFile': '파일에 보관',
'assistant.change.label.attachedTo': '첨부 대상',
'assistant.card.file.open': '파일에서 열기',
};
export default assistant;
+3
View File
@@ -494,5 +494,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'De assistent het bestand laten lezen',
'assistant.change.label.sentTo': 'Gaat naar',
'assistant.step.readingAttachment': 'Bestand lezen',
'assistant.change.verb.keepFile': 'Bestand bewaren in Bestanden',
'assistant.change.label.attachedTo': 'Gekoppeld aan',
'assistant.card.file.open': 'Openen in Bestanden',
};
export default assistant;
+3
View File
@@ -537,5 +537,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Pozwól asystentowi przeczytać plik',
'assistant.change.label.sentTo': 'Trafia do',
'assistant.step.readingAttachment': 'Czytam plik',
'assistant.change.verb.keepFile': 'Zapisz plik w Plikach',
'assistant.change.label.attachedTo': 'Dołączono do',
'assistant.card.file.open': 'Otwórz w Plikach',
};
export default assistant;
+3
View File
@@ -538,5 +538,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Разрешить ассистенту прочитать файл',
'assistant.change.label.sentTo': 'Отправляется в',
'assistant.step.readingAttachment': 'Читаю файл',
'assistant.change.verb.keepFile': 'Сохранить файл в Файлы',
'assistant.change.label.attachedTo': 'Прикреплён к',
'assistant.card.file.open': 'Открыть в Файлах',
};
export default assistant;
+3
View File
@@ -512,5 +512,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Nechať asistenta prečítať súbor',
'assistant.change.label.sentTo': 'Odosiela sa do',
'assistant.step.readingAttachment': 'Čítam súbor',
'assistant.change.verb.keepFile': 'Uložiť súbor do Súborov',
'assistant.change.label.attachedTo': 'Pripojené k',
'assistant.card.file.open': 'Otvoriť v Súboroch',
};
export default assistant;
+3
View File
@@ -492,5 +492,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Låt assistenten läsa filen',
'assistant.change.label.sentTo': 'Skickas till',
'assistant.step.readingAttachment': 'Läser filen',
'assistant.change.verb.keepFile': 'Spara filen i Filer',
'assistant.change.label.attachedTo': 'Bifogad till',
'assistant.card.file.open': 'Öppna i Filer',
};
export default assistant;
+3
View File
@@ -463,5 +463,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'อนุญาตให้ผู้ช่วยอ่านไฟล์',
'assistant.change.label.sentTo': 'ส่งไปยัง',
'assistant.step.readingAttachment': 'กำลังอ่านไฟล์',
'assistant.change.verb.keepFile': 'เก็บไฟล์ไว้ในไฟล์',
'assistant.change.label.attachedTo': 'แนบกับ',
'assistant.card.file.open': 'เปิดในไฟล์',
};
export default assistant;
+3
View File
@@ -492,5 +492,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Asistanın dosyayı okumasına izin ver',
'assistant.change.label.sentTo': 'Gönderileceği yer',
'assistant.step.readingAttachment': 'Dosya okunuyor',
'assistant.change.verb.keepFile': 'Dosyayı Dosyalar’a kaydet',
'assistant.change.label.attachedTo': 'Eklendiği yer',
'assistant.card.file.open': 'Dosyalar’da aç',
};
export default assistant;
+3
View File
@@ -536,5 +536,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Дозволити асистентові прочитати файл',
'assistant.change.label.sentTo': 'Надсилається до',
'assistant.step.readingAttachment': 'Читаю файл',
'assistant.change.verb.keepFile': 'Зберегти файл у Файлах',
'assistant.change.label.attachedTo': 'Прикріплено до',
'assistant.card.file.open': 'Відкрити у Файлах',
};
export default assistant;
+3
View File
@@ -466,5 +466,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': 'Cho phép trợ lý đọc tệp',
'assistant.change.label.sentTo': 'Gửi đến',
'assistant.step.readingAttachment': 'Đang đọc tệp',
'assistant.change.verb.keepFile': 'Lưu tệp vào Tệp',
'assistant.change.label.attachedTo': 'Đính kèm vào',
'assistant.card.file.open': 'Mở trong Tệp',
};
export default assistant;
+3
View File
@@ -457,5 +457,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': '允許助理讀取檔案',
'assistant.change.label.sentTo': '傳送至',
'assistant.step.readingAttachment': '正在讀取檔案',
'assistant.change.verb.keepFile': '將檔案儲存到檔案',
'assistant.change.label.attachedTo': '附加到',
'assistant.card.file.open': '在檔案中開啟',
};
export default assistant;
+3
View File
@@ -457,5 +457,8 @@ const assistant: TranslationStrings = {
'assistant.change.verb.readAttachment': '允许助手读取文件',
'assistant.change.label.sentTo': '发送至',
'assistant.step.readingAttachment': '正在读取文件',
'assistant.change.verb.keepFile': '把文件保存到文件',
'assistant.change.label.attachedTo': '附加到',
'assistant.card.file.open': '在文件中打开',
};
export default assistant;