mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-22 23:16:46 +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.
42 lines
1.9 KiB
TypeScript
42 lines
1.9 KiB
TypeScript
import { useTranslation } from '../../i18n';
|
|
import { chatOf, useAssistantStore } from '../../store/assistantStore';
|
|
import { useSettingsStore } from '../../store/settingsStore';
|
|
import { prefersReducedMotion } from '../../utils/reducedMotion';
|
|
import { liveStepText } from './assistantModel';
|
|
|
|
interface LiveStep {
|
|
/** The call the line speaks of. */
|
|
toolCallId: string;
|
|
/** "Searching near Trastevere": what the running step does, and where. */
|
|
text: string;
|
|
/**
|
|
* The step searches an area and the map is set to follow it there (the
|
|
* setting is on and motion is not reduced), so the line may say so.
|
|
*/
|
|
hasArea: boolean;
|
|
}
|
|
|
|
/**
|
|
* What the assistant is doing right now, in words, once a running step said
|
|
* where it looks: the line under the steps and the phone's pill read it. Null
|
|
* while no step names a place or a query. The step's name comes from the call
|
|
* in the chat; the place from the stream, which never stores it.
|
|
*/
|
|
export function useAssistantLiveStep(tripId: number): LiveStep | null {
|
|
const { t } = useTranslation();
|
|
const follow = useSettingsStore((s) => s.settings.assistant_map_follow) !== false;
|
|
const activity = useAssistantStore((s) => chatOf(s, tripId).live.activity);
|
|
const toolName = useAssistantStore((s) => {
|
|
const id = chatOf(s, tripId).live.activity?.toolCallId;
|
|
if (!id) return null;
|
|
const messages = chatOf(s, tripId).messages;
|
|
const last = messages[messages.length - 1];
|
|
const call = last?.parts.find((p) => p.type === 'tool-call' && p.toolCallId === id);
|
|
return call?.type === 'tool-call' ? call.toolName : null;
|
|
});
|
|
if (!activity || !toolName || !activity.label) return null;
|
|
const { key, params } = liveStepText(toolName, activity.label);
|
|
const hasArea = activity.area !== null && follow && !prefersReducedMotion();
|
|
return { toolCallId: activity.toolCallId, text: t(key, params), hasArea };
|
|
}
|