Compare commits

...

5 Commits

Author SHA1 Message Date
Maurice 067ab89430 fix(calendar): give transport events a LOCATION and GEO from their endpoints
A car or other transport booking carried its route only in the description, so
a calendar app had no place to navigate to. Without a location of its own, a
transport event now takes the endpoint the traveller has to get to: the
destination of a drive of their own (car, bicycle) and the departure of a ride
they board, the side the per-leg events already use. A car's pickup and
drop-off events are located at their own endpoints. A location the booking
states keeps winning.

Closes #2909
2026-10-30 21:54:19 +01:00
Maurice 019c668744 fix(llm-parse): ask Anthropic models for the extraction tool instead of forcing it
Claude Sonnet 5.5, Opus 5.5 and Fable 5.1 reject tool_choice type "tool" and
"any" with a 400, so every booking import through the Anthropic provider failed
on them. The request now sends tool_choice auto with parallel tool use off,
which every Anthropic model and Messages-compatible gateway accepts, and the
system prompt tells the model to answer through the emit tool exactly once. A
model that still answers in text is reported as before.

Closes #2902
2026-10-30 21:54:19 +01:00
Maurice b953ece4b3 fix(journey): stop the entry views from shifting while photos and providers load
Opening an entry on the share page showed the hero at no height until the
original arrived, then pushed the story down, and the lightbox stayed black
until the full photo had loaded. The hero now reserves the photo's proportions
(4:3 when none were recorded) with its thumbnail behind it, and the lightbox
shows the thumbnail and a spinner until the original is in.

The phone entry sheet probed the photo providers again on every open and added
the External photos button once the answer came, squeezing the icons of the
other two buttons. The journey screen already knows the connected providers, so
it hands them to the sheet, and the icons keep their size.

The picked neutral mood was a grey tint on a grey sheet; a picked mood is now
framed in its full colour and announced as pressed.

Closes #2907
Closes #2908
Closes #2905
2026-10-30 21:15:38 +01:00
Maurice 94a9cbf070 fix(journey): draw the live Dawarich trail in the colour of its day
The live trail arrived in Dawarich's own day palette, counted from the first
recorded day, while a journey colours its days by the entries. A day's line and
its pins therefore wore different colours. The trail of a day that has entries
now takes that day's colour, the way the kept recordings already did.

Closes #2906
2026-10-30 21:15:37 +01:00
Maurice 8eebcea9f5 fix(journey): keep GL photo markers absolutely positioned so thumbnails sit on their coordinates
The journey map's photo thumbnails set position:relative inline on the marker
element. That overrides the engine's .mapboxgl-marker/.maplibregl-marker
position:absolute, so every thumbnail entered the normal flow below the ones
drawn before it and the engine's translate was added on top: the further down
the list, the further the photo drifted from its spot. The location dot had the
same inline position. Both now leave position to the engine's class.

