feat(assistant): trip assistant chat with your own AI connection

Adds an in-app assistant that reads and plans the open trip. Users connect
their own provider (Sign in with ChatGPT, or an Anthropic, OpenAI, Gemini or
OpenRouter key) or use the one the admin set up, including a custom
OpenAI-compatible server. It is an addon and only shows while a connection
is usable.

The chat runs on the existing MCP tools, pinned to the trip. Every change is
held as a change card the user applies or discards, and applied changes can
be undone. On the desktop it is a floating window that can be moved and
resized; on the phone it is fullscreen. Search results show as place cards
that can go onto a day, weather lookups as a strip, proposed places as
ghost markers on the map with a before/after switch, and an answer can be
shared into the trip chat. Booking files can be dropped in and are read
into change cards.
This commit is contained in:
Maurice
2026-10-21 18:52:44 +02:00
parent bb3c0151d5
commit 214984f398
505 changed files with 51841 additions and 227 deletions
@@ -0,0 +1,84 @@
import { LLM_PHOTO_EXTENSIONS } from '@trek/shared';
import { type DragEvent, useState } from 'react';
import { useTranslation } from '../../i18n';
import { chatOf, useAssistantStore } from '../../store/assistantStore';
import { useToast } from '../shared/Toast';
/** What the booking import reads (the server checks again), and how big one file may be. */
export const ATTACH_EXTENSIONS: readonly string[] = [
'.pdf',
'.eml',
'.pkpass',
'.ics',
'.html',
'.htm',
'.txt',
...LLM_PHOTO_EXTENSIONS,
];
const MAX_ATTACH_BYTES = 10 * 1024 * 1024;
function extensionOf(name: string): string {
const dot = name.lastIndexOf('.');
return dot < 0 ? '' : name.slice(dot).toLowerCase();
}
function hasFiles(e: DragEvent): boolean {
return Array.from(e.dataTransfer.types).includes('Files');
}
/**
* Hands a booking file to the chat, from the paperclip, a paste or a drop on
* the window. One file at a time, refused here with a toast when it is not
* one the import reads or too big, so a wrong file never costs a round trip.
* The drop handlers go on the whole chat; `dragging` lights its drop zone.
*/
export function useAssistantAttach(tripId: number) {
const { t } = useTranslation();
const toast = useToast();
const attach = useAssistantStore((s) => s.attach);
const busy = useAssistantStore((s) => chatOf(s, tripId).isRunning);
const [dragging, setDragging] = useState(false);
const take = (files: FileList | File[] | null | undefined): boolean => {
const file = files ? Array.from(files)[0] : undefined;
if (!file) return false;
if (busy) return true;
if (!ATTACH_EXTENSIONS.includes(extensionOf(file.name))) {
toast.warning(t('assistant.attach.unsupported'));
return true;
}
if (file.size > MAX_ATTACH_BYTES) {
toast.warning(t('assistant.attach.tooLarge'));
return true;
}
void attach(tripId, file);
return true;
};
const dropZone = {
onDragEnter: (e: DragEvent) => {
if (!hasFiles(e)) return;
e.preventDefault();
setDragging(true);
},
onDragOver: (e: DragEvent) => {
if (!hasFiles(e)) return;
e.preventDefault();
e.dataTransfer.dropEffect = 'copy';
},
onDragLeave: (e: DragEvent) => {
// Leaving for a child is not leaving the zone.
if (e.currentTarget.contains(e.relatedTarget as Node | null)) return;
setDragging(false);
},
onDrop: (e: DragEvent) => {
if (!hasFiles(e)) return;
e.preventDefault();
setDragging(false);
take(e.dataTransfer.files);
},
};
return { take, busy, dragging, dropZone, accept: ATTACH_EXTENSIONS.join(',') };
}