mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 13:23:04 +00:00
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:
@@ -0,0 +1,67 @@
|
||||
// FE-MAP-GHOST-GL-001 to 002: the assistant's suggestions on the GL map, as hand-positioned pins.
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { AssistantGhost } from './mapViewContract';
|
||||
import { useAssistantGhostMarkersGL } from './useAssistantGhostMarkersGL';
|
||||
|
||||
const GHOSTS: AssistantGhost[] = [
|
||||
{ id: 'a', lat: 41.9, lng: 12.48, name: 'Pantheon' },
|
||||
{ id: 'b', lat: 41.89, lng: 12.49, name: '<b>Forum</b>' },
|
||||
];
|
||||
|
||||
function setup(hoveredId: string | null = null) {
|
||||
const container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
const map = { getContainer: () => container, on: vi.fn(), off: vi.fn() };
|
||||
const attached: { el: HTMLElement; lng: number; lat: number; remove: ReturnType<typeof vi.fn> }[] = [];
|
||||
const pinsRef = { current: [] as { remove: () => void }[] };
|
||||
const onHover = vi.fn();
|
||||
const hook = renderHook(
|
||||
({ hovered }) =>
|
||||
useAssistantGhostMarkersGL({
|
||||
mapRef: { current: map },
|
||||
mapReady: true,
|
||||
pinsRef,
|
||||
attachPin: (el, lng, lat) => {
|
||||
container.appendChild(el);
|
||||
const pin = { el, lng, lat, remove: vi.fn(() => el.remove()) };
|
||||
attached.push(pin);
|
||||
return pin;
|
||||
},
|
||||
ghosts: GHOSTS,
|
||||
hoveredId: hovered,
|
||||
onHover,
|
||||
onClick: vi.fn(),
|
||||
}),
|
||||
{ initialProps: { hovered: hoveredId } }
|
||||
);
|
||||
return { container, attached, pinsRef, onHover, hook };
|
||||
}
|
||||
|
||||
describe('useAssistantGhostMarkersGL', () => {
|
||||
it('FE-MAP-GHOST-GL-001: puts each ghost where it belongs, hands the pins to the reposition, and names it as text', () => {
|
||||
const { container, attached, pinsRef, onHover } = setup();
|
||||
expect(attached.map((p) => [p.lng, p.lat])).toEqual([
|
||||
[12.48, 41.9],
|
||||
[12.49, 41.89],
|
||||
]);
|
||||
expect(pinsRef.current).toHaveLength(2);
|
||||
attached[1]?.el.dispatchEvent(new Event('pointerenter'));
|
||||
expect(onHover).toHaveBeenCalledWith('b');
|
||||
const label = container.querySelector('[data-testid="assistant-ghost-label"]');
|
||||
expect(label?.textContent).toBe('<b>Forum</b>');
|
||||
expect(label?.querySelector('b')).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-MAP-GHOST-GL-002: a hover marks its ghost without rebuilding a pin, and unmounting takes them all off', () => {
|
||||
const { attached, pinsRef, hook } = setup();
|
||||
act(() => hook.rerender({ hovered: 'a' }));
|
||||
expect(attached).toHaveLength(2);
|
||||
expect(attached[0]?.el.classList.contains('is-hot')).toBe(true);
|
||||
expect(attached[1]?.el.classList.contains('is-hot')).toBe(false);
|
||||
|
||||
hook.unmount();
|
||||
expect(attached.every((p) => p.remove.mock.calls.length === 1)).toBe(true);
|
||||
expect(pinsRef.current).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user