mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-22 06:56:35 +00:00
214984f398
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.
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { useMemo } from 'react';
|
|
|
|
import { useTranslation } from '../../i18n';
|
|
import { useCanDo } from '../../store/permissionsStore';
|
|
import { useTripStore } from '../../store/tripStore';
|
|
import { localIsoDate } from '../../utils/localDate';
|
|
import { suggestionsFor, tripPhase } from './assistantModel';
|
|
import { useAssistantFocus } from './useAssistantFocus';
|
|
|
|
export interface ReadySuggestion {
|
|
id: string;
|
|
/** What the button says, and the question it sends. */
|
|
prompt: string;
|
|
}
|
|
|
|
/**
|
|
* The questions the empty chat offers, worded and ready to send, and whether
|
|
* the user may change this trip at all. For a trip the planner is not showing
|
|
* (one picked from the dashboard) neither its dates nor its rights are at
|
|
* hand, so it gets the general questions and none that would change it.
|
|
*/
|
|
export function useAssistantSuggestions(tripId: number): { suggestions: ReadySuggestion[]; canEdit: boolean } {
|
|
const { t } = useTranslation();
|
|
const can = useCanDo();
|
|
const trip = useTripStore((s) => (s.trip?.id === tripId ? s.trip : null));
|
|
const hasPlaces = useTripStore((s) => s.places.length > 0);
|
|
const { label, kind } = useAssistantFocus(tripId);
|
|
const canEdit = !!trip && can('place_edit', trip);
|
|
|
|
const suggestions = useMemo(() => {
|
|
const phase = trip
|
|
? tripPhase({
|
|
startDate: trip.start_date ?? null,
|
|
endDate: trip.end_date ?? null,
|
|
hasPlaces,
|
|
today: localIsoDate(),
|
|
})
|
|
: 'upcoming';
|
|
return suggestionsFor({
|
|
phase,
|
|
canEdit,
|
|
place: kind === 'place' ? label : null,
|
|
day: kind === 'day' ? label : null,
|
|
}).map((s) => ({ id: s.id, prompt: t(s.labelKey, s.params) }));
|
|
}, [trip, hasPlaces, canEdit, kind, label, t]);
|
|
|
|
return { suggestions, canEdit };
|
|
}
|