mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 22:46:32 +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.
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import './assistant.css';
|
|
|
|
import { AssistantRuntimeProvider } from '@assistant-ui/react';
|
|
import { useMemo } from 'react';
|
|
|
|
import AssistantThread from './AssistantThread';
|
|
import { type AssistantView, AssistantViewContext } from './assistantViewContext';
|
|
import { useAssistantRuntime } from './useAssistantRuntime';
|
|
|
|
export interface AssistantSurfaceProps extends AssistantView {
|
|
/** Named in the composer's placeholder. */
|
|
tripTitle: string;
|
|
}
|
|
|
|
/**
|
|
* The chat for one trip, the same on the desktop window and the phone screen.
|
|
* Its own chunk: this is the only module tree that pulls in @assistant-ui, so
|
|
* nobody downloads the chat runtime before opening the assistant.
|
|
*/
|
|
export default function AssistantSurface({
|
|
tripId,
|
|
tripTitle,
|
|
variant,
|
|
density,
|
|
onShowOnMap,
|
|
onFocusDay,
|
|
onRevealMap,
|
|
}: AssistantSurfaceProps) {
|
|
const runtime = useAssistantRuntime(tripId);
|
|
// The phone is always compact; a window is what its width says.
|
|
const view = useMemo(
|
|
() => ({
|
|
tripId,
|
|
variant,
|
|
density: variant === 'fullscreen' ? ('compact' as const) : (density ?? 'roomy'),
|
|
onShowOnMap,
|
|
onFocusDay,
|
|
onRevealMap,
|
|
}),
|
|
[tripId, variant, density, onShowOnMap, onFocusDay, onRevealMap]
|
|
);
|
|
return (
|
|
<AssistantRuntimeProvider runtime={runtime}>
|
|
<AssistantViewContext.Provider value={view}>
|
|
<AssistantThread tripTitle={tripTitle} />
|
|
</AssistantViewContext.Provider>
|
|
</AssistantRuntimeProvider>
|
|
);
|
|
}
|