Files
TREK/client/src/components/Assistant/useTripMemory.ts
T
Maurice 26df56d76c feat(assistant): one AI tile for assistant, parsing and MCP, a planner-aware chat
The three AI addons share one tile in the integration column; a dialog holds
the connection, the assistant's limits and AI parsing, which now reads with
the assistant's connection unless an install keeps its own. Existing parsing
configs stay where they are and keep winning.

The chat sees the map on screen, offers next questions under an answer,
shows its live step in the window head, previews waiting changes inside the
day list, checks whether a day still works, folds a multi-day plan into a
week grid, keeps per-trip notes and can estimate costs. An empty or cut-off
answer gets one push instead of ending silently, and the assistant's own
step and size limits are raised.
2026-10-21 22:29:57 +02:00

39 lines
1.4 KiB
TypeScript

import { useTranslation } from '../../i18n';
import { useSettingsStore } from '../../store/settingsStore';
import { useToast } from '../shared/Toast';
/** As long as the server reads a trip's notes; more is cut there. */
export const MAX_MEMORY_CHARS = 2_000;
/**
* What the user keeps for the assistant to mind on one trip ("vegetarian, no
* museums"): read from and saved to their settings, one entry per trip, so it
* follows them to every device. Every question on the trip carries it. The
* same for the window and the phone.
*/
export function useTripMemory(tripId: number) {
const { t } = useTranslation();
const toast = useToast();
const all = useSettingsStore((s) => s.settings.assistant_memory);
const updateSetting = useSettingsStore((s) => s.updateSetting);
const text = all?.[String(tripId)] ?? '';
/** Saves the notes; empty ones are dropped rather than kept as a blank entry. */
const save = async (next: string): Promise<boolean> => {
const trimmed = next.trim().slice(0, MAX_MEMORY_CHARS);
const rest = { ...(all ?? {}) };
if (trimmed) rest[String(tripId)] = trimmed;
else delete rest[String(tripId)];
try {
await updateSetting('assistant_memory', rest);
toast.success(t('assistant.memory.saved'));
return true;
} catch (e: unknown) {
toast.error(e instanceof Error ? e.message : t('common.error'));
return false;
}
};
return { text, has: text.trim().length > 0, save };
}