Closes #2910
2026-10-30 21:15:37 +01:00
23 changed files with 323 additions and 139 deletions
+2 -2
View File
@@ -4,12 +4,12 @@
"@typescript-eslint/no-misused-promises": 847,
"no-console": 88,
"complexity": 218,
"@typescript-eslint/no-explicit-any": 146,
"@typescript-eslint/no-explicit-any": 144,
"trek/no-swallowed-catch": 129,
"max-params": 32,
"trek/store-without-selector": 67,
"react-hooks/refs": 555,
"react-hooks/set-state-in-effect": 194,
"react-hooks/set-state-in-effect": 193,
"@typescript-eslint/no-floating-promises": 164,
"react-hooks/exhaustive-deps": 116,
"@typescript-eslint/no-unused-vars": 124,
@@ -1,4 +1,4 @@
// FE-COMP-JMAPGL-001 to FE-COMP-JMAPGL-048, FE-COMP-JMAPGL-2453
// FE-COMP-JMAPGL-001 to FE-COMP-JMAPGL-048, FE-COMP-JMAPGL-2453, FE-COMP-JMAPGL-2910
type Spy = ReturnType<typeof vi.fn>
@@ -644,6 +644,15 @@ describe('JourneyMapGL', () => {
expect(gl.map.on).toHaveBeenCalledWith('moveend', expect.any(Function))
})
it('FE-COMP-JMAPGL-2910: no marker element sets its own position, so the engine keeps it absolute', () => {
withToken()
const photos = [{ id: 'a', lat: 45, lng: 5, thumbUrl: '/api/photos/1/thumbnail' }]
const marks = [{ kind: 'stay', key: 's1', lat: 46, lng: 6, color: '#14b8a6', stay: {} }]
render(<JourneyMapGL checkins={[]} entries={entries} photos={photos} marks={marks} />)
expect(gl.markers.some(m => m.element.innerHTML.includes('/api/photos/'))).toBe(true)
for (const marker of gl.markers) expect(marker.element.style.position).toBe('')
})
it('FE-COMP-JMAPGL-2889: panning keeps the photo and mark groups, only a zoom regroups them', () => {
withToken()
const photos = [
@@ -557,7 +557,10 @@ function JourneyMapGL(
if (!photos?.length) return
for (const cluster of clusterPhotos(photos, glWorldPx(map))) {
const el = document.createElement('div')
el.style.cssText = 'position:relative;width:48px;height:48px;cursor:pointer'
// No inline `position` (#2910): the engine's marker class positions the element
// absolutely, and `position:relative` would drop it into the normal flow, where
// every thumbnail sits below the ones drawn before it.
el.style.cssText = 'width:48px;height:48px;cursor:pointer'
el.innerHTML = photoMarkerHtml(cluster.members[0].thumbUrl, cluster.members.length)
el.addEventListener('click', (ev) => {
ev.stopPropagation()
@@ -1,4 +1,4 @@
// FE-COMP-JENTRYVIEW-001 to FE-COMP-JENTRYVIEW-020
// FE-COMP-JENTRYVIEW-001 to FE-COMP-JENTRYVIEW-022
import { render, screen, fireEvent } from '../../../tests/helpers/render'
import { resetAllStores, seedStore } from '../../../tests/helpers/store'
@@ -136,6 +136,18 @@ describe('MobileEntryView', () => {
expect(container.querySelector('svg.lucide-camera')).toBeNull()
})
it('FE-COMP-JENTRYVIEW-021: the hero holds the proportions of the photo and shows its thumbnail before the original arrives (#2907)', () => {
const { container } = renderView(buildEntry({ photos: [{ ...buildPhoto(4), width: 3000, height: 2000 }] }))
const hero = container.querySelector('img') as HTMLImageElement
expect(hero.style.aspectRatio).toBe('3000 / 2000')
expect(hero.style.backgroundImage).toContain('/api/photos/4/thumbnail')
})
it('FE-COMP-JENTRYVIEW-022: a photo without recorded dimensions still reserves a 4:3 hero', () => {
const { container } = renderView(buildEntry({ photos: [buildPhoto(4)] }))
expect((container.querySelector('img') as HTMLImageElement).style.aspectRatio).toBe('4 / 3')
})
it('FE-COMP-JENTRYVIEW-008: several photos add a counter and a thumbnail strip', () => {
const { container } = renderView(buildEntry({ photos: [buildPhoto(4), buildPhoto(5), buildPhoto(6)] }))
expect(screen.getByText('3 photos')).toBeInTheDocument()
@@ -4,6 +4,7 @@ import {
Sun, CloudSun, Cloud, CloudRain, CloudLightning, Snowflake,
ThumbsUp, ThumbsDown,
} from 'lucide-react'
import type { CSSProperties } from 'react'
import JournalBody from './JournalBody'
import { useTranslation } from '../../i18n'
import { formatLocationName } from '../../utils/formatters'
@@ -39,6 +40,22 @@ function photoUrl(
return `/api/photos/${p.photo_id}/${size}`
}
/**
* The hero's box before its picture arrives (#2907): the photo's own proportions
* when the upload recorded them, else 4:3, so the story below does not jump down
* once the original has loaded. The thumbnail, usually cached by the strip or the
* feed already, fills that box meanwhile.
*/
function heroPlaceholderStyle(photo: JourneyPhoto, thumbUrl: string): CSSProperties {
const ratio = photo.width && photo.height ? `${photo.width} / ${photo.height}` : '4 / 3'
return {
aspectRatio: ratio,
backgroundImage: `url("${encodeURI(thumbUrl)}")`,
backgroundSize: 'cover',
backgroundPosition: 'center',
}
}
interface Props {
entry: JourneyEntry
readOnly?: boolean
@@ -114,8 +131,10 @@ export default function MobileEntryView({ entry, readOnly, publicPhotoUrl, onClo
<img
src={photoUrl(photos[0], photos[0].media_type === 'video' ? 'thumbnail' : 'original', publicPhotoUrl)}
alt=""
className={`w-full max-h-[50vh] ${photos[0].media_type === 'video' ? 'object-contain' : 'object-cover'
decoding="async"
className={`block w-full max-h-[50vh] bg-surface-secondary ${photos[0].media_type === 'video' ? 'object-contain' : 'object-cover'
}`}
style={heroPlaceholderStyle(photos[0], photoUrl(photos[0], 'thumbnail', publicPhotoUrl))}
/>
)}
@@ -143,7 +162,7 @@ export default function MobileEntryView({ entry, readOnly, publicPhotoUrl, onClo
key={p.id || i}
type="button"
aria-label={p.caption || t('journey.photos')}
className={`relative h-16 w-16 flex-shrink-0 cursor-pointer overflow-hidden rounded-lg border-0 p-0 hover:ring-2 ring-zinc-900/30 dark:ring-white/30 transition-all ${p.media_type === 'video' ? 'bg-black' : 'bg-transparent'
className={`relative h-16 w-16 flex-shrink-0 cursor-pointer overflow-hidden rounded-lg border-0 p-0 hover:ring-2 ring-zinc-900/30 dark:ring-white/30 transition-all ${p.media_type === 'video' ? 'bg-black' : 'bg-surface-secondary'
}`}
onClick={() => onPhotoClick(photos, i)}
>
@@ -1,4 +1,4 @@
// FE-COMP-LIGHTBOX-001 to FE-COMP-LIGHTBOX-027
// FE-COMP-LIGHTBOX-001 to FE-COMP-LIGHTBOX-029
// Plyr needs a real media pipeline, so the player is stubbed here.
vi.mock('./VideoPlayer', () => ({
@@ -326,4 +326,28 @@ describe('PhotoLightbox', () => {
expect(screen.getByText('Google', { selector: 'p' })).toBeInTheDocument();
expect(screen.queryByRole('link')).not.toBeInTheDocument();
});
it('FE-COMP-LIGHTBOX-028: the thumbnail and a spinner stand in until the original has loaded (#2907)', () => {
const { container } = render(
<PhotoLightbox photos={[{ id: 'a', src: '/a/original', thumbSrc: '/a/thumbnail' }]} onClose={vi.fn()} />,
);
const placeholder = screen.getByTestId('lightbox-loading');
expect(placeholder.querySelector('img')).toHaveAttribute('src', '/a/thumbnail');
expect(placeholder.querySelector('svg.animate-spin')).toBeInTheDocument();
fireEvent.load(container.ownerDocument.querySelector('img[src="/a/original"]') as HTMLImageElement);
expect(screen.queryByTestId('lightbox-loading')).not.toBeInTheDocument();
});
it('FE-COMP-LIGHTBOX-029: the next photo waits for its own original, and a failed one drops the spinner too', () => {
render(
<PhotoLightbox photos={[{ id: 'a', src: '/a.jpg' }, { id: 'b', src: '/b.jpg' }]} onClose={vi.fn()} />,
);
fireEvent.load(document.querySelector('img[src="/a.jpg"]') as HTMLImageElement);
expect(screen.queryByTestId('lightbox-loading')).not.toBeInTheDocument();
fireEvent.keyDown(window, { key: 'ArrowRight' });
expect(screen.getByTestId('lightbox-loading')).toBeInTheDocument();
fireEvent.error(document.querySelector('img[src="/b.jpg"]') as HTMLImageElement);
expect(screen.queryByTestId('lightbox-loading')).not.toBeInTheDocument();
});
});
@@ -1,5 +1,5 @@
import { useState, useEffect, useCallback, useRef } from 'react'
import { ChevronLeft, ChevronRight, X, ZoomIn, ZoomOut } from 'lucide-react'
import { ChevronLeft, ChevronRight, Loader2, X, ZoomIn, ZoomOut } from 'lucide-react'
import VideoPlayer from './VideoPlayerLazy'
import { usePhotoZoom } from './usePhotoZoom'
import { Tooltip } from '../shared/Tooltip'
@@ -8,6 +8,12 @@ import { isRtlLanguage, useTranslation } from '../../i18n'
interface LightboxPhoto {
id: string
src: string
/**
* A small rendition of the same photo, usually cached already by the grid that
* opened the lightbox. It stands in while the original loads, which on a slow
* server or connection can take seconds (#2907).
*/
thumbSrc?: string
caption?: string | null
/** Where the caption's credit points to (a photo's source page), opened in a new tab. */
captionHref?: string | null
@@ -52,6 +58,9 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
// Zoom starts over on every photo (#1484).
const zoom = usePhotoZoom(photo?.id)
const isImage = !!photo && photo.mediaType !== 'video'
// The id whose original has finished (or failed) loading; any other photo is still on its way.
const [loadedId, setLoadedId] = useState<string | null>(null)
const loading = isImage && loadedId !== photo.id
const hasPrev = idx > 0
const hasNext = idx < photos.length - 1
@@ -187,6 +196,8 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
src={photo.src}
alt={photo.caption || ''}
draggable={false}
onLoad={() => setLoadedId(photo.id)}
onError={() => setLoadedId(photo.id)}
{...zoom.mouse}
style={{
maxWidth: '92vw', maxHeight: '92vh',
@@ -198,6 +209,17 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
/>
)}
{loading && (
<div data-testid="lightbox-loading" aria-hidden="true" style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', pointerEvents: 'none' }}>
{photo.thumbSrc && (
<img src={photo.thumbSrc} alt="" draggable={false} style={{ width: '92vw', height: '92vh', objectFit: 'contain', borderRadius: 4 }} />
)}
<span style={{ ...ROUND_BTN, position: 'absolute', cursor: 'default' }}>
<Loader2 size={18} className="animate-spin" />
</span>
</div>
)}
{/* Next button */}
{hasNext && (
<button type="button" onClick={next} aria-label={t('journey.lightbox.next')} className="flex sm:opacity-0 sm:group-hover/lightbox:opacity-100 focus-visible:opacity-100 transition-opacity" style={{
@@ -97,6 +97,8 @@ describe('attachLocationMarker', () => {
expect(root.children).toHaveLength(3)
// The cone starts hidden — there is no heading until the first fix.
expect((root.children[1] as HTMLElement).style.display).toBe('none')
// The GL marker class owns `position`; an inline one would drop it into the flow.
expect(root.style.position).toBe('')
})
it('FE-COMP-LOCMARKERGL-003: adds the accuracy source and fill layer when the map is already loaded', () => {
@@ -13,7 +13,9 @@ type MarkerConstructor = new (options?: { element?: HTMLElement; anchor?: string
// and mapbox doesn't get confused about which element to position.
function buildLocationEl(): { root: HTMLDivElement; cone: HTMLDivElement } {
const root = document.createElement('div')
root.style.cssText = 'width:28px;height:28px;position:relative;pointer-events:none;'
// No inline `position`: the GL marker class keeps the root absolute, which the
// children's insets resolve against (see the note on markers in MapViewGL).
root.style.cssText = 'width:28px;height:28px;pointer-events:none;'
// Accuracy pulse behind the dot
const pulse = document.createElement('div')
pulse.style.cssText = `
@@ -258,6 +258,7 @@ export default function MJourneyDetail({ journeyId, embedded = false }: JourneyD
photos: photos.map(p => ({
id: p.id,
src: photoUrl(p, 'original'),
thumbSrc: photoUrl(p, 'thumbnail'),
caption: p.caption ?? null,
provider: p.provider,
asset_id: p.asset_id,
@@ -590,6 +591,7 @@ export default function MJourneyDetail({ journeyId, embedded = false }: JourneyD
showWeather={current.show_weather !== 0}
userId={useAuthStore.getState().user?.id || 0}
trips={current.trips}
photoProviders={availableProviders}
onMoveEarlier={
canEditEntries && editingEntry.id !== 0 && editingEntry.type !== 'skeleton' && dayNeighbours(editingEntry).canMoveUp
? () => { void moveWithinDay(editingEntry, -1) }
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useRef, useState } from 'react'
import { useRef, useState, type CSSProperties } from 'react'
import { Briefcase, Camera, Plus, Image, Images, X, MapPin, Locate, Trash2, CheckCircle2, MinusCircle, ChevronUp, ChevronDown, EyeOff, Play } from 'lucide-react'
import MSheet from '../../components/MSheet'
import MIconBtn from '../../components/MIconBtn'
@@ -9,13 +9,23 @@ import { CustomDatePicker } from '../../../components/shared/CustomDateTimePicke
import { isVideoFile } from '../../../utils/videoPoster'
import type { ResilientResult, UploadProgress } from '../../../utils/uploadQueue'
import type { JourneyEntry, JourneyPhoto, GalleryPhoto, JourneyTrip } from '../../../store/journeyStore'
import { useAddonStore } from '../../../store/addonStore'
import { photoUrl, posterlessVideo } from '../../../pages/journeyDetail/JourneyDetailPage.helpers'
import JournalBody from '../../../components/Journey/JournalBody'
import { ProviderPicker } from '../../../components/Journey/JourneyDetailPageProviderPicker'
import { MOBILE_MOODS, MOBILE_WEATHERS } from './mobileJourneyMeta'
import { useJourneyEntryForm, type PendingProviderGroup } from '../../../components/Journey/useJourneyEntryForm'
const NO_PROVIDERS: { id: string; name: string }[] = []
/**
* A picked mood chip: its colour as the frame and the label, a light wash of it
* behind. The frame is the full colour because a tint alone left the grey neutral
* mood looking like the chips at rest on a dark sheet (#2905).
*/
function moodChipActiveStyle(color: string): CSSProperties {
return { background: `${color}33`, color, borderColor: color }
}
const PRO_COLOR = '#2FA37A'
const CON_COLOR = '#D6273B'
@@ -38,6 +48,12 @@ interface MJourneyEntrySheetProps {
readOnly?: boolean
userId?: number
trips?: JourneyTrip[]
/**
* The photo providers (Immich, Synology Photos) connected for this user. The
* journey screen asks once when it opens, so the sheet has the answer the
* moment it appears instead of probing again and growing a button later (#2908).
*/
photoProviders?: { id: string; name: string }[]
/** The optional fields this journey still keeps (discussion #2299). Values are never cleared. */
showVerdict?: boolean
showMood?: boolean
@@ -68,7 +84,7 @@ interface MJourneyEntrySheetProps {
* search, mood (4), weather (6) and tags. Read-only for viewer contributors.
*/
export default function MJourneyEntrySheet({
entry, galleryPhotos, quickCapture = false, readOnly = false, userId = 0, trips = [],
entry, galleryPhotos, quickCapture = false, readOnly = false, userId = 0, trips = [], photoProviders: providers = NO_PROVIDERS,
showVerdict = true, showMood = true, showWeather = true, onMoveEarlier, onMoveLater, onDismiss,
onClose, onSave, onUploadPhotos, onAddProviderPhotos, onDelete, onDone,
}: MJourneyEntrySheetProps) {
@@ -88,41 +104,10 @@ export default function MJourneyEntrySheet({
})
const [showExternal, setShowExternal] = useState(false)
const [externalProvider, setExternalProvider] = useState<string | null>(null)
const [providers, setProviders] = useState<{ id: string; name: string }[]>([])
const [captureOnly, setCaptureOnly] = useState(quickCapture)
const fileRef = useRef<HTMLInputElement>(null)
const cameraRef = useRef<HTMLInputElement>(null)
// The addon list is already in the store — this only probes which of the
// photo providers is actually connected for this user.
const addons = useAddonStore(s => s.addons)
const addonsLoaded = useAddonStore(s => s.loaded)
const photoProviders = useMemo(
() => addons.filter(a => a.type === 'photo_provider' && a.enabled).map(a => ({ id: a.id, name: a.name })),
[addons],
)
useEffect(() => {
if (readOnly) return
// App.tsx loads the addon list on boot, so this only reacts to it. Kicking off
// a second load from here would race the other consumers, and loadAddons
// overwrites the list unconditionally when it lands.
if (!addonsLoaded) return
if (photoProviders.length === 0) { setProviders([]); return }
let active = true
;void (async () => {
const connected: { id: string; name: string }[] = []
for (const provider of photoProviders) {
try {
const res = await fetch(`/api/integrations/memories/${provider.id}/status`, { credentials: 'include' })
if (res.ok && (await res.json()).connected) connected.push(provider)
} catch { /* provider stays hidden */ }
}
if (active) setProviders(connected)
})()
return () => { active = false }
}, [readOnly, addonsLoaded, photoProviders])
const activeProvider = externalProvider || providers[0]?.id || null
const providerExistingAssetIds = providerAssetIds(activeProvider)
@@ -191,13 +176,13 @@ export default function MJourneyEntrySheet({
>
{uploadProgress ? (
<>
<span className="h-[14px] w-[14px] animate-spin rounded-full border-2 border-[color:var(--m-rowbr)] border-t-m-muted" />
{t('journey.editor.uploadingProgress', { done: String(uploadProgress.done), total: String(uploadProgress.total) })}
<span className="h-[14px] w-[14px] shrink-0 animate-spin rounded-full border-2 border-[color:var(--m-rowbr)] border-t-m-muted" />
<span className="truncate">{t('journey.editor.uploadingProgress', { done: String(uploadProgress.done), total: String(uploadProgress.total) })}</span>
</>
) : (
<>
{captureOnly ? <Camera size={14} strokeWidth={2.2} /> : <Plus size={14} strokeWidth={2.2} />}
{captureOnly ? t('journey.photo.add') : t('journey.editor.uploadPhotos')}
{captureOnly ? <Camera size={14} strokeWidth={2.2} className="shrink-0" /> : <Plus size={14} strokeWidth={2.2} className="shrink-0" />}
<span className="truncate">{captureOnly ? t('journey.photo.add') : t('journey.editor.uploadPhotos')}</span>
</>
)}
</button>
@@ -215,12 +200,14 @@ export default function MJourneyEntrySheet({
: 'border-dashed border-[color:var(--m-rowbr)] text-m-muted'
}`}
>
<Image size={14} strokeWidth={2} />
{captureOnly ? t('journey.share.gallery') : t('journey.editor.fromGallery')}
<Image size={14} strokeWidth={2} className="shrink-0" />
<span className="truncate">{captureOnly ? t('journey.share.gallery') : t('journey.editor.fromGallery')}</span>
</button>
{/* Immich/Synology, the same source the desktop editor offers (#1808).
Only shown once a provider is actually connected — on a phone a
button that can only say "nothing connected" is not worth its width. */}
Only shown once a provider is actually connected: on a phone a
button that can only say "nothing connected" is not worth its width.
The icons keep their size and the labels truncate, so a third
button never squeezes the other two (#2908). */}
{!captureOnly && providers.length > 0 && (
<button
type="button"
@@ -232,8 +219,8 @@ export default function MJourneyEntrySheet({
: 'border-dashed border-[color:var(--m-rowbr)] text-m-muted'
}`}
>
<Images size={14} strokeWidth={2} />
{t('journey.editor.externalPhotos')}
<Images size={14} strokeWidth={2} className="shrink-0" />
<span className="truncate">{t('journey.editor.externalPhotos')}</span>
</button>
)}
</div>
@@ -627,11 +614,12 @@ export default function MJourneyEntrySheet({
key={m.id}
type="button"
disabled={readOnly}
aria-pressed={active}
onClick={() => setMood(active ? '' : m.id)}
className={`flex items-center gap-[5px] rounded-full border px-3 py-[7px] text-[0.71875rem] font-semibold ${
active ? '' : 'border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] text-m-muted'
}`}
style={active ? { background: `${m.color}24`, color: m.color, borderColor: `${m.color}4D` } : undefined}
style={active ? moodChipActiveStyle(m.color) : undefined}
>
<m.icon size={13} strokeWidth={2.2} />
{t(m.labelKey)}
+4 -4
View File
@@ -213,7 +213,7 @@ export function JourneyDetailPageDesktop({ journeyId, embedded = false }: Journe
onClose={() => setViewingEntry(null)}
onEdit={() => { setViewingEntry(null); setEditingEntry(viewingEntry); }}
onDelete={() => { setViewingEntry(null); setDeleteTarget(viewingEntry); }}
onPhotoClick={(photos, idx) => setLightbox({ photos: photos.map(p => ({ id: p.id, src: photoUrl(p, 'original'), caption: p.caption, provider: p.provider, asset_id: p.asset_id, owner_id: p.owner_id, mediaType: p.media_type })), index: idx })}
onPhotoClick={(photos, idx) => setLightbox({ photos: photos.map(p => ({ id: p.id, src: photoUrl(p, 'original'), thumbSrc: photoUrl(p, 'thumbnail'), caption: p.caption, provider: p.provider, asset_id: p.asset_id, owner_id: p.owner_id, mediaType: p.media_type })), index: idx })}
/>
)}
@@ -602,7 +602,7 @@ export function JourneyDetailPageDesktop({ journeyId, embedded = false }: Journe
readOnly={!canEditEntries}
onEdit={() => setEditingEntry(entry)}
onDelete={() => setDeleteTarget(entry)}
onPhotoClick={(photos, idx) => setLightbox({ photos: photos.map(p => ({ id: p.id, src: photoUrl(p, 'original'), caption: p.caption, provider: p.provider, asset_id: p.asset_id, owner_id: p.owner_id, mediaType: p.media_type })), index: idx })}
onPhotoClick={(photos, idx) => setLightbox({ photos: photos.map(p => ({ id: p.id, src: photoUrl(p, 'original'), thumbSrc: photoUrl(p, 'thumbnail'), caption: p.caption, provider: p.provider, asset_id: p.asset_id, owner_id: p.owner_id, mediaType: p.media_type })), index: idx })}
/>
)}
</div>
@@ -656,7 +656,7 @@ export function JourneyDetailPageDesktop({ journeyId, embedded = false }: Journe
userId={useAuthStore.getState().user?.id || 0}
trips={current.trips}
canEdit={canEditEntries}
onPhotoClick={(photos, idx) => setLightbox({ photos: photos.map(p => ({ id: p.id, src: photoUrl(p, 'original'), caption: p.caption ?? null, provider: p.provider, asset_id: p.asset_id, owner_id: p.owner_id, mediaType: p.media_type })), index: idx })}
onPhotoClick={(photos, idx) => setLightbox({ photos: photos.map(p => ({ id: p.id, src: photoUrl(p, 'original'), thumbSrc: photoUrl(p, 'thumbnail'), caption: p.caption ?? null, provider: p.provider, asset_id: p.asset_id, owner_id: p.owner_id, mediaType: p.media_type })), index: idx })}
onRefresh={() => loadJourney(Number(id))}
onAddProviderPhotos={addPickedProviderPhotos}
/>
@@ -735,7 +735,7 @@ export function JourneyDetailPageDesktop({ journeyId, embedded = false }: Journe
const entry = current.entries.find(e => String(e.id) === entryId)
if (!entry?.photos?.length) return
setLightbox({
photos: entry.photos.map(p => ({ id: p.id, src: photoUrl(p, 'original'), caption: p.caption, provider: p.provider, asset_id: p.asset_id, owner_id: p.owner_id, mediaType: p.media_type })),
photos: entry.photos.map(p => ({ id: p.id, src: photoUrl(p, 'original'), thumbSrc: photoUrl(p, 'thumbnail'), caption: p.caption, provider: p.provider, asset_id: p.asset_id, owner_id: p.owner_id, mediaType: p.media_type })),
index,
})
}}
+18 -24
View File
@@ -72,6 +72,20 @@ function photoUrl(p: { photo_id: number }, shareToken: string, kind: 'thumbnail'
return `/api/public/journey/${shareToken}/photos/${p.photo_id}/${kind}`;
}
type SharedPhoto = { id: number | string; photo_id: number; caption?: string | null; media_type?: string | null };
// The lightbox opens on the original and shows the thumbnail the page already
// loaded until it arrives, instead of a black screen (#2907).
function lightboxPhoto(p: SharedPhoto, shareToken: string) {
return {
id: String(p.id),
src: photoUrl(p, shareToken, 'original'),
thumbSrc: photoUrl(p, shareToken, 'thumbnail'),
caption: p.caption ?? null,
mediaType: p.media_type,
};
}
// The share route answers 404 for the thumbnail of a clip that has no poster, and
// an <img> pointed at it draws the broken-image glyph (#2341). The black ground
// the layouts give a video stands in for the picture.
@@ -172,12 +186,7 @@ export default function JourneyPublicPage() {
const picked = allPhotos.filter((p) => wanted.has(String(p.id)));
if (!token || picked.length === 0) return;
setLightbox({
photos: picked.map((p) => ({
id: String(p.id),
src: photoUrl(p, token, 'original'),
caption: p.caption,
mediaType: p.media_type,
})),
photos: picked.map((p) => lightboxPhoto(p, token)),
index: 0,
});
};
@@ -243,12 +252,7 @@ export default function JourneyPublicPage() {
const prosArr = entry.pros_cons?.pros ?? [];
const consArr = entry.pros_cons?.cons ?? [];
const hasProscons = prosArr.length > 0 || consArr.length > 0;
const lightboxPhotos = photos.map((p) => ({
id: String(p.id),
src: photoUrl(p, token!, 'original'),
caption: p.caption,
mediaType: p.media_type,
}));
const lightboxPhotos = photos.map((p) => lightboxPhoto(p, token!));
const isActive = activeEntryId === String(entry.id);
return (
@@ -559,12 +563,7 @@ export default function JourneyPublicPage() {
className="relative block aspect-square w-full cursor-pointer overflow-hidden rounded-lg"
onClick={() =>
setLightbox({
photos: allPhotos.map((p) => ({
id: String(p.id),
src: photoUrl(p, token!, 'original'),
caption: p.caption,
mediaType: p.media_type,
})),
photos: allPhotos.map((p) => lightboxPhoto(p, token!)),
index: idx,
})
}
@@ -760,12 +759,7 @@ export default function JourneyPublicPage() {
onDelete={() => { }}
onPhotoClick={(photos, idx) =>
setLightbox({
photos: photos.map((p) => ({
id: String(p.id),
src: photoUrl(p as any, token!, 'original'),
caption: (p as any).caption ?? null,
mediaType: p.media_type,
})),
photos: photos.map((p) => lightboxPhoto(p, token!)),
index: idx,
})
}
@@ -470,7 +470,7 @@ export function useJourneyDetail({ journeyId, embedded = false }: JourneyDetailO
const photos = (current?.gallery ?? []).filter(p => wanted.has(String(p.id)))
if (!photos.length) return
setLightbox({
photos: photos.map(p => ({ id: p.id, src: photoUrl(p, 'original'), caption: p.caption, provider: p.provider, asset_id: p.asset_id, owner_id: p.owner_id, mediaType: p.media_type })),
photos: photos.map(p => ({ id: p.id, src: photoUrl(p, 'original'), thumbSrc: photoUrl(p, 'thumbnail'), caption: p.caption, provider: p.provider, asset_id: p.asset_id, owner_id: p.owner_id, mediaType: p.media_type })),
index: 0,
})
}, [current?.gallery])
@@ -1,4 +1,4 @@
// FE-JRN-DETAIL-RECORDINGS-001 to FE-JRN-DETAIL-RECORDINGS-003
// FE-JRN-DETAIL-RECORDINGS-001 to FE-JRN-DETAIL-RECORDINGS-004
//
// JRN-01: the journey page's map lines, with the days the journey keeps beside
// the trips' GPX tracks and the live Dawarich trail.
@@ -81,4 +81,15 @@ describe('useJourneyDetailRecordings', () => {
});
expect(setup({ dawarichStatus: 'disconnected' }).result.current.canTakeOverRecording).toBe(false);
});
it('FE-JRN-DETAIL-RECORDINGS-004: the live trail of a day with entries wears the colour of that day, a day without keeps its own (#2906)', async () => {
repo.list.mockResolvedValue([]);
const live = [
line({ place_id: -1, trip_id: 0, kind: 'dawarich_live', date: '2026-05-14', color: '#2563EB' }),
line({ place_id: -2, trip_id: 0, kind: 'dawarich_live', date: '2026-05-15', color: '#7C3AED' }),
];
const { result } = setup({ liveTracks: live });
await waitFor(() => expect(repo.list).toHaveBeenCalledWith(7));
expect(result.current.mapTracks.map((track) => track.color)).toEqual(['#aa0000', '#ff0055', '#7C3AED']);
});
});
@@ -6,7 +6,7 @@ import type { DawarichSuggestionsStatus } from '../../hooks/useDawarichSuggestio
/**
* The recorded days a journey keeps (JRN-01) as the journey page wires them:
* their lines in the colour of the pins of their day, beside the trips' GPX
* tracks and the live Dawarich trail. A kept day is the journey's own, so it
* tracks and the live Dawarich trail, which takes those colours too. A kept day is the journey's own, so it
* draws whatever the GPX switch says, and wins over the live trail of its date.
*/
export function useJourneyDetailRecordings({
@@ -42,9 +42,16 @@ export function useJourneyDetailRecordings({
const mapTracks = useMemo(() => {
if (recordings.tracks.length === 0 && liveTracks.length === 0) return tripTracks;
const live = liveTracks.filter((track) => !track.date || !recordings.byDate.has(track.date));
// The live trail comes in Dawarich's own day palette; on a journey a day wears
// the colour of its entries, so the line of a day with entries takes theirs (#2906).
const live = liveTracks
.filter((track) => !track.date || !recordings.byDate.has(track.date))
.map((track) => {
const color = track.date ? colorOfDay(track.date) : null;
return color && color !== track.color ? { ...track, color } : track;
});
return [...tripTracks, ...recordings.tracks, ...live];
}, [tripTracks, recordings.tracks, recordings.byDate, liveTracks]);
}, [tripTracks, recordings.tracks, recordings.byDate, liveTracks, colorOfDay]);
return {
recordings,
@@ -26,7 +26,7 @@ export function useJourneyPublic() {
const [error, setError] = useState(false)
const isMobile = useIsMobile()
const [view, setView] = useState<'timeline' | 'gallery' | 'map'>('timeline')
const [lightbox, setLightbox] = useState<{ photos: { id: string; src: string; caption?: string | null; mediaType?: string | null }[]; index: number } | null>(null)
const [lightbox, setLightbox] = useState<{ photos: { id: string; src: string; thumbSrc?: string; caption?: string | null; mediaType?: string | null }[]; index: number } | null>(null)
const [showLangPicker, setShowLangPicker] = useState(false)
const locale = useSettingsStore(s => s.settings.language) || 'en'
const mapRef = useRef<JourneyMapHandle>(null)
@@ -4,7 +4,6 @@ import { http, HttpResponse } from 'msw';
import { localIsoDate } from '../../../../src/utils/localDate';
import userEvent from '@testing-library/user-event';
import { mapsApi, weatherApi } from '../../../../src/api/client';
import { useAddonStore } from '../../../../src/store/addonStore';
import MJourneyEntrySheet from '../../../../src/mobile/screens/journey/MJourneyEntrySheet';
import type { GalleryPhoto, JourneyEntry, JourneyPhoto } from '../../../../src/store/journeyStore';
import type { ResilientResult, UploadProgress } from '../../../../src/utils/uploadQueue';
@@ -252,6 +251,7 @@ interface MountOptions {
withProviderHook?: boolean;
upload?: UploadFn;
strict?: boolean;
photoProviders?: { id: string; name: string }[];
}
const defaultUpload: UploadFn = async (_entryId, files, cbs) => {
@@ -274,6 +274,7 @@ function mountSheet(sheetEntry: JourneyEntry, opts: MountOptions = {}) {
readOnly={opts.readOnly ?? false}
userId={42}
trips={[]}
photoProviders={opts.photoProviders}
onClose={onClose}
onSave={onSave}
onUploadPhotos={onUploadPhotos}
@@ -745,6 +746,18 @@ describe('MJourneyEntrySheet full editor', () => {
expect(onSave.mock.calls[0][0]).toMatchObject({ mood: null, weather: null });
});
it('FE-MOB-JENTRY-2905: the picked neutral mood is framed in its own colour and pressed, unlike the chips at rest', async () => {
const user = userEvent.setup();
mountSheet(buildEntry({ id: 5 }));
await user.click(screen.getByRole('button', { name: 'Neutral' }));
const neutral = screen.getByRole('button', { name: 'Neutral' });
expect(neutral).toHaveAttribute('aria-pressed', 'true');
expect(neutral.className).not.toContain('text-m-muted');
expect(neutral.style.borderColor).toBe('rgb(154, 154, 161)');
expect(screen.getByRole('button', { name: 'Good' })).toHaveAttribute('aria-pressed', 'false');
});
it('FE-MOB-JENTRY-022: picks a searched location and stores its coordinates', async () => {
server.use(http.post('/api/maps/search', () => HttpResponse.json({
places: [
@@ -1161,15 +1174,10 @@ describe('MJourneyEntrySheet quick capture edge cases', () => {
// FE-MOB-JENTRY-041 to FE-MOB-JENTRY-047 — external photo providers in the phone
// editor (#1808), mirroring the desktop EntryEditor mechanics.
const immichAddon = { id: 'immich', name: 'Immich', type: 'photo_provider', icon: 'camera', enabled: true };
function seedAddons(addons: Array<Record<string, unknown>>) {
useAddonStore.setState({ addons: addons as never, loaded: true });
}
const immich = [{ id: 'immich', name: 'Immich' }];
function useConnectedImmich() {
server.use(
http.get('/api/integrations/memories/immich/status', () => HttpResponse.json({ connected: true })),
http.post('/api/integrations/memories/immich/search', () => HttpResponse.json({
assets: [{ id: 'asset-1', takenAt: '2026-03-15T09:00:00.000Z', mediaType: 'image' }],
hasMore: false,
@@ -1185,27 +1193,32 @@ describe('MJourneyEntrySheet external photos', () => {
afterEach(() => {
delete window.__addToast;
useAddonStore.setState({ addons: [], loaded: false });
});
it('FE-MOB-JENTRY-041: hides the button while no provider is connected', async () => {
let probes = 0;
seedAddons([immichAddon]);
server.use(http.get('/api/integrations/memories/immich/status', () => {
probes += 1;
return HttpResponse.json({ connected: false });
}));
it('FE-MOB-JENTRY-041: hides the button while no provider is connected', () => {
mountSheet(buildEntry({ id: 5 }));
await waitFor(() => expect(probes).toBe(1));
expect(screen.queryByRole('button', { name: 'External photos' })).not.toBeInTheDocument();
});
it('FE-MOB-JENTRY-2908: a connected provider is there on the first render, without a probe of its own', () => {
let probes = 0;
server.use(http.get('/api/integrations/memories/immich/status', () => {
probes += 1;
return HttpResponse.json({ connected: true });
}));
mountSheet(buildEntry({ id: 5 }), { photoProviders: immich });
const external = screen.getByRole('button', { name: 'External photos' });
// The icons keep their width when a third button shares the row.
expect(external.querySelector('svg')).toHaveClass('shrink-0');
expect(screen.getByRole('button', { name: 'From Gallery' }).querySelector('svg')).toHaveClass('shrink-0');
expect(probes).toBe(0);
});
it('FE-MOB-JENTRY-042: opens the embedded picker for a connected provider', async () => {
seedAddons([immichAddon, { id: 'budget', name: 'Budget', type: 'feature', icon: 'wallet', enabled: true }]);
useConnectedImmich();
const user = userEvent.setup();
mountSheet(buildEntry({ id: 5, location_lat: 41.9, location_lng: 12.5, location_name: 'Rome' }));
mountSheet(buildEntry({ id: 5, location_lat: 41.9, location_lng: 12.5, location_name: 'Rome' }), { photoProviders: immich });
await user.click(await screen.findByRole('button', { name: 'External photos' }));
@@ -1216,20 +1229,18 @@ describe('MJourneyEntrySheet external photos', () => {
});
it('FE-MOB-JENTRY-043: stays out of the quick capture sheet', async () => {
seedAddons([immichAddon]);
useConnectedImmich();
Object.defineProperty(navigator, 'geolocation', { configurable: true, value: undefined });
mountSheet(buildEntry(), { quickCapture: true });
mountSheet(buildEntry(), { quickCapture: true, photoProviders: immich });
expect(await screen.findByRole('button', { name: 'Gallery' })).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'External photos' })).not.toBeInTheDocument();
});
it('FE-MOB-JENTRY-044: queues a picked photo and sends it after the save', async () => {
seedAddons([immichAddon]);
useConnectedImmich();
const user = userEvent.setup();
const { onSave, onAddProviderPhotos, onDone } = mountSheet(buildEntry({ id: 5 }));
const { onSave, onAddProviderPhotos, onDone } = mountSheet(buildEntry({ id: 5 }), { photoProviders: immich });
await user.click(await screen.findByRole('button', { name: 'External photos' }));
await user.click(await screen.findByAltText(''));
@@ -1249,10 +1260,9 @@ describe('MJourneyEntrySheet external photos', () => {
});
it('FE-MOB-JENTRY-045: drops the queue again from the panel header', async () => {
seedAddons([immichAddon]);
useConnectedImmich();
const user = userEvent.setup();
const { onAddProviderPhotos } = mountSheet(buildEntry({ id: 5 }));
const { onAddProviderPhotos } = mountSheet(buildEntry({ id: 5 }), { photoProviders: immich });
await user.click(await screen.findByRole('button', { name: 'External photos' }));
await user.click(await screen.findByAltText(''));
@@ -1265,11 +1275,10 @@ describe('MJourneyEntrySheet external photos', () => {
});
it('FE-MOB-JENTRY-046: a failed provider add keeps the queue and does not create a second entry', async () => {
seedAddons([immichAddon]);
useConnectedImmich();
const user = userEvent.setup();
// A brand new entry: the first save creates it, the provider write then fails.
const { onSave, onAddProviderPhotos, onDone } = mountSheet(buildEntry());
const { onSave, onAddProviderPhotos, onDone } = mountSheet(buildEntry(), { photoProviders: immich });
onAddProviderPhotos.mockRejectedValueOnce(new Error('immich down'));
await user.click(await screen.findByRole('button', { name: 'External photos' }));
@@ -1293,10 +1302,9 @@ describe('MJourneyEntrySheet external photos', () => {
});
it('FE-MOB-JENTRY-047: a skeleton with only provider photos is promoted to an entry', async () => {
seedAddons([immichAddon]);
useConnectedImmich();
const user = userEvent.setup();
const { onSave } = mountSheet(buildEntry({ id: 9, type: 'skeleton', title: 'Venice' }));
const { onSave } = mountSheet(buildEntry({ id: 9, type: 'skeleton', title: 'Venice' }), { photoProviders: immich });
await user.click(await screen.findByRole('button', { name: 'External photos' }));
await user.click(await screen.findByAltText(''));
+33 -9
View File
@@ -14,6 +14,7 @@ import { addDays } from '../days/days.service';
import { ReservationsService } from '../reservations/reservations.service';
import { InjectRepository } from '@mikro-orm/nestjs';
import { Injectable } from '@nestjs/common';
import { isTransportReservationType } from '@trek/shared';
/** The VCALENDAR preamble every TREK calendar starts with, single-trip or merged. */
export const CALENDAR_HEADER =
@@ -572,14 +573,18 @@ export class CalendarService {
// as the pickup. Positional first/last is only a fallback when no role is
// present at all, and only with more than one endpoint, so a lone endpoint is
// never both sides (#1721).
const windowSidesOf = (r: any): { start: WindowSide | null; end: WindowSide | null } => {
const eps = endpointsMap.get(r.id);
const endpointOf = (reservationId: number, side: 'from' | 'to') => {
const eps = endpointsMap.get(reservationId);
const ordered = eps && eps.length > 0 ? [...eps].sort((a, b) => a.sequence - b.sequence) : [];
const roleFrom = ordered.find((e) => e.role === 'from');
const roleTo = ordered.find((e) => e.role === 'to');
const noRoles = !roleFrom && !roleTo;
const startEp = roleFrom ?? (noRoles && ordered.length > 1 ? ordered[0] : undefined);
const endEp = roleTo ?? (noRoles && ordered.length > 1 ? ordered[ordered.length - 1] : undefined);
const byRole = ordered.find((e) => e.role === side);
if (byRole) return byRole;
const noRoles = !ordered.some((e) => e.role === 'from' || e.role === 'to');
if (!noRoles || ordered.length < 2) return undefined;
return side === 'from' ? ordered[0] : ordered[ordered.length - 1];
};
const windowSidesOf = (r: any): { start: WindowSide | null; end: WindowSide | null } => {
const startEp = endpointOf(r.id, 'from');
const endEp = endpointOf(r.id, 'to');
const fromEp = (ep: typeof startEp): WindowSide | null =>
ep && isDate(ep.local_date) && isTime(ep.local_time)
@@ -665,6 +670,24 @@ export class CalendarService {
return out;
};
// Where a transport takes the traveller, as a LOCATION (and GEO) a calendar can
// navigate to (#2909): the route in the description is no address. The side is
// the one the traveller has to get to, the destination of a drive of their own
// and the departure of a ride they board, as the per-leg events do. A
// location the booking states itself still wins.
const SELF_DRIVEN_TYPES = new Set(['car', 'bicycle']);
const locationLines = (
r: { id: number; type?: string | null; location?: string | null },
side: 'from' | 'to' = SELF_DRIVEN_TYPES.has(r.type ?? '') ? 'to' : 'from',
): string => {
if (r.location) return `LOCATION:${esc(r.location)}\r\n`;
const ep = isTransportReservationType(r.type) ? endpointOf(r.id, side) : undefined;
const name = ep?.name || ep?.code;
if (!ep || !name) return '';
const geo = Number.isFinite(ep.lat) && Number.isFinite(ep.lng) ? `GEO:${ep.lat};${ep.lng}\r\n` : '';
return `LOCATION:${esc(name)}\r\n${geo}`;
};
// Reservations as events
for (const r of reservations) {
// The two hand-over events below stand in for this booking entirely.
@@ -701,7 +724,7 @@ export class CalendarService {
const desc = describeReservation(r);
if (desc) ev += `DESCRIPTION:${esc(desc)}\r\n`;
if (r.location) ev += `LOCATION:${esc(r.location)}\r\n`;
ev += locationLines(r);
ev += `END:VEVENT\r\n`;
events.push(ev);
}
@@ -859,7 +882,8 @@ export class CalendarService {
}
ev += `SUMMARY:${esc(summary)}\r\n`;
if (desc) ev += `DESCRIPTION:${esc(desc)}\r\n`;
if (r.location) ev += `LOCATION:${esc(r.location)}\r\n`;
// A hand-over happens where the car is collected or returned.
ev += locationLines(r, kind === 'pickup' ? 'from' : 'to');
ev += `END:VEVENT\r\n`;
events.push(ev);
};
@@ -10,10 +10,13 @@ const DEFAULT_MAX_TOKENS = 8192;
const ANTHROPIC_VERSION = '2023-06-01';
/**
* Anthropic Messages API client. Structured output via forced tool-use: a single
* Anthropic Messages API client. Structured output via tool use: a single
* `emit_<rootKey>` tool (`emit_reservations` by default) whose `input_schema` is
* the caller's schema, with `tool_choice` forcing it — the documented, reliable
* way to get structured JSON.
* the caller's schema, which the system prompt asks the model to answer with.
* The tool is not forced through `tool_choice`: the current models (Claude
* Sonnet 5.5, Opus 5.5, Fable 5.1) refuse `{ type: 'tool' }` and `{ type: 'any' }`
* with a 400, while `auto` is accepted by every model and by Messages-compatible
* gateways (#2902). A model that answers in text instead is reported as such below.
* PDFs go as native base64 `document` blocks (Anthropic reads scanned PDFs), photos
* as `image` blocks.
* Raw fetch (no SDK) to match the codebase's HTTP style.
@@ -48,7 +51,7 @@ export class AnthropicClient implements LlmExtractionClient {
const body = {
model: input.model,
max_tokens: maxTokens,
system: input.prompt,
system: `${input.prompt}\n\n${toolInstruction(toolName)}`,
tools: [
{
name: toolName,
@@ -56,7 +59,8 @@ export class AnthropicClient implements LlmExtractionClient {
input_schema: input.jsonSchema,
},
],
tool_choice: { type: 'tool', name: toolName },
// At most one call: the whole list goes into it.
tool_choice: { type: 'auto', disable_parallel_tool_use: true },
messages: [{ role: 'user', content }],
};
@@ -97,7 +101,7 @@ export class AnthropicClient implements LlmExtractionClient {
throw new Error('Anthropic declined to process this document');
}
// A run that hits the cap stops mid-tool-call, so what arrives is a fragment
// of the list or nothing at all — and a forced tool that was not called left
// of the list or nothing at all — and a tool that was not called left
// no list either. Neither is "this document holds no booking", but both came
// back as [] and reached the person as an empty preview with nothing in the
// log: the #2375 symptom, on the provider the dropdown offers first.
@@ -114,3 +118,8 @@ export class AnthropicClient implements LlmExtractionClient {
}
const USER_TEXT = 'Extract every travel reservation from the following document as schema.org JSON-LD.';
/** What stands in for the forced tool call: the answer goes through the tool, once, and nowhere else. */
function toolInstruction(toolName: string): string {
return `Answer only by calling the ${toolName} tool, exactly once, with everything you extracted. Call it with an empty list when the document holds nothing to extract. Do not answer in text.`;
}
@@ -1513,6 +1513,50 @@ describe('car rentals', () => {
expect(ics).not.toContain('Pickup: Dayless');
expect(ics).not.toContain('Drop-off: Dayless');
});
// ── Where a transport goes: LOCATION and GEO from its endpoints (#2909) ─────
const eventOf = (ics: string, summary: string) =>
ics.replaceAll('\r\n ', '').split('BEGIN:VEVENT').find((ev) => ev.includes(`SUMMARY:${summary}\r\n`)) ?? '';
it('CAL-2909a: a drive of its own is located at its destination, each hand-over where it happens', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id, { title: 'Road Trip' });
const drive = createReservation(testDb, trip.id, { title: 'Drive', type: 'car' });
await updateRows(orm, Reservations, { id: drive.id }, { reservation_time: null, reservation_end_time: null, location: null });
await insertEndpoint(drive.id, 'from', 0, '1 Origin Road, Startville', 48.1, 11.5, 'Europe/Berlin', '09:00', '2026-07-07');
await insertEndpoint(drive.id, 'to', 1, '123 Example Street, Sampletown', 47.5, 12.25, 'Europe/Berlin', '13:00', '2026-07-07');
const { ics } = await svc.exportICS(trip.id);
const event = eventOf(ics, 'Drive');
expect(event).toContain('LOCATION:123 Example Street\\, Sampletown\r\n');
expect(event).toContain('GEO:47.5;12.25\r\n');
// The route stays in the description.
expect(event).toContain('Route: 1 Origin Road\\, Startville → 123 Example Street\\, Sampletown');
expect(eventOf(ics, 'Pickup: Drive')).toContain('LOCATION:1 Origin Road\\, Startville\r\n');
expect(eventOf(ics, 'Drop-off: Drive')).toContain('LOCATION:123 Example Street\\, Sampletown\r\n');
});
it('CAL-2909b: a ride the traveller boards is located where it departs, and a stated location still wins', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id, { title: 'Rail Trip' });
const train = createReservation(testDb, trip.id, { title: 'ICE 571', type: 'train' });
const ferry = createReservation(testDb, trip.id, { title: 'Ferry', type: 'ferry' });
await updateRows(orm, Reservations, { id: train.id }, { reservation_time: null, reservation_end_time: null, location: null });
await updateRows(orm, Reservations, { id: ferry.id }, { reservation_time: null, reservation_end_time: null, location: 'Pier 3' });
await insertEndpoint(train.id, 'from', 0, 'Mannheim Hbf', 49.4794, 8.4692, 'Europe/Berlin', '08:00', '2026-07-08');
await insertEndpoint(train.id, 'to', 1, 'Berlin Hbf', 52.525, 13.369, 'Europe/Berlin', '12:30', '2026-07-08');
await insertEndpoint(ferry.id, 'from', 0, 'Mannheim Hbf', 49.4794, 8.4692, 'Europe/Berlin', '08:00', '2026-07-08');
await insertEndpoint(ferry.id, 'to', 1, 'Berlin Hbf', 52.525, 13.369, 'Europe/Berlin', '12:30', '2026-07-08');
const { ics } = await svc.exportICS(trip.id);
expect(eventOf(ics, 'ICE 571')).toContain('LOCATION:Mannheim Hbf\r\nGEO:49.4794;8.4692\r\n');
const ferryEvent = eventOf(ics, 'Ferry');
expect(ferryEvent).toContain('LOCATION:Pier 3\r\n');
expect(ferryEvent).not.toContain('GEO:');
});
});
describe('staged bookings', () => {
@@ -576,7 +576,7 @@ describe('AnthropicClient', () => {
expect(fetchFn.mock.calls[0][0]).toBe('http://gateway.lan:4000/v1/messages');
expect(fetchFn.mock.calls[1][0]).toBe('https://api.anthropic.com/v1/messages');
const body = JSON.parse((fetchFn.mock.calls[0][1] as RequestInit).body as string);
expect(body.tool_choice).toMatchObject({ type: 'tool', name: 'emit_reservations' });
expect(body.tool_choice).toEqual({ type: 'auto', disable_parallel_tool_use: true });
});
it('tells a prompt too long for a gateway apart from other refusals', async () => {
@@ -632,7 +632,7 @@ describe('AnthropicClient', () => {
expect(blockOf(1).type).toBe('document');
});
it('forces the emit_reservations tool and reads its input', async () => {
it('asks for the emit_reservations tool without forcing it and reads its input (#2902)', async () => {
const fetchFn = mockFetch(() =>
jsonResponse({
stop_reason: 'tool_use',
@@ -644,8 +644,12 @@ describe('AnthropicClient', () => {
const out = await new AnthropicClient().extract(baseInput);
expect(out).toEqual([{ '@type': 'LodgingReservation' }]);
const body = JSON.parse((fetchFn.mock.calls[0][1] as RequestInit).body as string);
expect(body.tool_choice).toEqual({ type: 'tool', name: 'emit_reservations' });
// Claude Sonnet 5.5, Opus 5.5 and Fable 5.1 refuse a forced tool_choice with a 400;
// auto with one call at most is accepted by every model, the prompt names the tool.
expect(body.tool_choice).toEqual({ type: 'auto', disable_parallel_tool_use: true });
expect(body.tools[0].name).toBe('emit_reservations');
expect(body.system.startsWith(baseInput.prompt)).toBe(true);
expect(body.system).toContain('Answer only by calling the emit_reservations tool, exactly once');
});
/*
@@ -702,7 +706,7 @@ describe('AnthropicClient', () => {
});
/*
* A forced tool that was never called, and a run that stopped at the cap with a
* A tool that was never called, and a run that stopped at the cap with a
* fragment of one, both came back as [] — so a long voucher reached the person
* as "no reservations found", with an empty warnings array and nothing in the
* log. That is the #2375 symptom on the provider the dropdown offers first, so
@@ -734,7 +738,7 @@ describe('AnthropicClient', () => {
}
});
it('throws when the forced tool was never called (#2375)', async () => {
it('throws when the tool was never called (#2375)', async () => {
mockFetch(() =>
jsonResponse({
stop_reason: 'end_turn',
+1 -1
View File
@@ -84,7 +84,7 @@ The **AI Parsing** tab starts with **Reads bookings with**, which shows the conn
The form for an **Own connection** has these fields:
- **Provider**: **Local (Ollama)**, **OpenAI** or **Anthropic**.
- **Base URL**: empty means the provider's own address: `http://localhost:11434/v1` for a local Ollama server, `https://api.openai.com/v1` for OpenAI and `https://api.anthropic.com` for Anthropic. Any OpenAI-compatible endpoint goes here. For Anthropic it can name a gateway that speaks the Anthropic Messages API; give it without `/v1`, since TREK adds `/v1/messages`, and the gateway has to accept PDF document blocks and forced tool calls. Picking another provider empties the field, so an address meant for one never receives another provider's key.
- **Base URL**: empty means the provider's own address: `http://localhost:11434/v1` for a local Ollama server, `https://api.openai.com/v1` for OpenAI and `https://api.anthropic.com` for Anthropic. Any OpenAI-compatible endpoint goes here. For Anthropic it can name a gateway that speaks the Anthropic Messages API; give it without `/v1`, since TREK adds `/v1/messages`, and the gateway has to accept PDF document blocks and tool calls. Picking another provider empties the field, so an address meant for one never receives another provider's key.
- **API key**: optional for a local server (the field says *Often not needed*), required for the cloud providers. It is stored **encrypted** and shown masked (`••••••••`) once saved; leaving it unchanged keeps the stored key.
- **Model**: the model id, for example `qwen3.5:4b`, `gpt-4o` or `claude-opus-4-8`.